asma-core-helpers 0.28.1 → 0.29.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 +32 -3
- package/lib/collaboration/applyOperation.js.map +1 -1
- package/lib/collaboration/operations.d.ts +23 -3
- package/lib/collaboration/operations.d.ts.map +1 -1
- package/lib/collaboration/operations.js.map +1 -1
- package/lib/collaboration/schemas.d.ts +9 -3
- package/lib/collaboration/schemas.d.ts.map +1 -1
- package/lib/collaboration/schemas.js +41 -6
- package/lib/collaboration/schemas.js.map +1 -1
- package/lib/collaboration/templateDocument.d.ts +59 -3
- package/lib/collaboration/templateDocument.d.ts.map +1 -1
- package/lib/collaboration/templateDocument.js +40 -0
- package/lib/collaboration/templateDocument.js.map +1 -1
- package/package.json +1 -1
- package/src/collaboration/applyOperation.test.ts +154 -1
- package/src/collaboration/applyOperation.ts +55 -3
- package/src/collaboration/operations.ts +26 -1
- package/src/collaboration/schemas.test.ts +111 -0
- package/src/collaboration/schemas.ts +51 -7
- package/src/collaboration/templateDocument.ts +71 -3
|
@@ -264,15 +264,71 @@ export type BindingTarget = {
|
|
|
264
264
|
};
|
|
265
265
|
/** Serialises a binding target so the "one binding per target" invariant is checkable. */
|
|
266
266
|
export declare const bindingTargetKey: (target: BindingTarget) => string;
|
|
267
|
+
/**
|
|
268
|
+
* A binding's expected cardinality (§13.1). Closed rather than a loose string because the compiler
|
|
269
|
+
* branches on it: `0..1`/`1` fill one slot, `0..*`/`1..*` feed a grid's rows, and a typo would compile
|
|
270
|
+
* into an artifact that is immutable forever.
|
|
271
|
+
*
|
|
272
|
+
* `0..1` is the default, so DOC-LAW-2 means it is **never stored** — a binding that takes at most one
|
|
273
|
+
* value carries no `cardinality` key at all.
|
|
274
|
+
*
|
|
275
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-15-20-38-analysis-qnr-external-data-mapping-options.md:840 — the four values
|
|
276
|
+
*/
|
|
277
|
+
export declare const BINDING_CARDINALITIES: readonly ['0..1', '1', '0..*', '1..*'];
|
|
278
|
+
export type BindingCardinality = (typeof BINDING_CARDINALITIES)[number];
|
|
279
|
+
/**
|
|
280
|
+
* What the runtime does when the source yields **no** value for a binding. `omit` leaves the question
|
|
281
|
+
* unfilled (the default); `error` makes the absence a prefill failure the author wants surfaced rather
|
|
282
|
+
* than silently tolerated.
|
|
283
|
+
*/
|
|
284
|
+
export declare const BINDING_ON_MISSING: readonly ['omit', 'error'];
|
|
285
|
+
export type BindingOnMissing = (typeof BINDING_ON_MISSING)[number];
|
|
286
|
+
/**
|
|
287
|
+
* What the runtime does when the source yields **many** values for a binding expecting one. `error` is
|
|
288
|
+
* the default — an ambiguous prefill is a real defect — and `first` is the deliberate opt-in, which is
|
|
289
|
+
* why the node's `orderBy` must make "first" deterministic before it means anything.
|
|
290
|
+
*/
|
|
291
|
+
export declare const BINDING_ON_MANY: readonly ['error', 'first'];
|
|
292
|
+
export type BindingOnMany = (typeof BINDING_ON_MANY)[number];
|
|
293
|
+
/**
|
|
294
|
+
* The three binding behaviours and their defaults, in one place because two rules depend on it: the
|
|
295
|
+
* reducer omits a chosen value that equals its default (DOC-LAW-2 — a key present with its own default
|
|
296
|
+
* is a second encoding of "not set", and the hash is computed on the minimal form), and every reader
|
|
297
|
+
* hydrates the absent key back to the same value.
|
|
298
|
+
*
|
|
299
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-15-20-38-analysis-qnr-external-data-mapping-options.md:832 — absent because they equal their defaults
|
|
300
|
+
*/
|
|
301
|
+
/** The binding behaviours a reader sees — total, because the stored document is minimal. */
|
|
302
|
+
export type ResolvedBindingOptions = {
|
|
303
|
+
cardinality: BindingCardinality;
|
|
304
|
+
onMissing: BindingOnMissing;
|
|
305
|
+
onMany: BindingOnMany;
|
|
306
|
+
};
|
|
307
|
+
export declare const BINDING_OPTION_DEFAULTS: {
|
|
308
|
+
readonly cardinality: '0..1';
|
|
309
|
+
readonly onMissing: 'omit';
|
|
310
|
+
readonly onMany: 'error';
|
|
311
|
+
};
|
|
267
312
|
export type MappingBinding = {
|
|
268
313
|
nodeId: NodeId;
|
|
269
314
|
fieldId: string;
|
|
270
315
|
target: BindingTarget;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
316
|
+
/** Absent means `0..1` (BINDING_OPTION_DEFAULTS) — never stored at its default. */
|
|
317
|
+
cardinality?: BindingCardinality;
|
|
318
|
+
/** Absent means `omit`. */
|
|
319
|
+
onMissing?: BindingOnMissing;
|
|
320
|
+
/** Absent means `error`. */
|
|
321
|
+
onMany?: BindingOnMany;
|
|
274
322
|
[key: string]: unknown;
|
|
275
323
|
};
|
|
324
|
+
/**
|
|
325
|
+
* Hydrates a stored binding's behaviours to the total set (§2.2a: "the hydrated in-memory binding is
|
|
326
|
+
* a total object"). One place rather than `?? 'omit'` at each use site — a reader that spelled the
|
|
327
|
+
* fallback itself would be a second declaration of the default, free to drift from the reducer's.
|
|
328
|
+
*/
|
|
329
|
+
export declare const resolveBindingOptions: (binding: MappingBinding) => ResolvedBindingOptions;
|
|
330
|
+
/** Whether a binding's cardinality means "many values", i.e. it feeds a grid's rows rather than one slot. */
|
|
331
|
+
export declare const bindingIsMultiValued: (binding: MappingBinding) => boolean;
|
|
276
332
|
/** Carries no `nodeId` back-pointer: the node already lists it (§2.2a). */
|
|
277
333
|
export type MappingFilter = {
|
|
278
334
|
fieldId: string;
|
|
@@ -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,K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,CAAA;IACvD,kBAAkB,CAAC,EAAE,MAAM,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAA;CACvD,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC5B,cAAc,EAAE,UAAU,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IACxC,wBAAwB,CAAC,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;IACtD,gBAAgB,CAAC,EAAE,MAAM,CAAC,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"}
|
|
@@ -15,6 +15,46 @@
|
|
|
15
15
|
export const bindingTargetKey = (target) => target.kind === 'question'
|
|
16
16
|
? `question:${target.questionId}`
|
|
17
17
|
: `gridColumn:${target.gridQuestionId}:${target.columnQuestionId}`;
|
|
18
|
+
/**
|
|
19
|
+
* A binding's expected cardinality (§13.1). Closed rather than a loose string because the compiler
|
|
20
|
+
* branches on it: `0..1`/`1` fill one slot, `0..*`/`1..*` feed a grid's rows, and a typo would compile
|
|
21
|
+
* into an artifact that is immutable forever.
|
|
22
|
+
*
|
|
23
|
+
* `0..1` is the default, so DOC-LAW-2 means it is **never stored** — a binding that takes at most one
|
|
24
|
+
* value carries no `cardinality` key at all.
|
|
25
|
+
*
|
|
26
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-15-20-38-analysis-qnr-external-data-mapping-options.md:840 — the four values
|
|
27
|
+
*/
|
|
28
|
+
export const BINDING_CARDINALITIES = ['0..1', '1', '0..*', '1..*'];
|
|
29
|
+
/**
|
|
30
|
+
* What the runtime does when the source yields **no** value for a binding. `omit` leaves the question
|
|
31
|
+
* unfilled (the default); `error` makes the absence a prefill failure the author wants surfaced rather
|
|
32
|
+
* than silently tolerated.
|
|
33
|
+
*/
|
|
34
|
+
export const BINDING_ON_MISSING = ['omit', 'error'];
|
|
35
|
+
/**
|
|
36
|
+
* What the runtime does when the source yields **many** values for a binding expecting one. `error` is
|
|
37
|
+
* the default — an ambiguous prefill is a real defect — and `first` is the deliberate opt-in, which is
|
|
38
|
+
* why the node's `orderBy` must make "first" deterministic before it means anything.
|
|
39
|
+
*/
|
|
40
|
+
export const BINDING_ON_MANY = ['error', 'first'];
|
|
41
|
+
export const BINDING_OPTION_DEFAULTS = {
|
|
42
|
+
cardinality: '0..1',
|
|
43
|
+
onMissing: 'omit',
|
|
44
|
+
onMany: 'error',
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Hydrates a stored binding's behaviours to the total set (§2.2a: "the hydrated in-memory binding is
|
|
48
|
+
* a total object"). One place rather than `?? 'omit'` at each use site — a reader that spelled the
|
|
49
|
+
* fallback itself would be a second declaration of the default, free to drift from the reducer's.
|
|
50
|
+
*/
|
|
51
|
+
export const resolveBindingOptions = (binding) => ({
|
|
52
|
+
cardinality: binding.cardinality ?? BINDING_OPTION_DEFAULTS.cardinality,
|
|
53
|
+
onMissing: binding.onMissing ?? BINDING_OPTION_DEFAULTS.onMissing,
|
|
54
|
+
onMany: binding.onMany ?? BINDING_OPTION_DEFAULTS.onMany,
|
|
55
|
+
});
|
|
56
|
+
/** Whether a binding's cardinality means "many values", i.e. it feeds a grid's rows rather than one slot. */
|
|
57
|
+
export const bindingIsMultiValued = (binding) => resolveBindingOptions(binding).cardinality.endsWith('*');
|
|
18
58
|
/**
|
|
19
59
|
* A new family's document. `questionOrder` is present-and-empty rather than absent
|
|
20
60
|
* because it is the document's only structural array and every reader indexes it; an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateDocument.js","sourceRoot":"","sources":["../../src/collaboration/templateDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA0PH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAqB,EAAU,EAAE,CAC9D,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;
|
|
1
|
+
{"version":3,"file":"templateDocument.js","sourceRoot":"","sources":["../../src/collaboration/templateDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA0PH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAqB,EAAU,EAAE,CAC9D,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;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAU,CAAA;AAG3E;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,OAAO,CAAU,CAAA;AAG5D;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,CAAU,CAAA;AAkB1D,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACnC,WAAW,EAAE,MAAM;IACnB,SAAS,EAAE,MAAM;IACjB,MAAM,EAAE,OAAO;CACwB,CAAA;AAe3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAuB,EAA0B,EAAE,CAAC,CAAC;IACvF,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,uBAAuB,CAAC,WAAW;IACvE,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,uBAAuB,CAAC,SAAS;IACjE,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,uBAAuB,CAAC,MAAM;CAC3D,CAAC,CAAA;AAEF,6GAA6G;AAC7G,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,OAAuB,EAAW,EAAE,CACrE,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAqE5D;;;;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
|
@@ -7,8 +7,18 @@ import {
|
|
|
7
7
|
UnknownOperationError,
|
|
8
8
|
applyOperation,
|
|
9
9
|
} from './applyOperation.js'
|
|
10
|
+
import { canonicalJson, reduceToMinimalForm } from './canonicalize.js'
|
|
10
11
|
import type { TemplateOp } from './operations.js'
|
|
11
|
-
import {
|
|
12
|
+
import { templateDocumentIsDefault } from './schemas.js'
|
|
13
|
+
import {
|
|
14
|
+
BINDING_CARDINALITIES,
|
|
15
|
+
BINDING_OPTION_DEFAULTS,
|
|
16
|
+
bindingIsMultiValued,
|
|
17
|
+
emptyTemplateDocument,
|
|
18
|
+
resolveBindingOptions,
|
|
19
|
+
type MappingBinding,
|
|
20
|
+
type QnrTemplateDocument,
|
|
21
|
+
} from './templateDocument.js'
|
|
12
22
|
|
|
13
23
|
/**
|
|
14
24
|
* Guards the invariants a consumer would notice if a publish broke them. The exhaustive
|
|
@@ -991,3 +1001,146 @@ describe('applyOperation', () => {
|
|
|
991
1001
|
assert.equal(replayed.revision, deleted.revision + 1)
|
|
992
1002
|
})
|
|
993
1003
|
})
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* The binding behaviours — `cardinality` / `onMissing` / `onMany` (§2.2a, TASK-304 AC-6).
|
|
1008
|
+
*
|
|
1009
|
+
* Two rules meet on these three members and pull in opposite directions, which is what the suite is
|
|
1010
|
+
* really about. The author must be able to state them **explicitly**, because the compiler branches on
|
|
1011
|
+
* them and an artifact is immutable once minted; and DOC-LAW-2 says the *document* may never carry a
|
|
1012
|
+
* key at its own default, because the hash is computed on the minimal form. So "explicitly chosen" and
|
|
1013
|
+
* "stored" are deliberately not the same thing: choosing the default writes nothing.
|
|
1014
|
+
*
|
|
1015
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-15-20-38-analysis-qnr-external-data-mapping-options.md:832
|
|
1016
|
+
*/
|
|
1017
|
+
describe('mappingBinding behaviours', () => {
|
|
1018
|
+
const bound = apply([
|
|
1019
|
+
{ type: 'question.create', questionId: 'q-1', questionType: 'TextShort' },
|
|
1020
|
+
{ type: 'mappingNode.create', nodeId: 'n-1', entityId: 'Actor' },
|
|
1021
|
+
])
|
|
1022
|
+
|
|
1023
|
+
const create = (options: Partial<Pick<MappingBinding, 'cardinality' | 'onMissing' | 'onMany'>> = {}) =>
|
|
1024
|
+
applyOperation(bound, {
|
|
1025
|
+
type: 'mappingBinding.create',
|
|
1026
|
+
bindingId: 'b-1',
|
|
1027
|
+
nodeId: 'n-1',
|
|
1028
|
+
fieldId: 'Navn',
|
|
1029
|
+
target: { kind: 'question', questionId: 'q-1' },
|
|
1030
|
+
...options,
|
|
1031
|
+
})
|
|
1032
|
+
|
|
1033
|
+
const binding = (doc: QnrTemplateDocument) => doc.mappingBindingsById?.['b-1']
|
|
1034
|
+
|
|
1035
|
+
it('stores a behaviour the author narrowed away from its default', () => {
|
|
1036
|
+
const doc = create({ cardinality: '0..*', onMissing: 'error', onMany: 'first' })
|
|
1037
|
+
|
|
1038
|
+
assert.deepEqual(binding(doc), {
|
|
1039
|
+
nodeId: 'n-1',
|
|
1040
|
+
fieldId: 'Navn',
|
|
1041
|
+
target: { kind: 'question', questionId: 'q-1' },
|
|
1042
|
+
cardinality: '0..*',
|
|
1043
|
+
onMissing: 'error',
|
|
1044
|
+
onMany: 'first',
|
|
1045
|
+
})
|
|
1046
|
+
})
|
|
1047
|
+
|
|
1048
|
+
it('omits each behaviour the author explicitly set to its own default (DOC-LAW-2)', () => {
|
|
1049
|
+
// One at a time, so a reducer that special-cased only `cardinality` cannot pass.
|
|
1050
|
+
for (const [key, value] of Object.entries(BINDING_OPTION_DEFAULTS)) {
|
|
1051
|
+
const doc = create({ [key]: value })
|
|
1052
|
+
|
|
1053
|
+
assert.deepEqual(
|
|
1054
|
+
binding(doc),
|
|
1055
|
+
{ nodeId: 'n-1', fieldId: 'Navn', target: { kind: 'question', questionId: 'q-1' } },
|
|
1056
|
+
`${key}: '${value}' is the default and must not be stored`,
|
|
1057
|
+
)
|
|
1058
|
+
}
|
|
1059
|
+
})
|
|
1060
|
+
|
|
1061
|
+
it('makes an explicitly-defaulted binding byte-identical to an untouched one', () => {
|
|
1062
|
+
// The consequence that matters: `document_hash` decides whether a version is minted and
|
|
1063
|
+
// whether a re-import diverged. Two authors reaching the same binding through different
|
|
1064
|
+
// clicks must not produce two hashes.
|
|
1065
|
+
const untouched = canonicalJson(reduceToMinimalForm(create(), { isDefault: templateDocumentIsDefault }))
|
|
1066
|
+
const spelledOut = canonicalJson(
|
|
1067
|
+
reduceToMinimalForm(create({ cardinality: '0..1', onMissing: 'omit', onMany: 'error' }), {
|
|
1068
|
+
isDefault: templateDocumentIsDefault,
|
|
1069
|
+
}),
|
|
1070
|
+
)
|
|
1071
|
+
|
|
1072
|
+
assert.equal(spelledOut, untouched)
|
|
1073
|
+
})
|
|
1074
|
+
|
|
1075
|
+
it('sets, replaces and unsets a behaviour through update', () => {
|
|
1076
|
+
const set = applyOperation(create(), {
|
|
1077
|
+
type: 'mappingBinding.update',
|
|
1078
|
+
bindingId: 'b-1',
|
|
1079
|
+
patch: { onMany: 'first' },
|
|
1080
|
+
})
|
|
1081
|
+
assert.equal(binding(set)?.onMany, 'first')
|
|
1082
|
+
|
|
1083
|
+
const replaced = applyOperation(set, {
|
|
1084
|
+
type: 'mappingBinding.update',
|
|
1085
|
+
bindingId: 'b-1',
|
|
1086
|
+
patch: { onMany: 'error' },
|
|
1087
|
+
})
|
|
1088
|
+
// 'error' IS the default, so replacing back to it removes the key rather than storing it.
|
|
1089
|
+
assert.equal('onMany' in (binding(replaced) ?? {}), false)
|
|
1090
|
+
|
|
1091
|
+
const unset = applyOperation(set, {
|
|
1092
|
+
type: 'mappingBinding.update',
|
|
1093
|
+
bindingId: 'b-1',
|
|
1094
|
+
patch: { onMany: null },
|
|
1095
|
+
})
|
|
1096
|
+
assert.equal('onMany' in (binding(unset) ?? {}), false)
|
|
1097
|
+
})
|
|
1098
|
+
|
|
1099
|
+
it('leaves a behaviour alone when the patch does not name it', () => {
|
|
1100
|
+
const doc = create({ cardinality: '1..*', onMissing: 'error' })
|
|
1101
|
+
|
|
1102
|
+
const patched = applyOperation(doc, {
|
|
1103
|
+
type: 'mappingBinding.update',
|
|
1104
|
+
bindingId: 'b-1',
|
|
1105
|
+
patch: { fieldId: 'Adresse' },
|
|
1106
|
+
})
|
|
1107
|
+
|
|
1108
|
+
assert.equal(binding(patched)?.fieldId, 'Adresse')
|
|
1109
|
+
assert.equal(binding(patched)?.cardinality, '1..*')
|
|
1110
|
+
assert.equal(binding(patched)?.onMissing, 'error')
|
|
1111
|
+
})
|
|
1112
|
+
|
|
1113
|
+
it('never writes an explicit null into the document', () => {
|
|
1114
|
+
const doc = applyOperation(create({ onMissing: 'error' }), {
|
|
1115
|
+
type: 'mappingBinding.update',
|
|
1116
|
+
bindingId: 'b-1',
|
|
1117
|
+
patch: { onMissing: null, cardinality: null, onMany: null },
|
|
1118
|
+
})
|
|
1119
|
+
|
|
1120
|
+
assert.equal(canonicalJson(binding(doc)).includes('null'), false)
|
|
1121
|
+
})
|
|
1122
|
+
|
|
1123
|
+
it('hydrates absent behaviours to the defaults every reader must agree on', () => {
|
|
1124
|
+
assert.deepEqual(resolveBindingOptions(binding(create()) as MappingBinding), BINDING_OPTION_DEFAULTS)
|
|
1125
|
+
|
|
1126
|
+
assert.deepEqual(resolveBindingOptions(binding(create({ onMany: 'first' })) as MappingBinding), {
|
|
1127
|
+
...BINDING_OPTION_DEFAULTS,
|
|
1128
|
+
onMany: 'first',
|
|
1129
|
+
})
|
|
1130
|
+
})
|
|
1131
|
+
|
|
1132
|
+
it('reads exactly the starred cardinalities as multi-valued', () => {
|
|
1133
|
+
const multi = BINDING_CARDINALITIES.filter((cardinality) =>
|
|
1134
|
+
bindingIsMultiValued({
|
|
1135
|
+
nodeId: 'n-1',
|
|
1136
|
+
fieldId: 'Navn',
|
|
1137
|
+
target: { kind: 'question', questionId: 'q-1' },
|
|
1138
|
+
cardinality,
|
|
1139
|
+
}),
|
|
1140
|
+
)
|
|
1141
|
+
|
|
1142
|
+
assert.deepEqual(multi, ['0..*', '1..*'])
|
|
1143
|
+
// And the absent case resolves through the default, which is single-valued.
|
|
1144
|
+
assert.equal(bindingIsMultiValued(binding(create()) as MappingBinding), false)
|
|
1145
|
+
})
|
|
1146
|
+
})
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import type { TemplateOp } from './operations.js'
|
|
2
2
|
import type {
|
|
3
|
+
BindingCardinality,
|
|
4
|
+
BindingOnMany,
|
|
5
|
+
BindingOnMissing,
|
|
6
|
+
MappingBinding,
|
|
3
7
|
MappingNode,
|
|
4
8
|
QnrDataMapping,
|
|
5
9
|
QnrQuestion,
|
|
6
10
|
QnrTemplateDocument,
|
|
7
11
|
QuestionId,
|
|
8
12
|
} from './templateDocument.js'
|
|
9
|
-
import { bindingTargetKey } from './templateDocument.js'
|
|
13
|
+
import { BINDING_OPTION_DEFAULTS, bindingTargetKey } from './templateDocument.js'
|
|
14
|
+
|
|
15
|
+
/** The behaviour members, so the write loop cannot silently miss one that `BINDING_OPTION_DEFAULTS` gains. */
|
|
16
|
+
const BINDING_OPTION_KEYS = Object.keys(BINDING_OPTION_DEFAULTS) as ReadonlyArray<keyof typeof BINDING_OPTION_DEFAULTS>
|
|
10
17
|
|
|
11
18
|
/**
|
|
12
19
|
* The authoring reducer. Pure: takes a document and an op, returns a new document with
|
|
@@ -109,6 +116,38 @@ const moveInOrder = (order: readonly string[], id: string, toIndex: number): str
|
|
|
109
116
|
return [...without.slice(0, at), id, ...without.slice(at)]
|
|
110
117
|
}
|
|
111
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Writes a binding's three behaviours in canonical minimal form.
|
|
121
|
+
*
|
|
122
|
+
* Three cases, and the middle one is the reason this is a function rather than a spread:
|
|
123
|
+
* `undefined` leaves the stored value alone (the member was not part of this edit), an explicit
|
|
124
|
+
* `null` unsets it, and **a value equal to the default unsets it too** — DOC-LAW-2 forbids a key
|
|
125
|
+
* present with its own default, so an author choosing `onMany: 'error'` and an author never touching
|
|
126
|
+
* it must produce byte-identical documents. If they did not, the same binding would carry two
|
|
127
|
+
* `document_hash` values depending on which control the author clicked, minting a spurious version
|
|
128
|
+
* and reading as divergence against the imported original.
|
|
129
|
+
*
|
|
130
|
+
* @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:195 — DOC-LAW-2
|
|
131
|
+
*/
|
|
132
|
+
const writeBindingOptions = (
|
|
133
|
+
binding: MappingBinding,
|
|
134
|
+
options: {
|
|
135
|
+
cardinality?: BindingCardinality | null
|
|
136
|
+
onMissing?: BindingOnMissing | null
|
|
137
|
+
onMany?: BindingOnMany | null
|
|
138
|
+
},
|
|
139
|
+
): MappingBinding => {
|
|
140
|
+
let next = binding
|
|
141
|
+
|
|
142
|
+
for (const key of BINDING_OPTION_KEYS) {
|
|
143
|
+
const chosen = options[key]
|
|
144
|
+
if (chosen === undefined) continue
|
|
145
|
+
next = writeField(next, key, chosen === BINDING_OPTION_DEFAULTS[key] ? null : chosen)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return next
|
|
149
|
+
}
|
|
150
|
+
|
|
112
151
|
const omitKey = <V>(record: Record<string, V>, key: string): Record<string, V> => {
|
|
113
152
|
const { [key]: _removed, ...rest } = record
|
|
114
153
|
return rest
|
|
@@ -1072,7 +1111,10 @@ const reduce = (doc: QnrTemplateDocument, op: TemplateOp): QnrTemplateDocument =
|
|
|
1072
1111
|
...doc,
|
|
1073
1112
|
mappingBindingsById: {
|
|
1074
1113
|
...(doc.mappingBindingsById ?? {}),
|
|
1075
|
-
[op.bindingId]:
|
|
1114
|
+
[op.bindingId]: writeBindingOptions(
|
|
1115
|
+
{ nodeId: op.nodeId, fieldId: op.fieldId, target: op.target },
|
|
1116
|
+
op,
|
|
1117
|
+
),
|
|
1076
1118
|
},
|
|
1077
1119
|
}
|
|
1078
1120
|
// The owning mapping root's `bindingOrder` lists the new binding — when the tree is
|
|
@@ -1114,11 +1156,21 @@ const reduce = (doc: QnrTemplateDocument, op: TemplateOp): QnrTemplateDocument =
|
|
|
1114
1156
|
)
|
|
1115
1157
|
}
|
|
1116
1158
|
}
|
|
1159
|
+
// The behaviours go through `writeBindingOptions` rather than the spread: a spread would
|
|
1160
|
+
// store `cardinality: '0..1'` verbatim (a key present with its own default — DOC-LAW-2) and
|
|
1161
|
+
// would write `null` for an unset, which the document may never carry.
|
|
1162
|
+
const {
|
|
1163
|
+
cardinality: _cardinality,
|
|
1164
|
+
onMissing: _onMissing,
|
|
1165
|
+
onMany: _onMany,
|
|
1166
|
+
...structural
|
|
1167
|
+
} = op.patch
|
|
1168
|
+
|
|
1117
1169
|
return {
|
|
1118
1170
|
...doc,
|
|
1119
1171
|
mappingBindingsById: {
|
|
1120
1172
|
...doc.mappingBindingsById,
|
|
1121
|
-
[op.bindingId]: { ...binding, ...op.patch
|
|
1173
|
+
[op.bindingId]: writeBindingOptions({ ...binding, ...structural }, op.patch),
|
|
1122
1174
|
},
|
|
1123
1175
|
}
|
|
1124
1176
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ActionId,
|
|
3
3
|
AltId,
|
|
4
|
+
BindingCardinality,
|
|
4
5
|
BindingId,
|
|
6
|
+
BindingOnMany,
|
|
7
|
+
BindingOnMissing,
|
|
5
8
|
BindingTarget,
|
|
6
9
|
DocScalar,
|
|
7
10
|
FilterId,
|
|
@@ -116,17 +119,39 @@ export type TemplateOp =
|
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
121
|
| { type: 'mappingNode.delete'; nodeId: NodeId }
|
|
122
|
+
/**
|
|
123
|
+
* The three behaviours are optional here and **omitted from the document when they equal their
|
|
124
|
+
* default** (DOC-LAW-2, `BINDING_OPTION_DEFAULTS`): the op carries what the author chose, the
|
|
125
|
+
* document stores only what differs. Authoring them is the point — a binding whose behaviour
|
|
126
|
+
* could not be stated would leave the compiler to guess what happens when the source yields
|
|
127
|
+
* nothing or yields many.
|
|
128
|
+
*/
|
|
119
129
|
| {
|
|
120
130
|
type: 'mappingBinding.create'
|
|
121
131
|
bindingId: BindingId
|
|
122
132
|
nodeId: NodeId
|
|
123
133
|
fieldId: string
|
|
124
134
|
target: BindingTarget
|
|
135
|
+
cardinality?: BindingCardinality
|
|
136
|
+
onMissing?: BindingOnMissing
|
|
137
|
+
onMany?: BindingOnMany
|
|
125
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* `null` on a behaviour is the explicit unset — the author returned it to the default, which the
|
|
141
|
+
* document encodes as absence. Without the tri-state "back to default" would be unexpressible:
|
|
142
|
+
* omitting the member from the patch means "leave it alone", which is a different edit.
|
|
143
|
+
*/
|
|
126
144
|
| {
|
|
127
145
|
type: 'mappingBinding.update'
|
|
128
146
|
bindingId: BindingId
|
|
129
|
-
patch: {
|
|
147
|
+
patch: {
|
|
148
|
+
nodeId?: NodeId
|
|
149
|
+
fieldId?: string
|
|
150
|
+
target?: BindingTarget
|
|
151
|
+
cardinality?: BindingCardinality | null
|
|
152
|
+
onMissing?: BindingOnMissing | null
|
|
153
|
+
onMany?: BindingOnMany | null
|
|
154
|
+
}
|
|
130
155
|
}
|
|
131
156
|
| { type: 'mappingBinding.delete'; bindingId: BindingId }
|
|
132
157
|
| {
|
|
@@ -422,3 +422,114 @@ describe('schema ↔ vocabulary parity', () => {
|
|
|
422
422
|
assert.equal(out instanceof type.errors, false)
|
|
423
423
|
})
|
|
424
424
|
})
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* The binding behaviours at the two validation layers (TASK-304 AC-6).
|
|
429
|
+
*
|
|
430
|
+
* The document schema and the op schema disagree on `null` **on purpose** — the op layer is the only
|
|
431
|
+
* place the absent-vs-cleared tri-state exists — so both halves are asserted rather than assumed.
|
|
432
|
+
*/
|
|
433
|
+
describe('mappingBinding behaviour schemas', () => {
|
|
434
|
+
const createOp = (options: Record<string, unknown>) => ({
|
|
435
|
+
type: 'mappingBinding.create',
|
|
436
|
+
bindingId: 'b-1',
|
|
437
|
+
nodeId: 'n-1',
|
|
438
|
+
fieldId: 'Navn',
|
|
439
|
+
target: { kind: 'question', questionId: 'q-1' },
|
|
440
|
+
...options,
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
const documentWith = (binding: Record<string, unknown>): QnrTemplateDocument =>
|
|
444
|
+
({
|
|
445
|
+
...emptyTemplateDocument('tpl-1'),
|
|
446
|
+
questionsById: { 'q-1': { type: 'TextShort' } },
|
|
447
|
+
questionOrder: ['q-1'],
|
|
448
|
+
mappingNodesById: { 'n-1': { entityId: 'Actor' } },
|
|
449
|
+
mappingBindingsById: { 'b-1': binding },
|
|
450
|
+
}) as unknown as QnrTemplateDocument
|
|
451
|
+
|
|
452
|
+
it('accepts every declared behaviour value on the create op', () => {
|
|
453
|
+
for (const cardinality of ['0..1', '1', '0..*', '1..*']) {
|
|
454
|
+
assert.equal(templateOpSchema(createOp({ cardinality })) instanceof type.errors, false, cardinality)
|
|
455
|
+
}
|
|
456
|
+
for (const onMissing of ['omit', 'error']) {
|
|
457
|
+
assert.equal(templateOpSchema(createOp({ onMissing })) instanceof type.errors, false, onMissing)
|
|
458
|
+
}
|
|
459
|
+
for (const onMany of ['error', 'first']) {
|
|
460
|
+
assert.equal(templateOpSchema(createOp({ onMany })) instanceof type.errors, false, onMany)
|
|
461
|
+
}
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
it('refuses a behaviour value outside the closed set', () => {
|
|
465
|
+
// The whole reason these are not `string?`: this op compiles into an immutable artifact.
|
|
466
|
+
assert.ok(templateOpSchema(createOp({ cardinality: '0..2' })) instanceof type.errors)
|
|
467
|
+
assert.ok(templateOpSchema(createOp({ onMissing: 'ignore' })) instanceof type.errors)
|
|
468
|
+
assert.ok(templateOpSchema(createOp({ onMany: 'last' })) instanceof type.errors)
|
|
469
|
+
})
|
|
470
|
+
|
|
471
|
+
it('refuses a behaviour value outside the closed set on a STORED binding too', () => {
|
|
472
|
+
// The op schema guards the wire; this one guards the document. Both are needed: an import or a
|
|
473
|
+
// replay writes a document without passing an op through, and a loose document position would
|
|
474
|
+
// let a value the compiler cannot branch on reach an immutable artifact.
|
|
475
|
+
for (const option of [{ cardinality: '0..2' }, { onMissing: 'ignore' }, { onMany: 'last' }]) {
|
|
476
|
+
const result = validateTemplateDocument(
|
|
477
|
+
documentWith({
|
|
478
|
+
nodeId: 'n-1',
|
|
479
|
+
fieldId: 'Navn',
|
|
480
|
+
target: { kind: 'question', questionId: 'q-1' },
|
|
481
|
+
...option,
|
|
482
|
+
}),
|
|
483
|
+
)
|
|
484
|
+
|
|
485
|
+
assert.equal(result.ok, false, `${JSON.stringify(option)} must not validate`)
|
|
486
|
+
}
|
|
487
|
+
})
|
|
488
|
+
|
|
489
|
+
it('admits null in an update patch and refuses it in the document', () => {
|
|
490
|
+
const patched = templateOpSchema({
|
|
491
|
+
type: 'mappingBinding.update',
|
|
492
|
+
bindingId: 'b-1',
|
|
493
|
+
patch: { cardinality: null, onMissing: null, onMany: null },
|
|
494
|
+
})
|
|
495
|
+
assert.equal(patched instanceof type.errors, false)
|
|
496
|
+
|
|
497
|
+
assert.ok(
|
|
498
|
+
validateTemplateDocument(documentWith({
|
|
499
|
+
nodeId: 'n-1',
|
|
500
|
+
fieldId: 'Navn',
|
|
501
|
+
target: { kind: 'question', questionId: 'q-1' },
|
|
502
|
+
onMany: null,
|
|
503
|
+
})).ok === false,
|
|
504
|
+
)
|
|
505
|
+
})
|
|
506
|
+
|
|
507
|
+
it('counts a stored behaviour at its default as a DOC-LAW-2 violation', () => {
|
|
508
|
+
const violations = findDocLawDefaultViolations(
|
|
509
|
+
documentWith({
|
|
510
|
+
nodeId: 'n-1',
|
|
511
|
+
fieldId: 'Navn',
|
|
512
|
+
target: { kind: 'question', questionId: 'q-1' },
|
|
513
|
+
cardinality: '0..1',
|
|
514
|
+
}),
|
|
515
|
+
)
|
|
516
|
+
|
|
517
|
+
assert.deepEqual(
|
|
518
|
+
violations.map((violation) => violation.path),
|
|
519
|
+
['mappingBindingsById.b-1.cardinality'],
|
|
520
|
+
)
|
|
521
|
+
})
|
|
522
|
+
|
|
523
|
+
it('never reads a mapping NODE cardinality as an omittable default', () => {
|
|
524
|
+
// A node's default cardinality is the catalog relation's, not a literal — so a node that
|
|
525
|
+
// narrows a `0..*` relation to a single row stores `0..1` meaningfully. A suffix-matched
|
|
526
|
+
// default rule would drop exactly that member and silently widen the traversal.
|
|
527
|
+
assert.equal(templateDocumentIsDefault('mappingNodesById.n-1.cardinality', '0..1'), false)
|
|
528
|
+
assert.equal(templateDocumentIsDefault('mappingBindingsById.b-1.cardinality', '0..1'), true)
|
|
529
|
+
|
|
530
|
+
// And a non-default value on a binding is never omittable either.
|
|
531
|
+
assert.equal(templateDocumentIsDefault('mappingBindingsById.b-1.cardinality', '0..*'), false)
|
|
532
|
+
assert.equal(templateDocumentIsDefault('mappingBindingsById.b-1.onMissing', 'omit'), true)
|
|
533
|
+
assert.equal(templateDocumentIsDefault('mappingBindingsById.b-1.onMany', 'error'), true)
|
|
534
|
+
})
|
|
535
|
+
})
|