@fireproof/core 0.20.0-dev-preview-25 → 0.20.0-dev-preview-27

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
@@ -113,10 +113,11 @@ declare class keysByFingerprint implements KeysByFingerprint {
113
113
  readonly keys: Record<string, keyWithFingerPrint>;
114
114
  readonly keybag: KeyBag;
115
115
  readonly name: string;
116
+ readonly id: string;
116
117
  static from(keyBag: KeyBag, named: KeysItem): Promise<KeysByFingerprint>;
117
118
  constructor(keyBag: KeyBag, name: string);
118
119
  get(fingerPrint?: Uint8Array | string): Promise<KeyWithFingerPrint | undefined>;
119
- upsert(materialStrOrUint8: string | Uint8Array, def: boolean, keyBagAction?: boolean): Promise<Result<KeyUpsertResult>>;
120
+ upsert(materialStrOrUint8: string | Uint8Array, def?: boolean, keyBagAction?: boolean): Promise<Result<KeyUpsertResult>>;
120
121
  asKeysItem(): Promise<KeysItem>;
121
122
  }
122
123
  declare class KeyBag {
@@ -463,9 +464,10 @@ interface KeyUpsertResult {
463
464
  readonly kfp: KeyWithFingerPrint;
464
465
  }
465
466
  interface KeysByFingerprint {
467
+ readonly id: string;
466
468
  readonly name: string;
467
469
  get(fingerPrint?: Uint8Array | string): Promise<KeyWithFingerPrint | undefined>;
468
- upsert(key: string | Uint8Array, def: boolean): Promise<Result<KeyUpsertResult>>;
470
+ upsert(key: string | Uint8Array, def?: boolean): Promise<Result<KeyUpsertResult>>;
469
471
  asKeysItem(): Promise<KeysItem>;
470
472
  }
471
473
  interface CryptoAction {
@@ -1359,7 +1361,7 @@ interface WriteQueue<T extends DocUpdate<S>, S extends DocTypes = DocTypes> {
1359
1361
  close(): Promise<void>;
1360
1362
  }
1361
1363
  interface LedgerOpts {
1362
- readonly name?: string;
1364
+ readonly name: string;
1363
1365
  readonly meta?: DbMeta;
1364
1366
  readonly gatewayInterceptor?: SerdeGatewayInterceptor;
1365
1367
  readonly writeQueue: WriteQueueParams;
@@ -1384,7 +1386,7 @@ interface Ledger extends HasCRDT {
1384
1386
 
1385
1387
  declare function keyConfigOpts(sthis: SuperThis, name?: string, opts?: ConfigOpts): string;
1386
1388
  declare function isLedger(db: unknown): db is Ledger;
1387
- declare function LedgerFactory(name: string | undefined, opts?: ConfigOpts): Ledger;
1389
+ declare function LedgerFactory(name: string, opts?: ConfigOpts): Ledger;
1388
1390
  declare class LedgerShell implements Ledger {
1389
1391
  readonly ref: LedgerImpl;
1390
1392
  readonly writeQueue: WriteQueue<DocUpdate<DocTypes>>;
package/index.d.ts CHANGED
@@ -113,10 +113,11 @@ declare class keysByFingerprint implements KeysByFingerprint {
113
113
  readonly keys: Record<string, keyWithFingerPrint>;
114
114
  readonly keybag: KeyBag;
115
115
  readonly name: string;
116
+ readonly id: string;
116
117
  static from(keyBag: KeyBag, named: KeysItem): Promise<KeysByFingerprint>;
117
118
  constructor(keyBag: KeyBag, name: string);
118
119
  get(fingerPrint?: Uint8Array | string): Promise<KeyWithFingerPrint | undefined>;
119
- upsert(materialStrOrUint8: string | Uint8Array, def: boolean, keyBagAction?: boolean): Promise<Result<KeyUpsertResult>>;
120
+ upsert(materialStrOrUint8: string | Uint8Array, def?: boolean, keyBagAction?: boolean): Promise<Result<KeyUpsertResult>>;
120
121
  asKeysItem(): Promise<KeysItem>;
121
122
  }
122
123
  declare class KeyBag {
@@ -463,9 +464,10 @@ interface KeyUpsertResult {
463
464
  readonly kfp: KeyWithFingerPrint;
464
465
  }
465
466
  interface KeysByFingerprint {
467
+ readonly id: string;
466
468
  readonly name: string;
467
469
  get(fingerPrint?: Uint8Array | string): Promise<KeyWithFingerPrint | undefined>;
468
- upsert(key: string | Uint8Array, def: boolean): Promise<Result<KeyUpsertResult>>;
470
+ upsert(key: string | Uint8Array, def?: boolean): Promise<Result<KeyUpsertResult>>;
469
471
  asKeysItem(): Promise<KeysItem>;
470
472
  }
471
473
  interface CryptoAction {
@@ -1359,7 +1361,7 @@ interface WriteQueue<T extends DocUpdate<S>, S extends DocTypes = DocTypes> {
1359
1361
  close(): Promise<void>;
1360
1362
  }
1361
1363
  interface LedgerOpts {
1362
- readonly name?: string;
1364
+ readonly name: string;
1363
1365
  readonly meta?: DbMeta;
1364
1366
  readonly gatewayInterceptor?: SerdeGatewayInterceptor;
1365
1367
  readonly writeQueue: WriteQueueParams;
@@ -1384,7 +1386,7 @@ interface Ledger extends HasCRDT {
1384
1386
 
1385
1387
  declare function keyConfigOpts(sthis: SuperThis, name?: string, opts?: ConfigOpts): string;
1386
1388
  declare function isLedger(db: unknown): db is Ledger;
1387
- declare function LedgerFactory(name: string | undefined, opts?: ConfigOpts): Ledger;
1389
+ declare function LedgerFactory(name: string, opts?: ConfigOpts): Ledger;
1388
1390
  declare class LedgerShell implements Ledger {
1389
1391
  readonly ref: LedgerImpl;
1390
1392
  readonly writeQueue: WriteQueue<DocUpdate<DocTypes>>;
package/index.js CHANGED
@@ -589,7 +589,7 @@ var KeyBagProviderFile = class {
589
589
  if (isNotFoundError(e)) {
590
590
  return void 0;
591
591
  }
592
- throw this.logger.Error().Err(e).Str("file", ctx.dirName).Msg("read bag failed").AsError();
592
+ throw this.logger.Error().Err(e).Any("file", ctx).Msg("read bag failed").AsError();
593
593
  }
594
594
  }
595
595
  async set(item) {
@@ -689,6 +689,7 @@ var keysByFingerprint = class _keysByFingerprint {
689
689
  this.keys = {};
690
690
  this.keybag = keyBag;
691
691
  this.name = name;
692
+ this.id = keyBag.rt.sthis.nextId(4).str;
692
693
  }
693
694
  static async from(keyBag, named) {
694
695
  const kbf = new _keysByFingerprint(keyBag, named.name);
@@ -712,23 +713,23 @@ var keysByFingerprint = class _keysByFingerprint {
712
713
  async get(fingerPrint) {
713
714
  if (fingerPrint instanceof Uint8Array) {
714
715
  fingerPrint = base58btc2.encode(fingerPrint);
716
+ } else {
717
+ fingerPrint = fingerPrint || "*";
715
718
  }
716
- if (fingerPrint) {
717
- return this.keys[fingerPrint];
718
- }
719
- const def = this.keys["*"];
720
- if (!def) {
721
- throw this.keybag.logger.Error().Msg("KeyBag: keysByFingerprint: no default").AsError();
719
+ const found = this.keys[fingerPrint];
720
+ if (found) {
721
+ return found;
722
722
  }
723
- return def;
723
+ throw this.keybag.logger.Error().Str("fpr", fingerPrint).Any("fprs", Object.keys(this.keys)).Msg("keysByFingerprint: not found").AsError();
724
724
  }
725
725
  async upsert(materialStrOrUint8, def, keyBagAction = true) {
726
+ def = !!def;
726
727
  const rKfp = await toKeyWithFingerPrint(this.keybag, materialStrOrUint8);
727
728
  if (rKfp.isErr()) {
728
729
  return Result2.Err(rKfp);
729
730
  }
730
731
  const kfp = rKfp.Ok();
731
- const found = this.keys[kfp.fingerPrint];
732
+ let found = this.keys[kfp.fingerPrint];
732
733
  if (found) {
733
734
  if (found.default === def) {
734
735
  return Result2.Ok({
@@ -736,23 +737,24 @@ var keysByFingerprint = class _keysByFingerprint {
736
737
  kfp: found
737
738
  });
738
739
  }
740
+ } else {
741
+ found = new keyWithFingerPrint(kfp, materialStrOrUint8, def);
739
742
  }
740
743
  if (def) {
741
744
  for (const i of Object.values(this.keys)) {
742
745
  i.default = false;
743
746
  }
744
747
  }
745
- const out = new keyWithFingerPrint(kfp, materialStrOrUint8, def);
746
- this.keys[kfp.fingerPrint] = out;
748
+ this.keys[kfp.fingerPrint] = found;
747
749
  if (def) {
748
- this.keys["*"] = out;
750
+ this.keys["*"] = found;
749
751
  }
750
752
  if (keyBagAction) {
751
753
  this.keybag._upsertNamedKey(this);
752
754
  }
753
755
  return Result2.Ok({
754
756
  modified: keyBagAction && true,
755
- kfp: out
757
+ kfp: found
756
758
  });
757
759
  }
758
760
  async asKeysItem() {
@@ -835,7 +837,7 @@ var KeyBag = class {
835
837
  const keyName = `@${keyFactory()}@`;
836
838
  const ret = await this.getNamedKey(keyName);
837
839
  if (ret.isErr()) {
838
- return ret;
840
+ return Result2.Err(ret);
839
841
  }
840
842
  const urb = url.build().setParam(PARAM.STORE_KEY, keyName);
841
843
  return Result2.Ok(urb.URI());
@@ -843,7 +845,7 @@ var KeyBag = class {
843
845
  if (storeKey.startsWith("@") && storeKey.endsWith("@")) {
844
846
  const ret = await this.getNamedKey(storeKey);
845
847
  if (ret.isErr()) {
846
- return ret;
848
+ return Result2.Err(ret);
847
849
  }
848
850
  }
849
851
  return Result2.Ok(url);
@@ -901,6 +903,7 @@ var KeyBag = class {
901
903
  return this._seq.add(async () => {
902
904
  const rKbf = await this._getNamedKey(ksi.name, true);
903
905
  if (rKbf.isErr()) {
906
+ this.logger.Error().Err(rKbf).Str("name", ksi.name).Msg("_upsertNamedKey: getNamedKey failed");
904
907
  this._namedKeyCache.unget(ksi.name);
905
908
  }
906
909
  await bag.set(await ksi.asKeysItem());
@@ -1206,6 +1209,7 @@ var MEMORY_VERSION = "v0.19-memory";
1206
1209
 
1207
1210
  // src/runtime/gateways/memory/gateway.ts
1208
1211
  var MemoryGateway = class {
1212
+ // readonly logger: Logger;
1209
1213
  constructor(sthis, memorys) {
1210
1214
  this.memorys = memorys;
1211
1215
  this.sthis = sthis;
@@ -3125,6 +3129,7 @@ var noCrypto = class {
3125
3129
  this.logger = ensureLogger(sthis, "noCrypto");
3126
3130
  this.crypto = cyrt;
3127
3131
  this.key = {
3132
+ id: sthis.nextId().str,
3128
3133
  name: "noCrypto",
3129
3134
  get: () => {
3130
3135
  throw this.logger.Error().Msg("noCrypto.get not implemented").AsError();
@@ -4700,7 +4705,7 @@ var LedgerImpl = class {
4700
4705
  this.crdt.clock.onTock(() => this._no_update_notify());
4701
4706
  }
4702
4707
  get name() {
4703
- return this.opts.storeUrls.data.data.getParam(PARAM.NAME) ?? "default";
4708
+ return this.opts.name;
4704
4709
  }
4705
4710
  addShell(shell) {
4706
4711
  this.shells.add(shell);
@@ -4898,7 +4903,7 @@ __export(file_exports, {
4898
4903
 
4899
4904
  // src/version.ts
4900
4905
  var PACKAGE_VERSION = Object.keys({
4901
- "0.20.0-dev-preview-25": "xxxx"
4906
+ "0.20.0-dev-preview-27": "xxxx"
4902
4907
  })[0];
4903
4908
  export {
4904
4909
  CRDTImpl,