@typeberry/jam 0.2.0-5746fdc → 0.2.0-661fe38

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.
@@ -24033,44 +24033,40 @@ var GpVersion;
24033
24033
  GpVersion["V0_6_7"] = "0.6.7";
24034
24034
  GpVersion["V0_7_0"] = "0.7.0";
24035
24035
  GpVersion["V0_7_1"] = "0.7.1";
24036
- GpVersion["V0_7_2"] = "0.7.2-preview";
24036
+ GpVersion["V0_7_2"] = "0.7.2";
24037
24037
  })(GpVersion || (GpVersion = {}));
24038
24038
  var TestSuite;
24039
24039
  (function (TestSuite) {
24040
24040
  TestSuite["W3F_DAVXY"] = "w3f-davxy";
24041
24041
  TestSuite["JAMDUNA"] = "jamduna";
24042
24042
  })(TestSuite || (TestSuite = {}));
24043
+ const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
24043
24044
  const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
24044
- const DEFAULT_VERSION = GpVersion.V0_7_1;
24045
+ const DEFAULT_VERSION = GpVersion.V0_7_2;
24045
24046
  const env = typeof process === "undefined" ? {} : process.env;
24046
24047
  let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
24047
24048
  let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
24048
- const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
24049
24049
  function parseCurrentVersion(env) {
24050
24050
  if (env === undefined) {
24051
24051
  return undefined;
24052
24052
  }
24053
- switch (env) {
24054
- case GpVersion.V0_6_7:
24055
- case GpVersion.V0_7_0:
24056
- case GpVersion.V0_7_1:
24057
- case GpVersion.V0_7_2:
24058
- return env;
24059
- default:
24060
- throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
24053
+ for (const v of Object.values(GpVersion)) {
24054
+ if (env === v) {
24055
+ return v;
24056
+ }
24061
24057
  }
24058
+ throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
24062
24059
  }
24063
24060
  function parseCurrentSuite(env) {
24064
24061
  if (env === undefined) {
24065
24062
  return undefined;
24066
24063
  }
24067
- switch (env) {
24068
- case TestSuite.W3F_DAVXY:
24069
- case TestSuite.JAMDUNA:
24070
- return env;
24071
- default:
24072
- throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
24064
+ for (const s of Object.values(TestSuite)) {
24065
+ if (env === s) {
24066
+ return s;
24067
+ }
24073
24068
  }
24069
+ throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
24074
24070
  }
24075
24071
  class Compatibility {
24076
24072
  static override(version) {
@@ -24231,6 +24227,13 @@ class WithDebug {
24231
24227
  return debug_inspect(this);
24232
24228
  }
24233
24229
  }
24230
+ function lazyInspect(obj) {
24231
+ return {
24232
+ toString() {
24233
+ return debug_inspect(obj);
24234
+ },
24235
+ };
24236
+ }
24234
24237
 
24235
24238
  ;// CONCATENATED MODULE: ./packages/core/utils/dev.ts
24236
24239
  const dev_env = typeof process === "undefined" ? {} : process.env;
@@ -28621,6 +28624,8 @@ const EC_SEGMENT_SIZE = 4104;
28621
28624
  * Additional data that has to be passed to the codec to correctly parse incoming bytes.
28622
28625
  */
28623
28626
  class ChainSpec extends WithDebug {
28627
+ /** Human-readable name of the chain spec. */
28628
+ name;
28624
28629
  /** Number of validators. */
28625
28630
  validatorsCount;
28626
28631
  /** 1/3 of number of validators */
@@ -28663,6 +28668,7 @@ class ChainSpec extends WithDebug {
28663
28668
  maxLookupAnchorAge;
28664
28669
  constructor(data) {
28665
28670
  super();
28671
+ this.name = data.name;
28666
28672
  this.validatorsCount = data.validatorsCount;
28667
28673
  this.thirdOfValidators = numbers_tryAsU16(Math.floor(data.validatorsCount / 3));
28668
28674
  this.validatorsSuperMajority = numbers_tryAsU16(Math.floor(data.validatorsCount / 3) * 2 + 1);
@@ -28683,6 +28689,7 @@ class ChainSpec extends WithDebug {
28683
28689
  }
28684
28690
  /** Set of values for "tiny" chain as defined in JAM test vectors. */
28685
28691
  const tinyChainSpec = new ChainSpec({
28692
+ name: "tiny",
28686
28693
  validatorsCount: numbers_tryAsU16(6),
28687
28694
  coresCount: numbers_tryAsU16(2),
28688
28695
  epochLength: numbers_tryAsU32(12),
@@ -28704,6 +28711,7 @@ const tinyChainSpec = new ChainSpec({
28704
28711
  * Please note that only validatorsCount and epochLength are "full", the rest is copied from "tiny".
28705
28712
  */
28706
28713
  const fullChainSpec = new ChainSpec({
28714
+ name: "full",
28707
28715
  validatorsCount: numbers_tryAsU16(1023),
28708
28716
  coresCount: numbers_tryAsU16(341),
28709
28717
  epochLength: numbers_tryAsU32(600),
@@ -31321,8 +31329,8 @@ const DEV_CONFIG = "dev";
31321
31329
  const DEFAULT_CONFIG = "default";
31322
31330
  const NODE_DEFAULTS = {
31323
31331
  name: isBrowser() ? "browser" : external_node_os_default().hostname(),
31324
- config: DEFAULT_CONFIG,
31325
- pvm: PvmBackend.BuiltIn,
31332
+ config: [DEFAULT_CONFIG],
31333
+ pvm: PvmBackend.Ananas,
31326
31334
  };
31327
31335
  /** Chain spec chooser. */
31328
31336
  var KnownChainSpec;
@@ -31374,25 +31382,137 @@ class NodeConfiguration {
31374
31382
  this.authorship = authorship;
31375
31383
  }
31376
31384
  }
31377
- function loadConfig(configPath) {
31378
- if (configPath === DEFAULT_CONFIG) {
31379
- logger.log `🔧 Loading DEFAULT config`;
31380
- return parseFromJson(configs.default, NodeConfiguration.fromJson);
31381
- }
31382
- if (configPath === DEV_CONFIG) {
31383
- logger.log `🔧 Loading DEV config`;
31384
- return parseFromJson(configs.dev, NodeConfiguration.fromJson);
31385
+ function loadConfig(config, withRelPath) {
31386
+ logger.log `🔧 Loading config`;
31387
+ let mergedJson = {};
31388
+ for (const entry of config) {
31389
+ logger.log `🔧 Applying '${entry}'`;
31390
+ if (entry === DEV_CONFIG) {
31391
+ mergedJson = structuredClone(configs.dev); // clone to avoid mutating the original config. not doing a merge since dev and default should theoretically replace all properties.
31392
+ continue;
31393
+ }
31394
+ if (entry === DEFAULT_CONFIG) {
31395
+ mergedJson = structuredClone(configs.default);
31396
+ continue;
31397
+ }
31398
+ // try to parse as JSON
31399
+ try {
31400
+ const parsed = JSON.parse(entry);
31401
+ deepMerge(mergedJson, parsed);
31402
+ continue;
31403
+ }
31404
+ catch { }
31405
+ // if not, try to load as file
31406
+ if (entry.indexOf("=") === -1 && entry.endsWith(".json")) {
31407
+ try {
31408
+ const configFile = fs.readFileSync(withRelPath(entry), "utf8");
31409
+ const parsed = JSON.parse(configFile);
31410
+ deepMerge(mergedJson, parsed);
31411
+ }
31412
+ catch (e) {
31413
+ throw new Error(`Unable to load config from ${entry}: ${e}`);
31414
+ }
31415
+ }
31416
+ else {
31417
+ // finally try to process as a pseudo-jq query
31418
+ try {
31419
+ processQuery(mergedJson, entry, withRelPath);
31420
+ }
31421
+ catch (e) {
31422
+ throw new Error(`Error while processing '${entry}': ${e}`);
31423
+ }
31424
+ }
31385
31425
  }
31386
31426
  try {
31387
- logger.log `🔧 Loading config from ${configPath}`;
31388
- const configFile = fs.readFileSync(configPath, "utf8");
31389
- const parsed = JSON.parse(configFile);
31390
- return parseFromJson(parsed, NodeConfiguration.fromJson);
31427
+ const parsed = parseFromJson(mergedJson, NodeConfiguration.fromJson);
31428
+ logger.log `🔧 Config ready`;
31429
+ return parsed;
31391
31430
  }
31392
31431
  catch (e) {
31393
- throw new Error(`Unable to load config file from ${configPath}: ${e}`);
31432
+ throw new Error(`Unable to parse config: ${e}`);
31394
31433
  }
31395
31434
  }
31435
+ function deepMerge(target, source) {
31436
+ if (!isJsonObject(source)) {
31437
+ throw new Error(`Expected object, got ${source}`);
31438
+ }
31439
+ for (const key in source) {
31440
+ if (isJsonObject(source[key])) {
31441
+ if (!isJsonObject(target[key])) {
31442
+ target[key] = {};
31443
+ }
31444
+ deepMerge(target[key], source[key]);
31445
+ }
31446
+ else {
31447
+ target[key] = source[key];
31448
+ }
31449
+ }
31450
+ }
31451
+ /**
31452
+ * Caution: updates input directly.
31453
+ * Processes a pseudo-jq query. Syntax:
31454
+ * .path.to.value = { ... } - updates value with the specified object by replacement
31455
+ * .path.to.value += { ... } - updates value with the specified object by merging
31456
+ * .path.to.value = file.json - updates value with the contents of file.json
31457
+ * .path.to.value += file.json - merges the contents of file.json onto value
31458
+ */
31459
+ function processQuery(input, query, withRelPath) {
31460
+ const queryParts = query.split("=");
31461
+ if (queryParts.length === 2) {
31462
+ let [path, value] = queryParts.map((part) => part.trim());
31463
+ let merge = false;
31464
+ // detect += syntax
31465
+ if (path.endsWith("+")) {
31466
+ merge = true;
31467
+ path = path.slice(0, -1);
31468
+ }
31469
+ let parsedValue;
31470
+ if (value.endsWith(".json")) {
31471
+ try {
31472
+ const configFile = fs.readFileSync(withRelPath(value), "utf8");
31473
+ const parsed = JSON.parse(configFile);
31474
+ parsedValue = parsed;
31475
+ }
31476
+ catch (e) {
31477
+ throw new Error(`Unable to load config from ${value}: ${e}`);
31478
+ }
31479
+ }
31480
+ else {
31481
+ try {
31482
+ parsedValue = JSON.parse(value);
31483
+ }
31484
+ catch (e) {
31485
+ throw new Error(`Unrecognized syntax '${value}': ${e}`);
31486
+ }
31487
+ }
31488
+ let pathParts = path.split(".");
31489
+ // allow leading dot in path
31490
+ if (pathParts[0] === "") {
31491
+ pathParts = pathParts.slice(1);
31492
+ }
31493
+ let target = input;
31494
+ for (let i = 0; i < pathParts.length; i++) {
31495
+ const part = pathParts[i];
31496
+ if (!isJsonObject(target[part])) {
31497
+ target[part] = {};
31498
+ }
31499
+ if (i === pathParts.length - 1) {
31500
+ if (merge) {
31501
+ deepMerge(target[part], parsedValue);
31502
+ }
31503
+ else {
31504
+ target[part] = parsedValue;
31505
+ }
31506
+ return;
31507
+ }
31508
+ target = target[part];
31509
+ }
31510
+ }
31511
+ throw new Error("Unrecognized syntax.");
31512
+ }
31513
+ function isJsonObject(value) {
31514
+ return typeof value === "object" && value !== null && !Array.isArray(value);
31515
+ }
31396
31516
 
31397
31517
  ;// CONCATENATED MODULE: ./packages/jam/config-node/index.ts
31398
31518