@uipath/maestro-builder-sdk 6.105.0 → 6.106.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.
package/README.md CHANGED
@@ -182,7 +182,17 @@ undeclared `$vars` reference (a mistyped variable or step name in a `` js`…` `
182
182
  expression) is `check`'s `EXPR_UNDECLARED_REF`, and `compile` writes the read as
183
183
  authored, so a `.flow` that already has one still decompiles and compiles. An
184
184
  expression that is not valid JavaScript is `EXPR_SYNTAX`: `compile` refuses it
185
- with a `FlowBuildError`, and `check` reports it too. For a COMPILED `.flow`, `uip maestro flow validate` is the authoritative
185
+ with a `FlowBuildError`, and `check` reports it too.
186
+
187
+ `flow build` runs the two in that order: `check` first, then `compile` only
188
+ when `check` found no error. It takes the options of both, including `check`'s
189
+ `--baseline <original.flow>` (or `--baseline-from`, as `merge` spells it), and
190
+ exits with their codes. `build` compiles and does not merge, so with
191
+ `--baseline` it needs `-o`, and refuses an `-o` that is the original: write the
192
+ edit back into the original with `flow merge`. For instance `npx flow-sdk flow build Hello -o
193
+ Hello.flow` prints `check`'s findings and then `compile: wrote Hello.flow`, or
194
+ stops after `check` with `build: check found 1 error(s); not compiling`.
195
+ `compile` itself still does not check. For a COMPILED `.flow`, `uip maestro flow validate` is the authoritative
186
196
  product validator, and `uip maestro flow debug` (or `flow-debug`) runs it. Case and BPMN use the same family-first shape:
187
197
  `uip maestro case compile|check|decompile` and
188
198
  `uip maestro bpmn compile|check|format`.
@@ -213,7 +223,8 @@ and `merge` report the `path` they wrote. A verb whose plain output is the
213
223
  result itself (`registry search`, `registry path`, `bpmn check --graph`) prints it
214
224
  only as that object under `--json`, never a second copy on stderr. `package.json` lists the optional
215
225
  surface a caller may probe for in `cliCapabilities` (`json-result`; `fetch-definitions` when a
216
- connector definition no library carries is fetched through `uip`, so no library has to be pulled).
226
+ connector definition no library carries is fetched through `uip`, so no library has to be pulled;
227
+ `flow-build` when the SDK has `flow build`).
217
228
  `flow-sdk capabilities` prints that list with the installed version (`--json` for one
218
229
  object), and `flowSdk.minVersion` in a project's `package.json` makes the `flow`, `case`
219
230
  and `bpmn` verbs refuse an older SDK (`website/reference/CLI-LOOP.md`).
@@ -34,7 +34,7 @@ import { sourceTypeDiagnostics } from './source-types.js';
34
34
  import { graphModel, renderGraph } from './graph.js';
35
35
  import { Bindings } from '../core/bindings.js';
36
36
  import { connectorCheckOpts, openCliLibrary } from '../core/cli-library.js';
37
- import { fetchDefinitionsEnabled } from '../registry/fetch/fetch-definitions.js';
37
+ import { fetchesDefinitions } from '../registry/fetch/with-fetched-definitions.js';
38
38
  import { withFetchedDefinitions } from '../registry/fetch/with-fetched-definitions.js';
39
39
  import { flagValue, runWhenInvokedDirectly } from '../cli-run.js';
40
40
  import { ensureTypeScriptRuntime } from '../node-runtime.js';
@@ -90,7 +90,7 @@ export async function run(argv) {
90
90
  let baselineBuilt;
91
91
  if (original !== undefined) {
92
92
  try {
93
- const library = openCliLibrary(argv, { always: fetchDefinitionsEnabled() });
93
+ const library = openCliLibrary(argv, { always: fetchesDefinitions(argv) });
94
94
  baselineBuilt = await buildOriginal(original, {
95
95
  ...(library ? { library } : {}),
96
96
  source: readFileSync(file, 'utf8'),
@@ -45,8 +45,7 @@ import { flagValue, runWhenInvokedDirectly } from '../cli-run.js';
45
45
  import { decompilePipeline } from './decompile-pipeline.js';
46
46
  import { sourceDigest, stampSource } from './decompile-stamp.js';
47
47
  import { openCliLibrary } from '../core/cli-library.js';
48
- import { fetchDefinitionsEnabled } from '../registry/fetch/fetch-definitions.js';
49
- import { fetchMissedBy } from '../registry/fetch/with-fetched-definitions.js';
48
+ import { fetchMissedBy, fetchesDefinitions } from '../registry/fetch/with-fetched-definitions.js';
50
49
  import { BPMN_IMPORT } from '../package-name.js';
51
50
  import { fileURLToPath } from 'node:url';
52
51
  /**
@@ -108,7 +107,7 @@ export async function run(argv) {
108
107
  if (connectors === 'lift') {
109
108
  await fetchMissedBy(argv, (probe) => decompilePipeline(xml, { importSpecifier, style, keepFlowIds, keepUnusedBindings, sdkEntry, library: probe }), { who: 'decompile' });
110
109
  }
111
- const library = connectors === 'lift' ? openCliLibrary(argv, { always: fetchDefinitionsEnabled() }) : undefined;
110
+ const library = connectors === 'lift' ? openCliLibrary(argv, { always: fetchesDefinitions(argv) }) : undefined;
112
111
  const { source, pruned, connectors: connectorSummary, lifted, fallback } = await decompilePipeline(xml, {
113
112
  importSpecifier, style, keepFlowIds, keepUnusedBindings, sdkEntry, ...(library ? { library } : {}),
114
113
  });
@@ -48,8 +48,7 @@ import { loadBuiltBpmn } from './load.js';
48
48
  import { serialize } from './serialize.js';
49
49
  import { Bindings } from '../core/bindings.js';
50
50
  import { openCliLibrary } from '../core/cli-library.js';
51
- import { fetchDefinitionsEnabled } from '../registry/fetch/fetch-definitions.js';
52
- import { fetchMissedBy } from '../registry/fetch/with-fetched-definitions.js';
51
+ import { fetchMissedBy, fetchesDefinitions } from '../registry/fetch/with-fetched-definitions.js';
53
52
  import { FETCHED_PROVENANCE } from '../core/library.js';
54
53
  import { readCliResources } from '../registry/prepare/resources.js';
55
54
  import { ensureTypeScriptRuntime } from '../node-runtime.js';
@@ -157,7 +156,7 @@ async function compileSides(argv, editedPath, originalPath, original, explicitBa
157
156
  ...(decompiled !== undefined ? [deriveBaseline(original, { serialize: probeOpts, ...stampedDecompile(decompiled, probe) })] : []),
158
157
  ]);
159
158
  }, { who: 'bpmn-merge' });
160
- const library = openCliLibrary(argv, { always: fetchDefinitionsEnabled() });
159
+ const library = openCliLibrary(argv, { always: fetchesDefinitions(argv) });
161
160
  const opts = { ...base, ...(library ? { library } : {}) };
162
161
  // Two catches, as `compile` has them, so a broken source fails here exactly as it
163
162
  // fails there. While the source loads, only a builder refusal is printed by its code;
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { type CliExitCode } from './cli-run.js';
3
+ export declare function run(argv: string[]): Promise<CliExitCode>;
@@ -0,0 +1,192 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * build-cli — `flow check`, then `flow compile` only when the check is clean.
4
+ *
5
+ * Usage:
6
+ * node --experimental-strip-types build-cli.js <flow.ts | BaseName> \
7
+ * [-o out.flow] [--library <dir>] [--connectors-local <dir>] [--bindings <file>] \
8
+ * [--resources <file>] [--baseline <original.flow> [--package <name>]]
9
+ *
10
+ * `compile` does not run `check` (docs/CHECK_COMPILE_CONTRACT_DESIGN.md D1, D2):
11
+ * it stops only when it cannot write a correct `.flow`, and a lint finding such
12
+ * as `EMPTY_ARM` is never a reason for it to stop. So the order "check, then
13
+ * compile" was the caller's to remember (#1998). This verb owns it:
14
+ *
15
+ * - It runs `check` with the options `flow check` takes. With `--baseline`
16
+ * (`--baseline-from` is the same option, spelled as `merge` spells it) the
17
+ * findings are scoped to the edit, so a pre-existing finding on a node the
18
+ * edit did not touch is a warning and does not stop the build. `build`
19
+ * compiles, it does not merge, so with `--baseline` it needs `-o`, and
20
+ * refuses an `-o` that is the baseline file (usage error, 2): the
21
+ * write-back into the original is `flow merge`.
22
+ * - An error stops it: nothing is compiled and the exit code is check's (1;
23
+ * 2 for a usage error).
24
+ * - Otherwise it runs `compile` with the options `flow compile` takes, and the
25
+ * exit code is compile's.
26
+ *
27
+ * Exit codes are the two commands' own: 0 written, 1 a finding or refusal, 2 a
28
+ * usage error. `compile` itself is unchanged. Under `--json` the one result
29
+ * object holds both commands' diagnostics, check's first, and `stage` says
30
+ * which command decided the result: `"check"` when it stopped there,
31
+ * `"compile"` otherwise.
32
+ *
33
+ * For instance `flow build Order.flow.ts -o Order.flow` with a step that reads
34
+ * an unknown variable prints check's `✗ [UPDATE_UNKNOWN_VAR] …`, then
35
+ * `build: check found 1 error(s); not compiling`, and exits 1.
36
+ */
37
+ import { realpathSync } from 'node:fs';
38
+ import { resolve } from 'node:path';
39
+ import { reportDiagnostics, reportedFields, reportResult } from './cli-result.js';
40
+ import { runWhenInvokedDirectly } from './cli-run.js';
41
+ import { run as runCheck } from './check-cli.js';
42
+ import { run as runCompile } from './compile-cli.js';
43
+ /** The options that take a value, and which of the two commands each goes to. */
44
+ const VALUE_FLAGS = new Map([
45
+ ['-o', { check: false, compile: true }],
46
+ ['--output', { check: false, compile: true }],
47
+ ['--library', { check: true, compile: true }],
48
+ ['--connectors-local', { check: true, compile: true }],
49
+ ['--bindings', { check: true, compile: true }],
50
+ ['--resources', { check: true, compile: true }],
51
+ ['--baseline', { check: true, compile: false }],
52
+ ['--baseline-from', { check: true, compile: false }],
53
+ ['--package', { check: true, compile: false }],
54
+ ]);
55
+ const USAGE = 'usage: build <flow.ts | BaseName> [-o out.flow] [--library <dir>] [--connectors-local <dir>] [--bindings <file>] '
56
+ + '[--resources <file>] [--baseline <original.flow> [--package <name>]]';
57
+ export async function run(argv) {
58
+ if (argv.length === 0 || argv[0] === '-h' || argv[0] === '--help') {
59
+ console.error(USAGE);
60
+ return 2;
61
+ }
62
+ const parsed = parseArgs(argv);
63
+ if (typeof parsed === 'string') {
64
+ console.error(`build: ${parsed}`);
65
+ console.error(USAGE);
66
+ reportResult({ error: parsed });
67
+ return 2;
68
+ }
69
+ const checked = await runCheck(parsed.check);
70
+ const checkDiagnostics = diagnosticsReported();
71
+ if (checked !== 0) {
72
+ const errors = checkDiagnostics.filter((d) => d.level === 'error').length;
73
+ console.error(checked === 2
74
+ ? 'build: check refused its arguments; not compiling.'
75
+ : `build: check found ${errors} error(s); not compiling. Fix them and run build again.`);
76
+ reportResult({ stage: 'check' });
77
+ return checked;
78
+ }
79
+ const compiled = await runCompile(parsed.compile);
80
+ if (compiled !== 0 && parsed.baseline) {
81
+ // check --baseline turns a pre-existing finding into a warning, but compile
82
+ // judges the whole flow (D2), so an untouched node that fails to lower stops it.
83
+ console.error('build: compile refused. A refusal on a node the edit did not touch is written back as saved by '
84
+ + '`flow merge --baseline-from <original.flow>`.');
85
+ }
86
+ // Both commands' findings, check's first; a finding both report is listed once.
87
+ const seen = new Set();
88
+ const all = [...checkDiagnostics, ...diagnosticsReported()].filter((d) => {
89
+ const key = JSON.stringify([d.level, d.code, d.message, d.step]);
90
+ if (seen.has(key))
91
+ return false;
92
+ seen.add(key);
93
+ return true;
94
+ });
95
+ reportDiagnostics(all);
96
+ reportResult({ stage: 'compile' });
97
+ return compiled;
98
+ }
99
+ /** The two commands' argv, or why `argv` is refused. */
100
+ function parseArgs(argv) {
101
+ const check = [];
102
+ const compile = [];
103
+ const positionals = [];
104
+ const baselines = [];
105
+ for (let i = 0; i < argv.length; i++) {
106
+ const arg = argv[i];
107
+ const target = VALUE_FLAGS.get(arg);
108
+ if (target !== undefined) {
109
+ const value = argv[i + 1];
110
+ if (value === undefined)
111
+ return `${arg} takes a value`;
112
+ i++;
113
+ if (arg === '--baseline' || arg === '--baseline-from') {
114
+ baselines.push(value);
115
+ continue;
116
+ }
117
+ const flag = arg === '--output' ? '-o' : arg;
118
+ if (target.check)
119
+ check.push(flag, value);
120
+ if (target.compile)
121
+ compile.push(flag, value);
122
+ continue;
123
+ }
124
+ // `flow check --source` names the mode build always runs in.
125
+ if (arg === '--source')
126
+ continue;
127
+ if (arg.startsWith('-'))
128
+ return `unknown option ${arg}`;
129
+ positionals.push(arg);
130
+ }
131
+ if (positionals.length !== 1) {
132
+ return positionals.length === 0 ? 'missing <flow.ts | BaseName>' : `takes one source, got ${positionals.join(', ')}`;
133
+ }
134
+ if (new Set(baselines).size > 1)
135
+ return `--baseline and --baseline-from name different files: ${baselines.join(', ')}`;
136
+ const [source] = positionals;
137
+ const baseline = baselines[0];
138
+ if (baseline !== undefined) {
139
+ const refused = baselineOutputRefusal(baseline, outputOf(compile));
140
+ if (refused !== undefined)
141
+ return refused;
142
+ }
143
+ return {
144
+ check: [source, ...check, ...(baseline !== undefined ? ['--baseline', baseline] : [])],
145
+ compile: [source, ...compile],
146
+ baseline: baseline !== undefined,
147
+ };
148
+ }
149
+ /** The `-o` value in compile's argv, if any. */
150
+ function outputOf(compile) {
151
+ const i = compile.indexOf('-o');
152
+ return i >= 0 ? compile[i + 1] : undefined;
153
+ }
154
+ /**
155
+ * Why `build --baseline` refuses where it would write, or `undefined`.
156
+ *
157
+ * `build` compiles; it does not merge. A plain compile over the original
158
+ * `.flow` rewrites every node, the untouched ones included, which is the lossy
159
+ * write the brownfield loop avoids: the write-back is `flow merge
160
+ * --baseline-from`, which keeps the untouched nodes as saved. So with
161
+ * `--baseline`, `-o` is required (without it the output is named after the
162
+ * flow, which for a decompiled canvas is the original's own name) and must not
163
+ * be the baseline file. For instance `build Order.flow.ts -o Order.flow
164
+ * --baseline Order.flow` is refused; `-o .flow-sdk/Order.built.flow` is not.
165
+ */
166
+ function baselineOutputRefusal(baseline, output) {
167
+ const merge = `To write the edit back into the original, run \`flow merge <source> --original ${baseline}\` instead.`;
168
+ if (output === undefined) {
169
+ return `--baseline needs -o: without it the .flow is named after the flow, which can be the original ${baseline}. `
170
+ + `build compiles and does not merge, so it never writes over the original. ${merge}`;
171
+ }
172
+ if (realOrResolved(output) === realOrResolved(baseline)) {
173
+ return `-o ${output} is the --baseline file. build compiles and does not merge, so writing there would replace `
174
+ + `every node of the original, the untouched ones included. Pass -o another path. ${merge}`;
175
+ }
176
+ return undefined;
177
+ }
178
+ /** `path` with its symlinks resolved when it exists, else made absolute. */
179
+ function realOrResolved(path) {
180
+ try {
181
+ return realpathSync.native(path);
182
+ }
183
+ catch {
184
+ return resolve(path);
185
+ }
186
+ }
187
+ /** The diagnostics the last command reported. */
188
+ function diagnosticsReported() {
189
+ const diags = reportedFields().diagnostics;
190
+ return Array.isArray(diags) ? diags : [];
191
+ }
192
+ runWhenInvokedDirectly(import.meta.url, 'build', run);
@@ -28,8 +28,7 @@
28
28
  import { reportResult } from '../cli-result.js';
