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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +3 -2
  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 +1819 -1051
  8. package/index.cjs.map +1 -1
  9. package/index.d.cts +746 -333
  10. package/index.d.ts +746 -333
  11. package/index.js +1792 -1026
  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 +12 -4
  24. package/react/index.cjs.map +1 -1
  25. package/react/index.js.map +1 -1
  26. package/react/metafile-cjs.json +1 -1
  27. package/react/metafile-esm.json +1 -1
  28. package/tests/blockstore/fp-envelope.test.ts-off +65 -0
  29. package/tests/blockstore/interceptor-gateway.test.ts +122 -0
  30. package/tests/blockstore/keyed-crypto-indexdb-file.test.ts +130 -0
  31. package/tests/blockstore/keyed-crypto.test.ts +73 -118
  32. package/tests/blockstore/loader.test.ts +18 -9
  33. package/tests/blockstore/store.test.ts +40 -31
  34. package/tests/blockstore/transaction.test.ts +14 -13
  35. package/tests/fireproof/all-gateway.test.ts +283 -213
  36. package/tests/fireproof/cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.ts +324 -316
  37. package/tests/fireproof/crdt.test.ts +78 -19
  38. package/tests/fireproof/database.test.ts +225 -29
  39. package/tests/fireproof/fireproof.test.ts +92 -73
  40. package/tests/fireproof/hello.test.ts +17 -13
  41. package/tests/fireproof/indexer.test.ts +67 -43
  42. package/tests/fireproof/utils.test.ts +47 -6
  43. package/tests/gateway/file/loader-config.test.ts +307 -0
  44. package/tests/gateway/fp-envelope-serialize.test.ts +256 -0
  45. package/tests/gateway/indexdb/loader-config.test.ts +79 -0
  46. package/tests/helpers.ts +44 -17
  47. package/tests/react/useFireproof.test.tsx +1 -1
  48. package/tests/www/todo.html +24 -3
  49. package/web/index.cjs +102 -116
  50. package/web/index.cjs.map +1 -1
  51. package/web/index.d.cts +15 -29
  52. package/web/index.d.ts +15 -29
  53. package/web/index.js +91 -105
  54. package/web/index.js.map +1 -1
  55. package/web/metafile-cjs.json +1 -1
  56. package/web/metafile-esm.json +1 -1
  57. package/node/chunk-4A4RAVNS.js +0 -17
  58. package/node/chunk-4A4RAVNS.js.map +0 -1
  59. package/node/mem-filesystem-LPPT7QV5.js +0 -40
  60. package/node/mem-filesystem-LPPT7QV5.js.map +0 -1
  61. package/tests/fireproof/config.test.ts +0 -163
  62. /package/tests/blockstore/{fragment-gateway.test.ts → fragment-gateway.test.ts-off} +0 -0
  63. /package/tests/fireproof/{multiple-ledger.test.ts → multiple-database.test.ts} +0 -0
package/node/index.js CHANGED
@@ -1,12 +1,15 @@
1
- import {
2
- toArrayBuffer
3
- } from "./chunk-4A4RAVNS.js";
4
-
5
- // src/runtime/gateways/file/node/key-bag-file.ts
6
- import { isNotFoundError } from "@fireproof/core";
7
-
8
- // src/runtime/gateways/file/node/get-file-system.ts
9
- import { KeyedResolvOnce } from "@adviser/cement";
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
+ }
10
13
 
11
14
  // src/runtime/gateways/file/node/node-filesystem.ts
12
15
  import { runtimeFn } from "@adviser/cement";
@@ -45,235 +48,17 @@ var NodeFileSystem = class {
45
48
  }
46
49
  };
47
50
 
