@uipath/maestro-builder-sdk 6.101.0 → 6.103.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 +22 -22
- package/dist/api-members.md +30 -30
- package/dist/core/actions.d.ts +6 -0
- package/dist/core/actions.js +7 -0
- package/dist/core/binding-messages.d.ts +33 -1
- package/dist/core/binding-messages.js +51 -0
- package/dist/core/connector-option-keys.d.ts +4 -0
- package/dist/core/connector-option-keys.js +9 -0
- package/dist/core/entity-schema.d.ts +94 -0
- package/dist/core/entity-schema.js +58 -0
- package/dist/core/event-subscription.d.ts +8 -0
- package/dist/core/event-subscription.js +2 -4
- package/dist/core/nodes/node-type.d.ts +25 -0
- package/dist/core/nodes/versioned.d.ts +3 -1
- package/dist/core/nodes/versioned.js +1 -0
- package/dist/core/option-keys.d.ts +62 -0
- package/dist/core/option-keys.js +66 -0
- package/dist/core/refusals.d.ts +10 -0
- package/dist/core/refusals.js +12 -0
- package/dist/core/resource-resolution.d.ts +9 -0
- package/dist/flow-node-type.d.ts +31 -1
- package/dist/flow-option-keys.d.ts +22 -0
- package/dist/flow-option-keys.js +33 -0
- package/dist/flow-sdk.js +5 -9
- package/dist/nodes/agent/flow/inline-agent.js +2 -4
- package/dist/nodes/agent/flow/node-type.js +12 -0
- package/dist/nodes/ai-patterns/flow/node-type.js +6 -0
- package/dist/nodes/connector/flow/event-trigger.js +4 -2
- package/dist/nodes/connector/flow/event-wait.js +4 -2
- package/dist/nodes/connector/flow/node-type.js +5 -4
- package/dist/nodes/connector/flow/raw-node.js +1 -1
- package/dist/nodes/conversation/flow/node-type.js +9 -0
- package/dist/nodes/data-fabric/flow/check.js +214 -0
- package/dist/nodes/data-fabric/flow/verbs.js +10 -0
- package/dist/nodes/delay/flow/node-type.js +4 -0
- package/dist/nodes/document/flow/ixp.js +4 -0
- package/dist/nodes/document/flow/node-type.js +6 -0
- package/dist/nodes/hitl/flow/node-type.js +4 -0
- package/dist/nodes/http/flow/check.js +55 -0
- package/dist/nodes/http/flow/node-type.js +7 -4
- package/dist/nodes/process/flow/node-type.js +10 -0
- package/dist/nodes/queue/flow/node-type.js +4 -0
- package/dist/nodes/script/flow/node-type.js +4 -0
- package/dist/nodes/transform/flow/node-type.js +4 -0
- package/dist/nodes/trigger/flow/check.js +193 -2
- package/dist/nodes/trigger/flow/node-type.js +6 -0
- 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/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/dist/serialize.js +73 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { nearestName } from '../../../core/edit-distance.js';
|
|
2
2
|
import { escapeRegExp } from '../../../core/escape-regexp.js';
|
|
3
3
|
import { isJsExpressionValue } from '../../../core/wire-expr.js';
|
|
4
|
+
import { Expr } from '../../../core/expr.js';
|
|
4
5
|
export const HTTP_DIAGNOSTICS = {
|
|
5
6
|
HTTP_V1_RETIRED: { severity: 'warning', summary: 'the plain node is retired on the tenant registry' },
|
|
6
7
|
HTTP_BINDING_REQUIRES_MANAGED: { severity: 'error', summary: 'connection settings on the standalone node' },
|
|
@@ -18,6 +19,7 @@ export const HTTP_DIAGNOSTICS = {
|
|
|
18
19
|
HTTP_READ_UNKNOWN_FIELD: { severity: 'error', summary: 'a read outside the response envelope or the declared body' },
|
|
19
20
|
HTTP_READ_WITHOUT_RETURNS: { severity: 'error', summary: 'a body field read with no `returns`' },
|
|
20
21
|
HTTP_ONERROR_V1: { severity: 'error', summary: '.onError() on the plain node' },
|
|
22
|
+
HTTP_LITERAL_SECRET_HEADER: { severity: 'warning', summary: 'a literal credential in an Authorization or API-key header, stored in the .flow as plain text' },
|
|
21
23
|
};
|
|
22
24
|
/**
|
|
23
25
|
* An ISO-8601 DURATION, which is what both http definitions declare `timeout` to
|
|
@@ -37,6 +39,58 @@ const ISO8601_DURATION = /^P(?!$)(\d+(?:\.\d+)?Y)?(\d+(?:\.\d+)?M)?(\d+(?:\.\d+)
|
|
|
37
39
|
* (it refuses something that works); a too-wide one costs nothing.
|
|
38
40
|
*/
|
|
39
41
|
const RETRY_COUNT_SOFT_MAX = 5;
|
|
42
|
+
/**
|
|
43
|
+
* Header names that carry a credential: `Authorization` and
|
|
44
|
+
* `Proxy-Authorization`, and any name with an `api-key`, `apikey`, `token`,
|
|
45
|
+
* `secret`, `password` or `subscription-key` part (`X-Api-Key`, `api-key`,
|
|
46
|
+
* `X-Auth-Token`, `PRIVATE-TOKEN`, `Ocp-Apim-Subscription-Key`). Matched on
|
|
47
|
+
* `-`/`_`-separated parts, so `X-Token-Count` or `Accept` do not match.
|
|
48
|
+
*/
|
|
49
|
+
const SECRET_HEADER = /^(?:proxy-)?authorization$|(?:^|[-_])(?:api[-_]?key|apikey|token|secret|password|passwd|subscription[-_]key|functions[-_]key)$/i;
|
|
50
|
+
/** An HTTP auth scheme word on its own (`Bearer`, `Basic`), which carries no credential yet. */
|
|
51
|
+
const AUTH_SCHEME_ONLY = /^(?:bearer|basic|token|apikey|digest)?$/i;
|
|
52
|
+
/**
|
|
53
|
+
* The text a header value carries when it is a constant: a plain string, a
|
|
54
|
+
* `lit()`, or a `js` expression that is nothing but a string literal
|
|
55
|
+
* (`` js`"Bearer abc"` ``). `undefined` for anything evaluated at run time.
|
|
56
|
+
*/
|
|
57
|
+
function literalHeaderText(value) {
|
|
58
|
+
if (typeof value === 'string')
|
|
59
|
+
return isJsExpressionValue(value) ? undefined : value;
|
|
60
|
+
if (!(value instanceof Expr))
|
|
61
|
+
return undefined;
|
|
62
|
+
if (value.literal)
|
|
63
|
+
return typeof value.value === 'string' ? value.value : undefined;
|
|
64
|
+
try {
|
|
65
|
+
const parsed = JSON.parse(value.js.trim());
|
|
66
|
+
return typeof parsed === 'string' ? parsed : undefined;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A literal credential in a request header (#1977). The value is written into
|
|
74
|
+
* the `.flow` as plain text, so it is in the source, in every exported
|
|
75
|
+
* solution and in the designer, readable by anyone who can open the flow. A
|
|
76
|
+
* warning, not an error: the request still works, and a designer flow that
|
|
77
|
+
* already carries one should not stop an unrelated edit. An empty value and a
|
|
78
|
+
* scheme word alone (`'Bearer '`) carry nothing, so they are not reported.
|
|
79
|
+
*/
|
|
80
|
+
function checkSecretHeaders(inputs, ctx) {
|
|
81
|
+
for (const [name, value] of Object.entries(inputs?.headers ?? {})) {
|
|
82
|
+
if (!SECRET_HEADER.test(name.trim()))
|
|
83
|
+
continue;
|
|
84
|
+
const text = literalHeaderText(value);
|
|
85
|
+
if (text === undefined || AUTH_SCHEME_ONLY.test(text.trim()))
|
|
86
|
+
continue;
|
|
87
|
+
ctx.report('HTTP_LITERAL_SECRET_HEADER', `Step "${ctx.step}" sets the "${name}" header to a literal value. A literal is written into the .flow as `
|
|
88
|
+
+ `plain text, so the credential is readable by anyone who can open the flow or its exported solution. `
|
|
89
|
+
+ `Keep it in an Integration Service HTTP connection (managed: true with connection and folder, which `
|
|
90
|
+
+ `authenticates the request, and drop the header), or read it from a flow input with no \`default\`, which `
|
|
91
|
+
+ `the caller supplies at run time. A \`default\` on an input or a .var() is written into the .flow too.`, `http({ url: …, managed: true, connection, folder })`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
40
94
|
/**
|
|
41
95
|
* The two http settings every deployed request node carries.
|
|
42
96
|
*
|
|
@@ -117,6 +171,7 @@ function comparesFailingCode(js, step) {
|
|
|
117
171
|
export function checkHttpStep(inputs, ctx) {
|
|
118
172
|
const step = ctx.step;
|
|
119
173
|
checkHttp(inputs, ctx);
|
|
174
|
+
checkSecretHeaders(inputs, ctx);
|
|
120
175
|
// A managed step's binding labels are the serializer's (BINDING_*), as a
|
|
121
176
|
// connector step's are.
|
|
122
177
|
const seen = new Set();
|
|
@@ -13,6 +13,7 @@ import { isRecord } from '../../../core/node-envelope.js';
|
|
|
13
13
|
import { wireExprBody } from '../../../core/wire-expr.js';
|
|
14
14
|
import { checkHttpRead, checkHttpStep, plainHttpOnErrorMessage } from './check.js';
|
|
15
15
|
import { CompileRefusal } from '../../../core/compile-refusal.js';
|
|
16
|
+
import { declareKeys } from '../../../core/option-keys.js';
|
|
16
17
|
const PLAIN = 'core.action.http';
|
|
17
18
|
const MANAGED = 'core.action.http.v2';
|
|
18
19
|
/** The definition's `inputDefaults` at the version being emitted. */
|
|
@@ -104,10 +105,9 @@ function managedHttpBinding(i, ctx) {
|
|
|
104
105
|
// The same resolution a connector step gets: a self-referential binding is an
|
|
105
106
|
// error, a stub is a warning.
|
|
106
107
|
const where = `managed http "${ctx.step}"`;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
};
|
|
108
|
+
const { connectionId, folderKey } = ctx.resolveBindingPair(i, where);
|
|
109
|
+
// Both labels are non-empty strings (refused above otherwise), so both resolve.
|
|
110
|
+
return { connectionId: connectionId, folderKey: folderKey };
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* The MANAGED HTTP node's inputs (`core.action.http.v2`).
|
|
@@ -410,9 +410,12 @@ function httpAt(typeName, version, managed) {
|
|
|
410
410
|
exits: httpExits,
|
|
411
411
|
};
|
|
412
412
|
}
|
|
413
|
+
/** Every key of `http()`'s options (builder-sdk#1990); `tsc` holds the list to `HttpInputs`. */
|
|
414
|
+
const HTTP_OPTIONS = { inputs: declareKeys({ branches: true, method: true, url: true, headers: true, query: true, body: true, contentType: true, managed: true, returns: true, timeout: true, retryCount: true, connection: true, folder: true, targetConnector: true }) };
|
|
413
415
|
function httpType(typeName, version, managed) {
|
|
414
416
|
return {
|
|
415
417
|
kind: 'http', typeName, factory: 'http', defaultVersion: version,
|
|
418
|
+
optionKeys: HTTP_OPTIONS,
|
|
416
419
|
versions: { [version]: httpAt(typeName, version, managed) },
|
|
417
420
|
matches: ({ inputs }) => Boolean(inputs?.managed) === managed,
|
|
418
421
|
};
|
|
@@ -19,6 +19,7 @@ import { resourceNodeSortOrder } from '../../../core/process-resource-sort-order
|
|
|
19
19
|
import { processResourceBindings, processResourceLocation } from '../../../core/process-resource.js';
|
|
20
20
|
import { checkAgent, checkAgentRead, checkAgenticProcess, checkAgenticProcessRead, checkApiWorkflow, checkApiWorkflowRead, checkPublishedFunction, checkPublishedFunctionRead, checkRpaWorkflow, rpaWorkflowRead, } from './check.js';
|
|
21
21
|
import { refuseLossyProcess } from './refusals.js';
|
|
22
|
+
import { declareKeys } from '../../../core/option-keys.js';
|
|
22
23
|
/** The RPA-workflow node type family. The process's release key is the suffix. */
|
|
23
24
|
const RPA_WORKFLOW_PREFIX = 'uipath.core.rpa-workflow.';
|
|
24
25
|
/**
|
|
@@ -831,6 +832,14 @@ function processCheck(spec, ctx) {
|
|
|
831
832
|
case 'agent': return checkAgent(spec.inputs, ctx);
|
|
832
833
|
}
|
|
833
834
|
}
|
|
835
|
+
/** Every key of each factory's options (builder-sdk#1990), by kind; `tsc` holds each list to its type. */
|
|
836
|
+
const PROCESS_OPTIONS = {
|
|
837
|
+
rpaWorkflow: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, returns: true }) },
|
|
838
|
+
apiWorkflow: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, returns: true }) },
|
|
839
|
+
publishedFunction: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, returns: true }) },
|
|
840
|
+
agenticProcess: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, form: true, completion: true, returns: true }) },
|
|
841
|
+
agent: { inputs: declareKeys({ key: true, name: true, location: true, folderPath: true, projectId: true, inputs: true, returns: true, flavour: true }) },
|
|
842
|
+
};
|
|
834
843
|
function processType(kind, prefix, factory, form) {
|
|
835
844
|
const impl = {
|
|
836
845
|
kind, typeName: `${prefix}*`, version: '1.0.0', factory, definition: 'per-tenant',
|
|
@@ -852,6 +861,7 @@ function processType(kind, prefix, factory, form) {
|
|
|
852
861
|
};
|
|
853
862
|
return {
|
|
854
863
|
kind, typeName: `${prefix}*`, typeNamePrefix: prefix, factory, defaultVersion: '1.0.0',
|
|
864
|
+
optionKeys: ownEntry(PROCESS_OPTIONS, kind),
|
|
855
865
|
versions: { '1.0.0': impl },
|
|
856
866
|
// The agentic process's three forms share its kind; an absent or unknown form
|
|
857
867
|
// is the default `bpmn` one, as the definition builder reads it.
|
|
@@ -4,6 +4,7 @@ import { isRecord } from '../../../core/node-envelope.js';
|
|
|
4
4
|
import { checkQueueItem, itemDataIsString, itemIsNotObject, queueItemExprMessage, queueItemNotObjectMessage, queueReturnsWithoutWaitMessage, } from './check.js';
|
|
5
5
|
import { QUEUE_ITEM_RECORD_SCHEMA } from './record.js';
|
|
6
6
|
import { CompileRefusal } from '../../../core/compile-refusal.js';
|
|
7
|
+
import { declareKeys } from '../../../core/option-keys.js';
|
|
7
8
|
const CREATE = 'core.action.queue.create';
|
|
8
9
|
const CREATE_AND_WAIT = 'core.action.queue.create-and-wait';
|
|
9
10
|
/**
|
|
@@ -356,9 +357,12 @@ function queueAt(typeName, wait) {
|
|
|
356
357
|
output: ({ inputs }) => queueOutput(inputs, wait),
|
|
357
358
|
};
|
|
358
359
|
}
|
|
360
|
+
/** Every key of `queueItem()`'s options (builder-sdk#1990); `tsc` holds the list to `QueueItemInputs`. */
|
|
361
|
+
const QUEUE_ITEM_OPTIONS = { inputs: declareKeys({ queue: true, folderPath: true, key: true, item: true, priority: true, reference: true, deferDate: true, dueDate: true, wait: true, returns: true }) };
|
|
359
362
|
function queueType(typeName, wait) {
|
|
360
363
|
return {
|
|
361
364
|
kind: 'queueItem', typeName, factory: 'queueItem', defaultVersion: '1.2',
|
|
365
|
+
optionKeys: QUEUE_ITEM_OPTIONS,
|
|
362
366
|
versions: { '1.2': queueAt(typeName, wait) },
|
|
363
367
|
matches: ({ inputs }) => Boolean(inputs?.wait) === wait,
|
|
364
368
|
};
|
|
@@ -10,6 +10,7 @@ import { unknownMetadataKeys } from '../../../core/flow-metadata.js';
|
|
|
10
10
|
import { scriptBodyEarlyError, scriptBodySyntaxError, scriptBodyTypeScriptSyntax, tryLowerScriptFunction } from '../../../core/script-function.js';
|
|
11
11
|
import { FLOW_SCRIPT_RUNTIME } from './runtime.js';
|
|
12
12
|
import { checkScript } from './check.js';
|
|
13
|
+
import { declareKeys } from '../../../core/option-keys.js';
|
|
13
14
|
/**
|
|
14
15
|
* Declare what a `core.action.script` node actually publishes.
|
|
15
16
|
*
|
|
@@ -213,7 +214,10 @@ function scriptAt(version) {
|
|
|
213
214
|
output: () => ({ kind: 'opaque' }),
|
|
214
215
|
};
|
|
215
216
|
}
|
|
217
|
+
/** Every key of `script()`'s options (builder-sdk#1990); `tsc` holds the list to `ScriptInputs`. */
|
|
218
|
+
const SCRIPT_OPTIONS = { inputs: declareKeys({ code: true, returns: true }) };
|
|
216
219
|
export const scriptNodeType = {
|
|
217
220
|
kind: 'script', typeName: 'core.action.script', factory: 'script', defaultVersion: '1.0.0',
|
|
221
|
+
optionKeys: SCRIPT_OPTIONS,
|
|
218
222
|
versions: { '1.0.0': scriptAt('1.0.0'), '1.1': scriptAt('1.1') },
|
|
219
223
|
};
|
|
@@ -12,6 +12,7 @@ import { jsonClone } from '../../../core/json-clone.js';
|
|
|
12
12
|
import { VARIANT_OPERATION } from './spec.js';
|
|
13
13
|
import { checkTransform, nearestIn } from './check.js';
|
|
14
14
|
import { CompileRefusal } from '../../../core/compile-refusal.js';
|
|
15
|
+
import { declareKeys } from '../../../core/option-keys.js';
|
|
15
16
|
/**
|
|
16
17
|
* Emit a transform's `inputs` in the canonical shape the node's runtime reads:
|
|
17
18
|
* `collection` as a BARE variable path (not `=js:`-prefixed — it is a path
|
|
@@ -277,9 +278,12 @@ function transformAt(typeName, variant, version, factory) {
|
|
|
277
278
|
output: () => ({ kind: 'opaque' }),
|
|
278
279
|
};
|
|
279
280
|
}
|
|
281
|
+
/** Every key of `transform()`'s options (builder-sdk#1990); `tsc` holds the list to `TransformInputs`. */
|
|
282
|
+
const TRANSFORM_OPTIONS = { inputs: declareKeys({ collection: true, variant: true, operations: true }) };
|
|
280
283
|
function transformType(typeName, variant, factory) {
|
|
281
284
|
return {
|
|
282
285
|
kind: 'transform', typeName, factory: 'transform', defaultVersion: '1.0.0',
|
|
286
|
+
optionKeys: TRANSFORM_OPTIONS,
|
|
283
287
|
versions: { '1.0.0': transformAt(typeName, variant, '1.0.0', factory), '1.1': transformAt(typeName, variant, '1.1', factory) },
|
|
284
288
|
// The generic type is the one for any spec without a KNOWN variant — an unknown
|
|
285
289
|
// one included, so check still reports it (see serialize above).
|
|
@@ -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.
|
|
@@ -19,6 +19,7 @@ import { CompileRefusal } from '../../../core/compile-refusal.js';
|
|
|
19
19
|
import { checkSchedule, checkStartingPrompts, fitsScheduleV12, isIsoInterval } from './check.js';
|
|
20
20
|
import { isJsExpressionValue } from '../../../core/wire-expr.js';
|
|
21
21
|
import { SCHEDULE_PRESETS } from './spec.js';
|
|
22
|
+
import { declareKeys } from '../../../core/option-keys.js';
|
|
22
23
|
/** A Quartz cron expression: 6–7 whitespace-separated fields, none of them an ISO `R/` interval. */
|
|
23
24
|
function isQuartz(every) {
|
|
24
25
|
// An `=js:` expression can have six tokens too; it is not cron.
|
|
@@ -175,8 +176,12 @@ export const manualTriggerType = {
|
|
|
175
176
|
// survives recompilation (design §5.3).
|
|
176
177
|
print: () => ({ factory: 'manual' }),
|
|
177
178
|
};
|
|
179
|
+
/** Every key of each trigger factory's options (builder-sdk#1990); `tsc` holds each list to its type. */
|
|
180
|
+
const SCHEDULED_OPTIONS = { inputs: declareKeys({ every: true }) };
|
|
181
|
+
const CONVERSATION_TRIGGER_OPTIONS = { appearance: declareKeys({ welcomeTitle: true, welcomeDescription: true, startingPrompts: true, personalWorkspaceConnectionsOnly: true }) };
|
|
178
182
|
export const scheduledTriggerType = {
|
|
179
183
|
kind: 'scheduled', typeName: 'core.trigger.scheduled', factory: 'scheduled',
|
|
184
|
+
optionKeys: SCHEDULED_OPTIONS,
|
|
180
185
|
noun: 'schedule',
|
|
181
186
|
serialize: (spec, ctx) => {
|
|
182
187
|
const version = scheduledVersion(spec.inputs, ctx.version);
|
|
@@ -289,6 +294,7 @@ function liftAppearance(node) {
|
|
|
289
294
|
}
|
|
290
295
|
export const conversationTriggerType = {
|
|
291
296
|
kind: 'conversation', typeName: 'core.trigger.conversation', factory: 'conversationTrigger',
|
|
297
|
+
optionKeys: CONVERSATION_TRIGGER_OPTIONS,
|
|
292
298
|
onePerFlow: 'SINGLE_CONVERSATION_TRIGGER',
|
|
293
299
|
serialize: (spec, ctx) => {
|
|
294
300
|
const version = ctx.version ?? CONVERSATION_DEFAULT_VERSION;
|
|
@@ -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
|
+
}>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Refusal } from "../errors.js";
|
|
2
|
+
import { dfChoiceSetValues, dfEntityGet } from "../uip/commands.js";
|
|
3
|
+
import { failureReason, getCI, isSuccess, parseEnvelope } from "../uip/envelope.js";
|
|
4
|
+
/** The all-zero folder id Data Fabric gives everything at tenant level. */
|
|
5
|
+
const TENANT_FOLDER_ID = "00000000-0000-0000-0000-000000000000";
|
|
6
|
+
/** Choice-set values read a page at a time; a set longer than this many pages is left unread. */
|
|
7
|
+
const CHOICE_PAGE_SIZE = 500;
|
|
8
|
+
const CHOICE_MAX_PAGES = 10;
|
|
9
|
+
function text(value) {
|
|
10
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
11
|
+
}
|
|
12
|
+
/** A folder id worth passing on: not absent, and not the tenant's all-zero one. */
|
|
13
|
+
function folderOf(value) {
|
|
14
|
+
const id = text(value);
|
|
15
|
+
return id === undefined || id === TENANT_FOLDER_ID ? undefined : id;
|
|
16
|
+
}
|
|
17
|
+
/** One raw `Fields[]` entry as the recorded column, or `undefined` for one with no name. */
|
|
18
|
+
export function fieldSchema(raw) {
|
|
19
|
+
const name = text(getCI(raw, "Name"));
|
|
20
|
+
if (name === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
const dataType = getCI(raw, "FieldDataType");
|
|
23
|
+
const type = (text(getCI(dataType, "Name")) ?? "UNKNOWN").toUpperCase();
|
|
24
|
+
const display = text(getCI(raw, "FieldDisplayType"));
|
|
25
|
+
const displayName = text(getCI(raw, "DisplayName"));
|
|
26
|
+
const lengthLimit = getCI(dataType, "LengthLimit");
|
|
27
|
+
const defaultValue = getCI(raw, "DefaultValue");
|
|
28
|
+
const field = {
|
|
29
|
+
name,
|
|
30
|
+
...(displayName !== undefined && displayName !== name ? { displayName } : {}),
|
|
31
|
+
type,
|
|
32
|
+
required: getCI(raw, "IsRequired") === true,
|
|
33
|
+
};
|
|
34
|
+
if (getCI(raw, "IsSystemField") === true)
|
|
35
|
+
field.system = true;
|
|
36
|
+
if (defaultValue !== undefined && defaultValue !== null)
|
|
37
|
+
field.hasDefault = true;
|
|
38
|
+
if (getCI(raw, "IsUnique") === true || getCI(raw, "IsPrimaryKey") === true)
|
|
39
|
+
field.unique = true;
|
|
40
|
+
if (getCI(raw, "IsAttachment") === true || type === "FILE" || display === "File")
|
|
41
|
+
field.attachment = true;
|
|
42
|
+
if (type === "AUTO_NUMBER" || display === "AutoNumber")
|
|
43
|
+
field.autoNumber = true;
|
|
44
|
+
if (typeof lengthLimit === "number" && Number.isFinite(lengthLimit))
|
|
45
|
+
field.lengthLimit = lengthLimit;
|
|
46
|
+
if (type === "RELATIONSHIP") {
|
|
47
|
+
const entity = getCI(raw, "ReferenceEntity");
|
|
48
|
+
const entityName = text(getCI(entity, "Name"));
|
|
49
|
+
if (entityName !== undefined) {
|
|
50
|
+
const entityId = text(getCI(entity, "Id"));
|
|
51
|
+
const displayField = text(getCI(getCI(getCI(raw, "ReferenceField"), "Definition"), "Name"));
|
|
52
|
+
field.reference = {
|
|
53
|
+
entity: entityName,
|
|
54
|
+
...(entityId !== undefined ? { entityId } : {}),
|
|
55
|
+
...(displayField !== undefined ? { displayField } : {}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const choiceSetId = text(getCI(raw, "ChoiceSetId"));
|
|
60
|
+
if (choiceSetId !== undefined) {
|
|
61
|
+
field.choiceSet = { name: text(getCI(getCI(raw, "ReferenceChoiceSet"), "Name")) ?? "", id: choiceSetId };
|
|
62
|
+
}
|
|
63
|
+
return field;
|
|
64
|
+
}
|
|
65
|
+
/** One `Data.Items[]` entry of `list-values` as a recorded value, or `undefined` for one with no number. */
|
|
66
|
+
function choiceValue(raw) {
|
|
67
|
+
const name = text(getCI(raw, "Name"));
|
|
68
|
+
const numberId = getCI(raw, "NumberId");
|
|
69
|
+
if (name === undefined || typeof numberId !== "number")
|
|
70
|
+
return undefined;
|
|
71
|
+
const displayName = text(getCI(raw, "DisplayName"));
|
|
72
|
+
return { name, ...(displayName !== undefined && displayName !== name ? { displayName } : {}), numberId };
|
|
73
|
+
}
|
|
74
|
+
/** Every value of one choice set, or a reason it could not be read. */
|
|
75
|
+
async function readChoiceValues(client, id, folderKey, cwd) {
|
|
76
|
+
const values = [];
|
|
77
|
+
for (let page = 0; page < CHOICE_MAX_PAGES; page++) {
|
|
78
|
+
const argv = dfChoiceSetValues(id, { ...(folderKey !== undefined ? { folderKey } : {}), limit: CHOICE_PAGE_SIZE, ...(page > 0 ? { offset: page * CHOICE_PAGE_SIZE } : {}) });
|
|
79
|
+
const result = await client.run(argv, { cwd });
|
|
80
|
+
const envelope = parseEnvelope(result.stdout);
|
|
81
|
+
if (result.code !== 0 || !isSuccess(envelope))
|
|
82
|
+
return failureReason(result);
|
|
83
|
+
const data = getCI(envelope, "Data");
|
|
84
|
+
const items = getCI(data, "Items");
|
|
85
|
+
for (const raw of Array.isArray(items) ? items : []) {
|
|
86
|
+
const value = choiceValue(raw);
|
|
87
|
+
if (value !== undefined)
|
|
88
|
+
values.push(value);
|
|
89
|
+
}
|
|
90
|
+
if (getCI(data, "HasNextPage") !== true)
|
|
91
|
+
return values;
|
|
92
|
+
}
|
|
93
|
+
return `more than ${CHOICE_MAX_PAGES * CHOICE_PAGE_SIZE} values`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The entity's columns, with each choice set's values.
|
|
97
|
+
*
|
|
98
|
+
* A choice set that cannot be read leaves that column's `values` out, with a
|
|
99
|
+
* warning: its column is still checked by name and type, only not by value.
|
|
100
|
+
*
|
|
101
|
+
* @param client - The `uip` client every call goes through.
|
|
102
|
+
* @param target - The entity's id, and the folder key of a folder-scoped one.
|
|
103
|
+
* @param cwd - Where to run `uip`.
|
|
104
|
+
* @returns The columns, in the order the tenant lists them, and a warning per choice set left unread.
|
|
105
|
+
* @throws Refusal `ENTITY_SCHEMA_UNREAD` when `entities get` fails or returns no columns.
|
|
106
|
+
*/
|
|
107
|
+
export async function readEntitySchema(client, target, cwd) {
|
|
108
|
+
const argv = dfEntityGet(target.id, target.folderKey);
|
|
109
|
+
const result = await client.run(argv, { cwd });
|
|
110
|
+
const envelope = parseEnvelope(result.stdout);
|
|
111
|
+
if (result.code !== 0 || !isSuccess(envelope)) {
|
|
112
|
+
throw new Refusal(`could not read the entity's columns (${failureReason(result)}).\n ${argv.slice(0, -2).join(" ")}`, "ENTITY_SCHEMA_UNREAD");
|
|
113
|
+
}
|
|
114
|
+
const raw = getCI(getCI(envelope, "Data"), "Fields");
|
|
115
|
+
const fields = (Array.isArray(raw) ? raw : []).map((f) => ({ raw: f, field: fieldSchema(f) }))
|
|
116
|
+
.filter((f) => f.field !== undefined);
|
|
117
|
+
if (fields.length === 0) {
|
|
118
|
+
throw new Refusal(`the entity's schema lists no columns.\n ${argv.slice(0, -2).join(" ")}`, "ENTITY_SCHEMA_UNREAD");
|
|
119
|
+
}
|
|
120
|
+
const warnings = [];
|
|
121
|
+
for (const { raw: rawField, field } of fields) {
|
|
122
|
+
if (field.choiceSet === undefined)
|
|
123
|
+
continue;
|
|
124
|
+
const folderKey = folderOf(getCI(getCI(rawField, "ReferenceChoiceSet"), "FolderId")) ?? target.folderKey;
|
|
125
|
+
const values = await readChoiceValues(client, field.choiceSet.id, folderKey, cwd);
|
|
126
|
+
if (typeof values === "string") {
|
|
127
|
+
warnings.push(`could not read the values of choice set ${JSON.stringify(field.choiceSet.name || field.choiceSet.id)} `
|
|
128
|
+
+ `(column ${JSON.stringify(field.name)}): ${values}. check will not judge that column's values.`);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
field.choiceSet.values = values;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { fields: fields.map((f) => f.field), warnings };
|
|
135
|
+
}
|