29
29
  import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
30
30
  import { openCliLibrary } from '../core/cli-library.js';
31
- import { fetchDefinitionsEnabled } from '../registry/fetch/fetch-definitions.js';
32
- import { fetchMissedBy } from '../registry/fetch/with-fetched-definitions.js';
31
+ import { fetchMissedBy, fetchesDefinitions } from '../registry/fetch/with-fetched-definitions.js';
33
32
  import { resolveLibraryDir } from '../core/library-cache.js';
34
33
  import { basename, join, resolve } from 'node:path';
35
34
  import { defaultOverlayDir, defaultSourceOut, workDirBeside, workPath, writeSource } from '../workdir.js';
@@ -81,7 +80,7 @@ export async function run(argv) {
81
80
  await fetchMissedBy(argv, (probe) => run(probe), { who: 'case-decompile' });
82
81
  // A fetch may have created the overlay: look again, so the pipeline helper records it.
83
82
  overlayDir = flagValue(argv, '--connectors-local') ?? defaultOverlayDir();
84
- const library = openCliLibrary(argv, { always: fetchDefinitionsEnabled() });
83
+ const library = openCliLibrary(argv, { always: fetchesDefinitions(argv) });
85
84
  let result;
86
85
  if (!library)
87
86
  result = run(undefined);
@@ -98,6 +98,35 @@ export function registerFlowCommands(program) {
98
98
  '`uip maestro flow debug` / `flow-debug <file.flow>` to run it. ' +
99
99
  'Authoring-time checks still work on a .flow.ts source (--source).');
100
100
  });
