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
@@ -0,0 +1,380 @@
1
+ /**
2
+ * `databases codegen --lang swift` orchestrator (issue #1547, Phase 4).
3
+ *
4
+ * The Swift counterpart of `db-codegen/dbGenerator.ts`. Reads the SAME synced
5
+ * `database-types/*.toml` and emits ONE `<type>.generated.swift` per database
6
+ * type. Each file carries the type's record structs (read shape), per-op params
7
+ * structs (write shape), per-op result typealiases, and a typed `<Type>Ops`
8
+ * factory over the additive generic `executeOperation` overload on
9
+ * `DatabasesAPI` (the only published SDK surface for this generator).
10
+ *
11
+ * Design decisions realized (issue #1547):
12
+ * - Operation + record metadata (which ops exist, their params, their result
13
+ * descriptor, and per-model fields) is read from the SHARED `describeDbType`
14
+ * IR — the SAME source the TS renderer (`db-codegen/dbGenerator.ts`) reads.
15
+ * The Swift renderer reconstructs none of it (binding item 5), so the two
16
+ * clients can never disagree on a type's surface.
17
+ * - The generic result envelopes (`DBQueryResult<T>`, `DBMutationResult`, …)
18
+ * live in the JsBaoClient SDK, NOT emitted per file — a Swift package
19
+ * compiles all generated files into one module, so a per-file copy would
20
+ * collide. Generated files reference the SDK envelopes (mirrors how Phase 3
21
+ * put the workflow result envelopes in the SDK).
22
+ * - Swift has no analog of TS `Pick<M, …>` / `Partial<M>`, so a query op with
23
+ * a `pick`/`partial` projection types its rows as the open `JSONValue`
24
+ * rather than a narrowed record (the same Fork-4 "no clean analog →
25
+ * JSONValue" fallback the emitter uses for un-descended schema nodes). A
26
+ * `full` projection over a known record types as `DBQueryResult<Record>`.
27
+ * - Disk lifecycle (write / `--check` / orphan cleanup) delegates to the
28
+ * shared `writeOrCheckGeneratedFiles`, scoped by an ownership BANNER
29
+ * distinct from both the workflow Swift banner and the model codegen's, so
30
+ * a shared Swift output dir stays safe.
31
+ */
32
+ import * as path from "path";
33
+ import { writeOrCheckGeneratedFiles, } from "../codegen-shared/generatedFiles.js";
34
+ import { describeDbType, } from "../db-codegen/dbTypeIR.js";
35
+ import { resolveRecordInterfaceName, opParamsInterfaceName, opResultAliasName, } from "../db-codegen/dbNaming.js";
36
+ import { GENERATED_SWIFT_FILE_SUFFIX } from "./generator.js";
37
+ import { structTypeName, enumTypeName, enumCaseNames, swiftPropertyName, unescapeIdentifier, } from "./swiftNaming.js";
38
+ import { swiftTypeForDbFieldType, swiftTypeForDbParamType, } from "./dbSwiftTypes.js";
39
+ /**
40
+ * Banner prefix stamped on every CLI-emitted database `.generated.swift` file.
41
+ * Distinct from both the workflow Swift banner (`// AUTO-GENERATED FROM
42
+ * workflows/`) and the model codegen's (`// Generated by swift-bao-codegen`),
43
+ * so none of the three generators' stale-sweeps ever deletes another's files
44
+ * when they share an output dir.
45
+ */
46
+ export const DB_SWIFT_BANNER_PREFIX = "// AUTO-GENERATED FROM database-types/";
47
+ /** Swift module the generated types + factory import. */
48
+ const CLIENT_MODULE = "JsBaoClient";
49
+ const INDENT = " ";
50
+ const CONFORMANCES = "Codable, Equatable, Sendable";
51
+ /** A Swift string literal (runtime call passes the op name verbatim). */
52
+ function swiftStringLiteral(s) {
53
+ const escaped = s
54
+ .replace(/\\/g, "\\\\")
55
+ .replace(/"/g, '\\"')
56
+ .replace(/\n/g, "\\n")
57
+ .replace(/\r/g, "\\r")
58
+ .replace(/\t/g, "\\t");
59
+ return `"${escaped}"`;
60
+ }
61
+ /** Swift record struct type name for a model (shared naming + Swift sanitize). */
62
+ export function dbRecordSwiftTypeName(modelName, className) {
63
+ return structTypeName(resolveRecordInterfaceName(modelName, className));
64
+ }
65
+ /** `<Op>Params` Swift struct name (shared PascalCase + Swift sanitize). */
66
+ function dbParamsSwiftTypeName(opName) {
67
+ return structTypeName(opParamsInterfaceName(opName));
68
+ }
69
+ /** `<Op>Result` Swift typealias name. */
70
+ function dbResultSwiftTypeName(opName) {
71
+ return structTypeName(opResultAliasName(opName));
72
+ }
73
+ /** `<Type>Ops` Swift struct name (e.g. `securities-ref` → `SecuritiesRefOps`). */
74
+ function dbOpsStructName(databaseType) {
75
+ return `${structTypeName(databaseType)}Ops`;
76
+ }
77
+ /** camelCase `<type>Ops` free-function factory name, keyword-escaped. */
78
+ function dbOpsFactoryName(databaseType) {
79
+ const base = structTypeName(databaseType);
80
+ const camel = base.charAt(0).toLowerCase() + base.slice(1) + "Ops";
81
+ // A leading `_` (digit-safe struct name) stays; a camelCased factory name is
82
+ // a legal `func` identifier and never a reserved word once suffixed `Ops`.
83
+ return camel;
84
+ }
85
+ /**
86
+ * Render a nested `String`-raw enum for a field/param declaring `enum = [...]`.
87
+ * Matches the JSON-Schema emitter's + model codegen's nested-enum shape.
88
+ */
89
+ function renderStringEnum(typeName, values, indent) {
90
+ const pad = INDENT.repeat(indent);
91
+ const inner = INDENT.repeat(indent + 1);
92
+ const cases = enumCaseNames(values);
93
+ const lines = [
94
+ `${pad}public enum ${typeName}: String, Codable, CaseIterable, Sendable {`,
95
+ ];
96
+ for (const c of cases)
97
+ lines.push(`${inner}case ${c.name} = ${swiftStringLiteral(c.raw)}`);
98
+ lines.push(`${pad}}`);
99
+ return lines.join("\n");
100
+ }
101
+ /**
102
+ * Render a Swift `struct` from resolved members + nested-enum declarations. A
103
+ * public memberwise initializer is always emitted (the synthesized one is not
104
+ * public across module boundaries); `CodingKeys` only when a wire key isn't a
105
+ * legal/idiomatic Swift identifier. No custom Codable is needed — DB records /
106
+ * params have no oneOf / open-object / required-nullable cases.
107
+ */
108
+ function renderStruct(typeName, members, nestedEnumDecls) {
109
+ const b = INDENT;
110
+ const needsCodingKeys = members.some((m) => unescapeIdentifier(m.swiftName) !== m.wireKey);
111
+ const out = [`public struct ${typeName}: ${CONFORMANCES} {`];
112
+ for (const decl of nestedEnumDecls)
113
+ out.push(decl);
114
+ if (nestedEnumDecls.length > 0)
115
+ out.push("");
116
+ for (const m of members) {
117
+ out.push(`${b}public var ${m.swiftName}: ${m.type}${m.optional ? "?" : ""}`);
118
+ }
119
+ if (members.length > 0)
120
+ out.push("");
121
+ // Public memberwise initializer.
122
+ if (members.length === 0) {
123
+ out.push(`${b}public init() {}`);
124
+ }
125
+ else {
126
+ out.push(`${b}public init(`);
127
+ members.forEach((m, i) => {
128
+ const type = `${m.type}${m.optional ? "?" : ""}`;
129
+ const def = m.optional ? " = nil" : "";
130
+ out.push(`${b}${b}${m.swiftName}: ${type}${def}${i < members.length - 1 ? "," : ""}`);
131
+ });
132
+ out.push(`${b}) {`);
133
+ for (const m of members)
134
+ out.push(`${b}${b}self.${m.swiftName} = ${m.swiftName}`);
135
+ out.push(`${b}}`);
136
+ }
137
+ if (needsCodingKeys) {
138
+ out.push("");
139
+ out.push(`${b}public enum CodingKeys: String, CodingKey {`);
140
+ for (const m of members) {
141
+ const bare = unescapeIdentifier(m.swiftName);
142
+ const rhs = bare !== m.wireKey ? ` = ${swiftStringLiteral(m.wireKey)}` : "";
143
+ out.push(`${b}${b}case ${m.swiftName}${rhs}`);
144
+ }
145
+ out.push(`${b}}`);
146
+ }
147
+ out.push(`}`);
148
+ return out.join("\n");
149
+ }
150
+ /**
151
+ * Render one record model. Empty (no declared fields and no stamped fields) →
152
+ * an open typealias (`[String: JSONValue]`), mirroring the TS empty-record
153
+ * `Record<string, unknown>` — a Database-DO record is schemaless, so the empty
154
+ * shape stays open.
155
+ */
156
+ function renderRecordStruct(typeName, fields, stampedFields) {
157
+ const members = [];
158
+ const nestedEnums = [];
159
+ const declared = new Set();
160
+ for (const f of fields) {
161
+ declared.add(f.name);
162
+ let type;
163
+ if (f.type === "string" && Array.isArray(f.enum) && f.enum.length > 0) {
164
+ const enumName = enumTypeName(f.name);
165
+ nestedEnums.push(renderStringEnum(enumName, f.enum, 1));
166
+ type = enumName;
167
+ }
168
+ else {
169
+ type = swiftTypeForDbFieldType(f.type);
170
+ }
171
+ members.push({
172
+ wireKey: f.name,
173
+ swiftName: swiftPropertyName(f.name),
174
+ type,
175
+ optional: !f.required,
176
+ });
177
+ }
178
+ // Server-stamped fields → optional String props if not already declared.
179
+ for (const stamped of stampedFields) {
180
+ if (declared.has(stamped))
181
+ continue;
182
+ declared.add(stamped);
183
+ members.push({
184
+ wireKey: stamped,
185
+ swiftName: swiftPropertyName(stamped),
186
+ type: "String",
187
+ optional: true,
188
+ });
189
+ }
190
+ if (members.length === 0) {
191
+ return `public typealias ${typeName} = [String: JSONValue]`;
192
+ }
193
+ return renderStruct(typeName, members, nestedEnums);
194
+ }
195
+ /** Render one op-params struct (write shape). */
196
+ function renderParamsStruct(typeName, op) {
197
+ const members = [];
198
+ const nestedEnums = [];
199
+ for (const p of op.params) {
200
+ let type;
201
+ if (p.type === "string" && Array.isArray(p.enum) && p.enum.length > 0) {
202
+ const enumName = enumTypeName(p.name);
203
+ nestedEnums.push(renderStringEnum(enumName, p.enum, 1));
204
+ type = swiftTypeForDbParamType(p.type, enumName, p.items);
205
+ }
206
+ else if (p.type === "array" &&
207
+ p.items === "string" &&
208
+ Array.isArray(p.enum) &&
209
+ p.enum.length > 0) {
210
+ const enumName = enumTypeName(p.name);
211
+ nestedEnums.push(renderStringEnum(enumName, p.enum, 1));
212
+ type = swiftTypeForDbParamType(p.type, enumName, p.items);
213
+ }
214
+ else {
215
+ type = swiftTypeForDbParamType(p.type, undefined, p.items);
216
+ }
217
+ members.push({
218
+ wireKey: p.name,
219
+ swiftName: swiftPropertyName(p.name),
220
+ type,
221
+ optional: !p.required,
222
+ });
223
+ }
224
+ // A no-param op still gets an empty struct so the factory can construct `()`.
225
+ return renderStruct(typeName, members, nestedEnums);
226
+ }
227
+ /**
228
+ * Swift `DBQueryResult<…>` element for a query op / returning pipeline step.
229
+ * A known record with a `full` projection → `DBQueryResult<Record>`. A
230
+ * `pick`/`partial` projection has no Swift Pick/Partial analog → open rows
231
+ * (`DBQueryResult<JSONValue>`); a null record likewise.
232
+ */
233
+ function queryResultSwift(recordTypeName, projection) {
234
+ if (recordTypeName === null)
235
+ return "DBQueryResult<JSONValue>";
236
+ const kind = projection?.kind ?? "full";
237
+ return kind === "full"
238
+ ? `DBQueryResult<${recordTypeName}>`
239
+ : "DBQueryResult<JSONValue>";
240
+ }
241
+ /** Resolve the Swift result type expression for an op. */
242
+ function resultSwiftType(op, recordTypeByModel) {
243
+ const recordFor = (model) => model ? recordTypeByModel[model] ?? null : null;
244
+ switch (op.opType) {
245
+ case "query":
246
+ return queryResultSwift(recordFor(op.resultModelName), op.projection);
247
+ case "mutation":
248
+ return "DBMutationResult";
249
+ case "count":
250
+ return "DBCountResult";
251
+ case "aggregate":
252
+ return "DBAggregateResult";
253
+ case "applyToQuery":
254
+ return "DBApplyToQueryResult";
255
+ case "pipeline": {
256
+ const d = op.pipelineReturn ?? { kind: "opaque" };
257
+ switch (d.kind) {
258
+ case "query":
259
+ return queryResultSwift(recordFor(d.modelName), d.projection);
260
+ case "count":
261
+ return "DBCountResult";
262
+ case "aggregate":
263
+ return "DBAggregateResult";
264
+ case "opaque":
265
+ default:
266
+ return "DBPipelineResult";
267
+ }
268
+ }
269
+ default:
270
+ // Unknown op type → the opaque JSONValue (parity with the TS `unknown`).
271
+ return "JSONValue";
272
+ }
273
+ }
274
+ /**
275
+ * Render the typed `<Type>Ops` factory: a struct with one `async throws`
276
+ * method per op, each binding `<Op>Params` in and `<Op>Result` out over the
277
+ * generic `DatabasesAPI.executeOperation` overload, plus a free-function
278
+ * factory. Returns "" for a type with no operations.
279
+ */
280
+ function renderOpsFactory(databaseType, ops) {
281
+ if (ops.length === 0)
282
+ return "";
283
+ const structName = dbOpsStructName(databaseType);
284
+ const factoryName = dbOpsFactoryName(databaseType);
285
+ const b = INDENT;
286
+ const lines = [
287
+ `/// Typed accessor for \`${databaseType}\` operations. Obtain one with`,
288
+ `/// \`${factoryName}(client, databaseId:)\`.`,
289
+ `public struct ${structName}: Sendable {`,
290
+ `${b}public let client: JsBaoClient`,
291
+ `${b}public let databaseId: String`,
292
+ ``,
293
+ `${b}public init(client: JsBaoClient, databaseId: String) {`,
294
+ `${b}${b}self.client = client`,
295
+ `${b}${b}self.databaseId = databaseId`,
296
+ `${b}}`,
297
+ ];
298
+ for (const op of ops) {
299
+ const method = swiftPropertyName(op.opName);
300
+ const paramsType = dbParamsSwiftTypeName(op.opName);
301
+ const resultType = dbResultSwiftTypeName(op.opName);
302
+ const nameLiteral = swiftStringLiteral(op.opName);
303
+ // With params: `method(_ params:, options…)`. Without: options only, and
304
+ // the empty params struct is constructed for the call.
305
+ const paramLine = op.hasParams ? `${b}${b}_ params: ${paramsType},` : null;
306
+ const paramsArg = op.hasParams ? "params" : `${paramsType}()`;
307
+ lines.push(``, `${b}/// Execute the \`${op.opName}\` operation.`, `${b}public func ${method}(`);
308
+ if (paramLine)
309
+ lines.push(paramLine);
310
+ lines.push(`${b}${b}limit: Int? = nil,`, `${b}${b}cursor: String? = nil,`, `${b}${b}direction: SortDirection? = nil,`, `${b}${b}timing: Bool? = nil`, `${b}) async throws -> ${resultType} {`, `${b}${b}try await client.databases.executeOperation(`, `${b}${b}${b}databaseId: databaseId,`, `${b}${b}${b}name: ${nameLiteral},`, `${b}${b}${b}params: ${paramsArg},`, `${b}${b}${b}limit: limit,`, `${b}${b}${b}cursor: cursor,`, `${b}${b}${b}direction: direction,`, `${b}${b}${b}timing: timing`, `${b}${b})`, `${b}}`);
311
+ }
312
+ lines.push(`}`, ``);
313
+ lines.push(`/// Typed operations factory for the \`${databaseType}\` database type.`, `public func ${factoryName}(_ client: JsBaoClient, databaseId: String) -> ${structName} {`, `${b}${structName}(client: client, databaseId: databaseId)`, `}`);
314
+ return lines.join("\n");
315
+ }
316
+ /**
317
+ * Render the full `<type>.generated.swift` content for one database-type TOML.
318
+ * Pure — exported so tests can assert on the string directly. Throws on a Swift
319
+ * record type-name collision between two models (mirrors the TS collision guard).
320
+ */
321
+ export function renderDbTypeSwiftFile(input) {
322
+ const ir = describeDbType(input);
323
+ // model → Swift record type name, with a collision guard.
324
+ const recordTypeByModel = {};
325
+ const seen = new Map(); // typeName → modelName
326
+ for (const rec of ir.records) {
327
+ const typeName = dbRecordSwiftTypeName(rec.modelName, rec.className);
328
+ const prior = seen.get(typeName);
329
+ if (prior !== undefined && prior !== rec.modelName) {
330
+ throw new Error(`swift db codegen: record type-name collision — models "${prior}" and ` +
331
+ `"${rec.modelName}" both produce Swift type "${typeName}". Add a ` +
332
+ `class_name override to one of them.`);
333
+ }
334
+ seen.set(typeName, rec.modelName);
335
+ recordTypeByModel[rec.modelName] = typeName;
336
+ }
337
+ const banner = [
338
+ `// AUTO-GENERATED FROM database-types/${ir.databaseType}.toml — DO NOT EDIT.`,
339
+ "// Run `primitive databases codegen --lang swift` to regenerate.",
340
+ `// fingerprint: ${ir.fingerprint}`,
341
+ ].join("\n");
342
+ const imports = ["import Foundation", `import ${CLIENT_MODULE}`].join("\n");
343
+ const blocks = [banner, imports];
344
+ // Record structs, sorted by Swift type name for deterministic output.
345
+ const sortedRecords = [...ir.records].sort((a, b) => recordTypeByModel[a.modelName].localeCompare(recordTypeByModel[b.modelName]));
346
+ for (const rec of sortedRecords) {
347
+ blocks.push(renderRecordStruct(recordTypeByModel[rec.modelName], rec.fields, ir.stampedFields));
348
+ }
349
+ // Per-op params structs + result aliases (ops already sorted by op name).
350
+ for (const op of ir.ops) {
351
+ blocks.push(renderParamsStruct(dbParamsSwiftTypeName(op.opName), op));
352
+ blocks.push(`public typealias ${dbResultSwiftTypeName(op.opName)} = ${resultSwiftType(op, recordTypeByModel)}`);
353
+ }
354
+ const factory = renderOpsFactory(ir.databaseType, ir.ops);
355
+ if (factory)
356
+ blocks.push(factory);
357
+ return blocks.join("\n\n") + "\n";
358
+ }
359
+ /**
360
+ * Run Swift database codegen end-to-end. One `<type>.generated.swift` per
361
+ * database type; delegates the disk lifecycle to the shared writer/checker with
362
+ * banner-scoped ownership so a shared Swift output dir stays safe.
363
+ */
364
+ export async function generateDbSwiftTypes(options) {
365
+ const outAbs = path.resolve(options.outputDir);
366
+ const filesToWrite = new Map();
367
+ for (const input of options.inputs) {
368
+ const filePath = path.join(outAbs, `${input.databaseType}${GENERATED_SWIFT_FILE_SUFFIX}`);
369
+ filesToWrite.set(filePath, renderDbTypeSwiftFile(input));
370
+ }
371
+ return await writeOrCheckGeneratedFiles({
372
+ outputDir: outAbs,
373
+ filesToWrite,
374
+ check: options.check,
375
+ fullOwnership: options.singleType !== true,
376
+ generatedSuffix: GENERATED_SWIFT_FILE_SUFFIX,
377
+ ownershipBanner: DB_SWIFT_BANNER_PREFIX,
378
+ });
379
+ }
380
+ //# sourceMappingURL=dbGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dbGenerator.js","sourceRoot":"","sources":["../../../../src/lib/swift-codegen/dbGenerator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EACL,0BAA0B,GAE3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,cAAc,GAIf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,mBAA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,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAoC;IAEpC,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,IAAI,CAAC,IAAI,CACxB,MAAM,EACN,GAAG,KAAK,CAAC,YAAY,GAAG,2BAA2B,EAAE,CACtD,CAAC;QACF,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,MAAM,0BAA0B,CAAC;QACtC,SAAS,EAAE,MAAM;QACjB,YAAY;QACZ,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,aAAa,EAAE,OAAO,CAAC,UAAU,KAAK,IAAI;QAC1C,eAAe,EAAE,2BAA2B;QAC5C,eAAe,EAAE,sBAAsB;KACxC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Map database-type TOML field/param types → Swift `Codable` types for the
3
+ * `databases codegen --lang swift` generator (issue #1547, Phase 4).
4
+ *
5
+ * The Swift counterpart of `db-codegen/dbTsTypes.ts`. Same vocabulary, same
6
+ * fallbacks — only the emitted syntax differs:
7
+ * - record fields: `string|id|date → String`, `number → Double`,
8
+ * `boolean → Bool`, `stringset → [String]` (a StringSet serializes to a
9
+ * string array on the wire).
10
+ * - op params: `string → String`, `number → Double`, `integer → Int`
11
+ * (Fork 4 — Swift distinguishes integer from number), `boolean → Bool`,
12
+ * `object → [String: JSONValue]` (the Swift analog of the TS
13
+ * `Record<string, unknown>`), `array → [Element]`.
14
+ *
15
+ * A string `enum` on a field/param has no clean scalar analog, so — exactly
16
+ * like the JSON-Schema emitter's nested `String` enums — the RENDERER emits a
17
+ * nested `enum … : String, …` and passes its type name in here; this module
18
+ * only handles the scalar/array base mapping. An unrecognized type falls back
19
+ * to `JSONValue` (the Swift analog of TS `unknown`), never a throw, so one
20
+ * unrecognized field doesn't block codegen for the whole file.
21
+ */
22
+ /** Swift base type for a record field type (enum handled by the renderer). */
23
+ export declare function swiftTypeForDbFieldType(fieldType: string): string;
24
+ /**
25
+ * Swift type for a record field, honoring an optional nested-enum type name
26
+ * (#843). When `enumTypeName` is set the field declared a non-empty string
27
+ * `enum` and the renderer emitted a nested `String` enum of that name;
28
+ * otherwise fall back to the base mapping.
29
+ */
30
+ export declare function swiftTypeForDbField(fieldType: string, enumTypeName?: string): string;
31
+ /** Swift base type for an op-param scalar type (array/enum handled below). */
32
+ export declare function swiftTypeForDbParamScalar(paramType: string): string;
33
+ /**
34
+ * Swift type for an op param, honoring an optional nested-enum type name (#861)
35
+ * and an `array` element type (#1488). Mirrors `dbTsTypes.tsTypeForDbParamType`.
36
+ * - array param: `[Element]`, where `items` is the scalar element type (a
37
+ * string-element array with an enum renders `[EnumName]`); a missing/
38
+ * unresolved element renders `[JSONValue]`.
39
+ * - string param with an enum: the nested-enum type name.
40
+ * - otherwise the base scalar mapping.
41
+ */
42
+ export declare function swiftTypeForDbParamType(paramType: string, enumTypeName?: string, items?: string): string;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Map database-type TOML field/param types → Swift `Codable` types for the
3
+ * `databases codegen --lang swift` generator (issue #1547, Phase 4).
4
+ *
5
+ * The Swift counterpart of `db-codegen/dbTsTypes.ts`. Same vocabulary, same
6
+ * fallbacks — only the emitted syntax differs:
7
+ * - record fields: `string|id|date → String`, `number → Double`,
8
+ * `boolean → Bool`, `stringset → [String]` (a StringSet serializes to a
9
+ * string array on the wire).
10
+ * - op params: `string → String`, `number → Double`, `integer → Int`
11
+ * (Fork 4 — Swift distinguishes integer from number), `boolean → Bool`,
12
+ * `object → [String: JSONValue]` (the Swift analog of the TS
13
+ * `Record<string, unknown>`), `array → [Element]`.
14
+ *
15
+ * A string `enum` on a field/param has no clean scalar analog, so — exactly
16
+ * like the JSON-Schema emitter's nested `String` enums — the RENDERER emits a
17
+ * nested `enum … : String, …` and passes its type name in here; this module
18
+ * only handles the scalar/array base mapping. An unrecognized type falls back
19
+ * to `JSONValue` (the Swift analog of TS `unknown`), never a throw, so one
20
+ * unrecognized field doesn't block codegen for the whole file.
21
+ */
22
+ /** Swift base type for a record field type (enum handled by the renderer). */
23
+ export function swiftTypeForDbFieldType(fieldType) {
24
+ switch (fieldType) {
25
+ case "string":
26
+ case "id":
27
+ case "date":
28
+ return "String";
29
+ case "number":
30
+ return "Double";
31
+ case "boolean":
32
+ return "Bool";
33
+ case "stringset":
34
+ // A StringSet serializes to a string array on the wire.
35
+ return "[String]";
36
+ default:
37
+ return "JSONValue";
38
+ }
39
+ }
40
+ /**
41
+ * Swift type for a record field, honoring an optional nested-enum type name
42
+ * (#843). When `enumTypeName` is set the field declared a non-empty string
43
+ * `enum` and the renderer emitted a nested `String` enum of that name;
44
+ * otherwise fall back to the base mapping.
45
+ */
46
+ export function swiftTypeForDbField(fieldType, enumTypeName) {
47
+ if (fieldType === "string" && enumTypeName)
48
+ return enumTypeName;
49
+ return swiftTypeForDbFieldType(fieldType);
50
+ }
51
+ /** Swift base type for an op-param scalar type (array/enum handled below). */
52
+ export function swiftTypeForDbParamScalar(paramType) {
53
+ switch (paramType) {
54
+ case "string":
55
+ return "String";
56
+ case "number":
57
+ return "Double";
58
+ // Fork 4: Swift can distinguish integer from number; the TS emitter widens
59
+ // both to `number`, but Swift maps `integer → Int`.
60
+ case "integer":
61
+ return "Int";
62
+ case "boolean":
63
+ return "Bool";
64
+ case "object":
65
+ // The Swift analog of the TS `Record<string, unknown>`.
66
+ return "[String: JSONValue]";
67
+ default:
68
+ return "JSONValue";
69
+ }
70
+ }
71
+ /**
72
+ * Swift type for an op param, honoring an optional nested-enum type name (#861)
73
+ * and an `array` element type (#1488). Mirrors `dbTsTypes.tsTypeForDbParamType`.
74
+ * - array param: `[Element]`, where `items` is the scalar element type (a
75
+ * string-element array with an enum renders `[EnumName]`); a missing/
76
+ * unresolved element renders `[JSONValue]`.
77
+ * - string param with an enum: the nested-enum type name.
78
+ * - otherwise the base scalar mapping.
79
+ */
80
+ export function swiftTypeForDbParamType(paramType, enumTypeName, items) {
81
+ if (paramType === "array") {
82
+ let elem;
83
+ if (items === "string" && enumTypeName) {
84
+ elem = enumTypeName;
85
+ }
86
+ else if (items) {
87
+ // The element type is always scalar here, so this never re-enters the
88
+ // array branch.
89
+ elem = swiftTypeForDbParamScalar(items);
90
+ }
91
+ else {
92
+ elem = "JSONValue";
93
+ }
94
+ return `[${elem}]`;
95
+ }
96
+ if (paramType === "string" && enumTypeName)
97
+ return enumTypeName;
98
+ return swiftTypeForDbParamScalar(paramType);
99
+ }
100
+ //# sourceMappingURL=dbSwiftTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dbSwiftTypes.js","sourceRoot":"","sources":["../../../../src/lib/swift-codegen/dbSwiftTypes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,8EAA8E;AAC9E,MAAM,UAAU,uBAAuB,CAAC,SAAiB;IACvD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK,IAAI,CAAC;QACV,KAAK,MAAM;YACT,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAChB,KAAK,WAAW;YACd,wDAAwD;YACxD,OAAO,UAAU,CAAC;QACpB;YACE,OAAO,WAAW,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAAiB,EACjB,YAAqB;IAErB,IAAI,SAAS,KAAK,QAAQ,IAAI,YAAY;QAAE,OAAO,YAAY,CAAC;IAChE,OAAO,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAC5C,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,yBAAyB,CAAC,SAAiB;IACzD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,2EAA2E;QAC3E,oDAAoD;QACpD,KAAK,SAAS;YACZ,OAAO,KAAK,CAAC;QACf,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAChB,KAAK,QAAQ;YACX,wDAAwD;YACxD,OAAO,qBAAqB,CAAC;QAC/B;YACE,OAAO,WAAW,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CACrC,SAAiB,EACjB,YAAqB,EACrB,KAAc;IAEd,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;QAC1B,IAAI,IAAY,CAAC;QACjB,IAAI,KAAK,KAAK,QAAQ,IAAI,YAAY,EAAE,CAAC;YACvC,IAAI,GAAG,YAAY,CAAC;QACtB,CAAC;aAAM,IAAI,KAAK,EAAE,CAAC;YACjB,sEAAsE;YACtE,gBAAgB;YAChB,IAAI,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,WAAW,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,IAAI,GAAG,CAAC;IACrB,CAAC;IACD,IAAI,SAAS,KAAK,QAAQ,IAAI,YAAY;QAAE,OAAO,YAAY,CAAC;IAChE,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * `workflows codegen --lang swift` orchestrator (issue #1547, Phases 2-3).
3
+ *
4
+ * The Swift counterpart of `workflow-codegen/generator.ts`. Reads the SAME
5
+ * synced workflow TOMLs (`.primitive/sync/<env>/<appId>/workflows/*.toml`) and
6
+ * emits ONE `<key>.generated.swift` per workflow. Each file carries the
7
+ * workflow's `<Key>Input`/`<Key>Output` Swift `Codable` types (Phase 1's
8
+ * `renderSwiftRootType`) plus — Phase 3 — a typed invoker factory: a free
9
+ * function `func <key>(_ client:) -> <Key>Workflow` returning a struct with
10
+ * `async throws` `runSync`/`start`/`getStatus` methods (Fork 2 = A). The
11
+ * factory binds `<Key>Input`/`<Key>Output` over the additive generic overloads
12
+ * on `WorkflowsAPI` (the only published SDK surface).
13
+ *
14
+ * Design decisions realized (maintainer decision, issue #1547):
15
+ * - Schemas are interpreted through the SAME drift-guarded descriptor the TS
16
+ * emitter reads (Fork 1 = A), via `renderSwiftRootType`, so a generated
17
+ * Swift type can never promise a shape the runtime validator rejects.
18
+ * - Operation metadata (key, `syncCallable`, required-vs-optional `input`) is
19
+ * read from the SHARED `describeWorkflowInvoker` IR — the SAME source the TS
20
+ * invoker uses. The Swift renderer reconstructs none of it (#1547 binding 5),
21
+ * so the two clients can never disagree on which operations a workflow
22
+ * exposes or whether its input is required.
23
+ * - `runSync` is emitted ONLY for `syncCallable: true` workflows (the server
24
+ * rejects run-sync otherwise), matching the TS factory. `start` + `getStatus`
25
+ * are emitted for every non-reserved workflow.
26
+ * - Disk lifecycle (write / `--check` / orphan cleanup) delegates to the shared
27
+ * `writeOrCheckGeneratedFiles`, scoped by an ownership BANNER (the "banner
28
+ * namespacing" edge case) so a shared Swift output dir stays safe.
29
+ */
30
+ import { type WriteOrCheckResult } from "../codegen-shared/generatedFiles.js";
31
+ /** Suffix identifying a generated Swift file. */
32
+ export declare const GENERATED_SWIFT_FILE_SUFFIX = ".generated.swift";
33
+ /**
34
+ * Banner prefix stamped at the top of every CLI-emitted `.generated.swift`
35
+ * file. Deliberately DISTINCT from the Swift model codegen's
36
+ * `// Generated by swift-bao-codegen` header so that:
37
+ * - the model codegen's stale-sweep (which only removes files starting with
38
+ * its own header) never deletes these; and
39
+ * - this generator's cleanup (scoped to this prefix) never deletes a
40
+ * model-codegen file that shares the `.generated.swift` suffix.
41
+ * The prefix is common to every workflow file, so it is a safe ownership key.
42
+ */
43
+ export declare const SWIFT_BANNER_PREFIX = "// AUTO-GENERATED FROM workflows/";
44
+ export interface WorkflowSwiftCodegenInput {
45
+ /** Source `.toml` filename stem (fallback key when `[workflow].key` is absent). */
46
+ fileStem: string;
47
+ /** Path to the source `workflows/<key>.toml` file. */
48
+ tomlPath: string;
49
+ /** Raw TOML content (already read from disk). */
50
+ tomlContent: string;
51
+ }
52
+ export interface GenerateWorkflowSwiftTypesOptions {
53
+ inputs: WorkflowSwiftCodegenInput[];
54
+ /** Directory where the `<key>.generated.swift` files are written. */
55
+ outputDir: string;
56
+ /** `--check`: compare against disk, do not write. */
57
+ check?: boolean;
58
+ /**
59
+ * Set when the run was filtered to a single workflow key. `inputs` is then a
60
+ * PARTIAL view, so orphan cleanup / stale detection is scoped to the filtered
61
+ * file and must not touch sibling `*.generated.swift` files. Mirrors the TS
62
+ * generator's `singleWorkflow`.
63
+ */
64
+ singleWorkflow?: boolean;
65
+ }
66
+ /** PascalCase, sanitized, non-keyword base type name for a workflow key.
67
+ * `create-checkout-session` → `CreateCheckoutSession`; `123-job` → `_123Job`
68
+ * (digit-leading prefixed, parity with the TS `ensureValidIdentifierStart`). */
69
+ export declare function workflowSwiftTypeBaseName(key: string): string;
70
+ /**
71
+ * Render the full `<key>.generated.swift` content for a single workflow TOML.
72
+ * Returns null for a reserved (`__internal.*`) workflow. Pure — exported so
73
+ * tests can assert on the string directly.
74
+ */
75
+ export declare function renderWorkflowSwiftFile(input: WorkflowSwiftCodegenInput): {
76
+ key: string;
77
+ content: string;
78
+ } | null;
79
+ /**
80
+ * Run Swift workflow codegen end-to-end. One `<key>.generated.swift` per
81
+ * workflow; delegates the disk lifecycle to the shared writer/checker with
82
+ * banner-scoped ownership so a shared Swift output dir stays safe.
83
+ */
84
+ export declare function generateWorkflowSwiftTypes(options: GenerateWorkflowSwiftTypesOptions): Promise<WriteOrCheckResult>;