@fireproof/core 0.19.121-dev → 0.19.122

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 (70) hide show
  1. package/deno.json +3 -3
  2. package/index.cjs +600 -1004
  3. package/index.cjs.map +1 -1
  4. package/index.d.cts +26 -60
  5. package/index.d.ts +26 -60
  6. package/index.js +392 -97
  7. package/index.js.map +1 -1
  8. package/metafile-cjs.json +1 -1
  9. package/metafile-esm.json +1 -1
  10. package/node/index.cjs +374 -0
  11. package/node/index.cjs.map +1 -0
  12. package/node/index.d.cts +43 -0
  13. package/node/index.d.ts +43 -0
  14. package/node/index.js +279 -0
  15. package/node/index.js.map +1 -0
  16. package/node/{mem-filesystem.js → mem-filesystem-LPPT7QV5.js} +1 -1
  17. package/node/metafile-cjs.json +1 -1
  18. package/node/metafile-esm.json +1 -1
  19. package/package.json +17 -15
  20. package/react/index.cjs +91 -26
  21. package/react/index.cjs.map +1 -1
  22. package/react/index.d.cts +16 -1
  23. package/react/index.d.ts +16 -1
  24. package/react/index.js +92 -27
  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/keyed-crypto.test.ts +4 -2
  29. package/tests/fireproof/config.test.ts +133 -142
  30. package/web/{gateway-impl.cjs → index.cjs} +58 -9
  31. package/web/index.cjs.map +1 -0
  32. package/web/index.d.cts +44 -0
  33. package/web/index.d.ts +44 -0
  34. package/web/{gateway-impl.js → index.js} +52 -5
  35. package/web/index.js.map +1 -0
  36. package/web/metafile-cjs.json +1 -1
  37. package/web/metafile-esm.json +1 -1
  38. package/chunk-7EWIAXTM.js +0 -7
  39. package/chunk-7EWIAXTM.js.map +0 -1
  40. package/chunk-F4FC6B2T.js +0 -63
  41. package/chunk-F4FC6B2T.js.map +0 -1
  42. package/chunk-PZ5AY32C.js +0 -10
  43. package/chunk-PZ5AY32C.js.map +0 -1
  44. package/chunk-RXC4JGJT.js +0 -301
  45. package/chunk-RXC4JGJT.js.map +0 -1
  46. package/gateway-C62S56GY.js +0 -66
  47. package/gateway-C62S56GY.js.map +0 -1
  48. package/gateway-VVS4QWDA.js +0 -145
  49. package/gateway-VVS4QWDA.js.map +0 -1
  50. package/key-bag-file-PWZ3QE7B.js +0 -55
  51. package/key-bag-file-PWZ3QE7B.js.map +0 -1
  52. package/key-bag-indexdb-SYG3YD4D.js +0 -51
  53. package/key-bag-indexdb-SYG3YD4D.js.map +0 -1
  54. package/node/mem-filesystem.cjs +0 -72
  55. package/node/mem-filesystem.cjs.map +0 -1
  56. package/node/mem-filesystem.d.cts +0 -25
  57. package/node/mem-filesystem.d.ts +0 -25
  58. package/node/node-filesystem.cjs +0 -86
  59. package/node/node-filesystem.cjs.map +0 -1
  60. package/node/node-filesystem.d.cts +0 -35
  61. package/node/node-filesystem.d.ts +0 -35
  62. package/node/node-filesystem.js +0 -44
  63. package/node/node-filesystem.js.map +0 -1
  64. package/utils-ZVVGAXFE.js +0 -13
  65. package/utils-ZVVGAXFE.js.map +0 -1
  66. package/web/gateway-impl.cjs.map +0 -1
  67. package/web/gateway-impl.d.cts +0 -31
  68. package/web/gateway-impl.d.ts +0 -31
  69. package/web/gateway-impl.js.map +0 -1
  70. /package/node/{mem-filesystem.js.map → mem-filesystem-LPPT7QV5.js.map} +0 -0
package/index.js CHANGED
@@ -1,32 +1,11 @@
1
- import {
2
- FILESTORE_VERSION
3
- } from "./chunk-7EWIAXTM.js";
4
- import {
5
- getFileName,
6
- getFileSystem,
7
- getPath
8
- } from "./chunk-F4FC6B2T.js";
9
- import {
10
- NotFoundError,
11
- Result,
12
- UInt8ArrayEqual,
13
- dataDir,
14
- ensureLogger,
15
- ensureSuperLog,
16
- ensureSuperThis,
17
- exceptionWrapper,
18
- getKey,
19
- getName,
20
- getStore,
21
- isNotFoundError,
22
- onSuperThis
23
- } from "./chunk-RXC4JGJT.js";
24
- import {
25
- __export
26
- } from "./chunk-PZ5AY32C.js";
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
27
6
 
28
7
  // src/database.ts
29
- import { ResolveOnce as ResolveOnce6 } from "@adviser/cement";
8
+ import { ResolveOnce as ResolveOnce7 } from "@adviser/cement";
30
9
 
31
10
  // src/write-queue.ts
