@typeberry/convert 0.9.0-959889e → 0.9.0-a723180

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.
Files changed (3) hide show
  1. package/index.js +35 -7
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -8832,9 +8832,11 @@ class SortedArray {
8832
8832
  removeOne(v) {
8833
8833
  const findIdx = this.binarySearch(v);
8834
8834
  if (findIdx.isEqual) {
8835
- // remove the element
8836
- this.array.splice(findIdx.idx, 1);
8835
+ // remove the element and return the stored one
8836
+ const [removed] = this.array.splice(findIdx.idx, 1);
8837
+ return removed;
8837
8838
  }
8839
+ return undefined;
8838
8840
  }
8839
8841
  has(v) {
8840
8842
  return this.binarySearch(v).isEqual;
@@ -8989,8 +8991,12 @@ class SortedSet extends SortedArray {
8989
8991
  */
8990
8992
  replace(v) {
8991
8993
  const findIdx = this.binarySearch(v);
8992
- const toRemove = findIdx.isEqual ? 1 : 0;
8993
- this.array.splice(findIdx.idx, toRemove, v);
8994
+ if (findIdx.isEqual) {
8995
+ const [displaced] = this.array.splice(findIdx.idx, 1, v);
8996
+ return displaced;
8997
+ }
8998
+ this.array.splice(findIdx.idx, 0, v);
8999
+ return undefined;
8994
9000
  }
8995
9001
  /** Create a new SortedSet from two sorted collections. */
8996
9002
  static fromTwoSortedCollections(first, second) {
@@ -11521,6 +11527,13 @@ var KnownChainSpec;
11521
11527
  /** Full chain spec. */
11522
11528
  KnownChainSpec["Full"] = "full";
11523
11529
  })(KnownChainSpec || (KnownChainSpec = {}));
11530
+ /** Persistent regular-node database backend. */
11531
+ var RegularStateBackend;
11532
+ (function (RegularStateBackend) {
11533
+ /** @deprecated lmdb remains available as an explicit fallback, but fjall is the default backend. */
11534
+ RegularStateBackend["Lmdb"] = "lmdb";
11535
+ RegularStateBackend["Fjall"] = "fjall";
11536
+ })(RegularStateBackend || (RegularStateBackend = {}));
11524
11537
  const knownChainSpecFromJson = json.fromString((input, ctx) => {
11525
11538
  switch (input) {
11526
11539
  case KnownChainSpec.Tiny:
@@ -11531,12 +11544,23 @@ const knownChainSpecFromJson = json.fromString((input, ctx) => {
11531
11544
  throw Error(`unknown network flavor: ${input} at ${ctx}`);
11532
11545
  }
11533
11546
  });
11547
+ const regularStateBackendFromJson = json.fromString((input, ctx) => {
11548
+ switch (input) {
11549
+ case RegularStateBackend.Lmdb:
11550
+ return RegularStateBackend.Lmdb;
11551
+ case RegularStateBackend.Fjall:
11552
+ return RegularStateBackend.Fjall;
11553
+ default:
11554
+ throw Error(`unknown state backend: ${input} at ${ctx}`);
11555
+ }
11556
+ });
11534
11557
  class NodeConfiguration {
11535
11558
  $schema;
11536
11559
  version;
11537
11560
  flavor;
11538
11561
  chainSpec;
11539
11562
  databaseBasePath;
11563
+ stateBackend;
11540
11564
  authorship;
11541
11565
  static fromJson = json.object({
11542
11566
  $schema: "string",
@@ -11544,22 +11568,26 @@ class NodeConfiguration {
11544
11568
  flavor: knownChainSpecFromJson,
11545
11569
  chain_spec: JipChainSpec.fromJson,
11546
11570
  database_base_path: json.optional("string"),
11571
+ state_backend: json.optional(regularStateBackendFromJson),
11547
11572
  authorship: AuthorshipOptions.fromJson,
11548
11573
  }, NodeConfiguration.new);
11549
- static new({ $schema, version, flavor, chain_spec, database_base_path, authorship }) {
11574
+ static new({ $schema, version, flavor, chain_spec, database_base_path, state_backend, authorship, }) {
11550
11575
  if (version !== 1) {
11551
11576
  throw new Error("Only version=1 config is supported.");
11552
11577
  }
11553
- return new NodeConfiguration($schema, version, flavor, chain_spec, database_base_path ?? undefined, authorship);
11578
+ return new NodeConfiguration($schema, version, flavor, chain_spec, database_base_path ?? undefined, state_backend ?? RegularStateBackend.Fjall, authorship);
11554
11579
  }
11555
11580
  constructor($schema, version, flavor, chainSpec,
11556
11581
  /** If database path is not provided, we load an in-memory db. */
11557
- databaseBasePath, authorship) {
11582
+ databaseBasePath,
11583
+ /** Persistent database backend used when `databaseBasePath` is set. */
11584
+ stateBackend, authorship) {
11558
11585
  this.$schema = $schema;
11559
11586
  this.version = version;
11560
11587
  this.flavor = flavor;
11561
11588
  this.chainSpec = chainSpec;
11562
11589
  this.databaseBasePath = databaseBasePath;
11590
+ this.stateBackend = stateBackend;
11563
11591
  this.authorship = authorship;
11564
11592
  }
11565
11593
  }