@sdeverywhere/check-core 0.1.3 → 0.1.5

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
@@ -3084,6 +3084,7 @@ import { assertNever as assertNever11 } from "assert-never";
3084
3084
  // src/bundle/model-inputs.ts
3085
3085
  var ModelInputs = class {
3086
3086
  constructor(modelSpec) {
3087
+ this.modelSpec = modelSpec;
3087
3088
  /** All inputs keyed by lookup name (lowercase variable name or alias). */
3088
3089
  this.inputsByLookupName = /* @__PURE__ */ new Map();
3089
3090
  /** All input ID aliases. */
@@ -3130,6 +3131,14 @@ var ModelInputs = class {
3130
3131
  getInputVarForName(name) {
3131
3132
  return this.inputsByLookupName.get(name.toLowerCase());
3132
3133
  }
3134
+ /**
3135
+ * Return the `InputVar` that matches the requested variable ID.
3136
+ *
3137
+ * @param varId The variable identifier to match.
3138
+ */
3139
+ getInputVarForVarId(varId) {
3140
+ return this.modelSpec.inputVars.get(varId);
3141
+ }
3133
3142
  };
3134
3143
 
3135
3144
  // src/comparison/config/resolve/comparison-scenario-specs.ts
@@ -3351,6 +3360,19 @@ function resolveScenariosFromSpec(modelInputsL, modelInputsR, scenarioSpec, genK
3351
3360
  )
3352
3361
  ];
3353
3362
  }
3363
+ case "scenario-with-setting-group": {
3364
+ return [
3365
+ resolveScenarioForSettingGroup(
3366
+ modelInputsL,
3367
+ modelInputsR,
3368
+ genKey(),
3369
+ scenarioSpec.id,
3370
+ scenarioSpec.title,
3371
+ scenarioSpec.subtitle,
3372
+ scenarioSpec.settingGroupId
3373
+ )
3374
+ ];
3375
+ }
3354
3376
  default:
3355
3377
  assertNever11(scenarioSpec);
3356
3378
  }
@@ -3480,6 +3502,113 @@ function resolveScenarioForDistinctInputSpecs(modelInputsL, modelInputsR, key, i
3480
3502
  specR
3481
3503
  };
3482
3504
  }
