@uipath/maestro-builder-sdk 6.96.7 → 6.97.0

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.
Files changed (48) hide show
  1. package/README.md +2 -1
  2. package/dist/bpmn/check-cli.js +8 -4
  3. package/dist/bpmn/compile-cli.js +4 -3
  4. package/dist/bpmn/decompile-cli.js +15 -1
  5. package/dist/bpmn/decompile-pipeline.d.ts +5 -0
  6. package/dist/bpmn/decompile-pipeline.js +3 -3
  7. package/dist/bpmn/decompile-stamp.d.ts +13 -0
  8. package/dist/bpmn/decompile-stamp.js +8 -0
  9. package/dist/bpmn/decompile.d.ts +17 -4
  10. package/dist/bpmn/decompile.js +9 -4
  11. package/dist/bpmn/merge-cli.js +32 -4
  12. package/dist/bpmn/merge-source.d.ts +2 -0
  13. package/dist/bpmn/merge-source.js +1 -0
  14. package/dist/case/check-cli.js +4 -2
  15. package/dist/case/compile-cli.js +14 -9
  16. package/dist/case/decompile-cli.d.ts +1 -1
  17. package/dist/case/decompile-cli.js +12 -2
  18. package/dist/check-cli.js +12 -6
  19. package/dist/cli/commands/registry.js +2 -0
  20. package/dist/compile-cli.js +16 -10
  21. package/dist/core/cli-library.d.ts +18 -2
  22. package/dist/core/cli-library.js +25 -5
  23. package/dist/core/library.d.ts +74 -2
  24. package/dist/core/library.js +88 -11
  25. package/dist/decompile-cli.js +17 -2
  26. package/dist/decompile-stamp.d.ts +13 -0
  27. package/dist/decompile-stamp.js +7 -1
  28. package/dist/emit.js +5 -8
  29. package/dist/merge-cli.js +51 -1
  30. package/dist/registry/curated-overlay.d.ts +11 -0
  31. package/dist/registry/curated-overlay.js +27 -0
  32. package/dist/registry/describe-cli.d.ts +3 -0
  33. package/dist/registry/describe-cli.js +38 -6
  34. package/dist/registry/fetch/fetch-connectors.d.ts +21 -0
  35. package/dist/registry/fetch/fetch-connectors.js +84 -0
  36. package/dist/registry/fetch/fetch-definitions.d.ts +61 -0
  37. package/dist/registry/fetch/fetch-definitions.js +447 -0
  38. package/dist/registry/fetch/flow-requests.d.ts +14 -0
  39. package/dist/registry/fetch/flow-requests.js +81 -0
  40. package/dist/registry/fetch/with-fetched-definitions.d.ts +46 -0
  41. package/dist/registry/fetch/with-fetched-definitions.js +211 -0
  42. package/dist/registry/library-build/events.d.ts +9 -2
  43. package/dist/registry/library-build/events.js +4 -10
  44. package/dist/registry/pull-cli.d.ts +9 -0
  45. package/dist/registry/pull-cli.js +150 -10
  46. package/dist/registry/search-cli.d.ts +25 -0
  47. package/dist/registry/search-cli.js +94 -10
  48. package/package.json +4 -3
