@uipath/maestro-builder-sdk 6.96.1 → 6.96.3

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,120 @@
1
+ /**
2
+ * A connector operation a decompiled Flow step CARRIES: the file's own
3
+ * description of an operation the connector library does not have at all.
4
+ *
5
+ * The published library is a snapshot. A tenant keeps adding connectors and
6
+ * operations after it is taken (Data Fabric `create-entity-record`, Test
7
+ * Manager, a tenant's custom connector), and Studio Web saves a step against the
8
+ * LIVE connector. With the library as the only authority, compile refused such a
9
+ * step as CONNECTOR_NOT_IN_LIBRARY, so the source decompile wrote for an
10
+ * untouched product flow did not compile.
11
+ *
12
+ * The `.flow` file describes the operation in two places, and between them they
13
+ * hold everything compile reads from a library entry:
14
+ *
15
+ * - its `definitions[]` entry for the node type: the form, handles, model,
16
+ * bindings and activity type id. Decompile carries it in `.definitions([...])`,
17
+ * exactly as it carries a pinned core node's definition (#1128).
18
+ * - the node's own `inputs.detail`: the HTTP method and endpoint it calls, the
19
+ * operation verb its configuration records, and the slot (body, query, path)
20
+ * of every input it sets. Decompile carries these as the step's `carried`
21
+ * option: `{ method, endpoint, operation, fields }`.
22
+ *
23
+ * This is the same idea as Case's carried connector fields
24
+ * (`core/carried-connector-fields.ts`, #1362): the file's own definition is the
25
+ * third source, after the SDK and the library. It is a FALLBACK only:
26
+ *
27
+ * - compile reads it only when the library has no entry for the node type. An
28
+ * operation the library knows is compiled from the library, whatever is
29
+ * carried, so a carried copy can never relax what the library declares.
30
+ * - it names only the inputs the file sets. An input it does not name is still
31
+ * `unknown input` (CONNECTOR_INPUT). A carried field is optional, except a
32
+ * path field the endpoint template names (`{entityName}`): the file shows
33
+ * that a field exists, not that it is required, but an unfilled placeholder
34
+ * is a node `flow validate` refuses.
35
+ * - the method must be one `flow validate` accepts, every `{name}` in the
36
+ * endpoint needs a carried path field, and the carried definition must record
37
+ * the step's connector key and method (`carriedDefinitionMismatch`).
38
+ * - without the carried definition in `.definitions([...])`, the step is still
39
+ * CONNECTOR_NOT_IN_LIBRARY.
40
+ *
41
+ * For instance a Data Fabric "Create Entity Record" step, saved against a
42
+ * connector newer than the library, decompiles to
43
+ *
44
+ * ```ts
45
+ * connector("uipath-uipath-dataservice", "create-entity-record", { Name: "Ada", entityName: "Contact" }, {
46
+ * connection: "…", folder: "…",
47
+ * carried: { method: "POST", endpoint: "/v2/{entityName}/CreateEntityRecord", operation: "create",
48
+ * fields: [{ name: "Name", location: "body" }, { name: "entityName", location: "path" }] },
49
+ * })
50
+ * ```
51
+ *
52
+ * plus `.definitions([createEntityRecordV1_0_0Definition])`, and compiles back.
53
+ */
54
+ import { type CarriedConnectorField } from './carried-connector-fields.js';
55
+ import type { ResolvedConnector } from './library.js';
56
+ /** The file's description of a connector operation the library lacks; see the module comment. */
57
+ export interface CarriedConnectorOperation {
58
+ /** The HTTP method the node calls, as the file saved it (`detail.method`), e.g. `POST`. */
59
+ method: string;
60
+ /** The endpoint the node calls (`detail.endpoint`), e.g. `/v2/{entityName}/CreateEntityRecord`. */
61
+ endpoint: string;
62
+ /** The operation verb the node's configuration records (`essentialConfiguration.operation`), e.g. `create` or `list`. */
63
+ operation?: string;
64
+ /** Every input the node sets, with the slot it rides in. Each is optional to compile; any other input is refused. */
65
+ fields?: readonly CarriedConnectorField[];
66
+ }
67
+ /**
68
+ * The `{name}` placeholders in an endpoint template, in order. For instance
69
+ * `/v2/{ProjectId}/testsets/{id}` gives `['ProjectId', 'id']`.
70
+ */
71
+ export declare function endpointPlaceholders(endpoint: string): string[];
72
+ /**
73
+ * Why `carried` cannot be a step's carried operation, or `undefined` when it can.
74
+ *
75
+ * For instance `{ endpoint: '/send' }` is refused for naming no `method`.
76
+ */
77
+ export declare function carriedOperationRefusal(carried: unknown, where: string): string | undefined;
78
+ /**
79
+ * Why `definition` cannot be the definition of carried operation `carried` on
80
+ * connector `key`, or `undefined` when it can: the connector key and HTTP
81
+ * method the definition itself records must agree with the step's. A
82
+ * definition borrowed from another connector, or from an operation with
83
+ * another verb, is refused. A definition that records neither is not checked
84
+ * on that point.
85
+ *
86
+ * For instance a Slack POST operation's definition under
87
+ * `carried: { method: 'DELETE', … }` is refused.
88
+ */
89
+ export declare function carriedDefinitionMismatch(definition: Record<string, unknown>, key: string, carried: CarriedConnectorOperation, where: string): string | undefined;
90
+ /**
91
+ * The operation `carried` and the carried `definition` describe, resolved as
92
+ * `Library.resolve` resolves a library entry. `carried` must have passed
93
+ * {@link carriedOperationRefusal}.
94
+ *
95
+ * The entry is built from the two halves: the transport (method, endpoint, verb)
96
+ * from `carried`, the object, activity kind and connector name from the
97
+ * definition. The fields are the carried ones, optional except a path field
98
+ * the endpoint template names.
99
+ *
100
+ * @param nodeType - The step's node type, `uipath.connector.<key>.<action>`.
101
+ * @param key - The connector key.
102
+ * @param version - The step's pinned version, which the definition carries.
103
+ * @param definition - The carried `definitions[]` entry for `nodeType@version`.
104
+ * @param carried - The step's carried operation.
105
+ */
106
+ export declare function carriedConnector(nodeType: string, key: string, version: string, definition: Record<string, unknown>, carried: CarriedConnectorOperation): ResolvedConnector;
107
+ /**
108
+ * The operation a saved connector node describes, for decompile to carry: its
109
+ * method, endpoint, the verb its configuration records, and each input it sets
110
+ * with its slot. `undefined` when the node does not describe one compile could
111
+ * rebuild: no method `flow validate` accepts or no endpoint, a multipart part
112
+ * (its part list is the library's to declare), one name in two slots, or an
113
+ * endpoint placeholder no path parameter fills.
114
+ *
115
+ * For instance a node with `detail: { method: 'POST', endpoint: '/send', bodyParameters: { text: 'hi' } }`
116
+ * gives `{ method: 'POST', endpoint: '/send', fields: [{ name: 'text', location: 'body' }] }`.
117
+ *
118
+ * @param detail - The node's `inputs.detail`.
119
+ */
120
+ export declare function carriedOperationOf(detail: Record<string, unknown>): CarriedConnectorOperation | undefined;
@@ -0,0 +1,297 @@
1
+ /**
2
+ * A connector operation a decompiled Flow step CARRIES: the file's own
3
+ * description of an operation the connector library does not have at all.
4
+ *
5
+ * The published library is a snapshot. A tenant keeps adding connectors and
6
+ * operations after it is taken (Data Fabric `create-entity-record`, Test
7
+ * Manager, a tenant's custom connector), and Studio Web saves a step against the
8
+ * LIVE connector. With the library as the only authority, compile refused such a
9
+ * step as CONNECTOR_NOT_IN_LIBRARY, so the source decompile wrote for an
10
+ * untouched product flow did not compile.
11
+ *
12
+ * The `.flow` file describes the operation in two places, and between them they
13
+ * hold everything compile reads from a library entry:
14
+ *
15
+ * - its `definitions[]` entry for the node type: the form, handles, model,
16
+ * bindings and activity type id. Decompile carries it in `.definitions([...])`,
17
+ * exactly as it carries a pinned core node's definition (#1128).
18
+ * - the node's own `inputs.detail`: the HTTP method and endpoint it calls, the
19
+ * operation verb its configuration records, and the slot (body, query, path)
20
+ * of every input it sets. Decompile carries these as the step's `carried`
21
+ * option: `{ method, endpoint, operation, fields }`.
22
+ *
23
+ * This is the same idea as Case's carried connector fields
24
+ * (`core/carried-connector-fields.ts`, #1362): the file's own definition is the
25
+ * third source, after the SDK and the library. It is a FALLBACK only:
26
+ *
27
+ * - compile reads it only when the library has no entry for the node type. An
28
+ * operation the library knows is compiled from the library, whatever is
29
+ * carried, so a carried copy can never relax what the library declares.
30
+ * - it names only the inputs the file sets. An input it does not name is still
31
+ * `unknown input` (CONNECTOR_INPUT). A carried field is optional, except a
32
+ * path field the endpoint template names (`{entityName}`): the file shows
33
+ * that a field exists, not that it is required, but an unfilled placeholder
34
+ * is a node `flow validate` refuses.
35
+ * - the method must be one `flow validate` accepts, every `{name}` in the
36
+ * endpoint needs a carried path field, and the carried definition must record
37
+ * the step's connector key and method (`carriedDefinitionMismatch`).
38
+ * - without the carried definition in `.definitions([...])`, the step is still
39
+ * CONNECTOR_NOT_IN_LIBRARY.
40
+ *
41
+ * For instance a Data Fabric "Create Entity Record" step, saved against a
42
+ * connector newer than the library, decompiles to
43
+ *
44
+ * ```ts
45
+ * connector("uipath-uipath-dataservice", "create-entity-record", { Name: "Ada", entityName: "Contact" }, {
46
+ * connection: "…", folder: "…",
47
+ * carried: { method: "POST", endpoint: "/v2/{entityName}/CreateEntityRecord", operation: "create",
48
+ * fields: [{ name: "Name", location: "body" }, { name: "entityName", location: "path" }] },
49
+ * })
50
+ * ```
51
+ *
52
+ * plus `.definitions([createEntityRecordV1_0_0Definition])`, and compiles back.
53
+ */
54
+ import { carriedConnectorFieldsRefusal } from './carried-connector-fields.js';
55
+ import { ownEntry } from './own-entry.js';
56
+ import { transportHttpMethod } from './connector-inputs.js';
57
+ const KEYS = new Set(['method', 'endpoint', 'operation', 'fields']);
58
+ /** The HTTP methods `flow validate` accepts on a connector node, upper-cased. */
59
+ const METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']);
60
+ /** Whether `method` is one of {@link METHODS}, in any case. */
61
+ function isHttpMethod(method) {
62
+ return typeof method === 'string' && METHODS.has(method.toUpperCase());
63
+ }
64
+ /**
65
+ * The `{name}` placeholders in an endpoint template, in order. For instance
66
+ * `/v2/{ProjectId}/testsets/{id}` gives `['ProjectId', 'id']`.
67
+ */
68
+ export function endpointPlaceholders(endpoint) {
69
+ return [...endpoint.matchAll(/\{([^{}]+)\}/g)].map((m) => m[1]);
70
+ }
71
+ /**
72
+ * Why `carried` cannot be a step's carried operation, or `undefined` when it can.
73
+ *
74
+ * For instance `{ endpoint: '/send' }` is refused for naming no `method`.
75
+ */
76
+ export function carriedOperationRefusal(carried, where) {
77
+ if (carried === undefined)
78
+ return undefined;
79
+ if (!carried || typeof carried !== 'object' || Array.isArray(carried))
80
+ return `${where}: carried must be an object { method, endpoint, operation?, fields? }.`;
81
+ const c = carried;
82
+ const extra = Object.keys(c).find((key) => !KEYS.has(key));
83
+ if (extra !== undefined)
84
+ return `${where}: carried has unsupported key "${extra}".`;
85
+ if (!isHttpMethod(c.method))
86
+ return `${where}: carried.method must be the HTTP method the file's node calls: GET, POST, PUT, PATCH or DELETE.`;
87
+ if (typeof c.endpoint !== 'string' || !c.endpoint.startsWith('/'))
88
+ return `${where}: carried.endpoint must be the endpoint the file's node calls, starting with "/".`;
89
+ if (c.operation !== undefined && (typeof c.operation !== 'string' || !c.operation))
90
+ return `${where}: carried.operation must be a non-empty string when given.`;
91
+ const fieldsRefusal = carriedConnectorFieldsRefusal(c.fields, `${where}: carried`);
92
+ if (fieldsRefusal)
93
+ return fieldsRefusal;
94
+ // Every `{name}` the endpoint template has needs a carried PATH field: the
95
+ // platform fills the template from `pathParameters`, and `flow validate`
96
+ // refuses a node with a placeholder no path parameter fills.
97
+ const paths = new Set((c.fields ?? [])
98
+ .filter((f) => f.location === 'path').map((f) => f.name));
99
+ const unfilled = endpointPlaceholders(c.endpoint).filter((name) => !paths.has(name));
100
+ if (unfilled.length > 0)
101
+ return `${where}: carried.endpoint ${JSON.stringify(c.endpoint)} has ${unfilled.map((n) => `{${n}}`).join(', ')} `
102
+ + `with no carried field of location "path" to fill ${unfilled.length > 1 ? 'them' : 'it'}.`;
103
+ return undefined;
104
+ }
105
+ /**
106
+ * Why `definition` cannot be the definition of carried operation `carried` on
107
+ * connector `key`, or `undefined` when it can: the connector key and HTTP
108
+ * method the definition itself records must agree with the step's. A
109
+ * definition borrowed from another connector, or from an operation with
110
+ * another verb, is refused. A definition that records neither is not checked
111
+ * on that point.
112
+ *
113
+ * For instance a Slack POST operation's definition under
114
+ * `carried: { method: 'DELETE', … }` is refused.
115
+ */
116
+ export function carriedDefinitionMismatch(definition, key, carried, where) {
117
+ const identity = definitionIdentity(definition);
118
+ const context = definition.model?.context;
119
+ const contextValue = (name) => (Array.isArray(context)
120
+ ? context.find((c) => c?.name === name)?.value
121
+ : undefined);
122
+ const text = (v) => (typeof v === 'string' && v ? v : undefined);
123
+ const definedKey = text(identity.connectorKey) ?? text(contextValue('connectorKey'));
124
+ if (definedKey !== undefined && definedKey !== key)
125
+ return `${where}: the carried definition is connector "${definedKey}"'s, not "${key}"'s. `
126
+ + 'Keep the definition the .flow file holds for this node.';
127
+ const definedMethod = text(identity.httpMethod) ?? text(contextValue('method'));
128
+ if (definedMethod !== undefined && transportHttpMethod(definedMethod.toUpperCase()) !== transportHttpMethod(carried.method.toUpperCase()))
129
+ return `${where}: carried.method is ${carried.method.toUpperCase()}, but the carried definition's operation is ${definedMethod.toUpperCase()}. `
130
+ + 'Keep the method and definition the .flow file holds for this node.';
131
+ return undefined;
132
+ }
133
+ /** The definition's own copy of the activity's identity: `connectorDetail.configuration`, parsed. */
134
+ function definitionIdentity(definition) {
135
+ let found = {};
136
+ const visit = (v) => {
137
+ if (Array.isArray(v)) {
138
+ v.forEach(visit);
139
+ return;
140
+ }
141
+ if (!v || typeof v !== 'object')
142
+ return;
143
+ const detail = v.connectorDetail;
144
+ if (typeof detail?.configuration === 'string') {
145
+ try {
146
+ const parsed = JSON.parse(detail.configuration);
147
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
148
+ found = parsed;
149
+ }
150
+ catch {
151
+ // Not JSON: the definition names no identity here.
152
+ }
153
+ return;
154
+ }
155
+ for (const child of Object.values(v))
156
+ visit(child);
157
+ };
158
+ visit(definition.form);
159
+ return found;
160
+ }
161
+ /** The first `uiPathActivityTypeId` string anywhere in the definition, as the library reads it. */
162
+ function activityTypeIdOf(definition) {
163
+ if (!definition || typeof definition !== 'object')
164
+ return undefined;
165
+ if (Array.isArray(definition)) {
166
+ for (const item of definition) {
167
+ const id = activityTypeIdOf(item);
168
+ if (id !== undefined)
169
+ return id;
170
+ }
171
+ return undefined;
172
+ }
173
+ const own = ownEntry(definition, 'uiPathActivityTypeId');
174
+ if (typeof own === 'string' && own)
175
+ return own;
176
+ for (const child of Object.values(definition)) {
177
+ const id = activityTypeIdOf(child);
178
+ if (id !== undefined)
179
+ return id;
180
+ }
181
+ return undefined;
182
+ }
183
+ /**
184
+ * The operation `carried` and the carried `definition` describe, resolved as
185
+ * `Library.resolve` resolves a library entry. `carried` must have passed
186
+ * {@link carriedOperationRefusal}.
187
+ *
188
+ * The entry is built from the two halves: the transport (method, endpoint, verb)
189
+ * from `carried`, the object, activity kind and connector name from the
190
+ * definition. The fields are the carried ones, optional except a path field
191
+ * the endpoint template names.
192
+ *
193
+ * @param nodeType - The step's node type, `uipath.connector.<key>.<action>`.
194
+ * @param key - The connector key.
195
+ * @param version - The step's pinned version, which the definition carries.
196
+ * @param definition - The carried `definitions[]` entry for `nodeType@version`.
197
+ * @param carried - The step's carried operation.
198
+ */
199
+ export function carriedConnector(nodeType, key, version, definition, carried) {
200
+ const identity = definitionIdentity(definition);
201
+ const text = (v) => (typeof v === 'string' && v ? v : undefined);
202
+ const objectName = text(identity.objectName) ?? '';
203
+ const connectorName = text(definition.display?.sourceDisplayName) ?? '';
204
+ const operation = {
205
+ // `buildConfiguration` lower-cases the verb; the file's is already lower-case.
206
+ ...(carried.operation !== undefined ? { name: carried.operation } : {}),
207
+ objectName,
208
+ httpMethod: carried.method.toUpperCase(),
209
+ path: carried.endpoint,
210
+ activityType: text(identity.activityType) ?? 'Curated',
211
+ ...(identity.subType !== undefined ? { subType: identity.subType } : {}),
212
+ ...(identity.supportsStreaming !== undefined ? { supportsStreaming: identity.supportsStreaming } : {}),
213
+ };
214
+ // A path field the endpoint template names is required: without it the node
215
+ // calls an unfilled `{name}`, which `flow validate` refuses. Every other
216
+ // carried field is optional: the file shows that it exists, not that it is required.
217
+ const templated = new Set(endpointPlaceholders(carried.endpoint));
218
+ const fields = (carried.fields ?? []).map((f) => ({
219
+ name: f.name, location: f.location, required: f.location === 'path' && templated.has(f.name),
220
+ ...(f.type !== undefined ? { type: f.type } : {}),
221
+ }));
222
+ const activityTypeId = activityTypeIdOf(definition);
223
+ return {
224
+ nodeType,
225
+ version,
226
+ connectorKey: key,
227
+ connectorName,
228
+ httpMethod: carried.method.toUpperCase(),
229
+ endpoint: carried.endpoint,
230
+ ...(activityTypeId !== undefined ? { activityTypeId } : {}),
231
+ v1def: definition,
232
+ entry: { connector: { key, name: connectorName }, operation },
233
+ fields,
234
+ multipartParts: [],
235
+ objectName,
236
+ };
237
+ }
238
+ /** The slot each `inputs.detail` parameter map rides in, as a carried field's location. */
239
+ const SLOTS = [['bodyParameters', 'body'], ['queryParameters', 'query'], ['pathParameters', 'path']];
240
+ /**
241
+ * The operation a saved connector node describes, for decompile to carry: its
242
+ * method, endpoint, the verb its configuration records, and each input it sets
243
+ * with its slot. `undefined` when the node does not describe one compile could
244
+ * rebuild: no method `flow validate` accepts or no endpoint, a multipart part
245
+ * (its part list is the library's to declare), one name in two slots, or an
246
+ * endpoint placeholder no path parameter fills.
247
+ *
248
+ * For instance a node with `detail: { method: 'POST', endpoint: '/send', bodyParameters: { text: 'hi' } }`
249
+ * gives `{ method: 'POST', endpoint: '/send', fields: [{ name: 'text', location: 'body' }] }`.
250
+ *
251
+ * @param detail - The node's `inputs.detail`.
252
+ */
253
+ export function carriedOperationOf(detail) {
254
+ const { method, endpoint } = detail;
255
+ if (!isHttpMethod(method) || typeof endpoint !== 'string' || !endpoint.startsWith('/'))
256
+ return undefined;
257
+ if (Array.isArray(detail.multipartParameters) && detail.multipartParameters.length > 0)
258
+ return undefined;
259
+ const fields = [];
260
+ const seen = new Set();
261
+ for (const [slot, location] of SLOTS) {
262
+ const m = detail[slot];
263
+ if (!m || typeof m !== 'object' || Array.isArray(m))
264
+ continue;
265
+ for (const name of Object.keys(m)) {
266
+ if (!name || seen.has(name))
267
+ return undefined;
268
+ seen.add(name);
269
+ fields.push({ name, location });
270
+ }
271
+ }
272
+ // A template placeholder the node fills from no path parameter: compile would
273
+ // refuse the description, so it is not carried.
274
+ const paths = new Set(fields.filter((f) => f.location === 'path').map((f) => f.name));
275
+ if (endpointPlaceholders(endpoint).some((name) => !paths.has(name)))
276
+ return undefined;
277
+ const operation = savedOperationVerb(detail.configuration);
278
+ return {
279
+ method,
280
+ endpoint,
281
+ ...(operation !== undefined ? { operation } : {}),
282
+ ...(fields.length > 0 ? { fields } : {}),
283
+ };
284
+ }
285
+ /** `essentialConfiguration.operation` of a node's `=jsonString:` configuration, when it records one. */
286
+ function savedOperationVerb(configuration) {
287
+ if (typeof configuration !== 'string' || !configuration.startsWith('=jsonString:'))
288
+ return undefined;
289
+ try {
290
+ const parsed = JSON.parse(configuration.slice('=jsonString:'.length));
291
+ const verb = parsed?.essentialConfiguration?.operation;
292
+ return typeof verb === 'string' && verb ? verb : undefined;
293
+ }
294
+ catch {
295
+ return undefined;
296
+ }
297
+ }
@@ -297,6 +297,18 @@ export declare class Library {
297
297
  */
298
298
  lookupSpecs(key: string, action: string, version?: string, objectName?: string): Record<string, LookupSpec>;
299
299
  resolve(key: string, action: string, version?: string, objectName?: string): ResolvedConnector;
300
+ /**
301
+ * Whether any layer (the prepared overlay or the library) has an entry for
302
+ * `nodeType`, at any version. `false` is exactly when `resolve` refuses the
303
+ * operation as CONNECTOR_NOT_IN_LIBRARY whatever object is asked for: Flow
304
+ * decompile carries such an operation from the file
305
+ * (`core/carried-connector-operation.ts`). Reads the index only, so it warns
306
+ * about nothing.
307
+ *
308
+ * For instance `indexes('uipath.connector.uipath-salesforce-slack.send-message-to-channel')`
309
+ * is `true` on the shipped library.
310
+ */
311
+ indexes(nodeType: string): boolean;
300
312
  /**
301
313
  * One operation's page source, for `registry describe`: the entry and definition
302
314
  * of one index row, from the first layer that carries it. That is the prepared
@@ -112,6 +112,20 @@ export class Library {
112
112
  resolve(key, action, version, objectName) {
113
113
  return this.resolveType(`uipath.connector.${key}.${action}`, version, objectName);
114
114
  }
115
+ /**
116
+ * Whether any layer (the prepared overlay or the library) has an entry for
117
+ * `nodeType`, at any version. `false` is exactly when `resolve` refuses the
118
+ * operation as CONNECTOR_NOT_IN_LIBRARY whatever object is asked for: Flow
119
+ * decompile carries such an operation from the file
120
+ * (`core/carried-connector-operation.ts`). Reads the index only, so it warns
121
+ * about nothing.
122
+ *
123
+ * For instance `indexes('uipath.connector.uipath-salesforce-slack.send-message-to-channel')`
124
+ * is `true` on the shipped library.
125
+ */
126
+ indexes(nodeType) {
127
+ return this.carries(nodeType);
128
+ }
115
129
  /**
116
130
  * One operation's page source, for `registry describe`: the entry and definition
117
131
  * of one index row, from the first layer that carries it. That is the prepared
@@ -4,6 +4,7 @@
4
4
  *
5
5
  * Usage:
6
6
  * flow-decompile <original.flow> [-o Name.flow.ts] [--import <specifier>] [--strict] [--scripts function|string]
7
+ * [--library <library-json dir>] [--connectors-local <dir>]
7
8
  *
8
9
  * The reverse of compile-cli: reads a `.flow` JSON and emits Flow SDK builder
9
10
  * source whose default export re-serializes to the same graph (same node ids,
@@ -13,6 +14,10 @@
13
14
  * unsupported construct is a hard error instead of a `// TODO` marker.
14
15
  * `--scripts string` prints every script step as `script({ code })` instead of
15
16
  * as a TypeScript function (the default, where the body allows it).
17
+ * `--library` and `--connectors-local` pick the connector library as `compile`
18
+ * does (default `$FLOW_SDK_LIBRARY_JSON`, else the pulled cache): a connector
19
+ * operation it has no entry for is carried from the file, so the untouched step
20
+ * compiles back (`core/carried-connector-operation.ts`).
16
21
  *
17
22
  * The source's first line is a stamp (decompile-stamp.ts): the original's name, the
18
23
  * digest of the source written, and the options that shaped it. `flow merge
@@ -34,6 +39,7 @@ import { PACKAGE_NAME } from './package-name.js';
34
39
  import { commentText } from './core/comment-text.js';
35
40
  import { loadNodePackages } from './node-packages.js';
36
41
  import { pipelineFrontDoor } from './registry/uip/pipeline-front-door.js';
42
+ import { openCliLibrary } from './core/cli-library.js';
37
43
  /** Derive a PascalCase base name from the flow name/id for the default output file. */
38
44
  function baseName(flow) {
39
45
  const src = flow.name ?? flow.id ?? 'Flow';
@@ -46,10 +52,10 @@ function baseName(flow) {
46
52
  }
47
53
  export async function run(argv) {
48
54
  if (argv.length === 0 || argv[0] === '-h' || argv[0] === '--help') {
49
- console.error('usage: flow-decompile <original.flow> [-o Name.flow.ts] [--import <specifier>] [--package <name>]... [--strict] [--scripts function|string]');
55
+ console.error('usage: flow-decompile <original.flow> [-o Name.flow.ts] [--import <specifier>] [--package <name>]... [--strict] [--scripts function|string] [--library <dir>] [--connectors-local <dir>]');
50
56
  return 2;
51
57
  }
52
- const flags = new Set(['-o', '--import', '--package', '--scripts']);
58
+ const flags = new Set(['-o', '--import', '--package', '--scripts', '--library', '--connectors-local']);
53
59
  const pos = argv.find((a, i) => !flags.has(a) && !flags.has(argv[i - 1]) && !a.startsWith('--'));
54
60
  if (!pos) {
55
61
  console.error('flow-decompile: missing <original.flow>');
@@ -73,9 +79,22 @@ export async function run(argv) {
73
79
  console.error(`flow-decompile: warning: ${message}`);
74
80
  if (packages.loaded.length > 0)
75
81
  reportResult({ packages: packages.loaded.map((p) => p.package) });
82
+ // The library `compile` will open, so a connector operation it has no entry
83
+ // for is carried from the file instead of being refused on recompile. Decompile
84
+ // needs no library otherwise: one it cannot read (a corrupt or half-written
85
+ // cache) is a warning, and the source is written with nothing carried.
86
+ let library;
87
+ try {
88
+ library = openCliLibrary(argv);
89
+ }
90
+ catch (error) {
91
+ console.error(`flow-decompile: warning: connector library unreadable (${error instanceof Error ? error.message : String(error)}); nothing is carried`);
92
+ library = undefined;
93
+ }
76
94
  const strict = argv.includes('--strict');
77
95
  const ts = decompileFlowFile(pos, flow, {
78
96
  importSpecifier: flagValue(argv, '--import') ?? PACKAGE_NAME,
97
+ ...(library ? { library } : {}),
79
98
  bestEffort: !strict,
80
99
  scripts,
81
100
  // Findings the source cannot carry on its own (a node no trigger reaches, a
@@ -29,6 +29,7 @@
29
29
  * re-attached by `flow-merge`; see `docs/FLOW_PARITY.md`).
30
30
  */
31
31
  import { type FlowGlobalDeclaration } from './flow-variables.js';
32
+ import type { Library } from './core/library.js';
32
33
  /** An expression envelope as written by `migrate.ts` (`{type,expression,fieldType}`). */
33
34
  interface WrappedSource {
34
35
  type: string;
@@ -163,6 +164,18 @@ export interface DecompileOptions {
163
164
  * elsewhere, where the loader's `toString()` has not been measured.
164
165
  */
165
166
  scripts?: 'function' | 'string';
167
+ /**
168
+ * The connector library `compile` will resolve the flow's connector steps
169
+ * against. With it, a connector operation the library has no entry for (a
170
+ * connector or operation newer than the snapshot) is carried from the file:
171
+ * its `definitions[]` entry in `.definitions([...])` and its node's method,
172
+ * endpoint and input slots as the step's `carried` option, so the untouched
173
+ * step compiles back (`core/carried-connector-operation.ts`). Without one,
174
+ * nothing is carried, and compile resolves every step against its own library.
175
+ * The CLI opens the one `compile` opens (`--library`, else
176
+ * `$FLOW_SDK_LIBRARY_JSON`, else the pulled cache).
177
+ */
178
+ library?: Library;
166
179
  }
167
180
  /**
168
181
  * Tracks which identifiers the emitted source uses, per module, so each import
package/dist/decompile.js CHANGED
@@ -89,6 +89,14 @@ let runRawManifests = [];
89
89
  * definition and the node keeps its version even when the author edits it.
90
90
  */
91
91
  let runCarried = new Map();
92
+ /**
93
+ * The connector nodes whose operation the source carries, by `<type>@<version>`:
94
+ * the decompile's library has no entry for the type, and `runCarried` holds the
95
+ * file's definition for the pair. See `core/carried-connector-operation.ts`.
96
+ */
97
+ let runCarriedOperations = new Set();
98
+ /** `DecompileOptions.library` for the current run. */
99
+ let runLibrary;
92
100
  /** The file's top-level `bindings[]` rows, by id, for {@link resolveTemplateBindings}. */
93
101
  let runBindings = new Map();
94
102
  let runStrict = false;
@@ -817,6 +825,7 @@ function liftRegistered(node, impl = registeredImpl(node), graph) {
817
825
  sidecar: (path) => runReadSidecar?.(path),
818
826
  flowId: runFlowId,
819
827
  definitionOf: (n) => runDefs.get(`${n.type}@${n.typeVersion}`) ?? runDefs.get(n.type),
828
+ carriesOperation: () => runCarriedOperations.has(`${node.type}@${version}`),
820
829
  attached: (port, limit = Infinity, accept = () => true) => {
821
830
  const found = [];
822
831
  for (const e of graph?.outEdges(node.id) ?? []) {
@@ -1120,7 +1129,10 @@ function carriedPairs(flow) {
1120
1129
  continue;
1121
1130
  const shipped = shippedVersions(n.type);
1122
1131
  const unresolvable = shipped.length > 0 && !shipped.includes(n.typeVersion);
1123
- if (!unresolvable && !isCanvasDraft(n) && !isDraftDecision(n))
1132
+ const operation = carriesOperation(n);
1133
+ if (operation)
1134
+ runCarriedOperations.add(key);
1135
+ if (!unresolvable && !operation && !isCanvasDraft(n) && !isDraftDecision(n))
1124
1136
  continue;
1125
1137
  const base = `${camel(String(n.type).split('.').pop() ?? 'node')}V${String(n.typeVersion).replace(/[^A-Za-z0-9]+/g, '_')}Definition`;
1126
1138
  let name = base;
@@ -1132,6 +1144,14 @@ function carriedPairs(flow) {
1132
1144
  }
1133
1145
  return out;
1134
1146
  }
1147
+ /**
1148
+ * Whether the source carries node `n` from the file because decompile's library
1149
+ * cannot resolve it: its node type says so (`FlowNodeType.carriesFromFile`).
1150
+ * The caller checks that the file holds its definition.
1151
+ */
1152
+ function carriesOperation(n) {
1153
+ return runLibrary !== undefined && registeredImpl(n)?.carriesFromFile?.(n, runLibrary) === true;
1154
+ }
1135
1155
  /**
1136
1156
  * The input names a definition declares: its `inputDefaults` keys and the
1137
1157
  * top-level `inputs.<name>` its form fields edit. For instance quick-form@1.1
@@ -3052,6 +3072,8 @@ export function decompile(flow, options = {}) {
3052
3072
  if (!runDefs.has(d.nodeType))
3053
3073
  runDefs.set(d.nodeType, d);
3054
3074
  }
3075
+ runLibrary = options.library;
3076
+ runCarriedOperations = new Set();
3055
3077
  runCarried = carriedPairs(flow);
3056
3078
  // Best effort: a malformed `bindings` section (not an array) indexes nothing.
3057
3079
  const rows = flow.bindings;
@@ -312,6 +312,15 @@ export interface FlowDeserializeContext {
312
312
  type: string;
313
313
  typeVersion?: string;
314
314
  }): unknown;
315
+ /**
316
+ * Whether decompile carries this connector node's operation: decompile was
317
+ * given a library with no entry for the node's type, and the file holds the
318
+ * node's definition, which the source carries in `.definitions([...])`. The
319
+ * lift then writes the operation's transport and fields as the step's
320
+ * `carried` option (`core/carried-connector-operation.ts`). `false` for any
321
+ * other node.
322
+ */
323
+ carriesOperation(): boolean;
315
324
  /**
316
325
  * The nodes attached to this one on an artifact handle (`tool`, `context`,
317
326
  * `escalation`, `memory`), in edge order, at most `limit` of them. Their edges
@@ -530,6 +539,16 @@ export interface FlowNodeType<Spec> extends NodeType<Spec, FlowNodeContribution,
530
539
  * file's own `definitions[]` entry for the node, if any. Absent: never a draft.
531
540
  */
532
541
  isDraft?(node: unknown, definition: unknown): boolean;
542
+ /**
543
+ * Whether decompile carries a serialized node of this type from the file
544
+ * because `library` (the one decompile was given) cannot resolve it: decompile
545
+ * then copies the node's definition into `.definitions([...])`, and the lift
546
+ * sees `FlowDeserializeContext.carriesOperation()` as `true`. A connector
547
+ * operation answers `true` for a node type the library does not index whose
548
+ * saved `inputs.detail` describes an operation compile can rebuild
549
+ * (`core/carried-connector-operation.ts`). Absent: never.
550
+ */
551
+ carriesFromFile?(node: unknown, library: NonNullable<SerializeOpts['library']>): boolean;
533
552
  /**
534
553
  * The node-level `model` every node of this type carries, whichever path emits
535
554
  * it — this type's `serialize`, or a `rawNode` of its definition. `'omit'`: none
package/dist/merge-cli.js CHANGED
@@ -317,7 +317,8 @@ export async function run(argv) {
317
317
  }
318
318
  // Decompiled as the stamp records, so the baseline is built from the source the
319
319
  // author started from; without a stamp, with decompile's defaults.
320
- const decompileOpts = stamp ? { scripts: stamp.scripts, strict: stamp.strict } : {};
320
+ // The library decompile carried connector operations against: the one compile opens.
321
+ const decompileOpts = { ...(stamp ? { scripts: stamp.scripts, strict: stamp.strict } : {}), ...(library ? { library } : {}) };
321
322
  let baselineCompile;
322
323
  if (derivedFrom) {
323
324
  try {