@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.js CHANGED
@@ -322,13 +322,29 @@ var CheckDataCoordinator = class {
322
322
  constructor(taskQueue) {
323
323
  this.taskQueue = taskQueue;
324
324
  }
325
- requestDataset(requestKey, scenarioSpec, datasetKey, onResponse) {
325
+ /**
326
+ * Request a dataset from the model.
327
+ *
328
+ * @param requestKey The unique key for the request.
329
+ * @param scenarioSpec The scenario spec that defines the inputs for the model run.
330
+ * @param datasetKey The key of the dataset to be fetched.
331
+ * @param options Optional configuration including constant and lookup overrides.
332
+ * @param onResponse The callback that will be called with the dataset.
333
+ */
334
+ requestDataset(requestKey, scenarioSpec, datasetKey, options, onResponse) {
326
335
  const task = {
327
336
  key: requestKey,
328
337
  kind: "check-data-coordinator",
329
338
  process: (bundleModels) => __async(null, null, function* () {
330
339
  const bundleModelR = bundleModels.R;
331
- const result = yield bundleModelR.getDatasetsForScenario(scenarioSpec, [datasetKey]);
340
+ let getDatasetsOptions;
341
+ if ((options == null ? void 0 : options.constants) || (options == null ? void 0 : options.lookups)) {
342
+ getDatasetsOptions = {
343
+ constants: options.constants,
344
+ lookups: options.lookups
345
+ };
346
+ }
347
+ const result = yield bundleModelR.getDatasetsForScenario(scenarioSpec, [datasetKey], getDatasetsOptions);
332
348
  const dataset = result.datasetMap.get(datasetKey);
333
349
  onResponse(dataset);
334
350
  })
@@ -1596,9 +1612,25 @@ function inputValueAtPosition(inputVar, position) {
1596
1612
  case "at-default":
1597
1613
  return inputVar.defaultValue;
1598
1614
  case "at-minimum":
1599
- return inputVar.minValue;
1615
+ switch (inputVar.kind) {
1616
+ case "slider":
1617
+ return inputVar.minValue;
1618
+ case "switch":
1619
+ return inputVar.offValue;
1620
+ default:
1621
+ assertNever4(inputVar);
1622
+ }
1623
+ // eslint-disable-next-line no-fallthrough
1600
1624
  case "at-maximum":
1601
- return inputVar.maxValue;
1625
+ switch (inputVar.kind) {
1626
+ case "slider":
1627
+ return inputVar.maxValue;
1628
+ case "switch":
1629
+ return inputVar.onValue;
1630
+ default:
1631
+ assertNever4(inputVar);
1632
+ }
1633
+ // eslint-disable-next-line no-fallthrough
1602
1634
  default:
1603
1635
  assertNever4(position);
1604
1636
  }
@@ -2027,14 +2059,19 @@ var ComparisonDataCoordinator = class {
2027
2059
  * will be fetched from the "left" bundle's model, otherwise they will be fetched from
2028
2060
  * the "right" bundle's model.
2029
2061
  * @param scenarioSpecR The scenario used for the second ("right") model of the comparison.
2030
- * @param graphId The keys of the datasets to be fetched.
2062
+ * @param datasetKeys The keys of the datasets to be fetched.
2063
+ * @param options Optional configuration including constant and lookup overrides.
2031
2064
  * @param onResponse The callback that will be called with the dataset maps.
2032
2065
  */
2033
- requestDatasetMaps(requestKey, sourceL, scenarioSpecL, sourceR, scenarioSpecR, datasetKeys, onResponse) {
2034
- function fetchDatasets(bundleModel, scenarioSpec) {
2066
+ requestDatasetMaps(requestKey, sourceL, scenarioSpecL, sourceR, scenarioSpecR, datasetKeys, options, onResponse) {
2067
+ function fetchDatasets(bundleModel, scenarioSpec, constants, lookups) {
2035
2068
  return __async(this, null, function* () {
2036
2069
  if (scenarioSpec) {
2037
- return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys);
2070
+ let getDatasetsOptions;
2071
+ if (constants || lookups) {
2072
+ getDatasetsOptions = { constants, lookups };
2073
+ }
2074
+ return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys, getDatasetsOptions);
2038
2075
  } else {
2039
2076
  return void 0;
2040
2077
  }
@@ -2049,12 +2086,12 @@ var ComparisonDataCoordinator = class {
2049
2086
  let resultL;
2050
2087
  let resultR;
2051
2088
  if (modelL === modelR) {
2052
- resultL = yield fetchDatasets(modelL, scenarioSpecL);
2053
- resultR = yield fetchDatasets(modelR, scenarioSpecR);
2089
+ resultL = yield fetchDatasets(modelL, scenarioSpecL, options == null ? void 0 : options.constantsL, options == null ? void 0 : options.lookupsL);
2090
+ resultR = yield fetchDatasets(modelR, scenarioSpecR, options == null ? void 0 : options.constantsR, options == null ? void 0 : options.lookupsR);
2054
2091
  } else {
2055
2092
  const results = yield Promise.all([
2056
- fetchDatasets(modelL, scenarioSpecL),
2057
- fetchDatasets(modelR, scenarioSpecR)
2093
+ fetchDatasets(modelL, scenarioSpecL, options == null ? void 0 : options.constantsL, options == null ? void 0 : options.lookupsL),
2094
+ fetchDatasets(modelR, scenarioSpecR, options == null ? void 0 : options.constantsR, options == null ? void 0 : options.lookupsR)
2058
2095
  ]);
2059
2096
  resultL = results[0];
2060
2097
  resultR = results[1];
@@ -3914,7 +3951,18 @@ function resolveInputVarAtPosition(inputVar, position) {
3914
3951
  };
3915
3952
  }
3916
3953
  function resolveInputVarAtValue(inputVar, value) {
3917
- if (value >= inputVar.minValue && value <= inputVar.maxValue) {
3954
+ let inRange;
3955
+ switch (inputVar.kind) {
3956
+ case "slider":
3957
+ inRange = value >= inputVar.minValue && value <= inputVar.maxValue;
3958
+ break;
3959
+ case "switch":
3960
+ inRange = value === inputVar.offValue || value === inputVar.onValue;
3961
+ break;
3962
+ default:
3963
+ assertNever10(inputVar);
3964
+ }
3965
+ if (inRange) {
3918
3966
  return {
3919
3967
  inputVar,
3920
3968
  value
@@ -3944,9 +3992,25 @@ function inputValueAtPosition2(inputVar, position) {
3944
3992
  case "at-default":
3945
3993
  return inputVar.defaultValue;
3946
3994
  case "at-minimum":
3947
- return inputVar.minValue;
3995
+ switch (inputVar.kind) {
3996
+ case "slider":
3997
+ return inputVar.minValue;
3998
+ case "switch":
3999
+ return inputVar.offValue;
4000
+ default:
4001
+ assertNever10(inputVar);
4002
+ }
4003
+ // eslint-disable-next-line no-fallthrough
3948
4004
  case "at-maximum":
3949
- return inputVar.maxValue;
4005
+ switch (inputVar.kind) {
4006
+ case "slider":
4007
+ return inputVar.maxValue;
4008
+ case "switch":
4009
+ return inputVar.onValue;
4010
+ default:
4011
+ assertNever10(inputVar);
4012
+ }
4013
+ // eslint-disable-next-line no-fallthrough
3950
4014
  default:
3951
4015
  assertNever10(position);
3952
4016
  }
@@ -4478,12 +4542,12 @@ function handleRenames(origCurrentBundle, renamedDatasetKeys) {
4478
4542
  var _a, _b, _c;
4479
4543
  return {
4480
4544
  modelSpec: origBundleModelR.modelSpec,
4481
- getDatasetsForScenario: (scenarioSpec, datasetKeys) => __async(null, null, function* () {
4545
+ getDatasetsForScenario: (scenarioSpec, datasetKeys, options) => __async(null, null, function* () {
4482
4546
  const rightKeySet = /* @__PURE__ */ new Set();
4483
4547
  for (const key of datasetKeys) {
4484
4548
  rightKeySet.add(rightKeyForLeftKey(key));
4485
4549
  }
4486
- const result = yield origBundleModelR.getDatasetsForScenario(scenarioSpec, [...rightKeySet]);
4550
+ const result = yield origBundleModelR.getDatasetsForScenario(scenarioSpec, [...rightKeySet], options);
4487
4551
  const resultMap = /* @__PURE__ */ new Map();
4488
4552
  for (const [rightKey, dataset] of result.datasetMap.entries()) {
4489
4553
  resultMap.set(rightKey, dataset);
@@ -4981,8 +5045,12 @@ var DataPlanner = class {
4981
5045
  * is needed from the right model.
4982
5046
  * @param datasetKey The key for the dataset to be fetched from each model for the given scenario.
4983
5047
  * @param dataAction The action to be performed with the fetched datasets.
5048
+ * @param constantsL Optional constant overrides for the "left" model.
5049
+ * @param constantsR Optional constant overrides for the "right" model.
5050
+ * @param lookupsL Optional lookup overrides for the "left" model.
5051
+ * @param lookupsR Optional lookup overrides for the "right" model.
4984
5052
  */
4985
- addRequest(scenarioSpecL, scenarioSpecR, datasetKey, dataAction) {
5053
+ addRequest(scenarioSpecL, scenarioSpecR, datasetKey, dataAction, constantsL, constantsR, lookupsL, lookupsR) {
4986
5054
  if (scenarioSpecL === void 0 && scenarioSpecR === void 0) {
4987
5055
  console.warn("WARNING: Both scenario specs are undefined for DataPlanner request, skipping");
4988
5056
  return;
@@ -4991,17 +5059,17 @@ var DataPlanner = class {
4991
5059
  let uid;
4992
5060
  if (scenarioSpecL && scenarioSpecR) {
4993
5061
  taskSetsMap = this.taskSetsLR;
4994
- uid = scenarioPairUid(scenarioSpecL, scenarioSpecR);
5062
+ uid = scenarioPairUid(scenarioSpecL, scenarioSpecR, constantsL, constantsR, lookupsL, lookupsR);
4995
5063
  } else if (scenarioSpecR) {
4996
5064
  taskSetsMap = this.taskSetsR;
4997
- uid = scenarioSpecR.uid;
5065
+ uid = scenarioPairUid(void 0, scenarioSpecR, void 0, constantsR, void 0, lookupsR);
4998
5066
  } else {
4999
5067
  taskSetsMap = this.taskSetsL;
5000
- uid = scenarioSpecL.uid;
5068
+ uid = scenarioPairUid(scenarioSpecL, void 0, constantsL, void 0, lookupsL, void 0);
5001
5069
  }
5002
5070
  let taskSet = taskSetsMap.get(uid);
5003
5071
  if (!taskSet) {
5004
- taskSet = new DataTaskSet(scenarioSpecL, scenarioSpecR);
5072
+ taskSet = new DataTaskSet(scenarioSpecL, scenarioSpecR, constantsL, constantsR, lookupsL, lookupsR);
5005
5073
  taskSetsMap.set(uid, taskSet);
5006
5074
  }
5007
5075
  taskSet.addTask({
@@ -5020,26 +5088,33 @@ var DataPlanner = class {
5020
5088
  const lKeyMappings = /* @__PURE__ */ new Map();
5021
5089
  const rKeyMappings = /* @__PURE__ */ new Map();
5022
5090
  for (const lrUid of this.taskSetsLR.keys()) {
5023
- const [lUid, rUid] = lrUid.split("::");
5024
- if (!lKeyMappings.has(lUid)) {
5025
- lKeyMappings.set(lUid, lrUid);
5091
+ const parsed = parsePairUid(lrUid);
5092
+ const lKey = sideKey(parsed.lScenarioUid, parsed.lConstUid, parsed.lLookupUid);
5093
+ const rKey = sideKey(parsed.rScenarioUid, parsed.rConstUid, parsed.rLookupUid);
5094
+ if (parsed.lScenarioUid && !lKeyMappings.has(lKey)) {
5095
+ lKeyMappings.set(lKey, lrUid);
5026
5096
  }
5027
- if (!rKeyMappings.has(rUid)) {
5028
- rKeyMappings.set(rUid, lrUid);
5097
+ if (parsed.rScenarioUid && !rKeyMappings.has(rKey)) {
5098
+ rKeyMappings.set(rKey, lrUid);
5029
5099
  }
5030
5100
  }
5031
- function merge(taskSetsLR, taskSetsForSide, keyMappingsForSide) {
5032
- for (const [keyForSide, taskSetForSide] of taskSetsForSide.entries()) {
5033
- const lrKey = keyMappingsForSide.get(keyForSide);
5101
+ function merge(taskSetsLR, taskSetsForSide, keyMappingsForSide, side) {
5102
+ for (const [pairUidForSide, taskSetForSide] of taskSetsForSide.entries()) {
5103
+ const parsed = parsePairUid(pairUidForSide);
5104
+ const scenarioUid = side === "L" ? parsed.lScenarioUid : parsed.rScenarioUid;
5105
+ const constUid = side === "L" ? parsed.lConstUid : parsed.rConstUid;
5106
+ const lookupUid = side === "L" ? parsed.lLookupUid : parsed.rLookupUid;
5107
+ const sKey = sideKey(scenarioUid, constUid, lookupUid);
5108
+ const lrKey = keyMappingsForSide.get(sKey);
5034
5109
  if (lrKey) {
5035
5110
  const taskSetLR = taskSetsLR.get(lrKey);
5036
5111
  taskSetLR.merge(taskSetForSide);
5037
- taskSetsForSide.delete(keyForSide);
5112
+ taskSetsForSide.delete(pairUidForSide);
5038
5113
  }
5039
5114
  }
5040
5115
  }
5041
- merge(this.taskSetsLR, this.taskSetsL, lKeyMappings);
5042
- merge(this.taskSetsLR, this.taskSetsR, rKeyMappings);
5116
+ merge(this.taskSetsLR, this.taskSetsL, lKeyMappings, "L");
5117
+ merge(this.taskSetsLR, this.taskSetsR, rKeyMappings, "R");
5043
5118
  const requests = [];
5044
5119
  const batchSize = this.batchSize;
5045
5120
  function addRequests(taskSets) {
@@ -5056,9 +5131,13 @@ var DataPlanner = class {
5056
5131
  }
5057
5132
  };
5058
5133
  var DataTaskSet = class {
5059
- constructor(scenarioSpecL, scenarioSpecR) {
5134
+ constructor(scenarioSpecL, scenarioSpecR, constantsL, constantsR, lookupsL, lookupsR) {
5060
5135
  this.scenarioSpecL = scenarioSpecL;
5061
5136
  this.scenarioSpecR = scenarioSpecR;
5137
+ this.constantsL = constantsL;
5138
+ this.constantsR = constantsR;
5139
+ this.lookupsL = lookupsL;
5140
+ this.lookupsR = lookupsR;
5062
5141
  this.modelTasks = /* @__PURE__ */ new Map();
5063
5142
  this.modelImplTasks = /* @__PURE__ */ new Map();
5064
5143
  }
@@ -5113,6 +5192,10 @@ var DataTaskSet = class {
5113
5192
  dataRequests.push({
5114
5193
  scenarioSpecL: this.scenarioSpecL,
5115
5194
  scenarioSpecR: this.scenarioSpecR,
5195
+ constantsL: this.constantsL,
5196
+ constantsR: this.constantsR,
5197
+ lookupsL: this.lookupsL,
5198
+ lookupsR: this.lookupsR,
5116
5199
  dataTasks
5117
5200
  });
5118
5201
  }
@@ -5127,6 +5210,10 @@ var DataTaskSet = class {
5127
5210
  dataRequests.push({
5128
5211
  scenarioSpecL: this.scenarioSpecL,
5129
5212
  scenarioSpecR: this.scenarioSpecR,
5213
+ constantsL: this.constantsL,
5214
+ constantsR: this.constantsR,
5215
+ lookupsL: this.lookupsL,
5216
+ lookupsR: this.lookupsR,
5130
5217
  dataTasks
5131
5218
  });
5132
5219
  }
@@ -5134,10 +5221,76 @@ var DataTaskSet = class {
5134
5221
  return dataRequests;
5135
5222
  }
5136
5223
  };
5137
- function scenarioPairUid(scenarioSpecL, scenarioSpecR) {
5224
+ function constantsUid(constants) {
5225
+ if (!constants || constants.length === 0) {
5226
+ return "";
5227
+ }
5228
+ const sorted = [...constants].sort((a, b) => a.varId.localeCompare(b.varId));
5229
+ return sorted.map((c) => `${c.varId}=${c.value}`).join(",");
5230
+ }
5231
+ function lookupsUid(lookups) {
5232
+ if (!lookups || lookups.length === 0) {
5233
+ return "";
5234
+ }
5235
+ const sorted = [...lookups].sort((a, b) => a.varId.localeCompare(b.varId));
5236
+ return sorted.map((l) => {
5237
+ if (l.points === void 0) {
5238
+ return `${l.varId}=`;
5239
+ }
5240
+ return `${l.varId}=[${l.points.join(",")}]`;
5241
+ }).join(";");
5242
+ }
5243
+ function sideKey(scenarioUid, constUid, lookupUid) {
5244
+ let key = scenarioUid;
5245
+ if (constUid) {
5246
+ key += `##${constUid}`;
5247
+ }
5248
+ if (lookupUid) {
5249
+ key += `%%${lookupUid}`;
5250
+ }
5251
+ return key;
5252
+ }
5253
+ function parsePairUid(pairUid) {
5254
+ var _a, _b, _c, _d, _e, _f;
5255
+ let rest = pairUid;
5256
+ let lookupsPart = "";
5257
+ const lookupsIdx = rest.indexOf("%%");
5258
+ if (lookupsIdx >= 0) {
5259
+ lookupsPart = rest.substring(lookupsIdx + 2);
5260
+ rest = rest.substring(0, lookupsIdx);
5261
+ }
5262
+ let constantsPart = "";
5263
+ const constantsIdx = rest.indexOf("##");
5264
+ if (constantsIdx >= 0) {
5265
+ constantsPart = rest.substring(constantsIdx + 2);
5266
+ rest = rest.substring(0, constantsIdx);
5267
+ }
5268
+ const scenarioParts = rest.split("::");
5269
+ const lScenarioUid = (_a = scenarioParts[0]) != null ? _a : "";
5270
+ const rScenarioUid = (_b = scenarioParts[1]) != null ? _b : "";
5271
+ const constantsParts = constantsPart.split("||");
5272
+ const lConstUid = constantsPart ? (_c = constantsParts[0]) != null ? _c : "" : "";
5273
+ const rConstUid = constantsPart ? (_d = constantsParts[1]) != null ? _d : "" : "";
5274
+ const lookupsParts = lookupsPart.split("||");
5275
+ const lLookupUid = lookupsPart ? (_e = lookupsParts[0]) != null ? _e : "" : "";
5276
+ const rLookupUid = lookupsPart ? (_f = lookupsParts[1]) != null ? _f : "" : "";
5277
+ return { lScenarioUid, rScenarioUid, lConstUid, rConstUid, lLookupUid, rLookupUid };
5278
+ }
5279
+ function scenarioPairUid(scenarioSpecL, scenarioSpecR, constantsL, constantsR, lookupsL, lookupsR) {
5138
5280
  const uidL = (scenarioSpecL == null ? void 0 : scenarioSpecL.uid) || "";
5139
5281
  const uidR = (scenarioSpecR == null ? void 0 : scenarioSpecR.uid) || "";
5140
- return `${uidL}::${uidR}`;
5282
+ let uid = `${uidL}::${uidR}`;
5283
+ const constUidL = constantsUid(constantsL);
5284
+ const constUidR = constantsUid(constantsR);
5285
+ if (constUidL || constUidR) {
5286
+ uid += `##${constUidL}||${constUidR}`;
5287
+ }
5288
+ const lookupUidL = lookupsUid(lookupsL);
5289
+ const lookupUidR = lookupsUid(lookupsR);
5290
+ if (lookupUidL || lookupUidR) {
5291
+ uid += `%%${lookupUidL}||${lookupUidR}`;
5292
+ }
5293
+ return uid;
5141
5294
  }
5142
5295
 
5143
5296
  // src/check/check-runner.ts
@@ -5428,10 +5581,14 @@ var SuiteRunner = class {
5428
5581
  datasetKeySet.add(dataTask.datasetKey);
5429
5582
  }
5430
5583
  const datasetKeys = [...datasetKeySet];
5431
- function getDatasets(bundleModel, scenarioSpec) {
5584
+ function getDatasets(bundleModel, scenarioSpec, constants, lookups) {
5432
5585
  return __async(this, null, function* () {
5433
5586
  if (bundleModel && scenarioSpec) {
5434
- return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys);
5587
+ let options;
5588
+ if (constants || lookups) {
5589
+ options = { constants, lookups };
5590
+ }
5591
+ return bundleModel.getDatasetsForScenario(scenarioSpec, datasetKeys, options);
5435
5592
  } else {
5436
5593
  return void 0;
5437
5594
  }
@@ -5440,8 +5597,8 @@ var SuiteRunner = class {
5440
5597
  const bundleModelL = bundleModels.L;
5441
5598
  const bundleModelR = bundleModels.R;
5442
5599
  const [datasetsResultL, datasetsResultR] = yield Promise.all([
5443
- getDatasets(bundleModelL, request.scenarioSpecL),
5444
- getDatasets(bundleModelR, request.scenarioSpecR)
5600
+ getDatasets(bundleModelL, request.scenarioSpecL, request.constantsL, request.lookupsL),
5601
+ getDatasets(bundleModelR, request.scenarioSpecR, request.constantsR, request.lookupsR)
5445
5602
  ]);
5446
5603
  if (datasetsResultL == null ? void 0 : datasetsResultL.modelRunTime) {
5447
5604
  this.perfStatsL.addRun(datasetsResultL == null ? void 0 : datasetsResultL.modelRunTime);