@fresho/router 0.4.0 → 0.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.
@@ -0,0 +1,724 @@
1
+ import { n as runMiddleware } from "./middleware-B-_0PLA6.mjs";
2
+
3
+ //#region src/schema.ts
4
+ /** Valid base types for primitives and arrays. */
5
+ const PRIMITIVE_TYPES = [
6
+ "string",
7
+ "number",
8
+ "boolean",
9
+ "unknown"
10
+ ];
11
+ /** Checks if a schema field is a nested object (not a type string). */
12
+ function isNestedSchema(field) {
13
+ return typeof field === "object" && field !== null;
14
+ }
15
+ /**
16
+ * Validates and coerces a single primitive value.
17
+ * Returns [success, result, errorMessage].
18
+ */
19
+ function validatePrimitive(value, baseType) {
20
+ switch (baseType) {
21
+ case "string": return [
22
+ true,
23
+ String(value),
24
+ null
25
+ ];
26
+ case "number": {
27
+ const num = Number(value);
28
+ if (Number.isNaN(num)) return [
29
+ false,
30
+ void 0,
31
+ "Expected number"
32
+ ];
33
+ return [
34
+ true,
35
+ num,
36
+ null
37
+ ];
38
+ }
39
+ case "boolean":
40
+ if (value === "true" || value === "1" || value === true) return [
41
+ true,
42
+ true,
43
+ null
44
+ ];
45
+ else if (value === "false" || value === "0" || value === false) return [
46
+ true,
47
+ false,
48
+ null
49
+ ];
50
+ return [
51
+ false,
52
+ void 0,
53
+ "Expected boolean (true/false)"
54
+ ];
55
+ case "unknown": return [
56
+ true,
57
+ value,
58
+ null
59
+ ];
60
+ default: return [
61
+ false,
62
+ void 0,
63
+ `Unknown type: ${baseType}`
64
+ ];
65
+ }
66
+ }
67
+ /**
68
+ * Validates a schema field value (primitive, array, or nested object).
69
+ * Returns [success, result, errors].
70
+ */
71
+ function validateField(key, field, value, parentPath = "") {
72
+ const fieldPath = parentPath ? `${parentPath}.${key}` : key;
73
+ const errors = {};
74
+ if (isNestedSchema(field)) {
75
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
76
+ errors[fieldPath] = ["Expected object"];
77
+ return [
78
+ false,
79
+ void 0,
80
+ errors
81
+ ];
82
+ }
83
+ const nestedResult = validateSchema(field, value, fieldPath);
84
+ return [
85
+ nestedResult.success,
86
+ nestedResult.data,
87
+ nestedResult.errors
88
+ ];
89
+ }
90
+ const typeStr = field;
91
+ const isOptional = typeStr.endsWith("?");
92
+ const isArray = typeStr.includes("[]");
93
+ let baseType = isOptional ? typeStr.slice(0, -1) : typeStr;
94
+ if (isArray) baseType = baseType.replace("[]", "");
95
+ if (value === void 0 || value === "") {
96
+ if (!isOptional) {
97
+ errors[fieldPath] = ["Required"];
98
+ return [
99
+ false,
100
+ void 0,
101
+ errors
102
+ ];
103
+ }
104
+ return [
105
+ true,
106
+ void 0,
107
+ {}
108
+ ];
109
+ }
110
+ if (isArray) {
111
+ if (!Array.isArray(value)) {
112
+ errors[fieldPath] = ["Expected array"];
113
+ return [
114
+ false,
115
+ void 0,
116
+ errors
117
+ ];
118
+ }
119
+ const resultArray = [];
120
+ for (let i = 0; i < value.length; i++) {
121
+ const [success$1, coerced$1, errorMsg$1] = validatePrimitive(value[i], baseType);
122
+ if (!success$1) {
123
+ errors[`${fieldPath}[${i}]`] = [errorMsg$1];
124
+ return [
125
+ false,
126
+ void 0,
127
+ errors
128
+ ];
129
+ }
130
+ resultArray.push(coerced$1);
131
+ }
132
+ return [
133
+ true,
134
+ resultArray,
135
+ {}
136
+ ];
137
+ }
138
+ const [success, coerced, errorMsg] = validatePrimitive(value, baseType);
139
+ if (!success) {
140
+ errors[fieldPath] = [errorMsg];
141
+ return [
142
+ false,
143
+ void 0,
144
+ errors
145
+ ];
146
+ }
147
+ return [
148
+ true,
149
+ coerced,
150
+ {}
151
+ ];
152
+ }
153
+ /**
154
+ * Validates a full schema against data.
155
+ * Returns { success, data, errors }.
156
+ */
157
+ function validateSchema(schema, data, parentPath = "") {
158
+ const result = {};
159
+ const allErrors = {};
160
+ for (const [key, field] of Object.entries(schema)) {
161
+ const value = data[key];
162
+ const [success, coerced, fieldErrors] = validateField(key, field, value, parentPath);
163
+ if (!success) Object.assign(allErrors, fieldErrors);
164
+ else if (coerced !== void 0) result[key] = coerced;
165
+ }
166
+ return {
167
+ success: Object.keys(allErrors).length === 0,
168
+ data: result,
169
+ errors: allErrors
170
+ };
171
+ }
172
+ /** Validates schema definition at compile time. */
173
+ function validateSchemaDefinition(schema, path = "") {
174
+ for (const [key, field] of Object.entries(schema)) {
175
+ const fieldPath = path ? `${path}.${key}` : key;
176
+ if (isNestedSchema(field)) validateSchemaDefinition(field, fieldPath);
177
+ else {
178
+ const typeStr = field;
179
+ let baseType = typeStr.endsWith("?") ? typeStr.slice(0, -1) : typeStr;
180
+ baseType = baseType.replace("[]", "");
181
+ if (!PRIMITIVE_TYPES.includes(baseType)) throw new Error(`Unknown type '${typeStr}' at '${fieldPath}'`);
182
+ }
183
+ }
184
+ }
185
+ /**
186
+ * Compiles a schema definition into a validator.
187
+ *
188
+ * Used internally by the router to validate query parameters and request bodies.
189
+ * Provides a Zod-compatible `safeParse` API for consistency.
190
+ *
191
+ * @param schema - The schema definition object
192
+ * @returns A compiled schema with `safeParse` method
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const userSchema = compileSchema({
197
+ * name: 'string',
198
+ * age: 'number',
199
+ * email: 'string?',
200
+ * });
201
+ *
202
+ * const result = userSchema.safeParse({ name: 'Alice', age: 30 });
203
+ * if (result.success) {
204
+ * console.log(result.data.name); // 'Alice'
205
+ * } else {
206
+ * console.log(result.error.flatten().fieldErrors);
207
+ * }
208
+ * ```
209
+ */
210
+ function compileSchema(schema) {
211
+ validateSchemaDefinition(schema);
212
+ return { safeParse(data) {
213
+ const { success, data: result, errors } = validateSchema(schema, data);
214
+ if (!success) return {
215
+ success: false,
216
+ error: { flatten: () => ({ fieldErrors: errors }) }
217
+ };
218
+ return {
219
+ success: true,
220
+ data: result
221
+ };
222
+ } };
223
+ }
224
+ /**
225
+ * Converts a schema definition to JSON Schema, recursing into nested objects.
226
+ *
227
+ * @param descriptions - Field descriptions keyed by name, dotted for nested fields
228
+ * @param prefix - Dotted path of `schema` within the root, for nested lookups
229
+ */
230
+ function toJsonSchema(schema, descriptions = {}, prefix = "") {
231
+ const properties = {};
232
+ const required = [];
233
+ for (const [key, field] of Object.entries(schema)) {
234
+ const description = descriptions[`${prefix}${key}`];
235
+ const described = description === void 0 ? {} : { description };
236
+ if (isNestedSchema(field)) {
237
+ properties[key] = {
238
+ ...toJsonSchema(field, descriptions, `${prefix}${key}.`),
239
+ ...described
240
+ };
241
+ required.push(key);
242
+ continue;
243
+ }
244
+ const optional = field.endsWith("?");
245
+ const base = optional ? field.slice(0, -1) : field;
246
+ const primitive = base.replace("[]", "");
247
+ const item = primitive === "unknown" ? {} : { type: primitive };
248
+ properties[key] = base.endsWith("[]") ? {
249
+ type: "array",
250
+ items: item,
251
+ ...described
252
+ } : {
253
+ ...item,
254
+ ...described
255
+ };
256
+ if (!optional) required.push(key);
257
+ }
258
+ return {
259
+ type: "object",
260
+ properties,
261
+ ...required.length > 0 && { required }
262
+ };
263
+ }
264
+
265
+ //#endregion
266
+ //#region src/types.ts
267
+ /** HTTP method property names. */
268
+ const HTTP_METHODS = new Set([
269
+ "get",
270
+ "post",
271
+ "put",
272
+ "patch",
273
+ "delete",
274
+ "options",
275
+ "head"
276
+ ]);
277
+ /** Symbol to mark an object as a route definition. */
278
+ const ROUTE_MARKER = Symbol.for("@fresho/router:route");
279
+ /** Symbol to mark an object as a router. */
280
+ const ROUTER_MARKER = Symbol.for("@fresho/router:router");
281
+ /** Checks if a value is a function. */
282
+ function isFunction(value) {
283
+ return typeof value === "function";
284
+ }
285
+ /** Checks if entry is a Route (marked with ROUTE_MARKER). */
286
+ function isRoute(entry) {
287
+ return typeof entry === "object" && entry !== null && ROUTE_MARKER in entry;
288
+ }
289
+ /** Checks if entry is a Router (marked with ROUTER_MARKER). */
290
+ function isRouter(entry) {
291
+ return typeof entry === "object" && entry !== null && ROUTER_MARKER in entry;
292
+ }
293
+
294
+ //#endregion
295
+ //#region src/handler.ts
296
+ /**
297
+ * Escapes special regex characters in a string.
298
+ */
299
+ function escapeRegex(str) {
300
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
301
+ }
302
+ /**
303
+ * Converts a path with :param segments to a regex pattern.
304
+ */
305
+ function pathToRegex(path) {
306
+ const paramNames = [];
307
+ const parts = path.split(/:(\w+)/g);
308
+ let regexStr = "";
309
+ for (let i = 0; i < parts.length; i++) if (i % 2 === 0) regexStr += escapeRegex(parts[i]);
310
+ else {
311
+ paramNames.push(parts[i]);
312
+ regexStr += "([^/]+)";
313
+ }
314
+ return {
315
+ pattern: /* @__PURE__ */ new RegExp(`^${regexStr}$`),
316
+ paramNames
317
+ };
318
+ }
319
+ /**
320
+ * Converts a property name to a path segment.
321
+ * - `$param` becomes `:param`
322
+ * - Other names become literal segments
323
+ */
324
+ function propertyToSegment$1(prop) {
325
+ if (prop.startsWith("$")) return `:${prop.slice(1)}`;
326
+ return prop;
327
+ }
328
+ /** Collects and compiles all routes from a router tree. */
329
+ function compileRoutes(routerDef, parentPath = "", parentMiddleware = []) {
330
+ const currentMiddleware = [...parentMiddleware, ...routerDef.middleware || []];
331
+ const compiled = [];
332
+ for (const [prop, entry] of Object.entries(routerDef.routes)) if (isRouter(entry)) {
333
+ const segment = propertyToSegment$1(prop);
334
+ const newPath = parentPath ? `${parentPath}/${segment}` : `/${segment}`;
335
+ compiled.push(...compileRoutes(entry, newPath, currentMiddleware));
336
+ } else if (HTTP_METHODS.has(prop)) {
337
+ const method = prop.toUpperCase();
338
+ const { pattern, paramNames } = pathToRegex(parentPath || "/");
339
+ if (isFunction(entry)) compiled.push({
340
+ method,
341
+ pattern,
342
+ paramNames,
343
+ handler: entry,
344
+ middleware: currentMiddleware
345
+ });
346
+ else if (isRoute(entry)) {
347
+ const routeDef = entry;
348
+ compiled.push({
349
+ method,
350
+ pattern,
351
+ paramNames,
352
+ handler: routeDef.handler,
353
+ middleware: currentMiddleware,
354
+ querySchema: routeDef.query ? compileSchema(routeDef.query) : void 0,
355
+ bodySchema: routeDef.body ? compileSchema(routeDef.body) : void 0
356
+ });
357
+ }
358
+ }
359
+ return compiled;
360
+ }
361
+ /**
362
+ * Strips the body from a response for HEAD requests.
363
+ */
364
+ function stripBodyForHead(response, isHead) {
365
+ if (!isHead) return response;
366
+ return new Response(null, {
367
+ status: response.status,
368
+ statusText: response.statusText,
369
+ headers: response.headers
370
+ });
371
+ }
372
+ /**
373
+ * Creates a fetch handler from a router definition.
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * const api = router({
378
+ * health: router({
379
+ * get: async () => ({ status: 'ok' }),
380
+ * }),
381
+ * users: router({
382
+ * get: async () => [...],
383
+ * $id: router({
384
+ * get: async (c) => ({ id: c.path.id }),
385
+ * }),
386
+ * }),
387
+ * });
388
+ *
389
+ * export default { fetch: api.handler() };
390
+ * ```
391
+ */
392
+ function createHandler(routerDef) {
393
+ const compiledRoutes = compileRoutes(routerDef);
394
+ return async (request, env, ctx) => {
395
+ const url = new URL(request.url);
396
+ const method = request.method.toUpperCase();
397
+ const isHead = method === "HEAD";
398
+ for (const compiled of compiledRoutes) {
399
+ if (!(compiled.method === method || method === "OPTIONS" || method === "HEAD" && compiled.method === "GET")) continue;
400
+ const match = compiled.pattern.exec(url.pathname);
401
+ if (!match) continue;
402
+ const path = {};
403
+ for (let i = 0; i < compiled.paramNames.length; i++) path[compiled.paramNames[i]] = decodeURIComponent(match[i + 1]);
404
+ const context = {
405
+ request,
406
+ path,
407
+ query: {},
408
+ body: {},
409
+ env,
410
+ executionCtx: ctx
411
+ };
412
+ if (compiled.middleware.length > 0 || compiled.handler || compiled.querySchema || compiled.bodySchema) return stripBodyForHead(await runMiddleware(compiled.middleware, context, async () => {
413
+ const routeId = `${compiled.method} ${url.pathname}`;
414
+ let query = {};
415
+ if (compiled.querySchema) {
416
+ const raw = Object.fromEntries(url.searchParams);
417
+ const result = compiled.querySchema.safeParse(raw);
418
+ if (!result.success) return Response.json({
419
+ error: "Invalid query parameters",
420
+ route: routeId,
421
+ details: result.error.flatten()
422
+ }, { status: 400 });
423
+ query = result.data;
424
+ }
425
+ let body = {};
426
+ if (compiled.bodySchema && [
427
+ "POST",
428
+ "PUT",
429
+ "PATCH"
430
+ ].includes(method)) {
431
+ const raw = await request.json().catch(() => ({}));
432
+ const result = compiled.bodySchema.safeParse(raw);
433
+ if (!result.success) return Response.json({
434
+ error: "Invalid request body",
435
+ route: routeId,
436
+ details: result.error.flatten()
437
+ }, { status: 400 });
438
+ body = result.data;
439
+ }
440
+ context.query = query;
441
+ context.body = body;
442
+ if (compiled.handler) {
443
+ const handlerContext = {
444
+ request,
445
+ path,
446
+ query,
447
+ body,
448
+ env,
449
+ executionCtx: ctx
450
+ };
451
+ for (const key of Object.keys(context)) if (![
452
+ "request",
453
+ "path",
454
+ "query",
455
+ "body",
456
+ "env",
457
+ "executionCtx"
458
+ ].includes(key)) handlerContext[key] = context[key];
459
+ const result = await compiled.handler(handlerContext);
460
+ if (result instanceof Response) return result;
461
+ return Response.json(result);
462
+ }
463
+ return Response.json({});
464
+ }), isHead);
465
+ return stripBodyForHead(Response.json({}), isHead);
466
+ }
467
+ return Response.json({ error: "Not Found" }, { status: 404 });
468
+ };
469
+ }
470
+
471
+ //#endregion
472
+ //#region src/core.ts
473
+ /**
474
+ * @fileoverview Core route and router creation functions.
475
+ *
476
+ * ## Path Convention
477
+ * - Property names = URL path segments
478
+ * - `$param` prefix = dynamic segment (`:param`)
479
+ * - `get`, `post`, `put`, `patch`, `delete` = HTTP method handlers
480
+ *
481
+ * ## Typing Best Practices
482
+ *
483
+ * **Schemas** (`query`/`body`) provide runtime validation AND type inference.
484
+ * Use them for any input that needs validation:
485
+ * ```typescript
486
+ * get: route({
487
+ * query: { limit: 'number?' },
488
+ * handler: async (c) => c.query.limit, // limit: number | undefined
489
+ * })
490
+ * ```
491
+ *
492
+ * **Context** (`route.ctx<T>()`) provides types only (no validation).
493
+ * Use it for path params, env bindings, and middleware-injected values:
494
+ * ```typescript
495
+ * interface MyContext {
496
+ * path: { id: string };
497
+ * env: { DB: Database };
498
+ * user: { name: string }; // from auth middleware
499
+ * }
500
+ * get: route.ctx<MyContext>()({
501
+ * handler: async (c) => ({ id: c.path.id, user: c.user.name }),
502
+ * })
503
+ * ```
504
+ *
505
+ * **Important:** Don't add explicit type annotations to handler parameters.
506
+ * Let types flow from schemas and context:
507
+ * ```typescript
508
+ * // GOOD: types inferred from schema
509
+ * handler: async (c) => c.query.limit
510
+ *
511
+ * // BAD: redundant type annotation
512
+ * handler: async (c: { query: { limit?: number } }) => c.query.limit
513
+ * ```
514
+ */
515
+ /**
516
+ * Creates a route with query/body validation schemas.
517
+ *
518
+ * Use `route()` when you need request validation. For simple handlers
519
+ * without validation, you can use bare functions directly in the router.
520
+ *
521
+ * @example
522
+ * ```typescript
523
+ * // Route with query validation
524
+ * get: route({
525
+ * query: { limit: 'number?', offset: 'number?' },
526
+ * handler: async (c) => {
527
+ * const items = await db.list(c.query.limit, c.query.offset);
528
+ * return { items };
529
+ * },
530
+ * })
531
+ *
532
+ * // Route with body validation
533
+ * post: route({
534
+ * body: { name: 'string', email: 'string' },
535
+ * handler: async (c) => {
536
+ * const user = await db.create(c.body);
537
+ * return user;
538
+ * },
539
+ * })
540
+ *
541
+ * // Simple handler without validation (bare function)
542
+ * get: async () => ({ status: 'ok' })
543
+ * ```
544
+ */
545
+ function route(definition) {
546
+ return {
547
+ ...definition,
548
+ [ROUTE_MARKER]: true
549
+ };
550
+ }
551
+ /** Creates a chainable context builder. */
552
+ function createCtxBuilder() {
553
+ const builder = (definition) => ({
554
+ ...definition,
555
+ [ROUTE_MARKER]: true
556
+ });
557
+ builder.ctx = () => createCtxBuilder();
558
+ return builder;
559
+ }
560
+ /**
561
+ * Creates a route with typed context for values not covered by schemas.
562
+ *
563
+ * Use `route.ctx<T>()` to type:
564
+ * - **Path params**: `{ path: { id: string } }` for `$id` segments
565
+ * - **Env bindings**: `{ env: { DB: Database } }` for runtime environment
566
+ * - **Middleware values**: `{ user: User }` for auth middleware, etc.
567
+ *
568
+ * Context provides types only, not runtime validation. For validated inputs,
569
+ * use `query` and `body` schemas instead.
570
+ *
571
+ * @example
572
+ * ```typescript
573
+ * interface AppContext {
574
+ * path: { id: string };
575
+ * env: { DB: D1Database };
576
+ * user: { id: string }; // injected by auth middleware
577
+ * }
578
+ *
579
+ * $id: router({
580
+ * get: route.ctx<AppContext>()({
581
+ * query: { include: 'string?' }, // schema for validation
582
+ * handler: async (c) => {
583
+ * // c.path.id, c.env.DB, c.user.id - from context
584
+ * // c.query.include - from schema
585
+ * return c.env.DB.get(c.path.id);
586
+ * },
587
+ * }),
588
+ * })
589
+ * ```
590
+ */
591
+ route.ctx = () => createCtxBuilder();
592
+ /**
593
+ * Creates a router that groups paths and applies middleware.
594
+ *
595
+ * @example
596
+ * ```typescript
597
+ * const api = router({
598
+ * health: router({
599
+ * get: async () => ({ status: 'ok' }),
600
+ * }),
601
+ *
602
+ * users: router({
603
+ * // GET /users - list users
604
+ * get: route({
605
+ * query: { limit: 'number?' },
606
+ * handler: async (c) => db.users.list(c.query.limit),
607
+ * }),
608
+ *
609
+ * // POST /users - create user
610
+ * post: route({
611
+ * body: { name: 'string', email: 'string' },
612
+ * handler: async (c) => db.users.create(c.body),
613
+ * }),
614
+ *
615
+ * // /users/:id
616
+ * $id: router({
617
+ * get: async (c) => db.users.get(c.path.id),
618
+ * delete: async (c) => db.users.delete(c.path.id),
619
+ * }),
620
+ * }),
621
+ * });
622
+ *
623
+ * export default { fetch: api.handler() };
624
+ * ```
625
+ */
626
+ function router(routes, ...middleware) {
627
+ const self = {
628
+ routes,
629
+ middleware: middleware.length > 0 ? middleware : void 0,
630
+ handler() {
631
+ return createHandler(self);
632
+ }
633
+ };
634
+ self[ROUTER_MARKER] = true;
635
+ return self;
636
+ }
637
+
638
+ //#endregion
639
+ //#region src/docs.ts
640
+ /**
641
+ * @fileoverview OpenAPI documentation generation.
642
+ *
643
+ * Generates OpenAPI 3.0 documentation from router definitions.
644
+ *
645
+ * **Path Convention:**
646
+ * - Property names = URL path segments
647
+ * - `$param` prefix = dynamic segment (`{param}` in OpenAPI)
648
+ * - `get`, `post`, `put`, `patch`, `delete` = HTTP method handlers
649
+ */
650
+ /** Converts property name to path segment, handling $param convention. */
651
+ function propertyToSegment(prop) {
652
+ if (prop.startsWith("$")) return `{${prop.slice(1)}}`;
653
+ return prop;
654
+ }
655
+ /** Collects all routes from a router tree, with `{param}` path segments. */
656
+ function collectRoutes(routerDef, parentPath = "") {
657
+ const collectedRoutes = [];
658
+ for (const [prop, entry] of Object.entries(routerDef.routes)) if (HTTP_METHODS.has(prop)) {
659
+ const path = parentPath || "/";
660
+ if (isFunction(entry)) collectedRoutes.push({
661
+ path,
662
+ method: prop,
663
+ route: null
664
+ });
665
+ else if (isRoute(entry)) collectedRoutes.push({
666
+ path,
667
+ method: prop,
668
+ route: entry
669
+ });
670
+ } else if (isRouter(entry)) {
671
+ const segment = propertyToSegment(prop);
672
+ const newPath = parentPath ? `${parentPath}/${segment}` : `/${segment}`;
673
+ collectedRoutes.push(...collectRoutes(entry, newPath));
674
+ }
675
+ return collectedRoutes;
676
+ }
677
+ /** Generates OpenAPI documentation from a router. */
678
+ function generateDocs(config) {
679
+ const paths = {};
680
+ const allRoutes = collectRoutes(config.router);
681
+ for (const { path, method, route: route$1 } of allRoutes) {
682
+ if (!paths[path]) paths[path] = {};
683
+ const operation = {
684
+ operationId: route$1?.operationId,
685
+ description: route$1?.description,
686
+ responses: {
687
+ 200: { description: "Successful response" },
688
+ 400: { description: "Validation error" }
689
+ }
690
+ };
691
+ if (route$1?.query) {
692
+ const querySchema = route$1.query;
693
+ operation.parameters = Object.entries(querySchema).filter(([, type]) => typeof type === "string").map(([name, type]) => ({
694
+ name,
695
+ in: "query",
696
+ required: !type.endsWith("?"),
697
+ description: route$1.descriptions?.[name],
698
+ schema: { type: type.replace("?", "").replace("[]", "") }
699
+ }));
700
+ }
701
+ if (route$1?.body && [
702
+ "post",
703
+ "put",
704
+ "patch"
705
+ ].includes(method)) operation.requestBody = {
706
+ required: true,
707
+ content: { "application/json": { schema: toJsonSchema(route$1.body, route$1.descriptions) } }
708
+ };
709
+ paths[path][method] = operation;
710
+ }
711
+ return {
712
+ openapi: "3.0.0",
713
+ info: {
714
+ title: config.title,
715
+ version: config.version,
716
+ description: config.description
717
+ },
718
+ paths
719
+ };
720
+ }
721
+
722
+ //#endregion
723
+ export { isFunction as a, compileSchema as c, router as i, toJsonSchema as l, generateDocs as n, isRoute as o, route as r, isRouter as s, collectRoutes as t };
724
+ //# sourceMappingURL=docs-B1IFBS_w.mjs.map