@fireproof/core 0.19.121 → 0.20.0-dev-preview-05

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. package/README.md +13 -12
  2. package/deno/index.d.ts +7 -0
  3. package/deno/index.js +66 -0
  4. package/deno/index.js.map +1 -0
  5. package/deno/metafile-esm.json +1 -0
  6. package/deno.json +2 -3
  7. package/index.cjs +1827 -1059
  8. package/index.cjs.map +1 -1
  9. package/index.d.cts +747 -334
  10. package/index.d.ts +747 -334
  11. package/index.js +1800 -1034
  12. package/index.js.map +1 -1
  13. package/metafile-cjs.json +1 -1
  14. package/metafile-esm.json +1 -1
  15. package/node/index.cjs +16 -293
  16. package/node/index.cjs.map +1 -1
  17. package/node/index.d.cts +4 -40
  18. package/node/index.d.ts +4 -40
  19. package/node/index.js +22 -237
  20. package/node/index.js.map +1 -1
  21. package/node/metafile-cjs.json +1 -1
  22. package/node/metafile-esm.json +1 -1
  23. package/package.json +14 -6
  24. package/react/index.cjs +22 -22
  25. package/react/index.cjs.map +1 -1
  26. package/react/index.d.cts +7 -7
  27. package/react/index.d.ts +7 -7
  28. package/react/index.js +22 -22
  29. package/react/index.js.map +1 -1
  30. package/react/metafile-cjs.json +1 -1
  31. package/react/metafile-esm.json +1 -1
  32. package/tests/blockstore/fp-envelope.test.ts-off +65 -0
  33. package/tests/blockstore/interceptor-gateway.test.ts +122 -0
  34. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
  35. package/tests/blockstore/keyed-crypto.test.ts +73 -118
  36. package/tests/blockstore/loader.test.ts +18 -9
  37. package/tests/blockstore/store.test.ts +40 -31
  38. package/tests/blockstore/transaction.test.ts +14 -13
  39. package/tests/fireproof/all-gateway.test.ts +286 -216
  40. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  41. package/tests/fireproof/crdt.test.ts +78 -19
  42. package/tests/fireproof/fireproof.test.ts +111 -92
  43. package/tests/fireproof/hello.test.ts +21 -17
  44. package/tests/fireproof/indexer.test.ts +74 -50
  45. package/tests/fireproof/{database.test.ts → ledger.test.ts} +241 -45
  46. package/tests/fireproof/multiple-ledger.test.ts +2 -2
  47. package/tests/fireproof/utils.test.ts +47 -6
  48. package/tests/gateway/file/loader-config.test.ts +307 -0
  49. package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
  50. package/tests/gateway/indexdb/loader-config.test.ts +79 -0
  51. package/tests/helpers.ts +44 -17
  52. package/tests/react/useFireproof.test.tsx +2 -2
  53. package/tests/www/gallery.html +2 -2
  54. package/tests/www/todo-aws.html +1 -1
  55. package/tests/www/todo-ipfs.html +1 -1
  56. package/tests/www/todo-local.html +1 -1
  57. package/tests/www/todo.html +25 -4
  58. package/web/index.cjs +102 -116
  59. package/web/index.cjs.map +1 -1
  60. package/web/index.d.cts +15 -29
  61. package/web/index.d.ts +15 -29
  62. package/web/index.js +91 -105
  63. package/web/index.js.map +1 -1
  64. package/web/metafile-cjs.json +1 -1
  65. package/web/metafile-esm.json +1 -1
  66. package/node/chunk-4A4RAVNS.js +0 -17
  67. package/node/chunk-4A4RAVNS.js.map +0 -1
  68. package/node/mem-filesystem-LPPT7QV5.js +0 -40
  69. package/node/mem-filesystem-LPPT7QV5.js.map +0 -1
  70. package/tests/fireproof/config.test.ts +0 -163
  71. /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://fireproof.storage/static/img/flame.svg" alt="Fireproof logo" width="25"> [Fireproof](https://fireproof.storage) realtime database
