asma-core-helpers 0.16.0 → 0.17.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 +34 -0
- package/lib/collaboration/applyOperation.d.ts.map +1 -0
- package/lib/collaboration/applyOperation.js +319 -0
- package/lib/collaboration/applyOperation.js.map +1 -0
- package/lib/collaboration/index.d.ts +24 -0
- package/lib/collaboration/index.d.ts.map +1 -0
- package/lib/collaboration/index.js +24 -0
- package/lib/collaboration/index.js.map +1 -0
- package/lib/collaboration/operations.d.ts +89 -0
- package/lib/collaboration/operations.d.ts.map +1 -0
- package/lib/collaboration/operations.js +22 -0
- package/lib/collaboration/operations.js.map +1 -0
- package/lib/collaboration/templateDocument.d.ts +112 -0
- package/lib/collaboration/templateDocument.d.ts.map +1 -0
- package/lib/collaboration/templateDocument.js +24 -0
- package/lib/collaboration/templateDocument.js.map +1 -0
- package/package.json +5 -1
- package/src/collaboration/applyOperation.test.ts +124 -0
- package/src/collaboration/applyOperation.ts +358 -0
- package/src/collaboration/index.ts +24 -0
- package/src/collaboration/operations.ts +73 -0
- package/src/collaboration/templateDocument.ts +103 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TemplateOp } from './operations.js';
|
|
2
|
+
import type { QnrTemplateDocument } from './templateDocument.js';
|
|
3
|
+
/**
|
|
4
|
+
* The authoring reducer. Pure: takes a document and an op, returns a new document with
|
|
5
|
+
* `revision` bumped by one. The frontend applies it locally before the op leaves the
|
|
6
|
+
* client and bunjs applies it authoritatively before the op becomes durable, so any
|
|
7
|
+
* divergence between the two is a data-loss bug — hence one implementation, not two.
|
|
8
|
+
*
|
|
9
|
+
* Idempotency by `op_id` and revision assignment on the wire are persistence concerns
|
|
10
|
+
* and deliberately live outside this function.
|
|
11
|
+
*
|
|
12
|
+
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:380 (vocabulary)
|
|
13
|
+
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:384 (authoring dataflow)
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Base for the reducer's typed failures. A plain `Error` subclass on purpose: this module
|
|
17
|
+
* also runs in the browser, and bunjs's `CustomError` reaches `@hono/zod-openapi`, the AI
|
|
18
|
+
* vendor error and the logger — none of which can ship to a client. It carries the two
|
|
19
|
+
* fields the service's error resolver reads, so bunjs maps it losslessly to the same
|
|
20
|
+
* status and code the `CustomError` subclasses produced (`processErrorDoNotNotify`).
|
|
21
|
+
*/
|
|
22
|
+
export declare class CollaborationError extends Error {
|
|
23
|
+
readonly statusCode: number;
|
|
24
|
+
readonly code: string;
|
|
25
|
+
constructor(message: string, statusCode: number, code: string);
|
|
26
|
+
}
|
|
27
|
+
export declare class UnknownOperationError extends CollaborationError {
|
|
28
|
+
constructor(type: string);
|
|
29
|
+
}
|
|
30
|
+
export declare class OperationConflictError extends CollaborationError {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
export declare const applyOperation: (document: QnrTemplateDocument, op: TemplateOp) => QnrTemplateDocument;
|
|
34
|
+
//# sourceMappingURL=applyOperation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyOperation.d.ts","sourceRoot":"","sources":["../../src/collaboration/applyOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAiB,mBAAmB,EAAc,MAAM,uBAAuB,CAAA;AAE3F;;;;;;;;;;;GAWG;AAEH;;;;;;GAMG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IACzC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB,YAAY,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAK5D;CACJ;AAED,qBAAa,qBAAsB,SAAQ,kBAAkB;IACzD,YAAY,IAAI,EAAE,MAAM,EAEvB;CACJ;AAED,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC1D,YAAY,OAAO,EAAE,MAAM,EAE1B;CACJ;AAkGD,eAAO,MAAM,cAAc,aAAc,mBAAmB,MAAM,UAAU,KAAG,mBAG9E,CAAA"}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The authoring reducer. Pure: takes a document and an op, returns a new document with
|
|
3
|
+
* `revision` bumped by one. The frontend applies it locally before the op leaves the
|
|
4
|
+
* client and bunjs applies it authoritatively before the op becomes durable, so any
|
|
5
|
+
* divergence between the two is a data-loss bug — hence one implementation, not two.
|
|
6
|
+
*
|
|
7
|
+
* Idempotency by `op_id` and revision assignment on the wire are persistence concerns
|
|
8
|
+
* and deliberately live outside this function.
|
|
9
|
+
*
|
|
10
|
+
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:380 (vocabulary)
|
|
11
|
+
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:384 (authoring dataflow)
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Base for the reducer's typed failures. A plain `Error` subclass on purpose: this module
|
|
15
|
+
* also runs in the browser, and bunjs's `CustomError` reaches `@hono/zod-openapi`, the AI
|
|
16
|
+
* vendor error and the logger — none of which can ship to a client. It carries the two
|
|
17
|
+
* fields the service's error resolver reads, so bunjs maps it losslessly to the same
|
|
18
|
+
* status and code the `CustomError` subclasses produced (`processErrorDoNotNotify`).
|
|
19
|
+
*/
|
|
20
|
+
export class CollaborationError extends Error {
|
|
21
|
+
statusCode;
|
|
22
|
+
code;
|
|
23
|
+
constructor(message, statusCode, code) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'CollaborationError';
|
|
26
|
+
this.statusCode = statusCode;
|
|
27
|
+
this.code = code;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class UnknownOperationError extends CollaborationError {
|
|
31
|
+
constructor(type) {
|
|
32
|
+
super(`Unknown qnr template operation "${type}"`, 422, 'qnr_unknown_operation');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class OperationConflictError extends CollaborationError {
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super(message, 409, 'qnr_operation_conflict');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Serialises a binding target so the "one binding per target" invariant is checkable. */
|
|
41
|
+
const targetKey = (target) => target.kind === 'question'
|
|
42
|
+
? `question:${target.questionId}`
|
|
43
|
+
: `gridColumn:${target.gridQuestionId}:${target.columnQuestionId}`;
|
|
44
|
+
/** Sets a key, or removes it when the op carried an explicit unset. */
|
|
45
|
+
const writeField = (record, field, value) => {
|
|
46
|
+
const next = { ...record };
|
|
47
|
+
if (value === null || value === undefined)
|
|
48
|
+
delete next[field];
|
|
49
|
+
else
|
|
50
|
+
next[field] = value;
|
|
51
|
+
return next;
|
|
52
|
+
};
|
|
53
|
+
/** Inserts `id` at `index`, clamped into range. Absent index appends. */
|
|
54
|
+
const insertAt = (order, id, index) => {
|
|
55
|
+
const next = [...order];
|
|
56
|
+
const at = index === undefined ? next.length : Math.max(0, Math.min(index, next.length));
|
|
57
|
+
next.splice(at, 0, id);
|
|
58
|
+
return next;
|
|
59
|
+
};
|
|
60
|
+
const moveInOrder = (order, id, toIndex) => {
|
|
61
|
+
const without = order.filter((entry) => entry !== id);
|
|
62
|
+
const at = Math.max(0, Math.min(toIndex, without.length));
|
|
63
|
+
return [...without.slice(0, at), id, ...without.slice(at)];
|
|
64
|
+
};
|
|
65
|
+
const omitKey = (record, key) => {
|
|
66
|
+
const { [key]: _removed, ...rest } = record;
|
|
67
|
+
return rest;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Spreads `patch` onto `base`, **omitting** keys whose value is `undefined` rather than
|
|
71
|
+
* assigning it. Required by `exactOptionalPropertyTypes`: `{ ...doc, x: undefined }` is
|
|
72
|
+
* a type error, and it is also the wrong shape — an absent key and a key holding
|
|
73
|
+
* `undefined` serialise differently.
|
|
74
|
+
*/
|
|
75
|
+
const patchDocument = (base, patch) => {
|
|
76
|
+
const next = { ...base };
|
|
77
|
+
for (const [key, value] of Object.entries(patch)) {
|
|
78
|
+
if (value === undefined)
|
|
79
|
+
delete next[key];
|
|
80
|
+
else
|
|
81
|
+
next[key] = value;
|
|
82
|
+
}
|
|
83
|
+
return next;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* DOC-LAW-2 at the document boundary: an optional collection that just became empty is
|
|
87
|
+
* removed, so two documents with the same content are the same document.
|
|
88
|
+
*
|
|
89
|
+
* `questionOrder` is exempt — it is the one structural array every reader indexes, and
|
|
90
|
+
* making "no questions yet" indistinguishable from "malformed" would buy nothing.
|
|
91
|
+
*/
|
|
92
|
+
const OPTIONAL_COLLECTIONS = [
|
|
93
|
+
'meta',
|
|
94
|
+
'questionsById',
|
|
95
|
+
'gridRowsById',
|
|
96
|
+
'gridRowOrderByQuestionId',
|
|
97
|
+
'alternativesById',
|
|
98
|
+
'alternativeOrderByQuestionId',
|
|
99
|
+
'tabsById',
|
|
100
|
+
'tabOrder',
|
|
101
|
+
'actionsById',
|
|
102
|
+
'dataMappingsById',
|
|
103
|
+
'mappingNodesById',
|
|
104
|
+
'mappingBindingsById',
|
|
105
|
+
'mappingFiltersById',
|
|
106
|
+
];
|
|
107
|
+
const prune = (doc) => {
|
|
108
|
+
const next = { ...doc };
|
|
109
|
+
for (const key of OPTIONAL_COLLECTIONS) {
|
|
110
|
+
const value = next[key];
|
|
111
|
+
if (value === undefined)
|
|
112
|
+
continue;
|
|
113
|
+
const isEmpty = Array.isArray(value)
|
|
114
|
+
? value.length === 0
|
|
115
|
+
: typeof value === 'object' && value !== null && Object.keys(value).length === 0;
|
|
116
|
+
if (isEmpty)
|
|
117
|
+
delete next[key];
|
|
118
|
+
}
|
|
119
|
+
return next;
|
|
120
|
+
};
|
|
121
|
+
/** Drops every binding whose target no longer resolves to an existing question. */
|
|
122
|
+
const dropBindingsForQuestion = (doc, questionId) => {
|
|
123
|
+
if (!doc.mappingBindingsById)
|
|
124
|
+
return doc;
|
|
125
|
+
const kept = Object.entries(doc.mappingBindingsById).filter(([, binding]) => {
|
|
126
|
+
const { target } = binding;
|
|
127
|
+
return target.kind === 'question'
|
|
128
|
+
? target.questionId !== questionId
|
|
129
|
+
: target.gridQuestionId !== questionId && target.columnQuestionId !== questionId;
|
|
130
|
+
});
|
|
131
|
+
return { ...doc, mappingBindingsById: Object.fromEntries(kept) };
|
|
132
|
+
};
|
|
133
|
+
export const applyOperation = (document, op) => {
|
|
134
|
+
const next = reduce(document, op);
|
|
135
|
+
return prune({ ...next, revision: document.revision + 1 });
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* One switch over a closed vocabulary. Splitting it per entity family would hide the
|
|
139
|
+
* `never` exhaustiveness check that turns an unhandled op into a compile error.
|
|
140
|
+
*/
|
|
141
|
+
const reduce = (doc, op) => {
|
|
142
|
+
switch (op.type) {
|
|
143
|
+
case 'template.updateMeta': {
|
|
144
|
+
let meta = { ...(doc.meta ?? {}) };
|
|
145
|
+
for (const [key, value] of Object.entries(op.patch)) {
|
|
146
|
+
meta = writeField(meta, key, value);
|
|
147
|
+
}
|
|
148
|
+
return { ...doc, meta };
|
|
149
|
+
}
|
|
150
|
+
case 'question.create': {
|
|
151
|
+
if (doc.questionsById?.[op.questionId]) {
|
|
152
|
+
throw new OperationConflictError(`Question "${op.questionId}" already exists`);
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
...doc,
|
|
156
|
+
questionsById: { ...(doc.questionsById ?? {}), [op.questionId]: { kind: op.kind } },
|
|
157
|
+
questionOrder: insertAt(doc.questionOrder, op.questionId, op.atIndex),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
case 'question.updateField': {
|
|
161
|
+
const question = doc.questionsById?.[op.questionId];
|
|
162
|
+
if (!question) {
|
|
163
|
+
throw new OperationConflictError(`Unknown question "${op.questionId}"`);
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
...doc,
|
|
167
|
+
questionsById: {
|
|
168
|
+
...doc.questionsById,
|
|
169
|
+
[op.questionId]: writeField(question, op.field, op.value),
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
case 'question.move': {
|
|
174
|
+
if (!doc.questionsById?.[op.questionId]) {
|
|
175
|
+
throw new OperationConflictError(`Unknown question "${op.questionId}"`);
|
|
176
|
+
}
|
|
177
|
+
return { ...doc, questionOrder: moveInOrder(doc.questionOrder, op.questionId, op.toIndex) };
|
|
178
|
+
}
|
|
179
|
+
case 'question.delete': {
|
|
180
|
+
const alternativeIds = doc.alternativeOrderByQuestionId?.[op.questionId] ?? [];
|
|
181
|
+
let alternativesById = doc.alternativesById;
|
|
182
|
+
if (alternativesById) {
|
|
183
|
+
alternativesById = alternativeIds.reduce((acc, id) => omitKey(acc, id), alternativesById);
|
|
184
|
+
}
|
|
185
|
+
const withoutQuestion = patchDocument(doc, {
|
|
186
|
+
questionsById: doc.questionsById && omitKey(doc.questionsById, op.questionId),
|
|
187
|
+
questionOrder: doc.questionOrder.filter((id) => id !== op.questionId),
|
|
188
|
+
alternativesById,
|
|
189
|
+
alternativeOrderByQuestionId: doc.alternativeOrderByQuestionId && omitKey(doc.alternativeOrderByQuestionId, op.questionId),
|
|
190
|
+
gridRowOrderByQuestionId: doc.gridRowOrderByQuestionId && omitKey(doc.gridRowOrderByQuestionId, op.questionId),
|
|
191
|
+
});
|
|
192
|
+
// A binding pointing at a deleted question is an unresolvable reference the
|
|
193
|
+
// compiler would reject at publication; drop it with its target.
|
|
194
|
+
return dropBindingsForQuestion(withoutQuestion, op.questionId);
|
|
195
|
+
}
|
|
196
|
+
case 'alternative.create': {
|
|
197
|
+
if (!doc.questionsById?.[op.questionId]) {
|
|
198
|
+
throw new OperationConflictError(`Unknown question "${op.questionId}"`);
|
|
199
|
+
}
|
|
200
|
+
const order = doc.alternativeOrderByQuestionId?.[op.questionId] ?? [];
|
|
201
|
+
return {
|
|
202
|
+
...doc,
|
|
203
|
+
alternativesById: {
|
|
204
|
+
...(doc.alternativesById ?? {}),
|
|
205
|
+
[op.alternativeId]: op.label === undefined ? {} : { label: op.label },
|
|
206
|
+
},
|
|
207
|
+
alternativeOrderByQuestionId: {
|
|
208
|
+
...(doc.alternativeOrderByQuestionId ?? {}),
|
|
209
|
+
[op.questionId]: insertAt(order, op.alternativeId, op.atIndex),
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
case 'alternative.delete': {
|
|
214
|
+
const order = doc.alternativeOrderByQuestionId?.[op.questionId] ?? [];
|
|
215
|
+
const remaining = order.filter((id) => id !== op.alternativeId);
|
|
216
|
+
return patchDocument(doc, {
|
|
217
|
+
alternativesById: doc.alternativesById && omitKey(doc.alternativesById, op.alternativeId),
|
|
218
|
+
alternativeOrderByQuestionId: {
|
|
219
|
+
...(doc.alternativeOrderByQuestionId ?? {}),
|
|
220
|
+
[op.questionId]: remaining,
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
case 'mappingNode.create': {
|
|
225
|
+
if (doc.mappingNodesById?.[op.nodeId]) {
|
|
226
|
+
throw new OperationConflictError(`Mapping node "${op.nodeId}" already exists`);
|
|
227
|
+
}
|
|
228
|
+
const node = writeField(writeField({ entityId: op.entityId }, 'parentNodeId', op.parentNodeId ?? null), 'relationshipId', op.relationshipId ?? null);
|
|
229
|
+
return { ...doc, mappingNodesById: { ...(doc.mappingNodesById ?? {}), [op.nodeId]: node } };
|
|
230
|
+
}
|
|
231
|
+
case 'mappingNode.delete': {
|
|
232
|
+
const filterIds = doc.mappingNodesById?.[op.nodeId]?.filterOrder ?? [];
|
|
233
|
+
let filtersById = doc.mappingFiltersById;
|
|
234
|
+
if (filtersById) {
|
|
235
|
+
filtersById = filterIds.reduce((acc, id) => omitKey(acc, id), filtersById);
|
|
236
|
+
}
|
|
237
|
+
const bindings = Object.entries(doc.mappingBindingsById ?? {}).filter(([, binding]) => binding.nodeId !== op.nodeId);
|
|
238
|
+
return patchDocument(doc, {
|
|
239
|
+
mappingNodesById: doc.mappingNodesById && omitKey(doc.mappingNodesById, op.nodeId),
|
|
240
|
+
mappingFiltersById: filtersById,
|
|
241
|
+
mappingBindingsById: Object.fromEntries(bindings),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
case 'mappingBinding.create': {
|
|
245
|
+
if (!doc.mappingNodesById?.[op.nodeId]) {
|
|
246
|
+
throw new OperationConflictError(`Unknown mapping node "${op.nodeId}"`);
|
|
247
|
+
}
|
|
248
|
+
const wanted = targetKey(op.target);
|
|
249
|
+
const clash = Object.entries(doc.mappingBindingsById ?? {}).find(([, binding]) => targetKey(binding.target) === wanted);
|
|
250
|
+
if (clash) {
|
|
251
|
+
throw new OperationConflictError(`Target ${wanted} is already bound by "${clash[0]}" — at most one binding per target`);
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
...doc,
|
|
255
|
+
mappingBindingsById: {
|
|
256
|
+
...(doc.mappingBindingsById ?? {}),
|
|
257
|
+
[op.bindingId]: { nodeId: op.nodeId, fieldId: op.fieldId, target: op.target },
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
case 'mappingBinding.update': {
|
|
262
|
+
const binding = doc.mappingBindingsById?.[op.bindingId];
|
|
263
|
+
if (!binding) {
|
|
264
|
+
throw new OperationConflictError(`Unknown mapping binding "${op.bindingId}"`);
|
|
265
|
+
}
|
|
266
|
+
if (op.patch.nodeId && !doc.mappingNodesById?.[op.patch.nodeId]) {
|
|
267
|
+
throw new OperationConflictError(`Unknown mapping node "${op.patch.nodeId}"`);
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
...doc,
|
|
271
|
+
mappingBindingsById: {
|
|
272
|
+
...doc.mappingBindingsById,
|
|
273
|
+
[op.bindingId]: { ...binding, ...op.patch },
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
case 'mappingBinding.delete':
|
|
278
|
+
return patchDocument(doc, {
|
|
279
|
+
mappingBindingsById: doc.mappingBindingsById && omitKey(doc.mappingBindingsById, op.bindingId),
|
|
280
|
+
});
|
|
281
|
+
case 'mappingFilter.set': {
|
|
282
|
+
const node = doc.mappingNodesById?.[op.nodeId];
|
|
283
|
+
if (!node) {
|
|
284
|
+
throw new OperationConflictError(`Unknown mapping node "${op.nodeId}"`);
|
|
285
|
+
}
|
|
286
|
+
const filterOrder = node.filterOrder ?? [];
|
|
287
|
+
const filter = writeField({ fieldId: op.fieldId, operator: op.operator }, 'value', op.value ?? null);
|
|
288
|
+
return {
|
|
289
|
+
...doc,
|
|
290
|
+
mappingFiltersById: { ...(doc.mappingFiltersById ?? {}), [op.filterId]: filter },
|
|
291
|
+
mappingNodesById: {
|
|
292
|
+
...doc.mappingNodesById,
|
|
293
|
+
[op.nodeId]: {
|
|
294
|
+
...node,
|
|
295
|
+
filterOrder: filterOrder.includes(op.filterId) ? filterOrder : [...filterOrder, op.filterId],
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
case 'mappingFilter.delete': {
|
|
301
|
+
const nodes = Object.fromEntries(Object.entries(doc.mappingNodesById ?? {}).map(([nodeId, node]) => [
|
|
302
|
+
nodeId,
|
|
303
|
+
node.filterOrder?.includes(op.filterId)
|
|
304
|
+
? { ...node, filterOrder: node.filterOrder.filter((id) => id !== op.filterId) }
|
|
305
|
+
: node,
|
|
306
|
+
]));
|
|
307
|
+
return patchDocument(doc, {
|
|
308
|
+
mappingFiltersById: doc.mappingFiltersById && omitKey(doc.mappingFiltersById, op.filterId),
|
|
309
|
+
mappingNodesById: nodes,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
default: {
|
|
313
|
+
// Exhaustiveness: a new op member makes this a compile error, not a silent no-op.
|
|
314
|
+
const unhandled = op;
|
|
315
|
+
throw new UnknownOperationError(unhandled?.type ?? 'undefined');
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
//# sourceMappingURL=applyOperation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyOperation.js","sourceRoot":"","sources":["../../src/collaboration/applyOperation.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AAEH;;;;;;GAMG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAChC,UAAU,CAAQ;IAClB,IAAI,CAAQ;IAErB,YAAY,OAAe,EAAE,UAAkB,EAAE,IAAY;QACzD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,CAAC;CACJ;AAED,MAAM,OAAO,qBAAsB,SAAQ,kBAAkB;IACzD,YAAY,IAAY;QACpB,KAAK,CAAC,mCAAmC,IAAI,GAAG,EAAE,GAAG,EAAE,uBAAuB,CAAC,CAAA;IACnF,CAAC;CACJ;AAED,MAAM,OAAO,sBAAuB,SAAQ,kBAAkB;IAC1D,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,wBAAwB,CAAC,CAAA;IACjD,CAAC;CACJ;AAED,0FAA0F;AAC1F,MAAM,SAAS,GAAG,CAAC,MAAqB,EAAU,EAAE,CAChD,MAAM,CAAC,IAAI,KAAK,UAAU;IACtB,CAAC,CAAC,YAAY,MAAM,CAAC,UAAU,EAAE;IACjC,CAAC,CAAC,cAAc,MAAM,CAAC,cAAc,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAA;AAE1E,uEAAuE;AACvE,MAAM,UAAU,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AE,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC;oBACnC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE;oBAC/E,CAAC,CAAC,IAAI;aACb,CAAC,CACL,CAAA;YACD,OAAO,aAAa,CAAC,GAAG,EAAE;gBACtB,kBAAkB,EAAE,GAAG,CAAC,kBAAkB,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,EAAE,CAAC,QAAQ,CAAC;gBAC1F,gBAAgB,EAAE,KAAK;aAC1B,CAAC,CAAA;QACN,CAAC;QAED,SAAS,CAAC;YACN,kFAAkF;YAClF,MAAM,SAAS,GAAU,EAAE,CAAA;YAC3B,MAAM,IAAI,qBAAqB,CAAE,SAA+B,EAAE,IAAI,IAAI,WAAW,CAAC,CAAA;QAC1F,CAAC;IACL,CAAC;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The QNR authoring collaboration contract: the normalized template document, the op
|
|
3
|
+
* vocabulary, and the reducer that turns one into the other.
|
|
4
|
+
*
|
|
5
|
+
* Published as its own subpath (`asma-core-helpers/collaboration`) rather than through the
|
|
6
|
+
* root barrel, and that is load-bearing rather than tidiness: the root barrel re-exports
|
|
7
|
+
* modules that read `window` and `localStorage` at module top level (`helpers/getSubdomain`,
|
|
8
|
+
* `helpers/initEnvConfigsVars`), and ESM evaluates every re-exported module on import — so
|
|
9
|
+
* importing the barrel from a Bun/Node service throws `ReferenceError: window is not
|
|
10
|
+
* defined` before any of this code runs. This entry point is browser- and server-safe
|
|
11
|
+
* because nothing under it imports anything at all.
|
|
12
|
+
*
|
|
13
|
+
* Both sides of the questionnaire editor consume exactly this module: the frontend applies
|
|
14
|
+
* an op locally before it leaves the client, bunjs applies the same op authoritatively
|
|
15
|
+
* before it becomes durable. Two implementations would make every divergence a data-loss
|
|
16
|
+
* bug, which is why the contract lives here instead of in either consumer.
|
|
17
|
+
*
|
|
18
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:422 (shared contracts package)
|
|
19
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-21-40-plan-qnr-stage2-new-model-editor-and-sync.md:690 (FILE-001)
|
|
20
|
+
*/
|
|
21
|
+
export * from './templateDocument.js';
|
|
22
|
+
export * from './operations.js';
|
|
23
|
+
export * from './applyOperation.js';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/collaboration/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The QNR authoring collaboration contract: the normalized template document, the op
|
|
3
|
+
* vocabulary, and the reducer that turns one into the other.
|
|
4
|
+
*
|
|
5
|
+
* Published as its own subpath (`asma-core-helpers/collaboration`) rather than through the
|
|
6
|
+
* root barrel, and that is load-bearing rather than tidiness: the root barrel re-exports
|
|
7
|
+
* modules that read `window` and `localStorage` at module top level (`helpers/getSubdomain`,
|
|
8
|
+
* `helpers/initEnvConfigsVars`), and ESM evaluates every re-exported module on import — so
|
|
9
|
+
* importing the barrel from a Bun/Node service throws `ReferenceError: window is not
|
|
10
|
+
* defined` before any of this code runs. This entry point is browser- and server-safe
|
|
11
|
+
* because nothing under it imports anything at all.
|
|
12
|
+
*
|
|
13
|
+
* Both sides of the questionnaire editor consume exactly this module: the frontend applies
|
|
14
|
+
* an op locally before it leaves the client, bunjs applies the same op authoritatively
|
|
15
|
+
* before it becomes durable. Two implementations would make every divergence a data-loss
|
|
16
|
+
* bug, which is why the contract lives here instead of in either consumer.
|
|
17
|
+
*
|
|
18
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:422 (shared contracts package)
|
|
19
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-21-40-plan-qnr-stage2-new-model-editor-and-sync.md:690 (FILE-001)
|
|
20
|
+
*/
|
|
21
|
+
export * from './templateDocument.js';
|
|
22
|
+
export * from './operations.js';
|
|
23
|
+
export * from './applyOperation.js';
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/collaboration/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { AltId, BindingId, BindingTarget, DocScalar, FilterId, NodeId, QuestionId } from './templateDocument.js';
|
|
2
|
+
/**
|
|
3
|
+
* The authoring op vocabulary. `entity.action`, stable-id targets only, append-only —
|
|
4
|
+
* a new op is a new member, never a changed one.
|
|
5
|
+
*
|
|
6
|
+
* `null` in an op payload is the **explicit unset** the way JSON-merge-patch uses it.
|
|
7
|
+
* DOC-LAW-2 bans `null` in the stored document, not in the op that produces it: the op
|
|
8
|
+
* layer is the only place the absent-vs-cleared tri-state survives.
|
|
9
|
+
*
|
|
10
|
+
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:380
|
|
11
|
+
* @see _docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:195 (DOC-LAW-2 tri-state)
|
|
12
|
+
*/
|
|
13
|
+
/** A value an op may write. `null` means unset. */
|
|
14
|
+
export type OpValue = DocScalar | null;
|
|
15
|
+
export type TemplateOp = {
|
|
16
|
+
type: 'template.updateMeta';
|
|
17
|
+
patch: Record<string, OpValue | Record<string, unknown>>;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'question.create';
|
|
20
|
+
questionId: QuestionId;
|
|
21
|
+
kind: string;
|
|
22
|
+
atIndex?: number;
|
|
23
|
+
} | {
|
|
24
|
+
type: 'question.updateField';
|
|
25
|
+
questionId: QuestionId;
|
|
26
|
+
field: string;
|
|
27
|
+
value: OpValue;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'question.move';
|
|
30
|
+
questionId: QuestionId;
|
|
31
|
+
toIndex: number;
|
|
32
|
+
} | {
|
|
33
|
+
type: 'question.delete';
|
|
34
|
+
questionId: QuestionId;
|
|
35
|
+
} | {
|
|
36
|
+
type: 'alternative.create';
|
|
37
|
+
questionId: QuestionId;
|
|
38
|
+
alternativeId: AltId;
|
|
39
|
+
label?: string;
|
|
40
|
+
atIndex?: number;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'alternative.delete';
|
|
43
|
+
questionId: QuestionId;
|
|
44
|
+
alternativeId: AltId;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'mappingNode.create';
|
|
47
|
+
nodeId: NodeId;
|
|
48
|
+
entityId: string;
|
|
49
|
+
parentNodeId?: NodeId;
|
|
50
|
+
relationshipId?: string;
|
|
51
|
+
} | {
|
|
52
|
+
type: 'mappingNode.delete';
|
|
53
|
+
nodeId: NodeId;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'mappingBinding.create';
|
|
56
|
+
bindingId: BindingId;
|
|
57
|
+
nodeId: NodeId;
|
|
58
|
+
fieldId: string;
|
|
59
|
+
target: BindingTarget;
|
|
60
|
+
} | {
|
|
61
|
+
type: 'mappingBinding.update';
|
|
62
|
+
bindingId: BindingId;
|
|
63
|
+
patch: {
|
|
64
|
+
nodeId?: NodeId;
|
|
65
|
+
fieldId?: string;
|
|
66
|
+
target?: BindingTarget;
|
|
67
|
+
};
|
|
68
|
+
} | {
|
|
69
|
+
type: 'mappingBinding.delete';
|
|
70
|
+
bindingId: BindingId;
|
|
71
|
+
} | {
|
|
72
|
+
type: 'mappingFilter.set';
|
|
73
|
+
filterId: FilterId;
|
|
74
|
+
nodeId: NodeId;
|
|
75
|
+
fieldId: string;
|
|
76
|
+
operator: string;
|
|
77
|
+
value?: DocScalar;
|
|
78
|
+
} | {
|
|
79
|
+
type: 'mappingFilter.delete';
|
|
80
|
+
filterId: FilterId;
|
|
81
|
+
};
|
|
82
|
+
export type TemplateOpType = TemplateOp['type'];
|
|
83
|
+
/**
|
|
84
|
+
* The op types this reducer implements. The vocabulary in the architecture doc is
|
|
85
|
+
* larger (grid rows, tabs, actions, layout, visibility/highlight rules); those slot
|
|
86
|
+
* into the same registry without changing the envelope.
|
|
87
|
+
*/
|
|
88
|
+
export declare const IMPLEMENTED_OP_TYPES: readonly ["template.updateMeta", "question.create", "question.updateField", "question.move", "question.delete", "alternative.create", "alternative.delete", "mappingNode.create", "mappingNode.delete", "mappingBinding.create", "mappingBinding.update", "mappingBinding.delete", "mappingFilter.set", "mappingFilter.delete"];
|
|
89
|
+
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/collaboration/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAErH;;;;;;;;;;GAUG;AAEH,mDAAmD;AACnD,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,IAAI,CAAA;AAEtC,MAAM,MAAM,UAAU,GAChB;IAAE,IAAI,EAAE,qBAAqB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CA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AK,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,aAAa,CAAA;KAAE,CAAA;CACvE,GACD;IAAE,IAAI,EAAE,uBAAuB,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,GACvD;IACI,IAAI,EAAE,mBAAmB,CAAA;IACzB,QAAQ,EAAE,QAAQ,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,SAAS,CAAA;CACpB,GACD;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAA;AAE1D,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;AAE/C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,iUAea,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The op types this reducer implements. The vocabulary in the architecture doc is
|
|
3
|
+
* larger (grid rows, tabs, actions, layout, visibility/highlight rules); those slot
|
|
4
|
+
* into the same registry without changing the envelope.
|
|
5
|
+
*/
|
|
6
|
+
export const IMPLEMENTED_OP_TYPES = [
|
|
7
|
+
'template.updateMeta',
|
|
8
|
+
'question.create',
|
|
9
|
+
'question.updateField',
|
|
10
|
+
'question.move',
|
|
11
|
+
'question.delete',
|
|
12
|
+
'alternative.create',
|
|
13
|
+
'alternative.delete',
|
|
14
|
+
'mappingNode.create',
|
|
15
|
+
'mappingNode.delete',
|
|
16
|
+
'mappingBinding.create',
|
|
17
|
+
'mappingBinding.update',
|
|
18
|
+
'mappingBinding.delete',
|
|
19
|
+
'mappingFilter.set',
|
|
20
|
+
'mappingFilter.delete',
|
|
21
|
+
];
|
|
22
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/collaboration/operations.ts"],"names":[],"mappings":"AAoDA;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAChC,qBAAqB;IACrB,iBAAiB;IACjB,sBAAsB;IACtB,eAAe;IACf,iBAAiB;IACjB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;IACvB,mBAAmB;IACnB,sBAAsB;CACoB,CAAA"}
|