asma-core-helpers 0.19.0 → 0.20.1
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 +233 -0
- 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 +93 -4
- package/lib/collaboration/operations.d.ts.map +1 -1
- package/lib/collaboration/operations.js +23 -8
- 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/lib/helpers/EnvironmentsUrls.d.ts +0 -3
- package/lib/helpers/EnvironmentsUrls.d.ts.map +1 -1
- package/lib/helpers/EnvironmentsUrls.js +0 -3
- package/lib/helpers/EnvironmentsUrls.js.map +1 -1
- package/lib/helpers/generateEnvConfigsBindings.d.ts +1 -4
- package/lib/helpers/generateEnvConfigsBindings.d.ts.map +1 -1
- package/lib/helpers/generateEnvConfigsBindings.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.ts +248 -1
- package/src/collaboration/canonicalize.ts +209 -0
- package/src/collaboration/docLaws.ts +123 -0
- package/src/collaboration/operations.ts +87 -12
- package/src/collaboration/templateDocument.ts +137 -5
- package/src/helpers/EnvironmentsUrls.ts +0 -3
- package/src/helpers/generateEnvConfigsBindings.ts +1 -4
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical form for hashed documents.
|
|
3
|
+
*
|
|
4
|
+
* Two separable steps, because two consumers need different amounts of it:
|
|
5
|
+
*
|
|
6
|
+
* 1. `reduceToMinimalForm` — DOC-LAW-2: absent is the only encoding of "not set".
|
|
7
|
+
* 2. `canonicalJson` — RFC 8785 (JCS): sorted members, no whitespace, ECMAScript
|
|
8
|
+
* numbers, plus NFC normalisation, which JCS deliberately leaves out.
|
|
9
|
+
*
|
|
10
|
+
* The template/answer documents reduce their whole body; the data engine's
|
|
11
|
+
* `structureHash` reduces only four members of the structure document and then runs
|
|
12
|
+
* the identical serialiser — same bytes, different selection.
|
|
13
|
+
*
|
|
14
|
+
* This is the single shared implementation: the frontend, bunjs and the data engine
|
|
15
|
+
* all produce the same bytes from here. `hashCanonical` is the one function that needs
|
|
16
|
+
* a platform primitive (SHA-256), so it takes an injectable hasher with a WebCrypto
|
|
17
|
+
* default that works in browsers, Node 18+ and Bun alike.
|
|
18
|
+
*
|
|
19
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:195 (DOC-LAW-2)
|
|
20
|
+
* @see asma-modules/_docs/qnr-data-engine/specs/2026-07-30-00-11-spec-qnr-data-engine-contract.md:652 (§8.2)
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* A prototype check, not a `typeof` check. `typeof new Date() === 'object'` and a Date
|
|
24
|
+
* has no own enumerable keys, so a `typeof` test would serialise it as `{}` — silently
|
|
25
|
+
* erasing a timestamp from a hashed document.
|
|
26
|
+
*/
|
|
27
|
+
const isPlainObject = (value) => {
|
|
28
|
+
if (typeof value !== 'object' || value === null)
|
|
29
|
+
return false;
|
|
30
|
+
const proto = Object.getPrototypeOf(value);
|
|
31
|
+
return proto === Object.prototype || proto === null;
|
|
32
|
+
};
|
|
33
|
+
const joinPath = (parent, key) => (parent === '' ? key : `${parent}.${key}`);
|
|
34
|
+
/**
|
|
35
|
+
* DOC-LAW-2 reduction. Drops explicit `null`, `[]`, `{}` and any key carrying its own
|
|
36
|
+
* default — recursively, so a container that becomes empty is itself dropped and the
|
|
37
|
+
* result is a fixed point (reducing twice is a no-op).
|
|
38
|
+
*
|
|
39
|
+
* The root container is always returned, even if it reduces to empty: a caller asking
|
|
40
|
+
* to canonicalize a document wants a document back, not `undefined`.
|
|
41
|
+
*/
|
|
42
|
+
export const reduceToMinimalForm = (value, options = {}) => {
|
|
43
|
+
const reduced = reduceNode(value, '', options);
|
|
44
|
+
if (reduced !== undefined)
|
|
45
|
+
return reduced;
|
|
46
|
+
return (Array.isArray(value) ? [] : {});
|
|
47
|
+
};
|
|
48
|
+
const reduceNode = (value, path, options) => {
|
|
49
|
+
if (value === null)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
// ponytail: array members are reduced but never removed. Dropping one would
|
|
53
|
+
// silently change length and order, and order is the only ordering carrier
|
|
54
|
+
// (DOC-LAW-1) — a null member is a schema violation for the lint to catch,
|
|
55
|
+
// not something to paper over here.
|
|
56
|
+
let anyMemberSurvived = false;
|
|
57
|
+
const members = value.map((member, index) => {
|
|
58
|
+
const reducedMember = reduceNode(member, joinPath(path, String(index)), options);
|
|
59
|
+
if (reducedMember !== undefined) {
|
|
60
|
+
anyMemberSurvived = true;
|
|
61
|
+
return reducedMember;
|
|
62
|
+
}
|
|
63
|
+
// A container member that reduces away becomes the EMPTY container, not the original.
|
|
64
|
+
// Restoring the original would put back the very nulls this reduction exists to remove, and
|
|
65
|
+
// the storage guard `document = jsonb_strip_nulls(document)` then rejects the row — which is
|
|
66
|
+
// exactly how this was found, on the first real import against dev. A primitive `null` member
|
|
67
|
+
// is kept: `jsonb_strip_nulls` removes null object *fields* only, so an array null is legal,
|
|
68
|
+
// and dropping it would change the length this branch is protecting.
|
|
69
|
+
if (Array.isArray(member))
|
|
70
|
+
return [];
|
|
71
|
+
if (isPlainObject(member))
|
|
72
|
+
return {};
|
|
73
|
+
return member;
|
|
74
|
+
});
|
|
75
|
+
if (members.length === 0)
|
|
76
|
+
return undefined;
|
|
77
|
+
// An array in which NOTHING survived reduction carries no information, so the key goes — same rule
|
|
78
|
+
// as an empty object, reached one level later. Length is not worth protecting here because there is
|
|
79
|
+
// no content whose position it could describe.
|
|
80
|
+
//
|
|
81
|
+
// Measured, and the reason this branch exists: legacy `dependent_questions` members hold exactly
|
|
82
|
+
// `{dependent_question_id, dependent_composite_question_id}` and **all 3,702 members sampled on dev
|
|
83
|
+
// have both fields null**. Without this rule the port stored 620 arrays of `{}` per version —
|
|
84
|
+
// simultaneously a DOC-LAW-1 violation (array of objects) and a DOC-LAW-2 one (empty object), and
|
|
85
|
+
// invisible to the storage CHECK because `jsonb_strip_nulls` does not remove empty objects.
|
|
86
|
+
//
|
|
87
|
+
// A MIXED array — some members surviving, some not — is deliberately still kept with its empties, so
|
|
88
|
+
// the surviving members keep their positions. That case is left for `findDocLawViolations` to report
|
|
89
|
+
// rather than papered over here, because papering over it would move a real content position.
|
|
90
|
+
if (!anyMemberSurvived)
|
|
91
|
+
return undefined;
|
|
92
|
+
return members;
|
|
93
|
+
}
|
|
94
|
+
if (isPlainObject(value)) {
|
|
95
|
+
const result = {};
|
|
96
|
+
for (const [key, member] of Object.entries(value)) {
|
|
97
|
+
const memberPath = joinPath(path, key);
|
|
98
|
+
if (options.isDefault?.(memberPath, member))
|
|
99
|
+
continue;
|
|
100
|
+
const reducedMember = reduceNode(member, memberPath, options);
|
|
101
|
+
if (reducedMember === undefined)
|
|
102
|
+
continue;
|
|
103
|
+
result[key] = reducedMember;
|
|
104
|
+
}
|
|
105
|
+
return Object.keys(result).length === 0 ? undefined : result;
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* RFC 8785 JSON Canonicalization Scheme over the value, plus NFC.
|
|
111
|
+
*
|
|
112
|
+
* Refuses anything JSON cannot carry rather than emitting a lossy encoding — an
|
|
113
|
+
* `undefined` silently vanishing from a hashed document is exactly the class of bug
|
|
114
|
+
* a canonical form exists to prevent.
|
|
115
|
+
*/
|
|
116
|
+
export const canonicalJson = (value) => serialize(value, '');
|
|
117
|
+
const serialize = (value, path) => {
|
|
118
|
+
if (value === null)
|
|
119
|
+
return 'null';
|
|
120
|
+
switch (typeof value) {
|
|
121
|
+
case 'boolean':
|
|
122
|
+
return value ? 'true' : 'false';
|
|
123
|
+
case 'string':
|
|
124
|
+
// JSON.stringify already produces ECMAScript-minimal escaping, which is
|
|
125
|
+
// what JCS mandates.
|
|
126
|
+
return JSON.stringify(value.normalize('NFC'));
|
|
127
|
+
case 'number':
|
|
128
|
+
if (!Number.isFinite(value)) {
|
|
129
|
+
throw new Error(`canonicalJson: ${value} is not finite at "${path || '<root>'}"`);
|
|
130
|
+
}
|
|
131
|
+
// JSON.stringify uses Number::toString, which is JCS's number rule.
|
|
132
|
+
return JSON.stringify(value);
|
|
133
|
+
case 'undefined':
|
|
134
|
+
throw new Error(`canonicalJson: undefined at "${path || '<root>'}"`);
|
|
135
|
+
case 'bigint':
|
|
136
|
+
throw new Error(`canonicalJson: bigint is unsupported at "${path || '<root>'}"`);
|
|
137
|
+
case 'function':
|
|
138
|
+
case 'symbol':
|
|
139
|
+
throw new Error(`canonicalJson: ${typeof value} is unsupported at "${path || '<root>'}"`);
|
|
140
|
+
}
|
|
141
|
+
if (Array.isArray(value)) {
|
|
142
|
+
return `[${value.map((member, index) => serialize(member, joinPath(path, String(index)))).join(',')}]`;
|
|
143
|
+
}
|
|
144
|
+
if (!isPlainObject(value)) {
|
|
145
|
+
const name = Object.prototype.toString.call(value).slice(8, -1);
|
|
146
|
+
throw new Error(`canonicalJson: ${name} is unsupported at "${path || '<root>'}"`);
|
|
147
|
+
}
|
|
148
|
+
// Normalise before sorting: normalisation can change the code units that sorting
|
|
149
|
+
// compares, so the other order would not be stable.
|
|
150
|
+
const members = new Map();
|
|
151
|
+
for (const [key, member] of Object.entries(value)) {
|
|
152
|
+
const normalized = key.normalize('NFC');
|
|
153
|
+
if (members.has(normalized)) {
|
|
154
|
+
throw new Error(`canonicalJson: keys "${key}" and its NFC twin collide at "${path || '<root>'}"`);
|
|
155
|
+
}
|
|
156
|
+
members.set(normalized, member);
|
|
157
|
+
}
|
|
158
|
+
const body = [...members.keys()]
|
|
159
|
+
.sort() // default comparison is by UTF-16 code unit, which is JCS's rule
|
|
160
|
+
.map((key) => `${JSON.stringify(key)}:${serialize(members.get(key), joinPath(path, key))}`)
|
|
161
|
+
.join(',');
|
|
162
|
+
return `{${body}}`;
|
|
163
|
+
};
|
|
164
|
+
const bytesToHex = (bytes) => [...bytes].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
165
|
+
/**
|
|
166
|
+
* WebCrypto SHA-256 — the default hasher. Present in browsers, Node 18+ and Bun as
|
|
167
|
+
* `globalThis.crypto`, so one implementation serves every consumer of this package.
|
|
168
|
+
* A server-side consumer with a sync hot path may inject its own hasher instead.
|
|
169
|
+
*/
|
|
170
|
+
export const webCryptoSha256 = async (utf8) => {
|
|
171
|
+
const bytes = new TextEncoder().encode(utf8);
|
|
172
|
+
const digest = await crypto.subtle.digest('SHA-256', bytes);
|
|
173
|
+
return bytesToHex(new Uint8Array(digest));
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Canonical hash of a document: `sha256:` over RFC 8785 + NFC bytes of its minimal
|
|
177
|
+
* form. `hasher` is injectable so a server can use sync node:crypto while the browser
|
|
178
|
+
* keeps the WebCrypto default — the bytes hashed are identical either way.
|
|
179
|
+
*/
|
|
180
|
+
export const hashCanonical = (value, hasher = webCryptoSha256) => {
|
|
181
|
+
const maybeHex = hasher(canonicalJson(value));
|
|
182
|
+
return Promise.resolve(maybeHex).then((hex) => `sha256:${hex}`);
|
|
183
|
+
};
|
|
184
|
+
//# sourceMappingURL=canonicalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonicalize.js","sourceRoot":"","sources":["../../src/collaboration/canonicalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAWH;;;;GAIG;AACH,MAAM,aAAa,GAAG,CAAC,KAAc,EAAoC,EAAE;IACvE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAC7D,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAC1C,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,CAAA;AACvD,CAAC,CAAA;AAED,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,GAAW,EAAE,EAAE,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAA;AAE5F;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAI,KAAQ,EAAE,OAAO,GAAkB,EAAE,EAAK,EAAE;IAC/E,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAA;IAC9C,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,OAAY,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAM,CAAA;AAChD,CAAC,CAAA;AAED,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AAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;IAC3D,OAAO,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;AAC7C,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAE,MAAM,GAAc,eAAe,EAAmB,EAAE;IAClG,MAAM,QAAQ,GAAG,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7C,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,CAAA;AACnE,CAAC,CAAA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { JsonValue } from './canonicalize.js';
|
|
2
|
+
/**
|
|
3
|
+
* The two document laws, as an executable check (plan TASK-003).
|
|
4
|
+
*
|
|
5
|
+
* Both are stated in the architecture as prose and enforced at the storage boundary by a CHECK constraint
|
|
6
|
+
* that can only see one of them. `jsonb_strip_nulls(document) = document` catches DOC-LAW-2's explicit
|
|
7
|
+
* `null`, and nothing in the database can catch DOC-LAW-1 at all — an array of objects is perfectly valid
|
|
8
|
+
* jsonb. So the law that matters most for merges is the one with no guard, which is what this file is.
|
|
9
|
+
*
|
|
10
|
+
* ═══ DOC-LAW-1 · NO ARRAYS OF OBJECTS ═══
|
|
11
|
+
* A collection is `<x>ById` plus a primitive order array. The reason is merge behaviour, not taste: JSON
|
|
12
|
+
* Merge Patch (RFC 7386) — the delta format — replaces an array **wholesale**. For an order array of ids
|
|
13
|
+
* that is exactly right, because reordering *is* a whole-array change. For an array of objects it is a
|
|
14
|
+
* silent data loss: two authors editing different members of one array produce two patches, and the second
|
|
15
|
+
* to land discards the first's edit with no conflict raised. Keying the members by id turns that same
|
|
16
|
+
* situation into two patches touching different keys, which merge cleanly.
|
|
17
|
+
*
|
|
18
|
+
* ═══ DOC-LAW-2 · ABSENT IS THE ONLY ENCODING OF "NOT SET" ═══
|
|
19
|
+
* No explicit `null`, no empty object, no empty array, no key carrying its own default. Two encodings of
|
|
20
|
+
* "not set" means two documents that render identically can hash differently — and the hash is what decides
|
|
21
|
+
* whether a version is minted, whether a re-import diverged, and whether two authors actually conflicted.
|
|
22
|
+
*
|
|
23
|
+
* ═══ WHY A LINT AND NOT A TYPE ═══
|
|
24
|
+
* `QnrQuestion` carries an index signature (`[key: string]: unknown`), because a question's per-type
|
|
25
|
+
* configuration bag is genuinely open. That is the right type and it is also why the compiler cannot see
|
|
26
|
+
* either violation: the legacy import writes into exactly that open space. This check found a real one —
|
|
27
|
+
* `dependent_questions` arrives from legacy as an array of objects and was being stored verbatim.
|
|
28
|
+
*
|
|
29
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:193 — DOC-LAW-1
|
|
30
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:195 — DOC-LAW-2
|
|
31
|
+
*/
|
|
32
|
+
export type DocLawViolation = {
|
|
33
|
+
law: 'DOC-LAW-1' | 'DOC-LAW-2';
|
|
34
|
+
/** Dotted path to the offending node, array members included as numeric segments. */
|
|
35
|
+
path: string;
|
|
36
|
+
detail: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Every violation in a document, deepest-first is not guaranteed — order follows traversal.
|
|
40
|
+
*
|
|
41
|
+
* `revision` is exempt from DOC-LAW-2's default rule: it is `0` on a fresh document and `0` is its
|
|
42
|
+
* meaningful value there, not an omittable default. Nothing else is exempt.
|
|
43
|
+
*/
|
|
44
|
+
export declare const findDocLawViolations: (document: unknown) => DocLawViolation[];
|
|
45
|
+
/**
|
|
46
|
+
* Rewrites a legacy array-of-objects into the DOC-LAW-1 shape, in place of the array.
|
|
47
|
+
*
|
|
48
|
+
* `{ <field>: [ {...}, {...} ] }` becomes `{ <field>ById: { <id>: {...} }, <field>Order: [ <id>, … ] }`,
|
|
49
|
+
* with ids derived by the caller so they are stable across revisions — a random id would make every
|
|
50
|
+
* re-import look like an edit, which is the same trap `derivedAlternativeId` exists to avoid.
|
|
51
|
+
*/
|
|
52
|
+
export declare const toKeyedCollection: <T>(members: readonly T[], idOf: (member: T, index: number) => string) => {
|
|
53
|
+
byId: Record<string, T>;
|
|
54
|
+
order: string[];
|
|
55
|
+
};
|
|
56
|
+
/** True when the value is an array carrying at least one object or array member. */
|
|
57
|
+
export declare const isArrayOfContainers: (value: unknown) => value is JsonValue[];
|
|
58
|
+
//# sourceMappingURL=docLaws.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docLaws.d.ts","sourceRoot":"","sources":["../../src/collaboration/docLaws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,MAAM,MAAM,eAAe,GAAG;IAC1B,GAAG,EAAE,WAAW,GAAG,WAAW,CAAA;IAC9B,qFAAqF;IACrF,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAUD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,aAAc,OAAO,KAAG,eAAe,EAyCvE,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,WACtB,SAAS,CAAC,EAAE,QACf,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,KAC3C;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAW5C,CAAA;AAED,oFAAoF;AACpF,eAAO,MAAM,mBAAmB,UAAW,OAAO,KAAG,KAAK,IAAI,SAAS,EAC2B,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const isPlainObject = (value) => {
|
|
2
|
+
if (typeof value !== 'object' || value === null)
|
|
3
|
+
return false;
|
|
4
|
+
const proto = Object.getPrototypeOf(value);
|
|
5
|
+
return proto === Object.prototype || proto === null;
|
|
6
|
+
};
|
|
7
|
+
const joinPath = (parent, key) => (parent === '' ? key : `${parent}.${key}`);
|
|
8
|
+
/**
|
|
9
|
+
* Every violation in a document, deepest-first is not guaranteed — order follows traversal.
|
|
10
|
+
*
|
|
11
|
+
* `revision` is exempt from DOC-LAW-2's default rule: it is `0` on a fresh document and `0` is its
|
|
12
|
+
* meaningful value there, not an omittable default. Nothing else is exempt.
|
|
13
|
+
*/
|
|
14
|
+
export const findDocLawViolations = (document) => {
|
|
15
|
+
const violations = [];
|
|
16
|
+
const walk = (value, path) => {
|
|
17
|
+
if (value === null) {
|
|
18
|
+
violations.push({ law: 'DOC-LAW-2', path, detail: 'explicit null; omit the key instead' });
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (Array.isArray(value)) {
|
|
22
|
+
if (value.length === 0) {
|
|
23
|
+
violations.push({ law: 'DOC-LAW-2', path, detail: 'empty array; omit the key instead' });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
value.forEach((member, index) => {
|
|
27
|
+
const memberPath = joinPath(path, String(index));
|
|
28
|
+
if (isPlainObject(member) || Array.isArray(member)) {
|
|
29
|
+
violations.push({
|
|
30
|
+
law: 'DOC-LAW-1',
|
|
31
|
+
path: memberPath,
|
|
32
|
+
detail: `array member is ${Array.isArray(member) ? 'an array' : 'an object'}; use <x>ById plus a primitive order array`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
walk(member, memberPath);
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (isPlainObject(value)) {
|
|
40
|
+
const keys = Object.keys(value);
|
|
41
|
+
if (keys.length === 0 && path !== '') {
|
|
42
|
+
violations.push({ law: 'DOC-LAW-2', path, detail: 'empty object; omit the key instead' });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
for (const key of keys)
|
|
46
|
+
walk(value[key], joinPath(path, key));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
walk(document, '');
|
|
50
|
+
return violations;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Rewrites a legacy array-of-objects into the DOC-LAW-1 shape, in place of the array.
|
|
54
|
+
*
|
|
55
|
+
* `{ <field>: [ {...}, {...} ] }` becomes `{ <field>ById: { <id>: {...} }, <field>Order: [ <id>, … ] }`,
|
|
56
|
+
* with ids derived by the caller so they are stable across revisions — a random id would make every
|
|
57
|
+
* re-import look like an edit, which is the same trap `derivedAlternativeId` exists to avoid.
|
|
58
|
+
*/
|
|
59
|
+
export const toKeyedCollection = (members, idOf) => {
|
|
60
|
+
const byId = {};
|
|
61
|
+
const order = [];
|
|
62
|
+
members.forEach((member, index) => {
|
|
63
|
+
const id = idOf(member, index);
|
|
64
|
+
byId[id] = member;
|
|
65
|
+
order.push(id);
|
|
66
|
+
});
|
|
67
|
+
return { byId, order };
|
|
68
|
+
};
|
|
69
|
+
/** True when the value is an array carrying at least one object or array member. */
|
|
70
|
+
export const isArrayOfContainers = (value) => Array.isArray(value) && value.some((member) => isPlainObject(member) || Array.isArray(member));
|
|
71
|
+
//# sourceMappingURL=docLaws.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docLaws.js","sourceRoot":"","sources":["../../src/collaboration/docLaws.ts"],"names":[],"mappings":"AAwCA,MAAM,aAAa,GAAG,CAAC,KAAc,EAAoC,EAAE;IACvE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAC7D,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAC1C,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,K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ED,oFAAoF;AACpF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAwB,EAAE,CACxE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA"}
|
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
import type { AltId, BindingId, BindingTarget, DocScalar, FilterId, NodeId, QuestionId } from './templateDocument.js';
|
|
1
|
+
import type { ActionId, AltId, BindingId, BindingTarget, DocScalar, FilterId, HighlightRuleId, NodeId, QuestionId, RowId, RuleCondition, TabId, VisibilityRuleId } from './templateDocument.js';
|
|
2
2
|
import type { QuestionType } from './questionTypes.js';
|
|
3
3
|
/**
|
|
4
|
-
* The authoring op vocabulary. `entity.action`, stable-id targets only, append-only —
|
|
4
|
+
* The authoring op vocabulary (architecture §5). `entity.action`, stable-id targets only, append-only —
|
|
5
5
|
* a new op is a new member, never a changed one.
|
|
6
6
|
*
|
|
7
7
|
* `null` in an op payload is the **explicit unset** the way JSON-merge-patch uses it.
|
|
8
8
|
* DOC-LAW-2 bans `null` in the stored document, not in the op that produces it: the op
|
|
9
9
|
* layer is the only place the absent-vs-cleared tri-state survives.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Two move conventions coexist deliberately: `question.move`/`alternative.move`/`tab.move`
|
|
12
|
+
* carry `toIndex` (the established authoring shape), while `gridRow.move` is
|
|
13
|
+
* **anchor-relative** (`afterRowId`, OQ-V2-24) — array position is never identity, and a
|
|
14
|
+
* row index would denote different rows to two clients that disagree by one insert.
|
|
15
|
+
*
|
|
16
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:380 (op vocabulary)
|
|
17
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:195 (DOC-LAW-2 tri-state)
|
|
13
18
|
*/
|
|
14
19
|
/** A value an op may write. `null` means unset. */
|
|
15
20
|
export type OpValue = DocScalar | null;
|
|
16
21
|
export type TemplateOp = {
|
|
17
22
|
type: 'template.updateMeta';
|
|
18
23
|
patch: Record<string, OpValue | Record<string, unknown>>;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'template.updateSettings';
|
|
26
|
+
/** Dotted-path patch into `meta.settings` (journal wiring, recipient requirements). */
|
|
27
|
+
patch: Record<string, OpValue | Record<string, unknown>>;
|
|
19
28
|
} | {
|
|
20
29
|
type: 'question.create';
|
|
21
30
|
questionId: QuestionId;
|
|
@@ -33,6 +42,27 @@ export type TemplateOp = {
|
|
|
33
42
|
} | {
|
|
34
43
|
type: 'question.delete';
|
|
35
44
|
questionId: QuestionId;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'gridRow.create';
|
|
47
|
+
questionId: QuestionId;
|
|
48
|
+
rowId: RowId;
|
|
49
|
+
label?: string;
|
|
50
|
+
atIndex?: number;
|
|
51
|
+
} | {
|
|
52
|
+
type: 'gridRow.move';
|
|
53
|
+
questionId: QuestionId;
|
|
54
|
+
rowId: RowId;
|
|
55
|
+
afterRowId: RowId | null;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'gridRow.delete';
|
|
58
|
+
questionId: QuestionId;
|
|
59
|
+
rowId: RowId;
|
|
60
|
+
} | {
|
|
61
|
+
type: 'gridRow.updateCell';
|
|
62
|
+
questionId: QuestionId;
|
|
63
|
+
rowId: RowId;
|
|
64
|
+
columnQuestionId: QuestionId;
|
|
65
|
+
value: OpValue;
|
|
36
66
|
} | {
|
|
37
67
|
type: 'alternative.create';
|
|
38
68
|
questionId: QuestionId;
|
|
@@ -60,12 +90,55 @@ export type TemplateOp = {
|
|
|
60
90
|
type: 'alternative.delete';
|
|
61
91
|
questionId: QuestionId;
|
|
62
92
|
alternativeId: AltId;
|
|
93
|
+
} | {
|
|
94
|
+
type: 'tab.create';
|
|
95
|
+
tabId: TabId;
|
|
96
|
+
label?: string;
|
|
97
|
+
atIndex?: number;
|
|
98
|
+
} | {
|
|
99
|
+
type: 'tab.updateField';
|
|
100
|
+
tabId: TabId;
|
|
101
|
+
field: string;
|
|
102
|
+
value: OpValue;
|
|
103
|
+
} | {
|
|
104
|
+
type: 'tab.move';
|
|
105
|
+
tabId: TabId;
|
|
106
|
+
toIndex: number;
|
|
107
|
+
} | {
|
|
108
|
+
type: 'tab.delete';
|
|
109
|
+
tabId: TabId;
|
|
110
|
+
} | {
|
|
111
|
+
type: 'layout.updateQuestion';
|
|
112
|
+
questionId: QuestionId;
|
|
113
|
+
patch: Record<string, OpValue>;
|
|
114
|
+
} | {
|
|
115
|
+
type: 'action.create';
|
|
116
|
+
actionId: ActionId;
|
|
117
|
+
kind?: string;
|
|
118
|
+
} | {
|
|
119
|
+
type: 'action.updateField';
|
|
120
|
+
actionId: ActionId;
|
|
121
|
+
field: string;
|
|
122
|
+
value: OpValue;
|
|
123
|
+
} | {
|
|
124
|
+
type: 'action.delete';
|
|
125
|
+
actionId: ActionId;
|
|
63
126
|
} | {
|
|
64
127
|
type: 'mappingNode.create';
|
|
65
128
|
nodeId: NodeId;
|
|
66
129
|
entityId: string;
|
|
67
130
|
parentNodeId?: NodeId;
|
|
68
131
|
relationshipId?: string;
|
|
132
|
+
} | {
|
|
133
|
+
type: 'mappingNode.update';
|
|
134
|
+
nodeId: NodeId;
|
|
135
|
+
patch: {
|
|
136
|
+
entityId?: string;
|
|
137
|
+
/** `null` explicitly unsets — the node becomes a root. */
|
|
138
|
+
parentNodeId?: NodeId | null;
|
|
139
|
+
relationshipId?: string | null;
|
|
140
|
+
filterOrder?: FilterId[];
|
|
141
|
+
};
|
|
69
142
|
} | {
|
|
70
143
|
type: 'mappingNode.delete';
|
|
71
144
|
nodeId: NodeId;
|
|
@@ -96,6 +169,22 @@ export type TemplateOp = {
|
|
|
96
169
|
} | {
|
|
97
170
|
type: 'mappingFilter.delete';
|
|
98
171
|
filterId: FilterId;
|
|
172
|
+
} | {
|
|
173
|
+
type: 'visibilityRule.set';
|
|
174
|
+
ruleId: VisibilityRuleId;
|
|
175
|
+
questionId: QuestionId;
|
|
176
|
+
condition: RuleCondition;
|
|
177
|
+
} | {
|
|
178
|
+
type: 'visibilityRule.delete';
|
|
179
|
+
ruleId: VisibilityRuleId;
|
|
180
|
+
} | {
|
|
181
|
+
type: 'highlightRule.set';
|
|
182
|
+
ruleId: HighlightRuleId;
|
|
183
|
+
questionId: QuestionId;
|
|
184
|
+
condition: RuleCondition;
|
|
185
|
+
} | {
|
|
186
|
+
type: 'highlightRule.delete';
|
|
187
|
+
ruleId: HighlightRuleId;
|
|
99
188
|
};
|
|
100
189
|
export type TemplateOpType = TemplateOp['type'];
|
|
101
190
|
export declare const IMPLEMENTED_OP_TYPES: readonly TemplateOpType[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/collaboration/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/collaboration/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,QAAQ,EACR,KAAK,EACL,SAAS,EACT,aAAa,EACb,SAAS,EACT,QAAQ,EACR,eAAe,EACf,MAAM,EACN,UAAU,EACV,KAAK,EACL,aAAa,EACb,KAAK,EACL,gBAAgB,EACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD;;;;;;;;;;;;;;;GAeG;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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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,GACpD;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAC;IAAC,UAAU,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,aAAa,CAAA;CAAE,GAC1G;IAAE,IAAI,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,MAAM,EAAE,eAAe,CAAC;IAAC,UAAU,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,aAAa,CAAA;CAAE,GACxG;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,CAAA;AAE/D,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;AA8C/C,eAAO,MAAM,oBAAoB,EAAoC,SAAS,cAAc,EAAE,CAAA"}
|
|
@@ -1,30 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The op types this reducer implements.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* compile error**. `satisfies readonly TemplateOpType[]` only rejected entries that are not op types;
|
|
8
|
-
* it could not notice a missing one, and this list is what downstream validators are built against —
|
|
9
|
-
* an op absent here is an op the server rejects at runtime with nothing red anywhere first.
|
|
2
|
+
* The op types this reducer implements. Declared as a total `Record` over the union
|
|
3
|
+
* rather than a bare list, so **omitting an op is a compile error**. `satisfies readonly
|
|
4
|
+
* TemplateOpType[]` only rejected entries that are not op types; it could not notice a
|
|
5
|
+
* missing one, and this list is what downstream validators are built against — an op
|
|
6
|
+
* absent here is an op the server rejects at runtime with nothing red anywhere first.
|
|
10
7
|
*/
|
|
11
8
|
const OP_TYPE_COVERAGE = {
|
|
12
9
|
'template.updateMeta': true,
|
|
10
|
+
'template.updateSettings': true,
|
|
13
11
|
'question.create': true,
|
|
14
12
|
'question.updateField': true,
|
|
15
13
|
'question.move': true,
|
|
16
14
|
'question.delete': true,
|
|
15
|
+
'gridRow.create': true,
|
|
16
|
+
'gridRow.move': true,
|
|
17
|
+
'gridRow.delete': true,
|
|
18
|
+
'gridRow.updateCell': true,
|
|
17
19
|
'alternative.create': true,
|
|
18
20
|
'alternative.updateField': true,
|
|
19
21
|
'alternative.move': true,
|
|
20
22
|
'alternative.delete': true,
|
|
23
|
+
'tab.create': true,
|
|
24
|
+
'tab.updateField': true,
|
|
25
|
+
'tab.move': true,
|
|
26
|
+
'tab.delete': true,
|
|
27
|
+
'layout.updateQuestion': true,
|
|
28
|
+
'action.create': true,
|
|
29
|
+
'action.updateField': true,
|
|
30
|
+
'action.delete': true,
|
|
21
31
|
'mappingNode.create': true,
|
|
32
|
+
'mappingNode.update': true,
|
|
22
33
|
'mappingNode.delete': true,
|
|
23
34
|
'mappingBinding.create': true,
|
|
24
35
|
'mappingBinding.update': true,
|
|
25
36
|
'mappingBinding.delete': true,
|
|
26
37
|
'mappingFilter.set': true,
|
|
27
38
|
'mappingFilter.delete': true,
|
|
39
|
+
'visibilityRule.set': true,
|
|
40
|
+
'visibilityRule.delete': true,
|
|
41
|
+
'highlightRule.set': true,
|
|
42
|
+
'highlightRule.delete': true,
|
|
28
43
|
};
|
|
29
44
|
export const IMPLEMENTED_OP_TYPES = Object.keys(OP_TYPE_COVERAGE);
|
|
30
45
|
//# sourceMappingURL=operations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/collaboration/operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/collaboration/operations.ts"],"names":[],"mappings":"AA0HA;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAiC;IACnD,qBAAqB,EAAE,IAAI;IAC3B,yBAAyB,EAAE,IAAI;IAC/B,iBAAiB,EAAE,IAAI;IACvB,sBAAsB,EAAE,IAAI;IAC5B,eAAe,EAAE,IAAI;IACrB,iBAAiB,EAAE,IAAI;IACvB,gBAAgB,EAAE,IAAI;IACtB,cAAc,EAAE,IAAI;IACpB,gBAAgB,EAAE,IAAI;IACtB,oBAAoB,EAAE,IAAI;IAC1B,oBAAoB,EAAE,IAAI;IAC1B,yBAAyB,EAAE,IAAI;IAC/B,kBAAkB,EAAE,IAAI;IACxB,oBAAoB,EAAE,IAAI;IAC1B,YAAY,EAAE,IAAI;IAClB,iBAAiB,EAAE,IAAI;IACvB,UAAU,EAAE,IAAI;IAChB,YAAY,EAAE,IAAI;IAClB,uBAAuB,EAAE,IAAI;IAC7B,eAAe,EAAE,IAAI;IACrB,oBAAoB,EAAE,IAAI;IAC1B,eAAe,EAAE,IAAI;IACrB,oBAAoB,EAAE,IAAI;IAC1B,oBAAoB,EAAE,IAAI;IAC1B,oBAAoB,EAAE,IAAI;IAC1B,uBAAuB,EAAE,IAAI;IAC7B,uBAAuB,EAAE,IAAI;IAC7B,uBAAuB,EAAE,IAAI;IAC7B,mBAAmB,EAAE,IAAI;IACzB,sBAAsB,EAAE,IAAI;IAC5B,oBAAoB,EAAE,IAAI;IAC1B,uBAAuB,EAAE,IAAI;IAC7B,mBAAmB,EAAE,IAAI;IACzB,sBAAsB,EAAE,IAAI;CAC/B,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAA8B,CAAA"}
|