@taserjs/router 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/app.cjs +27 -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} +5 -5
- package/dist/cjs/builder/factories.cjs.map +1 -0
- package/dist/cjs/builder/factories.d.cts +15 -0
- 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} +41 -34
- package/dist/cjs/builder/route.cjs.map +1 -0
- package/dist/cjs/builder/route.d.cts +4 -0
- package/dist/cjs/{taser-router.cjs → builder/router.cjs} +38 -13
- package/dist/cjs/builder/router.cjs.map +1 -0
- package/dist/{esm/taser-router.d.ts → cjs/builder/router.d.cts} +16 -11
- 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 +2 -2
- package/dist/cjs/define/middleware.cjs.map +1 -1
- package/dist/cjs/define/middleware.d.cts +10 -8
- 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 -28
- package/dist/cjs/index.d.cts +7 -8
- 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/reply.cjs +8 -19
- package/dist/cjs/reply.d.cts +1 -2
- package/dist/cjs/stream.cjs +8 -31
- package/dist/cjs/stream.d.cts +1 -1
- package/dist/cjs/types/app.d.cts +8 -26
- package/dist/cjs/types/index.d.cts +60 -19
- package/dist/cjs/types/returns.d.cts +8 -11
- package/dist/cjs/types/type-utils.d.cts +8 -7
- package/dist/cjs/types/units.cjs.map +1 -1
- package/dist/cjs/types/units.d.cts +6 -17
- package/dist/esm/builder/app.d.ts +11 -0
- package/dist/esm/builder/app.js +26 -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/builder/factories.d.ts +15 -0
- package/dist/esm/{factories.js → builder/factories.js} +5 -5
- 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/builder/route.d.ts +4 -0
- package/dist/esm/{route.js → builder/route.js} +41 -34
- package/dist/esm/builder/route.js.map +1 -0
- package/dist/{cjs/taser-router.d.cts → esm/builder/router.d.ts} +16 -11
- package/dist/esm/{taser-router.js → builder/router.js} +37 -12
- 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 +10 -8
- package/dist/esm/define/middleware.js +2 -2
- 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 +7 -8
- 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/reply.d.ts +1 -2
- package/dist/esm/reply.js +1 -2
- package/dist/esm/stream.d.ts +1 -1
- package/dist/esm/stream.js +1 -2
- package/dist/esm/types/app.d.ts +8 -26
- package/dist/esm/types/index.d.ts +60 -19
- package/dist/esm/types/returns.d.ts +8 -11
- package/dist/esm/types/type-utils.d.ts +8 -7
- package/dist/esm/types/units.d.ts +6 -17
- package/dist/esm/types/units.js.map +1 -1
- package/package.json +3 -3
- package/src/builder/app.ts +39 -0
- package/src/builder/factories.ts +58 -0
- package/src/{middleware.ts → builder/middleware.ts} +2 -2
- package/src/{route.ts → builder/route.ts} +55 -35
- package/src/{taser-router.ts → builder/router.ts} +77 -28
- package/src/{create-context.ts → context/create-context.ts} +2 -2
- package/src/define/middleware.ts +115 -123
- package/src/define/validators.ts +1 -1
- package/src/index.ts +13 -20
- 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/reply.ts +1 -11
- package/src/stream.ts +1 -1
- package/src/types/app.ts +13 -28
- package/src/types/index.ts +126 -22
- package/src/types/returns.ts +9 -78
- package/src/types/type-utils.ts +10 -6
- package/src/types/units.ts +36 -16
- 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/factories.d.cts +0 -61
- package/dist/cjs/middleware.cjs.map +0 -1
- package/dist/cjs/route.cjs.map +0 -1
- package/dist/cjs/route.d.cts +0 -5
- 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/esm/constants.js.map +0 -1
- package/dist/esm/create-context.js.map +0 -1
- package/dist/esm/factories.d.ts +0 -61
- package/dist/esm/factories.js.map +0 -1
- package/dist/esm/middleware.js.map +0 -1
- package/dist/esm/route.d.ts +0 -5
- 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.js.map +0 -1
- package/src/factories.ts +0 -185
- package/src/taser-app.ts +0 -38
- /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/dist/cjs/index.d.cts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export type { RouterRegister } from './register.js';
|
|
2
|
-
export type { InferInput, InferOutput, Method, PathParams, ReturnsMap, RoutePath, Schema, Simplify, } from './types/index.js';
|
|
3
|
-
export type { ContextDefinition,
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export { createContext } from './create-context.js';
|
|
2
|
+
export type { HttpMethod, InferInput, InferOutput, InferRouteContext, InferRouteInput, InferRouteOutput, Method, MiddlewareDefinition, PathParams, ReturnsMap, RouteDefinition, RouteExport, RoutePath, Schema, Simplify, StatusCode, } from './types/index.js';
|
|
3
|
+
export type { ContextDefinition, CreateTaserAppOptions, InferAppContext, InferAppManifest, OnErrorOptions, RouteManifestShape, } from './types/app.js';
|
|
4
|
+
export { ValidationError, validationErrorSchema } from '@taserjs/router-utils';
|
|
5
|
+
export type { ResponseValidationFailureHandler, SuccessStatusCode } from '@taserjs/router-utils';
|
|
6
|
+
export { createTaserApp, TaserRouter } from './builder/router.js';
|
|
7
|
+
export { TaserApp } from './builder/app.js';
|
|
8
|
+
export { createContext } from './context/create-context.js';
|
|
10
9
|
export { defineHandler } from './define/handler.js';
|
|
11
10
|
export { defineMiddleware } from './define/middleware.js';
|
|
12
11
|
export type { TaserCookieJar, TaserHeaders } from '@taserjs/router-core';
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_wrap_hono = require("./wrap-hono.cjs");
|
|
3
3
|
let hono_body_limit = require("hono/body-limit");
|
|
4
4
|
//#region src/middleware/body-limit.ts
|
|
5
|
-
var
|
|
5
|
+
var wrapped = require_wrap_hono.wrapHonoMiddleware(hono_body_limit.bodyLimit);
|
|
6
6
|
function bodyLimit(...args) {
|
|
7
|
-
return
|
|
7
|
+
return wrapped(...args);
|
|
8
8
|
}
|
|
9
9
|
//#endregion
|
|
10
10
|
exports.bodyLimit = bodyLimit;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-limit.cjs","names":[],"sources":["../../../src/middleware/body-limit.ts"],"sourcesContent":["import { bodyLimit as honoBodyLimit } from \"hono/body-limit\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst
|
|
1
|
+
{"version":3,"file":"body-limit.cjs","names":[],"sources":["../../../src/middleware/body-limit.ts"],"sourcesContent":["import { bodyLimit as honoBodyLimit } from \"hono/body-limit\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst wrapped = wrapHonoMiddleware(honoBodyLimit);\n\nexport function bodyLimit(...args: Parameters<typeof honoBodyLimit>) {\n return wrapped(...args);\n}\n\nexport type BodyLimitOptions = Parameters<typeof honoBodyLimit>[0];\n"],"mappings":";;;;AAIA,IAAM,UAAU,kBAAA,mBAAmB,gBAAA,SAAa;AAEhD,SAAgB,UAAU,GAAG,MAAwC;CACnE,OAAO,QAAQ,GAAG,IAAI;AACxB"}
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_wrap_hono = require("./wrap-hono.cjs");
|
|
3
3
|
let hono_compress = require("hono/compress");
|
|
4
4
|
//#region src/middleware/compress.ts
|
|
5
|
-
var
|
|
5
|
+
var wrapped = require_wrap_hono.wrapHonoMiddleware(hono_compress.compress);
|
|
6
6
|
function compress(...args) {
|
|
7
|
-
return
|
|
7
|
+
return wrapped(...args);
|
|
8
8
|
}
|
|
9
9
|
//#endregion
|
|
10
10
|
exports.compress = compress;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress.cjs","names":[],"sources":["../../../src/middleware/compress.ts"],"sourcesContent":["import { compress as honoCompress } from \"hono/compress\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst
|
|
1
|
+
{"version":3,"file":"compress.cjs","names":[],"sources":["../../../src/middleware/compress.ts"],"sourcesContent":["import { compress as honoCompress } from \"hono/compress\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst wrapped = wrapHonoMiddleware(honoCompress);\n\nexport function compress(...args: Parameters<typeof honoCompress>) {\n return wrapped(...args);\n}\n\nexport type CompressOptions = NonNullable<Parameters<typeof honoCompress>[0]>;\n"],"mappings":";;;;AAIA,IAAM,UAAU,kBAAA,mBAAmB,cAAA,QAAY;AAE/C,SAAgB,SAAS,GAAG,MAAuC;CACjE,OAAO,QAAQ,GAAG,IAAI;AACxB"}
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_wrap_hono = require("./wrap-hono.cjs");
|
|
3
3
|
let hono_cors = require("hono/cors");
|
|
4
4
|
//#region src/middleware/cors.ts
|
|
5
|
-
var
|
|
5
|
+
var wrapped = require_wrap_hono.wrapHonoMiddleware(hono_cors.cors);
|
|
6
6
|
function cors(...args) {
|
|
7
|
-
return
|
|
7
|
+
return wrapped(...args);
|
|
8
8
|
}
|
|
9
9
|
//#endregion
|
|
10
10
|
exports.cors = cors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.cjs","names":[],"sources":["../../../src/middleware/cors.ts"],"sourcesContent":["import { cors as honoCors } from \"hono/cors\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst
|
|
1
|
+
{"version":3,"file":"cors.cjs","names":[],"sources":["../../../src/middleware/cors.ts"],"sourcesContent":["import { cors as honoCors } from \"hono/cors\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst wrapped = wrapHonoMiddleware(honoCors);\n\nexport function cors(...args: Parameters<typeof honoCors>) {\n return wrapped(...args);\n}\n\nexport type CorsOptions = NonNullable<Parameters<typeof honoCors>[0]>;\n"],"mappings":";;;;AAIA,IAAM,UAAU,kBAAA,mBAAmB,UAAA,IAAQ;AAE3C,SAAgB,KAAK,GAAG,MAAmC;CACzD,OAAO,QAAQ,GAAG,IAAI;AACxB"}
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_wrap_hono = require("./wrap-hono.cjs");
|
|
3
3
|
let hono_csrf = require("hono/csrf");
|
|
4
4
|
//#region src/middleware/csrf.ts
|
|
5
|
-
var
|
|
5
|
+
var wrapped = require_wrap_hono.wrapHonoMiddleware(hono_csrf.csrf);
|
|
6
6
|
function csrf(...args) {
|
|
7
|
-
return
|
|
7
|
+
return wrapped(...args);
|
|
8
8
|
}
|
|
9
9
|
//#endregion
|
|
10
10
|
exports.csrf = csrf;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csrf.cjs","names":[],"sources":["../../../src/middleware/csrf.ts"],"sourcesContent":["import { csrf as honoCsrf } from \"hono/csrf\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst
|
|
1
|
+
{"version":3,"file":"csrf.cjs","names":[],"sources":["../../../src/middleware/csrf.ts"],"sourcesContent":["import { csrf as honoCsrf } from \"hono/csrf\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst wrapped = wrapHonoMiddleware(honoCsrf);\n\nexport function csrf(...args: Parameters<typeof honoCsrf>) {\n return wrapped(...args);\n}\n\nexport type CsrfOptions = NonNullable<Parameters<typeof honoCsrf>[0]>;\n"],"mappings":";;;;AAIA,IAAM,UAAU,kBAAA,mBAAmB,UAAA,IAAQ;AAE3C,SAAgB,KAAK,GAAG,MAAmC;CACzD,OAAO,QAAQ,GAAG,IAAI;AACxB"}
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_wrap_hono = require("./wrap-hono.cjs");
|
|
3
3
|
let hono_etag = require("hono/etag");
|
|
4
4
|
//#region src/middleware/etag.ts
|
|
5
|
-
var
|
|
5
|
+
var wrapped = require_wrap_hono.wrapHonoMiddleware(hono_etag.etag);
|
|
6
6
|
function etag(...args) {
|
|
7
|
-
return
|
|
7
|
+
return wrapped(...args);
|
|
8
8
|
}
|
|
9
9
|
//#endregion
|
|
10
10
|
exports.etag = etag;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"etag.cjs","names":[],"sources":["../../../src/middleware/etag.ts"],"sourcesContent":["import { etag as honoEtag } from \"hono/etag\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst
|
|
1
|
+
{"version":3,"file":"etag.cjs","names":[],"sources":["../../../src/middleware/etag.ts"],"sourcesContent":["import { etag as honoEtag } from \"hono/etag\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst wrapped = wrapHonoMiddleware(honoEtag);\n\nexport function etag(...args: Parameters<typeof honoEtag>) {\n return wrapped(...args);\n}\n\nexport type EtagOptions = NonNullable<Parameters<typeof honoEtag>[0]>;\n"],"mappings":";;;;AAIA,IAAM,UAAU,kBAAA,mBAAmB,UAAA,IAAQ;AAE3C,SAAgB,KAAK,GAAG,MAAmC;CACzD,OAAO,QAAQ,GAAG,IAAI;AACxB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_middleware = require("../define/middleware.cjs");
|
|
3
|
-
|
|
3
|
+
const require_wrap_hono = require("./wrap-hono.cjs");
|
|
4
4
|
let hono_jwk = require("hono/jwk");
|
|
5
5
|
//#region src/middleware/jwk.ts
|
|
6
6
|
function assertJwksScheme(jwksUri, allowInsecure) {
|
|
@@ -18,13 +18,7 @@ function jwk(options, init) {
|
|
|
18
18
|
const jwksUri = options.jwks_uri;
|
|
19
19
|
if (typeof jwksUri === "string") assertJwksScheme(jwksUri, options.allowInsecure ?? false);
|
|
20
20
|
const { allowInsecure: _allowInsecure, ...honoOptions } = options;
|
|
21
|
-
|
|
22
|
-
return require_middleware.defineMiddleware({ handler: (ctx, next) => {
|
|
23
|
-
return (0, _taserjs_router_core.createTaserCompatHandler)(honoMw)(ctx, async () => {
|
|
24
|
-
const payload = ctx.var.jwtPayload;
|
|
25
|
-
return next({ jwtPayload: payload });
|
|
26
|
-
});
|
|
27
|
-
} });
|
|
21
|
+
return require_middleware.defineMiddleware({ handler: require_wrap_hono.extractJwtPayload((0, hono_jwk.jwk)(honoOptions, init?.headers !== void 0 ? { headers: init.headers } : void 0)) });
|
|
28
22
|
}
|
|
29
23
|
//#endregion
|
|
30
24
|
exports.jwk = jwk;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwk.cjs","names":[],"sources":["../../../src/middleware/jwk.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"jwk.cjs","names":[],"sources":["../../../src/middleware/jwk.ts"],"sourcesContent":["import type { MiddlewareHandler } from \"hono\";\nimport { jwk as honoJwk } from \"hono/jwk\";\n\nimport { defineMiddleware } from \"../define/middleware.js\";\nimport type { JwtMiddlewareUnit, JwtPayloadState } from \"./jwt.js\";\nimport { extractJwtPayload } from \"./wrap-hono.js\";\n\nexport type JwkOptions = Parameters<typeof honoJwk>[0];\n\nexport type JwkRequestInit = Pick<RequestInit, \"headers\">;\n\nexport type JwkMiddlewareOptions = JwkOptions & {\n /** Allow `http://` JWKS URLs (local dev). Default false — requires `https://`. */\n allowInsecure?: boolean;\n};\n\nfunction assertJwksScheme(jwksUri: string, allowInsecure: boolean): void {\n const scheme = new URL(jwksUri).protocol.replace(\":\", \"\");\n if (scheme === \"https\") {\n return;\n }\n if (scheme === \"http\" && allowInsecure) {\n return;\n }\n throw new Error(`JWKS URL must use https:// (or http:// with allowInsecure: true): \"${jwksUri}\"`);\n}\n\n/**\n * JWK auth middleware. Invalid or missing tokens return **401** (Hono).\n * Successfully decoded payload is placed in `ctx.state.jwtPayload`.\n * Static `jwks_uri` must use HTTPS unless `allowInsecure: true`.\n */\nexport function jwk<TPayload = Record<string, unknown>>(\n options: JwkMiddlewareOptions,\n init?: JwkRequestInit,\n): JwtMiddlewareUnit<TPayload> {\n const jwksUri = options.jwks_uri;\n if (typeof jwksUri === \"string\") {\n assertJwksScheme(jwksUri, options.allowInsecure ?? false);\n }\n\n const { allowInsecure: _allowInsecure, ...honoOptions } = options;\n const safeInit = init?.headers !== undefined ? { headers: init.headers } : undefined;\n const honoMw: MiddlewareHandler = honoJwk(honoOptions, safeInit);\n\n return defineMiddleware<JwtPayloadState<TPayload>>({\n handler: extractJwtPayload<TPayload>(honoMw),\n });\n}\n"],"mappings":";;;;;AAgBA,SAAS,iBAAiB,SAAiB,eAA8B;CACvE,MAAM,SAAS,IAAI,IAAI,OAAO,CAAC,CAAC,SAAS,QAAQ,KAAK,EAAE;CACxD,IAAI,WAAW,SACb;CAEF,IAAI,WAAW,UAAU,eACvB;CAEF,MAAM,IAAI,MAAM,sEAAsE,QAAQ,EAAE;AAClG;;;;;;AAOA,SAAgB,IACd,SACA,MAC6B;CAC7B,MAAM,UAAU,QAAQ;CACxB,IAAI,OAAO,YAAY,UACrB,iBAAiB,SAAS,QAAQ,iBAAiB,KAAK;CAG1D,MAAM,EAAE,eAAe,gBAAgB,GAAG,gBAAgB;CAI1D,OAAO,mBAAA,iBAA4C,EACjD,SAAS,kBAAA,mBAAA,GAAA,SAAA,IAAA,CAH+B,aADzB,MAAM,YAAY,KAAA,IAAY,EAAE,SAAS,KAAK,QAAQ,IAAI,KAAA,CAIpC,CAAM,EAC7C,CAAC;AACH"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_middleware = require("../define/middleware.cjs");
|
|
3
|
-
|
|
3
|
+
const require_wrap_hono = require("./wrap-hono.cjs");
|
|
4
4
|
let hono_jwt = require("hono/jwt");
|
|
5
5
|
//#region src/middleware/jwt.ts
|
|
6
6
|
/**
|
|
@@ -8,13 +8,7 @@ let hono_jwt = require("hono/jwt");
|
|
|
8
8
|
* Successfully decoded payload is placed in `ctx.state.jwtPayload`.
|
|
9
9
|
*/
|
|
10
10
|
function jwt(options) {
|
|
11
|
-
|
|
12
|
-
return require_middleware.defineMiddleware({ handler: (ctx, next) => {
|
|
13
|
-
return (0, _taserjs_router_core.createTaserCompatHandler)(honoMw)(ctx, async () => {
|
|
14
|
-
const payload = ctx.var.jwtPayload;
|
|
15
|
-
return next({ jwtPayload: payload });
|
|
16
|
-
});
|
|
17
|
-
} });
|
|
11
|
+
return require_middleware.defineMiddleware({ handler: require_wrap_hono.extractJwtPayload((0, hono_jwt.jwt)(options)) });
|
|
18
12
|
}
|
|
19
13
|
//#endregion
|
|
20
14
|
exports.jwt = jwt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.cjs","names":[],"sources":["../../../src/middleware/jwt.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"jwt.cjs","names":[],"sources":["../../../src/middleware/jwt.ts"],"sourcesContent":["import type { MiddlewareHandler } from \"hono\";\nimport { jwt as honoJwt } from \"hono/jwt\";\n\nimport { defineMiddleware } from \"../define/middleware.js\";\nimport type { MiddlewareReturnFromParts, MiddlewareUnit } from \"../types/units.js\";\nimport { extractJwtPayload } from \"./wrap-hono.js\";\n\nexport type JwtPayloadState<TPayload> = {\n jwtPayload: TPayload;\n};\n\nexport type JwtMiddlewareUnit<TPayload> = MiddlewareUnit<\n MiddlewareReturnFromParts<unknown, unknown, unknown, JwtPayloadState<TPayload>>\n>;\n\nexport type JwtOptions = Parameters<typeof honoJwt>[0];\n\n/**\n * JWT auth middleware. Invalid or missing tokens return **401** (Hono).\n * Successfully decoded payload is placed in `ctx.state.jwtPayload`.\n */\nexport function jwt<TPayload = Record<string, unknown>>(\n options: JwtOptions,\n): JwtMiddlewareUnit<TPayload> {\n const honoMw: MiddlewareHandler = honoJwt(options);\n return defineMiddleware<JwtPayloadState<TPayload>>({\n handler: extractJwtPayload<TPayload>(honoMw),\n });\n}\n"],"mappings":";;;;;;;;;AAqBA,SAAgB,IACd,SAC6B;CAE7B,OAAO,mBAAA,iBAA4C,EACjD,SAAS,kBAAA,mBAAA,GAAA,SAAA,IAAA,CAF+B,OAEH,CAAM,EAC7C,CAAC;AACH"}
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_wrap_hono = require("./wrap-hono.cjs");
|
|
3
3
|
let hono_secure_headers = require("hono/secure-headers");
|
|
4
4
|
//#region src/middleware/secure-headers.ts
|
|
5
|
-
var
|
|
5
|
+
var wrapped = require_wrap_hono.wrapHonoMiddleware(hono_secure_headers.secureHeaders);
|
|
6
6
|
function secureHeaders(...args) {
|
|
7
|
-
return
|
|
7
|
+
return wrapped(...args);
|
|
8
8
|
}
|
|
9
9
|
//#endregion
|
|
10
10
|
exports.secureHeaders = secureHeaders;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secure-headers.cjs","names":[],"sources":["../../../src/middleware/secure-headers.ts"],"sourcesContent":["import { secureHeaders as honoSecureHeaders } from \"hono/secure-headers\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst
|
|
1
|
+
{"version":3,"file":"secure-headers.cjs","names":[],"sources":["../../../src/middleware/secure-headers.ts"],"sourcesContent":["import { secureHeaders as honoSecureHeaders } from \"hono/secure-headers\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst wrapped = wrapHonoMiddleware(honoSecureHeaders);\n\nexport function secureHeaders(...args: Parameters<typeof honoSecureHeaders>) {\n return wrapped(...args);\n}\n\nexport type SecureHeadersOptions = NonNullable<Parameters<typeof honoSecureHeaders>[0]>;\n"],"mappings":";;;;AAIA,IAAM,UAAU,kBAAA,mBAAmB,oBAAA,aAAiB;AAEpD,SAAgB,cAAc,GAAG,MAA4C;CAC3E,OAAO,QAAQ,GAAG,IAAI;AACxB"}
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_wrap_hono = require("./wrap-hono.cjs");
|
|
3
3
|
let hono_timing = require("hono/timing");
|
|
4
4
|
//#region src/middleware/timing.ts
|
|
5
|
-
var
|
|
5
|
+
var wrapped = require_wrap_hono.wrapHonoMiddleware(hono_timing.timing);
|
|
6
6
|
function timing(...args) {
|
|
7
|
-
return
|
|
7
|
+
return wrapped(...args);
|
|
8
8
|
}
|
|
9
9
|
//#endregion
|
|
10
10
|
exports.timing = timing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timing.cjs","names":[],"sources":["../../../src/middleware/timing.ts"],"sourcesContent":["import { timing as honoTiming } from \"hono/timing\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst
|
|
1
|
+
{"version":3,"file":"timing.cjs","names":[],"sources":["../../../src/middleware/timing.ts"],"sourcesContent":["import { timing as honoTiming } from \"hono/timing\";\n\nimport { wrapHonoMiddleware } from \"./wrap-hono.js\";\n\nconst wrapped = wrapHonoMiddleware(honoTiming);\n\nexport function timing(...args: Parameters<typeof honoTiming>) {\n return wrapped(...args);\n}\n\nexport type TimingOptions = NonNullable<Parameters<typeof honoTiming>[0]>;\n"],"mappings":";;;;AAIA,IAAM,UAAU,kBAAA,mBAAmB,YAAA,MAAU;AAE7C,SAAgB,OAAO,GAAG,MAAqC;CAC7D,OAAO,QAAQ,GAAG,IAAI;AACxB"}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
const require_middleware = require("../define/middleware.cjs");
|
|
2
|
+
let _taserjs_router_core = require("@taserjs/router-core");
|
|
2
3
|
//#region src/middleware/wrap-hono.ts
|
|
3
4
|
function wrapHonoMiddleware(honoFactory) {
|
|
4
5
|
return (...args) => require_middleware.defineMiddleware(honoFactory(...args));
|
|
5
6
|
}
|
|
7
|
+
/** Extracts the jwtPayload from Hono's variable bag and forwards it into Taser's state via next(). */
|
|
8
|
+
function extractJwtPayload(honoMw) {
|
|
9
|
+
const taserHandler = (0, _taserjs_router_core.createTaserCompatHandler)(honoMw);
|
|
10
|
+
return (ctx, next) => taserHandler(ctx, async () => {
|
|
11
|
+
const payload = ctx.var.jwtPayload;
|
|
12
|
+
return next({ jwtPayload: payload });
|
|
13
|
+
});
|
|
14
|
+
}
|
|
6
15
|
//#endregion
|
|
16
|
+
exports.extractJwtPayload = extractJwtPayload;
|
|
7
17
|
exports.wrapHonoMiddleware = wrapHonoMiddleware;
|
|
8
18
|
|
|
9
19
|
//# sourceMappingURL=wrap-hono.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap-hono.cjs","names":[],"sources":["../../../src/middleware/wrap-hono.ts"],"sourcesContent":["import type { MiddlewareHandler } from \"hono\";\n\nimport { defineMiddleware } from \"../define/middleware.js\";\nimport type { MiddlewareReturnFromParts, MiddlewareUnit } from \"../types/units.js\";\n\nexport function wrapHonoMiddleware<F extends (...args: never[]) => MiddlewareHandler>(\n honoFactory: F,\n): (\n ...args: Parameters<F>\n) => MiddlewareUnit<MiddlewareReturnFromParts<unknown, unknown, unknown, {}>> {\n return (...args) => defineMiddleware(honoFactory(...args));\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"wrap-hono.cjs","names":[],"sources":["../../../src/middleware/wrap-hono.ts"],"sourcesContent":["import { createTaserCompatHandler } from \"@taserjs/router-core\";\nimport type { MiddlewareHandler } from \"hono\";\n\nimport { defineMiddleware } from \"../define/middleware.js\";\nimport type { MiddlewareReturnFromParts, MiddlewareUnit } from \"../types/units.js\";\n\nexport function wrapHonoMiddleware<F extends (...args: never[]) => MiddlewareHandler>(\n honoFactory: F,\n): (\n ...args: Parameters<F>\n) => MiddlewareUnit<MiddlewareReturnFromParts<unknown, unknown, unknown, {}>> {\n return (...args) => defineMiddleware(honoFactory(...args));\n}\n\n/** Extracts the jwtPayload from Hono's variable bag and forwards it into Taser's state via next(). */\nexport function extractJwtPayload<TPayload>(\n honoMw: MiddlewareHandler,\n): (ctx: unknown, next: (state: { jwtPayload: TPayload }) => unknown) => unknown {\n const taserHandler = createTaserCompatHandler(honoMw);\n return (ctx, next) =>\n taserHandler(ctx, async () => {\n const payload = (ctx as unknown as { var: { jwtPayload?: unknown } }).var.jwtPayload;\n return next({ jwtPayload: payload as TPayload });\n });\n}\n"],"mappings":";;;AAMA,SAAgB,mBACd,aAG4E;CAC5E,QAAQ,GAAG,SAAS,mBAAA,iBAAiB,YAAY,GAAG,IAAI,CAAC;AAC3D;;AAGA,SAAgB,kBACd,QAC+E;CAC/E,MAAM,gBAAA,GAAA,qBAAA,yBAAA,CAAwC,MAAM;CACpD,QAAQ,KAAK,SACX,aAAa,KAAK,YAAY;EAC5B,MAAM,UAAW,IAAqD,IAAI;EAC1E,OAAO,KAAK,EAAE,YAAY,QAAoB,CAAC;CACjD,CAAC;AACL"}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import { MiddlewareHandler } from 'hono';
|
|
2
2
|
import { MiddlewareReturnFromParts, MiddlewareUnit } from '../types/units.js';
|
|
3
3
|
export declare function wrapHonoMiddleware<F extends (...args: never[]) => MiddlewareHandler>(honoFactory: F): (...args: Parameters<F>) => MiddlewareUnit<MiddlewareReturnFromParts<unknown, unknown, unknown, {}>>;
|
|
4
|
+
/** Extracts the jwtPayload from Hono's variable bag and forwards it into Taser's state via next(). */
|
|
5
|
+
export declare function extractJwtPayload<TPayload>(honoMw: MiddlewareHandler): (ctx: unknown, next: (state: {
|
|
6
|
+
jwtPayload: TPayload;
|
|
7
|
+
}) => unknown) => unknown;
|
package/dist/cjs/reply.cjs
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
Object.defineProperty(exports, "reply", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function() {
|
|
12
|
-
return _taserjs_router_utils_reply.reply;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(exports, "successReply", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function() {
|
|
18
|
-
return _taserjs_router_utils_reply.successReply;
|
|
19
|
-
}
|
|
1
|
+
var _taserjs_router_utils_reply = require("@taserjs/router-utils/reply");
|
|
2
|
+
Object.keys(_taserjs_router_utils_reply).forEach(function(k) {
|
|
3
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _taserjs_router_utils_reply[k];
|
|
7
|
+
}
|
|
8
|
+
});
|
|
20
9
|
});
|
package/dist/cjs/reply.d.cts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export type { BinaryBody, BodyKind, FileReplyInit, RedirectInit, ReplyBodyKind, ReplyInit, ReplyOf, SuccessReplyData, } from '@taserjs/router-utils/reply';
|
|
1
|
+
export * from '@taserjs/router-utils/reply';
|
package/dist/cjs/stream.cjs
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
Object.defineProperty(exports, "buffer", {
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function() {
|
|
12
|
-
return _taserjs_router_utils.buffer;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
Object.defineProperty(exports, "file", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function() {
|
|
18
|
-
return _taserjs_router_utils.file;
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(exports, "pipe", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function() {
|
|
24
|
-
return _taserjs_router_utils.pipe;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(exports, "stream", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function() {
|
|
30
|
-
return _taserjs_router_utils.stream;
|
|
31
|
-
}
|
|
1
|
+
var _taserjs_router_utils_stream = require("@taserjs/router-utils/stream");
|
|
2
|
+
Object.keys(_taserjs_router_utils_stream).forEach(function(k) {
|
|
3
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _taserjs_router_utils_stream[k];
|
|
7
|
+
}
|
|
8
|
+
});
|
|
32
9
|
});
|
package/dist/cjs/stream.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from '@taserjs/router-utils/stream';
|
package/dist/cjs/types/app.d.cts
CHANGED
|
@@ -1,47 +1,29 @@
|
|
|
1
|
+
import { CookieRuntimeConfig, RouteManifestShape } from '@taserjs/router-core';
|
|
1
2
|
import { ResponseValidationFailureHandler } from '@taserjs/router-utils';
|
|
2
|
-
import { TaserApp } from '../
|
|
3
|
+
import { TaserApp } from '../builder/app.js';
|
|
3
4
|
import { ReturnsMap } from './returns.js';
|
|
4
5
|
import { Schema } from './schema.js';
|
|
5
6
|
export type CreateTaserAppOptions = {
|
|
6
|
-
basePath?: string;
|
|
7
7
|
response?: {
|
|
8
8
|
/** Validate handler replies against returns maps. Default true. */
|
|
9
9
|
validate?: boolean;
|
|
10
10
|
onValidationFailure?: ResponseValidationFailureHandler;
|
|
11
11
|
};
|
|
12
12
|
/** Global cookie defaults and signing secret. Per-call `ctx.cookies.set` options override defaults. */
|
|
13
|
-
cookies?:
|
|
14
|
-
secret?: string | BufferSource;
|
|
15
|
-
path?: string;
|
|
16
|
-
httpOnly?: boolean;
|
|
17
|
-
sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
|
|
18
|
-
secure?: boolean;
|
|
19
|
-
domain?: string;
|
|
20
|
-
maxAge?: number;
|
|
21
|
-
expires?: Date;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export type CreateContextArgs = {
|
|
25
|
-
native?: import('./units.js').NativeContext;
|
|
13
|
+
cookies?: CookieRuntimeConfig;
|
|
26
14
|
};
|
|
27
15
|
export type ContextDefinition<TBoot extends Record<string, unknown> = Record<string, never>, TReq extends Record<string, unknown> = Record<string, never>> = {
|
|
28
16
|
boot?: () => TBoot | Promise<TBoot>;
|
|
29
|
-
request?: (
|
|
17
|
+
request?: (req: Request) => TReq | Promise<TReq>;
|
|
30
18
|
};
|
|
31
19
|
export type InferAppContext<T extends ContextDefinition<Record<string, unknown>, Record<string, unknown>>> = T extends ContextDefinition<infer TBoot, infer TReq> ? TBoot & TReq : Record<string, never>;
|
|
32
20
|
export type OnErrorOptions<TResponses extends ReturnsMap = ReturnsMap> = {
|
|
33
21
|
responses?: TResponses;
|
|
34
22
|
handle: (error: unknown, ctx?: unknown) => Response | Promise<Response>;
|
|
35
23
|
};
|
|
36
|
-
export type InferAppManifest<TApp> = TApp extends TaserApp<infer TManifest> ? TManifest :
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* Mount the Taser handler on a framework app.
|
|
40
|
-
* Use universal wildcard patterns (`/*`, `/prefix/*`) for Hono/Fastify.
|
|
41
|
-
* Use framework-native splat patterns for Express (e.g. `/{*splat}`, `/*splat`).
|
|
42
|
-
*/
|
|
43
|
-
mount(pattern: string, frameworkApp: TFrameworkApp): void;
|
|
44
|
-
};
|
|
24
|
+
export type InferAppManifest<TApp> = TApp extends TaserApp<infer TManifest, any> ? TManifest : TApp extends {
|
|
25
|
+
manifest: infer TManifest;
|
|
26
|
+
} ? TManifest : TApp extends RouteManifestShape ? TApp : never;
|
|
45
27
|
export type { RouteManifestShape } from '@taserjs/router-core';
|
|
46
28
|
export type { Schema };
|
|
47
|
-
export type { TaserApp
|
|
29
|
+
export type { TaserApp } from '../builder/app.js';
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Awaitable, TaserCookieJar, TaserHeaders } from '@taserjs/router-core';
|
|
2
2
|
import { RouterRegister } from '../register.js';
|
|
3
|
-
import { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape,
|
|
3
|
+
import { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape, Simplify, UnionToIntersection, UnitRuntimeContext } from './type-utils.js';
|
|
4
4
|
import { ReturnsMap, ValidHandlerReply } from './returns.js';
|
|
5
5
|
import { Schema } from './schema.js';
|
|
6
|
-
import { AppContext, ExtractState, HandlerContext, HandlerUnit, InlineMiddlewareOptions, Method, MiddlewareDefinition, MiddlewareReturnFromParts, MiddlewareUnit,
|
|
6
|
+
import { AppContext, ExtractState, HandlerContext, HandlerUnit, InlineMiddlewareOptions, Method, MiddlewareDefinition, MiddlewareReturnFromParts, MiddlewareUnit, ValidatorParts } from './units.js';
|
|
7
7
|
export type { Awaitable } from '@taserjs/router-core';
|
|
8
8
|
export type { SchemaRequestShape, InferInput, InferOutput, Schema, StandardSchemaV1, } from './schema.js';
|
|
9
9
|
export type { RouterRegister } from '../register.js';
|
|
10
|
-
export type { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape, Simplify, UnwrapPart, } from './type-utils.js';
|
|
11
|
-
export type { EmptyReturns, EnforceHandlerReply, HandlerReply, HasReturns, MergeReturns,
|
|
12
|
-
export type { AppContext, ExtractState, HandlerContext, HandlerUnit, HttpMethod, InlineMiddlewareOptions, IsUnknown, Method, MiddlewareDefinition, MiddlewareNext, MiddlewareReturnFromParts, MiddlewareUnit,
|
|
10
|
+
export type { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape, Simplify, UnitRuntimeContext, UnwrapPart, } from './type-utils.js';
|
|
11
|
+
export type { EmptyReturns, EnforceHandlerReply, HandlerReply, HasReturns, MergeReturns, ReplyFor, ReturnsMap, StatusCode, ValidHandlerReply, } from './returns.js';
|
|
12
|
+
export type { AppContext, ExtractState, HandlerContext, HandlerUnit, HttpMethod, InlineMiddlewareOptions, IsUnknown, Method, MiddlewareDefinition, MiddlewareNext, MiddlewareReturnFromParts, MiddlewareUnit, NextFn, NextResult, StandaloneMiddlewareContext, StateBrand, ValidatorParts, } from './units.js';
|
|
13
13
|
export type RoutePath = RouterRegister extends {
|
|
14
14
|
RoutePath: infer P;
|
|
15
15
|
} ? P : never;
|
|
@@ -29,6 +29,7 @@ type ParseParam<Segment extends string> = Segment extends "*" ? {
|
|
|
29
29
|
} : {};
|
|
30
30
|
type ParseParamsFromSegments<S extends string> = S extends `${infer Segment}/${infer Rest}` ? ParseParam<Segment> & ParseParamsFromSegments<Rest> : ParseParam<S>;
|
|
31
31
|
export type PathParams<Path extends string> = Path extends `/${infer Rest}` ? ParseParamsFromSegments<Rest> : {};
|
|
32
|
+
export type ResolveParams<TPathParams, TSchemaParams> = TSchemaParams extends Record<string, unknown> ? [keyof TSchemaParams] extends [never] ? TPathParams : Simplify<Omit<TPathParams, keyof TSchemaParams> & TSchemaParams> : TPathParams;
|
|
32
33
|
type LayoutParent<Layout extends LayoutId> = LayoutTree[Layout] extends {
|
|
33
34
|
parent: infer Parent extends LayoutId | null;
|
|
34
35
|
} ? Parent : null;
|
|
@@ -56,12 +57,14 @@ type RouteParent<Path extends RoutePath, TMethod extends Method> = RouteEntry<Pa
|
|
|
56
57
|
type RouteLayoutChain<Path extends RoutePath, TMethod extends Method> = RouteEntry<Path, TMethod> extends {
|
|
57
58
|
layoutChain: infer Chain extends readonly LayoutId[];
|
|
58
59
|
} ? Chain : RouteParent<Path, TMethod> extends LayoutId ? readonly [RouteParent<Path, TMethod>] : readonly [];
|
|
59
|
-
type
|
|
60
|
+
export type RouteLayoutMiddlewares<Path extends RoutePath, TMethod extends Method> = ResolveLayoutChainMiddlewares<RouteLayoutChain<Path, TMethod>>;
|
|
61
|
+
export type RouteLayoutField<Path extends RoutePath, TMethod extends Method, Field extends "query" | "params" | "body" | "state"> = MergeMiddlewareField<RouteLayoutMiddlewares<Path, TMethod>, Field>;
|
|
62
|
+
export type RouteLayoutInputField<Path extends RoutePath, TMethod extends Method, Field extends "query" | "params" | "body"> = MergeMiddlewareInputField<RouteLayoutMiddlewares<Path, TMethod>, Field>;
|
|
63
|
+
type RouteResolvedField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body" | "state"> = RouteLayoutField<Path, TMethod, Field> & MergeMiddlewareField<Acc, Field>;
|
|
60
64
|
type RouteChainField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body" | "state"> = RouteResolvedField<Path, TMethod, Acc, Field>;
|
|
61
|
-
type UnitRuntimeContext = Omit<RuntimeContextFields<NativeContext>, "var">;
|
|
62
65
|
export type RouteChainContext<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], TQuery, TParams, TBody, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
63
66
|
query: Simplify<MergePart<TQuery, RouteChainField<Path, TMethod, Acc, "query">>>;
|
|
64
|
-
params: Simplify<PathParams<Path
|
|
67
|
+
params: Simplify<ResolveParams<PathParams<Path>, MergePart<TParams, RouteChainField<Path, TMethod, Acc, "params">>>>;
|
|
65
68
|
body: Simplify<MergePart<TBody, RouteChainField<Path, TMethod, Acc, "body">>>;
|
|
66
69
|
state: Simplify<RouteChainField<Path, TMethod, Acc, "state">>;
|
|
67
70
|
headers: TaserHeaders;
|
|
@@ -77,9 +80,9 @@ export type RouteHandleContext<Path extends RoutePath, TMethod extends Method, A
|
|
|
77
80
|
query: Simplify<MergePart<Validators extends {
|
|
78
81
|
query?: infer Q;
|
|
79
82
|
} ? Q : unknown, RouteResolvedField<Path, TMethod, Acc, "query">>>;
|
|
80
|
-
params: Simplify<PathParams<Path
|
|
83
|
+
params: Simplify<ResolveParams<PathParams<Path>, MergePart<Validators extends {
|
|
81
84
|
params?: infer P;
|
|
82
|
-
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params"
|
|
85
|
+
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params">>>>;
|
|
83
86
|
body: Simplify<MergePart<Validators extends {
|
|
84
87
|
body?: infer B;
|
|
85
88
|
} ? B : unknown, RouteResolvedField<Path, TMethod, Acc, "body">>>;
|
|
@@ -96,15 +99,15 @@ export type RouteHandleContextWithoutBody<Path extends RoutePath, TMethod extend
|
|
|
96
99
|
query: Simplify<MergePart<Validators extends {
|
|
97
100
|
query?: infer Q;
|
|
98
101
|
} ? Q : unknown, RouteResolvedField<Path, TMethod, Acc, "query">>>;
|
|
99
|
-
params: Simplify<PathParams<Path
|
|
102
|
+
params: Simplify<ResolveParams<PathParams<Path>, MergePart<Validators extends {
|
|
100
103
|
params?: infer P;
|
|
101
|
-
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params"
|
|
104
|
+
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params">>>>;
|
|
102
105
|
body: never;
|
|
103
106
|
state: Simplify<RouteResolvedField<Path, TMethod, Acc, "state">>;
|
|
104
107
|
headers: TaserHeaders;
|
|
105
108
|
cookies: TaserCookieJar;
|
|
106
109
|
}>;
|
|
107
|
-
type RouteResolvedInputField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body"> =
|
|
110
|
+
type RouteResolvedInputField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body"> = RouteLayoutInputField<Path, TMethod, Field> & MergeMiddlewareInputField<Acc, Field>;
|
|
108
111
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
109
112
|
type IsEmptyObject<T> = [keyof T] extends [never] ? true : false;
|
|
110
113
|
export type IsLayoutAllowed<TRequiredLayouts, TChain extends readonly LayoutId[]> = [
|
|
@@ -119,11 +122,11 @@ type RouteQueryInput<Path extends RoutePath, TMethod extends Method, Acc extends
|
|
|
119
122
|
} ? QI : unknown, Validators extends {
|
|
120
123
|
query?: infer Q;
|
|
121
124
|
} ? Q : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "query">>>;
|
|
122
|
-
type RouteParamsInput<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts> = Simplify<PathParams<Path
|
|
125
|
+
type RouteParamsInput<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts> = Simplify<ResolveParams<PathParams<Path>, MergePart<RequestShape<Validators extends {
|
|
123
126
|
paramsIn?: infer PI;
|
|
124
127
|
} ? PI : unknown, Validators extends {
|
|
125
128
|
params?: infer P;
|
|
126
|
-
} ? P : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "params"
|
|
129
|
+
} ? P : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "params">>>>;
|
|
127
130
|
type RouteBodyInput<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts> = Simplify<MergePart<RequestShape<Validators extends {
|
|
128
131
|
bodyIn?: infer BI;
|
|
129
132
|
} ? BI : unknown, Validators extends {
|
|
@@ -131,14 +134,15 @@ type RouteBodyInput<Path extends RoutePath, TMethod extends Method, Acc extends
|
|
|
131
134
|
} ? B : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "body">>>;
|
|
132
135
|
export type RouteHandleInputWithoutBody<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts = {}> = Simplify<InputFacet<RouteQueryInput<Path, TMethod, Acc, Validators>, "query"> & InputFacet<RouteParamsInput<Path, TMethod, Acc, Validators>, "params">>;
|
|
133
136
|
export type RouteHandleInput<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts = {}> = Simplify<RouteHandleInputWithoutBody<Path, TMethod, Acc, Validators> & InputFacet<RouteBodyInput<Path, TMethod, Acc, Validators>, "body">>;
|
|
134
|
-
export type
|
|
137
|
+
export type InferRouteInputFromPath<Path extends RoutePath, TMethod extends Method> = RouteEntry<Path, TMethod> extends {
|
|
135
138
|
route: infer Route;
|
|
136
139
|
} ? Route extends {
|
|
137
140
|
$Infer: {
|
|
138
141
|
Input: infer I;
|
|
139
142
|
};
|
|
140
143
|
} ? I : never : never;
|
|
141
|
-
type
|
|
144
|
+
export type MiddlewareLayoutField<Layout extends LayoutId, Field extends "query" | "params" | "body" | "state"> = MergeMiddlewareField<ResolveLayoutMiddlewares<LayoutParent<Layout>>, Field>;
|
|
145
|
+
type MiddlewareChainField<Layout extends LayoutId, Acc extends readonly unknown[], Field extends "query" | "params" | "body" | "state"> = MiddlewareLayoutField<Layout, Field> & MergeMiddlewareField<Acc, Field>;
|
|
142
146
|
export type MiddlewareChainContext<Layout extends LayoutId, Acc extends readonly unknown[], TQuery, TParams, TBody, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
143
147
|
query: Simplify<MergePart<TQuery, MiddlewareChainField<Layout, Acc, "query">>>;
|
|
144
148
|
params: Simplify<MergePart<TParams, MiddlewareChainField<Layout, Acc, "params">>>;
|
|
@@ -177,10 +181,11 @@ export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc exte
|
|
|
177
181
|
readonly middlewares: readonly MiddlewareDefinition[];
|
|
178
182
|
readonly handlerMiddlewares: readonly MiddlewareDefinition[];
|
|
179
183
|
readonly returns?: TReturns;
|
|
184
|
+
readonly bodyMode?: "json" | "form" | "urlencoded";
|
|
180
185
|
handler: (ctx: unknown) => Awaitable<Response>;
|
|
181
186
|
readonly $Infer: {
|
|
182
187
|
Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleContextWithoutBody<Path, TMethod, Acc, {}> : RouteHandleContext<Path, TMethod, Acc, {}>;
|
|
183
|
-
|
|
188
|
+
Input: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleInputWithoutBody<Path, TMethod, Acc, {}> : RouteHandleInput<Path, TMethod, Acc, {}>;
|
|
184
189
|
Output: TOutput;
|
|
185
190
|
};
|
|
186
191
|
query?: Schema<unknown>;
|
|
@@ -197,12 +202,22 @@ type RouteHandleResult<Path extends RoutePath, TMethod extends Method, Acc exten
|
|
|
197
202
|
Output: TOutput;
|
|
198
203
|
};
|
|
199
204
|
};
|
|
200
|
-
export type
|
|
205
|
+
export type RouteBuilderBase<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[] = readonly [], Validators extends ValidatorParts = {}, TReturns extends ReturnsMap = {}, TAppContext extends Record<string, unknown> = AppContext> = {
|
|
201
206
|
readonly path: Path;
|
|
202
207
|
readonly method: TMethod;
|
|
203
208
|
readonly $Infer: {
|
|
204
209
|
Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleContextWithoutBody<Path, TMethod, Acc, Validators, TAppContext> : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>;
|
|
210
|
+
Input: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleInputWithoutBody<Path, TMethod, Acc, Validators> : RouteHandleInput<Path, TMethod, Acc, Validators>;
|
|
211
|
+
Output: TReturns;
|
|
205
212
|
};
|
|
213
|
+
query<TQuery, TQueryIn = unknown>(schema: Schema<TQuery, TQueryIn>): RouteBuilder<Path, TMethod, Acc, Omit<Validators, "query" | "queryIn"> & {
|
|
214
|
+
query: TQuery;
|
|
215
|
+
queryIn: TQueryIn;
|
|
216
|
+
}, TReturns, TAppContext>;
|
|
217
|
+
params<TParams, TParamsIn = unknown>(schema: Schema<TParams, TParamsIn>): RouteBuilder<Path, TMethod, Acc, Omit<Validators, "params" | "paramsIn"> & {
|
|
218
|
+
params: TParams;
|
|
219
|
+
paramsIn: TParamsIn;
|
|
220
|
+
}, TReturns, TAppContext>;
|
|
206
221
|
returns<const M extends ReturnsMap>(map: M): RouteBuilder<Path, TMethod, Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>;
|
|
207
222
|
use<TAcc, UReturns extends ReturnsMap = {}, TRequiredLayouts = unknown, TRequiredState = unknown>(unit: MiddlewareUnit<TAcc, UReturns, TRequiredLayouts, TRequiredState>, ..._assert: [
|
|
208
223
|
IsLayoutAllowed<TRequiredLayouts, RouteLayoutChain<Path, TMethod>>,
|
|
@@ -228,6 +243,16 @@ export type RouteBuilder<Path extends RoutePath, TMethod extends Method, Acc ext
|
|
|
228
243
|
]): RouteHandleResult<Path, TMethod, Acc, Validators, TReturns, R, TAppContext>;
|
|
229
244
|
handler<HandlerAcc extends readonly unknown[] = readonly [], HandlerValidators extends ValidatorParts = ValidatorParts, HReturns extends ReturnsMap = {}, HOutput = Response>(unit: HandlerUnit<HandlerAcc, HandlerValidators, HReturns, HOutput>): RouteHandleResult<Path, TMethod, readonly [...Acc, ...HandlerAcc], Validators, Omit<TReturns, keyof HReturns> & HReturns, HOutput, TAppContext>;
|
|
230
245
|
};
|
|
246
|
+
export type RouteBuilder<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[] = readonly [], Validators extends ValidatorParts = {}, TReturns extends ReturnsMap = {}, TAppContext extends Record<string, unknown> = AppContext> = RouteBuilderBase<Path, TMethod, Acc, Validators, TReturns, TAppContext> & (TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? {} : {
|
|
247
|
+
body<TBody, TBodyIn = unknown>(schema: Schema<TBody, TBodyIn>): RouteBuilder<Path, TMethod, Acc, Omit<Validators, "body" | "bodyIn"> & {
|
|
248
|
+
body: TBody;
|
|
249
|
+
bodyIn: TBodyIn;
|
|
250
|
+
}, TReturns, TAppContext>;
|
|
251
|
+
body<Mode extends "json" | "form" | "urlencoded", TBody, TBodyIn = unknown>(mode: Mode, schema: Schema<TBody, TBodyIn>): RouteBuilder<Path, TMethod, Acc, Omit<Validators, "body" | "bodyIn"> & {
|
|
252
|
+
body: TBody;
|
|
253
|
+
bodyIn: TBodyIn;
|
|
254
|
+
}, TReturns, TAppContext>;
|
|
255
|
+
});
|
|
231
256
|
export type HandlerBuilder<Acc extends readonly unknown[] = readonly [], Validators extends ValidatorParts = {}, TReturns extends ReturnsMap = {}, TAppContext extends Record<string, unknown> = AppContext> = {
|
|
232
257
|
returns<const M extends ReturnsMap>(map: M): HandlerBuilder<Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>;
|
|
233
258
|
use<TAcc, UReturns extends ReturnsMap = {}, TRequiredLayouts = unknown, TRequiredState = unknown>(unit: MiddlewareUnit<TAcc, UReturns, TRequiredLayouts, TRequiredState>, ..._assert: [IsStateSatisfied<MergeMiddlewareField<Acc, "state">, TRequiredState>] extends [
|
|
@@ -254,3 +279,19 @@ export type HandlerBuilder<Acc extends readonly unknown[] = readonly [], Validat
|
|
|
254
279
|
}
|
|
255
280
|
]): HandlerUnit<Acc, Validators, TReturns, R>;
|
|
256
281
|
};
|
|
282
|
+
export type RouteDefinition<Path extends RoutePath = RoutePath, TMethod extends Method = Method, Acc extends readonly unknown[] = readonly unknown[], Validators extends ValidatorParts = ValidatorParts, TReturns extends ReturnsMap = ReturnsMap, TOutput = Response, TAppContext extends Record<string, unknown> = AppContext> = RouteHandleResult<Path, TMethod, Acc, Validators, TReturns, TOutput, TAppContext>;
|
|
283
|
+
export type InferRouteContext<R> = R extends {
|
|
284
|
+
$Infer: {
|
|
285
|
+
Context: infer C;
|
|
286
|
+
};
|
|
287
|
+
} ? C : never;
|
|
288
|
+
export type InferRouteInput<R> = R extends {
|
|
289
|
+
$Infer: {
|
|
290
|
+
Input: infer I;
|
|
291
|
+
};
|
|
292
|
+
} ? I : never;
|
|
293
|
+
export type InferRouteOutput<R> = R extends {
|
|
294
|
+
$Infer: {
|
|
295
|
+
Output: infer O;
|
|
296
|
+
};
|
|
297
|
+
} ? O : never;
|