@uipath/maestro-builder-sdk 6.105.1 → 6.107.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 +13 -2
- package/dist/api-index.md +34 -33
- package/dist/api-members.md +101 -99
- package/dist/build-cli.d.ts +3 -0
- package/dist/build-cli.js +192 -0
- package/dist/cli/commands/flow.js +29 -0
- package/dist/cli-result.d.ts +5 -0
- package/dist/cli-result.js +7 -0
- package/dist/compile-cli.js +14 -0
- package/dist/core/refusals.d.ts +1 -0
- package/dist/core/refusals.js +1 -0
- package/dist/decompile.js +78 -33
- package/dist/flow-output-backing.d.ts +1 -0
- package/dist/flow-output-backing.js +1 -1
- package/dist/flow-sdk.d.ts +15 -0
- package/dist/flow-sdk.js +6 -0
- package/dist/flow-types.d.ts +10 -5
- package/dist/flow-types.js +10 -5
- package/dist/flow-variables.d.ts +4 -0
- package/dist/flow-variables.js +5 -1
- package/dist/merge-cli.js +14 -1
- package/dist/project-flows.d.ts +40 -0
- package/dist/project-flows.js +136 -0
- package/dist/serialize.js +15 -7
- package/package.json +5 -3
|
@@ -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);
|
|
@@ -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')
|
package/dist/cli-result.d.ts
CHANGED
|
@@ -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`.
|
package/dist/cli-result.js
CHANGED
|
@@ -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`.
|
package/dist/compile-cli.js
CHANGED
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
* other draft, such as one an agent just wrote (even of an operation the canvas
|
|
21
21
|
* has a draft of), is refused.
|
|
22
22
|
*
|
|
23
|
+
* Writing into a Flow project (`project.uiproj` at or above the output) that
|
|
24
|
+
* already holds another `.flow` below it, outside dot-folders, warns
|
|
25
|
+
* `SECOND_FLOW_IN_PROJECT` (project-flows.ts): `uip` or a reader that globs the
|
|
26
|
+
* project can take it for the project's flow.
|
|
27
|
+
*
|
|
23
28
|
* `--no-check` is a deprecated no-op: it is accepted for one minor version, with
|
|
24
29
|
* a warning, and then removed.
|
|
25
30
|
*/
|
|
@@ -43,6 +48,7 @@ import { flowSources, projectMainFlow, resourceSourcesOfOtherFlows } from './pro
|
|
|
43
48
|
import { fnv1aX4Uuid } from './core/stable-id.js';
|
|
44
49
|
import { cliSpelling } from './core/cli-spelling.js';
|
|
45
50
|
import { readNodeCatalog } from './node-catalog-files.js';
|
|
51
|
+
import { secondFlowWarning } from './project-flows.js';
|
|
46
52
|
/** An agent folder name: a uuid, any case. */
|
|
47
53
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
48
54
|
export async function run(argv) {
|
|
@@ -201,6 +207,14 @@ export async function run(argv) {
|
|
|
201
207
|
reportDiagnostics(diagnostics);
|
|
202
208
|
return 1;
|
|
203
209
|
}
|
|
210
|
+
// A second `.flow` in the Flow project, outside dot-folders (a backup, a
|
|
211
|
+
// baseline/ compile), is one `uip` or a globbing reader can take for the
|
|
212
|
+
// project's (#1996). Said here, where the `.flow` is written; never fatal.
|
|
213
|
+
const second = secondFlowWarning(out);
|
|
214
|
+
if (second !== undefined) {
|
|
215
|
+
console.error(` ${diagnosticLine(second)}`);
|
|
216
|
+
diagnostics.push(second);
|
|
217
|
+
}
|
|
204
218
|
// Reported before the first write, so a write that throws still carries it.
|
|
205
219
|
reportDiagnostics(diagnostics);
|
|
206
220
|
writeJsonFile(out, flowJson);
|
package/dist/core/refusals.d.ts
CHANGED
|
@@ -281,6 +281,7 @@ export declare const REFUSALS: {
|
|
|
281
281
|
readonly DATAFABRIC_UNKNOWN_FIELD: "lint";
|
|
282
282
|
readonly DEAD_END: "lint";
|
|
283
283
|
readonly DECLARATION_SHAPE: "lowering";
|
|
284
|
+
readonly DECLARATION_FORMAT_INVALID: "lowering";
|
|
284
285
|
readonly DECLARATION_TYPE_NOT_FLOW: "lowering";
|
|
285
286
|
readonly DECLARATION_TYPE_UNKNOWN: "lowering";
|
|
286
287
|
readonly DECOMPILE_NOT_A_NUMBER: "lowering";
|
package/dist/core/refusals.js
CHANGED
|
@@ -355,6 +355,7 @@ export const REFUSALS = {
|
|
|
355
355
|
DATAFABRIC_UNKNOWN_FIELD: 'lint',
|
|
356
356
|
DEAD_END: 'lint',
|
|
357
357
|
DECLARATION_SHAPE: 'lowering',
|
|
358
|
+
DECLARATION_FORMAT_INVALID: 'lowering',
|
|
358
359
|
DECLARATION_TYPE_NOT_FLOW: 'lowering',
|
|
359
360
|
DECLARATION_TYPE_UNKNOWN: 'lowering',
|
|
360
361
|
DECOMPILE_NOT_A_NUMBER: 'lowering',
|
package/dist/decompile.js
CHANGED
|
@@ -40,7 +40,7 @@ import { tsKey as key, tsLiteral, tsNumber, tsObject as objLit, tsOptions as opt
|
|
|
40
40
|
import { wireExprBody } from './core/wire-expr.js';
|
|
41
41
|
import { hasExits } from './core/step-ports.js';
|
|
42
42
|
import { readFlowGlobals } from './flow-variables.js';
|
|
43
|
-
import { FLOW_TYPE_NAMES,
|
|
43
|
+
import { FLOW_TYPE_NAMES, runtimeEquivalentFlowType } from './flow-types.js';
|
|
44
44
|
import { outputBackingGlobal, outputBackingName } from './flow-output-backing.js';
|
|
45
45
|
import { mapJsCode } from './core/js-code-spans.js';
|
|
46
46
|
import { VARS_READ_RE } from './core/vars-read.js';
|
|
@@ -1222,61 +1222,106 @@ function camel(id) {
|
|
|
1222
1222
|
// ─── Variables ────────────────────────────────────────────────────────────────
|
|
1223
1223
|
const TYPE_NAMES = new Set(FLOW_TYPE_NAMES);
|
|
1224
1224
|
/**
|
|
1225
|
-
* `types.<name>` for a global's type (#861).
|
|
1225
|
+
* `types.<name>` for a global's type (#861, #1997).
|
|
1226
1226
|
*
|
|
1227
|
-
* A Flow type prints as itself.
|
|
1228
|
-
*
|
|
1227
|
+
* A Flow type prints as itself. The Case-only types print as the Flow type
|
|
1228
|
+
* the run already sees, so an untouched global never blocks a brownfield
|
|
1229
|
+
* edit:
|
|
1230
|
+
* - `float` / `double` print as `{ type: types.number, format: 'double' }`
|
|
1231
|
+
* (`VarSpec.format`), which recompiles to the file's own `"type":"double"`.
|
|
1232
|
+
* Nothing changes, so nothing warns. The width matters: `flow pack` writes
|
|
1233
|
+
* it into the entry point's schema as `"format":"double"`.
|
|
1229
1234
|
* - `date` / `datetime` print as `types.string`, the type Flow packaging
|
|
1230
|
-
* already gives them
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1237
|
-
*/
|
|
1238
|
-
function
|
|
1235
|
+
* already gives them. The recompiled `.flow` says `"type":"string"`.
|
|
1236
|
+
* - `jsonSchema` prints as `types.object` (`types.array` when its schema is
|
|
1237
|
+
* an array's) with the file's schema (its `body`, else `schema`, as `flow pack` reads them) in
|
|
1238
|
+
* `{ schema }`. The recompiled `.flow` says `"type":"object"`.
|
|
1239
|
+
* A type that changes warns once per variable (an error when `bestEffort` is
|
|
1240
|
+
* false), naming what the recompile writes. Any other string prints as a
|
|
1241
|
+
* string literal: `DECLARATION_TYPE_UNKNOWN`.
|
|
1242
|
+
*/
|
|
1243
|
+
function printedType(g) {
|
|
1239
1244
|
if (TYPE_NAMES.has(g.type))
|
|
1240
|
-
return
|
|
1241
|
-
|
|
1242
|
-
|
|
1245
|
+
return { type: g.type };
|
|
1246
|
+
if (g.type === 'float' || g.type === 'double')
|
|
1247
|
+
return { type: 'number', format: g.type };
|
|
1243
1248
|
const head = `variable ${tsLiteral(g.id)} has type ${tsLiteral(g.type)}`;
|
|
1244
|
-
const
|
|
1245
|
-
|
|
1249
|
+
const equivalent = runtimeEquivalentFlowType(g.type);
|
|
1250
|
+
let printed;
|
|
1251
|
+
let message;
|
|
1252
|
+
if (equivalent !== undefined) {
|
|
1253
|
+
printed = { type: equivalent };
|
|
1254
|
+
message = `${head}, a Case type Flow does not model. The source declares it types.${equivalent}, so a recompile `
|
|
1246
1255
|
+ `writes "type":"${equivalent}" in its place; nothing changes at run time, because flow pack already `
|
|
1247
|
-
+ `writes a ${g.type} as a plain string
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1256
|
+
+ `writes a ${g.type} as a plain string.`;
|
|
1257
|
+
}
|
|
1258
|
+
else if (g.type === 'jsonSchema') {
|
|
1259
|
+
const schema = jsonSchemaBody(g);
|
|
1260
|
+
const kind = schema?.type === 'array' ? 'array' : 'object';
|
|
1261
|
+
printed = { type: kind, ...(schema !== undefined ? { schema } : {}) };
|
|
1262
|
+
message = `${head}, a Case type Flow does not model. The source declares it types.${kind}`
|
|
1263
|
+
+ `${schema !== undefined ? ' with its schema in { schema }' : ''}, so a recompile writes "type":"${kind}" in its `
|
|
1264
|
+
+ `place; nothing changes at run time, because the engine reads both as JSON.`;
|
|
1265
|
+
}
|
|
1266
|
+
else {
|
|
1267
|
+
printed = { type: g.type };
|
|
1268
|
+
message = `${head}, which is not a Flow type. The source keeps it as a string, which the builder refuses `
|
|
1269
|
+
+ `(DECLARATION_TYPE_UNKNOWN): declare one of ${FLOW_TYPE_NAMES.map((t) => `types.${t}`).join(', ')}.`;
|
|
1270
|
+
}
|
|
1253
1271
|
if (runStrict)
|
|
1254
1272
|
throw new Error(`decompile: ${message}`);
|
|
1255
1273
|
warnOnce(message);
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1274
|
+
return printed;
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* A `jsonSchema` global's shape: the `body` Case writes it in (an object, or
|
|
1278
|
+
* that object as JSON text), else its `schema`. `undefined` when it has
|
|
1279
|
+
* neither. `body` first, because `flow pack` packs `body ?? schema`
|
|
1280
|
+
* (flow-workbench `variableToJsonSchema`), so the recompiled entry point packs
|
|
1281
|
+
* the shape the original did.
|
|
1282
|
+
*/
|
|
1283
|
+
function jsonSchemaBody(g) {
|
|
1284
|
+
const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
1285
|
+
const fromBody = (body) => {
|
|
1286
|
+
if (isObject(body))
|
|
1287
|
+
return body;
|
|
1288
|
+
if (typeof body !== 'string')
|
|
1289
|
+
return undefined;
|
|
1290
|
+
try {
|
|
1291
|
+
const parsed = JSON.parse(body);
|
|
1292
|
+
return isObject(parsed) ? parsed : undefined;
|
|
1293
|
+
}
|
|
1294
|
+
catch {
|
|
1295
|
+
return undefined;
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
return fromBody(g.body) ?? (isObject(g.schema) ? g.schema : undefined);
|
|
1259
1299
|
}
|
|
1260
1300
|
/**
|
|
1261
1301
|
* A global carrying metadata decompiles to the rich VarSpec spelling
|
|
1262
|
-
* (`{ type: types.x, description, subType, schema }`); a bare one
|
|
1263
|
-
* compact `name: types.x` form.
|
|
1302
|
+
* (`{ type: types.x, format, description, subType, schema }`); a bare one
|
|
1303
|
+
* keeps the compact `name: types.x` form.
|
|
1264
1304
|
*/
|
|
1265
1305
|
function declExpr(g, withDefault, imp, shared) {
|
|
1306
|
+
const printed = printedType(g);
|
|
1307
|
+
const type = TYPE_NAMES.has(printed.type) ? `${imp.use('types')}.${printed.type}` : tsLiteral(printed.type);
|
|
1308
|
+
const schema = printed.schema ?? g.schema;
|
|
1266
1309
|
const meta = [];
|
|
1310
|
+
if (printed.format !== undefined)
|
|
1311
|
+
meta.push(`format: ${tsLiteral(printed.format)}`);
|
|
1267
1312
|
if (withDefault && g.defaultValue !== undefined)
|
|
1268
1313
|
meta.push(`default: ${tsLiteral(g.defaultValue)}`);
|
|
1269
1314
|
if (g.description !== undefined)
|
|
1270
1315
|
meta.push(`description: ${tsLiteral(g.description)}`);
|
|
1271
1316
|
if (g.subType !== undefined)
|
|
1272
1317
|
meta.push(`subType: ${tsLiteral(g.subType)}`);
|
|
1273
|
-
if (
|
|
1274
|
-
meta.push(`schema: ${tsLiteral(
|
|
1318
|
+
if (schema !== undefined)
|
|
1319
|
+
meta.push(`schema: ${tsLiteral(schema)}`);
|
|
1275
1320
|
if (shared !== undefined)
|
|
1276
1321
|
meta.push(`shared: ${tsLiteral(shared)}`);
|
|
1277
1322
|
if (meta.length === 0)
|
|
1278
|
-
return
|
|
1279
|
-
return `{ type: ${
|
|
1323
|
+
return type;
|
|
1324
|
+
return `{ type: ${type}, ${meta.join(', ')} }`;
|
|
1280
1325
|
}
|
|
1281
1326
|
function sharedCopies(flow, triggers) {
|
|
1282
1327
|
const globals = readFlowGlobals(flow.variables, runStrict);
|
|
@@ -67,6 +67,7 @@ export declare function planOutputBacking(built: Pick<BuiltFlow, 'inputs' | 'ste
|
|
|
67
67
|
export declare function outputBackingGlobal(o: {
|
|
68
68
|
name: string;
|
|
69
69
|
type: string;
|
|
70
|
+
format?: string;
|
|
70
71
|
default?: unknown;
|
|
71
72
|
subType?: string;
|
|
72
73
|
schema?: Record<string, unknown>;
|
|
@@ -221,7 +221,7 @@ export function planOutputBacking(built, outputs, vars, sharedOutputs = new Set(
|
|
|
221
221
|
/** The `inout` global that backs output `o`: its type and value metadata, no description. */
|
|
222
222
|
export function outputBackingGlobal(o, id) {
|
|
223
223
|
return {
|
|
224
|
-
id, name: id, direction: 'inout', type: o.type,
|
|
224
|
+
id, name: id, direction: 'inout', type: o.format ?? o.type,
|
|
225
225
|
...(o.default !== undefined ? { defaultValue: o.default } : {}),
|
|
226
226
|
...(o.subType !== undefined ? { subType: o.subType } : {}),
|
|
227
227
|
...(o.schema !== undefined ? { schema: o.schema } : {}),
|
package/dist/flow-sdk.d.ts
CHANGED
|
@@ -74,9 +74,13 @@ export interface VarDecl {
|
|
|
74
74
|
subType?: string;
|
|
75
75
|
/** JSON schema for complex type validation (object/array shapes). */
|
|
76
76
|
schema?: Record<string, unknown>;
|
|
77
|
+
/** A `number`'s width, written as the global's `type`. See {@link VarSpec.format}. */
|
|
78
|
+
format?: NumberFormat;
|
|
77
79
|
/** Inputs only: the flow variable this root's input is copied into when the root fires. See {@link VarSpec.shared}. */
|
|
78
80
|
shared?: string;
|
|
79
81
|
}
|
|
82
|
+
/** The widths a `types.number` variable may keep: {@link VarSpec.format}. */
|
|
83
|
+
export type NumberFormat = 'float' | 'double';
|
|
80
84
|
/**
|
|
81
85
|
* The rich spelling of a variable declaration: pass it instead of a bare
|
|
82
86
|
* `types.*` descriptor wherever `.input()` / `.output()` / `.var()` take one,
|
|
@@ -93,6 +97,17 @@ export interface VarSpec {
|
|
|
93
97
|
subType?: string;
|
|
94
98
|
/** JSON schema for complex type validation (object/array shapes). */
|
|
95
99
|
schema?: Record<string, unknown>;
|
|
100
|
+
/**
|
|
101
|
+
* `types.number` only: keep a `float` or `double` width the `.flow` already
|
|
102
|
+
* carries. The global is written `"type":"double"` instead of `"number"`, and
|
|
103
|
+
* `flow pack` puts `{ "type": "number", "format": "double" }` in the entry
|
|
104
|
+
* point's schema. The run is the same either way: the engine reads every
|
|
105
|
+
* number as a double. Decompile prints it for a global a Case-era or Studio
|
|
106
|
+
* Web file typed `float` / `double`, so a recompile writes the file's own type
|
|
107
|
+
* back, e.g. `.input({ rate: { type: types.number, format: 'double' } })`.
|
|
108
|
+
* Any other type, or another value, is `DECLARATION_FORMAT_INVALID`.
|
|
109
|
+
*/
|
|
110
|
+
format?: NumberFormat;
|
|
96
111
|
/**
|
|
97
112
|
* Default value — the variable's value before anything assigns it. On an
|
|
98
113
|
* output it is the starting value a `{ updates }` accumulator reads, e.g.
|
package/dist/flow-sdk.js
CHANGED
|
@@ -91,6 +91,10 @@ function varDeclOf(method, name, value) {
|
|
|
91
91
|
if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
|
|
92
92
|
const spec = value;
|
|
93
93
|
assertType(method, name, spec.type);
|
|
94
|
+
if (spec.format !== undefined && (spec.type !== 'number' || !NUMBER_FORMATS.includes(spec.format))) {
|
|
95
|
+
throw new CompileRefusal('DECLARATION_FORMAT_INVALID', `.${method}() declared ${JSON.stringify(name)} with format ${JSON.stringify(spec.format)} on types.${String(spec.type)}. `
|
|
96
|
+
+ `A format keeps a number's width: use { type: types.number, format: 'float' } or 'double', or drop it.`);
|
|
97
|
+
}
|
|
94
98
|
if (spec.shared !== undefined) {
|
|
95
99
|
if (method !== 'input') {
|
|
96
100
|
throw new CompileRefusal('SHARED_INPUT_NOT_INPUT', `.${method}() declared ${JSON.stringify(name)} with { shared }, which only an input takes: it names `
|
|
@@ -108,6 +112,7 @@ function varDeclOf(method, name, value) {
|
|
|
108
112
|
...(spec.description !== undefined ? { description: spec.description } : {}),
|
|
109
113
|
...(spec.subType !== undefined ? { subType: spec.subType } : {}),
|
|
110
114
|
...(spec.schema !== undefined ? { schema: spec.schema } : {}),
|
|
115
|
+
...(spec.format !== undefined ? { format: spec.format } : {}),
|
|
111
116
|
...(spec.shared !== undefined ? { shared: spec.shared } : {}),
|
|
112
117
|
};
|
|
113
118
|
}
|
|
@@ -135,6 +140,7 @@ function assertType(method, name, type) {
|
|
|
135
140
|
throw new CompileRefusal('DECLARATION_TYPE_UNKNOWN', `.${method}() declared ${JSON.stringify(name)} with type ${JSON.stringify(type)}, which is not `
|
|
136
141
|
+ `a type. Use one of ${flowTypes}.`);
|
|
137
142
|
}
|
|
143
|
+
const NUMBER_FORMATS = ['float', 'double'];
|
|
138
144
|
export function onEvent(a, opts) {
|
|
139
145
|
return builtinTriggerSpec({ kind: 'event', subscription: subscriptionFrom(a, opts) });
|
|
140
146
|
}
|
package/dist/flow-types.d.ts
CHANGED
|
@@ -22,7 +22,10 @@ import type { TypeDesc } from './core/expr.js';
|
|
|
22
22
|
*
|
|
23
23
|
* The others are Case-only. Packaging turns `date` / `datetime` into a plain
|
|
24
24
|
* `string` with no format, the expression model types `float` / `double` /
|
|
25
|
-
* `jsonSchema` as `any`, and no Flow editor offers any of them.
|
|
25
|
+
* `jsonSchema` as `any`, and no Flow editor offers any of them. One thing is
|
|
26
|
+
* kept: packaging writes a `float` / `double` global as `"type":"number"` with
|
|
27
|
+
* `"format":"float"` / `"double"` in the entry point's schema, so a Flow
|
|
28
|
+
* number may carry that width as `{ type: types.number, format }`.
|
|
26
29
|
*
|
|
27
30
|
* `satisfies Record<TypeDesc, …>` makes this exhaustive: adding a type to
|
|
28
31
|
* `types` without deciding whether Flow takes it is a compile error here.
|
|
@@ -36,8 +39,8 @@ declare const flowTypeSupport: {
|
|
|
36
39
|
readonly file: true;
|
|
37
40
|
readonly any: true;
|
|
38
41
|
readonly integer: true;
|
|
39
|
-
readonly float: "types.number";
|
|
40
|
-
readonly double: "types.number";
|
|
42
|
+
readonly float: "{ type: types.number, format: 'float' }";
|
|
43
|
+
readonly double: "{ type: types.number, format: 'double' }";
|
|
41
44
|
readonly date: "types.string";
|
|
42
45
|
readonly datetime: "types.string";
|
|
43
46
|
readonly jsonSchema: "types.object or types.array, with its shape in { schema }";
|
|
@@ -65,8 +68,10 @@ export declare function nonFlowTypeReplacement(type: string): string | undefined
|
|
|
65
68
|
* older SDK or Studio Web wrote still round-trips; the recompile writes
|
|
66
69
|
* `"type":"string"`, which the decompile warning announces.
|
|
67
70
|
*
|
|
68
|
-
* `undefined` for every other type
|
|
69
|
-
* `
|
|
71
|
+
* `undefined` for every other type. Decompile prints `float` / `double` as
|
|
72
|
+
* `{ type: types.number, format }` (`VarSpec.format`), which writes the same
|
|
73
|
+
* type back, and `jsonSchema` as `types.object` / `types.array` with the
|
|
74
|
+
* shape in `{ schema }`.
|
|
70
75
|
*/
|
|
71
76
|
export declare function runtimeEquivalentFlowType(type: string): FlowTypeDesc | undefined;
|
|
72
77
|
export {};
|
package/dist/flow-types.js
CHANGED
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
*
|
|
12
12
|
* The others are Case-only. Packaging turns `date` / `datetime` into a plain
|
|
13
13
|
* `string` with no format, the expression model types `float` / `double` /
|
|
14
|
-
* `jsonSchema` as `any`, and no Flow editor offers any of them.
|
|
14
|
+
* `jsonSchema` as `any`, and no Flow editor offers any of them. One thing is
|
|
15
|
+
* kept: packaging writes a `float` / `double` global as `"type":"number"` with
|
|
16
|
+
* `"format":"float"` / `"double"` in the entry point's schema, so a Flow
|
|
17
|
+
* number may carry that width as `{ type: types.number, format }`.
|
|
15
18
|
*
|
|
16
19
|
* `satisfies Record<TypeDesc, …>` makes this exhaustive: adding a type to
|
|
17
20
|
* `types` without deciding whether Flow takes it is a compile error here.
|
|
@@ -25,8 +28,8 @@ const flowTypeSupport = {
|
|
|
25
28
|
file: true,
|
|
26
29
|
any: true,
|
|
27
30
|
integer: true,
|
|
28
|
-
float:
|
|
29
|
-
double:
|
|
31
|
+
float: "{ type: types.number, format: 'float' }",
|
|
32
|
+
double: "{ type: types.number, format: 'double' }",
|
|
30
33
|
date: 'types.string',
|
|
31
34
|
datetime: 'types.string',
|
|
32
35
|
jsonSchema: 'types.object or types.array, with its shape in { schema }',
|
|
@@ -54,8 +57,10 @@ export function nonFlowTypeReplacement(type) {
|
|
|
54
57
|
* older SDK or Studio Web wrote still round-trips; the recompile writes
|
|
55
58
|
* `"type":"string"`, which the decompile warning announces.
|
|
56
59
|
*
|
|
57
|
-
* `undefined` for every other type
|
|
58
|
-
* `
|
|
60
|
+
* `undefined` for every other type. Decompile prints `float` / `double` as
|
|
61
|
+
* `{ type: types.number, format }` (`VarSpec.format`), which writes the same
|
|
62
|
+
* type back, and `jsonSchema` as `types.object` / `types.array` with the
|
|
63
|
+
* shape in `{ schema }`.
|
|
59
64
|
*/
|
|
60
65
|
export function runtimeEquivalentFlowType(type) {
|
|
61
66
|
return type === 'date' || type === 'datetime' ? 'string' : undefined;
|
package/dist/flow-variables.d.ts
CHANGED
|
@@ -93,6 +93,8 @@ export interface SharedInputFeed {
|
|
|
93
93
|
export interface SharedInputTarget {
|
|
94
94
|
name: string;
|
|
95
95
|
type: string;
|
|
96
|
+
/** An `auto` target's number width, from the first input feeding it. */
|
|
97
|
+
format?: string;
|
|
96
98
|
/** What declares it: an explicit `.var()` / `.output()`, or the SDK (`auto`). */
|
|
97
99
|
declaredAs: 'var' | 'output' | 'auto';
|
|
98
100
|
hasDefault: boolean;
|
|
@@ -112,12 +114,14 @@ export interface SharedInputsPlan {
|
|
|
112
114
|
autoVars: {
|
|
113
115
|
name: string;
|
|
114
116
|
type: string;
|
|
117
|
+
format?: string;
|
|
115
118
|
}[];
|
|
116
119
|
problems: SharedInputsProblem[];
|
|
117
120
|
}
|
|
118
121
|
/** The `{ shared }` slice of an input declaration. */
|
|
119
122
|
interface SharedCapable extends DeclaredVariable {
|
|
120
123
|
shared?: string;
|
|
124
|
+
format?: string;
|
|
121
125
|
}
|
|
122
126
|
/**
|
|
123
127
|
* Plan the variables that root inputs feed with `{ shared: '<var>' }`.
|