@taserjs/router 0.1.5 → 0.1.6

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.
@@ -39,9 +39,12 @@ type LayoutParentsMap = RouterRegister extends {
39
39
  type LayoutParent<Layout extends LayoutId> = Layout extends keyof LayoutParentsMap ? LayoutParentsMap[Layout] extends LayoutId ? LayoutParentsMap[Layout] : null : LayoutTree[Layout] extends {
40
40
  parent: infer Parent extends LayoutId | null;
41
41
  } ? Parent : null;
42
+ type LayoutMiddlewares<Layout extends LayoutId> = LayoutTree[Layout]["middlewares"] extends {
43
+ readonly __acc?: infer Acc extends readonly unknown[];
44
+ } ? Acc : LayoutTree[Layout]["middlewares"] extends infer Acc extends readonly unknown[] ? Acc : readonly [];
42
45
  type ResolveLayoutMiddlewares<Layout extends LayoutId | null, Depth extends readonly unknown[] = []> = Depth["length"] extends 10 ? readonly [] : Layout extends LayoutId ? readonly [
43
46
  ...ResolveLayoutMiddlewares<LayoutParent<Layout>, [...Depth, unknown]>,
44
- ...LayoutTree[Layout]["middlewares"]
47
+ ...LayoutMiddlewares<Layout>
45
48
  ] : readonly [];
46
49
  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 [];
47
50
  export type ResolveLayoutMiddlewaresState<Layout extends LayoutId | null> = Layout extends LayoutId ? MergeMiddlewareField<ResolveLayoutMiddlewares<Layout>, "state"> : {};
@@ -51,7 +54,7 @@ type ResolveLayoutChainMiddlewares<Chain extends readonly LayoutId[]> = Chain ex
51
54
  infer Head extends LayoutId,
52
55
  ...infer Rest
53
56
  ] ? readonly [
54
- ...LayoutTree[Head]["middlewares"],
57
+ ...LayoutMiddlewares<Head>,
55
58
  ...ResolveLayoutChainMiddlewares<Rest extends readonly LayoutId[] ? Rest : readonly []>
56
59
  ] : readonly [];
57
60
  type RouteEntry<Path extends RoutePath, TMethod extends Method> = RouteByPathMethod[Path] extends {
@@ -156,9 +159,10 @@ export type MiddlewareChainContext<Layout extends LayoutId, Acc extends readonly
156
159
  headers: TaserHeaders;
157
160
  cookies: TaserCookieJar;
158
161
  }>;
159
- export type MiddlewareBuilder<Layout extends LayoutId, Acc extends readonly unknown[] = readonly [], TAppContext extends Record<string, unknown> = AppContext> = Acc & {
162
+ export type MiddlewareBuilder<Layout extends LayoutId, Acc extends readonly unknown[] = readonly [], TAppContext extends Record<string, unknown> = AppContext> = {
160
163
  readonly layout: Layout;
161
164
  readonly middlewares: readonly MiddlewareDefinition[];
165
+ readonly __acc?: Acc;
162
166
  readonly $Infer: {
163
167
  Context: MiddlewareChainContext<Layout, Acc, unknown, unknown, unknown, TAppContext>;
164
168
  };
@@ -176,11 +180,12 @@ export type MiddlewareBuilder<Layout extends LayoutId, Acc extends readonly unkn
176
180
  ]): MiddlewareBuilder<Layout, readonly [...Acc, TAcc], TAppContext>;
177
181
  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>;
178
182
  };
