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.
Files changed (173) hide show
  1. package/README.md +38 -10
  2. package/dist/bin/primitive.js +8 -0
  3. package/dist/bin/primitive.js.map +1 -1
  4. package/dist/src/commands/apps.js +54 -2
  5. package/dist/src/commands/apps.js.map +1 -1
  6. package/dist/src/commands/auth.js +16 -6
  7. package/dist/src/commands/auth.js.map +1 -1
  8. package/dist/src/commands/blob-buckets.js +84 -7
  9. package/dist/src/commands/blob-buckets.js.map +1 -1
  10. package/dist/src/commands/catalog.js +3 -3
  11. package/dist/src/commands/catalog.js.map +1 -1
  12. package/dist/src/commands/collections.js +12 -9
  13. package/dist/src/commands/collections.js.map +1 -1
  14. package/dist/src/commands/databases.js +220 -82
  15. package/dist/src/commands/databases.js.map +1 -1
  16. package/dist/src/commands/documents.js +77 -0
  17. package/dist/src/commands/documents.js.map +1 -1
  18. package/dist/src/commands/group-type-configs.js +1 -9
  19. package/dist/src/commands/group-type-configs.js.map +1 -1
  20. package/dist/src/commands/groups.js +12 -6
  21. package/dist/src/commands/groups.js.map +1 -1
  22. package/dist/src/commands/guides.d.ts +161 -0
  23. package/dist/src/commands/guides.js +502 -84
  24. package/dist/src/commands/guides.js.map +1 -1
  25. package/dist/src/commands/integrations.js +2 -2
  26. package/dist/src/commands/integrations.js.map +1 -1
  27. package/dist/src/commands/metadata.d.ts +2 -0
  28. package/dist/src/commands/metadata.js +344 -0
  29. package/dist/src/commands/metadata.js.map +1 -0
  30. package/dist/src/commands/prompts.js +2 -2
  31. package/dist/src/commands/prompts.js.map +1 -1
  32. package/dist/src/commands/rule-sets.d.ts +1 -0
  33. package/dist/src/commands/rule-sets.js +25 -3
  34. package/dist/src/commands/rule-sets.js.map +1 -1
  35. package/dist/src/commands/scripts.d.ts +2 -0
  36. package/dist/src/commands/scripts.js +667 -0
  37. package/dist/src/commands/scripts.js.map +1 -0
  38. package/dist/src/commands/settings.d.ts +15 -0
  39. package/dist/src/commands/settings.js +102 -0
  40. package/dist/src/commands/settings.js.map +1 -0
  41. package/dist/src/commands/sync-app-settings.d.ts +105 -0
  42. package/dist/src/commands/sync-app-settings.js +339 -0
  43. package/dist/src/commands/sync-app-settings.js.map +1 -0
  44. package/dist/src/commands/sync.d.ts +204 -9
  45. package/dist/src/commands/sync.js +1706 -371
  46. package/dist/src/commands/sync.js.map +1 -1
  47. package/dist/src/commands/vars.d.ts +8 -0
  48. package/dist/src/commands/vars.js +110 -0
  49. package/dist/src/commands/vars.js.map +1 -0
  50. package/dist/src/commands/webhooks.js +17 -3
  51. package/dist/src/commands/webhooks.js.map +1 -1
  52. package/dist/src/commands/workflows.d.ts +30 -0
  53. package/dist/src/commands/workflows.js +667 -59
  54. package/dist/src/commands/workflows.js.map +1 -1
  55. package/dist/src/lib/api-client.d.ts +122 -18
  56. package/dist/src/lib/api-client.js +131 -2
  57. package/dist/src/lib/api-client.js.map +1 -1
  58. package/dist/src/lib/app-settings-descriptor.d.ts +108 -0
  59. package/dist/src/lib/app-settings-descriptor.js +250 -0
  60. package/dist/src/lib/app-settings-descriptor.js.map +1 -0
  61. package/dist/src/lib/batch.d.ts +26 -0
  62. package/dist/src/lib/batch.js +32 -0
  63. package/dist/src/lib/batch.js.map +1 -0
  64. package/dist/src/lib/block-layout.d.ts +160 -0
  65. package/dist/src/lib/block-layout.js +451 -0
  66. package/dist/src/lib/block-layout.js.map +1 -0
  67. package/dist/src/lib/codegen-shared/generatedFiles.d.ts +76 -0
  68. package/dist/src/lib/codegen-shared/generatedFiles.js +144 -0
  69. package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -0
  70. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +68 -0
  71. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +168 -0
  72. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -0
  73. package/dist/src/lib/config-toml.d.ts +10 -0
  74. package/dist/src/lib/config-toml.js +42 -0
  75. package/dist/src/lib/config-toml.js.map +1 -0
  76. package/dist/src/lib/config.d.ts +16 -0
  77. package/dist/src/lib/config.js +41 -0
  78. package/dist/src/lib/config.js.map +1 -1
  79. package/dist/src/lib/constants.d.ts +9 -0
  80. package/dist/src/lib/constants.js +9 -0
  81. package/dist/src/lib/constants.js.map +1 -1
  82. package/dist/src/lib/csv.d.ts +1 -2
  83. package/dist/src/lib/csv.js +3 -8
  84. package/dist/src/lib/csv.js.map +1 -1
  85. package/dist/src/lib/db-codegen/dbGenerator.d.ts +21 -65
  86. package/dist/src/lib/db-codegen/dbGenerator.js +117 -321
  87. package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
  88. package/dist/src/lib/db-codegen/dbNaming.d.ts +37 -0
  89. package/dist/src/lib/db-codegen/dbNaming.js +70 -0
  90. package/dist/src/lib/db-codegen/dbNaming.js.map +1 -1
  91. package/dist/src/lib/db-codegen/dbTemplates.d.ts +165 -5
  92. package/dist/src/lib/db-codegen/dbTemplates.js +292 -16
  93. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
  94. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +7 -3
  95. package/dist/src/lib/db-codegen/dbTsTypes.js +23 -1
  96. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  97. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +146 -0
  98. package/dist/src/lib/db-codegen/dbTypeIR.js +517 -0
  99. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -0
  100. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.d.ts +101 -0
  101. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js +200 -0
  102. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js.map +1 -0
  103. package/dist/src/lib/generated-allowlist.js +43 -0
  104. package/dist/src/lib/generated-allowlist.js.map +1 -1
  105. package/dist/src/lib/init-config.js +2 -2
  106. package/dist/src/lib/init-config.js.map +1 -1
  107. package/dist/src/lib/output.d.ts +25 -5
  108. package/dist/src/lib/output.js +32 -4
  109. package/dist/src/lib/output.js.map +1 -1
  110. package/dist/src/lib/query-operators.d.ts +43 -0
  111. package/dist/src/lib/query-operators.js +80 -0
  112. package/dist/src/lib/query-operators.js.map +1 -0
  113. package/dist/src/lib/swift-codegen/dbGenerator.d.ts +68 -0
  114. package/dist/src/lib/swift-codegen/dbGenerator.js +380 -0
  115. package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -0
  116. package/dist/src/lib/swift-codegen/dbSwiftTypes.d.ts +42 -0
  117. package/dist/src/lib/swift-codegen/dbSwiftTypes.js +100 -0
  118. package/dist/src/lib/swift-codegen/dbSwiftTypes.js.map +1 -0
  119. package/dist/src/lib/swift-codegen/generator.d.ts +84 -0
  120. package/dist/src/lib/swift-codegen/generator.js +178 -0
  121. package/dist/src/lib/swift-codegen/generator.js.map +1 -0
  122. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +72 -0
  123. package/dist/src/lib/swift-codegen/schemaToSwift.js +644 -0
  124. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -0
  125. package/dist/src/lib/swift-codegen/swiftNaming.d.ts +85 -0
  126. package/dist/src/lib/swift-codegen/swiftNaming.js +198 -0
  127. package/dist/src/lib/swift-codegen/swiftNaming.js.map +1 -0
  128. package/dist/src/lib/sync-resource-types.d.ts +225 -0
  129. package/dist/src/lib/sync-resource-types.js +394 -0
  130. package/dist/src/lib/sync-resource-types.js.map +1 -0
  131. package/dist/src/lib/toml-database-config.d.ts +10 -19
  132. package/dist/src/lib/toml-database-config.js +28 -59
  133. package/dist/src/lib/toml-database-config.js.map +1 -1
  134. package/dist/src/lib/toml-metadata-config.d.ts +147 -0
  135. package/dist/src/lib/toml-metadata-config.js +463 -0
  136. package/dist/src/lib/toml-metadata-config.js.map +1 -0
  137. package/dist/src/lib/toml-native-form.d.ts +46 -0
  138. package/dist/src/lib/toml-native-form.js +78 -0
  139. package/dist/src/lib/toml-native-form.js.map +1 -0
  140. package/dist/src/lib/toml-params-validator.d.ts +34 -0
  141. package/dist/src/lib/toml-params-validator.js +118 -3
  142. package/dist/src/lib/toml-params-validator.js.map +1 -1
  143. package/dist/src/lib/workflow-apply.d.ts +86 -0
  144. package/dist/src/lib/workflow-apply.js +127 -0
  145. package/dist/src/lib/workflow-apply.js.map +1 -0
  146. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.d.ts +129 -0
  147. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js +269 -0
  148. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js.map +1 -0
  149. package/dist/src/lib/workflow-codegen/generator.d.ts +87 -0
  150. package/dist/src/lib/workflow-codegen/generator.js +290 -0
  151. package/dist/src/lib/workflow-codegen/generator.js.map +1 -0
  152. package/dist/src/lib/workflow-codegen/invokerIR.d.ts +85 -0
  153. package/dist/src/lib/workflow-codegen/invokerIR.js +71 -0
  154. package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -0
  155. package/dist/src/lib/workflow-codegen/naming.d.ts +33 -0
  156. package/dist/src/lib/workflow-codegen/naming.js +81 -0
  157. package/dist/src/lib/workflow-codegen/naming.js.map +1 -0
  158. package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +64 -0
  159. package/dist/src/lib/workflow-codegen/schemaToTs.js +282 -0
  160. package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -0
  161. package/dist/src/lib/workflow-fragments.js +3 -3
  162. package/dist/src/lib/workflow-fragments.js.map +1 -1
  163. package/dist/src/lib/workflow-payload.d.ts +68 -0
  164. package/dist/src/lib/workflow-payload.js +150 -0
  165. package/dist/src/lib/workflow-payload.js.map +1 -0
  166. package/dist/src/lib/workflow-toml-validator.d.ts +1 -1
  167. package/dist/src/lib/workflow-toml-validator.js +37 -1
  168. package/dist/src/lib/workflow-toml-validator.js.map +1 -1
  169. package/dist/src/types/index.d.ts +11 -0
  170. package/dist/src/validators.d.ts +4 -3
  171. package/dist/src/validators.js +6 -5
  172. package/dist/src/validators.js.map +1 -1
  173. package/package.json +7 -3
