@fireproof/core 0.20.0-dev-preview-60 → 0.20.0-dev-preview-62

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.d.cts CHANGED
@@ -223,7 +223,10 @@ declare function coerceIntoUint8(raw: ToUInt8): Result<Uint8Array>;
223
223
  declare function coercePromiseIntoUint8(raw: PromiseToUInt8): Promise<Result<Uint8Array>>;
224
224
  declare function makeName(fnString: string): string;
225
225
  declare function storeType2DataMetaWal(store: StoreType): "data" | "wal" | "meta";
226
- declare function ensureURIDefaults(sthis: SuperThis, name: string, curi: CoerceURI | undefined, uri: URI, store: StoreType, ctx?: Partial<{
226
+ declare function ensureURIDefaults(sthis: SuperThis, names: {
227
+ name: string;
228
+ local?: string;
229
+ }, curi: CoerceURI | undefined, uri: URI, store: StoreType, ctx?: Partial<{
227
230
  readonly idx: boolean;
228
231
  readonly file: boolean;
229
232
  }>): URI;
@@ -1199,6 +1202,7 @@ declare const PARAM: {
1199
1202
  CAR_COMPACT_CACHE_SIZE: string;
1200
1203
  CAR_META_CACHE_SIZE: string;
1201
1204
  GENESIS_CID: string;
1205
+ LOCAL_NAME: string;
1202
1206
  };
1203
1207
  type PARAMS = (typeof PARAM)[keyof typeof PARAM];
1204
1208
  declare function throwFalsy<T>(value: T | Falsy): T;
package/index.d.ts CHANGED
@@ -223,7 +223,10 @@ declare function coerceIntoUint8(raw: ToUInt8): Result<Uint8Array>;
223
223
  declare function coercePromiseIntoUint8(raw: PromiseToUInt8): Promise<Result<Uint8Array>>;
224
224
  declare function makeName(fnString: string): string;
225
225
  declare function storeType2DataMetaWal(store: StoreType): "data" | "wal" | "meta";
226
- declare function ensureURIDefaults(sthis: SuperThis, name: string, curi: CoerceURI | undefined, uri: URI, store: StoreType, ctx?: Partial<{
226
+ declare function ensureURIDefaults(sthis: SuperThis, names: {
227
+ name: string;
228
+ local?: string;
229
+ }, curi: CoerceURI | undefined, uri: URI, store: StoreType, ctx?: Partial<{
227
230
  readonly idx: boolean;
228
231
  readonly file: boolean;
229
232
  }>): URI;
@@ -1199,6 +1202,7 @@ declare const PARAM: {
1199
1202
  CAR_COMPACT_CACHE_SIZE: string;
1200
1203
  CAR_META_CACHE_SIZE: string;
1201
1204
  GENESIS_CID: string;
1205
+ LOCAL_NAME: string;
1202
1206
  };
1203
1207
  type PARAMS = (typeof PARAM)[keyof typeof PARAM];
1204
1208
  declare function throwFalsy<T>(value: T | Falsy): T;
package/index.js CHANGED
@@ -23,7 +23,7 @@ import {
23
23
 
24
24
  // src/types.ts
25
25
  function isFalsy(value) {
26
- return value === false && value === null && value === void 0;
26
+ return value === false || value === null || value === void 0;
27
27
  }
28
28
  var PARAM = {
29
29
  SUFFIX: "suffix",
@@ -51,7 +51,8 @@ var PARAM = {
51
51
  CAR_CACHE_SIZE: "carCacheSize",
52
52
  CAR_COMPACT_CACHE_SIZE: "carCompactCacheSize",
53
53
  CAR_META_CACHE_SIZE: "carMetaCacheSize",
54
- GENESIS_CID: "baembeiarootfireproofgenesisblockaaaafireproofgenesisblocka"
54
+ GENESIS_CID: "baembeiarootfireproofgenesisblockaaaafireproofgenesisblocka",
55
+ LOCAL_NAME: "localName"
55
56
  // FS = "fs",
56
57
  };
57
58
  function throwFalsy(value) {
@@ -426,11 +427,11 @@ function storeType2DataMetaWal(store) {
426
427
  throw new Error(`unknown store ${store}`);
427
428
  }
428
429
  }
429
- function ensureURIDefaults(sthis, name, curi, uri, store, ctx) {
430
+ function ensureURIDefaults(sthis, names, curi, uri, store, ctx) {
430
431
  ctx = ctx || {};
431
- const ret = (curi ? URI.from(curi) : uri).build().setParam(PARAM.STORE, store).defParam(PARAM.NAME, name);
432
- if (!ret.hasParam(PARAM.NAME)) {
433
- throw sthis.logger.Error().Url(ret).Any("ctx", ctx).Msg("Ledger name is required").AsError();
432
+ const ret = (curi ? URI.from(curi) : uri).build().setParam(PARAM.STORE, store).defParam(PARAM.NAME, names.name);
433
+ if (names.local) {
434
+ ret.defParam(PARAM.LOCAL_NAME, names.local);
434
435
  }
435
436
  if (ctx.idx) {
436
437
  ret.defParam(PARAM.INDEX, "idx");
@@ -1238,6 +1239,13 @@ import { Result as Result5 } from "@adviser/cement";
1238
1239
  var MEMORY_VERSION = "v0.19-memory";
1239
1240
 
1240
1241
  // src/runtime/gateways/memory/gateway.ts
1242
+ function cleanURI(uri) {
1243
+ return uri.build().cleanParams(
1244
+ PARAM.VERSION,
1245
+ // PARAM.STORE,
1246
+ PARAM.LOCAL_NAME
1247
+ ).URI();
1248
+ }
1241
1249
  var MemoryGateway = class {
1242
1250
  // readonly logger: Logger;
1243
1251
  constructor(sthis, memorys) {
@@ -1255,33 +1263,33 @@ var MemoryGateway = class {
1255
1263
  return Promise.resolve(Result5.Ok(void 0));
1256
1264
  }
1257
1265
  destroy(baseUrl) {
1258
- const keyUrl = baseUrl.toString();
1266
+ const keyUrl = cleanURI(baseUrl);
1267
+ const match = keyUrl.match(keyUrl);
1259
1268
  for (const key of this.memorys.keys()) {
1260
- if (key.startsWith(keyUrl)) {
1269
+ if (keyUrl.match(key).score >= match.score) {
1261
1270
  this.memorys.delete(key);
1262
1271
  }
1263
1272
  }
1264
- this.memorys.clear();
1265
1273
  return Promise.resolve(Result5.Ok(void 0));
1266
1274
  }
1267
1275
  async put(url, bytes) {
1268
- this.memorys.set(url.toString(), bytes);
1276
+ this.memorys.set(cleanURI(url).toString(), bytes);
1269
1277
  return Result5.Ok(void 0);
1270
1278
  }
1271
1279
  // get could return a NotFoundError if the key is not found
1272
1280
  get(url) {
1273
- const x = this.memorys.get(url.toString());
1281
+ const x = this.memorys.get(cleanURI(url).toString());
1274
1282
  if (!x) {
1275
1283
  return Promise.resolve(Result5.Err(new NotFoundError(`not found: ${url.toString()}`)));
1276
1284
  }
1277
1285
  return Promise.resolve(Result5.Ok(x));
1278
1286
  }
1279
1287
  delete(url) {
1280
- this.memorys.delete(url.toString());
1288
+ this.memorys.delete(cleanURI(url).toString());
1281
1289
  return Promise.resolve(Result5.Ok(void 0));
1282
1290
  }
1283
1291
  async getPlain(url, key) {
1284
- const x = this.memorys.get(url.build().setParam(PARAM.KEY, key).toString());
1292
+ const x = this.memorys.get(cleanURI(url).build().setParam(PARAM.KEY, key).toString());
1285
1293
  if (!x) {
1286
1294
  return Result5.Err(new NotFoundError("not found"));
1287
1295
  }
@@ -2964,19 +2972,44 @@ var AttachedRemotesImpl = class {
2964
2972
  const gws = {
2965
2973
  car: {
2966
2974
  ...gwp.car,
2967
- url: ensureURIDefaults(this.loadable.sthis, attached.name, gwp.car.url, URI9.from(gwp.car.url), "car")
2975
+ url: ensureURIDefaults(
2976
+ this.loadable.sthis,
2977
+ { name: attached.name, local: this._local?.gatewayUrls.car.url.getParam(PARAM.NAME) },
2978
+ void 0,
2979
+ URI9.from(gwp.car.url),
2980
+ "car"
2981
+ )
2968
2982
  },
2969
2983
  file: {
2970
2984
  ...gwp.file,
2971
- url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, URI9.from(gwp.file.url), "file", { file: true })
2985
+ url: ensureURIDefaults(
2986
+ this.loadable.sthis,
2987
+ { name: attached.name, local: this._local?.gatewayUrls.file.url.getParam(PARAM.NAME) },
2988
+ void 0,
2989
+ URI9.from(gwp.file.url),
2990
+ "file",
2991
+ { file: true }
2992
+ )
2972
2993
  },
2973
2994
  meta: {
2974
2995
  ...gwp.meta,
2975
- url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, URI9.from(gwp.meta.url), "meta")
2996
+ url: ensureURIDefaults(
2997
+ this.loadable.sthis,
2998
+ { name: attached.name, local: this._local?.gatewayUrls.meta.url.getParam(PARAM.NAME) },
2999
+ void 0,
3000
+ URI9.from(gwp.meta.url),
3001
+ "meta"
3002
+ )
2976
3003
  },
2977
3004
  wal: gwp.wal ? {
2978
3005
  ...gwp.wal,
2979
- url: ensureURIDefaults(this.loadable.sthis, attached.name, void 0, URI9.from(gwp.wal.url), "wal")
3006
+ url: ensureURIDefaults(
3007
+ this.loadable.sthis,
3008
+ { name: attached.name, local: this._local?.gatewayUrls.wal?.url.getParam(PARAM.NAME) },
3009
+ void 0,
3010
+ URI9.from(gwp.wal.url),
3011
+ "wal"
3012
+ )
2980
3013
  } : void 0
2981
3014
  };
2982
3015
  const key = JSON.stringify(
@@ -3001,7 +3034,7 @@ var AttachedRemotesImpl = class {
3001
3034
  );
3002
3035
  if (result.stores.wal) {
3003
3036
  if (this._local) {
3004
- throw this.loadable.sthis.logger.Error().Msg("local store could only set once").AsError();
3037
+ throw this.loadable.sthis.logger.Error().Any({ urls: result.gatewayUrls }).Msg("local store could only set once").AsError();
3005
3038
  }
3006
3039
  this._local = result;
3007
3040
  }
@@ -3068,10 +3101,11 @@ var Loader = class {
3068
3101
  if (!at.stores.wal) {
3069
3102
  try {
3070
3103
  const dbMeta = await at.stores.meta.load();
3071
- if (!Array.isArray(dbMeta)) {
3072
- throw this.logger.Error().Msg("missing dbMeta").AsError();
3104
+ if (Array.isArray(dbMeta)) {
3105
+ await this.handleDbMetasFromStore(dbMeta, this.attachedStores.activate(at.stores));
3106
+ } else if (!isFalsy(dbMeta)) {
3107
+ throw this.logger.Error().Any({ dbMeta }).Msg("missing dbMeta").AsError();
3073
3108
  }
3074
- await this.handleDbMetasFromStore(dbMeta, this.attachedStores.activate(at.stores));
3075
3109
  } catch (e) {
3076
3110
  this.logger.Error().Err(e).Msg("error attaching store");
3077
3111
  at.detach();
@@ -5200,19 +5234,26 @@ function toStoreURIRuntime(sthis, name, sopts) {
5200
5234
  const base = URI13.from(sopts.base);
5201
5235
  return {
5202
5236
  idx: {
5203
- car: ensureURIDefaults(sthis, name, sopts.idx?.car ?? sopts.data?.car, base, "car", { idx: true }),
5204
- file: ensureURIDefaults(sthis, name, sopts.idx?.file ?? sopts.idx?.car ?? sopts.data?.file ?? sopts.data?.car, base, "file", {
5205
- file: true,
5206
- idx: true
5207
- }),
5208
- meta: ensureURIDefaults(sthis, name, sopts.idx?.meta ?? sopts.data?.meta, base, "meta", { idx: true }),
5209
- wal: ensureURIDefaults(sthis, name, sopts.idx?.wal ?? sopts.data?.wal, base, "wal", { idx: true })
5237
+ car: ensureURIDefaults(sthis, { name }, sopts.idx?.car ?? sopts.data?.car, base, "car", { idx: true }),
5238
+ file: ensureURIDefaults(
5239
+ sthis,
5240
+ { name },
5241
+ sopts.idx?.file ?? sopts.idx?.car ?? sopts.data?.file ?? sopts.data?.car,
5242
+ base,
5243
+ "file",
5244
+ {
5245
+ file: true,
5246
+ idx: true
5247
+ }
5248
+ ),
5249
+ meta: ensureURIDefaults(sthis, { name }, sopts.idx?.meta ?? sopts.data?.meta, base, "meta", { idx: true }),
5250
+ wal: ensureURIDefaults(sthis, { name }, sopts.idx?.wal ?? sopts.data?.wal, base, "wal", { idx: true })
5210
5251
  },
5211
5252
  data: {
5212
- car: ensureURIDefaults(sthis, name, sopts.data?.car, base, "car"),
5213
- file: ensureURIDefaults(sthis, name, sopts.data?.file ?? sopts.data?.car, base, "file", { file: true }),
5214
- meta: ensureURIDefaults(sthis, name, sopts.data?.meta, base, "meta"),
5215
- wal: ensureURIDefaults(sthis, name, sopts.data?.wal, base, "wal")
5253
+ car: ensureURIDefaults(sthis, { name }, sopts.data?.car, base, "car"),
5254
+ file: ensureURIDefaults(sthis, { name }, sopts.data?.file ?? sopts.data?.car, base, "file", { file: true }),
5255
+ meta: ensureURIDefaults(sthis, { name }, sopts.data?.meta, base, "meta"),
5256
+ wal: ensureURIDefaults(sthis, { name }, sopts.data?.wal, base, "wal")
5216
5257
  }
5217
5258
  };
5218
5259
  }
@@ -7218,7 +7259,7 @@ function buildResDelWAL(msgCtx, req, ctx) {
7218
7259
 
7219
7260
  // src/version.ts
7220
7261
  var PACKAGE_VERSION = Object.keys({
7221
- "0.20.0-dev-preview-60": "xxxx"
7262
+ "0.20.0-dev-preview-62": "xxxx"
7222
7263
  })[0];
7223
7264
  export {
7224
7265
  CRDTImpl,