@uipath/maestro-builder-sdk 6.102.0 → 6.104.0
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/dist/api-index.md +20 -18
- package/dist/api-members.md +18 -17
- package/dist/bpmn/check.js +4 -0
- package/dist/case/check.d.ts +1 -1
- package/dist/case/check.js +4 -0
- package/dist/check.js +4 -0
- package/dist/core/connector-checks.d.ts +7 -0
- package/dist/core/connector-checks.js +12 -2
- package/dist/core/entity-schema.d.ts +94 -0
- package/dist/core/entity-schema.js +58 -0
- package/dist/core/event-checks.d.ts +3 -0
- package/dist/core/event-checks.js +17 -3
- package/dist/core/lookup-connection.d.ts +90 -0
- package/dist/core/lookup-connection.js +165 -0
- package/dist/core/lookups.d.ts +26 -0
- package/dist/core/lookups.js +30 -4
- package/dist/core/refusals.d.ts +8 -0
- package/dist/core/refusals.js +8 -0
- package/dist/core/resource-resolution.d.ts +9 -0
- package/dist/nodes/data-fabric/flow/check.js +214 -0
- package/dist/nodes/trigger/flow/check.js +193 -2
- package/dist/nodes/trigger/flow/spec.d.ts +10 -1
- package/dist/registry/prepare/entity-schema.d.ts +40 -0
- package/dist/registry/prepare/entity-schema.js +135 -0
- package/dist/registry/prepare/ledger.js +20 -10
- package/dist/registry/prepare/resources.d.ts +12 -5
- package/dist/registry/prepare/resources.js +26 -4
- package/dist/registry/prepare-cli.js +38 -3
- package/dist/registry/uip/commands.d.ts +19 -0
- package/dist/registry/uip/commands.js +25 -0
- package/package.json +2 -2
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { entityPrepareCommand, } from '../../../core/resource-resolution.js';
|
|
8
8
|
import { Expr } from '../../../core/expr.js';
|
|
9
|
+
import { nearestName } from '../../../core/edit-distance.js';
|
|
10
|
+
import { entityField, recordedEntitySchema, } from '../../../core/entity-schema.js';
|
|
9
11
|
export const DATA_FABRIC_DIAGNOSTICS = {
|
|
10
12
|
DATAFABRIC_NO_ENTITY: { severity: 'error', summary: 'a verb names no entity' },
|
|
11
13
|
DATAFABRIC_EMPTY_VALUES: { severity: 'error', summary: 'a create writes no non-blank column' },
|
|
@@ -20,6 +22,12 @@ export const DATA_FABRIC_DIAGNOSTICS = {
|
|
|
20
22
|
DATAFABRIC_FROMREAD_UNKNOWN: { severity: 'error', summary: '{ fromRead } names no read step' },
|
|
21
23
|
DATAFABRIC_FROMREAD_MULTIPLE: { severity: 'error', summary: "{ fromRead } names a resultMode: 'multiple' query" },
|
|
22
24
|
DATAFABRIC_DELETE_HAS_NO_OUTPUT: { severity: 'error', summary: "a read of a delete's output" },
|
|
25
|
+
DATAFABRIC_UNKNOWN_FIELD: { severity: 'error', summary: 'a column the recorded entity schema does not have' },
|
|
26
|
+
DATAFABRIC_FIELD_TYPE: { severity: 'error', summary: "a literal that is not a value of its column's type" },
|
|
27
|
+
DATAFABRIC_CHOICE_VALUE: { severity: 'error', summary: "a choice-set filter literal that is not one of the set's numberIds" },
|
|
28
|
+
DATAFABRIC_CHOICE_WRITE_VALUE: { severity: 'warning', summary: "a choice-set write literal that is not one of the set's numberIds" },
|
|
29
|
+
DATAFABRIC_NULL_REQUIRED: { severity: 'error', summary: 'an update that blanks a non-nullable column' },
|
|
30
|
+
DATAFABRIC_REQUIRED_MISSING: { severity: 'error', summary: 'a create that leaves a mandatory column out' },
|
|
23
31
|
};
|
|
24
32
|
function checkEntity(inputs, ctx) {
|
|
25
33
|
// An object is `{ name, folder }`, whose shape the serializer judges
|
|
@@ -34,6 +42,9 @@ export function checkRead(inputs, ctx) {
|
|
|
34
42
|
checkEntity(inputs, ctx);
|
|
35
43
|
checkQuery(inputs, ctx);
|
|
36
44
|
checkScope(inputs, ctx);
|
|
45
|
+
const schema = schemaOf(inputs, ctx);
|
|
46
|
+
if (schema !== undefined)
|
|
47
|
+
checkReadColumns(inputs, schema, ctx);
|
|
37
48
|
}
|
|
38
49
|
export function checkCreate(inputs, ctx) {
|
|
39
50
|
checkEntity(inputs, ctx);
|
|
@@ -50,6 +61,9 @@ export function checkCreate(inputs, ctx) {
|
|
|
50
61
|
}
|
|
51
62
|
checkColumns(Object.keys(inputs.values ?? {}), 'values', ctx);
|
|
52
63
|
checkScope(inputs, ctx);
|
|
64
|
+
const schema = schemaOf(inputs, ctx);
|
|
65
|
+
if (schema !== undefined)
|
|
66
|
+
checkWriteColumns(inputs.values ?? {}, 'values', schema, ctx);
|
|
53
67
|
}
|
|
54
68
|
export function checkUpdate(inputs, ctx) {
|
|
55
69
|
checkEntity(inputs, ctx);
|
|
@@ -58,6 +72,9 @@ export function checkUpdate(inputs, ctx) {
|
|
|
58
72
|
}
|
|
59
73
|
checkColumns(Object.keys(inputs.set ?? {}), 'set', ctx);
|
|
60
74
|
checkScope(inputs, ctx);
|
|
75
|
+
const schema = schemaOf(inputs, ctx);
|
|
76
|
+
if (schema !== undefined)
|
|
77
|
+
checkWriteColumns(inputs.set ?? {}, 'set', schema, ctx);
|
|
61
78
|
}
|
|
62
79
|
export function checkWrite(inputs, ctx) {
|
|
63
80
|
checkEntity(inputs, ctx);
|
|
@@ -171,3 +188,200 @@ export function checkFromRead(placements, ctx) {
|
|
|
171
188
|
}
|
|
172
189
|
}
|
|
173
190
|
}
|
|
191
|
+
// ─── Columns, against the schema `prepare --entity` recorded (#1980) ───────────
|
|
192
|
+
//
|
|
193
|
+
// Data Fabric DROPS a column it does not know rather than rejecting it, and the
|
|
194
|
+
// engine only LOGS a write Data Fabric refuses. So a misspelt filter field reads
|
|
195
|
+
// every record, a misspelt sort returns an arbitrary slice, a misspelt `set` key
|
|
196
|
+
// writes nothing, and a choice-set label in a filter matches nothing — each one
|
|
197
|
+
// validates clean and runs green. Nothing offline can tell a real column from a
|
|
198
|
+
// typo; the ledger can, once `prepare --entity` has read the entity's columns.
|
|
199
|
+
// With no recorded schema these rules say nothing, as before.
|
|
200
|
+
/** The schema recorded for the step's entity, or `undefined`. */
|
|
201
|
+
function schemaOf(inputs, ctx) {
|
|
202
|
+
if (inputs.entity === undefined || (typeof inputs.entity === 'string' && inputs.entity.trim() === ''))
|
|
203
|
+
return undefined;
|
|
204
|
+
return recordedEntitySchema(ctx.options.resources, {
|
|
205
|
+
entity: inputs.entity,
|
|
206
|
+
...(inputs.folderKey !== undefined ? { folderKey: inputs.folderKey } : {}),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/** Where the judged columns came from, and how to refresh them: the tail of every message. */
|
|
210
|
+
function provenance(schema) {
|
|
211
|
+
const { row } = schema;
|
|
212
|
+
const ref = row.folderPath !== null ? { name: row.name, folder: row.folderPath } : { name: row.name };
|
|
213
|
+
return ` (columns as \`registry prepare --entity\` recorded them at ${row.resolvedAt ?? 'an unknown time'}; `
|
|
214
|
+
+ `if the entity changed since, re-run ${entityPrepareCommand(ref)})`;
|
|
215
|
+
}
|
|
216
|
+
/** `"Stauts"` → `did you mean "Status"?`, or the column list when nothing is close. */
|
|
217
|
+
function nearMiss(name, fields) {
|
|
218
|
+
const names = fields.map((f) => f.name);
|
|
219
|
+
const near = nearestName(name, names);
|
|
220
|
+
if (near !== undefined)
|
|
221
|
+
return `did you mean ${JSON.stringify(near)}? (names are case-sensitive)`;
|
|
222
|
+
const own = fields.filter((f) => f.system !== true).map((f) => f.name);
|
|
223
|
+
return `its columns are ${own.map((n) => JSON.stringify(n)).join(', ')}, plus the system columns`;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The column a query names, or a reason it names none. A dotted related path
|
|
227
|
+
* (`customer.Name`) resolves its first segment, which must be a relationship
|
|
228
|
+
* column; the deeper segments are the related entity's, which the schema does
|
|
229
|
+
* not hold.
|
|
230
|
+
*/
|
|
231
|
+
function queryColumn(path, fields) {
|
|
232
|
+
const [head] = path.split('.');
|
|
233
|
+
const field = entityField(fields, head);
|
|
234
|
+
if (field === undefined)
|
|
235
|
+
return { problem: `has no column ${JSON.stringify(head)}: ${nearMiss(head, fields)}` };
|
|
236
|
+
if (path.includes('.') && field.reference === undefined) {
|
|
237
|
+
return { problem: `has no relationship column ${JSON.stringify(head)} to reach ${JSON.stringify(path)} through: ${JSON.stringify(head)} is ${field.type}` };
|
|
238
|
+
}
|
|
239
|
+
return path.includes('.') ? {} : { field };
|
|
240
|
+
}
|
|
241
|
+
function checkReadColumns(inputs, schema, ctx) {
|
|
242
|
+
const entity = JSON.stringify(schema.row.name);
|
|
243
|
+
const unknown = (path, where, effect, problem) => {
|
|
244
|
+
ctx.report('DATAFABRIC_UNKNOWN_FIELD', `"${ctx.step}" ${where} ${JSON.stringify(path)}, but entity ${entity} ${problem}. `
|
|
245
|
+
+ `Data Fabric drops a column it does not know instead of rejecting it, so ${effect}.${provenance(schema)}`);
|
|
246
|
+
};
|
|
247
|
+
for (const f of inputs.filters ?? []) {
|
|
248
|
+
const { field, problem } = queryColumn(f.field, schema.fields);
|
|
249
|
+
if (problem !== undefined) {
|
|
250
|
+
unknown(f.field, 'filters on', 'the row filters nothing and the read matches more records than meant', problem);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (field !== undefined)
|
|
254
|
+
checkValue(field, f.value, `its filter on ${JSON.stringify(f.field)}`, f.operator ?? '=', schema, ctx);
|
|
255
|
+
}
|
|
256
|
+
if (inputs.sort !== undefined) {
|
|
257
|
+
const { problem } = queryColumn(inputs.sort.field, schema.fields);
|
|
258
|
+
if (problem !== undefined)
|
|
259
|
+
unknown(inputs.sort.field, 'sorts on', 'the rows come back unsorted and a limited slice is arbitrary', problem);
|
|
260
|
+
}
|
|
261
|
+
for (const name of inputs.fields ?? []) {
|
|
262
|
+
const { problem } = queryColumn(name, schema.fields);
|
|
263
|
+
if (problem !== undefined)
|
|
264
|
+
unknown(name, 'selects', 'the column is simply missing from every record the step publishes', problem);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/** A column Data Fabric lets a write set: not system-assigned, not a file, not an auto-number. */
|
|
268
|
+
function writable(field) {
|
|
269
|
+
return field.system !== true && field.attachment !== true && field.autoNumber !== true && !SYSTEM_COLUMNS.has(field.name);
|
|
270
|
+
}
|
|
271
|
+
const isBlank = (v) => !(v instanceof Expr) && String(v ?? '').trim() === '';
|
|
272
|
+
function checkWriteColumns(values, option, schema, ctx) {
|
|
273
|
+
const entity = JSON.stringify(schema.row.name);
|
|
274
|
+
for (const [name, value] of Object.entries(values)) {
|
|
275
|
+
// System columns are DATAFABRIC_SYSTEM_COLUMN's, whatever the schema says.
|
|
276
|
+
if (SYSTEM_COLUMNS.has(name))
|
|
277
|
+
continue;
|
|
278
|
+
const field = entityField(schema.fields, name);
|
|
279
|
+
if (field === undefined) {
|
|
280
|
+
ctx.report('DATAFABRIC_UNKNOWN_FIELD', `"${ctx.step}" writes ${JSON.stringify(name)} in { ${option} }, but entity ${entity} has no such column: `
|
|
281
|
+
+ `${nearMiss(name, schema.fields)}. Data Fabric drops a column it does not know instead of rejecting it, so the `
|
|
282
|
+
+ `${option === 'set' ? 'update' : 'create'} runs green without writing it.${provenance(schema)}`);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
// A blank update writes an explicit null (flow-workbench `buildWriteBodyFromFieldValues`,
|
|
286
|
+
// `emptyValue: 'null'`), which a non-nullable column rejects — and the engine
|
|
287
|
+
// only logs the rejection. A blank create is omitted instead, which is the
|
|
288
|
+
// missing-column rule below.
|
|
289
|
+
if (option === 'set' && isBlank(value) && field.required && writable(field)) {
|
|
290
|
+
ctx.report('DATAFABRIC_NULL_REQUIRED', `"${ctx.step}" sets ${JSON.stringify(name)} to a blank value, which an update writes as null, `
|
|
291
|
+
+ `but ${JSON.stringify(name)} is required (non-nullable) on entity ${entity}. Data Fabric rejects the write and the engine only `
|
|
292
|
+
+ `logs it, so the record comes back unchanged and the run goes green.${provenance(schema)}`, `give ${JSON.stringify(name)} a real value, or leave it out of { set } to keep the current one`);
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
checkValue(field, value, `{ ${option} } ${JSON.stringify(name)}`, '=', schema, ctx);
|
|
296
|
+
}
|
|
297
|
+
if (option === 'values') {
|
|
298
|
+
// What an insert must carry: required, writable, and with no server default
|
|
299
|
+
// (flow-workbench `isMandatoryEntityWriteField`). A blank is omitted from the
|
|
300
|
+
// insert, so it counts as missing.
|
|
301
|
+
const missing = schema.fields.filter((f) => f.required && f.hasDefault !== true && writable(f)
|
|
302
|
+
&& (!Object.hasOwn(values, f.name) || isBlank(values[f.name])));
|
|
303
|
+
if (missing.length) {
|
|
304
|
+
ctx.report('DATAFABRIC_REQUIRED_MISSING', `"${ctx.step}" creates a record without ${missing.map((f) => JSON.stringify(f.name)).join(', ')}, `
|
|
305
|
+
+ `which entity ${entity} requires and has no default for. Data Fabric rejects the insert and the engine only logs it, so the run `
|
|
306
|
+
+ `goes green having created nothing.${provenance(schema)}`, `values: { ${missing.map((f) => `${f.name}: <value>`).join(', ')} }`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/** The operators whose value is one value of the column's type; `contains` and friends match text, `in` takes a list. */
|
|
311
|
+
const TYPED_OPERATORS = new Set(['=', '!=', '>', '>=', '<', '<=']);
|
|
312
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
313
|
+
/** What a literal of the column's type looks like, or `undefined` for a type whose text anything can be. */
|
|
314
|
+
function typeShape(type) {
|
|
315
|
+
switch (type) {
|
|
316
|
+
case 'INTEGER':
|
|
317
|
+
case 'BIG_INTEGER':
|
|
318
|
+
case 'AUTO_NUMBER':
|
|
319
|
+
return { test: (v) => /^-?\d+$/.test(v), what: 'a whole number', example: "'42'" };
|
|
320
|
+
case 'DECIMAL':
|
|
321
|
+
case 'FLOAT':
|
|
322
|
+
case 'DOUBLE':
|
|
323
|
+
return { test: (v) => /^-?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?$/.test(v), what: 'a number', example: "'12.50'" };
|
|
324
|
+
case 'BOOLEAN':
|
|
325
|
+
// Any case: nothing shows Data Fabric rejects `'True'`, so check does not either.
|
|
326
|
+
return { test: (v) => /^(true|false)$/i.test(v), what: "'true' or 'false'", example: "'true'" };
|
|
327
|
+
case 'UUID':
|
|
328
|
+
case 'RELATIONSHIP':
|
|
329
|
+
return { test: (v) => UUID.test(v), what: 'a record id (a GUID)', example: "'3f2c…-…'" };
|
|
330
|
+
case 'DATE':
|
|
331
|
+
return { test: (v) => /^\d{4}-\d{2}-\d{2}$/.test(v), what: 'a date, YYYY-MM-DD', example: "'2026-11-13'" };
|
|
332
|
+
case 'DATETIME':
|
|
333
|
+
case 'DATETIME_WITH_TZ':
|
|
334
|
+
return {
|
|
335
|
+
test: (v) => /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/.test(v) && Number.isFinite(Date.parse(v)),
|
|
336
|
+
what: 'an ISO 8601 date-time', example: "'2026-11-13T09:30:00Z'",
|
|
337
|
+
};
|
|
338
|
+
default:
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* A literal against its column: a choice-set column takes one of the set's
|
|
344
|
+
* `numberId`s, never a label; any other typed column takes a value of its type.
|
|
345
|
+
* An expression is judged at run time, and a blank is the blank rules' business.
|
|
346
|
+
*/
|
|
347
|
+
function checkValue(field, value, where, operator, schema, ctx) {
|
|
348
|
+
if (value instanceof Expr || typeof value !== 'string')
|
|
349
|
+
return;
|
|
350
|
+
const literal = value.trim();
|
|
351
|
+
if (literal === '' || literal.startsWith('=js:') || !TYPED_OPERATORS.has(operator))
|
|
352
|
+
return;
|
|
353
|
+
if (field.type === 'CHOICE_SET_SINGLE') {
|
|
354
|
+
const choices = field.choiceSet?.values;
|
|
355
|
+
if (choices === undefined || choices.length === 0)
|
|
356
|
+
return;
|
|
357
|
+
if (/^-?\d+$/.test(literal) && choices.some((c) => c.numberId === Number(literal)))
|
|
358
|
+
return;
|
|
359
|
+
const lower = literal.toLowerCase();
|
|
360
|
+
const label = choices.find((c) => c.name.toLowerCase() === lower || c.displayName?.toLowerCase() === lower);
|
|
361
|
+
const set = `choice set ${JSON.stringify(field.choiceSet.name || field.choiceSet.id)}`;
|
|
362
|
+
const listed = choices.map((c) => `${c.numberId} = ${c.displayName ?? c.name}`).join(', ');
|
|
363
|
+
// A filter compares the numberId (the platform's query; a label matches
|
|
364
|
+
// nothing), so a filter is an error. That a WRITE stores only the numberId,
|
|
365
|
+
// and drops a label, is not confirmed, so a write is a warning.
|
|
366
|
+
if (!where.startsWith('its filter')) {
|
|
367
|
+
ctx.report('DATAFABRIC_CHOICE_WRITE_VALUE', label !== undefined
|
|
368
|
+
? `"${ctx.step}": ${where} writes the label ${JSON.stringify(literal)} to ${JSON.stringify(field.name)}, a ${set} column, which stores `
|
|
369
|
+
+ `the choice's numberId. A filter on a label matches nothing; a write of one may be dropped too. Write the numberId.${provenance(schema)}`
|
|
370
|
+
: `"${ctx.step}": ${where} is ${JSON.stringify(literal)}, which is not a value of ${set} (${listed}).${provenance(schema)}`, label !== undefined ? `'${label.numberId}' (${label.displayName ?? label.name})` : `one of: ${listed}`);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
ctx.report('DATAFABRIC_CHOICE_VALUE', label !== undefined
|
|
374
|
+
? `"${ctx.step}": ${where} uses the label ${JSON.stringify(literal)}, but ${JSON.stringify(field.name)} is a ${set} column, which `
|
|
375
|
+
+ `compares the choice's numberId, never its label — a label matches nothing, silently.${provenance(schema)}`
|
|
376
|
+
: `"${ctx.step}": ${where} is ${JSON.stringify(literal)}, which is not a value of ${set} (${listed}).${provenance(schema)}`, label !== undefined ? `'${label.numberId}' (${label.displayName ?? label.name})` : `one of: ${listed}`);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
const shape = typeShape(field.type);
|
|
380
|
+
if (shape === undefined || shape.test(literal))
|
|
381
|
+
return;
|
|
382
|
+
ctx.report('DATAFABRIC_FIELD_TYPE', `"${ctx.step}": ${where} is ${JSON.stringify(literal)}, but ${JSON.stringify(field.name)} is ${field.type} and takes ${shape.what}. `
|
|
383
|
+
+ (where.startsWith('its filter')
|
|
384
|
+
? 'Data Fabric cannot compare the column with it, so the read matches nothing or faults at run time.'
|
|
385
|
+
: 'Data Fabric rejects the value and the engine only logs the rejection, so the write runs green without it.')
|
|
386
|
+
+ provenance(schema), `a literal like ${shape.example}, or an expression that produces one`);
|
|
387
|
+
}
|
|
@@ -4,6 +4,7 @@ export const TRIGGER_DIAGNOSTICS = {
|
|
|
4
4
|
SCHEDULE_NO_INTERVAL: { severity: 'error', summary: 'a schedule with no `every`, so it never starts the flow' },
|
|
5
5
|
SCHEDULE_NOT_ISO: { severity: 'error', summary: '`every` is not an ISO-8601 repeating interval or a Quartz cron expression' },
|
|
6
6
|
SCHEDULE_NEVER_FIRES: { severity: 'error', summary: 'a zero-length interval, so the schedule never comes round' },
|
|
7
|
+
SCHEDULE_CRON_INVALID: { severity: 'error', summary: 'a cron expression Orchestrator refuses at deploy: both day fields set (no `?`), a seconds field that is not one number, a value out of range, or a special in the wrong field' },
|
|
7
8
|
FORM_TRIGGER_NO_INPUTS: { severity: 'error', summary: 'a form trigger on a root with no inputs, so the form has no fields' },
|
|
8
9
|
TRIGGER_INPUTS_IGNORED: { severity: 'warning', summary: 'an entry point declares inputs its trigger never passes' },
|
|
9
10
|
SINGLE_CONVERSATION_TRIGGER: { severity: 'error', summary: 'a second root started by a conversation' },
|
|
@@ -107,8 +108,16 @@ export function checkSchedule(spec, ctx) {
|
|
|
107
108
|
const every = String(raw).trim();
|
|
108
109
|
if (SCHEDULE_CRON_RE.test(every.trim())) {
|
|
109
110
|
// A Quartz cron expression — admitted by the scheduled trigger's 1.2
|
|
110
|
-
// definition (the serializer selects it automatically).
|
|
111
|
-
//
|
|
111
|
+
// definition (the serializer selects it automatically). The definition's
|
|
112
|
+
// pattern checks each field's characters only, so `validate` accepts
|
|
113
|
+
// `0 30 9 * * MON-FRI`, and Orchestrator refuses it at deploy ([1600]
|
|
114
|
+
// "Invalid cron expression syntax", #1087). The field rules Quartz applies
|
|
115
|
+
// are checked here; the ISO rules below do not apply to cron.
|
|
116
|
+
const problem = quartzCronProblem(every);
|
|
117
|
+
if (problem !== undefined) {
|
|
118
|
+
at('SCHEDULE_CRON_INVALID', `The scheduled trigger's cron expression ${JSON.stringify(every)} is one Orchestrator does not accept. `
|
|
119
|
+
+ `${problem.reasons.join(' ')} Quartz fields: second minute hour day-of-month month day-of-week [year].`, problem.fixed === undefined ? undefined : `every: '${problem.fixed}'`);
|
|
120
|
+
}
|
|
112
121
|
return;
|
|
113
122
|
}
|
|
114
123
|
if (!SCHEDULE_RE.test(every)) {
|
|
@@ -127,6 +136,188 @@ export function checkSchedule(spec, ctx) {
|
|
|
127
136
|
+ `comes round. Use a non-zero interval.`, `every: 'R/PT1H'`);
|
|
128
137
|
}
|
|
129
138
|
}
|
|
139
|
+
const MONTH_NAMES = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
|
|
140
|
+
const DAY_NAMES = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
|
|
141
|
+
const CRON_FIELDS = [
|
|
142
|
+
{ name: 'second', min: 0, max: 59 },
|
|
143
|
+
{ name: 'minute', min: 0, max: 59 },
|
|
144
|
+
{ name: 'hour', min: 0, max: 23 },
|
|
145
|
+
{ name: 'day-of-month', min: 1, max: 31 },
|
|
146
|
+
{ name: 'month', min: 1, max: 12, names: MONTH_NAMES },
|
|
147
|
+
{ name: 'day-of-week', min: 1, max: 7, names: DAY_NAMES },
|
|
148
|
+
{ name: 'year', min: 1970, max: 2099 },
|
|
149
|
+
];
|
|
150
|
+
const SECOND = 0;
|
|
151
|
+
const DOM = 3;
|
|
152
|
+
const DOW = 5;
|
|
153
|
+
const YEAR = 6;
|
|
154
|
+
/**
|
|
155
|
+
* Why Orchestrator refuses a cron expression that already matches the
|
|
156
|
+
* definition's pattern (6 or 7 fields of the allowed characters), every reason
|
|
157
|
+
* at once, and the corrected expression when every reason has one clear fix;
|
|
158
|
+
* `undefined` when it is accepted.
|
|
159
|
+
*
|
|
160
|
+
* The rules are Quartz's own (`CronExpression`, the parser Orchestrator's
|
|
161
|
+
* scheduler uses), plus Orchestrator's own recurrence rule:
|
|
162
|
+
* - exactly one of day-of-month and day-of-week is `?` ("Support for
|
|
163
|
+
* specifying both a day-of-week AND a day-of-month parameter is not
|
|
164
|
+
* implemented"): deploy answers `[1600]` (#1087, observed);
|
|
165
|
+
* - the seconds field is one number: Orchestrator's `ScheduleValidator.
|
|
166
|
+
* IsValidRecurrence` parses it with `int.TryParse`, and anything else
|
|
167
|
+
* (`0/30`, `*`) is `[1609] InvalidCronRecurrence` (#2010 review);
|
|
168
|
+
* - `?` only in the two day fields; every number in its field's range, and
|
|
169
|
+
* day-of-week 1-7 (SUN-SAT); month names only in month, day names only in
|
|
170
|
+
* day-of-week; `L` only in the two day fields, `W` only in day-of-month,
|
|
171
|
+
* `#` only in day-of-week; a step at most the field's maximum;
|
|
172
|
+
* - `L` with other days in a list ("... 'L' with other days ... is not
|
|
173
|
+
* implemented"), more than one `#` in day-of-week ("multiple 'nth' days"),
|
|
174
|
+
* and a descending year range ("Start year must be less than stop year").
|
|
175
|
+
*/
|
|
176
|
+
function quartzCronProblem(every) {
|
|
177
|
+
const fields = every.trim().split(/\s+/);
|
|
178
|
+
const reasons = [];
|
|
179
|
+
const fixedFields = [...fields];
|
|
180
|
+
let fixable = true;
|
|
181
|
+
for (let i = 0; i < fields.length; i++) {
|
|
182
|
+
const problem = cronFieldProblem(fields[i], i);
|
|
183
|
+
if (problem === undefined)
|
|
184
|
+
continue;
|
|
185
|
+
reasons.push(problem.reason);
|
|
186
|
+
if (problem.fix === undefined)
|
|
187
|
+
fixable = false;
|
|
188
|
+
else
|
|
189
|
+
fixedFields[i] = problem.fix;
|
|
190
|
+
}
|
|
191
|
+
// The day rule is judged on the fields as fixed, so `0 30 9 * * 0` gets both
|
|
192
|
+
// findings, and one suggestion, in one round.
|
|
193
|
+
const dom = fixedFields[DOM];
|
|
194
|
+
const dow = fixedFields[DOW];
|
|
195
|
+
if (dom !== '?' && dow !== '?') {
|
|
196
|
+
reasons.push(`Day-of-month (${JSON.stringify(dom)}) and day-of-week (${JSON.stringify(dow)}) are both set, and `
|
|
197
|
+
+ 'Quartz needs `?` ("no specific value") in exactly one of them: `?` in day-of-month to run on the weekdays '
|
|
198
|
+
+ 'given, or `?` in day-of-week to run on the days of the month given. Deploy refuses it with '
|
|
199
|
+
+ '"[1600] Invalid cron expression syntax".');
|
|
200
|
+
// `*` means "any day", so `?` in its place says the same thing. With values
|
|
201
|
+
// in both, either fix changes the schedule, so none is suggested.
|
|
202
|
+
if (dom === '*')
|
|
203
|
+
fixedFields[DOM] = '?';
|
|
204
|
+
else if (dow === '*')
|
|
205
|
+
fixedFields[DOW] = '?';
|
|
206
|
+
else
|
|
207
|
+
fixable = false;
|
|
208
|
+
}
|
|
209
|
+
else if (dom === '?' && dow === '?') {
|
|
210
|
+
reasons.push('Day-of-month and day-of-week are both `?`, and Quartz needs a value in exactly one of them (`*` for '
|
|
211
|
+
+ 'every day). Deploy refuses it with "[1600] Invalid cron expression syntax".');
|
|
212
|
+
fixedFields[DOW] = '*';
|
|
213
|
+
}
|
|
214
|
+
if (reasons.length === 0)
|
|
215
|
+
return undefined;
|
|
216
|
+
return fixable ? { reasons, fixed: fixedFields.join(' ') } : { reasons };
|
|
217
|
+
}
|
|
218
|
+
/** Why one field is out of the rules, and the field's fix when one is clear; `undefined` when it is fine. */
|
|
219
|
+
function cronFieldProblem(value, index) {
|
|
220
|
+
const field = CRON_FIELDS[index];
|
|
221
|
+
const where = `Field ${index + 1} (${field.name}) is ${JSON.stringify(value)}`;
|
|
222
|
+
const refused = (why, fix) => ({ reason: `${where}: ${why}`, ...(fix !== undefined ? { fix } : {}) });
|
|
223
|
+
if (value === '?') {
|
|
224
|
+
return index === DOM || index === DOW ? undefined : refused('`?` is allowed only in day-of-month and day-of-week.');
|
|
225
|
+
}
|
|
226
|
+
for (const item of value.split(',')) {
|
|
227
|
+
const reason = cronItemProblem(item, index, field);
|
|
228
|
+
if (reason === undefined)
|
|
229
|
+
continue;
|
|
230
|
+
// A Unix Sunday alone has one clear fix.
|
|
231
|
+
return refused(reason, index === DOW && value === '0' ? 'SUN' : undefined);
|
|
232
|
+
}
|
|
233
|
+
const items = value.split(',');
|
|
234
|
+
if (items.length > 1 && (index === DOM || index === DOW) && /L/.test(value)) {
|
|
235
|
+
return refused('Quartz does not take `L` together with other days in a list.');
|
|
236
|
+
}
|
|
237
|
+
if (index === DOW && (value.match(/#/g) ?? []).length > 1) {
|
|
238
|
+
return refused('Quartz does not take more than one `#` ("nth weekday") in day-of-week.');
|
|
239
|
+
}
|
|
240
|
+
if (index === YEAR) {
|
|
241
|
+
const descending = items.map((item) => /^(\d+)-(\d+)/.exec(item)).find((m) => m !== null && Number(m[1]) > Number(m[2]));
|
|
242
|
+
if (descending)
|
|
243
|
+
return refused(`the range ${descending[0]} runs backwards; a year range goes from the earlier year to the later.`);
|
|
244
|
+
}
|
|
245
|
+
if (index === SECOND && !/^\d+$/.test(value)) {
|
|
246
|
+
return refused('Orchestrator takes one number in the seconds field, and deploy refuses anything else with '
|
|
247
|
+
+ '"[1609] InvalidCronRecurrence" (the recurrence must be at least one minute). Write a single second, such as `0`.', '0');
|
|
248
|
+
}
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
/** Why one comma-separated item of a field is out of Quartz's rules, or `undefined`. */
|
|
252
|
+
function cronItemProblem(item, index, field) {
|
|
253
|
+
const range = `${field.min}-${field.max}`;
|
|
254
|
+
if (item === '?')
|
|
255
|
+
return '`?` must be the whole field, not part of a list.';
|
|
256
|
+
// The two day fields' specials.
|
|
257
|
+
if (index === DOM) {
|
|
258
|
+
if (item === 'L' || item === 'LW')
|
|
259
|
+
return undefined;
|
|
260
|
+
const lastOffset = /^L-(\d+)$/.exec(item);
|
|
261
|
+
if (lastOffset)
|
|
262
|
+
return Number(lastOffset[1]) <= 30 ? undefined : '`L-n` takes an offset of at most 30.';
|
|
263
|
+
const weekday = /^(\d+)W$/.exec(item);
|
|
264
|
+
if (weekday)
|
|
265
|
+
return numberProblem(weekday[1], field, range);
|
|
266
|
+
}
|
|
267
|
+
else if (index === DOW) {
|
|
268
|
+
if (item === 'L')
|
|
269
|
+
return undefined;
|
|
270
|
+
const special = /^(\d+|[A-Z]{3})(L|#(\d+))$/.exec(item);
|
|
271
|
+
if (special) {
|
|
272
|
+
const day = dayProblem(special[1], field, range);
|
|
273
|
+
if (day !== undefined)
|
|
274
|
+
return day;
|
|
275
|
+
if (special[3] !== undefined && !/^[1-5]$/.test(special[3]))
|
|
276
|
+
return '`#n` names the nth weekday of the month, 1-5.';
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (/[LW#]/.test(item.replace(/^[A-Z]{3}/, '').replace(/-[A-Z]{3}/, ''))) {
|
|
281
|
+
return '`L` is allowed only in the two day fields, `W` only in day-of-month, and `#` only in day-of-week.';
|
|
282
|
+
}
|
|
283
|
+
const [base, step, extra] = item.split('/');
|
|
284
|
+
if (extra !== undefined)
|
|
285
|
+
return 'a step has one `/`.';
|
|
286
|
+
if (step !== undefined) {
|
|
287
|
+
if (!/^\d+$/.test(step))
|
|
288
|
+
return 'the step after `/` is a number.';
|
|
289
|
+
if (Number(step) > field.max)
|
|
290
|
+
return `the step after \`/\` is at most ${field.max}.`;
|
|
291
|
+
}
|
|
292
|
+
if (base === '*')
|
|
293
|
+
return undefined;
|
|
294
|
+
const bounds = base.split('-');
|
|
295
|
+
if (bounds.length > 2)
|
|
296
|
+
return 'a range has one `-`.';
|
|
297
|
+
for (const bound of bounds) {
|
|
298
|
+
const reason = dayProblem(bound, field, range);
|
|
299
|
+
if (reason !== undefined)
|
|
300
|
+
return reason;
|
|
301
|
+
}
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
/** A number or a name in a field: the name must be one the field takes. */
|
|
305
|
+
function dayProblem(token, field, range) {
|
|
306
|
+
if (/^\d+$/.test(token))
|
|
307
|
+
return numberProblem(token, field, range);
|
|
308
|
+
if (field.names === undefined)
|
|
309
|
+
return `${field.name} takes numbers only (${range}).`;
|
|
310
|
+
return field.names.includes(token) ? undefined : `\`${token}\` is not a ${field.name} name (${field.names[0]}-${field.names[field.names.length - 1]}).`;
|
|
311
|
+
}
|
|
312
|
+
function numberProblem(token, field, range) {
|
|
313
|
+
const n = Number(token);
|
|
314
|
+
if (n >= field.min && n <= field.max)
|
|
315
|
+
return undefined;
|
|
316
|
+
if (field.names === DAY_NAMES && n === 0) {
|
|
317
|
+
return '`0` is out of range 1-7: Quartz counts day-of-week from Sunday = 1 (SUN), unlike Unix cron. Write SUN or 1.';
|
|
318
|
+
}
|
|
319
|
+
return `${n} is out of range ${range}.`;
|
|
320
|
+
}
|
|
130
321
|
/** Best guess at what the author meant, for a `SCHEDULE_NOT_ISO` suggestion. */
|
|
131
322
|
function nearestInterval(every) {
|
|
132
323
|
// By far the likeliest slip: a correct duration missing the "R/" repeat marker.
|
|
@@ -28,9 +28,18 @@ export type SchedulePreset = (typeof SCHEDULE_PRESETS)[number];
|
|
|
28
28
|
export type ScheduleEvery = SchedulePreset | (string & {});
|
|
29
29
|
export interface ScheduledInputs {
|
|
30
30
|
/**
|
|
31
|
-
* The recurring interval, e.g. `'R/PT1H'` for hourly
|
|
31
|
+
* The recurring interval, e.g. `'R/PT1H'` for hourly, or a Quartz cron
|
|
32
|
+
* expression, e.g. `'0 30 9 ? * MON-FRI'` for 09:30 on weekdays.
|
|
32
33
|
*
|
|
33
34
|
* @remarks
|
|
35
|
+
* A Quartz cron has six fields, plus an optional year: second, minute, hour,
|
|
36
|
+
* day-of-month, month, day-of-week. Exactly one of the two day fields is `?`,
|
|
37
|
+
* and the seconds field is one number (Orchestrator refuses `0/30` or `*`
|
|
38
|
+
* there: a schedule recurs at most once a minute). Quartz numbers weekdays 1-7 from Sunday (`1` = SUN), not 0-6 as Unix cron
|
|
39
|
+
* does, so a Unix `1-5` means Sunday to Thursday here; day names (`MON-FRI`)
|
|
40
|
+
* avoid that. `check` refuses a cron Quartz or Orchestrator would refuse
|
|
41
|
+
* (`SCHEDULE_CRON_INVALID`).
|
|
42
|
+
*
|
|
34
43
|
* ONE field. At 1.2, the default, the emitted `.flow` has one too:
|
|
35
44
|
* `timerValue`. Pinned to 1.1 it has two: the 1.1 designer form encodes a
|
|
36
45
|
* preset in `timerPreset` and anything else as `timerPreset: 'custom'` +
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a Data Fabric entity's columns from the tenant, for `registry prepare
|
|
3
|
+
* --entity` to record beside its keys (#1980). `check` validates a step's
|
|
4
|
+
* column names, value types, choice-set values and nullability against them
|
|
5
|
+
* (`core/entity-schema.ts`).
|
|
6
|
+
*
|
|
7
|
+
* Two reads, both read-only:
|
|
8
|
+
*
|
|
9
|
+
* - `uip df entities get <id> [--folder-key <key>]` gives every column: its name,
|
|
10
|
+
* `FieldDataType.Name`, `IsRequired`, `IsSystemField`, `DefaultValue`, and for a
|
|
11
|
+
* relationship or choice-set column what it points at.
|
|
12
|
+
* - `uip df choice-sets list-values <id> [--folder-key <key>]`, once per choice
|
|
13
|
+
* set, gives each value's `NumberId`: a filter on a choice-set column compares
|
|
14
|
+
* the number, never the label, and a label matches nothing.
|
|
15
|
+
*/
|
|
16
|
+
import type { EntityFieldSchema } from "../../core/entity-schema.js";
|
|
17
|
+
import type { UipClient } from "../uip/client.js";
|
|
18
|
+
/** Which entity to read: the id `entities get` takes, and the folder key of a folder-scoped one. */
|
|
19
|
+
export interface EntitySchemaTarget {
|
|
20
|
+
id: string;
|
|
21
|
+
folderKey?: string;
|
|
22
|
+
}
|
|
23
|
+
/** One raw `Fields[]` entry as the recorded column, or `undefined` for one with no name. */
|
|
24
|
+
export declare function fieldSchema(raw: unknown): EntityFieldSchema | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* The entity's columns, with each choice set's values.
|
|
27
|
+
*
|
|
28
|
+
* A choice set that cannot be read leaves that column's `values` out, with a
|
|
29
|
+
* warning: its column is still checked by name and type, only not by value.
|
|
30
|
+
*
|
|
31
|
+
* @param client - The `uip` client every call goes through.
|
|
32
|
+
* @param target - The entity's id, and the folder key of a folder-scoped one.
|
|
33
|
+
* @param cwd - Where to run `uip`.
|
|
34
|
+
* @returns The columns, in the order the tenant lists them, and a warning per choice set left unread.
|
|
35
|
+
* @throws Refusal `ENTITY_SCHEMA_UNREAD` when `entities get` fails or returns no columns.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readEntitySchema(client: UipClient, target: EntitySchemaTarget, cwd: string): Promise<{
|
|
38
|
+
fields: EntityFieldSchema[];
|
|
39
|
+
warnings: string[];
|
|
40
|
+
}>;
|