@azx-pbc/axiom-builder 0.0.0-stage → 0.0.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.
Files changed (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +648 -2
  3. package/dist/cards/selectors.d.ts +70 -0
  4. package/dist/cards/selectors.d.ts.map +1 -0
  5. package/dist/cards/selectors.js +194 -0
  6. package/dist/cards/selectors.js.map +1 -0
  7. package/dist/definition.d.ts +36 -0
  8. package/dist/definition.d.ts.map +1 -0
  9. package/dist/definition.js +48 -0
  10. package/dist/definition.js.map +1 -0
  11. package/dist/evidence/cases.d.ts +44 -0
  12. package/dist/evidence/cases.d.ts.map +1 -0
  13. package/dist/evidence/cases.js +578 -0
  14. package/dist/evidence/cases.js.map +1 -0
  15. package/dist/evidence/repairs.d.ts +99 -0
  16. package/dist/evidence/repairs.d.ts.map +1 -0
  17. package/dist/evidence/repairs.js +181 -0
  18. package/dist/evidence/repairs.js.map +1 -0
  19. package/dist/evidence/summary.d.ts +35 -0
  20. package/dist/evidence/summary.d.ts.map +1 -0
  21. package/dist/evidence/summary.js +38 -0
  22. package/dist/evidence/summary.js.map +1 -0
  23. package/dist/i18n/gaps.d.ts +3 -0
  24. package/dist/i18n/gaps.d.ts.map +1 -0
  25. package/dist/i18n/gaps.js +2 -0
  26. package/dist/i18n/gaps.js.map +1 -0
  27. package/dist/i18n/message-slots.d.ts +19 -0
  28. package/dist/i18n/message-slots.d.ts.map +1 -0
  29. package/dist/i18n/message-slots.js +101 -0
  30. package/dist/i18n/message-slots.js.map +1 -0
  31. package/dist/i18n/text-locale.d.ts +13 -0
  32. package/dist/i18n/text-locale.d.ts.map +1 -0
  33. package/dist/i18n/text-locale.js +14 -0
  34. package/dist/i18n/text-locale.js.map +1 -0
  35. package/dist/i18n/translations.d.ts +56 -0
  36. package/dist/i18n/translations.d.ts.map +1 -0
  37. package/dist/i18n/translations.js +103 -0
  38. package/dist/i18n/translations.js.map +1 -0
  39. package/dist/impact/references.d.ts +143 -0
  40. package/dist/impact/references.d.ts.map +1 -0
  41. package/dist/impact/references.js +429 -0
  42. package/dist/impact/references.js.map +1 -0
  43. package/dist/index.d.ts +86 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +58 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/preview/compile-preview.d.ts +67 -0
  48. package/dist/preview/compile-preview.d.ts.map +1 -0
  49. package/dist/preview/compile-preview.js +286 -0
  50. package/dist/preview/compile-preview.js.map +1 -0
  51. package/dist/preview/handle.d.ts +119 -0
  52. package/dist/preview/handle.d.ts.map +1 -0
  53. package/dist/preview/handle.js +2 -0
  54. package/dist/preview/handle.js.map +1 -0
  55. package/dist/preview/held.d.ts +39 -0
  56. package/dist/preview/held.d.ts.map +1 -0
  57. package/dist/preview/held.js +15 -0
  58. package/dist/preview/held.js.map +1 -0
  59. package/dist/preview/measurement.d.ts +5 -0
  60. package/dist/preview/measurement.d.ts.map +1 -0
  61. package/dist/preview/measurement.js +18 -0
  62. package/dist/preview/measurement.js.map +1 -0
  63. package/dist/publish/build.d.ts +33 -0
  64. package/dist/publish/build.d.ts.map +1 -0
  65. package/dist/publish/build.js +15 -0
  66. package/dist/publish/build.js.map +1 -0
  67. package/dist/publish/diff.d.ts +208 -0
  68. package/dist/publish/diff.d.ts.map +1 -0
  69. package/dist/publish/diff.js +227 -0
  70. package/dist/publish/diff.js.map +1 -0
  71. package/dist/publish/review.d.ts +41 -0
  72. package/dist/publish/review.d.ts.map +1 -0
  73. package/dist/publish/review.js +22 -0
  74. package/dist/publish/review.js.map +1 -0
  75. package/dist/schema/dataset-input.d.ts +30 -0
  76. package/dist/schema/dataset-input.d.ts.map +1 -0
  77. package/dist/schema/dataset-input.js +58 -0
  78. package/dist/schema/dataset-input.js.map +1 -0
  79. package/dist/schema/dataset.d.ts +166 -0
  80. package/dist/schema/dataset.d.ts.map +1 -0
  81. package/dist/schema/dataset.js +281 -0
  82. package/dist/schema/dataset.js.map +1 -0
  83. package/dist/schema/declarations.d.ts +15 -0
  84. package/dist/schema/declarations.d.ts.map +1 -0
  85. package/dist/schema/declarations.js +47 -0
  86. package/dist/schema/declarations.js.map +1 -0
  87. package/dist/schema/document.d.ts +504 -0
  88. package/dist/schema/document.d.ts.map +1 -0
  89. package/dist/schema/document.js +337 -0
  90. package/dist/schema/document.js.map +1 -0
  91. package/dist/schema/error.d.ts +15 -0
  92. package/dist/schema/error.d.ts.map +1 -0
  93. package/dist/schema/error.js +18 -0
  94. package/dist/schema/error.js.map +1 -0
  95. package/dist/schema/field-id.d.ts +8 -0
  96. package/dist/schema/field-id.d.ts.map +1 -0
  97. package/dist/schema/field-id.js +47 -0
  98. package/dist/schema/field-id.js.map +1 -0
  99. package/dist/schema/layout.d.ts +118 -0
  100. package/dist/schema/layout.d.ts.map +1 -0
  101. package/dist/schema/layout.js +101 -0
  102. package/dist/schema/layout.js.map +1 -0
  103. package/dist/schema/palette.d.ts +103 -0
  104. package/dist/schema/palette.d.ts.map +1 -0
  105. package/dist/schema/palette.js +140 -0
  106. package/dist/schema/palette.js.map +1 -0
  107. package/dist/schema/read.d.ts +49 -0
  108. package/dist/schema/read.d.ts.map +1 -0
  109. package/dist/schema/read.js +942 -0
  110. package/dist/schema/read.js.map +1 -0
  111. package/dist/store/apply-dataset.d.ts +14 -0
  112. package/dist/store/apply-dataset.d.ts.map +1 -0
  113. package/dist/store/apply-dataset.js +513 -0
  114. package/dist/store/apply-dataset.js.map +1 -0
  115. package/dist/store/apply.d.ts +37 -0
  116. package/dist/store/apply.d.ts.map +1 -0
  117. package/dist/store/apply.js +2269 -0
  118. package/dist/store/apply.js.map +1 -0
  119. package/dist/store/candidate.d.ts +37 -0
  120. package/dist/store/candidate.d.ts.map +1 -0
  121. package/dist/store/candidate.js +178 -0
  122. package/dist/store/candidate.js.map +1 -0
  123. package/dist/store/commands/coverage.d.ts +58 -0
  124. package/dist/store/commands/coverage.d.ts.map +1 -0
  125. package/dist/store/commands/coverage.js +354 -0
  126. package/dist/store/commands/coverage.js.map +1 -0
  127. package/dist/store/commands/dataset.d.ts +26 -0
  128. package/dist/store/commands/dataset.d.ts.map +1 -0
  129. package/dist/store/commands/dataset.js +368 -0
  130. package/dist/store/commands/dataset.js.map +1 -0
  131. package/dist/store/commands/document.d.ts +21 -0
  132. package/dist/store/commands/document.d.ts.map +1 -0
  133. package/dist/store/commands/document.js +160 -0
  134. package/dist/store/commands/document.js.map +1 -0
  135. package/dist/store/commands/field.d.ts +32 -0
  136. package/dist/store/commands/field.d.ts.map +1 -0
  137. package/dist/store/commands/field.js +572 -0
  138. package/dist/store/commands/field.js.map +1 -0
  139. package/dist/store/commands/layout.d.ts +16 -0
  140. package/dist/store/commands/layout.d.ts.map +1 -0
  141. package/dist/store/commands/layout.js +70 -0
  142. package/dist/store/commands/layout.js.map +1 -0
  143. package/dist/store/commands/parse.d.ts +19 -0
  144. package/dist/store/commands/parse.d.ts.map +1 -0
  145. package/dist/store/commands/parse.js +328 -0
  146. package/dist/store/commands/parse.js.map +1 -0
  147. package/dist/store/commands/readers.d.ts +198 -0
  148. package/dist/store/commands/readers.d.ts.map +1 -0
  149. package/dist/store/commands/readers.js +711 -0
  150. package/dist/store/commands/readers.js.map +1 -0
  151. package/dist/store/commands/rule.d.ts +24 -0
  152. package/dist/store/commands/rule.d.ts.map +1 -0
  153. package/dist/store/commands/rule.js +379 -0
  154. package/dist/store/commands/rule.js.map +1 -0
  155. package/dist/store/commands/shapes.d.ts +900 -0
  156. package/dist/store/commands/shapes.d.ts.map +1 -0
  157. package/dist/store/commands/shapes.js +166 -0
  158. package/dist/store/commands/shapes.js.map +1 -0
  159. package/dist/store/commands/suggestions.d.ts +37 -0
  160. package/dist/store/commands/suggestions.d.ts.map +1 -0
  161. package/dist/store/commands/suggestions.js +177 -0
  162. package/dist/store/commands/suggestions.js.map +1 -0
  163. package/dist/store/commands.d.ts +16 -0
  164. package/dist/store/commands.d.ts.map +1 -0
  165. package/dist/store/commands.js +13 -0
  166. package/dist/store/commands.js.map +1 -0
  167. package/dist/store/dataset-candidate.d.ts +33 -0
  168. package/dist/store/dataset-candidate.d.ts.map +1 -0
  169. package/dist/store/dataset-candidate.js +31 -0
  170. package/dist/store/dataset-candidate.js.map +1 -0
  171. package/dist/store/dataset-pin.d.ts +93 -0
  172. package/dist/store/dataset-pin.d.ts.map +1 -0
  173. package/dist/store/dataset-pin.js +86 -0
  174. package/dist/store/dataset-pin.js.map +1 -0
  175. package/dist/store/dataset-store.d.ts +96 -0
  176. package/dist/store/dataset-store.d.ts.map +1 -0
  177. package/dist/store/dataset-store.js +112 -0
  178. package/dist/store/dataset-store.js.map +1 -0
  179. package/dist/store/history.d.ts +149 -0
  180. package/dist/store/history.d.ts.map +1 -0
  181. package/dist/store/history.js +173 -0
  182. package/dist/store/history.js.map +1 -0
  183. package/dist/store/measurement.d.ts +5 -0
  184. package/dist/store/measurement.d.ts.map +1 -0
  185. package/dist/store/measurement.js +20 -0
  186. package/dist/store/measurement.js.map +1 -0
  187. package/dist/store/notify.d.ts +11 -0
  188. package/dist/store/notify.d.ts.map +1 -0
  189. package/dist/store/notify.js +26 -0
  190. package/dist/store/notify.js.map +1 -0
  191. package/dist/store/published.d.ts +50 -0
  192. package/dist/store/published.d.ts.map +1 -0
  193. package/dist/store/published.js +27 -0
  194. package/dist/store/published.js.map +1 -0
  195. package/dist/store/refusals.d.ts +175 -0
  196. package/dist/store/refusals.d.ts.map +1 -0
  197. package/dist/store/refusals.js +160 -0
  198. package/dist/store/refusals.js.map +1 -0
  199. package/dist/store/steps.d.ts +14 -0
  200. package/dist/store/steps.d.ts.map +1 -0
  201. package/dist/store/steps.js +124 -0
  202. package/dist/store/steps.js.map +1 -0
  203. package/dist/store/store.d.ts +142 -0
  204. package/dist/store/store.d.ts.map +1 -0
  205. package/dist/store/store.js +136 -0
  206. package/dist/store/store.js.map +1 -0
  207. package/dist/store/unchanged.d.ts +12 -0
  208. package/dist/store/unchanged.d.ts.map +1 -0
  209. package/dist/store/unchanged.js +35 -0
  210. package/dist/store/unchanged.js.map +1 -0
  211. package/dist/visual/emit.d.ts +21 -0
  212. package/dist/visual/emit.d.ts.map +1 -0
  213. package/dist/visual/emit.js +133 -0
  214. package/dist/visual/emit.js.map +1 -0
  215. package/dist/visual/parse.d.ts +32 -0
  216. package/dist/visual/parse.d.ts.map +1 -0
  217. package/dist/visual/parse.js +330 -0
  218. package/dist/visual/parse.js.map +1 -0
  219. package/dist/visual/project.d.ts +40 -0
  220. package/dist/visual/project.d.ts.map +1 -0
  221. package/dist/visual/project.js +349 -0
  222. package/dist/visual/project.js.map +1 -0
  223. package/dist/visual/represent.d.ts +50 -0
  224. package/dist/visual/represent.d.ts.map +1 -0
  225. package/dist/visual/represent.js +66 -0
  226. package/dist/visual/represent.js.map +1 -0
  227. package/dist/visual/vocabulary.d.ts +121 -0
  228. package/dist/visual/vocabulary.d.ts.map +1 -0
  229. package/dist/visual/vocabulary.js +32 -0
  230. package/dist/visual/vocabulary.js.map +1 -0
  231. package/package.json +52 -3
@@ -0,0 +1,101 @@
1
+ import { readLayout } from '@azx-pbc/axiom-compiler';
2
+ import { isRecord } from '@azx-pbc/axiom-runtime';
3
+ import { authoredFields, fieldDeclarationMessageKeys, fieldMessageKey, optionMessageKey, } from '../schema/document.js';
4
+ /**
5
+ * The message keys a draft can render.
6
+ *
7
+ * A catalogue entry is only worth writing when something names it: the document title, a field's
8
+ * label, help or placeholder, an option's label or availability reason, an alternative's label, a
9
+ * rule's message, or a layout node's title, text, description or readout label. A text filed under a key nothing names is invisible to every renderer, and it
10
+ * is not harmless — the next declaration whose id or option code slugs to that key is refused as
11
+ * a duplicate, so a typo silently reserves the slot for a field the author has not written yet.
12
+ *
13
+ * The three walks below are the builder's answer to a question the compiler already answers for
14
+ * the opposite direction (`unresolvedMessageKeys` reports a key *used* but not declared). Reading
15
+ * the layout through the compiler's own `readLayout` keeps the node shape in one place; the
16
+ * member names a layout slot may use are pinned against the compiler's `MESSAGE_SLOTS` by a test.
17
+ */
18
+ /** Every string a document names as a message key through a member the slot table declares. */
19
+ function countKeys(value, counts) {
20
+ if (Array.isArray(value)) {
21
+ for (const entry of value)
22
+ countKeys(entry, counts);
23
+ return;
24
+ }
25
+ if (!isRecord(value))
26
+ return;
27
+ for (const [name, member] of Object.entries(value)) {
28
+ if (name === 'messageKey' && typeof member === 'string')
29
+ countKey(counts, member);
30
+ else
31
+ countKeys(member, counts);
32
+ }
33
+ }
34
+ function countKey(counts, key) {
35
+ counts.set(key, (counts.get(key) ?? 0) + 1);
36
+ }
37
+ /** The message keys one layout node and its children name. */
38
+ function countLayoutKeys(nodes, counts) {
39
+ for (const node of nodes) {
40
+ for (const key of [node.titleKey, node.descriptionKey, node.textKey]) {
41
+ if (key !== undefined)
42
+ countKey(counts, key);
43
+ }
44
+ for (const readout of node.readouts) {
45
+ if (readout.labelKey !== undefined)
46
+ countKey(counts, readout.labelKey);
47
+ }
48
+ countLayoutKeys(node.children, counts);
49
+ }
50
+ }
51
+ /**
52
+ * Every message key this draft names, with the number of declaring members that name it.
53
+ *
54
+ * The catalogue is not consulted: this is the answer to "does something render this key", and a
55
+ * caller that wants "can this key be written" adds the entries the catalogue already holds, so a
56
+ * document loaded from disk can still correct a text it carries. The count lets an edit tell a key
57
+ * that is a slot's own from one another member also names: two members naming one key are two
58
+ * renderings of one sentence, so neither may rewrite it on the other's behalf.
59
+ */
60
+ export function namedMessageKeyCounts(document) {
61
+ const counts = new Map();
62
+ if (document.titleKey !== undefined)
63
+ countKey(counts, document.titleKey);
64
+ for (const { field, trail } of authoredFields(document)) {
65
+ countKey(counts, fieldMessageKey(trail));
66
+ for (const key of [field.labelKey, field.descriptionKey, field.placeholderKey]) {
67
+ if (key !== undefined)
68
+ countKey(counts, key);
69
+ }
70
+ for (const key of fieldDeclarationMessageKeys(field))
71
+ countKey(counts, key);
72
+ for (const option of field.options ?? []) {
73
+ countKey(counts, option.labelKey);
74
+ countKey(counts, optionMessageKey(trail, option.code));
75
+ if (option.unavailableMessageKey !== undefined)
76
+ countKey(counts, option.unavailableMessageKey);
77
+ for (const suggestion of option.suggests ?? [])
78
+ countKey(counts, suggestion.labelKey);
79
+ }
80
+ }
81
+ // A rule's own messages sit under `messageKey`: its own, its gate items' and its screen
82
+ // reasons'. One walk over the rule list names those without restating the shapes. An
83
+ // alternative's label sits under `labelKey` like a field's, so it is named beside them.
84
+ for (const rule of document.rules ?? []) {
85
+ for (const suggestion of rule.suggests ?? [])
86
+ countKey(counts, suggestion.labelKey);
87
+ }
88
+ countKeys(document.rules ?? [], counts);
89
+ countLayoutKeys(readLayout(document), counts);
90
+ return counts;
91
+ }
92
+ /**
93
+ * Every message key this draft names, from its declarations, its rules and its layout.
94
+ *
95
+ * The set is the count map's keys: a member that names a key makes it renderable, however many
96
+ * members name it.
97
+ */
98
+ export function namedMessageKeys(document) {
99
+ return new Set(namedMessageKeyCounts(document).keys());
100
+ }
101
+ //# sourceMappingURL=message-slots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message-slots.js","sourceRoot":"","sources":["../../src/i18n/message-slots.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EACL,cAAc,EACd,2BAA2B,EAC3B,eAAe,EACf,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;GAaG;AAEH,+FAA+F;AAC/F,SAAS,SAAS,CAAC,KAAc,EAAE,MAA2B;IAC5D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,KAAK;YAAE,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACpD,OAAO;IACT,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO;IAC7B,KAAK,MAAM,CAAC,IA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IACD,SAAS,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC;IACxC,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAA2B;IAC1D,OAAO,IAAI,GAAG,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import { readLayout } from '@azx-pbc/axiom-compiler';\nimport { isRecord } from '@azx-pbc/axiom-runtime';\nimport type { AuthoringDocument } from '../schema/document.js';\nimport {\n authoredFields,\n fieldDeclarationMessageKeys,\n fieldMessageKey,\n optionMessageKey,\n} from '../schema/document.js';\n\n/**\n * The message keys a draft can render.\n *\n * A catalogue entry is only worth writing when something names it: the document title, a field's\n * label, help or placeholder, an option's label or availability reason, an alternative's label, a\n * rule's message, or a layout node's title, text, description or readout label. A text filed under a key nothing names is invisible to every renderer, and it\n * is not harmless — the next declaration whose id or option code slugs to that key is refused as\n * a duplicate, so a typo silently reserves the slot for a field the author has not written yet.\n *\n * The three walks below are the builder's answer to a question the compiler already answers for\n * the opposite direction (`unresolvedMessageKeys` reports a key *used* but not declared). Reading\n * the layout through the compiler's own `readLayout` keeps the node shape in one place; the\n * member names a layout slot may use are pinned against the compiler's `MESSAGE_SLOTS` by a test.\n */\n\n/** Every string a document names as a message key through a member the slot table declares. */\nfunction countKeys(value: unknown, counts: Map<string, number>): void {\n if (Array.isArray(value)) {\n for (const entry of value) countKeys(entry, counts);\n return;\n }\n if (!isRecord(value)) return;\n for (const [name, member] of Object.entries(value)) {\n if (name === 'messageKey' && typeof member === 'string') countKey(counts, member);\n else countKeys(member, counts);\n }\n}\n\nfunction countKey(counts: Map<string, number>, key: string): void {\n counts.set(key, (counts.get(key) ?? 0) + 1);\n}\n\n/** The message keys one layout node and its children name. */\nfunction countLayoutKeys(nodes: ReturnType<typeof readLayout>, counts: Map<string, number>): void {\n for (const node of nodes) {\n for (const key of [node.titleKey, node.descriptionKey, node.textKey]) {\n if (key !== undefined) countKey(counts, key);\n }\n for (const readout of node.readouts) {\n if (readout.labelKey !== undefined) countKey(counts, readout.labelKey);\n }\n countLayoutKeys(node.children, counts);\n }\n}\n\n/**\n * Every message key this draft names, with the number of declaring members that name it.\n *\n * The catalogue is not consulted: this is the answer to \"does something render this key\", and a\n * caller that wants \"can this key be written\" adds the entries the catalogue already holds, so a\n * document loaded from disk can still correct a text it carries. The count lets an edit tell a key\n * that is a slot's own from one another member also names: two members naming one key are two\n * renderings of one sentence, so neither may rewrite it on the other's behalf.\n */\nexport function namedMessageKeyCounts(document: AuthoringDocument): ReadonlyMap<string, number> {\n const counts = new Map<string, number>();\n if (document.titleKey !== undefined) countKey(counts, document.titleKey);\n for (const { field, trail } of authoredFields(document)) {\n countKey(counts, fieldMessageKey(trail));\n for (const key of [field.labelKey, field.descriptionKey, field.placeholderKey]) {\n if (key !== undefined) countKey(counts, key);\n }\n for (const key of fieldDeclarationMessageKeys(field)) countKey(counts, key);\n for (const option of field.options ?? []) {\n countKey(counts, option.labelKey);\n countKey(counts, optionMessageKey(trail, option.code));\n if (option.unavailableMessageKey !== undefined)\n countKey(counts, option.unavailableMessageKey);\n for (const suggestion of option.suggests ?? []) countKey(counts, suggestion.labelKey);\n }\n }\n // A rule's own messages sit under `messageKey`: its own, its gate items' and its screen\n // reasons'. One walk over the rule list names those without restating the shapes. An\n // alternative's label sits under `labelKey` like a field's, so it is named beside them.\n for (const rule of document.rules ?? []) {\n for (const suggestion of rule.suggests ?? []) countKey(counts, suggestion.labelKey);\n }\n countKeys(document.rules ?? [], counts);\n countLayoutKeys(readLayout(document), counts);\n return counts;\n}\n\n/**\n * Every message key this draft names, from its declarations, its rules and its layout.\n *\n * The set is the count map's keys: a member that names a key makes it renderable, however many\n * members name it.\n */\nexport function namedMessageKeys(document: AuthoringDocument): ReadonlySet<string> {\n return new Set(namedMessageKeyCounts(document).keys());\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { AuthoringDocument } from '../schema/document.js';
2
+ /**
3
+ * The locale a literal the store writes is filed under.
4
+ *
5
+ * An author's text is written in one locale — the document's default, or the first declared one
6
+ * when a document names only a set. Starting a document refuses a default that is not canonical,
7
+ * a `setMessageText` writes the locale it was given, and a minted label has to pick one, so the
8
+ * choice is stated once here: minting, the translator's export and the preview's locale fallback
9
+ * all read the same answer, and a document that states neither has no answer at all rather than a
10
+ * silently invented one.
11
+ */
12
+ export declare function documentTextLocale(document: AuthoringDocument): string | undefined;
13
+ //# sourceMappingURL=text-locale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-locale.d.ts","sourceRoot":"","sources":["../../src/i18n/text-locale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAElF"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The locale a literal the store writes is filed under.
3
+ *
4
+ * An author's text is written in one locale — the document's default, or the first declared one
5
+ * when a document names only a set. Starting a document refuses a default that is not canonical,
6
+ * a `setMessageText` writes the locale it was given, and a minted label has to pick one, so the
7
+ * choice is stated once here: minting, the translator's export and the preview's locale fallback
8
+ * all read the same answer, and a document that states neither has no answer at all rather than a
9
+ * silently invented one.
10
+ */
11
+ export function documentTextLocale(document) {
12
+ return document.defaultLocale ?? document.locales?.[0];
13
+ }
14
+ //# sourceMappingURL=text-locale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-locale.js","sourceRoot":"","sources":["../../src/i18n/text-locale.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAA2B;IAC5D,OAAO,QAAQ,CAAC,aAAa,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;AACzD,CAAC","sourcesContent":["import type { AuthoringDocument } from '../schema/document.js';\n\n/**\n * The locale a literal the store writes is filed under.\n *\n * An author's text is written in one locale — the document's default, or the first declared one\n * when a document names only a set. Starting a document refuses a default that is not canonical,\n * a `setMessageText` writes the locale it was given, and a minted label has to pick one, so the\n * choice is stated once here: minting, the translator's export and the preview's locale fallback\n * all read the same answer, and a document that states neither has no answer at all rather than a\n * silently invented one.\n */\nexport function documentTextLocale(document: AuthoringDocument): string | undefined {\n return document.defaultLocale ?? document.locales?.[0];\n}\n"]}
@@ -0,0 +1,56 @@
1
+ import type { AuthoringDocument } from '../schema/document.js';
2
+ import type { AuthoringRefusal } from '../store/refusals.js';
3
+ /**
4
+ * Committing translations, and handing a translator the work that is outstanding.
5
+ *
6
+ * A catalogue entry states a text per locale and the document declares the set it must be
7
+ * complete in. The store writes only the locale it was given, so a missing translation stays
8
+ * genuinely absent in the document — never an English copy filed under a Spanish key. A preview
9
+ * is what shows an author the form before the text is translated; a compile is what refuses to
10
+ * publish it.
11
+ */
12
+ /** One text a translator supplies: the entry, the locale, and the text itself. */
13
+ export interface TranslationEntry {
14
+ readonly messageKey: string;
15
+ readonly locale: string;
16
+ readonly text: string;
17
+ }
18
+ /** One piece of outstanding translation work, with the text a translator starts from. */
19
+ export interface MissingTranslation {
20
+ readonly messageKey: string;
21
+ /** The declared locale the entry has no text in. */
22
+ readonly locale: string;
23
+ /** The text the catalogue already states in its default locale. */
24
+ readonly sourceText: string;
25
+ /** The locale `sourceText` is written in. */
26
+ readonly sourceLocale: string;
27
+ }
28
+ /**
29
+ * The outstanding translation work, one row per missing `(messageKey, locale)`.
30
+ *
31
+ * The list is derived from `translationGaps`, which is the compiler's own completeness walk, so
32
+ * what a translator is asked for and what a compile refuses are the same set.
33
+ */
34
+ export declare function exportMissingTranslations(document: AuthoringDocument): readonly MissingTranslation[];
35
+ /** The document after committing translations, or the reason the batch was refused. */
36
+ export type TranslationImport = {
37
+ readonly ok: true;
38
+ readonly document: AuthoringDocument;
39
+ } | {
40
+ readonly ok: false;
41
+ readonly refusal: AuthoringRefusal;
42
+ };
43
+ /**
44
+ * Commits a batch of translations as one document change.
45
+ *
46
+ * The texts are written exactly as supplied and nothing else moves: a translation is a text for
47
+ * an entry in one locale. An empty text is refused outright, because a catalogue entry states at
48
+ * least one character and an empty one would compile as untranslated. A locale the document's
49
+ * catalogue does not own is refused for the reason `setMessageText` states the same rule: a text
50
+ * filed under an undeclared tag renders nowhere, so writing it would leave the document with a
51
+ * `MESSAGE_LOCALE` defect the translator could not repair. Two texts for one `(messageKey,
52
+ * locale)` in one batch are refused as a duplicate, because the batch would otherwise keep one of
53
+ * them silently and the author could not tell which.
54
+ */
55
+ export declare function importTranslations(document: AuthoringDocument, translations: readonly TranslationEntry[]): TranslationImport;
56
+ //# sourceMappingURL=translations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translations.d.ts","sourceRoot":"","sources":["../../src/i18n/translations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAK7D;;;;;;;;GAQG;AAEH,kFAAkF;AAClF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,yFAAyF;AACzF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mEAAmE;IACnE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAoBD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,iBAAiB,GAC1B,SAAS,kBAAkB,EAAE,CAS/B;AAED,uFAAuF;AACvF,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;CAAE,GAC3D;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAE/D;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,iBAAiB,EAC3B,YAAY,EAAE,SAAS,gBAAgB,EAAE,GACxC,iBAAiB,CAgFnB"}
@@ -0,0 +1,103 @@
1
+ import { admitsLocale, isCanonicalLocale, undeclaredLocaleDetail } from '../schema/document.js';
2
+ import { authoringRefusal } from '../store/refusals.js';
3
+ import { translationGaps } from './gaps.js';
4
+ import { namedMessageKeys } from './message-slots.js';
5
+ import { documentTextLocale } from './text-locale.js';
6
+ /** The source text and the locale it is actually written in, with a deterministic fallback. */
7
+ function sourceOf(document, entry) {
8
+ const preferred = documentTextLocale(document);
9
+ const preferredText = preferred === undefined ? undefined : entry[preferred];
10
+ if (preferredText !== undefined && preferred !== undefined) {
11
+ return { sourceText: preferredText, sourceLocale: preferred };
12
+ }
13
+ const firstLocale = Object.keys(entry).sort()[0];
14
+ const firstText = firstLocale === undefined ? undefined : entry[firstLocale];
15
+ if (firstText !== undefined && firstLocale !== undefined) {
16
+ return { sourceText: firstText, sourceLocale: firstLocale };
17
+ }
18
+ return { sourceText: '', sourceLocale: preferred ?? '' };
19
+ }
20
+ /**
21
+ * The outstanding translation work, one row per missing `(messageKey, locale)`.
22
+ *
23
+ * The list is derived from `translationGaps`, which is the compiler's own completeness walk, so
24
+ * what a translator is asked for and what a compile refuses are the same set.
25
+ */
26
+ export function exportMissingTranslations(document) {
27
+ return translationGaps(document).map((gap) => {
28
+ const entry = document.messages[gap.messageKey] ?? {};
29
+ return {
30
+ messageKey: gap.messageKey,
31
+ locale: gap.locale,
32
+ ...sourceOf(document, entry),
33
+ };
34
+ });
35
+ }
36
+ /**
37
+ * Commits a batch of translations as one document change.
38
+ *
39
+ * The texts are written exactly as supplied and nothing else moves: a translation is a text for
40
+ * an entry in one locale. An empty text is refused outright, because a catalogue entry states at
41
+ * least one character and an empty one would compile as untranslated. A locale the document's
42
+ * catalogue does not own is refused for the reason `setMessageText` states the same rule: a text
43
+ * filed under an undeclared tag renders nowhere, so writing it would leave the document with a
44
+ * `MESSAGE_LOCALE` defect the translator could not repair. Two texts for one `(messageKey,
45
+ * locale)` in one batch are refused as a duplicate, because the batch would otherwise keep one of
46
+ * them silently and the author could not tell which.
47
+ */
48
+ export function importTranslations(document, translations) {
49
+ if (translations.length === 0) {
50
+ return {
51
+ ok: false,
52
+ refusal: authoringRefusal('MALFORMED_COMMAND', '$.messages', 'a translation import states at least one entry'),
53
+ };
54
+ }
55
+ const messages = new Map(Object.entries(document.messages));
56
+ const named = namedMessageKeys(document);
57
+ const written = new Set();
58
+ for (const translation of translations) {
59
+ const path = `$.messages[${JSON.stringify(translation.messageKey)}]`;
60
+ if (!isCanonicalLocale(translation.locale)) {
61
+ return {
62
+ ok: false,
63
+ refusal: authoringRefusal('MALFORMED_COMMAND', path, `\`${translation.locale}\` is not a canonical locale tag; write a language, an optional script and an optional region, in canonical spelling`),
64
+ };
65
+ }
66
+ if (translation.text.trim() === '') {
67
+ return {
68
+ ok: false,
69
+ refusal: authoringRefusal('MALFORMED_COMMAND', path, `the text for \`${translation.locale}\` is empty; a catalogue entry states at least one character`),
70
+ };
71
+ }
72
+ if (!admitsLocale(document, translation.locale)) {
73
+ return {
74
+ ok: false,
75
+ refusal: authoringRefusal('UNDECLARED_LOCALE', `${path}[${JSON.stringify(translation.locale)}]`, undeclaredLocaleDetail(document, translation.locale)),
76
+ };
77
+ }
78
+ if (!messages.has(translation.messageKey) && !named.has(translation.messageKey)) {
79
+ return {
80
+ ok: false,
81
+ refusal: authoringRefusal('UNKNOWN_MESSAGE', path, `message key \`${translation.messageKey}\` is named by no declaration, rule or layout node in this draft`),
82
+ };
83
+ }
84
+ const slot = `${translation.messageKey}\u0000${translation.locale}`;
85
+ if (written.has(slot)) {
86
+ return {
87
+ ok: false,
88
+ refusal: authoringRefusal('DUPLICATE_ID', path, `the batch states \`${translation.locale}\` for \`${translation.messageKey}\` twice; one entry states one text per locale`),
89
+ };
90
+ }
91
+ written.add(slot);
92
+ messages.set(translation.messageKey, {
93
+ ...(messages.get(translation.messageKey) ?? {}),
94
+ [translation.locale]: translation.text,
95
+ });
96
+ }
97
+ return {
98
+ ok: true,
99
+ // `Object.fromEntries` defines even `__proto__` as own data for the compiler to judge.
100
+ document: { ...document, messages: Object.fromEntries(messages) },
101
+ };
102
+ }
103
+ //# sourceMappingURL=translations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translations.js","sourceRoot":"","sources":["../../src/i18n/translations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AA8BtD,+FAA+F;AAC/F,SAAS,QAAQ,CACf,QAA2B,EAC3B,KAAuC;IAEvC,MAAM,SAAS,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAG,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7E,IAAI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,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,CAAC;YAChF,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,OAAO,EAAE,gBAAgB,CACvB,iBAAiB,EACjB,IAAI,EACJ,iBAAiB,WAAW,CAAC,UAAU,kEAAkE,CAC1G;aACF,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,GAAG,GAAG,WAAW,CAAC,UAAU,SAAS,WAAW,CAAC,MAAM,EAAE,CAAC;QACpE,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACtB,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,OAAO,EAAE,gBAAgB,CACvB,cAAc,EACd,IAAI,EACJ,sBAAsB,WAAW,CAAC,MAAM,YAAY,WAAW,CAAC,UAAU,gDAAgD,CAC3H;aACF,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,EAAE;YACnC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;YAC/C,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,IAAI;SACvC,CAAC,CAAC;IACL,CAAC;IACD,OAAO;QACL,EAAE,EAAE,IAAI;QACR,uFAAuF;QACvF,QAAQ,EAAE,EAAE,GAAG,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;KAClE,CAAC;AACJ,CAAC","sourcesContent":["import type { AuthoringDocument } from '../schema/document.js';\nimport { admitsLocale, isCanonicalLocale, undeclaredLocaleDetail } from '../schema/document.js';\nimport { authoringRefusal } from '../store/refusals.js';\nimport type { AuthoringRefusal } from '../store/refusals.js';\nimport { translationGaps } from './gaps.js';\nimport { namedMessageKeys } from './message-slots.js';\nimport { documentTextLocale } from './text-locale.js';\n\n/**\n * Committing translations, and handing a translator the work that is outstanding.\n *\n * A catalogue entry states a text per locale and the document declares the set it must be\n * complete in. The store writes only the locale it was given, so a missing translation stays\n * genuinely absent in the document — never an English copy filed under a Spanish key. A preview\n * is what shows an author the form before the text is translated; a compile is what refuses to\n * publish it.\n */\n\n/** One text a translator supplies: the entry, the locale, and the text itself. */\nexport interface TranslationEntry {\n readonly messageKey: string;\n readonly locale: string;\n readonly text: string;\n}\n\n/** One piece of outstanding translation work, with the text a translator starts from. */\nexport interface MissingTranslation {\n readonly messageKey: string;\n /** The declared locale the entry has no text in. */\n readonly locale: string;\n /** The text the catalogue already states in its default locale. */\n readonly sourceText: string;\n /** The locale `sourceText` is written in. */\n readonly sourceLocale: string;\n}\n\n/** The source text and the locale it is actually written in, with a deterministic fallback. */\nfunction sourceOf(\n document: AuthoringDocument,\n entry: Readonly<Record<string, string>>,\n): { readonly sourceText: string; readonly sourceLocale: string } {\n const preferred = documentTextLocale(document);\n const preferredText = preferred === undefined ? undefined : entry[preferred];\n if (preferredText !== undefined && preferred !== undefined) {\n return { sourceText: preferredText, sourceLocale: preferred };\n }\n const firstLocale = Object.keys(entry).sort()[0];\n const firstText = firstLocale === undefined ? undefined : entry[firstLocale];\n if (firstText !== undefined && firstLocale !== undefined) {\n return { sourceText: firstText, sourceLocale: firstLocale };\n }\n return { sourceText: '', sourceLocale: preferred ?? '' };\n}\n\n/**\n * The outstanding translation work, one row per missing `(messageKey, locale)`.\n *\n * The list is derived from `translationGaps`, which is the compiler's own completeness walk, so\n * what a translator is asked for and what a compile refuses are the same set.\n */\nexport function exportMissingTranslations(\n document: AuthoringDocument,\n): readonly MissingTranslation[] {\n return translationGaps(document).map((gap) => {\n const entry = document.messages[gap.messageKey] ?? {};\n return {\n messageKey: gap.messageKey,\n locale: gap.locale,\n ...sourceOf(document, entry),\n };\n });\n}\n\n/** The document after committing translations, or the reason the batch was refused. */\nexport type TranslationImport =\n | { readonly ok: true; readonly document: AuthoringDocument }\n | { readonly ok: false; readonly refusal: AuthoringRefusal };\n\n/**\n * Commits a batch of translations as one document change.\n *\n * The texts are written exactly as supplied and nothing else moves: a translation is a text for\n * an entry in one locale. An empty text is refused outright, because a catalogue entry states at\n * least one character and an empty one would compile as untranslated. A locale the document's\n * catalogue does not own is refused for the reason `setMessageText` states the same rule: a text\n * filed under an undeclared tag renders nowhere, so writing it would leave the document with a\n * `MESSAGE_LOCALE` defect the translator could not repair. Two texts for one `(messageKey,\n * locale)` in one batch are refused as a duplicate, because the batch would otherwise keep one of\n * them silently and the author could not tell which.\n */\nexport function importTranslations(\n document: AuthoringDocument,\n translations: readonly TranslationEntry[],\n): TranslationImport {\n if (translations.length === 0) {\n return {\n ok: false,\n refusal: authoringRefusal(\n 'MALFORMED_COMMAND',\n '$.messages',\n 'a translation import states at least one entry',\n ),\n };\n }\n const messages = new Map<string, Readonly<Record<string, string>>>(\n Object.entries(document.messages),\n );\n const named = namedMessageKeys(document);\n const written = new Set<string>();\n for (const translation of translations) {\n const path = `$.messages[${JSON.stringify(translation.messageKey)}]`;\n if (!isCanonicalLocale(translation.locale)) {\n return {\n ok: false,\n refusal: authoringRefusal(\n 'MALFORMED_COMMAND',\n path,\n `\\`${translation.locale}\\` is not a canonical locale tag; write a language, an optional script and an optional region, in canonical spelling`,\n ),\n };\n }\n if (translation.text.trim() === '') {\n return {\n ok: false,\n refusal: authoringRefusal(\n 'MALFORMED_COMMAND',\n path,\n `the text for \\`${translation.locale}\\` is empty; a catalogue entry states at least one character`,\n ),\n };\n }\n if (!admitsLocale(document, translation.locale)) {\n return {\n ok: false,\n refusal: authoringRefusal(\n 'UNDECLARED_LOCALE',\n `${path}[${JSON.stringify(translation.locale)}]`,\n undeclaredLocaleDetail(document, translation.locale),\n ),\n };\n }\n if (!messages.has(translation.messageKey) && !named.has(translation.messageKey)) {\n return {\n ok: false,\n refusal: authoringRefusal(\n 'UNKNOWN_MESSAGE',\n path,\n `message key \\`${translation.messageKey}\\` is named by no declaration, rule or layout node in this draft`,\n ),\n };\n }\n const slot = `${translation.messageKey}\\u0000${translation.locale}`;\n if (written.has(slot)) {\n return {\n ok: false,\n refusal: authoringRefusal(\n 'DUPLICATE_ID',\n path,\n `the batch states \\`${translation.locale}\\` for \\`${translation.messageKey}\\` twice; one entry states one text per locale`,\n ),\n };\n }\n written.add(slot);\n messages.set(translation.messageKey, {\n ...(messages.get(translation.messageKey) ?? {}),\n [translation.locale]: translation.text,\n });\n }\n return {\n ok: true,\n // `Object.fromEntries` defines even `__proto__` as own data for the compiler to judge.\n document: { ...document, messages: Object.fromEntries(messages) },\n };\n}\n"]}
@@ -0,0 +1,143 @@
1
+ import type { AuthoringDocument, AuthoringRule } from '../schema/document.js';
2
+ /**
3
+ * What a draft says about one field, read without compiling it.
4
+ *
5
+ * A builder must answer "what happens if I delete this field?" while the draft is still
6
+ * unfinished, so the answer cannot come from a compiled artifact. It comes from the same walk the
7
+ * compiler's own dependency report uses — the runtime's `collectReadRefs` over `parseExpr` trees —
8
+ * and from the document members that name a field without holding an expression.
9
+ *
10
+ * The report separates the halves because they answer different questions:
11
+ *
12
+ * - `dependencyReads` is expression reads, the half a compiled artifact also reports. Its
13
+ * rule-sourced entries are exactly what `ruleReads` reports for that rule in an artifact
14
+ * compiled from the same document, so "safe to delete" cannot disagree with the compiled
15
+ * dependency report; layout reads and an array's `rowsFrom` reads are reported only here, and
16
+ * `inspectDeps` carries neither layout reads nor `rowScoped`.
17
+ * - `references` is every non-expression slot that names the field: a rule target, a layout
18
+ * placement, a signature's bound coverage, an option source's key field, a test case's inputs
19
+ * and access references, and a natural row key's member.
20
+ * - `messageKeys` is the message keys the declaration itself names. They are cleanup candidates,
21
+ * not proof of disuse: another declaration or layout node may share a key. They are not
22
+ * references to the field, so they stay out of `references`.
23
+ * - `unparseable` is every expression slot the draft holds that the parser refused, and every slot
24
+ * that holds no text at all. Either could read any field, so while this list is non-empty no
25
+ * field is proven unreferenced: the caller repairs or reads the named slots before deleting.
26
+ *
27
+ * A rule that parses but names an undeclared field is *not* unparseable. The parser does not
28
+ * typecheck, so its path still reports as a read of that name — which is what a typo looks like
29
+ * from here, and is the useful answer while the author is still typing.
30
+ *
31
+ * Cost: one parse and one read walk per expression slot for the whole document, and one layout
32
+ * read, held against the document's identity until the document object changes. A call is a
33
+ * lookup plus a copy of one field's list, so reporting on every field of a large draft shares the
34
+ * one pass instead of walking the document once per field.
35
+ */
36
+ /**
37
+ * One expression slot a draft states: the text to read, or the reason it holds no Expr v1 source.
38
+ *
39
+ * A document a host loads is only as well typed as the file it came from, so a slot can hold
40
+ * `null`, a number or an object. A slot is still a slot — naming it unparseable is what keeps the
41
+ * report honest — but it never reaches the parser, which expects text.
42
+ */
43
+ export type ExpressionSlot = {
44
+ readonly source: 'rule' | 'layout' | 'field';
45
+ /** The rule's id, the layout node's document path, or the declaring field's id. */
46
+ readonly sourceId: string;
47
+ /** The slot's location in the draft, in the compiler's diagnostic path spelling. */
48
+ readonly path: string;
49
+ readonly sourceText: string;
50
+ } | {
51
+ readonly source: 'rule' | 'layout' | 'field';
52
+ readonly sourceId: string;
53
+ readonly path: string;
54
+ /** Why this slot holds no Expr v1 source text. */
55
+ readonly refusal: string;
56
+ };
57
+ /** One field read through an expression, with the slot that read it. */
58
+ export interface DependencyRead {
59
+ readonly source: 'rule' | 'layout' | 'field';
60
+ /** The rule's id, the layout node's document path, or the declaring field's id. */
61
+ readonly sourceId: string;
62
+ /** The expression slot that read the field. */
63
+ readonly path: string;
64
+ /** Whether the read happened through the rule's own item scope. */
65
+ readonly rowScoped: boolean;
66
+ }
67
+ /** The kinds of non-expression slot that can name a field. */
68
+ export type FieldReferenceKind =
69
+ /** A rule's `fieldId`: the field it targets, or the array an item rule addresses. */
70
+ 'rule_field'
71
+ /** One entry of a rule's `fieldIds`, the targets a multi-target rule decides. */
72
+ | 'rule_field_ids'
73
+ /** A rule's `targetFieldId`: the row member an item rule writes or constrains. */
74
+ | 'rule_target'
75
+ /** A `defaultCompute` rule's `overrideFieldId`: the companion field it stores overrides in. */
76
+ | 'rule_override'
77
+ /** A field one of a rule's alternatives writes, `RULES-6.1.1`. */
78
+ | 'rule_suggestion'
79
+ /** A field one of an option's alternatives writes, `RULES-7.1.4`. */
80
+ | 'option_suggestion'
81
+ /** A field a rule's embedded test case supplies, redacts, writes or grants access to. */
82
+ | 'rule_case'
83
+ /** A layout node that places the field, or lists it among a summary's fields. */
84
+ | 'layout_field'
85
+ /** One entry of a `signature_capture` field's `covers`. */
86
+ | 'signature_cover'
87
+ /** A `dependsOn` entry, or the source field, of another field's `optionSource`. */
88
+ | 'option_source'
89
+ /** The member a record array's natural `rowKey` names. */
90
+ | 'row_key';
91
+ /** One non-expression slot that names the field. */
92
+ export interface FieldReference {
93
+ readonly kind: FieldReferenceKind;
94
+ /** The slot's location in the draft, in the compiler's diagnostic path spelling. */
95
+ readonly path: string;
96
+ /** The rule the slot belongs to, for the slots that belong to one. */
97
+ readonly ruleId?: string;
98
+ /** The declaration the slot belongs to, for a slot owned by a field rather than a rule. */
99
+ readonly sourceFieldId?: string;
100
+ }
101
+ /** One expression slot the parser refused. */
102
+ export interface UnparseableExpression {
103
+ readonly source: 'rule' | 'layout' | 'field';
104
+ readonly sourceId: string;
105
+ readonly path: string;
106
+ /** The parser's own reason, kept verbatim so a host shows the author what it said. */
107
+ readonly detail: string;
108
+ }
109
+ /** Everything one draft says about one field. */
110
+ export interface FieldReferences {
111
+ readonly fieldId: string;
112
+ readonly dependencyReads: readonly DependencyRead[];
113
+ readonly references: readonly FieldReference[];
114
+ readonly messageKeys: readonly string[];
115
+ readonly unparseable: readonly UnparseableExpression[];
116
+ }
117
+ /**
118
+ * Every expression slot one rule states, in the order the artifact declares them.
119
+ *
120
+ * The slot list is the builder's reading of the authoring document, and it is pinned against the
121
+ * runtime's own `ruleExpressions` by a test: the two must enumerate the same trees for the same
122
+ * rule, so a slot the compiler reads cannot go unreported here. That is why `reasons` is read only
123
+ * for `kind: 'screen'`: the runtime folds another kind's reasons into no expression at all, and a
124
+ * malformed draft that states one reads nothing.
125
+ */
126
+ export declare function ruleExpressionSlots(rule: AuthoringRule, base: string): readonly ExpressionSlot[];
127
+ /**
128
+ * Every reference a draft holds to one field, and every expression slot it could not read.
129
+ *
130
+ * A field id may sit inside a container — a row member is named by `targetFieldId` in an item
131
+ * rule, by a layout leaf under the array, and by a signature's coverage — so the walk covers the
132
+ * whole declaration tree rather than the top level only.
133
+ *
134
+ * One pass answers every field. The document is immutable by contract and the store rebuilds the
135
+ * declarations a command touched, so the answer is held against the document's identity: the
136
+ * first question parses each slot once and the next five hundred read that answer, rather than
137
+ * parsing the document once per field. An in-place mutation would break the same immutability the
138
+ * history's structural sharing relies on, so it is outside this contract by construction.
139
+ */
140
+ export declare function referencesOf(document: AuthoringDocument, fieldId: string): FieldReferences;
141
+ /** The expression slots the impact walk has parsed since the process started. */
142
+ export declare function expressionSlotParses(): number;
143
+ //# sourceMappingURL=references.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"references.d.ts","sourceRoot":"","sources":["../../src/impact/references.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GACtB;IACE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC7C,mFAAmF;IACnF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oFAAoF;IACpF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,GACD;IACE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC7C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI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