@zenstackhq/server 3.5.5 → 3.6.0

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 (105) hide show
  1. package/dist/api.cjs +2729 -4451
  2. package/dist/api.cjs.map +1 -1
  3. package/dist/api.d.cts +219 -207
  4. package/dist/api.d.mts +249 -0
  5. package/dist/api.mjs +2745 -0
  6. package/dist/api.mjs.map +1 -0
  7. package/dist/common-BjzwQE8S.d.mts +16 -0
  8. package/dist/common-Cdj4rLFr.mjs +9 -0
  9. package/dist/common-Cdj4rLFr.mjs.map +1 -0
  10. package/dist/common-D2RyWTAZ.cjs +14 -0
  11. package/dist/common-D2RyWTAZ.cjs.map +1 -0
  12. package/dist/common-D3fx-IHt.d.cts +16 -0
  13. package/dist/elysia.cjs +46 -114
  14. package/dist/elysia.cjs.map +1 -1
  15. package/dist/elysia.d.cts +37 -36
  16. package/dist/elysia.d.mts +54 -0
  17. package/dist/elysia.mjs +48 -0
  18. package/dist/elysia.mjs.map +1 -0
  19. package/dist/express.cjs +40 -110
  20. package/dist/express.cjs.map +1 -1
  21. package/dist/express.d.cts +21 -20
  22. package/dist/express.d.mts +32 -0
  23. package/dist/express.mjs +42 -0
  24. package/dist/express.mjs.map +1 -0
  25. package/dist/fastify.cjs +36 -100
  26. package/dist/fastify.cjs.map +1 -1
  27. package/dist/fastify.d.cts +15 -14
  28. package/dist/fastify.d.mts +23 -0
  29. package/dist/fastify.mjs +36 -0
  30. package/dist/fastify.mjs.map +1 -0
  31. package/dist/hono.cjs +31 -108
  32. package/dist/hono.cjs.map +1 -1
  33. package/dist/hono.d.cts +11 -10
  34. package/dist/hono.d.mts +19 -0
  35. package/dist/hono.mjs +33 -0
  36. package/dist/hono.mjs.map +1 -0
  37. package/dist/next.cjs +81 -169
  38. package/dist/next.cjs.map +1 -1
  39. package/dist/next.d.cts +32 -29
  40. package/dist/{next.d.ts → next.d.mts} +32 -29
  41. package/dist/next.mjs +86 -0
  42. package/dist/next.mjs.map +1 -0
  43. package/dist/nuxt.cjs +414 -104
  44. package/dist/nuxt.cjs.map +1 -1
  45. package/dist/nuxt.d.cts +538 -12
  46. package/dist/nuxt.d.mts +545 -0
  47. package/dist/nuxt.mjs +416 -0
  48. package/dist/nuxt.mjs.map +1 -0
  49. package/dist/openapi-BPFL4Hn6.mjs +585 -0
  50. package/dist/openapi-BPFL4Hn6.mjs.map +1 -0
  51. package/dist/openapi-BUzfCKi-.cjs +586 -0
  52. package/dist/openapi-BUzfCKi-.cjs.map +1 -0
  53. package/dist/spec-utils-C7vlChMD.cjs +278 -0
  54. package/dist/spec-utils-C7vlChMD.cjs.map +1 -0
  55. package/dist/spec-utils-Syk4SLCX.mjs +200 -0
  56. package/dist/spec-utils-Syk4SLCX.mjs.map +1 -0
  57. package/dist/sveltekit.cjs +87 -188
  58. package/dist/sveltekit.cjs.map +1 -1
  59. package/dist/sveltekit.d.cts +24 -22
  60. package/dist/sveltekit.d.mts +43 -0
  61. package/dist/sveltekit.mjs +88 -0
  62. package/dist/sveltekit.mjs.map +1 -0
  63. package/dist/tanstack-start.cjs +59 -133
  64. package/dist/tanstack-start.cjs.map +1 -1
  65. package/dist/tanstack-start.d.cts +19 -14
  66. package/dist/tanstack-start.d.mts +37 -0
  67. package/dist/tanstack-start.mjs +60 -0
  68. package/dist/tanstack-start.mjs.map +1 -0
  69. package/dist/types-6NFtxov5.d.mts +74 -0
  70. package/dist/types-DYdFPTkH.d.cts +74 -0
  71. package/dist/utils-B9NX7OcP.cjs +85 -0
  72. package/dist/utils-B9NX7OcP.cjs.map +1 -0
  73. package/dist/utils-Doc_CQNd.mjs +39 -0
  74. package/dist/utils-Doc_CQNd.mjs.map +1 -0
  75. package/package.json +28 -27
  76. package/dist/api.d.ts +0 -237
  77. package/dist/api.js +0 -4437
  78. package/dist/api.js.map +0 -1
  79. package/dist/common-Cuu8bjzK.d.cts +0 -14
  80. package/dist/common-WHbiInuf.d.ts +0 -14
  81. package/dist/elysia.d.ts +0 -53
  82. package/dist/elysia.js +0 -82
  83. package/dist/elysia.js.map +0 -1
  84. package/dist/express.d.ts +0 -31
  85. package/dist/express.js +0 -78
  86. package/dist/express.js.map +0 -1
  87. package/dist/fastify.d.ts +0 -22
  88. package/dist/fastify.js +0 -68
  89. package/dist/fastify.js.map +0 -1
  90. package/dist/hono.d.ts +0 -18
  91. package/dist/hono.js +0 -76
  92. package/dist/hono.js.map +0 -1
  93. package/dist/next.js +0 -140
  94. package/dist/next.js.map +0 -1
  95. package/dist/nuxt.d.ts +0 -19
  96. package/dist/nuxt.js +0 -73
  97. package/dist/nuxt.js.map +0 -1
  98. package/dist/sveltekit.d.ts +0 -41
  99. package/dist/sveltekit.js +0 -156
  100. package/dist/sveltekit.js.map +0 -1
  101. package/dist/tanstack-start.d.ts +0 -32
  102. package/dist/tanstack-start.js +0 -104
  103. package/dist/tanstack-start.js.map +0 -1
  104. package/dist/types-CU_PWKr9.d.cts +0 -72
  105. package/dist/types-CU_PWKr9.d.ts +0 -72
