@sdeverywhere/check-core 0.1.4 → 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.cjs +129 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -3
- package/dist/index.d.ts +31 -3
- package/dist/index.js +129 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -3132,6 +3132,7 @@ var import_assert_never11 = require("assert-never");
|
|
|
3132
3132
|
// src/bundle/model-inputs.ts
|
|
3133
3133
|
var ModelInputs = class {
|
|
3134
3134
|
constructor(modelSpec) {
|
|
3135
|
+
this.modelSpec = modelSpec;
|
|
3135
3136
|
/** All inputs keyed by lookup name (lowercase variable name or alias). */
|
|
3136
3137
|
this.inputsByLookupName = /* @__PURE__ */ new Map();
|
|
3137
3138
|
/** All input ID aliases. */
|
|
@@ -3178,6 +3179,14 @@ var ModelInputs = class {
|
|
|
3178
3179
|
getInputVarForName(name) {
|
|
3179
3180
|
return this.inputsByLookupName.get(name.toLowerCase());
|
|
3180
3181
|
}
|
|
3182
|
+
/**
|
|
3183
|
+
* Return the `InputVar` that matches the requested variable ID.
|
|
3184
|
+
*
|
|
3185
|
+
* @param varId The variable identifier to match.
|
|
3186
|
+
*/
|
|
3187
|
+
getInputVarForVarId(varId) {
|
|
3188
|
+
return this.modelSpec.inputVars.get(varId);
|
|
3189
|
+
}
|
|
3181
3190
|
};
|
|
3182
3191
|
|
|
3183
3192
|
// src/comparison/config/resolve/comparison-scenario-specs.ts
|
|
@@ -3399,6 +3408,19 @@ function resolveScenariosFromSpec(modelInputsL, modelInputsR, scenarioSpec, genK
|
|
|
3399
3408
|
)
|
|
3400
3409
|
];
|
|
3401
3410
|
}
|
|
3411
|
+
case "scenario-with-setting-group": {
|
|
3412
|
+
return [
|
|
3413
|
+
resolveScenarioForSettingGroup(
|
|
3414
|
+
modelInputsL,
|
|
3415
|
+
modelInputsR,
|
|
3416
|
+
genKey(),
|
|
3417
|
+
scenarioSpec.id,
|
|
3418
|
+
scenarioSpec.title,
|
|
3419
|
+
scenarioSpec.subtitle,
|
|
3420
|
+
scenarioSpec.settingGroupId
|
|
3421
|
+
)
|
|
3422
|
+
];
|
|
3423
|
+
}
|
|
3402
3424
|
default:
|
|
3403
3425
|
(0, import_assert_never11.assertNever)(scenarioSpec);
|
|
3404
3426
|
}
|
|
@@ -3528,6 +3550,113 @@ function resolveScenarioForDistinctInputSpecs(modelInputsL, modelInputsR, key, i
|
|
|
3528
3550
|
specR
|
|
3529
3551
|
};
|
|
3530
3552
|
}
|
|
3553
|
+
function resolveScenarioForSettingGroup(modelInputsL, modelInputsR, key, id, title, subtitle, settingGroupId) {
|
|
3554
|
+
var _a, _b;
|
|
3555
|
+
function inputVarNameForVarId(modelInputs, varId) {
|
|
3556
|
+
const inputVar = modelInputs.getInputVarForVarId(varId);
|
|
3557
|
+
if (inputVar !== void 0) {
|
|
3558
|
+
return inputVar.varName;
|
|
3559
|
+
} else {
|
|
3560
|
+
return varId;
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
function inputPositionForPosition(position) {
|
|
3564
|
+
switch (position) {
|
|
3565
|
+
case "at-minimum":
|
|
3566
|
+
return "min";
|
|
3567
|
+
case "at-maximum":
|
|
3568
|
+
return "max";
|
|
3569
|
+
case "at-default":
|
|
3570
|
+
return "default";
|
|
3571
|
+
default:
|
|
3572
|
+
throw new Error(`Unknown input position: ${position}`);
|
|
3573
|
+
}
|
|
3574
|
+
}
|
|
3575
|
+
function inputSpecForSetting(modelInputs, inputSetting) {
|
|
3576
|
+
switch (inputSetting.kind) {
|
|
3577
|
+
case "position":
|
|
3578
|
+
return {
|
|
3579
|
+
kind: "input-at-position",
|
|
3580
|
+
inputName: inputVarNameForVarId(modelInputs, inputSetting.inputVarId),
|
|
3581
|
+
position: inputPositionForPosition(inputSetting.position)
|
|
3582
|
+
};
|
|
3583
|
+
case "value":
|
|
3584
|
+
return {
|
|
3585
|
+
kind: "input-at-value",
|
|
3586
|
+
inputName: inputVarNameForVarId(modelInputs, inputSetting.inputVarId),
|
|
3587
|
+
value: inputSetting.value
|
|
3588
|
+
};
|
|
3589
|
+
default:
|
|
3590
|
+
throw new Error(`Unknown input setting kind: ${inputSetting}`);
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
function inputSpecsForSettingGroup(modelInputs, inputSettings) {
|
|
3594
|
+
return inputSettings.map((inputSetting) => inputSpecForSetting(modelInputs, inputSetting));
|
|
3595
|
+
}
|
|
3596
|
+
const inputSettingsL = ((_a = modelInputsL.modelSpec.inputSettingGroups) == null ? void 0 : _a.get(settingGroupId)) || [];
|
|
3597
|
+
const inputSettingsR = ((_b = modelInputsR.modelSpec.inputSettingGroups) == null ? void 0 : _b.get(settingGroupId)) || [];
|
|
3598
|
+
const inputsL = inputSpecsForSettingGroup(modelInputsL, inputSettingsL);
|
|
3599
|
+
const inputsR = inputSpecsForSettingGroup(modelInputsR, inputSettingsR);
|
|
3600
|
+
const scenario = resolveScenarioForDistinctInputSpecs(
|
|
3601
|
+
modelInputsL,
|
|
3602
|
+
modelInputsR,
|
|
3603
|
+
key,
|
|
3604
|
+
id,
|
|
3605
|
+
title,
|
|
3606
|
+
subtitle,
|
|
3607
|
+
inputsL,
|
|
3608
|
+
inputsR
|
|
3609
|
+
);
|
|
3610
|
+
function scenarioString(scenario2) {
|
|
3611
|
+
if (scenario2.kind === "input-settings") {
|
|
3612
|
+
const settings = scenario2.settings.map((setting) => {
|
|
3613
|
+
switch (setting.kind) {
|
|
3614
|
+
case "position":
|
|
3615
|
+
return `${setting.inputVarId}=${setting.position}`;
|
|
3616
|
+
case "value":
|
|
3617
|
+
return `${setting.inputVarId}=${setting.value}`;
|
|
3618
|
+
default:
|
|
3619
|
+
throw new Error(`Unexpected input setting kind: ${setting}`);
|
|
3620
|
+
}
|
|
3621
|
+
});
|
|
3622
|
+
return settings.sort().join("__");
|
|
3623
|
+
} else {
|
|
3624
|
+
throw new Error(`Unexpected scenario spec kind: ${scenario2.kind}`);
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
function scenariosAreEqual(scenarioL, scenarioR) {
|
|
3628
|
+
return scenarioString(scenarioL) === scenarioString(scenarioR);
|
|
3629
|
+
}
|
|
3630
|
+
function errorState(inputSettings) {
|
|
3631
|
+
if (inputSettings.length === 0) {
|
|
3632
|
+
return { error: { kind: "unknown-input-setting-group" } };
|
|
3633
|
+
} else {
|
|
3634
|
+
return {};
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
if (inputSettingsL.length === 0 || inputSettingsR.length === 0) {
|
|
3638
|
+
if (scenario.settings.kind === "input-settings") {
|
|
3639
|
+
const errorSetting = {
|
|
3640
|
+
requestedName: settingGroupId,
|
|
3641
|
+
stateL: errorState(inputSettingsL),
|
|
3642
|
+
stateR: errorState(inputSettingsR)
|
|
3643
|
+
};
|
|
3644
|
+
scenario.settings.inputs.unshift(errorSetting);
|
|
3645
|
+
}
|
|
3646
|
+
if (inputSettingsL.length === 0) {
|
|
3647
|
+
scenario.specL = void 0;
|
|
3648
|
+
}
|
|
3649
|
+
if (inputSettingsR.length === 0) {
|
|
3650
|
+
scenario.specR = void 0;
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
if (scenario.settings.kind === "input-settings") {
|
|
3654
|
+
if (scenario.specL && scenario.specR && !scenariosAreEqual(scenario.specL, scenario.specR)) {
|
|
3655
|
+
scenario.settings.settingsDiffer = true;
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
return scenario;
|
|
3659
|
+
}
|
|
3531
3660
|
function resolveInputForName(modelInputsL, modelInputsR, inputName, at) {
|
|
3532
3661
|
return {
|
|
3533
3662
|
requestedName: inputName,
|