@taserjs/router 0.1.4 → 0.1.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/factories.cjs.map +1 -1
- package/dist/cjs/builder/factories.d.cts +9 -9
- package/dist/cjs/builder/middleware-unit.cjs +21 -12
- package/dist/cjs/builder/middleware-unit.cjs.map +1 -1
- package/dist/cjs/builder/middleware-unit.d.cts +1 -18
- package/dist/cjs/builder/middleware.cjs +1 -0
- package/dist/cjs/builder/middleware.cjs.map +1 -1
- package/dist/cjs/builder/route.cjs +1 -0
- package/dist/cjs/builder/route.cjs.map +1 -1
- package/dist/cjs/builder/router.cjs +1 -16
- package/dist/cjs/builder/router.cjs.map +1 -1
- package/dist/cjs/builder/router.d.cts +6 -17
- package/dist/cjs/builder/standalone.cjs +43 -0
- package/dist/cjs/builder/standalone.cjs.map +1 -0
- package/dist/cjs/builder/standalone.d.cts +28 -0
- package/dist/cjs/define/middleware.cjs +2 -3
- package/dist/cjs/define/middleware.cjs.map +1 -1
- package/dist/cjs/define/middleware.d.cts +15 -16
- package/dist/cjs/index.cjs +13 -2
- package/dist/cjs/index.d.cts +5 -3
- package/dist/cjs/middleware/body-limit.cjs +1 -1
- package/dist/cjs/middleware/body-limit.cjs.map +1 -1
- package/dist/cjs/middleware/body-limit.d.cts +1 -1
- package/dist/cjs/middleware/compress.cjs +1 -1
- package/dist/cjs/middleware/compress.cjs.map +1 -1
- package/dist/cjs/middleware/compress.d.cts +1 -1
- package/dist/cjs/middleware/cors.cjs +1 -1
- package/dist/cjs/middleware/cors.cjs.map +1 -1
- package/dist/cjs/middleware/cors.d.cts +1 -1
- package/dist/cjs/middleware/csrf.cjs +1 -1
- package/dist/cjs/middleware/csrf.cjs.map +1 -1
- package/dist/cjs/middleware/csrf.d.cts +1 -1
- package/dist/cjs/middleware/etag.cjs +1 -1
- package/dist/cjs/middleware/etag.cjs.map +1 -1
- package/dist/cjs/middleware/etag.d.cts +1 -1
- package/dist/cjs/middleware/hono-mw.cjs +1 -1
- package/dist/cjs/middleware/hono-mw.cjs.map +1 -1
- package/dist/cjs/middleware/hono-mw.d.cts +1 -1
- package/dist/cjs/middleware/jwk.cjs +1 -1
- package/dist/cjs/middleware/jwk.cjs.map +1 -1
- package/dist/cjs/middleware/jwt.cjs +1 -1
- package/dist/cjs/middleware/jwt.cjs.map +1 -1
- package/dist/cjs/middleware/secure-headers.cjs +1 -1
- package/dist/cjs/middleware/secure-headers.cjs.map +1 -1
- package/dist/cjs/middleware/secure-headers.d.cts +1 -1
- package/dist/cjs/middleware/timing.cjs +1 -1
- package/dist/cjs/middleware/timing.cjs.map +1 -1
- package/dist/cjs/middleware/timing.d.cts +1 -1
- package/dist/cjs/types/index.d.cts +18 -13
- package/dist/cjs/types/type-utils.d.cts +2 -2
- package/dist/cjs/types/units.d.cts +17 -19
- package/dist/esm/builder/factories.d.ts +9 -9
- package/dist/esm/builder/factories.js.map +1 -1
- package/dist/esm/builder/middleware-unit.d.ts +1 -18
- package/dist/esm/builder/middleware-unit.js +21 -12
- package/dist/esm/builder/middleware-unit.js.map +1 -1
- package/dist/esm/builder/middleware.js +1 -0
- package/dist/esm/builder/middleware.js.map +1 -1
- package/dist/esm/builder/route.js +1 -0
- package/dist/esm/builder/route.js.map +1 -1
- package/dist/esm/builder/router.d.ts +6 -17
- package/dist/esm/builder/router.js +1 -16
- package/dist/esm/builder/router.js.map +1 -1
- package/dist/esm/builder/standalone.d.ts +28 -0
- package/dist/esm/builder/standalone.js +32 -0
- package/dist/esm/builder/standalone.js.map +1 -0
- package/dist/esm/define/middleware.d.ts +15 -16
- package/dist/esm/define/middleware.js +2 -3
- package/dist/esm/define/middleware.js.map +1 -1
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/middleware/body-limit.d.ts +1 -1
- package/dist/esm/middleware/body-limit.js +2 -2
- package/dist/esm/middleware/body-limit.js.map +1 -1
- package/dist/esm/middleware/compress.d.ts +1 -1
- package/dist/esm/middleware/compress.js +2 -2
- package/dist/esm/middleware/compress.js.map +1 -1
- package/dist/esm/middleware/cors.d.ts +1 -1
- package/dist/esm/middleware/cors.js +2 -2
- package/dist/esm/middleware/cors.js.map +1 -1
- package/dist/esm/middleware/csrf.d.ts +1 -1
- package/dist/esm/middleware/csrf.js +2 -2
- package/dist/esm/middleware/csrf.js.map +1 -1
- package/dist/esm/middleware/etag.d.ts +1 -1
- package/dist/esm/middleware/etag.js +2 -2
- package/dist/esm/middleware/etag.js.map +1 -1
- package/dist/esm/middleware/hono-mw.d.ts +1 -1
- package/dist/esm/middleware/hono-mw.js +1 -1
- package/dist/esm/middleware/hono-mw.js.map +1 -1
- package/dist/esm/middleware/jwk.js +2 -2
- package/dist/esm/middleware/jwk.js.map +1 -1
- package/dist/esm/middleware/jwt.js +2 -2
- package/dist/esm/middleware/jwt.js.map +1 -1
- package/dist/esm/middleware/secure-headers.d.ts +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.d.ts +1 -1
- package/dist/esm/middleware/timing.js +2 -2
- package/dist/esm/middleware/timing.js.map +1 -1
- package/dist/esm/types/index.d.ts +18 -13
- package/dist/esm/types/type-utils.d.ts +2 -2
- package/dist/esm/types/units.d.ts +17 -19
- package/package.json +3 -3
- package/src/builder/factories.ts +2 -2
- package/src/builder/middleware-unit.ts +22 -11
- package/src/builder/middleware.ts +2 -0
- package/src/builder/route.ts +2 -0
- package/src/builder/router.ts +7 -60
- package/src/builder/standalone.ts +70 -0
- package/src/define/middleware.ts +37 -18
- package/src/index.ts +26 -2
- 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/hono-mw.ts +1 -1
- package/src/middleware/jwk.ts +2 -2
- package/src/middleware/jwt.ts +2 -2
- package/src/middleware/secure-headers.ts +2 -2
- package/src/middleware/timing.ts +2 -2
- package/src/types/index.ts +39 -24
- package/src/types/type-utils.ts +8 -4
- package/src/types/units.ts +46 -22
- package/dist/cjs/register.d.cts +0 -2
- package/dist/esm/register.d.ts +0 -2
- package/src/register.ts +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { compress as honoCompress } from 'hono/compress';
|
|
2
|
-
export declare function compress(...args: Parameters<typeof honoCompress>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Response
|
|
2
|
+
export declare function compress(...args: Parameters<typeof honoCompress>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Promise<Response>, unknown, unknown, unknown, {}, null, {}>;
|
|
3
3
|
export type CompressOptions = NonNullable<Parameters<typeof honoCompress>[0]>;
|
|
@@ -4,7 +4,7 @@ const require_hono_mw = require("./hono-mw.cjs");
|
|
|
4
4
|
let hono_cors = require("hono/cors");
|
|
5
5
|
//#region src/middleware/cors.ts
|
|
6
6
|
function cors(...args) {
|
|
7
|
-
return require_middleware.
|
|
7
|
+
return require_middleware.middleware(require_hono_mw.honoMw((0, hono_cors.cors)(...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 {
|
|
1
|
+
{"version":3,"file":"cors.cjs","names":[],"sources":["../../../src/middleware/cors.ts"],"sourcesContent":["import { cors as honoCors } from \"hono/cors\";\n\nimport { middleware } from \"../define/middleware.js\";\nimport { honoMw } from \"./hono-mw.js\";\n\nexport function cors(...args: Parameters<typeof honoCors>) {\n return middleware(honoMw(honoCors(...args)));\n}\n\nexport type CorsOptions = NonNullable<Parameters<typeof honoCors>[0]>;\n"],"mappings":";;;;;AAKA,SAAgB,KAAK,GAAG,MAAmC;CACzD,OAAO,mBAAA,WAAW,gBAAA,QAAA,GAAA,UAAA,KAAA,CAAgB,GAAG,IAAI,CAAC,CAAC;AAC7C"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { cors as honoCors } from 'hono/cors';
|
|
2
|
-
export declare function cors(...args: Parameters<typeof honoCors>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Response
|
|
2
|
+
export declare function cors(...args: Parameters<typeof honoCors>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Promise<Response>, unknown, unknown, unknown, {}, null, {}>;
|
|
3
3
|
export type CorsOptions = NonNullable<Parameters<typeof honoCors>[0]>;
|
|
@@ -4,7 +4,7 @@ const require_hono_mw = require("./hono-mw.cjs");
|
|
|
4
4
|
let hono_csrf = require("hono/csrf");
|
|
5
5
|
//#region src/middleware/csrf.ts
|
|
6
6
|
function csrf(...args) {
|
|
7
|
-
return require_middleware.
|
|
7
|
+
return require_middleware.middleware(require_hono_mw.honoMw((0, hono_csrf.csrf)(...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 {
|
|
1
|
+
{"version":3,"file":"csrf.cjs","names":[],"sources":["../../../src/middleware/csrf.ts"],"sourcesContent":["import { csrf as honoCsrf } from \"hono/csrf\";\n\nimport { middleware } from \"../define/middleware.js\";\nimport { honoMw } from \"./hono-mw.js\";\n\nexport function csrf(...args: Parameters<typeof honoCsrf>) {\n return middleware(honoMw(honoCsrf(...args)));\n}\n\nexport type CsrfOptions = NonNullable<Parameters<typeof honoCsrf>[0]>;\n"],"mappings":";;;;;AAKA,SAAgB,KAAK,GAAG,MAAmC;CACzD,OAAO,mBAAA,WAAW,gBAAA,QAAA,GAAA,UAAA,KAAA,CAAgB,GAAG,IAAI,CAAC,CAAC;AAC7C"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { csrf as honoCsrf } from 'hono/csrf';
|
|
2
|
-
export declare function csrf(...args: Parameters<typeof honoCsrf>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Response
|
|
2
|
+
export declare function csrf(...args: Parameters<typeof honoCsrf>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Promise<Response>, unknown, unknown, unknown, {}, null, {}>;
|
|
3
3
|
export type CsrfOptions = NonNullable<Parameters<typeof honoCsrf>[0]>;
|
|
@@ -4,7 +4,7 @@ const require_hono_mw = require("./hono-mw.cjs");
|
|
|
4
4
|
let hono_etag = require("hono/etag");
|
|
5
5
|
//#region src/middleware/etag.ts
|
|
6
6
|
function etag(...args) {
|
|
7
|
-
return require_middleware.
|
|
7
|
+
return require_middleware.middleware(require_hono_mw.honoMw((0, hono_etag.etag)(...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 {
|
|
1
|
+
{"version":3,"file":"etag.cjs","names":[],"sources":["../../../src/middleware/etag.ts"],"sourcesContent":["import { etag as honoEtag } from \"hono/etag\";\n\nimport { middleware } from \"../define/middleware.js\";\nimport { honoMw } from \"./hono-mw.js\";\n\nexport function etag(...args: Parameters<typeof honoEtag>) {\n return middleware(honoMw(honoEtag(...args)));\n}\n\nexport type EtagOptions = NonNullable<Parameters<typeof honoEtag>[0]>;\n"],"mappings":";;;;;AAKA,SAAgB,KAAK,GAAG,MAAmC;CACzD,OAAO,mBAAA,WAAW,gBAAA,QAAA,GAAA,UAAA,KAAA,CAAgB,GAAG,IAAI,CAAC,CAAC;AAC7C"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { etag as honoEtag } from 'hono/etag';
|
|
2
|
-
export declare function etag(...args: Parameters<typeof honoEtag>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Response
|
|
2
|
+
export declare function etag(...args: Parameters<typeof honoEtag>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Promise<Response>, unknown, unknown, unknown, {}, null, {}>;
|
|
3
3
|
export type EtagOptions = NonNullable<Parameters<typeof honoEtag>[0]>;
|
|
@@ -11,7 +11,7 @@ let _taserjs_router_core = require("@taserjs/router-core");
|
|
|
11
11
|
*
|
|
12
12
|
* const app = t.get("/hello").use(honoMw(cors()));
|
|
13
13
|
* // or
|
|
14
|
-
* const customCors =
|
|
14
|
+
* const customCors = middleware(honoMw(cors()));
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
function honoMw(middleware) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono-mw.cjs","names":[],"sources":["../../../src/middleware/hono-mw.ts"],"sourcesContent":["import { createTaserCompatHandler } from \"@taserjs/router-core\";\nimport type { MiddlewareHandler } from \"hono\";\n\n/**\n * Adapts a standard Web / Hono-compatible middleware function `(c, next) => ...`\n * into a Taser-compatible middleware handler function `(ctx, next) => Promise<Response>`.\n *\n * @example\n * ```ts\n * import { honoMw } from \"@taserjs/router\";\n * import { cors } from \"hono/cors\";\n *\n * const app = t.get(\"/hello\").use(honoMw(cors()));\n * // or\n * const customCors =
|
|
1
|
+
{"version":3,"file":"hono-mw.cjs","names":[],"sources":["../../../src/middleware/hono-mw.ts"],"sourcesContent":["import { createTaserCompatHandler } from \"@taserjs/router-core\";\nimport type { MiddlewareHandler } from \"hono\";\n\n/**\n * Adapts a standard Web / Hono-compatible middleware function `(c, next) => ...`\n * into a Taser-compatible middleware handler function `(ctx, next) => Promise<Response>`.\n *\n * @example\n * ```ts\n * import { honoMw } from \"@taserjs/router\";\n * import { cors } from \"hono/cors\";\n *\n * const app = t.get(\"/hello\").use(honoMw(cors()));\n * // or\n * const customCors = middleware(honoMw(cors()));\n * ```\n */\nexport function honoMw(\n middleware: MiddlewareHandler,\n): (ctx: unknown, next: any) => Promise<Response> {\n return createTaserCompatHandler(middleware) as (ctx: unknown, next: any) => Promise<Response>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,SAAgB,OACd,YACgD;CAChD,QAAA,GAAA,qBAAA,yBAAA,CAAgC,UAAU;AAC5C"}
|
|
@@ -10,7 +10,7 @@ import { MiddlewareHandler } from 'hono';
|
|
|
10
10
|
*
|
|
11
11
|
* const app = t.get("/hello").use(honoMw(cors()));
|
|
12
12
|
* // or
|
|
13
|
-
* const customCors =
|
|
13
|
+
* const customCors = middleware(honoMw(cors()));
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export declare function honoMw(middleware: MiddlewareHandler): (ctx: unknown, next: any) => Promise<Response>;
|
|
@@ -19,7 +19,7 @@ function jwk(options, init) {
|
|
|
19
19
|
if (typeof jwksUri === "string") assertJwksScheme(jwksUri, options.allowInsecure ?? false);
|
|
20
20
|
const { allowInsecure: _allowInsecure, ...honoOptions } = options;
|
|
21
21
|
const mw = require_hono_mw.honoMw((0, hono_jwk.jwk)(honoOptions, init?.headers !== void 0 ? { headers: init.headers } : void 0));
|
|
22
|
-
return require_middleware.
|
|
22
|
+
return require_middleware.middleware((ctx, next) => mw(ctx, async () => {
|
|
23
23
|
const payload = ctx.var.jwtPayload;
|
|
24
24
|
return next({ jwtPayload: payload });
|
|
25
25
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwk.cjs","names":[],"sources":["../../../src/middleware/jwk.ts"],"sourcesContent":["import { jwk as honoJwk } from \"hono/jwk\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"jwk.cjs","names":[],"sources":["../../../src/middleware/jwk.ts"],"sourcesContent":["import { jwk as honoJwk } from \"hono/jwk\";\n\nimport { middleware } from \"../define/middleware.js\";\nimport { honoMw } from \"./hono-mw.js\";\nimport type { JwtMiddlewareUnit, JwtPayloadState } from \"./jwt.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 mw = honoMw(honoJwk(honoOptions, safeInit));\n\n return middleware<JwtPayloadState<TPayload>>((ctx, next) =>\n mw(ctx, async () => {\n const payload = (ctx as unknown as { var: { jwtPayload?: unknown } }).var.jwtPayload;\n return next({ jwtPayload: payload as TPayload });\n }),\n );\n}\n"],"mappings":";;;;;AAeA,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;CAE1D,MAAM,KAAK,gBAAA,QAAA,GAAA,SAAA,IAAA,CAAe,aADT,MAAM,YAAY,KAAA,IAAY,EAAE,SAAS,KAAK,QAAQ,IAAI,KAAA,CAC5B,CAAC;CAEhD,OAAO,mBAAA,YAAuC,KAAK,SACjD,GAAG,KAAK,YAAY;EAClB,MAAM,UAAW,IAAqD,IAAI;EAC1E,OAAO,KAAK,EAAE,YAAY,QAAoB,CAAC;CACjD,CAAC,CACH;AACF"}
|
|
@@ -9,7 +9,7 @@ let hono_jwt = require("hono/jwt");
|
|
|
9
9
|
*/
|
|
10
10
|
function jwt(options) {
|
|
11
11
|
const mw = require_hono_mw.honoMw((0, hono_jwt.jwt)(options));
|
|
12
|
-
return require_middleware.
|
|
12
|
+
return require_middleware.middleware((ctx, next) => mw(ctx, async () => {
|
|
13
13
|
const payload = ctx.var.jwtPayload;
|
|
14
14
|
return next({ jwtPayload: payload });
|
|
15
15
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.cjs","names":[],"sources":["../../../src/middleware/jwt.ts"],"sourcesContent":["import { jwt as honoJwt } from \"hono/jwt\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"jwt.cjs","names":[],"sources":["../../../src/middleware/jwt.ts"],"sourcesContent":["import { jwt as honoJwt } from \"hono/jwt\";\n\nimport { middleware } from \"../define/middleware.js\";\nimport type { MiddlewareReturnFromParts, MiddlewareUnit } from \"../types/units.js\";\nimport { honoMw } from \"./hono-mw.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 mw = honoMw(honoJwt(options));\n return middleware<JwtPayloadState<TPayload>>((ctx, next) =>\n mw(ctx, async () => {\n const payload = (ctx as unknown as { var: { jwtPayload?: unknown } }).var.jwtPayload;\n return next({ jwtPayload: payload as TPayload });\n }),\n );\n}\n"],"mappings":";;;;;;;;;AAoBA,SAAgB,IACd,SAC6B;CAC7B,MAAM,KAAK,gBAAA,QAAA,GAAA,SAAA,IAAA,CAAe,OAAO,CAAC;CAClC,OAAO,mBAAA,YAAuC,KAAK,SACjD,GAAG,KAAK,YAAY;EAClB,MAAM,UAAW,IAAqD,IAAI;EAC1E,OAAO,KAAK,EAAE,YAAY,QAAoB,CAAC;CACjD,CAAC,CACH;AACF"}
|
|
@@ -4,7 +4,7 @@ const require_hono_mw = require("./hono-mw.cjs");
|
|
|
4
4
|
let hono_secure_headers = require("hono/secure-headers");
|
|
5
5
|
//#region src/middleware/secure-headers.ts
|
|
6
6
|
function secureHeaders(...args) {
|
|
7
|
-
return require_middleware.
|
|
7
|
+
return require_middleware.middleware(require_hono_mw.honoMw((0, hono_secure_headers.secureHeaders)(...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 {
|
|
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 { middleware } from \"../define/middleware.js\";\nimport { honoMw } from \"./hono-mw.js\";\n\nexport function secureHeaders(...args: Parameters<typeof honoSecureHeaders>) {\n return middleware(honoMw(honoSecureHeaders(...args)));\n}\n\nexport type SecureHeadersOptions = NonNullable<Parameters<typeof honoSecureHeaders>[0]>;\n"],"mappings":";;;;;AAKA,SAAgB,cAAc,GAAG,MAA4C;CAC3E,OAAO,mBAAA,WAAW,gBAAA,QAAA,GAAA,oBAAA,cAAA,CAAyB,GAAG,IAAI,CAAC,CAAC;AACtD"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { secureHeaders as honoSecureHeaders } from 'hono/secure-headers';
|
|
2
|
-
export declare function secureHeaders(...args: Parameters<typeof honoSecureHeaders>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Response
|
|
2
|
+
export declare function secureHeaders(...args: Parameters<typeof honoSecureHeaders>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Promise<Response>, unknown, unknown, unknown, {}, null, {}>;
|
|
3
3
|
export type SecureHeadersOptions = NonNullable<Parameters<typeof honoSecureHeaders>[0]>;
|
|
@@ -4,7 +4,7 @@ const require_hono_mw = require("./hono-mw.cjs");
|
|
|
4
4
|
let hono_timing = require("hono/timing");
|
|
5
5
|
//#region src/middleware/timing.ts
|
|
6
6
|
function timing(...args) {
|
|
7
|
-
return require_middleware.
|
|
7
|
+
return require_middleware.middleware(require_hono_mw.honoMw((0, hono_timing.timing)(...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 {
|
|
1
|
+
{"version":3,"file":"timing.cjs","names":[],"sources":["../../../src/middleware/timing.ts"],"sourcesContent":["import { timing as honoTiming } from \"hono/timing\";\n\nimport { middleware } from \"../define/middleware.js\";\nimport { honoMw } from \"./hono-mw.js\";\n\nexport function timing(...args: Parameters<typeof honoTiming>) {\n return middleware(honoMw(honoTiming(...args)));\n}\n\nexport type TimingOptions = NonNullable<Parameters<typeof honoTiming>[0]>;\n"],"mappings":";;;;;AAKA,SAAgB,OAAO,GAAG,MAAqC;CAC7D,OAAO,mBAAA,WAAW,gBAAA,QAAA,GAAA,YAAA,OAAA,CAAkB,GAAG,IAAI,CAAC,CAAC;AAC/C"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { timing as honoTiming } from 'hono/timing';
|
|
2
|
-
export declare function timing(...args: Parameters<typeof honoTiming>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Response
|
|
2
|
+
export declare function timing(...args: Parameters<typeof honoTiming>): import('../types/units.js').DefineMiddlewareResult<unknown, unknown, unknown, {}, Promise<Response>, unknown, unknown, unknown, {}, null, {}>;
|
|
3
3
|
export type TimingOptions = NonNullable<Parameters<typeof honoTiming>[0]>;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Awaitable, TaserCookieJar, TaserHeaders } from '@taserjs/router-core';
|
|
2
|
-
import { RouterRegister } from '../
|
|
2
|
+
import { RouterRegister } from '../index.js';
|
|
3
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 {
|
|
6
|
+
import { EmptyAppContext, ExtractState, Method, MiddlewareDefinition, MiddlewareReturnFromParts, MiddlewareUnit, NextFn, 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
|
-
export type { RouterRegister } from '../register.js';
|
|
10
9
|
export type { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape, Simplify, UnitRuntimeContext, UnwrapPart, } from './type-utils.js';
|
|
11
10
|
export type { EmptyReturns, EnforceHandlerReply, HandlerReply, HasReturns, MergeReturns, ReplyFor, ReturnsMap, StatusCode, ValidHandlerReply, } from './returns.js';
|
|
12
|
-
export type {
|
|
11
|
+
export type { EmptyAppContext, ExtractState, HttpMethod, IsUnknown, Method, MiddlewareDefinition, MiddlewareReturnFromParts, MiddlewareUnit, MiddlewareUnitBuilder, NextFn, NextResult, StandaloneMiddlewareContext, StateBrand, ValidatorParts, } from './units.js';
|
|
12
|
+
export type AppContext = RouterRegister extends {
|
|
13
|
+
AppContext: infer C;
|
|
14
|
+
} ? C : EmptyAppContext;
|
|
13
15
|
export type RoutePath = RouterRegister extends {
|
|
14
16
|
RoutePath: infer P;
|
|
15
17
|
} ? P : never;
|
|
@@ -22,6 +24,7 @@ export type LayoutTree = RouterRegister extends {
|
|
|
22
24
|
export type RouteByPathMethod = RouterRegister extends {
|
|
23
25
|
RouteByPathMethod: infer R;
|
|
24
26
|
} ? R : Record<never, never>;
|
|
27
|
+
export type LayoutBuilder<TAppContext extends Record<string, unknown> = AppContext> = <const Layout extends LayoutId>(layout: Layout) => MiddlewareBuilder<Layout, readonly [], TAppContext>;
|
|
25
28
|
type ParseParam<Segment extends string> = Segment extends "*" ? {
|
|
26
29
|
_splat: string;
|
|
27
30
|
} : Segment extends `:${infer Name extends string}` ? Name extends "" ? {} : {
|
|
@@ -30,14 +33,17 @@ type ParseParam<Segment extends string> = Segment extends "*" ? {
|
|
|
30
33
|
type ParseParamsFromSegments<S extends string> = S extends `${infer Segment}/${infer Rest}` ? ParseParam<Segment> & ParseParamsFromSegments<Rest> : ParseParam<S>;
|
|
31
34
|
export type PathParams<Path extends string> = Path extends `/${infer Rest}` ? ParseParamsFromSegments<Rest> : {};
|
|
32
35
|
export type ResolveParams<TPathParams, TSchemaParams> = TSchemaParams extends Record<string, unknown> ? [keyof TSchemaParams] extends [never] ? TPathParams : Simplify<Omit<TPathParams, keyof TSchemaParams> & TSchemaParams> : TPathParams;
|
|
33
|
-
type
|
|
36
|
+
type LayoutParentsMap = RouterRegister extends {
|
|
37
|
+
LayoutParents: infer LP extends Record<string, unknown>;
|
|
38
|
+
} ? LP : {};
|
|
39
|
+
type LayoutParent<Layout extends LayoutId> = Layout extends keyof LayoutParentsMap ? LayoutParentsMap[Layout] extends LayoutId ? LayoutParentsMap[Layout] : null : LayoutTree[Layout] extends {
|
|
34
40
|
parent: infer Parent extends LayoutId | null;
|
|
35
41
|
} ? Parent : null;
|
|
36
|
-
type ResolveLayoutMiddlewares<Layout extends LayoutId | null> =
|
|
37
|
-
...ResolveLayoutMiddlewares<LayoutParent<Layout
|
|
42
|
+
type ResolveLayoutMiddlewares<Layout extends LayoutId | null, Depth extends readonly unknown[] = []> = Depth["length"] extends 10 ? readonly [] : Layout extends LayoutId ? readonly [
|
|
43
|
+
...ResolveLayoutMiddlewares<LayoutParent<Layout>, [...Depth, unknown]>,
|
|
38
44
|
...LayoutTree[Layout]["middlewares"]
|
|
39
45
|
] : readonly [];
|
|
40
|
-
export type ResolveLayoutIdChain<L extends LayoutId | null> =
|
|
46
|
+
export type ResolveLayoutIdChain<L extends LayoutId | null, Depth extends readonly unknown[] = []> = Depth["length"] extends 10 ? readonly [] : L extends LayoutId ? readonly [...ResolveLayoutIdChain<LayoutParent<L>, [...Depth, unknown]>, L] : readonly [];
|
|
41
47
|
export type ResolveLayoutMiddlewaresState<Layout extends LayoutId | null> = Layout extends LayoutId ? MergeMiddlewareField<ResolveLayoutMiddlewares<Layout>, "state"> : {};
|
|
42
48
|
export type ResolveLayoutsState<Layouts extends LayoutId | readonly LayoutId[]> = Layouts extends LayoutId ? ResolveLayoutMiddlewaresState<Layouts> : Layouts extends readonly LayoutId[] ? UnionToIntersection<Layouts[number] extends infer L extends LayoutId ? ResolveLayoutMiddlewaresState<L> : never> : {};
|
|
43
49
|
/** Fold layout middleware Acc from a route's layoutChain (shallow → deep). */
|
|
@@ -61,12 +67,11 @@ export type RouteLayoutMiddlewares<Path extends RoutePath, TMethod extends Metho
|
|
|
61
67
|
export type RouteLayoutField<Path extends RoutePath, TMethod extends Method, Field extends "query" | "params" | "body" | "state"> = MergeMiddlewareField<RouteLayoutMiddlewares<Path, TMethod>, Field>;
|
|
62
68
|
export type RouteLayoutInputField<Path extends RoutePath, TMethod extends Method, Field extends "query" | "params" | "body"> = MergeMiddlewareInputField<RouteLayoutMiddlewares<Path, TMethod>, Field>;
|
|
63
69
|
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>;
|
|
64
|
-
type RouteChainField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body" | "state"> = RouteResolvedField<Path, TMethod, Acc, Field>;
|
|
65
70
|
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 & {
|
|
66
|
-
query: Simplify<MergePart<TQuery,
|
|
67
|
-
params: Simplify<ResolveParams<PathParams<Path>, MergePart<TParams,
|
|
68
|
-
body: Simplify<MergePart<TBody,
|
|
69
|
-
state: Simplify<
|
|
71
|
+
query: Simplify<MergePart<TQuery, RouteResolvedField<Path, TMethod, Acc, "query">>>;
|
|
72
|
+
params: Simplify<ResolveParams<PathParams<Path>, MergePart<TParams, RouteResolvedField<Path, TMethod, Acc, "params">>>>;
|
|
73
|
+
body: Simplify<MergePart<TBody, RouteResolvedField<Path, TMethod, Acc, "body">>>;
|
|
74
|
+
state: Simplify<RouteResolvedField<Path, TMethod, Acc, "state">>;
|
|
70
75
|
headers: TaserHeaders;
|
|
71
76
|
cookies: TaserCookieJar;
|
|
72
77
|
}>;
|
|
@@ -37,8 +37,8 @@ export type MiddlewareInputField<Middleware, Field extends MiddlewareInputFieldN
|
|
|
37
37
|
[K in Field]: infer V;
|
|
38
38
|
};
|
|
39
39
|
} ? V : {};
|
|
40
|
-
export type MergeMiddlewareField<Middlewares extends readonly unknown[], Field extends MiddlewareFieldName> =
|
|
41
|
-
export type MergeMiddlewareInputField<Middlewares extends readonly unknown[], Field extends MiddlewareInputFieldName> =
|
|
40
|
+
export type MergeMiddlewareField<Middlewares extends readonly unknown[], Field extends MiddlewareFieldName> = Middlewares extends readonly [] ? {} : Middlewares extends readonly [infer Head, ...infer Tail] ? MiddlewareField<Head, Field> & MergeMiddlewareField<Tail, Field> : MiddlewareField<Middlewares[number], Field>;
|
|
41
|
+
export type MergeMiddlewareInputField<Middlewares extends readonly unknown[], Field extends MiddlewareInputFieldName> = Middlewares extends readonly [] ? {} : Middlewares extends readonly [infer Head, ...infer Tail] ? MiddlewareInputField<Head, Field> & MergeMiddlewareInputField<Tail, Field> : MiddlewareInputField<Middlewares[number], Field>;
|
|
42
42
|
export type RuntimeContextFields = {
|
|
43
43
|
request: Request;
|
|
44
44
|
method: Method;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MiddlewareDefinition as CoreMiddlewareDefinition, TaserCookieJar, TaserHeaders } from '@taserjs/router-core';
|
|
2
2
|
import { RequestShape, Simplify, UnitRuntimeContext, UnwrapPart } from './type-utils.js';
|
|
3
3
|
import { ReturnsMap } from './returns.js';
|
|
4
4
|
import { Schema } from './schema.js';
|
|
5
5
|
export type { HttpMethod, Method } from './type-utils.js';
|
|
6
6
|
export type { EmptyReturns, MergeReturns, ReturnsMap, HandlerReply, HasReturns, StatusCode, ValidHandlerReply, EnforceHandlerReply, } from './returns.js';
|
|
7
7
|
/** Default empty app context for standalone units without a bound router instance. */
|
|
8
|
-
export type
|
|
8
|
+
export type EmptyAppContext = Record<never, never>;
|
|
9
9
|
export type ValidatorParts = {
|
|
10
10
|
query?: unknown;
|
|
11
11
|
params?: unknown;
|
|
@@ -18,16 +18,12 @@ export declare const StateBrand: unique symbol;
|
|
|
18
18
|
export type NextResult<TState = unknown> = Response & {
|
|
19
19
|
readonly [StateBrand]?: TState;
|
|
20
20
|
};
|
|
21
|
-
export type
|
|
22
|
-
[StateBrand]?:
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
}> extends {
|
|
26
|
-
[StateBrand]?: infer S;
|
|
27
|
-
} ? [S] extends [never] ? {} : S : {};
|
|
21
|
+
export type ExtractStateFromUnion<T> = T extends {
|
|
22
|
+
readonly [StateBrand]?: infer S;
|
|
23
|
+
} ? [S] extends [never] ? never : [unknown] extends [S] ? {} : S : never;
|
|
24
|
+
export type ExtractState<T> = [ExtractStateFromUnion<Awaited<T>>] extends [never] ? {} : ExtractStateFromUnion<Awaited<T>>;
|
|
28
25
|
export type IsUnknown<T> = [unknown] extends [T] ? true : false;
|
|
29
26
|
export type NextFn<TExpectedState = unknown> = IsUnknown<TExpectedState> extends true ? <S extends Record<string, unknown> = {}>(state?: S) => Promise<NextResult<S>> : (state: TExpectedState) => Promise<NextResult<TExpectedState>>;
|
|
30
|
-
export type MiddlewareNext = NextFn;
|
|
31
27
|
export type MiddlewareDefinition = CoreMiddlewareDefinition<ReturnsMap>;
|
|
32
28
|
export type MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TQueryIn = TQuery, TParamsIn = TParams, TBodyIn = TBody> = {
|
|
33
29
|
query: Simplify<UnwrapPart<TQuery>>;
|
|
@@ -42,7 +38,7 @@ export type MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TQueryIn =
|
|
|
42
38
|
};
|
|
43
39
|
};
|
|
44
40
|
export type DefineMiddlewareResult<TQuery, TParams, TBody, TState, R, TQueryIn = TQuery, TParamsIn = TParams, TBodyIn = TBody, TReturns extends ReturnsMap = {}, TLayout = null, TRequires = {}> = MiddlewareUnit<MiddlewareReturnFromParts<TQuery, TParams, TBody, IsUnknown<TState> extends true ? ExtractState<R> : TState, TQueryIn, TParamsIn, TBodyIn>, TReturns, TLayout, TRequires>;
|
|
45
|
-
export type StandaloneMiddlewareContext<TQuery = unknown, TParams = unknown, TBody = unknown, TAppContext extends Record<string, unknown> =
|
|
41
|
+
export type StandaloneMiddlewareContext<TQuery = unknown, TParams = unknown, TBody = unknown, TAppContext extends Record<string, unknown> = EmptyAppContext, TState = {}> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
46
42
|
query: Simplify<UnwrapPart<TQuery>>;
|
|
47
43
|
params: Simplify<UnwrapPart<TParams>>;
|
|
48
44
|
body: Simplify<UnwrapPart<TBody>>;
|
|
@@ -50,18 +46,20 @@ export type StandaloneMiddlewareContext<TQuery = unknown, TParams = unknown, TBo
|
|
|
50
46
|
headers: TaserHeaders;
|
|
51
47
|
cookies: TaserCookieJar;
|
|
52
48
|
}>;
|
|
49
|
+
export declare const MiddlewareUnitBrand: unique symbol;
|
|
53
50
|
export type MiddlewareUnit<TAcc = unknown, TReturns extends ReturnsMap = {}, TRequiredLayouts = unknown, TRequiredState = unknown> = MiddlewareDefinition & {
|
|
51
|
+
readonly [MiddlewareUnitBrand]: true;
|
|
54
52
|
readonly __middlewareAcc: TAcc;
|
|
55
53
|
readonly __returns?: TReturns;
|
|
56
54
|
readonly __requiredLayouts?: TRequiredLayouts;
|
|
57
55
|
readonly __requiredState?: TRequiredState;
|
|
58
56
|
};
|
|
59
|
-
export type MiddlewareUnitBuilder<TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TRequiredLayouts = unknown, TRequiredState = {}, TAppContext extends Record<string, unknown> =
|
|
60
|
-
query<Q, QIn = unknown>(schema: Schema<Q, QIn>): MiddlewareUnitBuilder<Q, TParams, TBody, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, QIn, TParamsIn, TBodyIn>;
|
|
61
|
-
params<P, PIn = unknown>(schema: Schema<P, PIn>): MiddlewareUnitBuilder<TQuery, P, TBody, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, PIn, TBodyIn>;
|
|
62
|
-
body<B, BIn = unknown>(schema: Schema<B, BIn>): MiddlewareUnitBuilder<TQuery, TParams, B, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, TParamsIn, BIn>;
|
|
63
|
-
body<Mode extends "json" | "form" | "urlencoded", B, BIn = unknown>(mode: Mode, schema: Schema<B, BIn>): MiddlewareUnitBuilder<TQuery, TParams, B, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, TParamsIn, BIn>;
|
|
64
|
-
returns<const M extends ReturnsMap>(map: M): MiddlewareUnitBuilder<TQuery, TParams, TBody, Omit<TReturns, keyof M> & M, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, TParamsIn, TBodyIn>;
|
|
65
|
-
requires<Requires extends Record<string, unknown>>(): MiddlewareUnitBuilder<TQuery, TParams, TBody, TReturns, TRequiredLayouts, TRequiredState & Requires, TAppContext, TInheritedState, TQueryIn, TParamsIn, TBodyIn>;
|
|
66
|
-
handler<
|
|
57
|
+
export type MiddlewareUnitBuilder<TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TRequiredLayouts = unknown, TRequiredState = {}, TAppContext extends Record<string, unknown> = EmptyAppContext, TInheritedState = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, TExpectedState = unknown> = MiddlewareUnit<MiddlewareReturnFromParts<TQuery, TParams, TBody, IsUnknown<TExpectedState> extends true ? {} : TExpectedState, TQueryIn, TParamsIn, TBodyIn>, TReturns, TRequiredLayouts, TRequiredState> & {
|
|
58
|
+
query<Q, QIn = unknown>(schema: Schema<Q, QIn>): MiddlewareUnitBuilder<Q, TParams, TBody, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, QIn, TParamsIn, TBodyIn, TExpectedState>;
|
|
59
|
+
params<P, PIn = unknown>(schema: Schema<P, PIn>): MiddlewareUnitBuilder<TQuery, P, TBody, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, PIn, TBodyIn, TExpectedState>;
|
|
60
|
+
body<B, BIn = unknown>(schema: Schema<B, BIn>): MiddlewareUnitBuilder<TQuery, TParams, B, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, TParamsIn, BIn, TExpectedState>;
|
|
61
|
+
body<Mode extends "json" | "form" | "urlencoded", B, BIn = unknown>(mode: Mode, schema: Schema<B, BIn>): MiddlewareUnitBuilder<TQuery, TParams, B, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, TParamsIn, BIn, TExpectedState>;
|
|
62
|
+
returns<const M extends ReturnsMap>(map: M): MiddlewareUnitBuilder<TQuery, TParams, TBody, Omit<TReturns, keyof M> & M, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, TParamsIn, TBodyIn, TExpectedState>;
|
|
63
|
+
requires<Requires extends Record<string, unknown>>(): MiddlewareUnitBuilder<TQuery, TParams, TBody, TReturns, TRequiredLayouts, TRequiredState & Requires, TAppContext, TInheritedState, TQueryIn, TParamsIn, TBodyIn, TExpectedState>;
|
|
64
|
+
handler<R>(fn: (ctx: StandaloneMiddlewareContext<TQuery, TParams, TBody, TAppContext, TInheritedState & TRequiredState>, next: NextFn<TExpectedState>) => R): DefineMiddlewareResult<TQuery, TParams, TBody, IsUnknown<TExpectedState> extends true ? ExtractState<R> : TExpectedState, R, TQueryIn, TParamsIn, TBodyIn, TReturns, TRequiredLayouts, TRequiredState>;
|
|
67
65
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { RouteBuilder, RoutePath } from '../types/index.js';
|
|
2
|
-
import {
|
|
1
|
+
import { AppContext, RouteBuilder, RoutePath } from '../types/index.js';
|
|
2
|
+
import { HttpMethod } from '../types/units.js';
|
|
3
3
|
export type CreateWithoutBodyRoute<M extends "GET" | "DELETE" | "OPTIONS" | "HEAD", TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath>(path: Path) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
|
|
4
4
|
export type CreateWithBodyRoute<M extends "POST" | "PUT" | "PATCH", TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath>(path: Path) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
|
|
5
5
|
export type CreateAnyRoute<TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath, const Methods extends readonly HttpMethod[]>(path: Path, methods: Methods) => RouteBuilder<Path, Methods[number], readonly [], {}, {}, TAppContext>;
|
|
6
6
|
export type CreateAllRoute<TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath>(path: Path) => RouteBuilder<Path, HttpMethod, readonly [], {}, {}, TAppContext>;
|
|
7
|
-
export declare const createGetRoute: CreateWithoutBodyRoute<"GET",
|
|
8
|
-
export declare const createDeleteRoute: CreateWithoutBodyRoute<"DELETE",
|
|
9
|
-
export declare const createOptionsRoute: CreateWithoutBodyRoute<"OPTIONS",
|
|
10
|
-
export declare const createHeadRoute: CreateWithoutBodyRoute<"HEAD",
|
|
11
|
-
export declare const createPostRoute: CreateWithBodyRoute<"POST",
|
|
12
|
-
export declare const createPutRoute: CreateWithBodyRoute<"PUT",
|
|
13
|
-
export declare const createPatchRoute: CreateWithBodyRoute<"PATCH",
|
|
7
|
+
export declare const createGetRoute: CreateWithoutBodyRoute<"GET", import('../index.js').EmptyAppContext>;
|
|
8
|
+
export declare const createDeleteRoute: CreateWithoutBodyRoute<"DELETE", import('../index.js').EmptyAppContext>;
|
|
9
|
+
export declare const createOptionsRoute: CreateWithoutBodyRoute<"OPTIONS", import('../index.js').EmptyAppContext>;
|
|
10
|
+
export declare const createHeadRoute: CreateWithoutBodyRoute<"HEAD", import('../index.js').EmptyAppContext>;
|
|
11
|
+
export declare const createPostRoute: CreateWithBodyRoute<"POST", import('../index.js').EmptyAppContext>;
|
|
12
|
+
export declare const createPutRoute: CreateWithBodyRoute<"PUT", import('../index.js').EmptyAppContext>;
|
|
13
|
+
export declare const createPatchRoute: CreateWithBodyRoute<"PATCH", import('../index.js').EmptyAppContext>;
|
|
14
14
|
export declare const createAnyRoute: CreateAnyRoute;
|
|
15
15
|
export declare const createAllRoute: CreateAllRoute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.js","names":[],"sources":["../../../src/builder/factories.ts"],"sourcesContent":["import { createRouteBuilder } from \"./route.js\";\nimport type { RouteBuilder, RoutePath } from \"../types/index.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"factories.js","names":[],"sources":["../../../src/builder/factories.ts"],"sourcesContent":["import { createRouteBuilder } from \"./route.js\";\nimport type { AppContext, RouteBuilder, RoutePath } from \"../types/index.js\";\nimport type { HttpMethod } from \"../types/units.js\";\n\nexport type CreateWithoutBodyRoute<\n M extends \"GET\" | \"DELETE\" | \"OPTIONS\" | \"HEAD\",\n TAppContext extends Record<string, unknown> = AppContext,\n> = <const Path extends RoutePath>(\n path: Path,\n) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;\n\nexport type CreateWithBodyRoute<\n M extends \"POST\" | \"PUT\" | \"PATCH\",\n TAppContext extends Record<string, unknown> = AppContext,\n> = <const Path extends RoutePath>(\n path: Path,\n) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;\n\nexport type CreateAnyRoute<TAppContext extends Record<string, unknown> = AppContext> = <\n const Path extends RoutePath,\n const Methods extends readonly HttpMethod[],\n>(\n path: Path,\n methods: Methods,\n) => RouteBuilder<Path, Methods[number], readonly [], {}, {}, TAppContext>;\n\nexport type CreateAllRoute<TAppContext extends Record<string, unknown> = AppContext> = <\n const Path extends RoutePath,\n>(\n path: Path,\n) => RouteBuilder<Path, HttpMethod, readonly [], {}, {}, TAppContext>;\n\nfunction createWithoutBodyRoute<M extends \"GET\" | \"DELETE\" | \"OPTIONS\" | \"HEAD\">(\n method: M,\n): CreateWithoutBodyRoute<M> {\n return ((path: string) =>\n createRouteBuilder(path, method)) as unknown as CreateWithoutBodyRoute<M>;\n}\n\nfunction createWithBodyRoute<M extends \"POST\" | \"PUT\" | \"PATCH\">(\n method: M,\n): CreateWithBodyRoute<M> {\n return ((path: string) => createRouteBuilder(path, method)) as unknown as CreateWithBodyRoute<M>;\n}\n\nexport const createGetRoute = createWithoutBodyRoute(\"GET\");\nexport const createDeleteRoute = createWithoutBodyRoute(\"DELETE\");\nexport const createOptionsRoute = createWithoutBodyRoute(\"OPTIONS\");\nexport const createHeadRoute = createWithoutBodyRoute(\"HEAD\");\nexport const createPostRoute = createWithBodyRoute(\"POST\");\nexport const createPutRoute = createWithBodyRoute(\"PUT\");\nexport const createPatchRoute = createWithBodyRoute(\"PATCH\");\n\nexport const createAnyRoute: CreateAnyRoute = ((path: string, methods: readonly HttpMethod[]) =>\n createRouteBuilder(path, \"ANY\", methods)) as unknown as CreateAnyRoute;\n\nexport const createAllRoute: CreateAllRoute = ((path: string) =>\n createRouteBuilder(path, \"ALL\")) as unknown as CreateAllRoute;\n"],"mappings":";;AAgCA,SAAS,uBACP,QAC2B;CAC3B,SAAS,SACP,mBAAmB,MAAM,MAAM;AACnC;AAEA,SAAS,oBACP,QACwB;CACxB,SAAS,SAAiB,mBAAmB,MAAM,MAAM;AAC3D;AAEA,IAAa,iBAAiB,uBAAuB,KAAK;AAC1D,IAAa,oBAAoB,uBAAuB,QAAQ;AAChE,IAAa,qBAAqB,uBAAuB,SAAS;AAClE,IAAa,kBAAkB,uBAAuB,MAAM;AAC5D,IAAa,kBAAkB,oBAAoB,MAAM;AACzD,IAAa,iBAAiB,oBAAoB,KAAK;AACvD,IAAa,mBAAmB,oBAAoB,OAAO;AAE3D,IAAa,mBAAmC,MAAc,YAC5D,mBAAmB,MAAM,OAAO,OAAO;AAEzC,IAAa,mBAAmC,SAC9C,mBAAmB,MAAM,KAAK"}
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { ReturnsMap } from '../types/returns.js';
|
|
3
|
-
import { Schema } from '../types/schema.js';
|
|
4
|
-
export declare function createMiddlewareUnitBuilder(requiredLayouts?: string | readonly string[]): {
|
|
5
|
-
query(schema: Schema<unknown>): /*elided*/ any;
|
|
6
|
-
params(schema: Schema<unknown>): /*elided*/ any;
|
|
7
|
-
body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>): /*elided*/ any;
|
|
8
|
-
returns(map: ReturnsMap): /*elided*/ any;
|
|
9
|
-
requires(): /*elided*/ any;
|
|
10
|
-
handler(fn: (ctx: any, next: any) => any): {
|
|
11
|
-
__middlewareAcc: unknown;
|
|
12
|
-
__requiredLayouts?: string | readonly string[];
|
|
13
|
-
returns?: ReturnsMap;
|
|
14
|
-
__returns?: ReturnsMap;
|
|
15
|
-
bodyMode?: BodyMode;
|
|
16
|
-
handler: (ctx: any, next: any) => any;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
1
|
+
export declare function createMiddlewareUnitBuilder(requiredLayouts?: string | readonly string[]): any;
|
|
@@ -4,6 +4,20 @@ function createMiddlewareUnitBuilder(requiredLayouts) {
|
|
|
4
4
|
const validators = {};
|
|
5
5
|
let bodyMode;
|
|
6
6
|
let returnsMap;
|
|
7
|
+
function toUnit(fn) {
|
|
8
|
+
const schemas = pickDefinedSchemas(validators);
|
|
9
|
+
return {
|
|
10
|
+
...fn ? { handler: fn } : {},
|
|
11
|
+
...schemas,
|
|
12
|
+
...bodyMode ? { bodyMode } : {},
|
|
13
|
+
...returnsMap ? {
|
|
14
|
+
returns: returnsMap,
|
|
15
|
+
__returns: returnsMap
|
|
16
|
+
} : {},
|
|
17
|
+
...requiredLayouts !== void 0 ? { __requiredLayouts: requiredLayouts } : {},
|
|
18
|
+
__middlewareAcc: void 0
|
|
19
|
+
};
|
|
20
|
+
}
|
|
7
21
|
const builder = {
|
|
8
22
|
query(schema) {
|
|
9
23
|
validators.query = schema;
|
|
@@ -34,19 +48,14 @@ function createMiddlewareUnitBuilder(requiredLayouts) {
|
|
|
34
48
|
return builder;
|
|
35
49
|
},
|
|
36
50
|
handler(fn) {
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
__returns: returnsMap
|
|
44
|
-
} : {},
|
|
45
|
-
...requiredLayouts !== void 0 ? { __requiredLayouts: requiredLayouts } : {},
|
|
46
|
-
__middlewareAcc: void 0
|
|
47
|
-
};
|
|
48
|
-
}
|
|
51
|
+
return toUnit(fn);
|
|
52
|
+
},
|
|
53
|
+
toUnit() {
|
|
54
|
+
return toUnit();
|
|
55
|
+
},
|
|
56
|
+
__middlewareAcc: void 0
|
|
49
57
|
};
|
|
58
|
+
if (requiredLayouts !== void 0) builder.__requiredLayouts = requiredLayouts;
|
|
50
59
|
return builder;
|
|
51
60
|
}
|
|
52
61
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware-unit.js","names":[],"sources":["../../../src/builder/middleware-unit.ts"],"sourcesContent":["import type { BodyMode } from \"@taserjs/router-core\";\n\nimport type { ReturnsMap } from \"../types/returns.js\";\nimport type { Schema } from \"../types/schema.js\";\nimport { pickDefinedSchemas, type SchemaValidators } from \"../define/validators.js\";\n\nexport function createMiddlewareUnitBuilder(requiredLayouts?: string | readonly string[]) {\n const validators: SchemaValidators = {};\n let bodyMode: BodyMode | undefined;\n let returnsMap: ReturnsMap | undefined;\n\n const builder = {\n query(schema: Schema<unknown>) {\n validators.query = schema;\n return builder;\n },\n params(schema: Schema<unknown>) {\n validators.params = schema;\n return builder;\n },\n body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>) {\n if (typeof modeOrSchema === \"string\") {\n bodyMode = modeOrSchema as BodyMode;\n if (schema !== undefined) {\n validators.body = schema;\n }\n } else {\n bodyMode = \"json\";\n validators.body = modeOrSchema;\n }\n return builder;\n },\n returns(map: ReturnsMap) {\n returnsMap = { ...returnsMap, ...map };\n return builder;\n },\n requires() {\n return builder;\n },\n handler(fn: (ctx: any, next: any) => any) {\n
|
|
1
|
+
{"version":3,"file":"middleware-unit.js","names":[],"sources":["../../../src/builder/middleware-unit.ts"],"sourcesContent":["import type { BodyMode } from \"@taserjs/router-core\";\n\nimport type { ReturnsMap } from \"../types/returns.js\";\nimport type { Schema } from \"../types/schema.js\";\nimport { pickDefinedSchemas, type SchemaValidators } from \"../define/validators.js\";\n\nexport function createMiddlewareUnitBuilder(requiredLayouts?: string | readonly string[]) {\n const validators: SchemaValidators = {};\n let bodyMode: BodyMode | undefined;\n let returnsMap: ReturnsMap | undefined;\n\n function toUnit(fn?: (ctx: any, next: any) => any) {\n const schemas = pickDefinedSchemas(validators);\n return {\n ...(fn ? { handler: fn } : {}),\n ...schemas,\n ...(bodyMode ? { bodyMode } : {}),\n ...(returnsMap ? { returns: returnsMap, __returns: returnsMap } : {}),\n ...(requiredLayouts !== undefined ? { __requiredLayouts: requiredLayouts } : {}),\n __middlewareAcc: undefined as unknown,\n };\n }\n\n const builder: any = {\n query(schema: Schema<unknown>) {\n validators.query = schema;\n return builder;\n },\n params(schema: Schema<unknown>) {\n validators.params = schema;\n return builder;\n },\n body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>) {\n if (typeof modeOrSchema === \"string\") {\n bodyMode = modeOrSchema as BodyMode;\n if (schema !== undefined) {\n validators.body = schema;\n }\n } else {\n bodyMode = \"json\";\n validators.body = modeOrSchema;\n }\n return builder;\n },\n returns(map: ReturnsMap) {\n returnsMap = { ...returnsMap, ...map };\n return builder;\n },\n requires() {\n return builder;\n },\n handler(fn: (ctx: any, next: any) => any) {\n return toUnit(fn);\n },\n toUnit() {\n return toUnit();\n },\n __middlewareAcc: undefined as unknown,\n };\n\n if (requiredLayouts !== undefined) {\n builder.__requiredLayouts = requiredLayouts;\n }\n\n return builder;\n}\n"],"mappings":";;AAMA,SAAgB,4BAA4B,iBAA8C;CACxF,MAAM,aAA+B,CAAC;CACtC,IAAI;CACJ,IAAI;CAEJ,SAAS,OAAO,IAAmC;EACjD,MAAM,UAAU,mBAAmB,UAAU;EAC7C,OAAO;GACL,GAAI,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;GAC5B,GAAG;GACH,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;GAC/B,GAAI,aAAa;IAAE,SAAS;IAAY,WAAW;GAAW,IAAI,CAAC;GACnE,GAAI,oBAAoB,KAAA,IAAY,EAAE,mBAAmB,gBAAgB,IAAI,CAAC;GAC9E,iBAAiB,KAAA;EACnB;CACF;CAEA,MAAM,UAAe;EACnB,MAAM,QAAyB;GAC7B,WAAW,QAAQ;GACnB,OAAO;EACT;EACA,OAAO,QAAyB;GAC9B,WAAW,SAAS;GACpB,OAAO;EACT;EACA,KAAK,cAA0C,QAA0B;GACvE,IAAI,OAAO,iBAAiB,UAAU;IACpC,WAAW;IACX,IAAI,WAAW,KAAA,GACb,WAAW,OAAO;GAEtB,OAAO;IACL,WAAW;IACX,WAAW,OAAO;GACpB;GACA,OAAO;EACT;EACA,QAAQ,KAAiB;GACvB,aAAa;IAAE,GAAG;IAAY,GAAG;GAAI;GACrC,OAAO;EACT;EACA,WAAW;GACT,OAAO;EACT;EACA,QAAQ,IAAkC;GACxC,OAAO,OAAO,EAAE;EAClB;EACA,SAAS;GACP,OAAO,OAAO;EAChB;EACA,iBAAiB,KAAA;CACnB;CAEA,IAAI,oBAAoB,KAAA,GACtB,QAAQ,oBAAoB;CAG9B,OAAO;AACT"}
|
|
@@ -6,6 +6,7 @@ function createMiddleware(layout) {
|
|
|
6
6
|
middlewares: entries,
|
|
7
7
|
use(definition) {
|
|
8
8
|
if (typeof definition === "function") entries.push({ handler: definition });
|
|
9
|
+
else if (typeof definition?.toUnit === "function") entries.push(definition.toUnit());
|
|
9
10
|
else entries.push(definition);
|
|
10
11
|
return chain;
|
|
11
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","names":[],"sources":["../../../src/builder/middleware.ts"],"sourcesContent":["import type { LayoutId, MiddlewareBuilder } from \"../types/index.js\";\nimport type { MiddlewareDefinition } from \"../types/units.js\";\n\nexport function createMiddleware<const Layout extends LayoutId>(\n layout: Layout,\n): MiddlewareBuilder<Layout, readonly []> {\n const entries: MiddlewareDefinition[] = [];\n\n const chain = {\n layout,\n middlewares: entries,\n use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)) {\n if (typeof definition === \"function\") {\n entries.push({ handler: definition as any });\n } else {\n entries.push(definition);\n }\n return chain;\n },\n };\n\n return chain as unknown as MiddlewareBuilder<Layout, readonly []>;\n}\n"],"mappings":";AAGA,SAAgB,iBACd,QACwC;CACxC,MAAM,UAAkC,CAAC;CAEzC,MAAM,QAAQ;EACZ;EACA,aAAa;EACb,IAAI,YAAmE;GACrE,IAAI,OAAO,eAAe,YACxB,QAAQ,KAAK,EAAE,SAAS,WAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware.js","names":[],"sources":["../../../src/builder/middleware.ts"],"sourcesContent":["import type { LayoutId, MiddlewareBuilder } from \"../types/index.js\";\nimport type { MiddlewareDefinition } from \"../types/units.js\";\n\nexport function createMiddleware<const Layout extends LayoutId>(\n layout: Layout,\n): MiddlewareBuilder<Layout, readonly []> {\n const entries: MiddlewareDefinition[] = [];\n\n const chain = {\n layout,\n middlewares: entries,\n use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)) {\n if (typeof definition === \"function\") {\n entries.push({ handler: definition as any });\n } else if (typeof (definition as any)?.toUnit === \"function\") {\n entries.push((definition as any).toUnit());\n } else {\n entries.push(definition);\n }\n return chain;\n },\n };\n\n return chain as unknown as MiddlewareBuilder<Layout, readonly []>;\n}\n"],"mappings":";AAGA,SAAgB,iBACd,QACwC;CACxC,MAAM,UAAkC,CAAC;CAEzC,MAAM,QAAQ;EACZ;EACA,aAAa;EACb,IAAI,YAAmE;GACrE,IAAI,OAAO,eAAe,YACxB,QAAQ,KAAK,EAAE,SAAS,WAAkB,CAAC;QACtC,IAAI,OAAQ,YAAoB,WAAW,YAChD,QAAQ,KAAM,WAAmB,OAAO,CAAC;QAEzC,QAAQ,KAAK,UAAU;GAEzB,OAAO;EACT;CACF;CAEA,OAAO;AACT"}
|
|
@@ -55,6 +55,7 @@ function createRouteBuilder(path, method, methods) {
|
|
|
55
55
|
},
|
|
56
56
|
use(definition) {
|
|
57
57
|
if (typeof definition === "function") middlewares.push({ handler: definition });
|
|
58
|
+
else if (typeof definition?.toUnit === "function") middlewares.push(definition.toUnit());
|
|
58
59
|
else middlewares.push(definition);
|
|
59
60
|
return builder;
|
|
60
61
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","names":[],"sources":["../../../src/builder/route.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport {\n collectReturnsFromDefinitions,\n hasInputSchemas,\n mergeReturnsMaps,\n withAuto422,\n} from \"@taserjs/router-utils\";\nimport type { BodyMode } from \"@taserjs/router-core\";\n\nimport type {\n Method,\n RouteBuilder,\n RoutePath,\n ReturnsMap,\n ValidatorParts,\n Schema,\n} from \"../types/index.js\";\nimport type { HttpMethod, MiddlewareDefinition } from \"../types/units.js\";\nimport { pickDefinedSchemas, type SchemaValidators } from \"../define/validators.js\";\n\nfunction toUtilsMap(map: ReturnsMap | undefined): Record<number, StandardSchemaV1> {\n if (!map) {\n return {};\n }\n const out: Record<number, StandardSchemaV1> = {};\n for (const [key, schema] of Object.entries(map)) {\n if (schema !== undefined) {\n out[Number(key)] = schema;\n }\n }\n return out;\n}\n\nfunction buildEffectiveReturns(args: {\n middlewareReturns: ReturnsMap;\n routeReturns: ReturnsMap;\n schemas: {\n query?: unknown;\n params?: unknown;\n body?: unknown;\n middlewares?: readonly MiddlewareDefinition[];\n };\n}): Record<number, StandardSchemaV1> | undefined {\n const merged = mergeReturnsMaps(\n toUtilsMap(args.middlewareReturns),\n toUtilsMap(args.routeReturns),\n );\n const with422 = withAuto422(merged, hasInputSchemas(args.schemas));\n return Object.keys(with422).length > 0 ? with422 : undefined;\n}\n\nfunction buildRouteBase(\n path: string,\n method: HttpMethod | \"ANY\" | \"ALL\",\n methods: readonly HttpMethod[] | undefined,\n middlewares: MiddlewareDefinition[],\n) {\n return {\n path,\n method,\n ...(methods ? { methods: [...methods] } : {}),\n middlewares: [...middlewares],\n };\n}\n\n/** Shared internal builder — not part of the public `@taserjs/router` API. */\nexport function createRouteBuilder(\n path: string,\n method: HttpMethod | \"ANY\" | \"ALL\",\n methods?: readonly HttpMethod[],\n): RouteBuilder<RoutePath, Method, readonly [], ValidatorParts> {\n const middlewares: MiddlewareDefinition[] = [];\n let routeReturns: Record<number, StandardSchemaV1> = {};\n const validators: SchemaValidators = {};\n let bodyMode: BodyMode | undefined;\n\n const builder = {\n path,\n method,\n query(schema: Schema<unknown>) {\n validators.query = schema;\n return builder;\n },\n params(schema: Schema<unknown>) {\n validators.params = schema;\n return builder;\n },\n body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>) {\n if (typeof modeOrSchema === \"string\") {\n bodyMode = modeOrSchema as BodyMode;\n if (schema !== undefined) {\n validators.body = schema;\n }\n } else {\n bodyMode = \"json\";\n validators.body = modeOrSchema;\n }\n return builder;\n },\n returns(map: ReturnsMap) {\n routeReturns = { ...routeReturns, ...toUtilsMap(map) };\n return builder;\n },\n use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)) {\n if (typeof definition === \"function\") {\n middlewares.push({ handler: definition as any });\n } else {\n middlewares.push(definition);\n }\n return builder;\n },\n handler(fn: (ctx: unknown) => Response | Promise<Response>) {\n const routeSchemas = pickDefinedSchemas(validators);\n const base = buildRouteBase(path, method, methods, middlewares);\n\n const returns = buildEffectiveReturns({\n middlewareReturns: collectReturnsFromDefinitions(middlewares),\n routeReturns,\n schemas: {\n ...validators,\n middlewares,\n },\n });\n\n return {\n ...base,\n handler: fn,\n ...routeSchemas,\n ...(bodyMode ? { bodyMode } : {}),\n ...(returns ? { returns } : {}),\n };\n },\n };\n\n return builder as unknown as RouteBuilder<RoutePath, Method, readonly [], ValidatorParts>;\n}\n"],"mappings":";;;AAoBA,SAAS,WAAW,KAA+D;CACjF,IAAI,CAAC,KACH,OAAO,CAAC;CAEV,MAAM,MAAwC,CAAC;CAC/C,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,GAAG,GAC5C,IAAI,WAAW,KAAA,GACb,IAAI,OAAO,GAAG,KAAK;CAGvB,OAAO;AACT;AAEA,SAAS,sBAAsB,MASkB;CAK/C,MAAM,UAAU,YAJD,iBACb,WAAW,KAAK,iBAAiB,GACjC,WAAW,KAAK,YAAY,CAEF,GAAQ,gBAAgB,KAAK,OAAO,CAAC;CACjE,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IAAI,UAAU,KAAA;AACrD;AAEA,SAAS,eACP,MACA,QACA,SACA,aACA;CACA,OAAO;EACL;EACA;EACA,GAAI,UAAU,EAAE,SAAS,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC;EAC3C,aAAa,CAAC,GAAG,WAAW;CAC9B;AACF;;AAGA,SAAgB,mBACd,MACA,QACA,SAC8D;CAC9D,MAAM,cAAsC,CAAC;CAC7C,IAAI,eAAiD,CAAC;CACtD,MAAM,aAA+B,CAAC;CACtC,IAAI;CAEJ,MAAM,UAAU;EACd;EACA;EACA,MAAM,QAAyB;GAC7B,WAAW,QAAQ;GACnB,OAAO;EACT;EACA,OAAO,QAAyB;GAC9B,WAAW,SAAS;GACpB,OAAO;EACT;EACA,KAAK,cAA0C,QAA0B;GACvE,IAAI,OAAO,iBAAiB,UAAU;IACpC,WAAW;IACX,IAAI,WAAW,KAAA,GACb,WAAW,OAAO;GAEtB,OAAO;IACL,WAAW;IACX,WAAW,OAAO;GACpB;GACA,OAAO;EACT;EACA,QAAQ,KAAiB;GACvB,eAAe;IAAE,GAAG;IAAc,GAAG,WAAW,GAAG;GAAE;GACrD,OAAO;EACT;EACA,IAAI,YAAmE;GACrE,IAAI,OAAO,eAAe,YACxB,YAAY,KAAK,EAAE,SAAS,WAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"route.js","names":[],"sources":["../../../src/builder/route.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport {\n collectReturnsFromDefinitions,\n hasInputSchemas,\n mergeReturnsMaps,\n withAuto422,\n} from \"@taserjs/router-utils\";\nimport type { BodyMode } from \"@taserjs/router-core\";\n\nimport type {\n Method,\n RouteBuilder,\n RoutePath,\n ReturnsMap,\n ValidatorParts,\n Schema,\n} from \"../types/index.js\";\nimport type { HttpMethod, MiddlewareDefinition } from \"../types/units.js\";\nimport { pickDefinedSchemas, type SchemaValidators } from \"../define/validators.js\";\n\nfunction toUtilsMap(map: ReturnsMap | undefined): Record<number, StandardSchemaV1> {\n if (!map) {\n return {};\n }\n const out: Record<number, StandardSchemaV1> = {};\n for (const [key, schema] of Object.entries(map)) {\n if (schema !== undefined) {\n out[Number(key)] = schema;\n }\n }\n return out;\n}\n\nfunction buildEffectiveReturns(args: {\n middlewareReturns: ReturnsMap;\n routeReturns: ReturnsMap;\n schemas: {\n query?: unknown;\n params?: unknown;\n body?: unknown;\n middlewares?: readonly MiddlewareDefinition[];\n };\n}): Record<number, StandardSchemaV1> | undefined {\n const merged = mergeReturnsMaps(\n toUtilsMap(args.middlewareReturns),\n toUtilsMap(args.routeReturns),\n );\n const with422 = withAuto422(merged, hasInputSchemas(args.schemas));\n return Object.keys(with422).length > 0 ? with422 : undefined;\n}\n\nfunction buildRouteBase(\n path: string,\n method: HttpMethod | \"ANY\" | \"ALL\",\n methods: readonly HttpMethod[] | undefined,\n middlewares: MiddlewareDefinition[],\n) {\n return {\n path,\n method,\n ...(methods ? { methods: [...methods] } : {}),\n middlewares: [...middlewares],\n };\n}\n\n/** Shared internal builder — not part of the public `@taserjs/router` API. */\nexport function createRouteBuilder(\n path: string,\n method: HttpMethod | \"ANY\" | \"ALL\",\n methods?: readonly HttpMethod[],\n): RouteBuilder<RoutePath, Method, readonly [], ValidatorParts> {\n const middlewares: MiddlewareDefinition[] = [];\n let routeReturns: Record<number, StandardSchemaV1> = {};\n const validators: SchemaValidators = {};\n let bodyMode: BodyMode | undefined;\n\n const builder = {\n path,\n method,\n query(schema: Schema<unknown>) {\n validators.query = schema;\n return builder;\n },\n params(schema: Schema<unknown>) {\n validators.params = schema;\n return builder;\n },\n body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>) {\n if (typeof modeOrSchema === \"string\") {\n bodyMode = modeOrSchema as BodyMode;\n if (schema !== undefined) {\n validators.body = schema;\n }\n } else {\n bodyMode = \"json\";\n validators.body = modeOrSchema;\n }\n return builder;\n },\n returns(map: ReturnsMap) {\n routeReturns = { ...routeReturns, ...toUtilsMap(map) };\n return builder;\n },\n use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)) {\n if (typeof definition === \"function\") {\n middlewares.push({ handler: definition as any });\n } else if (typeof (definition as any)?.toUnit === \"function\") {\n middlewares.push((definition as any).toUnit());\n } else {\n middlewares.push(definition);\n }\n return builder;\n },\n handler(fn: (ctx: unknown) => Response | Promise<Response>) {\n const routeSchemas = pickDefinedSchemas(validators);\n const base = buildRouteBase(path, method, methods, middlewares);\n\n const returns = buildEffectiveReturns({\n middlewareReturns: collectReturnsFromDefinitions(middlewares),\n routeReturns,\n schemas: {\n ...validators,\n middlewares,\n },\n });\n\n return {\n ...base,\n handler: fn,\n ...routeSchemas,\n ...(bodyMode ? { bodyMode } : {}),\n ...(returns ? { returns } : {}),\n };\n },\n };\n\n return builder as unknown as RouteBuilder<RoutePath, Method, readonly [], ValidatorParts>;\n}\n"],"mappings":";;;AAoBA,SAAS,WAAW,KAA+D;CACjF,IAAI,CAAC,KACH,OAAO,CAAC;CAEV,MAAM,MAAwC,CAAC;CAC/C,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,GAAG,GAC5C,IAAI,WAAW,KAAA,GACb,IAAI,OAAO,GAAG,KAAK;CAGvB,OAAO;AACT;AAEA,SAAS,sBAAsB,MASkB;CAK/C,MAAM,UAAU,YAJD,iBACb,WAAW,KAAK,iBAAiB,GACjC,WAAW,KAAK,YAAY,CAEF,GAAQ,gBAAgB,KAAK,OAAO,CAAC;CACjE,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IAAI,UAAU,KAAA;AACrD;AAEA,SAAS,eACP,MACA,QACA,SACA,aACA;CACA,OAAO;EACL;EACA;EACA,GAAI,UAAU,EAAE,SAAS,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC;EAC3C,aAAa,CAAC,GAAG,WAAW;CAC9B;AACF;;AAGA,SAAgB,mBACd,MACA,QACA,SAC8D;CAC9D,MAAM,cAAsC,CAAC;CAC7C,IAAI,eAAiD,CAAC;CACtD,MAAM,aAA+B,CAAC;CACtC,IAAI;CAEJ,MAAM,UAAU;EACd;EACA;EACA,MAAM,QAAyB;GAC7B,WAAW,QAAQ;GACnB,OAAO;EACT;EACA,OAAO,QAAyB;GAC9B,WAAW,SAAS;GACpB,OAAO;EACT;EACA,KAAK,cAA0C,QAA0B;GACvE,IAAI,OAAO,iBAAiB,UAAU;IACpC,WAAW;IACX,IAAI,WAAW,KAAA,GACb,WAAW,OAAO;GAEtB,OAAO;IACL,WAAW;IACX,WAAW,OAAO;GACpB;GACA,OAAO;EACT;EACA,QAAQ,KAAiB;GACvB,eAAe;IAAE,GAAG;IAAc,GAAG,WAAW,GAAG;GAAE;GACrD,OAAO;EACT;EACA,IAAI,YAAmE;GACrE,IAAI,OAAO,eAAe,YACxB,YAAY,KAAK,EAAE,SAAS,WAAkB,CAAC;QAC1C,IAAI,OAAQ,YAAoB,WAAW,YAChD,YAAY,KAAM,WAAmB,OAAO,CAAC;QAE7C,YAAY,KAAK,UAAU;GAE7B,OAAO;EACT;EACA,QAAQ,IAAoD;GAC1D,MAAM,eAAe,mBAAmB,UAAU;GAClD,MAAM,OAAO,eAAe,MAAM,QAAQ,SAAS,WAAW;GAE9D,MAAM,UAAU,sBAAsB;IACpC,mBAAmB,8BAA8B,WAAW;IAC5D;IACA,SAAS;KACP,GAAG;KACH;IACF;GACF,CAAC;GAED,OAAO;IACL,GAAG;IACH,SAAS;IACT,GAAG;IACH,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;IAC/B,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;GAC/B;EACF;CACF;CAEA,OAAO;AACT"}
|