@@ -0,0 +1,585 @@
1
+ import { c as isOperationIncluded, d as PROCEDURE_ROUTE_PREFIXES, i as getMetaDescription, l as isProcedureIncluded, r as getIncludedModels, u as mayDenyAccess } from "./spec-utils-Syk4SLCX.mjs";
2
+ import { lowerCaseFirst, upperCaseFirst } from "@zenstackhq/common-helpers";
3
+ import { CoreCrudOperations, createQuerySchemaFactory } from "@zenstackhq/orm";
4
+ //#region src/api/rpc/openapi.ts
5
+ const GET_OPERATIONS = new Set([
6
+ "findFirst",
7
+ "findUnique",
8
+ "findMany",
9
+ "aggregate",
10
+ "groupBy",
11
+ "count",
12
+ "exists"
13
+ ]);
14
+ const POST_OPERATIONS = new Set([
15
+ "create",
16
+ "createMany",
17
+ "createManyAndReturn",
18
+ "upsert"
19
+ ]);
20
+ const PUT_OPERATIONS = new Set([
21
+ "update",
22
+ "updateMany",
23
+ "updateManyAndReturn"
24
+ ]);
25
+ const DELETE_OPERATIONS = new Set(["delete", "deleteMany"]);
26
+ const JSON_CT = "application/json";
27
+ /**
28
+ * Per-operation metadata: human-readable summary and response data schema shape.
29
+ * Operations absent from this map (aggregate, groupBy, count) return a generic schema.
30
+ */
31
+ const OPERATION_INFO = {
32
+ findUnique: {
33
+ summary: (m) => `Find a unique ${m}`,
34
+ dataSchema: (ref) => ({ anyOf: [ref, { type: "null" }] })
35
+ },
36
+ findFirst: {
37
+ summary: (m) => `Find the first ${m}`,
38
+ dataSchema: (ref) => ({ anyOf: [ref, { type: "null" }] })
39
+ },
40
+ findMany: {
41
+ summary: (m) => `List ${m} entities`,
42
+ dataSchema: (ref) => ({
43
+ type: "array",
44
+ items: ref
45
+ })
46
+ },
47
+ create: {
48
+ summary: (m) => `Create a ${m}`,
49
+ dataSchema: (ref) => ref
50
+ },
51
+ createMany: {
52
+ summary: (m) => `Create multiple ${m} entities`,
53
+ dataSchema: () => ({
54
+ type: "object",
55
+ properties: { count: { type: "integer" } },
56
+ required: ["count"]
57
+ })
58
+ },
59
+ createManyAndReturn: {
60
+ summary: (m) => `Create multiple ${m}s and return them`,
61
+ dataSchema: (ref) => ({
62
+ type: "array",
63
+ items: ref
64
+ })
65
+ },
66
+ update: {
67
+ summary: (m) => `Update a ${m}`,
68
+ dataSchema: (ref) => ref
69
+ },
70
+ updateMany: {
71
+ summary: (m) => `Update multiple ${m} entities`,
72
+ dataSchema: () => ({
73
+ type: "object",
74
+ properties: { count: { type: "integer" } },
75
+ required: ["count"]
76
+ })
77
+ },
78
+ updateManyAndReturn: {
79
+ summary: (m) => `Update multiple ${m} entities and return them`,
80
+ dataSchema: (ref) => ({
81
+ type: "array",
82
+ items: ref
83
+ })
84
+ },
85
+ upsert: {
86
+ summary: (m) => `Upsert a ${m}`,
87
+ dataSchema: (ref) => ref
88
+ },
89
+ delete: {
90
+ summary: (m) => `Delete a ${m}`,
91
+ dataSchema: (ref) => ref
92
+ },
93
+ deleteMany: {
94
+ summary: (m) => `Delete multiple ${m} entities`,
95
+ dataSchema: () => ({
96
+ type: "object",
97
+ properties: { count: { type: "integer" } },
98
+ required: ["count"]
99
+ })
100
+ },
101
+ exists: {
102
+ summary: (m) => `Check ${m} existence`,
103
+ dataSchema: () => ({ type: "boolean" })
104
+ }
105
+ };
106
+ function errorResponse(description) {
107
+ return {
108
+ description,
109
+ content: { [JSON_CT]: { schema: { $ref: "#/components/schemas/_rpcErrorResponse" } } }
110
+ };
111
+ }
112
+ const ERROR_400 = errorResponse("Error occurred while processing the request");
113
+ const ERROR_403 = errorResponse("Forbidden: insufficient permissions to perform this operation");
114
+ const ERROR_404 = errorResponse("Resource not found");
115
+ const ERROR_422 = errorResponse("Operation is unprocessable due to validation errors");
116
+ const ERROR_500 = errorResponse("Internal server error");
117
+ const NOT_FOUND_OPERATIONS = new Set(["update", "delete"]);
118
+ /**
119
+ * Generates an OpenAPI v3.1 specification for the RPC-style API handler.
120
+ */
121
+ var RPCApiSpecGenerator = class {
122
+ specOptions;
123
+ factory;
124
+ /**
125
+ * Schemas extracted from the Zod registry, keyed by their registered ID, with
126
+ * all `$ref` values already rewritten to `#/components/schemas/<id>`.
127
+ */
128
+ registrySchemas = {};
129
+ constructor(handlerOptions) {
130
+ this.handlerOptions = handlerOptions;
131
+ this.factory = createQuerySchemaFactory(handlerOptions.schema, handlerOptions.queryOptions);
132
+ }
133
+ get schema() {
134
+ return this.handlerOptions.schema;
135
+ }
136
+ get queryOptions() {
137
+ return this.handlerOptions?.queryOptions;
138
+ }
139
+ generateSpec(options) {
140
+ this.specOptions = options;
141
+ const rawRegistry = this.factory.toJSONSchema();
142
+ this.registrySchemas = this.transformRegistrySchemas(rawRegistry.schemas);
143
+ return {
144
+ openapi: "3.1.0",
145
+ info: {
146
+ title: options?.title ?? "ZenStack Generated API",
147
+ version: options?.version ?? "1.0.0",
148
+ ...options?.description && { description: options.description },
149
+ ...options?.summary && { summary: options.summary }
150
+ },
151
+ tags: this.generateTags(),
152
+ paths: this.generatePaths(),
153
+ components: { schemas: {
154
+ ...this.registrySchemas,
155
+ ...this.generateSharedSchemas()
156
+ } }
157
+ };
158
+ }
159
+ /**
160
+ * Takes the raw `schemas` map from `z.toJSONSchema(registry)` and:
161
+ * 1. Rewrites bare-ID `$ref` values (e.g. `"UserWhereInput"`) to full
162
+ * component paths (`"#/components/schemas/UserWhereInput"`).
163
+ * 2. Strips the `$schema` keyword from each top-level schema object, as it
164
+ * is redundant inside an OpenAPI document.
165
+ * 3. Resolves Zod's auto-generated `__shared/$defs/schemaN` aliases.
166
+ * When a `__shared/$defs/schemaN` entry is itself a plain `$ref` to a
167
+ * named schema, every reference to it is rewritten to point directly at
168
+ * the target schema, removing the double indirection. Any remaining
169
+ * `__shared` entries (complex shared sub-schemas) are promoted to
170
+ * top-level component schemas with stable names.
171
+ */
172
+ transformRegistrySchemas(schemas) {
173
+ let result;
174
+ const serialized = JSON.stringify(schemas).replace(/"(\$ref)":"([^"#][^"]*)"/g, (_, key, id) => `"${key}":"#/components/schemas/${id}"`).replaceAll("{\"type\":\"integer\",\"minimum\":0,\"maximum\":9007199254740991}", "{\"$ref\":\"#/components/schemas/_nonNegativeInteger\"}").replaceAll("{\"type\":\"integer\",\"minimum\":-9007199254740991,\"maximum\":9007199254740991}", "{\"$ref\":\"#/components/schemas/_integer\"}");
175
+ result = JSON.parse(serialized);
176
+ const shared = result["__shared"];
177
+ if (shared?.$defs) {
178
+ const refMap = {};
179
+ const promoted = {};
180
+ for (const [key, entry] of Object.entries(shared.$defs)) {
181
+ const sharedRef = `#/components/schemas/__shared#/$defs/${key}`;
182
+ if (entry && typeof entry === "object" && "$ref" in entry && Object.keys(entry).length === 1) refMap[sharedRef] = entry.$ref;
183
+ else {
184
+ const promotedName = `_shared_${key}`;
185
+ promoted[promotedName] = entry;
186
+ refMap[sharedRef] = `#/components/schemas/${promotedName}`;
187
+ }
188
+ }
189
+ if (Object.keys(refMap).length > 0) {
190
+ const escapedKeys = Object.keys(refMap).map((k) => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
191
+ const pattern = new RegExp(`"\\$ref":"(${escapedKeys.join("|")})"`, "g");
192
+ const resolved = JSON.stringify(result).replace(pattern, (_, ref) => `"$ref":"${refMap[ref]}"`);
193
+ result = JSON.parse(resolved);
194
+ delete result["__shared"];
195
+ Object.assign(result, promoted);
196
+ }
197
+ }
198
+ for (const s of Object.values(result)) if (s && typeof s === "object") delete s["$schema"];
199
+ return result;
200
+ }
201
+ generateTags() {
202
+ return getIncludedModels(this.schema, this.queryOptions).map((modelName) => ({
203
+ name: lowerCaseFirst(modelName),
204
+ description: `${modelName} operations`
205
+ }));
206
+ }
207
+ generatePaths() {
208
+ const paths = {};
209
+ for (const modelName of getIncludedModels(this.schema, this.queryOptions)) {
210
+ const modelDef = this.schema.models[modelName];
211
+ const tag = lowerCaseFirst(modelName);
212
+ for (const op of CoreCrudOperations) {
213
+ if (!isOperationIncluded(modelName, op, this.queryOptions)) continue;
214
+ const method = this.getHttpMethod(op);
215
+ const operation = this.buildModelOperation(modelName, modelDef, op, tag);
216
+ paths[`/${lowerCaseFirst(modelName)}/${op}`] = { [method]: operation };
217
+ }
218
+ }
219
+ if (this.schema.procedures) for (const [procName, procDef] of Object.entries(this.schema.procedures)) {
220
+ if (!isProcedureIncluded(procName, this.queryOptions)) continue;
221
+ const method = procDef.mutation ? "post" : "get";
222
+ paths[`/${PROCEDURE_ROUTE_PREFIXES}/${procName}`] = { [method]: this.buildProcedureOperation(procName, procDef, method) };
223
+ }
224
+ paths["/$transaction/sequential"] = { post: this.buildTransactionOperation() };
225
+ return paths;
226
+ }
227
+ getHttpMethod(op) {
228
+ if (GET_OPERATIONS.has(op)) return "get";
229
+ if (POST_OPERATIONS.has(op)) return "post";
230
+ if (PUT_OPERATIONS.has(op)) return "put";
231
+ if (DELETE_OPERATIONS.has(op)) return "delete";
232
+ return "post";
233
+ }
234
+ /**
235
+ * Returns a JSON Schema `$ref` pointing to the pre-built component schema for
236
+ * the given model+operation, or `undefined` if the schema was not registered
237
+ * (e.g. the operation is not supported for that model).
238
+ */
239
+ getOperationInputSchemaRef(modelName, op) {
240
+ const id = `${modelName}${upperCaseFirst(op)}Args`;
241
+ return id in this.registrySchemas ? { $ref: `#/components/schemas/${id}` } : void 0;
242
+ }
243
+ /**
244
+ * Maps an RPC operation name to its corresponding access policy operation type.
245
+ * Policy attributes use 'read', 'create', 'update', 'delete', 'all'.
246
+ */
247
+ policyOp(op) {
248
+ if (GET_OPERATIONS.has(op)) return "read";
249
+ if (DELETE_OPERATIONS.has(op)) return "delete";
250
+ if (PUT_OPERATIONS.has(op)) return "update";
251
+ return "create";
252
+ }
253
+ buildModelOperation(modelName, modelDef, op, tag) {
254
+ const isQueryOp = GET_OPERATIONS.has(op) || DELETE_OPERATIONS.has(op);
255
+ const successCode = POST_OPERATIONS.has(op) ? "201" : "200";
256
+ const inputSchemaRef = this.getOperationInputSchemaRef(modelName, op);
257
+ const operation = {
258
+ tags: [tag],
259
+ summary: OPERATION_INFO[op]?.summary(modelName) ?? `${modelName}.${op}`,
260
+ operationId: `${lowerCaseFirst(modelName)}_${op}`,
261
+ responses: {
262
+ [successCode]: {
263
+ description: "Operation succeeded",
264
+ content: { [JSON_CT]: { schema: this.buildOperationSuccessSchema(modelName, op) } }
265
+ },
266
+ "400": ERROR_400,
267
+ ...NOT_FOUND_OPERATIONS.has(op) && { "404": ERROR_404 },
268
+ "422": ERROR_422,
269
+ "500": ERROR_500,
270
+ ...mayDenyAccess(modelDef, this.policyOp(op), this.specOptions?.respectAccessPolicies) && { "403": ERROR_403 }
271
+ }
272
+ };
273
+ if (inputSchemaRef) if (isQueryOp) {
274
+ const inputSchemaId = `${modelName}${upperCaseFirst(op)}Args`;
275
+ const inputSchema = this.registrySchemas[inputSchemaId];
276
+ operation["parameters"] = [{
277
+ name: "q",
278
+ in: "query",
279
+ ...Array.isArray(inputSchema?.required) && inputSchema.required.length > 0 && { required: true },
280
+ description: `JSON-encoded arguments for ${modelName}.${op}`,
281
+ content: { [JSON_CT]: { schema: inputSchemaRef } }
282
+ }, {
283
+ name: "meta",
284
+ in: "query",
285
+ description: "JSON-encoded SuperJSON serialization metadata for the \"q\" parameter",
286
+ schema: { type: "string" }
287
+ }];
288
+ } else operation["requestBody"] = {
289
+ required: true,
290
+ content: { [JSON_CT]: { schema: inputSchemaRef } }
291
+ };
292
+ return operation;
293
+ }
294
+ buildProcedureOperation(procName, procDef, method) {
295
+ const argsSchemaId = `${procName}ProcArgs`;
296
+ const argsSchemaRef = argsSchemaId in this.registrySchemas ? { $ref: `#/components/schemas/${argsSchemaId}` } : { type: "object" };
297
+ const hasRequiredParams = Object.values(procDef.params ?? {}).some((p) => !p.optional);
298
+ const envelopeSchema = {
299
+ type: "object",
300
+ properties: { args: argsSchemaRef },
301
+ ...hasRequiredParams && { required: ["args"] }
302
+ };
303
+ const op = {
304
+ tags: ["$procs"],
305
+ summary: `Execute procedure \`${procName}\``,
306
+ operationId: `proc_${procName}`,
307
+ responses: {
308
+ "200": {
309
+ description: `Result of ${procName}`,
310
+ content: { [JSON_CT]: { schema: {
311
+ type: "object",
312
+ properties: {
313
+ data: this.getProcedureDataSchema(procDef),
314
+ meta: {
315
+ type: "object",
316
+ properties: { serialization: {} }
317
+ }
318
+ }
319
+ } } }
320
+ },
321
+ "400": ERROR_400,
322
+ "403": ERROR_403,
323
+ "404": ERROR_404,
324
+ "422": ERROR_422,
325
+ "500": ERROR_500
326
+ }
327
+ };
328
+ const hasParams = Object.keys(procDef.params ?? {}).length > 0;
329
+ if (method === "get") {
330
+ if (hasParams) op["parameters"] = [{
331
+ name: "q",
332
+ in: "query",
333
+ ...hasRequiredParams && { required: true },
334
+ description: `JSON-encoded arguments for procedure ${procName}`,
335
+ content: { [JSON_CT]: { schema: envelopeSchema } }
336
+ }, {
337
+ name: "meta",
338
+ in: "query",
339
+ description: "JSON-encoded SuperJSON serialization metadata for the \"q\" parameter",
340
+ schema: { type: "string" }
341
+ }];
342
+ } else if (hasParams) op["requestBody"] = {
343
+ ...hasRequiredParams && { required: true },
344
+ content: { [JSON_CT]: { schema: envelopeSchema } }
345
+ };
346
+ return op;
347
+ }
348
+ getProcedureDataSchema(procDef) {
349
+ const { returnType, returnArray } = procDef;
350
+ let base;
351
+ if (this.isBuiltinType(returnType)) base = this.builtinTypeToJsonSchema(returnType);
352
+ else if (this.schema.enums?.[returnType] || this.schema.models?.[returnType] || this.schema.typeDefs?.[returnType]) base = { $ref: `#/components/schemas/${returnType}` };
353
+ else base = {};
354
+ return returnArray ? {
355
+ type: "array",
356
+ items: base
357
+ } : base;
358
+ }
359
+ buildTransactionOperation() {
360
+ return {
361
+ tags: ["$transaction"],
362
+ summary: "Execute a sequential transaction",
363
+ operationId: "transaction_sequential",
364
+ requestBody: {
365
+ required: true,
366
+ content: { [JSON_CT]: { schema: { $ref: "#/components/schemas/_rpcTransactionRequest" } } }
367
+ },
368
+ responses: {
369
+ "200": {
370
+ description: "Transaction succeeded",
371
+ content: { [JSON_CT]: { schema: { $ref: "#/components/schemas/_rpcSuccessResponse" } } }
372
+ },
373
+ "400": ERROR_400,
374
+ "403": ERROR_403,
375
+ "404": ERROR_404,
376
+ "422": ERROR_422,
377
+ "500": ERROR_500
378
+ }
379
+ };
380
+ }
381
+ generateSharedSchemas() {
382
+ const enumSchemas = {};
383
+ for (const [enumName, enumDef] of Object.entries(this.schema.enums ?? {})) enumSchemas[enumName] = this.buildEnumSchema(enumDef);
384
+ const typeDefSchemas = {};
385
+ for (const [typeName, typeDef] of Object.entries(this.schema.typeDefs ?? {})) typeDefSchemas[typeName] = this.buildTypeDefSchema(typeDef);
386
+ const modelEntitySchemas = {};
387
+ for (const modelName of getIncludedModels(this.schema, this.queryOptions)) modelEntitySchemas[modelName] = this.buildModelEntitySchema(this.schema.models[modelName]);
388
+ return {
389
+ ...enumSchemas,
390
+ ...typeDefSchemas,
391
+ ...modelEntitySchemas,
392
+ _integer: {
393
+ type: "integer",
394
+ minimum: -9007199254740991,
395
+ maximum: 9007199254740991
396
+ },
397
+ _nonNegativeInteger: {
398
+ type: "integer",
399
+ minimum: 0,
400
+ maximum: 9007199254740991
401
+ },
402
+ _rpcSuccessResponse: {
403
+ type: "object",
404
+ properties: {
405
+ data: {},
406
+ meta: {
407
+ type: "object",
408
+ properties: { serialization: {} }
409
+ }
410
+ }
411
+ },
412
+ _rpcErrorResponse: {
413
+ type: "object",
414
+ properties: { error: {
415
+ type: "object",
416
+ properties: {
417
+ message: { type: "string" },
418
+ reason: { type: "string" },
419
+ model: { type: "string" },
420
+ rejectedByPolicy: { type: "boolean" },
421
+ rejectedByValidation: { type: "boolean" },
422
+ rejectReason: { type: "string" },
423
+ dbErrorCode: { type: "string" }
424
+ },
425
+ required: ["message"]
426
+ } },
427
+ required: ["error"]
428
+ },
429
+ _rpcTransactionRequest: {
430
+ type: "array",
431
+ items: {
432
+ type: "object",
433
+ properties: {
434
+ model: { type: "string" },
435
+ op: {
436
+ type: "string",
437
+ enum: [...CoreCrudOperations]
438
+ },
439
+ args: { type: "object" }
440
+ },
441
+ required: ["model", "op"]
442
+ }
443
+ }
444
+ };
445
+ }
446
+ builtinTypeToJsonSchema(type) {
447
+ switch (type) {
448
+ case "String": return { type: "string" };
449
+ case "Boolean": return { type: "boolean" };
450
+ case "Int": return { type: "integer" };
451
+ case "Float": return { type: "number" };
452
+ case "BigInt": return { type: "integer" };
453
+ case "Decimal": return { type: "string" };
454
+ case "DateTime": return {
455
+ type: "string",
456
+ format: "date-time"
457
+ };
458
+ case "Bytes": return {
459
+ type: "string",
460
+ format: "byte"
461
+ };
462
+ default: return {};
463
+ }
464
+ }
465
+ isBuiltinType(type) {
466
+ return [
467
+ "String",
468
+ "Boolean",
469
+ "Int",
470
+ "Float",
471
+ "BigInt",
472
+ "Decimal",
473
+ "DateTime",
474
+ "Bytes",
475
+ "Json",
476
+ "Unsupported"
477
+ ].includes(type);
478
+ }
479
+ /**
480
+ * Builds a JSON Schema object describing a custom typedef
481
+ */
482
+ buildEnumSchema(enumDef) {
483
+ return {
484
+ type: "string",
485
+ enum: Object.values(enumDef.values)
486
+ };
487
+ }
488
+ buildTypeDefSchema(typeDef) {
489
+ const properties = {};
490
+ const required = [];
491
+ for (const [fieldName, fieldDef] of Object.entries(typeDef.fields)) {
492
+ const isRef = !this.isBuiltinType(fieldDef.type) && (this.schema.enums?.[fieldDef.type] || this.schema.typeDefs?.[fieldDef.type]);
493
+ const base = this.isBuiltinType(fieldDef.type) ? this.builtinTypeToJsonSchema(fieldDef.type) : isRef ? { $ref: `#/components/schemas/${fieldDef.type}` } : { type: "object" };
494
+ const fieldDesc = getMetaDescription(fieldDef.attributes);
495
+ if (fieldDesc && !isRef) base.description = fieldDesc;
496
+ const typed = fieldDef.array ? {
497
+ type: "array",
498
+ items: base
499
+ } : base;
500
+ properties[fieldName] = fieldDef.optional ? { anyOf: [typed, { type: "null" }] } : typed;
501
+ if (!fieldDef.optional) required.push(fieldName);
502
+ }
503
+ const schema = {
504
+ type: "object",
505
+ properties
506
+ };
507
+ if (required.length > 0) schema["required"] = required;
508
+ return schema;
509
+ }
510
+ /**
511
+ * Builds a JSON Schema object describing a model entity
512
+ */
513
+ buildModelEntitySchema(modelDef) {
514
+ const properties = {};
515
+ const required = [];
516
+ for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
517
+ if (fieldDef.omit) continue;
518
+ if (fieldDef.relation) {
519
+ const refSchema = { $ref: `#/components/schemas/${fieldDef.type}` };
520
+ const base = fieldDef.array ? {
521
+ type: "array",
522
+ items: refSchema
523
+ } : refSchema;
524
+ properties[fieldName] = !fieldDef.array && fieldDef.optional ? { anyOf: [base, { type: "null" }] } : base;
525
+ } else if (this.schema.enums?.[fieldDef.type]) {
526
+ const refSchema = { $ref: `#/components/schemas/${fieldDef.type}` };
527
+ const base = fieldDef.array ? {
528
+ type: "array",
529
+ items: refSchema
530
+ } : refSchema;
531
+ properties[fieldName] = fieldDef.optional ? { anyOf: [base, { type: "null" }] } : base;
532
+ required.push(fieldName);
533
+ } else if (this.isBuiltinType(fieldDef.type)) {
534
+ const base = this.builtinTypeToJsonSchema(fieldDef.type);
535
+ const fieldDesc = getMetaDescription(fieldDef.attributes);
536
+ if (fieldDesc) base.description = fieldDesc;
537
+ const typed = fieldDef.array ? {
538
+ type: "array",
539
+ items: base
540
+ } : base;
541
+ properties[fieldName] = fieldDef.optional ? { anyOf: [typed, { type: "null" }] } : typed;
542
+ required.push(fieldName);
543
+ } else if (this.schema.typeDefs?.[fieldDef.type]) {
544
+ const refSchema = { $ref: `#/components/schemas/${fieldDef.type}` };
545
+ const base = fieldDef.array ? {
546
+ type: "array",
547
+ items: refSchema
548
+ } : refSchema;
549
+ properties[fieldName] = fieldDef.optional ? { anyOf: [base, { type: "null" }] } : base;
550
+ required.push(fieldName);
551
+ } else {
552
+ properties[fieldName] = fieldDef.array ? {
553
+ type: "array",
554
+ items: { type: "object" }
555
+ } : { type: "object" };
556
+ required.push(fieldName);
557
+ }
558
+ }
559
+ const schema = {
560
+ type: "object",
561
+ properties
562
+ };
563
+ if (required.length > 0) schema["required"] = required;
564
+ const modelDesc = getMetaDescription(modelDef.attributes);
565
+ if (modelDesc) schema.description = modelDesc;
566
+ return schema;
567
+ }
568
+ buildOperationSuccessSchema(modelName, op) {
569
+ const entityRef = { $ref: `#/components/schemas/${modelName}` };
570
+ return {
571
+ type: "object",
572
+ properties: {
573
+ data: OPERATION_INFO[op]?.dataSchema(entityRef) ?? {},
574
+ meta: {
575
+ type: "object",
576
+ properties: { serialization: {} }
577
+ }
578
+ }
579
+ };
580
+ }
581
+ };
582
+ //#endregion
583
+ export { RPCApiSpecGenerator };
584
+
585
+ //# sourceMappingURL=openapi-BPFL4Hn6.mjs.map