@azx-pbc/axiom-react 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 (191) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +604 -2
  3. package/dist/FormErrorBoundary.d.ts +37 -0
  4. package/dist/FormErrorBoundary.d.ts.map +1 -0
  5. package/dist/FormErrorBoundary.js +54 -0
  6. package/dist/FormErrorBoundary.js.map +1 -0
  7. package/dist/FormProvider.d.ts +197 -0
  8. package/dist/FormProvider.d.ts.map +1 -0
  9. package/dist/FormProvider.js +149 -0
  10. package/dist/FormProvider.js.map +1 -0
  11. package/dist/field-error.d.ts +154 -0
  12. package/dist/field-error.d.ts.map +1 -0
  13. package/dist/field-error.js +2 -0
  14. package/dist/field-error.js.map +1 -0
  15. package/dist/field-props.d.ts +362 -0
  16. package/dist/field-props.d.ts.map +1 -0
  17. package/dist/field-props.js +64 -0
  18. package/dist/field-props.js.map +1 -0
  19. package/dist/form-context.d.ts +31 -0
  20. package/dist/form-context.d.ts.map +1 -0
  21. package/dist/form-context.js +13 -0
  22. package/dist/form-context.js.map +1 -0
  23. package/dist/form-store.d.ts +784 -0
  24. package/dist/form-store.d.ts.map +1 -0
  25. package/dist/form-store.js +2179 -0
  26. package/dist/form-store.js.map +1 -0
  27. package/dist/hints.d.ts +60 -0
  28. package/dist/hints.d.ts.map +1 -0
  29. package/dist/hints.js +158 -0
  30. package/dist/hints.js.map +1 -0
  31. package/dist/index.d.ts +57 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +36 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/render/field-value.d.ts +92 -0
  36. package/dist/render/field-value.d.ts.map +1 -0
  37. package/dist/render/field-value.js +124 -0
  38. package/dist/render/field-value.js.map +1 -0
  39. package/dist/render/nodes.d.ts +303 -0
  40. package/dist/render/nodes.d.ts.map +1 -0
  41. package/dist/render/nodes.js +325 -0
  42. package/dist/render/nodes.js.map +1 -0
  43. package/dist/render/schema.d.ts +30 -0
  44. package/dist/render/schema.d.ts.map +1 -0
  45. package/dist/render/schema.js +40 -0
  46. package/dist/render/schema.js.map +1 -0
  47. package/dist/render/value-text.d.ts +59 -0
  48. package/dist/render/value-text.d.ts.map +1 -0
  49. package/dist/render/value-text.js +104 -0
  50. package/dist/render/value-text.js.map +1 -0
  51. package/dist/store/array-bindings.d.ts +110 -0
  52. package/dist/store/array-bindings.d.ts.map +1 -0
  53. package/dist/store/array-bindings.js +181 -0
  54. package/dist/store/array-bindings.js.map +1 -0
  55. package/dist/store/bindings.d.ts +12 -0
  56. package/dist/store/bindings.d.ts.map +1 -0
  57. package/dist/store/bindings.js +16 -0
  58. package/dist/store/bindings.js.map +1 -0
  59. package/dist/store/buffer-state.d.ts +42 -0
  60. package/dist/store/buffer-state.d.ts.map +1 -0
  61. package/dist/store/buffer-state.js +51 -0
  62. package/dist/store/buffer-state.js.map +1 -0
  63. package/dist/store/configure.d.ts +19 -0
  64. package/dist/store/configure.d.ts.map +1 -0
  65. package/dist/store/configure.js +28 -0
  66. package/dist/store/configure.js.map +1 -0
  67. package/dist/store/derive.d.ts +106 -0
  68. package/dist/store/derive.d.ts.map +1 -0
  69. package/dist/store/derive.js +417 -0
  70. package/dist/store/derive.js.map +1 -0
  71. package/dist/store/errors.d.ts +20 -0
  72. package/dist/store/errors.d.ts.map +1 -0
  73. package/dist/store/errors.js +101 -0
  74. package/dist/store/errors.js.map +1 -0
  75. package/dist/store/fields.d.ts +35 -0
  76. package/dist/store/fields.d.ts.map +1 -0
  77. package/dist/store/fields.js +81 -0
  78. package/dist/store/fields.js.map +1 -0
  79. package/dist/store/form-channel.d.ts +174 -0
  80. package/dist/store/form-channel.d.ts.map +1 -0
  81. package/dist/store/form-channel.js +411 -0
  82. package/dist/store/form-channel.js.map +1 -0
  83. package/dist/store/gates.d.ts +22 -0
  84. package/dist/store/gates.d.ts.map +1 -0
  85. package/dist/store/gates.js +44 -0
  86. package/dist/store/gates.js.map +1 -0
  87. package/dist/store/ids.d.ts +20 -0
  88. package/dist/store/ids.d.ts.map +1 -0
  89. package/dist/store/ids.js +28 -0
  90. package/dist/store/ids.js.map +1 -0
  91. package/dist/store/inputs.d.ts +114 -0
  92. package/dist/store/inputs.d.ts.map +1 -0
  93. package/dist/store/inputs.js +202 -0
  94. package/dist/store/inputs.js.map +1 -0
  95. package/dist/store/layout.d.ts +81 -0
  96. package/dist/store/layout.d.ts.map +1 -0
  97. package/dist/store/layout.js +285 -0
  98. package/dist/store/layout.js.map +1 -0
  99. package/dist/store/messages.d.ts +56 -0
  100. package/dist/store/messages.d.ts.map +1 -0
  101. package/dist/store/messages.js +157 -0
  102. package/dist/store/messages.js.map +1 -0
  103. package/dist/store/option-pages.d.ts +193 -0
  104. package/dist/store/option-pages.d.ts.map +1 -0
  105. package/dist/store/option-pages.js +598 -0
  106. package/dist/store/option-pages.js.map +1 -0
  107. package/dist/store/parse-print.d.ts +105 -0
  108. package/dist/store/parse-print.d.ts.map +1 -0
  109. package/dist/store/parse-print.js +415 -0
  110. package/dist/store/parse-print.js.map +1 -0
  111. package/dist/store/proposals.d.ts +114 -0
  112. package/dist/store/proposals.d.ts.map +1 -0
  113. package/dist/store/proposals.js +90 -0
  114. package/dist/store/proposals.js.map +1 -0
  115. package/dist/store/publish.d.ts +48 -0
  116. package/dist/store/publish.d.ts.map +1 -0
  117. package/dist/store/publish.js +96 -0
  118. package/dist/store/publish.js.map +1 -0
  119. package/dist/store/snapshots.d.ts +63 -0
  120. package/dist/store/snapshots.d.ts.map +1 -0
  121. package/dist/store/snapshots.js +154 -0
  122. package/dist/store/snapshots.js.map +1 -0
  123. package/dist/store/steps.d.ts +13 -0
  124. package/dist/store/steps.d.ts.map +1 -0
  125. package/dist/store/steps.js +31 -0
  126. package/dist/store/steps.js.map +1 -0
  127. package/dist/store/view.d.ts +124 -0
  128. package/dist/store/view.d.ts.map +1 -0
  129. package/dist/store/view.js +301 -0
  130. package/dist/store/view.js.map +1 -0
  131. package/dist/store/visibility.d.ts +68 -0
  132. package/dist/store/visibility.d.ts.map +1 -0
  133. package/dist/store/visibility.js +231 -0
  134. package/dist/store/visibility.js.map +1 -0
  135. package/dist/store/wizard-cursor.d.ts +43 -0
  136. package/dist/store/wizard-cursor.d.ts.map +1 -0
  137. package/dist/store/wizard-cursor.js +67 -0
  138. package/dist/store/wizard-cursor.js.map +1 -0
  139. package/dist/store/writes.d.ts +50 -0
  140. package/dist/store/writes.d.ts.map +1 -0
  141. package/dist/store/writes.js +91 -0
  142. package/dist/store/writes.js.map +1 -0
  143. package/dist/typed.d.ts +134 -0
  144. package/dist/typed.d.ts.map +1 -0
  145. package/dist/typed.js +74 -0
  146. package/dist/typed.js.map +1 -0
  147. package/dist/useAsyncOptions.d.ts +20 -0
  148. package/dist/useAsyncOptions.d.ts.map +1 -0
  149. package/dist/useAsyncOptions.js +70 -0
  150. package/dist/useAsyncOptions.js.map +1 -0
  151. package/dist/useBufferedInput.d.ts +69 -0
  152. package/dist/useBufferedInput.d.ts.map +1 -0
  153. package/dist/useBufferedInput.js +132 -0
  154. package/dist/useBufferedInput.js.map +1 -0
  155. package/dist/useField.d.ts +42 -0
  156. package/dist/useField.d.ts.map +1 -0
  157. package/dist/useField.js +63 -0
  158. package/dist/useField.js.map +1 -0
  159. package/dist/useFieldArray.d.ts +25 -0
  160. package/dist/useFieldArray.d.ts.map +1 -0
  161. package/dist/useFieldArray.js +18 -0
  162. package/dist/useFieldArray.js.map +1 -0
  163. package/dist/useForm.d.ts +20 -0
  164. package/dist/useForm.d.ts.map +1 -0
  165. package/dist/useForm.js +9 -0
  166. package/dist/useForm.js.map +1 -0
  167. package/dist/useFormState.d.ts +23 -0
  168. package/dist/useFormState.d.ts.map +1 -0
  169. package/dist/useFormState.js +11 -0
  170. package/dist/useFormState.js.map +1 -0
  171. package/dist/useGate.d.ts +15 -0
  172. package/dist/useGate.d.ts.map +1 -0
  173. package/dist/useGate.js +21 -0
  174. package/dist/useGate.js.map +1 -0
  175. package/dist/useLayout.d.ts +29 -0
  176. package/dist/useLayout.d.ts.map +1 -0
  177. package/dist/useLayout.js +59 -0
  178. package/dist/useLayout.js.map +1 -0
  179. package/dist/useMessage.d.ts +58 -0
  180. package/dist/useMessage.d.ts.map +1 -0
  181. package/dist/useMessage.js +62 -0
  182. package/dist/useMessage.js.map +1 -0
  183. package/dist/useWatch.d.ts +19 -0
  184. package/dist/useWatch.d.ts.map +1 -0
  185. package/dist/useWatch.js +17 -0
  186. package/dist/useWatch.js.map +1 -0
  187. package/dist/useWizard.d.ts +166 -0
  188. package/dist/useWizard.d.ts.map +1 -0
  189. package/dist/useWizard.js +554 -0
  190. package/dist/useWizard.js.map +1 -0
  191. package/package.json +62 -3