101
+ flow.command('build')
102
+ .description('Check authored TypeScript, then compile it to a .flow only when the check finds no error. Same options and exit codes as check and compile; compile itself still does not check.')
103
+ .argument('<source>', 'a .flow.ts path or bare name')
104
+ .option('--source', 'check authored TypeScript (the only kind build takes)')
105
+ .option('-o, --output <file>', 'output .flow path')
106
+ .option('--library <dir>', 'connector library directory')
107
+ .option('--connectors-local <dir>', 'connection-resolved connector overlay')
108
+ .option('--bindings <file>', 'bindings.json path')
109
+ .option('--resources <file>', 'resource ledger that registry prepare writes (default .flow-sdk/resources.json)')
110
+ .option('--baseline <file>', 'the original .flow the source was decompiled from, as for flow check: findings on nodes the edit did not touch, which the original has too, become warnings and do not stop the build. Needs -o, and -o must not be this file: build compiles, it does not merge (use flow merge to write back into the original)')
111
+ .option('--baseline-from <file>', 'the same as --baseline, spelled as flow merge spells it')
112
+ .option('--package <name...>', 'trust and load this node-type package for --baseline (repeatable)')
113
+ .action(async (source, options) => {
114
+ if (emitOnlyEnabled()) {
115
+ refuse('flow-sdk flow build: disabled by emit-only mode, which turns check off; use `flow compile`');
116
+ return;
117
+ }
118
+ const argv = [source];
119
+ addValue(argv, '-o', options.output);
120
+ addValue(argv, '--library', options.library);
121
+ addValue(argv, '--connectors-local', options.connectorsLocal);
122
+ addValue(argv, '--bindings', options.bindings);
123
+ addValue(argv, '--resources', options.resources);
124
+ addValue(argv, '--baseline', options.baseline);
125
+ addValue(argv, '--baseline-from', options.baselineFrom);
126
+ for (const name of options.package ?? [])
127
+ argv.push('--package', name);
128
+ await invoke('flow build', () => import('../../build-cli.js'), argv);
129
+ });
101
130
  flow.command('decompile')
