@taserjs/router 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/cjs/builder/app.cjs +27 -0
  2. package/dist/cjs/builder/app.cjs.map +1 -0
  3. package/dist/cjs/builder/app.d.cts +11 -0
  4. package/dist/cjs/{constants.cjs → builder/constants.cjs} +1 -1
  5. package/dist/cjs/builder/constants.cjs.map +1 -0
  6. package/dist/cjs/{factories.cjs → builder/factories.cjs} +5 -5
  7. package/dist/cjs/builder/factories.cjs.map +1 -0
  8. package/dist/cjs/builder/factories.d.cts +15 -0
  9. package/dist/cjs/{middleware.cjs → builder/middleware.cjs} +1 -1
  10. package/dist/cjs/builder/middleware.cjs.map +1 -0
  11. package/dist/cjs/{middleware.d.cts → builder/middleware.d.cts} +1 -1
  12. package/dist/cjs/{route.cjs → builder/route.cjs} +41 -34
  13. package/dist/cjs/builder/route.cjs.map +1 -0
  14. package/dist/cjs/builder/route.d.cts +4 -0
  15. package/dist/cjs/{taser-router.cjs → builder/router.cjs} +38 -13
  16. package/dist/cjs/builder/router.cjs.map +1 -0
  17. package/dist/{esm/taser-router.d.ts → cjs/builder/router.d.cts} +16 -11
  18. package/dist/cjs/{create-context.cjs → context/create-context.cjs} +1 -1
  19. package/dist/cjs/context/create-context.cjs.map +1 -0
  20. package/dist/cjs/{create-context.d.cts → context/create-context.d.cts} +2 -2
  21. package/dist/cjs/define/middleware.cjs +2 -2
  22. package/dist/cjs/define/middleware.cjs.map +1 -1
  23. package/dist/cjs/define/middleware.d.cts +10 -8
  24. package/dist/cjs/define/validators.cjs +1 -1
  25. package/dist/cjs/define/validators.cjs.map +1 -1
  26. package/dist/cjs/define/validators.d.cts +1 -1
  27. package/dist/cjs/index.cjs +6 -28
  28. package/dist/cjs/index.d.cts +7 -8
  29. package/dist/cjs/middleware/body-limit.cjs +2 -2
  30. package/dist/cjs/middleware/body-limit.cjs.map +1 -1
  31. package/dist/cjs/middleware/compress.cjs +2 -2
  32. package/dist/cjs/middleware/compress.cjs.map +1 -1
  33. package/dist/cjs/middleware/cors.cjs +2 -2
  34. package/dist/cjs/middleware/cors.cjs.map +1 -1
  35. package/dist/cjs/middleware/csrf.cjs +2 -2
  36. package/dist/cjs/middleware/csrf.cjs.map +1 -1
  37. package/dist/cjs/middleware/etag.cjs +2 -2
  38. package/dist/cjs/middleware/etag.cjs.map +1 -1
  39. package/dist/cjs/middleware/jwk.cjs +2 -8
  40. package/dist/cjs/middleware/jwk.cjs.map +1 -1
  41. package/dist/cjs/middleware/jwt.cjs +2 -8
  42. package/dist/cjs/middleware/jwt.cjs.map +1 -1
  43. package/dist/cjs/middleware/secure-headers.cjs +2 -2
  44. package/dist/cjs/middleware/secure-headers.cjs.map +1 -1
  45. package/dist/cjs/middleware/timing.cjs +2 -2
  46. package/dist/cjs/middleware/timing.cjs.map +1 -1
  47. package/dist/cjs/middleware/wrap-hono.cjs +10 -0
  48. package/dist/cjs/middleware/wrap-hono.cjs.map +1 -1
  49. package/dist/cjs/middleware/wrap-hono.d.cts +4 -0
  50. package/dist/cjs/reply.cjs +8 -19
  51. package/dist/cjs/reply.d.cts +1 -2
  52. package/dist/cjs/stream.cjs +8 -31
  53. package/dist/cjs/stream.d.cts +1 -1
  54. package/dist/cjs/types/app.d.cts +8 -26
  55. package/dist/cjs/types/index.d.cts +60 -19
  56. package/dist/cjs/types/returns.d.cts +8 -11
  57. package/dist/cjs/types/type-utils.d.cts +8 -7
  58. package/dist/cjs/types/units.cjs.map +1 -1
  59. package/dist/cjs/types/units.d.cts +6 -17
  60. package/dist/esm/builder/app.d.ts +11 -0
  61. package/dist/esm/builder/app.js +26 -0
  62. package/dist/esm/builder/app.js.map +1 -0
  63. package/dist/esm/{constants.js → builder/constants.js} +1 -1
  64. package/dist/esm/builder/constants.js.map +1 -0
  65. package/dist/esm/builder/factories.d.ts +15 -0
  66. package/dist/esm/{factories.js → builder/factories.js} +5 -5
  67. package/dist/esm/builder/factories.js.map +1 -0
  68. package/dist/esm/{middleware.d.ts → builder/middleware.d.ts} +1 -1
  69. package/dist/esm/{middleware.js → builder/middleware.js} +1 -1
  70. package/dist/esm/builder/middleware.js.map +1 -0
  71. package/dist/esm/builder/route.d.ts +4 -0
  72. package/dist/esm/{route.js → builder/route.js} +41 -34
  73. package/dist/esm/builder/route.js.map +1 -0
  74. package/dist/{cjs/taser-router.d.cts → esm/builder/router.d.ts} +16 -11
  75. package/dist/esm/{taser-router.js → builder/router.js} +37 -12
  76. package/dist/esm/builder/router.js.map +1 -0
  77. package/dist/esm/{create-context.d.ts → context/create-context.d.ts} +2 -2
  78. package/dist/esm/{create-context.js → context/create-context.js} +1 -1
  79. package/dist/esm/context/create-context.js.map +1 -0
  80. package/dist/esm/define/middleware.d.ts +10 -8
  81. package/dist/esm/define/middleware.js +2 -2
  82. package/dist/esm/define/middleware.js.map +1 -1
  83. package/dist/esm/define/validators.d.ts +1 -1
  84. package/dist/esm/define/validators.js +1 -1
  85. package/dist/esm/define/validators.js.map +1 -1
  86. package/dist/esm/index.d.ts +7 -8
  87. package/dist/esm/index.js +5 -6
  88. package/dist/esm/middleware/body-limit.js +2 -2
  89. package/dist/esm/middleware/body-limit.js.map +1 -1
  90. package/dist/esm/middleware/compress.js +2 -2
  91. package/dist/esm/middleware/compress.js.map +1 -1
  92. package/dist/esm/middleware/cors.js +2 -2
  93. package/dist/esm/middleware/cors.js.map +1 -1
  94. package/dist/esm/middleware/csrf.js +2 -2
  95. package/dist/esm/middleware/csrf.js.map +1 -1
  96. package/dist/esm/middleware/etag.js +2 -2
  97. package/dist/esm/middleware/etag.js.map +1 -1
  98. package/dist/esm/middleware/jwk.js +2 -8
  99. package/dist/esm/middleware/jwk.js.map +1 -1
  100. package/dist/esm/middleware/jwt.js +2 -8
  101. package/dist/esm/middleware/jwt.js.map +1 -1
  102. package/dist/esm/middleware/secure-headers.js +2 -2
  103. package/dist/esm/middleware/secure-headers.js.map +1 -1
  104. package/dist/esm/middleware/timing.js +2 -2
  105. package/dist/esm/middleware/timing.js.map +1 -1
  106. package/dist/esm/middleware/wrap-hono.d.ts +4 -0
  107. package/dist/esm/middleware/wrap-hono.js +10 -1
  108. package/dist/esm/middleware/wrap-hono.js.map +1 -1
  109. package/dist/esm/reply.d.ts +1 -2
  110. package/dist/esm/reply.js +1 -2
  111. package/dist/esm/stream.d.ts +1 -1
  112. package/dist/esm/stream.js +1 -2
  113. package/dist/esm/types/app.d.ts +8 -26
  114. package/dist/esm/types/index.d.ts +60 -19
  115. package/dist/esm/types/returns.d.ts +8 -11
  116. package/dist/esm/types/type-utils.d.ts +8 -7
  117. package/dist/esm/types/units.d.ts +6 -17
  118. package/dist/esm/types/units.js.map +1 -1
  119. package/package.json +3 -3
  120. package/src/builder/app.ts +39 -0
  121. package/src/builder/factories.ts +58 -0
  122. package/src/{middleware.ts → builder/middleware.ts} +2 -2
  123. package/src/{route.ts → builder/route.ts} +55 -35
  124. package/src/{taser-router.ts → builder/router.ts} +77 -28
  125. package/src/{create-context.ts → context/create-context.ts} +2 -2
  126. package/src/define/middleware.ts +115 -123
  127. package/src/define/validators.ts +1 -1
  128. package/src/index.ts +13 -20
  129. package/src/middleware/body-limit.ts +2 -2
  130. package/src/middleware/compress.ts +2 -2
  131. package/src/middleware/cors.ts +2 -2
  132. package/src/middleware/csrf.ts +2 -2
  133. package/src/middleware/etag.ts +2 -2
  134. package/src/middleware/jwk.ts +2 -7
  135. package/src/middleware/jwt.ts +2 -7
  136. package/src/middleware/secure-headers.ts +2 -2
  137. package/src/middleware/timing.ts +2 -2
  138. package/src/middleware/wrap-hono.ts +13 -0
  139. package/src/reply.ts +1 -11
  140. package/src/stream.ts +1 -1
  141. package/src/types/app.ts +13 -28
  142. package/src/types/index.ts +126 -22
  143. package/src/types/returns.ts +9 -78
  144. package/src/types/type-utils.ts +10 -6
  145. package/src/types/units.ts +36 -16
  146. package/dist/cjs/constants.cjs.map +0 -1
  147. package/dist/cjs/create-context.cjs.map +0 -1
  148. package/dist/cjs/factories.cjs.map +0 -1
  149. package/dist/cjs/factories.d.cts +0 -61
  150. package/dist/cjs/middleware.cjs.map +0 -1
  151. package/dist/cjs/route.cjs.map +0 -1
  152. package/dist/cjs/route.d.cts +0 -5
  153. package/dist/cjs/taser-app.cjs +0 -36
  154. package/dist/cjs/taser-app.cjs.map +0 -1
  155. package/dist/cjs/taser-app.d.cts +0 -18
  156. package/dist/cjs/taser-router.cjs.map +0 -1
  157. package/dist/esm/constants.js.map +0 -1
  158. package/dist/esm/create-context.js.map +0 -1
  159. package/dist/esm/factories.d.ts +0 -61
  160. package/dist/esm/factories.js.map +0 -1
  161. package/dist/esm/middleware.js.map +0 -1
  162. package/dist/esm/route.d.ts +0 -5
  163. package/dist/esm/route.js.map +0 -1
  164. package/dist/esm/taser-app.d.ts +0 -18
  165. package/dist/esm/taser-app.js +0 -35
  166. package/dist/esm/taser-app.js.map +0 -1
  167. package/dist/esm/taser-router.js.map +0 -1
  168. package/src/factories.ts +0 -185
  169. package/src/taser-app.ts +0 -38
  170. /package/dist/cjs/{constants.d.cts → builder/constants.d.cts} +0 -0
  171. /package/dist/esm/{constants.d.ts → builder/constants.d.ts} +0 -0
  172. /package/src/{constants.ts → builder/constants.ts} +0 -0