48
- // src/runtime/gateways/file/node/get-file-system.ts
49
- var externalLoaders = new KeyedResolvOnce();
50
- async function getFileSystem(url) {
51
- const name = url.getParam("fs", "node");
52
- let fs;
53
- switch (name) {
54
- case "mem":
55
- fs = await externalLoaders.get(name).once(async () => {
56
- const { MemFileSystem } = await import("./mem-filesystem-LPPT7QV5.js");
57
- return new MemFileSystem();
58
- });
59
- break;
60
- // case 'deno': {
61
- // const { DenoFileSystem } = await import("./deno-filesystem.js");
62
- // fs = new DenoFileSystem();
63
- // break;
64
- // }
65
- default:
66
- fs = await externalLoaders.get(name).once(async () => {
67
- return new NodeFileSystem();
68
- });
69
- }
70
- return fs.start();
71
- }
72
-
73
- // src/runtime/gateways/file/node/key-bag-file.ts
74
- var KeyBagProviderFile = class {
75
- async _prepare(id) {
76
- await this.sthis.start();
77
- let sysFS;
78
- switch (this.url.protocol) {
79
- case "file:": {
80
- sysFS = await getFileSystem(this.url);
81
- break;
82
- }
83
- default:
84
- throw this.logger.Error().Url(this.url).Msg("unsupported protocol").AsError();
85
- }
86
- const dirName = this.url.pathname;
87
- await sysFS.mkdir(dirName, { recursive: true });
88
- return {
89
- dirName,
90
- sysFS,
91
- fName: this.sthis.pathOps.join(dirName, `${id.replace(/[^a-zA-Z0-9]/g, "_")}.json`)
92
- };
93
- }
94
- constructor(url, sthis) {
95
- this.url = url;
96
- this.sthis = sthis;
97
- this.logger = sthis.logger;
98
- }
99
- async get(id) {
100
- const ctx = await this._prepare(id);
101
- try {
102
- const p = await ctx.sysFS.readfile(ctx.fName);
103
- const ki = JSON.parse(this.sthis.txt.decode(p));
104
- return ki;
105
- } catch (e) {
106
- if (isNotFoundError(e)) {
107
- return void 0;
108
- }
109
- throw this.logger.Error().Err(e).Str("file", ctx.dirName).Msg("read bag failed").AsError();
110
- }
111
- }
112
- async set(id, item) {
113
- const ctx = await this._prepare(id);
114
- const p = this.sthis.txt.encode(JSON.stringify(item, null, 2));
115
- await ctx.sysFS.writefile(ctx.fName, p);
116
- }
117
- };
118
-
119
- // src/runtime/gateways/file/version.ts
120
- var FILESTORE_VERSION = "v0.19-file";
121
-
122
- // src/runtime/gateways/file/node/gateway-impl.ts
123
- import { exception2Result, KeyedResolvOnce as KeyedResolvOnce2, Result } from "@adviser/cement";
124
- import { ensureLogger, exceptionWrapper, isNotFoundError as isNotFoundError2, NotFoundError } from "@fireproof/core";
125
-
126
- // src/runtime/gateways/file/node/utils.ts
127
- import { getStore } from "@fireproof/core";
128
- function getPath(url, sthis) {
129
- const basePath = url.pathname;
130
- const name = url.getParam("name");
131
- if (name) {
132
- const version = url.getParam("version");
133
- if (!version) throw sthis.logger.Error().Url(url).Msg(`version not found`).AsError();
134
- return sthis.pathOps.join(basePath, version, name);
135
- }
136
- return sthis.pathOps.join(basePath);
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
+ });
137
60
  }
