@sdeverywhere/plugin-check 0.3.29 → 0.3.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdeverywhere/plugin-check",
3
- "version": "0.3.29",
3
+ "version": "0.3.31",
4
4
  "files": [
5
5
  "bin/**",
6
6
  "dist/**",
@@ -25,8 +25,8 @@
25
25
  "dependencies": {
26
26
  "@rollup/plugin-node-resolve": "^16.0.3",
27
27
  "@rollup/plugin-replace": "^6.0.3",
28
- "@sdeverywhere/check-core": "^0.1.8",
29
- "@sdeverywhere/check-ui-shell": "^0.2.20",
28
+ "@sdeverywhere/check-core": "^0.1.10",
29
+ "@sdeverywhere/check-ui-shell": "^0.2.22",
30
30
  "@sdeverywhere/runtime": "^0.2.8",
31
31
  "@sdeverywhere/runtime-async": "^0.2.8",
32
32
  "assert-never": "^1.2.1",
@@ -2,11 +2,9 @@
2
2
 
3
3
  import type {
4
4
  Bundle,
5
- BundleGraphData,
6
5
  BundleModel as CheckBundleModel,
7
6
  DatasetKey,
8
7
  DatasetsResult,
9
- LinkItem,
10
8
  ModelSpec,
11
9
  ScenarioSpec
12
10
  } from '@sdeverywhere/check-core'
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { assertNever } from 'assert-never'
4
4
 
5
- import type { InputVar, ScenarioSpec } from '@sdeverywhere/check-core'
5
+ import type { ScenarioSpec, SliderInputVar } from '@sdeverywhere/check-core'
6
6
  import type { InputValue, InputVarId } from '@sdeverywhere/runtime'
7
7
  import { createInputValue } from '@sdeverywhere/runtime'
8
8
 
@@ -28,7 +28,15 @@ export interface InputSpec {
28
28
  maxValue: number
29
29
  }
30
30
 
31
- export interface Input extends InputVar {
31
+ // TODO: For now we always treat each input as a slider, because the `InputSpec`
32
+ // type in the `@sdeverywhere/build` package only carries slider-style fields
33
+ // (defaultValue/minValue/maxValue) and doesn't distinguish sliders from
34
+ // switches. In practice, plugin-config-driven builds map a switch's
35
+ // `offValue`/`onValue` onto `minValue`/`maxValue` here, so things work well
36
+ // enough through the model-check pipeline, but it's not ideal. Developers can
37
+ // implement their own bundle (rather than using this template) if they need to
38
+ // expose true switch inputs.
39
+ export type Input = SliderInputVar & {
32
40
  value: InputValue
33
41
  }
34
42
 
@@ -39,7 +47,11 @@ export function getInputVars(inputSpecs: InputSpec[]): Map<InputVarId, Input> {
39
47
  const inputs: Map<InputVarId, Input> = new Map()
40
48
  for (const inputSpec of inputSpecs) {
41
49
  const varId = inputSpec.varId
50
+ // TODO: We always construct a slider-kind input here; see the note on the
51
+ // `Input` type above. Switches reach this point with their off/on values
52
+ // already mapped onto `minValue`/`maxValue`.
42
53
  const input: Input = {
54
+ kind: 'slider',
43
55
  inputId: inputSpec.inputId,
44
56
  varId,
45
57
  varName: inputSpec.varName,
@@ -113,6 +113,18 @@ function createBaseComparisonSpecs(bundleL: Bundle, bundleR: Bundle): Comparison
113
113
  addInputs(bundleL, inputsByIdL)
114
114
  addInputs(bundleR, inputsByIdR)
115
115
 
116
+ // Get the value of an input at the requested matrix position. For sliders,
117
+ // this is `minValue`/`maxValue`; for switches, this is `offValue`/`onValue`
118
+ // (matching the convention used by check-core's position resolution).
119
+ const valueAtPos = (iv: InputVar, position: 'min' | 'max'): number => {
120
+ switch (iv.kind) {
121
+ case 'slider':
122
+ return position === 'min' ? iv.minValue : iv.maxValue
123
+ case 'switch':
124
+ return position === 'min' ? iv.offValue : iv.onValue
125
+ }
126
+ }
127
+
116
128
  // Create an "all inputs at default" scenario
117
129
  const scenarios: ComparisonScenarioSpec[] = []
118
130
  scenarios.push({
@@ -131,16 +143,12 @@ function createBaseComparisonSpecs(bundleL: Bundle, bundleR: Bundle): Comparison
131
143
  return
132
144
  }
133
145
 
134
- // Don't add a scenario if the input's min or max is equal to its default (this is already
135
- // covered by the `all_inputs_at_default` scenario from above)
136
- if (position === 'min') {
137
- if (inputL.minValue === inputL.defaultValue && inputR.minValue === inputR.defaultValue) {
138
- return
139
- }
140
- } else {
141
- if (inputL.maxValue === inputL.defaultValue && inputR.maxValue === inputR.defaultValue) {
142
- return
143
- }
146
+ // Don't add a scenario if the input's value at the requested position is equal to its default
147
+ // value (this is already covered by the `all_inputs_at_default` scenario from above)
148
+ const valL = valueAtPos(inputL, position)
149
+ const valR = valueAtPos(inputR, position)
150
+ if (valL === inputL.defaultValue && valR === inputR.defaultValue) {
151
+ return
144
152
  }
145
153
 
146
154
  // Derive the scenario name from the related slider name (or if not defined, the variable name)