@fireproof/core 0.20.0-dev-preview-13 → 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
@@ -240,7 +240,7 @@ interface SerdeGateway {
240
240
  put<T>(sthis: SuperThis, url: URI, body: FPEnvelope<T>, loader?: Loadable): Promise<VoidResult>;
241
241
  get<S>(sthis: SuperThis, url: URI, loader?: Loadable): Promise<SerdeGetResult<S>>;
242
242
  delete(sthis: SuperThis, url: URI, loader?: Loadable): Promise<VoidResult>;
243
- subscribe?(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<UnsubscribeResult>;
243
+ subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<UnsubscribeResult>;
244
244
  getPlain(sthis: SuperThis, url: URI, key: string, loader?: Loadable): Promise<Result<Uint8Array>>;
245
245
  destroy(sthis: SuperThis, baseUrl: URI, loader?: Loadable): Promise<VoidResult>;
246
246
  }
@@ -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,14 +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>>;
1541
- put<T>(sthis: SuperThis, url: URI, env: FPEnvelope<T>): Promise<Result<void>>;
1542
- get<S>(sthis: SuperThis, url: URI): Promise<SerdeGetResult<S>>;
1543
- delete(sthis: SuperThis, url: URI): Promise<Result<void>>;
1544
- destroy(sthis: SuperThis, baseURL: URI): Promise<Result<void>>;
1545
- getPlain(sthis: SuperThis, iurl: URI, key: string): Promise<Result<Uint8Array<ArrayBufferLike>, Error>>;
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>>;
1545
+ private subscribeFn;
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>>;
1546
1552
  }
1547
1553
 
1548
1554
  type index$1_CARDecodeEnvelope = CARDecodeEnvelope;
package/index.d.ts CHANGED
@@ -240,7 +240,7 @@ interface SerdeGateway {
240
240
  put<T>(sthis: SuperThis, url: URI, body: FPEnvelope<T>, loader?: Loadable): Promise<VoidResult>;
241
241
  get<S>(sthis: SuperThis, url: URI, loader?: Loadable): Promise<SerdeGetResult<S>>;
242
242
  delete(sthis: SuperThis, url: URI, loader?: Loadable): Promise<VoidResult>;
243
- subscribe?(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<UnsubscribeResult>;
243
+ subscribe(sthis: SuperThis, url: URI, callback: (meta: FPEnvelopeMeta) => Promise<void>, loader?: Loadable): Promise<UnsubscribeResult>;
244
244
  getPlain(sthis: SuperThis, url: URI, key: string, loader?: Loadable): Promise<Result<Uint8Array>>;
245
245
  destroy(sthis: SuperThis, baseUrl: URI, loader?: Loadable): Promise<VoidResult>;
246
246
  }
@@ -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,14 +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>>;
1541
- put<T>(sthis: SuperThis, url: URI, env: FPEnvelope<T>): Promise<Result<void>>;
1542
- get<S>(sthis: SuperThis, url: URI): Promise<SerdeGetResult<S>>;
1543
- delete(sthis: SuperThis, url: URI): Promise<Result<void>>;
1544
- destroy(sthis: SuperThis, baseURL: URI): Promise<Result<void>>;
1545
- getPlain(sthis: SuperThis, iurl: URI, key: string): Promise<Result<Uint8Array<ArrayBufferLike>, Error>>;
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>>;
1545
+ private subscribeFn;
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>>;
1546
1552
  }
1547
1553
 