138
- function getFileName(url, sthis) {
139
- const key = url.getParam("key");
140
- if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
141
- const res = getStore(url, sthis, (...a) => a.join("-"));
142
- switch (res.store) {
143
- case "data":
144
- return sthis.pathOps.join(res.name, key + ".car");
145
- case "wal":
146
- case "meta":
147
- return sthis.pathOps.join(res.name, key + ".json");
148
- default:
149
- throw sthis.logger.Error().Url(url).Msg(`unsupported store type`).AsError();
150
- }
151
- }
152
-
153
- // src/runtime/gateways/file/node/gateway-impl.ts
154
- var versionFiles = new KeyedResolvOnce2();
155
- var FileGateway = class {
156
- constructor(sthis) {
157
- this.sthis = sthis;
158
- this.logger = sthis.logger;
159
- }
160
- async getVersionFromFile(fs, path, logger) {
161
- return versionFiles.get(path).once(async () => {
162
- await fs.mkdir(path, { recursive: true });
163
- const vFile = this.sthis.pathOps.join(path, "version");
164
- const vFileStat = await fs.stat(vFile).catch(() => void 0);
165
- if (!vFileStat) {
166
- await fs.writefile(this.sthis.pathOps.join(path, "version"), FILESTORE_VERSION);
167
- return FILESTORE_VERSION;
168
- } else if (!vFileStat.isFile()) {
169
- throw logger.Error().Str("file", vFile).Msg(`version file is a directory`).AsError();
170
- }
171
- const v = await fs.readfile(vFile);
172
- const vStr = this.sthis.txt.decode(v);
173
- if (vStr !== FILESTORE_VERSION) {
174
- logger.Warn().Str("file", vFile).Str("from", vStr).Str("expected", FILESTORE_VERSION).Msg(`version mismatch`);
175
- }
176
- return vStr;
177
- });
178
- }
179
- start(baseURL) {
180
- return exception2Result(async () => {
181
- const fs = await getFileSystem(baseURL);
182
- const url = baseURL.build();
183
- url.defParam("version", FILESTORE_VERSION);
184
- const dbUrl = await this.buildUrl(url.URI(), "dummy");
185
- const dbdirFile = this.getFilePath(dbUrl.Ok());
186
- await fs.mkdir(this.sthis.pathOps.dirname(dbdirFile), { recursive: true });
187
- const dbroot = this.sthis.pathOps.dirname(dbdirFile);
188
- this.logger.Debug().Url(url.URI()).Str("dbroot", dbroot).Msg("start");
189
- url.setParam("version", await this.getVersionFromFile(fs, dbroot, this.logger));
190
- return url.URI();
191
- });
192
- }
193
- async buildUrl(baseUrl, key) {
194
- return Result.Ok(baseUrl.build().setParam("key", key).URI());
195
- }
196
- async close() {
197
- return Result.Ok(void 0);
198
- }
199
- // abstract buildUrl(baseUrl: URL, key: string): Promise<Result<URL>>;
200
- getFilePath(url) {
201
- const key = url.getParam("key");
202
- if (!key) throw this.logger.Error().Url(url).Msg(`key not found`).AsError();
203
- return this.sthis.pathOps.join(getPath(url, this.sthis), getFileName(url, this.sthis));
204
- }
205
- async put(url, body) {
206
- return exception2Result(async () => {
207
- const file = await this.getFilePath(url);
208
- this.logger.Debug().Str("url", url.toString()).Str("file", file).Msg("put");
209
- await getFileSystem(url).then((fs) => fs.writefile(file, body));
210
- });
211
- }
212
- async get(url) {
213
- return exceptionWrapper(async () => {
214
- const file = this.getFilePath(url);
215
- try {
216
- const res = await getFileSystem(url).then((fs) => fs.readfile(file));
217
- this.logger.Debug().Url(url.asURL()).Str("file", file).Msg("get");
218
- return Result.Ok(new Uint8Array(res));
219
- } catch (e) {
220
- if (isNotFoundError2(e)) {
221
- return Result.Err(new NotFoundError(`file not found: ${file}`));
222
- }
223
- return Result.Err(e);
224
- }
225
- });
226
- }
227
- async delete(url) {
228
- return exception2Result(async () => {
229
- await getFileSystem(url).then((fs) => fs.unlink(this.getFilePath(url)));
230
- });
231
- }
232
- async destroy(baseURL) {
233
- const url = await this.buildUrl(baseURL, "x");
234
- if (url.isErr()) return url;
235
- const filepath = this.sthis.pathOps.dirname(this.getFilePath(url.Ok()));
236
- const fs = await getFileSystem(baseURL);
237
- let files = [];
238
- try {
239
- files = await fs.readdir(filepath);
240
- } catch (e) {
241
- if (!isNotFoundError2(e)) {
242
- throw this.logger.Error().Err(e).Str("dir", filepath).Msg("destroy:readdir").AsError();
243
- }
244
- }
245
- for (const file of files) {
246
- const pathed = this.sthis.pathOps.join(filepath, file);
247
- try {
248
- await fs.unlink(pathed);
249
- } catch (e) {
250
- if (!isNotFoundError2(e)) {
251
- throw this.logger.Error().Err(e).Str("file", pathed).Msg("destroy:unlink").AsError();
252
- }
253
- }
254
- }
255
- return Result.Ok(void 0);
256
- }
257
- };
258
- var FileTestGateway = class {
259
- constructor(sthis) {
260
- this.logger = ensureLogger(sthis, "FileTestStore");
261
- this.sthis = sthis;
262
- }
263
- async get(iurl, key) {
264
- const url = iurl.build().setParam("key", key).URI();
265
- const dbFile = this.sthis.pathOps.join(getPath(url, this.sthis), getFileName(url, this.sthis));
266
- this.logger.Debug().Url(url).Str("dbFile", dbFile).Msg("get");
267
- const buffer = await (await getFileSystem(url)).readfile(dbFile);
268
- this.logger.Debug().Url(url).Str("dbFile", dbFile).Len(buffer).Msg("got");
269
- return buffer;
270
- }
271
- };
272
61
  export {
273
- FileGateway as GatewayImpl,
274
- FileTestGateway as GatewayTestImpl,
275
- KeyBagProviderFile,
276
- KeyBagProviderFile as KeyBagProviderImpl,
277
- getFileSystem
62
+ getSysFileSystem
278
63
  };
