@zenstackhq/server 3.5.6 → 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
package/dist/api.d.mts ADDED
@@ -0,0 +1,249 @@
1
+ import { i as Response, n as LogConfig, r as RequestContext, t as ApiHandler } from "./types-6NFtxov5.mjs";
2
+ import { QueryOptions } from "@zenstackhq/orm";
3
+ import { SchemaDef } from "@zenstackhq/orm/schema";
4
+ import * as _$openapi_types0 from "openapi-types";
5
+ import { OpenAPIV3_1 } from "openapi-types";
6
+
7
+ //#region src/api/common/types.d.ts
8
+ type CommonHandlerOptions<Schema extends SchemaDef> = {
9
+ /** Query options that affect the behavior of the OpenAPI provider. */queryOptions?: QueryOptions<Schema>;
10
+ };
11
+ type OpenApiSpecOptions = {
12
+ /** Spec title. Defaults to 'ZenStack Generated API' */title?: string; /** Spec version. Defaults to '1.0.0' */
13
+ version?: string; /** Spec description. */
14
+ description?: string; /** Spec summary. */
15
+ summary?: string;
16
+ /**
17
+ * When true, assumes that the schema includes access policies, and adds
18
+ * 403 responses to operations that can potentially be rejected.
19
+ */
20
+ respectAccessPolicies?: boolean;
21
+ };
22
+ /**
23
+ * Interface for generating OpenAPI specifications.
24
+ */
25
+ interface OpenApiSpecGenerator {
26
+ /**
27
+ * Generates an OpenAPI v3.1 specification document.
28
+ */
29
+ generateSpec(options?: OpenApiSpecOptions): Promise<OpenAPIV3_1.Document>;
30
+ }
31
+ //#endregion
32
+ //#region src/api/rest/index.d.ts
33
+ /**
34
+ * Options for {@link RestApiHandler}
35
+ */
36
+ type RestApiHandlerOptions<Schema extends SchemaDef = SchemaDef> = {
37
+ /**
38
+ * The schema
39
+ */
40
+ schema: Schema;
41
+ /**
42
+ * Logging configuration
43
+ */
44
+ log?: LogConfig;
45
+ /**
46
+ * The base endpoint of the RESTful API, must be a valid URL
47
+ */
48
+ endpoint: string;
49
+ /**
50
+ * The default page size for limiting the number of results returned
51
+ * from collection queries, including resource collection, related data
52
+ * of collection types, and relationship of collection types.
53
+ *
54
+ * Defaults to 100. Set to Infinity to disable pagination.
55
+ */
56
+ pageSize?: number;
57
+ /**
58
+ * The divider used to separate compound ID fields in the URL.
59
+ * Defaults to '_'.
60
+ */
61
+ idDivider?: string;
62
+ /**
63
+ * The charset used for URL segment values. Defaults to `a-zA-Z0-9-_~ %`. You can change it if your entity's ID values
64
+ * allow different characters. Specifically, if your models use compound IDs and the idDivider is set to a different value,
65
+ * it should be included in the charset.
66
+ */
67
+ urlSegmentCharset?: string;
68
+ /**
69
+ * Mapping from model names to URL segment names.
70
+ */
71
+ modelNameMapping?: Record<string, string>;
72
+ /**
73
+ * Mapping from model names to unique field name to be used as resource's ID.
74
+ */
75
+ externalIdMapping?: Record<string, string>;
76
+ /**
77
+ * When `true`, enables nested route handling for all to-many relations:
78
+ * `/:parentType/:parentId/:relationName` (collection) and
79
+ * `/:parentType/:parentId/:relationName/:childId` (single).
80
+ *
81
+ * Defaults to `false`.
82
+ */
83
+ nestedRoutes?: boolean;
84
+ } & CommonHandlerOptions<Schema>;
85
+ /**
86
+ * RESTful-style API request handler (compliant with JSON:API)
87
+ */
88
+ declare class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements ApiHandler<Schema>, OpenApiSpecGenerator {
89
+ private readonly options;
90
+ private serializers;
91
+ private readonly errors;
92
+ private filterParamPattern;
93
+ private createUpdatePayloadSchema;
94
+ private updateSingleRelationSchema;
95
+ private updateCollectionRelationSchema;
96
+ private upsertMetaSchema;
97
+ private typeMap;
98
+ private idDivider;
99
+ private urlPatternMap;
100
+ private modelNameMapping;
101
+ private reverseModelNameMapping;
102
+ private externalIdMapping;
103
+ private nestedRoutes;
104
+ constructor(options: RestApiHandlerOptions<Schema>);
105
+ private validateOptions;
106
+ get schema(): Schema;
107
+ get log(): LogConfig | undefined;
108
+ private buildUrlPatternMap;
109
+ private mapModelName;
110
+ /**
111
+ * Resolves child model type and reverse relation from a parent relation name.
112
+ * e.g. given parentType='user', parentRelation='posts', returns { childType:'post', reverseRelation:'author' }
113
+ */
114
+ private resolveNestedRelation;
115
+ private mergeFilters;
116
+ /**
117
+ * Builds a WHERE filter for the child model that constrains results to those belonging to the given parent.
118
+ * @param parentType lowercased parent model name
119
+ * @param parentId parent resource ID string
120
+ * @param parentRelation relation field name on the parent model (e.g. 'posts')
121
+ */
122
+ private buildNestedParentFilter;
123
+ private matchUrlPattern;
124
+ handleRequest({
125
+ client,
126
+ method,
127
+ path,
128
+ query,
129
+ requestBody
130
+ }: RequestContext<Schema>): Promise<Response>;
131
+ private handleGenericError;
132
+ private processProcedureRequest;
133
+ private makeProcBadInputErrorResponse;
134
+ private makeProcGenericErrorResponse;
135
+ /**
136
+ * Builds the ORM `args` object (include, select) shared by single-read operations.
137
+ * Returns the args to pass to findUnique/findFirst and the resolved `include` list for serialization,
138
+ * or an error response if query params are invalid.
139
+ */
140
+ private buildSingleReadArgs;
141
+ private processSingleRead;
142
+ private processFetchRelated;
143
+ private processReadRelationship;
144
+ private processCollectionRead;
145
+ /**
146
+ * Builds link URL for a nested resource using parent type, parent ID, relation name, and optional child ID.
147
+ * Uses the parent model name mapping for the parent segment; the relation name is used as-is.
148
+ */
149
+ private makeNestedLinkUrl;
150
+ private processNestedSingleRead;
151
+ private processNestedCreate;
152
+ /**
153
+ * Builds the ORM `data` payload for a nested update, shared by both to-many (childId present)
154
+ * and to-one (childId absent) variants. Returns either `{ updateData }` or `{ error }`.
155
+ */
156
+ private buildNestedUpdatePayload;
157
+ /**
158
+ * Handles PATCH /:type/:id/:relationship/:childId (to-many) and
159
+ * PATCH /:type/:id/:relationship (to-one, childId undefined).
160
+ */
161
+ private processNestedUpdate;
162
+ private processNestedDelete;
163
+ private buildPartialSelect;
164
+ private addTotalCountToMeta;
165
+ private makePaginator;
166
+ private processRequestBody;
167
+ private processCreate;
168
+ private processUpsert;
169
+ private getUniqueFieldSets;
170
+ private processRelationshipCRUD;
171
+ private processUpdate;
172
+ private processDelete;
173
+ private requireModel;
174
+ private getIdFields;
175
+ private requireField;
176
+ private buildTypeMap;
177
+ private getModelInfo;
178
+ private makeLinkUrl;
179
+ private buildSerializers;
180
+ private getId;
181
+ private serializeItems;
182
+ private injectCompoundId;
183
+ private toPlainObject;
184
+ private replaceURLSearchParams;
185
+ private makeIdFilter;
186
+ private makeIdSelect;
187
+ private makeIdConnect;
188
+ private makeIdKey;
189
+ private makeDefaultIdKey;
190
+ private makeCompoundId;
191
+ private makeUpsertWhere;
192
+ private includeRelationshipIds;
193
+ private coerce;
194
+ private makeNormalizedUrl;
195
+ private getPagination;
196
+ private buildFilter;
197
+ private buildSort;
198
+ private buildRelationSelect;
199
+ private makeFilterValue;
200
+ private injectRelationQuery;
201
+ private handleORMError;
202
+ private makeError;
203
+ private makeUnsupportedModelError;
204
+ private makeUnsupportedRelationshipError;
205
+ generateSpec(options?: OpenApiSpecOptions): Promise<_$openapi_types0.OpenAPIV3_1.Document<{}>>;
206
+ }
207
+ //#endregion
208
+ //#region src/api/rpc/index.d.ts
209
+ /**
210
+ * Options for {@link RPCApiHandler}
211
+ */
212
+ type RPCApiHandlerOptions<Schema extends SchemaDef = SchemaDef> = {
213
+ /**
214
+ * The schema
215
+ */
216
+ schema: Schema;
217
+ /**
218
+ * Logging configuration
219
+ */
220
+ log?: LogConfig;
221
+ } & CommonHandlerOptions<Schema>;
222
+ /**
223
+ * RPC style API request handler that mirrors the ZenStackClient API
224
+ */
225
+ declare class RPCApiHandler<Schema extends SchemaDef = SchemaDef> implements ApiHandler<Schema>, OpenApiSpecGenerator {
226
+ private readonly options;
227
+ constructor(options: RPCApiHandlerOptions<Schema>);
228
+ private validateOptions;
229
+ get schema(): Schema;
230
+ get log(): LogConfig | undefined;
231
+ handleRequest({
232
+ client,
233
+ method,
234
+ path,
235
+ query,
236
+ requestBody
237
+ }: RequestContext<Schema>): Promise<Response>;
238
+ private handleTransaction;
239
+ private handleProcedureRequest;
240
+ private isValidModel;
241
+ private makeBadInputErrorResponse;
242
+ private makeGenericErrorResponse;
243
+ private makeORMErrorResponse;
244
+ generateSpec(options?: OpenApiSpecOptions): Promise<_$openapi_types0.OpenAPIV3_1.Document<{}>>;
245
+ private processRequestPayload;
246
+ }
247
+ //#endregion
248
+ export { type OpenApiSpecGenerator, type OpenApiSpecOptions, RPCApiHandler, type RPCApiHandlerOptions, RestApiHandler, type RestApiHandlerOptions };
249
+ //# sourceMappingURL=api.d.mts.map