@uipath/maestro-builder-sdk 6.86.15 → 6.86.16

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.
@@ -22,12 +22,36 @@ import type { BuiltCase } from './case-sdk.js';
22
22
  export interface CaseLocatedDiagnostic extends ExprDiagnostic {
23
23
  where: string;
24
24
  }
25
+ /**
26
+ * The undeclared `vars.<root>` names `expr` reads, as `build()` reports them
27
+ * (`EXPR_UNDECLARED_REF`). A task-output reference stands in as a declared root.
28
+ * For decompile, which refuses such a gate by name rather than writing source
29
+ * compile refuses.
30
+ */
31
+ export declare function undeclaredVarReads(expr: string, roots: ReadonlySet<string>): string[];
25
32
  /**
26
33
  * The platform variable that says whether the stage labelled `label` has run
27
34
  * (case-schema `baseLocalStageHasRunVariableInfoForStage`): `Stage 1` ->
28
35
  * `stageHasRun_Stage_1`. Exported for the Case fuzzer's stage renames.
29
36
  */
30
37
  export declare function stageHasRunVariable(label: string): string;
38
+ /**
39
+ * Variables the platform declares for every case, which a plan's gates may read
40
+ * though no row of the plan declares them. `uip maestro case validate` adds the
41
+ * same set to the variables it checks against (case-schema
42
+ * `validateCaseManagementVariables`), and the BPMN converter writes each one:
43
+ *
44
+ * - `stageHasRun_<stage label>` per stage (`getCaseStateVariables`), set in the
45
+ * initial variables setup and updated when the stage exits or completes. The
46
+ * platform's own V11->V12 migration writes gates on it:
47
+ * `=js:(vars.stageHasRun_Review != true)` for "first time this stage runs";
48
+ * - the hidden event-subprocess rows `tasksEventSubprocessResponse`,
49
+ * `mainEventSubprocessResponse`, `connectorResponse` and `eventMetadata`.
50
+ *
51
+ * Not here: the per-SLA `stageSla_<stage>_<sla id>` rows, whose ids compile
52
+ * mints after this check runs.
53
+ */
54
+ export declare function platformVariables(stageLabels: readonly string[]): string[];
31
55
  /** Every first-level expression problem in a built case, each stamped with its location. */
32
56
  export declare function checkCaseExpressions(built: BuiltCase): CaseLocatedDiagnostic[];
33
57
  /**
@@ -15,7 +15,7 @@
15
15
  * (`rule.stage` / `rule.tasks`) are a different thing and are checked by
16
16
  * `case/check.ts`, not here.
17
17
  */
18
- import { checkExpression } from '../core/expr-check.js';
18
+ import { checkExpression, extractRefs } from '../core/expr-check.js';
19
19
  import { CompileRefusal } from '../core/compile-refusal.js';
20
20
  import { readEventFilter } from '../core/event-filters.js';
21
21
  import { defaultActionOutputVar } from './action-output-var.js';
@@ -77,6 +77,17 @@ function checkTaskOutputRefs(built, value, where, out) {
77
77
  out.push({ level: 'error', code: 'TASK_OUTPUT_REF_UNRESOLVED', message: unresolvedTaskOutputRef(ref, why), where });
78
78
  }
79
79
  }
