asma-core-helpers 0.38.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/collaboration/applyOperation.d.ts.map +1 -1
  2. package/lib/collaboration/applyOperation.js +194 -0
  3. package/lib/collaboration/applyOperation.js.map +1 -1
  4. package/lib/collaboration/index.d.ts +1 -0
  5. package/lib/collaboration/index.d.ts.map +1 -1
  6. package/lib/collaboration/index.js +1 -0
  7. package/lib/collaboration/index.js.map +1 -1
  8. package/lib/collaboration/operations.d.ts +98 -0
  9. package/lib/collaboration/operations.d.ts.map +1 -1
  10. package/lib/collaboration/operations.js +4 -0
  11. package/lib/collaboration/operations.js.map +1 -1
  12. package/lib/collaboration/schemas.d.ts +138 -0
  13. package/lib/collaboration/schemas.d.ts.map +1 -1
  14. package/lib/collaboration/schemas.js +198 -10
  15. package/lib/collaboration/schemas.js.map +1 -1
  16. package/lib/collaboration/templateAuthoringMeta.d.ts +424 -0
  17. package/lib/collaboration/templateAuthoringMeta.d.ts.map +1 -0
  18. package/lib/collaboration/templateAuthoringMeta.js +726 -0
  19. package/lib/collaboration/templateAuthoringMeta.js.map +1 -0
  20. package/lib/collaboration/templateDocument.d.ts +136 -14
  21. package/lib/collaboration/templateDocument.d.ts.map +1 -1
  22. package/lib/collaboration/templateDocument.js +19 -0
  23. package/lib/collaboration/templateDocument.js.map +1 -1
  24. package/lib/collaboration/testHelpers/documentGenerator.d.ts.map +1 -1
  25. package/lib/collaboration/testHelpers/documentGenerator.js +53 -0
  26. package/lib/collaboration/testHelpers/documentGenerator.js.map +1 -1
  27. package/lib/collaboration/typeContracts.d.ts +139 -0
  28. package/lib/collaboration/typeContracts.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/collaboration/applyOperation.ts +251 -0
  31. package/src/collaboration/index.ts +1 -0
  32. package/src/collaboration/operations.ts +100 -0
  33. package/src/collaboration/property.test.ts +56 -1
  34. package/src/collaboration/schemas.test.ts +172 -1
  35. package/src/collaboration/schemas.ts +214 -9
  36. package/src/collaboration/templateAuthoringMeta.test.ts +1286 -0
  37. package/src/collaboration/templateAuthoringMeta.ts +1098 -0
  38. package/src/collaboration/templateDocument.ts +139 -14
  39. package/src/collaboration/testHelpers/documentGenerator.ts +60 -0
  40. package/src/collaboration/typeContracts.ts +155 -0
