clear-router 2.1.2 → 2.1.4

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.
@@ -1,4 +1,4 @@
1
- import { d as RouteInfo, i as Route, l as ControllerAction, n as HttpContext, r as Middleware, t as Handler, u as HttpMethod } from "../express-C77arBZx.js";
1
+ import { d as RouteInfo, i as Route, l as ControllerAction, n as HttpContext, r as Middleware, t as Handler, u as HttpMethod } from "../express-sjYra4oE.cjs";
2
2
  import { Router as Router$1 } from "express";
3
3
 
4
4
  //#region src/express/router.d.ts
@@ -0,0 +1,133 @@
1
+ import { d as RouteInfo, i as Route, l as ControllerAction, n as HttpContext, r as Middleware, t as Handler, u as HttpMethod } from "../express-WiUTZlHA.mjs";
2
+ import { Router as Router$1 } from "express";
3
+
4
+ //#region src/express/router.d.ts
5
+ /**
6
+ * @class clear-router
7
+ * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
8
+ * @author Refkinscallv
9
+ * @author 3m1n3nc3
10
+ * @repository https://github.com/toneflix/clear-router
11
+ */
12
+ declare class Router {
13
+ /**
14
+ * All registered routes
15
+ */
16
+ static routes: Array<Route<HttpContext, Middleware>>;
17
+ /**
18
+ * Current route prefix
19
+ */
20
+ static prefix: string;
21
+ /**
22
+ * Group-level middlewares
23
+ */
24
+ static groupMiddlewares: Middleware[];
25
+ /**
26
+ * Global-level middlewares
27
+ */
28
+ static globalMiddlewares: Middleware[];
29
+ /**
30
+ * Normalize path by removing duplicate slashes and ensuring leading slash
31
+ * @param path - Path to normalize
32
+ * @returns Normalized path
33
+ */
34
+ static normalizePath(path: string): string;
35
+ /**
36
+ * Add a route with specified HTTP methods, path, handler, and middlewares
37
+ * @param methods - HTTP method(s) for the route
38
+ * @param path - Route path
39
+ * @param handler - Route handler function or controller reference
40
+ * @param middlewares - Array of middleware functions
41
+ */
42
+ static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[]): void;
43
+ /**
44
+ * Register RESTful API resource routes for a controller with optional action filtering
45
+ *
46
+ * @param basePath - Base path for the resource
47
+ * @param controller - Controller object containing action methods
48
+ * @param options - Optional filtering options for actions
49
+ */
50
+ static apiResource(basePath: string, controller: any, options?: {
51
+ only?: ControllerAction[];
52
+ except?: ControllerAction[];
53
+ }): void;
54
+ /**
55
+ * Register a GET route
56
+ * @param path - Route path
57
+ * @param handler - Route handler
58
+ * @param middlewares - Middleware functions
59
+ */
60
+ static get(path: string, handler: Handler, middlewares?: Middleware[]): void;
61
+ /**
62
+ * Register a POST route
63
+ * @param path - Route path
64
+ * @param handler - Route handler
65
+ * @param middlewares - Middleware functions
66
+ */
67
+ static post(path: string, handler: Handler, middlewares?: Middleware[]): void;
68
+ /**
69
+ * Register a PUT route
70
+ * @param path - Route path
71
+ * @param handler - Route handler
72
+ * @param middlewares - Middleware functions
73
+ */
74
+ static put(path: string, handler: Handler, middlewares?: Middleware[]): void;
75
+ /**
76
+ * Register a DELETE route
77
+ * @param path - Route path
78
+ * @param handler - Route handler
79
+ * @param middlewares - Middleware functions
80
+ */
81
+ static delete(path: string, handler: Handler, middlewares?: Middleware[]): void;
82
+ /**
83
+ * Register a PATCH route
84
+ * @param path - Route path
85
+ * @param handler - Route handler
86
+ * @param middlewares - Middleware functions
87
+ */
88
+ static patch(path: string, handler: Handler, middlewares?: Middleware[]): void;
89
+ /**
90
+ * Register an OPTIONS route
91
+ * @param path - Route path
92
+ * @param handler - Route handler
93
+ * @param middlewares - Middleware functions
94
+ */
95
+ static options(path: string, handler: Handler, middlewares?: Middleware[]): void;
96
+ /**
97
+ * Register a HEAD route
98
+ * @param path - Route path
99
+ * @param handler - Route handler
100
+ * @param middlewares - Middleware functions
101
+ */
102
+ static head(path: string, handler: Handler, middlewares?: Middleware[]): void;
103
+ /**
104
+ * Group routes with a common prefix and middlewares
105
+ * @param prefix - URL prefix for grouped routes
106
+ * @param callback - Function containing route definitions
107
+ * @param middlewares - Middleware functions applied to all routes in group
108
+ */
109
+ static group(prefix: string, callback: () => void, middlewares?: Middleware[]): void;
110
+ /**
111
+ * Apply global middlewares for the duration of the callback
112
+ * @param middlewares - Middleware functions
113
+ * @param callback - Function containing route definitions
114
+ */
115
+ static middleware(middlewares: Middleware[], callback: () => void): void;
116
+ /**
117
+ * Get all registered routes with their information
118
+ * @returns Array of route information objects
119
+ */
120
+ static allRoutes(): RouteInfo[];
121
+ /**
122
+ * Apply all registered routes to the provided Express Router instance
123
+ * Handles controller-method binding and middleware application
124
+ * All errors are thrown to Express error handling middleware
125
+ *
126
+ * @param router - Express Router instance
127
+ */
128
+ static apply(router: Router$1): void;
129
+ static apply(router: Router$1): Promise<void>;
130
+ private static bindRequestToInstance;
131
+ }
132
+ //#endregion
133
+ export { Router };
@@ -1,4 +1,4 @@
1
- import { a as H3App, c as Middleware, d as RouteInfo, i as Route, l as ControllerAction, o as Handler, s as HttpContext, u as HttpMethod } from "../express-C77arBZx.js";
1
+ import { a as H3App, c as Middleware, d as RouteInfo, i as Route, l as ControllerAction, o as Handler, s as HttpContext, u as HttpMethod } from "../express-sjYra4oE.cjs";
2
2
  import { H3 } from "h3";
