@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ControllerHandler = void 0;
|
|
4
4
|
exports.Controller = Controller;
|
|
5
5
|
const inversify_1 = require("inversify");
|
|
6
6
|
const keys_1 = require("../../constants/keys");
|
|
@@ -8,31 +8,38 @@ const route_decorator_1 = require("./route-decorator");
|
|
|
8
8
|
const apply_decorators_1 = require("../../utils/apply-decorators");
|
|
9
9
|
const get_class_methods_1 = require("../../utils/class/get-class-methods");
|
|
10
10
|
const url_join_1 = require("../../utils/url/url-join");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const metadata = Reflect.getOwnMetadata(keys_1.CONTROLLER_KEY, target);
|
|
15
|
-
if (!metadata) {
|
|
16
|
-
console.warn(`Class ${target.name} does not have a Controller decorator`);
|
|
17
|
-
return [];
|
|
11
|
+
class ControllerHandler {
|
|
12
|
+
static getMetadata(target) {
|
|
13
|
+
return Reflect.getOwnMetadata(keys_1.CONTROLLER_KEY, target);
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// Add the route to the routes array
|
|
27
|
-
routes.push({
|
|
28
|
-
methodName: methodName,
|
|
29
|
-
method: routeMetadata.method,
|
|
30
|
-
path: url
|
|
31
|
-
});
|
|
15
|
+
static getRoutes(target) {
|
|
16
|
+
const routes = [];
|
|
17
|
+
const prototype = target.prototype;
|
|
18
|
+
const metadata = Reflect.getOwnMetadata(keys_1.CONTROLLER_KEY, target);
|
|
19
|
+
if (!metadata) {
|
|
20
|
+
console.warn(`Class ${target.name} does not have a Controller decorator`);
|
|
21
|
+
return [];
|
|
32
22
|
}
|
|
23
|
+
const methodNames = (0, get_class_methods_1.getClassMethods)(target);
|
|
24
|
+
// Compile all routes from the controller
|
|
25
|
+
for (const methodName of methodNames) {
|
|
26
|
+
const routeMetadata = route_decorator_1.RouteHandler.getMetadata(prototype, methodName);
|
|
27
|
+
if (routeMetadata) {
|
|
28
|
+
// Join the controller path with the route path
|
|
29
|
+
const url = (0, url_join_1.urlJoin)(metadata.path, routeMetadata.path);
|
|
30
|
+
// Add the route to the routes array
|
|
31
|
+
routes.push({
|
|
32
|
+
methodName: methodName,
|
|
33
|
+
method: routeMetadata.method,
|
|
34
|
+
path: url,
|
|
35
|
+
paramTypes: routeMetadata.paramTypes
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return routes;
|
|
33
40
|
}
|
|
34
|
-
return routes;
|
|
35
41
|
}
|
|
42
|
+
exports.ControllerHandler = ControllerHandler;
|
|
36
43
|
/**
|
|
37
44
|
* A class decorator that wraps all methods in the class with error handling.
|
|
38
45
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/controller-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/controller-decorator.ts"],"names":[],"mappings":";;;AAwDA,gCAIC;AA5DD,yCAAsC;AACtC,2CAAiD;AACjD,uDAA+D;AAC/D,+DAA0D;AAC1D,uEAAiE;AACjE,mDAA8C;AAM9C,MAAa,iBAAiB;IAC5B,MAAM,CAAC,WAAW,CAAC,MAAc;QAC/B,OAAO,OAAO,CAAC,cAAc,CAAC,qBAAc,EAAE,MAAM,CAAC,CAAA;IACvD,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAgB;QAC/B,MAAM,MAAM,GAAoB,EAAE,CAAA;QAClC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QAElC,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,qBAAc,EAAE,MAAM,CAAC,CAAA;QAE/D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,IAAI,uCAAuC,CAAC,CAAA;YACzE,OAAO,EAAE,CAAA;QACX,CAAC;QAED,MAAM,WAAW,GAAG,IAAA,mCAAe,EAAC,MAAM,CAAC,CAAA;QAE3C,yCAAyC;QACzC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,MAAM,aAAa,GAAG,8BAAY,CAAC,WAAW,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;YAErE,IAAI,aAAa,EAAE,CAAC;gBAClB,+CAA+C;gBAC/C,MAAM,GAAG,GAAG,IAAA,kBAAO,EAAC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;gBAEtD,oCAAoC;gBACpC,MAAM,CAAC,IAAI,CAAC;oBACV,UAAU,EAAE,UAAU;oBACtB,MAAM,EAAE,aAAa,CAAC,MAAM;oBAC5B,IAAI,EAAE,GAAG;oBACT,UAAU,EAAE,aAAa,CAAC,UAAU;iBACrC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAtCD,8CAsCC;AAED;;;;GAIG;AACH,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAA,kCAAe,EAAC,IAAA,sBAAU,GAAE,EAAE,UAAU,MAAgB;QAC7D,OAAO,CAAC,cAAc,CAAC,qBAAc,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,CAAC,CAAA;IAC1D,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -2,15 +2,10 @@ export type ParamMetadata = {
|
|
|
2
2
|
name: string;
|
|
3
3
|
parameterIndex: number;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @param propertyKey - The property key.
|
|
10
|
-
* @param args - The arguments.
|
|
11
|
-
* @returns The parameter and parameter index.
|
|
12
|
-
*/
|
|
13
|
-
export declare function paramDecoratorHandler(target: object, propertyKey: string | symbol, args: any[]): Promise<any>;
|
|
5
|
+
export declare class ParamHandler {
|
|
6
|
+
static getMetadata(target: object, propertyKey: string | symbol): ParamMetadata[] | undefined;
|
|
7
|
+
static handle(target: object, propertyKey: string | symbol, args: any[]): Promise<any>;
|
|
8
|
+
}
|
|
14
9
|
/**
|
|
15
10
|
* Decorator to validate the param of the request.
|
|
16
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"param-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/param-decorator.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"param-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/param-decorator.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,aAAa,EAAE,GAAG,SAAS;WAmBjB,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,IAAI,EAAE,GAAG,EAAE,GACV,OAAO,CAAC,GAAG,CAAC;CAmChB;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,IAE9B,QAAQ,MAAM,EACd,aAAa,MAAM,GAAG,MAAM,EAC5B,gBAAgB,MAAM,UAYzB"}
|
|
@@ -1,42 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ParamHandler = void 0;
|
|
4
4
|
exports.Param = Param;
|
|
5
5
|
const keys_1 = require("../../constants/keys");
|
|
6
6
|
const api_exception_1 = require("../../exceptions/api-exception");
|
|
7
7
|
const get_next_arguments_1 = require("../../utils/nextjs/get-next-arguments");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @returns The parameter and parameter index.
|
|
15
|
-
*/
|
|
16
|
-
async function paramDecoratorHandler(target, propertyKey, args) {
|
|
17
|
-
const metadatas = Reflect.getOwnMetadata(keys_1.PARAM_KEY, target, propertyKey);
|
|
18
|
-
// If the metadata is found, validate the param.
|
|
19
|
-
if (metadatas && metadatas.length > 0) {
|
|
20
|
-
const params = await (0, get_next_arguments_1.getNextParamArgument)(args);
|
|
21
|
-
// If params is undefined or null, all required params are missing
|
|
22
|
-
if (!params) {
|
|
23
|
-
throw new api_exception_1.ValidationApiException(`Invalid param: ${metadatas[0].name} is required`);
|
|
8
|
+
class ParamHandler {
|
|
9
|
+
static getMetadata(target, propertyKey) {
|
|
10
|
+
let metadatas = Reflect.getOwnMetadata(keys_1.PARAM_KEY, target, propertyKey);
|
|
11
|
+
// If not found on instance, try constructor prototype
|
|
12
|
+
if (!metadatas && target.constructor) {
|
|
13
|
+
metadatas = Reflect.getOwnMetadata(keys_1.PARAM_KEY, target.constructor.prototype, propertyKey);
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
return metadatas;
|
|
16
|
+
}
|
|
17
|
+
static async handle(target, propertyKey, args) {
|
|
18
|
+
const metadatas = this.getMetadata(target, propertyKey);
|
|
19
|
+
// If the metadata is found, validate the param.
|
|
20
|
+
if (metadatas && metadatas.length > 0) {
|
|
21
|
+
const params = await (0, get_next_arguments_1.getNextParamArgument)(args);
|
|
22
|
+
// If params is undefined or null, all required params are missing
|
|
23
|
+
if (!params) {
|
|
24
|
+
throw new api_exception_1.ValidationApiException(`Invalid param: ${metadatas[0].name} is required`);
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
// Validate the param.
|
|
27
|
+
return metadatas.map((metadata) => {
|
|
28
|
+
const value = params[metadata.name];
|
|
29
|
+
// If the param is not found, throw a validation error.
|
|
30
|
+
if (!value) {
|
|
31
|
+
throw new api_exception_1.ValidationApiException(`Invalid param: ${metadata.name} is required`);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
type: 'param',
|
|
35
|
+
parameter: value,
|
|
36
|
+
parameterIndex: metadata.parameterIndex
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
37
41
|
}
|
|
38
|
-
return null;
|
|
39
42
|
}
|
|
43
|
+
exports.ParamHandler = ParamHandler;
|
|
40
44
|
/**
|
|
41
45
|
* Decorator to validate the param of the request.
|
|
42
46
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"param-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/param-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"param-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/param-decorator.ts"],"names":[],"mappings":";;;AA+EA,sBAgBC;AA/FD,2CAA4C;AAC5C,8DAAmE;AACnE,0EAAwE;AAOxE,MAAa,YAAY;IACvB,MAAM,CAAC,WAAW,CAChB,MAAc,EACd,WAA4B;QAE5B,IAAI,SAAS,GAAgC,OAAO,CAAC,cAAc,CACjE,gBAAS,EACT,MAAM,EACN,WAAW,CACZ,CAAA;QAED,sDAAsD;QACtD,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACrC,SAAS,GAAG,OAAO,CAAC,cAAc,CAChC,gBAAS,EACT,MAAM,CAAC,WAAW,CAAC,SAAS,EAC5B,WAAW,CACZ,CAAA;QACH,CAAC;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,MAAc,EACd,WAA4B,EAC5B,IAAW;QAEX,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;QAEvD,gDAAgD;QAChD,IAAI,SAAS,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtC,MAAM,MAAM,GAA2B,MAAM,IAAA,yCAAoB,EAAC,IAAI,CAAC,CAAA;YAEvE,kEAAkE;YAClE,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ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13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
parameterIndex: number;
|
|
18
|
-
} | null;
|
|
5
|
+
export declare class QueryHandler {
|
|
6
|
+
static getMetadata(target: object, propertyKey: string | symbol): QueryMetadata | undefined;
|
|
7
|
+
static handle(target: object, propertyKey: string | symbol, args: any[]): {
|
|
8
|
+
type: string;
|
|
9
|
+
parameter: {
|
|
10
|
+
[k: string]: string;
|
|
11
|
+
};
|
|
12
|
+
parameterIndex: number;
|
|
13
|
+
} | null;
|
|
14
|
+
}
|
|
19
15
|
/**
|
|
20
16
|
* Decorator to validate the query of the request.
|
|
21
17
|
*
|
|
22
18
|
* @param schema - The Zod schema to validate the query against.
|
|
23
19
|
* @returns A decorator function that can be used to decorate a controller method.
|
|
24
20
|
*/
|
|
25
|
-
export declare function Query(
|
|
21
|
+
export declare function Query(): (target: object, propertyKey: string | symbol, propertyIndex: number) => void;
|
|
26
22
|
//# sourceMappingURL=query-decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/query-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/query-decorator.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,aAAa,GAAG,SAAS;IAmB5B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE;;;;;;;CAmBxE;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,KAEjB,QAAQ,MAAM,EACd,aAAa,MAAM,GAAG,MAAM,EAC5B,eAAe,MAAM,UAaxB"}
|
|
@@ -1,61 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.QueryHandler = void 0;
|
|
4
4
|
exports.Query = Query;
|
|
5
5
|
const keys_1 = require("../../constants/keys");
|
|
6
|
-
const api_exception_1 = require("../../exceptions/api-exception");
|
|
7
6
|
const get_next_arguments_1 = require("../../utils/nextjs/get-next-arguments");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!metadata.schema) {
|
|
7
|
+
class QueryHandler {
|
|
8
|
+
static getMetadata(target, propertyKey) {
|
|
9
|
+
let metadata = Reflect.getOwnMetadata(keys_1.QUERY_KEY, target, propertyKey);
|
|
10
|
+
// If not found on instance, try constructor prototype
|
|
11
|
+
if (!metadata && target.constructor) {
|
|
12
|
+
metadata = Reflect.getOwnMetadata(keys_1.QUERY_KEY, target.constructor.prototype, propertyKey);
|
|
13
|
+
}
|
|
14
|
+
return metadata;
|
|
15
|
+
}
|
|
16
|
+
static handle(target, propertyKey, args) {
|
|
17
|
+
const metadata = this.getMetadata(target, propertyKey);
|
|
18
|
+
// If the metadata is found, validate the query.
|
|
19
|
+
if (metadata) {
|
|
20
|
+
const request = (0, get_next_arguments_1.getNextRequestArgument)(args);
|
|
21
|
+
const { searchParams } = new URL(request.url);
|
|
22
|
+
const query = Object.fromEntries(searchParams.entries());
|
|
25
23
|
return {
|
|
24
|
+
type: 'query',
|
|
26
25
|
parameter: query,
|
|
27
26
|
parameterIndex: metadata.parameterIndex
|
|
28
27
|
};
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
const parsedQuery = resolvedSchema?.safeParse(query);
|
|
32
|
-
// If the query is not valid, throw a validation error.
|
|
33
|
-
if (parsedQuery && !parsedQuery.success) {
|
|
34
|
-
throw new api_exception_1.ValidationApiException(`Invalid query parameters: ${JSON.stringify(parsedQuery.error.flatten().fieldErrors)}`);
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
parameter: parsedQuery?.data || query,
|
|
38
|
-
parameterIndex: metadata.parameterIndex
|
|
39
|
-
};
|
|
29
|
+
return null;
|
|
40
30
|
}
|
|
41
|
-
return null;
|
|
42
31
|
}
|
|
32
|
+
exports.QueryHandler = QueryHandler;
|
|
43
33
|
/**
|
|
44
34
|
* Decorator to validate the query of the request.
|
|
45
35
|
*
|
|
46
36
|
* @param schema - The Zod schema to validate the query against.
|
|
47
37
|
* @returns A decorator function that can be used to decorate a controller method.
|
|
48
38
|
*/
|
|
49
|
-
function Query(
|
|
50
|
-
return function (target, propertyKey,
|
|
51
|
-
//
|
|
52
|
-
const lazySchema = schema
|
|
53
|
-
? () => (typeof schema === 'function' ? schema() : schema)
|
|
54
|
-
: undefined;
|
|
39
|
+
function Query() {
|
|
40
|
+
return function (target, propertyKey, propertyIndex) {
|
|
41
|
+
// Get the parameter type from design:paramtypes
|
|
55
42
|
Reflect.defineMetadata(keys_1.QUERY_KEY, {
|
|
56
43
|
propertyKey,
|
|
57
|
-
parameterIndex
|
|
58
|
-
schema: lazySchema
|
|
44
|
+
parameterIndex: propertyIndex
|
|
59
45
|
}, target, propertyKey);
|
|
60
46
|
};
|
|
61
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/query-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/query-decorator.ts"],"names":[],"mappings":";;;AA0DA,sBAiBC;AA3ED,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AAC,CAAA;AACH,CAAC"}
|
|
@@ -2,18 +2,14 @@ export type RequestMetadata = {
|
|
|
2
2
|
propertyKey: string | symbol;
|
|
3
3
|
parameterIndex: number;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export declare function requestDecoratorHandler(target: object, propertyKey: string | symbol, args: any[]): {
|
|
14
|
-
parameter: any;
|
|
15
|
-
parameterIndex: number;
|
|
16
|
-
} | null;
|
|
5
|
+
export declare class RequestHandler {
|
|
6
|
+
static getMetadata(target: object, propertyKey: string | symbol): RequestMetadata | undefined;
|
|
7
|
+
static handle(target: object, propertyKey: string | symbol, args: any[]): {
|
|
8
|
+
type: string;
|
|
9
|
+
parameter: any;
|
|
10
|
+
parameterIndex: number;
|
|
11
|
+
} | null;
|
|
12
|
+
}
|
|
17
13
|
/**
|
|
18
14
|
* Decorator to fetch the request object.
|
|
19
15
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/request-decorator.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"request-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/request-decorator.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,qBAAa,cAAc;IACzB,MAAM,CAAC,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,eAAe,GAAG,SAAS;IAmB9B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE;;;;;CAYxE;AAED;;;;GAIG;AACH,wBAAgB,OAAO,KAEnB,QAAQ,MAAM,EACd,aAAa,MAAM,GAAG,MAAM,EAC5B,gBAAgB,MAAM,UAYzB;AAED,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,CAAA"}
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RequestHandler = void 0;
|
|
4
4
|
exports.Request = Request;
|
|
5
5
|
exports.Req = Request;
|
|
6
6
|
const keys_1 = require("../../constants/keys");
|
|
7
7
|
const get_next_arguments_1 = require("../../utils/nextjs/get-next-arguments");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
class RequestHandler {
|
|
9
|
+
static getMetadata(target, propertyKey) {
|
|
10
|
+
let metadata = Reflect.getOwnMetadata(keys_1.REQUEST_KEY, target, propertyKey);
|
|
11
|
+
// If not found on instance, try constructor prototype
|
|
12
|
+
if (!metadata && target.constructor) {
|
|
13
|
+
metadata = Reflect.getOwnMetadata(keys_1.REQUEST_KEY, target.constructor.prototype, propertyKey);
|
|
14
|
+
}
|
|
15
|
+
return metadata;
|
|
16
|
+
}
|
|
17
|
+
static handle(target, propertyKey, args) {
|
|
18
|
+
const metadata = this.getMetadata(target, propertyKey);
|
|
19
|
+
if (metadata) {
|
|
20
|
+
return {
|
|
21
|
+
type: 'custom',
|
|
22
|
+
parameter: (0, get_next_arguments_1.getNextRequestArgument)(args),
|
|
23
|
+
parameterIndex: metadata.parameterIndex
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
23
27
|
}
|
|
24
|
-
return null;
|
|
25
28
|
}
|
|
29
|
+
exports.RequestHandler = RequestHandler;
|
|
26
30
|
/**
|
|
27
31
|
* Decorator to fetch the request object.
|
|
28
32
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/request-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/request-decorator.ts"],"names":[],"mappings":";;;AAkDA,0BAgBC;AAEmB,sBAAG;AApEvB,2CAA8C;AAC9C,0EAA0E;AAO1E,MAAa,cAAc;IACzB,MAAM,CAAC,WAAW,CAChB,MAAc,EACd,WAA4B;QAE5B,IAAI,QAAQ,GAAoB,OAAO,CAAC,cAAc,CACpD,kBAAW,EACX,MAAM,EACN,WAAW,CACZ,CAAA;QAED,sDAAsD;QACtD,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACpC,QAAQ,GAAG,OAAO,CAAC,cAAc,CAC/B,kBAAW,EACX,MAAM,CAAC,WAAW,CAAC,SAAS,EAC5B,WAAW,CACZ,CAAA;QACH,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,WAA4B,EAAE,IAAW;QACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;QAEtD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,IAAA,2CAAsB,EAAC,IAAI,CAAC;gBACvC,cAAc,EAAE,QAAQ,CAAC,cAAc;aACxC,CAAA;QACH,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAnCD,wCAmCC;AAED;;;;GAIG;AACH,SAAgB,OAAO;IACrB,OAAO,UACL,MAAc,EACd,WAA4B,EAC5B,cAAsB;QAEtB,OAAO,CAAC,cAAc,CACpB,kBAAW,EACX;YACE,WAAW;YACX,cAAc;SACf,EACD,MAAM,EACN,WAAW,CACZ,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { HttpMethods } from '../../constants/http-methods';
|
|
2
2
|
export type RouteMetadata = {
|
|
3
|
+
methodName: string;
|
|
3
4
|
method: HttpMethods;
|
|
4
5
|
path: string;
|
|
6
|
+
paramTypes: any[];
|
|
5
7
|
};
|
|
6
|
-
export
|
|
8
|
+
export type RouteContext = {
|
|
9
|
+
type?: 'body' | 'param' | 'query' | 'custom';
|
|
10
|
+
parameter: any;
|
|
11
|
+
parameterIndex: number;
|
|
12
|
+
paramType?: any;
|
|
13
|
+
};
|
|
14
|
+
export declare class RouteHandler {
|
|
15
|
+
static getMetadata(target: object, propertyKey: string | symbol): RouteMetadata;
|
|
16
|
+
static getArgs(target: object, propertyKey: string | symbol, originalArgs: any[]): Promise<RouteContext[]>;
|
|
17
|
+
}
|
|
7
18
|
export declare function Route(method: HttpMethods, path: string): MethodDecorator;
|
|
8
19
|
/**
|
|
9
20
|
* Decorator to define a GET route.
|
|
@@ -36,6 +47,10 @@ export declare function Patch(path?: string): MethodDecorator;
|
|
|
36
47
|
/**
|
|
37
48
|
* Decorator to define a DELETE route.
|
|
38
49
|
*
|
|
50
|
+
* When the decorated method returns `null` or `undefined`, the response will
|
|
51
|
+
* automatically be HTTP 204 No Content (with no body). If the method returns
|
|
52
|
+
* a non-null value, it will be serialized as JSON with status 200.
|
|
53
|
+
*
|
|
39
54
|
* @param path - The path of the route.
|
|
40
55
|
* @returns A decorator function that can be used to decorate a controller method.
|
|
41
56
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/route-decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAMtD,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,WAAW,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"route-decorator.d.ts","sourceRoot":"","sources":["../../../src/controllers/decorators/route-decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAMtD,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,WAAW,CAAA;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,GAAG,EAAE,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAA;IAC5C,SAAS,EAAE,GAAG,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,GAAG,CAAA;CAChB,CAAA;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,WAAW,CAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,aAAa;WAIH,OAAO,CAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,YAAY,EAAE,GAAG,EAAE,GAClB,OAAO,CAAC,YAAY,EAAE,CAAC;CAa3B;AAED,wBAAgB,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CAoCxE;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,IAAI,GAAE,MAAW,mBAEpC;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,IAAI,GAAE,MAAW,mBAErC;AAED;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,IAAI,GAAE,MAAW,mBAEpC;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,MAAW,mBAEtC;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,IAAI,GAAE,MAAW,mBAEvC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RouteHandler = void 0;
|
|
4
4
|
exports.Route = Route;
|
|
5
5
|
exports.Get = Get;
|
|
6
6
|
exports.Post = Post;
|
|
@@ -10,35 +10,46 @@ exports.Delete = Delete;
|
|
|
10
10
|
const server_1 = require("next/server");
|
|
11
11
|
const keys_1 = require("../../constants/keys");
|
|
12
12
|
const http_methods_1 = require("../../constants/http-methods");
|
|
13
|
+
const request_decorator_1 = require("./request-decorator");
|
|
13
14
|
const body_decorator_1 = require("./body-decorator");
|
|
14
15
|
const param_decorator_1 = require("./param-decorator");
|
|
15
16
|
const query_decorator_1 = require("./query-decorator");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
class RouteHandler {
|
|
18
|
+
static getMetadata(target, propertyKey) {
|
|
19
|
+
return Reflect.getOwnMetadata(keys_1.ROUTE_KEY, target, propertyKey);
|
|
20
|
+
}
|
|
21
|
+
static async getArgs(target, propertyKey, originalArgs) {
|
|
22
|
+
const args = [
|
|
23
|
+
await request_decorator_1.RequestHandler.handle(target, propertyKey, originalArgs),
|
|
24
|
+
await query_decorator_1.QueryHandler.handle(target, propertyKey, originalArgs),
|
|
25
|
+
await param_decorator_1.ParamHandler.handle(target, propertyKey, originalArgs),
|
|
26
|
+
await body_decorator_1.BodyHandler.handle(target, propertyKey, originalArgs)
|
|
27
|
+
]
|
|
28
|
+
.flat()
|
|
29
|
+
.filter((a) => a !== null && a !== undefined)
|
|
30
|
+
.sort((a, b) => a.parameterIndex - b.parameterIndex);
|
|
31
|
+
return args;
|
|
32
|
+
}
|
|
19
33
|
}
|
|
34
|
+
exports.RouteHandler = RouteHandler;
|
|
20
35
|
function Route(method, path) {
|
|
21
36
|
return function (target, propertyKey, descriptor) {
|
|
37
|
+
const paramTypes = Reflect.getMetadata('design:paramtypes', target, propertyKey) || [];
|
|
22
38
|
Reflect.defineMetadata(keys_1.ROUTE_KEY, {
|
|
39
|
+
methodName: propertyKey,
|
|
23
40
|
method: method,
|
|
24
|
-
path
|
|
41
|
+
path,
|
|
42
|
+
paramTypes
|
|
25
43
|
}, target, propertyKey);
|
|
26
44
|
const originalMethod = descriptor.value;
|
|
27
|
-
descriptor.value = async function (...
|
|
28
|
-
const args = [
|
|
29
|
-
await (0, request_decorator_1.requestDecoratorHandler)(target, propertyKey, originalArgs),
|
|
30
|
-
await (0, query_decorator_1.queryDecoratorHandler)(target, propertyKey, originalArgs),
|
|
31
|
-
await (0, param_decorator_1.paramDecoratorHandler)(target, propertyKey, originalArgs),
|
|
32
|
-
await (0, body_decorator_1.bodyDecoratorHandler)(target, propertyKey, originalArgs)
|
|
33
|
-
]
|
|
34
|
-
.flat()
|
|
35
|
-
.filter((a) => a !== null && a !== undefined)
|
|
36
|
-
.sort((a, b) => a.parameterIndex - b.parameterIndex)
|
|
37
|
-
.map((a) => a.parameter);
|
|
45
|
+
descriptor.value = async function (...args) {
|
|
38
46
|
const response = await originalMethod.apply(this, args);
|
|
39
47
|
if (response instanceof server_1.NextResponse) {
|
|
40
48
|
return response;
|
|
41
49
|
}
|
|
50
|
+
if (response == null) {
|
|
51
|
+
return new server_1.NextResponse(null, { status: 204 });
|
|
52
|
+
}
|
|
42
53
|
return server_1.NextResponse.json(response);
|
|
43
54
|
};
|
|
44
55
|
};
|
|
@@ -82,6 +93,10 @@ function Patch(path = '') {
|
|
|
82
93
|
/**
|
|
83
94
|
* Decorator to define a DELETE route.
|
|
84
95
|
*
|
|
96
|
+
* When the decorated method returns `null` or `undefined`, the response will
|
|
97
|
+
* automatically be HTTP 204 No Content (with no body). If the method returns
|
|
98
|
+
* a non-null value, it will be serialized as JSON with status 200.
|
|
99
|
+
*
|
|
85
100
|
* @param path - The path of the route.
|
|
86
101
|
* @returns A decorator function that can be used to decorate a controller method.
|
|
87
102
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/route-decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"route-decorator.js","sourceRoot":"","sources":["../../../src/controllers/decorators/route-decorator.ts"],"names":[],"mappings":";;;AAiDA,sBAoCC;AAQD,kBAEC;AAQD,oBAEC;AAQD,kBAEC;AAQD,sBAEC;AAYD,wBAEC;AA3ID,wCAA0C;AAC1C,2CAA4C;AAC5C,2DAAsD;AACtD,2DAAoD;AACpD,qDAA8C;AAC9C,uDAAgD;AAChD,uDAAgD;AAgBhD,MAAa,YAAY;IACvB,MAAM,CAAC,WAAW,CAChB,MAAc,EACd,WAA4B;QAE5B,OAAO,OAAO,CAAC,cAAc,CAAC,gBAAS,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;IAC/D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAClB,MAAc,EACd,WAA4B,EAC5B,YAAmB;QAEnB,MAAM,IAAI,GAAG;YACX,MAAM,kCAAc,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC;YAC9D,MAAM,8BAAY,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC;YAC5D,MAAM,8BAAY,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC;YAC5D,MAAM,4BAAW,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC;SAC5D;aACE,IAAI,EAAE;aACN,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,CAAC;aAC5C,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAA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AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,GAAG,CAAC,OAAe,EAAE;IACnC,OAAO,KAAK,CAAC,0BAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AACrC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,KAAK,CAAC,OAAe,EAAE;IACrC,OAAO,KAAK,CAAC,0BAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AACvC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,MAAM,CAAC,OAAe,EAAE;IACtC,OAAO,KAAK,CAAC,0BAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;AACxC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BindToFluentSyntax, Container as InversifyContainer, ServiceIdentifier } from 'inversify';
|
|
1
|
+
import { BindToFluentSyntax, GetAllOptions, GetOptions, Container as InversifyContainer, OptionalGetOptions, ServiceIdentifier } from 'inversify';
|
|
2
2
|
/**
|
|
3
3
|
* A Wrapper class for the Inversify Container.
|
|
4
4
|
* Allows the container into a N depth hierarchy module system.
|
|
@@ -15,8 +15,9 @@ export declare class Container {
|
|
|
15
15
|
*/
|
|
16
16
|
load(module: ContainerModule): void;
|
|
17
17
|
bind<T>(serviceIdentifier: ServiceIdentifier<T>): BindToFluentSyntax<T>;
|
|
18
|
-
get<T>(serviceIdentifier: ServiceIdentifier<T
|
|
19
|
-
getAsync<T>(serviceIdentifier: ServiceIdentifier<T
|
|
18
|
+
get<T>(serviceIdentifier: ServiceIdentifier<T>, options?: OptionalGetOptions): T;
|
|
19
|
+
getAsync<T>(serviceIdentifier: ServiceIdentifier<T>, options?: GetOptions): Promise<T>;
|
|
20
|
+
getAllAsync<T>(serviceIdentifier: ServiceIdentifier<T>, options?: GetAllOptions): Promise<T[]>;
|
|
20
21
|
isBound<T>(serviceIdentifier: ServiceIdentifier<T>): boolean;
|
|
21
22
|
unbind<T>(serviceIdentifier: ServiceIdentifier<T>): void;
|
|
22
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/dependency-injection/container.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,SAAS,IAAI,kBAAkB,EAC/B,iBAAiB,EAClB,MAAM,WAAW,CAAA;AAElB;;;GAGG;AACH,qBAAa,SAAS;IACb,SAAS,EAAE,kBAAkB,CAAA;IACpC,OAAO,CAAC,aAAa,CAAkC;;
|
|
1
|
+
{"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/dependency-injection/container.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,SAAS,IAAI,kBAAkB,EAC/B,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,WAAW,CAAA;AAElB;;;GAGG;AACH,qBAAa,SAAS;IACb,SAAS,EAAE,kBAAkB,CAAA;IACpC,OAAO,CAAC,aAAa,CAAkC;;IAQvD;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,eAAe;IAgB5B,IAAI,CAAC,CAAC,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC;IAIvE,GAAG,CAAC,CAAC,EACH,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC,EACvC,OAAO,CAAC,EAAE,kBAAkB,GAC3B,CAAC;IAOJ,QAAQ,CAAC,CAAC,EACR,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC,EACvC,OAAO,CAAC,EAAE,UAAU,GACnB,OAAO,CAAC,CAAC,CAAC;IAOb,WAAW,CAAC,CAAC,EACX,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC,EACvC,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,CAAC,EAAE,CAAC;IAIf,OAAO,CAAC,CAAC,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO;I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