@cargo-ai/cdk 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/cli/commands/inputTypes.d.ts +8 -0
- package/build/src/cli/commands/inputTypes.d.ts.map +1 -1
- package/build/src/cli/commands/inputTypes.js +40 -7
- package/build/src/cli/commands/types.d.ts.map +1 -1
- package/build/src/cli/commands/types.js +44 -6
- package/build/src/index.d.ts +1 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/resources/model.d.ts +14 -2
- package/build/src/resources/model.d.ts.map +1 -1
- package/build/src/resources/model.js +12 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -15,6 +15,14 @@ export declare function printJsonSchemaInput(schema: unknown): string;
|
|
|
15
15
|
* workflow builder Refs). Used by `cargo-ai cdk types`.
|
|
16
16
|
*/
|
|
17
17
|
export declare function printJsonSchemaType(schema: unknown): string;
|
|
18
|
+
/**
|
|
19
|
+
* Print an integration action's static output JSON Schema as a plain TS type —
|
|
20
|
+
* no `Ref<T> | T` widening and no `EncryptionRef`. Returns `undefined` when
|
|
21
|
+
* the schema is missing or too loose to be useful; the caller falls back to
|
|
22
|
+
* `any`, which stays usable everywhere a nested `Ref<Record<string, unknown>>`
|
|
23
|
+
* would not.
|
|
24
|
+
*/
|
|
25
|
+
export declare function printJsonSchemaOutput(schema: unknown): string | undefined;
|
|
18
26
|
/**
|
|
19
27
|
* Print a tool release's `formFields` as a TS input type. Returns
|
|
20
28
|
* `undefined` when the fields can't be interpreted (caller falls back to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputTypes.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/inputTypes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inputTypes.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/inputTypes.ts"],"names":[],"mappings":"AAqCA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,QAE+D,CAAC;AAEjG;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAM5D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAQ3D;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAQzE;AAmUD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAU5E"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
// TypeScript
|
|
1
|
+
// TypeScript type printers for `cargo-ai workflow sync` codegen.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
3
|
+
// Sources of truth:
|
|
4
4
|
// - Integration actions expose their config as JSON Schema on
|
|
5
|
-
// `connection.integration.list` (`action.config.schema`)
|
|
5
|
+
// `connection.integration.list` (`action.config.schema`), and — for
|
|
6
|
+
// actions with a static output — their output as `action.output.schema`.
|
|
6
7
|
// - Workspace tools expose their input as `formFields` on the tool
|
|
7
8
|
// workflow's deployed release (`orchestration.release.getDeployed`).
|
|
8
9
|
// - Agent nodes accept a single global shape (`{ prompt, output? }`) —
|
|
9
10
|
// the engine validates every agent node against `AiUtils.agentConfig`.
|
|
10
11
|
//
|
|
11
|
-
//
|
|
12
|
-
// `Ref<T> | T` so callers can pass either a builder Ref or a literal.
|
|
13
|
-
//
|
|
14
|
-
//
|
|
12
|
+
// Input printers run in "input mode": each top-level property is widened to
|
|
13
|
+
// `Ref<T> | T` so callers can pass either a builder Ref or a literal. The
|
|
14
|
+
// output printer emits plain types (outputs come back as a `Ref` the caller
|
|
15
|
+
// dot-accesses). Anything unrecognized falls back to `unknown` — codegen must
|
|
16
|
+
// never abort on a schema edge case.
|
|
15
17
|
//
|
|
16
18
|
// Mirrors `packages/workflow-sdk/scripts/lib/jsonSchemaToTs.ts` (which is a
|
|
17
19
|
// build-time-only script the CLI can't import).
|
|
@@ -47,6 +49,22 @@ export function printJsonSchemaType(schema) {
|
|
|
47
49
|
const printed = printSchema(schema, false, true);
|
|
48
50
|
return printed === "unknown" ? "Record<string, unknown>" : printed;
|
|
49
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Print an integration action's static output JSON Schema as a plain TS type —
|
|
54
|
+
* no `Ref<T> | T` widening and no `EncryptionRef`. Returns `undefined` when
|
|
55
|
+
* the schema is missing or too loose to be useful; the caller falls back to
|
|
56
|
+
* `any`, which stays usable everywhere a nested `Ref<Record<string, unknown>>`
|
|
57
|
+
* would not.
|
|
58
|
+
*/
|
|
59
|
+
export function printJsonSchemaOutput(schema) {
|
|
60
|
+
if (schema === null || typeof schema !== "object") {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
const printed = printSchema(schema, false, false);
|
|
64
|
+
return printed === "unknown" || printed === "Record<string, unknown>"
|
|
65
|
+
? undefined
|
|
66
|
+
: printed;
|
|
67
|
+
}
|
|
50
68
|
// The platform's shared `encryption` schema definition: an object with a `type`
|
|
51
69
|
// const/enum of "encryption" plus `isEncrypted` and `value`. In CDK config types
|
|
52
70
|
// these positions become `EncryptionRef` (see printObject).
|
|
@@ -65,6 +83,10 @@ function isEncryptionSchema(schema) {
|
|
|
65
83
|
}
|
|
66
84
|
function printSchema(schema, topLevel, encRef) {
|
|
67
85
|
if (Array.isArray(schema.type)) {
|
|
86
|
+
// zod's `z.any()` lowers to the full list of JSON types; print `unknown`
|
|
87
|
+
// instead of a noisy 7-member union.
|
|
88
|
+
if (isAnyTypeList(schema.type))
|
|
89
|
+
return "unknown";
|
|
68
90
|
return uniqueUnion(schema.type.map((t) => printPrimitive(t, schema, false, encRef)));
|
|
69
91
|
}
|
|
70
92
|
if (schema.enum !== undefined && schema.enum.length > 0) {
|
|
@@ -103,6 +125,17 @@ function printSchema(schema, topLevel, encRef) {
|
|
|
103
125
|
return "unknown";
|
|
104
126
|
return printPrimitive(schema.type, schema, topLevel, encRef);
|
|
105
127
|
}
|
|
128
|
+
const ANY_TYPE_LIST = [
|
|
129
|
+
"string",
|
|
130
|
+
"number",
|
|
131
|
+
"boolean",
|
|
132
|
+
"object",
|
|
133
|
+
"array",
|
|
134
|
+
"null",
|
|
135
|
+
];
|
|
136
|
+
function isAnyTypeList(types) {
|
|
137
|
+
return ANY_TYPE_LIST.every((t) => types.includes(t));
|
|
138
|
+
}
|
|
106
139
|
function printPrimitive(type, schema, topLevel, encRef) {
|
|
107
140
|
switch (type) {
|
|
108
141
|
case "string":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsIzC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,IAAI,CAkE7E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { handleApiCall, info, success } from "../io.js";
|
|
4
|
-
import { printJsonSchemaInput, printJsonSchemaType } from "./inputTypes.js";
|
|
4
|
+
import { printJsonSchemaInput, printJsonSchemaOutput, printJsonSchemaType, } from "./inputTypes.js";
|
|
5
5
|
// Composite natives surfaced via dedicated SDK syntax / scope helpers —
|
|
6
6
|
// excluded so we don't double-register them. Mirrors the codegen exclusion
|
|
7
7
|
// list in `packages/workflow-sdk/scripts/generateNativeIntegration.ts`
|
|
@@ -37,7 +37,7 @@ const BUNDLED_NATIVE = new Set([
|
|
|
37
37
|
export function registerTypesCommand(parent, getApi) {
|
|
38
38
|
parent
|
|
39
39
|
.command("types")
|
|
40
|
-
.description("Generate per-workspace TypeScript types for the Cargo CDK — typed defineConnector/defineModel config + integration actions in workflow bodies")
|
|
40
|
+
.description("Generate per-workspace TypeScript types for the Cargo CDK — typed defineConnector/defineModel config, model columns + integration actions in workflow bodies")
|
|
41
41
|
.option("--dir <path>", "Repo root the generated files are written into (default: cwd)")
|
|
42
42
|
.option("--out <dir>", "Output subdirectory for generated files (default: .cargo-ai)", ".cargo-ai")
|
|
43
43
|
.action(async (opts) => {
|
|
@@ -69,12 +69,13 @@ export function registerTypesCommand(parent, getApi) {
|
|
|
69
69
|
].join("\n"));
|
|
70
70
|
info(``);
|
|
71
71
|
const extractorCount = payload.extractorConfigs.reduce((n, e) => n + e.extractors.length, 0);
|
|
72
|
-
info(`Typed ${String(payload.connectorConfigs.length)} connector config(s), ${String(extractorCount)} extractor config(s), ${String(payload.agentTriggerConfigs.length)} agent trigger config(s), ${String(payload.integrations.length)} integration(s), ${String(payload.native.length)} native action(s).`);
|
|
72
|
+
info(`Typed ${String(payload.connectorConfigs.length)} connector config(s), ${String(extractorCount)} extractor config(s), ${String(payload.agentTriggerConfigs.length)} agent trigger config(s), ${String(payload.modelColumns.length)} model column set(s), ${String(payload.integrations.length)} integration(s), ${String(payload.native.length)} native action(s).`);
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
async function fetchWorkspaceSurface(api) {
|
|
76
76
|
const integrationsResult = await handleApiCall(() => api.connection.integration.list({}));
|
|
77
77
|
const nativeIntegrationResult = await handleApiCall(() => api.connection.nativeIntegration.get());
|
|
78
|
+
const modelsResult = await handleApiCall(() => api.storage.model.all());
|
|
78
79
|
const rawIntegrations = integrationsResult.integrations;
|
|
79
80
|
const integrations = collectIntegrations(rawIntegrations);
|
|
80
81
|
const native = collectNative(nativeIntegrationResult.nativeIntegration.actions);
|
|
@@ -82,6 +83,7 @@ async function fetchWorkspaceSurface(api) {
|
|
|
82
83
|
const extractorConfigs = collectExtractorConfigs(rawIntegrations);
|
|
83
84
|
const extractorSlugs = collectExtractorSlugs(rawIntegrations);
|
|
84
85
|
const agentTriggerConfigs = collectAgentTriggerConfigs(rawIntegrations);
|
|
86
|
+
const modelColumns = collectModelColumns(modelsResult.models);
|
|
85
87
|
return {
|
|
86
88
|
integrations,
|
|
87
89
|
native,
|
|
@@ -89,6 +91,7 @@ async function fetchWorkspaceSurface(api) {
|
|
|
89
91
|
extractorConfigs,
|
|
90
92
|
extractorSlugs,
|
|
91
93
|
agentTriggerConfigs,
|
|
94
|
+
modelColumns,
|
|
92
95
|
};
|
|
93
96
|
}
|
|
94
97
|
// integrationSlug → connector config type. Skips integrations whose schema
|
|
@@ -177,6 +180,30 @@ function collectExtractorSlugs(integrations) {
|
|
|
177
180
|
out.sort((a, b) => a.integrationSlug.localeCompare(b.integrationSlug));
|
|
178
181
|
return out;
|
|
179
182
|
}
|
|
183
|
+
// modelSlug → every column slug it exposes. Additional columns are addressed
|
|
184
|
+
// with their kind as a storage prefix (`computed__score`, `custom__notes`, …) —
|
|
185
|
+
// the same slugs `/storage/columns/list` returns — while original columns stay
|
|
186
|
+
// bare. Models whose columns haven't been inferred yet are skipped; two models
|
|
187
|
+
// sharing a slug (across datasets) merge their column sets so the generated
|
|
188
|
+
// union accepts either.
|
|
189
|
+
function collectModelColumns(models) {
|
|
190
|
+
const bySlug = new Map();
|
|
191
|
+
for (const model of models) {
|
|
192
|
+
const previous = bySlug.get(model.slug);
|
|
193
|
+
bySlug.set(model.slug, [
|
|
194
|
+
...(previous === undefined ? [] : previous),
|
|
195
|
+
...model.columns.map((column) => column.slug),
|
|
196
|
+
...model.additionalColumns.map((column) => `${column.kind}__${column.slug}`),
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
return [...bySlug]
|
|
200
|
+
.filter(([, slugs]) => slugs.length > 0)
|
|
201
|
+
.map(([modelSlug, slugs]) => ({
|
|
202
|
+
modelSlug,
|
|
203
|
+
columns: [...new Set(slugs)].sort((a, b) => a.localeCompare(b)),
|
|
204
|
+
}))
|
|
205
|
+
.sort((a, b) => a.modelSlug.localeCompare(b.modelSlug));
|
|
206
|
+
}
|
|
180
207
|
function collectIntegrations(integrations) {
|
|
181
208
|
const out = [];
|
|
182
209
|
for (const integration of integrations) {
|
|
@@ -186,12 +213,13 @@ function collectIntegrations(integrations) {
|
|
|
186
213
|
continue;
|
|
187
214
|
const actions = actionEntries.map(([slug, raw]) => {
|
|
188
215
|
const meta = raw;
|
|
189
|
-
const { config } = meta;
|
|
216
|
+
const { config, output } = meta;
|
|
190
217
|
return {
|
|
191
218
|
slug,
|
|
192
219
|
name: trimOrUndefined(meta.name),
|
|
193
220
|
description: trimOrUndefined(meta.description),
|
|
194
221
|
inputTypeSrc: printJsonSchemaInput(config !== undefined ? config.schema : undefined),
|
|
222
|
+
outputTypeSrc: printJsonSchemaOutput(output !== undefined ? output.schema : undefined),
|
|
195
223
|
};
|
|
196
224
|
});
|
|
197
225
|
out.push({
|
|
@@ -270,6 +298,14 @@ function renderTypes(payload) {
|
|
|
270
298
|
}
|
|
271
299
|
cdkLines.push(` }`);
|
|
272
300
|
}
|
|
301
|
+
if (payload.modelColumns.length > 0) {
|
|
302
|
+
cdkLines.push(` interface ModelColumns {`);
|
|
303
|
+
for (const m of payload.modelColumns) {
|
|
304
|
+
const union = m.columns.map((c) => JSON.stringify(c)).join(" | ");
|
|
305
|
+
cdkLines.push(` ${jsonKey(m.modelSlug)}: ${union};`);
|
|
306
|
+
}
|
|
307
|
+
cdkLines.push(` }`);
|
|
308
|
+
}
|
|
273
309
|
if (payload.agentTriggerConfigs.length > 0) {
|
|
274
310
|
cdkLines.push(` interface AgentTriggerConfigs {`);
|
|
275
311
|
for (const t of payload.agentTriggerConfigs) {
|
|
@@ -308,10 +344,12 @@ function renderTypes(payload) {
|
|
|
308
344
|
}, " ");
|
|
309
345
|
if (actionDoc !== "")
|
|
310
346
|
wfLines.push(actionDoc.trimEnd());
|
|
311
|
-
//
|
|
347
|
+
// Actions with a static output schema get a real output type; the rest
|
|
348
|
+
// (dynamic or absent outputs) fall back to `any` (not `Record<string,
|
|
312
349
|
// unknown>`, which lowers to an unusable nested `Ref`) — the result is
|
|
313
350
|
// then usable as a string, an object, or in any typed slot.
|
|
314
|
-
|
|
351
|
+
const outputSrc = action.outputTypeSrc !== undefined ? action.outputTypeSrc : "any";
|
|
352
|
+
wfLines.push(` ${jsonKey(action.slug)}: IntegrationAction<${action.inputTypeSrc}, ${outputSrc}>;`);
|
|
315
353
|
}
|
|
316
354
|
wfLines.push(` };`);
|
|
317
355
|
}
|
package/build/src/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type { FolderHandle, FolderKind, FolderSpec, } from "./resources/folder.j
|
|
|
16
16
|
export { defineFolder } from "./resources/folder.js";
|
|
17
17
|
export type { McpServerHandle, McpServerSpec } from "./resources/mcpServer.js";
|
|
18
18
|
export { defineMcpServer } from "./resources/mcpServer.js";
|
|
19
|
-
export type { ExtractorConfigs, ExtractorSlugs, ModelHandle, ModelSpec, UnificationColumnSpec, UnificationParentSpec, UnificationSpec, } from "./resources/model.js";
|
|
19
|
+
export type { ExtractorConfigs, ExtractorSlugs, ModelColumns, ModelHandle, ModelSpec, UnificationColumnSpec, UnificationParentSpec, UnificationSpec, } from "./resources/model.js";
|
|
20
20
|
export { defineModel } from "./resources/model.js";
|
|
21
21
|
export type { PlayHandle, PlaySpec } from "./resources/play.js";
|
|
22
22
|
export { definePlay } from "./resources/play.js";
|
package/build/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAUA,YAAY,EACV,aAAa,EACb,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB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,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAMlE,OAAO,EACL,QAAQ,EACR,cAAc,EACd,uBAAuB,EACvB,OAAO,EACP,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,wBAAwB,CAAC;AAGhC,YAAY,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,KAAK,GACN,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EACP,cAAc,EACd,MAAM,EACN,KAAK,GACN,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,QAAQ,EACR,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,OAAO,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,OAAO,EACP,OAAO,EACP,UAAU,GACX,MAAM,WAAW,CAAC;AAGnB,cAAc,mBAAmB,CAAC"}
|
|
@@ -43,6 +43,15 @@ type ExtractorConfigFor<S extends string, E extends string> = S extends keyof Ex
|
|
|
43
43
|
export interface ExtractorSlugs {
|
|
44
44
|
}
|
|
45
45
|
type ExtractorSlugFor<S extends string> = S extends keyof ExtractorSlugs ? ExtractorSlugs[S] & string : string;
|
|
46
|
+
export interface ModelColumns {
|
|
47
|
+
}
|
|
48
|
+
type ModelColumnsAccessor<Slug extends string> = Slug extends keyof ModelColumns ? {
|
|
49
|
+
readonly [C in ModelColumns[Slug] & string]: C;
|
|
50
|
+
} & {
|
|
51
|
+
readonly [columnSlug: string]: string;
|
|
52
|
+
} : {
|
|
53
|
+
readonly [columnSlug: string]: string;
|
|
54
|
+
};
|
|
46
55
|
type LiteralUnion<T extends string> = T | (string & {});
|
|
47
56
|
export type ModelSpec<S extends string = string, E extends LiteralUnion<ExtractorSlugFor<S>> = LiteralUnion<ExtractorSlugFor<S>>> = {
|
|
48
57
|
name?: string;
|
|
@@ -67,11 +76,14 @@ export type ModelSpec<S extends string = string, E extends LiteralUnion<Extracto
|
|
|
67
76
|
*/
|
|
68
77
|
unification?: UnificationSpec;
|
|
69
78
|
};
|
|
70
|
-
export type ModelHandle = {
|
|
79
|
+
export type ModelHandle<Slug extends string = string> = {
|
|
71
80
|
readonly slug: string;
|
|
72
81
|
readonly uuid: Token;
|
|
73
82
|
readonly resource: "model";
|
|
83
|
+
/** This model's columns — `model.columns.<columnSlug>` yields the slug
|
|
84
|
+
* string, for relationships, unification, and segment column lists. */
|
|
85
|
+
readonly columns: ModelColumnsAccessor<Slug>;
|
|
74
86
|
};
|
|
75
|
-
export declare function defineModel<S extends string, E extends LiteralUnion<ExtractorSlugFor<S>>>(slug:
|
|
87
|
+
export declare function defineModel<Slug extends string, S extends string, E extends LiteralUnion<ExtractorSlugFor<S>>>(slug: Slug, spec: ModelSpec<S, E>): ModelHandle<Slug>;
|
|
76
88
|
export {};
|
|
77
89
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/resources/model.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAwB,KAAK,KAAK,EAAS,MAAM,YAAY,CAAC;AACrE,OAAO,EACL,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,QAAQ,EAEd,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IA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proxy mirroring `connector.actions`: `model.columns.<columnSlug>`
|
|
40
|
+
// echoes the slug back as a plain string. No server knowledge is needed —
|
|
41
|
+
// columns are slug-addressed, so the accessor works before the model exists
|
|
42
|
+
// (symbols and `then` pass through as undefined).
|
|
43
|
+
const columns = new Proxy({}, {
|
|
44
|
+
get(_target, prop) {
|
|
45
|
+
if (typeof prop !== "string" || prop === "then")
|
|
46
|
+
return undefined;
|
|
47
|
+
return prop;
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return { slug, uuid: token(id, "uuid"), resource: "model", columns };
|
|
40
51
|
}
|
|
41
52
|
// Lower a `UnificationSpec` to the wire shape `StorageTypes.ModelUnification`.
|
|
42
53
|
// The only reshaping is the parent link: a `model` parent carries a handle/ref
|