@taserjs/router 0.1.9 → 0.1.11

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 (52) hide show
  1. package/LICENSE +1 -1
  2. package/dist/cjs/builder/middleware-unit.cjs +50 -50
  3. package/dist/cjs/builder/middleware-unit.cjs.map +1 -1
  4. package/dist/cjs/builder/middleware-unit.d.cts +34 -1
  5. package/dist/cjs/builder/middleware.cjs +13 -12
  6. package/dist/cjs/builder/middleware.cjs.map +1 -1
  7. package/dist/cjs/builder/normalize.cjs +10 -0
  8. package/dist/cjs/builder/normalize.cjs.map +1 -0
  9. package/dist/cjs/builder/normalize.d.cts +2 -0
  10. package/dist/cjs/builder/route.cjs +63 -67
  11. package/dist/cjs/builder/route.cjs.map +1 -1
  12. package/dist/cjs/builder/standalone.cjs +18 -34
  13. package/dist/cjs/builder/standalone.cjs.map +1 -1
  14. package/dist/cjs/builder/standalone.d.cts +7 -14
  15. package/dist/cjs/index.cjs +0 -11
  16. package/dist/cjs/index.d.cts +2 -2
  17. package/dist/cjs/middleware/hono-mw.cjs +1 -1
  18. package/dist/cjs/middleware/hono-mw.cjs.map +1 -1
  19. package/dist/cjs/middleware/hono-mw.d.cts +1 -1
  20. package/dist/esm/builder/middleware-unit.d.ts +34 -1
  21. package/dist/esm/builder/middleware-unit.js +50 -50
  22. package/dist/esm/builder/middleware-unit.js.map +1 -1
  23. package/dist/esm/builder/middleware.js +13 -12
  24. package/dist/esm/builder/middleware.js.map +1 -1
  25. package/dist/esm/builder/normalize.d.ts +2 -0
  26. package/dist/esm/builder/normalize.js +10 -0
  27. package/dist/esm/builder/normalize.js.map +1 -0
  28. package/dist/esm/builder/route.js +63 -67
  29. package/dist/esm/builder/route.js.map +1 -1
  30. package/dist/esm/builder/standalone.d.ts +7 -14
  31. package/dist/esm/builder/standalone.js +19 -24
  32. package/dist/esm/builder/standalone.js.map +1 -1
  33. package/dist/esm/index.d.ts +2 -2
  34. package/dist/esm/index.js +2 -2
  35. package/dist/esm/middleware/hono-mw.d.ts +1 -1
  36. package/dist/esm/middleware/hono-mw.js +1 -1
  37. package/dist/esm/middleware/hono-mw.js.map +1 -1
  38. package/package.json +3 -3
  39. package/src/builder/middleware-unit.ts +56 -51
  40. package/src/builder/middleware.ts +16 -18
  41. package/src/builder/normalize.ts +13 -0
  42. package/src/builder/route.ts +81 -82
  43. package/src/builder/standalone.ts +56 -52
  44. package/src/index.ts +2 -17
  45. package/src/middleware/hono-mw.ts +1 -1
  46. package/dist/cjs/builder/factories.cjs +0 -31
  47. package/dist/cjs/builder/factories.cjs.map +0 -1
  48. package/dist/cjs/builder/factories.d.cts +0 -16
  49. package/dist/esm/builder/factories.d.ts +0 -16
  50. package/dist/esm/builder/factories.js +0 -22
  51. package/dist/esm/builder/factories.js.map +0 -1
  52. package/src/builder/factories.ts +0 -59
@@ -4,63 +4,68 @@ import type { ReturnsMap } from "../types/returns.js";
4
4
  import type { Schema } from "../types/schema.js";
5
5
  import { pickDefinedSchemas, type SchemaValidators } from "../define/validators.js";
6
6
 
