@taserjs/router 0.0.2 → 0.0.4
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/README.md +2 -0
- package/dist/cjs/constants.cjs.map +1 -1
- package/dist/cjs/create-context.cjs.map +1 -1
- package/dist/cjs/define/handler.cjs.map +1 -1
- package/dist/cjs/define/middleware.cjs +18 -27
- package/dist/cjs/define/middleware.cjs.map +1 -1
- package/dist/cjs/define/middleware.d.cts +27 -79
- package/dist/cjs/define/validators.cjs.map +1 -1
- package/dist/cjs/factories.cjs.map +1 -1
- package/dist/cjs/factories.d.cts +2 -2
- package/dist/cjs/index.cjs +1 -2
- package/dist/cjs/index.d.cts +1 -1
- 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 +11 -4
- package/dist/cjs/middleware/jwk.cjs.map +1 -1
- package/dist/cjs/middleware/jwk.d.cts +4 -5
- package/dist/cjs/middleware/jwt.cjs +11 -5
- package/dist/cjs/middleware/jwt.cjs.map +1 -1
- package/dist/cjs/middleware/jwt.d.cts +7 -5
- 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 +9 -0
- package/dist/cjs/middleware/wrap-hono.cjs.map +1 -0
- package/dist/cjs/middleware/wrap-hono.d.cts +3 -0
- package/dist/cjs/middleware.cjs.map +1 -1
- package/dist/cjs/reply.d.cts +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +1 -1
- package/dist/cjs/stream.d.cts +1 -1
- package/dist/cjs/taser-app.cjs +0 -6
- package/dist/cjs/taser-app.cjs.map +1 -1
- package/dist/cjs/taser-app.d.cts +0 -3
- package/dist/cjs/taser-router.cjs +9 -10
- package/dist/cjs/taser-router.cjs.map +1 -1
- package/dist/cjs/taser-router.d.cts +9 -11
- package/dist/cjs/types/app.d.cts +3 -2
- package/dist/cjs/types/index.d.cts +94 -143
- package/dist/cjs/types/type-utils.d.cts +8 -10
- package/dist/cjs/types/units.cjs.map +1 -1
- package/dist/cjs/types/units.d.cts +32 -27
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/create-context.js.map +1 -1
- package/dist/esm/define/handler.js.map +1 -1
- package/dist/esm/define/middleware.d.ts +27 -79
- package/dist/esm/define/middleware.js +18 -27
- package/dist/esm/define/middleware.js.map +1 -1
- package/dist/esm/define/validators.js.map +1 -1
- package/dist/esm/factories.d.ts +2 -2
- package/dist/esm/factories.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/middleware/body-limit.js +1 -1
- package/dist/esm/middleware/body-limit.js.map +1 -1
- package/dist/esm/middleware/compress.js +1 -1
- package/dist/esm/middleware/compress.js.map +1 -1
- package/dist/esm/middleware/cors.js +1 -1
- package/dist/esm/middleware/cors.js.map +1 -1
- package/dist/esm/middleware/csrf.js +1 -1
- package/dist/esm/middleware/csrf.js.map +1 -1
- package/dist/esm/middleware/etag.js +1 -1
- package/dist/esm/middleware/etag.js.map +1 -1
- package/dist/esm/middleware/jwk.d.ts +4 -5
- package/dist/esm/middleware/jwk.js +11 -4
- package/dist/esm/middleware/jwk.js.map +1 -1
- package/dist/esm/middleware/jwt.d.ts +7 -5
- package/dist/esm/middleware/jwt.js +11 -5
- package/dist/esm/middleware/jwt.js.map +1 -1
- package/dist/esm/middleware/secure-headers.js +1 -1
- package/dist/esm/middleware/secure-headers.js.map +1 -1
- package/dist/esm/middleware/timing.js +1 -1
- package/dist/esm/middleware/timing.js.map +1 -1
- package/dist/esm/middleware/wrap-hono.d.ts +3 -0
- package/dist/esm/middleware/wrap-hono.js +9 -0
- package/dist/esm/middleware/wrap-hono.js.map +1 -0
- package/dist/esm/middleware.js.map +1 -1
- package/dist/esm/reply.d.ts +1 -1
- package/dist/esm/route.d.ts +1 -1
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/stream.d.ts +1 -1
- package/dist/esm/taser-app.d.ts +0 -3
- package/dist/esm/taser-app.js +1 -6
- package/dist/esm/taser-app.js.map +1 -1
- package/dist/esm/taser-router.d.ts +9 -11
- package/dist/esm/taser-router.js +7 -8
- package/dist/esm/taser-router.js.map +1 -1
- package/dist/esm/types/app.d.ts +3 -2
- package/dist/esm/types/index.d.ts +94 -143
- package/dist/esm/types/type-utils.d.ts +8 -10
- package/dist/esm/types/units.d.ts +32 -27
- package/dist/esm/types/units.js.map +1 -1
- package/package.json +17 -17
- package/src/constants.ts +6 -6
- package/src/create-context.ts +8 -8
- package/src/define/handler.ts +24 -34
- package/src/define/middleware.ts +222 -222
- package/src/define/validators.ts +10 -10
- package/src/factories.ts +63 -61
- package/src/index.ts +12 -12
- package/src/middleware/body-limit.ts +5 -5
- package/src/middleware/compress.ts +5 -5
- package/src/middleware/cors.ts +5 -5
- package/src/middleware/csrf.ts +5 -5
- package/src/middleware/etag.ts +5 -5
- package/src/middleware/jwk.ts +33 -26
- package/src/middleware/jwt.ts +26 -10
- package/src/middleware/secure-headers.ts +5 -5
- package/src/middleware/timing.ts +5 -5
- package/src/middleware/wrap-hono.ts +12 -0
- package/src/middleware.ts +7 -7
- package/src/reply.ts +2 -6
- package/src/route.ts +45 -48
- package/src/stream.ts +1 -7
- package/src/taser-app.ts +13 -18
- package/src/taser-router.ts +103 -98
- package/src/types/app.ts +33 -35
- package/src/types/index.ts +403 -731
- package/src/types/returns.ts +92 -97
- package/src/types/schema.ts +8 -9
- package/src/types/type-utils.ts +42 -45
- package/src/types/units.ts +140 -104
- package/dist/cjs/middleware/auth.cjs +0 -34
- package/dist/cjs/middleware/auth.cjs.map +0 -1
- package/dist/cjs/middleware/auth.d.cts +0 -9
- package/dist/esm/middleware/auth.d.ts +0 -9
- package/dist/esm/middleware/auth.js +0 -33
- package/dist/esm/middleware/auth.js.map +0 -1
- package/src/middleware/auth.ts +0 -51
package/src/factories.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createRouteBuilder } from
|
|
2
|
-
import type { RouteBuilder, RoutePath, Schema } from
|
|
3
|
-
import type { AppContext, HttpMethod } from
|
|
1
|
+
import { createRouteBuilder } from "./route.js";
|
|
2
|
+
import type { RouteBuilder, RoutePath, Schema } from "./types/index.js";
|
|
3
|
+
import type { AppContext, HttpMethod } from "./types/units.js";
|
|
4
4
|
|
|
5
5
|
type WithoutBodyOptions<TQuery, TParams, TQueryIn = unknown, TParamsIn = unknown> = {
|
|
6
|
-
query?: Schema<TQuery, TQueryIn
|
|
7
|
-
params?: Schema<TParams, TParamsIn
|
|
8
|
-
}
|
|
6
|
+
query?: Schema<TQuery, TQueryIn>;
|
|
7
|
+
params?: Schema<TParams, TParamsIn>;
|
|
8
|
+
};
|
|
9
9
|
|
|
10
10
|
type WithBodyOptions<
|
|
11
11
|
TQuery,
|
|
@@ -15,14 +15,16 @@ type WithBodyOptions<
|
|
|
15
15
|
TParamsIn = unknown,
|
|
16
16
|
TBodyIn = unknown,
|
|
17
17
|
> = WithoutBodyOptions<TQuery, TParams, TQueryIn, TParamsIn> & {
|
|
18
|
-
body?: Schema<TBody, TBodyIn
|
|
19
|
-
}
|
|
18
|
+
body?: Schema<TBody, TBodyIn>;
|
|
19
|
+
};
|
|
20
20
|
|
|
21
21
|
export type CreateWithoutBodyRoute<
|
|
22
|
-
M extends
|
|
22
|
+
M extends "GET" | "DELETE" | "OPTIONS" | "HEAD",
|
|
23
23
|
TAppContext extends Record<string, unknown> = AppContext,
|
|
24
24
|
> = {
|
|
25
|
-
<const Path extends RoutePath>(
|
|
25
|
+
<const Path extends RoutePath>(
|
|
26
|
+
path: Path,
|
|
27
|
+
): RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
|
|
26
28
|
<
|
|
27
29
|
const Path extends RoutePath,
|
|
28
30
|
TQuery = unknown,
|
|
@@ -37,21 +39,23 @@ export type CreateWithoutBodyRoute<
|
|
|
37
39
|
M,
|
|
38
40
|
readonly [],
|
|
39
41
|
{
|
|
40
|
-
query: TQuery
|
|
41
|
-
params: TParams
|
|
42
|
-
queryIn: TQueryIn
|
|
43
|
-
paramsIn: TParamsIn
|
|
42
|
+
query: TQuery;
|
|
43
|
+
params: TParams;
|
|
44
|
+
queryIn: TQueryIn;
|
|
45
|
+
paramsIn: TParamsIn;
|
|
44
46
|
},
|
|
45
47
|
{},
|
|
46
48
|
TAppContext
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
+
>;
|
|
50
|
+
};
|
|
49
51
|
|
|
50
52
|
export type CreateWithBodyRoute<
|
|
51
|
-
M extends
|
|
53
|
+
M extends "POST" | "PUT" | "PATCH",
|
|
52
54
|
TAppContext extends Record<string, unknown> = AppContext,
|
|
53
55
|
> = {
|
|
54
|
-
<const Path extends RoutePath>(
|
|
56
|
+
<const Path extends RoutePath>(
|
|
57
|
+
path: Path,
|
|
58
|
+
): RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
|
|
55
59
|
<
|
|
56
60
|
const Path extends RoutePath,
|
|
57
61
|
TQuery = unknown,
|
|
@@ -68,23 +72,23 @@ export type CreateWithBodyRoute<
|
|
|
68
72
|
M,
|
|
69
73
|
readonly [],
|
|
70
74
|
{
|
|
71
|
-
query: TQuery
|
|
72
|
-
params: TParams
|
|
73
|
-
body: TBody
|
|
74
|
-
queryIn: TQueryIn
|
|
75
|
-
paramsIn: TParamsIn
|
|
76
|
-
bodyIn: TBodyIn
|
|
75
|
+
query: TQuery;
|
|
76
|
+
params: TParams;
|
|
77
|
+
body: TBody;
|
|
78
|
+
queryIn: TQueryIn;
|
|
79
|
+
paramsIn: TParamsIn;
|
|
80
|
+
bodyIn: TBodyIn;
|
|
77
81
|
},
|
|
78
82
|
{},
|
|
79
83
|
TAppContext
|
|
80
|
-
|
|
81
|
-
}
|
|
84
|
+
>;
|
|
85
|
+
};
|
|
82
86
|
|
|
83
87
|
export type CreateAnyRoute<TAppContext extends Record<string, unknown> = AppContext> = {
|
|
84
88
|
<const Path extends RoutePath, const Methods extends readonly HttpMethod[]>(
|
|
85
89
|
path: Path,
|
|
86
90
|
methods: Methods,
|
|
87
|
-
): RouteBuilder<Path, Methods[number], readonly [], {}, {}, TAppContext
|
|
91
|
+
): RouteBuilder<Path, Methods[number], readonly [], {}, {}, TAppContext>;
|
|
88
92
|
<
|
|
89
93
|
const Path extends RoutePath,
|
|
90
94
|
const Methods extends readonly HttpMethod[],
|
|
@@ -103,20 +107,22 @@ export type CreateAnyRoute<TAppContext extends Record<string, unknown> = AppCont
|
|
|
103
107
|
Methods[number],
|
|
104
108
|
readonly [],
|
|
105
109
|
{
|
|
106
|
-
query: TQuery
|
|
107
|
-
params: TParams
|
|
108
|
-
body: TBody
|
|
109
|
-
queryIn: TQueryIn
|
|
110
|
-
paramsIn: TParamsIn
|
|
111
|
-
bodyIn: TBodyIn
|
|
110
|
+
query: TQuery;
|
|
111
|
+
params: TParams;
|
|
112
|
+
body: TBody;
|
|
113
|
+
queryIn: TQueryIn;
|
|
114
|
+
paramsIn: TParamsIn;
|
|
115
|
+
bodyIn: TBodyIn;
|
|
112
116
|
},
|
|
113
117
|
{},
|
|
114
118
|
TAppContext
|
|
115
|
-
|
|
116
|
-
}
|
|
119
|
+
>;
|
|
120
|
+
};
|
|
117
121
|
|
|
118
122
|
export type CreateAllRoute<TAppContext extends Record<string, unknown> = AppContext> = {
|
|
119
|
-
<const Path extends RoutePath>(
|
|
123
|
+
<const Path extends RoutePath>(
|
|
124
|
+
path: Path,
|
|
125
|
+
): RouteBuilder<Path, HttpMethod, readonly [], {}, {}, TAppContext>;
|
|
120
126
|
<
|
|
121
127
|
const Path extends RoutePath,
|
|
122
128
|
TQuery = unknown,
|
|
@@ -133,51 +139,47 @@ export type CreateAllRoute<TAppContext extends Record<string, unknown> = AppCont
|
|
|
133
139
|
HttpMethod,
|
|
134
140
|
readonly [],
|
|
135
141
|
{
|
|
136
|
-
query: TQuery
|
|
137
|
-
params: TParams
|
|
138
|
-
body: TBody
|
|
139
|
-
queryIn: TQueryIn
|
|
140
|
-
paramsIn: TParamsIn
|
|
141
|
-
bodyIn: TBodyIn
|
|
142
|
+
query: TQuery;
|
|
143
|
+
params: TParams;
|
|
144
|
+
body: TBody;
|
|
145
|
+
queryIn: TQueryIn;
|
|
146
|
+
paramsIn: TParamsIn;
|
|
147
|
+
bodyIn: TBodyIn;
|
|
142
148
|
},
|
|
143
149
|
{},
|
|
144
150
|
TAppContext
|
|
145
|
-
|
|
146
|
-
}
|
|
151
|
+
>;
|
|
152
|
+
};
|
|
147
153
|
|
|
148
|
-
function createWithoutBodyRoute<M extends
|
|
154
|
+
function createWithoutBodyRoute<M extends "GET" | "DELETE" | "OPTIONS" | "HEAD">(
|
|
149
155
|
method: M,
|
|
150
156
|
): CreateWithoutBodyRoute<M> {
|
|
151
157
|
return ((path: string, options?: WithoutBodyOptions<unknown, unknown>) =>
|
|
152
|
-
createRouteBuilder(path, method, options)
|
|
153
|
-
) as unknown as CreateWithoutBodyRoute<M>
|
|
158
|
+
createRouteBuilder(path, method, options)) as unknown as CreateWithoutBodyRoute<M>;
|
|
154
159
|
}
|
|
155
160
|
|
|
156
|
-
function createWithBodyRoute<M extends
|
|
161
|
+
function createWithBodyRoute<M extends "POST" | "PUT" | "PATCH">(
|
|
157
162
|
method: M,
|
|
158
163
|
): CreateWithBodyRoute<M> {
|
|
159
164
|
return ((path: string, options?: WithBodyOptions<unknown, unknown, unknown>) =>
|
|
160
|
-
createRouteBuilder(path, method, options)
|
|
161
|
-
) as unknown as CreateWithBodyRoute<M>
|
|
165
|
+
createRouteBuilder(path, method, options)) as unknown as CreateWithBodyRoute<M>;
|
|
162
166
|
}
|
|
163
167
|
|
|
164
|
-
export const createGetRoute = createWithoutBodyRoute(
|
|
165
|
-
export const createDeleteRoute = createWithoutBodyRoute(
|
|
166
|
-
export const createOptionsRoute = createWithoutBodyRoute(
|
|
167
|
-
export const createHeadRoute = createWithoutBodyRoute(
|
|
168
|
-
export const createPostRoute = createWithBodyRoute(
|
|
169
|
-
export const createPutRoute = createWithBodyRoute(
|
|
170
|
-
export const createPatchRoute = createWithBodyRoute(
|
|
168
|
+
export const createGetRoute = createWithoutBodyRoute("GET");
|
|
169
|
+
export const createDeleteRoute = createWithoutBodyRoute("DELETE");
|
|
170
|
+
export const createOptionsRoute = createWithoutBodyRoute("OPTIONS");
|
|
171
|
+
export const createHeadRoute = createWithoutBodyRoute("HEAD");
|
|
172
|
+
export const createPostRoute = createWithBodyRoute("POST");
|
|
173
|
+
export const createPutRoute = createWithBodyRoute("PUT");
|
|
174
|
+
export const createPatchRoute = createWithBodyRoute("PATCH");
|
|
171
175
|
|
|
172
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
173
176
|
export const createAnyRoute: CreateAnyRoute = ((
|
|
174
177
|
path: string,
|
|
175
178
|
methods: readonly HttpMethod[],
|
|
176
179
|
options?: WithBodyOptions<unknown, unknown, unknown>,
|
|
177
|
-
) => createRouteBuilder(path,
|
|
180
|
+
) => createRouteBuilder(path, "ANY", options, methods)) as unknown as CreateAnyRoute;
|
|
178
181
|
|
|
179
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
180
182
|
export const createAllRoute: CreateAllRoute = ((
|
|
181
183
|
path: string,
|
|
182
184
|
options?: WithBodyOptions<unknown, unknown, unknown>,
|
|
183
|
-
) => createRouteBuilder(path,
|
|
185
|
+
) => createRouteBuilder(path, "ALL", options)) as unknown as CreateAllRoute;
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { RouterRegister } from
|
|
1
|
+
export type { RouterRegister } from "./register.js";
|
|
2
2
|
export type {
|
|
3
3
|
InferInput,
|
|
4
4
|
InferOutput,
|
|
@@ -8,7 +8,7 @@ export type {
|
|
|
8
8
|
RoutePath,
|
|
9
9
|
Schema,
|
|
10
10
|
Simplify,
|
|
11
|
-
} from
|
|
11
|
+
} from "./types/index.js";
|
|
12
12
|
export type {
|
|
13
13
|
ContextDefinition,
|
|
14
14
|
CreateContextArgs,
|
|
@@ -18,7 +18,7 @@ export type {
|
|
|
18
18
|
OnErrorOptions,
|
|
19
19
|
RouteManifestShape,
|
|
20
20
|
TaserHandler,
|
|
21
|
-
} from
|
|
21
|
+
} from "./types/app.js";
|
|
22
22
|
|
|
23
23
|
export {
|
|
24
24
|
isReplyResult,
|
|
@@ -26,20 +26,20 @@ export {
|
|
|
26
26
|
stream,
|
|
27
27
|
ValidationError,
|
|
28
28
|
validationErrorSchema,
|
|
29
|
-
} from
|
|
29
|
+
} from "@taserjs/router-utils";
|
|
30
30
|
export type {
|
|
31
31
|
ReplyBodyKind,
|
|
32
32
|
ReplyOf,
|
|
33
33
|
ResponseValidationFailureHandler,
|
|
34
34
|
SuccessReplyData,
|
|
35
35
|
SuccessStatusCode,
|
|
36
|
-
} from
|
|
36
|
+
} from "@taserjs/router-utils";
|
|
37
37
|
|
|
38
|
-
export { createAnyRoute, createAllRoute } from
|
|
39
|
-
export { createTaserApp, TaserRouter } from
|
|
40
|
-
export { TaserApp,
|
|
41
|
-
export { createContext } from
|
|
42
|
-
export { defineHandler } from
|
|
43
|
-
export { defineMiddleware } from
|
|
38
|
+
export { createAnyRoute, createAllRoute } from "./factories.js";
|
|
39
|
+
export { createTaserApp, TaserRouter } from "./taser-router.js";
|
|
40
|
+
export { TaserApp, TaserNativeBound } from "./taser-app.js";
|
|
41
|
+
export { createContext } from "./create-context.js";
|
|
42
|
+
export { defineHandler } from "./define/handler.js";
|
|
43
|
+
export { defineMiddleware } from "./define/middleware.js";
|
|
44
44
|
|
|
45
|
-
export type { TaserCookieJar, TaserHeaders } from
|
|
45
|
+
export type { TaserCookieJar, TaserHeaders } from "@taserjs/router-core";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { bodyLimit as honoBodyLimit } from
|
|
1
|
+
import { bodyLimit as honoBodyLimit } from "hono/body-limit";
|
|
2
2
|
|
|
3
|
-
import { wrapHonoMiddleware } from
|
|
3
|
+
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const honoBodyLimitMiddleware = wrapHonoMiddleware(honoBodyLimit)
|
|
5
|
+
const honoBodyLimitMiddleware = wrapHonoMiddleware(honoBodyLimit);
|
|
6
6
|
|
|
7
7
|
export function bodyLimit(...args: Parameters<typeof honoBodyLimit>) {
|
|
8
|
-
return honoBodyLimitMiddleware(...args)
|
|
8
|
+
return honoBodyLimitMiddleware(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type BodyLimitOptions = Parameters<typeof honoBodyLimit>[0]
|
|
11
|
+
export type BodyLimitOptions = Parameters<typeof honoBodyLimit>[0];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { compress as honoCompress } from
|
|
1
|
+
import { compress as honoCompress } from "hono/compress";
|
|
2
2
|
|
|
3
|
-
import { wrapHonoMiddleware } from
|
|
3
|
+
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const honoCompressMiddleware = wrapHonoMiddleware(honoCompress)
|
|
5
|
+
const honoCompressMiddleware = wrapHonoMiddleware(honoCompress);
|
|
6
6
|
|
|
7
7
|
export function compress(...args: Parameters<typeof honoCompress>) {
|
|
8
|
-
return honoCompressMiddleware(...args)
|
|
8
|
+
return honoCompressMiddleware(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type CompressOptions = NonNullable<Parameters<typeof honoCompress>[0]
|
|
11
|
+
export type CompressOptions = NonNullable<Parameters<typeof honoCompress>[0]>;
|
package/src/middleware/cors.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { cors as honoCors } from
|
|
1
|
+
import { cors as honoCors } from "hono/cors";
|
|
2
2
|
|
|
3
|
-
import { wrapHonoMiddleware } from
|
|
3
|
+
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const honoCorsMiddleware = wrapHonoMiddleware(honoCors)
|
|
5
|
+
const honoCorsMiddleware = wrapHonoMiddleware(honoCors);
|
|
6
6
|
|
|
7
7
|
export function cors(...args: Parameters<typeof honoCors>) {
|
|
8
|
-
return honoCorsMiddleware(...args)
|
|
8
|
+
return honoCorsMiddleware(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type CorsOptions = NonNullable<Parameters<typeof honoCors>[0]
|
|
11
|
+
export type CorsOptions = NonNullable<Parameters<typeof honoCors>[0]>;
|
package/src/middleware/csrf.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { csrf as honoCsrf } from
|
|
1
|
+
import { csrf as honoCsrf } from "hono/csrf";
|
|
2
2
|
|
|
3
|
-
import { wrapHonoMiddleware } from
|
|
3
|
+
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const honoCsrfMiddleware = wrapHonoMiddleware(honoCsrf)
|
|
5
|
+
const honoCsrfMiddleware = wrapHonoMiddleware(honoCsrf);
|
|
6
6
|
|
|
7
7
|
export function csrf(...args: Parameters<typeof honoCsrf>) {
|
|
8
|
-
return honoCsrfMiddleware(...args)
|
|
8
|
+
return honoCsrfMiddleware(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type CsrfOptions = NonNullable<Parameters<typeof honoCsrf>[0]
|
|
11
|
+
export type CsrfOptions = NonNullable<Parameters<typeof honoCsrf>[0]>;
|
package/src/middleware/etag.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { etag as honoEtag } from
|
|
1
|
+
import { etag as honoEtag } from "hono/etag";
|
|
2
2
|
|
|
3
|
-
import { wrapHonoMiddleware } from
|
|
3
|
+
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const honoEtagMiddleware = wrapHonoMiddleware(honoEtag)
|
|
5
|
+
const honoEtagMiddleware = wrapHonoMiddleware(honoEtag);
|
|
6
6
|
|
|
7
7
|
export function etag(...args: Parameters<typeof honoEtag>) {
|
|
8
|
-
return honoEtagMiddleware(...args)
|
|
8
|
+
return honoEtagMiddleware(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type EtagOptions = NonNullable<Parameters<typeof honoEtag>[0]
|
|
11
|
+
export type EtagOptions = NonNullable<Parameters<typeof honoEtag>[0]>;
|
package/src/middleware/jwk.ts
CHANGED
|
@@ -1,47 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createTaserCompatHandler } from "@taserjs/router-core";
|
|
2
|
+
import type { MiddlewareHandler } from "hono";
|
|
3
|
+
import { jwk as honoJwk } from "hono/jwk";
|
|
2
4
|
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
+
import { defineMiddleware } from "../define/middleware.js";
|
|
6
|
+
import type { JwtMiddlewareUnit, JwtPayloadState } from "./jwt.js";
|
|
5
7
|
|
|
6
|
-
export type JwkOptions = Parameters<typeof honoJwk>[0]
|
|
8
|
+
export type JwkOptions = Parameters<typeof honoJwk>[0];
|
|
7
9
|
|
|
8
|
-
export type JwkRequestInit = Pick<RequestInit,
|
|
10
|
+
export type JwkRequestInit = Pick<RequestInit, "headers">;
|
|
9
11
|
|
|
10
12
|
export type JwkMiddlewareOptions = JwkOptions & {
|
|
11
13
|
/** Allow `http://` JWKS URLs (local dev). Default false — requires `https://`. */
|
|
12
|
-
allowInsecure?: boolean
|
|
13
|
-
}
|
|
14
|
+
allowInsecure?: boolean;
|
|
15
|
+
};
|
|
14
16
|
|
|
15
17
|
function assertJwksScheme(jwksUri: string, allowInsecure: boolean): void {
|
|
16
|
-
const scheme = new URL(jwksUri).protocol.replace(
|
|
17
|
-
if (scheme ===
|
|
18
|
-
return
|
|
18
|
+
const scheme = new URL(jwksUri).protocol.replace(":", "");
|
|
19
|
+
if (scheme === "https") {
|
|
20
|
+
return;
|
|
19
21
|
}
|
|
20
|
-
if (scheme ===
|
|
21
|
-
return
|
|
22
|
+
if (scheme === "http" && allowInsecure) {
|
|
23
|
+
return;
|
|
22
24
|
}
|
|
23
|
-
throw new Error(
|
|
24
|
-
`JWKS URL must use https:// (or http:// with allowInsecure: true): "${jwksUri}"`,
|
|
25
|
-
)
|
|
25
|
+
throw new Error(`JWKS URL must use https:// (or http:// with allowInsecure: true): "${jwksUri}"`);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* JWK auth middleware. Invalid or missing tokens return **401** (Hono).
|
|
30
|
-
*
|
|
30
|
+
* Successfully decoded payload is placed in `ctx.state.jwtPayload`.
|
|
31
31
|
* Static `jwks_uri` must use HTTPS unless `allowInsecure: true`.
|
|
32
32
|
*/
|
|
33
|
-
export function jwk<TPayload
|
|
34
|
-
payloadSchema: Schema<TPayload>,
|
|
33
|
+
export function jwk<TPayload = Record<string, unknown>>(
|
|
35
34
|
options: JwkMiddlewareOptions,
|
|
36
35
|
init?: JwkRequestInit,
|
|
37
|
-
):
|
|
38
|
-
const jwksUri = options.jwks_uri
|
|
39
|
-
if (typeof jwksUri ===
|
|
40
|
-
assertJwksScheme(jwksUri, options.allowInsecure ?? false)
|
|
36
|
+
): JwtMiddlewareUnit<TPayload> {
|
|
37
|
+
const jwksUri = options.jwks_uri;
|
|
38
|
+
if (typeof jwksUri === "string") {
|
|
39
|
+
assertJwksScheme(jwksUri, options.allowInsecure ?? false);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
const { allowInsecure: _allowInsecure, ...honoOptions } = options
|
|
44
|
-
const safeInit = init?.headers !== undefined ? { headers: init.headers } : undefined
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const { allowInsecure: _allowInsecure, ...honoOptions } = options;
|
|
43
|
+
const safeInit = init?.headers !== undefined ? { headers: init.headers } : undefined;
|
|
44
|
+
const honoMw: MiddlewareHandler = honoJwk(honoOptions, safeInit);
|
|
45
|
+
|
|
46
|
+
return defineMiddleware<JwtPayloadState<TPayload>>({
|
|
47
|
+
handler: (ctx, next) => {
|
|
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
|
+
},
|
|
53
|
+
});
|
|
47
54
|
}
|
package/src/middleware/jwt.ts
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createTaserCompatHandler } from "@taserjs/router-core";
|
|
2
|
+
import type { MiddlewareHandler } from "hono";
|
|
3
|
+
import { jwt as honoJwt } from "hono/jwt";
|
|
2
4
|
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
+
import { defineMiddleware } from "../define/middleware.js";
|
|
6
|
+
import type { MiddlewareReturnFromParts, MiddlewareUnit } from "../types/units.js";
|
|
5
7
|
|
|
6
|
-
export type
|
|
8
|
+
export type JwtPayloadState<TPayload> = {
|
|
9
|
+
jwtPayload: TPayload;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type JwtMiddlewareUnit<TPayload> = MiddlewareUnit<
|
|
13
|
+
MiddlewareReturnFromParts<unknown, unknown, unknown, JwtPayloadState<TPayload>>
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
export type JwtOptions = Parameters<typeof honoJwt>[0];
|
|
7
17
|
|
|
8
18
|
/**
|
|
9
19
|
* JWT auth middleware. Invalid or missing tokens return **401** (Hono).
|
|
10
|
-
*
|
|
11
|
-
* Use optional schema fields for intentionally optional claims.
|
|
20
|
+
* Successfully decoded payload is placed in `ctx.state.jwtPayload`.
|
|
12
21
|
*/
|
|
13
|
-
export function jwt<TPayload
|
|
14
|
-
payloadSchema: Schema<TPayload>,
|
|
22
|
+
export function jwt<TPayload = Record<string, unknown>>(
|
|
15
23
|
options: JwtOptions,
|
|
16
|
-
):
|
|
17
|
-
|
|
24
|
+
): JwtMiddlewareUnit<TPayload> {
|
|
25
|
+
const honoMw: MiddlewareHandler = honoJwt(options);
|
|
26
|
+
return defineMiddleware<JwtPayloadState<TPayload>>({
|
|
27
|
+
handler: (ctx, next) => {
|
|
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
|
+
},
|
|
33
|
+
});
|
|
18
34
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { secureHeaders as honoSecureHeaders } from
|
|
1
|
+
import { secureHeaders as honoSecureHeaders } from "hono/secure-headers";
|
|
2
2
|
|
|
3
|
-
import { wrapHonoMiddleware } from
|
|
3
|
+
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const honoSecureHeadersMiddleware = wrapHonoMiddleware(honoSecureHeaders)
|
|
5
|
+
const honoSecureHeadersMiddleware = wrapHonoMiddleware(honoSecureHeaders);
|
|
6
6
|
|
|
7
7
|
export function secureHeaders(...args: Parameters<typeof honoSecureHeaders>) {
|
|
8
|
-
return honoSecureHeadersMiddleware(...args)
|
|
8
|
+
return honoSecureHeadersMiddleware(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type SecureHeadersOptions = NonNullable<Parameters<typeof honoSecureHeaders>[0]
|
|
11
|
+
export type SecureHeadersOptions = NonNullable<Parameters<typeof honoSecureHeaders>[0]>;
|
package/src/middleware/timing.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { timing as honoTiming } from
|
|
1
|
+
import { timing as honoTiming } from "hono/timing";
|
|
2
2
|
|
|
3
|
-
import { wrapHonoMiddleware } from
|
|
3
|
+
import { wrapHonoMiddleware } from "./wrap-hono.js";
|
|
4
4
|
|
|
5
|
-
const honoTimingMiddleware = wrapHonoMiddleware(honoTiming)
|
|
5
|
+
const honoTimingMiddleware = wrapHonoMiddleware(honoTiming);
|
|
6
6
|
|
|
7
7
|
export function timing(...args: Parameters<typeof honoTiming>) {
|
|
8
|
-
return honoTimingMiddleware(...args)
|
|
8
|
+
return honoTimingMiddleware(...args);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export type TimingOptions = NonNullable<Parameters<typeof honoTiming>[0]
|
|
11
|
+
export type TimingOptions = NonNullable<Parameters<typeof honoTiming>[0]>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from "hono";
|
|
2
|
+
|
|
3
|
+
import { defineMiddleware } from "../define/middleware.js";
|
|
4
|
+
import type { MiddlewareReturnFromParts, MiddlewareUnit } from "../types/units.js";
|
|
5
|
+
|
|
6
|
+
export function wrapHonoMiddleware<F extends (...args: never[]) => MiddlewareHandler>(
|
|
7
|
+
honoFactory: F,
|
|
8
|
+
): (
|
|
9
|
+
...args: Parameters<F>
|
|
10
|
+
) => MiddlewareUnit<MiddlewareReturnFromParts<unknown, unknown, unknown, {}>> {
|
|
11
|
+
return (...args) => defineMiddleware(honoFactory(...args));
|
|
12
|
+
}
|
package/src/middleware.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { LayoutId, MiddlewareBuilder } from
|
|
2
|
-
import type { MiddlewareDefinition } from
|
|
1
|
+
import type { LayoutId, MiddlewareBuilder } from "./types/index.js";
|
|
2
|
+
import type { MiddlewareDefinition } from "./types/units.js";
|
|
3
3
|
|
|
4
4
|
export function createMiddleware<const Layout extends LayoutId>(
|
|
5
5
|
layout: Layout,
|
|
6
6
|
): MiddlewareBuilder<Layout, readonly []> {
|
|
7
|
-
const entries: MiddlewareDefinition[] = []
|
|
7
|
+
const entries: MiddlewareDefinition[] = [];
|
|
8
8
|
|
|
9
9
|
const chain = {
|
|
10
10
|
layout,
|
|
11
11
|
middlewares: entries,
|
|
12
12
|
use(definition: MiddlewareDefinition) {
|
|
13
|
-
entries.push(definition)
|
|
14
|
-
return chain
|
|
13
|
+
entries.push(definition);
|
|
14
|
+
return chain;
|
|
15
15
|
},
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
|
|
18
|
-
return chain as unknown as MiddlewareBuilder<Layout, readonly []
|
|
18
|
+
return chain as unknown as MiddlewareBuilder<Layout, readonly []>;
|
|
19
19
|
}
|
package/src/reply.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
errorReply,
|
|
3
|
-
reply,
|
|
4
|
-
successReply,
|
|
5
|
-
} from '@taserjs/router-utils/reply'
|
|
1
|
+
export { errorReply, reply, successReply } from "@taserjs/router-utils/reply";
|
|
6
2
|
export type {
|
|
7
3
|
BinaryBody,
|
|
8
4
|
BodyKind,
|
|
@@ -12,4 +8,4 @@ export type {
|
|
|
12
8
|
ReplyInit,
|
|
13
9
|
ReplyOf,
|
|
14
10
|
SuccessReplyData,
|
|
15
|
-
} from
|
|
11
|
+
} from "@taserjs/router-utils/reply";
|