@@ -0,0 +1,285 @@
1
+ import { assertNever, evaluatePresentation, meetAccess, sameWireValue, } from '@azx-pbc/axiom-runtime';
2
+ import { bindingErrors } from './errors.js';
3
+ import { messageFormatter } from './messages.js';
4
+ const NO_READOUTS = Object.freeze([]);
5
+ /**
6
+ * The presentation channel's one pass over one session.
7
+ *
8
+ * Layout is chrome: its `visibleWhen`, callout parameters and readouts are evaluated apart from
9
+ * the report, so nothing here can reach a sealed decision. The store owns the cache and the
10
+ * hook owns nothing, which is why this is a named seam rather than a call inside a hook.
11
+ */
12
+ export function layoutOf(compiled, input, env) {
13
+ return evaluatePresentation(compiled, input, env);
14
+ }
15
+ /** The node one id names, or `undefined` when the artifact declares none. */
16
+ export function findLayoutNode(views, nodeId) {
17
+ for (const node of views) {
18
+ if (node.nodeId === nodeId)
19
+ return node;
20
+ const found = findLayoutNode(childrenOf(node), nodeId);
21
+ if (found !== undefined)
22
+ return found;
23
+ }
24
+ return undefined;
25
+ }
26
+ /** The section node one layout anchor names, or `undefined` when the layout declares none. */
27
+ export function findLayoutSection(views, sectionId) {
28
+ for (const node of views) {
29
+ if (node.kind === 'section' && node.sectionId === sectionId)
30
+ return node;
31
+ const found = findLayoutSection(childrenOf(node), sectionId);
32
+ if (found !== undefined)
33
+ return found;
34
+ }
35
+ return undefined;
36
+ }
37
+ /**
38
+ * The steps of the form's wizard, in authored order.
39
+ *
40
+ * A wizard is declared at most once and holds only steps, so an artifact that carries none
41
+ * answers an empty list rather than inventing a single-page flow.
42
+ */
43
+ export function wizardSteps(views) {
44
+ for (const node of views) {
45
+ if (node.kind === 'wizard')
46
+ return node.children;
47
+ }
48
+ return [];
49
+ }
50
+ /** The step one id names, wherever the wizard places it. */
51
+ export function findStepView(views, stepId) {
52
+ for (const node of views) {
53
+ if (node.kind === 'step' && node.stepId === stepId)
54
+ return node;
55
+ const found = findStepView(childrenOf(node), stepId);
56
+ if (found !== undefined)
57
+ return found;
58
+ }
59
+ return undefined;
60
+ }
61
+ /** The children a container node holds; a leaf holds none. */
62
+ function childrenOf(node) {
63
+ switch (node.kind) {
64
+ case 'section':
65
+ case 'group':
66
+ case 'step':
67
+ case 'wizard':
68
+ return node.children;
69
+ case 'field':
70
+ case 'heading':
71
+ case 'callout':
72
+ case 'divider':
73
+ case 'sop_block':
74
+ case 'summary_card':
75
+ return [];
76
+ default:
77
+ return assertNever(node);
78
+ }
79
+ }
80
+ /**
81
+ * One node's slice, with the error facts a collapsed container needs.
82
+ *
83
+ * A member of an array has no bindable field value, so its rows answer for it; a container
84
+ * answers for itself and for every row it holds. Only visible bindings count, because a
85
+ * failure the host may not show is not one an accordion badge can name.
86
+ */
87
+ export function layoutSliceOf(node, compiled, engine, form, facts, byId = fieldsByIdOf(form)) {
88
+ const fieldIds = fieldLeavesOf(node);
89
+ let access = 'read_write';
90
+ let errorCount = 0;
91
+ for (const fieldId of fieldIds) {
92
+ const field = byId.get(fieldId);
93
+ if (field === undefined)
94
+ continue;
95
+ access = meetAccess(access, field.access);
96
+ const fact = facts.get(fieldId);
97
+ if (fact !== undefined && fact.arrayContainerId === undefined && field.visible) {
98
+ const state = engine.getField(fieldId);
99
+ if (state.visible)
100
+ errorCount += blockingCount(state);
101
+ }
102
+ for (const row of field.rows ?? []) {
103
+ const state = engine.getField(fieldId, row.rowKey);
104
+ if (state.visible)
105
+ errorCount += blockingCount(state);
106
+ }
107
+ // An item member has no field-level value: its access is the member declaration's answer
108
+ // and every failure it raises lives on its own rows. Fold both, so a section holding an
109
+ // array reports the failures its member rows hide and the access a section badge shows.
110
+ if (fact !== undefined &&
111
+ fact.arrayContainerId === undefined &&
112
+ fact.field.primitive === 'array') {
113
+ for (const member of facts.values()) {
114
+ if (member.arrayContainerId !== fieldId)
115
+ continue;
116
+ const memberField = byId.get(member.field.fieldId);
117
+ if (memberField === undefined)
118
+ continue;
119
+ access = meetAccess(access, memberField.access);
120
+ for (const row of field.rows ?? []) {
121
+ const state = engine.getField(memberField.fieldId, row.rowKey);
122
+ if (state.visible)
123
+ errorCount += blockingCount(state);
124
+ }
125
+ }
126
+ }
127
+ // A single record has one value and no rows: fold each member's own binding, so a section
128
+ // badge counts the failures inside the group even though only the container was placed.
129
+ if (fact !== undefined &&
130
+ fact.arrayContainerId === undefined &&
131
+ fact.field.primitive === 'record') {
132
+ for (const member of fact.field.fields ?? []) {
133
+ const memberField = byId.get(member.fieldId);
134
+ if (memberField === undefined)
135
+ continue;
136
+ access = meetAccess(access, memberField.access);
137
+ if (!memberField.visible)
138
+ continue;
139
+ const state = engine.getField(member.fieldId);
140
+ if (state.visible)
141
+ errorCount += blockingCount(state);
142
+ }
143
+ }
144
+ }
145
+ const message = messageOf(node, compiled);
146
+ return Object.freeze({
147
+ nodeId: node.nodeId,
148
+ kind: node.kind,
149
+ visible: node.visible,
150
+ access,
151
+ text: message.text,
152
+ messageKey: message.key,
153
+ messageParams: message.params,
154
+ readouts: readoutsOf(node),
155
+ hasErrors: errorCount > 0,
156
+ errorCount,
157
+ });
158
+ }
159
+ /**
160
+ * Whether two layout passes state the same chrome.
161
+ *
162
+ * The comparison is over the published view, not a hash, so a record edit that moves no
163
+ * visibility, message or readout keeps the array identity a `useLayout` consumer already
164
+ * rendered. Properties are built in one order by one function, so text equality is enough.
165
+ */
166
+ export function sameLayoutViews(left, right) {
167
+ // A structural walk, not two serialisations: the comparison runs on every publish, and
168
+ // building two full JSON strings to decide "unchanged" allocated more than the pass it guards.
169
+ return sameViewValue(left, right);
170
+ }
171
+ /** Structural equality of two published view trees, with no string built. */
172
+ function sameViewValue(left, right) {
173
+ if (left === right)
174
+ return true;
175
+ if (Array.isArray(left) || Array.isArray(right)) {
176
+ if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length)
177
+ return false;
178
+ return left.every((value, index) => sameViewValue(value, right[index]));
179
+ }
180
+ if (typeof left !== 'object' || left === null)
181
+ return false;
182
+ if (typeof right !== 'object' || right === null)
183
+ return false;
184
+ const keys = Object.keys(left);
185
+ if (keys.length !== Object.keys(right).length)
186
+ return false;
187
+ for (const key of keys) {
188
+ if (!Object.hasOwn(right, key))
189
+ return false;
190
+ if (!sameViewValue(Reflect.get(left, key), Reflect.get(right, key)))
191
+ return false;
192
+ }
193
+ return true;
194
+ }
195
+ /** Whether two slices state the same facts, so an unrelated publish keeps the identity. */
196
+ export function sameLayoutSlice(left, right) {
197
+ return (left.nodeId === right.nodeId &&
198
+ left.kind === right.kind &&
199
+ left.visible === right.visible &&
200
+ left.access === right.access &&
201
+ left.text === right.text &&
202
+ left.messageKey === right.messageKey &&
203
+ sameMessageParams(left.messageParams, right.messageParams) &&
204
+ left.errorCount === right.errorCount &&
205
+ left.hasErrors === right.hasErrors &&
206
+ sameReadouts(left.readouts, right.readouts));
207
+ }
208
+ function sameMessageParams(left, right) {
209
+ if (left === undefined || right === undefined)
210
+ return left === right;
211
+ const keys = Object.keys(left);
212
+ return (keys.length === Object.keys(right).length &&
213
+ keys.every((key) => Object.hasOwn(right, key) && sameWireValue(left[key], right[key])));
214
+ }
215
+ function sameReadouts(left, right) {
216
+ return (left.length === right.length &&
217
+ left.every((readout, index) => {
218
+ const other = right[index];
219
+ return (other !== undefined &&
220
+ readout.labelKey === other.labelKey &&
221
+ sameWireValue(readout.value, other.value));
222
+ }));
223
+ }
224
+ /** The blocking failures one binding's derived state reports. */
225
+ function blockingCount(state) {
226
+ let count = 0;
227
+ for (const error of bindingErrors(state).errors) {
228
+ if (error.blocking)
229
+ count += 1;
230
+ }
231
+ return count;
232
+ }
233
+ /**
234
+ * The declaration list indexed by field, for the slices one publish reads.
235
+ *
236
+ * A section that places five hundred fields would otherwise scan the array once per leaf. The
237
+ * caller that reads several slices passes one index for the whole form; a lone read builds it
238
+ * here and pays one pass over the declarations, never one per leaf.
239
+ */
240
+ export function fieldsByIdOf(form) {
241
+ return new Map(form.fields.map((entry) => [entry.fieldId, entry]));
242
+ }
243
+ /** Every field leaf a node places, depth first. */
244
+ function fieldLeavesOf(node) {
245
+ if (node.kind === 'field')
246
+ return [node.fieldId];
247
+ const leaves = [];
248
+ for (const child of childrenOf(node))
249
+ leaves.push(...fieldLeavesOf(child));
250
+ return leaves;
251
+ }
252
+ /** The message a node states at the artifact's default locale; empty when it states none. */
253
+ function messageOf(node, compiled) {
254
+ const key = primaryKeyOf(node);
255
+ if (key === undefined)
256
+ return { key: undefined, params: undefined, text: '' };
257
+ const params = 'params' in node ? node.params : undefined;
258
+ const format = messageFormatter(compiled, undefined);
259
+ return { key, params, text: format(key, params ?? {}) };
260
+ }
261
+ /** The message key a node's own text is written under. */
262
+ function primaryKeyOf(node) {
263
+ switch (node.kind) {
264
+ case 'section':
265
+ case 'group':
266
+ case 'step':
267
+ case 'heading':
268
+ case 'summary_card':
269
+ return node.titleKey;
270
+ case 'callout':
271
+ case 'sop_block':
272
+ return node.textKey;
273
+ case 'field':
274
+ case 'divider':
275
+ case 'wizard':
276
+ return undefined;
277
+ default:
278
+ return assertNever(node);
279
+ }
280
+ }
281
+ /** A summary card's readouts, and none for every other node. */
282
+ function readoutsOf(node) {
283
+ return node.kind === 'summary_card' ? (node.readouts ?? NO_READOUTS) : NO_READOUTS;
284
+ }
285
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","sourceR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AK,SAAS,CAAC;QACf,KAAK,cAAc;YACjB,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,KAAK,SAAS,CAAC;QACf,KAAK,WAAW;YACd,OAAO,IAAI,CAAC,OAAO,CAAC;QACtB,KAAK,OAAO,CAAC;QACb,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,gEAAgE;AAChE,SAAS,UAAU,CAAC,IAAoB;IACtC,OAAO,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;AACrF,CAAC","sourcesContent":["import {\n assertNever,\n evaluatePresentation,\n meetAccess,\n sameWireValue,\n} from '@azx-pbc/axiom-runtime';\nimport type {\n CompiledSchema,\n Engine,\n EvaluationEnv,\n EvaluationInput,\n FieldAccess,\n FormFieldState,\n FormState,\n LayoutNodeView,\n LayoutReadoutView,\n LayoutStepView,\n WireValue,\n} from '@azx-pbc/axiom-runtime';\nimport type { FieldFacts } from './fields.js';\nimport { bindingErrors } from './errors.js';\nimport { messageFormatter } from './messages.js';\n\n/**\n * What a section, step or any other layout node states for a renderer.\n *\n * The chrome itself is the presentation channel's answer: visibility, the resolved title text\n * and the summary card's readouts. The error facts are the form channel's, folded for a\n * collapsed container so an accordion badge can state how many failures it hides; `access` is\n * the meet of the member fields' resolved answers, never a second overlay resolution.\n */\nexport interface LayoutSlice {\n readonly nodeId: string;\n readonly kind: LayoutNodeView['kind'];\n readonly visible: boolean;\n readonly access: FieldAccess;\n /**\n * The node's own text at the artifact's default locale.\n *\n * This is a convenience, not the only answer: a structured argument (money, a date, an\n * instant, a `timeslot`, a percentage) has no plain spelling, so it resolves to the message\n * key. A host rendering such a message, or another locale, reads `messageKey` and\n * `messageParams` through its own formatter, or passes that formatter to\n * `useLayoutNode`/`useSection`.\n */\n readonly text: string;\n /** The message key this node's own text is written under, when it states one. */\n readonly messageKey: string | undefined;\n /** The arguments `messageKey` interpolates, resolved from the presentation channel. */\n readonly messageParams: Readonly<Record<string, WireValue>> | undefined;\n readonly readouts: readonly LayoutReadoutView[];\n readonly hasErrors: boolean;\n readonly errorCount: number;\n}\n\nconst NO_READOUTS: readonly LayoutReadoutView[] = Object.freeze([]);\n\n/**\n * The presentation channel's one pass over one session.\n *\n * Layout is chrome: its `visibleWhen`, callout parameters and readouts are evaluated apart from\n * the report, so nothing here can reach a sealed decision. The store owns the cache and the\n * hook owns nothing, which is why this is a named seam rather than a call inside a hook.\n */\nexport function layoutOf(\n compiled: CompiledSchema,\n input: EvaluationInput,\n env: EvaluationEnv,\n): readonly LayoutNodeView[] {\n return evaluatePresentation(compiled, input, env);\n}\n\n/** The node one id names, or `undefined` when the artifact declares none. */\nexport function findLayoutNode(\n views: readonly LayoutNodeView[],\n nodeId: string,\n): LayoutNodeView | undefined {\n for (const node of views) {\n if (node.nodeId === nodeId) return node;\n const found = findLayoutNode(childrenOf(node), nodeId);\n if (found !== undefined) return found;\n }\n return undefined;\n}\n\n/** The section node one layout anchor names, or `undefined` when the layout declares none. */\nexport function findLayoutSection(\n views: readonly LayoutNodeView[],\n sectionId: string,\n): LayoutNodeView | undefined {\n for (const node of views) {\n if (node.kind === 'section' && node.sectionId === sectionId) return node;\n const found = findLayoutSection(childrenOf(node), sectionId);\n if (found !== undefined) return found;\n }\n return undefined;\n}\n\n/**\n * The steps of the form's wizard, in authored order.\n *\n * A wizard is declared at most once and holds only steps, so an artifact that carries none\n * answers an empty list rather than inventing a single-page flow.\n */\nexport function wizardSteps(views: readonly LayoutNodeView[]): readonly LayoutStepView[] {\n for (const node of views) {\n if (node.kind === 'wizard') return node.children;\n }\n return [];\n}\n\n/** The step one id names, wherever the wizard places it. */\nexport function findStepView(\n views: readonly LayoutNodeView[],\n stepId: string,\n): LayoutStepView | undefined {\n for (const node of views) {\n if (node.kind === 'step' && node.stepId === stepId) return node;\n const found = findStepView(childrenOf(node), stepId);\n if (found !== undefined) return found;\n }\n return undefined;\n}\n\n/** The children a container node holds; a leaf holds none. */\nfunction childrenOf(node: LayoutNodeView): readonly LayoutNodeView[] {\n switch (node.kind) {\n case 'section':\n case 'group':\n case 'step':\n case 'wizard':\n return node.children;\n case 'field':\n case 'heading':\n case 'callout':\n case 'divider':\n case 'sop_block':\n case 'summary_card':\n return [];\n default:\n return assertNever(node);\n }\n}\n\n/**\n * One node's slice, with the error facts a collapsed container needs.\n *\n * A member of an array has no bindable field value, so its rows answer for it; a container\n * answers for itself and for every row it holds. Only visible bindings count, because a\n * failure the host may not show is not one an accordion badge can name.\n */\nexport function layoutSliceOf(\n node: LayoutNodeView,\n compiled: CompiledSchema,\n engine: Engine,\n form: FormState,\n facts: ReadonlyMap<string, FieldFacts>,\n byId: ReadonlyMap<string, FormFieldState> = fieldsByIdOf(form),\n): LayoutSlice {\n const fieldIds = fieldLeavesOf(node);\n let access: FieldAccess = 'read_write';\n let errorCount = 0;\n for (const fieldId of fieldIds) {\n const field = byId.get(fieldId);\n if (field === undefined) continue;\n access = meetAccess(access, field.access);\n const fact = facts.get(fieldId);\n if (fact !== undefined && fact.arrayContainerId === undefined && field.visible) {\n const state = engine.getField(fieldId);\n if (state.visible) errorCount += blockingCount(state);\n }\n for (const row of field.rows ?? []) {\n const state = engine.getField(fieldId, row.rowKey);\n if (state.visible) errorCount += blockingCount(state);\n }\n // An item member has no field-level value: its access is the member declaration's answer\n // and every failure it raises lives on its own rows. Fold both, so a section holding an\n // array reports the failures its member rows hide and the access a section badge shows.\n if (\n fact !== undefined &&\n fact.arrayContainerId === undefined &&\n fact.field.primitive === 'array'\n ) {\n for (const member of facts.values()) {\n if (member.arrayContainerId !== fieldId) continue;\n const memberField = byId.get(member.field.fieldId);\n if (memberField === undefined) continue;\n access = meetAccess(access, memberField.access);\n for (const row of field.rows ?? []) {\n const state = engine.getField(memberField.fieldId, row.rowKey);\n if (state.visible) errorCount += blockingCount(state);\n }\n }\n }\n // A single record has one value and no rows: fold each member's own binding, so a section\n // badge counts the failures inside the group even though only the container was placed.\n if (\n fact !== undefined &&\n fact.arrayContainerId === undefined &&\n fact.field.primitive === 'record'\n ) {\n for (const member of fact.field.fields ?? []) {\n const memberField = byId.get(member.fieldId);\n if (memberField === undefined) continue;\n access = meetAccess(access, memberField.access);\n if (!memberField.visible) continue;\n const state = engine.getField(member.fieldId);\n if (state.visible) errorCount += blockingCount(state);\n }\n }\n }\n const message = messageOf(node, compiled);\n return Object.freeze({\n nodeId: node.nodeId,\n kind: node.kind,\n visible: node.visible,\n access,\n text: message.text,\n messageKey: message.key,\n messageParams: message.params,\n readouts: readoutsOf(node),\n hasErrors: errorCount > 0,\n errorCount,\n });\n}\n\n/**\n * Whether two layout passes state the same chrome.\n *\n * The comparison is over the published view, not a hash, so a record edit that moves no\n * visibility, message or readout keeps the array identity a `useLayout` consumer already\n * rendered. Properties are built in one order by one function, so text equality is enough.\n */\nexport function sameLayoutViews(\n left: readonly LayoutNodeView[],\n right: readonly LayoutNodeView[],\n): boolean {\n // A structural walk, not two serialisations: the comparison runs on every publish, and\n // building two full JSON strings to decide \"unchanged\" allocated more than the pass it guards.\n return sameViewValue(left, right);\n}\n\n/** Structural equality of two published view trees, with no string built. */\nfunction sameViewValue(left: unknown, right: unknown): boolean {\n if (left === right) return true;\n if (Array.isArray(left) || Array.isArray(right)) {\n if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false;\n return left.every((value, index) => sameViewValue(value, right[index]));\n }\n if (typeof left !== 'object' || left === null) return false;\n if (typeof right !== 'object' || right === null) return false;\n const keys = Object.keys(left);\n if (keys.length !== Object.keys(right).length) return false;\n for (const key of keys) {\n if (!Object.hasOwn(right, key)) return false;\n if (!sameViewValue(Reflect.get(left, key), Reflect.get(right, key))) return false;\n }\n return true;\n}\n\n/** Whether two slices state the same facts, so an unrelated publish keeps the identity. */\nexport function sameLayoutSlice(left: LayoutSlice, right: LayoutSlice): boolean {\n return (\n left.nodeId === right.nodeId &&\n left.kind === right.kind &&\n left.visible === right.visible &&\n left.access === right.access &&\n left.text === right.text &&\n left.messageKey === right.messageKey &&\n sameMessageParams(left.messageParams, right.messageParams) &&\n left.errorCount === right.errorCount &&\n left.hasErrors === right.hasErrors &&\n sameReadouts(left.readouts, right.readouts)\n );\n}\n\nfunction sameMessageParams(\n left: Readonly<Record<string, WireValue>> | undefined,\n right: Readonly<Record<string, WireValue>> | undefined,\n): boolean {\n if (left === undefined || right === undefined) return left === right;\n const keys = Object.keys(left);\n return (\n keys.length === Object.keys(right).length &&\n keys.every((key) => Object.hasOwn(right, key) && sameWireValue(left[key], right[key]))\n );\n}\n\nfunction sameReadouts(\n left: readonly LayoutReadoutView[],\n right: readonly LayoutReadoutView[],\n): boolean {\n return (\n left.length === right.length &&\n left.every((readout, index) => {\n const other = right[index];\n return (\n other !== undefined &&\n readout.labelKey === other.labelKey &&\n sameWireValue(readout.value, other.value)\n );\n })\n );\n}\n\n/** The blocking failures one binding's derived state reports. */\nfunction blockingCount(state: ReturnType<Engine['getField']>): number {\n let count = 0;\n for (const error of bindingErrors(state).errors) {\n if (error.blocking) count += 1;\n }\n return count;\n}\n\n/**\n * The declaration list indexed by field, for the slices one publish reads.\n *\n * A section that places five hundred fields would otherwise scan the array once per leaf. The\n * caller that reads several slices passes one index for the whole form; a lone read builds it\n * here and pays one pass over the declarations, never one per leaf.\n */\nexport function fieldsByIdOf(form: FormState): ReadonlyMap<string, FormFieldState> {\n return new Map(form.fields.map((entry) => [entry.fieldId, entry] as const));\n}\n\n/** Every field leaf a node places, depth first. */\nfunction fieldLeavesOf(node: LayoutNodeView): readonly string[] {\n if (node.kind === 'field') return [node.fieldId];\n const leaves: string[] = [];\n for (const child of childrenOf(node)) leaves.push(...fieldLeavesOf(child));\n return leaves;\n}\n\n/** The message a node states at the artifact's default locale, and what a host needs to restate it. */\ninterface NodeMessage {\n readonly key: string | undefined;\n readonly params: Readonly<Record<string, WireValue>> | undefined;\n readonly text: string;\n}\n\n/** The message a node states at the artifact's default locale; empty when it states none. */\nfunction messageOf(node: LayoutNodeView, compiled: CompiledSchema): NodeMessage {\n const key = primaryKeyOf(node);\n if (key === undefined) return { key: undefined, params: undefined, text: '' };\n const params = 'params' in node ? node.params : undefined;\n const format = messageFormatter(compiled, undefined);\n return { key, params, text: format(key, params ?? {}) };\n}\n\n/** The message key a node's own text is written under. */\nfunction primaryKeyOf(node: LayoutNodeView): string | undefined {\n switch (node.kind) {\n case 'section':\n case 'group':\n case 'step':\n case 'heading':\n case 'summary_card':\n return node.titleKey;\n case 'callout':\n case 'sop_block':\n return node.textKey;\n case 'field':\n case 'divider':\n case 'wizard':\n return undefined;\n default:\n return assertNever(node);\n }\n}\n\n/** A summary card's readouts, and none for every other node. */\nfunction readoutsOf(node: LayoutNodeView): readonly LayoutReadoutView[] {\n return node.kind === 'summary_card' ? (node.readouts ?? NO_READOUTS) : NO_READOUTS;\n}\n"]}
@@ -0,0 +1,56 @@
1
+ import type { MessageParam } from '@azx-pbc/axiom-runtime/messages';
2
+ import type { CompiledSchema, WireValue } from '@azx-pbc/axiom-runtime';
3
+ /**
4
+ * What a message argument means, so a value the wire cannot format by itself is still shown.
5
+ *
6
+ * A message AST carries argument names and nothing else, so a `"2026-01-31"` and a `"café"` are
7
+ * one `string`. The host says which is which — and only the host can, because rendering a date,
8
+ * an instant, a money amount or a percentage for display is the host's job and never the
9
+ * runtime's (`[MODEL-6.1.3]`).
10
+ */
11
+ export type MessageValueKind = 'text' | 'integer' | 'decimal' | 'boolean' | 'null' | 'array' | 'record' | 'money' | 'date' | 'instant' | 'timeslot' | 'percentage';
12
+ /** One argument with the meaning the wire shape alone cannot state. */
13
+ export interface DeclaredMessageValue {
14
+ readonly value: WireValue;
15
+ readonly descriptor: MessageValueKind;
16
+ }
17
+ /**
18
+ * One message argument: a canonical wire value, or a value with the meaning it carries.
19
+ *
20
+ * A bare wire value is read by its shape, so a plain string, a number and a boolean render as
21
+ * they are and a money or `timeslot` record is structured. A wrapped value states what a date,
22
+ * an instant or a percentage is, which shape alone cannot answer.
23
+ */
24
+ export type MessageArgument = WireValue | DeclaredMessageValue;
25
+ /**
26
+ * The host's display formatter, `formatValue(name, value, descriptor)`.
27
+ *
28
+ * It receives every argument and answers the text a message interpolates, or `undefined` when
29
+ * this host does not format that kind. A structured value — money, a date, an instant, a
30
+ * `timeslot`, a percentage — that no formatter answers falls back to the message key, because
31
+ * rendering the wire spelling as though it were display text is a wrong answer, not a
32
+ * fallback.
33
+ */
34
+ export type FormatValue = (name: string, value: WireValue, descriptor: MessageValueKind) => MessageParam | undefined;
35
+ /** A formatter bound to one artifact and one requested locale. */
36
+ export type MessageFormatter = (key: string, params?: Readonly<Record<string, MessageArgument>>) => string;
37
+ /**
38
+ * The formatter one artifact and one requested locale answer with.
39
+ *
40
+ * `locale` is a request, not a promise: the runtime resolves it to a declared catalogue key
41
+ * and renders that entry under that key's own plural rules, so `pt-PT` against a `pt`
42
+ * catalogue renders `pt` text with `pt` rules and the requested tag is never handed to a
43
+ * formatter. Passing no locale renders the document's default.
44
+ */
45
+ export declare function messageFormatter(compiled: CompiledSchema, locale: string | undefined, formatValue?: FormatValue): MessageFormatter;
46
+ /**
47
+ * The formatter for keys the *host* supplies rather than the artifact.
48
+ *
49
+ * An option loader answers at runtime with a `labelKey` the artifact never declared, and a
50
+ * server that names one key the catalogue lacks must not crash the render. Such a key renders
51
+ * as itself, exactly as a structured value with no host formatter does; the artifact's own
52
+ * message path (`messageFormatter`, behind `useMessage`) stays strict, because a key the
53
+ * compiler declared and the catalogue lacks is a bug in the artifact, not in host data.
54
+ */
55
+ export declare function hostMessageFormatter(compiled: CompiledSchema, locale: string | undefined, formatValue?: FormatValue): MessageFormatter;
56
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/store/messages.ts"],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runtime/messages';
2
+ import { AxiomError, isRecord } from '@azx-pbc/axiom-runtime';
3
+ /** The kinds the host must format: their wire spelling is not display text. */
4
+ const STRUCTURED = new Set([
5
+ 'money',
6
+ 'date',
7
+ 'instant',
8
+ 'timeslot',
9
+ 'percentage',
10
+ ]);
11
+ const KINDS = new Set([
12
+ 'text',
13
+ 'integer',
14
+ 'decimal',
15
+ 'boolean',
16
+ 'null',
17
+ 'array',
18
+ 'record',
19
+ 'money',
20
+ 'date',
21
+ 'instant',
22
+ 'timeslot',
23
+ 'percentage',
24
+ ]);
25
+ /**
26
+ * The formatter one artifact and one requested locale answer with.
27
+ *
28
+ * `locale` is a request, not a promise: the runtime resolves it to a declared catalogue key
29
+ * and renders that entry under that key's own plural rules, so `pt-PT` against a `pt`
30
+ * catalogue renders `pt` text with `pt` rules and the requested tag is never handed to a
31
+ * formatter. Passing no locale renders the document's default.
32
+ */
33
+ export function messageFormatter(compiled, locale, formatValue) {
34
+ return (key, params = {}) => {
35
+ const formatted = {};
36
+ let fallback = false;
37
+ for (const [name, argument] of Object.entries(params)) {
38
+ // The runtime reads a param only when the selected message branch uses it. A lazy getter
39
+ // keeps an unused structured value from forcing the key fallback or calling the host's
40
+ // formatter. `0` is a valid plural/select placeholder; an unavailable answer discards the
41
+ // rendered text below, so that placeholder never reaches the caller.
42
+ let answered = false;
43
+ let resolved = '0';
44
+ Object.defineProperty(formatted, name, {
45
+ enumerable: true,
46
+ get: () => {
47
+ if (answered)
48
+ return resolved;
49
+ answered = true;
50
+ const declared = isDeclaredArgument(argument);
51
+ const value = declared ? argument.value : argument;
52
+ const descriptor = declared ? argument.descriptor : shapeKind(value);
53
+ const answer = formatValue?.(name, value, descriptor);
54
+ if (answer !== undefined) {
55
+ resolved = answer;
56
+ return resolved;
57
+ }
58
+ const canonical = STRUCTURED.has(descriptor) ? undefined : canonicalParam(value);
59
+ if (canonical === undefined) {
60
+ fallback = true;
61
+ return resolved;
62
+ }
63
+ resolved = canonical;
64
+ return resolved;
65
+ },
66
+ });
67
+ }
68
+ let text;
69
+ try {
70
+ text = formatCatalogueMessage(compiled, key, locale, formatted);
71
+ }
72
+ catch (error) {
73
+ // Only a declared message missing an argument falls back to the key: a rule's params name
74
+ // record fields, and an undecided computed value is absent from them. Every other failure
75
+ // (undeclared key, invalid locale tag, missing locale entry, malformed plural or select
76
+ // AST, missing `other` branch, malformed count, or runtime argument failure) is a caller or
77
+ // artifact defect and must surface rather than degrade silently into raw message keys.
78
+ if (hasCatalogueMessage(compiled, key) && isMissingArgumentError(error)) {
79
+ return key;
80
+ }
81
+ throw error;
82
+ }
83
+ return fallback ? key : text;
84
+ };
85
+ }
86
+ /** Whether `error` is the runtime's structured refusal for an absent message argument. */
87
+ function isMissingArgumentError(error) {
88
+ if (!(error instanceof AxiomError) || error.code !== 'ENGINE_ERROR')
89
+ return false;
90
+ const reason = Object.getOwnPropertyDescriptor(error, 'reason')?.value;
91
+ return reason === 'missing_message_argument';
92
+ }
93
+ /**
94
+ * The formatter for keys the *host* supplies rather than the artifact.
95
+ *
96
+ * An option loader answers at runtime with a `labelKey` the artifact never declared, and a
97
+ * server that names one key the catalogue lacks must not crash the render. Such a key renders
98
+ * as itself, exactly as a structured value with no host formatter does; the artifact's own
99
+ * message path (`messageFormatter`, behind `useMessage`) stays strict, because a key the
100
+ * compiler declared and the catalogue lacks is a bug in the artifact, not in host data.
101
+ */
102
+ export function hostMessageFormatter(compiled, locale, formatValue) {
103
+ const format = messageFormatter(compiled, locale, formatValue);
104
+ return (key, params) => (hasCatalogueMessage(compiled, key) ? format(key, params) : key);
105
+ }
106
+ /** Whether the artifact's catalogue declares one message key. */
107
+ function hasCatalogueMessage(compiled, key) {
108
+ return compiled.messages !== undefined && Object.hasOwn(compiled.messages, key);
109
+ }
110
+ /** Whether the host wrapped an argument with the meaning its wire shape cannot state. */
111
+ function isDeclaredArgument(argument) {
112
+ if (!isRecord(argument))
113
+ return false;
114
+ const descriptor = argument['descriptor'];
115
+ return (typeof descriptor === 'string' && KINDS.has(descriptor) && Object.hasOwn(argument, 'value'));
116
+ }
117
+ /** The meaning a bare wire value carries by its shape. */
118
+ function shapeKind(value) {
119
+ if (value === null)
120
+ return 'null';
121
+ if (typeof value === 'string')
122
+ return 'text';
123
+ if (typeof value === 'boolean')
124
+ return 'boolean';
125
+ if (typeof value === 'number')
126
+ return 'integer';
127
+ if (Array.isArray(value))
128
+ return 'array';
129
+ if (isMoney(value))
130
+ return 'money';
131
+ if (isTimeslot(value))
132
+ return 'timeslot';
133
+ return 'record';
134
+ }
135
+ function isMoney(value) {
136
+ return (isRecord(value) &&
137
+ typeof value['minor'] === 'string' &&
138
+ typeof value['currency'] === 'string' &&
139
+ typeof value['scale'] === 'number');
140
+ }
141
+ function isTimeslot(value) {
142
+ return (isRecord(value) &&
143
+ typeof value['slotId'] === 'string' &&
144
+ typeof value['start'] === 'string' &&
145
+ typeof value['end'] === 'string');
146
+ }
147
+ /** The text a canonical scalar interpolates, or `undefined` for a value with no plain spelling. */
148
+ function canonicalParam(value) {
149
+ if (value === null)
150
+ return '';
151
+ if (typeof value === 'string' || typeof value === 'boolean')
152
+ return value;
153
+ if (typeof value === 'number')
154
+ return Number.isFinite(value) ? value : undefined;
155
+ return undefined;
156
+ }
157
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/store/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AA6D9D,+EAA+E;AAC/E,MAAM,UAAU,GAAkC,IAAI,GAAG,CAAC;IACxD,OAAO;IACP,MAAM;IACN,SAAS;IACT,UAAU;IACV,YAAY;CACb,CAAC,CAAC;AAEH,MAAM,KAAK,GAAwB,IAAI,GAAG,CAAmB;IAC3D,MAAM;IACN,SAAS;IACT,SAAS;IACT,SAAS;IACT,MA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OAAO,OAAO,CAAC;IACnC,IAAI,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC;IACzC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,OAAO,CAAC,KAAgB;IAC/B,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;QACf,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ;QAClC,OAAO,KAAK,CAAC,UAAU,CAAC,KAAK,QAAQ;QACrC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ,CACnC,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAAgB;IAClC,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;QACf,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,QAAQ;QACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ;QAClC,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,QAAQ,CACjC,CAAC;AACJ,CAAC;AAED,mGAAmG;AACnG,SAAS,cAAc,CAAC,KAAgB;IACtC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC1E,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACjF,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import { formatCatalogueMessage } from '@azx-pbc/axiom-runtime/messages';\nimport type { MessageParam } from '@azx-pbc/axiom-runtime/messages';\nimport { AxiomError, isRecord } from '@azx-pbc/axiom-runtime';\nimport type { CompiledSchema, WireValue } from '@azx-pbc/axiom-runtime';\n\n/**\n * What a message argument means, so a value the wire cannot format by itself is still shown.\n *\n * A message AST carries argument names and nothing else, so a `\"2026-01-31\"` and a `\"café\"` are\n * one `string`. The host says which is which — and only the host can, because rendering a date,\n * an instant, a money amount or a percentage for display is the host's job and never the\n * runtime's (`[MODEL-6.1.3]`).\n */\nexport type MessageValueKind =\n | 'text'\n | 'integer'\n | 'decimal'\n | 'boolean'\n | 'null'\n | 'array'\n | 'record'\n | 'money'\n | 'date'\n | 'instant'\n | 'timeslot'\n | 'percentage';\n\n/** One argument with the meaning the wire shape alone cannot state. */\nexport interface DeclaredMessageValue {\n readonly value: WireValue;\n readonly descriptor: MessageValueKind;\n}\n\n/**\n * One message argument: a canonical wire value, or a value with the meaning it carries.\n *\n * A bare wire value is read by its shape, so a plain string, a number and a boolean render as\n * they are and a money or `timeslot` record is structured. A wrapped value states what a date,\n * an instant or a percentage is, which shape alone cannot answer.\n */\nexport type MessageArgument = WireValue | DeclaredMessageValue;\n\n/**\n * The host's display formatter, `formatValue(name, value, descriptor)`.\n *\n * It receives every argument and answers the text a message interpolates, or `undefined` when\n * this host does not format that kind. A structured value — money, a date, an instant, a\n * `timeslot`, a percentage — that no formatter answers falls back to the message key, because\n * rendering the wire spelling as though it were display text is a wrong answer, not a\n * fallback.\n */\nexport type FormatValue = (\n name: string,\n value: WireValue,\n descriptor: MessageValueKind,\n) => MessageParam | undefined;\n\n/** A formatter bound to one artifact and one requested locale. */\nexport type MessageFormatter = (\n key: string,\n params?: Readonly<Record<string, MessageArgument>>,\n) => string;\n\n/** The kinds the host must format: their wire spelling is not display text. */\nconst STRUCTURED: ReadonlySet<MessageValueKind> = new Set([\n 'money',\n 'date',\n 'instant',\n 'timeslot',\n 'percentage',\n]);\n\nconst KINDS: ReadonlySet<string> = new Set<MessageValueKind>([\n 'text',\n 'integer',\n 'decimal',\n 'boolean',\n 'null',\n 'array',\n 'record',\n 'money',\n 'date',\n 'instant',\n 'timeslot',\n 'percentage',\n]);\n\n/**\n * The formatter one artifact and one requested locale answer with.\n *\n * `locale` is a request, not a promise: the runtime resolves it to a declared catalogue key\n * and renders that entry under that key's own plural rules, so `pt-PT` against a `pt`\n * catalogue renders `pt` text with `pt` rules and the requested tag is never handed to a\n * formatter. Passing no locale renders the document's default.\n */\nexport function messageFormatter(\n compiled: CompiledSchema,\n locale: string | undefined,\n formatValue?: FormatValue,\n): MessageFormatter {\n return (key, params = {}) => {\n const formatted: Record<string, MessageParam> = {};\n let fallback = false;\n for (const [name, argument] of Object.entries(params)) {\n // The runtime reads a param only when the selected message branch uses it. A lazy getter\n // keeps an unused structured value from forcing the key fallback or calling the host's\n // formatter. `0` is a valid plural/select placeholder; an unavailable answer discards the\n // rendered text below, so that placeholder never reaches the caller.\n let answered = false;\n let resolved: MessageParam = '0';\n Object.defineProperty(formatted, name, {\n enumerable: true,\n get: (): MessageParam => {\n if (answered) return resolved;\n answered = true;\n const declared = isDeclaredArgument(argument);\n const value: WireValue = declared ? argument.value : argument;\n const descriptor = declared ? argument.descriptor : shapeKind(value);\n const answer = formatValue?.(name, value, descriptor);\n if (answer !== undefined) {\n resolved = answer;\n return resolved;\n }\n const canonical = STRUCTURED.has(descriptor) ? undefined : canonicalParam(value);\n if (canonical === undefined) {\n fallback = true;\n return resolved;\n }\n resolved = canonical;\n return resolved;\n },\n });\n }\n let text: string;\n try {\n text = formatCatalogueMessage(compiled, key, locale, formatted);\n } catch (error) {\n // Only a declared message missing an argument falls back to the key: a rule's params name\n // record fields, and an undecided computed value is absent from them. Every other failure\n // (undeclared key, invalid locale tag, missing locale entry, malformed plural or select\n // AST, missing `other` branch, malformed count, or runtime argument failure) is a caller or\n // artifact defect and must surface rather than degrade silently into raw message keys.\n if (hasCatalogueMessage(compiled, key) && isMissingArgumentError(error)) {\n return key;\n }\n throw error;\n }\n return fallback ? key : text;\n };\n}\n\n/** Whether `error` is the runtime's structured refusal for an absent message argument. */\nfunction isMissingArgumentError(error: unknown): boolean {\n if (!(error instanceof AxiomError) || error.code !== 'ENGINE_ERROR') return false;\n const reason: unknown = Object.getOwnPropertyDescriptor(error, 'reason')?.value;\n return reason === 'missing_message_argument';\n}\n\n/**\n * The formatter for keys the *host* supplies rather than the artifact.\n *\n * An option loader answers at runtime with a `labelKey` the artifact never declared, and a\n * server that names one key the catalogue lacks must not crash the render. Such a key renders\n * as itself, exactly as a structured value with no host formatter does; the artifact's own\n * message path (`messageFormatter`, behind `useMessage`) stays strict, because a key the\n * compiler declared and the catalogue lacks is a bug in the artifact, not in host data.\n */\nexport function hostMessageFormatter(\n compiled: CompiledSchema,\n locale: string | undefined,\n formatValue?: FormatValue,\n): MessageFormatter {\n const format = messageFormatter(compiled, locale, formatValue);\n return (key, params) => (hasCatalogueMessage(compiled, key) ? format(key, params) : key);\n}\n\n/** Whether the artifact's catalogue declares one message key. */\nfunction hasCatalogueMessage(compiled: CompiledSchema, key: string): boolean {\n return compiled.messages !== undefined && Object.hasOwn(compiled.messages, key);\n}\n\n/** Whether the host wrapped an argument with the meaning its wire shape cannot state. */\nfunction isDeclaredArgument(argument: MessageArgument): argument is DeclaredMessageValue {\n if (!isRecord(argument)) return false;\n const descriptor = argument['descriptor'];\n return (\n typeof descriptor === 'string' && KINDS.has(descriptor) && Object.hasOwn(argument, 'value')\n );\n}\n\n/** The meaning a bare wire value carries by its shape. */\nfunction shapeKind(value: WireValue): MessageValueKind {\n if (value === null) return 'null';\n if (typeof value === 'string') return 'text';\n if (typeof value === 'boolean') return 'boolean';\n if (typeof value === 'number') return 'integer';\n if (Array.isArray(value)) return 'array';\n if (isMoney(value)) return 'money';\n if (isTimeslot(value)) return 'timeslot';\n return 'record';\n}\n\nfunction isMoney(value: WireValue): boolean {\n return (\n isRecord(value) &&\n typeof value['minor'] === 'string' &&\n typeof value['currency'] === 'string' &&\n typeof value['scale'] === 'number'\n );\n}\n\nfunction isTimeslot(value: WireValue): boolean {\n return (\n isRecord(value) &&\n typeof value['slotId'] === 'string' &&\n typeof value['start'] === 'string' &&\n typeof value['end'] === 'string'\n );\n}\n\n/** The text a canonical scalar interpolates, or `undefined` for a value with no plain spelling. */\nfunction canonicalParam(value: WireValue): MessageParam | undefined {\n if (value === null) return '';\n if (typeof value === 'string' || typeof value === 'boolean') return value;\n if (typeof value === 'number') return Number.isFinite(value) ? value : undefined;\n return undefined;\n}\n"]}