@taserjs/router 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -7
- package/dist/cjs/builder/constants.cjs +0 -6
- package/dist/cjs/builder/constants.cjs.map +1 -1
- package/dist/cjs/builder/constants.d.cts +0 -5
- package/dist/cjs/builder/factories.cjs.map +1 -1
- package/dist/cjs/builder/factories.d.cts +9 -9
- package/dist/cjs/builder/middleware-unit.cjs +64 -0
- package/dist/cjs/builder/middleware-unit.cjs.map +1 -0
- package/dist/cjs/builder/middleware-unit.d.cts +1 -0
- package/dist/cjs/builder/middleware.cjs +3 -1
- package/dist/cjs/builder/middleware.cjs.map +1 -1
- package/dist/cjs/builder/route.cjs +7 -21
- package/dist/cjs/builder/route.cjs.map +1 -1
- package/dist/cjs/builder/router.cjs +1 -20
- package/dist/cjs/builder/router.cjs.map +1 -1
- package/dist/cjs/builder/router.d.cts +6 -27
- package/dist/cjs/builder/standalone.cjs +43 -0
- package/dist/cjs/builder/standalone.cjs.map +1 -0
- package/dist/cjs/builder/standalone.d.cts +28 -0
- package/dist/cjs/define/middleware.cjs +11 -16
- package/dist/cjs/define/middleware.cjs.map +1 -1
- package/dist/cjs/define/middleware.d.cts +44 -34
- package/dist/cjs/index.cjs +15 -4
- package/dist/cjs/index.d.cts +6 -4
- package/dist/cjs/middleware/body-limit.cjs +3 -3
- package/dist/cjs/middleware/body-limit.cjs.map +1 -1
- package/dist/cjs/middleware/body-limit.d.cts +1 -1
- package/dist/cjs/middleware/compress.cjs +3 -3
- package/dist/cjs/middleware/compress.cjs.map +1 -1
- package/dist/cjs/middleware/compress.d.cts +1 -1
- package/dist/cjs/middleware/cors.cjs +3 -3
- package/dist/cjs/middleware/cors.cjs.map +1 -1
- package/dist/cjs/middleware/cors.d.cts +1 -1
- package/dist/cjs/middleware/csrf.cjs +3 -3
- package/dist/cjs/middleware/csrf.cjs.map +1 -1
- package/dist/cjs/middleware/csrf.d.cts +1 -1
- package/dist/cjs/middleware/etag.cjs +3 -3
- package/dist/cjs/middleware/etag.cjs.map +1 -1
- package/dist/cjs/middleware/etag.d.cts +1 -1
- package/dist/cjs/middleware/hono-mw.cjs +23 -0
- package/dist/cjs/middleware/hono-mw.cjs.map +1 -0
- package/dist/cjs/middleware/hono-mw.d.cts +16 -0
- package/dist/cjs/middleware/jwk.cjs +6 -2
- package/dist/cjs/middleware/jwk.cjs.map +1 -1
- package/dist/cjs/middleware/jwt.cjs +6 -2
- package/dist/cjs/middleware/jwt.cjs.map +1 -1
- package/dist/cjs/middleware/secure-headers.cjs +3 -3
- package/dist/cjs/middleware/secure-headers.cjs.map +1 -1
- package/dist/cjs/middleware/secure-headers.d.cts +1 -1
- package/dist/cjs/middleware/timing.cjs +3 -3
- package/dist/cjs/middleware/timing.cjs.map +1 -1
- package/dist/cjs/middleware/timing.d.cts +1 -1
- package/dist/cjs/types/index.d.cts +20 -52
- package/dist/cjs/types/type-utils.d.cts +2 -2
- package/dist/cjs/types/units.d.cts +18 -45
- package/dist/esm/builder/constants.d.ts +0 -5
- package/dist/esm/builder/constants.js +1 -6
- package/dist/esm/builder/constants.js.map +1 -1
- package/dist/esm/builder/factories.d.ts +9 -9
- package/dist/esm/builder/factories.js.map +1 -1
- package/dist/esm/builder/middleware-unit.d.ts +1 -0
- package/dist/esm/builder/middleware-unit.js +64 -0
- package/dist/esm/builder/middleware-unit.js.map +1 -0
- package/dist/esm/builder/middleware.js +3 -1
- package/dist/esm/builder/middleware.js.map +1 -1
- package/dist/esm/builder/route.js +7 -21
- package/dist/esm/builder/route.js.map +1 -1
- package/dist/esm/builder/router.d.ts +6 -27
- package/dist/esm/builder/router.js +1 -20
- package/dist/esm/builder/router.js.map +1 -1
- package/dist/esm/builder/standalone.d.ts +28 -0
- package/dist/esm/builder/standalone.js +32 -0
- package/dist/esm/builder/standalone.js.map +1 -0
- package/dist/esm/define/middleware.d.ts +44 -34
- package/dist/esm/define/middleware.js +11 -16
- package/dist/esm/define/middleware.js.map +1 -1
- package/dist/esm/index.d.ts +6 -4
- package/dist/esm/index.js +3 -3
- package/dist/esm/middleware/body-limit.d.ts +1 -1
- package/dist/esm/middleware/body-limit.js +3 -3
- package/dist/esm/middleware/body-limit.js.map +1 -1
- package/dist/esm/middleware/compress.d.ts +1 -1
- package/dist/esm/middleware/compress.js +3 -3
- package/dist/esm/middleware/compress.js.map +1 -1
- package/dist/esm/middleware/cors.d.ts +1 -1
- package/dist/esm/middleware/cors.js +3 -3
- package/dist/esm/middleware/cors.js.map +1 -1
- package/dist/esm/middleware/csrf.d.ts +1 -1
- package/dist/esm/middleware/csrf.js +3 -3
- package/dist/esm/middleware/csrf.js.map +1 -1
- package/dist/esm/middleware/etag.d.ts +1 -1
- package/dist/esm/middleware/etag.js +3 -3
- package/dist/esm/middleware/etag.js.map +1 -1
- package/dist/esm/middleware/hono-mw.d.ts +16 -0
- package/dist/esm/middleware/hono-mw.js +23 -0
- package/dist/esm/middleware/hono-mw.js.map +1 -0
- package/dist/esm/middleware/jwk.js +7 -3
- package/dist/esm/middleware/jwk.js.map +1 -1
- package/dist/esm/middleware/jwt.js +7 -3
- package/dist/esm/middleware/jwt.js.map +1 -1
- package/dist/esm/middleware/secure-headers.d.ts +1 -1
- package/dist/esm/middleware/secure-headers.js +3 -3
- package/dist/esm/middleware/secure-headers.js.map +1 -1
- package/dist/esm/middleware/timing.d.ts +1 -1
- package/dist/esm/middleware/timing.js +3 -3
- package/dist/esm/middleware/timing.js.map +1 -1
- package/dist/esm/types/index.d.ts +20 -52
- package/dist/esm/types/type-utils.d.ts +2 -2
- package/dist/esm/types/units.d.ts +18 -45
- package/package.json +3 -3
- package/src/builder/constants.ts +0 -6
- package/src/builder/factories.ts +2 -2
- package/src/builder/middleware-unit.ts +66 -0
- package/src/builder/middleware.ts +8 -2
- package/src/builder/route.ts +10 -34
- package/src/builder/router.ts +7 -77
- package/src/builder/standalone.ts +70 -0
- package/src/define/middleware.ts +155 -231
- package/src/index.ts +29 -3
- package/src/middleware/body-limit.ts +3 -4
- package/src/middleware/compress.ts +3 -4
- package/src/middleware/cors.ts +3 -4
- package/src/middleware/csrf.ts +3 -4
- package/src/middleware/etag.ts +3 -4
- package/src/middleware/hono-mw.ts +22 -0
- package/src/middleware/jwk.ts +10 -8
- package/src/middleware/jwt.ts +9 -7
- package/src/middleware/secure-headers.ts +3 -4
- package/src/middleware/timing.ts +3 -4
- package/src/types/index.ts +54 -196
- package/src/types/type-utils.ts +8 -4
- package/src/types/units.ts +153 -87
- package/dist/cjs/define/handler.cjs +0 -38
- package/dist/cjs/define/handler.cjs.map +0 -1
- package/dist/cjs/define/handler.d.cts +0 -13
- package/dist/cjs/middleware/wrap-hono.cjs +0 -19
- package/dist/cjs/middleware/wrap-hono.cjs.map +0 -1
- package/dist/cjs/middleware/wrap-hono.d.cts +0 -7
- package/dist/cjs/register.d.cts +0 -2
- package/dist/cjs/types/units.cjs +0 -8
- package/dist/cjs/types/units.cjs.map +0 -1
- package/dist/esm/define/handler.d.ts +0 -13
- package/dist/esm/define/handler.js +0 -38
- package/dist/esm/define/handler.js.map +0 -1
- package/dist/esm/middleware/wrap-hono.d.ts +0 -7
- package/dist/esm/middleware/wrap-hono.js +0 -18
- package/dist/esm/middleware/wrap-hono.js.map +0 -1
- package/dist/esm/register.d.ts +0 -2
- package/dist/esm/types/units.js +0 -8
- package/dist/esm/types/units.js.map +0 -1
- package/src/define/handler.ts +0 -62
- package/src/middleware/wrap-hono.ts +0 -25
- package/src/register.ts +0 -1
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Awaitable, TaserCookieJar, TaserHeaders } from '@taserjs/router-core';
|
|
2
|
-
import { RouterRegister } from '../
|
|
2
|
+
import { RouterRegister } from '../index.js';
|
|
3
3
|
import { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape, Simplify, UnionToIntersection, UnitRuntimeContext } from './type-utils.js';
|
|
4
4
|
import { ReturnsMap, ValidHandlerReply } from './returns.js';
|
|
5
5
|
import { Schema } from './schema.js';
|
|
6
|
-
import {
|
|
6
|
+
import { EmptyAppContext, ExtractState, Method, MiddlewareDefinition, MiddlewareReturnFromParts, MiddlewareUnit, NextFn, ValidatorParts } from './units.js';
|
|
7
7
|
export type { Awaitable } from '@taserjs/router-core';
|
|
8
8
|
export type { SchemaRequestShape, InferInput, InferOutput, Schema, StandardSchemaV1, } from './schema.js';
|
|
9
|
-
export type { RouterRegister } from '../register.js';
|
|
10
9
|
export type { MergeMiddlewareField, MergeMiddlewareInputField, MergePart, RequestShape, Simplify, UnitRuntimeContext, UnwrapPart, } from './type-utils.js';
|
|
11
10
|
export type { EmptyReturns, EnforceHandlerReply, HandlerReply, HasReturns, MergeReturns, ReplyFor, ReturnsMap, StatusCode, ValidHandlerReply, } from './returns.js';
|
|
12
|
-
export type {
|
|
11
|
+
export type { EmptyAppContext, ExtractState, HttpMethod, IsUnknown, Method, MiddlewareDefinition, MiddlewareReturnFromParts, MiddlewareUnit, MiddlewareUnitBuilder, NextFn, NextResult, StandaloneMiddlewareContext, StateBrand, ValidatorParts, } from './units.js';
|
|
12
|
+
export type AppContext = RouterRegister extends {
|
|
13
|
+
AppContext: infer C;
|
|
14
|
+
} ? C : EmptyAppContext;
|
|
13
15
|
export type RoutePath = RouterRegister extends {
|
|
14
16
|
RoutePath: infer P;
|
|
15
17
|
} ? P : never;
|
|
@@ -22,6 +24,7 @@ export type LayoutTree = RouterRegister extends {
|
|
|
22
24
|
export type RouteByPathMethod = RouterRegister extends {
|
|
23
25
|
RouteByPathMethod: infer R;
|
|
24
26
|
} ? R : Record<never, never>;
|
|
27
|
+
export type LayoutBuilder<TAppContext extends Record<string, unknown> = AppContext> = <const Layout extends LayoutId>(layout: Layout) => MiddlewareBuilder<Layout, readonly [], TAppContext>;
|
|
25
28
|
type ParseParam<Segment extends string> = Segment extends "*" ? {
|
|
26
29
|
_splat: string;
|
|
27
30
|
} : Segment extends `:${infer Name extends string}` ? Name extends "" ? {} : {
|
|
@@ -30,14 +33,17 @@ type ParseParam<Segment extends string> = Segment extends "*" ? {
|
|
|
30
33
|
type ParseParamsFromSegments<S extends string> = S extends `${infer Segment}/${infer Rest}` ? ParseParam<Segment> & ParseParamsFromSegments<Rest> : ParseParam<S>;
|
|
31
34
|
export type PathParams<Path extends string> = Path extends `/${infer Rest}` ? ParseParamsFromSegments<Rest> : {};
|
|
32
35
|
export type ResolveParams<TPathParams, TSchemaParams> = TSchemaParams extends Record<string, unknown> ? [keyof TSchemaParams] extends [never] ? TPathParams : Simplify<Omit<TPathParams, keyof TSchemaParams> & TSchemaParams> : TPathParams;
|
|
33
|
-
type
|
|
36
|
+
type LayoutParentsMap = RouterRegister extends {
|
|
37
|
+
LayoutParents: infer LP extends Record<string, unknown>;
|
|
38
|
+
} ? LP : {};
|
|
39
|
+
type LayoutParent<Layout extends LayoutId> = Layout extends keyof LayoutParentsMap ? LayoutParentsMap[Layout] extends LayoutId ? LayoutParentsMap[Layout] : null : LayoutTree[Layout] extends {
|
|
34
40
|
parent: infer Parent extends LayoutId | null;
|
|
35
41
|
} ? Parent : null;
|
|
36
|
-
type ResolveLayoutMiddlewares<Layout extends LayoutId | null> =
|
|
37
|
-
...ResolveLayoutMiddlewares<LayoutParent<Layout
|
|
42
|
+
type ResolveLayoutMiddlewares<Layout extends LayoutId | null, Depth extends readonly unknown[] = []> = Depth["length"] extends 10 ? readonly [] : Layout extends LayoutId ? readonly [
|
|
43
|
+
...ResolveLayoutMiddlewares<LayoutParent<Layout>, [...Depth, unknown]>,
|
|
38
44
|
...LayoutTree[Layout]["middlewares"]
|
|
39
45
|
] : readonly [];
|
|
40
|
-
export type ResolveLayoutIdChain<L extends LayoutId | null> =
|
|
46
|
+
export type ResolveLayoutIdChain<L extends LayoutId | null, Depth extends readonly unknown[] = []> = Depth["length"] extends 10 ? readonly [] : L extends LayoutId ? readonly [...ResolveLayoutIdChain<LayoutParent<L>, [...Depth, unknown]>, L] : readonly [];
|
|
41
47
|
export type ResolveLayoutMiddlewaresState<Layout extends LayoutId | null> = Layout extends LayoutId ? MergeMiddlewareField<ResolveLayoutMiddlewares<Layout>, "state"> : {};
|
|
42
48
|
export type ResolveLayoutsState<Layouts extends LayoutId | readonly LayoutId[]> = Layouts extends LayoutId ? ResolveLayoutMiddlewaresState<Layouts> : Layouts extends readonly LayoutId[] ? UnionToIntersection<Layouts[number] extends infer L extends LayoutId ? ResolveLayoutMiddlewaresState<L> : never> : {};
|
|
43
49
|
/** Fold layout middleware Acc from a route's layoutChain (shallow → deep). */
|
|
@@ -61,12 +67,11 @@ export type RouteLayoutMiddlewares<Path extends RoutePath, TMethod extends Metho
|
|
|
61
67
|
export type RouteLayoutField<Path extends RoutePath, TMethod extends Method, Field extends "query" | "params" | "body" | "state"> = MergeMiddlewareField<RouteLayoutMiddlewares<Path, TMethod>, Field>;
|
|
62
68
|
export type RouteLayoutInputField<Path extends RoutePath, TMethod extends Method, Field extends "query" | "params" | "body"> = MergeMiddlewareInputField<RouteLayoutMiddlewares<Path, TMethod>, Field>;
|
|
63
69
|
type RouteResolvedField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body" | "state"> = RouteLayoutField<Path, TMethod, Field> & MergeMiddlewareField<Acc, Field>;
|
|
64
|
-
type RouteChainField<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], Field extends "query" | "params" | "body" | "state"> = RouteResolvedField<Path, TMethod, Acc, Field>;
|
|
65
70
|
export type RouteChainContext<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], TQuery, TParams, TBody, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
66
|
-
query: Simplify<MergePart<TQuery,
|
|
67
|
-
params: Simplify<ResolveParams<PathParams<Path>, MergePart<TParams,
|
|
68
|
-
body: Simplify<MergePart<TBody,
|
|
69
|
-
state: Simplify<
|
|
71
|
+
query: Simplify<MergePart<TQuery, RouteResolvedField<Path, TMethod, Acc, "query">>>;
|
|
72
|
+
params: Simplify<ResolveParams<PathParams<Path>, MergePart<TParams, RouteResolvedField<Path, TMethod, Acc, "params">>>>;
|
|
73
|
+
body: Simplify<MergePart<TBody, RouteResolvedField<Path, TMethod, Acc, "body">>>;
|
|
74
|
+
state: Simplify<RouteResolvedField<Path, TMethod, Acc, "state">>;
|
|
70
75
|
headers: TaserHeaders;
|
|
71
76
|
cookies: TaserCookieJar;
|
|
72
77
|
}>;
|
|
@@ -169,17 +174,13 @@ export type MiddlewareBuilder<Layout extends LayoutId, Acc extends readonly unkn
|
|
|
169
174
|
actualState: MiddlewareChainField<Layout, Acc, "state">;
|
|
170
175
|
}
|
|
171
176
|
]): MiddlewareBuilder<Layout, readonly [...Acc, TAcc], TAppContext>;
|
|
172
|
-
use<
|
|
173
|
-
...Acc,
|
|
174
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, ExtractState<R>, TQueryIn, TParamsIn, TBodyIn>
|
|
175
|
-
], TAppContext>;
|
|
177
|
+
use<R = unknown>(fn: (ctx: MiddlewareChainContext<Layout, Acc, unknown, unknown, unknown, TAppContext>, next: NextFn) => Awaitable<R>): MiddlewareBuilder<Layout, readonly [...Acc, MiddlewareReturnFromParts<unknown, unknown, unknown, ExtractState<R>>], TAppContext>;
|
|
176
178
|
};
|
|
177
179
|
export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], TReturns extends ReturnsMap = {}, TOutput = Response> = Acc & {
|
|
178
180
|
readonly path: Path;
|
|
179
181
|
readonly method: TMethod | "ANY" | "ALL";
|
|
180
182
|
readonly methods?: readonly Method[];
|
|
181
183
|
readonly middlewares: readonly MiddlewareDefinition[];
|
|
182
|
-
readonly handlerMiddlewares: readonly MiddlewareDefinition[];
|
|
183
184
|
readonly returns?: TReturns;
|
|
184
185
|
readonly bodyMode?: "json" | "form" | "urlencoded";
|
|
185
186
|
handler: (ctx: unknown) => Awaitable<Response>;
|
|
@@ -191,9 +192,6 @@ export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc exte
|
|
|
191
192
|
query?: Schema<unknown>;
|
|
192
193
|
params?: Schema<unknown>;
|
|
193
194
|
body?: Schema<unknown>;
|
|
194
|
-
handlerQuery?: Schema<unknown>;
|
|
195
|
-
handlerParams?: Schema<unknown>;
|
|
196
|
-
handlerBody?: Schema<unknown>;
|
|
197
195
|
};
|
|
198
196
|
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"> & {
|
|
199
197
|
readonly $Infer: {
|
|
@@ -231,17 +229,13 @@ export type RouteBuilderBase<Path extends RoutePath, TMethod extends Method, Acc
|
|
|
231
229
|
actualState: RouteResolvedField<Path, TMethod, Acc, "state">;
|
|
232
230
|
}
|
|
233
231
|
]): RouteBuilder<Path, TMethod, readonly [...Acc, TAcc], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
234
|
-
use<
|
|
235
|
-
...Acc,
|
|
236
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, ExtractState<R>, TQueryIn, TParamsIn, TBodyIn>
|
|
237
|
-
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
232
|
+
use<R = unknown>(fn: (ctx: RouteChainContext<Path, TMethod, Acc, unknown, unknown, unknown, TAppContext>, next: NextFn) => Awaitable<R>): RouteBuilder<Path, TMethod, readonly [...Acc, MiddlewareReturnFromParts<unknown, unknown, unknown, ExtractState<R>>], Validators, TReturns, TAppContext>;
|
|
238
233
|
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>] ? [] : [
|
|
239
234
|
{
|
|
240
235
|
expected: ValidHandlerReply<R, TReturns>;
|
|
241
236
|
actual: R;
|
|
242
237
|
}
|
|
243
238
|
]): RouteHandleResult<Path, TMethod, Acc, Validators, TReturns, R, TAppContext>;
|
|
244
|
-
handler<HandlerAcc extends readonly unknown[] = readonly [], HandlerValidators extends ValidatorParts = ValidatorParts, HReturns extends ReturnsMap = {}, HOutput = Response>(unit: HandlerUnit<HandlerAcc, HandlerValidators, HReturns, HOutput>): RouteHandleResult<Path, TMethod, readonly [...Acc, ...HandlerAcc], Validators, Omit<TReturns, keyof HReturns> & HReturns, HOutput, TAppContext>;
|
|
245
239
|
};
|
|
246
240
|
export type RouteBuilder<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[] = readonly [], Validators extends ValidatorParts = {}, TReturns extends ReturnsMap = {}, TAppContext extends Record<string, unknown> = AppContext> = RouteBuilderBase<Path, TMethod, Acc, Validators, TReturns, TAppContext> & (TMethod extends "GET" | "DELETE" | "HEAD" | "OPTIONS" ? {} : {
|
|
247
241
|
body<TBody, TBodyIn = unknown>(schema: Schema<TBody, TBodyIn>): RouteBuilder<Path, TMethod, Acc, Omit<Validators, "body" | "bodyIn"> & {
|
|
@@ -253,32 +247,6 @@ export type RouteBuilder<Path extends RoutePath, TMethod extends Method, Acc ext
|
|
|
253
247
|
bodyIn: TBodyIn;
|
|
254
248
|
}, TReturns, TAppContext>;
|
|
255
249
|
});
|
|
256
|
-
export type HandlerBuilder<Acc extends readonly unknown[] = readonly [], Validators extends ValidatorParts = {}, TReturns extends ReturnsMap = {}, TAppContext extends Record<string, unknown> = AppContext> = {
|
|
257
|
-
returns<const M extends ReturnsMap>(map: M): HandlerBuilder<Acc, Validators, Omit<TReturns, keyof M> & M, TAppContext>;
|
|
258
|
-
use<TAcc, UReturns extends ReturnsMap = {}, TRequiredLayouts = unknown, TRequiredState = unknown>(unit: MiddlewareUnit<TAcc, UReturns, TRequiredLayouts, TRequiredState>, ..._assert: [IsStateSatisfied<MergeMiddlewareField<Acc, "state">, TRequiredState>] extends [
|
|
259
|
-
true
|
|
260
|
-
] ? [] : [
|
|
261
|
-
{
|
|
262
|
-
error: "Middleware cannot be attached to this handler";
|
|
263
|
-
requiredState: TRequiredState;
|
|
264
|
-
actualState: MergeMiddlewareField<Acc, "state">;
|
|
265
|
-
}
|
|
266
|
-
]): HandlerBuilder<readonly [...Acc, TAcc], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
267
|
-
use<TQuery = unknown, TParams = unknown, TBody = unknown, UReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, R = unknown>(options: InlineMiddlewareOptions<HandlerContext<Acc, {
|
|
268
|
-
query: TQuery;
|
|
269
|
-
params: TParams;
|
|
270
|
-
body: TBody;
|
|
271
|
-
}, TAppContext>, TQuery, TParams, TBody, UReturns, TQueryIn, TParamsIn, TBodyIn, R>): HandlerBuilder<readonly [
|
|
272
|
-
...Acc,
|
|
273
|
-
MiddlewareReturnFromParts<TQuery, TParams, TBody, ExtractState<R>, TQueryIn, TParamsIn, TBodyIn>
|
|
274
|
-
], Validators, Omit<TReturns, keyof UReturns> & UReturns, TAppContext>;
|
|
275
|
-
handler<R extends Response = Response>(fn: (ctx: HandlerContext<Acc, Validators, TAppContext>) => Awaitable<R>, ..._assert: [R] extends [ValidHandlerReply<R, TReturns>] ? [] : [
|
|
276
|
-
{
|
|
277
|
-
expected: ValidHandlerReply<R, TReturns>;
|
|
278
|
-
actual: R;
|
|
279
|
-
}
|
|
280
|
-
]): HandlerUnit<Acc, Validators, TReturns, R>;
|
|
281
|
-
};
|
|
282
250
|
export type RouteDefinition<Path extends RoutePath = RoutePath, TMethod extends Method = Method, Acc extends readonly unknown[] = readonly unknown[], Validators extends ValidatorParts = ValidatorParts, TReturns extends ReturnsMap = ReturnsMap, TOutput = Response, TAppContext extends Record<string, unknown> = AppContext> = RouteHandleResult<Path, TMethod, Acc, Validators, TReturns, TOutput, TAppContext>;
|
|
283
251
|
export type InferRouteContext<R> = R extends {
|
|
284
252
|
$Infer: {
|
|
@@ -37,8 +37,8 @@ export type MiddlewareInputField<Middleware, Field extends MiddlewareInputFieldN
|
|
|
37
37
|
[K in Field]: infer V;
|
|
38
38
|
};
|
|
39
39
|
} ? V : {};
|
|
40
|
-
export type MergeMiddlewareField<Middlewares extends readonly unknown[], Field extends MiddlewareFieldName> =
|
|
41
|
-
export type MergeMiddlewareInputField<Middlewares extends readonly unknown[], Field extends MiddlewareInputFieldName> =
|
|
40
|
+
export type MergeMiddlewareField<Middlewares extends readonly unknown[], Field extends MiddlewareFieldName> = Middlewares extends readonly [] ? {} : Middlewares extends readonly [infer Head, ...infer Tail] ? MiddlewareField<Head, Field> & MergeMiddlewareField<Tail, Field> : MiddlewareField<Middlewares[number], Field>;
|
|
41
|
+
export type MergeMiddlewareInputField<Middlewares extends readonly unknown[], Field extends MiddlewareInputFieldName> = Middlewares extends readonly [] ? {} : Middlewares extends readonly [infer Head, ...infer Tail] ? MiddlewareInputField<Head, Field> & MergeMiddlewareInputField<Tail, Field> : MiddlewareInputField<Middlewares[number], Field>;
|
|
42
42
|
export type RuntimeContextFields = {
|
|
43
43
|
request: Request;
|
|
44
44
|
method: Method;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { MiddlewareDefinition as CoreMiddlewareDefinition, TaserCookieJar, TaserHeaders } from '@taserjs/router-core';
|
|
2
|
+
import { RequestShape, Simplify, UnitRuntimeContext, UnwrapPart } from './type-utils.js';
|
|
3
3
|
import { ReturnsMap } from './returns.js';
|
|
4
4
|
import { Schema } from './schema.js';
|
|
5
5
|
export type { HttpMethod, Method } from './type-utils.js';
|
|
6
6
|
export type { EmptyReturns, MergeReturns, ReturnsMap, HandlerReply, HasReturns, StatusCode, ValidHandlerReply, EnforceHandlerReply, } from './returns.js';
|
|
7
7
|
/** Default empty app context for standalone units without a bound router instance. */
|
|
8
|
-
export type
|
|
8
|
+
export type EmptyAppContext = Record<never, never>;
|
|
9
9
|
export type ValidatorParts = {
|
|
10
10
|
query?: unknown;
|
|
11
11
|
params?: unknown;
|
|
@@ -18,16 +18,12 @@ export declare const StateBrand: unique symbol;
|
|
|
18
18
|
export type NextResult<TState = unknown> = Response & {
|
|
19
19
|
readonly [StateBrand]?: TState;
|
|
20
20
|
};
|
|
21
|
-
export type
|
|
22
|
-
[StateBrand]?:
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
}> extends {
|
|
26
|
-
[StateBrand]?: infer S;
|
|
27
|
-
} ? [S] extends [never] ? {} : S : {};
|
|
21
|
+
export type ExtractStateFromUnion<T> = T extends {
|
|
22
|
+
readonly [StateBrand]?: infer S;
|
|
23
|
+
} ? [S] extends [never] ? never : [unknown] extends [S] ? {} : S : never;
|
|
24
|
+
export type ExtractState<T> = [ExtractStateFromUnion<Awaited<T>>] extends [never] ? {} : ExtractStateFromUnion<Awaited<T>>;
|
|
28
25
|
export type IsUnknown<T> = [unknown] extends [T] ? true : false;
|
|
29
26
|
export type NextFn<TExpectedState = unknown> = IsUnknown<TExpectedState> extends true ? <S extends Record<string, unknown> = {}>(state?: S) => Promise<NextResult<S>> : (state: TExpectedState) => Promise<NextResult<TExpectedState>>;
|
|
30
|
-
export type MiddlewareNext = NextFn;
|
|
31
27
|
export type MiddlewareDefinition = CoreMiddlewareDefinition<ReturnsMap>;
|
|
32
28
|
export type MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TQueryIn = TQuery, TParamsIn = TParams, TBodyIn = TBody> = {
|
|
33
29
|
query: Simplify<UnwrapPart<TQuery>>;
|
|
@@ -42,7 +38,7 @@ export type MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TQueryIn =
|
|
|
42
38
|
};
|
|
43
39
|
};
|
|
44
40
|
export type DefineMiddlewareResult<TQuery, TParams, TBody, TState, R, TQueryIn = TQuery, TParamsIn = TParams, TBodyIn = TBody, TReturns extends ReturnsMap = {}, TLayout = null, TRequires = {}> = MiddlewareUnit<MiddlewareReturnFromParts<TQuery, TParams, TBody, IsUnknown<TState> extends true ? ExtractState<R> : TState, TQueryIn, TParamsIn, TBodyIn>, TReturns, TLayout, TRequires>;
|
|
45
|
-
export type StandaloneMiddlewareContext<TQuery = unknown, TParams = unknown, TBody = unknown, TAppContext extends Record<string, unknown> =
|
|
41
|
+
export type StandaloneMiddlewareContext<TQuery = unknown, TParams = unknown, TBody = unknown, TAppContext extends Record<string, unknown> = EmptyAppContext, TState = {}> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
46
42
|
query: Simplify<UnwrapPart<TQuery>>;
|
|
47
43
|
params: Simplify<UnwrapPart<TParams>>;
|
|
48
44
|
body: Simplify<UnwrapPart<TBody>>;
|
|
@@ -50,43 +46,20 @@ export type StandaloneMiddlewareContext<TQuery = unknown, TParams = unknown, TBo
|
|
|
50
46
|
headers: TaserHeaders;
|
|
51
47
|
cookies: TaserCookieJar;
|
|
52
48
|
}>;
|
|
53
|
-
export
|
|
54
|
-
query: Simplify<MergePart<Validators extends {
|
|
55
|
-
query?: infer Q;
|
|
56
|
-
} ? Q : unknown, MergeMiddlewareField<Acc, "query">>>;
|
|
57
|
-
params: Simplify<MergePart<Validators extends {
|
|
58
|
-
params?: infer P;
|
|
59
|
-
} ? P : unknown, MergeMiddlewareField<Acc, "params">>>;
|
|
60
|
-
body: Simplify<MergePart<Validators extends {
|
|
61
|
-
body?: infer B;
|
|
62
|
-
} ? B : unknown, MergeMiddlewareField<Acc, "body">>>;
|
|
63
|
-
state: Simplify<MergeMiddlewareField<Acc, "state">>;
|
|
64
|
-
headers: TaserHeaders;
|
|
65
|
-
cookies: TaserCookieJar;
|
|
66
|
-
}>;
|
|
49
|
+
export declare const MiddlewareUnitBrand: unique symbol;
|
|
67
50
|
export type MiddlewareUnit<TAcc = unknown, TReturns extends ReturnsMap = {}, TRequiredLayouts = unknown, TRequiredState = unknown> = MiddlewareDefinition & {
|
|
51
|
+
readonly [MiddlewareUnitBrand]: true;
|
|
68
52
|
readonly __middlewareAcc: TAcc;
|
|
69
53
|
readonly __returns?: TReturns;
|
|
70
54
|
readonly __requiredLayouts?: TRequiredLayouts;
|
|
71
55
|
readonly __requiredState?: TRequiredState;
|
|
72
56
|
};
|
|
73
|
-
export type
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
query?: Schema<unknown>;
|
|
82
|
-
params?: Schema<unknown>;
|
|
83
|
-
body?: Schema<unknown>;
|
|
84
|
-
};
|
|
85
|
-
export type InlineMiddlewareOptions<Ctx = unknown, TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, R = unknown> = {
|
|
86
|
-
query?: Schema<TQuery, TQueryIn>;
|
|
87
|
-
params?: Schema<TParams, TParamsIn>;
|
|
88
|
-
body?: Schema<TBody, TBodyIn>;
|
|
89
|
-
returns?: TReturns;
|
|
90
|
-
handler: (ctx: Ctx, next: NextFn) => Awaitable<R>;
|
|
57
|
+
export type MiddlewareUnitBuilder<TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TRequiredLayouts = unknown, TRequiredState = {}, TAppContext extends Record<string, unknown> = EmptyAppContext, TInheritedState = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, TExpectedState = unknown> = MiddlewareUnit<MiddlewareReturnFromParts<TQuery, TParams, TBody, IsUnknown<TExpectedState> extends true ? {} : TExpectedState, TQueryIn, TParamsIn, TBodyIn>, TReturns, TRequiredLayouts, TRequiredState> & {
|
|
58
|
+
query<Q, QIn = unknown>(schema: Schema<Q, QIn>): MiddlewareUnitBuilder<Q, TParams, TBody, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, QIn, TParamsIn, TBodyIn, TExpectedState>;
|
|
59
|
+
params<P, PIn = unknown>(schema: Schema<P, PIn>): MiddlewareUnitBuilder<TQuery, P, TBody, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, PIn, TBodyIn, TExpectedState>;
|
|
60
|
+
body<B, BIn = unknown>(schema: Schema<B, BIn>): MiddlewareUnitBuilder<TQuery, TParams, B, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, TParamsIn, BIn, TExpectedState>;
|
|
61
|
+
body<Mode extends "json" | "form" | "urlencoded", B, BIn = unknown>(mode: Mode, schema: Schema<B, BIn>): MiddlewareUnitBuilder<TQuery, TParams, B, TReturns, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, TParamsIn, BIn, TExpectedState>;
|
|
62
|
+
returns<const M extends ReturnsMap>(map: M): MiddlewareUnitBuilder<TQuery, TParams, TBody, Omit<TReturns, keyof M> & M, TRequiredLayouts, TRequiredState, TAppContext, TInheritedState, TQueryIn, TParamsIn, TBodyIn, TExpectedState>;
|
|
63
|
+
requires<Requires extends Record<string, unknown>>(): MiddlewareUnitBuilder<TQuery, TParams, TBody, TReturns, TRequiredLayouts, TRequiredState & Requires, TAppContext, TInheritedState, TQueryIn, TParamsIn, TBodyIn, TExpectedState>;
|
|
64
|
+
handler<R>(fn: (ctx: StandaloneMiddlewareContext<TQuery, TParams, TBody, TAppContext, TInheritedState & TRequiredState>, next: NextFn<TExpectedState>) => R): DefineMiddlewareResult<TQuery, TParams, TBody, IsUnknown<TExpectedState> extends true ? ExtractState<R> : TExpectedState, R, TQueryIn, TParamsIn, TBodyIn, TReturns, TRequiredLayouts, TRequiredState>;
|
|
91
65
|
};
|
|
92
|
-
export declare function isHandlerUnit(value: unknown): value is HandlerUnit<readonly unknown[], ValidatorParts>;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
/** Input schema keys validated by middleware and route handlers. Headers/cookies are parsed only. */
|
|
2
2
|
export declare const SCHEMA_KEYS: readonly ["query", "params", "body"];
|
|
3
3
|
export type SchemaKey = (typeof SCHEMA_KEYS)[number];
|
|
4
|
-
export declare const HANDLER_SCHEMA_KEY_MAP: {
|
|
5
|
-
readonly query: "handlerQuery";
|
|
6
|
-
readonly params: "handlerParams";
|
|
7
|
-
readonly body: "handlerBody";
|
|
8
|
-
};
|
|
@@ -5,12 +5,7 @@ var SCHEMA_KEYS = [
|
|
|
5
5
|
"params",
|
|
6
6
|
"body"
|
|
7
7
|
];
|
|
8
|
-
var HANDLER_SCHEMA_KEY_MAP = {
|
|
9
|
-
query: "handlerQuery",
|
|
10
|
-
params: "handlerParams",
|
|
11
|
-
body: "handlerBody"
|
|
12
|
-
};
|
|
13
8
|
//#endregion
|
|
14
|
-
export {
|
|
9
|
+
export { SCHEMA_KEYS };
|
|
15
10
|
|
|
16
11
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../../../src/builder/constants.ts"],"sourcesContent":["/** Input schema keys validated by middleware and route handlers. Headers/cookies are parsed only. */\nexport const SCHEMA_KEYS = [\"query\", \"params\", \"body\"] as const;\n\nexport type SchemaKey = (typeof SCHEMA_KEYS)[number];\n
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../../src/builder/constants.ts"],"sourcesContent":["/** Input schema keys validated by middleware and route handlers. Headers/cookies are parsed only. */\nexport const SCHEMA_KEYS = [\"query\", \"params\", \"body\"] as const;\n\nexport type SchemaKey = (typeof SCHEMA_KEYS)[number];\n"],"mappings":";;AACA,IAAa,cAAc;CAAC;CAAS;CAAU;AAAM"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { RouteBuilder, RoutePath } from '../types/index.js';
|
|
2
|
-
import {
|
|
1
|
+
import { AppContext, RouteBuilder, RoutePath } from '../types/index.js';
|
|
2
|
+
import { HttpMethod } from '../types/units.js';
|
|
3
3
|
export type CreateWithoutBodyRoute<M extends "GET" | "DELETE" | "OPTIONS" | "HEAD", TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath>(path: Path) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
|
|
4
4
|
export type CreateWithBodyRoute<M extends "POST" | "PUT" | "PATCH", TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath>(path: Path) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
|
|
5
5
|
export type CreateAnyRoute<TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath, const Methods extends readonly HttpMethod[]>(path: Path, methods: Methods) => RouteBuilder<Path, Methods[number], readonly [], {}, {}, TAppContext>;
|
|
6
6
|
export type CreateAllRoute<TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath>(path: Path) => RouteBuilder<Path, HttpMethod, readonly [], {}, {}, TAppContext>;
|
|
7
|
-
export declare const createGetRoute: CreateWithoutBodyRoute<"GET",
|
|
8
|
-
export declare const createDeleteRoute: CreateWithoutBodyRoute<"DELETE",
|
|
9
|
-
export declare const createOptionsRoute: CreateWithoutBodyRoute<"OPTIONS",
|
|
10
|
-
export declare const createHeadRoute: CreateWithoutBodyRoute<"HEAD",
|
|
11
|
-
export declare const createPostRoute: CreateWithBodyRoute<"POST",
|
|
12
|
-
export declare const createPutRoute: CreateWithBodyRoute<"PUT",
|
|
13
|
-
export declare const createPatchRoute: CreateWithBodyRoute<"PATCH",
|
|
7
|
+
export declare const createGetRoute: CreateWithoutBodyRoute<"GET", import('../index.js').EmptyAppContext>;
|
|
8
|
+
export declare const createDeleteRoute: CreateWithoutBodyRoute<"DELETE", import('../index.js').EmptyAppContext>;
|
|
9
|
+
export declare const createOptionsRoute: CreateWithoutBodyRoute<"OPTIONS", import('../index.js').EmptyAppContext>;
|
|
10
|
+
export declare const createHeadRoute: CreateWithoutBodyRoute<"HEAD", import('../index.js').EmptyAppContext>;
|
|
11
|
+
export declare const createPostRoute: CreateWithBodyRoute<"POST", import('../index.js').EmptyAppContext>;
|
|
12
|
+
export declare const createPutRoute: CreateWithBodyRoute<"PUT", import('../index.js').EmptyAppContext>;
|
|
13
|
+
export declare const createPatchRoute: CreateWithBodyRoute<"PATCH", import('../index.js').EmptyAppContext>;
|
|
14
14
|
export declare const createAnyRoute: CreateAnyRoute;
|
|
15
15
|
export declare const createAllRoute: CreateAllRoute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factories.js","names":[],"sources":["../../../src/builder/factories.ts"],"sourcesContent":["import { createRouteBuilder } from \"./route.js\";\nimport type { RouteBuilder, RoutePath } from \"../types/index.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"factories.js","names":[],"sources":["../../../src/builder/factories.ts"],"sourcesContent":["import { createRouteBuilder } from \"./route.js\";\nimport type { AppContext, RouteBuilder, RoutePath } from \"../types/index.js\";\nimport type { HttpMethod } from \"../types/units.js\";\n\nexport type CreateWithoutBodyRoute<\n M extends \"GET\" | \"DELETE\" | \"OPTIONS\" | \"HEAD\",\n TAppContext extends Record<string, unknown> = AppContext,\n> = <const Path extends RoutePath>(\n path: Path,\n) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;\n\nexport type CreateWithBodyRoute<\n M extends \"POST\" | \"PUT\" | \"PATCH\",\n TAppContext extends Record<string, unknown> = AppContext,\n> = <const Path extends RoutePath>(\n path: Path,\n) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;\n\nexport type CreateAnyRoute<TAppContext extends Record<string, unknown> = AppContext> = <\n const Path extends RoutePath,\n const Methods extends readonly HttpMethod[],\n>(\n path: Path,\n methods: Methods,\n) => RouteBuilder<Path, Methods[number], readonly [], {}, {}, TAppContext>;\n\nexport type CreateAllRoute<TAppContext extends Record<string, unknown> = AppContext> = <\n const Path extends RoutePath,\n>(\n path: Path,\n) => RouteBuilder<Path, HttpMethod, readonly [], {}, {}, TAppContext>;\n\nfunction createWithoutBodyRoute<M extends \"GET\" | \"DELETE\" | \"OPTIONS\" | \"HEAD\">(\n method: M,\n): CreateWithoutBodyRoute<M> {\n return ((path: string) =>\n createRouteBuilder(path, method)) as unknown as CreateWithoutBodyRoute<M>;\n}\n\nfunction createWithBodyRoute<M extends \"POST\" | \"PUT\" | \"PATCH\">(\n method: M,\n): CreateWithBodyRoute<M> {\n return ((path: string) => createRouteBuilder(path, method)) as unknown as CreateWithBodyRoute<M>;\n}\n\nexport const createGetRoute = createWithoutBodyRoute(\"GET\");\nexport const createDeleteRoute = createWithoutBodyRoute(\"DELETE\");\nexport const createOptionsRoute = createWithoutBodyRoute(\"OPTIONS\");\nexport const createHeadRoute = createWithoutBodyRoute(\"HEAD\");\nexport const createPostRoute = createWithBodyRoute(\"POST\");\nexport const createPutRoute = createWithBodyRoute(\"PUT\");\nexport const createPatchRoute = createWithBodyRoute(\"PATCH\");\n\nexport const createAnyRoute: CreateAnyRoute = ((path: string, methods: readonly HttpMethod[]) =>\n createRouteBuilder(path, \"ANY\", methods)) as unknown as CreateAnyRoute;\n\nexport const createAllRoute: CreateAllRoute = ((path: string) =>\n createRouteBuilder(path, \"ALL\")) as unknown as CreateAllRoute;\n"],"mappings":";;AAgCA,SAAS,uBACP,QAC2B;CAC3B,SAAS,SACP,mBAAmB,MAAM,MAAM;AACnC;AAEA,SAAS,oBACP,QACwB;CACxB,SAAS,SAAiB,mBAAmB,MAAM,MAAM;AAC3D;AAEA,IAAa,iBAAiB,uBAAuB,KAAK;AAC1D,IAAa,oBAAoB,uBAAuB,QAAQ;AAChE,IAAa,qBAAqB,uBAAuB,SAAS;AAClE,IAAa,kBAAkB,uBAAuB,MAAM;AAC5D,IAAa,kBAAkB,oBAAoB,MAAM;AACzD,IAAa,iBAAiB,oBAAoB,KAAK;AACvD,IAAa,mBAAmB,oBAAoB,OAAO;AAE3D,IAAa,mBAAmC,MAAc,YAC5D,mBAAmB,MAAM,OAAO,OAAO;AAEzC,IAAa,mBAAmC,SAC9C,mBAAmB,MAAM,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createMiddlewareUnitBuilder(requiredLayouts?: string | readonly string[]): any;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { pickDefinedSchemas } from "../define/validators.js";
|
|
2
|
+
//#region src/builder/middleware-unit.ts
|
|
3
|
+
function createMiddlewareUnitBuilder(requiredLayouts) {
|
|
4
|
+
const validators = {};
|
|
5
|
+
let bodyMode;
|
|
6
|
+
let returnsMap;
|
|
7
|
+
function toUnit(fn) {
|
|
8
|
+
const schemas = pickDefinedSchemas(validators);
|
|
9
|
+
return {
|
|
10
|
+
...fn ? { handler: fn } : {},
|
|
11
|
+
...schemas,
|
|
12
|
+
...bodyMode ? { bodyMode } : {},
|
|
13
|
+
...returnsMap ? {
|
|
14
|
+
returns: returnsMap,
|
|
15
|
+
__returns: returnsMap
|
|
16
|
+
} : {},
|
|
17
|
+
...requiredLayouts !== void 0 ? { __requiredLayouts: requiredLayouts } : {},
|
|
18
|
+
__middlewareAcc: void 0
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const builder = {
|
|
22
|
+
query(schema) {
|
|
23
|
+
validators.query = schema;
|
|
24
|
+
return builder;
|
|
25
|
+
},
|
|
26
|
+
params(schema) {
|
|
27
|
+
validators.params = schema;
|
|
28
|
+
return builder;
|
|
29
|
+
},
|
|
30
|
+
body(modeOrSchema, schema) {
|
|
31
|
+
if (typeof modeOrSchema === "string") {
|
|
32
|
+
bodyMode = modeOrSchema;
|
|
33
|
+
if (schema !== void 0) validators.body = schema;
|
|
34
|
+
} else {
|
|
35
|
+
bodyMode = "json";
|
|
36
|
+
validators.body = modeOrSchema;
|
|
37
|
+
}
|
|
38
|
+
return builder;
|
|
39
|
+
},
|
|
40
|
+
returns(map) {
|
|
41
|
+
returnsMap = {
|
|
42
|
+
...returnsMap,
|
|
43
|
+
...map
|
|
44
|
+
};
|
|
45
|
+
return builder;
|
|
46
|
+
},
|
|
47
|
+
requires() {
|
|
48
|
+
return builder;
|
|
49
|
+
},
|
|
50
|
+
handler(fn) {
|
|
51
|
+
return toUnit(fn);
|
|
52
|
+
},
|
|
53
|
+
toUnit() {
|
|
54
|
+
return toUnit();
|
|
55
|
+
},
|
|
56
|
+
__middlewareAcc: void 0
|
|
57
|
+
};
|
|
58
|
+
if (requiredLayouts !== void 0) builder.__requiredLayouts = requiredLayouts;
|
|
59
|
+
return builder;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { createMiddlewareUnitBuilder };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=middleware-unit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-unit.js","names":[],"sources":["../../../src/builder/middleware-unit.ts"],"sourcesContent":["import type { BodyMode } from \"@taserjs/router-core\";\n\nimport type { ReturnsMap } from \"../types/returns.js\";\nimport type { Schema } from \"../types/schema.js\";\nimport { pickDefinedSchemas, type SchemaValidators } from \"../define/validators.js\";\n\nexport function createMiddlewareUnitBuilder(requiredLayouts?: string | readonly string[]) {\n const validators: SchemaValidators = {};\n let bodyMode: BodyMode | undefined;\n let returnsMap: ReturnsMap | undefined;\n\n function toUnit(fn?: (ctx: any, next: any) => any) {\n const schemas = pickDefinedSchemas(validators);\n return {\n ...(fn ? { handler: fn } : {}),\n ...schemas,\n ...(bodyMode ? { bodyMode } : {}),\n ...(returnsMap ? { returns: returnsMap, __returns: returnsMap } : {}),\n ...(requiredLayouts !== undefined ? { __requiredLayouts: requiredLayouts } : {}),\n __middlewareAcc: undefined as unknown,\n };\n }\n\n const builder: any = {\n query(schema: Schema<unknown>) {\n validators.query = schema;\n return builder;\n },\n params(schema: Schema<unknown>) {\n validators.params = schema;\n return builder;\n },\n body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>) {\n if (typeof modeOrSchema === \"string\") {\n bodyMode = modeOrSchema as BodyMode;\n if (schema !== undefined) {\n validators.body = schema;\n }\n } else {\n bodyMode = \"json\";\n validators.body = modeOrSchema;\n }\n return builder;\n },\n returns(map: ReturnsMap) {\n returnsMap = { ...returnsMap, ...map };\n return builder;\n },\n requires() {\n return builder;\n },\n handler(fn: (ctx: any, next: any) => any) {\n return toUnit(fn);\n },\n toUnit() {\n return toUnit();\n },\n __middlewareAcc: undefined as unknown,\n };\n\n if (requiredLayouts !== undefined) {\n builder.__requiredLayouts = requiredLayouts;\n }\n\n return builder;\n}\n"],"mappings":";;AAMA,SAAgB,4BAA4B,iBAA8C;CACxF,MAAM,aAA+B,CAAC;CACtC,IAAI;CACJ,IAAI;CAEJ,SAAS,OAAO,IAAmC;EACjD,MAAM,UAAU,mBAAmB,UAAU;EAC7C,OAAO;GACL,GAAI,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;GAC5B,GAAG;GACH,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;GAC/B,GAAI,aAAa;IAAE,SAAS;IAAY,WAAW;GAAW,IAAI,CAAC;GACnE,GAAI,oBAAoB,KAAA,IAAY,EAAE,mBAAmB,gBAAgB,IAAI,CAAC;GAC9E,iBAAiB,KAAA;EACnB;CACF;CAEA,MAAM,UAAe;EACnB,MAAM,QAAyB;GAC7B,WAAW,QAAQ;GACnB,OAAO;EACT;EACA,OAAO,QAAyB;GAC9B,WAAW,SAAS;GACpB,OAAO;EACT;EACA,KAAK,cAA0C,QAA0B;GACvE,IAAI,OAAO,iBAAiB,UAAU;IACpC,WAAW;IACX,IAAI,WAAW,KAAA,GACb,WAAW,OAAO;GAEtB,OAAO;IACL,WAAW;IACX,WAAW,OAAO;GACpB;GACA,OAAO;EACT;EACA,QAAQ,KAAiB;GACvB,aAAa;IAAE,GAAG;IAAY,GAAG;GAAI;GACrC,OAAO;EACT;EACA,WAAW;GACT,OAAO;EACT;EACA,QAAQ,IAAkC;GACxC,OAAO,OAAO,EAAE;EAClB;EACA,SAAS;GACP,OAAO,OAAO;EAChB;EACA,iBAAiB,KAAA;CACnB;CAEA,IAAI,oBAAoB,KAAA,GACtB,QAAQ,oBAAoB;CAG9B,OAAO;AACT"}
|
|
@@ -5,7 +5,9 @@ function createMiddleware(layout) {
|
|
|
5
5
|
layout,
|
|
6
6
|
middlewares: entries,
|
|
7
7
|
use(definition) {
|
|
8
|
-
entries.push(definition);
|
|
8
|
+
if (typeof definition === "function") entries.push({ handler: definition });
|
|
9
|
+
else if (typeof definition?.toUnit === "function") entries.push(definition.toUnit());
|
|
10
|
+
else entries.push(definition);
|
|
9
11
|
return chain;
|
|
10
12
|
}
|
|
11
13
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","names":[],"sources":["../../../src/builder/middleware.ts"],"sourcesContent":["import type { LayoutId, MiddlewareBuilder } from \"../types/index.js\";\nimport type { MiddlewareDefinition } from \"../types/units.js\";\n\nexport function createMiddleware<const Layout extends LayoutId>(\n layout: Layout,\n): MiddlewareBuilder<Layout, readonly []> {\n const entries: MiddlewareDefinition[] = [];\n\n const chain = {\n layout,\n middlewares: entries,\n use(definition: MiddlewareDefinition) {\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,
|
|
1
|
+
{"version":3,"file":"middleware.js","names":[],"sources":["../../../src/builder/middleware.ts"],"sourcesContent":["import type { LayoutId, MiddlewareBuilder } from \"../types/index.js\";\nimport type { MiddlewareDefinition } from \"../types/units.js\";\n\nexport function createMiddleware<const Layout extends LayoutId>(\n layout: Layout,\n): MiddlewareBuilder<Layout, readonly []> {\n const entries: MiddlewareDefinition[] = [];\n\n const chain = {\n layout,\n middlewares: entries,\n use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)) {\n if (typeof definition === \"function\") {\n entries.push({ handler: definition as any });\n } else if (typeof (definition as any)?.toUnit === \"function\") {\n entries.push((definition as any).toUnit());\n } else {\n entries.push(definition);\n }\n return chain;\n },\n };\n\n return chain as unknown as MiddlewareBuilder<Layout, readonly []>;\n}\n"],"mappings":";AAGA,SAAgB,iBACd,QACwC;CACxC,MAAM,UAAkC,CAAC;CAEzC,MAAM,QAAQ;EACZ;EACA,aAAa;EACb,IAAI,YAAmE;GACrE,IAAI,OAAO,eAAe,YACxB,QAAQ,KAAK,EAAE,SAAS,WAAkB,CAAC;QACtC,IAAI,OAAQ,YAAoB,WAAW,YAChD,QAAQ,KAAM,WAAmB,OAAO,CAAC;QAEzC,QAAQ,KAAK,UAAU;GAEzB,OAAO;EACT;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { isHandlerUnit } from "../types/units.js";
|
|
2
|
-
import { HANDLER_SCHEMA_KEY_MAP } from "./constants.js";
|
|
3
1
|
import { pickDefinedSchemas } from "../define/validators.js";
|
|
4
2
|
import { collectReturnsFromDefinitions, hasInputSchemas, mergeReturnsMaps, withAuto422 } from "@taserjs/router-utils";
|
|
5
3
|
//#region src/builder/route.ts
|
|
@@ -10,7 +8,7 @@ function toUtilsMap(map) {
|
|
|
10
8
|
return out;
|
|
11
9
|
}
|
|
12
10
|
function buildEffectiveReturns(args) {
|
|
13
|
-
const with422 = withAuto422(mergeReturnsMaps(toUtilsMap(args.middlewareReturns), toUtilsMap(args.routeReturns)
|
|
11
|
+
const with422 = withAuto422(mergeReturnsMaps(toUtilsMap(args.middlewareReturns), toUtilsMap(args.routeReturns)), hasInputSchemas(args.schemas));
|
|
14
12
|
return Object.keys(with422).length > 0 ? with422 : void 0;
|
|
15
13
|
}
|
|
16
14
|
function buildRouteBase(path, method, methods, middlewares) {
|
|
@@ -56,38 +54,26 @@ function createRouteBuilder(path, method, methods) {
|
|
|
56
54
|
return builder;
|
|
57
55
|
},
|
|
58
56
|
use(definition) {
|
|
59
|
-
middlewares.push(definition);
|
|
57
|
+
if (typeof definition === "function") middlewares.push({ handler: definition });
|
|
58
|
+
else if (typeof definition?.toUnit === "function") middlewares.push(definition.toUnit());
|
|
59
|
+
else middlewares.push(definition);
|
|
60
60
|
return builder;
|
|
61
61
|
},
|
|
62
|
-
handler(
|
|
62
|
+
handler(fn) {
|
|
63
63
|
const routeSchemas = pickDefinedSchemas(validators);
|
|
64
64
|
const base = buildRouteBase(path, method, methods, middlewares);
|
|
65
|
-
const unit = isHandlerUnit(fnOrUnit) ? fnOrUnit : {
|
|
66
|
-
handler: fnOrUnit,
|
|
67
|
-
middlewares: [],
|
|
68
|
-
returns: void 0
|
|
69
|
-
};
|
|
70
|
-
const handlerSchemas = isHandlerUnit(fnOrUnit) ? pickDefinedSchemas(fnOrUnit, HANDLER_SCHEMA_KEY_MAP) : {};
|
|
71
65
|
const returns = buildEffectiveReturns({
|
|
72
66
|
middlewareReturns: collectReturnsFromDefinitions(middlewares),
|
|
73
67
|
routeReturns,
|
|
74
|
-
handlerMiddlewareReturns: collectReturnsFromDefinitions(unit.middlewares),
|
|
75
|
-
handlerReturns: unit.returns,
|
|
76
68
|
schemas: {
|
|
77
69
|
...validators,
|
|
78
|
-
|
|
79
|
-
handlerParams: unit.params,
|
|
80
|
-
handlerBody: unit.body,
|
|
81
|
-
middlewares,
|
|
82
|
-
handlerMiddlewares: unit.middlewares
|
|
70
|
+
middlewares
|
|
83
71
|
}
|
|
84
72
|
});
|
|
85
73
|
return {
|
|
86
74
|
...base,
|
|
87
|
-
|
|
88
|
-
handler: unit.handler,
|
|
75
|
+
handler: fn,
|
|
89
76
|
...routeSchemas,
|
|
90
|
-
...handlerSchemas,
|
|
91
77
|
...bodyMode ? { bodyMode } : {},
|
|
92
78
|
...returns ? { returns } : {}
|
|
93
79
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","names":[],"sources":["../../../src/builder/route.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport {\n collectReturnsFromDefinitions,\n hasInputSchemas,\n mergeReturnsMaps,\n withAuto422,\n} from \"@taserjs/router-utils\";\nimport type { BodyMode } from \"@taserjs/router-core\";\n\nimport type {\n Method,\n RouteBuilder,\n RoutePath,\n ReturnsMap,\n ValidatorParts,\n Schema,\n} from \"../types/index.js\";\nimport type { HttpMethod, MiddlewareDefinition } from \"../types/units.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"route.js","names":[],"sources":["../../../src/builder/route.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport {\n collectReturnsFromDefinitions,\n hasInputSchemas,\n mergeReturnsMaps,\n withAuto422,\n} from \"@taserjs/router-utils\";\nimport type { BodyMode } from \"@taserjs/router-core\";\n\nimport type {\n Method,\n RouteBuilder,\n RoutePath,\n ReturnsMap,\n ValidatorParts,\n Schema,\n} from \"../types/index.js\";\nimport type { HttpMethod, MiddlewareDefinition } from \"../types/units.js\";\nimport { pickDefinedSchemas, type SchemaValidators } from \"../define/validators.js\";\n\nfunction toUtilsMap(map: ReturnsMap | undefined): Record<number, StandardSchemaV1> {\n if (!map) {\n return {};\n }\n const out: Record<number, StandardSchemaV1> = {};\n for (const [key, schema] of Object.entries(map)) {\n if (schema !== undefined) {\n out[Number(key)] = schema;\n }\n }\n return out;\n}\n\nfunction buildEffectiveReturns(args: {\n middlewareReturns: ReturnsMap;\n routeReturns: ReturnsMap;\n schemas: {\n query?: unknown;\n params?: unknown;\n body?: unknown;\n middlewares?: readonly MiddlewareDefinition[];\n };\n}): Record<number, StandardSchemaV1> | undefined {\n const merged = mergeReturnsMaps(\n toUtilsMap(args.middlewareReturns),\n toUtilsMap(args.routeReturns),\n );\n const with422 = withAuto422(merged, hasInputSchemas(args.schemas));\n return Object.keys(with422).length > 0 ? with422 : undefined;\n}\n\nfunction buildRouteBase(\n path: string,\n method: HttpMethod | \"ANY\" | \"ALL\",\n methods: readonly HttpMethod[] | undefined,\n middlewares: MiddlewareDefinition[],\n) {\n return {\n path,\n method,\n ...(methods ? { methods: [...methods] } : {}),\n middlewares: [...middlewares],\n };\n}\n\n/** Shared internal builder — not part of the public `@taserjs/router` API. */\nexport function createRouteBuilder(\n path: string,\n method: HttpMethod | \"ANY\" | \"ALL\",\n methods?: readonly HttpMethod[],\n): RouteBuilder<RoutePath, Method, readonly [], ValidatorParts> {\n const middlewares: MiddlewareDefinition[] = [];\n let routeReturns: Record<number, StandardSchemaV1> = {};\n const validators: SchemaValidators = {};\n let bodyMode: BodyMode | undefined;\n\n const builder = {\n path,\n method,\n query(schema: Schema<unknown>) {\n validators.query = schema;\n return builder;\n },\n params(schema: Schema<unknown>) {\n validators.params = schema;\n return builder;\n },\n body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>) {\n if (typeof modeOrSchema === \"string\") {\n bodyMode = modeOrSchema as BodyMode;\n if (schema !== undefined) {\n validators.body = schema;\n }\n } else {\n bodyMode = \"json\";\n validators.body = modeOrSchema;\n }\n return builder;\n },\n returns(map: ReturnsMap) {\n routeReturns = { ...routeReturns, ...toUtilsMap(map) };\n return builder;\n },\n use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)) {\n if (typeof definition === \"function\") {\n middlewares.push({ handler: definition as any });\n } else if (typeof (definition as any)?.toUnit === \"function\") {\n middlewares.push((definition as any).toUnit());\n } else {\n middlewares.push(definition);\n }\n return builder;\n },\n handler(fn: (ctx: unknown) => Response | Promise<Response>) {\n const routeSchemas = pickDefinedSchemas(validators);\n const base = buildRouteBase(path, method, methods, middlewares);\n\n const returns = buildEffectiveReturns({\n middlewareReturns: collectReturnsFromDefinitions(middlewares),\n routeReturns,\n schemas: {\n ...validators,\n middlewares,\n },\n });\n\n return {\n ...base,\n handler: fn,\n ...routeSchemas,\n ...(bodyMode ? { bodyMode } : {}),\n ...(returns ? { returns } : {}),\n };\n },\n };\n\n return builder as unknown as RouteBuilder<RoutePath, Method, readonly [], ValidatorParts>;\n}\n"],"mappings":";;;AAoBA,SAAS,WAAW,KAA+D;CACjF,IAAI,CAAC,KACH,OAAO,CAAC;CAEV,MAAM,MAAwC,CAAC;CAC/C,KAAK,MAAM,CAAC,KAAK,WAAW,OAAO,QAAQ,GAAG,GAC5C,IAAI,WAAW,KAAA,GACb,IAAI,OAAO,GAAG,KAAK;CAGvB,OAAO;AACT;AAEA,SAAS,sBAAsB,MASkB;CAK/C,MAAM,UAAU,YAJD,iBACb,WAAW,KAAK,iBAAiB,GACjC,WAAW,KAAK,YAAY,CAEF,GAAQ,gBAAgB,KAAK,OAAO,CAAC;CACjE,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IAAI,UAAU,KAAA;AACrD;AAEA,SAAS,eACP,MACA,QACA,SACA,aACA;CACA,OAAO;EACL;EACA;EACA,GAAI,UAAU,EAAE,SAAS,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC;EAC3C,aAAa,CAAC,GAAG,WAAW;CAC9B;AACF;;AAGA,SAAgB,mBACd,MACA,QACA,SAC8D;CAC9D,MAAM,cAAsC,CAAC;CAC7C,IAAI,eAAiD,CAAC;CACtD,MAAM,aAA+B,CAAC;CACtC,IAAI;CAEJ,MAAM,UAAU;EACd;EACA;EACA,MAAM,QAAyB;GAC7B,WAAW,QAAQ;GACnB,OAAO;EACT;EACA,OAAO,QAAyB;GAC9B,WAAW,SAAS;GACpB,OAAO;EACT;EACA,KAAK,cAA0C,QAA0B;GACvE,IAAI,OAAO,iBAAiB,UAAU;IACpC,WAAW;IACX,IAAI,WAAW,KAAA,GACb,WAAW,OAAO;GAEtB,OAAO;IACL,WAAW;IACX,WAAW,OAAO;GACpB;GACA,OAAO;EACT;EACA,QAAQ,KAAiB;GACvB,eAAe;IAAE,GAAG;IAAc,GAAG,WAAW,GAAG;GAAE;GACrD,OAAO;EACT;EACA,IAAI,YAAmE;GACrE,IAAI,OAAO,eAAe,YACxB,YAAY,KAAK,EAAE,SAAS,WAAkB,CAAC;QAC1C,IAAI,OAAQ,YAAoB,WAAW,YAChD,YAAY,KAAM,WAAmB,OAAO,CAAC;QAE7C,YAAY,KAAK,UAAU;GAE7B,OAAO;EACT;EACA,QAAQ,IAAoD;GAC1D,MAAM,eAAe,mBAAmB,UAAU;GAClD,MAAM,OAAO,eAAe,MAAM,QAAQ,SAAS,WAAW;GAE9D,MAAM,UAAU,sBAAsB;IACpC,mBAAmB,8BAA8B,WAAW;IAC5D;IACA,SAAS;KACP,GAAG;KACH;IACF;GACF,CAAC;GAED,OAAO;IACL,GAAG;IACH,SAAS;IACT,GAAG;IACH,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;IAC/B,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;GAC/B;EACF;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1,47 +1,26 @@
|
|
|
1
1
|
import { NotFoundHandler, OnErrorHandler, RouteManifestShape } from '@taserjs/router-core';
|
|
2
|
-
import { DefineMiddlewareFn } from '../define/middleware.js';
|
|
3
2
|
import { TaserApp } from './app.js';
|
|
4
3
|
import { ContextDefinition, CreateTaserAppOptions, OnErrorOptions } from '../types/app.js';
|
|
5
|
-
import {
|
|
6
|
-
import { HandlerBuilder, LayoutId, MiddlewareBuilder } from '../types/index.js';
|
|
4
|
+
import { EmptyAppContext } from '../types/units.js';
|
|
7
5
|
import { ReturnsMap } from '../types/returns.js';
|
|
8
|
-
import { Schema } from '../types/schema.js';
|
|
9
|
-
import { CreateAllRoute, CreateAnyRoute, CreateWithBodyRoute, CreateWithoutBodyRoute } from './factories.js';
|
|
10
6
|
type RouterState = {
|
|
11
7
|
options: CreateTaserAppOptions;
|
|
12
8
|
contextDef: ContextDefinition<Record<string, unknown>, Record<string, unknown>>;
|
|
13
9
|
onError?: OnErrorHandler;
|
|
14
10
|
notFound?: NotFoundHandler;
|
|
15
11
|
};
|
|
16
|
-
export declare class TaserRouter<TAppContext extends Record<string, unknown> =
|
|
12
|
+
export declare class TaserRouter<TAppContext extends Record<string, unknown> = EmptyAppContext, THasNotFound extends boolean = false> {
|
|
17
13
|
private readonly state;
|
|
14
|
+
readonly $Infer: {
|
|
15
|
+
Context: TAppContext;
|
|
16
|
+
};
|
|
18
17
|
constructor(options?: CreateTaserAppOptions, state?: Partial<Omit<RouterState, "options">>);
|
|
19
18
|
context<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>>(definition: ContextDefinition<TBoot, TReq>): TaserRouter<TBoot & TReq, THasNotFound>;
|
|
20
19
|
onError<TResponses extends ReturnsMap = ReturnsMap>(options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>["handle"]): this;
|
|
21
20
|
notFound(handler: (ctx: unknown) => Response | Promise<Response> | unknown): TaserRouter<TAppContext, true>;
|
|
22
|
-
get: CreateWithoutBodyRoute<"GET", TAppContext>;
|
|
23
|
-
post: CreateWithBodyRoute<"POST", TAppContext>;
|
|
24
|
-
put: CreateWithBodyRoute<"PUT", TAppContext>;
|
|
25
|
-
patch: CreateWithBodyRoute<"PATCH", TAppContext>;
|
|
26
|
-
delete: CreateWithoutBodyRoute<"DELETE", TAppContext>;
|
|
27
|
-
options: CreateWithoutBodyRoute<"OPTIONS", TAppContext>;
|
|
28
|
-
head: CreateWithoutBodyRoute<"HEAD", TAppContext>;
|
|
29
|
-
any: CreateAnyRoute<TAppContext>;
|
|
30
|
-
all: CreateAllRoute<TAppContext>;
|
|
31
|
-
middleware<const Layout extends LayoutId>(layout: Layout): MiddlewareBuilder<Layout, readonly [], TAppContext>;
|
|
32
|
-
defineHandler<TQuery = unknown, TParams = unknown, TBody = unknown>(options?: {
|
|
33
|
-
query?: Schema<TQuery>;
|
|
34
|
-
params?: Schema<TParams>;
|
|
35
|
-
body?: Schema<TBody>;
|
|
36
|
-
}): HandlerBuilder<readonly [], {
|
|
37
|
-
query: TQuery;
|
|
38
|
-
params: TParams;
|
|
39
|
-
body: TBody;
|
|
40
|
-
}, {}, TAppContext>;
|
|
41
|
-
defineMiddleware: DefineMiddlewareFn<TAppContext>;
|
|
42
21
|
create<const TManifest extends RouteManifestShape>(manifest: TManifest, runtimeOptions?: {
|
|
43
22
|
basePath?: string;
|
|
44
23
|
}): TaserApp<TManifest, THasNotFound>;
|
|
45
24
|
}
|
|
46
|
-
export declare function createTaserApp(options?: CreateTaserAppOptions): TaserRouter<
|
|
25
|
+
export declare function createTaserApp(options?: CreateTaserAppOptions): TaserRouter<EmptyAppContext, false>;
|
|
47
26
|
export {};
|