@elementumai/edk 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +38 -6
  2. package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
  3. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  4. package/dist-sdk/src/engine/coverage-gaps.d.ts +5 -0
  5. package/dist-sdk/src/engine/coverage-gaps.js +9 -0
  6. package/dist-sdk/src/engine/ei/run.d.ts +20 -1
  7. package/dist-sdk/src/engine/ei/run.js +102 -14
  8. package/dist-sdk/src/engine/pull/ref-only.d.ts +18 -0
  9. package/dist-sdk/src/engine/pull/ref-only.js +52 -0
  10. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +2 -1
  11. package/dist-sdk/src/entities/access-policy/from-tf.js +7 -1
  12. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  13. package/dist-sdk/src/entities/app/build.d.ts +1 -1
  14. package/dist-sdk/src/entities/app/build.js +79 -4
  15. package/dist-sdk/src/entities/app/from-tf.js +1 -2
  16. package/dist-sdk/src/entities/app/stage-keys.d.ts +18 -3
  17. package/dist-sdk/src/entities/app/stage-keys.js +40 -6
  18. package/dist-sdk/src/entities/app/to-tf.js +1 -0
  19. package/dist-sdk/src/entities/automation/build.d.ts +50 -24
  20. package/dist-sdk/src/entities/automation/build.js +16 -6
  21. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +32 -3
  22. package/dist-sdk/src/entities/automation/from-tf.d.ts +13 -2
  23. package/dist-sdk/src/entities/automation/from-tf.js +269 -63
  24. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  25. package/dist-sdk/src/entities/automation/module.js +1 -1
  26. package/dist-sdk/src/entities/automation/run-target.d.ts +2 -0
  27. package/dist-sdk/src/entities/automation/run-target.js +5 -0
  28. package/dist-sdk/src/entities/automation/script-code.d.ts +2 -1
  29. package/dist-sdk/src/entities/automation/script-code.js +82 -1
  30. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  31. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  32. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +1 -1
  33. package/dist-sdk/src/entities/automation/task-output-labels.js +9 -1
  34. package/dist-sdk/src/entities/automation/tasks.d.ts +47 -14
  35. package/dist-sdk/src/entities/automation/tasks.js +18 -4
  36. package/dist-sdk/src/entities/automation/to-tf.js +256 -28
  37. package/dist-sdk/src/entities/automation/triggers.d.ts +48 -15
  38. package/dist-sdk/src/entities/automation/triggers.js +9 -9
  39. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  40. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  41. package/dist-sdk/src/entities/chart/from-tf.js +25 -1
  42. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  43. package/dist-sdk/src/entities/chart/printer.js +5 -2
  44. package/dist-sdk/src/entities/chart/to-tf.js +19 -1
  45. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +1 -0
  46. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  47. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  48. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +1 -1
  49. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  50. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  51. package/dist-sdk/src/entities/field/module.js +8 -2
  52. package/dist-sdk/src/entities/field/to-tf.d.ts +8 -2
  53. package/dist-sdk/src/entities/field/to-tf.js +57 -34
  54. package/dist-sdk/src/entities/org/role.js +5 -0
  55. package/dist-sdk/src/entities/service-account/module.js +5 -0
  56. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  57. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  58. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  59. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  60. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  61. package/dist-sdk/src/entities/skill/module.js +2 -0
  62. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  63. package/dist-sdk/src/entities/view/from-tf.d.ts +8 -4
  64. package/dist-sdk/src/entities/view/from-tf.js +3 -5
  65. package/dist-sdk/src/entities/view/module.js +5 -0
  66. package/dist-sdk/src/entities/widget/from-tf.js +2 -2
  67. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +5 -3
  68. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  69. package/dist-sdk/src/graph/index.d.ts +15 -2
  70. package/dist-sdk/src/graph/index.js +12 -0
  71. package/dist-sdk/src/graph/types.d.ts +38 -0
  72. package/package.json +1 -1
@@ -78,7 +78,8 @@ export declare function stripTsIgnoreLines(code: string): string;
78
78
  * half of what the `code` function's TS return type already gives the type
79
79
  * system. Same best-effort contract as the closure scan:
80
80
  *
81
- * - every `return`ed object literal contributes its top-level keys; multiple
81
+ * - every top-level `return`ed object literal contributes its top-level keys
82
+ * (a return inside a callback or nested function is skipped); multiple
82
83
  * returns merge (a key typed differently across branches widens to "text")
