@lerianstudio/sindarian-server 1.0.0 → 1.1.0
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 +268 -21
- package/dist/constants/keys.d.ts +2 -0
- package/dist/constants/keys.d.ts.map +1 -1
- package/dist/constants/keys.js +3 -1
- package/dist/constants/keys.js.map +1 -1
- package/dist/controllers/decorators/route-decorator.d.ts +4 -0
- package/dist/controllers/decorators/route-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/route-decorator.js +7 -0
- package/dist/controllers/decorators/route-decorator.js.map +1 -1
- package/dist/dependency-injection/container.d.ts +4 -3
- package/dist/dependency-injection/container.d.ts.map +1 -1
- package/dist/dependency-injection/container.js +14 -3
- package/dist/dependency-injection/container.js.map +1 -1
- package/dist/dependency-injection/injectable-decorator.d.ts +5 -0
- package/dist/dependency-injection/injectable-decorator.d.ts.map +1 -1
- package/dist/dependency-injection/injectable-decorator.js +9 -0
- package/dist/dependency-injection/injectable-decorator.js.map +1 -1
- package/dist/guards/can-activate.d.ts +21 -0
- package/dist/guards/can-activate.d.ts.map +1 -0
- package/dist/guards/can-activate.js +3 -0
- package/dist/guards/can-activate.js.map +1 -0
- package/dist/guards/decorators/index.d.ts +2 -0
- package/dist/guards/decorators/index.d.ts.map +1 -0
- package/dist/guards/decorators/index.js +18 -0
- package/dist/guards/decorators/index.js.map +1 -0
- package/dist/guards/decorators/use-guards-decorator.d.ts +44 -0
- package/dist/guards/decorators/use-guards-decorator.d.ts.map +1 -0
- package/dist/guards/decorators/use-guards-decorator.js +127 -0
- package/dist/guards/decorators/use-guards-decorator.js.map +1 -0
- package/dist/guards/index.d.ts +3 -0
- package/dist/guards/index.d.ts.map +1 -0
- package/dist/guards/index.js +19 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/interceptor/decorators/use-interceptor-decorator.d.ts.map +1 -1
- package/dist/interceptor/decorators/use-interceptor-decorator.js +4 -12
- package/dist/interceptor/decorators/use-interceptor-decorator.js.map +1 -1
- package/dist/logger/console-logger.d.ts.map +1 -1
- package/dist/logger/console-logger.js +6 -0
- package/dist/logger/console-logger.js.map +1 -1
- package/dist/middleware/index.d.ts +3 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +19 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/middleware-handler.d.ts +6 -0
- package/dist/middleware/middleware-handler.d.ts.map +1 -0
- package/dist/middleware/middleware-handler.js +19 -0
- package/dist/middleware/middleware-handler.js.map +1 -0
- package/dist/middleware/middleware.d.ts +6 -0
- package/dist/middleware/middleware.d.ts.map +1 -0
- package/dist/middleware/middleware.js +7 -0
- package/dist/middleware/middleware.js.map +1 -0
- package/dist/modules/module-decorator.d.ts.map +1 -1
- package/dist/modules/module-decorator.js +27 -1
- package/dist/modules/module-decorator.js.map +1 -1
- package/dist/pipes/decorators/use-pipes.js +1 -1
- package/dist/pipes/decorators/use-pipes.js.map +1 -1
- package/dist/server/server-factory.d.ts +38 -1
- package/dist/server/server-factory.d.ts.map +1 -1
- package/dist/server/server-factory.js +129 -14
- package/dist/server/server-factory.js.map +1 -1
- package/dist/services/guards.d.ts +2 -0
- package/dist/services/guards.d.ts.map +1 -0
- package/dist/services/guards.js +5 -0
- package/dist/services/guards.js.map +1 -0
- package/dist/services/middleware.d.ts +2 -0
- package/dist/services/middleware.d.ts.map +1 -0
- package/dist/services/middleware.js +5 -0
- package/dist/services/middleware.js.map +1 -0
- package/dist/utils/routes/route-specificity.d.ts +40 -0
- package/dist/utils/routes/route-specificity.d.ts.map +1 -0
- package/dist/utils/routes/route-specificity.js +89 -0
- package/dist/utils/routes/route-specificity.js.map +1 -0
- package/dist/utils/url/url-match.d.ts.map +1 -1
- package/dist/utils/url/url-match.js +16 -2
- package/dist/utils/url/url-match.js.map +1 -1
- package/package.json +2 -3
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { Container } from '../dependency-injection/container';
|
|
2
2
|
import { ExceptionFilter } from '../exceptions/exception-filter';
|
|
3
|
+
import { CanActivate } from '../guards';
|
|
3
4
|
import { Interceptor } from '../interceptor/interceptor';
|
|
4
5
|
import { ModuleMetadata } from '../modules/module-decorator';
|
|
5
6
|
import { Class } from '../types/class';
|
|
6
7
|
import { NextRequest } from 'next/server';
|
|
7
8
|
import { LoggerService } from '../logger/logger-service';
|
|
8
9
|
import { PipeTransform } from '../pipes/pipe-transform';
|
|
10
|
+
import { GetOptions, OptionalGetOptions } from 'inversify';
|
|
11
|
+
import { Middleware } from '../middleware/middleware';
|
|
9
12
|
export type ServerFactoryOptions = {
|
|
10
13
|
logger?: LoggerService | boolean;
|
|
11
14
|
};
|
|
12
15
|
export declare class ServerFactory {
|
|
13
16
|
private globalPrefix;
|
|
14
17
|
private globalFilters;
|
|
18
|
+
private globalGuards;
|
|
15
19
|
private globalInterceptors;
|
|
16
20
|
private globalPipes;
|
|
21
|
+
private globalMiddlewares;
|
|
17
22
|
private readonly module;
|
|
18
23
|
private readonly container;
|
|
19
24
|
private readonly routes;
|
|
@@ -25,8 +30,24 @@ export declare class ServerFactory {
|
|
|
25
30
|
*/
|
|
26
31
|
setGlobalPrefix(prefix: string): void;
|
|
27
32
|
useGlobalFilters(...filters: ExceptionFilter[]): void;
|
|
33
|
+
useGlobalGuards(...guards: CanActivate[]): void;
|
|
28
34
|
useGlobalInterceptors(...interceptors: Interceptor[]): void;
|
|
29
35
|
useGlobalPipes(...pipes: PipeTransform[]): void;
|
|
36
|
+
useGlobalMiddleware(...middlewares: Middleware[]): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get a service synchronously
|
|
39
|
+
* @param service - The service to get
|
|
40
|
+
* @param options - The options for getting the service
|
|
41
|
+
* @returns The service instance
|
|
42
|
+
*/
|
|
43
|
+
get<T>(service: Class<T>, options?: OptionalGetOptions): T;
|
|
44
|
+
/**
|
|
45
|
+
* Get a service asynchronously
|
|
46
|
+
* @param service - The service to get
|
|
47
|
+
* @param options - The options for getting the service
|
|
48
|
+
* @returns A promise that resolves to the service instance
|
|
49
|
+
*/
|
|
50
|
+
getAsync<T>(service: Class<T>, options?: GetOptions): Promise<T>;
|
|
30
51
|
/**
|
|
31
52
|
* Handle a request
|
|
32
53
|
* @param request - The request to handle
|
|
@@ -35,7 +56,11 @@ export declare class ServerFactory {
|
|
|
35
56
|
*/
|
|
36
57
|
handler(request: NextRequest, { params }: {
|
|
37
58
|
params: Promise<any>;
|
|
38
|
-
}): Promise<
|
|
59
|
+
}): Promise<Response>;
|
|
60
|
+
/**
|
|
61
|
+
* Core request handling pipeline: guards -> interceptors -> handler -> exception filters
|
|
62
|
+
*/
|
|
63
|
+
private _handleRequest;
|
|
39
64
|
private static _registerLogger;
|
|
40
65
|
/**
|
|
41
66
|
* Parse the request
|
|
@@ -50,9 +75,21 @@ export declare class ServerFactory {
|
|
|
50
75
|
* @returns The route
|
|
51
76
|
*/
|
|
52
77
|
private _fetchRoute;
|
|
78
|
+
/**
|
|
79
|
+
* Fetch guards for a controller method
|
|
80
|
+
* @param controller - The controller instance
|
|
81
|
+
* @param methodName - The method name
|
|
82
|
+
* @returns Array of guard instances
|
|
83
|
+
*/
|
|
84
|
+
private _fetchGuards;
|
|
53
85
|
private _fetchInterceptors;
|
|
54
86
|
private _fetchHandler;
|
|
55
87
|
private _fetchExceptionFilters;
|
|
88
|
+
/**
|
|
89
|
+
* Fetch all middleware: explicit globals + APP_MIDDLEWARE container bindings
|
|
90
|
+
* Execution order: first registered = outermost
|
|
91
|
+
*/
|
|
92
|
+
private _fetchMiddlewares;
|
|
56
93
|
/**
|
|
57
94
|
* Fetch the pipes for a controller method
|
|
58
95
|
* @param controller
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-factory.d.ts","sourceRoot":"","sources":["../../src/server/server-factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,E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M,EAAE,cAAc,EAAE;WAQ3D,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,oBAAoB;IAgBlE;;;OAGG;IACI,eAAe,CAAC,MAAM,EAAE,MAAM;IAI9B,gBAAgB,CAAC,GAAG,OAAO,EAAE,eAAe,EAAE;IAI9C,eAAe,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE;IAIxC,qBAAqB,CAAC,GAAG,YAAY,EAAE,WAAW,EAAE;IAIpD,cAAc,CAAC,GAAG,KAAK,EAAE,aAAa,EAAE;IAIxC,mBAAmB,CAAC,GAAG,WAAW,EAAE,UAAU,EAAE;IAIvD;;;;;OAKG;IACI,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,CAAC;IAIjE;;;;;OAKG;IACI,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC;IAIvE;;;;;OAKG;IACU,OAAO,CAClB,OAAO,EAAE,WAAW,EACpB,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;KAAE;IAYtC;;OAEG;YACW,cAAc;IAmG5B,OAAO,CAAC,MAAM,CAAC,eAAe;IAM9B;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAoBrB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAiBnB;;;;;OAKG;YACW,YAAY;YA0BZ,kBAAkB;IAwBhC,OAAO,CAAC,aAAa;YAiBP,sBAAsB;IAqBpC;;;OAGG;YACW,iBAAiB;IAgB/B;;;;;OAKG;YACW,WAAW;CAyB1B"}
|
|
@@ -8,9 +8,11 @@ const container_1 = require("../dependency-injection/container");
|
|
|
8
8
|
const base_exception_filter_1 = require("../exceptions/base-exception-filter");
|
|
9
9
|
const catch_decorator_1 = require("../exceptions/decorators/catch-decorator");
|
|
10
10
|
const use_filters_decorator_1 = require("../exceptions/decorators/use-filters-decorator");
|
|
11
|
+
const guards_1 = require("../guards");
|
|
11
12
|
const use_interceptor_decorator_1 = require("../interceptor/decorators/use-interceptor-decorator");
|
|
12
13
|
const module_decorator_1 = require("../modules/module-decorator");
|
|
13
14
|
const filters_1 = require("../services/filters");
|
|
15
|
+
const guards_2 = require("../services/guards");
|
|
14
16
|
const interceptor_1 = require("../services/interceptor");
|
|
15
17
|
const request_1 = require("../services/request");
|
|
16
18
|
const url_match_1 = require("../utils/url/url-match");
|
|
@@ -21,12 +23,17 @@ const lodash_1 = require("lodash");
|
|
|
21
23
|
const pipes_1 = require("../services/pipes");
|
|
22
24
|
const use_pipes_1 = require("../pipes/decorators/use-pipes");
|
|
23
25
|
const route_decorator_1 = require("../controllers/decorators/route-decorator");
|
|
26
|
+
const route_specificity_1 = require("../utils/routes/route-specificity");
|
|
27
|
+
const middleware_handler_1 = require("../middleware/middleware-handler");
|
|
28
|
+
const middleware_1 = require("../services/middleware");
|
|
24
29
|
class ServerFactory {
|
|
25
30
|
constructor(module, container, routes) {
|
|
26
31
|
this.globalPrefix = '';
|
|
27
32
|
this.globalFilters = [new base_exception_filter_1.BaseExceptionFilter()];
|
|
33
|
+
this.globalGuards = [];
|
|
28
34
|
this.globalInterceptors = [];
|
|
29
35
|
this.globalPipes = [];
|
|
36
|
+
this.globalMiddlewares = [];
|
|
30
37
|
this.module = module;
|
|
31
38
|
this.container = container;
|
|
32
39
|
this.routes = routes;
|
|
@@ -37,7 +44,10 @@ class ServerFactory {
|
|
|
37
44
|
this._registerLogger(options?.logger);
|
|
38
45
|
container.load(module.prototype[keys_1.MODULE_PROPERTY]);
|
|
39
46
|
const routes = (0, module_decorator_1.moduleHandler)(module);
|
|
40
|
-
|
|
47
|
+
// Sort routes by specificity (most specific first)
|
|
48
|
+
// This ensures routes like /users/active match before /users/:id
|
|
49
|
+
const sortedRoutes = (0, route_specificity_1.sortRoutesBySpecificity)(routes);
|
|
50
|
+
return new ServerFactory(module, container, sortedRoutes);
|
|
41
51
|
}
|
|
42
52
|
/**
|
|
43
53
|
* Set the global prefix for the server
|
|
@@ -49,12 +59,36 @@ class ServerFactory {
|
|
|
49
59
|
useGlobalFilters(...filters) {
|
|
50
60
|
this.globalFilters.push(...filters);
|
|
51
61
|
}
|
|
62
|
+
useGlobalGuards(...guards) {
|
|
63
|
+
this.globalGuards.push(...guards);
|
|
64
|
+
}
|
|
52
65
|
useGlobalInterceptors(...interceptors) {
|
|
53
66
|
this.globalInterceptors.push(...interceptors);
|
|
54
67
|
}
|
|
55
68
|
useGlobalPipes(...pipes) {
|
|
56
69
|
this.globalPipes.push(...pipes);
|
|
57
70
|
}
|
|
71
|
+
useGlobalMiddleware(...middlewares) {
|
|
72
|
+
this.globalMiddlewares.push(...middlewares);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get a service synchronously
|
|
76
|
+
* @param service - The service to get
|
|
77
|
+
* @param options - The options for getting the service
|
|
78
|
+
* @returns The service instance
|
|
79
|
+
*/
|
|
80
|
+
get(service, options) {
|
|
81
|
+
return this.container.get(service, options);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Get a service asynchronously
|
|
85
|
+
* @param service - The service to get
|
|
86
|
+
* @param options - The options for getting the service
|
|
87
|
+
* @returns A promise that resolves to the service instance
|
|
88
|
+
*/
|
|
89
|
+
getAsync(service, options) {
|
|
90
|
+
return this.container.getAsync(service, options);
|
|
91
|
+
}
|
|
58
92
|
/**
|
|
59
93
|
* Handle a request
|
|
60
94
|
* @param request - The request to handle
|
|
@@ -62,6 +96,14 @@ class ServerFactory {
|
|
|
62
96
|
* @returns The response from the handler
|
|
63
97
|
*/
|
|
64
98
|
async handler(request, { params }) {
|
|
99
|
+
// Resolve middleware chain: explicit globals + APP_MIDDLEWARE container bindings
|
|
100
|
+
const middlewares = await this._fetchMiddlewares();
|
|
101
|
+
return middleware_handler_1.MiddlewareHandler.execute(request, middlewares, () => this._handleRequest(request, params));
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Core request handling pipeline: guards -> interceptors -> handler -> exception filters
|
|
105
|
+
*/
|
|
106
|
+
async _handleRequest(request, params) {
|
|
65
107
|
const host = new arguments_host_1.ArgumentsHost([request]);
|
|
66
108
|
let controller;
|
|
67
109
|
try {
|
|
@@ -72,6 +114,10 @@ class ServerFactory {
|
|
|
72
114
|
controller = await this.container.getAsync(match?.controller);
|
|
73
115
|
const handler = this._fetchHandler(controller, match?.methodName);
|
|
74
116
|
const executionContext = new execution_context_1.ExecutionContext(controller.constructor, handler, [request]);
|
|
117
|
+
// Check if there's any guards to execute
|
|
118
|
+
const guards = await this._fetchGuards(controller, match?.methodName);
|
|
119
|
+
// Execute guards - throws ForbiddenApiException if any guard returns false
|
|
120
|
+
await guards_1.GuardHandler.execute(executionContext, guards);
|
|
75
121
|
// Check if there's any interceptors to execute
|
|
76
122
|
const interceptors = await this._fetchInterceptors(controller);
|
|
77
123
|
// Check if there's any pipes to execute
|
|
@@ -94,6 +140,11 @@ class ServerFactory {
|
|
|
94
140
|
// Check if any specific type is registered, if none, it's a catch all filter
|
|
95
141
|
if (!type || error instanceof type) {
|
|
96
142
|
const response = await filter.catch(error, host);
|
|
143
|
+
// Add validation
|
|
144
|
+
if (response && !(response instanceof Response)) {
|
|
145
|
+
logger_1.Logger.error(`ExceptionFilter ${filter.constructor.name} returned invalid response type: ${response?.constructor?.name}`);
|
|
146
|
+
return server_1.NextResponse.json({ message: 'Internal server error' }, { status: 500 });
|
|
147
|
+
}
|
|
97
148
|
// If a response is returned from the filter, use it
|
|
98
149
|
if (response) {
|
|
99
150
|
return response;
|
|
@@ -115,7 +166,15 @@ class ServerFactory {
|
|
|
115
166
|
*/
|
|
116
167
|
_parseRequest(request) {
|
|
117
168
|
const { pathname } = new URL(request.url);
|
|
118
|
-
|
|
169
|
+
// Strip the global prefix from the pathname
|
|
170
|
+
let strippedPathname = pathname;
|
|
171
|
+
if (this.globalPrefix && pathname.startsWith(this.globalPrefix)) {
|
|
172
|
+
strippedPathname = pathname.slice(this.globalPrefix.length);
|
|
173
|
+
}
|
|
174
|
+
// Ensure pathname starts with / after stripping prefix
|
|
175
|
+
if (!strippedPathname.startsWith('/')) {
|
|
176
|
+
strippedPathname = '/' + strippedPathname;
|
|
177
|
+
}
|
|
119
178
|
return {
|
|
120
179
|
pathname: strippedPathname,
|
|
121
180
|
method: request.method.toUpperCase()
|
|
@@ -140,12 +199,41 @@ class ServerFactory {
|
|
|
140
199
|
}
|
|
141
200
|
return route;
|
|
142
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Fetch guards for a controller method
|
|
204
|
+
* @param controller - The controller instance
|
|
205
|
+
* @param methodName - The method name
|
|
206
|
+
* @returns Array of guard instances
|
|
207
|
+
*/
|
|
208
|
+
async _fetchGuards(controller, methodName) {
|
|
209
|
+
const guards = [...this.globalGuards];
|
|
210
|
+
// Fetch all registered global guards
|
|
211
|
+
try {
|
|
212
|
+
const appGuards = await this.container.getAllAsync(guards_2.APP_GUARD);
|
|
213
|
+
if (appGuards.length > 0) {
|
|
214
|
+
guards.push(...appGuards);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
// No bindings found or error retrieving - continue without APP_GUARD providers
|
|
219
|
+
}
|
|
220
|
+
// Fetch controller and method guards
|
|
221
|
+
if (controller) {
|
|
222
|
+
guards.push(...(await guards_1.GuardHandler.fetch(this.container, controller, methodName)));
|
|
223
|
+
}
|
|
224
|
+
return guards;
|
|
225
|
+
}
|
|
143
226
|
async _fetchInterceptors(controller) {
|
|
144
227
|
const interceptors = [...this.globalInterceptors];
|
|
145
|
-
// Fetch
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
228
|
+
// Fetch all registered global interceptors
|
|
229
|
+
try {
|
|
230
|
+
const appInterceptors = await this.container.getAllAsync(interceptor_1.APP_INTERCEPTOR);
|
|
231
|
+
if (appInterceptors.length > 0) {
|
|
232
|
+
interceptors.push(...appInterceptors);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
// No bindings found or error retrieving - continue without APP_INTERCEPTOR providers
|
|
149
237
|
}
|
|
150
238
|
if (controller) {
|
|
151
239
|
// Fetch controller interceptors
|
|
@@ -163,16 +251,38 @@ class ServerFactory {
|
|
|
163
251
|
}
|
|
164
252
|
async _fetchExceptionFilters(controller) {
|
|
165
253
|
const filters = [...this.globalFilters];
|
|
166
|
-
// Fetch
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
254
|
+
// Fetch all registered global filters
|
|
255
|
+
try {
|
|
256
|
+
const appFilters = await this.container.getAllAsync(filters_1.APP_FILTER);
|
|
257
|
+
if (appFilters.length > 0) {
|
|
258
|
+
filters.push(...appFilters);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
// No bindings found or error retrieving - continue without APP_FILTER providers
|
|
170
263
|
}
|
|
171
264
|
if (controller) {
|
|
172
265
|
filters.push(...(await use_filters_decorator_1.FilterHandler.fetch(this.container, controller)));
|
|
173
266
|
}
|
|
174
267
|
return filters.reverse();
|
|
175
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Fetch all middleware: explicit globals + APP_MIDDLEWARE container bindings
|
|
271
|
+
* Execution order: first registered = outermost
|
|
272
|
+
*/
|
|
273
|
+
async _fetchMiddlewares() {
|
|
274
|
+
const middlewares = [...this.globalMiddlewares];
|
|
275
|
+
try {
|
|
276
|
+
const appMiddlewares = await this.container.getAllAsync(middleware_1.APP_MIDDLEWARE);
|
|
277
|
+
if (appMiddlewares.length > 0) {
|
|
278
|
+
middlewares.push(...appMiddlewares);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
// No bindings found - continue without APP_MIDDLEWARE providers
|
|
283
|
+
}
|
|
284
|
+
return middlewares;
|
|
285
|
+
}
|
|
176
286
|
/**
|
|
177
287
|
* Fetch the pipes for a controller method
|
|
178
288
|
* @param controller
|
|
@@ -181,10 +291,15 @@ class ServerFactory {
|
|
|
181
291
|
*/
|
|
182
292
|
async _fetchPipes(controller, methodName) {
|
|
183
293
|
const pipes = [...this.globalPipes];
|
|
184
|
-
// Fetch
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
294
|
+
// Fetch all registered global pipes
|
|
295
|
+
try {
|
|
296
|
+
const appPipes = await this.container.getAllAsync(pipes_1.APP_PIPE);
|
|
297
|
+
if (appPipes.length > 0) {
|
|
298
|
+
pipes.push(...appPipes);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
// No bindings found or error retrieving - continue without APP_PIPE providers
|
|
188
303
|
}
|
|
189
304
|
// Fetch controller pipes
|
|
190
305
|
if (controller) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-factory.js","sourceRoot":"","sources":["../../src/server/server-factory.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AACxD,mEAA8D;AAC9D,2CAAkD;AAElD,gEAA4D;AAC5D,8EAAwE;AACxE,6EAAsE;AACtE,yFAA6E;AAE7E,kGAAuF;AAEvF,iEAA0E;AAC1E,gDAA+C;AAC/C,wDAAwD;AACxD,gDAAgD;AAEhD,qDAAgD;AAChD,wCAAuD;AAEvD,4CAAwC;AACxC,8DAAiE;AACjE,mCAA8B;AAE9B,4CAA2C;AAC3C,4DAA0D;AAC1D,8EAAuE;
|
|
1
|
+
{"version":3,"file":"server-factory.js","sourceRoot":"","sources":["../../src/server/server-factory.ts"],"names":[],"mappings":";;;AAAA,6DAAwD;AACxD,mEAA8D;AAC9D,2CAAkD;AAElD,gEAA4D;AAC5D,8EAAwE;AACxE,6EAAsE;AACtE,yFAA6E;AAE7E,qCAAoD;AACpD,kGAAuF;AAEvF,iEAA0E;AAC1E,gDAA+C;AAC/C,8CAA6C;AAC7C,wDAAwD;AACxD,gDAAgD;A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AC,OAAO,EAAE,CAAA;IACxB,CAAC;CACF;AArZD,sCAqZC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/services/guards.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,eAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/services/guards.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/services/middleware.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,eAA2B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/services/middleware.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ModuleMetadata } from '../../modules/module-decorator';
|
|
2
|
+
/**
|
|
3
|
+
* Sort routes by specificity (most specific first)
|
|
4
|
+
* Routes with more static segments come before routes with parameters
|
|
5
|
+
* This matches NestJS behavior to ensure routes like:
|
|
6
|
+
* - GET /organizations/:id/ledgers/with-assets (more specific)
|
|
7
|
+
* - GET /organizations/:id/ledgers/:ledgerId (less specific)
|
|
8
|
+
* are matched in the correct order
|
|
9
|
+
*
|
|
10
|
+
* @param routes - Array of route metadata to sort
|
|
11
|
+
* @returns Sorted array with most specific routes first
|
|
12
|
+
*/
|
|
13
|
+
export declare function sortRoutesBySpecificity(routes: ModuleMetadata[]): ModuleMetadata[];
|
|
14
|
+
/**
|
|
15
|
+
* Calculate specificity score for a route path
|
|
16
|
+
* Higher score = more specific route
|
|
17
|
+
*
|
|
18
|
+
* This algorithm is based on the route-sort library by Luke Edwards
|
|
19
|
+
* https://github.com/lukeed/route-sort
|
|
20
|
+
*
|
|
21
|
+
* Segment Values (lower = more specific):
|
|
22
|
+
* - Static segment: 1
|
|
23
|
+
* - Parameter (:id): 111
|
|
24
|
+
* - Parameter with suffix (:id.format): 11
|
|
25
|
+
* - Optional parameter (:id?): 1111
|
|
26
|
+
* - Wildcard (*): 100000000000 (1e11)
|
|
27
|
+
*
|
|
28
|
+
* Rank = (segment_count - 1) / sum_of_segment_values
|
|
29
|
+
* Higher rank = more specific route
|
|
30
|
+
*
|
|
31
|
+
* Examples:
|
|
32
|
+
* - /users/active (2 static) = 1 / 2 = 0.5
|
|
33
|
+
* - /users/:id (1 static + 1 param) = 1 / 112 = ~0.0089
|
|
34
|
+
* - /users/* (1 static + 1 wildcard) = 1 / 100000000001 = ~1e-11
|
|
35
|
+
*
|
|
36
|
+
* @param path - The route path to score
|
|
37
|
+
* @returns Specificity score (higher = more specific)
|
|
38
|
+
*/
|
|
39
|
+
export declare function calculateRouteSpecificity(path: string): number;
|
|
40
|
+
//# sourceMappingURL=route-specificity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-specificity.d.ts","sourceRoot":"","sources":["../../../src/utils/routes/route-specificity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAE3D;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,cAAc,EAAE,GACvB,cAAc,EAAE,CAMlB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiB9D"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortRoutesBySpecificity = sortRoutesBySpecificity;
|
|
4
|
+
exports.calculateRouteSpecificity = calculateRouteSpecificity;
|
|
5
|
+
/**
|
|
6
|
+
* Sort routes by specificity (most specific first)
|
|
7
|
+
* Routes with more static segments come before routes with parameters
|
|
8
|
+
* This matches NestJS behavior to ensure routes like:
|
|
9
|
+
* - GET /organizations/:id/ledgers/with-assets (more specific)
|
|
10
|
+
* - GET /organizations/:id/ledgers/:ledgerId (less specific)
|
|
11
|
+
* are matched in the correct order
|
|
12
|
+
*
|
|
13
|
+
* @param routes - Array of route metadata to sort
|
|
14
|
+
* @returns Sorted array with most specific routes first
|
|
15
|
+
*/
|
|
16
|
+
function sortRoutesBySpecificity(routes) {
|
|
17
|
+
return [...routes].sort((a, b) => {
|
|
18
|
+
const aScore = calculateRouteSpecificity(a.path);
|
|
19
|
+
const bScore = calculateRouteSpecificity(b.path);
|
|
20
|
+
return bScore - aScore; // Higher score = more specific = comes first
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Calculate specificity score for a route path
|
|
25
|
+
* Higher score = more specific route
|
|
26
|
+
*
|
|
27
|
+
* This algorithm is based on the route-sort library by Luke Edwards
|
|
28
|
+
* https://github.com/lukeed/route-sort
|
|
29
|
+
*
|
|
30
|
+
* Segment Values (lower = more specific):
|
|
31
|
+
* - Static segment: 1
|
|
32
|
+
* - Parameter (:id): 111
|
|
33
|
+
* - Parameter with suffix (:id.format): 11
|
|
34
|
+
* - Optional parameter (:id?): 1111
|
|
35
|
+
* - Wildcard (*): 100000000000 (1e11)
|
|
36
|
+
*
|
|
37
|
+
* Rank = (segment_count - 1) / sum_of_segment_values
|
|
38
|
+
* Higher rank = more specific route
|
|
39
|
+
*
|
|
40
|
+
* Examples:
|
|
41
|
+
* - /users/active (2 static) = 1 / 2 = 0.5
|
|
42
|
+
* - /users/:id (1 static + 1 param) = 1 / 112 = ~0.0089
|
|
43
|
+
* - /users/* (1 static + 1 wildcard) = 1 / 100000000001 = ~1e-11
|
|
44
|
+
*
|
|
45
|
+
* @param path - The route path to score
|
|
46
|
+
* @returns Specificity score (higher = more specific)
|
|
47
|
+
*/
|
|
48
|
+
function calculateRouteSpecificity(path) {
|
|
49
|
+
const segments = path.split('/').filter((s) => s.length > 0);
|
|
50
|
+
if (segments.length === 0) {
|
|
51
|
+
// Root path is treated as a static route
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
let totalValue = 0;
|
|
55
|
+
for (const segment of segments) {
|
|
56
|
+
totalValue += getSegmentValue(segment);
|
|
57
|
+
}
|
|
58
|
+
// Calculate rank: (segment_count - 1) / total_value
|
|
59
|
+
// Higher rank = more specific
|
|
60
|
+
return (segments.length - 1) / totalValue;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get numeric value for a route segment
|
|
64
|
+
* Lower value = more specific
|
|
65
|
+
*
|
|
66
|
+
* @param segment - Route segment to evaluate
|
|
67
|
+
* @returns Numeric value representing specificity
|
|
68
|
+
*/
|
|
69
|
+
function getSegmentValue(segment) {
|
|
70
|
+
// Wildcard
|
|
71
|
+
if (segment === '*') {
|
|
72
|
+
return 1e11;
|
|
73
|
+
}
|
|
74
|
+
// Optional parameter (:id?)
|
|
75
|
+
if (/^:.*\?$/.test(segment)) {
|
|
76
|
+
return 1111;
|
|
77
|
+
}
|
|
78
|
+
// Parameter with suffix (:id.format)
|
|
79
|
+
if (/^:.*\./.test(segment)) {
|
|
80
|
+
return 11;
|
|
81
|
+
}
|
|
82
|
+
// Regular parameter (:id)
|
|
83
|
+
if (segment.startsWith(':')) {
|
|
84
|
+
return 111;
|
|
85
|
+
}
|
|
86
|
+
// Static segment
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=route-specificity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-specificity.js","sourceRoot":"","sources":["../../../src/utils/routes/route-specificity.ts"],"names":[],"mappings":";;AAaA,0DAQC;AA2BD,8DAiBC;AA/DD;;;;;;;;;;GAUG;AACH,SAAgB,uBAAuB,CACr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AC;QAC3B,OAAO,EAAE,CAAA;IACX,CAAC;IAED,0BAA0B;IAC1B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,iBAAiB;IACjB,OAAO,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-match.d.ts","sourceRoot":"","sources":["../../../src/utils/url/url-match.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"url-match.d.ts","sourceRoot":"","sources":["../../../src/utils/url/url-match.ts"],"names":[],"mappings":"AAcA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,WAOvD"}
|
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.urlMatch = urlMatch;
|
|
4
4
|
const path_to_regexp_1 = require("path-to-regexp");
|
|
5
|
+
/**
|
|
6
|
+
* Normalize a path by removing trailing slashes (except for root path)
|
|
7
|
+
* @param path - The path to normalize
|
|
8
|
+
* @returns The normalized path
|
|
9
|
+
*/
|
|
10
|
+
function normalizePath(path) {
|
|
11
|
+
if (path === '/' || path === '') {
|
|
12
|
+
return path;
|
|
13
|
+
}
|
|
14
|
+
return path.endsWith('/') ? path.slice(0, -1) : path;
|
|
15
|
+
}
|
|
5
16
|
/**
|
|
6
17
|
* Check if a pathname matches a route
|
|
7
18
|
* @param pathname - The pathname to check
|
|
@@ -9,7 +20,10 @@ const path_to_regexp_1 = require("path-to-regexp");
|
|
|
9
20
|
* @returns True if the pathname matches the route, false otherwise
|
|
10
21
|
*/
|
|
11
22
|
function urlMatch(pathname, route) {
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
// Normalize both paths to handle Next.js trailingSlash configuration
|
|
24
|
+
const normalizedPathname = normalizePath(pathname);
|
|
25
|
+
const normalizedRoute = normalizePath(route);
|
|
26
|
+
const { regexp } = (0, path_to_regexp_1.pathToRegexp)(normalizedRoute);
|
|
27
|
+
return regexp.test(normalizedPathname);
|
|
14
28
|
}
|
|
15
29
|
//# sourceMappingURL=url-match.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url-match.js","sourceRoot":"","sources":["../../../src/utils/url/url-match.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"url-match.js","sourceRoot":"","sources":["../../../src/utils/url/url-match.ts"],"names":[],"mappings":";;AAoBA,4BAOC;AA3BD,mDAA6C;AAE7C;;;;GAIG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChC,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACtD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,QAAgB,EAAE,KAAa;IACtD,qEAAqE;IACrE,MAAM,kBAAkB,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IAClD,MAAM,eAAe,GAAG,aAAa,CAAC,KAAK,CAAC,CAAA;IAE5C,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,6BAAY,EAAC,eAAe,CAAC,CAAA;IAChD,OAAO,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;AACxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lerianstudio/sindarian-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Sindarian Server",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/LerianStudio/console-sdk.git",
|
|
13
|
+
"url": "git+https://github.com/LerianStudio/console-sdk.git",
|
|
14
14
|
"directory": "packages/sindarian-server"
|
|
15
15
|
},
|
|
16
16
|
"type": "commonjs",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"lint:check": "eslint ."
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@lerianstudio/lib-logs": ">=1.1.0",
|
|
36
35
|
"path-to-regexp": "^8.3.0"
|
|
37
36
|
},
|
|
38
37
|
"peerDependencies": {
|