@fireproof/core 0.20.0-dev-preview-14 → 0.20.0-dev-preview-15

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
@@ -295,6 +295,13 @@ interface SerdeGatewayInterceptor {
295
295
  subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader: Loadable): Promise<Result<SerdeGatewaySubscribeReturn>>;
296
296
  }
297
297
 
298
+ declare class Context {
299
+ private ctx;
300
+ set<T>(key: string, value: T): void;
301
+ get<T>(key: string): T | undefined;
302
+ delete(key: string): void;
303
+ }
304
+
298
305
  type AnyLink = Link<unknown, number, number, Version>;
299
306
  type CarGroup = AnyLink[];
300
307
  type CarLog = CarGroup[];
@@ -450,7 +457,8 @@ interface RefBlockstore {
450
457
  readonly blockstore: RefLoadable;
451
458
  }
452
459
  interface Connection {
453
- readonly loaded: Promise<void>;
460
+ loaded(): Future<void>;
461
+ readonly context: Context;
454
462
  connectStorage(ref: RefLoadable | RefBlockstore): void;
455
463
  }
456
464
  interface BaseStore {
@@ -703,10 +711,13 @@ declare function parseCarFile<T>(reader: CarReader$1, logger: Logger): Promise<C
703
711
  declare abstract class ConnectionBase implements Connection {
704
712
  private loader?;
705
713
  taskManager?: TaskManager;
706
- loaded: Promise<void>;
714
+ readonly context: Context;
707
715
  readonly url: URI;
708
716
  readonly logger: Logger;
709
717
  constructor(url: URI, logger: Logger);
718
+ private readonly _loaded;
719
+ private _metaIsLoading;
720
+ loaded(): Future<void>;
710
721
  refresh(): Promise<void>;
711
722
  connect(refl: RefLoadable | RefBlockstore): Promise<void>;
712
723
  connectMeta(refl: RefLoadable | RefBlockstore): Promise<void>;
@@ -897,13 +908,6 @@ declare class Index<K extends IndexKeyType, T extends DocTypes, R extends DocFra
897
908
  _updateIndex(): Promise<IndexTransactionMeta>;
898
909
  }
899
910
 
900
- declare class Context {
901
- private ctx;
902
- set<T>(key: string, value: T): void;
903
- get<T>(key: string): T | undefined;
904
- delete(key: string): void;
905
- }
906
-
907
911
  type Falsy = false | null | undefined;
908
912
  declare function isFalsy(value: unknown): value is Falsy;
909
913
  declare enum PARAM {
@@ -1535,16 +1539,16 @@ declare namespace index$2 {
1535
1539
  declare class DefSerdeGateway implements SerdeGateway {
1536
1540
  readonly gw: Gateway;
1537
1541
  constructor(gw: Gateway);
1538
- start(sthis: SuperThis, baseURL: URI): Promise<Result<URI>>;
1539
- buildUrl(sthis: SuperThis, baseUrl: URI, key: string): Promise<Result<URI>>;
1540
- close(sthis: SuperThis, uri: URI): Promise<Result<void>>;
1542
+ start(sthis: SuperThis, baseURL: URI, loader?: Loadable): Promise<Result<URI>>;
1543
+ buildUrl(sthis: SuperThis, baseUrl: URI, key: string, loader?: Loadable): Promise<Result<URI>>;
1544
+ close(sthis: SuperThis, uri: URI, loader?: Loadable): Promise<Result<void>>;
1541
1545
  private subscribeFn;
1542
- put<T>(sthis: SuperThis, url: URI, env: FPEnvelope<T>): Promise<Result<void>>;
1543
- get<S>(sthis: SuperThis, url: URI): Promise<SerdeGetResult<S>>;
1544
- subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>): Promise<Result<() => void>>;
1545
- delete(sthis: SuperThis, url: URI): Promise<Result<void>>;
1546
- destroy(sthis: SuperThis, baseURL: URI): Promise<Result<void>>;
1547
- getPlain(sthis: SuperThis, iurl: URI, key: string): Promise<Result<Uint8Array<ArrayBufferLike>, Error>>;
1546
+ put<T>(sthis: SuperThis, url: URI, env: FPEnvelope<T>, loader?: Loadable): Promise<Result<void>>;
1547
+ get<S>(sthis: SuperThis, url: URI, loader?: Loadable): Promise<SerdeGetResult<S>>;
1548
+ subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<Result<() => void>>;
1549
+ delete(sthis: SuperThis, url: URI, loader?: Loadable): Promise<Result<void>>;
1550
+ destroy(sthis: SuperThis, baseURL: URI, loader?: Loadable): Promise<Result<void>>;
1551
+ getPlain(sthis: SuperThis, iurl: URI, key: string, loader?: Loadable): Promise<Result<Uint8Array<ArrayBufferLike>, Error>>;
1548
1552
  }
1549
1553
 
1550
1554
  type index$1_CARDecodeEnvelope = CARDecodeEnvelope;
package/index.d.ts CHANGED
@@ -295,6 +295,13 @@ interface SerdeGatewayInterceptor {
295
295
  subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader: Loadable): Promise<Result<SerdeGatewaySubscribeReturn>>;
296
296
  }
297
297
 
298
+ declare class Context {
299
+ private ctx;
300
+ set<T>(key: string, value: T): void;
301
+ get<T>(key: string): T | undefined;
302
+ delete(key: string): void;
303
+ }
304
+
298
305
  type AnyLink = Link<unknown, number, number, Version>;
299
306
  type CarGroup = AnyLink[];
300
307
  type CarLog = CarGroup[];
@@ -450,7 +457,8 @@ interface RefBlockstore {
450
457
  readonly blockstore: RefLoadable;
451
458
  }
452
459
  interface Connection {
453
- readonly loaded: Promise<void>;
460
+ loaded(): Future<void>;
461
+ readonly context: Context;
454
462
  connectStorage(ref: RefLoadable | RefBlockstore): void;
455
463
  }
456
464
  interface BaseStore {
@@ -703,10 +711,13 @@ declare function parseCarFile<T>(reader: CarReader$1, logger: Logger): Promise<C
703
711
  declare abstract class ConnectionBase implements Connection {
704
712
  private loader?;
705
713
  taskManager?: TaskManager;
706
- loaded: Promise<void>;
714
+ readonly context: Context;
707
715
  readonly url: URI;
708
716
  readonly logger: Logger;
709
717
  constructor(url: URI, logger: Logger);
718
+ private readonly _loaded;
719
+ private _metaIsLoading;
720
+ loaded(): Future<void>;
710
721
  refresh(): Promise<void>;
711
722
  connect(refl: RefLoadable | RefBlockstore): Promise<void>;
712
723
  connectMeta(refl: RefLoadable | RefBlockstore): Promise<void>;
@@ -897,13 +908,6 @@ declare class Index<K extends IndexKeyType, T extends DocTypes, R extends DocFra
897
908
  _updateIndex(): Promise<IndexTransactionMeta>;
898
909
  }
899
910
 
900
- declare class Context {
901
- private ctx;
902
- set<T>(key: string, value: T): void;
903
- get<T>(key: string): T | undefined;
904
- delete(key: string): void;
905
- }
906
-
907
911
  type Falsy = false | null | undefined;
908
912
  declare function isFalsy(value: unknown): value is Falsy;
909
913
  declare enum PARAM {
@@ -1535,16 +1539,16 @@ declare namespace index$2 {
1535
1539
  declare class DefSerdeGateway implements SerdeGateway {
1536
1540
  readonly gw: Gateway;
1537
1541
  constructor(gw: Gateway);
1538
- start(sthis: SuperThis, baseURL: URI): Promise<Result<URI>>;
1539
- buildUrl(sthis: SuperThis, baseUrl: URI, key: string): Promise<Result<URI>>;
1540
- close(sthis: SuperThis, uri: URI): Promise<Result<void>>;
1542
+ start(sthis: SuperThis, baseURL: URI, loader?: Loadable): Promise<Result<URI>>;
1543
+ buildUrl(sthis: SuperThis, baseUrl: URI, key: string, loader?: Loadable): Promise<Result<URI>>;
1544
+ close(sthis: SuperThis, uri: URI, loader?: Loadable): Promise<Result<void>>;
1541
1545
  private subscribeFn;
1542
- put<T>(sthis: SuperThis, url: URI, env: FPEnvelope<T>): Promise<Result<void>>;
1543
- get<S>(sthis: SuperThis, url: URI): Promise<SerdeGetResult<S>>;
1544
- subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>): Promise<Result<() => void>>;
1545
- delete(sthis: SuperThis, url: URI): Promise<Result<void>>;
1546
- destroy(sthis: SuperThis, baseURL: URI): Promise<Result<void>>;
1547
- getPlain(sthis: SuperThis, iurl: URI, key: string): Promise<Result<Uint8Array<ArrayBufferLike>, Error>>;
1546
+ put<T>(sthis: SuperThis, url: URI, env: FPEnvelope<T>, loader?: Loadable): Promise<Result<void>>;
1547
+ get<S>(sthis: SuperThis, url: URI, loader?: Loadable): Promise<SerdeGetResult<S>>;
1548
+ subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<Result<() => void>>;
1549
+ delete(sthis: SuperThis, url: URI, loader?: Loadable): Promise<Result<void>>;
1550
+ destroy(sthis: SuperThis, baseURL: URI, loader?: Loadable): Promise<Result<void>>;
1551
+ getPlain(sthis: SuperThis, iurl: URI, key: string, loader?: Loadable): Promise<Result<Uint8Array<ArrayBufferLike>, Error>>;
1548
1552
  }
1549
1553
 
1550
1554
  type index$1_CARDecodeEnvelope = CARDecodeEnvelope;
package/index.js CHANGED
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/ledger.ts
8
- import { BuildURI as BuildURI2, KeyedResolvOnce as KeyedResolvOnce4, ResolveOnce as ResolveOnce7, URI as URI12 } from "@adviser/cement";
8
+ import { BuildURI as BuildURI2, KeyedResolvOnce as KeyedResolvOnce4, ResolveOnce as ResolveOnce7, URI as URI13 } from "@adviser/cement";
9
9
 
10
10
  // src/utils.ts
11
11
  import {
@@ -1203,16 +1203,20 @@ var DefSerdeGateway = class {
1203
1203
  this.subscribeFn = /* @__PURE__ */ new Map();
1204
1204
  this.gw = gw;
1205
1205
  }
1206
- start(sthis, baseURL) {
1206
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1207
+ start(sthis, baseURL, loader) {
1207
1208
  return this.gw.start(baseURL, sthis);
1208
1209
  }
1209
- async buildUrl(sthis, baseUrl, key) {
1210
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1211
+ async buildUrl(sthis, baseUrl, key, loader) {
1210
1212
  return this.gw.buildUrl(baseUrl, key, sthis);
1211
1213
  }
1212
- async close(sthis, uri) {
1214
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1215
+ async close(sthis, uri, loader) {
1213
1216
  return this.gw.close(uri, sthis);
1214
1217
  }
1215
- async put(sthis, url, env) {
1218
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1219
+ async put(sthis, url, env, loader) {
1216
1220
  const rUint8 = await fpSerialize(sthis, env);
1217
1221
  if (rUint8.isErr()) return rUint8;
1218
1222
  const ret = this.gw.put(url, rUint8.Ok(), sthis);
@@ -1223,12 +1227,13 @@ var DefSerdeGateway = class {
1223
1227
  }
1224
1228
  return ret;
1225
1229
  }
1226
- async get(sthis, url) {
1230
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1231
+ async get(sthis, url, loader) {
1227
1232
  const res = await this.gw.get(url, sthis);
1228
1233
  if (res.isErr()) return Result7.Err(res.Err());
1229
1234
  return fpDeserialize(sthis, url, res);
1230
1235
  }
1231
- async subscribe(sthis, url, callback) {
1236
+ async subscribe(sthis, url, callback, loader) {
1232
1237
  if (!this.gw.subscribe) {
1233
1238
  this.subscribeFn.set(url.toString(), callback);
1234
1239
  return Result7.Ok(() => {
@@ -1247,13 +1252,16 @@ var DefSerdeGateway = class {
1247
1252
  );
1248
1253
  return unreg;
1249
1254
  }
1250
- async delete(sthis, url) {
1255
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1256
+ async delete(sthis, url, loader) {
1251
1257
  return this.gw.delete(url, sthis);
1252
1258
  }
1253
- async destroy(sthis, baseURL) {
1259
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1260
+ async destroy(sthis, baseURL, loader) {
1254
1261
  return this.gw.destroy(baseURL, sthis);
1255
1262
  }
1256
- async getPlain(sthis, iurl, key) {
1263
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1264
+ async getPlain(sthis, iurl, key, loader) {
1257
1265
  return this.gw.getPlain(iurl, key, sthis);
1258
1266
  }
1259
1267
  };
@@ -3639,6 +3647,9 @@ function toStoreRuntime(sthis, endeOpts = {}) {
3639
3647
  };
3640
3648
  }
3641
3649
 
3650
+ // src/blockstore/connection-base.ts
3651
+ import { exception2Result as exception2Result4, Future as Future3 } from "@adviser/cement";
3652
+
3642
3653
  // src/blockstore/store-remote.ts
3643
3654
  async function RemoteDataStore(sthis, url, opts) {
3644
3655
  const ds = new DataStoreImpl(sthis, url, opts);
@@ -3651,6 +3662,22 @@ async function RemoteMetaStore(sthis, url, opts) {
3651
3662
  return ms;
3652
3663
  }
3653
3664
 
3665
+ // src/context.ts
3666
+ var Context = class {
3667
+ constructor() {
3668
+ this.ctx = /* @__PURE__ */ new Map();
3669
+ }
3670
+ set(key, value) {
3671
+ this.ctx.set(key, value);
3672
+ }
3673
+ get(key) {
3674
+ return this.ctx.get(key);
3675
+ }
3676
+ delete(key) {
3677
+ this.ctx.delete(key);
3678
+ }
3679
+ };
3680
+
3654
3681
  // src/blockstore/connection-base.ts
3655
3682
  function coerceLoader(ref) {
3656
3683
  const refl = ref;
@@ -3665,10 +3692,22 @@ function coerceLoader(ref) {
3665
3692
  }
3666
3693
  var ConnectionBase = class {
3667
3694
  constructor(url, logger) {
3668
- this.loaded = Promise.resolve();
3695
+ // loaded: Promise<void> = Promise.resolve();
3696
+ this.context = new Context();
3697
+ this._loaded = /* @__PURE__ */ new Set();
3698
+ this._metaIsLoading = false;
3669
3699
  this.logger = logger;
3670
3700
  this.url = url;
3671
3701
  }
3702
+ loaded() {
3703
+ const f = new Future3();
3704
+ if (!this._metaIsLoading) {
3705
+ f.resolve();
3706
+ } else {
3707
+ this._loaded.add(f);
3708
+ }
3709
+ return f;
3710
+ }
3672
3711
  async refresh() {
3673
3712
  await throwFalsy(throwFalsy(this.loader).remoteMetaStore).load();
3674
3713
  await (await throwFalsy(this.loader).WALStore()).process();
@@ -3696,22 +3735,34 @@ var ConnectionBase = class {
3696
3735
  loader
3697
3736
  });
3698
3737
  this.loader.remoteMetaStore = remote;
3699
- this.loaded = this.loader.ready().then(async () => {
3738
+ this._metaIsLoading = true;
3739
+ this.loader.ready().then(async () => {
3700
3740
  return remote.load().then(async () => {
3701
- return (await throwFalsy(this.loader).WALStore()).process();
3741
+ const res = await exception2Result4(async () => {
3742
+ return await (await throwFalsy(this.loader).WALStore()).process();
3743
+ });
3744
+ this._metaIsLoading = false;
3745
+ for (const f of this._loaded) {
3746
+ if (res.isErr()) {
3747
+ f.reject(res.Err());
3748
+ } else {
3749
+ f.resolve();
3750
+ }
3751
+ }
3752
+ this._loaded.clear();
3702
3753
  });
3703
3754
  });
3704
3755
  }
3705
3756
  async connectStorage(refl) {
3706
3757
  const loader = coerceLoader(refl);
3707
- if (!loader) throw this.logger.Error().Msg("connectStorage_X: loader is required").AsError();
3758
+ if (!loader) throw this.logger.Error().Msg("connectStorage: loader is required").AsError();
3708
3759
  this.loader = loader;
3709
3760
  const dataUrl = this.url.build().defParam("store" /* STORE */, "data").URI();
3710
3761
  const rgateway = await getStartedGateway(loader.sthis, dataUrl);
3711
3762
  if (rgateway.isErr())
3712
- throw this.logger.Error().Result("err", rgateway).Url(dataUrl).Msg("connectStorage_X: gateway is required").AsError();
3763
+ throw this.logger.Error().Result("err", rgateway).Url(dataUrl).Msg("connectStorage: gateway is required").AsError();
3713
3764
  const name = dataUrl.getParam("name" /* NAME */);
3714
- if (!name) throw this.logger.Error().Url(dataUrl).Msg("connectStorage_X: name is required").AsError;
3765
+ if (!name) throw this.logger.Error().Url(dataUrl).Msg("connectStorage: name is required").AsError;
3715
3766
  loader.remoteCarStore = await RemoteDataStore(loader.sthis, this.url, {
3716
3767
  gateway: rgateway.Ok().gateway,
3717
3768
  loader
@@ -4327,22 +4378,6 @@ var CRDTImpl = class {
4327
4378
  }
4328
4379
  };
4329
4380
 
4330
- // src/context.ts
4331
- var Context = class {
4332
- constructor() {
4333
- this.ctx = /* @__PURE__ */ new Map();
4334
- }
4335
- set(key, value) {
4336
- this.ctx.set(key, value);
4337
- }
4338
- get(key) {
4339
- return this.ctx.get(key);
4340
- }
4341
- delete(key) {
4342
- this.ctx.delete(key);
4343
- }
4344
- };
4345
-
4346
4381
  // src/ledger.ts
4347
4382
  var ledgers = new KeyedResolvOnce4();
4348
4383
  function keyConfigOpts(sthis, name, opts) {
@@ -4530,7 +4565,7 @@ var LedgerImpl = class {
4530
4565
  };
4531
4566
  function defaultURI2(sthis, curi, uri, store, ctx) {
4532
4567
  ctx = ctx || {};
4533
- const ret = (curi ? URI12.from(curi) : uri).build().setParam("store" /* STORE */, store);
4568
+ const ret = (curi ? URI13.from(curi) : uri).build().setParam("store" /* STORE */, store);
4534
4569
  if (!ret.hasParam("name" /* NAME */)) {
4535
4570
  const name = sthis.pathOps.basename(ret.URI().pathname);
4536
4571
  if (!name) {
@@ -4637,7 +4672,7 @@ __export(file_exports, {
4637
4672
 
4638
4673
  // src/version.ts
4639
4674
  var PACKAGE_VERSION = Object.keys({
4640
- "0.20.0-dev-preview-14": "xxxx"
4675
+ "0.20.0-dev-preview-15": "xxxx"
4641
4676
  })[0];
4642
4677
  export {
4643
4678
  CRDTImpl,