@taserjs/router 0.0.1 → 0.0.3

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 (142) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/constants.cjs.map +1 -1
  3. package/dist/cjs/create-context.cjs.map +1 -1
  4. package/dist/cjs/define/handler.cjs.map +1 -1
  5. package/dist/cjs/define/middleware.cjs +5 -24
  6. package/dist/cjs/define/middleware.cjs.map +1 -1
  7. package/dist/cjs/define/middleware.d.cts +10 -79
  8. package/dist/cjs/define/validators.cjs.map +1 -1
  9. package/dist/cjs/factories.cjs.map +1 -1
  10. package/dist/cjs/factories.d.cts +2 -2
  11. package/dist/cjs/index.cjs +7 -2
  12. package/dist/cjs/index.d.cts +2 -2
  13. package/dist/cjs/middleware/body-limit.cjs +2 -2
  14. package/dist/cjs/middleware/body-limit.cjs.map +1 -1
  15. package/dist/cjs/middleware/compress.cjs +2 -2
  16. package/dist/cjs/middleware/compress.cjs.map +1 -1
  17. package/dist/cjs/middleware/cors.cjs +2 -2
  18. package/dist/cjs/middleware/cors.cjs.map +1 -1
  19. package/dist/cjs/middleware/csrf.cjs +2 -2
  20. package/dist/cjs/middleware/csrf.cjs.map +1 -1
  21. package/dist/cjs/middleware/etag.cjs +2 -2
  22. package/dist/cjs/middleware/etag.cjs.map +1 -1
  23. package/dist/cjs/middleware/jwk.cjs +11 -4
  24. package/dist/cjs/middleware/jwk.cjs.map +1 -1
  25. package/dist/cjs/middleware/jwk.d.cts +4 -5
  26. package/dist/cjs/middleware/jwt.cjs +11 -5
  27. package/dist/cjs/middleware/jwt.cjs.map +1 -1
  28. package/dist/cjs/middleware/jwt.d.cts +7 -5
  29. package/dist/cjs/middleware/secure-headers.cjs +2 -2
  30. package/dist/cjs/middleware/secure-headers.cjs.map +1 -1
  31. package/dist/cjs/middleware/timing.cjs +2 -2
  32. package/dist/cjs/middleware/timing.cjs.map +1 -1
  33. package/dist/cjs/middleware/wrap-hono.cjs +9 -0
  34. package/dist/cjs/middleware/wrap-hono.cjs.map +1 -0
  35. package/dist/cjs/middleware/wrap-hono.d.cts +3 -0
  36. package/dist/cjs/middleware.cjs.map +1 -1
  37. package/dist/cjs/reply.cjs +20 -0
  38. package/dist/cjs/reply.d.cts +2 -0
  39. package/dist/cjs/route.cjs.map +1 -1
  40. package/dist/cjs/route.d.cts +1 -1
  41. package/dist/cjs/stream.cjs +32 -0
  42. package/dist/cjs/stream.d.cts +1 -0
  43. package/dist/cjs/taser-app.cjs +0 -6
  44. package/dist/cjs/taser-app.cjs.map +1 -1
  45. package/dist/cjs/taser-app.d.cts +0 -3
  46. package/dist/cjs/taser-router.cjs +9 -10
  47. package/dist/cjs/taser-router.cjs.map +1 -1
  48. package/dist/cjs/taser-router.d.cts +9 -11
  49. package/dist/cjs/types/app.d.cts +3 -2
  50. package/dist/cjs/types/index.d.cts +53 -139
  51. package/dist/cjs/types/type-utils.d.cts +8 -11
  52. package/dist/cjs/types/units.cjs.map +1 -1
  53. package/dist/cjs/types/units.d.cts +27 -24
  54. package/dist/esm/constants.js.map +1 -1
  55. package/dist/esm/create-context.js.map +1 -1
  56. package/dist/esm/define/handler.js.map +1 -1
  57. package/dist/esm/define/middleware.d.ts +10 -79
  58. package/dist/esm/define/middleware.js +5 -24
  59. package/dist/esm/define/middleware.js.map +1 -1
  60. package/dist/esm/define/validators.js.map +1 -1
  61. package/dist/esm/factories.d.ts +2 -2
  62. package/dist/esm/factories.js.map +1 -1
  63. package/dist/esm/index.d.ts +2 -2
  64. package/dist/esm/index.js +4 -4
  65. package/dist/esm/middleware/body-limit.js +1 -1
  66. package/dist/esm/middleware/body-limit.js.map +1 -1
  67. package/dist/esm/middleware/compress.js +1 -1
  68. package/dist/esm/middleware/compress.js.map +1 -1
  69. package/dist/esm/middleware/cors.js +1 -1
  70. package/dist/esm/middleware/cors.js.map +1 -1
  71. package/dist/esm/middleware/csrf.js +1 -1
  72. package/dist/esm/middleware/csrf.js.map +1 -1
  73. package/dist/esm/middleware/etag.js +1 -1
  74. package/dist/esm/middleware/etag.js.map +1 -1
  75. package/dist/esm/middleware/jwk.d.ts +4 -5
  76. package/dist/esm/middleware/jwk.js +11 -4
  77. package/dist/esm/middleware/jwk.js.map +1 -1
  78. package/dist/esm/middleware/jwt.d.ts +7 -5
  79. package/dist/esm/middleware/jwt.js +11 -5
  80. package/dist/esm/middleware/jwt.js.map +1 -1
  81. package/dist/esm/middleware/secure-headers.js +1 -1
  82. package/dist/esm/middleware/secure-headers.js.map +1 -1
  83. package/dist/esm/middleware/timing.js +1 -1
  84. package/dist/esm/middleware/timing.js.map +1 -1
  85. package/dist/esm/middleware/wrap-hono.d.ts +3 -0
  86. package/dist/esm/middleware/wrap-hono.js +9 -0
  87. package/dist/esm/middleware/wrap-hono.js.map +1 -0
  88. package/dist/esm/middleware.js.map +1 -1
  89. package/dist/esm/reply.d.ts +2 -0
  90. package/dist/esm/reply.js +2 -0
  91. package/dist/esm/route.d.ts +1 -1
  92. package/dist/esm/route.js.map +1 -1
  93. package/dist/esm/stream.d.ts +1 -0
  94. package/dist/esm/stream.js +2 -0
  95. package/dist/esm/taser-app.d.ts +0 -3
  96. package/dist/esm/taser-app.js +1 -6
  97. package/dist/esm/taser-app.js.map +1 -1
  98. package/dist/esm/taser-router.d.ts +9 -11
  99. package/dist/esm/taser-router.js +7 -8
  100. package/dist/esm/taser-router.js.map +1 -1
  101. package/dist/esm/types/app.d.ts +3 -2
  102. package/dist/esm/types/index.d.ts +53 -139
  103. package/dist/esm/types/type-utils.d.ts +8 -11
  104. package/dist/esm/types/units.d.ts +27 -24
  105. package/dist/esm/types/units.js.map +1 -1
  106. package/package.json +37 -17
  107. package/src/constants.ts +6 -6
  108. package/src/create-context.ts +8 -8
  109. package/src/define/handler.ts +24 -34
  110. package/src/define/middleware.ts +66 -256
  111. package/src/define/validators.ts +10 -10
  112. package/src/factories.ts +63 -61
  113. package/src/index.ts +13 -12
  114. package/src/middleware/body-limit.ts +5 -5
  115. package/src/middleware/compress.ts +5 -5
  116. package/src/middleware/cors.ts +5 -5
  117. package/src/middleware/csrf.ts +5 -5
  118. package/src/middleware/etag.ts +5 -5
  119. package/src/middleware/jwk.ts +33 -26
  120. package/src/middleware/jwt.ts +26 -10
  121. package/src/middleware/secure-headers.ts +5 -5
  122. package/src/middleware/timing.ts +5 -5
  123. package/src/middleware/wrap-hono.ts +12 -0
  124. package/src/middleware.ts +7 -7
  125. package/src/reply.ts +11 -0
  126. package/src/route.ts +45 -48
  127. package/src/stream.ts +1 -0
  128. package/src/taser-app.ts +13 -18
  129. package/src/taser-router.ts +103 -98
  130. package/src/types/app.ts +33 -35
  131. package/src/types/index.ts +299 -722
  132. package/src/types/returns.ts +92 -97
  133. package/src/types/schema.ts +8 -9
  134. package/src/types/type-utils.ts +42 -46
  135. package/src/types/units.ts +135 -104
  136. package/dist/cjs/middleware/auth.cjs +0 -34
  137. package/dist/cjs/middleware/auth.cjs.map +0 -1
  138. package/dist/cjs/middleware/auth.d.cts +0 -9
  139. package/dist/esm/middleware/auth.d.ts +0 -9
  140. package/dist/esm/middleware/auth.js +0 -33
  141. package/dist/esm/middleware/auth.js.map +0 -1
  142. package/src/middleware/auth.ts +0 -51
