@elementumai/edk 0.9.18 → 0.9.20
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 +154 -9
- package/dist-sdk/src/catalog/factories.d.ts +35 -1
- package/dist-sdk/src/catalog/factories.js +36 -0
- package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
- package/dist-sdk/src/catalog/from-authoring.js +34 -9
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +2 -2
- package/dist-sdk/src/catalog/org.d.ts +39 -1
- package/dist-sdk/src/catalog/org.js +460 -50
- package/dist-sdk/src/catalog/render.js +6 -6
- package/dist-sdk/src/catalog/token.js +7 -0
- package/dist-sdk/src/catalog/types.d.ts +44 -1
- package/dist-sdk/src/catalog/types.js +13 -0
- package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
- package/dist-sdk/src/core/triggers/on-demand.js +10 -2
- package/dist-sdk/src/engine/build/context.d.ts +1 -1
- package/dist-sdk/src/engine/ei/run.d.ts +149 -0
- package/dist-sdk/src/engine/ei/run.js +1132 -0
- package/dist-sdk/src/engine/logging.d.ts +17 -0
- package/dist-sdk/src/engine/logging.js +18 -0
- package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
- package/dist-sdk/src/engine/pull/ref-only.js +64 -27
- package/dist-sdk/src/engine/pull/result-output.d.ts +8 -0
- package/dist-sdk/src/engine/pull/result-output.js +88 -4
- package/dist-sdk/src/engine/tf/expr.js +39 -14
- package/dist-sdk/src/engine/tf/index.d.ts +3 -3
- package/dist-sdk/src/engine/tf/index.js +2 -2
- package/dist-sdk/src/engine/tf/labels.d.ts +8 -0
- package/dist-sdk/src/engine/tf/labels.js +13 -0
- package/dist-sdk/src/engine/tf/model.d.ts +22 -1
- package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
- package/dist-sdk/src/engine/tf/parse.js +197 -10
- package/dist-sdk/src/engine/tf/render.d.ts +4 -2
- package/dist-sdk/src/engine/tf/render.js +41 -7
- package/dist-sdk/src/engine/validation.d.ts +39 -0
- package/dist-sdk/src/engine/validation.js +85 -0
- package/dist-sdk/src/engine/workspace/loader.js +49 -12
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
- package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +16 -6
- package/dist-sdk/src/entities/agent/build.d.ts +4 -16
- package/dist-sdk/src/entities/agent/build.js +40 -5
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
- package/dist-sdk/src/entities/agent/to-tf.js +6 -3
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +29 -6
- package/dist-sdk/src/entities/app/build.d.ts +98 -19
- package/dist-sdk/src/entities/app/build.js +51 -19
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
- package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
- package/dist-sdk/src/entities/app/from-tf.js +11 -5
- package/dist-sdk/src/entities/app/index.d.ts +6 -5
- package/dist-sdk/src/entities/app/index.js +2 -0
- package/dist-sdk/src/entities/app/module.js +18 -2
- package/dist-sdk/src/entities/app/to-tf.js +21 -11
- package/dist-sdk/src/entities/automation/build.d.ts +49 -6
- package/dist-sdk/src/entities/automation/build.js +163 -19
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +320 -39
- package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
- package/dist-sdk/src/entities/automation/from-tf.js +563 -74
- package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
- package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
- package/dist-sdk/src/entities/automation/index.d.ts +2 -2
- package/dist-sdk/src/entities/automation/index.js +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +2 -0
- package/dist-sdk/src/entities/automation/module.js +93 -8
- package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
- package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
- package/dist-sdk/src/entities/automation/script-code.js +91 -5
- package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
- package/dist-sdk/src/entities/automation/system-ref-name.js +48 -0
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +47 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +53 -4
- package/dist-sdk/src/entities/automation/tasks.js +38 -9
- package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
- package/dist-sdk/src/entities/automation/to-tf.js +647 -167
- package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
- package/dist-sdk/src/entities/automation/triggers.js +4 -0
- package/dist-sdk/src/entities/automation/types.js +1 -0
- package/dist-sdk/src/entities/chart/from-tf.js +33 -17
- package/dist-sdk/src/entities/chart/module.js +3 -1
- package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
- package/dist-sdk/src/entities/chart/printer.js +26 -16
- package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
- package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
- package/dist-sdk/src/entities/chart/to-tf.js +21 -12
- package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
- package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
- package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
- package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +72 -30
- package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
- package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
- package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
- package/dist-sdk/src/entities/element/build.d.ts +33 -13
- package/dist-sdk/src/entities/element/build.js +5 -1
- package/dist-sdk/src/entities/element/from-tf.d.ts +12 -0
- package/dist-sdk/src/entities/element/from-tf.js +64 -3
- package/dist-sdk/src/entities/element/index.d.ts +5 -2
- package/dist-sdk/src/entities/element/index.js +2 -0
- package/dist-sdk/src/entities/element/module.js +11 -3
- package/dist-sdk/src/entities/element/to-tf.js +20 -2
- package/dist-sdk/src/entities/field/build.d.ts +14 -1
- package/dist-sdk/src/entities/field/build.js +3 -0
- package/dist-sdk/src/entities/field/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/field/from-tf.js +50 -1
- package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
- package/dist-sdk/src/entities/field/media-types.js +30 -0
- package/dist-sdk/src/entities/field/module.js +1 -0
- package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
- package/dist-sdk/src/entities/field/to-tf.js +142 -22
- package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
- package/dist-sdk/src/entities/file-reader/module.js +1 -0
- package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
- package/dist-sdk/src/entities/file-reader/types.js +1 -1
- package/dist-sdk/src/entities/portal/build.d.ts +26 -0
- package/dist-sdk/src/entities/portal/build.js +37 -0
- package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
- package/dist-sdk/src/entities/portal/from-tf.js +75 -0
- package/dist-sdk/src/entities/portal/index.d.ts +1 -0
- package/dist-sdk/src/entities/portal/index.js +1 -0
- package/dist-sdk/src/entities/portal/module.d.ts +3 -0
- package/dist-sdk/src/entities/portal/module.js +28 -0
- package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
- package/dist-sdk/src/entities/portal/to-tf.js +73 -0
- package/dist-sdk/src/entities/portal/types.d.ts +1 -0
- package/dist-sdk/src/entities/portal/types.js +1 -0
- package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
- package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
- package/dist-sdk/src/entities/relationship/module.js +2 -0
- package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
- package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +10 -0
- package/dist-sdk/src/entities/relationship/to-tf.js +31 -13
- package/dist-sdk/src/entities/search-table/module.js +1 -0
- package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
- package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
- package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
- package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
- package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
- package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
- package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
- package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -2
- package/dist-sdk/src/entities/shared/filters/index.d.ts +25 -2
- package/dist-sdk/src/entities/shared/filters/index.js +38 -5
- package/dist-sdk/src/entities/shared/filters/print.js +31 -3
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +25 -3
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +51 -15
- package/dist-sdk/src/entities/shared/filters/types.d.ts +22 -5
- package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
- package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
- package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
- package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
- package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
- package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
- package/dist-sdk/src/entities/skill/access-policy.js +101 -0
- package/dist-sdk/src/entities/skill/build.d.ts +3 -0
- package/dist-sdk/src/entities/skill/build.js +3 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +23 -1
- package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill/from-tf.js +70 -22
- package/dist-sdk/src/entities/skill/index.d.ts +2 -0
- package/dist-sdk/src/entities/skill/index.js +1 -0
- package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
- package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
- package/dist-sdk/src/entities/skill/module.js +1 -0
- package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/skill/to-tf.js +19 -6
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -6
- package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
- package/dist-sdk/src/entities/table/catalog.js +66 -0
- package/dist-sdk/src/entities/table/module.js +2 -1
- package/dist-sdk/src/entities/table/to-tf.js +5 -5
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +89 -0
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +277 -0
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +51 -0
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +360 -0
- package/dist-sdk/src/entities/view/agent-view-layout.d.ts +151 -0
- package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
- package/dist-sdk/src/entities/view/from-tf.d.ts +6 -3
- package/dist-sdk/src/entities/view/from-tf.js +161 -14
- package/dist-sdk/src/entities/view/module.js +30 -3
- package/dist-sdk/src/entities/view/to-tf.d.ts +24 -2
- package/dist-sdk/src/entities/view/to-tf.js +95 -9
- package/dist-sdk/src/entities/view/types.d.ts +4 -15
- package/dist-sdk/src/entities/view/types.js +17 -15
- package/dist-sdk/src/entities/widget/build.d.ts +16 -1
- package/dist-sdk/src/entities/widget/build.js +11 -1
- package/dist-sdk/src/entities/widget/to-tf.js +36 -10
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +38 -10
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +54 -0
- package/dist-sdk/src/graph/index.js +30 -0
- package/dist-sdk/src/graph/modules.js +2 -0
- package/dist-sdk/src/graph/types.d.ts +133 -2
- package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
- package/dist-sdk/src/internal/sdk-package.js +1 -0
- package/package.json +11 -1
|
@@ -13,8 +13,45 @@
|
|
|
13
13
|
import { decodeTemplateEscapes } from "./escape.js";
|
|
14
14
|
import { parseStringValue, TfExprError } from "./expr.js";
|
|
15
15
|
let runtimeParser;
|
|
16
|
+
let batchParser;
|
|
16
17
|
let packageParser;
|
|
17
18
|
const HCL2JSON_PACKAGE = `@cdktf/${"hcl2json"}`;
|
|
19
|
+
/**
|
|
20
|
+
* Converted hcl2json output keyed by source text. Pull normalizers re-read the
|
|
21
|
+
* whole export directory several times; unchanged files reuse the conversion.
|
|
22
|
+
* Safe to share because conversion below never mutates the raw objects.
|
|
23
|
+
*/
|
|
24
|
+
const rawCache = new Map();
|
|
25
|
+
const RAW_CACHE_MAX_TEXT_CHARS = 64 * 1024 * 1024;
|
|
26
|
+
let rawCacheTextChars = 0;
|
|
27
|
+
function cacheRaw(text, raw) {
|
|
28
|
+
if (text.length > RAW_CACHE_MAX_TEXT_CHARS)
|
|
29
|
+
return;
|
|
30
|
+
if (rawCache.has(text))
|
|
31
|
+
return;
|
|
32
|
+
while (rawCacheTextChars + text.length > RAW_CACHE_MAX_TEXT_CHARS) {
|
|
33
|
+
const oldest = rawCache.keys().next();
|
|
34
|
+
if (oldest.done === true)
|
|
35
|
+
break;
|
|
36
|
+
rawCache.delete(oldest.value);
|
|
37
|
+
rawCacheTextChars -= oldest.value.length;
|
|
38
|
+
}
|
|
39
|
+
rawCache.set(text, raw);
|
|
40
|
+
rawCacheTextChars += text.length;
|
|
41
|
+
}
|
|
42
|
+
/** Test seam: forget cached conversions. */
|
|
43
|
+
export function clearHclParseCache() {
|
|
44
|
+
rawCache.clear();
|
|
45
|
+
rawCacheTextChars = 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Install a batch converter (the CLI's native bridge). Batch reads prefer it;
|
|
49
|
+
* when it throws, parsing falls back to the WASM parser for the rest of the
|
|
50
|
+
* process.
|
|
51
|
+
*/
|
|
52
|
+
export function installHcl2JsonBatchRuntime(parser) {
|
|
53
|
+
batchParser = parser;
|
|
54
|
+
}
|
|
18
55
|
/**
|
|
19
56
|
* The Bun executable installs an embedded-WASM parser before loading the CLI.
|
|
20
57
|
* Node/SDK consumers keep using the upstream package directly.
|
|
@@ -207,14 +244,76 @@ function hasLiteralBackendValue(body, key) {
|
|
|
207
244
|
return typeof value === "string" && value !== "" && !value.startsWith("${");
|
|
208
245
|
}
|
|
209
246
|
export async function parseHcl(text) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
247
|
+
const [result] = await parseHclDocuments([text]);
|
|
248
|
+
if (result instanceof Error)
|
|
249
|
+
throw result;
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Parse many HCL texts, in order. A document that fails yields its
|
|
254
|
+
* TfParseError in place so one bad file never hides the others.
|
|
255
|
+
*/
|
|
256
|
+
export async function parseHclDocuments(texts) {
|
|
257
|
+
const raws = texts.map((text) => {
|
|
258
|
+
try {
|
|
259
|
+
assertNoUnsafeIntegers(text);
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
return e instanceof TfParseError ? e : new TfParseError(String(e));
|
|
263
|
+
}
|
|
264
|
+
return rawCache.get(text);
|
|
265
|
+
});
|
|
266
|
+
const pending = texts.flatMap((text, index) => (raws[index] === undefined ? [{ text, index }] : []));
|
|
267
|
+
if (pending.length > 0) {
|
|
268
|
+
const converted = await convertWithHcl2Json(pending.map(({ text }) => text));
|
|
269
|
+
pending.forEach(({ text, index }, i) => {
|
|
270
|
+
const raw = converted[i];
|
|
271
|
+
if (raw instanceof Error) {
|
|
272
|
+
raws[index] = new TfParseError(`HCL parse failed: ${raw.message}`);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
cacheRaw(text, raw);
|
|
276
|
+
raws[index] = raw;
|
|
277
|
+
});
|
|
214
278
|
}
|
|
215
|
-
|
|
216
|
-
|
|
279
|
+
return raws.map((raw) => {
|
|
280
|
+
if (raw instanceof TfParseError)
|
|
281
|
+
return raw;
|
|
282
|
+
try {
|
|
283
|
+
return documentFromHcl2Json(raw);
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
if (e instanceof TfParseError)
|
|
287
|
+
return e;
|
|
288
|
+
throw e;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
async function convertWithHcl2Json(texts) {
|
|
293
|
+
const inputs = texts.map((contents) => ({ filename: "edk-parse.tf", contents }));
|
|
294
|
+
if (batchParser !== undefined) {
|
|
295
|
+
try {
|
|
296
|
+
const results = await batchParser(inputs);
|
|
297
|
+
if (results.length === inputs.length)
|
|
298
|
+
return results;
|
|
299
|
+
throw new Error(`batch HCL parser returned ${results.length} results for ${inputs.length} documents`);
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
batchParser = undefined;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const results = [];
|
|
306
|
+
for (const input of inputs) {
|
|
307
|
+
try {
|
|
308
|
+
results.push(await parseWithHcl2Json(input.filename, input.contents));
|
|
309
|
+
}
|
|
310
|
+
catch (e) {
|
|
311
|
+
results.push(e instanceof Error ? e : new Error(String(e)));
|
|
312
|
+
}
|
|
217
313
|
}
|
|
314
|
+
return results;
|
|
315
|
+
}
|
|
316
|
+
function documentFromHcl2Json(raw) {
|
|
218
317
|
const blocks = [];
|
|
219
318
|
for (const key of Object.keys(raw)) {
|
|
220
319
|
if (!KNOWN_TOP_LEVEL.has(key)) {
|
|
@@ -229,7 +328,14 @@ export async function parseHcl(text) {
|
|
|
229
328
|
for (const [type, byLabel] of Object.entries(byType)) {
|
|
230
329
|
for (const [label, bodies] of Object.entries(byLabel)) {
|
|
231
330
|
for (const body of bodies) {
|
|
232
|
-
|
|
331
|
+
const ctx = `${kind}.${type}.${label}`;
|
|
332
|
+
if (kind === "resource" && isRecord(body) && "lifecycle" in body) {
|
|
333
|
+
const { lifecycle, ...rest } = body;
|
|
334
|
+
blocks.push({ kind, type, label, attrs: convertBody(rest, ctx), lifecycle: convertLifecycle(lifecycle, ctx) });
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
blocks.push({ kind, type, label, attrs: convertBody(body, ctx) });
|
|
338
|
+
}
|
|
233
339
|
}
|
|
234
340
|
}
|
|
235
341
|
}
|
|
@@ -255,8 +361,20 @@ export async function parseHcl(text) {
|
|
|
255
361
|
const variables = raw["variable"];
|
|
256
362
|
if (variables) {
|
|
257
363
|
for (const [name, bodies] of Object.entries(variables)) {
|
|
258
|
-
for (const body of bodies)
|
|
259
|
-
|
|
364
|
+
for (const body of bodies) {
|
|
365
|
+
if (isRecord(body) && "validation" in body) {
|
|
366
|
+
const { validation, ...rest } = body;
|
|
367
|
+
blocks.push({
|
|
368
|
+
kind: "variable",
|
|
369
|
+
label: name,
|
|
370
|
+
attrs: convertBody(rest, `variable.${name}`),
|
|
371
|
+
variableValidation: convertVariableValidation(validation, `variable.${name}`),
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
blocks.push({ kind: "variable", label: name, attrs: convertBody(body, `variable.${name}`) });
|
|
376
|
+
}
|
|
377
|
+
}
|
|
260
378
|
}
|
|
261
379
|
}
|
|
262
380
|
const terraformBodies = raw["terraform"];
|
|
@@ -267,6 +385,39 @@ export async function parseHcl(text) {
|
|
|
267
385
|
}
|
|
268
386
|
return { blocks };
|
|
269
387
|
}
|
|
388
|
+
function isRecord(value) {
|
|
389
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
390
|
+
}
|
|
391
|
+
const BARE_REFERENCE_RE = /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/;
|
|
392
|
+
/**
|
|
393
|
+
* hcl2json reads `lifecycle { ignore_changes = all }` as
|
|
394
|
+
* `[{ "ignore_changes": "${all}" }]` and a name list as `["${name}", ...]`.
|
|
395
|
+
* Only that one shape is accepted — any other lifecycle setting stays loud.
|
|
396
|
+
*/
|
|
397
|
+
function convertLifecycle(value, ctx) {
|
|
398
|
+
const at = `${ctx}.lifecycle`;
|
|
399
|
+
if (!Array.isArray(value) || value.length !== 1 || !isRecord(value[0])) {
|
|
400
|
+
throw new TfParseError(`unexpected lifecycle block shape at ${at}`);
|
|
401
|
+
}
|
|
402
|
+
const keys = Object.keys(value[0]);
|
|
403
|
+
if (keys.length !== 1 || keys[0] !== "ignore_changes") {
|
|
404
|
+
throw new TfParseError(`at ${at}: only ignore_changes is supported, got ${keys.join(", ") || "nothing"}`);
|
|
405
|
+
}
|
|
406
|
+
const ignore = value[0]["ignore_changes"];
|
|
407
|
+
if (ignore === "${all}")
|
|
408
|
+
return { ignoreChanges: "all" };
|
|
409
|
+
if (Array.isArray(ignore)) {
|
|
410
|
+
return {
|
|
411
|
+
ignoreChanges: ignore.map((entry) => {
|
|
412
|
+
const match = typeof entry === "string" ? BARE_REFERENCE_RE.exec(entry) : null;
|
|
413
|
+
if (match === null)
|
|
414
|
+
throw new TfParseError(`at ${at}.ignore_changes: expected attribute names, got ${JSON.stringify(entry)}`);
|
|
415
|
+
return match[1];
|
|
416
|
+
}),
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
throw new TfParseError(`at ${at}.ignore_changes: expected all or a list of attribute names`);
|
|
420
|
+
}
|
|
270
421
|
function convertBody(body, ctx) {
|
|
271
422
|
if (typeof body !== "object" || body === null || Array.isArray(body)) {
|
|
272
423
|
throw new TfParseError(`unexpected block body shape at ${ctx}`);
|
|
@@ -284,7 +435,7 @@ function convertValue(value, ctx) {
|
|
|
284
435
|
return value;
|
|
285
436
|
if (typeof value === "string") {
|
|
286
437
|
try {
|
|
287
|
-
return parseStringValue(value, { allowVariables:
|
|
438
|
+
return parseStringValue(value, { allowVariables: allowsVariableReference(ctx) });
|
|
288
439
|
}
|
|
289
440
|
catch (e) {
|
|
290
441
|
if (e instanceof TfExprError) {
|
|
@@ -310,10 +461,46 @@ function convertValue(value, ctx) {
|
|
|
310
461
|
}
|
|
311
462
|
throw new TfParseError(`unsupported value type "${typeof value}" at ${ctx}`);
|
|
312
463
|
}
|
|
464
|
+
function allowsVariableReference(ctx) {
|
|
465
|
+
return isCredentialVariableContext(ctx) || isWriteOnlyApiSecretContext(ctx);
|
|
466
|
+
}
|
|
313
467
|
function isCredentialVariableContext(ctx) {
|
|
468
|
+
// Resource types stay inside regex literals. src/engine must not contain
|
|
469
|
+
// quoted elementum_* resource-type strings.
|
|
314
470
|
return /^resource\.elementum_cloudlink\.[^.]+\.credentials(?:\.|$)/.test(ctx) ||
|
|
315
471
|
/^resource\.elementum_phone_provider\.[^.]+\.twilio(?:\.|$)/.test(ctx);
|
|
316
472
|
}
|
|
473
|
+
function isWriteOnlyApiSecretContext(ctx) {
|
|
474
|
+
return /^resource\.elementum_api_task\.[^.]+\.headers\[\d+\]\.value$/.test(ctx) ||
|
|
475
|
+
/^resource\.elementum_api_task\.[^.]+\.basic_auth\.username$/.test(ctx);
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* hcl2json reads `validation { condition = var.x != "" }` as
|
|
479
|
+
* `[{ condition: "${var.x != \"\"}", error_message: "..." }]`. The condition
|
|
480
|
+
* is not a closed-grammar expression, so it is preserved as raw text.
|
|
481
|
+
*/
|
|
482
|
+
function convertVariableValidation(value, ctx) {
|
|
483
|
+
const at = `${ctx}.validation`;
|
|
484
|
+
if (!Array.isArray(value) || value.length !== 1 || !isRecord(value[0])) {
|
|
485
|
+
throw new TfParseError(`unexpected validation block shape at ${at}`);
|
|
486
|
+
}
|
|
487
|
+
const condition = unwrapHclExpr(value[0]["condition"]);
|
|
488
|
+
const errorMessage = value[0]["error_message"];
|
|
489
|
+
if (condition === undefined || condition === "") {
|
|
490
|
+
throw new TfParseError(`at ${at}: validation condition must be an expression`);
|
|
491
|
+
}
|
|
492
|
+
if (typeof errorMessage !== "string") {
|
|
493
|
+
throw new TfParseError(`at ${at}: validation error_message must be a string`);
|
|
494
|
+
}
|
|
495
|
+
return { condition, errorMessage };
|
|
496
|
+
}
|
|
497
|
+
function unwrapHclExpr(value) {
|
|
498
|
+
if (typeof value !== "string")
|
|
499
|
+
return undefined;
|
|
500
|
+
if (value.startsWith("${") && value.endsWith("}") && value.length >= 3)
|
|
501
|
+
return value.slice(2, -1);
|
|
502
|
+
return value;
|
|
503
|
+
}
|
|
317
504
|
/**
|
|
318
505
|
* Refuse to parse text whose integer literals exceed Number.MAX_SAFE_INTEGER —
|
|
319
506
|
* hcl2json would round them silently (verified: 2^53+1 → 2^53).
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
* Formatting is OURS (deterministic, 2-space indent, attrs sorted
|
|
6
6
|
* alphabetically) — ei's incidental formatting is not replicated; the
|
|
7
7
|
* round-trip check is structural, both sides parsed by the same parser.
|
|
8
|
-
* The ei dialect is attributes-only (verified across real exports)
|
|
9
|
-
* nested
|
|
8
|
+
* The ei resource dialect is attributes-only (verified across real exports).
|
|
9
|
+
* Two nested blocks are emitted outside that dialect: a resource's
|
|
10
|
+
* `lifecycle`, which only smart apply sets, and a variable's `validation`,
|
|
11
|
+
* which only a required write-only secret sets.
|
|
10
12
|
*/
|
|
11
13
|
import type { TfBlock, TfDocument } from "./model.js";
|
|
12
14
|
export declare function renderDocument(doc: TfDocument): string;
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
* Formatting is OURS (deterministic, 2-space indent, attrs sorted
|
|
6
6
|
* alphabetically) — ei's incidental formatting is not replicated; the
|
|
7
7
|
* round-trip check is structural, both sides parsed by the same parser.
|
|
8
|
-
* The ei dialect is attributes-only (verified across real exports)
|
|
9
|
-
* nested
|
|
8
|
+
* The ei resource dialect is attributes-only (verified across real exports).
|
|
9
|
+
* Two nested blocks are emitted outside that dialect: a resource's
|
|
10
|
+
* `lifecycle`, which only smart apply sets, and a variable's `validation`,
|
|
11
|
+
* which only a required write-only secret sets.
|
|
10
12
|
*/
|
|
11
13
|
import { quoteHclString } from "./escape.js";
|
|
12
14
|
import { isTfExpr } from "./model.js";
|
|
@@ -15,11 +17,40 @@ export function renderDocument(doc) {
|
|
|
15
17
|
}
|
|
16
18
|
export function renderBlock(block) {
|
|
17
19
|
const header = blockHeader(block);
|
|
18
|
-
const
|
|
20
|
+
const lines = Object.entries(block.attrs)
|
|
19
21
|
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
20
|
-
.map(([key, value]) => ` ${key} = ${renderValue(value, 1)}`)
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
.map(([key, value]) => ` ${key} = ${renderValue(value, 1)}`);
|
|
23
|
+
if (block.lifecycle !== undefined) {
|
|
24
|
+
if (block.kind !== "resource")
|
|
25
|
+
throw new Error(`a lifecycle block is only valid on a resource, not ${block.kind}`);
|
|
26
|
+
lines.push(renderLifecycle(block.lifecycle));
|
|
27
|
+
}
|
|
28
|
+
if (block.variableValidation !== undefined) {
|
|
29
|
+
if (block.kind !== "variable")
|
|
30
|
+
throw new Error(`a validation block is only valid on a variable, not ${block.kind}`);
|
|
31
|
+
lines.push(renderVariableValidation(block.label, block.variableValidation));
|
|
32
|
+
}
|
|
33
|
+
return `${header} {\n${lines.join("\n")}\n}\n`;
|
|
34
|
+
}
|
|
35
|
+
const ATTRIBUTE_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
36
|
+
function renderLifecycle(lifecycle) {
|
|
37
|
+
if (lifecycle.ignoreChanges === "all")
|
|
38
|
+
return " lifecycle {\n ignore_changes = all\n }";
|
|
39
|
+
const names = lifecycle.ignoreChanges.map((name) => {
|
|
40
|
+
if (!ATTRIBUTE_NAME_RE.test(name))
|
|
41
|
+
throw new Error(`ignore_changes names a top-level attribute, got "${name}"`);
|
|
42
|
+
return name;
|
|
43
|
+
});
|
|
44
|
+
return ` lifecycle {\n ignore_changes = [${names.join(", ")}]\n }`;
|
|
45
|
+
}
|
|
46
|
+
const REQUIRED_SECRET_CONDITION = /^var\.[A-Za-z_][A-Za-z0-9_]* != ""$/;
|
|
47
|
+
function renderVariableValidation(label, validation) {
|
|
48
|
+
if (!label || !ATTRIBUTE_NAME_RE.test(label))
|
|
49
|
+
throw new Error(`variable validation needs an identifier name, got "${label ?? ""}"`);
|
|
50
|
+
if (!REQUIRED_SECRET_CONDITION.test(validation.condition)) {
|
|
51
|
+
throw new Error(`variable ${label} validation condition must refuse an empty value`);
|
|
52
|
+
}
|
|
53
|
+
return ` validation {\n condition = ${validation.condition}\n error_message = ${quoteHclString(validation.errorMessage)}\n }`;
|
|
23
54
|
}
|
|
24
55
|
function blockHeader(block) {
|
|
25
56
|
switch (block.kind) {
|
|
@@ -67,8 +98,11 @@ function renderValue(value, depth) {
|
|
|
67
98
|
return `{\n${body}\n${close}}`;
|
|
68
99
|
}
|
|
69
100
|
const BARE_KEY_RE = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
101
|
+
// `for` starts a for-expression, so `{ for = 1 }` is not an object. `null`,
|
|
102
|
+
// `true`, and `false` are literals; quote them too. `if` is a valid bare key.
|
|
103
|
+
const RESERVED_OBJECT_KEYS = new Set(["false", "for", "null", "true"]);
|
|
70
104
|
function objectKey(k) {
|
|
71
|
-
return BARE_KEY_RE.test(k) ? k : quoteHclString(k);
|
|
105
|
+
return BARE_KEY_RE.test(k) && !RESERVED_OBJECT_KEYS.has(k) ? k : quoteHclString(k);
|
|
72
106
|
}
|
|
73
107
|
function renderExpr(e, depth) {
|
|
74
108
|
switch (e.$expr) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type ValidationSeverity = "fatal" | "warning";
|
|
2
|
+
export type ValidationMode = "pull" | "build";
|
|
3
|
+
export interface ValidationFailure {
|
|
4
|
+
readonly severity: ValidationSeverity;
|
|
5
|
+
/** Terraform resource address, `type.label`. */
|
|
6
|
+
readonly address: string;
|
|
7
|
+
/** Automation or agent display name. */
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly ownerKind: string;
|
|
10
|
+
readonly message: string;
|
|
11
|
+
/**
|
|
12
|
+
* A reference the live config no longer satisfies (for example a run-automation
|
|
13
|
+
* tool that does not map a newly required trigger parameter). Pull downgrades
|
|
14
|
+
* these to warnings; build/plan/apply keep them fatal.
|
|
15
|
+
*/
|
|
16
|
+
readonly staleReference?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function formatValidationFailure(failure: ValidationFailure): string;
|
|
19
|
+
export declare class ValidationFailureError extends Error {
|
|
20
|
+
readonly failures: readonly ValidationFailure[];
|
|
21
|
+
constructor(failures: readonly ValidationFailure[]);
|
|
22
|
+
}
|
|
23
|
+
/** True for this module's class and for the same-shaped error from a loader copy. */
|
|
24
|
+
export declare function isValidationFailureError(error: unknown): error is ValidationFailureError;
|
|
25
|
+
export declare function withValidationSession<T>(mode: ValidationMode, run: () => T): T;
|
|
26
|
+
export declare function withValidationSessionAsync<T>(mode: ValidationMode, run: () => Promise<T>): Promise<T>;
|
|
27
|
+
export declare function currentValidationMode(): ValidationMode | undefined;
|
|
28
|
+
export declare function currentValidationScope(): {
|
|
29
|
+
readonly appTfLabel?: string;
|
|
30
|
+
readonly parentScope?: "app" | "element" | "table";
|
|
31
|
+
};
|
|
32
|
+
export declare function setValidationScope(scope: {
|
|
33
|
+
appTfLabel?: string;
|
|
34
|
+
parentScope?: "app" | "element" | "table";
|
|
35
|
+
}): void;
|
|
36
|
+
export declare function sessionValidationFailures(): readonly ValidationFailure[];
|
|
37
|
+
/** Record failures into the active session. No-op when nothing is collecting. */
|
|
38
|
+
export declare function recordValidations(incoming: readonly ValidationFailure[]): void;
|
|
39
|
+
export declare function hasFatalValidation(failures: readonly ValidationFailure[]): boolean;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collects validation failures across a pull or build instead of stopping at
|
|
3
|
+
* the first one. A stale reference is fatal while authoring (build/plan/apply)
|
|
4
|
+
* and a warning on pull, which is a read of live configuration.
|
|
5
|
+
*/
|
|
6
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
|
+
export function formatValidationFailure(failure) {
|
|
8
|
+
return `${failure.address}: ${failure.ownerKind} "${failure.name}": ${failure.message}`;
|
|
9
|
+
}
|
|
10
|
+
export class ValidationFailureError extends Error {
|
|
11
|
+
failures;
|
|
12
|
+
constructor(failures) {
|
|
13
|
+
super(failures.map(formatValidationFailure).join("\n"));
|
|
14
|
+
this.name = "ValidationFailureError";
|
|
15
|
+
this.failures = failures;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The workspace loader evaluates authored files through a second module
|
|
20
|
+
* graph (native import with a generation query, or jiti with
|
|
21
|
+
* `moduleCache: false`). A storage local to this module would be invisible
|
|
22
|
+
* to `def()` in that copy, and `instanceof` against this class would miss.
|
|
23
|
+
* One process-wide store keeps the async context shared.
|
|
24
|
+
*/
|
|
25
|
+
const STORAGE_KEY = Symbol.for("edk.validationStorage");
|
|
26
|
+
function storage() {
|
|
27
|
+
const host = globalThis;
|
|
28
|
+
host[STORAGE_KEY] ??= new AsyncLocalStorage();
|
|
29
|
+
return host[STORAGE_KEY];
|
|
30
|
+
}
|
|
31
|
+
/** True for this module's class and for the same-shaped error from a loader copy. */
|
|
32
|
+
export function isValidationFailureError(error) {
|
|
33
|
+
if (error instanceof ValidationFailureError)
|
|
34
|
+
return true;
|
|
35
|
+
if (!(error instanceof Error) || error.name !== "ValidationFailureError")
|
|
36
|
+
return false;
|
|
37
|
+
return Array.isArray(error.failures);
|
|
38
|
+
}
|
|
39
|
+
export function withValidationSession(mode, run) {
|
|
40
|
+
if (storage().getStore() !== undefined)
|
|
41
|
+
return run();
|
|
42
|
+
return storage().run({ mode, failures: [], seen: new Set() }, run);
|
|
43
|
+
}
|
|
44
|
+
export function withValidationSessionAsync(mode, run) {
|
|
45
|
+
if (storage().getStore() !== undefined)
|
|
46
|
+
return run();
|
|
47
|
+
return storage().run({ mode, failures: [], seen: new Set() }, run);
|
|
48
|
+
}
|
|
49
|
+
export function currentValidationMode() {
|
|
50
|
+
return storage().getStore()?.mode;
|
|
51
|
+
}
|
|
52
|
+
export function currentValidationScope() {
|
|
53
|
+
const session = storage().getStore();
|
|
54
|
+
return { appTfLabel: session?.appTfLabel, parentScope: session?.parentScope };
|
|
55
|
+
}
|
|
56
|
+
export function setValidationScope(scope) {
|
|
57
|
+
const session = storage().getStore();
|
|
58
|
+
if (session === undefined)
|
|
59
|
+
return;
|
|
60
|
+
if (scope.appTfLabel !== undefined)
|
|
61
|
+
session.appTfLabel = scope.appTfLabel;
|
|
62
|
+
if (scope.parentScope !== undefined)
|
|
63
|
+
session.parentScope = scope.parentScope;
|
|
64
|
+
}
|
|
65
|
+
export function sessionValidationFailures() {
|
|
66
|
+
return storage().getStore()?.failures ?? [];
|
|
67
|
+
}
|
|
68
|
+
/** Record failures into the active session. No-op when nothing is collecting. */
|
|
69
|
+
export function recordValidations(incoming) {
|
|
70
|
+
const session = storage().getStore();
|
|
71
|
+
if (session === undefined)
|
|
72
|
+
return;
|
|
73
|
+
for (const failure of incoming) {
|
|
74
|
+
const severity = failure.staleReference === true && session.mode === "pull" ? "warning" : failure.severity;
|
|
75
|
+
const recorded = severity === failure.severity ? failure : { ...failure, severity };
|
|
76
|
+
const key = `${recorded.severity}\0${recorded.address}\0${recorded.message}`;
|
|
77
|
+
if (session.seen.has(key))
|
|
78
|
+
continue;
|
|
79
|
+
session.seen.add(key);
|
|
80
|
+
session.failures.push(recorded);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function hasFatalValidation(failures) {
|
|
84
|
+
return failures.some((failure) => failure.severity === "fatal");
|
|
85
|
+
}
|
|
@@ -211,7 +211,11 @@ function registerHooksOnce() {
|
|
|
211
211
|
}
|
|
212
212
|
const resolved = nextResolveOrTsSibling(specifier, context, nextResolve, parentURL);
|
|
213
213
|
if (resolved.url.startsWith("file:")) {
|
|
214
|
-
const
|
|
214
|
+
const resolvedPath = fileURLToPath(resolved.url.split("?")[0]);
|
|
215
|
+
const resolvedRoot = owningRoot(resolvedPath);
|
|
216
|
+
if (resolvedRoot !== undefined && context.conditions?.includes("require") && resolvedPath.endsWith(".ts")) {
|
|
217
|
+
return { url: pathToFileURL(generationRequirePath(resolvedPath)).href, format: "module-typescript", shortCircuit: true };
|
|
218
|
+
}
|
|
215
219
|
if (resolvedRoot !== undefined) {
|
|
216
220
|
return { ...resolved, url: stamp(resolved.url, resolvedRoot) };
|
|
217
221
|
}
|
|
@@ -219,6 +223,10 @@ function registerHooksOnce() {
|
|
|
219
223
|
return resolved;
|
|
220
224
|
},
|
|
221
225
|
load(url, context, nextLoad) {
|
|
226
|
+
const requiredPath = url.startsWith("file:") ? realPathOfGenerationRequire(fileURLToPath(url)) : undefined;
|
|
227
|
+
if (requiredPath !== undefined) {
|
|
228
|
+
return { format: "module-typescript", source: readFileSync(requiredPath, "utf8"), shortCircuit: true };
|
|
229
|
+
}
|
|
222
230
|
// Authored source is always ESM. Without this, the module type is
|
|
223
231
|
// decided by whichever `package.json` happens to sit above the
|
|
224
232
|
// workspace — a root missing `"type": "module"` (an older workspace, or
|
|
@@ -265,6 +273,33 @@ function nextResolveOrTsSibling(specifier, context, nextResolve, parentURL) {
|
|
|
265
273
|
}
|
|
266
274
|
return nextResolve(specifier, context);
|
|
267
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* CommonJS `require` (the org barrel's lazy `catalogRequire` getters) caches
|
|
278
|
+
* by file path and drops the generation query, so a stamped URL would still
|
|
279
|
+
* hand every later generation the first module this process required. A
|
|
280
|
+
* per-generation sibling filename makes the cache key unique; the load hook
|
|
281
|
+
* serves the real file's source for it. Relative imports inside the module
|
|
282
|
+
* resolve unchanged because the virtual file shares the real one's directory.
|
|
283
|
+
*/
|
|
284
|
+
const GENERATION_REQUIRE_SUFFIX = /\.__edk_gen_\d+__\.ts$/;
|
|
285
|
+
function generationRequirePath(path) {
|
|
286
|
+
return `${path.slice(0, -".ts".length)}.__edk_gen_${stampGeneration}__.ts`;
|
|
287
|
+
}
|
|
288
|
+
function realPathOfGenerationRequire(path) {
|
|
289
|
+
return GENERATION_REQUIRE_SUFFIX.test(path) ? path.replace(GENERATION_REQUIRE_SUFFIX, ".ts") : undefined;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* CommonJS also memoizes `(parent directory, request) -> filename`, and
|
|
293
|
+
* honors that memo while the filename is still in `require.cache`. Dropping
|
|
294
|
+
* the previous generations' virtual entries forces a fresh resolve.
|
|
295
|
+
*/
|
|
296
|
+
function evictGenerationRequires() {
|
|
297
|
+
const cache = nodeModule.createRequire(import.meta.url).cache;
|
|
298
|
+
for (const key of Object.keys(cache)) {
|
|
299
|
+
if (GENERATION_REQUIRE_SUFFIX.test(key))
|
|
300
|
+
delete cache[key];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
268
303
|
function stamp(url, _root) {
|
|
269
304
|
const separator = url.includes("?") ? "&" : "?";
|
|
270
305
|
return `${url}${separator}${GENERATION_KEY}=${stampGeneration}`;
|
|
@@ -331,18 +366,20 @@ export function createWorkspaceLoader(orgRoot) {
|
|
|
331
366
|
return {
|
|
332
367
|
async import(file) {
|
|
333
368
|
return enqueueImport(async () => {
|
|
334
|
-
generation
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
try {
|
|
338
|
-
const url = pathToFileURL(resolve(file)).href;
|
|
339
|
-
// Set inside the serialized section so overlapping imports cannot
|
|
340
|
-
// see each other's file.
|
|
341
|
-
return await withImportingFile(resolve(file), () => nativeImport(`${url}?${GENERATION_KEY}=${generation}`));
|
|
342
|
-
}
|
|
343
|
-
finally {
|
|
344
|
-
stampGeneration = previous;
|
|
369
|
+
if (generation === undefined) {
|
|
370
|
+
generation = ++nextGeneration;
|
|
371
|
+
evictGenerationRequires();
|
|
345
372
|
}
|
|
373
|
+
// Deliberately left set after the import: the org barrel's lazy
|
|
374
|
+
// `catalogRequire` getters resolve when authored callbacks run, long
|
|
375
|
+
// after the import returned. Resetting would bind those reads to one
|
|
376
|
+
// stale generation for the whole process (a pull's throwaway stub
|
|
377
|
+
// catalog leaked into its own later build that way).
|
|
378
|
+
stampGeneration = generation;
|
|
379
|
+
const url = pathToFileURL(resolve(file)).href;
|
|
380
|
+
// Set inside the serialized section so overlapping imports cannot
|
|
381
|
+
// see each other's file.
|
|
382
|
+
return await withImportingFile(resolve(file), () => nativeImport(`${url}?${GENERATION_KEY}=${generation}`));
|
|
346
383
|
});
|
|
347
384
|
},
|
|
348
385
|
};
|
|
@@ -28,6 +28,8 @@ export interface AccessPolicyOwner {
|
|
|
28
28
|
readonly ownerRefName: string;
|
|
29
29
|
readonly fieldKey: string;
|
|
30
30
|
}>;
|
|
31
|
+
/** Decode a `data.elementum_field.<label>.id` owned by this owner (an unmanaged relationship target). */
|
|
32
|
+
readonly dataField?: (label: string) => RefExpr | undefined;
|
|
31
33
|
}
|
|
32
34
|
export interface NormalizedAccessPolicy {
|
|
33
35
|
readonly filter: Filter<RefExpr, RefExpr>;
|
|
@@ -35,8 +37,16 @@ export interface NormalizedAccessPolicy {
|
|
|
35
37
|
readonly groupIds?: readonly AccessPolicyGroupRef[];
|
|
36
38
|
readonly serviceAccountIds?: readonly AccessPolicyServiceAccountRef[];
|
|
37
39
|
}
|
|
40
|
+
export interface FilterFromTfOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Views keep a raw word a word, so a TEXT-wrapped option lookup must say it
|
|
43
|
+
* is an option — otherwise build rewrites the stored wrapper type. Owners
|
|
44
|
+
* that always rebuild a bare label into its lookup leave this off.
|
|
45
|
+
*/
|
|
46
|
+
readonly optionLookupsAreIdentities?: boolean;
|
|
47
|
+
}
|
|
38
48
|
/** Decode one `filter` attribute through the shared exhaustive codec. */
|
|
39
|
-
export declare function filterFromTf(value: TfValue, owner: AccessPolicyOwner, where: string, ctx?: FromTfContext): Filter<RefExpr, RefExpr>;
|
|
49
|
+
export declare function filterFromTf(value: TfValue, owner: AccessPolicyOwner, where: string, ctx?: FromTfContext, options?: FilterFromTfOptions): Filter<RefExpr, RefExpr>;
|
|
40
50
|
export declare function principalList(value: TfValue | undefined, dataType: "elementum_user", where: string, ctx: FromTfContext, owner?: AccessPolicyOwner): AccessPolicyUserRef[] | undefined;
|
|
41
51
|
export declare function principalList(value: TfValue | undefined, dataType: "elementum_group", where: string, ctx: FromTfContext, owner?: AccessPolicyOwner): AccessPolicyGroupRef[] | undefined;
|
|
42
52
|
export declare function principalList(value: TfValue | undefined, dataType: "elementum_service_account", where: string, ctx: FromTfContext, owner?: AccessPolicyOwner): AccessPolicyServiceAccountRef[] | undefined;
|
|
@@ -50,6 +50,10 @@ function fieldRef(value, owner, where) {
|
|
|
50
50
|
}
|
|
51
51
|
return { kind: "unresolved", uuid: value, hint: "field" };
|
|
52
52
|
}
|
|
53
|
+
const dataLabel = owner.dataField === undefined ? undefined : dataRefLabel(value, "elementum_field");
|
|
54
|
+
const dataField = dataLabel === undefined ? undefined : owner.dataField?.(dataLabel);
|
|
55
|
+
if (dataField !== undefined)
|
|
56
|
+
return dataField;
|
|
53
57
|
throw new EntityTfError(`${where}: field reference cannot be reconstructed`);
|
|
54
58
|
}
|
|
55
59
|
/**
|
|
@@ -76,12 +80,13 @@ function picklistOptionLabel(value, owner) {
|
|
|
76
80
|
: undefined;
|
|
77
81
|
}
|
|
78
82
|
/** Decode one `filter` attribute through the shared exhaustive codec. */
|
|
79
|
-
export function filterFromTf(value, owner, where, ctx) {
|
|
83
|
+
export function filterFromTf(value, owner, where, ctx, options) {
|
|
80
84
|
try {
|
|
81
85
|
return deserializeFilterFromTf(value, {
|
|
82
86
|
field: (fieldValue) => fieldRef(fieldValue, owner, where),
|
|
83
87
|
reference: () => { throw new EntityTfError(`${where}: access-policy reference values are not supported`); },
|
|
84
88
|
literal: (literal) => picklistOptionLabel(literal, owner) ?? stageName(literal, owner, ctx) ?? literal,
|
|
89
|
+
...(options?.optionLookupsAreIdentities === true && { optionLookupsAreIdentities: true }),
|
|
85
90
|
});
|
|
86
91
|
}
|
|
87
92
|
catch (error) {
|
|
@@ -63,6 +63,17 @@ export interface FilterToTfContext extends Omit<AccessPolicyToTfContext, "orgRef
|
|
|
63
63
|
* Explicit UUID selections retain their identity regardless of this flag.
|
|
64
64
|
*/
|
|
65
65
|
readonly resolvePicklistLiterals?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Resolve a filter field owned by another aspect (a relationship filter on
|
|
68
|
+
* the related record's field). Returning undefined keeps the owner-scoped
|
|
69
|
+
* mapping.
|
|
70
|
+
*/
|
|
71
|
+
readonly foreignField?: (token: {
|
|
72
|
+
readonly refName: string;
|
|
73
|
+
readonly parent: string;
|
|
74
|
+
readonly fieldType?: string;
|
|
75
|
+
readonly name?: string;
|
|
76
|
+
}, where: string) => TfValue | undefined;
|
|
66
77
|
}
|
|
67
78
|
export interface AccessPolicyToTfResult {
|
|
68
79
|
readonly block: TfBlock;
|