@elementumai/edk 0.10.4 → 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 (171) hide show
  1. package/README.md +49 -13
  2. package/dist-sdk/src/catalog/token.js +2 -1
  3. package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
  4. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  5. package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
  6. package/dist-sdk/src/engine/build/context.d.ts +4 -0
  7. package/dist-sdk/src/engine/coverage-gaps.d.ts +7 -0
  8. package/dist-sdk/src/engine/coverage-gaps.js +12 -0
  9. package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
  10. package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
  11. package/dist-sdk/src/engine/ei/run.d.ts +42 -1
  12. package/dist-sdk/src/engine/ei/run.js +201 -32
  13. package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
  14. package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
  15. package/dist-sdk/src/engine/ei/state.d.ts +1 -1
  16. package/dist-sdk/src/engine/ei/state.js +17 -4
  17. package/dist-sdk/src/engine/progress.d.ts +3 -1
  18. package/dist-sdk/src/engine/progress.js +7 -3
  19. package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
  20. package/dist-sdk/src/engine/pull/authored-address.js +180 -29
  21. package/dist-sdk/src/engine/pull/context.d.ts +37 -2
  22. package/dist-sdk/src/engine/pull/context.js +7 -4
  23. package/dist-sdk/src/engine/pull/ref-only.d.ts +18 -0
  24. package/dist-sdk/src/engine/pull/ref-only.js +52 -0
  25. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  26. package/dist-sdk/src/engine/tf/index.js +2 -2
  27. package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
  28. package/dist-sdk/src/engine/tf/labels.js +50 -0
  29. package/dist-sdk/src/engine/tf/model.d.ts +2 -0
  30. package/dist-sdk/src/engine/tf/model.js +26 -0
  31. package/dist-sdk/src/engine/validation.d.ts +2 -0
  32. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +18 -0
  33. package/dist-sdk/src/entities/access-policy/from-tf.js +58 -24
  34. package/dist-sdk/src/entities/access-policy/member-list.d.ts +32 -0
  35. package/dist-sdk/src/entities/access-policy/member-list.js +57 -0
  36. package/dist-sdk/src/entities/access-policy/module.js +10 -0
  37. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +4 -3
  38. package/dist-sdk/src/entities/access-policy/to-tf.js +21 -12
  39. package/dist-sdk/src/entities/agent/build.js +7 -5
  40. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -0
  41. package/dist-sdk/src/entities/agent/from-tf.js +13 -3
  42. package/dist-sdk/src/entities/agent/to-tf.js +11 -5
  43. package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
  44. package/dist-sdk/src/entities/agent/tools.js +6 -2
  45. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  46. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
  47. package/dist-sdk/src/entities/agent-tool/to-tf.js +56 -3
  48. package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
  49. package/dist-sdk/src/entities/agent-tool/types.js +13 -9
  50. package/dist-sdk/src/entities/app/build.d.ts +12 -1
  51. package/dist-sdk/src/entities/app/build.js +80 -4
  52. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +5 -7
  53. package/dist-sdk/src/entities/app/from-tf.js +17 -12
  54. package/dist-sdk/src/entities/app/stage-keys.d.ts +18 -3
  55. package/dist-sdk/src/entities/app/stage-keys.js +40 -6
  56. package/dist-sdk/src/entities/app/to-tf.js +7 -4
  57. package/dist-sdk/src/entities/automation/build.d.ts +52 -31
  58. package/dist-sdk/src/entities/automation/build.js +59 -20
  59. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
  60. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +39 -14
  61. package/dist-sdk/src/entities/automation/from-tf.d.ts +35 -2
  62. package/dist-sdk/src/entities/automation/from-tf.js +721 -93
  63. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  64. package/dist-sdk/src/entities/automation/module.d.ts +22 -2
  65. package/dist-sdk/src/entities/automation/module.js +244 -57
  66. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +22 -2
  67. package/dist-sdk/src/entities/automation/output-key-wire-name.js +54 -3
  68. package/dist-sdk/src/entities/automation/run-target.d.ts +61 -0
  69. package/dist-sdk/src/entities/automation/run-target.js +104 -0
  70. package/dist-sdk/src/entities/automation/script-code.d.ts +11 -1
  71. package/dist-sdk/src/entities/automation/script-code.js +106 -4
  72. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  73. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  74. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -1
  75. package/dist-sdk/src/entities/automation/task-output-labels.js +58 -1
  76. package/dist-sdk/src/entities/automation/tasks.d.ts +67 -22
  77. package/dist-sdk/src/entities/automation/tasks.js +18 -4
  78. package/dist-sdk/src/entities/automation/to-tf.d.ts +1 -3
  79. package/dist-sdk/src/entities/automation/to-tf.js +354 -64
  80. package/dist-sdk/src/entities/automation/triggers.d.ts +63 -11
  81. package/dist-sdk/src/entities/automation/triggers.js +45 -5
  82. package/dist-sdk/src/entities/automation/types.d.ts +21 -0
  83. package/dist-sdk/src/entities/automation/types.js +26 -0
  84. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  85. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  86. package/dist-sdk/src/entities/chart/from-tf.js +25 -1
  87. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  88. package/dist-sdk/src/entities/chart/printer.js +5 -2
  89. package/dist-sdk/src/entities/chart/to-tf.js +19 -1
  90. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
  91. package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
  92. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  93. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +8 -2
  94. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  95. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  96. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
  97. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +66 -20
  98. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  99. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
  100. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
  101. package/dist-sdk/src/entities/element/build.d.ts +10 -0
  102. package/dist-sdk/src/entities/element/build.js +1 -0
  103. package/dist-sdk/src/entities/element/from-tf.js +14 -9
  104. package/dist-sdk/src/entities/element/to-tf.js +7 -4
  105. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  106. package/dist-sdk/src/entities/field/from-tf.js +79 -1
  107. package/dist-sdk/src/entities/field/module.js +14 -1
  108. package/dist-sdk/src/entities/field/to-tf.d.ts +38 -3
  109. package/dist-sdk/src/entities/field/to-tf.js +108 -34
  110. package/dist-sdk/src/entities/file-reader/module.js +3 -3
  111. package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
  112. package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
  113. package/dist-sdk/src/entities/file-reader/types.js +7 -0
  114. package/dist-sdk/src/entities/org/group.d.ts +1 -0
  115. package/dist-sdk/src/entities/org/group.js +2 -1
  116. package/dist-sdk/src/entities/org/role.js +5 -0
  117. package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
  118. package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
  119. package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
  120. package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
  121. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
  122. package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
  123. package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
  124. package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
  125. package/dist-sdk/src/entities/role/from-tf.js +24 -7
  126. package/dist-sdk/src/entities/role/to-tf.js +25 -7
  127. package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
  128. package/dist-sdk/src/entities/service-account/module.js +20 -0
  129. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  130. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  131. package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
  132. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  133. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
  134. package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
  135. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  136. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  137. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
  138. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
  139. package/dist-sdk/src/entities/skill/from-tf.js +10 -3
  140. package/dist-sdk/src/entities/skill/module.js +18 -0
  141. package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
  142. package/dist-sdk/src/entities/skill/to-tf.js +23 -14
  143. package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
  144. package/dist-sdk/src/entities/skill/tools.js +6 -2
  145. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  146. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
  147. package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
  148. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  149. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +8 -2
  150. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +20 -10
  151. package/dist-sdk/src/entities/view/from-tf.d.ts +68 -4
  152. package/dist-sdk/src/entities/view/from-tf.js +394 -22
  153. package/dist-sdk/src/entities/view/module.js +20 -0
  154. package/dist-sdk/src/entities/view/portable.d.ts +11 -0
  155. package/dist-sdk/src/entities/view/portable.js +47 -0
  156. package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
  157. package/dist-sdk/src/entities/view/to-tf.js +25 -7
  158. package/dist-sdk/src/entities/view/types.js +1 -1
  159. package/dist-sdk/src/entities/widget/build.d.ts +4 -3
  160. package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
  161. package/dist-sdk/src/entities/widget/from-tf.js +100 -3
  162. package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
  163. package/dist-sdk/src/entities/widget/to-tf.js +77 -14
  164. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +30 -9
  165. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  166. package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
  167. package/dist-sdk/src/graph/field-resource-types.js +11 -0
  168. package/dist-sdk/src/graph/index.d.ts +41 -3
  169. package/dist-sdk/src/graph/index.js +24 -2
  170. package/dist-sdk/src/graph/types.d.ts +195 -5
  171. package/package.json +1 -1