@@ -1,6 +1,5 @@
1
- import type { Awaitable, TaserCookieJar, TaserHeaders } from '@taserjs/router-core'
2
- import type { ReplyResult } from '@taserjs/router-utils'
3
- import type { RouterRegister } from '../register.js'
1
+ import type { Awaitable, TaserCookieJar, TaserHeaders } from "@taserjs/router-core";
2
+ import type { RouterRegister } from "../register.js";
4
3
  import type {
5
4
  MergeMiddlewareField,
6
5
  MergeMiddlewareInputField,
@@ -8,30 +7,32 @@ import type {
8
7
  RequestShape,
9
8
  RuntimeContextFields,
10
9
  Simplify,
11
- } from './type-utils.js'
12
- import type { ReturnsMap, ValidHandlerReply } from './returns.js'
13
- import type { Schema } from './schema.js'
10
+ } from "./type-utils.js";
11
+ import type { ReturnsMap, ValidHandlerReply } from "./returns.js";
12
+ import type { Schema } from "./schema.js";
14
13
  import type {
15
14
  AppContext,
15
+ ExtractState,
16
16
  HandlerContext,
17
17
  HandlerUnit,
18
+ InlineMiddlewareOptions,
18
19
  Method,
19
20
  MiddlewareDefinition,
20
21
  MiddlewareReturnFromParts,
21
22
  MiddlewareUnit,
22
23
  NativeContext,
23
24
  ValidatorParts,
24
- } from './units.js'
25
+ } from "./units.js";
25
26
 
26
- export type { Awaitable } from '@taserjs/router-core'
27
+ export type { Awaitable } from "@taserjs/router-core";
27
28
  export type {
28
29
  SchemaRequestShape,
29
30
  InferInput,
30
31
  InferOutput,
31
32
  Schema,
32
33
  StandardSchemaV1,
33
- } from './schema.js'
34
- export type { RouterRegister } from '../register.js'
34
+ } from "./schema.js";
35
+ export type { RouterRegister } from "../register.js";
35
36
  export type {
36
37
  MergeMiddlewareField,
37
38
  MergeMiddlewareInputField,
@@ -39,7 +40,7 @@ export type {
39
40
  RequestShape,
40
41
  Simplify,
41
42
  UnwrapPart,
42
- } from './type-utils.js'
43
+ } from "./type-utils.js";
43
44
  export type {
44
45
  EmptyReturns,
45
46
  EnforceHandlerReply,
@@ -50,112 +51,111 @@ export type {
50
51
  ReturnsMap,
51
52
  StatusCode,
52
53
  ValidHandlerReply,
53
- } from './returns.js'
54
+ } from "./returns.js";
54
55
  export type {
55
56
  AppContext,
57
+ ExtractState,
56
58
  HandlerContext,
57
59
  HandlerUnit,
58
60
  HttpMethod,
59
61
  InlineMiddlewareOptions,
62
+ IsUnknown,
60
63
  Method,
61
64
  MiddlewareDefinition,
62
65
  MiddlewareNext,
63
66
  MiddlewareReturnFromParts,
64
67
  MiddlewareUnit,
65
68
  NativeContext,
69
+ NextFn,
70
+ NextResult,
66
71
  StandaloneMiddlewareContext,
72
+ StateBrand,
67
73
  ValidatorParts,
68
- } from './units.js'
74
+ } from "./units.js";
69
75
 
70
- export type RoutePath = RouterRegister extends { RoutePath: infer P } ? P : never
71
- export type LayoutId = RouterRegister extends { LayoutId: infer L } ? L : never
72
- export type LayoutTree = RouterRegister extends { LayoutTree: infer T } ? T : Record<never, never>
76
+ export type RoutePath = RouterRegister extends { RoutePath: infer P } ? P : never;
77
+ export type LayoutId = RouterRegister extends { LayoutId: infer L } ? L : never;
78
+ export type LayoutTree = RouterRegister extends { LayoutTree: infer T } ? T : Record<never, never>;
73
79
  export type RouteByPathMethod = RouterRegister extends { RouteByPathMethod: infer R }
74
80
  ? R
75
- : Record<never, never>
76
-
77
- type ParseParam<Segment extends string>
78
- = Segment extends '*' ? { _splat: string }
79
- : Segment extends `:${infer Name extends string}`
80
- ? Name extends '' ? {} : { [K in Name]: string }
81
- : {}
82
-
83
- type ParseParamsFromSegments<S extends string>
84
- = S extends `${infer Segment}/${infer Rest}`
85
- ? ParseParam<Segment> & ParseParamsFromSegments<Rest>
86
- : ParseParam<S>
87
-
88
- export type PathParams<Path extends string>
89
- = Path extends `/${infer Rest}` ? ParseParamsFromSegments<Rest> : {}
90
-
91
- type LayoutParent<Layout extends LayoutId>
92
- = LayoutTree[Layout] extends { parent: infer Parent extends LayoutId | null }
93
- ? Parent
94
- : null
81
+ : Record<never, never>;
82
+
83
+ type ParseParam<Segment extends string> = Segment extends "*"
84
+ ? { _splat: string }
85
+ : Segment extends `:${infer Name extends string}`
86
+ ? Name extends ""
87
+ ? {}
88
+ : { [K in Name]: string }
89
+ : {};
90
+
91
+ type ParseParamsFromSegments<S extends string> = S extends `${infer Segment}/${infer Rest}`
92
+ ? ParseParam<Segment> & ParseParamsFromSegments<Rest>
93
+ : ParseParam<S>;
94
+
95
+ export type PathParams<Path extends string> = Path extends `/${infer Rest}`
96
+ ? ParseParamsFromSegments<Rest>
97
+ : {};
98
+
99
+ type LayoutParent<Layout extends LayoutId> = LayoutTree[Layout] extends {
100
+ parent: infer Parent extends LayoutId | null;
101
+ }
102
+ ? Parent
103
+ : null;
95
104
 
