@taserjs/router 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/app.cjs +22 -0
- package/dist/cjs/builder/app.cjs.map +1 -0
- package/dist/cjs/builder/app.d.cts +11 -0
- package/dist/cjs/{constants.cjs → builder/constants.cjs} +1 -1
- package/dist/cjs/builder/constants.cjs.map +1 -0
- package/dist/cjs/{factories.cjs → builder/factories.cjs} +1 -1
- package/dist/cjs/builder/factories.cjs.map +1 -0
- package/dist/cjs/{factories.d.cts → builder/factories.d.cts} +2 -2
- package/dist/cjs/{middleware.cjs → builder/middleware.cjs} +1 -1
- package/dist/cjs/builder/middleware.cjs.map +1 -0
- package/dist/cjs/{middleware.d.cts → builder/middleware.d.cts} +1 -1
- package/dist/cjs/{route.cjs → builder/route.cjs} +19 -33
- package/dist/cjs/builder/route.cjs.map +1 -0
- package/dist/cjs/{route.d.cts → builder/route.d.cts} +3 -3
- package/dist/cjs/{taser-router.cjs → builder/router.cjs} +38 -11
- package/dist/cjs/builder/router.cjs.map +1 -0
- package/dist/cjs/builder/router.d.cts +48 -0
- package/dist/cjs/{create-context.cjs → context/create-context.cjs} +1 -1
- package/dist/cjs/context/create-context.cjs.map +1 -0
- package/dist/cjs/{create-context.d.cts → context/create-context.d.cts} +2 -2
- package/dist/cjs/define/validators.cjs +1 -1
- package/dist/cjs/define/validators.cjs.map +1 -1
- package/dist/cjs/define/validators.d.cts +1 -1
- package/dist/cjs/index.cjs +6 -16
- package/dist/cjs/index.d.cts +6 -7
- package/dist/cjs/middleware/body-limit.cjs +2 -2
- package/dist/cjs/middleware/body-limit.cjs.map +1 -1
- package/dist/cjs/middleware/compress.cjs +2 -2
- package/dist/cjs/middleware/compress.cjs.map +1 -1
- package/dist/cjs/middleware/cors.cjs +2 -2
- package/dist/cjs/middleware/cors.cjs.map +1 -1
- package/dist/cjs/middleware/csrf.cjs +2 -2
- package/dist/cjs/middleware/csrf.cjs.map +1 -1
- package/dist/cjs/middleware/etag.cjs +2 -2
- package/dist/cjs/middleware/etag.cjs.map +1 -1
- package/dist/cjs/middleware/jwk.cjs +2 -8
- package/dist/cjs/middleware/jwk.cjs.map +1 -1
- package/dist/cjs/middleware/jwt.cjs +2 -8
- package/dist/cjs/middleware/jwt.cjs.map +1 -1
- package/dist/cjs/middleware/secure-headers.cjs +2 -2
- package/dist/cjs/middleware/secure-headers.cjs.map +1 -1
- package/dist/cjs/middleware/timing.cjs +2 -2
- package/dist/cjs/middleware/timing.cjs.map +1 -1
- package/dist/cjs/middleware/wrap-hono.cjs +10 -0
- package/dist/cjs/middleware/wrap-hono.cjs.map +1 -1
- package/dist/cjs/middleware/wrap-hono.d.cts +4 -0
- package/dist/cjs/types/app.d.cts +7 -7
- package/dist/cjs/types/index.d.cts +32 -13
- package/dist/cjs/types/returns.d.cts +2 -2
- package/dist/cjs/types/type-utils.d.cts +1 -2
- package/dist/cjs/types/units.cjs.map +1 -1
- package/dist/cjs/types/units.d.cts +4 -9
- package/dist/esm/builder/app.d.ts +11 -0
- package/dist/esm/builder/app.js +22 -0
- package/dist/esm/builder/app.js.map +1 -0
- package/dist/esm/{constants.js → builder/constants.js} +1 -1
- package/dist/esm/builder/constants.js.map +1 -0
- package/dist/esm/{factories.d.ts → builder/factories.d.ts} +2 -2
- package/dist/esm/{factories.js → builder/factories.js} +1 -1
- package/dist/esm/builder/factories.js.map +1 -0
- package/dist/esm/{middleware.d.ts → builder/middleware.d.ts} +1 -1
- package/dist/esm/{middleware.js → builder/middleware.js} +1 -1
- package/dist/esm/builder/middleware.js.map +1 -0
- package/dist/esm/{route.d.ts → builder/route.d.ts} +3 -3
- package/dist/esm/{route.js → builder/route.js} +19 -33
- package/dist/esm/builder/route.js.map +1 -0
- package/dist/esm/builder/router.d.ts +48 -0
- package/dist/esm/{taser-router.js → builder/router.js} +37 -10
- package/dist/esm/builder/router.js.map +1 -0
- package/dist/esm/{create-context.d.ts → context/create-context.d.ts} +2 -2
- package/dist/esm/{create-context.js → context/create-context.js} +1 -1
- package/dist/esm/context/create-context.js.map +1 -0
- package/dist/esm/define/validators.d.ts +1 -1
- package/dist/esm/define/validators.js +1 -1
- package/dist/esm/define/validators.js.map +1 -1
- package/dist/esm/index.d.ts +6 -7
- package/dist/esm/index.js +5 -6
- package/dist/esm/middleware/body-limit.js +2 -2
- package/dist/esm/middleware/body-limit.js.map +1 -1
- package/dist/esm/middleware/compress.js +2 -2
- package/dist/esm/middleware/compress.js.map +1 -1
- package/dist/esm/middleware/cors.js +2 -2
- package/dist/esm/middleware/cors.js.map +1 -1
- package/dist/esm/middleware/csrf.js +2 -2
- package/dist/esm/middleware/csrf.js.map +1 -1
- package/dist/esm/middleware/etag.js +2 -2
- package/dist/esm/middleware/etag.js.map +1 -1
- package/dist/esm/middleware/jwk.js +2 -8
- package/dist/esm/middleware/jwk.js.map +1 -1
- package/dist/esm/middleware/jwt.js +2 -8
- package/dist/esm/middleware/jwt.js.map +1 -1
- package/dist/esm/middleware/secure-headers.js +2 -2
- package/dist/esm/middleware/secure-headers.js.map +1 -1
- package/dist/esm/middleware/timing.js +2 -2
- package/dist/esm/middleware/timing.js.map +1 -1
- package/dist/esm/middleware/wrap-hono.d.ts +4 -0
- package/dist/esm/middleware/wrap-hono.js +10 -1
- package/dist/esm/middleware/wrap-hono.js.map +1 -1
- package/dist/esm/types/app.d.ts +7 -7
- package/dist/esm/types/index.d.ts +32 -13
- package/dist/esm/types/returns.d.ts +2 -2
- package/dist/esm/types/type-utils.d.ts +1 -2
- package/dist/esm/types/units.d.ts +4 -9
- package/dist/esm/types/units.js.map +1 -1
- package/package.json +3 -3
- package/src/builder/app.ts +28 -0
- package/src/{factories.ts → builder/factories.ts} +2 -2
- package/src/{middleware.ts → builder/middleware.ts} +2 -2
- package/src/{route.ts → builder/route.ts} +30 -34
- package/src/builder/router.ts +347 -0
- package/src/{create-context.ts → context/create-context.ts} +2 -2
- package/src/define/validators.ts +1 -1
- package/src/index.ts +9 -12
- package/src/middleware/body-limit.ts +2 -2
- package/src/middleware/compress.ts +2 -2
- package/src/middleware/cors.ts +2 -2
- package/src/middleware/csrf.ts +2 -2
- package/src/middleware/etag.ts +2 -2
- package/src/middleware/jwk.ts +2 -7
- package/src/middleware/jwt.ts +2 -7
- package/src/middleware/secure-headers.ts +2 -2
- package/src/middleware/timing.ts +2 -2
- package/src/middleware/wrap-hono.ts +13 -0
- package/src/types/app.ts +12 -8
- package/src/types/index.ts +44 -10
- package/src/types/returns.ts +2 -2
- package/src/types/type-utils.ts +1 -2
- package/src/types/units.ts +4 -8
- package/dist/cjs/constants.cjs.map +0 -1
- package/dist/cjs/create-context.cjs.map +0 -1
- package/dist/cjs/factories.cjs.map +0 -1
- package/dist/cjs/middleware.cjs.map +0 -1
- package/dist/cjs/route.cjs.map +0 -1
- package/dist/cjs/taser-app.cjs +0 -36
- package/dist/cjs/taser-app.cjs.map +0 -1
- package/dist/cjs/taser-app.d.cts +0 -18
- package/dist/cjs/taser-router.cjs.map +0 -1
- package/dist/cjs/taser-router.d.cts +0 -42
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/create-context.js.map +0 -1
- package/dist/esm/factories.js.map +0 -1
- package/dist/esm/middleware.js.map +0 -1
- package/dist/esm/route.js.map +0 -1
- package/dist/esm/taser-app.d.ts +0 -18
- package/dist/esm/taser-app.js +0 -35
- package/dist/esm/taser-app.js.map +0 -1
- package/dist/esm/taser-router.d.ts +0 -42
- package/dist/esm/taser-router.js.map +0 -1
- package/src/taser-app.ts +0 -38
- package/src/taser-router.ts +0 -165
- /package/dist/cjs/{constants.d.cts → builder/constants.d.cts} +0 -0
- /package/dist/esm/{constants.d.ts → builder/constants.d.ts} +0 -0
- /package/src/{constants.ts → builder/constants.ts} +0 -0
|
@@ -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/types/app.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { 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 = {
|
|
@@ -21,19 +22,18 @@ export type CreateTaserAppOptions = {
|
|
|
21
22
|
expires?: Date;
|
|
22
23
|
};
|
|
23
24
|
};
|
|
24
|
-
export type CreateContextArgs = {
|
|
25
|
-
native?: import('./units.js').NativeContext;
|
|
26
|
-
};
|
|
27
25
|
export type ContextDefinition<TBoot extends Record<string, unknown> = Record<string, never>, TReq extends Record<string, unknown> = Record<string, never>> = {
|
|
28
26
|
boot?: () => TBoot | Promise<TBoot>;
|
|
29
|
-
request?: (
|
|
27
|
+
request?: (req: Request) => TReq | Promise<TReq>;
|
|
30
28
|
};
|
|
31
29
|
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
30
|
export type OnErrorOptions<TResponses extends ReturnsMap = ReturnsMap> = {
|
|
33
31
|
responses?: TResponses;
|
|
34
32
|
handle: (error: unknown, ctx?: unknown) => Response | Promise<Response>;
|
|
35
33
|
};
|
|
36
|
-
export type InferAppManifest<TApp> = TApp extends TaserApp<infer TManifest> ? TManifest :
|
|
34
|
+
export type InferAppManifest<TApp> = TApp extends TaserApp<infer TManifest> ? TManifest : TApp extends {
|
|
35
|
+
manifest: infer TManifest;
|
|
36
|
+
} ? TManifest : TApp extends RouteManifestShape ? TApp : never;
|
|
37
37
|
export type TaserHandler<TFrameworkApp> = {
|
|
38
38
|
/**
|
|
39
39
|
* Mount the Taser handler on a framework app.
|
|
@@ -44,4 +44,4 @@ export type TaserHandler<TFrameworkApp> = {
|
|
|
44
44
|
};
|
|
45
45
|
export type { RouteManifestShape } from '@taserjs/router-core';
|
|
46
46
|
export type { Schema };
|
|
47
|
-
export type { TaserApp
|
|
47
|
+
export type { TaserApp } from '../builder/app.js';
|
|
@@ -3,13 +3,13 @@ import { RouterRegister } from '../register.js';
|
|
|
3
3
|
import { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape, RuntimeContextFields, Simplify, UnionToIntersection } 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
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,
|
|
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;
|
|
@@ -58,10 +59,10 @@ type RouteLayoutChain<Path extends RoutePath, TMethod extends Method> = RouteEnt
|
|
|
58
59
|
} ? Chain : RouteParent<Path, TMethod> extends LayoutId ? readonly [RouteParent<Path, TMethod>] : readonly [];
|
|
59
60
|
type RouteResolvedField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body" | "state"> = MergeMiddlewareField<ResolveLayoutChainMiddlewares<RouteLayoutChain<Path, TMethod>>, Field> & MergeMiddlewareField<Acc, Field>;
|
|
60
61
|
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
|
|
62
|
+
type UnitRuntimeContext = Omit<RuntimeContextFields, "var">;
|
|
62
63
|
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
64
|
query: Simplify<MergePart<TQuery, RouteChainField<Path, TMethod, Acc, "query">>>;
|
|
64
|
-
params: Simplify<PathParams<Path
|
|
65
|
+
params: Simplify<ResolveParams<PathParams<Path>, MergePart<TParams, RouteChainField<Path, TMethod, Acc, "params">>>>;
|
|
65
66
|
body: Simplify<MergePart<TBody, RouteChainField<Path, TMethod, Acc, "body">>>;
|
|
66
67
|
state: Simplify<RouteChainField<Path, TMethod, Acc, "state">>;
|
|
67
68
|
headers: TaserHeaders;
|
|
@@ -77,9 +78,9 @@ export type RouteHandleContext<Path extends RoutePath, TMethod extends Method, A
|
|
|
77
78
|
query: Simplify<MergePart<Validators extends {
|
|
78
79
|
query?: infer Q;
|
|
79
80
|
} ? Q : unknown, RouteResolvedField<Path, TMethod, Acc, "query">>>;
|
|
80
|
-
params: Simplify<PathParams<Path
|
|
81
|
+
params: Simplify<ResolveParams<PathParams<Path>, MergePart<Validators extends {
|
|
81
82
|
params?: infer P;
|
|
82
|
-
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params"
|
|
83
|
+
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params">>>>;
|
|
83
84
|
body: Simplify<MergePart<Validators extends {
|
|
84
85
|
body?: infer B;
|
|
85
86
|
} ? B : unknown, RouteResolvedField<Path, TMethod, Acc, "body">>>;
|
|
@@ -96,9 +97,9 @@ export type RouteHandleContextWithoutBody<Path extends RoutePath, TMethod extend
|
|
|
96
97
|
query: Simplify<MergePart<Validators extends {
|
|
97
98
|
query?: infer Q;
|
|
98
99
|
} ? Q : unknown, RouteResolvedField<Path, TMethod, Acc, "query">>>;
|
|
99
|
-
params: Simplify<PathParams<Path
|
|
100
|
+
params: Simplify<ResolveParams<PathParams<Path>, MergePart<Validators extends {
|
|
100
101
|
params?: infer P;
|
|
101
|
-
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params"
|
|
102
|
+
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params">>>>;
|
|
102
103
|
body: never;
|
|
103
104
|
state: Simplify<RouteResolvedField<Path, TMethod, Acc, "state">>;
|
|
104
105
|
headers: TaserHeaders;
|
|
@@ -119,11 +120,11 @@ type RouteQueryInput<Path extends RoutePath, TMethod extends Method, Acc extends
|
|
|
119
120
|
} ? QI : unknown, Validators extends {
|
|
120
121
|
query?: infer Q;
|
|
121
122
|
} ? 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
|
|
123
|
+
type RouteParamsInput<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts> = Simplify<ResolveParams<PathParams<Path>, MergePart<RequestShape<Validators extends {
|
|
123
124
|
paramsIn?: infer PI;
|
|
124
125
|
} ? PI : unknown, Validators extends {
|
|
125
126
|
params?: infer P;
|
|
126
|
-
} ? P : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "params"
|
|
127
|
+
} ? P : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "params">>>>;
|
|
127
128
|
type RouteBodyInput<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts> = Simplify<MergePart<RequestShape<Validators extends {
|
|
128
129
|
bodyIn?: infer BI;
|
|
129
130
|
} ? BI : unknown, Validators extends {
|
|
@@ -131,7 +132,7 @@ type RouteBodyInput<Path extends RoutePath, TMethod extends Method, Acc extends
|
|
|
131
132
|
} ? B : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "body">>>;
|
|
132
133
|
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
134
|
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
|
|
135
|
+
export type InferRouteInputFromPath<Path extends RoutePath, TMethod extends Method> = RouteEntry<Path, TMethod> extends {
|
|
135
136
|
route: infer Route;
|
|
136
137
|
} ? Route extends {
|
|
137
138
|
$Infer: {
|
|
@@ -180,7 +181,7 @@ export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc exte
|
|
|
180
181
|
handler: (ctx: unknown) => Awaitable<Response>;
|
|
181
182
|
readonly $Infer: {
|
|
182
183
|
Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleContextWithoutBody<Path, TMethod, Acc, {}> : RouteHandleContext<Path, TMethod, Acc, {}>;
|
|
183
|
-
|
|
184
|
+
Input: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleInputWithoutBody<Path, TMethod, Acc, {}> : RouteHandleInput<Path, TMethod, Acc, {}>;
|
|
184
185
|
Output: TOutput;
|
|
185
186
|
};
|
|
186
187
|
query?: Schema<unknown>;
|
|
@@ -202,6 +203,8 @@ export type RouteBuilder<Path extends RoutePath, TMethod extends Method, Acc ext
|
|
|
202
203
|
readonly method: TMethod;
|
|
203
204
|
readonly $Infer: {
|
|
204
205
|
Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleContextWithoutBody<Path, TMethod, Acc, Validators, TAppContext> : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>;
|
|
206
|
+
Input: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleInputWithoutBody<Path, TMethod, Acc, Validators> : RouteHandleInput<Path, TMethod, Acc, Validators>;
|
|
207
|
+
Output: TReturns;
|
|
205
208
|
};
|
|
206
209
|
returns<const M extends ReturnsMap>(map: M): RouteBuilder<Path, TMethod, Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>;
|
|
207
210
|
use<TAcc, UReturns extends ReturnsMap = {}, TRequiredLayouts = unknown, TRequiredState = unknown>(unit: MiddlewareUnit<TAcc, UReturns, TRequiredLayouts, TRequiredState>, ..._assert: [
|
|
@@ -254,3 +257,19 @@ export type HandlerBuilder<Acc extends readonly unknown[] = readonly [], Validat
|
|
|
254
257
|
}
|
|
255
258
|
]): HandlerUnit<Acc, Validators, TReturns, R>;
|
|
256
259
|
};
|
|
260
|
+
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>;
|
|
261
|
+
export type InferRouteContext<R> = R extends {
|
|
262
|
+
$Infer: {
|
|
263
|
+
Context: infer C;
|
|
264
|
+
};
|
|
265
|
+
} ? C : never;
|
|
266
|
+
export type InferRouteInput<R> = R extends {
|
|
267
|
+
$Infer: {
|
|
268
|
+
Input: infer I;
|
|
269
|
+
};
|
|
270
|
+
} ? I : never;
|
|
271
|
+
export type InferRouteOutput<R> = R extends {
|
|
272
|
+
$Infer: {
|
|
273
|
+
Output: infer O;
|
|
274
|
+
};
|
|
275
|
+
} ? O : never;
|
|
@@ -13,7 +13,7 @@ export type ReturnsMap = {
|
|
|
13
13
|
/** Later map wins on overlapping status keys. */
|
|
14
14
|
export type MergeReturns<A extends ReturnsMap, B extends ReturnsMap> = Omit<A, keyof B> & B;
|
|
15
15
|
/** Typed reply union for statuses declared in a returns map. */
|
|
16
|
-
export type
|
|
16
|
+
export type ReplyFor<M extends ReturnsMap> = {
|
|
17
17
|
[S in keyof M]-?: S extends StatusCode ? M[S] extends Schema<unknown> ? ReplyOf<S, Simplify<InferOutput<M[S]>>> : never : never;
|
|
18
18
|
}[keyof M];
|
|
19
19
|
export type EmptyReturns = {};
|
|
@@ -34,4 +34,4 @@ export type EnforceHandlerReply<R, M extends ReturnsMap> = [R] extends [ValidHan
|
|
|
34
34
|
* Expected `.handler` return type for a returns map.
|
|
35
35
|
* Prefer constraining handler generics with {@link EnforceHandlerReply}.
|
|
36
36
|
*/
|
|
37
|
-
export type HandlerReply<M extends ReturnsMap> = HasReturns<M> extends true ?
|
|
37
|
+
export type HandlerReply<M extends ReturnsMap> = HasReturns<M> extends true ? ReplyFor<M> | Response : Response;
|
|
@@ -37,13 +37,12 @@ export type MiddlewareInputField<Middleware, Field extends MiddlewareInputFieldN
|
|
|
37
37
|
} ? V : {};
|
|
38
38
|
export type MergeMiddlewareField<Middlewares extends readonly unknown[], Field extends MiddlewareFieldName> = [Middlewares] extends [readonly []] ? {} : UnionToIntersection<MiddlewareField<Middlewares[number], Field>>;
|
|
39
39
|
export type MergeMiddlewareInputField<Middlewares extends readonly unknown[], Field extends MiddlewareInputFieldName> = [Middlewares] extends [readonly []] ? {} : UnionToIntersection<MiddlewareInputField<Middlewares[number], Field>>;
|
|
40
|
-
export type RuntimeContextFields
|
|
40
|
+
export type RuntimeContextFields = {
|
|
41
41
|
request: Request;
|
|
42
42
|
method: Method;
|
|
43
43
|
url: URL;
|
|
44
44
|
headers: import('@taserjs/router-core').TaserHeaders;
|
|
45
45
|
cookies: import('@taserjs/router-core').TaserCookieJar;
|
|
46
46
|
var: Record<string, unknown>;
|
|
47
|
-
native?: TNative;
|
|
48
47
|
};
|
|
49
48
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.cjs","names":[],"sources":["../../../src/types/units.ts"],"sourcesContent":["import type { Awaitable, TaserCookieJar, TaserHeaders } from \"@taserjs/router-core\";\
|
|
1
|
+
{"version":3,"file":"units.cjs","names":[],"sources":["../../../src/types/units.ts"],"sourcesContent":["import type { Awaitable, TaserCookieJar, TaserHeaders } from \"@taserjs/router-core\";\n\nimport type {\n MergeMiddlewareField,\n MergePart,\n RequestShape,\n RuntimeContextFields,\n Simplify,\n UnwrapPart,\n} from \"./type-utils.js\";\nimport type { ReturnsMap } from \"./returns.js\";\nimport type { Schema } from \"./schema.js\";\n\nexport type { HttpMethod, Method } from \"./type-utils.js\";\nexport type {\n EmptyReturns,\n MergeReturns,\n ReturnsMap,\n HandlerReply,\n HasReturns,\n StatusCode,\n ValidHandlerReply,\n EnforceHandlerReply,\n} from \"./returns.js\";\n\n/** Default empty app context for standalone units without a bound router instance. */\nexport type AppContext = Record<never, never>;\n\nexport type ValidatorParts = {\n query?: unknown;\n params?: unknown;\n body?: unknown;\n queryIn?: unknown;\n paramsIn?: unknown;\n bodyIn?: unknown;\n};\n\nexport declare const StateBrand: unique symbol;\n\nexport type NextResult<TState = unknown> = Response & {\n readonly [StateBrand]?: TState;\n};\n\nexport type ExtractState<T> = [Extract<Awaited<T>, { [StateBrand]?: unknown }>] extends [never]\n ? {}\n : Extract<Awaited<T>, { [StateBrand]?: unknown }> extends { [StateBrand]?: infer S }\n ? [S] extends [never]\n ? {}\n : S\n : {};\n\nexport type IsUnknown<T> = [unknown] extends [T] ? true : false;\n\nexport type NextFn<TExpectedState = unknown> =\n IsUnknown<TExpectedState> extends true\n ? <S extends Record<string, unknown> = {}>(state?: S) => Promise<NextResult<S>>\n : (state: TExpectedState) => Promise<NextResult<TExpectedState>>;\n\nexport type MiddlewareNext = NextFn;\n\nexport type MiddlewareDefinition = {\n query?: unknown;\n params?: unknown;\n body?: unknown;\n returns?: ReturnsMap;\n handler: (ctx: unknown, next: MiddlewareNext) => Awaitable<Response | unknown>;\n};\n\nexport type MiddlewareReturnFromParts<\n TQuery,\n TParams,\n TBody,\n TState,\n TQueryIn = TQuery,\n TParamsIn = TParams,\n TBodyIn = TBody,\n> = {\n query: Simplify<UnwrapPart<TQuery>>;\n params: Simplify<UnwrapPart<TParams>>;\n body: Simplify<UnwrapPart<TBody>>;\n state: Simplify<UnwrapPart<TState>>;\n /** Pre-parse shapes merged into route `$Infer.Input`. */\n input: {\n query: RequestShape<TQueryIn, TQuery>;\n params: RequestShape<TParamsIn, TParams>;\n body: RequestShape<TBodyIn, TBody>;\n };\n};\n\ntype UnitRuntimeContext = Omit<RuntimeContextFields, \"var\">;\n\nexport type StandaloneMiddlewareContext<\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TAppContext extends Record<string, unknown> = AppContext,\n TState = {},\n> = Simplify<\n TAppContext &\n UnitRuntimeContext & {\n query: Simplify<UnwrapPart<TQuery>>;\n params: Simplify<UnwrapPart<TParams>>;\n body: Simplify<UnwrapPart<TBody>>;\n state: Simplify<UnwrapPart<TState>>;\n headers: TaserHeaders;\n cookies: TaserCookieJar;\n }\n>;\n\nexport type HandlerContext<\n Acc extends readonly unknown[],\n Validators extends ValidatorParts,\n TAppContext extends Record<string, unknown> = AppContext,\n> = Simplify<\n TAppContext &\n UnitRuntimeContext & {\n query: Simplify<\n MergePart<\n Validators extends { query?: infer Q } ? Q : unknown,\n MergeMiddlewareField<Acc, \"query\">\n >\n >;\n params: Simplify<\n MergePart<\n Validators extends { params?: infer P } ? P : unknown,\n MergeMiddlewareField<Acc, \"params\">\n >\n >;\n body: Simplify<\n MergePart<\n Validators extends { body?: infer B } ? B : unknown,\n MergeMiddlewareField<Acc, \"body\">\n >\n >;\n state: Simplify<MergeMiddlewareField<Acc, \"state\">>;\n headers: TaserHeaders;\n cookies: TaserCookieJar;\n }\n>;\n\nexport type MiddlewareUnit<\n TAcc = unknown,\n TReturns extends ReturnsMap = {},\n TRequiredLayouts = unknown,\n TRequiredState = unknown,\n> = MiddlewareDefinition & {\n readonly __middlewareAcc: TAcc;\n readonly __returns?: TReturns;\n readonly __requiredLayouts?: TRequiredLayouts;\n readonly __requiredState?: TRequiredState;\n};\n\nexport type HandlerUnit<\n _Acc extends readonly unknown[],\n _Validators extends ValidatorParts,\n TReturns extends ReturnsMap = {},\n TOutput = Response,\n> = {\n readonly __returns?: TReturns;\n readonly $Infer: {\n Output: TOutput;\n };\n middlewares: readonly MiddlewareDefinition[];\n handler: (ctx: unknown) => Awaitable<Response>;\n returns?: ReturnsMap;\n query?: Schema<unknown>;\n params?: Schema<unknown>;\n body?: Schema<unknown>;\n};\n\nexport type InlineMiddlewareOptions<\n Ctx = unknown,\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TReturns extends ReturnsMap = {},\n TQueryIn = unknown,\n TParamsIn = unknown,\n TBodyIn = unknown,\n R = unknown,\n> = {\n query?: Schema<TQuery, TQueryIn>;\n params?: Schema<TParams, TParamsIn>;\n body?: Schema<TBody, TBodyIn>;\n returns?: TReturns;\n handler: (ctx: Ctx, next: NextFn) => Awaitable<R>;\n};\n\nexport function isHandlerUnit(\n value: unknown,\n): value is HandlerUnit<readonly unknown[], ValidatorParts> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"handler\" in value &&\n \"middlewares\" in value &&\n Array.isArray((value as HandlerUnit<readonly unknown[], ValidatorParts>).middlewares)\n );\n}\n"],"mappings":";AA4LA,SAAgB,cACd,OAC0D;CAC1D,OACE,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,iBAAiB,SACjB,MAAM,QAAS,MAA0D,WAAW;AAExF"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Awaitable, TaserCookieJar, TaserHeaders } from '@taserjs/router-core';
|
|
2
|
-
import { ReplyResult } from '@taserjs/router-utils';
|
|
3
|
-
import { RouterRegister } from '../register.js';
|
|
4
2
|
import { MergeMiddlewareField, MergePart, RequestShape, RuntimeContextFields, Simplify, UnwrapPart } from './type-utils.js';
|
|
5
3
|
import { ReturnsMap } from './returns.js';
|
|
6
4
|
import { Schema } from './schema.js';
|
|
@@ -8,9 +6,6 @@ export type { HttpMethod, Method } from './type-utils.js';
|
|
|
8
6
|
export type { EmptyReturns, MergeReturns, ReturnsMap, HandlerReply, HasReturns, StatusCode, ValidHandlerReply, EnforceHandlerReply, } from './returns.js';
|
|
9
7
|
/** Default empty app context for standalone units without a bound router instance. */
|
|
10
8
|
export type AppContext = Record<never, never>;
|
|
11
|
-
export type NativeContext = RouterRegister extends {
|
|
12
|
-
NativeContext: infer N;
|
|
13
|
-
} ? N : unknown;
|
|
14
9
|
export type ValidatorParts = {
|
|
15
10
|
query?: unknown;
|
|
16
11
|
params?: unknown;
|
|
@@ -20,7 +15,7 @@ export type ValidatorParts = {
|
|
|
20
15
|
bodyIn?: unknown;
|
|
21
16
|
};
|
|
22
17
|
export declare const StateBrand: unique symbol;
|
|
23
|
-
export type NextResult<TState = unknown> =
|
|
18
|
+
export type NextResult<TState = unknown> = Response & {
|
|
24
19
|
readonly [StateBrand]?: TState;
|
|
25
20
|
};
|
|
26
21
|
export type ExtractState<T> = [Extract<Awaited<T>, {
|
|
@@ -38,7 +33,7 @@ export type MiddlewareDefinition = {
|
|
|
38
33
|
params?: unknown;
|
|
39
34
|
body?: unknown;
|
|
40
35
|
returns?: ReturnsMap;
|
|
41
|
-
handler: (ctx: unknown, next: MiddlewareNext) => Awaitable<
|
|
36
|
+
handler: (ctx: unknown, next: MiddlewareNext) => Awaitable<Response | unknown>;
|
|
42
37
|
};
|
|
43
38
|
export type MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TQueryIn = TQuery, TParamsIn = TParams, TBodyIn = TBody> = {
|
|
44
39
|
query: Simplify<UnwrapPart<TQuery>>;
|
|
@@ -52,7 +47,7 @@ export type MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TQueryIn =
|
|
|
52
47
|
body: RequestShape<TBodyIn, TBody>;
|
|
53
48
|
};
|
|
54
49
|
};
|
|
55
|
-
type UnitRuntimeContext = Omit<RuntimeContextFields
|
|
50
|
+
type UnitRuntimeContext = Omit<RuntimeContextFields, "var">;
|
|
56
51
|
export type StandaloneMiddlewareContext<TQuery = unknown, TParams = unknown, TBody = unknown, TAppContext extends Record<string, unknown> = AppContext, TState = {}> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
57
52
|
query: Simplify<UnwrapPart<TQuery>>;
|
|
58
53
|
params: Simplify<UnwrapPart<TParams>>;
|
|
@@ -87,7 +82,7 @@ export type HandlerUnit<_Acc extends readonly unknown[], _Validators extends Val
|
|
|
87
82
|
Output: TOutput;
|
|
88
83
|
};
|
|
89
84
|
middlewares: readonly MiddlewareDefinition[];
|
|
90
|
-
handler: (ctx: unknown) => Awaitable<
|
|
85
|
+
handler: (ctx: unknown) => Awaitable<Response>;
|
|
91
86
|
returns?: ReturnsMap;
|
|
92
87
|
query?: Schema<unknown>;
|
|
93
88
|
params?: Schema<unknown>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RouteManifestShape, TaserRuntime } from '@taserjs/router-core';
|
|
2
|
+
declare class TaserServeView {
|
|
3
|
+
protected readonly runtime: TaserRuntime;
|
|
4
|
+
readonly fetch: (request: Request, env?: unknown, executionCtx?: unknown) => Promise<Response> | Response;
|
|
5
|
+
constructor(runtime: TaserRuntime);
|
|
6
|
+
}
|
|
7
|
+
export declare class TaserApp<TManifest extends RouteManifestShape = RouteManifestShape> extends TaserServeView {
|
|
8
|
+
readonly __manifest?: TManifest;
|
|
9
|
+
constructor(runtime: TaserRuntime, manifest?: TManifest);
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/builder/app.ts
|
|
2
|
+
var TaserServeView = class {
|
|
3
|
+
runtime;
|
|
4
|
+
fetch;
|
|
5
|
+
constructor(runtime) {
|
|
6
|
+
this.runtime = runtime;
|
|
7
|
+
this.fetch = (request, env, executionCtx) => {
|
|
8
|
+
return this.runtime.fetch(request, env, executionCtx);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var TaserApp = class extends TaserServeView {
|
|
13
|
+
__manifest;
|
|
14
|
+
constructor(runtime, manifest) {
|
|
15
|
+
super(runtime);
|
|
16
|
+
if (manifest !== void 0) this.__manifest = manifest;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { TaserApp };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","names":[],"sources":["../../../src/builder/app.ts"],"sourcesContent":["import type { RouteManifestShape, TaserRuntime } from \"@taserjs/router-core\";\n\nclass TaserServeView {\n readonly fetch: (\n request: Request,\n env?: unknown,\n executionCtx?: unknown,\n ) => Promise<Response> | Response;\n\n constructor(protected readonly runtime: TaserRuntime) {\n this.fetch = (request: Request, env?: unknown, executionCtx?: unknown) => {\n return this.runtime.fetch(request, env, executionCtx as never);\n };\n }\n}\n\nexport class TaserApp<\n TManifest extends RouteManifestShape = RouteManifestShape,\n> extends TaserServeView {\n readonly __manifest?: TManifest;\n\n constructor(runtime: TaserRuntime, manifest?: TManifest) {\n super(runtime);\n if (manifest !== undefined) {\n this.__manifest = manifest;\n }\n }\n}\n"],"mappings":";AAEA,IAAM,iBAAN,MAAqB;CAOY;CAN/B;CAMA,YAAY,SAA0C;EAAvB,KAAA,UAAA;EAC7B,KAAK,SAAS,SAAkB,KAAe,iBAA2B;GACxE,OAAO,KAAK,QAAQ,MAAM,SAAS,KAAK,YAAqB;EAC/D;CACF;AACF;AAEA,IAAa,WAAb,cAEU,eAAe;CACvB;CAEA,YAAY,SAAuB,UAAsB;EACvD,MAAM,OAAO;EACb,IAAI,aAAa,KAAA,GACf,KAAK,aAAa;CAEtB;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../../src/builder/constants.ts"],"sourcesContent":["/** Input schema keys validated by middleware and route handlers. Headers/cookies are parsed only. */\nexport const SCHEMA_KEYS = [\"query\", \"params\", \"body\"] as const;\n\nexport type SchemaKey = (typeof SCHEMA_KEYS)[number];\n\nexport const HANDLER_SCHEMA_KEY_MAP = {\n query: \"handlerQuery\",\n params: \"handlerParams\",\n body: \"handlerBody\",\n} as const satisfies Record<SchemaKey, string>;\n"],"mappings":";;AACA,IAAa,cAAc;CAAC;CAAS;CAAU;AAAM;AAIrD,IAAa,yBAAyB;CACpC,OAAO;CACP,QAAQ;CACR,MAAM;AACR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RouteBuilder, RoutePath, Schema } from '
|
|
2
|
-
import { AppContext, HttpMethod } from '
|
|
1
|
+
import { RouteBuilder, RoutePath, Schema } from '../types/index.js';
|
|
2
|
+
import { AppContext, HttpMethod } from '../types/units.js';
|
|
3
3
|
type WithoutBodyOptions<TQuery, TParams, TQueryIn = unknown, TParamsIn = unknown> = {
|
|
4
4
|
query?: Schema<TQuery, TQueryIn>;
|
|
5
5
|
params?: Schema<TParams, TParamsIn>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factories.js","names":[],"sources":["../../../src/builder/factories.ts"],"sourcesContent":["import { createRouteBuilder } from \"./route.js\";\nimport type { RouteBuilder, RoutePath, Schema } from \"../types/index.js\";\nimport type { AppContext, HttpMethod } from \"../types/units.js\";\n\ntype WithoutBodyOptions<TQuery, TParams, TQueryIn = unknown, TParamsIn = unknown> = {\n query?: Schema<TQuery, TQueryIn>;\n params?: Schema<TParams, TParamsIn>;\n};\n\ntype WithBodyOptions<\n TQuery,\n TParams,\n TBody,\n TQueryIn = unknown,\n TParamsIn = unknown,\n TBodyIn = unknown,\n> = WithoutBodyOptions<TQuery, TParams, TQueryIn, TParamsIn> & {\n body?: Schema<TBody, TBodyIn>;\n};\n\nexport type CreateWithoutBodyRoute<\n M extends \"GET\" | \"DELETE\" | \"OPTIONS\" | \"HEAD\",\n TAppContext extends Record<string, unknown> = AppContext,\n> = {\n <const Path extends RoutePath>(\n path: Path,\n ): RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;\n <\n const Path extends RoutePath,\n TQuery = unknown,\n TParams = unknown,\n TQueryIn = unknown,\n TParamsIn = unknown,\n >(\n path: Path,\n options: WithoutBodyOptions<TQuery, TParams, TQueryIn, TParamsIn>,\n ): RouteBuilder<\n Path,\n M,\n readonly [],\n {\n query: TQuery;\n params: TParams;\n queryIn: TQueryIn;\n paramsIn: TParamsIn;\n },\n {},\n TAppContext\n >;\n};\n\nexport type CreateWithBodyRoute<\n M extends \"POST\" | \"PUT\" | \"PATCH\",\n TAppContext extends Record<string, unknown> = AppContext,\n> = {\n <const Path extends RoutePath>(\n path: Path,\n ): RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;\n <\n const Path extends RoutePath,\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TQueryIn = unknown,\n TParamsIn = unknown,\n TBodyIn = unknown,\n >(\n path: Path,\n options: WithBodyOptions<TQuery, TParams, TBody, TQueryIn, TParamsIn, TBodyIn>,\n ): RouteBuilder<\n Path,\n M,\n readonly [],\n {\n query: TQuery;\n params: TParams;\n body: TBody;\n queryIn: TQueryIn;\n paramsIn: TParamsIn;\n bodyIn: TBodyIn;\n },\n {},\n TAppContext\n >;\n};\n\nexport type CreateAnyRoute<TAppContext extends Record<string, unknown> = AppContext> = {\n <const Path extends RoutePath, const Methods extends readonly HttpMethod[]>(\n path: Path,\n methods: Methods,\n ): RouteBuilder<Path, Methods[number], readonly [], {}, {}, TAppContext>;\n <\n const Path extends RoutePath,\n const Methods extends readonly HttpMethod[],\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TQueryIn = unknown,\n TParamsIn = unknown,\n TBodyIn = unknown,\n >(\n path: Path,\n methods: Methods,\n options: WithBodyOptions<TQuery, TParams, TBody, TQueryIn, TParamsIn, TBodyIn>,\n ): RouteBuilder<\n Path,\n Methods[number],\n readonly [],\n {\n query: TQuery;\n params: TParams;\n body: TBody;\n queryIn: TQueryIn;\n paramsIn: TParamsIn;\n bodyIn: TBodyIn;\n },\n {},\n TAppContext\n >;\n};\n\nexport type CreateAllRoute<TAppContext extends Record<string, unknown> = AppContext> = {\n <const Path extends RoutePath>(\n path: Path,\n ): RouteBuilder<Path, HttpMethod, readonly [], {}, {}, TAppContext>;\n <\n const Path extends RoutePath,\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TQueryIn = unknown,\n TParamsIn = unknown,\n TBodyIn = unknown,\n >(\n path: Path,\n options: WithBodyOptions<TQuery, TParams, TBody, TQueryIn, TParamsIn, TBodyIn>,\n ): RouteBuilder<\n Path,\n HttpMethod,\n readonly [],\n {\n query: TQuery;\n params: TParams;\n body: TBody;\n queryIn: TQueryIn;\n paramsIn: TParamsIn;\n bodyIn: TBodyIn;\n },\n {},\n TAppContext\n >;\n};\n\nfunction createWithoutBodyRoute<M extends \"GET\" | \"DELETE\" | \"OPTIONS\" | \"HEAD\">(\n method: M,\n): CreateWithoutBodyRoute<M> {\n return ((path: string, options?: WithoutBodyOptions<unknown, unknown>) =>\n createRouteBuilder(path, method, options)) as unknown as CreateWithoutBodyRoute<M>;\n}\n\nfunction createWithBodyRoute<M extends \"POST\" | \"PUT\" | \"PATCH\">(\n method: M,\n): CreateWithBodyRoute<M> {\n return ((path: string, options?: WithBodyOptions<unknown, unknown, unknown>) =>\n createRouteBuilder(path, method, options)) 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 = ((\n path: string,\n methods: readonly HttpMethod[],\n options?: WithBodyOptions<unknown, unknown, unknown>,\n) => createRouteBuilder(path, \"ANY\", options, methods)) as unknown as CreateAnyRoute;\n\nexport const createAllRoute: CreateAllRoute = ((\n path: string,\n options?: WithBodyOptions<unknown, unknown, unknown>,\n) => createRouteBuilder(path, \"ALL\", options)) as unknown as CreateAllRoute;\n"],"mappings":";;AAyJA,SAAS,uBACP,QAC2B;CAC3B,SAAS,MAAc,YACrB,mBAAmB,MAAM,QAAQ,OAAO;AAC5C;AAEA,SAAS,oBACP,QACwB;CACxB,SAAS,MAAc,YACrB,mBAAmB,MAAM,QAAQ,OAAO;AAC5C;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,mBACX,MACA,SACA,YACG,mBAAmB,MAAM,OAAO,SAAS,OAAO;AAErD,IAAa,mBACX,MACA,YACG,mBAAmB,MAAM,OAAO,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { LayoutId, MiddlewareBuilder } from '
|
|
1
|
+
import { LayoutId, MiddlewareBuilder } from '../types/index.js';
|
|
2
2
|
export declare function createMiddleware<const Layout extends LayoutId>(layout: Layout): MiddlewareBuilder<Layout, readonly []>;
|
|
@@ -0,0 +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) {\n entries.push(definition);\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,YAAkC;GACpC,QAAQ,KAAK,UAAU;GACvB,OAAO;EACT;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Method, RouteBuilder, RoutePath, ValidatorParts } from '
|
|
2
|
-
import { HttpMethod } from '
|
|
3
|
-
import { SchemaValidators } from '
|
|
1
|
+
import { Method, RouteBuilder, RoutePath, ValidatorParts } from '../types/index.js';
|
|
2
|
+
import { HttpMethod } from '../types/units.js';
|
|
3
|
+
import { SchemaValidators } from '../define/validators.js';
|
|
4
4
|
/** Shared internal builder — not part of the public `@taserjs/router` API. */
|
|
5
5
|
export declare function createRouteBuilder(path: string, method: HttpMethod | "ANY" | "ALL", validators?: SchemaValidators, methods?: readonly HttpMethod[]): RouteBuilder<RoutePath, Method, readonly [], ValidatorParts>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isHandlerUnit } from "
|
|
1
|
+
import { isHandlerUnit } from "../types/units.js";
|
|
2
2
|
import { HANDLER_SCHEMA_KEY_MAP } from "./constants.js";
|
|
3
|
-
import { pickDefinedSchemas } from "
|
|
3
|
+
import { pickDefinedSchemas } from "../define/validators.js";
|
|
4
4
|
import { collectReturnsFromDefinitions, hasInputSchemas, mergeReturnsMaps, withAuto422 } from "@taserjs/router-utils";
|
|
5
|
-
//#region src/route.ts
|
|
5
|
+
//#region src/builder/route.ts
|
|
6
6
|
function toUtilsMap(map) {
|
|
7
7
|
if (!map) return {};
|
|
8
8
|
const out = {};
|
|
@@ -42,46 +42,32 @@ function createRouteBuilder(path, method, validators = {}, methods) {
|
|
|
42
42
|
handler(fnOrUnit) {
|
|
43
43
|
const routeSchemas = pickDefinedSchemas(validators);
|
|
44
44
|
const base = buildRouteBase(path, method, methods, middlewares);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
handlerReturns: fnOrUnit.returns,
|
|
52
|
-
schemas: {
|
|
53
|
-
...validators,
|
|
54
|
-
handlerQuery: fnOrUnit.query,
|
|
55
|
-
handlerParams: fnOrUnit.params,
|
|
56
|
-
handlerBody: fnOrUnit.body,
|
|
57
|
-
middlewares,
|
|
58
|
-
handlerMiddlewares: fnOrUnit.middlewares
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return {
|
|
62
|
-
...base,
|
|
63
|
-
handlerMiddlewares: [...fnOrUnit.middlewares],
|
|
64
|
-
handler: fnOrUnit.handler,
|
|
65
|
-
...routeSchemas,
|
|
66
|
-
...handlerSchemas,
|
|
67
|
-
...returns ? { returns } : {}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
45
|
+
const unit = isHandlerUnit(fnOrUnit) ? fnOrUnit : {
|
|
46
|
+
handler: fnOrUnit,
|
|
47
|
+
middlewares: [],
|
|
48
|
+
returns: void 0
|
|
49
|
+
};
|
|
50
|
+
const handlerSchemas = isHandlerUnit(fnOrUnit) ? pickDefinedSchemas(fnOrUnit, HANDLER_SCHEMA_KEY_MAP) : {};
|
|
70
51
|
const returns = buildEffectiveReturns({
|
|
71
52
|
middlewareReturns: collectReturnsFromDefinitions(middlewares),
|
|
72
53
|
routeReturns,
|
|
73
|
-
handlerMiddlewareReturns:
|
|
74
|
-
handlerReturns:
|
|
54
|
+
handlerMiddlewareReturns: collectReturnsFromDefinitions(unit.middlewares),
|
|
55
|
+
handlerReturns: unit.returns,
|
|
75
56
|
schemas: {
|
|
76
57
|
...validators,
|
|
77
|
-
|
|
58
|
+
handlerQuery: unit.query,
|
|
59
|
+
handlerParams: unit.params,
|
|
60
|
+
handlerBody: unit.body,
|
|
61
|
+
middlewares,
|
|
62
|
+
handlerMiddlewares: unit.middlewares
|
|
78
63
|
}
|
|
79
64
|
});
|
|
80
65
|
return {
|
|
81
66
|
...base,
|
|
82
|
-
handlerMiddlewares: [],
|
|
83
|
-
handler:
|
|
67
|
+
handlerMiddlewares: [...unit.middlewares],
|
|
68
|
+
handler: unit.handler,
|
|
84
69
|
...routeSchemas,
|
|
70
|
+
...handlerSchemas,
|
|
85
71
|
...returns ? { returns } : {}
|
|
86
72
|
};
|
|
87
73
|
}
|