@@ -11,15 +11,25 @@
11
11
  * classes — so we emit plain `export interface` types with no class
12
12
  * shell, no barrel registration, and `import type` only.
13
13
  * 2. We add an OPERATIONS half codegen-v2 has no analog for: per-op
14
- * input-params interfaces + per-op result aliases keyed off `op.type`.
14
+ * input-params interfaces + per-op result aliases. The alias for an op
15
+ * is derived from `op.type` AND, where it matters, the op's parsed
16
+ * `definition`: a query op's `projection` (#1439), a mutation op's step
17
+ * kinds (#1438), and a pipeline op's `return` step (#1437). The generator
18
+ * resolves those into the small descriptors below; the templates stay pure
19
+ * string-emitters.
15
20
  */
16
21
  import { tsTypeForDbField, tsTypeForDbParamType } from "./dbTsTypes.js";
17
22
  const HEADER_BANNER = "// AUTO-GENERATED FROM database-types TOML — DO NOT EDIT.";
18
23
  const REGEN_INSTRUCTION = "// Run `primitive databases codegen <database-type>` to regenerate.";
19
- /** The shared generic result aliases, keyed off `op.type`. */
20
- export const RESULT_ALIASES_BLOCK = `// Generic per-op result shapes, keyed off the operation type. The op
21
- // return contract is NOT stored in the TOML — these mirror the runtime
22
- // result shapes produced by the database-operations controller.
24
+ /**
25
+ * The shared generic result shapes referenced by the per-op aliases. These
26
+ * mirror the runtime result shapes produced by the database-operations
27
+ * controller; per-op aliases point at them (and, where the definition makes the
28
+ * shape derivable, at a narrowed form — see `renderOpResultAlias`).
29
+ */
30
+ export const RESULT_ALIASES_BLOCK = `// Generic per-op result shapes. These mirror the runtime result shapes
31
+ // produced by the database-operations controller; per-op aliases reference
32
+ // them (or a narrowed form when the op definition makes the shape derivable).
23
33
 
24
34
  /** \`query\` ops return a page of records. */
25
35
  export interface QueryResult<T = Record<string, unknown>> {
@@ -28,9 +38,29 @@ export interface QueryResult<T = Record<string, unknown>> {
28
38
  nextCursor?: string;
29
39
  }
30
40
 
31
- /** \`mutation\` ops return per-step results. */
41
+ /**
42
+ * One step's result inside a \`mutation\` op's uniform response (#1458).
43
+ * \`op\` is the step kind; \`id\` is the record id (the resolved canonical id for
44
+ * \`upsertOn\` saves). \`values\` carries an \`increment\` step's post-increment
45
+ * counters; \`error\` a per-step failure string.
46
+ */
47
+ export interface MutationStepResult {
48
+ op: "save" | "patch" | "delete" | "increment" | "addToSet" | "removeFromSet";
49
+ success: boolean;
50
+ id: string;
51
+ values?: Record<string, number>;
52
+ error?: string;
53
+ }
54
+
55
+ /**
56
+ * Every \`mutation\` op returns a uniform \`{ results: MutationStepResult[] }\`
57
+ * in DEFINITION-STEP order — one entry per step, tagged with its \`op\` kind and
58
+ * record \`id\` (#1458). This is a SUCCESS-PATH guarantee: a step that fails at
59
+ * the HTTP level surfaces as an error, and committed sibling writes in the same
60
+ * op are not reported (the ops are not yet executed atomically — see #1478).
61
+ */
32
62
  export interface MutationResult {
33
- results: unknown[];
63
+ results: MutationStepResult[];
34
64
  }
35
65
 
36
66
  /** \`count\` ops return a single count. */
@@ -125,22 +155,67 @@ export function renderOpParamsInterface(input) {
125
155
  lines.push(`export interface ${interfaceName} {`);
126
156
  for (const p of params) {
127
157
  const optional = p.required ? "" : "?";
128
- lines.push(` ${p.name}${optional}: ${tsTypeForDbParamType(p.type, p.enum)};`);
158
+ lines.push(` ${p.name}${optional}: ${tsTypeForDbParamType(p.type, p.enum, p.items)};`);
129
159
  }
130
160
  lines.push(`}`);
131
161
  return lines.join("\n");
132
162
  }
133
163
  /**
134
- * Render a per-op result alias keyed off `op.type`.
164
+ * Compute the generic argument for a `QueryResult<...>` from the op's record
165
+ * interface + projection classification (#1439). Reused for a pipeline op's
166
+ * returning `query` step (#1437), so both type identically to a plain query.
167
+ *
168
+ * A null record interface (the op's model has no `[models.*]` schema) has
169
+ * nothing to `Pick` from, so it always falls back to
170
+ * `Record<string, unknown>` regardless of any projection.
171
+ */
172
+ function queryResultGeneric(recordInterfaceName, projection) {
173
+ if (recordInterfaceName === null)
174
+ return "Record<string, unknown>";
175
+ const p = projection ?? { kind: "full" };
176
+ switch (p.kind) {
177
+ case "full":
178
+ return recordInterfaceName;
179
+ case "partial":
180
+ return `Partial<${recordInterfaceName}>`;
181
+ case "pick": {
182
+ // The generator guarantees a non-empty, field-guarded, sorted list; a
183
+ // defensive empty check keeps this total. Field names are emitted as TS
184
+ // string literals via JSON.stringify.
185
+ if (p.fields.length === 0)
186
+ return recordInterfaceName;
187
+ const members = p.fields.map((f) => JSON.stringify(f)).join(" | ");
188
+ return `Pick<${recordInterfaceName}, ${members}>`;
189
+ }
190
+ case "omit": {
191
+ // Static all-exclusion over known members (id/type already filtered out by
192
+ // the generator). The classifier guarantees a non-empty, sorted, member-
193
+ // guarded list; the defensive empty check keeps this total. Same literal
194
+ // emission style as `pick`.
195
+ if (p.fields.length === 0)
196
+ return recordInterfaceName;
197
+ const members = p.fields.map((f) => JSON.stringify(f)).join(" | ");
198
+ return `Omit<${recordInterfaceName}, ${members}>`;
199
+ }
200
+ }
201
+ }
202
+ /**
203
+ * Render a per-op result alias. The alias is derived from `op.type` and, where
204
+ * the shape is derivable from the parsed op definition, a narrowed form:
205
+ * - `query` → `QueryResult<M>`, narrowed by the op `projection` (#1439).
206
+ * - `mutation` → `MutationResult` — every mutation op returns the uniform
207
+ * `{ results: MutationStepResult[] }` in definition order (#1458).
208
+ * - `pipeline` → the returned step's result type (#1437); `return: "all"` /
209
+ * no-return / unresolvable keep the generic `PipelineResult`.
135
210
  */
136
211
  export function renderOpResultAlias(input) {
137
- const { aliasName, opType, recordInterfaceName } = input;
212
+ const { aliasName, opType, recordInterfaceName, projection } = input;
138
213
  switch (opType) {
139
- case "query": {
140
- const generic = recordInterfaceName ?? "Record<string, unknown>";
141
- return `export type ${aliasName} = QueryResult<${generic}>;`;
142
- }
214
+ case "query":
215
+ return `export type ${aliasName} = QueryResult<${queryResultGeneric(recordInterfaceName, projection)}>;`;
143
216
  case "mutation":
217
+ // Every mutation op returns the uniform `{ results: MutationStepResult[] }`
218
+ // in definition-step order (#1458) — no more per-category flat shapes.
144
219
  return `export type ${aliasName} = MutationResult;`;
145
220
  case "count":
146
221
  return `export type ${aliasName} = CountResult;`;
@@ -148,12 +223,213 @@ export function renderOpResultAlias(input) {
148
223
  return `export type ${aliasName} = AggregateResult;`;
149
224
  case "applyToQuery":
150
225
  return `export type ${aliasName} = ApplyToQueryResult;`;
151
- case "pipeline":
152
- return `export type ${aliasName} = PipelineResult;`;
226
+ case "pipeline": {
227
+ const d = input.pipelineReturn ?? { kind: "opaque" };
228
+ switch (d.kind) {
229
+ case "query":
230
+ return `export type ${aliasName} = QueryResult<${queryResultGeneric(d.recordInterfaceName, d.projection)}>;`;
231
+ case "count":
232
+ return `export type ${aliasName} = CountResult;`;
233
+ case "aggregate":
234
+ return `export type ${aliasName} = AggregateResult;`;
235
+ // `opaque` — `return: "all"`, no `return`, or a step the generator
236
+ // couldn't resolve — keeps the generic `PipelineResult` (unchanged).
237
+ case "opaque":
238
+ default:
239
+ return `export type ${aliasName} = PipelineResult;`;
240
+ }
241
+ }
153
242
  default:
154
243
  // Unknown op type — emit a permissive alias rather than throwing,
155
244
  // so one stray op doesn't block codegen for the whole file.
156
245
  return `export type ${aliasName} = unknown;`;
157
246
  }
158
247
  }
248
+ // The `databases.executeOperation<R>` member on the structural client shape.
249
+ // `object` (not `Record<string, unknown>`) so a strict generated `<Op>Params`
250
+ // interface — which has no index signature — is still assignable here.
251
+ const EXECUTE_OPERATION_MEMBER = [
252
+ " executeOperation<R>(",
253
+ " databaseId: string,",
254
+ " name: string,",
255
+ " options?: {",
256
+ " params?: object;",
257
+ " limit?: number;",
258
+ " cursor?: string;",
259
+ " direction?: 1 | -1;",
260
+ " timing?: boolean;",
261
+ " },",
262
+ " ): Promise<R>;",
263
+ ];
264
+ // The `databases.subscribe<T>` member on the structural client shape
265
+ // (#1544 Phase 2). Mirrors the client's `subscribe<T, P>` closely enough that
266
+ // the real `JsBaoClient` satisfies it structurally; `P` defaults there so the
267
+ // single generic here is compatible.
268
+ const SUBSCRIBE_MEMBER = [
269
+ " subscribe<T>(",
270
+ " databaseId: string,",
271
+ " subscriptionKey: string,",
272
+ " options: SubscribeOptions<T>,",
273
+ " ): () => void;",
274
+ ];
275
+ // Non-param options (pagination + diagnostics) each ops factory method accepts.
276
+ const OPS_CALL_OPTIONS_BLOCK = [
277
+ "// Non-param options (pagination + diagnostics) each factory method accepts",
278
+ "// alongside its params, passed straight through to `executeOperation`.",
279
+ "interface OpsCallOptions {",
280
+ " limit?: number;",
281
+ " cursor?: string;",
282
+ " direction?: 1 | -1;",
283
+ " timing?: boolean;",
284
+ "}",
285
+ ].join("\n");
286
+ // Inlined structural subscribe types (#1544 Phase 2) — import-free mirrors of
287
+ // the client's `DatabaseSubscribeOptions` / `DatabaseChangePayload` /
288
+ // `DatabaseChangeEvent`. `T` is the record type bound to each change; a
289
+ // projected subscription binds `T` to a `Pick<Record, …select>`.
290
+ const SUBSCRIBE_TYPES_BLOCK = [
291
+ "interface SubscribeOptions<T> {",
292
+ " params?: Record<string, any>;",
293
+ " onChange: (event: SubscribeChangePayload<T>) => void;",
294
+ "}",
295
+ "interface SubscribeChangePayload<T> {",
296
+ ' type: "db.change";',
297
+ " databaseId: string;",
298
+ " subscriptionKey: string;",
299
+ " changes: SubscribeChangeEvent<T>[];",
300
+ " timestamp: string;",
301
+ " originConnectionId: string | null;",
302
+ " originUserId: string | null;",
303
+ " isOrigin: boolean;",
304
+ " isOriginUser: boolean;",
305
+ "}",
306
+ "interface SubscribeChangeEvent<T> {",
307
+ ' changeType?: "enter" | "update" | "leave";',
308
+ ' op: "save" | "patch" | "delete" | "increment" | "addToSet" | "removeFromSet";',
309
+ " modelName: string;",
310
+ " id: string;",
311
+ " data?: T | null;",
312
+ " previousData?: T | null;",
313
+ "}",
314
+ ].join("\n");
315
+ /**
316
+ * The inlined structural client shape, carrying whichever members the file
317
+ * needs (`executeOperation` for ops, `subscribe` for subscriptions). One shared
318
+ * `OpsClient` interface serves both the `<type>Ops` and `<type>Subscriptions`
319
+ * factories so the file never declares the interface twice.
320
+ */
321
+ function renderClientInterface(members) {
322
+ return [
323
+ "// Minimal structural client shape — inlined so this file stays import-free",
324
+ "// and carries no runtime dependency on the client package. The real",
325
+ "// `JsBaoClient` satisfies it structurally.",
326
+ "interface OpsClient {",
327
+ " databases: {",
328
+ ...members,
329
+ " };",
330
+ "}",
331
+ ].join("\n");
332
+ }
333
+ /** One factory method per op, pairing `<Op>Params` in with `<Op>Result` out. */
334
+ function opsMethodLines(ops) {
335
+ return ops.map((op) => {
336
+ const nameLiteral = JSON.stringify(op.opName);
337
+ if (op.hasParams) {
338
+ return (` ${op.propertyKey}: (params: ${op.paramsInterfaceName}, options?: OpsCallOptions): Promise<${op.resultAliasName}> =>\n` +
339
+ ` client.databases.executeOperation<${op.resultAliasName}>(databaseId, ${nameLiteral}, { params, ...options }),`);
340
+ }
341
+ // No declared params: the method takes only the optional options object, so
342
+ // it stays callable with no arguments (`ops.foo()`).
343
+ return (` ${op.propertyKey}: (options?: OpsCallOptions): Promise<${op.resultAliasName}> =>\n` +
344
+ ` client.databases.executeOperation<${op.resultAliasName}>(databaseId, ${nameLiteral}, { ...options }),`);
345
+ });
346
+ }
347
+ /** The `export function <type>Ops(...)` factory body. */
348
+ function opsFactoryBlock(factoryName, databaseType, ops) {
349
+ return [
350
+ `/** Typed accessor for \`${databaseType}\` operations. */`,
351
+ `export function ${factoryName}(client: OpsClient, databaseId: string) {`,
352
+ " return {",
353
+ ...opsMethodLines(ops),
354
+ " };",
355
+ "}",
356
+ ].join("\n");
357
+ }
358
+ /**
359
+ * Render the typed-operations factory (#1441): an inlined structural client
360
+ * interface + a shared call-options type + the `export function <type>Ops`
361
+ * factory. Each method pairs an op's `<Op>Params` input with its `<Op>Result`
362
+ * output and calls `client.databases.executeOperation<<Op>Result>(...)`, so the
363
+ * generated code carries no `as` cast and no import — the real `JsBaoClient`
364
+ * satisfies the structural `OpsClient` param.
365
+ *
366
+ * Returns "" for a database type with no operations, so the caller can omit the
367
+ * factory entirely rather than emit an empty function.
368
+ */
369
+ export function renderOpsFactory(input) {
370
+ const { factoryName, databaseType, ops } = input;
371
+ if (ops.length === 0)
372
+ return "";
373
+ return [
374
+ renderClientInterface(EXECUTE_OPERATION_MEMBER),
375
+ OPS_CALL_OPTIONS_BLOCK,
376
+ opsFactoryBlock(factoryName, databaseType, ops),
377
+ ].join("\n\n");
378
+ }
379
+ /** The `export function <type>Subscriptions(...)` factory body. */
380
+ function subscriptionsFactoryBlock(factoryName, databaseType, subscriptions) {
381
+ const methodLines = subscriptions.map((sub) => {
382
+ const keyLiteral = JSON.stringify(sub.subscriptionKey);
383
+ return (` ${sub.propertyKey}: (options: SubscribeOptions<${sub.eventType}>): (() => void) =>\n` +
384
+ ` client.databases.subscribe<${sub.eventType}>(databaseId, ${keyLiteral}, options),`);
385
+ });
386
+ return [
387
+ `/** Typed accessor for \`${databaseType}\` realtime subscriptions. */`,
388
+ `export function ${factoryName}(client: OpsClient, databaseId: string) {`,
389
+ " return {",
390
+ ...methodLines,
391
+ " };",
392
+ "}",
393
+ ].join("\n");
394
+ }
395
+ /**
396
+ * Render the typed-ops factory (#1441) and the typed-subscriptions factory
397
+ * (#1544 Phase 2) for one database type, sharing a single structural `OpsClient`
398
+ * interface (Fork 4 = A).
399
+ *
400
+ * With no subscriptions this is byte-identical to {@link renderOpsFactory}, so
401
+ * every existing generated file (none of which has subscriptions) is unchanged.
402
+ * When subscriptions exist, the shared `OpsClient` gains a `subscribe<T>`
403
+ * member, the inlined subscribe types are emitted once, and a separate
404
+ * `<type>Subscriptions` factory follows the ops factory. The file stays
405
+ * import-free (behavior 10).
406
+ *
407
+ * Returns "" when the type has neither ops nor subscriptions.
408
+ */
409
+ export function renderFactories(input) {
410
+ const { databaseType, ops, subscriptions } = input;
411
+ // No subscriptions → identical to the standalone ops factory (keeps every
412
+ // pre-#1544 generated file byte-for-byte unchanged).
413
+ if (subscriptions.length === 0) {
414
+ return renderOpsFactory({
415
+ factoryName: input.opsFactoryName,
416
+ databaseType,
417
+ ops,
418
+ });
419
+ }
420
+ const hasOps = ops.length > 0;
421
+ const members = [
422
+ ...(hasOps ? EXECUTE_OPERATION_MEMBER : []),
423
+ ...SUBSCRIBE_MEMBER,
424
+ ];
425
+ const blocks = [renderClientInterface(members)];
426
+ if (hasOps)
427
+ blocks.push(OPS_CALL_OPTIONS_BLOCK);
428
+ blocks.push(SUBSCRIBE_TYPES_BLOCK);
429
+ if (hasOps) {
430
+ blocks.push(opsFactoryBlock(input.opsFactoryName, databaseType, ops));
431
+ }
432
+ blocks.push(subscriptionsFactoryBlock(input.subscriptionsFactoryName, databaseType, subscriptions));
433
+ return blocks.join("\n\n");
434
+ }
159
435
  //# sourceMappingURL=dbTemplates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dbTemplates.js","sourceRoot":"","sources":["../../../../src/lib/db-codegen/dbTemplates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAExE,MAAM,aAAa,GACjB,2DAA2D,CAAC;AAC9D,MAAM,iBAAiB,GACrB,qEAAqE,CAAC;AAmExE,8DAA8D;AAC9D,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCnC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,WAAmB;IAC9C,OAAO;QACL,aAAa;QACb,iBAAiB;QACjB,mBAAmB,WAAW,EAAE;KACjC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,KAAiC;IAEjC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IACvD,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,KAAK,MAAM,CAAC,IAAI,MAA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AAE,KAAK,CAAC,cAAc;YACjC,YAAY;YACZ,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9B,MAAM,OAAO,GAAG;QACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,GAAG,gBAAgB;KACpB,CAAC;IAEF,MAAM,MAAM,GAAa,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,IAAI,MAAM;QAAE,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAChD,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnC,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,cAAc,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC;IACxE,CAAC;IACD,MAAM,CAAC,IAAI,CACT,yBAAyB,CACvB,KAAK,CAAC,wBAAwB,EAC9B,YAAY,EACZ,aAAa,CACd,CACF,CAAC;IAEF,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC7B,CAAC"}
@@ -33,8 +33,12 @@
33
33
  * library's internal type paths.
34
34
  */
35
35
  export type DbFieldType = "string" | "number" | "boolean" | "date" | "id" | "stringset";
36
- /** Param types accepted in an `[[operations]]` `params` block. */
37
- export type DbParamType = "string" | "number" | "boolean" | "object";
36
+ /**
37
+ * Param types accepted in an `[[operations]]` `params` block. `array` (#1488)
38
+ * carries a scalar `items` element type; `integer` (also surfaced in #1488 when
39
+ * reconciling the registration/runtime type lists) maps to `number`.
40
+ */
41
+ export type DbParamType = "string" | "number" | "boolean" | "integer" | "object" | "array";
38
42
  /**
39
43
  * Returns the TS type expression for a record field type. Unknown types
40
44
  * fall back to `unknown` rather than throwing: the database-type TOML is
@@ -75,4 +79,4 @@ export declare function tsTypeForDbField(fieldType: string, enumValues?: string[
75
79
  * the base type for a non-string param or an empty enum rather than throwing —
76
80
  * the server is the source of truth for rejecting a malformed param `enum`.
77
81
  */
78
- export declare function tsTypeForDbParamType(paramType: string, enumValues?: string[]): string;
82
+ export declare function tsTypeForDbParamType(paramType: string, enumValues?: string[], items?: string): string;
@@ -90,7 +90,28 @@ export function tsTypeForDbField(fieldType, enumValues) {
90
90
  * the base type for a non-string param or an empty enum rather than throwing —
91
91
  * the server is the source of truth for rejecting a malformed param `enum`.
92
92
  */
93
- export function tsTypeForDbParamType(paramType, enumValues) {
93
+ export function tsTypeForDbParamType(paramType, enumValues, items) {
94
+ // Array param (#1488): a declared `type = "array"` (Phase 2) or one inferred
95
+ // from a `$in`/`$nin` binding (Phase 1). `items` is the scalar element type;
96
+ // a per-element `enum` on a string-element array renders `("a" | "b")[]`.
97
+ // A missing/unresolved `items` renders `unknown[]` (the conservative widen).
98
+ if (paramType === "array") {
99
+ let elem;
100
+ if (items === "string" &&
101
+ Array.isArray(enumValues) &&
102
+ enumValues.length > 0) {
103
+ elem = `(${tsUnionFromEnum(enumValues)})`;
104
+ }
105
+ else if (items) {
106
+ // Element type is always scalar here, so the recursion never re-enters
107
+ // this array branch.
108
+ elem = tsTypeForDbParamType(items);
109
+ }
110
+ else {
111
+ elem = "unknown";
112
+ }
113
+ return `${elem}[]`;
114
+ }
94
115
  if (paramType === "string" &&
95
116
  Array.isArray(enumValues) &&
96
117
  enumValues.length > 0) {
@@ -100,6 +121,7 @@ export function tsTypeForDbParamType(paramType, enumValues) {
100
121
  case "string":
101
122
  return "string";
102
123
  case "number":
124
+ case "integer":
103
125
  return "number";
104
126
  case "boolean":
105
127
  return "boolean";
@@ -1 +1 @@
1
- {"version":3,"file":"dbTsTypes.js","sourceRoot":"","sources":["../../../../src/lib/db-codegen/dbTsTypes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAoBH;;;;;;GAMG;AACH,MAAM,U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;IAEd,6EAA6E;IAC7E,6EAA6E;IAC7E,0EAA0E;IAC1E,6EAA6E;IAC7E,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;QAC1B,IAAI,IAAY,CAAC;QACjB,IACE,KAAK,KAAK,QAAQ;YAClB,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;YACzB,UAAU,CAAC,MAAM,GAAG,CAAC,EACrB,CAAC;YACD,IAAI,GAAG,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,CAAC;QAC5C,CAAC;aAAM,IAAI,KAAK,EAAE,CAAC;YACjB,uEAAuE;YACvE,qBAAqB;YACrB,IAAI,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,GAAG,IAAI,IAAI,CAAC;IACrB,CAAC;IACD,IACE,SAAS,KAAK,QAAQ;QACtB,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QACzB,UAAU,CAAC,MAAM,GAAG,CAAC,EACrB,CAAC;QACD,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IACD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,yBAAyB,CAAC;QACnC;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Shared database-type operation IR (issue #1547, Phase 4).
3
+ *
4
+ * `describeDbType` resolves ONE database-type TOML into a naming-neutral
5
+ * descriptor of its record models and operations — the record fields (with
6
+ * inferred required-ness), the per-op input params, and the per-op result
7
+ * descriptor (query projection #1439, mutation, count, aggregate,
8
+ * applyToQuery, pipeline return #1437). It performs NO language-specific
9
+ * naming: the TS renderer (`dbGenerator.ts`) and the Swift renderer
10
+ * (`swift-codegen/dbGenerator.ts`) both consume this SAME IR and each apply
11
+ * their own identifier rules. Neither renderer re-walks the op definitions, so
12
+ * the two clients can never disagree on which operations a database type
13
+ * exposes, what params they take, or what shape they return (issue #1547
14
+ * binding item 5 — the same "shared operation IR, no metadata reconstruction"
15
+ * contract Phase 3's `describeWorkflowInvoker` gives the workflow invoker).
16
+ *
17
+ * The resolution logic here was lifted verbatim from `renderDbTypeFile`'s
18
+ * former inline body; the only change is that result descriptors reference a
19
+ * MODEL NAME (naming-neutral) rather than a resolved TS interface name, so the
20
+ * Swift renderer can map the same model to its own type name.
21
+ */
22
+ import type { RecordField, ParamField, ProjectionClassification } from "./dbTemplates.js";
23
+ export interface DbCodegenInput {
24
+ /** Database type name (drives the output filename). */
25
+ databaseType: string;
26
+ /** Path to the source `database-types/<type>.toml` file. */
27
+ tomlPath: string;
28
+ /** Raw TOML content (already read from disk). */
29
+ tomlContent: string;
30
+ }
31
+ /**
32
+ * Naming-neutral form of a pipeline op's resolved `return` step (#1437). Same
33
+ * shape as `dbTemplates.PipelineReturnDescriptor` but keyed on the returning
34
+ * step's MODEL NAME instead of a resolved interface name, so each renderer maps
35
+ * it to its own record type. `opaque` → the generic pipeline-result envelope.
36
+ */
37
+ export type PipelineReturnIR = {
38
+ kind: "query";
39
+ modelName: string | null;
40
+ projection: ProjectionClassification;
41
+ } | {
42
+ kind: "count";
43
+ } | {
44
+ kind: "aggregate";
45
+ } | {
46
+ kind: "opaque";
47
+ };
48
+ /** One record model on a database type (read shape), naming-neutral. */
49
+ export interface DbRecordIR {
50
+ /** TOML model name (e.g. `accounts`). */
51
+ modelName: string;
52
+ /** Optional `class_name` override from the schema (naming input). */
53
+ className?: string;
54
+ /**
55
+ * Record fields with required-ness already resolved (schema `required`,
56
+ * `id` auto-assign, and op-params inference #842 folded in). Rendered into a
57
+ * struct/interface member per field.
58
+ */
59
+ fields: RecordField[];
60
+ }
61
+ /** One operation on a database type, naming-neutral. */
62
+ export interface DbOpIR {
63
+ /** Exact operation name (the `executeOperation` string argument). */
64
+ opName: string;
65
+ /** Operation type (`query|mutation|count|aggregate|pipeline|applyToQuery`). */
66
+ opType: string;
67
+ /** Declared input params (sorted by name), write shape. */
68
+ params: ParamField[];
69
+ /** Whether the op declares any params (a param-less op is callable bare). */
70
+ hasParams: boolean;
71
+ /**
72
+ * For a `query` op, the model its result rows are typed over — or null when
73
+ * the op has no model or the model has no record schema (the result falls
74
+ * back to an open/untyped row).
75
+ */
76
+ resultModelName: string | null;
77
+ /** For a `query` op, how its static `projection` narrows the record (#1439). */
78
+ projection?: ProjectionClassification;
79
+ /** For a `pipeline` op, the resolved `return`-step shape (#1437). */
80
+ pipelineReturn?: PipelineReturnIR;
81
+ }
82
+ /**
83
+ * One realtime subscription on a database type (#1544 Phase 2), naming-neutral.
84
+ *
85
+ * `modelName` is guaranteed to name a model that has a record schema on this
86
+ * type (`describeDbType` throws otherwise — a subscription can't be typed
87
+ * against a model the type doesn't declare; matches the server's
88
+ * `modelName is required` create validation). `select` fields, when present,
89
+ * are each guaranteed to be a known member of that record (declared field or
90
+ * stamped field) unless the record is the open `Record<string, unknown>` form,
91
+ * so the renderer can emit a valid `Pick<Record, …>` without a further guard.
92
+ */
93
+ export interface DbSubscriptionIR {
94
+ /** Subscription key (the `subscribe()` string argument). */
95
+ subscriptionKey: string;
96
+ /** Model whose record type binds the delivered change payload. */
97
+ modelName: string;
98
+ /**
99
+ * Projected field names when the subscription declares `select` (→ the event
100
+ * record narrows to `Pick<Record, …fields>`), else null (→ the full record).
101
+ * Sorted + de-duplicated for deterministic output.
102
+ */
103
+ select: string[] | null;
104
+ }
105
+ /** The shared, naming-neutral descriptor of one database type. */
106
+ export interface DbTypeIR {
107
+ /** Database type name (drives the output filename). */
108
+ databaseType: string;
109
+ /** Content fingerprint stamped in the generated header. */
110
+ fingerprint: string;
111
+ /** Server-stamped field names appended as OPTIONAL props on every record. */
112
+ stampedFields: string[];
113
+ /** Record models (schema order; renderers sort by their own type name). */
114
+ records: DbRecordIR[];
115
+ /** Operations, sorted by op name for deterministic output. */
116
+ ops: DbOpIR[];
117
+ /** Subscriptions, sorted by subscription key for deterministic output. */
118
+ subscriptions: DbSubscriptionIR[];
119
+ }
120
+ /**
121
+ * Resolve a database-type TOML into the shared, naming-neutral IR. Pure: no
122
+ * I/O beyond parsing the passed content. Both the TS and Swift renderers call
123
+ * this so their op/record metadata can never diverge.
124
+ */
125
+ export declare function describeDbType(input: DbCodegenInput): DbTypeIR;
126
+ /**
127
+ * Infer the scalar element type for op params consumed by a `$in`/`$nin`
128
+ * filter operator (#1488). See the original doc in `dbGenerator.ts` — moved
129
+ * here unchanged. Returns a map of param name → element TS type
130
+ * (`"unknown"` sentinel → widen to an untyped element).
131
+ */
132
+ export declare function inferArrayParamElementTypes(op: any, fieldTypesByModel: Map<string, Map<string, string>>): Map<string, string>;
133
+ /**
134
+ * Per-model result of {@link inferRequiredRecordFields}. Shaped as an object so
135
+ * it can grow additional inferred metadata later without changing callers.
136
+ */
137
+ export interface InferredRecordModelInfo {
138
+ /** Record field names promoted to non-optional by op-params inference. */
139
+ fields: Set<string>;
140
+ }
141
+ /**
142
+ * Infer which record fields are always supplied at create time from `save` op
143
+ * params (#842). See the original doc in `dbGenerator.ts` — moved here
144
+ * unchanged.
145
+ */
146
+ export declare function inferRequiredRecordFields(operations: any[]): Map<string, InferredRecordModelInfo>;