96
- type ResolveLayoutMiddlewares<Layout extends LayoutId | null>
97
- = Layout extends null ? readonly []
98
- : Layout extends LayoutId
99
- ? readonly [
105
+ type ResolveLayoutMiddlewares<Layout extends LayoutId | null> = Layout extends null
106
+ ? readonly []
107
+ : Layout extends LayoutId
108
+ ? readonly [
100
109
  ...ResolveLayoutMiddlewares<LayoutParent<Layout>>,
101
- ...LayoutTree[Layout]['middlewares'],
110
+ ...LayoutTree[Layout]["middlewares"],
102
111
  ]
103
- : readonly []
112
+ : readonly [];
104
113
 
105
114
  /** Fold layout middleware Acc from a route's layoutChain (shallow → deep). */
106
- type ResolveLayoutChainMiddlewares<Chain extends readonly LayoutId[]>
107
- = Chain extends readonly [infer Head extends LayoutId, ...infer Rest]
108
- ? readonly [
109
- ...LayoutTree[Head]['middlewares'],
110
- ...ResolveLayoutChainMiddlewares<
111
- Rest extends readonly LayoutId[] ? Rest : readonly []
112
- >,
115
+ type ResolveLayoutChainMiddlewares<Chain extends readonly LayoutId[]> = Chain extends readonly [
116
+ infer Head extends LayoutId,
117
+ ...infer Rest,
118
+ ]
119
+ ? readonly [
120
+ ...LayoutTree[Head]["middlewares"],
121
+ ...ResolveLayoutChainMiddlewares<Rest extends readonly LayoutId[] ? Rest : readonly []>,
113
122
  ]
114
- : readonly []
123
+ : readonly [];
115
124
 
116
- type RouteEntry<
117
- Path extends RoutePath,
118
- TMethod extends Method,
119
- > = RouteByPathMethod[Path] extends { [K in TMethod]: infer Entry } ? Entry : never
125
+ type RouteEntry<Path extends RoutePath, TMethod extends Method> = RouteByPathMethod[Path] extends {
126
+ [K in TMethod]: infer Entry;
127
+ }
128
+ ? Entry
129
+ : never;
120
130
 
121
- type RouteParent<Path extends RoutePath, TMethod extends Method>
122
- = RouteEntry<Path, TMethod> extends { parent: infer Parent extends LayoutId | null }
131
+ type RouteParent<Path extends RoutePath, TMethod extends Method> =
132
+ RouteEntry<Path, TMethod> extends { parent: infer Parent extends LayoutId | null }
123
133
  ? Parent
124
- : null
134
+ : null;
125
135
 
126
- type RouteLayoutChain<Path extends RoutePath, TMethod extends Method>
127
- = RouteEntry<Path, TMethod> extends { layoutChain: infer Chain extends readonly LayoutId[] }
136
+ type RouteLayoutChain<Path extends RoutePath, TMethod extends Method> =
137
+ RouteEntry<Path, TMethod> extends { layoutChain: infer Chain extends readonly LayoutId[] }
128
138
  ? Chain
129
139
  : RouteParent<Path, TMethod> extends LayoutId
130
140
  ? readonly [RouteParent<Path, TMethod>]
131
- : readonly []
141
+ : readonly [];
132
142
 
133
143
  type RouteResolvedField<
134
144
  Path extends RoutePath,
135
145
  TMethod extends Method,
136
146
  Acc extends readonly unknown[],
137
- Field extends 'query' | 'params' | 'body' | 'state' | 'ctx',
138
- > = MergeMiddlewareField<
139
- ResolveLayoutChainMiddlewares<RouteLayoutChain<Path, TMethod>>,
140
- Field
141
- > & MergeMiddlewareField<Acc, Field>
142
-
143
- type MiddlewareCtxField<
144
- Layout extends LayoutId,
145
- Field extends 'query' | 'params' | 'body' | 'state' | 'ctx',
146
- > = MergeMiddlewareField<
147
- ResolveLayoutMiddlewares<LayoutParent<Layout>>,
148
- Field
149
- >
147
+ Field extends "query" | "params" | "body" | "state",
148
+ > = MergeMiddlewareField<ResolveLayoutChainMiddlewares<RouteLayoutChain<Path, TMethod>>, Field> &
149
+ MergeMiddlewareField<Acc, Field>;
150
150
 
151
151
  type RouteChainField<
152
152
  Path extends RoutePath,
153
153
  TMethod extends Method,
154
154
  Acc extends readonly unknown[],
155
- Field extends 'query' | 'params' | 'body' | 'state' | 'ctx',
156
- > = RouteResolvedField<Path, TMethod, Acc, Field>
155
+ Field extends "query" | "params" | "body" | "state",
156
+ > = RouteResolvedField<Path, TMethod, Acc, Field>;
157
157
 
158
- type UnitRuntimeContext = Omit<RuntimeContextFields<NativeContext>, 'var'>
158
+ type UnitRuntimeContext = Omit<RuntimeContextFields<NativeContext>, "var">;
159
159
 
160
160
  export type RouteChainContext<
161
161
  Path extends RoutePath,
@@ -166,104 +166,110 @@ export type RouteChainContext<
166
166
  TBody,
167
167
  TAppContext extends Record<string, unknown> = AppContext,
168
168
  > = Simplify<
169
- TAppContext
170
- & UnitRuntimeContext
171
- & RouteChainField<Path, TMethod, Acc, 'ctx'>
172
- & {
173
- query: Simplify<MergePart<TQuery, RouteChainField<Path, TMethod, Acc, 'query'>>>
174
- params: Simplify<PathParams<Path> & MergePart<TParams, RouteChainField<Path, TMethod, Acc, 'params'>>>
175
- body: Simplify<MergePart<TBody, RouteChainField<Path, TMethod, Acc, 'body'>>>
176
- state: Simplify<RouteChainField<Path, TMethod, Acc, 'state'>>
177
- headers: TaserHeaders
178
- cookies: TaserCookieJar
179
- }
180
- >
169
+ TAppContext &
170
+ UnitRuntimeContext & {
171
+ query: Simplify<MergePart<TQuery, RouteChainField<Path, TMethod, Acc, "query">>>;
172
+ params: Simplify<
173
+ PathParams<Path> & MergePart<TParams, RouteChainField<Path, TMethod, Acc, "params">>
174
+ >;
175
+ body: Simplify<MergePart<TBody, RouteChainField<Path, TMethod, Acc, "body">>>;
176
+ state: Simplify<RouteChainField<Path, TMethod, Acc, "state">>;
177
+ headers: TaserHeaders;
178
+ cookies: TaserCookieJar;
179
+ }
180
+ >;
181
181
 
182
182
  export type RouteHandleContext<
183
183
  Path extends RoutePath,
184
184
  TMethod extends Method,
185
185
  Acc extends readonly unknown[],
186
186
  Validators extends {
187
- query?: unknown
188
- params?: unknown
189
- body?: unknown
187
+ query?: unknown;
188
+ params?: unknown;
189
+ body?: unknown;
190
190
  },
191
191
  TAppContext extends Record<string, unknown> = AppContext,
192
192
  > = Simplify<
193
- TAppContext
194
- & UnitRuntimeContext
195
- & RouteResolvedField<Path, TMethod, Acc, 'ctx'>
196
- & {
197
- path: Path
198
- method: TMethod
199
- query: Simplify<MergePart<
200
- Validators extends { query?: infer Q } ? Q : unknown,
201
- RouteResolvedField<Path, TMethod, Acc, 'query'>
202
- >>
203
- params: Simplify<PathParams<Path> & MergePart<
204
- Validators extends { params?: infer P } ? P : unknown,
205
- RouteResolvedField<Path, TMethod, Acc, 'params'>
206
- >>
207
- body: Simplify<MergePart<
208
- Validators extends { body?: infer B } ? B : unknown,
209
- RouteResolvedField<Path, TMethod, Acc, 'body'>
210
- >>
211
- state: Simplify<RouteResolvedField<Path, TMethod, Acc, 'state'>>
212
- headers: TaserHeaders
213
- cookies: TaserCookieJar
214
- }
215
- >
193
+ TAppContext &
194
+ UnitRuntimeContext & {
195
+ path: Path;
196
+ method: TMethod;
197
+ query: Simplify<
198
+ MergePart<
199
+ Validators extends { query?: infer Q } ? Q : unknown,
200
+ RouteResolvedField<Path, TMethod, Acc, "query">
201
+ >
202
+ >;
203
+ params: Simplify<
204
+ PathParams<Path> &
205
+ MergePart<
206
+ Validators extends { params?: infer P } ? P : unknown,
207
+ RouteResolvedField<Path, TMethod, Acc, "params">
208
+ >
209
+ >;
210
+ body: Simplify<
211
+ MergePart<
212
+ Validators extends { body?: infer B } ? B : unknown,
213
+ RouteResolvedField<Path, TMethod, Acc, "body">
214
+ >
215
+ >;
216
+ state: Simplify<RouteResolvedField<Path, TMethod, Acc, "state">>;
217
+ headers: TaserHeaders;
218
+ cookies: TaserCookieJar;
219
+ }
220
+ >;
216
221
 
217
222
  export type RouteHandleContextWithoutBody<
218
223
  Path extends RoutePath,
219
224
  TMethod extends Method,
220
225
  Acc extends readonly unknown[],
221
226
  Validators extends {
222
- query?: unknown
223
- params?: unknown
227
+ query?: unknown;
228
+ params?: unknown;
224
229
  },
225
230
  TAppContext extends Record<string, unknown> = AppContext,
226
231
  > = Simplify<
227
- TAppContext
228
- & UnitRuntimeContext
229
- & RouteResolvedField<Path, TMethod, Acc, 'ctx'>
230
- & {
231
- path: Path
232
- method: TMethod
233
- query: Simplify<MergePart<
234
- Validators extends { query?: infer Q } ? Q : unknown,
235
- RouteResolvedField<Path, TMethod, Acc, 'query'>
236
- >>
237
- params: Simplify<PathParams<Path> & MergePart<
238
- Validators extends { params?: infer P } ? P : unknown,
239
- RouteResolvedField<Path, TMethod, Acc, 'params'>
240
- >>
241
- body: never
242
- state: Simplify<RouteResolvedField<Path, TMethod, Acc, 'state'>>
243
- headers: TaserHeaders
244
- cookies: TaserCookieJar
245
- }
246
- >
232
+ TAppContext &
233
+ UnitRuntimeContext & {
234
+ path: Path;
235
+ method: TMethod;
236
+ query: Simplify<
237
+ MergePart<
238
+ Validators extends { query?: infer Q } ? Q : unknown,
239
+ RouteResolvedField<Path, TMethod, Acc, "query">
240
+ >
241
+ >;
242
+ params: Simplify<
243
+ PathParams<Path> &
244
+ MergePart<
245
+ Validators extends { params?: infer P } ? P : unknown,
246
+ RouteResolvedField<Path, TMethod, Acc, "params">
247
+ >
248
+ >;
249
+ body: never;
250
+ state: Simplify<RouteResolvedField<Path, TMethod, Acc, "state">>;
251
+ headers: TaserHeaders;
252
+ cookies: TaserCookieJar;
253
+ }
254
+ >;
247
255
 
248
256
  type RouteResolvedInputField<
249
257
  Path extends RoutePath,
250
258
  TMethod extends Method,
251
259
  Acc extends readonly unknown[],
252
- Field extends 'query' | 'params' | 'body',
260
+ Field extends "query" | "params" | "body",
253
261
  > = MergeMiddlewareInputField<
254
262
  ResolveLayoutChainMiddlewares<RouteLayoutChain<Path, TMethod>>,
255
263
  Field
256
- > & MergeMiddlewareInputField<Acc, Field>
264
+ > &
265
+ MergeMiddlewareInputField<Acc, Field>;
257
266
 
258
- type IsNever<T> = [T] extends [never] ? true : false
267
+ type IsNever<T> = [T] extends [never] ? true : false;
259
268
 
260
- type IsEmptyObject<T> = [keyof T] extends [never] ? true : false
269
+ type IsEmptyObject<T> = [keyof T] extends [never] ? true : false;
261
270
 
262
- type InputFacet<T, K extends string> = IsNever<T> extends true
263
- ? {}
264
- : IsEmptyObject<T> extends true
265
- ? {}
266
- : { [Key in K]: T }
271
+ type InputFacet<T, K extends string> =
272
+ IsNever<T> extends true ? {} : IsEmptyObject<T> extends true ? {} : { [Key in K]: T };
267
273
 
268
274
  type RouteQueryInput<
269
275
  Path extends RoutePath,
@@ -276,9 +282,9 @@ type RouteQueryInput<
276
282
  Validators extends { queryIn?: infer QI } ? QI : unknown,
277
283
  Validators extends { query?: infer Q } ? Q : unknown
278
284
  >,
279
- RouteResolvedInputField<Path, TMethod, Acc, 'query'>
285
+ RouteResolvedInputField<Path, TMethod, Acc, "query">
280
286
  >
281
- >
287
+ >;
282
288
 
283
289
  type RouteParamsInput<
284
290
  Path extends RoutePath,
@@ -286,14 +292,15 @@ type RouteParamsInput<
286
292
  Acc extends readonly unknown[],
287
293
  Validators extends ValidatorParts,
288
294
  > = Simplify<
289
- PathParams<Path> & MergePart<
290
- RequestShape<
291
- Validators extends { paramsIn?: infer PI } ? PI : unknown,
292
- Validators extends { params?: infer P } ? P : unknown
293
- >,
294
- RouteResolvedInputField<Path, TMethod, Acc, 'params'>
295
- >
296
- >
295
+ PathParams<Path> &
296
+ MergePart<
297
+ RequestShape<
298
+ Validators extends { paramsIn?: infer PI } ? PI : unknown,
299
+ Validators extends { params?: infer P } ? P : unknown
300
+ >,
301
+ RouteResolvedInputField<Path, TMethod, Acc, "params">
302
+ >
303
+ >;
297
304
 
298
305
  type RouteBodyInput<
299
306
  Path extends RoutePath,
@@ -306,9 +313,9 @@ type RouteBodyInput<
306
313
  Validators extends { bodyIn?: infer BI } ? BI : unknown,
307
314
  Validators extends { body?: infer B } ? B : unknown
308
315
  >,
309
- RouteResolvedInputField<Path, TMethod, Acc, 'body'>
316
+ RouteResolvedInputField<Path, TMethod, Acc, "body">
310
317
  >
311
- >
318
+ >;
312
319
 
313
320
  export type RouteHandleInputWithoutBody<
314
321
  Path extends RoutePath,
@@ -316,9 +323,9 @@ export type RouteHandleInputWithoutBody<
316
323
  Acc extends readonly unknown[],
317
324
  Validators extends ValidatorParts = {},
318
325
  > = Simplify<
319
- InputFacet<RouteQueryInput<Path, TMethod, Acc, Validators>, 'query'>
320
- & InputFacet<RouteParamsInput<Path, TMethod, Acc, Validators>, 'params'>
321
- >
326
+ InputFacet<RouteQueryInput<Path, TMethod, Acc, Validators>, "query"> &
327
+ InputFacet<RouteParamsInput<Path, TMethod, Acc, Validators>, "params">
328
+ >;
322
329
 
323
330
  export type RouteHandleInput<
324
331
  Path extends RoutePath,
@@ -326,22 +333,23 @@ export type RouteHandleInput<
326
333
  Acc extends readonly unknown[],
327
334
  Validators extends ValidatorParts = {},
328
335
  > = Simplify<
329
- RouteHandleInputWithoutBody<Path, TMethod, Acc, Validators>
330
- & InputFacet<RouteBodyInput<Path, TMethod, Acc, Validators>, 'body'>
331
- >
336
+ RouteHandleInputWithoutBody<Path, TMethod, Acc, Validators> &
337
+ InputFacet<RouteBodyInput<Path, TMethod, Acc, Validators>, "body">
338
+ >;
332
339
 
333
- export type InferRouteInput<
334
- Path extends RoutePath,
335
- TMethod extends Method,
336
- > = RouteEntry<Path, TMethod> extends { route: infer Route }
337
- ? Route extends { $Infer: { Input: infer I } } ? I : never
338
- : never
340
+ export type InferRouteInput<Path extends RoutePath, TMethod extends Method> =
341
+ RouteEntry<Path, TMethod> extends { route: infer Route }
342
+ ? Route extends { $Infer: { Input: infer I } }
343
+ ? I
344
+ : never
345
+ : never;
339
346
 
340
347
  type MiddlewareChainField<
341
348
  Layout extends LayoutId,
342
349
  Acc extends readonly unknown[],
343
- Field extends 'query' | 'params' | 'body' | 'state' | 'ctx',
344
- > = MiddlewareCtxField<Layout, Field> & MergeMiddlewareField<Acc, Field>
350
+ Field extends "query" | "params" | "body" | "state",
351
+ > = MergeMiddlewareField<ResolveLayoutMiddlewares<LayoutParent<Layout>>, Field> &
352
+ MergeMiddlewareField<Acc, Field>;
345
353
 
346
354
  export type MiddlewareChainContext<
347
355
  Layout extends LayoutId,
@@ -351,194 +359,31 @@ export type MiddlewareChainContext<
351
359
  TBody,
352
360
  TAppContext extends Record<string, unknown> = AppContext,
353
361
  > = Simplify<
354
- TAppContext
355
- & UnitRuntimeContext
356
- & MiddlewareChainField<Layout, Acc, 'ctx'>
357
- & {
358
- query: Simplify<MergePart<TQuery, MiddlewareChainField<Layout, Acc, 'query'>>>
359
- params: Simplify<MergePart<TParams, MiddlewareChainField<Layout, Acc, 'params'>>>
360
- body: Simplify<MergePart<TBody, MiddlewareChainField<Layout, Acc, 'body'>>>
361
- state: Simplify<MiddlewareChainField<Layout, Acc, 'state'>>
362
- headers: TaserHeaders
363
- cookies: TaserCookieJar
364
- }
365
- >
366
-
367
- type StatefulUseOptions<
368
- Ctx,
369
- TState,
370
- TQuery,
371
- TParams,
372
- TBody,
373
- TReturns extends ReturnsMap = {},
374
- TQueryIn = unknown,
375
- TParamsIn = unknown,
376
- TBodyIn = unknown,
377
- > = {
378
- state: Schema<TState>
379
- query?: Schema<TQuery, TQueryIn>
380
- params?: Schema<TParams, TParamsIn>
381
- body?: Schema<TBody, TBodyIn>
382
- returns?: TReturns
383
- handler: (
384
- ctx: Ctx,
385
- next: (args: { state: TState }) => Promise<ReplyResult>,
386
- ) => Awaitable<ReplyResult | Response | unknown>
387
- }
388
-
389
- type CtxUseOptions<
390
- Ctx,
391
- TCtx,
392
- TQuery,
393
- TParams,
394
- TBody,
395
- TReturns extends ReturnsMap = {},
396
- TQueryIn = unknown,
397
- TParamsIn = unknown,
398
- TBodyIn = unknown,
399
- > = {
400
- ctx: Schema<TCtx>
401
- query?: Schema<TQuery, TQueryIn>
402
- params?: Schema<TParams, TParamsIn>
403
- body?: Schema<TBody, TBodyIn>
404
- returns?: TReturns
405
- handler: (
406
- ctx: Ctx,
407
- next: (args: { ctx: TCtx }) => Promise<ReplyResult>,
408
- ) => Awaitable<ReplyResult | Response | unknown>
409
- }
410
-
411
- type StateAndCtxUseOptions<
412
- Ctx,
413
- TState,
414
- TCtx,
415
- TQuery,
416
- TParams,
417
- TBody,
418
- TReturns extends ReturnsMap = {},
419
- TQueryIn = unknown,
420
- TParamsIn = unknown,
421
- TBodyIn = unknown,
422
- > = {
423
- state: Schema<TState>
424
- ctx: Schema<TCtx>
425
- query?: Schema<TQuery, TQueryIn>
426
- params?: Schema<TParams, TParamsIn>
427
- body?: Schema<TBody, TBodyIn>
428
- returns?: TReturns
429
- handler: (
430
- ctx: Ctx,
431
- next: (args: { state: TState, ctx: TCtx }) => Promise<ReplyResult>,
432
- ) => Awaitable<ReplyResult | Response | unknown>
433
- }
434
-
435
- type StatelessUseOptions<
436
- Ctx,
437
- TQuery,
438
- TParams,
439
- TBody,
440
- TReturns extends ReturnsMap = {},
441
- TQueryIn = unknown,
442
- TParamsIn = unknown,
443
- TBodyIn = unknown,
444
- > = {
445
- query?: Schema<TQuery, TQueryIn>
446
- params?: Schema<TParams, TParamsIn>
447
- body?: Schema<TBody, TBodyIn>
448
- returns?: TReturns
449
- handler: (
450
- ctx: Ctx,
451
- next: () => Promise<ReplyResult>,
452
- ) => Awaitable<ReplyResult | Response | unknown>
453
- }
362
+ TAppContext &
363
+ UnitRuntimeContext & {
364
+ query: Simplify<MergePart<TQuery, MiddlewareChainField<Layout, Acc, "query">>>;
365
+ params: Simplify<MergePart<TParams, MiddlewareChainField<Layout, Acc, "params">>>;
366
+ body: Simplify<MergePart<TBody, MiddlewareChainField<Layout, Acc, "body">>>;
367
+ state: Simplify<MiddlewareChainField<Layout, Acc, "state">>;
368
+ headers: TaserHeaders;
369
+ cookies: TaserCookieJar;
370
+ }
371
+ >;
454
372
 
455
373
  export type MiddlewareBuilder<
456
374
  Layout extends LayoutId,
457
375
  Acc extends readonly unknown[] = readonly [],
458
376
  TAppContext extends Record<string, unknown> = AppContext,
459
377
  > = Acc & {
460
- readonly layout: Layout
461
- readonly middlewares: readonly MiddlewareDefinition[]
378
+ readonly layout: Layout;
379
+ readonly middlewares: readonly MiddlewareDefinition[];
462
380
  readonly $Infer: {
463
- Context: MiddlewareChainContext<Layout, Acc, unknown, unknown, unknown, TAppContext>
464
- }
381
+ Context: MiddlewareChainContext<Layout, Acc, unknown, unknown, unknown, TAppContext>;
382
+ };
465
383
  use<TAcc, TReturns extends ReturnsMap = {}>(
466
384
  unit: MiddlewareUnit<TAcc, TReturns>,
467
- ): MiddlewareBuilder<Layout, readonly [...Acc, TAcc], TAppContext>
468
- use<
469
- TState,
470
- TCtx,
471
- TQuery = unknown,
472
- TParams = unknown,
473
- TBody = unknown,
474
- TReturns extends ReturnsMap = {},
475
- TQueryIn = unknown,
476
- TParamsIn = unknown,
477
- TBodyIn = unknown,
478
- >(
479
- options: StateAndCtxUseOptions<
480
- MiddlewareChainContext<Layout, Acc, TQuery, TParams, TBody, TAppContext>,
481
- TState,
482
- TCtx,
483
- TQuery,
484
- TParams,
485
- TBody,
486
- TReturns,
487
- TQueryIn,
488
- TParamsIn,
489
- TBodyIn
490
- >,
491
- ): MiddlewareBuilder<
492
- Layout,
493
- readonly [...Acc, MiddlewareReturnFromParts<
494
- TQuery,
495
- TParams,
496
- TBody,
497
- TState,
498
- TCtx,
499
- TQueryIn,
500
- TParamsIn,
501
- TBodyIn
502
- >],
503
- TAppContext
504
- >
505
- use<
506
- TState,
507
- TQuery = unknown,
508
- TParams = unknown,
509
- TBody = unknown,
510
- TReturns extends ReturnsMap = {},
511
- TQueryIn = unknown,
512
- TParamsIn = unknown,
513
- TBodyIn = unknown,
514
- >(
515
- options: StatefulUseOptions<
516
- MiddlewareChainContext<Layout, Acc, TQuery, TParams, TBody, TAppContext>,
517
- TState,
518
- TQuery,
519
- TParams,
520
- TBody,
521
- TReturns,
522
- TQueryIn,
523
- TParamsIn,
524
- TBodyIn
525
- >,
526
- ): MiddlewareBuilder<
527
- Layout,
528
- readonly [...Acc, MiddlewareReturnFromParts<
529
- TQuery,
530
- TParams,
531
- TBody,
532
- TState,
533
- unknown,
534
- TQueryIn,
535
- TParamsIn,
536
- TBodyIn
537
- >],
538
- TAppContext
539
- >
385
+ ): MiddlewareBuilder<Layout, readonly [...Acc, TAcc], TAppContext>;
540
386
  use<
541
- TCtx,
542
387
  TQuery = unknown,
543
388
  TParams = unknown,
544
389
  TBody = unknown,
@@ -546,66 +391,36 @@ export type MiddlewareBuilder<
546
391
  TQueryIn = unknown,
547
392
  TParamsIn = unknown,
548
393
  TBodyIn = unknown,
394
+ R = unknown,
549
395
  >(
550
- options: CtxUseOptions<
396
+ options: InlineMiddlewareOptions<
551
397
  MiddlewareChainContext<Layout, Acc, TQuery, TParams, TBody, TAppContext>,
552
- TCtx,
553
398
  TQuery,
554
399
  TParams,
555
400
  TBody,
556
401
  TReturns,
557
402
  TQueryIn,
558
403
  TParamsIn,
559
- TBodyIn
404
+ TBodyIn,
405
+ R
560
406
  >,
561
407
  ): MiddlewareBuilder<
562
408
  Layout,
563
- readonly [...Acc, MiddlewareReturnFromParts<
564
- TQuery,
565
- TParams,
566
- TBody,
567
- {},
568
- TCtx,
569
- TQueryIn,
570
- TParamsIn,
571
- TBodyIn
572
- >],
573
- TAppContext
574
- >
575
- use<
576
- TQuery = unknown,
577
- TParams = unknown,
578
- TBody = unknown,
579
- TReturns extends ReturnsMap = {},
580
- TQueryIn = unknown,
581
- TParamsIn = unknown,
582
- TBodyIn = unknown,
583
- >(
584
- options: StatelessUseOptions<
585
- MiddlewareChainContext<Layout, Acc, TQuery, TParams, TBody, TAppContext>,
586
- TQuery,
587
- TParams,
588
- TBody,
589
- TReturns,
590
- TQueryIn,
591
- TParamsIn,
592
- TBodyIn
593
- >,
594
- ): MiddlewareBuilder<
595
- Layout,
596
- readonly [...Acc, MiddlewareReturnFromParts<
597
- TQuery,
598
- TParams,
599
- TBody,
600
- {},
601
- unknown,
602
- TQueryIn,
603
- TParamsIn,
604
- TBodyIn
605
- >],
409
+ readonly [
410
+ ...Acc,
411
+ MiddlewareReturnFromParts<
412
+ TQuery,
413
+ TParams,
414
+ TBody,
415
+ ExtractState<R>,
416
+ TQueryIn,
417
+ TParamsIn,
418
+ TBodyIn
419
+ >,
420
+ ],
606
421
  TAppContext
607
- >
608
- }
422
+ >;
423
+ };
609
424
 