@@ -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
+ }
@@ -1,5 +1,14 @@
1
+ import type { TaskOutputReference } from "../../graph/types.js";
1
2
  /** userSearch authoring output → provider refs-map key (as exported from live user-search tasks). */
2
3
  export declare const USER_SEARCH_REF_WIRE_NAMES: Readonly<Record<string, string>>;
4
+ /**
5
+ * A user search's refs-map key → the reference an exported value envelope
6
+ * carries: the name and the `fieldType`/`multiple` of the envelope that key
7
+ * holds, as the provider's refs map of a live user-search task lists them
8
+ * (ironman capture, #1701). The build-vs-export comparison reads all of it;
9
+ * the build names the referenceable ones (TASK_OUTPUT_REFERENCE_NAMES below).
10
+ */
11
+ export declare const USER_SEARCH_OUTPUT_REFERENCES: Readonly<Record<string, TaskOutputReference>>;
3
12
  /**
4
13
  * Task-own outputs whose WorkflowTaskReference name (what an exported
5
14
  * envelope and a calculation mustache carry) differs from the provider
@@ -7,10 +16,17 @@ export declare const USER_SEARCH_REF_WIRE_NAMES: Readonly<Record<string, string>
7
16
  * and matching mobius' `shared.json` label tables.
8
17
  */
