primitive-admin 1.1.0-alpha.47 → 1.1.0-alpha.49

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.
Files changed (74) hide show
  1. package/dist/bin/primitive.js +2 -0
  2. package/dist/bin/primitive.js.map +1 -1
  3. package/dist/src/commands/apps.js +54 -2
  4. package/dist/src/commands/apps.js.map +1 -1
  5. package/dist/src/commands/databases.js +31 -10
  6. package/dist/src/commands/databases.js.map +1 -1
  7. package/dist/src/commands/documents.js +77 -0
  8. package/dist/src/commands/documents.js.map +1 -1
  9. package/dist/src/commands/guides.d.ts +15 -12
  10. package/dist/src/commands/guides.js +22 -15
  11. package/dist/src/commands/guides.js.map +1 -1
  12. package/dist/src/commands/settings.d.ts +15 -0
  13. package/dist/src/commands/settings.js +102 -0
  14. package/dist/src/commands/settings.js.map +1 -0
  15. package/dist/src/commands/sync-app-settings.d.ts +105 -0
  16. package/dist/src/commands/sync-app-settings.js +339 -0
  17. package/dist/src/commands/sync-app-settings.js.map +1 -0
  18. package/dist/src/commands/sync.d.ts +34 -19
  19. package/dist/src/commands/sync.js +373 -200
  20. package/dist/src/commands/sync.js.map +1 -1
  21. package/dist/src/commands/workflows.js +32 -10
  22. package/dist/src/commands/workflows.js.map +1 -1
  23. package/dist/src/lib/api-client.d.ts +2 -0
  24. package/dist/src/lib/api-client.js +6 -0
  25. package/dist/src/lib/api-client.js.map +1 -1
  26. package/dist/src/lib/app-settings-descriptor.d.ts +108 -0
  27. package/dist/src/lib/app-settings-descriptor.js +250 -0
  28. package/dist/src/lib/app-settings-descriptor.js.map +1 -0
  29. package/dist/src/lib/codegen-shared/generatedFiles.d.ts +15 -0
  30. package/dist/src/lib/codegen-shared/generatedFiles.js +27 -10
  31. package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -1
  32. package/dist/src/lib/db-codegen/dbGenerator.d.ts +11 -83
  33. package/dist/src/lib/db-codegen/dbGenerator.js +93 -556
  34. package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
  35. package/dist/src/lib/db-codegen/dbNaming.d.ts +15 -7
  36. package/dist/src/lib/db-codegen/dbNaming.js +25 -13
  37. package/dist/src/lib/db-codegen/dbNaming.js.map +1 -1
  38. package/dist/src/lib/db-codegen/dbTemplates.d.ts +55 -4
  39. package/dist/src/lib/db-codegen/dbTemplates.js +169 -40
  40. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
  41. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +146 -0
  42. package/dist/src/lib/db-codegen/dbTypeIR.js +517 -0
  43. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -0
  44. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.d.ts +101 -0
  45. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js +200 -0
  46. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js.map +1 -0
  47. package/dist/src/lib/swift-codegen/dbGenerator.d.ts +68 -0
  48. package/dist/src/lib/swift-codegen/dbGenerator.js +380 -0
  49. package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -0
  50. package/dist/src/lib/swift-codegen/dbSwiftTypes.d.ts +42 -0
  51. package/dist/src/lib/swift-codegen/dbSwiftTypes.js +100 -0
  52. package/dist/src/lib/swift-codegen/dbSwiftTypes.js.map +1 -0
  53. package/dist/src/lib/swift-codegen/generator.d.ts +84 -0
  54. package/dist/src/lib/swift-codegen/generator.js +178 -0
  55. package/dist/src/lib/swift-codegen/generator.js.map +1 -0
  56. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +72 -0
  57. package/dist/src/lib/swift-codegen/schemaToSwift.js +644 -0
  58. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -0
  59. package/dist/src/lib/swift-codegen/swiftNaming.d.ts +85 -0
  60. package/dist/src/lib/swift-codegen/swiftNaming.js +198 -0
  61. package/dist/src/lib/swift-codegen/swiftNaming.js.map +1 -0
  62. package/dist/src/lib/sync-resource-types.d.ts +225 -0
  63. package/dist/src/lib/sync-resource-types.js +394 -0
  64. package/dist/src/lib/sync-resource-types.js.map +1 -0
  65. package/dist/src/lib/template.d.ts +1 -1
  66. package/dist/src/lib/template.js +6 -3
  67. package/dist/src/lib/template.js.map +1 -1
  68. package/dist/src/lib/workflow-codegen/generator.d.ts +18 -5
  69. package/dist/src/lib/workflow-codegen/generator.js +116 -41
  70. package/dist/src/lib/workflow-codegen/generator.js.map +1 -1
  71. package/dist/src/lib/workflow-codegen/invokerIR.d.ts +85 -0
  72. package/dist/src/lib/workflow-codegen/invokerIR.js +71 -0
  73. package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -0
  74. package/package.json +4 -2
