@elementumai/edk 0.10.4 → 0.11.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.
- package/README.md +11 -7
- package/dist-sdk/src/catalog/token.js +2 -1
- package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
- package/dist-sdk/src/engine/build/context.d.ts +4 -0
- package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
- package/dist-sdk/src/engine/coverage-gaps.js +3 -0
- package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
- package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
- package/dist-sdk/src/engine/ei/run.d.ts +22 -0
- package/dist-sdk/src/engine/ei/run.js +99 -18
- package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
- package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
- package/dist-sdk/src/engine/ei/state.d.ts +1 -1
- package/dist-sdk/src/engine/ei/state.js +17 -4
- package/dist-sdk/src/engine/progress.d.ts +3 -1
- package/dist-sdk/src/engine/progress.js +7 -3
- package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
- package/dist-sdk/src/engine/pull/authored-address.js +180 -29
- package/dist-sdk/src/engine/pull/context.d.ts +37 -2
- package/dist-sdk/src/engine/pull/context.js +7 -4
- package/dist-sdk/src/engine/tf/index.d.ts +2 -2
- package/dist-sdk/src/engine/tf/index.js +2 -2
- package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
- package/dist-sdk/src/engine/tf/labels.js +50 -0
- package/dist-sdk/src/engine/tf/model.d.ts +2 -0
- package/dist-sdk/src/engine/tf/model.js +26 -0
- package/dist-sdk/src/engine/validation.d.ts +2 -0
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +17 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +52 -24
- package/dist-sdk/src/entities/access-policy/member-list.d.ts +32 -0
- package/dist-sdk/src/entities/access-policy/member-list.js +57 -0
- package/dist-sdk/src/entities/access-policy/module.js +5 -0
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +4 -3
- package/dist-sdk/src/entities/access-policy/to-tf.js +21 -12
- package/dist-sdk/src/entities/agent/build.js +7 -5
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -0
- package/dist-sdk/src/entities/agent/from-tf.js +13 -3
- package/dist-sdk/src/entities/agent/to-tf.js +11 -5
- package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
- package/dist-sdk/src/entities/agent/tools.js +6 -2
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.js +56 -3
- package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
- package/dist-sdk/src/entities/agent-tool/types.js +13 -9
- package/dist-sdk/src/entities/app/build.d.ts +11 -0
- package/dist-sdk/src/entities/app/build.js +1 -0
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +5 -7
- package/dist-sdk/src/entities/app/from-tf.js +16 -10
- package/dist-sdk/src/entities/app/to-tf.js +6 -4
- package/dist-sdk/src/entities/automation/build.d.ts +2 -7
- package/dist-sdk/src/entities/automation/build.js +43 -14
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +7 -11
- package/dist-sdk/src/entities/automation/from-tf.d.ts +23 -1
- package/dist-sdk/src/entities/automation/from-tf.js +456 -34
- package/dist-sdk/src/entities/automation/index.d.ts +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +22 -2
- package/dist-sdk/src/entities/automation/module.js +244 -57
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +22 -2
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +54 -3
- package/dist-sdk/src/entities/automation/run-target.d.ts +59 -0
- package/dist-sdk/src/entities/automation/run-target.js +99 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +9 -0
- package/dist-sdk/src/entities/automation/script-code.js +24 -3
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +16 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +49 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +20 -8
- package/dist-sdk/src/entities/automation/to-tf.d.ts +1 -3
- package/dist-sdk/src/entities/automation/to-tf.js +102 -40
- package/dist-sdk/src/entities/automation/triggers.d.ts +22 -3
- package/dist-sdk/src/entities/automation/triggers.js +40 -0
- package/dist-sdk/src/entities/automation/types.d.ts +21 -0
- package/dist-sdk/src/entities/automation/types.js +26 -0
- package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
- package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
- package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +7 -2
- package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +65 -19
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
- package/dist-sdk/src/entities/element/build.d.ts +10 -0
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/from-tf.js +14 -9
- package/dist-sdk/src/entities/element/to-tf.js +6 -4
- package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
- package/dist-sdk/src/entities/field/from-tf.js +79 -1
- package/dist-sdk/src/entities/field/module.js +7 -0
- package/dist-sdk/src/entities/field/to-tf.d.ts +30 -1
- package/dist-sdk/src/entities/field/to-tf.js +51 -0
- package/dist-sdk/src/entities/file-reader/module.js +3 -3
- package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
- package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
- package/dist-sdk/src/entities/file-reader/types.js +7 -0
- package/dist-sdk/src/entities/org/group.d.ts +1 -0
- package/dist-sdk/src/entities/org/group.js +2 -1
- package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
- package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
- package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
- package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
- package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
- package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
- package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
- package/dist-sdk/src/entities/role/from-tf.js +24 -7
- package/dist-sdk/src/entities/role/to-tf.js +25 -7
- package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
- package/dist-sdk/src/entities/service-account/module.js +15 -0
- package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
- package/dist-sdk/src/entities/skill/from-tf.js +10 -3
- package/dist-sdk/src/entities/skill/module.js +16 -0
- package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
- package/dist-sdk/src/entities/skill/to-tf.js +23 -14
- package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
- package/dist-sdk/src/entities/skill/tools.js +6 -2
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +8 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +20 -10
- package/dist-sdk/src/entities/view/from-tf.d.ts +60 -0
- package/dist-sdk/src/entities/view/from-tf.js +391 -17
- package/dist-sdk/src/entities/view/module.js +15 -0
- package/dist-sdk/src/entities/view/portable.d.ts +11 -0
- package/dist-sdk/src/entities/view/portable.js +47 -0
- package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
- package/dist-sdk/src/entities/view/to-tf.js +25 -7
- package/dist-sdk/src/entities/view/types.js +1 -1
- package/dist-sdk/src/entities/widget/build.d.ts +4 -3
- package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/widget/from-tf.js +100 -3
- package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
- package/dist-sdk/src/entities/widget/to-tf.js +77 -14
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +27 -8
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
- package/dist-sdk/src/graph/field-resource-types.js +11 -0
- package/dist-sdk/src/graph/index.d.ts +28 -3
- package/dist-sdk/src/graph/index.js +12 -2
- package/dist-sdk/src/graph/types.d.ts +157 -5
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JsonStreamReader } from "./json-stream-reader.js";
|
|
2
|
+
const SAVED_PLAN_OPTIONS = {
|
|
3
|
+
subject: "the saved plan's JSON",
|
|
4
|
+
keptRootKeys: new Set(["resource_changes", "prior_state"]),
|
|
5
|
+
walkedPaths: new Set([
|
|
6
|
+
"",
|
|
7
|
+
"resource_changes",
|
|
8
|
+
"prior_state",
|
|
9
|
+
"prior_state.values",
|
|
10
|
+
"prior_state.values.root_module",
|
|
11
|
+
"prior_state.values.root_module.resources",
|
|
12
|
+
]),
|
|
13
|
+
};
|
|
14
|
+
/** Feed `tofu show -json` stdout chunk by chunk with {@link write}, then call {@link end}. */
|
|
15
|
+
export class SavedPlanReader extends JsonStreamReader {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(SAVED_PLAN_OPTIONS);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -27,7 +27,7 @@ export interface StateSnapshotOptions {
|
|
|
27
27
|
readonly runtime?: StateSnapshotRuntime;
|
|
28
28
|
}
|
|
29
29
|
export interface StateSnapshotRuntime {
|
|
30
|
-
pull(tfDir: string): Promise<
|
|
30
|
+
pull(tfDir: string): Promise<TerraformStateSnapshot>;
|
|
31
31
|
}
|
|
32
32
|
export declare class StateSnapshotError extends Error {
|
|
33
33
|
constructor(message: string);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { assertNoUnmigratedLocalState, requireWorkspaceBackend, } from "../workspace/backend.js";
|
|
4
|
+
import { JsonStreamReader } from "./json-stream-reader.js";
|
|
4
5
|
import { EiRunError, runEiCapture } from "./run.js";
|
|
5
6
|
export class StateSnapshotError extends Error {
|
|
6
7
|
constructor(message) {
|
|
@@ -8,8 +9,20 @@ export class StateSnapshotError extends Error {
|
|
|
8
9
|
this.name = "StateSnapshotError";
|
|
9
10
|
}
|
|
10
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* `ei state pull` read as it streams, each resource parsed on its own, so a
|
|
14
|
+
* state of any size fits (edk#2248).
|
|
15
|
+
*/
|
|
16
|
+
const STATE_READER_OPTIONS = {
|
|
17
|
+
subject: "the pulled state's JSON",
|
|
18
|
+
walkedPaths: new Set(["", "resources"]),
|
|
19
|
+
};
|
|
11
20
|
const DEFAULT_RUNTIME = {
|
|
12
|
-
pull: (tfDir) =>
|
|
21
|
+
pull: async (tfDir) => {
|
|
22
|
+
const reader = new JsonStreamReader(STATE_READER_OPTIONS);
|
|
23
|
+
await runEiCapture(["state", "pull"], { cwd: tfDir, suppressStderr: true, onStdout: (chunk) => reader.write(chunk) });
|
|
24
|
+
return reader.end();
|
|
25
|
+
},
|
|
13
26
|
};
|
|
14
27
|
export function isNoStateError(error) {
|
|
15
28
|
if (!(error instanceof EiRunError))
|
|
@@ -75,9 +88,9 @@ export async function readStateSnapshot(options) {
|
|
|
75
88
|
throw new StateSnapshotError(error.message);
|
|
76
89
|
}
|
|
77
90
|
}
|
|
78
|
-
let
|
|
91
|
+
let pulled;
|
|
79
92
|
try {
|
|
80
|
-
|
|
93
|
+
pulled = await (options.runtime ?? DEFAULT_RUNTIME).pull(options.tfDir);
|
|
81
94
|
}
|
|
82
95
|
catch (error) {
|
|
83
96
|
if (isNoStateError(error))
|
|
@@ -87,5 +100,5 @@ export async function readStateSnapshot(options) {
|
|
|
87
100
|
: error.message;
|
|
88
101
|
throw new StateSnapshotError(`could not pull state from backend "${backend.type}" in ${options.tfDir}: ${detail}`);
|
|
89
102
|
}
|
|
90
|
-
return
|
|
103
|
+
return pulled;
|
|
91
104
|
}
|
|
@@ -43,7 +43,9 @@ export declare function writeUserOutput(text: string, destination?: NodeJS.Writa
|
|
|
43
43
|
*/
|
|
44
44
|
export declare function writeUserPayload(text: string, destination?: NodeJS.WritableStream): void;
|
|
45
45
|
/** Write a final user-facing operation status without contaminating pipes. */
|
|
46
|
-
export declare function writeUserStatus(message: string, color: "green" | "red" | "yellow"): void;
|
|
46
|
+
export declare function writeUserStatus(message: string, color: "green" | "red" | "yellow", destination?: NodeJS.WriteStream): void;
|
|
47
|
+
/** Where a command whose piped stdout is one JSON summary (pull, clone) writes status text. */
|
|
48
|
+
export declare function summaryCommandStatusStream(): NodeJS.WriteStream;
|
|
47
49
|
export interface LiveProgressOptions {
|
|
48
50
|
readonly label: string;
|
|
49
51
|
/** Omit when the number of steps is not knowable in advance. */
|
|
@@ -138,13 +138,17 @@ export function writeUserPayload(text, destination = process.stdout) {
|
|
|
138
138
|
destination.write(text);
|
|
139
139
|
}
|
|
140
140
|
/** Write a final user-facing operation status without contaminating pipes. */
|
|
141
|
-
export function writeUserStatus(message, color) {
|
|
141
|
+
export function writeUserStatus(message, color, destination = process.stdout) {
|
|
142
142
|
if (machineReadableLogs)
|
|
143
143
|
return;
|
|
144
|
-
const rendered =
|
|
144
|
+
const rendered = destination.isTTY === true && process.env["NO_COLOR"] === undefined
|
|
145
145
|
? renderTextEffects(message, [{ start: 0, end: message.length, color, bold: true }])
|
|
146
146
|
: message;
|
|
147
|
-
writeUserOutput(`${rendered}\n
|
|
147
|
+
writeUserOutput(`${rendered}\n`, destination);
|
|
148
|
+
}
|
|
149
|
+
/** Where a command whose piped stdout is one JSON summary (pull, clone) writes status text. */
|
|
150
|
+
export function summaryCommandStatusStream() {
|
|
151
|
+
return process.stdout.isTTY === true ? process.stdout : progressStream();
|
|
148
152
|
}
|
|
149
153
|
const SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
150
154
|
let activeProgress;
|
|
@@ -11,6 +11,13 @@ import type { TerraformStateResource } from "../ei/state.js";
|
|
|
11
11
|
import { type TfDocument } from "../tf/model.js";
|
|
12
12
|
/** The platform id an import id ends with (`<parent>/<id>` and `<a>:<id>` forms included). */
|
|
13
13
|
export declare function canonicalImportId(importId: string): string;
|
|
14
|
+
/** The key {@link authoredAddressesById} binds a resource type + platform id under. */
|
|
15
|
+
export declare function typedIdentity(type: string, id: string): string;
|
|
16
|
+
/** Inverse of {@link typedIdentity}. */
|
|
17
|
+
export declare function parseTypedIdentity(identity: string): {
|
|
18
|
+
readonly type: string;
|
|
19
|
+
readonly id: string;
|
|
20
|
+
};
|
|
14
21
|
/**
|
|
15
22
|
* Index managed state by resource type and canonical platform identity.
|
|
16
23
|
*
|
|
@@ -58,10 +65,17 @@ export declare function authoredAddressesFromSource(doc: TfDocument, importIds:
|
|
|
58
65
|
* reference as `.<key>`; those references break after the pull (#1579).
|
|
59
66
|
*/
|
|
60
67
|
export declare function staleAuthoredFieldReferences(unmatched: readonly AuthoredSourceField[], otherSources: readonly string[]): readonly AuthoredSourceField[];
|
|
68
|
+
/**
|
|
69
|
+
* Several export addresses whose authored targets share one key slot: one
|
|
70
|
+
* identity bound at two export addresses, or two fields authored at one label.
|
|
71
|
+
* `from[i]` is authored at `authoredTargets[i]`.
|
|
72
|
+
*/
|
|
61
73
|
export interface AuthoredAddressAmbiguity {
|
|
62
|
-
readonly
|
|
74
|
+
readonly authoredTargets: readonly string[];
|
|
63
75
|
readonly from: readonly string[];
|
|
64
76
|
}
|
|
77
|
+
/** The pull warning for an {@link AuthoredAddressAmbiguity}. */
|
|
78
|
+
export declare function authoredAddressAmbiguityWarning(ambiguity: AuthoredAddressAmbiguity): string;
|
|
65
79
|
export interface AuthoredAddressConflict {
|
|
66
80
|
readonly from: string;
|
|
67
81
|
readonly authoredTarget: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FIELD_RESOURCE_TYPE_SET } from "../../graph/field-resource-types.js";
|
|
1
2
|
import { sanitizeName, tsLabelToTfLabel } from "../tf/labels.js";
|
|
2
3
|
import { isTfExpr } from "../tf/model.js";
|
|
3
4
|
/** The platform id an import id ends with (`<parent>/<id>` and `<a>:<id>` forms included). */
|
|
@@ -5,9 +6,15 @@ export function canonicalImportId(importId) {
|
|
|
5
6
|
const last = importId.split(/[:/]/).at(-1);
|
|
6
7
|
return last === undefined || last === "" ? importId : last;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/** The key {@link authoredAddressesById} binds a resource type + platform id under. */
|
|
10
|
+
export function typedIdentity(type, id) {
|
|
9
11
|
return `${type}\u0000${canonicalImportId(id)}`;
|
|
10
12
|
}
|
|
13
|
+
/** Inverse of {@link typedIdentity}. */
|
|
14
|
+
export function parseTypedIdentity(identity) {
|
|
15
|
+
const separator = identity.indexOf("\u0000");
|
|
16
|
+
return { type: identity.slice(0, separator), id: identity.slice(separator + 1) };
|
|
17
|
+
}
|
|
11
18
|
function addressType(address) {
|
|
12
19
|
const dot = address.indexOf(".");
|
|
13
20
|
return dot === -1 ? undefined : address.slice(0, dot);
|
|
@@ -27,6 +34,11 @@ export function authoredAddressesById(resources) {
|
|
|
27
34
|
typeof resource.name !== "string") {
|
|
28
35
|
continue;
|
|
29
36
|
}
|
|
37
|
+
// A failed adoption parks objects at `edk_adopt_move_tmp_*` (#1997). That
|
|
38
|
+
// name is not an authored address; keeping it would make the next pull
|
|
39
|
+
// adopt the temporary label instead of moving the object back.
|
|
40
|
+
if (resource.name.startsWith("edk_adopt_move_tmp_"))
|
|
41
|
+
continue;
|
|
30
42
|
const address = `${resource.type}.${resource.name}`;
|
|
31
43
|
for (const instance of resource.instances ?? []) {
|
|
32
44
|
const id = instance.attributes?.id;
|
|
@@ -132,20 +144,54 @@ export function staleAuthoredFieldReferences(unmatched, otherSources) {
|
|
|
132
144
|
return otherSources.some((text) => ref.test(text));
|
|
133
145
|
});
|
|
134
146
|
}
|
|
147
|
+
/** The pull warning for an {@link AuthoredAddressAmbiguity}. */
|
|
148
|
+
export function authoredAddressAmbiguityWarning(ambiguity) {
|
|
149
|
+
const targets = new Set(ambiguity.authoredTargets);
|
|
150
|
+
if (targets.size === 1) {
|
|
151
|
+
return (`could not preserve authored address ${ambiguity.authoredTargets[0]}: ` +
|
|
152
|
+
`the current export binds that identity at ${ambiguity.from.join(" and ")}; keeping export labels`);
|
|
153
|
+
}
|
|
154
|
+
const pairs = ambiguity.from.map((from, i) => `${ambiguity.authoredTargets[i]} for ${from}`);
|
|
155
|
+
return `could not preserve authored addresses ${pairs.join(" and ")}: those fields would print under one key; keeping export labels`;
|
|
156
|
+
}
|
|
135
157
|
/**
|
|
136
158
|
* Join export addresses to the addresses state already binds, by platform id.
|
|
137
159
|
*
|
|
138
160
|
* ei numbers same-named resources `_1`, `_2` in its export order, so a label
|
|
139
161
|
* can change hands between pulls (#1658). An authored target the export gives
|
|
140
162
|
* to another identity is still taken back when that occupant moves to its own
|
|
141
|
-
* authored address, or when the occupant is new to state and
|
|
142
|
-
*
|
|
163
|
+
* authored address, or when the occupant is new to state and a label is free
|
|
164
|
+
* at the end of the chain of moves that starts there: the occupant takes that
|
|
165
|
+
* label instead. For one move that is a swap. When a live add and a live
|
|
166
|
+
* remove shift every later positional label by one (#2053), the chain is the
|
|
167
|
+
* whole shift: every managed identity keeps its authored address and the new
|
|
168
|
+
* identity takes the label the last move leaves. Managed identities whose
|
|
169
|
+
* authored labels rotate among themselves all take them back. A label is
|
|
170
|
+
* free when no move claims it and no identity in this export is authored
|
|
171
|
+
* there; a label whose authored identity is absent from the export (deleted
|
|
172
|
+
* live) is free, and adoption releases that dead binding before the import
|
|
173
|
+
* (#1898).
|
|
143
174
|
* An occupant counts as new only when `inState` (every managed identity state
|
|
144
175
|
* holds) is given and doesn't contain it. Anything else stays at its export
|
|
145
176
|
* address and is reported.
|
|
177
|
+
*
|
|
178
|
+
* Occupancy is by {@link labelSlot}: an owner's fields print as one bag keyed
|
|
179
|
+
* by label, so a field of one type holds its label against every field type
|
|
180
|
+
* (#1859). When the result would still put two fields at one label, the
|
|
181
|
+
* join throws rather than print one key twice.
|
|
146
182
|
*/
|
|
147
183
|
function resolveAuthoredAddresses(importIds, authoredById, inState) {
|
|
148
|
-
const
|
|
184
|
+
const exportAtSlot = new Map();
|
|
185
|
+
for (const address of importIds.keys()) {
|
|
186
|
+
const slot = labelSlot(address);
|
|
187
|
+
const held = exportAtSlot.get(slot);
|
|
188
|
+
if (held === undefined)
|
|
189
|
+
exportAtSlot.set(slot, [address]);
|
|
190
|
+
else
|
|
191
|
+
held.push(address);
|
|
192
|
+
}
|
|
193
|
+
const occupantsOf = (slot, except) => (exportAtSlot.get(slot) ?? []).filter((address) => address !== except);
|
|
194
|
+
const claimsBySlot = new Map();
|
|
149
195
|
for (const [from, id] of importIds) {
|
|
150
196
|
const type = addressType(from);
|
|
151
197
|
if (type === undefined)
|
|
@@ -153,66 +199,171 @@ function resolveAuthoredAddresses(importIds, authoredById, inState) {
|
|
|
153
199
|
const to = authoredById.get(typedIdentity(type, id));
|
|
154
200
|
if (to === undefined || to === from)
|
|
155
201
|
continue;
|
|
156
|
-
const claims =
|
|
202
|
+
const claims = claimsBySlot.get(labelSlot(to));
|
|
157
203
|
if (claims === undefined)
|
|
158
|
-
|
|
159
|
-
else
|
|
160
|
-
claims.push(
|
|
204
|
+
claimsBySlot.set(labelSlot(to), { target: to, targets: [to], from: [from] });
|
|
205
|
+
else {
|
|
206
|
+
claims.targets.push(to);
|
|
207
|
+
claims.from.push(from);
|
|
208
|
+
}
|
|
161
209
|
}
|
|
162
210
|
const ambiguities = [];
|
|
163
211
|
const pending = new Map();
|
|
164
|
-
for (const
|
|
212
|
+
for (const { target, targets, from } of claimsBySlot.values()) {
|
|
165
213
|
if (from.length > 1)
|
|
166
|
-
ambiguities.push({
|
|
214
|
+
ambiguities.push({ authoredTargets: targets, from });
|
|
167
215
|
else
|
|
168
|
-
pending.set(from[0],
|
|
216
|
+
pending.set(from[0], target);
|
|
169
217
|
}
|
|
170
|
-
const
|
|
218
|
+
const exportIdentities = new Set();
|
|
219
|
+
for (const [address, id] of importIds) {
|
|
220
|
+
const type = addressType(address);
|
|
221
|
+
if (type !== undefined)
|
|
222
|
+
exportIdentities.add(typedIdentity(type, id));
|
|
223
|
+
}
|
|
224
|
+
// Authored labels of identities this export still has. One whose identity
|
|
225
|
+
// is absent from the export was deleted live and does not hold its label.
|
|
226
|
+
const liveAuthoredSlots = new Set([...authoredById].filter(([identity]) => exportIdentities.has(identity)).map(([, address]) => labelSlot(address)));
|
|
171
227
|
const accepted = new Map();
|
|
172
|
-
const
|
|
228
|
+
const acceptedSlots = new Set();
|
|
173
229
|
const aliases = [];
|
|
174
230
|
const accept = (from, to) => {
|
|
175
231
|
accepted.set(from, to);
|
|
176
|
-
|
|
232
|
+
acceptedSlots.add(labelSlot(to));
|
|
177
233
|
aliases.push({ from, to });
|
|
178
234
|
};
|
|
235
|
+
// The label left free at the end of the chain of pending moves that vacates
|
|
236
|
+
// `from`: each pending move into the label just vacated leaves its own
|
|
237
|
+
// export label, until no move claims one. Undefined when that label is
|
|
238
|
+
// claimed, ambiguous, already taken, or authored to an identity this export
|
|
239
|
+
// still has.
|
|
240
|
+
const freeLabelAfterChain = (from) => {
|
|
241
|
+
const seen = new Set([from]);
|
|
242
|
+
let vacated = from;
|
|
243
|
+
for (;;) {
|
|
244
|
+
const claims = claimsBySlot.get(labelSlot(vacated));
|
|
245
|
+
if (claims === undefined)
|
|
246
|
+
break;
|
|
247
|
+
const mover = claims.from.length === 1 ? claims.from[0] : undefined;
|
|
248
|
+
if (mover === undefined || pending.get(mover) !== claims.target || seen.has(mover))
|
|
249
|
+
return undefined;
|
|
250
|
+
seen.add(mover);
|
|
251
|
+
vacated = mover;
|
|
252
|
+
}
|
|
253
|
+
const slot = labelSlot(vacated);
|
|
254
|
+
if (liveAuthoredSlots.has(slot) || acceptedSlots.has(slot) || occupantsOf(slot, vacated).length > 0)
|
|
255
|
+
return undefined;
|
|
256
|
+
return vacated;
|
|
257
|
+
};
|
|
258
|
+
// Managed identities whose pending moves each target the label the next one
|
|
259
|
+
// leaves, closing back on `from`: the whole rotation can be taken at once.
|
|
260
|
+
const rotationFrom = (from) => {
|
|
261
|
+
const members = [from];
|
|
262
|
+
let mover = from;
|
|
263
|
+
for (;;) {
|
|
264
|
+
const occupants = occupantsOf(labelSlot(pending.get(mover)), mover);
|
|
265
|
+
if (occupants.length !== 1)
|
|
266
|
+
return undefined;
|
|
267
|
+
const next = occupants[0];
|
|
268
|
+
if (next === from)
|
|
269
|
+
return members;
|
|
270
|
+
if (!pending.has(next) || members.includes(next))
|
|
271
|
+
return undefined;
|
|
272
|
+
members.push(next);
|
|
273
|
+
mover = next;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
179
276
|
// A move whose target is held by another moving identity waits for that move.
|
|
180
277
|
for (let progressed = true; progressed && pending.size > 0;) {
|
|
181
278
|
progressed = false;
|
|
182
279
|
for (const [from, to] of pending) {
|
|
183
|
-
const occupiedById = importIds.get(to);
|
|
184
280
|
const sourceId = importIds.get(from);
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
|
|
281
|
+
const occupants = occupantsOf(labelSlot(to), from);
|
|
282
|
+
const free = occupants.every((address) => canonicalImportId(importIds.get(address)) === canonicalImportId(sourceId));
|
|
283
|
+
const vacated = occupants.length > 0 && occupants.every((address) => accepted.has(address));
|
|
284
|
+
const occupant = occupants.length === 1 ? occupants[0] : undefined;
|
|
285
|
+
const occupantIdentity = occupant === undefined ? undefined : typedIdentity(addressType(occupant), importIds.get(occupant));
|
|
286
|
+
const occupantNew = occupantIdentity !== undefined && inState !== undefined && !inState.has(occupantIdentity) && !authoredById.has(occupantIdentity);
|
|
287
|
+
const rotation = occupant !== undefined && pending.has(occupant) ? rotationFrom(from) : undefined;
|
|
288
|
+
const occupantLabel = occupantNew ? freeLabelAfterChain(from) : undefined;
|
|
289
|
+
if (free || vacated) {
|
|
190
290
|
accept(from, to);
|
|
291
|
+
pending.delete(from);
|
|
191
292
|
}
|
|
192
|
-
else if (
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
293
|
+
else if (rotation !== undefined) {
|
|
294
|
+
// Managed identities whose labels traded places (two of them: a swap).
|
|
295
|
+
for (const member of rotation) {
|
|
296
|
+
accept(member, pending.get(member));
|
|
297
|
+
pending.delete(member);
|
|
298
|
+
}
|
|
197
299
|
}
|
|
198
|
-
else if (
|
|
300
|
+
else if (occupant !== undefined && occupantLabel !== undefined) {
|
|
301
|
+
// The rest of the chain follows on later passes: each target is then
|
|
302
|
+
// held by an identity that has already moved.
|
|
199
303
|
accept(from, to);
|
|
200
|
-
accept(
|
|
304
|
+
accept(occupant, withLabelOf(occupant, occupantLabel));
|
|
305
|
+
pending.delete(from);
|
|
201
306
|
}
|
|
202
307
|
else {
|
|
203
308
|
continue;
|
|
204
309
|
}
|
|
205
|
-
pending.delete(from);
|
|
206
310
|
progressed = true;
|
|
207
311
|
}
|
|
208
312
|
}
|
|
209
313
|
const conflicts = [...pending].map(([from, authoredTarget]) => ({
|
|
210
314
|
from,
|
|
211
315
|
authoredTarget,
|
|
212
|
-
occupiedById: importIds.get(authoredTarget) ?? "",
|
|
316
|
+
occupiedById: importIds.get(occupantsOf(labelSlot(authoredTarget), from)[0] ?? "") ?? "",
|
|
213
317
|
}));
|
|
318
|
+
assertOneAddressPerSlot(importIds, accepted);
|
|
214
319
|
return { aliases, ambiguities, conflicts };
|
|
215
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* The key space an address takes its label in: one per label for every field
|
|
323
|
+
* type, since an owner's fields print as one bag keyed by label alone; the
|
|
324
|
+
* address itself otherwise.
|
|
325
|
+
*/
|
|
326
|
+
function labelSlot(address) {
|
|
327
|
+
const type = addressType(address);
|
|
328
|
+
return type !== undefined && FIELD_RESOURCE_TYPE_SET.has(type) ? `\u0000field.${address.slice(type.length + 1)}` : address;
|
|
329
|
+
}
|
|
330
|
+
/** `address`'s resource type at `labelSource`'s label. */
|
|
331
|
+
function withLabelOf(address, labelSource) {
|
|
332
|
+
return `${addressType(address)}.${labelSource.slice(labelSource.indexOf(".") + 1)}`;
|
|
333
|
+
}
|
|
334
|
+
/** Whether `slot` (a {@link labelSlot}) is an owner's shared field key space. */
|
|
335
|
+
function isFieldSlot(slot) {
|
|
336
|
+
return slot.startsWith("\u0000field.");
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Two fields at one label would print one bag key twice, and the build would
|
|
340
|
+
* keep only the second, planning to replace the other's live field (#1859).
|
|
341
|
+
* Fail closed instead of printing that.
|
|
342
|
+
*/
|
|
343
|
+
function assertOneAddressPerSlot(importIds, accepted) {
|
|
344
|
+
const bySlot = new Map();
|
|
345
|
+
for (const from of importIds.keys()) {
|
|
346
|
+
const to = accepted.get(from) ?? from;
|
|
347
|
+
const held = bySlot.get(labelSlot(to));
|
|
348
|
+
if (held === undefined)
|
|
349
|
+
bySlot.set(labelSlot(to), [{ from, to }]);
|
|
350
|
+
else
|
|
351
|
+
held.push({ from, to });
|
|
352
|
+
}
|
|
353
|
+
for (const [slot, moves] of bySlot) {
|
|
354
|
+
if (moves.length < 2)
|
|
355
|
+
continue;
|
|
356
|
+
const named = moves.map(({ from, to }) => (from === to ? from : `${from} (as ${to})`)).join(" and ");
|
|
357
|
+
if (!isFieldSlot(slot)) {
|
|
358
|
+
throw new Error(`pull would print ${named} at one address, and the next plan would replace one of those live resources. ` +
|
|
359
|
+
"Pull stopped instead. Rename one of them in Elementum, then pull again.");
|
|
360
|
+
}
|
|
361
|
+
throw new Error(`pull would print fields ${named} under one field key, and the next plan would replace one of those live fields. ` +
|
|
362
|
+
'Pull stopped instead. This usually means the export numbered a repeated name with a _N suffix (two fields named "Notes" ' +
|
|
363
|
+
'export as notes and notes_1) and a third field named "Notes 1", "Notes_1" or "Notes-1" takes the same key. ' +
|
|
364
|
+
"Rename one of these fields in Elementum, then pull again.");
|
|
365
|
+
}
|
|
366
|
+
}
|
|
216
367
|
/**
|
|
217
368
|
* Resolve export addresses to addresses already bound in authored state.
|
|
218
369
|
*
|
|
@@ -16,6 +16,11 @@ export interface ImportedResourceRef {
|
|
|
16
16
|
readonly attrs: Readonly<Record<string, TfValue>>;
|
|
17
17
|
}
|
|
18
18
|
/** Extraction context: stream lookups + the diagnostics sink. */
|
|
19
|
+
/** An automation the export left out, as omitted-automations.json names it. */
|
|
20
|
+
export interface OmittedAutomationIdentity {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
}
|
|
19
24
|
export interface FromTfContext {
|
|
20
25
|
/** Lookup-attr value of a data block in the same stream: ("elementum_category", "experiments") → "Experiments". */
|
|
21
26
|
dataName(type: string, label: string): string | undefined;
|
|
@@ -56,6 +61,11 @@ export interface FromTfContext {
|
|
|
56
61
|
readonly columnRefNamesByName?: ReadonlyMap<string, string>;
|
|
57
62
|
readonly columnRefNamesById?: ReadonlyMap<string, string>;
|
|
58
63
|
}>;
|
|
64
|
+
/** Platform file-reader id → its owning app and reader key, bound exactly by workspace state. */
|
|
65
|
+
readonly foreignFileReaderRefsById?: ReadonlyMap<string, {
|
|
66
|
+
readonly ownerRefName: string;
|
|
67
|
+
readonly refName: string;
|
|
68
|
+
}>;
|
|
59
69
|
/** Namespace → refName for portable ref-only app/element catalogs. */
|
|
60
70
|
readonly foreignAppRefNamespaces?: ReadonlyMap<string, string>;
|
|
61
71
|
readonly foreignElementRefNamespaces?: ReadonlyMap<string, string>;
|
|
@@ -74,6 +84,23 @@ export interface FromTfContext {
|
|
|
74
84
|
readonly name: string;
|
|
75
85
|
readonly namespace?: string;
|
|
76
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* Set by `clone app`, which drops the export's import blocks before
|
|
89
|
+
* extraction. `sourceImportId` reads the dropped ones (by resource
|
|
90
|
+
* address): a reference to a field clone does not copy keeps that id when
|
|
91
|
+
* the field's block names another app, element or task as its owner, and fails
|
|
92
|
+
* the clone otherwise, naming the field and the reference (#1990).
|
|
93
|
+
* `sourceImportedAddress` is the reverse: the address a dropped import
|
|
94
|
+
* gave a bare platform id, so `importedResource` still resolves the bare
|
|
95
|
+
* ids an export writes when it can't name a field (#1991).
|
|
96
|
+
* `systemFieldReadFailure` is why the live read of the source app's system
|
|
97
|
+
* fields failed, if it did, so an unmapped id's error names it (#1492).
|
|
98
|
+
*/
|
|
99
|
+
readonly cloning?: {
|
|
100
|
+
readonly sourceImportId: (address: string) => string | undefined;
|
|
101
|
+
readonly sourceImportedAddress?: (id: string) => string | undefined;
|
|
102
|
+
readonly systemFieldReadFailure?: string;
|
|
103
|
+
};
|
|
77
104
|
/** `data.<field-type>.<label>` → generated ref-only catalog member. */
|
|
78
105
|
readonly foreignFieldRefsByDataAddress?: ReadonlyMap<string, {
|
|
79
106
|
readonly ownerRefName: string;
|
|
@@ -107,6 +134,14 @@ export interface FromTfContext {
|
|
|
107
134
|
* ei writes a service account owned by another app as a bare id.
|
|
108
135
|
*/
|
|
109
136
|
readonly serviceAccountsById?: ReadonlyMap<string, ServiceAccountIdentity>;
|
|
137
|
+
/**
|
|
138
|
+
* The automations the export left out (omitted-automations.json), by
|
|
139
|
+
* platform id (#1877). A run-automation widget whose raw automation id is
|
|
140
|
+
* listed here warns, naming the automation and the export's reason; any
|
|
141
|
+
* other raw id (such as another app's automation) is a valid reference and
|
|
142
|
+
* stays silent. Undefined: no listed id, so only an empty id warns.
|
|
143
|
+
*/
|
|
144
|
+
readonly omittedAutomationsById?: ReadonlyMap<string, OmittedAutomationIdentity>;
|
|
110
145
|
/**
|
|
111
146
|
* Foreign app/element display names this stream saw referenced (currently:
|
|
112
147
|
* a RELATION field's `related_object_id` as a `data.elementum_app`/
|
|
@@ -238,8 +273,8 @@ export interface AuthoringBlocker {
|
|
|
238
273
|
*/
|
|
239
274
|
readonly ownFileKind?: string;
|
|
240
275
|
}
|
|
241
|
-
/** The pull-abort message for one or more authoring blockers. */
|
|
242
|
-
export declare function authoringBlockedMessage(blockers: readonly AuthoringBlocker[]): string;
|
|
276
|
+
/** The pull-abort (or, for `clone app`, clone-abort) message for one or more authoring blockers. */
|
|
277
|
+
export declare function authoringBlockedMessage(blockers: readonly AuthoringBlocker[], command?: "pull" | "clone"): string;
|
|
243
278
|
/**
|
|
244
279
|
* Record an authoring blocker. Without a sink (a caller outside the stream
|
|
245
280
|
* pipeline) it throws, so a blocker is never silently dropped.
|
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { EntityTfError } from "../entity.js";
|
|
8
8
|
import { isTfExpr, tfLabelToTsLabel } from "../tf/index.js";
|
|
9
|
-
/** The pull-abort message for one or more authoring blockers. */
|
|
10
|
-
export function authoringBlockedMessage(blockers) {
|
|
9
|
+
/** The pull-abort (or, for `clone app`, clone-abort) message for one or more authoring blockers. */
|
|
10
|
+
export function authoringBlockedMessage(blockers, command = "pull") {
|
|
11
11
|
const remedies = [...new Set(blockers.map((blocker) => blocker.remedy))];
|
|
12
|
-
|
|
13
|
-
"
|
|
12
|
+
const head = command === "clone"
|
|
13
|
+
? "Clone aborted: the clone cannot reproduce this configuration of the source app, so no clone source was written:\n"
|
|
14
|
+
: "Pull aborted: authored source cannot reproduce this live configuration, " +
|
|
15
|
+
"and printing the rest would change it on the next apply:\n";
|
|
16
|
+
return (head +
|
|
14
17
|
blockers.map((blocker) => ` - ${blocker.description}`).join("\n") +
|
|
15
18
|
remedies.map((remedy) => `\n${remedy}`).join(""));
|
|
16
19
|
}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* toHcl emitters produce TfBlock rendered by renderDocument.
|
|
5
5
|
*/
|
|
6
6
|
export type { PathSeg, TfBlock, TfBlockKind, TfDocument, TfExpr, TfLifecycle, TfValue, TfVariableValidation } from "./model.js";
|
|
7
|
-
export { expr, isTfExpr } from "./model.js";
|
|
7
|
+
export { expr, forEachExpr, isTfExpr } from "./model.js";
|
|
8
8
|
export { decodeTemplateEscapes, encodeTemplateEscapes, quoteHclString } from "./escape.js";
|
|
9
9
|
export { parseExpression, parseStringValue, TfExprError } from "./expr.js";
|
|
10
10
|
export { assertNoUnsafeIntegers, inspectBackendHcl, parseHcl, parseHclDocuments, TfParseError, type BackendHclInspection, } from "./parse.js";
|
|
11
11
|
export { renderBlock, renderDocument } from "./render.js";
|
|
12
12
|
export { hclCodeLines, hclDepthDelta, hclStatementEnd, type HclCodeLine } from "./scan.js";
|
|
13
|
-
export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isTfLabel, isUuid, ownerFromScopedChildLabel, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, stageHandleTfLabel, stableIdSuffix, tfLabelToTsLabel, tsLabelToTfLabel, taskResourceLabelPrefix, type ChildResourceScope, type FieldOwnerScope, } from "./labels.js";
|
|
13
|
+
export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, collisionLabelSuffixes, elementResourceLabelPrefix, elementScopedResourceLabel, exportLabelSuffix, isCanonicalTsLabel, isTfLabel, isUuid, ownerFromScopedChildLabel, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, stageHandleTfLabel, stableIdSuffix, tfLabelToTsLabel, tsLabelToTfLabel, taskResourceLabelPrefix, type ChildResourceScope, type FieldOwnerScope, } from "./labels.js";
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* A second dialect must not exist: extractors consume TfBlock from parseHcl;
|
|
4
4
|
* toHcl emitters produce TfBlock rendered by renderDocument.
|
|
5
5
|
*/
|
|
6
|
-
export { expr, isTfExpr } from "./model.js";
|
|
6
|
+
export { expr, forEachExpr, isTfExpr } from "./model.js";
|
|
7
7
|
export { decodeTemplateEscapes, encodeTemplateEscapes, quoteHclString } from "./escape.js";
|
|
8
8
|
export { parseExpression, parseStringValue, TfExprError } from "./expr.js";
|
|
9
9
|
export { assertNoUnsafeIntegers, inspectBackendHcl, parseHcl, parseHclDocuments, TfParseError, } from "./parse.js";
|
|
10
10
|
export { renderBlock, renderDocument } from "./render.js";
|
|
11
11
|
export { hclCodeLines, hclDepthDelta, hclStatementEnd } from "./scan.js";
|
|
12
|
-
export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, elementResourceLabelPrefix, elementScopedResourceLabel, isCanonicalTsLabel, isTfLabel, isUuid, ownerFromScopedChildLabel, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, stageHandleTfLabel, stableIdSuffix, tfLabelToTsLabel, tsLabelToTfLabel, taskResourceLabelPrefix, } from "./labels.js";
|
|
12
|
+
export { appResourceLabelPrefix, appScopedResourceLabel, bareChildResourceLabel, childPartFromScopedLabel, collisionLabelSuffixes, elementResourceLabelPrefix, elementScopedResourceLabel, exportLabelSuffix, isCanonicalTsLabel, isTfLabel, isUuid, ownerFromScopedChildLabel, sanitizeName, scopedLabelToBagKey, scopedResourceLabel, snakeSlug, splitCamelCase, stageHandleTfLabel, stableIdSuffix, tfLabelToTsLabel, tsLabelToTfLabel, taskResourceLabelPrefix, } from "./labels.js";
|
|
@@ -116,3 +116,25 @@ export declare function ownerFromScopedChildLabel(scopedLabel: string): {
|
|
|
116
116
|
export declare function stableIdSuffix(id: string): string;
|
|
117
117
|
/** Scoped terraform label → authoring bag key / ref key. */
|
|
118
118
|
export declare function scopedLabelToBagKey(ownerTfLabel: string, scopedLabel: string, scope?: FieldOwnerScope): string;
|
|
119
|
+
/**
|
|
120
|
+
* The `N` of an export label `<base>_<N>` (N ≥ 1), or undefined when `label`
|
|
121
|
+
* is `base` itself or not derived from it. Pull reads a tool's pinned
|
|
122
|
+
* `labelSuffix` this way (edk#1987). An `N` above `Number.MAX_SAFE_INTEGER`
|
|
123
|
+
* is not a pin either: as a number it would round to a different label, so
|
|
124
|
+
* the tool stays unpinned rather than being silently renumbered.
|
|
125
|
+
*/
|
|
126
|
+
export declare function exportLabelSuffix(base: string, label: string): number | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* `_N` suffixes, by position, for one owner's tools whose labels share a
|
|
129
|
+
* `base` (edk#1987). A tool with a pinned `labelSuffix` keeps exactly that
|
|
130
|
+
* `_N`. Every other tool takes the lowest count its group has not used or
|
|
131
|
+
* pinned, in list order, so the first unpinned one keeps the bare label.
|
|
132
|
+
* ei counts the same way in the platform's order; pull pins every tool ei
|
|
133
|
+
* gave a suffix, so tools ei counted but pull doesn't print (unimplemented
|
|
134
|
+
* kinds, dropped tools) still leave their slots free. `undefined` entries
|
|
135
|
+
* (tools ei doesn't count) get no suffix.
|
|
136
|
+
*/
|
|
137
|
+
export declare function collisionLabelSuffixes(entries: readonly ({
|
|
138
|
+
readonly base: string;
|
|
139
|
+
readonly pinned?: number;
|
|
140
|
+
} | undefined)[]): readonly string[];
|
|
@@ -266,3 +266,53 @@ export function stableIdSuffix(id) {
|
|
|
266
266
|
export function scopedLabelToBagKey(ownerTfLabel, scopedLabel, scope = "app") {
|
|
267
267
|
return tfLabelToTsLabel(childPartFromScopedLabel(ownerTfLabel, scopedLabel, scope));
|
|
268
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* The `N` of an export label `<base>_<N>` (N ≥ 1), or undefined when `label`
|
|
271
|
+
* is `base` itself or not derived from it. Pull reads a tool's pinned
|
|
272
|
+
* `labelSuffix` this way (edk#1987). An `N` above `Number.MAX_SAFE_INTEGER`
|
|
273
|
+
* is not a pin either: as a number it would round to a different label, so
|
|
274
|
+
* the tool stays unpinned rather than being silently renumbered.
|
|
275
|
+
*/
|
|
276
|
+
export function exportLabelSuffix(base, label) {
|
|
277
|
+
if (!label.startsWith(`${base}_`))
|
|
278
|
+
return undefined;
|
|
279
|
+
const rest = label.slice(base.length + 1);
|
|
280
|
+
if (!/^[1-9][0-9]*$/.test(rest))
|
|
281
|
+
return undefined;
|
|
282
|
+
const count = Number(rest);
|
|
283
|
+
return Number.isSafeInteger(count) ? count : undefined;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* `_N` suffixes, by position, for one owner's tools whose labels share a
|
|
287
|
+
* `base` (edk#1987). A tool with a pinned `labelSuffix` keeps exactly that
|
|
288
|
+
* `_N`. Every other tool takes the lowest count its group has not used or
|
|
289
|
+
* pinned, in list order, so the first unpinned one keeps the bare label.
|
|
290
|
+
* ei counts the same way in the platform's order; pull pins every tool ei
|
|
291
|
+
* gave a suffix, so tools ei counted but pull doesn't print (unimplemented
|
|
292
|
+
* kinds, dropped tools) still leave their slots free. `undefined` entries
|
|
293
|
+
* (tools ei doesn't count) get no suffix.
|
|
294
|
+
*/
|
|
295
|
+
export function collisionLabelSuffixes(entries) {
|
|
296
|
+
const taken = new Map();
|
|
297
|
+
const takenFor = (base) => {
|
|
298
|
+
const set = taken.get(base) ?? new Set();
|
|
299
|
+
taken.set(base, set);
|
|
300
|
+
return set;
|
|
301
|
+
};
|
|
302
|
+
for (const entry of entries) {
|
|
303
|
+
if (entry?.pinned !== undefined)
|
|
304
|
+
takenFor(entry.base).add(entry.pinned);
|
|
305
|
+
}
|
|
306
|
+
return entries.map((entry) => {
|
|
307
|
+
if (entry === undefined)
|
|
308
|
+
return "";
|
|
309
|
+
if (entry.pinned !== undefined)
|
|
310
|
+
return `_${entry.pinned}`;
|
|
311
|
+
const used = takenFor(entry.base);
|
|
312
|
+
let count = 0;
|
|
313
|
+
while (used.has(count))
|
|
314
|
+
count++;
|
|
315
|
+
used.add(count);
|
|
316
|
+
return count > 0 ? `_${count}` : "";
|
|
317
|
+
});
|
|
318
|
+
}
|
|
@@ -110,3 +110,5 @@ export declare const expr: {
|
|
|
110
110
|
scopedAttr(name: string, path?: PathSeg[]): TfExpr;
|
|
111
111
|
forObject(variable: string, collection: TfExpr, key: TfExpr, value: TfExpr): TfExpr;
|
|
112
112
|
};
|
|
113
|
+
/** Visits every expression leaf in a value, recursing into nested expressions. */
|
|
114
|
+
export declare function forEachExpr(value: TfValue, visit: (e: TfExpr) => void): void;
|