@tsed/platform-exceptions 8.0.0-rc.4 → 8.0.0-rc.6

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.
@@ -1,4 +1,4 @@
1
- import { registerProvider } from "@tsed/di";
1
+ import { injectable } from "@tsed/di";
2
2
  import { registerExceptionType } from "../domain/ExceptionFiltersContainer.js";
3
3
  /**
4
4
  * Register a new class to handle an specific exception.
@@ -10,10 +10,7 @@ export function Catch(...types) {
10
10
  types.forEach((type) => {
11
11
  registerExceptionType(type, target);
12
12
  });
13
- registerProvider({
14
- provide: target,
15
- useClass: target
16
- });
13
+ injectable(target).class(target);
17
14
  };
18
15
  }
19
16
  //# sourceMappingURL=catch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"catch.js","sourceRoot":"","sources":["../../../src/decorators/catch.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAC,qBAAqB,EAAC,MAAM,wCAAwC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,GAAG,KAAqC;IAC5D,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,qBAAqB,CAAC,IAAI,EAAE,MAAa,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QACH,gBAAgB,CAAC;YACf,OAAO,EAAE,MAAM;YACf,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"catch.js","sourceRoot":"","sources":["../../../src/decorators/catch.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAmB,MAAM,UAAU,CAAC;AAEtD,OAAO,EAAC,qBAAqB,EAAC,MAAM,wCAAwC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,GAAG,KAAqC;IAC5D,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,qBAAqB,CAAC,IAAI,EAAE,MAAa,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QACH,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACnC,CAAC,CAAC;AACJ,CAAC"}
@@ -1,6 +1,5 @@
1
- import { __decorate, __metadata } from "tslib";
2
1
  import { ancestorsOf, classOf, nameOf } from "@tsed/core";
3
- import { Inject, Injectable, InjectorService } from "@tsed/di";
2
+ import { inject, injectable } from "@tsed/di";
4
3
  import { ErrorFilter } from "../components/ErrorFilter.js";
5
4
  import { ExceptionFilter } from "../components/ExceptionFilter.js";
6
5
  import { MongooseErrorFilter } from "../components/MongooseErrorFilter.js";
@@ -12,41 +11,33 @@ import { ResourceNotFound } from "../errors/ResourceNotFound.js";
12
11
  *
13
12
  * @platform
14
13
  */
15
- let PlatformExceptions = class PlatformExceptions {
14
+ export class PlatformExceptions {
16
15
  constructor() {
17
16
  this.types = new Map();
18
- }
19
- $onInit() {
20
17
  ExceptionFiltersContainer.forEach((token, type) => {
21
- this.types.set(type, this.injector.get(token));
18
+ this.types.set(type, token);
22
19
  });
23
20
  }
24
21
  catch(error, ctx) {
22
+ return this.resolve(error, ctx).catch(error, ctx);
23
+ }
24
+ resourceNotFound(ctx) {
25
+ return this.catch(new ResourceNotFound(ctx.request.url), ctx);
26
+ }
27
+ resolve(error, ctx) {
25
28
  const name = nameOf(classOf(error));
26
29
  if (name && this.types.has(name)) {
27
- return this.types.get(name).catch(error, ctx);
30
+ return inject(this.types.get(name));
28
31
  }
29
32
  const target = ancestorsOf(error)
30
33
  .reverse()
31
34
  .find((target) => this.types.has(target));
32
35
  if (target) {
33
- return this.types.get(target).catch(error, ctx);
36
+ return inject(this.types.get(target));
34
37
  }
35
38
  // default
36
- return this.types.get(Error).catch(error, ctx);
37
- }
38
- resourceNotFound(ctx) {
39
- return this.catch(new ResourceNotFound(ctx.request.url), ctx);
39
+ return inject(this.types.get(Error));
40
40
  }
41
- };
42
- __decorate([
43
- Inject(),
44
- __metadata("design:type", InjectorService)
45
- ], PlatformExceptions.prototype, "injector", void 0);
46
- PlatformExceptions = __decorate([
47
- Injectable({
48
- imports: [ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]
49
- })
50
- ], PlatformExceptions);
51
- export { PlatformExceptions };
41
+ }
42
+ injectable(PlatformExceptions).imports([ErrorFilter, ExceptionFilter, MongooseErrorFilter, StringErrorFilter]);
52
43
  //# sourceMappingURL=PlatformExceptions.js.map