3
3
 
4
4
  //#region src/h3/router.d.ts
@@ -0,0 +1,131 @@
1
+ import { a as H3App, c as Middleware, d as RouteInfo, i as Route, l as ControllerAction, o as Handler, s as HttpContext, u as HttpMethod } from "../express-WiUTZlHA.mjs";
2
+ import { H3 } from "h3";
3
+
4
+ //#region src/h3/router.d.ts
5
+ /**
6
+ * @class clear-router
7
+ * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
8
+ * @author 3m1n3nc3
9
+ * @repository https://github.com/toneflix/clear-router
10
+ */
11
+ declare class Router {
12
+ /**
13
+ * All registered routes
14
+ */
15
+ static routes: Array<Route<HttpContext, Middleware>>;
16
+ /**
17
+ * Current route prefix
18
+ */
19
+ static prefix: string;
20
+ /**
21
+ * Group-level middlewares
22
+ */
23
+ static groupMiddlewares: Middleware[];
24
+ /**
25
+ * Global-level middlewares
26
+ */
27
+ static globalMiddlewares: Middleware[];
28
+ /**
29
+ * Normalize path by removing duplicate slashes and ensuring leading slash
30
+ * @param path - Path to normalize
31
+ * @returns Normalized path
32
+ */
33
+ static normalizePath(path: string): string;
34
+ /**
35
+ * Add a route with specified HTTP methods, path, handler, and middlewares
36
+ * @param methods - HTTP method(s) for the route
37
+ * @param path - Route path
38
+ * @param handler - Route handler function or controller reference
39
+ * @param middlewares - Array of middleware functions
40
+ */
41
+ static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[]): void;
42
+ /**
43
+ * Register RESTful API resource routes for a controller with optional action filtering
44
+ *
45
+ * @param basePath - Base path for the resource
46
+ * @param controller - Controller object containing action methods
47
+ * @param options - Optional filtering options for actions
48
+ */
49
+ static apiResource(basePath: string, controller: any, options?: {
50
+ only?: ControllerAction[];
51
+ except?: ControllerAction[];
52
+ }): void;
53
+ /**
54
+ * Register a GET route
55
+ * @param path - Route path
56
+ * @param handler - Route handler
57
+ * @param middlewares - Middleware functions
58
+ */
59
+ static get(path: string, handler: Handler, middlewares?: Middleware[]): void;
60
+ /**
61
+ * Register a POST route
62
+ * @param path - Route path
63
+ * @param handler - Route handler
64
+ * @param middlewares - Middleware functions
65
+ */
66
+ static post(path: string, handler: Handler, middlewares?: Middleware[]): void;
67
+ /**
68
+ * Register a PUT route
69
+ * @param path - Route path
70
+ * @param handler - Route handler
71
+ * @param middlewares - Middleware functions
72
+ */
73
+ static put(path: string, handler: Handler, middlewares?: Middleware[]): void;
74
+ /**
75
+ * Register a DELETE route
76
+ * @param path - Route path
77
+ * @param handler - Route handler
78
+ * @param middlewares - Middleware functions
79
+ */
80
+ static delete(path: string, handler: Handler, middlewares?: Middleware[]): void;
81
+ /**
82
+ * Register a PATCH route
83
+ * @param path - Route path
84
+ * @param handler - Route handler
85
+ * @param middlewares - Middleware functions
86
+ */
87
+ static patch(path: string, handler: Handler, middlewares?: Middleware[]): void;
88
+ /**
89
+ * Register an OPTIONS route
90
+ * @param path - Route path
91
+ * @param handler - Route handler
92
+ * @param middlewares - Middleware functions
93
+ */
94
+ static options(path: string, handler: Handler, middlewares?: Middleware[]): void;
95
+ /**
96
+ * Register a HEAD route
97
+ * @param path - Route path
98
+ * @param handler - Route handler
99
+ * @param middlewares - Middleware functions
100
+ */
101
+ static head(path: string, handler: Handler, middlewares?: Middleware[]): void;
102
+ /**
103
+ * Group routes with a common prefix and middlewares
104
+ * @param prefix - URL prefix for grouped routes
105
+ * @param callback - Function containing route definitions
106
+ * @param middlewares - Middleware functions applied to all routes in group
107
+ */
108
+ static group(prefix: string, callback: () => void, middlewares?: Middleware[]): void;
109
+ /**
110
+ * Apply global middlewares for the duration of the callback
111
+ * @param middlewares - Middleware functions
112
+ * @param callback - Function containing route definitions
113
+ */
114
+ static middleware(middlewares: Middleware[], callback: () => void): void;
115
+ /**
116
+ * Get all registered routes with their information
117
+ * @returns Array of route information objects
118
+ */
119
+ static allRoutes(): RouteInfo[];
120
+ /**
121
+ * Apply all registered routes to the provided H3 Router instance
122
+ * Handles controller-method binding and middleware application
123
+ * All errors are thrown to H3 error handling middleware
124
+ *
125
+ * @param app - H3 app instance
126
+ */
127
+ static apply(app: H3): H3App;
128
+ private static bindRequestToInstance;
129
+ }
130
+ //#endregion
131
+ export { Router };
@@ -0,0 +1,91 @@
1
+ import { NextFunction, Request, Response as Response$1 } from "express";
2
+ import { H3Event, Middleware } from "h3";
3
+
4
+ //#region types/basic.d.ts
5
+ /**
6
+ * Controller method reference
7
+ */
8
+ type ControllerHandler = [any, string];
9
+ /**
10
+ * HTTP methods supported by the router
11
+ */
12
+ type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
13
+ /**
14
+ * Generic Object type for request data
15
+ */
16
+ type RequestData = Record<string, any>;
17
+ //#endregion
18
+ //#region types/express.d.ts
19
+ /**
20
+ * Middleware function type
21
+ */
22
+ type Middleware$1 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
23
+ //#endregion
24
+ //#region types/h3.d.ts
25
+ /**
26
+ * HTTP context passed to route handlers
27
+ */
28
+ type HttpContext = H3Event & {};
29
+ /**
30
+ * Route handler function type
31
+ */
32
+ type RouteHandler = (
33
+ /**
34
+ * H3 event context
35
+ */
36
+
37
+ ctx: HttpContext,
38
+ /**
39
+ * ClearRequest instance
40
+ */
41
+
42
+ req: ClearRequest) => any | Promise<any>;
43
+ /**
44
+ * Handler can be either a function or controller reference
45
+ */
46
+ type Handler = RouteHandler | ControllerHandler;
47
+ //#endregion
48
+ //#region src/Route.d.ts
49
+ declare class Route<X = any, M = Middleware | Middleware$1> {
50
+ ctx: X;
51
+ body: RequestData;
52
+ query: RequestData;
53
+ params: RequestData;
54
+ clearRequest: ClearRequest;
55
+ methods: HttpMethod[];
56
+ path: string;
57
+ handler: Handler;
58
+ middlewares: M[];
59
+ constructor(methods: HttpMethod[], path: string, handler: Handler, middlewares?: M[]);
60
+ }
61
+ //#endregion
62
+ //#region src/ClearRequest.d.ts
63
+ declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
64
+ [key: string]: any;
65
+ /**
66
+ * @param body - Parsed request body
67
+ */
68
+ body: RequestData;
69
+ /**
70
+ * @param query - Parsed query parameters
71
+ */
72
+ query: RequestData;
73
+ /**
74
+ * @param params - Parsed route parameters
75
+ */
76
+ params: RequestData;
77
+ route: Route<X, M>;
78
+ constructor(init?: Partial<ClearRequest>);
79
+ }
80
+ //#endregion
81
+ //#region src/Controller.d.ts
82
+ declare abstract class Controller<X = any> {
83
+ [x: string]: any;
84
+ ctx: X;
85
+ body: RequestData;
86
+ query: RequestData;
87
+ params: RequestData;
88
+ clearRequest: ClearRequest;
89
+ }
90
+ //#endregion
91
+ export { ClearRequest, Controller, Route };
@@ -0,0 +1,25 @@
1
+ import { RequestData } from "../types/basic.mjs";
2
+ import { Middleware } from "../types/h3.mjs";
3
+ import { Route } from "./Route.mjs";
4
+ import { Middleware as Middleware$1 } from "../types/express.mjs";
5
+
6
+ //#region src/ClearRequest.d.ts
7
+ declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
8
+ [key: string]: any;
9
+ /**
10
+ * @param body - Parsed request body
11
+ */
12
+ body: RequestData;
13
+ /**
14
+ * @param query - Parsed query parameters
15
+ */
16
+ query: RequestData;
17
+ /**
18
+ * @param params - Parsed route parameters
19
+ */
20
+ params: RequestData;
21
+ route: Route<X, M>;
22
+ constructor(init?: Partial<ClearRequest>);
23
+ }
24
+ //#endregion
25
+ export { ClearRequest };
@@ -0,0 +1,20 @@
1
+ import { HttpMethod, RequestData } from "../types/basic.mjs";
2
+ import { Handler, Middleware } from "../types/h3.mjs";
3
+ import { ClearRequest } from "./ClearRequest.mjs";
4
+ import { Middleware as Middleware$1 } from "../types/express.mjs";
5
+
6
+ //#region src/Route.d.ts
7
+ declare class Route<X = any, M = Middleware | Middleware$1> {
8
+ ctx: X;
9
+ body: RequestData;
10
+ query: RequestData;
11
+ params: RequestData;
12
+ clearRequest: ClearRequest;
13
+ methods: HttpMethod[];
14
+ path: string;
15
+ handler: Handler;
16
+ middlewares: M[];
17
+ constructor(methods: HttpMethod[], path: string, handler: Handler, middlewares?: M[]);
18
+ }
19
+ //#endregion
20
+ export { Route };
@@ -1,5 +1,5 @@
1
- import { ControllerHandler } from "./basic.js";
2
- import { ClearRequest } from "../src/ClearRequest.js";
1
+ import { ControllerHandler } from "./basic.mjs";
2
+ import { ClearRequest } from "./ClearRequest.mjs";
3
3
  import { NextFunction, Request, Response } from "express";
4
4
 
5
5
  //#region types/express.d.ts
@@ -1,5 +1,5 @@
1
- import { ControllerHandler } from "./basic.js";
2
- import { ClearRequest } from "../src/ClearRequest.js";
1
+ import { ControllerHandler } from "./basic.mjs";
2
+ import { ClearRequest } from "./ClearRequest.mjs";
3
3
  import { H3, H3Event, Middleware, TypedServerRequest } from "h3";
4
4
 
5
5
  //#region types/h3.d.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-router",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Laravel-style routing system for Express.js and H3, with CommonJS, ESM, and TypeScript support",
5
5
  "keywords": [
6
6
  "h3",
@@ -30,7 +30,7 @@
30
30
  "type": "module",
31
31
  "main": "./dist/index.cjs",
32
32
  "module": "./dist/index.mjs",
33
- "types": "./dist/index.d.ts",
33
+ "types": "./dist/index.d.cts",
34
34
  "exports": {
35
35
  ".": {
36
36
  "import": "./dist/index.mjs",
File without changes
File without changes