@@ -29,14 +29,34 @@ import { connectorInputErrors, connectorResourceRefusals } from './connector-inp
29
29
  * pull` filled (`resolveLibraryDir`). The overlay is `--connectors-local <dir>`,
30
30
  * else `.flow-sdk/connectors-local` (or a legacy `./connectors-local`) when it
31
31
  * has an `index.json` — the directory `registry prepare` writes by default.
32
+ *
33
+ * Either one is enough. With no pre-cache library the overlay is the whole
34
+ * library, so what `prepare` (or a fetch through `uip`) wrote is read even
35
+ * when the published zip was never pulled (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md).
36
+ * With neither there is no library, unless `opts.always` asks for an empty one:
37
+ * the CLIs that fetch a missing definition through `uip` need every connector
38
+ * step to be a miss they can record, not a LIBRARY_REQUIRED.
39
+ *
40
+ * A `--library` named on the command line is used or refused, never stepped
41
+ * around: one with no `index.json` is LIBRARY_NOT_FOUND, so a typo cannot
42
+ * quietly build from an older overlay instead. Only the defaults (the
43
+ * environment and the pulled cache) fall back to the overlay alone.
32
44
  */
33
- export function openCliLibrary(argv) {
34
- const libDir = resolveLibraryDir(flagValue(argv, '--library'));
45
+ export function openCliLibrary(argv, opts = {}) {
35
46
  // Through the reader, not `existsSync`: a host's reader serves a library that is on no disk.
36
- if (!libDir || defaultReadText()(join(libDir, 'index.json')) === undefined)
37
- return undefined;
47
+ const read = defaultReadText();
48
+ const hasIndex = (dir) => dir !== undefined && read(join(dir, 'index.json')) !== undefined;
49
+ const named = flagValue(argv, '--library');
50
+ if (named !== undefined && !hasIndex(named))
51
+ return new Library(named, { overlayDir: flagValue(argv, '--connectors-local') ?? defaultOverlayDir() });
52
+ const libDir = resolveLibraryDir(named);
38
53
  const overlayDir = flagValue(argv, '--connectors-local') ?? defaultOverlayDir();
39
- return new Library(libDir, { overlayDir });
54
+ const { always, ...hooks } = opts;
55
+ if (hasIndex(libDir))
56
+ return new Library(libDir, { overlayDir, ...hooks });
57
+ if (hasIndex(overlayDir))
58
+ return new Library(undefined, { overlayDir, ...hooks });
59
+ return always ? new Library(undefined, hooks) : undefined;
40
60
  }
41
61
  /**
42
62
  * The connector half of a family's check options, from a library the CLI already
@@ -230,6 +230,49 @@ export interface LibraryOpts {
230
230
  readText?: ReadText;
231
231
  /** Receives the library's warnings. Defaults to stderr; a host without `process` passes its own. */
232
232
  warn?: (message: string) => void;
233
+ /**
234
+ * Told about every node type a resolve found in NO layer, before the
235
+ * CONNECTOR_NOT_IN_LIBRARY it throws. A CLI records these, fetches them
236
+ * through `uip` into the overlay, and runs again with a fresh `Library`
237
+ * (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md §3.2). Only a miss of the whole
238
+ * node type (or of the object asked for) is reported: a version or object
239
+ * the library refuses on a node type it does carry is the library's answer.
240
+ */
241
+ onMiss?: (miss: LibraryMiss) => void;
242
+ /**
243
+ * A sentence appended to CONNECTOR_NOT_IN_LIBRARY for a node type no layer
244
+ * carries: why fetching it did not help (the tenant was asked and does not
245
+ * serve it, or `uip` could not be asked). The CLIs set it on the run after a
246
+ * fetch, so the refusal says what to do next.
247
+ */
248
+ missNote?: (nodeType: string) => string | undefined;
249
+ /**
250
+ * Index rows to leave out of every layer. `flow merge` derives its baseline
251
+ * from the library as the decompile saw it: the node types its stamp records
252
+ * as lacked (`lacked=`) are hidden, whatever has been fetched or prepared for
253
+ * them since, so the stamped source comes back.
254
+ */
255
+ hide?: (row: {
256
+ nodeType?: unknown;
257
+ connectorKey?: unknown;
258
+ provenance?: unknown;
259
+ }) => boolean;
260
+ /**
261
+ * Told about a connector key whose saved wire `identifyAction` or
262
+ * `identifyEvent` could not reverse to an operation, before the refusal it
263
+ * throws. They match on method and path (or event operation), not on a node
264
+ * type, so what is missing is named by connector: the decompilers record these
265
+ * and fetch the connector's operations no layer holds through `uip`
266
+ * (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md). Reported whether or not other
267
+ * operations of the connector are held: a partial cache lacks the rest.
268
+ */
269
+ onConnectorMiss?: (connectorKey: string) => void;
270
+ }
271
+ /** A node type no layer of a {@link Library} carries, as {@link LibraryOpts.onMiss} receives it. */
272
+ export interface LibraryMiss {
273
+ nodeType: string;
274
+ version?: string;
275
+ objectName?: string;
233
276
  }
234
277
  export { ConnectorResolveError, type ConnectorResolveCode } from './connector-resolve-error.js';
235
278
  /** What `registry describe` renders one operation's page from. */
@@ -247,6 +290,13 @@ export interface PageSource {
247
290
  /** `objectName`s the ledgers declare connector-invariant. */
248
291
  invariant: ReadonlySet<string>;
249
292
  }
293
+ /**
294
+ * The `provenance` a definition fetched through `uip` carries, on its entry and
295
+ * its index row (`registry/fetch/`). It sits in the overlay beside what
296
+ * `registry prepare` wrote, but has no connection behind it, so it never counts
297
+ * as prepared.
298
+ */
299
+ export declare const FETCHED_PROVENANCE = "uip-fetch";
250
300
  export declare class Library {
251
301
  private layers;
252
302
  /** The LIST-ENVELOPE LEDGER, overlay first so a prepared entry can add a row. */
@@ -269,7 +319,20 @@ export declare class Library {
269
319
  private readonly invariantCollections;
270
320
  private readonly read;
271
321
  private readonly warn;
272
- constructor(dir: string, opts?: LibraryOpts);
322
+ private readonly onMiss?;
323
+ private readonly missNote?;
324
+ private readonly onConnectorMiss?;
325
+ /**
326
+ * @param dir - The pre-cache library (`registry pull`'s `library-json`), or
327
+ * `undefined` when there is none: the library then resolves from the
328
+ * overlay alone, and with no overlay either it resolves nothing, so every
329
+ * connector operation is CONNECTOR_NOT_IN_LIBRARY
330
+ * (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md). A `dir` that is given but
331
+ * has no index is still LIBRARY_NOT_FOUND: a named library that is not
332
+ * there is a mistake, not an absence. `openCliLibrary` builds one that way
333
+ * for a `--library` flag with no index, which is how the CLIs refuse it.
334
+ */
335
+ constructor(dir: string | undefined, opts?: LibraryOpts);
273
336
  /**
274
337
  * Resolve a connector ACTION (`uipath.connector.<key>.<action>`).
275
338
  *
@@ -308,7 +371,7 @@ export declare class Library {
308
371
  * For instance `indexes('uipath.connector.uipath-salesforce-slack.send-message-to-channel')`
309
372
  * is `true` on the shipped library.
310
373
  */
311
- indexes(nodeType: string): boolean;
374
+ indexes(nodeType: string, objectName?: string): boolean;
312
375
  /**
313
376
  * One operation's page source, for `registry describe`: the entry and definition
314
377
  * of one index row, from the first layer that carries it. That is the prepared
@@ -504,7 +567,16 @@ export declare class Library {
504
567
  private describeMiss;
505
568
  /** Every direct operation id under `prefix` (no further dot), across layers, sorted and de-duplicated. */
506
569
  private opsUnder;
570
+ /**
571
+ * Whether `nodeType` is a GENERIC operation the layers carry for other objects
572
+ * but not for `objectName` (in any case). False for a curated operation, where
573
+ * an object is the author's mistake, and for one whose objects come from the
574
+ * connection (`objectFromDiscovery`), which only `prepare --object` can fill.
575
+ */
576
+ private variantMissing;
507
577
  /** Whether any layer indexes `nodeType` (at `version`, when one is asked for). */
578
+ /** {@link LibraryOpts.onConnectorMiss}, for a wire of `connectorKey` no layer could identify. */
579
+ private noteConnectorMiss;
508
580
  private carries;
509
581
  /** The connector key is in no entry at all. */
510
582
  private noConnector;
@@ -18,6 +18,13 @@ import { CompileRefusal } from './compile-refusal.js';
18
18
  import { transportHttpMethod } from './connector-inputs.js';
19
19
  import { wireActivityTypeMatches } from './connector-configuration.js';
20
20
  export { ConnectorResolveError } from './connector-resolve-error.js';
21
+ /**
22
+ * The `provenance` a definition fetched through `uip` carries, on its entry and
23
+ * its index row (`registry/fetch/`). It sits in the overlay beside what
24
+ * `registry prepare` wrote, but has no connection behind it, so it never counts
25
+ * as prepared.
26
+ */
27
+ export const FETCHED_PROVENANCE = 'uip-fetch';
21
28
  export class Library {
22
29
  layers = [];
23
30
  /** The LIST-ENVELOPE LEDGER, overlay first so a prepared entry can add a row. */
@@ -40,9 +47,25 @@ export class Library {
40
47
  invariantCollections;
41
48
  read;
42
49
  warn;
50
+ onMiss;
51
+ missNote;
52
+ onConnectorMiss;
53
+ /**
54
+ * @param dir - The pre-cache library (`registry pull`'s `library-json`), or
55
+ * `undefined` when there is none: the library then resolves from the
56
+ * overlay alone, and with no overlay either it resolves nothing, so every
57
+ * connector operation is CONNECTOR_NOT_IN_LIBRARY
58
+ * (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md). A `dir` that is given but
59
+ * has no index is still LIBRARY_NOT_FOUND: a named library that is not
60
+ * there is a mistake, not an absence. `openCliLibrary` builds one that way
61
+ * for a `--library` flag with no index, which is how the CLIs refuse it.
62
+ */
43
63
  constructor(dir, opts = {}) {
44
64
  const read = (this.read = opts.readText ?? defaultReadText());
45
65
  this.warn = opts.warn ?? ((message) => { globalThis.process?.stderr?.write(message); });
66
+ this.onMiss = opts.onMiss;
67
+ this.missNote = opts.missNote;
68
+ this.onConnectorMiss = opts.onConnectorMiss;
46
69
  // A new identity per Library, so the per-reader caches never keep an overlay file: `prepare` rewrites them.
47
70
  const readOverlay = (path) => read(path);
48
71
  this.lookupResolutions = loadLookupResolutions(opts.overlayDir, readOverlay);
@@ -55,10 +78,16 @@ export class Library {
55
78
  if (opts.overlayDir) {
56
79
  const overlayIndex = readOverlay(libraryPath(opts.overlayDir, 'index.json'));
57
80
  if (overlayIndex !== undefined)
58
- this.layers.push({ dir: opts.overlayDir, entries: JSON.parse(overlayIndex).entries ?? [], overlay: true });
81
+ this.layers.push({
82
+ dir: opts.overlayDir,
83
+ entries: (JSON.parse(overlayIndex).entries ?? []).filter((row) => !opts.hide?.(row)),
84
+ overlay: true,
85
+ });
59
86
  this.envelopeRows.push(...loadListEnvelopes(opts.overlayDir, readOverlay));
60
87
  }
61
88
  this.envelopeRows.push(...loadListEnvelopes(dir, read));
89
+ if (dir === undefined)
90
+ return;
62
91
  const idx = libraryPath(dir, 'index.json');
63
92
  const entries = libraryEntries(read, idx);
64
93
  if (entries === undefined)
@@ -66,7 +95,7 @@ export class Library {
66
95
  + (read === readTextFromDisk
67
96
  ? `Run \`${PULL_COMMAND}\`, or point --library / $FLOW_SDK_LIBRARY_JSON at a library-json dir.`
