@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
|
@@ -5,7 +5,7 @@ import { MergeMiddlewareField, MergePart, RequestShape, RuntimeContextFields, Si
|
|
|
5
5
|
import { ReturnsMap } from './returns.js';
|
|
6
6
|
import { Schema } from './schema.js';
|
|
7
7
|
export type { HttpMethod, Method } from './type-utils.js';
|
|
8
|
-
export type { EmptyReturns, MergeReturns, ReturnsMap, HandlerReply, HasReturns, StatusCode, ValidHandlerReply, EnforceHandlerReply } from './returns.js';
|
|
8
|
+
export type { EmptyReturns, MergeReturns, ReturnsMap, HandlerReply, HasReturns, StatusCode, ValidHandlerReply, EnforceHandlerReply, } from './returns.js';
|
|
9
9
|
/** Default empty app context for standalone units without a bound router instance. */
|
|
10
10
|
export type AppContext = Record<never, never>;
|
|
11
11
|
export type NativeContext = RouterRegister extends {
|
|
@@ -19,27 +19,32 @@ export type ValidatorParts = {
|
|
|
19
19
|
paramsIn?: unknown;
|
|
20
20
|
bodyIn?: unknown;
|
|
21
21
|
};
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
ctx?: unknown;
|
|
26
|
-
}): Promise<ReplyResult>;
|
|
22
|
+
export declare const StateBrand: unique symbol;
|
|
23
|
+
export type NextResult<TState = unknown> = ReplyResult & {
|
|
24
|
+
readonly [StateBrand]?: TState;
|
|
27
25
|
};
|
|
26
|
+
export type ExtractState<T> = [Extract<Awaited<T>, {
|
|
27
|
+
[StateBrand]?: unknown;
|
|
28
|
+
}>] extends [never] ? {} : Extract<Awaited<T>, {
|
|
29
|
+
[StateBrand]?: unknown;
|
|
30
|
+
}> extends {
|
|
31
|
+
[StateBrand]?: infer S;
|
|
32
|
+
} ? [S] extends [never] ? {} : S : {};
|
|
33
|
+
export type IsUnknown<T> = [unknown] extends [T] ? true : false;
|
|
34
|
+
export type NextFn<TExpectedState = unknown> = IsUnknown<TExpectedState> extends true ? <S extends Record<string, unknown> = {}>(state?: S) => Promise<NextResult<S>> : (state: TExpectedState) => Promise<NextResult<TExpectedState>>;
|
|
35
|
+
export type MiddlewareNext = NextFn;
|
|
28
36
|
export type MiddlewareDefinition = {
|
|
29
|
-
state?: unknown;
|
|
30
|
-
ctx?: unknown;
|
|
31
37
|
query?: unknown;
|
|
32
38
|
params?: unknown;
|
|
33
39
|
body?: unknown;
|
|
34
40
|
returns?: ReturnsMap;
|
|
35
41
|
handler: (ctx: unknown, next: MiddlewareNext) => Awaitable<ReplyResult | Response | unknown>;
|
|
36
42
|
};
|
|
37
|
-
export type MiddlewareReturnFromParts<TQuery, TParams, TBody, TState,
|
|
43
|
+
export type MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TQueryIn = TQuery, TParamsIn = TParams, TBodyIn = TBody> = {
|
|
38
44
|
query: Simplify<UnwrapPart<TQuery>>;
|
|
39
45
|
params: Simplify<UnwrapPart<TParams>>;
|
|
40
46
|
body: Simplify<UnwrapPart<TBody>>;
|
|
41
47
|
state: Simplify<UnwrapPart<TState>>;
|
|
42
|
-
ctx: Simplify<UnwrapPart<TCtx>>;
|
|
43
48
|
/** Pre-parse shapes merged into route `$Infer.Input`. */
|
|
44
49
|
input: {
|
|
45
50
|
query: RequestShape<TQueryIn, TQuery>;
|
|
@@ -47,7 +52,7 @@ export type MiddlewareReturnFromParts<TQuery, TParams, TBody, TState, TCtx = unk
|
|
|
47
52
|
body: RequestShape<TBodyIn, TBody>;
|
|
48
53
|
};
|
|
49
54
|
};
|
|
50
|
-
type UnitRuntimeContext = Omit<RuntimeContextFields<NativeContext>,
|
|
55
|
+
type UnitRuntimeContext = Omit<RuntimeContextFields<NativeContext>, "var">;
|
|
51
56
|
export type StandaloneMiddlewareContext<TQuery = unknown, TParams = unknown, TBody = unknown, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
52
57
|
query: Simplify<UnwrapPart<TQuery>>;
|
|
53
58
|
params: Simplify<UnwrapPart<TParams>>;
|
|
@@ -56,17 +61,17 @@ export type StandaloneMiddlewareContext<TQuery = unknown, TParams = unknown, TBo
|
|
|
56
61
|
headers: TaserHeaders;
|
|
57
62
|
cookies: TaserCookieJar;
|
|
58
63
|
}>;
|
|
59
|
-
export type HandlerContext<Acc extends readonly unknown[], Validators extends ValidatorParts, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext &
|
|
64
|
+
export type HandlerContext<Acc extends readonly unknown[], Validators extends ValidatorParts, TAppContext extends Record<string, unknown> = AppContext> = Simplify<TAppContext & UnitRuntimeContext & {
|
|
60
65
|
query: Simplify<MergePart<Validators extends {
|
|
61
66
|
query?: infer Q;
|
|
62
|
-
} ? Q : unknown, MergeMiddlewareField<Acc,
|
|
67
|
+
} ? Q : unknown, MergeMiddlewareField<Acc, "query">>>;
|
|
63
68
|
params: Simplify<MergePart<Validators extends {
|
|
64
69
|
params?: infer P;
|
|
65
|
-
} ? P : unknown, MergeMiddlewareField<Acc,
|
|
70
|
+
} ? P : unknown, MergeMiddlewareField<Acc, "params">>>;
|
|
66
71
|
body: Simplify<MergePart<Validators extends {
|
|
67
72
|
body?: infer B;
|
|
68
|
-
} ? B : unknown, MergeMiddlewareField<Acc,
|
|
69
|
-
state: Simplify<MergeMiddlewareField<Acc,
|
|
73
|
+
} ? B : unknown, MergeMiddlewareField<Acc, "body">>>;
|
|
74
|
+
state: Simplify<MergeMiddlewareField<Acc, "state">>;
|
|
70
75
|
headers: TaserHeaders;
|
|
71
76
|
cookies: TaserCookieJar;
|
|
72
77
|
}>;
|
|
@@ -86,13 +91,11 @@ export type HandlerUnit<_Acc extends readonly unknown[], _Validators extends Val
|
|
|
86
91
|
params?: Schema<unknown>;
|
|
87
92
|
body?: Schema<unknown>;
|
|
88
93
|
};
|
|
89
|
-
export type InlineMiddlewareOptions = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
returns?: ReturnsMap;
|
|
96
|
-
handler: (ctx: unknown, next: MiddlewareNext) => Awaitable<unknown>;
|
|
94
|
+
export type InlineMiddlewareOptions<Ctx = unknown, TQuery = unknown, TParams = unknown, TBody = unknown, TReturns extends ReturnsMap = {}, TQueryIn = unknown, TParamsIn = unknown, TBodyIn = unknown, R = unknown> = {
|
|
95
|
+
query?: Schema<TQuery, TQueryIn>;
|
|
96
|
+
params?: Schema<TParams, TParamsIn>;
|
|
97
|
+
body?: Schema<TBody, TBodyIn>;
|
|
98
|
+
returns?: TReturns;
|
|
99
|
+
handler: (ctx: Ctx, next: NextFn) => Awaitable<R>;
|
|
97
100
|
};
|
|
98
101
|
export declare function isHandlerUnit(value: unknown): value is HandlerUnit<readonly unknown[], ValidatorParts>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.js","names":[],"sources":["../../../src/types/units.ts"],"sourcesContent":["import type { Awaitable, TaserCookieJar, TaserHeaders } from
|
|
1
|
+
{"version":3,"file":"units.js","names":[],"sources":["../../../src/types/units.ts"],"sourcesContent":["import type { Awaitable, TaserCookieJar, TaserHeaders } from \"@taserjs/router-core\";\nimport type { ReplyResult } from \"@taserjs/router-utils\";\n\nimport type { RouterRegister } from \"../register.js\";\nimport type {\n MergeMiddlewareField,\n MergePart,\n RequestShape,\n RuntimeContextFields,\n Simplify,\n UnwrapPart,\n} from \"./type-utils.js\";\nimport type { ReturnsMap } from \"./returns.js\";\nimport type { Schema } from \"./schema.js\";\n\nexport type { HttpMethod, Method } from \"./type-utils.js\";\nexport type {\n EmptyReturns,\n MergeReturns,\n ReturnsMap,\n HandlerReply,\n HasReturns,\n StatusCode,\n ValidHandlerReply,\n EnforceHandlerReply,\n} from \"./returns.js\";\n\n/** Default empty app context for standalone units without a bound router instance. */\nexport type AppContext = Record<never, never>;\n\nexport type NativeContext = RouterRegister extends { NativeContext: infer N } ? N : unknown;\n\nexport type ValidatorParts = {\n query?: unknown;\n params?: unknown;\n body?: unknown;\n queryIn?: unknown;\n paramsIn?: unknown;\n bodyIn?: unknown;\n};\n\nexport declare const StateBrand: unique symbol;\n\nexport type NextResult<TState = unknown> = ReplyResult & {\n readonly [StateBrand]?: TState;\n};\n\nexport type ExtractState<T> = [Extract<Awaited<T>, { [StateBrand]?: unknown }>] extends [never]\n ? {}\n : Extract<Awaited<T>, { [StateBrand]?: unknown }> extends { [StateBrand]?: infer S }\n ? [S] extends [never]\n ? {}\n : S\n : {};\n\nexport type IsUnknown<T> = [unknown] extends [T] ? true : false;\n\nexport type NextFn<TExpectedState = unknown> =\n IsUnknown<TExpectedState> extends true\n ? <S extends Record<string, unknown> = {}>(state?: S) => Promise<NextResult<S>>\n : (state: TExpectedState) => Promise<NextResult<TExpectedState>>;\n\nexport type MiddlewareNext = NextFn;\n\nexport type MiddlewareDefinition = {\n query?: unknown;\n params?: unknown;\n body?: unknown;\n returns?: ReturnsMap;\n handler: (ctx: unknown, next: MiddlewareNext) => Awaitable<ReplyResult | Response | unknown>;\n};\n\nexport type MiddlewareReturnFromParts<\n TQuery,\n TParams,\n TBody,\n TState,\n TQueryIn = TQuery,\n TParamsIn = TParams,\n TBodyIn = TBody,\n> = {\n query: Simplify<UnwrapPart<TQuery>>;\n params: Simplify<UnwrapPart<TParams>>;\n body: Simplify<UnwrapPart<TBody>>;\n state: Simplify<UnwrapPart<TState>>;\n /** Pre-parse shapes merged into route `$Infer.Input`. */\n input: {\n query: RequestShape<TQueryIn, TQuery>;\n params: RequestShape<TParamsIn, TParams>;\n body: RequestShape<TBodyIn, TBody>;\n };\n};\n\ntype UnitRuntimeContext = Omit<RuntimeContextFields<NativeContext>, \"var\">;\n\nexport type StandaloneMiddlewareContext<\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TAppContext extends Record<string, unknown> = AppContext,\n> = Simplify<\n TAppContext &\n UnitRuntimeContext & {\n query: Simplify<UnwrapPart<TQuery>>;\n params: Simplify<UnwrapPart<TParams>>;\n body: Simplify<UnwrapPart<TBody>>;\n state: {};\n headers: TaserHeaders;\n cookies: TaserCookieJar;\n }\n>;\n\nexport type HandlerContext<\n Acc extends readonly unknown[],\n Validators extends ValidatorParts,\n TAppContext extends Record<string, unknown> = AppContext,\n> = Simplify<\n TAppContext &\n UnitRuntimeContext & {\n query: Simplify<\n MergePart<\n Validators extends { query?: infer Q } ? Q : unknown,\n MergeMiddlewareField<Acc, \"query\">\n >\n >;\n params: Simplify<\n MergePart<\n Validators extends { params?: infer P } ? P : unknown,\n MergeMiddlewareField<Acc, \"params\">\n >\n >;\n body: Simplify<\n MergePart<\n Validators extends { body?: infer B } ? B : unknown,\n MergeMiddlewareField<Acc, \"body\">\n >\n >;\n state: Simplify<MergeMiddlewareField<Acc, \"state\">>;\n headers: TaserHeaders;\n cookies: TaserCookieJar;\n }\n>;\n\nexport type MiddlewareUnit<\n TAcc = unknown,\n TReturns extends ReturnsMap = {},\n> = MiddlewareDefinition & {\n readonly __middlewareAcc: TAcc;\n readonly __returns?: TReturns;\n};\n\nexport type HandlerUnit<\n _Acc extends readonly unknown[],\n _Validators extends ValidatorParts,\n TReturns extends ReturnsMap = {},\n TOutput = Response,\n> = {\n readonly __returns?: TReturns;\n readonly $Infer: {\n Output: TOutput;\n };\n middlewares: readonly MiddlewareDefinition[];\n handler: (ctx: unknown) => Awaitable<ReplyResult | Response>;\n returns?: ReturnsMap;\n query?: Schema<unknown>;\n params?: Schema<unknown>;\n body?: Schema<unknown>;\n};\n\nexport type InlineMiddlewareOptions<\n Ctx = unknown,\n TQuery = unknown,\n TParams = unknown,\n TBody = unknown,\n TReturns extends ReturnsMap = {},\n TQueryIn = unknown,\n TParamsIn = unknown,\n TBodyIn = unknown,\n R = unknown,\n> = {\n query?: Schema<TQuery, TQueryIn>;\n params?: Schema<TParams, TParamsIn>;\n body?: Schema<TBody, TBodyIn>;\n returns?: TReturns;\n handler: (ctx: Ctx, next: NextFn) => Awaitable<R>;\n};\n\nexport function isHandlerUnit(\n value: unknown,\n): value is HandlerUnit<readonly unknown[], ValidatorParts> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"handler\" in value &&\n \"middlewares\" in value &&\n Array.isArray((value as HandlerUnit<readonly unknown[], ValidatorParts>).middlewares)\n );\n}\n"],"mappings":";AA2LA,SAAgB,cACd,OAC0D;CAC1D,OACE,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,iBAAiB,SACjB,MAAM,QAAS,MAA0D,WAAW;AAExF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taserjs/router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Type-safe Node.js router with runtime validation and middleware",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/taserjs/taserjs.git",
|
|
9
|
+
"directory": "packages/router"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
5
15
|
"type": "module",
|
|
6
16
|
"sideEffects": false,
|
|
7
17
|
"main": "./dist/cjs/index.cjs",
|
|
@@ -18,6 +28,26 @@
|
|
|
18
28
|
"default": "./dist/cjs/index.cjs"
|
|
19
29
|
}
|
|
20
30
|
},
|
|
31
|
+
"./reply": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/esm/reply.d.ts",
|
|
34
|
+
"default": "./dist/esm/reply.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/cjs/reply.d.cts",
|
|
38
|
+
"default": "./dist/cjs/reply.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./stream": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/esm/stream.d.ts",
|
|
44
|
+
"default": "./dist/esm/stream.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/cjs/stream.d.cts",
|
|
48
|
+
"default": "./dist/cjs/stream.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
21
51
|
"./body-limit": {
|
|
22
52
|
"import": {
|
|
23
53
|
"types": "./dist/esm/middleware/body-limit.d.ts",
|
|
@@ -110,15 +140,15 @@
|
|
|
110
140
|
},
|
|
111
141
|
"./package.json": "./package.json"
|
|
112
142
|
},
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
|
|
143
|
+
"publishConfig": {
|
|
144
|
+
"access": "public",
|
|
145
|
+
"registry": "https://registry.npmjs.org"
|
|
146
|
+
},
|
|
117
147
|
"dependencies": {
|
|
118
148
|
"@standard-schema/spec": "^1.1.0",
|
|
119
149
|
"hono": "^4.10.3",
|
|
120
|
-
"@taserjs/router-core": "0.0.
|
|
121
|
-
"@taserjs/router-utils": "0.0.
|
|
150
|
+
"@taserjs/router-core": "0.0.3",
|
|
151
|
+
"@taserjs/router-utils": "0.0.3"
|
|
122
152
|
},
|
|
123
153
|
"devDependencies": {
|
|
124
154
|
"@tanstack/vite-config": "^0.6.0",
|
|
@@ -130,16 +160,6 @@
|
|
|
130
160
|
"engines": {
|
|
131
161
|
"node": ">=20.19"
|
|
132
162
|
},
|
|
133
|
-
"license": "ISC",
|
|
134
|
-
"repository": {
|
|
135
|
-
"type": "git",
|
|
136
|
-
"url": "git+https://github.com/taserjs/taserjs.git",
|
|
137
|
-
"directory": "packages/router"
|
|
138
|
-
},
|
|
139
|
-
"publishConfig": {
|
|
140
|
-
"access": "public",
|
|
141
|
-
"registry": "https://registry.npmjs.org"
|
|
142
|
-
},
|
|
143
163
|
"scripts": {
|
|
144
164
|
"clean": "rimraf dist",
|
|
145
165
|
"build": "vite build && publint --strict",
|
package/src/constants.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** Input schema keys validated by middleware and route handlers. Headers/cookies are parsed only. */
|
|
2
|
-
export const SCHEMA_KEYS = [
|
|
2
|
+
export const SCHEMA_KEYS = ["query", "params", "body"] as const;
|
|
3
3
|
|
|
4
|
-
export type SchemaKey = (typeof SCHEMA_KEYS)[number]
|
|
4
|
+
export type SchemaKey = (typeof SCHEMA_KEYS)[number];
|
|
5
5
|
|
|
6
6
|
export const HANDLER_SCHEMA_KEY_MAP = {
|
|
7
|
-
query:
|
|
8
|
-
params:
|
|
9
|
-
body:
|
|
10
|
-
} as const satisfies Record<SchemaKey, string
|
|
7
|
+
query: "handlerQuery",
|
|
8
|
+
params: "handlerParams",
|
|
9
|
+
body: "handlerBody",
|
|
10
|
+
} as const satisfies Record<SchemaKey, string>;
|
package/src/create-context.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { ReservedContextKey } from
|
|
1
|
+
import type { ReservedContextKey } from "@taserjs/router-core";
|
|
2
2
|
|
|
3
|
-
import type { ContextDefinition } from
|
|
3
|
+
import type { ContextDefinition } from "./types/app.js";
|
|
4
4
|
|
|
5
|
-
type NoReservedKeysConstraint<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
type NoReservedKeysConstraint<
|
|
6
|
+
TBoot extends Record<string, unknown>,
|
|
7
|
+
TReq extends Record<string, unknown>,
|
|
8
|
+
> = Extract<keyof TBoot | keyof TReq, ReservedContextKey> extends never ? unknown : never;
|
|
9
9
|
|
|
10
10
|
export function createContext<
|
|
11
11
|
TBoot extends Record<string, unknown> = Record<string, never>,
|
|
@@ -13,7 +13,7 @@ export function createContext<
|
|
|
13
13
|
>(
|
|
14
14
|
definition: ContextDefinition<TBoot, TReq> & NoReservedKeysConstraint<TBoot, TReq>,
|
|
15
15
|
): ContextDefinition<TBoot, TReq> {
|
|
16
|
-
return definition
|
|
16
|
+
return definition;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export type { ContextDefinition, InferAppContext } from
|
|
19
|
+
export type { ContextDefinition, InferAppContext } from "./types/app.js";
|
package/src/define/handler.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { HandlerBuilder } from
|
|
1
|
+
import type { HandlerBuilder } from "../types/index.js";
|
|
2
2
|
import type {
|
|
3
3
|
AppContext,
|
|
4
4
|
HandlerUnit,
|
|
5
5
|
MiddlewareDefinition,
|
|
6
6
|
ReturnsMap,
|
|
7
7
|
ValidatorParts,
|
|
8
|
-
} from
|
|
9
|
-
import type { Schema } from
|
|
10
|
-
import { pickDefinedSchemas, type SchemaValidators } from
|
|
11
|
-
import { collectReturnsFromDefinitions } from
|
|
8
|
+
} from "../types/units.js";
|
|
9
|
+
import type { Schema } from "../types/schema.js";
|
|
10
|
+
import { pickDefinedSchemas, type SchemaValidators } from "./validators.js";
|
|
11
|
+
import { collectReturnsFromDefinitions } from "@taserjs/router-utils";
|
|
12
12
|
|
|
13
13
|
function createHandlerBuilder<TAppContext extends Record<string, unknown> = AppContext>(
|
|
14
14
|
validators: SchemaValidators,
|
|
@@ -17,56 +17,46 @@ function createHandlerBuilder<TAppContext extends Record<string, unknown> = AppC
|
|
|
17
17
|
): HandlerBuilder<readonly [], ValidatorParts, {}, TAppContext> {
|
|
18
18
|
const builder = {
|
|
19
19
|
returns(map: ReturnsMap) {
|
|
20
|
-
return createHandlerBuilder<TAppContext>(validators, middlewares, { ...returnsMap, ...map })
|
|
20
|
+
return createHandlerBuilder<TAppContext>(validators, middlewares, { ...returnsMap, ...map });
|
|
21
21
|
},
|
|
22
22
|
use(unitOrOptions: MiddlewareDefinition) {
|
|
23
|
-
middlewares.push(unitOrOptions)
|
|
24
|
-
return builder
|
|
23
|
+
middlewares.push(unitOrOptions);
|
|
24
|
+
return builder;
|
|
25
25
|
},
|
|
26
26
|
handler(fn: (ctx: unknown) => unknown) {
|
|
27
|
-
const mwReturns = collectReturnsFromDefinitions(middlewares)
|
|
28
|
-
const mergedReturns = { ...mwReturns, ...returnsMap }
|
|
27
|
+
const mwReturns = collectReturnsFromDefinitions(middlewares);
|
|
28
|
+
const mergedReturns = { ...mwReturns, ...returnsMap };
|
|
29
29
|
const unit = {
|
|
30
30
|
$Infer: { Output: undefined as unknown as Response },
|
|
31
31
|
middlewares: [...middlewares],
|
|
32
|
-
handler: fn as HandlerUnit<readonly [], ValidatorParts>[
|
|
32
|
+
handler: fn as HandlerUnit<readonly [], ValidatorParts>["handler"],
|
|
33
33
|
...pickDefinedSchemas(validators),
|
|
34
34
|
...(Object.keys(mergedReturns).length > 0 ? { returns: mergedReturns } : {}),
|
|
35
|
-
} as HandlerUnit<readonly [], ValidatorParts
|
|
36
|
-
return unit
|
|
35
|
+
} as HandlerUnit<readonly [], ValidatorParts>;
|
|
36
|
+
return unit;
|
|
37
37
|
},
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
39
|
|
|
40
|
-
return builder as unknown as HandlerBuilder<readonly [], ValidatorParts, {}, TAppContext
|
|
40
|
+
return builder as unknown as HandlerBuilder<readonly [], ValidatorParts, {}, TAppContext>;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export function defineHandler<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{},
|
|
47
|
-
TAppContext
|
|
48
|
-
>
|
|
43
|
+
export function defineHandler<
|
|
44
|
+
TAppContext extends Record<string, unknown> = AppContext,
|
|
45
|
+
>(): HandlerBuilder<readonly [], {}, {}, TAppContext>;
|
|
49
46
|
|
|
50
47
|
export function defineHandler<
|
|
51
48
|
TAppContext extends Record<string, unknown> = AppContext,
|
|
52
49
|
TQuery = unknown,
|
|
53
50
|
TParams = unknown,
|
|
54
51
|
TBody = unknown,
|
|
55
|
-
>(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
},
|
|
61
|
-
): HandlerBuilder<
|
|
62
|
-
readonly [],
|
|
63
|
-
{ query: TQuery, params: TParams, body: TBody },
|
|
64
|
-
{},
|
|
65
|
-
TAppContext
|
|
66
|
-
>
|
|
52
|
+
>(options: {
|
|
53
|
+
query?: Schema<TQuery>;
|
|
54
|
+
params?: Schema<TParams>;
|
|
55
|
+
body?: Schema<TBody>;
|
|
56
|
+
}): HandlerBuilder<readonly [], { query: TQuery; params: TParams; body: TBody }, {}, TAppContext>;
|
|
67
57
|
|
|
68
58
|
export function defineHandler<TAppContext extends Record<string, unknown> = AppContext>(
|
|
69
59
|
options?: SchemaValidators,
|
|
70
60
|
): HandlerBuilder<readonly [], ValidatorParts, {}, TAppContext> {
|
|
71
|
-
return createHandlerBuilder<TAppContext>(options ?? {}, [], {})
|
|
61
|
+
return createHandlerBuilder<TAppContext>(options ?? {}, [], {});
|
|
72
62
|
}
|