@hg-ts/validation 0.5.39 → 0.5.40

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/dist/dto.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"dto.d.ts","sourceRoot":"","sources":["../src/dto.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,IAAI,QAAQ,EACjB,SAAS,EACT,SAAS,EACT,MAAM,KAAK,CAAC;AAEb,MAAM,MAAM,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE,MAAM,GAAG,OAAO,IAAI;IACrD,QAAQ,OAAO,CAAC;IAChB,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CAChC,CAAA;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAC/C,MAAM,EAAE,CAAC,GACP,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAWrB;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAMxD"}
1
+ {"version":3,"file":"dto.d.ts","sourceRoot":"","sources":["../src/dto.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,IAAI,QAAQ,EAEjB,SAAS,EACT,SAAS,EACT,MAAM,KAAK,CAAC;AAGb,MAAM,MAAM,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE,MAAM,GAAG,OAAO,IAAI;IACrD,QAAQ,OAAO,CAAC;IAChB,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;CAChC,CAAA;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAC/C,MAAM,EAAE,CAAC,GACP,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAmBrB;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAMxD"}
package/dist/dto.js CHANGED
@@ -1,9 +1,19 @@
1
+ import { ZodError, } from 'zod';
2
+ import { ValidationException } from './validation.exception.js';
1
3
  export function createZodDto(schema) {
2
4
  class AugmentedZodDto {
3
5
  static isZodDto = true;
4
6
  static schema = schema;
5
7
  static create(input) {
6
- return this.schema.parse(input);
8
+ try {
9
+ return this.schema.parse(input);
10
+ }
11
+ catch (error) {
12
+ if (error instanceof ZodError) {
13
+ throw new ValidationException(error);
14
+ }
15
+ throw error;
16
+ }
7
17
  }
8
18
  }
9
19
  return AugmentedZodDto;
package/dist/dto.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"dto.js","sourceRoot":"","sources":["../src/dto.ts"],"names":[],"mappings":"AAaA,MAAM,UAAU,YAAY,CAC3B,MAAS;IAET,MAAe,eAAe;QACtB,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QAEvB,MAAM,CAAC,MAAM,CAAC,KAAc;YAClC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAoB,CAAC;QACpD,CAAC;;IAGF,OAAO,eAAiD,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACtC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,UAAU,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC;AACvD,CAAC"}
1
+ {"version":3,"file":"dto.js","sourceRoot":"","sources":["../src/dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,QAAQ,GAGR,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAShE,MAAM,UAAU,YAAY,CAC3B,MAAS;IAET,MAAe,eAAe;QACtB,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QAEvB,MAAM,CAAC,MAAM,CAAC,KAAc;YAClC,IAAI,CAAC;gBACJ,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAoB,CAAC;YACpD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;oBAC/B,MAAM,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC;gBACtC,CAAC;gBAED,MAAM,KAAK,CAAC;YACb,CAAC;QACF,CAAC;;IAGF,OAAO,eAAiD,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAc;IACtC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,UAAU,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC;AACvD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hg-ts/validation",
3
- "version": "0.5.39",
3
+ "version": "0.5.40",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "exports": {
@@ -16,10 +16,10 @@
16
16
  "lint:ts:fix": "lint-ts --fix"
17
17
  },
18
18
  "devDependencies": {
19
- "@hg-ts-config/typescript": "0.5.39",
20
- "@hg-ts/exception": "0.5.39",
21
- "@hg-ts/linter": "0.5.39",
22
- "@hg-ts/types": "0.5.39",
19
+ "@hg-ts-config/typescript": "0.5.40",
20
+ "@hg-ts/exception": "0.5.40",
21
+ "@hg-ts/linter": "0.5.40",
22
+ "@hg-ts/types": "0.5.40",
23
23
  "@types/node": "22.19.1",
24
24
  "eslint": "9.18.0",
25
25
  "reflect-metadata": "0.2.2",
@@ -28,7 +28,7 @@
28
28
  "typescript": "5.7.3"
29
29
  },
30
30
  "peerDependencies": {
31
- "@hg-ts/exception": "0.5.39",
31
+ "@hg-ts/exception": "0.5.40",
32
32
  "reflect-metadata": "*",
33
33
  "tslib": "*"
34
34
  },
package/src/dto.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  infer as ZodInfer,
3
+ ZodError,
3
4
  ZodObject,
4
5
  ZodSchema,
5
6
  } from 'zod';
7
+ import { ValidationException } from './validation.exception.js';
6
8
 
7
9
  export type ZodDto<TOutput = any, TInput = TOutput> = {
8
10
  new (): TOutput;
@@ -19,7 +21,15 @@ export function createZodDto<T extends ZodObject>(
19
21
  public static schema = schema;
20
22
 
21
23
  public static create(input: unknown): AugmentedZodDto {
22
- return this.schema.parse(input) as AugmentedZodDto;
24
+ try {
25
+ return this.schema.parse(input) as AugmentedZodDto;
26
+ } catch (error) {
27
+ if (error instanceof ZodError) {
28
+ throw new ValidationException(error);
29
+ }
30
+
31
+ throw error;
32
+ }
23
33
  }
24
34
  }
25
35