asma-core-helpers 0.32.0 → 0.34.0
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/lib/collaboration/applyOperation.d.ts +5 -13
- package/lib/collaboration/applyOperation.d.ts.map +1 -1
- package/lib/collaboration/applyOperation.js +450 -20
- package/lib/collaboration/applyOperation.js.map +1 -1
- package/lib/collaboration/operations.d.ts +113 -1
- package/lib/collaboration/operations.d.ts.map +1 -1
- package/lib/collaboration/operations.js +7 -0
- package/lib/collaboration/operations.js.map +1 -1
- package/lib/collaboration/schemas.d.ts +54 -0
- package/lib/collaboration/schemas.d.ts.map +1 -1
- package/lib/collaboration/schemas.js +74 -1
- package/lib/collaboration/schemas.js.map +1 -1
- package/lib/collaboration/templateDocument.d.ts +194 -0
- package/lib/collaboration/templateDocument.d.ts.map +1 -1
- package/lib/collaboration/templateDocument.js +104 -0
- package/lib/collaboration/templateDocument.js.map +1 -1
- package/lib/collaboration/testHelpers/documentGenerator.d.ts +24 -0
- package/lib/collaboration/testHelpers/documentGenerator.d.ts.map +1 -1
- package/lib/collaboration/testHelpers/documentGenerator.js +180 -2
- package/lib/collaboration/testHelpers/documentGenerator.js.map +1 -1
- package/lib/collaboration/typeContracts.d.ts +73 -1
- package/lib/collaboration/typeContracts.d.ts.map +1 -1
- package/lib/g-definitions.d.ts +17 -0
- package/lib/g-definitions.d.ts.map +1 -1
- package/lib/g-definitions.js +13 -0
- package/lib/g-definitions.js.map +1 -1
- package/lib/helpers/sectionPath.helpers.d.ts +64 -0
- package/lib/helpers/sectionPath.helpers.d.ts.map +1 -0
- package/lib/helpers/sectionPath.helpers.js +68 -0
- package/lib/helpers/sectionPath.helpers.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/collaboration/applyOperation.ts +517 -17
- package/src/collaboration/operations.ts +95 -0
- package/src/collaboration/property.test.ts +49 -0
- package/src/collaboration/schemas.ts +82 -0
- package/src/collaboration/templateDocument.ts +238 -1
- package/src/collaboration/testHelpers/documentGenerator.ts +201 -2
- package/src/collaboration/typeContracts.ts +106 -1
- package/src/collaboration/typedAuthoring.test.ts +1091 -0
- package/src/collaboration/typedAuthoringHardening.test.ts +344 -1
- package/src/g-definitions.ts +29 -0
- package/src/helpers/sectionPath.helpers.test.ts +159 -0
- package/src/helpers/sectionPath.helpers.ts +129 -0
- package/src/index.ts +1 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TemplateOp } from '../operations.js'
|
|
2
|
+
import { makeExpressionTargetToken } from '../templateDocument.js'
|
|
2
3
|
import { mulberry32, pick } from './seededRandom.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -16,13 +17,17 @@ import { mulberry32, pick } from './seededRandom.js'
|
|
|
16
17
|
|
|
17
18
|
export const DOCUMENT_ID = 'tpl-prop'
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
// `Chart` and `ExpressionQuestion` are here so the AC-9 operations can reach a SUCCESS path: every one
|
|
21
|
+
// of them requires an owner of one of those exact types, so a run without them would only ever exercise
|
|
22
|
+
// refusals and a broken reducer would look fine.
|
|
23
|
+
const QUESTION_TYPES_FOR_PROP = ['TextShort', 'DateField', 'RadioButtons', 'CheckBoxes', 'LinearScale', 'QuestionGrid', 'Chart', 'ExpressionQuestion'] as const
|
|
20
24
|
|
|
21
25
|
const NEW_QUESTION_ID = (n: number): string => `q-${n}`
|
|
22
26
|
const NEW_ROW_ID = (n: number): string => `r-${n}`
|
|
23
27
|
const NEW_ALT_ID = (n: number): string => `a-${n}`
|
|
24
28
|
const NEW_TAB_ID = (n: number): string => `t-${n}`
|
|
25
29
|
const NEW_ACTION_ID = (n: number): string => `x-${n}`
|
|
30
|
+
const NEW_LEGEND_ID = (n: number): string => `lg-${n}`
|
|
26
31
|
const NEW_NODE_ID = (n: number): string => `n-${n}`
|
|
27
32
|
const NEW_BINDING_ID = (n: number): string => `b-${n}`
|
|
28
33
|
const NEW_FILTER_ID = (n: number): string => `f-${n}`
|
|
@@ -38,11 +43,35 @@ type IdPools = {
|
|
|
38
43
|
columnOwnerById: Record<string, string>
|
|
39
44
|
gridRows: string[]
|
|
40
45
|
alternatives: string[]
|
|
46
|
+
/**
|
|
47
|
+
* Which question each alternative hangs off.
|
|
48
|
+
*
|
|
49
|
+
* Needed because the Chart and Expression operations require an alternative owned by that exact
|
|
50
|
+
* question: picking from the flat `alternatives` pool made every generated assignment a
|
|
51
|
+
* wrong-owner refusal, so the reducer's success path was never reached at all.
|
|
52
|
+
*/
|
|
53
|
+
alternativeOwnerById: Record<string, string>
|
|
41
54
|
tabs: string[]
|
|
42
55
|
actions: string[]
|
|
43
56
|
nodes: string[]
|
|
44
57
|
bindings: string[]
|
|
45
58
|
filters: string[]
|
|
59
|
+
charts: string[]
|
|
60
|
+
/**
|
|
61
|
+
* Charts whose `chart.type` is already `radar`.
|
|
62
|
+
*
|
|
63
|
+
* Tracked because the AC-9 Chart chain is five deep — create a Chart, set radar, create a legend,
|
|
64
|
+
* create an alternative on that Chart, flag a target — and each step gates the next. Choosing
|
|
65
|
+
* uniformly at each step made the whole chain vanishingly rare, so the reducer's success paths were
|
|
66
|
+
* never reached and the property run proved nothing about them.
|
|
67
|
+
*/
|
|
68
|
+
radarCharts: string[]
|
|
69
|
+
expressionQuestions: string[]
|
|
70
|
+
/** Chart legend ids, and the Chart each belongs to — an assignment must cite its owner's legend. */
|
|
71
|
+
chartLegends: string[]
|
|
72
|
+
chartLegendOwnerById: Record<string, string>
|
|
73
|
+
/** Questions carrying `flags.is_expression`, i.e. the ones legal as a formula/assignment target. */
|
|
74
|
+
expressionTargets: string[]
|
|
46
75
|
visibilityRules: string[]
|
|
47
76
|
highlightRules: string[]
|
|
48
77
|
narrativeRules: string[]
|
|
@@ -56,11 +85,18 @@ const emptyPools = (): IdPools => ({
|
|
|
56
85
|
columnOwnerById: {},
|
|
57
86
|
gridRows: [],
|
|
58
87
|
alternatives: [],
|
|
88
|
+
alternativeOwnerById: {},
|
|
59
89
|
tabs: [],
|
|
60
90
|
actions: [],
|
|
61
91
|
nodes: [],
|
|
62
92
|
bindings: [],
|
|
63
93
|
filters: [],
|
|
94
|
+
charts: [],
|
|
95
|
+
radarCharts: [],
|
|
96
|
+
expressionQuestions: [],
|
|
97
|
+
chartLegends: [],
|
|
98
|
+
chartLegendOwnerById: {},
|
|
99
|
+
expressionTargets: [],
|
|
64
100
|
visibilityRules: [],
|
|
65
101
|
highlightRules: [],
|
|
66
102
|
narrativeRules: [],
|
|
@@ -90,6 +126,12 @@ const fieldValue = (field: 'label' | 'required' | 'scale.from' | 'grid.singleRow
|
|
|
90
126
|
|
|
91
127
|
const maybe = (random: () => number, probability: number): boolean => random() < probability
|
|
92
128
|
|
|
129
|
+
/** An alternative the given question actually owns, or a ghost id so the refusal path is reached. */
|
|
130
|
+
const ownedAlternative = (random: () => number, pools: IdPools, ownerId: string): string => {
|
|
131
|
+
const owned = pools.alternatives.filter((id) => pools.alternativeOwnerById[id] === ownerId)
|
|
132
|
+
return owned.length > 0 ? pick(random, owned) : 'a-ghost'
|
|
133
|
+
}
|
|
134
|
+
|
|
93
135
|
export type GeneratedSequence = {
|
|
94
136
|
ops: TemplateOp[]
|
|
95
137
|
/** Whether each op was applied (false = the reducer rejected it — expected conflicts). */
|
|
@@ -211,7 +253,7 @@ const nextOp = (random: () => number, pools: IdPools): TemplateOp => {
|
|
|
211
253
|
|
|
212
254
|
/** Operations added by ASMA-7676, kept in a dedicated mix so every seeded run exercises them. */
|
|
213
255
|
const nextAddedContractOp = (random: () => number, pools: IdPools): TemplateOp => {
|
|
214
|
-
const choice = Math.floor(random() *
|
|
256
|
+
const choice = Math.floor(random() * 25)
|
|
215
257
|
const columnQuestionId = pickOrFallback(random, pools.columns, 'c-ghost')
|
|
216
258
|
const ownerQuestionId = pools.columnOwnerById[columnQuestionId] ?? pickOrFallback(random, pools.grids, 'g-ghost')
|
|
217
259
|
const questionId = idOrNew(random, pools.questions, NEW_QUESTION_ID)
|
|
@@ -334,6 +376,128 @@ const nextAddedContractOp = (random: () => number, pools: IdPools): TemplateOp =
|
|
|
334
376
|
questionId: columnQuestionId,
|
|
335
377
|
metadata: maybe(random, 0.3) ? null : maybe(random, 0.5) ? { all: true } : { from: 'a', to: 'b' },
|
|
336
378
|
}
|
|
379
|
+
// ── ASMA-7683 combined post-v0.31 repair: tab membership, legacy override, AC-9. ──
|
|
380
|
+
case 16:
|
|
381
|
+
return {
|
|
382
|
+
type: 'tab.setQuestion',
|
|
383
|
+
tabId: pickOrFallback(random, pools.tabs, 't-ghost'),
|
|
384
|
+
questionId: pickOrFallback(random, pools.questions, 'q-ghost'),
|
|
385
|
+
include: maybe(random, 0.7),
|
|
386
|
+
...(maybe(random, 0.5) ? { atIndex: Math.floor(random() * 3) } : {}),
|
|
387
|
+
}
|
|
388
|
+
case 17:
|
|
389
|
+
return {
|
|
390
|
+
type: 'tab.setRowCountQuestion',
|
|
391
|
+
tabId: pickOrFallback(random, pools.tabs, 't-ghost'),
|
|
392
|
+
// Grids reach the success path; any question reaches the not-a-grid refusal.
|
|
393
|
+
questionId: maybe(random, 0.6)
|
|
394
|
+
? pickOrFallback(random, pools.grids, 'g-ghost')
|
|
395
|
+
: pickOrFallback(random, pools.questions, 'q-ghost'),
|
|
396
|
+
include: maybe(random, 0.7),
|
|
397
|
+
...(maybe(random, 0.5) ? { atIndex: Math.floor(random() * 3) } : {}),
|
|
398
|
+
}
|
|
399
|
+
case 18:
|
|
400
|
+
return {
|
|
401
|
+
type: 'mappingBinding.setLegacyOverride',
|
|
402
|
+
bindingId: pickOrFallback(random, pools.bindings, 'b-ghost'),
|
|
403
|
+
legacyOverride: maybe(random, 0.3)
|
|
404
|
+
? null
|
|
405
|
+
: maybe(random, 0.5)
|
|
406
|
+
? { planId: `Actor.Felt${Math.floor(random() * 4)}` }
|
|
407
|
+
: { kind: 'connector', mappingRule: `rule-${Math.floor(random() * 3)}` },
|
|
408
|
+
}
|
|
409
|
+
// Enabling writes: the AC-9 operations require `chart.type: 'radar'` and
|
|
410
|
+
// `flags.is_expression: true`, so a run that never sets them could only ever refuse.
|
|
411
|
+
case 19: {
|
|
412
|
+
// Advances the Chart chain by one step rather than re-rolling a step already taken. Each
|
|
413
|
+
// step gates the next, so choosing uniformly among them left the far end (a legend that
|
|
414
|
+
// exists long enough to be deleted) effectively unreachable in a seeded run.
|
|
415
|
+
const pending = pools.charts.filter((id) => !pools.radarCharts.includes(id))
|
|
416
|
+
if (pending.length > 0) {
|
|
417
|
+
return {
|
|
418
|
+
type: 'question.updateField',
|
|
419
|
+
questionId: pick(random, pending),
|
|
420
|
+
// A `pie` occasionally, so the not-radar refusal is reached too.
|
|
421
|
+
field: 'chart.type',
|
|
422
|
+
value: maybe(random, 0.85) ? 'radar' : 'pie',
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return {
|
|
426
|
+
type: 'chartLegend.create',
|
|
427
|
+
questionId: pickOrFallback(random, pools.radarCharts, 'q-ghost'),
|
|
428
|
+
legendId: NEW_LEGEND_ID(pools.chartLegends.length),
|
|
429
|
+
label: `Legend ${pools.chartLegends.length}`,
|
|
430
|
+
...(maybe(random, 0.4) ? { atIndex: Math.floor(random() * 3) } : {}),
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
case 20:
|
|
434
|
+
return {
|
|
435
|
+
type: 'question.updateField',
|
|
436
|
+
questionId: pickOrFallback(random, pools.questions, 'q-ghost'),
|
|
437
|
+
field: 'flags.is_expression',
|
|
438
|
+
value: true,
|
|
439
|
+
}
|
|
440
|
+
case 21:
|
|
441
|
+
return {
|
|
442
|
+
type: 'chartLegend.create',
|
|
443
|
+
// Radar charts reach the success path; a plain Chart reaches the not-radar refusal.
|
|
444
|
+
questionId: maybe(random, 0.8)
|
|
445
|
+
? pickOrFallback(random, pools.radarCharts, 'q-ghost')
|
|
446
|
+
: pickOrFallback(random, pools.charts, 'q-ghost'),
|
|
447
|
+
legendId: NEW_LEGEND_ID(pools.chartLegends.length),
|
|
448
|
+
label: `Legend ${pools.chartLegends.length}`,
|
|
449
|
+
...(maybe(random, 0.4) ? { atIndex: Math.floor(random() * 3) } : {}),
|
|
450
|
+
}
|
|
451
|
+
case 22: {
|
|
452
|
+
const chartId = maybe(random, 0.85)
|
|
453
|
+
? pickOrFallback(random, pools.radarCharts, 'q-ghost')
|
|
454
|
+
: pickOrFallback(random, pools.charts, 'q-ghost')
|
|
455
|
+
// Scoped to this Chart's OWN legends. Picking from the global pool made almost every
|
|
456
|
+
// generated delete a wrong-owner refusal, so the cascade was never exercised.
|
|
457
|
+
const ownLegends = pools.chartLegends.filter((id) => pools.chartLegendOwnerById[id] === chartId)
|
|
458
|
+
if (maybe(random, 0.3)) {
|
|
459
|
+
return {
|
|
460
|
+
type: 'chartLegend.delete',
|
|
461
|
+
questionId: chartId,
|
|
462
|
+
legendId: ownLegends.length > 0 ? pick(random, ownLegends) : 'lg-ghost',
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
// An assignment needs the Chart, an alternative that Chart owns, one of ITS legends, and a
|
|
466
|
+
// flagged target. Anything less is a refusal, so all four are lined up here on purpose.
|
|
467
|
+
return {
|
|
468
|
+
type: 'alternative.setChartLegend',
|
|
469
|
+
questionId: chartId,
|
|
470
|
+
alternativeId: ownedAlternative(random, pools, chartId),
|
|
471
|
+
chartLegend: maybe(random, 0.25)
|
|
472
|
+
? null
|
|
473
|
+
: {
|
|
474
|
+
id: ownLegends.length > 0 ? pick(random, ownLegends) : 'lg-ghost',
|
|
475
|
+
questionIdMap: pickOrFallback(random, pools.expressionTargets, 'q-ghost'),
|
|
476
|
+
},
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
case 23: {
|
|
480
|
+
const targets = pools.expressionTargets.slice(0, 1 + Math.floor(random() * 2))
|
|
481
|
+
const expressionQuestionId = pickOrFallback(random, pools.expressionQuestions, 'q-ghost')
|
|
482
|
+
return {
|
|
483
|
+
type: 'alternative.setExpressionFormula',
|
|
484
|
+
questionId: expressionQuestionId,
|
|
485
|
+
alternativeId: ownedAlternative(random, pools, expressionQuestionId),
|
|
486
|
+
value: targets.map((id) => makeExpressionTargetToken(id)).join(' + ') || '0',
|
|
487
|
+
expressionTargets: targets,
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
// Alternatives on a Chart / ExpressionQuestion owner, which the general mix creates only by
|
|
491
|
+
// accident — without them the two operations above can only ever refuse.
|
|
492
|
+
case 24:
|
|
493
|
+
return {
|
|
494
|
+
type: 'alternative.create',
|
|
495
|
+
questionId: maybe(random, 0.5)
|
|
496
|
+
? pickOrFallback(random, pools.radarCharts, 'q-ghost')
|
|
497
|
+
: pickOrFallback(random, pools.expressionQuestions, 'q-ghost'),
|
|
498
|
+
alternativeId: NEW_ALT_ID(pools.alternatives.length),
|
|
499
|
+
label: 'Alt',
|
|
500
|
+
}
|
|
337
501
|
default:
|
|
338
502
|
return {
|
|
339
503
|
type: 'gridColumn.setLayout',
|
|
@@ -356,11 +520,23 @@ const updatePools = (op: TemplateOp, ok: boolean, pools: IdPools): void => {
|
|
|
356
520
|
case 'question.create':
|
|
357
521
|
pools.questions.push(op.questionId)
|
|
358
522
|
if (op.questionType === 'QuestionGrid') pools.grids.push(op.questionId)
|
|
523
|
+
if (op.questionType === 'Chart') pools.charts.push(op.questionId)
|
|
524
|
+
if (op.questionType === 'ExpressionQuestion') pools.expressionQuestions.push(op.questionId)
|
|
359
525
|
break
|
|
360
526
|
case 'question.delete':
|
|
361
527
|
pools.questions = pools.questions.filter((id) => id !== op.questionId)
|
|
362
528
|
pools.grids = pools.grids.filter((id) => id !== op.questionId)
|
|
363
529
|
pools.columns = pools.columns.filter((id) => id !== op.questionId)
|
|
530
|
+
pools.charts = pools.charts.filter((id) => id !== op.questionId)
|
|
531
|
+
pools.radarCharts = pools.radarCharts.filter((id) => id !== op.questionId)
|
|
532
|
+
pools.expressionQuestions = pools.expressionQuestions.filter((id) => id !== op.questionId)
|
|
533
|
+
pools.expressionTargets = pools.expressionTargets.filter((id) => id !== op.questionId)
|
|
534
|
+
// A deleted Chart takes its legends out of the pool with it, or a later assignment would
|
|
535
|
+
// cite a legend whose owner no longer exists and could never reach a success path.
|
|
536
|
+
pools.chartLegends = pools.chartLegends.filter((id) => pools.chartLegendOwnerById[id] !== op.questionId)
|
|
537
|
+
for (const [legendId, owner] of Object.entries(pools.chartLegendOwnerById)) {
|
|
538
|
+
if (owner === op.questionId) delete pools.chartLegendOwnerById[legendId]
|
|
539
|
+
}
|
|
364
540
|
delete pools.columnOwnerById[op.questionId]
|
|
365
541
|
break
|
|
366
542
|
case 'gridColumn.create':
|
|
@@ -373,10 +549,33 @@ const updatePools = (op: TemplateOp, ok: boolean, pools: IdPools): void => {
|
|
|
373
549
|
break
|
|
374
550
|
case 'alternative.create':
|
|
375
551
|
pools.alternatives.push(op.alternativeId)
|
|
552
|
+
pools.alternativeOwnerById[op.alternativeId] = op.questionId
|
|
553
|
+
break
|
|
554
|
+
case 'alternative.delete':
|
|
555
|
+
pools.alternatives = pools.alternatives.filter((id) => id !== op.alternativeId)
|
|
556
|
+
delete pools.alternativeOwnerById[op.alternativeId]
|
|
376
557
|
break
|
|
377
558
|
case 'tab.create':
|
|
378
559
|
pools.tabs.push(op.tabId)
|
|
379
560
|
break
|
|
561
|
+
case 'question.updateField':
|
|
562
|
+
// Track the enabling writes, so a later target/legend choice can reach a success path.
|
|
563
|
+
if (op.field === 'flags.is_expression' && op.value === true && !pools.expressionTargets.includes(op.questionId)) {
|
|
564
|
+
pools.expressionTargets.push(op.questionId)
|
|
565
|
+
}
|
|
566
|
+
if (op.field === 'chart.type') {
|
|
567
|
+
pools.radarCharts = pools.radarCharts.filter((id) => id !== op.questionId)
|
|
568
|
+
if (op.value === 'radar') pools.radarCharts.push(op.questionId)
|
|
569
|
+
}
|
|
570
|
+
break
|
|
571
|
+
case 'chartLegend.create':
|
|
572
|
+
pools.chartLegends.push(op.legendId)
|
|
573
|
+
pools.chartLegendOwnerById[op.legendId] = op.questionId
|
|
574
|
+
break
|
|
575
|
+
case 'chartLegend.delete':
|
|
576
|
+
pools.chartLegends = pools.chartLegends.filter((id) => id !== op.legendId)
|
|
577
|
+
delete pools.chartLegendOwnerById[op.legendId]
|
|
578
|
+
break
|
|
380
579
|
case 'action.create':
|
|
381
580
|
pools.actions.push(op.actionId)
|
|
382
581
|
break
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { TemplateOp } from './operations.js'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
ActionMetadata,
|
|
4
|
+
AlternativeChartLegend,
|
|
5
|
+
LegacyBindingOverride,
|
|
6
|
+
MappingBinding,
|
|
7
|
+
} from './templateDocument.js'
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* Compile-time assertions that the closed unions stay closed.
|
|
@@ -55,3 +60,103 @@ export type ActionMetadataAcceptsLegalShapes = Assert<
|
|
|
55
60
|
: false
|
|
56
61
|
: false
|
|
57
62
|
>
|
|
63
|
+
|
|
64
|
+
// ─── LegacyBindingOverride requires at least one member ───
|
|
65
|
+
// A bare `{}` is an exception recording nothing, and under DOC-LAW-2 it is also a second encoding of
|
|
66
|
+
// "absent". The three arms are what make that unrepresentable rather than merely refused at runtime:
|
|
67
|
+
// one optional-everything type would type-check the empty record and leave the parser as the only guard.
|
|
68
|
+
export type LegacyOverrideRefusesEmpty = Assert<Refuses<Record<string, never>, LegacyBindingOverride>>
|
|
69
|
+
|
|
70
|
+
/** Each single member, and the all-member record, must stay legal or the assertion above proves nothing. */
|
|
71
|
+
export type LegacyOverrideAcceptsLegalShapes = Assert<
|
|
72
|
+
Refuses<{ planId: string }, LegacyBindingOverride> extends false
|
|
73
|
+
? Refuses<{ kind: string }, LegacyBindingOverride> extends false
|
|
74
|
+
? Refuses<{ mappingRule: string }, LegacyBindingOverride> extends false
|
|
75
|
+
? Refuses<{ planId: string; kind: string; mappingRule: string }, LegacyBindingOverride> extends false
|
|
76
|
+
? true
|
|
77
|
+
: false
|
|
78
|
+
: false
|
|
79
|
+
: false
|
|
80
|
+
: false
|
|
81
|
+
>
|
|
82
|
+
|
|
83
|
+
// ─── the Chart assignment payload carries no label ───
|
|
84
|
+
// The reducer derives `label` from the owning legend. A client-supplied one would let a single legend id
|
|
85
|
+
// carry two labels across two alternatives — two `document_hash` values for one authored state — so the
|
|
86
|
+
// operation payload must not even be able to express it.
|
|
87
|
+
export type SetChartLegendRefusesClientLabel = Assert<
|
|
88
|
+
Refuses<
|
|
89
|
+
{
|
|
90
|
+
type: 'alternative.setChartLegend'
|
|
91
|
+
questionId: string
|
|
92
|
+
alternativeId: string
|
|
93
|
+
chartLegend: { id: string; questionIdMap: string; label: string }
|
|
94
|
+
},
|
|
95
|
+
TemplateOp
|
|
96
|
+
>
|
|
97
|
+
>
|
|
98
|
+
|
|
99
|
+
/** The label-free selection, and the `null` clear, must both stay legal. */
|
|
100
|
+
export type SetChartLegendAcceptsSelectionAndNull = Assert<
|
|
101
|
+
Refuses<
|
|
102
|
+
{
|
|
103
|
+
type: 'alternative.setChartLegend'
|
|
104
|
+
questionId: string
|
|
105
|
+
alternativeId: string
|
|
106
|
+
chartLegend: { id: string; questionIdMap: string }
|
|
107
|
+
},
|
|
108
|
+
TemplateOp
|
|
109
|
+
> extends false
|
|
110
|
+
? Refuses<
|
|
111
|
+
{ type: 'alternative.setChartLegend'; questionId: string; alternativeId: string; chartLegend: null },
|
|
112
|
+
TemplateOp
|
|
113
|
+
> extends false
|
|
114
|
+
? true
|
|
115
|
+
: false
|
|
116
|
+
: false
|
|
117
|
+
>
|
|
118
|
+
|
|
119
|
+
/** The STORED assignment does carry the derived label — the payload and the record are different types. */
|
|
120
|
+
export type StoredChartLegendCarriesLabel = Assert<
|
|
121
|
+
Refuses<{ id: string; questionIdMap: string }, AlternativeChartLegend>
|
|
122
|
+
>
|
|
123
|
+
|
|
124
|
+
// ─── the Expression formula is one operation, not two field writes ───
|
|
125
|
+
// Splitting the formula from its target list is the mutation this refusal exists to catch: an op arm
|
|
126
|
+
// missing `expressionTargets` must not type-check, or a caller could land the text and lose the list.
|
|
127
|
+
export type SetExpressionFormulaRequiresTargets = Assert<
|
|
128
|
+
Refuses<
|
|
129
|
+
{ type: 'alternative.setExpressionFormula'; questionId: string; alternativeId: string; value: string },
|
|
130
|
+
TemplateOp
|
|
131
|
+
>
|
|
132
|
+
>
|
|
133
|
+
|
|
134
|
+
// ─── the released document member stays `unknown` on read ───
|
|
135
|
+
/**
|
|
136
|
+
* `MappingBinding.legacyOverride` must NOT be narrowed to the closed canonical union.
|
|
137
|
+
*
|
|
138
|
+
* Nothing else can catch this. Narrowing it is a type-only change, so every runtime gate stays green:
|
|
139
|
+
* the open `[key: string]: unknown` index keeps the narrowed member assignable, the reducer writes
|
|
140
|
+
* through a `Record<string, unknown>` cast, and `parseLegacyBindingOverride` takes `unknown`, so no call
|
|
141
|
+
* site objects. `ts:check`, `pnpm test` and `pnpm test:package` all pass with the member narrowed.
|
|
142
|
+
*
|
|
143
|
+
* The consequence is consumer-visible and is exactly what ADR-0008 DEC-006 forbids: with the member
|
|
144
|
+
* narrowed, a consumer may write `binding.legacyOverride?.planId` with no compile error against a
|
|
145
|
+
* document carrying an arbitrary historical value. History would *appear* canonical, and BunJS
|
|
146
|
+
* publication would lose its reason to call the parser at all.
|
|
147
|
+
*
|
|
148
|
+
* Asserting the member REFUSES the canonical union is the pin: `unknown` is not assignable to
|
|
149
|
+
* `LegacyBindingOverride | undefined`, so this holds at head and fails the moment the member is
|
|
150
|
+
* narrowed to it.
|
|
151
|
+
*/
|
|
152
|
+
export type LegacyOverrideMemberStaysUnknown = Assert<
|
|
153
|
+
Refuses<MappingBinding['legacyOverride'], LegacyBindingOverride | undefined>
|
|
154
|
+
>
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The other half, so the assertion above cannot pass by the member having become something unrelated:
|
|
158
|
+
* a canonical value must still be assignable *into* the member.
|
|
159
|
+
*/
|
|
160
|
+
export type LegacyOverrideMemberAcceptsCanonical = Assert<
|
|
161
|
+
Refuses<LegacyBindingOverride, MappingBinding['legacyOverride']> extends false ? true : false
|
|
162
|
+
>
|