asma-core-helpers 0.19.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.
Files changed (35) hide show
  1. package/lib/collaboration/answerDocument.d.ts +50 -0
  2. package/lib/collaboration/answerDocument.d.ts.map +1 -0
  3. package/lib/collaboration/answerDocument.js +10 -0
  4. package/lib/collaboration/answerDocument.js.map +1 -0
  5. package/lib/collaboration/answerOperations.d.ts +40 -0
  6. package/lib/collaboration/answerOperations.d.ts.map +1 -0
  7. package/lib/collaboration/answerOperations.js +9 -0
  8. package/lib/collaboration/answerOperations.js.map +1 -0
  9. package/lib/collaboration/applyOperation.d.ts.map +1 -1
  10. package/lib/collaboration/applyOperation.js +233 -0
  11. package/lib/collaboration/applyOperation.js.map +1 -1
  12. package/lib/collaboration/canonicalize.d.ts +61 -0
  13. package/lib/collaboration/canonicalize.d.ts.map +1 -0
  14. package/lib/collaboration/canonicalize.js +184 -0
  15. package/lib/collaboration/canonicalize.js.map +1 -0
  16. package/lib/collaboration/docLaws.d.ts +58 -0
  17. package/lib/collaboration/docLaws.d.ts.map +1 -0
  18. package/lib/collaboration/docLaws.js +71 -0
  19. package/lib/collaboration/docLaws.js.map +1 -0
  20. package/lib/collaboration/operations.d.ts +93 -4
  21. package/lib/collaboration/operations.d.ts.map +1 -1
  22. package/lib/collaboration/operations.js +23 -8
  23. package/lib/collaboration/operations.js.map +1 -1
  24. package/lib/collaboration/templateDocument.d.ts +128 -4
  25. package/lib/collaboration/templateDocument.d.ts.map +1 -1
  26. package/lib/collaboration/templateDocument.js +3 -3
  27. package/lib/collaboration/templateDocument.js.map +1 -1
  28. package/package.json +2 -1
  29. package/src/collaboration/answerDocument.ts +57 -0
  30. package/src/collaboration/answerOperations.ts +34 -0
  31. package/src/collaboration/applyOperation.ts +248 -1
  32. package/src/collaboration/canonicalize.ts +209 -0
  33. package/src/collaboration/docLaws.ts +123 -0
  34. package/src/collaboration/operations.ts +87 -12
  35. 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
 
15
15
  import type { QuestionSubtype, QuestionType } from './questionTypes.js'
@@ -23,10 +23,93 @@ export type NodeId = string
23
23
  export type BindingId = string
24
24
  export type FilterId = string
25
25
  export type MappingId = string
26
+ export type VisibilityRuleId = string
27
+ export type HighlightRuleId = string
26
28
 
27
29
  /** A scalar a document may carry. Deliberately not `any`: DOC-LAW-2 bans `null`. */
28
30
  export type DocScalar = string | number | boolean
29
31
 
