@fireproof/core 0.19.121-dev → 0.20.0-dev-preview-05
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +13 -12
- package/deno/index.d.ts +7 -0
- package/deno/index.js +66 -0
- package/deno/index.js.map +1 -0
- package/deno/metafile-esm.json +1 -0
- package/deno.json +3 -4
- package/index.cjs +1797 -1431
- package/index.cjs.map +1 -1
- package/index.d.cts +760 -381
- package/index.d.ts +760 -381
- package/index.js +1976 -913
- package/index.js.map +1 -1
- package/metafile-cjs.json +1 -1
- package/metafile-esm.json +1 -1
- package/node/{node-filesystem.cjs → index.cjs} +17 -6
- package/node/index.cjs.map +1 -0
- package/node/index.d.cts +7 -0
- package/node/index.d.ts +7 -0
- package/node/{node-filesystem.js → index.js} +25 -5
- package/node/index.js.map +1 -0
- package/node/metafile-cjs.json +1 -1
- package/node/metafile-esm.json +1 -1
- package/package.json +27 -17
- package/react/index.cjs +22 -22
- package/react/index.cjs.map +1 -1
- package/react/index.d.cts +7 -7
- package/react/index.d.ts +7 -7
- package/react/index.js +22 -22
- package/react/index.js.map +1 -1
- package/react/metafile-cjs.json +1 -1
- package/react/metafile-esm.json +1 -1
- package/tests/blockstore/fp-envelope.test.ts-off +65 -0
- package/tests/blockstore/interceptor-gateway.test.ts +122 -0
- package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
- package/tests/blockstore/keyed-crypto.test.ts +75 -118
- package/tests/blockstore/loader.test.ts +18 -9
- package/tests/blockstore/store.test.ts +40 -31
- package/tests/blockstore/transaction.test.ts +14 -13
- package/tests/fireproof/all-gateway.test.ts +286 -216
- package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
- package/tests/fireproof/crdt.test.ts +78 -19
- package/tests/fireproof/fireproof.test.ts +111 -92
- package/tests/fireproof/hello.test.ts +21 -17
- package/tests/fireproof/indexer.test.ts +74 -50
- package/tests/fireproof/{database.test.ts → ledger.test.ts} +241 -45
- package/tests/fireproof/multiple-ledger.test.ts +2 -2
- package/tests/fireproof/utils.test.ts +47 -6
- package/tests/gateway/file/loader-config.test.ts +307 -0
- package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
- package/tests/gateway/indexdb/loader-config.test.ts +79 -0
- package/tests/helpers.ts +44 -17
- package/tests/react/useFireproof.test.tsx +2 -2
- package/tests/www/gallery.html +2 -2
- package/tests/www/todo-aws.html +1 -1
- package/tests/www/todo-ipfs.html +1 -1
- package/tests/www/todo-local.html +1 -1
- package/tests/www/todo.html +25 -4
- package/web/index.cjs +218 -0
- package/web/index.cjs.map +1 -0
- package/web/index.d.cts +30 -0
- package/web/index.d.ts +30 -0
- package/web/index.js +195 -0
- package/web/index.js.map +1 -0
- package/web/metafile-cjs.json +1 -1
- package/web/metafile-esm.json +1 -1
- package/chunk-7EWIAXTM.js +0 -7
- package/chunk-7EWIAXTM.js.map +0 -1
- package/chunk-F4FC6B2T.js +0 -63
- package/chunk-F4FC6B2T.js.map +0 -1
- package/chunk-PZ5AY32C.js +0 -10
- package/chunk-PZ5AY32C.js.map +0 -1
- package/chunk-RXC4JGJT.js +0 -301
- package/chunk-RXC4JGJT.js.map +0 -1
- package/gateway-C62S56GY.js +0 -66
- package/gateway-C62S56GY.js.map +0 -1
- package/gateway-VVS4QWDA.js +0 -145
- package/gateway-VVS4QWDA.js.map +0 -1
- package/key-bag-file-PWZ3QE7B.js +0 -55
- package/key-bag-file-PWZ3QE7B.js.map +0 -1
- package/key-bag-indexdb-SYG3YD4D.js +0 -51
- package/key-bag-indexdb-SYG3YD4D.js.map +0 -1
- package/node/chunk-4A4RAVNS.js +0 -17
- package/node/chunk-4A4RAVNS.js.map +0 -1
- package/node/mem-filesystem.cjs +0 -72
- package/node/mem-filesystem.cjs.map +0 -1
- package/node/mem-filesystem.d.cts +0 -25
- package/node/mem-filesystem.d.ts +0 -25
- package/node/mem-filesystem.js +0 -40
- package/node/mem-filesystem.js.map +0 -1
- package/node/node-filesystem.cjs.map +0 -1
- package/node/node-filesystem.d.cts +0 -35
- package/node/node-filesystem.d.ts +0 -35
- package/node/node-filesystem.js.map +0 -1
- package/tests/fireproof/config.test.ts +0 -172
- package/utils-ZVVGAXFE.js +0 -13
- package/utils-ZVVGAXFE.js.map +0 -1
- package/web/gateway-impl.cjs +0 -183
- package/web/gateway-impl.cjs.map +0 -1
- package/web/gateway-impl.d.cts +0 -31
- package/web/gateway-impl.d.ts +0 -31
- package/web/gateway-impl.js +0 -162
- package/web/gateway-impl.js.map +0 -1
- /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/gateways/file/node/index.ts","../../../src/runtime/gateways/file/node/to-array-buffer.ts","../../../src/runtime/gateways/file/node/node-filesystem.ts","../../../src/runtime/gateways/file/node/get-sys-file-system.ts"],"sourcesContent":["// test needs that\nexport * from \"./get-sys-file-system.js\";\n","export function toArrayBuffer(buffer: Buffer | string): Uint8Array {\n if (typeof buffer === \"string\") {\n buffer = Buffer.from(buffer);\n }\n const ab = new ArrayBuffer(buffer.length);\n const view = new Uint8Array(ab);\n for (let i = 0; i < buffer.length; ++i) {\n view[i] = buffer[i];\n }\n return view;\n}\n","import type { PathLike, MakeDirectoryOptions, Stats, ObjectEncodingOptions } from \"node:fs\";\nimport type { mkdir, readdir, rm, copyFile, readFile, stat, unlink, writeFile } from \"node:fs/promises\";\nimport { toArrayBuffer } from \"./to-array-buffer.js\";\nimport type { SysFileSystem } from \"@fireproof/core\";\nimport { runtimeFn } from \"@adviser/cement\";\n\nexport class NodeFileSystem implements SysFileSystem {\n fs?: {\n mkdir: typeof mkdir;\n readdir: typeof readdir;\n rm: typeof rm;\n copyFile: typeof copyFile;\n readFile: typeof readFile;\n stat: typeof stat;\n unlink: typeof unlink;\n writeFile: typeof writeFile;\n };\n\n async start(): Promise<SysFileSystem> {\n this.fs = await import(\"node:fs/promises\");\n return this;\n }\n async mkdir(path: PathLike, options?: { recursive: boolean }): Promise<string | undefined> {\n return this.fs?.mkdir(path, options);\n }\n async readdir(path: PathLike, options?: ObjectEncodingOptions): Promise<string[]> {\n return this.fs?.readdir(path, options) as Promise<string[]>;\n }\n async rm(path: PathLike, options?: MakeDirectoryOptions & { recursive: boolean }): Promise<void> {\n return this.fs?.rm(path, options);\n }\n async copyFile(source: PathLike, destination: PathLike): Promise<void> {\n return this.fs?.copyFile(source, destination);\n }\n async readfile(path: PathLike, options?: { encoding: BufferEncoding; flag?: string }): Promise<Uint8Array> {\n const ret = (await this.fs?.readFile(path, options)) as Buffer;\n return toArrayBuffer(ret);\n }\n stat(path: PathLike): Promise<Stats> {\n return this.fs?.stat(path) as Promise<Stats>;\n }\n async unlink(path: PathLike): Promise<void> {\n return this.fs?.unlink(path);\n }\n async writefile(path: PathLike, data: Uint8Array | string): Promise<void> {\n if (runtimeFn().isDeno) {\n return this.fs?.writeFile(path, data);\n }\n return this.fs?.writeFile(path, Buffer.from(data));\n }\n}\n\n// import { type NodeMap, join } from \"../../sys-container.js\";\n// import type { ObjectEncodingOptions, PathLike } from \"fs\";\n// import * as fs from \"fs/promises\";\n// import * as path from \"path\";\n// import * as os from \"os\";\n// import * as url from \"url\";\n// import { toArrayBuffer } from \"./utils.js\";\n\n// export async function createNodeSysContainer(): Promise<NodeMap> {\n// // const nodePath = \"node:path\";\n// // const nodeOS = \"node:os\";\n// // const nodeURL = \"node:url\";\n// // const nodeFS = \"node:fs\";\n// // const fs = (await import(\"node:fs\")).promises;\n// // const assert = \"assert\";\n// // const path = await import(\"node:path\");\n// return {\n// state: \"node\",\n// ...path,\n// // ...(await import(\"node:os\")),\n// // ...(await import(\"node:url\")),\n// ...os,\n// ...url,\n// ...fs,\n// join,\n// stat: fs.stat as NodeMap[\"stat\"],\n// readdir: fs.readdir as NodeMap[\"readdir\"],\n// readfile: async (path: PathLike, options?: ObjectEncodingOptions): Promise<Uint8Array> => {\n// const rs = await fs.readFile(path, options);\n// return toArrayBuffer(rs);\n// },\n// writefile: fs.writeFile as NodeMap[\"writefile\"],\n// };\n// }\n","import type { SysFileSystem } from \"@fireproof/core\";\nimport { NodeFileSystem } from \"./node-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 NodeFileSystem();\n await nfs.start();\n return nfs;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,cAAc,QAAqC;AACjE,MAAI,OAAO,WAAW,UAAU;AAC9B,aAAS,OAAO,KAAK,MAAM;AAAA,EAC7B;AACA,QAAM,KAAK,IAAI,YAAY,OAAO,MAAM;AACxC,QAAM,OAAO,IAAI,WAAW,EAAE;AAC9B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,EAAE,GAAG;AACtC,SAAK,CAAC,IAAI,OAAO,CAAC;AAAA,EACpB;AACA,SAAO;AACT;;;ACNA,oBAA0B;AAEnB,IAAM,iBAAN,MAA8C;AAAA,EAYnD,MAAM,QAAgC;AACpC,SAAK,KAAK,MAAM,OAAO,aAAkB;AACzC,WAAO;AAAA,EACT;AAAA,EACA,MAAM,MAAM,MAAgB,SAA+D;AACzF,WAAO,KAAK,IAAI,MAAM,MAAM,OAAO;AAAA,EACrC;AAAA,EACA,MAAM,QAAQ,MAAgB,SAAoD;AAChF,WAAO,KAAK,IAAI,QAAQ,MAAM,OAAO;AAAA,EACvC;AAAA,EACA,MAAM,GAAG,MAAgB,SAAwE;AAC/F,WAAO,KAAK,IAAI,GAAG,MAAM,OAAO;AAAA,EAClC;AAAA,EACA,MAAM,SAAS,QAAkB,aAAsC;AACrE,WAAO,KAAK,IAAI,SAAS,QAAQ,WAAW;AAAA,EAC9C;AAAA,EACA,MAAM,SAAS,MAAgB,SAA4E;AACzG,UAAM,MAAO,MAAM,KAAK,IAAI,SAAS,MAAM,OAAO;AAClD,WAAO,cAAc,GAAG;AAAA,EAC1B;AAAA,EACA,KAAK,MAAgC;AACnC,WAAO,KAAK,IAAI,KAAK,IAAI;AAAA,EAC3B;AAAA,EACA,MAAM,OAAO,MAA+B;AAC1C,WAAO,KAAK,IAAI,OAAO,IAAI;AAAA,EAC7B;AAAA,EACA,MAAM,UAAU,MAAgB,MAA0C;AACxE,YAAI,yBAAU,EAAE,QAAQ;AACtB,aAAO,KAAK,IAAI,UAAU,MAAM,IAAI;AAAA,IACtC;AACA,WAAO,KAAK,IAAI,UAAU,MAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EACnD;AACF;;;AChDA,IAAAA,iBAAiC;AAEjC,IAAM,MAAM,IAAI,2BAA2B;AAE3C,eAAsB,iBAAiB,KAAkC;AACvE,SAAO,IAAI,KAAK,YAAY;AAC1B,UAAMC,OAAM,IAAI,eAAe;AAC/B,UAAMA,KAAI,MAAM;AAChB,WAAOA;AAAA,EACT,CAAC;AACH;","names":["import_cement","nfs"]}
|
package/node/index.d.cts
ADDED
package/node/index.d.ts
ADDED
@@ -1,6 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
// src/runtime/gateways/file/node/to-array-buffer.ts
|
2
|
+
function toArrayBuffer(buffer) {
|
3
|
+
if (typeof buffer === "string") {
|
4
|
+
buffer = Buffer.from(buffer);
|
5
|
+
}
|
6
|
+
const ab = new ArrayBuffer(buffer.length);
|
7
|
+
const view = new Uint8Array(ab);
|
8
|
+
for (let i = 0; i < buffer.length; ++i) {
|
9
|
+
view[i] = buffer[i];
|
10
|
+
}
|
11
|
+
return view;
|
12
|
+
}
|
4
13
|
|
5
14
|
// src/runtime/gateways/file/node/node-filesystem.ts
|
6
15
|
import { runtimeFn } from "@adviser/cement";
|
@@ -38,7 +47,18 @@ var NodeFileSystem = class {
|
|
38
47
|
return this.fs?.writeFile(path, Buffer.from(data));
|
39
48
|
}
|
40
49
|
};
|
50
|
+
|
51
|
+
// src/runtime/gateways/file/node/get-sys-file-system.ts
|
52
|
+
import { ResolveOnce } from "@adviser/cement";
|
53
|
+
var nfs = new ResolveOnce();
|
54
|
+
async function getSysFileSystem(url) {
|
55
|
+
return nfs.once(async () => {
|
56
|
+
const nfs2 = new NodeFileSystem();
|
57
|
+
await nfs2.start();
|
58
|
+
return nfs2;
|
59
|
+
});
|
60
|
+
}
|
41
61
|
export {
|
42
|
-
|
62
|
+
getSysFileSystem
|
43
63
|
};
|
44
|
-
//# sourceMappingURL=
|
64
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/gateways/file/node/to-array-buffer.ts","../../../src/runtime/gateways/file/node/node-filesystem.ts","../../../src/runtime/gateways/file/node/get-sys-file-system.ts"],"sourcesContent":["export function toArrayBuffer(buffer: Buffer | string): Uint8Array {\n if (typeof buffer === \"string\") {\n buffer = Buffer.from(buffer);\n }\n const ab = new ArrayBuffer(buffer.length);\n const view = new Uint8Array(ab);\n for (let i = 0; i < buffer.length; ++i) {\n view[i] = buffer[i];\n }\n return view;\n}\n","import type { PathLike, MakeDirectoryOptions, Stats, ObjectEncodingOptions } from \"node:fs\";\nimport type { mkdir, readdir, rm, copyFile, readFile, stat, unlink, writeFile } from \"node:fs/promises\";\nimport { toArrayBuffer } from \"./to-array-buffer.js\";\nimport type { SysFileSystem } from \"@fireproof/core\";\nimport { runtimeFn } from \"@adviser/cement\";\n\nexport class NodeFileSystem implements SysFileSystem {\n fs?: {\n mkdir: typeof mkdir;\n readdir: typeof readdir;\n rm: typeof rm;\n copyFile: typeof copyFile;\n readFile: typeof readFile;\n stat: typeof stat;\n unlink: typeof unlink;\n writeFile: typeof writeFile;\n };\n\n async start(): Promise<SysFileSystem> {\n this.fs = await import(\"node:fs/promises\");\n return this;\n }\n async mkdir(path: PathLike, options?: { recursive: boolean }): Promise<string | undefined> {\n return this.fs?.mkdir(path, options);\n }\n async readdir(path: PathLike, options?: ObjectEncodingOptions): Promise<string[]> {\n return this.fs?.readdir(path, options) as Promise<string[]>;\n }\n async rm(path: PathLike, options?: MakeDirectoryOptions & { recursive: boolean }): Promise<void> {\n return this.fs?.rm(path, options);\n }\n async copyFile(source: PathLike, destination: PathLike): Promise<void> {\n return this.fs?.copyFile(source, destination);\n }\n async readfile(path: PathLike, options?: { encoding: BufferEncoding; flag?: string }): Promise<Uint8Array> {\n const ret = (await this.fs?.readFile(path, options)) as Buffer;\n return toArrayBuffer(ret);\n }\n stat(path: PathLike): Promise<Stats> {\n return this.fs?.stat(path) as Promise<Stats>;\n }\n async unlink(path: PathLike): Promise<void> {\n return this.fs?.unlink(path);\n }\n async writefile(path: PathLike, data: Uint8Array | string): Promise<void> {\n if (runtimeFn().isDeno) {\n return this.fs?.writeFile(path, data);\n }\n return this.fs?.writeFile(path, Buffer.from(data));\n }\n}\n\n// import { type NodeMap, join } from \"../../sys-container.js\";\n// import type { ObjectEncodingOptions, PathLike } from \"fs\";\n// import * as fs from \"fs/promises\";\n// import * as path from \"path\";\n// import * as os from \"os\";\n// import * as url from \"url\";\n// import { toArrayBuffer } from \"./utils.js\";\n\n// export async function createNodeSysContainer(): Promise<NodeMap> {\n// // const nodePath = \"node:path\";\n// // const nodeOS = \"node:os\";\n// // const nodeURL = \"node:url\";\n// // const nodeFS = \"node:fs\";\n// // const fs = (await import(\"node:fs\")).promises;\n// // const assert = \"assert\";\n// // const path = await import(\"node:path\");\n// return {\n// state: \"node\",\n// ...path,\n// // ...(await import(\"node:os\")),\n// // ...(await import(\"node:url\")),\n// ...os,\n// ...url,\n// ...fs,\n// join,\n// stat: fs.stat as NodeMap[\"stat\"],\n// readdir: fs.readdir as NodeMap[\"readdir\"],\n// readfile: async (path: PathLike, options?: ObjectEncodingOptions): Promise<Uint8Array> => {\n// const rs = await fs.readFile(path, options);\n// return toArrayBuffer(rs);\n// },\n// writefile: fs.writeFile as NodeMap[\"writefile\"],\n// };\n// }\n","import type { SysFileSystem } from \"@fireproof/core\";\nimport { NodeFileSystem } from \"./node-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 NodeFileSystem();\n await nfs.start();\n return nfs;\n });\n}\n"],"mappings":";AAAO,SAAS,cAAc,QAAqC;AACjE,MAAI,OAAO,WAAW,UAAU;AAC9B,aAAS,OAAO,KAAK,MAAM;AAAA,EAC7B;AACA,QAAM,KAAK,IAAI,YAAY,OAAO,MAAM;AACxC,QAAM,OAAO,IAAI,WAAW,EAAE;AAC9B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,EAAE,GAAG;AACtC,SAAK,CAAC,IAAI,OAAO,CAAC;AAAA,EACpB;AACA,SAAO;AACT;;;ACNA,SAAS,iBAAiB;AAEnB,IAAM,iBAAN,MAA8C;AAAA,EAYnD,MAAM,QAAgC;AACpC,SAAK,KAAK,MAAM,OAAO,kBAAkB;AACzC,WAAO;AAAA,EACT;AAAA,EACA,MAAM,MAAM,MAAgB,SAA+D;AACzF,WAAO,KAAK,IAAI,MAAM,MAAM,OAAO;AAAA,EACrC;AAAA,EACA,MAAM,QAAQ,MAAgB,SAAoD;AAChF,WAAO,KAAK,IAAI,QAAQ,MAAM,OAAO;AAAA,EACvC;AAAA,EACA,MAAM,GAAG,MAAgB,SAAwE;AAC/F,WAAO,KAAK,IAAI,GAAG,MAAM,OAAO;AAAA,EAClC;AAAA,EACA,MAAM,SAAS,QAAkB,aAAsC;AACrE,WAAO,KAAK,IAAI,SAAS,QAAQ,WAAW;AAAA,EAC9C;AAAA,EACA,MAAM,SAAS,MAAgB,SAA4E;AACzG,UAAM,MAAO,MAAM,KAAK,IAAI,SAAS,MAAM,OAAO;AAClD,WAAO,cAAc,GAAG;AAAA,EAC1B;AAAA,EACA,KAAK,MAAgC;AACnC,WAAO,KAAK,IAAI,KAAK,IAAI;AAAA,EAC3B;AAAA,EACA,MAAM,OAAO,MAA+B;AAC1C,WAAO,KAAK,IAAI,OAAO,IAAI;AAAA,EAC7B;AAAA,EACA,MAAM,UAAU,MAAgB,MAA0C;AACxE,QAAI,UAAU,EAAE,QAAQ;AACtB,aAAO,KAAK,IAAI,UAAU,MAAM,IAAI;AAAA,IACtC;AACA,WAAO,KAAK,IAAI,UAAU,MAAM,OAAO,KAAK,IAAI,CAAC;AAAA,EACnD;AACF;;;AChDA,SAAS,mBAAwB;AAEjC,IAAM,MAAM,IAAI,YAA2B;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"]}
|
package/node/metafile-cjs.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"inputs":{"src/runtime/gateways/file/node/to-array-buffer.ts":{"bytes":313,"imports":[],"format":"esm"},"src/runtime/gateways/file/node/
|
1
|
+
{"inputs":{"src/runtime/gateways/file/node/to-array-buffer.ts":{"bytes":313,"imports":[],"format":"esm"},"src/runtime/gateways/file/node/node-filesystem.ts":{"bytes":3138,"imports":[{"path":"src/runtime/gateways/file/node/to-array-buffer.ts","kind":"import-statement","original":"./to-array-buffer.js"},{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"fs/promises","kind":"dynamic-import","external":true}],"format":"esm"},"src/runtime/gateways/file/node/get-sys-file-system.ts":{"bytes":462,"imports":[{"path":"src/runtime/gateways/file/node/node-filesystem.ts","kind":"import-statement","original":"./node-filesystem.js"},{"path":"@adviser/cement","kind":"import-statement","external":true}],"format":"esm"},"src/runtime/gateways/file/node/index.ts":{"bytes":61,"imports":[{"path":"src/runtime/gateways/file/node/get-sys-file-system.ts","kind":"import-statement","original":"./get-sys-file-system.js"}],"format":"esm"}},"outputs":{"dist/fireproof-core/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":5849},"dist/fireproof-core/node/index.cjs":{"imports":[{"path":"@adviser/cement","kind":"require-call","external":true},{"path":"fs/promises","kind":"dynamic-import","external":true},{"path":"@adviser/cement","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/runtime/gateways/file/node/index.ts","inputs":{"src/runtime/gateways/file/node/index.ts":{"bytesInOutput":143},"src/runtime/gateways/file/node/to-array-buffer.ts":{"bytesInOutput":277},"src/runtime/gateways/file/node/node-filesystem.ts":{"bytesInOutput":915},"src/runtime/gateways/file/node/get-sys-file-system.ts":{"bytesInOutput":252}},"bytes":3193}}}
|
package/node/metafile-esm.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"inputs":{"src/runtime/gateways/file/node/to-array-buffer.ts":{"bytes":313,"imports":[],"format":"esm"},"src/runtime/gateways/file/node/
|
1
|
+
{"inputs":{"src/runtime/gateways/file/node/to-array-buffer.ts":{"bytes":313,"imports":[],"format":"esm"},"src/runtime/gateways/file/node/node-filesystem.ts":{"bytes":3138,"imports":[{"path":"src/runtime/gateways/file/node/to-array-buffer.ts","kind":"import-statement","original":"./to-array-buffer.js"},{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"dynamic-import","external":true}],"format":"esm"},"src/runtime/gateways/file/node/get-sys-file-system.ts":{"bytes":462,"imports":[{"path":"src/runtime/gateways/file/node/node-filesystem.ts","kind":"import-statement","original":"./node-filesystem.js"},{"path":"@adviser/cement","kind":"import-statement","external":true}],"format":"esm"},"src/runtime/gateways/file/node/index.ts":{"bytes":61,"imports":[{"path":"src/runtime/gateways/file/node/get-sys-file-system.ts","kind":"import-statement","original":"./get-sys-file-system.js"}],"format":"esm"}},"outputs":{"dist/fireproof-core/node/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":5658},"dist/fireproof-core/node/index.js":{"imports":[{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"dynamic-import","external":true},{"path":"@adviser/cement","kind":"import-statement","external":true}],"exports":["getSysFileSystem"],"entryPoint":"src/runtime/gateways/file/node/index.ts","inputs":{"src/runtime/gateways/file/node/to-array-buffer.ts":{"bytesInOutput":277},"src/runtime/gateways/file/node/node-filesystem.ts":{"bytesInOutput":898},"src/runtime/gateways/file/node/get-sys-file-system.ts":{"bytesInOutput":235},"src/runtime/gateways/file/node/index.ts":{"bytesInOutput":0}},"bytes":1606}}}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fireproof/core",
|
3
|
-
"version": "0.
|
4
|
-
"description": "Live
|
3
|
+
"version": "0.20.0-dev-preview-05",
|
4
|
+
"description": "Live ledger for the web.",
|
5
5
|
"type": "module",
|
6
6
|
"module": "./index.js",
|
7
7
|
"main": "./index.cjs",
|
@@ -9,32 +9,43 @@
|
|
9
9
|
"exports": {
|
10
10
|
".": {
|
11
11
|
"import": "./index.js",
|
12
|
+
"browser": "./index.js",
|
12
13
|
"require": "./index.cjs",
|
13
14
|
"types": "./index.d.ts"
|
14
15
|
},
|
15
16
|
"./node": {
|
16
|
-
"import":
|
17
|
-
|
18
|
-
|
17
|
+
"import": {
|
18
|
+
"browser": "./web/index.js",
|
19
|
+
"default": "./node/index.js"
|
20
|
+
},
|
21
|
+
"browser": "./web/index.js",
|
22
|
+
"require": "./node/index.cjs",
|
23
|
+
"types": "./node/index.d.ts"
|
19
24
|
},
|
20
|
-
"./
|
21
|
-
"import":
|
22
|
-
|
23
|
-
|
25
|
+
"./deno": {
|
26
|
+
"import": {
|
27
|
+
"browser": "./web/index.js",
|
28
|
+
"default": "./deno/index.js"
|
29
|
+
},
|
30
|
+
"browser": "./web/index.js",
|
31
|
+
"require": "./deno/index.cjs",
|
32
|
+
"types": "./deno/index.d.ts"
|
24
33
|
},
|
25
34
|
"./web": {
|
26
|
-
"import": "./web/
|
27
|
-
"
|
28
|
-
"
|
35
|
+
"import": "./web/index.js",
|
36
|
+
"browser": "./web/index.js",
|
37
|
+
"require": "./web/index.cjs",
|
38
|
+
"types": "./web/index.d.ts"
|
29
39
|
},
|
30
40
|
"./react": {
|
31
41
|
"import": "./react/index.js",
|
42
|
+
"browser": "./react/index.js",
|
32
43
|
"require": "./react/index.cjs",
|
33
44
|
"types": "./react/index.d.ts"
|
34
45
|
}
|
35
46
|
},
|
36
47
|
"keywords": [
|
37
|
-
"
|
48
|
+
"ledger",
|
38
49
|
"JSON",
|
39
50
|
"document",
|
40
51
|
"IPLD",
|
@@ -64,14 +75,13 @@
|
|
64
75
|
"react": "^18.3.1"
|
65
76
|
},
|
66
77
|
"dependencies": {
|
67
|
-
"@adviser/cement": "^0.3.
|
68
|
-
"@fireproof/vendor": "^1.0.
|
69
|
-
"@ipld/unixfs": "^3.0.0",
|
78
|
+
"@adviser/cement": "^0.3.5",
|
79
|
+
"@fireproof/vendor": "^1.0.4",
|
70
80
|
"multiformats": "^13.3.1",
|
81
|
+
"@ipld/unixfs": "^3.0.0",
|
71
82
|
"charwise": "^3.0.1",
|
72
83
|
"prolly-trees": "^1.0.4",
|
73
84
|
"idb": "^8.0.1",
|
74
|
-
"memfs": "^4.15.1",
|
75
85
|
"p-limit": "^6.2.0",
|
76
86
|
"p-map": "^7.0.3",
|
77
87
|
"p-retry": "^6.2.1"
|
package/react/index.cjs
CHANGED
@@ -34,7 +34,7 @@ var import_core = require("@fireproof/core");
|
|
34
34
|
var import_react = require("react");
|
35
35
|
var FireproofCtx = {};
|
36
36
|
function useFireproof(name = "useFireproof", config = {}) {
|
37
|
-
const
|
37
|
+
const ledger = typeof name === "string" ? (0, import_core.fireproof)(name, config) : name;
|
38
38
|
function useDocument2(initialDocOrFn) {
|
39
39
|
let initialDoc;
|
40
40
|
if (typeof initialDocOrFn === "function") {
|
@@ -45,12 +45,12 @@ function useFireproof(name = "useFireproof", config = {}) {
|
|
45
45
|
const docId = initialDoc._id ?? "";
|
46
46
|
const [doc, setDoc] = (0, import_react.useState)(initialDoc);
|
47
47
|
const refreshDoc = (0, import_react.useCallback)(async () => {
|
48
|
-
const doc2 = docId ? await
|
48
|
+
const doc2 = docId ? await ledger.get(docId).catch(() => initialDoc) : initialDoc;
|
49
49
|
setDoc(doc2);
|
50
50
|
}, [docId]);
|
51
51
|
const saveDoc = (0, import_react.useCallback)(
|
52
52
|
async (existingDoc) => {
|
53
|
-
const res = await
|
53
|
+
const res = await ledger.put(existingDoc ?? doc);
|
54
54
|
if (!existingDoc && !doc._id) setDoc((d) => ({ ...d, _id: res.id }));
|
55
55
|
return res;
|
56
56
|
},
|
@@ -59,9 +59,9 @@ function useFireproof(name = "useFireproof", config = {}) {
|
|
59
59
|
const deleteDoc = (0, import_react.useCallback)(
|
60
60
|
async (existingDoc) => {
|
61
61
|
const id = existingDoc?._id ?? docId;
|
62
|
-
const doc2 = await
|
63
|
-
if (!doc2) throw
|
64
|
-
const res = await
|
62
|
+
const doc2 = await ledger.get(id).catch(() => void 0);
|
63
|
+
if (!doc2) throw ledger.logger.Error().Str("id", id).Msg(`Document not found`).AsError();
|
64
|
+
const res = await ledger.del(id);
|
65
65
|
setDoc(initialDoc);
|
66
66
|
return res;
|
67
67
|
},
|
@@ -76,7 +76,7 @@ function useFireproof(name = "useFireproof", config = {}) {
|
|
76
76
|
);
|
77
77
|
(0, import_react.useEffect)(() => {
|
78
78
|
if (!docId) return;
|
79
|
-
return
|
79
|
+
return ledger.subscribe((changes) => {
|
80
80
|
if (changes.find((c) => c._id === docId)) {
|
81
81
|
void refreshDoc();
|
82
82
|
}
|
@@ -95,12 +95,12 @@ function useFireproof(name = "useFireproof", config = {}) {
|
|
95
95
|
const queryString = (0, import_react.useMemo)(() => JSON.stringify(query), [query]);
|
96
96
|
const mapFnString = (0, import_react.useMemo)(() => mapFn.toString(), [mapFn]);
|
97
97
|
const refreshRows = (0, import_react.useCallback)(async () => {
|
98
|
-
const res = await
|
98
|
+
const res = await ledger.query(mapFn, query);
|
99
99
|
setResult({ ...res, docs: res.rows.map((r) => r.doc) });
|
100
100
|
}, [mapFnString, queryString]);
|
101
101
|
(0, import_react.useEffect)(() => {
|
102
102
|
refreshRows();
|
103
|
-
return
|
103
|
+
return ledger.subscribe(refreshRows);
|
104
104
|
}, [refreshRows]);
|
105
105
|
return result;
|
106
106
|
}
|
@@ -110,12 +110,12 @@ function useFireproof(name = "useFireproof", config = {}) {
|
|
110
110
|
});
|
111
111
|
const queryString = (0, import_react.useMemo)(() => JSON.stringify(query), [query]);
|
112
112
|
const refreshRows = (0, import_react.useCallback)(async () => {
|
113
|
-
const res = await
|
113
|
+
const res = await ledger.allDocs(query);
|
114
114
|
setResult({ ...res, docs: res.rows.map((r) => r.value) });
|
115
115
|
}, [queryString]);
|
116
116
|
(0, import_react.useEffect)(() => {
|
117
117
|
refreshRows();
|
118
|
-
return
|
118
|
+
return ledger.subscribe(refreshRows);
|
119
119
|
}, [refreshRows]);
|
120
120
|
return result;
|
121
121
|
}
|
@@ -125,46 +125,46 @@ function useFireproof(name = "useFireproof", config = {}) {
|
|
125
125
|
});
|
126
126
|
const queryString = (0, import_react.useMemo)(() => JSON.stringify(opts), [opts]);
|
127
127
|
const refreshRows = (0, import_react.useCallback)(async () => {
|
128
|
-
const res = await
|
128
|
+
const res = await ledger.changes(since, opts);
|
129
129
|
setResult({ ...res, docs: res.rows.map((r) => r.value) });
|
130
130
|
}, [since, queryString]);
|
131
131
|
(0, import_react.useEffect)(() => {
|
132
132
|
refreshRows();
|
133
|
-
return
|
133
|
+
return ledger.subscribe(refreshRows);
|
134
134
|
}, [refreshRows]);
|
135
135
|
return result;
|
136
136
|
}
|
137
|
-
return {
|
137
|
+
return { ledger, useLiveQuery: useLiveQuery2, useDocument: useDocument2, useAllDocs: useAllDocs2, useChanges: useChanges2 };
|
138
138
|
}
|
139
139
|
|
140
140
|
// src/react/useDocument.ts
|
141
141
|
function topLevelUseDocument(...args) {
|
142
|
-
const { useDocument: useDocument2,
|
143
|
-
topLevelUseDocument.
|
142
|
+
const { useDocument: useDocument2, ledger } = useFireproof();
|
143
|
+
topLevelUseDocument.ledger = ledger;
|
144
144
|
return useDocument2(...args);
|
145
145
|
}
|
146
146
|
var useDocument = topLevelUseDocument;
|
147
147
|
|
148
148
|
// src/react/useLiveQuery.ts
|
149
149
|
function topLevelUseLiveQuery(...args) {
|
150
|
-
const { useLiveQuery: useLiveQuery2,
|
151
|
-
topLevelUseLiveQuery.
|
150
|
+
const { useLiveQuery: useLiveQuery2, ledger } = useFireproof();
|
151
|
+
topLevelUseLiveQuery.ledger = ledger;
|
152
152
|
return useLiveQuery2(...args);
|
153
153
|
}
|
154
154
|
var useLiveQuery = topLevelUseLiveQuery;
|
155
155
|
|
156
156
|
// src/react/useAllDocs.ts
|
157
157
|
function topLevelUseAllDocs(...args) {
|
158
|
-
const { useAllDocs: useAllDocs2,
|
159
|
-
topLevelUseAllDocs.
|
158
|
+
const { useAllDocs: useAllDocs2, ledger } = useFireproof();
|
159
|
+
topLevelUseAllDocs.ledger = ledger;
|
160
160
|
return useAllDocs2(...args);
|
161
161
|
}
|
162
162
|
var useAllDocs = topLevelUseAllDocs;
|
163
163
|
|
164
164
|
// src/react/useChanges.ts
|
165
165
|
function topLevelUseChanges(...args) {
|
166
|
-
const { useChanges: useChanges2,
|
167
|
-
topLevelUseChanges.
|
166
|
+
const { useChanges: useChanges2, ledger } = useFireproof();
|
167
|
+
topLevelUseChanges.ledger = ledger;
|
168
168
|
return useChanges2(...args);
|
169
169
|
}
|
170
170
|
var useChanges = topLevelUseChanges;
|
package/react/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/react/index.ts","../../../src/react/useFireproof.ts","../../../src/react/useDocument.ts","../../../src/react/useLiveQuery.ts","../../../src/react/useAllDocs.ts","../../../src/react/useChanges.ts"],"sourcesContent":["export { type TLUseDocument, useDocument } from \"./useDocument.js\";\nexport { FireproofCtx, type UseFireproof, useFireproof } from \"./useFireproof.js\";\nexport { type TLUseLiveQuery, useLiveQuery } from \"./useLiveQuery.js\";\nexport { type TLUseAllDocs, useAllDocs } from \"./useAllDocs.js\";\nexport { type TLUseChanges, useChanges } from \"./useChanges.js\";\n// why is this there is should be a package system\n// export * from \"@fireproof/core\";\n","import type {\n ConfigOpts,\n Database,\n DocFragment,\n DocResponse,\n DocSet,\n DocTypes,\n DocWithId,\n IndexKeyType,\n IndexRow,\n MapFn,\n QueryOpts,\n} from \"@fireproof/core\";\nimport { fireproof } from \"@fireproof/core\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport type { AllDocsQueryOpts, ChangesOptions, ClockHead } from \"@fireproof/core\";\n\nexport interface LiveQueryResult<T extends DocTypes, K extends IndexKeyType, R extends DocFragment = T> {\n readonly docs: DocWithId<T>[];\n readonly rows: IndexRow<K, T, R>[];\n}\n\nexport type UseLiveQuery = <T extends DocTypes, K extends IndexKeyType = string, R extends DocFragment = T>(\n mapFn: string | MapFn<T>,\n query?: QueryOpts<K>,\n initialRows?: IndexRow<K, T, R>[],\n) => LiveQueryResult<T, K, R>;\n\nexport interface AllDocsResult<T extends DocTypes> {\n readonly docs: DocWithId<T>[];\n}\n\nexport interface ChangesResult<T extends DocTypes> {\n readonly docs: DocWithId<T>[];\n}\n\nexport type UseAllDocs = <T extends DocTypes>(query?: AllDocsQueryOpts) => AllDocsResult<T>;\n\nexport type UseChanges = <T extends DocTypes>(since: ClockHead, opts: ChangesOptions) => ChangesResult<T>;\n\ninterface UpdateDocFnOptions {\n readonly replace?: boolean;\n readonly reset?: boolean;\n}\n\ntype UpdateDocFn<T extends DocTypes> = (newDoc?: DocSet<T>, options?: UpdateDocFnOptions) => void;\n\ntype StoreDocFn<T extends DocTypes> = (existingDoc?: DocWithId<T>) => Promise<DocResponse>;\n\ntype DeleteDocFn<T extends DocTypes> = (existingDoc?: DocWithId<T>) => Promise<DocResponse>;\n\nexport type UseDocumentResult<T extends DocTypes> = [DocWithId<T>, UpdateDocFn<T>, StoreDocFn<T>, DeleteDocFn<T>];\n\nexport type UseDocumentInitialDocOrFn<T extends DocTypes> = DocSet<T> | (() => DocSet<T>);\nexport type UseDocument = <T extends DocTypes>(initialDocOrFn: UseDocumentInitialDocOrFn<T>) => UseDocumentResult<T>;\n\nexport interface UseFireproof {\n readonly database: Database;\n /**\n * ## Summary\n *\n * React hook that provides the ability to create/update/save new Fireproof documents into your custom Fireproof database.\n * The creation occurs when you do not pass in an `_id` as part of your initial document -- the database will assign a new\n * one when you call the provided `save` handler. The hook also provides generics support so you can inline your custom type into\n * the invocation to receive type-safety and auto-complete support in your IDE.\n *\n * ## Usage\n *\n * ```tsx\n * const [todo, setTodo, saveTodo] = useDocument<Todo>({\n * text: '',\n * date: Date.now(),\n * completed: false\n * })\n *\n * const [doc, setDoc, saveDoc] = useDocument<Customer>({\n * _id: `${props.customerId}-profile`, // you can imagine `customerId` as a prop passed in\n * name: \"\",\n * company: \"\",\n * startedAt: Date.now()\n * })\n * ```\n *\n * ## Overview\n *\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useLiveQuery` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\n readonly useDocument: UseDocument;\n /**\n * ## Summary\n * React hook that provides access to live query results, enabling real-time updates in your app.\n *\n * ## Usage\n * ```tsx\n * const result = useLiveQuery(\"date\"); // using string key\n * const result = useLiveQuery('date', { limit: 10, descending: true }) // key + options\n * const result = useLiveQuery<CustomType>(\"date\"); // using generics\n * const result = useLiveQuery((doc) => doc.date)); // using map function\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useLiveQuery` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\n readonly useLiveQuery: UseLiveQuery;\n /**\n * ## Summary\n * React hook that provides access to all documents in the database, sorted by `_id`.\n *\n * ## Usage\n * ```tsx\n * const result = useAllDocs({ limit: 10, descending: true }); // with options\n * const result = useAllDocs(); // without options\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useAllDocs` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\n readonly useAllDocs: UseAllDocs;\n /**\n * ## Summary\n * React hook that provides access to all new documents in the database added since the last time the changes was called\n *\n * ## Usage\n * ```tsx\n * const result = useChanges(prevresult.clock,{limit:10}); // with options\n * const result = useChanges(); // without options\n * const database = useChanges.database; // underlying \"useFireproof\" database accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useAllDocs`, `useChanges` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\n readonly useChanges: UseChanges;\n}\n\n/**\n * @deprecated Use the `useFireproof` hook instead\n */\nexport const FireproofCtx = {} as UseFireproof;\n\n/**\n *\n * ## Summary\n *\n * React hook to create a custom-named Fireproof database and provides the utility hooks to query against it.\n *\n * ## Usage\n * ```tsx\n * const { database, useLiveQuery, useDocument } = useFireproof(\"dbname\");\n * const { database, useLiveQuery, useDocument } = useFireproof(\"dbname\", { ...options });\n * ```\n *\n * ## Overview\n *\n * TL;DR: Only use this hook if you need to configure a database name other than the default `useFireproof`.\n *\n * For most applications, using the `useLiveQuery` or `useDocument` hooks exported from `use-fireproof` should\n * suffice for the majority of use-cases. Under the hood, they act against a database named `useFireproof` instantiated with\n * default configurations. However, if you need to do a custom database setup or configure a database name more to your liking\n * than the default `useFireproof`, then use `useFireproof` as it exists for that purpose. It will provide you with the\n * custom database accessor and *lexically scoped* versions of `useLiveQuery` and `useDocument` that act against said\n * custom database.\n *\n */\nexport function useFireproof(name: string | Database = \"useFireproof\", config: ConfigOpts = {}): UseFireproof {\n const database = typeof name === \"string\" ? fireproof(name, config) : name;\n\n function useDocument<T extends DocTypes>(initialDocOrFn: UseDocumentInitialDocOrFn<T>): UseDocumentResult<T> {\n let initialDoc: DocSet<T>;\n if (typeof initialDocOrFn === \"function\") {\n initialDoc = initialDocOrFn();\n } else {\n initialDoc = initialDocOrFn;\n }\n\n // We purposely refetch the docId everytime to check if it has changed\n const docId = initialDoc._id ?? \"\";\n\n // We do not want to force consumers to memoize their initial document so we do it for them.\n // We use the stringified generator function to ensure that the memoization is stable across renders.\n // const initialDoc = useMemo(initialDocFn, [initialDocFn.toString()]);\n const [doc, setDoc] = useState(initialDoc);\n\n const refreshDoc = useCallback(async () => {\n // todo add option for mvcc checks\n const doc = docId ? await database.get<T>(docId).catch(() => initialDoc) : initialDoc;\n setDoc(doc);\n }, [docId]);\n\n const saveDoc: StoreDocFn<T> = useCallback(\n async (existingDoc) => {\n const res = await database.put(existingDoc ?? doc);\n // If the document was created, then we need to update the local state with the new `_id`\n if (!existingDoc && !doc._id) setDoc((d) => ({ ...d, _id: res.id }));\n return res;\n },\n [doc],\n );\n\n const deleteDoc: DeleteDocFn<T> = useCallback(\n async (existingDoc) => {\n const id = existingDoc?._id ?? docId;\n const doc = await database.get<T>(id).catch(() => undefined);\n if (!doc) throw database.logger.Error().Str(\"id\", id).Msg(`Document not found`).AsError();\n const res = await database.del(id);\n setDoc(initialDoc);\n return res;\n },\n [docId, initialDoc],\n );\n\n const updateDoc: UpdateDocFn<T> = useCallback(\n (newDoc, opts = { replace: false, reset: false }) => {\n if (!newDoc) return void (opts.reset ? setDoc(initialDoc) : refreshDoc());\n setDoc((d) => (opts.replace ? (newDoc as DocWithId<T>) : { ...d, ...newDoc }));\n },\n [refreshDoc, initialDoc],\n );\n\n useEffect(() => {\n if (!docId) return;\n return database.subscribe((changes) => {\n if (changes.find((c) => c._id === docId)) {\n void refreshDoc(); // todo use change.value\n }\n });\n }, [docId, refreshDoc]);\n\n useEffect(() => {\n void refreshDoc();\n }, [refreshDoc]);\n\n return [{ _id: docId, ...doc }, updateDoc, saveDoc, deleteDoc];\n }\n\n function useLiveQuery<T extends DocTypes, K extends IndexKeyType = string, R extends DocFragment = T>(\n mapFn: MapFn<T> | string,\n query = {},\n initialRows: IndexRow<K, T, R>[] = [],\n ): LiveQueryResult<T, K, R> {\n const [result, setResult] = useState<LiveQueryResult<T, K, R>>(() => ({\n rows: initialRows,\n docs: initialRows.map((r) => r.doc).filter((r): r is DocWithId<T> => !!r),\n }));\n\n const queryString = useMemo(() => JSON.stringify(query), [query]);\n const mapFnString = useMemo(() => mapFn.toString(), [mapFn]);\n\n const refreshRows = useCallback(async () => {\n const res = await database.query<K, T, R>(mapFn, query);\n setResult({ ...res, docs: res.rows.map((r) => r.doc as DocWithId<T>) });\n }, [mapFnString, queryString]);\n\n useEffect(() => {\n refreshRows(); // Initial data fetch\n return database.subscribe(refreshRows);\n }, [refreshRows]);\n\n return result;\n }\n\n function useAllDocs<T extends DocTypes>(query: AllDocsQueryOpts = {}): AllDocsResult<T> {\n const [result, setResult] = useState<AllDocsResult<T>>({\n docs: [],\n });\n\n const queryString = useMemo(() => JSON.stringify(query), [query]);\n\n const refreshRows = useCallback(async () => {\n const res = await database.allDocs<T>(query);\n setResult({ ...res, docs: res.rows.map((r) => r.value as DocWithId<T>) });\n }, [queryString]);\n\n useEffect(() => {\n refreshRows(); // Initial data fetch\n return database.subscribe(refreshRows);\n }, [refreshRows]);\n\n return result;\n }\n\n function useChanges<T extends DocTypes>(since: ClockHead = [], opts: ChangesOptions = {}): ChangesResult<T> {\n const [result, setResult] = useState<ChangesResult<T>>({\n docs: [],\n });\n\n const queryString = useMemo(() => JSON.stringify(opts), [opts]);\n\n const refreshRows = useCallback(async () => {\n const res = await database.changes<T>(since, opts);\n setResult({ ...res, docs: res.rows.map((r) => r.value as DocWithId<T>) });\n }, [since, queryString]);\n\n useEffect(() => {\n refreshRows(); // Initial data fetch\n return database.subscribe(refreshRows);\n }, [refreshRows]);\n\n return result;\n }\n\n return { database, useLiveQuery, useDocument, useAllDocs, useChanges };\n}\n","import { Database, DocTypes, DocWithId } from \"@fireproof/core\";\n\nimport { UseDocument, UseDocumentResult, useFireproof } from \"./useFireproof.js\";\n\nexport interface TLUseDocument {\n <T extends DocTypes>(initialDoc: DocWithId<T>): UseDocumentResult<T>;\n database: Database;\n}\n\nfunction topLevelUseDocument(...args: Parameters<UseDocument>) {\n const { useDocument, database } = useFireproof();\n (topLevelUseDocument as TLUseDocument).database = database;\n return useDocument(...args);\n}\n\n/**\n * ## Summary\n *\n * React hook that provides the ability to create new Fireproof documents. The creation occurs when\n * you do not pass in an `_id` as part of your initial document -- the database will assign a new one when\n * you call the provided `save` handler This uses the default database named `useFireproof` under the hood which you can also\n * access via the `database` accessor.\n *\n * ## Usage\n *\n * ```tsx\n * const [todo, setTodo, saveTodo] = useDocument(() => ({\n * text: '',\n * date: Date.now(),\n * completed: false\n * }))\n *\n * const [doc, setDoc, saveDoc] = useDocument(() => ({\n * _id: `${props.customerId}-profile`, // you can imagine `customerId` as a prop passed in\n * name: \"\",\n * company: \"\",\n * startedAt: Date.now()\n * }))\n *\n * const database = useDocument.database; // underlying \"useFireproof\" database accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useLiveQuery` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\nexport const useDocument = topLevelUseDocument as TLUseDocument;\n","import { Database, DocFragment, DocTypes, IndexKeyType } from \"@fireproof/core\";\n\nimport { LiveQueryResult, useFireproof, UseLiveQuery } from \"./useFireproof.js\";\n\nexport interface TLUseLiveQuery {\n <T extends DocTypes, K extends IndexKeyType, R extends DocFragment = T>(\n ...args: Parameters<UseLiveQuery>\n ): LiveQueryResult<T, K, R>;\n database: Database;\n}\n\nfunction topLevelUseLiveQuery(...args: Parameters<UseLiveQuery>) {\n const { useLiveQuery, database } = useFireproof();\n (topLevelUseLiveQuery as TLUseLiveQuery).database = database;\n return useLiveQuery(...args);\n}\n\n/**\n * ## Summary\n * React hook that provides access to live query results, enabling real-time updates in your app. This uses\n * the default database named \"useFireproof\" under the hood which you can also access via the `database` accessor.\n *\n * ## Usage\n * ```tsx\n * const results = useLiveQuery(\"date\"); // using string\n * const results = useLiveQuery((doc) => doc.date)); // using map function\n * const database = useLiveQuery.database; // underlying \"useFireproof\" database accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useLiveQuery` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\nexport const useLiveQuery = topLevelUseLiveQuery as TLUseLiveQuery;\n","import { Database, DocTypes } from \"@fireproof/core\";\n\nimport { AllDocsResult, useFireproof, UseAllDocs } from \"./useFireproof.js\";\n\nexport interface TLUseAllDocs {\n <T extends DocTypes>(...args: Parameters<UseAllDocs>): AllDocsResult<T>;\n database: Database;\n}\n\nfunction topLevelUseAllDocs(...args: Parameters<UseAllDocs>) {\n const { useAllDocs, database } = useFireproof();\n (topLevelUseAllDocs as TLUseAllDocs).database = database;\n return useAllDocs(...args);\n}\n\n/**\n * ## Summary\n * React hook that provides access to all documents in the database, sorted by `_id`.\n *\n * ## Usage\n * ```tsx\n * const result = useAllDocs({ limit: 10, descending: true }); // with options\n * const result = useAllDocs(); // without options\n * const database = useAllDocs.database; // underlying \"useFireproof\" database accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useAllDocs` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\nexport const useAllDocs = topLevelUseAllDocs as TLUseAllDocs;\n","import { Database, DocTypes } from \"@fireproof/core\";\n\nimport { ChangesResult, useFireproof, UseChanges } from \"./useFireproof.js\";\n\nexport interface TLUseChanges {\n <T extends DocTypes>(...args: Parameters<UseChanges>): ChangesResult<T>;\n database: Database;\n}\n\nfunction topLevelUseChanges(...args: Parameters<UseChanges>) {\n const { useChanges, database } = useFireproof();\n (topLevelUseChanges as TLUseChanges).database = database;\n return useChanges(...args);\n}\n\n/**\n * ## Summary\n * React hook that provides access to all new documents in the database added since the last time the changes was called\n *\n * ## Usage\n * ```tsx\n * const result = useChanges(prevresult.clock,{limit:10}); // with options\n * const result = useChanges(); // without options\n * const database = useChanges.database; // underlying \"useFireproof\" database accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useAllDocs`, `useChanges` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\nexport const useChanges = topLevelUseChanges as TLUseChanges;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaA,kBAA0B;AAC1B,mBAA0D;AAoInD,IAAM,eAAe,CAAC;AA0BtB,SAAS,aAAa,OAA0B,gBAAgB,SAAqB,CAAC,GAAiB;AAC5G,QAAM,WAAW,OAAO,SAAS,eAAW,uBAAU,MAAM,MAAM,IAAI;AAEtE,WAASA,aAAgC,gBAAoE;AAC3G,QAAI;AACJ,QAAI,OAAO,mBAAmB,YAAY;AACxC,mBAAa,eAAe;AAAA,IAC9B,OAAO;AACL,mBAAa;AAAA,IACf;AAGA,UAAM,QAAQ,WAAW,OAAO;AAKhC,UAAM,CAAC,KAAK,MAAM,QAAI,uBAAS,UAAU;AAEzC,UAAM,iBAAa,0BAAY,YAAY;AAEzC,YAAMC,OAAM,QAAQ,MAAM,SAAS,IAAO,KAAK,EAAE,MAAM,MAAM,UAAU,IAAI;AAC3E,aAAOA,IAAG;AAAA,IACZ,GAAG,CAAC,KAAK,CAAC;AAEV,UAAM,cAAyB;AAAA,MAC7B,OAAO,gBAAgB;AACrB,cAAM,MAAM,MAAM,SAAS,IAAI,eAAe,GAAG;AAEjD,YAAI,CAAC,eAAe,CAAC,IAAI,IAAK,QAAO,CAAC,OAAO,EAAE,GAAG,GAAG,KAAK,IAAI,GAAG,EAAE;AACnE,eAAO;AAAA,MACT;AAAA,MACA,CAAC,GAAG;AAAA,IACN;AAEA,UAAM,gBAA4B;AAAA,MAChC,OAAO,gBAAgB;AACrB,cAAM,KAAK,aAAa,OAAO;AAC/B,cAAMA,OAAM,MAAM,S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Y,YAAY;AAC1C,YAAM,MAAM,MAAM,SAAS,QAAW,OAAO,IAAI;AACjD,gBAAU,EAAE,GAAG,KAAK,MAAM,IAAI,KAAK,IAAI,CAAC,MAAM,EAAE,KAAqB,EAAE,CAAC;AAAA,IAC1E,GAAG,CAAC,OAAO,WAAW,CAAC;AAEvB,gCAAU,MAAM;AACd,kBAAY;AACZ,aAAO,SAAS,UAAU,WAAW;AAAA,IACvC,GAAG,CAAC,WAAW,CAAC;AAEhB,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,UAAU,cAAAF,eAAc,aAAAF,cAAa,YAAAG,aAAY,YAAAC,YAAW;AACvE;;;AC7SA,SAAS,uBAAuB,MAA+B;AAC7D,QAAM,EAAE,aAAAC,cAAa,SAAS,IAAI,aAAa;AAC/C,EAAC,oBAAsC,WAAW;AAClD,SAAOA,aAAY,GAAG,IAAI;AAC5B;AAkCO,IAAM,cAAc;;;ACpC3B,SAAS,wBAAwB,MAAgC;AAC/D,QAAM,EAAE,cAAAC,eAAc,SAAS,IAAI,aAAa;AAChD,EAAC,qBAAwC,WAAW;AACpD,SAAOA,cAAa,GAAG,IAAI;AAC7B;AAmBO,IAAM,eAAe;;;ACzB5B,SAAS,sBAAsB,MAA8B;AAC3D,QAAM,EAAE,YAAAC,aAAY,SAAS,IAAI,aAAa;AAC9C,EAAC,mBAAoC,WAAW;AAChD,SAAOA,YAAW,GAAG,IAAI;AAC3B;AAkBO,IAAM,aAAa;;;ACtB1B,SAAS,sBAAsB,MAA8B;AAC3D,QAAM,EAAE,YAAAC,aAAY,SAAS,IAAI,aAAa;AAC9C,EAAC,mBAAoC,WAAW;AAChD,SAAOA,YAAW,GAAG,IAAI;AAC3B;AAkBO,IAAM,aAAa;","names":["useDocument","doc","useLiveQuery","useAllDocs","useChanges","useDocument","useLiveQuery","useAllDocs","useChanges"]}
|
1
|
+
{"version":3,"sources":["../../../src/react/index.ts","../../../src/react/useFireproof.ts","../../../src/react/useDocument.ts","../../../src/react/useLiveQuery.ts","../../../src/react/useAllDocs.ts","../../../src/react/useChanges.ts"],"sourcesContent":["export {\n type TLUseDocument,\n /** @deprecated Use return values from useFireproof('dbname') instead. Top level usage will be removed in future versions. */\n useDocument,\n} from \"./useDocument.js\";\nexport { FireproofCtx, type UseFireproof, useFireproof } from \"./useFireproof.js\";\nexport {\n type TLUseLiveQuery,\n /** @deprecated Use return values from useFireproof('dbname') instead. Top level usage will be removed in future versions. */\n useLiveQuery,\n} from \"./useLiveQuery.js\";\nexport {\n type TLUseAllDocs,\n /** @deprecated Use return values from useFireproof('dbname') instead. Top level usage will be removed in future versions. */\n useAllDocs,\n} from \"./useAllDocs.js\";\nexport {\n type TLUseChanges,\n /** @deprecated Use return values from useFireproof('dbname') instead. Top level usage will be removed in future versions. */\n useChanges,\n} from \"./useChanges.js\";\n// why is this there is should be a package system\n// export * from \"@fireproof/core\";\n","import type {\n ConfigOpts,\n DocFragment,\n DocResponse,\n DocSet,\n DocTypes,\n DocWithId,\n IndexKeyType,\n IndexRow,\n Ledger,\n MapFn,\n QueryOpts,\n} from \"@fireproof/core\";\nimport { fireproof } from \"@fireproof/core\";\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport type { AllDocsQueryOpts, ChangesOptions, ClockHead } from \"@fireproof/core\";\n\nexport interface LiveQueryResult<T extends DocTypes, K extends IndexKeyType, R extends DocFragment = T> {\n readonly docs: DocWithId<T>[];\n readonly rows: IndexRow<K, T, R>[];\n}\n\nexport type UseLiveQuery = <T extends DocTypes, K extends IndexKeyType = string, R extends DocFragment = T>(\n mapFn: string | MapFn<T>,\n query?: QueryOpts<K>,\n initialRows?: IndexRow<K, T, R>[],\n) => LiveQueryResult<T, K, R>;\n\nexport interface AllDocsResult<T extends DocTypes> {\n readonly docs: DocWithId<T>[];\n}\n\nexport interface ChangesResult<T extends DocTypes> {\n readonly docs: DocWithId<T>[];\n}\n\nexport type UseAllDocs = <T extends DocTypes>(query?: AllDocsQueryOpts) => AllDocsResult<T>;\n\nexport type UseChanges = <T extends DocTypes>(since: ClockHead, opts: ChangesOptions) => ChangesResult<T>;\n\ninterface UpdateDocFnOptions {\n readonly replace?: boolean;\n readonly reset?: boolean;\n}\n\ntype UpdateDocFn<T extends DocTypes> = (newDoc?: DocSet<T>, options?: UpdateDocFnOptions) => void;\n\ntype StoreDocFn<T extends DocTypes> = (existingDoc?: DocWithId<T>) => Promise<DocResponse>;\n\ntype DeleteDocFn<T extends DocTypes> = (existingDoc?: DocWithId<T>) => Promise<DocResponse>;\n\nexport type UseDocumentResult<T extends DocTypes> = [DocWithId<T>, UpdateDocFn<T>, StoreDocFn<T>, DeleteDocFn<T>];\n\nexport type UseDocumentInitialDocOrFn<T extends DocTypes> = DocSet<T> | (() => DocSet<T>);\nexport type UseDocument = <T extends DocTypes>(initialDocOrFn: UseDocumentInitialDocOrFn<T>) => UseDocumentResult<T>;\n\nexport interface UseFireproof {\n readonly ledger: Ledger;\n /**\n * ## Summary\n *\n * React hook that provides the ability to create/update/save new Fireproof documents into your custom Fireproof ledger.\n * The creation occurs when you do not pass in an `_id` as part of your initial document -- the ledger will assign a new\n * one when you call the provided `save` handler. The hook also provides generics support so you can inline your custom type into\n * the invocation to receive type-safety and auto-complete support in your IDE.\n *\n * ## Usage\n *\n * ```tsx\n * const [todo, setTodo, saveTodo] = useDocument<Todo>({\n * text: '',\n * date: Date.now(),\n * completed: false\n * })\n *\n * const [doc, setDoc, saveDoc] = useDocument<Customer>({\n * _id: `${props.customerId}-profile`, // you can imagine `customerId` as a prop passed in\n * name: \"\",\n * company: \"\",\n * startedAt: Date.now()\n * })\n * ```\n *\n * ## Overview\n *\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useLiveQuery` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\n readonly useDocument: UseDocument;\n /**\n * ## Summary\n * React hook that provides access to live query results, enabling real-time updates in your app.\n *\n * ## Usage\n * ```tsx\n * const result = useLiveQuery(\"date\"); // using string key\n * const result = useLiveQuery('date', { limit: 10, descending: true }) // key + options\n * const result = useLiveQuery<CustomType>(\"date\"); // using generics\n * const result = useLiveQuery((doc) => doc.date)); // using map function\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useLiveQuery` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\n readonly useLiveQuery: UseLiveQuery;\n /**\n * ## Summary\n * React hook that provides access to all documents in the ledger, sorted by `_id`.\n *\n * ## Usage\n * ```tsx\n * const result = useAllDocs({ limit: 10, descending: true }); // with options\n * const result = useAllDocs(); // without options\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useAllDocs` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\n readonly useAllDocs: UseAllDocs;\n /**\n * ## Summary\n * React hook that provides access to all new documents in the ledger added since the last time the changes was called\n *\n * ## Usage\n * ```tsx\n * const result = useChanges(prevresult.clock,{limit:10}); // with options\n * const result = useChanges(); // without options\n * const ledger = useChanges.ledger; // underlying \"useFireproof\" ledger accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useAllDocs`, `useChanges` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\n readonly useChanges: UseChanges;\n}\n\n/**\n * @deprecated Use the `useFireproof` hook instead\n */\nexport const FireproofCtx = {} as UseFireproof;\n\n/**\n *\n * ## Summary\n *\n * React hook to create a custom-named Fireproof ledger and provides the utility hooks to query against it.\n *\n * ## Usage\n * ```tsx\n * const { ledger, useLiveQuery, useDocument } = useFireproof(\"dbname\");\n * const { ledger, useLiveQuery, useDocument } = useFireproof(\"dbname\", { ...options });\n * ```\n *\n * ## Overview\n *\n * TL;DR: Only use this hook if you need to configure a ledger name other than the default `useFireproof`.\n *\n * For most applications, using the `useLiveQuery` or `useDocument` hooks exported from `use-fireproof` should\n * suffice for the majority of use-cases. Under the hood, they act against a ledger named `useFireproof` instantiated with\n * default configurations. However, if you need to do a custom ledger setup or configure a ledger name more to your liking\n * than the default `useFireproof`, then use `useFireproof` as it exists for that purpose. It will provide you with the\n * custom ledger accessor and *lexically scoped* versions of `useLiveQuery` and `useDocument` that act against said\n * custom ledger.\n *\n */\nexport function useFireproof(name: string | Ledger = \"useFireproof\", config: ConfigOpts = {}): UseFireproof {\n const ledger = typeof name === \"string\" ? fireproof(name, config) : name;\n\n function useDocument<T extends DocTypes>(initialDocOrFn: UseDocumentInitialDocOrFn<T>): UseDocumentResult<T> {\n let initialDoc: DocSet<T>;\n if (typeof initialDocOrFn === \"function\") {\n initialDoc = initialDocOrFn();\n } else {\n initialDoc = initialDocOrFn;\n }\n\n // We purposely refetch the docId everytime to check if it has changed\n const docId = initialDoc._id ?? \"\";\n\n // We do not want to force consumers to memoize their initial document so we do it for them.\n // We use the stringified generator function to ensure that the memoization is stable across renders.\n // const initialDoc = useMemo(initialDocFn, [initialDocFn.toString()]);\n const [doc, setDoc] = useState(initialDoc);\n\n const refreshDoc = useCallback(async () => {\n // todo add option for mvcc checks\n const doc = docId ? await ledger.get<T>(docId).catch(() => initialDoc) : initialDoc;\n setDoc(doc);\n }, [docId]);\n\n const saveDoc: StoreDocFn<T> = useCallback(\n async (existingDoc) => {\n const res = await ledger.put(existingDoc ?? doc);\n // If the document was created, then we need to update the local state with the new `_id`\n if (!existingDoc && !doc._id) setDoc((d) => ({ ...d, _id: res.id }));\n return res;\n },\n [doc],\n );\n\n const deleteDoc: DeleteDocFn<T> = useCallback(\n async (existingDoc) => {\n const id = existingDoc?._id ?? docId;\n const doc = await ledger.get<T>(id).catch(() => undefined);\n if (!doc) throw ledger.logger.Error().Str(\"id\", id).Msg(`Document not found`).AsError();\n const res = await ledger.del(id);\n setDoc(initialDoc);\n return res;\n },\n [docId, initialDoc],\n );\n\n const updateDoc: UpdateDocFn<T> = useCallback(\n (newDoc, opts = { replace: false, reset: false }) => {\n if (!newDoc) return void (opts.reset ? setDoc(initialDoc) : refreshDoc());\n setDoc((d) => (opts.replace ? (newDoc as DocWithId<T>) : { ...d, ...newDoc }));\n },\n [refreshDoc, initialDoc],\n );\n\n useEffect(() => {\n if (!docId) return;\n return ledger.subscribe((changes) => {\n if (changes.find((c) => c._id === docId)) {\n void refreshDoc(); // todo use change.value\n }\n });\n }, [docId, refreshDoc]);\n\n useEffect(() => {\n void refreshDoc();\n }, [refreshDoc]);\n\n return [{ _id: docId, ...doc }, updateDoc, saveDoc, deleteDoc];\n }\n\n function useLiveQuery<T extends DocTypes, K extends IndexKeyType = string, R extends DocFragment = T>(\n mapFn: MapFn<T> | string,\n query = {},\n initialRows: IndexRow<K, T, R>[] = [],\n ): LiveQueryResult<T, K, R> {\n const [result, setResult] = useState<LiveQueryResult<T, K, R>>(() => ({\n rows: initialRows,\n docs: initialRows.map((r) => r.doc).filter((r): r is DocWithId<T> => !!r),\n }));\n\n const queryString = useMemo(() => JSON.stringify(query), [query]);\n const mapFnString = useMemo(() => mapFn.toString(), [mapFn]);\n\n const refreshRows = useCallback(async () => {\n const res = await ledger.query<K, T, R>(mapFn, query);\n setResult({ ...res, docs: res.rows.map((r) => r.doc as DocWithId<T>) });\n }, [mapFnString, queryString]);\n\n useEffect(() => {\n refreshRows(); // Initial data fetch\n return ledger.subscribe(refreshRows);\n }, [refreshRows]);\n\n return result;\n }\n\n function useAllDocs<T extends DocTypes>(query: AllDocsQueryOpts = {}): AllDocsResult<T> {\n const [result, setResult] = useState<AllDocsResult<T>>({\n docs: [],\n });\n\n const queryString = useMemo(() => JSON.stringify(query), [query]);\n\n const refreshRows = useCallback(async () => {\n const res = await ledger.allDocs<T>(query);\n setResult({ ...res, docs: res.rows.map((r) => r.value as DocWithId<T>) });\n }, [queryString]);\n\n useEffect(() => {\n refreshRows(); // Initial data fetch\n return ledger.subscribe(refreshRows);\n }, [refreshRows]);\n\n return result;\n }\n\n function useChanges<T extends DocTypes>(since: ClockHead = [], opts: ChangesOptions = {}): ChangesResult<T> {\n const [result, setResult] = useState<ChangesResult<T>>({\n docs: [],\n });\n\n const queryString = useMemo(() => JSON.stringify(opts), [opts]);\n\n const refreshRows = useCallback(async () => {\n const res = await ledger.changes<T>(since, opts);\n setResult({ ...res, docs: res.rows.map((r) => r.value as DocWithId<T>) });\n }, [since, queryString]);\n\n useEffect(() => {\n refreshRows(); // Initial data fetch\n return ledger.subscribe(refreshRows);\n }, [refreshRows]);\n\n return result;\n }\n\n return { ledger, useLiveQuery, useDocument, useAllDocs, useChanges };\n}\n","import { Ledger, DocTypes, DocWithId } from \"@fireproof/core\";\n\nimport { UseDocument, UseDocumentResult, useFireproof } from \"./useFireproof.js\";\n\nexport interface TLUseDocument {\n <T extends DocTypes>(initialDoc: DocWithId<T>): UseDocumentResult<T>;\n ledger: Ledger;\n}\n\nfunction topLevelUseDocument(...args: Parameters<UseDocument>) {\n const { useDocument, ledger } = useFireproof();\n (topLevelUseDocument as TLUseDocument).ledger = ledger;\n return useDocument(...args);\n}\n\n/**\n * ## Summary\n *\n * React hook that provides the ability to create new Fireproof documents. The creation occurs when\n * you do not pass in an `_id` as part of your initial document -- the ledger will assign a new one when\n * you call the provided `save` handler This uses the default ledger named `useFireproof` under the hood which you can also\n * access via the `ledger` accessor.\n *\n * ## Usage\n *\n * ```tsx\n * const [todo, setTodo, saveTodo] = useDocument(() => ({\n * text: '',\n * date: Date.now(),\n * completed: false\n * }))\n *\n * const [doc, setDoc, saveDoc] = useDocument(() => ({\n * _id: `${props.customerId}-profile`, // you can imagine `customerId` as a prop passed in\n * name: \"\",\n * company: \"\",\n * startedAt: Date.now()\n * }))\n *\n * const ledger = useDocument.ledger; // underlying \"useFireproof\" ledger accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useLiveQuery` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\nexport const useDocument = topLevelUseDocument as TLUseDocument;\n","import { Ledger, DocFragment, DocTypes, IndexKeyType } from \"@fireproof/core\";\n\nimport { LiveQueryResult, useFireproof, UseLiveQuery } from \"./useFireproof.js\";\n\nexport interface TLUseLiveQuery {\n <T extends DocTypes, K extends IndexKeyType, R extends DocFragment = T>(\n ...args: Parameters<UseLiveQuery>\n ): LiveQueryResult<T, K, R>;\n ledger: Ledger;\n}\n\nfunction topLevelUseLiveQuery(...args: Parameters<UseLiveQuery>) {\n const { useLiveQuery, ledger } = useFireproof();\n (topLevelUseLiveQuery as TLUseLiveQuery).ledger = ledger;\n return useLiveQuery(...args);\n}\n\n/**\n * ## Summary\n * React hook that provides access to live query results, enabling real-time updates in your app. This uses\n * the default ledger named \"useFireproof\" under the hood which you can also access via the `ledger` accessor.\n *\n * ## Usage\n * ```tsx\n * const results = useLiveQuery(\"date\"); // using string\n * const results = useLiveQuery((doc) => doc.date)); // using map function\n * const ledger = useLiveQuery.ledger; // underlying \"useFireproof\" ledger accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useLiveQuery` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\nexport const useLiveQuery = topLevelUseLiveQuery as TLUseLiveQuery;\n","import { Ledger, DocTypes } from \"@fireproof/core\";\n\nimport { AllDocsResult, useFireproof, UseAllDocs } from \"./useFireproof.js\";\n\nexport interface TLUseAllDocs {\n <T extends DocTypes>(...args: Parameters<UseAllDocs>): AllDocsResult<T>;\n ledger: Ledger;\n}\n\nfunction topLevelUseAllDocs(...args: Parameters<UseAllDocs>) {\n const { useAllDocs, ledger } = useFireproof();\n (topLevelUseAllDocs as TLUseAllDocs).ledger = ledger;\n return useAllDocs(...args);\n}\n\n/**\n * ## Summary\n * React hook that provides access to all documents in the ledger, sorted by `_id`.\n *\n * ## Usage\n * ```tsx\n * const result = useAllDocs({ limit: 10, descending: true }); // with options\n * const result = useAllDocs(); // without options\n * const ledger = useAllDocs.ledger; // underlying \"useFireproof\" ledger accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useAllDocs` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\nexport const useAllDocs = topLevelUseAllDocs as TLUseAllDocs;\n","import { Ledger, DocTypes } from \"@fireproof/core\";\n\nimport { ChangesResult, useFireproof, UseChanges } from \"./useFireproof.js\";\n\nexport interface TLUseChanges {\n <T extends DocTypes>(...args: Parameters<UseChanges>): ChangesResult<T>;\n ledger: Ledger;\n}\n\nfunction topLevelUseChanges(...args: Parameters<UseChanges>) {\n const { useChanges, ledger } = useFireproof();\n (topLevelUseChanges as TLUseChanges).ledger = ledger;\n return useChanges(...args);\n}\n\n/**\n * ## Summary\n * React hook that provides access to all new documents in the ledger added since the last time the changes was called\n *\n * ## Usage\n * ```tsx\n * const result = useChanges(prevresult.clock,{limit:10}); // with options\n * const result = useChanges(); // without options\n * const ledger = useChanges.ledger; // underlying \"useFireproof\" ledger accessor\n * ```\n *\n * ## Overview\n * Changes made via remote sync peers, or other members of your cloud replica group will appear automatically\n * when you use the `useAllDocs`, `useChanges` and `useDocument` APIs. By default, Fireproof stores data in the browser's\n * local storage.\n */\nexport const useChanges = topLevelUseChanges as TLUseChanges;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaA,kBAA0B;AAC1B,mBAA0D;AAoInD,IAAM,eAAe,CAAC;AA0BtB,SAAS,aAAa,OAAwB,gBAAgB,SAAqB,CAAC,GAAiB;AAC1G,QAAM,SAAS,OAAO,SAAS,eAAW,uBAAU,MAAM,MAAM,IAAI;AAEpE,WAASA,aAAgC,gBAAoE;AAC3G,QAAI;AACJ,QAAI,OAAO,mBAAmB,YAAY;AACxC,mBAAa,eAAe;AAAA,IAC9B,OAAO;AACL,mBAAa;AAAA,IACf;AAGA,UAAM,QAAQ,WAAW,OAAO;AAKhC,UAAM,CAAC,KAAK,MAA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AClD,SAAOA,cAAa,GAAG,IAAI;AAC7B;AAmBO,IAAM,eAAe;;;ACzB5B,SAAS,sBAAsB,MAA8B;AAC3D,QAAM,EAAE,YAAAC,aAAY,OAAO,IAAI,aAAa;AAC5C,EAAC,mBAAoC,SAAS;AAC9C,SAAOA,YAAW,GAAG,IAAI;AAC3B;AAkBO,IAAM,aAAa;;;ACtB1B,SAAS,sBAAsB,MAA8B;AAC3D,QAAM,EAAE,YAAAC,aAAY,OAAO,IAAI,aAAa;AAC5C,EAAC,mBAAoC,SAAS;AAC9C,SAAOA,YAAW,GAAG,IAAI;AAC3B;AAkBO,IAAM,aAAa;","names":["useDocument","doc","useLiveQuery","useAllDocs","useChanges","useDocument","useLiveQuery","useAllDocs","useChanges"]}
|
package/react/index.d.cts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Ledger, ConfigOpts, DocTypes, IndexKeyType, DocFragment, DocWithId, IndexRow, MapFn, QueryOpts, AllDocsQueryOpts, ClockHead, ChangesOptions, DocSet, DocResponse } from '@fireproof/core';
|
2
2
|
|
3
3
|
interface LiveQueryResult<T extends DocTypes, K extends IndexKeyType, R extends DocFragment = T> {
|
4
4
|
readonly docs: DocWithId<T>[];
|
@@ -24,36 +24,36 @@ type UseDocumentResult<T extends DocTypes> = [DocWithId<T>, UpdateDocFn<T>, Stor
|
|
24
24
|
type UseDocumentInitialDocOrFn<T extends DocTypes> = DocSet<T> | (() => DocSet<T>);
|
25
25
|
type UseDocument = <T extends DocTypes>(initialDocOrFn: UseDocumentInitialDocOrFn<T>) => UseDocumentResult<T>;
|
26
26
|
interface UseFireproof {
|
27
|
-
readonly
|
27
|
+
readonly ledger: Ledger;
|
28
28
|
readonly useDocument: UseDocument;
|
29
29
|
readonly useLiveQuery: UseLiveQuery;
|
30
30
|
readonly useAllDocs: UseAllDocs;
|
31
31
|
readonly useChanges: UseChanges;
|
32
32
|
}
|
33
33
|
declare const FireproofCtx: UseFireproof;
|
34
|
-
declare function useFireproof(name?: string |
|
34
|
+
declare function useFireproof(name?: string | Ledger, config?: ConfigOpts): UseFireproof;
|
35
35
|
|
36
36
|
interface TLUseDocument {
|
37
37
|
<T extends DocTypes>(initialDoc: DocWithId<T>): UseDocumentResult<T>;
|
38
|
-
|
38
|
+
ledger: Ledger;
|
39
39
|
}
|
40
40
|
declare const useDocument: TLUseDocument;
|
41
41
|
|
42
42
|
interface TLUseLiveQuery {
|
43
43
|
<T extends DocTypes, K extends IndexKeyType, R extends DocFragment = T>(...args: Parameters<UseLiveQuery>): LiveQueryResult<T, K, R>;
|
44
|
-
|
44
|
+
ledger: Ledger;
|
45
45
|
}
|
46
46
|
declare const useLiveQuery: TLUseLiveQuery;
|
47
47
|
|
48
48
|
interface TLUseAllDocs {
|
49
49
|
<T extends DocTypes>(...args: Parameters<UseAllDocs>): AllDocsResult<T>;
|
50
|
-
|
50
|
+
ledger: Ledger;
|
51
51
|
}
|
52
52
|
declare const useAllDocs: TLUseAllDocs;
|
53
53
|
|
54
54
|
interface TLUseChanges {
|
55
55
|
<T extends DocTypes>(...args: Parameters<UseChanges>): ChangesResult<T>;
|
56
|
-
|
56
|
+
ledger: Ledger;
|
57
57
|
}
|
58
58
|
declare const useChanges: TLUseChanges;
|
59
59
|
|
package/react/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Ledger, ConfigOpts, DocTypes, IndexKeyType, DocFragment, DocWithId, IndexRow, MapFn, QueryOpts, AllDocsQueryOpts, ClockHead, ChangesOptions, DocSet, DocResponse } from '@fireproof/core';
|
2
2
|
|
3
3
|
interface LiveQueryResult<T extends DocTypes, K extends IndexKeyType, R extends DocFragment = T> {
|
4
4
|
readonly docs: DocWithId<T>[];
|
@@ -24,36 +24,36 @@ type UseDocumentResult<T extends DocTypes> = [DocWithId<T>, UpdateDocFn<T>, Stor
|
|
24
24
|
type UseDocumentInitialDocOrFn<T extends DocTypes> = DocSet<T> | (() => DocSet<T>);
|
25
25
|
type UseDocument = <T extends DocTypes>(initialDocOrFn: UseDocumentInitialDocOrFn<T>) => UseDocumentResult<T>;
|
26
26
|
interface UseFireproof {
|
27
|
-
readonly
|
27
|
+
readonly ledger: Ledger;
|
28
28
|
readonly useDocument: UseDocument;
|
29
29
|
readonly useLiveQuery: UseLiveQuery;
|
30
30
|
readonly useAllDocs: UseAllDocs;
|
31
31
|
readonly useChanges: UseChanges;
|
32
32
|
}
|
33
33
|
declare const FireproofCtx: UseFireproof;
|
34
|
-
declare function useFireproof(name?: string |
|
34
|
+
declare function useFireproof(name?: string | Ledger, config?: ConfigOpts): UseFireproof;
|
35
35
|
|
36
36
|
interface TLUseDocument {
|
37
37
|
<T extends DocTypes>(initialDoc: DocWithId<T>): UseDocumentResult<T>;
|
38
|
-
|
38
|
+
ledger: Ledger;
|
39
39
|
}
|
40
40
|
declare const useDocument: TLUseDocument;
|
41
41
|
|
42
42
|
interface TLUseLiveQuery {
|
43
43
|
<T extends DocTypes, K extends IndexKeyType, R extends DocFragment = T>(...args: Parameters<UseLiveQuery>): LiveQueryResult<T, K, R>;
|
44
|
-
|
44
|
+
ledger: Ledger;
|
45
45
|
}
|
46
46
|
declare const useLiveQuery: TLUseLiveQuery;
|
47
47
|
|
48
48
|
interface TLUseAllDocs {
|
49
49
|
<T extends DocTypes>(...args: Parameters<UseAllDocs>): AllDocsResult<T>;
|
50
|
-
|
50
|
+
ledger: Ledger;
|
51
51
|
}
|
52
52
|
declare const useAllDocs: TLUseAllDocs;
|
53
53
|
|
54
54
|
interface TLUseChanges {
|
55
55
|
<T extends DocTypes>(...args: Parameters<UseChanges>): ChangesResult<T>;
|
56
|
-
|
56
|
+
ledger: Ledger;
|
57
57
|
}
|
58
58
|
declare const useChanges: TLUseChanges;
|
59
59
|
|