forked from fireproof-storage/fireproof
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge connect to encrypted-blockstore
- Loading branch information
Dhruv Soni
authored and
Dhruv Soni
committed
Apr 10, 2024
1 parent
a7391cc
commit 251bbca
Showing
50 changed files
with
929 additions
and
1,407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// eslint-disable-next-line no-undef | ||
module.exports = { | ||
env: { | ||
mocha: true | ||
}, | ||
plugins: [ | ||
'mocha' | ||
], | ||
ignorePatterns: ['dist/'], | ||
parser: '@typescript-eslint/parser', | ||
extends: [ | ||
'standard', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:@typescript-eslint/recommended-requiring-type-checking', | ||
'plugin:mocha/recommended' | ||
], | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
project: './tsconfig.json' | ||
}, | ||
rules: { | ||
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], | ||
'@typescript-eslint/no-use-before-define': ['error', { functions: false, classes: false, variables: true, typedefs: false }], | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/ban-ts-comment': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/type-annotation-spacing': 'error', | ||
'no-use-before-define': 'off', | ||
'no-void': 'off', | ||
'space-before-function-paren': ['error', { | ||
anonymous: 'always', | ||
named: 'never', | ||
asyncArrow: 'always' | ||
}], | ||
semi: ['error', 'never'] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
./README.md | ||
dist/ | ||
stats.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# `@fireproof/aws` | ||
|
||
[Fireproof](https://use-fireproof.com) is an embedded JavaScript document database that runs in the browser (or anywhere with JavaScript) and **[connects to any cloud](https://www.npmjs.com/package/@fireproof/connect)**. | ||
|
||
This module, `@fireproof/aws`, allows you to connect your Fireproof database to AWS S3 and DynamoDB via pre defined Lambda functions, enabling you to sync your data across multiple users in real-time. | ||
|
||
## Get started | ||
|
||
We assume you already have an app that uses Fireproof in the browser, and you want to setup collaboration among multiple users via the cloud. To write your first Fireproof app, see the [Fireproof quickstart](https://use-fireproof.com/docs/react-tutorial), otherwise read on. | ||
|
||
### 1. Install | ||
|
||
In your existing Fireproof app install the connector: | ||
|
||
```sh | ||
npm install @fireproof/aws | ||
``` | ||
|
||
### 2. Connect | ||
|
||
You're all done on the server, and ready to develop locally and then deploy with no further changes. Now you just need to connect to the AWS in your client code. Fireproof has an already deployed SAM template and to use the provisioned resources without the websocket based live syncing (backwards compatibility with older fireproof versions) as well as with websocket connections you can simply use the s3Free and awsFree functions respectively. However, if one wants to deploy their own resources they can do so by deploying our sam template and adding the neccassary urls to connect's aws function: | ||
|
||
```js | ||
// you already have this in your app | ||
import { useFireproof } from "use-fireproof"; | ||
// add this line | ||
import { connect } from "@fireproof/aws"; | ||
``` | ||
|
||
Now later in your app connect to the party (be sure to do this a component that runs on every render, like your root component or layout): | ||
|
||
```js | ||
const { database } = useFireproof("my-app-database-name"); | ||
const connection = connect.awsFree(database); | ||
``` | ||
|
||
OR | ||
|
||
```js | ||
const { database } = useFireproof("my-app-database-name"); | ||
const connection = connect.s3Free(database); | ||
``` | ||
|
||
OR | ||
|
||
```js | ||
const { database } = useFireproof("my-app-database-name"); | ||
const connection = connect.aws(database, { | ||
uploadUrl, | ||
downloadUrl, | ||
websocketUrl, | ||
}); | ||
``` | ||
|
||
All the functions are idempotent and designed to be safe to call on every render. | ||
|
||
### 3. Collaborate | ||
|
||
Now you can use Fireproof as you normally would, and it will sync in realtime with other users. Any existing apps you have that use the [live query](https://use-fireproof.com/docs/react-hooks/use-live-query) or [subscription](https://use-fireproof.com/docs/database-api/database#subscribe) APIs will automatically render multi-user updates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@fireproof/aws", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "./dist/browser/index.cjs", | ||
"module": "./dist/browser/index.esm.js", | ||
"exports": { | ||
".": { | ||
"import": "./dist/browser/index.esm.js", | ||
"require": "./dist/browser/index.cjs", | ||
"types": "./dist/types/index.d.ts", | ||
"script": "./dist/browser/index.iife.js" | ||
}, | ||
"./node": { | ||
"import": "./dist/node/index.esm.js", | ||
"require": "./dist/node/index.cjs", | ||
"types": "./dist/types/index.d.ts", | ||
"script": "./dist/browser/index.iife.js", | ||
"default": "./dist/node/index.esm.js" | ||
} | ||
}, | ||
"browser": "./dist/index.browser.iife.js", | ||
"types": "./dist/types/index.d.ts", | ||
"files": [ | ||
"dist/node", | ||
"dist/browser", | ||
"dist/types" | ||
], | ||
"type": "module", | ||
"scripts": { | ||
"prepublishOnly": "npm run build", | ||
"build:clean": "rm -rf dist", | ||
"build:tsc": "npm run build:clean && tsc && mkdir dist/tsc && mv dist/*.js dist/tsc/ && node ../encrypted-blockstore/scripts/types.js", | ||
"build:script": "node ../encrypted-blockstore/scripts/build.js", | ||
"build": "npm run build:tsc && npm run build:script && cp dist/browser/index.iife.js ../fireproof/test/www/connect.iife.js", | ||
"clean": "rm -rf node_modules", | ||
"test": "node ../encrypted-blockstore/scripts/test.js", | ||
"browser-test": "node ../connectors-helper/scripts/browser-test.js" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@fireproof/encrypted-blockstore": "workspace:^", | ||
"cross-fetch": "^4.0.0", | ||
"js-base64": "^3.7.5" | ||
}, | ||
"devDependencies": { | ||
"ts-loader": "^9.4.4", | ||
"typescript": "^5.4.4" | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/connect/src/connect-s3.ts → packages/connect-aws/src/connect-s3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { ConnectS3 } from './connect-s3' | ||
import { Connection,Connectable } from '@fireproof/encrypted-blockstore' | ||
import type { AnyLink } from '@fireproof/encrypted-blockstore' | ||
export type { AnyLink } | ||
import { | ||
UploadDataFnParams, | ||
UploadMetaFnParams, | ||
DownloadDataFnParams, | ||
DownloadMetaFnParams | ||
} from './types' | ||
|
||
|
||
export const connect = { | ||
s3Free: ({ blockstore }: Connectable) => { | ||
const upload = 'https://udvtu5wy39.execute-api.us-east-2.amazonaws.com/uploads' | ||
const download = 'https://crdt-s3uploadbucket-dcjyurxwxmba.s3.us-east-2.amazonaws.com' | ||
const websocket = '' | ||
const connection = new ConnectS3(upload, download, websocket) | ||
connection.connect(blockstore) | ||
return connection | ||
}, | ||
awsFree: ({ blockstore, name }: Connectable) => { | ||
const upload = 'https://udvtu5wy39.execute-api.us-east-2.amazonaws.com/uploads' | ||
const download = 'https://crdt-s3uploadbucket-dcjyurxwxmba.s3.us-east-2.amazonaws.com' | ||
const websocket = `wss://v7eax67rm6.execute-api.us-east-2.amazonaws.com/Prod?database=${name}` | ||
const connection = new ConnectS3(upload, download, websocket) | ||
connection.connect(blockstore) | ||
return connection | ||
}, | ||
aws: ( | ||
{ blockstore, name }: Connectable, | ||
{ upload, download, websocket }: { upload: string; download: string; websocket: string } | ||
) => { | ||
const updatedwebsocket = `${websocket}?database=${name}` | ||
const connection = new ConnectS3(upload, download, updatedwebsocket) | ||
connection.connect(blockstore) | ||
return connection | ||
}, | ||
} | ||
|
||
export function validateDataParams(params: DownloadDataFnParams | UploadDataFnParams) { | ||
const { type, name, car } = params | ||
if (!name) throw new Error('name is required') | ||
if (!car) { | ||
throw new Error('car is required') | ||
} | ||
if (type !== 'file' && type !== 'data') { | ||
throw new Error('type must be file or data') | ||
} | ||
} | ||
|
||
export function validateMetaParams(params: DownloadMetaFnParams | UploadMetaFnParams) { | ||
const { name, branch } = params | ||
if (!name) throw new Error('name is required') | ||
if (!branch) { | ||
throw new Error('branch is required') | ||
} | ||
} | ||
|
||
export { ConnectS3 } |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"include": ["src", "test", ".eslintrc.cjs", "scripts"], | ||
"compilerOptions": { | ||
"module": "esnext", | ||
"target": "esnext", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"jsx": "react", | ||
"skipLibCheck": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"emitDeclarationOnly": false, | ||
"declarationDir": "dist/types", | ||
"declaration": true, | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"forceConsistentCasingInFileNames": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.