@elementumai/edk 0.9.9 → 0.9.10
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/dist-sdk/src/engine/build/context.d.ts +2 -0
- package/dist-sdk/src/entities/app/to-tf.d.ts +1 -1
- package/dist-sdk/src/entities/app/to-tf.js +2 -0
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +78 -19
- package/dist-sdk/src/entities/automation/script-code.d.ts +7 -0
- package/dist-sdk/src/entities/automation/script-code.js +17 -3
- package/dist-sdk/src/entities/automation/to-tf.js +9 -0
- package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/dashboard/to-tf.js +4 -0
- package/dist-sdk/src/entities/datamine/from-tf.js +23 -3
- package/package.json +1 -1
|
@@ -92,6 +92,8 @@ export interface WorkspaceAspect {
|
|
|
92
92
|
readonly onDemandRecordParamByAutomationRefName?: ReadonlyMap<string, string>;
|
|
93
93
|
/** Terraform labels of datamines managed by a table in this workspace. */
|
|
94
94
|
readonly managedDatamineLabels?: ReadonlySet<string>;
|
|
95
|
+
/** Ref names of own-file children present in this workspace, grouped by kind. */
|
|
96
|
+
readonly managedChildRefNames?: ReadonlyMap<string, ReadonlySet<string>>;
|
|
95
97
|
}
|
|
96
98
|
/**
|
|
97
99
|
* Key for the `workspaceAspects` map: an app and an element MAY share a
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* Unsupported authoring shapes degrade through `diagnostics` — reported,
|
|
15
15
|
* never silent, never thrown (plan §4.3).
|
|
16
16
|
*/
|
|
17
|
-
import type
|
|
17
|
+
import { type ToTfContext } from "../../engine/build/context.js";
|
|
18
18
|
import type { BuildFieldMetadata } from "../../graph/types.js";
|
|
19
19
|
import { type DeployableEntity } from "../../engine/entity.js";
|
|
20
20
|
import { type TfBlock } from "../../engine/tf/index.js";
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* Unsupported authoring shapes degrade through `diagnostics` — reported,
|
|
15
15
|
* never silent, never thrown (plan §4.3).
|
|
16
16
|
*/
|
|
17
|
+
import { workspaceAspectKey } from "../../engine/build/context.js";
|
|
17
18
|
import { DEPLOY_DEFAULT_STATUS_OPTION_VALUES, SYSTEM_FIELD_HCL_KEY_BY_KEY, SYSTEM_FIELD_KEY_BY_TAG } from "../../core/system-fields.js";
|
|
18
19
|
import { EntityTfError } from "../../engine/entity.js";
|
|
19
20
|
import { expr, snakeSlug } from "../../engine/tf/index.js";
|
|
@@ -246,6 +247,7 @@ export function appToTf(entity, ctx) {
|
|
|
246
247
|
ownerResourceType: APP_RESOURCE_TYPE,
|
|
247
248
|
orgRefs: ctx.orgRefs,
|
|
248
249
|
workspaceAspects: ctx.workspaceAspects,
|
|
250
|
+
availableChartRefNames: ctx.workspaceAspects?.get(workspaceAspectKey("app", ctx.appRefName))?.managedChildRefNames?.get("chart"),
|
|
249
251
|
diagnostics: ctx.diagnostics,
|
|
250
252
|
}));
|
|
251
253
|
blocks.push(...widgetsToTf(payload.widgets, {
|
|
@@ -37,6 +37,7 @@ import { isRefExpr } from "../../shared/filters/ast.js";
|
|
|
37
37
|
import { printFilter as printCanonicalFilter } from "../../shared/filters/print.js";
|
|
38
38
|
import { UNRESOLVED_FIELD_MARKER } from "../../shared/ref.js";
|
|
39
39
|
import { UNRESOLVED_REFERENCE_MARKER } from "../filter.js";
|
|
40
|
+
import { INJECTED_TS_IGNORE } from "../script-code.js";
|
|
40
41
|
import { unresolvedReferenceComment } from "../../../engine/pull/ref-only.js";
|
|
41
42
|
// ---------------------------------------------------------------------------
|
|
42
43
|
// Factory name mapping — v1 AST `factory` → v2 factory function name.
|
|
@@ -248,21 +249,6 @@ export function printAutomationV2(ast, opts = {}) {
|
|
|
248
249
|
// ---------------------------------------------------------------------------
|
|
249
250
|
function renderHeader(ast, imports, _opts) {
|
|
250
251
|
const lines = [];
|
|
251
|
-
if (imports.usesScriptInput) {
|
|
252
|
-
// executeScript task bodies are printed VERBATIM from the platform's
|
|
253
|
-
// plain-JavaScript source (script-code.ts) — they carry no type
|
|
254
|
-
// annotations of their own, so under this workspace's `noImplicitAny`
|
|
255
|
-
// every untyped nested function/variable in a pulled script body fails
|
|
256
|
-
// `tsc` (#749). The script text is later re-extracted byte-exact from
|
|
257
|
-
// this file's own source (`tryExtractFromCurrentSource`) and shipped to
|
|
258
|
-
// the platform as literal JavaScript, so annotating it in place isn't
|
|
259
|
-
// safe — `: any` would be invalid JS if the file is ever hand-edited
|
|
260
|
-
// into something the extractor can't match and falls back to
|
|
261
|
-
// `Function#toString()`. `@ts-nocheck` must lead the file to take
|
|
262
|
-
// effect, so it costs this one file's typechecking (still fully
|
|
263
|
-
// buildable) rather than the workspace's.
|
|
264
|
-
lines.push(`// @ts-nocheck — executeScript task bodies below are untyped platform JavaScript (see #749)`);
|
|
265
|
-
}
|
|
266
252
|
lines.push(`/**`);
|
|
267
253
|
lines.push(` * ${ast.name}`);
|
|
268
254
|
lines.push(` *`);
|
|
@@ -544,6 +530,7 @@ function formatExecuteScript(task, state, indent, refCtx = DEFAULT_CTX) {
|
|
|
544
530
|
}
|
|
545
531
|
const code = task.args.code ?? task.args.script;
|
|
546
532
|
if (typeof code === "string") {
|
|
533
|
+
lines.push(`${configPad}// @ts-ignore`);
|
|
547
534
|
lines.push(`${configPad}code: ${printScriptCodeFn(code, indent + 1, state)},`);
|
|
548
535
|
}
|
|
549
536
|
if (task.args.outputs !== undefined && task.args.outputs !== null && typeof task.args.outputs === "object") {
|
|
@@ -582,11 +569,79 @@ function formatExecuteScript(task, state, indent, refCtx = DEFAULT_CTX) {
|
|
|
582
569
|
* references. Hand-authored `.executeScript` calls are unaffected — they
|
|
583
570
|
* still get full inference since they never pass this printer.
|
|
584
571
|
*/
|
|
572
|
+
/**
|
|
573
|
+
* Annotates lines of a script body with `// @ts-ignore` so untyped nested
|
|
574
|
+
* declarations (such as `function helper(value) { ... }`) pass under
|
|
575
|
+
* `noImplicitAny` when pulled scripts are type-checked.
|
|
576
|
+
* Lines inside multi-line template literals or block comments are left
|
|
577
|
+
* unannotated to avoid altering string literals or breaking comments.
|
|
578
|
+
*/
|
|
579
|
+
function annotateScriptLines(body, indent) {
|
|
580
|
+
const innerPad = " ".repeat(indent);
|
|
581
|
+
const lines = body.replace(/\r\n/g, "\n").split("\n");
|
|
582
|
+
let inBacktick = false;
|
|
583
|
+
let inBlockComment = false;
|
|
584
|
+
const result = [];
|
|
585
|
+
for (const line of lines) {
|
|
586
|
+
if (line.trim().length === 0) {
|
|
587
|
+
result.push("");
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
const wasInBacktick = inBacktick;
|
|
591
|
+
const wasInBlockComment = inBlockComment;
|
|
592
|
+
for (let i = 0; i < line.length; i++) {
|
|
593
|
+
const c = line[i];
|
|
594
|
+
const next = line[i + 1];
|
|
595
|
+
if (inBlockComment) {
|
|
596
|
+
if (c === "*" && next === "/") {
|
|
597
|
+
inBlockComment = false;
|
|
598
|
+
i++;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
else if (inBacktick) {
|
|
602
|
+
if (c === "\\") {
|
|
603
|
+
i++;
|
|
604
|
+
}
|
|
605
|
+
else if (c === "`") {
|
|
606
|
+
inBacktick = false;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
if (c === "/" && next === "*") {
|
|
611
|
+
inBlockComment = true;
|
|
612
|
+
i++;
|
|
613
|
+
}
|
|
614
|
+
else if (c === "/" && next === "/") {
|
|
615
|
+
break;
|
|
616
|
+
}
|
|
617
|
+
else if (c === "`") {
|
|
618
|
+
inBacktick = true;
|
|
619
|
+
}
|
|
620
|
+
else if (c === '"' || c === "'") {
|
|
621
|
+
const quote = c;
|
|
622
|
+
i++;
|
|
623
|
+
while (i < line.length && line[i] !== quote) {
|
|
624
|
+
if (line[i] === "\\")
|
|
625
|
+
i++;
|
|
626
|
+
i++;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
const trimmed = line.trim();
|
|
632
|
+
const isCommentLine = trimmed.startsWith("//") || (trimmed.startsWith("/*") && trimmed.endsWith("*/"));
|
|
633
|
+
if (wasInBacktick || wasInBlockComment || isCommentLine) {
|
|
634
|
+
result.push(`${innerPad}${line}`);
|
|
635
|
+
}
|
|
636
|
+
else {
|
|
637
|
+
result.push(`${innerPad}${INJECTED_TS_IGNORE}\n${innerPad}${line}`);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return result.join("\n");
|
|
641
|
+
}
|
|
585
642
|
function printScriptCodeFn(body, indent, state) {
|
|
586
643
|
const pad = " ".repeat(indent);
|
|
587
|
-
const
|
|
588
|
-
const lines = body.replace(/\r\n/g, "\n").split("\n");
|
|
589
|
-
const indented = lines.map((line) => (line.length === 0 ? "" : `${innerPad}${line}`)).join("\n");
|
|
644
|
+
const indented = annotateScriptLines(body, indent + 1);
|
|
590
645
|
state.imports.usesScriptInput = true;
|
|
591
646
|
return `(input: ScriptInput<Record<string, unknown>>) => {\n${indented}\n${pad}}`;
|
|
592
647
|
}
|
|
@@ -1068,7 +1123,11 @@ function printObjectLiteral(obj, state, indent, refCtx) {
|
|
|
1068
1123
|
if (entries.length === 0)
|
|
1069
1124
|
return "{}";
|
|
1070
1125
|
const pad = " ".repeat(indent);
|
|
1071
|
-
const lines = entries.map(([k, v]) =>
|
|
1126
|
+
const lines = entries.map(([k, v]) => {
|
|
1127
|
+
const isScript = (k === "code" || k === "script") && typeof v === "string";
|
|
1128
|
+
const prefix = isScript ? `${pad}// @ts-ignore\n` : "";
|
|
1129
|
+
return `${prefix}${pad}${safeKey(k)}: ${printArgValue(k, v, state, indent + 1, refCtx)},`;
|
|
1130
|
+
});
|
|
1072
1131
|
return `{\n${lines.join("\n")}\n${" ".repeat(indent - 1)}}`;
|
|
1073
1132
|
}
|
|
1074
1133
|
function printArrayLiteral(arr, state, indent, refCtx) {
|
|
@@ -12,6 +12,13 @@ export declare class ScriptCodeError extends Error {
|
|
|
12
12
|
* with expression body (wrapped into a `return`), and `function` declarations.
|
|
13
13
|
*/
|
|
14
14
|
export declare function extractScriptBody(fn: (...args: never[]) => unknown): string;
|
|
15
|
+
export declare const INJECTED_TS_IGNORE = "// @ts-ignore edk:injected";
|
|
16
|
+
/**
|
|
17
|
+
* Strips `// @ts-ignore edk:injected` directive lines that were injected
|
|
18
|
+
* by the pull printer to suppress `noImplicitAny` errors in untyped script bodies.
|
|
19
|
+
* Legitimate user-authored `// @ts-ignore` comments are preserved.
|
|
20
|
+
*/
|
|
21
|
+
export declare function stripTsIgnoreLines(code: string): string;
|
|
15
22
|
/**
|
|
16
23
|
* Infer the executeScript output schema (property name → authoring type
|
|
17
24
|
* alias) from the script body's `return {...}` object literals — the runtime
|
|
@@ -109,8 +109,21 @@ export function extractScriptBody(fn) {
|
|
|
109
109
|
throw new ScriptCodeError("executeScript code: could not extract a script body from the function source — " +
|
|
110
110
|
"author it as `(input) => { ... return {...}; }`.");
|
|
111
111
|
}
|
|
112
|
+
export const INJECTED_TS_IGNORE = "// @ts-ignore edk:injected";
|
|
113
|
+
/**
|
|
114
|
+
* Strips `// @ts-ignore edk:injected` directive lines that were injected
|
|
115
|
+
* by the pull printer to suppress `noImplicitAny` errors in untyped script bodies.
|
|
116
|
+
* Legitimate user-authored `// @ts-ignore` comments are preserved.
|
|
117
|
+
*/
|
|
118
|
+
export function stripTsIgnoreLines(code) {
|
|
119
|
+
return code
|
|
120
|
+
.replace(/\r\n/g, "\n")
|
|
121
|
+
.split("\n")
|
|
122
|
+
.filter((line) => !/^\s*\/\/\s*@ts-ignore\s+edk:injected\s*$/.test(line))
|
|
123
|
+
.join("\n");
|
|
124
|
+
}
|
|
112
125
|
function finishBody(rawBody, rawParams, fullSrc) {
|
|
113
|
-
const body = dedent(rawBody.replace(/^\n+/, "").replace(/\s+$/, ""));
|
|
126
|
+
const body = dedent(stripTsIgnoreLines(rawBody).replace(/^\n+/, "").replace(/\s+$/, ""));
|
|
114
127
|
const params = collectParamNames(rawParams);
|
|
115
128
|
const unknown = freeIdentifiers(body, params);
|
|
116
129
|
if (unknown.length > 0) {
|
|
@@ -644,8 +657,9 @@ function scanExecuteScriptBodies(src) {
|
|
|
644
657
|
const name = unquoteIfStringLiteral(call.args[0]);
|
|
645
658
|
if (name !== undefined) {
|
|
646
659
|
const body = extractCodeBody(call.args[1]);
|
|
647
|
-
if (body !== undefined)
|
|
648
|
-
result.set(name, dedent(body.replace(/^\n+/, "").replace(/\s+$/, "")));
|
|
660
|
+
if (body !== undefined) {
|
|
661
|
+
result.set(name, dedent(stripTsIgnoreLines(body).replace(/^\n+/, "").replace(/\s+$/, "")));
|
|
662
|
+
}
|
|
649
663
|
}
|
|
650
664
|
}
|
|
651
665
|
}
|
|
@@ -1452,6 +1452,15 @@ function filterReferenceToTf(value, refs, role = "value", realType) {
|
|
|
1452
1452
|
if (isUuid(fieldKey)) {
|
|
1453
1453
|
return `trigger.${value.name}`;
|
|
1454
1454
|
}
|
|
1455
|
+
// unresolvedField()'s value-position escape tags the same
|
|
1456
|
+
// unresolvable field with UNRESOLVED_FIELD_MARKER instead of a bare
|
|
1457
|
+
// uuid (see wireRefName's matching check). Without this, the marker
|
|
1458
|
+
// fails the isUuid check above and falls through to the generic
|
|
1459
|
+
// `.refs[...]` lookup below, which is the wrong wire convention for
|
|
1460
|
+
// a filter reference and points at a refs-map key that doesn't exist.
|
|
1461
|
+
if (fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)) {
|
|
1462
|
+
return `trigger.${value.name.replace(UNRESOLVED_FIELD_MARKER, "")}`;
|
|
1463
|
+
}
|
|
1455
1464
|
}
|
|
1456
1465
|
const triggerRefKey = triggerWireRefName(value.name, refs);
|
|
1457
1466
|
if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
|
|
@@ -37,6 +37,8 @@ export interface DashboardToTfOptions {
|
|
|
37
37
|
readonly ownerResourceType?: "elementum_app" | "elementum_element";
|
|
38
38
|
readonly orgRefs?: OrgRefLookup;
|
|
39
39
|
readonly workspaceAspects?: ReadonlyMap<string, WorkspaceAspect>;
|
|
40
|
+
/** Chart files actually present for this owner in the current workspace build. */
|
|
41
|
+
readonly availableChartRefNames?: ReadonlySet<string>;
|
|
40
42
|
readonly diagnostics: string[];
|
|
41
43
|
}
|
|
42
44
|
export declare function dashboardsToTf(dashboards: Readonly<Record<string, AppDashboardWire>> | undefined, opts: DashboardToTfOptions): TfBlock[];
|
|
@@ -98,6 +98,10 @@ function resolveChart(value, where, opts) {
|
|
|
98
98
|
opts.diagnostics.push(`${where}: chart belongs to ${JSON.stringify(value.parent)}, not dashboard owner ${JSON.stringify(opts.ownerRefName)}; dropped`);
|
|
99
99
|
return undefined;
|
|
100
100
|
}
|
|
101
|
+
if (opts.availableChartRefNames !== undefined && !opts.availableChartRefNames.has(refName)) {
|
|
102
|
+
opts.diagnostics.push(`${where}: chart ref ${JSON.stringify(refName)} has no available chart resource; dropped`);
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
101
105
|
return expr.resourceAttr(CHART_RESOURCE_TYPE, scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(refName), opts.scope), ["id"]);
|
|
102
106
|
}
|
|
103
107
|
function resolveAspect(value, where, opts) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
|
|
1
|
+
import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
|
|
2
2
|
import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
|
|
3
3
|
import { EntityTfError } from "../../engine/entity.js";
|
|
4
4
|
import { isTfExpr, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
@@ -71,7 +71,7 @@ export function tableDataminesFromTf(blocks, tableTfLabel, columnKeyByName, ctx,
|
|
|
71
71
|
field: (value) => ({
|
|
72
72
|
kind: "tableColumn",
|
|
73
73
|
tableRefName: tfLabelToTsLabel(tableTfLabel),
|
|
74
|
-
columnRefName: tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, where),
|
|
74
|
+
columnRefName: tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, ctx, where),
|
|
75
75
|
}),
|
|
76
76
|
reference: () => { throw new EntityTfError(`${where}.filter: datamine filters do not support reference values`); },
|
|
77
77
|
}),
|
|
@@ -81,7 +81,7 @@ export function tableDataminesFromTf(blocks, tableTfLabel, columnKeyByName, ctx,
|
|
|
81
81
|
}];
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
-
function tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, where) {
|
|
84
|
+
function tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, ctx, where) {
|
|
85
85
|
if (typeof value === "string") {
|
|
86
86
|
return columnKeyById.get(value) ?? columnKeyByName.get(value) ?? value;
|
|
87
87
|
}
|
|
@@ -94,5 +94,25 @@ function tableColumnKey(value, tableTfLabel, columnKeyByName, columnKeyById, whe
|
|
|
94
94
|
if (key !== undefined)
|
|
95
95
|
return key;
|
|
96
96
|
}
|
|
97
|
+
const fieldLabel = dataRefLabel(value, "elementum_field");
|
|
98
|
+
if (fieldLabel !== undefined) {
|
|
99
|
+
const attrs = ctx.dataAttrs?.("elementum_field", fieldLabel);
|
|
100
|
+
if (attrs === undefined) {
|
|
101
|
+
throw new EntityTfError(`${where}.filter: data.elementum_field.${fieldLabel} has no matching data block`);
|
|
102
|
+
}
|
|
103
|
+
const ownerLabel = resourceRefLabel(attrs["object_id"], "elementum_table")
|
|
104
|
+
?? dataRefLabel(attrs["object_id"], "elementum_table");
|
|
105
|
+
if (ownerLabel !== tableTfLabel) {
|
|
106
|
+
throw new EntityTfError(`${where}.filter: data.elementum_field.${fieldLabel}.object_id does not reference elementum_table.${tableTfLabel}`);
|
|
107
|
+
}
|
|
108
|
+
const name = attrs["name"];
|
|
109
|
+
if (typeof name !== "string" || name === "") {
|
|
110
|
+
throw new EntityTfError(`${where}.filter: data.elementum_field.${fieldLabel}.name has no string name`);
|
|
111
|
+
}
|
|
112
|
+
const key = columnKeyByName.get(name);
|
|
113
|
+
if (key !== undefined)
|
|
114
|
+
return key;
|
|
115
|
+
throw new EntityTfError(`${where}.filter: data.elementum_field.${fieldLabel}.name does not resolve to a column on elementum_table.${tableTfLabel}`);
|
|
116
|
+
}
|
|
97
117
|
throw new EntityTfError(`${where}.filter: field does not resolve to a column on this table`);
|
|
98
118
|
}
|
package/package.json
CHANGED