@sequenceholdings/studio-cli 0.1.26 → 0.1.28
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 +265 -81
- package/dist/app/adapters.d.ts +9 -0
- package/dist/app/adapters.js +176 -0
- package/dist/app/commands.d.ts +2 -2
- package/dist/app/commands.js +98 -22
- package/dist/app/deploy.d.ts +9 -10
- package/dist/app/deploy.js +83 -141
- package/dist/app/graph.d.ts +15 -0
- package/dist/app/graph.js +36 -0
- package/dist/app/manifest-validation.d.ts +16 -0
- package/dist/app/manifest-validation.js +99 -0
- package/dist/app/manifest.d.ts +27 -9
- package/dist/app/manifest.js +23 -107
- package/dist/app/paths.d.ts +14 -0
- package/dist/app/paths.js +77 -0
- package/dist/app/primitive-scaffold.d.ts +18 -0
- package/dist/app/primitive-scaffold.js +136 -0
- package/dist/app/readme.d.ts +4 -18
- package/dist/app/readme.js +107 -229
- package/dist/app/run-deployment.d.ts +8 -0
- package/dist/app/run-deployment.js +50 -0
- package/dist/app/scaffold-files.d.ts +13 -0
- package/dist/app/scaffold-files.js +68 -0
- package/dist/app/scaffold.d.ts +11 -3
- package/dist/app/scaffold.js +77 -245
- package/dist/app/workspace-compile.d.ts +18 -0
- package/dist/app/workspace-compile.js +143 -0
- package/dist/app/workspace-model.d.ts +70 -0
- package/dist/app/workspace-model.js +159 -0
- package/dist/app/workspace-scaffold.d.ts +27 -0
- package/dist/app/workspace-scaffold.js +126 -0
- package/dist/app/workspace.d.ts +14 -0
- package/dist/app/workspace.js +147 -0
- package/dist/atlas-client.js +28 -6
- package/dist/auth-cmds/commands.d.ts +1 -1
- package/dist/auth-cmds/commands.js +5 -2
- package/dist/functions/commands.js +7 -1
- package/dist/functions/manifest.d.ts +18 -0
- package/dist/functions/manifest.js +29 -4
- package/dist/main.js +9 -4
- package/dist/orm/delegate.js +30 -23
- package/dist/pat-hints.js +1 -0
- package/dist/pipeline/commands.js +27 -9
- package/dist/pipeline/lifecycle.d.ts +2 -0
- package/dist/pipeline/lifecycle.js +91 -11
- package/dist/process/build.js +59 -43
- package/dist/process/codegen.d.ts +3 -2
- package/dist/process/codegen.js +143 -27
- package/dist/process/commands.d.ts +2 -0
- package/dist/process/commands.js +63 -18
- package/dist/process/discover.d.ts +6 -3
- package/dist/process/discover.js +11 -3
- package/dist/process/lint.d.ts +14 -0
- package/dist/process/lint.js +143 -5
- package/dist/process/plan-diff.d.ts +8 -0
- package/dist/process/plan-diff.js +61 -4
- package/dist/process/safety-baseline.d.ts +154 -0
- package/dist/process/safety-baseline.js +387 -0
- package/dist/process/simulate.js +64 -22
- package/dist/repos/commands.d.ts +1 -1
- package/dist/repos/commands.js +29 -3
- package/package.json +8 -7
package/dist/process/build.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { execSync } from 'node:child_process';
|
|
6
6
|
import { finalizeBundleIdentity, forEachSerializedNode, } from '@sequenceholdings/lattice/bundle';
|
|
7
|
-
import { parseDurationMs, serializeRetryConfig, } from '@sequenceholdings/lattice/define';
|
|
7
|
+
import { isJsonataExpr, parseDurationMs, serializeRetryConfig, } from '@sequenceholdings/lattice/define';
|
|
8
8
|
export async function buildBundleFromProcesses(defs, options) {
|
|
9
9
|
if (defs.length === 0) {
|
|
10
10
|
throw new Error('no lattice process definitions found in configured roots');
|
|
@@ -84,6 +84,9 @@ function serializeProcess(input) {
|
|
|
84
84
|
...(input.process.tags && input.process.tags.length > 0
|
|
85
85
|
? { tags: input.process.tags }
|
|
86
86
|
: {}),
|
|
87
|
+
...(input.process.input_schema !== undefined
|
|
88
|
+
? { input_schema: input.process.input_schema }
|
|
89
|
+
: {}),
|
|
87
90
|
...(input.process.max_iterations !== undefined
|
|
88
91
|
? { max_iterations: input.process.max_iterations }
|
|
89
92
|
: {}),
|
|
@@ -113,6 +116,20 @@ function serializeProcess(input) {
|
|
|
113
116
|
: {}),
|
|
114
117
|
};
|
|
115
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Emit a mapper slot into node metadata: a function serializes to
|
|
121
|
+
* `<base>_source` (its `Function.toString()`), a `jsonata()` expression to
|
|
122
|
+
* `<base>_expr`. The two forms are mutually exclusive per slot by
|
|
123
|
+
* construction here; registration re-enforces that for hand-built bundles.
|
|
124
|
+
*/
|
|
125
|
+
function serializeMapperSlot(meta, base, value) {
|
|
126
|
+
if (typeof value === 'function') {
|
|
127
|
+
meta[`${base}_source`] = value.toString();
|
|
128
|
+
}
|
|
129
|
+
else if (isJsonataExpr(value)) {
|
|
130
|
+
meta[`${base}_expr`] = value.expr;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
116
133
|
/**
|
|
117
134
|
* Serialize one node definition to its bundle form. Extracted so parallel
|
|
118
135
|
* sub-nodes round-trip through the exact same path as top-level nodes —
|
|
@@ -161,10 +178,7 @@ function serializeNodeMetadata(node) {
|
|
|
161
178
|
if (native.run_as?.service_account) {
|
|
162
179
|
meta.run_as = { service_account: native.run_as.service_account };
|
|
163
180
|
}
|
|
164
|
-
|
|
165
|
-
if (typeof nativeInputMapper === 'function') {
|
|
166
|
-
meta.input_mapper_source = nativeInputMapper.toString();
|
|
167
|
-
}
|
|
181
|
+
serializeMapperSlot(meta, 'input_mapper', native.input);
|
|
168
182
|
return meta;
|
|
169
183
|
}
|
|
170
184
|
case 'agent': {
|
|
@@ -172,6 +186,9 @@ function serializeNodeMetadata(node) {
|
|
|
172
186
|
const meta = {
|
|
173
187
|
agent_id: agent.agent.id,
|
|
174
188
|
};
|
|
189
|
+
if (agent.agent.version !== undefined) {
|
|
190
|
+
meta.agent_version = agent.agent.version;
|
|
191
|
+
}
|
|
175
192
|
if (agent.timeout !== undefined)
|
|
176
193
|
meta.timeout = agent.timeout;
|
|
177
194
|
if (agent.workflowId !== undefined)
|
|
@@ -180,10 +197,11 @@ function serializeNodeMetadata(node) {
|
|
|
180
197
|
meta.on_reset_edge_id = agent.on_reset_edge_id;
|
|
181
198
|
if (agent.bindings)
|
|
182
199
|
meta.bindings = agent.bindings;
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
meta.
|
|
200
|
+
// Per-node service-account override — omitted when unset for hash stability.
|
|
201
|
+
if (agent.run_as?.service_account) {
|
|
202
|
+
meta.run_as = { service_account: agent.run_as.service_account };
|
|
186
203
|
}
|
|
204
|
+
serializeMapperSlot(meta, 'input_mapper', agent.input);
|
|
187
205
|
return meta;
|
|
188
206
|
}
|
|
189
207
|
case 'human': {
|
|
@@ -199,11 +217,13 @@ function serializeNodeMetadata(node) {
|
|
|
199
217
|
meta.complete_label = human.completeLabel;
|
|
200
218
|
if (human.hideTimeoutEdgeFromAdvance)
|
|
201
219
|
meta.hide_timeout_edge_from_advance = true;
|
|
202
|
-
// advance_allowed is
|
|
203
|
-
//
|
|
204
|
-
// hook). Serialize the
|
|
205
|
-
|
|
206
|
-
|
|
220
|
+
// advance_allowed is a static ACL object, a `(ctx) => ACL` mapper, or a
|
|
221
|
+
// jsonata() expression, resolved per-step at entry (the per-branch
|
|
222
|
+
// fan-out assignment hook). Serialize the dynamic forms like the other
|
|
223
|
+
// mapper slots.
|
|
224
|
+
if (typeof human.advance_allowed === 'function' ||
|
|
225
|
+
isJsonataExpr(human.advance_allowed)) {
|
|
226
|
+
serializeMapperSlot(meta, 'advance_allowed_mapper', human.advance_allowed);
|
|
207
227
|
}
|
|
208
228
|
else if (human.advance_allowed) {
|
|
209
229
|
meta.advance_allowed = human.advance_allowed;
|
|
@@ -217,15 +237,15 @@ function serializeNodeMetadata(node) {
|
|
|
217
237
|
if (email === true) {
|
|
218
238
|
meta.email_notification = true;
|
|
219
239
|
}
|
|
220
|
-
else if (typeof email === 'function') {
|
|
240
|
+
else if (typeof email === 'function' || isJsonataExpr(email)) {
|
|
241
|
+
// Bare template forms: a fn or a jsonata() expression IS the "ready"
|
|
242
|
+
// template.
|
|
221
243
|
meta.email_notification = true;
|
|
222
|
-
meta
|
|
244
|
+
serializeMapperSlot(meta, 'email_notification_template', email);
|
|
223
245
|
}
|
|
224
246
|
else if (email && typeof email === 'object') {
|
|
225
247
|
meta.email_notification = true;
|
|
226
|
-
|
|
227
|
-
meta.email_notification_template_source = email.template.toString();
|
|
228
|
-
}
|
|
248
|
+
serializeMapperSlot(meta, 'email_notification_template', email.template);
|
|
229
249
|
if (email.timezone)
|
|
230
250
|
meta.email_notification_timezone = email.timezone;
|
|
231
251
|
if (email.reminders && email.reminders.length > 0) {
|
|
@@ -235,6 +255,7 @@ function serializeNodeMetadata(node) {
|
|
|
235
255
|
...(typeof r.template === 'function'
|
|
236
256
|
? { template_source: r.template.toString() }
|
|
237
257
|
: {}),
|
|
258
|
+
...(isJsonataExpr(r.template) ? { template_expr: r.template.expr } : {}),
|
|
238
259
|
}));
|
|
239
260
|
}
|
|
240
261
|
// Deploy-env allowlist (plain data, no sandboxed fn). Copied so the
|
|
@@ -244,57 +265,52 @@ function serializeNodeMetadata(node) {
|
|
|
244
265
|
meta.email_notification_enabled_environments = [...email.enabledEnvironments];
|
|
245
266
|
}
|
|
246
267
|
}
|
|
247
|
-
// dueDate `(ctx) => Date
|
|
248
|
-
|
|
249
|
-
meta.due_date_source = human.dueDate.toString();
|
|
250
|
-
}
|
|
268
|
+
// dueDate `(ctx) => Date` (or jsonata → ISO string), computed per-run.
|
|
269
|
+
serializeMapperSlot(meta, 'due_date', human.dueDate);
|
|
251
270
|
if (human.bindings)
|
|
252
271
|
meta.bindings = human.bindings;
|
|
253
272
|
if (Array.isArray(human.artifact_refs)) {
|
|
254
273
|
meta.artifact_refs = human.artifact_refs;
|
|
255
274
|
}
|
|
256
|
-
else
|
|
257
|
-
meta
|
|
275
|
+
else {
|
|
276
|
+
serializeMapperSlot(meta, 'artifact_refs_mapper', human.artifact_refs);
|
|
258
277
|
}
|
|
259
278
|
// First-class comment-chain opt-in — packed alongside artifact_refs (NOT
|
|
260
279
|
// inside the author `metadata` bag), so it serializes as its own node
|
|
261
280
|
// field that the inbox/process-activity reads at `node.metadata.comments`.
|
|
262
281
|
if (human.comments)
|
|
263
282
|
meta.comments = human.comments;
|
|
264
|
-
|
|
265
|
-
if (typeof humanInputMapper === 'function') {
|
|
266
|
-
meta.input_mapper_source = humanInputMapper.toString();
|
|
267
|
-
}
|
|
283
|
+
serializeMapperSlot(meta, 'input_mapper', human.input);
|
|
268
284
|
return meta;
|
|
269
285
|
}
|
|
270
286
|
case 'subprocess': {
|
|
271
287
|
const subprocess = node;
|
|
272
|
-
const toSource = (fn) => fn.toString();
|
|
273
288
|
const smeta = {
|
|
274
289
|
process_id: subprocess.process,
|
|
275
290
|
version: subprocess.version ?? '',
|
|
276
291
|
bundle_hash: '',
|
|
277
292
|
on_child_error: subprocess.on_child_error,
|
|
278
|
-
|
|
293
|
+
...(typeof subprocess.output === 'function'
|
|
294
|
+
? { output_mapper_source: subprocess.output.toString() }
|
|
295
|
+
: { output_mapper_expr: subprocess.output.expr }),
|
|
279
296
|
...(subprocess.supervisor_retry !== undefined
|
|
280
297
|
? { supervisor_retry: serializeRetryConfig(subprocess.supervisor_retry) }
|
|
281
298
|
: {}),
|
|
282
299
|
};
|
|
283
300
|
const meta = { subprocess: smeta };
|
|
284
|
-
|
|
285
|
-
meta.input_mapper_source = toSource(subprocess.input);
|
|
286
|
-
}
|
|
301
|
+
serializeMapperSlot(meta, 'input_mapper', subprocess.input);
|
|
287
302
|
if (subprocess.bindings)
|
|
288
303
|
meta.bindings = subprocess.bindings;
|
|
289
304
|
return meta;
|
|
290
305
|
}
|
|
291
306
|
case 'parallel': {
|
|
292
307
|
const parallel = node;
|
|
293
|
-
const toSource = (fn) => fn.toString();
|
|
294
308
|
const pmeta = {
|
|
295
309
|
mode: parallel.branches ? 'static' : 'dynamic',
|
|
296
310
|
on_branch_error: parallel.on_branch_error,
|
|
297
|
-
|
|
311
|
+
...(typeof parallel.join === 'function'
|
|
312
|
+
? { join_source: parallel.join.toString() }
|
|
313
|
+
: { join_expr: parallel.join.expr }),
|
|
298
314
|
};
|
|
299
315
|
// Serialized only when non-default ('eager') so existing barrier
|
|
300
316
|
// bundles keep their hashes; a missing field reads as 'barrier'.
|
|
@@ -314,7 +330,12 @@ function serializeNodeMetadata(node) {
|
|
|
314
330
|
}));
|
|
315
331
|
}
|
|
316
332
|
else {
|
|
317
|
-
|
|
333
|
+
if (typeof parallel.fan_out === 'function') {
|
|
334
|
+
pmeta.fan_out_source = parallel.fan_out.toString();
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
pmeta.fan_out_expr = parallel.fan_out.expr;
|
|
338
|
+
}
|
|
318
339
|
if (parallel.max_fanout !== undefined)
|
|
319
340
|
pmeta.max_fanout = parallel.max_fanout;
|
|
320
341
|
pmeta.branch = serializeNode(parallel.branch);
|
|
@@ -326,9 +347,7 @@ function serializeNodeMetadata(node) {
|
|
|
326
347
|
// executes it and the runner reads the directive from its payload input.
|
|
327
348
|
// (Nesting it under `parallel` left it unread, disabling selective
|
|
328
349
|
// re-run + epoch invalidation entirely.)
|
|
329
|
-
|
|
330
|
-
meta.input_mapper_source = toSource(parallel.input);
|
|
331
|
-
}
|
|
350
|
+
serializeMapperSlot(meta, 'input_mapper', parallel.input);
|
|
332
351
|
if (parallel.bindings)
|
|
333
352
|
meta.bindings = parallel.bindings;
|
|
334
353
|
return meta;
|
|
@@ -360,10 +379,7 @@ function serializeNodeMetadata(node) {
|
|
|
360
379
|
}
|
|
361
380
|
// NOTE: `middleware` (e.g. withRetry) is serialized generically for every
|
|
362
381
|
// node kind in `serializeNode` above — don't duplicate it here.
|
|
363
|
-
|
|
364
|
-
if (typeof inputMapper === 'function') {
|
|
365
|
-
meta.input_mapper_source = inputMapper.toString();
|
|
366
|
-
}
|
|
382
|
+
serializeMapperSlot(meta, 'input_mapper', mf.input);
|
|
367
383
|
return meta;
|
|
368
384
|
}
|
|
369
385
|
default:
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* published from the UI can be pulled back into a local tree.
|
|
5
5
|
*
|
|
6
6
|
* Fidelity notes (the bundle is a compiled artifact, not the original source):
|
|
7
|
-
* -
|
|
8
|
-
*
|
|
7
|
+
* - JS mapper bodies are the build-time `Function.toString()` strings; JSONata
|
|
8
|
+
* mapper expressions are reconstructed as `jsonata('…')`. Both rebuild to
|
|
9
|
+
* the same content-addressed bundle fields.
|
|
9
10
|
* - Automation bodies live in the Atlas image; only the registry id is
|
|
10
11
|
* emitted (`function: '<id>'`).
|
|
11
12
|
* - Co-located subprocess pins (version / bundle_hash) are dropped — they are
|
package/dist/process/codegen.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* published from the UI can be pulled back into a local tree.
|
|
5
5
|
*
|
|
6
6
|
* Fidelity notes (the bundle is a compiled artifact, not the original source):
|
|
7
|
-
* -
|
|
8
|
-
*
|
|
7
|
+
* - JS mapper bodies are the build-time `Function.toString()` strings; JSONata
|
|
8
|
+
* mapper expressions are reconstructed as `jsonata('…')`. Both rebuild to
|
|
9
|
+
* the same content-addressed bundle fields.
|
|
9
10
|
* - Automation bodies live in the Atlas image; only the registry id is
|
|
10
11
|
* emitted (`function: '<id>'`).
|
|
11
12
|
* - Co-located subprocess pins (version / bundle_hash) are dropped — they are
|
|
@@ -49,7 +50,9 @@ export function generateProcessFiles(process, bundle) {
|
|
|
49
50
|
process.max_concurrent_runs !== undefined
|
|
50
51
|
? ` max_concurrent_runs: ${process.max_concurrent_runs},`
|
|
51
52
|
: null,
|
|
52
|
-
process.supervisor_retry !== undefined
|
|
53
|
+
process.supervisor_retry !== undefined
|
|
54
|
+
? ` supervisor_retry: ${retryConfig(process.supervisor_retry, ctx)},`
|
|
55
|
+
: null,
|
|
53
56
|
process.run_as !== undefined
|
|
54
57
|
? ` run_as: { ${[
|
|
55
58
|
process.run_as.email !== undefined ? `email: ${lit(process.run_as.email)}` : null,
|
|
@@ -60,6 +63,9 @@ export function generateProcessFiles(process, bundle) {
|
|
|
60
63
|
.filter((f) => f !== null)
|
|
61
64
|
.join(', ')} },`
|
|
62
65
|
: null,
|
|
66
|
+
process.input_schema !== undefined
|
|
67
|
+
? ` input_schema: ${pretty(process.input_schema, 1)},`
|
|
68
|
+
: null,
|
|
63
69
|
Array.isArray(process.tags) && process.tags.length > 0
|
|
64
70
|
? ` tags: ${pretty(process.tags, 1)},`
|
|
65
71
|
: null,
|
|
@@ -93,13 +99,15 @@ function emitNode(node, ctx) {
|
|
|
93
99
|
ctx.used.add('defineAgentNode');
|
|
94
100
|
return call('defineAgentNode', [
|
|
95
101
|
...head,
|
|
96
|
-
` agent: { id: ${lit(String(m.agent_id))}
|
|
102
|
+
` agent: { id: ${lit(String(m.agent_id))}${m.agent_version !== undefined
|
|
103
|
+
? `, version: ${value(m.agent_version)}`
|
|
104
|
+
: ''} },`,
|
|
97
105
|
m.workflow_id != null ? ` workflowId: ${lit(String(m.workflow_id))},` : null,
|
|
98
106
|
m.on_reset_edge_id != null ? ` on_reset_edge_id: ${lit(String(m.on_reset_edge_id))},` : null,
|
|
99
107
|
m.timeout !== undefined ? ` timeout: ${value(m.timeout)},` : null,
|
|
100
108
|
bindings(m.bindings),
|
|
101
|
-
middleware(m.middleware),
|
|
102
|
-
mapper('input', m.input_mapper_source),
|
|
109
|
+
middleware(m.middleware, ctx),
|
|
110
|
+
mapper('input', m.input_mapper_source, m.input_mapper_expr, ctx),
|
|
103
111
|
tail,
|
|
104
112
|
]);
|
|
105
113
|
}
|
|
@@ -113,13 +121,18 @@ function emitNode(node, ctx) {
|
|
|
113
121
|
m.timeout !== undefined ? ` timeout: ${value(m.timeout)},` : null,
|
|
114
122
|
m.on_timeout_edge_id != null ? ` on_timeout_edge_id: ${lit(String(m.on_timeout_edge_id))},` : null,
|
|
115
123
|
m.hide_timeout_edge_from_advance === true ? ` hideTimeoutEdgeFromAdvance: true,` : null,
|
|
116
|
-
m.
|
|
124
|
+
mapper('advance_allowed', m.advance_allowed_mapper_source, m.advance_allowed_mapper_expr, ctx),
|
|
125
|
+
m.advance_allowed !== undefined
|
|
126
|
+
? ` advance_allowed: ${pretty(m.advance_allowed, 1)},`
|
|
127
|
+
: null,
|
|
117
128
|
m.assignable_to !== undefined ? ` assignable_to: ${pretty(m.assignable_to, 1)},` : null,
|
|
118
129
|
bindings(m.bindings),
|
|
119
130
|
Array.isArray(m.artifact_refs) ? ` artifact_refs: ${pretty(m.artifact_refs, 1)},` : null,
|
|
120
|
-
mapper('artifact_refs', m.artifact_refs_mapper_source),
|
|
131
|
+
mapper('artifact_refs', m.artifact_refs_mapper_source, m.artifact_refs_mapper_expr, ctx),
|
|
121
132
|
m.comments !== undefined ? ` comments: ${pretty(m.comments, 1)},` : null,
|
|
122
|
-
mapper('
|
|
133
|
+
mapper('dueDate', m.due_date_source, m.due_date_expr, ctx),
|
|
134
|
+
emailNotification(m, ctx),
|
|
135
|
+
mapper('input', m.input_mapper_source, m.input_mapper_expr, ctx),
|
|
123
136
|
tail,
|
|
124
137
|
]);
|
|
125
138
|
}
|
|
@@ -136,8 +149,8 @@ function emitNode(node, ctx) {
|
|
|
136
149
|
m.limits !== undefined ? ` limits: ${pretty(m.limits, 1)},` : null,
|
|
137
150
|
runAsField(m.run_as),
|
|
138
151
|
bindings(m.bindings),
|
|
139
|
-
middleware(m.middleware),
|
|
140
|
-
mapper('input', m.input_mapper_source),
|
|
152
|
+
middleware(m.middleware, ctx),
|
|
153
|
+
mapper('input', m.input_mapper_source, m.input_mapper_expr, ctx),
|
|
141
154
|
tail,
|
|
142
155
|
]);
|
|
143
156
|
}
|
|
@@ -150,10 +163,12 @@ function emitNode(node, ctx) {
|
|
|
150
163
|
// Colocated pins re-resolve on rebuild; keep an external target's pin.
|
|
151
164
|
ctx.colocated.has(sub.process_id) ? null : ` version: ${lit(sub.version)},`,
|
|
152
165
|
` on_child_error: ${lit(sub.on_child_error)},`,
|
|
153
|
-
sub.supervisor_retry !== undefined
|
|
166
|
+
sub.supervisor_retry !== undefined
|
|
167
|
+
? ` supervisor_retry: ${retryConfig(sub.supervisor_retry, ctx)},`
|
|
168
|
+
: null,
|
|
154
169
|
bindings(m.bindings),
|
|
155
|
-
mapper('input', m.input_mapper_source),
|
|
156
|
-
|
|
170
|
+
mapper('input', m.input_mapper_source, m.input_mapper_expr, ctx),
|
|
171
|
+
requiredMapper('output', sub.output_mapper_source, sub.output_mapper_expr, ctx, `subprocess node "${node.id}"`),
|
|
157
172
|
tail,
|
|
158
173
|
]);
|
|
159
174
|
}
|
|
@@ -167,8 +182,7 @@ function emitNode(node, ctx) {
|
|
|
167
182
|
.join('\n')}\n ],`);
|
|
168
183
|
}
|
|
169
184
|
else {
|
|
170
|
-
|
|
171
|
-
branchFields.push(` fan_out: ${par.fan_out_source},`);
|
|
185
|
+
branchFields.push(requiredMapper('fan_out', par.fan_out_source, par.fan_out_expr, ctx, `parallel node "${node.id}"`));
|
|
172
186
|
if (par.max_fanout !== undefined)
|
|
173
187
|
branchFields.push(` max_fanout: ${par.max_fanout},`);
|
|
174
188
|
if (par.branch)
|
|
@@ -178,13 +192,15 @@ function emitNode(node, ctx) {
|
|
|
178
192
|
...head,
|
|
179
193
|
...branchFields,
|
|
180
194
|
par.max_concurrency !== undefined ? ` max_concurrency: ${par.max_concurrency},` : null,
|
|
181
|
-
par.supervisor_retry !== undefined
|
|
195
|
+
par.supervisor_retry !== undefined
|
|
196
|
+
? ` supervisor_retry: ${retryConfig(par.supervisor_retry, ctx)},`
|
|
197
|
+
: null,
|
|
182
198
|
bindings(m.bindings),
|
|
183
199
|
` on_branch_error: ${lit(par.on_branch_error)},`,
|
|
184
200
|
// Only 'eager' is ever serialized (barrier is the omitted default).
|
|
185
201
|
par.join_mode === 'eager' ? ` join_mode: ${lit('eager')},` : null,
|
|
186
|
-
|
|
187
|
-
mapper('input', m.input_mapper_source),
|
|
202
|
+
requiredMapper('join', par.join_source, par.join_expr, ctx, `parallel node "${node.id}"`),
|
|
203
|
+
mapper('input', m.input_mapper_source, m.input_mapper_expr, ctx),
|
|
188
204
|
tail,
|
|
189
205
|
]);
|
|
190
206
|
}
|
|
@@ -201,8 +217,8 @@ function emitNode(node, ctx) {
|
|
|
201
217
|
m.limits !== undefined ? ` limits: ${pretty(m.limits, 1)},` : null,
|
|
202
218
|
runAsField(m.run_as),
|
|
203
219
|
bindings(m.bindings),
|
|
204
|
-
middleware(m.middleware),
|
|
205
|
-
mapper('input', m.input_mapper_source),
|
|
220
|
+
middleware(m.middleware, ctx),
|
|
221
|
+
mapper('input', m.input_mapper_source, m.input_mapper_expr, ctx),
|
|
206
222
|
tail,
|
|
207
223
|
];
|
|
208
224
|
return call('defineManagedFunctionNode', fields);
|
|
@@ -227,11 +243,104 @@ function runAsField(runAs) {
|
|
|
227
243
|
return null;
|
|
228
244
|
return ` run_as: { service_account: ${lit(sa)} },`;
|
|
229
245
|
}
|
|
230
|
-
/**
|
|
231
|
-
function mapper(field, source) {
|
|
232
|
-
|
|
246
|
+
/** Inverse of build.ts's serializeMapperSlot for pulled source generation. */
|
|
247
|
+
function mapper(field, source, expr, ctx) {
|
|
248
|
+
const rendered = mapperValue(source, expr, ctx);
|
|
249
|
+
return rendered === null ? null : ` ${field}: ${rendered},`;
|
|
250
|
+
}
|
|
251
|
+
function requiredMapper(field, source, expr, ctx, owner) {
|
|
252
|
+
const rendered = mapperValue(source, expr, ctx);
|
|
253
|
+
if (rendered === null) {
|
|
254
|
+
throw new Error(`codegen: ${owner} has no ${field} mapper`);
|
|
255
|
+
}
|
|
256
|
+
return ` ${field}: ${rendered},`;
|
|
257
|
+
}
|
|
258
|
+
function mapperValue(source, expr, ctx) {
|
|
259
|
+
if (typeof source === 'string' && source.length > 0)
|
|
260
|
+
return source;
|
|
261
|
+
if (typeof expr === 'string' && expr.length > 0) {
|
|
262
|
+
ctx.used.add('jsonata');
|
|
263
|
+
return `jsonata(${lit(expr)})`;
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
function retryConfig(value, ctx, depth = 1) {
|
|
268
|
+
if (!isRecord(value)) {
|
|
269
|
+
throw new Error('codegen: retry config is not an object');
|
|
270
|
+
}
|
|
271
|
+
const fieldIndent = ' '.repeat(depth + 1);
|
|
272
|
+
const closingIndent = ' '.repeat(depth);
|
|
273
|
+
const fields = [
|
|
274
|
+
'maxAttempts',
|
|
275
|
+
'factor',
|
|
276
|
+
'minTimeoutInMs',
|
|
277
|
+
'maxTimeoutInMs',
|
|
278
|
+
'randomize',
|
|
279
|
+
].flatMap((key) => value[key] === undefined
|
|
280
|
+
? []
|
|
281
|
+
: [`${fieldIndent}${lit(key)}: ${pretty(value[key], depth + 1)},`]);
|
|
282
|
+
const retryIf = mapperValue(value.retryIf, value.retryIfExpr, ctx);
|
|
283
|
+
if (retryIf !== null)
|
|
284
|
+
fields.push(`${fieldIndent}retryIf: ${retryIf},`);
|
|
285
|
+
return fields.length === 0
|
|
286
|
+
? '{}'
|
|
287
|
+
: `{\n${fields.join('\n')}\n${closingIndent}}`;
|
|
288
|
+
}
|
|
289
|
+
function emailNotification(metadata, ctx) {
|
|
290
|
+
if (metadata.email_notification !== true)
|
|
233
291
|
return null;
|
|
234
|
-
|
|
292
|
+
const template = mapperValue(metadata.email_notification_template_source, metadata.email_notification_template_expr, ctx);
|
|
293
|
+
const reminders = emailReminders(metadata.email_notification_reminders, ctx);
|
|
294
|
+
const timezone = typeof metadata.email_notification_timezone === 'string'
|
|
295
|
+
? metadata.email_notification_timezone
|
|
296
|
+
: undefined;
|
|
297
|
+
const enabledEnvironments = Array.isArray(metadata.email_notification_enabled_environments)
|
|
298
|
+
? metadata.email_notification_enabled_environments
|
|
299
|
+
: undefined;
|
|
300
|
+
if (timezone === undefined &&
|
|
301
|
+
reminders === null &&
|
|
302
|
+
enabledEnvironments === undefined) {
|
|
303
|
+
return template === null
|
|
304
|
+
? ' emailNotification: true,'
|
|
305
|
+
: ` emailNotification: ${template},`;
|
|
306
|
+
}
|
|
307
|
+
const fields = [
|
|
308
|
+
template === null ? null : ` template: ${template},`,
|
|
309
|
+
timezone === undefined ? null : ` timezone: ${lit(timezone)},`,
|
|
310
|
+
reminders === null ? null : ` reminders: ${reminders},`,
|
|
311
|
+
enabledEnvironments === undefined
|
|
312
|
+
? null
|
|
313
|
+
: ` enabledEnvironments: ${pretty(enabledEnvironments, 2)},`,
|
|
314
|
+
]
|
|
315
|
+
.filter((field) => field !== null)
|
|
316
|
+
.join('\n');
|
|
317
|
+
return ` emailNotification: {\n${fields}\n },`;
|
|
318
|
+
}
|
|
319
|
+
function emailReminders(value, ctx) {
|
|
320
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
321
|
+
return null;
|
|
322
|
+
const reminders = value.map((raw, index) => {
|
|
323
|
+
if (!isRecord(raw)) {
|
|
324
|
+
throw new Error(`codegen: email notification reminder ${index} is not an object`);
|
|
325
|
+
}
|
|
326
|
+
const template = mapperValue(raw.template_source, raw.template_expr, ctx);
|
|
327
|
+
const fields = [
|
|
328
|
+
typeof raw.before === 'string'
|
|
329
|
+
? ` before: ${lit(raw.before)},`
|
|
330
|
+
: null,
|
|
331
|
+
typeof raw.after === 'string'
|
|
332
|
+
? ` after: ${lit(raw.after)},`
|
|
333
|
+
: null,
|
|
334
|
+
template === null ? null : ` template: ${template},`,
|
|
335
|
+
]
|
|
336
|
+
.filter((field) => field !== null)
|
|
337
|
+
.join('\n');
|
|
338
|
+
return ` {\n${fields}\n }`;
|
|
339
|
+
});
|
|
340
|
+
return `[\n${reminders.join(',\n')}\n ]`;
|
|
341
|
+
}
|
|
342
|
+
function isRecord(value) {
|
|
343
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
235
344
|
}
|
|
236
345
|
/** A safely-escaped TS string literal. */
|
|
237
346
|
function lit(value) {
|
|
@@ -260,10 +369,17 @@ function bindings(v) {
|
|
|
260
369
|
return ` bindings: ${pretty(v, 1)},`;
|
|
261
370
|
}
|
|
262
371
|
/** An optional `middleware: [...]` field (node-execution middleware refs). */
|
|
263
|
-
function middleware(v) {
|
|
372
|
+
function middleware(v, ctx) {
|
|
264
373
|
if (!Array.isArray(v) || v.length === 0)
|
|
265
374
|
return null;
|
|
266
|
-
|
|
375
|
+
const refs = v.map((rawRef) => {
|
|
376
|
+
if (!isRecord(rawRef) || rawRef.id !== 'retry' || !isRecord(rawRef.config)) {
|
|
377
|
+
return ` ${pretty(rawRef, 2)}`;
|
|
378
|
+
}
|
|
379
|
+
ctx.used.add('withRetry');
|
|
380
|
+
return ` withRetry(${retryConfig(rawRef.config, ctx, 2)})`;
|
|
381
|
+
});
|
|
382
|
+
return ` middleware: [\n${refs.join(',\n')}\n ],`;
|
|
267
383
|
}
|
|
268
384
|
/** A node id → a valid, readable JS const identifier (camelCase, never a
|
|
269
385
|
* reserved word, always starting with a letter/underscore). */
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
export interface ParsedArgs {
|
|
8
8
|
positional: string[];
|
|
9
9
|
flags: Record<string, string | true>;
|
|
10
|
+
/** All string values for flags supplied more than once; `flags` keeps the last value. */
|
|
11
|
+
repeatedFlags?: Record<string, string[]>;
|
|
10
12
|
}
|
|
11
13
|
export declare function parseArgs(rest: string[]): ParsedArgs;
|
|
12
14
|
export type ProcessSourceSpec = {
|