asma-core-helpers 0.18.0 → 0.20.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/answerDocument.d.ts +50 -0
- package/lib/collaboration/answerDocument.d.ts.map +1 -0
- package/lib/collaboration/answerDocument.js +10 -0
- package/lib/collaboration/answerDocument.js.map +1 -0
- package/lib/collaboration/answerOperations.d.ts +40 -0
- package/lib/collaboration/answerOperations.d.ts.map +1 -0
- package/lib/collaboration/answerOperations.js +9 -0
- package/lib/collaboration/answerOperations.js.map +1 -0
- package/lib/collaboration/applyOperation.d.ts.map +1 -1
- package/lib/collaboration/applyOperation.js +290 -4
- package/lib/collaboration/applyOperation.js.map +1 -1
- package/lib/collaboration/canonicalize.d.ts +61 -0
- package/lib/collaboration/canonicalize.d.ts.map +1 -0
- package/lib/collaboration/canonicalize.js +184 -0
- package/lib/collaboration/canonicalize.js.map +1 -0
- package/lib/collaboration/docLaws.d.ts +58 -0
- package/lib/collaboration/docLaws.d.ts.map +1 -0
- package/lib/collaboration/docLaws.js +71 -0
- package/lib/collaboration/docLaws.js.map +1 -0
- package/lib/collaboration/operations.d.ts +111 -10
- package/lib/collaboration/operations.d.ts.map +1 -1
- package/lib/collaboration/operations.js +42 -19
- package/lib/collaboration/operations.js.map +1 -1
- package/lib/collaboration/templateDocument.d.ts +128 -4
- package/lib/collaboration/templateDocument.d.ts.map +1 -1
- package/lib/collaboration/templateDocument.js +3 -3
- package/lib/collaboration/templateDocument.js.map +1 -1
- package/package.json +2 -1
- package/src/collaboration/answerDocument.ts +57 -0
- package/src/collaboration/answerOperations.ts +34 -0
- package/src/collaboration/applyOperation.test.ts +152 -0
- package/src/collaboration/applyOperation.ts +316 -4
- package/src/collaboration/canonicalize.ts +209 -0
- package/src/collaboration/docLaws.ts +123 -0
- package/src/collaboration/operations.ts +114 -23
- package/src/collaboration/templateDocument.ts +137 -5
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* to a total in-memory model once at the document boundary rather than writing `?? {}`
|
|
8
8
|
* at each use site.
|
|
9
9
|
*
|
|
10
|
-
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:152 (document shape)
|
|
11
|
-
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:193 (DOC-LAW-1)
|
|
12
|
-
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:214 (§2.2a mapping graph)
|
|
10
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:152 (document shape)
|
|
11
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:193 (DOC-LAW-1)
|
|
12
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:214 (§2.2a mapping graph)
|
|
13
13
|
*/
|
|
14
14
|
import type { QuestionSubtype, QuestionType } from './questionTypes.js';
|
|
15
15
|
export type QuestionId = string;
|
|
@@ -21,8 +21,85 @@ export type NodeId = string;
|
|
|
21
21
|
export type BindingId = string;
|
|
22
22
|
export type FilterId = string;
|
|
23
23
|
export type MappingId = string;
|
|
24
|
+
export type VisibilityRuleId = string;
|
|
25
|
+
export type HighlightRuleId = string;
|
|
24
26
|
/** A scalar a document may carry. Deliberately not `any`: DOC-LAW-2 bans `null`. */
|
|
25
27
|
export type DocScalar = string | number | boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The required access level of the pinned version (OQ-V2-2): 1 anonymous, 2 identifiable
|
|
30
|
+
* without authentication, 3 lower-assurance authentication, 4 BankID. Never collapsed
|
|
31
|
+
* to a boolean; `invitationRequired` is a separate axis.
|
|
32
|
+
*/
|
|
33
|
+
export type RequiredAccessLevel = 1 | 2 | 3 | 4;
|
|
34
|
+
/** Who the questionnaire is initiated by (OQ-V2-15 wire vocabulary). */
|
|
35
|
+
export type Initiator = 'coordinator' | 'recipient';
|
|
36
|
+
/**
|
|
37
|
+
* What happens to in-flight instances when the family publishes a new version
|
|
38
|
+
* (OQ-V2-16, IMM-I5). v1 implements `never`; `always`/`ask` land later.
|
|
39
|
+
*/
|
|
40
|
+
export type TemplateUpdateMode = 'never' | 'always' | 'ask';
|
|
41
|
+
/**
|
|
42
|
+
* The typed semantic body of the document (`meta`). Absent means the default, per
|
|
43
|
+
* DOC-LAW-2 — a questionnaire that requires nothing special stores `meta` with only
|
|
44
|
+
* what differs. Fields still open after the naming freeze (Gate-4) ride the index
|
|
45
|
+
* signature; the decided fields are spelled out so a typo is a compile error.
|
|
46
|
+
*/
|
|
47
|
+
export type QnrTemplateMeta = {
|
|
48
|
+
title?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
/** Journal-wiring settings (M-007 aliases normalize here). */
|
|
51
|
+
settings?: {
|
|
52
|
+
journal?: {
|
|
53
|
+
/** `activityId_required`/`soknadid_required`/`sokndaid_required` unify here (architecture §2.2(7)). */
|
|
54
|
+
requires_activity_id?: boolean;
|
|
55
|
+
};
|
|
56
|
+
/** Recipient-side requirements. */
|
|
57
|
+
recipient?: {
|
|
58
|
+
/** Legacy `ask_for_phone_nr`. */
|
|
59
|
+
ask_for_phone_nr?: boolean;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/** Admission policy of the pinned version (OQ-V2-2/15/16). */
|
|
63
|
+
instancePolicy?: {
|
|
64
|
+
requiredAccessLevel?: RequiredAccessLevel;
|
|
65
|
+
/** Open level-1 is invitation-free; invitation-protected level-1 sets this. */
|
|
66
|
+
invitationRequired?: boolean;
|
|
67
|
+
initiator?: Initiator;
|
|
68
|
+
template_update_mode?: TemplateUpdateMode;
|
|
69
|
+
};
|
|
70
|
+
/** Presentation profiles (PM-6): audience/flow/layout/visibility — still loose pending their editor. */
|
|
71
|
+
presentationProfiles?: Record<string, unknown>;
|
|
72
|
+
/** Owner-domain soft references (REQ-013): ids only, no bodies, no FK validation. */
|
|
73
|
+
compatibility?: {
|
|
74
|
+
consentTemplateIds?: string[];
|
|
75
|
+
smsTemplateIds?: string[];
|
|
76
|
+
};
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* The per-question-type configuration of a `QuestionGrid` (OQ-V2-17) — the repeat
|
|
81
|
+
* policy of the grid's rows. Lives at `question.grid.*`.
|
|
82
|
+
*/
|
|
83
|
+
export type QuestionGridConfig = {
|
|
84
|
+
minRows?: number;
|
|
85
|
+
maxRows?: number;
|
|
86
|
+
/** `single_row` in OQ-V2-17 prose — max 1 row. */
|
|
87
|
+
singleRow?: boolean;
|
|
88
|
+
deletableRows?: boolean;
|
|
89
|
+
alwaysNew?: boolean;
|
|
90
|
+
timestamps?: boolean;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Grid-owned presentation (OQ-V2-17/25): row-editor layout, filters, grid actions,
|
|
94
|
+
* highlight rules, the header-tab reference and authored default column widths live
|
|
95
|
+
* here — there is no parallel `settings_ui` or `layoutByQuestionId` map.
|
|
96
|
+
*/
|
|
97
|
+
export type QuestionGridPresentation = {
|
|
98
|
+
headerTabId?: TabId;
|
|
99
|
+
/** OQ-V2-25: authored defaults; per-user widths are preference state outside both documents. */
|
|
100
|
+
defaultColumnWidthsByQuestionId?: Record<QuestionId, number>;
|
|
101
|
+
[key: string]: unknown;
|
|
102
|
+
};
|
|
26
103
|
/**
|
|
27
104
|
* `type` is the question's own discriminator (M-062), a closed union rather than a string — see
|
|
28
105
|
* `questionTypes.ts` for why the value cannot be loose. Not to be confused with the other `kind`
|
|
@@ -35,6 +112,10 @@ export type QnrQuestion = {
|
|
|
35
112
|
label?: string;
|
|
36
113
|
required?: boolean;
|
|
37
114
|
defaultValue?: DocScalar;
|
|
115
|
+
/** `QuestionGrid` only: the row repeat policy. */
|
|
116
|
+
grid?: QuestionGridConfig;
|
|
117
|
+
/** `QuestionGrid` only: grid-owned presentation (layout, filters, actions, column widths). */
|
|
118
|
+
presentation?: QuestionGridPresentation;
|
|
38
119
|
[key: string]: unknown;
|
|
39
120
|
};
|
|
40
121
|
export type QnrAlternative = {
|
|
@@ -42,8 +123,11 @@ export type QnrAlternative = {
|
|
|
42
123
|
value?: DocScalar;
|
|
43
124
|
[key: string]: unknown;
|
|
44
125
|
};
|
|
126
|
+
/** An authored predefined grid row; cells are keyed by column question id. */
|
|
45
127
|
export type QnrGridRow = {
|
|
46
128
|
label?: string;
|
|
129
|
+
/** Authored default cell values, keyed by the column question id. */
|
|
130
|
+
cells?: Record<QuestionId, DocScalar>;
|
|
47
131
|
[key: string]: unknown;
|
|
48
132
|
};
|
|
49
133
|
export type QnrTab = {
|
|
@@ -54,6 +138,26 @@ export type QnrAction = {
|
|
|
54
138
|
kind?: string;
|
|
55
139
|
[key: string]: unknown;
|
|
56
140
|
};
|
|
141
|
+
/**
|
|
142
|
+
* A typed conditional (OQ-V2-17/architecture §2.2(4)): question visibility/highlight
|
|
143
|
+
* depends on another question's answer. Legacy `dependent_question`+`dependent_questions`
|
|
144
|
+
* duals normalize into rule collections (byId + per-question order, DOC-LAW-1).
|
|
145
|
+
*/
|
|
146
|
+
export type RuleCondition = {
|
|
147
|
+
sourceQuestionId: QuestionId;
|
|
148
|
+
alternativeId?: AltId;
|
|
149
|
+
operator?: string;
|
|
150
|
+
value?: DocScalar;
|
|
151
|
+
[key: string]: unknown;
|
|
152
|
+
};
|
|
153
|
+
export type VisibilityRule = {
|
|
154
|
+
condition: RuleCondition;
|
|
155
|
+
[key: string]: unknown;
|
|
156
|
+
};
|
|
157
|
+
export type HighlightRule = {
|
|
158
|
+
condition: RuleCondition;
|
|
159
|
+
[key: string]: unknown;
|
|
160
|
+
};
|
|
57
161
|
/** One traversal step. Many questions off one entity share a single node (§2.2a). */
|
|
58
162
|
export type MappingNode = {
|
|
59
163
|
entityId: string;
|
|
@@ -92,7 +196,7 @@ export type MappingFilter = {
|
|
|
92
196
|
export type QnrTemplateDocument = {
|
|
93
197
|
documentId: string;
|
|
94
198
|
revision: number;
|
|
95
|
-
meta?:
|
|
199
|
+
meta?: QnrTemplateMeta;
|
|
96
200
|
questionsById?: Record<QuestionId, QnrQuestion>;
|
|
97
201
|
questionOrder: QuestionId[];
|
|
98
202
|
gridRowsById?: Record<RowId, QnrGridRow>;
|
|
@@ -102,6 +206,10 @@ export type QnrTemplateDocument = {
|
|
|
102
206
|
tabsById?: Record<TabId, QnrTab>;
|
|
103
207
|
tabOrder?: TabId[];
|
|
104
208
|
actionsById?: Record<ActionId, QnrAction>;
|
|
209
|
+
visibilityRulesById?: Record<VisibilityRuleId, VisibilityRule>;
|
|
210
|
+
visibilityRuleOrderByQuestionId?: Record<QuestionId, VisibilityRuleId[]>;
|
|
211
|
+
highlightRulesById?: Record<HighlightRuleId, HighlightRule>;
|
|
212
|
+
highlightRuleOrderByQuestionId?: Record<QuestionId, HighlightRuleId[]>;
|
|
105
213
|
dataMappingsById?: Record<MappingId, {
|
|
106
214
|
sourceId: string;
|
|
107
215
|
rootNodeId: NodeId;
|
|
@@ -111,6 +219,22 @@ export type QnrTemplateDocument = {
|
|
|
111
219
|
mappingBindingsById?: Record<BindingId, MappingBinding>;
|
|
112
220
|
mappingFiltersById?: Record<FilterId, MappingFilter>;
|
|
113
221
|
};
|
|
222
|
+
/**
|
|
223
|
+
* A reusable question-template bundle (OQ-V2-1): the root question plus every owned
|
|
224
|
+
* child question, alternative, predefined grid row, scoped tab/action, order and
|
|
225
|
+
* internal reference needed to use it. Stored whole in `qnr_question_templates.bundle`;
|
|
226
|
+
* a manual pick deep-copies and validates it into the family document.
|
|
227
|
+
*/
|
|
228
|
+
export type QnrQuestionBundle = {
|
|
229
|
+
rootQuestionId: QuestionId;
|
|
230
|
+
questionsById: Record<QuestionId, QnrQuestion>;
|
|
231
|
+
gridRowsById?: Record<RowId, QnrGridRow>;
|
|
232
|
+
gridRowOrderByQuestionId?: Record<QuestionId, RowId[]>;
|
|
233
|
+
alternativesById?: Record<AltId, QnrAlternative>;
|
|
234
|
+
alternativeOrderByQuestionId?: Record<QuestionId, AltId[]>;
|
|
235
|
+
tabsById?: Record<TabId, QnrTab>;
|
|
236
|
+
actionsById?: Record<ActionId, QnrAction>;
|
|
237
|
+
};
|
|
114
238
|
/**
|
|
115
239
|
* A new family's document. `questionOrder` is present-and-empty rather than absent
|
|
116
240
|
* because it is the document's only structural array and every reader indexes it; an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateDocument.d.ts","sourceRoot":"","sources":["../../src/collaboration/templateDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEvE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAA;AAC/B,MAAM,MAAM,KAAK,GAAG,MAAM,CAAA;AAC1B,MAAM,MAAM,KAAK,GAAG,MAAM,CAAA;AAC1B,MAAM,MAAM,KAAK,GAAG,MAAM,CAAA;AAC1B,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAC7B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAC3B,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAC9B,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAC7B,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"templateDocument.d.ts","sourceRoot":"","sources":["../../src/collaboration/templateDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEvE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAA;AAC/B,MAAM,MAAM,KAAK,GAAG,MAAM,CAAA;AAC1B,MAAM,MAAM,KAAK,GAAG,MAAM,CAAA;AAC1B,MAAM,MAAM,KAAK,GA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AC,KAAK,EAAE,cAAc,CAAC,CAAA;IAChD,4BAA4B,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;CAC5C,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,eAAgB,MAAM,KAAG,mBAIzD,CAAA"}
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* to a total in-memory model once at the document boundary rather than writing `?? {}`
|
|
8
8
|
* at each use site.
|
|
9
9
|
*
|
|
10
|
-
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:152 (document shape)
|
|
11
|
-
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:193 (DOC-LAW-1)
|
|
12
|
-
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:214 (§2.2a mapping graph)
|
|
10
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:152 (document shape)
|
|
11
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:193 (DOC-LAW-1)
|
|
12
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:214 (§2.2a mapping graph)
|
|
13
13
|
*/
|
|
14
14
|
/**
|
|
15
15
|
* A new family's document. `questionOrder` is present-and-empty rather than absent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateDocument.js","sourceRoot":"","sources":["../../src/collaboration/templateDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"templateDocument.js","sourceRoot":"","sources":["../../src/collaboration/templateDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA8NH;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,UAAkB,EAAuB,EAAE,CAAC,CAAC;IAC/E,UAAU;IACV,QAAQ,EAAE,CAAC;IACX,aAAa,EAAE,EAAE;CACpB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "asma-core-helpers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Core helper utilities for ASMA applications",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib/**/*",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@0no-co/graphql.web": "^1.0.9",
|
|
46
46
|
"@urql/core": "^6.0.3",
|
|
47
47
|
"@urql/exchange-auth": "^3.0.0",
|
|
48
|
+
"arktype": "^2.2.3",
|
|
48
49
|
"asma-event-bus": "^0.7.27",
|
|
49
50
|
"buffer": "^6.0.3",
|
|
50
51
|
"idb-keyval": "^6.2.1",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { DocScalar, QuestionId, RowId } from './templateDocument.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The instance answer document (OQ-V2-8/24/44/47) — the filling-side sibling of the
|
|
5
|
+
* template authoring document. It stores **answers only**: the definition comes from the
|
|
6
|
+
* pinned immutable template version, never from here.
|
|
7
|
+
*
|
|
8
|
+
* **DOC-LAW-2's scoped exception lives here.** Absence means "never answered" in answer
|
|
9
|
+
* state, so an explicit `null` encodes the genuinely different fact "answered then
|
|
10
|
+
* cleared" — that is what keeps the journal dispatch from re-sending a prefilled value
|
|
11
|
+
* after the recipient cleared it. The template document keeps the strict no-null rule;
|
|
12
|
+
* this one does not.
|
|
13
|
+
*
|
|
14
|
+
* A grid row added at answer time is owned by this document (`answerGridRowsById` +
|
|
15
|
+
* order arrays), not by the template — the template's predefined rows stay frozen in the
|
|
16
|
+
* pinned version.
|
|
17
|
+
*
|
|
18
|
+
* The op vocabulary for this document (`answer.set/clear`, `gridRow.add/remove/move`,
|
|
19
|
+
* `gridAnswer.set`) is defined in `answerOperations.ts`; the reducer is a Phase-7
|
|
20
|
+
* deliverable, so this file and the op union are contract-only for now.
|
|
21
|
+
*
|
|
22
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:181 (QnrAnswerDocument)
|
|
23
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:195 (DOC-LAW-2 exception)
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An answer value. `null` is the deliberate-clear marker; a primitive array is legal
|
|
28
|
+
* because DOC-LAW-1 allows primitive arrays (multi-select = selected alternative ids).
|
|
29
|
+
*/
|
|
30
|
+
export type AnswerValue = DocScalar | DocScalar[] | null
|
|
31
|
+
|
|
32
|
+
/** One instance-added grid row. `deleted: true` is the tombstone (OQ-V2-24). */
|
|
33
|
+
export type AnswerGridRow = {
|
|
34
|
+
questionGridId: QuestionId
|
|
35
|
+
/** The captured source-row identity — an opaque string, never parsed (OQ-V2-24). */
|
|
36
|
+
entityRef?: string
|
|
37
|
+
deleted?: true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type QnrAnswerDocument = {
|
|
41
|
+
documentId: string
|
|
42
|
+
revision: number
|
|
43
|
+
answersByQuestionId?: Record<QuestionId, AnswerValue>
|
|
44
|
+
gridAnswersByQuestionId?: Record<QuestionId, Record<RowId, Record<QuestionId, AnswerValue>>>
|
|
45
|
+
answerGridRowsById?: Record<RowId, AnswerGridRow>
|
|
46
|
+
answerGridRowOrderByQuestionId?: Record<QuestionId, RowId[]>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A fresh instance document. `answerGridRowOrderByQuestionId` is absent (no rows yet) —
|
|
51
|
+
* unlike the template's `questionOrder`, nothing here is structural: the template's
|
|
52
|
+
* question order already exists, and row order is only meaningful once rows exist.
|
|
53
|
+
*/
|
|
54
|
+
export const emptyAnswerDocument = (documentId: string): QnrAnswerDocument => ({
|
|
55
|
+
documentId,
|
|
56
|
+
revision: 0,
|
|
57
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AnswerValue } from './answerDocument.js'
|
|
2
|
+
import type { QuestionId, RowId } from './templateDocument.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The filling (answer-document) op vocabulary (architecture §5, OQ-V2-24/44/47).
|
|
6
|
+
*
|
|
7
|
+
* Contract-only for now: the types are the Phase-0 deliverable so both sides of the
|
|
8
|
+
* wire and the Phase-1 DDL agree on the shape; the reducer that applies them
|
|
9
|
+
* (`applyAnswerOperation`) is a Phase-7 deliverable. The authoring vocabulary lives in
|
|
10
|
+
* `operations.ts`; this one is deliberately separate because the two documents have
|
|
11
|
+
* different mutability (OQ-V2-8) and different law regimes (the explicit `null` clear
|
|
12
|
+
* marker is legal in answer state, never in the template document).
|
|
13
|
+
*
|
|
14
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:380 (filling vocabulary)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export type AnswerOp =
|
|
18
|
+
| { type: 'answer.set'; questionId: QuestionId; value: AnswerValue }
|
|
19
|
+
| { type: 'answer.clear'; questionId: QuestionId }
|
|
20
|
+
| { type: 'gridRow.add'; questionId: QuestionId; rowId: RowId; afterRowId?: RowId }
|
|
21
|
+
| { type: 'gridRow.remove'; questionId: QuestionId; rowId: RowId }
|
|
22
|
+
| { type: 'gridAnswer.set'; questionId: QuestionId; rowId: RowId; columnQuestionId: QuestionId; value: AnswerValue }
|
|
23
|
+
|
|
24
|
+
export type AnswerOpType = AnswerOp['type']
|
|
25
|
+
|
|
26
|
+
const ANSWER_OP_TYPE_COVERAGE: Record<AnswerOpType, true> = {
|
|
27
|
+
'answer.set': true,
|
|
28
|
+
'answer.clear': true,
|
|
29
|
+
'gridRow.add': true,
|
|
30
|
+
'gridRow.remove': true,
|
|
31
|
+
'gridAnswer.set': true,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const IMPLEMENTED_ANSWER_OP_TYPES = Object.keys(ANSWER_OP_TYPE_COVERAGE) as readonly AnswerOpType[]
|
|
@@ -24,6 +24,7 @@ const doc0 = emptyTemplateDocument('tpl-1')
|
|
|
24
24
|
|
|
25
25
|
const apply = (ops: TemplateOp[], from = doc0) => ops.reduce((doc, op) => applyOperation(doc, op), from)
|
|
26
26
|
|
|
27
|
+
|
|
27
28
|
const threeQuestions = apply([
|
|
28
29
|
{ type: 'question.create', questionId: 'q-1', questionType: 'TextShort' },
|
|
29
30
|
{ type: 'question.create', questionId: 'q-2', questionType: 'TextShort' },
|
|
@@ -94,6 +95,157 @@ describe('applyOperation', () => {
|
|
|
94
95
|
assert.equal(removed.alternativesById, undefined)
|
|
95
96
|
})
|
|
96
97
|
|
|
98
|
+
it('writes a nested per-type field through a dotted path', () => {
|
|
99
|
+
// The per-type configuration is nested in the document (`question.scale.{from, to}`) while an
|
|
100
|
+
// op value is a scalar, so without path support a LinearScale's own settings cannot be
|
|
101
|
+
// authored at all.
|
|
102
|
+
const created = apply([{ type: 'question.create', questionId: 'q-1', questionType: 'LinearScale' }])
|
|
103
|
+
|
|
104
|
+
const configured = apply(
|
|
105
|
+
[
|
|
106
|
+
{ type: 'question.updateField', questionId: 'q-1', field: 'scale.from', value: 1 },
|
|
107
|
+
{ type: 'question.updateField', questionId: 'q-1', field: 'scale.toLabel', value: 'Svært godt' },
|
|
108
|
+
],
|
|
109
|
+
created,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
assert.deepEqual(configured.questionsById?.['q-1'], {
|
|
113
|
+
type: 'LinearScale',
|
|
114
|
+
scale: { from: 1, toLabel: 'Svært godt' },
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('removes the nested group when its last key is unset, never storing it empty', () => {
|
|
119
|
+
// DOC-LAW-2: an empty collection is not stored. Leaving `{ scale: {} }` behind would change
|
|
120
|
+
// `document_hash` for a document that carries no scale at all, so two clients that took
|
|
121
|
+
// different routes to the same state would disagree about the hash.
|
|
122
|
+
const configured = apply([
|
|
123
|
+
{ type: 'question.create', questionId: 'q-1', questionType: 'LinearScale' },
|
|
124
|
+
{ type: 'question.updateField', questionId: 'q-1', field: 'scale.from', value: 1 },
|
|
125
|
+
])
|
|
126
|
+
|
|
127
|
+
const cleared = applyOperation(configured, {
|
|
128
|
+
type: 'question.updateField',
|
|
129
|
+
questionId: 'q-1',
|
|
130
|
+
field: 'scale.from',
|
|
131
|
+
value: null,
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
assert.deepEqual(cleared.questionsById?.['q-1'], { type: 'LinearScale' })
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('keeps sibling keys when one nested key is unset', () => {
|
|
138
|
+
const configured = apply([
|
|
139
|
+
{ type: 'question.create', questionId: 'q-1', questionType: 'LinearScale' },
|
|
140
|
+
{ type: 'question.updateField', questionId: 'q-1', field: 'scale.from', value: 1 },
|
|
141
|
+
{ type: 'question.updateField', questionId: 'q-1', field: 'scale.to', value: 10 },
|
|
142
|
+
])
|
|
143
|
+
|
|
144
|
+
const cleared = applyOperation(configured, {
|
|
145
|
+
type: 'question.updateField',
|
|
146
|
+
questionId: 'q-1',
|
|
147
|
+
field: 'scale.from',
|
|
148
|
+
value: null,
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
assert.deepEqual(cleared.questionsById?.['q-1'], { type: 'LinearScale', scale: { to: 10 } })
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('does not mutate the document a nested write was derived from', () => {
|
|
155
|
+
// The store keeps the confirmed base and replays pending ops onto it, so a nested write that
|
|
156
|
+
// reached into the previous object would corrupt the base and make the replay non-repeatable.
|
|
157
|
+
const before = apply([
|
|
158
|
+
{ type: 'question.create', questionId: 'q-1', questionType: 'LinearScale' },
|
|
159
|
+
{ type: 'question.updateField', questionId: 'q-1', field: 'scale.from', value: 1 },
|
|
160
|
+
])
|
|
161
|
+
|
|
162
|
+
applyOperation(before, { type: 'question.updateField', questionId: 'q-1', field: 'scale.to', value: 10 })
|
|
163
|
+
|
|
164
|
+
assert.deepEqual(before.questionsById?.['q-1'], { type: 'LinearScale', scale: { from: 1 } })
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it('renames an alternative in place, keeping the id every answer references', () => {
|
|
168
|
+
// The whole reason this op exists rather than delete-then-create: an answer stores the
|
|
169
|
+
// alternative id, so a rename that mints a new id orphans every answer that chose it.
|
|
170
|
+
const created = apply([
|
|
171
|
+
{ type: 'question.create', questionId: 'q-1', questionType: 'RadioButtons' },
|
|
172
|
+
{ type: 'alternative.create', questionId: 'q-1', alternativeId: 'a-1', label: 'Ja' },
|
|
173
|
+
])
|
|
174
|
+
|
|
175
|
+
const renamed = applyOperation(created, {
|
|
176
|
+
type: 'alternative.updateField',
|
|
177
|
+
questionId: 'q-1',
|
|
178
|
+
alternativeId: 'a-1',
|
|
179
|
+
field: 'label',
|
|
180
|
+
value: 'Ja, alltid',
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
assert.deepEqual(renamed.alternativesById, { 'a-1': { label: 'Ja, alltid' } })
|
|
184
|
+
assert.deepEqual(renamed.alternativeOrderByQuestionId, { 'q-1': ['a-1'] })
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('reorders alternatives without touching their values', () => {
|
|
188
|
+
const created = apply([
|
|
189
|
+
{ type: 'question.create', questionId: 'q-1', questionType: 'CheckBoxes' },
|
|
190
|
+
{ type: 'alternative.create', questionId: 'q-1', alternativeId: 'a-1', label: 'En' },
|
|
191
|
+
{ type: 'alternative.create', questionId: 'q-1', alternativeId: 'a-2', label: 'To' },
|
|
192
|
+
{ type: 'alternative.create', questionId: 'q-1', alternativeId: 'a-3', label: 'Tre' },
|
|
193
|
+
])
|
|
194
|
+
|
|
195
|
+
const moved = applyOperation(created, {
|
|
196
|
+
type: 'alternative.move',
|
|
197
|
+
questionId: 'q-1',
|
|
198
|
+
alternativeId: 'a-3',
|
|
199
|
+
toIndex: 0,
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
assert.deepEqual(moved.alternativeOrderByQuestionId?.['q-1'], ['a-3', 'a-1', 'a-2'])
|
|
203
|
+
assert.deepEqual(moved.alternativesById, created.alternativesById)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('refuses to edit or move an alternative through the wrong question', () => {
|
|
207
|
+
// An id that exists but hangs off another question means the clients disagree about
|
|
208
|
+
// structure; writing the value anyway would report success and diverge the documents.
|
|
209
|
+
const created = apply([
|
|
210
|
+
{ type: 'question.create', questionId: 'q-1', questionType: 'RadioButtons' },
|
|
211
|
+
{ type: 'question.create', questionId: 'q-2', questionType: 'RadioButtons' },
|
|
212
|
+
{ type: 'alternative.create', questionId: 'q-1', alternativeId: 'a-1', label: 'Ja' },
|
|
213
|
+
])
|
|
214
|
+
|
|
215
|
+
assert.throws(
|
|
216
|
+
() =>
|
|
217
|
+
applyOperation(created, {
|
|
218
|
+
type: 'alternative.updateField',
|
|
219
|
+
questionId: 'q-2',
|
|
220
|
+
alternativeId: 'a-1',
|
|
221
|
+
field: 'label',
|
|
222
|
+
value: 'Nei',
|
|
223
|
+
}),
|
|
224
|
+
OperationConflictError,
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
assert.throws(
|
|
228
|
+
() => applyOperation(created, { type: 'alternative.move', questionId: 'q-2', alternativeId: 'a-1', toIndex: 0 }),
|
|
229
|
+
OperationConflictError,
|
|
230
|
+
)
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('refuses to edit an alternative that does not exist', () => {
|
|
234
|
+
const created = apply([{ type: 'question.create', questionId: 'q-1', questionType: 'RadioButtons' }])
|
|
235
|
+
|
|
236
|
+
assert.throws(
|
|
237
|
+
() =>
|
|
238
|
+
applyOperation(created, {
|
|
239
|
+
type: 'alternative.updateField',
|
|
240
|
+
questionId: 'q-1',
|
|
241
|
+
alternativeId: 'ghost',
|
|
242
|
+
field: 'label',
|
|
243
|
+
value: 'Ja',
|
|
244
|
+
}),
|
|
245
|
+
OperationConflictError,
|
|
246
|
+
)
|
|
247
|
+
})
|
|
248
|
+
|
|
97
249
|
it('refuses a duplicate create as a conflict', () => {
|
|
98
250
|
const once = applyOperation(doc0, { type: 'question.create', questionId: 'q-1', questionType: 'TextShort' })
|
|
99
251
|
|