@@ -0,0 +1,424 @@
1
+ import type { JsonValue } from './canonicalize.js';
2
+ import type { ConflictMarker } from './conflicts.js';
3
+ import type { TemplateOp } from './operations.js';
4
+ import type { DocScalar, Initiator, QnrTemplateDocument, QnrTemplateMeta, RequiredAccessLevel, TemplateUpdateMode, TemplateVisibility } from './templateDocument.js';
5
+ /**
6
+ * The template metadata/settings authoring surface: one exact-path registry, one non-mutating
7
+ * total reader, and the canonical loci concurrent intent is compared on.
8
+ *
9
+ * **Why a registry rather than three agreeing implementations.** The reducer, the canonical write
10
+ * boundary, the legacy importer and the authoring UI must share one vocabulary and one set of
11
+ * defaults, because the hash is computed on the minimal form: if the importer thought
12
+ * `rendering.refresh_button` defaulted to `false` and the reducer thought `true`, an imported
13
+ * template and the same template re-authored by hand would carry two `document_hash` values for one
14
+ * authored state — minting a spurious version and reading as divergence against the import. So the
15
+ * defaults are declared once, here, and every consumer reads them from this module.
16
+ *
17
+ * **Why the paths are absolute and matched exactly.** The released `templateDocumentIsDefault`
18
+ * matches its default names by *suffix* (`path.endsWith('.' + name)`), which was safe for the three
19
+ * names it carried and is not safe for this vocabulary: `title`, `enabled` and `refresh_button` are
20
+ * ordinary words that appear in imported unknown bags, inside presentation profiles and on questions.
21
+ * A suffix rule would prune a coincidentally-named unknown key — silent data loss in a hashed
22
+ * document. Every path declared here is therefore the complete document-absolute path, anchored at
23
+ * the document root the way `reduceToMinimalForm` is invoked on a whole document.
24
+ *
25
+ * **Why this registry is NOT retrofitted onto the released canonical form.** See
26
+ * `templateAuthoringIsDefault` in `schemas.ts`: three of the paths below (`requiredAccessLevel`,
27
+ * `initiator`, `template_update_mode`) are released schema members with no declared default, so an
28
+ * already-stored document may legitimately carry them spelled out. Declaring their defaults inside
29
+ * the released predicate would change those documents' canonical bytes and therefore their
30
+ * `document_hash` — i.e. it would break the immutable versions this work must preserve. The released
31
+ * predicate stays byte-identical and the expanded one applies to new writes and new canonical
32
+ * imports only.
33
+ *
34
+ * @see asma-modules/_docs/editor/qnrs/cross/2026-07-12-20-20-architecture-qnr-v2-model-collaboration-sync.md:195 — DOC-LAW-2
35
+ */
36
+ /**
37
+ * The seven editable metadata paths, relative to `meta`, and the value each one takes.
38
+ *
39
+ * A correlated union rather than `{ field: string; value: OpValue }`: the value a path accepts is a
40
+ * property OF the path, so a single loose pair would type-check `{field: 'visibility', value: 7}`
41
+ * and leave the reducer as the only thing that noticed — a runtime refusal for something the
42
+ * compiler can prevent. The op arms in `operations.ts` are derived from this union, so adding a
43
+ * field here is what adds it to the wire, and nothing can drift between the two declarations.
44
+ *
45
+ * `legacy.plan_category` is deliberately NOT a member. It is import-preserved compatibility residue
46
+ * with no asserted default, not a control an author sets; giving it an authoring arm would invent a
47
+ * product meaning this work is not authorized to invent.
48
+ */
49
+ export type TemplateMetaFieldWrite = {
50
+ field: 'title';
51
+ value: string;
52
+ } | {
53
+ field: 'description';
54
+ value: string;
55
+ } | {
56
+ field: 'visibility';
57
+ value: TemplateVisibility;
58
+ } | {
59
+ field: 'instancePolicy.requiredAccessLevel';
60
+ value: RequiredAccessLevel;
61
+ } | {
62
+ field: 'instancePolicy.invitationRequired';
63
+ value: boolean;
64
+ } | {
65
+ field: 'instancePolicy.initiator';
66
+ value: Initiator;
67
+ } | {
68
+ field: 'instancePolicy.template_update_mode';
69
+ value: TemplateUpdateMode;
70
+ };
71
+ /** The seven metadata paths a typed operation may write. */
72
+ export type MetaField = TemplateMetaFieldWrite['field'];
73
+ /** Every value any metadata path accepts. Correlation lives in {@link TemplateMetaFieldWrite}. */
74
+ export type MetaFieldValue = TemplateMetaFieldWrite['value'];
75
+ /**
76
+ * The 23 settings leaves, as group-relative paths under `meta.settings`.
77
+ *
78
+ * Grouped by the surface they configure rather than flattened, because the groups are what make the
79
+ * minimal form prunable: unsetting the last leaf of `rendering` removes `rendering`, and unsetting
80
+ * the last group removes `settings` (DOC-LAW-2). Every leaf is a boolean; the only non-false default
81
+ * is `rendering.refresh_button`.
82
+ */
83
+ export declare const TEMPLATE_SETTING_FIELDS: readonly ['journal.auto_import', 'journal.requires_activity_id', 'journal.register_new_activity', 'journal.user_context_me', 'pdf.import', 'pdf.generate_for_participant', 'pdf.send_to_journal', 'rendering.tabs', 'rendering.continuous', 'rendering.multi_step', 'rendering.collapse_all', 'rendering.top_level_actions', 'rendering.refresh_button', 'rendering.filter_document_reports_on_tab', 'rendering.hide_recipient_info', 'lifecycle.rejectable', 'lifecycle.shareable', 'lifecycle.allow_multiple', 'lifecycle.generate_on_start', 'recipient.requires_phone_number', 'highlight.enabled', 'highlight.show_to_recipient', 'distribution.mirror_to_advoca'];
84
+ export type SettingField = (typeof TEMPLATE_SETTING_FIELDS)[number];
85
+ /** The seven metadata paths as a runtime list, so a consumer can iterate the vocabulary it renders. */
86
+ export declare const TEMPLATE_META_FIELDS: readonly ["title", "description", "visibility", "instancePolicy.requiredAccessLevel", "instancePolicy.invitationRequired", "instancePolicy.initiator", "instancePolicy.template_update_mode"];
87
+ /**
88
+ * The owner-domain soft-reference sets (REQ-013): ids only, no bodies, no FK validation.
89
+ *
90
+ * Authored by membership add/remove rather than whole-array writes, for DOC-LAW-1's reason: two
91
+ * authors adding different ids concurrently produce two member edits that both survive, where two
92
+ * whole-array patches would have the second discard the first.
93
+ */
94
+ export declare const COMPATIBILITY_COLLECTIONS: readonly ['consentTemplateIds', 'smsTemplateIds'];
95
+ export type CompatibilityCollection = (typeof COMPATIBILITY_COLLECTIONS)[number];
96
+ export declare const isMetaField: (value: unknown) => value is MetaField;
97
+ export declare const isSettingField: (value: unknown) => value is SettingField;
98
+ export declare const isCompatibilityCollection: (value: unknown) => value is CompatibilityCollection;
99
+ /** The metadata defaults, keyed by document-absolute path. Absent is the only encoding of each. */
100
+ export declare const TEMPLATE_META_DEFAULTS: {
101
+ readonly title: '';
102
+ readonly description: '';
103
+ readonly visibility: 'visible';
104
+ readonly 'instancePolicy.requiredAccessLevel': 4;
105
+ readonly 'instancePolicy.invitationRequired': false;
106
+ readonly 'instancePolicy.initiator': 'coordinator';
107
+ readonly 'instancePolicy.template_update_mode': 'never';
108
+ };
109
+ /**
110
+ * The settings defaults.
111
+ *
112
+ * `rendering.refresh_button` is the one `true`: legacy's flag model initialises it on, so a template
113
+ * that never mentions it still shows the refresh control. Evidence is
114
+ * `asma-app-editor/src/mst/models/flags/QnrFlagsBase.model.ts`. Getting this one wrong is not a
115
+ * cosmetic defect — it flips a control for every imported template that omits the flag.
116
+ */
117
+ export declare const TEMPLATE_SETTING_DEFAULTS: {
118
+ readonly 'journal.auto_import': false;
119
+ readonly 'journal.requires_activity_id': false;
120
+ readonly 'journal.register_new_activity': false;
121
+ readonly 'journal.user_context_me': false;
122
+ readonly 'pdf.import': false;
123
+ readonly 'pdf.generate_for_participant': false;
124
+ readonly 'pdf.send_to_journal': false;
125
+ readonly 'rendering.tabs': false;
126
+ readonly 'rendering.continuous': false;
127
+ readonly 'rendering.multi_step': false;
128
+ readonly 'rendering.collapse_all': false;
129
+ readonly 'rendering.top_level_actions': false;
130
+ readonly 'rendering.refresh_button': true;
131
+ readonly 'rendering.filter_document_reports_on_tab': false;
132
+ readonly 'rendering.hide_recipient_info': false;
133
+ readonly 'lifecycle.rejectable': false;
134
+ readonly 'lifecycle.shareable': false;
135
+ readonly 'lifecycle.allow_multiple': false;
136
+ readonly 'lifecycle.generate_on_start': false;
137
+ readonly 'recipient.requires_phone_number': false;
138
+ readonly 'highlight.enabled': false;
139
+ readonly 'highlight.show_to_recipient': false;
140
+ readonly 'distribution.mirror_to_advoca': false;
141
+ };
142
+ /** `meta.<field>` — the document-absolute path (and canonical conflict locus) of a metadata field. */
143
+ export declare const metaFieldPath: (field: MetaField) => string;
144
+ /** `meta.settings.<field>` — the document-absolute path (and locus) of a settings leaf. */
145
+ export declare const settingFieldPath: (field: SettingField) => string;
146
+ /** `meta.compatibility.<collection>` — the whole set, which overlaps every one of its members. */
147
+ export declare const compatibilityCollectionPath: (collection: CompatibilityCollection) => string;
148
+ /**
149
+ * The locus of ONE member of a soft-id set.
150
+ *
151
+ * The id is an opaque bracketed member, not a dotted path segment: a soft id may legitimately contain
152
+ * a `.` (and legacy numeric ids stringify to anything), so `meta.compatibility.consentTemplateIds.a.b`
153
+ * would be ambiguous between the id `a.b` and a nested path. `JSON.stringify` escapes quotes and
154
+ * backslashes, which makes the encoding injective — two different ids can never produce one locus,
155
+ * and a locus can never be mistaken for an ancestor of another member.
156
+ *
157
+ * NFC-normalised for the same reason the stored set is (see `normalizeCompatibilityId`): the canonical
158
+ * serializer normalises strings, so two NFC-equivalent spellings are ONE member and must be ONE locus.
159
+ */
160
+ export declare const compatibilityIdPath: (collection: CompatibilityCollection, id: string) => string;
161
+ /**
162
+ * Every default this surface declares, by exact document-absolute path.
163
+ *
164
+ * A `Map` rather than an object so a path containing a `__proto__`-shaped segment cannot reach
165
+ * `Object.prototype` during lookup.
166
+ */
167
+ export declare const TEMPLATE_AUTHORING_DEFAULTS: ReadonlyMap<string, MetaFieldValue | boolean>;
168
+ /**
169
+ * Whether `value` at `path` is this surface's declared default and must therefore be omitted.
170
+ *
171
+ * Exact-path only, by design — see the module header. Feeds `templateAuthoringIsDefault`, which is
172
+ * the canonical-write predicate; it is deliberately NOT part of the released
173
+ * `templateDocumentIsDefault` used to verify historical stored snapshots.
174
+ */
175
+ export declare const isTemplateAuthoringDefault: (path: string, value: unknown) => boolean;
176
+ /** The declared default of a metadata field — total, so a reader never spells one itself. */
177
+ export declare const templateMetaDefault: <F extends MetaField>(field: F) => (typeof TEMPLATE_META_DEFAULTS)[F];
178
+ /** The declared default of a settings leaf. */
179
+ export declare const templateSettingDefault: (field: SettingField) => boolean;
180
+ /**
181
+ * How competing spellings of one field resolve.
182
+ *
183
+ * Two strategies, and the difference is not stylistic — it is the difference between a conservative
184
+ * requirement and a replaceable preference:
185
+ *
186
+ * - **`or`** — the journal activity-id and auto-import aliases. Legacy carries three spellings of the
187
+ * activity requirement (`activityId_required`, `soknadid_required`, the misspelled
188
+ * `sokndaid_required`), written by different code paths over the years, and a template that set ANY
189
+ * of them required an activity id. Taking the last entry would silently drop the requirement for
190
+ * whichever spelling happened to come second in key order, so these OR — and disagreeing booleans
191
+ * are reported, never resolved silently.
192
+ * - **`canonical-first`** — everything else. The canonical own-property wins when present, else the
193
+ * first recognized alias wins. Phone is the named case: it must NOT OR, because the new typed
194
+ * vocabulary is `requires_phone_number` and an author who turns the requirement OFF must see it
195
+ * off — an OR would let the stale `ask_for_phone_nr: true` outvote the explicit new `false`.
196
+ * (The reducer additionally clears the alias on a typed write, so the stale value cannot survive to
197
+ * be read at all; the reader's precedence is the second half of that guarantee, for documents no
198
+ * typed op has touched yet.)
199
+ */
200
+ export type TemplateAliasStrategy = 'or' | 'canonical-first';
201
+ export type TemplateAliasRule = {
202
+ /** Document-absolute recognized historical spellings, in precedence order. */
203
+ readonly aliasPaths: readonly string[];
204
+ readonly strategy: TemplateAliasStrategy;
205
+ };
206
+ /**
207
+ * The recognized alias spellings, keyed by canonical document-absolute path.
208
+ *
209
+ * Closed and explicit: a spelling absent here is an ordinary unknown member that this surface must
210
+ * leave alone, not a value it may read or clear. Extending the table is the only way to recognize a
211
+ * new legacy spelling, which is what keeps "recognized alias" from becoming "anything that looks
212
+ * related".
213
+ */
214
+ export declare const TEMPLATE_AUTHORING_ALIASES: ReadonlyMap<string, TemplateAliasRule>;
215
+ /** The recognized alias paths of one canonical path, or none. */
216
+ export declare const templateAliasPathsOf: (canonicalPath: string) => readonly string[];
217
+ /**
218
+ * The canonical paths a write at `path` reaches through the recognized alias table.
219
+ *
220
+ * **Overlap, not equality**, and that distinction was a reproduced defect. An open patch writing
221
+ * `initiator.unresolved` is writing INSIDE the recognized alias `meta.initiator`: it makes that path
222
+ * an object, and the next typed initiator write deletes the alias wholesale — taking the intervening
223
+ * data with it. Matching the alias exactly classified the two as disjoint, so the orders produced
224
+ * different documents with no conflict raised, which is precisely the lost update the locus
225
+ * machinery exists to catch. Ancestor and descendant both count, the same way they do for canonical
226
+ * loci.
227
+ *
228
+ * Plural because one legacy spelling could in principle serve two canonical fields; the lookup is a
229
+ * scan rather than a reverse index so the forward table stays the single declaration.
230
+ */
231
+ export declare const templateCanonicalPathsTouchedByAlias: (path: string) => readonly string[];
232
+ /**
233
+ * What a reader could not resolve cleanly. A finding is the difference between "the author never set
234
+ * this" and "the stored value is unusable": without it a malformed known value would be shown as its
235
+ * default, and the author would see a setting that reads `off` over a document that says something
236
+ * else entirely.
237
+ */
238
+ export type TemplateAuthoringFinding = {
239
+ kind: 'malformed-value'
240
+ /** Two recognized spellings of one field are both present and disagree. */
241
+ | 'alias-disagreement'
242
+ /** A recognized legacy spelling supplied the effective value; no canonical property exists yet. */
243
+ | 'legacy-alias-read'
244
+ /** A soft-id set, or one of its members, is not a law-valid primitive set. */
245
+ | 'malformed-collection'
246
+ /**
247
+ * An ancestor container on the way to this field is not a container, so the field cannot be
248
+ * read — and the typed operations refuse to write through it. Distinct from
249
+ * `malformed-value`, which is about the leaf itself: here the leaf was never reached.
250
+ */
251
+ | 'malformed-ancestor';
252
+ /** The canonical locus the finding is about. */
253
+ locus: string;
254
+ /** The exact document paths the evidence was read from. */
255
+ paths: readonly string[];
256
+ detail: string;
257
+ };
258
+ /**
259
+ * The hydrated metadata surface — total, because the stored document is minimal.
260
+ *
261
+ * **Never persisted.** This is the read-side hydration the architecture puts at the document
262
+ * boundary; writing it back would store every default and change `document_hash` for a document
263
+ * nobody edited. `settings` is flat, keyed by the same group-relative paths the operations use, so a
264
+ * UI renders the 23 controls by iterating `TEMPLATE_SETTING_FIELDS` and an app never re-spells the
265
+ * nesting.
266
+ */
267
+ export type ResolvedTemplateAuthoringMeta = {
268
+ title: string;
269
+ description: string;
270
+ visibility: TemplateVisibility;
271
+ instancePolicy: {
272
+ requiredAccessLevel: RequiredAccessLevel;
273
+ invitationRequired: boolean;
274
+ initiator: Initiator;
275
+ template_update_mode: TemplateUpdateMode;
276
+ };
277
+ settings: Record<SettingField, boolean>;
278
+ compatibility: Record<CompatibilityCollection, readonly string[]>;
279
+ /**
280
+ * Import-preserved residue, surfaced read-only and shaped exactly as stored. Optional rather
281
+ * than defaulted: `plan_category` has no asserted default, and inventing `{}` here would tempt a
282
+ * consumer to persist an empty container DOC-LAW-2 forbids.
283
+ */
284
+ legacy?: {
285
+ plan_category?: DocScalar;
286
+ flags?: Record<string, unknown>;
287
+ };
288
+ findings: readonly TemplateAuthoringFinding[];
289
+ };
290
+ /**
291
+ * The value a metadata field accepts, or `undefined` when the candidate is not one.
292
+ *
293
+ * The cast is the one place a union of precise readers has to be called through a dynamic field: each
294
+ * entry accepts `unknown` and returns its own field's value type, so widening the return to
295
+ * `MetaFieldValue` is sound — it is the union of exactly those types.
296
+ */
297
+ export declare const parseMetaFieldValue: (field: MetaField, value: unknown) => MetaFieldValue | undefined;
298
+ /**
299
+ * The canonical member form of one soft id.
300
+ *
301
+ * Two normalisations, each for a stated reason:
302
+ *
303
+ * - **A legacy numeric id becomes its lossless decimal string.** The sets are declared `string[]`, and
304
+ * legacy template ids are integers; `String(n)` round-trips every JS number that can be an id, so
305
+ * the port keeps the identity instead of dropping the association.
306
+ * - **NFC.** `canonicalJson` NFC-normalises strings, so two NFC-equivalent spellings of one id
307
+ * serialise to the same bytes. Deduplicating on the raw strings would therefore store two members
308
+ * that canonicalize to one, which is a duplicate inside a *set* and a second encoding of one state.
309
+ */
310
+ export declare const normalizeCompatibilityId: (value: unknown) => string | undefined;
311
+ /**
312
+ * The id a NEW typed membership operation may carry: a nonempty string, NFC-normalised. Never a number.
313
+ *
314
+ * Separate from {@link normalizeCompatibilityId} on purpose, and the separation is the point. Numeric
315
+ * tolerance exists for **stored legacy members** — ids the port inherited and must not drop. A new
316
+ * operation is authored today against a contract whose wire schema says `string > 0`, so accepting
317
+ * `id: 42` in the reducer would mean the schema and the replay path disagree about what the vocabulary
318
+ * is: an op refused at the boundary would still land when replayed from a log. One spelling for new
319
+ * producers, full tolerance for old data.
320
+ */
321
+ export declare const parseCompatibilityOperationId: (value: unknown) => string | undefined;
322
+ /**
323
+ * The canonical stored form of a touched soft-id set: sorted, unique, NFC.
324
+ *
325
+ * Sorted by UTF-16 code unit, which is the same comparison `canonicalJson` uses for object keys —
326
+ * one ordering rule in the contract rather than two. Sorting at all is what makes the set's identity
327
+ * independent of the order members were added in: two authors who add the same two ids in opposite
328
+ * orders must produce one document, not two hashes.
329
+ */
330
+ export declare const normalizeCompatibilityIds: (ids: readonly string[]) => string[];
331
+ /**
332
+ * The one total reader over the stored metadata — the single declaration of what this surface means.
333
+ *
334
+ * **Non-mutating, and that is load-bearing rather than hygiene.** The caller is usually holding the
335
+ * live document the reducer also holds, so a reader that filled in a default would change the hashed
336
+ * bytes of a document nobody edited — minting a version from a page load. Nothing here writes to
337
+ * `meta`, and the returned `compatibility` arrays are fresh.
338
+ *
339
+ * Accepts `undefined` so a brand-new family (no `meta` key at all, DOC-LAW-2) resolves to the same
340
+ * total object as a document that spelled every default out.
341
+ */
342
+ export declare const resolveTemplateAuthoringMeta: (meta: QnrTemplateMeta | undefined) => ResolvedTemplateAuthoringMeta;
343
+ /**
344
+ * Whether two loci name overlapping state.
345
+ *
346
+ * Both directions count, because the log a new submission is checked against contains ancestor writes:
347
+ * a released `template.updateMeta` patch on `instancePolicy` overlaps a typed write to
348
+ * `instancePolicy.initiator`, and a whole-set write to `compatibility.consentTemplateIds` overlaps
349
+ * every member of that set. Treating only equal strings as overlapping is exactly the missed check
350
+ * that lets a catch-up op silently overwrite another author's intent.
351
+ */
352
+ export declare const templateLociOverlap: (left: string, right: string) => boolean;
353
+ /**
354
+ * What one operation intends at one locus.
355
+ *
356
+ * `set` carries the canonical value the op lands — `null` meaning "the leaf/member is absent", which
357
+ * is how a restored default and an explicit unset both look in a minimal document. `opaque` means the
358
+ * op touches the locus but its effect is not determinable from the op alone: that is every released
359
+ * open-arm patch, whose outcome depends on the base document the reducer would apply it to. Shared
360
+ * deliberately reports `opaque` rather than guessing, because a guess here would be a silent
361
+ * convergence verdict on an overwrite.
362
+ */
363
+ export type TemplateAuthoringIntent = {
364
+ locus: string;
365
+ kind: 'set';
366
+ value: JsonValue | null;
367
+ } | {
368
+ locus: string;
369
+ kind: 'opaque';
370
+ };
371
+ /**
372
+ * Which canonical loci an operation touches, and what it intends there.
373
+ *
374
+ * The four typed arms report determinate intents. The two released open arms report `opaque` intents
375
+ * for every canonical locus their patch keys reach — by exact path, by ancestor, by descendant, and
376
+ * through the recognized alias table, because a patch that writes `settings.ask_for_phone_nr` is
377
+ * writing the phone requirement whatever it spells it. Every other operation touches no metadata and
378
+ * returns nothing, which is what makes "disjoint loci commute" true by construction for the rest of
379
+ * the vocabulary.
380
+ */
381
+ export declare const templateAuthoringIntentsOf: (op: TemplateOp) => readonly TemplateAuthoringIntent[];
382
+ /**
383
+ * Whether two operations' metadata intents commute, converge, or conflict.
384
+ *
385
+ * - **disjoint** — no overlapping locus. Different leaves of one group, and different ids of one
386
+ * collection, land here: both edits survive, which is the whole reason settings are leaf operations
387
+ * and soft-id sets are membership operations rather than object patches.
388
+ * - **convergent** — every overlapping locus carries the same determinate intended value on both
389
+ * sides. Add/add and remove/remove of one id are the canonical cases, as is two clients choosing
390
+ * the same value for one flag; the second write is content-idempotent and may be allowed through.
391
+ * - **conflict** — anything else: different values at one locus, add against remove of one id, or an
392
+ * overlap where either side is `opaque`. A scalar has no automatic "both" merge, so this is a
393
+ * refusal plus a durable marker, never a silent last-writer-wins.
394
+ */
395
+ export type TemplateAuthoringOverlap = {
396
+ status: 'disjoint';
397
+ } | {
398
+ status: 'convergent';
399
+ loci: readonly string[];
400
+ } | {
401
+ status: 'conflict';
402
+ loci: readonly string[];
403
+ };
404
+ export declare const classifyTemplateAuthoringOverlap: (left: TemplateOp, right: TemplateOp) => TemplateAuthoringOverlap;
405
+ /**
406
+ * The value a document currently holds at a locus, `null` when absent.
407
+ *
408
+ * Exists so the conflict record's base and current values come from one implementation rather than
409
+ * each caller's own traversal: a generic "read the structure" fallback is what produced markers whose
410
+ * base and left values were the same current value, which tells a resolver nothing. `null` for absent
411
+ * is deliberate and legal — conflict records are outside the template's DOC-LAW-2.
412
+ *
413
+ * A bracketed member locus answers membership: the id when the set contains it, `null` when not.
414
+ */
415
+ export declare const readTemplateAuthoringLocus: (document: Pick<QnrTemplateDocument, 'meta'>, locus: string) => JsonValue | null;
416
+ /**
417
+ * Where a template metadata conflict is recorded on the released marker shape.
418
+ *
419
+ * The document IS the entity for this surface — there is no per-field entity id — so the locus is the
420
+ * marker's `fieldPath` and the family document its `entityId`. Spelling that convention here keeps
421
+ * the real path in the record instead of a generic `_structure` placeholder.
422
+ */
423
+ export declare const templateAuthoringConflictTarget: (documentId: string, locus: string) => Pick<ConflictMarker, 'entityType' | 'entityId' | 'fieldPath'>;
424
+ //# sourceMappingURL=templateAuthoringMeta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templateAuthoringMeta.d.ts","sourceRoot":"","sources":["../../src/collaboration/templateAuthoringMeta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EACR,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EACrB,MAAM,uBAAuB,CAAA;AAG9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,sBAAsB,GAC5B;IA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