primitive-admin 1.0.53 → 1.0.55
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 +38 -10
- package/dist/bin/primitive.js +8 -0
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/apps.js +54 -2
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth.js +16 -6
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/blob-buckets.js +84 -7
- package/dist/src/commands/blob-buckets.js.map +1 -1
- package/dist/src/commands/catalog.js +3 -3
- package/dist/src/commands/catalog.js.map +1 -1
- package/dist/src/commands/collections.js +12 -9
- package/dist/src/commands/collections.js.map +1 -1
- package/dist/src/commands/databases.js +220 -82
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/documents.js +77 -0
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/group-type-configs.js +1 -9
- package/dist/src/commands/group-type-configs.js.map +1 -1
- package/dist/src/commands/groups.js +12 -6
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/guides.d.ts +161 -0
- package/dist/src/commands/guides.js +502 -84
- package/dist/src/commands/guides.js.map +1 -1
- package/dist/src/commands/integrations.js +2 -2
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/metadata.d.ts +2 -0
- package/dist/src/commands/metadata.js +344 -0
- package/dist/src/commands/metadata.js.map +1 -0
- package/dist/src/commands/prompts.js +2 -2
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.d.ts +1 -0
- package/dist/src/commands/rule-sets.js +25 -3
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/scripts.d.ts +2 -0
- package/dist/src/commands/scripts.js +667 -0
- package/dist/src/commands/scripts.js.map +1 -0
- package/dist/src/commands/settings.d.ts +15 -0
- package/dist/src/commands/settings.js +102 -0
- package/dist/src/commands/settings.js.map +1 -0
- package/dist/src/commands/sync-app-settings.d.ts +105 -0
- package/dist/src/commands/sync-app-settings.js +339 -0
- package/dist/src/commands/sync-app-settings.js.map +1 -0
- package/dist/src/commands/sync.d.ts +204 -9
- package/dist/src/commands/sync.js +1706 -371
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/vars.d.ts +8 -0
- package/dist/src/commands/vars.js +110 -0
- package/dist/src/commands/vars.js.map +1 -0
- package/dist/src/commands/webhooks.js +17 -3
- package/dist/src/commands/webhooks.js.map +1 -1
- package/dist/src/commands/workflows.d.ts +30 -0
- package/dist/src/commands/workflows.js +667 -59
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.d.ts +122 -18
- package/dist/src/lib/api-client.js +131 -2
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +108 -0
- package/dist/src/lib/app-settings-descriptor.js +250 -0
- package/dist/src/lib/app-settings-descriptor.js.map +1 -0
- package/dist/src/lib/batch.d.ts +26 -0
- package/dist/src/lib/batch.js +32 -0
- package/dist/src/lib/batch.js.map +1 -0
- package/dist/src/lib/block-layout.d.ts +160 -0
- package/dist/src/lib/block-layout.js +451 -0
- package/dist/src/lib/block-layout.js.map +1 -0
- package/dist/src/lib/codegen-shared/generatedFiles.d.ts +76 -0
- package/dist/src/lib/codegen-shared/generatedFiles.js +144 -0
- package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +68 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +168 -0
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -0
- package/dist/src/lib/config-toml.d.ts +10 -0
- package/dist/src/lib/config-toml.js +42 -0
- package/dist/src/lib/config-toml.js.map +1 -0
- package/dist/src/lib/config.d.ts +16 -0
- package/dist/src/lib/config.js +41 -0
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/constants.d.ts +9 -0
- package/dist/src/lib/constants.js +9 -0
- package/dist/src/lib/constants.js.map +1 -1
- package/dist/src/lib/csv.d.ts +1 -2
- package/dist/src/lib/csv.js +3 -8
- package/dist/src/lib/csv.js.map +1 -1
- package/dist/src/lib/db-codegen/dbGenerator.d.ts +21 -65
- package/dist/src/lib/db-codegen/dbGenerator.js +117 -321
- package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
- package/dist/src/lib/db-codegen/dbNaming.d.ts +37 -0
- package/dist/src/lib/db-codegen/dbNaming.js +70 -0
- package/dist/src/lib/db-codegen/dbNaming.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTemplates.d.ts +165 -5
- package/dist/src/lib/db-codegen/dbTemplates.js +292 -16
- package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +7 -3
- package/dist/src/lib/db-codegen/dbTsTypes.js +23 -1
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +146 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js +517 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.d.ts +101 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js +200 -0
- package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js.map +1 -0
- package/dist/src/lib/generated-allowlist.js +43 -0
- package/dist/src/lib/generated-allowlist.js.map +1 -1
- package/dist/src/lib/init-config.js +2 -2
- package/dist/src/lib/init-config.js.map +1 -1
- package/dist/src/lib/output.d.ts +25 -5
- package/dist/src/lib/output.js +32 -4
- package/dist/src/lib/output.js.map +1 -1
- package/dist/src/lib/query-operators.d.ts +43 -0
- package/dist/src/lib/query-operators.js +80 -0
- package/dist/src/lib/query-operators.js.map +1 -0
- package/dist/src/lib/swift-codegen/dbGenerator.d.ts +68 -0
- package/dist/src/lib/swift-codegen/dbGenerator.js +380 -0
- package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.d.ts +42 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.js +100 -0
- package/dist/src/lib/swift-codegen/dbSwiftTypes.js.map +1 -0
- package/dist/src/lib/swift-codegen/generator.d.ts +84 -0
- package/dist/src/lib/swift-codegen/generator.js +178 -0
- package/dist/src/lib/swift-codegen/generator.js.map +1 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +72 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.js +644 -0
- package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -0
- package/dist/src/lib/swift-codegen/swiftNaming.d.ts +85 -0
- package/dist/src/lib/swift-codegen/swiftNaming.js +198 -0
- package/dist/src/lib/swift-codegen/swiftNaming.js.map +1 -0
- package/dist/src/lib/sync-resource-types.d.ts +225 -0
- package/dist/src/lib/sync-resource-types.js +394 -0
- package/dist/src/lib/sync-resource-types.js.map +1 -0
- package/dist/src/lib/toml-database-config.d.ts +10 -19
- package/dist/src/lib/toml-database-config.js +28 -59
- package/dist/src/lib/toml-database-config.js.map +1 -1
- package/dist/src/lib/toml-metadata-config.d.ts +147 -0
- package/dist/src/lib/toml-metadata-config.js +463 -0
- package/dist/src/lib/toml-metadata-config.js.map +1 -0
- package/dist/src/lib/toml-native-form.d.ts +46 -0
- package/dist/src/lib/toml-native-form.js +78 -0
- package/dist/src/lib/toml-native-form.js.map +1 -0
- package/dist/src/lib/toml-params-validator.d.ts +34 -0
- package/dist/src/lib/toml-params-validator.js +118 -3
- package/dist/src/lib/toml-params-validator.js.map +1 -1
- package/dist/src/lib/workflow-apply.d.ts +86 -0
- package/dist/src/lib/workflow-apply.js +127 -0
- package/dist/src/lib/workflow-apply.js.map +1 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.d.ts +129 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js +269 -0
- package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js.map +1 -0
- package/dist/src/lib/workflow-codegen/generator.d.ts +87 -0
- package/dist/src/lib/workflow-codegen/generator.js +290 -0
- package/dist/src/lib/workflow-codegen/generator.js.map +1 -0
- package/dist/src/lib/workflow-codegen/invokerIR.d.ts +85 -0
- package/dist/src/lib/workflow-codegen/invokerIR.js +71 -0
- package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -0
- package/dist/src/lib/workflow-codegen/naming.d.ts +33 -0
- package/dist/src/lib/workflow-codegen/naming.js +81 -0
- package/dist/src/lib/workflow-codegen/naming.js.map +1 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +64 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.js +282 -0
- package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -0
- package/dist/src/lib/workflow-fragments.js +3 -3
- package/dist/src/lib/workflow-fragments.js.map +1 -1
- package/dist/src/lib/workflow-payload.d.ts +68 -0
- package/dist/src/lib/workflow-payload.js +150 -0
- package/dist/src/lib/workflow-payload.js.map +1 -0
- package/dist/src/lib/workflow-toml-validator.d.ts +1 -1
- package/dist/src/lib/workflow-toml-validator.js +37 -1
- package/dist/src/lib/workflow-toml-validator.js.map +1 -1
- package/dist/src/types/index.d.ts +11 -0
- package/dist/src/validators.d.ts +4 -3
- package/dist/src/validators.js +6 -5
- package/dist/src/validators.js.map +1 -1
- package/package.json +7 -3
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `workflows codegen` orchestrator (issue #1442).
|
|
3
|
+
*
|
|
4
|
+
* Reads synced workflow TOMLs (`.primitive/sync/<env>/<appId>/workflows/*.toml`)
|
|
5
|
+
* and emits ONE generated file per workflow —
|
|
6
|
+
* `workflows/generated/<key>.generated.ts` — each containing the workflow's
|
|
7
|
+
* `<Key>Input`/`<Key>Output` types plus a typed `<key>(client)` invoker factory
|
|
8
|
+
* returning `{ runSync?, start, getStatus }`. This mirrors `databases codegen`'s per-type
|
|
9
|
+
* `<Type>.generated.ts` layout (#1441's `<type>Ops`): per-file artifacts keep
|
|
10
|
+
* team merges conflict-free and let a `[workflow-key]` filter regenerate exactly
|
|
11
|
+
* one file.
|
|
12
|
+
*
|
|
13
|
+
* Design decisions (see the plan of record on #1442, post-pivot):
|
|
14
|
+
* - Schemas are interpreted through the SHARED descriptor
|
|
15
|
+
* (`generated-schema-descriptor.ts`, a vendored copy of the server's
|
|
16
|
+
* `schema-validation` descriptor) so the generated types match runtime
|
|
17
|
+
* validation exactly. A malformed schema throws (fail-and-exit).
|
|
18
|
+
* - `.runSync` is emitted only for `syncCallable: true` workflows (the server
|
|
19
|
+
* rejects run-sync otherwise); `.start`, `.getStatus`, and `.terminate` for
|
|
20
|
+
* every non-reserved workflow (the typed async path, issue #1512 —
|
|
21
|
+
* async-only workflows are exactly the ones that need a typed `getStatus` /
|
|
22
|
+
* `terminate`). `.terminate` binds `<Key>Output` (a terminated run can carry
|
|
23
|
+
* partial output); issue #1543 added the member, reversing #1512's
|
|
24
|
+
* start/status-only decision.
|
|
25
|
+
* - `.define` is emitted only for an apply-mode workflow
|
|
26
|
+
* (`requiresClientApply !== false`, the server's default). It binds
|
|
27
|
+
* `<Key>Output` so the `onApply` handler's `output` is the workflow's real
|
|
28
|
+
* output type rather than `any` (issue #1543, on top of #1542's
|
|
29
|
+
* `define<O>` / `WorkflowDefineOptions<O>` generics). `getPendingApplies`
|
|
30
|
+
* gets no member — #1542 made it a concrete `PendingApply[]` with no output
|
|
31
|
+
* to bind, and it is scoped to a document rather than a workflow.
|
|
32
|
+
* - `.cronTriggers.{create,update}` bind `<Key>Input` to the trigger's
|
|
33
|
+
* `rootInput` and pin `workflowKey`, so a cron helper can't be redirected at
|
|
34
|
+
* another workflow (issue #1543). `rootInput` is `Partial<<Key>Input>` for
|
|
35
|
+
* an object-shaped input schema (an `inputMapping` may supply the rest) and
|
|
36
|
+
* the full `<Key>Input` otherwise.
|
|
37
|
+
* - `input` is a REQUIRED option iff the schema rejects `{}` (the client's
|
|
38
|
+
* `input ?? {}` fallback would fail validation); otherwise `input?`.
|
|
39
|
+
* - The runtime call always passes the ORIGINAL key string; only identifiers
|
|
40
|
+
* are sanitized. `workflowKey` is set AFTER spreading `opts`, so a caller
|
|
41
|
+
* cannot override it.
|
|
42
|
+
* - Disk lifecycle (write / `--check` / suffix-based cleanup) delegates to the
|
|
43
|
+
* shared `writeOrCheckGeneratedFiles`, exactly like `databases codegen`.
|
|
44
|
+
*/
|
|
45
|
+
import * as path from "path";
|
|
46
|
+
import { writeOrCheckGeneratedFiles, } from "../codegen-shared/generatedFiles.js";
|
|
47
|
+
import { fingerprintToml } from "../db-codegen/dbFingerprint.js";
|
|
48
|
+
import { schemaToTsType } from "./schemaToTs.js";
|
|
49
|
+
import { describeSchema } from "./generated-schema-descriptor.js";
|
|
50
|
+
import { describeWorkflowInvoker } from "./invokerIR.js";
|
|
51
|
+
import { workflowInputTypeName, workflowOutputTypeName, workflowFactoryName, } from "./naming.js";
|
|
52
|
+
/** Suffix identifying a generated file (shared with `databases codegen`). */
|
|
53
|
+
export const GENERATED_FILE_SUFFIX = ".generated.ts";
|
|
54
|
+
/** The client package the generated file imports its types from. */
|
|
55
|
+
const CLIENT_PACKAGE = "js-bao-wss-client";
|
|
56
|
+
/**
|
|
57
|
+
* Render a top-level `<Name>Input`/`<Name>Output` declaration. An absent schema
|
|
58
|
+
* → `unknown`. A plain object type → an `interface`; anything else → a `type`
|
|
59
|
+
* alias.
|
|
60
|
+
*
|
|
61
|
+
* A discriminated-union (`oneOf`) output renders as `{…} | {…}`, which begins
|
|
62
|
+
* with `{` too — but it must be a `type` alias, not `interface Foo {…} | {…}`
|
|
63
|
+
* (invalid TS). Decide via the shared descriptor (`describeSchema(...).oneOf`),
|
|
64
|
+
* not the `startsWith("{")` heuristic (#1511).
|
|
65
|
+
*/
|
|
66
|
+
function renderTypeDecl(name, schema) {
|
|
67
|
+
if (schema === undefined) {
|
|
68
|
+
return `export type ${name} = unknown;`;
|
|
69
|
+
}
|
|
70
|
+
const expr = schemaToTsType(schema, 0);
|
|
71
|
+
if (expr.startsWith("{") && !describeSchema(schema).oneOf) {
|
|
72
|
+
return `export interface ${name} ${expr}`;
|
|
73
|
+
}
|
|
74
|
+
return `export type ${name} = ${expr};`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Parse a single workflow TOML into the data the emitter needs. Throws on
|
|
78
|
+
* malformed schema JSON (fail-and-exit) — the honest `unknown` fallback is for
|
|
79
|
+
* valid-but-untypeable schemas only. Returns null for a reserved workflow.
|
|
80
|
+
*
|
|
81
|
+
* The operation metadata (key, `syncCallable`, required-vs-optional `input`,
|
|
82
|
+
* parsed schemas) comes from the SHARED `describeWorkflowInvoker` IR so the TS
|
|
83
|
+
* and Swift invokers can never disagree (#1547 binding item 5). Only the
|
|
84
|
+
* TS-specific naming + type-declaration rendering happens here.
|
|
85
|
+
*/
|
|
86
|
+
function parseWorkflow(input) {
|
|
87
|
+
// #1464 removed `@iarna/toml`; #1446 makes `sync pull` emit schemas as native
|
|
88
|
+
// TOML tables (incl. mixed-type enums like `enum = ["ok", 1]`, TOML 1.0). The
|
|
89
|
+
// shared IR uses `parseConfigToml` + `safeJsonParse` under the hood.
|
|
90
|
+
const ir = describeWorkflowInvoker({
|
|
91
|
+
fileStem: input.fileStem,
|
|
92
|
+
tomlContent: input.tomlContent,
|
|
93
|
+
});
|
|
94
|
+
if (!ir)
|
|
95
|
+
return null; // reserved workflow
|
|
96
|
+
const inputTypeName = workflowInputTypeName(ir.key);
|
|
97
|
+
const outputTypeName = workflowOutputTypeName(ir.key);
|
|
98
|
+
return {
|
|
99
|
+
key: ir.key,
|
|
100
|
+
syncCallable: ir.syncCallable,
|
|
101
|
+
inputTypeName,
|
|
102
|
+
outputTypeName,
|
|
103
|
+
factoryName: workflowFactoryName(ir.key),
|
|
104
|
+
inputDecl: renderTypeDecl(inputTypeName, ir.inputSchema),
|
|
105
|
+
outputDecl: renderTypeDecl(outputTypeName, ir.outputSchema),
|
|
106
|
+
inputRequired: ir.inputRequired,
|
|
107
|
+
// Object-shaped only when the schema declares exactly `type: "object"` —
|
|
108
|
+
// the one case where `Partial<<Key>Input>` is a sound cron `rootInput`
|
|
109
|
+
// type. Schema-less / union / scalar / array → not object-shaped.
|
|
110
|
+
inputIsObjectShaped: ir.inputSchema !== undefined &&
|
|
111
|
+
describeSchema(ir.inputSchema).singularType === "object",
|
|
112
|
+
requiresClientApply: ir.requiresClientApply,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Render the typed invoker factory for one workflow. */
|
|
116
|
+
function renderFactory(wf) {
|
|
117
|
+
const keyLiteral = JSON.stringify(wf.key);
|
|
118
|
+
const inputMember = wf.inputRequired
|
|
119
|
+
? `input: ${wf.inputTypeName}`
|
|
120
|
+
: `input?: ${wf.inputTypeName}`;
|
|
121
|
+
const lines = [
|
|
122
|
+
`export function ${wf.factoryName}(client: JsBaoClient) {`,
|
|
123
|
+
` return {`,
|
|
124
|
+
];
|
|
125
|
+
// Spread `opts` FIRST, then set `workflowKey` LAST, so the factory's intended
|
|
126
|
+
// key always wins. `Omit<..., "workflowKey">` only rejects an excess
|
|
127
|
+
// `workflowKey` on object literals; a caller passing an options *variable*
|
|
128
|
+
// carrying an extra `workflowKey` (or any untyped JS caller) would otherwise
|
|
129
|
+
// override the key and invoke the wrong workflow if the spread came last.
|
|
130
|
+
if (wf.syncCallable) {
|
|
131
|
+
lines.push(` runSync: (\n` +
|
|
132
|
+
` opts: { ${inputMember} } & Omit<RunSyncWorkflowOptions, "workflowKey" | "input">\n` +
|
|
133
|
+
` ) =>\n` +
|
|
134
|
+
` client.workflows.runSync<${wf.inputTypeName}, ${wf.outputTypeName}>({\n` +
|
|
135
|
+
` ...opts,\n` +
|
|
136
|
+
` workflowKey: ${keyLiteral},\n` +
|
|
137
|
+
` }),`);
|
|
138
|
+
}
|
|
139
|
+
lines.push(` start: (\n` +
|
|
140
|
+
` opts: { ${inputMember} } & Omit<StartWorkflowOptions, "workflowKey" | "input">\n` +
|
|
141
|
+
` ) =>\n` +
|
|
142
|
+
` client.workflows.start<${wf.inputTypeName}>({\n` +
|
|
143
|
+
` ...opts,\n` +
|
|
144
|
+
` workflowKey: ${keyLiteral},\n` +
|
|
145
|
+
` }),`);
|
|
146
|
+
// Typed status fetch (#1512), emitted for EVERY non-reserved workflow — not
|
|
147
|
+
// gated on `syncCallable`, since async-only workflows are exactly the ones
|
|
148
|
+
// that need a typed `status.output`. `output` is bound to `<Key>Output` from
|
|
149
|
+
// the workflow's `outputSchema` (schema-less → `unknown`, same as the sync
|
|
150
|
+
// path). `runKey` stays required (unlike start/runSync, which auto-generate
|
|
151
|
+
// it — you cannot fetch a run's status without knowing which run). Same
|
|
152
|
+
// spread-first / key-last ordering so an untyped caller cannot override the
|
|
153
|
+
// key and read the wrong workflow's status.
|
|
154
|
+
lines.push(` getStatus: (opts: Omit<GetWorkflowStatusOptions, "workflowKey">) =>\n` +
|
|
155
|
+
` client.workflows.getStatus<${wf.outputTypeName}>({\n` +
|
|
156
|
+
` ...opts,\n` +
|
|
157
|
+
` workflowKey: ${keyLiteral},\n` +
|
|
158
|
+
` }),`);
|
|
159
|
+
// Typed termination (#1543), emitted for EVERY non-reserved workflow — any
|
|
160
|
+
// run can be terminated. `output` is bound to `<Key>Output` (a terminated run
|
|
161
|
+
// can carry partial output), same schema-less → `unknown` rule as getStatus.
|
|
162
|
+
// `runKey` stays required. Same spread-first / key-last ordering so an untyped
|
|
163
|
+
// caller cannot override the key and terminate the wrong workflow's run. This
|
|
164
|
+
// member reverses #1512's start/status-only decision.
|
|
165
|
+
lines.push(` terminate: (opts: Omit<TerminateWorkflowOptions, "workflowKey">) =>\n` +
|
|
166
|
+
` client.workflows.terminate<${wf.outputTypeName}>({\n` +
|
|
167
|
+
` ...opts,\n` +
|
|
168
|
+
` workflowKey: ${keyLiteral},\n` +
|
|
169
|
+
` }),`);
|
|
170
|
+
// Typed apply handler (#1543 Phase 2), emitted ONLY for an apply-mode
|
|
171
|
+
// workflow (`requiresClientApply !== false` — the same default the server
|
|
172
|
+
// uses to decide a completed run needs a client apply). `WorkflowDefineOptions<O>`
|
|
173
|
+
// and `WorkflowApplyHandler<O>` come from #1542; binding `<Key>Output` here
|
|
174
|
+
// makes the `onApply` callback's `output` the workflow's real output type
|
|
175
|
+
// instead of `any`. The key is passed as a positional argument, so there is
|
|
176
|
+
// no spread a caller could use to override it.
|
|
177
|
+
//
|
|
178
|
+
// No `getPendingApplies` member: #1542 shipped it as a concrete
|
|
179
|
+
// `PendingApply[]` (the server element carries no `output`, so there is no
|
|
180
|
+
// output generic to bind), and the call is scoped to a DOCUMENT rather than
|
|
181
|
+
// a workflow — a per-workflow member would bind nothing and would wrongly
|
|
182
|
+
// suggest the result only covers this workflow.
|
|
183
|
+
if (wf.requiresClientApply) {
|
|
184
|
+
lines.push(` define: (options: WorkflowDefineOptions<${wf.outputTypeName}>) =>\n` +
|
|
185
|
+
` client.workflows.define<${wf.outputTypeName}>(${keyLiteral}, options),`);
|
|
186
|
+
}
|
|
187
|
+
// Typed cron-trigger create/update (#1543), folded INTO the factory (not a
|
|
188
|
+
// separate export). The client's own `rootInput` generic (#1542) is bound to
|
|
189
|
+
// `<Key>Input`: `Partial<...>` for an object-shaped schema (an `inputMapping`
|
|
190
|
+
// may supply the rest), the full type otherwise. Binding the generic rather
|
|
191
|
+
// than restating the field keeps the caller-facing params in step with the
|
|
192
|
+
// client contract — notably `update` accepts `rootInput: null` to clear a
|
|
193
|
+
// stored root input, while `create` does not (the server rejects a null there
|
|
194
|
+
// with a 400). `workflowKey` is Omit-ted from the caller-facing params and
|
|
195
|
+
// pinned LAST so a caller can't redirect the trigger at another workflow.
|
|
196
|
+
// Nothing is spread after `workflowKey` — `rootInput` rides in via `...params`
|
|
197
|
+
// — preserving the key-last convention.
|
|
198
|
+
const rootInputType = wf.inputIsObjectShaped
|
|
199
|
+
? `Partial<${wf.inputTypeName}>`
|
|
200
|
+
: wf.inputTypeName;
|
|
201
|
+
lines.push(` cronTriggers: {\n` +
|
|
202
|
+
` create: (\n` +
|
|
203
|
+
` params: Omit<CreateCronTriggerParams<${rootInputType}>, "workflowKey">\n` +
|
|
204
|
+
` ) =>\n` +
|
|
205
|
+
` client.cronTriggers.create<${rootInputType}>({\n` +
|
|
206
|
+
` ...params,\n` +
|
|
207
|
+
` workflowKey: ${keyLiteral},\n` +
|
|
208
|
+
` }),\n` +
|
|
209
|
+
` update: (\n` +
|
|
210
|
+
` triggerId: string,\n` +
|
|
211
|
+
` params: Omit<UpdateCronTriggerParams<${rootInputType}>, "workflowKey">\n` +
|
|
212
|
+
` ) =>\n` +
|
|
213
|
+
` client.cronTriggers.update<${rootInputType}>(triggerId, {\n` +
|
|
214
|
+
` ...params,\n` +
|
|
215
|
+
` workflowKey: ${keyLiteral},\n` +
|
|
216
|
+
` }),\n` +
|
|
217
|
+
` },`);
|
|
218
|
+
lines.push(` };`, `}`);
|
|
219
|
+
return lines.join("\n");
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Render the full `<key>.generated.ts` content for a single workflow TOML input.
|
|
223
|
+
* Returns null for a reserved (`__internal.*`) workflow. Pure — exported so
|
|
224
|
+
* tests can assert on the string directly.
|
|
225
|
+
*/
|
|
226
|
+
export function renderWorkflowFile(input) {
|
|
227
|
+
const wf = parseWorkflow(input);
|
|
228
|
+
if (!wf)
|
|
229
|
+
return null;
|
|
230
|
+
const fingerprint = fingerprintToml(input.tomlContent);
|
|
231
|
+
// Only import the option types actually referenced, so the generated file
|
|
232
|
+
// compiles under a consumer's `noUnusedLocals`. `GetWorkflowStatusOptions`,
|
|
233
|
+
// `TerminateWorkflowOptions`, and the two cron-param types are always
|
|
234
|
+
// referenced now — every factory emits `getStatus`, `terminate` (#1512 /
|
|
235
|
+
// #1543), and `cronTriggers.{create,update}` (#1543).
|
|
236
|
+
const imports = [
|
|
237
|
+
"CreateCronTriggerParams",
|
|
238
|
+
"GetWorkflowStatusOptions",
|
|
239
|
+
"JsBaoClient",
|
|
240
|
+
"StartWorkflowOptions",
|
|
241
|
+
"TerminateWorkflowOptions",
|
|
242
|
+
"UpdateCronTriggerParams",
|
|
243
|
+
];
|
|
244
|
+
if (wf.syncCallable)
|
|
245
|
+
imports.push("RunSyncWorkflowOptions");
|
|
246
|
+
// Only an apply-mode workflow emits `define`, so its option type is imported
|
|
247
|
+
// only then — a non-apply-mode file would otherwise fail `noUnusedLocals`.
|
|
248
|
+
if (wf.requiresClientApply)
|
|
249
|
+
imports.push("WorkflowDefineOptions");
|
|
250
|
+
imports.sort();
|
|
251
|
+
const blocks = [];
|
|
252
|
+
blocks.push([
|
|
253
|
+
`// AUTO-GENERATED FROM workflows/${wf.key}.toml — DO NOT EDIT.`,
|
|
254
|
+
"// Run `primitive workflows codegen` to regenerate.",
|
|
255
|
+
`// fingerprint: ${fingerprint}`,
|
|
256
|
+
].join("\n"));
|
|
257
|
+
blocks.push(`import type {\n${imports
|
|
258
|
+
.map((i) => ` ${i},`)
|
|
259
|
+
.join("\n")}\n} from "${CLIENT_PACKAGE}";`);
|
|
260
|
+
blocks.push(wf.inputDecl);
|
|
261
|
+
blocks.push(wf.outputDecl);
|
|
262
|
+
blocks.push(renderFactory(wf));
|
|
263
|
+
return { key: wf.key, content: blocks.join("\n\n") + "\n" };
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Run workflow codegen end-to-end. One `<key>.generated.ts` per workflow;
|
|
267
|
+
* delegates the disk lifecycle to the shared writer/checker, exactly like
|
|
268
|
+
* `databases codegen`.
|
|
269
|
+
*/
|
|
270
|
+
export async function generateWorkflowTypes(options) {
|
|
271
|
+
const outAbs = path.resolve(options.outputDir);
|
|
272
|
+
const filesToWrite = new Map();
|
|
273
|
+
for (const input of options.inputs) {
|
|
274
|
+
const rendered = renderWorkflowFile(input);
|
|
275
|
+
if (!rendered)
|
|
276
|
+
continue; // reserved workflow — no file
|
|
277
|
+
const filePath = path.join(outAbs, `${rendered.key}${GENERATED_FILE_SUFFIX}`);
|
|
278
|
+
filesToWrite.set(filePath, rendered.content);
|
|
279
|
+
}
|
|
280
|
+
return await writeOrCheckGeneratedFiles({
|
|
281
|
+
outputDir: outAbs,
|
|
282
|
+
filesToWrite,
|
|
283
|
+
check: options.check,
|
|
284
|
+
// A single-workflow filter run owns only a subset of the generated files,
|
|
285
|
+
// so orphan cleanup / stale detection must be scoped to the filtered file.
|
|
286
|
+
fullOwnership: options.singleWorkflow !== true,
|
|
287
|
+
generatedSuffix: GENERATED_FILE_SUFFIX,
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/lib/workflow-codegen/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,0BAA0B,GAE3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AAErB,6EAA6E;AAC7E,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAAC;AAErD,oEAAoE;AACpE,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAyD3C;;;;;;;;;GASG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,MAAW;IAC/C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,eAAe,IAAI,aAAa,CAAC;IAC1C,CAAC;IACD,MAA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,CAAC,CAAC;IAC3B,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC;IAE/B,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAqC;IAErC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAE/C,MAAM,YAAY,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC/C,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,CAAC,QAAQ;YAAE,SAAS,CAAC,8BAA8B;QACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CACxB,MAAM,EACN,GAAG,QAAQ,CAAC,GAAG,GAAG,qBAAqB,EAAE,CAC1C,CAAC;QACF,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,0BAA0B,CAAC;QACtC,SAAS,EAAE,MAAM;QACjB,YAAY;QACZ,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,0EAA0E;QAC1E,2EAA2E;QAC3E,aAAa,EAAE,OAAO,CAAC,cAAc,KAAK,IAAI;QAC9C,eAAe,EAAE,qBAAqB;KACvC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared workflow-invoker IR (issue #1547, Phase 3).
|
|
3
|
+
*
|
|
4
|
+
* The typed invoker factory is generated on BOTH the TypeScript side
|
|
5
|
+
* (`workflow-codegen/generator.ts`) and the Swift side
|
|
6
|
+
* (`swift-codegen/generator.ts`). The maintainer decision (item 5, binding)
|
|
7
|
+
* requires that invoker generation reuse ONE description of the workflow's
|
|
8
|
+
* operation metadata — the runtime key, whether `runSync` is emitted
|
|
9
|
+
* (`syncCallable`), whether `input` is a required argument, and whether the
|
|
10
|
+
* workflow is apply-mode (`requiresClientApply`) — rather than each language
|
|
11
|
+
* renderer re-deriving it from the TOML. This module is that
|
|
12
|
+
* single source: both renderers call `describeWorkflowInvoker` and read the
|
|
13
|
+
* SAME `WorkflowInvokerIR`, so the two clients can never disagree on which
|
|
14
|
+
* operations a workflow exposes or whether its input is required.
|
|
15
|
+
*
|
|
16
|
+
* What stays language-specific (and is therefore NOT in the IR): the emitted
|
|
17
|
+
* identifiers (the TS and Swift base names come from different naming helpers)
|
|
18
|
+
* and the rendered type declarations. The IR carries only the parsed schemas +
|
|
19
|
+
* the neutral operation flags; each renderer turns the schemas into its own
|
|
20
|
+
* syntax.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Prefix marking a platform-owned workflow key (mirrors the server's
|
|
24
|
+
* `INTERNAL_WORKFLOW_KEY_PREFIX`; inlined because the CLI cannot import from
|
|
25
|
+
* `src/`). Such workflows are never client-invocable and are skipped. This is
|
|
26
|
+
* the single copy the TS and Swift generators now share.
|
|
27
|
+
*/
|
|
28
|
+
export declare const INTERNAL_WORKFLOW_KEY_PREFIX = "__internal.";
|
|
29
|
+
/** Raw inputs a renderer already has on hand for one workflow TOML. */
|
|
30
|
+
export interface WorkflowInvokerSource {
|
|
31
|
+
/** Source `.toml` filename stem (fallback key when `[workflow].key` is absent). */
|
|
32
|
+
fileStem: string;
|
|
33
|
+
/** Raw TOML content (already read from disk). */
|
|
34
|
+
tomlContent: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Language-neutral description of one workflow's invoker surface. Consumed by
|
|
38
|
+
* both the TS and Swift invoker renderers; neither reconstructs these decisions
|
|
39
|
+
* on its own.
|
|
40
|
+
*/
|
|
41
|
+
export interface WorkflowInvokerIR {
|
|
42
|
+
/**
|
|
43
|
+
* The ORIGINAL workflow key. The runtime call always passes this verbatim —
|
|
44
|
+
* only emitted identifiers are sanitized (per language).
|
|
45
|
+
*/
|
|
46
|
+
key: string;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the workflow is sync-callable. `runSync` is emitted ONLY when this
|
|
49
|
+
* is true (the server rejects run-sync for non-sync-callable workflows), on
|
|
50
|
+
* both clients.
|
|
51
|
+
*/
|
|
52
|
+
syncCallable: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Whether `input` is a REQUIRED argument. True iff the input schema rejects
|
|
55
|
+
* the empty object `{}` (the client's `input ?? {}` fallback would then fail
|
|
56
|
+
* validation). A schema-less workflow accepts anything → optional. Computed
|
|
57
|
+
* ONCE here via `schemaRejectsEmptyObject`, shared with both renderers.
|
|
58
|
+
*/
|
|
59
|
+
inputRequired: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the workflow is apply-mode — its completed run waits for a client
|
|
62
|
+
* to apply the output. Mirrors the server's default: apply-mode unless the
|
|
63
|
+
* TOML sets `requiresClientApply = false` (`src/workflows/app-workflow.ts`).
|
|
64
|
+
* Only an apply-mode workflow gets a `define` member on the generated
|
|
65
|
+
* invoker (issue #1543). Parsed here, alongside `syncCallable`, so no
|
|
66
|
+
* renderer reparses the TOML for it.
|
|
67
|
+
*/
|
|
68
|
+
requiresClientApply: boolean;
|
|
69
|
+
/** Parsed input schema, or `undefined` when absent. */
|
|
70
|
+
inputSchema: unknown;
|
|
71
|
+
/** Parsed output schema, or `undefined` when absent. */
|
|
72
|
+
outputSchema: unknown;
|
|
73
|
+
}
|
|
74
|
+
/** True for a platform-owned (reserved) workflow key. */
|
|
75
|
+
export declare function isReservedWorkflowKey(key: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Parse one workflow TOML into the shared invoker IR. Returns `null` for a
|
|
78
|
+
* reserved (`__internal.*`) workflow (no invoker is generated). Throws on
|
|
79
|
+
* malformed schema JSON (fail-and-exit) — the honest `undefined`/`unknown`
|
|
80
|
+
* fallback is for valid-but-untypeable schemas only.
|
|
81
|
+
*
|
|
82
|
+
* This is the ONE place that reads `syncCallable` / `requiresClientApply` and
|
|
83
|
+
* computes required-vs-optional `input`; both language generators call it.
|
|
84
|
+
*/
|
|
85
|
+
export declare function describeWorkflowInvoker(source: WorkflowInvokerSource): WorkflowInvokerIR | null;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared workflow-invoker IR (issue #1547, Phase 3).
|
|
3
|
+
*
|
|
4
|
+
* The typed invoker factory is generated on BOTH the TypeScript side
|
|
5
|
+
* (`workflow-codegen/generator.ts`) and the Swift side
|
|
6
|
+
* (`swift-codegen/generator.ts`). The maintainer decision (item 5, binding)
|
|
7
|
+
* requires that invoker generation reuse ONE description of the workflow's
|
|
8
|
+
* operation metadata — the runtime key, whether `runSync` is emitted
|
|
9
|
+
* (`syncCallable`), whether `input` is a required argument, and whether the
|
|
10
|
+
* workflow is apply-mode (`requiresClientApply`) — rather than each language
|
|
11
|
+
* renderer re-deriving it from the TOML. This module is that
|
|
12
|
+
* single source: both renderers call `describeWorkflowInvoker` and read the
|
|
13
|
+
* SAME `WorkflowInvokerIR`, so the two clients can never disagree on which
|
|
14
|
+
* operations a workflow exposes or whether its input is required.
|
|
15
|
+
*
|
|
16
|
+
* What stays language-specific (and is therefore NOT in the IR): the emitted
|
|
17
|
+
* identifiers (the TS and Swift base names come from different naming helpers)
|
|
18
|
+
* and the rendered type declarations. The IR carries only the parsed schemas +
|
|
19
|
+
* the neutral operation flags; each renderer turns the schemas into its own
|
|
20
|
+
* syntax.
|
|
21
|
+
*/
|
|
22
|
+
import { parseConfigToml } from "../config-toml.js";
|
|
23
|
+
import { safeJsonParse } from "../workflow-payload.js";
|
|
24
|
+
import { schemaRejectsEmptyObject } from "./schemaToTs.js";
|
|
25
|
+
/**
|
|
26
|
+
* Prefix marking a platform-owned workflow key (mirrors the server's
|
|
27
|
+
* `INTERNAL_WORKFLOW_KEY_PREFIX`; inlined because the CLI cannot import from
|
|
28
|
+
* `src/`). Such workflows are never client-invocable and are skipped. This is
|
|
29
|
+
* the single copy the TS and Swift generators now share.
|
|
30
|
+
*/
|
|
31
|
+
export const INTERNAL_WORKFLOW_KEY_PREFIX = "__internal.";
|
|
32
|
+
/** True for a platform-owned (reserved) workflow key. */
|
|
33
|
+
export function isReservedWorkflowKey(key) {
|
|
34
|
+
return (typeof key === "string" &&
|
|
35
|
+
key.trim().toLowerCase().startsWith(INTERNAL_WORKFLOW_KEY_PREFIX));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parse one workflow TOML into the shared invoker IR. Returns `null` for a
|
|
39
|
+
* reserved (`__internal.*`) workflow (no invoker is generated). Throws on
|
|
40
|
+
* malformed schema JSON (fail-and-exit) — the honest `undefined`/`unknown`
|
|
41
|
+
* fallback is for valid-but-untypeable schemas only.
|
|
42
|
+
*
|
|
43
|
+
* This is the ONE place that reads `syncCallable` / `requiresClientApply` and
|
|
44
|
+
* computes required-vs-optional `input`; both language generators call it.
|
|
45
|
+
*/
|
|
46
|
+
export function describeWorkflowInvoker(source) {
|
|
47
|
+
const data = parseConfigToml(source.tomlContent);
|
|
48
|
+
const workflow = data?.workflow ?? {};
|
|
49
|
+
const key = typeof workflow.key === "string" && workflow.key.length > 0
|
|
50
|
+
? workflow.key
|
|
51
|
+
: source.fileStem;
|
|
52
|
+
if (isReservedWorkflowKey(key))
|
|
53
|
+
return null;
|
|
54
|
+
// safeJsonParse throws on invalid JSON in a schema string — let it bubble.
|
|
55
|
+
const inputSchema = safeJsonParse(workflow.inputSchema);
|
|
56
|
+
const outputSchema = safeJsonParse(workflow.outputSchema);
|
|
57
|
+
return {
|
|
58
|
+
key,
|
|
59
|
+
syncCallable: workflow.syncCallable === true,
|
|
60
|
+
// `input` is required iff the schema rejects the client's `{}` fallback.
|
|
61
|
+
// A schema-less workflow (`undefined`) accepts anything → optional.
|
|
62
|
+
inputRequired: inputSchema !== undefined && schemaRejectsEmptyObject(inputSchema),
|
|
63
|
+
// Apply-mode unless explicitly disabled — the same `!== false` default the
|
|
64
|
+
// server applies when it decides whether a completed run needs a client
|
|
65
|
+
// apply. An absent key means apply-mode.
|
|
66
|
+
requiresClientApply: workflow.requiresClientApply !== false,
|
|
67
|
+
inputSchema,
|
|
68
|
+
outputSchema,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=invokerIR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invokerIR.js","sourceRoot":"","sources":["../../../../src/lib/workflow-codegen/invokerIR.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,aAAa,CAAC;AAiD1D,yDAAyD;AACzD,MAAM,UAAU,qBAAqB,CAAC,GAAW;IAC/C,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,4BAA4B,CAAC,CAClE,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAA6B;IAE7B,MAAM,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,WAAW,CAAQ,CAAC;IACxD,MAAM,QAAQ,GAAG,IAAI,EAAE,QAAQ,IAAI,EAAE,CAAC;IACtC,MAAM,GAAG,GACP,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC;QACzD,CAAC,CAAC,QAAQ,CAAC,GAAG;QACd,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;IAEtB,IAAI,qBAAqB,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAE5C,2EAA2E;IAC3E,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACxD,MAAM,YAAY,GAAG,aAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAE1D,OAAO;QACL,GAAG;QACH,YAAY,EAAE,QAAQ,CAAC,YAAY,KAAK,IAAI;QAC5C,yEAAyE;QACzE,oEAAoE;QACpE,aAAa,EACX,WAAW,KAAK,SAAS,IAAI,wBAAwB,CAAC,WAAW,CAAC;QACpE,2EAA2E;QAC3E,wEAAwE;QACxE,yCAAyC;QACzC,mBAAmB,EAAE,QAAQ,CAAC,mBAAmB,KAAK,KAAK;QAC3D,WAAW;QACX,YAAY;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifier-naming helpers for `workflows codegen` (issue #1442).
|
|
3
|
+
*
|
|
4
|
+
* Workflow keys resolve case-insensitively server-side and may contain
|
|
5
|
+
* characters that aren't valid TS identifiers (`.`, `-`). Only the emitted
|
|
6
|
+
* identifiers are sanitized — the runtime call always passes the ORIGINAL key
|
|
7
|
+
* string.
|
|
8
|
+
*
|
|
9
|
+
* Type names: `pascalCase(key) + "Input" | "Output"` (reuses `pascalCase` from
|
|
10
|
+
* the database codegen so the two commands share one PascalCase rule).
|
|
11
|
+
* Factory property: a camelCase form of the key.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* `create-checkout-session` / `createCheckoutSession` → `CreateCheckoutSession`.
|
|
15
|
+
* A digit-leading key (`123-job` → `_123Job`) is prefixed with `_` so the
|
|
16
|
+
* emitted type name is a valid TS identifier.
|
|
17
|
+
*/
|
|
18
|
+
export declare function workflowTypeBaseName(key: string): string;
|
|
19
|
+
/** PascalCase base + `Input` (e.g. `CreateCheckoutSessionInput`). */
|
|
20
|
+
export declare function workflowInputTypeName(key: string): string;
|
|
21
|
+
/** PascalCase base + `Output` (e.g. `CreateCheckoutSessionOutput`). */
|
|
22
|
+
export declare function workflowOutputTypeName(key: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* camelCase factory function name for a workflow key: PascalCase, then lowercase
|
|
25
|
+
* the first character (`create-checkout-session` → `createCheckoutSession`,
|
|
26
|
+
* `refresh-sheet` → `refreshSheet`). Used as the top-level exported factory
|
|
27
|
+
* function name in the per-workflow generated file, so it must be a legal
|
|
28
|
+
* function identifier: a digit-leading key (`123-job` → `_123Job`) is
|
|
29
|
+
* underscore-prefixed, and a key that lands on a JS reserved word (`delete`,
|
|
30
|
+
* `new`, `import`) is underscore-suffixed (`delete_`). Only the emitted
|
|
31
|
+
* identifier changes; the runtime call still passes the ORIGINAL key string.
|
|
32
|
+
*/
|
|
33
|
+
export declare function workflowFactoryName(key: string): string;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifier-naming helpers for `workflows codegen` (issue #1442).
|
|
3
|
+
*
|
|
4
|
+
* Workflow keys resolve case-insensitively server-side and may contain
|
|
5
|
+
* characters that aren't valid TS identifiers (`.`, `-`). Only the emitted
|
|
6
|
+
* identifiers are sanitized — the runtime call always passes the ORIGINAL key
|
|
7
|
+
* string.
|
|
8
|
+
*
|
|
9
|
+
* Type names: `pascalCase(key) + "Input" | "Output"` (reuses `pascalCase` from
|
|
10
|
+
* the database codegen so the two commands share one PascalCase rule).
|
|
11
|
+
* Factory property: a camelCase form of the key.
|
|
12
|
+
*/
|
|
13
|
+
import { pascalCase } from "../db-codegen/dbNaming.js";
|
|
14
|
+
/**
|
|
15
|
+
* Ensure an identifier is a valid TS identifier start. The server accepts
|
|
16
|
+
* workflow keys matching `^[a-z0-9][a-z0-9-_]{2,}$`, so a digit-leading key
|
|
17
|
+
* like `123-job` PascalCases to `123Job` — not a legal TS type name or
|
|
18
|
+
* unquoted object property, since identifiers can't start with a digit.
|
|
19
|
+
* Prefix an underscore in that case (`123Job` → `_123Job`). Only the emitted
|
|
20
|
+
* identifier changes; the runtime call still passes the ORIGINAL key string.
|
|
21
|
+
*/
|
|
22
|
+
function ensureValidIdentifierStart(name) {
|
|
23
|
+
const first = name.charAt(0);
|
|
24
|
+
if (first >= "0" && first <= "9") {
|
|
25
|
+
return `_${name}`;
|
|
26
|
+
}
|
|
27
|
+
return name;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* `create-checkout-session` / `createCheckoutSession` → `CreateCheckoutSession`.
|
|
31
|
+
* A digit-leading key (`123-job` → `_123Job`) is prefixed with `_` so the
|
|
32
|
+
* emitted type name is a valid TS identifier.
|
|
33
|
+
*/
|
|
34
|
+
export function workflowTypeBaseName(key) {
|
|
35
|
+
return ensureValidIdentifierStart(pascalCase(key));
|
|
36
|
+
}
|
|
37
|
+
/** PascalCase base + `Input` (e.g. `CreateCheckoutSessionInput`). */
|
|
38
|
+
export function workflowInputTypeName(key) {
|
|
39
|
+
return `${workflowTypeBaseName(key)}Input`;
|
|
40
|
+
}
|
|
41
|
+
/** PascalCase base + `Output` (e.g. `CreateCheckoutSessionOutput`). */
|
|
42
|
+
export function workflowOutputTypeName(key) {
|
|
43
|
+
return `${workflowTypeBaseName(key)}Output`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Reserved words that cannot be used as a bare `function <name>` declaration.
|
|
47
|
+
* The per-workflow factory is now a top-level exported function (not an
|
|
48
|
+
* object-literal property), so a key that camelCases to one of these must be
|
|
49
|
+
* escaped or `export function delete(client) {}` is a syntax error. Covers ES
|
|
50
|
+
* reserved words plus the strict-mode/future set — a workflow key resolves case
|
|
51
|
+
* -insensitively and matches `^[a-z0-9][a-z0-9-_]{2,}$`, so only the lowercase
|
|
52
|
+
* single-word forms can actually collide.
|
|
53
|
+
*/
|
|
54
|
+
const RESERVED_WORDS = new Set([
|
|
55
|
+
"break", "case", "catch", "class", "const", "continue", "debugger",
|
|
56
|
+
"default", "delete", "do", "else", "enum", "export", "extends", "false",
|
|
57
|
+
"finally", "for", "function", "if", "import", "in", "instanceof", "new",
|
|
58
|
+
"null", "return", "super", "switch", "this", "throw", "true", "try",
|
|
59
|
+
"typeof", "var", "void", "while", "with", "yield", "let", "static",
|
|
60
|
+
"implements", "interface", "package", "private", "protected", "public",
|
|
61
|
+
"await",
|
|
62
|
+
]);
|
|
63
|
+
/**
|
|
64
|
+
* camelCase factory function name for a workflow key: PascalCase, then lowercase
|
|
65
|
+
* the first character (`create-checkout-session` → `createCheckoutSession`,
|
|
66
|
+
* `refresh-sheet` → `refreshSheet`). Used as the top-level exported factory
|
|
67
|
+
* function name in the per-workflow generated file, so it must be a legal
|
|
68
|
+
* function identifier: a digit-leading key (`123-job` → `_123Job`) is
|
|
69
|
+
* underscore-prefixed, and a key that lands on a JS reserved word (`delete`,
|
|
70
|
+
* `new`, `import`) is underscore-suffixed (`delete_`). Only the emitted
|
|
71
|
+
* identifier changes; the runtime call still passes the ORIGINAL key string.
|
|
72
|
+
*/
|
|
73
|
+
export function workflowFactoryName(key) {
|
|
74
|
+
const pascal = pascalCase(key);
|
|
75
|
+
if (pascal.length === 0)
|
|
76
|
+
return pascal;
|
|
77
|
+
const camel = pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
78
|
+
const safeStart = ensureValidIdentifierStart(camel);
|
|
79
|
+
return RESERVED_WORDS.has(safeStart) ? `${safeStart}_` : safeStart;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=naming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.js","sourceRoot":"","sources":["../../../../src/lib/workflow-codegen/naming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD;;;;;;;GAOG;AACH,SAAS,0BAA0B,CAAC,IAAY;IAC9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;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;IACpD,OAAO,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-Schema → TypeScript converter for `workflows codegen` (issue #1442).
|
|
3
|
+
*
|
|
4
|
+
* Workflow `inputSchema`/`outputSchema` are real JSON Schema. This converter
|
|
5
|
+
* types only the subset the server's validator descends into — and it reads
|
|
6
|
+
* that interpretation from the SAME descriptor the server validator consumes,
|
|
7
|
+
* vendored into the CLI as `generated-schema-descriptor.ts` (a byte copy of
|
|
8
|
+
* `src/workflows/schema-descriptor.ts`, kept fresh by
|
|
9
|
+
* `cli/scripts/gen-workflow-schema-descriptor.mjs` + its drift guard). So the
|
|
10
|
+
* generated type and the runtime validation can never disagree on:
|
|
11
|
+
*
|
|
12
|
+
* - `type` single scalar (`string`/`number`/`integer`/`boolean`/`null`) →
|
|
13
|
+
* the mapped TS scalar.
|
|
14
|
+
* - `type` array-union — only when every member is a scalar/`null` → a TS
|
|
15
|
+
* union. A union that contains `object` or `array` renders `unknown`,
|
|
16
|
+
* because the server only walks `properties`/`items` for the bare string
|
|
17
|
+
* `"object"`/`"array"` — a union is never descended, so a precise-looking
|
|
18
|
+
* type would over-promise.
|
|
19
|
+
* - `enum` → a scalar-literal union, intersected with the declared `type`
|
|
20
|
+
* first (the server gates on `type` before checking `enum`).
|
|
21
|
+
* - `type: "object"` with `properties` → a nested object type; `required[]`
|
|
22
|
+
* drives `name:` vs `name?:`. An OPEN object (no `additionalProperties:
|
|
23
|
+
* false`) also emits `[key: string]: unknown` so extra keys the runtime
|
|
24
|
+
* validator accepts don't hit TS excess-property errors; a CLOSED object
|
|
25
|
+
* (`additionalProperties: false`) omits the index signature.
|
|
26
|
+
* - `type: "array"` with `items` → `T[]`.
|
|
27
|
+
* - `oneOf` whose members are ALL `type: "object"` → a discriminated
|
|
28
|
+
* (tagged) union: the `|`-union of member object types, keyed by an
|
|
29
|
+
* auto-detected single-literal-`enum` discriminator (#1511). A defective
|
|
30
|
+
* all-object tagged union (no/ambiguous discriminator, <2 members) or an
|
|
31
|
+
* all-object `anyOf` (unsupported in v1) is a STRICT codegen error, not a
|
|
32
|
+
* silent `unknown` (Fork 3, resolved by the maintainer).
|
|
33
|
+
*
|
|
34
|
+
* Everything else the server ignores (`$ref`, `allOf`, `format`,
|
|
35
|
+
* `patternProperties`, numeric constraints, tuple `items`, and a `oneOf`/`anyOf`
|
|
36
|
+
* whose members are NOT all objects) renders `unknown`.
|
|
37
|
+
*
|
|
38
|
+
* Errors are NOT swallowed here — a malformed schema fails upstream at parse
|
|
39
|
+
* time, and a defective tagged union throws — this walker otherwise returns
|
|
40
|
+
* `unknown` for anything it does not recognize.
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Convert a parsed JSON Schema node to a TypeScript type expression. Object
|
|
44
|
+
* types render multi-line (2-space indent per level); everything else renders
|
|
45
|
+
* on a single line. `indent` is the current indentation depth.
|
|
46
|
+
*/
|
|
47
|
+
export declare function schemaToTsType(schema: any, indent?: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* True when the schema REJECTS an empty object `{}` — i.e. the client's
|
|
50
|
+
* `rootInput: options.input ?? {}` fallback would fail validation, so `input`
|
|
51
|
+
* must be a compile-time-required option (issue #1442, P4). Derived from the
|
|
52
|
+
* shared descriptor so it matches the server validator exactly:
|
|
53
|
+
*
|
|
54
|
+
* - a valid top-level discriminated-union (`oneOf`): the runtime always
|
|
55
|
+
* requires the discriminator present, so `{}` matches no case;
|
|
56
|
+
* - a declared top-level `type` that `{}` does not satisfy (anything but
|
|
57
|
+
* `object`, e.g. `string`/`array`, or a union with no `object` arm);
|
|
58
|
+
* - a top-level `enum` (a fresh `{}` is never an enum member);
|
|
59
|
+
* - `type: "object"` with a non-empty `required[]` (a missing required key).
|
|
60
|
+
*
|
|
61
|
+
* An all-optional object schema, or a schema with no top-level constraints,
|
|
62
|
+
* accepts `{}` → `input` is optional.
|
|
63
|
+
*/
|
|
64
|
+
export declare function schemaRejectsEmptyObject(schema: any): boolean;
|