@@ -16,11 +16,24 @@
16
16
  * `schema-validation` descriptor) so the generated types match runtime
17
17
  * validation exactly. A malformed schema throws (fail-and-exit).
18
18
  * - `.runSync` is emitted only for `syncCallable: true` workflows (the server
19
- * rejects run-sync otherwise); `.start` and `.getStatus` for every
20
- * non-reserved workflow (the typed async path, issue #1512 — async-only
21
- * workflows are exactly the ones that need a typed `getStatus`). No
22
- * `.terminate` member is emitted (the factory stays a start/status helper;
23
- * typed termination is available via the client's explicit `terminate<O>`).
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.
24
37
  * - `input` is a REQUIRED option iff the schema rejects `{}` (the client's
25
38
  * `input ?? {}` fallback would fail validation); otherwise `input?`.
26
39
  * - The runtime call always passes the ORIGINAL key string; only identifiers
@@ -30,26 +43,16 @@
30
43
  * shared `writeOrCheckGeneratedFiles`, exactly like `databases codegen`.
31
44
  */
32
45
  import * as path from "path";
33
- import { parseConfigToml } from "../config-toml.js";
34
- import { safeJsonParse } from "../workflow-payload.js";
35
46
  import { writeOrCheckGeneratedFiles, } from "../codegen-shared/generatedFiles.js";
36
47
  import { fingerprintToml } from "../db-codegen/dbFingerprint.js";
37
- import { schemaToTsType, schemaRejectsEmptyObject } from "./schemaToTs.js";
48
+ import { schemaToTsType } from "./schemaToTs.js";
38
49
  import { describeSchema } from "./generated-schema-descriptor.js";
50
+ import { describeWorkflowInvoker } from "./invokerIR.js";
39
51
  import { workflowInputTypeName, workflowOutputTypeName, workflowFactoryName, } from "./naming.js";
40
- /** Prefix marking a platform-owned workflow key (mirrors the server's
41
- * `INTERNAL_WORKFLOW_KEY_PREFIX`; inlined because the CLI cannot import from
42
- * `src/`). Such workflows are never client-invocable and are skipped. */
43
- const INTERNAL_WORKFLOW_KEY_PREFIX = "__internal.";
44
52
  /** Suffix identifying a generated file (shared with `databases codegen`). */
45
53
  export const GENERATED_FILE_SUFFIX = ".generated.ts";
46
54
  /** The client package the generated file imports its types from. */
47
55
  const CLIENT_PACKAGE = "js-bao-wss-client";
48
- /** True for a platform-owned workflow key. */
49
- function isReservedKey(key) {
50
- return (typeof key === "string" &&
51
- key.trim().toLowerCase().startsWith(INTERNAL_WORKFLOW_KEY_PREFIX));
52
- }
53
56
  /**
54
57
  * Render a top-level `<Name>Input`/`<Name>Output` declaration. An absent schema
55
58
  * → `unknown`. A plain object type → an `interface`; anything else → a `type`
@@ -74,35 +77,39 @@ function renderTypeDecl(name, schema) {
74
77
  * Parse a single workflow TOML into the data the emitter needs. Throws on
75
78
  * malformed schema JSON (fail-and-exit) — the honest `unknown` fallback is for
76
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.
77
85
  */
78
86
  function parseWorkflow(input) {
79
87
  // #1464 removed `@iarna/toml`; #1446 makes `sync pull` emit schemas as native
80
88
  // TOML tables (incl. mixed-type enums like `enum = ["ok", 1]`, TOML 1.0). The
81
- // `parseConfigToml` facade parses both. `safeJsonParse` still owns the
82
- // string-vs-inline-table schema handling.
83
- const data = parseConfigToml(input.tomlContent);
84
- const workflow = data?.workflow ?? {};
85
- const key = typeof workflow.key === "string" && workflow.key.length > 0
86
- ? workflow.key
87
- : input.fileStem;
88
- if (isReservedKey(key))
89
- return null;
90
- // safeJsonParse throws on invalid JSON in a schema string — let it bubble.
91
- const inputSchema = safeJsonParse(workflow.inputSchema);
92
- const outputSchema = safeJsonParse(workflow.outputSchema);
93
- const inputTypeName = workflowInputTypeName(key);
94
- const outputTypeName = workflowOutputTypeName(key);
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);
95
98
  return {
96
- key,
97
- syncCallable: workflow.syncCallable === true,
99
+ key: ir.key,
100
+ syncCallable: ir.syncCallable,
98
101
  inputTypeName,
99
102
  outputTypeName,
100
- factoryName: workflowFactoryName(key),
101
- inputDecl: renderTypeDecl(inputTypeName, inputSchema),
102
- outputDecl: renderTypeDecl(outputTypeName, outputSchema),
103
- // `input` is required iff the schema rejects the client's `{}` fallback.
104
- // A schema-less workflow (`undefined`) accepts anything → optional.
105
- inputRequired: inputSchema !== undefined && schemaRejectsEmptyObject(inputSchema),
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,
106
113
  };
107
114
  }