610
425
  export type RouteExport<
611
426
  Path extends RoutePath,
@@ -614,27 +429,27 @@ export type RouteExport<
614
429
  TReturns extends ReturnsMap = {},
615
430
  TOutput = Response,
616
431
  > = Acc & {
617
- readonly path: Path
618
- readonly method: TMethod | 'ANY' | 'ALL'
619
- readonly methods?: readonly Method[]
620
- readonly middlewares: readonly MiddlewareDefinition[]
621
- readonly handlerMiddlewares: readonly MiddlewareDefinition[]
622
- readonly returns?: TReturns
623
- handler: (ctx: unknown) => Awaitable<Response>
432
+ readonly path: Path;
433
+ readonly method: TMethod | "ANY" | "ALL";
434
+ readonly methods?: readonly Method[];
435
+ readonly middlewares: readonly MiddlewareDefinition[];
436
+ readonly handlerMiddlewares: readonly MiddlewareDefinition[];
437
+ readonly returns?: TReturns;
438
+ handler: (ctx: unknown) => Awaitable<Response>;
624
439
  readonly $Infer: {
625
- Context: TMethod extends 'GET' | 'DELETE' | 'HEAD' | 'OPTIONS'
440
+ Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS"
626
441
  ? RouteHandleContextWithoutBody<Path, TMethod, Acc, {}>
627
- : RouteHandleContext<Path, TMethod, Acc, {}>
442
+ : RouteHandleContext<Path, TMethod, Acc, {}>;
628
443
  /** Concrete handler reply (`ReplyOf` union) for client inference. */
629
- Output: TOutput
630
- }
631
- query?: Schema<unknown>
632
- params?: Schema<unknown>
633
- body?: Schema<unknown>
634
- handlerQuery?: Schema<unknown>
635
- handlerParams?: Schema<unknown>
636
- handlerBody?: Schema<unknown>
637
- }
444
+ Output: TOutput;
445
+ };
446
+ query?: Schema<unknown>;
447
+ params?: Schema<unknown>;
448
+ body?: Schema<unknown>;
449
+ handlerQuery?: Schema<unknown>;
450
+ handlerParams?: Schema<unknown>;
451
+ handlerBody?: Schema<unknown>;
452
+ };
638
453
 
