@uipath/maestro-builder-sdk 6.120.19 → 6.120.21

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.
@@ -0,0 +1,179 @@
1
+ /**
2
+ * bpmn/script-js — reading a BPMN script task's JavaScript: which names a piece of code
3
+ * binds, and where it reads one.
4
+ *
5
+ * Parsed with acorn, as the Case checks parse JavaScript, so only real references count:
6
+ * a property name, an object key, a string, template text, a regex or a comment is none.
7
+ * Shared by `check` (a script output's `result` reads) and the expression rules (a script
8
+ * body's `vars.<id>` reads, bpmn-expr-check).
9
+ */
10
+ import { parse } from 'acorn';
11
+ export const isJsNode = (v) => typeof v === 'object' && v !== null && typeof v.type === 'string';
12
+ /** The child nodes of `node`, in source order. */
13
+ export function jsChildren(node) {
14
+ const out = [];
15
+ for (const [field, v] of Object.entries(node)) {
16
+ if (field === 'type' || field === 'start' || field === 'end')
17
+ continue;
18
+ if (Array.isArray(v))
19
+ for (const item of v) {
20
+ if (isJsNode(item))
21
+ out.push(item);
22
+ }
23
+ else if (isJsNode(v))
24
+ out.push(v);
25
+ }
26
+ return out;
27
+ }
28
+ /** Whether a binding pattern (`result`, `{ a: result }`, `[result = 1]`, `...result`) declares `name`. */
29
+ export function patternBinds(p, name) {
30
+ switch (p.type) {
31
+ case 'Identifier': return p.name === name;
32
+ case 'AssignmentPattern': return patternBinds(p.left, name);
33
+ case 'RestElement': return patternBinds(p.argument, name);
34
+ case 'ArrayPattern': return p.elements.some((e) => e !== null && patternBinds(e, name));
35
+ // A pattern's computed key or default value is an expression, not a binding.
36
+ case 'ObjectPattern': return p.properties.some((pr) => patternBinds(pr.type === 'RestElement' ? pr : pr.value, name));
37
+ default: return false;
38
+ }
39
+ }
40
+ export const isFunction = (n) => /Function/.test(n.type);
41
+ /** Whether a `let`/`const`/`var` declaration of the given kinds declares `name`. */
42
+ export function declarationBinds(n, name, kinds) {
43
+ return isJsNode(n) && n.type === 'VariableDeclaration' && kinds(n.kind)
44
+ && n.declarations.some((d) => patternBinds(d.id, name));
45
+ }
46
+ /** Whether these statements, at the top of one block, declare `name` block-scoped: `let`, `const`, `class` or a function declaration. */
47
+ export function lexicallyBinds(statements, name) {
48
+ return statements.some((s) => declarationBinds(s, name, (k) => k !== 'var')
49
+ || ((s.type === 'ClassDeclaration' || s.type === 'FunctionDeclaration') && isJsNode(s.id) && s.id.name === name));
50
+ }
51
+ /** 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. */
52
+ export function varBinds(node, name) {
53
+ if (declarationBinds(node, name, (k) => k === 'var'))
54
+ return true;
55
+ return jsChildren(node).some((c) => !isFunction(c) && c.type !== 'StaticBlock' && varBinds(c, name));
56
+ }
57
+ /**
58
+ * Whether `node` opens a scope that declares `name`, so every `name` inside it is that
59
+ * binding, not the outer one. A function: its own name (an expression's), a parameter,
60
+ * a `var` anywhere in its body outside a nested function, or a block-scoped declaration
61
+ * at the top of its body. A block, a `switch`, a `for` head or a `catch` parameter: the
62
+ * declarations scoped to it. A declaration in a nested function shadows only inside that
63
+ * function, so it is found when the walk reaches that function, never from outside.
64
+ */
65
+ export function scopeBinds(node, name) {
66
+ if (isFunction(node)) {
67
+ if (node.type === 'FunctionExpression' && isJsNode(node.id) && node.id.name === name)
68
+ return true;
69
+ if (node.params.some((p) => patternBinds(p, name)))
70
+ return true;
71
+ const body = node.body;
72
+ return body.type === 'BlockStatement' && (varBinds(body, name) || lexicallyBinds(body.body, name));
73
+ }
74
+ switch (node.type) {
75
+ case 'BlockStatement': return lexicallyBinds(node.body, name);
76
+ case 'StaticBlock': return varBinds(node, name) || lexicallyBinds(node.body, name);
77
+ case 'SwitchStatement': return lexicallyBinds(node.cases.flatMap((c) => c.consequent), name);
78
+ case 'CatchClause': return isJsNode(node.param) && patternBinds(node.param, name);
79
+ case 'ForStatement': return declarationBinds(node.init, name, (k) => k !== 'var');
80
+ case 'ForInStatement':
81
+ case 'ForOfStatement': return declarationBinds(node.left, name, (k) => k !== 'var');
82
+ case 'ClassExpression':
83
+ case 'ClassDeclaration': return isJsNode(node.id) && node.id.name === name;
84
+ default: return false;
85
+ }
86
+ }
87
+ /** The string a member selector names: `.response`, `['response']`, `` [`response`] ``; `undefined` for any other. */
88
+ export function memberName(member) {
89
+ const prop = member.property;
90
+ if (!member.computed)
91
+ return prop.type === 'Identifier' ? prop.name : undefined;
92
+ if (prop.type === 'Literal')
93
+ return typeof prop.value === 'string' ? prop.value : undefined;
94
+ const quasis = prop.quasis;
95
+ return prop.type === 'TemplateLiteral' && quasis?.length === 1 ? quasis[0].value.cooked : undefined;
96
+ }
97
+ /** Whether a `vars.<root>` met under a node is a read. */
98
+ var ReadContext;
99
+ (function (ReadContext) {
100
+ /** It is: the body uses the value. */
101
+ ReadContext[ReadContext["Read"] = 0] = "Read";
102
+ /** Under `typeof`: the body only asks whether it exists. */
103
+ ReadContext[ReadContext["TypeofOperand"] = 1] = "TypeofOperand";
104
+ })(ReadContext || (ReadContext = {}));
105
+ /**
106
+ * Every `vars.<root>` a script BODY reads, with the path after the root, or `undefined`
107
+ * when the body does not parse (nothing is claimed about code that does not run).
108
+ *
109
+ * The platform runs the body as a function (`(function(){<body>})()`, as the local
110
+ * engine does) with `vars` in scope. A read is a member selector on that `vars`: dotted
111
+ * (`vars.amount`), or a quoted key (`vars['amount']`). Not a read:
112
+ *
113
+ * - anything under a scope that binds its own `vars` (a parameter, `let`, `const`,
114
+ * `var`, a function or `catch` binding), which is not the platform's;
115
+ * - a computed key (`vars[name]`), which names no root this can see;
116
+ * - a call through `vars` (`vars.hasOwnProperty('x')`): an `Object.prototype` method,
117
+ * not a variable;
118
+ * - the operand of `typeof`, which a script uses to ask whether a variable exists;
119
+ * - a root the body itself ASSIGNS (`vars.total = …`, `vars.total ??= 0`) or deletes,
120
+ * whose later read is of the body's own value.
121
+ */
122
+ export function scriptVarReads(script) {
123
+ let program;
124
+ try {
125
+ program = parse(`(function(){${script}\n})`, { ecmaVersion: 'latest', sourceType: 'script' });
126
+ }
127
+ catch {
128
+ return undefined;
129
+ }
130
+ const reads = [];
131
+ const written = new Set();
132
+ /** `stack` is the ancestors of `node`, nearest last. */
133
+ const visit = (node, stack, context) => {
134
+ if (node.type === 'MemberExpression' && isJsNode(node.object) && node.object.type === 'Identifier' && node.object.name === 'vars') {
135
+ const root = memberName(node);
136
+ const parent = stack[stack.length - 1];
137
+ if (root !== undefined) {
138
+ const target = (parent?.type === 'AssignmentExpression' && parent.left === node)
139
+ || parent?.type === 'UpdateExpression'
140
+ || (parent?.type === 'UnaryExpression' && parent.operator === 'delete');
141
+ const callee = parent?.type === 'CallExpression' && parent.callee === node;
142
+ if (target)
143
+ written.add(root);
144
+ else if (!callee && context === ReadContext.Read) {
145
+ // The selectors after the root, outward: `vars.step1.output.ok` → ['output', 'ok'].
146
+ const path = [];
147
+ let inner = node;
148
+ for (let k = stack.length - 1; k >= 0; k--) {
149
+ const outer = stack[k];
150
+ if (outer.type !== 'MemberExpression' || outer.object !== inner)
151
+ break;
152
+ const name = memberName(outer);
153
+ if (name === undefined)
154
+ break;
155
+ path.push(name);
156
+ inner = outer;
157
+ }
158
+ reads.push({ root, path, raw: ['vars', root, ...path].join('.') });
159
+ }
160
+ }
161
+ // A computed key is code of its own (`vars[pick(vars.kind)]`).
162
+ if (node.computed)
163
+ visit(node.property, [...stack, node], context);
164
+ return;
165
+ }
166
+ if (scopeBinds(node, 'vars'))
167
+ return;
168
+ const typeofOperand = node.type === 'UnaryExpression' && node.operator === 'typeof';
169
+ for (const child of jsChildren(node)) {
170
+ // A name in a property position is not a reference: `a.vars`, `{ vars: … }`, a label.
171
+ const isName = child === node.key || child === node.property || child === node.label || child === node.meta;
172
+ if (isName && !node.computed)
173
+ continue;
174
+ visit(child, [...stack, node], typeofOperand ? ReadContext.TypeofOperand : context);
175
+ }
176
+ };
177
+ visit(program, [], ReadContext.Read);
178
+ return reads.filter((r) => !written.has(r.root));
179
+ }
package/dist/bpmn-api.md CHANGED
@@ -615,7 +615,7 @@ One sequence flow in the built graph — the edge from `source` to `target` (`bp
615
615
  - `BpmnFlow.source: string` — The id of the element the flow leaves.
616
616
  - `BpmnFlow.target: string` — The id of the element it arrives at.
617
617
  - `BpmnFlow.name?: string` — Edge label the designer shows.
618
- - `BpmnFlow.condition?: string` — `=`-expression gating this flow (exclusive/inclusive gateway outgoing).
618
+ - `BpmnFlow.condition?: string` — `=`-expression gating this flow (exclusive/inclusive gateway outgoing), e.g. `'=js:vars.status == "ok"'`.
619
619
  - `BpmnFlow.implied?: true` — Set on a flow the builder wrote by implication — an arm's chain, a handler's path, a construct's join, or a…
620
620
 
621
621
  ### `BpmnVarDecl`
@@ -159,3 +159,10 @@ export declare function quotedOnlyMentions(expr: string, namespace?: string): Qu
159
159
  * "fully valid"; the `validate` CLI is what proves the rest.
160
160
  */
161
161
  export declare function checkExpression(expr: string, scope: ExprScope, escapes?: readonly CookedEscape[]): ExprDiagnostic[];
162
+ /**
163
+ * The resolution half of {@link checkExpression}, for references found some other way
164
+ * than by scanning an expression's text — a BPMN script body's `vars.<id>` reads, which
165
+ * are found by parsing the JavaScript (`bpmn/script-js.ts`). Every reference's root must
166
+ * resolve; one diagnostic per unresolved root.
167
+ */
168
+ export declare function checkRefs(refs: readonly ExprRef[], scope: ExprScope): ExprDiagnostic[];
@@ -316,9 +316,6 @@ function nearMiss(name, roots) {
316
316
  */
317
317
  export function checkExpression(expr, scope, escapes = []) {
318
318
  const namespace = scope.namespace ?? DEFAULT_NAMESPACE;
319
- const noun = scope.noun ?? 'input, variable, or step';
320
- const diags = [];
321
- const seen = new Set();
322
319
  // Syntax first: an expression that does not parse cannot have meaningful
323
320
  // references, and reporting both would just be noise on one root cause.
324
321
  const syntax = scope.syntax === 'javascript' ? syntaxError(expr) : undefined;
@@ -340,8 +337,21 @@ export function checkExpression(expr, scope, escapes = []) {
340
337
  : {}),
341
338
  }];
342
339
  }
340
+ return checkRefs(extractRefs(expr, namespace), scope);
341
+ }
342
+ /**
343
+ * The resolution half of {@link checkExpression}, for references found some other way
344
+ * than by scanning an expression's text — a BPMN script body's `vars.<id>` reads, which
345
+ * are found by parsing the JavaScript (`bpmn/script-js.ts`). Every reference's root must
346
+ * resolve; one diagnostic per unresolved root.
347
+ */
348
+ export function checkRefs(refs, scope) {
349
+ const namespace = scope.namespace ?? DEFAULT_NAMESPACE;
350
+ const noun = scope.noun ?? 'input, variable, or step';
351
+ const diags = [];
352
+ const seen = new Set();
343
353
  const dotted = dottedRoots(scope.roots);
344
- for (const ref of extractRefs(expr, namespace)) {
354
+ for (const ref of refs) {
345
355
  if (scope.roots.has(ref.root))
346
356
  continue;
347
357
  const name = dotted.length ? unresolvedDottedName(ref, dotted) : ref.root;
@@ -355,6 +355,8 @@ export declare const REFUSALS: {
355
355
  readonly EVENT_WHERE_NOT_SCALAR: "lowering";
356
356
  readonly EXCEPTION_STAGE_REQUIRED: "lint";
357
357
  readonly EXPR_ARGUMENT_REF: "lint";
358
+ readonly EXPR_BARE_PREFIX: "lint";
359
+ readonly EXPR_BARE_PREFIX_JS_SYNTAX: "lint";
358
360
  readonly EXPR_BARE_VAR_REF: "lint";
359
361
  readonly EXPR_SYNTAX: "lowering";
360
362
  readonly EXPR_UNDECLARED_REF: "lint";
@@ -429,6 +429,8 @@ export const REFUSALS = {
429
429
  EVENT_WHERE_NOT_SCALAR: 'lowering',
430
430
  EXCEPTION_STAGE_REQUIRED: 'lint',
431
431
  EXPR_ARGUMENT_REF: 'lint',
432
+ EXPR_BARE_PREFIX: 'lint',
433
+ EXPR_BARE_PREFIX_JS_SYNTAX: 'lint',
432
434
  EXPR_BARE_VAR_REF: 'lint',
433
435
  EXPR_SYNTAX: 'lowering',
434
436
  EXPR_UNDECLARED_REF: 'lint',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.120.19",
3
+ "version": "6.120.21",
4
4
  "description": "Build UiPath Flow, Case, and BPMN artifacts by writing TypeScript.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.uipath.com/maestro",
@@ -124,5 +124,5 @@
124
124
  "@types/node": "^22.7.0",
125
125
  "esbuild": "^0.28.1"
126
126
  },
127
- "gitref": "b422c75363bbd5372d32499c77e6937ae2cc7f85"
127
+ "gitref": "e6178daa6ae6b993efc27cf07a2ed1d9b21a9e23"
128
128
  }