asma-core-helpers 0.38.0 → 0.40.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.map +1 -1
- package/lib/collaboration/applyOperation.js +194 -0
- package/lib/collaboration/applyOperation.js.map +1 -1
- package/lib/collaboration/index.d.ts +1 -0
- package/lib/collaboration/index.d.ts.map +1 -1
- package/lib/collaboration/index.js +1 -0
- package/lib/collaboration/index.js.map +1 -1
- package/lib/collaboration/operations.d.ts +98 -0
- package/lib/collaboration/operations.d.ts.map +1 -1
- package/lib/collaboration/operations.js +4 -0
- package/lib/collaboration/operations.js.map +1 -1
- package/lib/collaboration/schemas.d.ts +138 -0
- package/lib/collaboration/schemas.d.ts.map +1 -1
- package/lib/collaboration/schemas.js +198 -10
- package/lib/collaboration/schemas.js.map +1 -1
- package/lib/collaboration/templateAuthoringMeta.d.ts +424 -0
- package/lib/collaboration/templateAuthoringMeta.d.ts.map +1 -0
- package/lib/collaboration/templateAuthoringMeta.js +726 -0
- package/lib/collaboration/templateAuthoringMeta.js.map +1 -0
- package/lib/collaboration/templateDocument.d.ts +136 -14
- package/lib/collaboration/templateDocument.d.ts.map +1 -1
- package/lib/collaboration/templateDocument.js +19 -0
- package/lib/collaboration/templateDocument.js.map +1 -1
- package/lib/collaboration/testHelpers/documentGenerator.d.ts.map +1 -1
- package/lib/collaboration/testHelpers/documentGenerator.js +53 -0
- package/lib/collaboration/testHelpers/documentGenerator.js.map +1 -1
- package/lib/collaboration/typeContracts.d.ts +139 -0
- package/lib/collaboration/typeContracts.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/collaboration/applyOperation.ts +251 -0
- package/src/collaboration/index.ts +1 -0
- package/src/collaboration/operations.ts +100 -0
- package/src/collaboration/property.test.ts +56 -1
- package/src/collaboration/schemas.test.ts +172 -1
- package/src/collaboration/schemas.ts +214 -9
- package/src/collaboration/templateAuthoringMeta.test.ts +1286 -0
- package/src/collaboration/templateAuthoringMeta.ts +1098 -0
- package/src/collaboration/templateDocument.ts +139 -14
- package/src/collaboration/testHelpers/documentGenerator.ts +60 -0
- package/src/collaboration/typeContracts.ts +155 -0
|
@@ -8,9 +8,11 @@ import { findDocLawViolations } from './docLaws.js'
|
|
|
8
8
|
import {
|
|
9
9
|
findDuplicateBindingTargets,
|
|
10
10
|
findQuestionOwnershipViolations,
|
|
11
|
+
templateAuthoringIsDefault,
|
|
11
12
|
templateDocumentIsDefault,
|
|
12
13
|
validateTemplateDocument,
|
|
13
14
|
} from './schemas.js'
|
|
15
|
+
import { resolveTemplateAuthoringMeta } from './templateAuthoringMeta.js'
|
|
14
16
|
import { emptyTemplateDocument } from './templateDocument.js'
|
|
15
17
|
import { generateOpSequence, DOCUMENT_ID } from './testHelpers/documentGenerator.js'
|
|
16
18
|
import { mulberry32, shuffleKeys } from './testHelpers/seededRandom.js'
|
|
@@ -138,7 +140,12 @@ describe('the combined repair operations are reached by the property run', () =>
|
|
|
138
140
|
|
|
139
141
|
// More seeds than the invariant suite uses: each op needs its own preconditions to line up
|
|
140
142
|
// (a radar Chart, a flagged target, an existing legend), which no single short run reaches.
|
|
141
|
-
|
|
143
|
+
//
|
|
144
|
+
// Seeds 8 and 23 joined the list when ASMA-8339 added a metadata branch to the generator: a new
|
|
145
|
+
// branch shifts every seeded stream, and `alternative.setChartLegend` lost the one run where its
|
|
146
|
+
// three preconditions happened to coincide. Widening the seed list is the honest repair —
|
|
147
|
+
// weakening the assertion to "generated" would leave a broken reducer looking fine.
|
|
148
|
+
for (const seed of [4, 7, 8, 13, 23, 99, 101, 202, 303, 404]) {
|
|
142
149
|
const { generated } = runSequence(seed, 400)
|
|
143
150
|
generated.ops.forEach((op, index) => {
|
|
144
151
|
if (!(NEW_OP_TYPES as readonly string[]).includes(op.type)) return
|
|
@@ -160,6 +167,54 @@ describe('the combined repair operations are reached by the property run', () =>
|
|
|
160
167
|
})
|
|
161
168
|
})
|
|
162
169
|
|
|
170
|
+
/**
|
|
171
|
+
* ASMA-8339's four typed metadata/settings arms must be *exercised* by the seeded runs, not merely
|
|
172
|
+
* listed in the generator.
|
|
173
|
+
*
|
|
174
|
+
* Acceptance only, deliberately: from a schema-valid payload against a schema-valid document these
|
|
175
|
+
* arms have no reachable reducer refusal, because their closure lives in the correlated types and the
|
|
176
|
+
* wire schema. Asserting a refusal here would therefore need a deliberately invalid op, which belongs
|
|
177
|
+
* in `templateAuthoringMeta.test.ts` — and would quietly break the generator's own rule that every
|
|
178
|
+
* generated op is schema-valid.
|
|
179
|
+
*/
|
|
180
|
+
describe('the metadata/settings operations are reached by the property run', () => {
|
|
181
|
+
const METADATA_OP_TYPES = [
|
|
182
|
+
'template.setMetaFieldTyped',
|
|
183
|
+
'template.setSettingTyped',
|
|
184
|
+
'template.addCompatibilityId',
|
|
185
|
+
'template.removeCompatibilityId',
|
|
186
|
+
] as const
|
|
187
|
+
|
|
188
|
+
it('applies each metadata operation successfully across the seeded runs', () => {
|
|
189
|
+
const accepted = new Map<string, number>()
|
|
190
|
+
|
|
191
|
+
for (const seed of [4, 7, 13, 99]) {
|
|
192
|
+
const { generated } = runSequence(seed, 400)
|
|
193
|
+
generated.ops.forEach((op, index) => {
|
|
194
|
+
if (!(METADATA_OP_TYPES as readonly string[]).includes(op.type)) return
|
|
195
|
+
if (generated.outcomes[index] === true) accepted.set(op.type, (accepted.get(op.type) ?? 0) + 1)
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
assert.deepEqual(
|
|
200
|
+
METADATA_OP_TYPES.filter((type) => (accepted.get(type) ?? 0) === 0),
|
|
201
|
+
[],
|
|
202
|
+
`never applied successfully: ${JSON.stringify([...accepted])}`,
|
|
203
|
+
)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('leaves the metadata the runs produced law-clean and readable', () => {
|
|
207
|
+
for (const seed of [4, 7, 13, 99]) {
|
|
208
|
+
const { doc } = runSequence(seed, 400)
|
|
209
|
+
const reduced = reduceToMinimalForm(doc, { isDefault: templateAuthoringIsDefault })
|
|
210
|
+
assert.deepEqual(findDocLawViolations(reduced), [], `seed ${seed}`)
|
|
211
|
+
// The total reader must stay total and silent over anything the typed arms can produce:
|
|
212
|
+
// a finding here would mean the reducer stored something its own reader calls malformed.
|
|
213
|
+
assert.deepEqual(resolveTemplateAuthoringMeta(doc.meta).findings, [], `seed ${seed}`)
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
})
|
|
217
|
+
|
|
163
218
|
describe('canonicalization stability', () => {
|
|
164
219
|
const labelDoc = (label: string) => ({
|
|
165
220
|
documentId: 'tpl-nfc',
|
|
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict'
|
|
|
2
2
|
import { describe, it } from 'node:test'
|
|
3
3
|
import { type } from 'arktype'
|
|
4
4
|
|
|
5
|
-
import { canonicalJson, reduceToMinimalForm } from './canonicalize.js'
|
|
5
|
+
import { canonicalJson, hashCanonical, reduceToMinimalForm } from './canonicalize.js'
|
|
6
6
|
import { findDocLawViolations } from './docLaws.js'
|
|
7
7
|
import { emptyTemplateDocument, type QnrTemplateDocument } from './templateDocument.js'
|
|
8
8
|
import { IMPLEMENTED_ANSWER_OP_TYPES } from './answerOperations.js'
|
|
@@ -20,7 +20,9 @@ import {
|
|
|
20
20
|
findTemplateSchemaDocLawViolations,
|
|
21
21
|
qnrAnswerDocumentSchema,
|
|
22
22
|
qnrTemplateDocumentSchema,
|
|
23
|
+
templateAuthoringIsDefault,
|
|
23
24
|
templateDocumentIsDefault,
|
|
25
|
+
templateDocumentIsDefaultV0281,
|
|
24
26
|
templateOpSchema,
|
|
25
27
|
validateTemplateDocument,
|
|
26
28
|
} from './schemas.js'
|
|
@@ -533,3 +535,172 @@ describe('mappingBinding behaviour schemas', () => {
|
|
|
533
535
|
assert.equal(templateDocumentIsDefault('mappingBindingsById.b-1.onMany', 'error'), true)
|
|
534
536
|
})
|
|
535
537
|
})
|
|
538
|
+
|
|
539
|
+
// ────────────── OQ-V2-56 · the frozen 0.28.1 canonical-default predicate ──────────────
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* `templateDocumentIsDefaultV0281` exists because "the released predicate" is a moving target.
|
|
543
|
+
*
|
|
544
|
+
* 0.29.0 added the binding-behaviour branch, so a consumer pinned to 0.28.1 hashed a binding carrying
|
|
545
|
+
* `cardinality: '0..1'` with that member PRESENT, while every later release prunes it. Verifying such
|
|
546
|
+
* a snapshot with today's predicate reports corruption that is not there. These cases pin the old
|
|
547
|
+
* rule as an artifact: they describe bytes that were already written, so none of them may be
|
|
548
|
+
* "updated" to match a future canonical form.
|
|
549
|
+
*/
|
|
550
|
+
describe('the 0.28.1 default predicate is frozen', () => {
|
|
551
|
+
/** Every name 0.28.1 shipped, transcribed from `e885e839` — the complete list, in its order. */
|
|
552
|
+
const V0281_DEFAULT_NAMES = [
|
|
553
|
+
'required',
|
|
554
|
+
'requires_activity_id',
|
|
555
|
+
'ask_for_phone_nr',
|
|
556
|
+
'invitationRequired',
|
|
557
|
+
'singleRow',
|
|
558
|
+
'alwaysNew',
|
|
559
|
+
'timestamps',
|
|
560
|
+
] as const
|
|
561
|
+
|
|
562
|
+
it('recognises exactly the seven 0.28.1 names, and only at `false`', () => {
|
|
563
|
+
for (const name of V0281_DEFAULT_NAMES) {
|
|
564
|
+
assert.equal(templateDocumentIsDefaultV0281(`someObject.${name}`, false), true, name)
|
|
565
|
+
// 0.28.1 keyed on the VALUE too: `true` is content, not an omittable default.
|
|
566
|
+
assert.equal(templateDocumentIsDefaultV0281(`someObject.${name}`, true), false, name)
|
|
567
|
+
// And on a non-boolean, which is a malformed value rather than a default.
|
|
568
|
+
assert.equal(templateDocumentIsDefaultV0281(`someObject.${name}`, 'false'), false, name)
|
|
569
|
+
}
|
|
570
|
+
})
|
|
571
|
+
|
|
572
|
+
it('reproduces 0.28.1\u2019s suffix matching, warts included', () => {
|
|
573
|
+
// The leading dot is required, so a ROOT key named `required` was never a default…
|
|
574
|
+
assert.equal(templateDocumentIsDefaultV0281('required', false), false)
|
|
575
|
+
// …while a coincidentally-named unknown member WAS matched. That is a flaw the later
|
|
576
|
+
// exact-path registry avoids, and preserving it here is the point: the bytes were hashed
|
|
577
|
+
// under this rule, so softening it now would change what 0.28.1 meant.
|
|
578
|
+
assert.equal(templateDocumentIsDefaultV0281('someUnknownBag.required', false), true)
|
|
579
|
+
assert.equal(templateDocumentIsDefaultV0281('a.b.c.timestamps', false), true)
|
|
580
|
+
// A partial suffix is not a match.
|
|
581
|
+
assert.equal(templateDocumentIsDefaultV0281('x.notrequired', false), false)
|
|
582
|
+
assert.equal(templateDocumentIsDefaultV0281('x.required_extra', false), false)
|
|
583
|
+
})
|
|
584
|
+
|
|
585
|
+
it('does NOT treat the three binding behaviours as defaults', () => {
|
|
586
|
+
// The whole delta, in four lines. 0.28.1 had no branch for these, so a binding spelling out
|
|
587
|
+
// its own default kept that member — and that is what the consumer's stored hashes cover.
|
|
588
|
+
for (const [key, value] of [
|
|
589
|
+
['cardinality', '0..1'],
|
|
590
|
+
['onMissing', 'omit'],
|
|
591
|
+
['onMany', 'error'],
|
|
592
|
+
] as const) {
|
|
593
|
+
const path = `mappingBindingsById.b-1.${key}`
|
|
594
|
+
assert.equal(templateDocumentIsDefaultV0281(path, value), false, path)
|
|
595
|
+
assert.equal(templateDocumentIsDefault(path, value), true, `${path} must still be pruned by the live predicate`)
|
|
596
|
+
}
|
|
597
|
+
})
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* The frozen list must not be the live list under another name.
|
|
601
|
+
*
|
|
602
|
+
* Today they happen to hold the same seven entries, so an implementation that simply reused
|
|
603
|
+
* `TEMPLATE_DOCUMENT_DEFAULT_PATHS` would pass every case above — and would then silently
|
|
604
|
+
* redefine "0.28.1" the first time the live list grows. This case is what makes that
|
|
605
|
+
* implementation fail: it names members the live registry may legitimately gain and asserts the
|
|
606
|
+
* frozen predicate stays blind to them.
|
|
607
|
+
*/
|
|
608
|
+
it('stays blind to names 0.28.1 did not ship, however the live list evolves', () => {
|
|
609
|
+
for (const name of [
|
|
610
|
+
'deletableRows',
|
|
611
|
+
'editable',
|
|
612
|
+
'auto_import',
|
|
613
|
+
'refresh_button',
|
|
614
|
+
'requires_phone_number',
|
|
615
|
+
'invitation_required',
|
|
616
|
+
]) {
|
|
617
|
+
assert.equal(templateDocumentIsDefaultV0281(`someObject.${name}`, false), false, name)
|
|
618
|
+
}
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
it('agrees with the live predicate everywhere EXCEPT the binding behaviours', () => {
|
|
622
|
+
// A differential oracle rather than a restatement of the implementation: if the frozen copy
|
|
623
|
+
// had dropped, renamed or gained a name, some probe outside the binding paths would disagree.
|
|
624
|
+
const probes: Array<[string, unknown]> = []
|
|
625
|
+
for (const name of [...V0281_DEFAULT_NAMES, 'deletableRows', 'editable', 'cardinality', 'onMany']) {
|
|
626
|
+
for (const value of [false, true, '0..1', 'omit', 'error', 0, null, undefined]) {
|
|
627
|
+
probes.push([`questionsById.q-1.${name}`, value])
|
|
628
|
+
probes.push([`mappingNodesById.n-1.${name}`, value])
|
|
629
|
+
probes.push([`meta.settings.journal.${name}`, value])
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const disagreements = probes.filter(
|
|
634
|
+
([path, value]) => templateDocumentIsDefaultV0281(path, value) !== templateDocumentIsDefault(path, value),
|
|
635
|
+
)
|
|
636
|
+
assert.deepEqual(disagreements, [], 'the two predicates must differ ONLY on mappingBindingsById paths')
|
|
637
|
+
|
|
638
|
+
// …and on those paths they must genuinely differ, or the oracle above proves nothing.
|
|
639
|
+
assert.notEqual(
|
|
640
|
+
templateDocumentIsDefaultV0281('mappingBindingsById.b-1.cardinality', '0..1'),
|
|
641
|
+
templateDocumentIsDefault('mappingBindingsById.b-1.cardinality', '0..1'),
|
|
642
|
+
)
|
|
643
|
+
})
|
|
644
|
+
})
|
|
645
|
+
|
|
646
|
+
describe('a 0.28.1-era snapshot verifies only under the 0.28.1 predicate', () => {
|
|
647
|
+
/** A binding spelling out all three behaviours — the shape the two canonical forms disagree on. */
|
|
648
|
+
const V0281_ERA_DOCUMENT: QnrTemplateDocument = {
|
|
649
|
+
documentId: 'tpl-v0281',
|
|
650
|
+
revision: 4,
|
|
651
|
+
questionOrder: ['q-1'],
|
|
652
|
+
questionsById: { 'q-1': { type: 'TextShort', required: false } },
|
|
653
|
+
mappingNodesById: { 'n-1': { entityId: 'Actor', cardinality: '0..1' } },
|
|
654
|
+
mappingBindingsById: {
|
|
655
|
+
'b-1': {
|
|
656
|
+
nodeId: 'n-1',
|
|
657
|
+
fieldId: 'Navn',
|
|
658
|
+
target: { kind: 'question', questionId: 'q-1' },
|
|
659
|
+
cardinality: '0..1',
|
|
660
|
+
onMissing: 'omit',
|
|
661
|
+
onMany: 'error',
|
|
662
|
+
},
|
|
663
|
+
},
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
it('keeps the binding behaviours and prunes the sentinel flag', async () => {
|
|
667
|
+
const reduced = reduceToMinimalForm(V0281_ERA_DOCUMENT, { isDefault: templateDocumentIsDefaultV0281 })
|
|
668
|
+
assert.equal(
|
|
669
|
+
canonicalJson(reduced),
|
|
670
|
+
'{"documentId":"tpl-v0281","mappingBindingsById":{"b-1":{"cardinality":"0..1","fieldId":"Navn",' +
|
|
671
|
+
'"nodeId":"n-1","onMany":"error","onMissing":"omit","target":{"kind":"question","questionId":"q-1"}}},' +
|
|
672
|
+
'"mappingNodesById":{"n-1":{"cardinality":"0..1","entityId":"Actor"}},"questionOrder":["q-1"],' +
|
|
673
|
+
'"questionsById":{"q-1":{"type":"TextShort"}},"revision":4}',
|
|
674
|
+
)
|
|
675
|
+
assert.equal(
|
|
676
|
+
await hashCanonical(reduced),
|
|
677
|
+
'sha256:38f3d38e0b0350b46d1f077f5368f2496cb93bed65572586d627490cb6d0ad30',
|
|
678
|
+
)
|
|
679
|
+
})
|
|
680
|
+
|
|
681
|
+
it('hashes differently under the live and authoring predicates, which is the gap', async () => {
|
|
682
|
+
const live = reduceToMinimalForm(V0281_ERA_DOCUMENT, { isDefault: templateDocumentIsDefault })
|
|
683
|
+
const authoring = reduceToMinimalForm(V0281_ERA_DOCUMENT, { isDefault: templateAuthoringIsDefault })
|
|
684
|
+
|
|
685
|
+
const liveHash = 'sha256:c7a82f82efbc2994c75069704245a99c087a726115fcf0a4aa0f19fe1e75b26d'
|
|
686
|
+
assert.equal(await hashCanonical(live), liveHash)
|
|
687
|
+
// The authoring predicate is a superset of the live one and adds nothing on this shape, so a
|
|
688
|
+
// NEW write of the same content agrees with the live form — only 0.28.1 stands apart.
|
|
689
|
+
assert.equal(await hashCanonical(authoring), liveHash)
|
|
690
|
+
|
|
691
|
+
assert.notEqual(
|
|
692
|
+
await hashCanonical(reduceToMinimalForm(V0281_ERA_DOCUMENT, { isDefault: templateDocumentIsDefaultV0281 })),
|
|
693
|
+
liveHash,
|
|
694
|
+
)
|
|
695
|
+
})
|
|
696
|
+
|
|
697
|
+
it('leaves a node-level behaviour alone under every predicate', () => {
|
|
698
|
+
// The live predicate anchors on `mappingBindingsById.<id>.<key>`, so a NODE carrying a
|
|
699
|
+
// deliberately-narrowed `cardinality` survives all three. Pinned because a suffix rule here
|
|
700
|
+
// would drop the one member that made the node take a single row.
|
|
701
|
+
for (const isDefault of [templateDocumentIsDefaultV0281, templateDocumentIsDefault, templateAuthoringIsDefault]) {
|
|
702
|
+
const reduced = reduceToMinimalForm(V0281_ERA_DOCUMENT, { isDefault }) as QnrTemplateDocument
|
|
703
|
+
assert.equal(reduced.mappingNodesById?.['n-1']?.['cardinality'], '0..1')
|
|
704
|
+
}
|
|
705
|
+
})
|
|
706
|
+
})
|
|
@@ -5,6 +5,11 @@ import { findDocLawViolations, type DocLawViolation } from './docLaws.js'
|
|
|
5
5
|
import { IMPLEMENTED_ANSWER_OP_TYPES } from './answerOperations.js'
|
|
6
6
|
import { IMPLEMENTED_OP_TYPES } from './operations.js'
|
|
7
7
|
import { QUESTION_TYPES } from './questionTypes.js'
|
|
8
|
+
import {
|
|
9
|
+
COMPATIBILITY_COLLECTIONS,
|
|
10
|
+
isTemplateAuthoringDefault,
|
|
11
|
+
TEMPLATE_SETTING_FIELDS,
|
|
12
|
+
} from './templateAuthoringMeta.js'
|
|
8
13
|
import type { BindingTarget, QnrTemplateDocument } from './templateDocument.js'
|
|
9
14
|
import {
|
|
10
15
|
ACTION_TYPES,
|
|
@@ -328,18 +333,70 @@ const dataMappingSchema = type({
|
|
|
328
333
|
bindingOrder: 'string[]?',
|
|
329
334
|
})
|
|
330
335
|
|
|
336
|
+
/**
|
|
337
|
+
* The 23 settings leaves, grouped by the surface they configure.
|
|
338
|
+
*
|
|
339
|
+
* Each group keeps an open index signature, and that is not laxity: `template.updateSettings` is a
|
|
340
|
+
* released OPEN arm and the legacy importer wrote raw flat flags through it, so stored documents carry
|
|
341
|
+
* members outside this vocabulary. Narrowing a group would make an already-stored document fail
|
|
342
|
+
* validation — ADR-0008 DEC-006 — while the typed operations stay closed, which is the asymmetry this
|
|
343
|
+
* surface is built on: open to read and replay, closed to author.
|
|
344
|
+
*/
|
|
345
|
+
const qnrTemplateSettingsSchema = type({
|
|
346
|
+
"journal?": type({
|
|
347
|
+
auto_import: 'boolean?',
|
|
348
|
+
requires_activity_id: 'boolean?',
|
|
349
|
+
register_new_activity: 'boolean?',
|
|
350
|
+
user_context_me: 'boolean?',
|
|
351
|
+
...({ '[string]': 'unknown' } as const),
|
|
352
|
+
}),
|
|
353
|
+
"pdf?": type({
|
|
354
|
+
import: 'boolean?',
|
|
355
|
+
generate_for_participant: 'boolean?',
|
|
356
|
+
send_to_journal: 'boolean?',
|
|
357
|
+
...({ '[string]': 'unknown' } as const),
|
|
358
|
+
}),
|
|
359
|
+
"rendering?": type({
|
|
360
|
+
tabs: 'boolean?',
|
|
361
|
+
continuous: 'boolean?',
|
|
362
|
+
multi_step: 'boolean?',
|
|
363
|
+
collapse_all: 'boolean?',
|
|
364
|
+
top_level_actions: 'boolean?',
|
|
365
|
+
refresh_button: 'boolean?',
|
|
366
|
+
filter_document_reports_on_tab: 'boolean?',
|
|
367
|
+
hide_recipient_info: 'boolean?',
|
|
368
|
+
...({ '[string]': 'unknown' } as const),
|
|
369
|
+
}),
|
|
370
|
+
"lifecycle?": type({
|
|
371
|
+
rejectable: 'boolean?',
|
|
372
|
+
shareable: 'boolean?',
|
|
373
|
+
allow_multiple: 'boolean?',
|
|
374
|
+
generate_on_start: 'boolean?',
|
|
375
|
+
...({ '[string]': 'unknown' } as const),
|
|
376
|
+
}),
|
|
377
|
+
"recipient?": type({
|
|
378
|
+
requires_phone_number: 'boolean?',
|
|
379
|
+
/** The released spelling, retained so a stored document and an old log stay valid. */
|
|
380
|
+
ask_for_phone_nr: 'boolean?',
|
|
381
|
+
...({ '[string]': 'unknown' } as const),
|
|
382
|
+
}),
|
|
383
|
+
"highlight?": type({
|
|
384
|
+
enabled: 'boolean?',
|
|
385
|
+
show_to_recipient: 'boolean?',
|
|
386
|
+
...({ '[string]': 'unknown' } as const),
|
|
387
|
+
}),
|
|
388
|
+
"distribution?": type({
|
|
389
|
+
mirror_to_advoca: 'boolean?',
|
|
390
|
+
...({ '[string]': 'unknown' } as const),
|
|
391
|
+
}),
|
|
392
|
+
...({ '[string]': 'unknown' } as const),
|
|
393
|
+
})
|
|
394
|
+
|
|
331
395
|
const qnrTemplateMetaSchema = type({
|
|
332
396
|
title: 'string?',
|
|
333
397
|
description: 'string?',
|
|
334
|
-
"
|
|
335
|
-
|
|
336
|
-
requires_activity_id: 'boolean?',
|
|
337
|
-
}),
|
|
338
|
-
"recipient?": type({
|
|
339
|
-
ask_for_phone_nr: 'boolean?',
|
|
340
|
-
}),
|
|
341
|
-
...({ '[string]': 'unknown' } as const),
|
|
342
|
-
}),
|
|
398
|
+
"visibility?": '"visible" | "hidden"',
|
|
399
|
+
"settings?": qnrTemplateSettingsSchema,
|
|
343
400
|
"instancePolicy?": type({
|
|
344
401
|
"requiredAccessLevel?": '1 | 2 | 3 | 4',
|
|
345
402
|
invitationRequired: 'boolean?',
|
|
@@ -351,6 +408,12 @@ const qnrTemplateMetaSchema = type({
|
|
|
351
408
|
consentTemplateIds: 'string[]?',
|
|
352
409
|
smsTemplateIds: 'string[]?',
|
|
353
410
|
}),
|
|
411
|
+
/** Import-only residue (M-013 and unrecognized flags); no authoring operation reaches it. */
|
|
412
|
+
"legacy?": type({
|
|
413
|
+
"plan_category?": docScalar,
|
|
414
|
+
flags: 'Record<string, unknown>?',
|
|
415
|
+
...({ '[string]': 'unknown' } as const),
|
|
416
|
+
}),
|
|
354
417
|
...({ '[string]': 'unknown' } as const),
|
|
355
418
|
})
|
|
356
419
|
|
|
@@ -406,6 +469,70 @@ export const qnrAnswerDocumentSchema = type({
|
|
|
406
469
|
export const templateOpSchema = type.or(
|
|
407
470
|
type({ type: '"template.updateMeta"', patch: `Record<string, ${opValue} | Record<string, unknown>>` }),
|
|
408
471
|
type({ type: '"template.updateSettings"', patch: `Record<string, ${opValue} | Record<string, unknown>>` }),
|
|
472
|
+
/**
|
|
473
|
+
* `template.setMetaFieldTyped` — one arm per editable path, so the value cannot disagree with the
|
|
474
|
+
* field (the same device `mappingFilter.setTyped` uses for its operator-correlated payloads).
|
|
475
|
+
* `opTypeNames` deduplicates by op name, so these seven arms are one vocabulary member.
|
|
476
|
+
*
|
|
477
|
+
* `'+': 'reject'` is load-bearing on every arm: ArkType admits undeclared keys by default, so
|
|
478
|
+
* without it an `{field, value, patch}` payload would validate and the reducer would be the only
|
|
479
|
+
* thing that noticed the extra member.
|
|
480
|
+
*/
|
|
481
|
+
type({ type: '"template.setMetaFieldTyped"', field: '"title"', value: 'string | null', '+': 'reject' }),
|
|
482
|
+
type({ type: '"template.setMetaFieldTyped"', field: '"description"', value: 'string | null', '+': 'reject' }),
|
|
483
|
+
type({
|
|
484
|
+
type: '"template.setMetaFieldTyped"',
|
|
485
|
+
field: '"visibility"',
|
|
486
|
+
value: '"visible" | "hidden" | null',
|
|
487
|
+
'+': 'reject',
|
|
488
|
+
}),
|
|
489
|
+
type({
|
|
490
|
+
type: '"template.setMetaFieldTyped"',
|
|
491
|
+
field: '"instancePolicy.requiredAccessLevel"',
|
|
492
|
+
value: '1 | 2 | 3 | 4 | null',
|
|
493
|
+
'+': 'reject',
|
|
494
|
+
}),
|
|
495
|
+
type({
|
|
496
|
+
type: '"template.setMetaFieldTyped"',
|
|
497
|
+
field: '"instancePolicy.invitationRequired"',
|
|
498
|
+
value: 'boolean | null',
|
|
499
|
+
'+': 'reject',
|
|
500
|
+
}),
|
|
501
|
+
type({
|
|
502
|
+
type: '"template.setMetaFieldTyped"',
|
|
503
|
+
field: '"instancePolicy.initiator"',
|
|
504
|
+
value: '"coordinator" | "recipient" | null',
|
|
505
|
+
'+': 'reject',
|
|
506
|
+
}),
|
|
507
|
+
type({
|
|
508
|
+
type: '"template.setMetaFieldTyped"',
|
|
509
|
+
field: '"instancePolicy.template_update_mode"',
|
|
510
|
+
value: '"never" | "always" | "ask" | null',
|
|
511
|
+
'+': 'reject',
|
|
512
|
+
}),
|
|
513
|
+
/** The 23 leaves come from the shared registry, so the wire cannot admit a path the reducer lacks. */
|
|
514
|
+
type({
|
|
515
|
+
type: '"template.setSettingTyped"',
|
|
516
|
+
field: type.enumerated(...TEMPLATE_SETTING_FIELDS),
|
|
517
|
+
value: 'boolean | null',
|
|
518
|
+
'+': 'reject',
|
|
519
|
+
}),
|
|
520
|
+
/**
|
|
521
|
+
* Soft ids are nonempty strings — `string > 0` — and deliberately not UUIDs: legacy template ids
|
|
522
|
+
* are integers, preserved by their lossless decimal spelling.
|
|
523
|
+
*/
|
|
524
|
+
type({
|
|
525
|
+
type: '"template.addCompatibilityId"',
|
|
526
|
+
collection: type.enumerated(...COMPATIBILITY_COLLECTIONS),
|
|
527
|
+
id: 'string > 0',
|
|
528
|
+
'+': 'reject',
|
|
529
|
+
}),
|
|
530
|
+
type({
|
|
531
|
+
type: '"template.removeCompatibilityId"',
|
|
532
|
+
collection: type.enumerated(...COMPATIBILITY_COLLECTIONS),
|
|
533
|
+
id: 'string > 0',
|
|
534
|
+
'+': 'reject',
|
|
535
|
+
}),
|
|
409
536
|
type({
|
|
410
537
|
type: '"question.create"',
|
|
411
538
|
questionId: 'string',
|
|
@@ -924,6 +1051,84 @@ export const templateDocumentIsDefault: IsDefault = (path, value) => {
|
|
|
924
1051
|
return value === false && TEMPLATE_DOCUMENT_DEFAULT_PATHS.some((name) => path.endsWith(`.${name}`))
|
|
925
1052
|
}
|
|
926
1053
|
|
|
1054
|
+
/**
|
|
1055
|
+
* The default registry **exactly as 0.28.1 shipped it** — a historical artifact, not a live list.
|
|
1056
|
+
*
|
|
1057
|
+
* Deliberately a full transcription rather than a reference to
|
|
1058
|
+
* {@link TEMPLATE_DOCUMENT_DEFAULT_PATHS}, even though the two are identical today. The live list is
|
|
1059
|
+
* allowed to grow; this one is not, because it describes bytes that were already hashed. Sharing the
|
|
1060
|
+
* identifier would make the next addition to the live list silently rewrite what "0.28.1" means, which
|
|
1061
|
+
* is the one thing a frozen predicate must never do.
|
|
1062
|
+
*
|
|
1063
|
+
* @see v0.28.1 `src/collaboration/schemas.ts` — `e885e839bec33c6950cfe3f192e07a64412541d8`
|
|
1064
|
+
*/
|
|
1065
|
+
const TEMPLATE_DOCUMENT_DEFAULT_PATHS_V0281: readonly string[] = [
|
|
1066
|
+
'required',
|
|
1067
|
+
'requires_activity_id',
|
|
1068
|
+
'ask_for_phone_nr',
|
|
1069
|
+
'invitationRequired',
|
|
1070
|
+
'singleRow',
|
|
1071
|
+
'alwaysNew',
|
|
1072
|
+
'timestamps',
|
|
1073
|
+
]
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* The 0.28.1 canonical-default predicate, frozen for consumers that still hash against that release.
|
|
1077
|
+
*
|
|
1078
|
+
* **Why this exists.** `templateDocumentIsDefault` is "the released predicate", but *released* is a
|
|
1079
|
+
* moving target: 0.29.0 added a branch for the three `mappingBindingsById.<id>.{cardinality,
|
|
1080
|
+
* onMissing, onMany}` behaviours, whose defaults are VALUES rather than `false`. A consumer pinned to
|
|
1081
|
+
* 0.28.1 therefore hashed a binding carrying `cardinality: '0..1'` **with that member present**, while
|
|
1082
|
+
* 0.29.0 and later prune it. Same document, two canonical byte strings, two `document_hash` values —
|
|
1083
|
+
* so verifying a 0.28.1-era stored snapshot with today's predicate reports corruption that is not
|
|
1084
|
+
* there.
|
|
1085
|
+
*
|
|
1086
|
+
* This is a consumer compatibility gap exposed by adoption, not a defect in the stored data: the
|
|
1087
|
+
* earlier shared byte-identity check for this work was performed against `a0dfc955` (0.38.0), which is
|
|
1088
|
+
* the correct baseline for THIS package's history and the wrong one for a consumer pinned to 0.28.1.
|
|
1089
|
+
* Nothing historical is rewritten — the fix is to make the old rule addressable.
|
|
1090
|
+
*
|
|
1091
|
+
* **Which predicate to use.** Three, with three different jobs, and picking by name rather than by
|
|
1092
|
+
* recency is the whole point:
|
|
1093
|
+
*
|
|
1094
|
+
* - `templateDocumentIsDefaultV0281` — verify a snapshot hashed by a consumer pinned to **0.28.1 or
|
|
1095
|
+
* earlier**, as stored.
|
|
1096
|
+
* - {@link templateDocumentIsDefault} — verify a snapshot hashed by **0.29.0 through 0.38.0**, as
|
|
1097
|
+
* stored. Unchanged, and existing consumers keep reading it.
|
|
1098
|
+
* - {@link templateAuthoringIsDefault} — normalize a **new** write or a **new** canonical import.
|
|
1099
|
+
*
|
|
1100
|
+
* **Never "keep this in sync".** It has no forward semantics to track: if a future release changes the
|
|
1101
|
+
* canonical form again, that release gets its own frozen predicate and this one keeps meaning 0.28.1.
|
|
1102
|
+
*/
|
|
1103
|
+
export const templateDocumentIsDefaultV0281: IsDefault = (path, value) =>
|
|
1104
|
+
value === false && TEMPLATE_DOCUMENT_DEFAULT_PATHS_V0281.some((name) => path.endsWith(`.${name}`))
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* The canonical-write predicate: the released rules PLUS the ASMA-8339 metadata/settings registry.
|
|
1108
|
+
*
|
|
1109
|
+
* **Two predicates, not one, and the split is a correctness requirement rather than caution.**
|
|
1110
|
+
* `templateDocumentIsDefault` above is released and is what the stored immutable snapshots were
|
|
1111
|
+
* hashed with; it must stay byte-identical, because three of the paths the new registry declares
|
|
1112
|
+
* (`instancePolicy.requiredAccessLevel` = 4, `initiator` = 'coordinator',
|
|
1113
|
+
* `template_update_mode` = 'never') are released schema members with NO declared default, so an
|
|
1114
|
+
* already-stored document may legitimately carry them spelled out. Adding their defaults to the
|
|
1115
|
+
* released predicate would drop those keys from the canonical bytes of documents that already exist
|
|
1116
|
+
* — changing their `document_hash` and breaking exactly the immutable versions this work must
|
|
1117
|
+
* preserve. The same holds for `meta.title: ''`.
|
|
1118
|
+
*
|
|
1119
|
+
* So: verify a historical snapshot AS STORED with `templateDocumentIsDefault`, and normalize a NEW
|
|
1120
|
+
* write or a NEW canonical import with this one. An imported document and the same content authored
|
|
1121
|
+
* through the typed operations both go through this predicate, which is what makes their hashes
|
|
1122
|
+
* equal.
|
|
1123
|
+
*
|
|
1124
|
+
* The released suffix-matched rows are inherited verbatim rather than re-anchored: re-anchoring them
|
|
1125
|
+
* would change the released canonical form for the paths they already cover. Every row the new
|
|
1126
|
+
* registry adds is matched on its complete document-absolute path, so it cannot prune a
|
|
1127
|
+
* coincidentally-named unknown `title`, `enabled` or `refresh_button` elsewhere in the document.
|
|
1128
|
+
*/
|
|
1129
|
+
export const templateAuthoringIsDefault: IsDefault = (path, value) =>
|
|
1130
|
+
templateDocumentIsDefault(path, value) || isTemplateAuthoringDefault(path, value)
|
|
1131
|
+
|
|
927
1132
|
/**
|
|
928
1133
|
* The instance-side half of the default lint: every present-and-default field on a stored
|
|
929
1134
|
* template document, ready for the contract test to reject. Complements
|