@@ -4,7 +4,7 @@ import {
4
4
  type OnErrorHandler,
5
5
  type RouteManifestShape,
6
6
  } from "@taserjs/router-core";
7
- import { normalizeOnError } from "@taserjs/router-utils";
7
+ import { isPromise, normalizeOnError } from "@taserjs/router-utils";
8
8
 
9
9
  import {
10
10
  createAllRoute,
@@ -17,13 +17,15 @@ import {
17
17
  createPostRoute,
18
18
  createPutRoute,
19
19
  } from "./factories.js";
20
- import { defineHandler } from "./define/handler.js";
20
+ import { defineHandler } from "../define/handler.js";
21
+ import { defineMiddleware, type DefineMiddlewareFn } from "../define/middleware.js";
21
22
  import { createMiddleware } from "./middleware.js";
22
- import { TaserApp } from "./taser-app.js";
23
- import type { ContextDefinition, CreateTaserAppOptions, OnErrorOptions } from "./types/app.js";
24
- import type { AppContext } from "./types/units.js";
25
- import type { HandlerBuilder, LayoutId, MiddlewareBuilder } from "./types/index.js";
26
- import type { Schema } from "./types/schema.js";
23
+ import { TaserApp } from "./app.js";
24
+ import type { ContextDefinition, CreateTaserAppOptions, OnErrorOptions } from "../types/app.js";
25
+ import type { AppContext } from "../types/units.js";
26
+ import type { HandlerBuilder, LayoutId, MiddlewareBuilder } from "../types/index.js";
27
+ import type { ReturnsMap } from "../types/returns.js";
28
+ import type { Schema } from "../types/schema.js";
27
29
  import type {
28
30
  CreateAllRoute,
29
31
  CreateAnyRoute,
@@ -46,7 +48,10 @@ type RouterState = {
46
48
 
47
49
  const emptyContext: ContextDefinition<Record<string, unknown>, Record<string, unknown>> = {};
48
50
 
49
- export class TaserRouter<TAppContext extends Record<string, unknown> = AppContext> {
51
+ export class TaserRouter<
52
+ TAppContext extends Record<string, unknown> = AppContext,
53
+ THasNotFound extends boolean = false,
54
+ > {
50
55
  private readonly state: RouterState;
51
56
 
52
57
  constructor(options: CreateTaserAppOptions = {}, state?: Partial<Omit<RouterState, "options">>) {
@@ -60,22 +65,23 @@ export class TaserRouter<TAppContext extends Record<string, unknown> = AppContex
60
65
 
61
66
  context<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>>(
62
67
  definition: ContextDefinition<TBoot, TReq>,
63
- ): TaserRouter<TBoot & TReq> {
68
+ ): TaserRouter<TBoot & TReq, THasNotFound> {
64
69
  this.state.contextDef = definition;
65
- return this as unknown as TaserRouter<TBoot & TReq>;
70
+ return this as unknown as TaserRouter<TBoot & TReq, THasNotFound>;
66
71
  }
67
72
 
68
- onError<
69
- TResponses extends import("./types/returns.js").ReturnsMap =
70
- import("./types/returns.js").ReturnsMap,
71
- >(options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>["handle"]): this {
73
+ onError<TResponses extends ReturnsMap = ReturnsMap>(
74
+ options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>["handle"],
75
+ ): this {
72
76
  this.state.onError = toOnErrorHandler(options);
73
77
  return this;
74
78
  }
75
79
 
76
- notFound(handler: (ctx: unknown) => Response | Promise<Response> | unknown): this {
80
+ notFound(
81
+ handler: (ctx: unknown) => Response | Promise<Response> | unknown,
82
+ ): TaserRouter<TAppContext, true> {
77
83
  this.state.notFound = (ctx) => handler(ctx);
78
- return this;
84
+ return this as unknown as TaserRouter<TAppContext, true>;
79
85
  }
80
86
 
81
87
  get: CreateWithoutBodyRoute<"GET", TAppContext> = createGetRoute as CreateWithoutBodyRoute<
@@ -126,22 +132,63 @@ export class TaserRouter<TAppContext extends Record<string, unknown> = AppContex
126
132
  : defineHandler<TAppContext>(options);
127
133
  }
128
134
 
129
- create<const TManifest extends RouteManifestShape>(manifest: TManifest): TaserApp<TManifest> {
135
+ defineMiddleware: DefineMiddlewareFn<TAppContext> =
136
+ defineMiddleware as DefineMiddlewareFn<TAppContext>;
137
+
138
+ create<const TManifest extends RouteManifestShape>(
139
+ manifest: TManifest,
140
+ runtimeOptions?: { basePath?: string },
141
+ ): TaserApp<TManifest, THasNotFound> {
130
142
  const definition = this.state.contextDef;
131
143
  const validateResponse = this.state.options.response?.validate ?? true;
132
144
  const onValidationFailure = this.state.options.response?.onValidationFailure;
133
- const basePath = this.state.options.basePath;
145
+ const basePath = runtimeOptions?.basePath;
134
146
 
135
147
  const hasCustomContext = definition.boot !== undefined || definition.request !== undefined;
136
- const bootPromise = hasCustomContext
137
- ? Promise.resolve(definition.boot?.() ?? ({} as Record<string, unknown>))
138
- : undefined;
148
+ let bootContextResolved: Record<string, unknown> | undefined;
149
+ let bootPromise: Promise<Record<string, unknown>> | undefined;
150
+
151
+ if (definition.boot !== undefined) {
152
+ const bootResult = definition.boot();
153
+ if (isPromise(bootResult)) {
154
+ bootPromise = bootResult.then((ctx) => {
155
+ bootContextResolved = (ctx ?? {}) as Record<string, unknown>;
156
+ return bootContextResolved;
157
+ });
158
+ } else {
159
+ bootContextResolved = (bootResult ?? {}) as Record<string, unknown>;
160
+ }
161
+ } else if (hasCustomContext) {
162
+ bootContextResolved = {};
163
+ }
139
164
 
140
165
  const contextFactory = hasCustomContext
141
- ? async ({ native }: { native?: unknown } = {}) => {
142
- const bootContext = (await bootPromise) ?? {};
143
- const requestContext = (await definition.request?.({ native: native as never })) ?? {};
144
- return { ...bootContext, ...requestContext };
166
+ ? (req?: Request) => {
167
+ if (bootPromise !== undefined && bootContextResolved === undefined) {
168
+ return bootPromise.then(async (bootContext) => {
169
+ if (!definition.request) {
170
+ return { ...bootContext };
171
+ }
172
+ const requestResult = definition.request(req!);
173
+ const requestContext = isPromise(requestResult) ? await requestResult : requestResult;
174
+ return { ...bootContext, ...requestContext };
175
+ });
176
+ }
177
+
178
+ const bootContext = bootContextResolved ?? {};
179
+ if (!definition.request) {
180
+ return { ...bootContext };
181
+ }
182
+
183
+ const requestResult = definition.request(req!);
184
+ if (isPromise(requestResult)) {
185
+ return requestResult.then((requestContext) => ({
186
+ ...bootContext,
187
+ ...requestContext,
188
+ }));
189
+ }
190
+
191
+ return { ...bootContext, ...(requestResult as Record<string, unknown>) };
145
192
  }
146
193
  : () => ({});
147
194
 
@@ -156,10 +203,12 @@ export class TaserRouter<TAppContext extends Record<string, unknown> = AppContex
156
203
  ...(this.state.options.cookies !== undefined ? { cookies: this.state.options.cookies } : {}),
157
204
  });
158
205
 
159
- return new TaserApp(runtime, manifest);
206
+ return new TaserApp(runtime, manifest) as unknown as TaserApp<TManifest, THasNotFound>;
160
207
  }
161
208
  }
162
209
 
163
- export function createTaserApp(options: CreateTaserAppOptions = {}): TaserRouter {
164
- return new TaserRouter(options);
210
+ export function createTaserApp(
211
+ options: CreateTaserAppOptions = {},
212
+ ): TaserRouter<AppContext, false> {
213
+ return new TaserRouter<AppContext, false>(options);
165
214
  }
@@ -1,6 +1,6 @@
1
1
  import type { ReservedContextKey } from "@taserjs/router-core";
2
2
 
3
- import type { ContextDefinition } from "./types/app.js";
3
+ import type { ContextDefinition } from "../types/app.js";
4
4
 
5
5
  type NoReservedKeysConstraint<
6
6
  TBoot extends Record<string, unknown>,
@@ -16,4 +16,4 @@ export function createContext<
16
16
  return definition;
17
17
  }
18
18
 
19
- export type { ContextDefinition, InferAppContext } from "./types/app.js";
19
+ export type { ContextDefinition, InferAppContext } from "../types/app.js";
@@ -3,8 +3,7 @@ import { createTaserCompatHandler, type Awaitable } from "@taserjs/router-core";
3
3
  import type { ReturnsMap } from "../types/returns.js";
4
4
  import type {
5
5
  AppContext,
6
- ExtractState,
7
- IsUnknown,
6
+ DefineMiddlewareResult,
8
7
  MiddlewareReturnFromParts,
9
8
  MiddlewareUnit,
10
9
  NextFn,
@@ -17,9 +16,9 @@ import type {
17
16
  } from "../types/index.js";
18
17
  import type { Schema } from "../types/schema.js";
19
18
 
20
- type HonoMiddlewareHandler = Parameters<typeof createTaserCompatHandler>[0];
19
+ export type HonoMiddlewareHandler = Parameters<typeof createTaserCompatHandler>[0];
21
20
 
22
- type HonoMiddlewareUnit = MiddlewareUnit<
21
+ export type HonoMiddlewareUnit = MiddlewareUnit<
23
22
  MiddlewareReturnFromParts<unknown, unknown, unknown, {}>,
24
23
  {},
25
24
  null,
@@ -109,145 +108,137 @@ export type MultiScopedMiddlewareOptions<
109
108
  ) => Awaitable<R>;
110
109
  };
111
110
 
112
- export function defineMiddleware(middleware: HonoMiddlewareHandler): HonoMiddlewareUnit;
111
+ export interface DefineMiddlewareFn<TAppContext extends Record<string, unknown> = AppContext> {
112
+ (middleware: HonoMiddlewareHandler): HonoMiddlewareUnit;
113
113
 
114
- export function defineMiddleware<
115
- const Layout extends LayoutId,
116
- TState = unknown,
117
- TRequires = {},
118
- TAppContext extends Record<string, unknown> = AppContext,
119
- TQuery = unknown,
120
- TParams = unknown,
121
- TBody = unknown,
122
- TReturns extends ReturnsMap = {},
123
- TQueryIn = unknown,
124
- TParamsIn = unknown,
125
- TBodyIn = unknown,
126
- R = unknown,
127
- >(
128
- layout: Layout,
129
- options: ScopedMiddlewareOptions<
130
- Layout,
131
- TState,
132
- TRequires,
114
+ <
115
+ const Layout extends LayoutId,
116
+ TState = unknown,
117
+ TRequires = {},
118
+ TQuery = unknown,
119
+ TParams = unknown,
120
+ TBody = unknown,
121
+ TReturns extends ReturnsMap = {},
122
+ TQueryIn = unknown,
123
+ TParamsIn = unknown,
124
+ TBodyIn = unknown,
125
+ R = unknown,
126
+ >(
127
+ layout: Layout,
128
+ options: ScopedMiddlewareOptions<
129
+ Layout,
130
+ TState,
131
+ TRequires,
132
+ TQuery,
133
+ TParams,
134
+ TBody,
135
+ TReturns,
136
+ TQueryIn,
137
+ TParamsIn,
138
+ TBodyIn,
139
+ TAppContext,
140
+ R
141
+ >,
142
+ ): DefineMiddlewareResult<
133
143
  TQuery,
134
144
  TParams,
135
145
  TBody,
136
- TReturns,
146
+ TState,
147
+ R,
137
148
  TQueryIn,
138
149
  TParamsIn,
139
150
  TBodyIn,
140
- TAppContext,
141
- R
142
- >,
143
- ): MiddlewareUnit<
144
- MiddlewareReturnFromParts<
145
- TQuery,
146
- TParams,
147
- TBody,
148
- IsUnknown<TState> extends true ? ExtractState<R> : TState,
149
- TQueryIn,
150
- TParamsIn,
151
- TBodyIn
152
- >,
153
- TReturns,
154
- Layout,
155
- TRequires
156
- >;
151
+ TReturns,
152
+ Layout,
153
+ TRequires
154
+ >;
157
155
 
158
- export function defineMiddleware<
159
- const Layouts extends readonly [LayoutId, ...LayoutId[]],
160
- TState = unknown,
161
- TRequires = {},
162
- TAppContext extends Record<string, unknown> = AppContext,
163
- TQuery = unknown,
164
- TParams = unknown,
165
- TBody = unknown,
166
- TReturns extends ReturnsMap = {},
167
- TQueryIn = unknown,
168
- TParamsIn = unknown,
169
- TBodyIn = unknown,
170
- R = unknown,
171
- >(
172
- layouts: Layouts,
173
- options: MultiScopedMiddlewareOptions<
174
- Layouts,
175
- TState,
176
- TRequires,
156
+ <
157
+ const Layouts extends readonly [LayoutId, ...LayoutId[]],
158
+ TState = unknown,
159
+ TRequires = {},
160
+ TQuery = unknown,
161
+ TParams = unknown,
162
+ TBody = unknown,
163
+ TReturns extends ReturnsMap = {},
164
+ TQueryIn = unknown,
165
+ TParamsIn = unknown,
166
+ TBodyIn = unknown,
167
+ R = unknown,
168
+ >(
169
+ layouts: Layouts,
170
+ options: MultiScopedMiddlewareOptions<
171
+ Layouts,
172
+ TState,
173
+ TRequires,
174
+ TQuery,
175
+ TParams,
176
+ TBody,
177
+ TReturns,
178
+ TQueryIn,
179
+ TParamsIn,
180
+ TBodyIn,
181
+ TAppContext,
182
+ R
183
+ >,
184
+ ): DefineMiddlewareResult<
177
185
  TQuery,
178
186
  TParams,
179
187
  TBody,
180
- TReturns,
188
+ TState,
189
+ R,
181
190
  TQueryIn,
182
191
  TParamsIn,
183
192
  TBodyIn,
184
- TAppContext,
185
- R
186
- >,
187
- ): MiddlewareUnit<
188
- MiddlewareReturnFromParts<
189
- TQuery,
190
- TParams,
191
- TBody,
192
- IsUnknown<TState> extends true ? ExtractState<R> : TState,
193
- TQueryIn,
194
- TParamsIn,
195
- TBodyIn
196
- >,
197
- TReturns,
198
- Layouts,
199
- TRequires
200
- >;
193
+ TReturns,
194
+ Layouts,
195
+ TRequires
196
+ >;
201
197
 
202
- export function defineMiddleware<
203
- TState = unknown,
204
- TRequires = {},
205
- TAppContext extends Record<string, unknown> = AppContext,
206
- TQuery = unknown,
207
- TParams = unknown,
208
- TBody = unknown,
209
- TReturns extends ReturnsMap = {},
210
- TQueryIn = unknown,
211
- TParamsIn = unknown,
212
- TBodyIn = unknown,
213
- R = unknown,
214
- >(
215
- options: DefineMiddlewareOptions<
216
- TState,
217
- TRequires,
198
+ <
199
+ TState = unknown,
200
+ TRequires = {},
201
+ TQuery = unknown,
202
+ TParams = unknown,
203
+ TBody = unknown,
204
+ TReturns extends ReturnsMap = {},
205
+ TQueryIn = unknown,
206
+ TParamsIn = unknown,
207
+ TBodyIn = unknown,
208
+ R = unknown,
209
+ >(
210
+ options: DefineMiddlewareOptions<
211
+ TState,
212
+ TRequires,
213
+ TQuery,
214
+ TParams,
215
+ TBody,
216
+ TReturns,
217
+ TQueryIn,
218
+ TParamsIn,
219
+ TBodyIn,
220
+ TAppContext,
221
+ R
222
+ >,
223
+ ): DefineMiddlewareResult<
218
224
  TQuery,
219
225
  TParams,
220
226
  TBody,
221
- TReturns,
227
+ TState,
228
+ R,
222
229
  TQueryIn,
223
230
  TParamsIn,
224
231
  TBodyIn,
225
- TAppContext,
226
- R
227
- >,
228
- ): MiddlewareUnit<
229
- MiddlewareReturnFromParts<
230
- TQuery,
231
- TParams,
232
- TBody,
233
- IsUnknown<TState> extends true ? ExtractState<R> : TState,
234
- TQueryIn,
235
- TParamsIn,
236
- TBodyIn
237
- >,
238
- TReturns,
239
- null,
240
- TRequires
241
- >;
232
+ TReturns,
233
+ null,
234
+ TRequires
235
+ >;
236
+ }
242
237
 
243
- export function defineMiddleware(
244
- first:
245
- | string
246
- | readonly string[]
247
- | HonoMiddlewareHandler
248
- | DefineMiddlewareOptions<any, any, any, any, any, any, any, any, any, any, any>,
249
- second?: DefineMiddlewareOptions<any, any, any, any, any, any, any, any, any, any, any>,
250
- ): unknown {
238
+ export const defineMiddleware: DefineMiddlewareFn<AppContext> = function defineMiddleware(
239
+ first: any,
240
+ second?: any,
241
+ ): any {
251
242
  if (typeof first === "string" || Array.isArray(first)) {
252
243
  const options = second!;
253
244
  const unit = {
@@ -262,7 +253,8 @@ export function defineMiddleware(
262
253
  if (typeof first === "function") {
263
254
  const honoMiddleware = first as HonoMiddlewareHandler;
264
255
  return defineMiddleware({
265
- handler: (ctx, next) => createTaserCompatHandler(honoMiddleware)(ctx, next),
256
+ handler: (ctx: unknown, next: (state?: Record<string, unknown>) => unknown) =>
257
+ createTaserCompatHandler(honoMiddleware)(ctx, next),
266
258
  });
267
259
  }
268
260
 
@@ -286,4 +278,4 @@ export function defineMiddleware(
286
278
  };
287
279
 
288
280
  return unit;
289
- }
281
+ };
@@ -1,5 +1,5 @@
1
1
  import type { Schema } from "../types/schema.js";
2
- import { SCHEMA_KEYS, type SchemaKey } from "../constants.js";
2
+ import { SCHEMA_KEYS, type SchemaKey } from "../builder/constants.js";
3
3
 
4
4
  export type SchemaValidators = {
5
5
  query?: Schema<unknown>;
package/src/index.ts CHANGED
@@ -1,44 +1,37 @@
1
1
  export type { RouterRegister } from "./register.js";
2
2
  export type {
3
+ HttpMethod,
3
4
  InferInput,
4
5
  InferOutput,
6
+ InferRouteContext,
7
+ InferRouteInput,
8
+ InferRouteOutput,
5
9
  Method,
10
+ MiddlewareDefinition,
6
11
  PathParams,
7
12
  ReturnsMap,
13
+ RouteDefinition,
14
+ RouteExport,
8
15
  RoutePath,
9
16
  Schema,
10
17
  Simplify,
18
+ StatusCode,
11
19
  } from "./types/index.js";
12
20
  export type {
13
21
  ContextDefinition,
14
- CreateContextArgs,
15
22
  CreateTaserAppOptions,
16
23
  InferAppContext,
17
24
  InferAppManifest,
18
25
  OnErrorOptions,
19
26
  RouteManifestShape,
20
- TaserHandler,
21
27
  } from "./types/app.js";
22
28
 
23
- export {
24
- isReplyResult,
25
- reply,
26
- stream,
27
- ValidationError,
28
- validationErrorSchema,
29
- } from "@taserjs/router-utils";
30
- export type {
31
- ReplyBodyKind,
32
- ReplyOf,
33
- ResponseValidationFailureHandler,
34
- SuccessReplyData,
35
- SuccessStatusCode,
36
- } from "@taserjs/router-utils";
29
+ export { ValidationError, validationErrorSchema } from "@taserjs/router-utils";
30
+ export type { ResponseValidationFailureHandler, SuccessStatusCode } from "@taserjs/router-utils";
37
31
 
38
- export { createAnyRoute, createAllRoute } from "./factories.js";
39
- export { createTaserApp, TaserRouter } from "./taser-router.js";
40
- export { TaserApp, TaserNativeBound } from "./taser-app.js";
41
- export { createContext } from "./create-context.js";
32
+ export { createTaserApp, TaserRouter } from "./builder/router.js";
33
+ export { TaserApp } from "./builder/app.js";
34
+ export { createContext } from "./context/create-context.js";
42
35
  export { defineHandler } from "./define/handler.js";
43
36
  export { defineMiddleware } from "./define/middleware.js";
44
37
 
@@ -2,10 +2,10 @@ import { bodyLimit as honoBodyLimit } from "hono/body-limit";
2
2
 
3
3
  import { wrapHonoMiddleware } from "./wrap-hono.js";
4
4
 
5
- const honoBodyLimitMiddleware = wrapHonoMiddleware(honoBodyLimit);
5
+ const wrapped = wrapHonoMiddleware(honoBodyLimit);
6
6
 
7
7
  export function bodyLimit(...args: Parameters<typeof honoBodyLimit>) {
8
- return honoBodyLimitMiddleware(...args);
8
+ return wrapped(...args);
9
9
  }
10
10
 
11
11
  export type BodyLimitOptions = Parameters<typeof honoBodyLimit>[0];
@@ -2,10 +2,10 @@ import { compress as honoCompress } from "hono/compress";
2
2
 
3
3
  import { wrapHonoMiddleware } from "./wrap-hono.js";
4
4
 
5
- const honoCompressMiddleware = wrapHonoMiddleware(honoCompress);
5
+ const wrapped = wrapHonoMiddleware(honoCompress);
6
6
 
7
7
  export function compress(...args: Parameters<typeof honoCompress>) {
8
- return honoCompressMiddleware(...args);
8
+ return wrapped(...args);
9
9
  }
10
10
 
11
11
  export type CompressOptions = NonNullable<Parameters<typeof honoCompress>[0]>;
@@ -2,10 +2,10 @@ import { cors as honoCors } from "hono/cors";
2
2
 
3
3
  import { wrapHonoMiddleware } from "./wrap-hono.js";
4
4
 
5
- const honoCorsMiddleware = wrapHonoMiddleware(honoCors);
5
+ const wrapped = wrapHonoMiddleware(honoCors);
6
6
 
7
7
  export function cors(...args: Parameters<typeof honoCors>) {
8
- return honoCorsMiddleware(...args);
8
+ return wrapped(...args);
9
9
  }
10
10
 
11
11
  export type CorsOptions = NonNullable<Parameters<typeof honoCors>[0]>;
@@ -2,10 +2,10 @@ import { csrf as honoCsrf } from "hono/csrf";
2
2
 
3
3
  import { wrapHonoMiddleware } from "./wrap-hono.js";
4
4
 
5
- const honoCsrfMiddleware = wrapHonoMiddleware(honoCsrf);
5
+ const wrapped = wrapHonoMiddleware(honoCsrf);
6
6
 
7
7
  export function csrf(...args: Parameters<typeof honoCsrf>) {
8
- return honoCsrfMiddleware(...args);
8
+ return wrapped(...args);
9
9
  }
10
10
 
11
11
  export type CsrfOptions = NonNullable<Parameters<typeof honoCsrf>[0]>;
@@ -2,10 +2,10 @@ import { etag as honoEtag } from "hono/etag";
2
2
 
3
3
  import { wrapHonoMiddleware } from "./wrap-hono.js";
4
4
 
5
- const honoEtagMiddleware = wrapHonoMiddleware(honoEtag);
5
+ const wrapped = wrapHonoMiddleware(honoEtag);
6
6
 
7
7
  export function etag(...args: Parameters<typeof honoEtag>) {
8
- return honoEtagMiddleware(...args);
8
+ return wrapped(...args);
9
9
  }
10
10
 
11
11
  export type EtagOptions = NonNullable<Parameters<typeof honoEtag>[0]>;
@@ -1,9 +1,9 @@
1
- import { createTaserCompatHandler } from "@taserjs/router-core";
2
1
  import type { MiddlewareHandler } from "hono";
3
2
  import { jwk as honoJwk } from "hono/jwk";
4
3
 
5
4
  import { defineMiddleware } from "../define/middleware.js";
6
5
  import type { JwtMiddlewareUnit, JwtPayloadState } from "./jwt.js";
6
+ import { extractJwtPayload } from "./wrap-hono.js";
7
7
 
8
8
  export type JwkOptions = Parameters<typeof honoJwk>[0];
9
9
 
@@ -44,11 +44,6 @@ export function jwk<TPayload = Record<string, unknown>>(
44
44
  const honoMw: MiddlewareHandler = honoJwk(honoOptions, safeInit);
45
45
 
46
46
  return defineMiddleware<JwtPayloadState<TPayload>>({
47
- handler: (ctx, next) => {
48
- return createTaserCompatHandler(honoMw)(ctx, async () => {
49
- const payload = (ctx as unknown as { var: { jwtPayload?: unknown } }).var.jwtPayload;
50
- return next({ jwtPayload: payload as TPayload });
51
- });
52
- },
47
+ handler: extractJwtPayload<TPayload>(honoMw),
53
48
  });
54
49
  }
@@ -1,9 +1,9 @@
1
- import { createTaserCompatHandler } from "@taserjs/router-core";
2
1
  import type { MiddlewareHandler } from "hono";
3
2
  import { jwt as honoJwt } from "hono/jwt";
4
3
 
5
4
  import { defineMiddleware } from "../define/middleware.js";
6
5
  import type { MiddlewareReturnFromParts, MiddlewareUnit } from "../types/units.js";
6
+ import { extractJwtPayload } from "./wrap-hono.js";
7
7
 
8
8
  export type JwtPayloadState<TPayload> = {
9
9
  jwtPayload: TPayload;
@@ -24,11 +24,6 @@ export function jwt<TPayload = Record<string, unknown>>(
24
24
  ): JwtMiddlewareUnit<TPayload> {
25
25
  const honoMw: MiddlewareHandler = honoJwt(options);
26
26
  return defineMiddleware<JwtPayloadState<TPayload>>({
27
- handler: (ctx, next) => {
28
- return createTaserCompatHandler(honoMw)(ctx, async () => {
29
- const payload = (ctx as unknown as { var: { jwtPayload?: unknown } }).var.jwtPayload;
30
- return next({ jwtPayload: payload as TPayload });
31
- });
32
- },
27
+ handler: extractJwtPayload<TPayload>(honoMw),
33
28
  });
34
29
  }
@@ -2,10 +2,10 @@ import { secureHeaders as honoSecureHeaders } from "hono/secure-headers";
2
2
 
3
3
  import { wrapHonoMiddleware } from "./wrap-hono.js";
4
4
 
5
- const honoSecureHeadersMiddleware = wrapHonoMiddleware(honoSecureHeaders);
5
+ const wrapped = wrapHonoMiddleware(honoSecureHeaders);
6
6
 
7
7
  export function secureHeaders(...args: Parameters<typeof honoSecureHeaders>) {
8
- return honoSecureHeadersMiddleware(...args);
8
+ return wrapped(...args);
9
9
  }
10
10
 
11
11
  export type SecureHeadersOptions = NonNullable<Parameters<typeof honoSecureHeaders>[0]>;