279
64
  //# sourceMappingURL=index.js.map
package/node/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/gateways/file/node/key-bag-file.ts","../../../src/runtime/gateways/file/node/get-file-system.ts","../../../src/runtime/gateways/file/node/node-filesystem.ts","../../../src/runtime/gateways/file/version.ts","../../../src/runtime/gateways/file/node/gateway-impl.ts","../../../src/runtime/gateways/file/node/utils.ts"],"sourcesContent":["import { URI } from \"@adviser/cement\";\nimport { isNotFoundError, Logger } from \"@fireproof/core\";\nimport type { rt, SuperThis, SysFileSystem } from \"@fireproof/core\";\nimport { getFileSystem } from \"./get-file-system.js\";\n\ninterface KeyBagCtx {\n readonly dirName: string;\n readonly sysFS: SysFileSystem;\n readonly fName: string;\n}\n\nexport class KeyBagProviderFile implements rt.kb.KeyBagProvider {\n async _prepare(id: string): Promise<KeyBagCtx> {\n await this.sthis.start();\n let sysFS: SysFileSystem;\n switch (this.url.protocol) {\n case \"file:\": {\n sysFS = await getFileSystem(this.url);\n break;\n }\n default:\n throw this.logger.Error().Url(this.url).Msg(\"unsupported protocol\").AsError();\n }\n const dirName = this.url.pathname;\n await sysFS.mkdir(dirName, { recursive: true });\n return {\n dirName,\n sysFS,\n fName: this.sthis.pathOps.join(dirName, `${id.replace(/[^a-zA-Z0-9]/g, \"_\")}.json`),\n };\n }\n\n private readonly url: URI;\n readonly logger: Logger;\n readonly sthis: SuperThis;\n constructor(url: URI, sthis: SuperThis) {\n this.url = url;\n this.sthis = sthis;\n this.logger = sthis.logger;\n }\n\n async get(id: string): Promise<rt.kb.KeyItem | undefined> {\n const ctx = await this._prepare(id);\n try {\n const p = await ctx.sysFS.readfile(ctx.fName);\n const ki = JSON.parse(this.sthis.txt.decode(p)) as rt.kb.KeyItem;\n return ki;\n } catch (e) {\n if (isNotFoundError(e)) {\n return undefined;\n }\n throw this.logger.Error().Err(e).Str(\"file\", ctx.dirName).Msg(\"read bag failed\").AsError();\n }\n }\n\n async set(id: string, item: rt.kb.KeyItem): Promise<void> {\n const ctx = await this._prepare(id);\n const p = this.sthis.txt.encode(JSON.stringify(item, null, 2));\n await ctx.sysFS.writefile(ctx.fName, p);\n }\n}\n","import { KeyedResolvOnce, type URI } from \"@adviser/cement\";\nimport type { SysFileSystem } from \"@fireproof/core\";\nimport { NodeFileSystem } from \"./node-filesystem.js\";\n\nconst externalLoaders = new KeyedResolvOnce<SysFileSystem>();\nexport async function getFileSystem(url: URI): Promise<SysFileSystem> {\n const name = url.getParam(\"fs\", \"node\");\n let fs: SysFileSystem;\n switch (name) {\n case \"mem\":\n fs = await externalLoaders.get(name).once(async () => {\n const { MemFileSystem } = await import(\"./mem-filesystem.js\");\n return new MemFileSystem();\n });\n break;\n // case 'deno': {\n // const { DenoFileSystem } = await import(\"./deno-filesystem.js\");\n // fs = new DenoFileSystem();\n // break;\n // }\n default:\n fs = await externalLoaders.get(name).once(async () => {\n return new NodeFileSystem();\n });\n }\n return fs.start();\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","export const FILESTORE_VERSION = \"v0.19-file\";\n","import { FILESTORE_VERSION } from \"../version.js\";\nimport { exception2Result, KeyedResolvOnce, Logger, Result, URI } from \"@adviser/cement\";\nimport { ensureLogger, exceptionWrapper, isNotFoundError, NotFoundError, bs } from \"@fireproof/core\";\nimport { getFileName, getPath } from \"./utils.js\";\nimport type { SuperThis, SysFileSystem } from \"@fireproof/core\";\nimport { getFileSystem } from \"./get-file-system.js\";\n\nconst versionFiles = new KeyedResolvOnce<string>();\n\nexport class FileGateway implements bs.Gateway {\n // abstract readonly storeType: StoreType;\n readonly logger: Logger;\n readonly sthis: SuperThis;\n\n constructor(sthis: SuperThis) {\n this.sthis = sthis;\n this.logger = sthis.logger;\n }\n\n async getVersionFromFile(fs: SysFileSystem, path: string, logger: Logger): Promise<string> {\n return versionFiles.get(path).once(async () => {\n await fs.mkdir(path, { recursive: true });\n const vFile = this.sthis.pathOps.join(path, \"version\");\n const vFileStat = await fs.stat(vFile).catch(() => undefined);\n if (!vFileStat) {\n await fs.writefile(this.sthis.pathOps.join(path, \"version\"), FILESTORE_VERSION);\n return FILESTORE_VERSION;\n } else if (!vFileStat.isFile()) {\n throw logger.Error().Str(\"file\", vFile).Msg(`version file is a directory`).AsError();\n }\n const v = await fs.readfile(vFile);\n const vStr = this.sthis.txt.decode(v);\n if (vStr !== FILESTORE_VERSION) {\n logger.Warn().Str(\"file\", vFile).Str(\"from\", vStr).Str(\"expected\", FILESTORE_VERSION).Msg(`version mismatch`);\n }\n return vStr;\n });\n }\n\n start(baseURL: URI): Promise<Result<URI>> {\n return exception2Result(async () => {\n const fs = await getFileSystem(baseURL);\n const url = baseURL.build();\n url.defParam(\"version\", FILESTORE_VERSION);\n // url.defParam(\"store\", this.storeType);\n const dbUrl = await this.buildUrl(url.URI(), \"dummy\");\n const dbdirFile = this.getFilePath(dbUrl.Ok());\n await fs.mkdir(this.sthis.pathOps.dirname(dbdirFile), { recursive: true });\n const dbroot = this.sthis.pathOps.dirname(dbdirFile);\n this.logger.Debug().Url(url.URI()).Str(\"dbroot\", dbroot).Msg(\"start\");\n url.setParam(\"version\", await this.getVersionFromFile(fs, dbroot, this.logger));\n return url.URI();\n });\n }\n\n async buildUrl(baseUrl: URI, key: string): Promise<Result<URI>> {\n return Result.Ok(baseUrl.build().setParam(\"key\", key).URI());\n }\n\n async close(): Promise<Result<void>> {\n return Result.Ok(undefined);\n }\n // abstract buildUrl(baseUrl: URL, key: string): Promise<Result<URL>>;\n\n getFilePath(url: URI): string {\n const key = url.getParam(\"key\");\n if (!key) throw this.logger.Error().Url(url).Msg(`key not found`).AsError();\n return this.sthis.pathOps.join(getPath(url, this.sthis), getFileName(url, this.sthis));\n }\n\n async put(url: URI, body: Uint8Array): Promise<Result<void>> {\n return exception2Result(async () => {\n const file = await this.getFilePath(url);\n this.logger.Debug().Str(\"url\", url.toString()).Str(\"file\", file).Msg(\"put\");\n await getFileSystem(url).then((fs) => fs.writefile(file, body));\n });\n }\n\n async get(url: URI): Promise<bs.GetResult> {\n return exceptionWrapper(async () => {\n const file = this.getFilePath(url);\n try {\n const res = await getFileSystem(url).then((fs) => fs.readfile(file));\n this.logger.Debug().Url(url.asURL()).Str(\"file\", file).Msg(\"get\");\n return Result.Ok(new Uint8Array(res));\n } catch (e: unknown) {\n // this.logger.Error().Err(e).Str(\"file\", file).Msg(\"get\");\n if (isNotFoundError(e)) {\n return Result.Err(new NotFoundError(`file not found: ${file}`));\n }\n return Result.Err(e as Error);\n }\n });\n }\n\n async delete(url: URI): Promise<Result<void>> {\n return exception2Result(async () => {\n await getFileSystem(url).then((fs) => fs.unlink(this.getFilePath(url)));\n });\n }\n\n async destroy(baseURL: URI): Promise<Result<void>> {\n const url = await this.buildUrl(baseURL, \"x\");\n if (url.isErr()) return url;\n const filepath = this.sthis.pathOps.dirname(this.getFilePath(url.Ok()));\n const fs = await getFileSystem(baseURL);\n let files: string[] = [];\n try {\n files = await fs.readdir(filepath);\n } catch (e: unknown) {\n if (!isNotFoundError(e)) {\n throw this.logger.Error().Err(e).Str(\"dir\", filepath).Msg(\"destroy:readdir\").AsError();\n }\n }\n for (const file of files) {\n const pathed = this.sthis.pathOps.join(filepath, file);\n try {\n await fs.unlink(pathed);\n } catch (e: unknown) {\n if (!isNotFoundError(e)) {\n throw this.logger.Error().Err(e).Str(\"file\", pathed).Msg(\"destroy:unlink\").AsError();\n }\n }\n }\n return Result.Ok(undefined);\n }\n}\n\nexport class FileTestGateway implements bs.TestGateway {\n readonly logger: Logger;\n readonly sthis: SuperThis;\n constructor(sthis: SuperThis) {\n this.logger = ensureLogger(sthis, \"FileTestStore\");\n this.sthis = sthis;\n }\n\n async get(iurl: URI, key: string) {\n const url = iurl.build().setParam(\"key\", key).URI();\n const dbFile = this.sthis.pathOps.join(getPath(url, this.sthis), getFileName(url, this.sthis));\n this.logger.Debug().Url(url).Str(\"dbFile\", dbFile).Msg(\"get\");\n const buffer = await (await getFileSystem(url)).readfile(dbFile);\n this.logger.Debug().Url(url).Str(\"dbFile\", dbFile).Len(buffer).Msg(\"got\");\n return buffer;\n }\n}\n","import type { URI } from \"@adviser/cement\";\nimport { getStore } from \"@fireproof/core\";\nimport type { SuperThis } from \"@fireproof/core\";\n\nexport function getPath(url: URI, sthis: SuperThis): string {\n const basePath = url.pathname;\n // .toString()\n // .replace(new RegExp(`^${url.protocol}//`), \"\")\n // .replace(/\\?.*$/, \"\");\n const name = url.getParam(\"name\");\n if (name) {\n const version = url.getParam(\"version\");\n if (!version) throw sthis.logger.Error().Url(url).Msg(`version not found`).AsError();\n return sthis.pathOps.join(basePath, version, name);\n }\n return sthis.pathOps.join(basePath);\n}\n\nexport function getFileName(url: URI, sthis: SuperThis): string {\n const key = url.getParam(\"key\");\n if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();\n const res = getStore(url, sthis, (...a: string[]) => a.join(\"-\"));\n switch (res.store) {\n case \"data\":\n return sthis.pathOps.join(res.name, key + \".car\");\n case \"wal\":\n case \"meta\":\n return sthis.pathOps.join(res.name, key + \".json\");\n default:\n throw sthis.logger.Error().Url(url).Msg(`unsupported store type`).AsError();\n }\n}\n"],"mappings":";;;;;AACA,SAAS,uBAA+B;;;ACDxC,SAAS,uBAAiC;;;ACI1C,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;;;AD9CA,IAAM,kBAAkB,IAAI,gBAA+B;A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KeyedResolvOnce","isNotFoundError","KeyedResolvOnce","isNotFoundError"]}
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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AAwB;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"]}
@@ -1 +1 @@
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/mem-filesystem.ts":{"bytes":1461,"imports":[{"path":"memfs","kind":"import-statement","external":true},{"path":"memfs/lib/node/types/options.js","kind":"import-statement","external":true},{"path":"src/runtime/gateways/file/node/to-array-buffer.ts","kind":"import-statement","original":"./to-array-buffer.js"}],"format":"esm"},"src/runtime/gateways/file/node/get-file-system.ts":{"bytes":905,"imports":[{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"src/runtime/gateways/file/node/node-filesystem.ts","kind":"import-statement","original":"./node-filesystem.js"},{"path":"src/runtime/gateways/file/node/mem-filesystem.ts","kind":"dynamic-import","original":"./mem-filesystem.js"}],"format":"esm"},"src/runtime/gateways/file/node/key-bag-file.ts":{"bytes":1860,"imports":[{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/runtime/gateways/file/node/get-file-system.ts","kind":"import-statement","original":"./get-file-system.js"}],"format":"esm"},"src/runtime/gateways/file/version.ts":{"bytes":47,"imports":[],"format":"esm"},"src/runtime/gateways/file/node/utils.ts":{"bytes":1159,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true}],"format":"esm"},"src/runtime/gateways/file/node/gateway-impl.ts":{"bytes":5551,"imports":[{"path":"src/runtime/gateways/file/version.ts","kind":"import-statement","original":"../version.js"},{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/runtime/gateways/file/node/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"src/runtime/gateways/file/node/get-file-system.ts","kind":"import-statement","original":"./get-file-system.js"}],"format":"esm"},"src/runtime/gateways/file/node/index.ts":{"bytes":346,"imports":[{"path":"src/runtime/gateways/file/node/key-bag-file.ts","kind":"import-statement","original":"./key-bag-file.js"},{"path":"src/runtime/gateways/file/node/get-file-system.ts","kind":"import-statement","original":"./get-file-system.js"},{"path":"src/runtime/gateways/file/node/key-bag-file.ts","kind":"import-statement","original":"./key-bag-file.js"},{"path":"src/runtime/gateways/file/node/gateway-impl.ts","kind":"import-statement","original":"./gateway-impl.js"}],"format":"esm"}},"outputs":{"dist/fireproof-core/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":24401},"dist/fireproof-core/node/index.cjs":{"imports":[{"path":"memfs","kind":"require-call","external":true},{"path":"@fireproof/core","kind":"require-call","external":true},{"path":"@adviser/cement","kind":"require-call","external":true},{"path":"@adviser/cement","kind":"require-call","external":true},{"path":"fs/promises","kind":"dynamic-import","external":true},{"path":"@adviser/cement","kind":"require-call","external":true},{"path":"@fireproof/core","kind":"require-call","external":true},{"path":"@fireproof/core","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/runtime/gateways/file/node/index.ts","inputs":{"src/runtime/gateways/file/node/to-array-buffer.ts":{"bytesInOutput":396},"src/runtime/gateways/file/node/mem-filesystem.ts":{"bytesInOutput":1255},"src/runtime/gateways/file/node/index.ts":{"bytesInOutput":309},"src/runtime/gateways/file/node/key-bag-file.ts":{"bytesInOutput":1307},"src/runtime/gateways/file/node/get-file-system.ts":{"bytesInOutput":799},"src/runtime/gateways/file/node/node-filesystem.ts":{"bytesInOutput":939},"src/runtime/gateways/file/version.ts":{"bytesInOutput":38},"src/runtime/gateways/file/node/gateway-impl.ts":{"bytesInOutput":4814},"src/runtime/gateways/file/node/utils.ts":{"bytesInOutput":915}},"bytes":12889}}}
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}}}
@@ -1 +1 @@
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/mem-filesystem.ts":{"bytes":1461,"imports":[{"path":"memfs","kind":"import-statement","external":true},{"path":"memfs/lib/node/types/options.js","kind":"import-statement","external":true},{"path":"src/runtime/gateways/file/node/to-array-buffer.ts","kind":"import-statement","original":"./to-array-buffer.js"}],"format":"esm"},"src/runtime/gateways/file/node/get-file-system.ts":{"bytes":905,"imports":[{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"src/runtime/gateways/file/node/node-filesystem.ts","kind":"import-statement","original":"./node-filesystem.js"},{"path":"src/runtime/gateways/file/node/mem-filesystem.ts","kind":"dynamic-import","original":"./mem-filesystem.js"}],"format":"esm"},"src/runtime/gateways/file/node/key-bag-file.ts":{"bytes":1860,"imports":[{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/runtime/gateways/file/node/get-file-system.ts","kind":"import-statement","original":"./get-file-system.js"}],"format":"esm"},"src/runtime/gateways/file/version.ts":{"bytes":47,"imports":[],"format":"esm"},"src/runtime/gateways/file/node/utils.ts":{"bytes":1159,"imports":[{"path":"@fireproof/core","kind":"import-statement","external":true}],"format":"esm"},"src/runtime/gateways/file/node/gateway-impl.ts":{"bytes":5551,"imports":[{"path":"src/runtime/gateways/file/version.ts","kind":"import-statement","original":"../version.js"},{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"src/runtime/gateways/file/node/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"src/runtime/gateways/file/node/get-file-system.ts","kind":"import-statement","original":"./get-file-system.js"}],"format":"esm"},"src/runtime/gateways/file/node/index.ts":{"bytes":346,"imports":[{"path":"src/runtime/gateways/file/node/key-bag-file.ts","kind":"import-statement","original":"./key-bag-file.js"},{"path":"src/runtime/gateways/file/node/get-file-system.ts","kind":"import-statement","original":"./get-file-system.js"},{"path":"src/runtime/gateways/file/node/key-bag-file.ts","kind":"import-statement","original":"./key-bag-file.js"},{"path":"src/runtime/gateways/file/node/gateway-impl.ts","kind":"import-statement","original":"./gateway-impl.js"}],"format":"esm"}},"outputs":{"dist/fireproof-core/node/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":20876},"dist/fireproof-core/node/index.js":{"imports":[{"path":"dist/fireproof-core/node/chunk-4A4RAVNS.js","kind":"import-statement"},{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"dynamic-import","external":true},{"path":"dist/fireproof-core/node/mem-filesystem-LPPT7QV5.js","kind":"dynamic-import"},{"path":"@adviser/cement","kind":"import-statement","external":true},{"path":"@fireproof/core","kind":"import-statement","external":true},{"path":"@fireproof/core","kind":"import-statement","external":true}],"exports":["GatewayImpl","GatewayTestImpl","KeyBagProviderFile","KeyBagProviderImpl","getFileSystem"],"entryPoint":"src/runtime/gateways/file/node/index.ts","inputs":{"src/runtime/gateways/file/node/key-bag-file.ts":{"bytesInOutput":1295},"src/runtime/gateways/file/node/get-file-system.ts":{"bytesInOutput":726},"src/runtime/gateways/file/node/node-filesystem.ts":{"bytesInOutput":898},"src/runtime/gateways/file/node/index.ts":{"bytesInOutput":0},"src/runtime/gateways/file/version.ts":{"bytesInOutput":38},"src/runtime/gateways/file/node/gateway-impl.ts":{"bytesInOutput":4652},"src/runtime/gateways/file/node/utils.ts":{"bytesInOutput":894}},"bytes":9171},"dist/fireproof-core/node/mem-filesystem-LPPT7QV5.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":2372},"dist/fireproof-core/node/mem-filesystem-LPPT7QV5.js":{"imports":[{"path":"dist/fireproof-core/node/chunk-4A4RAVNS.js","kind":"import-statement"},{"path":"memfs","kind":"import-statement","external":true}],"exports":["MemFileSystem"],"entryPoint":"src/runtime/gateways/file/node/mem-filesystem.ts","inputs":{"src/runtime/gateways/file/node/mem-filesystem.ts":{"bytesInOutput":739}},"bytes":875},"dist/fireproof-core/node/chunk-4A4RAVNS.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":735},"dist/fireproof-core/node/chunk-4A4RAVNS.js":{"imports":[],"exports":["toArrayBuffer"],"inputs":{"src/runtime/gateways/file/node/to-array-buffer.ts":{"bytesInOutput":277}},"bytes":359}}}
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@fireproof/core",
3
- "version": "0.19.121",
3
+ "version": "0.20.0-dev-preview-06",
4
4
  "description": "Live database for the web.",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -22,6 +22,15 @@
22
22
  "require": "./node/index.cjs",
23
23
  "types": "./node/index.d.ts"
24
24
  },
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"
33
+ },
25
34
  "./web": {
26
35
  "import": "./web/index.js",
27
36
  "browser": "./web/index.js",
@@ -66,14 +75,13 @@
66
75
  "react": "^18.3.1"
67
76
  },
68
77
  "dependencies": {
69
- "@adviser/cement": "^0.3.4",
78
+ "@adviser/cement": "^0.3.5",
70
79
  "@fireproof/vendor": "^1.0.4",
71
- "@ipld/unixfs": "^3.0.0",
72
80
  "multiformats": "^13.3.1",
81
+ "@ipld/unixfs": "^3.0.0",
73
82
  "charwise": "^3.0.1",
74
83
  "prolly-trees": "^1.0.4",
75
84
  "idb": "^8.0.1",
76
- "memfs": "^4.15.1",
77
85
  "p-limit": "^6.2.0",
78
86
  "p-map": "^7.0.3",
79
87
  "p-retry": "^6.2.1"
@@ -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 */\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AO,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 Database,\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,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