7
- export function createMiddlewareUnitBuilder(requiredLayouts?: string | readonly string[]) {
8
- const validators: SchemaValidators = {};
9
- let bodyMode: BodyMode | undefined;
10
- let returnsMap: ReturnsMap | undefined;
7
+ class MiddlewareUnitBuilderImpl {
8
+ private readonly validators: SchemaValidators = {};
9
+ private bodyMode: BodyMode | undefined;
10
+ private returnsMap: ReturnsMap | undefined;
11
+ readonly __requiredLayouts: string | readonly string[] | undefined;
12
+ readonly __middlewareAcc: unknown = undefined;
13
+
14
+ constructor(requiredLayouts?: string | readonly string[]) {
15
+ this.__requiredLayouts = requiredLayouts;
16
+ }
17
+
18
+ query(schema: Schema<unknown>): this {
19
+ this.validators.query = schema;
20
+ return this;
21
+ }
22
+
23
+ params(schema: Schema<unknown>): this {
24
+ this.validators.params = schema;
25
+ return this;
26
+ }
27
+
28
+ body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>): this {
29
+ if (typeof modeOrSchema === "string") {
30
+ this.bodyMode = modeOrSchema as BodyMode;
31
+ if (schema !== undefined) {
32
+ this.validators.body = schema;
33
+ }
34
+ } else {
35
+ this.bodyMode = "json";
36
+ this.validators.body = modeOrSchema;
37
+ }
38
+ return this;
39
+ }
40
+
41
+ returns(map: ReturnsMap): this {
42
+ this.returnsMap = this.returnsMap ? { ...this.returnsMap, ...map } : { ...map };
43
+ return this;
44
+ }
45
+
46
+ requires(): this {
47
+ return this;
48
+ }
11
49
 
12
- function toUnit(fn?: (ctx: any, next: any) => any) {
13
- const schemas = pickDefinedSchemas(validators);
50
+ handler(fn: (ctx: any, next: any) => any) {
51
+ return this.toUnit(fn);
52
+ }
53
+
54
+ toUnit(fn?: (ctx: any, next: any) => any) {
55
+ const schemas = pickDefinedSchemas(this.validators);
14
56
  return {
15
57
  ...(fn ? { handler: fn } : {}),
16
58
  ...schemas,
17
- ...(bodyMode ? { bodyMode } : {}),
18
- ...(returnsMap ? { returns: returnsMap, __returns: returnsMap } : {}),
19
- ...(requiredLayouts !== undefined ? { __requiredLayouts: requiredLayouts } : {}),
59
+ ...(this.bodyMode ? { bodyMode: this.bodyMode } : {}),
60
+ ...(this.returnsMap ? { returns: this.returnsMap, __returns: this.returnsMap } : {}),
61
+ ...(this.__requiredLayouts !== undefined
62
+ ? { __requiredLayouts: this.__requiredLayouts }
63
+ : {}),
20
64
  __middlewareAcc: undefined as unknown,
21
65
  };
22
66
  }
67
+ }
23
68
 
24
- const builder: any = {
25
- query(schema: Schema<unknown>) {
26
- validators.query = schema;
27
- return builder;
28
- },
29
- params(schema: Schema<unknown>) {
30
- validators.params = schema;
31
- return builder;
32
- },
33
- body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>) {
34
- if (typeof modeOrSchema === "string") {
35
- bodyMode = modeOrSchema as BodyMode;
36
- if (schema !== undefined) {
37
- validators.body = schema;
38
- }
39
- } else {
40
- bodyMode = "json";
41
- validators.body = modeOrSchema;
42
- }
43
- return builder;
44
- },
45
- returns(map: ReturnsMap) {
46
- returnsMap = { ...returnsMap, ...map };
47
- return builder;
48
- },
49
- requires() {
50
- return builder;
51
- },
52
- handler(fn: (ctx: any, next: any) => any) {
53
- return toUnit(fn);
54
- },
55
- toUnit() {
56
- return toUnit();
57
- },
58
- __middlewareAcc: undefined as unknown,
59
- };
60
-
61
- if (requiredLayouts !== undefined) {
62
- builder.__requiredLayouts = requiredLayouts;
63
- }
64
-
65
- return builder;
69
+ export function createMiddlewareUnitBuilder(requiredLayouts?: string | readonly string[]) {
70
+ return new MiddlewareUnitBuilderImpl(requiredLayouts);
66
71
  }
