@azx-pbc/axiom-builder 0.0.0-stage → 0.0.6

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,572 @@
1
+ import { CURRENCY_CODE_PATTERN, CONTROLS } from '@azx-pbc/axiom-runtime';
2
+ import { fieldRequiresControl, fieldsControls } from '../../schema/palette.js';
3
+ import { readTestCaseList } from './rule.js';
4
+ import { MAX_MEMBER_NESTING, admitsOptions, describe, fail, onlyMembers, readAnnotations, readBoolean, readBound, readChoice, readControl, readEditable, readIdentifier, readIdentifierList, readInteger, readLiteral, readMessageKey, readOptionalChoice, readOptionalDurationUnit, readOptionalInteger, readOptionalLiteral, readOptionalText, readPath, readPositiveInteger, readRecord, readRowKey, readText, readTextList, readUnitList, isCanonicalInteger, ITEM_PRIMITIVES, ON_HIDE_POLICIES, } from './readers.js';
5
+ /** The field primitives a declaration states, in the metaschema's own vocabulary. */
6
+ export const FIELD_PRIMITIVES = [
7
+ 'string',
8
+ 'boolean',
9
+ 'integer',
10
+ 'decimal',
11
+ 'money',
12
+ 'quantity',
13
+ 'duration',
14
+ 'date',
15
+ 'instant',
16
+ 'time',
17
+ 'media_ref',
18
+ 'signature_ref',
19
+ 'timeslot',
20
+ 'address',
21
+ 'coordinate',
22
+ 'array',
23
+ 'record',
24
+ ];
25
+ /** One option source, `schema.v1.json` `optionSource`. */
26
+ function readOptionSource(draftIn, record, path) {
27
+ if (!Object.hasOwn(record, 'optionSource'))
28
+ return undefined;
29
+ const source = readRecord(draftIn, record['optionSource'], `${path}.optionSource`, '`optionSource`');
30
+ if (source === undefined)
31
+ return undefined;
32
+ const kind = readText(draftIn, source, 'kind', `${path}.optionSource`);
33
+ if (kind === 'host') {
34
+ onlyMembers(draftIn, source, ['kind', 'sourceId', 'dependsOn'], `${path}.optionSource`);
35
+ const sourceId = readIdentifier(draftIn, source, 'sourceId', `${path}.optionSource`);
36
+ const dependsOn = Object.hasOwn(source, 'dependsOn')
37
+ ? readIdentifierList(draftIn, source['dependsOn'], `${path}.optionSource.dependsOn`, '`dependsOn`')
38
+ : undefined;
39
+ if (sourceId === undefined || draftIn.refusal !== undefined)
40
+ return undefined;
41
+ return { kind, sourceId, ...(dependsOn === undefined ? {} : { dependsOn }) };
42
+ }
43
+ if (kind === 'field') {
44
+ onlyMembers(draftIn, source, ['kind', 'fieldId'], `${path}.optionSource`);
45
+ const fieldId = readIdentifier(draftIn, source, 'fieldId', `${path}.optionSource`);
46
+ if (fieldId === undefined)
47
+ return undefined;
48
+ return { kind, fieldId };
49
+ }
50
+ return fail(draftIn, `${path}.optionSource.kind`, `\`kind\` is \`host\` or \`field\`; received ${describe(kind)}`);
51
+ }
52
+ export function readFieldSpec(draftIn, value, path, depth) {
53
+ const spec = readRecord(draftIn, value, path, 'a field');
54
+ if (spec === undefined)
55
+ return undefined;
56
+ onlyMembers(draftIn, spec, [
57
+ 'fieldId',
58
+ 'label',
59
+ 'primitive',
60
+ 'control',
61
+ 'items',
62
+ 'currency',
63
+ 'scale',
64
+ 'units',
65
+ 'unit',
66
+ 'step',
67
+ 'minimum',
68
+ 'maximum',
69
+ 'minimumMessage',
70
+ 'maximumMessage',
71
+ 'placement',
72
+ 'colSpan',
73
+ 'parent',
74
+ 'index',
75
+ 'annotations',
76
+ 'options',
77
+ 'optionSource',
78
+ 'rowKey',
79
+ 'members',
80
+ 'covers',
81
+ ], path);
82
+ const fieldId = readIdentifier(draftIn, spec, 'fieldId', path);
83
+ const label = readLiteral(draftIn, spec, 'label', path);
84
+ const primitive = readChoice(draftIn, spec, 'primitive', path, FIELD_PRIMITIVES);
85
+ const itemPrimitive = readOptionalChoice(draftIn, spec, 'items', path, ITEM_PRIMITIVES);
86
+ const currency = readOptionalText(draftIn, spec, 'currency', path);
87
+ const scale = readOptionalInteger(draftIn, spec, 'scale', path);
88
+ const units = Object.hasOwn(spec, 'units')
89
+ ? readUnitList(draftIn, spec['units'], `${path}.units`, '`units`')
90
+ : undefined;
91
+ const unit = readOptionalDurationUnit(draftIn, spec, 'unit', path);
92
+ const step = Object.hasOwn(spec, 'step') ? readBound(draftIn, spec, 'step', path) : undefined;
93
+ const minimum = Object.hasOwn(spec, 'minimum')
94
+ ? readBound(draftIn, spec, 'minimum', path)
95
+ : undefined;
96
+ const maximum = Object.hasOwn(spec, 'maximum')
97
+ ? readBound(draftIn, spec, 'maximum', path)
98
+ : undefined;
99
+ const minimumMessage = readOptionalLiteral(draftIn, spec, 'minimumMessage', path);
100
+ const maximumMessage = readOptionalLiteral(draftIn, spec, 'maximumMessage', path);
101
+ const placement = readOptionalChoice(draftIn, spec, 'placement', path, [
102
+ 'append',
103
+ 'none',
104
+ ]);
105
+ const colSpan = readOptionalInteger(draftIn, spec, 'colSpan', path);
106
+ const parent = readPath(draftIn, spec, 'parent', path);
107
+ const index = readOptionalInteger(draftIn, spec, 'index', path);
108
+ if (index !== undefined && index < 0) {
109
+ fail(draftIn, `${path}.index`, '`index` is a position from zero; it cannot be negative');
110
+ }
111
+ const annotations = readAnnotations(draftIn, spec, path);
112
+ const rowKey = readRowKey(draftIn, spec, path);
113
+ const options = readOptionSpecs(draftIn, spec, path);
114
+ const optionSource = readOptionSource(draftIn, spec, path);
115
+ // A coverage list is read as the metaschema states it — identifiers, no duplicates, never
116
+ // empty — and passed through whatever the primitive: the compiler refuses it on a field that
117
+ // is not a `signature_capture`, at the document path, rather than the store dropping it.
118
+ const covers = Object.hasOwn(spec, 'covers')
119
+ ? readIdentifierList(draftIn, spec['covers'], `${path}.covers`, '`covers`')
120
+ : undefined;
121
+ // A member tree is read only where the primitive admits one, so a scalar that states extra
122
+ // members is refused for that rather than for something inside a tree it cannot hold.
123
+ const members = primitive === 'record' ? readMembers(draftIn, spec, path, 'a record', depth + 1) : undefined;
124
+ if (colSpan !== undefined && (colSpan < 1 || colSpan > 4)) {
125
+ fail(draftIn, `${path}.colSpan`, `\`colSpan\` is 1 to 4 columns; received ${String(colSpan)}`);
126
+ }
127
+ if (placement === 'none' && (parent !== undefined || colSpan !== undefined)) {
128
+ fail(draftIn, `${path}.placement`, 'a field declared without a placement states no `parent` and no `colSpan`; `placeField` supplies both when the field is placed');
129
+ }
130
+ if (primitive === 'record') {
131
+ if (members === undefined && draftIn.refusal === undefined) {
132
+ fail(draftIn, `${path}.members`, 'a record declares at least one member in `members`; the metaschema states `minItems: 1`');
133
+ }
134
+ }
135
+ else if (Object.hasOwn(spec, 'members')) {
136
+ fail(draftIn, `${path}.members`, 'only a `record` declares `members`; a repeating record is `addRecordArray`, and a member tree belongs to a record');
137
+ }
138
+ if (primitive === 'array' && itemPrimitive === undefined) {
139
+ fail(draftIn, `${path}.items`, 'a scalar or attachment array declares its elements in `items`; a repeating record uses `addRecordArray`');
140
+ }
141
+ if (primitive !== 'array' && itemPrimitive !== undefined) {
142
+ fail(draftIn, `${path}.items`, 'only an array declares `items`');
143
+ }
144
+ if (options !== undefined && optionSource !== undefined) {
145
+ fail(draftIn, `${path}.optionSource`, 'a field states its option domain one way: `options` or `optionSource`, never both');
146
+ }
147
+ const optionsAdmitted = admitsOptions(primitive, itemPrimitive);
148
+ if (primitive === 'array') {
149
+ if (!optionsAdmitted && rowKey === undefined && optionSource === undefined) {
150
+ fail(draftIn, `${path}.rowKey`, 'a freeform array states how its rows are identified in a `rowKey`; only an array of strings, integers or durations has an option domain instead');
151
+ }
152
+ if (rowKey !== undefined && (options !== undefined || optionSource !== undefined)) {
153
+ fail(draftIn, `${path}.rowKey`, 'an array identified by a `rowKey` declares no option domain: a domain identifies its rows by their values');
154
+ }
155
+ if (rowKey === undefined && options === undefined && optionSource === undefined) {
156
+ fail(draftIn, `${path}.rowKey`, 'an array states how its rows are identified: a `rowKey` for a freeform array, or an `options` domain');
157
+ }
158
+ }
159
+ else {
160
+ if (rowKey !== undefined) {
161
+ fail(draftIn, `${path}.rowKey`, 'only an array declares a `rowKey`');
162
+ }
163
+ if ((options !== undefined || optionSource !== undefined) && !optionsAdmitted) {
164
+ fail(draftIn, `${path}.options`, `a \`${String(primitive)}\` field holds values an option domain cannot name; options are stated on a string, integer, boolean or duration field`);
165
+ }
166
+ }
167
+ // A duration's option codes are the positive amounts it offers: the unit belongs to the
168
+ // declaration and only the amount varies, so a code outside that domain is a value the control
169
+ // could never write. The compiler states the same rule (`INVALID_CONTROL`); refusing here names
170
+ // the entry before the candidate gate reports the whole field.
171
+ const optionHolder = primitive === 'array' ? itemPrimitive : primitive;
172
+ if (options !== undefined && optionHolder === 'duration') {
173
+ const index = options.findIndex((option) => typeof option.code !== 'number' || !Number.isSafeInteger(option.code) || option.code <= 0);
174
+ const option = options[index];
175
+ if (option !== undefined) {
176
+ fail(draftIn, `${path}.options[${String(index)}].code`, `a \`duration\` option code is a positive whole amount; received \`${String(option.code)}\`, and the declaration states the unit, so the code states only the amount`);
177
+ }
178
+ }
179
+ // A money domain belongs to the declaration that holds the amounts. The store refuses a
180
+ // declaration that *omits* it, because that is a command-shape question an author can answer
181
+ // from the refusal, and it names the spelling a currency has to be; whether the domain is legal
182
+ // on a shape at all — its presence, its scale range, its refusal elsewhere — is the closed
183
+ // metaschema's, which refuses `currency`/`scale` on every non-`money` field and item
184
+ // (`MODEL-2.1.15`). Restating that here would be a second authority for one fact.
185
+ const holdsMoney = primitive === 'money' || itemPrimitive === 'money';
186
+ if (holdsMoney) {
187
+ if (currency === undefined) {
188
+ fail(draftIn, `${path}.currency`, 'a `money` declaration states its ISO 4217 currency');
189
+ }
190
+ else if (!CURRENCY_CODE_PATTERN.test(currency)) {
191
+ fail(draftIn, `${path}.currency`, `\`currency\` is \`${currency}\`; write three upper-case letters, as \`USD\``);
192
+ }
193
+ if (scale === undefined) {
194
+ fail(draftIn, `${path}.scale`, 'a `money` declaration states its `scale`, the minor-unit digits');
195
+ }
196
+ }
197
+ // A quantity's unit domain is what makes its values measurable, so a declaration that omits it
198
+ // is half a shape. The list's spelling and uniqueness are `readUnitList`'s; what belongs to the
199
+ // declaration is that it states one at all.
200
+ const holdsQuantity = primitive === 'quantity' || itemPrimitive === 'quantity';
201
+ if (holdsQuantity && units === undefined && draftIn.refusal === undefined) {
202
+ fail(draftIn, `${path}.units`, 'a `quantity` declaration states its unit domain in `units`; write the non-empty list of unit codes the value may name, such as `["sqm", "each"]`');
203
+ }
204
+ // A bound is presentation copy plus the rule it compiles to, and the metaschema requires the
205
+ // sentence wherever the bound is stated. Pairing them here keeps a caller from writing half a
206
+ // declaration the candidate gate would then refuse at the document path.
207
+ if (minimum !== undefined && minimumMessage === undefined) {
208
+ fail(draftIn, `${path}.minimumMessage`, 'a `minimum` states the sentence a value below it raises in `minimumMessage`');
209
+ }
210
+ if (minimumMessage !== undefined && minimum === undefined) {
211
+ fail(draftIn, `${path}.minimum`, '`minimumMessage` is the sentence `minimum` raises, so it states no value on its own; add `minimum` or remove the sentence');
212
+ }
213
+ if (maximum !== undefined && maximumMessage === undefined) {
214
+ fail(draftIn, `${path}.maximumMessage`, 'a `maximum` states the sentence a value above it raises in `maximumMessage`');
215
+ }
216
+ if (maximumMessage !== undefined && maximum === undefined) {
217
+ fail(draftIn, `${path}.maximum`, '`maximumMessage` is the sentence `maximum` raises, so it states no value on its own; add `maximum` or remove the sentence');
218
+ }
219
+ const control = primitive === undefined
220
+ ? undefined
221
+ : readControl(draftIn, spec, primitive, itemPrimitive, path);
222
+ if (primitive !== undefined &&
223
+ control === undefined &&
224
+ fieldRequiresControl(primitive, itemPrimitive)) {
225
+ fail(draftIn, `${path}.control`, `a \`${primitive}\` field states a control; the matrix pairs ${fieldsControls(primitive, itemPrimitive).join(', ')}`);
226
+ }
227
+ if (fieldId === undefined ||
228
+ label === undefined ||
229
+ primitive === undefined ||
230
+ draftIn.refusal !== undefined) {
231
+ return undefined;
232
+ }
233
+ return {
234
+ fieldId,
235
+ label,
236
+ primitive,
237
+ ...(control === undefined ? {} : { control }),
238
+ ...(itemPrimitive === undefined ? {} : { items: itemPrimitive }),
239
+ ...(currency === undefined ? {} : { currency }),
240
+ ...(scale === undefined ? {} : { scale }),
241
+ ...(units === undefined ? {} : { units }),
242
+ ...(unit === undefined ? {} : { unit }),
243
+ ...(step === undefined ? {} : { step }),
244
+ ...(minimum === undefined ? {} : { minimum }),
245
+ ...(maximum === undefined ? {} : { maximum }),
246
+ ...(minimumMessage === undefined ? {} : { minimumMessage }),
247
+ ...(maximumMessage === undefined ? {} : { maximumMessage }),
248
+ ...(rowKey === undefined ? {} : { rowKey }),
249
+ ...(options === undefined ? {} : { options }),
250
+ ...(optionSource === undefined ? {} : { optionSource }),
251
+ ...(covers === undefined ? {} : { covers }),
252
+ ...(members === undefined ? {} : { members }),
253
+ ...(placement === undefined ? {} : { placement }),
254
+ ...(colSpan === undefined ? {} : { colSpan }),
255
+ ...(parent === undefined ? {} : { parent }),
256
+ ...(index === undefined ? {} : { index }),
257
+ ...(annotations === undefined ? {} : { annotations }),
258
+ };
259
+ }
260
+ function readOptionSpecs(draftIn, record, path) {
261
+ if (!Object.hasOwn(record, 'options'))
262
+ return undefined;
263
+ const value = record['options'];
264
+ if (!Array.isArray(value) || value.length === 0) {
265
+ return fail(draftIn, `${path}.options`, 'an option domain states at least one option');
266
+ }
267
+ const options = [];
268
+ value.forEach((entry, index) => {
269
+ const at = `${path}.options[${String(index)}]`;
270
+ const option = readRecord(draftIn, entry, at, 'an option');
271
+ if (option === undefined)
272
+ return;
273
+ onlyMembers(draftIn, option, ['code', 'label'], at);
274
+ const code = option['code'];
275
+ const label = readLiteral(draftIn, option, 'label', at);
276
+ let narrowed;
277
+ if (typeof code === 'string' && code !== '')
278
+ narrowed = code;
279
+ else if (isCanonicalInteger(code))
280
+ narrowed = code;
281
+ else
282
+ fail(draftIn, `${at}.code`, '`code` is a non-empty text or a whole number');
283
+ if (narrowed === undefined || label === undefined)
284
+ return;
285
+ options.push({ code: narrowed, label });
286
+ });
287
+ return options.length === value.length ? options : undefined;
288
+ }
289
+ function readMembers(draftIn, record, path, what, depth) {
290
+ if (!Object.hasOwn(record, 'members'))
291
+ return undefined;
292
+ const value = record['members'];
293
+ if (!Array.isArray(value) || value.length === 0) {
294
+ return fail(draftIn, `${path}.members`, `${what} declares at least one member in \`members\`; the metaschema states \`minItems: 1\``);
295
+ }
296
+ const parsed = [];
297
+ value.forEach((member, index) => {
298
+ const one = readMemberSpec(draftIn, member, `${path}.members[${String(index)}]`, depth);
299
+ if (one !== undefined)
300
+ parsed.push(one);
301
+ });
302
+ const [first, ...rest] = parsed;
303
+ if (first === undefined || draftIn.refusal !== undefined)
304
+ return undefined;
305
+ return [first, ...rest];
306
+ }
307
+ export function readMemberSpec(draftIn, value, path, depth) {
308
+ if (depth > MAX_MEMBER_NESTING) {
309
+ return fail(draftIn, path, `container members nest at most ${String(MAX_MEMBER_NESTING)} records deep; this one is deeper`);
310
+ }
311
+ const spec = readRecord(draftIn, value, path, 'a container member');
312
+ if (spec === undefined)
313
+ return undefined;
314
+ const kind = readText(draftIn, spec, 'kind', path);
315
+ if (kind === 'field') {
316
+ onlyMembers(draftIn, spec, ['kind', 'field'], path);
317
+ const field = readFieldSpec(draftIn, spec['field'], `${path}.field`, depth);
318
+ if (field === undefined)
319
+ return undefined;
320
+ if (field.parent !== undefined) {
321
+ return fail(draftIn, `${path}.field.parent`, 'a container member has no placement of its own; place the container instead');
322
+ }
323
+ if (field.colSpan !== undefined) {
324
+ return fail(draftIn, `${path}.field.colSpan`, 'a container member has no column span of its own; set the container’s layout leaf instead');
325
+ }
326
+ if (field.placement !== undefined) {
327
+ return fail(draftIn, `${path}.field.placement`, 'a container member has no placement of its own; the container owns the layout leaf');
328
+ }
329
+ const member = field;
330
+ return { kind: 'field', field: member };
331
+ }
332
+ if (kind === 'record') {
333
+ onlyMembers(draftIn, spec, ['kind', 'recordId', 'members'], path);
334
+ const recordId = readIdentifier(draftIn, spec, 'recordId', path);
335
+ const members = readMembers(draftIn, spec, path, 'a record member', depth + 1);
336
+ if (recordId === undefined || members === undefined || draftIn.refusal !== undefined) {
337
+ return undefined;
338
+ }
339
+ return { kind: 'record', recordId, members };
340
+ }
341
+ return fail(draftIn, `${path}.kind`, `\`kind\` is \`field\` or \`record\`; received ${describe(kind)}`);
342
+ }
343
+ export function readRecordArray(draftIn, value, path) {
344
+ const spec = readRecord(draftIn, value, path, 'a record array');
345
+ if (spec === undefined)
346
+ return undefined;
347
+ onlyMembers(draftIn, spec, ['fieldId', 'label', 'rowKey', 'members', 'placement', 'colSpan', 'parent'], path);
348
+ const fieldId = readIdentifier(draftIn, spec, 'fieldId', path);
349
+ const label = readOptionalLiteral(draftIn, spec, 'label', path);
350
+ const rowKey = readRowKey(draftIn, spec, path);
351
+ if (rowKey === undefined) {
352
+ fail(draftIn, `${path}.rowKey`, 'a record array states how its rows are identified');
353
+ }
354
+ const placement = readOptionalChoice(draftIn, spec, 'placement', path, [
355
+ 'append',
356
+ 'none',
357
+ ]);
358
+ const colSpan = readOptionalInteger(draftIn, spec, 'colSpan', path);
359
+ const parent = readPath(draftIn, spec, 'parent', path);
360
+ if (colSpan !== undefined && (colSpan < 1 || colSpan > 4)) {
361
+ fail(draftIn, `${path}.colSpan`, `\`colSpan\` is 1 to 4 columns; received ${String(colSpan)}`);
362
+ }
363
+ if (placement === 'none' && (parent !== undefined || colSpan !== undefined)) {
364
+ fail(draftIn, `${path}.placement`, 'a record array declared without a placement states no `parent` and no `colSpan`; `placeField` supplies both when it is placed');
365
+ }
366
+ const members = readMembers(draftIn, spec, path, 'a record array', 1);
367
+ if (fieldId === undefined ||
368
+ rowKey === undefined ||
369
+ members === undefined ||
370
+ draftIn.refusal !== undefined) {
371
+ return undefined;
372
+ }
373
+ return {
374
+ fieldId,
375
+ ...(label === undefined ? {} : { label }),
376
+ rowKey,
377
+ members,
378
+ ...(placement === undefined ? {} : { placement }),
379
+ ...(colSpan === undefined ? {} : { colSpan }),
380
+ ...(parent === undefined ? {} : { parent }),
381
+ };
382
+ }
383
+ /** One declared field's editable metadata, as an edit states it. */
384
+ export function readEditFieldSpec(draftIn, value, path) {
385
+ const spec = readRecord(draftIn, value, path, 'a field edit');
386
+ if (spec === undefined)
387
+ return undefined;
388
+ onlyMembers(draftIn, spec, ['control', 'descriptionKey', 'placeholderKey', 'onHide', 'annotations'], path);
389
+ const control = readEditable(spec, 'control', () => readChoice(draftIn, spec, 'control', path, CONTROLS));
390
+ const descriptionKey = readEditable(spec, 'descriptionKey', () => readText(draftIn, spec, 'descriptionKey', path));
391
+ const placeholderKey = readEditable(spec, 'placeholderKey', () => readText(draftIn, spec, 'placeholderKey', path));
392
+ const onHide = readEditable(spec, 'onHide', () => readChoice(draftIn, spec, 'onHide', path, ON_HIDE_POLICIES));
393
+ const annotations = readEditable(spec, 'annotations', () => readAnnotations(draftIn, spec, path));
394
+ if (draftIn.refusal !== undefined)
395
+ return undefined;
396
+ if (control === undefined &&
397
+ descriptionKey === undefined &&
398
+ placeholderKey === undefined &&
399
+ onHide === undefined &&
400
+ annotations === undefined) {
401
+ return fail(draftIn, path, 'a field edit states at least one member to change: `control`, `descriptionKey`, `placeholderKey`, `onHide` or `annotations`');
402
+ }
403
+ return {
404
+ ...(control === undefined ? {} : { control }),
405
+ ...(descriptionKey === undefined ? {} : { descriptionKey }),
406
+ ...(placeholderKey === undefined ? {} : { placeholderKey }),
407
+ ...(onHide === undefined ? {} : { onHide }),
408
+ ...(annotations === undefined ? {} : { annotations }),
409
+ };
410
+ }
411
+ /** The members one declaration edit may state; a member outside this list is refused. */
412
+ const FIELD_DECLARATION_MEMBERS = [
413
+ 'required',
414
+ 'requiredMessageKey',
415
+ 'requiredWhen',
416
+ 'visibleWhen',
417
+ 'minLength',
418
+ 'maxLength',
419
+ 'minLengthMessageKey',
420
+ 'maxLengthMessageKey',
421
+ 'minItems',
422
+ 'maxItems',
423
+ 'maxScale',
424
+ 'maxScaleMessageKey',
425
+ 'minimum',
426
+ 'maximum',
427
+ 'minimumMessageKey',
428
+ 'maximumMessageKey',
429
+ 'step',
430
+ 'accept',
431
+ 'minBytes',
432
+ 'maxBytes',
433
+ 'rowsFrom',
434
+ 'requiredTestCases',
435
+ 'visibleWhenTestCases',
436
+ 'minimumTestCases',
437
+ 'maximumTestCases',
438
+ 'minLengthTestCases',
439
+ 'maxLengthTestCases',
440
+ ];
441
+ /** A declared count, refused below zero where the metaschema's `minimum` states the floor. */
442
+ function readCount(draftIn, spec, key, path) {
443
+ return readEditable(spec, key, () => {
444
+ const value = readInteger(draftIn, spec, key, path);
445
+ if (value === undefined)
446
+ return undefined;
447
+ if (value < 0) {
448
+ fail(draftIn, `${path}.${key}`, `\`${key}\` counts at least zero; received ${String(value)}`);
449
+ return undefined;
450
+ }
451
+ return value;
452
+ });
453
+ }
454
+ /**
455
+ * One declaration edit: the members that compile into a rule, each left alone, cleared or set.
456
+ *
457
+ * An empty edit is refused for the same reason an empty `editField` is: a command that changes
458
+ * nothing is an undo step an author cannot see and cannot explain. The relations between the
459
+ * members — a bound needs its message key, `required` excludes `requiredWhen`, a count belongs
460
+ * to an array — are the closed metaschema's and the compiler's declaration walk's, not a third
461
+ * copy here; the store reports their refusals at the member the author wrote.
462
+ */
463
+ export function readFieldDeclarationSpec(draftIn, value, path) {
464
+ const spec = readRecord(draftIn, value, path, 'a field declaration');
465
+ if (spec === undefined)
466
+ return undefined;
467
+ onlyMembers(draftIn, spec, FIELD_DECLARATION_MEMBERS, path);
468
+ const required = readEditable(spec, 'required', () => readBoolean(draftIn, spec, 'required', path));
469
+ const requiredMessageKey = readEditable(spec, 'requiredMessageKey', () => readMessageKey(draftIn, spec, 'requiredMessageKey', path));
470
+ const requiredWhen = readEditable(spec, 'requiredWhen', () => readLiteral(draftIn, spec, 'requiredWhen', path));
471
+ const visibleWhen = readEditable(spec, 'visibleWhen', () => readLiteral(draftIn, spec, 'visibleWhen', path));
472
+ const minLength = readCount(draftIn, spec, 'minLength', path);
473
+ const maxLength = readCount(draftIn, spec, 'maxLength', path);
474
+ const minLengthMessageKey = readEditable(spec, 'minLengthMessageKey', () => readMessageKey(draftIn, spec, 'minLengthMessageKey', path));
475
+ const maxLengthMessageKey = readEditable(spec, 'maxLengthMessageKey', () => readMessageKey(draftIn, spec, 'maxLengthMessageKey', path));
476
+ const minItems = readCount(draftIn, spec, 'minItems', path);
477
+ const maxItems = readCount(draftIn, spec, 'maxItems', path);
478
+ const maxScale = readCount(draftIn, spec, 'maxScale', path);
479
+ const maxScaleMessageKey = readEditable(spec, 'maxScaleMessageKey', () => readMessageKey(draftIn, spec, 'maxScaleMessageKey', path));
480
+ const minimum = readEditable(spec, 'minimum', () => readBound(draftIn, spec, 'minimum', path));
481
+ const maximum = readEditable(spec, 'maximum', () => readBound(draftIn, spec, 'maximum', path));
482
+ const minimumMessageKey = readEditable(spec, 'minimumMessageKey', () => readMessageKey(draftIn, spec, 'minimumMessageKey', path));
483
+ const maximumMessageKey = readEditable(spec, 'maximumMessageKey', () => readMessageKey(draftIn, spec, 'maximumMessageKey', path));
484
+ const step = readEditable(spec, 'step', () => readBound(draftIn, spec, 'step', path));
485
+ const accept = readEditable(spec, 'accept', () => readTextList(draftIn, spec['accept'], `${path}.accept`, '`accept`'));
486
+ const minBytes = readEditable(spec, 'minBytes', () => readPositiveInteger(draftIn, spec, 'minBytes', path));
487
+ const maxBytes = readEditable(spec, 'maxBytes', () => readPositiveInteger(draftIn, spec, 'maxBytes', path));
488
+ const rowsFrom = readEditable(spec, 'rowsFrom', () => readLiteral(draftIn, spec, 'rowsFrom', path));
489
+ const requiredTestCases = readEditable(spec, 'requiredTestCases', () => readTestCaseList(draftIn, spec, path, 'requiredTestCases'));
490
+ const visibleWhenTestCases = readEditable(spec, 'visibleWhenTestCases', () => readTestCaseList(draftIn, spec, path, 'visibleWhenTestCases'));
491
+ const minimumTestCases = readEditable(spec, 'minimumTestCases', () => readTestCaseList(draftIn, spec, path, 'minimumTestCases'));
492
+ const maximumTestCases = readEditable(spec, 'maximumTestCases', () => readTestCaseList(draftIn, spec, path, 'maximumTestCases'));
493
+ const minLengthTestCases = readEditable(spec, 'minLengthTestCases', () => readTestCaseList(draftIn, spec, path, 'minLengthTestCases'));
494
+ const maxLengthTestCases = readEditable(spec, 'maxLengthTestCases', () => readTestCaseList(draftIn, spec, path, 'maxLengthTestCases'));
495
+ if (draftIn.refusal !== undefined)
496
+ return undefined;
497
+ const declaration = {
498
+ ...(required === undefined ? {} : { required }),
499
+ ...(requiredMessageKey === undefined ? {} : { requiredMessageKey }),
500
+ ...(requiredWhen === undefined ? {} : { requiredWhen }),
501
+ ...(visibleWhen === undefined ? {} : { visibleWhen }),
502
+ ...(minLength === undefined ? {} : { minLength }),
503
+ ...(maxLength === undefined ? {} : { maxLength }),
504
+ ...(minLengthMessageKey === undefined ? {} : { minLengthMessageKey }),
505
+ ...(maxLengthMessageKey === undefined ? {} : { maxLengthMessageKey }),
506
+ ...(minItems === undefined ? {} : { minItems }),
507
+ ...(maxItems === undefined ? {} : { maxItems }),
508
+ ...(maxScale === undefined ? {} : { maxScale }),
509
+ ...(maxScaleMessageKey === undefined ? {} : { maxScaleMessageKey }),
510
+ ...(minimum === undefined ? {} : { minimum }),
511
+ ...(maximum === undefined ? {} : { maximum }),
512
+ ...(minimumMessageKey === undefined ? {} : { minimumMessageKey }),
513
+ ...(maximumMessageKey === undefined ? {} : { maximumMessageKey }),
514
+ ...(step === undefined ? {} : { step }),
515
+ ...(accept === undefined ? {} : { accept }),
516
+ ...(minBytes === undefined ? {} : { minBytes }),
517
+ ...(maxBytes === undefined ? {} : { maxBytes }),
518
+ ...(rowsFrom === undefined ? {} : { rowsFrom }),
519
+ ...(requiredTestCases === undefined ? {} : { requiredTestCases }),
520
+ ...(visibleWhenTestCases === undefined ? {} : { visibleWhenTestCases }),
521
+ ...(minimumTestCases === undefined ? {} : { minimumTestCases }),
522
+ ...(maximumTestCases === undefined ? {} : { maximumTestCases }),
523
+ ...(minLengthTestCases === undefined ? {} : { minLengthTestCases }),
524
+ ...(maxLengthTestCases === undefined ? {} : { maxLengthTestCases }),
525
+ };
526
+ if (Object.keys(declaration).length === 0) {
527
+ return fail(draftIn, path, 'a field declaration change states at least one member to change: `required`, `requiredMessageKey`, `requiredWhen`, `visibleWhen`, `minLength`, `maxLength`, `minLengthMessageKey`, `maxLengthMessageKey`, `minItems`, `maxItems`, `maxScale`, `maxScaleMessageKey`, `minimum`, `maximum`, `minimumMessageKey`, `maximumMessageKey`, `step`, `accept`, `minBytes`, `maxBytes`, `rowsFrom`, `requiredTestCases`, `visibleWhenTestCases`, `minimumTestCases`, `maximumTestCases`, `minLengthTestCases` or `maxLengthTestCases`');
528
+ }
529
+ return declaration;
530
+ }
531
+ /**
532
+ * One declaration's new value domain, as `setFieldPrimitive` states it.
533
+ *
534
+ * The domain grammar — which primitives hold which items, where a money currency and scale belong,
535
+ * which controls the matrix pairs, and how a freeform array is identified — is the one
536
+ * `readFieldSpec` already states for `addField`. Restating it here would be a second authority for
537
+ * one fact, so this reader states the edit's record, folds it into an addition under a synthetic
538
+ * identity, and reads it through that door. The synthetic `fieldId` and `label` never reach a
539
+ * document; the caller's declaration identity and copy stay the store's.
540
+ */
541
+ export function readFieldPrimitiveSpec(draftIn, value, path) {
542
+ const spec = readRecord(draftIn, value, path, 'a field domain');
543
+ if (spec === undefined)
544
+ return undefined;
545
+ onlyMembers(draftIn, spec, [
546
+ 'primitive',
547
+ 'control',
548
+ 'items',
549
+ 'currency',
550
+ 'scale',
551
+ 'units',
552
+ 'unit',
553
+ 'options',
554
+ 'rowKey',
555
+ 'covers',
556
+ ], path);
557
+ const primitive = readChoice(draftIn, spec, 'primitive', path, FIELD_PRIMITIVES);
558
+ if (primitive === 'record') {
559
+ return fail(draftIn, `${path}.primitive`, 'a record’s members are its declaration: add a new record rather than retyping one under the members that depend on it');
560
+ }
561
+ const asAddition = { ...spec, fieldId: 'f_domain', label: 'domain' };
562
+ const added = readFieldSpec(draftIn, asAddition, path, 0);
563
+ if (added === undefined)
564
+ return undefined;
565
+ const { fieldId: _fieldId, label: _label, placement: _placement, parent: _parent, colSpan: _colSpan, annotations: _annotations, optionSource: _optionSource, members: _members, ...domain } = added;
566
+ const resolved = domain.primitive;
567
+ if (resolved === 'record') {
568
+ return fail(draftIn, `${path}.primitive`, 'a record’s members are its declaration: add a new record rather than retyping one under the members that depend on it');
569
+ }
570
+ return { ...domain, primitive: resolved };
571
+ }
572
+ //# sourceMappingURL=field.js.map