639
454
  type RouteHandleResult<
640
455
  Path extends RoutePath,
@@ -644,17 +459,17 @@ type RouteHandleResult<
644
459
  TReturns extends ReturnsMap = {},
645
460
  TOutput = Response,
646
461
  TAppContext extends Record<string, unknown> = AppContext,
647
- > = Omit<RouteExport<Path, TMethod, Acc, TReturns, TOutput>, '$Infer'> & {
462
+ > = Omit<RouteExport<Path, TMethod, Acc, TReturns, TOutput>, "$Infer"> & {
648
463
  readonly $Infer: {
649
- Context: TMethod extends 'GET' | 'DELETE' | 'HEAD' | 'OPTIONS'
464
+ Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS"
650
465
  ? RouteHandleContextWithoutBody<Path, TMethod, Acc, Validators, TAppContext>
651
- : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>
652
- Input: TMethod extends 'GET' | 'DELETE' | 'HEAD' | 'OPTIONS'
466
+ : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>;
467
+ Input: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS"
653
468
  ? RouteHandleInputWithoutBody<Path, TMethod, Acc, Validators>
654
- : RouteHandleInput<Path, TMethod, Acc, Validators>
655
- Output: TOutput
656
- }
657
- }
469
+ : RouteHandleInput<Path, TMethod, Acc, Validators>;
470
+ Output: TOutput;
471
+ };
472
+ };
658
473
 