32
+ /**
33
+ * The required access level of the pinned version (OQ-V2-2): 1 anonymous, 2 identifiable
34
+ * without authentication, 3 lower-assurance authentication, 4 BankID. Never collapsed
35
+ * to a boolean; `invitationRequired` is a separate axis.
36
+ */
37
+ export type RequiredAccessLevel = 1 | 2 | 3 | 4
38
+
39
+ /** Who the questionnaire is initiated by (OQ-V2-15 wire vocabulary). */
40
+ export type Initiator = 'coordinator' | 'recipient'
41
+
42
+ /**
43
+ * What happens to in-flight instances when the family publishes a new version
44
+ * (OQ-V2-16, IMM-I5). v1 implements `never`; `always`/`ask` land later.
45
+ */
46
+ export type TemplateUpdateMode = 'never' | 'always' | 'ask'
47
+
48
+ /**
49
+ * The typed semantic body of the document (`meta`). Absent means the default, per
50
+ * DOC-LAW-2 — a questionnaire that requires nothing special stores `meta` with only
51
+ * what differs. Fields still open after the naming freeze (Gate-4) ride the index
52
+ * signature; the decided fields are spelled out so a typo is a compile error.
53
+ */
54
+ export type QnrTemplateMeta = {
55
+ title?: string
56
+ description?: string
57
+ /** Journal-wiring settings (M-007 aliases normalize here). */
58
+ settings?: {
59
+ journal?: {
60
+ /** `activityId_required`/`soknadid_required`/`sokndaid_required` unify here (architecture §2.2(7)). */
61
+ requires_activity_id?: boolean
62
+ }
63
+ /** Recipient-side requirements. */
64
+ recipient?: {
65
+ /** Legacy `ask_for_phone_nr`. */
66
+ ask_for_phone_nr?: boolean
67
+ }
68
+ }
69
+ /** Admission policy of the pinned version (OQ-V2-2/15/16). */
70
+ instancePolicy?: {
71
+ requiredAccessLevel?: RequiredAccessLevel
72
+ /** Open level-1 is invitation-free; invitation-protected level-1 sets this. */
73
+ invitationRequired?: boolean
74
+ initiator?: Initiator
75
+ template_update_mode?: TemplateUpdateMode
76
+ }
77
+ /** Presentation profiles (PM-6): audience/flow/layout/visibility — still loose pending their editor. */
78
+ presentationProfiles?: Record<string, unknown>
79
+ /** Owner-domain soft references (REQ-013): ids only, no bodies, no FK validation. */
80
+ compatibility?: {
81
+ consentTemplateIds?: string[]
82
+ smsTemplateIds?: string[]
83
+ }
84
+ [key: string]: unknown
85
+ }
86
+
87
+ /**
88
+ * The per-question-type configuration of a `QuestionGrid` (OQ-V2-17) — the repeat
89
+ * policy of the grid's rows. Lives at `question.grid.*`.
90
+ */
91
+ export type QuestionGridConfig = {
92
+ minRows?: number
93
+ maxRows?: number
94
+ /** `single_row` in OQ-V2-17 prose — max 1 row. */
95
+ singleRow?: boolean
96
+ deletableRows?: boolean
97
+ alwaysNew?: boolean
98
+ timestamps?: boolean
99
+ }
100
+
101
+ /**
102
+ * Grid-owned presentation (OQ-V2-17/25): row-editor layout, filters, grid actions,
103
+ * highlight rules, the header-tab reference and authored default column widths live
104
+ * here — there is no parallel `settings_ui` or `layoutByQuestionId` map.
105
+ */
106
+ export type QuestionGridPresentation = {
107
+ headerTabId?: TabId
108
+ /** OQ-V2-25: authored defaults; per-user widths are preference state outside both documents. */
109
+ defaultColumnWidthsByQuestionId?: Record<QuestionId, number>
110
+ [key: string]: unknown
111
+ }
112
+
30
113
  /**
31
114
  * `type` is the question's own discriminator (M-062), a closed union rather than a string — see
32
115
  * `questionTypes.ts` for why the value cannot be loose. Not to be confused with the other `kind`
@@ -39,14 +122,42 @@ export type QnrQuestion = {
39
122
  label?: string
40
123
  required?: boolean
41
124
  defaultValue?: DocScalar
125
+ /** `QuestionGrid` only: the row repeat policy. */
126
+ grid?: QuestionGridConfig
127
+ /** `QuestionGrid` only: grid-owned presentation (layout, filters, actions, column widths). */
128
+ presentation?: QuestionGridPresentation
42
129
  [key: string]: unknown
43
130
  }
44
131
 
45
132
  export type QnrAlternative = { label?: string; value?: DocScalar; [key: string]: unknown }
