@yomotech/view-toolkit 1.0.37 → 1.0.38
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/fesm2022/yomotech-view-toolkit-catalog.mjs +674 -0
- package/fesm2022/yomotech-view-toolkit-catalog.mjs.map +1 -0
- package/fesm2022/yomotech-view-toolkit.mjs +5575 -3091
- package/fesm2022/yomotech-view-toolkit.mjs.map +1 -1
- package/package.json +5 -1
- package/types/yomotech-view-toolkit-catalog.d.ts +216 -0
- package/types/yomotech-view-toolkit.d.ts +664 -41
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-18
|
|
2
|
+
// - new: the period - type dateRange (stored [from, to]) with its control dateRangepicker, the date
|
|
3
|
+
// keyboard, placeholder and the date display settings (#166 E4)
|
|
4
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-17
|
|
5
|
+
// - new: the field catalog - the ONE place that says which controls exist, which data they fit,
|
|
6
|
+
// which settings they offer, how dates/times/decimals/currencies are encoded and how a field
|
|
7
|
+
// layout is checked. The Designer, the renderer, the AI contract (capabilities.json, schemas,
|
|
8
|
+
// validator, prompt) are to read it from here instead of keeping their own copies (CONTROLS-PLAN.md,
|
|
9
|
+
// step 1, #165).
|
|
10
|
+
// Taken over unchanged from the Designer's field-settings.ts (shuaib, the most complete rules so
|
|
11
|
+
// far) - so the Designer behaves exactly as before once it reads them from here - plus:
|
|
12
|
+
// - basicType: the aliases of the data types (image -> media, checkbox -> boolean, date&time ->
|
|
13
|
+
// datetime, decimal -> bigdecimal), from the developer's field-policy.ts (12248aef, reverted)
|
|
14
|
+
// - placeholder for every control a value is typed or chosen in (before: textInput, textArea,
|
|
15
|
+
// password, dropdown, combobox only)
|
|
16
|
+
// - the keyboard: option.keyboardType per field (string, alpha, numeric, email, date, time; native
|
|
17
|
+
// or none keep the system keyboard); without one the control's default, then the data type's
|
|
18
|
+
// It only describes and checks; nothing renders from it yet (step 2).
|
|
19
|
+
// - change 2026-10-18: effectiveControl - the control the app really uses when option.control is
|
|
20
|
+
// missing (most fields of TM, Paperfeed, Luv2shop, Hotel): the old switches (password, email,
|
|
21
|
+
// timeOnly), DTO types that are a control themselves (dropdown, creditCard, quantity), then the
|
|
22
|
+
// data type. A date with its own pattern (format "yy-mm-dd") stays a date. The old option.keyboard
|
|
23
|
+
// counts when keyboardType is missing (#166)
|
|
24
|
+
const clone = (value) => JSON.parse(JSON.stringify(value));
|
|
25
|
+
const own = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
26
|
+
function resolveProperty(root, reference) {
|
|
27
|
+
const parts = (reference || '').replace(/^#\/?/, '').split('/').filter(Boolean).map(p => p.replace(/~1/g, '/').replace(/~0/g, '~'));
|
|
28
|
+
let node = root;
|
|
29
|
+
for (const part of parts)
|
|
30
|
+
node = node?.[part] ?? node?.properties?.[part];
|
|
31
|
+
if (node?.type)
|
|
32
|
+
return node;
|
|
33
|
+
const name = parts[parts.length - 1];
|
|
34
|
+
const objectName = parts.find(p => p !== 'properties');
|
|
35
|
+
return root?.[objectName]?.[name] ?? root?.[objectName]?.properties?.[name] ?? root?.properties?.[name] ?? {};
|
|
36
|
+
}
|
|
37
|
+
function normalizeFormat(value) {
|
|
38
|
+
return { date: 'iso-date', time: 'iso-time', 'date-time': 'iso-datetime', datetime: 'iso-datetime', 'date&time': 'iso-datetime', bigdecimal: 'decimal' }[String(value).toLowerCase()] || value || '';
|
|
39
|
+
}
|
|
40
|
+
function baseType(schema, fallback) {
|
|
41
|
+
const t = String(schema.type || fallback || '').toLowerCase();
|
|
42
|
+
if (t === 'dropdown')
|
|
43
|
+
return 'string';
|
|
44
|
+
if (t === 'quantity')
|
|
45
|
+
return 'integer';
|
|
46
|
+
return ['date', 'time', 'datetime', 'date-time', 'date&time'].includes(t) ? 'string' : ['decimal', 'bigdecimal'].includes(t) ? 'string' : t;
|
|
47
|
+
}
|
|
48
|
+
function effectiveFormat(schema, fallback, data) {
|
|
49
|
+
const semantic = String(schema.type || fallback || '').toLowerCase();
|
|
50
|
+
const temporal = ['date', 'time', 'datetime', 'date-time', 'date&time', 'decimal', 'bigdecimal'].includes(semantic);
|
|
51
|
+
const declared = normalizeFormat(schema.format || data.format || '');
|
|
52
|
+
// A date with its own display pattern (format "yy-mm-dd") is still a date.
|
|
53
|
+
if (temporal && declared && !DATA_FORMATS.includes(declared))
|
|
54
|
+
return normalizeFormat(semantic);
|
|
55
|
+
return declared || (temporal ? normalizeFormat(semantic) : '');
|
|
56
|
+
}
|
|
57
|
+
function rulesFor(schema, data) {
|
|
58
|
+
// The document's array enum is an item enum, unlike JSON Schema's whole-array enum.
|
|
59
|
+
const source = schema.type === 'array' ? { ...schema, enum: schema.items?.enum } : schema;
|
|
60
|
+
const rules = { ...(data.validation || {}) };
|
|
61
|
+
for (const k of ['enum', 'pattern', 'minLength', 'maxLength', 'minimum', 'maximum', 'multipleOf', 'minItems', 'maxItems', 'uniqueItems']) {
|
|
62
|
+
if (source[k] !== undefined)
|
|
63
|
+
rules[k] = source[k];
|
|
64
|
+
}
|
|
65
|
+
return rules;
|
|
66
|
+
}
|
|
67
|
+
function controlsFor(schema, fallback, option) {
|
|
68
|
+
const d = option.fieldData || {}, t = baseType(schema, fallback), f = effectiveFormat(schema, fallback, d), r = rulesFor(schema, d);
|
|
69
|
+
let values = [];
|
|
70
|
+
const declared = String(schema["type"] || fallback || '').toLowerCase();
|
|
71
|
+
if (declared === 'creditcard')
|
|
72
|
+
values = ['creditCard'];
|
|
73
|
+
else if (declared === 'quantity')
|
|
74
|
+
values = ['quantity', 'spinner', 'textInput'];
|
|
75
|
+
else if (declared === 'dropdown')
|
|
76
|
+
values = ['dropdown', 'combobox', 'autocomplete', 'radiobutton'];
|
|
77
|
+
// a period from - to, stored as the pair [from, to] (#166 E4)
|
|
78
|
+
else if (declared === 'daterange')
|
|
79
|
+
values = ['dateRangepicker'];
|
|
80
|
+
else if (f === 'flag' || t === 'boolean')
|
|
81
|
+
values = ['checkbox', 'switch', 'radiobutton'];
|
|
82
|
+
else if (f === 'iso-date')
|
|
83
|
+
values = ['datepicker', 'textInput'];
|
|
84
|
+
else if (f === 'iso-time')
|
|
85
|
+
values = ['timepicker', 'textInput'];
|
|
86
|
+
else if (f === 'iso-datetime')
|
|
87
|
+
values = ['dateTimepicker', 'textInput'];
|
|
88
|
+
else if (f === 'decimal')
|
|
89
|
+
values = ['textInput', 'spinner'];
|
|
90
|
+
else if (t === 'array')
|
|
91
|
+
values = ['picklist', 'multiselect'];
|
|
92
|
+
else if (r.enum)
|
|
93
|
+
values = ['dropdown', 'radiobutton', 'combobox', 'autocomplete'];
|
|
94
|
+
else if (t === 'string')
|
|
95
|
+
values = ['textInput', 'textArea', 'password', 'combobox', 'autocomplete', 'email'];
|
|
96
|
+
else if (t === 'integer' || t === 'number')
|
|
97
|
+
values = ['textInput', 'spinner', 'slider'];
|
|
98
|
+
if (values.length)
|
|
99
|
+
values.push('output');
|
|
100
|
+
const labels = { textInput: 'Text field', textArea: 'Text area', dateTimepicker: 'Date and time picker', dateRangepicker: 'Date range picker', radiobutton: 'Radio buttons', datepicker: 'Date picker', timepicker: 'Time picker', output: 'Read-only output', creditCard: 'Credit card', quantity: 'Quantity' };
|
|
101
|
+
return values.map(value => ({ value, label: labels[value] || value[0].toUpperCase() + value.slice(1) }));
|
|
102
|
+
}
|
|
103
|
+
const canonicalControl = (c) => ({ textfield: 'textInput', textarea: 'textArea', radioButton: 'radiobutton', datetimepicker: 'dateTimepicker', daterangepicker: 'dateRangepicker', date: 'datepicker', time: 'timepicker' }[c] || c);
|
|
104
|
+
// ---------------------------------------------------------------------------------------------
|
|
105
|
+
// Data types, controls, placeholder and keyboard
|
|
106
|
+
// ---------------------------------------------------------------------------------------------
|
|
107
|
+
/** The data types of a property after its aliases. */
|
|
108
|
+
const BASIC_TYPES = ['string', 'number', 'integer', 'bigdecimal', 'boolean', 'date', 'time', 'datetime', 'dateRange', 'media', 'array'];
|
|
109
|
+
/** Older or other names of a data type and the type they mean. */
|
|
110
|
+
const TYPE_ALIASES = { daterange: 'dateRange', image: 'media', checkbox: 'boolean', 'date-time': 'datetime', 'date&time': 'datetime', decimal: 'bigdecimal' };
|
|
111
|
+
/** The data type of a property, aliases resolved ("image" -> "media"). */
|
|
112
|
+
function basicType(property) {
|
|
113
|
+
const value = String(property?.type || 'string').toLowerCase();
|
|
114
|
+
return TYPE_ALIASES[value] || value;
|
|
115
|
+
}
|
|
116
|
+
/** Every control the Designer offers (option.control), with the name it is shown under. */
|
|
117
|
+
const CONTROLS = {
|
|
118
|
+
textInput: 'Text field', textArea: 'Text area', password: 'Password', email: 'Email',
|
|
119
|
+
combobox: 'Combobox', autocomplete: 'Autocomplete', dropdown: 'Dropdown',
|
|
120
|
+
checkbox: 'Checkbox', switch: 'Switch', radiobutton: 'Radio buttons',
|
|
121
|
+
spinner: 'Spinner', slider: 'Slider',
|
|
122
|
+
datepicker: 'Date picker', timepicker: 'Time picker', dateTimepicker: 'Date and time picker',
|
|
123
|
+
dateRangepicker: 'Date range picker',
|
|
124
|
+
picklist: 'Picklist', multiselect: 'Multiselect', output: 'Read-only output',
|
|
125
|
+
creditCard: 'Credit card', quantity: 'Quantity',
|
|
126
|
+
};
|
|
127
|
+
/** DTO types that name their control themselves (older projects). */
|
|
128
|
+
const CONTROL_TYPES = { dropdown: 'dropdown', creditcard: 'creditCard', quantity: 'quantity' };
|
|
129
|
+
/**
|
|
130
|
+
* The control a field is shown with: option.control; without one what the app uses - an old switch
|
|
131
|
+
* (password, email, timeOnly), a DTO type that is a control (dropdown, creditCard, quantity), else
|
|
132
|
+
* the first control that fits the data (date -> datepicker, boolean -> checkbox, text -> textInput).
|
|
133
|
+
* '' when nothing fits (media, objects).
|
|
134
|
+
*/
|
|
135
|
+
function effectiveControl(option, schema = {}, fallback = '') {
|
|
136
|
+
const o = option || {};
|
|
137
|
+
if (o.control)
|
|
138
|
+
return canonicalControl(o.control);
|
|
139
|
+
const allowed = controlsFor(schema || {}, fallback, o).map(c => c.value);
|
|
140
|
+
const legacy = o.password ? 'password' : o.email ? 'email' : o.timeOnly ? 'timepicker' : '';
|
|
141
|
+
if (legacy && allowed.includes(legacy))
|
|
142
|
+
return legacy;
|
|
143
|
+
const own = CONTROL_TYPES[String(schema?.type || fallback || '').toLowerCase()];
|
|
144
|
+
if (own)
|
|
145
|
+
return own;
|
|
146
|
+
return allowed.find(c => c !== 'output') || '';
|
|
147
|
+
}
|
|
148
|
+
/** Controls a value is typed or chosen in - they take a placeholder. */
|
|
149
|
+
const PLACEHOLDER_CONTROLS = [
|
|
150
|
+
'textInput', 'textArea', 'password', 'email', 'dropdown', 'combobox', 'autocomplete',
|
|
151
|
+
'spinner', 'datepicker', 'timepicker', 'dateTimepicker', 'dateRangepicker', 'multiselect',
|
|
152
|
+
];
|
|
153
|
+
/** The toolkit keyboards a field can ask for (option.keyboardType). */
|
|
154
|
+
const KEYBOARD_TYPES = ['string', 'alpha', 'numeric', 'email', 'date', 'time'];
|
|
155
|
+
/** keyboardType values that keep the device's system keyboard. */
|
|
156
|
+
const SYSTEM_KEYBOARDS = ['native', 'none'];
|
|
157
|
+
/** Controls a keyboard is chosen for. */
|
|
158
|
+
const KEYBOARD_CONTROLS = [
|
|
159
|
+
'textInput', 'textArea', 'password', 'email', 'combobox', 'autocomplete',
|
|
160
|
+
'spinner', 'datepicker', 'timepicker', 'dateTimepicker', 'dateRangepicker', 'quantity',
|
|
161
|
+
];
|
|
162
|
+
/** The keyboard a control brings when the field names none (as the Designer preselects it). */
|
|
163
|
+
function defaultKeyboard(control, schema = {}, fallback = '', data = {}) {
|
|
164
|
+
const c = canonicalControl(control), t = baseType(schema, fallback), f = effectiveFormat(schema, fallback, data);
|
|
165
|
+
if (c === 'email')
|
|
166
|
+
return 'email';
|
|
167
|
+
if (c === 'timepicker')
|
|
168
|
+
return 'time';
|
|
169
|
+
if (['datepicker', 'dateTimepicker', 'dateRangepicker'].includes(c))
|
|
170
|
+
return 'date';
|
|
171
|
+
if (['textArea', 'password', 'combobox', 'autocomplete'].includes(c))
|
|
172
|
+
return 'string';
|
|
173
|
+
if (f === 'iso-time')
|
|
174
|
+
return 'time';
|
|
175
|
+
if (['iso-date', 'iso-datetime'].includes(f))
|
|
176
|
+
return 'date';
|
|
177
|
+
if (['spinner', 'quantity'].includes(c) || ['number', 'integer'].includes(t) || f === 'decimal')
|
|
178
|
+
return 'numeric';
|
|
179
|
+
return 'string';
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The keyboard of a field: its keyboardType; native/none (and a password without one) keep the
|
|
183
|
+
* system keyboard (null); without keyboardType the control's default; without a control the data
|
|
184
|
+
* type's (date, time, number/integer, string, email format). The per-type keyboards are only the
|
|
185
|
+
* fallback.
|
|
186
|
+
*/
|
|
187
|
+
function keyboardFor(option, property = {}) {
|
|
188
|
+
const explicit = option?.keyboardType ?? option?.keyboard;
|
|
189
|
+
if (SYSTEM_KEYBOARDS.includes(explicit))
|
|
190
|
+
return null;
|
|
191
|
+
if (KEYBOARD_TYPES.includes(explicit))
|
|
192
|
+
return explicit;
|
|
193
|
+
const control = canonicalControl(option?.control || '');
|
|
194
|
+
if (control === 'password' || option?.password)
|
|
195
|
+
return null;
|
|
196
|
+
if (control && KEYBOARD_CONTROLS.includes(control))
|
|
197
|
+
return defaultKeyboard(control, property, '', option?.fieldData || {});
|
|
198
|
+
if (option?.email || property?.format === 'email')
|
|
199
|
+
return 'email';
|
|
200
|
+
switch (basicType(property)) {
|
|
201
|
+
case 'date': return 'date';
|
|
202
|
+
case 'time': return 'time';
|
|
203
|
+
case 'number':
|
|
204
|
+
case 'integer':
|
|
205
|
+
case 'bigdecimal': return 'numeric';
|
|
206
|
+
case 'string': return 'string';
|
|
207
|
+
default: return null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/** The part of a date/time a property shows and takes (DTO type date / time / date&time), else null. */
|
|
211
|
+
function temporalPart(property) {
|
|
212
|
+
const t = basicType(property);
|
|
213
|
+
return t === 'date' || t === 'time' || t === 'datetime' ? t : null;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* How date and time values travel - the same for every project:
|
|
217
|
+
* - every value is a string (JSON has no date type); the app turns it into a date for showing and
|
|
218
|
+
* back into a string for sending, steered by the DTO type alone
|
|
219
|
+
* - read: ISO, date and time, a value without timezone is local wall time; Z or an offset is
|
|
220
|
+
* dropped (wall time) - P5W1 sends 2025-11-04T16:30:00
|
|
221
|
+
* - send: ISO with the device's offset, 2026-10-18T08:00:00+02:00 (the daily split of the time
|
|
222
|
+
* recording, convertToDailyLogs, stays as it is)
|
|
223
|
+
* - shown and typed: the app language, year with four digits (de 18.10.2026, time 08:05);
|
|
224
|
+
* lists: displayFormat short / medium (default) / long / custom
|
|
225
|
+
*/
|
|
226
|
+
const TEMPORAL_TRANSFER = {
|
|
227
|
+
read: 'iso, local wall time, offset dropped',
|
|
228
|
+
send: 'iso with local offset',
|
|
229
|
+
show: 'app language, four-digit year',
|
|
230
|
+
listStyles: ['short', 'medium', 'long', 'custom'],
|
|
231
|
+
listDefault: 'medium',
|
|
232
|
+
};
|
|
233
|
+
/** The encodings a field can declare (option.fieldData.format). */
|
|
234
|
+
const DATA_FORMATS = ['iso-date', 'iso-time', 'iso-datetime', 'flag', 'decimal'];
|
|
235
|
+
/** How a date or time is shown (option.displayFormat). */
|
|
236
|
+
const DISPLAY_FORMATS = ['short', 'medium', 'long', 'custom'];
|
|
237
|
+
/** How a number is shown (option.numberStyle). */
|
|
238
|
+
const NUMBER_STYLES = ['decimal', 'currency', 'percent'];
|
|
239
|
+
const setting = (key, label, kind = 'text', values, hint) => ({ key, label, kind, values, hint });
|
|
240
|
+
const yesNo = (key, label) => setting(key, label, 'select', ['true', 'false']);
|
|
241
|
+
function displaySettings(schema, fallback, option) {
|
|
242
|
+
const c = canonicalControl(option.control), t = baseType(schema, fallback), f = effectiveFormat(schema, fallback, option.fieldData || {}), r = rulesFor(schema, option.fieldData || {});
|
|
243
|
+
const result = [yesNo('readonly', 'Read only'), setting('messages', 'Validation messages', 'json', undefined, 'JSON object: validation rule names mapped to messages or translation keys.')];
|
|
244
|
+
if (PLACEHOLDER_CONTROLS.includes(c))
|
|
245
|
+
result.push(setting('placeholder', 'Placeholder'));
|
|
246
|
+
if (c === 'textInput')
|
|
247
|
+
result.push(setting('mask', 'Input mask'));
|
|
248
|
+
if (c === 'textArea')
|
|
249
|
+
result.push(setting('rows', 'Visible rows', 'number'));
|
|
250
|
+
if (['spinner', 'slider'].includes(c))
|
|
251
|
+
result.push(setting('step', 'Step', 'number'));
|
|
252
|
+
if (c === 'slider')
|
|
253
|
+
result.push(yesNo('showValue', 'Show slider value'));
|
|
254
|
+
if (['checkbox', 'switch'].includes(c))
|
|
255
|
+
result.push(setting('labelPosition', 'Label position', 'select', ['left', 'right']));
|
|
256
|
+
if (c === 'switch')
|
|
257
|
+
result.push(setting('labelOn', 'On label'), setting('labelOff', 'Off label'));
|
|
258
|
+
if (['checkbox', 'switch', 'radiobutton'].includes(c) && t === 'boolean')
|
|
259
|
+
result.push(setting('checkedBooleanValue', 'Value represented by the active state', 'select', ['true', 'false'], 'Stores a Boolean. Choose false to invert the visual state; this does not change the DTO type.'));
|
|
260
|
+
if (['checkbox', 'switch', 'radiobutton'].includes(c) && f === 'flag')
|
|
261
|
+
result.push(setting('checkedValue', 'Active value'), setting('uncheckedValue', 'Inactive value'));
|
|
262
|
+
if (['radiobutton', 'dropdown', 'combobox', 'autocomplete', 'picklist', 'multiselect'].includes(c))
|
|
263
|
+
result.push(setting('labels', 'Value labels', 'json', undefined, 'JSON object mapping allowed stored values to captions or translation keys.'));
|
|
264
|
+
if (c === 'radiobutton')
|
|
265
|
+
result.push(setting('orientation', 'Orientation', 'select', ['horizontal', 'vertical']));
|
|
266
|
+
if (c === 'combobox')
|
|
267
|
+
result.push(yesNo('allowCustom', 'Allow values outside the list'));
|
|
268
|
+
if (c === 'autocomplete')
|
|
269
|
+
result.push(setting('source', 'Suggestion source URL'), setting('minChars', 'Minimum characters', 'number'));
|
|
270
|
+
if (c === 'picklist')
|
|
271
|
+
result.push(yesNo('sortable', 'Allow item reordering'));
|
|
272
|
+
if (c === 'multiselect')
|
|
273
|
+
result.push(setting('maxVisible', 'Visible selected items', 'number'));
|
|
274
|
+
if ((['iso-date', 'iso-time', 'iso-datetime'].includes(f) && ['textInput', 'datepicker', 'timepicker', 'dateTimepicker', 'output'].includes(c)) || c === 'dateRangepicker') {
|
|
275
|
+
result.push(setting('displayFormat', 'Display style', 'select', ['short', 'medium', 'long', 'custom']));
|
|
276
|
+
if (option.displayFormat === 'custom')
|
|
277
|
+
result.push(setting('customDisplayFormat', 'Fixed display pattern', 'text', undefined, 'Use only when every locale must show the same pattern.'));
|
|
278
|
+
result.push(setting('displayTimezone', 'Display timezone', 'text', undefined, 'local, UTC, or an IANA timezone such as Asia/Karachi.'));
|
|
279
|
+
}
|
|
280
|
+
if ((['integer', 'number'].includes(t) || f === 'decimal') && ['textInput', 'spinner', 'slider', 'output'].includes(c)) {
|
|
281
|
+
result.push(setting('numberStyle', 'Number style', 'select', ['decimal', 'currency', 'percent']), yesNo('grouping', 'Group digits'));
|
|
282
|
+
if (!option.numberStyle || option.numberStyle === 'decimal')
|
|
283
|
+
result.push(setting('decimals', 'Displayed decimal places', 'number'));
|
|
284
|
+
result.push(setting('unit', 'Standard unit', 'text', undefined, 'An Intl unit identifier, for example kilogram or liter.'), setting('unitLabel', 'Custom unit translation key'));
|
|
285
|
+
}
|
|
286
|
+
if (c === 'dropdown')
|
|
287
|
+
result.push(setting('optionlabel', 'Response label field'), setting('optionvalue', 'Response value field'));
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
function dataSettings(schema, fallback, option) {
|
|
291
|
+
const t = baseType(schema, fallback), f = effectiveFormat(schema, fallback, option.fieldData || {});
|
|
292
|
+
const result = [];
|
|
293
|
+
if (['integer', 'number'].includes(t) || f === 'decimal') {
|
|
294
|
+
result.push(setting('currency', 'Fixed currency code', 'text', undefined, 'ISO currency code. Independent of the user locale.'), setting('currencyField', 'Currency property reference'));
|
|
295
|
+
if (t === 'integer')
|
|
296
|
+
result.push(yesNo('minorUnits', 'Store in currency minor units'));
|
|
297
|
+
}
|
|
298
|
+
return result;
|
|
299
|
+
}
|
|
300
|
+
function validationSettings(schema, fallback, option) {
|
|
301
|
+
const t = baseType(schema, fallback), f = effectiveFormat(schema, fallback, option.fieldData || {});
|
|
302
|
+
const result = [setting('enum', 'Allowed values', 'json', undefined, t === 'array' ? 'JSON array of allowed item values.' : 'JSON array; preserve each value’s data type.')];
|
|
303
|
+
if (t === 'string')
|
|
304
|
+
result.push(setting('minLength', 'Minimum length', 'number'), setting('maxLength', 'Maximum length', 'number'), setting('pattern', 'Validation pattern'));
|
|
305
|
+
if (['integer', 'number'].includes(t) || f === 'decimal')
|
|
306
|
+
result.push(setting('minimum', 'Minimum value', f === 'decimal' ? 'text' : 'number'), setting('maximum', 'Maximum value', f === 'decimal' ? 'text' : 'number'), setting('multipleOf', 'Value increment', f === 'decimal' ? 'text' : 'number'));
|
|
307
|
+
if (t === 'array')
|
|
308
|
+
result.push(setting('minItems', 'Minimum items', 'number'), setting('maxItems', 'Maximum items', 'number'), yesNo('uniqueItems', 'Require unique items'));
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
function decimalParts(value) {
|
|
312
|
+
const m = /^(-?)(\d+)(?:\.(\d+))?$/.exec(String(value));
|
|
313
|
+
return m ? [BigInt((m[1] || '') + m[2] + (m[3] || '')), (m[3] || '').length] : null;
|
|
314
|
+
}
|
|
315
|
+
function decimalPair(a, b) {
|
|
316
|
+
const x = decimalParts(a), y = decimalParts(b);
|
|
317
|
+
if (!x || !y)
|
|
318
|
+
return null;
|
|
319
|
+
const scale = Math.max(x[1], y[1]);
|
|
320
|
+
return [x[0] * 10n ** BigInt(scale - x[1]), y[0] * 10n ** BigInt(scale - y[1])];
|
|
321
|
+
}
|
|
322
|
+
function validDate(v) {
|
|
323
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(v);
|
|
324
|
+
if (!m)
|
|
325
|
+
return false;
|
|
326
|
+
const year = +m[1], month = +m[2], day = +m[3];
|
|
327
|
+
const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
328
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
|
|
329
|
+
}
|
|
330
|
+
function validTime(v) {
|
|
331
|
+
const m = /^(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(Z|[+-](\d{2}):(\d{2}))$/.exec(v);
|
|
332
|
+
return !!m && +m[1] < 24 && +m[2] < 60 && +m[3] < 60 && (!m[5] || (+m[5] < 24 && +m[6] < 60));
|
|
333
|
+
}
|
|
334
|
+
function validateSettings(schema, fallback, option, context) {
|
|
335
|
+
const errors = [], d = option.fieldData || {}, r = rulesFor(schema, d), t = baseType(schema, fallback), f = effectiveFormat(schema, fallback, d), c = canonicalControl(option.control);
|
|
336
|
+
const fail = (condition, message) => { if (condition)
|
|
337
|
+
errors.push(message); };
|
|
338
|
+
fail(!t, 'The property type could not be resolved. Provide propertySchema or propertyType.');
|
|
339
|
+
fail(d.format !== undefined && !['iso-date', 'iso-time', 'iso-datetime', 'flag', 'decimal'].includes(d.format), 'Choose a supported data meaning.');
|
|
340
|
+
fail(['iso-date', 'iso-time', 'iso-datetime', 'flag'].includes(f) && t !== 'string', 'Date, time, and flag formats require a string property.');
|
|
341
|
+
fail(f === 'decimal' && !['string', 'number'].includes(t), 'Exact decimal format requires string or number.');
|
|
342
|
+
fail(!!schema.format && !!d.format && normalizeFormat(schema.format) !== normalizeFormat(d.format), 'The format conflicts with the property schema.');
|
|
343
|
+
for (const k of Object.keys(d.validation || {})) {
|
|
344
|
+
const source = t === 'array' && k === 'enum' ? schema.items?.enum : schema[k];
|
|
345
|
+
fail(source !== undefined && JSON.stringify(source) !== JSON.stringify(d.validation[k]), `${k} conflicts with the property schema; keep the source constraint.`);
|
|
346
|
+
}
|
|
347
|
+
const pendingDropdown = context?.allowPendingValues && c === 'dropdown' && t === 'string' && !f && r.enum === undefined;
|
|
348
|
+
fail(!pendingDropdown && !controlsFor(schema, fallback, option).some(x => x.value === c), 'Select a control compatible with the effective data type.');
|
|
349
|
+
fail(!!r.pattern && t !== 'string', 'Patterns are only supported for strings.');
|
|
350
|
+
try {
|
|
351
|
+
if (r.pattern)
|
|
352
|
+
new RegExp(r.pattern);
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
errors.push('The validation pattern is not a valid regular expression.');
|
|
356
|
+
}
|
|
357
|
+
for (const k of ['minimum', 'maximum', 'multipleOf'])
|
|
358
|
+
fail(r[k] !== undefined && !(['integer', 'number'].includes(t) || f === 'decimal'), `${k} requires a numeric or decimal property.`);
|
|
359
|
+
for (const k of ['minLength', 'maxLength'])
|
|
360
|
+
fail(r[k] !== undefined && t !== 'string', `${k} requires a string property.`);
|
|
361
|
+
for (const k of ['minItems', 'maxItems', 'uniqueItems'])
|
|
362
|
+
fail(r[k] !== undefined && t !== 'array', `${k} requires an array property.`);
|
|
363
|
+
for (const k of ['minLength', 'maxLength', 'minItems', 'maxItems'])
|
|
364
|
+
fail(r[k] !== undefined && (!Number.isInteger(r[k]) || r[k] < 0), `${k} must be a nonnegative integer.`);
|
|
365
|
+
for (const [a, b] of [['minLength', 'maxLength'], ['minItems', 'maxItems']])
|
|
366
|
+
fail(r[a] !== undefined && r[b] !== undefined && r[a] > r[b], `${a} cannot exceed ${b}.`);
|
|
367
|
+
for (const k of ['minimum', 'maximum', 'multipleOf'])
|
|
368
|
+
if (r[k] !== undefined)
|
|
369
|
+
fail(f === 'decimal' ? !decimalParts(r[k]) : typeof r[k] !== 'number' || !Number.isFinite(r[k]), `${k} must be a valid numeric value.`);
|
|
370
|
+
if (r.minimum !== undefined && r.maximum !== undefined) {
|
|
371
|
+
const pair = decimalPair(r.minimum, r.maximum);
|
|
372
|
+
fail(pair ? pair[0] > pair[1] : r.minimum > r.maximum, 'Minimum cannot exceed maximum.');
|
|
373
|
+
}
|
|
374
|
+
if (r.multipleOf !== undefined) {
|
|
375
|
+
const p = decimalParts(r.multipleOf);
|
|
376
|
+
fail(!p || p[0] <= 0n, 'Value increment must be greater than zero.');
|
|
377
|
+
}
|
|
378
|
+
if (r.enum !== undefined) {
|
|
379
|
+
fail(!Array.isArray(r.enum) || !r.enum.length, 'Allowed values must be a nonempty JSON array.');
|
|
380
|
+
if (Array.isArray(r.enum)) {
|
|
381
|
+
fail(new Set(r.enum.map((v) => JSON.stringify(v))).size !== r.enum.length, 'Allowed values must not contain duplicates.');
|
|
382
|
+
const et = t === 'array' ? schema.items?.type || 'string' : t;
|
|
383
|
+
fail(r.enum.some((v) => et === 'integer' ? !Number.isInteger(v) : et === 'array' ? !Array.isArray(v) : typeof v !== et), 'Allowed values must match the property or item type.');
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
fail(c === 'combobox' && !!r.enum && option.allowCustom === true, 'Custom values cannot be enabled for an enum.');
|
|
387
|
+
fail(!!d.currency && !!d.currencyField, 'Choose a fixed currency OR a currency property, not both.');
|
|
388
|
+
fail(option.numberStyle === 'currency' && !d.currency && !d.currencyField, 'Currency display requires a currency code or currency property.');
|
|
389
|
+
fail(d.minorUnits === true && (t !== 'integer' || (!d.currency && !d.currencyField)), 'Minor units require integer storage and a currency.');
|
|
390
|
+
fail(option.numberStyle !== 'decimal' && !!option.numberStyle && option.decimals !== undefined, 'Decimal places apply only to decimal display; currency precision comes from the currency.');
|
|
391
|
+
fail(!!option.unit && !!option.unitLabel, 'Choose a standard unit OR a custom unit translation key.');
|
|
392
|
+
if (d.currency) {
|
|
393
|
+
const currencies = Intl.supportedValuesOf?.('currency');
|
|
394
|
+
fail(!/^[A-Z]{3}$/.test(d.currency) || (!!currencies && !currencies.includes(d.currency)), 'Choose a supported uppercase ISO currency code.');
|
|
395
|
+
}
|
|
396
|
+
if (d.currencyField && context?.propertySchema) {
|
|
397
|
+
const siblingRef = context.reference.slice(0, context.reference.lastIndexOf('/') + 1) + String(d.currencyField).replace(/~/g, '~0').replace(/\//g, '~1');
|
|
398
|
+
const currencyProperty = resolveProperty(context.propertySchema, String(d.currencyField).includes('/') ? d.currencyField : siblingRef);
|
|
399
|
+
fail(currencyProperty.type !== 'string', 'The currency property must exist in the property schema and have string storage.');
|
|
400
|
+
}
|
|
401
|
+
fail(option.checkedBooleanValue !== undefined && typeof option.checkedBooleanValue !== 'boolean', 'The active Boolean value must be true or false.');
|
|
402
|
+
for (const k of ['required', 'readonly', 'allowCustom', 'showValue', 'grouping'])
|
|
403
|
+
fail(option[k] !== undefined && typeof option[k] !== 'boolean', `${k} must be a Boolean.`);
|
|
404
|
+
for (const k of ['minorUnits'])
|
|
405
|
+
fail(d[k] !== undefined && typeof d[k] !== 'boolean', `${k} must be a Boolean.`);
|
|
406
|
+
fail(r.uniqueItems !== undefined && typeof r.uniqueItems !== 'boolean', 'uniqueItems must be a Boolean.');
|
|
407
|
+
if (option.unit) {
|
|
408
|
+
try {
|
|
409
|
+
new Intl.NumberFormat('en', { style: 'unit', unit: option.unit });
|
|
410
|
+
}
|
|
411
|
+
catch {
|
|
412
|
+
errors.push('The standard unit is not supported by Intl.');
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (option.displayTimezone && option.displayTimezone !== 'local') {
|
|
416
|
+
try {
|
|
417
|
+
new Intl.DateTimeFormat('en', { timeZone: option.displayTimezone });
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
errors.push('Enter a valid display timezone.');
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
fail(option.displayFormat === 'custom' && !option.customDisplayFormat, 'Enter a fixed display pattern.');
|
|
424
|
+
for (const k of ['rows', 'maxVisible', 'step'])
|
|
425
|
+
fail(option[k] !== undefined && (typeof option[k] !== 'number' || !Number.isFinite(option[k]) || option[k] <= 0), `${k} must be greater than zero.`);
|
|
426
|
+
for (const k of ['rows', 'maxVisible', 'minChars', 'decimals'])
|
|
427
|
+
fail(option[k] !== undefined && (!Number.isInteger(option[k]) || option[k] < 0), `${k} must be a nonnegative integer.`);
|
|
428
|
+
fail(t === 'integer' && option.step !== undefined && !Number.isInteger(option.step), 'Integer controls require a whole-number step.');
|
|
429
|
+
if (f === 'flag') {
|
|
430
|
+
fail(!Array.isArray(r.enum) || r.enum.length !== 2, 'A flag requires exactly two allowed string values.');
|
|
431
|
+
fail(option.checkedValue === undefined || option.uncheckedValue === undefined || option.checkedValue === option.uncheckedValue, 'Set different active and inactive flag values.');
|
|
432
|
+
if (Array.isArray(r.enum))
|
|
433
|
+
for (const k of ['checkedValue', 'uncheckedValue'])
|
|
434
|
+
fail(!r.enum.includes(option[k]), `${k} must exist in the allowed values.`);
|
|
435
|
+
}
|
|
436
|
+
if (option.labels !== undefined) {
|
|
437
|
+
fail(!option.labels || typeof option.labels !== 'object' || Array.isArray(option.labels), 'Value labels must be a JSON object.');
|
|
438
|
+
if (option.labels && typeof option.labels === 'object')
|
|
439
|
+
fail(Object.values(option.labels).some(v => typeof v !== 'string'), 'Label captions must be strings.');
|
|
440
|
+
const values = t === 'boolean' ? [true, false] : r.enum;
|
|
441
|
+
if (values && option.labels)
|
|
442
|
+
fail(Object.keys(option.labels).some(k => !values.some((v) => String(v) === k)), 'Every label key must match an allowed value.');
|
|
443
|
+
}
|
|
444
|
+
if (option.messages && typeof option.messages === 'object')
|
|
445
|
+
fail(Object.values(option.messages).some(v => typeof v !== 'string'), 'Validation messages must contain string captions or translation keys.');
|
|
446
|
+
for (const [key, values] of [['labelPosition', ['left', 'right']], ['orientation', ['horizontal', 'vertical']], ['numberStyle', ['decimal', 'currency', 'percent']]])
|
|
447
|
+
fail(option[key] !== undefined && !values.includes(option[key]), `Choose a supported ${key}.`);
|
|
448
|
+
fail(option.messages !== undefined && (!option.messages || typeof option.messages !== 'object' || Array.isArray(option.messages)), 'Validation messages must be a JSON object.');
|
|
449
|
+
const allowed = new Set(displaySettings(schema, fallback, option).map(s => s.key));
|
|
450
|
+
for (const k of ['placeholder', 'rows', 'mask', 'step', 'showValue', 'labelPosition', 'labelOn', 'labelOff', 'orientation', 'allowCustom', 'source', 'minChars', 'labels', 'maxVisible', 'displayFormat', 'displayTimezone', 'customDisplayFormat', 'numberStyle', 'decimals', 'grouping', 'unit', 'unitLabel', 'checkedValue', 'uncheckedValue', 'checkedBooleanValue'])
|
|
451
|
+
fail(option[k] !== undefined && !allowed.has(k), `${k} is not applicable to this control and data meaning.`);
|
|
452
|
+
for (const k of ['currency', 'currencyField', 'minorUnits'])
|
|
453
|
+
fail(d[k] !== undefined && !dataSettings(schema, fallback, option).some(s => s.key === k), `${k} requires the appropriate numeric type.`);
|
|
454
|
+
const validateValue = (value, name, valueType, item = false) => {
|
|
455
|
+
fail(valueType === 'integer' ? !Number.isInteger(value) : valueType === 'array' ? !Array.isArray(value) : typeof value !== valueType, `${name} must match ${valueType} storage.`);
|
|
456
|
+
if (Array.isArray(r.enum) && !r.enum.some((v) => JSON.stringify(v) === JSON.stringify(value)))
|
|
457
|
+
fail(valueType !== 'array', `${name} is outside the allowed values.`);
|
|
458
|
+
if (valueType === 'string') {
|
|
459
|
+
const v = String(value);
|
|
460
|
+
if (!item) {
|
|
461
|
+
fail(f === 'iso-date' && !validDate(v), `${name} must be an existing ISO date.`);
|
|
462
|
+
fail(f === 'iso-time' && !validTime(v), `${name} must be an ISO time with timezone.`);
|
|
463
|
+
const parts = v.split('T');
|
|
464
|
+
fail(f === 'iso-datetime' && (parts.length !== 2 || !validDate(parts[0]) || !validTime(parts[1])), `${name} must be an ISO date and time with timezone.`);
|
|
465
|
+
fail(r.minLength !== undefined && [...v].length < r.minLength, `${name} is too short.`);
|
|
466
|
+
fail(r.maxLength !== undefined && [...v].length > r.maxLength, `${name} is too long.`);
|
|
467
|
+
try {
|
|
468
|
+
if (r.pattern)
|
|
469
|
+
fail(!new RegExp(r.pattern).test(v), `${name} does not match the pattern.`);
|
|
470
|
+
}
|
|
471
|
+
catch { }
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (!item && (['integer', 'number'].includes(valueType) || f === 'decimal')) {
|
|
475
|
+
fail(valueType !== 'string' && !Number.isFinite(value), `${name} must be finite.`);
|
|
476
|
+
fail(f === 'decimal' && !decimalParts(value), `${name} must be a plain decimal value.`);
|
|
477
|
+
for (const k of ['minimum', 'maximum', 'multipleOf'])
|
|
478
|
+
if (r[k] !== undefined) {
|
|
479
|
+
const p = decimalPair(value, r[k]);
|
|
480
|
+
if (p)
|
|
481
|
+
fail(k === 'minimum' ? p[0] < p[1] : k === 'maximum' ? p[0] > p[1] : p[1] !== 0n && p[0] % p[1] !== 0n, `${name} violates ${k}.`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (valueType === 'array' && Array.isArray(value)) {
|
|
485
|
+
fail(r.minItems !== undefined && value.length < r.minItems, `${name} has too few items.`);
|
|
486
|
+
fail(r.maxItems !== undefined && value.length > r.maxItems, `${name} has too many items.`);
|
|
487
|
+
fail(r.uniqueItems === true && new Set(value.map(v => JSON.stringify(v))).size !== value.length, `${name} contains duplicate items.`);
|
|
488
|
+
value.forEach(v => validateValue(v, `${name} item`, schema.items?.type || 'string', true));
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
if (option.keyboardType !== undefined) {
|
|
492
|
+
fail(![...KEYBOARD_TYPES, ...SYSTEM_KEYBOARDS].includes(option.keyboardType), 'Choose a supported keyboard.');
|
|
493
|
+
fail(!!c && !KEYBOARD_CONTROLS.includes(c), 'This control has no keyboard.');
|
|
494
|
+
}
|
|
495
|
+
if (own(d, 'default') && own(schema, 'default'))
|
|
496
|
+
fail(JSON.stringify(d.default) !== JSON.stringify(schema.default), 'Default conflicts with the property schema.');
|
|
497
|
+
const defaultValue = own(schema, 'default') ? schema.default : d.default;
|
|
498
|
+
if (own(schema, 'default') || own(d, 'default'))
|
|
499
|
+
validateValue(defaultValue, 'Default value', t);
|
|
500
|
+
return [...new Set(errors)];
|
|
501
|
+
}
|
|
502
|
+
/** Call before activating a saved field layout; throws rather than warning. */
|
|
503
|
+
function assertFieldSettings(schema, fallback, option, context) {
|
|
504
|
+
const errors = validateSettings(schema, fallback, option, context);
|
|
505
|
+
if (errors.length)
|
|
506
|
+
throw new Error('Invalid field layout: ' + errors.join(' '));
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-19
|
|
510
|
+
// - new: the format of an app's test flows (#166). Every app brings its own test suite in its hidden
|
|
511
|
+
// system folder .liveforge/tests/ - one JSON file per flow. The same steps are run by the test
|
|
512
|
+
// runner inside the app (Designer preview, "Run tests") and by viewdefinition-e2e on simulators.
|
|
513
|
+
// Pages and fields are named by their name in the project (page folder, field key), never by a
|
|
514
|
+
// caption - a test runs in every language. Buttons by their action (Save, Add, Delete).
|
|
515
|
+
// A flow that writes real data says so ("books": true) and only runs after an explicit confirmation.
|
|
516
|
+
// checkTestFlow returns codes with parameters, the editor translates them.
|
|
517
|
+
// - new: a run can be stopped (FlowResult.stopped, TestRun.stopped)
|
|
518
|
+
// - new: expect blocked - a writing button is there and the flow may not press it
|
|
519
|
+
const TESTS_DIR = '.liveforge/tests';
|
|
520
|
+
const RESULTS_DIR = '.liveforge/results';
|
|
521
|
+
const TEST_DEVICES = ['phone', 'tablet', 'laptop', 'desktop'];
|
|
522
|
+
const ORIENTATIONS = ['portrait', 'landscape'];
|
|
523
|
+
const STEP_KINDS = ['open', 'tap', 'type', 'pick', 'press', 'rotate', 'device', 'wait', 'expect'];
|
|
524
|
+
/** What an expect step can check - one of them per step. */
|
|
525
|
+
const EXPECT_KINDS = ['value', 'shows', 'keyboard', 'list', 'message', 'visible', 'hidden', 'locked', 'blocked', 'inFrame'];
|
|
526
|
+
/** What has to stay inside the page frame (safe areas, top gap). */
|
|
527
|
+
const FRAME_PARTS = ['keyboard', 'dialog', 'calendar', 'list', 'menu'];
|
|
528
|
+
const LIST_STATES = ['open', 'closed'];
|
|
529
|
+
const DEFAULT_DEVICES = ['phone', 'tablet'];
|
|
530
|
+
/**
|
|
531
|
+
* How many runs the backend keeps in .liveforge/results - defaults, the project configuration can
|
|
532
|
+
* change them: at most `max` runs; while they together are bigger than `maxBytes` (mostly images of
|
|
533
|
+
* failed steps) the oldest go, but `min` runs always stay. Results are not exported.
|
|
534
|
+
*/
|
|
535
|
+
const RESULTS_KEEP = { max: 10, min: 5, maxBytes: 20 * 1024 * 1024 };
|
|
536
|
+
/** The runs to delete, oldest first; runs: name (sortable by date-time) and size in bytes. */
|
|
537
|
+
function resultsToDelete(runs, keep = RESULTS_KEEP) {
|
|
538
|
+
const sorted = [...runs].sort((a, b) => a.name.localeCompare(b.name));
|
|
539
|
+
const gone = [];
|
|
540
|
+
let total = sorted.reduce((sum, r) => sum + r.size, 0);
|
|
541
|
+
while (sorted.length > keep.min && (sorted.length > keep.max || total > keep.maxBytes)) {
|
|
542
|
+
const old = sorted.shift();
|
|
543
|
+
total -= old.size;
|
|
544
|
+
gone.push(old.name);
|
|
545
|
+
}
|
|
546
|
+
return gone;
|
|
547
|
+
}
|
|
548
|
+
/** "tablet:landscape" → { device: 'tablet', orientation: 'landscape' }; null when unknown. */
|
|
549
|
+
function parseDevice(text) {
|
|
550
|
+
const [device, orientation = 'portrait'] = String(text || '').split(':');
|
|
551
|
+
if (!TEST_DEVICES.includes(device))
|
|
552
|
+
return null;
|
|
553
|
+
if (!ORIENTATIONS.includes(orientation))
|
|
554
|
+
return null;
|
|
555
|
+
return { device: device, orientation: orientation };
|
|
556
|
+
}
|
|
557
|
+
/** The devices a flow runs on. */
|
|
558
|
+
function flowDevices(flow) {
|
|
559
|
+
return flow.devices?.length ? flow.devices : DEFAULT_DEVICES;
|
|
560
|
+
}
|
|
561
|
+
/** The kind of a step - the first step key it has. */
|
|
562
|
+
function stepKind(step) {
|
|
563
|
+
return STEP_KINDS.find((k) => step && Object.prototype.hasOwnProperty.call(step, k)) || null;
|
|
564
|
+
}
|
|
565
|
+
const text = (v) => typeof v === 'string' && v.trim().length > 0;
|
|
566
|
+
/** The problems of a flow; an empty list means it can run. */
|
|
567
|
+
function checkTestFlow(flow) {
|
|
568
|
+
const problems = [];
|
|
569
|
+
const add = (code, step, params) => problems.push({ code, step, params });
|
|
570
|
+
if (!flow || typeof flow !== 'object' || Array.isArray(flow))
|
|
571
|
+
return [{ code: 'notAnObject' }];
|
|
572
|
+
if (!text(flow.name))
|
|
573
|
+
add('nameMissing');
|
|
574
|
+
if (flow.books !== undefined && typeof flow.books !== 'boolean')
|
|
575
|
+
add('booksNotBoolean');
|
|
576
|
+
if (flow.devices !== undefined) {
|
|
577
|
+
if (!Array.isArray(flow.devices))
|
|
578
|
+
add('devicesNotList');
|
|
579
|
+
else
|
|
580
|
+
flow.devices.filter((d) => !parseDevice(d)).forEach((d) => add('unknownDevice', undefined, { device: String(d) }));
|
|
581
|
+
}
|
|
582
|
+
if (!Array.isArray(flow.steps) || !flow.steps.length) {
|
|
583
|
+
add('stepsMissing');
|
|
584
|
+
return problems;
|
|
585
|
+
}
|
|
586
|
+
flow.steps.forEach((step, i) => {
|
|
587
|
+
const n = i + 1;
|
|
588
|
+
if (!step || typeof step !== 'object' || Array.isArray(step)) {
|
|
589
|
+
add('stepNotAnObject', n);
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
const kinds = STEP_KINDS.filter((k) => k in step);
|
|
593
|
+
if (kinds.length !== 1) {
|
|
594
|
+
add(kinds.length ? 'stepSeveralKinds' : 'stepUnknown', n, { keys: Object.keys(step).join(', ') });
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
const kind = kinds[0];
|
|
598
|
+
switch (kind) {
|
|
599
|
+
case 'open':
|
|
600
|
+
case 'tap':
|
|
601
|
+
case 'press':
|
|
602
|
+
if (!text(step[kind]))
|
|
603
|
+
add('stepNameMissing', n, { kind });
|
|
604
|
+
break;
|
|
605
|
+
case 'type':
|
|
606
|
+
if (typeof step.type !== 'string')
|
|
607
|
+
add('typeNotText', n);
|
|
608
|
+
if (!text(step.into))
|
|
609
|
+
add('intoMissing', n);
|
|
610
|
+
break;
|
|
611
|
+
case 'pick':
|
|
612
|
+
if (!text(step.pick))
|
|
613
|
+
add('stepNameMissing', n, { kind });
|
|
614
|
+
if (!text(step.in))
|
|
615
|
+
add('inMissing', n);
|
|
616
|
+
break;
|
|
617
|
+
case 'rotate':
|
|
618
|
+
if (!ORIENTATIONS.includes(step.rotate))
|
|
619
|
+
add('unknownOrientation', n, { orientation: String(step.rotate) });
|
|
620
|
+
break;
|
|
621
|
+
case 'device':
|
|
622
|
+
if (!parseDevice(step.device))
|
|
623
|
+
add('unknownDevice', n, { device: String(step.device) });
|
|
624
|
+
break;
|
|
625
|
+
case 'wait':
|
|
626
|
+
if (typeof step.wait !== 'number' || step.wait < 0 || step.wait > 60000)
|
|
627
|
+
add('waitOutOfRange', n);
|
|
628
|
+
break;
|
|
629
|
+
case 'expect':
|
|
630
|
+
checkExpect(step.expect, n, add);
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
return problems;
|
|
635
|
+
}
|
|
636
|
+
function checkExpect(e, n, add) {
|
|
637
|
+
if (!e || typeof e !== 'object' || Array.isArray(e)) {
|
|
638
|
+
add('expectNotAnObject', n);
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
const kinds = EXPECT_KINDS.filter((k) => k in e);
|
|
642
|
+
if (kinds.length !== 1) {
|
|
643
|
+
add(kinds.length ? 'expectSeveralKinds' : 'expectUnknown', n, { keys: Object.keys(e).join(', ') });
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const kind = kinds[0];
|
|
647
|
+
if ((kind === 'value' || kind === 'shows') && !text(e.field))
|
|
648
|
+
add('fieldMissing', n, { kind });
|
|
649
|
+
if (kind === 'shows' && typeof e.shows !== 'string')
|
|
650
|
+
add('showsNotText', n);
|
|
651
|
+
if (kind === 'keyboard' && !text(e.keyboard))
|
|
652
|
+
add('keyboardMissing', n);
|
|
653
|
+
if (kind === 'list' && !LIST_STATES.includes(e.list))
|
|
654
|
+
add('unknownListState', n, { list: String(e.list) });
|
|
655
|
+
if (kind === 'message' && !text(e.message))
|
|
656
|
+
add('messageMissing', n);
|
|
657
|
+
if ((kind === 'visible' || kind === 'hidden' || kind === 'locked' || kind === 'blocked') && !text(e[kind]))
|
|
658
|
+
add('stepNameMissing', n, { kind });
|
|
659
|
+
if (kind === 'inFrame' && !FRAME_PARTS.includes(e.inFrame))
|
|
660
|
+
add('unknownFramePart', n, { part: String(e.inFrame) });
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-19
|
|
664
|
+
// - new: the test flow format of an app's .liveforge/tests (#166)
|
|
665
|
+
// Faramarz Yousefian and Agent Toni (Claude Opus 5.5) 2026-10-18
|
|
666
|
+
// - new: @yomotech/view-toolkit/catalog - the field catalog without Angular, for the Designer,
|
|
667
|
+
// node tests and the AI contract tools (#166)
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Generated bundle index. Do not edit.
|
|
671
|
+
*/
|
|
672
|
+
|
|
673
|
+
export { BASIC_TYPES, CONTROLS, CONTROL_TYPES, DATA_FORMATS, DEFAULT_DEVICES, DISPLAY_FORMATS, EXPECT_KINDS, FRAME_PARTS, KEYBOARD_CONTROLS, KEYBOARD_TYPES, LIST_STATES, NUMBER_STYLES, ORIENTATIONS, PLACEHOLDER_CONTROLS, RESULTS_DIR, RESULTS_KEEP, STEP_KINDS, SYSTEM_KEYBOARDS, TEMPORAL_TRANSFER, TESTS_DIR, TEST_DEVICES, TYPE_ALIASES, assertFieldSettings, baseType, basicType, canonicalControl, checkTestFlow, clone, controlsFor, dataSettings, defaultKeyboard, displaySettings, effectiveControl, effectiveFormat, flowDevices, keyboardFor, normalizeFormat, parseDevice, resolveProperty, resultsToDelete, rulesFor, stepKind, temporalPart, validateSettings, validationSettings };
|
|
674
|
+
//# sourceMappingURL=yomotech-view-toolkit-catalog.mjs.map
|