@@ -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,EAAY,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,UAAU,CAAC;AAExE,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,eAAe,EAAC,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAC,mBAAmB,EAAC,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAC,iBAAiB,EAAC,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAqB,yBAAyB,EAAC,MAAM,wCAAwC,CAAC;AACrG,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAG/D;;;;GAIG;AAII,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAAxB;QACL,UAAK,GAAoD,IAAI,GAAG,EAAE,CAAC;IAiCrE,CAAC;IA5BC,OAAO;QACL,yBAAyB,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAChD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ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,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,CAAC;QACvC,CAAC;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,CAAC;YACX,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAE,CAAC,CAAC;QACzC,CAAC;QAED,UAAU;QACV,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,CAAC;IACxC,CAAC;CACF;AAED,UAAU,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,CAAC,CAAC,CAAC"}
@@ -1,15 +1,14 @@
1
- import { DIContext, InjectorService } from "@tsed/di";
1
+ import { DIContext, type TokenProvider } from "@tsed/di";
2
2
  import { ExceptionFilterKey } from "../domain/ExceptionFiltersContainer.js";
3
- import { ExceptionFilterMethods } from "../interfaces/ExceptionFilterMethods.js";
4
3
  /**
5
4
  * Catch all errors and return the json error with the right status code when it's possible.
6
5
  *
7
6
  * @platform
8
7
  */
9
8
  export declare class PlatformExceptions {
10
- types: Map<ExceptionFilterKey, ExceptionFilterMethods>;
11
- injector: InjectorService;
12
- $onInit(): void;
13
- catch(error: unknown, ctx: DIContext): void;
14
- resourceNotFound(ctx: DIContext): void;
9
+ types: Map<ExceptionFilterKey, TokenProvider>;
10
+ constructor();
11
+ catch(error: unknown, ctx: DIContext): any;
12
+ resourceNotFound(ctx: DIContext): any;
13
+ protected resolve(error: any, ctx: DIContext): any;
15
14
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/platform-exceptions",
3
3
  "description": "Platform exceptions module for Ts.ED Framework",
4
4
  "type": "module",
5
- "version": "8.0.0-rc.4",
5
+ "version": "8.0.0-rc.6",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -24,22 +24,22 @@
24
24
  "tslib": "2.7.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@tsed/barrels": "8.0.0-rc.4",
28
- "@tsed/core": "8.0.0-rc.4",
29
- "@tsed/di": "8.0.0-rc.4",
30
- "@tsed/exceptions": "8.0.0-rc.4",
31
- "@tsed/schema": "8.0.0-rc.4",
32
- "@tsed/typescript": "8.0.0-rc.4",
27
+ "@tsed/barrels": "8.0.0-rc.6",
28
+ "@tsed/core": "8.0.0-rc.6",
29
+ "@tsed/di": "8.0.0-rc.6",
30
+ "@tsed/exceptions": "8.0.0-rc.6",
31
+ "@tsed/schema": "8.0.0-rc.6",
32
+ "@tsed/typescript": "8.0.0-rc.6",
33
33
  "ajv": "^8.17.1",
34
34
  "eslint": "9.12.0",
35
35
  "typescript": "5.4.5",
36
36
  "vitest": "2.1.2"
37
37
  },
38
38
  "peerDependencies": {
39
- "@tsed/core": "8.0.0-rc.4",
40
- "@tsed/di": "8.0.0-rc.4",
41
- "@tsed/exceptions": "8.0.0-rc.4",
42
- "@tsed/schema": "8.0.0-rc.4"
39
+ "@tsed/core": "8.0.0-rc.6",
40
+ "@tsed/di": "8.0.0-rc.6",
41
+ "@tsed/exceptions": "8.0.0-rc.6",
42
+ "@tsed/schema": "8.0.0-rc.6"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "@tsed/core": {
package/vitest.config.mts CHANGED
@@ -11,7 +11,7 @@ export default defineConfig(
11
11
  ...presets.test.coverage,
12
12
  thresholds: {
13
13
  statements: 100,
14
- branches: 96.66,
14
+ branches: 97.36,
15
15
  functions: 100,
16
16
  lines: 100
17
17
  }