@cosmneo/onion-lasagna 0.2.0 → 0.2.1
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.
- package/dist/{chunk-GGSAAZPM.js → chunk-AUMHMWDD.js} +19 -20
- package/dist/chunk-AUMHMWDD.js.map +1 -0
- package/dist/chunk-H5TNDC5U.js +138 -0
- package/dist/chunk-H5TNDC5U.js.map +1 -0
- package/dist/chunk-MF2JDREK.js +168 -0
- package/dist/chunk-MF2JDREK.js.map +1 -0
- package/dist/{chunk-PUVAB3JX.js → chunk-XIRJ73IO.js} +38 -36
- package/dist/chunk-XIRJ73IO.js.map +1 -0
- package/dist/{chunk-DS7TE6KZ.js → chunk-XP6PLTV2.js} +11 -3
- package/dist/chunk-XP6PLTV2.js.map +1 -0
- package/dist/global.js +3 -3
- package/dist/http/index.cjs +563 -93
- package/dist/http/index.cjs.map +1 -1
- package/dist/http/index.d.cts +4 -3
- package/dist/http/index.d.ts +4 -3
- package/dist/http/index.js +30 -12
- package/dist/http/openapi/index.cjs +43 -35
- package/dist/http/openapi/index.cjs.map +1 -1
- package/dist/http/openapi/index.d.cts +8 -34
- package/dist/http/openapi/index.d.ts +8 -34
- package/dist/http/openapi/index.js +2 -2
- package/dist/http/route/index.cjs +106 -9
- package/dist/http/route/index.cjs.map +1 -1
- package/dist/http/route/index.d.cts +133 -227
- package/dist/http/route/index.d.ts +133 -227
- package/dist/http/route/index.js +5 -2
- package/dist/http/server/index.cjs +24 -19
- package/dist/http/server/index.cjs.map +1 -1
- package/dist/http/server/index.d.cts +1 -1
- package/dist/http/server/index.d.ts +1 -1
- package/dist/http/server/index.js +2 -2
- package/dist/http/shared/index.cjs.map +1 -1
- package/dist/http/shared/index.d.cts +10 -14
- package/dist/http/shared/index.d.ts +10 -14
- package/dist/http/shared/index.js +11 -127
- package/dist/http/shared/index.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/{router-definition.type-ynBhT16T.d.cts → router-definition.type-BElX-Pl4.d.cts} +169 -256
- package/dist/{router-definition.type-DORVlLNk.d.ts → router-definition.type-DxG8ncJZ.d.ts} +169 -256
- package/package.json +1 -1
- package/dist/chunk-BZULBF4N.js +0 -82
- package/dist/chunk-BZULBF4N.js.map +0 -1
- package/dist/chunk-DS7TE6KZ.js.map +0 -1
- package/dist/chunk-GGSAAZPM.js.map +0 -1
- package/dist/chunk-PUVAB3JX.js.map +0 -1
|
@@ -125,10 +125,9 @@ declare function buildPath(template: string, params: Record<string, string>): st
|
|
|
125
125
|
declare function normalizePath(path: string): string;
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
* @fileoverview Core route definition types.
|
|
128
|
+
* @fileoverview Core route definition types (v2 — flat API).
|
|
129
129
|
*
|
|
130
|
-
*
|
|
131
|
-
* definition captures all information needed for:
|
|
130
|
+
* A route definition captures all information needed for:
|
|
132
131
|
* - Type-safe client generation
|
|
133
132
|
* - Server-side route registration with automatic validation
|
|
134
133
|
* - OpenAPI specification generation
|
|
@@ -136,144 +135,6 @@ declare function normalizePath(path: string): string;
|
|
|
136
135
|
* @module unified/route/types/route-definition
|
|
137
136
|
*/
|
|
138
137
|
|
|
139
|
-
/**
|
|
140
|
-
* Request body configuration.
|
|
141
|
-
*/
|
|
142
|
-
interface RequestBodyConfig<T = unknown> {
|
|
143
|
-
/**
|
|
144
|
-
* Schema for validating the request body.
|
|
145
|
-
*/
|
|
146
|
-
readonly schema: SchemaAdapter<T>;
|
|
147
|
-
/**
|
|
148
|
-
* Content type of the request body.
|
|
149
|
-
* @default 'application/json'
|
|
150
|
-
*/
|
|
151
|
-
readonly contentType?: ContentType;
|
|
152
|
-
/**
|
|
153
|
-
* Whether the body is required.
|
|
154
|
-
* @default true
|
|
155
|
-
*/
|
|
156
|
-
readonly required?: boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Description for OpenAPI documentation.
|
|
159
|
-
*/
|
|
160
|
-
readonly description?: string;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Query parameters configuration.
|
|
164
|
-
*/
|
|
165
|
-
interface QueryParamsConfig<T = unknown> {
|
|
166
|
-
/**
|
|
167
|
-
* Schema for validating query parameters.
|
|
168
|
-
*/
|
|
169
|
-
readonly schema: SchemaAdapter<T>;
|
|
170
|
-
/**
|
|
171
|
-
* Description for OpenAPI documentation.
|
|
172
|
-
*/
|
|
173
|
-
readonly description?: string;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Path parameters configuration (optional override).
|
|
177
|
-
* By default, path params are extracted from the path template.
|
|
178
|
-
*/
|
|
179
|
-
interface PathParamsConfig<T = unknown> {
|
|
180
|
-
/**
|
|
181
|
-
* Schema for validating path parameters.
|
|
182
|
-
* If provided, overrides the auto-extracted types from the path.
|
|
183
|
-
*/
|
|
184
|
-
readonly schema: SchemaAdapter<T>;
|
|
185
|
-
/**
|
|
186
|
-
* Description for OpenAPI documentation.
|
|
187
|
-
*/
|
|
188
|
-
readonly description?: string;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Headers configuration.
|
|
192
|
-
*/
|
|
193
|
-
interface HeadersConfig<T = unknown> {
|
|
194
|
-
/**
|
|
195
|
-
* Schema for validating headers.
|
|
196
|
-
*/
|
|
197
|
-
readonly schema: SchemaAdapter<T>;
|
|
198
|
-
/**
|
|
199
|
-
* Description for OpenAPI documentation.
|
|
200
|
-
*/
|
|
201
|
-
readonly description?: string;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Context configuration.
|
|
205
|
-
* Used to validate and type context data from middleware (e.g., JWT payload).
|
|
206
|
-
*/
|
|
207
|
-
interface ContextConfig<T = unknown> {
|
|
208
|
-
/**
|
|
209
|
-
* Schema for validating context data.
|
|
210
|
-
* Context is extracted by the framework adapter's contextExtractor.
|
|
211
|
-
*/
|
|
212
|
-
readonly schema: SchemaAdapter<T>;
|
|
213
|
-
/**
|
|
214
|
-
* Description for documentation.
|
|
215
|
-
*/
|
|
216
|
-
readonly description?: string;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Complete request configuration.
|
|
220
|
-
*/
|
|
221
|
-
interface RequestConfig<TBody = undefined, TQuery = undefined, TParams = undefined, THeaders = undefined, TContext = undefined> {
|
|
222
|
-
/**
|
|
223
|
-
* Request body schema and configuration.
|
|
224
|
-
*/
|
|
225
|
-
readonly body?: TBody extends undefined ? undefined : RequestBodyConfig<TBody>;
|
|
226
|
-
/**
|
|
227
|
-
* Query parameters schema and configuration.
|
|
228
|
-
*/
|
|
229
|
-
readonly query?: TQuery extends undefined ? undefined : QueryParamsConfig<TQuery>;
|
|
230
|
-
/**
|
|
231
|
-
* Path parameters schema and configuration.
|
|
232
|
-
* Optional - by default inferred from path template.
|
|
233
|
-
*/
|
|
234
|
-
readonly params?: TParams extends undefined ? undefined : PathParamsConfig<TParams>;
|
|
235
|
-
/**
|
|
236
|
-
* Headers schema and configuration.
|
|
237
|
-
*/
|
|
238
|
-
readonly headers?: THeaders extends undefined ? undefined : HeadersConfig<THeaders>;
|
|
239
|
-
/**
|
|
240
|
-
* Context schema and configuration.
|
|
241
|
-
* Validates context data extracted from middleware (e.g., JWT payload).
|
|
242
|
-
* Validation failure throws InternalServerError.
|
|
243
|
-
*/
|
|
244
|
-
readonly context?: TContext extends undefined ? undefined : ContextConfig<TContext>;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Single response configuration.
|
|
248
|
-
*/
|
|
249
|
-
interface ResponseConfig<T = unknown> {
|
|
250
|
-
/**
|
|
251
|
-
* Description for OpenAPI documentation.
|
|
252
|
-
* Required for OpenAPI compliance.
|
|
253
|
-
*/
|
|
254
|
-
readonly description: string;
|
|
255
|
-
/**
|
|
256
|
-
* Schema for the response body.
|
|
257
|
-
* Optional - some responses (204, 3xx) have no body.
|
|
258
|
-
*/
|
|
259
|
-
readonly schema?: SchemaAdapter<T>;
|
|
260
|
-
/**
|
|
261
|
-
* Content type of the response body.
|
|
262
|
-
* @default 'application/json'
|
|
263
|
-
*/
|
|
264
|
-
readonly contentType?: ContentType;
|
|
265
|
-
/**
|
|
266
|
-
* Response headers schema.
|
|
267
|
-
*/
|
|
268
|
-
readonly headers?: SchemaAdapter<Record<string, string>>;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Map of status codes to response configurations.
|
|
272
|
-
* Defined as an interface so IDE hovers show "ResponsesConfig"
|
|
273
|
-
* instead of expanding all ~60 HTTP status code keys.
|
|
274
|
-
*/
|
|
275
|
-
interface ResponsesConfig extends Readonly<Partial<Record<HttpStatusCode, ResponseConfig>>> {
|
|
276
|
-
}
|
|
277
138
|
/**
|
|
278
139
|
* Security requirement for OpenAPI.
|
|
279
140
|
*/
|
|
@@ -305,7 +166,7 @@ interface RouteDocumentation {
|
|
|
305
166
|
readonly tags?: readonly string[];
|
|
306
167
|
/**
|
|
307
168
|
* Unique operation identifier.
|
|
308
|
-
*
|
|
169
|
+
* If not specified, auto-generated from the router key path.
|
|
309
170
|
*/
|
|
310
171
|
readonly operationId?: string;
|
|
311
172
|
/**
|
|
@@ -324,47 +185,138 @@ interface RouteDocumentation {
|
|
|
324
185
|
readonly externalDocs?: ExternalDocs;
|
|
325
186
|
}
|
|
326
187
|
/**
|
|
327
|
-
*
|
|
328
|
-
*
|
|
188
|
+
* Metadata for a schema field (body, query, params, headers, context).
|
|
189
|
+
*
|
|
190
|
+
* Allows passing OpenAPI metadata alongside a schema without nesting.
|
|
191
|
+
* Each field on `defineRoute` accepts either a bare `SchemaAdapter` or
|
|
192
|
+
* a `SchemaFieldConfig` object:
|
|
193
|
+
*
|
|
194
|
+
* @example Bare schema (common case)
|
|
195
|
+
* ```typescript
|
|
196
|
+
* body: zodSchema(z.object({ name: z.string() }))
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* @example With metadata
|
|
200
|
+
* ```typescript
|
|
201
|
+
* body: {
|
|
202
|
+
* schema: zodSchema(z.object({ name: z.string() })),
|
|
203
|
+
* description: 'The user to create',
|
|
204
|
+
* contentType: 'application/json',
|
|
205
|
+
* }
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
interface SchemaFieldConfig<T extends SchemaAdapter = SchemaAdapter> {
|
|
209
|
+
readonly schema: T;
|
|
210
|
+
/** Description for OpenAPI generation. */
|
|
211
|
+
readonly description?: string;
|
|
212
|
+
/** Content type (body only). @default 'application/json' */
|
|
213
|
+
readonly contentType?: string;
|
|
214
|
+
/** Whether the field is required (body only). @default true */
|
|
215
|
+
readonly required?: boolean;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* A schema field accepts either a bare SchemaAdapter or a config with metadata.
|
|
329
219
|
*/
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
* '/api/users/:userId'
|
|
341
|
-
* '/api/projects/{projectId}/tasks/{taskId}'
|
|
342
|
-
*/
|
|
343
|
-
readonly path: TPath;
|
|
344
|
-
/**
|
|
345
|
-
* Request configuration including body, query, params, headers, and context.
|
|
346
|
-
*/
|
|
347
|
-
readonly request?: {
|
|
348
|
-
readonly body?: RequestBodyConfig<TBody>;
|
|
349
|
-
readonly query?: QueryParamsConfig<TQuery>;
|
|
350
|
-
readonly params?: PathParamsConfig<TPathParams>;
|
|
351
|
-
readonly headers?: HeadersConfig<THeaders>;
|
|
352
|
-
readonly context?: ContextConfig<TContext>;
|
|
220
|
+
type SchemaFieldInput<T extends SchemaAdapter = SchemaAdapter> = T | SchemaFieldConfig<T>;
|
|
221
|
+
/**
|
|
222
|
+
* Stored metadata for all schema fields on a route.
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
225
|
+
interface RouteFieldMeta {
|
|
226
|
+
readonly body?: {
|
|
227
|
+
readonly description?: string;
|
|
228
|
+
readonly contentType?: string;
|
|
229
|
+
readonly required?: boolean;
|
|
353
230
|
};
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
readonly
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
231
|
+
readonly query?: {
|
|
232
|
+
readonly description?: string;
|
|
233
|
+
};
|
|
234
|
+
readonly params?: {
|
|
235
|
+
readonly description?: string;
|
|
236
|
+
};
|
|
237
|
+
readonly headers?: {
|
|
238
|
+
readonly description?: string;
|
|
239
|
+
};
|
|
240
|
+
readonly context?: {
|
|
241
|
+
readonly description?: string;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Configuration for a single response status code.
|
|
246
|
+
*
|
|
247
|
+
* Used with the `responses` field on `defineRoute` to specify per-status
|
|
248
|
+
* schemas, descriptions, and content types for OpenAPI generation.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* responses: {
|
|
253
|
+
* 201: { schema: zodSchema(userSchema), description: 'Created' },
|
|
254
|
+
* 400: { description: 'Validation error' },
|
|
255
|
+
* 409: { description: 'User already exists' },
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
interface ResponseFieldConfig {
|
|
260
|
+
readonly schema?: SchemaAdapter;
|
|
261
|
+
readonly description?: string;
|
|
262
|
+
readonly contentType?: string;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Per-status response definitions keyed by HTTP status code.
|
|
266
|
+
*/
|
|
267
|
+
type ResponsesDefinition = Readonly<Record<number, ResponseFieldConfig>>;
|
|
268
|
+
/**
|
|
269
|
+
* Extracts the success response SchemaAdapter from a ResponsesDefinition.
|
|
270
|
+
* Cascades through 200 → 201 → 202 → 204.
|
|
271
|
+
*/
|
|
272
|
+
type ExtractSuccessSchema<T> = T extends {
|
|
273
|
+
200: {
|
|
274
|
+
schema: infer S extends SchemaAdapter;
|
|
275
|
+
};
|
|
276
|
+
} ? S : T extends {
|
|
277
|
+
201: {
|
|
278
|
+
schema: infer S extends SchemaAdapter;
|
|
279
|
+
};
|
|
280
|
+
} ? S : T extends {
|
|
281
|
+
202: {
|
|
282
|
+
schema: infer S extends SchemaAdapter;
|
|
283
|
+
};
|
|
284
|
+
} ? S : T extends {
|
|
285
|
+
204: {
|
|
286
|
+
schema: infer S extends SchemaAdapter;
|
|
287
|
+
};
|
|
288
|
+
} ? S : undefined;
|
|
289
|
+
/**
|
|
290
|
+
* Grouped request schemas for a route definition.
|
|
291
|
+
*
|
|
292
|
+
* Contains all input schemas: body, query, path params, headers, and context.
|
|
293
|
+
* Each field is either a `SchemaAdapter` or `undefined` if not specified.
|
|
294
|
+
*/
|
|
295
|
+
interface RouteRequestDefinition<TBody = undefined, TQuery = undefined, TPathParams = Record<string, string>, THeaders = undefined, TContext = undefined> {
|
|
296
|
+
/** Request body schema. */
|
|
297
|
+
readonly body: SchemaAdapter<TBody> | undefined;
|
|
298
|
+
/** Query parameters schema. */
|
|
299
|
+
readonly query: SchemaAdapter<TQuery> | undefined;
|
|
300
|
+
/**
|
|
301
|
+
* Path parameters schema.
|
|
302
|
+
* If not provided, path params are inferred from the path template.
|
|
303
|
+
*/
|
|
304
|
+
readonly params: SchemaAdapter<TPathParams> | undefined;
|
|
305
|
+
/** Headers schema. */
|
|
306
|
+
readonly headers: SchemaAdapter<THeaders> | undefined;
|
|
307
|
+
/** Context schema (e.g., JWT payload from middleware). */
|
|
308
|
+
readonly context: SchemaAdapter<TContext> | undefined;
|
|
362
309
|
}
|
|
363
310
|
/**
|
|
364
311
|
* A fully defined route with computed types.
|
|
365
312
|
* This is the output of `defineRoute()`.
|
|
313
|
+
*
|
|
314
|
+
* Request schemas are grouped under `request`:
|
|
315
|
+
* - `request.body`, `request.query`, `request.params`, `request.headers`, `request.context`
|
|
316
|
+
*
|
|
317
|
+
* Responses are per-status via the `responses` field.
|
|
366
318
|
*/
|
|
367
|
-
interface RouteDefinition<TMethod extends HttpMethod = HttpMethod, TPath extends string = string, TBody = undefined, TQuery = undefined, TPathParams = PathParams<TPath>, THeaders = undefined, TContext = undefined,
|
|
319
|
+
interface RouteDefinition<TMethod extends HttpMethod = HttpMethod, TPath extends string = string, TBody = undefined, TQuery = undefined, TPathParams = PathParams<TPath>, THeaders = undefined, TContext = undefined, TResponse = undefined> {
|
|
368
320
|
/**
|
|
369
321
|
* HTTP method for this route.
|
|
370
322
|
*/
|
|
@@ -374,23 +326,24 @@ interface RouteDefinition<TMethod extends HttpMethod = HttpMethod, TPath extends
|
|
|
374
326
|
*/
|
|
375
327
|
readonly path: TPath;
|
|
376
328
|
/**
|
|
377
|
-
* Request
|
|
329
|
+
* Request schemas (body, query, params, headers, context).
|
|
378
330
|
*/
|
|
379
|
-
readonly request:
|
|
380
|
-
readonly body: RequestBodyConfig<TBody> | undefined;
|
|
381
|
-
readonly query: QueryParamsConfig<TQuery> | undefined;
|
|
382
|
-
readonly params: PathParamsConfig<TPathParams> | undefined;
|
|
383
|
-
readonly headers: HeadersConfig<THeaders> | undefined;
|
|
384
|
-
readonly context: ContextConfig<TContext> | undefined;
|
|
385
|
-
};
|
|
331
|
+
readonly request: RouteRequestDefinition<TBody, TQuery, TPathParams, THeaders, TContext>;
|
|
386
332
|
/**
|
|
387
|
-
*
|
|
333
|
+
* Per-status response configurations.
|
|
334
|
+
* Each key is an HTTP status code, each value has optional schema, description, and contentType.
|
|
388
335
|
*/
|
|
389
|
-
readonly responses:
|
|
336
|
+
readonly responses: Readonly<Record<string, ResponseFieldConfig>> | undefined;
|
|
390
337
|
/**
|
|
391
338
|
* OpenAPI documentation.
|
|
392
339
|
*/
|
|
393
340
|
readonly docs: RouteDocumentation;
|
|
341
|
+
/**
|
|
342
|
+
* Schema field metadata for OpenAPI generation.
|
|
343
|
+
* Populated when fields are passed as `{ schema, description?, contentType?, required? }`.
|
|
344
|
+
* @internal
|
|
345
|
+
*/
|
|
346
|
+
readonly _meta: RouteFieldMeta;
|
|
394
347
|
/**
|
|
395
348
|
* Phantom types for TypeScript inference.
|
|
396
349
|
* Never accessed at runtime.
|
|
@@ -404,53 +357,41 @@ interface RouteDefinition<TMethod extends HttpMethod = HttpMethod, TPath extends
|
|
|
404
357
|
readonly pathParams: TPathParams;
|
|
405
358
|
readonly headers: THeaders;
|
|
406
359
|
readonly context: TContext;
|
|
407
|
-
readonly
|
|
360
|
+
readonly response: TResponse;
|
|
408
361
|
};
|
|
409
362
|
}
|
|
410
363
|
/**
|
|
411
364
|
* Infers the request body type from a route definition.
|
|
412
365
|
*/
|
|
413
|
-
type InferRouteBody<T> = T extends RouteDefinition<HttpMethod, string, infer TBody, unknown, unknown, unknown,
|
|
366
|
+
type InferRouteBody<T> = T extends RouteDefinition<HttpMethod, string, infer TBody, unknown, unknown, unknown, unknown, unknown> ? TBody : never;
|
|
414
367
|
/**
|
|
415
368
|
* Infers the query params type from a route definition.
|
|
416
369
|
*/
|
|
417
|
-
type InferRouteQuery<T> = T extends RouteDefinition<HttpMethod, string, unknown, infer TQuery, unknown, unknown,
|
|
370
|
+
type InferRouteQuery<T> = T extends RouteDefinition<HttpMethod, string, unknown, infer TQuery, unknown, unknown, unknown, unknown> ? TQuery : never;
|
|
418
371
|
/**
|
|
419
372
|
* Infers the path params type from a route definition.
|
|
420
373
|
*/
|
|
421
|
-
type InferRoutePathParams<T> = T extends RouteDefinition<HttpMethod, string, unknown, unknown, infer TPathParams, unknown,
|
|
374
|
+
type InferRoutePathParams<T> = T extends RouteDefinition<HttpMethod, string, unknown, unknown, infer TPathParams, unknown, unknown, unknown> ? TPathParams : never;
|
|
422
375
|
/**
|
|
423
376
|
* Infers the headers type from a route definition.
|
|
424
377
|
*/
|
|
425
|
-
type InferRouteHeaders<T> = T extends RouteDefinition<HttpMethod, string, unknown, unknown, unknown, infer THeaders, unknown,
|
|
378
|
+
type InferRouteHeaders<T> = T extends RouteDefinition<HttpMethod, string, unknown, unknown, unknown, infer THeaders, unknown, unknown> ? THeaders : never;
|
|
426
379
|
/**
|
|
427
380
|
* Infers the context type from a route definition.
|
|
428
381
|
*/
|
|
429
|
-
type InferRouteContext<T> = T extends RouteDefinition<HttpMethod, string, unknown, unknown, unknown, unknown, infer TContext,
|
|
430
|
-
/**
|
|
431
|
-
* Infers the response type for a specific status code.
|
|
432
|
-
*/
|
|
433
|
-
type InferRouteResponse<T, TStatus extends HttpStatusCode> = T extends RouteDefinition<HttpMethod, string, unknown, unknown, unknown, unknown, unknown, infer TResponses> ? TStatus extends keyof TResponses ? TResponses[TStatus] extends ResponseConfig<infer TData> ? TData : never : never : never;
|
|
382
|
+
type InferRouteContext<T> = T extends RouteDefinition<HttpMethod, string, unknown, unknown, unknown, unknown, infer TContext, unknown> ? TContext : never;
|
|
434
383
|
/**
|
|
435
|
-
* Infers the
|
|
384
|
+
* Infers the response type from a route definition.
|
|
436
385
|
*/
|
|
437
|
-
type
|
|
438
|
-
200: ResponseConfig<infer T200>;
|
|
439
|
-
} ? T200 : TResponses extends {
|
|
440
|
-
201: ResponseConfig<infer T201>;
|
|
441
|
-
} ? T201 : TResponses extends {
|
|
442
|
-
202: ResponseConfig<infer T202>;
|
|
443
|
-
} ? T202 : TResponses extends {
|
|
444
|
-
204: ResponseConfig;
|
|
445
|
-
} ? void : unknown : never;
|
|
386
|
+
type InferRouteResponse<T> = T extends RouteDefinition<HttpMethod, string, unknown, unknown, unknown, unknown, unknown, infer TResponse> ? TResponse : never;
|
|
446
387
|
/**
|
|
447
388
|
* Extracts the method from a route definition.
|
|
448
389
|
*/
|
|
449
|
-
type InferRouteMethod<T> = T extends RouteDefinition<infer TMethod, string, unknown, unknown, unknown, unknown, unknown,
|
|
390
|
+
type InferRouteMethod<T> = T extends RouteDefinition<infer TMethod, string, unknown, unknown, unknown, unknown, unknown, unknown> ? TMethod : never;
|
|
450
391
|
/**
|
|
451
392
|
* Extracts the path from a route definition.
|
|
452
393
|
*/
|
|
453
|
-
type InferRoutePath<T> = T extends RouteDefinition<HttpMethod, infer TPath, unknown, unknown, unknown, unknown, unknown,
|
|
394
|
+
type InferRoutePath<T> = T extends RouteDefinition<HttpMethod, infer TPath, unknown, unknown, unknown, unknown, unknown, unknown> ? TPath : never;
|
|
454
395
|
|
|
455
396
|
/**
|
|
456
397
|
* @fileoverview Router definition types for grouping routes.
|
|
@@ -464,16 +405,30 @@ type InferRoutePath<T> = T extends RouteDefinition<HttpMethod, infer TPath, unkn
|
|
|
464
405
|
*/
|
|
465
406
|
|
|
466
407
|
/**
|
|
467
|
-
* A router entry can be
|
|
468
|
-
* Uses permissive types to allow any valid route definition.
|
|
408
|
+
* A router entry can be a route definition, a nested router config, or a router definition.
|
|
469
409
|
*/
|
|
470
|
-
type RouterEntry = RouteDefinition<HttpMethod, string, unknown, unknown, unknown, unknown, unknown,
|
|
410
|
+
type RouterEntry = RouteDefinition<HttpMethod, string, unknown, unknown, unknown, unknown, unknown, any> | RouterConfig | RouterDefinition;
|
|
471
411
|
/**
|
|
472
412
|
* Configuration for a router (group of routes).
|
|
473
413
|
*/
|
|
474
414
|
interface RouterConfig {
|
|
475
415
|
readonly [key: string]: RouterEntry;
|
|
476
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Router-level defaults applied to all child routes.
|
|
419
|
+
*/
|
|
420
|
+
interface RouterDefaults {
|
|
421
|
+
/**
|
|
422
|
+
* Default tags for all routes in this router.
|
|
423
|
+
* Merged with route-specific tags.
|
|
424
|
+
*/
|
|
425
|
+
readonly tags?: readonly string[];
|
|
426
|
+
/**
|
|
427
|
+
* Default context schema for all routes in this router.
|
|
428
|
+
* Applied to routes that don't define their own context.
|
|
429
|
+
*/
|
|
430
|
+
readonly context?: SchemaAdapter;
|
|
431
|
+
}
|
|
477
432
|
/**
|
|
478
433
|
* A fully defined router.
|
|
479
434
|
*/
|
|
@@ -487,9 +442,9 @@ interface RouterDefinition<T extends RouterConfig = RouterConfig> {
|
|
|
487
442
|
*/
|
|
488
443
|
readonly basePath?: string;
|
|
489
444
|
/**
|
|
490
|
-
* Default
|
|
445
|
+
* Default values applied to all child routes.
|
|
491
446
|
*/
|
|
492
|
-
readonly
|
|
447
|
+
readonly defaults?: RouterDefaults;
|
|
493
448
|
/**
|
|
494
449
|
* Marker to identify this as a router.
|
|
495
450
|
* @internal
|
|
@@ -506,26 +461,6 @@ declare function isRouteDefinition(value: unknown): value is RouteDefinition;
|
|
|
506
461
|
declare function isRouterDefinition(value: unknown): value is RouterDefinition;
|
|
507
462
|
/**
|
|
508
463
|
* Flattens a router into a map of path keys to route definitions.
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* ```typescript
|
|
512
|
-
* const router = defineRouter({
|
|
513
|
-
* users: {
|
|
514
|
-
* list: listUsersRoute,
|
|
515
|
-
* get: getUserRoute,
|
|
516
|
-
* },
|
|
517
|
-
* posts: {
|
|
518
|
-
* create: createPostRoute,
|
|
519
|
-
* },
|
|
520
|
-
* });
|
|
521
|
-
*
|
|
522
|
-
* type Flat = FlattenRouter<typeof router>;
|
|
523
|
-
* // {
|
|
524
|
-
* // 'users.list': typeof listUsersRoute,
|
|
525
|
-
* // 'users.get': typeof getUserRoute,
|
|
526
|
-
* // 'posts.create': typeof createPostRoute,
|
|
527
|
-
* // }
|
|
528
|
-
* ```
|
|
529
464
|
*/
|
|
530
465
|
type FlattenRouter<T extends RouterConfig, Prefix extends string = ''> = T extends RouterConfig ? {
|
|
531
466
|
[K in keyof T]: T[K] extends RouteDefinition<any, any, any, any, any, any, any, any> ? {
|
|
@@ -534,33 +469,16 @@ type FlattenRouter<T extends RouterConfig, Prefix extends string = ''> = T exten
|
|
|
534
469
|
}[keyof T] extends infer U ? U extends Record<string, RouteDefinition<any, any, any, any, any, any, any, any>> ? U : never : never : never;
|
|
535
470
|
/**
|
|
536
471
|
* Gets all route keys from a router.
|
|
537
|
-
*
|
|
538
|
-
* @example
|
|
539
|
-
* ```typescript
|
|
540
|
-
* type Keys = RouterKeys<typeof router>;
|
|
541
|
-
* // 'users.list' | 'users.get' | 'posts.create'
|
|
542
|
-
* ```
|
|
543
472
|
*/
|
|
544
473
|
type RouterKeys<T extends RouterConfig, Prefix extends string = ''> = T extends RouterConfig ? {
|
|
545
474
|
[K in keyof T]: T[K] extends RouteDefinition<any, any, any, any, any, any, any, any> ? `${Prefix}${K & string}` : T[K] extends RouterConfig ? RouterKeys<T[K], `${Prefix}${K & string}.`> : never;
|
|
546
475
|
}[keyof T] : never;
|
|
547
476
|
/**
|
|
548
477
|
* Gets a route by its dotted key path.
|
|
549
|
-
*
|
|
550
|
-
* @example
|
|
551
|
-
* ```typescript
|
|
552
|
-
* type UserGet = GetRoute<typeof router, 'users.get'>;
|
|
553
|
-
* // typeof getUserRoute
|
|
554
|
-
* ```
|
|
555
478
|
*/
|
|
556
479
|
type GetRoute<T extends RouterConfig, K extends string> = K extends `${infer Head}.${infer Tail}` ? Head extends keyof T ? T[Head] extends RouterConfig ? GetRoute<T[Head], Tail> : never : never : K extends keyof T ? T[K] extends RouteDefinition<any, any, any, any, any, any, any, any> ? T[K] : never : never;
|
|
557
480
|
/**
|
|
558
481
|
* Deep-merges two router configs at the type level.
|
|
559
|
-
*
|
|
560
|
-
* - If both sides are sub-routers (extend RouterConfig), recurse.
|
|
561
|
-
* - Otherwise last-one-wins (B overrides A).
|
|
562
|
-
* - RouteDefinition does NOT extend RouterConfig (it has `method`, `path`, etc.)
|
|
563
|
-
* so the conditional correctly distinguishes leaves from sub-routers.
|
|
564
482
|
*/
|
|
565
483
|
type DeepMergeTwo<A extends RouterConfig, B extends RouterConfig> = {
|
|
566
484
|
readonly [K in keyof A | keyof B]: K extends keyof A ? K extends keyof B ? A[K] extends RouterConfig ? B[K] extends RouterConfig ? DeepMergeTwo<A[K], B[K]> : B[K] : B[K] : A[K] : K extends keyof B ? B[K] : never;
|
|
@@ -577,11 +495,6 @@ type DeepMergeAll<T extends readonly RouterConfig[]> = T extends readonly [
|
|
|
577
495
|
] ? DeepMergeAll<[DeepMergeTwo<First, Second>, ...Rest]> : RouterConfig;
|
|
578
496
|
/**
|
|
579
497
|
* Recursively flattens complex types for clean IDE hover display.
|
|
580
|
-
* Applied at return sites (not inside recursion) so DTS emit stays fast —
|
|
581
|
-
* TypeScript only resolves when concrete types are provided.
|
|
582
|
-
*
|
|
583
|
-
* Works with any recursive object type: router configs, client types,
|
|
584
|
-
* React Query hooks, etc. Functions and primitives pass through unchanged.
|
|
585
498
|
*/
|
|
586
499
|
type PrettifyDeep<T> = T extends (...args: any[]) => any ? T : T extends object ? {
|
|
587
500
|
readonly [K in keyof T]: PrettifyDeep<T[K]>;
|
|
@@ -594,4 +507,4 @@ declare function collectRoutes(config: RouterConfig, basePath?: string): {
|
|
|
594
507
|
route: RouteDefinition;
|
|
595
508
|
}[];
|
|
596
509
|
|
|
597
|
-
export {
|
|
510
|
+
export { type RouterDefaults as A, type SchemaFieldConfig as B, type ContentType as C, type DeepMergeTwo as D, type ExtractPathParamNames as E, type FlattenRouter as F, type GetRoute as G, type HttpMethod as H, type InferRouteBody as I, type RouteFieldMeta as J, type ResponseFieldConfig as K, type SecurityRequirement as L, type ExternalDocs as M, type RouteRequestDefinition as N, type PathParams as P, type RouteDefinition as R, type SchemaFieldInput as S, type HttpStatusCode as a, type HasPathParams as b, type RouteDocumentation as c, type RouterConfig as d, type RouterDefinition as e, type RouterEntry as f, type RouterKeys as g, type DeepMergeAll as h, type PrettifyDeep as i, type InferRouteQuery as j, type InferRoutePathParams as k, type InferRouteHeaders as l, type InferRouteContext as m, type InferRouteResponse as n, type InferRouteMethod as o, type InferRoutePath as p, isRouteDefinition as q, isRouterDefinition as r, collectRoutes as s, buildPath as t, normalizePath as u, pathToRegex as v, getPathParamNames as w, hasPathParams as x, type ResponsesDefinition as y, type ExtractSuccessSchema as z };
|
package/package.json
CHANGED
package/dist/chunk-BZULBF4N.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isRouteDefinition,
|
|
3
|
-
isRouterDefinition
|
|
4
|
-
} from "./chunk-DS7TE6KZ.js";
|
|
5
|
-
|
|
6
|
-
// src/presentation/http/route/define-route.ts
|
|
7
|
-
function defineRoute(input) {
|
|
8
|
-
const definition = {
|
|
9
|
-
method: input.method,
|
|
10
|
-
path: input.path,
|
|
11
|
-
request: {
|
|
12
|
-
body: input.request?.body ?? void 0,
|
|
13
|
-
query: input.request?.query ?? void 0,
|
|
14
|
-
params: input.request?.params ?? void 0,
|
|
15
|
-
headers: input.request?.headers ?? void 0,
|
|
16
|
-
context: input.request?.context ?? void 0
|
|
17
|
-
},
|
|
18
|
-
responses: input.responses,
|
|
19
|
-
docs: {
|
|
20
|
-
summary: input.docs?.summary,
|
|
21
|
-
description: input.docs?.description,
|
|
22
|
-
tags: input.docs?.tags,
|
|
23
|
-
operationId: input.docs?.operationId,
|
|
24
|
-
deprecated: input.docs?.deprecated ?? false,
|
|
25
|
-
security: input.docs?.security,
|
|
26
|
-
externalDocs: input.docs?.externalDocs
|
|
27
|
-
},
|
|
28
|
-
_types: void 0
|
|
29
|
-
};
|
|
30
|
-
return Object.freeze(definition);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/presentation/http/route/define-router.ts
|
|
34
|
-
function defineRouter(routes, options) {
|
|
35
|
-
const definition = {
|
|
36
|
-
routes,
|
|
37
|
-
basePath: options?.basePath,
|
|
38
|
-
tags: options?.tags,
|
|
39
|
-
_isRouter: true
|
|
40
|
-
};
|
|
41
|
-
return deepFreeze(definition);
|
|
42
|
-
}
|
|
43
|
-
function deepFreeze(obj) {
|
|
44
|
-
const propNames = Object.getOwnPropertyNames(obj);
|
|
45
|
-
for (const name of propNames) {
|
|
46
|
-
const value = obj[name];
|
|
47
|
-
if (value && typeof value === "object" && !Object.isFrozen(value)) {
|
|
48
|
-
deepFreeze(value);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return Object.freeze(obj);
|
|
52
|
-
}
|
|
53
|
-
function extractRoutes(input) {
|
|
54
|
-
return isRouterDefinition(input) ? input.routes : input;
|
|
55
|
-
}
|
|
56
|
-
function isSubRouter(value) {
|
|
57
|
-
return typeof value === "object" && value !== null && !isRouteDefinition(value) && !isRouterDefinition(value);
|
|
58
|
-
}
|
|
59
|
-
function deepMergeConfigs(a, b) {
|
|
60
|
-
const result = { ...a };
|
|
61
|
-
for (const key of Object.keys(b)) {
|
|
62
|
-
const aVal = result[key];
|
|
63
|
-
const bVal = b[key];
|
|
64
|
-
if (isSubRouter(aVal) && isSubRouter(bVal)) {
|
|
65
|
-
result[key] = deepMergeConfigs(aVal, bVal);
|
|
66
|
-
} else {
|
|
67
|
-
result[key] = bVal;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
function mergeRouters(...routers) {
|
|
73
|
-
const merged = routers.map(extractRoutes).reduce(deepMergeConfigs);
|
|
74
|
-
return defineRouter(merged);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export {
|
|
78
|
-
defineRoute,
|
|
79
|
-
defineRouter,
|
|
80
|
-
mergeRouters
|
|
81
|
-
};
|
|
82
|
-
//# sourceMappingURL=chunk-BZULBF4N.js.map
|