102
131
  .description('Convert a .flow artifact to authored TypeScript.')
103
132
  .argument('<input>', 'input .flow path')
@@ -6,6 +6,11 @@
6
6
  * @param fields - JSON-serializable values, e.g. `{ path, nodes, edges }`.
7
7
  */
8
8
  export declare function reportResult(fields: Record<string, unknown>): void;
9
+ /**
10
+ * The fields this run has reported so far, for a verb that runs two tools and
11
+ * reports their results as one (`flow build`: check, then compile).
12
+ */
13
+ export declare function reportedFields(): Readonly<Record<string, unknown>>;
9
14
  /**
10
15
  * Print text that IS the verb's result (a pretty-printed object, a captured
11
16
  * path), as opposed to a status line such as `compile: wrote X`.
@@ -19,6 +19,13 @@ function slot() {
19
19
  export function reportResult(fields) {
20
20
  Object.assign(slot().fields, fields);
21
21
  }
22
+ /**
23
+ * The fields this run has reported so far, for a verb that runs two tools and
24
+ * reports their results as one (`flow build`: check, then compile).
25
+ */
26
+ export function reportedFields() {
27
+ return slot().fields;
28
+ }
22
29
  /**
23
30
  * Print text that IS the verb's result (a pretty-printed object, a captured
24
31
  * path), as opposed to a status line such as `compile: wrote X`.
@@ -24,6 +24,14 @@ import type { EventCheckOpts } from './event-checks.js';
24
24
  * environment and the pulled cache) fall back to the overlay alone.
25
25
  */
