@sdeverywhere/check-core 0.1.1 → 0.1.2

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/dist/index.cjs CHANGED
@@ -1,9 +1,26 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
8
  var __getProtoOf = Object.getPrototypeOf;
6
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7
24
  var __export = (target, all) => {
8
25
  for (var name in all)
9
26
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,10 +34,34 @@ var __copyProps = (to, from, except, desc) => {
17
34
  return to;
18
35
  };
19
36
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
+ // If the importer is in node compatibility mode or this is not an ESM
38
+ // file that has been converted to a CommonJS file using a Babel-
39
+ // compatible transform (i.e. "__esModule" has not been set), then set
40
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
41
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
42
  mod
22
43
  ));
23
44
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
45
+ var __async = (__this, __arguments, generator) => {
46
+ return new Promise((resolve, reject) => {
47
+ var fulfilled = (value) => {
48
+ try {
49
+ step(generator.next(value));
50
+ } catch (e) {
51
+ reject(e);
52
+ }
53
+ };
54
+ var rejected = (value) => {
55
+ try {
56
+ step(generator.throw(value));
57
+ } catch (e) {
58
+ reject(e);
59
+ }
60
+ };
61
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
62
+ step((generator = generator.apply(__this, __arguments)).next());
63
+ });
64
+ };
24
65
 
25
66
  // src/index.ts
26
67
  var src_exports = {};
@@ -48,9 +89,13 @@ module.exports = __toCommonJS(src_exports);
48
89
  var TaskQueue = class {
49
90
  constructor(processor) {
50
91
  this.processor = processor;
92
+ /** The queue of task keys, most recent at front. */
51
93
  this.taskKeyQueue = [];
94
+ /** The map of tasks. */
52
95
  this.taskMap = /* @__PURE__ */ new Map();
96
+ /** Whether tasks are being processed. */
53
97
  this.processing = false;
98
+ /** Whether `shutdown` has been called. */
54
99
  this.stopped = false;
55
100
  }
56
101
  addTask(key, input, onComplete) {
@@ -88,39 +133,41 @@ var TaskQueue = class {
88
133
  });
89
134
  }
90
135
  }