32
11
  function writeQueue(worker, payload = Infinity, unbounded = false) {
@@ -69,7 +48,7 @@ function writeQueue(worker, payload = Infinity, unbounded = false) {
69
48
  }
70
49
 
71
50
  // src/crdt.ts
72
- import { ResolveOnce as ResolveOnce5 } from "@adviser/cement";
51
+ import { ResolveOnce as ResolveOnce6 } from "@adviser/cement";
73
52
 
74
53
  // src/runtime/wait-pr-multiformats/block.ts
75
54
  var block_exports = {};
@@ -177,7 +156,7 @@ function toCIDBlock(block) {
177
156
  }
178
157
 
179
158
  // src/blockstore/store-factory.ts
180
- import { KeyedResolvOnce as KeyedResolvOnce2, URI as URI5 } from "@adviser/cement";
159
+ import { KeyedResolvOnce as KeyedResolvOnce2, URI as URI6, runtimeFn as runtimeFn3 } from "@adviser/cement";
181
160
 
182
161
  // src/runtime/files.ts
183
162
  var files_exports = {};
@@ -252,7 +231,7 @@ var UnixFSFileBuilder = class {
252
231
 
253
232
  // src/blockstore/store.ts
254
233
  import { format as format2, parse as parse2 } from "@fireproof/vendor/@ipld/dag-json";
255
- import { exception2Result, ResolveOnce as ResolveOnce3, Result as Result5 } from "@adviser/cement";
234
+ import { exception2Result, ResolveOnce as ResolveOnce4, Result as Result5 } from "@adviser/cement";
256
235
 
257
236
  // src/types.ts
258
237
  function isFalsy(value) {
@@ -271,10 +250,293 @@ function falsyToUndef(value) {
271
250
  return value;
272
251
  }
273
252
 
253
+ // src/utils.ts
254
+ import {
255
+ LoggerImpl,
256
+ IsLogger,
257
+ Result,
258
+ ResolveOnce,
259
+ isURL,
260
+ URI,
261
+ runtimeFn,
262
+ envFactory,
263
+ toCryptoRuntime,
264
+ JSONFormatter,
265
+ YAMLFormatter
266
+ } from "@adviser/cement";
267
+ import { base58btc } from "multiformats/bases/base58";
268
+ var _globalLogger = new ResolveOnce();
269
+ function globalLogger() {
270
+ return _globalLogger.once(() => new LoggerImpl());
271
+ }
272
+ var registerFP_DEBUG = new ResolveOnce();
273
+ var SuperThisImpl = class _SuperThisImpl {
274
+ constructor(opts) {
275
+ this.logger = opts.logger;
276
+ this.env = opts.env;
277
+ this.crypto = opts.crypto;
278
+ this.pathOps = opts.pathOps;
279
+ this.txt = opts.txt;
280
+ this.ctx = { ...opts.ctx };
281
+ }
282
+ nextId(bytes = 6) {
283
+ const bin = this.crypto.randomBytes(bytes);
284
+ return {
285
+ str: base58btc.encode(bin),
286
+ bin
287
+ };
288
+ }
289
+ timeOrderedNextId(now) {
290
+ now = typeof now === "number" ? now : (/* @__PURE__ */ new Date()).getTime();
291
+ const t = (281474976710656 + now).toString(16).replace(/^1/, "");
292
+ const bin = this.crypto.randomBytes(10);
293
+ bin[1] = bin[1] & 240 | (bin[1] | 8 && 11);
294
+ const hex = Array.from(bin).map((i) => i.toString(16).padStart(2, "0")).join("");
295
+ return {
296
+ str: `${t.slice(0, 8)}-${t.slice(8)}-7${hex.slice(0, 3)}-${hex.slice(3, 7)}-${hex.slice(7, 19)}`
297
+ };
298
+ }
299
+ start() {
300
+ return Promise.resolve();
301
+ }
302
+ clone(override) {
303
+ return new _SuperThisImpl({
304
+ logger: override.logger || this.logger,
305
+ env: envFactory(override.env) || this.env,
306
+ crypto: override.crypto || this.crypto,
307
+ pathOps: override.pathOps || this.pathOps,
308
+ txt: override.txt || this.txt,
309
+ ctx: { ...this.ctx, ...override.ctx }
310
+ });
311
+ }
312
+ };
313
+ function presetEnv() {
314
+ const penv = new Map([
315
+ // ["FP_DEBUG", "xxx"],
316
+ // ["FP_ENV", "development"],
317
+ ...Array.from(
318
+ Object.entries(
319
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
320
+ globalThis[Symbol.for("FP_PRESET_ENV")] || {}
321
+ )
322
+ )
323
+ // .map(([k, v]) => [k, v as string])
324
+ ]);
325
+ return penv;
326
+ }
327
+ var pathOpsImpl = class {
328
+ join(...paths) {
329
+ return paths.map((i) => i.replace(/\/+$/, "")).join("/");
330
+ }
331
+ dirname(path) {
332
+ return path.split("/").slice(0, -1).join("/");
333
+ }
334
+ // homedir() {
335
+ // throw new Error("SysContainer:homedir is not available in seeded state");
336
+ // }
337
+ };
338
+ var pathOps = new pathOpsImpl();
339
+ var txtOps = {
340
+ // eslint-disable-next-line no-restricted-globals
341
+ encode: (input) => new TextEncoder().encode(input),
342
+ // eslint-disable-next-line no-restricted-globals
343
+ decode: (input) => new TextDecoder().decode(input)
344
+ };
345
+ var _onSuperThis = /* @__PURE__ */ new Map();
346
+ function onSuperThis(fn) {
347
+ const key = `onSuperThis-${Math.random().toString(36).slice(2)}`;
348
+ _onSuperThis.set(key, fn);
349
+ return () => {
350
+ _onSuperThis.delete(key);
351
+ };
352
+ }
353
+ function ensureSuperThis(osthis) {
354
+ const env = envFactory({
355
+ symbol: osthis?.env?.symbol || "FP_ENV",
356
+ presetEnv: osthis?.env?.presetEnv || presetEnv()
357
+ });
358
+ const ret = new SuperThisImpl({
359
+ logger: osthis?.logger || globalLogger(),
360
+ env,
361
+ crypto: osthis?.crypto || toCryptoRuntime(),
362
+ ctx: osthis?.ctx || {},
363
+ pathOps,
364
+ txt: osthis?.txt || txtOps
365
+ });
366
+ _onSuperThis.forEach((fn) => fn(ret));
367
+ return ret;
368
+ }
369
+ function ensureSuperLog(sthis, componentName, ctx) {
370
+ return sthis.clone({
371
+ logger: ensureLogger(sthis, componentName, ctx)
372
+ });
373
+ }
374
+ function ensureLogger(sthis, componentName, ctx) {
375
+ let logger;
376
+ if (sthis && IsLogger(sthis.logger)) {
377
+ logger = sthis.logger;
378
+ } else {
379
+ logger = globalLogger();
380
+ }
381
+ const cLogger = logger.With().Module(componentName);
382
+ const debug = [];
383
+ let exposeStack = false;
384
+ if (ctx) {
385
+ if ("debug" in ctx) {
386
+ if (typeof ctx.debug === "string" && ctx.debug.length > 0) {
387
+ debug.push(ctx.debug);
388
+ } else {
389
+ debug.push(componentName);
390
+ }
391
+ delete ctx.debug;
392
+ }
393
+ if ("exposeStack" in ctx) {
394
+ exposeStack = true;
395
+ delete ctx.exposeStack;
396
+ }
397
+ if ("this" in ctx) {
398
+ cLogger.Str("this", sthis.nextId(4).str);
399
+ delete ctx.this;
400
+ }
401
+ for (const [key, value] of Object.entries(ctx)) {
402
+ switch (typeof value) {
403
+ case "string":
404
+ cLogger.Str(key, value);
405
+ break;
406
+ case "number":
407
+ cLogger.Uint64(key, value);
408
+ break;
409
+ default:
410
+ if (value instanceof Date) {
411
+ cLogger.Str(key, value.toISOString());
412
+ } else if (isURL(value)) {
413
+ cLogger.Str(key, value.toString());
414
+ } else if (typeof value === "function") {
415
+ cLogger.Ref(key, value);
416
+ } else {
417
+ cLogger.Any(key, value);
418
+ }
419
+ break;
420
+ }
421
+ }
422
+ }
423
+ registerFP_DEBUG.once(async () => {
424
+ sthis.env.onSet(
425
+ (key, value) => {
426
+ switch (key) {
427
+ case "FP_FORMAT": {
428
+ switch (value) {
429
+ case "jsonice":
430
+ logger.SetFormatter(new JSONFormatter(logger.TxtEnDe(), 2));
431
+ break;
432
+ case "yaml":
433
+ logger.SetFormatter(new YAMLFormatter(logger.TxtEnDe(), 2));
434
+ break;
435
+ case "json":
436
+ default:
437
+ logger.SetFormatter(new JSONFormatter(logger.TxtEnDe()));
438
+ break;
439
+ }
440
+ break;
441
+ }
442
+ case "FP_DEBUG":
443
+ logger.SetDebug(value || []);
444
+ break;
445
+ case "FP_STACK":
446
+ logger.SetExposeStack(!!value);
447
+ break;
448
+ }
449
+ },
450
+ "FP_FORMAT",
451
+ "FP_DEBUG",
452
+ "FP_STACK"
453
+ );
454
+ }).finally(() => {
455
+ });
456
+ if (debug.length > 0) {
457
+ logger.SetDebug(debug);
458
+ }
459
+ if (exposeStack) {
460
+ logger.SetExposeStack(true);
461
+ }
462
+ const out = cLogger.Logger();
463
+ return out;
464
+ }
465
+ function getStore(url, sthis, joiner) {
466
+ const store = url.getParam("store");
467
+ switch (store) {
468
+ case "data":
469
+ case "wal":
470
+ case "meta":
471
+ break;
472
+ default:
473
+ throw sthis.logger.Error().Url(url).Msg(`store not found`).AsError();
474
+ }
475
+ let name = store;
476
+ if (url.hasParam("index")) {
477
+ name = joiner(url.getParam("index") || "idx", name);
478
+ }
479
+ return { store, name };
480
+ }
481
+ function getKey(url, logger) {
482
+ const result = url.getParam("key");
483
+ if (!result) throw logger.Error().Str("url", url.toString()).Msg(`key not found`).AsError();
484
+ return result;
485
+ }
486
+ function getName(sthis, url) {
487
+ let result = url.getParam("name");
488
+ if (!result) {
489
+ result = sthis.pathOps.dirname(url.pathname);
490
+ if (result.length === 0) {
491
+ throw sthis.logger.Error().Str("url", url.toString()).Msg(`name not found`).AsError();
492
+ }
493
+ }
494
+ return result;
495
+ }
496
+ async function exceptionWrapper(fn) {
497
+ return fn().catch((e) => Result.Err(e));
498
+ }
499
+ var NotFoundError = class extends Error {
500
+ constructor() {
501
+ super(...arguments);
502
+ this.code = "ENOENT";
503
+ }
504
+ };
505
+ function isNotFoundError(e) {
506
+ if (Result.Is(e)) {
507
+ if (e.isOk()) return false;
508
+ e = e.Err();
509
+ }
510
+ if (e.code === "ENOENT") return true;
511
+ return false;
512
+ }
513
+ function dataDir(sthis, name, base) {
514
+ if (!base) {
515
+ if (!runtimeFn().isBrowser) {
516
+ const home = sthis.env.get("HOME") || "./";
517
+ base = sthis.env.get("FP_STORAGE_URL") || `file://${sthis.pathOps.join(home, ".fireproof")}`;
518
+ } else {
519
+ base = sthis.env.get("FP_STORAGE_URL") || `indexdb://fp`;
520
+ }
521
+ }
522
+ return URI.from(base.toString()).build().setParam("name", name || "").URI();
523
+ }
524
+ function UInt8ArrayEqual(a, b) {
525
+ if (a.length !== b.length) {
526
+ return false;
527
+ }
528
+ for (let i = 0; i < a.length; i++) {
529
+ if (a[i] !== b[i]) {
530
+ return false;
531
+ }
532
+ }
533
+ return true;
534
+ }
535
+
274
536
  // src/blockstore/loader.ts
275
537
  import pLimit from "p-limit";
276
538
  import { CarReader } from "@fireproof/vendor/@ipld/car/reader";
277
- import { ResolveOnce as ResolveOnce2 } from "@adviser/cement";
539
+ import { ResolveOnce as ResolveOnce3 } from "@adviser/cement";
278
540
 
279
541
  // src/blockstore/loader-helpers.ts
280
542
  import { sha256 as hasher } from "multiformats/hashes/sha2";
@@ -293,7 +555,7 @@ async function parseCarFile(reader, logger) {
293
555
 
294
556
  // src/blockstore/transaction.ts
295
557
  import { MemoryBlockstore } from "@fireproof/vendor/@web3-storage/pail/block";
296
- import { toCryptoRuntime } from "@adviser/cement";
558
+ import { toCryptoRuntime as toCryptoRuntime2 } from "@adviser/cement";
297
559
  var CarTransaction = class extends MemoryBlockstore {
298
560
  constructor(parent, opts = { add: true, noLoader: false }) {
299
561
  super();
@@ -328,7 +590,7 @@ function defaultedBlockstoreRuntime(sthis, opts, component, ctx) {
328
590
  ...opts,
329
591
  logger,
330
592
  keyBag: opts.keyBag || {},
331
- crypto: toCryptoRuntime(opts.crypto),
593
+ crypto: toCryptoRuntime2(opts.crypto),
332
594
  store,
333
595
  storeRuntime: toStoreRuntime(store, sthis)
334
596
  };
@@ -564,18 +826,18 @@ __export(key_bag_exports, {
564
826
  });
565
827
  import {
566
828
  KeyedResolvOnce,
567
- ResolveOnce,
829
+ ResolveOnce as ResolveOnce2,
568
830
  ResolveSeq,
569
831
  Result as Result2,
570
- runtimeFn,
571
- toCryptoRuntime as toCryptoRuntime2,
572
- URI
832
+ runtimeFn as runtimeFn2,
833
+ toCryptoRuntime as toCryptoRuntime3,
834
+ URI as URI2
573
835
  } from "@adviser/cement";
574
- import { base58btc } from "multiformats/bases/base58";
836
+ import { base58btc as base58btc2 } from "multiformats/bases/base58";
575
837
  var KeyBag = class {
576
838
  constructor(rt) {
577
839
  this.rt = rt;
578
- this._warnOnce = new ResolveOnce();
840
+ this._warnOnce = new ResolveOnce2();
579
841
  this._seq = new ResolveSeq();
580
842
  this.logger = ensureLogger(rt.sthis, "KeyBag");
581
843
  this.logger.Debug().Msg("KeyBag created");
@@ -590,7 +852,7 @@ var KeyBag = class {
590
852
  return await this.rt.crypto.importKey(
591
853
  "raw",
592
854
  // raw or jwk
593
- base58btc.decode(key),
855
+ base58btc2.decode(key),
594
856
  // hexStringToUint8Array(key), // raw data
595
857
  "AES-GCM",
596
858
  extractable,
@@ -620,12 +882,12 @@ var KeyBag = class {
620
882
  return Result2.Ok(url);
621
883
  }
622
884
  async toKeyWithFingerPrint(keyStr) {
623
- const material = base58btc.decode(keyStr);
885
+ const material = base58btc2.decode(keyStr);
624
886
  const key = await this.subtleKey(keyStr);
625
887
  const fpr = await this.rt.crypto.digestSHA256(material);
626
888
  return Result2.Ok({
627
889
  key,
628
- fingerPrint: base58btc.encode(new Uint8Array(fpr))
890
+ fingerPrint: base58btc2.encode(new Uint8Array(fpr))
629
891
  });
630
892
  }
631
893
  async setNamedKey(name, key) {
@@ -654,7 +916,7 @@ var KeyBag = class {
654
916
  const ext = new Uint8Array(await this.rt.crypto.exportKey("raw", named.key));
655
917
  return {
656
918
  key: ext,
657
- keyStr: base58btc.encode(ext)
919
+ keyStr: base58btc2.encode(ext)
658
920
  };
659
921
  }
660
922
  });
@@ -673,7 +935,7 @@ var KeyBag = class {
673
935
  this.logger.Debug().Str("id", id).Str("name", name).Msg("failIfNotFound getNamedKey");
674
936
  return Result2.Err(new Error(`Key not found: ${name}`));
675
937
  }
676
- const ret = await this._setNamedKey(name, base58btc.encode(this.rt.crypto.randomBytes(this.rt.keyLength)));
938
+ const ret = await this._setNamedKey(name, base58btc2.encode(this.rt.crypto.randomBytes(this.rt.keyLength)));
677
939
  this.logger.Debug().Str("id", id).Str("name", name).Result("fpr", ret).Msg("createKey getNamedKey-post");
678
940
  return ret;
679
941
  });
@@ -684,15 +946,15 @@ var keyBagProviderFactories = new Map(
684
946
  {
685
947
  protocol: "file:",
686
948
  factory: async (url, sthis) => {
687
- const { KeyBagProviderFile } = await import("./key-bag-file-PWZ3QE7B.js");
688
- return new KeyBagProviderFile(url, sthis);
949
+ const { KeyBagProviderImpl } = await import("@fireproof/core/node");
950
+ return new KeyBagProviderImpl(url, sthis);
689
951
  }
690
952
  },
691
953
  {
692
954
  protocol: "indexdb:",
693
955
  factory: async (url, sthis) => {
694
- const { KeyBagProviderIndexDB } = await import("./key-bag-indexdb-SYG3YD4D.js");
695
- return new KeyBagProviderIndexDB(url, sthis);
956
+ const { KeyBagProviderImpl } = await import("@fireproof/core/web");
957
+ return new KeyBagProviderImpl(url, sthis);
696
958
  }
697
959
  }
698
960
  ].map((i) => [i.protocol, i])
@@ -707,15 +969,15 @@ function registerKeyBagProviderFactory(item) {
707
969
  function defaultKeyBagUrl(sthis) {
708
970
  let bagFnameOrUrl = sthis.env.get("FP_KEYBAG_URL");
709
971
  let url;
710
- if (runtimeFn().isBrowser) {
711
- url = URI.from(bagFnameOrUrl || "indexdb://fp-keybag");
972
+ if (runtimeFn2().isBrowser) {
973
+ url = URI2.from(bagFnameOrUrl || "indexdb://fp-keybag");
712
974
  } else {
713
975
  if (!bagFnameOrUrl) {
714
976
  const home = sthis.env.get("HOME");
715
977
  bagFnameOrUrl = `${home}/.fireproof/keybag`;
716
- url = URI.from(`file://${bagFnameOrUrl}`);
978
+ url = URI2.from(`file://${bagFnameOrUrl}`);
717
979
  } else {
718
- url = URI.from(bagFnameOrUrl);
980
+ url = URI2.from(bagFnameOrUrl);
719
981
  }
720
982
  }
721
983
  const logger = ensureLogger(sthis, "defaultKeyBagUrl");
@@ -729,7 +991,7 @@ function defaultKeyBagOpts(sthis, kbo) {
729
991
  const logger = ensureLogger(sthis, "KeyBag");
730
992
  let url;
731
993
  if (kbo.url) {
732
- url = URI.from(kbo.url);
994
+ url = URI2.from(kbo.url);
733
995
  logger.Debug().Url(url).Msg("from opts");
734
996
  } else {
735
997
  url = defaultKeyBagUrl(sthis);
@@ -744,7 +1006,7 @@ function defaultKeyBagOpts(sthis, kbo) {
744
1006
  }
745
1007
  return {
746
1008
  url,
747
- crypto: kbo.crypto || toCryptoRuntime2({}),
1009
+ crypto: kbo.crypto || toCryptoRuntime3({}),
748
1010
  sthis,
749
1011
  logger,
750
1012
  keyLength: kbo.keyLength || 16,
@@ -938,7 +1200,7 @@ var Loader = class {
938
1200
  this.getBlockCache = /* @__PURE__ */ new Map();
939
1201
  this.seenMeta = /* @__PURE__ */ new Set();
940
1202
  this.writeLimit = pLimit(1);
941
- this.onceReady = new ResolveOnce2();
1203
+ this.onceReady = new ResolveOnce3();
942
1204
  this.name = name;
943
1205
  this.sthis = sthis;
944
1206
  this.ebOpts = defaultedBlockstoreRuntime(
@@ -1263,7 +1525,7 @@ __export(keyed_crypto_exports, {
1263
1525
  BlockIvKeyIdCodec: () => BlockIvKeyIdCodec,
1264
1526
  keyedCryptoFactory: () => keyedCryptoFactory
1265
1527
  });
1266
- import { base58btc as base58btc2 } from "multiformats/bases/base58";
1528
+ import { base58btc as base58btc3 } from "multiformats/bases/base58";
1267
1529
  import { sha256 as hasher4 } from "multiformats/hashes/sha2";
1268
1530
  import * as CBOR from "@fireproof/vendor/cborg";
1269
1531
  var generateIV = {
@@ -1308,7 +1570,7 @@ var BlockIvKeyIdCodec = class {
1308
1570
  const calcIv = this.iv || await getGenerateIVFn(this.ko.url, this.opts).calc(this.ko, this.ko.crypto, data);
1309
1571
  const { iv } = this.ko.algo(calcIv);
1310
1572
  const fprt = await this.ko.fingerPrint();
1311
- const keyId = base58btc2.decode(fprt);
1573
+ const keyId = base58btc3.decode(fprt);
1312
1574
  this.ko.logger.Debug().Str("fp", fprt).Msg("encode");
1313
1575
  return CBOR.encode({
1314
1576
  iv,
@@ -1325,9 +1587,9 @@ var BlockIvKeyIdCodec = class {
1325
1587
  }
1326
1588
  const { iv, keyId, data } = CBOR.decode(bytes);
1327
1589
  const fprt = await this.ko.fingerPrint();
1328
- this.ko.logger.Debug().Str("fp", base58btc2.encode(keyId)).Msg("decode");
1329
- if (base58btc2.encode(keyId) !== fprt) {
1330
- throw this.ko.logger.Error().Str("fp", fprt).Str("keyId", base58btc2.encode(keyId)).Msg("keyId mismatch").AsError();
1590
+ this.ko.logger.Debug().Str("fp", base58btc3.encode(keyId)).Msg("decode");
1591
+ if (base58btc3.encode(keyId) !== fprt) {
1592
+ throw this.ko.logger.Error().Str("fp", fprt).Str("keyId", base58btc3.encode(keyId)).Msg("keyId mismatch").AsError();
1331
1593
  }
1332
1594
  const result = await this.ko._decrypt({ iv, bytes: data });
1333
1595
  if (!this.opts?.noIVVerify && !await getGenerateIVFn(this.ko.url, this.opts).verify(this.ko, this.ko.crypto, iv, result)) {
@@ -1431,7 +1693,7 @@ async function keyedCryptoFactory(url, kb, sthis) {
1431
1693
 
1432
1694
  // src/blockstore/fragment-gateway.ts
1433
1695
  import { Result as Result3 } from "@adviser/cement";
1434
- import { base58btc as base58btc3 } from "multiformats/bases/base58";
1696
+ import { base58btc as base58btc4 } from "multiformats/bases/base58";
1435
1697
  import { encode as encode3, decode as decode3 } from "@fireproof/vendor/cborg";
1436
1698
  function getFragSize(url) {
1437
1699
  const fragSize = url.getParam("fragSize");
@@ -1468,7 +1730,7 @@ async function getFrags(url, innerGW, headerSize, logger) {
1468
1730
  const firstFragment = decode3(firstRaw.unwrap());
1469
1731
  const blockSize = firstFragment.data.length;
1470
1732
  const ops = [Promise.resolve(Result3.Ok(firstFragment))];
1471
- const fidStr = base58btc3.encode(firstFragment.fid);
1733
+ const fidStr = base58btc4.encode(firstFragment.fid);
1472
1734
  const fragUrl = url.build().setParam("fid", fidStr).setParam("len", firstFragment.len.toString()).setParam("headerSize", headerSize.toString());
1473
1735
  for (let ofs = blockSize; ofs < firstFragment.len; ofs += blockSize) {
1474
1736
  ops.push(
@@ -1478,7 +1740,7 @@ async function getFrags(url, innerGW, headerSize, logger) {
1478
1740
  return raw2;
1479
1741
  }
1480
1742
  const fragment = decode3(raw2.unwrap());
1481
- if (base58btc3.encode(fragment.fid) !== fidStr) {
1743
+ if (base58btc4.encode(fragment.fid) !== fidStr) {
1482
1744
  return Result3.Err(logger.Error().Msg("Fragment fid mismatch").AsError());
1483
1745
  }
1484
1746
  if (fragment.ofs !== ofs2) {
@@ -1575,7 +1837,7 @@ var FragmentGateway = class {
1575
1837
  return Result3.Err(rfrag.Err());
1576
1838
  }
1577
1839
  const frag = rfrag.Ok();
1578
- const fidStr = base58btc3.encode(frag.fid);
1840
+ const fidStr = base58btc4.encode(frag.fid);
1579
1841
  const fragUrl = url.build().setParam("fid", fidStr).setParam("len", frag.len.toString()).setParam("headerSize", this.headerSize.toString()).URI();
1580
1842
  await this.innerGW.delete(fragUrl);
1581
1843
  }
@@ -1903,7 +2165,7 @@ var WALStoreImpl = class extends BaseStoreImpl {
1903
2165
  constructor(loader, url, opts) {
1904
2166
  super(loader.name, url, { ...opts }, loader.sthis, ensureLogger(loader.sthis, "WALStoreImpl"));
1905
2167
  this.storeType = "wal";
1906
- this._ready = new ResolveOnce3();
2168
+ this._ready = new ResolveOnce4();
1907
2169
  this.walState = { operations: [], noLoaderOps: [], fileOperations: [] };
1908
2170
  this.processing = void 0;
1909
2171
  this.processQueue = new CommitQueue();
@@ -2100,10 +2362,10 @@ function buildURL(optURL, loader) {
2100
2362
  const obuItem = Array.from(storeFactory.values()).find((items) => items.overrideBaseURL);
2101
2363
  let obuUrl;
2102
2364
  if (obuItem && obuItem.overrideBaseURL) {
2103
- obuUrl = URI5.from(obuItem.overrideBaseURL);
2365
+ obuUrl = URI6.from(obuItem.overrideBaseURL);
2104
2366
  }
2105
2367
  const ret = ensureIsIndex(
2106
- URI5.from(optURL || obuUrl || dataDir(loader.sthis, loader.name, storeOpts.stores?.base)),
2368
+ URI6.from(optURL || obuUrl || dataDir(loader.sthis, loader.name, storeOpts.stores?.base)),
2107
2369
  storeOpts.isIndex
2108
2370
  );
2109
2371
  return ret;
@@ -2241,28 +2503,32 @@ function toStoreRuntime(opts, sthis) {
2241
2503
  decodeFile: opts.decodeFile || decodeFile
2242
2504
  };
2243
2505
  }
2244
- registerStoreProtocol({
2245
- protocol: "file:",
2246
- gateway: async (sthis) => {
2247
- const { FileGateway } = await import("./gateway-VVS4QWDA.js");
2248
- return new FileGateway(sthis);
2249
- },
2250
- test: async (sthis) => {
2251
- const { FileTestStore } = await import("./gateway-VVS4QWDA.js");
2252
- return new FileTestStore(sthis);
2253
- }
2254
- });
2255
- registerStoreProtocol({
2256
- protocol: "indexdb:",
2257
- gateway: async (sthis) => {
2258
- const { IndexDBGateway } = await import("./gateway-C62S56GY.js");
2259
- return new IndexDBGateway(sthis);
2260
- },
2261
- test: async (sthis) => {
2262
- const { IndexDBTestStore } = await import("./gateway-C62S56GY.js");
2263
- return new IndexDBTestStore(sthis);
2264
- }
2265
- });
2506
+ if (runtimeFn3().isNodeIsh || runtimeFn3().isDeno) {
2507
+ registerStoreProtocol({
2508
+ protocol: "file:",
2509
+ gateway: async (sthis) => {
2510
+ const { GatewayImpl } = await import("@fireproof/core/node");
2511
+ return new GatewayImpl(sthis);
2512
+ },
2513
+ test: async (sthis) => {
2514
+ const { GatewayTestImpl } = await import("@fireproof/core/node");
2515
+ return new GatewayTestImpl(sthis);
2516
+ }
2517
+ });
2518
+ }
2519
+ if (runtimeFn3().isBrowser) {
2520
+ registerStoreProtocol({
2521
+ protocol: "indexdb:",
2522
+ gateway: async (sthis) => {
2523
+ const { GatewayImpl } = await import("@fireproof/core/web");
2524
+ return new GatewayImpl(sthis);
2525
+ },
2526
+ test: async (sthis) => {
2527
+ const { GatewayTestImpl } = await import("@fireproof/core/web");
2528
+ return new GatewayTestImpl(sthis);
2529
+ }
2530
+ });
2531
+ }
2266
2532
 
2267
2533
  // src/blockstore/store-remote.ts
2268
2534
  async function RemoteDataStore(sthis, name, url, opts) {
@@ -2962,7 +3228,7 @@ var Index = class {
2962
3228
  // src/crdt-clock.ts
2963
3229
  import { advance } from "@fireproof/vendor/@web3-storage/pail/clock";
2964
3230
  import { root as root2 } from "@fireproof/vendor/@web3-storage/pail/crdt";
2965
- import { ResolveOnce as ResolveOnce4 } from "@adviser/cement";
3231
+ import { ResolveOnce as ResolveOnce5 } from "@adviser/cement";
2966
3232
 
2967
3233
  // src/apply-head-queue.ts
2968
3234
  function applyHeadQueue(worker, logger) {
@@ -3019,7 +3285,7 @@ var CRDTClock = class {
3019
3285
  this.zoomers = /* @__PURE__ */ new Set();
3020
3286
  this.watchers = /* @__PURE__ */ new Set();
3021
3287
  this.emptyWatchers = /* @__PURE__ */ new Set();
3022
- this._ready = new ResolveOnce4();
3288
+ this._ready = new ResolveOnce5();
3023
3289
  this.blockstore = blockstore;
3024
3290
  this.logger = ensureLogger(blockstore.sthis, "CRDTClock");
3025
3291
  this.applyHeadQueue = applyHeadQueue(this.int_applyHead.bind(this), this.logger);
@@ -3132,7 +3398,7 @@ async function advanceBlocks(logger, newHead, tblocks, head) {
3132
3398
  var CRDT = class {
3133
3399
  constructor(sthis, name, opts = {}) {
3134
3400
  this.indexers = /* @__PURE__ */ new Map();
3135
- this.onceReady = new ResolveOnce5();
3401
+ this.onceReady = new ResolveOnce6();
3136
3402
  this.sthis = sthis;
3137
3403
  this.name = name;
3138
3404
  this.logger = ensureLogger(sthis, "CRDT");
@@ -3252,7 +3518,7 @@ var Database = class {
3252
3518
  this._listening = false;
3253
3519
  this._listeners = /* @__PURE__ */ new Set();
3254
3520
  this._noupdate_listeners = /* @__PURE__ */ new Set();
3255
- this._ready = new ResolveOnce6();
3521
+ this._ready = new ResolveOnce7();
3256
3522
  this.name = name;
3257
3523
  this.opts = opts || this.opts;
3258
3524
  this.sthis = ensureSuperThis(this.opts);
@@ -3459,14 +3725,40 @@ __export(runtime_exports, {
3459
3725
  INDEXDB_VERSION: () => INDEXDB_VERSION,
3460
3726
  files: () => files_exports,
3461
3727
  getFileName: () => getFileName,
3462
- getFileSystem: () => getFileSystem,
3463
3728
  getPath: () => getPath,
3464
3729
  kb: () => key_bag_exports,
3465
3730
  kc: () => keyed_crypto_exports,
3466
3731
  mf: () => wait_pr_multiformats_exports,
3467
- runtimeFn: () => runtimeFn2
3732
+ runtimeFn: () => runtimeFn4
3468
3733
  });
3469
3734
 
3735
+ // src/runtime/gateways/file/node/utils.ts
3736
+ import { getStore as getStore2 } from "@fireproof/core";
3737
+ function getPath(url, sthis) {
3738
+ const basePath = url.pathname;
3739
+ const name = url.getParam("name");
3740
+ if (name) {
3741
+ const version = url.getParam("version");
3742
+ if (!version) throw sthis.logger.Error().Url(url).Msg(`version not found`).AsError();
3743
+ return sthis.pathOps.join(basePath, version, name);
3744
+ }
3745
+ return sthis.pathOps.join(basePath);
3746
+ }
3747
+ function getFileName(url, sthis) {
3748
+ const key = url.getParam("key");
3749
+ if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
3750
+ const res = getStore2(url, sthis, (...a) => a.join("-"));
3751
+ switch (res.store) {
3752
+ case "data":
3753
+ return sthis.pathOps.join(res.name, key + ".car");
3754
+ case "wal":
3755
+ case "meta":
3756
+ return sthis.pathOps.join(res.name, key + ".json");
3757
+ default:
3758
+ throw sthis.logger.Error().Url(url).Msg(`unsupported store type`).AsError();
3759
+ }
3760
+ }
3761
+
3470
3762
  // src/runtime/wait-pr-multiformats/index.ts
3471
3763
  var wait_pr_multiformats_exports = {};
3472
3764
  __export(wait_pr_multiformats_exports, {
@@ -3478,14 +3770,17 @@ __export(wait_pr_multiformats_exports, {
3478
3770
  var codec_interface_exports = {};
3479
3771
 
3480
3772
  // src/runtime/index.ts
3481
- import { runtimeFn as runtimeFn2 } from "@adviser/cement";
3773
+ import { runtimeFn as runtimeFn4 } from "@adviser/cement";
3774
+
3775
+ // src/runtime/gateways/file/version.ts
3776
+ var FILESTORE_VERSION = "v0.19-file";
3482
3777
 
3483
3778
  // src/runtime/gateways/indexdb/version.ts
3484
3779
  var INDEXDB_VERSION = "v0.19-indexdb";
3485
3780
 
3486
3781
  // src/version.ts
3487
3782
  var PACKAGE_VERSION = Object.keys({
3488
- "0.19.121-dev": "xxxx"
3783
+ "0.19.122": "xxxx"
3489
3784
  })[0];
3490
3785
  export {
3491
3786
  CRDT,