clear-router 2.0.3 → 2.0.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.
package/README.md CHANGED
@@ -1,11 +1,23 @@
1
- # @refkinscallv/express-routing
1
+ # Toneflix Clear Router
2
2
 
3
3
  Laravel-style routing system for Express.js in JavaScript. Clean route definitions, middleware support, and controller bindings with full TypeScript support.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @refkinscallv/express-routing
8
+ npm install clear-router
9
+ ```
10
+
11
+ OR
12
+
13
+ ```bash
14
+ pnpm add clear-router
15
+ ```
16
+
17
+ OR
18
+
19
+ ```bash
20
+ yarn add clear-router
9
21
  ```
10
22
 
11
23
  ## Features
@@ -27,16 +39,16 @@ npm install @refkinscallv/express-routing
27
39
 
28
40
  ```javascript
29
41
  const express = require('express');
30
- const Routes = require('@refkinscallv/express-routing');
42
+ const Routes = require('clear-router');
31
43
 
32
44
  const app = express();
33
45
  const router = express.Router();
34
46
 
35
- Routes.get('/hello', ({ res }) => {
47
+ Router.get('/hello', ({ res }) => {
36
48
  res.send('Hello World');
37
49
  });
38
50
 
39
- Routes.apply(router);
51
+ Router.apply(router);
40
52
  app.use(router);
41
53
 
42
54
  app.listen(3000);
@@ -46,16 +58,16 @@ app.listen(3000);
46
58
 
47
59
  ```javascript
48
60
  import express from 'express';
49
- import Routes from '@refkinscallv/express-routing';
61
+ import Router from 'clear-router';
50
62
 
51
63
  const app = express();
52
64
  const router = express.Router();
53
65
 
54
- Routes.get('/hello', ({ res }) => {
66
+ Router.get('/hello', ({ res }) => {
55
67
  res.send('Hello World');
56
68
  });
57
69
 
58
- await Routes.apply(router);
70
+ await Router.apply(router);
59
71
  app.use(router);
60
72
 
61
73
  app.listen(3000);
@@ -65,16 +77,16 @@ app.listen(3000);
65
77
 
66
78
  ```typescript
67
79
  import express from 'express';
68
- import Routes from '@refkinscallv/express-routing';
80
+ import Router from 'clear-router';
69
81
 
70
82
  const app = express();
71
83
  const router = express.Router();
72
84
 
73
- Routes.get('/hello', ({ res }) => {
85
+ Router.get('/hello', ({ res }) => {
74
86
  res.send('Hello World');
75
87
  });
76
88
 
77
- await Routes.apply(router);
89
+ await Router.apply(router);
78
90
  app.use(router);
79
91
 
80
92
  app.listen(3000);
@@ -85,7 +97,7 @@ app.listen(3000);
85
97
  ### Basic Route
86
98
 
87
99
  ```javascript
88
- Routes.get('/hello', ({ res }) => {
100
+ Router.get('/hello', ({ res }) => {
89
101
  res.send('Hello World');
90
102
  });
91
103
  ```
@@ -98,7 +110,7 @@ const authMiddleware = (req, res, next) => {
98
110
  next();
99
111
  };
100
112
 
101
- Routes.post('/secure', ({ res }) => res.send('Protected'), [authMiddleware]);
113
+ Router.post('/secure', ({ res }) => res.send('Protected'), [authMiddleware]);
102
114
  ```
103
115
 
104
116
  ### Controller Binding
@@ -110,7 +122,7 @@ class UserController {
110
122
  }
111
123
  }
112
124
 
113
- Routes.get('/users', [UserController, 'index']);
125
+ Router.get('/users', [UserController, 'index']);
114
126
  ```
115
127
 
116
128
  Class-based handlers will auto-bind to static or instance methods.
@@ -118,31 +130,35 @@ Class-based handlers will auto-bind to static or instance methods.
118
130
  ### Grouped Routes
119
131
 
120
132
  ```javascript
121
- Routes.group('/admin', () => {
122
- Routes.get('/dashboard', ({ res }) => res.send('Admin Panel'));
133
+ Router.group('/admin', () => {
134
+ Router.get('/dashboard', ({ res }) => res.send('Admin Panel'));
123
135
  });
124
136
  ```
125
137
 
126
138
  With middleware:
127
139
 
128
140
  ```javascript
129
- Routes.group('/secure', () => {
130
- Routes.get('/data', ({ res }) => res.send('Secure Data'));
131
- }, [authMiddleware]);
141
+ Router.group(
142
+ '/secure',
143
+ () => {
144
+ Router.get('/data', ({ res }) => res.send('Secure Data'));
145
+ },
146
+ [authMiddleware],
147
+ );
132
148
  ```
133
149
 
134
150
  ### Global Middleware Scope
135
151
 
136
152
  ```javascript
137
- Routes.middleware([authMiddleware], () => {
138
- Routes.get('/profile', ({ res }) => res.send('My Profile'));
153
+ Router.middleware([authMiddleware], () => {
154
+ Router.get('/profile', ({ res }) => res.send('My Profile'));
139
155
  });
140
156
  ```
141
157
 
142
158
  ### Multiple HTTP Methods
143
159
 
144
160
  ```javascript
145
- Routes.add(['get', 'post'], '/handle', ({ req, res }) => {
161
+ Router.add(['get', 'post'], '/handle', ({ req, res }) => {
146
162
  res.send(`Method: ${req.method}`);
147
163
  });
148
164
  ```
@@ -150,10 +166,10 @@ Routes.add(['get', 'post'], '/handle', ({ req, res }) => {
150
166
  ### Inspecting Routes
151
167
 
152
168
  ```javascript
153
- Routes.get('/hello', ({ res }) => res.send('Hello'));
154
- Routes.post('/world', ({ res }) => res.send('World'));
169
+ Router.get('/hello', ({ res }) => res.send('Hello'));
170
+ Router.post('/world', ({ res }) => res.send('World'));
155
171
 
156
- const allRoutes = Routes.allRoutes();
172
+ const allRoutes = Router.allRoutes();
157
173
  console.log(allRoutes);
158
174
  // Output:
159
175
  // [
@@ -1,4 +1,6 @@
1
- //#region src/express/routes.ts
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+
3
+ //#region src/express/router.ts
2
4
  /**
3
5
  * @class clear-router
4
6
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
@@ -6,7 +8,7 @@
6
8
  * @author 3m1n3nc3
7
9
  * @repository https://github.com/toneflix/clear-router
8
10
  */
9
- var Routes = class {
11
+ var Router = class {
10
12
  /**
11
13
  * All registered routes
12
14
  */
@@ -245,4 +247,5 @@ var Routes = class {
245
247
  };
246
248
 
247
249
  //#endregion
248
- export { Routes as default };
250
+ exports.Router = Router;
251
+ exports.default = Router;
@@ -1,5 +1,5 @@
1
1
  import { i as RouteInfo, n as ControllerHandler, r as HttpMethod, t as ControllerAction } from "../basic-BCxhZ1Wd.cjs";
2
- import { NextFunction, Request, Response, Router } from "express";
2
+ import { NextFunction, Request, Response, Router as Router$1 } from "express";
3
3
 
4
4
  //#region types/express.d.ts
5
5
  /**
@@ -23,7 +23,7 @@ type Handler = RouteHandler | ControllerHandler;
23
23
  */
24
24
  type Middleware = (req: Request, res: Response, next: NextFunction) => any | Promise<any>;
25
25
  //#endregion
26
- //#region src/express/routes.d.ts
26
+ //#region src/express/router.d.ts
27
27
  /**
28
28
  * @class clear-router
29
29
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
@@ -31,7 +31,7 @@ type Middleware = (req: Request, res: Response, next: NextFunction) => any | Pro
31
31
  * @author 3m1n3nc3
32
32
  * @repository https://github.com/toneflix/clear-router
33
33
  */
34
- declare class Routes {
34
+ declare class Router {
35
35
  /**
36
36
  * All registered routes
37
37
  */
@@ -152,7 +152,8 @@ declare class Routes {
152
152
  *
153
153
  * @param router - Express Router instance
154
154
  */
155
- static apply(router: Router): void;
156
- static apply(router: Router): Promise<void>;
155
+ static apply(router: Router$1): void;
156
+ static apply(router: Router$1): Promise<void>;
157
157
  }
158
- export = Routes;
158
+ //#endregion
159
+ export { Router, Router as default };
@@ -1,5 +1,5 @@
1
1
  import { i as RouteInfo, n as ControllerHandler, r as HttpMethod, t as ControllerAction } from "../basic-POMY6a76.mjs";
2
- import { NextFunction, Request, Response, Router } from "express";
2
+ import { NextFunction, Request, Response, Router as Router$1 } from "express";
3
3
 
4
4
  //#region types/express.d.ts
5
5
  /**
@@ -23,7 +23,7 @@ type Handler = RouteHandler | ControllerHandler;
23
23
  */
24
24
  type Middleware = (req: Request, res: Response, next: NextFunction) => any | Promise<any>;
25
25
  //#endregion
26
- //#region src/express/routes.d.ts
26
+ //#region src/express/router.d.ts
27
27
  /**
28
28
  * @class clear-router
29
29
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
@@ -31,7 +31,7 @@ type Middleware = (req: Request, res: Response, next: NextFunction) => any | Pro
31
31
  * @author 3m1n3nc3
32
32
  * @repository https://github.com/toneflix/clear-router
33
33
  */
34
- declare class Routes {
34
+ declare class Router {
35
35
  /**
36
36
  * All registered routes
37
37
  */
@@ -152,8 +152,8 @@ declare class Routes {
152
152
  *
153
153
  * @param router - Express Router instance
154
154
  */
155
- static apply(router: Router): void;
156
- static apply(router: Router): Promise<void>;
155
+ static apply(router: Router$1): void;
156
+ static apply(router: Router$1): Promise<void>;
157
157
  }
158
158
  //#endregion
159
- export { Routes as default };
159
+ export { Router, Router as default };
@@ -1,5 +1,4 @@
1
-
2
- //#region src/express/routes.ts
1
+ //#region src/express/router.ts
3
2
  /**
4
3
  * @class clear-router
5
4
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
@@ -7,7 +6,7 @@
7
6
  * @author 3m1n3nc3
8
7
  * @repository https://github.com/toneflix/clear-router
9
8
  */
10
- var Routes = class {
9
+ var Router = class {
11
10
  /**
12
11
  * All registered routes
13
12
  */
@@ -246,4 +245,4 @@ var Routes = class {
246
245
  };
247
246
 
248
247
  //#endregion
249
- module.exports = Routes;
248
+ export { Router, Router as default };
@@ -1,11 +1,13 @@
1
- //#region src/h3/routes.ts
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+
3
+ //#region src/h3/router.ts
2
4
  /**
3
5
  * @class clear-router
4
6
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
5
7
  * @author 3m1n3nc3
6
8
  * @repository https://github.com/toneflix/clear-router
7
9
  */
8
- var Routes = class {
10
+ var Router = class {
9
11
  /**
10
12
  * All registered routes
11
13
  */
@@ -248,4 +250,5 @@ var Routes = class {
248
250
  };
249
251
 
250
252
  //#endregion
251
- export { Routes as default };
253
+ exports.Router = Router;
254
+ exports.default = Router;
@@ -18,14 +18,14 @@ type RouteHandler = (ctx: HttpContext) => any | Promise<any>;
18
18
  */
19
19
  type Handler = RouteHandler | ControllerHandler;
20
20
  //#endregion
21
- //#region src/h3/routes.d.ts
21
+ //#region src/h3/router.d.ts
22
22
  /**
23
23
  * @class clear-router
24
24
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
25
25
  * @author 3m1n3nc3
26
26
  * @repository https://github.com/toneflix/clear-router
27
27
  */
28
- declare class Routes {
28
+ declare class Router {
29
29
  /**
30
30
  * All registered routes
31
31
  */
@@ -148,4 +148,5 @@ declare class Routes {
148
148
  */
149
149
  static apply(app: H3): H3App;
150
150
  }
151
- export = Routes;
151
+ //#endregion
152
+ export { Router, Router as default };
@@ -18,14 +18,14 @@ type RouteHandler = (ctx: HttpContext) => any | Promise<any>;
18
18
  */
19
19
  type Handler = RouteHandler | ControllerHandler;
20
20
  //#endregion
21
- //#region src/h3/routes.d.ts
21
+ //#region src/h3/router.d.ts
22
22
  /**
23
23
  * @class clear-router
24
24
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
25
25
  * @author 3m1n3nc3
26
26
  * @repository https://github.com/toneflix/clear-router
27
27
  */
28
- declare class Routes {
28
+ declare class Router {
29
29
  /**
30
30
  * All registered routes
31
31
  */
@@ -149,4 +149,4 @@ declare class Routes {
149
149
  static apply(app: H3): H3App;
150
150
  }
151
151
  //#endregion
152
- export { Routes as default };
152
+ export { Router, Router as default };
@@ -1,12 +1,11 @@
1
-
2
- //#region src/h3/routes.ts
1
+ //#region src/h3/router.ts
3
2
  /**
4
3
  * @class clear-router
5
4
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
6
5
  * @author 3m1n3nc3
7
6
  * @repository https://github.com/toneflix/clear-router
8
7
  */
9
- var Routes = class {
8
+ var Router = class {
10
9
  /**
11
10
  * All registered routes
12
11
  */
@@ -249,4 +248,4 @@ var Routes = class {
249
248
  };
250
249
 
251
250
  //#endregion
252
- module.exports = Routes;
251
+ export { Router, Router as default };
@@ -0,0 +1,7 @@
1
+ //#region types/basic.d.ts
2
+ /**
3
+ * Controller method reference
4
+ */
5
+ type ControllerHandler = [any, string];
6
+ //#endregion
7
+ export { ControllerHandler };
@@ -0,0 +1,26 @@
1
+ import { ControllerHandler } from "./basic.mjs";
2
+ import { NextFunction, Request, Response } from "express";
3
+
4
+ //#region types/express.d.ts
5
+ /**
6
+ * HTTP context passed to route handlers
7
+ */
8
+ interface HttpContext {
9
+ req: Request;
10
+ res: Response;
11
+ next: NextFunction;
12
+ }
13
+ /**
14
+ * Route handler function type
15
+ */
16
+ type RouteHandler = (ctx: HttpContext) => any | Promise<any>;
17
+ /**
18
+ * Handler can be either a function or controller reference
19
+ */
20
+ type Handler = RouteHandler | ControllerHandler;
21
+ /**
22
+ * Middleware function type
23
+ */
24
+ type Middleware = (req: Request, res: Response, next: NextFunction) => any | Promise<any>;
25
+ //#endregion
26
+ export { Handler, HttpContext, Middleware, RouteHandler };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,23 @@
1
+ import { ControllerHandler } from "./basic.mjs";
2
+ import { H3, H3Event, Middleware, TypedServerRequest } from "h3";
3
+
4
+ //#region types/h3.d.ts
5
+ type H3App = Omit<H3['fetch'], 'fetch'> & {
6
+ fetch: (request: TypedServerRequest) => Promise<Response>;
7
+ };
8
+ type MaybePromise<T = unknown> = T | Promise<T>;
9
+ /**
10
+ * HTTP context passed to route handlers
11
+ */
12
+ type HttpContext = H3Event;
13
+ /**
14
+ * Route handler function type
15
+ */
16
+ type RouteHandler = (ctx: HttpContext) => any | Promise<any>;
17
+ /**
18
+ * Handler can be either a function or controller reference
19
+ */
20
+ type Handler = RouteHandler | ControllerHandler;
21
+ type NextFunction = () => MaybePromise<unknown | undefined>;
22
+ //#endregion
23
+ export { H3App, Handler, HttpContext, MaybePromise, type Middleware, NextFunction, RouteHandler };
@@ -0,0 +1 @@
1
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-router",
3
- "version": "2.0.3",
3
+ "version": "2.0.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",
@@ -32,13 +32,15 @@
32
32
  "module": "dist/express/routes.mjs",
33
33
  "types": "dist/express/routes.d.mts",
34
34
  "exports": {
35
- "./express/routes": {
36
- "import": "./dist/express/routes.mjs",
37
- "require": "./dist/express/routes.cjs"
35
+ "./express": "./dist/types/express.mjs",
36
+ "./express/router": {
37
+ "import": "./dist/express/router.mjs",
38
+ "require": "./dist/express/router.cjs"
38
39
  },
39
- "./h3/routes": {
40
- "import": "./dist/h3/routes.mjs",
41
- "require": "./dist/h3/routes.cjs"
40
+ "./h3": "./dist/types/h3.mjs",
41
+ "./h3/router": {
42
+ "import": "./dist/h3/router.mjs",
43
+ "require": "./dist/h3/router.cjs"
42
44
  },
43
45
  "./package.json": "./package.json"
44
46
  },