91
- async processNextTask() {
92
- var _a, _b;
93
- const taskKey = this.taskKeyQueue.shift();
94
- if (!taskKey) {
95
- return;
96
- }
97
- const task = this.taskMap.get(taskKey);
98
- if (task) {
99
- this.taskMap.delete(taskKey);
100
- } else {
101
- return;
102
- }
103
- let output;
104
- try {
105
- output = await this.processor.process(task.input);
106
- } catch (e) {
107
- if (!this.stopped) {
108
- this.shutdown();
109
- (_a = this.onIdle) == null ? void 0 : _a.call(this, e);
136
+ processNextTask() {
137
+ return __async(this, null, function* () {
138
+ var _a, _b;
139
+ const taskKey = this.taskKeyQueue.shift();
140
+ if (!taskKey) {
141
+ return;
110
142
  }
111
- return;
112
- }
113
- task.onComplete(output);
114
- if (this.taskKeyQueue.length > 0) {
115
- setTimeout(() => {
116
- this.processNextTask();
117
- });
118
- } else {
119
- this.processing = false;
120
- if (!this.stopped) {
121
- (_b = this.onIdle) == null ? void 0 : _b.call(this);
143
+ const task = this.taskMap.get(taskKey);
144
+ if (task) {
145
+ this.taskMap.delete(taskKey);
146
+ } else {
147
+ return;
122
148
  }
123
- }
149
+ let output;
150
+ try {
151
+ output = yield this.processor.process(task.input);
152
+ } catch (e) {
153
+ if (!this.stopped) {
154
+ this.shutdown();
155
+ (_a = this.onIdle) == null ? void 0 : _a.call(this, e);
156
+ }
157
+ return;
158
+ }
159
+ task.onComplete(output);
160
+ if (this.taskKeyQueue.length > 0) {
161
+ setTimeout(() => {
162
+ this.processNextTask();
163
+ });
164
+ } else {
165
+ this.processing = false;
166
+ if (!this.stopped) {
167
+ (_b = this.onIdle) == null ? void 0 : _b.call(this);
168
+ }
169
+ }
170
+ });
124
171
  }
125
172
  };
126
173
 
@@ -129,13 +176,13 @@ var CheckDataCoordinator = class {
129
176
  constructor(bundleModel) {
130
177
  this.bundleModel = bundleModel;
131
178
  this.taskQueue = new TaskQueue({
132
- process: async (request) => {
133
- const result = await this.bundleModel.getDatasetsForScenario(request.scenarioSpec, [request.datasetKey]);
179
+ process: (request) => __async(this, null, function* () {
180
+ const result = yield this.bundleModel.getDatasetsForScenario(request.scenarioSpec, [request.datasetKey]);
134
181
  const dataset = result.datasetMap.get(request.datasetKey);
135
182
  return {
136
183
  dataset
137
184
  };
138
- }
185
+ })
139
186
  });
140
187
  }
141
188
  requestDataset(requestKey, scenarioSpec, datasetKey, onResponse) {
@@ -1688,6 +1735,24 @@ var CheckPlanner = class {
1688
1735
  dataRefs: this.dataRefs
1689
1736
  };
1690
1737
  }
1738
+ /**
1739
+ * Record any references to additional datasets contained in the given predicate.
1740
+ * For example, if the predicate is:
1741
+ * ```
1742
+ * gt:
1743
+ * dataset:
1744
+ * name: 'XYZ'
1745
+ * scenario:
1746
+ * inputs: all
1747
+ * at: default
1748
+ * ```
1749
+ * this will add a reference to the scenario/dataset pair so that the data can
1750
+ * be fetched in a later stage.
1751
+ *
1752
+ * @param predicateSpec The predicate spec.
1753
+ * @param checkScenario The scenario in which the dataset is being checked.
1754
+ * @param checkDataset The dataset that is being checked.
1755
+ */
1691
1756
  addDataRefs(predicateSpec, checkScenario, checkDataset) {
1692
1757
  let dataRefs;
1693
1758
  const addDataRef = (op) => {
@@ -1816,7 +1881,7 @@ var ComparisonDataCoordinator = class {
1816
1881
  this.bundleModelL = bundleModelL;
1817
1882
  this.bundleModelR = bundleModelR;
1818
1883
  this.taskQueue = new TaskQueue({
1819
- process: async (request) => {
1884
+ process: (request) => __async(this, null, function* () {
1820
1885
  switch (request.kind) {
1821
1886
  case "dataset":
1822
1887
  return this.processDatasetRequest(request);
@@ -1825,44 +1890,52 @@ var ComparisonDataCoordinator = class {
1825
1890
  default:
1826
1891
  (0, import_assert_never7.assertNever)(request);
1827
1892
  }
1828
- }
1893
+ })
1829
1894
  });
1830
1895
  }
1831
- async processDatasetRequest(request) {
1832
- async function fetchDatasets(bundleModel, scenarioSpec) {
1833
- if (scenarioSpec) {
1834
- return bundleModel.getDatasetsForScenario(scenarioSpec, request.datasetKeys);
1835
- } else {
1836
- return void 0;
1896
+ processDatasetRequest(request) {
1897
+ return __async(this, null, function* () {
1898
+ function fetchDatasets(bundleModel, scenarioSpec) {
1899
+ return __async(this, null, function* () {
1900
+ if (scenarioSpec) {
1901
+ return bundleModel.getDatasetsForScenario(scenarioSpec, request.datasetKeys);
1902
+ } else {
1903
+ return void 0;
1904
+ }
1905
+ });
1837
1906
  }
1838
- }
1839
- const [resultL, resultR] = await Promise.all([
1840
- fetchDatasets(this.bundleModelL, request.scenarioSpecL),
1841
- fetchDatasets(this.bundleModelR, request.scenarioSpecR)
1842
- ]);
1843
- return {
1844
- kind: "dataset",
1845
- datasetMapL: resultL == null ? void 0 : resultL.datasetMap,
1846
- datasetMapR: resultR == null ? void 0 : resultR.datasetMap
1847
- };
1907
+ const [resultL, resultR] = yield Promise.all([
1908
+ fetchDatasets(this.bundleModelL, request.scenarioSpecL),
1909
+ fetchDatasets(this.bundleModelR, request.scenarioSpecR)
1910
+ ]);
1911
+ return {
1912
+ kind: "dataset",
1913
+ datasetMapL: resultL == null ? void 0 : resultL.datasetMap,
1914
+ datasetMapR: resultR == null ? void 0 : resultR.datasetMap
1915
+ };
1916
+ });
1848
1917
  }
1849
- async processGraphDataRequest(request) {
1850
- async function fetchGraphData(bundleModel, scenarioSpec) {
1851
- if (scenarioSpec) {
1852
- return bundleModel.getGraphDataForScenario(scenarioSpec, request.graphId);
1853
- } else {
1854
- return void 0;
1918
+ processGraphDataRequest(request) {
1919
+ return __async(this, null, function* () {
1920
+ function fetchGraphData(bundleModel, scenarioSpec) {
1921
+ return __async(this, null, function* () {
1922
+ if (scenarioSpec) {
1923
+ return bundleModel.getGraphDataForScenario(scenarioSpec, request.graphId);
1924
+ } else {
1925
+ return void 0;
1926
+ }
1927
+ });
1855
1928
  }
1856
- }
1857
- const [graphDataL, graphDataR] = await Promise.all([
1858
- fetchGraphData(this.bundleModelL, request.scenarioSpecL),
1859
- fetchGraphData(this.bundleModelR, request.scenarioSpecR)
1860
- ]);
1861
- return {
1862
- kind: "graph-data",
1863
- graphDataL,
1864
- graphDataR
1865
- };
1929
+ const [graphDataL, graphDataR] = yield Promise.all([
1930
+ fetchGraphData(this.bundleModelL, request.scenarioSpecL),
1931
+ fetchGraphData(this.bundleModelR, request.scenarioSpecR)
1932
+ ]);
1933
+ return {
1934
+ kind: "graph-data",
1935
+ graphDataL,
1936
+ graphDataR
1937
+ };
1938
+ });
1866
1939
  }
1867
1940
  requestDatasetMaps(requestKey, scenarioSpecL, scenarioSpecR, datasetKeys, onResponse) {
1868
1941
  const request = {
@@ -2298,7 +2371,9 @@ function compareScores(a, b) {
2298
2371
  // src/bundle/model-inputs.ts
2299
2372
  var ModelInputs = class {
2300
2373
  constructor(modelSpec) {
2374
+ /** All inputs keyed by lookup name (lowercase variable name or alias). */
2301
2375
  this.inputsByLookupName = /* @__PURE__ */ new Map();
2376
+ /** All input ID aliases. */
2302
2377
  this.inputIdAliases = /* @__PURE__ */ new Set();
2303
2378
  for (const inputVar of modelSpec.inputVars.values()) {
2304
2379
  const varNameKey = inputVar.varName.toLowerCase();
@@ -2328,9 +2403,17 @@ var ModelInputs = class {
2328
2403
  }
2329
2404
  }
2330
2405
  }
2406
+ /**
2407
+ * Return the set of `id XYZ` aliases for all input variables.
2408
+ */
2331
2409
  getAllInputIdAliases() {
2332
2410
  return [...this.inputIdAliases];
2333
2411
  }
2412
+ /**
2413
+ * Return the `InputVar` that matches the requested name (either by variable name or alias).
2414
+ *
2415
+ * @param name The variable name or alias to match.
2416
+ */
2334
2417
  getInputVarForName(name) {
2335
2418
  return this.inputsByLookupName.get(name.toLowerCase());
2336
2419
  }
@@ -2352,6 +2435,9 @@ var comparison_schema_default = {
2352
2435
  $ref: "#/$defs/top_level_array_item"
2353
2436
  },
2354
2437
  $defs: {
2438
+ //
2439
+ // TOP-LEVEL
2440
+ //
2355
2441
  top_level_array_item: {
2356
2442
  oneOf: [
2357
2443
  { $ref: "#/$defs/scenario_array_item" },
@@ -2359,6 +2445,9 @@ var comparison_schema_default = {
2359
2445
  { $ref: "#/$defs/view_group_array_item" }
2360
2446
  ]
2361
2447
  },
2448
+ //
2449
+ // SCENARIOS
2450
+ //
2362
2451
  scenario_array_item: {
2363
2452
  type: "object",
2364
2453
  additionalProperties: false,
@@ -2375,7 +2464,9 @@ var comparison_schema_default = {
2375
2464
  { $ref: "#/$defs/scenario_with_input_at_value" },
2376
2465
  { $ref: "#/$defs/scenario_with_multiple_input_settings" },
2377
2466
  { $ref: "#/$defs/scenario_with_inputs_in_preset_at_position" },
2467
+ // { $ref: '#/$defs/scenario_with_inputs_in_group_at_position' }
2378
2468
  { $ref: "#/$defs/scenario_preset" }
2469
+ // { $ref: '#/$defs/scenario_expand_for_each_input_in_group' }
2379
2470
  ]
2380
2471
  },
2381
2472
  scenario_position: {
@@ -2515,6 +2606,9 @@ var comparison_schema_default = {
2515
2606
  },
2516
2607
  required: ["preset"]
2517
2608
  },
2609
+ //
2610
+ // SCENARIO GROUPS
2611
+ //
2518
2612
  scenario_group_array_item: {
2519
2613
  type: "object",
2520
2614
  additionalProperties: false,
@@ -2590,6 +2684,9 @@ var comparison_schema_default = {
2590
2684
  },
2591
2685
  required: ["scenario_group_ref"]
2592
2686
  },
2687
+ //
2688
+ // VIEWS
2689
+ //
2593
2690
  view: {
2594
2691
  type: "object",
2595
2692
  additionalProperties: false,
@@ -2623,6 +2720,9 @@ var comparison_schema_default = {
2623
2720
  },
2624
2721
  minItems: 1
2625
2722
  },
2723
+ //
2724
+ // VIEW GROUPS
2725
+ //
2626
2726
  view_group_array_item: {
2627
2727
  type: "object",
2628
2728
  additionalProperties: false,
@@ -2906,15 +3006,18 @@ function scenarioSpecFromInputs(inputs, side) {
2906
3006
  if (state.inputVar === void 0) {
2907
3007
  return void 0;
2908
3008
  }
2909
- const varId = state.inputVar.varId;
2910
- if (state.position) {
2911
- settings.push(positionSetting(varId, state.position));
2912
- } else {
2913
- settings.push(valueSetting(varId, state.value));
2914
- }
3009
+ settings.push(inputSettingFromResolvedInputState(state));
2915
3010
  }
2916
3011
  return inputSettingsSpec(settings);
2917
3012
  }
3013
+ function inputSettingFromResolvedInputState(state) {
3014
+ const varId = state.inputVar.varId;
3015
+ if (state.position) {
3016
+ return positionSetting(varId, state.position);
3017
+ } else {
3018
+ return valueSetting(varId, state.value);
3019
+ }
3020
+ }
2918
3021
 
2919
3022
  // src/comparison/config/resolve/comparison-resolver.ts
2920
3023
  function resolveComparisonSpecs(modelInputsL, modelInputsR, specs) {
@@ -2950,7 +3053,7 @@ function resolveComparisonSpecs(modelInputsL, modelInputsR, specs) {
2950
3053
  if (scenarioItem.kind === "scenario-ref") {
2951
3054
  const referencedScenario = resolvedScenarios.getScenarioForId(scenarioItem.scenarioId);
2952
3055
  if (referencedScenario) {
2953
- const resolvedScenario = { ...referencedScenario };
3056
+ const resolvedScenario = __spreadValues({}, referencedScenario);
2954
3057
  if (scenarioItem.title) {
2955
3058
  resolvedScenario.title = scenarioItem.title;
2956
3059
  }
@@ -2988,7 +3091,9 @@ function resolveComparisonSpecs(modelInputsL, modelInputsR, specs) {
2988
3091
  }
2989
3092
  var ResolvedScenarios = class {
2990
3093
  constructor() {
3094
+ /** The array of all resolved scenarios. */
2991
3095
  this.resolvedScenarios = [];
3096
+ /** The set of resolved scenarios that include an ID, keyed by ID. */
2992
3097
  this.resolvedScenariosById = /* @__PURE__ */ new Map();
2993
3098
  }
2994
3099
  add(scenarios) {
@@ -3038,6 +3143,20 @@ function resolveScenariosFromSpec(modelInputsL, modelInputsR, scenarioSpec, genK
3038
3143
  )
3039
3144
  ];
3040
3145
  }
3146
+ case "scenario-with-distinct-inputs": {
3147
+ return [
3148
+ resolveScenarioForDistinctInputSpecs(
3149
+ modelInputsL,
3150
+ modelInputsR,
3151
+ genKey(),
3152
+ scenarioSpec.id,
3153
+ scenarioSpec.title,
3154
+ scenarioSpec.subtitle,
3155
+ scenarioSpec.inputsL,
3156
+ scenarioSpec.inputsR
3157
+ )
3158
+ ];
3159
+ }
3041
3160
  default:
3042
3161
  (0, import_assert_never11.assertNever)(scenarioSpec);
3043
3162
  }
@@ -3114,6 +3233,59 @@ function resolveScenarioForInputSpecs(modelInputsL, modelInputsR, key, id, title
3114
3233
  specR
3115
3234
  };
3116
3235
  }
3236
+ function resolveScenarioForDistinctInputSpecs(modelInputsL, modelInputsR, key, id, title, subtitle, inputSpecsL, inputSpecsR) {
3237
+ const inputsWithErrors = [];
3238
+ const settingsL = [];
3239
+ const settingsR = [];
3240
+ function resolveInputSpec(side, modelInputs, inputSpec) {
3241
+ let inputState;
3242
+ switch (inputSpec.kind) {
3243
+ case "input-at-position":
3244
+ inputState = resolveInputForNameInModel(modelInputs, inputSpec.inputName, inputSpec.position);
3245
+ break;
3246
+ case "input-at-value":
3247
+ inputState = resolveInputForNameInModel(modelInputs, inputSpec.inputName, inputSpec.value);
3248
+ break;
3249
+ default:
3250
+ (0, import_assert_never11.assertNever)(inputSpec);
3251
+ }
3252
+ if (inputState.error !== void 0) {
3253
+ inputsWithErrors.push({
3254
+ requestedName: inputSpec.inputName,
3255
+ stateL: side === "left" ? inputState : {},
3256
+ stateR: side === "right" ? inputState : {}
3257
+ });
3258
+ } else {
3259
+ const inputSetting = inputSettingFromResolvedInputState(inputState);
3260
+ if (side === "left") {
3261
+ settingsL.push(inputSetting);
3262
+ } else {
3263
+ settingsR.push(inputSetting);
3264
+ }
3265
+ }
3266
+ }
3267
+ inputSpecsL.forEach((inputSpec) => resolveInputSpec("left", modelInputsL, inputSpec));
3268
+ inputSpecsR.forEach((inputSpec) => resolveInputSpec("right", modelInputsR, inputSpec));
3269
+ let specL;
3270
+ let specR;
3271
+ if (inputsWithErrors.length === 0) {
3272
+ specL = inputSettingsSpec(settingsL);
3273
+ specR = inputSettingsSpec(settingsR);
3274
+ }
3275
+ return {
3276
+ kind: "scenario",
3277
+ key,
3278
+ id,
3279
+ title,
3280
+ subtitle,
3281
+ settings: {
3282
+ kind: "input-settings",
3283
+ inputs: inputsWithErrors
3284
+ },
3285
+ specL,
3286
+ specR
3287
+ };
3288
+ }
3117
3289
  function resolveInputForName(modelInputsL, modelInputsR, inputName, at) {
3118
3290
  return {
3119
3291
  requestedName: inputName,
@@ -3189,7 +3361,9 @@ function inputValueAtPosition2(inputVar, position) {
3189
3361
  }
3190
3362
  var ResolvedScenarioGroups = class {
3191
3363
  constructor() {
3364
+ /** The array of all resolved scenario groups. */
3192
3365
  this.resolvedGroups = [];
3366
+ /** The set of resolved scenario groups that include an ID, keyed by ID. */
3193
3367
  this.resolvedGroupsById = /* @__PURE__ */ new Map();
3194
3368
  }
3195
3369
  add(group) {
@@ -3361,6 +3535,11 @@ function getComparisonDatasets(modelSpecL, modelSpecR, datasetOptions) {
3361
3535
  return new ComparisonDatasetsImpl(modelSpecL, modelSpecR, datasetOptions);
3362
3536
  }
3363
3537
  var ComparisonDatasetsImpl = class {
3538
+ /**
3539
+ * @param modelSpecL The model spec for the "left" bundle being compared.
3540
+ * @param modelSpecR The model spec for the "right" bundle being compared.
3541
+ * @param datasetOptions The custom configuration for the datasets to be compared.
3542
+ */
3364
3543
  constructor(modelSpecL, modelSpecR, datasetOptions) {
3365
3544
  this.datasetOptions = datasetOptions;
3366
3545
  const renamedDatasetKeys = datasetOptions == null ? void 0 : datasetOptions.renamedDatasetKeys;
@@ -3399,12 +3578,15 @@ var ComparisonDatasetsImpl = class {
3399
3578
  });
3400
3579
  }
3401
3580
  }
3581
+ // from ComparisonDatasets interface
3402
3582
  getAllDatasets() {
3403
3583
  return this.allDatasets.values();
3404
3584
  }
3585
+ // from ComparisonDatasets interface
3405
3586
  getDataset(datasetKey) {
3406
3587
  return this.allDatasets.get(datasetKey);
3407
3588
  }
3589
+ // from ComparisonDatasets interface
3408
3590
  getDatasetKeysForScenario(scenario) {
3409
3591
  var _a;
3410
3592
  if (((_a = this.datasetOptions) == null ? void 0 : _a.datasetKeysForScenario) !== void 0) {
@@ -3430,9 +3612,17 @@ var ComparisonScenariosImpl = class {
3430
3612
  this.scenarioDefs.set(scenario.key, scenario);
3431
3613
  }
3432
3614
  }
3615
+ /**
3616
+ * Return all `ComparisonScenario` instances that are available for comparisons.
3617
+ */
3433
3618
  getAllScenarios() {
3434
3619
  return this.scenarioDefs.values();
3435
3620
  }
3621
+ /**
3622
+ * Return the scenario definition for the given key.
3623
+ *
3624
+ * @param key The key for the scenario.
3625
+ */
3436
3626
  getScenario(key) {
3437
3627
  return this.scenarioDefs.get(key);
3438
3628
  }
@@ -3459,11 +3649,11 @@ var PromiseQueue = class {
3459
3649
  }
3460
3650
  add(f) {
3461
3651
  return new Promise((resolve, reject) => {
3462
- const run = async () => {
3652
+ const run = () => __async(this, null, function* () {
3463
3653
  this.runningCount++;
3464
3654
  const promise = f();
3465
3655
  try {
3466
- const result = await promise;
3656
+ const result = yield promise;
3467
3657
  resolve(result);
3468
3658
  } catch (e) {
3469
3659
  reject(e);
@@ -3471,7 +3661,7 @@ var PromiseQueue = class {
3471
3661
  this.runningCount--;
3472
3662
  this.runNext();
3473
3663
  }
3474
- };
3664
+ });
3475
3665
  if (this.runningCount < 1) {
3476
3666
  run();
3477
3667
  } else {
@@ -3490,81 +3680,84 @@ var PromiseQueue = class {
3490
3680
  };
3491
3681
 
3492
3682
  // src/config/config.ts
3493
- async function createConfig(options) {
3494
- var _a;
3495
- const origCurrentBundle = await loadSynchronized(options.current);
3496
- let currentBundle;
3497
- let comparisonConfig;
3498
- if (options.comparison === void 0) {
3499
- currentBundle = origCurrentBundle;
3500
- } else {
3501
- const baselineBundle = await loadSynchronized(options.comparison.baseline);
3502
- const renamedDatasetKeys = (_a = options.comparison.datasets) == null ? void 0 : _a.renamedDatasetKeys;
3503
- const invertedRenamedKeys = /* @__PURE__ */ new Map();
3504
- renamedDatasetKeys == null ? void 0 : renamedDatasetKeys.forEach((newKey, oldKey) => {
3505
- invertedRenamedKeys.set(newKey, oldKey);
3506
- });
3507
- const rightKeyForLeftKey = (leftKey) => {
3508
- return (renamedDatasetKeys == null ? void 0 : renamedDatasetKeys.get(leftKey)) || leftKey;
3509
- };
3510
- const leftKeyForRightKey = (rightKey) => {
3511
- return invertedRenamedKeys.get(rightKey) || rightKey;
3512
- };
3513
- const origBundleModelR = origCurrentBundle.model;
3514
- const adjBundleModelR = {
3515
- modelSpec: origBundleModelR.modelSpec,
3516
- getDatasetsForScenario: async (scenarioSpec, datasetKeys) => {
3517
- const rightKeys = datasetKeys.map(rightKeyForLeftKey);
3518
- const result = await origBundleModelR.getDatasetsForScenario(scenarioSpec, rightKeys);
3519
- const mapWithRightKeys = result.datasetMap;
3520
- const mapWithLeftKeys = /* @__PURE__ */ new Map();
3521
- for (const [rightKey, dataset] of mapWithRightKeys.entries()) {
3522
- const leftKey = leftKeyForRightKey(rightKey);
3523
- mapWithLeftKeys.set(leftKey, dataset);
3524
- }
3525
- return {
3526
- datasetMap: mapWithLeftKeys,
3527
- modelRunTime: result.modelRunTime
3528
- };
3529
- },
3530
- getGraphDataForScenario: origBundleModelR.getGraphDataForScenario.bind(origBundleModelR),
3531
- getGraphLinksForScenario: origBundleModelR.getGraphLinksForScenario.bind(origBundleModelR)
3532
- };
3533
- currentBundle = {
3534
- ...origCurrentBundle,
3535
- model: adjBundleModelR
3683
+ function createConfig(options) {
3684
+ return __async(this, null, function* () {
3685
+ var _a;
3686
+ const origCurrentBundle = yield loadSynchronized(options.current);
3687
+ let currentBundle;
3688
+ let comparisonConfig;
3689
+ if (options.comparison === void 0) {
3690
+ currentBundle = origCurrentBundle;
3691
+ } else {
3692
+ const baselineBundle = yield loadSynchronized(options.comparison.baseline);
3693
+ const renamedDatasetKeys = (_a = options.comparison.datasets) == null ? void 0 : _a.renamedDatasetKeys;
3694
+ const invertedRenamedKeys = /* @__PURE__ */ new Map();
3695
+ renamedDatasetKeys == null ? void 0 : renamedDatasetKeys.forEach((newKey, oldKey) => {
3696
+ invertedRenamedKeys.set(newKey, oldKey);
3697
+ });
3698
+ const rightKeyForLeftKey = (leftKey) => {
3699
+ return (renamedDatasetKeys == null ? void 0 : renamedDatasetKeys.get(leftKey)) || leftKey;
3700
+ };
3701
+ const leftKeyForRightKey = (rightKey) => {
3702
+ return invertedRenamedKeys.get(rightKey) || rightKey;
3703
+ };
3704
+ const origBundleModelR = origCurrentBundle.model;
3705
+ const adjBundleModelR = {
3706
+ modelSpec: origBundleModelR.modelSpec,
3707
+ getDatasetsForScenario: (scenarioSpec, datasetKeys) => __async(this, null, function* () {
3708
+ const rightKeys = datasetKeys.map(rightKeyForLeftKey);
3709
+ const result = yield origBundleModelR.getDatasetsForScenario(scenarioSpec, rightKeys);
3710
+ const mapWithRightKeys = result.datasetMap;
3711
+ const mapWithLeftKeys = /* @__PURE__ */ new Map();
3712
+ for (const [rightKey, dataset] of mapWithRightKeys.entries()) {
3713
+ const leftKey = leftKeyForRightKey(rightKey);
3714
+ mapWithLeftKeys.set(leftKey, dataset);
3715
+ }
3716
+ return {
3717
+ datasetMap: mapWithLeftKeys,
3718
+ modelRunTime: result.modelRunTime
3719
+ };
3720
+ }),
3721
+ getGraphDataForScenario: origBundleModelR.getGraphDataForScenario.bind(origBundleModelR),
3722
+ getGraphLinksForScenario: origBundleModelR.getGraphLinksForScenario.bind(origBundleModelR)
3723
+ };
3724
+ currentBundle = __spreadProps(__spreadValues({}, origCurrentBundle), {
3725
+ model: adjBundleModelR
3726
+ });
3727
+ const modelSpecL = baselineBundle.model.modelSpec;
3728
+ const modelSpecR = currentBundle.model.modelSpec;
3729
+ const modelInputsL = new ModelInputs(modelSpecL);
3730
+ const modelInputsR = new ModelInputs(modelSpecR);
3731
+ const comparisonDefs = resolveComparisonSpecsFromSources(modelInputsL, modelInputsR, options.comparison.specs);
3732
+ comparisonConfig = {
3733
+ bundleL: baselineBundle,
3734
+ bundleR: currentBundle,
3735
+ thresholds: options.comparison.thresholds,
3736
+ scenarios: getComparisonScenarios(comparisonDefs.scenarios),
3737
+ datasets: getComparisonDatasets(modelSpecL, modelSpecR, options.comparison.datasets),
3738
+ viewGroups: comparisonDefs.viewGroups
3739
+ };
3740
+ }
3741
+ const checkConfig = {
3742
+ bundle: currentBundle,
3743
+ tests: options.check.tests
3536
3744
  };
3537
- const modelSpecL = baselineBundle.model.modelSpec;
3538
- const modelSpecR = currentBundle.model.modelSpec;
3539
- const modelInputsL = new ModelInputs(modelSpecL);
3540
- const modelInputsR = new ModelInputs(modelSpecR);
3541
- const comparisonDefs = resolveComparisonSpecsFromSources(modelInputsL, modelInputsR, options.comparison.specs);
3542
- comparisonConfig = {
3543
- bundleL: baselineBundle,
3544
- bundleR: currentBundle,
3545
- thresholds: options.comparison.thresholds,
3546
- scenarios: getComparisonScenarios(comparisonDefs.scenarios),
3547
- datasets: getComparisonDatasets(modelSpecL, modelSpecR, options.comparison.datasets),
3548
- viewGroups: comparisonDefs.viewGroups
3745
+ return {
3746
+ check: checkConfig,
3747
+ comparison: comparisonConfig
3549
3748
  };
3550
- }
3551
- const checkConfig = {
3552
- bundle: currentBundle,
3553
- tests: options.check.tests
3554
- };
3555
- return {
3556
- check: checkConfig,
3557
- comparison: comparisonConfig
3558
- };
3749
+ });
3559
3750
  }
3560
- async function loadSynchronized(sourceBundle) {
3561
- const sourceModel = await sourceBundle.bundle.initModel();
3562
- const synchronizedModel = synchronizedBundleModel(sourceModel);
3563
- return {
3564
- name: sourceBundle.name,
3565
- version: sourceBundle.bundle.version,
3566
- model: synchronizedModel
3567
- };
3751
+ function loadSynchronized(sourceBundle) {
3752
+ return __async(this, null, function* () {
3753
+ const sourceModel = yield sourceBundle.bundle.initModel();
3754
+ const synchronizedModel = synchronizedBundleModel(sourceModel);
3755
+ return {
3756
+ name: sourceBundle.name,
3757
+ version: sourceBundle.bundle.version,
3758
+ model: synchronizedModel
3759
+ };
3760
+ });
3568
3761
  }
3569
3762
 
3570
3763
  // src/perf/perf-runner.ts
@@ -3614,22 +3807,22 @@ var PerfRunner = class {
3614
3807
  this.mode = mode;
3615
3808
  const scenarioSpec = allInputsAtPositionSpec("at-default");
3616
3809
  this.taskQueue = new TaskQueue({
3617
- process: async (request) => {
3810
+ process: (request) => __async(this, null, function* () {
3618
3811
  switch (request.kind) {
3619
3812
  case "left": {
3620
- const result = await bundleModelL.getDatasetsForScenario(scenarioSpec, []);
3813
+ const result = yield bundleModelL.getDatasetsForScenario(scenarioSpec, []);
3621
3814
  return {
3622
3815
  runTimeL: result.modelRunTime
3623
3816
  };
3624
3817
  }
3625
3818
  case "right": {
3626
- const result = await bundleModelR.getDatasetsForScenario(scenarioSpec, []);
3819
+ const result = yield bundleModelR.getDatasetsForScenario(scenarioSpec, []);
3627
3820
  return {
3628
3821
  runTimeR: result.modelRunTime
3629
3822
  };
3630
3823
  }
3631
3824
  case "both": {
3632
- const [resultL, resultR] = await Promise.all([
3825
+ const [resultL, resultR] = yield Promise.all([
3633
3826
  bundleModelL.getDatasetsForScenario(scenarioSpec, []),
3634
3827
  bundleModelR.getDatasetsForScenario(scenarioSpec, [])
3635
3828
  ]);
@@ -3641,7 +3834,7 @@ var PerfRunner = class {
3641
3834
  default:
3642
3835
  (0, import_assert_never12.assertNever)(request.kind);
3643
3836
  }
3644
- }
3837
+ })
3645
3838
  });
3646
3839
  }
3647
3840
  start() {
@@ -3689,13 +3882,31 @@ var PerfRunner = class {
3689
3882
 
3690
3883
  // src/data/data-planner.ts
3691
3884
  var DataPlanner = class {
3885
+ /**
3886
+ * @param batchSize The maximum number of impl vars that can be fetched
3887
+ * with a single request; this is usually the same as the number of
3888
+ * normal model outputs.
3889
+ */
3692
3890
  constructor(batchSize) {
3693
3891
  this.batchSize = batchSize;
3892
+ /** Tasks that need to access both "left" and "right" models in parallel. */
3694
3893
  this.taskSetsLR = /* @__PURE__ */ new Map();
3894
+ /** Tasks that only need to access the "left" model. */
3695
3895
  this.taskSetsL = /* @__PURE__ */ new Map();
3896
+ /** Tasks that only need to access the "right" model. */
3696
3897
  this.taskSetsR = /* @__PURE__ */ new Map();
3697
3898
  this.complete = false;
3698
3899
  }
3900
+ /**
3901
+ * Add a request to the plan for the given scenario(s) and data task.
3902
+ *
3903
+ * @param scenarioSpecL The input scenario used to configure the "left" model, or undefined if no data
3904
+ * is needed from the left model.
3905
+ * @param scenarioSpecR The input scenario used to configure the "right" model, or undefined if no data
3906
+ * is needed from the right model.
3907
+ * @param datasetKey The key for the dataset to be fetched from each model for the given scenario.
3908
+ * @param dataAction The action to be performed with the fetched datasets.
3909
+ */
3699
3910
  addRequest(scenarioSpecL, scenarioSpecR, datasetKey, dataAction) {
3700
3911
  if (scenarioSpecL === void 0 && scenarioSpecR === void 0) {
3701
3912
  console.warn("WARNING: Both scenario specs are undefined for DataPlanner request, skipping");
@@ -3723,6 +3934,9 @@ var DataPlanner = class {
3723
3934
  dataAction
3724
3935
  });
3725
3936
  }
3937
+ /**
3938
+ * Build a plan that minimizes the number of data fetches needed.
3939
+ */
3726
3940
  buildPlan() {
3727
3941
  if (this.complete) {
3728
3942
  throw new Error("DataPlanner.buildPlan() can only be called once");
@@ -3773,6 +3987,12 @@ var DataTaskSet = class {
3773
3987
  this.modelTasks = /* @__PURE__ */ new Map();
3774
3988
  this.modelImplTasks = /* @__PURE__ */ new Map();
3775
3989
  }
3990
+ /**
3991
+ * Add a task that will be performed when the data is fetched for the scenario(s)
3992
+ * associated with this task set.
3993
+ *
3994
+ * @param dataTask A task that performs an action using the fetched dataset(s).
3995
+ */
3776
3996
  addTask(dataTask) {
3777
3997
  let taskMap;
3778
3998
  if (dataTask.datasetKey.startsWith("ModelImpl")) {
@@ -3787,6 +4007,11 @@ var DataTaskSet = class {
3787
4007
  }
3788
4008
  tasks.push(dataTask);
3789
4009
  }
4010
+ /**
4011
+ * Add all tasks from the given set into this set.
4012
+ *
4013
+ * @param otherTaskSet The other task set that will be merged into this one.
4014
+ */
3790
4015
  merge(otherTaskSet) {
3791
4016
  for (const tasks of otherTaskSet.modelTasks.values()) {
3792
4017
  for (const task of tasks) {
@@ -3799,6 +4024,12 @@ var DataTaskSet = class {
3799
4024
  }
3800
4025
  }
3801
4026
  }
4027
+ /**
4028
+ * Create one or more data requests that can be used to fetch data for the configured scenario(s).
4029
+ *
4030
+ * @param batchSize The maximum number of impl vars that can be fetched with a single request.
4031
+ * This is usually the same as the number of normal model outputs.
4032
+ */
3802
4033
  buildRequests(batchSize) {
3803
4034
  const dataRequests = [];
3804
4035
  if (this.modelTasks.size > 0) {
@@ -4034,42 +4265,46 @@ var SuiteRunner = class {
4034
4265
  });
4035
4266
  }
4036
4267
  }
4037
- async processRequest(request) {
4038
- var _a, _b;
4039
- const datasetKeySet = /* @__PURE__ */ new Set();
4040
- for (const dataTask of request.dataTasks) {
4041
- datasetKeySet.add(dataTask.datasetKey);
4042
- }
4043
- const datasetKeys = [...datasetKeySet];
4044
- async function getDatasets(bundleModel, scenarioSpec) {
4045
- if (bundleModel && scenarioSpec) {
4046
- return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys);
4047
- } else {
4048
- return void 0;
4268
+ processRequest(request) {
4269
+ return __async(this, null, function* () {
4270
+ var _a, _b;
4271
+ const datasetKeySet = /* @__PURE__ */ new Set();
4272
+ for (const dataTask of request.dataTasks) {
4273
+ datasetKeySet.add(dataTask.datasetKey);
4049
4274
  }
4050
- }
4051
- const bundleModelL = (_a = this.config.comparison) == null ? void 0 : _a.bundleL.model;
4052
- const bundleModelR = ((_b = this.config.comparison) == null ? void 0 : _b.bundleR.model) || this.config.check.bundle.model;
4053
- const [datasetsResultL, datasetsResultR] = await Promise.all([
4054
- getDatasets(bundleModelL, request.scenarioSpecL),
4055
- getDatasets(bundleModelR, request.scenarioSpecR)
4056
- ]);
4057
- if (datasetsResultL == null ? void 0 : datasetsResultL.modelRunTime) {
4058
- this.perfStatsL.addRun(datasetsResultL == null ? void 0 : datasetsResultL.modelRunTime);
4059
- }
4060
- if (datasetsResultR == null ? void 0 : datasetsResultR.modelRunTime) {
4061
- this.perfStatsR.addRun(datasetsResultR == null ? void 0 : datasetsResultR.modelRunTime);
4062
- }
4063
- const datasetMapL = datasetsResultL == null ? void 0 : datasetsResultL.datasetMap;
4064
- const datasetMapR = datasetsResultR == null ? void 0 : datasetsResultR.datasetMap;
4065
- for (const dataTask of request.dataTasks) {
4066
- const datasetL = datasetMapL == null ? void 0 : datasetMapL.get(dataTask.datasetKey);
4067
- const datasetR = datasetMapR == null ? void 0 : datasetMapR.get(dataTask.datasetKey);
4068
- dataTask.dataAction({
4069
- datasetL,
4070
- datasetR
4071
- });
4072
- }
4275
+ const datasetKeys = [...datasetKeySet];
4276
+ function getDatasets(bundleModel, scenarioSpec) {
4277
+ return __async(this, null, function* () {
4278
+ if (bundleModel && scenarioSpec) {
4279
+ return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys);
4280
+ } else {
4281
+ return void 0;
4282
+ }
4283
+ });
4284
+ }
4285
+ const bundleModelL = (_a = this.config.comparison) == null ? void 0 : _a.bundleL.model;
4286
+ const bundleModelR = ((_b = this.config.comparison) == null ? void 0 : _b.bundleR.model) || this.config.check.bundle.model;
4287
+ const [datasetsResultL, datasetsResultR] = yield Promise.all([
4288
+ getDatasets(bundleModelL, request.scenarioSpecL),
4289
+ getDatasets(bundleModelR, request.scenarioSpecR)
4290
+ ]);
4291
+ if (datasetsResultL == null ? void 0 : datasetsResultL.modelRunTime) {
4292
+ this.perfStatsL.addRun(datasetsResultL == null ? void 0 : datasetsResultL.modelRunTime);
4293
+ }
4294
+ if (datasetsResultR == null ? void 0 : datasetsResultR.modelRunTime) {
4295
+ this.perfStatsR.addRun(datasetsResultR == null ? void 0 : datasetsResultR.modelRunTime);
4296
+ }
4297
+ const datasetMapL = datasetsResultL == null ? void 0 : datasetsResultL.datasetMap;
4298
+ const datasetMapR = datasetsResultR == null ? void 0 : datasetsResultR.datasetMap;
4299
+ for (const dataTask of request.dataTasks) {
4300
+ const datasetL = datasetMapL == null ? void 0 : datasetMapL.get(dataTask.datasetKey);
4301
+ const datasetR = datasetMapR == null ? void 0 : datasetMapR.get(dataTask.datasetKey);
4302
+ dataTask.dataAction({
4303
+ datasetL,
4304
+ datasetR
4305
+ });
4306
+ }
4307
+ });
4073
4308
  }
4074
4309
  };
4075
4310
  function runSuite(config, callbacks, options) {