@typeberry/jam 0.2.0-5746fdc → 0.2.0-79dc2d4

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;
@@ -31321,7 +31324,7 @@ const DEV_CONFIG = "dev";
31321
31324
  const DEFAULT_CONFIG = "default";
31322
31325
  const NODE_DEFAULTS = {
31323
31326
  name: isBrowser() ? "browser" : external_node_os_default().hostname(),
31324
- config: DEFAULT_CONFIG,
31327
+ config: [DEFAULT_CONFIG],
31325
31328
  pvm: PvmBackend.BuiltIn,
31326
31329
  };
31327
31330
  /** Chain spec chooser. */
@@ -31374,25 +31377,137 @@ class NodeConfiguration {
31374
31377
  this.authorship = authorship;
31375
31378
  }
31376
31379
  }
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);
31380
+ function loadConfig(config, withRelPath) {
31381
+ logger.log `🔧 Loading config`;
31382
+ let mergedJson = {};
31383
+ for (const entry of config) {
31384
+ logger.log `🔧 Applying '${entry}'`;
31385
+ if (entry === DEV_CONFIG) {
31386
+ mergedJson = structuredClone(configs.dev); // clone to avoid mutating the original config. not doing a merge since dev and default should theoretically replace all properties.
31387
+ continue;
31388
+ }
31389
+ if (entry === DEFAULT_CONFIG) {
31390
+ mergedJson = structuredClone(configs.default);
31391
+ continue;
31392
+ }
31393
+ // try to parse as JSON
31394
+ try {
31395
+ const parsed = JSON.parse(entry);
31396
+ deepMerge(mergedJson, parsed);
31397
+ continue;
31398
+ }
31399
+ catch { }
31400
+ // if not, try to load as file
31401
+ if (entry.indexOf("=") === -1 && entry.endsWith(".json")) {
31402
+ try {
31403
+ const configFile = fs.readFileSync(withRelPath(entry), "utf8");
31404
+ const parsed = JSON.parse(configFile);
31405
+ deepMerge(mergedJson, parsed);
31406
+ }
31407
+ catch (e) {
31408
+ throw new Error(`Unable to load config from ${entry}: ${e}`);
31409
+ }
31410
+ }
31411
+ else {
31412
+ // finally try to process as a pseudo-jq query
31413
+ try {
31414
+ processQuery(mergedJson, entry, withRelPath);
31415
+ }
31416
+ catch (e) {
31417
+ throw new Error(`Error while processing '${entry}': ${e}`);
31418
+ }
31419
+ }
31385
31420
  }
31386
31421
  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);
31422
+ const parsed = parseFromJson(mergedJson, NodeConfiguration.fromJson);
31423
+ logger.log `🔧 Config ready`;
31424
+ return parsed;
31391
31425
  }
31392
31426
  catch (e) {
31393
- throw new Error(`Unable to load config file from ${configPath}: ${e}`);
31427
+ throw new Error(`Unable to parse config: ${e}`);
31394
31428
  }
31395
31429
  }
31430
+ function deepMerge(target, source) {
31431
+ if (!isJsonObject(source)) {
31432
+ throw new Error(`Expected object, got ${source}`);
31433
+ }
31434
+ for (const key in source) {
31435
+ if (isJsonObject(source[key])) {
31436
+ if (!isJsonObject(target[key])) {
31437
+ target[key] = {};
31438
+ }
31439
+ deepMerge(target[key], source[key]);
31440
+ }
31441
+ else {
31442
+ target[key] = source[key];
31443
+ }
31444
+ }
31445
+ }
31446
+ /**
31447
+ * Caution: updates input directly.
31448
+ * Processes a pseudo-jq query. Syntax:
31449
+ * .path.to.value = { ... } - updates value with the specified object by replacement
31450
+ * .path.to.value += { ... } - updates value with the specified object by merging
31451
+ * .path.to.value = file.json - updates value with the contents of file.json
31452
+ * .path.to.value += file.json - merges the contents of file.json onto value
31453
+ */
31454
+ function processQuery(input, query, withRelPath) {
31455
+ const queryParts = query.split("=");
31456
+ if (queryParts.length === 2) {
31457
+ let [path, value] = queryParts.map((part) => part.trim());
31458
+ let merge = false;
31459
+ // detect += syntax
31460
+ if (path.endsWith("+")) {
31461
+ merge = true;
31462
+ path = path.slice(0, -1);
31463
+ }
31464
+ let parsedValue;
31465
+ if (value.endsWith(".json")) {
31466
+ try {
31467
+ const configFile = fs.readFileSync(withRelPath(value), "utf8");
31468
+ const parsed = JSON.parse(configFile);
31469
+ parsedValue = parsed;
31470
+ }
31471
+ catch (e) {
31472
+ throw new Error(`Unable to load config from ${value}: ${e}`);
31473
+ }
31474
+ }
31475
+ else {
31476
+ try {
31477
+ parsedValue = JSON.parse(value);
31478
+ }
31479
+ catch (e) {
31480
+ throw new Error(`Unrecognized syntax '${value}': ${e}`);
31481
+ }
31482
+ }
31483
+ let pathParts = path.split(".");
31484
+ // allow leading dot in path
31485
+ if (pathParts[0] === "") {
31486
+ pathParts = pathParts.slice(1);
31487
+ }
31488
+ let target = input;
31489
+ for (let i = 0; i < pathParts.length; i++) {
31490
+ const part = pathParts[i];
31491
+ if (!isJsonObject(target[part])) {
31492
+ target[part] = {};
31493
+ }
31494
+ if (i === pathParts.length - 1) {
31495
+ if (merge) {
31496
+ deepMerge(target[part], parsedValue);
31497
+ }
31498
+ else {
31499
+ target[part] = parsedValue;
31500
+ }
31501
+ return;
31502
+ }
31503
+ target = target[part];
31504
+ }
31505
+ }
31506
+ throw new Error("Unrecognized syntax.");
31507
+ }
31508
+ function isJsonObject(value) {
31509
+ return typeof value === "object" && value !== null && !Array.isArray(value);
31510
+ }
31396
31511
 
31397
31512
  ;// CONCATENATED MODULE: ./packages/jam/config-node/index.ts
31398
31513