@lerianstudio/sindarian-server 1.0.0-beta.9 → 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 +3 -0
- package/dist/constants/keys.d.ts.map +1 -1
- package/dist/constants/keys.js +4 -1
- package/dist/constants/keys.js.map +1 -1
- package/dist/controllers/decorators/body-decorator.d.ts +12 -16
- package/dist/controllers/decorators/body-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/body-decorator.js +52 -58
- package/dist/controllers/decorators/body-decorator.js.map +1 -1
- package/dist/controllers/decorators/controller-decorator.d.ts +5 -4
- package/dist/controllers/decorators/controller-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/controller-decorator.js +29 -22
- package/dist/controllers/decorators/controller-decorator.js.map +1 -1
- package/dist/controllers/decorators/param-decorator.d.ts +4 -9
- package/dist/controllers/decorators/param-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/param-decorator.js +33 -29
- package/dist/controllers/decorators/param-decorator.js.map +1 -1
- package/dist/controllers/decorators/query-decorator.d.ts +11 -15
- package/dist/controllers/decorators/query-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/query-decorator.js +24 -38
- package/dist/controllers/decorators/query-decorator.js.map +1 -1
- package/dist/controllers/decorators/request-decorator.d.ts +8 -12
- package/dist/controllers/decorators/request-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/request-decorator.js +21 -17
- package/dist/controllers/decorators/request-decorator.js.map +1 -1
- package/dist/controllers/decorators/route-decorator.d.ts +16 -1
- package/dist/controllers/decorators/route-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/route-decorator.js +31 -16
- 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/exceptions/api-exception.d.ts +4 -7
- package/dist/exceptions/api-exception.d.ts.map +1 -1
- package/dist/exceptions/api-exception.js +8 -4
- package/dist/exceptions/api-exception.js.map +1 -1
- package/dist/exceptions/base-exception-filter.d.ts.map +1 -1
- package/dist/exceptions/base-exception-filter.js +10 -3
- package/dist/exceptions/base-exception-filter.js.map +1 -1
- package/dist/exceptions/decorators/use-filters-decorator.d.ts +12 -1
- package/dist/exceptions/decorators/use-filters-decorator.d.ts.map +1 -1
- package/dist/exceptions/decorators/use-filters-decorator.js +34 -3
- package/dist/exceptions/decorators/use-filters-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 +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/interceptor/decorators/use-interceptor-decorator.d.ts +10 -3
- package/dist/interceptor/decorators/use-interceptor-decorator.d.ts.map +1 -1
- package/dist/interceptor/decorators/use-interceptor-decorator.js +52 -22
- 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 +2 -2
- package/dist/modules/module-decorator.d.ts.map +1 -1
- package/dist/modules/module-decorator.js +34 -14
- package/dist/modules/module-decorator.js.map +1 -1
- package/dist/pipes/decorators/index.d.ts +2 -0
- package/dist/pipes/decorators/index.d.ts.map +1 -0
- package/dist/pipes/decorators/index.js +6 -0
- package/dist/pipes/decorators/index.js.map +1 -0
- package/dist/pipes/decorators/use-pipes.d.ts +19 -0
- package/dist/pipes/decorators/use-pipes.d.ts.map +1 -0
- package/dist/pipes/decorators/use-pipes.js +118 -0
- package/dist/pipes/decorators/use-pipes.js.map +1 -0
- package/dist/pipes/index.d.ts +3 -0
- package/dist/pipes/index.d.ts.map +1 -0
- package/dist/pipes/index.js +18 -0
- package/dist/pipes/index.js.map +1 -0
- package/dist/pipes/pipe-transform.d.ts +46 -0
- package/dist/pipes/pipe-transform.d.ts.map +1 -0
- package/dist/pipes/pipe-transform.js +3 -0
- package/dist/pipes/pipe-transform.js.map +1 -0
- package/dist/server/server-factory.d.ts +48 -1
- package/dist/server/server-factory.d.ts.map +1 -1
- package/dist/server/server-factory.js +169 -34
- 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/services/pipes.d.ts +2 -0
- package/dist/services/pipes.d.ts.map +1 -0
- package/dist/services/pipes.js +5 -0
- package/dist/services/pipes.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/dist/zod/create-zod-dto.d.ts +16 -0
- package/dist/zod/create-zod-dto.d.ts.map +1 -0
- package/dist/zod/create-zod-dto.js +14 -0
- package/dist/zod/create-zod-dto.js.map +1 -0
- package/dist/zod/index.d.ts +3 -0
- package/dist/zod/index.d.ts.map +1 -0
- package/dist/zod/index.js +8 -0
- package/dist/zod/index.js.map +1 -0
- package/dist/zod/zod-validation-pipe.d.ts +5 -0
- package/dist/zod/zod-validation-pipe.d.ts.map +1 -0
- package/dist/zod/zod-validation-pipe.js +35 -0
- package/dist/zod/zod-validation-pipe.js.map +1 -0
- package/package.json +6 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pipes/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./decorators"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pipes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Class } from '../types/class';
|
|
2
|
+
/**
|
|
3
|
+
* @publicApi
|
|
4
|
+
*/
|
|
5
|
+
export type Paramtype = 'body' | 'query' | 'param' | 'custom';
|
|
6
|
+
export type Transform<T = any> = (value: T, metadata: ArgumentMetadata) => any;
|
|
7
|
+
/**
|
|
8
|
+
* Interface describing a pipe implementation's `transform()` method metadata argument.
|
|
9
|
+
*
|
|
10
|
+
* @see [Pipes](https://docs.nestjs.com/pipes)
|
|
11
|
+
*
|
|
12
|
+
* @publicApi
|
|
13
|
+
*/
|
|
14
|
+
export interface ArgumentMetadata {
|
|
15
|
+
/**
|
|
16
|
+
* Indicates whether argument is a body, query, param, or custom parameter
|
|
17
|
+
*/
|
|
18
|
+
readonly type: Paramtype;
|
|
19
|
+
/**
|
|
20
|
+
* Underlying base type (e.g., `String`) of the parameter, based on the type
|
|
21
|
+
* definition in the route handler.
|
|
22
|
+
*/
|
|
23
|
+
readonly metatype?: Class<any> | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* String passed as an argument to the decorator.
|
|
26
|
+
* Example: `@Body('userId')` would yield `userId`
|
|
27
|
+
*/
|
|
28
|
+
readonly data?: string | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Interface describing implementation of a pipe.
|
|
32
|
+
*
|
|
33
|
+
* @see [Pipes](https://docs.nestjs.com/pipes)
|
|
34
|
+
*
|
|
35
|
+
* @publicApi
|
|
36
|
+
*/
|
|
37
|
+
export interface PipeTransform<T = any, R = any> {
|
|
38
|
+
/**
|
|
39
|
+
* Method to implement a custom pipe. Called with two parameters
|
|
40
|
+
*
|
|
41
|
+
* @param value argument before it is received by route handler method
|
|
42
|
+
* @param metadata contains metadata about the value
|
|
43
|
+
*/
|
|
44
|
+
transform(value: T, metadata: ArgumentMetadata): R;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=pipe-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipe-transform.d.ts","sourceRoot":"","sources":["../../src/pipes/pipe-transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAErC;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAA;AAE7D,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,gBAAgB,KAAK,GAAG,CAAA;AAE9E;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAA;IAC1C;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACnC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;IAC7C;;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,gBAAgB,GAAG,CAAC,CAAA;CACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipe-transform.js","sourceRoot":"","sources":["../../src/pipes/pipe-transform.ts"],"names":[],"mappings":""}
|
|
@@ -1,17 +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';
|
|
9
|
+
import { PipeTransform } from '../pipes/pipe-transform';
|
|
10
|
+
import { GetOptions, OptionalGetOptions } from 'inversify';
|
|
11
|
+
import { Middleware } from '../middleware/middleware';
|
|
8
12
|
export type ServerFactoryOptions = {
|
|
9
13
|
logger?: LoggerService | boolean;
|
|
10
14
|
};
|
|
11
15
|
export declare class ServerFactory {
|
|
12
16
|
private globalPrefix;
|
|
13
17
|
private globalFilters;
|
|
18
|
+
private globalGuards;
|
|
14
19
|
private globalInterceptors;
|
|
20
|
+
private globalPipes;
|
|
21
|
+
private globalMiddlewares;
|
|
15
22
|
private readonly module;
|
|
16
23
|
private readonly container;
|
|
17
24
|
private readonly routes;
|
|
@@ -23,7 +30,24 @@ export declare class ServerFactory {
|
|
|
23
30
|
*/
|
|
24
31
|
setGlobalPrefix(prefix: string): void;
|
|
25
32
|
useGlobalFilters(...filters: ExceptionFilter[]): void;
|
|
33
|
+
useGlobalGuards(...guards: CanActivate[]): void;
|
|
26
34
|
useGlobalInterceptors(...interceptors: Interceptor[]): void;
|
|
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>;
|
|
27
51
|
/**
|
|
28
52
|
* Handle a request
|
|
29
53
|
* @param request - The request to handle
|
|
@@ -32,7 +56,11 @@ export declare class ServerFactory {
|
|
|
32
56
|
*/
|
|
33
57
|
handler(request: NextRequest, { params }: {
|
|
34
58
|
params: Promise<any>;
|
|
35
|
-
}): Promise<
|
|
59
|
+
}): Promise<Response>;
|
|
60
|
+
/**
|
|
61
|
+
* Core request handling pipeline: guards -> interceptors -> handler -> exception filters
|
|
62
|
+
*/
|
|
63
|
+
private _handleRequest;
|
|
36
64
|
private static _registerLogger;
|
|
37
65
|
/**
|
|
38
66
|
* Parse the request
|
|
@@ -47,8 +75,27 @@ export declare class ServerFactory {
|
|
|
47
75
|
* @returns The route
|
|
48
76
|
*/
|
|
49
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;
|
|
50
85
|
private _fetchInterceptors;
|
|
51
86
|
private _fetchHandler;
|
|
52
87
|
private _fetchExceptionFilters;
|
|
88
|
+
/**
|
|
89
|
+
* Fetch all middleware: explicit globals + APP_MIDDLEWARE container bindings
|
|
90
|
+
* Execution order: first registered = outermost
|
|
91
|
+
*/
|
|
92
|
+
private _fetchMiddlewares;
|
|
93
|
+
/**
|
|
94
|
+
* Fetch the pipes for a controller method
|
|
95
|
+
* @param controller
|
|
96
|
+
* @param methodName
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
private _fetchPipes;
|
|
53
100
|
}
|
|
54
101
|
//# sourceMappingURL=server-factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-factory.d.ts","sourceRoot":"","sources":["../../src/server/server-factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AAI5D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"server-factory.d.ts","sourceRoot":"","sources":["../../src/server/server-factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AAI5D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAgB,MAAM,UAAU,CAAA;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAiB,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAK1E,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAIvD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAKtD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAIpD,MAAM,MAAM,oBAAoB,GAAG;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E,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");
|
|
@@ -18,11 +20,20 @@ const server_1 = require("next/server");
|
|
|
18
20
|
const logger_1 = require("../logger/logger");
|
|
19
21
|
const api_exception_1 = require("../exceptions/api-exception");
|
|
20
22
|
const lodash_1 = require("lodash");
|
|
23
|
+
const pipes_1 = require("../services/pipes");
|
|
24
|
+
const use_pipes_1 = require("../pipes/decorators/use-pipes");
|
|
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");
|
|
21
29
|
class ServerFactory {
|
|
22
30
|
constructor(module, container, routes) {
|
|
23
31
|
this.globalPrefix = '';
|
|
24
32
|
this.globalFilters = [new base_exception_filter_1.BaseExceptionFilter()];
|
|
33
|
+
this.globalGuards = [];
|
|
25
34
|
this.globalInterceptors = [];
|
|
35
|
+
this.globalPipes = [];
|
|
36
|
+
this.globalMiddlewares = [];
|
|
26
37
|
this.module = module;
|
|
27
38
|
this.container = container;
|
|
28
39
|
this.routes = routes;
|
|
@@ -33,7 +44,10 @@ class ServerFactory {
|
|
|
33
44
|
this._registerLogger(options?.logger);
|
|
34
45
|
container.load(module.prototype[keys_1.MODULE_PROPERTY]);
|
|
35
46
|
const routes = (0, module_decorator_1.moduleHandler)(module);
|
|
36
|
-
|
|
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);
|
|
37
51
|
}
|
|
38
52
|
/**
|
|
39
53
|
* Set the global prefix for the server
|
|
@@ -45,9 +59,36 @@ class ServerFactory {
|
|
|
45
59
|
useGlobalFilters(...filters) {
|
|
46
60
|
this.globalFilters.push(...filters);
|
|
47
61
|
}
|
|
62
|
+
useGlobalGuards(...guards) {
|
|
63
|
+
this.globalGuards.push(...guards);
|
|
64
|
+
}
|
|
48
65
|
useGlobalInterceptors(...interceptors) {
|
|
49
66
|
this.globalInterceptors.push(...interceptors);
|
|
50
67
|
}
|
|
68
|
+
useGlobalPipes(...pipes) {
|
|
69
|
+
this.globalPipes.push(...pipes);
|
|
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
|
+
}
|
|
51
92
|
/**
|
|
52
93
|
* Handle a request
|
|
53
94
|
* @param request - The request to handle
|
|
@@ -55,21 +96,40 @@ class ServerFactory {
|
|
|
55
96
|
* @returns The response from the handler
|
|
56
97
|
*/
|
|
57
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) {
|
|
58
107
|
const host = new arguments_host_1.ArgumentsHost([request]);
|
|
59
108
|
let controller;
|
|
60
109
|
try {
|
|
61
110
|
// Bind the current request to the container for this request lifecycle
|
|
62
111
|
(0, request_1.bindRequest)(this.container, request);
|
|
63
112
|
const { pathname, method } = this._parseRequest(request);
|
|
64
|
-
const
|
|
65
|
-
controller = await this.container.getAsync(
|
|
66
|
-
const handler = this._fetchHandler(controller,
|
|
113
|
+
const match = this._fetchRoute(pathname, method);
|
|
114
|
+
controller = await this.container.getAsync(match?.controller);
|
|
115
|
+
const handler = this._fetchHandler(controller, match?.methodName);
|
|
67
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);
|
|
68
121
|
// Check if there's any interceptors to execute
|
|
69
122
|
const interceptors = await this._fetchInterceptors(controller);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
123
|
+
// Check if there's any pipes to execute
|
|
124
|
+
const pipes = await this._fetchPipes(controller, match?.methodName);
|
|
125
|
+
return await use_interceptor_decorator_1.InterceptorHandler.execute(executionContext, interceptors, async () => {
|
|
126
|
+
// Parse args
|
|
127
|
+
const args = await route_decorator_1.RouteHandler.getArgs(controller, match?.methodName, [request, { params }]);
|
|
128
|
+
// Run registered pipes
|
|
129
|
+
const pipedArgs = await use_pipes_1.PipeHandler.execute(controller, match?.methodName, pipes, args);
|
|
130
|
+
// Execute controller
|
|
131
|
+
return await handler.call(controller, ...pipedArgs);
|
|
132
|
+
});
|
|
73
133
|
}
|
|
74
134
|
catch (error) {
|
|
75
135
|
const filters = await this._fetchExceptionFilters(controller);
|
|
@@ -80,6 +140,11 @@ class ServerFactory {
|
|
|
80
140
|
// Check if any specific type is registered, if none, it's a catch all filter
|
|
81
141
|
if (!type || error instanceof type) {
|
|
82
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
|
+
}
|
|
83
148
|
// If a response is returned from the filter, use it
|
|
84
149
|
if (response) {
|
|
85
150
|
return response;
|
|
@@ -101,7 +166,15 @@ class ServerFactory {
|
|
|
101
166
|
*/
|
|
102
167
|
_parseRequest(request) {
|
|
103
168
|
const { pathname } = new URL(request.url);
|
|
104
|
-
|
|
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
|
+
}
|
|
105
178
|
return {
|
|
106
179
|
pathname: strippedPathname,
|
|
107
180
|
method: request.method.toUpperCase()
|
|
@@ -126,25 +199,45 @@ class ServerFactory {
|
|
|
126
199
|
}
|
|
127
200
|
return route;
|
|
128
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
|
+
}
|
|
129
226
|
async _fetchInterceptors(controller) {
|
|
130
227
|
const interceptors = [...this.globalInterceptors];
|
|
131
|
-
// Fetch
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// If it's an instance, resolve from container using its constructor
|
|
145
|
-
return this.container.getAsync(interceptor.constructor);
|
|
146
|
-
}));
|
|
147
|
-
interceptors.push(...resolvedInterceptors);
|
|
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
|
|
237
|
+
}
|
|
238
|
+
if (controller) {
|
|
239
|
+
// Fetch controller interceptors
|
|
240
|
+
interceptors.push(...(await use_interceptor_decorator_1.InterceptorHandler.fetch(this.container, controller)));
|
|
148
241
|
}
|
|
149
242
|
return interceptors.reverse();
|
|
150
243
|
}
|
|
@@ -158,20 +251,62 @@ class ServerFactory {
|
|
|
158
251
|
}
|
|
159
252
|
async _fetchExceptionFilters(controller) {
|
|
160
253
|
const filters = [...this.globalFilters];
|
|
161
|
-
// Fetch
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
|
165
263
|
}
|
|
166
264
|
if (controller) {
|
|
167
|
-
|
|
168
|
-
const controllerFilters = (0, use_filters_decorator_1.filterHandler)(controller.constructor);
|
|
169
|
-
if (controllerFilters.length > 0) {
|
|
170
|
-
filters.push(...controllerFilters);
|
|
171
|
-
}
|
|
265
|
+
filters.push(...(await use_filters_decorator_1.FilterHandler.fetch(this.container, controller)));
|
|
172
266
|
}
|
|
173
267
|
return filters.reverse();
|
|
174
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
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Fetch the pipes for a controller method
|
|
288
|
+
* @param controller
|
|
289
|
+
* @param methodName
|
|
290
|
+
* @returns
|
|
291
|
+
*/
|
|
292
|
+
async _fetchPipes(controller, methodName) {
|
|
293
|
+
const pipes = [...this.globalPipes];
|
|
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
|
|
303
|
+
}
|
|
304
|
+
// Fetch controller pipes
|
|
305
|
+
if (controller) {
|
|
306
|
+
pipes.push(...(await use_pipes_1.PipeHandler.fetch(this.container, controller, methodName)));
|
|
307
|
+
}
|
|
308
|
+
return pipes.reverse();
|
|
309
|
+
}
|
|
175
310
|
}
|
|
176
311
|
exports.ServerFactory = ServerFactory;
|
|
177
312
|
//# sourceMappingURL=server-factory.js.map
|
|
@@ -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,
|
|
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;AAEhD,qDAAgD;AAChD,wCAAuD;AAEvD,4CAAwC;AACxC,8DAAiE;AACjE,mCAA8B;AAE9B,4CAA2C;AAC3C,4DAA0D;AAC1D,8EAAuE;AACvE,wEAA0E;AAG1E,wEAAmE;AACnE,sDAAsD;AAMtD,MAAa,aAAa;IAYxB,YAAY,MAAa,EAAE,SAAoB,EAAE,MAAwB;QAXjE,iBAAY,GAAW,EAAE,CAAA;QACzB,kBAAa,GAAsB,CAAC,IAAI,2CAAmB,EAAE,CAAC,CAAA;QAC9D,iBAAY,GAAkB,EAAE,CAAA;QAChC,uBAAkB,GAAkB,EAAE,CAAA;QACtC,gBAAW,GAAoB,EAAE,CAAA;QACjC,sBAAiB,GAAiB,EAAE,CAAA;QAO1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,eAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;IACpC,CAAC;IAEM,MAAM,CAAC,MAAM,CAAC,MAAa,EAAE,OAA8B;QAChE,MAAM,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAA;QAEjC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAErC,S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CAAgB,gBAAQ,CAAC,CAAA;YAC1E,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxB,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,8EAA8E;QAChF,CAAC;QAED,yBAAyB;QACzB,IAAI,UAAU,EAAE,CAAC;YACf,KAAK,CAAC,IAAI,CACR,GAAG,CAAC,MAAM,uBAAW,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CACrE,CAAA;QACH,CAAC;QAED,OAAO,KAAK,CAAC,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 @@
|
|
|
1
|
+
{"version":3,"file":"pipes.d.ts","sourceRoot":"","sources":["../../src/services/pipes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,eAAqB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipes.js","sourceRoot":"","sources":["../../src/services/pipes.ts"],"names":[],"mappings":";;;AAAa,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,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"}
|