1548
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 {
@@ -1029,9 +1029,6 @@ var MemoryGateway = class {
1029
1029
  // src/runtime/gateways/def-serde-gateway.ts
1030
1030
  import { Result as Result7 } from "@adviser/cement";
1031
1031
 
1032
- // src/runtime/gateways/fp-envelope-serialize.ts
1033
- import { exception2Result as exception2Result2, Result as Result6 } from "@adviser/cement";
1034
-
1035
1032
  // src/blockstore/fp-envelope.ts
1036
1033
  import { Result as Result5 } from "@adviser/cement";
1037
1034
  var FPEnvelopeType = /* @__PURE__ */ ((FPEnvelopeType2) => {
@@ -1049,6 +1046,7 @@ function File2FPMsg(fpfile) {
1049
1046
  }
1050
1047
 
1051
1048
  // src/runtime/gateways/fp-envelope-serialize.ts
1049
+ import { exception2Result as exception2Result2, Result as Result6 } from "@adviser/cement";
1052
1050
  import { decodeEventBlock, EventBlock } from "@fireproof/vendor/@web3-storage/pail/clock";
1053
1051
  import { base64pad } from "multiformats/bases/base64";
1054
1052
  import { CID } from "multiformats";
@@ -1202,34 +1200,68 @@ async function fpDeserialize(sthis, url, intoRaw, pdecoder) {
1202
1200
  // src/runtime/gateways/def-serde-gateway.ts
1203
1201
  var DefSerdeGateway = class {
1204
1202
  constructor(gw) {
1203
+ this.subscribeFn = /* @__PURE__ */ new Map();
1205
1204
  this.gw = gw;
1206
1205
  }
1207
- start(sthis, baseURL) {
1206
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1207
+ start(sthis, baseURL, loader) {
1208
1208
  return this.gw.start(baseURL, sthis);
1209
1209
  }
1210
- async buildUrl(sthis, baseUrl, key) {
1210
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1211
+ async buildUrl(sthis, baseUrl, key, loader) {
1211
1212
  return this.gw.buildUrl(baseUrl, key, sthis);
1212
1213
  }
1213
- async close(sthis, uri) {
1214
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1215
+ async close(sthis, uri, loader) {
1214
1216
  return this.gw.close(uri, sthis);
1215
1217
  }
1216
- async put(sthis, url, env) {
1218
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1219
+ async put(sthis, url, env, loader) {
1217
1220
  const rUint8 = await fpSerialize(sthis, env);
1218
1221
  if (rUint8.isErr()) return rUint8;
1219
- return this.gw.put(url, rUint8.Ok(), sthis);
1222
+ const ret = this.gw.put(url, rUint8.Ok(), sthis);
1223
+ if (env.type === "meta" /* META */) {
1224
+ if (this.subscribeFn.has(url.toString())) {
1225
+ this.subscribeFn.get(url.toString())(env);
1226
+ }
1227
+ }
1228
+ return ret;
1220
1229
  }
1221
- async get(sthis, url) {
1230
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1231
+ async get(sthis, url, loader) {
1222
1232
  const res = await this.gw.get(url, sthis);
1223
1233
  if (res.isErr()) return Result7.Err(res.Err());
1224
1234
  return fpDeserialize(sthis, url, res);
1225
1235
  }
1226
- async delete(sthis, url) {
1236
+ async subscribe(sthis, url, callback, loader) {
1237
+ if (!this.gw.subscribe) {
1238
+ this.subscribeFn.set(url.toString(), callback);
1239
+ return Result7.Ok(() => {
1240
+ this.subscribeFn.delete(url.toString());
1241
+ });
1242
+ }
1243
+ const unreg = await this.gw.subscribe(
1244
+ url,
1245
+ (raw2) => {
1246
+ fpDeserialize(sthis, url, Result7.Ok(raw2)).then((res) => {
1247
+ if (res.isErr()) return;
1248
+ callback(res.Ok());
1249
+ });
1250
+ },
1251
+ sthis
1252
+ );
1253
+ return unreg;
1254
+ }
1255
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1256
+ async delete(sthis, url, loader) {
1227
1257
  return this.gw.delete(url, sthis);
1228
1258
  }
1229
- async destroy(sthis, baseURL) {
1259
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1260
+ async destroy(sthis, baseURL, loader) {
1230
1261
  return this.gw.destroy(baseURL, sthis);
1231
1262
  }
1232
- async getPlain(sthis, iurl, key) {
1263
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1264
+ async getPlain(sthis, iurl, key, loader) {
1233
1265
  return this.gw.getPlain(iurl, key, sthis);
1234
1266
  }
1235
1267
  };
@@ -3615,6 +3647,9 @@ function toStoreRuntime(sthis, endeOpts = {}) {
3615
3647
  };
3616
3648
  }
3617
3649
 
3650
+ // src/blockstore/connection-base.ts
3651
+ import { exception2Result as exception2Result4, Future as Future3 } from "@adviser/cement";
3652
+
3618
3653
  // src/blockstore/store-remote.ts
3619
3654
  async function RemoteDataStore(sthis, url, opts) {
3620
3655
  const ds = new DataStoreImpl(sthis, url, opts);
@@ -3627,6 +3662,22 @@ async function RemoteMetaStore(sthis, url, opts) {
3627
3662
  return ms;
3628
3663
  }
3629
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
+
3630
3681
  // src/blockstore/connection-base.ts
3631
3682
  function coerceLoader(ref) {
3632
3683
  const refl = ref;
@@ -3641,10 +3692,22 @@ function coerceLoader(ref) {
3641
3692
  }
3642
3693
  var ConnectionBase = class {
3643
3694
  constructor(url, logger) {
3644
- 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;
3645
3699
  this.logger = logger;
3646
3700
  this.url = url;
3647
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
+ }
3648
3711
  async refresh() {
3649
3712
  await throwFalsy(throwFalsy(this.loader).remoteMetaStore).load();
3650
3713
  await (await throwFalsy(this.loader).WALStore()).process();
@@ -3672,22 +3735,34 @@ var ConnectionBase = class {
3672
3735
  loader
3673
3736
  });
3674
3737
  this.loader.remoteMetaStore = remote;
3675
- this.loaded = this.loader.ready().then(async () => {
3738
+ this._metaIsLoading = true;
3739
+ this.loader.ready().then(async () => {
3676
3740
  return remote.load().then(async () => {
3677
- 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();
3678
3753
  });
3679
3754
  });
3680
3755
  }
3681
3756
  async connectStorage(refl) {
3682
3757
  const loader = coerceLoader(refl);
3683
- 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();
3684
3759
  this.loader = loader;
3685
3760
  const dataUrl = this.url.build().defParam("store" /* STORE */, "data").URI();
3686
3761
  const rgateway = await getStartedGateway(loader.sthis, dataUrl);
3687
3762
  if (rgateway.isErr())
3688
- 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();
3689
3764
  const name = dataUrl.getParam("name" /* NAME */);
3690
- 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;
3691
3766
  loader.remoteCarStore = await RemoteDataStore(loader.sthis, this.url, {
3692
3767
  gateway: rgateway.Ok().gateway,
3693
3768
  loader
@@ -4303,22 +4378,6 @@ var CRDTImpl = class {
4303
4378
  }
4304
4379
  };
4305
4380
 
4306
- // src/context.ts
4307
- var Context = class {
4308
- constructor() {
4309
- this.ctx = /* @__PURE__ */ new Map();
4310
- }
4311
- set(key, value) {
4312
- this.ctx.set(key, value);
4313
- }
4314
- get(key) {
4315
- return this.ctx.get(key);
4316
- }
4317
- delete(key) {
4318
- this.ctx.delete(key);
4319
- }
4320
- };
4321
-
4322
4381
  // src/ledger.ts
4323
4382
  var ledgers = new KeyedResolvOnce4();
4324
4383
  function keyConfigOpts(sthis, name, opts) {
@@ -4506,7 +4565,7 @@ var LedgerImpl = class {
4506
4565
  };
4507
4566
  function defaultURI2(sthis, curi, uri, store, ctx) {
4508
4567
  ctx = ctx || {};
4509
- 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);
4510
4569
  if (!ret.hasParam("name" /* NAME */)) {
4511
4570
  const name = sthis.pathOps.basename(ret.URI().pathname);
4512
4571
  if (!name) {
@@ -4613,7 +4672,7 @@ __export(file_exports, {
4613
4672
 
4614
4673
  // src/version.ts
4615
4674
  var PACKAGE_VERSION = Object.keys({
4616
- "0.20.0-dev-preview-13": "xxxx"
4675
+ "0.20.0-dev-preview-15": "xxxx"
4617
4676
  })[0];
4618
4677
  export {
4619
4678
  CRDTImpl,