@arikajs/router 0.0.1
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/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/Route.d.ts +15 -0
- package/dist/Route.d.ts.map +1 -0
- package/dist/Route.js +29 -0
- package/dist/Route.js.map +1 -0
- package/dist/RouteEntry.d.ts +25 -0
- package/dist/RouteEntry.d.ts.map +1 -0
- package/dist/RouteEntry.js +54 -0
- package/dist/RouteEntry.js.map +1 -0
- package/dist/RouteMatcher.d.ts +6 -0
- package/dist/RouteMatcher.d.ts.map +1 -0
- package/dist/RouteMatcher.js +33 -0
- package/dist/RouteMatcher.js.map +1 -0
- package/dist/RouteRegistry.d.ts +22 -0
- package/dist/RouteRegistry.d.ts.map +1 -0
- package/dist/RouteRegistry.js +58 -0
- package/dist/RouteRegistry.js.map +1 -0
- package/dist/Router.d.ts +44 -0
- package/dist/Router.d.ts.map +1 -0
- package/dist/Router.js +82 -0
- package/dist/Router.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/tests/Router.test.d.ts +2 -0
- package/dist/tests/Router.test.d.ts.map +1 -0
- package/dist/tests/Router.test.js +137 -0
- package/dist/tests/Router.test.js.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ArikaJs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
## Arika Router
|
|
2
|
+
|
|
3
|
+
`@arikajs/router` is the **routing and request-dispatching layer** of the ArikaJS framework.
|
|
4
|
+
|
|
5
|
+
It is responsible for mapping HTTP requests to route handlers in a predictable, framework-controlled way, without depending on Express, Fastify, or any external routing library.
|
|
6
|
+
|
|
7
|
+
Arika Router integrates directly with **@arikajs/http** and **@arikajs/foundation** to provide an elegant, intuitive routing experience.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
### Status
|
|
12
|
+
|
|
13
|
+
- **Stage**: Early Development / v0.x
|
|
14
|
+
- **Scope (v1.x)**:
|
|
15
|
+
- HTTP method based routing (GET, POST, PUT, PATCH, DELETE)
|
|
16
|
+
- Path-based route matching (Static & Regex)
|
|
17
|
+
- Route parameters (`/users/:id`)
|
|
18
|
+
- Central route registry
|
|
19
|
+
- Route grouping with prefixes & middleware
|
|
20
|
+
- Route naming
|
|
21
|
+
- Controller resolution from container
|
|
22
|
+
- Route handler execution (dispatching)
|
|
23
|
+
- **Out of scope (for now)**:
|
|
24
|
+
- API Versioning helpers
|
|
25
|
+
- Automatic OpenAPI/Swagger generation
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- **Core Routing**
|
|
32
|
+
- HTTP method based routing (GET, POST, PUT, PATCH, DELETE)
|
|
33
|
+
- Path-based route matching
|
|
34
|
+
- Central route registry
|
|
35
|
+
|
|
36
|
+
- **Route Grouping**
|
|
37
|
+
- Group routes with a common prefix
|
|
38
|
+
- Nested groups support
|
|
39
|
+
|
|
40
|
+
- **Request Matching**
|
|
41
|
+
- Method + path matching
|
|
42
|
+
- First match wins logic
|
|
43
|
+
- Predictable matching order
|
|
44
|
+
|
|
45
|
+
- **Dispatching**
|
|
46
|
+
- Route handler execution
|
|
47
|
+
- Framework-controlled dispatch flow
|
|
48
|
+
- Decoupled from HTTP response handling
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm install @arikajs/router
|
|
56
|
+
# or
|
|
57
|
+
yarn add @arikajs/router
|
|
58
|
+
# or
|
|
59
|
+
pnpm add @arikajs/router
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
⚠️ Requires `@arikajs/http` and `@arikajs/foundation`.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
### 1. Register Routes
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { Route } from '@arikajs/router';
|
|
72
|
+
|
|
73
|
+
Route.get('/hello', () => {
|
|
74
|
+
return 'Hello World';
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
Route.post('/submit', (request) => {
|
|
78
|
+
return 'Form submitted';
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 2. Route Parameters & Fluent Chaining
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
Route.get('/users/:id', (request, id) => {
|
|
86
|
+
return `User ID: ${id}`;
|
|
87
|
+
})
|
|
88
|
+
.as('users.show')
|
|
89
|
+
.withMiddleware(AuthMiddleware);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 3. Controller Resolution
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { UserController } from './controllers/UserController';
|
|
96
|
+
|
|
97
|
+
Route.get('/users', [UserController, 'index']);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 4. Route Grouping
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
Route.group('/api', () => {
|
|
104
|
+
Route.get('/users', () => {
|
|
105
|
+
return ['user1', 'user2'];
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Architecture Overview
|
|
113
|
+
|
|
114
|
+
The router follows a simple flow:
|
|
115
|
+
|
|
116
|
+
```text
|
|
117
|
+
HTTP Request
|
|
118
|
+
↓
|
|
119
|
+
HttpKernel (@arikajs/http)
|
|
120
|
+
↓
|
|
121
|
+
RouteMatcher
|
|
122
|
+
↓
|
|
123
|
+
Matched Route
|
|
124
|
+
↓
|
|
125
|
+
Dispatcher
|
|
126
|
+
↓
|
|
127
|
+
Handler Execution
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
The router never writes to the response directly. It only decides **which handler should run**.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Route Matching
|
|
135
|
+
|
|
136
|
+
The router matches incoming requests using method and path:
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
const route = routeMatcher.match('GET', '/hello');
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Matching rules:
|
|
143
|
+
- Method must match exactly.
|
|
144
|
+
- Supports both static paths and dynamic parameters (`/users/:id`).
|
|
145
|
+
- The first route defined that matches will be selected.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Dispatching
|
|
150
|
+
|
|
151
|
+
Once a route is matched, the dispatcher executes the handler:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
await dispatcher.dispatch(route, request);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The dispatcher focuses purely on execution, leaving middleware and response formatting to other layers of the framework.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Road Map
|
|
162
|
+
|
|
163
|
+
- [x] Route parameters (`/users/:id`)
|
|
164
|
+
- [x] Controller resolution from container
|
|
165
|
+
- [x] Route-level middleware
|
|
166
|
+
- [x] Named routes
|
|
167
|
+
- [x] Route caching for performance
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Versioning & Stability
|
|
172
|
+
|
|
173
|
+
- While in **v0.x**, the API may change between minor versions.
|
|
174
|
+
- Once the core routing engine stabilizes, `@arikajs/router` will move to **v1.0** and follow **semver** strictly.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Contributing
|
|
179
|
+
|
|
180
|
+
Contributions are welcome! Please ensure you:
|
|
181
|
+
- Run the test suite before submitting PRs.
|
|
182
|
+
- Add tests for new features.
|
|
183
|
+
- Follow the existing coding style.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
`@arikajs/router` is open-sourced software licensed under the **MIT license**.
|
package/dist/Route.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RouteHandler } from './types';
|
|
2
|
+
import { RouteEntry } from './RouteEntry';
|
|
3
|
+
export declare class Route {
|
|
4
|
+
static get(path: string, handler: RouteHandler): RouteEntry;
|
|
5
|
+
static post(path: string, handler: RouteHandler): RouteEntry;
|
|
6
|
+
static put(path: string, handler: RouteHandler): RouteEntry;
|
|
7
|
+
static patch(path: string, handler: RouteHandler): RouteEntry;
|
|
8
|
+
static delete(path: string, handler: RouteHandler): RouteEntry;
|
|
9
|
+
static group(options: string | {
|
|
10
|
+
prefix?: string;
|
|
11
|
+
middleware?: any | any[];
|
|
12
|
+
}, callback: () => void): void;
|
|
13
|
+
static model(key: string, resolver: any): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=Route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../src/Route.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,KAAK;WACA,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU;WAIpD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU;WAIrD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU;WAIpD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU;WAItD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU;WAIvD,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,CAAA;KAAE,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;WAIlG,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;CAGxD"}
|
package/dist/Route.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Route = void 0;
|
|
4
|
+
const RouteRegistry_1 = require("./RouteRegistry");
|
|
5
|
+
class Route {
|
|
6
|
+
static get(path, handler) {
|
|
7
|
+
return RouteRegistry_1.RouteRegistry.getInstance().addRoute('GET', path, handler);
|
|
8
|
+
}
|
|
9
|
+
static post(path, handler) {
|
|
10
|
+
return RouteRegistry_1.RouteRegistry.getInstance().addRoute('POST', path, handler);
|
|
11
|
+
}
|
|
12
|
+
static put(path, handler) {
|
|
13
|
+
return RouteRegistry_1.RouteRegistry.getInstance().addRoute('PUT', path, handler);
|
|
14
|
+
}
|
|
15
|
+
static patch(path, handler) {
|
|
16
|
+
return RouteRegistry_1.RouteRegistry.getInstance().addRoute('PATCH', path, handler);
|
|
17
|
+
}
|
|
18
|
+
static delete(path, handler) {
|
|
19
|
+
return RouteRegistry_1.RouteRegistry.getInstance().addRoute('DELETE', path, handler);
|
|
20
|
+
}
|
|
21
|
+
static group(options, callback) {
|
|
22
|
+
RouteRegistry_1.RouteRegistry.getInstance().group(options, callback);
|
|
23
|
+
}
|
|
24
|
+
static model(key, resolver) {
|
|
25
|
+
RouteRegistry_1.RouteRegistry.getInstance().model(key, resolver);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Route = Route;
|
|
29
|
+
//# sourceMappingURL=Route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Route.js","sourceRoot":"","sources":["../src/Route.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAIhD,MAAa,KAAK;IACP,MAAM,CAAC,GAAG,CAAC,IAAY,EAAE,OAAqB;QACjD,OAAO,6BAAa,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;IAEM,MAAM,CAAC,IAAI,CAAC,IAAY,EAAE,OAAqB;QAClD,OAAO,6BAAa,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACvE,CAAC;IAEM,MAAM,CAAC,GAAG,CAAC,IAAY,EAAE,OAAqB;QACjD,OAAO,6BAAa,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,IAAY,EAAE,OAAqB;QACnD,OAAO,6BAAa,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACxE,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,IAAY,EAAE,OAAqB;QACpD,OAAO,6BAAa,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,OAA+D,EAAE,QAAoB;QACrG,6BAAa,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,GAAW,EAAE,QAAa;QAC1C,6BAAa,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACrD,CAAC;CACJ;AA5BD,sBA4BC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RouteHandler, RouteDefinition } from './types';
|
|
2
|
+
export declare class RouteEntry implements RouteDefinition {
|
|
3
|
+
method: string;
|
|
4
|
+
path: string;
|
|
5
|
+
handler: RouteHandler;
|
|
6
|
+
name?: string;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
middleware: any[];
|
|
9
|
+
regex: RegExp;
|
|
10
|
+
paramKeys: string[];
|
|
11
|
+
constructor(method: string, path: string, handler: RouteHandler, prefix?: string, groupMiddleware?: any[]);
|
|
12
|
+
/**
|
|
13
|
+
* Set a name for the route.
|
|
14
|
+
*/
|
|
15
|
+
as(name: string): this;
|
|
16
|
+
/**
|
|
17
|
+
* Add middleware to the route.
|
|
18
|
+
*/
|
|
19
|
+
withMiddleware(middleware: any | any[]): this;
|
|
20
|
+
/**
|
|
21
|
+
* Compile the path into a regex.
|
|
22
|
+
*/
|
|
23
|
+
private compilePath;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=RouteEntry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteEntry.d.ts","sourceRoot":"","sources":["../src/RouteEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAExD,qBAAa,UAAW,YAAW,eAAe;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,GAAG,EAAE,CAAM;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,EAAE,CAAM;gBAEpB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,eAAe,GAAE,GAAG,EAAO;IAY7G;;OAEG;IACI,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK7B;;OAEG;IACI,cAAc,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,EAAE,GAAG,IAAI;IASpD;;OAEG;IACH,OAAO,CAAC,WAAW;CActB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteEntry = void 0;
|
|
4
|
+
class RouteEntry {
|
|
5
|
+
constructor(method, path, handler, prefix, groupMiddleware = []) {
|
|
6
|
+
this.middleware = [];
|
|
7
|
+
this.paramKeys = [];
|
|
8
|
+
this.method = method.toUpperCase();
|
|
9
|
+
this.path = path;
|
|
10
|
+
this.handler = handler;
|
|
11
|
+
this.prefix = prefix;
|
|
12
|
+
this.middleware = [...groupMiddleware];
|
|
13
|
+
const { regex, paramKeys } = this.compilePath(path);
|
|
14
|
+
this.regex = regex;
|
|
15
|
+
this.paramKeys = paramKeys;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Set a name for the route.
|
|
19
|
+
*/
|
|
20
|
+
as(name) {
|
|
21
|
+
this.name = name;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Add middleware to the route.
|
|
26
|
+
*/
|
|
27
|
+
withMiddleware(middleware) {
|
|
28
|
+
if (Array.isArray(middleware)) {
|
|
29
|
+
this.middleware.push(...middleware);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.middleware.push(middleware);
|
|
33
|
+
}
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Compile the path into a regex.
|
|
38
|
+
*/
|
|
39
|
+
compilePath(path) {
|
|
40
|
+
const paramKeys = [];
|
|
41
|
+
const pattern = path
|
|
42
|
+
.replace(/:([a-zA-Z0-9_]+)|\{([a-zA-Z0-9_]+)\}/g, (_, key1, key2) => {
|
|
43
|
+
paramKeys.push(key1 || key2);
|
|
44
|
+
return '([^/]+)';
|
|
45
|
+
})
|
|
46
|
+
.replace(/\//g, '\\/');
|
|
47
|
+
return {
|
|
48
|
+
regex: new RegExp(`^${pattern}$`),
|
|
49
|
+
paramKeys
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.RouteEntry = RouteEntry;
|
|
54
|
+
//# sourceMappingURL=RouteEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteEntry.js","sourceRoot":"","sources":["../src/RouteEntry.ts"],"names":[],"mappings":";;;AAEA,MAAa,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;YAC7B,OAAO,SAAS,CAAC;QACrB,CAAC,CAAC;aACD,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAE3B,OAAO;YACH,KAAK,EAAE,IAAI,MAAM,CAAC,IAAI,OAAO,GAAG,CAAC;YACjC,SAAS;SACZ,CAAC;IACN,CAAC;CACJ;AA3DD,gCA2DC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteMatcher.d.ts","sourceRoot":"","sources":["../src/RouteMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGvC,qBAAa,YAAY;IACd,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IA2B/D,OAAO,CAAC,aAAa;CAGxB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteMatcher = void 0;
|
|
4
|
+
const RouteRegistry_1 = require("./RouteRegistry");
|
|
5
|
+
class RouteMatcher {
|
|
6
|
+
match(method, path) {
|
|
7
|
+
const routes = RouteRegistry_1.RouteRegistry.getInstance().getRoutes();
|
|
8
|
+
const normalizedMethod = method.toUpperCase();
|
|
9
|
+
const normalizedPath = this.normalizePath(path);
|
|
10
|
+
for (const route of routes) {
|
|
11
|
+
if (route.method !== normalizedMethod) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const match = normalizedPath.match(route.regex);
|
|
15
|
+
if (match) {
|
|
16
|
+
const params = {};
|
|
17
|
+
route.paramKeys.forEach((key, index) => {
|
|
18
|
+
params[key] = match[index + 1];
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
route,
|
|
22
|
+
params
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
normalizePath(path) {
|
|
29
|
+
return path.replace(/\/+/g, '/') || '/';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.RouteMatcher = RouteMatcher;
|
|
33
|
+
//# sourceMappingURL=RouteMatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteMatcher.js","sourceRoot":"","sources":["../src/RouteMatcher.ts"],"names":[],"mappings":";;;AACA,mDAAgD;AAEhD,MAAa,YAAY;IACd,KAAK,CAAC,MAAc,EAAE,IAAY;QACrC,MAAM,MAAM,GAAG,6BAAa,CAAC,WAAW,EAAE,CAAC,SAAS,EAAE,CAAC;QACvD,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAEhD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YACzB,IAAI,KAAK,CAAC,MAAM,KAAK,gBAAgB,EAAE,CAAC;gBACpC,SAAS;YACb,CAAC;YAED,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAChD,IAAI,KAAK,EAAE,CAAC;gBACR,MAAM,MAAM,GAA2B,EAAE,CAAC;gBAC1C,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;oBACnC,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;gBACnC,CAAC,CAAC,CAAC;gBAEH,OAAO;oBACH,KAAK;oBACL,MAAM;iBACT,CAAC;YACN,CAAC;QACL,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAEO,aAAa,CAAC,IAAY;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,GAAG,CAAC;IAC5C,CAAC;CACJ;AA/BD,oCA+BC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RouteHandler } from './types';
|
|
2
|
+
import { RouteEntry } from './RouteEntry';
|
|
3
|
+
export declare class RouteRegistry {
|
|
4
|
+
private static instance;
|
|
5
|
+
private routes;
|
|
6
|
+
private groupStack;
|
|
7
|
+
private middlewareStack;
|
|
8
|
+
private models;
|
|
9
|
+
private constructor();
|
|
10
|
+
static getInstance(): RouteRegistry;
|
|
11
|
+
model(key: string, resolver: any): void;
|
|
12
|
+
getModels(): Map<string, any>;
|
|
13
|
+
addRoute(method: string, path: string, handler: RouteHandler): RouteEntry;
|
|
14
|
+
group(options: string | {
|
|
15
|
+
prefix?: string;
|
|
16
|
+
middleware?: any | any[];
|
|
17
|
+
}, callback: () => void): void;
|
|
18
|
+
getRoutes(): RouteEntry[];
|
|
19
|
+
clear(): void;
|
|
20
|
+
private normalizePath;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=RouteRegistry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteRegistry.d.ts","sourceRoot":"","sources":["../src/RouteRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,aAAa;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgB;IACvC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,eAAe,CAAe;IACtC,OAAO,CAAC,MAAM,CAA+B;IAE7C,OAAO;WAEO,WAAW,IAAI,aAAa;IAOnC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAIvC,SAAS,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;IAI7B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU;IAiBzE,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,GAAG,GAAG,GAAG,EAAE,CAAA;KAAE,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAkBlG,SAAS,IAAI,UAAU,EAAE;IAIzB,KAAK,IAAI,IAAI;IAMpB,OAAO,CAAC,aAAa;CAIxB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteRegistry = void 0;
|
|
4
|
+
const RouteEntry_1 = require("./RouteEntry");
|
|
5
|
+
class RouteRegistry {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.routes = [];
|
|
8
|
+
this.groupStack = [];
|
|
9
|
+
this.middlewareStack = [];
|
|
10
|
+
this.models = new Map();
|
|
11
|
+
}
|
|
12
|
+
static getInstance() {
|
|
13
|
+
if (!RouteRegistry.instance) {
|
|
14
|
+
RouteRegistry.instance = new RouteRegistry();
|
|
15
|
+
}
|
|
16
|
+
return RouteRegistry.instance;
|
|
17
|
+
}
|
|
18
|
+
model(key, resolver) {
|
|
19
|
+
this.models.set(key, resolver);
|
|
20
|
+
}
|
|
21
|
+
getModels() {
|
|
22
|
+
return this.models;
|
|
23
|
+
}
|
|
24
|
+
addRoute(method, path, handler) {
|
|
25
|
+
const prefix = this.groupStack.join('');
|
|
26
|
+
const fullPath = this.normalizePath(prefix + '/' + path);
|
|
27
|
+
const groupMiddleware = this.middlewareStack.flat();
|
|
28
|
+
const route = new RouteEntry_1.RouteEntry(method, fullPath, handler, prefix || undefined, groupMiddleware);
|
|
29
|
+
this.routes.push(route);
|
|
30
|
+
return route;
|
|
31
|
+
}
|
|
32
|
+
group(options, callback) {
|
|
33
|
+
let prefix = typeof options === 'string' ? options : options.prefix || '';
|
|
34
|
+
if (prefix && !prefix.startsWith('/')) {
|
|
35
|
+
prefix = '/' + prefix;
|
|
36
|
+
}
|
|
37
|
+
const middleware = typeof options === 'string' ? [] : (Array.isArray(options.middleware) ? options.middleware : (options.middleware ? [options.middleware] : []));
|
|
38
|
+
this.groupStack.push(prefix);
|
|
39
|
+
this.middlewareStack.push(middleware);
|
|
40
|
+
callback();
|
|
41
|
+
this.middlewareStack.pop();
|
|
42
|
+
this.groupStack.pop();
|
|
43
|
+
}
|
|
44
|
+
getRoutes() {
|
|
45
|
+
return this.routes;
|
|
46
|
+
}
|
|
47
|
+
clear() {
|
|
48
|
+
this.routes = [];
|
|
49
|
+
this.groupStack = [];
|
|
50
|
+
this.middlewareStack = [];
|
|
51
|
+
}
|
|
52
|
+
normalizePath(path) {
|
|
53
|
+
const normalized = path.replace(/\/+/g, '/');
|
|
54
|
+
return normalized.startsWith('/') ? normalized : '/' + normalized;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.RouteRegistry = RouteRegistry;
|
|
58
|
+
//# sourceMappingURL=RouteRegistry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteRegistry.js","sourceRoot":"","sources":["../src/RouteRegistry.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAE1C,MAAa,aAAa;IAOtB;QALQ,WAAM,GAAiB,EAAE,CAAC;QAC1B,eAAU,GAAa,EAAE,CAAC;QAC1B,oBAAe,GAAY,EAAE,CAAC;QAC9B,WAAM,GAAqB,IAAI,GAAG,EAAE,CAAC;IAErB,CAAC;IAElB,MAAM,CAAC,WAAW;QACrB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC1B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAClC,CAAC;IAEM,KAAK,CAAC,GAAW,EAAE,QAAa;QACnC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,Q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,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7B,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEtC,QAAQ,EAAE,CAAC;QAEX,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;IAC1B,CAAC;IAEM,SAAS;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;IAC9B,CAAC;IAEO,aAAa,CAAC,IAAY;QAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7C,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,UAAU,CAAC;IACtE,CAAC;CACJ;AAzED,sCAyEC"}
|
package/dist/Router.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Request, Response } from '@arikajs/http';
|
|
2
|
+
import { MatchedRoute, Container } from './types';
|
|
3
|
+
export declare class Router {
|
|
4
|
+
private matcher;
|
|
5
|
+
private dispatcher;
|
|
6
|
+
private cache;
|
|
7
|
+
constructor(container?: Container);
|
|
8
|
+
/**
|
|
9
|
+
* Sync models from the static registry.
|
|
10
|
+
*/
|
|
11
|
+
private syncModels;
|
|
12
|
+
/**
|
|
13
|
+
* Set the container for the dispatcher.
|
|
14
|
+
*/
|
|
15
|
+
setContainer(container: Container): this;
|
|
16
|
+
/**
|
|
17
|
+
* Set the middleware groups.
|
|
18
|
+
*/
|
|
19
|
+
setMiddlewareGroups(groups: Record<string, any[]>): this;
|
|
20
|
+
/**
|
|
21
|
+
* Set the route middleware aliases.
|
|
22
|
+
*/
|
|
23
|
+
setRouteMiddleware(middleware: Record<string, any>): this;
|
|
24
|
+
/**
|
|
25
|
+
* Register a route model binding.
|
|
26
|
+
*/
|
|
27
|
+
model(key: string, resolver: ((value: any) => Promise<any>) | {
|
|
28
|
+
findOrFail: (id: any) => Promise<any>;
|
|
29
|
+
}): this;
|
|
30
|
+
/**
|
|
31
|
+
* Match a request to a route.
|
|
32
|
+
*/
|
|
33
|
+
match(method: string, path: string): MatchedRoute | null;
|
|
34
|
+
/**
|
|
35
|
+
* Clear the route cache.
|
|
36
|
+
*/
|
|
37
|
+
clearCache(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Dispatch the request to the matching route and return the result.
|
|
40
|
+
* Note: This does not wrap the result in a Response object.
|
|
41
|
+
*/
|
|
42
|
+
dispatch(request: Request, response: Response): Promise<any>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=Router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGlD,qBAAa,MAAM;IACf,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,KAAK,CAA+C;gBAEhD,SAAS,CAAC,EAAE,SAAS;IAKjC;;OAEG;IACH,OAAO,CAAC,UAAU;IAOlB;;OAEG;IACI,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAK/C;;OAEG;IACI,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI;IAK/D;;OAEG;IACI,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAKhE;;OAEG;IACI,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG;QAAE,UAAU,EAAE,CAAC,EAAE,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;KAAE,GAAG,IAAI;IAKrH;;OAEG;IACI,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAa/D;;OAEG;IACI,UAAU,IAAI,IAAI;IAIzB;;;OAGG;IACU,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CAU5E"}
|
package/dist/Router.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Router = void 0;
|
|
4
|
+
const RouteMatcher_1 = require("./RouteMatcher");
|
|
5
|
+
const dispatcher_1 = require("@arikajs/dispatcher");
|
|
6
|
+
const RouteRegistry_1 = require("./RouteRegistry");
|
|
7
|
+
class Router {
|
|
8
|
+
constructor(container) {
|
|
9
|
+
this.cache = new Map();
|
|
10
|
+
this.matcher = new RouteMatcher_1.RouteMatcher();
|
|
11
|
+
this.dispatcher = new dispatcher_1.Dispatcher(container);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Sync models from the static registry.
|
|
15
|
+
*/
|
|
16
|
+
syncModels() {
|
|
17
|
+
const models = RouteRegistry_1.RouteRegistry.getInstance().getModels();
|
|
18
|
+
for (const [key, resolver] of models.entries()) {
|
|
19
|
+
this.dispatcher.bind(key, resolver);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Set the container for the dispatcher.
|
|
24
|
+
*/
|
|
25
|
+
setContainer(container) {
|
|
26
|
+
this.dispatcher.setContainer(container);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Set the middleware groups.
|
|
31
|
+
*/
|
|
32
|
+
setMiddlewareGroups(groups) {
|
|
33
|
+
this.dispatcher.setMiddlewareGroups(groups);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Set the route middleware aliases.
|
|
38
|
+
*/
|
|
39
|
+
setRouteMiddleware(middleware) {
|
|
40
|
+
this.dispatcher.setRouteMiddleware(middleware);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Register a route model binding.
|
|
45
|
+
*/
|
|
46
|
+
model(key, resolver) {
|
|
47
|
+
this.dispatcher.bind(key, resolver);
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Match a request to a route.
|
|
52
|
+
*/
|
|
53
|
+
match(method, path) {
|
|
54
|
+
const cacheKey = `${method.toUpperCase()}:${path}`;
|
|
55
|
+
if (this.cache.has(cacheKey)) {
|
|
56
|
+
return this.cache.get(cacheKey);
|
|
57
|
+
}
|
|
58
|
+
const matched = this.matcher.match(method, path);
|
|
59
|
+
this.cache.set(cacheKey, matched);
|
|
60
|
+
return matched;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Clear the route cache.
|
|
64
|
+
*/
|
|
65
|
+
clearCache() {
|
|
66
|
+
this.cache.clear();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Dispatch the request to the matching route and return the result.
|
|
70
|
+
* Note: This does not wrap the result in a Response object.
|
|
71
|
+
*/
|
|
72
|
+
async dispatch(request, response) {
|
|
73
|
+
this.syncModels();
|
|
74
|
+
const matched = this.match(request.method(), request.path());
|
|
75
|
+
if (!matched) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return await this.dispatcher.dispatch(matched, request, response);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.Router = Router;
|
|
82
|
+
//# sourceMappingURL=Router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":";;;AACA,iDAA8C;AAC9C,oDAAiD;AAEjD,mDAAgD;AAEhD,MAAa,MAAM;IAKf,YAAY,SAAqB;QAFzB,UAAK,GAAqC,IAAI,GAAG,EAAE,CAAC;QAGxD,IAAI,CAAC,OAAO,GAAG,IAAI,2BAAY,EAAE,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,IAAI,uBAAU,CAAC,SAAS,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACK,UAAU;QACd,MAAM,MAAM,GAAG,6BAAa,CAAC,WAAW,EAAE,CAAC,SAAS,EAAE,CAAC;QACvD,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YAC7C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACxC,CAAC;IACL,CAAC;IAED;;OAEG;IACI,YAAY,CAAC,SAAoB;QACpC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,mBAAmB,CAAC,MAA6B;QACpD,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,kBAAkB,CAAC,UAA+B;QACrD,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,GAAW,EAAE,QAAoF;QAC1G,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;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C;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Route"), exports);
|
|
18
|
+
__exportStar(require("./RouteEntry"), exports);
|
|
19
|
+
__exportStar(require("./Router"), exports);
|
|
20
|
+
__exportStar(require("./RouteMatcher"), exports);
|
|
21
|
+
__exportStar(require("./RouteRegistry"), exports);
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,+CAA6B;AAC7B,2CAAyB;AACzB,iDAA+B;AAC/B,kDAAgC;AAChC,0CAAwB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.test.d.ts","sourceRoot":"","sources":["../../src/tests/Router.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_test_1 = require("node:test");
|
|
7
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
8
|
+
const index_1 = require("../index");
|
|
9
|
+
(0, node_test_1.test)('Router can register and match routes', async (t) => {
|
|
10
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
11
|
+
index_1.Route.get('/hello', () => 'world');
|
|
12
|
+
const router = new index_1.Router();
|
|
13
|
+
const matched = router.match('GET', '/hello');
|
|
14
|
+
node_assert_1.default.ok(matched);
|
|
15
|
+
node_assert_1.default.strictEqual(matched.route.path, '/hello');
|
|
16
|
+
node_assert_1.default.strictEqual(matched.route.method, 'GET');
|
|
17
|
+
});
|
|
18
|
+
(0, node_test_1.test)('Router can handle groups with prefixes', async (t) => {
|
|
19
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
20
|
+
index_1.Route.group('/api', () => {
|
|
21
|
+
index_1.Route.get('/users', () => 'users');
|
|
22
|
+
});
|
|
23
|
+
const router = new index_1.Router();
|
|
24
|
+
const matched = router.match('GET', '/api/users');
|
|
25
|
+
node_assert_1.default.ok(matched);
|
|
26
|
+
node_assert_1.default.strictEqual(matched.route.path, '/api/users');
|
|
27
|
+
});
|
|
28
|
+
(0, node_test_1.test)('Router supports nested groups', async (t) => {
|
|
29
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
30
|
+
index_1.Route.group('/admin', () => {
|
|
31
|
+
index_1.Route.group('/users', () => {
|
|
32
|
+
index_1.Route.get('/list', () => 'admin-users-list');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
const router = new index_1.Router();
|
|
36
|
+
const matched = router.match('GET', '/admin/users/list');
|
|
37
|
+
node_assert_1.default.ok(matched);
|
|
38
|
+
node_assert_1.default.strictEqual(matched.route.path, '/admin/users/list');
|
|
39
|
+
});
|
|
40
|
+
(0, node_test_1.test)('Router can extract route parameters', async (t) => {
|
|
41
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
42
|
+
index_1.Route.get('/users/:id', (request, id) => id);
|
|
43
|
+
const router = new index_1.Router();
|
|
44
|
+
const matched = router.match('GET', '/users/123');
|
|
45
|
+
node_assert_1.default.ok(matched);
|
|
46
|
+
node_assert_1.default.strictEqual(matched.params.id, '123');
|
|
47
|
+
// Mock request
|
|
48
|
+
const mockRequest = {
|
|
49
|
+
method: () => 'GET',
|
|
50
|
+
path: () => '/users/123'
|
|
51
|
+
};
|
|
52
|
+
const mockResponse = {};
|
|
53
|
+
const result = await router.dispatch(mockRequest, mockResponse);
|
|
54
|
+
node_assert_1.default.strictEqual(result, '123');
|
|
55
|
+
});
|
|
56
|
+
(0, node_test_1.test)('Router supports group middleware', async (t) => {
|
|
57
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
58
|
+
const middleware1 = () => { };
|
|
59
|
+
const middleware2 = () => { };
|
|
60
|
+
index_1.Route.group({ prefix: '/api', middleware: [middleware1] }, () => {
|
|
61
|
+
index_1.Route.get('/users', () => 'users').withMiddleware(middleware2);
|
|
62
|
+
});
|
|
63
|
+
const router = new index_1.Router();
|
|
64
|
+
const matched = router.match('GET', '/api/users');
|
|
65
|
+
node_assert_1.default.ok(matched);
|
|
66
|
+
node_assert_1.default.strictEqual(matched.route.middleware.length, 2);
|
|
67
|
+
node_assert_1.default.strictEqual(matched.route.middleware[0], middleware1);
|
|
68
|
+
node_assert_1.default.strictEqual(matched.route.middleware[1], middleware2);
|
|
69
|
+
});
|
|
70
|
+
(0, node_test_1.test)('Router supports fluent chaining', async (t) => {
|
|
71
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
72
|
+
const route = index_1.Route.get('/fluent', () => 'ok')
|
|
73
|
+
.as('fluent.route')
|
|
74
|
+
.withMiddleware('some-middleware');
|
|
75
|
+
node_assert_1.default.strictEqual(route.name, 'fluent.route');
|
|
76
|
+
node_assert_1.default.strictEqual(route.middleware[0], 'some-middleware');
|
|
77
|
+
});
|
|
78
|
+
(0, node_test_1.test)('Router can dispatch routes', async (t) => {
|
|
79
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
80
|
+
index_1.Route.get('/hello', () => 'world');
|
|
81
|
+
const router = new index_1.Router();
|
|
82
|
+
// Mock request
|
|
83
|
+
const mockRequest = {
|
|
84
|
+
method: () => 'GET',
|
|
85
|
+
path: () => '/hello'
|
|
86
|
+
};
|
|
87
|
+
const mockResponse = {};
|
|
88
|
+
const result = await router.dispatch(mockRequest, mockResponse);
|
|
89
|
+
node_assert_1.default.strictEqual(result, 'world');
|
|
90
|
+
});
|
|
91
|
+
(0, node_test_1.test)('Router returns null if no match', async (t) => {
|
|
92
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
93
|
+
index_1.Route.get('/hello', () => 'world');
|
|
94
|
+
const router = new index_1.Router();
|
|
95
|
+
const mockRequest = {
|
|
96
|
+
method: () => 'GET',
|
|
97
|
+
path: () => '/not-found'
|
|
98
|
+
};
|
|
99
|
+
const mockResponse = {};
|
|
100
|
+
const result = await router.dispatch(mockRequest, mockResponse);
|
|
101
|
+
node_assert_1.default.strictEqual(result, null);
|
|
102
|
+
});
|
|
103
|
+
(0, node_test_1.test)('Router caches match results', async (t) => {
|
|
104
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
105
|
+
index_1.Route.get('/cache-test', () => 'ok');
|
|
106
|
+
let matchCount = 0;
|
|
107
|
+
const router = new index_1.Router();
|
|
108
|
+
// Patch the matcher to track calls
|
|
109
|
+
const matcher = router.matcher;
|
|
110
|
+
const originalMatch = matcher.match;
|
|
111
|
+
matcher.match = (...args) => {
|
|
112
|
+
matchCount++;
|
|
113
|
+
return originalMatch.apply(matcher, args);
|
|
114
|
+
};
|
|
115
|
+
router.match('GET', '/cache-test');
|
|
116
|
+
router.match('GET', '/cache-test');
|
|
117
|
+
const result = router.match('GET', '/cache-test');
|
|
118
|
+
node_assert_1.default.ok(result);
|
|
119
|
+
node_assert_1.default.strictEqual(matchCount, 1, 'Matcher should only be called once due to caching');
|
|
120
|
+
});
|
|
121
|
+
(0, node_test_1.test)('Router can clear cache', async (t) => {
|
|
122
|
+
index_1.RouteRegistry.getInstance().clear();
|
|
123
|
+
index_1.Route.get('/cache-test', () => 'ok');
|
|
124
|
+
let matchCount = 0;
|
|
125
|
+
const router = new index_1.Router();
|
|
126
|
+
const matcher = router.matcher;
|
|
127
|
+
const originalMatch = matcher.match;
|
|
128
|
+
matcher.match = (...args) => {
|
|
129
|
+
matchCount++;
|
|
130
|
+
return originalMatch.apply(matcher, args);
|
|
131
|
+
};
|
|
132
|
+
router.match('GET', '/cache-test');
|
|
133
|
+
router.clearCache();
|
|
134
|
+
router.match('GET', '/cache-test');
|
|
135
|
+
node_assert_1.default.strictEqual(matchCount, 2, 'Matcher should be called twice because cache was cleared');
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=Router.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.test.js","sourceRoot":"","sources":["../../src/tests/Router.test.ts"],"names":[],"mappings":";;;;;AAAA,yCAAiC;AACjC,8DAAiC;AACjC,oCAAwD;AAGxD,IAAA,gBAAI,EAAC,sCAAsC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IACrD,qBAAa,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,CAAC;IAEpC,aAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;IAEnC,MAAM,MAAM,GAAG,IAAI,cAAM,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAE9C,qBAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IACnB,qBAA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ACxC,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC;IACpC,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;QAC/B,UAAU,EAAE,CAAC;QACb,OAAO,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACnC,MAAM,CAAC,UAAU,EAAE,CAAC;IACpB,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAEnC,qBAAM,CAAC,WAAW,CAAC,UAAU,EAAE,CAAC,EAAE,0DAA0D,CAAC,CAAC;AAClG,CAAC,CAAC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type RouteHandler = any;
|
|
2
|
+
export interface RouteDefinition {
|
|
3
|
+
method: string;
|
|
4
|
+
path: string;
|
|
5
|
+
handler: RouteHandler;
|
|
6
|
+
name?: string;
|
|
7
|
+
prefix?: string;
|
|
8
|
+
middleware: any[];
|
|
9
|
+
regex?: RegExp;
|
|
10
|
+
paramKeys?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface MatchedRoute {
|
|
13
|
+
route: RouteDefinition;
|
|
14
|
+
params: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export interface Container {
|
|
17
|
+
make<T>(token: any): T;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC;AAE/B,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,eAAe,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,SAAS;IACtB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC;CAC1B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@arikajs/router",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Routing and request-dispatching layer of the ArikaJS framework.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc -p tsconfig.json",
|
|
10
|
+
"clean": "rm -rf dist",
|
|
11
|
+
"prepare": "echo skip",
|
|
12
|
+
"lint": "eslint src --ext .ts",
|
|
13
|
+
"test": "npx tsx --test tests/**/*.test.ts",
|
|
14
|
+
"test:watch": "npx tsx --test --watch tests/**/*.test.ts"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"arika",
|
|
21
|
+
"arika-js",
|
|
22
|
+
"framework",
|
|
23
|
+
"router",
|
|
24
|
+
"routing",
|
|
25
|
+
"dispatcher"
|
|
26
|
+
],
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20.0.0"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/arikajs/router.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/arikajs/router/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/arikajs/router#readme",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@arikajs/http": "^0.0.1",
|
|
40
|
+
"@arikajs/dispatcher": "^0.0.1"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^20.11.24",
|
|
44
|
+
"typescript": "^5.3.3"
|
|
45
|
+
},
|
|
46
|
+
"author": "Prakash Tank"
|
|
47
|
+
}
|