83
84
  * - value types come from LITERAL values only: string/template → "text",
84
85
  * integral number → "integer", other number → "number", true/false →
@@ -297,7 +297,8 @@ function collectParamNames(params) {
297
297
  * half of what the `code` function's TS return type already gives the type
298
298
  * system. Same best-effort contract as the closure scan:
299
299
  *
300
- * - every `return`ed object literal contributes its top-level keys; multiple
300
+ * - every top-level `return`ed object literal contributes its top-level keys
301
+ * (a return inside a callback or nested function is skipped); multiple
301
302
  * returns merge (a key typed differently across branches widens to "text")
302
303
  * - value types come from LITERAL values only: string/template → "text",
303
304
  * integral number → "integer", other number → "number", true/false →
@@ -312,6 +313,18 @@ function collectParamNames(params) {
312
313
  * with `${}` nesting) so braces inside them don't derail the literal walk.
313
314
  */
314
315
  export function inferOutputSchema(body) {
316
+ let topLevel = topLevelReturns(body);
317
+ if (topLevel === undefined) {
318
+ // A stored TypeScript body (a scriptFile keeps its types): scan the
319
+ // type-stripped body the #2286 lint also reads, so both see the same
320
+ // top-level returns. A body that still doesn't parse reads every return.
321
+ const stripped = typeStrippedBody(body);
322
+ if (stripped !== undefined) {
323
+ topLevel = topLevelReturns(stripped);
324
+ if (topLevel !== undefined)
325
+ body = stripped;
326
+ }
327
+ }
315
328
  const merged = {};
316
329
  let found = false;
317
330
  const src = body;
@@ -329,11 +342,21 @@ export function inferOutputSchema(body) {
329
342
  if (src.startsWith("return", i) &&
330
343
  !/[A-Za-z0-9_$]/.test(src[i + 6] ?? "") &&
331
344
  !/[A-Za-z0-9_$.]/.test(src[i - 1] ?? "")) {
345
+ const returned = topLevel?.get(i);
346
+ if (topLevel !== undefined && (returned === undefined || returned === "nothing")) {
347
+ // A return inside a callback or nested function is not the script's
348
+ // result, and a bare `return` (including `return` followed by a
349
+ // newline and `{`, which automatic semicolon insertion ends) sets no keys.
350
+ i += 6;
351
+ continue;
352
+ }
332
353
  let j = skipWs(src, i + 6);
333
354
  while (src[j] === "(")
334
355
  j = skipWs(src, j + 1);
335
356
  if (src[j] !== "{")
336
357
  return undefined; // non-literal return → bail
358
+ if (returned !== undefined && returned !== j)
359
+ return undefined; // `{ ... }.x` or another non-literal → bail
337
360
  const lit = parseReturnedLiteral(src, j);
338
361
  if (lit === undefined)
339
362
  return undefined; // spread/computed key → bail
@@ -348,6 +371,64 @@ export function inferOutputSchema(body) {
348
371
  }
349
372
  return found ? merged : undefined;
350
373
  }
374
+ /**
375
+ * The body's top-level `return` statements: the ones the script's own
376
+ * function runs, not those inside a callback or nested function
377
+ * (`ROWS.map((r) => { return { id: r.id }; })`). Maps each `return` keyword's
378
+ * offset to the offset of its returned object literal, "nothing" for a bare
379
+ * `return`, or "other" for any other value. Undefined when the body is not
380
+ * plain JavaScript.
381
+ */
382
+ function topLevelReturns(body) {
383
+ let program;
384
+ try {
385
+ program = parse(body, {
386
+ ecmaVersion: "latest",
387
+ sourceType: "script",
388
+ allowReturnOutsideFunction: true,
389
+ allowAwaitOutsideFunction: true,
390
+ });
391
+ }
392
+ catch {
393
+ return undefined;
394
+ }
395
+ const returns = new Map();
396
+ const visit = (node) => {
397
+ if (Array.isArray(node)) {
398
+ for (const child of node)
399
+ visit(child);
400
+ return;
401
+ }
402
+ if (typeof node !== "object" || node === null)
403
+ return;
404
+ const { type, start, argument } = node;
405
+ if (typeof type !== "string")
406
+ return;
407
+ if (type === "FunctionDeclaration" || type === "FunctionExpression" || type === "ArrowFunctionExpression")
408
+ return;
409
+ if (type === "ReturnStatement" && typeof start === "number") {
410
+ const literal = argument;
411
+ returns.set(start, literal === null || literal === undefined
412
+ ? "nothing"
413
+ : literal.type === "ObjectExpression" && typeof literal.start === "number" ? literal.start : "other");
414
+ }
415
+ for (const [key, value] of Object.entries(node))
416
+ if (key !== "type")
417
+ visit(value);
418
+ };
419
+ visit(program);
420
+ return returns;
421
+ }
422
+ /** The body with TypeScript types stripped, or undefined when it can't be (no TypeScript, or it doesn't parse). */
423
+ function typeStrippedBody(body) {
424
+ try {
425
+ const stripped = toPlatformScriptBody(body, "executeScript output inference");
426
+ return stripped === body ? undefined : stripped;
427
+ }
428
+ catch {
429
+ return undefined;
430
+ }
431
+ }
351
432
  /** Skip whitespace and comments. */
352
433
  function skipWs(src, i) {
353
434
  for (;;) {
@@ -0,0 +1,13 @@
1
+ /** The input names a script reads from `input.parameters`, and the keys its top-level object returns set. */
2
+ export interface ScriptParameterUse {
3
+ readonly reads: ReadonlySet<string>;
4
+ /** Undefined when a top-level return isn't a plain object literal with static keys. */
5
+ readonly returnedKeys: ReadonlySet<string> | undefined;
6
+ /** Whether any top-level `return` returns a value. With none, every run returns undefined and fails. */
7
+ readonly returnsValue: boolean;
8
+ }
9
+ export declare function scriptParameterUse(code: string): ScriptParameterUse | undefined;
10
+ /** The top-level output names an `outputs` schema declares, or undefined when its shape isn't a plain object. */
11
+ export declare function declaredScriptOutputs(outputSchema: unknown): readonly string[] | undefined;
12
+ /** Advisory messages for one executeScript task. */
13
+ export declare function scriptLintFindings(taskName: string, code: unknown, inputs: unknown, outputSchema: unknown): string[];
@@ -0,0 +1,418 @@
1
+ /**
2
+ * Advisory checks of an executeScript body against its declared inputs and
3
+ * outputs (edk#2286). A read of an undeclared input is always undefined, and a
4
+ * declared output no return sets is always empty. A script with no top-level
5
+ * return fails every run (edk#2364). Build, plan and apply can't catch these, so
6
+ * build reports them as advisories.
7
+ */
8
+ import { parse } from "acorn";
9
+ import { toPlatformScriptBody } from "./script-code.js";
10
+ const FUNCTION_TYPES = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"]);
11
+ function parseScript(code) {
12
+ const options = { ecmaVersion: "latest", sourceType: "script", allowReturnOutsideFunction: true };
13
+ try {
14
+ return parse(code, options);
15
+ }
16
+ catch {
17
+ try {
18
+ return parse(toPlatformScriptBody(code, "script lint"), options);
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ }
24
+ }
25
+ function isNode(value) {
26
+ return typeof value === "object" && value !== null && typeof value.type === "string";
27
+ }
28
+ function children(node) {
29
+ return Object.entries(node).filter(([key]) => key !== "type" && key !== "start" && key !== "end").map(([, value]) => value);
30
+ }
31
+ function propertyName(key, computed) {
32
+ if (!isNode(key))
33
+ return undefined;
34
+ if (computed !== true && key.type === "Identifier")
35
+ return key["name"];
36
+ if (key.type === "Literal" && typeof key["value"] === "string")
37
+ return key["value"];
38
+ return undefined;
39
+ }
40
+ function newScope(parent, isFunction) {
41
+ return { parent, isFunction, bindings: new Map() };
42
+ }
43
+ function bind(scope, name) {
44
+ let binding = scope.bindings.get(name);
45
+ if (binding === undefined) {
46
+ binding = { alias: false, assigned: false, inits: [] };
47
+ scope.bindings.set(name, binding);
48
+ }
49
+ return binding;
50
+ }
51
+ function functionScope(scope) {
52
+ let current = scope;
53
+ while (!current.isFunction && current.parent !== undefined)
54
+ current = current.parent;
55
+ return current;
56
+ }
57
+ function resolve(scope, name) {
58
+ for (let current = scope; current !== undefined; current = current.parent) {
59
+ const binding = current.bindings.get(name);
60
+ if (binding !== undefined)
61
+ return binding;
62
+ }
63
+ return undefined;
64
+ }
65
+ function patternNames(pattern) {
66
+ const names = [];
67
+ const collect = (node) => {
68
+ if (!isNode(node))
69
+ return;
70
+ switch (node.type) {
71
+ case "Identifier":
72
+ names.push(node["name"]);
73
+ return;
74
+ case "ObjectPattern":
75
+ for (const property of node["properties"])
76
+ collect(property.type === "RestElement" ? property["argument"] : property["value"]);
77
+ return;
78
+ case "ArrayPattern":
79
+ for (const element of node["elements"])
80
+ collect(element);
81
+ return;
82
+ case "RestElement":
83
+ collect(node["argument"]);
84
+ return;
85
+ case "AssignmentPattern":
86
+ collect(node["left"]);
87
+ return;
88
+ }
89
+ };
90
+ collect(pattern);
91
+ return names;
92
+ }
93
+ /** Whether `name` is bound by `{ parameters: name }` (or `{ parameters }`) in an object pattern. */
94
+ function parametersPropertyValue(pattern, name) {
95
+ if (!isNode(pattern) || pattern.type !== "ObjectPattern")
96
+ return false;
97
+ return pattern["properties"].some((property) => property.type === "Property" && propertyName(property["key"], property["computed"]) === "parameters" &&
98
+ isNode(property["value"]) && property["value"].type === "Identifier" && property["value"]["name"] === name);
99
+ }
100
+ /** The `<object>.parameters` member expression, for a binding destructured out of `<object>`. */
101
+ function parametersOf(object) {
102
+ return { type: "MemberExpression", computed: false, object, property: { type: "Identifier", name: "parameters" } };
103
+ }
104
+ /**
105
+ * Builds the scopes of a script. The platform runs the body in a function
106
+ * nested in one that declares `const input`, so an undeclared `input` is the
107
+ * script's input. Each
108
+ * function, block, loop, catch clause and switch gets its own scope, and `var`
109
+ * belongs to the nearest function.
110
+ */
111
+ function buildScopes(program) {
112
+ const scopes = new Map();
113
+ const declareFunction = (node, scope) => {
114
+ const inner = newScope(scope, true);
115
+ scopes.set(node, inner);
116
+ if (node.type === "FunctionExpression" && isNode(node["id"]))
117
+ bind(inner, node["id"]["name"]);
118
+ for (const param of node["params"])
119
+ for (const name of patternNames(param))
120
+ bind(inner, name);
121
+ declare(node["params"], inner);
122
+ const body = node["body"];
123
+ if (isNode(body) && body.type === "BlockStatement") {
124
+ scopes.set(body, inner);
125
+ declare(body["body"], inner);
126
+ }
127
+ else {
128
+ declare(body, inner);
129
+ }
130
+ };
131
+ const declare = (node, scope) => {
132
+ if (Array.isArray(node)) {
133
+ for (const item of node)
134
+ declare(item, scope);
135
+ return;
136
+ }
137
+ if (!isNode(node))
138
+ return;
139
+ switch (node.type) {
140
+ case "FunctionDeclaration":
141
+ if (isNode(node["id"]))
142
+ bind(scope, node["id"]["name"]);
143
+ declareFunction(node, scope);
144
+ return;
145
+ case "FunctionExpression":
146
+ case "ArrowFunctionExpression":
147
+ declareFunction(node, scope);
148
+ return;
149
+ case "ClassDeclaration":
150
+ if (isNode(node["id"]))
151
+ bind(scope, node["id"]["name"]);
152
+ break;
153
+ case "BlockStatement":
154
+ case "ForStatement":
155
+ case "ForInStatement":
156
+ case "ForOfStatement": {
157
+ const inner = newScope(scope, false);
158
+ scopes.set(node, inner);
159
+ for (const child of children(node))
160
+ declare(child, inner);
161
+ return;
162
+ }
163
+ case "SwitchStatement": {
164
+ // The discriminant is outside the cases' block.
165
+ declare(node["discriminant"], scope);
166
+ const inner = newScope(scope, false);
167
+ for (const switchCase of node["cases"]) {
168
+ scopes.set(switchCase, inner);
169
+ declare(switchCase, inner);
170
+ }
171
+ return;
172
+ }
173
+ case "StaticBlock": {
174
+ const inner = newScope(scope, true);
175
+ scopes.set(node, inner);
176
+ declare(node["body"], inner);
177
+ return;
178
+ }
179
+ case "ClassExpression": {
180
+ if (!isNode(node["id"]))
181
+ break;
182
+ const inner = newScope(scope, false);
183
+ scopes.set(node, inner);
184
+ bind(inner, node["id"]["name"]);
185
+ for (const child of children(node))
186
+ declare(child, inner);
187
+ return;
188
+ }
189
+ case "CatchClause": {
190
+ const inner = newScope(scope, false);
191
+ scopes.set(node, inner);
192
+ for (const name of patternNames(node["param"]))
193
+ bind(inner, name);
194
+ declare(node["body"], inner);
195
+ return;
196
+ }
197
+ case "VariableDeclaration": {
198
+ const target = node["kind"] === "var" ? functionScope(scope) : scope;
199
+ for (const declarator of node["declarations"]) {
200
+ for (const name of patternNames(declarator["id"])) {
201
+ const binding = bind(target, name);
202
+ if (isNode(declarator["id"]) && declarator["id"].type === "Identifier") {
203
+ if (declarator["init"] !== null && declarator["init"] !== undefined) {
204
+ binding.inits.push({ init: declarator["init"], scope });
205
+ }
206
+ else if (node["kind"] !== "var") {
207
+ binding.inits.push({ init: undefined, scope });
208
+ }
209
+ }
210
+ else if (parametersPropertyValue(declarator["id"], name)) {
211
+ binding.inits.push({ init: parametersOf(declarator["init"]), scope });
212
+ }
213
+ else {
214
+ binding.assigned = true;
215
+ }
216
+ }
217
+ declare(declarator["id"], scope);
218
+ declare(declarator["init"], scope);
219
+ }
220
+ return;
221
+ }
222
+ }
223
+ for (const child of children(node))
224
+ declare(child, scope);
225
+ };
226
+ const root = newScope(undefined, true);
227
+ scopes.set(program, root);
228
+ declare(program["body"], root);
229
+ return scopes;
230
+ }
231
+ /** Walks a node with the scope that holds each node, and whether it is inside a function. */
232
+ function walkScoped(node, scope, inFunction, scopes, visit) {
233
+ if (Array.isArray(node)) {
234
+ for (const item of node)
235
+ walkScoped(item, scope, inFunction, scopes, visit);
236
+ return;
237
+ }
238
+ if (!isNode(node))
239
+ return;
240
+ const own = scopes.get(node) ?? scope;
241
+ visit(node, own, inFunction);
242
+ const childInFunction = inFunction || FUNCTION_TYPES.has(node.type);
243
+ for (const child of children(node))
244
+ walkScoped(child, own, childInFunction, scopes, visit);
245
+ }
246
+ export function scriptParameterUse(code) {
247
+ const program = parseScript(code);
248
+ if (program === undefined)
249
+ return undefined;
250
+ const scopes = buildScopes(program);
251
+ const root = scopes.get(program);
252
+ walkScoped(program, root, false, scopes, (node, scope) => {
253
+ if (node.type === "AssignmentExpression" && isNode(node["left"]) && node["left"].type === "Identifier") {
254
+ const binding = resolve(scope, node["left"]["name"]);
255
+ if (binding !== undefined)
256
+ binding.assigned = true;
257
+ }
258
+ if (node.type === "UpdateExpression" && isNode(node["argument"]) && node["argument"].type === "Identifier") {
259
+ const binding = resolve(scope, node["argument"]["name"]);
260
+ if (binding !== undefined)
261
+ binding.assigned = true;
262
+ }
263
+ if ((node.type === "ForInStatement" || node.type === "ForOfStatement") && isNode(node["left"])) {
264
+ const targets = node["left"].type === "VariableDeclaration"
265
+ ? node["left"]["declarations"].flatMap((declarator) => patternNames(declarator["id"]))
266
+ : patternNames(node["left"]);
267
+ for (const name of targets) {
268
+ const binding = resolve(scope, name);
269
+ if (binding !== undefined)
270
+ binding.assigned = true;
271
+ }
272
+ }
273
+ });
274
+ // `input.parameters`, read through the script's own `input`, or an alias of it.
275
+ const isParametersOf = (node, scope) => {
276
+ if (!isNode(node))
277
+ return false;
278
+ switch (node.type) {
279
+ case "Identifier":
280
+ return resolve(scope, node["name"])?.alias === true;
281
+ case "MemberExpression":
282
+ return node["computed"] !== true && isNode(node["object"]) && node["object"].type === "Identifier" &&
283
+ node["object"]["name"] === "input" && resolve(scope, "input") === undefined &&
284
+ isNode(node["property"]) && node["property"]["name"] === "parameters";
285
+ case "LogicalExpression":
286
+ return node["operator"] === "&&" ? isParametersOf(node["right"], scope) : isParametersOf(node["left"], scope);
287
+ case "ChainExpression":
288
+ return isParametersOf(node["expression"], scope);
289
+ case "ConditionalExpression":
290
+ return (isParametersOf(node["consequent"], scope) && isEmptyObjectOrParameters(node["alternate"], scope)) ||
291
+ (isParametersOf(node["alternate"], scope) && isEmptyObjectOrParameters(node["consequent"], scope));
292
+ }
293
+ return false;
294
+ };
295
+ const isEmptyObjectOrParameters = (node, scope) => (isNode(node) && node.type === "ObjectExpression" && node["properties"].length === 0) || isParametersOf(node, scope);
296
+ const bindings = [...new Set([...scopes.values()])].flatMap((scope) => [...scope.bindings.values()]);
297
+ for (let changed = true; changed;) {
298
+ changed = false;
299
+ for (const binding of bindings) {
300
+ if (binding.alias || binding.assigned || binding.inits.length === 0)
301
+ continue;
302
+ if (binding.inits.every(({ init, scope }) => isParametersOf(init, scope))) {
303
+ binding.alias = true;
304
+ changed = true;
305
+ }
306
+ }
307
+ }
308
+ const reads = new Set();
309
+ const returnedKeys = new Set();
310
+ let returnsKnown = true;
311
+ let returnsValue = false;
312
+ const collectReturn = (argument, scope) => {
313
+ if (!returnsUndefined(argument, scope))
314
+ returnsValue = true;
315
+ if (!isNode(argument) || argument.type !== "ObjectExpression") {
316
+ returnsKnown = false;
317
+ return;
318
+ }
319
+ for (const property of argument["properties"]) {
320
+ const name = property.type === "Property" ? propertyName(property["key"], property["computed"]) : undefined;
321
+ if (name === undefined)
322
+ returnsKnown = false;
323
+ else
324
+ returnedKeys.add(name);
325
+ }
326
+ };
327
+ // A called member such as `input.parameters.hasOwnProperty(...)` is a method, and a written one is
328
+ // set by the script. Neither is an input.
329
+ const notReads = new Set();
330
+ const written = new Set();
331
+ walkScoped(program, root, false, scopes, (node, scope, inFunction) => {
332
+ if (node.type === "CallExpression" && isNode(node["callee"]))
333
+ notReads.add(node["callee"]);
334
+ if (node.type === "AssignmentExpression" && isNode(node["left"]))
335
+ notReads.add(node["left"]);
336
+ if (node.type === "UpdateExpression" && isNode(node["argument"]))
337
+ notReads.add(node["argument"]);
338
+ if (node.type === "VariableDeclarator" && isNode(node["id"]) && node["id"].type === "ObjectPattern" &&
339
+ isParametersOf(node["init"], scope)) {
340
+ for (const property of node["id"]["properties"]) {
341
+ const name = property.type === "Property" ? propertyName(property["key"], property["computed"]) : undefined;
342
+ if (name !== undefined)
343
+ reads.add(name);
344
+ }
345
+ }
346
+ if (node.type === "MemberExpression" && isParametersOf(node["object"], scope)) {
347
+ const name = propertyName(node["property"], node["computed"]);
348
+ if (name !== undefined)
349
+ (notReads.has(node) ? written : reads).add(name);
350
+ }
351
+ if (node.type === "ReturnStatement" && !inFunction)
352
+ collectReturn(node["argument"], scope);
353
+ });
354
+ for (const name of written)
355
+ reads.delete(name);
356
+ return { reads, returnedKeys: returnsKnown ? returnedKeys : undefined, returnsValue };
357
+ }
358
+ /** Whether a return argument is plainly undefined: none, `undefined` (not shadowed), or `void <expr>`. */
359
+ function returnsUndefined(argument, scope) {
360
+ if (!isNode(argument))
361
+ return true;
362
+ if (argument.type === "Identifier" && argument["name"] === "undefined")
363
+ return resolve(scope, "undefined") === undefined;
364
+ return argument.type === "UnaryExpression" && argument["operator"] === "void";
365
+ }
366
+ /** The top-level output names an `outputs` schema declares, or undefined when its shape isn't a plain object. */
367
+ export function declaredScriptOutputs(outputSchema) {
368
+ if (typeof outputSchema !== "object" || outputSchema === null)
369
+ return undefined;
370
+ const root = outputSchema.object;
371
+ if (root === undefined || !Array.isArray(root.properties))
372
+ return undefined;
373
+ const names = [];
374
+ for (const property of root.properties) {
375
+ if (typeof property !== "object" || property === null)
376
+ return undefined;
377
+ const inner = Object.values(property)[0];
378
+ const name = typeof inner === "object" && inner !== null ? inner.name : undefined;
379
+ if (typeof name !== "string")
380
+ return undefined;
381
+ names.push(name);
382
+ }
383
+ return names;
384
+ }
385
+ /** Advisory messages for one executeScript task. */
386
+ export function scriptLintFindings(taskName, code, inputs, outputSchema) {
387
+ if (typeof code !== "string")
388
+ return [];
389
+ const use = scriptParameterUse(code);
390
+ if (use === undefined)
391
+ return [];
392
+ const declaredInputs = Array.isArray(inputs)
393
+ ? inputs.flatMap((input) => typeof input === "object" && input !== null && typeof input.name === "string" ? [input.name] : [])
394
+ : [];
395
+ const findings = [];
396
+ const declared = declaredInputs.length > 0 ? declaredInputs.join(", ") : "none";
397
+ for (const name of use.reads) {
398
+ if (!declaredInputs.includes(name)) {
399
+ findings.push(`executeScript "${taskName}" reads input "${name}", which its inputs don't declare, so it is always undefined. Declared inputs: ${declared}.`);
400
+ }
401
+ }
402
+ if (!use.returnsValue) {
403
+ // The platform's executor throws "The function MUST return a valid JavaScript object" when the
404
+ // script's result is undefined, so each declared output being empty is the lesser problem.
405
+ findings.push(`executeScript "${taskName}" has no top-level return that returns a value, so every run fails ("The function MUST return a valid JavaScript object"). A return inside a callback or nested function does not count. End the script with return { ... }.`);
406
+ return findings;
407
+ }
408
+ const outputs = declaredScriptOutputs(outputSchema);
409
+ if (outputs !== undefined && use.returnedKeys !== undefined) {
410
+ const returned = use.returnedKeys.size > 0 ? [...use.returnedKeys].join(", ") : "none";
411
+ for (const name of outputs) {
412
+ if (!use.returnedKeys.has(name)) {
413
+ findings.push(`executeScript "${taskName}" declares output "${name}", which no return of its script sets, so it is always empty. Returned keys: ${returned}.`);
414
+ }
415
+ }
416
+ }
417
+ return findings;
418
+ }
@@ -26,7 +26,7 @@ export declare function taskOutputReferences(): Readonly<Record<string, Readonly
26
26
  /**
27
27
  * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
28
28
  * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
29
- * `record_reference` needs; a field-mapped input needs the record itself.
29
+ * `record_reference` needs; a script input needs the record itself.
30
30
  */
31
31
  export declare const WHOLE_RECORD_REF_WIRE_NAMES: Readonly<Record<string, string>>;
32
32
  /**
@@ -58,6 +58,14 @@ export const TASK_OUTPUT_REFERENCE_NAMES = {
58
58
  "API Response (text)": "textResponse",
59
59
  "API Response Status Code": "statusCode",
60
60
  },
61
+ // Captured live from a deployed table_records_search task's refs map (edk#2407).
62
+ elementum_table_records_search_task: {
63
+ "All matching table rows": "records",
64
+ "First matching table row": "record",
65
+ "Row count": "count",
66
+ "Column metadata for the result": "metaData",
67
+ "Source table id": "tableId",
68
+ },
61
69
  // Captured live from a deployed bulk_update_fields task's refs map.
62
70
  elementum_bulk_update_fields_task: {
63
71
  "Records Updated": "recordsUpdated",
@@ -84,7 +92,7 @@ export function taskOutputReferences() {
84
92
  /**
85
93
  * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
86
94
  * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
87
- * `record_reference` needs; a field-mapped input needs the record itself.
95
+ * `record_reference` needs; a script input needs the record itself.
88
96
  */
89
97
  export const WHOLE_RECORD_REF_WIRE_NAMES = {
90
98
  recordSearch: "First found record",