179
- export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], TReturns extends ReturnsMap = {}, TOutput = Response> = Acc & {
183
+ export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], TReturns extends ReturnsMap = {}, TOutput = Response> = {
180
184
  readonly path: Path;
181
185
  readonly method: TMethod | "ANY" | "ALL";
182
186
  readonly methods?: readonly Method[];
183
187
  readonly middlewares: readonly MiddlewareDefinition[];
188
+ readonly __acc?: Acc;
184
189
  readonly returns?: TReturns;
185
190
  readonly bodyMode?: "json" | "form" | "urlencoded";
186
191
  handler: (ctx: unknown) => Awaitable<Response>;
@@ -39,9 +39,12 @@ type LayoutParentsMap = RouterRegister extends {
39
39
  type LayoutParent<Layout extends LayoutId> = Layout extends keyof LayoutParentsMap ? LayoutParentsMap[Layout] extends LayoutId ? LayoutParentsMap[Layout] : null : LayoutTree[Layout] extends {
40
40
  parent: infer Parent extends LayoutId | null;
41
41
  } ? Parent : null;
42
+ type LayoutMiddlewares<Layout extends LayoutId> = LayoutTree[Layout]["middlewares"] extends {
43
+ readonly __acc?: infer Acc extends readonly unknown[];
44
+ } ? Acc : LayoutTree[Layout]["middlewares"] extends infer Acc extends readonly unknown[] ? Acc : readonly [];
42
45
  type ResolveLayoutMiddlewares<Layout extends LayoutId | null, Depth extends readonly unknown[] = []> = Depth["length"] extends 10 ? readonly [] : Layout extends LayoutId ? readonly [
43
46
  ...ResolveLayoutMiddlewares<LayoutParent<Layout>, [...Depth, unknown]>,
44
- ...LayoutTree[Layout]["middlewares"]
47
+ ...LayoutMiddlewares<Layout>
45
48
  ] : readonly [];
46
49
  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 [];
47
50
  export type ResolveLayoutMiddlewaresState<Layout extends LayoutId | null> = Layout extends LayoutId ? MergeMiddlewareField<ResolveLayoutMiddlewares<Layout>, "state"> : {};
@@ -51,7 +54,7 @@ type ResolveLayoutChainMiddlewares<Chain extends readonly LayoutId[]> = Chain ex
51
54
  infer Head extends LayoutId,
52
55
  ...infer Rest
53
56
  ] ? readonly [
54
- ...LayoutTree[Head]["middlewares"],
57
+ ...LayoutMiddlewares<Head>,
55
58
  ...ResolveLayoutChainMiddlewares<Rest extends readonly LayoutId[] ? Rest : readonly []>
56
59
  ] : readonly [];
57
60
  type RouteEntry<Path extends RoutePath, TMethod extends Method> = RouteByPathMethod[Path] extends {
@@ -156,9 +159,10 @@ export type MiddlewareChainContext<Layout extends LayoutId, Acc extends readonly
156
159
  headers: TaserHeaders;
157
160
  cookies: TaserCookieJar;
158
161
  }>;
159
- export type MiddlewareBuilder<Layout extends LayoutId, Acc extends readonly unknown[] = readonly [], TAppContext extends Record<string, unknown> = AppContext> = Acc & {
162
+ export type MiddlewareBuilder<Layout extends LayoutId, Acc extends readonly unknown[] = readonly [], TAppContext extends Record<string, unknown> = AppContext> = {
160
163
  readonly layout: Layout;
161
164
  readonly middlewares: readonly MiddlewareDefinition[];
165
+ readonly __acc?: Acc;
162
166
  readonly $Infer: {
163
167
  Context: MiddlewareChainContext<Layout, Acc, unknown, unknown, unknown, TAppContext>;
164
168
  };
@@ -176,11 +180,12 @@ export type MiddlewareBuilder<Layout extends LayoutId, Acc extends readonly unkn
176
180
  ]): MiddlewareBuilder<Layout, readonly [...Acc, TAcc], TAppContext>;
177
181
  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>;
178
182
  };
