@uipath/maestro-builder-sdk 6.120.18 → 6.120.20
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 +30 -30
- package/dist/api-members.md +115 -115
- package/dist/bpmn/bpmn-expr-check.d.ts +10 -0
- package/dist/bpmn/bpmn-expr-check.js +79 -175
- package/dist/bpmn/bpmn-sdk.d.ts +27 -4
- package/dist/bpmn/bpmn-sdk.js +20 -1
- package/dist/bpmn/check.js +1 -86
- package/dist/bpmn/declared-vars.d.ts +30 -1
- package/dist/bpmn/declared-vars.js +63 -0
- package/dist/bpmn/decompile.js +11 -1
- package/dist/bpmn/expr-fields.d.ts +106 -0
- package/dist/bpmn/expr-fields.js +321 -0
- package/dist/bpmn/expression-value.d.ts +16 -0
- package/dist/bpmn/expression-value.js +18 -0
- package/dist/bpmn/script-js.d.ts +49 -0
- package/dist/bpmn/script-js.js +179 -0
- package/dist/bpmn/serialize.d.ts +0 -26
- package/dist/bpmn/serialize.js +3 -42
- package/dist/bpmn-api.md +2 -2
- package/dist/core/actions.d.ts +2 -2
- package/dist/core/expr-check.d.ts +7 -0
- package/dist/core/expr-check.js +14 -4
- package/dist/core/list-envelope.d.ts +7 -0
- package/dist/core/refusals.d.ts +1 -0
- package/dist/core/refusals.js +1 -0
- package/dist/registry/curated-overlay.d.ts +18 -3
- package/dist/registry/curated-overlay.js +98 -5
- package/dist/registry/prepare/actions.d.ts +1 -1
- package/dist/registry/prepare/actions.js +1 -1
- package/dist/registry/prepare/messages.js +1 -1
- package/lib/library-json.samples/list-envelopes.json +29 -1
- package/package.json +2 -2
|
@@ -20,9 +20,17 @@
|
|
|
20
20
|
* are all readable downstream. `nodeDeclaredVars` supplies them; being stricter
|
|
21
21
|
* than the platform here would reject working processes.
|
|
22
22
|
*
|
|
23
|
+
* A declared name is not always a readable one: a process input is scoped to its start
|
|
24
|
+
* event and an output to its end event, and a read of either from another element is
|
|
25
|
+
* `EXPR_ARGUMENT_REF` (#2138, `BpmnRoots.args`).
|
|
26
|
+
*
|
|
23
27
|
* A loop's item binds `iterator.<itemVar>`, and a script output writes `=result.…`
|
|
24
28
|
* — different namespaces, left alone (only `vars.` is the author's to get wrong).
|
|
25
29
|
* Variables are SCOPED: a sub-process sees the enclosing variables plus its own.
|
|
30
|
+
*
|
|
31
|
+
* WHICH fields carry an expression, and which names are in scope at each, is not decided
|
|
32
|
+
* here: `bpmnExpressionFields` (expr-fields.ts) yields every one, and a rule only judges
|
|
33
|
+
* what it is handed.
|
|
26
34
|
*/
|
|
27
35
|
import { type ExprDiagnostic } from '../core/expr-check.js';
|
|
28
36
|
import type { BuiltBpmn } from './bpmn-sdk.js';
|
|
@@ -32,6 +40,8 @@ export interface BpmnLocatedDiagnostic extends ExprDiagnostic {
|
|
|
32
40
|
where: string;
|
|
33
41
|
/** The id of the flow or element the expression is on. */
|
|
34
42
|
elementId?: string;
|
|
43
|
+
/** The field's path inside that element — see {@link BpmnExprField.path}. */
|
|
44
|
+
path?: string;
|
|
35
45
|
}
|
|
36
46
|
/** Every first-level expression problem in a built BPMN process, stamped with its location. */
|
|
37
47
|
export declare function checkBpmnExpressions(built: BuiltBpmn): BpmnLocatedDiagnostic[];
|
|
@@ -20,22 +20,33 @@
|
|
|
20
20
|
* are all readable downstream. `nodeDeclaredVars` supplies them; being stricter
|
|
21
21
|
* than the platform here would reject working processes.
|
|
22
22
|
*
|
|
23
|
+
* A declared name is not always a readable one: a process input is scoped to its start
|
|
24
|
+
* event and an output to its end event, and a read of either from another element is
|
|
25
|
+
* `EXPR_ARGUMENT_REF` (#2138, `BpmnRoots.args`).
|
|
26
|
+
*
|
|
23
27
|
* A loop's item binds `iterator.<itemVar>`, and a script output writes `=result.…`
|
|
24
28
|
* — different namespaces, left alone (only `vars.` is the author's to get wrong).
|
|
25
29
|
* Variables are SCOPED: a sub-process sees the enclosing variables plus its own.
|
|
30
|
+
*
|
|
31
|
+
* WHICH fields carry an expression, and which names are in scope at each, is not decided
|
|
32
|
+
* here: `bpmnExpressionFields` (expr-fields.ts) yields every one, and a rule only judges
|
|
33
|
+
* what it is handed.
|
|
26
34
|
*/
|
|
27
|
-
import { checkExpression } from '../core/expr-check.js';
|
|
28
|
-
import {
|
|
35
|
+
import { checkExpression, checkRefs, extractRefs } from '../core/expr-check.js';
|
|
36
|
+
import { bpmnExpressionFields } from './expr-fields.js';
|
|
37
|
+
import { scriptVarReads } from './script-js.js';
|
|
29
38
|
import { CompileRefusal } from '../core/compile-refusal.js';
|
|
39
|
+
import { tsLiteral } from '../core/ts-literal.js';
|
|
30
40
|
const NOUN = 'variable';
|
|
31
41
|
const NAMESPACE = 'vars';
|
|
32
42
|
const BINDING_NOUN = 'binding';
|
|
33
43
|
const BINDING_NAMESPACE = 'bindings';
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
/** An `=`-expression field's findings. */
|
|
45
|
+
function checkExpr(f, out) {
|
|
46
|
+
const { text: expr, where, roots } = f;
|
|
37
47
|
for (const d of checkExpression(expr, { roots: roots.vars, noun: NOUN, namespace: NAMESPACE }))
|
|
38
48
|
out.push({ ...d, where });
|
|
49
|
+
argumentReads(extractRefs(expr, NAMESPACE), f, out);
|
|
39
50
|
for (const d of checkExpression(expr, { roots: roots.bindings, noun: BINDING_NOUN, namespace: BINDING_NAMESPACE }))
|
|
40
51
|
out.push({ ...d, where });
|
|
41
52
|
// A process variable is always read through the `vars` namespace. The bare
|
|
@@ -46,7 +57,9 @@ function checkExpr(expr, where, roots, out) {
|
|
|
46
57
|
// Keep this intentionally narrow (a single optionally-parenthesized name) so
|
|
47
58
|
// local declarations inside arbitrary `=js:` programs are not guessed at.
|
|
48
59
|
const bare = expr.match(/^\s*=(?:js:)?\s*\(?\s*([A-Za-z_$][\w$]*)\s*\)?\s*$/)?.[1];
|
|
49
|
-
|
|
60
|
+
// Not on an output row's source: that is read against the node's own result, where a
|
|
61
|
+
// bare name is a result field (a human task's `=category` answer), not a variable.
|
|
62
|
+
if (bare && !f.result && roots.varIds.has(bare)) {
|
|
50
63
|
out.push({
|
|
51
64
|
level: 'error',
|
|
52
65
|
code: 'EXPR_BARE_VAR_REF',
|
|
@@ -56,187 +69,78 @@ function checkExpr(expr, where, roots, out) {
|
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
/**
|
|
59
|
-
*
|
|
72
|
+
* The `vars.<root>` reads in a script task's BODY, judged like an expression's
|
|
73
|
+
* (EXPR_UNDECLARED_REF). The platform runs the body with `vars` in scope, so a read of a
|
|
74
|
+
* name nothing declares is `undefined` at run time, exactly as it is in an expression.
|
|
60
75
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
76
|
+
* Read by parsing the JavaScript (`scriptVarReads`), never by scanning its text, so a
|
|
77
|
+
* `vars.` in a comment, a string or a property name is not taken for a read; a body that
|
|
78
|
+
* rebinds `vars`, asks `typeof vars.x`, or assigns the root itself is left alone. A body
|
|
79
|
+
* that does not parse is not judged. The bare-spelling rule does not apply: a bare name
|
|
80
|
+
* in a script is a JavaScript identifier, which SCRIPT_BARE_INPUT_REF (check.ts) owns.
|
|
66
81
|
*/
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
checkExpr(v, where, roots, out);
|
|
71
|
-
else
|
|
72
|
-
deepExprStrings(v, where, roots, out);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/** Reach `=`-expression strings anywhere in a connector's (possibly nested) inputs. */
|
|
76
|
-
function deepExprStrings(val, where, roots, out) {
|
|
77
|
-
if (typeof val === 'string') {
|
|
78
|
-
if (val.startsWith('='))
|
|
79
|
-
checkExpr(val, where, roots, out);
|
|
82
|
+
function checkScript(f, out) {
|
|
83
|
+
const reads = scriptVarReads(f.text);
|
|
84
|
+
if (!reads?.length)
|
|
80
85
|
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
for (const d of checkRefs(reads, { roots: f.roots.vars, noun: NOUN, namespace: NAMESPACE }))
|
|
87
|
+
out.push({ ...d, where: f.where });
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Report each read of a process argument — see `BpmnRoots.args`. One finding per
|
|
91
|
+
* argument per field, naming the form that IS readable: the start-event mapping into a
|
|
92
|
+
* process variable for an input, the variable the end event maps from for an output.
|
|
93
|
+
* The element an argument is scoped to reads it freely: its mapping is the bridge.
|
|
94
|
+
*
|
|
95
|
+
* Expression fields only. What is known to reject the read is the canvas's expression
|
|
96
|
+
* resolution and `validate`; a script body is JavaScript in the code editor, and
|
|
97
|
+
* `validate` says nothing about a `vars.<input>` read there, so it is not reported.
|
|
98
|
+
*/
|
|
99
|
+
function argumentReads(refs, f, out) {
|
|
100
|
+
if (!f.roots.args.size)
|
|
85
101
|
return;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
const seen = new Set();
|
|
103
|
+
for (const ref of refs) {
|
|
104
|
+
const arg = f.roots.args.get(ref.root);
|
|
105
|
+
if (!arg || arg.scope === f.elementId || seen.has(arg.decl.id))
|
|
106
|
+
continue;
|
|
107
|
+
seen.add(arg.decl.id);
|
|
108
|
+
out.push({ level: 'error', code: 'EXPR_ARGUMENT_REF', message: argumentMessage(ref.root, arg), where: f.where });
|
|
90
109
|
}
|
|
91
110
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const roots = { vars: new Set(rootsIn.vars), varIds: rootsIn.varIds, bindings: rootsIn.bindings };
|
|
100
|
-
for (const n of nodes)
|
|
101
|
-
for (const name of nodeDeclaredVars(n))
|
|
102
|
-
roots.vars.add(name);
|
|
103
|
-
for (const f of flows) {
|
|
104
|
-
const found = [];
|
|
105
|
-
checkExpr(f.condition, `flow "${f.id}" condition`, roots, found);
|
|
106
|
-
for (const d of found)
|
|
107
|
-
out.push({ ...d, elementId: f.id });
|
|
108
|
-
}
|
|
109
|
-
for (const n of nodes) {
|
|
110
|
-
walkNode(n, roots, out);
|
|
111
|
+
function argumentMessage(root, { decl, scope }) {
|
|
112
|
+
const type = typeof decl.type === 'string' ? decl.type : 'string';
|
|
113
|
+
if (decl.direction === 'output') {
|
|
114
|
+
return (`\`vars.${root}\` reads process output \`${decl.id}\`, which is scoped to \`${scope}\` and only ` +
|
|
115
|
+
`written by its mapping: Studio Web reports "A variable is unresolved" on a read of it, and ` +
|
|
116
|
+
`\`validate\` reports VARIABLE_DOES_NOT_EXIST where it checks the read. Compute the value into a \`.var()\`, read that variable here, ` +
|
|
117
|
+
`and map it onto \`${decl.id}\` in \`${scope}\`'s payload.`);
|
|
111
118
|
}
|
|
119
|
+
const local = `${decl.id}In`;
|
|
120
|
+
return (`\`vars.${root}\` reads process input \`${decl.id}\`, which is scoped to \`${scope}\`: Studio Web ` +
|
|
121
|
+
`reports "A variable is unresolved" on a read of it from any other element, and \`validate\` reports ` +
|
|
122
|
+
`VARIABLE_NOT_SET where it checks the read (the engine runs it; the designer does not accept it). Map it, as the canvas ` +
|
|
123
|
+
`does, into a variable scoped to that start event and read the variable: ` +
|
|
124
|
+
`\`.var(${tsLiteral(local)}, ${tsLiteral(type)}, { elementId: ${tsLiteral(scope)} })\` and ` +
|
|
125
|
+
`\`.startEvent(${tsLiteral(scope)}, { payload: { type: ` +
|
|
126
|
+
`'BPMN.Variables', outputRows: [{ name: ${tsLiteral(decl.name)}, type: ${tsLiteral(type)}, ` +
|
|
127
|
+
`source: ${tsLiteral(`=vars.${decl.id}`)}, var: ${tsLiteral(local)} }] } })\`, then read \`=vars.${local}\`.`);
|
|
112
128
|
}
|
|
113
|
-
/**
|
|
114
|
-
function
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
located.push({ ...d, elementId: n.id });
|
|
120
|
-
};
|
|
121
|
-
{
|
|
122
|
-
// An errorMapping row's `condition` is an expression on EVERY activity kind, so
|
|
123
|
-
// it is checked before the per-kind arms rather than inside them. Worth checking
|
|
124
|
-
// here specifically because the CANVAS treats an undeclared reference in it as a
|
|
125
|
-
// blocking error while `uip maestro bpmn validate` says nothing at all — so
|
|
126
|
-
// without this the author's first sign of trouble is the designer refusing the
|
|
127
|
-
// artifact, long after every gate this repo runs went green.
|
|
128
|
-
// Events carry no errorMapping — the field exists on the activity arms only.
|
|
129
|
-
//
|
|
130
|
-
// `error` is a BUILT-IN root here, not an author declaration. The skill's
|
|
131
|
-
// expression reference says so outright — "Error mapping conditions may inspect the
|
|
132
|
-
// built-in error object through `vars.error`, for example
|
|
133
|
-
// `=vars.error.code == \"SERVICE_UNAVAILABLE\"`" — and that example is the whole
|
|
134
|
-
// point of the scenario: a row exists to classify a failure, so the only thing worth
|
|
135
|
-
// branching on is the failure. Requiring `.var('error', …)` first forced authors to
|
|
136
|
-
// declare a DECOY variable whose only purpose was to quiet this check, and which then
|
|
137
|
-
// shipped as a real `uipath:inputOutput` row in the artifact.
|
|
138
|
-
//
|
|
139
|
-
// Scoped to this one expression slot rather than added to the shared root set: outside
|
|
140
|
-
// an errorMapping condition there is no error object in scope, so `vars.error` there
|
|
141
|
-
// really is an undeclared reference and should still be reported.
|
|
142
|
-
// `error` joins `vars` (so `vars.error` resolves) but NOT `varIds`: it is a
|
|
143
|
-
// scoped runtime binding, not a declared variable, so `=error` is not a bare
|
|
144
|
-
// spelling of one.
|
|
145
|
-
const errRoots = { vars: new Set(roots.vars).add('error'), varIds: roots.varIds, bindings: roots.bindings };
|
|
146
|
-
for (const row of ('errorMapping' in n ? n.errorMapping : undefined) ?? []) {
|
|
147
|
-
checkExpr(row.condition, `${at} errorMapping "${row.code}" condition`, errRoots, out);
|
|
148
|
-
}
|
|
149
|
-
// A loop's collection and completion condition, on every activity kind EXCEPT the
|
|
150
|
-
// sub-process, which checks its own below in the right scopes. Only that arm used to
|
|
151
|
-
// check them, so a `.scriptTask({ loop })` — the commonest looping shape — had
|
|
152
|
-
// neither expression checked. It matters more now the engine HONOURS the completion
|
|
153
|
-
// condition: an unevaluatable one is swallowed there and the loop runs the whole
|
|
154
|
-
// collection, so this is the gate that reports it.
|
|
155
|
-
if (n.kind !== 'subProcess' && 'loop' in n && n.loop !== undefined) {
|
|
156
|
-
checkExpr(n.loop.collection, `${at} loop collection`, roots, out);
|
|
157
|
-
// The iterator bindings (`iterator.item`, `iterator.<itemVar>`) are the loop's
|
|
158
|
-
// own, not author declarations, so a completion condition may read them.
|
|
159
|
-
const loopRoots = {
|
|
160
|
-
vars: new Set(roots.vars).add('iterator'),
|
|
161
|
-
varIds: roots.varIds,
|
|
162
|
-
bindings: roots.bindings,
|
|
163
|
-
};
|
|
164
|
-
checkExpr(n.loop.completion, `${at} loop completion`, loopRoots, out);
|
|
165
|
-
}
|
|
166
|
-
if (n.kind === 'scriptTask') {
|
|
167
|
-
checkExprValues(n.inputs, `${at} input`, roots, out);
|
|
168
|
-
checkExprValues(n.outputs, `${at} output`, roots, out);
|
|
169
|
-
}
|
|
170
|
-
else if (n.kind === 'task') {
|
|
171
|
-
checkExprValues(n.set, `${at} assignment`, roots, out);
|
|
172
|
-
}
|
|
173
|
-
else if (n.kind === 'connector') {
|
|
174
|
-
deepExprStrings(n.inputs, `${at} input`, roots, out);
|
|
175
|
-
}
|
|
176
|
-
else if (n.kind === 'subProcess') {
|
|
177
|
-
// A sub-process is its own variable scope: it sees the enclosing variables
|
|
178
|
-
// plus the ones it declares. The loop COLLECTION is evaluated in the
|
|
179
|
-
// enclosing scope (before entry); the body and completion see the sub-scope.
|
|
180
|
-
checkExpr(n.loop?.collection, `${at} loop collection`, roots, out);
|
|
181
|
-
const subRoots = { vars: new Set(roots.vars), varIds: new Set(roots.varIds), bindings: roots.bindings };
|
|
182
|
-
// By ID as well as display name, exactly as the root scope below: an expression
|
|
183
|
-
// reads `vars.<id>`. This added the name alone, so a sub-process variable whose
|
|
184
|
-
// display name differed from its id — every `errorVar`, displayed as `Error` —
|
|
185
|
-
// was unreadable inside the very scope that declares it.
|
|
186
|
-
for (const v of n.variables) {
|
|
187
|
-
subRoots.vars.add(v.id);
|
|
188
|
-
subRoots.vars.add(v.name);
|
|
189
|
-
subRoots.varIds.add(v.id);
|
|
190
|
-
}
|
|
191
|
-
checkExpr(n.loop?.completion, `${at} loop completion`, subRoots, out);
|
|
192
|
-
flush();
|
|
193
|
-
walk(n.nodes, n.flows, subRoots, located);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
flush();
|
|
129
|
+
/** Every finding on one field. */
|
|
130
|
+
function checkField(f, out) {
|
|
131
|
+
if (f.form === 'script')
|
|
132
|
+
checkScript(f, out);
|
|
133
|
+
else
|
|
134
|
+
checkExpr(f, out);
|
|
197
135
|
}
|
|
198
136
|
/** Every first-level expression problem in a built BPMN process, stamped with its location. */
|
|
199
137
|
export function checkBpmnExpressions(built) {
|
|
200
|
-
const roots = {
|
|
201
|
-
// Keyed by ID, which is what an expression reads — `BpmnVarDecl.id` is documented as
|
|
202
|
-
// "what expressions read as `vars.<id>`", and every product-shaped artifact agrees:
|
|
203
|
-
// the fixtures under skills `edit/*/fixture` declare
|
|
204
|
-
// `<uipath:inputOutput id="Var_OrderId" name="OrderId">` and reference
|
|
205
|
-
// `=vars.Var_OrderId`, never the display name.
|
|
206
|
-
//
|
|
207
|
-
// This read `v.name`, so a variable given a friendly name became unreferenceable: the
|
|
208
|
-
// id an expression uses was not in the root set and every reference to it failed
|
|
209
|
-
// EXPR_UNDECLARED_REF. It only looked right because `.var()` defaults `name` to the id,
|
|
210
|
-
// so the bug was invisible until a display name differed — which is exactly what
|
|
211
|
-
// `bpmn-decompile` produces from any real artifact, so it blocked the whole
|
|
212
|
-
// decompile-edit-recompile round trip.
|
|
213
|
-
//
|
|
214
|
-
// The display name is accepted too. It is not what the wire uses, but an author who
|
|
215
|
-
// wrote `vars.<displayName>` in an existing process should get the reference resolved
|
|
216
|
-
// rather than a spurious error from a stricter check.
|
|
217
|
-
vars: new Set(built.variables.flatMap((v) => [v.id, v.name])),
|
|
218
|
-
varIds: new Set(built.variables.map((v) => v.id)),
|
|
219
|
-
// Author-declared bindings, plus the symbolic connection/folder names a
|
|
220
|
-
// connector turns into bindings at serialize time — the author's own spelling
|
|
221
|
-
// is what they would reference, so both are legitimate roots.
|
|
222
|
-
bindings: new Set([...built.bindings.map((b) => b.id), ...connectorBindingNames(built.nodes)]),
|
|
223
|
-
};
|
|
224
138
|
const out = [];
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const out = [];
|
|
231
|
-
for (const n of nodes) {
|
|
232
|
-
if (n.kind === 'connector') {
|
|
233
|
-
if (n.connection)
|
|
234
|
-
out.push(n.connection);
|
|
235
|
-
if (n.folder)
|
|
236
|
-
out.push(n.folder);
|
|
237
|
-
}
|
|
238
|
-
if (n.kind === 'subProcess')
|
|
239
|
-
out.push(...connectorBindingNames(n.nodes));
|
|
139
|
+
for (const f of bpmnExpressionFields(built)) {
|
|
140
|
+
const found = [];
|
|
141
|
+
checkField(f, found);
|
|
142
|
+
for (const d of found)
|
|
143
|
+
out.push({ ...d, elementId: f.elementId, path: f.path });
|
|
240
144
|
}
|
|
241
145
|
return out;
|
|
242
146
|
}
|
package/dist/bpmn/bpmn-sdk.d.ts
CHANGED
|
@@ -1938,9 +1938,13 @@ export interface VarOpts {
|
|
|
1938
1938
|
* the process's manual START event and a top-level `.output()` to the END event
|
|
1939
1939
|
* whose mapping writes it (or the only end event): that is how every Studio Web
|
|
1940
1940
|
* export and converter output declares a process's public contract, and what the
|
|
1941
|
-
* canvas, the entry-point derivation and the graders read it from.
|
|
1942
|
-
*
|
|
1943
|
-
*
|
|
1941
|
+
* canvas, the entry-point derivation and the graders read it from. It also decides
|
|
1942
|
+
* who may READ it: an input scoped to the start event is readable only by that start
|
|
1943
|
+
* event's own mapping, and an output by nobody. The engine resolves `vars.<id>` by id
|
|
1944
|
+
* whatever the scope, so a direct read runs, but Studio Web shows "A variable is
|
|
1945
|
+
* unresolved" on it and `validate` reports `VARIABLE_NOT_SET`; `check` reports it as
|
|
1946
|
+
* `EXPR_ARGUMENT_REF`. Map an input, on the start event, into a `.var()` scoped to that
|
|
1947
|
+
* start event and read the variable, as the canvas does (see `.input()`). `uip maestro bpmn validate` (1.203+) requires
|
|
1944
1948
|
* SOME `elementId`: a declaration with none is `ROOT_VARIABLE_MISSING_ELEMENT_ID`,
|
|
1945
1949
|
* and every `vars.<id>` read of it fails `VARIABLE_DOES_NOT_EXIST`. Name an element
|
|
1946
1950
|
* to scope the variable to it explicitly (the node whose output fills it, a specific
|
|
@@ -3495,7 +3499,26 @@ declare abstract class ScopeBuilder {
|
|
|
3495
3499
|
*/
|
|
3496
3500
|
var(id: string, type: BpmnVarType, opts?: VarOpts): this;
|
|
3497
3501
|
/**
|
|
3498
|
-
* A read-only entry input (`uipath:input`).
|
|
3502
|
+
* A read-only entry input (`uipath:input`), scoped to the manual start event.
|
|
3503
|
+
*
|
|
3504
|
+
* Only the start event's own mapping reads it. Every other element reads the variable
|
|
3505
|
+
* that mapping copies it into, scoped to the start event — which is what Studio Web
|
|
3506
|
+
* writes when an input is added on the canvas: a
|
|
3507
|
+
* `vars.<input>` read anywhere else is "A variable is unresolved" on the canvas, and
|
|
3508
|
+
* `check` reports it as `EXPR_ARGUMENT_REF`.
|
|
3509
|
+
*
|
|
3510
|
+
* ```ts
|
|
3511
|
+
* bpmn('approve')
|
|
3512
|
+
* .input('amount', 'number')
|
|
3513
|
+
* .var('amountIn', 'number', { elementId: 'start' })
|
|
3514
|
+
* .startEvent('start', {
|
|
3515
|
+
* payload: {
|
|
3516
|
+
* type: 'BPMN.Variables',
|
|
3517
|
+
* outputRows: [{ name: 'amount', type: 'number', source: '=vars.amount', var: 'amountIn' }],
|
|
3518
|
+
* },
|
|
3519
|
+
* })
|
|
3520
|
+
* // downstream: '=vars.amountIn > 1000', never '=vars.amount > 1000'
|
|
3521
|
+
* ```
|
|
3499
3522
|
*
|
|
3500
3523
|
* @param id - The input's name.
|
|
3501
3524
|
* @param type - A `types.*` descriptor, or another product spelling ({@link BpmnVarType}).
|
package/dist/bpmn/bpmn-sdk.js
CHANGED
|
@@ -2468,7 +2468,26 @@ class ScopeBuilder {
|
|
|
2468
2468
|
return this.declareVar(id, type, 'inputOutput', opts);
|
|
2469
2469
|
}
|
|
2470
2470
|
/**
|
|
2471
|
-
* A read-only entry input (`uipath:input`).
|
|
2471
|
+
* A read-only entry input (`uipath:input`), scoped to the manual start event.
|
|
2472
|
+
*
|
|
2473
|
+
* Only the start event's own mapping reads it. Every other element reads the variable
|
|
2474
|
+
* that mapping copies it into, scoped to the start event — which is what Studio Web
|
|
2475
|
+
* writes when an input is added on the canvas: a
|
|
2476
|
+
* `vars.<input>` read anywhere else is "A variable is unresolved" on the canvas, and
|
|
2477
|
+
* `check` reports it as `EXPR_ARGUMENT_REF`.
|
|
2478
|
+
*
|
|
2479
|
+
* ```ts
|
|
2480
|
+
* bpmn('approve')
|
|
2481
|
+
* .input('amount', 'number')
|
|
2482
|
+
* .var('amountIn', 'number', { elementId: 'start' })
|
|
2483
|
+
* .startEvent('start', {
|
|
2484
|
+
* payload: {
|
|
2485
|
+
* type: 'BPMN.Variables',
|
|
2486
|
+
* outputRows: [{ name: 'amount', type: 'number', source: '=vars.amount', var: 'amountIn' }],
|
|
2487
|
+
* },
|
|
2488
|
+
* })
|
|
2489
|
+
* // downstream: '=vars.amountIn > 1000', never '=vars.amount > 1000'
|
|
2490
|
+
* ```
|
|
2472
2491
|
*
|
|
2473
2492
|
* @param id - The input's name.
|
|
2474
2493
|
* @param type - A `types.*` descriptor, or another product spelling ({@link BpmnVarType}).
|
package/dist/bpmn/check.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* platform rule it corresponds to and how the two differ.
|
|
17
17
|
*/
|
|
18
18
|
import { parse } from 'acorn';
|
|
19
|
+
import { jsChildren, memberName, scopeBinds } from './script-js.js';
|
|
19
20
|
import { checkBpmnExpressions } from './bpmn-expr-check.js';
|
|
20
21
|
import { allNodes, collectSerializerModel, folderCompanionKeys, implicitNodeVars, processId } from './serialize.js';
|
|
21
22
|
import { refreshConnectionDiagnostics } from './refresh-connections.js';
|
|
@@ -1115,92 +1116,6 @@ function readsBareIdentifier(script, name) {
|
|
|
1115
1116
|
}
|
|
1116
1117
|
/** The `result` members a v2+ output may read directly: the wrapper, and the error slot. */
|
|
1117
1118
|
const RESULT_MEMBERS = new Set(['response', 'Error']);
|
|
1118
|
-
const isJsNode = (v) => typeof v === 'object' && v !== null && typeof v.type === 'string';
|
|
1119
|
-
/** The child nodes of `node`, in source order. */
|
|
1120
|
-
function jsChildren(node) {
|
|
1121
|
-
const out = [];
|
|
1122
|
-
for (const [field, v] of Object.entries(node)) {
|
|
1123
|
-
if (field === 'type' || field === 'start' || field === 'end')
|
|
1124
|
-
continue;
|
|
1125
|
-
if (Array.isArray(v))
|
|
1126
|
-
for (const item of v) {
|
|
1127
|
-
if (isJsNode(item))
|
|
1128
|
-
out.push(item);
|
|
1129
|
-
}
|
|
1130
|
-
else if (isJsNode(v))
|
|
1131
|
-
out.push(v);
|
|
1132
|
-
}
|
|
1133
|
-
return out;
|
|
1134
|
-
}
|
|
1135
|
-
/** Whether a binding pattern (`result`, `{ a: result }`, `[result = 1]`, `...result`) declares `name`. */
|
|
1136
|
-
function patternBinds(p, name) {
|
|
1137
|
-
switch (p.type) {
|
|
1138
|
-
case 'Identifier': return p.name === name;
|
|
1139
|
-
case 'AssignmentPattern': return patternBinds(p.left, name);
|
|
1140
|
-
case 'RestElement': return patternBinds(p.argument, name);
|
|
1141
|
-
case 'ArrayPattern': return p.elements.some((e) => e !== null && patternBinds(e, name));
|
|
1142
|
-
// A pattern's computed key or default value is an expression, not a binding.
|
|
1143
|
-
case 'ObjectPattern': return p.properties.some((pr) => patternBinds(pr.type === 'RestElement' ? pr : pr.value, name));
|
|
1144
|
-
default: return false;
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
const isFunction = (n) => /Function/.test(n.type);
|
|
1148
|
-
/** Whether a `let`/`const`/`var` declaration of the given kinds declares `name`. */
|
|
1149
|
-
function declarationBinds(n, name, kinds) {
|
|
1150
|
-
return isJsNode(n) && n.type === 'VariableDeclaration' && kinds(n.kind)
|
|
1151
|
-
&& n.declarations.some((d) => patternBinds(d.id, name));
|
|
1152
|
-
}
|
|
1153
|
-
/** Whether these statements, at the top of one block, declare `name` block-scoped: `let`, `const`, `class` or a function declaration. */
|
|
1154
|
-
function lexicallyBinds(statements, name) {
|
|
1155
|
-
return statements.some((s) => declarationBinds(s, name, (k) => k !== 'var')
|
|
1156
|
-
|| ((s.type === 'ClassDeclaration' || s.type === 'FunctionDeclaration') && isJsNode(s.id) && s.id.name === name));
|
|
1157
|
-
}
|
|
1158
|
-
/** Whether a `var` under `node` declares `name` in the function `node` belongs to: nested functions and static blocks are their own `var` scope and are not walked. */
|
|
1159
|
-
function varBinds(node, name) {
|
|
1160
|
-
if (declarationBinds(node, name, (k) => k === 'var'))
|
|
1161
|
-
return true;
|
|
1162
|
-
return jsChildren(node).some((c) => !isFunction(c) && c.type !== 'StaticBlock' && varBinds(c, name));
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Whether `node` opens a scope that declares `name`, so every `name` inside it is that
|
|
1166
|
-
* binding, not the outer one. A function: its own name (an expression's), a parameter,
|
|
1167
|
-
* a `var` anywhere in its body outside a nested function, or a block-scoped declaration
|
|
1168
|
-
* at the top of its body. A block, a `switch`, a `for` head or a `catch` parameter: the
|
|
1169
|
-
* declarations scoped to it. A declaration in a nested function shadows only inside that
|
|
1170
|
-
* function, so it is found when the walk reaches that function, never from outside.
|
|
1171
|
-
*/
|
|
1172
|
-
function scopeBinds(node, name) {
|
|
1173
|
-
if (isFunction(node)) {
|
|
1174
|
-
if (node.type === 'FunctionExpression' && isJsNode(node.id) && node.id.name === name)
|
|
1175
|
-
return true;
|
|
1176
|
-
if (node.params.some((p) => patternBinds(p, name)))
|
|
1177
|
-
return true;
|
|
1178
|
-
const body = node.body;
|
|
1179
|
-
return body.type === 'BlockStatement' && (varBinds(body, name) || lexicallyBinds(body.body, name));
|
|
1180
|
-
}
|
|
1181
|
-
switch (node.type) {
|
|
1182
|
-
case 'BlockStatement': return lexicallyBinds(node.body, name);
|
|
1183
|
-
case 'StaticBlock': return varBinds(node, name) || lexicallyBinds(node.body, name);
|
|
1184
|
-
case 'SwitchStatement': return lexicallyBinds(node.cases.flatMap((c) => c.consequent), name);
|
|
1185
|
-
case 'CatchClause': return isJsNode(node.param) && patternBinds(node.param, name);
|
|
1186
|
-
case 'ForStatement': return declarationBinds(node.init, name, (k) => k !== 'var');
|
|
1187
|
-
case 'ForInStatement':
|
|
1188
|
-
case 'ForOfStatement': return declarationBinds(node.left, name, (k) => k !== 'var');
|
|
1189
|
-
case 'ClassExpression':
|
|
1190
|
-
case 'ClassDeclaration': return isJsNode(node.id) && node.id.name === name;
|
|
1191
|
-
default: return false;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
/** The string a member selector names: `.response`, `['response']`, `` [`response`] ``; `undefined` for any other. */
|
|
1195
|
-
function memberName(member) {
|
|
1196
|
-
const prop = member.property;
|
|
1197
|
-
if (!member.computed)
|
|
1198
|
-
return prop.type === 'Identifier' ? prop.name : undefined;
|
|
1199
|
-
if (prop.type === 'Literal')
|
|
1200
|
-
return typeof prop.value === 'string' ? prop.value : undefined;
|
|
1201
|
-
const quasis = prop.quasis;
|
|
1202
|
-
return prop.type === 'TemplateLiteral' && quasis?.length === 1 ? quasis[0].value.cooked : undefined;
|
|
1203
|
-
}
|
|
1204
1119
|
/**
|
|
1205
1120
|
* Where `code` reads the variable `result` other than through `result.response` or
|
|
1206
1121
|
* `result.Error`: the span of each such identifier, in source order, and whether it is an object
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* It lives outside `bpmn-sdk.ts` so the checker does not import the builder back
|
|
6
6
|
* (the runtime import cycle FB003 reported).
|
|
7
7
|
*/
|
|
8
|
-
import type { BpmnNode } from './bpmn-sdk.js';
|
|
8
|
+
import type { BpmnNode, BpmnVarDecl } from './bpmn-sdk.js';
|
|
9
9
|
/**
|
|
10
10
|
* The variables a connector task's output rows land in.
|
|
11
11
|
*
|
|
@@ -58,3 +58,32 @@ export declare function typedNodeDeclaredVars(n: Extract<BpmnNode, {
|
|
|
58
58
|
* @internal
|
|
59
59
|
*/
|
|
60
60
|
export declare function nodeDeclaredVars(n: BpmnNode): string[];
|
|
61
|
+
/**
|
|
62
|
+
* Where an unscoped PUBLIC declaration belongs at the top level of a process.
|
|
63
|
+
*
|
|
64
|
+
* Every real artifact agrees: across the 97 Studio Web exports and converter outputs
|
|
65
|
+
* measured (`research/bpmn-roundtrip/corpus/`, the run-6 `v1` arm), all 107 public
|
|
66
|
+
* `uipath:input` declarations are scoped to the process's manual START event and all
|
|
67
|
+
* 37 `uipath:output` declarations to the END event whose mapping writes them — none to
|
|
68
|
+
* the process. The engine does not need it (`BpmnDataManager.EvaluateProcessVariables`
|
|
69
|
+
* seeds every declaration into one variables scope by id, and an expression resolves
|
|
70
|
+
* `vars.<id>` there whatever the declaration's `elementId`), but the canvas, the
|
|
71
|
+
* entry-point derivation and the graders that read a process's contract do: a process
|
|
72
|
+
* input is "the start event's input". Until this, the SDK wrote the process id, which
|
|
73
|
+
* validated and ran and was the one placement nothing else on the platform produces —
|
|
74
|
+
* cluster D of docs/BPMN_AUTHORING_ERGONOMICS_DESIGN.md §1b.
|
|
75
|
+
*
|
|
76
|
+
* Shared by the serializer, which writes it, and the expression check, which needs to
|
|
77
|
+
* know where a public argument is readable from (#2138).
|
|
78
|
+
*
|
|
79
|
+
* The rule, mirrored by `bpmn-decompile` so an unscoped declaration round-trips without
|
|
80
|
+
* an explicit `elementId`:
|
|
81
|
+
* - `input` → the one root start event with no event definition and no trigger,
|
|
82
|
+
* when there is exactly one; else the process.
|
|
83
|
+
* - `output` → the one root end event whose payload writes `var="<id>"`; else the one
|
|
84
|
+
* root end event, when there is exactly one; else the process.
|
|
85
|
+
* - `inputOutput` → the process (an internal variable is process-level state; the
|
|
86
|
+
* engine's debug variables report lists exactly those).
|
|
87
|
+
* An explicit `elementId` always wins, and `null` still means "write none".
|
|
88
|
+
*/
|
|
89
|
+
export declare function publicDeclarationScope(nodes: BpmnNode[], processId: string): (v: BpmnVarDecl) => string;
|
|
@@ -54,6 +54,26 @@ export function typedNodeDeclaredVars(n) {
|
|
|
54
54
|
* @internal
|
|
55
55
|
*/
|
|
56
56
|
export function nodeDeclaredVars(n) {
|
|
57
|
+
return [...ownDeclaredVars(n), ...payloadDeclaredVars(n)];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The variables a node's decorating PAYLOAD writes: each `uipath:output` row's `var`, as
|
|
61
|
+
* on any other node. A start event's `BPMN.Variables` mapping copies an input into a
|
|
62
|
+
* process variable this way, a message start event lands the message in one, and a
|
|
63
|
+
* sub-process's mapping hoists its result into the enclosing scope (`var="fetch.output"`,
|
|
64
|
+
* the shape the Flow converter emits for every HTTP, connector and loop node).
|
|
65
|
+
*/
|
|
66
|
+
function payloadDeclaredVars(n) {
|
|
67
|
+
const payload = 'payload' in n ? n.payload : undefined;
|
|
68
|
+
return (payload?.outputRows ?? []).map((r) => r.var).filter((v) => v !== undefined);
|
|
69
|
+
}
|
|
70
|
+
function ownDeclaredVars(n) {
|
|
71
|
+
// A trigger's payload row writes a variable like any typed node's; serialize declares it
|
|
72
|
+
// (`implicitNodeVars`), so a read of it resolves.
|
|
73
|
+
if (n.kind === 'startEvent' && n.trigger) {
|
|
74
|
+
const v = typedNodeOutputVar(n.id, n.trigger.type, n.trigger.outputVar);
|
|
75
|
+
return v ? [v] : [];
|
|
76
|
+
}
|
|
57
77
|
if (n.kind === 'connector') {
|
|
58
78
|
const { response, error } = connectorOutputVars(n);
|
|
59
79
|
return [response, error, ...Object.keys(n.outputs ?? {})];
|
|
@@ -80,3 +100,46 @@ export function nodeDeclaredVars(n) {
|
|
|
80
100
|
return Object.keys(n.set);
|
|
81
101
|
return [];
|
|
82
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Where an unscoped PUBLIC declaration belongs at the top level of a process.
|
|
105
|
+
*
|
|
106
|
+
* Every real artifact agrees: across the 97 Studio Web exports and converter outputs
|
|
107
|
+
* measured (`research/bpmn-roundtrip/corpus/`, the run-6 `v1` arm), all 107 public
|
|
108
|
+
* `uipath:input` declarations are scoped to the process's manual START event and all
|
|
109
|
+
* 37 `uipath:output` declarations to the END event whose mapping writes them — none to
|
|
110
|
+
* the process. The engine does not need it (`BpmnDataManager.EvaluateProcessVariables`
|
|
111
|
+
* seeds every declaration into one variables scope by id, and an expression resolves
|
|
112
|
+
* `vars.<id>` there whatever the declaration's `elementId`), but the canvas, the
|
|
113
|
+
* entry-point derivation and the graders that read a process's contract do: a process
|
|
114
|
+
* input is "the start event's input". Until this, the SDK wrote the process id, which
|
|
115
|
+
* validated and ran and was the one placement nothing else on the platform produces —
|
|
116
|
+
* cluster D of docs/BPMN_AUTHORING_ERGONOMICS_DESIGN.md §1b.
|
|
117
|
+
*
|
|
118
|
+
* Shared by the serializer, which writes it, and the expression check, which needs to
|
|
119
|
+
* know where a public argument is readable from (#2138).
|
|
120
|
+
*
|
|
121
|
+
* The rule, mirrored by `bpmn-decompile` so an unscoped declaration round-trips without
|
|
122
|
+
* an explicit `elementId`:
|
|
123
|
+
* - `input` → the one root start event with no event definition and no trigger,
|
|
124
|
+
* when there is exactly one; else the process.
|
|
125
|
+
* - `output` → the one root end event whose payload writes `var="<id>"`; else the one
|
|
126
|
+
* root end event, when there is exactly one; else the process.
|
|
127
|
+
* - `inputOutput` → the process (an internal variable is process-level state; the
|
|
128
|
+
* engine's debug variables report lists exactly those).
|
|
129
|
+
* An explicit `elementId` always wins, and `null` still means "write none".
|
|
130
|
+
*/
|
|
131
|
+
export function publicDeclarationScope(nodes, processId) {
|
|
132
|
+
const manualStarts = nodes.filter((n) => n.kind === 'startEvent' && n.event === undefined && n.trigger === undefined);
|
|
133
|
+
const ends = nodes.filter((n) => n.kind === 'endEvent');
|
|
134
|
+
return (v) => {
|
|
135
|
+
if (v.direction === 'input')
|
|
136
|
+
return manualStarts.length === 1 ? manualStarts[0].id : processId;
|
|
137
|
+
if (v.direction === 'output') {
|
|
138
|
+
const writers = ends.filter((e) => (e.payload?.outputRows ?? []).some((r) => r.var === v.id));
|
|
139
|
+
if (writers.length === 1)
|
|
140
|
+
return writers[0].id;
|
|
141
|
+
return ends.length === 1 ? ends[0].id : processId;
|
|
142
|
+
}
|
|
143
|
+
return processId;
|
|
144
|
+
};
|
|
145
|
+
}
|
package/dist/bpmn/decompile.js
CHANGED
|
@@ -1176,7 +1176,17 @@ function publicDeclarationScopeOf(process, processId) {
|
|
|
1176
1176
|
// payload — manual to this side, not manual to the emitter. The round trip then moved
|
|
1177
1177
|
// a public input's `elementId` from the trigger start to the process. Excluding ANY
|
|
1178
1178
|
// typed payload makes the two agree for every shape the SDK can emit.
|
|
1179
|
-
|
|
1179
|
+
//
|
|
1180
|
+
// A `uipath:mapping` is not a typed payload: it is the `BPMN.Variables` mapping a
|
|
1181
|
+
// manual start carries to copy its inputs into process variables (the canvas's own
|
|
1182
|
+
// shape, and the only element allowed to read an input — #2138). It decompiles to
|
|
1183
|
+
// `.startEvent(id, { payload })`, which the emitter counts as manual, so it is one here.
|
|
1184
|
+
const manualStarts = elements.filter((el) => {
|
|
1185
|
+
if (el.$type !== 'bpmn:StartEvent' || (el.eventDefinitions ?? []).length)
|
|
1186
|
+
return false;
|
|
1187
|
+
const payload = payloadOf(el);
|
|
1188
|
+
return payload === undefined || payload.$type === 'uipath:Mapping';
|
|
1189
|
+
});
|
|
1180
1190
|
const ends = elements.filter((el) => el.$type === 'bpmn:EndEvent');
|
|
1181
1191
|
return (kind, v) => {
|
|
1182
1192
|
if (kind === 'input')
|