@taserjs/router 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cjs/constants.cjs.map +1 -1
- package/dist/cjs/create-context.cjs.map +1 -1
- package/dist/cjs/define/handler.cjs.map +1 -1
- package/dist/cjs/define/middleware.cjs +5 -24
- package/dist/cjs/define/middleware.cjs.map +1 -1
- package/dist/cjs/define/middleware.d.cts +10 -79
- package/dist/cjs/define/validators.cjs.map +1 -1
- package/dist/cjs/factories.cjs.map +1 -1
- package/dist/cjs/factories.d.cts +2 -2
- package/dist/cjs/index.cjs +7 -2
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/middleware/body-limit.cjs +2 -2
- package/dist/cjs/middleware/body-limit.cjs.map +1 -1
- package/dist/cjs/middleware/compress.cjs +2 -2
- package/dist/cjs/middleware/compress.cjs.map +1 -1
- package/dist/cjs/middleware/cors.cjs +2 -2
- package/dist/cjs/middleware/cors.cjs.map +1 -1
- package/dist/cjs/middleware/csrf.cjs +2 -2
- package/dist/cjs/middleware/csrf.cjs.map +1 -1
- package/dist/cjs/middleware/etag.cjs +2 -2
- package/dist/cjs/middleware/etag.cjs.map +1 -1
- package/dist/cjs/middleware/jwk.cjs +11 -4
- package/dist/cjs/middleware/jwk.cjs.map +1 -1
- package/dist/cjs/middleware/jwk.d.cts +4 -5
- package/dist/cjs/middleware/jwt.cjs +11 -5
- package/dist/cjs/middleware/jwt.cjs.map +1 -1
- package/dist/cjs/middleware/jwt.d.cts +7 -5
- package/dist/cjs/middleware/secure-headers.cjs +2 -2
- package/dist/cjs/middleware/secure-headers.cjs.map +1 -1
- package/dist/cjs/middleware/timing.cjs +2 -2
- package/dist/cjs/middleware/timing.cjs.map +1 -1
- package/dist/cjs/middleware/wrap-hono.cjs +9 -0
- package/dist/cjs/middleware/wrap-hono.cjs.map +1 -0
- package/dist/cjs/middleware/wrap-hono.d.cts +3 -0
- package/dist/cjs/middleware.cjs.map +1 -1
- package/dist/cjs/reply.cjs +20 -0
- package/dist/cjs/reply.d.cts +2 -0
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +1 -1
- package/dist/cjs/stream.cjs +32 -0
- package/dist/cjs/stream.d.cts +1 -0
- package/dist/cjs/taser-app.cjs +0 -6
- package/dist/cjs/taser-app.cjs.map +1 -1
- package/dist/cjs/taser-app.d.cts +0 -3
- package/dist/cjs/taser-router.cjs +9 -10
- package/dist/cjs/taser-router.cjs.map +1 -1
- package/dist/cjs/taser-router.d.cts +9 -11
- package/dist/cjs/types/app.d.cts +3 -2
- package/dist/cjs/types/index.d.cts +53 -139
- package/dist/cjs/types/type-utils.d.cts +8 -11
- package/dist/cjs/types/units.cjs.map +1 -1
- package/dist/cjs/types/units.d.cts +27 -24
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/create-context.js.map +1 -1
- package/dist/esm/define/handler.js.map +1 -1
- package/dist/esm/define/middleware.d.ts +10 -79
- package/dist/esm/define/middleware.js +5 -24
- package/dist/esm/define/middleware.js.map +1 -1
- package/dist/esm/define/validators.js.map +1 -1
- package/dist/esm/factories.d.ts +2 -2
- package/dist/esm/factories.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +4 -4
- package/dist/esm/middleware/body-limit.js +1 -1
- package/dist/esm/middleware/body-limit.js.map +1 -1
- package/dist/esm/middleware/compress.js +1 -1
- package/dist/esm/middleware/compress.js.map +1 -1
- package/dist/esm/middleware/cors.js +1 -1
- package/dist/esm/middleware/cors.js.map +1 -1
- package/dist/esm/middleware/csrf.js +1 -1
- package/dist/esm/middleware/csrf.js.map +1 -1
- package/dist/esm/middleware/etag.js +1 -1
- package/dist/esm/middleware/etag.js.map +1 -1
- package/dist/esm/middleware/jwk.d.ts +4 -5
- package/dist/esm/middleware/jwk.js +11 -4
- package/dist/esm/middleware/jwk.js.map +1 -1
- package/dist/esm/middleware/jwt.d.ts +7 -5
- package/dist/esm/middleware/jwt.js +11 -5
- package/dist/esm/middleware/jwt.js.map +1 -1
- package/dist/esm/middleware/secure-headers.js +1 -1
- package/dist/esm/middleware/secure-headers.js.map +1 -1
- package/dist/esm/middleware/timing.js +1 -1
- package/dist/esm/middleware/timing.js.map +1 -1
- package/dist/esm/middleware/wrap-hono.d.ts +3 -0
- package/dist/esm/middleware/wrap-hono.js +9 -0
- package/dist/esm/middleware/wrap-hono.js.map +1 -0
- package/dist/esm/middleware.js.map +1 -1
- package/dist/esm/reply.d.ts +2 -0
- package/dist/esm/reply.js +2 -0
- package/dist/esm/route.d.ts +1 -1
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/stream.d.ts +1 -0
- package/dist/esm/stream.js +2 -0
- package/dist/esm/taser-app.d.ts +0 -3
- package/dist/esm/taser-app.js +1 -6
- package/dist/esm/taser-app.js.map +1 -1
- package/dist/esm/taser-router.d.ts +9 -11
- package/dist/esm/taser-router.js +7 -8
- package/dist/esm/taser-router.js.map +1 -1
- package/dist/esm/types/app.d.ts +3 -2
- package/dist/esm/types/index.d.ts +53 -139
- package/dist/esm/types/type-utils.d.ts +8 -11
- package/dist/esm/types/units.d.ts +27 -24
- package/dist/esm/types/units.js.map +1 -1
- package/package.json +37 -17
- package/src/constants.ts +6 -6
- package/src/create-context.ts +8 -8
- package/src/define/handler.ts +24 -34
- package/src/define/middleware.ts +66 -256
- package/src/define/validators.ts +10 -10
- package/src/factories.ts +63 -61
- package/src/index.ts +13 -12
- package/src/middleware/body-limit.ts +5 -5
- package/src/middleware/compress.ts +5 -5
- package/src/middleware/cors.ts +5 -5
- package/src/middleware/csrf.ts +5 -5
- package/src/middleware/etag.ts +5 -5
- package/src/middleware/jwk.ts +33 -26
- package/src/middleware/jwt.ts +26 -10
- package/src/middleware/secure-headers.ts +5 -5
- package/src/middleware/timing.ts +5 -5
- package/src/middleware/wrap-hono.ts +12 -0
- package/src/middleware.ts +7 -7
- package/src/reply.ts +11 -0
- package/src/route.ts +45 -48
- package/src/stream.ts +1 -0
- package/src/taser-app.ts +13 -18
- package/src/taser-router.ts +103 -98
- package/src/types/app.ts +33 -35
- package/src/types/index.ts +299 -722
- package/src/types/returns.ts +92 -97
- package/src/types/schema.ts +8 -9
- package/src/types/type-utils.ts +42 -46
- package/src/types/units.ts +135 -104
- package/dist/cjs/middleware/auth.cjs +0 -34
- package/dist/cjs/middleware/auth.cjs.map +0 -1
- package/dist/cjs/middleware/auth.d.cts +0 -9
- package/dist/esm/middleware/auth.d.ts +0 -9
- package/dist/esm/middleware/auth.js +0 -33
- package/dist/esm/middleware/auth.js.map +0 -1
- package/src/middleware/auth.ts +0 -51
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { blob, buffer, file, pipe, stream } from '@taserjs/router-utils';
|
package/dist/esm/taser-app.d.ts
CHANGED
|
@@ -11,11 +11,8 @@ export declare class TaserNativeBound {
|
|
|
11
11
|
constructor(runtime: TaserRuntime, boundNative: unknown);
|
|
12
12
|
fetch(request: Request, env?: unknown, executionCtx?: unknown): Promise<Response>;
|
|
13
13
|
}
|
|
14
|
-
export declare class TaserMountedApp extends TaserServeView {
|
|
15
|
-
}
|
|
16
14
|
export declare class TaserApp<TManifest extends RouteManifestShape = RouteManifestShape> extends TaserServeView {
|
|
17
15
|
readonly __manifest?: TManifest;
|
|
18
16
|
constructor(runtime: TaserRuntime, manifest?: TManifest);
|
|
19
|
-
base(prefix: string): TaserMountedApp;
|
|
20
17
|
}
|
|
21
18
|
export {};
|
package/dist/esm/taser-app.js
CHANGED
|
@@ -22,19 +22,14 @@ var TaserNativeBound = class {
|
|
|
22
22
|
return this.runtime.native(this.boundNative).fetch(request, env, executionCtx);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
var TaserMountedApp = class extends TaserServeView {};
|
|
26
25
|
var TaserApp = class extends TaserServeView {
|
|
27
26
|
__manifest;
|
|
28
27
|
constructor(runtime, manifest) {
|
|
29
28
|
super(runtime);
|
|
30
29
|
if (manifest !== void 0) this.__manifest = manifest;
|
|
31
30
|
}
|
|
32
|
-
base(prefix) {
|
|
33
|
-
this.runtime.registerRoutePrefix(prefix);
|
|
34
|
-
return new TaserMountedApp(this.runtime);
|
|
35
|
-
}
|
|
36
31
|
};
|
|
37
32
|
//#endregion
|
|
38
|
-
export { TaserApp,
|
|
33
|
+
export { TaserApp, TaserNativeBound };
|
|
39
34
|
|
|
40
35
|
//# sourceMappingURL=taser-app.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taser-app.js","names":[],"sources":["../../src/taser-app.ts"],"sourcesContent":["import type { TaserRuntime } from
|
|
1
|
+
{"version":3,"file":"taser-app.js","names":[],"sources":["../../src/taser-app.ts"],"sourcesContent":["import type { TaserRuntime } from \"@taserjs/router-core\";\nimport type { RouteManifestShape } from \"@taserjs/router-core\";\n\nclass TaserServeView {\n constructor(protected readonly runtime: TaserRuntime) {}\n\n fetch(request: Request, env?: unknown, executionCtx?: unknown): Promise<Response> {\n return this.runtime.fetch(request, env, executionCtx as never);\n }\n\n native(native: unknown): TaserNativeBound {\n return new TaserNativeBound(this.runtime, native);\n }\n}\n\nexport class TaserNativeBound {\n constructor(\n private readonly runtime: TaserRuntime,\n private readonly boundNative: unknown,\n ) {}\n\n fetch(request: Request, env?: unknown, executionCtx?: unknown): Promise<Response> {\n return this.runtime.native(this.boundNative).fetch(request, env, executionCtx as never);\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":";AAGA,IAAM,iBAAN,MAAqB;CACY;CAA/B,YAAY,SAA0C;EAAvB,KAAA,UAAA;CAAwB;CAEvD,MAAM,SAAkB,KAAe,cAA2C;EAChF,OAAO,KAAK,QAAQ,MAAM,SAAS,KAAK,YAAqB;CAC/D;CAEA,OAAO,QAAmC;EACxC,OAAO,IAAI,iBAAiB,KAAK,SAAS,MAAM;CAClD;AACF;AAEA,IAAa,mBAAb,MAA8B;CAET;CACA;CAFnB,YACE,SACA,aACA;EAFiB,KAAA,UAAA;EACA,KAAA,cAAA;CAChB;CAEH,MAAM,SAAkB,KAAe,cAA2C;EAChF,OAAO,KAAK,QAAQ,OAAO,KAAK,WAAW,CAAC,CAAC,MAAM,SAAS,KAAK,YAAqB;CACxF;AACF;AAEA,IAAa,WAAb,cAEU,eAAe;CACvB;CAEA,YAAY,SAAuB,UAAsB;EACvD,MAAM,OAAO;EACb,IAAI,aAAa,KAAA,GACf,KAAK,aAAa;CAEtB;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NotFoundHandler, OnErrorHandler, RouteManifestShape } from '@taserjs/router-core';
|
|
2
|
-
import { defineMiddleware } from './define/middleware.js';
|
|
3
2
|
import { TaserApp } from './taser-app.js';
|
|
4
3
|
import { ContextDefinition, CreateTaserAppOptions, OnErrorOptions } from './types/app.js';
|
|
5
4
|
import { AppContext } from './types/units.js';
|
|
@@ -14,17 +13,17 @@ type RouterState = {
|
|
|
14
13
|
};
|
|
15
14
|
export declare class TaserRouter<TAppContext extends Record<string, unknown> = AppContext> {
|
|
16
15
|
private readonly state;
|
|
17
|
-
constructor(options?: CreateTaserAppOptions, state?: Partial<Omit<RouterState,
|
|
16
|
+
constructor(options?: CreateTaserAppOptions, state?: Partial<Omit<RouterState, "options">>);
|
|
18
17
|
context<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>>(definition: ContextDefinition<TBoot, TReq>): TaserRouter<TBoot & TReq>;
|
|
19
|
-
onError<TResponses extends import('./types/returns.js').ReturnsMap = import('./types/returns.js').ReturnsMap>(options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>[
|
|
18
|
+
onError<TResponses extends import('./types/returns.js').ReturnsMap = import('./types/returns.js').ReturnsMap>(options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>["handle"]): this;
|
|
20
19
|
notFound(handler: (ctx: unknown) => Response | Promise<Response> | unknown): this;
|
|
21
|
-
get: CreateWithoutBodyRoute<
|
|
22
|
-
post: CreateWithBodyRoute<
|
|
23
|
-
put: CreateWithBodyRoute<
|
|
24
|
-
patch: CreateWithBodyRoute<
|
|
25
|
-
delete: CreateWithoutBodyRoute<
|
|
26
|
-
options: CreateWithoutBodyRoute<
|
|
27
|
-
head: CreateWithoutBodyRoute<
|
|
20
|
+
get: CreateWithoutBodyRoute<"GET", TAppContext>;
|
|
21
|
+
post: CreateWithBodyRoute<"POST", TAppContext>;
|
|
22
|
+
put: CreateWithBodyRoute<"PUT", TAppContext>;
|
|
23
|
+
patch: CreateWithBodyRoute<"PATCH", TAppContext>;
|
|
24
|
+
delete: CreateWithoutBodyRoute<"DELETE", TAppContext>;
|
|
25
|
+
options: CreateWithoutBodyRoute<"OPTIONS", TAppContext>;
|
|
26
|
+
head: CreateWithoutBodyRoute<"HEAD", TAppContext>;
|
|
28
27
|
any: CreateAnyRoute<TAppContext>;
|
|
29
28
|
all: CreateAllRoute<TAppContext>;
|
|
30
29
|
middleware<const Layout extends LayoutId>(layout: Layout): MiddlewareBuilder<Layout, readonly [], TAppContext>;
|
|
@@ -37,7 +36,6 @@ export declare class TaserRouter<TAppContext extends Record<string, unknown> = A
|
|
|
37
36
|
params: TParams;
|
|
38
37
|
body: TBody;
|
|
39
38
|
}, {}, TAppContext>;
|
|
40
|
-
defineMiddleware(): ReturnType<typeof defineMiddleware<TAppContext>>;
|
|
41
39
|
create<const TManifest extends RouteManifestShape>(manifest: TManifest): TaserApp<TManifest>;
|
|
42
40
|
}
|
|
43
41
|
export declare function createTaserApp(options?: CreateTaserAppOptions): TaserRouter;
|
package/dist/esm/taser-router.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createAllRoute, createAnyRoute, createDeleteRoute, createGetRoute, createHeadRoute, createOptionsRoute, createPatchRoute, createPostRoute, createPutRoute } from "./factories.js";
|
|
2
2
|
import { defineHandler } from "./define/handler.js";
|
|
3
|
-
import { defineMiddleware } from "./define/middleware.js";
|
|
4
3
|
import { createMiddleware } from "./middleware.js";
|
|
5
4
|
import { TaserApp } from "./taser-app.js";
|
|
6
5
|
import { normalizeOnError } from "@taserjs/router-utils";
|
|
@@ -47,22 +46,22 @@ var TaserRouter = class {
|
|
|
47
46
|
defineHandler(options) {
|
|
48
47
|
return options === void 0 ? defineHandler() : defineHandler(options);
|
|
49
48
|
}
|
|
50
|
-
defineMiddleware() {
|
|
51
|
-
return defineMiddleware();
|
|
52
|
-
}
|
|
53
49
|
create(manifest) {
|
|
54
50
|
const definition = this.state.contextDef;
|
|
55
51
|
const validateResponse = this.state.options.response?.validate ?? true;
|
|
56
52
|
const onValidationFailure = this.state.options.response?.onValidationFailure;
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
const basePath = this.state.options.basePath;
|
|
54
|
+
const hasCustomContext = definition.boot !== void 0 || definition.request !== void 0;
|
|
55
|
+
const bootPromise = hasCustomContext ? Promise.resolve(definition.boot?.() ?? {}) : void 0;
|
|
56
|
+
return new TaserApp(createTaserRuntime(manifest, hasCustomContext ? async ({ native } = {}) => {
|
|
57
|
+
const bootContext = await bootPromise ?? {};
|
|
60
58
|
const requestContext = await definition.request?.({ native }) ?? {};
|
|
61
59
|
return {
|
|
62
60
|
...bootContext,
|
|
63
61
|
...requestContext
|
|
64
62
|
};
|
|
65
|
-
}, {
|
|
63
|
+
} : () => ({}), {
|
|
64
|
+
...basePath !== void 0 ? { basePath } : {},
|
|
66
65
|
response: {
|
|
67
66
|
validate: validateResponse,
|
|
68
67
|
...onValidationFailure !== void 0 ? { onValidationFailure } : {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"taser-router.js","names":[],"sources":["../../src/taser-router.ts"],"sourcesContent":["import {\n createTaserRuntime,\n type NotFoundHandler,\n type OnErrorHandler,\n type RouteManifestShape,\n} from
|
|
1
|
+
{"version":3,"file":"taser-router.js","names":[],"sources":["../../src/taser-router.ts"],"sourcesContent":["import {\n createTaserRuntime,\n type NotFoundHandler,\n type OnErrorHandler,\n type RouteManifestShape,\n} from \"@taserjs/router-core\";\nimport { 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 { createMiddleware } from \"./middleware.js\";\nimport { TaserApp } from \"./taser-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 { 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<TAppContext extends Record<string, unknown> = AppContext> {\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> {\n this.state.contextDef = definition;\n return this as unknown as TaserRouter<TBoot & TReq>;\n }\n\n onError<\n TResponses extends import(\"./types/returns.js\").ReturnsMap =\n import(\"./types/returns.js\").ReturnsMap,\n >(options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>[\"handle\"]): this {\n this.state.onError = toOnErrorHandler(options);\n return this;\n }\n\n notFound(handler: (ctx: unknown) => Response | Promise<Response> | unknown): this {\n this.state.notFound = (ctx) => handler(ctx);\n return this;\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 create<const TManifest extends RouteManifestShape>(manifest: TManifest): TaserApp<TManifest> {\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 = this.state.options.basePath;\n\n const hasCustomContext = definition.boot !== undefined || definition.request !== undefined;\n const bootPromise = hasCustomContext\n ? Promise.resolve(definition.boot?.() ?? ({} as Record<string, unknown>))\n : undefined;\n\n const contextFactory = hasCustomContext\n ? async ({ native }: { native?: unknown } = {}) => {\n const bootContext = (await bootPromise) ?? {};\n const requestContext = (await definition.request?.({ native: native as never })) ?? {};\n return { ...bootContext, ...requestContext };\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);\n }\n}\n\nexport function createTaserApp(options: CreateTaserAppOptions = {}): TaserRouter {\n return new TaserRouter(options);\n}\n"],"mappings":";;;;;;;AAiCA,SAAS,iBACP,gBACgB;CAChB,OAAO,iBAAiB,cAAc;AACxC;AASA,IAAM,eAAoF,CAAC;AAE3F,IAAa,cAAb,MAAmF;CACjF;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,YAC2B;EAC3B,KAAK,MAAM,aAAa;EACxB,OAAO;CACT;CAEA,QAGE,SAAkF;EAClF,KAAK,MAAM,UAAU,iBAAiB,OAAO;EAC7C,OAAO;CACT;CAEA,SAAS,SAAyE;EAChF,KAAK,MAAM,YAAY,QAAQ,QAAQ,GAAG;EAC1C,OAAO;CACT;CAEA,MAAkD;CAIlD,OAAiD;CAIjD,MAA+C;CAI/C,QAAmD;CAInD,SACE;CACF,UACE;CACF,OAAoD;CAIpD,MAAmC;CACnC,MAAmC;CAEnC,WACE,QACqD;EACrD,OAAO,iBAAiB,MAAM;CAChC;CAEA,cAAoE,SASlE;EACA,OAAO,YAAY,KAAA,IACf,cAA2B,IAC3B,cAA2B,OAAO;CACxC;CAEA,OAAmD,UAA0C;EAC3F,MAAM,aAAa,KAAK,MAAM;EAC9B,MAAM,mBAAmB,KAAK,MAAM,QAAQ,UAAU,YAAY;EAClE,MAAM,sBAAsB,KAAK,MAAM,QAAQ,UAAU;EACzD,MAAM,WAAW,KAAK,MAAM,QAAQ;EAEpC,MAAM,mBAAmB,WAAW,SAAS,KAAA,KAAa,WAAW,YAAY,KAAA;EACjF,MAAM,cAAc,mBAChB,QAAQ,QAAQ,WAAW,OAAO,KAAM,CAAC,CAA6B,IACtE,KAAA;EAqBJ,OAAO,IAAI,SAXK,mBAAmB,UARZ,mBACnB,OAAO,EAAE,WAAiC,CAAC,MAAM;GAC/C,MAAM,cAAe,MAAM,eAAgB,CAAC;GAC5C,MAAM,iBAAkB,MAAM,WAAW,UAAU,EAAU,OAAgB,CAAC,KAAM,CAAC;GACrF,OAAO;IAAE,GAAG;IAAa,GAAG;GAAe;EAC7C,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,eAAe,UAAiC,CAAC,GAAgB;CAC/E,OAAO,IAAI,YAAY,OAAO;AAChC"}
|
package/dist/esm/types/app.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { TaserApp } from '../taser-app.js';
|
|
|
3
3
|
import { ReturnsMap } from './returns.js';
|
|
4
4
|
import { Schema } from './schema.js';
|
|
5
5
|
export type CreateTaserAppOptions = {
|
|
6
|
+
basePath?: string;
|
|
6
7
|
response?: {
|
|
7
8
|
/** Validate handler replies against returns maps. Default true. */
|
|
8
9
|
validate?: boolean;
|
|
@@ -13,7 +14,7 @@ export type CreateTaserAppOptions = {
|
|
|
13
14
|
secret?: string | BufferSource;
|
|
14
15
|
path?: string;
|
|
15
16
|
httpOnly?: boolean;
|
|
16
|
-
sameSite?:
|
|
17
|
+
sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
|
|
17
18
|
secure?: boolean;
|
|
18
19
|
domain?: string;
|
|
19
20
|
maxAge?: number;
|
|
@@ -43,4 +44,4 @@ export type TaserHandler<TFrameworkApp> = {
|
|
|
43
44
|
};
|
|
44
45
|
export type { RouteManifestShape } from '@taserjs/router-core';
|
|
45
46
|
export type { Schema };
|
|
46
|
-
export type { TaserApp,
|
|
47
|
+
export type { TaserApp, TaserNativeBound } from '../taser-app.js';
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { Awaitable, TaserCookieJar, TaserHeaders } from '@taserjs/router-core';
|
|
2
|
-
import { ReplyResult } from '@taserjs/router-utils';
|
|
3
2
|
import { RouterRegister } from '../register.js';
|
|
4
3
|
import { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape, RuntimeContextFields, Simplify } from './type-utils.js';
|
|
5
4
|
import { ReturnsMap, ValidHandlerReply } from './returns.js';
|
|
6
5
|
import { Schema } from './schema.js';
|
|
7
|
-
import { AppContext, HandlerContext, HandlerUnit, Method, MiddlewareDefinition, MiddlewareReturnFromParts, MiddlewareUnit, NativeContext, ValidatorParts } from './units.js';
|
|
6
|
+
import { AppContext, ExtractState, HandlerContext, HandlerUnit, InlineMiddlewareOptions, Method, MiddlewareDefinition, MiddlewareReturnFromParts, MiddlewareUnit, NativeContext, ValidatorParts } from './units.js';
|
|
8
7
|
export type { Awaitable } from '@taserjs/router-core';
|
|
9
8
|
export type { SchemaRequestShape, InferInput, InferOutput, Schema, StandardSchemaV1, } from './schema.js';
|
|
10
9
|
export type { RouterRegister } from '../register.js';
|
|
11
10
|
export type { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape, Simplify, UnwrapPart, } from './type-utils.js';
|
|
12
11
|
export type { EmptyReturns, EnforceHandlerReply, HandlerReply, HasReturns, MergeReturns, ReplyResultFor, ReturnsMap, StatusCode, ValidHandlerReply, } from './returns.js';
|
|
13
|
-
export type { AppContext, HandlerContext, HandlerUnit, HttpMethod, InlineMiddlewareOptions, Method, MiddlewareDefinition, MiddlewareNext, MiddlewareReturnFromParts, MiddlewareUnit, NativeContext, StandaloneMiddlewareContext, ValidatorParts, } from './units.js';
|
|
12
|
+
export type { AppContext, ExtractState, HandlerContext, HandlerUnit, HttpMethod, InlineMiddlewareOptions, IsUnknown, Method, MiddlewareDefinition, MiddlewareNext, MiddlewareReturnFromParts, MiddlewareUnit, NativeContext, NextFn, NextResult, StandaloneMiddlewareContext, StateBrand, ValidatorParts, } from './units.js';
|
|
14
13
|
export type RoutePath = RouterRegister extends {
|
|
15
14
|
RoutePath: infer P;
|
|
16
15
|
} ? P : never;
|
|
@@ -23,9 +22,9 @@ export type LayoutTree = RouterRegister extends {
|
|
|
23
22
|
export type RouteByPathMethod = RouterRegister extends {
|
|
24
23
|
RouteByPathMethod: infer R;
|
|
25
24
|
} ? R : Record<never, never>;
|
|
26
|
-
type ParseParam<Segment extends string> = Segment extends
|
|
25
|
+
type ParseParam<Segment extends string> = Segment extends "*" ? {
|
|
27
26
|
_splat: string;
|
|
28
|
-
} : Segment extends `:${infer Name extends string}` ? Name extends
|
|
27
|
+
} : Segment extends `:${infer Name extends string}` ? Name extends "" ? {} : {
|
|
29
28
|
[K in Name]: string;
|
|
30
29
|
} : {};
|
|
31
30
|
type ParseParamsFromSegments<S extends string> = S extends `${infer Segment}/${infer Rest}` ? ParseParam<Segment> & ParseParamsFromSegments<Rest> : ParseParam<S>;
|
|
@@ -35,11 +34,14 @@ type LayoutParent<Layout extends LayoutId> = LayoutTree[Layout] extends {
|
|
|
35
34
|
} ? Parent : null;
|
|
36
35
|
type ResolveLayoutMiddlewares<Layout extends LayoutId | null> = Layout extends null ? readonly [] : Layout extends LayoutId ? readonly [
|
|
37
36
|
...ResolveLayoutMiddlewares<LayoutParent<Layout>>,
|
|
38
|
-
...LayoutTree[Layout][
|
|
37
|
+
...LayoutTree[Layout]["middlewares"]
|
|
39
38
|
] : readonly [];
|
|
40
39
|
/** Fold layout middleware Acc from a route's layoutChain (shallow → deep). */
|
|
41
|
-
type ResolveLayoutChainMiddlewares<Chain extends readonly LayoutId[]> = Chain extends readonly [
|
|
42
|
-
|
|
40
|
+
type ResolveLayoutChainMiddlewares<Chain extends readonly LayoutId[]> = Chain extends readonly [
|
|
41
|
+
infer Head extends LayoutId,
|
|
42
|
+
...infer Rest
|
|
43
|
+
] ? readonly [
|
|
44
|
+
...LayoutTree[Head]["middlewares"],
|
|
43
45
|
...ResolveLayoutChainMiddlewares<Rest extends readonly LayoutId[] ? Rest : readonly []>
|
|
44
46
|
] : readonly [];
|
|
45
47
|
type RouteEntry<Path extends RoutePath, TMethod extends Method> = RouteByPathMethod[Path] extends {
|
|
@@ -51,15 +53,14 @@ type RouteParent<Path extends RoutePath, TMethod extends Method> = RouteEntry<Pa
|
|
|
51
53
|
type RouteLayoutChain<Path extends RoutePath, TMethod extends Method> = RouteEntry<Path, TMethod> extends {
|
|
52
54
|
layoutChain: infer Chain extends readonly LayoutId[];
|
|
53
55
|
} ? Chain : RouteParent<Path, TMethod> extends LayoutId ? readonly [RouteParent<Path, TMethod>] : readonly [];
|
|
54
|
-
type RouteResolvedField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends
|
|
55
|
-
type
|
|
56
|
-
type
|
|
57
|
-
type
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
state: Simplify<RouteChainField<Path, TMethod, Acc, 'state'>>;
|
|
56
|
+
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>;
|
|
57
|
+
type RouteChainField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body" | "state"> = RouteResolvedField<Path, TMethod, Acc, Field>;
|
|
58
|
+
type UnitRuntimeContext = Omit<RuntimeContextFields<NativeContext>, "var">;
|
|
59
|
+
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 & {
|
|
60
|
+
query: Simplify<MergePart<TQuery, RouteChainField<Path, TMethod, Acc, "query">>>;
|
|
61
|
+
params: Simplify<PathParams<Path> & MergePart<TParams, RouteChainField<Path, TMethod, Acc, "params">>>;
|
|
62
|
+
body: Simplify<MergePart<TBody, RouteChainField<Path, TMethod, Acc, "body">>>;
|
|
63
|
+
state: Simplify<RouteChainField<Path, TMethod, Acc, "state">>;
|
|
63
64
|
headers: TaserHeaders;
|
|
64
65
|
cookies: TaserCookieJar;
|
|
65
66
|
}>;
|
|
@@ -67,40 +68,40 @@ export type RouteHandleContext<Path extends RoutePath, TMethod extends Method, A
|
|
|
67
68
|
query?: unknown;
|
|
68
69
|
params?: unknown;
|
|
69
70
|
body?: unknown;
|
|
70
|
-
}, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext &
|
|
71
|
+
}, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
71
72
|
path: Path;
|
|
72
73
|
method: TMethod;
|
|
73
74
|
query: Simplify<MergePart<Validators extends {
|
|
74
75
|
query?: infer Q;
|
|
75
|
-
} ? Q : unknown, RouteResolvedField<Path, TMethod, Acc,
|
|
76
|
+
} ? Q : unknown, RouteResolvedField<Path, TMethod, Acc, "query">>>;
|
|
76
77
|
params: Simplify<PathParams<Path> & MergePart<Validators extends {
|
|
77
78
|
params?: infer P;
|
|
78
|
-
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc,
|
|
79
|
+
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params">>>;
|
|
79
80
|
body: Simplify<MergePart<Validators extends {
|
|
80
81
|
body?: infer B;
|
|
81
|
-
} ? B : unknown, RouteResolvedField<Path, TMethod, Acc,
|
|
82
|
-
state: Simplify<RouteResolvedField<Path, TMethod, Acc,
|
|
82
|
+
} ? B : unknown, RouteResolvedField<Path, TMethod, Acc, "body">>>;
|
|
83
|
+
state: Simplify<RouteResolvedField<Path, TMethod, Acc, "state">>;
|
|
83
84
|
headers: TaserHeaders;
|
|
84
85
|
cookies: TaserCookieJar;
|
|
85
86
|
}>;
|
|
86
87
|
export type RouteHandleContextWithoutBody<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends {
|
|
87
88
|
query?: unknown;
|
|
88
89
|
params?: unknown;
|
|
89
|
-
}, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext &
|
|
90
|
+
}, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
90
91
|
path: Path;
|
|
91
92
|
method: TMethod;
|
|
92
93
|
query: Simplify<MergePart<Validators extends {
|
|
93
94
|
query?: infer Q;
|
|
94
|
-
} ? Q : unknown, RouteResolvedField<Path, TMethod, Acc,
|
|
95
|
+
} ? Q : unknown, RouteResolvedField<Path, TMethod, Acc, "query">>>;
|
|
95
96
|
params: Simplify<PathParams<Path> & MergePart<Validators extends {
|
|
96
97
|
params?: infer P;
|
|
97
|
-
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc,
|
|
98
|
+
} ? P : unknown, RouteResolvedField<Path, TMethod, Acc, "params">>>;
|
|
98
99
|
body: never;
|
|
99
|
-
state: Simplify<RouteResolvedField<Path, TMethod, Acc,
|
|
100
|
+
state: Simplify<RouteResolvedField<Path, TMethod, Acc, "state">>;
|
|
100
101
|
headers: TaserHeaders;
|
|
101
102
|
cookies: TaserCookieJar;
|
|
102
103
|
}>;
|
|
103
|
-
type RouteResolvedInputField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends
|
|
104
|
+
type RouteResolvedInputField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body"> = MergeMiddlewareInputField<ResolveLayoutChainMiddlewares<RouteLayoutChain<Path, TMethod>>, Field> & MergeMiddlewareInputField<Acc, Field>;
|
|
104
105
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
105
106
|
type IsEmptyObject<T> = [keyof T] extends [never] ? true : false;
|
|
106
107
|
type InputFacet<T, K extends string> = IsNever<T> extends true ? {} : IsEmptyObject<T> extends true ? {} : {
|
|
@@ -110,19 +111,19 @@ type RouteQueryInput<Path extends RoutePath, TMethod extends Method, Acc extends
|
|
|
110
111
|
queryIn?: infer QI;
|
|
111
112
|
} ? QI : unknown, Validators extends {
|
|
112
113
|
query?: infer Q;
|
|
113
|
-
} ? Q : unknown>, RouteResolvedInputField<Path, TMethod, Acc,
|
|
114
|
+
} ? Q : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "query">>>;
|
|
114
115
|
type RouteParamsInput<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts> = Simplify<PathParams<Path> & MergePart<RequestShape<Validators extends {
|
|
115
116
|
paramsIn?: infer PI;
|
|
116
117
|
} ? PI : unknown, Validators extends {
|
|
117
118
|
params?: infer P;
|
|
118
|
-
} ? P : unknown>, RouteResolvedInputField<Path, TMethod, Acc,
|
|
119
|
+
} ? P : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "params">>>;
|
|
119
120
|
type RouteBodyInput<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts> = Simplify<MergePart<RequestShape<Validators extends {
|
|
120
121
|
bodyIn?: infer BI;
|
|
121
122
|
} ? BI : unknown, Validators extends {
|
|
122
123
|
body?: infer B;
|
|
123
|
-
} ? B : unknown>, RouteResolvedInputField<Path, TMethod, Acc,
|
|
124
|
-
export type RouteHandleInputWithoutBody<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts = {}> = Simplify<InputFacet<RouteQueryInput<Path, TMethod, Acc, Validators>,
|
|
125
|
-
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>,
|
|
124
|
+
} ? B : unknown>, RouteResolvedInputField<Path, TMethod, Acc, "body">>>;
|
|
125
|
+
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">>;
|
|
126
|
+
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">>;
|
|
126
127
|
export type InferRouteInput<Path extends RoutePath, TMethod extends Method> = RouteEntry<Path, TMethod> extends {
|
|
127
128
|
route: infer Route;
|
|
128
129
|
} ? Route extends {
|
|
@@ -130,54 +131,15 @@ export type InferRouteInput<Path extends RoutePath, TMethod extends Method> = Ro
|
|
|
130
131
|
Input: infer I;
|
|
131
132
|
};
|
|
132
133
|
} ? I : never : never;
|
|
133
|
-
type MiddlewareChainField<Layout extends LayoutId, Acc extends readonly unknown[], Field extends
|
|
134
|
-
export type MiddlewareChainContext<Layout extends LayoutId, Acc extends readonly unknown[], TQuery, TParams, TBody, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext &
|
|
135
|
-
query: Simplify<MergePart<TQuery, MiddlewareChainField<Layout, Acc,
|
|
136
|
-
params: Simplify<MergePart<TParams, MiddlewareChainField<Layout, Acc,
|
|
137
|
-
body: Simplify<MergePart<TBody, MiddlewareChainField<Layout, Acc,
|
|
138
|
-
state: Simplify<MiddlewareChainField<Layout, Acc,
|
|
134
|
+
type MiddlewareChainField<Layout extends LayoutId, Acc extends readonly unknown[], Field extends "query" | "params" | "body" | "state"> = MergeMiddlewareField<ResolveLayoutMiddlewares<LayoutParent<Layout>>, Field> & MergeMiddlewareField<Acc, Field>;
|
|
135
|
+
export type MiddlewareChainContext<Layout extends LayoutId, Acc extends readonly unknown[], TQuery, TParams, TBody, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
136
|
+
query: Simplify<MergePart<TQuery, MiddlewareChainField<Layout, Acc, "query">>>;
|
|
137
|
+
params: Simplify<MergePart<TParams, MiddlewareChainField<Layout, Acc, "params">>>;
|
|
138
|
+
body: Simplify<MergePart<TBody, MiddlewareChainField<Layout, Acc, "body">>>;
|
|
139
|
+
state: Simplify<MiddlewareChainField<Layout, Acc, "state">>;
|
|
139
140
|
headers: TaserHeaders;
|
|
140
141
|
cookies: TaserCookieJar;
|
|
141
142
|
}>;
|
|
142
|
-
type StatefulUseOptions<Ctx, TState, TQuery, TParams, TBody, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown> = {
|
|
143
|
-
state: Schema<TState>;
|
|
144
|
-
query?: Schema<TQuery, TQueryIn>;
|
|
145
|
-
params?: Schema<TParams, TParamsIn>;
|
|
146
|
-
body?: Schema<TBody, TBodyIn>;
|
|
147
|
-
returns?: TReturns;
|
|
148
|
-
handler: (ctx: Ctx, next: (args: {
|
|
149
|
-
state: TState;
|
|
150
|
-
}) => Promise<ReplyResult>) => Awaitable<ReplyResult | Response | unknown>;
|
|
151
|
-
};
|
|
152
|
-
type CtxUseOptions<Ctx, TCtx, TQuery, TParams, TBody, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown> = {
|
|
153
|
-
ctx: Schema<TCtx>;
|
|
154
|
-
query?: Schema<TQuery, TQueryIn>;
|
|
155
|
-
params?: Schema<TParams, TParamsIn>;
|
|
156
|
-
body?: Schema<TBody, TBodyIn>;
|
|
157
|
-
returns?: TReturns;
|
|
158
|
-
handler: (ctx: Ctx, next: (args: {
|
|
159
|
-
ctx: TCtx;
|
|
160
|
-
}) => Promise<ReplyResult>) => Awaitable<ReplyResult | Response | unknown>;
|
|
161
|
-
};
|
|
162
|
-
type StateAndCtxUseOptions<Ctx, TState, TCtx, TQuery, TParams, TBody, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown> = {
|
|
163
|
-
state: Schema<TState>;
|
|
164
|
-
ctx: Schema<TCtx>;
|
|
165
|
-
query?: Schema<TQuery, TQueryIn>;
|
|
166
|
-
params?: Schema<TParams, TParamsIn>;
|
|
167
|
-
body?: Schema<TBody, TBodyIn>;
|
|
168
|
-
returns?: TReturns;
|
|
169
|
-
handler: (ctx: Ctx, next: (args: {
|
|
170
|
-
state: TState;
|
|
171
|
-
ctx: TCtx;
|
|
172
|
-
}) => Promise<ReplyResult>) => Awaitable<ReplyResult | Response | unknown>;
|
|
173
|
-
};
|
|
174
|
-
type StatelessUseOptions<Ctx, TQuery, TParams, TBody, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown> = {
|
|
175
|
-
query?: Schema<TQuery, TQueryIn>;
|
|
176
|
-
params?: Schema<TParams, TParamsIn>;
|
|
177
|
-
body?: Schema<TBody, TBodyIn>;
|
|
178
|
-
returns?: TReturns;
|
|
179
|
-
handler: (ctx: Ctx, next: () => Promise<ReplyResult>) => Awaitable<ReplyResult | Response | unknown>;
|
|
180
|
-
};
|
|
181
143
|
export type MiddlewareBuilder<Layout extends LayoutId, Acc extends readonly unknown[] = readonly [], TAppContext extends Record<string, unknown> = AppContext> = Acc & {
|
|
182
144
|
readonly layout: Layout;
|
|
183
145
|
readonly middlewares: readonly MiddlewareDefinition[];
|
|
@@ -185,33 +147,21 @@ export type MiddlewareBuilder<Layout extends LayoutId, Acc extends readonly unkn
|
|
|
185
147
|
Context: MiddlewareChainContext<Layout, Acc, unknown, unknown, unknown, TAppContext>;
|
|
186
148
|
};
|
|
187
149
|
use<TAcc, TReturns extends ReturnsMap = {}>(unit: MiddlewareUnit<TAcc, TReturns>): MiddlewareBuilder<Layout, readonly [...Acc, TAcc], TAppContext>;
|
|
188
|
-
use<
|
|
189
|
-
...Acc,
|
|
190
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TCtx, TQueryIn, TParamsIn, TBodyIn>
|
|
191
|
-
], TAppContext>;
|
|
192
|
-
use<TState, TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown>(options: StatefulUseOptions<MiddlewareChainContext<Layout, Acc, TQuery, TParams, TBody, TAppContext>, TState, TQuery, TParams, TBody, TReturns, TQueryIn, TParamsIn, TBodyIn>): MiddlewareBuilder<Layout, readonly [
|
|
193
|
-
...Acc,
|
|
194
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, unknown, TQueryIn, TParamsIn, TBodyIn>
|
|
195
|
-
], TAppContext>;
|
|
196
|
-
use<TCtx, TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown>(options: CtxUseOptions<MiddlewareChainContext<Layout, Acc, TQuery, TParams, TBody, TAppContext>, TCtx, TQuery, TParams, TBody, TReturns, TQueryIn, TParamsIn, TBodyIn>): MiddlewareBuilder<Layout, readonly [
|
|
150
|
+
use<TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, R = unknown>(options: InlineMiddlewareOptions<MiddlewareChainContext<Layout, Acc, TQuery, TParams, TBody, TAppContext>, TQuery, TParams, TBody, TReturns, TQueryIn, TParamsIn, TBodyIn, R>): MiddlewareBuilder<Layout, readonly [
|
|
197
151
|
...Acc,
|
|
198
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody,
|
|
199
|
-
], TAppContext>;
|
|
200
|
-
use<TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown>(options: StatelessUseOptions<MiddlewareChainContext<Layout, Acc, TQuery, TParams, TBody, TAppContext>, TQuery, TParams, TBody, TReturns, TQueryIn, TParamsIn, TBodyIn>): MiddlewareBuilder<Layout, readonly [
|
|
201
|
-
...Acc,
|
|
202
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, {}, unknown, TQueryIn, TParamsIn, TBodyIn>
|
|
152
|
+
MiddlewareReturnFromParts<TQuery, TParams, TBody, ExtractState<R>, TQueryIn, TParamsIn, TBodyIn>
|
|
203
153
|
], TAppContext>;
|
|
204
154
|
};
|
|
205
155
|
export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], TReturns extends ReturnsMap = {}, TOutput = Response> = Acc & {
|
|
206
156
|
readonly path: Path;
|
|
207
|
-
readonly method: TMethod |
|
|
157
|
+
readonly method: TMethod | "ANY" | "ALL";
|
|
208
158
|
readonly methods?: readonly Method[];
|
|
209
159
|
readonly middlewares: readonly MiddlewareDefinition[];
|
|
210
160
|
readonly handlerMiddlewares: readonly MiddlewareDefinition[];
|
|
211
161
|
readonly returns?: TReturns;
|
|
212
162
|
handler: (ctx: unknown) => Awaitable<Response>;
|
|
213
163
|
readonly $Infer: {
|
|
214
|
-
Context: TMethod extends
|
|
164
|
+
Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleContextWithoutBody<Path, TMethod, Acc, {}> : RouteHandleContext<Path, TMethod, Acc, {}>;
|
|
215
165
|
/** Concrete handler reply (`ReplyOf` union) for client inference. */
|
|
216
166
|
Output: TOutput;
|
|
217
167
|
};
|
|
@@ -222,10 +172,10 @@ export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc exte
|
|
|
222
172
|
handlerParams?: Schema<unknown>;
|
|
223
173
|
handlerBody?: Schema<unknown>;
|
|
224
174
|
};
|
|
225
|
-
type RouteHandleResult<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts, TReturns extends ReturnsMap = {}, TOutput = Response, TAppContext extends Record<string, unknown> = AppContext> = Omit<RouteExport<Path, TMethod, Acc, TReturns, TOutput>,
|
|
175
|
+
type RouteHandleResult<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Validators extends ValidatorParts, TReturns extends ReturnsMap = {}, TOutput = Response, TAppContext extends Record<string, unknown> = AppContext> = Omit<RouteExport<Path, TMethod, Acc, TReturns, TOutput>, "$Infer"> & {
|
|
226
176
|
readonly $Infer: {
|
|
227
|
-
Context: TMethod extends
|
|
228
|
-
Input: TMethod extends
|
|
177
|
+
Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleContextWithoutBody<Path, TMethod, Acc, Validators, TAppContext> : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>;
|
|
178
|
+
Input: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleInputWithoutBody<Path, TMethod, Acc, Validators> : RouteHandleInput<Path, TMethod, Acc, Validators>;
|
|
229
179
|
Output: TOutput;
|
|
230
180
|
};
|
|
231
181
|
};
|
|
@@ -233,27 +183,15 @@ export type RouteBuilder<Path extends RoutePath, TMethod extends Method, Acc ext
|
|
|
233
183
|
readonly path: Path;
|
|
234
184
|
readonly method: TMethod;
|
|
235
185
|
readonly $Infer: {
|
|
236
|
-
Context: TMethod extends
|
|
186
|
+
Context: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleContextWithoutBody<Path, TMethod, Acc, Validators, TAppContext> : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>;
|
|
237
187
|
};
|
|
238
188
|
returns<const M extends ReturnsMap>(map: M): RouteBuilder<Path, TMethod, Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>;
|
|
239
189
|
use<TAcc, UReturns extends ReturnsMap = {}>(unit: MiddlewareUnit<TAcc, UReturns>): RouteBuilder<Path, TMethod, readonly [...Acc, TAcc], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
240
|
-
use<
|
|
241
|
-
...Acc,
|
|
242
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TCtx, TQueryIn, TParamsIn, TBodyIn>
|
|
243
|
-
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
244
|
-
use<TState, TQuery = unknown, TParams = unknown, TBody = unknown, UReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown>(options: StatefulUseOptions<RouteChainContext<Path, TMethod, Acc, TQuery, TParams, TBody, TAppContext>, TState, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn>): RouteBuilder<Path, TMethod, readonly [
|
|
245
|
-
...Acc,
|
|
246
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, unknown, TQueryIn, TParamsIn, TBodyIn>
|
|
247
|
-
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
248
|
-
use<TCtx, TQuery = unknown, TParams = unknown, TBody = unknown, UReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown>(options: CtxUseOptions<RouteChainContext<Path, TMethod, Acc, TQuery, TParams, TBody, TAppContext>, TCtx, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn>): RouteBuilder<Path, TMethod, readonly [
|
|
249
|
-
...Acc,
|
|
250
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, {}, TCtx, TQueryIn, TParamsIn, TBodyIn>
|
|
251
|
-
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
252
|
-
use<TQuery = unknown, TParams = unknown, TBody = unknown, UReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown>(options: StatelessUseOptions<RouteChainContext<Path, TMethod, Acc, TQuery, TParams, TBody, TAppContext>, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn>): RouteBuilder<Path, TMethod, readonly [
|
|
190
|
+
use<TQuery = unknown, TParams = unknown, TBody = unknown, UReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, R = unknown>(options: InlineMiddlewareOptions<RouteChainContext<Path, TMethod, Acc, TQuery, TParams, TBody, TAppContext>, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn, R>): RouteBuilder<Path, TMethod, readonly [
|
|
253
191
|
...Acc,
|
|
254
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody,
|
|
192
|
+
MiddlewareReturnFromParts<TQuery, TParams, TBody, ExtractState<R>, TQueryIn, TParamsIn, TBodyIn>
|
|
255
193
|
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
256
|
-
handler<R extends Response = Response>(fn: (ctx: TMethod extends
|
|
194
|
+
handler<R extends Response = Response>(fn: (ctx: TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? RouteHandleContextWithoutBody<Path, TMethod, Acc, Validators, TAppContext> : RouteHandleContext<Path, TMethod, Acc, Validators, TAppContext>) => Awaitable<R>, ..._assert: [R] extends [ValidHandlerReply<R, TReturns>] ? [] : [
|
|
257
195
|
{
|
|
258
196
|
expected: ValidHandlerReply<R, TReturns>;
|
|
259
197
|
actual: R;
|
|
@@ -264,37 +202,13 @@ export type RouteBuilder<Path extends RoutePath, TMethod extends Method, Acc ext
|
|
|
264
202
|
export type HandlerBuilder<Acc extends readonly unknown[] = readonly [], Validators extends ValidatorParts = {}, TReturns extends ReturnsMap = {}, TAppContext extends Record<string, unknown> = AppContext> = {
|
|
265
203
|
returns<const M extends ReturnsMap>(map: M): HandlerBuilder<Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>;
|
|
266
204
|
use<TAcc, UReturns extends ReturnsMap = {}>(unit: MiddlewareUnit<TAcc, UReturns>): HandlerBuilder<readonly [...Acc, TAcc], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
267
|
-
use<
|
|
268
|
-
query: TQuery;
|
|
269
|
-
params: TParams;
|
|
270
|
-
body: TBody;
|
|
271
|
-
}, TAppContext>, TState, TCtx, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn>): HandlerBuilder<readonly [
|
|
272
|
-
...Acc,
|
|
273
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TCtx, TQueryIn, TParamsIn, TBodyIn>
|
|
274
|
-
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
275
|
-
use<TState, TQuery = unknown, TParams = unknown, TBody = unknown, UReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown>(options: StatefulUseOptions<HandlerContext<Acc, {
|
|
276
|
-
query: TQuery;
|
|
277
|
-
params: TParams;
|
|
278
|
-
body: TBody;
|
|
279
|
-
}, TAppContext>, TState, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn>): HandlerBuilder<readonly [
|
|
280
|
-
...Acc,
|
|
281
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, unknown, TQueryIn, TParamsIn, TBodyIn>
|
|
282
|
-
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
283
|
-
use<TCtx, TQuery = unknown, TParams = unknown, TBody = unknown, UReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown>(options: CtxUseOptions<HandlerContext<Acc, {
|
|
284
|
-
query: TQuery;
|
|
285
|
-
params: TParams;
|
|
286
|
-
body: TBody;
|
|
287
|
-
}, TAppContext>, TCtx, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn>): HandlerBuilder<readonly [
|
|
288
|
-
...Acc,
|
|
289
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, {}, TCtx, TQueryIn, TParamsIn, TBodyIn>
|
|
290
|
-
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
291
|
-
use<TQuery = unknown, TParams = unknown, TBody = unknown, UReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown>(options: StatelessUseOptions<HandlerContext<Acc, {
|
|
205
|
+
use<TQuery = unknown, TParams = unknown, TBody = unknown, UReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, R = unknown>(options: InlineMiddlewareOptions<HandlerContext<Acc, {
|
|
292
206
|
query: TQuery;
|
|
293
207
|
params: TParams;
|
|
294
208
|
body: TBody;
|
|
295
|
-
}, TAppContext>, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn>): HandlerBuilder<readonly [
|
|
209
|
+
}, TAppContext>, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn, R>): HandlerBuilder<readonly [
|
|
296
210
|
...Acc,
|
|
297
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody,
|
|
211
|
+
MiddlewareReturnFromParts<TQuery, TParams, TBody, ExtractState<R>, TQueryIn, TParamsIn, TBodyIn>
|
|
298
212
|
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
299
213
|
handler<R extends Response = Response>(fn: (ctx: HandlerContext<Acc, Validators, TAppContext>) => Awaitable<R>, ..._assert: [R] extends [ValidHandlerReply<R, TReturns>] ? [] : [
|
|
300
214
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type Method =
|
|
1
|
+
export type Method = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD";
|
|
2
2
|
export type HttpMethod = Method;
|
|
3
|
-
export type MiddlewareFieldName =
|
|
4
|
-
export type MiddlewareInputFieldName =
|
|
3
|
+
export type MiddlewareFieldName = "query" | "params" | "body" | "state";
|
|
4
|
+
export type MiddlewareInputFieldName = "query" | "params" | "body";
|
|
5
5
|
export type UnwrapPart<T> = unknown extends T ? {} : T;
|
|
6
6
|
export type MergePart<T, Base> = unknown extends T ? Base : Base & T;
|
|
7
7
|
/** Collapse intersections so `Omit`/`keyof` treat the result as one object type. */
|
|
@@ -21,17 +21,15 @@ export type RequestShape<TIn, TOut> = unknown extends TIn ? UnwrapPart<TOut> : S
|
|
|
21
21
|
[K in keyof TIn]: K extends keyof TOut ? RequestPropType<TIn[K], TOut[K]> : TIn[K];
|
|
22
22
|
}>;
|
|
23
23
|
export type UnionToIntersection<U> = (U extends unknown ? (value: U) => void : never) extends (value: infer Value) => void ? Value : never;
|
|
24
|
-
export type MiddlewareField<Middleware, Field extends MiddlewareFieldName> = Field extends
|
|
24
|
+
export type MiddlewareField<Middleware, Field extends MiddlewareFieldName> = Field extends "query" ? Middleware extends {
|
|
25
25
|
query: infer Query;
|
|
26
|
-
} ? Query : {} : Field extends
|
|
26
|
+
} ? Query : {} : Field extends "params" ? Middleware extends {
|
|
27
27
|
params: infer Params;
|
|
28
|
-
} ? Params : {} : Field extends
|
|
28
|
+
} ? Params : {} : Field extends "body" ? Middleware extends {
|
|
29
29
|
body: infer Body;
|
|
30
|
-
} ? Body : {} : Field extends
|
|
30
|
+
} ? Body : {} : Field extends "state" ? Middleware extends {
|
|
31
31
|
state: infer State;
|
|
32
|
-
} ? State : {} :
|
|
33
|
-
ctx: infer Ctx;
|
|
34
|
-
} ? Ctx : {} : {};
|
|
32
|
+
} ? State : {} : {};
|
|
35
33
|
export type MiddlewareInputField<Middleware, Field extends MiddlewareInputFieldName> = Middleware extends {
|
|
36
34
|
input: {
|
|
37
35
|
[K in Field]: infer V;
|
|
@@ -45,7 +43,6 @@ export type RuntimeContextFields<TNative = unknown> = {
|
|
|
45
43
|
url: URL;
|
|
46
44
|
headers: import('@taserjs/router-core').TaserHeaders;
|
|
47
45
|
cookies: import('@taserjs/router-core').TaserCookieJar;
|
|
48
|
-
reply: typeof import('@taserjs/router-utils').reply;
|
|
49
46
|
var: Record<string, unknown>;
|
|
50
47
|
native?: TNative;
|
|
51
48
|
};
|