@fireproof/core 0.19.121-dev → 0.19.121

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 (62) hide show
  1. package/deno.json +2 -2
  2. package/index.cjs +624 -1026
  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 +394 -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 +16 -14
  20. package/tests/blockstore/keyed-crypto.test.ts +4 -2
  21. package/tests/fireproof/config.test.ts +133 -142
  22. package/web/{gateway-impl.cjs → index.cjs} +58 -9
  23. package/web/index.cjs.map +1 -0
  24. package/web/index.d.cts +44 -0
  25. package/web/index.d.ts +44 -0
  26. package/web/{gateway-impl.js → index.js} +52 -5
  27. package/web/index.js.map +1 -0
  28. package/web/metafile-cjs.json +1 -1
  29. package/web/metafile-esm.json +1 -1
  30. package/chunk-7EWIAXTM.js +0 -7
  31. package/chunk-7EWIAXTM.js.map +0 -1
  32. package/chunk-F4FC6B2T.js +0 -63
  33. package/chunk-F4FC6B2T.js.map +0 -1
  34. package/chunk-PZ5AY32C.js +0 -10
  35. package/chunk-PZ5AY32C.js.map +0 -1
  36. package/chunk-RXC4JGJT.js +0 -301
  37. package/chunk-RXC4JGJT.js.map +0 -1
  38. package/gateway-C62S56GY.js +0 -66
  39. package/gateway-C62S56GY.js.map +0 -1
  40. package/gateway-VVS4QWDA.js +0 -145
  41. package/gateway-VVS4QWDA.js.map +0 -1
  42. package/key-bag-file-PWZ3QE7B.js +0 -55
  43. package/key-bag-file-PWZ3QE7B.js.map +0 -1
  44. package/key-bag-indexdb-SYG3YD4D.js +0 -51
  45. package/key-bag-indexdb-SYG3YD4D.js.map +0 -1
  46. package/node/mem-filesystem.cjs +0 -72
  47. package/node/mem-filesystem.cjs.map +0 -1
  48. package/node/mem-filesystem.d.cts +0 -25
  49. package/node/mem-filesystem.d.ts +0 -25
  50. package/node/node-filesystem.cjs +0 -86
  51. package/node/node-filesystem.cjs.map +0 -1
  52. package/node/node-filesystem.d.cts +0 -35
  53. package/node/node-filesystem.d.ts +0 -35
  54. package/node/node-filesystem.js +0 -44
  55. package/node/node-filesystem.js.map +0 -1
  56. package/utils-ZVVGAXFE.js +0 -13
  57. package/utils-ZVVGAXFE.js.map +0 -1
  58. package/web/gateway-impl.cjs.map +0 -1
  59. package/web/gateway-impl.d.cts +0 -31
  60. package/web/gateway-impl.d.ts +0 -31
  61. package/web/gateway-impl.js.map +0 -1
  62. /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,295 @@ 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 (IsLogger(sthis)) {
377
+ logger = sthis;
378
+ } else if (sthis && IsLogger(sthis.logger)) {
379
+ logger = sthis.logger;
380
+ } else {
381
+ logger = globalLogger();
382
+ }
383
+ const cLogger = logger.With().Module(componentName);
384
+ const debug = [];
385
+ let exposeStack = false;
386
+ if (ctx) {
387
+ if ("debug" in ctx) {
388
+ if (typeof ctx.debug === "string" && ctx.debug.length > 0) {
389
+ debug.push(ctx.debug);
390
+ } else {
391
+ debug.push(componentName);
392
+ }
393
+ delete ctx.debug;
394
+ }
395
+ if ("exposeStack" in ctx) {
396
+ exposeStack = true;
397
+ delete ctx.exposeStack;
398
+ }
399
+ if ("this" in ctx) {
400
+ cLogger.Str("this", sthis.nextId(4).str);
401
+ delete ctx.this;
402
+ }
403
+ for (const [key, value] of Object.entries(ctx)) {
404
+ switch (typeof value) {
405
+ case "string":
406
+ cLogger.Str(key, value);
407
+ break;
408
+ case "number":
409
+ cLogger.Uint64(key, value);
410
+ break;
411
+ default:
412
+ if (value instanceof Date) {
413
+ cLogger.Str(key, value.toISOString());
414
+ } else if (isURL(value)) {
415
+ cLogger.Str(key, value.toString());
416
+ } else if (typeof value === "function") {
417
+ cLogger.Ref(key, value);
418
+ } else {
419
+ cLogger.Any(key, value);
420
+ }
421
+ break;
422
+ }
423
+ }
424
+ }
425
+ registerFP_DEBUG.once(async () => {
426
+ sthis.env.onSet(
427
+ (key, value) => {
428
+ switch (key) {
429
+ case "FP_FORMAT": {
430
+ switch (value) {
431
+ case "jsonice":
432
+ logger.SetFormatter(new JSONFormatter(logger.TxtEnDe(), 2));
433
+ break;
434
+ case "yaml":
435
+ logger.SetFormatter(new YAMLFormatter(logger.TxtEnDe(), 2));
436
+ break;
437
+ case "json":
438
+ default:
439
+ logger.SetFormatter(new JSONFormatter(logger.TxtEnDe()));
440
+ break;
441
+ }
442
+ break;
443
+ }
444
+ case "FP_DEBUG":
445
+ logger.SetDebug(value || []);
446
+ break;
447
+ case "FP_STACK":
448
+ logger.SetExposeStack(!!value);
449
+ break;
450
+ }
451
+ },
452
+ "FP_FORMAT",
453
+ "FP_DEBUG",
454
+ "FP_STACK"
455
+ );
456
+ }).finally(() => {
457
+ });
458
+ if (debug.length > 0) {
459
+ logger.SetDebug(debug);
460
+ }
461
+ if (exposeStack) {
462
+ logger.SetExposeStack(true);
463
+ }
464
+ const out = cLogger.Logger();
465
+ return out;
466
+ }
467
+ function getStore(url, sthis, joiner) {
468
+ const store = url.getParam("store");
469
+ switch (store) {
470
+ case "data":
471
+ case "wal":
472
+ case "meta":
473
+ break;
474
+ default:
475
+ throw sthis.logger.Error().Url(url).Msg(`store not found`).AsError();
476
+ }
477
+ let name = store;
478
+ if (url.hasParam("index")) {
479
+ name = joiner(url.getParam("index") || "idx", name);
480
+ }
481
+ return { store, name };
482
+ }
483
+ function getKey(url, logger) {
484
+ const result = url.getParam("key");
485
+ if (!result) throw logger.Error().Str("url", url.toString()).Msg(`key not found`).AsError();
486
+ return result;
487
+ }
488
+ function getName(sthis, url) {
489
+ let result = url.getParam("name");
490
+ if (!result) {
491
+ result = sthis.pathOps.dirname(url.pathname);
492
+ if (result.length === 0) {
493
+ throw sthis.logger.Error().Str("url", url.toString()).Msg(`name not found`).AsError();
494
+ }
495
+ }
496
+ return result;
497
+ }
498
+ async function exceptionWrapper(fn) {
499
+ return fn().catch((e) => Result.Err(e));
500
+ }
501
+ var NotFoundError = class extends Error {
502
+ constructor() {
503
+ super(...arguments);
504
+ this.code = "ENOENT";
505
+ }
506
+ };
507
+ function isNotFoundError(e) {
508
+ if (Result.Is(e)) {
509
+ if (e.isOk()) return false;
510
+ e = e.Err();
511
+ }
512
+ if (e.code === "ENOENT") return true;
513
+ return false;
514
+ }
515
+ function dataDir(sthis, name, base) {
516
+ if (!base) {
517
+ if (!runtimeFn().isBrowser) {
518
+ const home = sthis.env.get("HOME") || "./";
519
+ base = sthis.env.get("FP_STORAGE_URL") || `file://${sthis.pathOps.join(home, ".fireproof")}`;
520
+ } else {
521
+ base = sthis.env.get("FP_STORAGE_URL") || `indexdb://fp`;
522
+ }
523
+ }
524
+ return URI.from(base.toString()).build().setParam("name", name || "").URI();
525
+ }
526
+ function UInt8ArrayEqual(a, b) {
527
+ if (a.length !== b.length) {
528
+ return false;
529
+ }
530
+ for (let i = 0; i < a.length; i++) {
531
+ if (a[i] !== b[i]) {
532
+ return false;
533
+ }
534
+ }
535
+ return true;
536
+ }
537
+
274
538
  // src/blockstore/loader.ts