659
474
  export type RouteBuilder<
660
475
  Path extends RoutePath,
@@ -664,16 +479,16 @@ export type RouteBuilder<
664
479
  TReturns extends ReturnsMap = {},
665
480
  TAppContext extends Record<string, unknown> = AppContext,
666
481
  > = {
667
- readonly path: Path
668
- readonly method: TMethod
482
+ readonly path: Path;
483
+ readonly method: TMethod;
669
484
  readonly $Infer: {
670
- Context: TMethod extends 'GET' | 'DELETE' | 'HEAD' | 'OPTIONS'
485
+ Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS"
671
486
  ? RouteHandleContextWithoutBody<Path, TMethod, Acc, Validators, TAppContext>
672
- : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>
673
- }
487
+ : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>;
488
+ };
674
489
  returns<const M extends ReturnsMap>(
675
490
  map: M,
676
- ): RouteBuilder<Path, TMethod, Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>
491
+ ): RouteBuilder<Path, TMethod, Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>;
677
492
  use<TAcc, UReturns extends ReturnsMap = {}>(
678
493
  unit: MiddlewareUnit<TAcc, UReturns>,
679
494
  ): RouteBuilder<
@@ -683,87 +498,8 @@ export type RouteBuilder<
683
498
  Validators,
684
499
  Omit<TReturns, keyof UReturns> & UReturns,
