asma-core-helpers 0.30.0 → 0.32.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 (42) hide show
  1. package/lib/collaboration/applyOperation.d.ts +33 -1
  2. package/lib/collaboration/applyOperation.d.ts.map +1 -1
  3. package/lib/collaboration/applyOperation.js +633 -9
  4. package/lib/collaboration/applyOperation.js.map +1 -1
  5. package/lib/collaboration/operations.d.ts +109 -2
  6. package/lib/collaboration/operations.d.ts.map +1 -1
  7. package/lib/collaboration/operations.js +7 -0
  8. package/lib/collaboration/operations.js.map +1 -1
  9. package/lib/collaboration/schemas.d.ts +163 -0
  10. package/lib/collaboration/schemas.d.ts.map +1 -1
  11. package/lib/collaboration/schemas.js +173 -3
  12. package/lib/collaboration/schemas.js.map +1 -1
  13. package/lib/collaboration/templateDocument.d.ts +176 -0
  14. package/lib/collaboration/templateDocument.d.ts.map +1 -1
  15. package/lib/collaboration/templateDocument.js +9 -0
  16. package/lib/collaboration/templateDocument.js.map +1 -1
  17. package/lib/collaboration/testHelpers/documentGenerator.js +78 -1
  18. package/lib/collaboration/testHelpers/documentGenerator.js.map +1 -1
  19. package/lib/collaboration/typeContracts.d.ts +53 -0
  20. package/lib/collaboration/typeContracts.d.ts.map +1 -0
  21. package/lib/collaboration/typeContracts.js +2 -0
  22. package/lib/collaboration/typeContracts.js.map +1 -0
  23. package/lib/validation/index.d.ts +1 -1
  24. package/lib/validation/index.d.ts.map +1 -1
  25. package/lib/validation/index.js +1 -1
  26. package/lib/validation/index.js.map +1 -1
  27. package/lib/validation/rules.d.ts +4 -0
  28. package/lib/validation/rules.d.ts.map +1 -1
  29. package/lib/validation/rules.js +18 -1
  30. package/lib/validation/rules.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/collaboration/applyOperation.ts +736 -9
  33. package/src/collaboration/operations.ts +97 -0
  34. package/src/collaboration/schemas.ts +191 -1
  35. package/src/collaboration/templateDocument.ts +167 -1
  36. package/src/collaboration/testHelpers/documentGenerator.ts +77 -1
  37. package/src/collaboration/typeContracts.ts +57 -0
  38. package/src/collaboration/typedAuthoring.test.ts +641 -0
  39. package/src/collaboration/typedAuthoringHardening.test.ts +408 -0
  40. package/src/validation/index.ts +15 -1
  41. package/src/validation/rules.test.ts +106 -1
  42. package/src/validation/rules.ts +25 -1
