@tsed/platform-exceptions 7.0.0-beta.2 → 7.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/jest.config.js +14 -0
- package/lib/cjs/components/ErrorFilter.js +2 -3
- package/lib/cjs/components/ErrorFilter.js.map +1 -1
- package/lib/cjs/components/ExceptionFilter.js +1 -1
- package/lib/cjs/components/MongooseErrorFilter.js +1 -1
- package/lib/cjs/components/StringErrorFilter.js +1 -1
- package/lib/cjs/domain/ExceptionSchema.js +1 -1
- package/lib/cjs/domain/ExceptionSchema.js.map +1 -1
- package/lib/cjs/errors/ResourceNotFound.js +1 -0
- package/lib/cjs/errors/ResourceNotFound.js.map +1 -1
- package/lib/cjs/index.js +13 -15
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/ExceptionFilterMethods.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/PlatformExceptions.js +5 -6
- package/lib/cjs/services/PlatformExceptions.js.map +1 -1
- package/lib/esm/components/ErrorFilter.js +2 -3
- package/lib/esm/components/ErrorFilter.js.map +1 -1
- package/lib/esm/components/ExceptionFilter.js +2 -2
- package/lib/esm/components/MongooseErrorFilter.js +2 -2
- package/lib/esm/components/StringErrorFilter.js +1 -1
- package/lib/esm/decorators/catch.js +1 -1
- package/lib/esm/errors/ResourceNotFound.js +1 -0
- package/lib/esm/errors/ResourceNotFound.js.map +1 -1
- package/lib/esm/index.js +13 -15
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/ExceptionFilterMethods.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/PlatformExceptions.js +8 -9
- package/lib/esm/services/PlatformExceptions.js.map +1 -1
- package/lib/types/index.d.ts +6 -3
- package/lib/types/interfaces/ExceptionFilterMethods.d.ts +2 -2
- package/lib/types/services/PlatformExceptions.d.ts +3 -3
- package/package.json +34 -14
- package/readme.md +4 -4
- package/tsconfig.compile.esm.json +1 -12
package/jest.config.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// For a detailed explanation regarding each configuration property, visit:
|
|
2
|
+
// https://jestjs.io/docs/en/configuration.html
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
...require("@tsed/jest-config")(__dirname, "platform-exceptions"),
|
|
6
|
+
coverageThreshold: {
|
|
7
|
+
global: {
|
|
8
|
+
statements: 100,
|
|
9
|
+
branches: 94.73,
|
|
10
|
+
functions: 100,
|
|
11
|
+
lines: 100
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -18,9 +18,8 @@ let ErrorFilter = class ErrorFilter {
|
|
|
18
18
|
.body(env === core_1.Env.PROD ? "InternalServerError" : err);
|
|
19
19
|
}
|
|
20
20
|
mapError(error, env) {
|
|
21
|
-
var _a;
|
|
22
21
|
return {
|
|
23
|
-
name:
|
|
22
|
+
name: error.origin?.name || error.name,
|
|
24
23
|
message: error.message,
|
|
25
24
|
status: error.status || 500,
|
|
26
25
|
errors: this.getErrors(error),
|
|
@@ -41,7 +40,7 @@ let ErrorFilter = class ErrorFilter {
|
|
|
41
40
|
}, {});
|
|
42
41
|
}
|
|
43
42
|
};
|
|
44
|
-
ErrorFilter =
|
|
43
|
+
ErrorFilter = tslib_1.__decorate([
|
|
45
44
|
(0, catch_1.Catch)(Error)
|
|
46
45
|
], ErrorFilter);
|
|
47
46
|
exports.ErrorFilter = ErrorFilter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorFilter.js","sourceRoot":"","sources":["../../../src/components/ErrorFilter.ts"],"names":[],"mappings":";;;;AAAA,qCAA+B;AAE/B,+CAA0C;AAI1C,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB,KAAK,CAAC,KAAU,EAAE,GAAgB;QAChC,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAC,GAAG,GAAG,CAAC;QACpC,MAAM,GAAG,GAAG,IAAI,C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AED,QAAQ,CAAC,KAAU,EAAE,GAAS;QAC5B,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,KAAK,CAAC,IAAI;YACtC,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,GAAG;YAC3B,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC7B,KAAK,EAAE,GAAG,KAAK,UAAG,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SACjD,CAAC;IACJ,CAAC;IAES,SAAS,CAAC,KAAU;QAC5B,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAC,MAAM,EAAM,EAAE,EAAE;YAC1E,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;IAES,UAAU,CAAC,KAAU;QAC7B,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAC,OAAO,EAAM,EAAE,EAAE;YAC1E,OAAO;gBACL,GAAG,GAAG;gBACN,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;aACnB,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AAxCY,WAAW;IADvB,IAAA,aAAK,EAAC,KAAK,CAAC;GACA,WAAW,CAwCvB;AAxCY,kCAAW","sourcesContent":["import {Env} from \"@tsed/core\";\nimport {BaseContext} from \"@tsed/di\";\nimport {Catch} from \"../decorators/catch\";\nimport type {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n@Catch(Error)\nexport class ErrorFilter implements ExceptionFilterMethods {\n catch(error: any, ctx: BaseContext): void {\n const {response, logger, env} = ctx;\n const err = this.mapError(error, env);\n\n logger.error({\n error: {...err, stack: error.stack}\n });\n\n response\n .setHeaders(this.getHeaders(error))\n .status(err.status)\n .contentType(\"application/json\")\n .body(env === Env.PROD ? \"InternalServerError\" : err);\n }\n\n mapError(error: any, env?: Env) {\n return {\n name: error.origin?.name || error.name,\n message: error.message,\n status: error.status || 500,\n errors: this.getErrors(error),\n stack: env === Env.DEV ? error.stack : undefined\n };\n }\n\n protected getErrors(error: any) {\n return [error, error.origin].filter(Boolean).reduce((errs, {errors}: any) => {\n return errs.concat(errors).filter(Boolean);\n }, []);\n }\n\n protected getHeaders(error: any) {\n return [error, error.origin].filter(Boolean).reduce((obj, {headers}: any) => {\n return {\n ...obj,\n ...(headers || {})\n };\n }, {});\n }\n}\n"]}
|
|
@@ -16,7 +16,7 @@ let ExceptionFilter = class ExceptionFilter extends ErrorFilter_1.ErrorFilter {
|
|
|
16
16
|
response.setHeaders(this.getHeaders(error)).contentType("application/json").status(error.status).body(err);
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
ExceptionFilter =
|
|
19
|
+
ExceptionFilter = tslib_1.__decorate([
|
|
20
20
|
(0, catch_1.Catch)(exceptions_1.Exception)
|
|
21
21
|
], ExceptionFilter);
|
|
22
22
|
exports.ExceptionFilter = ExceptionFilter;
|
|
@@ -10,7 +10,7 @@ let MongooseErrorFilter = class MongooseErrorFilter extends ErrorFilter_1.ErrorF
|
|
|
10
10
|
return super.catch(new exceptions_1.BadRequest(error.message, error), ctx);
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
MongooseErrorFilter =
|
|
13
|
+
MongooseErrorFilter = tslib_1.__decorate([
|
|
14
14
|
(0, catch_1.Catch)("MongooseError", "MongoError")
|
|
15
15
|
], MongooseErrorFilter);
|
|
16
16
|
exports.MongooseErrorFilter = MongooseErrorFilter;
|
|
@@ -9,7 +9,7 @@ let StringErrorFilter = class StringErrorFilter {
|
|
|
9
9
|
ctx.response.status(404).body(toHTML(error));
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
StringErrorFilter =
|
|
12
|
+
StringErrorFilter = tslib_1.__decorate([
|
|
13
13
|
(0, catch_1.Catch)(String)
|
|
14
14
|
], StringErrorFilter);
|
|
15
15
|
exports.StringErrorFilter = StringErrorFilter;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const Exceptions =
|
|
4
|
+
const Exceptions = tslib_1.__importStar(require("@tsed/exceptions"));
|
|
5
5
|
const exceptions_1 = require("@tsed/exceptions");
|
|
6
6
|
const schema_1 = require("@tsed/schema");
|
|
7
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExceptionSchema.js","sourceRoot":"","sources":["../../../src/domain/ExceptionSchema.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ExceptionSchema.js","sourceRoot":"","sources":["../../../src/domain/ExceptionSchema.ts"],"names":[],"mappings":";;;AAAA,qEAA+C;AAC/C,iDAA2C;AAC3C,yCAAuG;AAEvG;;GAEG;AACH,MAAM,WAAW,GAAG,IAAA,eAAM,EAAC;IACzB,IAAI,EAAE,IAAA,eAAM,GAAE,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,gBAAgB,CAAC;IACvD,OAAO,EAAE,IAAA,eAAM,GAAE,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,kBAAkB,CAAC;CAC7D,CAAC;KACC,KAAK,CAAC,cAAc,CAAC;KACrB,OAAO,EAAE,CAAC;AAEb,IAAA,aAAI,EAAC,sBAAS,CAAC,CAAC,UAAU,CAAC;IACzB,IAAI,EAAE,IAAA,eAAM,GAAE,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC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port {array, defineStatusModel, from, getStatusConstant, number, object, string} from \"@tsed/schema\";\n\n/**\n * @ignore\n */\nconst ErrorSchema = object({\n name: string().required().description(\"The error name\"),\n message: string().required().description(\"An error message\")\n})\n .label(\"GenericError\")\n .unknown();\n\nfrom(Exception).properties({\n name: string().required().description(\"The error name\"),\n message: string().required().description(\"An error message\"),\n status: number().required().description(\"The status code of the exception\"),\n errors: array().items(ErrorSchema).description(\"A list of related errors\"),\n stack: string().description(\"The stack trace (only in development mode)\")\n});\n\n// Auto load models for all Exceptions\nObject.values(Exceptions).forEach((target: any) => {\n if (target !== Exception && target.STATUS) {\n if (target.STATUS > 302) {\n const name = getStatusConstant(target.STATUS);\n from(target).properties({\n name: string().required().example(name).default(name).description(\"The error name\"),\n status: number().required().example(target.STATUS).default(target.STATUS).description(\"The status code of the exception\")\n });\n\n defineStatusModel(target.STATUS, target);\n }\n }\n});\n"]}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ResourceNotFound = void 0;
|
|
4
4
|
const exceptions_1 = require("@tsed/exceptions");
|
|
5
5
|
class ResourceNotFound extends exceptions_1.NotFound {
|
|
6
|
+
url;
|
|
6
7
|
constructor(url) {
|
|
7
8
|
super(`Resource "${url}" not found`);
|
|
8
9
|
this.url = url;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceNotFound.js","sourceRoot":"","sources":["../../../src/errors/ResourceNotFound.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAE1C,MAAa,gBAAiB,SAAQ,qBAAQ;
|
|
1
|
+
{"version":3,"file":"ResourceNotFound.js","sourceRoot":"","sources":["../../../src/errors/ResourceNotFound.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAE1C,MAAa,gBAAiB,SAAQ,qBAAQ;IACnC,GAAG,CAAS;IAErB,YAAY,GAAW;QACrB,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC,CAAC;QAErC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF;AARD,4CAQC","sourcesContent":["import {NotFound} from \"@tsed/exceptions\";\n\nexport class ResourceNotFound extends NotFound {\n readonly url: string;\n\n constructor(url: string) {\n super(`Resource \"${url}\" not found`);\n\n this.url = url;\n }\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
(0, tslib_1.__exportStar)(require("./interfaces/ExceptionFilterMethods"), exports);
|
|
15
|
-
// middlewares
|
|
16
|
-
(0, tslib_1.__exportStar)(require("./services/PlatformExceptions"), exports);
|
|
17
|
-
// errors
|
|
18
|
-
(0, tslib_1.__exportStar)(require("./errors/ResourceNotFound"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./components/ErrorFilter"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./components/ExceptionFilter"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./components/MongooseErrorFilter"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./components/StringErrorFilter"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./decorators/catch"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./domain/ExceptionFiltersContainer"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./domain/ExceptionSchema"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./errors/ResourceNotFound"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./interfaces/ExceptionFilterMethods"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./services/PlatformExceptions"), exports);
|
|
19
17
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mEAAyC;AACzC,uEAA6C;AAC7C,2EAAiD;AACjD,yEAA+C;AAC/C,6DAAmC;AACnC,6EAAmD;AACnD,mEAAyC;AACzC,oEAA0C;AAC1C,8EAAoD;AACpD,wEAA8C","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/ErrorFilter\";\nexport * from \"./components/ExceptionFilter\";\nexport * from \"./components/MongooseErrorFilter\";\nexport * from \"./components/StringErrorFilter\";\nexport * from \"./decorators/catch\";\nexport * from \"./domain/ExceptionFiltersContainer\";\nexport * from \"./domain/ExceptionSchema\";\nexport * from \"./errors/ResourceNotFound\";\nexport * from \"./interfaces/ExceptionFilterMethods\";\nexport * from \"./services/PlatformExceptions\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExceptionFilterMethods.js","sourceRoot":"","sources":["../../../src/interfaces/ExceptionFilterMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"ExceptionFilterMethods.js","sourceRoot":"","sources":["../../../src/interfaces/ExceptionFilterMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {DIContext} from \"@tsed/di\";\n\nexport interface ExceptionFilterMethods<T = unknown> {\n catch(error: T, ctx: DIContext): void;\n}\n"]}
|
|
@@ -16,9 +16,8 @@ const ResourceNotFound_1 = require("../errors/ResourceNotFound");
|
|
|
16
16
|
* @platform
|
|
17
17
|
*/
|
|
18
18
|
let PlatformExceptions = class PlatformExceptions {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
19
|
+
types = new Map();
|
|
20
|
+
injector;
|
|
22
21
|
$onInit() {
|
|
23
22
|
ExceptionFiltersContainer_1.ExceptionFiltersContainer.forEach((token, type) => {
|
|
24
23
|
this.types.set(type, this.injector.get(token));
|
|
@@ -42,11 +41,11 @@ let PlatformExceptions = class PlatformExceptions {
|
|
|
42
41
|
return this.catch(new ResourceNotFound_1.ResourceNotFound(ctx.request.url), ctx);
|
|
43
42
|
}
|
|
44
43
|
};
|
|
45
|
-
|
|
44
|
+
tslib_1.__decorate([
|
|
46
45
|
(0, di_1.Inject)(),
|
|
47
|
-
|
|
46
|
+
tslib_1.__metadata("design:type", di_1.InjectorService)
|
|
48
47
|
], PlatformExceptions.prototype, "injector", void 0);
|
|
49
|
-
PlatformExceptions =
|
|
48
|
+
PlatformExceptions = tslib_1.__decorate([
|
|
50
49
|
(0, di_1.Injectable)({
|
|
51
50
|
imports: [ErrorFilter_1.ErrorFilter, ExceptionFilter_1.ExceptionFilter, MongooseErrorFilter_1.MongooseErrorFilter, StringErrorFilter_1.StringErrorFilter]
|
|
52
51
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformExceptions.js","sourceRoot":"","sources":["../../../src/services/PlatformExceptions.ts"],"names":[],"mappings":";;;;AAAA,qCAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"PlatformExceptions.js","sourceRoot":"","sources":["../../../src/services/PlatformExceptions.ts"],"names":[],"mappings":";;;;AAAA,qCAAwD;AACxD,iCAAqF;AACrF,2DAAsD;AACtD,mEAA8D;AAC9D,2EAAsE;AACtE,uEAAkE;AAClE,mFAAkG;AAClG,iEAA4D;AAG5D;;;;GAIG;AAIH,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAC7B,KAAK,GAAoD,IAAI,GAAG,EAAE,CAAC;IAGnE,QAAQ,CAAkB;IAE1B,OAAO;QACL,qDAAyB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChD,IAAI,CAAC,KAAK,CAAC,GAA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AAkB,CAkC9B;AAlCY,gDAAkB","sourcesContent":["import {ancestorsOf, classOf, nameOf} from \"@tsed/core\";\nimport {BaseContext, DIContext, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {ErrorFilter} from \"../components/ErrorFilter\";\nimport {ExceptionFilter} from \"../components/ExceptionFilter\";\nimport {MongooseErrorFilter} from \"../components/MongooseErrorFilter\";\nimport {StringErrorFilter} from \"../components/StringErrorFilter\";\nimport {ExceptionFilterKey, ExceptionFiltersContainer} from \"../domain/ExceptionFiltersContainer\";\nimport {ResourceNotFound} from \"../errors/ResourceNotFound\";\nimport {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n/**\n * Catch all errors and return the json error with the right status code when it's possible.\n *\n * @platform\n */\n@Injectable({\n imports: [ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]\n})\nexport class PlatformExceptions {\n types: Map<ExceptionFilterKey, ExceptionFilterMethods> = new Map();\n\n @Inject()\n injector: InjectorService;\n\n $onInit() {\n ExceptionFiltersContainer.forEach((token, type) => {\n this.types.set(type, this.injector.get(token)!);\n });\n }\n\n catch(error: unknown, ctx: DIContext) {\n const name = nameOf(classOf(error));\n\n if (name && this.types.has(name)) {\n return this.types.get(name)!.catch(error, ctx);\n }\n\n const target = ancestorsOf(error)\n .reverse()\n .find((target) => this.types.has(target));\n\n if (target) {\n return this.types.get(target)!.catch(error, ctx);\n }\n\n // default\n return this.types.get(Error)!.catch(error, ctx);\n }\n\n resourceNotFound(ctx: DIContext) {\n return this.catch(new ResourceNotFound(ctx.request.url), ctx);\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { Env } from "@tsed/core";
|
|
3
|
-
import { Catch } from "../decorators/catch";
|
|
3
|
+
import { Catch } from "../decorators/catch.js";
|
|
4
4
|
let ErrorFilter = class ErrorFilter {
|
|
5
5
|
catch(error, ctx) {
|
|
6
6
|
const { response, logger, env } = ctx;
|
|
@@ -15,9 +15,8 @@ let ErrorFilter = class ErrorFilter {
|
|
|
15
15
|
.body(env === Env.PROD ? "InternalServerError" : err);
|
|
16
16
|
}
|
|
17
17
|
mapError(error, env) {
|
|
18
|
-
var _a;
|
|
19
18
|
return {
|
|
20
|
-
name:
|
|
19
|
+
name: error.origin?.name || error.name,
|
|
21
20
|
message: error.message,
|
|
22
21
|
status: error.status || 500,
|
|
23
22
|
errors: this.getErrors(error),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorFilter.js","sourceRoot":"","sources":["../../../src/components/ErrorFilter.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAC,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAI1C,IAAa,WAAW,GAAxB,MAAa,WAAW;IACtB,KAAK,CAAC,KAAU,EAAE,GAAgB;QAChC,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAC,GAAG,GAAG,CAAC;QACpC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAEtC,MAAM,CAAC,KAAK,CAAC;YACX,KAAK,EAAE,EAAC,GAAG,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAC;SACpC,CAAC,CAAC;QAEH,QAAQ;aACL,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aAClC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;aAClB,WAAW,CAAC,kBAAkB,CAAC;aAC/B,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;IAED,QAAQ,CAAC,KAAU,EAAE,GAAS
|
|
1
|
+
{"version":3,"file":"ErrorFilter.js","sourceRoot":"","sources":["../../../src/components/ErrorFilter.ts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OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAC,MAAM,EAAM,EAAE,EAAE;YAC1E,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;IAES,UAAU,CAAC,KAAU;QAC7B,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAC,OAAO,EAAM,EAAE,EAAE;YAC1E,OAAO;gBACL,GAAG,GAAG;gBACN,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;aACnB,CAAC;QACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;CACF,CAAA;AAxCY,WAAW;IADvB,KAAK,CAAC,KAAK,CAAC;GACA,WAAW,CAwCvB;SAxCY,WAAW","sourcesContent":["import {Env} from \"@tsed/core\";\nimport {BaseContext} from \"@tsed/di\";\nimport {Catch} from \"../decorators/catch\";\nimport type {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n@Catch(Error)\nexport class ErrorFilter implements ExceptionFilterMethods {\n catch(error: any, ctx: BaseContext): void {\n const {response, logger, env} = ctx;\n const err = this.mapError(error, env);\n\n logger.error({\n error: {...err, stack: error.stack}\n });\n\n response\n .setHeaders(this.getHeaders(error))\n .status(err.status)\n .contentType(\"application/json\")\n .body(env === Env.PROD ? \"InternalServerError\" : err);\n }\n\n mapError(error: any, env?: Env) {\n return {\n name: error.origin?.name || error.name,\n message: error.message,\n status: error.status || 500,\n errors: this.getErrors(error),\n stack: env === Env.DEV ? error.stack : undefined\n };\n }\n\n protected getErrors(error: any) {\n return [error, error.origin].filter(Boolean).reduce((errs, {errors}: any) => {\n return errs.concat(errors).filter(Boolean);\n }, []);\n }\n\n protected getHeaders(error: any) {\n return [error, error.origin].filter(Boolean).reduce((obj, {headers}: any) => {\n return {\n ...obj,\n ...(headers || {})\n };\n }, {});\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { Exception } from "@tsed/exceptions";
|
|
3
|
-
import { Catch } from "../decorators/catch";
|
|
4
|
-
import { ErrorFilter } from "./ErrorFilter";
|
|
3
|
+
import { Catch } from "../decorators/catch.js";
|
|
4
|
+
import { ErrorFilter } from "./ErrorFilter.js";
|
|
5
5
|
let ExceptionFilter = class ExceptionFilter extends ErrorFilter {
|
|
6
6
|
catch(error, ctx) {
|
|
7
7
|
const { response, logger, env } = ctx;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { BadRequest } from "@tsed/exceptions";
|
|
3
|
-
import { Catch } from "../decorators/catch";
|
|
4
|
-
import { ErrorFilter } from "./ErrorFilter";
|
|
3
|
+
import { Catch } from "../decorators/catch.js";
|
|
4
|
+
import { ErrorFilter } from "./ErrorFilter.js";
|
|
5
5
|
let MongooseErrorFilter = class MongooseErrorFilter extends ErrorFilter {
|
|
6
6
|
catch(error, ctx) {
|
|
7
7
|
return super.catch(new BadRequest(error.message, error), ctx);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { Catch } from "../decorators/catch";
|
|
2
|
+
import { Catch } from "../decorators/catch.js";
|
|
3
3
|
const toHTML = (message = "") => message.replace(/\n/gi, "<br />");
|
|
4
4
|
let StringErrorFilter = class StringErrorFilter {
|
|
5
5
|
catch(error, ctx) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { registerProvider } from "@tsed/di";
|
|
2
|
-
import { registerExceptionType } from "../domain/ExceptionFiltersContainer";
|
|
2
|
+
import { registerExceptionType } from "../domain/ExceptionFiltersContainer.js";
|
|
3
3
|
/**
|
|
4
4
|
* Register a new class to handle an specific exception.
|
|
5
5
|
* @decorator
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceNotFound.js","sourceRoot":"","sources":["../../../src/errors/ResourceNotFound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAE1C,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;
|
|
1
|
+
{"version":3,"file":"ResourceNotFound.js","sourceRoot":"","sources":["../../../src/errors/ResourceNotFound.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAE1C,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IACnC,GAAG,CAAS;IAErB,YAAY,GAAW;QACrB,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC,CAAC;QAErC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF","sourcesContent":["import {NotFound} from \"@tsed/exceptions\";\n\nexport class ResourceNotFound extends NotFound {\n readonly url: string;\n\n constructor(url: string) {\n super(`Resource \"${url}\" not found`);\n\n this.url = url;\n }\n}\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./components/ErrorFilter";
|
|
5
|
-
export * from "./components/
|
|
6
|
-
|
|
7
|
-
export * from "./
|
|
8
|
-
|
|
9
|
-
export * from "./domain/ExceptionFiltersContainer";
|
|
10
|
-
export * from "./domain/ExceptionSchema";
|
|
11
|
-
export * from "./
|
|
12
|
-
|
|
13
|
-
export * from "./services/PlatformExceptions";
|
|
14
|
-
// errors
|
|
15
|
-
export * from "./errors/ResourceNotFound";
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./components/ErrorFilter.js";
|
|
5
|
+
export * from "./components/ExceptionFilter.js";
|
|
6
|
+
export * from "./components/MongooseErrorFilter.js";
|
|
7
|
+
export * from "./components/StringErrorFilter.js";
|
|
8
|
+
export * from "./decorators/catch.js";
|
|
9
|
+
export * from "./domain/ExceptionFiltersContainer.js";
|
|
10
|
+
export * from "./domain/ExceptionSchema.js";
|
|
11
|
+
export * from "./errors/ResourceNotFound.js";
|
|
12
|
+
export * from "./interfaces/ExceptionFilterMethods.js";
|
|
13
|
+
export * from "./services/PlatformExceptions.js";
|
|
16
14
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,oBAAoB,CAAC;AACnC,cAAc,oCAAoC,CAAC;AACnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qCAAqC,CAAC;AACpD,cAAc,+BAA+B,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/ErrorFilter\";\nexport * from \"./components/ExceptionFilter\";\nexport * from \"./components/MongooseErrorFilter\";\nexport * from \"./components/StringErrorFilter\";\nexport * from \"./decorators/catch\";\nexport * from \"./domain/ExceptionFiltersContainer\";\nexport * from \"./domain/ExceptionSchema\";\nexport * from \"./errors/ResourceNotFound\";\nexport * from \"./interfaces/ExceptionFilterMethods\";\nexport * from \"./services/PlatformExceptions\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExceptionFilterMethods.js","sourceRoot":"","sources":["../../../src/interfaces/ExceptionFilterMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"ExceptionFilterMethods.js","sourceRoot":"","sources":["../../../src/interfaces/ExceptionFilterMethods.ts"],"names":[],"mappings":"","sourcesContent":["import {DIContext} from \"@tsed/di\";\n\nexport interface ExceptionFilterMethods<T = unknown> {\n catch(error: T, ctx: DIContext): void;\n}\n"]}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { ancestorsOf, classOf, nameOf } from "@tsed/core";
|
|
3
3
|
import { Inject, Injectable, InjectorService } from "@tsed/di";
|
|
4
|
-
import { ErrorFilter } from "../components/ErrorFilter";
|
|
5
|
-
import { ExceptionFilter } from "../components/ExceptionFilter";
|
|
6
|
-
import { MongooseErrorFilter } from "../components/MongooseErrorFilter";
|
|
7
|
-
import { StringErrorFilter } from "../components/StringErrorFilter";
|
|
8
|
-
import { ExceptionFiltersContainer } from "../domain/ExceptionFiltersContainer";
|
|
9
|
-
import { ResourceNotFound } from "../errors/ResourceNotFound";
|
|
4
|
+
import { ErrorFilter } from "../components/ErrorFilter.js";
|
|
5
|
+
import { ExceptionFilter } from "../components/ExceptionFilter.js";
|
|
6
|
+
import { MongooseErrorFilter } from "../components/MongooseErrorFilter.js";
|
|
7
|
+
import { StringErrorFilter } from "../components/StringErrorFilter.js";
|
|
8
|
+
import { ExceptionFiltersContainer } from "../domain/ExceptionFiltersContainer.js";
|
|
9
|
+
import { ResourceNotFound } from "../errors/ResourceNotFound.js";
|
|
10
10
|
/**
|
|
11
11
|
* Catch all errors and return the json error with the right status code when it's possible.
|
|
12
12
|
*
|
|
13
13
|
* @platform
|
|
14
14
|
*/
|
|
15
15
|
let PlatformExceptions = class PlatformExceptions {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
16
|
+
types = new Map();
|
|
17
|
+
injector;
|
|
19
18
|
$onInit() {
|
|
20
19
|
ExceptionFiltersContainer.forEach((token, type) => {
|
|
21
20
|
this.types.set(type, this.injector.get(token));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlatformExceptions.js","sourceRoot":"","sources":["../../../src/services/PlatformExceptions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"PlatformExceptions.js","sourceRoot":"","sources":["../../../src/services/PlatformExceptions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,YAAY,CAAC;AACxD,OAAO,EAAyB,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AACrF,OAAO,EAAC,WAAW,EAAC,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAC,iBAAiB,EAAC,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAqB,yBAAyB,EAAC,MAAM,qCAAqC,CAAC;AAClG,OAAO,EAAC,gBAAgB,EAAC,MAAM,4BAA4B,CAAC;AAG5D;;;;GAIG;AAIH,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAC7B,KAAK,GAAoD,IAAI,GAAG,EAAE,CAAC;IAGnE,QAAQ,CAAkB;IAE1B,OAAO;QACL,yBAAyB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAc,EAAE,GAAc;QAClC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAEpC,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAChC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;SAChD;QAED,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC;aAC9B,OAAO,EAAE;aACT,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QAE5C,IAAI,MAAM,EAAE;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;SAClD;QAED,UAAU;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC;IAED,gBAAgB,CAAC,GAAc;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;CACF,CAAA;AA9BC;IADC,MAAM,EAAE;8BACC,eAAe;oDAAC;AAJf,kBAAkB;IAH9B,UAAU,CAAC;QACV,OAAO,EAAE,CAAC,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,CAAC;KAChF,CAAC;GACW,kBAAkB,CAkC9B;SAlCY,kBAAkB","sourcesContent":["import {ancestorsOf, classOf, nameOf} from \"@tsed/core\";\nimport {BaseContext, DIContext, Inject, Injectable, InjectorService} from \"@tsed/di\";\nimport {ErrorFilter} from \"../components/ErrorFilter\";\nimport {ExceptionFilter} from \"../components/ExceptionFilter\";\nimport {MongooseErrorFilter} from \"../components/MongooseErrorFilter\";\nimport {StringErrorFilter} from \"../components/StringErrorFilter\";\nimport {ExceptionFilterKey, ExceptionFiltersContainer} from \"../domain/ExceptionFiltersContainer\";\nimport {ResourceNotFound} from \"../errors/ResourceNotFound\";\nimport {ExceptionFilterMethods} from \"../interfaces/ExceptionFilterMethods\";\n\n/**\n * Catch all errors and return the json error with the right status code when it's possible.\n *\n * @platform\n */\n@Injectable({\n imports: [ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]\n})\nexport class PlatformExceptions {\n types: Map<ExceptionFilterKey, ExceptionFilterMethods> = new Map();\n\n @Inject()\n injector: InjectorService;\n\n $onInit() {\n ExceptionFiltersContainer.forEach((token, type) => {\n this.types.set(type, this.injector.get(token)!);\n });\n }\n\n catch(error: unknown, ctx: DIContext) {\n const name = nameOf(classOf(error));\n\n if (name && this.types.has(name)) {\n return this.types.get(name)!.catch(error, ctx);\n }\n\n const target = ancestorsOf(error)\n .reverse()\n .find((target) => this.types.has(target));\n\n if (target) {\n return this.types.get(target)!.catch(error, ctx);\n }\n\n // default\n return this.types.get(Error)!.catch(error, ctx);\n }\n\n resourceNotFound(ctx: DIContext) {\n return this.catch(new ResourceNotFound(ctx.request.url), ctx);\n }\n}\n"]}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
3
4
|
export * from "./components/ErrorFilter";
|
|
5
|
+
export * from "./components/ExceptionFilter";
|
|
4
6
|
export * from "./components/MongooseErrorFilter";
|
|
7
|
+
export * from "./components/StringErrorFilter";
|
|
5
8
|
export * from "./decorators/catch";
|
|
6
9
|
export * from "./domain/ExceptionFiltersContainer";
|
|
7
10
|
export * from "./domain/ExceptionSchema";
|
|
11
|
+
export * from "./errors/ResourceNotFound";
|
|
8
12
|
export * from "./interfaces/ExceptionFilterMethods";
|
|
9
13
|
export * from "./services/PlatformExceptions";
|
|
10
|
-
export * from "./errors/ResourceNotFound";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DIContext, InjectorService } from "@tsed/di";
|
|
2
2
|
import { ExceptionFilterKey } from "../domain/ExceptionFiltersContainer";
|
|
3
3
|
import { ExceptionFilterMethods } from "../interfaces/ExceptionFilterMethods";
|
|
4
4
|
/**
|
|
@@ -10,6 +10,6 @@ export declare class PlatformExceptions {
|
|
|
10
10
|
types: Map<ExceptionFilterKey, ExceptionFilterMethods>;
|
|
11
11
|
injector: InjectorService;
|
|
12
12
|
$onInit(): void;
|
|
13
|
-
catch(error: unknown, ctx:
|
|
14
|
-
resourceNotFound(ctx:
|
|
13
|
+
catch(error: unknown, ctx: DIContext): void;
|
|
14
|
+
resourceNotFound(ctx: DIContext): void;
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-exceptions",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.20",
|
|
4
4
|
"description": "Platform exceptions module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/cjs/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
8
9
|
"typings": "./lib/types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
"types": "./lib/types/index.d.ts",
|
|
@@ -13,30 +14,49 @@
|
|
|
13
14
|
"default": "./lib/esm/index.js"
|
|
14
15
|
},
|
|
15
16
|
"scripts": {
|
|
16
|
-
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
17
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
|
-
"build:esm": "tsc --build tsconfig.compile.esm.json"
|
|
19
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
21
|
+
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
|
|
19
22
|
},
|
|
20
23
|
"dependencies": {
|
|
21
|
-
"tslib": "2.
|
|
24
|
+
"tslib": "2.4.0"
|
|
22
25
|
},
|
|
23
26
|
"devDependencies": {
|
|
24
|
-
"@tsed/core": "7.0.0-beta.
|
|
25
|
-
"@tsed/di": "7.0.0-beta.
|
|
26
|
-
"@tsed/exceptions": "7.0.0-beta.
|
|
27
|
-
"@tsed/schema": "7.0.0-beta.
|
|
27
|
+
"@tsed/core": "7.0.0-beta.20",
|
|
28
|
+
"@tsed/di": "7.0.0-beta.20",
|
|
29
|
+
"@tsed/exceptions": "7.0.0-beta.20",
|
|
30
|
+
"@tsed/schema": "7.0.0-beta.20"
|
|
28
31
|
},
|
|
29
32
|
"peerDependencies": {
|
|
30
|
-
"@tsed/core": "^7.0.0-beta.
|
|
31
|
-
"@tsed/di": "^7.0.0-beta.
|
|
32
|
-
"@tsed/exceptions": "^7.0.0-beta.
|
|
33
|
-
"@tsed/schema": "^7.0.0-beta.
|
|
33
|
+
"@tsed/core": "^7.0.0-beta.20",
|
|
34
|
+
"@tsed/di": "^7.0.0-beta.20",
|
|
35
|
+
"@tsed/exceptions": "^7.0.0-beta.20",
|
|
36
|
+
"@tsed/schema": "^7.0.0-beta.20"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"@tsed/core": {
|
|
40
|
+
"optional": false
|
|
41
|
+
},
|
|
42
|
+
"@tsed/di": {
|
|
43
|
+
"optional": false
|
|
44
|
+
},
|
|
45
|
+
"@tsed/exceptions": {
|
|
46
|
+
"optional": false
|
|
47
|
+
},
|
|
48
|
+
"@tsed/schema": {
|
|
49
|
+
"optional": false
|
|
50
|
+
}
|
|
34
51
|
},
|
|
35
52
|
"repository": "https://github.com/tsedio/tsed",
|
|
36
53
|
"bugs": {
|
|
37
54
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
38
55
|
},
|
|
39
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
56
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/platform/platform-exceptions",
|
|
40
57
|
"author": "Romain Lenzotti",
|
|
41
|
-
"license": "MIT"
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"tag": "beta"
|
|
61
|
+
}
|
|
42
62
|
}
|
package/readme.md
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
12
|
[](https://github.com/semantic-release/semantic-release)
|
|
13
13
|
[](https://github.com/prettier/prettier)
|
|
14
|
-
[](https://github.com/sponsors/romakita)
|
|
15
|
+
[](https://opencollective.com/tsed)
|
|
15
16
|
|
|
16
17
|
</div>
|
|
17
18
|
|
|
@@ -36,18 +37,17 @@ npm install --save @tsed/platform-exceptions
|
|
|
36
37
|
```
|
|
37
38
|
|
|
38
39
|
## Contributors
|
|
40
|
+
|
|
39
41
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html).
|
|
40
42
|
|
|
41
43
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
42
44
|
|
|
43
|
-
|
|
44
45
|
## Backers
|
|
45
46
|
|
|
46
47
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
47
48
|
|
|
48
49
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
|
|
49
50
|
|
|
50
|
-
|
|
51
51
|
## Sponsors
|
|
52
52
|
|
|
53
53
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -56,7 +56,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
56
56
|
|
|
57
57
|
The MIT License (MIT)
|
|
58
58
|
|
|
59
|
-
Copyright (c) 2016 -
|
|
59
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
60
60
|
|
|
61
61
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
62
62
|
|
|
@@ -8,16 +8,5 @@
|
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"declarationDir": "./lib/types"
|
|
10
10
|
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"test",
|
|
14
|
-
"lib",
|
|
15
|
-
"benchmark",
|
|
16
|
-
"coverage",
|
|
17
|
-
"spec",
|
|
18
|
-
"**/*.benchmark.ts",
|
|
19
|
-
"**/*.spec.ts",
|
|
20
|
-
"keys",
|
|
21
|
-
"jest.config.js"
|
|
22
|
-
]
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
23
12
|
}
|