@elementumai/edk 0.10.3 → 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 +52 -7
- package/dist-sdk/src/engine/pull/context.js +7 -4
- package/dist-sdk/src/engine/tf/index.d.ts +3 -2
- package/dist-sdk/src/engine/tf/index.js +3 -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/tf/scan.d.ts +22 -0
- package/dist-sdk/src/engine/tf/scan.js +123 -0
- package/dist-sdk/src/engine/validation.d.ts +2 -0
- package/dist-sdk/src/engine/workspace/loader.d.ts +8 -0
- package/dist-sdk/src/engine/workspace/loader.js +20 -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.d.ts +13 -11
- package/dist-sdk/src/entities/agent/to-tf.js +28 -17
- 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/from-tf.js +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.js +65 -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 +11 -7
- package/dist-sdk/src/entities/app/from-tf.js +19 -9
- 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 +55 -16
- 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 +273 -58
- package/dist-sdk/src/entities/automation/output-field-types.d.ts +8 -0
- package/dist-sdk/src/entities/automation/output-field-types.js +20 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +24 -2
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +72 -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 +8 -3
- package/dist-sdk/src/entities/automation/to-tf.js +171 -58
- 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 +16 -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 +44 -2
- 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 +10 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +18 -4
- package/dist-sdk/src/entities/view/custom-view-validate.js +6 -5
- package/dist-sdk/src/entities/view/from-tf.d.ts +68 -0
- package/dist-sdk/src/entities/view/from-tf.js +503 -25
- 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 +164 -5
- package/package.json +1 -1
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
import { type FromTfContext } from "../../engine/pull/context.js";
|
|
9
9
|
import { type FieldOwnerScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
|
|
10
10
|
import type { NormalizedField } from "../app/deserializer/normalize.js";
|
|
11
|
+
/** Whether one of the owner's own field resources is keyed `fieldKey`; true when the stream can't be listed. */
|
|
12
|
+
export declare function ownerMayHaveCustomField(owner: FieldOwner, fieldKey: string, ctx: FromTfContext): boolean;
|
|
11
13
|
export interface FieldOwner {
|
|
12
14
|
/** The owner's resource type ("elementum_app") — what `object_id` must reference. */
|
|
13
15
|
readonly type: string;
|
|
@@ -18,6 +20,28 @@ export interface FieldOwner {
|
|
|
18
20
|
/** The owner's catalog refName — the `appHandle` of same-owner field RefExprs. */
|
|
19
21
|
readonly refName?: string;
|
|
20
22
|
}
|
|
23
|
+
/** Who owns a field block, by its `object_id` (see {@link fieldBlockOwner}). */
|
|
24
|
+
export type FieldBlockOwner = "own" | "foreign" | "unresolved";
|
|
25
|
+
/**
|
|
26
|
+
* Who owns a field block, read from its `object_id` (#1990): `owner` itself,
|
|
27
|
+
* another app, element or task, or nobody extraction can name. fieldFromTf
|
|
28
|
+
* extracts only blocks whose `object_id` references `owner`; a clone keeps a
|
|
29
|
+
* reference to a field it does not copy only when that field is "foreign".
|
|
30
|
+
* - A bare id is "own" when it is `ownerId` (the owner's platform id, any
|
|
31
|
+
* case) and "foreign" otherwise.
|
|
32
|
+
* - An app, element or task `.id` reference is "own" when it is the owner's
|
|
33
|
+
* resource, and "foreign" for any other resource or another type.
|
|
34
|
+
* - A data lookup of the owner's type is "own" when it finds the owner by
|
|
35
|
+
* the attribute the provider looks it up by (see `dataLookupKey`: an app
|
|
36
|
+
* by namespace, else name; an element by namespace, else name, else
|
|
37
|
+
* handle; a task by name), and "foreign" when that attribute names
|
|
38
|
+
* something else.
|
|
39
|
+
* "unresolved" (fail closed) is a missing `ownerId` for a bare id, a string
|
|
40
|
+
* that is not a platform id, an `object_id` that is not an app, element or
|
|
41
|
+
* task `.id`, or a data lookup whose deciding attribute is missing, not a
|
|
42
|
+
* literal string, or absent from the owner's block.
|
|
43
|
+
*/
|
|
44
|
+
export declare function fieldBlockOwner(objectId: TfValue | undefined, owner: Pick<FieldOwner, "type" | "label">, ctx: FromTfContext, ownerId: string | undefined): FieldBlockOwner;
|
|
21
45
|
/**
|
|
22
46
|
* One field block → its normalized entry; undefined = skipped with a
|
|
23
47
|
* diagnostic (unknown resource type, or a field belonging to a different
|
|
@@ -214,7 +214,7 @@ function selfSystemField(v, owner, ctx) {
|
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
/** Whether one of the owner's own field resources is keyed `fieldKey`; true when the stream can't be listed. */
|
|
217
|
-
function ownerMayHaveCustomField(owner, fieldKey, ctx) {
|
|
217
|
+
export function ownerMayHaveCustomField(owner, fieldKey, ctx) {
|
|
218
218
|
if (ctx.resourcesOfType === undefined)
|
|
219
219
|
return true;
|
|
220
220
|
const scope = owner.scope ?? "app";
|
|
@@ -584,6 +584,82 @@ function staticParentLinkageFromTf(value, optionsValue, owner, ctx, where) {
|
|
|
584
584
|
...(optionParentLabels.size > 0 && { optionParentLabels }),
|
|
585
585
|
};
|
|
586
586
|
}
|
|
587
|
+
const FIELD_OWNER_RESOURCE_TYPES = new Set(["elementum_app", "elementum_element", "elementum_task"]);
|
|
588
|
+
const BARE_ASPECT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
589
|
+
/**
|
|
590
|
+
* Who owns a field block, read from its `object_id` (#1990): `owner` itself,
|
|
591
|
+
* another app, element or task, or nobody extraction can name. fieldFromTf
|
|
592
|
+
* extracts only blocks whose `object_id` references `owner`; a clone keeps a
|
|
593
|
+
* reference to a field it does not copy only when that field is "foreign".
|
|
594
|
+
* - A bare id is "own" when it is `ownerId` (the owner's platform id, any
|
|
595
|
+
* case) and "foreign" otherwise.
|
|
596
|
+
* - An app, element or task `.id` reference is "own" when it is the owner's
|
|
597
|
+
* resource, and "foreign" for any other resource or another type.
|
|
598
|
+
* - A data lookup of the owner's type is "own" when it finds the owner by
|
|
599
|
+
* the attribute the provider looks it up by (see `dataLookupKey`: an app
|
|
600
|
+
* by namespace, else name; an element by namespace, else name, else
|
|
601
|
+
* handle; a task by name), and "foreign" when that attribute names
|
|
602
|
+
* something else.
|
|
603
|
+
* "unresolved" (fail closed) is a missing `ownerId` for a bare id, a string
|
|
604
|
+
* that is not a platform id, an `object_id` that is not an app, element or
|
|
605
|
+
* task `.id`, or a data lookup whose deciding attribute is missing, not a
|
|
606
|
+
* literal string, or absent from the owner's block.
|
|
607
|
+
*/
|
|
608
|
+
export function fieldBlockOwner(objectId, owner, ctx, ownerId) {
|
|
609
|
+
if (typeof objectId === "string") {
|
|
610
|
+
if (ownerId === undefined || !BARE_ASPECT_ID.test(objectId))
|
|
611
|
+
return "unresolved";
|
|
612
|
+
return objectId.toLowerCase() === ownerId.toLowerCase() ? "own" : "foreign";
|
|
613
|
+
}
|
|
614
|
+
if (objectId === undefined ||
|
|
615
|
+
!isTfExpr(objectId) ||
|
|
616
|
+
(objectId.$expr !== "resource-attr" && objectId.$expr !== "data-attr") ||
|
|
617
|
+
!FIELD_OWNER_RESOURCE_TYPES.has(objectId.type) ||
|
|
618
|
+
objectId.path.length !== 1 ||
|
|
619
|
+
objectId.path[0] !== "id") {
|
|
620
|
+
return "unresolved";
|
|
621
|
+
}
|
|
622
|
+
if (objectId.type !== owner.type)
|
|
623
|
+
return "foreign";
|
|
624
|
+
if (objectId.$expr === "resource-attr")
|
|
625
|
+
return objectId.label === owner.label ? "own" : "foreign";
|
|
626
|
+
const lookup = ctx.dataAttrs?.(objectId.type, objectId.label);
|
|
627
|
+
const key = dataLookupKey(objectId.type, lookup);
|
|
628
|
+
if (key === undefined)
|
|
629
|
+
return "unresolved";
|
|
630
|
+
const ownValue = ctx.resourceByAddress?.(`${owner.type}.${owner.label}`)?.attrs[key];
|
|
631
|
+
if (typeof ownValue !== "string" || ownValue === "")
|
|
632
|
+
return "unresolved";
|
|
633
|
+
// The provider compares case-insensitively (app, element and task data sources).
|
|
634
|
+
return (lookup?.[key]).toLowerCase() === ownValue.toLowerCase() ? "own" : "foreign";
|
|
635
|
+
}
|
|
636
|
+
/** Each data source's lookup attributes, in the order it tries them. */
|
|
637
|
+
const DATA_LOOKUP_KEYS = new Map([
|
|
638
|
+
// app_data_source.go: namespace when set, else name.
|
|
639
|
+
["elementum_app", ["namespace", "name"]],
|
|
640
|
+
// element_data_source.go: namespace, else name, else handle.
|
|
641
|
+
["elementum_element", ["namespace", "name", "handle"]],
|
|
642
|
+
// task_data_source.go: name only.
|
|
643
|
+
["elementum_task", ["name"]],
|
|
644
|
+
]);
|
|
645
|
+
/**
|
|
646
|
+
* The attribute a `type` data source finds its target by: the first one in
|
|
647
|
+
* the provider's order that has a value. Only an absent, null or literal
|
|
648
|
+
* empty attribute falls through to the next, as in the provider. One that
|
|
649
|
+
* has a value pull cannot read (a `local`, a function call) decides the
|
|
650
|
+
* lookup but cannot be compared, so the result is undefined and the owner
|
|
651
|
+
* check fails closed, as it does when no attribute is set. A display name is
|
|
652
|
+
* compared only when the namespace is unset, since names are not unique.
|
|
653
|
+
*/
|
|
654
|
+
function dataLookupKey(type, attrs) {
|
|
655
|
+
for (const key of DATA_LOOKUP_KEYS.get(type) ?? []) {
|
|
656
|
+
const value = attrs?.[key];
|
|
657
|
+
if (value === undefined || value === null || value === "")
|
|
658
|
+
continue;
|
|
659
|
+
return typeof value === "string" ? key : undefined;
|
|
660
|
+
}
|
|
661
|
+
return undefined;
|
|
662
|
+
}
|
|
587
663
|
/**
|
|
588
664
|
* One field block → its normalized entry; undefined = skipped with a
|
|
589
665
|
* diagnostic (unknown resource type, or a field belonging to a different
|
|
@@ -620,6 +696,8 @@ export function fieldFromTf(block, owner, ctx) {
|
|
|
620
696
|
ctx.diagnostics.push(`${where}: unhandled attribute "${key}" — the export dialect grew; extend fieldFromTf deliberately`);
|
|
621
697
|
}
|
|
622
698
|
}
|
|
699
|
+
// Only an own block is extracted; a clone tells the other owners apart
|
|
700
|
+
// with fieldBlockOwner (#1990).
|
|
623
701
|
const objectLabel = resourceRefLabel(attrs["object_id"], owner.type);
|
|
624
702
|
if (objectLabel !== owner.label) {
|
|
625
703
|
ctx.diagnostics.push(`${where}: object_id does not reference ${owner.type}.${owner.label}; skipped`);
|
|
@@ -71,6 +71,13 @@ export const fieldModule = {
|
|
|
71
71
|
}),
|
|
72
72
|
refFromAuthoring: () => undefined,
|
|
73
73
|
},
|
|
74
|
+
roundtrip: {
|
|
75
|
+
referenceAliases: [],
|
|
76
|
+
// A filter on a foreign record's field: the build interpolates the
|
|
77
|
+
// field's lookup (`record.${data.elementum_field.<x>.id}`), the export
|
|
78
|
+
// inlines the field's id (#1701).
|
|
79
|
+
stateResolvedDataLookups: [{ dataType: FIELD_DATA_RESOURCE_TYPE }],
|
|
80
|
+
},
|
|
74
81
|
};
|
|
75
82
|
/**
|
|
76
83
|
* `elementum_managed_field_order` orders an owner's custom fields. Build emits
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* non-canonical bag key: it has no well-defined terraform address.
|
|
11
11
|
*/
|
|
12
12
|
import { type OrgRefLookup, type WorkspaceAspect } from "../../engine/build/context.js";
|
|
13
|
-
import { type FieldOwnerScope, type TfBlock, type TfExpr, type TfValue } from "../../engine/tf/index.js";
|
|
13
|
+
import { type ChildResourceScope, type FieldOwnerScope, type TfBlock, type TfExpr, type TfValue } from "../../engine/tf/index.js";
|
|
14
14
|
import { type PicklistValueWire } from "./options.js";
|
|
15
15
|
/**
|
|
16
16
|
* The authored fields known to belong to an app/element. Maps produced by a
|
|
@@ -163,4 +163,33 @@ export interface FieldToTfResult {
|
|
|
163
163
|
export declare function claimFieldDisplayName(seen: Map<string, string>, field: FieldToTfResult): void;
|
|
164
164
|
export declare function fieldToTf(typeKey: string, inner: FieldInnerWire, opts: FieldToTfOptions): FieldToTfResult | undefined;
|
|
165
165
|
export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: FieldOwnerScope, fieldOwnership?: FieldOwnership): TfExpr | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Why build leaves out an entry: its field reference has no field in source
|
|
168
|
+
* and no platform id (#1966, #1978). The gaps below state what apply then
|
|
169
|
+
* does, not the generic "the platform keeps its current value".
|
|
170
|
+
*/
|
|
171
|
+
export declare const UNRESOLVED_FIELD_REF = "field reference is unresolved (skipped during extract)";
|
|
172
|
+
/**
|
|
173
|
+
* Why build can't reference `refName` on another app or element of this
|
|
174
|
+
* workspace by its resource (#1966): that root's source has no such custom
|
|
175
|
+
* field, because its pull did not extract it or it was removed, so its
|
|
176
|
+
* resource address would name a resource no block declares and fail plan for
|
|
177
|
+
* the whole workspace. Callers look the field up by name instead, the way the
|
|
178
|
+
* export did; they report this reason only when the ref has no name to look
|
|
179
|
+
* it up by. Undefined when the root's fields are unknown, when `refName` is
|
|
180
|
+
* one of them, or when it is a system field.
|
|
181
|
+
*/
|
|
182
|
+
export declare function unauthoredSiblingFieldRef(refName: string, sibling: {
|
|
183
|
+
readonly kind: ChildResourceScope;
|
|
184
|
+
readonly refName: string;
|
|
185
|
+
readonly fieldOwnership?: FieldOwnership;
|
|
186
|
+
}): string | undefined;
|
|
187
|
+
/** A field ref's name, when it has one build can look the field up by. */
|
|
188
|
+
export declare function fieldLookupName(value: {
|
|
189
|
+
readonly name?: string;
|
|
190
|
+
}): string | undefined;
|
|
191
|
+
/** A dropped entry of `holder` (e.g. "dynamic layout"): apply removes it from the platform (#1978). */
|
|
192
|
+
export declare function droppedEntryGap(where: string, detail: string, holder: string): string;
|
|
193
|
+
/** A whole `resource` (e.g. "relationship") build leaves out: if it is already managed, plan destroys it (#1978). */
|
|
194
|
+
export declare function skippedResourceGap(where: string, detail: string, resource: string): string;
|
|
166
195
|
export {};
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* non-canonical bag key: it has no well-defined terraform address.
|
|
11
11
|
*/
|
|
12
12
|
import { EntityTfError } from "../../engine/entity.js";
|
|
13
|
+
import { typedCoverageGap } from "../../engine/coverage-gaps.js";
|
|
13
14
|
import { workspaceAspectKey } from "../../engine/build/context.js";
|
|
14
15
|
import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
15
16
|
import { SYSTEM_FIELD_KEY_SET, systemFieldTag } from "../../core/system-fields.js";
|
|
@@ -873,3 +874,53 @@ export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app
|
|
|
873
874
|
return undefined;
|
|
874
875
|
return expr.resourceAttr(subType.resourceType, scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(refName), scope), ["id"]);
|
|
875
876
|
}
|
|
877
|
+
/**
|
|
878
|
+
* Why build leaves out an entry: its field reference has no field in source
|
|
879
|
+
* and no platform id (#1966, #1978). The gaps below state what apply then
|
|
880
|
+
* does, not the generic "the platform keeps its current value".
|
|
881
|
+
*/
|
|
882
|
+
export const UNRESOLVED_FIELD_REF = "field reference is unresolved (skipped during extract)";
|
|
883
|
+
/**
|
|
884
|
+
* Why build can't reference `refName` on another app or element of this
|
|
885
|
+
* workspace by its resource (#1966): that root's source has no such custom
|
|
886
|
+
* field, because its pull did not extract it or it was removed, so its
|
|
887
|
+
* resource address would name a resource no block declares and fail plan for
|
|
888
|
+
* the whole workspace. Callers look the field up by name instead, the way the
|
|
889
|
+
* export did; they report this reason only when the ref has no name to look
|
|
890
|
+
* it up by. Undefined when the root's fields are unknown, when `refName` is
|
|
891
|
+
* one of them, or when it is a system field.
|
|
892
|
+
*/
|
|
893
|
+
export function unauthoredSiblingFieldRef(refName, sibling) {
|
|
894
|
+
if (sibling.fieldOwnership === undefined || sibling.fieldOwnership.has(refName))
|
|
895
|
+
return undefined;
|
|
896
|
+
const systemField = sibling.kind === "element"
|
|
897
|
+
? ELEMENT_SYSTEM_FIELD_KEY_SET.has(refName)
|
|
898
|
+
: SYSTEM_FIELD_KEY_SET.has(refName);
|
|
899
|
+
if (systemField)
|
|
900
|
+
return undefined;
|
|
901
|
+
const owner = `${sibling.kind} "${sibling.refName}"`;
|
|
902
|
+
return `field "${refName}" is not in the source of ${owner} (its pull did not extract it, or it was removed) ` +
|
|
903
|
+
`and the reference has no name to look it up by; add the field to ${owner}'s source, or re-pull ${owner}`;
|
|
904
|
+
}
|
|
905
|
+
/** A field ref's name, when it has one build can look the field up by. */
|
|
906
|
+
export function fieldLookupName(value) {
|
|
907
|
+
return value.name !== undefined && value.name.trim() !== "" ? value.name : undefined;
|
|
908
|
+
}
|
|
909
|
+
/** A dropped entry of `holder` (e.g. "dynamic layout"): apply removes it from the platform (#1978). */
|
|
910
|
+
export function droppedEntryGap(where, detail, holder) {
|
|
911
|
+
return typedCoverageGap({
|
|
912
|
+
kind: "dropped",
|
|
913
|
+
entity: where,
|
|
914
|
+
detail,
|
|
915
|
+
consequence: `the entry is not built, so apply removes it from the ${holder} on the platform if it is there`,
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
/** A whole `resource` (e.g. "relationship") build leaves out: if it is already managed, plan destroys it (#1978). */
|
|
919
|
+
export function skippedResourceGap(where, detail, resource) {
|
|
920
|
+
return typedCoverageGap({
|
|
921
|
+
kind: "skipped",
|
|
922
|
+
entity: where,
|
|
923
|
+
detail,
|
|
924
|
+
consequence: `the ${resource} is not built; if it is already managed, plan destroys it and apply deletes it from the platform`,
|
|
925
|
+
});
|
|
926
|
+
}
|
|
@@ -4,7 +4,7 @@ import { NO_CANVAS, } from "../../graph/types.js";
|
|
|
4
4
|
import { printFileReader } from "./deserializer/print-file-reader.js";
|
|
5
5
|
import { fileReaderFromTf } from "./from-tf.js";
|
|
6
6
|
import { fileReaderToTf } from "./to-tf.js";
|
|
7
|
-
import { ALL_FILE_READER_RESOURCE_TYPES, FILE_READER_SUB_TYPES } from "./types.js";
|
|
7
|
+
import { ALL_FILE_READER_RESOURCE_TYPES, FILE_READER_BAG, FILE_READER_SUB_TYPES } from "./types.js";
|
|
8
8
|
function isConfigured(value) {
|
|
9
9
|
return (typeof value === "object" &&
|
|
10
10
|
value !== null &&
|
|
@@ -79,7 +79,7 @@ function extractFileReaders(ownBlocks, _stream, ctx) {
|
|
|
79
79
|
export const fileReaderModule = {
|
|
80
80
|
kind: "file-reader",
|
|
81
81
|
stream: { role: "streamMember" },
|
|
82
|
-
authoring: { unit: "ownFile", bag:
|
|
82
|
+
authoring: { unit: "ownFile", bag: FILE_READER_BAG },
|
|
83
83
|
parents: [{ parent: "app", child: "file-reader" }, { parent: "element", child: "file-reader" }],
|
|
84
84
|
resource: {
|
|
85
85
|
shape: "subTypes",
|
|
@@ -106,7 +106,7 @@ export const fileReaderModule = {
|
|
|
106
106
|
catalog: {
|
|
107
107
|
participates: true,
|
|
108
108
|
refKind: "documentModel",
|
|
109
|
-
catalogBag:
|
|
109
|
+
catalogBag: FILE_READER_BAG,
|
|
110
110
|
renderOrder: 55,
|
|
111
111
|
catalogRoot: "app",
|
|
112
112
|
factoryName: "documentModelRef",
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* `skill/to-tf.ts`'s shape for a single-resource own-file kind.
|
|
5
5
|
*/
|
|
6
6
|
import { EntityTfError } from "../../engine/entity.js";
|
|
7
|
-
import {
|
|
7
|
+
import { expr } from "../../engine/tf/index.js";
|
|
8
8
|
import { APP_RESOURCE_TYPE } from "../app/module.js";
|
|
9
|
-
import { FILE_READER_SUB_TYPE_BY_TYPE_KEY } from "./types.js";
|
|
9
|
+
import { FILE_READER_SUB_TYPE_BY_TYPE_KEY, fileReaderResourceLabel } from "./types.js";
|
|
10
10
|
function serializeStructureField(f) {
|
|
11
11
|
switch (f.type) {
|
|
12
12
|
case "text":
|
|
@@ -65,7 +65,7 @@ export function fileReaderToTf(entity, ctx) {
|
|
|
65
65
|
if (subType === undefined || subType.implemented !== true) {
|
|
66
66
|
throw new EntityTfError(`file reader "${entity.refName}": type "${payload.type}" does not build on the terraform path yet`);
|
|
67
67
|
}
|
|
68
|
-
const tfLabel =
|
|
68
|
+
const tfLabel = fileReaderResourceLabel(ctx.appTfLabel, entity.refName);
|
|
69
69
|
const attrs = {
|
|
70
70
|
app_id: expr.resourceAttr(APP_RESOURCE_TYPE, ctx.appTfLabel, ["id"]),
|
|
71
71
|
name: payload.name,
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The file-reader entity's sub-type table. Five platform resource types share
|
|
3
|
-
* one ownership shape (app-scoped, own-file, one `.ts` per instance):
|
|
4
|
-
* `elementum_excel_file_reader`, `elementum_json_file_reader`,
|
|
5
|
-
* `elementum_text_file_reader`, `elementum_xml_file_reader`, and
|
|
6
|
-
* `elementum_ai_file_reader` — exactly the `entities/field/types.ts` /
|
|
7
|
-
* `entities/agent-tool/types.ts` pattern, one ROW per sub-type.
|
|
8
|
-
*
|
|
9
|
-
* All five variants are implemented. excel/json/text are the three
|
|
10
|
-
* `elementum_file_reader_task.file_reader_id` accepts (the provider's own
|
|
11
|
-
* schema docs say so explicitly); `ai` backs `elementum_ai_file_read_task`
|
|
12
|
-
* instead (see `entities/automation/types.ts`'s `aiFileAnalysis` row) — a
|
|
13
|
-
* live capture also confirms a plain `elementum_file_reader_task` can
|
|
14
|
-
* reference one. XML shares JSON's recursive structure dialect under the
|
|
15
|
-
* provider's `values` attribute.
|
|
16
|
-
*/
|
|
17
1
|
export interface FileReaderSubType {
|
|
18
2
|
/** The authoring `type` discriminant (`FileReaderOptions.type`). */
|
|
19
3
|
readonly typeKey: "excel" | "json" | "text" | "xml" | "ai";
|
|
@@ -31,3 +15,7 @@ export declare const FILE_READER_SUB_TYPE_BY_RESOURCE: ReadonlyMap<string, FileR
|
|
|
31
15
|
export declare const IMPLEMENTED_FILE_READER_RESOURCE_TYPES: readonly string[];
|
|
32
16
|
/** Every declared file-reader resource type — stream partition recognizes these by name. */
|
|
33
17
|
export declare const ALL_FILE_READER_RESOURCE_TYPES: readonly string[];
|
|
18
|
+
/** Own-file bag (`apps/<ref>/fileReaders/<refName>.ts`) and catalog bag. */
|
|
19
|
+
export declare const FILE_READER_BAG = "fileReaders";
|
|
20
|
+
/** The Terraform label build gives an app's file reader `refName`. */
|
|
21
|
+
export declare function fileReaderResourceLabel(ownerTfLabel: string, refName: string): string;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* reference one. XML shares JSON's recursive structure dialect under the
|
|
15
15
|
* provider's `values` attribute.
|
|
16
16
|
*/
|
|
17
|
+
import { appScopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/labels.js";
|
|
17
18
|
export const FILE_READER_SUB_TYPES = [
|
|
18
19
|
{ typeKey: "excel", resourceType: "elementum_excel_file_reader", implemented: true, unreadableAttributes: ["document_content", "document_name", "file_type"] },
|
|
19
20
|
{ typeKey: "json", resourceType: "elementum_json_file_reader", implemented: true },
|
|
@@ -27,3 +28,9 @@ export const FILE_READER_SUB_TYPE_BY_RESOURCE = new Map(FILE_READER_SUB_TYPES.ma
|
|
|
27
28
|
export const IMPLEMENTED_FILE_READER_RESOURCE_TYPES = FILE_READER_SUB_TYPES.filter((t) => t.implemented === true).map((t) => t.resourceType);
|
|
28
29
|
/** Every declared file-reader resource type — stream partition recognizes these by name. */
|
|
29
30
|
export const ALL_FILE_READER_RESOURCE_TYPES = FILE_READER_SUB_TYPES.map((t) => t.resourceType);
|
|
31
|
+
/** Own-file bag (`apps/<ref>/fileReaders/<refName>.ts`) and catalog bag. */
|
|
32
|
+
export const FILE_READER_BAG = "fileReaders";
|
|
33
|
+
/** The Terraform label build gives an app's file reader `refName`. */
|
|
34
|
+
export function fileReaderResourceLabel(ownerTfLabel, refName) {
|
|
35
|
+
return appScopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(refName));
|
|
36
|
+
}
|
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
import { type EntityKindModule } from "../../graph/types.js";
|
|
3
3
|
/** org.ts / OrgRefLookup bag — keep in lockstep with `data.orgBag`. */
|
|
4
4
|
export declare const GROUP_ORG_BAG: "groups";
|
|
5
|
+
export declare const GROUP_RESOURCE_TYPE = "elementum_group";
|
|
5
6
|
export declare const groupModule: EntityKindModule;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { namedOnlyFactoryEntry } from "../../catalog/render-helpers.js";
|
|
3
3
|
/** org.ts / OrgRefLookup bag — keep in lockstep with `data.orgBag`. */
|
|
4
4
|
export const GROUP_ORG_BAG = "groups";
|
|
5
|
+
export const GROUP_RESOURCE_TYPE = "elementum_group";
|
|
5
6
|
export const groupModule = {
|
|
6
7
|
kind: "group",
|
|
7
8
|
stream: { role: "streamMember" },
|
|
@@ -23,7 +24,7 @@ export const groupModule = {
|
|
|
23
24
|
},
|
|
24
25
|
authoring: { unit: "inline", bag: "groups" },
|
|
25
26
|
parents: [{ parent: "org", child: "group" }],
|
|
26
|
-
resource: { shape: "single", resourceType:
|
|
27
|
+
resource: { shape: "single", resourceType: GROUP_RESOURCE_TYPE, adoptable: true },
|
|
27
28
|
lifecycle: { participates: true },
|
|
28
29
|
canvas: { participates: true, label: "Groups", glyph: "◎", component: "orgIdentity" },
|
|
29
30
|
catalog: {
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { type FromTfContext } from "../../engine/pull/context.js";
|
|
2
2
|
import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
|
|
3
3
|
import type { NormalizedRecordCreateForm } from "../app/deserializer/normalize.js";
|
|
4
|
+
import { type UnextractedFieldOwner } from "../view/from-tf.js";
|
|
4
5
|
export interface RecordCreateFormOwner {
|
|
5
6
|
readonly type: string;
|
|
6
7
|
readonly label: string;
|
|
8
|
+
/**
|
|
9
|
+
* The owner's TF label (`preston_high`), which its child resource labels
|
|
10
|
+
* carry. Never the camelCase ref: the two differ once the label has an
|
|
11
|
+
* underscore (#2046).
|
|
12
|
+
*/
|
|
7
13
|
readonly ownerTfLabel: string;
|
|
8
14
|
readonly scope: ChildResourceScope;
|
|
15
|
+
/** The owner's extracted fields, so a field pull did not extract keeps its platform id (#1966). */
|
|
16
|
+
readonly unextracted?: UnextractedFieldOwner;
|
|
9
17
|
}
|
|
10
18
|
/** Provider resource -> id-free normalized create-form authoring. */
|
|
11
19
|
export declare function recordCreateFormFromTf(block: TfBlock | undefined, owner: RecordCreateFormOwner, ctx: FromTfContext): NormalizedRecordCreateForm | undefined;
|
|
@@ -2,6 +2,7 @@ import { optionalString, plainObject, resourceRefLabel } from "../../engine/pull
|
|
|
2
2
|
import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
|
|
3
3
|
import { scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
4
4
|
import { fieldKeyFromTfValue } from "../field/from-tf.js";
|
|
5
|
+
import { unextractedFieldRefId } from "../view/from-tf.js";
|
|
5
6
|
import { RECORD_CREATE_FORM_RESOURCE_TYPE } from "./module.js";
|
|
6
7
|
const KNOWN_ATTRS = new Set(["app_id", "sections"]);
|
|
7
8
|
const KNOWN_SECTION_ATTRS = new Set([
|
|
@@ -45,8 +46,15 @@ function sectionFromTf(raw, index, formWhere, owner, ctx) {
|
|
|
45
46
|
return undefined;
|
|
46
47
|
}
|
|
47
48
|
const fields = [];
|
|
48
|
-
for (const fieldId of fieldIds) {
|
|
49
|
-
|
|
49
|
+
for (const [fieldIndex, fieldId] of fieldIds.entries()) {
|
|
50
|
+
// Field resource labels carry the owner's TF label (`apps_<label>_<label>_…`),
|
|
51
|
+
// not its camelCase name (#1978).
|
|
52
|
+
const resolved = fieldKeyFromTfValue(fieldId, tfLabelToTsLabel(owner.label), owner.label, owner.scope, ctx);
|
|
53
|
+
// A field pull did not extract keeps its platform id: its key would print
|
|
54
|
+
// as nothing and crash build (#1966). With no id the pull fails (#1978).
|
|
55
|
+
const key = owner.unextracted === undefined
|
|
56
|
+
? resolved
|
|
57
|
+
: unextractedFieldRefId(fieldId, resolved, owner.unextracted, ctx, `${formWhere}.sections[${index}].field_ids[${fieldIndex}]`);
|
|
50
58
|
if (key === undefined) {
|
|
51
59
|
ctx.diagnostics.push(`${where}: field_ids entry ${JSON.stringify(fieldId)} is not a known field reference; dropped`);
|
|
52
60
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
|
|
2
|
-
|
|
2
|
+
import { type UnsafePlatformId } from "../../core/platform-id.js";
|
|
3
|
+
export type RecordCreateFormFieldRefWire = string | UnsafePlatformId | {
|
|
3
4
|
readonly refName?: string;
|
|
4
5
|
readonly fieldType?: string;
|
|
5
6
|
readonly parent?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { expr, isCanonicalTsLabel, scopedResourceLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isUnsafePlatformId } from "../../core/platform-id.js";
|
|
3
|
+
import { droppedEntryGap, fieldRefToTfValue, UNRESOLVED_FIELD_REF } from "../field/to-tf.js";
|
|
3
4
|
import { SUB_TYPE_BY_AUTHORING_TYPE } from "../field/types.js";
|
|
4
5
|
import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
|
|
5
6
|
import { RECORD_CREATE_FORM_RESOURCE_TYPE } from "./module.js";
|
|
@@ -55,7 +56,18 @@ export function recordCreateFormToTf(form, opts) {
|
|
|
55
56
|
}
|
|
56
57
|
function resolveFields(refs, where, opts) {
|
|
57
58
|
const out = [];
|
|
58
|
-
for (const ref of refs) {
|
|
59
|
+
for (const [index, ref] of refs.entries()) {
|
|
60
|
+
// A field pull did not extract stays as its platform id (#1736, #1966).
|
|
61
|
+
if (isUnsafePlatformId(ref)) {
|
|
62
|
+
out.push(ref.value);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
// Pulled source prints `undefined as any` for a field pull skipped with
|
|
66
|
+
// no id; report it instead of crashing on it (#1966).
|
|
67
|
+
if (typeof ref !== "string" && (ref === null || typeof ref !== "object")) {
|
|
68
|
+
opts.diagnostics.push(droppedEntryGap(`${where}.fields[${index}]`, `${UNRESOLVED_FIELD_REF}; dropped`, "record create form"));
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
59
71
|
if (typeof ref === "string") {
|
|
60
72
|
const attr = SYSTEM_FIELD_ID_ATTR_BY_KEY.get(ref);
|
|
61
73
|
if (attr === undefined)
|
|
@@ -2,13 +2,21 @@ import { type FromTfContext } from "../../engine/pull/context.js";
|
|
|
2
2
|
import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
|
|
3
3
|
import { type AccessPolicyOwner } from "../access-policy/from-tf.js";
|
|
4
4
|
import type { NormalizedRelationship } from "../app/deserializer/normalize.js";
|
|
5
|
+
import { type UnextractedFieldOwner } from "../view/from-tf.js";
|
|
5
6
|
export interface RelationshipOwner {
|
|
6
7
|
/** Public EDK vocabulary; provider resource names stay at the TF boundary. */
|
|
7
8
|
readonly kind: "app" | "element";
|
|
8
9
|
readonly label: string;
|
|
9
10
|
readonly ownerRefName: string;
|
|
11
|
+
/**
|
|
12
|
+
* The owner's TF label (`preston_high`), which its child resource labels
|
|
13
|
+
* carry. Never the camelCase ref: the two differ once the label has an
|
|
14
|
+
* underscore (#2046).
|
|
15
|
+
*/
|
|
10
16
|
readonly ownerTfLabel: string;
|
|
11
17
|
readonly scope: ChildResourceScope;
|
|
18
|
+
/** The owner's extracted fields, so a field pull did not extract keeps its platform id (#1966). */
|
|
19
|
+
readonly unextracted?: UnextractedFieldOwner;
|
|
12
20
|
}
|
|
13
21
|
export declare function relationshipsFromTf(blocks: readonly TfBlock[], owner: RelationshipOwner, ctx: FromTfContext): NormalizedRelationship[];
|
|
14
22
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
|
|
2
|
-
import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
|
|
1
|
+
import { dataRefLabel, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
|
|
2
|
+
import { expr, isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
|
|
3
3
|
import { filterFromTf } from "../access-policy/from-tf.js";
|
|
4
4
|
import { decodeForeignDataField, fieldKeyFromTfRef, fieldKeyFromTfValue } from "../field/from-tf.js";
|
|
5
5
|
import { resolveDataAspectTarget, resolveDataTaskTarget } from "../shared/aspect-target-from-tf.js";
|
|
6
6
|
import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
|
|
7
|
+
import { bareForeignFieldIdRef, isBarePlatformId, resolveOwnDataFieldRef, unextractedFieldRefId } from "../view/from-tf.js";
|
|
7
8
|
import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
|
|
8
9
|
const KNOWN_ATTRS = new Set(["object_id", "related_object_id", "columns", "filter"]);
|
|
9
10
|
export function relationshipsFromTf(blocks, owner, ctx) {
|
|
@@ -43,14 +44,49 @@ function relationshipFromTf(block, owner, ctx) {
|
|
|
43
44
|
continue;
|
|
44
45
|
}
|
|
45
46
|
const rec = raw;
|
|
46
|
-
|
|
47
|
-
const
|
|
47
|
+
// Field resource labels carry the owner's TF label, not its camelCase name (#1978).
|
|
48
|
+
const fieldKey = fieldKeyFromTfValue(rec["field_id"], owner.ownerRefName, owner.label, owner.scope, ctx);
|
|
49
|
+
// A field pull did not extract keeps its platform id: its key would print
|
|
50
|
+
// as nothing and build would drop the column (#1966). With no id the pull
|
|
51
|
+
// fails (#1978).
|
|
52
|
+
const field = owner.unextracted === undefined
|
|
53
|
+
? fieldKey
|
|
54
|
+
: unextractedFieldRefId(rec["field_id"], fieldKey, owner.unextracted, ctx, `${where}.columns[${index}]`);
|
|
55
|
+
// A bare related id ei couldn't name resolves the same way as the owner
|
|
56
|
+
// side, so the join column is never dropped silently (#1991).
|
|
57
|
+
const relatedRaw = rec["related_field_id"];
|
|
58
|
+
const relatedSite = `${where}.columns[${index}].related_field_id`;
|
|
59
|
+
// On a relationship to its own app or element, the related side is the
|
|
60
|
+
// owner's field too, so an own data source resolves and fails closed the
|
|
61
|
+
// way the owner side does (#1991).
|
|
62
|
+
const ownRelated = owner.unextracted !== undefined && target.kind === owner.kind && target.key === owner.ownerRefName
|
|
63
|
+
? resolveOwnDataFieldRef(relatedRaw, owner.unextracted, ctx, relatedSite)
|
|
64
|
+
: undefined;
|
|
65
|
+
const decodedRelated = ownRelated === "failedClosed" ? undefined : relatedFieldRef(relatedRaw, target, ctx);
|
|
66
|
+
const relatedField = (ownRelated !== undefined && ownRelated !== "failedClosed" && decodedRelated?.kind === "field" && decodedRelated.key !== ownRelated.key
|
|
67
|
+
? { ...decodedRelated, key: ownRelated.key, name: ownDataName(relatedRaw, ctx) ?? ownRelated.key }
|
|
68
|
+
: decodedRelated)
|
|
69
|
+
?? (ownRelated === undefined && typeof relatedRaw === "string" && isBarePlatformId(relatedRaw)
|
|
70
|
+
? bareRelatedFieldRef(relatedRaw, target, owner, ctx, relatedSite)
|
|
71
|
+
: undefined);
|
|
48
72
|
if (field === undefined || relatedField === undefined) {
|
|
49
73
|
ctx.diagnostics.push(`${where}.columns[${index}]: field references are not resolvable; dropped`);
|
|
50
74
|
continue;
|
|
51
75
|
}
|
|
52
76
|
columns.push({ field, relatedField });
|
|
53
77
|
}
|
|
78
|
+
// A relationship whose columns were all dropped would print as
|
|
79
|
+
// `columns: []`, which reads like an exported empty list (that one stays
|
|
80
|
+
// as is), so it fails instead (#1991).
|
|
81
|
+
if (columnsRaw.length > 0 && columns.length === 0) {
|
|
82
|
+
reportAuthoringBlocker(ctx, {
|
|
83
|
+
address: where,
|
|
84
|
+
description: `${where}: none of its ${columnsRaw.length} join column(s) could be resolved, so it would be written with no columns`,
|
|
85
|
+
remedy: ctx.cloning !== undefined
|
|
86
|
+
? "Check that each join column's fields still exist on both sides of the source app's relationship and run the clone again; if the export keeps naming them by an id it doesn't import, report it to the EDK maintainers."
|
|
87
|
+
: "Check that each join column's fields still exist on both sides and pull again; if the export keeps naming them by an id it doesn't import, report it to the EDK maintainers.",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
54
90
|
const key = scopedLabelToBagKey(owner.ownerTfLabel, block.label ?? "", owner.scope);
|
|
55
91
|
let filter;
|
|
56
92
|
if (block.attrs["filter"] !== undefined) {
|
|
@@ -83,13 +119,19 @@ function relationshipFromTf(block, owner, ctx) {
|
|
|
83
119
|
filter = filterFromTf(block.attrs["filter"], targetFilterOwner, `${where}.filter`, ctx);
|
|
84
120
|
}
|
|
85
121
|
catch (targetErr) {
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
//
|
|
90
|
-
// filter at all.
|
|
122
|
+
// Neither side decodes the filter. Writing the relationship with no
|
|
123
|
+
// filter would widen it on the next apply, and leaving it out of
|
|
124
|
+
// source drops a live, adopted relationship without a skipped gap,
|
|
125
|
+
// so pull fails closed naming the site (#2046).
|
|
91
126
|
const err = targetErr ?? ownerErr;
|
|
92
|
-
|
|
127
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
128
|
+
reportAuthoringBlocker(ctx, {
|
|
129
|
+
address: where,
|
|
130
|
+
description: `${message.startsWith(where) ? message : `${where}.filter: ${message}`}, so the relationship can't be written to source with its filter`,
|
|
131
|
+
remedy: ctx.cloning !== undefined
|
|
132
|
+
? "Check that each field the source relationship's filter names still exists on its app or element or on the related one, and run the clone again; if the export keeps naming a field pull can't decode, report it to the EDK maintainers."
|
|
133
|
+
: "Check that each field the relationship's filter names still exists on its app or element or on the related one, and pull again; if the export keeps naming a field pull can't decode, report it to the EDK maintainers.",
|
|
134
|
+
});
|
|
93
135
|
return undefined;
|
|
94
136
|
}
|
|
95
137
|
}
|
|
@@ -177,6 +219,42 @@ function targetDataFilterField(label, target, ctx) {
|
|
|
177
219
|
},
|
|
178
220
|
};
|
|
179
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* A related field the export names by a bare platform id (#1991). An id the
|
|
224
|
+
* export imports as one of the target's fields becomes its key. Otherwise the
|
|
225
|
+
* field is the target's, so it keeps its id when the target is another owner
|
|
226
|
+
* (Dax, 11:45); an imported field of no known target goes through its field
|
|
227
|
+
* block (#1990), and anything else fails naming `site` and the id.
|
|
228
|
+
*/
|
|
229
|
+
function bareRelatedFieldRef(v, target, owner, ctx, site) {
|
|
230
|
+
const ownTarget = target.kind === owner.kind && target.key === owner.ownerRefName;
|
|
231
|
+
const imported = ctx.importedResource?.(v);
|
|
232
|
+
const subType = imported === undefined ? undefined : SUB_TYPE_BY_RESOURCE.get(imported.type);
|
|
233
|
+
// Only a field whose block names the target as its owner is the target's.
|
|
234
|
+
const targetLabel = ownTarget ? owner.label : target.managed === true ? target.tfLabel : undefined;
|
|
235
|
+
if (imported !== undefined && subType !== undefined && targetLabel !== undefined && resourceRefLabel(imported.attrs["object_id"], targetResourceType(target)) === targetLabel) {
|
|
236
|
+
const scope = target.kind === "element" ? "element" : "app";
|
|
237
|
+
const key = fieldKeyFromTfRef(expr.resourceAttr(imported.type, imported.label, ["id"]), targetLabel, scope);
|
|
238
|
+
if (key !== undefined) {
|
|
239
|
+
return { kind: target.kind === "table" ? "tableColumn" : "field", key, name: key, parent: target.key, fieldType: subType.authoringType };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const unextracted = owner.unextracted ?? {
|
|
243
|
+
type: owner.kind === "app" ? "elementum_app" : "elementum_element",
|
|
244
|
+
label: owner.label,
|
|
245
|
+
ownerTfLabel: owner.ownerTfLabel,
|
|
246
|
+
scope: owner.kind,
|
|
247
|
+
};
|
|
248
|
+
return bareForeignFieldIdRef(v, unextracted, ctx, site, ownTarget ? undefined : `the relationship's target ${target.kind} ${JSON.stringify(target.name || target.key)}`);
|
|
249
|
+
}
|
|
250
|
+
/** A `data.elementum_field` lookup's own `name`, when it has one. */
|
|
251
|
+
function ownDataName(value, ctx) {
|
|
252
|
+
const label = dataRefLabel(value, "elementum_field");
|
|
253
|
+
return label === undefined ? undefined : ctx.dataName("elementum_field", label);
|
|
254
|
+
}
|
|
255
|
+
function targetResourceType(target) {
|
|
256
|
+
return target.kind === "element" ? "elementum_element" : target.kind === "table" ? "elementum_table" : target.kind === "task" ? "elementum_task" : "elementum_app";
|
|
257
|
+
}
|
|
180
258
|
function relatedFieldRef(value, target, ctx) {
|
|
181
259
|
if (value === undefined)
|
|
182
260
|
return undefined;
|