68
97
  : 'The reader passed to Library has no such file.'));
69
- this.layers.push({ dir, entries });
98
+ this.layers.push({ dir, entries: opts.hide ? entries.filter((row) => !opts.hide(row)) : entries });
70
99
  }
71
100
  /**
72
101
  * Resolve a connector ACTION (`uipath.connector.<key>.<action>`).
@@ -123,8 +152,8 @@ export class Library {
123
152
  * For instance `indexes('uipath.connector.uipath-salesforce-slack.send-message-to-channel')`
124
153
  * is `true` on the shipped library.
125
154
  */
126
- indexes(nodeType) {
127
- return this.carries(nodeType);
155
+ indexes(nodeType, objectName) {
156
+ return this.carries(nodeType) && !(objectName && this.variantMissing(nodeType, objectName));
128
157
  }
129
158
  /**
130
159
  * One operation's page source, for `registry describe`: the entry and definition
@@ -266,7 +295,8 @@ export class Library {
266
295
  || entry?.connector?.discovery?.hasCustomFieldDiscovery === true;
267
296
  if (!connectionResolved)
268
297
  return { kind: 'static', prepared: true };
269
- if (rows.some(({ overlay }) => overlay))
298
+ // A row fetched through `uip` has no connection behind it: only a `prepare` row counts.
299
+ if (rows.some(({ overlay, row }) => overlay && row.provenance !== FETCHED_PROVENANCE))
270
300
  return { kind: 'customFields', prepared: true };
271
301
  let bakedFields = [];
272
302
  try {
@@ -338,6 +368,7 @@ export class Library {
338
368
  }
339
369
  }
340
370
  }
371
+ this.noteConnectorMiss(wire.connectorKey);
341
372
  throw new CompileRefusal('CONNECTOR_NOT_IN_LIBRARY', `connector activity not found in library: ${wire.connectorKey} ${wire.httpMethod ?? '?'} ${wire.endpoint ?? '?'}`);
342
373
  }
343
374
  /**
@@ -377,7 +408,9 @@ export class Library {
377
408
  const nodeType = `uipath.connector.${kind}.${key}.${event}`;
378
409
  let rc;
379
410
  try {
380
- rc = this.resolveType(nodeType, version, objectName);
411
+ // A start form missing while its wait form resolves is no miss: the start
412
+ // form is derived from the wait form below. Reported only when both miss.
413
+ rc = this.resolveType(nodeType, version, objectName, eventFallback(kind) === undefined);
381
414
  }
382
415
  catch (error) {
383
416
  // The registry dump carries the WAIT form of every connector event and the
@@ -393,7 +426,7 @@ export class Library {
393
426
  const siblingType = `uipath.connector.${fallback.ns}.${key}.${event}`;
394
427
  let sibling;
395
428
  try {
396
- sibling = this.resolveType(siblingType, version, objectName);
429
+ sibling = this.resolveType(siblingType, version, objectName, false);
397
430
  }
398
431
  catch (siblingError) {
399
432
  // The wait form IS in the library and refused the request itself — a
@@ -402,8 +435,14 @@ export class Library {
402
435
  // told the author the connector was missing.
403
436
  if (this.carries(siblingType, version))
404
437
  throw siblingError;
438
+ if (!this.carries(nodeType, version)) {
439
+ this.onMiss?.({ nodeType, ...(version ? { version } : {}), ...(objectName ? { objectName } : {}) });
440
+ }
405
441
  throw error;
406
442
  }
443
+ if (objectName && this.variantMissing(siblingType, objectName, version)) {
444
+ this.onMiss?.({ nodeType, ...(version ? { version } : {}), objectName });
445
+ }
407
446
  rc = fallback.derive(sibling, nodeType);
408
447
  }
409
448
  return normalizeEventOperation(rc);
@@ -450,6 +489,7 @@ export class Library {
450
489
  }
451
490
  }
452
491
  }
492
+ this.noteConnectorMiss(wire.connectorKey);
453
493
  throw new CompileRefusal('EVENT_UNKNOWN', `connector ${kind} event not found in library: ${wire.connectorKey} `
454
494
  + `${wire.eventOperation ?? '?'} ${wire.objectName ?? '?'}`);
455
495
  }
@@ -553,7 +593,8 @@ export class Library {
553
593
  if (nodeType !== `uipath.connector.event.${key}.${event}`
554
594
  && nodeType !== `uipath.connector.trigger.${key}.${event}`)
555
595
  continue;
556
- if (layer.overlay === true)
596
+ // A row fetched through `uip` has no connection behind it: only a `prepare` row counts.
597
+ if (layer.overlay === true && row.provenance !== FETCHED_PROVENANCE)
557
598
  overlayPrepared = true;
558
599
  if (objectName && row.objectName === objectName)
559
600
  objectPrepared = true;
@@ -697,7 +738,14 @@ export class Library {
697
738
  * of the entries each layer resolves are UNIONED: the overlay can ADD fields
698
739
  * but never drop ones the baked library already exposed (C4).
699
740
  */
700
- resolveType(nodeType, version, objectName) {
741
+ resolveType(nodeType, version, objectName, report = true) {
742
+ // A generic operation that carries other objects but not this one is a miss
743
+ // too: a fetch writes only the objects asked for, so a second object is
744
+ // fetched when it is first asked for. Reported before resolving, because
745
+ // the layers may refuse the object or answer from a sibling's schema.
746
+ if (report && objectName && this.variantMissing(nodeType, objectName, version)) {
747
+ this.onMiss?.({ nodeType, ...(version ? { version } : {}), objectName });
748
+ }
701
749
  // Resolve the op within each layer (overlay first), then union fields across
702
750
  // the layers that carry it.
703
751
  const resolved = [];
@@ -721,6 +769,10 @@ export class Library {
721
769
  }
722
770
  return { ...primary, fields: [...byName.values()] };
723
771
  }
772
+ const missing = !this.carries(nodeType);
773
+ if (missing && report)
774
+ this.onMiss?.({ nodeType, ...(version ? { version } : {}), ...(objectName ? { objectName } : {}) });
775
+ const note = missing ? this.missNote?.(nodeType) : undefined;
724
776
  // Name the two event namespaces when the caller asked for one, so a typo in
725
777
  // an event name does not read as "this connector is missing".
726
778
  const hint = /^uipath\.connector\.(trigger|event)\./.test(nodeType)
@@ -729,7 +781,8 @@ export class Library {
729
781
  + `\`…connector.trigger.…\` starts a flow, \`…connector.event.…\` waits mid-flow.`
730
782
  : '';
731
783
  throw new ConnectorResolveError('CONNECTOR_NOT_IN_LIBRARY', `connector not in library: ${nodeType}${version ? '@' + version : ''}.${hint}`
732
- + this.describeMiss(nodeType, version, objectName));
784
+ + this.describeMiss(nodeType, version, objectName)
785
+ + (note ? ` ${note}` : ''));
733
786
  }
734
787
  /**
735
788
  * Turn a lookup miss into something actionable: which operations this connector
@@ -752,7 +805,8 @@ export class Library {
752
805
  if (!key)
753
806
  return '';
754
807
  // `describe` names no folder: on a browser host it is a store the agent cannot open.
755
- const where = searched ? ` Searched: ${this.layers.map((l) => l.dir).join(', ')}.` : '';
808
+ // No layer at all (nothing pulled, nothing fetched yet) searched nothing worth naming.
809
+ const where = searched && this.layers.length > 0 ? ` Searched: ${this.layers.map((l) => l.dir).join(', ')}.` : '';
756
810
  if (eventNs)
757
811
  return this.describeEventMiss(parts[2], key, asked, where, version, objectName);
758
812
  const ops = this.opsUnder(`uipath.connector.${key}.`);
@@ -779,7 +833,30 @@ export class Library {
779
833
  .map((t) => t.slice(prefix.length))
780
834
  .filter((op) => op !== '' && !op.includes('.'))))].sort();
781
835
  }
836
+ /**
837
+ * Whether `nodeType` is a GENERIC operation the layers carry for other objects
838
+ * but not for `objectName` (in any case). False for a curated operation, where
839
+ * an object is the author's mistake, and for one whose objects come from the
840
+ * connection (`objectFromDiscovery`), which only `prepare --object` can fill.
841
+ */
842
+ variantMissing(nodeType, objectName, version) {
843
+ const rows = this.layers.flatMap((l) => l.entries.filter((e) => e.nodeType === nodeType && (!version || e.version === version)));
844
+ if (rows.length === 0)
845
+ return false;
846
+ if (rows.some((row) => row.objectFromDiscovery === true))
847
+ return false;
848
+ // A generic event (start or wait form) is expanded per object too, and fetched per object.
849
+ const generic = rows.some((row) => row.activityType === 'Generic' || row.activityType === 'GenericExpanded' || row.activityType === 'GenericTrigger');
850
+ if (!generic)
851
+ return false;
852
+ const wanted = objectName.toLowerCase();
853
+ return !rows.some((row) => typeof row.objectName === 'string' && row.objectName.toLowerCase() === wanted);
854
+ }
782
855
  /** Whether any layer indexes `nodeType` (at `version`, when one is asked for). */
856
+ /** {@link LibraryOpts.onConnectorMiss}, for a wire of `connectorKey` no layer could identify. */
857
+ noteConnectorMiss(connectorKey) {
858
+ this.onConnectorMiss?.(connectorKey);
859
+ }
783
860
  carries(nodeType, version) {
784
861
  return this.layers.some((l) => l.entries.some((e) => e.nodeType === nodeType && (!version || e.version === version)));
785
862
  }
@@ -39,7 +39,9 @@ import { PACKAGE_NAME } from './package-name.js';
39
39
  import { commentText } from './core/comment-text.js';
40
40
  import { loadNodePackages } from './node-packages.js';
41
41
  import { pipelineFrontDoor } from './registry/uip/pipeline-front-door.js';
42
- import { openCliLibrary } from './core/cli-library.js';
42
+ import { flowConnectorRequests } from './registry/fetch/flow-requests.js';
43
+ import { openWithFetchedDefinitions } from './registry/fetch/with-fetched-definitions.js';
44
+ import { fetchableNodeType } from './registry/fetch/fetch-definitions.js';
43
45
  /** Derive a PascalCase base name from the flow name/id for the default output file. */
44
46
  function baseName(flow) {
45
47
  const src = flow.name ?? flow.id ?? 'Flow';
@@ -83,15 +85,26 @@ export async function run(argv) {
83
85
  // for is carried from the file instead of being refused on recompile. Decompile
84
86
  // needs no library otherwise: one it cannot read (a corrupt or half-written
85
87
  // cache) is a warning, and the source is written with nothing carried.
88
+ //
89
+ // What the file uses and no layer carries is fetched through `uip` first
90
+ // (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md), so the carry decision is made
91
+ // against what the tenant serves: only an operation the tenant does not serve
92
+ // is carried from the file.
86
93
  let library;
87
94
  try {
88
- library = openCliLibrary(argv);
95
+ library = await openWithFetchedDefinitions(argv, flowConnectorRequests(flow), { who: 'flow-decompile' });
89
96
  }
90
97
  catch (error) {
91
98
  console.error(`flow-decompile: warning: connector library unreadable (${error instanceof Error ? error.message : String(error)}); nothing is carried`);
92
99
  library = undefined;
93
100
  }
94
101
  const strict = argv.includes('--strict');
102
+ // What the library lacked as decompile saw it: those operations are carried
103
+ // from the file. Recorded in the stamp, so `flow merge` can hide them again and
104
+ // derive the same source even after they have been fetched (decompile-stamp.ts).
105
+ const lacked = library === undefined ? [] : [...new Set(flowConnectorRequests(flow)
106
+ .map((r) => r.nodeType)
107
+ .filter((nodeType) => !library.indexes(nodeType) && !library.indexes(fetchableNodeType(nodeType))))].sort();
95
108
  const ts = decompileFlowFile(pos, flow, {
96
109
  importSpecifier: flagValue(argv, '--import') ?? PACKAGE_NAME,
97
110
  ...(library ? { library } : {}),
@@ -112,6 +125,8 @@ export async function run(argv) {
112
125
  scripts,
113
126
  strict,
114
127
  packages: packages.loaded.map((p) => p.package),
128
+ lacked,
129
+ fetch: true,
115
130
  });
116
131
  const out = flagValue(argv, '-o') ?? defaultSourceOut(`${baseName(flow)}.flow.ts`);
117
132
  writeSource(out, stamped);
@@ -11,6 +11,19 @@ export interface FlowDecompileStamp {
11
11
  strict: boolean;
12
12
  /** The node-type packages decompile loaded. */
13
13
  packages: string[];
14
+ /**
15
+ * The connector node types no library layer held when decompiled, so decompile
16
+ * carried them from the file. `flow merge` hides them again to derive the
17
+ * baseline, whatever has been fetched or prepared for them since.
18
+ */
19
+ lacked: string[];
20
+ /**
21
+ * Written by a decompile that records `lacked` (the `fetch` token). Without
22
+ * it the stamp predates fetching through `uip`, and an empty `lacked` says
23
+ * nothing: `flow merge` then hides every fetched row instead, which is the
24
+ * library such a decompile saw.
25
+ */
26
+ fetch: boolean;
14
27
  }
15
28
  /** The stamp line, without a line terminator. */
16
29
  export declare function formatFlowStamp(stamp: FlowDecompileStamp): string;
@@ -30,6 +30,8 @@ export function formatFlowStamp(stamp) {
30
30
  `scripts=${stamp.scripts}`,
31
31
  ...(stamp.strict ? ['strict'] : []),
32
32
  ...(stamp.packages.length > 0 ? [`packages=${stamp.packages.join(',')}`] : []),
33
+ ...(stamp.lacked.length > 0 ? [`lacked=${stamp.lacked.join(',')}`] : []),
34
+ ...(stamp.fetch ? ['fetch'] : []),
33
35
  ],
34
36
  });
35
37
  }
@@ -49,7 +51,7 @@ export function readFlowStamp(source) {
49
51
  if (read === undefined || 'error' in read)
50
52
  return read;
51
53
  const { line } = read;
52
- const stamp = { file: read.file, sha256: read.sha256, scripts: 'function', strict: false, packages: [] };
54
+ const stamp = { file: read.file, sha256: read.sha256, scripts: 'function', strict: false, packages: [], lacked: [], fetch: false };
53
55
  const seen = new Set();
54
56
  for (const token of read.options) {
55
57
  const [key, value] = token.split('=', 2);
@@ -62,6 +64,10 @@ export function readFlowStamp(source) {
62
64
  stamp.strict = true;
63
65
  else if (key === 'packages' && value)
64
66
  stamp.packages = value.split(',');
67
+ else if (key === 'lacked' && value)
68
+ stamp.lacked = value.split(',');
69
+ else if (key === 'fetch' && value === undefined)
70
+ stamp.fetch = true;
65
71
  else
66
72
  return { error: `unknown option \`${token}\`: ${line}` };
67
73
  }
package/dist/emit.js CHANGED
@@ -26,25 +26,22 @@
26
26
  * the static pass should call `check()` — or use `compile-cli`.
27
27
  */
28
28
  import { existsSync, mkdirSync } from 'node:fs';
29
- import { dirname, join } from 'node:path';
29
+ import { dirname } from 'node:path';
30
30
  import { serialize } from './serialize.js';
31
- import { Library } from './library.js';
32
31
  import { Bindings } from './bindings.js';
33
- import { resolveLibraryDir } from './core/library-cache.js';
32
+ import { openCliLibrary } from './core/cli-library.js';
34
33
  import { defaultBindingsFile, defaultResourcesFile } from './workdir.js';
35
34
  import { readCliResources } from './registry/prepare/resources.js';
36
35
  import { writeJsonFile } from './core/json-file.js';
37
36
  /**
38
- * Resolve the connector library the same way `compile-cli` does: only load it
37
+ * Resolve the connector library the way `compile-cli` does (`openCliLibrary`),
38
+ * with the `connectors-local` overlay `registry prepare` writes: only load it
39
39
  * when it is actually there, so a flow with no connectors emits fine without a
40
40
  * built library. A connector action with no library then fails inside
41
41
  * `serialize()` with its own clear error.
42
42
  */
43
43
  function defaultLibrary(dir) {
44
- const libDir = resolveLibraryDir(dir);
45
- if (!libDir || !existsSync(join(libDir, 'index.json')))
46
- return undefined;
47
- return new Library(libDir);
44
+ return openCliLibrary(dir === undefined ? [] : ['--library', dir]);
48
45
  }
49
46
  /** The default resource ledger, parsed, when there is one. */
50
47
  function defaultResources() {
package/dist/merge-cli.js CHANGED
@@ -87,6 +87,10 @@ import { readFlowFile } from './decompile-file.js';
87
87
  import { readFlowStamp, restampFlowSource, sourceDigest, STAMP_MARKER } from './decompile-stamp.js';
88
88
  import { ensureTypeScriptRuntime } from './node-runtime.js';
89
89
  import { flowCheckOpts, openCliLibrary } from './cli-library.js';
90
+ import { FETCHED_PROVENANCE } from './core/library.js';
91
+ import { flowConnectorRequests, hidesLacked } from './registry/fetch/flow-requests.js';
92
+ import { fetchDefinitionsEnabled } from './registry/fetch/fetch-definitions.js';
93
+ import { openWithFetchedDefinitions, withFetchedDefinitions } from './registry/fetch/with-fetched-definitions.js';
90
94
  import { Bindings } from './bindings.js';
91
95
  import { defaultBindingsFile } from './workdir.js';
92
96
  import { loadNodePackages } from './node-packages.js';
@@ -276,7 +280,29 @@ export async function run(argv) {
276
280
  // source; both load TypeScript, so both need the type-stripping runtime.
277
281
  if (derivedFrom || editedIsSource)
278
282
  ensureTypeScriptRuntime();
279
- const library = derivedFrom || editedIsSource ? openCliLibrary(argv) : undefined;
283
+ const fetchedLibrary = derivedFrom || editedIsSource ? await mergeLibrary(argv, originalPath, editedIsSource ? resolve(editedPath) : undefined) : undefined;
284
+ // Both sides compile against the library as decompile saw it: the operations
285
+ // its stamp records as lacked (carried from the file) are hidden, whatever has
286
+ // been fetched or prepared for them since. So the baseline gives back the
287
+ // stamped source, and an untouched carried step compiles from what it carries
288
+ // on both sides rather than from the tenant on one (decompile-stamp.ts).
289
+ const lacked = stamp?.lacked ?? [];
290
+ // A stamp from before fetching records no `lacked`: that decompile saw no
291
+ // fetched row at all, so those are what is hidden.
292
+ const preFetch = stamp !== undefined && !stamp.fetch;
293
+ const hide = preFetch
294
+ ? (row) => row.provenance === FETCHED_PROVENANCE
295
+ : hidesLacked(lacked);
296
+ const library = (lacked.length > 0 || preFetch) && fetchedLibrary !== undefined
297
+ ? openCliLibrary(argv, {
298
+ always: true,
299
+ hide,
300
+ missNote: (nodeType) => (hidesLacked(lacked)({ nodeType })
301
+ ? 'This source carries it from the file it was decompiled from; '
302
+ + 'to compile a step against the tenant’s definition, decompile the original again.'
303
+ : undefined),
304
+ })
305
+ : fetchedLibrary;
280
306
  const bindings = derivedFrom || editedIsSource ? new Bindings(flagValue(argv, '--bindings') ?? defaultBindingsFile()) : undefined;
281
307
  const compileOpts = { library, bindings };
282
308
  // Resolved as decompile resolves it, so a split `.flow` merges as the document the
@@ -563,3 +589,27 @@ function onNode(r) {
563
589
  return { nodeId: r.nodeId ?? '', code: r.code, message: r.message };
564
590
  }
565
591
  runWhenInvokedDirectly(import.meta.url, 'flow-merge', run);
592
+ /**
593
+ * The library merge compiles with, holding every connector definition either
594
+ * side needs (docs/CONNECTOR_LIBRARY_OPTIONAL_DESIGN.md).
595
+ *
596
+ * The original's operations are read from the file and fetched through `uip`
597
+ * when no layer carries them, as `flow decompile` fetches them, so the derived
598
+ * baseline is decompiled and compiled against what the tenant serves. An edited
599
+ * `.flow.ts` can name an operation the original did not: one compile of it with
600
+ * a recording library finds those, and they are fetched too. With the fetch off
601
+ * this is `openCliLibrary(argv)`, as before.
602
+ */
603
+ async function mergeLibrary(argv, originalPath, editedSource) {
604
+ const original = readFlowFile(originalPath);
605
+ // One set of notes for both steps, so the merge's refusal of an operation the
606
+ // edit added still says why it could not be fetched.
607
+ const notes = new Map();
608
+ const library = await openWithFetchedDefinitions(argv, flowConnectorRequests(original), { who: 'flow-merge', notes });
609
+ if (editedSource === undefined || !fetchDefinitionsEnabled())
610
+ return library;
611
+ // A recording pass only, its result discarded: the merge compiles with the
612
+ // library opened after it, which reads whatever it fetched.
613
+ await withFetchedDefinitions(argv, (pass) => compileSourceDraftTolerant(editedSource, { library: pass }), { who: 'flow-merge', notes });
614
+ return openWithFetchedDefinitions(argv, flowConnectorRequests(original), { who: 'flow-merge', notes });
615
+ }
@@ -105,3 +105,14 @@ export interface CuratedOverlayCheck {
105
105
  * because readers that load that archive directly apply no overlay.
106
106
  */
107
107
  export declare function checkCuratedOverlay(libraryPath: string, overlayPath?: string): Promise<CuratedOverlayCheck>;
108
+ /**
109
+ * The curated overlay's two connection-free contributions to a library that
110
+ * was not pulled: the corrections ledger's patches for the entries `libraryPath`
111
+ * holds, and the side-tables, each copied only when `libraryPath` has none.
112
+ *
113
+ * For a partial library fetched one operation at a time through `uip`
114
+ * (`registry/fetch/`), where {@link applyCuratedOverlay} would be wrong: it also
115
+ * adds every definition this directory carries, and those are fixtures, not
116
+ * operations the tenant was asked about. Returns the corrected entry paths.
117
+ */
118
+ export declare function applyCorrectionsAndSideTables(libraryPath: string, sideTablesTo: string, overlayPath?: string): Promise<string[]>;
@@ -444,3 +444,30 @@ export async function checkCuratedOverlay(libraryPath, overlayPath = bundledOver
444
444
  }
445
445
  return { missing, staleCorrections };
446
446
  }
447
+ /**
448
+ * The curated overlay's two connection-free contributions to a library that
449
+ * was not pulled: the corrections ledger's patches for the entries `libraryPath`
450
+ * holds, and the side-tables, each copied only when `libraryPath` has none.
451
+ *
452
+ * For a partial library fetched one operation at a time through `uip`
453
+ * (`registry/fetch/`), where {@link applyCuratedOverlay} would be wrong: it also
454
+ * adds every definition this directory carries, and those are fixtures, not
455
+ * operations the tenant was asked about. Returns the corrected entry paths.
456
+ */
457
+ export async function applyCorrectionsAndSideTables(libraryPath, sideTablesTo, overlayPath = bundledOverlayPath()) {
458
+ const corrected = [];
459
+ for (const correction of await readOverlayCorrections(overlayPath)) {
460
+ if (!(await exists(join(libraryPath, correction.path))))
461
+ continue;
462
+ if ((await patchCorrection(libraryPath, overlayPath, correction)).added.length > 0)
463
+ corrected.push(correction.path);
464
+ }
465
+ for (const table of SIDE_TABLES) {
466
+ const target = join(sideTablesTo, table);
467
+ if (await exists(target))
468
+ continue;
469
+ await mkdir(sideTablesTo, { recursive: true });
470
+ await cp(join(overlayPath, table), target);
471
+ }
472
+ return sortedStrings(corrected);
473
+ }
@@ -6,5 +6,8 @@
6
6
  * `connectors-local` overlay first, then the library. So after `registry prepare`
7
7
  * it shows the connection's real fields. It is rendered from the entry on each call,
8
8
  * so it needs no `library-md` tree and no file the agent must keep a path to.
9
+ *
10
+ * An operation no layer carries is fetched through `uip` into `connectors-local`
11
+ * first, and its page says it came from the tenant.
9
12
  */
10
13
  export declare function run(argv: string[]): Promise<number>;