@@ -1,25 +1,23 @@
1
1
  import type { LayoutId, MiddlewareBuilder } from "../types/index.js";
2
2
  import type { MiddlewareDefinition } from "../types/units.js";
3
+ import { normalizeMiddlewareDefinition } from "./normalize.js";
4
+
5
+ class MiddlewareBuilderImpl<Layout extends LayoutId> {
6
+ readonly layout: Layout;
7
+ readonly middlewares: MiddlewareDefinition[] = [];
8
+
9
+ constructor(layout: Layout) {
10
+ this.layout = layout;
11
+ }
12
+
13
+ use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)): this {
14
+ this.middlewares.push(normalizeMiddlewareDefinition(definition));
15
+ return this;
16
+ }
17
+ }
3
18
 
4
19
  export function createMiddleware<const Layout extends LayoutId>(
5
20
  layout: Layout,
6
21
  ): MiddlewareBuilder<Layout, readonly []> {
7
- const entries: MiddlewareDefinition[] = [];
8
-
9
- const chain = {
10
- layout,
11
- middlewares: entries,
12
- use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)) {
13
- if (typeof definition === "function") {
14
- entries.push({ handler: definition as any });
15
- } else if (typeof (definition as any)?.toUnit === "function") {
16
- entries.push((definition as any).toUnit());
17
- } else {
18
- entries.push(definition);
19
- }
20
- return chain;
21
- },
22
- };
23
-
24
- return chain as unknown as MiddlewareBuilder<Layout, readonly []>;
22
+ return new MiddlewareBuilderImpl(layout) as unknown as MiddlewareBuilder<Layout, readonly []>;
25
23
  }
@@ -0,0 +1,13 @@
1
+ import type { MiddlewareDefinition } from "../types/units.js";
2
+
3
+ export function normalizeMiddlewareDefinition(
4
+ definition: MiddlewareDefinition | ((ctx: any, next: any) => any),
5
+ ): MiddlewareDefinition {
6
+ if (typeof definition === "function") {
7
+ return { handler: definition as any };
8
+ }
9
+ if (typeof (definition as any)?.toUnit === "function") {
10
+ return (definition as any).toUnit();
11
+ }
12
+ return definition;
13
+ }
@@ -17,21 +17,9 @@ import type {
17
17
  } from "../types/index.js";
18
18
  import type { HttpMethod, MiddlewareDefinition } from "../types/units.js";
19
19
  import { pickDefinedSchemas, type SchemaValidators } from "../define/validators.js";
20
+ import { normalizeMiddlewareDefinition } from "./normalize.js";
20
21
 
