@lerianstudio/sindarian-server 1.0.0-beta.2 → 1.0.0-beta.20
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 +52 -18
- package/dist/constants/keys.d.ts +1 -0
- package/dist/constants/keys.d.ts.map +1 -1
- package/dist/constants/keys.js +2 -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 +12 -1
- package/dist/controllers/decorators/route-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/route-decorator.js +24 -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/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/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -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 +60 -22
- package/dist/interceptor/decorators/use-interceptor-decorator.js.map +1 -1
- 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 +7 -13
- 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 +25 -0
- package/dist/server/server-factory.d.ts.map +1 -1
- package/dist/server/server-factory.js +98 -33
- package/dist/server/server-factory.js.map +1 -1
- package/dist/services/http-service.d.ts +2 -2
- package/dist/services/http-service.d.ts.map +1 -1
- package/dist/services/http-service.js.map +1 -1
- 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 -2
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
1
|
export type QueryMetadata = {
|
|
3
2
|
propertyKey: string | symbol;
|
|
4
3
|
parameterIndex: number;
|
|
5
|
-
schema?: () => z.ZodSchema;
|
|
6
4
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,2CAA4C;AAC5C,0EAA0E;AAO1E,MAAa,YAAY;IACvB,MAAM,CAAC,WAAW,CAChB,MAAc,EACd,WAA4B;QAE5B,IAAI,QAAQ,GAAkB,OAAO,CAAC,cAAc,CAClD,gBAAS,EACT,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,gBAAS,EACT,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,gDAAgD;QAChD,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,IAAA,2CAAsB,EAAC,IAAI,CAAC,CAAA;YAC5C,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAE7C,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,CAAA;YAExD,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,KAAK;gBAChB,cAAc,EAAE,QAAQ,CAAC,cAAc;aACxC,CAAA;QACH,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1CD,oCA0CC;AAED;;;;;GAKG;AACH,SAAgB,KAAK;IACnB,OAAO,UACL,MAAc,EACd,WAA4B,EAC5B,aAAqB;QAErB,gDAAgD;QAChD,OAAO,CAAC,cAAc,CACpB,gBAAS,EACT;YACE,WAAW;YACX,cAAc,EAAE,aAAa;SAC9B,EACD,MAAM,EACN,WAAW,CACZ,CAAA;IACH,CAAC,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.
|
|
@@ -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,CAgCxE;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;;;;;GAKG;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,31 +10,39 @@ 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;
|
|
@@ -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":"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"}
|
|
@@ -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;IAI5D,MAAM,CAAC,CAAC,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,IAAI;CAGzD;AAED,MAAM,MAAM,uBAAuB,GAAG,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAA;AAEpE;;;;GAIG;AACH,qBAAa,eAAe;IACnB,QAAQ,EAAE,uBAAuB,CAAA;gBAE5B,QAAQ,EAAE,uBAAuB;CAG9C"}
|
|
@@ -9,7 +9,9 @@ const inversify_1 = require("inversify");
|
|
|
9
9
|
class Container {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.loadedModules = new Set();
|
|
12
|
-
this.container = new inversify_1.Container(
|
|
12
|
+
this.container = new inversify_1.Container({
|
|
13
|
+
defaultScope: 'Singleton'
|
|
14
|
+
});
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Loads a module into the container.
|
|
@@ -31,12 +33,21 @@ class Container {
|
|
|
31
33
|
bind(serviceIdentifier) {
|
|
32
34
|
return this.container.bind(serviceIdentifier);
|
|
33
35
|
}
|
|
34
|
-
get(serviceIdentifier) {
|
|
36
|
+
get(serviceIdentifier, options) {
|
|
37
|
+
if (options !== undefined) {
|
|
38
|
+
return this.container.get(serviceIdentifier, options);
|
|
39
|
+
}
|
|
35
40
|
return this.container.get(serviceIdentifier);
|
|
36
41
|
}
|
|
37
|
-
getAsync(serviceIdentifier) {
|
|
42
|
+
getAsync(serviceIdentifier, options) {
|
|
43
|
+
if (options !== undefined) {
|
|
44
|
+
return this.container.getAsync(serviceIdentifier, options);
|
|
45
|
+
}
|
|
38
46
|
return this.container.getAsync(serviceIdentifier);
|
|
39
47
|
}
|
|
48
|
+
getAllAsync(serviceIdentifier, options) {
|
|
49
|
+
return this.container.getAllAsync(serviceIdentifier, options);
|
|
50
|
+
}
|
|
40
51
|
isBound(serviceIdentifier) {
|
|
41
52
|
return this.container.isBound(serviceIdentifier);
|
|
42
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/dependency-injection/container.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/dependency-injection/container.ts"],"names":[],"mappings":";;;AAAA,yCAOkB;AAElB;;;GAGG;AACH,MAAa,SAAS;IAIpB;QAFQ,kBAAa,GAAyB,IAAI,GAAG,EAAE,CAAA;QAGrD,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAkB,CAAC;YACtC,YAAY,EAAE,WAAW;SAC1B,CAAC,CAAA;IACJ,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,MAAuB;QAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CACb,qBAAqB,MAAM,kCAAkC,CAC9D,CAAA;QACH,CAAC;QAED,wDAAwD;QACxD,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACnC,OAAM;QACR,CAAC;QACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAE9B,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IAED,IAAI,CAAI,iBAAuC;QAC7C,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAC/C,CAAC;IAED,GAAG,CACD,iBAAuC,EACvC,OAA4B;QAE5B,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,iBAAiB,EAAE,OAAO,CAAM,CAAA;QAC5D,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,iBAAiB,CAAM,CAAA;IACnD,CAAC;IAED,QAAQ,CACN,iBAAuC,EACvC,OAAoB;QAEpB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;QAC5D,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAe,CAAA;IACjE,CAAC;IAED,WAAW,CACT,iBAAuC,EACvC,OAAuB;QAEvB,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;IAC/D,CAAC;IAED,OAAO,CAAI,iBAAuC;QAChD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAClD,CAAC;IAED,MAAM,CAAI,iBAAuC;QAC/C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAA;IAC1C,CAAC;CACF;AAtED,8BAsEC;AAID;;;;GAIG;AACH,MAAa,eAAe;IAG1B,YAAY,QAAiC;QAC3C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF;AAND,0CAMC"}
|
|
@@ -4,18 +4,15 @@ export declare class ApiException extends HttpException {
|
|
|
4
4
|
readonly code: string;
|
|
5
5
|
readonly title: string;
|
|
6
6
|
readonly message: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
title: string;
|
|
11
|
-
message: string;
|
|
12
|
-
};
|
|
7
|
+
private readonly metadata;
|
|
8
|
+
constructor(code: string, title: string, message: string, status?: HttpStatus, metadata?: any);
|
|
9
|
+
getResponse(): any;
|
|
13
10
|
}
|
|
14
11
|
export declare class BadRequestApiException extends ApiException {
|
|
15
12
|
constructor(message: string);
|
|
16
13
|
}
|
|
17
14
|
export declare class ValidationApiException extends ApiException {
|
|
18
|
-
constructor(message: string);
|
|
15
|
+
constructor(message: string, errors?: any);
|
|
19
16
|
}
|
|
20
17
|
export declare class UnauthorizedApiException extends ApiException {
|
|
21
18
|
constructor(message?: string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/api-exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,qBAAa,YAAa,SAAQ,aAAa;
|
|
1
|
+
{"version":3,"file":"api-exception.d.ts","sourceRoot":"","sources":["../../src/exceptions/api-exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,qBAAa,YAAa,SAAQ,aAAa;aAI3B,IAAI,EAAE,MAAM;aACZ,KAAK,EAAE,MAAM;aACb,OAAO,EAAE,MAAM;IALjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAK;gBAGZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAC/B,MAAM,GAAE,UAA6C,EACrD,QAAQ,GAAE,GAAQ;IAMpB,WAAW;CAQZ;AAED,qBAAa,sBAAuB,SAAQ,YAAY;gBAC1C,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,sBAAuB,SAAQ,YAAY;gBAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG;CAK1C;AAED,qBAAa,wBAAyB,SAAQ,YAAY;gBAC5C,OAAO,GAAE,MAAuB;CAG7C;AAED,qBAAa,qBAAsB,SAAQ,YAAY;gBACzC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,oBAAqB,SAAQ,YAAY;gBACxC,OAAO,EAAE,MAAM;CAG5B;AAED,qBAAa,+BAAgC,SAAQ,YAAY;gBACnD,OAAO,EAAE,MAAM;CAQ5B;AAED,qBAAa,+BAAgC,SAAQ,YAAY;gBACnD,OAAO,EAAE,MAAM;CAQ5B;AAED,qBAAa,8BAA+B,SAAQ,YAAY;gBAClD,OAAO,EAAE,MAAM;CAQ5B"}
|
|
@@ -4,17 +4,19 @@ exports.ServiceUnavailableApiException = exports.InternalServerErrorApiException
|
|
|
4
4
|
const http_status_1 = require("../constants/http-status");
|
|
5
5
|
const http_exception_1 = require("./http-exception");
|
|
6
6
|
class ApiException extends http_exception_1.HttpException {
|
|
7
|
-
constructor(code, title, message, status = http_status_1.HttpStatus.INTERNAL_SERVER_ERROR) {
|
|
7
|
+
constructor(code, title, message, status = http_status_1.HttpStatus.INTERNAL_SERVER_ERROR, metadata = {}) {
|
|
8
8
|
super(message, status);
|
|
9
9
|
this.code = code;
|
|
10
10
|
this.title = title;
|
|
11
11
|
this.message = message;
|
|
12
|
+
this.metadata = metadata;
|
|
12
13
|
}
|
|
13
14
|
getResponse() {
|
|
14
15
|
return {
|
|
15
16
|
code: this.code,
|
|
16
17
|
title: this.title,
|
|
17
|
-
message: this.message
|
|
18
|
+
message: this.message,
|
|
19
|
+
...this.metadata
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
}
|
|
@@ -26,8 +28,10 @@ class BadRequestApiException extends ApiException {
|
|
|
26
28
|
}
|
|
27
29
|
exports.BadRequestApiException = BadRequestApiException;
|
|
28
30
|
class ValidationApiException extends ApiException {
|
|
29
|
-
constructor(message) {
|
|
30
|
-
super('0007', 'Validation Error', message, http_status_1.HttpStatus.BAD_REQUEST
|
|
31
|
+
constructor(message, errors) {
|
|
32
|
+
super('0007', 'Validation Error', message, http_status_1.HttpStatus.BAD_REQUEST, {
|
|
33
|
+
errors
|
|
34
|
+
});
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
exports.ValidationApiException = ValidationApiException;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-exception.js","sourceRoot":"","sources":["../../src/exceptions/api-exception.ts"],"names":[],"mappings":";;;AAAA,yDAAoD;AACpD,qDAAgD;AAEhD,MAAa,YAAa,SAAQ,8BAAa;
|
|
1
|
+
{"version":3,"file":"api-exception.js","sourceRoot":"","sources":["../../src/exceptions/api-exception.ts"],"names":[],"mappings":";;;AAAA,yDAAoD;AACpD,qDAAgD;AAEhD,MAAa,YAAa,SAAQ,8BAAa;IAG7C,YACkB,IAAY,EACZ,KAAa,EACb,OAAe,EAC/B,SAAqB,wBAAU,CAAC,qBAAqB,EACrD,WAAgB,EAAE;QAElB,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QANN,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAQ;QAK/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;IAED,WAAW;QACT,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,GAAG,IAAI,CAAC,QAAQ;SACjB,CAAA;IACH,CAAC;CACF;AAtBD,oCAsBC;AAED,MAAa,sBAAuB,SAAQ,YAAY;IACtD,YAAY,OAAe;QACzB,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,wBAAU,CAAC,WAAW,CAAC,CAAA;IAC/D,CAAC;CACF;AAJD,wDAIC;AAED,MAAa,sBAAuB,SAAQ,YAAY;IACtD,YAAY,OAAe,EAAE,MAAY;QACvC,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,wBAAU,CAAC,WAAW,EAAE;YACjE,MAAM;SACP,CAAC,CAAA;IACJ,CAAC;CACF;AAND,wDAMC;AAED,MAAa,wBAAyB,SAAQ,YAAY;IACxD,YAAY,UAAkB,cAAc;QAC1C,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,wBAAU,CAAC,YAAY,CAAC,CAAA;IACjE,CAAC;CACF;AAJD,4DAIC;AAED,MAAa,qBAAsB,SAAQ,YAAY;IACrD,YAAY,OAAe;QACzB,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,wBAAU,CAAC,SAAS,CAAC,CAAA;IAC3D,CAAC;CACF;AAJD,sDAIC;AAED,MAAa,oBAAqB,SAAQ,YAAY;IACpD,YAAY,OAAe;QACzB,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,wBAAU,CAAC,SAAS,CAAC,CAAA;IAC3D,CAAC;CACF;AAJD,oDAIC;AAED,MAAa,+BAAgC,SAAQ,YAAY;IAC/D,YAAY,OAAe;QACzB,KAAK,CACH,MAAM,EACN,sBAAsB,EACtB,OAAO,EACP,wBAAU,CAAC,oBAAoB,CAChC,CAAA;IACH,CAAC;CACF;AATD,0EASC;AAED,MAAa,+BAAgC,SAAQ,YAAY;IAC/D,YAAY,OAAe;QACzB,KAAK,CACH,MAAM,EACN,uBAAuB,EACvB,OAAO,EACP,wBAAU,CAAC,qBAAqB,CACjC,CAAA;IACH,CAAC;CACF;AATD,0EASC;AAED,MAAa,8BAA+B,SAAQ,YAAY;IAC9D,YAAY,OAAe;QACzB,KAAK,CACH,MAAM,EACN,qBAAqB,EACrB,OAAO,EACP,wBAAU,CAAC,mBAAmB,CAC/B,CAAA;IACH,CAAC;CACF;AATD,wEASC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-exception-filter.d.ts","sourceRoot":"","sources":["../../src/exceptions/base-exception-filter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base-exception-filter.d.ts","sourceRoot":"","sources":["../../src/exceptions/base-exception-filter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,qBAAa,mBAAoB,YAAW,eAAe;IACnD,KAAK,CAAC,SAAS,EAAE,GAAG;;;CAmB3B"}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseExceptionFilter = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const api_exception_1 = require("./api-exception");
|
|
4
6
|
const server_1 = require("next/server");
|
|
5
7
|
class BaseExceptionFilter {
|
|
6
8
|
async catch(exception) {
|
|
7
|
-
|
|
9
|
+
if (exception instanceof api_exception_1.ApiException) {
|
|
10
|
+
const status = exception.getStatus ? exception.getStatus() : 500;
|
|
11
|
+
return server_1.NextResponse.json({
|
|
12
|
+
message: exception.message || 'Internal server error'
|
|
13
|
+
}, { status });
|
|
14
|
+
}
|
|
8
15
|
return server_1.NextResponse.json({
|
|
9
|
-
message: exception.message
|
|
10
|
-
}, { status });
|
|
16
|
+
message: exception.message
|
|
17
|
+
}, { status: constants_1.HttpStatus.INTERNAL_SERVER_ERROR });
|
|
11
18
|
}
|
|
12
19
|
}
|
|
13
20
|
exports.BaseExceptionFilter = BaseExceptionFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-exception-filter.js","sourceRoot":"","sources":["../../src/exceptions/base-exception-filter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"base-exception-filter.js","sourceRoot":"","sources":["../../src/exceptions/base-exception-filter.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,mDAA8C;AAE9C,wCAA0C;AAE1C,MAAa,mBAAmB;IAC9B,KAAK,CAAC,KAAK,CAAC,SAAc;QACxB,IAAI,SAAS,YAAY,4BAAY,EAAE,CAAC;YACtC,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;YAEhE,OAAO,qBAAY,CAAC,IAAI,CACtB;gBACE,OAAO,EAAE,SAAS,CAAC,OAAO,IAAI,uBAAuB;aACtD,EACD,EAAE,MAAM,EAAE,CACX,CAAA;QACH,CAAC;QAED,OAAO,qBAAY,CAAC,IAAI,CACtB;YACE,OAAO,EAAE,SAAS,CAAC,OAAO;SAC3B,EACD,EAAE,MAAM,EAAE,sBAAU,CAAC,qBAAqB,EAAE,CAC7C,CAAA;IACH,CAAC;CACF;AApBD,kDAoBC"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { Container } from '../../dependency-injection';
|
|
1
2
|
import { Class } from '../../types/class';
|
|
2
|
-
|
|
3
|
+
import { ExceptionFilter } from '../exception-filter';
|
|
4
|
+
export type FilterMetadata = {
|
|
5
|
+
filters: Class[];
|
|
6
|
+
};
|
|
7
|
+
export declare class FilterHandler {
|
|
8
|
+
static getMetadata(target: object): FilterMetadata;
|
|
9
|
+
static register(container: Container, target: object): Promise<void>;
|
|
10
|
+
static fetch(container: Container, target: object): Promise<ExceptionFilter[]>;
|
|
11
|
+
static _fetch(container: Container, filter: ExceptionFilter | Class<ExceptionFilter>): Promise<ExceptionFilter>;
|
|
12
|
+
static _register(container: Container, filter: ExceptionFilter | Class<ExceptionFilter>): Promise<void>;
|
|
13
|
+
}
|
|
3
14
|
export declare function UseFilters(filters: Class[]): ClassDecorator;
|
|
4
15
|
//# sourceMappingURL=use-filters-decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-filters-decorator.d.ts","sourceRoot":"","sources":["../../../src/exceptions/decorators/use-filters-decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"use-filters-decorator.d.ts","sourceRoot":"","sources":["../../../src/exceptions/decorators/use-filters-decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,KAAK,EAAE,CAAA;CACjB,CAAA;AAED,qBAAa,aAAa;IACxB,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc;WAQrC,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;WAQ7C,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;WAQ1C,MAAM,CACjB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC;WAUrC,SAAS,CACpB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,eAAe,GAAG,KAAK,CAAC,eAAe,CAAC;CAQnD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,cAAc,CAS3D"}
|
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FilterHandler = void 0;
|
|
4
4
|
exports.UseFilters = UseFilters;
|
|
5
5
|
const keys_1 = require("../../constants/keys");
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
class FilterHandler {
|
|
7
|
+
static getMetadata(target) {
|
|
8
|
+
const metadata = Reflect.getOwnMetadata(keys_1.FILTER_KEY, target);
|
|
9
|
+
if (metadata) {
|
|
10
|
+
return { filters: metadata };
|
|
11
|
+
}
|
|
12
|
+
return { filters: [] };
|
|
13
|
+
}
|
|
14
|
+
static async register(container, target) {
|
|
15
|
+
const { filters } = this.getMetadata(target);
|
|
16
|
+
await Promise.all(filters.map((filter) => FilterHandler._register(container, filter)));
|
|
17
|
+
}
|
|
18
|
+
static async fetch(container, target) {
|
|
19
|
+
const { filters } = this.getMetadata(target);
|
|
20
|
+
return Promise.all(filters.map((filter) => this._fetch(container, filter)));
|
|
21
|
+
}
|
|
22
|
+
static async _fetch(container, filter) {
|
|
23
|
+
// If it's a class constructor (function), resolve from container
|
|
24
|
+
if (typeof filter === 'function') {
|
|
25
|
+
return container.getAsync(filter);
|
|
26
|
+
}
|
|
27
|
+
// If it's an instance, resolve from container using its constructor
|
|
28
|
+
return container.getAsync(filter.constructor);
|
|
29
|
+
}
|
|
30
|
+
static async _register(container, filter) {
|
|
31
|
+
if (typeof filter === 'function') {
|
|
32
|
+
container.bind(filter).to(filter).inSingletonScope();
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
container.bind(filter.constructor).toConstantValue(filter);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
8
38
|
}
|
|
39
|
+
exports.FilterHandler = FilterHandler;
|
|
9
40
|
function UseFilters(filters) {
|
|
10
41
|
return (target) => {
|
|
11
42
|
const existingFilters = Reflect.getOwnMetadata(keys_1.FILTER_KEY, target) || [];
|