275
539
  import pLimit from "p-limit";
276
540
  import { CarReader } from "@fireproof/vendor/@ipld/car/reader";
277
- import { ResolveOnce as ResolveOnce2 } from "@adviser/cement";
541
+ import { ResolveOnce as ResolveOnce3 } from "@adviser/cement";
278
542
 
279
543
  // src/blockstore/loader-helpers.ts
280
544
  import { sha256 as hasher } from "multiformats/hashes/sha2";
@@ -293,7 +557,7 @@ async function parseCarFile(reader, logger) {
293
557
 
294
558
  // src/blockstore/transaction.ts
295
559
  import { MemoryBlockstore } from "@fireproof/vendor/@web3-storage/pail/block";
296
- import { toCryptoRuntime } from "@adviser/cement";
560
+ import { toCryptoRuntime as toCryptoRuntime2 } from "@adviser/cement";
297
561
  var CarTransaction = class extends MemoryBlockstore {
298
562
  constructor(parent, opts = { add: true, noLoader: false }) {
299
563
  super();
@@ -328,7 +592,7 @@ function defaultedBlockstoreRuntime(sthis, opts, component, ctx) {
328
592
  ...opts,
329
593
  logger,
330
594
  keyBag: opts.keyBag || {},
331
- crypto: toCryptoRuntime(opts.crypto),
595
+ crypto: toCryptoRuntime2(opts.crypto),
332
596
  store,
333
597
  storeRuntime: toStoreRuntime(store, sthis)
334
598
  };
@@ -564,18 +828,18 @@ __export(key_bag_exports, {
564
828
  });
565
829
  import {
566
830
  KeyedResolvOnce,
567
- ResolveOnce,
831
+ ResolveOnce as ResolveOnce2,
568
832
  ResolveSeq,
569
833
  Result as Result2,
570
- runtimeFn,
571
- toCryptoRuntime as toCryptoRuntime2,
572
- URI
834
+ runtimeFn as runtimeFn2,
835
+ toCryptoRuntime as toCryptoRuntime3,
836
+ URI as URI2
573
837
  } from "@adviser/cement";
574
- import { base58btc } from "multiformats/bases/base58";
838
+ import { base58btc as base58btc2 } from "multiformats/bases/base58";
575
839
  var KeyBag = class {
576
840
  constructor(rt) {
577
841
  this.rt = rt;
578
- this._warnOnce = new ResolveOnce();
842
+ this._warnOnce = new ResolveOnce2();
579
843
  this._seq = new ResolveSeq();
580
844
  this.logger = ensureLogger(rt.sthis, "KeyBag");
581
845
  this.logger.Debug().Msg("KeyBag created");
@@ -590,7 +854,7 @@ var KeyBag = class {
590
854
  return await this.rt.crypto.importKey(
591
855
  "raw",
592
856
  // raw or jwk
593
- base58btc.decode(key),
857
+ base58btc2.decode(key),
594
858
  // hexStringToUint8Array(key), // raw data
595
859
  "AES-GCM",
596
860
  extractable,
@@ -620,12 +884,12 @@ var KeyBag = class {
620
884
  return Result2.Ok(url);
621
885
  }
622
886
  async toKeyWithFingerPrint(keyStr) {
623
- const material = base58btc.decode(keyStr);
887
+ const material = base58btc2.decode(keyStr);
624
888
  const key = await this.subtleKey(keyStr);
625
889
  const fpr = await this.rt.crypto.digestSHA256(material);
626
890
  return Result2.Ok({
627
891
  key,
628
- fingerPrint: base58btc.encode(new Uint8Array(fpr))
892
+ fingerPrint: base58btc2.encode(new Uint8Array(fpr))
629
893
  });
630
894
  }
631
895
  async setNamedKey(name, key) {
@@ -654,7 +918,7 @@ var KeyBag = class {
654
918
  const ext = new Uint8Array(await this.rt.crypto.exportKey("raw", named.key));
655
919
  return {
656
920
  key: ext,
657
- keyStr: base58btc.encode(ext)
921
+ keyStr: base58btc2.encode(ext)
658
922
  };
659
923
  }
660
924
  });
@@ -673,7 +937,7 @@ var KeyBag = class {
673
937
  this.logger.Debug().Str("id", id).Str("name", name).Msg("failIfNotFound getNamedKey");
674
938
  return Result2.Err(new Error(`Key not found: ${name}`));
675
939
  }
676
- const ret = await this._setNamedKey(name, base58btc.encode(this.rt.crypto.randomBytes(this.rt.keyLength)));
940
+ const ret = await this._setNamedKey(name, base58btc2.encode(this.rt.crypto.randomBytes(this.rt.keyLength)));
677
941
  this.logger.Debug().Str("id", id).Str("name", name).Result("fpr", ret).Msg("createKey getNamedKey-post");
678
942
  return ret;
679
943
  });
@@ -684,15 +948,15 @@ var keyBagProviderFactories = new Map(
684
948
  {
685
949
  protocol: "file:",
686
950
  factory: async (url, sthis) => {
687
- const { KeyBagProviderFile } = await import("./key-bag-file-PWZ3QE7B.js");
688
- return new KeyBagProviderFile(url, sthis);
951
+ const { KeyBagProviderImpl } = await import("@fireproof/core/node");
952
+ return new KeyBagProviderImpl(url, sthis);
689
953
  }
690
954
  },
691
955
  {
692
956
  protocol: "indexdb:",
693
957
  factory: async (url, sthis) => {
694
- const { KeyBagProviderIndexDB } = await import("./key-bag-indexdb-SYG3YD4D.js");
695
- return new KeyBagProviderIndexDB(url, sthis);
958
+ const { KeyBagProviderImpl } = await import("@fireproof/core/web");
959
+ return new KeyBagProviderImpl(url, sthis);
696
960
  }
697
961
  }
698
962
  ].map((i) => [i.protocol, i])
@@ -707,15 +971,15 @@ function registerKeyBagProviderFactory(item) {
707
971
  function defaultKeyBagUrl(sthis) {
708
972
  let bagFnameOrUrl = sthis.env.get("FP_KEYBAG_URL");
709
973
  let url;
710
- if (runtimeFn().isBrowser) {
711
- url = URI.from(bagFnameOrUrl || "indexdb://fp-keybag");
974
+ if (runtimeFn2().isBrowser) {
975
+ url = URI2.from(bagFnameOrUrl || "indexdb://fp-keybag");
712
976
  } else {
713
977
  if (!bagFnameOrUrl) {
714
978
  const home = sthis.env.get("HOME");
715
979
  bagFnameOrUrl = `${home}/.fireproof/keybag`;
716
- url = URI.from(`file://${bagFnameOrUrl}`);
980
+ url = URI2.from(`file://${bagFnameOrUrl}`);
717
981
  } else {
718
- url = URI.from(bagFnameOrUrl);
982
+ url = URI2.from(bagFnameOrUrl);
719
983
  }
720
984
  }
721
985
  const logger = ensureLogger(sthis, "defaultKeyBagUrl");
@@ -729,7 +993,7 @@ function defaultKeyBagOpts(sthis, kbo) {
729
993
  const logger = ensureLogger(sthis, "KeyBag");
730
994
  let url;
731
995
  if (kbo.url) {
732
- url = URI.from(kbo.url);
996
+ url = URI2.from(kbo.url);
733
997
  logger.Debug().Url(url).Msg("from opts");
734
998
  } else {
735
999
  url = defaultKeyBagUrl(sthis);
@@ -744,7 +1008,7 @@ function defaultKeyBagOpts(sthis, kbo) {
744
1008
  }
745
1009
  return {
746
1010
  url,
747
- crypto: kbo.crypto || toCryptoRuntime2({}),
1011
+ crypto: kbo.crypto || toCryptoRuntime3({}),
748
1012
  sthis,
749
1013
  logger,
750
1014
  keyLength: kbo.keyLength || 16,
@@ -938,7 +1202,7 @@ var Loader = class {
938
1202
  this.getBlockCache = /* @__PURE__ */ new Map();
939
1203
  this.seenMeta = /* @__PURE__ */ new Set();
940
1204
  this.writeLimit = pLimit(1);
941
- this.onceReady = new ResolveOnce2();
1205
+ this.onceReady = new ResolveOnce3();
942
1206
  this.name = name;
943
1207
  this.sthis = sthis;
944
1208
  this.ebOpts = defaultedBlockstoreRuntime(
@@ -1263,7 +1527,7 @@ __export(keyed_crypto_exports, {
1263
1527
  BlockIvKeyIdCodec: () => BlockIvKeyIdCodec,
1264
1528
  keyedCryptoFactory: () => keyedCryptoFactory
1265
1529
  });
1266
- import { base58btc as base58btc2 } from "multiformats/bases/base58";
1530
+ import { base58btc as base58btc3 } from "multiformats/bases/base58";
1267
1531
  import { sha256 as hasher4 } from "multiformats/hashes/sha2";
1268
1532
  import * as CBOR from "@fireproof/vendor/cborg";
1269
1533
  var generateIV = {
@@ -1308,7 +1572,7 @@ var BlockIvKeyIdCodec = class {
1308
1572
  const calcIv = this.iv || await getGenerateIVFn(this.ko.url, this.opts).calc(this.ko, this.ko.crypto, data);
1309
1573
  const { iv } = this.ko.algo(calcIv);
1310
1574
  const fprt = await this.ko.fingerPrint();
1311
- const keyId = base58btc2.decode(fprt);
1575
+ const keyId = base58btc3.decode(fprt);
1312
1576
  this.ko.logger.Debug().Str("fp", fprt).Msg("encode");
1313
1577
  return CBOR.encode({
1314
1578
  iv,
@@ -1325,9 +1589,9 @@ var BlockIvKeyIdCodec = class {
1325
1589
  }
1326
1590
  const { iv, keyId, data } = CBOR.decode(bytes);
1327
1591
  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();
1592
+ this.ko.logger.Debug().Str("fp", base58btc3.encode(keyId)).Msg("decode");
1593
+ if (base58btc3.encode(keyId) !== fprt) {
1594
+ throw this.ko.logger.Error().Str("fp", fprt).Str("keyId", base58btc3.encode(keyId)).Msg("keyId mismatch").AsError();
1331
1595
  }
1332
1596
  const result = await this.ko._decrypt({ iv, bytes: data });
1333
1597
  if (!this.opts?.noIVVerify && !await getGenerateIVFn(this.ko.url, this.opts).verify(this.ko, this.ko.crypto, iv, result)) {
@@ -1431,7 +1695,7 @@ async function keyedCryptoFactory(url, kb, sthis) {
1431
1695
 
1432
1696
  // src/blockstore/fragment-gateway.ts
1433
1697
  import { Result as Result3 } from "@adviser/cement";
1434
- import { base58btc as base58btc3 } from "multiformats/bases/base58";
1698
+ import { base58btc as base58btc4 } from "multiformats/bases/base58";
1435
1699
  import { encode as encode3, decode as decode3 } from "@fireproof/vendor/cborg";
1436
1700
  function getFragSize(url) {
1437
1701
  const fragSize = url.getParam("fragSize");
@@ -1468,7 +1732,7 @@ async function getFrags(url, innerGW, headerSize, logger) {
1468
1732
  const firstFragment = decode3(firstRaw.unwrap());
1469
1733
  const blockSize = firstFragment.data.length;
1470
1734
  const ops = [Promise.resolve(Result3.Ok(firstFragment))];
1471
- const fidStr = base58btc3.encode(firstFragment.fid);
1735
+ const fidStr = base58btc4.encode(firstFragment.fid);
1472
1736
  const fragUrl = url.build().setParam("fid", fidStr).setParam("len", firstFragment.len.toString()).setParam("headerSize", headerSize.toString());
1473
1737
  for (let ofs = blockSize; ofs < firstFragment.len; ofs += blockSize) {
1474
1738
  ops.push(
@@ -1478,7 +1742,7 @@ async function getFrags(url, innerGW, headerSize, logger) {
1478
1742
  return raw2;
1479
1743
  }
1480
1744
  const fragment = decode3(raw2.unwrap());
1481
- if (base58btc3.encode(fragment.fid) !== fidStr) {
1745
+ if (base58btc4.encode(fragment.fid) !== fidStr) {
1482
1746
  return Result3.Err(logger.Error().Msg("Fragment fid mismatch").AsError());
1483
1747
  }
1484
1748
  if (fragment.ofs !== ofs2) {
@@ -1575,7 +1839,7 @@ var FragmentGateway = class {
1575
1839
  return Result3.Err(rfrag.Err());
1576
1840
  }
1577
1841
  const frag = rfrag.Ok();
1578
- const fidStr = base58btc3.encode(frag.fid);
1842
+ const fidStr = base58btc4.encode(frag.fid);
1579
1843
  const fragUrl = url.build().setParam("fid", fidStr).setParam("len", frag.len.toString()).setParam("headerSize", this.headerSize.toString()).URI();
1580
1844
  await this.innerGW.delete(fragUrl);
1581
1845
  }
@@ -1903,7 +2167,7 @@ var WALStoreImpl = class extends BaseStoreImpl {
1903
2167
  constructor(loader, url, opts) {
1904
2168
  super(loader.name, url, { ...opts }, loader.sthis, ensureLogger(loader.sthis, "WALStoreImpl"));
1905
2169
  this.storeType = "wal";
1906
- this._ready = new ResolveOnce3();
2170
+ this._ready = new ResolveOnce4();
1907
2171
  this.walState = { operations: [], noLoaderOps: [], fileOperations: [] };
1908
2172
  this.processing = void 0;
1909
2173
  this.processQueue = new CommitQueue();
@@ -2100,10 +2364,10 @@ function buildURL(optURL, loader) {
2100
2364
  const obuItem = Array.from(storeFactory.values()).find((items) => items.overrideBaseURL);
2101
2365
  let obuUrl;
2102
2366
  if (obuItem && obuItem.overrideBaseURL) {
2103
- obuUrl = URI5.from(obuItem.overrideBaseURL);
2367
+ obuUrl = URI6.from(obuItem.overrideBaseURL);
2104
2368
  }
2105
2369
  const ret = ensureIsIndex(
2106
- URI5.from(optURL || obuUrl || dataDir(loader.sthis, loader.name, storeOpts.stores?.base)),
2370
+ URI6.from(optURL || obuUrl || dataDir(loader.sthis, loader.name, storeOpts.stores?.base)),
2107
2371
  storeOpts.isIndex
2108
2372
  );
2109
2373
  return ret;
@@ -2241,28 +2505,32 @@ function toStoreRuntime(opts, sthis) {
2241
2505
  decodeFile: opts.decodeFile || decodeFile
2242
2506
  };
2243
2507
  }
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
- });
2508
+ if (runtimeFn3().isNodeIsh || runtimeFn3().isDeno) {
2509
+ registerStoreProtocol({
2510
+ protocol: "file:",
2511
+ gateway: async (sthis) => {
2512
+ const { GatewayImpl } = await import("@fireproof/core/node");
2513
+ return new GatewayImpl(sthis);
2514
+ },
2515
+ test: async (sthis) => {
2516
+ const { GatewayTestImpl } = await import("@fireproof/core/node");
2517
+ return new GatewayTestImpl(sthis);
2518
+ }
2519
+ });
2520
+ }
2521
+ if (runtimeFn3().isBrowser) {
2522
+ registerStoreProtocol({
2523
+ protocol: "indexdb:",
2524
+ gateway: async (sthis) => {
2525
+ const { GatewayImpl } = await import("@fireproof/core/web");
2526
+ return new GatewayImpl(sthis);
2527
+ },
2528
+ test: async (sthis) => {
2529
+ const { GatewayTestImpl } = await import("@fireproof/core/web");
2530
+ return new GatewayTestImpl(sthis);
2531
+ }
2532
+ });
2533
+ }
2266
2534
 
2267
2535
  // src/blockstore/store-remote.ts
2268
2536
  async function RemoteDataStore(sthis, name, url, opts) {
@@ -2962,7 +3230,7 @@ var Index = class {
2962
3230
  // src/crdt-clock.ts
2963
3231
  import { advance } from "@fireproof/vendor/@web3-storage/pail/clock";
2964
3232
  import { root as root2 } from "@fireproof/vendor/@web3-storage/pail/crdt";
2965
- import { ResolveOnce as ResolveOnce4 } from "@adviser/cement";
3233
+ import { ResolveOnce as ResolveOnce5 } from "@adviser/cement";
2966
3234
 
2967
3235
  // src/apply-head-queue.ts
2968
3236
  function applyHeadQueue(worker, logger) {
@@ -3019,7 +3287,7 @@ var CRDTClock = class {
3019
3287
  this.zoomers = /* @__PURE__ */ new Set();
3020
3288
  this.watchers = /* @__PURE__ */ new Set();
3021
3289
  this.emptyWatchers = /* @__PURE__ */ new Set();
3022
- this._ready = new ResolveOnce4();
3290
+ this._ready = new ResolveOnce5();
3023
3291
  this.blockstore = blockstore;
3024
3292
  this.logger = ensureLogger(blockstore.sthis, "CRDTClock");
3025
3293
  this.applyHeadQueue = applyHeadQueue(this.int_applyHead.bind(this), this.logger);
@@ -3132,7 +3400,7 @@ async function advanceBlocks(logger, newHead, tblocks, head) {
3132
3400
  var CRDT = class {
3133
3401
  constructor(sthis, name, opts = {}) {
3134
3402
  this.indexers = /* @__PURE__ */ new Map();
3135
- this.onceReady = new ResolveOnce5();
3403
+ this.onceReady = new ResolveOnce6();
3136
3404
  this.sthis = sthis;
3137
3405
  this.name = name;
3138
3406
  this.logger = ensureLogger(sthis, "CRDT");
@@ -3252,7 +3520,7 @@ var Database = class {
3252
3520
  this._listening = false;
3253
3521
  this._listeners = /* @__PURE__ */ new Set();
3254
3522
  this._noupdate_listeners = /* @__PURE__ */ new Set();
3255
- this._ready = new ResolveOnce6();
3523
+ this._ready = new ResolveOnce7();
3256
3524
  this.name = name;
3257
3525
  this.opts = opts || this.opts;
3258
3526
  this.sthis = ensureSuperThis(this.opts);
@@ -3459,14 +3727,40 @@ __export(runtime_exports, {
3459
3727
  INDEXDB_VERSION: () => INDEXDB_VERSION,
3460
3728
  files: () => files_exports,
3461
3729
  getFileName: () => getFileName,
3462
- getFileSystem: () => getFileSystem,
3463
3730
  getPath: () => getPath,
3464
3731
  kb: () => key_bag_exports,
3465
3732
  kc: () => keyed_crypto_exports,
3466
3733
  mf: () => wait_pr_multiformats_exports,
3467
- runtimeFn: () => runtimeFn2
3734
+ runtimeFn: () => runtimeFn4
3468
3735
  });
3469
3736
 
3737
+ // src/runtime/gateways/file/node/utils.ts
3738
+ import { getStore as getStore2 } from "@fireproof/core";
3739
+ function getPath(url, sthis) {
3740
+ const basePath = url.pathname;
3741
+ const name = url.getParam("name");
3742
+ if (name) {
3743
+ const version = url.getParam("version");
3744
+ if (!version) throw sthis.logger.Error().Url(url).Msg(`version not found`).AsError();
3745
+ return sthis.pathOps.join(basePath, version, name);
3746
+ }
3747
+ return sthis.pathOps.join(basePath);
3748
+ }
3749
+ function getFileName(url, sthis) {
3750
+ const key = url.getParam("key");
3751
+ if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
3752
+ const res = getStore2(url, sthis, (...a) => a.join("-"));
3753
+ switch (res.store) {
3754
+ case "data":
3755
+ return sthis.pathOps.join(res.name, key + ".car");
3756
+ case "wal":
3757
+ case "meta":
3758
+ return sthis.pathOps.join(res.name, key + ".json");
3759
+ default:
3760
+ throw sthis.logger.Error().Url(url).Msg(`unsupported store type`).AsError();
3761
+ }
3762
+ }
3763
+
3470
3764
  // src/runtime/wait-pr-multiformats/index.ts
3471
3765
  var wait_pr_multiformats_exports = {};
3472
3766
  __export(wait_pr_multiformats_exports, {
@@ -3478,14 +3772,17 @@ __export(wait_pr_multiformats_exports, {
3478
3772
  var codec_interface_exports = {};
3479
3773
 
3480
3774
  // src/runtime/index.ts
3481
- import { runtimeFn as runtimeFn2 } from "@adviser/cement";
3775
+ import { runtimeFn as runtimeFn4 } from "@adviser/cement";
3776
+
3777
+ // src/runtime/gateways/file/version.ts
3778
+ var FILESTORE_VERSION = "v0.19-file";
3482
3779
 
3483
3780
  // src/runtime/gateways/indexdb/version.ts
3484
3781
  var INDEXDB_VERSION = "v0.19-indexdb";
3485
3782
 
3486
3783
  // src/version.ts
3487
3784
  var PACKAGE_VERSION = Object.keys({
3488
- "0.19.121-dev": "xxxx"
3785
+ "0.19.121": "xxxx"
3489
3786
  })[0];
3490
3787
  export {
3491
3788
  CRDT,