9
18
  export declare const TASK_OUTPUT_REFERENCE_NAMES: Readonly<Record<string, Readonly<Record<string, string>>>>;
19
+ /**
20
+ * Each {@link TASK_OUTPUT_REFERENCE_NAMES} key with the type of the envelope
21
+ * it holds: the output's contract (`TASK_OUTPUT_CONTRACTS`). The
22
+ * build-vs-export comparison reads an exported envelope as that key only when
23
+ * the envelope is of this type.
24
+ */
25
+ export declare function taskOutputReferences(): Readonly<Record<string, Readonly<Record<string, TaskOutputReference>>>>;
10
26
  /**
11
27
  * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
12
28
  * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
13
- * `record_reference` needs; a field-mapped input needs the record itself.
29
+ * `record_reference` needs; a script input needs the record itself.
14
30
  */
15
31
  export declare const WHOLE_RECORD_REF_WIRE_NAMES: Readonly<Record<string, string>>;
16
32
  /**
@@ -1,3 +1,4 @@
1
+ import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
1
2
  /** userSearch authoring output → provider refs-map key (as exported from live user-search tasks). */
2
3
  export const USER_SEARCH_REF_WIRE_NAMES = {
3
4
  "user.id": "User's Id",
@@ -8,6 +9,24 @@ export const USER_SEARCH_REF_WIRE_NAMES = {
8
9
  users: "All found users",
9
10
  count: "Users Size",
10
11
  };
12
+ /**
13
+ * A user search's refs-map key → the reference an exported value envelope
14
+ * carries: the name and the `fieldType`/`multiple` of the envelope that key
15
+ * holds, as the provider's refs map of a live user-search task lists them
16
+ * (ironman capture, #1701). The build-vs-export comparison reads all of it;
17
+ * the build names the referenceable ones (TASK_OUTPUT_REFERENCE_NAMES below).
18
+ */
19
+ export const USER_SEARCH_OUTPUT_REFERENCES = {
20
+ "Users Size": { name: "count", fieldType: "NUMBER", multiple: false },
21
+ "First found user": { name: "user", fieldType: "USER", multiple: false },
22
+ "All found users": { name: "users", fieldType: "USER", multiple: true },
23
+ "User's Id": { name: "user.id", fieldType: "USER_ID", multiple: false },
24
+ "User's Name": { name: "user.name", fieldType: "TEXT", multiple: false },
25
+ "User's Email": { name: "user.email", fieldType: "TEXT", multiple: false },
26
+ Manager: { name: "user.employee.manager", fieldType: "EMPLOYEE", multiple: false },
27
+ "Manager Name": { name: "user.employee.manager.name", fieldType: "TEXT", multiple: false },
28
+ "Manager Email": { name: "user.employee.manager.email", fieldType: "TEXT", multiple: false },
29
+ };
11
30
  /**
12
31
  * Task-own outputs whose WorkflowTaskReference name (what an exported
13
32
  * envelope and a calculation mustache carry) differs from the provider
@@ -19,6 +38,12 @@ export const TASK_OUTPUT_REFERENCE_NAMES = {
19
38
  "Records Size": "count",
20
39
  "First found record id": "recordId",
21
40
  },
41
+ // The user-search outputs with a contract, so a calculation names `count`,
42
+ // `user.id`, … and not "Users Size" (#1738). The manager outputs have no
43
+ // contract (not referenceable at publish) and keep their refs key.
44
+ elementum_user_search_task: Object.fromEntries(Object.entries(USER_SEARCH_OUTPUT_REFERENCES)
45
+ .filter(([, ref]) => TASK_OUTPUT_CONTRACTS.user_search?.[ref.name] !== undefined)
46
+ .map(([key, ref]) => [key, ref.name])),
22
47
  elementum_user_group_search_task: {
23
48
  "Groups Size": "count",
24
49
  "First found group": "group",
@@ -26,16 +51,48 @@ export const TASK_OUTPUT_REFERENCE_NAMES = {
26
51
  Name: "group.name",
27
52
  "All found groups": "groups",
28
53
  },
54
+ // A JSON apiRequest's refs keys (edk#2058, `ei refs --from-remote`); the
55
+ // send_api_request contract names them response/textResponse/statusCode.
56
+ elementum_api_task: {
57
+ "API Response": "response",
58
+ "API Response (text)": "textResponse",
59
+ "API Response Status Code": "statusCode",
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
+ },
29
69
  // Captured live from a deployed bulk_update_fields task's refs map.
30
70
  elementum_bulk_update_fields_task: {
31
71
  "Records Updated": "recordsUpdated",
32
72
  "All Matching Records Updated": "allMatchingRecordsUpdated",
33
73
  },
34
74
  };
75
+ /**
76
+ * Each {@link TASK_OUTPUT_REFERENCE_NAMES} key with the type of the envelope
77
+ * it holds: the output's contract (`TASK_OUTPUT_CONTRACTS`). The
78
+ * build-vs-export comparison reads an exported envelope as that key only when
79
+ * the envelope is of this type.
80
+ */
81
+ export function taskOutputReferences() {
82
+ return Object.fromEntries(Object.entries(TASK_OUTPUT_REFERENCE_NAMES).map(([taskType, names]) => {
83
+ const executor = RESOURCE_TYPE_TO_EXECUTOR[taskType];
84
+ return [taskType, Object.fromEntries(Object.entries(names).map(([key, name]) => {
85
+ const contract = executor === undefined ? undefined : TASK_OUTPUT_CONTRACTS[executor]?.[name];
86
+ if (contract === undefined)
87
+ throw new Error(`no output contract for ${taskType} output "${name}" (refs key "${key}")`);
88
+ return [key, { name, fieldType: contract.fieldType, multiple: contract.multiple }];
89
+ }))];
90
+ }));
91
+ }
35
92
  /**
36
93
  * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
37
94
  * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
38
- * `record_reference` needs; a field-mapped input needs the record itself.
95
+ * `record_reference` needs; a script input needs the record itself.
39
96
  */
40
97
  export const WHOLE_RECORD_REF_WIRE_NAMES = {
41
98
  recordSearch: "First found record",