@taserjs/router 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/app.cjs +27 -0
- package/dist/cjs/builder/app.cjs.map +1 -0
- package/dist/cjs/builder/app.d.cts +11 -0
- package/dist/cjs/{constants.cjs → builder/constants.cjs} +1 -1
- package/dist/cjs/builder/constants.cjs.map +1 -0
- package/dist/cjs/{factories.cjs → builder/factories.cjs} +5 -5
- package/dist/cjs/builder/factories.cjs.map +1 -0
- package/dist/cjs/builder/factories.d.cts +15 -0
- package/dist/cjs/{middleware.cjs → builder/middleware.cjs} +1 -1
- package/dist/cjs/builder/middleware.cjs.map +1 -0
- package/dist/cjs/{middleware.d.cts → builder/middleware.d.cts} +1 -1
- package/dist/cjs/{route.cjs → builder/route.cjs} +41 -34
- package/dist/cjs/builder/route.cjs.map +1 -0
- package/dist/cjs/builder/route.d.cts +4 -0
- package/dist/cjs/{taser-router.cjs → builder/router.cjs} +38 -13
- package/dist/cjs/builder/router.cjs.map +1 -0
- package/dist/{esm/taser-router.d.ts → cjs/builder/router.d.cts} +16 -11
- package/dist/cjs/{create-context.cjs → context/create-context.cjs} +1 -1
- package/dist/cjs/context/create-context.cjs.map +1 -0
- package/dist/cjs/{create-context.d.cts → context/create-context.d.cts} +2 -2
- package/dist/cjs/define/middleware.cjs +2 -2
- package/dist/cjs/define/middleware.cjs.map +1 -1
- package/dist/cjs/define/middleware.d.cts +10 -8
- package/dist/cjs/define/validators.cjs +1 -1
- package/dist/cjs/define/validators.cjs.map +1 -1
- package/dist/cjs/define/validators.d.cts +1 -1
- package/dist/cjs/index.cjs +6 -28
- package/dist/cjs/index.d.cts +7 -8
- package/dist/cjs/middleware/body-limit.cjs +2 -2
- package/dist/cjs/middleware/body-limit.cjs.map +1 -1
- package/dist/cjs/middleware/compress.cjs +2 -2
- package/dist/cjs/middleware/compress.cjs.map +1 -1
- package/dist/cjs/middleware/cors.cjs +2 -2
- package/dist/cjs/middleware/cors.cjs.map +1 -1
- package/dist/cjs/middleware/csrf.cjs +2 -2
- package/dist/cjs/middleware/csrf.cjs.map +1 -1
- package/dist/cjs/middleware/etag.cjs +2 -2
- package/dist/cjs/middleware/etag.cjs.map +1 -1
- package/dist/cjs/middleware/jwk.cjs +2 -8
- package/dist/cjs/middleware/jwk.cjs.map +1 -1
- package/dist/cjs/middleware/jwt.cjs +2 -8
- package/dist/cjs/middleware/jwt.cjs.map +1 -1
- package/dist/cjs/middleware/secure-headers.cjs +2 -2
- package/dist/cjs/middleware/secure-headers.cjs.map +1 -1
- package/dist/cjs/middleware/timing.cjs +2 -2
- package/dist/cjs/middleware/timing.cjs.map +1 -1
- package/dist/cjs/middleware/wrap-hono.cjs +10 -0
- package/dist/cjs/middleware/wrap-hono.cjs.map +1 -1
- package/dist/cjs/middleware/wrap-hono.d.cts +4 -0
- package/dist/cjs/reply.cjs +8 -19
- package/dist/cjs/reply.d.cts +1 -2
- package/dist/cjs/stream.cjs +8 -31
- package/dist/cjs/stream.d.cts +1 -1
- package/dist/cjs/types/app.d.cts +8 -26
- package/dist/cjs/types/index.d.cts +60 -19
- package/dist/cjs/types/returns.d.cts +8 -11
- package/dist/cjs/types/type-utils.d.cts +8 -7
- package/dist/cjs/types/units.cjs.map +1 -1
- package/dist/cjs/types/units.d.cts +6 -17
- package/dist/esm/builder/app.d.ts +11 -0
- package/dist/esm/builder/app.js +26 -0
- package/dist/esm/builder/app.js.map +1 -0
- package/dist/esm/{constants.js → builder/constants.js} +1 -1
- package/dist/esm/builder/constants.js.map +1 -0
- package/dist/esm/builder/factories.d.ts +15 -0
- package/dist/esm/{factories.js → builder/factories.js} +5 -5
- package/dist/esm/builder/factories.js.map +1 -0
- package/dist/esm/{middleware.d.ts → builder/middleware.d.ts} +1 -1
- package/dist/esm/{middleware.js → builder/middleware.js} +1 -1
- package/dist/esm/builder/middleware.js.map +1 -0
- package/dist/esm/builder/route.d.ts +4 -0
- package/dist/esm/{route.js → builder/route.js} +41 -34
- package/dist/esm/builder/route.js.map +1 -0
- package/dist/{cjs/taser-router.d.cts → esm/builder/router.d.ts} +16 -11
- package/dist/esm/{taser-router.js → builder/router.js} +37 -12
- package/dist/esm/builder/router.js.map +1 -0
- package/dist/esm/{create-context.d.ts → context/create-context.d.ts} +2 -2
- package/dist/esm/{create-context.js → context/create-context.js} +1 -1
- package/dist/esm/context/create-context.js.map +1 -0
- package/dist/esm/define/middleware.d.ts +10 -8
- package/dist/esm/define/middleware.js +2 -2
- package/dist/esm/define/middleware.js.map +1 -1
- package/dist/esm/define/validators.d.ts +1 -1
- package/dist/esm/define/validators.js +1 -1
- package/dist/esm/define/validators.js.map +1 -1
- package/dist/esm/index.d.ts +7 -8
- package/dist/esm/index.js +5 -6
- package/dist/esm/middleware/body-limit.js +2 -2
- package/dist/esm/middleware/body-limit.js.map +1 -1
- package/dist/esm/middleware/compress.js +2 -2
- package/dist/esm/middleware/compress.js.map +1 -1
- package/dist/esm/middleware/cors.js +2 -2
- package/dist/esm/middleware/cors.js.map +1 -1
- package/dist/esm/middleware/csrf.js +2 -2
- package/dist/esm/middleware/csrf.js.map +1 -1
- package/dist/esm/middleware/etag.js +2 -2
- package/dist/esm/middleware/etag.js.map +1 -1
- package/dist/esm/middleware/jwk.js +2 -8
- package/dist/esm/middleware/jwk.js.map +1 -1
- package/dist/esm/middleware/jwt.js +2 -8
- package/dist/esm/middleware/jwt.js.map +1 -1
- package/dist/esm/middleware/secure-headers.js +2 -2
- package/dist/esm/middleware/secure-headers.js.map +1 -1
- package/dist/esm/middleware/timing.js +2 -2
- package/dist/esm/middleware/timing.js.map +1 -1
- package/dist/esm/middleware/wrap-hono.d.ts +4 -0
- package/dist/esm/middleware/wrap-hono.js +10 -1
- package/dist/esm/middleware/wrap-hono.js.map +1 -1
- package/dist/esm/reply.d.ts +1 -2
- package/dist/esm/reply.js +1 -2
- package/dist/esm/stream.d.ts +1 -1
- package/dist/esm/stream.js +1 -2
- package/dist/esm/types/app.d.ts +8 -26
- package/dist/esm/types/index.d.ts +60 -19
- package/dist/esm/types/returns.d.ts +8 -11
- package/dist/esm/types/type-utils.d.ts +8 -7
- package/dist/esm/types/units.d.ts +6 -17
- package/dist/esm/types/units.js.map +1 -1
- package/package.json +3 -3
- package/src/builder/app.ts +39 -0
- package/src/builder/factories.ts +58 -0
- package/src/{middleware.ts → builder/middleware.ts} +2 -2
- package/src/{route.ts → builder/route.ts} +55 -35
- package/src/{taser-router.ts → builder/router.ts} +77 -28
- package/src/{create-context.ts → context/create-context.ts} +2 -2
- package/src/define/middleware.ts +115 -123
- package/src/define/validators.ts +1 -1
- package/src/index.ts +13 -20
- package/src/middleware/body-limit.ts +2 -2
- package/src/middleware/compress.ts +2 -2
- package/src/middleware/cors.ts +2 -2
- package/src/middleware/csrf.ts +2 -2
- package/src/middleware/etag.ts +2 -2
- package/src/middleware/jwk.ts +2 -7
- package/src/middleware/jwt.ts +2 -7
- package/src/middleware/secure-headers.ts +2 -2
- package/src/middleware/timing.ts +2 -2
- package/src/middleware/wrap-hono.ts +13 -0
- package/src/reply.ts +1 -11
- package/src/stream.ts +1 -1
- package/src/types/app.ts +13 -28
- package/src/types/index.ts +126 -22
- package/src/types/returns.ts +9 -78
- package/src/types/type-utils.ts +10 -6
- package/src/types/units.ts +36 -16
- package/dist/cjs/constants.cjs.map +0 -1
- package/dist/cjs/create-context.cjs.map +0 -1
- package/dist/cjs/factories.cjs.map +0 -1
- package/dist/cjs/factories.d.cts +0 -61
- package/dist/cjs/middleware.cjs.map +0 -1
- package/dist/cjs/route.cjs.map +0 -1
- package/dist/cjs/route.d.cts +0 -5
- package/dist/cjs/taser-app.cjs +0 -36
- package/dist/cjs/taser-app.cjs.map +0 -1
- package/dist/cjs/taser-app.d.cts +0 -18
- package/dist/cjs/taser-router.cjs.map +0 -1
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/create-context.js.map +0 -1
- package/dist/esm/factories.d.ts +0 -61
- package/dist/esm/factories.js.map +0 -1
- package/dist/esm/middleware.js.map +0 -1
- package/dist/esm/route.d.ts +0 -5
- package/dist/esm/route.js.map +0 -1
- package/dist/esm/taser-app.d.ts +0 -18
- package/dist/esm/taser-app.js +0 -35
- package/dist/esm/taser-app.js.map +0 -1
- package/dist/esm/taser-router.js.map +0 -1
- package/src/factories.ts +0 -185
- package/src/taser-app.ts +0 -38
- /package/dist/cjs/{constants.d.cts → builder/constants.d.cts} +0 -0
- /package/dist/esm/{constants.d.ts → builder/constants.d.ts} +0 -0
- /package/src/{constants.ts → builder/constants.ts} +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/builder/app.ts
|
|
2
|
+
var TaserServeView = class {
|
|
3
|
+
runtime;
|
|
4
|
+
fetch;
|
|
5
|
+
request;
|
|
6
|
+
constructor(runtime) {
|
|
7
|
+
this.runtime = runtime;
|
|
8
|
+
this.fetch = (request, env, executionCtx) => {
|
|
9
|
+
return this.runtime.fetch(request, env, executionCtx);
|
|
10
|
+
};
|
|
11
|
+
this.request = (path, init) => {
|
|
12
|
+
return this.runtime.request(path, init);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var TaserApp = class extends TaserServeView {
|
|
17
|
+
__manifest;
|
|
18
|
+
constructor(runtime, manifest) {
|
|
19
|
+
super(runtime);
|
|
20
|
+
if (manifest !== void 0) this.__manifest = manifest;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.TaserApp = TaserApp;
|
|
25
|
+
exports.TaserServeView = TaserServeView;
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=app.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.cjs","names":[],"sources":["../../../src/builder/app.ts"],"sourcesContent":["import type { RouteManifestShape, TaserRuntime } from \"@taserjs/router-core\";\n\nexport class TaserServeView<THasNotFound extends boolean = boolean> {\n readonly fetch: (\n request: Request,\n env?: unknown,\n executionCtx?: unknown,\n ) => THasNotFound extends true\n ? Promise<Response> | Response\n : Promise<Response | undefined> | Response | undefined;\n\n readonly request: (\n path: string,\n init?: RequestInit,\n ) => THasNotFound extends true ? Promise<Response> : Promise<Response | undefined>;\n\n constructor(protected readonly runtime: TaserRuntime<THasNotFound>) {\n this.fetch = (request: Request, env?: unknown, executionCtx?: unknown) => {\n return this.runtime.fetch(request, env, executionCtx as never);\n };\n this.request = (path: string, init?: RequestInit) => {\n return this.runtime.request(path, init);\n };\n }\n}\n\nexport class TaserApp<\n TManifest extends RouteManifestShape = RouteManifestShape,\n THasNotFound extends boolean = boolean,\n> extends TaserServeView<THasNotFound> {\n readonly __manifest?: TManifest;\n\n constructor(runtime: TaserRuntime<THasNotFound>, manifest?: TManifest) {\n super(runtime);\n if (manifest !== undefined) {\n this.__manifest = manifest;\n }\n }\n}\n"],"mappings":";AAEA,IAAa,iBAAb,MAAoE;CAcnC;CAb/B;CAQA;CAKA,YAAY,SAAwD;EAArC,KAAA,UAAA;EAC7B,KAAK,SAAS,SAAkB,KAAe,iBAA2B;GACxE,OAAO,KAAK,QAAQ,MAAM,SAAS,KAAK,YAAqB;EAC/D;EACA,KAAK,WAAW,MAAc,SAAuB;GACnD,OAAO,KAAK,QAAQ,QAAQ,MAAM,IAAI;EACxC;CACF;AACF;AAEA,IAAa,WAAb,cAGU,eAA6B;CACrC;CAEA,YAAY,SAAqC,UAAsB;EACrE,MAAM,OAAO;EACb,IAAI,aAAa,KAAA,GACf,KAAK,aAAa;CAEtB;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RouteManifestShape, TaserRuntime } from '@taserjs/router-core';
|
|
2
|
+
export declare class TaserServeView<THasNotFound extends boolean = boolean> {
|
|
3
|
+
protected readonly runtime: TaserRuntime<THasNotFound>;
|
|
4
|
+
readonly fetch: (request: Request, env?: unknown, executionCtx?: unknown) => THasNotFound extends true ? Promise<Response> | Response : Promise<Response | undefined> | Response | undefined;
|
|
5
|
+
readonly request: (path: string, init?: RequestInit) => THasNotFound extends true ? Promise<Response> : Promise<Response | undefined>;
|
|
6
|
+
constructor(runtime: TaserRuntime<THasNotFound>);
|
|
7
|
+
}
|
|
8
|
+
export declare class TaserApp<TManifest extends RouteManifestShape = RouteManifestShape, THasNotFound extends boolean = boolean> extends TaserServeView<THasNotFound> {
|
|
9
|
+
readonly __manifest?: TManifest;
|
|
10
|
+
constructor(runtime: TaserRuntime<THasNotFound>, manifest?: TManifest);
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","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,10 +1,10 @@
|
|
|
1
1
|
const require_route = require("./route.cjs");
|
|
2
|
-
//#region src/factories.ts
|
|
2
|
+
//#region src/builder/factories.ts
|
|
3
3
|
function createWithoutBodyRoute(method) {
|
|
4
|
-
return ((path
|
|
4
|
+
return ((path) => require_route.createRouteBuilder(path, method));
|
|
5
5
|
}
|
|
6
6
|
function createWithBodyRoute(method) {
|
|
7
|
-
return ((path
|
|
7
|
+
return ((path) => require_route.createRouteBuilder(path, method));
|
|
8
8
|
}
|
|
9
9
|
var createGetRoute = createWithoutBodyRoute("GET");
|
|
10
10
|
var createDeleteRoute = createWithoutBodyRoute("DELETE");
|
|
@@ -13,8 +13,8 @@ var createHeadRoute = createWithoutBodyRoute("HEAD");
|
|
|
13
13
|
var createPostRoute = createWithBodyRoute("POST");
|
|
14
14
|
var createPutRoute = createWithBodyRoute("PUT");
|
|
15
15
|
var createPatchRoute = createWithBodyRoute("PATCH");
|
|
16
|
-
var createAnyRoute = ((path, methods
|
|
17
|
-
var createAllRoute = ((path
|
|
16
|
+
var createAnyRoute = ((path, methods) => require_route.createRouteBuilder(path, "ANY", methods));
|
|
17
|
+
var createAllRoute = ((path) => require_route.createRouteBuilder(path, "ALL"));
|
|
18
18
|
//#endregion
|
|
19
19
|
exports.createAllRoute = createAllRoute;
|
|
20
20
|
exports.createAnyRoute = createAnyRoute;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factories.cjs","names":[],"sources":["../../../src/builder/factories.ts"],"sourcesContent":["import { createRouteBuilder } from \"./route.js\";\nimport type { RouteBuilder, RoutePath } from \"../types/index.js\";\nimport type { AppContext, 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,cAAA,mBAAmB,MAAM,MAAM;AACnC;AAEA,SAAS,oBACP,QACwB;CACxB,SAAS,SAAiB,cAAA,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,cAAA,mBAAmB,MAAM,OAAO,OAAO;AAEzC,IAAa,mBAAmC,SAC9C,cAAA,mBAAmB,MAAM,KAAK"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RouteBuilder, RoutePath } from '../types/index.js';
|
|
2
|
+
import { AppContext, HttpMethod } from '../types/units.js';
|
|
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
|
+
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
|
+
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
|
+
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", AppContext>;
|
|
8
|
+
export declare const createDeleteRoute: CreateWithoutBodyRoute<"DELETE", AppContext>;
|
|
9
|
+
export declare const createOptionsRoute: CreateWithoutBodyRoute<"OPTIONS", AppContext>;
|
|
10
|
+
export declare const createHeadRoute: CreateWithoutBodyRoute<"HEAD", AppContext>;
|
|
11
|
+
export declare const createPostRoute: CreateWithBodyRoute<"POST", AppContext>;
|
|
12
|
+
export declare const createPutRoute: CreateWithBodyRoute<"PUT", AppContext>;
|
|
13
|
+
export declare const createPatchRoute: CreateWithBodyRoute<"PATCH", AppContext>;
|
|
14
|
+
export declare const createAnyRoute: CreateAnyRoute;
|
|
15
|
+
export declare const createAllRoute: CreateAllRoute;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.cjs","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,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 []>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const require_units = require("
|
|
1
|
+
const require_units = require("../types/units.cjs");
|
|
2
2
|
const require_constants = require("./constants.cjs");
|
|
3
|
-
const require_validators = require("
|
|
3
|
+
const require_validators = require("../define/validators.cjs");
|
|
4
4
|
let _taserjs_router_utils = require("@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 = {};
|
|
@@ -22,12 +22,32 @@ function buildRouteBase(path, method, methods, middlewares) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
/** Shared internal builder — not part of the public `@taserjs/router` API. */
|
|
25
|
-
function createRouteBuilder(path, method,
|
|
25
|
+
function createRouteBuilder(path, method, methods) {
|
|
26
26
|
const middlewares = [];
|
|
27
27
|
let routeReturns = {};
|
|
28
|
+
const validators = {};
|
|
29
|
+
let bodyMode;
|
|
28
30
|
const builder = {
|
|
29
31
|
path,
|
|
30
32
|
method,
|
|
33
|
+
query(schema) {
|
|
34
|
+
validators.query = schema;
|
|
35
|
+
return builder;
|
|
36
|
+
},
|
|
37
|
+
params(schema) {
|
|
38
|
+
validators.params = schema;
|
|
39
|
+
return builder;
|
|
40
|
+
},
|
|
41
|
+
body(modeOrSchema, schema) {
|
|
42
|
+
if (typeof modeOrSchema === "string") {
|
|
43
|
+
bodyMode = modeOrSchema;
|
|
44
|
+
if (schema !== void 0) validators.body = schema;
|
|
45
|
+
} else {
|
|
46
|
+
bodyMode = "json";
|
|
47
|
+
validators.body = modeOrSchema;
|
|
48
|
+
}
|
|
49
|
+
return builder;
|
|
50
|
+
},
|
|
31
51
|
returns(map) {
|
|
32
52
|
routeReturns = {
|
|
33
53
|
...routeReturns,
|
|
@@ -42,46 +62,33 @@ function createRouteBuilder(path, method, validators = {}, methods) {
|
|
|
42
62
|
handler(fnOrUnit) {
|
|
43
63
|
const routeSchemas = require_validators.pickDefinedSchemas(validators);
|
|
44
64
|
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
|
-
}
|
|
65
|
+
const unit = require_units.isHandlerUnit(fnOrUnit) ? fnOrUnit : {
|
|
66
|
+
handler: fnOrUnit,
|
|
67
|
+
middlewares: [],
|
|
68
|
+
returns: void 0
|
|
69
|
+
};
|
|
70
|
+
const handlerSchemas = require_units.isHandlerUnit(fnOrUnit) ? require_validators.pickDefinedSchemas(fnOrUnit, require_constants.HANDLER_SCHEMA_KEY_MAP) : {};
|
|
70
71
|
const returns = buildEffectiveReturns({
|
|
71
72
|
middlewareReturns: (0, _taserjs_router_utils.collectReturnsFromDefinitions)(middlewares),
|
|
72
73
|
routeReturns,
|
|
73
|
-
handlerMiddlewareReturns:
|
|
74
|
-
handlerReturns:
|
|
74
|
+
handlerMiddlewareReturns: (0, _taserjs_router_utils.collectReturnsFromDefinitions)(unit.middlewares),
|
|
75
|
+
handlerReturns: unit.returns,
|
|
75
76
|
schemas: {
|
|
76
77
|
...validators,
|
|
77
|
-
|
|
78
|
+
handlerQuery: unit.query,
|
|
79
|
+
handlerParams: unit.params,
|
|
80
|
+
handlerBody: unit.body,
|
|
81
|
+
middlewares,
|
|
82
|
+
handlerMiddlewares: unit.middlewares
|
|
78
83
|
}
|
|
79
84
|
});
|
|
80
85
|
return {
|
|
81
86
|
...base,
|
|
82
|
-
handlerMiddlewares: [],
|
|
83
|
-
handler:
|
|
87
|
+
handlerMiddlewares: [...unit.middlewares],
|
|
88
|
+
handler: unit.handler,
|
|
84
89
|
...routeSchemas,
|
|
90
|
+
...handlerSchemas,
|
|
91
|
+
...bodyMode ? { bodyMode } : {},
|
|
85
92
|
...returns ? { returns } : {}
|
|
86
93
|
};
|
|
87
94
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route.cjs","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 { isHandlerUnit } from \"../types/units.js\";\nimport { HANDLER_SCHEMA_KEY_MAP } from \"./constants.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 handlerMiddlewareReturns: ReturnsMap;\n handlerReturns: ReturnsMap | undefined;\n schemas: {\n query?: unknown;\n params?: unknown;\n body?: unknown;\n handlerQuery?: unknown;\n handlerParams?: unknown;\n handlerBody?: unknown;\n middlewares?: readonly MiddlewareDefinition[];\n handlerMiddlewares?: readonly MiddlewareDefinition[];\n };\n}): Record<number, StandardSchemaV1> | undefined {\n const merged = mergeReturnsMaps(\n toUtilsMap(args.middlewareReturns),\n toUtilsMap(args.routeReturns),\n toUtilsMap(args.handlerMiddlewareReturns),\n toUtilsMap(args.handlerReturns),\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) {\n middlewares.push(definition);\n return builder;\n },\n handler(fnOrUnit: ((ctx: unknown) => unknown) | unknown) {\n const routeSchemas = pickDefinedSchemas(validators);\n const base = buildRouteBase(path, method, methods, middlewares);\n\n const unit = isHandlerUnit(fnOrUnit)\n ? fnOrUnit\n : {\n handler: fnOrUnit as (ctx: unknown) => Response | Promise<Response>,\n middlewares: [] as MiddlewareDefinition[],\n returns: undefined as ReturnsMap | undefined,\n };\n\n const handlerSchemas = isHandlerUnit(fnOrUnit)\n ? pickDefinedSchemas(fnOrUnit, HANDLER_SCHEMA_KEY_MAP)\n : {};\n\n const returns = buildEffectiveReturns({\n middlewareReturns: collectReturnsFromDefinitions(middlewares),\n routeReturns,\n handlerMiddlewareReturns: collectReturnsFromDefinitions(unit.middlewares),\n handlerReturns: unit.returns,\n schemas: {\n ...validators,\n handlerQuery: (unit as any).query,\n handlerParams: (unit as any).params,\n handlerBody: (unit as any).body,\n middlewares,\n handlerMiddlewares: unit.middlewares,\n },\n });\n\n return {\n ...base,\n handlerMiddlewares: [...unit.middlewares],\n handler: unit.handler,\n ...routeSchemas,\n ...handlerSchemas,\n ...(bodyMode ? { bodyMode } : {}),\n ...(returns ? { returns } : {}),\n };\n },\n };\n\n return builder as unknown as RouteBuilder<RoutePath, Method, readonly [], ValidatorParts>;\n}\n"],"mappings":";;;;;AAsBA,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,MAekB;CAO/C,MAAM,WAAA,GAAA,sBAAA,YAAA,EAAA,GAAA,sBAAA,iBAAA,CALJ,WAAW,KAAK,iBAAiB,GACjC,WAAW,KAAK,YAAY,GAC5B,WAAW,KAAK,wBAAwB,GACxC,WAAW,KAAK,cAAc,CAEJ,IAAA,GAAA,sBAAA,gBAAA,CAAwB,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,YAAkC;GACpC,YAAY,KAAK,UAAU;GAC3B,OAAO;EACT;EACA,QAAQ,UAAiD;GACvD,MAAM,eAAe,mBAAA,mBAAmB,UAAU;GAClD,MAAM,OAAO,eAAe,MAAM,QAAQ,SAAS,WAAW;GAE9D,MAAM,OAAO,cAAA,cAAc,QAAQ,IAC/B,WACA;IACE,SAAS;IACT,aAAa,CAAC;IACd,SAAS,KAAA;GACX;GAEJ,MAAM,iBAAiB,cAAA,cAAc,QAAQ,IACzC,mBAAA,mBAAmB,UAAU,kBAAA,sBAAsB,IACnD,CAAC;GAEL,MAAM,UAAU,sBAAsB;IACpC,oBAAA,GAAA,sBAAA,8BAAA,CAAiD,WAAW;IAC5D;IACA,2BAAA,GAAA,sBAAA,8BAAA,CAAwD,KAAK,WAAW;IACxE,gBAAgB,KAAK;IACrB,SAAS;KACP,GAAG;KACH,cAAe,KAAa;KAC5B,eAAgB,KAAa;KAC7B,aAAc,KAAa;KAC3B;KACA,oBAAoB,KAAK;IAC3B;GACF,CAAC;GAED,OAAO;IACL,GAAG;IACH,oBAAoB,CAAC,GAAG,KAAK,WAAW;IACxC,SAAS,KAAK;IACd,GAAG;IACH,GAAG;IACH,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;IAC/B,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;GAC/B;EACF;CACF;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Method, RouteBuilder, RoutePath, ValidatorParts } from '../types/index.js';
|
|
2
|
+
import { HttpMethod } from '../types/units.js';
|
|
3
|
+
/** Shared internal builder — not part of the public `@taserjs/router` API. */
|
|
4
|
+
export declare function createRouteBuilder(path: string, method: HttpMethod | "ANY" | "ALL", methods?: readonly HttpMethod[]): RouteBuilder<RoutePath, Method, readonly [], ValidatorParts>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const require_factories = require("./factories.cjs");
|
|
2
|
-
const require_handler = require("
|
|
3
|
-
const require_middleware = require("
|
|
4
|
-
const
|
|
2
|
+
const require_handler = require("../define/handler.cjs");
|
|
3
|
+
const require_middleware = require("../define/middleware.cjs");
|
|
4
|
+
const require_middleware$1 = require("./middleware.cjs");
|
|
5
|
+
const require_app = require("./app.cjs");
|
|
5
6
|
let _taserjs_router_utils = require("@taserjs/router-utils");
|
|
6
7
|
let _taserjs_router_core = require("@taserjs/router-core");
|
|
7
|
-
//#region src/
|
|
8
|
+
//#region src/builder/router.ts
|
|
8
9
|
function toOnErrorHandler(onErrorOptions) {
|
|
9
10
|
return (0, _taserjs_router_utils.normalizeOnError)(onErrorOptions);
|
|
10
11
|
}
|
|
@@ -41,24 +42,48 @@ var TaserRouter = class {
|
|
|
41
42
|
any = require_factories.createAnyRoute;
|
|
42
43
|
all = require_factories.createAllRoute;
|
|
43
44
|
middleware(layout) {
|
|
44
|
-
return require_middleware.createMiddleware(layout);
|
|
45
|
+
return require_middleware$1.createMiddleware(layout);
|
|
45
46
|
}
|
|
46
47
|
defineHandler(options) {
|
|
47
48
|
return options === void 0 ? require_handler.defineHandler() : require_handler.defineHandler(options);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
defineMiddleware = require_middleware.defineMiddleware;
|
|
51
|
+
create(manifest, runtimeOptions) {
|
|
50
52
|
const definition = this.state.contextDef;
|
|
51
53
|
const validateResponse = this.state.options.response?.validate ?? true;
|
|
52
54
|
const onValidationFailure = this.state.options.response?.onValidationFailure;
|
|
53
|
-
const basePath =
|
|
55
|
+
const basePath = runtimeOptions?.basePath;
|
|
54
56
|
const hasCustomContext = definition.boot !== void 0 || definition.request !== void 0;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
57
|
+
let bootContextResolved;
|
|
58
|
+
let bootPromise;
|
|
59
|
+
if (definition.boot !== void 0) {
|
|
60
|
+
const bootResult = definition.boot();
|
|
61
|
+
if ((0, _taserjs_router_utils.isPromise)(bootResult)) bootPromise = bootResult.then((ctx) => {
|
|
62
|
+
bootContextResolved = ctx ?? {};
|
|
63
|
+
return bootContextResolved;
|
|
64
|
+
});
|
|
65
|
+
else bootContextResolved = bootResult ?? {};
|
|
66
|
+
} else if (hasCustomContext) bootContextResolved = {};
|
|
67
|
+
return new require_app.TaserApp((0, _taserjs_router_core.createTaserRuntime)(manifest, hasCustomContext ? (req) => {
|
|
68
|
+
if (bootPromise !== void 0 && bootContextResolved === void 0) return bootPromise.then(async (bootContext) => {
|
|
69
|
+
if (!definition.request) return { ...bootContext };
|
|
70
|
+
const requestResult = definition.request(req);
|
|
71
|
+
const requestContext = (0, _taserjs_router_utils.isPromise)(requestResult) ? await requestResult : requestResult;
|
|
72
|
+
return {
|
|
73
|
+
...bootContext,
|
|
74
|
+
...requestContext
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
const bootContext = bootContextResolved ?? {};
|
|
78
|
+
if (!definition.request) return { ...bootContext };
|
|
79
|
+
const requestResult = definition.request(req);
|
|
80
|
+
if ((0, _taserjs_router_utils.isPromise)(requestResult)) return requestResult.then((requestContext) => ({
|
|
60
81
|
...bootContext,
|
|
61
82
|
...requestContext
|
|
83
|
+
}));
|
|
84
|
+
return {
|
|
85
|
+
...bootContext,
|
|
86
|
+
...requestResult
|
|
62
87
|
};
|
|
63
88
|
} : () => ({}), {
|
|
64
89
|
...basePath !== void 0 ? { basePath } : {},
|
|
@@ -79,4 +104,4 @@ function createTaserApp(options = {}) {
|
|
|
79
104
|
exports.TaserRouter = TaserRouter;
|
|
80
105
|
exports.createTaserApp = createTaserApp;
|
|
81
106
|
|
|
82
|
-
//# sourceMappingURL=
|
|
107
|
+
//# sourceMappingURL=router.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.cjs","names":[],"sources":["../../../src/builder/router.ts"],"sourcesContent":["import {\n createTaserRuntime,\n type NotFoundHandler,\n type OnErrorHandler,\n type RouteManifestShape,\n} from \"@taserjs/router-core\";\nimport { isPromise, normalizeOnError } from \"@taserjs/router-utils\";\n\nimport {\n createAllRoute,\n createAnyRoute,\n createDeleteRoute,\n createGetRoute,\n createHeadRoute,\n createOptionsRoute,\n createPatchRoute,\n createPostRoute,\n createPutRoute,\n} from \"./factories.js\";\nimport { defineHandler } from \"../define/handler.js\";\nimport { defineMiddleware, type DefineMiddlewareFn } from \"../define/middleware.js\";\nimport { createMiddleware } from \"./middleware.js\";\nimport { TaserApp } from \"./app.js\";\nimport type { ContextDefinition, CreateTaserAppOptions, OnErrorOptions } from \"../types/app.js\";\nimport type { AppContext } from \"../types/units.js\";\nimport type { HandlerBuilder, LayoutId, MiddlewareBuilder } from \"../types/index.js\";\nimport type { ReturnsMap } from \"../types/returns.js\";\nimport type { Schema } from \"../types/schema.js\";\nimport type {\n CreateAllRoute,\n CreateAnyRoute,\n CreateWithBodyRoute,\n CreateWithoutBodyRoute,\n} from \"./factories.js\";\n\nfunction toOnErrorHandler(\n onErrorOptions: OnErrorOptions | OnErrorOptions[\"handle\"],\n): OnErrorHandler {\n return normalizeOnError(onErrorOptions);\n}\n\ntype RouterState = {\n options: CreateTaserAppOptions;\n contextDef: ContextDefinition<Record<string, unknown>, Record<string, unknown>>;\n onError?: OnErrorHandler;\n notFound?: NotFoundHandler;\n};\n\nconst emptyContext: ContextDefinition<Record<string, unknown>, Record<string, unknown>> = {};\n\nexport class TaserRouter<\n TAppContext extends Record<string, unknown> = AppContext,\n THasNotFound extends boolean = false,\n> {\n private readonly state: RouterState;\n\n constructor(options: CreateTaserAppOptions = {}, state?: Partial<Omit<RouterState, \"options\">>) {\n this.state = {\n options,\n contextDef: state?.contextDef ?? emptyContext,\n ...(state?.onError !== undefined ? { onError: state.onError } : {}),\n ...(state?.notFound !== undefined ? { notFound: state.notFound } : {}),\n };\n }\n\n context<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>>(\n definition: ContextDefinition<TBoot, TReq>,\n ): TaserRouter<TBoot & TReq, THasNotFound> {\n this.state.contextDef = definition;\n return this as unknown as TaserRouter<TBoot & TReq, THasNotFound>;\n }\n\n onError<TResponses extends ReturnsMap = ReturnsMap>(\n options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>[\"handle\"],\n ): this {\n this.state.onError = toOnErrorHandler(options);\n return this;\n }\n\n notFound(\n handler: (ctx: unknown) => Response | Promise<Response> | unknown,\n ): TaserRouter<TAppContext, true> {\n this.state.notFound = (ctx) => handler(ctx);\n return this as unknown as TaserRouter<TAppContext, true>;\n }\n\n get: CreateWithoutBodyRoute<\"GET\", TAppContext> = createGetRoute as CreateWithoutBodyRoute<\n \"GET\",\n TAppContext\n >;\n post: CreateWithBodyRoute<\"POST\", TAppContext> = createPostRoute as CreateWithBodyRoute<\n \"POST\",\n TAppContext\n >;\n put: CreateWithBodyRoute<\"PUT\", TAppContext> = createPutRoute as CreateWithBodyRoute<\n \"PUT\",\n TAppContext\n >;\n patch: CreateWithBodyRoute<\"PATCH\", TAppContext> = createPatchRoute as CreateWithBodyRoute<\n \"PATCH\",\n TAppContext\n >;\n delete: CreateWithoutBodyRoute<\"DELETE\", TAppContext> =\n createDeleteRoute as CreateWithoutBodyRoute<\"DELETE\", TAppContext>;\n options: CreateWithoutBodyRoute<\"OPTIONS\", TAppContext> =\n createOptionsRoute as CreateWithoutBodyRoute<\"OPTIONS\", TAppContext>;\n head: CreateWithoutBodyRoute<\"HEAD\", TAppContext> = createHeadRoute as CreateWithoutBodyRoute<\n \"HEAD\",\n TAppContext\n >;\n any: CreateAnyRoute<TAppContext> = createAnyRoute as CreateAnyRoute<TAppContext>;\n all: CreateAllRoute<TAppContext> = createAllRoute as CreateAllRoute<TAppContext>;\n\n middleware<const Layout extends LayoutId>(\n layout: Layout,\n ): MiddlewareBuilder<Layout, readonly [], TAppContext> {\n return createMiddleware(layout) as MiddlewareBuilder<Layout, readonly [], TAppContext>;\n }\n\n defineHandler<TQuery = unknown, TParams = unknown, TBody = unknown>(options?: {\n query?: Schema<TQuery>;\n params?: Schema<TParams>;\n body?: Schema<TBody>;\n }): HandlerBuilder<\n readonly [],\n { query: TQuery; params: TParams; body: TBody },\n {},\n TAppContext\n > {\n return options === undefined\n ? defineHandler<TAppContext>()\n : defineHandler<TAppContext>(options);\n }\n\n defineMiddleware: DefineMiddlewareFn<TAppContext> =\n defineMiddleware as DefineMiddlewareFn<TAppContext>;\n\n create<const TManifest extends RouteManifestShape>(\n manifest: TManifest,\n runtimeOptions?: { basePath?: string },\n ): TaserApp<TManifest, THasNotFound> {\n const definition = this.state.contextDef;\n const validateResponse = this.state.options.response?.validate ?? true;\n const onValidationFailure = this.state.options.response?.onValidationFailure;\n const basePath = runtimeOptions?.basePath;\n\n const hasCustomContext = definition.boot !== undefined || definition.request !== undefined;\n let bootContextResolved: Record<string, unknown> | undefined;\n let bootPromise: Promise<Record<string, unknown>> | undefined;\n\n if (definition.boot !== undefined) {\n const bootResult = definition.boot();\n if (isPromise(bootResult)) {\n bootPromise = bootResult.then((ctx) => {\n bootContextResolved = (ctx ?? {}) as Record<string, unknown>;\n return bootContextResolved;\n });\n } else {\n bootContextResolved = (bootResult ?? {}) as Record<string, unknown>;\n }\n } else if (hasCustomContext) {\n bootContextResolved = {};\n }\n\n const contextFactory = hasCustomContext\n ? (req?: Request) => {\n if (bootPromise !== undefined && bootContextResolved === undefined) {\n return bootPromise.then(async (bootContext) => {\n if (!definition.request) {\n return { ...bootContext };\n }\n const requestResult = definition.request(req!);\n const requestContext = isPromise(requestResult) ? await requestResult : requestResult;\n return { ...bootContext, ...requestContext };\n });\n }\n\n const bootContext = bootContextResolved ?? {};\n if (!definition.request) {\n return { ...bootContext };\n }\n\n const requestResult = definition.request(req!);\n if (isPromise(requestResult)) {\n return requestResult.then((requestContext) => ({\n ...bootContext,\n ...requestContext,\n }));\n }\n\n return { ...bootContext, ...(requestResult as Record<string, unknown>) };\n }\n : () => ({});\n\n const runtime = createTaserRuntime(manifest, contextFactory, {\n ...(basePath !== undefined ? { basePath } : {}),\n response: {\n validate: validateResponse,\n ...(onValidationFailure !== undefined ? { onValidationFailure } : {}),\n },\n ...(this.state.onError !== undefined ? { onError: this.state.onError } : {}),\n ...(this.state.notFound !== undefined ? { notFound: this.state.notFound } : {}),\n ...(this.state.options.cookies !== undefined ? { cookies: this.state.options.cookies } : {}),\n });\n\n return new TaserApp(runtime, manifest) as unknown as TaserApp<TManifest, THasNotFound>;\n }\n}\n\nexport function createTaserApp(\n options: CreateTaserAppOptions = {},\n): TaserRouter<AppContext, false> {\n return new TaserRouter<AppContext, false>(options);\n}\n"],"mappings":";;;;;;;;AAmCA,SAAS,iBACP,gBACgB;CAChB,QAAA,GAAA,sBAAA,iBAAA,CAAwB,cAAc;AACxC;AASA,IAAM,eAAoF,CAAC;AAE3F,IAAa,cAAb,MAGE;CACA;CAEA,YAAY,UAAiC,CAAC,GAAG,OAA+C;EAC9F,KAAK,QAAQ;GACX;GACA,YAAY,OAAO,cAAc;GACjC,GAAI,OAAO,YAAY,KAAA,IAAY,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;GACjE,GAAI,OAAO,aAAa,KAAA,IAAY,EAAE,UAAU,MAAM,SAAS,IAAI,CAAC;EACtE;CACF;CAEA,QACE,YACyC;EACzC,KAAK,MAAM,aAAa;EACxB,OAAO;CACT;CAEA,QACE,SACM;EACN,KAAK,MAAM,UAAU,iBAAiB,OAAO;EAC7C,OAAO;CACT;CAEA,SACE,SACgC;EAChC,KAAK,MAAM,YAAY,QAAQ,QAAQ,GAAG;EAC1C,OAAO;CACT;CAEA,MAAkD,kBAAA;CAIlD,OAAiD,kBAAA;CAIjD,MAA+C,kBAAA;CAI/C,QAAmD,kBAAA;CAInD,SACE,kBAAA;CACF,UACE,kBAAA;CACF,OAAoD,kBAAA;CAIpD,MAAmC,kBAAA;CACnC,MAAmC,kBAAA;CAEnC,WACE,QACqD;EACrD,OAAO,qBAAA,iBAAiB,MAAM;CAChC;CAEA,cAAoE,SASlE;EACA,OAAO,YAAY,KAAA,IACf,gBAAA,cAA2B,IAC3B,gBAAA,cAA2B,OAAO;CACxC;CAEA,mBACE,mBAAA;CAEF,OACE,UACA,gBACmC;EACnC,MAAM,aAAa,KAAK,MAAM;EAC9B,MAAM,mBAAmB,KAAK,MAAM,QAAQ,UAAU,YAAY;EAClE,MAAM,sBAAsB,KAAK,MAAM,QAAQ,UAAU;EACzD,MAAM,WAAW,gBAAgB;EAEjC,MAAM,mBAAmB,WAAW,SAAS,KAAA,KAAa,WAAW,YAAY,KAAA;EACjF,IAAI;EACJ,IAAI;EAEJ,IAAI,WAAW,SAAS,KAAA,GAAW;GACjC,MAAM,aAAa,WAAW,KAAK;GACnC,KAAA,GAAA,sBAAA,UAAA,CAAc,UAAU,GACtB,cAAc,WAAW,MAAM,QAAQ;IACrC,sBAAuB,OAAO,CAAC;IAC/B,OAAO;GACT,CAAC;QAED,sBAAuB,cAAc,CAAC;EAE1C,OAAO,IAAI,kBACT,sBAAsB,CAAC;EA4CzB,OAAO,IAAI,YAAA,UAAA,GAAA,qBAAA,mBAAA,CAXwB,UA9BZ,oBAClB,QAAkB;GACjB,IAAI,gBAAgB,KAAA,KAAa,wBAAwB,KAAA,GACvD,OAAO,YAAY,KAAK,OAAO,gBAAgB;IAC7C,IAAI,CAAC,WAAW,SACd,OAAO,EAAE,GAAG,YAAY;IAE1B,MAAM,gBAAgB,WAAW,QAAQ,GAAI;IAC7C,MAAM,kBAAA,GAAA,sBAAA,UAAA,CAA2B,aAAa,IAAI,MAAM,gBAAgB;IACxE,OAAO;KAAE,GAAG;KAAa,GAAG;IAAe;GAC7C,CAAC;GAGH,MAAM,cAAc,uBAAuB,CAAC;GAC5C,IAAI,CAAC,WAAW,SACd,OAAO,EAAE,GAAG,YAAY;GAG1B,MAAM,gBAAgB,WAAW,QAAQ,GAAI;GAC7C,KAAA,GAAA,sBAAA,UAAA,CAAc,aAAa,GACzB,OAAO,cAAc,MAAM,oBAAoB;IAC7C,GAAG;IACH,GAAG;GACL,EAAE;GAGJ,OAAO;IAAE,GAAG;IAAa,GAAI;GAA0C;EACzE,WACO,CAAC,IAEiD;GAC3D,GAAI,aAAa,KAAA,IAAY,EAAE,SAAS,IAAI,CAAC;GAC7C,UAAU;IACR,UAAU;IACV,GAAI,wBAAwB,KAAA,IAAY,EAAE,oBAAoB,IAAI,CAAC;GACrE;GACA,GAAI,KAAK,MAAM,YAAY,KAAA,IAAY,EAAE,SAAS,KAAK,MAAM,QAAQ,IAAI,CAAC;GAC1E,GAAI,KAAK,MAAM,aAAa,KAAA,IAAY,EAAE,UAAU,KAAK,MAAM,SAAS,IAAI,CAAC;GAC7E,GAAI,KAAK,MAAM,QAAQ,YAAY,KAAA,IAAY,EAAE,SAAS,KAAK,MAAM,QAAQ,QAAQ,IAAI,CAAC;EAC5F,CAEoB,GAAS,QAAQ;CACvC;AACF;AAEA,SAAgB,eACd,UAAiC,CAAC,GACF;CAChC,OAAO,IAAI,YAA+B,OAAO;AACnD"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { NotFoundHandler, OnErrorHandler, RouteManifestShape } from '@taserjs/router-core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { DefineMiddlewareFn } from '../define/middleware.js';
|
|
3
|
+
import { TaserApp } from './app.js';
|
|
4
|
+
import { ContextDefinition, CreateTaserAppOptions, OnErrorOptions } from '../types/app.js';
|
|
5
|
+
import { AppContext } from '../types/units.js';
|
|
6
|
+
import { HandlerBuilder, LayoutId, MiddlewareBuilder } from '../types/index.js';
|
|
7
|
+
import { ReturnsMap } from '../types/returns.js';
|
|
8
|
+
import { Schema } from '../types/schema.js';
|
|
7
9
|
import { CreateAllRoute, CreateAnyRoute, CreateWithBodyRoute, CreateWithoutBodyRoute } from './factories.js';
|
|
8
10
|
type RouterState = {
|
|
9
11
|
options: CreateTaserAppOptions;
|
|
@@ -11,12 +13,12 @@ type RouterState = {
|
|
|
11
13
|
onError?: OnErrorHandler;
|
|
12
14
|
notFound?: NotFoundHandler;
|
|
13
15
|
};
|
|
14
|
-
export declare class TaserRouter<TAppContext extends Record<string, unknown> = AppContext> {
|
|
16
|
+
export declare class TaserRouter<TAppContext extends Record<string, unknown> = AppContext, THasNotFound extends boolean = false> {
|
|
15
17
|
private readonly state;
|
|
16
18
|
constructor(options?: CreateTaserAppOptions, state?: Partial<Omit<RouterState, "options">>);
|
|
17
|
-
context<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>>(definition: ContextDefinition<TBoot, TReq>): TaserRouter<TBoot & TReq>;
|
|
18
|
-
onError<TResponses extends
|
|
19
|
-
notFound(handler: (ctx: unknown) => Response | Promise<Response> | unknown):
|
|
19
|
+
context<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>>(definition: ContextDefinition<TBoot, TReq>): TaserRouter<TBoot & TReq, THasNotFound>;
|
|
20
|
+
onError<TResponses extends ReturnsMap = ReturnsMap>(options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>["handle"]): this;
|
|
21
|
+
notFound(handler: (ctx: unknown) => Response | Promise<Response> | unknown): TaserRouter<TAppContext, true>;
|
|
20
22
|
get: CreateWithoutBodyRoute<"GET", TAppContext>;
|
|
21
23
|
post: CreateWithBodyRoute<"POST", TAppContext>;
|
|
22
24
|
put: CreateWithBodyRoute<"PUT", TAppContext>;
|
|
@@ -36,7 +38,10 @@ export declare class TaserRouter<TAppContext extends Record<string, unknown> = A
|
|
|
36
38
|
params: TParams;
|
|
37
39
|
body: TBody;
|
|
38
40
|
}, {}, TAppContext>;
|
|
39
|
-
|
|
41
|
+
defineMiddleware: DefineMiddlewareFn<TAppContext>;
|
|
42
|
+
create<const TManifest extends RouteManifestShape>(manifest: TManifest, runtimeOptions?: {
|
|
43
|
+
basePath?: string;
|
|
44
|
+
}): TaserApp<TManifest, THasNotFound>;
|
|
40
45
|
}
|
|
41
|
-
export declare function createTaserApp(options?: CreateTaserAppOptions): TaserRouter
|
|
46
|
+
export declare function createTaserApp(options?: CreateTaserAppOptions): TaserRouter<AppContext, false>;
|
|
42
47
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-context.cjs","names":[],"sources":["../../../src/context/create-context.ts"],"sourcesContent":["import type { ReservedContextKey } from \"@taserjs/router-core\";\n\nimport type { ContextDefinition } from \"../types/app.js\";\n\ntype NoReservedKeysConstraint<\n TBoot extends Record<string, unknown>,\n TReq extends Record<string, unknown>,\n> = Extract<keyof TBoot | keyof TReq, ReservedContextKey> extends never ? unknown : never;\n\nexport function createContext<\n TBoot extends Record<string, unknown> = Record<string, never>,\n TReq extends Record<string, unknown> = Record<string, never>,\n>(\n definition: ContextDefinition<TBoot, TReq> & NoReservedKeysConstraint<TBoot, TReq>,\n): ContextDefinition<TBoot, TReq> {\n return definition;\n}\n\nexport type { ContextDefinition, InferAppContext } from \"../types/app.js\";\n"],"mappings":";AASA,SAAgB,cAId,YACgC;CAChC,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReservedContextKey } from '@taserjs/router-core';
|
|
2
|
-
import { ContextDefinition } from '
|
|
2
|
+
import { ContextDefinition } from '../types/app.js';
|
|
3
3
|
type NoReservedKeysConstraint<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>> = Extract<keyof TBoot | keyof TReq, ReservedContextKey> extends never ? unknown : never;
|
|
4
4
|
export declare function createContext<TBoot extends Record<string, unknown> = Record<string, never>, TReq extends Record<string, unknown> = Record<string, never>>(definition: ContextDefinition<TBoot, TReq> & NoReservedKeysConstraint<TBoot, TReq>): ContextDefinition<TBoot, TReq>;
|
|
5
|
-
export type { ContextDefinition, InferAppContext } from '
|
|
5
|
+
export type { ContextDefinition, InferAppContext } from '../types/app.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
let _taserjs_router_core = require("@taserjs/router-core");
|
|
2
2
|
//#region src/define/middleware.ts
|
|
3
|
-
function defineMiddleware(first, second) {
|
|
3
|
+
var defineMiddleware = function defineMiddleware(first, second) {
|
|
4
4
|
if (typeof first === "string" || Array.isArray(first)) {
|
|
5
5
|
const options = second;
|
|
6
6
|
return {
|
|
@@ -20,7 +20,7 @@ function defineMiddleware(first, second) {
|
|
|
20
20
|
__middlewareAcc: void 0,
|
|
21
21
|
...options.returns ? { __returns: options.returns } : {}
|
|
22
22
|
};
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
//#endregion
|
|
25
25
|
exports.defineMiddleware = defineMiddleware;
|
|
26
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.cjs","names":[],"sources":["../../../src/define/middleware.ts"],"sourcesContent":["import { createTaserCompatHandler, type Awaitable } from \"@taserjs/router-core\";\n\nimport type { ReturnsMap } from \"../types/returns.js\";\nimport type {\n AppContext,\n
|
|
1
|
+
{"version":3,"file":"middleware.cjs","names":[],"sources":["../../../src/define/middleware.ts"],"sourcesContent":["import { createTaserCompatHandler, type Awaitable } from \"@taserjs/router-core\";\n\nimport type { ReturnsMap } from \"../types/returns.js\";\nimport type {\n AppContext,\n DefineMiddlewareResult,\n MiddlewareReturnFromParts,\n MiddlewareUnit,\n NextFn,\n StandaloneMiddlewareContext,\n} from \"../types/units.js\";\nimport type {\n LayoutId,\n ResolveLayoutMiddlewaresState,\n ResolveLayoutsState,\n} from \"../types/index.js\";\nimport type { Schema } from \"../types/schema.js\";\n\nexport type HonoMiddlewareHandler = Parameters<typeof createTaserCompatHandler>[0];\n\nexport type HonoMiddlewareUnit = MiddlewareUnit<\n MiddlewareReturnFromParts<unknown, unknown, unknown, {}>,\n {},\n null,\n {}\n>;\n\nexport type DefineMiddlewareOptions<\n TState = unknown,\n TRequires = {},\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TReturns extends ReturnsMap = {},\n TQueryIn = unknown,\n TParamsIn = unknown,\n TBodyIn = unknown,\n TAppContext extends Record<string, unknown> = AppContext,\n R = unknown,\n> = {\n query?: Schema<TQuery, TQueryIn>;\n params?: Schema<TParams, TParamsIn>;\n body?: Schema<TBody, TBodyIn>;\n returns?: TReturns;\n handler: (\n ctx: StandaloneMiddlewareContext<TQuery, TParams, TBody, TAppContext, TRequires>,\n next: NextFn<NoInfer<TState>>,\n ) => Awaitable<R>;\n};\n\nexport type ScopedMiddlewareOptions<\n Layout extends LayoutId,\n TState = unknown,\n TRequires = {},\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TReturns extends ReturnsMap = {},\n TQueryIn = unknown,\n TParamsIn = unknown,\n TBodyIn = unknown,\n TAppContext extends Record<string, unknown> = AppContext,\n R = unknown,\n> = {\n query?: Schema<TQuery, TQueryIn>;\n params?: Schema<TParams, TParamsIn>;\n body?: Schema<TBody, TBodyIn>;\n returns?: TReturns;\n handler: (\n ctx: StandaloneMiddlewareContext<\n TQuery,\n TParams,\n TBody,\n TAppContext,\n ResolveLayoutMiddlewaresState<Layout> & TRequires\n >,\n next: NextFn<NoInfer<TState>>,\n ) => Awaitable<R>;\n};\n\nexport type MultiScopedMiddlewareOptions<\n Layouts extends readonly LayoutId[],\n TState = unknown,\n TRequires = {},\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TReturns extends ReturnsMap = {},\n TQueryIn = unknown,\n TParamsIn = unknown,\n TBodyIn = unknown,\n TAppContext extends Record<string, unknown> = AppContext,\n R = unknown,\n> = {\n query?: Schema<TQuery, TQueryIn>;\n params?: Schema<TParams, TParamsIn>;\n body?: Schema<TBody, TBodyIn>;\n returns?: TReturns;\n handler: (\n ctx: StandaloneMiddlewareContext<\n TQuery,\n TParams,\n TBody,\n TAppContext,\n ResolveLayoutsState<Layouts> & TRequires\n >,\n next: NextFn<NoInfer<TState>>,\n ) => Awaitable<R>;\n};\n\nexport interface DefineMiddlewareFn<TAppContext extends Record<string, unknown> = AppContext> {\n (middleware: HonoMiddlewareHandler): HonoMiddlewareUnit;\n\n <\n const Layout extends LayoutId,\n TState = unknown,\n TRequires = {},\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 layout: Layout,\n options: ScopedMiddlewareOptions<\n Layout,\n TState,\n TRequires,\n TQuery,\n TParams,\n TBody,\n TReturns,\n TQueryIn,\n TParamsIn,\n TBodyIn,\n TAppContext,\n R\n >,\n ): DefineMiddlewareResult<\n TQuery,\n TParams,\n TBody,\n TState,\n R,\n TQueryIn,\n TParamsIn,\n TBodyIn,\n TReturns,\n Layout,\n TRequires\n >;\n\n <\n const Layouts extends readonly [LayoutId, ...LayoutId[]],\n TState = unknown,\n TRequires = {},\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 layouts: Layouts,\n options: MultiScopedMiddlewareOptions<\n Layouts,\n TState,\n TRequires,\n TQuery,\n TParams,\n TBody,\n TReturns,\n TQueryIn,\n TParamsIn,\n TBodyIn,\n TAppContext,\n R\n >,\n ): DefineMiddlewareResult<\n TQuery,\n TParams,\n TBody,\n TState,\n R,\n TQueryIn,\n TParamsIn,\n TBodyIn,\n TReturns,\n Layouts,\n TRequires\n >;\n\n <\n TState = unknown,\n TRequires = {},\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 options: DefineMiddlewareOptions<\n TState,\n TRequires,\n TQuery,\n TParams,\n TBody,\n TReturns,\n TQueryIn,\n TParamsIn,\n TBodyIn,\n TAppContext,\n R\n >,\n ): DefineMiddlewareResult<\n TQuery,\n TParams,\n TBody,\n TState,\n R,\n TQueryIn,\n TParamsIn,\n TBodyIn,\n TReturns,\n null,\n TRequires\n >;\n}\n\nexport const defineMiddleware: DefineMiddlewareFn<AppContext> = function defineMiddleware(\n first: any,\n second?: any,\n): any {\n if (typeof first === \"string\" || Array.isArray(first)) {\n const options = second!;\n const unit = {\n ...options,\n __middlewareAcc: undefined as unknown,\n ...(options?.returns ? { __returns: options.returns } : {}),\n __requiredLayouts: first,\n };\n return unit;\n }\n\n if (typeof first === \"function\") {\n const honoMiddleware = first as HonoMiddlewareHandler;\n return defineMiddleware({\n handler: (ctx: unknown, next: (state?: Record<string, unknown>) => unknown) =>\n createTaserCompatHandler(honoMiddleware)(ctx, next),\n });\n }\n\n const options = first as DefineMiddlewareOptions<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >;\n const unit = {\n ...options,\n __middlewareAcc: undefined as unknown,\n ...(options.returns ? { __returns: options.returns } : {}),\n };\n\n return unit;\n};\n"],"mappings":";;AA6OA,IAAa,mBAAmD,SAAS,iBACvE,OACA,QACK;CACL,IAAI,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GAAG;EACrD,MAAM,UAAU;EAOhB,OAAO;GALL,GAAG;GACH,iBAAiB,KAAA;GACjB,GAAI,SAAS,UAAU,EAAE,WAAW,QAAQ,QAAQ,IAAI,CAAC;GACzD,mBAAmB;EAEd;CACT;CAEA,IAAI,OAAO,UAAU,YAAY;EAC/B,MAAM,iBAAiB;EACvB,OAAO,iBAAiB,EACtB,UAAU,KAAc,UAAA,GAAA,qBAAA,yBAAA,CACG,cAAc,CAAC,CAAC,KAAK,IAAI,EACtD,CAAC;CACH;CAEA,MAAM,UAAU;CAmBhB,OAAO;EALL,GAAG;EACH,iBAAiB,KAAA;EACjB,GAAI,QAAQ,UAAU,EAAE,WAAW,QAAQ,QAAQ,IAAI,CAAC;CAGnD;AACT"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createTaserCompatHandler, Awaitable } from '@taserjs/router-core';
|
|
2
2
|
import { ReturnsMap } from '../types/returns.js';
|
|
3
|
-
import { AppContext,
|
|
3
|
+
import { AppContext, DefineMiddlewareResult, MiddlewareReturnFromParts, MiddlewareUnit, NextFn, StandaloneMiddlewareContext } from '../types/units.js';
|
|
4
4
|
import { LayoutId, ResolveLayoutMiddlewaresState, ResolveLayoutsState } from '../types/index.js';
|
|
5
5
|
import { Schema } from '../types/schema.js';
|
|
6
|
-
type HonoMiddlewareHandler = Parameters<typeof createTaserCompatHandler>[0];
|
|
7
|
-
type HonoMiddlewareUnit = MiddlewareUnit<MiddlewareReturnFromParts<unknown, unknown, unknown, {}>, {}, null, {}>;
|
|
6
|
+
export type HonoMiddlewareHandler = Parameters<typeof createTaserCompatHandler>[0];
|
|
7
|
+
export type HonoMiddlewareUnit = MiddlewareUnit<MiddlewareReturnFromParts<unknown, unknown, unknown, {}>, {}, null, {}>;
|
|
8
8
|
export type DefineMiddlewareOptions<TState = unknown, TRequires = {}, TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, TAppContext extends Record<string, unknown> = AppContext, R = unknown> = {
|
|
9
9
|
query?: Schema<TQuery, TQueryIn>;
|
|
10
10
|
params?: Schema<TParams, TParamsIn>;
|
|
@@ -26,8 +26,10 @@ export type MultiScopedMiddlewareOptions<Layouts extends readonly LayoutId[], TS
|
|
|
26
26
|
returns?: TReturns;
|
|
27
27
|
handler: (ctx: StandaloneMiddlewareContext<TQuery, TParams, TBody, TAppContext, ResolveLayoutsState<Layouts> & TRequires>, next: NextFn<NoInfer<TState>>) => Awaitable<R>;
|
|
28
28
|
};
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
export interface DefineMiddlewareFn<TAppContext extends Record<string, unknown> = AppContext> {
|
|
30
|
+
(middleware: HonoMiddlewareHandler): HonoMiddlewareUnit;
|
|
31
|
+
<const Layout extends LayoutId, TState = unknown, TRequires = {}, TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, R = unknown>(layout: Layout, options: ScopedMiddlewareOptions<Layout, TState, TRequires, TQuery, TParams, TBody, TReturns, TQueryIn, TParamsIn, TBodyIn, TAppContext, R>): DefineMiddlewareResult<TQuery, TParams, TBody, TState, R, TQueryIn, TParamsIn, TBodyIn, TReturns, Layout, TRequires>;
|
|
32
|
+
<const Layouts extends readonly [LayoutId, ...LayoutId[]], TState = unknown, TRequires = {}, TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, R = unknown>(layouts: Layouts, options: MultiScopedMiddlewareOptions<Layouts, TState, TRequires, TQuery, TParams, TBody, TReturns, TQueryIn, TParamsIn, TBodyIn, TAppContext, R>): DefineMiddlewareResult<TQuery, TParams, TBody, TState, R, TQueryIn, TParamsIn, TBodyIn, TReturns, Layouts, TRequires>;
|
|
33
|
+
<TState = unknown, TRequires = {}, TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, R = unknown>(options: DefineMiddlewareOptions<TState, TRequires, TQuery, TParams, TBody, TReturns, TQueryIn, TParamsIn, TBodyIn, TAppContext, R>): DefineMiddlewareResult<TQuery, TParams, TBody, TState, R, TQueryIn, TParamsIn, TBodyIn, TReturns, null, TRequires>;
|
|
34
|
+
}
|
|
35
|
+
export declare const defineMiddleware: DefineMiddlewareFn<AppContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.cjs","names":[],"sources":["../../../src/define/validators.ts"],"sourcesContent":["import type { Schema } from \"../types/schema.js\";\nimport { SCHEMA_KEYS, type SchemaKey } from \"../constants.js\";\n\nexport type SchemaValidators = {\n query?: Schema<unknown>;\n params?: Schema<unknown>;\n body?: Schema<unknown>;\n};\n\nexport function pickDefinedSchemas(\n source: SchemaValidators,\n keyMap?: Partial<Record<SchemaKey, string>>,\n): Record<string, Schema<unknown>> {\n const result: Record<string, Schema<unknown>> = {};\n for (const key of SCHEMA_KEYS) {\n const value = source[key];\n if (value !== undefined) {\n result[keyMap?.[key] ?? key] = value;\n }\n }\n return result;\n}\n"],"mappings":";;AASA,SAAgB,mBACd,QACA,QACiC;CACjC,MAAM,SAA0C,CAAC;CACjD,KAAK,MAAM,OAAO,kBAAA,aAAa;EAC7B,MAAM,QAAQ,OAAO;EACrB,IAAI,UAAU,KAAA,GACZ,OAAO,SAAS,QAAQ,OAAO;CAEnC;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"validators.cjs","names":[],"sources":["../../../src/define/validators.ts"],"sourcesContent":["import type { Schema } from \"../types/schema.js\";\nimport { SCHEMA_KEYS, type SchemaKey } from \"../builder/constants.js\";\n\nexport type SchemaValidators = {\n query?: Schema<unknown>;\n params?: Schema<unknown>;\n body?: Schema<unknown>;\n};\n\nexport function pickDefinedSchemas(\n source: SchemaValidators,\n keyMap?: Partial<Record<SchemaKey, string>>,\n): Record<string, Schema<unknown>> {\n const result: Record<string, Schema<unknown>> = {};\n for (const key of SCHEMA_KEYS) {\n const value = source[key];\n if (value !== undefined) {\n result[keyMap?.[key] ?? key] = value;\n }\n }\n return result;\n}\n"],"mappings":";;AASA,SAAgB,mBACd,QACA,QACiC;CACjC,MAAM,SAA0C,CAAC;CACjD,KAAK,MAAM,OAAO,kBAAA,aAAa;EAC7B,MAAM,QAAQ,OAAO;EACrB,IAAI,UAAU,KAAA,GACZ,OAAO,SAAS,QAAQ,OAAO;CAEnC;CACA,OAAO;AACT"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,44 +1,22 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_factories = require("./factories.cjs");
|
|
3
2
|
const require_handler = require("./define/handler.cjs");
|
|
4
|
-
const require_taser_app = require("./taser-app.cjs");
|
|
5
|
-
const require_taser_router = require("./taser-router.cjs");
|
|
6
|
-
const require_create_context = require("./create-context.cjs");
|
|
7
3
|
const require_middleware = require("./define/middleware.cjs");
|
|
4
|
+
const require_app = require("./builder/app.cjs");
|
|
5
|
+
const require_router = require("./builder/router.cjs");
|
|
6
|
+
const require_create_context = require("./context/create-context.cjs");
|
|
8
7
|
let _taserjs_router_utils = require("@taserjs/router-utils");
|
|
9
|
-
exports.TaserApp =
|
|
10
|
-
exports.
|
|
11
|
-
exports.TaserRouter = require_taser_router.TaserRouter;
|
|
8
|
+
exports.TaserApp = require_app.TaserApp;
|
|
9
|
+
exports.TaserRouter = require_router.TaserRouter;
|
|
12
10
|
Object.defineProperty(exports, "ValidationError", {
|
|
13
11
|
enumerable: true,
|
|
14
12
|
get: function() {
|
|
15
13
|
return _taserjs_router_utils.ValidationError;
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
exports.createAllRoute = require_factories.createAllRoute;
|
|
19
|
-
exports.createAnyRoute = require_factories.createAnyRoute;
|
|
20
16
|
exports.createContext = require_create_context.createContext;
|
|
21
|
-
exports.createTaserApp =
|
|
17
|
+
exports.createTaserApp = require_router.createTaserApp;
|
|
22
18
|
exports.defineHandler = require_handler.defineHandler;
|
|
23
19
|
exports.defineMiddleware = require_middleware.defineMiddleware;
|
|
24
|
-
Object.defineProperty(exports, "isReplyResult", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function() {
|
|
27
|
-
return _taserjs_router_utils.isReplyResult;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "reply", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function() {
|
|
33
|
-
return _taserjs_router_utils.reply;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "stream", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function() {
|
|
39
|
-
return _taserjs_router_utils.stream;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
20
|
Object.defineProperty(exports, "validationErrorSchema", {
|
|
43
21
|
enumerable: true,
|
|
44
22
|
get: function() {
|