46
- export type QnrGridRow = { label?: string; [key: string]: unknown }
133
+
134
+ /** An authored predefined grid row; cells are keyed by column question id. */
135
+ export type QnrGridRow = {
136
+ label?: string
137
+ /** Authored default cell values, keyed by the column question id. */
138
+ cells?: Record<QuestionId, DocScalar>
139
+ [key: string]: unknown
140
+ }
141
+
47
142
  export type QnrTab = { label?: string; [key: string]: unknown }
48
143
  export type QnrAction = { kind?: string; [key: string]: unknown }
49
144
 
145
+ /**
146
+ * A typed conditional (OQ-V2-17/architecture §2.2(4)): question visibility/highlight
147
+ * depends on another question's answer. Legacy `dependent_question`+`dependent_questions`
148
+ * duals normalize into rule collections (byId + per-question order, DOC-LAW-1).
149
+ */
150
+ export type RuleCondition = {
151
+ sourceQuestionId: QuestionId
152
+ alternativeId?: AltId
153
+ operator?: string
154
+ value?: DocScalar
155
+ [key: string]: unknown
156
+ }
157
+
158
+ export type VisibilityRule = { condition: RuleCondition; [key: string]: unknown }
159
+ export type HighlightRule = { condition: RuleCondition; [key: string]: unknown }
160
+
50
161
  /** One traversal step. Many questions off one entity share a single node (§2.2a). */
51
162
  export type MappingNode = {
52
163
  entityId: string
@@ -84,7 +195,7 @@ export type MappingFilter = {
84
195
  export type QnrTemplateDocument = {
85
196
  documentId: string
86
197
  revision: number
87
- meta?: Record<string, unknown>
198
+ meta?: QnrTemplateMeta
88
199
  questionsById?: Record<QuestionId, QnrQuestion>
89
200
  questionOrder: QuestionId[]
90
201
  gridRowsById?: Record<RowId, QnrGridRow>
@@ -94,12 +205,33 @@ export type QnrTemplateDocument = {
94
205
  tabsById?: Record<TabId, QnrTab>
95
206
  tabOrder?: TabId[]
96
207
  actionsById?: Record<ActionId, QnrAction>
208
+ visibilityRulesById?: Record<VisibilityRuleId, VisibilityRule>
209
+ visibilityRuleOrderByQuestionId?: Record<QuestionId, VisibilityRuleId[]>
210
+ highlightRulesById?: Record<HighlightRuleId, HighlightRule>
211
+ highlightRuleOrderByQuestionId?: Record<QuestionId, HighlightRuleId[]>
97
212
  dataMappingsById?: Record<MappingId, { sourceId: string; rootNodeId: NodeId; bindingOrder?: BindingId[] }>
98
213
  mappingNodesById?: Record<NodeId, MappingNode>
99
214
  mappingBindingsById?: Record<BindingId, MappingBinding>
100
215
  mappingFiltersById?: Record<FilterId, MappingFilter>
101
216
  }
102
217
 
218
+ /**
219
+ * A reusable question-template bundle (OQ-V2-1): the root question plus every owned
220
+ * child question, alternative, predefined grid row, scoped tab/action, order and
221
+ * internal reference needed to use it. Stored whole in `qnr_question_templates.bundle`;
222
+ * a manual pick deep-copies and validates it into the family document.
223
+ */
224
+ export type QnrQuestionBundle = {
225
+ rootQuestionId: QuestionId
226
+ questionsById: Record<QuestionId, QnrQuestion>
227
+ gridRowsById?: Record<RowId, QnrGridRow>
228
+ gridRowOrderByQuestionId?: Record<QuestionId, RowId[]>
229
+ alternativesById?: Record<AltId, QnrAlternative>
230
+ alternativeOrderByQuestionId?: Record<QuestionId, AltId[]>
231
+ tabsById?: Record<TabId, QnrTab>
232
+ actionsById?: Record<ActionId, QnrAction>
233
+ }
234
+
103
235
  /**
104
236
  * A new family's document. `questionOrder` is present-and-empty rather than absent
105
237
  * because it is the document's only structural array and every reader indexes it; an