@uipath/maestro-builder-sdk 6.122.9 → 6.122.10
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/core/js-code-spans.d.ts +0 -19
- package/dist/core/js-code-spans.js +94 -7
- package/dist/decompile.js +85 -1
- package/package.json +2 -2
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The parts of a JavaScript expression or script body that are code.
|
|
3
|
-
*
|
|
4
|
-
* Short version: `$vars.summary` inside a quoted string is text, not a read.
|
|
5
|
-
* A rewrite that renames `$vars.<name>` (a step's node id, an output's backing
|
|
6
|
-
* Variable, #1092) must leave string literals, comments and regex literals
|
|
7
|
-
* alone, or it changes what the flow does:
|
|
8
|
-
*
|
|
9
|
-
* ```js
|
|
10
|
-
* return "$vars.summary" + $vars.summary;
|
|
11
|
-
* // ^^^^^^^^^^^^^^^ text: kept ^^^^^^^^^^^^^ code: renamed
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* A template literal's text is kept too, and its `${…}` holes are code.
|
|
15
|
-
*
|
|
16
|
-
* This is a scanner, not a parser. It tells a regex literal from a division by
|
|
17
|
-
* the character before the `/` (the usual heuristic), so `return /"/` is read
|
|
18
|
-
* as a division. Nothing in a flow's expressions depends on that case.
|
|
19
|
-
*/
|
|
20
1
|
/**
|
|
21
2
|
* `text` with `fn` applied to each run of code, and every string, template
|
|
22
3
|
* text, comment and regex literal copied as written.
|
|
@@ -13,17 +13,86 @@
|
|
|
13
13
|
*
|
|
14
14
|
* A template literal's text is kept too, and its `${…}` holes are code.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* The spans come from a parse (acorn, as the BPMN and Case checks read
|
|
17
|
+
* JavaScript), so a `/` is a regex or a division exactly as the language says:
|
|
18
|
+
* `if (x) /re/.test(s)` and `return /re/` open a regex, `πreturn / 2` and
|
|
19
|
+
* `obj. return / 2` divide. Text that parses neither as a script body nor as an
|
|
20
|
+
* expression (a fragment, a typo) falls back to {@link scanJsCode}, a scanner
|
|
21
|
+
* that judges a `/` by the token before it.
|
|
19
22
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
import { parse } from 'acorn';
|
|
24
|
+
/** Non-code `[start, end)` spans of `text` from a parse, or undefined when it parses neither as a script body nor as an expression. */
|
|
25
|
+
function literalSpans(text) {
|
|
26
|
+
// An expression that is not a statement (`{ "a": 1 }`) parses inside parentheses.
|
|
27
|
+
for (const [prefix, suffix] of [['', ''], ['(', '\n)']]) {
|
|
28
|
+
const spans = [];
|
|
29
|
+
const src = prefix + text + suffix;
|
|
30
|
+
const at = (start, end) => {
|
|
31
|
+
const from = Math.max(start - prefix.length, 0);
|
|
32
|
+
const to = Math.min(end - prefix.length, text.length);
|
|
33
|
+
if (to > from)
|
|
34
|
+
spans.push([from, to]);
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
parse(src, {
|
|
38
|
+
ecmaVersion: 'latest', sourceType: 'script',
|
|
39
|
+
allowReturnOutsideFunction: true, allowAwaitOutsideFunction: true,
|
|
40
|
+
onToken: (t) => {
|
|
41
|
+
const label = t.type.label;
|
|
42
|
+
if (label === 'string' || label === 'regexp' || label === 'template' || label === 'invalidTemplate')
|
|
43
|
+
at(t.start, t.end);
|
|
44
|
+
},
|
|
45
|
+
onComment: (_block, _text, start, end) => at(start, end),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
return spans.sort((a, b) => a[0] - b[0]);
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
22
55
|
/**
|
|
23
56
|
* `text` with `fn` applied to each run of code, and every string, template
|
|
24
57
|
* text, comment and regex literal copied as written.
|
|
25
58
|
*/
|
|
26
59
|
export function mapJsCode(text, fn) {
|
|
60
|
+
// Every literal and comment opens with one of these: text with none is all code, and needs no parse.
|
|
61
|
+
if (!/["'`/]/.test(text))
|
|
62
|
+
return fn(text);
|
|
63
|
+
const spans = literalSpans(text);
|
|
64
|
+
if (spans === undefined)
|
|
65
|
+
return scanJsCode(text, fn);
|
|
66
|
+
let out = '';
|
|
67
|
+
let i = 0;
|
|
68
|
+
for (const [from, to] of spans) {
|
|
69
|
+
if (from < i)
|
|
70
|
+
continue;
|
|
71
|
+
if (from > i)
|
|
72
|
+
out += fn(text.slice(i, from));
|
|
73
|
+
out += text.slice(from, to);
|
|
74
|
+
i = to;
|
|
75
|
+
}
|
|
76
|
+
if (i < text.length)
|
|
77
|
+
out += fn(text.slice(i));
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
/** Characters after which a `/` starts a regex literal, not a division. */
|
|
81
|
+
const REGEX_AFTER = new Set('(,=:[!&|?{};+-*%<>~^'.split(''));
|
|
82
|
+
/** Keywords after which a `/` starts a regex literal: what follows them is an operand. */
|
|
83
|
+
const REGEX_AFTER_KEYWORD = new Set([
|
|
84
|
+
'return', 'typeof', 'instanceof', 'in', 'of', 'new', 'delete', 'void', 'throw', 'case', 'do', 'else', 'yield', 'await',
|
|
85
|
+
]);
|
|
86
|
+
/** A character of an identifier or a number: a word token. */
|
|
87
|
+
const IDENT = /[\p{ID_Continue}$\u200c\u200d]/u;
|
|
88
|
+
/**
|
|
89
|
+
* {@link mapJsCode} for text that does not parse: a scanner, not a parser. It
|
|
90
|
+
* tells a regex literal from a division by the token before the `/`, across
|
|
91
|
+
* whitespace and comments: a punctuator, or a keyword that leaves an operand
|
|
92
|
+
* position (`return /"/`). A member name spelled like a keyword
|
|
93
|
+
* (`x.return / 2`) is an operand, so its `/` divides.
|
|
94
|
+
*/
|
|
95
|
+
function scanJsCode(text, fn) {
|
|
27
96
|
let out = '';
|
|
28
97
|
const n = text.length;
|
|
29
98
|
const flushCode = (from, to) => { if (to > from)
|
|
@@ -66,21 +135,36 @@ export function mapJsCode(text, fn) {
|
|
|
66
135
|
const scanCode = (i, inHole) => {
|
|
67
136
|
let start = i;
|
|
68
137
|
let depth = 0;
|
|
138
|
+
// The token before the next one, across whitespace and comments: `prev` is
|
|
139
|
+
// its last character; `keyword` says it is a REGEX_AFTER_KEYWORD word that
|
|
140
|
+
// is not a member name (`x.return`, `x?. return`).
|
|
69
141
|
let prev = '';
|
|
142
|
+
let keyword = false;
|
|
70
143
|
while (i < n) {
|
|
71
144
|
const c = text[i];
|
|
145
|
+
if (IDENT.test(c)) {
|
|
146
|
+
let j = i + 1;
|
|
147
|
+
while (j < n && IDENT.test(text[j]))
|
|
148
|
+
j++;
|
|
149
|
+
keyword = prev !== '.' && REGEX_AFTER_KEYWORD.has(text.slice(i, j));
|
|
150
|
+
prev = text[j - 1];
|
|
151
|
+
i = j;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
72
154
|
if (c === '"' || c === "'") {
|
|
73
155
|
flushCode(start, i);
|
|
74
156
|
const j = endQuoted(i, c);
|
|
75
157
|
out += text.slice(i, j);
|
|
76
158
|
i = start = j;
|
|
77
159
|
prev = c;
|
|
160
|
+
keyword = false;
|
|
78
161
|
continue;
|
|
79
162
|
}
|
|
80
163
|
if (c === '`') {
|
|
81
164
|
flushCode(start, i);
|
|
82
165
|
i = start = scanTemplate(i);
|
|
83
166
|
prev = c;
|
|
167
|
+
keyword = false;
|
|
84
168
|
continue;
|
|
85
169
|
}
|
|
86
170
|
if (c === '/' && (text[i + 1] === '/' || text[i + 1] === '*')) {
|
|
@@ -91,12 +175,13 @@ export function mapJsCode(text, fn) {
|
|
|
91
175
|
i = start = j;
|
|
92
176
|
continue;
|
|
93
177
|
}
|
|
94
|
-
if (c === '/' && (prev === '' || REGEX_AFTER.has(prev))) {
|
|
178
|
+
if (c === '/' && (prev === '' || REGEX_AFTER.has(prev) || keyword)) {
|
|
95
179
|
flushCode(start, i);
|
|
96
180
|
const j = endRegex(i);
|
|
97
181
|
out += text.slice(i, j);
|
|
98
182
|
i = start = j;
|
|
99
183
|
prev = '/';
|
|
184
|
+
keyword = false;
|
|
100
185
|
continue;
|
|
101
186
|
}
|
|
102
187
|
if (inHole) {
|
|
@@ -110,8 +195,10 @@ export function mapJsCode(text, fn) {
|
|
|
110
195
|
depth--;
|
|
111
196
|
}
|
|
112
197
|
}
|
|
113
|
-
if (!/\s/.test(c))
|
|
198
|
+
if (!/\s/.test(c)) {
|
|
114
199
|
prev = c;
|
|
200
|
+
keyword = false;
|
|
201
|
+
}
|
|
115
202
|
i++;
|
|
116
203
|
}
|
|
117
204
|
flushCode(start, i);
|
package/dist/decompile.js
CHANGED
|
@@ -3064,6 +3064,8 @@ function renameVarRoot(v, from, to) {
|
|
|
3064
3064
|
const inCode = (js) => mapJsCode(js, (code) => code.replace(re, () => `$vars.${to}`));
|
|
3065
3065
|
const walk = (x, key) => {
|
|
3066
3066
|
if (typeof x === 'string') {
|
|
3067
|
+
if (!x.includes(`$vars.${from}`))
|
|
3068
|
+
return x;
|
|
3067
3069
|
if (x.startsWith('=js:'))
|
|
3068
3070
|
return '=js:' + inCode(x.slice(4));
|
|
3069
3071
|
if (x.startsWith('$vars.') || (key !== undefined && RAW_JS_FIELDS.has(key)))
|
|
@@ -3126,8 +3128,90 @@ function foldOutputBacking(flow) {
|
|
|
3126
3128
|
}
|
|
3127
3129
|
return out;
|
|
3128
3130
|
}
|
|
3131
|
+
/**
|
|
3132
|
+
* Read a flow input the file left process-level (an `in` global with no
|
|
3133
|
+
* `triggerNodeId`) through the trigger compile will bind it to.
|
|
3134
|
+
*
|
|
3135
|
+
* `.input()` declares a trigger-scoped input: compile stamps `triggerNodeId`
|
|
3136
|
+
* on every one it writes (the root trigger, or a subflow body's own Start), and
|
|
3137
|
+
* the runtime then surfaces it only as `$vars.<trigger>.output.<name>`. The
|
|
3138
|
+
* source has no spelling for a process-level input, so a bare `$vars.<name>`
|
|
3139
|
+
* read of one must move to the trigger's output with it, or the recompiled
|
|
3140
|
+
* file reads null under any trigger but a manual one (`flow validate` refuses
|
|
3141
|
+
* it). A read that is the whole value already came back as `input('<name>')`;
|
|
3142
|
+
* one inside a larger expression (`$vars.n * 4`) or a script kept the bare
|
|
3143
|
+
* spelling, so a no-edit round trip changed what the flow reads.
|
|
3144
|
+
*
|
|
3145
|
+
* Rewritten in code spans of code slots only (`renameInputReads`), in the
|
|
3146
|
+
* nodes and the variable updates, before anything is printed: the whole-value reads then
|
|
3147
|
+
* print as `input('<name>')` as before, and the rest as the trigger-output
|
|
3148
|
+
* path. A name a node of the scope also has is that node's (validate reads it
|
|
3149
|
+
* so too) and is left alone. Applied to each subflow body against its own
|
|
3150
|
+
* Start.
|
|
3151
|
+
*/
|
|
3152
|
+
function bindProcessInputReads(flow) {
|
|
3153
|
+
const subflows = flow.subflows
|
|
3154
|
+
? Object.fromEntries(Object.entries(flow.subflows).map(([k, c]) => [k, bindProcessInputReads(c)]))
|
|
3155
|
+
: undefined;
|
|
3156
|
+
let out = subflows ? { ...flow, subflows } : flow;
|
|
3157
|
+
const globals = Array.isArray(flow.variables?.globals) ? flow.variables.globals : [];
|
|
3158
|
+
const nodes = Array.isArray(flow.nodes) ? flow.nodes : [];
|
|
3159
|
+
const nodeIds = new Set(nodes.map((n) => n.id));
|
|
3160
|
+
const unscoped = globals.filter((g) => g.direction === 'in' && typeof g.id === 'string' && g.id !== ''
|
|
3161
|
+
&& (g.triggerNodeId === undefined || g.triggerNodeId === '') && !nodeIds.has(g.id));
|
|
3162
|
+
if (unscoped.length === 0)
|
|
3163
|
+
return out;
|
|
3164
|
+
// The default root, chosen as `decompile` chooses the one `.input()` binds to.
|
|
3165
|
+
const targets = new Set((flow.edges ?? []).map((e) => e.targetNodeId));
|
|
3166
|
+
const roots = nodes.filter((n) => typeof n.type === 'string' && isTrigger(n.type) && !targets.has(n.id));
|
|
3167
|
+
const trigger = roots.find((n) => (n.inputs ?? {}).isDefaultEntryPoint === true)
|
|
3168
|
+
?? roots.find((n) => n.id === DEFAULT_TRIGGER_ID)
|
|
3169
|
+
?? roots[0];
|
|
3170
|
+
if (trigger === undefined)
|
|
3171
|
+
return out;
|
|
3172
|
+
let rewritten = out.nodes;
|
|
3173
|
+
let updates = out.variables?.variableUpdates;
|
|
3174
|
+
for (const g of unscoped) {
|
|
3175
|
+
rewritten = renameInputReads(rewritten, g.id, `${trigger.id}.output.${g.id}`);
|
|
3176
|
+
updates = renameInputReads(updates, g.id, `${trigger.id}.output.${g.id}`);
|
|
3177
|
+
}
|
|
3178
|
+
out = { ...out, nodes: rewritten, variables: { ...out.variables, ...(updates !== undefined ? { variableUpdates: updates } : {}) } };
|
|
3179
|
+
return out;
|
|
3180
|
+
}
|
|
3181
|
+
/**
|
|
3182
|
+
* `renameVarRoot`, held to the slots that hold code: a `=js:` value anywhere,
|
|
3183
|
+
* and a value under a `RAW_JS_FIELDS` key or an output's `source`. A label, a
|
|
3184
|
+
* description or any other text that happens to start `$vars.` is data, and so
|
|
3185
|
+
* is a literal envelope and everything under a node's `display` and `ui`.
|
|
3186
|
+
*/
|
|
3187
|
+
function renameInputReads(v, from, to) {
|
|
3188
|
+
const re = new RegExp(`\\$vars\\.${escapeRegExp(from)}(?![A-Za-z0-9_$])`, 'g');
|
|
3189
|
+
// a function: `$&` in `to` is data
|
|
3190
|
+
const inCode = (js) => mapJsCode(js, (code) => code.replace(re, () => `$vars.${to}`));
|
|
3191
|
+
const walk = (x, key) => {
|
|
3192
|
+
if (typeof x === 'string') {
|
|
3193
|
+
if (!x.includes(`$vars.${from}`))
|
|
3194
|
+
return x;
|
|
3195
|
+
if (x.startsWith('=js:'))
|
|
3196
|
+
return '=js:' + inCode(x.slice(4));
|
|
3197
|
+
if (key !== undefined && (RAW_JS_FIELDS.has(key) || key === 'source'))
|
|
3198
|
+
return inCode(x);
|
|
3199
|
+
return x;
|
|
3200
|
+
}
|
|
3201
|
+
if (Array.isArray(x))
|
|
3202
|
+
return x.map((y) => walk(y, key));
|
|
3203
|
+
if (x && typeof x === 'object') {
|
|
3204
|
+
// A literal envelope's `expression` is its text, not code.
|
|
3205
|
+
if (x.type === 'literal')
|
|
3206
|
+
return x;
|
|
3207
|
+
return Object.fromEntries(Object.entries(x).map(([k, y]) => [k, k === 'display' || k === 'ui' ? y : walk(y, k)]));
|
|
3208
|
+
}
|
|
3209
|
+
return x;
|
|
3210
|
+
};
|
|
3211
|
+
return walk(v);
|
|
3212
|
+
}
|
|
3129
3213
|
export function decompile(flow, options = {}) {
|
|
3130
|
-
flow = foldOutputBacking(flow);
|
|
3214
|
+
flow = bindProcessInputReads(foldOutputBacking(flow));
|
|
3131
3215
|
runScripts = options.scripts ?? defaultScripts();
|
|
3132
3216
|
runModuleFunctions = [];
|
|
3133
3217
|
runFunctionNames = new Map();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uipath/maestro-builder-sdk",
|
|
3
|
-
"version": "6.122.
|
|
3
|
+
"version": "6.122.10",
|
|
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",
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
"@types/node": "^22.7.0",
|
|
127
127
|
"esbuild": "^0.28.1"
|
|
128
128
|
},
|
|
129
|
-
"gitref": "
|
|
129
|
+
"gitref": "3464553851157aa8f62eb57613f8be59527aaf5d"
|
|
130
130
|
}
|