@sdeverywhere/check-core 0.1.9 → 0.1.10

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
@@ -377,13 +377,29 @@ var CheckDataCoordinator = class {
377
377
  constructor(taskQueue) {
378
378
  this.taskQueue = taskQueue;
379
379
  }
380
- requestDataset(requestKey, scenarioSpec, datasetKey, onResponse) {
380
+ /**
381
+ * Request a dataset from the model.
382
+ *
383
+ * @param requestKey The unique key for the request.
384
+ * @param scenarioSpec The scenario spec that defines the inputs for the model run.
385
+ * @param datasetKey The key of the dataset to be fetched.
386
+ * @param options Optional configuration including constant and lookup overrides.
387
+ * @param onResponse The callback that will be called with the dataset.
388
+ */
389
+ requestDataset(requestKey, scenarioSpec, datasetKey, options, onResponse) {
381
390
  const task = {
382
391
  key: requestKey,
383
392
  kind: "check-data-coordinator",
384
393
  process: (bundleModels) => __async(null, null, function* () {
385
394
  const bundleModelR = bundleModels.R;
386
- const result = yield bundleModelR.getDatasetsForScenario(scenarioSpec, [datasetKey]);
395
+ let getDatasetsOptions;
396
+ if ((options == null ? void 0 : options.constants) || (options == null ? void 0 : options.lookups)) {
397
+ getDatasetsOptions = {
398
+ constants: options.constants,
399
+ lookups: options.lookups
400
+ };
401
+ }
402
+ const result = yield bundleModelR.getDatasetsForScenario(scenarioSpec, [datasetKey], getDatasetsOptions);
387
403
  const dataset = result.datasetMap.get(datasetKey);
388
404
  onResponse(dataset);
389
405
  })
@@ -1651,9 +1667,25 @@ function inputValueAtPosition(inputVar, position) {
1651
1667
  case "at-default":
1652
1668
  return inputVar.defaultValue;
1653
1669
  case "at-minimum":
1654
- return inputVar.minValue;
1670
+ switch (inputVar.kind) {
1671
+ case "slider":
1672
+ return inputVar.minValue;
1673
+ case "switch":
1674
+ return inputVar.offValue;
1675
+ default:
1676
+ (0, import_assert_never4.default)(inputVar);
1677
+ }
1678
+ // eslint-disable-next-line no-fallthrough
1655
1679
  case "at-maximum":
1656
- return inputVar.maxValue;
1680
+ switch (inputVar.kind) {
1681
+ case "slider":
1682
+ return inputVar.maxValue;
1683
+ case "switch":
1684
+ return inputVar.onValue;
1685
+ default:
1686
+ (0, import_assert_never4.default)(inputVar);
1687
+ }
1688
+ // eslint-disable-next-line no-fallthrough
1657
1689
  default:
1658
1690
  (0, import_assert_never4.default)(position);
1659
1691
  }
@@ -2082,14 +2114,19 @@ var ComparisonDataCoordinator = class {
2082
2114
  * will be fetched from the "left" bundle's model, otherwise they will be fetched from
2083
2115
  * the "right" bundle's model.
2084
2116
  * @param scenarioSpecR The scenario used for the second ("right") model of the comparison.
2085
- * @param graphId The keys of the datasets to be fetched.
2117
+ * @param datasetKeys The keys of the datasets to be fetched.
2118
+ * @param options Optional configuration including constant and lookup overrides.
2086
2119
  * @param onResponse The callback that will be called with the dataset maps.
2087
2120
  */
2088
- requestDatasetMaps(requestKey, sourceL, scenarioSpecL, sourceR, scenarioSpecR, datasetKeys, onResponse) {
2089
- function fetchDatasets(bundleModel, scenarioSpec) {
2121
+ requestDatasetMaps(requestKey, sourceL, scenarioSpecL, sourceR, scenarioSpecR, datasetKeys, options, onResponse) {
2122
+ function fetchDatasets(bundleModel, scenarioSpec, constants, lookups) {
2090
2123
  return __async(this, null, function* () {
2091
2124
  if (scenarioSpec) {
2092
- return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys);
2125
+ let getDatasetsOptions;
2126
+ if (constants || lookups) {
2127
+ getDatasetsOptions = { constants, lookups };
2128
+ }
2129
+ return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys, getDatasetsOptions);
2093
2130
  } else {
2094
2131
  return void 0;
2095
2132
  }
@@ -2104,12 +2141,12 @@ var ComparisonDataCoordinator = class {
2104
2141
  let resultL;
2105
2142
  let resultR;
2106
2143
  if (modelL === modelR) {
2107
- resultL = yield fetchDatasets(modelL, scenarioSpecL);
2108
- resultR = yield fetchDatasets(modelR, scenarioSpecR);
2144
+ resultL = yield fetchDatasets(modelL, scenarioSpecL, options == null ? void 0 : options.constantsL, options == null ? void 0 : options.lookupsL);
2145
+ resultR = yield fetchDatasets(modelR, scenarioSpecR, options == null ? void 0 : options.constantsR, options == null ? void 0 : options.lookupsR);
2109
2146
  } else {
2110
2147
  const results = yield Promise.all([
2111
- fetchDatasets(modelL, scenarioSpecL),
2112
- fetchDatasets(modelR, scenarioSpecR)
2148
+ fetchDatasets(modelL, scenarioSpecL, options == null ? void 0 : options.constantsL, options == null ? void 0 : options.lookupsL),
2149
+ fetchDatasets(modelR, scenarioSpecR, options == null ? void 0 : options.constantsR, options == null ? void 0 : options.lookupsR)
2113
2150
  ]);
2114
2151
  resultL = results[0];
2115
2152
  resultR = results[1];
@@ -3969,7 +4006,18 @@ function resolveInputVarAtPosition(inputVar, position) {
3969
4006
  };
3970
4007
  }
3971
4008
  function resolveInputVarAtValue(inputVar, value) {
3972
- if (value >= inputVar.minValue && value <= inputVar.maxValue) {
4009
+ let inRange;
4010
+ switch (inputVar.kind) {
4011
+ case "slider":
4012
+ inRange = value >= inputVar.minValue && value <= inputVar.maxValue;
4013
+ break;
4014
+ case "switch":
4015
+ inRange = value === inputVar.offValue || value === inputVar.onValue;
4016
+ break;
4017
+ default:
4018
+ (0, import_assert_never10.assertNever)(inputVar);
4019
+ }
4020
+ if (inRange) {
3973
4021
  return {
3974
4022
  inputVar,
3975
4023
  value
@@ -3999,9 +4047,25 @@ function inputValueAtPosition2(inputVar, position) {
3999
4047
  case "at-default":
4000
4048
  return inputVar.defaultValue;
4001
4049
  case "at-minimum":
4002
- return inputVar.minValue;
4050
+ switch (inputVar.kind) {
4051
+ case "slider":
4052
+ return inputVar.minValue;
4053
+ case "switch":
4054
+ return inputVar.offValue;
4055
+ default:
4056
+ (0, import_assert_never10.assertNever)(inputVar);
4057
+ }
4058
+ // eslint-disable-next-line no-fallthrough
4003
4059
  case "at-maximum":
4004
- return inputVar.maxValue;
4060
+ switch (inputVar.kind) {
4061
+ case "slider":
4062
+ return inputVar.maxValue;
4063
+ case "switch":
4064
+ return inputVar.onValue;
4065
+ default:
4066
+ (0, import_assert_never10.assertNever)(inputVar);
4067
+ }
4068
+ // eslint-disable-next-line no-fallthrough
4005
4069
  default:
4006
4070
  (0, import_assert_never10.assertNever)(position);
4007
4071
  }
@@ -4533,12 +4597,12 @@ function handleRenames(origCurrentBundle, renamedDatasetKeys) {
4533
4597
  var _a, _b, _c;
4534
4598
  return {
4535
4599
  modelSpec: origBundleModelR.modelSpec,
4536
- getDatasetsForScenario: (scenarioSpec, datasetKeys) => __async(null, null, function* () {
4600
+ getDatasetsForScenario: (scenarioSpec, datasetKeys, options) => __async(null, null, function* () {
4537
4601
  const rightKeySet = /* @__PURE__ */ new Set();
4538
4602
  for (const key of datasetKeys) {
4539
4603
  rightKeySet.add(rightKeyForLeftKey(key));
4540
4604
  }
4541
- const result = yield origBundleModelR.getDatasetsForScenario(scenarioSpec, [...rightKeySet]);
4605
+ const result = yield origBundleModelR.getDatasetsForScenario(scenarioSpec, [...rightKeySet], options);
4542
4606
  const resultMap = /* @__PURE__ */ new Map();
4543
4607
  for (const [rightKey, dataset] of result.datasetMap.entries()) {
4544
4608
  resultMap.set(rightKey, dataset);
@@ -5036,8 +5100,12 @@ var DataPlanner = class {
5036
5100
  * is needed from the right model.
5037
5101
  * @param datasetKey The key for the dataset to be fetched from each model for the given scenario.
5038
5102
  * @param dataAction The action to be performed with the fetched datasets.
5103
+ * @param constantsL Optional constant overrides for the "left" model.
5104
+ * @param constantsR Optional constant overrides for the "right" model.
5105
+ * @param lookupsL Optional lookup overrides for the "left" model.
5106
+ * @param lookupsR Optional lookup overrides for the "right" model.
5039
5107
  */
5040
- addRequest(scenarioSpecL, scenarioSpecR, datasetKey, dataAction) {
5108
+ addRequest(scenarioSpecL, scenarioSpecR, datasetKey, dataAction, constantsL, constantsR, lookupsL, lookupsR) {
5041
5109
  if (scenarioSpecL === void 0 && scenarioSpecR === void 0) {
5042
5110
  console.warn("WARNING: Both scenario specs are undefined for DataPlanner request, skipping");
5043
5111
  return;
@@ -5046,17 +5114,17 @@ var DataPlanner = class {
5046
5114
  let uid;
5047
5115
  if (scenarioSpecL && scenarioSpecR) {
5048
5116
  taskSetsMap = this.taskSetsLR;
5049
- uid = scenarioPairUid(scenarioSpecL, scenarioSpecR);
5117
+ uid = scenarioPairUid(scenarioSpecL, scenarioSpecR, constantsL, constantsR, lookupsL, lookupsR);
5050
5118
  } else if (scenarioSpecR) {
5051
5119
  taskSetsMap = this.taskSetsR;
5052
- uid = scenarioSpecR.uid;
5120
+ uid = scenarioPairUid(void 0, scenarioSpecR, void 0, constantsR, void 0, lookupsR);
5053
5121
  } else {
5054
5122
  taskSetsMap = this.taskSetsL;
5055
- uid = scenarioSpecL.uid;
5123
+ uid = scenarioPairUid(scenarioSpecL, void 0, constantsL, void 0, lookupsL, void 0);
5056
5124
  }
5057
5125
  let taskSet = taskSetsMap.get(uid);
5058
5126
  if (!taskSet) {
5059
- taskSet = new DataTaskSet(scenarioSpecL, scenarioSpecR);
5127
+ taskSet = new DataTaskSet(scenarioSpecL, scenarioSpecR, constantsL, constantsR, lookupsL, lookupsR);
5060
5128
  taskSetsMap.set(uid, taskSet);
5061
5129
  }
5062
5130
  taskSet.addTask({
@@ -5075,26 +5143,33 @@ var DataPlanner = class {
5075
5143
  const lKeyMappings = /* @__PURE__ */ new Map();
5076
5144
  const rKeyMappings = /* @__PURE__ */ new Map();
5077
5145
  for (const lrUid of this.taskSetsLR.keys()) {
5078
- const [lUid, rUid] = lrUid.split("::");
5079
- if (!lKeyMappings.has(lUid)) {
5080
- lKeyMappings.set(lUid, lrUid);
5146
+ const parsed = parsePairUid(lrUid);
5147
+ const lKey = sideKey(parsed.lScenarioUid, parsed.lConstUid, parsed.lLookupUid);
5148
+ const rKey = sideKey(parsed.rScenarioUid, parsed.rConstUid, parsed.rLookupUid);
5149
+ if (parsed.lScenarioUid && !lKeyMappings.has(lKey)) {
5150
+ lKeyMappings.set(lKey, lrUid);
5081
5151
  }
5082
- if (!rKeyMappings.has(rUid)) {
5083
- rKeyMappings.set(rUid, lrUid);
5152
+ if (parsed.rScenarioUid && !rKeyMappings.has(rKey)) {
5153
+ rKeyMappings.set(rKey, lrUid);
5084
5154
  }
5085
5155
  }
5086
- function merge(taskSetsLR, taskSetsForSide, keyMappingsForSide) {
5087
- for (const [keyForSide, taskSetForSide] of taskSetsForSide.entries()) {
5088
- const lrKey = keyMappingsForSide.get(keyForSide);
5156
+ function merge(taskSetsLR, taskSetsForSide, keyMappingsForSide, side) {
5157
+ for (const [pairUidForSide, taskSetForSide] of taskSetsForSide.entries()) {
5158
+ const parsed = parsePairUid(pairUidForSide);
5159
+ const scenarioUid = side === "L" ? parsed.lScenarioUid : parsed.rScenarioUid;
5160
+ const constUid = side === "L" ? parsed.lConstUid : parsed.rConstUid;
5161
+ const lookupUid = side === "L" ? parsed.lLookupUid : parsed.rLookupUid;
5162
+ const sKey = sideKey(scenarioUid, constUid, lookupUid);
5163
+ const lrKey = keyMappingsForSide.get(sKey);
5089
5164
  if (lrKey) {
5090
5165
  const taskSetLR = taskSetsLR.get(lrKey);
5091
5166
  taskSetLR.merge(taskSetForSide);
5092
- taskSetsForSide.delete(keyForSide);
5167
+ taskSetsForSide.delete(pairUidForSide);
5093
5168
  }
5094
5169
  }
5095
5170
  }
5096
- merge(this.taskSetsLR, this.taskSetsL, lKeyMappings);
5097
- merge(this.taskSetsLR, this.taskSetsR, rKeyMappings);
5171
+ merge(this.taskSetsLR, this.taskSetsL, lKeyMappings, "L");
5172
+ merge(this.taskSetsLR, this.taskSetsR, rKeyMappings, "R");
5098
5173
  const requests = [];
5099
5174
  const batchSize = this.batchSize;
5100
5175
  function addRequests(taskSets) {
@@ -5111,9 +5186,13 @@ var DataPlanner = class {
5111
5186
  }
5112
5187
  };
5113
5188
  var DataTaskSet = class {
5114
- constructor(scenarioSpecL, scenarioSpecR) {
5189
+ constructor(scenarioSpecL, scenarioSpecR, constantsL, constantsR, lookupsL, lookupsR) {
5115
5190
  this.scenarioSpecL = scenarioSpecL;
5116
5191
  this.scenarioSpecR = scenarioSpecR;
5192
+ this.constantsL = constantsL;
5193
+ this.constantsR = constantsR;
5194
+ this.lookupsL = lookupsL;
5195
+ this.lookupsR = lookupsR;
5117
5196
  this.modelTasks = /* @__PURE__ */ new Map();
5118
5197
  this.modelImplTasks = /* @__PURE__ */ new Map();
5119
5198
  }
@@ -5168,6 +5247,10 @@ var DataTaskSet = class {
5168
5247
  dataRequests.push({
5169
5248
  scenarioSpecL: this.scenarioSpecL,
5170
5249
  scenarioSpecR: this.scenarioSpecR,
5250
+ constantsL: this.constantsL,
5251
+ constantsR: this.constantsR,
5252
+ lookupsL: this.lookupsL,
5253
+ lookupsR: this.lookupsR,
5171
5254
  dataTasks
5172
5255
  });
5173
5256
  }
@@ -5182,6 +5265,10 @@ var DataTaskSet = class {
5182
5265
  dataRequests.push({
5183
5266
  scenarioSpecL: this.scenarioSpecL,
5184
5267
  scenarioSpecR: this.scenarioSpecR,
5268
+ constantsL: this.constantsL,
5269
+ constantsR: this.constantsR,
5270
+ lookupsL: this.lookupsL,
5271
+ lookupsR: this.lookupsR,
5185
5272
  dataTasks
5186
5273
  });
5187
5274
  }
@@ -5189,10 +5276,76 @@ var DataTaskSet = class {
5189
5276
  return dataRequests;
5190
5277
  }
5191
5278
  };
5192
- function scenarioPairUid(scenarioSpecL, scenarioSpecR) {
5279
+ function constantsUid(constants) {
5280
+ if (!constants || constants.length === 0) {
5281
+ return "";
5282
+ }
5283
+ const sorted = [...constants].sort((a, b) => a.varId.localeCompare(b.varId));
5284
+ return sorted.map((c) => `${c.varId}=${c.value}`).join(",");
5285
+ }
5286
+ function lookupsUid(lookups) {
5287
+ if (!lookups || lookups.length === 0) {
5288
+ return "";
5289
+ }
5290
+ const sorted = [...lookups].sort((a, b) => a.varId.localeCompare(b.varId));
5291
+ return sorted.map((l) => {
5292
+ if (l.points === void 0) {
5293
+ return `${l.varId}=`;
5294
+ }
5295
+ return `${l.varId}=[${l.points.join(",")}]`;
5296
+ }).join(";");
5297
+ }
5298
+ function sideKey(scenarioUid, constUid, lookupUid) {
5299
+ let key = scenarioUid;
5300
+ if (constUid) {
5301
+ key += `##${constUid}`;
5302
+ }
5303
+ if (lookupUid) {
5304
+ key += `%%${lookupUid}`;
5305
+ }
5306
+ return key;
5307
+ }
5308
+ function parsePairUid(pairUid) {
5309
+ var _a, _b, _c, _d, _e, _f;
5310
+ let rest = pairUid;
5311
+ let lookupsPart = "";
5312
+ const lookupsIdx = rest.indexOf("%%");
5313
+ if (lookupsIdx >= 0) {
5314
+ lookupsPart = rest.substring(lookupsIdx + 2);
5315
+ rest = rest.substring(0, lookupsIdx);
5316
+ }
5317
+ let constantsPart = "";
5318
+ const constantsIdx = rest.indexOf("##");
5319
+ if (constantsIdx >= 0) {
5320
+ constantsPart = rest.substring(constantsIdx + 2);
5321
+ rest = rest.substring(0, constantsIdx);
5322
+ }
5323
+ const scenarioParts = rest.split("::");
5324
+ const lScenarioUid = (_a = scenarioParts[0]) != null ? _a : "";
5325
+ const rScenarioUid = (_b = scenarioParts[1]) != null ? _b : "";
5326
+ const constantsParts = constantsPart.split("||");
5327
+ const lConstUid = constantsPart ? (_c = constantsParts[0]) != null ? _c : "" : "";
5328
+ const rConstUid = constantsPart ? (_d = constantsParts[1]) != null ? _d : "" : "";
5329
+ const lookupsParts = lookupsPart.split("||");
5330
+ const lLookupUid = lookupsPart ? (_e = lookupsParts[0]) != null ? _e : "" : "";
5331
+ const rLookupUid = lookupsPart ? (_f = lookupsParts[1]) != null ? _f : "" : "";
5332
+ return { lScenarioUid, rScenarioUid, lConstUid, rConstUid, lLookupUid, rLookupUid };
5333
+ }
5334
+ function scenarioPairUid(scenarioSpecL, scenarioSpecR, constantsL, constantsR, lookupsL, lookupsR) {
5193
5335
  const uidL = (scenarioSpecL == null ? void 0 : scenarioSpecL.uid) || "";
5194
5336
  const uidR = (scenarioSpecR == null ? void 0 : scenarioSpecR.uid) || "";
5195
- return `${uidL}::${uidR}`;
5337
+ let uid = `${uidL}::${uidR}`;
5338
+ const constUidL = constantsUid(constantsL);
5339
+ const constUidR = constantsUid(constantsR);
5340
+ if (constUidL || constUidR) {
5341
+ uid += `##${constUidL}||${constUidR}`;
5342
+ }
5343
+ const lookupUidL = lookupsUid(lookupsL);
5344
+ const lookupUidR = lookupsUid(lookupsR);
5345
+ if (lookupUidL || lookupUidR) {
5346
+ uid += `%%${lookupUidL}||${lookupUidR}`;
5347
+ }
5348
+ return uid;
5196
5349
  }
5197
5350
 
5198
5351
  // src/check/check-runner.ts
@@ -5483,10 +5636,14 @@ var SuiteRunner = class {
5483
5636
  datasetKeySet.add(dataTask.datasetKey);
5484
5637
  }
5485
5638
  const datasetKeys = [...datasetKeySet];
5486
- function getDatasets(bundleModel, scenarioSpec) {
5639
+ function getDatasets(bundleModel, scenarioSpec, constants, lookups) {
5487
5640
  return __async(this, null, function* () {
5488
5641
  if (bundleModel && scenarioSpec) {
5489
- return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys);
5642
+ let options;
5643
+ if (constants || lookups) {
5644
+ options = { constants, lookups };
5645
+ }
5646
+ return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys, options);
5490
5647
  } else {
5491
5648
  return void 0;
5492
5649
  }
@@ -5495,8 +5652,8 @@ var SuiteRunner = class {
5495
5652
  const bundleModelL = bundleModels.L;
5496
5653
  const bundleModelR = bundleModels.R;
5497
5654
  const [datasetsResultL, datasetsResultR] = yield Promise.all([
5498
- getDatasets(bundleModelL, request.scenarioSpecL),
5499
- getDatasets(bundleModelR, request.scenarioSpecR)
5655
+ getDatasets(bundleModelL, request.scenarioSpecL, request.constantsL, request.lookupsL),
5656
+ getDatasets(bundleModelR, request.scenarioSpecR, request.constantsR, request.lookupsR)
5500
5657
  ]);
5501
5658
  if (datasetsResultL == null ? void 0 : datasetsResultL.modelRunTime) {
5502
5659
  this.perfStatsL.addRun(datasetsResultL == null ? void 0 : datasetsResultL.modelRunTime);