26
26
  export declare function openCliLibrary(argv: readonly string[], opts?: CliLibraryOpts): Library | undefined;
27
+ /**
28
+ * Whether this invocation has a pre-cache library: one named by `--library`
29
+ * (even one that is not there, which {@link openCliLibrary} refuses), or a
30
+ * default (the environment, the pulled cache) with an index. Only without one
31
+ * is a missing definition fetched through `uip`: an operation a pulled library
32
+ * lacks is refused as it always was.
33
+ */
34
+ export declare function hasPulledLibrary(argv: readonly string[]): boolean;
27
35
  /** {@link openCliLibrary}'s options: the miss hooks it passes on, and whether to open an empty library. */
28
36
  export interface CliLibraryOpts extends Pick<LibraryOpts, 'onMiss' | 'missNote' | 'hide' | 'onConnectorMiss'> {
29
37
  always?: boolean;
@@ -43,9 +43,7 @@ import { connectorInputErrors, connectorResourceRefusals } from './connector-inp
43
43
  * environment and the pulled cache) fall back to the overlay alone.
44
44
  */
45
45
  export function openCliLibrary(argv, opts = {}) {
46
- // Through the reader, not `existsSync`: a host's reader serves a library that is on no disk.
47
- const read = defaultReadText();
48
- const hasIndex = (dir) => dir !== undefined && read(join(dir, 'index.json')) !== undefined;
46
+ const hasIndex = indexReader();
49
47
  const named = flagValue(argv, '--library');
50
48
  if (named !== undefined && !hasIndex(named))
51
49
  return new Library(named, { overlayDir: flagValue(argv, '--connectors-local') ?? defaultOverlayDir() });
@@ -58,6 +56,22 @@ export function openCliLibrary(argv, opts = {}) {
58
56
  return new Library(undefined, { overlayDir, ...hooks });
59
57
  return always ? new Library(undefined, hooks) : undefined;
60
58
  }
59
+ /** Whether `dir` holds a library index. Through the reader, not `existsSync`: a host's reader serves a library that is on no disk. */
60
+ function indexReader() {
61
+ const read = defaultReadText();
62
+ return (dir) => dir !== undefined && read(join(dir, 'index.json')) !== undefined;
63
+ }
64
+ /**
65
+ * Whether this invocation has a pre-cache library: one named by `--library`
66
+ * (even one that is not there, which {@link openCliLibrary} refuses), or a
67
+ * default (the environment, the pulled cache) with an index. Only without one
68
+ * is a missing definition fetched through `uip`: an operation a pulled library
69
+ * lacks is refused as it always was.
70
+ */
71
+ export function hasPulledLibrary(argv) {
72
+ const named = flagValue(argv, '--library');
73
+ return named !== undefined || indexReader()(resolveLibraryDir(undefined));
74
+ }
61
75
  /**
62
76
  * The connector half of a family's check options, from a library the CLI already
63
77
  * opened.
@@ -47,7 +47,13 @@ export declare function resolveCachedMarkdown(root?: string): string | undefined
47
47
  * The library a command should use: what the caller named, else the environment,
48
48
  * else the cache. Every compile entry point resolves through this so `pull` and
49
49
  * `compile` cannot disagree about where the library is — they did, and a library
50
- * written by `pull` was invisible to the SDK's own compile.
50
+ * written by `pull` was invisible to the SDK's own compile. An empty
51
+ * FLOW_SDK_LIBRARY_JSON is unset, not a library at the working directory.
52
+ *
53
+ * An environment value that names no index gives way to a pulled cache, as
54
+ * `registry pull` reads it: otherwise a stale variable would hide a library on
55
+ * disk, and a missing definition would be fetched beside it. With no cache it is
56
+ * returned as before (the overlay alone, or a host's reader, then answers).
51
57
  */
52
58
  export declare function resolveLibraryDir(named?: string): string | undefined;
53
59
  /** What `current` points at, for reporting. */
@@ -1,6 +1,7 @@
1
1
  import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
+ import { defaultReadText } from "./read-text.js";
4
5
  /**
5
6
  * Where the connector library lives.
6
7
  *
@@ -65,10 +66,30 @@ export function resolveCachedMarkdown(root = libraryCacheRoot()) {
65
66
  * The library a command should use: what the caller named, else the environment,
66
67
  * else the cache. Every compile entry point resolves through this so `pull` and
67
68
  * `compile` cannot disagree about where the library is — they did, and a library
68
- * written by `pull` was invisible to the SDK's own compile.
69
+ * written by `pull` was invisible to the SDK's own compile. An empty
70
+ * FLOW_SDK_LIBRARY_JSON is unset, not a library at the working directory.
71
+ *
72
+ * An environment value that names no index gives way to a pulled cache, as
73
+ * `registry pull` reads it: otherwise a stale variable would hide a library on
74
+ * disk, and a missing definition would be fetched beside it. With no cache it is
75
+ * returned as before (the overlay alone, or a host's reader, then answers).
69
76
  */
70
77
  export function resolveLibraryDir(named) {
71
- return named ?? process.env.FLOW_SDK_LIBRARY_JSON ?? resolveCachedLibrary();
78
+ if (named !== undefined)
79
+ return named;
80
+ const env = process.env.FLOW_SDK_LIBRARY_JSON || undefined;
81
+ if (env !== undefined && !hasIndexThroughReader(env))
82
+ return resolveCachedLibrary() ?? env;
83
+ return env ?? resolveCachedLibrary();
84
+ }
85
+ /** Whether `dir` holds an index, through the host's reader when one is set (a library on no disk). */
86
+ function hasIndexThroughReader(dir) {
87
+ try {
88
+ return defaultReadText()(join(dir, "index.json")) !== undefined;
89
+ }
90
+ catch {
91
+ return hasIndex(dir);
92
+ }
72
93
  }
73
94
  /** What `current` points at, for reporting. */
74
95
  export function currentEntrySha(root = libraryCacheRoot()) {
@@ -574,9 +574,9 @@ export declare class Library {
574
574
  * connection (`objectFromDiscovery`), which only `prepare --object` can fill.
575
575
  */
576
576
  private variantMissing;
577
- /** Whether any layer indexes `nodeType` (at `version`, when one is asked for). */
578
577
  /** {@link LibraryOpts.onConnectorMiss}, for a wire of `connectorKey` no layer could identify. */
579
578
  private noteConnectorMiss;
579
+ /** Whether any layer indexes `nodeType` (at `version`, when one is asked for). */
580
580
  private carries;
581
581
  /** The connector key is in no entry at all. */
582
582
  private noConnector;
@@ -25,6 +25,8 @@ export { ConnectorResolveError } from './connector-resolve-error.js';
25
25
  * as prepared.
26
26
  */
27
27
  export const FETCHED_PROVENANCE = 'uip-fetch';
28
+ /** The closing advice of a miss's description, which a caller's `missNote` replaces. */
29
+ const PULL_ADVICE = / If the (?:operation|connector|event) is newer than the library, refresh it with `[^`]+`\./;
28
30
  export class Library {
29
31
  layers = [];
30
32
  /** The LIST-ENVELOPE LEDGER, overlay first so a prepared entry can add a row. */
@@ -780,9 +782,12 @@ export class Library {
780
782
  + `the library index (\`index.json\`), and remember the two namespaces: `
781
783
  + `\`…connector.trigger.…\` starts a flow, \`…connector.event.…\` waits mid-flow.`
782
784
  : '';
785
+ // A caller's note says why it is missing (the tenant does not serve it, uip
786
+ // cannot be asked, merge hides it): it replaces the advice to pull, which
787
+ // cannot help there.
788
+ const described = this.describeMiss(nodeType, version, objectName);
783
789
  throw new ConnectorResolveError('CONNECTOR_NOT_IN_LIBRARY', `connector not in library: ${nodeType}${version ? '@' + version : ''}.${hint}`
784
- + this.describeMiss(nodeType, version, objectName)
785
- + (note ? ` ${note}` : ''));
790
+ + (note ? `${described.replace(PULL_ADVICE, '')} ${note}` : described));
786
791
  }
787
792
  /**
788
793
  * Turn a lookup miss into something actionable: which operations this connector
@@ -852,11 +857,11 @@ export class Library {
852
857
  const wanted = objectName.toLowerCase();
853
858
  return !rows.some((row) => typeof row.objectName === 'string' && row.objectName.toLowerCase() === wanted);
854
859
  }
855
- /** Whether any layer indexes `nodeType` (at `version`, when one is asked for). */
856
860
  /** {@link LibraryOpts.onConnectorMiss}, for a wire of `connectorKey` no layer could identify. */
857
861
  noteConnectorMiss(connectorKey) {
858
862
  this.onConnectorMiss?.(connectorKey);
859
863
  }
864
+ /** Whether any layer indexes `nodeType` (at `version`, when one is asked for). */
860
865
  carries(nodeType, version) {
861
866
  return this.layers.some((l) => l.entries.some((e) => e.nodeType === nodeType && (!version || e.version === version)));
862
867
  }
@@ -39,7 +39,7 @@ 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 { flowConnectorRequests } from './registry/fetch/flow-requests.js';
42
+ import { flowConnectorRequests, lackedToken } from './registry/fetch/flow-requests.js';
43
43
  import { openWithFetchedDefinitions } from './registry/fetch/with-fetched-definitions.js';
44
44
  import { fetchableNodeType } from './registry/fetch/fetch-definitions.js';
45
45
  /** Derive a PascalCase base name from the flow name/id for the default output file. */
@@ -102,9 +102,11 @@ export async function run(argv) {
102
102
  // What the library lacked as decompile saw it: those operations are carried
103
103
  // from the file. Recorded in the stamp, so `flow merge` can hide them again and
104
104
  // derive the same source even after they have been fetched (decompile-stamp.ts).
105
+ // Per object: a generic operation held for one object can lack another. With
106
+ // no library at all the stamp says so instead (`no-library`).
105
107
  const lacked = library === undefined ? [] : [...new Set(flowConnectorRequests(flow)
106
- .map((r) => r.nodeType)
107
- .filter((nodeType) => !library.indexes(nodeType) && !library.indexes(fetchableNodeType(nodeType))))].sort();
108
+ .filter((r) => !library.indexes(r.nodeType, r.objectName) && !library.indexes(fetchableNodeType(r.nodeType), r.objectName))
109
+ .map(lackedToken))].sort();
108
110
  const ts = decompileFlowFile(pos, flow, {
109
111
  importSpecifier: flagValue(argv, '--import') ?? PACKAGE_NAME,
110
112
  ...(library ? { library } : {}),
@@ -127,6 +129,7 @@ export async function run(argv) {
127
129
  packages: packages.loaded.map((p) => p.package),
128
130
  lacked,
129
131
  fetch: true,
132
+ noLibrary: library === undefined,
130
133
  });
131
134
  const out = flagValue(argv, '-o') ?? defaultSourceOut(`${baseName(flow)}.flow.ts`);
132
135
  writeSource(out, stamped);
@@ -24,6 +24,13 @@ export interface FlowDecompileStamp {
24
24
  * library such a decompile saw.
25
25
  */
26
26
  fetch: boolean;
27
+ /**
28
+ * The decompile opened no library at all (the `no-library` token): nothing
29
+ * pulled or fetched, and fetching off. Such a decompile writes another source
30
+ * than one whose library lacks an operation, so `flow merge` decompiles the
31
+ * baseline with no library too.
32
+ */
33
+ noLibrary: boolean;
27
34
  }
28
35
  /** The stamp line, without a line terminator. */
29
36
  export declare function formatFlowStamp(stamp: FlowDecompileStamp): string;
@@ -32,6 +32,7 @@ export function formatFlowStamp(stamp) {
32
32
  ...(stamp.packages.length > 0 ? [`packages=${stamp.packages.join(',')}`] : []),
33
33
  ...(stamp.lacked.length > 0 ? [`lacked=${stamp.lacked.join(',')}`] : []),
34
34
  ...(stamp.fetch ? ['fetch'] : []),
35
+ ...(stamp.noLibrary ? ['no-library'] : []),
35
36
  ],
36
37
  });
37
38
  }
@@ -51,7 +52,7 @@ export function readFlowStamp(source) {
51
52
  if (read === undefined || 'error' in read)
52
53
  return read;
53
54
  const { line } = read;
54
- const stamp = { file: read.file, sha256: read.sha256, scripts: 'function', strict: false, packages: [], lacked: [], fetch: false };
55
+ const stamp = { file: read.file, sha256: read.sha256, scripts: 'function', strict: false, packages: [], lacked: [], fetch: false, noLibrary: false };
55
56
  const seen = new Set();
56
57
  for (const token of read.options) {
57
58
  const [key, value] = token.split('=', 2);
@@ -68,6 +69,8 @@ export function readFlowStamp(source) {
68
69
  stamp.lacked = value.split(',');
69
70
  else if (key === 'fetch' && value === undefined)
70
71
  stamp.fetch = true;
72
+ else if (key === 'no-library' && value === undefined)
73
+ stamp.noLibrary = true;
71
74
  else
72
75
  return { error: `unknown option \`${token}\`: ${line}` };
73
76
  }