3505
+ function resolveScenarioForSettingGroup(modelInputsL, modelInputsR, key, id, title, subtitle, settingGroupId) {
3506
+ var _a, _b;
3507
+ function inputVarNameForVarId(modelInputs, varId) {
3508
+ const inputVar = modelInputs.getInputVarForVarId(varId);
3509
+ if (inputVar !== void 0) {
3510
+ return inputVar.varName;
3511
+ } else {
3512
+ return varId;
3513
+ }
3514
+ }
3515
+ function inputPositionForPosition(position) {
3516
+ switch (position) {
3517
+ case "at-minimum":
3518
+ return "min";
3519
+ case "at-maximum":
3520
+ return "max";
3521
+ case "at-default":
3522
+ return "default";
3523
+ default:
3524
+ throw new Error(`Unknown input position: ${position}`);
3525
+ }
3526
+ }
3527
+ function inputSpecForSetting(modelInputs, inputSetting) {
3528
+ switch (inputSetting.kind) {
3529
+ case "position":
3530
+ return {
3531
+ kind: "input-at-position",
3532
+ inputName: inputVarNameForVarId(modelInputs, inputSetting.inputVarId),
3533
+ position: inputPositionForPosition(inputSetting.position)
3534
+ };
3535
+ case "value":
3536
+ return {
3537
+ kind: "input-at-value",
3538
+ inputName: inputVarNameForVarId(modelInputs, inputSetting.inputVarId),
3539
+ value: inputSetting.value
3540
+ };
3541
+ default:
3542
+ throw new Error(`Unknown input setting kind: ${inputSetting}`);
3543
+ }
3544
+ }
3545
+ function inputSpecsForSettingGroup(modelInputs, inputSettings) {
3546
+ return inputSettings.map((inputSetting) => inputSpecForSetting(modelInputs, inputSetting));
3547
+ }
3548
+ const inputSettingsL = ((_a = modelInputsL.modelSpec.inputSettingGroups) == null ? void 0 : _a.get(settingGroupId)) || [];
3549
+ const inputSettingsR = ((_b = modelInputsR.modelSpec.inputSettingGroups) == null ? void 0 : _b.get(settingGroupId)) || [];
3550
+ const inputsL = inputSpecsForSettingGroup(modelInputsL, inputSettingsL);
3551
+ const inputsR = inputSpecsForSettingGroup(modelInputsR, inputSettingsR);
3552
+ const scenario = resolveScenarioForDistinctInputSpecs(
3553
+ modelInputsL,
3554
+ modelInputsR,
3555
+ key,
3556
+ id,
3557
+ title,
3558
+ subtitle,
3559
+ inputsL,
3560
+ inputsR
3561
+ );
3562
+ function scenarioString(scenario2) {
3563
+ if (scenario2.kind === "input-settings") {
3564
+ const settings = scenario2.settings.map((setting) => {
3565
+ switch (setting.kind) {
3566
+ case "position":
3567
+ return `${setting.inputVarId}=${setting.position}`;
3568
+ case "value":
3569
+ return `${setting.inputVarId}=${setting.value}`;
3570
+ default:
3571
+ throw new Error(`Unexpected input setting kind: ${setting}`);
3572
+ }
3573
+ });
3574
+ return settings.sort().join("__");
3575
+ } else {
3576
+ throw new Error(`Unexpected scenario spec kind: ${scenario2.kind}`);
3577
+ }
3578
+ }
3579
+ function scenariosAreEqual(scenarioL, scenarioR) {
3580
+ return scenarioString(scenarioL) === scenarioString(scenarioR);
3581
+ }
3582
+ function errorState(inputSettings) {
3583
+ if (inputSettings.length === 0) {
3584
+ return { error: { kind: "unknown-input-setting-group" } };
3585
+ } else {
3586
+ return {};
3587
+ }
3588
+ }
3589
+ if (inputSettingsL.length === 0 || inputSettingsR.length === 0) {
3590
+ if (scenario.settings.kind === "input-settings") {
3591
+ const errorSetting = {
3592
+ requestedName: settingGroupId,
3593
+ stateL: errorState(inputSettingsL),
3594
+ stateR: errorState(inputSettingsR)
3595
+ };
3596
+ scenario.settings.inputs.unshift(errorSetting);
3597
+ }
3598
+ if (inputSettingsL.length === 0) {
3599
+ scenario.specL = void 0;
3600
+ }
3601
+ if (inputSettingsR.length === 0) {
3602
+ scenario.specR = void 0;
3603
+ }
3604
+ }
3605
+ if (scenario.settings.kind === "input-settings") {
3606
+ if (scenario.specL && scenario.specR && !scenariosAreEqual(scenario.specL, scenario.specR)) {
3607
+ scenario.settings.settingsDiffer = true;
3608
+ }
3609
+ }
3610
+ return scenario;
3611
+ }
3483
3612
  function resolveInputForName(modelInputsL, modelInputsR, inputName, at) {
3484
3613
  return {
3485
3614
  requestedName: inputName,
@@ -4096,7 +4225,8 @@ function createConfig(options) {
4096
4225
  thresholds: options.comparison.thresholds,
4097
4226
  scenarios: getComparisonScenarios(comparisonDefs.scenarios),
4098
4227
  datasets: getComparisonDatasets(modelSpecL, modelSpecR, options.comparison.datasets),
4099
- viewGroups: comparisonDefs.viewGroups
4228
+ viewGroups: comparisonDefs.viewGroups,
4229
+ reportOptions: options.comparison.report
4100
4230
  };
4101
4231
  }
4102
4232
  const checkConfig = {