80
+ /**
81
+ * The undeclared `vars.<root>` names `expr` reads, as `build()` reports them
82
+ * (`EXPR_UNDECLARED_REF`). A task-output reference stands in as a declared root.
83
+ * For decompile, which refuses such a gate by name rather than writing source
84
+ * compile refuses.
85
+ */
86
+ export function undeclaredVarReads(expr, roots) {
87
+ const lowered = lowerTaskOutputRefs(expr, () => TASK_OUTPUT_ROOT);
88
+ const scope = new Set([...roots, TASK_OUTPUT_ROOT]);
89
+ return [...new Set(extractRefs(lowered, NAMESPACE).map((ref) => ref.root).filter((root) => !scope.has(root)))];
90
+ }
80
91
  function checkExpr(built, expr, where, roots, out) {
81
92
  if (!expr)
82
93
  return;
@@ -147,9 +158,9 @@ export function stageHasRunVariable(label) {
147
158
  * Not here: the per-SLA `stageSla_<stage>_<sla id>` rows, whose ids compile
148
159
  * mints after this check runs.
149
160
  */
150
- function platformVariables(built) {
161
+ export function platformVariables(stageLabels) {
151
162
  return [
152
- ...built.stages.map((s) => stageHasRunVariable(s.label)),
163
+ ...stageLabels.map((label) => stageHasRunVariable(label)),
153
164
  'tasksEventSubprocessResponse',
154
165
  'mainEventSubprocessResponse',
155
166
  'connectorResponse',
@@ -159,7 +170,7 @@ function platformVariables(built) {
159
170
  /** Every first-level expression problem in a built case, each stamped with its location. */
160
171
  export function checkCaseExpressions(built) {
161
172
  const roots = new Set(built.vars.map((v) => v.name));
162
- for (const name of platformVariables(built))
173
+ for (const name of platformVariables(built.stages.map((s) => s.label)))
163
174
  roots.add(name);
164
175
  // Task output bindings declare readable case variables too (`=vars.<var>`),
165
176
  // via a root `inputOutputs` companion — include them so a gate that reads a
@@ -186,7 +186,7 @@ export interface DecompileOptions {
186
186
  bestEffort?: boolean;
187
187
  }
188
188
  export interface CaseDecompileDiagnostic {
189
- code: 'UNSUPPORTED_TASK_KIND' | 'UNKNOWN_STAGE_REFERENCE' | 'UNKNOWN_TASK_REFERENCE' | 'UNKNOWN_EXIT_TARGET';
189
+ code: 'UNSUPPORTED_TASK_KIND' | 'UNKNOWN_STAGE_REFERENCE' | 'UNKNOWN_TASK_REFERENCE' | 'UNKNOWN_EXIT_TARGET' | 'UNDECLARED_VARIABLE_REFERENCE';
190
190
  message: string;
191
191
  location: string;
192
192
  }
@@ -25,6 +25,8 @@ import { bindingIdCandidates, offlineBindingLabel } from './ids.js';
25
25
  import { bindingRefId, isLiftFailure, isMintedWire, liftResourceFolder, liftResourceName, readBindingIds, resourceBindingOf, typedFolder, wireRows, } from './resource-wire.js';
26
26
  import { connectorPlaceholderKindOf } from './connector-placeholder.js';
27
27
  import { raiseTaskOutputReads, referableOutputIds } from './task-output-ref.js';
28
+ import { defaultActionOutputVar } from './action-output-var.js';
29
+ import { platformVariables, undeclaredVarReads } from './case-expr-check.js';
28
30
  const TASK_KIND_METHOD = {
29
31
  process: 'process',
30
32
  agent: 'agent',
@@ -2771,6 +2773,7 @@ export function decompileWithDiagnostics(plan, options = {}) {
2771
2773
  const diagnostics = [];
2772
2774
  refuseUnsupportedAuthoring(plan);
2773
2775
  plan = raiseTaskOutputRefs(plan);
2776
+ refuseUndeclaredGateReads(plan, options.bestEffort ? diagnostics : undefined);
2774
2777
  const preservation = collectPreservation(plan);
2775
2778
  const refs = buildRefs(plan, options.library, options.bestEffort ? diagnostics : undefined);
2776
2779
  const selectNextStage = selectNextStageByExit(plan, refs);
@@ -2861,6 +2864,90 @@ export function decompileWithDiagnostics(plan, options = {}) {
2861
2864
  const source = `import { ${imports.join(', ')} } from ${tsLiteral(options.importSpecifier ?? './case-sdk.js')};\n\n${diagnosticHeader}${out.toString()}\n`;
2862
2865
  return { source, diagnostics };
2863
2866
  }
2867
+ /**
2868
+ * Every name a `vars.<name>` gate of `plan` may read without `build()` calling
2869
+ * it undeclared: what the plan's rows declare (each `id` / `var` / `name`, a
2870
+ * literal `value` / `target`), an action form field's default variable, and the
2871
+ * variables the platform declares for every case. It is a superset of the roots
2872
+ * `build()` checks the decompiled source against, so decompile never refuses a
2873
+ * gate compile accepts.
2874
+ */
2875
+ function gateRoots(plan) {
2876
+ const roots = new Set(platformVariables((plan.nodes ?? []).filter(isStage).map((s) => String(s.data?.label ?? ''))));
2877
+ const walk = (value, inAction) => {
2878
+ if (Array.isArray(value)) {
2879
+ for (const item of value)
2880
+ walk(item, inAction);
2881
+ return;
2882
+ }
2883
+ if (!value || typeof value !== 'object')
2884
+ return;
2885
+ const row = value;
2886
+ const action = inAction || row.type === 'action';
2887
+ for (const [key, field] of Object.entries(row)) {
2888
+ if (typeof field === 'string') {
2889
+ if (key === 'id' || key === 'var' || key === 'name')
2890
+ roots.add(field);
2891
+ if ((key === 'value' || key === 'target') && !field.startsWith('='))
2892
+ roots.add(field);
2893
+ if ((key === 'value' || key === 'target') && /^=[\w$]+$/.test(field))
2894
+ roots.add(field.slice(1));
2895
+ if (key === 'name' && action)
2896
+ roots.add(defaultActionOutputVar(field));
2897
+ }
2898
+ else
2899
+ walk(field, action);
2900
+ }
2901
+ };
2902
+ walk({ ...plan, metadata: undefined }, false);
2903
+ walk(plan.metadata, false);
2904
+ return roots;
2905
+ }
2906
+ /**
2907
+ * Refuse a gate that reads a variable the plan does not declare. `build()`
2908
+ * rejects such a reference (`EXPR_UNDECLARED_REF`: `vars.` is a closed
2909
+ * namespace, and the runtime reads the name as `undefined`), so writing the
2910
+ * gate into the source would only hand the author source compile refuses.
2911
+ * Names the platform declares for every case (`stageHasRun_<stage>`, ...) are
2912
+ * not refused; see `platformVariables`.
2913
+ */
2914
+ function refuseUndeclaredGateReads(plan, diagnostics) {
2915
+ const roots = gateRoots(plan);
2916
+ const check = (expr, where) => {
2917
+ if (typeof expr !== 'string' || !expr)
2918
+ return;
2919
+ const missing = undeclaredVarReads(expr, roots);
2920
+ if (!missing.length)
2921
+ return;
2922
+ const reads = `reads ${missing.map((name) => `\`vars.${name}\``).join(', ')}, which no variable of the plan declares `
2923
+ + '(compile refuses it: EXPR_UNDECLARED_REF; at runtime it reads as undefined)';
2924
+ // Best effort keeps the gate and marks the source as needing this repair.
2925
+ if (diagnostics) {
2926
+ diagnostics.push({ code: 'UNDECLARED_VARIABLE_REFERENCE', location: where, message: `${reads}. Declare the variable, or fix the expression.` });
2927
+ return;
2928
+ }
2929
+ throw new Error(`${where} ${reads}. Declare the variable, or fix the expression to read one the case declares, then decompile again.`);
2930
+ };
2931
+ const rules = (conditions, where) => {
2932
+ for (const condition of conditions ?? [])
2933
+ for (const group of condition.rules ?? [])
2934
+ for (const r of group ?? [])
2935
+ check(r?.conditionExpression, where);
2936
+ };
2937
+ (plan.metadata?.slaRules ?? []).forEach((sla, i) => check(sla?.expression, `case SLA #${i + 1}`));
2938
+ rules(plan.metadata?.caseExitRules, 'case completion rule');
2939
+ for (const stage of (plan.nodes ?? []).filter(isStage)) {
2940
+ const at = `stage "${stage.data?.label ?? stage.id ?? '?'}"`;
2941
+ rules(stage.data?.entryConditions, `${at} entry rule`);
2942
+ rules(stage.data?.exitConditions, `${at} exit rule`);
2943
+ (stage.data?.slaRules ?? []).forEach((sla, i) => check(sla?.expression, `${at} SLA #${i + 1}`));
2944
+ for (const task of (stage.data?.tasks ?? []).flat()) {
2945
+ const tat = `task "${task?.displayName ?? task?.id ?? '?'}" in ${at}`;
2946
+ check(task?.skipCondition, `${tat} skip condition`);
2947
+ rules(task?.entryConditions, `${tat} entry rule`);
2948
+ }
2949
+ }
2950
+ }
2864
2951
  /**
2865
2952
  * The plan with each read of a task output that recompiling could not keep,
2866
2953
  * `vars.<output id>`, written as the task-output reference that names the same
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/maestro-builder-sdk",
3
- "version": "6.86.15",
3
+ "version": "6.86.16",
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",
@@ -103,5 +103,5 @@
103
103
  "@types/node": "^22.7.0",
104
104
  "esbuild": "^0.28.1"
105
105
  },
106
- "gitref": "1ea0d5d6d20c0aebdd6817378709f6b05d65432a"
106
+ "gitref": "3e9aa039200cbae561c1da363d34a4cbc4e6320c"
107
107
  }