@fireproof/core 0.20.0-dev-preview-53 → 0.20.0-dev-preview-55

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.
package/index.cjs CHANGED
@@ -74,7 +74,7 @@ __export(index_exports, {
74
74
  module.exports = __toCommonJS(index_exports);
75
75
 
76
76
  // src/ledger.ts
77
- var import_cement20 = require("@adviser/cement");
77
+ var import_cement21 = require("@adviser/cement");
78
78
 
79
79
  // src/utils.ts
80
80
  var import_cement = require("@adviser/cement");
@@ -569,70 +569,34 @@ __export(files_exports, {
569
569
  decodeFile: () => decodeFile,
570
570
  encodeFile: () => encodeFile
571
571
  });
572
- var UnixFS = __toESM(require("@ipld/unixfs"), 1);
573
572
  var raw = __toESM(require("multiformats/codecs/raw"), 1);
574
- var import_fixed = require("@ipld/unixfs/file/chunker/fixed");
575
- var import_balanced = require("@ipld/unixfs/file/layout/balanced");
576
- var import_ipfs_unixfs_exporter = require("ipfs-unixfs-exporter");
577
- var queuingStrategy = UnixFS.withCapacity();
578
- var settings = UnixFS.configure({
579
- fileChunkEncoder: raw,
580
- smallFileEncoder: raw,
581
- chunker: (0, import_fixed.withMaxChunkSize)(1024 * 1024),
582
- fileLayout: (0, import_balanced.withWidth)(1024)
583
- });
584
- async function collect(collectable) {
585
- const chunks = [];
586
- await collectable.pipeTo(
587
- new WritableStream({
588
- write(chunk) {
589
- chunks.push(chunk);
590
- }
591
- })
592
- );
593
- return chunks;
594
- }
573
+ var import_cid = require("multiformats/cid");
574
+ var import_sha2 = require("multiformats/hashes/sha2");
575
+ var import_cement3 = require("@adviser/cement");
595
576
  async function encodeFile(blob) {
596
- const readable = createFileEncoderStream(blob);
597
- const blocks = await collect(readable);
598
- return { cid: blocks.at(-1).cid, blocks };
577
+ const data = await (0, import_cement3.top_uint8)(blob);
578
+ const bytes = raw.encode(data);
579
+ const hash = await import_sha2.sha256.digest(bytes);
580
+ const cid = import_cid.CID.create(1, raw.code, hash);
581
+ const block = { cid, bytes };
582
+ return { cid, blocks: [block] };
599
583
  }
600
- async function decodeFile(blocks, cid, meta) {
601
- const entry = await (0, import_ipfs_unixfs_exporter.exporter)(cid.toString(), blocks, { length: meta.size });
602
- const chunks = [];
603
- for await (const chunk of entry.content()) {
604
- chunks.push(chunk);
605
- }
606
- return new File(chunks, entry.name, { type: meta.type, lastModified: 0 });
584
+ function isHasBlockAGet(obj) {
585
+ return typeof obj.get === "function";
607
586
  }
608
- function createFileEncoderStream(blob) {
609
- const { readable, writable } = new TransformStream({}, queuingStrategy);
610
- const unixfsWriter = UnixFS.createWriter({ writable, settings });
611
- const fileBuilder = new UnixFSFileBuilder("", blob);
612
- void (async () => {
613
- await fileBuilder.finalize(unixfsWriter);
614
- await unixfsWriter.close();
615
- })();
616
- return readable;
587
+ async function decodeFile(blocks, cid, meta) {
588
+ if (!isHasBlockAGet(blocks)) {
589
+ return import_cement3.Result.Err(new Error("Invalid block storage"));
590
+ }
591
+ return (0, import_cement3.exception2Result)(async () => {
592
+ const bytes = await blocks.get(cid);
593
+ const data = raw.decode(bytes);
594
+ return new File([data], "file", {
595
+ type: meta.type,
596
+ lastModified: meta.lastModified || 0
597
+ });
598
+ });
617
599
  }
618
- var UnixFSFileBuilder = class {
619
- #file;
620
- constructor(name, file) {
621
- this.name = name;
622
- this.#file = file;
623
- }
624
- async finalize(writer) {
625
- const unixfsFileWriter = UnixFS.createFileWriter(writer);
626
- await this.#file.stream().pipeTo(
627
- new WritableStream({
628
- async write(chunk) {
629
- await unixfsFileWriter.write(chunk);
630
- }
631
- })
632
- );
633
- return await unixfsFileWriter.close();
634
- }
635
- };
636
600
 
637
601
  // src/runtime/key-bag.ts
638
602
  var key_bag_exports = {};
@@ -645,13 +609,13 @@ __export(key_bag_exports, {
645
609
  registerKeyBagProviderFactory: () => registerKeyBagProviderFactory,
646
610
  toKeyWithFingerPrint: () => toKeyWithFingerPrint
647
611
  });
648
- var import_cement4 = require("@adviser/cement");
612
+ var import_cement5 = require("@adviser/cement");
649
613
  var import_base582 = require("multiformats/bases/base58");
650
614
 
651
615
  // src/runtime/gateways/file/sys-file-system-factory.ts
652
- var import_cement3 = require("@adviser/cement");
616
+ var import_cement4 = require("@adviser/cement");
653
617
  function sysFileSystemFactory(uri) {
654
- const rt = (0, import_cement3.runtimeFn)();
618
+ const rt = (0, import_cement4.runtimeFn)();
655
619
  switch (true) {
656
620
  case rt.isNodeIsh:
657
621
  return import("@fireproof/core/node").then((m) => m.getSysFileSystem(uri));
@@ -771,7 +735,7 @@ async function toKeyWithFingerPrint(keybag, materialStrOrUint8) {
771
735
  }
772
736
  const key = await keybag.subtleKey(material);
773
737
  const fpr = await keybag.rt.crypto.digestSHA256(material);
774
- return import_cement4.Result.Ok({
738
+ return import_cement5.Result.Ok({
775
739
  key,
776
740
  fingerPrint: import_base582.base58btc.encode(new Uint8Array(fpr)),
777
741
  extract: async () => {
@@ -827,13 +791,13 @@ var keysByFingerprint = class _keysByFingerprint {
827
791
  def = !!def;
828
792
  const rKfp = await toKeyWithFingerPrint(this.keybag, materialStrOrUint8);
829
793
  if (rKfp.isErr()) {
830
- return import_cement4.Result.Err(rKfp);
794
+ return import_cement5.Result.Err(rKfp);
831
795
  }
832
796
  const kfp = rKfp.Ok();
833
797
  let found = this.keys[kfp.fingerPrint];
834
798
  if (found) {
835
799
  if (found.default === def) {
836
- return import_cement4.Result.Ok({
800
+ return import_cement5.Result.Ok({
837
801
  modified: false,
838
802
  kfp: found
839
803
  });
@@ -853,7 +817,7 @@ var keysByFingerprint = class _keysByFingerprint {
853
817
  if (keyBagAction) {
854
818
  this.keybag._upsertNamedKey(this);
855
819
  }
856
- return import_cement4.Result.Ok({
820
+ return import_cement5.Result.Ok({
857
821
  modified: keyBagAction && true,
858
822
  kfp: found
859
823
  });
@@ -883,8 +847,8 @@ var keysByFingerprint = class _keysByFingerprint {
883
847
  };
884
848
  var KeyBag = class {
885
849
  constructor(rt) {
886
- this._warnOnce = new import_cement4.ResolveOnce();
887
- this._seq = new import_cement4.ResolveSeq();
850
+ this._warnOnce = new import_cement5.ResolveOnce();
851
+ this._seq = new import_cement5.ResolveSeq();
888
852
  // async getNamedExtractableKey(name: string, failIfNotFound = false): Promise<Result<KeysByFingerprint>> {
889
853
  // const ret = await this.getNamedKey(name, failIfNotFound);
890
854
  // if (ret.isErr()) {
@@ -902,7 +866,7 @@ var KeyBag = class {
902
866
  // },
903
867
  // });
904
868
  // }
905
- this._namedKeyCache = new import_cement4.KeyedResolvOnce();
869
+ this._namedKeyCache = new import_cement5.KeyedResolvOnce();
906
870
  this.rt = rt;
907
871
  this.logger = ensureLogger(rt.sthis, "KeyBag");
908
872
  }
@@ -932,24 +896,24 @@ var KeyBag = class {
932
896
  async ensureKeyFromUrl(url, keyFactory) {
933
897
  const storeKey = url.getParam(PARAM.STORE_KEY);
934
898
  if (storeKey === "insecure") {
935
- return import_cement4.Result.Ok(url);
899
+ return import_cement5.Result.Ok(url);
936
900
  }
937
901
  if (!storeKey) {
938
902
  const keyName = `@${keyFactory()}@`;
939
903
  const ret = await this.getNamedKey(keyName);
940
904
  if (ret.isErr()) {
941
- return import_cement4.Result.Err(ret);
905
+ return import_cement5.Result.Err(ret);
942
906
  }
943
907
  const urb = url.build().setParam(PARAM.STORE_KEY, keyName);
944
- return import_cement4.Result.Ok(urb.URI());
908
+ return import_cement5.Result.Ok(urb.URI());
945
909
  }
946
910
  if (storeKey.startsWith("@") && storeKey.endsWith("@")) {
947
911
  const ret = await this.getNamedKey(storeKey);
948
912
  if (ret.isErr()) {
949
- return import_cement4.Result.Err(ret);
913
+ return import_cement5.Result.Err(ret);
950
914
  }
951
915
  }
952
- return import_cement4.Result.Ok(url);
916
+ return import_cement5.Result.Ok(url);
953
917
  }
954
918
  async toKeysItem(ki) {
955
919
  if (!ki) return void 0;
@@ -1008,7 +972,7 @@ var KeyBag = class {
1008
972
  this._namedKeyCache.unget(ksi.name);
1009
973
  }
1010
974
  await bag.set(await ksi.asKeysItem());
1011
- return import_cement4.Result.Ok(ksi);
975
+ return import_cement5.Result.Ok(ksi);
1012
976
  });
1013
977
  }
1014
978
  async _getNamedKey(name, failIfNotFound, material) {
@@ -1018,7 +982,7 @@ var KeyBag = class {
1018
982
  const named = await this.toKeysItem(await bag.get(name));
1019
983
  if (named) {
1020
984
  this.logger.Debug().Str("id", id).Str("name", name).Any("fprs", Object.keys(named.keys)).Msg("fingerPrint getNamedKey");
1021
- return import_cement4.Result.Ok(await keysByFingerprint.from(this, named));
985
+ return import_cement5.Result.Ok(await keysByFingerprint.from(this, named));
1022
986
  }
1023
987
  if (!named && failIfNotFound) {
1024
988
  this._namedKeyCache.unget(name);
@@ -1039,10 +1003,10 @@ var KeyBag = class {
1039
1003
  }
1040
1004
  const res = await kp.upsert(keyMaterial, true);
1041
1005
  if (res.isErr()) {
1042
- return import_cement4.Result.Err(res);
1006
+ return import_cement5.Result.Err(res);
1043
1007
  }
1044
1008
  this.logger.Debug().Str("id", id).Str("name", name).Str("fpr", res.Ok().kfp.fingerPrint).Msg("createKey getNamedKey-post");
1045
- return import_cement4.Result.Ok(kp);
1009
+ return import_cement5.Result.Ok(kp);
1046
1010
  });
1047
1011
  }
1048
1012
  async getNamedKey(name, failIfNotFound = false, material) {
@@ -1084,15 +1048,15 @@ function registerKeyBagProviderFactory(item) {
1084
1048
  function defaultKeyBagUrl(sthis) {
1085
1049
  let bagFnameOrUrl = sthis.env.get("FP_KEYBAG_URL");
1086
1050
  let url;
1087
- if ((0, import_cement4.runtimeFn)().isBrowser) {
1088
- url = import_cement4.URI.from(bagFnameOrUrl || "indexeddb://fp-keybag");
1051
+ if ((0, import_cement5.runtimeFn)().isBrowser) {
1052
+ url = import_cement5.URI.from(bagFnameOrUrl || "indexeddb://fp-keybag");
1089
1053
  } else {
1090
1054
  if (!bagFnameOrUrl) {
1091
1055
  const home = sthis.env.get("HOME");
1092
1056
  bagFnameOrUrl = `${home}/.fireproof/keybag`;
1093
- url = import_cement4.URI.from(`file://${bagFnameOrUrl}`);
1057
+ url = import_cement5.URI.from(`file://${bagFnameOrUrl}`);
1094
1058
  } else {
1095
- url = import_cement4.URI.from(bagFnameOrUrl);
1059
+ url = import_cement5.URI.from(bagFnameOrUrl);
1096
1060
  }
1097
1061
  }
1098
1062
  const logger = ensureLogger(sthis, "defaultKeyBagUrl");
@@ -1107,19 +1071,19 @@ function defaultKeyBagOpts(sthis, kbo) {
1107
1071
  const logger = ensureLogger(sthis, "KeyBag");
1108
1072
  let url;
1109
1073
  if (kbo.url) {
1110
- url = import_cement4.URI.from(kbo.url);
1074
+ url = import_cement5.URI.from(kbo.url);
1111
1075
  logger.Debug().Url(url).Msg("from opts");
1112
1076
  } else {
1113
1077
  let bagFnameOrUrl = sthis.env.get("FP_KEYBAG_URL");
1114
- if ((0, import_cement4.runtimeFn)().isBrowser) {
1115
- url = import_cement4.URI.from(bagFnameOrUrl || "indexeddb://fp-keybag");
1078
+ if ((0, import_cement5.runtimeFn)().isBrowser) {
1079
+ url = import_cement5.URI.from(bagFnameOrUrl || "indexeddb://fp-keybag");
1116
1080
  } else {
1117
1081
  if (!bagFnameOrUrl) {
1118
1082
  const home = sthis.env.get("HOME");
1119
1083
  bagFnameOrUrl = `${home}/.fireproof/keybag`;
1120
- url = import_cement4.URI.from(`file://${bagFnameOrUrl}`);
1084
+ url = import_cement5.URI.from(`file://${bagFnameOrUrl}`);
1121
1085
  } else {
1122
- url = import_cement4.URI.from(bagFnameOrUrl);
1086
+ url = import_cement5.URI.from(bagFnameOrUrl);
1123
1087
  }
1124
1088
  }
1125
1089
  logger.Debug().Url(url).Msg("from env");
@@ -1133,7 +1097,7 @@ function defaultKeyBagOpts(sthis, kbo) {
1133
1097
  }
1134
1098
  return {
1135
1099
  url,
1136
- crypto: kbo.crypto || (0, import_cement4.toCryptoRuntime)({}),
1100
+ crypto: kbo.crypto || (0, import_cement5.toCryptoRuntime)({}),
1137
1101
  sthis,
1138
1102
  logger,
1139
1103
  keyLength: kbo.keyLength || 16,
@@ -1143,7 +1107,7 @@ function defaultKeyBagOpts(sthis, kbo) {
1143
1107
  }
1144
1108
  };
1145
1109
  }
1146
- var _keyBags = new import_cement4.KeyedResolvOnce();
1110
+ var _keyBags = new import_cement5.KeyedResolvOnce();
1147
1111
  async function getKeyBag(sthis, kbo = {}) {
1148
1112
  await sthis.start();
1149
1113
  const rt = defaultKeyBagOpts(sthis, kbo);
@@ -1151,7 +1115,7 @@ async function getKeyBag(sthis, kbo = {}) {
1151
1115
  }
1152
1116
 
1153
1117
  // src/blockstore/register-store-protocol.ts
1154
- var import_cement10 = require("@adviser/cement");
1118
+ var import_cement11 = require("@adviser/cement");
1155
1119
 
1156
1120
  // src/runtime/gateways/file/version.ts
1157
1121
  var FILESTORE_VERSION = "v0.19-file";
@@ -1160,10 +1124,9 @@ var FILESTORE_VERSION = "v0.19-file";
1160
1124
  var INDEXEDDB_VERSION = "v0.19-indexeddb";
1161
1125
 
1162
1126
  // src/runtime/gateways/file/gateway-impl.ts
1163
- var import_cement5 = require("@adviser/cement");
1127
+ var import_cement6 = require("@adviser/cement");
1164
1128
 
1165
1129
  // src/runtime/gateways/file/utils.ts
1166
- var import_core = require("@fireproof/core");
1167
1130
  function getPath(url, sthis) {
1168
1131
  const basePath = url.pathname;
1169
1132
  const name = url.getParam("name");
@@ -1175,7 +1138,7 @@ function getPath(url, sthis) {
1175
1138
  function getFileName(url, sthis) {
1176
1139
  const key = url.getParam("key");
1177
1140
  if (!key) throw sthis.logger.Error().Url(url).Msg(`key not found`).AsError();
1178
- const res = (0, import_core.getStore)(url, sthis, (...a) => a.join("-"));
1141
+ const res = getStore(url, sthis, (...a) => a.join("-"));
1179
1142
  switch (res.fromUrl) {
1180
1143
  case "file":
1181
1144
  return sthis.pathOps.join(res.name, key);
@@ -1190,7 +1153,7 @@ function getFileName(url, sthis) {
1190
1153
  }
1191
1154
 
1192
1155
  // src/runtime/gateways/file/gateway-impl.ts
1193
- var versionFiles = new import_cement5.KeyedResolvOnce();
1156
+ var versionFiles = new import_cement6.KeyedResolvOnce();
1194
1157
  var FileGateway = class {
1195
1158
  constructor(sthis, fs) {
1196
1159
  this.fs = fs;
@@ -1215,7 +1178,7 @@ var FileGateway = class {
1215
1178
  });
1216
1179
  }
1217
1180
  start(baseURL, sthis) {
1218
- return (0, import_cement5.exception2Result)(async () => {
1181
+ return (0, import_cement6.exception2Result)(async () => {
1219
1182
  await this.fs.start();
1220
1183
  const url = baseURL.build();
1221
1184
  url.defParam(PARAM.VERSION, FILESTORE_VERSION);
@@ -1229,10 +1192,10 @@ var FileGateway = class {
1229
1192
  });
1230
1193
  }
1231
1194
  async buildUrl(baseUrl, key) {
1232
- return import_cement5.Result.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI());
1195
+ return import_cement6.Result.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI());
1233
1196
  }
1234
1197
  async close() {
1235
- return import_cement5.Result.Ok(void 0);
1198
+ return import_cement6.Result.Ok(void 0);
1236
1199
  }
1237
1200
  getFilePath(url, sthis) {
1238
1201
  const key = url.getParam(PARAM.KEY);
@@ -1240,7 +1203,7 @@ var FileGateway = class {
1240
1203
  return sthis.pathOps.join(getPath(url, sthis), getFileName(url, sthis));
1241
1204
  }
1242
1205
  async put(url, bytes, sthis) {
1243
- return (0, import_cement5.exception2Result)(async () => {
1206
+ return (0, import_cement6.exception2Result)(async () => {
1244
1207
  const file = await this.getFilePath(url, sthis);
1245
1208
  sthis.logger.Debug().Str("url", url.toString()).Str("file", file).Msg("put");
1246
1209
  await this.fs.writefile(file, bytes);
@@ -1252,17 +1215,17 @@ var FileGateway = class {
1252
1215
  try {
1253
1216
  sthis.logger.Debug().Url(url).Str("file", file).Msg("get");
1254
1217
  const res = await this.fs.readfile(file);
1255
- return import_cement5.Result.Ok(res);
1218
+ return import_cement6.Result.Ok(res);
1256
1219
  } catch (e) {
1257
1220
  if (isNotFoundError(e)) {
1258
- return import_cement5.Result.Err(new NotFoundError(`file not found: ${file}`));
1221
+ return import_cement6.Result.Err(new NotFoundError(`file not found: ${file}`));
1259
1222
  }
1260
- return import_cement5.Result.Err(e);
1223
+ return import_cement6.Result.Err(e);
1261
1224
  }
1262
1225
  });
1263
1226
  }
1264
1227
  async delete(url, sthis) {
1265
- return (0, import_cement5.exception2Result)(async () => {
1228
+ return (0, import_cement6.exception2Result)(async () => {
1266
1229
  await this.fs.unlink(this.getFilePath(url, sthis));
1267
1230
  });
1268
1231
  }
@@ -1288,7 +1251,7 @@ var FileGateway = class {
1288
1251
  }
1289
1252
  }
1290
1253
  }
1291
- return import_cement5.Result.Ok(void 0);
1254
+ return import_cement6.Result.Ok(void 0);
1292
1255
  }
1293
1256
  async getPlain(iurl, key, sthis) {
1294
1257
  const url = iurl.build().setParam(PARAM.KEY, key).URI();
@@ -1296,7 +1259,7 @@ var FileGateway = class {
1296
1259
  sthis.logger.Debug().Url(url).Str("dbFile", dbFile).Msg("get");
1297
1260
  const buffer = await this.fs.readfile(dbFile);
1298
1261
  sthis.logger.Debug().Url(url).Str("dbFile", dbFile).Len(buffer).Msg("got");
1299
- return import_cement5.Result.Ok(buffer);
1262
+ return import_cement6.Result.Ok(buffer);
1300
1263
  }
1301
1264
  };
1302
1265
 
@@ -1305,7 +1268,7 @@ var gateway_exports = {};
1305
1268
  __export(gateway_exports, {
1306
1269
  MemoryGateway: () => MemoryGateway
1307
1270
  });
1308
- var import_cement6 = require("@adviser/cement");
1271
+ var import_cement7 = require("@adviser/cement");
1309
1272
 
1310
1273
  // src/runtime/gateways/memory/version.ts
1311
1274
  var MEMORY_VERSION = "v0.19-memory";
@@ -1318,14 +1281,14 @@ var MemoryGateway = class {
1318
1281
  this.sthis = sthis;
1319
1282
  }
1320
1283
  buildUrl(baseUrl, key) {
1321
- return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI()));
1284
+ return Promise.resolve(import_cement7.Result.Ok(baseUrl.build().setParam(PARAM.KEY, key).URI()));
1322
1285
  }
1323
1286
  start(baseUrl) {
1324
- return Promise.resolve(import_cement6.Result.Ok(baseUrl.build().setParam(PARAM.VERSION, MEMORY_VERSION).URI()));
1287
+ return Promise.resolve(import_cement7.Result.Ok(baseUrl.build().setParam(PARAM.VERSION, MEMORY_VERSION).URI()));
1325
1288
  }
1326
1289
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
1327
1290
  close(baseUrl) {
1328
- return Promise.resolve(import_cement6.Result.Ok(void 0));
1291
+ return Promise.resolve(import_cement7.Result.Ok(void 0));
1329
1292
  }
1330
1293
  destroy(baseUrl) {
1331
1294
  const keyUrl = baseUrl.toString();
@@ -1335,38 +1298,38 @@ var MemoryGateway = class {
1335
1298
  }
1336
1299
  }
1337
1300
  this.memorys.clear();
1338
- return Promise.resolve(import_cement6.Result.Ok(void 0));
1301
+ return Promise.resolve(import_cement7.Result.Ok(void 0));
1339
1302
  }
1340
1303
  async put(url, bytes) {
1341
1304
  this.memorys.set(url.toString(), bytes);
1342
- return import_cement6.Result.Ok(void 0);
1305
+ return import_cement7.Result.Ok(void 0);
1343
1306
  }
1344
1307
  // get could return a NotFoundError if the key is not found
1345
1308
  get(url) {
1346
1309
  const x = this.memorys.get(url.toString());
1347
1310
  if (!x) {
1348
- return Promise.resolve(import_cement6.Result.Err(new NotFoundError(`not found: ${url.toString()}`)));
1311
+ return Promise.resolve(import_cement7.Result.Err(new NotFoundError(`not found: ${url.toString()}`)));
1349
1312
  }
1350
- return Promise.resolve(import_cement6.Result.Ok(x));
1313
+ return Promise.resolve(import_cement7.Result.Ok(x));
1351
1314
  }
1352
1315
  delete(url) {
1353
1316
  this.memorys.delete(url.toString());
1354
- return Promise.resolve(import_cement6.Result.Ok(void 0));
1317
+ return Promise.resolve(import_cement7.Result.Ok(void 0));
1355
1318
  }
1356
1319
  async getPlain(url, key) {
1357
1320
  const x = this.memorys.get(url.build().setParam(PARAM.KEY, key).toString());
1358
1321
  if (!x) {
1359
- return import_cement6.Result.Err(new NotFoundError("not found"));
1322
+ return import_cement7.Result.Err(new NotFoundError("not found"));
1360
1323
  }
1361
- return import_cement6.Result.Ok(x);
1324
+ return import_cement7.Result.Ok(x);
1362
1325
  }
1363
1326
  };
1364
1327
 
1365
1328
  // src/runtime/gateways/def-serde-gateway.ts
1366
- var import_cement9 = require("@adviser/cement");
1329
+ var import_cement10 = require("@adviser/cement");
1367
1330
 
1368
1331
  // src/blockstore/fp-envelope.ts
1369
- var import_cement7 = require("@adviser/cement");
1332
+ var import_cement8 = require("@adviser/cement");
1370
1333
  var FPEnvelopeTypes = {
1371
1334
  CAR: "car",
1372
1335
  FILE: "file",
@@ -1374,14 +1337,14 @@ var FPEnvelopeTypes = {
1374
1337
  WAL: "wal"
1375
1338
  };
1376
1339
  function Car2FPMsg(fpcar) {
1377
- return import_cement7.Result.Ok({ type: FPEnvelopeTypes.CAR, payload: fpcar });
1340
+ return import_cement8.Result.Ok({ type: FPEnvelopeTypes.CAR, payload: fpcar });
1378
1341
  }
1379
1342
  function File2FPMsg(fpfile) {
1380
- return import_cement7.Result.Ok({ type: FPEnvelopeTypes.FILE, payload: fpfile });
1343
+ return import_cement8.Result.Ok({ type: FPEnvelopeTypes.FILE, payload: fpfile });
1381
1344
  }
1382
1345
 
1383
1346
  // src/runtime/gateways/fp-envelope-serialize.ts
1384
- var import_cement8 = require("@adviser/cement");
1347
+ var import_cement9 = require("@adviser/cement");
1385
1348
  var import_clock = require("@fireproof/vendor/@web3-storage/pail/clock");
1386
1349
  var import_base64 = require("multiformats/bases/base64");
1387
1350
  var import_multiformats = require("multiformats");
@@ -1420,10 +1383,10 @@ function WALState2Serialized(sthis, wal) {
1420
1383
  return serializedWAL;
1421
1384
  }
1422
1385
  var defaultEncoder = {
1423
- car: async (sthis, payload) => import_cement8.Result.Ok(payload),
1424
- file: async (sthis, payload) => import_cement8.Result.Ok(payload),
1425
- meta: async (sthis, payload) => import_cement8.Result.Ok(sthis.txt.encode(JSON.stringify(payload))),
1426
- wal: async (sthis, payload) => import_cement8.Result.Ok(sthis.txt.encode(JSON.stringify(payload)))
1386
+ car: async (sthis, payload) => import_cement9.Result.Ok(payload),
1387
+ file: async (sthis, payload) => import_cement9.Result.Ok(payload),
1388
+ meta: async (sthis, payload) => import_cement9.Result.Ok(sthis.txt.encode(JSON.stringify(payload))),
1389
+ wal: async (sthis, payload) => import_cement9.Result.Ok(sthis.txt.encode(JSON.stringify(payload)))
1427
1390
  };
1428
1391
  async function fpSerialize(sthis, env, pencoder) {
1429
1392
  const encoder = {
@@ -1445,13 +1408,13 @@ async function fpSerialize(sthis, env, pencoder) {
1445
1408
  }
1446
1409
  async function decode2DbMetaEvents(sthis, rserializedMeta) {
1447
1410
  if (rserializedMeta.isErr()) {
1448
- return import_cement8.Result.Err(rserializedMeta.Err());
1411
+ return import_cement9.Result.Err(rserializedMeta.Err());
1449
1412
  }
1450
1413
  const serializedMeta = rserializedMeta.unwrap();
1451
1414
  if (!Array.isArray(serializedMeta)) {
1452
1415
  return sthis.logger.Debug().Any("metaEntries", serializedMeta).Msg("No data in MetaEntries").ResultError();
1453
1416
  }
1454
- return import_cement8.Result.Ok(
1417
+ return import_cement9.Result.Ok(
1455
1418
  await Promise.all(
1456
1419
  serializedMeta.map(async (metaEntry) => {
1457
1420
  const eventBlock = await (0, import_clock.decodeEventBlock)(import_base64.base64pad.decode(metaEntry.data));
@@ -1473,10 +1436,10 @@ function toCid(sthis, link) {
1473
1436
  }
1474
1437
  async function decode2WalState(sthis, rserializedWAL) {
1475
1438
  if (rserializedWAL.isErr()) {
1476
- return import_cement8.Result.Err(rserializedWAL.Err());
1439
+ return import_cement9.Result.Err(rserializedWAL.Err());
1477
1440
  }
1478
1441
  const serializedWAL = rserializedWAL.unwrap();
1479
- return import_cement8.Result.Ok({
1442
+ return import_cement9.Result.Ok({
1480
1443
  fileOperations: (serializedWAL.fileOperations || []).map((fop) => ({
1481
1444
  cid: toCid(sthis, fop.cid),
1482
1445
  public: !!fop.public
@@ -1490,16 +1453,16 @@ async function decode2WalState(sthis, rserializedWAL) {
1490
1453
  });
1491
1454
  }
1492
1455
  var defaultDecoder = {
1493
- car: async (sthis, payload) => import_cement8.Result.Ok(payload),
1494
- file: async (sthis, payload) => import_cement8.Result.Ok(payload),
1495
- meta: async (sthis, payload) => (0, import_cement8.exception2Result)(() => JSON.parse(sthis.txt.decode(payload))),
1496
- wal: async (sthis, payload) => (0, import_cement8.exception2Result)(() => JSON.parse(sthis.txt.decode(payload)))
1456
+ car: async (sthis, payload) => import_cement9.Result.Ok(payload),
1457
+ file: async (sthis, payload) => import_cement9.Result.Ok(payload),
1458
+ meta: async (sthis, payload) => (0, import_cement9.exception2Result)(() => JSON.parse(sthis.txt.decode(payload))),
1459
+ wal: async (sthis, payload) => (0, import_cement9.exception2Result)(() => JSON.parse(sthis.txt.decode(payload)))
1497
1460
  };
1498
1461
  function makeFPEnvelope(type, payload) {
1499
1462
  if (payload.isErr()) {
1500
- return import_cement8.Result.Err(payload.Err());
1463
+ return import_cement9.Result.Err(payload.Err());
1501
1464
  }
1502
- return import_cement8.Result.Ok({
1465
+ return import_cement9.Result.Ok({
1503
1466
  type,
1504
1467
  payload: payload.unwrap()
1505
1468
  });
@@ -1507,7 +1470,7 @@ function makeFPEnvelope(type, payload) {
1507
1470
  async function fpDeserialize(sthis, url, intoRaw, pdecoder) {
1508
1471
  const rraw = await coercePromiseIntoUint8(intoRaw);
1509
1472
  if (rraw.isErr()) {
1510
- return import_cement8.Result.Err(rraw.Err());
1473
+ return import_cement9.Result.Err(rraw.Err());
1511
1474
  }
1512
1475
  const raw2 = rraw.unwrap();
1513
1476
  const decoder = {
@@ -1558,12 +1521,12 @@ var DefSerdeGateway = class {
1558
1521
  }
1559
1522
  async get({ loader: { sthis }, decoder }, url) {
1560
1523
  const res = await this.gw.get(url, sthis);
1561
- if (res.isErr()) return import_cement9.Result.Err(res.Err());
1524
+ if (res.isErr()) return import_cement10.Result.Err(res.Err());
1562
1525
  return fpDeserialize(sthis, url, res, decoder);
1563
1526
  }
1564
1527
  async subscribe({ loader: { sthis }, decoder }, url, callback) {
1565
1528
  function rawCallback(raw2) {
1566
- return fpDeserialize(sthis, url, import_cement9.Result.Ok(raw2), decoder).then((res) => {
1529
+ return fpDeserialize(sthis, url, import_cement10.Result.Ok(raw2), decoder).then((res) => {
1567
1530
  if (res.isErr()) {
1568
1531
  sthis.logger.Error().Err(res).Msg("Failed to deserialize");
1569
1532
  return;
@@ -1573,12 +1536,12 @@ var DefSerdeGateway = class {
1573
1536
  }
1574
1537
  if (!this.gw.subscribe) {
1575
1538
  if (!url.hasParam(PARAM.SELF_REFLECT)) {
1576
- return import_cement9.Result.Ok(() => {
1539
+ return import_cement10.Result.Ok(() => {
1577
1540
  });
1578
1541
  }
1579
1542
  const urlWithoutKey = url.build().delParam(PARAM.KEY).delParam(PARAM.SELF_REFLECT).toString();
1580
1543
  this.subscribeFn.set(urlWithoutKey, rawCallback);
1581
- return import_cement9.Result.Ok(() => {
1544
+ return import_cement10.Result.Ok(() => {
1582
1545
  this.subscribeFn.delete(urlWithoutKey);
1583
1546
  });
1584
1547
  }
@@ -1655,10 +1618,10 @@ function defaultGatewayFactoryItem() {
1655
1618
  return found;
1656
1619
  }
1657
1620
  function defaultURI(sthis) {
1658
- const rt = (0, import_cement10.runtimeFn)();
1659
- return import_cement10.BuildURI.from("file://").pathname(`${sthis.env.get("HOME")}/.fireproof/${FILESTORE_VERSION.replace(/-.*$/, "")}`).setParam(PARAM.VERSION, FILESTORE_VERSION).setParam(PARAM.URL_GEN, "default").setParam(PARAM.RUNTIME, rt.isNodeIsh ? "node" : rt.isDeno ? "deno" : "unknown").URI();
1621
+ const rt = (0, import_cement11.runtimeFn)();
1622
+ return import_cement11.BuildURI.from("file://").pathname(`${sthis.env.get("HOME")}/.fireproof/${FILESTORE_VERSION.replace(/-.*$/, "")}`).setParam(PARAM.VERSION, FILESTORE_VERSION).setParam(PARAM.URL_GEN, "default").setParam(PARAM.RUNTIME, rt.isNodeIsh ? "node" : rt.isDeno ? "deno" : "unknown").URI();
1660
1623
  }
1661
- if ((0, import_cement10.runtimeFn)().isNodeIsh || (0, import_cement10.runtimeFn)().isDeno) {
1624
+ if ((0, import_cement11.runtimeFn)().isNodeIsh || (0, import_cement11.runtimeFn)().isDeno) {
1662
1625
  registerStoreProtocol({
1663
1626
  protocol: "file:",
1664
1627
  isDefault: true,
@@ -1668,12 +1631,12 @@ if ((0, import_cement10.runtimeFn)().isNodeIsh || (0, import_cement10.runtimeFn)
1668
1631
  }
1669
1632
  });
1670
1633
  }
1671
- if ((0, import_cement10.runtimeFn)().isBrowser) {
1634
+ if ((0, import_cement11.runtimeFn)().isBrowser) {
1672
1635
  registerStoreProtocol({
1673
1636
  protocol: "indexeddb:",
1674
1637
  isDefault: true,
1675
1638
  defaultURI: () => {
1676
- return import_cement10.BuildURI.from("indexeddb://").pathname("fp").setParam(PARAM.VERSION, INDEXEDDB_VERSION).setParam(PARAM.RUNTIME, "browser").URI();
1639
+ return import_cement11.BuildURI.from("indexeddb://").pathname("fp").setParam(PARAM.VERSION, INDEXEDDB_VERSION).setParam(PARAM.RUNTIME, "browser").URI();
1677
1640
  },
1678
1641
  gateway: async () => {
1679
1642
  const { GatewayImpl } = await import("@fireproof/core/indexeddb");
@@ -1686,7 +1649,7 @@ registerStoreProtocol({
1686
1649
  protocol: "memory:",
1687
1650
  isDefault: false,
1688
1651
  defaultURI: () => {
1689
- return import_cement10.BuildURI.from("memory://").pathname("ram").URI();
1652
+ return import_cement11.BuildURI.from("memory://").pathname("ram").URI();
1690
1653
  },
1691
1654
  gateway: async (sthis) => {
1692
1655
  return new MemoryGateway(sthis, memory);
@@ -1699,44 +1662,44 @@ __export(block_exports, {
1699
1662
  Block: () => Block,
1700
1663
  create: () => create,
1701
1664
  createUnsafe: () => createUnsafe,
1702
- decode: () => decode,
1703
- encode: () => encode
1665
+ decode: () => decode2,
1666
+ encode: () => encode2
1704
1667
  });
1705
1668
  var import_multiformats2 = require("multiformats");
1706
1669
  var import_block = require("multiformats/block");
1707
1670
  var Block = import_block.Block;
1708
- async function decode({
1671
+ async function decode2({
1709
1672
  bytes,
1710
1673
  codec: codec3,
1711
- hasher: hasher6
1674
+ hasher: hasher7
1712
1675
  }) {
1713
1676
  if (bytes == null) throw new Error('Missing required argument "bytes"');
1714
- if (codec3 == null || hasher6 == null) throw new Error("Missing required argument: codec or hasher");
1677
+ if (codec3 == null || hasher7 == null) throw new Error("Missing required argument: codec or hasher");
1715
1678
  const value = await Promise.resolve(codec3.decode(bytes));
1716
1679
  let toHash = bytes;
1717
1680
  if (codec3.valueToHashBytes) {
1718
1681
  toHash = await Promise.resolve(codec3.valueToHashBytes(value));
1719
1682
  }
1720
- const hash = await hasher6.digest(toHash);
1683
+ const hash = await hasher7.digest(toHash);
1721
1684
  const cid = import_multiformats2.CID.create(1, codec3.code, hash);
1722
1685
  return new import_block.Block({ value, bytes: toHash, cid });
1723
1686
  }
1724
- async function encode({
1687
+ async function encode2({
1725
1688
  value,
1726
1689
  codec: codec3,
1727
- hasher: hasher6
1690
+ hasher: hasher7
1728
1691
  }) {
1729
1692
  if (typeof value === "undefined") throw new Error('Missing required argument "value"');
1730
- if (codec3 == null || hasher6 == null) throw new Error("Missing required argument: codec or hasher");
1693
+ if (codec3 == null || hasher7 == null) throw new Error("Missing required argument: codec or hasher");
1731
1694
  let bytes;
1732
1695
  let hash;
1733
1696
  if (codec3.bytesToHash) {
1734
1697
  const hashable = await Promise.resolve(codec3.bytesToHash(value));
1735
- hash = await hasher6.digest(hashable);
1698
+ hash = await hasher7.digest(hashable);
1736
1699
  bytes = await Promise.resolve(codec3.encode(value));
1737
1700
  } else {
1738
1701
  bytes = await Promise.resolve(codec3.encode(value));
1739
- hash = await hasher6.digest(bytes);
1702
+ hash = await hasher7.digest(bytes);
1740
1703
  }
1741
1704
  const cid = import_multiformats2.CID.create(1, codec3.code, hash);
1742
1705
  return new Block({ value, bytes, cid });
@@ -1744,13 +1707,13 @@ async function encode({
1744
1707
  async function create({
1745
1708
  bytes,
1746
1709
  cid,
1747
- hasher: hasher6,
1710
+ hasher: hasher7,
1748
1711
  codec: codec3
1749
1712
  }) {
1750
1713
  if (bytes == null) throw new Error('Missing required argument "bytes"');
1751
- if (hasher6 == null) throw new Error('Missing required argument "hasher"');
1714
+ if (hasher7 == null) throw new Error('Missing required argument "hasher"');
1752
1715
  const value = await Promise.resolve(codec3.decode(bytes));
1753
- const hash = await hasher6.digest(bytes);
1716
+ const hash = await hasher7.digest(bytes);
1754
1717
  if (!import_multiformats2.bytes.equals(cid.multihash.bytes, hash.bytes)) {
1755
1718
  throw new Error("CID hash does not match bytes");
1756
1719
  }
@@ -1777,11 +1740,11 @@ async function createUnsafe({
1777
1740
  }
1778
1741
 
1779
1742
  // src/indexer-helpers.ts
1780
- var import_sha2 = require("multiformats/hashes/sha2");
1743
+ var import_sha22 = require("multiformats/hashes/sha2");
1781
1744
  var codec = __toESM(require("@ipld/dag-cbor"), 1);
1782
1745
  var import_charwise = __toESM(require("charwise"), 1);
1783
1746
  var DbIndex = __toESM(require("prolly-trees/db-index"), 1);
1784
- var import_utils8 = require("prolly-trees/utils");
1747
+ var import_utils9 = require("prolly-trees/utils");
1785
1748
  var import_cache = require("prolly-trees/cache");
1786
1749
  var IndexTree = class {
1787
1750
  };
@@ -1789,17 +1752,17 @@ function refCompare(aRef, bRef) {
1789
1752
  if (Number.isNaN(aRef)) return -1;
1790
1753
  if (Number.isNaN(bRef)) throw new Error("ref may not be Infinity or NaN");
1791
1754
  if (aRef === Infinity) return 1;
1792
- return (0, import_utils8.simpleCompare)(aRef, bRef);
1755
+ return (0, import_utils9.simpleCompare)(aRef, bRef);
1793
1756
  }
1794
1757
  function compare(a, b) {
1795
1758
  const [aKey, aRef] = a;
1796
1759
  const [bKey, bRef] = b;
1797
- const comp = (0, import_utils8.simpleCompare)(aKey, bKey);
1760
+ const comp = (0, import_utils9.simpleCompare)(aKey, bKey);
1798
1761
  if (comp !== 0) return comp;
1799
1762
  return refCompare(aRef, bRef);
1800
1763
  }
1801
- var byKeyOpts = { cache: import_cache.nocache, chunker: (0, import_utils8.bf)(30), codec, hasher: import_sha2.sha256, compare };
1802
- var byIdOpts = { cache: import_cache.nocache, chunker: (0, import_utils8.bf)(30), codec, hasher: import_sha2.sha256, compare: import_utils8.simpleCompare };
1764
+ var byKeyOpts = { cache: import_cache.nocache, chunker: (0, import_utils9.bf)(30), codec, hasher: import_sha22.sha256, compare };
1765
+ var byIdOpts = { cache: import_cache.nocache, chunker: (0, import_utils9.bf)(30), codec, hasher: import_sha22.sha256, compare: import_utils9.simpleCompare };
1803
1766
  function indexEntriesForChanges(changes, mapFn) {
1804
1767
  const indexEntries = [];
1805
1768
  changes.forEach(({ id: key, value, del }) => {
@@ -1827,7 +1790,7 @@ function makeProllyGetBlock(blocks) {
1827
1790
  const block = await blocks.get(address);
1828
1791
  if (!block) throw new Error(`Missing block ${address.toString()}`);
1829
1792
  const { cid, bytes } = block;
1830
- return create({ cid, bytes, hasher: import_sha2.sha256, codec });
1793
+ return create({ cid, bytes, hasher: import_sha22.sha256, codec });
1831
1794
  };
1832
1795
  }
1833
1796
  async function bulkIndex(logger, tblocks, inIndex, indexEntries, opts) {
@@ -2200,6 +2163,9 @@ var DatabaseImpl = class {
2200
2163
  const result = await this.ledger.writeQueue.push({ id, del: true });
2201
2164
  return { id, clock: result?.head, name: this.name };
2202
2165
  }
2166
+ async remove(id) {
2167
+ return this.del(id);
2168
+ }
2203
2169
  async changes(since = [], opts = {}) {
2204
2170
  await this.ready();
2205
2171
  this.logger.Debug().Any("since", since).Any("opts", opts).Msg("changes");
@@ -2242,7 +2208,7 @@ var DatabaseImpl = class {
2242
2208
  };
2243
2209
 
2244
2210
  // src/crdt.ts
2245
- var import_cement19 = require("@adviser/cement");
2211
+ var import_cement20 = require("@adviser/cement");
2246
2212
 
2247
2213
  // src/blockstore/index.ts
2248
2214
  var blockstore_exports = {};
@@ -2266,6 +2232,7 @@ __export(blockstore_exports, {
2266
2232
  MetaActiveStore: () => MetaActiveStore,
2267
2233
  PassThroughGateway: () => PassThroughGateway,
2268
2234
  TaskManager: () => TaskManager,
2235
+ URIInterceptor: () => URIInterceptor,
2269
2236
  WALActiveStore: () => WALActiveStore,
2270
2237
  createAttachedStores: () => createAttachedStores,
2271
2238
  createDbMetaEvent: () => createDbMetaEvent,
@@ -2273,7 +2240,7 @@ __export(blockstore_exports, {
2273
2240
  ensureStoreEnDeFile: () => ensureStoreEnDeFile,
2274
2241
  getDefaultURI: () => getDefaultURI,
2275
2242
  getGatewayFactoryItem: () => getGatewayFactoryItem,
2276
- getStartedGateway: () => getStartedGateway,
2243
+ getInterceptableGateway: () => getInterceptableGateway,
2277
2244
  parseCarFile: () => parseCarFile,
2278
2245
  registerStoreProtocol: () => registerStoreProtocol,
2279
2246
  toCIDBlock: () => toCIDBlock,
@@ -2333,7 +2300,7 @@ var WALActiveStore = class extends BaseActiveStore {
2333
2300
  };
2334
2301
 
2335
2302
  // src/blockstore/store-factory.ts
2336
- var import_cement17 = require("@adviser/cement");
2303
+ var import_cement18 = require("@adviser/cement");
2337
2304
 
2338
2305
  // src/blockstore/store.ts
2339
2306
  var import_cement16 = require("@adviser/cement");
@@ -2341,16 +2308,16 @@ var import_cement16 = require("@adviser/cement");
2341
2308
  // src/blockstore/loader.ts
2342
2309
  var import_p_limit = __toESM(require("p-limit"), 1);
2343
2310
  var import_reader = require("@ipld/car/reader");
2344
- var import_cement14 = require("@adviser/cement");
2311
+ var import_cement15 = require("@adviser/cement");
2345
2312
 
2346
2313
  // src/blockstore/loader-helpers.ts
2347
- var import_sha22 = require("multiformats/hashes/sha2");
2314
+ var import_sha23 = require("multiformats/hashes/sha2");
2348
2315
  var dagCodec = __toESM(require("@ipld/dag-cbor"), 1);
2349
2316
  async function parseCarFile(reader, logger) {
2350
2317
  const roots = await reader.roots;
2351
2318
  const header = reader.blocks.find((i) => i.cid.equals(roots[0]));
2352
2319
  if (!header) throw logger.Error().Msg("missing header block").AsError();
2353
- const dec = await decode({ bytes: header.bytes, hasher: import_sha22.sha256, codec: dagCodec });
2320
+ const dec = await decode2({ bytes: header.bytes, hasher: import_sha23.sha256, codec: dagCodec });
2354
2321
  const fpvalue = dec.value;
2355
2322
  if (fpvalue && !fpvalue.fp) {
2356
2323
  throw logger.Error().Msg("missing fp").AsError();
@@ -2360,7 +2327,7 @@ async function parseCarFile(reader, logger) {
2360
2327
 
2361
2328
  // src/blockstore/transaction.ts
2362
2329
  var import_block4 = require("@fireproof/vendor/@web3-storage/pail/block");
2363
- var import_cement11 = require("@adviser/cement");
2330
+ var import_cement12 = require("@adviser/cement");
2364
2331
  var CarTransactionImpl = class {
2365
2332
  #memblock = new import_block4.MemoryBlockstore();
2366
2333
  #hackUnshift;
@@ -2415,7 +2382,7 @@ function defaultedBlockstoreRuntime(sthis, opts, component, ctx) {
2415
2382
  ...opts,
2416
2383
  logger,
2417
2384
  keyBag: opts.keyBag || {},
2418
- crypto: (0, import_cement11.toCryptoRuntime)(opts.crypto),
2385
+ crypto: (0, import_cement12.toCryptoRuntime)(opts.crypto),
2419
2386
  storeUrls: opts.storeUrls,
2420
2387
  taskManager: {
2421
2388
  removeAfter: 3,
@@ -2591,7 +2558,7 @@ var CompactionFetcher = class {
2591
2558
  };
2592
2559
 
2593
2560
  // src/blockstore/commit-queue.ts
2594
- var import_cement12 = require("@adviser/cement");
2561
+ var import_cement13 = require("@adviser/cement");
2595
2562
  var CommitQueue = class {
2596
2563
  constructor() {
2597
2564
  this.queue = [];
@@ -2602,7 +2569,7 @@ var CommitQueue = class {
2602
2569
  if (this.queue.length === 0 && !this.processing) {
2603
2570
  return Promise.resolve();
2604
2571
  }
2605
- const fn = new import_cement12.Future();
2572
+ const fn = new import_cement13.Future();
2606
2573
  this._waitIdleItems.add(fn);
2607
2574
  return fn.asPromise();
2608
2575
  }
@@ -2644,7 +2611,7 @@ var CommitQueue = class {
2644
2611
  // src/blockstore/commitor.ts
2645
2612
  var CBW = __toESM(require("@ipld/car/buffer-writer"), 1);
2646
2613
  var dagCodec2 = __toESM(require("@ipld/dag-cbor"), 1);
2647
- var import_sha23 = require("multiformats/hashes/sha2");
2614
+ var import_sha24 = require("multiformats/hashes/sha2");
2648
2615
  async function encodeCarFile(roots, t, codec3) {
2649
2616
  let size = 0;
2650
2617
  const headerSize = CBW.headerLength({ roots });
@@ -2661,7 +2628,7 @@ async function encodeCarFile(roots, t, codec3) {
2661
2628
  writer.write({ cid, bytes });
2662
2629
  }
2663
2630
  writer.close();
2664
- return await encode({ value: writer.bytes, hasher: import_sha23.sha256, codec: codec3 });
2631
+ return await encode2({ value: writer.bytes, hasher: import_sha24.sha256, codec: codec3 });
2665
2632
  }
2666
2633
  async function createCarFile(encoder, cid, t) {
2667
2634
  return encodeCarFile([cid], t, encoder);
@@ -2699,9 +2666,9 @@ function makeCarHeader(meta, cars, compact = false) {
2699
2666
  return { ...coreHeader, meta };
2700
2667
  }
2701
2668
  async function encodeCarHeader(fp) {
2702
- return await encode({
2669
+ return await encode2({
2703
2670
  value: { fp },
2704
- hasher: import_sha23.sha256,
2671
+ hasher: import_sha24.sha256,
2705
2672
  codec: dagCodec2
2706
2673
  });
2707
2674
  }
@@ -2744,7 +2711,7 @@ async function prepareCarFiles(encoder, threshold, rootBlock, t) {
2744
2711
  }
2745
2712
 
2746
2713
  // src/blockstore/loader.ts
2747
- var import_sha24 = require("multiformats/hashes/sha2");
2714
+ var import_sha25 = require("multiformats/hashes/sha2");
2748
2715
 
2749
2716
  // src/blockstore/task-manager.ts
2750
2717
  var TaskManager = class {
@@ -2795,7 +2762,7 @@ var TaskManager = class {
2795
2762
  };
2796
2763
 
2797
2764
  // src/blockstore/attachable-store.ts
2798
- var import_cement13 = require("@adviser/cement");
2765
+ var import_cement14 = require("@adviser/cement");
2799
2766
  var AttachedImpl = class {
2800
2767
  constructor(gws, stores, unreg) {
2801
2768
  this.gatewayUrls = gws;
@@ -2962,7 +2929,7 @@ async function createAttachedStores(urlOrGup, arOrLoadable, name = "local") {
2962
2929
  if (!urlOrGup) {
2963
2930
  throw new Error("urlOrGup is required");
2964
2931
  }
2965
- if ((0, import_cement13.isCoerceURI)(urlOrGup)) {
2932
+ if ((0, import_cement14.isCoerceURI)(urlOrGup)) {
2966
2933
  const url = urlOrGup;
2967
2934
  gup = {
2968
2935
  car: { url },
@@ -2980,7 +2947,7 @@ async function createAttachedStores(urlOrGup, arOrLoadable, name = "local") {
2980
2947
  }
2981
2948
  var AttachedRemotesImpl = class {
2982
2949
  constructor(loadable) {
2983
- this._remotes = new import_cement13.KeyedResolvOnce();
2950
+ this._remotes = new import_cement14.KeyedResolvOnce();
2984
2951
  this.loadable = loadable;
2985
2952
  }
2986
2953
  forRemotes(action) {
@@ -2996,8 +2963,8 @@ var AttachedRemotesImpl = class {
2996
2963
  return new ActiveStoreImpl(this._local.stores, this);
2997
2964
  }
2998
2965
  activate(store) {
2999
- if ((0, import_cement13.isCoerceURI)(store)) {
3000
- const activateUrl = import_cement13.URI.from(store);
2966
+ if ((0, import_cement14.isCoerceURI)(store)) {
2967
+ const activateUrl = import_cement14.URI.from(store);
3001
2968
  let maxScore = 0;
3002
2969
  let maxStore;
3003
2970
  for (const { value } of this._remotes.values()) {
@@ -3033,19 +3000,19 @@ var AttachedRemotesImpl = class {
3033
3000
  const gws = {
3034
3001
  car: {
3035
3002
  ...gwp.car,
3036
- url: ensureURIDefaults(this.loadable.sthis, attached.name, gwp.car.url, import_cement13.URI.from(gwp.car.url), "car")
3003
+ url: ensureURIDefaults(this.loadable.sthis, attached.name, gwp.car.url, import_cement14.URI.from(gwp.car.url), "car")
3037
3004
  },
3038
3005
  file: {
3039
3006
  ...gwp.file,
3040
- url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, import_cement13.URI.from(gwp.file.url), "file", { file: true })
3007
+ url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, import_cement14.URI.from(gwp.file.url), "file", { file: true })
3041
3008
  },
3042
3009
  meta: {
3043
3010
  ...gwp.meta,
3044
- url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, import_cement13.URI.from(gwp.meta.url), "meta")
3011
+ url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, import_cement14.URI.from(gwp.meta.url), "meta")
3045
3012
  },
3046
3013
  wal: gwp.wal ? {
3047
3014
  ...gwp.wal,
3048
- url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, import_cement13.URI.from(gwp.wal.url), "wal")
3015
+ url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, import_cement14.URI.from(gwp.wal.url), "wal")
3049
3016
  } : void 0
3050
3017
  };
3051
3018
  const key = JSON.stringify(
@@ -3086,7 +3053,7 @@ function carLogIncludesGroup(list, cids) {
3086
3053
  (arr) => cidSet === arr.map((cid) => cid.toString()).sort().join(",")
3087
3054
  );
3088
3055
  }
3089
- function uniqueCids(list, remove = new import_cement14.LRUSet()) {
3056
+ function uniqueCids(list, remove = new import_cement15.LRUSet()) {
3090
3057
  const byString = /* @__PURE__ */ new Map();
3091
3058
  for (const cid of list) {
3092
3059
  if (remove.has(cid.toString())) continue;
@@ -3100,7 +3067,7 @@ var Loader = class {
3100
3067
  this.isCompacting = false;
3101
3068
  this.maxConcurrentWrite = (0, import_p_limit.default)(1);
3102
3069
  this.carLog = new CarLog();
3103
- this.onceReady = new import_cement14.ResolveOnce();
3070
+ this.onceReady = new import_cement15.ResolveOnce();
3104
3071
  this.sthis = sthis;
3105
3072
  this.ebOpts = defaultedBlockstoreRuntime(
3106
3073
  sthis,
@@ -3111,15 +3078,15 @@ var Loader = class {
3111
3078
  "Loader"
3112
3079
  );
3113
3080
  this.logger = ensureLogger(sthis, "Loader");
3114
- this.cidCache = new import_cement14.KeyedResolvOnce({
3081
+ this.cidCache = new import_cement15.KeyedResolvOnce({
3115
3082
  lru: {
3116
3083
  maxEntries: parseInt(this.ebOpts.storeUrls.car.getParam(PARAM.CAR_CACHE_SIZE, "1000"), 10)
3117
3084
  }
3118
3085
  });
3119
- this.seenMeta = new import_cement14.LRUSet({
3086
+ this.seenMeta = new import_cement15.LRUSet({
3120
3087
  maxEntries: parseInt(this.ebOpts.storeUrls.meta.getParam(PARAM.CAR_META_CACHE_SIZE, "1000"), 10)
3121
3088
  });
3122
- this.seenCompacted = new import_cement14.LRUSet({
3089
+ this.seenCompacted = new import_cement15.LRUSet({
3123
3090
  maxEntries: parseInt(this.ebOpts.storeUrls.car.getParam(PARAM.CAR_COMPACT_CACHE_SIZE, "1000"), 10)
3124
3091
  });
3125
3092
  this.maxConcurrentCarReader = (0, import_p_limit.default)(parseInt(this.ebOpts.storeUrls.car.getParam(PARAM.CAR_PARALLEL, "5"), 10));
@@ -3424,7 +3391,7 @@ var Loader = class {
3424
3391
  if (!loadedCar) {
3425
3392
  throw this.logger.Error().Url(store.local().url()).Str("cid", carCidStr).Msg("missing car files").AsError();
3426
3393
  }
3427
- const bytes = await decode({ bytes: loadedCar.bytes, hasher: import_sha24.sha256, codec: (await activeStore.keyedCrypto()).codec() });
3394
+ const bytes = await decode2({ bytes: loadedCar.bytes, hasher: import_sha25.sha256, codec: (await activeStore.keyedCrypto()).codec() });
3428
3395
  const rawReader = await import_reader.CarReader.fromBytes(bytes.value.data);
3429
3396
  const blocks = [];
3430
3397
  for await (const block of rawReader.blocks()) {
@@ -3465,7 +3432,7 @@ __export(keyed_crypto_exports, {
3465
3432
  keyedCryptoFactory: () => keyedCryptoFactory
3466
3433
  });
3467
3434
  var import_base583 = require("multiformats/bases/base58");
3468
- var import_sha25 = require("multiformats/hashes/sha2");
3435
+ var import_sha26 = require("multiformats/hashes/sha2");
3469
3436
  var CBOR = __toESM(require("cborg"), 1);
3470
3437
  var generateIV = {
3471
3438
  random: {
@@ -3480,7 +3447,7 @@ var generateIV = {
3480
3447
  },
3481
3448
  hash: {
3482
3449
  calc: async (ko, crypto, data) => {
3483
- const hash = await import_sha25.sha256.digest(data);
3450
+ const hash = await import_sha26.sha256.digest(data);
3484
3451
  const hashBytes = new Uint8Array(hash.bytes);
3485
3452
  const hashArray = new Uint8Array(ko.ivLength);
3486
3453
  for (let i = 0; i < hashBytes.length; i++) {
@@ -3666,146 +3633,6 @@ var import_clock2 = require("@fireproof/vendor/@web3-storage/pail/clock");
3666
3633
  var import_dag_json2 = require("@ipld/dag-json");
3667
3634
  var import_p_retry = __toESM(require("p-retry"), 1);
3668
3635
  var import_p_map = __toESM(require("p-map"), 1);
3669
-
3670
- // src/blockstore/interceptor-gateway.ts
3671
- var import_cement15 = require("@adviser/cement");
3672
- var PassThroughGateway = class {
3673
- async buildUrl(ctx, url, key) {
3674
- const op = { url, key };
3675
- return import_cement15.Result.Ok({ op });
3676
- }
3677
- async start(ctx, url) {
3678
- const op = { url };
3679
- return import_cement15.Result.Ok({ op });
3680
- }
3681
- async close(ctx, url) {
3682
- const op = { url };
3683
- return import_cement15.Result.Ok({ op });
3684
- }
3685
- async delete(ctx, url) {
3686
- const op = { url };
3687
- return import_cement15.Result.Ok({ op });
3688
- }
3689
- async destroy(ctx, url) {
3690
- const op = { url };
3691
- return import_cement15.Result.Ok({ op });
3692
- }
3693
- async put(ctx, url, body) {
3694
- const op = { url, body };
3695
- return import_cement15.Result.Ok({ op });
3696
- }
3697
- async get(ctx, url) {
3698
- const op = { url };
3699
- return import_cement15.Result.Ok({ op });
3700
- }
3701
- async subscribe(ctx, url, callback) {
3702
- const op = { url, callback };
3703
- return import_cement15.Result.Ok({ op });
3704
- }
3705
- };
3706
- var passThrougthGateway = new PassThroughGateway();
3707
- var InterceptorGateway = class {
3708
- constructor(sthis, innerGW, interceptor) {
3709
- this.innerGW = innerGW;
3710
- this.interceptor = interceptor || passThrougthGateway;
3711
- }
3712
- async buildUrl(ctx, baseUrl, key) {
3713
- const rret = await this.interceptor.buildUrl(ctx, baseUrl, key);
3714
- if (rret.isErr()) {
3715
- return import_cement15.Result.Err(rret.Err());
3716
- }
3717
- const ret = rret.unwrap();
3718
- if (ret.stop && ret.value) {
3719
- return ret.value;
3720
- }
3721
- return this.innerGW.buildUrl(ctx, ret.op.url, ret.op.key);
3722
- }
3723
- async destroy(ctx, iurl) {
3724
- const rret = await this.interceptor.destroy(ctx, iurl);
3725
- if (rret.isErr()) {
3726
- return import_cement15.Result.Err(rret.Err());
3727
- }
3728
- const ret = rret.unwrap();
3729
- if (ret.stop && ret.value) {
3730
- return ret.value;
3731
- }
3732
- return this.innerGW.destroy(ctx, ret.op.url);
3733
- }
3734
- async start(ctx, url) {
3735
- const rret = await this.interceptor.start(ctx, url);
3736
- if (rret.isErr()) {
3737
- return import_cement15.Result.Err(rret.Err());
3738
- }
3739
- const ret = rret.unwrap();
3740
- if (ret.stop && ret.value) {
3741
- return ret.value;
3742
- }
3743
- return await this.innerGW.start(ctx, ret.op.url);
3744
- }
3745
- async close(ctx, url) {
3746
- const rret = await this.interceptor.close(ctx, url);
3747
- if (rret.isErr()) {
3748
- return import_cement15.Result.Err(rret.Err());
3749
- }
3750
- const ret = rret.unwrap();
3751
- if (ret.stop && ret.value) {
3752
- return ret.value;
3753
- }
3754
- return await this.innerGW.close(ctx, ret.op.url);
3755
- }
3756
- async put(ctx, url, fpEnv) {
3757
- const rret = await this.interceptor.put(ctx, url, fpEnv);
3758
- if (rret.isErr()) {
3759
- return import_cement15.Result.Err(rret.Err());
3760
- }
3761
- const ret = rret.unwrap();
3762
- if (ret.stop && ret.value) {
3763
- return ret.value;
3764
- }
3765
- return this.innerGW.put(ctx, ret.op.url, ret.op.body);
3766
- }
3767
- async get(ctx, url) {
3768
- const rret = await this.interceptor.get(ctx, url);
3769
- if (rret.isErr()) {
3770
- return import_cement15.Result.Err(rret.Err());
3771
- }
3772
- const ret = rret.unwrap();
3773
- if (ret.stop && ret.value) {
3774
- return ret.value;
3775
- }
3776
- return this.innerGW.get(ctx, ret.op.url);
3777
- }
3778
- async subscribe(ctx, url, callback) {
3779
- if (!this.innerGW.subscribe) {
3780
- return import_cement15.Result.Err(ctx.loader.sthis.logger.Error().Url(url).Msg("subscribe not supported").AsError());
3781
- }
3782
- const rret = await this.interceptor.subscribe(ctx, url, callback);
3783
- if (rret.isErr()) {
3784
- return import_cement15.Result.Err(rret.Err());
3785
- }
3786
- const ret = rret.unwrap();
3787
- if (ret.stop && ret.value) {
3788
- return ret.value;
3789
- }
3790
- return this.innerGW.subscribe(ctx, ret.op.url, ret.op.callback);
3791
- }
3792
- async delete(ctx, url) {
3793
- const rret = await this.interceptor.delete(ctx, url);
3794
- if (rret.isErr()) {
3795
- return import_cement15.Result.Err(rret.Err());
3796
- }
3797
- const ret = rret.unwrap();
3798
- if (ret.stop && ret.value) {
3799
- return ret.value;
3800
- }
3801
- return this.innerGW.delete(ctx, url);
3802
- }
3803
- async getPlain(ctx, url, key) {
3804
- return this.innerGW.getPlain(ctx, url, key);
3805
- }
3806
- };
3807
-
3808
- // src/blockstore/store.ts
3809
3636
  function guardVersion(url) {
3810
3637
  if (!url.hasParam("version")) {
3811
3638
  return import_cement16.Result.Err(`missing version: ${url.toString()}`);
@@ -3826,8 +3653,10 @@ var BaseStoreImpl = class {
3826
3653
  throw logger.Error().Url(this._url).Msg("missing name").AsError();
3827
3654
  }
3828
3655
  this.logger = logger.With().Str("this", this.sthis.nextId().str).Ref("url", () => this._url.toString()).Logger();
3829
- this.realGateway = opts.gateway;
3830
- this.gateway = new InterceptorGateway(this.sthis, opts.gateway, opts.gatewayInterceptor);
3656
+ this.gateway = opts.gateway;
3657
+ }
3658
+ get realGateway() {
3659
+ return this.gateway.innerGW;
3831
3660
  }
3832
3661
  url() {
3833
3662
  return this._url;
@@ -4131,7 +3960,7 @@ var WALStoreImpl = class extends BaseStoreImpl {
4131
3960
  const retryableUpload = (fn, description) => (0, import_p_retry.default)(fn, {
4132
3961
  retries: 5,
4133
3962
  onFailedAttempt: (error) => {
4134
- this.logger.Warn().Msg(`Attempt ${error.attemptNumber} failed for ${description}. There are ${error.retriesLeft} retries left.`);
3963
+ this.logger.Warn().Any("error", error).Any("fn", fn.toString()).Msg(`Attempt ${error.attemptNumber} failed for ${description}. There are ${error.retriesLeft} retries left.`);
4135
3964
  }
4136
3965
  });
4137
3966
  try {
@@ -4254,81 +4083,200 @@ var WALStoreImpl = class extends BaseStoreImpl {
4254
4083
  }
4255
4084
  };
4256
4085
 
4257
- // src/blockstore/store-factory.ts
4258
- var onceGateway = new import_cement17.KeyedResolvOnce();
4259
- var gatewayInstances = new import_cement17.KeyedResolvOnce();
4260
- async function getStartedGateway(ctx, url) {
4261
- return onceGateway.get(url.toString()).once(async () => {
4262
- const item = getGatewayFactoryItem(url.protocol);
4263
- if (item) {
4264
- const ret = {
4265
- url,
4266
- ...await gatewayInstances.get(url.protocol).once(async () => ({
4267
- gateway: await item.serdegateway(ctx.loader.sthis)
4268
- }))
4269
- };
4270
- const res = await ret.gateway.start(ctx, url);
4271
- if (res.isErr()) {
4272
- return import_cement17.Result.Err(ctx.loader.sthis.logger.Error().Result("start", res).Msg("start failed").AsError());
4273
- }
4274
- ret.url = res.Ok();
4275
- return import_cement17.Result.Ok(ret);
4086
+ // src/blockstore/interceptor-gateway.ts
4087
+ var import_cement17 = require("@adviser/cement");
4088
+ var PassThroughGateway = class {
4089
+ async buildUrl(ctx, url, key) {
4090
+ const op = { url, key };
4091
+ return import_cement17.Result.Ok({ op });
4092
+ }
4093
+ async start(ctx, url) {
4094
+ const op = { url };
4095
+ return import_cement17.Result.Ok({ op });
4096
+ }
4097
+ async close(ctx, url) {
4098
+ const op = { url };
4099
+ return import_cement17.Result.Ok({ op });
4100
+ }
4101
+ async delete(ctx, url) {
4102
+ const op = { url };
4103
+ return import_cement17.Result.Ok({ op });
4104
+ }
4105
+ async destroy(ctx, url) {
4106
+ const op = { url };
4107
+ return import_cement17.Result.Ok({ op });
4108
+ }
4109
+ async put(ctx, url, body) {
4110
+ const op = { url, body };
4111
+ return import_cement17.Result.Ok({ op });
4112
+ }
4113
+ async get(ctx, url) {
4114
+ const op = { url };
4115
+ return import_cement17.Result.Ok({ op });
4116
+ }
4117
+ async subscribe(ctx, url, callback) {
4118
+ const op = { url, callback };
4119
+ return import_cement17.Result.Ok({ op });
4120
+ }
4121
+ };
4122
+ var passThrougthGateway = new PassThroughGateway();
4123
+ var InterceptorGateway = class {
4124
+ constructor(sthis, innerGW, interceptor) {
4125
+ this.innerGW = innerGW;
4126
+ this.interceptor = interceptor || passThrougthGateway;
4127
+ }
4128
+ async buildUrl(ctx, baseUrl, key) {
4129
+ const rret = await this.interceptor.buildUrl(ctx, baseUrl, key);
4130
+ if (rret.isErr()) {
4131
+ return import_cement17.Result.Err(rret.Err());
4276
4132
  }
4277
- return import_cement17.Result.Err(ctx.loader.sthis.logger.Warn().Url(url).Msg("unsupported protocol").AsError());
4278
- });
4133
+ const ret = rret.unwrap();
4134
+ if (ret.stop && ret.value) {
4135
+ return ret.value;
4136
+ }
4137
+ return this.innerGW.buildUrl(ctx, ret.op.url, ret.op.key);
4138
+ }
4139
+ async destroy(ctx, iurl) {
4140
+ const rret = await this.interceptor.destroy(ctx, iurl);
4141
+ if (rret.isErr()) {
4142
+ return import_cement17.Result.Err(rret.Err());
4143
+ }
4144
+ const ret = rret.unwrap();
4145
+ if (ret.stop && ret.value) {
4146
+ return ret.value;
4147
+ }
4148
+ return this.innerGW.destroy(ctx, ret.op.url);
4149
+ }
4150
+ async start(ctx, url) {
4151
+ const rret = await this.interceptor.start(ctx, url);
4152
+ if (rret.isErr()) {
4153
+ return import_cement17.Result.Err(rret.Err());
4154
+ }
4155
+ const ret = rret.unwrap();
4156
+ if (ret.stop && ret.value) {
4157
+ return ret.value;
4158
+ }
4159
+ return await this.innerGW.start(ctx, ret.op.url);
4160
+ }
4161
+ async close(ctx, url) {
4162
+ const rret = await this.interceptor.close(ctx, url);
4163
+ if (rret.isErr()) {
4164
+ return import_cement17.Result.Err(rret.Err());
4165
+ }
4166
+ const ret = rret.unwrap();
4167
+ if (ret.stop && ret.value) {
4168
+ return ret.value;
4169
+ }
4170
+ return await this.innerGW.close(ctx, ret.op.url);
4171
+ }
4172
+ async put(ctx, url, fpEnv) {
4173
+ const rret = await this.interceptor.put(ctx, url, fpEnv);
4174
+ if (rret.isErr()) {
4175
+ return import_cement17.Result.Err(rret.Err());
4176
+ }
4177
+ const ret = rret.unwrap();
4178
+ if (ret.stop && ret.value) {
4179
+ return ret.value;
4180
+ }
4181
+ return this.innerGW.put(ctx, ret.op.url, ret.op.body);
4182
+ }
4183
+ async get(ctx, url) {
4184
+ const rret = await this.interceptor.get(ctx, url);
4185
+ if (rret.isErr()) {
4186
+ return import_cement17.Result.Err(rret.Err());
4187
+ }
4188
+ const ret = rret.unwrap();
4189
+ if (ret.stop && ret.value) {
4190
+ return ret.value;
4191
+ }
4192
+ return this.innerGW.get(ctx, ret.op.url);
4193
+ }
4194
+ async subscribe(ctx, url, callback) {
4195
+ if (!this.innerGW.subscribe) {
4196
+ return import_cement17.Result.Err(ctx.loader.sthis.logger.Error().Url(url).Msg("subscribe not supported").AsError());
4197
+ }
4198
+ const rret = await this.interceptor.subscribe(ctx, url, callback);
4199
+ if (rret.isErr()) {
4200
+ return import_cement17.Result.Err(rret.Err());
4201
+ }
4202
+ const ret = rret.unwrap();
4203
+ if (ret.stop && ret.value) {
4204
+ return ret.value;
4205
+ }
4206
+ return this.innerGW.subscribe(ctx, ret.op.url, ret.op.callback);
4207
+ }
4208
+ async delete(ctx, url) {
4209
+ const rret = await this.interceptor.delete(ctx, url);
4210
+ if (rret.isErr()) {
4211
+ return import_cement17.Result.Err(rret.Err());
4212
+ }
4213
+ const ret = rret.unwrap();
4214
+ if (ret.stop && ret.value) {
4215
+ return ret.value;
4216
+ }
4217
+ return this.innerGW.delete(ctx, url);
4218
+ }
4219
+ async getPlain(ctx, url, key) {
4220
+ return this.innerGW.getPlain(ctx, url, key);
4221
+ }
4222
+ };
4223
+
4224
+ // src/blockstore/store-factory.ts
4225
+ async function getInterceptableGateway(ctx, url, opt) {
4226
+ const item = getGatewayFactoryItem(url.protocol);
4227
+ if (item) {
4228
+ return import_cement18.Result.Ok(new InterceptorGateway(ctx.loader.sthis, await item.serdegateway(ctx.loader.sthis), opt.gatewayInterceptor));
4229
+ }
4230
+ return import_cement18.Result.Err(ctx.loader.sthis.logger.Warn().Url(url).Msg("unsupported protocol").AsError());
4279
4231
  }
4280
4232
  async function carStoreFactory(ctx, uai) {
4281
4233
  const storeUrl = uai.url.build().setParam(PARAM.STORE, "car").URI();
4282
- const rgateway = await getStartedGateway(ctx, storeUrl);
4234
+ const rgateway = await getInterceptableGateway(ctx, storeUrl, uai);
4283
4235
  if (rgateway.isErr()) {
4284
4236
  throw ctx.loader.sthis.logger.Error().Result("err", rgateway).Url(uai.url).Msg("notfound").AsError();
4285
4237
  }
4286
4238
  const gateway = rgateway.Ok();
4287
- const store = new CarStoreImpl(ctx.loader.sthis, gateway.url, {
4288
- gateway: gateway.gateway,
4289
- gatewayInterceptor: uai.gatewayInterceptor,
4239
+ const store = new CarStoreImpl(ctx.loader.sthis, uai.url, {
4240
+ gateway,
4290
4241
  loader: ctx.loader
4291
4242
  });
4292
4243
  return store;
4293
4244
  }
4294
4245
  async function fileStoreFactory(ctx, uai) {
4295
4246
  const storeUrl = uai.url.build().setParam(PARAM.STORE, "file").URI();
4296
- const rgateway = await getStartedGateway(ctx, storeUrl);
4247
+ const rgateway = await getInterceptableGateway(ctx, storeUrl, uai);
4297
4248
  if (rgateway.isErr()) {
4298
4249
  throw ctx.loader.sthis.logger.Error().Result("err", rgateway).Url(uai.url).Msg("notfound").AsError();
4299
4250
  }
4300
4251
  const gateway = rgateway.Ok();
4301
- const store = new FileStoreImpl(ctx.loader.sthis, gateway.url, {
4302
- gateway: gateway.gateway,
4303
- gatewayInterceptor: uai.gatewayInterceptor,
4252
+ const store = new FileStoreImpl(ctx.loader.sthis, uai.url, {
4253
+ gateway,
4304
4254
  loader: ctx.loader
4305
4255
  });
4306
4256
  return store;
4307
4257
  }
4308
4258
  async function metaStoreFactory(ctx, uai) {
4309
4259
  const storeUrl = uai.url.build().setParam(PARAM.STORE, "meta").URI();
4310
- const rgateway = await getStartedGateway(ctx, storeUrl);
4260
+ const rgateway = await getInterceptableGateway(ctx, storeUrl, uai);
4311
4261
  if (rgateway.isErr()) {
4312
4262
  throw ctx.loader.sthis.logger.Error().Result("err", rgateway).Url(uai.url).Msg("notfound").AsError();
4313
4263
  }
4314
4264
  const gateway = rgateway.Ok();
4315
- const store = new MetaStoreImpl(ctx.loader.sthis, gateway.url, {
4316
- gateway: gateway.gateway,
4317
- gatewayInterceptor: uai.gatewayInterceptor,
4265
+ const store = new MetaStoreImpl(ctx.loader.sthis, uai.url, {
4266
+ gateway,
4318
4267
  loader: ctx.loader
4319
4268
  });
4320
4269
  return store;
4321
4270
  }
4322
4271
  async function WALStoreFactory(ctx, uai) {
4323
4272
  const storeUrl = uai.url.build().setParam(PARAM.STORE, "wal").URI();
4324
- const rgateway = await getStartedGateway(ctx, storeUrl);
4273
+ const rgateway = await getInterceptableGateway(ctx, storeUrl, uai);
4325
4274
  if (rgateway.isErr()) {
4326
4275
  throw ctx.loader.sthis.logger.Error().Result("err", rgateway).Url(uai.url).Msg("notfound").AsError();
4327
4276
  }
4328
4277
  const gateway = rgateway.Ok();
4329
- const store = new WALStoreImpl(ctx.loader.sthis, gateway.url, {
4330
- gateway: gateway.gateway,
4331
- gatewayInterceptor: uai.gatewayInterceptor,
4278
+ const store = new WALStoreImpl(ctx.loader.sthis, uai.url, {
4279
+ gateway,
4332
4280
  loader: ctx.loader
4333
4281
  });
4334
4282
  return store;
@@ -4376,9 +4324,60 @@ function toStoreRuntime(sthis, endeOpts = {}) {
4376
4324
  };
4377
4325
  }
4378
4326
 
4327
+ // src/blockstore/uri-interceptor.ts
4328
+ var URIInterceptor = class _URIInterceptor extends PassThroughGateway {
4329
+ static withMapper(mapper) {
4330
+ return new _URIInterceptor().addMapper(mapper);
4331
+ }
4332
+ #uriMapper = /* @__PURE__ */ new Set();
4333
+ addMapper(mapper) {
4334
+ this.#uriMapper.add(mapper);
4335
+ return this;
4336
+ }
4337
+ async #map(uri) {
4338
+ let ret = uri;
4339
+ for (const mapper of this.#uriMapper) {
4340
+ ret = await mapper(ret);
4341
+ }
4342
+ return ret;
4343
+ }
4344
+ async buildUrl(ctx, url, key) {
4345
+ const ret = await super.buildUrl(ctx, await this.#map(url), key);
4346
+ return ret;
4347
+ }
4348
+ async start(ctx, url) {
4349
+ const ret = await super.start(ctx, await this.#map(url));
4350
+ return ret;
4351
+ }
4352
+ async close(ctx, url) {
4353
+ const ret = await super.close(ctx, await this.#map(url));
4354
+ return ret;
4355
+ }
4356
+ async delete(ctx, url) {
4357
+ const ret = await super.delete(ctx, await this.#map(url));
4358
+ return ret;
4359
+ }
4360
+ async destroy(ctx, url) {
4361
+ const ret = await super.destroy(ctx, await this.#map(url));
4362
+ return ret;
4363
+ }
4364
+ async put(ctx, url, body) {
4365
+ const ret = await super.put(ctx, await this.#map(url), body);
4366
+ return ret;
4367
+ }
4368
+ async get(ctx, url) {
4369
+ const ret = await super.get(ctx, await this.#map(url));
4370
+ return ret;
4371
+ }
4372
+ async subscribe(ctx, url, callback) {
4373
+ const ret = await super.subscribe(ctx, await this.#map(url), callback);
4374
+ return ret;
4375
+ }
4376
+ };
4377
+
4379
4378
  // src/crdt-helpers.ts
4380
4379
  var import_link2 = require("multiformats/link");
4381
- var import_sha26 = require("multiformats/hashes/sha2");
4380
+ var import_sha27 = require("multiformats/hashes/sha2");
4382
4381
  var codec2 = __toESM(require("@ipld/dag-cbor"), 1);
4383
4382
  var import_crdt = require("@fireproof/vendor/@web3-storage/pail/crdt");
4384
4383
  var import_clock3 = require("@fireproof/vendor/@web3-storage/pail/clock");
@@ -4465,7 +4464,7 @@ async function writeDocContent(store, blocks, update, logger) {
4465
4464
  await processFiles(store, blocks, update.value, logger);
4466
4465
  value = { doc: update.value };
4467
4466
  }
4468
- const block = await encode({ value, hasher: import_sha26.sha256, codec: codec2 });
4467
+ const block = await encode2({ value, hasher: import_sha27.sha256, codec: codec2 });
4469
4468
  blocks.putSync(block.cid, block.bytes);
4470
4469
  return block.cid;
4471
4470
  }
@@ -4496,11 +4495,11 @@ async function processFileset(logger, store, blocks, files) {
4496
4495
  for (const block of fileBlocks) {
4497
4496
  t.putSync(block.cid, block.bytes);
4498
4497
  }
4499
- files[filename] = { cid, type: file.type, size: file.size };
4498
+ files[filename] = { cid, type: file.type, size: file.size, lastModified: file.lastModified };
4500
4499
  } else {
4501
- const { cid, type, size, car } = files[filename];
4500
+ const { cid, type, size, car, lastModified } = files[filename];
4502
4501
  if (cid && type && size && car) {
4503
- files[filename] = { cid, type, size, car };
4502
+ files[filename] = { cid, type, size, car, lastModified };
4504
4503
  }
4505
4504
  }
4506
4505
  }
@@ -4540,15 +4539,21 @@ function readFileset(blocks, files, isPublic = false) {
4540
4539
  fileMeta.url = `https://${fileMeta.cid.toString()}.ipfs.w3s.link/`;
4541
4540
  }
4542
4541
  if (fileMeta.car) {
4543
- fileMeta.file = async () => await blocks.ebOpts.storeRuntime.decodeFile(
4544
- {
4545
- get: async (cid) => {
4546
- return await blocks.getFile(throwFalsy(fileMeta.car), cid);
4547
- }
4548
- },
4549
- fileMeta.cid,
4550
- fileMeta
4551
- );
4542
+ fileMeta.file = async () => {
4543
+ const result = await blocks.ebOpts.storeRuntime.decodeFile(
4544
+ {
4545
+ get: async (cid) => {
4546
+ return await blocks.getFile(throwFalsy(fileMeta.car), cid);
4547
+ }
4548
+ },
4549
+ fileMeta.cid,
4550
+ fileMeta
4551
+ );
4552
+ if (result.isErr()) {
4553
+ throw blocks.logger.Error().Any("error", result.Err()).Any("cid", fileMeta.cid).Msg("Error decoding file").AsError();
4554
+ }
4555
+ return result.unwrap();
4556
+ };
4552
4557
  }
4553
4558
  }
4554
4559
  files[filename] = fileMeta;
@@ -4557,7 +4562,7 @@ function readFileset(blocks, files, isPublic = false) {
4557
4562
  async function getValueFromLink(blocks, link, logger) {
4558
4563
  const block = await blocks.get(link);
4559
4564
  if (!block) throw logger.Error().Str("link", link.toString()).Msg(`Missing linked block`).AsError();
4560
- const { value } = await decode({ bytes: block.bytes, hasher: import_sha26.sha256, codec: codec2 });
4565
+ const { value } = await decode2({ bytes: block.bytes, hasher: import_sha27.sha256, codec: codec2 });
4561
4566
  const cvalue = {
4562
4567
  ...value,
4563
4568
  cid: link
@@ -4683,14 +4688,14 @@ async function doCompact(blockLog, head, logger) {
4683
4688
  async function getBlock(blocks, cidString) {
4684
4689
  const block = await blocks.get((0, import_link2.parse)(cidString));
4685
4690
  if (!block) throw new Error(`Missing block ${cidString}`);
4686
- const { cid, value } = await decode({ bytes: block.bytes, codec: codec2, hasher: import_sha26.sha256 });
4691
+ const { cid, value } = await decode2({ bytes: block.bytes, codec: codec2, hasher: import_sha27.sha256 });
4687
4692
  return new Block({ cid, value, bytes: block.bytes });
4688
4693
  }
4689
4694
 
4690
4695
  // src/crdt-clock.ts
4691
4696
  var import_clock4 = require("@fireproof/vendor/@web3-storage/pail/clock");
4692
4697
  var import_crdt2 = require("@fireproof/vendor/@web3-storage/pail/crdt");
4693
- var import_cement18 = require("@adviser/cement");
4698
+ var import_cement19 = require("@adviser/cement");
4694
4699
 
4695
4700
  // src/apply-head-queue.ts
4696
4701
  function applyHeadQueue(worker, logger) {
@@ -4747,7 +4752,7 @@ var CRDTClockImpl = class {
4747
4752
  this.zoomers = /* @__PURE__ */ new Map();
4748
4753
  this.watchers = /* @__PURE__ */ new Map();
4749
4754
  this.emptyWatchers = /* @__PURE__ */ new Map();
4750
- this._ready = new import_cement18.ResolveOnce();
4755
+ this._ready = new import_cement19.ResolveOnce();
4751
4756
  this.sthis = blockstore.sthis;
4752
4757
  this.blockstore = blockstore;
4753
4758
  this.logger = ensureLogger(blockstore.sthis, "CRDTClock");
@@ -4877,7 +4882,7 @@ async function advanceBlocks(logger, newHead, tblocks, head) {
4877
4882
  var CRDTImpl = class {
4878
4883
  constructor(sthis, opts) {
4879
4884
  this.indexers = /* @__PURE__ */ new Map();
4880
- this.onceReady = new import_cement19.ResolveOnce();
4885
+ this.onceReady = new import_cement20.ResolveOnce();
4881
4886
  this.sthis = sthis;
4882
4887
  this.crdt = this;
4883
4888
  this.logger = ensureLogger(sthis, "CRDT");
@@ -5023,7 +5028,7 @@ var Context = class {
5023
5028
  };
5024
5029
 
5025
5030
  // src/ledger.ts
5026
- var ledgers = new import_cement20.KeyedResolvOnce();
5031
+ var ledgers = new import_cement21.KeyedResolvOnce();
5027
5032
  function keyConfigOpts(sthis, name, opts) {
5028
5033
  return JSON.stringify(
5029
5034
  toSortedArray({
@@ -5115,7 +5120,7 @@ var LedgerImpl = class {
5115
5120
  this.shells = /* @__PURE__ */ new Set();
5116
5121
  this.context = new Context();
5117
5122
  this._onClosedFns = /* @__PURE__ */ new Map();
5118
- this._ready = new import_cement20.ResolveOnce();
5123
+ this._ready = new import_cement21.ResolveOnce();
5119
5124
  this.opts = opts;
5120
5125
  this.sthis = sthis;
5121
5126
  this.id = sthis.timeOrderedNextId().str;
@@ -5223,12 +5228,12 @@ function toStoreURIRuntime(sthis, name, sopts) {
5223
5228
  if (!sopts.base) {
5224
5229
  const fp_env = sthis.env.get("FP_STORAGE_URL");
5225
5230
  if (fp_env) {
5226
- sopts = { ...sopts, base: import_cement20.BuildURI.from(fp_env).setParam(PARAM.URL_GEN, "fromEnv") };
5231
+ sopts = { ...sopts, base: import_cement21.BuildURI.from(fp_env).setParam(PARAM.URL_GEN, "fromEnv") };
5227
5232
  } else {
5228
5233
  sopts = { ...sopts, base: getDefaultURI(sthis).build().setParam(PARAM.URL_GEN, "default") };
5229
5234
  }
5230
5235
  }
5231
- const base = import_cement20.URI.from(sopts.base);
5236
+ const base = import_cement21.URI.from(sopts.base);
5232
5237
  return {
5233
5238
  idx: {
5234
5239
  car: ensureURIDefaults(sthis, name, sopts.idx?.car ?? sopts.data?.car, base, "car", { idx: true }),
@@ -5269,7 +5274,7 @@ __export(runtime_exports, {
5269
5274
  keysByFingerprint: () => keysByFingerprint,
5270
5275
  mf: () => wait_pr_multiformats_exports,
5271
5276
  registerKeyBagProviderFactory: () => registerKeyBagProviderFactory,
5272
- runtimeFn: () => import_cement21.runtimeFn,
5277
+ runtimeFn: () => import_cement22.runtimeFn,
5273
5278
  toKeyWithFingerPrint: () => toKeyWithFingerPrint
5274
5279
  });
5275
5280
 
@@ -5284,7 +5289,7 @@ __export(wait_pr_multiformats_exports, {
5284
5289
  var codec_interface_exports = {};
5285
5290
 
5286
5291
  // src/runtime/index.ts
5287
- var import_cement21 = require("@adviser/cement");
5292
+ var import_cement22 = require("@adviser/cement");
5288
5293
 
5289
5294
  // src/runtime/gateways/index.ts
5290
5295
  var gateways_exports = {};
@@ -5307,6 +5312,6 @@ __export(file_exports, {
5307
5312
 
5308
5313
  // src/version.ts
5309
5314
  var PACKAGE_VERSION = Object.keys({
5310
- "0.20.0-dev-preview-53": "xxxx"
5315
+ "0.20.0-dev-preview-55": "xxxx"
5311
5316
  })[0];
5312
5317
  //# sourceMappingURL=index.cjs.map