@elementumai/edk 0.8.0-preview.11 → 0.8.1
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 +378 -324
- package/dist-sdk/src/catalog/ai-provider-models.d.ts +30 -0
- package/dist-sdk/src/catalog/ai-provider-models.js +63 -0
- package/dist-sdk/src/catalog/factories.d.ts +56 -3
- package/dist-sdk/src/catalog/factories.js +65 -2
- package/dist-sdk/src/catalog/from-authoring.js +6 -1
- package/dist-sdk/src/catalog/index.d.ts +3 -2
- package/dist-sdk/src/catalog/index.js +3 -2
- package/dist-sdk/src/catalog/org.d.ts +1 -1
- package/dist-sdk/src/catalog/org.js +83 -6
- package/dist-sdk/src/catalog/render.d.ts +13 -1
- package/dist-sdk/src/catalog/render.js +21 -4
- package/dist-sdk/src/catalog/token.js +14 -0
- package/dist-sdk/src/catalog/types.d.ts +60 -3
- package/dist-sdk/src/catalog/types.js +3 -0
- package/dist-sdk/src/core/system-fields.d.ts +2 -0
- package/dist-sdk/src/core/system-fields.js +2 -0
- package/dist-sdk/src/core/types/ai-provider.d.ts +10 -23
- package/dist-sdk/src/core/types/ai-provider.js +1 -25
- package/dist-sdk/src/core/types/app.d.ts +20 -1
- package/dist-sdk/src/engine/build/context.d.ts +18 -0
- package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
- package/dist-sdk/src/engine/build/source-context.js +23 -0
- package/dist-sdk/src/engine/pull/context.d.ts +15 -0
- package/dist-sdk/src/engine/pull/org.d.ts +10 -0
- package/dist-sdk/src/engine/pull/org.js +34 -4
- package/dist-sdk/src/engine/tf/index.d.ts +1 -1
- package/dist-sdk/src/engine/tf/index.js +1 -1
- package/dist-sdk/src/engine/tf/labels.d.ts +45 -0
- package/dist-sdk/src/engine/tf/labels.js +71 -0
- package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
- package/dist-sdk/src/entities/access-policy/build.js +7 -0
- package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
- package/dist-sdk/src/entities/access-policy/filter.js +83 -0
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +48 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +189 -0
- package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
- package/dist-sdk/src/entities/access-policy/module.js +17 -0
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +36 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +149 -0
- package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
- package/dist-sdk/src/entities/access-policy/types.js +10 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +38 -3
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +199 -32
- package/dist-sdk/src/entities/agent/from-tf.d.ts +18 -3
- package/dist-sdk/src/entities/agent/from-tf.js +135 -15
- package/dist-sdk/src/entities/agent/index.d.ts +1 -1
- package/dist-sdk/src/entities/agent/module.js +8 -2
- package/dist-sdk/src/entities/agent/to-tf.js +62 -10
- package/dist-sdk/src/entities/agent/tools.d.ts +88 -9
- package/dist-sdk/src/entities/agent/tools.js +46 -7
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +51 -4
- package/dist-sdk/src/entities/agent-tool/from-tf.js +131 -35
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +4 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +103 -17
- package/dist-sdk/src/entities/agent-tool/types.d.ts +5 -4
- package/dist-sdk/src/entities/agent-tool/types.js +38 -6
- package/dist-sdk/src/entities/app/build.d.ts +63 -13
- package/dist-sdk/src/entities/app/build.js +48 -1
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +3 -0
- package/dist-sdk/src/entities/app/from-tf.d.ts +1 -1
- package/dist-sdk/src/entities/app/from-tf.js +32 -15
- package/dist-sdk/src/entities/app/index.d.ts +4 -1
- package/dist-sdk/src/entities/app/index.js +2 -1
- package/dist-sdk/src/entities/app/module.js +9 -2
- package/dist-sdk/src/entities/app/to-tf.d.ts +5 -0
- package/dist-sdk/src/entities/app/to-tf.js +33 -4
- package/dist-sdk/src/entities/automation/build.d.ts +57 -13
- package/dist-sdk/src/entities/automation/build.js +48 -36
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +25 -8
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +16 -1
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +179 -43
- package/dist-sdk/src/entities/automation/filter.d.ts +15 -3
- package/dist-sdk/src/entities/automation/filter.js +12 -2
- package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -27
- package/dist-sdk/src/entities/automation/from-tf.js +1229 -223
- package/dist-sdk/src/entities/automation/index.d.ts +4 -0
- package/dist-sdk/src/entities/automation/index.js +4 -0
- package/dist-sdk/src/entities/automation/module.js +29 -32
- package/dist-sdk/src/entities/automation/operators.d.ts +29 -2
- package/dist-sdk/src/entities/automation/operators.js +27 -1
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +10 -21
- package/dist-sdk/src/entities/automation/script-code.js +272 -5
- package/dist-sdk/src/entities/automation/tasks.d.ts +125 -19
- package/dist-sdk/src/entities/automation/tasks.js +83 -15
- package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -29
- package/dist-sdk/src/entities/automation/to-tf.js +1134 -231
- package/dist-sdk/src/entities/automation/triggers.d.ts +9 -1
- package/dist-sdk/src/entities/automation/types.d.ts +29 -4
- package/dist-sdk/src/entities/automation/types.js +76 -46
- package/dist-sdk/src/entities/element/build.d.ts +23 -10
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/from-tf.d.ts +1 -1
- package/dist-sdk/src/entities/element/from-tf.js +18 -3
- package/dist-sdk/src/entities/element/index.d.ts +4 -1
- package/dist-sdk/src/entities/element/index.js +2 -1
- package/dist-sdk/src/entities/element/module.js +3 -1
- package/dist-sdk/src/entities/element/to-tf.js +21 -3
- package/dist-sdk/src/entities/field/build.d.ts +56 -13
- package/dist-sdk/src/entities/field/build.js +10 -0
- package/dist-sdk/src/entities/field/calc/runtime.js +4 -0
- package/dist-sdk/src/entities/field/from-tf.d.ts +5 -3
- package/dist-sdk/src/entities/field/from-tf.js +118 -7
- package/dist-sdk/src/entities/field/module.js +3 -2
- package/dist-sdk/src/entities/field/to-tf.d.ts +27 -9
- package/dist-sdk/src/entities/field/to-tf.js +62 -17
- package/dist-sdk/src/entities/field/types.d.ts +26 -0
- package/dist-sdk/src/entities/field/types.js +34 -12
- package/dist-sdk/src/entities/file-reader/build.d.ts +108 -50
- package/dist-sdk/src/entities/file-reader/build.js +23 -23
- package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
- package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
- package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
- package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
- package/dist-sdk/src/entities/file-reader/index.d.ts +8 -3
- package/dist-sdk/src/entities/file-reader/index.js +7 -2
- package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
- package/dist-sdk/src/entities/file-reader/module.js +115 -0
- package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
- package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
- package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
- package/dist-sdk/src/entities/file-reader/types.js +30 -0
- package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
- package/dist-sdk/src/entities/org/ai-provider.js +46 -0
- package/dist-sdk/src/entities/org/connector.d.ts +8 -1
- package/dist-sdk/src/entities/org/connector.js +12 -14
- package/dist-sdk/src/entities/org/group.js +10 -1
- package/dist-sdk/src/entities/org/index.d.ts +1 -0
- package/dist-sdk/src/entities/org/index.js +1 -0
- package/dist-sdk/src/entities/org/user.js +10 -1
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +44 -9
- package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
- package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
- package/dist-sdk/src/entities/shared/tool-field-ref.js +31 -0
- package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -1
- package/dist-sdk/src/entities/shared/types/field-types.js +9 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +19 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +36 -8
- package/dist-sdk/src/entities/skill/from-tf.js +4 -3
- package/dist-sdk/src/entities/skill/index.d.ts +1 -1
- package/dist-sdk/src/entities/skill/module.js +6 -1
- package/dist-sdk/src/entities/skill/to-tf.js +3 -2
- package/dist-sdk/src/entities/skill/tools.d.ts +25 -3
- package/dist-sdk/src/entities/skill/tools.js +17 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +15 -2
- package/dist-sdk/src/entities/skill-tool/from-tf.js +32 -11
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.js +32 -9
- package/dist-sdk/src/entities/view/from-tf.d.ts +6 -2
- package/dist-sdk/src/entities/view/from-tf.js +11 -9
- package/dist-sdk/src/entities/view/to-tf.d.ts +9 -7
- package/dist-sdk/src/entities/view/to-tf.js +33 -18
- package/dist-sdk/src/entities/view/types.d.ts +1 -1
- package/dist-sdk/src/entities/view/types.js +1 -1
- package/dist-sdk/src/graph/deferred-catalog-render.d.ts +0 -5
- package/dist-sdk/src/graph/deferred-catalog-render.js +1 -20
- package/dist-sdk/src/graph/index.d.ts +8 -0
- package/dist-sdk/src/graph/index.js +13 -9
- package/dist-sdk/src/graph/modules.js +6 -1
- package/dist-sdk/src/graph/types.d.ts +77 -3
- package/package.json +42 -14
- package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +0 -76
- package/dist-sdk/src/entities/automation/value-ref-tf.js +0 -190
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access-policy authoring options — the `accessPolicies: [...]` array shared
|
|
3
|
+
* by `defineApp`/`defineElement` (`entities/app/build.ts` /
|
|
4
|
+
* `entities/element/build.ts`). Kept here, not duplicated per parent, since
|
|
5
|
+
* both parents accept the identical shape.
|
|
6
|
+
*/
|
|
7
|
+
import type { GroupRef } from "../../catalog/index.js";
|
|
8
|
+
import type { AccessPolicyPrincipalRef } from "./from-tf.js";
|
|
9
|
+
import type { AccessPolicyFilter } from "./filter.js";
|
|
10
|
+
/**
|
|
11
|
+
* A principal (user/group) reference: a raw platform id — EDK has no
|
|
12
|
+
* `org.users` catalog bag to reference a user by handle (see
|
|
13
|
+
* `entities/org/user.ts`) — or, for groups only, a real `org.groups.<key>`
|
|
14
|
+
* catalog token. `AccessPolicyPrincipalRef` is the pulled-source echo (see
|
|
15
|
+
* that type's own doc comment) — round-tripped, not meant to be hand-authored.
|
|
16
|
+
*/
|
|
17
|
+
export type AccessPolicyUserRef = string | AccessPolicyPrincipalRef;
|
|
18
|
+
export type AccessPolicyGroupRef = string | GroupRef | AccessPolicyPrincipalRef;
|
|
19
|
+
export interface AccessPolicyOptions {
|
|
20
|
+
/** Row-level-security predicate. Omit for the platform default (matches every record). */
|
|
21
|
+
readonly filter?: AccessPolicyFilter;
|
|
22
|
+
readonly userIds?: readonly AccessPolicyUserRef[];
|
|
23
|
+
readonly groupIds?: readonly AccessPolicyGroupRef[];
|
|
24
|
+
/** Always raw platform ids — ei's exporter carries no `elementum_service_account` resource to reference yet. */
|
|
25
|
+
readonly serviceAccountIds?: readonly string[];
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access-policy authoring options — the `accessPolicies: [...]` array shared
|
|
3
|
+
* by `defineApp`/`defineElement` (`entities/app/build.ts` /
|
|
4
|
+
* `entities/element/build.ts`). Kept here, not duplicated per parent, since
|
|
5
|
+
* both parents accept the identical shape.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access-policy filter helpers — build the platform's wire `Filter` shape.
|
|
3
|
+
*
|
|
4
|
+
* Unlike automation's filter DSL (`entities/automation/filter.ts`), an access
|
|
5
|
+
* policy's filter has no trigger/task context to reference — it is always a
|
|
6
|
+
* plain row-level-security predicate over the OWNING app/element's own
|
|
7
|
+
* fields (confirmed by the frozen provider schema: `elementum_access_policy`
|
|
8
|
+
* carries `object_id` + `filter` + principal lists, nothing else). So the
|
|
9
|
+
* left-hand side of every operator is always a `FieldRef` catalog token —
|
|
10
|
+
* there is no `Ref`/`leftValue` row-less mode to support, and no user-directory
|
|
11
|
+
* field scope either (that's a distinct concept used elsewhere, e.g. approval
|
|
12
|
+
* chains — access policies filter the aspect's own records, never a fixed
|
|
13
|
+
* user-directory attribute).
|
|
14
|
+
*
|
|
15
|
+
* Operator/value-type coverage matches what `entities/automation/from-tf.ts`'s
|
|
16
|
+
* `decodeFilter` can round-trip (true/false/and/or/is_null/in/between/eq/gt/
|
|
17
|
+
* gte/lt/lte/like; text/number/boolean/null/current_user/field values) — this
|
|
18
|
+
* repo has no wider working filter-grammar implementation to match.
|
|
19
|
+
*/
|
|
20
|
+
import type { FieldRef } from "../../catalog/index.js";
|
|
21
|
+
import type { LikeMode } from "../shared/filters/index.js";
|
|
22
|
+
/** A wire filter (embeds `FieldRef` tokens at `field` positions). */
|
|
23
|
+
export type AccessPolicyFilter = Record<string, unknown>;
|
|
24
|
+
type Primitive = string | number | boolean | null;
|
|
25
|
+
/**
|
|
26
|
+
* Marker produced by {@link currentUser} — compares against the acting
|
|
27
|
+
* user's id/email/domain rather than a literal value.
|
|
28
|
+
*/
|
|
29
|
+
export interface CurrentUserFilterValue {
|
|
30
|
+
readonly __kind: "currentUser";
|
|
31
|
+
readonly currentUserType: "id" | "email" | "domain";
|
|
32
|
+
}
|
|
33
|
+
export type AccessPolicyFilterValue = Primitive | FieldRef | CurrentUserFilterValue;
|
|
34
|
+
/** Compare against the current (acting) user — id by default. */
|
|
35
|
+
export declare function currentUser(type?: "id" | "email" | "domain"): CurrentUserFilterValue;
|
|
36
|
+
/** Match every record (the minimal valid filter — the default when a policy has none configured). */
|
|
37
|
+
export declare function whereTrue(): AccessPolicyFilter;
|
|
38
|
+
/** Match no record. */
|
|
39
|
+
export declare function whereFalse(): AccessPolicyFilter;
|
|
40
|
+
export declare function eq(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
|
|
41
|
+
export declare function neq(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
|
|
42
|
+
export declare function gt(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
|
|
43
|
+
export declare function gte(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
|
|
44
|
+
export declare function lt(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
|
|
45
|
+
export declare function lte(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
|
|
46
|
+
export declare function like(field: FieldRef, v: string, options?: {
|
|
47
|
+
readonly not?: boolean;
|
|
48
|
+
readonly caseInsensitive?: boolean;
|
|
49
|
+
readonly mode?: LikeMode;
|
|
50
|
+
}): AccessPolicyFilter;
|
|
51
|
+
export declare function isNull(field: FieldRef, options?: {
|
|
52
|
+
readonly not?: boolean;
|
|
53
|
+
}): AccessPolicyFilter;
|
|
54
|
+
export declare function isNotNull(field: FieldRef): AccessPolicyFilter;
|
|
55
|
+
export declare function isIn(field: FieldRef, values: readonly AccessPolicyFilterValue[]): AccessPolicyFilter;
|
|
56
|
+
export declare function between(field: FieldRef, low: AccessPolicyFilterValue, high: AccessPolicyFilterValue, options?: {
|
|
57
|
+
readonly not?: boolean;
|
|
58
|
+
}): AccessPolicyFilter;
|
|
59
|
+
export declare function and(...children: AccessPolicyFilter[]): AccessPolicyFilter;
|
|
60
|
+
export declare function or(...children: AccessPolicyFilter[]): AccessPolicyFilter;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** Compare against the current (acting) user — id by default. */
|
|
2
|
+
export function currentUser(type = "id") {
|
|
3
|
+
return { __kind: "currentUser", currentUserType: type };
|
|
4
|
+
}
|
|
5
|
+
function isCurrentUserValue(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && value.__kind === "currentUser";
|
|
7
|
+
}
|
|
8
|
+
function isFieldValue(value) {
|
|
9
|
+
return typeof value === "object" && value !== null && value.__kind === "field";
|
|
10
|
+
}
|
|
11
|
+
/** Map a filter value to the platform's `Value` wire shape. */
|
|
12
|
+
function value(v) {
|
|
13
|
+
if (isCurrentUserValue(v))
|
|
14
|
+
return { type: "CURRENT_USER", currentUserType: v.currentUserType };
|
|
15
|
+
if (isFieldValue(v))
|
|
16
|
+
return { type: "FIELD", value: v };
|
|
17
|
+
if (v === null)
|
|
18
|
+
return { type: "NULL" };
|
|
19
|
+
if (typeof v === "number")
|
|
20
|
+
return { type: "NUMBER", value: v };
|
|
21
|
+
if (typeof v === "boolean")
|
|
22
|
+
return { type: "BOOLEAN", value: v };
|
|
23
|
+
return { type: "TEXT", value: v };
|
|
24
|
+
}
|
|
25
|
+
/** Match every record (the minimal valid filter — the default when a policy has none configured). */
|
|
26
|
+
export function whereTrue() {
|
|
27
|
+
return { type: "TRUE" };
|
|
28
|
+
}
|
|
29
|
+
/** Match no record. */
|
|
30
|
+
export function whereFalse() {
|
|
31
|
+
return { type: "FALSE" };
|
|
32
|
+
}
|
|
33
|
+
export function eq(field, v) {
|
|
34
|
+
return { type: "EQUALS", field, value: value(v) };
|
|
35
|
+
}
|
|
36
|
+
export function neq(field, v) {
|
|
37
|
+
return { type: "EQUALS", field, value: value(v), not: true };
|
|
38
|
+
}
|
|
39
|
+
export function gt(field, v) {
|
|
40
|
+
return { type: "GREATER_THAN", field, value: value(v) };
|
|
41
|
+
}
|
|
42
|
+
export function gte(field, v) {
|
|
43
|
+
return { type: "GREATER_THAN_EQUALS", field, value: value(v) };
|
|
44
|
+
}
|
|
45
|
+
export function lt(field, v) {
|
|
46
|
+
return { type: "LESS_THAN", field, value: value(v) };
|
|
47
|
+
}
|
|
48
|
+
export function lte(field, v) {
|
|
49
|
+
return { type: "LESS_THAN_EQUALS", field, value: value(v) };
|
|
50
|
+
}
|
|
51
|
+
export function like(field, v, options) {
|
|
52
|
+
return {
|
|
53
|
+
type: "LIKE",
|
|
54
|
+
field,
|
|
55
|
+
value: value(v),
|
|
56
|
+
...(options?.not ? { not: true } : {}),
|
|
57
|
+
...(options?.caseInsensitive !== undefined ? { caseInsensitive: options.caseInsensitive } : {}),
|
|
58
|
+
...(options?.mode ? { mode: options.mode } : {}),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export function isNull(field, options) {
|
|
62
|
+
return { type: "IS_NULL", field, ...(options?.not ? { not: true } : {}) };
|
|
63
|
+
}
|
|
64
|
+
export function isNotNull(field) {
|
|
65
|
+
return isNull(field, { not: true });
|
|
66
|
+
}
|
|
67
|
+
export function isIn(field, values) {
|
|
68
|
+
return { type: "IN", field, values: values.map((v) => value(v)) };
|
|
69
|
+
}
|
|
70
|
+
export function between(field, low, high, options) {
|
|
71
|
+
return {
|
|
72
|
+
type: "BETWEEN",
|
|
73
|
+
field,
|
|
74
|
+
values: [value(low), value(high)],
|
|
75
|
+
...(options?.not ? { not: true } : {}),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export function and(...children) {
|
|
79
|
+
return { type: "AND", children };
|
|
80
|
+
}
|
|
81
|
+
export function or(...children) {
|
|
82
|
+
return { type: "OR", children };
|
|
83
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access-policy extraction (#69): one `elementum_access_policy` block → the
|
|
3
|
+
* normalized shape the app/element printer consumes. The owning app/element's
|
|
4
|
+
* from-tf drives the pass and says who the owner is — this module never
|
|
5
|
+
* names the app/element resource type.
|
|
6
|
+
*
|
|
7
|
+
* `object_id` is always self (ei's exporter never emits a foreign owner —
|
|
8
|
+
* confirmed by `cmd/elementum/export/hcl_access_policy.go`'s `collectOwners`,
|
|
9
|
+
* which only ever sets `object_id` to the SAME app/element/task being
|
|
10
|
+
* exported) — so a block whose `object_id` doesn't match the owner is
|
|
11
|
+
* dropped with a diagnostic rather than silently misattributed.
|
|
12
|
+
*/
|
|
13
|
+
import { type FromTfContext } from "../../engine/pull/context.js";
|
|
14
|
+
import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
|
|
15
|
+
import type { FilterAst } from "../shared/filters/ast.js";
|
|
16
|
+
export interface AccessPolicyOwner {
|
|
17
|
+
readonly type: string;
|
|
18
|
+
readonly label: string;
|
|
19
|
+
/** `appRefName`/`elementRefName` — the owner's EDK refName (catalog root), used to build field refs. */
|
|
20
|
+
readonly ownerRefName: string;
|
|
21
|
+
/** The owner's terraform label (namespace) — used to strip the child-resource label prefix off `*_field` refs. */
|
|
22
|
+
readonly ownerTfLabel: string;
|
|
23
|
+
readonly scope: ChildResourceScope;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A resolved `data.elementum_user`/`data.elementum_group` reference, decoded
|
|
27
|
+
* from a pulled stream — reproduced byte-for-byte by `to-tf.ts`'s
|
|
28
|
+
* `rawLookup`, never re-derived. Also a valid `AccessPolicyUserRef`/
|
|
29
|
+
* `AccessPolicyGroupRef` (see `build.ts`), so the printer can round-trip it
|
|
30
|
+
* straight into `userIds`/`groupIds` without a separate print-time shape.
|
|
31
|
+
*/
|
|
32
|
+
export interface AccessPolicyPrincipalRef {
|
|
33
|
+
readonly __kind: "orgPrincipalRef";
|
|
34
|
+
readonly dataType: "elementum_user" | "elementum_group";
|
|
35
|
+
/** The data block's own label, captured verbatim — reproduced byte-for-byte, never re-derived. */
|
|
36
|
+
readonly label: string;
|
|
37
|
+
/** The data block's lookup-attr value ("email" for a user, "name" for a group). */
|
|
38
|
+
readonly value: string;
|
|
39
|
+
}
|
|
40
|
+
export interface NormalizedAccessPolicy {
|
|
41
|
+
readonly filter: FilterAst;
|
|
42
|
+
readonly userIds?: readonly (string | AccessPolicyPrincipalRef)[];
|
|
43
|
+
readonly groupIds?: readonly (string | AccessPolicyPrincipalRef)[];
|
|
44
|
+
/** Always raw platform ids — ei's exporter carries no `elementum_service_account` resource to reference yet. */
|
|
45
|
+
readonly serviceAccountIds?: readonly string[];
|
|
46
|
+
}
|
|
47
|
+
/** One `elementum_access_policy` block → its normalized shape, or undefined when it belongs to a different owner. */
|
|
48
|
+
export declare function accessPolicyFromTf(block: TfBlock, owner: AccessPolicyOwner, ctx: FromTfContext): NormalizedAccessPolicy | undefined;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access-policy extraction (#69): one `elementum_access_policy` block → the
|
|
3
|
+
* normalized shape the app/element printer consumes. The owning app/element's
|
|
4
|
+
* from-tf drives the pass and says who the owner is — this module never
|
|
5
|
+
* names the app/element resource type.
|
|
6
|
+
*
|
|
7
|
+
* `object_id` is always self (ei's exporter never emits a foreign owner —
|
|
8
|
+
* confirmed by `cmd/elementum/export/hcl_access_policy.go`'s `collectOwners`,
|
|
9
|
+
* which only ever sets `object_id` to the SAME app/element/task being
|
|
10
|
+
* exported) — so a block whose `object_id` doesn't match the owner is
|
|
11
|
+
* dropped with a diagnostic rather than silently misattributed.
|
|
12
|
+
*/
|
|
13
|
+
import { EntityTfError } from "../../engine/entity.js";
|
|
14
|
+
import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
|
|
15
|
+
import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
16
|
+
import { KNOWN_ACCESS_POLICY_ATTRS } from "./types.js";
|
|
17
|
+
function isObject(value) {
|
|
18
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function fieldRef(value, owner, where) {
|
|
21
|
+
if (isTfExpr(value) && value.$expr === "resource-attr" && value.type.endsWith("_field") && value.path[0] === "id") {
|
|
22
|
+
return { kind: "field", appHandle: owner.ownerRefName, fieldKey: scopedLabelToBagKey(owner.ownerTfLabel, value.label, owner.scope) };
|
|
23
|
+
}
|
|
24
|
+
// A system field (status/title/id/stage/…) has no own resource block — ei
|
|
25
|
+
// addresses its id via a `<ownerTfLabel>_<field>_field_id` local instead
|
|
26
|
+
// (same shape automation's decodeValue resolves for trigger/task field
|
|
27
|
+
// refs). Extremely common on real access-policy filters (row-level
|
|
28
|
+
// security keyed off Status is the whole point of the feature).
|
|
29
|
+
if (isTfExpr(value) && value.$expr === "local") {
|
|
30
|
+
const prefix = `${owner.ownerTfLabel}_`;
|
|
31
|
+
if (value.name.startsWith(prefix) && value.name.endsWith("_field_id")) {
|
|
32
|
+
return { kind: "field", appHandle: owner.ownerRefName, fieldKey: tfLabelToTsLabel(value.name.slice(prefix.length, -9)) };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === "string")
|
|
36
|
+
return { kind: "unresolved", uuid: value, hint: "field" };
|
|
37
|
+
throw new EntityTfError(`${where}: field reference cannot be reconstructed`);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A picklist-typed literal filter value ("Open") emits as a
|
|
41
|
+
* `local.<...>_options_by_label[label]` lookup on build, not a plain
|
|
42
|
+
* `{type:"text", value}` object (see `to-tf.ts`'s `picklistLiteralToTf`) —
|
|
43
|
+
* collapse it back to its readable label, mirroring automation's own
|
|
44
|
+
* `picklistOptionLabel`.
|
|
45
|
+
*/
|
|
46
|
+
function picklistOptionLabel(value) {
|
|
47
|
+
if (value === undefined || !isTfExpr(value) || value.$expr !== "local" || value.path.length !== 1)
|
|
48
|
+
return undefined;
|
|
49
|
+
const segment = value.path[0];
|
|
50
|
+
const isOptionsLookup = value.name.endsWith("_options_by_label") || value.name.endsWith("_option_ids_by_label");
|
|
51
|
+
return isOptionsLookup && typeof segment === "object" && segment !== null && "index" in segment && typeof segment.index === "string"
|
|
52
|
+
? segment.index
|
|
53
|
+
: undefined;
|
|
54
|
+
}
|
|
55
|
+
function filterValue(value, owner, where) {
|
|
56
|
+
const optionLabel = picklistOptionLabel(value);
|
|
57
|
+
if (optionLabel !== undefined)
|
|
58
|
+
return { kind: "text", value: optionLabel };
|
|
59
|
+
if (!isObject(value) || isTfExpr(value))
|
|
60
|
+
throw new EntityTfError(`${where}: filter value has an unrecognized shape`);
|
|
61
|
+
const type = typeof value.type === "string" ? value.type.toLowerCase() : undefined;
|
|
62
|
+
if (type === undefined)
|
|
63
|
+
throw new EntityTfError(`${where}: filter value has no type`);
|
|
64
|
+
if (type === "null")
|
|
65
|
+
return { kind: "null" };
|
|
66
|
+
if (type === "current_user") {
|
|
67
|
+
const raw = typeof value.current_user_type === "string" ? value.current_user_type.toLowerCase() : "id";
|
|
68
|
+
const currentUserType = raw === "email" || raw === "domain" ? raw : "id";
|
|
69
|
+
return { kind: "currentUser", currentUserType };
|
|
70
|
+
}
|
|
71
|
+
if (["text", "number", "boolean", "uuid", "date", "datetime"].includes(type)) {
|
|
72
|
+
return { kind: type, value: value.value };
|
|
73
|
+
}
|
|
74
|
+
if (type === "field")
|
|
75
|
+
return { kind: "reference", ref: fieldRef(value.value, owner, where) };
|
|
76
|
+
throw new EntityTfError(`${where}: unsupported filter value type "${type}"`);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Decode one `filter` attribute. Coverage matches automation's own
|
|
80
|
+
* `decodeFilter` (`entities/automation/from-tf.ts`) — the only proven,
|
|
81
|
+
* working filter-grammar round-trip in this codebase — minus the
|
|
82
|
+
* trigger/task `left_value.value_reference` branch, which cannot occur here
|
|
83
|
+
* (access policies have no trigger/task context to reference; the left side
|
|
84
|
+
* is always a `field_id`).
|
|
85
|
+
*/
|
|
86
|
+
function decodeFilter(value, owner, where) {
|
|
87
|
+
if (!isObject(value) || isTfExpr(value) || typeof value.type !== "string")
|
|
88
|
+
throw new EntityTfError(`${where}: invalid filter object`);
|
|
89
|
+
const type = value.type.toLowerCase();
|
|
90
|
+
if (type === "true" || type === "false")
|
|
91
|
+
return { kind: type };
|
|
92
|
+
if (type === "and" || type === "or") {
|
|
93
|
+
if (!Array.isArray(value.children))
|
|
94
|
+
throw new EntityTfError(`${where}: ${type} filter has no children`);
|
|
95
|
+
return { kind: type, children: value.children.map((child) => decodeFilter(child, owner, where)) };
|
|
96
|
+
}
|
|
97
|
+
if (value.field_id === undefined)
|
|
98
|
+
throw new EntityTfError(`${where}: ${type} filter has no field_id`);
|
|
99
|
+
const left = fieldRef(value.field_id, owner, where);
|
|
100
|
+
const not = value.not === true ? { not: true } : {};
|
|
101
|
+
if (type === "is_null")
|
|
102
|
+
return { kind: "isNull", left, ...not };
|
|
103
|
+
if (type === "in") {
|
|
104
|
+
if (!Array.isArray(value.values))
|
|
105
|
+
throw new EntityTfError(`${where}: in filter has no values`);
|
|
106
|
+
return { kind: "in", left, values: value.values.map((item) => filterValue(item, owner, where)), ...not };
|
|
107
|
+
}
|
|
108
|
+
if (type === "between") {
|
|
109
|
+
if (!Array.isArray(value.values) || value.values.length !== 2)
|
|
110
|
+
throw new EntityTfError(`${where}: between filter requires two values`);
|
|
111
|
+
return { kind: "between", left, values: [filterValue(value.values[0], owner, where), filterValue(value.values[1], owner, where)], ...not };
|
|
112
|
+
}
|
|
113
|
+
const kindByType = {
|
|
114
|
+
equals: "eq", greater_than: "gt", greater_than_equals: "gte", less_than: "lt", less_than_equals: "lte", like: "like",
|
|
115
|
+
};
|
|
116
|
+
const kind = kindByType[type];
|
|
117
|
+
if (kind === undefined || value.value === undefined)
|
|
118
|
+
throw new EntityTfError(`${where}: unsupported filter type "${type}"`);
|
|
119
|
+
const right = filterValue(value.value, owner, where);
|
|
120
|
+
return kind === "like"
|
|
121
|
+
? { kind, left, right, ...not, ...(typeof value.case_insensitive === "boolean" ? { caseInsensitive: value.case_insensitive } : {}), ...(typeof value.mode === "string" ? { mode: value.mode.toLowerCase() } : {}) }
|
|
122
|
+
: { kind, left, right, ...not };
|
|
123
|
+
}
|
|
124
|
+
/** Decode one `user_ids`/`group_ids` list item: a `data.elementum_user|group` lookup, or a raw platform id fallback. undefined = dropped, with a diagnostic already pushed. */
|
|
125
|
+
function principalListItem(item, dataType, where, ctx) {
|
|
126
|
+
const label = dataRefLabel(item, dataType);
|
|
127
|
+
if (label !== undefined) {
|
|
128
|
+
const value = ctx.dataName(dataType, label);
|
|
129
|
+
if (value !== undefined)
|
|
130
|
+
return { __kind: "orgPrincipalRef", dataType, label, value };
|
|
131
|
+
ctx.diagnostics.push(`${where}: references data.${dataType}.${label}, but the stream has no matching data block; dropped`);
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
if (typeof item === "string")
|
|
135
|
+
return item;
|
|
136
|
+
ctx.diagnostics.push(`${where}: list item has an unrecognized shape; dropped`);
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
function principalList(value, dataType, where, ctx) {
|
|
140
|
+
if (value === undefined)
|
|
141
|
+
return undefined;
|
|
142
|
+
if (!Array.isArray(value)) {
|
|
143
|
+
ctx.diagnostics.push(`${where}: is not a list; dropped`);
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const items = [];
|
|
147
|
+
for (const item of value) {
|
|
148
|
+
const decoded = principalListItem(item, dataType, where, ctx);
|
|
149
|
+
if (decoded !== undefined)
|
|
150
|
+
items.push(decoded);
|
|
151
|
+
}
|
|
152
|
+
return items.length > 0 ? items : undefined;
|
|
153
|
+
}
|
|
154
|
+
/** One `elementum_access_policy` block → its normalized shape, or undefined when it belongs to a different owner. */
|
|
155
|
+
export function accessPolicyFromTf(block, owner, ctx) {
|
|
156
|
+
const label = block.label;
|
|
157
|
+
if (label === undefined || label === "")
|
|
158
|
+
throw new EntityTfError("elementum_access_policy block is missing its label");
|
|
159
|
+
const where = `access policy (${block.type}.${label})`;
|
|
160
|
+
const attrs = block.attrs;
|
|
161
|
+
for (const key of Object.keys(attrs)) {
|
|
162
|
+
if (!KNOWN_ACCESS_POLICY_ATTRS.has(key)) {
|
|
163
|
+
ctx.diagnostics.push(`${where}: unhandled attribute "${key}" — the export dialect grew; extend accessPolicyFromTf deliberately`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (resourceRefLabel(attrs["object_id"], owner.type) !== owner.label) {
|
|
167
|
+
ctx.diagnostics.push(`${where}: object_id does not reference ${owner.type}.${owner.label}; skipped`);
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
const filter = attrs["filter"] !== undefined ? decodeFilter(attrs["filter"], owner, where) : { kind: "true" };
|
|
171
|
+
const userIds = principalList(attrs["user_ids"], "elementum_user", `${where}: user_ids`, ctx);
|
|
172
|
+
const groupIds = principalList(attrs["group_ids"], "elementum_group", `${where}: group_ids`, ctx);
|
|
173
|
+
let serviceAccountIds;
|
|
174
|
+
const saAttr = attrs["service_account_ids"];
|
|
175
|
+
if (Array.isArray(saAttr)) {
|
|
176
|
+
serviceAccountIds = saAttr.filter((id) => typeof id === "string");
|
|
177
|
+
if (serviceAccountIds.length === 0)
|
|
178
|
+
serviceAccountIds = undefined;
|
|
179
|
+
}
|
|
180
|
+
else if (saAttr !== undefined) {
|
|
181
|
+
ctx.diagnostics.push(`${where}: service_account_ids is not a list; dropped`);
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
filter,
|
|
185
|
+
...(userIds !== undefined && { userIds }),
|
|
186
|
+
...(groupIds !== undefined && { groupIds }),
|
|
187
|
+
...(serviceAccountIds !== undefined && { serviceAccountIds }),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The access-policy entity's registry entry (see src/graph/). */
|
|
2
|
+
import { NO_CATALOG, NO_DATA, NO_LIFECYCLE, } from "../../graph/types.js";
|
|
3
|
+
import { ACCESS_POLICY_RESOURCE_TYPE } from "./types.js";
|
|
4
|
+
export const accessPolicyModule = {
|
|
5
|
+
kind: "access-policy",
|
|
6
|
+
stream: { role: "streamMember" },
|
|
7
|
+
authoring: { unit: "inline", bag: "accessPolicies" },
|
|
8
|
+
parents: [
|
|
9
|
+
{ parent: "app", child: "access-policy" },
|
|
10
|
+
{ parent: "element", child: "access-policy" },
|
|
11
|
+
],
|
|
12
|
+
resource: { shape: "single", resourceType: ACCESS_POLICY_RESOURCE_TYPE, adoptable: true },
|
|
13
|
+
data: NO_DATA,
|
|
14
|
+
lifecycle: NO_LIFECYCLE,
|
|
15
|
+
canvas: { participates: true, label: "Access Policies", glyph: "🔒", component: "generic" },
|
|
16
|
+
catalog: NO_CATALOG,
|
|
17
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access-policy emission (#69): one authored `accessPolicies[]` entry → one
|
|
3
|
+
* `elementum_access_policy` resource block, in ei's dialect. The owning
|
|
4
|
+
* app/element's to-tf drives the pass and supplies the `object_id`
|
|
5
|
+
* back-reference — this module never names the owner's resource type.
|
|
6
|
+
*
|
|
7
|
+
* Label: `<ownerLabel>_access_policy` for the first entry, `..._access_policy_N`
|
|
8
|
+
* (0-indexed, matching ei's own numbering) for later ones — access policies
|
|
9
|
+
* have no display name on the platform, so identity is purely positional,
|
|
10
|
+
* same discipline as `cmd/elementum/export/imports.go`'s own
|
|
11
|
+
* `AppChildResourceName(app, "access_policy"/"access_policy_N")` scheme.
|
|
12
|
+
*/
|
|
13
|
+
import type { OrgRefLookup } from "../../engine/build/context.js";
|
|
14
|
+
import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
|
|
15
|
+
export interface AccessPolicyToTfContext {
|
|
16
|
+
readonly ownerTfLabel: string;
|
|
17
|
+
readonly scope: ChildResourceScope;
|
|
18
|
+
/** The owner's id reference, e.g. `elementum_app.<ns>.id` — computed by the owner's to-tf. */
|
|
19
|
+
readonly objectId: TfValue;
|
|
20
|
+
readonly orgRefs: OrgRefLookup;
|
|
21
|
+
readonly diagnostics: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface AccessPolicyToTfResult {
|
|
24
|
+
readonly block: TfBlock;
|
|
25
|
+
readonly address: string;
|
|
26
|
+
}
|
|
27
|
+
/** Authored filter shape — a plain wire-like object produced by `filter.ts`'s helpers (never hand-built by callers). */
|
|
28
|
+
export type AccessPolicyFilterInput = Record<string, unknown>;
|
|
29
|
+
export interface AccessPolicyEntryWire {
|
|
30
|
+
readonly filter?: AccessPolicyFilterInput;
|
|
31
|
+
readonly userIds?: readonly unknown[];
|
|
32
|
+
readonly groupIds?: readonly unknown[];
|
|
33
|
+
readonly serviceAccountIds?: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
/** One authored access-policy entry → its resource block, positioned by `index` (0-based) for label numbering. */
|
|
36
|
+
export declare function accessPolicyToTf(entry: AccessPolicyEntryWire, index: number, ctx: AccessPolicyToTfContext): AccessPolicyToTfResult;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access-policy emission (#69): one authored `accessPolicies[]` entry → one
|
|
3
|
+
* `elementum_access_policy` resource block, in ei's dialect. The owning
|
|
4
|
+
* app/element's to-tf drives the pass and supplies the `object_id`
|
|
5
|
+
* back-reference — this module never names the owner's resource type.
|
|
6
|
+
*
|
|
7
|
+
* Label: `<ownerLabel>_access_policy` for the first entry, `..._access_policy_N`
|
|
8
|
+
* (0-indexed, matching ei's own numbering) for later ones — access policies
|
|
9
|
+
* have no display name on the platform, so identity is purely positional,
|
|
10
|
+
* same discipline as `cmd/elementum/export/imports.go`'s own
|
|
11
|
+
* `AppChildResourceName(app, "access_policy"/"access_policy_N")` scheme.
|
|
12
|
+
*/
|
|
13
|
+
import { EntityTfError } from "../../engine/entity.js";
|
|
14
|
+
import { expr, scopedResourceLabel } from "../../engine/tf/index.js";
|
|
15
|
+
import { fieldRefToTfValue } from "../field/to-tf.js";
|
|
16
|
+
import { ACCESS_POLICY_RESOURCE_TYPE } from "./types.js";
|
|
17
|
+
function isFieldToken(v) {
|
|
18
|
+
return typeof v === "object" && v !== null && v.__kind === "field";
|
|
19
|
+
}
|
|
20
|
+
function fieldValueToTf(token, where, ctx) {
|
|
21
|
+
const refName = token.refName ?? "";
|
|
22
|
+
const value = fieldRefToTfValue(token.fieldType ?? "", refName, ctx.ownerTfLabel, ctx.scope);
|
|
23
|
+
if (value === undefined) {
|
|
24
|
+
throw new EntityTfError(`${where}: field token "${refName}" has no terraform field resource mapping`);
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
/** Resolve a PICKLIST/STATUS-field-typed string against its options-by-label local, if the field carries picklist metadata. */
|
|
29
|
+
function picklistLiteralToTf(literal, field, ctx) {
|
|
30
|
+
if (field?.options === undefined || !field.options.includes(literal))
|
|
31
|
+
return undefined;
|
|
32
|
+
const localName = field.tags?.includes("STATUS")
|
|
33
|
+
? `${ctx.ownerTfLabel}_status_options_by_label`
|
|
34
|
+
: field.tags?.includes("STAGE")
|
|
35
|
+
? `${ctx.ownerTfLabel}_stage_options_by_label`
|
|
36
|
+
: undefined;
|
|
37
|
+
// Non-status/stage picklists: the field's own options-by-label local, keyed
|
|
38
|
+
// by its scoped resource label — same derivation fieldToTf's options pass uses.
|
|
39
|
+
const resolvedLocalName = localName ?? `${scopedResourceLabel(ctx.ownerTfLabel, field?.refName ?? "", ctx.scope)}_options_by_label`;
|
|
40
|
+
return expr.local(resolvedLocalName, [{ index: literal }]);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Encode one `FilterAst` (authored via `entities/access-policy/filter.ts`'s
|
|
44
|
+
* `eq`/`and`/… helpers). Coverage matches automation's own `filterToTf` —
|
|
45
|
+
* the only proven, working filter-grammar round-trip in this codebase —
|
|
46
|
+
* minus the trigger/task `leftValue` branch, which cannot occur here.
|
|
47
|
+
*/
|
|
48
|
+
function filterToTf(f, where, ctx) {
|
|
49
|
+
if (typeof f !== "object" || f === null || typeof f.type !== "string") {
|
|
50
|
+
throw new EntityTfError(`${where}: invalid filter`);
|
|
51
|
+
}
|
|
52
|
+
const raw = f;
|
|
53
|
+
const type = raw.type.toLowerCase();
|
|
54
|
+
const result = { type };
|
|
55
|
+
const field = isFieldToken(raw.field) ? raw.field : undefined;
|
|
56
|
+
if (field !== undefined)
|
|
57
|
+
result.field_id = fieldValueToTf(field, where, ctx);
|
|
58
|
+
if (Array.isArray(raw.children)) {
|
|
59
|
+
result.children = raw.children.map((child) => filterToTf(child, where, ctx));
|
|
60
|
+
}
|
|
61
|
+
if (raw.value !== undefined)
|
|
62
|
+
result.value = literalValueToTf(raw.value, field, where, ctx);
|
|
63
|
+
if (Array.isArray(raw.values)) {
|
|
64
|
+
result.values = raw.values.map((item) => literalValueToTf(item, field, where, ctx));
|
|
65
|
+
}
|
|
66
|
+
if (typeof raw.not === "boolean")
|
|
67
|
+
result.not = raw.not;
|
|
68
|
+
if (typeof raw.caseInsensitive === "boolean")
|
|
69
|
+
result.case_insensitive = raw.caseInsensitive;
|
|
70
|
+
if (typeof raw.mode === "string")
|
|
71
|
+
result.mode = raw.mode;
|
|
72
|
+
if (result.type === "like" && result.mode === undefined)
|
|
73
|
+
result.mode = "legacy";
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
/** The wire `Value` shape (`{type, value?}`) `filter.ts`'s `eq`/`isIn`/etc. embed at `value`/`values[]`. */
|
|
77
|
+
function literalValueToTf(raw, field, where, ctx) {
|
|
78
|
+
if (typeof raw !== "object" || raw === null || typeof raw.type !== "string") {
|
|
79
|
+
throw new EntityTfError(`${where}: invalid filter value`);
|
|
80
|
+
}
|
|
81
|
+
const rec = raw;
|
|
82
|
+
const type = rec.type.toLowerCase();
|
|
83
|
+
if (type === "null")
|
|
84
|
+
return { type: "NULL" };
|
|
85
|
+
if (type === "current_user")
|
|
86
|
+
return { type: "CURRENT_USER", current_user_type: rec.currentUserType };
|
|
87
|
+
if (type === "field")
|
|
88
|
+
return fieldValueToTf(rec.value, where, ctx);
|
|
89
|
+
if (type === "text" && typeof rec.value === "string") {
|
|
90
|
+
const picklist = picklistLiteralToTf(rec.value, field, ctx);
|
|
91
|
+
return picklist ?? { type: "TEXT", value: rec.value };
|
|
92
|
+
}
|
|
93
|
+
return { type: type.toUpperCase(), value: rec.value };
|
|
94
|
+
}
|
|
95
|
+
function isOrgPrincipalRef(v) {
|
|
96
|
+
return typeof v === "object" && v !== null && v.__kind === "orgPrincipalRef";
|
|
97
|
+
}
|
|
98
|
+
function isGroupToken(v) {
|
|
99
|
+
return typeof v === "object" && v !== null && v.__kind === "group";
|
|
100
|
+
}
|
|
101
|
+
function principalListToTf(items, dataType, where, ctx) {
|
|
102
|
+
if (items === undefined || items.length === 0)
|
|
103
|
+
return undefined;
|
|
104
|
+
const values = [];
|
|
105
|
+
for (const item of items) {
|
|
106
|
+
if (isOrgPrincipalRef(item)) {
|
|
107
|
+
ctx.orgRefs.rawLookup(item.dataType, item.label, item.value);
|
|
108
|
+
values.push(expr.dataAttr(item.dataType, item.label, ["id"]));
|
|
109
|
+
}
|
|
110
|
+
else if (dataType === "elementum_group" && isGroupToken(item)) {
|
|
111
|
+
const resolved = ctx.orgRefs.byTsLabel("groups", item.refName ?? "");
|
|
112
|
+
if (resolved === undefined) {
|
|
113
|
+
ctx.diagnostics.push(`${where}: group token "${item.refName}" is not in the org catalog — re-run \`elementum pull org --data-only\``);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
values.push(expr.dataAttr("elementum_group", resolved.tfLabel, ["id"]));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (typeof item === "string") {
|
|
120
|
+
values.push(item);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
ctx.diagnostics.push(`${where}: ${dataType} list item has an unrecognized shape; dropped`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return values.length > 0 ? values : undefined;
|
|
127
|
+
}
|
|
128
|
+
/** One authored access-policy entry → its resource block, positioned by `index` (0-based) for label numbering. */
|
|
129
|
+
export function accessPolicyToTf(entry, index, ctx) {
|
|
130
|
+
const label = scopedResourceLabel(ctx.ownerTfLabel, index === 0 ? "access_policy" : `access_policy_${index}`, ctx.scope);
|
|
131
|
+
const where = `accessPolicies[${index}]`;
|
|
132
|
+
const attrs = {
|
|
133
|
+
object_id: ctx.objectId,
|
|
134
|
+
filter: entry.filter !== undefined ? filterToTf(entry.filter, where, ctx) : { type: "true" },
|
|
135
|
+
};
|
|
136
|
+
const userIds = principalListToTf(entry.userIds, "elementum_user", `${where}.userIds`, ctx);
|
|
137
|
+
if (userIds !== undefined)
|
|
138
|
+
attrs["user_ids"] = userIds;
|
|
139
|
+
const groupIds = principalListToTf(entry.groupIds, "elementum_group", `${where}.groupIds`, ctx);
|
|
140
|
+
if (groupIds !== undefined)
|
|
141
|
+
attrs["group_ids"] = groupIds;
|
|
142
|
+
if (entry.serviceAccountIds !== undefined && entry.serviceAccountIds.length > 0) {
|
|
143
|
+
attrs["service_account_ids"] = [...entry.serviceAccountIds];
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
block: { kind: "resource", type: ACCESS_POLICY_RESOURCE_TYPE, label, attrs },
|
|
147
|
+
address: `${ACCESS_POLICY_RESOURCE_TYPE}.${label}`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The access-policy entity's resource-type constant (see src/graph/). */
|
|
2
|
+
export declare const ACCESS_POLICY_RESOURCE_TYPE: "elementum_access_policy";
|
|
3
|
+
/** Attributes `accessPolicyFromTf` understands — anything else is dialect growth, reported loudly. */
|
|
4
|
+
export declare const KNOWN_ACCESS_POLICY_ATTRS: ReadonlySet<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The access-policy entity's resource-type constant (see src/graph/). */
|
|
2
|
+
export const ACCESS_POLICY_RESOURCE_TYPE = "elementum_access_policy";
|
|
3
|
+
/** Attributes `accessPolicyFromTf` understands — anything else is dialect growth, reported loudly. */
|
|
4
|
+
export const KNOWN_ACCESS_POLICY_ATTRS = new Set([
|
|
5
|
+
"object_id",
|
|
6
|
+
"filter",
|
|
7
|
+
"user_ids",
|
|
8
|
+
"group_ids",
|
|
9
|
+
"service_account_ids",
|
|
10
|
+
]);
|