1
+ # <img src="https://fireproof.storage/static/img/flame.svg" alt="Fireproof logo" width="25"> [Fireproof](https://fireproof.storage) realtime ledger
2
2
 
3
3
  <p align="right">
4
4
  <img src="https://img.shields.io/bundlephobia/minzip/%40fireproof%2Fcore" alt="Package size">
@@ -9,11 +9,11 @@
9
9
 
10
10
  ### No setup: write features first, access your data anywhere
11
11
 
12
- Add collaboration to any app with Fireproof. Access data from JavaScript servers and edge functions. Use live queries to update your UI automatically when the database changes. [Connect realtime sync](https://www.npmjs.com/package/@fireproof/connect) and those changes will sync between browsers and backend functions. Apps built this way are multi-player by default.
12
+ Add collaboration to any app with Fireproof. Access data from JavaScript servers and edge functions. Use live queries to update your UI automatically when the ledger changes. [Connect realtime sync](https://www.npmjs.com/package/@fireproof/connect) and those changes will sync between browsers and backend functions. Apps built this way are multi-player by default.
13
13
 
14
14
  ### JavaScript quick start
15
15
 
16
- The document database API will feel familiar. Queries use dynamic indexes, and the database can refresh your UI, as seen in the `db.subscribe` call below, as well as the React liveQuery hook.
16
+ The document ledger API will feel familiar. Queries use dynamic indexes, and the ledger can refresh your UI, as seen in the `db.subscribe` call below, as well as the React liveQuery hook.
17
17
 
18
18
  ```js
19
19
  import { fireproof } from "@fireproof/core";
@@ -32,34 +32,35 @@ beyonceDoc.hitSingles += 1;
32
32
  await db.put(beyonceDoc);
33
33
  ```
34
34
 
35
- Jump to the docs site [for JavaScript API basics.](https://use-fireproof.com/docs/database-api/basics)
35
+ Jump to the docs site [for JavaScript API basics.](https://use-fireproof.com/docs/ledger-api/basics)
36
36
 
37
37
  ### Live data hooks for React
38
38
 
39
39
  Fireproof [React hooks for live data](https://use-fireproof.com/docs/category/react-hooks) avoid boilerplate and make building collaborative apps a breeze.
40
40
 
41
41
  ```js
42
- import { useLiveQuery, useDocument } from 'use-fireproof'
42
+ import { useFireproof } from 'use-fireproof'
43
43
 
44
44
  function App() {
45
+ const { useLiveQuery, useDocument } = useFireproof("my-db-name")
45
46
  const completedTodos = useLiveQuery('completed', { limit: 10 })
46
- const [newTodo, setNewTodoData, saveNewTodo] = useDocument({type: 'todo', text: '', completed: false, created: Date.now() })
47
+ const [newTodo, setNewTodo, saveNewTodo] = useDocument(() => ({type: 'todo', text: '', completed: false, created: Date.now() }))
47
48
  ```
48
49
 
49
50
  Read the [step-by-step React tutorial](https://use-fireproof.com/docs/react-tutorial) to get started.
50
51
 
51
52
  ## Why choose Fireproof
52
53
 
53
- Compared to other embedded databases, Fireproof:
54
+ Compared to other embedded ledgers, Fireproof:
54
55
 
55
56
  - is network aware, encrypted, and multi-writer safe
56
57
  - is designed for real-time collaboration with CRDTs
57
58
  - offers cryptographic causal integrity for all operations
58
59
  - is built for the web, with a small package size and no wasm
59
60
 
60
- Deliver interactive experiences without waiting on the backend. Fireproof runs in any cloud, browser, or edge environment, so your application can access data anywhere.
61
+ Deliver interactive experiences without waiting on the backend. Fireproof runs in any cloud, browser, or edge environment, so your application can access tamperproof data anywhere.
61
62
 
62
- [Get the latest roadmap updates on our blog](https://fireproof.storage/blog/) or join our [Discord](https://discord.gg/cCryrNHePH) to collaborate. Read the docs to learn more about the database [architecture](https://use-fireproof.com/docs/architecture).
63
+ [Get the latest roadmap updates on our blog](https://fireproof.storage/blog/) or join our [Discord](https://discord.gg/cCryrNHePH) to collaborate. Read the docs to learn more about the ledger [architecture](https://use-fireproof.com/docs/architecture).
63
64
 
64
65
  ### Use cases
65
66
 
@@ -83,7 +84,7 @@ Get started with the React hooks:
83
84
  npm install use-fireproof
84
85
  ```
85
86
 
86
- or install the database in any JavaScript environment:
87
+ or install the ledger in any JavaScript environment:
87
88
 
88
89
  ```sh
89
90
  npm install @fireproof/core
@@ -95,7 +96,7 @@ The default build is optimized for browsers, to load the node build add `/node`:
95
96
  import { fireproof } from "@fireproof/core/node";
96
97
  ```
97
98
 
98
- Add the database to any web page via HTML script tag (global is `Fireproof`):
99
+ Add the ledger to any web page via HTML script tag (global is `Fireproof`):
99
100
 
100
101
  ```html
101
102
  <script src="https://cdn.jsdelivr.net/npm/@fireproof/core/dist/browser/fireproof.global.js"></script>
@@ -165,7 +166,7 @@ pnpm run build:doc
165
166
 
166
167
  ## Thanks 🙏
167
168
 
168
- Fireproof is a synthesis of work done by people in the web community over the years. I couldn't even begin to name all the folks who made pivotal contributions. Without npm, React, and VS Code all this would have taken so much longer. Thanks to everyone who supported me getting into database development via Apache CouchDB, one of the original document databases. The distinguishing work on immutable data-structures comes from the years of consideration [IPFS](https://ipfs.tech), [IPLD](https://ipld.io), and the [Filecoin APIs](https://docs.filecoin.io) have enjoyed.
169
+ Fireproof is a synthesis of work done by people in the web community over the years. I couldn't even begin to name all the folks who made pivotal contributions. Without npm, React, and VS Code all this would have taken so much longer. Thanks to everyone who supported me getting into ledger development via Apache CouchDB, one of the original document ledgers. The distinguishing work on immutable data-structures comes from the years of consideration [IPFS](https://ipfs.tech), [IPLD](https://ipld.io), and the [Filecoin APIs](https://docs.filecoin.io) have enjoyed.
169
170
 
170
171
  Thanks to Alan Shaw and Mikeal Rogers without whom this project would have never got started. The core Merkle hash-tree clock is based on [Alan's Pail](https://github.com/alanshaw/pail), and you can see the repository history goes all the way back to work begun as a branch of that repo. Mikeal wrote [the prolly trees implementation](https://github.com/mikeal/prolly-trees).
171
172
 
@@ -0,0 +1,7 @@
1
+ import { SysFileSystem } from '@fireproof/core';
2
+ import { URI } from '@adviser/cement';
3
+
4
+ declare function getSysFileSystem(url: URI): Promise<SysFileSystem>;
5
+
6
+ export { getSysFileSystem };
7
+ declare module '@fireproof/core/deno'
package/deno/index.js ADDED
@@ -0,0 +1,66 @@
1
+ // src/runtime/gateways/file/deno/deno-filesystem.ts
2
+ var DenoFileSystem = class {
3
+ async start() {
4
+ this.fs = Deno;
5
+ return this;
6
+ }
7
+ async mkdir(path, options) {
8
+ return this.fs?.mkdir(path, options).then(() => path);
9
+ }
10
+ async readdir(path) {
11
+ const ret = [];
12
+ for await (const dirEntry of this.fs.readdir(path)) {
13
+ ret.push(dirEntry.name);
14
+ }
15
+ return ret;
16
+ }
17
+ async rm(path, options) {
18
+ return this.fs?.rm(path, options);
19
+ }
20
+ async copyFile(source, destination) {
21
+ return this.fs?.copyFile(source, destination);
22
+ }
23
+ async readfile(path) {
24
+ return this.fs.readFile(path);
25
+ }
26
+ async stat(path) {
27
+ const x = await this.fs.stat(path);
28
+ return {
29
+ isFile: () => x.isFile,
30
+ isDirectory: () => x.isDirectory,
31
+ isBlockDevice: () => !!x.isBlockDevice,
32
+ isCharacterDevice: () => !!x.isCharDevice,
33
+ isSymbolicLink: () => !!x.isSymlink,
34
+ isFIFO: () => !!x.isFifo,
35
+ isSocket: () => !!x.isSocket,
36
+ uid: x.uid,
37
+ gid: x.gid,
38
+ size: x.size,
39
+ atime: x.atime,
40
+ mtime: x.mtime,
41
+ ctime: x.birthtime,
42
+ birthtime: x.birthtime
43
+ };
44
+ }
45
+ async unlink(path) {
46
+ return this.fs?.unlink(path);
47
+ }
48
+ async writefile(path, data) {
49
+ return this.fs?.writeFile(path, Buffer.from(data));
50
+ }
51
+ };
52
+
53
+ // src/runtime/gateways/file/deno/get-sys-file-system.ts
54
+ import { ResolveOnce } from "@adviser/cement";
55
+ var nfs = new ResolveOnce();
56
+ async function getSysFileSystem(url) {
57
+ return nfs.once(async () => {
58
+ const nfs2 = new DenoFileSystem();
59
+ await nfs2.start();
60
+ return nfs2;
61
+ });
62
+ }
63
+ export {
64
+ getSysFileSystem
65
+ };
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/gateways/file/deno/deno-filesystem.ts","../../../src/runtime/gateways/file/deno/get-sys-file-system.ts"],"sourcesContent":["import type { FPStats, SysFileSystem } from \"@fireproof/core\";\n\nexport class DenoFileSystem implements SysFileSystem {\n fs?: {\n mkdir: typeof Deno.mkdir;\n readdir: typeof Deno.readDir;\n rm: typeof Deno.remove;\n copyFile: typeof Deno.copyFile;\n readFile: typeof Deno.readFile;\n stat: typeof Deno.stat;\n unlink: typeof Deno.remove;\n writeFile: typeof Deno.writeFile;\n };\n\n async start(): Promise<SysFileSystem> {\n this.fs = Deno as unknown as DenoFileSystem[\"fs\"];\n return this;\n }\n async mkdir(path: string, options?: { recursive: boolean }): Promise<string | undefined> {\n return this.fs?.mkdir(path, options).then(() => path);\n }\n async readdir(path: string): Promise<string[]> {\n const ret = [];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n for await (const dirEntry of this.fs!.readdir(path)) {\n ret.push(dirEntry.name);\n }\n return ret;\n }\n async rm(path: string, options?: { recursive: boolean }): Promise<void> {\n return this.fs?.rm(path, options);\n }\n async copyFile(source: string, destination: string): Promise<void> {\n return this.fs?.copyFile(source, destination);\n }\n async readfile(path: string): Promise<Uint8Array> {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.fs!.readFile(path);\n }\n async stat(path: string): Promise<FPStats> {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const x = await this.fs!.stat(path);\n return {\n isFile: () => x.isFile,\n isDirectory: () => x.isDirectory,\n isBlockDevice: () => !!x.isBlockDevice,\n isCharacterDevice: () => !!x.isCharDevice,\n isSymbolicLink: () => !!x.isSymlink,\n isFIFO: () => !!x.isFifo,\n isSocket: () => !!x.isSocket,\n uid: x.uid,\n gid: x.gid,\n size: x.size,\n atime: x.atime,\n mtime: x.mtime,\n ctime: x.birthtime,\n birthtime: x.birthtime,\n };\n }\n async unlink(path: string): Promise<void> {\n return this.fs?.unlink(path);\n }\n async writefile(path: string, data: Uint8Array | string): Promise<void> {\n return this.fs?.writeFile(path, Buffer.from(data));\n }\n}\n","import type { SysFileSystem } from \"@fireproof/core\";\nimport { DenoFileSystem } from \"./deno-filesystem.js\";\nimport { ResolveOnce, URI } from \"@adviser/cement\";\n\nconst nfs = new ResolveOnce<SysFileSystem>();\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport async function getSysFileSystem(url: URI): Promise<SysFileSystem> {\n return nfs.once(async () => {\n const nfs = new DenoFileSystem();\n await nfs.start();\n return nfs;\n });\n}\n"],"mappings":";AAEO,IAAM,iBAAN,MAA8C;AAAA,EAYnD,MAAM,QAAgC;AACpC,SAAK,KAAK;AACV,WAAO;AAAA,EACT;AAAA,EACA,MAAM,MAAM,MAAc,SAA+D;AACvF,WAAO,KAAK,IAAI,MAAM,MAAM,OAAO,EAAE,KAAK,MAAM,IAAI;AAAA,EACtD;AAAA,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;AAE3C,eAAsB,iBAAiB,KAAkC;AACvE,SAAO,IAAI,KAAK,YAAY;AAC1B,UAAMA,OAAM,IAAI,eAAe;AAC/B,UAAMA,KAAI,MAAM;AAChB,WAAOA;AAAA,EACT,CAAC;AACH;","names":["nfs"]}
@@ -0,0 +1 @@
1
+ {"inputs":{"src/runtime/gateways/file/deno/deno-filesystem.ts":{"bytes":2181,"imports":[],"format":"esm"},"src/runtime/gateways/file/deno/get-sys-file-system.ts":{"bytes":462,"imports":[{"path":"src/runtime/gateways/file/deno/deno-filesystem.ts","kind":"import-statement","original":"./deno-filesystem.js"},{"path":"@adviser/cement","kind":"import-statement","external":true}],"format":"esm"},"src/runtime/gateways/file/deno/index.ts":{"bytes":61,"imports":[{"path":"src/runtime/gateways/file/deno/get-sys-file-system.ts","kind":"import-statement","original":"./get-sys-file-system.js"}],"format":"esm"}},"outputs":{"dist/fireproof-core/deno/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":4331},"dist/fireproof-core/deno/index.js":{"imports":[{"path":"@adviser/cement","kind":"import-statement","external":true}],"exports":["getSysFileSystem"],"entryPoint":"src/runtime/gateways/file/deno/index.ts","inputs":{"src/runtime/gateways/file/deno/deno-filesystem.ts":{"bytesInOutput":1243},"src/runtime/gateways/file/deno/get-sys-file-system.ts":{"bytesInOutput":235},"src/runtime/gateways/file/deno/index.ts":{"bytesInOutput":0}},"bytes":1620}}}
package/deno.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "imports": {
3
3
  "@fireproof/core": "./index.js",
4
- "@adviser/cement": "npm:@adviser/cement@^0.3.4",
4
+ "@adviser/cement": "npm:@adviser/cement@^0.3.5",
5
5
  "@fireproof/vendor": "npm:@fireproof/vendor@^1.0.4",
6
- "@ipld/unixfs": "npm:@ipld/unixfs@^3.0.0",
7
6
  "multiformats": "npm:multiformats@^13.3.1",
7
+ "@ipld/unixfs": "npm:@ipld/unixfs@^3.0.0",
8
8
  "charwise": "npm:charwise@^3.0.1",
9
9
  "prolly-trees": "npm:prolly-trees@^1.0.4",
10
10
  "idb": "npm:idb@^8.0.1",
11
- "memfs": "npm:memfs@^4.15.1",
12
11
  "p-limit": "npm:p-limit@^6.2.0",
13
12
  "p-map": "npm:p-map@^7.0.3",
14
13
  "p-retry": "npm:p-retry@^6.2.1"