685
500
  TAppContext
686
- >
687
- use<
688
- TState,
689
- TCtx,
690
- TQuery = unknown,
691
- TParams = unknown,
692
- TBody = unknown,
693
- UReturns extends ReturnsMap = {},
694
- TQueryIn = unknown,
695
- TParamsIn = unknown,
696
- TBodyIn = unknown,
697
- >(
698
- options: StateAndCtxUseOptions<
699
- RouteChainContext<Path, TMethod, Acc, TQuery, TParams, TBody, TAppContext>,
700
- TState,
701
- TCtx,
702
- TQuery,
703
- TParams,
704
- TBody,
705
- UReturns,
706
- TQueryIn,
707
- TParamsIn,
708
- TBodyIn
709
- >,
710
- ): RouteBuilder<
711
- Path,
712
- TMethod,
713
- readonly [...Acc, MiddlewareReturnFromParts<
714
- TQuery,
715
- TParams,
716
- TBody,
717
- TState,
718
- TCtx,
719
- TQueryIn,
720
- TParamsIn,
721
- TBodyIn
722
- >],
723
- Validators,
724
- Omit<TReturns, keyof UReturns> & UReturns,
725
- TAppContext
726
- >
727
- use<
728
- TState,
729
- TQuery = unknown,
730
- TParams = unknown,
731
- TBody = unknown,
732
- UReturns extends ReturnsMap = {},
733
- TQueryIn = unknown,
734
- TParamsIn = unknown,
735
- TBodyIn = unknown,
736
- >(
737
- options: StatefulUseOptions<
738
- RouteChainContext<Path, TMethod, Acc, TQuery, TParams, TBody, TAppContext>,
739
- TState,
740
- TQuery,
741
- TParams,
742
- TBody,
743
- UReturns,
744
- TQueryIn,
745
- TParamsIn,
746
- TBodyIn
747
- >,
748
- ): RouteBuilder<
749
- Path,
750
- TMethod,
751
- readonly [...Acc, MiddlewareReturnFromParts<
752
- TQuery,
753
- TParams,
754
- TBody,
755
- TState,
756
- unknown,
757
- TQueryIn,
758
- TParamsIn,
759
- TBodyIn
760
- >],
761
- Validators,
762
- Omit<TReturns, keyof UReturns> & UReturns,
763
- TAppContext
764
- >
501
+ >;
765
502
  use<
766
- TCtx,
767
503
  TQuery = unknown,
768
504
  TParams = unknown,
769
505
  TBody = unknown,
@@ -771,92 +507,53 @@ export type RouteBuilder<
771
507
  TQueryIn = unknown,
772
508
  TParamsIn = unknown,
773
509
  TBodyIn = unknown,
510
+ R = unknown,
774
511
  >(
775
- options: CtxUseOptions<
512
+ options: InlineMiddlewareOptions<
776
513
  RouteChainContext<Path, TMethod, Acc, TQuery, TParams, TBody, TAppContext>,
777
- TCtx,
778
514
  TQuery,
779
515
  TParams,
780
516
  TBody,
781
517
  UReturns,
782
518
  TQueryIn,
783
519
  TParamsIn,
784
- TBodyIn
520
+ TBodyIn,
521
+ R
785
522
  >,
786
523
  ): RouteBuilder<
787
524
  Path,
788
525
  TMethod,
789
- readonly [...Acc, MiddlewareReturnFromParts<
790
- TQuery,
791
- TParams,
792
- TBody,
793
- {},
794
- TCtx,
795
- TQueryIn,
796
- TParamsIn,
797
- TBodyIn
798
- >],
799
- Validators,
800
- Omit<TReturns, keyof UReturns> & UReturns,
801
- TAppContext
802
- >
803
- use<
804
- TQuery = unknown,
805
- TParams = unknown,
806
- TBody = unknown,
807
- UReturns extends ReturnsMap = {},
808
- TQueryIn = unknown,
809
- TParamsIn = unknown,
810
- TBodyIn = unknown,
811
- >(
812
- options: StatelessUseOptions<
813
- RouteChainContext<Path, TMethod, Acc, TQuery, TParams, TBody, TAppContext>,
814
- TQuery,
815
- TParams,
816
- TBody,
817
- UReturns,
818
- TQueryIn,
819
- TParamsIn,
820
- TBodyIn
821
- >,
822
- ): RouteBuilder<
823
- Path,
824
- TMethod,
825
- readonly [...Acc, MiddlewareReturnFromParts<
826
- TQuery,
827
- TParams,
828
- TBody,
829
- {},
830
- unknown,
831
- TQueryIn,
832
- TParamsIn,
833
- TBodyIn
834
- >],
526
+ readonly [
527
+ ...Acc,
528
+ MiddlewareReturnFromParts<
529
+ TQuery,
530
+ TParams,
531
+ TBody,
532
+ ExtractState<R>,
533
+ TQueryIn,
534
+ TParamsIn,
535
+ TBodyIn
536
+ >,
537
+ ],
835
538
  Validators,
836
539
  Omit<TReturns, keyof UReturns> & UReturns,
837
540
  TAppContext
838
- >
541
+ >;
839
542
  handler<R extends Response = Response>(
840
543
  fn: (
841
- ctx: TMethod extends 'GET' | 'DELETE' | 'HEAD' | 'OPTIONS'
544
+ ctx: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS"
842
545
  ? RouteHandleContextWithoutBody<Path, TMethod, Acc, Validators, TAppContext>
843
546
  : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>,
844
547
  ) => Awaitable<R>,
845
548
  ..._assert: [R] extends [ValidHandlerReply<R, TReturns>]
846
549
  ? []
847
- : [{
848
- expected: ValidHandlerReply<R, TReturns>
849
- actual: R
850
- }]
851
- ): RouteHandleResult<
852
- Path,
853
- TMethod,
854
- Acc,
855
- Validators,
856
- TReturns,
857
- R,
858
- TAppContext
859
- >
550
+ : [
551
+ {
552
+ expected: ValidHandlerReply<R, TReturns>;
553
+ actual: R;
554
+ },
555
+ ]
556
+ ): RouteHandleResult<Path, TMethod, Acc, Validators, TReturns, R, TAppContext>;
860
557
  handler<
