@taserjs/router 0.0.3 → 0.0.5
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/cjs/builder/app.cjs +22 -0
- package/dist/cjs/builder/app.cjs.map +1 -0
- package/dist/cjs/builder/app.d.cts +11 -0
- package/dist/cjs/{constants.cjs → builder/constants.cjs} +1 -1
- package/dist/cjs/builder/constants.cjs.map +1 -0
- package/dist/cjs/{factories.cjs → builder/factories.cjs} +1 -1
- package/dist/cjs/builder/factories.cjs.map +1 -0
- package/dist/cjs/{factories.d.cts → builder/factories.d.cts} +2 -2
- package/dist/cjs/{middleware.cjs → builder/middleware.cjs} +1 -1
- package/dist/cjs/builder/middleware.cjs.map +1 -0
- package/dist/cjs/{middleware.d.cts → builder/middleware.d.cts} +1 -1
- package/dist/cjs/{route.cjs → builder/route.cjs} +19 -33
- package/dist/cjs/builder/route.cjs.map +1 -0
- package/dist/cjs/{route.d.cts → builder/route.d.cts} +3 -3
- package/dist/cjs/{taser-router.cjs → builder/router.cjs} +38 -11
- package/dist/cjs/builder/router.cjs.map +1 -0
- package/dist/cjs/builder/router.d.cts +48 -0
- package/dist/cjs/{create-context.cjs → context/create-context.cjs} +1 -1
- package/dist/cjs/context/create-context.cjs.map +1 -0
- package/dist/cjs/{create-context.d.cts → context/create-context.d.cts} +2 -2
- package/dist/cjs/define/middleware.cjs +13 -3
- package/dist/cjs/define/middleware.cjs.map +1 -1
- package/dist/cjs/define/middleware.d.cts +21 -4
- package/dist/cjs/define/validators.cjs +1 -1
- package/dist/cjs/define/validators.cjs.map +1 -1
- package/dist/cjs/define/validators.d.cts +1 -1
- package/dist/cjs/index.cjs +6 -16
- package/dist/cjs/index.d.cts +6 -7
- package/dist/cjs/middleware/body-limit.cjs +2 -2
- package/dist/cjs/middleware/body-limit.cjs.map +1 -1
- package/dist/cjs/middleware/compress.cjs +2 -2
- package/dist/cjs/middleware/compress.cjs.map +1 -1
- package/dist/cjs/middleware/cors.cjs +2 -2
- package/dist/cjs/middleware/cors.cjs.map +1 -1
- package/dist/cjs/middleware/csrf.cjs +2 -2
- package/dist/cjs/middleware/csrf.cjs.map +1 -1
- package/dist/cjs/middleware/etag.cjs +2 -2
- package/dist/cjs/middleware/etag.cjs.map +1 -1
- package/dist/cjs/middleware/jwk.cjs +2 -8
- package/dist/cjs/middleware/jwk.cjs.map +1 -1
- package/dist/cjs/middleware/jwt.cjs +2 -8
- package/dist/cjs/middleware/jwt.cjs.map +1 -1
- package/dist/cjs/middleware/secure-headers.cjs +2 -2
- package/dist/cjs/middleware/secure-headers.cjs.map +1 -1
- package/dist/cjs/middleware/timing.cjs +2 -2
- package/dist/cjs/middleware/timing.cjs.map +1 -1
- package/dist/cjs/middleware/wrap-hono.cjs +10 -0
- package/dist/cjs/middleware/wrap-hono.cjs.map +1 -1
- package/dist/cjs/middleware/wrap-hono.d.cts +4 -0
- package/dist/cjs/types/app.d.cts +7 -7
- package/dist/cjs/types/index.d.cts +73 -17
- package/dist/cjs/types/returns.d.cts +2 -2
- package/dist/cjs/types/type-utils.d.cts +1 -2
- package/dist/cjs/types/units.cjs.map +1 -1
- package/dist/cjs/types/units.d.cts +9 -12
- package/dist/esm/builder/app.d.ts +11 -0
- package/dist/esm/builder/app.js +22 -0
- package/dist/esm/builder/app.js.map +1 -0
- package/dist/esm/{constants.js → builder/constants.js} +1 -1
- package/dist/esm/builder/constants.js.map +1 -0
- package/dist/esm/{factories.d.ts → builder/factories.d.ts} +2 -2
- package/dist/esm/{factories.js → builder/factories.js} +1 -1
- package/dist/esm/builder/factories.js.map +1 -0
- package/dist/esm/{middleware.d.ts → builder/middleware.d.ts} +1 -1
- package/dist/esm/{middleware.js → builder/middleware.js} +1 -1
- package/dist/esm/builder/middleware.js.map +1 -0
- package/dist/esm/{route.d.ts → builder/route.d.ts} +3 -3
- package/dist/esm/{route.js → builder/route.js} +19 -33
- package/dist/esm/builder/route.js.map +1 -0
- package/dist/esm/builder/router.d.ts +48 -0
- package/dist/esm/{taser-router.js → builder/router.js} +37 -10
- package/dist/esm/builder/router.js.map +1 -0
- package/dist/esm/{create-context.d.ts → context/create-context.d.ts} +2 -2
- package/dist/esm/{create-context.js → context/create-context.js} +1 -1
- package/dist/esm/context/create-context.js.map +1 -0
- package/dist/esm/define/middleware.d.ts +21 -4
- package/dist/esm/define/middleware.js +13 -3
- package/dist/esm/define/middleware.js.map +1 -1
- package/dist/esm/define/validators.d.ts +1 -1
- package/dist/esm/define/validators.js +1 -1
- package/dist/esm/define/validators.js.map +1 -1
- package/dist/esm/index.d.ts +6 -7
- package/dist/esm/index.js +5 -6
- package/dist/esm/middleware/body-limit.js +2 -2
- package/dist/esm/middleware/body-limit.js.map +1 -1
- package/dist/esm/middleware/compress.js +2 -2
- package/dist/esm/middleware/compress.js.map +1 -1
- package/dist/esm/middleware/cors.js +2 -2
- package/dist/esm/middleware/cors.js.map +1 -1
- package/dist/esm/middleware/csrf.js +2 -2
- package/dist/esm/middleware/csrf.js.map +1 -1
- package/dist/esm/middleware/etag.js +2 -2
- package/dist/esm/middleware/etag.js.map +1 -1
- package/dist/esm/middleware/jwk.js +2 -8
- package/dist/esm/middleware/jwk.js.map +1 -1
- package/dist/esm/middleware/jwt.js +2 -8
- package/dist/esm/middleware/jwt.js.map +1 -1
- package/dist/esm/middleware/secure-headers.js +2 -2
- package/dist/esm/middleware/secure-headers.js.map +1 -1
- package/dist/esm/middleware/timing.js +2 -2
- package/dist/esm/middleware/timing.js.map +1 -1
- package/dist/esm/middleware/wrap-hono.d.ts +4 -0
- package/dist/esm/middleware/wrap-hono.js +10 -1
- package/dist/esm/middleware/wrap-hono.js.map +1 -1
- package/dist/esm/types/app.d.ts +7 -7
- package/dist/esm/types/index.d.ts +73 -17
- package/dist/esm/types/returns.d.ts +2 -2
- package/dist/esm/types/type-utils.d.ts +1 -2
- package/dist/esm/types/units.d.ts +9 -12
- package/dist/esm/types/units.js.map +1 -1
- package/package.json +3 -3
- package/src/builder/app.ts +28 -0
- package/src/{factories.ts → builder/factories.ts} +2 -2
- package/src/{middleware.ts → builder/middleware.ts} +2 -2
- package/src/{route.ts → builder/route.ts} +30 -34
- package/src/builder/router.ts +347 -0
- package/src/{create-context.ts → context/create-context.ts} +2 -2
- package/src/define/middleware.ts +197 -7
- package/src/define/validators.ts +1 -1
- package/src/index.ts +9 -12
- package/src/middleware/body-limit.ts +2 -2
- package/src/middleware/compress.ts +2 -2
- package/src/middleware/cors.ts +2 -2
- package/src/middleware/csrf.ts +2 -2
- package/src/middleware/etag.ts +2 -2
- package/src/middleware/jwk.ts +2 -7
- package/src/middleware/jwt.ts +2 -7
- package/src/middleware/secure-headers.ts +2 -2
- package/src/middleware/timing.ts +2 -2
- package/src/middleware/wrap-hono.ts +13 -0
- package/src/types/app.ts +12 -8
- package/src/types/index.ts +145 -16
- package/src/types/returns.ts +2 -2
- package/src/types/type-utils.ts +1 -2
- package/src/types/units.ts +10 -9
- package/dist/cjs/constants.cjs.map +0 -1
- package/dist/cjs/create-context.cjs.map +0 -1
- package/dist/cjs/factories.cjs.map +0 -1
- package/dist/cjs/middleware.cjs.map +0 -1
- package/dist/cjs/route.cjs.map +0 -1
- package/dist/cjs/taser-app.cjs +0 -36
- package/dist/cjs/taser-app.cjs.map +0 -1
- package/dist/cjs/taser-app.d.cts +0 -18
- package/dist/cjs/taser-router.cjs.map +0 -1
- package/dist/cjs/taser-router.d.cts +0 -42
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/create-context.js.map +0 -1
- package/dist/esm/factories.js.map +0 -1
- package/dist/esm/middleware.js.map +0 -1
- package/dist/esm/route.js.map +0 -1
- package/dist/esm/taser-app.d.ts +0 -18
- package/dist/esm/taser-app.js +0 -35
- package/dist/esm/taser-app.js.map +0 -1
- package/dist/esm/taser-router.d.ts +0 -42
- package/dist/esm/taser-router.js.map +0 -1
- package/src/taser-app.ts +0 -38
- package/src/taser-router.ts +0 -165
- /package/dist/cjs/{constants.d.cts → builder/constants.d.cts} +0 -0
- /package/dist/esm/{constants.d.ts → builder/constants.d.ts} +0 -0
- /package/src/{constants.ts → builder/constants.ts} +0 -0
package/src/define/middleware.ts
CHANGED
|
@@ -10,14 +10,25 @@ import type {
|
|
|
10
10
|
NextFn,
|
|
11
11
|
StandaloneMiddlewareContext,
|
|
12
12
|
} from "../types/units.js";
|
|
13
|
+
import type {
|
|
14
|
+
LayoutId,
|
|
15
|
+
ResolveLayoutMiddlewaresState,
|
|
16
|
+
ResolveLayoutsState,
|
|
17
|
+
} from "../types/index.js";
|
|
13
18
|
import type { Schema } from "../types/schema.js";
|
|
14
19
|
|
|
15
20
|
type HonoMiddlewareHandler = Parameters<typeof createTaserCompatHandler>[0];
|
|
16
21
|
|
|
17
|
-
type HonoMiddlewareUnit = MiddlewareUnit<
|
|
22
|
+
type HonoMiddlewareUnit = MiddlewareUnit<
|
|
23
|
+
MiddlewareReturnFromParts<unknown, unknown, unknown, {}>,
|
|
24
|
+
{},
|
|
25
|
+
null,
|
|
26
|
+
{}
|
|
27
|
+
>;
|
|
18
28
|
|
|
19
29
|
export type DefineMiddlewareOptions<
|
|
20
30
|
TState = unknown,
|
|
31
|
+
TRequires = {},
|
|
21
32
|
TQuery = unknown,
|
|
22
33
|
TParams = unknown,
|
|
23
34
|
TBody = unknown,
|
|
@@ -33,7 +44,67 @@ export type DefineMiddlewareOptions<
|
|
|
33
44
|
body?: Schema<TBody, TBodyIn>;
|
|
34
45
|
returns?: TReturns;
|
|
35
46
|
handler: (
|
|
36
|
-
ctx: StandaloneMiddlewareContext<TQuery, TParams, TBody, TAppContext>,
|
|
47
|
+
ctx: StandaloneMiddlewareContext<TQuery, TParams, TBody, TAppContext, TRequires>,
|
|
48
|
+
next: NextFn<NoInfer<TState>>,
|
|
49
|
+
) => Awaitable<R>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type ScopedMiddlewareOptions<
|
|
53
|
+
Layout extends LayoutId,
|
|
54
|
+
TState = unknown,
|
|
55
|
+
TRequires = {},
|
|
56
|
+
TQuery = unknown,
|
|
57
|
+
TParams = unknown,
|
|
58
|
+
TBody = unknown,
|
|
59
|
+
TReturns extends ReturnsMap = {},
|
|
60
|
+
TQueryIn = unknown,
|
|
61
|
+
TParamsIn = unknown,
|
|
62
|
+
TBodyIn = unknown,
|
|
63
|
+
TAppContext extends Record<string, unknown> = AppContext,
|
|
64
|
+
R = unknown,
|
|
65
|
+
> = {
|
|
66
|
+
query?: Schema<TQuery, TQueryIn>;
|
|
67
|
+
params?: Schema<TParams, TParamsIn>;
|
|
68
|
+
body?: Schema<TBody, TBodyIn>;
|
|
69
|
+
returns?: TReturns;
|
|
70
|
+
handler: (
|
|
71
|
+
ctx: StandaloneMiddlewareContext<
|
|
72
|
+
TQuery,
|
|
73
|
+
TParams,
|
|
74
|
+
TBody,
|
|
75
|
+
TAppContext,
|
|
76
|
+
ResolveLayoutMiddlewaresState<Layout> & TRequires
|
|
77
|
+
>,
|
|
78
|
+
next: NextFn<NoInfer<TState>>,
|
|
79
|
+
) => Awaitable<R>;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type MultiScopedMiddlewareOptions<
|
|
83
|
+
Layouts extends readonly LayoutId[],
|
|
84
|
+
TState = unknown,
|
|
85
|
+
TRequires = {},
|
|
86
|
+
TQuery = unknown,
|
|
87
|
+
TParams = unknown,
|
|
88
|
+
TBody = unknown,
|
|
89
|
+
TReturns extends ReturnsMap = {},
|
|
90
|
+
TQueryIn = unknown,
|
|
91
|
+
TParamsIn = unknown,
|
|
92
|
+
TBodyIn = unknown,
|
|
93
|
+
TAppContext extends Record<string, unknown> = AppContext,
|
|
94
|
+
R = unknown,
|
|
95
|
+
> = {
|
|
96
|
+
query?: Schema<TQuery, TQueryIn>;
|
|
97
|
+
params?: Schema<TParams, TParamsIn>;
|
|
98
|
+
body?: Schema<TBody, TBodyIn>;
|
|
99
|
+
returns?: TReturns;
|
|
100
|
+
handler: (
|
|
101
|
+
ctx: StandaloneMiddlewareContext<
|
|
102
|
+
TQuery,
|
|
103
|
+
TParams,
|
|
104
|
+
TBody,
|
|
105
|
+
TAppContext,
|
|
106
|
+
ResolveLayoutsState<Layouts> & TRequires
|
|
107
|
+
>,
|
|
37
108
|
next: NextFn<NoInfer<TState>>,
|
|
38
109
|
) => Awaitable<R>;
|
|
39
110
|
};
|
|
@@ -41,7 +112,96 @@ export type DefineMiddlewareOptions<
|
|
|
41
112
|
export function defineMiddleware(middleware: HonoMiddlewareHandler): HonoMiddlewareUnit;
|
|
42
113
|
|
|
43
114
|
export function defineMiddleware<
|
|
115
|
+
const Layout extends LayoutId,
|
|
116
|
+
TState = unknown,
|
|
117
|
+
TRequires = {},
|
|
118
|
+
TAppContext extends Record<string, unknown> = AppContext,
|
|
119
|
+
TQuery = unknown,
|
|
120
|
+
TParams = unknown,
|
|
121
|
+
TBody = unknown,
|
|
122
|
+
TReturns extends ReturnsMap = {},
|
|
123
|
+
TQueryIn = unknown,
|
|
124
|
+
TParamsIn = unknown,
|
|
125
|
+
TBodyIn = unknown,
|
|
126
|
+
R = unknown,
|
|
127
|
+
>(
|
|
128
|
+
layout: Layout,
|
|
129
|
+
options: ScopedMiddlewareOptions<
|
|
130
|
+
Layout,
|
|
131
|
+
TState,
|
|
132
|
+
TRequires,
|
|
133
|
+
TQuery,
|
|
134
|
+
TParams,
|
|
135
|
+
TBody,
|
|
136
|
+
TReturns,
|
|
137
|
+
TQueryIn,
|
|
138
|
+
TParamsIn,
|
|
139
|
+
TBodyIn,
|
|
140
|
+
TAppContext,
|
|
141
|
+
R
|
|
142
|
+
>,
|
|
143
|
+
): MiddlewareUnit<
|
|
144
|
+
MiddlewareReturnFromParts<
|
|
145
|
+
TQuery,
|
|
146
|
+
TParams,
|
|
147
|
+
TBody,
|
|
148
|
+
IsUnknown<TState> extends true ? ExtractState<R> : TState,
|
|
149
|
+
TQueryIn,
|
|
150
|
+
TParamsIn,
|
|
151
|
+
TBodyIn
|
|
152
|
+
>,
|
|
153
|
+
TReturns,
|
|
154
|
+
Layout,
|
|
155
|
+
TRequires
|
|
156
|
+
>;
|
|
157
|
+
|
|
158
|
+
export function defineMiddleware<
|
|
159
|
+
const Layouts extends readonly [LayoutId, ...LayoutId[]],
|
|
44
160
|
TState = unknown,
|
|
161
|
+
TRequires = {},
|
|
162
|
+
TAppContext extends Record<string, unknown> = AppContext,
|
|
163
|
+
TQuery = unknown,
|
|
164
|
+
TParams = unknown,
|
|
165
|
+
TBody = unknown,
|
|
166
|
+
TReturns extends ReturnsMap = {},
|
|
167
|
+
TQueryIn = unknown,
|
|
168
|
+
TParamsIn = unknown,
|
|
169
|
+
TBodyIn = unknown,
|
|
170
|
+
R = unknown,
|
|
171
|
+
>(
|
|
172
|
+
layouts: Layouts,
|
|
173
|
+
options: MultiScopedMiddlewareOptions<
|
|
174
|
+
Layouts,
|
|
175
|
+
TState,
|
|
176
|
+
TRequires,
|
|
177
|
+
TQuery,
|
|
178
|
+
TParams,
|
|
179
|
+
TBody,
|
|
180
|
+
TReturns,
|
|
181
|
+
TQueryIn,
|
|
182
|
+
TParamsIn,
|
|
183
|
+
TBodyIn,
|
|
184
|
+
TAppContext,
|
|
185
|
+
R
|
|
186
|
+
>,
|
|
187
|
+
): MiddlewareUnit<
|
|
188
|
+
MiddlewareReturnFromParts<
|
|
189
|
+
TQuery,
|
|
190
|
+
TParams,
|
|
191
|
+
TBody,
|
|
192
|
+
IsUnknown<TState> extends true ? ExtractState<R> : TState,
|
|
193
|
+
TQueryIn,
|
|
194
|
+
TParamsIn,
|
|
195
|
+
TBodyIn
|
|
196
|
+
>,
|
|
197
|
+
TReturns,
|
|
198
|
+
Layouts,
|
|
199
|
+
TRequires
|
|
200
|
+
>;
|
|
201
|
+
|
|
202
|
+
export function defineMiddleware<
|
|
203
|
+
TState = unknown,
|
|
204
|
+
TRequires = {},
|
|
45
205
|
TAppContext extends Record<string, unknown> = AppContext,
|
|
46
206
|
TQuery = unknown,
|
|
47
207
|
TParams = unknown,
|
|
@@ -54,6 +214,7 @@ export function defineMiddleware<
|
|
|
54
214
|
>(
|
|
55
215
|
options: DefineMiddlewareOptions<
|
|
56
216
|
TState,
|
|
217
|
+
TRequires,
|
|
57
218
|
TQuery,
|
|
58
219
|
TParams,
|
|
59
220
|
TBody,
|
|
@@ -74,21 +235,50 @@ export function defineMiddleware<
|
|
|
74
235
|
TParamsIn,
|
|
75
236
|
TBodyIn
|
|
76
237
|
>,
|
|
77
|
-
TReturns
|
|
238
|
+
TReturns,
|
|
239
|
+
null,
|
|
240
|
+
TRequires
|
|
78
241
|
>;
|
|
79
242
|
|
|
80
243
|
export function defineMiddleware(
|
|
81
|
-
|
|
244
|
+
first:
|
|
245
|
+
| string
|
|
246
|
+
| readonly string[]
|
|
82
247
|
| HonoMiddlewareHandler
|
|
83
|
-
| DefineMiddlewareOptions<any, any, any, any, any, any, any, any, any, any>,
|
|
248
|
+
| DefineMiddlewareOptions<any, any, any, any, any, any, any, any, any, any, any>,
|
|
249
|
+
second?: DefineMiddlewareOptions<any, any, any, any, any, any, any, any, any, any, any>,
|
|
84
250
|
): unknown {
|
|
85
|
-
if (typeof
|
|
86
|
-
const
|
|
251
|
+
if (typeof first === "string" || Array.isArray(first)) {
|
|
252
|
+
const options = second!;
|
|
253
|
+
const unit = {
|
|
254
|
+
...options,
|
|
255
|
+
__middlewareAcc: undefined as unknown,
|
|
256
|
+
...(options?.returns ? { __returns: options.returns } : {}),
|
|
257
|
+
__requiredLayouts: first,
|
|
258
|
+
};
|
|
259
|
+
return unit;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (typeof first === "function") {
|
|
263
|
+
const honoMiddleware = first as HonoMiddlewareHandler;
|
|
87
264
|
return defineMiddleware({
|
|
88
265
|
handler: (ctx, next) => createTaserCompatHandler(honoMiddleware)(ctx, next),
|
|
89
266
|
});
|
|
90
267
|
}
|
|
91
268
|
|
|
269
|
+
const options = first as DefineMiddlewareOptions<
|
|
270
|
+
any,
|
|
271
|
+
any,
|
|
272
|
+
any,
|
|
273
|
+
any,
|
|
274
|
+
any,
|
|
275
|
+
any,
|
|
276
|
+
any,
|
|
277
|
+
any,
|
|
278
|
+
any,
|
|
279
|
+
any,
|
|
280
|
+
any
|
|
281
|
+
>;
|
|
92
282
|
const unit = {
|
|
93
283
|
...options,
|
|
94
284
|
__middlewareAcc: undefined as unknown,
|
package/src/define/validators.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,16 +2,20 @@ export type { RouterRegister } from "./register.js";
|
|
|
2
2
|
export type {
|
|
3
3
|
InferInput,
|
|
4
4
|
InferOutput,
|
|
5
|
+
InferRouteContext,
|
|
6
|
+
InferRouteInput,
|
|
7
|
+
InferRouteOutput,
|
|
5
8
|
Method,
|
|
6
9
|
PathParams,
|
|
7
10
|
ReturnsMap,
|
|
11
|
+
RouteDefinition,
|
|
12
|
+
RouteExport,
|
|
8
13
|
RoutePath,
|
|
9
14
|
Schema,
|
|
10
15
|
Simplify,
|
|
11
16
|
} from "./types/index.js";
|
|
12
17
|
export type {
|
|
13
18
|
ContextDefinition,
|
|
14
|
-
CreateContextArgs,
|
|
15
19
|
CreateTaserAppOptions,
|
|
16
20
|
InferAppContext,
|
|
17
21
|
InferAppManifest,
|
|
@@ -20,13 +24,7 @@ export type {
|
|
|
20
24
|
TaserHandler,
|
|
21
25
|
} from "./types/app.js";
|
|
22
26
|
|
|
23
|
-
export {
|
|
24
|
-
isReplyResult,
|
|
25
|
-
reply,
|
|
26
|
-
stream,
|
|
27
|
-
ValidationError,
|
|
28
|
-
validationErrorSchema,
|
|
29
|
-
} from "@taserjs/router-utils";
|
|
27
|
+
export { reply, stream, ValidationError, validationErrorSchema } from "@taserjs/router-utils";
|
|
30
28
|
export type {
|
|
31
29
|
ReplyBodyKind,
|
|
32
30
|
ReplyOf,
|
|
@@ -35,10 +33,9 @@ export type {
|
|
|
35
33
|
SuccessStatusCode,
|
|
36
34
|
} from "@taserjs/router-utils";
|
|
37
35
|
|
|
38
|
-
export {
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export { createContext } from "./create-context.js";
|
|
36
|
+
export { createTaserApp, TaserRouter } from "./builder/router.js";
|
|
37
|
+
export { TaserApp } from "./builder/app.js";
|
|
38
|
+
export { createContext } from "./context/create-context.js";
|
|
42
39
|
export { defineHandler } from "./define/handler.js";
|
|
43
40
|
export { defineMiddleware } from "./define/middleware.js";
|
|
44
41
|
|
|
@@ -2,10 +2,10 @@ import { bodyLimit as honoBodyLimit } from "hono/body-limit";
|
|
|
2
2
|
|
|
3
3
|
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const wrapped = wrapHonoMiddleware(honoBodyLimit);
|
|
6
6
|
|
|
7
7
|
export function bodyLimit(...args: Parameters<typeof honoBodyLimit>) {
|
|
8
|
-
return
|
|
8
|
+
return wrapped(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export type BodyLimitOptions = Parameters<typeof honoBodyLimit>[0];
|
|
@@ -2,10 +2,10 @@ import { compress as honoCompress } from "hono/compress";
|
|
|
2
2
|
|
|
3
3
|
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const wrapped = wrapHonoMiddleware(honoCompress);
|
|
6
6
|
|
|
7
7
|
export function compress(...args: Parameters<typeof honoCompress>) {
|
|
8
|
-
return
|
|
8
|
+
return wrapped(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export type CompressOptions = NonNullable<Parameters<typeof honoCompress>[0]>;
|
package/src/middleware/cors.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { cors as honoCors } from "hono/cors";
|
|
|
2
2
|
|
|
3
3
|
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const wrapped = wrapHonoMiddleware(honoCors);
|
|
6
6
|
|
|
7
7
|
export function cors(...args: Parameters<typeof honoCors>) {
|
|
8
|
-
return
|
|
8
|
+
return wrapped(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export type CorsOptions = NonNullable<Parameters<typeof honoCors>[0]>;
|
package/src/middleware/csrf.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { csrf as honoCsrf } from "hono/csrf";
|
|
|
2
2
|
|
|
3
3
|
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const wrapped = wrapHonoMiddleware(honoCsrf);
|
|
6
6
|
|
|
7
7
|
export function csrf(...args: Parameters<typeof honoCsrf>) {
|
|
8
|
-
return
|
|
8
|
+
return wrapped(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export type CsrfOptions = NonNullable<Parameters<typeof honoCsrf>[0]>;
|
package/src/middleware/etag.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { etag as honoEtag } from "hono/etag";
|
|
|
2
2
|
|
|
3
3
|
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const wrapped = wrapHonoMiddleware(honoEtag);
|
|
6
6
|
|
|
7
7
|
export function etag(...args: Parameters<typeof honoEtag>) {
|
|
8
|
-
return
|
|
8
|
+
return wrapped(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export type EtagOptions = NonNullable<Parameters<typeof honoEtag>[0]>;
|
package/src/middleware/jwk.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createTaserCompatHandler } from "@taserjs/router-core";
|
|
2
1
|
import type { MiddlewareHandler } from "hono";
|
|
3
2
|
import { jwk as honoJwk } from "hono/jwk";
|
|
4
3
|
|
|
5
4
|
import { defineMiddleware } from "../define/middleware.js";
|
|
6
5
|
import type { JwtMiddlewareUnit, JwtPayloadState } from "./jwt.js";
|
|
6
|
+
import { extractJwtPayload } from "./wrap-hono.js";
|
|
7
7
|
|
|
8
8
|
export type JwkOptions = Parameters<typeof honoJwk>[0];
|
|
9
9
|
|
|
@@ -44,11 +44,6 @@ export function jwk<TPayload = Record<string, unknown>>(
|
|
|
44
44
|
const honoMw: MiddlewareHandler = honoJwk(honoOptions, safeInit);
|
|
45
45
|
|
|
46
46
|
return defineMiddleware<JwtPayloadState<TPayload>>({
|
|
47
|
-
handler: (
|
|
48
|
-
return createTaserCompatHandler(honoMw)(ctx, async () => {
|
|
49
|
-
const payload = (ctx as unknown as { var: { jwtPayload?: unknown } }).var.jwtPayload;
|
|
50
|
-
return next({ jwtPayload: payload as TPayload });
|
|
51
|
-
});
|
|
52
|
-
},
|
|
47
|
+
handler: extractJwtPayload<TPayload>(honoMw),
|
|
53
48
|
});
|
|
54
49
|
}
|
package/src/middleware/jwt.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createTaserCompatHandler } from "@taserjs/router-core";
|
|
2
1
|
import type { MiddlewareHandler } from "hono";
|
|
3
2
|
import { jwt as honoJwt } from "hono/jwt";
|
|
4
3
|
|
|
5
4
|
import { defineMiddleware } from "../define/middleware.js";
|
|
6
5
|
import type { MiddlewareReturnFromParts, MiddlewareUnit } from "../types/units.js";
|
|
6
|
+
import { extractJwtPayload } from "./wrap-hono.js";
|
|
7
7
|
|
|
8
8
|
export type JwtPayloadState<TPayload> = {
|
|
9
9
|
jwtPayload: TPayload;
|
|
@@ -24,11 +24,6 @@ export function jwt<TPayload = Record<string, unknown>>(
|
|
|
24
24
|
): JwtMiddlewareUnit<TPayload> {
|
|
25
25
|
const honoMw: MiddlewareHandler = honoJwt(options);
|
|
26
26
|
return defineMiddleware<JwtPayloadState<TPayload>>({
|
|
27
|
-
handler: (
|
|
28
|
-
return createTaserCompatHandler(honoMw)(ctx, async () => {
|
|
29
|
-
const payload = (ctx as unknown as { var: { jwtPayload?: unknown } }).var.jwtPayload;
|
|
30
|
-
return next({ jwtPayload: payload as TPayload });
|
|
31
|
-
});
|
|
32
|
-
},
|
|
27
|
+
handler: extractJwtPayload<TPayload>(honoMw),
|
|
33
28
|
});
|
|
34
29
|
}
|
|
@@ -2,10 +2,10 @@ import { secureHeaders as honoSecureHeaders } from "hono/secure-headers";
|
|
|
2
2
|
|
|
3
3
|
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const wrapped = wrapHonoMiddleware(honoSecureHeaders);
|
|
6
6
|
|
|
7
7
|
export function secureHeaders(...args: Parameters<typeof honoSecureHeaders>) {
|
|
8
|
-
return
|
|
8
|
+
return wrapped(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export type SecureHeadersOptions = NonNullable<Parameters<typeof honoSecureHeaders>[0]>;
|
package/src/middleware/timing.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { timing as honoTiming } from "hono/timing";
|
|
|
2
2
|
|
|
3
3
|
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const wrapped = wrapHonoMiddleware(honoTiming);
|
|
6
6
|
|
|
7
7
|
export function timing(...args: Parameters<typeof honoTiming>) {
|
|
8
|
-
return
|
|
8
|
+
return wrapped(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export type TimingOptions = NonNullable<Parameters<typeof honoTiming>[0]>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createTaserCompatHandler } from "@taserjs/router-core";
|
|
1
2
|
import type { MiddlewareHandler } from "hono";
|
|
2
3
|
|
|
3
4
|
import { defineMiddleware } from "../define/middleware.js";
|
|
@@ -10,3 +11,15 @@ export function wrapHonoMiddleware<F extends (...args: never[]) => MiddlewareHan
|
|
|
10
11
|
) => MiddlewareUnit<MiddlewareReturnFromParts<unknown, unknown, unknown, {}>> {
|
|
11
12
|
return (...args) => defineMiddleware(honoFactory(...args));
|
|
12
13
|
}
|
|
14
|
+
|
|
15
|
+
/** Extracts the jwtPayload from Hono's variable bag and forwards it into Taser's state via next(). */
|
|
16
|
+
export function extractJwtPayload<TPayload>(
|
|
17
|
+
honoMw: MiddlewareHandler,
|
|
18
|
+
): (ctx: unknown, next: (state: { jwtPayload: TPayload }) => unknown) => unknown {
|
|
19
|
+
const taserHandler = createTaserCompatHandler(honoMw);
|
|
20
|
+
return (ctx, next) =>
|
|
21
|
+
taserHandler(ctx, async () => {
|
|
22
|
+
const payload = (ctx as unknown as { var: { jwtPayload?: unknown } }).var.jwtPayload;
|
|
23
|
+
return next({ jwtPayload: payload as TPayload });
|
|
24
|
+
});
|
|
25
|
+
}
|
package/src/types/app.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { RouteManifestShape } from "@taserjs/router-core";
|
|
1
2
|
import type { ResponseValidationFailureHandler } from "@taserjs/router-utils";
|
|
2
3
|
|
|
3
|
-
import type { TaserApp } from "../
|
|
4
|
+
import type { TaserApp } from "../builder/app.js";
|
|
4
5
|
import type { ReturnsMap } from "./returns.js";
|
|
5
6
|
import type { Schema } from "./schema.js";
|
|
6
7
|
|
|
@@ -24,16 +25,12 @@ export type CreateTaserAppOptions = {
|
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
export type CreateContextArgs = {
|
|
28
|
-
native?: import("./units.js").NativeContext;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
28
|
export type ContextDefinition<
|
|
32
29
|
TBoot extends Record<string, unknown> = Record<string, never>,
|
|
33
30
|
TReq extends Record<string, unknown> = Record<string, never>,
|
|
34
31
|
> = {
|
|
35
32
|
boot?: () => TBoot | Promise<TBoot>;
|
|
36
|
-
request?: (
|
|
33
|
+
request?: (req: Request) => TReq | Promise<TReq>;
|
|
37
34
|
};
|
|
38
35
|
|
|
39
36
|
export type InferAppContext<
|
|
@@ -45,7 +42,14 @@ export type OnErrorOptions<TResponses extends ReturnsMap = ReturnsMap> = {
|
|
|
45
42
|
handle: (error: unknown, ctx?: unknown) => Response | Promise<Response>;
|
|
46
43
|
};
|
|
47
44
|
|
|
48
|
-
export type InferAppManifest<TApp> =
|
|
45
|
+
export type InferAppManifest<TApp> =
|
|
46
|
+
TApp extends TaserApp<infer TManifest>
|
|
47
|
+
? TManifest
|
|
48
|
+
: TApp extends { manifest: infer TManifest }
|
|
49
|
+
? TManifest
|
|
50
|
+
: TApp extends RouteManifestShape
|
|
51
|
+
? TApp
|
|
52
|
+
: never;
|
|
49
53
|
|
|
50
54
|
export type TaserHandler<TFrameworkApp> = {
|
|
51
55
|
/**
|
|
@@ -60,4 +64,4 @@ export type { RouteManifestShape } from "@taserjs/router-core";
|
|
|
60
64
|
|
|
61
65
|
export type { Schema };
|
|
62
66
|
|
|
63
|
-
export type { TaserApp
|
|
67
|
+
export type { TaserApp } from "../builder/app.js";
|