@@ -211,7 +211,7 @@ const nextOp = (random: () => number, pools: IdPools): TemplateOp => {
211
211
 
212
212
  /** Operations added by ASMA-7676, kept in a dedicated mix so every seeded run exercises them. */
213
213
  const nextAddedContractOp = (random: () => number, pools: IdPools): TemplateOp => {
214
- const choice = Math.floor(random() * 9)
214
+ const choice = Math.floor(random() * 16)
215
215
  const columnQuestionId = pickOrFallback(random, pools.columns, 'c-ghost')
216
216
  const ownerQuestionId = pools.columnOwnerById[columnQuestionId] ?? pickOrFallback(random, pools.grids, 'g-ghost')
217
217
  const questionId = idOrNew(random, pools.questions, NEW_QUESTION_ID)
@@ -264,6 +264,76 @@ const nextAddedContractOp = (random: () => number, pools: IdPools): TemplateOp =
264
264
  return { type: 'qnrRule.delete', ruleId: pickOrFallback(random, pools.qnrRules, 'qr-ghost') }
265
265
  case 7:
266
266
  return { type: 'question.move', questionId: columnQuestionId, toIndex: Math.floor(random() * 5) }
267
+ // ── ASMA-7683 additive ops. Generated alongside the released vocabulary so the property run
268
+ // exercises them against the same invariants (DOC-law, ownership, hash stability) rather than
269
+ // only in their own hand-written cases.
270
+ case 8:
271
+ return {
272
+ type: 'gridColumn.setFilter',
273
+ questionId: ownerQuestionId,
274
+ columnQuestionId,
275
+ include: maybe(random, 0.7),
276
+ ...(maybe(random, 0.5) ? { atIndex: Math.floor(random() * 3) } : {}),
277
+ }
278
+ case 9:
279
+ return {
280
+ type: 'gridColumn.setAction',
281
+ questionId: pickOrFallback(random, pools.grids, 'g-ghost'),
282
+ actionId: pickOrFallback(random, pools.actions, 'x-ghost'),
283
+ include: maybe(random, 0.7),
284
+ ...(maybe(random, 0.5) ? { atIndex: Math.floor(random() * 3) } : {}),
285
+ }
286
+ case 10:
287
+ return {
288
+ type: 'tab.setLayout',
289
+ tabId: pickOrFallback(random, pools.tabs, 't-ghost'),
290
+ questionId: pickOrFallback(random, pools.questions, 'q-ghost'),
291
+ placement: maybe(random, 0.25)
292
+ ? null
293
+ : { row: Math.floor(random() * 3), cell: Math.floor(random() * 4) },
294
+ }
295
+ case 11:
296
+ return {
297
+ type: 'mappingFilter.setTyped',
298
+ filterId: NEW_FILTER_ID(pools.filters.length),
299
+ nodeId: pickOrFallback(random, pools.nodes, 'n-ghost'),
300
+ fieldId: `fld-${Math.floor(random() * 4)}`,
301
+ operator: 'eq',
302
+ value: `v-${Math.floor(random() * 3)}`,
303
+ }
304
+ case 12:
305
+ return {
306
+ type: 'mappingFilter.setTyped',
307
+ filterId: pickOrFallback(random, pools.filters, NEW_FILTER_ID(pools.filters.length)),
308
+ nodeId: pickOrFallback(random, pools.nodes, 'n-ghost'),
309
+ fieldId: `fld-${Math.floor(random() * 4)}`,
310
+ operator: 'in',
311
+ values: [`v-${Math.floor(random() * 3)}`, Math.floor(random() * 9)],
312
+ }
313
+ case 13:
314
+ return {
315
+ type: 'mappingFilter.setTyped',
316
+ filterId: pickOrFallback(random, pools.filters, NEW_FILTER_ID(pools.filters.length)),
317
+ nodeId: pickOrFallback(random, pools.nodes, 'n-ghost'),
318
+ fieldId: `fld-${Math.floor(random() * 4)}`,
319
+ operator: 'range',
320
+ from: Math.floor(random() * 5),
321
+ ...(maybe(random, 0.5) ? { to: 5 + Math.floor(random() * 5) } : {}),
322
+ }
323
+ case 14:
324
+ return {
325
+ type: 'action.createTyped',
326
+ actionId: NEW_ACTION_ID(pools.actions.length),
327
+ kind: maybe(random, 0.5) ? 'topLevelAction' : 'gridAction',
328
+ ...(maybe(random, 0.6) ? { label: `Handling ${Math.floor(random() * 5)}` } : {}),
329
+ }
330
+ case 15:
331
+ return {
332
+ type: 'action.setMetadata',
333
+ actionId: pickOrFallback(random, pools.actions, 'x-ghost'),
334
+ questionId: columnQuestionId,
335
+ metadata: maybe(random, 0.3) ? null : maybe(random, 0.5) ? { all: true } : { from: 'a', to: 'b' },
336
+ }
267
337
  default:
268
338
  return {
269
339
  type: 'gridColumn.setLayout',
@@ -277,6 +347,12 @@ const nextAddedContractOp = (random: () => number, pools: IdPools): TemplateOp =
277
347
  const updatePools = (op: TemplateOp, ok: boolean, pools: IdPools): void => {
278
348
  if (!ok) return
279
349
  switch (op.type) {
350
+ case 'mappingFilter.setTyped':
351
+ if (!pools.filters.includes(op.filterId)) pools.filters.push(op.filterId)
352
+ return
353
+ case 'action.createTyped':
354
+ pools.actions.push(op.actionId)
355
+ return
280
356
  case 'question.create':
281
357
  pools.questions.push(op.questionId)
282
358
  if (op.questionType === 'QuestionGrid') pools.grids.push(op.questionId)
@@ -0,0 +1,57 @@
1
+ import type { TemplateOp } from './operations.js'
2
+ import type { ActionMetadata } from './templateDocument.js'
3
+
4
+ /**
5
+ * Compile-time assertions that the closed unions stay closed.
6
+ *
7
+ * **Why these live in `src` and not in a test.** `tsconfig.json` excludes every `.test.ts` file from
8
+ * `ts:check`, and the runtime (`node --import tsx --test`) strips types without checking them — so a
9
+ * `@ts-expect-error` inside a test file is never evaluated by anything. A probe that cannot fail is
10
+ * worse than no probe: it reads like a guarantee. These assertions are in a checked module instead, so
11
+ * reopening either union turns `pnpm ts:check` red.
12
+ *
13
+ * Type-only: this module emits no runtime code.
14
+ */
15
+
16
+ /** Fails to compile unless `T` is exactly `true`. */
17
+ type Assert<T extends true> = T
18
+
19
+ /** `true` when `Candidate` is NOT assignable to `Target` — the shape is refused by the union. */
20
+ type Refuses<Candidate, Target> = [Candidate] extends [Target] ? false : true
21
+
22
+ // ─── action.createTyped is discriminated on `kind` ───
23
+ // `actionType` is a gridAction concept. A single arm with an optional member type-checked the
24
+ // combination below and left the reducer as the only thing that noticed.
25
+ export type ActionCreateTypedRefusesTopLevelActionType = Assert<
26
+ Refuses<
27
+ { type: 'action.createTyped'; actionId: string; kind: 'topLevelAction'; label?: string; actionType: 'COPY' },
28
+ TemplateOp
29
+ >
30
+ >
31
+
32
+ /** The same member on the gridAction arm must still be accepted, or the assertion above proves nothing. */
33
+ export type ActionCreateTypedAcceptsGridActionType = Assert<
34
+ Refuses<{ type: 'action.createTyped'; actionId: string; kind: 'gridAction'; actionType: 'COPY' }, TemplateOp> extends true
35
+ ? false
36
+ : true
37
+ >
38
+
39
+ // ─── ActionMetadata arms are mutually exclusive ───
40
+ // `all: true` is the all-to-all marker; carrying a bound beside it is two answers to one question, and
41
+ // a bare `{}` is indistinguishable from absent once DOC-LAW-2 strips empties.
42
+ export type ActionMetadataRefusesAllWithFrom = Assert<Refuses<{ all: true; from: string }, ActionMetadata>>
43
+ export type ActionMetadataRefusesAllWithTo = Assert<Refuses<{ all: true; to: string }, ActionMetadata>>
44
+ export type ActionMetadataRefusesEmpty = Assert<Refuses<Record<string, never>, ActionMetadata>>
45
+
46
+ /** The four legal shapes stay legal. */
47
+ export type ActionMetadataAcceptsLegalShapes = Assert<
48
+ Refuses<{ all: true }, ActionMetadata> extends false
49
+ ? Refuses<{ from: string }, ActionMetadata> extends false
50
+ ? Refuses<{ to: string }, ActionMetadata> extends false
51
+ ? Refuses<{ from: string; to: string }, ActionMetadata> extends false
52
+ ? true
53
+ : false
54
+ : false
55
+ : false
56
+ : false
57
+ >