861
558
  HandlerAcc extends readonly unknown[] = readonly [],
862
559
  HandlerValidators extends ValidatorParts = ValidatorParts,
@@ -872,8 +569,8 @@ export type RouteBuilder<
872
569
  Omit<TReturns, keyof HReturns> & HReturns,
873
570
  HOutput,
874
571
  TAppContext
875
- >
876
- }
572
+ >;
573
+ };
877
574
 
878
575
  export type HandlerBuilder<
879
576
  Acc extends readonly unknown[] = readonly [],
@@ -883,7 +580,7 @@ export type HandlerBuilder<
883
580
  > = {
884
581
  returns<const M extends ReturnsMap>(
885
582
  map: M,
886
- ): HandlerBuilder<Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>
583
+ ): HandlerBuilder<Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>;
887
584
  use<TAcc, UReturns extends ReturnsMap = {}>(
888
585
  unit: MiddlewareUnit<TAcc, UReturns>,
889
586
  ): HandlerBuilder<
@@ -891,51 +588,8 @@ export type HandlerBuilder<
891
588
  Validators,
892
589
  Omit<TReturns, keyof UReturns> & UReturns,
893
590
  TAppContext
894
- >
895
- use<
896
- TState,
897
- TCtx,
898
- TQuery = unknown,
899
- TParams = unknown,
900
- TBody = unknown,
901
- UReturns extends ReturnsMap = {},
902
- TQueryIn = unknown,
903
- TParamsIn = unknown,
904
- TBodyIn = unknown,
905
- >(
906
- options: StateAndCtxUseOptions<
907
- HandlerContext<
908
- Acc,
909
- { query: TQuery, params: TParams, body: TBody },
910
- TAppContext
911
- >,
912
- TState,
913
- TCtx,
914
- TQuery,
915
- TParams,
916
- TBody,
917
- UReturns,
918
- TQueryIn,
919
- TParamsIn,
920
- TBodyIn
921
- >,
922
- ): HandlerBuilder<
923
- readonly [...Acc, MiddlewareReturnFromParts<
924
- TQuery,
925
- TParams,
926
- TBody,
927
- TState,
928
- TCtx,
929
- TQueryIn,
930
- TParamsIn,
931
- TBodyIn
932
- >],
933
- Validators,
934
- Omit<TReturns, keyof UReturns> & UReturns,
935
- TAppContext
936
- >
591
+ >;
937
592
  use<
938
- TState,
939
593
  TQuery = unknown,
940
594
  TParams = unknown,
941
595
  TBody = unknown,
@@ -943,122 +597,45 @@ export type HandlerBuilder<
943
597
  TQueryIn = unknown,
944
598
  TParamsIn = unknown,
945
599
  TBodyIn = unknown,
600
+ R = unknown,
946
601
  >(
947
- options: StatefulUseOptions<
948
- HandlerContext<
949
- Acc,
950
- { query: TQuery, params: TParams, body: TBody },
951
- TAppContext
952
- >,
953
- TState,
602
+ options: InlineMiddlewareOptions<
603
+ HandlerContext<Acc, { query: TQuery; params: TParams; body: TBody }, TAppContext>,
954
604
  TQuery,
955
605
  TParams,
956
606
  TBody,
957
607
  UReturns,
958
608
  TQueryIn,
959
609
  TParamsIn,
960
- TBodyIn
610
+ TBodyIn,
611
+ R
961
612
  >,
962
613
  ): HandlerBuilder<
963
- readonly [...Acc, MiddlewareReturnFromParts<
964
- TQuery,
965
- TParams,
966
- TBody,
967
- TState,
968
- unknown,
969
- TQueryIn,
970
- TParamsIn,
971
- TBodyIn
972
- >],
973
- Validators,
974
- Omit<TReturns, keyof UReturns> & UReturns,
975
- TAppContext
976
- >
977
- use<
978
- TCtx,
979
- TQuery = unknown,
980
- TParams = unknown,
981
- TBody = unknown,
982
- UReturns extends ReturnsMap = {},
983
- TQueryIn = unknown,
984
- TParamsIn = unknown,
985
- TBodyIn = unknown,
986
- >(
987
- options: CtxUseOptions<
988
- HandlerContext<
989
- Acc,
990
- { query: TQuery, params: TParams, body: TBody },
991
- TAppContext
614
+ readonly [
615
+ ...Acc,
616
+ MiddlewareReturnFromParts<
617
+ TQuery,
618
+ TParams,
619
+ TBody,
620
+ ExtractState<R>,
621
+ TQueryIn,
622
+ TParamsIn,
623
+ TBodyIn
992
624
  >,
993
- TCtx,
994
- TQuery,
995
- TParams,
996
- TBody,
997
- UReturns,
998
- TQueryIn,
999
- TParamsIn,
1000
- TBodyIn
1001
- >,
1002
- ): HandlerBuilder<
1003
- readonly [...Acc, MiddlewareReturnFromParts<
1004
- TQuery,
1005
- TParams,
1006
- TBody,
1007
- {},
1008
- TCtx,
1009
- TQueryIn,
1010
- TParamsIn,
1011
- TBodyIn
1012
- >],
625
+ ],
1013
626
  Validators,
1014
627
  Omit<TReturns, keyof UReturns> & UReturns,
1015
628
  TAppContext
1016
- >
1017
- use<
1018
- TQuery = unknown,
1019
- TParams = unknown,
1020
- TBody = unknown,
1021
- UReturns extends ReturnsMap = {},
1022
- TQueryIn = unknown,
1023
- TParamsIn = unknown,
1024
- TBodyIn = unknown,
1025
- >(
1026
- options: StatelessUseOptions<
1027
- HandlerContext<
1028
- Acc,
1029
- { query: TQuery, params: TParams, body: TBody },
1030
- TAppContext
1031
- >,
1032
- TQuery,
1033
- TParams,
1034
- TBody,
1035
- UReturns,
1036
- TQueryIn,
1037
- TParamsIn,
1038
- TBodyIn
1039
- >,
1040
- ): HandlerBuilder<
1041
- readonly [...Acc, MiddlewareReturnFromParts<
1042
- TQuery,
1043
- TParams,
1044
- TBody,
1045
- {},
1046
- unknown,
1047
- TQueryIn,
1048
- TParamsIn,
1049
- TBodyIn
1050
- >],
1051
- Validators,
1052
- Omit<TReturns, keyof UReturns> & UReturns,
1053
- TAppContext
1054
- >
629
+ >;
1055
630
  handler<R extends Response = Response>(
1056
631
  fn: (ctx: HandlerContext<Acc, Validators, TAppContext>) => Awaitable<R>,
1057
632
  ..._assert: [R] extends [ValidHandlerReply<R, TReturns>]
1058
633
  ? []
1059
- : [{
1060
- expected: ValidHandlerReply<R, TReturns>
1061
- actual: R
1062
- }]
1063
- ): HandlerUnit<Acc, Validators, TReturns, R>
1064
- }
634
+ : [
635
+ {
636
+ expected: ValidHandlerReply<R, TReturns>;
637
+ actual: R;
638
+ },
639
+ ]
640
+ ): HandlerUnit<Acc, Validators, TReturns, R>;
641
+ };