@uipath/maestro-builder-sdk 6.94.6 → 6.95.1
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 +53 -53
- package/dist/api-members.md +230 -230
- package/dist/bpmn/bpmn-sdk.d.ts +20 -10
- package/dist/bpmn/decompile-cli.js +26 -55
- package/dist/bpmn/decompile-pipeline.d.ts +51 -0
- package/dist/bpmn/decompile-pipeline.js +78 -0
- package/dist/bpmn/decompile-stamp.d.ts +48 -0
- package/dist/bpmn/decompile-stamp.js +128 -0
- package/dist/bpmn/lift-verify.js +5 -2
- package/dist/bpmn/merge-cli.d.ts +5 -1
- package/dist/bpmn/merge-cli.js +266 -10
- package/dist/bpmn/merge-source.d.ts +86 -0
- package/dist/bpmn/merge-source.js +39 -0
- package/dist/bpmn-api.md +3 -3
- package/dist/case/preserve.d.ts +7 -7
- package/dist/cli/commands/bpmn.js +29 -4
- package/dist/flow-output-backing.d.ts +9 -0
- package/dist/flow-output-backing.js +9 -1
- package/dist/serialize.js +3 -3
- package/package.json +4 -3
package/dist/bpmn/bpmn-sdk.d.ts
CHANGED
|
@@ -963,7 +963,9 @@ export interface ScriptTaskOpts extends ActivityOpts {
|
|
|
963
963
|
* script task's return value: `ScriptActivities.DoInvokeScriptTaskAsync` in
|
|
964
964
|
* PO.BpmnEngine returns `{ "response": <whatever the script returned> }` when
|
|
965
965
|
* `IsVersionAtLeast(version, 2)`. So the script may return any JSON value and
|
|
966
|
-
* `=result.response` is that value
|
|
966
|
+
* `=result.response` is that value. The error row reads `=Error`, at the top level and
|
|
967
|
+
* not under `result`, as the platform's script-task template writes it
|
|
968
|
+
* (`<uipath:output name="Error" source="=Error" …/>`).
|
|
967
969
|
* `check` reports a row on a v2-or-later task that reads `result` any other way
|
|
968
970
|
* (`=result.severity`, `=result`) as `SCRIPT_RESULT_NOT_RESPONSE`, with the
|
|
969
971
|
* corrected expression (`=result.response.severity`).
|
|
@@ -1278,14 +1280,12 @@ export interface HttpOpts extends ActivityOpts {
|
|
|
1278
1280
|
connectorKey?: string;
|
|
1279
1281
|
/**
|
|
1280
1282
|
* EXTRA output rows: variable id → `=`-expression read against the node's own result,
|
|
1281
|
-
* e.g. `{
|
|
1283
|
+
* e.g. `{ orderId: '=response.body.id' }`.
|
|
1282
1284
|
*
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1285
|
-
*
|
|
1286
|
-
*
|
|
1287
|
-
* way every other output row works. The spec's own row is still emitted, so the artifact
|
|
1288
|
-
* stays what the platform expects.
|
|
1285
|
+
* The result is `response`, holding `{ code, headers, body }`: the node's own rows read
|
|
1286
|
+
* `=response.code`, `=response.headers` and `=response.body`, so a field of the body is
|
|
1287
|
+
* `=response.body.<field>`. A row may not write any variable the node already writes
|
|
1288
|
+
* (see {@link HttpOpts.outputVar}).
|
|
1289
1289
|
*/
|
|
1290
1290
|
outputs?: Record<string, string>;
|
|
1291
1291
|
/**
|
|
@@ -1357,7 +1357,12 @@ export interface OrchestratorOpts extends ActivityOpts {
|
|
|
1357
1357
|
folderKey?: string;
|
|
1358
1358
|
/**
|
|
1359
1359
|
* EXTRA output rows: variable id → `=`-expression read against the node's own result,
|
|
1360
|
-
* e.g. `{
|
|
1360
|
+
* e.g. `{ message: '=result.message' }` for a job whose output argument is `message`.
|
|
1361
|
+
* The job's output arguments sit under `result`, as a live-verified
|
|
1362
|
+
* `Orchestrator.ExecuteApiWorkflowAsync` maps them (`source="=result.message"`).
|
|
1363
|
+
* The local engine does not bind `result` yet (it binds the job's output under
|
|
1364
|
+
* `response`, and a local `*Async` start returns none), so on a local run this row
|
|
1365
|
+
* reads `undefined`; the platform reads it.
|
|
1361
1366
|
*
|
|
1362
1367
|
* Needed for the same reason `.humanTask()` has it: this family declares a TYPED output
|
|
1363
1368
|
* (`type="Orchestrator.RunJob"` and friends) with no `source`, which the designer resolves
|
|
@@ -1404,7 +1409,12 @@ export interface QueueItemOpts extends ActivityOpts {
|
|
|
1404
1409
|
wait?: boolean;
|
|
1405
1410
|
/**
|
|
1406
1411
|
* EXTRA output rows: variable id → `=`-expression read against the node's own result,
|
|
1407
|
-
* e.g. `{
|
|
1412
|
+
* e.g. `{ outputString: '=result.Output.OutputString' }` with `wait: true`. The processed
|
|
1413
|
+
* item sits under `result` and its output fields under `Output`, as a tenant-exported
|
|
1414
|
+
* `Orchestrator.CreateAndWaitForQueueItem` reads them (`source="=result"`, then
|
|
1415
|
+
* `vars.response.Output["OutputString"]`). The local engine does not bind `result`
|
|
1416
|
+
* yet and flattens `Output` into the item, so on a local run this row reads
|
|
1417
|
+
* `undefined`; the platform reads it.
|
|
1408
1418
|
*
|
|
1409
1419
|
* Needed for the same reason `.humanTask()` has it: this family declares a TYPED output
|
|
1410
1420
|
* (`type="Orchestrator.RunJob"` and friends) with no `source`, which the designer resolves
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
* resolves for a package consumer; the library default in `decompile.ts` stays
|
|
22
22
|
* repo-relative for in-tree callers, mirroring the Flow and Case arms.
|
|
23
23
|
*
|
|
24
|
+
* The first line of the written source is the stamp (decompile-stamp.ts):
|
|
25
|
+
* `// @decompiled-from <file> sha256:<hex> style=… connectors=…[ keep-flow-ids][ keep-unused-bindings]`.
|
|
26
|
+
* `bpmn merge X.bpmn.ts --original X.bpmn` reads it, refuses an original whose bytes
|
|
27
|
+
* changed since, and derives its baseline with the options it records.
|
|
28
|
+
*
|
|
24
29
|
* Diagram layout is not read or emitted — the SDK emits semantic-only XML. For a
|
|
25
30
|
* brownfield edit, `bpmn-merge` puts the original diagram back and draws only what the
|
|
26
31
|
* edit added (merge-placement.ts); `uip maestro bpmn format`, which lays the whole
|
|
@@ -37,9 +42,8 @@ import { readFileSync } from 'node:fs';
|
|
|
37
42
|
import { basename, resolve } from 'node:path';
|
|
38
43
|
import { defaultSourceOut, writeSource } from '../workdir.js';
|
|
39
44
|
import { flagValue, runWhenInvokedDirectly } from '../cli-run.js';
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import { verifyConnectorLifts } from './connector-lift-verify.js';
|
|
45
|
+
import { decompilePipeline } from './decompile-pipeline.js';
|
|
46
|
+
import { sourceDigest, stampSource } from './decompile-stamp.js';
|
|
43
47
|
import { openCliLibrary } from '../core/cli-library.js';
|
|
44
48
|
import { BPMN_IMPORT } from '../package-name.js';
|
|
45
49
|
import { fileURLToPath } from 'node:url';
|
|
@@ -88,63 +92,30 @@ export async function run(argv) {
|
|
|
88
92
|
console.error('decompile: missing <Name.bpmn>');
|
|
89
93
|
return 2;
|
|
90
94
|
}
|
|
91
|
-
const
|
|
95
|
+
const bytes = readFileSync(input);
|
|
96
|
+
const xml = bytes.toString('utf8');
|
|
92
97
|
const importSpecifier = flagValue(argv, '--import') ?? BPMN_IMPORT;
|
|
93
|
-
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
// was refused — one more decompile with those tasks pinned verbatim. The pinned set
|
|
97
|
-
// then rides into the nested-style passes below, so the flat and nested sources the
|
|
98
|
-
// nested verify compares make the same connector decisions.
|
|
98
|
+
// The connector lift (`--connectors lift`, the default when a library opens) and
|
|
99
|
+
// the nested lift, each verified before it is written: decompile-pipeline.ts, which
|
|
100
|
+
// `bpmn merge` also runs to derive its baseline from an original.
|
|
99
101
|
const library = connectors === 'lift' ? openCliLibrary(argv) : undefined;
|
|
100
102
|
const sdkEntry = fileURLToPath(new URL('./bpmn-sdk.js', import.meta.url));
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
importSpecifier,
|
|
105
|
-
keepUnusedBindings,
|
|
106
|
-
onPrune: (ids) => (pruned = ids),
|
|
107
|
-
...(library ? { library, connectors: 'lift' } : {}),
|
|
108
|
-
onConnectorLift: (s) => (connectorSummary = s),
|
|
109
|
-
};
|
|
110
|
-
let source = await decompile(xml, { ...base0, verbatimConnectors });
|
|
111
|
-
if (library && connectorSummary && connectorSummary.lifted.length > 0) {
|
|
112
|
-
const verdict = await verifyConnectorLifts(xml, connectorSummary, sdkEntry, library);
|
|
113
|
-
if (verdict.failed.size > 0) {
|
|
114
|
-
verbatimConnectors = new Set(verdict.failed.keys());
|
|
115
|
-
source = await decompile(xml, { ...base0, verbatimConnectors });
|
|
116
|
-
// The summary from the second pass says "did not verify"; carry the measured reason.
|
|
117
|
-
if (connectorSummary) {
|
|
118
|
-
connectorSummary.verbatim = connectorSummary.verbatim.map((v) => ({ id: v.id, reason: verdict.failed.get(v.id) ?? v.reason }));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
let lifted;
|
|
123
|
-
let fallback;
|
|
124
|
-
if (style === 'nested') {
|
|
125
|
-
// Two rungs: the top level in sequence mode, then without it. Built against THIS
|
|
126
|
-
// package's own entry, whatever specifier the written file carries — the check is
|
|
127
|
-
// about the graph, not about module resolution. The flow ids the lift renamed are
|
|
128
|
-
// the one sanctioned difference.
|
|
129
|
-
for (const sequenceMode of [true, false]) {
|
|
130
|
-
let summary;
|
|
131
|
-
const nested = await decompile(xml, {
|
|
132
|
-
...base0, verbatimConnectors, style: 'nested', relabelFlows: !keepFlowIds, sequenceMode, onLift: (s) => (summary = s),
|
|
133
|
-
});
|
|
134
|
-
const renamed = new Map((summary?.renamedFlows ?? []).map((r) => [r.from, r.to]));
|
|
135
|
-
const verdict = await sameGraph(source, nested, sdkEntry, renamed);
|
|
136
|
-
if (verdict.same) {
|
|
137
|
-
source = nested;
|
|
138
|
-
lifted = summary;
|
|
139
|
-
fallback = undefined;
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
fallback = verdict.reason ?? 'the graphs differ';
|
|
143
|
-
}
|
|
144
|
-
}
|
|
103
|
+
const { source, pruned, connectors: connectorSummary, lifted, fallback } = await decompilePipeline(xml, {
|
|
104
|
+
importSpecifier, style, keepFlowIds, keepUnusedBindings, sdkEntry, ...(library ? { library } : {}),
|
|
105
|
+
});
|
|
145
106
|
const base = basename(input).replace(/\.bpmn$/, '');
|
|
146
107
|
const out = flagValue(argv, '-o') ?? defaultSourceOut(`${base}.bpmn.ts`);
|
|
147
|
-
|
|
108
|
+
// The stamp says which original this came from, and how, so `bpmn merge X.bpmn.ts
|
|
109
|
+
// --original X.bpmn` can refuse an original that changed since and derive its
|
|
110
|
+
// baseline with the same options (decompile-stamp.ts).
|
|
111
|
+
writeSource(out, stampSource(source, {
|
|
112
|
+
file: basename(input),
|
|
113
|
+
sha256: sourceDigest(source),
|
|
114
|
+
style,
|
|
115
|
+
connectors: library ? 'lift' : 'verbatim',
|
|
116
|
+
keepFlowIds,
|
|
117
|
+
keepUnusedBindings,
|
|
118
|
+
}));
|
|
148
119
|
console.log(`decompile: wrote ${out}`);
|
|
149
120
|
if (pruned.length) {
|
|
150
121
|
// Never silent: these are declarations the source had and the output does not.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* decompile-pipeline — what `bpmn decompile` does to a `.bpmn`, as one call.
|
|
3
|
+
*
|
|
4
|
+
* The plain decompile is `decompile()`. The CLI runs more than that: it lifts the
|
|
5
|
+
* connector tasks the library can name and keeps only the lifts that verify, and with
|
|
6
|
+
* `style: 'nested'` it lifts the regions the builder's nesting constructs lower to,
|
|
7
|
+
* writing the nested source only when it builds the same graph as the flat one
|
|
8
|
+
* (lift-verify.ts). `bpmn merge` runs the same steps to derive its baseline from the
|
|
9
|
+
* original when it is given the edited SOURCE (merge-source.ts), so the two must not
|
|
10
|
+
* drift: both call this.
|
|
11
|
+
*
|
|
12
|
+
* Nothing here prints. The caller reports what came back.
|
|
13
|
+
*/
|
|
14
|
+
import type { Library } from '../core/library.js';
|
|
15
|
+
import { type ConnectorLiftSummary, type LiftSummary } from './decompile.js';
|
|
16
|
+
/** How to decompile: the options `bpmn decompile` takes, resolved. */
|
|
17
|
+
export interface DecompilePipelineOptions {
|
|
18
|
+
/** The module specifier of the emitted `import { bpmn }` line. */
|
|
19
|
+
importSpecifier: string;
|
|
20
|
+
/** `explicit` writes one call per element and flow; `nested` lifts what it can prove. */
|
|
21
|
+
style: 'explicit' | 'nested';
|
|
22
|
+
/** Confine the nested lift to regions whose flow ids already match, instead of pinning them. */
|
|
23
|
+
keepFlowIds?: boolean;
|
|
24
|
+
/** Echo bindings nothing references instead of dropping them. */
|
|
25
|
+
keepUnusedBindings?: boolean;
|
|
26
|
+
/** The connector library; given, connector tasks it can name are lifted to `.connector()`. */
|
|
27
|
+
library?: Library;
|
|
28
|
+
/** Absolute path of the `bpmn-sdk.js` the verifications build against. */
|
|
29
|
+
sdkEntry: string;
|
|
30
|
+
}
|
|
31
|
+
/** What the pipeline produced, and what it did to get there. */
|
|
32
|
+
export interface DecompilePipelineResult {
|
|
33
|
+
/** The `.bpmn.ts` source. */
|
|
34
|
+
source: string;
|
|
35
|
+
/** Binding ids dropped because nothing references them. */
|
|
36
|
+
pruned: string[];
|
|
37
|
+
/** The connector lift, when a library was in play. */
|
|
38
|
+
connectors?: ConnectorLiftSummary;
|
|
39
|
+
/** The nested lift, when `style: 'nested'` verified. */
|
|
40
|
+
lifted?: LiftSummary;
|
|
41
|
+
/** Why `style: 'nested'` fell back to the flat source. */
|
|
42
|
+
fallback?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Decompile `xml` the way `bpmn decompile` does.
|
|
46
|
+
*
|
|
47
|
+
* @param xml - The `.bpmn` text.
|
|
48
|
+
* @param opts - The resolved decompile options.
|
|
49
|
+
* @returns The source, and what the lifts did.
|
|
50
|
+
*/
|
|
51
|
+
export declare function decompilePipeline(xml: string, opts: DecompilePipelineOptions): Promise<DecompilePipelineResult>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { decompile } from './decompile.js';
|
|
2
|
+
import { sameGraph } from './lift-verify.js';
|
|
3
|
+
import { verifyConnectorLifts } from './connector-lift-verify.js';
|
|
4
|
+
/**
|
|
5
|
+
* Decompile `xml` the way `bpmn decompile` does.
|
|
6
|
+
*
|
|
7
|
+
* @param xml - The `.bpmn` text.
|
|
8
|
+
* @param opts - The resolved decompile options.
|
|
9
|
+
* @returns The source, and what the lifts did.
|
|
10
|
+
*/
|
|
11
|
+
export async function decompilePipeline(xml, opts) {
|
|
12
|
+
const { library, sdkEntry } = opts;
|
|
13
|
+
let pruned = [];
|
|
14
|
+
// The connector lift: name each connector task through the library, then keep only
|
|
15
|
+
// the lifts that verify. One decompile to plan, one verify, and — only when a lift
|
|
16
|
+
// was refused — one more decompile with those tasks pinned verbatim. The pinned set
|
|
17
|
+
// then rides into the nested-style passes below, so the flat and nested sources the
|
|
18
|
+
// nested verify compares make the same connector decisions.
|
|
19
|
+
let connectors;
|
|
20
|
+
let verbatimConnectors = new Set();
|
|
21
|
+
const base0 = {
|
|
22
|
+
importSpecifier: opts.importSpecifier,
|
|
23
|
+
keepUnusedBindings: opts.keepUnusedBindings === true,
|
|
24
|
+
onPrune: (ids) => (pruned = ids),
|
|
25
|
+
...(library ? { library, connectors: 'lift' } : {}),
|
|
26
|
+
onConnectorLift: (s) => (connectors = s),
|
|
27
|
+
};
|
|
28
|
+
let source = await decompile(xml, { ...base0, verbatimConnectors });
|
|
29
|
+
// `connectors` is assigned by the callback above; read it through a getter so the
|
|
30
|
+
// narrowing TypeScript did at the declaration does not survive the call.
|
|
31
|
+
const summary0 = () => connectors;
|
|
32
|
+
const planned = summary0();
|
|
33
|
+
if (library && planned && planned.lifted.length > 0) {
|
|
34
|
+
const verdict = await verifyConnectorLifts(xml, planned, sdkEntry, library);
|
|
35
|
+
if (verdict.failed.size > 0) {
|
|
36
|
+
verbatimConnectors = new Set(verdict.failed.keys());
|
|
37
|
+
source = await decompile(xml, { ...base0, verbatimConnectors });
|
|
38
|
+
// The summary from the second pass says "did not verify"; carry the measured reason.
|
|
39
|
+
const second = summary0();
|
|
40
|
+
if (second) {
|
|
41
|
+
second.verbatim = second.verbatim.map((v) => ({ id: v.id, reason: verdict.failed.get(v.id) ?? v.reason }));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
let lifted;
|
|
46
|
+
let fallback;
|
|
47
|
+
if (opts.style === 'nested') {
|
|
48
|
+
// Two rungs: the top level in sequence mode, then without it. Built against THIS
|
|
49
|
+
// package's own entry, whatever specifier the written file carries — the check is
|
|
50
|
+
// about the graph, not about module resolution. The flow ids the lift renamed are
|
|
51
|
+
// the one sanctioned difference.
|
|
52
|
+
for (const sequenceMode of [true, false]) {
|
|
53
|
+
let summary;
|
|
54
|
+
const nested = await decompile(xml, {
|
|
55
|
+
...base0, verbatimConnectors, style: 'nested', relabelFlows: opts.keepFlowIds !== true, sequenceMode, onLift: (s) => (summary = s),
|
|
56
|
+
});
|
|
57
|
+
const liftSummary = () => summary;
|
|
58
|
+
const renamed = new Map((liftSummary()?.renamedFlows ?? []).map((r) => [r.from, r.to]));
|
|
59
|
+
const verdict = await sameGraph(source, nested, sdkEntry, renamed);
|
|
60
|
+
if (verdict.same) {
|
|
61
|
+
source = nested;
|
|
62
|
+
lifted = liftSummary();
|
|
63
|
+
fallback = undefined;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
fallback = verdict.reason ?? 'the graphs differ';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const result = { source, pruned };
|
|
70
|
+
const finalSummary = summary0();
|
|
71
|
+
if (finalSummary)
|
|
72
|
+
result.connectors = finalSummary;
|
|
73
|
+
if (lifted)
|
|
74
|
+
result.lifted = lifted;
|
|
75
|
+
if (fallback)
|
|
76
|
+
result.fallback = fallback;
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** What `bpmn decompile` records about the decompile, and `bpmn merge` reads back. */
|
|
2
|
+
export interface DecompileStamp {
|
|
3
|
+
/** The original's base name. */
|
|
4
|
+
file: string;
|
|
5
|
+
/** {@link sourceDigest} of the source decompile made of the original, lowercase hex. */
|
|
6
|
+
sha256: string;
|
|
7
|
+
/** The style decompile was asked for. */
|
|
8
|
+
style: 'explicit' | 'nested';
|
|
9
|
+
/** `lift` when a library was open and the connector lift ran; else `verbatim`. */
|
|
10
|
+
connectors: 'lift' | 'verbatim';
|
|
11
|
+
/** Decompile was given `--keep-flow-ids`. */
|
|
12
|
+
keepFlowIds: boolean;
|
|
13
|
+
/** Decompile was given `--keep-unused-bindings`. */
|
|
14
|
+
keepUnusedBindings: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** The marker that starts the stamp line. */
|
|
17
|
+
export declare const STAMP_MARKER = "// @decompiled-from ";
|
|
18
|
+
/**
|
|
19
|
+
* The digest the stamp records: SHA-256, lowercase hex, of a source as decompile makes
|
|
20
|
+
* it (no stamp line), with the SDK import specifier replaced by a fixed one, so
|
|
21
|
+
* `--import` and the absolute entry merge decompiles against give the same digest.
|
|
22
|
+
*
|
|
23
|
+
* @param source - The decompiled source, before {@link stampSource}.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sourceDigest(source: string): string;
|
|
26
|
+
/** The stamp line, without a line terminator. */
|
|
27
|
+
export declare function formatStamp(stamp: DecompileStamp): string;
|
|
28
|
+
/** `source` with the stamp line in front of it. */
|
|
29
|
+
export declare function stampSource(source: string, stamp: DecompileStamp): string;
|
|
30
|
+
/**
|
|
31
|
+
* Read the stamp from a `.bpmn.ts` source: the first line that starts with
|
|
32
|
+
* {@link STAMP_MARKER}.
|
|
33
|
+
*
|
|
34
|
+
* @returns The stamp; `undefined` when the source has no stamp line; or `{ error }`
|
|
35
|
+
* naming what is wrong with a stamp line that does not parse.
|
|
36
|
+
*/
|
|
37
|
+
export declare function readStamp(source: string): DecompileStamp | {
|
|
38
|
+
error: string;
|
|
39
|
+
} | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* `source` with its stamp line pointed at a new original: the `file` and `sha256`
|
|
42
|
+
* replaced, the options kept. `bpmn merge` calls this after it writes over the original,
|
|
43
|
+
* so the same source merges again in the next round: the merged original is what the
|
|
44
|
+
* source, as it now stands, would decompile from.
|
|
45
|
+
*
|
|
46
|
+
* @returns The restamped source, or `undefined` when `source` has no readable stamp.
|
|
47
|
+
*/
|
|
48
|
+
export declare function restampSource(source: string, file: string, sha256: string): string | undefined;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* decompile-stamp — the line `bpmn decompile` writes at the top of a `.bpmn.ts` to say
|
|
3
|
+
* which original it came from and how, and the reader `bpmn merge` uses to check it.
|
|
4
|
+
*
|
|
5
|
+
* The format is one `//` comment line:
|
|
6
|
+
*
|
|
7
|
+
* // @decompiled-from <file name> sha256:<64 hex> style=<explicit|nested> connectors=<lift|verbatim>[ keep-flow-ids][ keep-unused-bindings]
|
|
8
|
+
*
|
|
9
|
+
* - `<file name>` is the original's base name, for the messages only; a renamed or
|
|
10
|
+
* copied original with the same bytes still matches.
|
|
11
|
+
* - `sha256:` is the SHA-256 of the SOURCE decompile wrote for the original, without
|
|
12
|
+
* the stamp line and with its SDK import specifier normalized ({@link sourceDigest}),
|
|
13
|
+
* not of the original's bytes. Merge decompiles `--original` again with the recorded
|
|
14
|
+
* options and compares: what it needs is that the baseline it derives is the source
|
|
15
|
+
* the author started from, and this checks exactly that. So a change decompile does
|
|
16
|
+
* not read — line endings, the `bpmndi` layout `bpmn format` rewrites, attribute order
|
|
17
|
+
* — merges, since merge keeps it from the original; and a change in what decompile
|
|
18
|
+
* makes of the same bytes, a connector library that lifts differently, is refused.
|
|
19
|
+
* - `style` is the style decompile was asked for. The nested lift is deterministic and
|
|
20
|
+
* verified, so asking again gives the same source, fallback to flat included.
|
|
21
|
+
* - `connectors` is what the connector lift DID: `lift` when a library was open and the
|
|
22
|
+
* lift ran, `verbatim` when it was turned off or no library opened.
|
|
23
|
+
* - `keep-flow-ids` and `keep-unused-bindings` are present when decompile was given them.
|
|
24
|
+
*
|
|
25
|
+
* `--import` is not recorded: it changes the module specifier the source imports, not
|
|
26
|
+
* what the source builds, and the digest reads the import line with the specifier
|
|
27
|
+
* normalized.
|
|
28
|
+
*
|
|
29
|
+
* Why (UiPath/builder-sdk#1889): the source form of merge (`merge X.bpmn.ts --original
|
|
30
|
+
* X.bpmn`) derives its baseline by decompiling `--original` again. That is the source
|
|
31
|
+
* the author started from only while `--original` is the file the source was decompiled
|
|
32
|
+
* from, with the same options. If `X.bpmn` changed in between, its changes are in the
|
|
33
|
+
* derived baseline and not in the source, so the merge reads them as the author's
|
|
34
|
+
* deletions and reverts them. The stamp lets merge check the first and reproduce the
|
|
35
|
+
* second, and merge refuses a source without one.
|
|
36
|
+
*
|
|
37
|
+
* Nothing here prints; the CLIs do.
|
|
38
|
+
*/
|
|
39
|
+
import { createHash } from 'node:crypto';
|
|
40
|
+
import { commentText } from '../core/comment-text.js';
|
|
41
|
+
/** The marker that starts the stamp line. */
|
|
42
|
+
export const STAMP_MARKER = '// @decompiled-from ';
|
|
43
|
+
/** The SDK import line of a decompiled source; `buildSource` (lift-verify.ts) rewrites the same line. */
|
|
44
|
+
const IMPORT_RE = /^(import\s*\{[^}]*\}\s*from\s*)["'][^"']+["'];/m;
|
|
45
|
+
/**
|
|
46
|
+
* The digest the stamp records: SHA-256, lowercase hex, of a source as decompile makes
|
|
47
|
+
* it (no stamp line), with the SDK import specifier replaced by a fixed one, so
|
|
48
|
+
* `--import` and the absolute entry merge decompiles against give the same digest.
|
|
49
|
+
*
|
|
50
|
+
* @param source - The decompiled source, before {@link stampSource}.
|
|
51
|
+
*/
|
|
52
|
+
export function sourceDigest(source) {
|
|
53
|
+
return createHash('sha256').update(source.replace(IMPORT_RE, '$1"@";')).digest('hex');
|
|
54
|
+
}
|
|
55
|
+
/** The stamp line, without a line terminator. */
|
|
56
|
+
export function formatStamp(stamp) {
|
|
57
|
+
return (`${STAMP_MARKER}${commentText(stamp.file)} sha256:${stamp.sha256} style=${stamp.style} connectors=${stamp.connectors}` +
|
|
58
|
+
(stamp.keepFlowIds ? ' keep-flow-ids' : '') +
|
|
59
|
+
(stamp.keepUnusedBindings ? ' keep-unused-bindings' : ''));
|
|
60
|
+
}
|
|
61
|
+
/** `source` with the stamp line in front of it. */
|
|
62
|
+
export function stampSource(source, stamp) {
|
|
63
|
+
return `${formatStamp(stamp)}\n${source}`;
|
|
64
|
+
}
|
|
65
|
+
const STAMP_RE = /^\/\/ @decompiled-from (.*) sha256:([0-9a-f]{64})((?: \S+)*)\s*$/;
|
|
66
|
+
/**
|
|
67
|
+
* Read the stamp from a `.bpmn.ts` source: the first line that starts with
|
|
68
|
+
* {@link STAMP_MARKER}.
|
|
69
|
+
*
|
|
70
|
+
* @returns The stamp; `undefined` when the source has no stamp line; or `{ error }`
|
|
71
|
+
* naming what is wrong with a stamp line that does not parse.
|
|
72
|
+
*/
|
|
73
|
+
export function readStamp(source) {
|
|
74
|
+
const line = source.split(/\r?\n/).find((l) => l.startsWith(STAMP_MARKER));
|
|
75
|
+
if (line === undefined)
|
|
76
|
+
return undefined;
|
|
77
|
+
const match = STAMP_RE.exec(line);
|
|
78
|
+
if (!match)
|
|
79
|
+
return { error: `the line does not read as \`${STAMP_MARKER}<file> sha256:<64 hex> <options>\`: ${line}` };
|
|
80
|
+
const stamp = {
|
|
81
|
+
file: match[1] ?? '',
|
|
82
|
+
sha256: match[2] ?? '',
|
|
83
|
+
style: 'explicit',
|
|
84
|
+
connectors: 'verbatim',
|
|
85
|
+
keepFlowIds: false,
|
|
86
|
+
keepUnusedBindings: false,
|
|
87
|
+
};
|
|
88
|
+
const seen = new Set();
|
|
89
|
+
for (const token of (match[3] ?? '').trim().split(' ').filter(Boolean)) {
|
|
90
|
+
const [key, value] = token.split('=', 2);
|
|
91
|
+
if (seen.has(key))
|
|
92
|
+
return { error: `\`${key}\` appears twice: ${line}` };
|
|
93
|
+
seen.add(key);
|
|
94
|
+
if (key === 'style' && (value === 'explicit' || value === 'nested'))
|
|
95
|
+
stamp.style = value;
|
|
96
|
+
else if (key === 'connectors' && (value === 'lift' || value === 'verbatim'))
|
|
97
|
+
stamp.connectors = value;
|
|
98
|
+
else if (key === 'keep-flow-ids' && value === undefined)
|
|
99
|
+
stamp.keepFlowIds = true;
|
|
100
|
+
else if (key === 'keep-unused-bindings' && value === undefined)
|
|
101
|
+
stamp.keepUnusedBindings = true;
|
|
102
|
+
else
|
|
103
|
+
return { error: `unknown option \`${token}\`: ${line}` };
|
|
104
|
+
}
|
|
105
|
+
for (const required of ['style', 'connectors']) {
|
|
106
|
+
if (!seen.has(required))
|
|
107
|
+
return { error: `\`${required}=\` is missing: ${line}` };
|
|
108
|
+
}
|
|
109
|
+
return stamp;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* `source` with its stamp line pointed at a new original: the `file` and `sha256`
|
|
113
|
+
* replaced, the options kept. `bpmn merge` calls this after it writes over the original,
|
|
114
|
+
* so the same source merges again in the next round: the merged original is what the
|
|
115
|
+
* source, as it now stands, would decompile from.
|
|
116
|
+
*
|
|
117
|
+
* @returns The restamped source, or `undefined` when `source` has no readable stamp.
|
|
118
|
+
*/
|
|
119
|
+
export function restampSource(source, file, sha256) {
|
|
120
|
+
const stamp = readStamp(source);
|
|
121
|
+
if (stamp === undefined || 'error' in stamp)
|
|
122
|
+
return undefined;
|
|
123
|
+
const lines = source.split('\n');
|
|
124
|
+
const at = lines.findIndex((l) => l.startsWith(STAMP_MARKER));
|
|
125
|
+
const cr = lines[at]?.endsWith('\r') ? '\r' : '';
|
|
126
|
+
lines[at] = `${formatStamp({ ...stamp, file, sha256 })}${cr}`;
|
|
127
|
+
return lines.join('\n');
|
|
128
|
+
}
|
package/dist/bpmn/lift-verify.js
CHANGED
|
@@ -77,12 +77,15 @@ export async function buildSource(source, sdkEntry) {
|
|
|
77
77
|
// two per verify and up to four per `decompile --style nested`.
|
|
78
78
|
//
|
|
79
79
|
// Safe to delete once the import has resolved: the module is fully evaluated, the SDK
|
|
80
|
-
// specifier was rewritten to an absolute
|
|
80
|
+
// specifier was rewritten to an absolute file URL OUTSIDE this directory, and the file
|
|
81
81
|
// name is `mkdtemp` plus a random suffix, so nothing re-resolves it.
|
|
82
82
|
try {
|
|
83
83
|
writeFileSync(join(dir, 'package.json'), '{"type":"module"}\n');
|
|
84
84
|
const file = join(dir, `Lift-${Math.random().toString(36).slice(2)}.bpmn.ts`);
|
|
85
|
-
|
|
85
|
+
// A file URL, not the raw path: an ESM specifier is a URL, so a `#` in the install
|
|
86
|
+
// path would start a fragment and a Windows drive prefix would read as a scheme.
|
|
87
|
+
const specifier = pathToFileURL(sdkEntry).href;
|
|
88
|
+
const rewritten = source.replace(/^(import\s*\{[^}]*\}\s*from\s*)["'][^"']+["'];/m, `$1${JSON.stringify(specifier)};`);
|
|
86
89
|
writeFileSync(file, rewritten);
|
|
87
90
|
const mod = await import(pathToFileURL(file).href);
|
|
88
91
|
if (!mod.default || !Array.isArray(mod.default.nodes))
|
package/dist/bpmn/merge-cli.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { type CliExitCode } from '../cli-run.js';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* `run(argv)` is the tool contract the family-first `flow-sdk` CLI loads: the
|
|
5
|
+
* original first, then the edited document or source.
|
|
6
|
+
*/
|
|
7
|
+
export declare function run(argv: string[]): Promise<CliExitCode>;
|