@azx-pbc/axiom-form-builder 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +231 -2
- package/dist/bridge/index.d.ts +12 -0
- package/dist/bridge/index.d.ts.map +1 -0
- package/dist/bridge/index.js +10 -0
- package/dist/bridge/index.js.map +1 -0
- package/dist/bridge/inspector-commands.d.ts +55 -0
- package/dist/bridge/inspector-commands.d.ts.map +1 -0
- package/dist/bridge/inspector-commands.js +532 -0
- package/dist/bridge/inspector-commands.js.map +1 -0
- package/dist/bridge/rule-context.d.ts +57 -0
- package/dist/bridge/rule-context.d.ts.map +1 -0
- package/dist/bridge/rule-context.js +302 -0
- package/dist/bridge/rule-context.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/inspector.d.ts +125 -0
- package/dist/inspector.d.ts.map +1 -0
- package/dist/inspector.js +2 -0
- package/dist/inspector.js.map +1 -0
- package/dist/reference/ReferencePicker.d.ts +59 -0
- package/dist/reference/ReferencePicker.d.ts.map +1 -0
- package/dist/reference/ReferencePicker.js +145 -0
- package/dist/reference/ReferencePicker.js.map +1 -0
- package/dist/reference/index.d.ts +13 -0
- package/dist/reference/index.d.ts.map +1 -0
- package/dist/reference/index.js +11 -0
- package/dist/reference/index.js.map +1 -0
- package/dist/reference/token.d.ts +44 -0
- package/dist/reference/token.d.ts.map +1 -0
- package/dist/reference/token.js +141 -0
- package/dist/reference/token.js.map +1 -0
- package/dist/reference/types.d.ts +49 -0
- package/dist/reference/types.d.ts.map +1 -0
- package/dist/reference/types.js +2 -0
- package/dist/reference/types.js.map +1 -0
- package/dist/rules/ConditionEditor.d.ts +38 -0
- package/dist/rules/ConditionEditor.d.ts.map +1 -0
- package/dist/rules/ConditionEditor.js +79 -0
- package/dist/rules/ConditionEditor.js.map +1 -0
- package/dist/rules/RuleBuilder.d.ts +76 -0
- package/dist/rules/RuleBuilder.d.ts.map +1 -0
- package/dist/rules/RuleBuilder.js +336 -0
- package/dist/rules/RuleBuilder.js.map +1 -0
- package/dist/rules/RuleList.d.ts +45 -0
- package/dist/rules/RuleList.d.ts.map +1 -0
- package/dist/rules/RuleList.js +62 -0
- package/dist/rules/RuleList.js.map +1 -0
- package/dist/rules/RuleMessageEditor.d.ts +38 -0
- package/dist/rules/RuleMessageEditor.d.ts.map +1 -0
- package/dist/rules/RuleMessageEditor.js +38 -0
- package/dist/rules/RuleMessageEditor.js.map +1 -0
- package/dist/rules/ValidationEditor.d.ts +60 -0
- package/dist/rules/ValidationEditor.d.ts.map +1 -0
- package/dist/rules/ValidationEditor.js +299 -0
- package/dist/rules/ValidationEditor.js.map +1 -0
- package/dist/rules/condition.d.ts +12 -0
- package/dist/rules/condition.d.ts.map +1 -0
- package/dist/rules/condition.js +46 -0
- package/dist/rules/condition.js.map +1 -0
- package/dist/rules/expression.d.ts +57 -0
- package/dist/rules/expression.d.ts.map +1 -0
- package/dist/rules/expression.js +286 -0
- package/dist/rules/expression.js.map +1 -0
- package/dist/rules/index.d.ts +28 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +19 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/messages.d.ts +64 -0
- package/dist/rules/messages.d.ts.map +1 -0
- package/dist/rules/messages.js +114 -0
- package/dist/rules/messages.js.map +1 -0
- package/dist/rules/operators.d.ts +25 -0
- package/dist/rules/operators.d.ts.map +1 -0
- package/dist/rules/operators.js +128 -0
- package/dist/rules/operators.js.map +1 -0
- package/dist/rules/sentence.d.ts +151 -0
- package/dist/rules/sentence.d.ts.map +1 -0
- package/dist/rules/sentence.js +527 -0
- package/dist/rules/sentence.js.map +1 -0
- package/dist/rules/templates.d.ts +163 -0
- package/dist/rules/templates.d.ts.map +1 -0
- package/dist/rules/templates.js +560 -0
- package/dist/rules/templates.js.map +1 -0
- package/dist/rules/types.d.ts +209 -0
- package/dist/rules/types.d.ts.map +1 -0
- package/dist/rules/types.js +2 -0
- package/dist/rules/types.js.map +1 -0
- package/dist/rules/validation-editor-api.d.ts +12 -0
- package/dist/rules/validation-editor-api.d.ts.map +1 -0
- package/dist/rules/validation-editor-api.js +12 -0
- package/dist/rules/validation-editor-api.js.map +1 -0
- package/dist/rules/validation.d.ts +27 -0
- package/dist/rules/validation.d.ts.map +1 -0
- package/dist/rules/validation.js +184 -0
- package/dist/rules/validation.js.map +1 -0
- package/dist/styles.css +900 -0
- package/package.json +65 -3
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { compileExpr, parseExpr, printExpr } from '@azx-pbc/axiom-compiler';
|
|
2
|
+
import { CURRENCY_CODE_PATTERN, DECIMAL_TEXT_PATTERN, INSTANT_PATTERN, INTEGER_TEXT_PATTERN, PLAIN_DATE_PATTERN, } from '@azx-pbc/axiom-runtime';
|
|
3
|
+
const MONEY_AMOUNT_PATTERN = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/;
|
|
4
|
+
/** The field a draft names, or `undefined`. */
|
|
5
|
+
export function fieldById(fields, fieldId) {
|
|
6
|
+
return fields.find((field) => field.fieldId === fieldId);
|
|
7
|
+
}
|
|
8
|
+
/** The table a draft names, or `undefined`. */
|
|
9
|
+
export function tableById(tables, tableId) {
|
|
10
|
+
return tables.find((table) => table.tableId === tableId);
|
|
11
|
+
}
|
|
12
|
+
/** The path one field is read by, honouring a repeater's binder (`r.f_qty`). */
|
|
13
|
+
export function fieldPath(fieldId, context) {
|
|
14
|
+
const prefix = context.pathPrefix;
|
|
15
|
+
return { kind: 'path', path: prefix === undefined ? fieldId : `${prefix}.${fieldId}` };
|
|
16
|
+
}
|
|
17
|
+
/** A bare table identifier: a dataset built-in's first operand, never a read. */
|
|
18
|
+
export function tablePath(tableId) {
|
|
19
|
+
return { kind: 'path', path: tableId };
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parses one authored operand against the field it is compared with.
|
|
23
|
+
*
|
|
24
|
+
* The domain is the field's, not a guess from the text: `"1.5"` typed against a decimal field is
|
|
25
|
+
* the decimal 1.5, and the same text against a text field is the string. A value outside the
|
|
26
|
+
* domain is reported here rather than handed to the compiler, so the editor can point at the
|
|
27
|
+
* operand the author typed.
|
|
28
|
+
*/
|
|
29
|
+
export function literalFor(field, text) {
|
|
30
|
+
switch (field.primitive) {
|
|
31
|
+
case 'string':
|
|
32
|
+
return { ok: true, node: { kind: 'literal', domain: 'string', value: text } };
|
|
33
|
+
case 'boolean': {
|
|
34
|
+
if (text === 'true') {
|
|
35
|
+
return { ok: true, node: { kind: 'literal', domain: 'boolean', value: true } };
|
|
36
|
+
}
|
|
37
|
+
if (text === 'false') {
|
|
38
|
+
return { ok: true, node: { kind: 'literal', domain: 'boolean', value: false } };
|
|
39
|
+
}
|
|
40
|
+
return invalid(field, text, 'a yes/no value is written `true` or `false`');
|
|
41
|
+
}
|
|
42
|
+
case 'integer': {
|
|
43
|
+
const trimmed = text.trim();
|
|
44
|
+
if (!INTEGER_TEXT_PATTERN.test(trimmed)) {
|
|
45
|
+
return invalid(field, text, 'a whole number has no fraction, no leading zero and no `-0`');
|
|
46
|
+
}
|
|
47
|
+
const value = Number(trimmed);
|
|
48
|
+
if (!Number.isSafeInteger(value)) {
|
|
49
|
+
return invalid(field, text, 'the number is outside the safe integer range');
|
|
50
|
+
}
|
|
51
|
+
return { ok: true, node: { kind: 'literal', domain: 'integer', value } };
|
|
52
|
+
}
|
|
53
|
+
case 'decimal': {
|
|
54
|
+
const trimmed = text.trim();
|
|
55
|
+
if (!DECIMAL_TEXT_PATTERN.test(trimmed)) {
|
|
56
|
+
return invalid(field, text, 'a decimal has no exponent, no leading zero and no trailing fractional zero');
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, node: { kind: 'literal', domain: 'decimal', value: trimmed } };
|
|
59
|
+
}
|
|
60
|
+
case 'quantity': {
|
|
61
|
+
// A quantity is a decimal with a unit domain: the literal is spelled like a decimal, and
|
|
62
|
+
// the unit the field's domain admits is the compiler's check rather than this parser's.
|
|
63
|
+
const trimmed = text.trim();
|
|
64
|
+
if (!DECIMAL_TEXT_PATTERN.test(trimmed)) {
|
|
65
|
+
return invalid(field, text, 'a quantity has no exponent, no leading zero and no trailing fractional zero');
|
|
66
|
+
}
|
|
67
|
+
return { ok: true, node: { kind: 'literal', domain: 'quantity', value: trimmed } };
|
|
68
|
+
}
|
|
69
|
+
case 'money':
|
|
70
|
+
return moneyLiteral(field, text);
|
|
71
|
+
case 'date': {
|
|
72
|
+
const trimmed = text.trim();
|
|
73
|
+
if (!PLAIN_DATE_PATTERN.test(trimmed)) {
|
|
74
|
+
return invalid(field, text, 'a date is written `YYYY-MM-DD`');
|
|
75
|
+
}
|
|
76
|
+
return { ok: true, node: { kind: 'literal', domain: 'date', value: trimmed } };
|
|
77
|
+
}
|
|
78
|
+
case 'instant': {
|
|
79
|
+
const trimmed = text.trim();
|
|
80
|
+
if (!INSTANT_PATTERN.test(trimmed)) {
|
|
81
|
+
return invalid(field, text, 'an instant is written `YYYY-MM-DDTHH:mm:ss.sssZ`');
|
|
82
|
+
}
|
|
83
|
+
return { ok: true, node: { kind: 'literal', domain: 'instant', value: trimmed } };
|
|
84
|
+
}
|
|
85
|
+
case 'media_ref':
|
|
86
|
+
case 'signature_ref':
|
|
87
|
+
case 'timeslot':
|
|
88
|
+
case 'time':
|
|
89
|
+
case 'duration':
|
|
90
|
+
case 'address':
|
|
91
|
+
case 'coordinate':
|
|
92
|
+
case 'record':
|
|
93
|
+
case 'array':
|
|
94
|
+
return {
|
|
95
|
+
ok: false,
|
|
96
|
+
problem: { code: 'unsupported-primitive', primitive: field.primitive },
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function invalid(field, text, detail) {
|
|
101
|
+
return {
|
|
102
|
+
ok: false,
|
|
103
|
+
problem: { code: 'invalid-literal', fieldId: field.fieldId, text, detail },
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function moneyLiteral(field, text) {
|
|
107
|
+
const { currency, scale } = field;
|
|
108
|
+
if (currency === undefined || scale === undefined || !CURRENCY_CODE_PATTERN.test(currency)) {
|
|
109
|
+
return {
|
|
110
|
+
ok: false,
|
|
111
|
+
problem: {
|
|
112
|
+
code: 'invalid-literal',
|
|
113
|
+
fieldId: field.fieldId,
|
|
114
|
+
text,
|
|
115
|
+
detail: 'the money field declares no currency and scale to spell an amount with',
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const minor = amountToMinor(text, scale);
|
|
120
|
+
if (!minor.ok)
|
|
121
|
+
return invalid(field, text, minor.detail);
|
|
122
|
+
return {
|
|
123
|
+
ok: true,
|
|
124
|
+
node: {
|
|
125
|
+
kind: 'literal',
|
|
126
|
+
domain: 'money',
|
|
127
|
+
value: { minor: minor.minor, currency, scale },
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The minor-unit integer for an amount written in major units, exactly.
|
|
133
|
+
*
|
|
134
|
+
* String arithmetic, not `Number`: `19.99 * 100` is binary floating point, and a money literal
|
|
135
|
+
* that silently became `1998.9999999999998` would not be the value the author typed. A fraction
|
|
136
|
+
* longer than the declared scale is refused rather than rounded, because a literal has no rounding
|
|
137
|
+
* mode to state.
|
|
138
|
+
*/
|
|
139
|
+
function amountToMinor(text, scale) {
|
|
140
|
+
const trimmed = text.trim();
|
|
141
|
+
if (!Number.isInteger(scale) || scale < 0 || scale > 6) {
|
|
142
|
+
return { ok: false, detail: 'the declared money scale is not an integer from 0 to 6' };
|
|
143
|
+
}
|
|
144
|
+
if (!MONEY_AMOUNT_PATTERN.test(trimmed)) {
|
|
145
|
+
return {
|
|
146
|
+
ok: false,
|
|
147
|
+
detail: 'write the amount as a decimal without an exponent, such as `12.50`',
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const negative = trimmed.startsWith('-');
|
|
151
|
+
const unsigned = negative ? trimmed.slice(1) : trimmed;
|
|
152
|
+
const [whole = '0', fraction = ''] = unsigned.split('.');
|
|
153
|
+
if (fraction.length > scale) {
|
|
154
|
+
return {
|
|
155
|
+
ok: false,
|
|
156
|
+
detail: `the amount has more than ${String(scale)} fraction digit${scale === 1 ? '' : 's'}`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const padded = `${whole}${fraction.padEnd(scale, '0')}`;
|
|
160
|
+
const digits = padded.replace(/^0+/, '');
|
|
161
|
+
if (digits.length === 0)
|
|
162
|
+
return { ok: true, minor: '0' };
|
|
163
|
+
return { ok: true, minor: negative ? `-${digits}` : digits };
|
|
164
|
+
}
|
|
165
|
+
/** One operand's node: a typed literal or the declared path of another field. */
|
|
166
|
+
export function operandNode(operand, field, context) {
|
|
167
|
+
if (operand.kind === 'field') {
|
|
168
|
+
if (fieldById(context.fields, operand.fieldId) === undefined) {
|
|
169
|
+
return { ok: false, problem: { code: 'missing-field', fieldId: operand.fieldId } };
|
|
170
|
+
}
|
|
171
|
+
return printNode(fieldPath(operand.fieldId, context));
|
|
172
|
+
}
|
|
173
|
+
const literal = literalFor(field, operand.text);
|
|
174
|
+
if (!literal.ok)
|
|
175
|
+
return { ok: false, problem: literal.problem };
|
|
176
|
+
return printNode(literal.node);
|
|
177
|
+
}
|
|
178
|
+
/** Prints one node through the compiler's printer, the only Expr v1 source authority. */
|
|
179
|
+
export function printNode(node) {
|
|
180
|
+
const printed = printExpr(node);
|
|
181
|
+
if (!printed.ok) {
|
|
182
|
+
return {
|
|
183
|
+
ok: false,
|
|
184
|
+
problem: { code: 'unprintable', detail: `${printed.reason}: ${printed.detail}` },
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return { ok: true, node, source: printed.source };
|
|
188
|
+
}
|
|
189
|
+
/** The compiler's declarations for a context, so a draft is checked against its own fields. */
|
|
190
|
+
function declarationsOf(context) {
|
|
191
|
+
return {
|
|
192
|
+
fields: context.fields.map(compiledField),
|
|
193
|
+
...(context.tables === undefined ? {} : { datasets: context.tables.map(datasetDeclaration) }),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function compiledField(field) {
|
|
197
|
+
const nested = nestedFields(field);
|
|
198
|
+
const items = fieldItem(field);
|
|
199
|
+
return {
|
|
200
|
+
fieldId: field.fieldId,
|
|
201
|
+
primitive: field.primitive,
|
|
202
|
+
...(field.currency === undefined ? {} : { currency: field.currency }),
|
|
203
|
+
...(field.scale === undefined ? {} : { scale: field.scale }),
|
|
204
|
+
...(nested === undefined ? {} : { fields: nested }),
|
|
205
|
+
...(items === undefined ? {} : { items }),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function nestedFields(field) {
|
|
209
|
+
if (field.columns === undefined)
|
|
210
|
+
return undefined;
|
|
211
|
+
return field.columns.map((column) => ({
|
|
212
|
+
fieldId: column.fieldId,
|
|
213
|
+
primitive: column.primitive,
|
|
214
|
+
...(column.currency === undefined ? {} : { currency: column.currency }),
|
|
215
|
+
...(column.scale === undefined ? {} : { scale: column.scale }),
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
function fieldItem(field) {
|
|
219
|
+
if (field.itemPrimitive === undefined)
|
|
220
|
+
return undefined;
|
|
221
|
+
return {
|
|
222
|
+
primitive: field.itemPrimitive,
|
|
223
|
+
...(field.currency === undefined ? {} : { currency: field.currency }),
|
|
224
|
+
...(field.scale === undefined ? {} : { scale: field.scale }),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function datasetDeclaration(table) {
|
|
228
|
+
const columns = table.columns?.map((column) => ({
|
|
229
|
+
columnId: column.columnId,
|
|
230
|
+
primitive: column.primitive,
|
|
231
|
+
role: column.role,
|
|
232
|
+
}));
|
|
233
|
+
return {
|
|
234
|
+
tableId: table.tableId,
|
|
235
|
+
kind: table.kind,
|
|
236
|
+
binding: table.binding,
|
|
237
|
+
...(table.hitPolicy === undefined ? {} : { hitPolicy: table.hitPolicy }),
|
|
238
|
+
...(columns === undefined ? {} : { columns }),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** The literal `true`, the expression of a rule with no condition. */
|
|
242
|
+
export function literalTrue() {
|
|
243
|
+
return { kind: 'literal', domain: 'boolean', value: true };
|
|
244
|
+
}
|
|
245
|
+
/** Parses one source into a node, or reports the parse diagnostic the author can fix. */
|
|
246
|
+
export function parseNode(source) {
|
|
247
|
+
const parsed = parseExpr(source);
|
|
248
|
+
if (!parsed.ok) {
|
|
249
|
+
return {
|
|
250
|
+
ok: false,
|
|
251
|
+
problem: {
|
|
252
|
+
code: 'unprintable',
|
|
253
|
+
detail: parsed.diagnostics[0]?.detail ?? 'the expression does not parse',
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return { ok: true, node: parsed.node, source };
|
|
258
|
+
}
|
|
259
|
+
/** Parses a rule's stored source, for a reader that displays rather than edits it. */
|
|
260
|
+
export function parseSource(source) {
|
|
261
|
+
return parseExpr(source);
|
|
262
|
+
}
|
|
263
|
+
/** The canonical source of one node, or `undefined` when it has no source form. */
|
|
264
|
+
export function sourceOf(node) {
|
|
265
|
+
const printed = printNode(node);
|
|
266
|
+
return printed.ok ? printed.source : undefined;
|
|
267
|
+
}
|
|
268
|
+
/** Compiles one source against the context's declarations. */
|
|
269
|
+
export function compileSource(source, context) {
|
|
270
|
+
const result = compileExpr(source, declarationsOf(context));
|
|
271
|
+
return result.ok ? { ok: true } : { ok: false, diagnostics: result.diagnostics };
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The context with a row binder, for a condition over a repeating table's rows.
|
|
275
|
+
*
|
|
276
|
+
* The fields become the table's columns and every path is prefixed with the binder, so the same
|
|
277
|
+
* validation editor that reads `f_qty` at record level reads `r.f_qty` inside a comprehension.
|
|
278
|
+
*/
|
|
279
|
+
export function rowContext(table, tables) {
|
|
280
|
+
return {
|
|
281
|
+
fields: table.columns ?? [],
|
|
282
|
+
...(tables === undefined ? {} : { tables }),
|
|
283
|
+
pathPrefix: 'r',
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=expression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../../src/rules/expression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAE5E,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAoBhC,MAAM,oBAAoB,GAAG,oCAAoC,CAAC;AAElE,+CAA+C;AAC/C,MAAM,UAAU,SAAS,CAAC,MAA4B,EAAE,OAAe;IACrE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,SAAS,CAAC,MAA4B,EAAE,OAAe;IACrE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,OAAoB;IAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAClC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,EAAE,EAAE,CAAC;AACzF,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AACzC,CAAC;AAOD;;;;;;;GAOG;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AAE,KAAK,CAAC,OAAO,IAAI,EAAE;QAC3B,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3C,UAAU,EAAE,GAAG;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import { compileExpr, parseExpr, printExpr } from '@azx-pbc/axiom-compiler';\nimport type { CompileExprResult, ParseExprResult, PrintResult } from '@azx-pbc/axiom-compiler';\nimport {\n CURRENCY_CODE_PATTERN,\n DECIMAL_TEXT_PATTERN,\n INSTANT_PATTERN,\n INTEGER_TEXT_PATTERN,\n PLAIN_DATE_PATTERN,\n} from '@azx-pbc/axiom-runtime';\nimport type {\n CompiledField,\n DatasetColumn,\n DatasetDeclaration,\n ExpressionDeclarations,\n ExprNode,\n FieldItem,\n LiteralNode,\n} from '@azx-pbc/axiom-runtime';\nimport type {\n CompileCheck,\n ExpressionBuild,\n ExpressionProblem,\n RuleContext,\n RuleField,\n RuleTable,\n ValueOperand,\n} from './types.js';\n\nconst MONEY_AMOUNT_PATTERN = /^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$/;\n\n/** The field a draft names, or `undefined`. */\nexport function fieldById(fields: readonly RuleField[], fieldId: string): RuleField | undefined {\n return fields.find((field) => field.fieldId === fieldId);\n}\n\n/** The table a draft names, or `undefined`. */\nexport function tableById(tables: readonly RuleTable[], tableId: string): RuleTable | undefined {\n return tables.find((table) => table.tableId === tableId);\n}\n\n/** The path one field is read by, honouring a repeater's binder (`r.f_qty`). */\nexport function fieldPath(fieldId: string, context: RuleContext): ExprNode {\n const prefix = context.pathPrefix;\n return { kind: 'path', path: prefix === undefined ? fieldId : `${prefix}.${fieldId}` };\n}\n\n/** A bare table identifier: a dataset built-in's first operand, never a read. */\nexport function tablePath(tableId: string): ExprNode {\n return { kind: 'path', path: tableId };\n}\n\n/** A literal node of the domain the field declares. */\nexport type LiteralBuild =\n | { readonly ok: true; readonly node: LiteralNode }\n | { readonly ok: false; readonly problem: ExpressionProblem };\n\n/**\n * Parses one authored operand against the field it is compared with.\n *\n * The domain is the field's, not a guess from the text: `\"1.5\"` typed against a decimal field is\n * the decimal 1.5, and the same text against a text field is the string. A value outside the\n * domain is reported here rather than handed to the compiler, so the editor can point at the\n * operand the author typed.\n */\nexport function literalFor(field: RuleField, text: string): LiteralBuild {\n switch (field.primitive) {\n case 'string':\n return { ok: true, node: { kind: 'literal', domain: 'string', value: text } };\n case 'boolean': {\n if (text === 'true') {\n return { ok: true, node: { kind: 'literal', domain: 'boolean', value: true } };\n }\n if (text === 'false') {\n return { ok: true, node: { kind: 'literal', domain: 'boolean', value: false } };\n }\n return invalid(field, text, 'a yes/no value is written `true` or `false`');\n }\n case 'integer': {\n const trimmed = text.trim();\n if (!INTEGER_TEXT_PATTERN.test(trimmed)) {\n return invalid(field, text, 'a whole number has no fraction, no leading zero and no `-0`');\n }\n const value = Number(trimmed);\n if (!Number.isSafeInteger(value)) {\n return invalid(field, text, 'the number is outside the safe integer range');\n }\n return { ok: true, node: { kind: 'literal', domain: 'integer', value } };\n }\n case 'decimal': {\n const trimmed = text.trim();\n if (!DECIMAL_TEXT_PATTERN.test(trimmed)) {\n return invalid(\n field,\n text,\n 'a decimal has no exponent, no leading zero and no trailing fractional zero',\n );\n }\n return { ok: true, node: { kind: 'literal', domain: 'decimal', value: trimmed } };\n }\n case 'quantity': {\n // A quantity is a decimal with a unit domain: the literal is spelled like a decimal, and\n // the unit the field's domain admits is the compiler's check rather than this parser's.\n const trimmed = text.trim();\n if (!DECIMAL_TEXT_PATTERN.test(trimmed)) {\n return invalid(\n field,\n text,\n 'a quantity has no exponent, no leading zero and no trailing fractional zero',\n );\n }\n return { ok: true, node: { kind: 'literal', domain: 'quantity', value: trimmed } };\n }\n case 'money':\n return moneyLiteral(field, text);\n case 'date': {\n const trimmed = text.trim();\n if (!PLAIN_DATE_PATTERN.test(trimmed)) {\n return invalid(field, text, 'a date is written `YYYY-MM-DD`');\n }\n return { ok: true, node: { kind: 'literal', domain: 'date', value: trimmed } };\n }\n case 'instant': {\n const trimmed = text.trim();\n if (!INSTANT_PATTERN.test(trimmed)) {\n return invalid(field, text, 'an instant is written `YYYY-MM-DDTHH:mm:ss.sssZ`');\n }\n return { ok: true, node: { kind: 'literal', domain: 'instant', value: trimmed } };\n }\n case 'media_ref':\n case 'signature_ref':\n case 'timeslot':\n case 'time':\n case 'duration':\n case 'address':\n case 'coordinate':\n case 'record':\n case 'array':\n return {\n ok: false,\n problem: { code: 'unsupported-primitive', primitive: field.primitive },\n };\n }\n}\n\nfunction invalid(field: RuleField, text: string, detail: string): LiteralBuild {\n return {\n ok: false,\n problem: { code: 'invalid-literal', fieldId: field.fieldId, text, detail },\n };\n}\n\nfunction moneyLiteral(field: RuleField, text: string): LiteralBuild {\n const { currency, scale } = field;\n if (currency === undefined || scale === undefined || !CURRENCY_CODE_PATTERN.test(currency)) {\n return {\n ok: false,\n problem: {\n code: 'invalid-literal',\n fieldId: field.fieldId,\n text,\n detail: 'the money field declares no currency and scale to spell an amount with',\n },\n };\n }\n const minor = amountToMinor(text, scale);\n if (!minor.ok) return invalid(field, text, minor.detail);\n return {\n ok: true,\n node: {\n kind: 'literal',\n domain: 'money',\n value: { minor: minor.minor, currency, scale },\n },\n };\n}\n\ntype MinorResult =\n | { readonly ok: true; readonly minor: string }\n | { readonly ok: false; readonly detail: string };\n\n/**\n * The minor-unit integer for an amount written in major units, exactly.\n *\n * String arithmetic, not `Number`: `19.99 * 100` is binary floating point, and a money literal\n * that silently became `1998.9999999999998` would not be the value the author typed. A fraction\n * longer than the declared scale is refused rather than rounded, because a literal has no rounding\n * mode to state.\n */\nfunction amountToMinor(text: string, scale: number): MinorResult {\n const trimmed = text.trim();\n if (!Number.isInteger(scale) || scale < 0 || scale > 6) {\n return { ok: false, detail: 'the declared money scale is not an integer from 0 to 6' };\n }\n if (!MONEY_AMOUNT_PATTERN.test(trimmed)) {\n return {\n ok: false,\n detail: 'write the amount as a decimal without an exponent, such as `12.50`',\n };\n }\n const negative = trimmed.startsWith('-');\n const unsigned = negative ? trimmed.slice(1) : trimmed;\n const [whole = '0', fraction = ''] = unsigned.split('.');\n if (fraction.length > scale) {\n return {\n ok: false,\n detail: `the amount has more than ${String(scale)} fraction digit${scale === 1 ? '' : 's'}`,\n };\n }\n const padded = `${whole}${fraction.padEnd(scale, '0')}`;\n const digits = padded.replace(/^0+/, '');\n if (digits.length === 0) return { ok: true, minor: '0' };\n return { ok: true, minor: negative ? `-${digits}` : digits };\n}\n\n/** One operand's node: a typed literal or the declared path of another field. */\nexport function operandNode(\n operand: ValueOperand,\n field: RuleField,\n context: RuleContext,\n): ExpressionBuild {\n if (operand.kind === 'field') {\n if (fieldById(context.fields, operand.fieldId) === undefined) {\n return { ok: false, problem: { code: 'missing-field', fieldId: operand.fieldId } };\n }\n return printNode(fieldPath(operand.fieldId, context));\n }\n const literal = literalFor(field, operand.text);\n if (!literal.ok) return { ok: false, problem: literal.problem };\n return printNode(literal.node);\n}\n\n/** Prints one node through the compiler's printer, the only Expr v1 source authority. */\nexport function printNode(node: ExprNode): ExpressionBuild {\n const printed: PrintResult = printExpr(node);\n if (!printed.ok) {\n return {\n ok: false,\n problem: { code: 'unprintable', detail: `${printed.reason}: ${printed.detail}` },\n };\n }\n return { ok: true, node, source: printed.source };\n}\n\n/** The compiler's declarations for a context, so a draft is checked against its own fields. */\nfunction declarationsOf(context: RuleContext): ExpressionDeclarations {\n return {\n fields: context.fields.map(compiledField),\n ...(context.tables === undefined ? {} : { datasets: context.tables.map(datasetDeclaration) }),\n };\n}\n\nfunction compiledField(field: RuleField): CompiledField {\n const nested = nestedFields(field);\n const items = fieldItem(field);\n return {\n fieldId: field.fieldId,\n primitive: field.primitive,\n ...(field.currency === undefined ? {} : { currency: field.currency }),\n ...(field.scale === undefined ? {} : { scale: field.scale }),\n ...(nested === undefined ? {} : { fields: nested }),\n ...(items === undefined ? {} : { items }),\n };\n}\n\nfunction nestedFields(field: RuleField): readonly CompiledField[] | undefined {\n if (field.columns === undefined) return undefined;\n return field.columns.map((column) => ({\n fieldId: column.fieldId,\n primitive: column.primitive,\n ...(column.currency === undefined ? {} : { currency: column.currency }),\n ...(column.scale === undefined ? {} : { scale: column.scale }),\n }));\n}\n\nfunction fieldItem(field: RuleField): FieldItem | undefined {\n if (field.itemPrimitive === undefined) return undefined;\n return {\n primitive: field.itemPrimitive,\n ...(field.currency === undefined ? {} : { currency: field.currency }),\n ...(field.scale === undefined ? {} : { scale: field.scale }),\n };\n}\n\nfunction datasetDeclaration(table: RuleTable): DatasetDeclaration {\n const columns: readonly DatasetColumn[] | undefined = table.columns?.map((column) => ({\n columnId: column.columnId,\n primitive: column.primitive,\n role: column.role,\n }));\n return {\n tableId: table.tableId,\n kind: table.kind,\n binding: table.binding,\n ...(table.hitPolicy === undefined ? {} : { hitPolicy: table.hitPolicy }),\n ...(columns === undefined ? {} : { columns }),\n };\n}\n\n/** The literal `true`, the expression of a rule with no condition. */\nexport function literalTrue(): LiteralNode {\n return { kind: 'literal', domain: 'boolean', value: true };\n}\n\n/** Parses one source into a node, or reports the parse diagnostic the author can fix. */\nexport function parseNode(\n source: string,\n):\n | { readonly ok: true; readonly node: ExprNode; readonly source: string }\n | { readonly ok: false; readonly problem: ExpressionProblem } {\n const parsed: ParseExprResult = parseExpr(source);\n if (!parsed.ok) {\n return {\n ok: false,\n problem: {\n code: 'unprintable',\n detail: parsed.diagnostics[0]?.detail ?? 'the expression does not parse',\n },\n };\n }\n return { ok: true, node: parsed.node, source };\n}\n\n/** Parses a rule's stored source, for a reader that displays rather than edits it. */\nexport function parseSource(source: string): ParseExprResult {\n return parseExpr(source);\n}\n\n/** The canonical source of one node, or `undefined` when it has no source form. */\nexport function sourceOf(node: ExprNode): string | undefined {\n const printed = printNode(node);\n return printed.ok ? printed.source : undefined;\n}\n\n/** Compiles one source against the context's declarations. */\nexport function compileSource(source: string, context: RuleContext): CompileCheck {\n const result: CompileExprResult = compileExpr(source, declarationsOf(context));\n return result.ok ? { ok: true } : { ok: false, diagnostics: result.diagnostics };\n}\n\n/**\n * The context with a row binder, for a condition over a repeating table's rows.\n *\n * The fields become the table's columns and every path is prefixed with the binder, so the same\n * validation editor that reads `f_qty` at record level reads `r.f_qty` inside a comprehension.\n */\nexport function rowContext(\n table: RuleField,\n tables: readonly RuleTable[] | undefined,\n): RuleContext {\n return {\n fields: table.columns ?? [],\n ...(tables === undefined ? {} : { tables }),\n pathPrefix: 'r',\n };\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rule-authoring module's door.
|
|
3
|
+
*
|
|
4
|
+
* The rule surface is three editors and a list, plus the two projections a host needs to render
|
|
5
|
+
* one: the sentence a rule reads as (`ruleSentence`) and the catalogue rows its messages live in
|
|
6
|
+
* (`messageRows`, `missingMessageLocales`, `copyMessageFromDefault`). The expression builders,
|
|
7
|
+
* operator tables and template catalogue behind them are internal: a host that needs one of those
|
|
8
|
+
* is authoring a different product, and the compiler's Expr entry is where the vocabulary lives.
|
|
9
|
+
*/
|
|
10
|
+
export { ConditionEditor } from './ConditionEditor.js';
|
|
11
|
+
export type { ConditionEditorLabels, ConditionEditorProps } from './ConditionEditor.js';
|
|
12
|
+
export { RuleBuilder } from './RuleBuilder.js';
|
|
13
|
+
export type { RuleBuilderLabels, RuleBuilderProps } from './RuleBuilder.js';
|
|
14
|
+
export { RuleList } from './RuleList.js';
|
|
15
|
+
export type { RuleListLabels, RuleListProps } from './RuleList.js';
|
|
16
|
+
export { RuleMessageEditor } from './RuleMessageEditor.js';
|
|
17
|
+
export type { RuleMessageEditorProps, RuleMessageLabels } from './RuleMessageEditor.js';
|
|
18
|
+
export { ValidationEditor } from './ValidationEditor.js';
|
|
19
|
+
export type { ValidationEditorLabels, ValidationEditorProps } from './ValidationEditor.js';
|
|
20
|
+
export { ruleSentence, DEFAULT_RULE_SENTENCE_LABELS } from './sentence.js';
|
|
21
|
+
export type { RuleSentenceLabels } from './sentence.js';
|
|
22
|
+
export { RULE_TEMPLATES, ruleTemplateNeedsMessage } from './templates.js';
|
|
23
|
+
export { defaultOperatorFor, defaultRuleTemplateDraft, defaultValidationDraft, validationExpression, withValidationField, withValidationOperator, } from './validation-editor-api.js';
|
|
24
|
+
export type { EmittedRule, RuleProblem, RuleTemplateDefinition, RuleTemplateDraft, RuleTemplateId, } from './templates.js';
|
|
25
|
+
export { copyMessageFromDefault, messageRows, missingMessageLocales, renameMessageKey, } from './messages.js';
|
|
26
|
+
export type { MessageCatalogue, MessageKeyRename, MessageRow } from './messages.js';
|
|
27
|
+
export type { ConditionDraft, ExpressionProblem, ReadableRule, RuleContext, RuleField, RuleSection, RuleStatus, RuleTable, RuleTableColumn, ValidationDraft, ValidationOperator, } from './types.js';
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAC3E,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACpF,YAAY,EACV,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rule-authoring module's door.
|
|
3
|
+
*
|
|
4
|
+
* The rule surface is three editors and a list, plus the two projections a host needs to render
|
|
5
|
+
* one: the sentence a rule reads as (`ruleSentence`) and the catalogue rows its messages live in
|
|
6
|
+
* (`messageRows`, `missingMessageLocales`, `copyMessageFromDefault`). The expression builders,
|
|
7
|
+
* operator tables and template catalogue behind them are internal: a host that needs one of those
|
|
8
|
+
* is authoring a different product, and the compiler's Expr entry is where the vocabulary lives.
|
|
9
|
+
*/
|
|
10
|
+
export { ConditionEditor } from './ConditionEditor.js';
|
|
11
|
+
export { RuleBuilder } from './RuleBuilder.js';
|
|
12
|
+
export { RuleList } from './RuleList.js';
|
|
13
|
+
export { RuleMessageEditor } from './RuleMessageEditor.js';
|
|
14
|
+
export { ValidationEditor } from './ValidationEditor.js';
|
|
15
|
+
export { ruleSentence, DEFAULT_RULE_SENTENCE_LABELS } from './sentence.js';
|
|
16
|
+
export { RULE_TEMPLATES, ruleTemplateNeedsMessage } from './templates.js';
|
|
17
|
+
export { defaultOperatorFor, defaultRuleTemplateDraft, defaultValidationDraft, validationExpression, withValidationField, withValidationOperator, } from './validation-editor-api.js';
|
|
18
|
+
export { copyMessageFromDefault, messageRows, missingMessageLocales, renameMessageKey, } from './messages.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EACL,sBAAsB,EACtB,WAAW,EACX,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,eAAe,CAAC","sourcesContent":["/**\n * The rule-authoring module's door.\n *\n * The rule surface is three editors and a list, plus the two projections a host needs to render\n * one: the sentence a rule reads as (`ruleSentence`) and the catalogue rows its messages live in\n * (`messageRows`, `missingMessageLocales`, `copyMessageFromDefault`). The expression builders,\n * operator tables and template catalogue behind them are internal: a host that needs one of those\n * is authoring a different product, and the compiler's Expr entry is where the vocabulary lives.\n */\nexport { ConditionEditor } from './ConditionEditor.js';\nexport type { ConditionEditorLabels, ConditionEditorProps } from './ConditionEditor.js';\nexport { RuleBuilder } from './RuleBuilder.js';\nexport type { RuleBuilderLabels, RuleBuilderProps } from './RuleBuilder.js';\nexport { RuleList } from './RuleList.js';\nexport type { RuleListLabels, RuleListProps } from './RuleList.js';\nexport { RuleMessageEditor } from './RuleMessageEditor.js';\nexport type { RuleMessageEditorProps, RuleMessageLabels } from './RuleMessageEditor.js';\nexport { ValidationEditor } from './ValidationEditor.js';\nexport type { ValidationEditorLabels, ValidationEditorProps } from './ValidationEditor.js';\nexport { ruleSentence, DEFAULT_RULE_SENTENCE_LABELS } from './sentence.js';\nexport type { RuleSentenceLabels } from './sentence.js';\nexport { RULE_TEMPLATES, ruleTemplateNeedsMessage } from './templates.js';\nexport {\n defaultOperatorFor,\n defaultRuleTemplateDraft,\n defaultValidationDraft,\n validationExpression,\n withValidationField,\n withValidationOperator,\n} from './validation-editor-api.js';\nexport type {\n EmittedRule,\n RuleProblem,\n RuleTemplateDefinition,\n RuleTemplateDraft,\n RuleTemplateId,\n} from './templates.js';\nexport {\n copyMessageFromDefault,\n messageRows,\n missingMessageLocales,\n renameMessageKey,\n} from './messages.js';\nexport type { MessageCatalogue, MessageKeyRename, MessageRow } from './messages.js';\nexport type {\n ConditionDraft,\n ExpressionProblem,\n ReadableRule,\n RuleContext,\n RuleField,\n RuleSection,\n RuleStatus,\n RuleTable,\n RuleTableColumn,\n ValidationDraft,\n ValidationOperator,\n} from './types.js';\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** The i18n view a rule message editor reads: declared locales and their message text. */
|
|
2
|
+
export interface MessageCatalogue {
|
|
3
|
+
readonly locales: readonly string[];
|
|
4
|
+
readonly defaultLocale: string;
|
|
5
|
+
readonly messages: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
6
|
+
}
|
|
7
|
+
/** One locale's state for one message key. */
|
|
8
|
+
export interface MessageRow {
|
|
9
|
+
readonly locale: string;
|
|
10
|
+
/** The text stored for the locale; absent when the locale has none. */
|
|
11
|
+
readonly text?: string;
|
|
12
|
+
/** Whether the locale has no non-blank text for this key. */
|
|
13
|
+
readonly missing: boolean;
|
|
14
|
+
readonly isDefault: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** The text a locale resolves to, and where it came from. */
|
|
17
|
+
export interface ResolvedMessage {
|
|
18
|
+
readonly text: string | undefined;
|
|
19
|
+
readonly source: 'locale' | 'default' | 'missing';
|
|
20
|
+
readonly locale: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolves one message key for one locale.
|
|
24
|
+
*
|
|
25
|
+
* The order is the document's: the exact locale, then its language prefix (`pt` for `pt-PT`),
|
|
26
|
+
* then the document default. `source` states which answered, so an editor can flag text that is
|
|
27
|
+
* only a fallback instead of presenting it as a translation.
|
|
28
|
+
*/
|
|
29
|
+
export declare function translateMessage(catalogue: MessageCatalogue, messageKey: string, locale?: string): ResolvedMessage;
|
|
30
|
+
/** Every declared locale's state for one message key, in the catalogue's locale order. */
|
|
31
|
+
export declare function messageRows(catalogue: MessageCatalogue, messageKey: string): readonly MessageRow[];
|
|
32
|
+
/** The declared locales that have no text for one key. */
|
|
33
|
+
export declare function missingMessageLocales(catalogue: MessageCatalogue, messageKey: string): readonly string[];
|
|
34
|
+
/** Whether one key is complete across every declared locale. */
|
|
35
|
+
export declare function messageComplete(catalogue: MessageCatalogue, messageKey: string): boolean;
|
|
36
|
+
/** A new catalogue with one locale's text set for one key. */
|
|
37
|
+
export declare function setMessageText(catalogue: MessageCatalogue, messageKey: string, locale: string, text: string): MessageCatalogue;
|
|
38
|
+
/**
|
|
39
|
+
* Copies the document default's text into one locale, or into every locale missing text.
|
|
40
|
+
*
|
|
41
|
+
* The copy is explicit and leaves every locale that already has text alone, so an editor's
|
|
42
|
+
* "copy from the document default" cannot overwrite a translation the author wrote.
|
|
43
|
+
*/
|
|
44
|
+
export declare function copyMessageFromDefault(catalogue: MessageCatalogue, messageKey: string, locale?: string): MessageCatalogue;
|
|
45
|
+
/** Why a message-key rename did not happen. */
|
|
46
|
+
type MessageKeyRenameRefusal = 'empty' | 'collision';
|
|
47
|
+
/** The outcome of renaming a message key: the new catalogue, or the refusal. */
|
|
48
|
+
export type MessageKeyRename = {
|
|
49
|
+
readonly ok: true;
|
|
50
|
+
readonly catalogue: MessageCatalogue;
|
|
51
|
+
} | {
|
|
52
|
+
readonly ok: false;
|
|
53
|
+
readonly reason: MessageKeyRenameRefusal;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Renames one message key, carrying its text to the new name.
|
|
57
|
+
*
|
|
58
|
+
* A collision is refused rather than merged: two rules sharing a key would make one message
|
|
59
|
+
* silently overwrite the other's translations, which is a decision for the author, not for a
|
|
60
|
+
* keystroke in the key input.
|
|
61
|
+
*/
|
|
62
|
+
export declare function renameMessageKey(catalogue: MessageCatalogue, from: string, to: string): MessageKeyRename;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/rules/messages.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/E;AAED,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACx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AAgF;AAChF,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAA;CAAE,GAC3D;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAA;CAAE,CAAC;AAErE;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,gBAAgB,EAC3B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,GACT,gBAAgB,CAYlB"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
function tableOf(catalogue, messageKey) {
|
|
2
|
+
return catalogue.messages[messageKey];
|
|
3
|
+
}
|
|
4
|
+
function storedText(catalogue, messageKey, locale) {
|
|
5
|
+
const table = tableOf(catalogue, messageKey);
|
|
6
|
+
if (table === undefined)
|
|
7
|
+
return undefined;
|
|
8
|
+
return table[locale];
|
|
9
|
+
}
|
|
10
|
+
function isMissing(text) {
|
|
11
|
+
return text === undefined || text.trim().length === 0;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resolves one message key for one locale.
|
|
15
|
+
*
|
|
16
|
+
* The order is the document's: the exact locale, then its language prefix (`pt` for `pt-PT`),
|
|
17
|
+
* then the document default. `source` states which answered, so an editor can flag text that is
|
|
18
|
+
* only a fallback instead of presenting it as a translation.
|
|
19
|
+
*/
|
|
20
|
+
export function translateMessage(catalogue, messageKey, locale) {
|
|
21
|
+
const requested = locale ?? catalogue.defaultLocale;
|
|
22
|
+
const exact = storedText(catalogue, messageKey, requested);
|
|
23
|
+
if (!isMissing(exact) && exact !== undefined) {
|
|
24
|
+
return { text: exact, source: 'locale', locale: requested };
|
|
25
|
+
}
|
|
26
|
+
const separator = requested.indexOf('-');
|
|
27
|
+
if (separator > 0) {
|
|
28
|
+
const prefix = requested.slice(0, separator);
|
|
29
|
+
const fallback = storedText(catalogue, messageKey, prefix);
|
|
30
|
+
if (!isMissing(fallback) && fallback !== undefined) {
|
|
31
|
+
return { text: fallback, source: 'locale', locale: prefix };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const fallback = storedText(catalogue, messageKey, catalogue.defaultLocale);
|
|
35
|
+
if (!isMissing(fallback) && fallback !== undefined) {
|
|
36
|
+
return { text: fallback, source: 'default', locale: catalogue.defaultLocale };
|
|
37
|
+
}
|
|
38
|
+
return { text: undefined, source: 'missing', locale: requested };
|
|
39
|
+
}
|
|
40
|
+
/** Every declared locale's state for one message key, in the catalogue's locale order. */
|
|
41
|
+
export function messageRows(catalogue, messageKey) {
|
|
42
|
+
return catalogue.locales.map((locale) => {
|
|
43
|
+
const text = storedText(catalogue, messageKey, locale);
|
|
44
|
+
const missing = isMissing(text);
|
|
45
|
+
return {
|
|
46
|
+
locale,
|
|
47
|
+
...(text === undefined ? {} : { text }),
|
|
48
|
+
missing,
|
|
49
|
+
isDefault: locale === catalogue.defaultLocale,
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** The declared locales that have no text for one key. */
|
|
54
|
+
export function missingMessageLocales(catalogue, messageKey) {
|
|
55
|
+
return messageRows(catalogue, messageKey)
|
|
56
|
+
.filter((row) => row.missing)
|
|
57
|
+
.map((row) => row.locale);
|
|
58
|
+
}
|
|
59
|
+
/** Whether one key is complete across every declared locale. */
|
|
60
|
+
export function messageComplete(catalogue, messageKey) {
|
|
61
|
+
return missingMessageLocales(catalogue, messageKey).length === 0;
|
|
62
|
+
}
|
|
63
|
+
/** A new catalogue with one locale's text set for one key. */
|
|
64
|
+
export function setMessageText(catalogue, messageKey, locale, text) {
|
|
65
|
+
const existing = catalogue.messages[messageKey] ?? {};
|
|
66
|
+
return {
|
|
67
|
+
...catalogue,
|
|
68
|
+
messages: {
|
|
69
|
+
...catalogue.messages,
|
|
70
|
+
[messageKey]: { ...existing, [locale]: text },
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Copies the document default's text into one locale, or into every locale missing text.
|
|
76
|
+
*
|
|
77
|
+
* The copy is explicit and leaves every locale that already has text alone, so an editor's
|
|
78
|
+
* "copy from the document default" cannot overwrite a translation the author wrote.
|
|
79
|
+
*/
|
|
80
|
+
export function copyMessageFromDefault(catalogue, messageKey, locale) {
|
|
81
|
+
const defaultText = storedText(catalogue, messageKey, catalogue.defaultLocale);
|
|
82
|
+
if (isMissing(defaultText) || defaultText === undefined)
|
|
83
|
+
return catalogue;
|
|
84
|
+
const targets = locale === undefined ? missingMessageLocales(catalogue, messageKey) : [locale];
|
|
85
|
+
let next = catalogue;
|
|
86
|
+
for (const target of targets) {
|
|
87
|
+
next = setMessageText(next, messageKey, target, defaultText);
|
|
88
|
+
}
|
|
89
|
+
return next;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Renames one message key, carrying its text to the new name.
|
|
93
|
+
*
|
|
94
|
+
* A collision is refused rather than merged: two rules sharing a key would make one message
|
|
95
|
+
* silently overwrite the other's translations, which is a decision for the author, not for a
|
|
96
|
+
* keystroke in the key input.
|
|
97
|
+
*/
|
|
98
|
+
export function renameMessageKey(catalogue, from, to) {
|
|
99
|
+
const name = to.trim();
|
|
100
|
+
if (name.length === 0)
|
|
101
|
+
return { ok: false, reason: 'empty' };
|
|
102
|
+
if (name === from)
|
|
103
|
+
return { ok: true, catalogue };
|
|
104
|
+
if (catalogue.messages[name] !== undefined)
|
|
105
|
+
return { ok: false, reason: 'collision' };
|
|
106
|
+
const text = catalogue.messages[from];
|
|
107
|
+
const messages = { ...catalogue.messages };
|
|
108
|
+
if (text !== undefined) {
|
|
109
|
+
messages[name] = text;
|
|
110
|
+
delete messages[from];
|
|
111
|
+
}
|
|
112
|
+
return { ok: true, catalogue: { ...catalogue, messages } };
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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AW,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAUD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAA2B,EAC3B,IAAY,EACZ,EAAU;IAEV,MAAM,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IACvB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC7D,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAClD,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IACtF,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC3C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QACtB,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC;AAC7D,CAAC","sourcesContent":["/** The i18n view a rule message editor reads: declared locales and their message text. */\nexport interface MessageCatalogue {\n readonly locales: readonly string[];\n readonly defaultLocale: string;\n readonly messages: Readonly<Record<string, Readonly<Record<string, string>>>>;\n}\n\n/** One locale's state for one message key. */\nexport interface MessageRow {\n readonly locale: string;\n /** The text stored for the locale; absent when the locale has none. */\n readonly text?: string;\n /** Whether the locale has no non-blank text for this key. */\n readonly missing: boolean;\n readonly isDefault: boolean;\n}\n\n/** The text a locale resolves to, and where it came from. */\nexport interface ResolvedMessage {\n readonly text: string | undefined;\n readonly source: 'locale' | 'default' | 'missing';\n readonly locale: string;\n}\n\nfunction tableOf(\n catalogue: MessageCatalogue,\n messageKey: string,\n): Readonly<Record<string, string>> | undefined {\n return catalogue.messages[messageKey];\n}\n\nfunction storedText(\n catalogue: MessageCatalogue,\n messageKey: string,\n locale: string,\n): string | undefined {\n const table = tableOf(catalogue, messageKey);\n if (table === undefined) return undefined;\n return table[locale];\n}\n\nfunction isMissing(text: string | undefined): boolean {\n return text === undefined || text.trim().length === 0;\n}\n\n/**\n * Resolves one message key for one locale.\n *\n * The order is the document's: the exact locale, then its language prefix (`pt` for `pt-PT`),\n * then the document default. `source` states which answered, so an editor can flag text that is\n * only a fallback instead of presenting it as a translation.\n */\nexport function translateMessage(\n catalogue: MessageCatalogue,\n messageKey: string,\n locale?: string,\n): ResolvedMessage {\n const requested = locale ?? catalogue.defaultLocale;\n const exact = storedText(catalogue, messageKey, requested);\n if (!isMissing(exact) && exact !== undefined) {\n return { text: exact, source: 'locale', locale: requested };\n }\n const separator = requested.indexOf('-');\n if (separator > 0) {\n const prefix = requested.slice(0, separator);\n const fallback = storedText(catalogue, messageKey, prefix);\n if (!isMissing(fallback) && fallback !== undefined) {\n return { text: fallback, source: 'locale', locale: prefix };\n }\n }\n const fallback = storedText(catalogue, messageKey, catalogue.defaultLocale);\n if (!isMissing(fallback) && fallback !== undefined) {\n return { text: fallback, source: 'default', locale: catalogue.defaultLocale };\n }\n return { text: undefined, source: 'missing', locale: requested };\n}\n\n/** Every declared locale's state for one message key, in the catalogue's locale order. */\nexport function messageRows(\n catalogue: MessageCatalogue,\n messageKey: string,\n): readonly MessageRow[] {\n return catalogue.locales.map((locale) => {\n const text = storedText(catalogue, messageKey, locale);\n const missing = isMissing(text);\n return {\n locale,\n ...(text === undefined ? {} : { text }),\n missing,\n isDefault: locale === catalogue.defaultLocale,\n };\n });\n}\n\n/** The declared locales that have no text for one key. */\nexport function missingMessageLocales(\n catalogue: MessageCatalogue,\n messageKey: string,\n): readonly string[] {\n return messageRows(catalogue, messageKey)\n .filter((row) => row.missing)\n .map((row) => row.locale);\n}\n\n/** Whether one key is complete across every declared locale. */\nexport function messageComplete(catalogue: MessageCatalogue, messageKey: string): boolean {\n return missingMessageLocales(catalogue, messageKey).length === 0;\n}\n\n/** A new catalogue with one locale's text set for one key. */\nexport function setMessageText(\n catalogue: MessageCatalogue,\n messageKey: string,\n locale: string,\n text: string,\n): MessageCatalogue {\n const existing = catalogue.messages[messageKey] ?? {};\n return {\n ...catalogue,\n messages: {\n ...catalogue.messages,\n [messageKey]: { ...existing, [locale]: text },\n },\n };\n}\n\n/**\n * Copies the document default's text into one locale, or into every locale missing text.\n *\n * The copy is explicit and leaves every locale that already has text alone, so an editor's\n * \"copy from the document default\" cannot overwrite a translation the author wrote.\n */\nexport function copyMessageFromDefault(\n catalogue: MessageCatalogue,\n messageKey: string,\n locale?: string,\n): MessageCatalogue {\n const defaultText = storedText(catalogue, messageKey, catalogue.defaultLocale);\n if (isMissing(defaultText) || defaultText === undefined) return catalogue;\n const targets = locale === undefined ? missingMessageLocales(catalogue, messageKey) : [locale];\n let next = catalogue;\n for (const target of targets) {\n next = setMessageText(next, messageKey, target, defaultText);\n }\n return next;\n}\n\n/** Why a message-key rename did not happen. */\ntype MessageKeyRenameRefusal = 'empty' | 'collision';\n\n/** The outcome of renaming a message key: the new catalogue, or the refusal. */\nexport type MessageKeyRename =\n | { readonly ok: true; readonly catalogue: MessageCatalogue }\n | { readonly ok: false; readonly reason: MessageKeyRenameRefusal };\n\n/**\n * Renames one message key, carrying its text to the new name.\n *\n * A collision is refused rather than merged: two rules sharing a key would make one message\n * silently overwrite the other's translations, which is a decision for the author, not for a\n * keystroke in the key input.\n */\nexport function renameMessageKey(\n catalogue: MessageCatalogue,\n from: string,\n to: string,\n): MessageKeyRename {\n const name = to.trim();\n if (name.length === 0) return { ok: false, reason: 'empty' };\n if (name === from) return { ok: true, catalogue };\n if (catalogue.messages[name] !== undefined) return { ok: false, reason: 'collision' };\n const text = catalogue.messages[from];\n const messages = { ...catalogue.messages };\n if (text !== undefined) {\n messages[name] = text;\n delete messages[from];\n }\n return { ok: true, catalogue: { ...catalogue, messages } };\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Primitive } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import type { ComparisonValidationOperator, RuleField, ValidationOperator } from './types.js';
|
|
3
|
+
/** How many operands an operator's editor shows. */
|
|
4
|
+
type OperatorArity = 'none' | 'one' | 'two' | 'list' | 'pattern';
|
|
5
|
+
/** One operator's label and the editor shape it needs. */
|
|
6
|
+
export interface ValidationOperatorDefinition {
|
|
7
|
+
readonly id: ValidationOperator;
|
|
8
|
+
/** The owner's own phrase; a host may override every label through the editor's `labels`. */
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly arity: OperatorArity;
|
|
11
|
+
}
|
|
12
|
+
/** The definition for one operator. */
|
|
13
|
+
export declare function validationOperatorDefinition(operator: ValidationOperator): ValidationOperatorDefinition;
|
|
14
|
+
/** The comparison operator one validation operator emits, or `undefined` for a call-shaped one. */
|
|
15
|
+
export declare function comparisonOperatorOf(operator: ComparisonValidationOperator): '==' | '!=' | '<' | '<=' | '>' | '>=';
|
|
16
|
+
/** Whether an operator is offered for a field's primitive. */
|
|
17
|
+
export declare function operatorApplies(operator: ValidationOperator, primitive: Primitive): boolean;
|
|
18
|
+
/** The operators the editor offers for one field, in reading order. */
|
|
19
|
+
export declare function operatorsForField(field: RuleField | undefined): readonly ValidationOperator[];
|
|
20
|
+
/** The first operator a field may use, and the one a field change falls back to. */
|
|
21
|
+
export declare function defaultOperatorFor(field: RuleField | undefined): ValidationOperator;
|
|
22
|
+
/** Whether a field can stand in as the right-hand operand of an operator over `primitive`. */
|
|
23
|
+
export declare function operandFieldCompatible(operator: ValidationOperator, primitive: Primitive, candidate: RuleField): boolean;
|
|
24
|
+
export {};
|
|
25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