asma-core-helpers 0.25.0 → 0.27.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 +237 -33
- 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 +35 -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 +101 -1
- package/lib/collaboration/schemas.d.ts.map +1 -1
- package/lib/collaboration/schemas.js +109 -6
- package/lib/collaboration/schemas.js.map +1 -1
- package/lib/collaboration/templateDocument.d.ts +28 -1
- package/lib/collaboration/templateDocument.d.ts.map +1 -1
- package/lib/collaboration/templateDocument.js.map +1 -1
- package/lib/collaboration/testHelpers/documentGenerator.d.ts +4 -0
- package/lib/collaboration/testHelpers/documentGenerator.d.ts.map +1 -1
- package/lib/collaboration/testHelpers/documentGenerator.js +100 -4
- package/lib/collaboration/testHelpers/documentGenerator.js.map +1 -1
- package/lib/validation/index.d.ts +9 -0
- package/lib/validation/index.d.ts.map +1 -0
- package/lib/validation/index.js +9 -0
- package/lib/validation/index.js.map +1 -0
- package/lib/validation/messages.d.ts +43 -0
- package/lib/validation/messages.d.ts.map +1 -0
- package/lib/validation/messages.js +44 -0
- package/lib/validation/messages.js.map +1 -0
- package/lib/validation/rules.d.ts +11 -0
- package/lib/validation/rules.d.ts.map +1 -0
- package/lib/validation/rules.js +28 -0
- package/lib/validation/rules.js.map +1 -0
- package/package.json +5 -1
- package/src/collaboration/applyOperation.test.ts +240 -1
- package/src/collaboration/applyOperation.ts +280 -36
- package/src/collaboration/index.ts +1 -0
- package/src/collaboration/operations.ts +35 -0
- package/src/collaboration/property.test.ts +20 -0
- package/src/collaboration/schemas.test.ts +87 -1
- package/src/collaboration/schemas.ts +137 -1
- package/src/collaboration/templateDocument.ts +27 -1
- package/src/collaboration/testHelpers/documentGenerator.ts +101 -5
- package/src/validation/index.ts +17 -0
- package/src/validation/messages.test.ts +41 -0
- package/src/validation/messages.ts +66 -0
- package/src/validation/rules.test.ts +72 -0
- package/src/validation/rules.ts +32 -0
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
applyOperation,
|
|
9
9
|
} from './applyOperation.js'
|
|
10
10
|
import type { TemplateOp } from './operations.js'
|
|
11
|
-
import { emptyTemplateDocument } from './templateDocument.js'
|
|
11
|
+
import { emptyTemplateDocument, type QnrTemplateDocument } from './templateDocument.js'
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Guards the invariants a consumer would notice if a publish broke them. The exhaustive
|
|
@@ -59,6 +59,199 @@ describe('applyOperation', () => {
|
|
|
59
59
|
assert.deepEqual(moved.questionOrder, ['q-2', 'q-3', 'q-1'])
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
+
it('creates an ordered grid-owned column without adding it to the top-level order', () => {
|
|
63
|
+
const grid = apply([{ type: 'question.create', questionId: 'g-1', questionType: 'QuestionGrid' }])
|
|
64
|
+
|
|
65
|
+
const withColumns = apply(
|
|
66
|
+
[
|
|
67
|
+
{
|
|
68
|
+
type: 'gridColumn.create',
|
|
69
|
+
questionId: 'g-1',
|
|
70
|
+
columnQuestionId: 'c-1',
|
|
71
|
+
questionType: 'TextShort',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'gridColumn.create',
|
|
75
|
+
questionId: 'g-1',
|
|
76
|
+
columnQuestionId: 'c-2',
|
|
77
|
+
questionType: 'DateField',
|
|
78
|
+
atIndex: 0,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
grid,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
assert.deepEqual(withColumns.questionOrder, ['g-1'])
|
|
85
|
+
assert.deepEqual(withColumns.questionsById?.['g-1']?.grid?.columnIds, ['c-2', 'c-1'])
|
|
86
|
+
assert.deepEqual(withColumns.questionsById?.['c-1'], { type: 'TextShort' })
|
|
87
|
+
assert.deepEqual(withColumns.questionsById?.['c-2'], { type: 'DateField' })
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('refuses every grid-column operation through a non-grid question', () => {
|
|
91
|
+
const ordinary = apply([{ type: 'question.create', questionId: 'q-1', questionType: 'TextShort' }])
|
|
92
|
+
|
|
93
|
+
assert.throws(
|
|
94
|
+
() =>
|
|
95
|
+
applyOperation(ordinary, {
|
|
96
|
+
type: 'gridColumn.create',
|
|
97
|
+
questionId: 'q-1',
|
|
98
|
+
columnQuestionId: 'c-1',
|
|
99
|
+
questionType: 'TextShort',
|
|
100
|
+
}),
|
|
101
|
+
OperationConflictError,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
const malformed = {
|
|
105
|
+
...ordinary,
|
|
106
|
+
questionsById: {
|
|
107
|
+
'q-1': { type: 'TextShort', grid: { columnIds: ['c-1'] } },
|
|
108
|
+
'c-1': { type: 'TextShort' },
|
|
109
|
+
},
|
|
110
|
+
} satisfies QnrTemplateDocument
|
|
111
|
+
|
|
112
|
+
assert.throws(
|
|
113
|
+
() =>
|
|
114
|
+
applyOperation(malformed, {
|
|
115
|
+
type: 'gridColumn.move',
|
|
116
|
+
questionId: 'q-1',
|
|
117
|
+
columnQuestionId: 'c-1',
|
|
118
|
+
toIndex: 0,
|
|
119
|
+
}),
|
|
120
|
+
OperationConflictError,
|
|
121
|
+
)
|
|
122
|
+
assert.throws(
|
|
123
|
+
() =>
|
|
124
|
+
applyOperation(malformed, {
|
|
125
|
+
type: 'gridColumn.setLayout',
|
|
126
|
+
questionId: 'q-1',
|
|
127
|
+
columnQuestionId: 'c-1',
|
|
128
|
+
placement: { row: 0, cell: 0 },
|
|
129
|
+
}),
|
|
130
|
+
OperationConflictError,
|
|
131
|
+
)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('moves a column only inside its grid and refuses to inject it into the top-level order', () => {
|
|
135
|
+
const withColumns = apply([
|
|
136
|
+
{ type: 'question.create', questionId: 'g-1', questionType: 'QuestionGrid' },
|
|
137
|
+
{
|
|
138
|
+
type: 'gridColumn.create',
|
|
139
|
+
questionId: 'g-1',
|
|
140
|
+
columnQuestionId: 'c-1',
|
|
141
|
+
questionType: 'TextShort',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
type: 'gridColumn.create',
|
|
145
|
+
questionId: 'g-1',
|
|
146
|
+
columnQuestionId: 'c-2',
|
|
147
|
+
questionType: 'DateField',
|
|
148
|
+
},
|
|
149
|
+
])
|
|
150
|
+
|
|
151
|
+
const moved = applyOperation(withColumns, {
|
|
152
|
+
type: 'gridColumn.move',
|
|
153
|
+
questionId: 'g-1',
|
|
154
|
+
columnQuestionId: 'c-1',
|
|
155
|
+
toIndex: 1,
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
assert.deepEqual(moved.questionsById?.['g-1']?.grid?.columnIds, ['c-2', 'c-1'])
|
|
159
|
+
assert.deepEqual(moved.questionOrder, ['g-1'])
|
|
160
|
+
assert.throws(
|
|
161
|
+
() => applyOperation(moved, { type: 'question.move', questionId: 'c-1', toIndex: 0 }),
|
|
162
|
+
OperationConflictError,
|
|
163
|
+
)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('sets and clears a grid column layout as one atomic placement', () => {
|
|
167
|
+
const withColumn = apply([
|
|
168
|
+
{ type: 'question.create', questionId: 'g-1', questionType: 'QuestionGrid' },
|
|
169
|
+
{
|
|
170
|
+
type: 'gridColumn.create',
|
|
171
|
+
questionId: 'g-1',
|
|
172
|
+
columnQuestionId: 'c-1',
|
|
173
|
+
questionType: 'TextShort',
|
|
174
|
+
},
|
|
175
|
+
])
|
|
176
|
+
|
|
177
|
+
const placed = applyOperation(withColumn, {
|
|
178
|
+
type: 'gridColumn.setLayout',
|
|
179
|
+
questionId: 'g-1',
|
|
180
|
+
columnQuestionId: 'c-1',
|
|
181
|
+
placement: { row: 2, cell: 1, keepCellSize: true },
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
assert.deepEqual(placed.questionsById?.['g-1']?.presentation?.rowEditor, {
|
|
185
|
+
layoutByQuestionId: { 'c-1': { row: 2, cell: 1, keepCellSize: true } },
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
const cleared = applyOperation(placed, {
|
|
189
|
+
type: 'gridColumn.setLayout',
|
|
190
|
+
questionId: 'g-1',
|
|
191
|
+
columnQuestionId: 'c-1',
|
|
192
|
+
placement: null,
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
assert.equal(cleared.questionsById?.['g-1']?.presentation, undefined)
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('deletes a column from grid cells and every convention-named presentation map', () => {
|
|
199
|
+
const withColumns = apply([
|
|
200
|
+
{ type: 'question.create', questionId: 'g-1', questionType: 'QuestionGrid' },
|
|
201
|
+
{
|
|
202
|
+
type: 'gridColumn.create',
|
|
203
|
+
questionId: 'g-1',
|
|
204
|
+
columnQuestionId: 'c-1',
|
|
205
|
+
questionType: 'TextShort',
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
type: 'gridColumn.create',
|
|
209
|
+
questionId: 'g-1',
|
|
210
|
+
columnQuestionId: 'c-2',
|
|
211
|
+
questionType: 'TextShort',
|
|
212
|
+
},
|
|
213
|
+
{ type: 'gridRow.create', questionId: 'g-1', rowId: 'r-1' },
|
|
214
|
+
{ type: 'gridRow.updateCell', questionId: 'g-1', rowId: 'r-1', columnQuestionId: 'c-1', value: 'one' },
|
|
215
|
+
{ type: 'gridRow.updateCell', questionId: 'g-1', rowId: 'r-1', columnQuestionId: 'c-2', value: 'two' },
|
|
216
|
+
])
|
|
217
|
+
const authored = {
|
|
218
|
+
...withColumns,
|
|
219
|
+
questionsById: {
|
|
220
|
+
...withColumns.questionsById,
|
|
221
|
+
'g-1': {
|
|
222
|
+
...withColumns.questionsById?.['g-1'],
|
|
223
|
+
presentation: {
|
|
224
|
+
rowEditor: {
|
|
225
|
+
layoutByQuestionId: {
|
|
226
|
+
'c-1': { row: 0, cell: 0 },
|
|
227
|
+
'c-2': { row: 0, cell: 1 },
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
defaultColumnWidthsByQuestionId: { 'c-1': 120, 'c-2': 160 },
|
|
231
|
+
soloByQuestionId: { 'c-1': 'remove-the-empty-map' },
|
|
232
|
+
toolbar: {
|
|
233
|
+
labelsByQuestionId: { 'c-1': 'First', 'c-2': 'Second' },
|
|
234
|
+
theme: 'compact',
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const deleted = applyOperation(authored, { type: 'question.delete', questionId: 'c-1' })
|
|
242
|
+
const presentation = deleted.questionsById?.['g-1']?.presentation
|
|
243
|
+
|
|
244
|
+
assert.deepEqual(deleted.questionsById?.['g-1']?.grid?.columnIds, ['c-2'])
|
|
245
|
+
assert.deepEqual(deleted.gridRowsById?.['r-1']?.cells, { 'c-2': 'two' })
|
|
246
|
+
assert.deepEqual(presentation?.rowEditor?.layoutByQuestionId, { 'c-2': { row: 0, cell: 1 } })
|
|
247
|
+
assert.deepEqual(presentation?.defaultColumnWidthsByQuestionId, { 'c-2': 160 })
|
|
248
|
+
assert.equal(presentation?.soloByQuestionId, undefined)
|
|
249
|
+
assert.deepEqual(presentation?.toolbar, {
|
|
250
|
+
labelsByQuestionId: { 'c-2': 'Second' },
|
|
251
|
+
theme: 'compact',
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
|
|
62
255
|
it('drops the bindings that targeted a deleted question, keeping the shared node', () => {
|
|
63
256
|
const bound = apply([
|
|
64
257
|
{ type: 'question.create', questionId: 'q-1', questionType: 'TextShort' },
|
|
@@ -282,6 +475,14 @@ describe('applyOperation', () => {
|
|
|
282
475
|
{ type: 'question.create', questionId: 'q-2', questionType: 'TextShort' },
|
|
283
476
|
{ type: 'visibilityRule.set', ruleId: 'vr-1', questionId: 'q-1', condition: { sourceQuestionId: 'q-2', value: 'x' } },
|
|
284
477
|
{ type: 'highlightRule.set', ruleId: 'hr-1', questionId: 'q-1', condition: { sourceQuestionId: 'q-2', value: 'y' } },
|
|
478
|
+
{ type: 'narrativeRule.set', ruleId: 'nr-1', questionId: 'q-1', condition: { sourceQuestionId: 'q-2' } },
|
|
479
|
+
{
|
|
480
|
+
type: 'qnrRule.set',
|
|
481
|
+
ruleId: 'qr-1',
|
|
482
|
+
questionId: 'q-1',
|
|
483
|
+
condition: { sourceQuestionId: 'q-1' },
|
|
484
|
+
templateFamilyId: 'family-1',
|
|
485
|
+
},
|
|
285
486
|
])
|
|
286
487
|
|
|
287
488
|
const deleted = applyOperation(doc, { type: 'question.delete', questionId: 'q-1' })
|
|
@@ -290,6 +491,44 @@ describe('applyOperation', () => {
|
|
|
290
491
|
assert.equal(deleted.visibilityRuleOrderByQuestionId, undefined)
|
|
291
492
|
assert.equal(deleted.highlightRulesById, undefined)
|
|
292
493
|
assert.equal(deleted.highlightRuleOrderByQuestionId, undefined)
|
|
494
|
+
assert.equal(deleted.narrativeRulesById, undefined)
|
|
495
|
+
assert.equal(deleted.narrativeRuleOrderByQuestionId, undefined)
|
|
496
|
+
assert.equal(deleted.qnrRulesById, undefined)
|
|
497
|
+
assert.equal(deleted.qnrRuleOrderByQuestionId, undefined)
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
it('stores narrative and qnr rules in root collections with per-question primitive order', () => {
|
|
501
|
+
const doc = apply([
|
|
502
|
+
{ type: 'question.create', questionId: 'q-1', questionType: 'TextShort' },
|
|
503
|
+
{ type: 'question.create', questionId: 'q-2', questionType: 'TextShort' },
|
|
504
|
+
{ type: 'narrativeRule.set', ruleId: 'nr-1', questionId: 'q-1', condition: { sourceQuestionId: 'q-2' } },
|
|
505
|
+
{
|
|
506
|
+
type: 'qnrRule.set',
|
|
507
|
+
ruleId: 'qr-1',
|
|
508
|
+
questionId: 'q-1',
|
|
509
|
+
condition: { sourceQuestionId: 'q-1', value: 'yes' },
|
|
510
|
+
templateFamilyId: 'family-1',
|
|
511
|
+
},
|
|
512
|
+
])
|
|
513
|
+
|
|
514
|
+
assert.deepEqual(doc.narrativeRulesById, {
|
|
515
|
+
'nr-1': { condition: { sourceQuestionId: 'q-2' } },
|
|
516
|
+
})
|
|
517
|
+
assert.deepEqual(doc.narrativeRuleOrderByQuestionId, { 'q-1': ['nr-1'] })
|
|
518
|
+
assert.deepEqual(doc.qnrRulesById, {
|
|
519
|
+
'qr-1': {
|
|
520
|
+
condition: { sourceQuestionId: 'q-1', value: 'yes' },
|
|
521
|
+
templateFamilyId: 'family-1',
|
|
522
|
+
},
|
|
523
|
+
})
|
|
524
|
+
assert.deepEqual(doc.qnrRuleOrderByQuestionId, { 'q-1': ['qr-1'] })
|
|
525
|
+
|
|
526
|
+
const withoutNarrative = applyOperation(doc, { type: 'narrativeRule.delete', ruleId: 'nr-1' })
|
|
527
|
+
const withoutEither = applyOperation(withoutNarrative, { type: 'qnrRule.delete', ruleId: 'qr-1' })
|
|
528
|
+
assert.equal(withoutEither.narrativeRulesById, undefined)
|
|
529
|
+
assert.equal(withoutEither.narrativeRuleOrderByQuestionId, undefined)
|
|
530
|
+
assert.equal(withoutEither.qnrRulesById, undefined)
|
|
531
|
+
assert.equal(withoutEither.qnrRuleOrderByQuestionId, undefined)
|
|
293
532
|
})
|
|
294
533
|
|
|
295
534
|
it('keeps another question\'s rule that references the deleted question, for validation to surface', () => {
|