21
- function toUtilsMap(map: ReturnsMap | undefined): Record<number, StandardSchemaV1> {
22
- if (!map) {
23
- return {};
24
- }
25
- const out: Record<number, StandardSchemaV1> = {};
26
- for (const [key, schema] of Object.entries(map)) {
27
- if (schema !== undefined) {
28
- out[Number(key)] = schema;
29
- }
30
- }
31
- return out;
32
- }
33
-
34
- function buildEffectiveReturns(args: {
22
+ function buildRouteReturnsWith422(args: {
35
23
  middlewareReturns: ReturnsMap;
36
24
  routeReturns: ReturnsMap;
37
25
  schemas: {
@@ -42,8 +30,8 @@ function buildEffectiveReturns(args: {
42
30
  };
43
31
  }): Record<number, StandardSchemaV1> | undefined {
44
32
  const merged = mergeReturnsMaps(
45
- toUtilsMap(args.middlewareReturns),
46
- toUtilsMap(args.routeReturns),
33
+ args.middlewareReturns as Record<number, StandardSchemaV1>,
34
+ args.routeReturns as Record<number, StandardSchemaV1>,
47
35
  );
48
36
  const with422 = withAuto422(merged, hasInputSchemas(args.schemas));
49
37
  return Object.keys(with422).length > 0 ? with422 : undefined;
@@ -63,76 +51,87 @@ function buildRouteBase(
63
51
  };
64
52
  }
65
53
 
54
+ class RouteBuilderImpl {
55
+ readonly path: string;
56
+ readonly method: HttpMethod | "ANY" | "ALL";
57
+ readonly methods: readonly HttpMethod[] | undefined;
58
+ private readonly middlewares: MiddlewareDefinition[] = [];
59
+ private readonly routeReturns: Record<number, StandardSchemaV1> = {};
60
+ private readonly validators: SchemaValidators = {};
61
+ private bodyMode: BodyMode | undefined;
62
+
63
+ constructor(path: string, method: HttpMethod | "ANY" | "ALL", methods?: readonly HttpMethod[]) {
64
+ this.path = path;
65
+ this.method = method;
66
+ this.methods = methods;
67
+ }
68
+
69
+ query(schema: Schema<unknown>): this {
70
+ this.validators.query = schema;
71
+ return this;
72
+ }
73
+
74
+ params(schema: Schema<unknown>): this {
75
+ this.validators.params = schema;
76
+ return this;
77
+ }
78
+
79
+ body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>): this {
80
+ if (typeof modeOrSchema === "string") {
81
+ this.bodyMode = modeOrSchema as BodyMode;
82
+ if (schema !== undefined) {
83
+ this.validators.body = schema;
84
+ }
85
+ } else {
86
+ this.bodyMode = "json";
87
+ this.validators.body = modeOrSchema;
88
+ }
89
+ return this;
90
+ }
91
+
92
+ returns(map: ReturnsMap): this {
93
+ Object.assign(this.routeReturns, map);
94
+ return this;
95
+ }
96
+
97
+ use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)): this {
98
+ this.middlewares.push(normalizeMiddlewareDefinition(definition));
99
+ return this;
100
+ }
101
+
102
+ handler(fn: (ctx: unknown) => Response | Promise<Response>) {
103
+ const routeSchemas = pickDefinedSchemas(this.validators);
104
+ const base = buildRouteBase(this.path, this.method, this.methods, this.middlewares);
105
+
106
+ const returns = buildRouteReturnsWith422({
107
+ middlewareReturns: collectReturnsFromDefinitions(this.middlewares),
108
+ routeReturns: this.routeReturns,
109
+ schemas: {
110
+ ...this.validators,
111
+ middlewares: this.middlewares,
112
+ },
113
+ });
114
+
115
+ return {
116
+ ...base,
117
+ handler: fn,
118
+ ...routeSchemas,
119
+ ...(this.bodyMode ? { bodyMode: this.bodyMode } : {}),
120
+ ...(returns ? { returns } : {}),
121
+ };
122
+ }
123
+ }
124
+
66
125
  /** Shared internal builder — not part of the public `@taserjs/router` API. */
67
126
  export function createRouteBuilder(
68
127
  path: string,
69
128
  method: HttpMethod | "ANY" | "ALL",
70
129
  methods?: readonly HttpMethod[],
71
130
  ): RouteBuilder<RoutePath, Method, readonly [], ValidatorParts> {
72
- const middlewares: MiddlewareDefinition[] = [];
73
- let routeReturns: Record<number, StandardSchemaV1> = {};
74
- const validators: SchemaValidators = {};
75
- let bodyMode: BodyMode | undefined;
76
-
77
- const builder = {
78
- path,
79
- method,
80
- query(schema: Schema<unknown>) {
81
- validators.query = schema;
82
- return builder;
83
- },
84
- params(schema: Schema<unknown>) {
85
- validators.params = schema;
86
- return builder;
87
- },
88
- body(modeOrSchema: BodyMode | Schema<unknown>, schema?: Schema<unknown>) {
89
- if (typeof modeOrSchema === "string") {
90
- bodyMode = modeOrSchema as BodyMode;
91
- if (schema !== undefined) {
92
- validators.body = schema;
93
- }
94
- } else {
95
- bodyMode = "json";
96
- validators.body = modeOrSchema;
97
- }
98
- return builder;
99
- },
100
- returns(map: ReturnsMap) {
101
- routeReturns = { ...routeReturns, ...toUtilsMap(map) };
102
- return builder;
103
- },
104
- use(definition: MiddlewareDefinition | ((ctx: any, next: any) => any)) {
105
- if (typeof definition === "function") {
106
- middlewares.push({ handler: definition as any });
107
- } else if (typeof (definition as any)?.toUnit === "function") {
108
- middlewares.push((definition as any).toUnit());
109
- } else {
110
- middlewares.push(definition);
111
- }
112
- return builder;
113
- },
114
- handler(fn: (ctx: unknown) => Response | Promise<Response>) {
115
- const routeSchemas = pickDefinedSchemas(validators);
116
- const base = buildRouteBase(path, method, methods, middlewares);
117
-
118
- const returns = buildEffectiveReturns({
119
- middlewareReturns: collectReturnsFromDefinitions(middlewares),
120
- routeReturns,
121
- schemas: {
122
- ...validators,
123
- middlewares,
124
- },
125
- });
126
-
127
- return {
128
- ...base,
129
- handler: fn,
130
- ...routeSchemas,
131
- ...(bodyMode ? { bodyMode } : {}),
132
- ...(returns ? { returns } : {}),
133
- };
134
- },
135
- };
136
-
137
- return builder as unknown as RouteBuilder<RoutePath, Method, readonly [], ValidatorParts>;
131
+ return new RouteBuilderImpl(path, method, methods) as unknown as RouteBuilder<
132
+ RoutePath,
133
+ Method,
134
+ readonly [],
135
+ ValidatorParts
136
+ >;
138
137
  }
@@ -1,48 +1,49 @@
1
- import type { AppContext, LayoutBuilder } from "../types/index.js";
2
- import {
3
- createAllRoute,
4
- createAnyRoute,
5
- createDeleteRoute,
6
- createGetRoute,
7
- createHeadRoute,
8
- createOptionsRoute,
9
- createPatchRoute,
10
- createPostRoute,
11
- createPutRoute,
12
- createQueryRoute,
13
- type CreateAllRoute,
14
- type CreateAnyRoute,
15
- type CreateWithBodyRoute,
16
- type CreateWithoutBodyRoute,
17
- } from "./factories.js";
1
+ import type { AppContext, LayoutBuilder, RouteBuilder, RoutePath } from "../types/index.js";
2
+ import type { HttpMethod } from "../types/units.js";
3
+ import { createRouteBuilder } from "./route.js";
18
4
  import { createMiddleware } from "./middleware.js";
19
5
  import { middleware as createMiddlewareFn, type MiddlewareFn } from "../define/middleware.js";
20
6
 
21
- export const get: CreateWithoutBodyRoute<"GET", AppContext> =
22
- createGetRoute as CreateWithoutBodyRoute<"GET", AppContext>;
23
- export const post: CreateWithBodyRoute<"POST", AppContext> = createPostRoute as CreateWithBodyRoute<
24
- "POST",
25
- AppContext
26
- >;
27
- export const put: CreateWithBodyRoute<"PUT", AppContext> = createPutRoute as CreateWithBodyRoute<
28
- "PUT",
29
- AppContext
30
- >;
31
- export const patch: CreateWithBodyRoute<"PATCH", AppContext> =
32
- createPatchRoute as CreateWithBodyRoute<"PATCH", AppContext>;
33
- export const del: CreateWithoutBodyRoute<"DELETE", AppContext> =
34
- createDeleteRoute as CreateWithoutBodyRoute<"DELETE", AppContext>;
35
- export const options: CreateWithoutBodyRoute<"OPTIONS", AppContext> =
36
- createOptionsRoute as CreateWithoutBodyRoute<"OPTIONS", AppContext>;
37
- export const head: CreateWithoutBodyRoute<"HEAD", AppContext> =
38
- createHeadRoute as CreateWithoutBodyRoute<"HEAD", AppContext>;
39
- export const query: CreateWithBodyRoute<"QUERY", AppContext> =
40
- createQueryRoute as CreateWithBodyRoute<"QUERY", AppContext>;
41
- export const any: CreateAnyRoute<AppContext> = createAnyRoute as CreateAnyRoute<AppContext>;
42
- export const all: CreateAllRoute<AppContext> = createAllRoute as CreateAllRoute<AppContext>;
7
+ export type CreateWithoutBodyRoute<
8
+ M extends "GET" | "DELETE" | "OPTIONS" | "HEAD",
9
+ TAppContext extends Record<string, unknown> = AppContext,
10
+ > = <const Path extends RoutePath>(
11
+ path: Path,
12
+ ) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
43
13
 
44
- export const layout: LayoutBuilder<AppContext> = createMiddleware as LayoutBuilder<AppContext>;
45
- export const middleware: MiddlewareFn<AppContext> = createMiddlewareFn as MiddlewareFn<AppContext>;
14
+ export type CreateWithBodyRoute<
15
+ M extends "POST" | "PUT" | "PATCH" | "QUERY",
16
+ TAppContext extends Record<string, unknown> = AppContext,
17
+ > = <const Path extends RoutePath>(
18
+ path: Path,
19
+ ) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
20
+
21
+ export type CreateAnyRoute<TAppContext extends Record<string, unknown> = AppContext> = <
22
+ const Path extends RoutePath,
23
+ const Methods extends readonly HttpMethod[],
24
+ >(
25
+ path: Path,
26
+ methods: Methods,
27
+ ) => RouteBuilder<Path, Methods[number], readonly [], {}, {}, TAppContext>;
28
+
29
+ export type CreateAllRoute<TAppContext extends Record<string, unknown> = AppContext> = <
30
+ const Path extends RoutePath,
31
+ >(
32
+ path: Path,
33
+ ) => RouteBuilder<Path, HttpMethod, readonly [], {}, {}, TAppContext>;
34
+
35
+ function createWithoutBodyRoute<M extends "GET" | "DELETE" | "OPTIONS" | "HEAD">(
36
+ method: M,
37
+ ): CreateWithoutBodyRoute<M> {
38
+ return ((path: string) =>
39
+ createRouteBuilder(path, method)) as unknown as CreateWithoutBodyRoute<M>;
40
+ }
41
+
42
+ function createWithBodyRoute<M extends "POST" | "PUT" | "PATCH" | "QUERY">(
43
+ method: M,
44
+ ): CreateWithBodyRoute<M> {
45
+ return ((path: string) => createRouteBuilder(path, method)) as unknown as CreateWithBodyRoute<M>;
46
+ }
46
47
 
47
48
  export type TaserNamespace<TAppContext extends Record<string, unknown> = AppContext> = {
48
49
  readonly get: CreateWithoutBodyRoute<"GET", TAppContext>;
@@ -59,17 +60,20 @@ export type TaserNamespace<TAppContext extends Record<string, unknown> = AppCont
59
60
  readonly middleware: MiddlewareFn<TAppContext>;
60
61
  };
61
62
 
63
+ export const middleware: MiddlewareFn<AppContext> = createMiddlewareFn as MiddlewareFn<AppContext>;
64
+
62
65
  export const t: TaserNamespace<AppContext> = {
63
- get,
64
- post,
65
- put,
66
- patch,
67
- delete: del,
68
- options,
69
- head,
70
- query,
71
- any,
72
- all,
73
- layout,
66
+ get: createWithoutBodyRoute("GET"),
67
+ post: createWithBodyRoute("POST"),
68
+ put: createWithBodyRoute("PUT"),
69
+ patch: createWithBodyRoute("PATCH"),
70
+ delete: createWithoutBodyRoute("DELETE"),
71
+ options: createWithoutBodyRoute("OPTIONS"),
72
+ head: createWithoutBodyRoute("HEAD"),
73
+ query: createWithBodyRoute("QUERY"),
74
+ any: ((path: string, methods: readonly HttpMethod[]) =>
75
+ createRouteBuilder(path, "ANY", methods)) as unknown as CreateAnyRoute<AppContext>,
76
+ all: ((path: string) => createRouteBuilder(path, "ALL")) as unknown as CreateAllRoute<AppContext>,
77
+ layout: createMiddleware as LayoutBuilder<AppContext>,
74
78
  middleware,
75
79
  };
package/src/index.ts CHANGED
@@ -43,22 +43,7 @@ export type {
43
43
  export { ValidationError, validationErrorSchema } from "@taserjs/router-utils";
44
44
  export type { ResponseValidationFailureHandler, SuccessStatusCode } from "@taserjs/router-utils";
45
45
 
46
- export {
47
- all,
48
- any,
49
- del,
50
- get,
51
- head,
52
- layout,
53
- middleware,
54
- options,
55
- patch,
56
- post,
57
- put,
58
- query,
59
- t,
60
- type TaserNamespace,
61
- } from "./builder/standalone.js";
46
+ export { middleware, t, type TaserNamespace } from "./builder/standalone.js";
62
47
 
63
48
  export { createTaserApp, TaserRouter } from "./builder/router.js";
64
49
  export { TaserApp } from "./builder/app.js";
@@ -66,4 +51,4 @@ export { createContext } from "./context/create-context.js";
66
51
  export { honoMw } from "./middleware/hono-mw.js";
67
52
  export type { MiddlewareFn } from "./define/middleware.js";
68
53
 
69
- export type { TaserCookieJar, TaserHeaders } from "@taserjs/router-core";
54
+ export type { TaserCookieJar, TaserCookieOptions, TaserHeaders } from "@taserjs/router-core";
@@ -5,7 +5,7 @@ import type { NextFn } from "../types/units.js";
5
5
 
6
6
  /**
7
7
  * Adapts a standard Web / Hono-compatible middleware function `(c, next) => ...`
8
- * into a Taser-compatible middleware handler function `(ctx, next) => Promise<Response>`.
8
+ * into a Taser.js-compatible middleware handler function `(ctx, next) => Promise<Response>`.
9
9
  *
10
10
  * @example
11
11
  * ```ts
@@ -1,31 +0,0 @@
1
- const require_route = require("./route.cjs");
2
- //#region src/builder/factories.ts
3
- function createWithoutBodyRoute(method) {
4
- return ((path) => require_route.createRouteBuilder(path, method));
5
- }
6
- function createWithBodyRoute(method) {
7
- return ((path) => require_route.createRouteBuilder(path, method));
8
- }
9
- var createGetRoute = createWithoutBodyRoute("GET");
10
- var createDeleteRoute = createWithoutBodyRoute("DELETE");
11
- var createOptionsRoute = createWithoutBodyRoute("OPTIONS");
12
- var createHeadRoute = createWithoutBodyRoute("HEAD");
13
- var createPostRoute = createWithBodyRoute("POST");
14
- var createPutRoute = createWithBodyRoute("PUT");
15
- var createPatchRoute = createWithBodyRoute("PATCH");
16
- var createQueryRoute = createWithBodyRoute("QUERY");
17
- var createAnyRoute = ((path, methods) => require_route.createRouteBuilder(path, "ANY", methods));
18
- var createAllRoute = ((path) => require_route.createRouteBuilder(path, "ALL"));
19
- //#endregion
20
- exports.createAllRoute = createAllRoute;
21
- exports.createAnyRoute = createAnyRoute;
22
- exports.createDeleteRoute = createDeleteRoute;
23
- exports.createGetRoute = createGetRoute;
24
- exports.createHeadRoute = createHeadRoute;
25
- exports.createOptionsRoute = createOptionsRoute;
26
- exports.createPatchRoute = createPatchRoute;
27
- exports.createPostRoute = createPostRoute;
28
- exports.createPutRoute = createPutRoute;
29
- exports.createQueryRoute = createQueryRoute;
30
-
31
- //# sourceMappingURL=factories.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"factories.cjs","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\" | \"QUERY\",\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\" | \"QUERY\">(\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\");\nexport const createQueryRoute = createWithBodyRoute(\"QUERY\");\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,cAAA,mBAAmB,MAAM,MAAM;AACnC;AAEA,SAAS,oBACP,QACwB;CACxB,SAAS,SAAiB,cAAA,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;AAC3D,IAAa,mBAAmB,oBAAoB,OAAO;AAE3D,IAAa,mBAAmC,MAAc,YAC5D,cAAA,mBAAmB,MAAM,OAAO,OAAO;AAEzC,IAAa,mBAAmC,SAC9C,cAAA,mBAAmB,MAAM,KAAK"}
@@ -1,16 +0,0 @@
1
- import { AppContext, RouteBuilder, RoutePath } from '../types/index.js';
2
- import { HttpMethod } from '../types/units.js';
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
- export type CreateWithBodyRoute<M extends "POST" | "PUT" | "PATCH" | "QUERY", TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath>(path: Path) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
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
- 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", import('../types/units.js').EmptyAppContext>;
8
- export declare const createDeleteRoute: CreateWithoutBodyRoute<"DELETE", import('../types/units.js').EmptyAppContext>;
9
- export declare const createOptionsRoute: CreateWithoutBodyRoute<"OPTIONS", import('../types/units.js').EmptyAppContext>;
10
- export declare const createHeadRoute: CreateWithoutBodyRoute<"HEAD", import('../types/units.js').EmptyAppContext>;
11
- export declare const createPostRoute: CreateWithBodyRoute<"POST", import('../types/units.js').EmptyAppContext>;
12
- export declare const createPutRoute: CreateWithBodyRoute<"PUT", import('../types/units.js').EmptyAppContext>;
13
- export declare const createPatchRoute: CreateWithBodyRoute<"PATCH", import('../types/units.js').EmptyAppContext>;
14
- export declare const createQueryRoute: CreateWithBodyRoute<"QUERY", import('../types/units.js').EmptyAppContext>;
15
- export declare const createAnyRoute: CreateAnyRoute;
16
- export declare const createAllRoute: CreateAllRoute;
@@ -1,16 +0,0 @@
1
- import { AppContext, RouteBuilder, RoutePath } from '../types/index.js';
2
- import { HttpMethod } from '../types/units.js';
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
- export type CreateWithBodyRoute<M extends "POST" | "PUT" | "PATCH" | "QUERY", TAppContext extends Record<string, unknown> = AppContext> = <const Path extends RoutePath>(path: Path) => RouteBuilder<Path, M, readonly [], {}, {}, TAppContext>;
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
- 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", 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
- export declare const createQueryRoute: CreateWithBodyRoute<"QUERY", import('../index.js').EmptyAppContext>;
15
- export declare const createAnyRoute: CreateAnyRoute;
16
- export declare const createAllRoute: CreateAllRoute;
@@ -1,22 +0,0 @@
1
- import { createRouteBuilder } from "./route.js";
2
- //#region src/builder/factories.ts
3
- function createWithoutBodyRoute(method) {
4
- return ((path) => createRouteBuilder(path, method));
5
- }
6
- function createWithBodyRoute(method) {
7
- return ((path) => createRouteBuilder(path, method));
8
- }
9
- var createGetRoute = createWithoutBodyRoute("GET");
10
- var createDeleteRoute = createWithoutBodyRoute("DELETE");
11
- var createOptionsRoute = createWithoutBodyRoute("OPTIONS");
12
- var createHeadRoute = createWithoutBodyRoute("HEAD");
13
- var createPostRoute = createWithBodyRoute("POST");
14
- var createPutRoute = createWithBodyRoute("PUT");
15
- var createPatchRoute = createWithBodyRoute("PATCH");
16
- var createQueryRoute = createWithBodyRoute("QUERY");
17
- var createAnyRoute = ((path, methods) => createRouteBuilder(path, "ANY", methods));
18
- var createAllRoute = ((path) => createRouteBuilder(path, "ALL"));
19
- //#endregion
20
- export { createAllRoute, createAnyRoute, createDeleteRoute, createGetRoute, createHeadRoute, createOptionsRoute, createPatchRoute, createPostRoute, createPutRoute, createQueryRoute };
21
-
22
- //# sourceMappingURL=factories.js.map
@@ -1 +0,0 @@
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\" | \"QUERY\",\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\" | \"QUERY\">(\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\");\nexport const createQueryRoute = createWithBodyRoute(\"QUERY\");\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;AAC3D,IAAa,mBAAmB,oBAAoB,OAAO;AAE3D,IAAa,mBAAmC,MAAc,YAC5D,mBAAmB,MAAM,OAAO,OAAO;AAEzC,IAAa,mBAAmC,SAC9C,mBAAmB,MAAM,KAAK"}