108
115
  /** Render the typed invoker factory for one workflow. */
@@ -149,6 +156,65 @@ function renderFactory(wf) {
149
156
  ` ...opts,\n` +
150
157
  ` workflowKey: ${keyLiteral},\n` +
151
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
+ ` },`);
152
218
  lines.push(` };`, `}`);
153
219
  return lines.join("\n");
154
220
  }
@@ -163,15 +229,24 @@ export function renderWorkflowFile(input) {
163
229
  return null;
164
230
  const fingerprint = fingerprintToml(input.tomlContent);
165
231
  // Only import the option types actually referenced, so the generated file
166
- // compiles under a consumer's `noUnusedLocals`. `GetWorkflowStatusOptions` is
167
- // always referenced now every factory emits a `getStatus` member (#1512).
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).
168
236
  const imports = [
237
+ "CreateCronTriggerParams",
169
238
  "GetWorkflowStatusOptions",
170
239
  "JsBaoClient",
171
240
  "StartWorkflowOptions",
241
+ "TerminateWorkflowOptions",
242
+ "UpdateCronTriggerParams",
172
243
  ];
173
244
  if (wf.syncCallable)
174
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");
175
250
  imports.sort();
176
251
  const blocks = [];
177
252
  blocks.push([
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../src/lib/workflow-codegen/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EACL,0BAA0B,G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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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primitive-admin",
3
- "version": "1.1.0-alpha.47",
3
+ "version": "1.1.0-alpha.49",
4
4
  "description": "CLI for administering Primitive applications",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,9 @@
22
22
  "gen:allowlist:check": "node scripts/gen-allowlist.mjs --check",
23
23
  "gen:workflow-descriptor": "node scripts/gen-workflow-schema-descriptor.mjs",
24
24
  "gen:workflow-descriptor:check": "node scripts/gen-workflow-schema-descriptor.mjs --check",
25
- "prebuild": "node scripts/gen-allowlist.mjs && node scripts/gen-workflow-schema-descriptor.mjs",
25
+ "gen:operation-def-descriptor": "node scripts/gen-operation-def-descriptor.mjs",
26
+ "gen:operation-def-descriptor:check": "node scripts/gen-operation-def-descriptor.mjs --check",
27
+ "prebuild": "node scripts/gen-allowlist.mjs && node scripts/gen-workflow-schema-descriptor.mjs && node scripts/gen-operation-def-descriptor.mjs",
26
28
  "build": "tsc",
27
29
  "typecheck": "tsc --noEmit",
28
30
  "prepublishOnly": "pnpm run build",