179
- export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], TReturns extends ReturnsMap = {}, TOutput = Response> = Acc & {
183
+ export type RouteExport<Path extends RoutePath, TMethod extends Method, Acc extends readonly unknown[], TReturns extends ReturnsMap = {}, TOutput = Response> = {
180
184
  readonly path: Path;
181
185
  readonly method: TMethod | "ANY" | "ALL";
182
186
  readonly methods?: readonly Method[];
183
187
  readonly middlewares: readonly MiddlewareDefinition[];
188
+ readonly __acc?: Acc;
184
189
  readonly returns?: TReturns;
185
190
  readonly bodyMode?: "json" | "form" | "urlencoded";
186
191
  handler: (ctx: unknown) => Awaitable<Response>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taserjs/router",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Type-safe Node.js router with runtime validation and middleware",
5
5
  "license": "ISC",
6
6
  "repository": {
@@ -147,8 +147,8 @@
147
147
  "dependencies": {
148
148
  "@standard-schema/spec": "^1.1.0",
149
149
  "hono": "^4.10.3",
150
- "@taserjs/router-utils": "0.1.5",
151
- "@taserjs/router-core": "0.1.5"
150
+ "@taserjs/router-core": "0.1.6",
151
+ "@taserjs/router-utils": "0.1.6"
152
152
  },
153
153
  "devDependencies": {
154
154
  "@tanstack/vite-config": "^0.6.0",
@@ -121,6 +121,14 @@ type LayoutParent<Layout extends LayoutId> = Layout extends keyof LayoutParentsM
121
121
  ? Parent
122
122
  : null;
123
123
 
124
+ type LayoutMiddlewares<Layout extends LayoutId> = LayoutTree[Layout]["middlewares"] extends {
125
+ readonly __acc?: infer Acc extends readonly unknown[];
126
+ }
127
+ ? Acc
128
+ : LayoutTree[Layout]["middlewares"] extends infer Acc extends readonly unknown[]
129
+ ? Acc
130
+ : readonly [];
131
+
124
132
  type ResolveLayoutMiddlewares<
125
133
  Layout extends LayoutId | null,
126
134
  Depth extends readonly unknown[] = [],
@@ -129,7 +137,7 @@ type ResolveLayoutMiddlewares<
129
137
  : Layout extends LayoutId
130
138
  ? readonly [
131
139
  ...ResolveLayoutMiddlewares<LayoutParent<Layout>, [...Depth, unknown]>,
132
- ...LayoutTree[Layout]["middlewares"],
140
+ ...LayoutMiddlewares<Layout>,
133
141
  ]
134
142
  : readonly [];
135
143
 
@@ -163,7 +171,7 @@ type ResolveLayoutChainMiddlewares<Chain extends readonly LayoutId[]> = Chain ex
163
171
  ...infer Rest,
164
172
  ]
165
173
  ? readonly [
166
- ...LayoutTree[Head]["middlewares"],
174
+ ...LayoutMiddlewares<Head>,
167
175
  ...ResolveLayoutChainMiddlewares<Rest extends readonly LayoutId[] ? Rest : readonly []>,
168
176
  ]
169
177
  : readonly [];
@@ -470,9 +478,10 @@ export type MiddlewareBuilder<
470
478
  Layout extends LayoutId,
471
479
  Acc extends readonly unknown[] = readonly [],
472
480
  TAppContext extends Record<string, unknown> = AppContext,
473
- > = Acc & {
481
+ > = {
474
482
  readonly layout: Layout;
475
483
  readonly middlewares: readonly MiddlewareDefinition[];
484
+ readonly __acc?: Acc;
476
485
  readonly $Infer: {
477
486
  Context: MiddlewareChainContext<Layout, Acc, unknown, unknown, unknown, TAppContext>;
478
487
  };
@@ -511,11 +520,12 @@ export type RouteExport<
511
520
  Acc extends readonly unknown[],
512
521
  TReturns extends ReturnsMap = {},
513
522
  TOutput = Response,
514
- > = Acc & {
523
+ > = {
515
524
  readonly path: Path;
516
525
  readonly method: TMethod | "ANY" | "ALL";
517
526
  readonly methods?: readonly Method[];
518
527
  readonly middlewares: readonly MiddlewareDefinition[];
528
+ readonly __acc?: Acc;
519
529
  readonly returns?: TReturns;
520
530
  readonly bodyMode?: "json" | "form" | "urlencoded";
521
531
  handler: (ctx: unknown) => Awaitable<Response>;