@stlmpp/nestjs-zod 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dto.d.cts CHANGED
@@ -1,2 +1,21 @@
1
- import { n as createZodDto, r as isZodDto, t as ZodDto } from "./dto-CMhDHMJh.cjs";
1
+ import { ZodType } from "zod";
2
+ import { input, output } from "zod/v4/core";
3
+
4
+ //#region src/dto.d.ts
5
+ type ZodDtoInstance<TSchema extends ZodType, Type extends 'input' | 'output'> = Type extends 'output' ? output<TSchema> : input<TSchema>;
6
+ interface ZodDto<TSchema extends ZodType = ZodType, TCodec extends boolean = boolean, Type extends 'input' | 'output' = 'input'> {
7
+ new (): ZodDtoInstance<TSchema, Type>;
8
+ isZodDto: true;
9
+ schema: TSchema;
10
+ codec: TCodec;
11
+ create(input: unknown): ZodDtoInstance<TSchema, Type>;
12
+ Output: ZodDto<ZodType, TCodec>;
13
+ _OPENAPI_METADATA_FACTORY(): unknown;
14
+ }
15
+ declare function createZodDto<TSchema extends ZodType, TCodec extends boolean = false, Type extends 'input' | 'output' = 'input'>(schema: TSchema, options?: {
16
+ codec?: TCodec;
17
+ type?: Type;
18
+ }): ZodDto<TSchema, TCodec, Type>;
19
+ declare function isZodDto(metatype: unknown): metatype is ZodDto<ZodType, boolean, 'input' | 'output'>;
20
+ //#endregion
2
21
  export { ZodDto, createZodDto, isZodDto };
package/dist/dto.d.mts CHANGED
@@ -1,2 +1,21 @@
1
- import { n as createZodDto, r as isZodDto, t as ZodDto } from "./dto-CMhDHMJh.mjs";
1
+ import { input, output } from "zod/v4/core";
2
+ import { ZodType } from "zod";
3
+
4
+ //#region src/dto.d.ts
5
+ type ZodDtoInstance<TSchema extends ZodType, Type extends 'input' | 'output'> = Type extends 'output' ? output<TSchema> : input<TSchema>;
6
+ interface ZodDto<TSchema extends ZodType = ZodType, TCodec extends boolean = boolean, Type extends 'input' | 'output' = 'input'> {
7
+ new (): ZodDtoInstance<TSchema, Type>;
8
+ isZodDto: true;
9
+ schema: TSchema;
10
+ codec: TCodec;
11
+ create(input: unknown): ZodDtoInstance<TSchema, Type>;
12
+ Output: ZodDto<ZodType, TCodec>;
13
+ _OPENAPI_METADATA_FACTORY(): unknown;
14
+ }
15
+ declare function createZodDto<TSchema extends ZodType, TCodec extends boolean = false, Type extends 'input' | 'output' = 'input'>(schema: TSchema, options?: {
16
+ codec?: TCodec;
17
+ type?: Type;
18
+ }): ZodDto<TSchema, TCodec, Type>;
19
+ declare function isZodDto(metatype: unknown): metatype is ZodDto<ZodType, boolean, 'input' | 'output'>;
20
+ //#endregion
2
21
  export { ZodDto, createZodDto, isZodDto };
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { a as UnknownSchema, i as RequiredBy, n as createZodDto, t as ZodDto } from "./dto-CMhDHMJh.cjs";
1
+ import { ZodDto, createZodDto } from "./dto.cjs";
2
+ import { ZodType } from "zod";
2
3
  import { input, output } from "zod/v4/core";
3
4
  import { BadRequestException, CallHandler, CanActivate, ExecutionContext, InternalServerErrorException, PipeTransform } from "@nestjs/common";
4
5
  import { z } from "zod/v3";
@@ -33,6 +34,19 @@ declare class ZodSerializationException extends InternalServerErrorException {
33
34
  }
34
35
  type ZodExceptionCreator = (error: unknown) => Error;
35
36
  //#endregion
37
+ //#region src/types.d.ts
38
+ interface UnknownSchema {
39
+ parse(input: unknown, options?: {
40
+ reportInput?: boolean;
41
+ [x: string | number | symbol]: unknown;
42
+ }): unknown;
43
+ encode?(input: unknown, options?: {
44
+ reportInput?: boolean;
45
+ [x: string | number | symbol]: unknown;
46
+ }): unknown;
47
+ array?: () => UnknownSchema;
48
+ }
49
+ //#endregion
36
50
  //#region src/guard.d.ts
37
51
  type Source = 'body' | 'query' | 'params';
38
52
  interface ZodBodyGuardOptions {
@@ -96,7 +110,11 @@ declare function createZodValidationPipe({
96
110
  declare const ZodValidationPipe: ZodValidationPipeClass;
97
111
  //#endregion
98
112
  //#region src/serializer.d.ts
99
- declare function ZodSerializerDto(dto: ZodDto | UnknownSchema | [ZodDto] | [UnknownSchema]): import("@nestjs/common").CustomDecorator<"ZOD_SERIALIZER_DTO_OPTIONS">;
113
+ declare function ZodSerializerDto(dto: ZodDto | UnknownSchema | [ZodDto] | [UnknownSchema]): import("@nestjs/common",{
114
+ with: {
115
+ "resolution-mode": "import"
116
+ }
117
+ }).CustomDecorator<"ZOD_SERIALIZER_DTO_OPTIONS">;
100
118
  interface ZodSerializerInterceptorOptions {
101
119
  reportInput?: boolean;
102
120
  }
@@ -113,7 +131,7 @@ declare const ZodSerializerInterceptor: ZodSerializerInterceptorClass;
113
131
  * @deprecated `validate` will be removed in a future version. It is
114
132
  * recommended to use `.parse` directly
115
133
  */
116
- declare function validate<TSchema extends UnknownSchema>(value: unknown, schemaOrDto: TSchema | ZodDto<TSchema, boolean>, createValidationException?: ZodExceptionCreator): ReturnType<TSchema['parse']>;
134
+ declare function validate(value: unknown, schemaOrDto: UnknownSchema | ZodDto, createValidationException?: ZodExceptionCreator): unknown;
117
135
  //#endregion
118
136
  //#region src/cleanupOpenApiDoc.d.ts
119
137
  /**
@@ -188,7 +206,7 @@ declare function cleanupOpenApiDoc(doc: OpenAPIObject, {
188
206
  * return [{ id: '1' }, { id: '2' }];
189
207
  * }
190
208
  */
191
- declare function ZodResponse<TSchema extends UnknownSchema>({
209
+ declare function ZodResponse<TSchema extends ZodType>({
192
210
  status,
193
211
  description,
194
212
  type
@@ -197,7 +215,7 @@ declare function ZodResponse<TSchema extends UnknownSchema>({
197
215
  description?: string;
198
216
  type: ZodDto<TSchema, true, 'input' | 'output'>;
199
217
  }): (target: object, propertyKey?: string | symbol, descriptor?: Pick<TypedPropertyDescriptor<(...args: any[]) => output<TSchema> | Promise<output<TSchema>>>, 'value'>) => void;
200
- declare function ZodResponse<TSchema extends RequiredBy<UnknownSchema, 'array'>>({
218
+ declare function ZodResponse<TSchema extends ZodType>({
201
219
  status,
202
220
  description,
203
221
  type
@@ -206,7 +224,7 @@ declare function ZodResponse<TSchema extends RequiredBy<UnknownSchema, 'array'>>
206
224
  description?: string;
207
225
  type: [ZodDto<TSchema, true, 'input' | 'output'>];
208
226
  }): (target: object, propertyKey?: string | symbol, descriptor?: Pick<TypedPropertyDescriptor<(...args: any[]) => Array<output<TSchema>> | Promise<Array<output<TSchema>>>>, 'value'>) => void;
209
- declare function ZodResponse<TSchema extends UnknownSchema>({
227
+ declare function ZodResponse<TSchema extends ZodType>({
210
228
  status,
211
229
  description,
212
230
  type
@@ -215,7 +233,7 @@ declare function ZodResponse<TSchema extends UnknownSchema>({
215
233
  description?: string;
216
234
  type: ZodDto<TSchema, false, 'input' | 'output'>;
217
235
  }): (target: object, propertyKey?: string | symbol, descriptor?: Pick<TypedPropertyDescriptor<(...args: any[]) => input<TSchema> | Promise<input<TSchema>>>, 'value'>) => void;
218
- declare function ZodResponse<TSchema extends RequiredBy<UnknownSchema, 'array'>>({
236
+ declare function ZodResponse<TSchema extends ZodType>({
219
237
  status,
220
238
  description,
221
239
  type
package/dist/index.d.mts CHANGED
@@ -1,9 +1,10 @@
1
- import { a as UnknownSchema, i as RequiredBy, n as createZodDto, t as ZodDto } from "./dto-CMhDHMJh.mjs";
1
+ import { ZodDto, createZodDto } from "./dto.mjs";
2
2
  import { input, output } from "zod/v4/core";
3
3
  import { z } from "zod/v3";
4
4
  import { BadRequestException, CallHandler, CanActivate, ExecutionContext, InternalServerErrorException, PipeTransform } from "@nestjs/common";
5
5
  import { Observable } from "rxjs";
6
6
  import { OpenAPIObject } from "@nestjs/swagger";
7
+ import { ZodType } from "zod";
7
8
 
8
9
  //#region src/config.d.ts
9
10
  interface ZodDtoConfig {
@@ -33,6 +34,19 @@ declare class ZodSerializationException extends InternalServerErrorException {
33
34
  }
34
35
  type ZodExceptionCreator = (error: unknown) => Error;
35
36
  //#endregion
37
+ //#region src/types.d.ts
38
+ interface UnknownSchema {
39
+ parse(input: unknown, options?: {
40
+ reportInput?: boolean;
41
+ [x: string | number | symbol]: unknown;
42
+ }): unknown;
43
+ encode?(input: unknown, options?: {
44
+ reportInput?: boolean;
45
+ [x: string | number | symbol]: unknown;
46
+ }): unknown;
47
+ array?: () => UnknownSchema;
48
+ }
49
+ //#endregion
36
50
  //#region src/guard.d.ts
37
51
  type Source = 'body' | 'query' | 'params';
38
52
  interface ZodBodyGuardOptions {
@@ -96,7 +110,11 @@ declare function createZodValidationPipe({
96
110
  declare const ZodValidationPipe: ZodValidationPipeClass;
97
111
  //#endregion
98
112
  //#region src/serializer.d.ts
99
- declare function ZodSerializerDto(dto: ZodDto | UnknownSchema | [ZodDto] | [UnknownSchema]): import("@nestjs/common").CustomDecorator<"ZOD_SERIALIZER_DTO_OPTIONS">;
113
+ declare function ZodSerializerDto(dto: ZodDto | UnknownSchema | [ZodDto] | [UnknownSchema]): import("@nestjs/common",{
114
+ with: {
115
+ "resolution-mode": "import"
116
+ }
117
+ }).CustomDecorator<"ZOD_SERIALIZER_DTO_OPTIONS">;
100
118
  interface ZodSerializerInterceptorOptions {
101
119
  reportInput?: boolean;
102
120
  }
@@ -113,7 +131,7 @@ declare const ZodSerializerInterceptor: ZodSerializerInterceptorClass;
113
131
  * @deprecated `validate` will be removed in a future version. It is
114
132
  * recommended to use `.parse` directly
115
133
  */
116
- declare function validate<TSchema extends UnknownSchema>(value: unknown, schemaOrDto: TSchema | ZodDto<TSchema, boolean>, createValidationException?: ZodExceptionCreator): ReturnType<TSchema['parse']>;
134
+ declare function validate(value: unknown, schemaOrDto: UnknownSchema | ZodDto, createValidationException?: ZodExceptionCreator): unknown;
117
135
  //#endregion
118
136
  //#region src/cleanupOpenApiDoc.d.ts
119
137
  /**
@@ -188,7 +206,7 @@ declare function cleanupOpenApiDoc(doc: OpenAPIObject, {
188
206
  * return [{ id: '1' }, { id: '2' }];
189
207
  * }
190
208
  */
191
- declare function ZodResponse<TSchema extends UnknownSchema>({
209
+ declare function ZodResponse<TSchema extends ZodType>({
192
210
  status,
193
211
  description,
194
212
  type
@@ -197,7 +215,7 @@ declare function ZodResponse<TSchema extends UnknownSchema>({
197
215
  description?: string;
198
216
  type: ZodDto<TSchema, true, 'input' | 'output'>;
199
217
  }): (target: object, propertyKey?: string | symbol, descriptor?: Pick<TypedPropertyDescriptor<(...args: any[]) => output<TSchema> | Promise<output<TSchema>>>, 'value'>) => void;
200
- declare function ZodResponse<TSchema extends RequiredBy<UnknownSchema, 'array'>>({
218
+ declare function ZodResponse<TSchema extends ZodType>({
201
219
  status,
202
220
  description,
203
221
  type
@@ -206,7 +224,7 @@ declare function ZodResponse<TSchema extends RequiredBy<UnknownSchema, 'array'>>
206
224
  description?: string;
207
225
  type: [ZodDto<TSchema, true, 'input' | 'output'>];
208
226
  }): (target: object, propertyKey?: string | symbol, descriptor?: Pick<TypedPropertyDescriptor<(...args: any[]) => Array<output<TSchema>> | Promise<Array<output<TSchema>>>>, 'value'>) => void;
209
- declare function ZodResponse<TSchema extends UnknownSchema>({
227
+ declare function ZodResponse<TSchema extends ZodType>({
210
228
  status,
211
229
  description,
212
230
  type
@@ -215,7 +233,7 @@ declare function ZodResponse<TSchema extends UnknownSchema>({
215
233
  description?: string;
216
234
  type: ZodDto<TSchema, false, 'input' | 'output'>;
217
235
  }): (target: object, propertyKey?: string | symbol, descriptor?: Pick<TypedPropertyDescriptor<(...args: any[]) => input<TSchema> | Promise<input<TSchema>>>, 'value'>) => void;
218
- declare function ZodResponse<TSchema extends RequiredBy<UnknownSchema, 'array'>>({
236
+ declare function ZodResponse<TSchema extends ZodType>({
219
237
  status,
220
238
  description,
221
239
  type
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stlmpp/nestjs-zod",
3
3
  "description": "All NestJS + Zod utilities you need",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "main": "./dist/index.cjs",
6
6
  "exports": {
7
7
  ".": {
@@ -50,7 +50,7 @@
50
50
  "scripts": {
51
51
  "dev": "vite",
52
52
  "build": "tsdown",
53
- "test": "TZ=UTC jest",
53
+ "test": "TZ=UTC vitest run",
54
54
  "lint": "eslint",
55
55
  "lint:fix": "eslint --fix",
56
56
  "format:write": "prettier --write \"src/**/*.ts\"",
@@ -58,18 +58,17 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "@eslint/js": "^10.0.1",
61
- "@golevelup/ts-jest": "^3.0.0",
61
+ "@golevelup/ts-vitest": "^4.0.0",
62
62
  "@ibm-cloud/openapi-ruleset": "^1.33.13",
63
63
  "@nest-zod/z": "workspace:*",
64
- "@nestjs/common": "^11.1.5",
65
- "@nestjs/core": "^11.1.5",
66
- "@nestjs/swagger": "^11.2.0",
67
- "@nestjs/swagger-v7": "npm:@nestjs/swagger@7.4.2",
68
- "@nestjs/testing": "^11.1.28",
64
+ "@nestjs/common": "^12.1.0",
65
+ "@nestjs/core": "^12.1.0",
66
+ "@nestjs/swagger": "^12.0.2",
67
+ "@nestjs/testing": "^12.1.0",
69
68
  "@stoplight/spectral-core": "^1.23.1",
70
69
  "@stoplight/spectral-rulesets": "^1.22.7",
70
+ "@swc/core": "^1.15.47",
71
71
  "@types/express": "^5.0.6",
72
- "@types/jest": "^29.5.2",
73
72
  "@types/lodash": "^4.17.23",
74
73
  "@types/merge-deep": "^3.0.0",
75
74
  "@types/node": "^25.9.1",
@@ -82,23 +81,23 @@
82
81
  "express": "^5.2.1",
83
82
  "express-openapi-validator": "^5.6.2",
84
83
  "globals": "^17.6.0",
85
- "jest": "^29.5.0",
86
84
  "jiti": "^2.7.0",
87
85
  "lodash": "^4.17.23",
88
86
  "prettier": "^3.9.6",
89
87
  "reflect-metadata": "^0.2.0",
90
88
  "rxjs": "^7.8.1",
91
89
  "supertest": "^7.2.2",
92
- "ts-jest": "^29.4.10",
93
90
  "tsdown": "^0.22.3",
94
91
  "typescript": "5.9.3",
95
- "typescript-eslint": "^8.66.0",
92
+ "typescript-eslint": "^8.67.0",
93
+ "unplugin-swc": "^2.0.0",
94
+ "vitest": "^5.0.1",
96
95
  "zod": "4.4.3",
97
96
  "zod-v4_0_0": "npm:zod@4.0.0"
98
97
  },
99
98
  "peerDependencies": {
100
- "@nestjs/common": "^10.0.0 || ^11.0.0",
101
- "@nestjs/swagger": "^7.4.2 || ^8.0.0 || ^11.0.0",
99
+ "@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
100
+ "@nestjs/swagger": "^7.4.2 || ^8.0.0 || ^11.0.0 || ^12.0.0",
102
101
  "rxjs": "^7.0.0",
103
102
  "zod": "^3.25.0 || ^4.0.0"
104
103
  },
@@ -1,61 +0,0 @@
1
- import { input, output } from "zod/v4/core";
2
-
3
- //#region src/types.d.ts
4
- interface UnknownSchema {
5
- parse(input: unknown, options?: {
6
- reportInput?: boolean;
7
- [x: string | number | symbol]: unknown;
8
- }): unknown;
9
- encode?(input: unknown, options?: {
10
- reportInput?: boolean;
11
- [x: string | number | symbol]: unknown;
12
- }): unknown;
13
- array?: () => UnknownSchema;
14
- }
15
- /**
16
- * RequiredBy
17
- * @desc From `T` make a set of properties by key `K` become required
18
- * @example
19
- * type Props = {
20
- * name?: string;
21
- * age?: number;
22
- * visible?: boolean;
23
- * };
24
- *
25
- * // Expect: { name: string; age: number; visible: boolean; }
26
- * type Props = RequiredBy<Props>;
27
- *
28
- * // Expect: { name?: string; age: number; visible: boolean; }
29
- * type Props = RequiredBy<Props, 'age' | 'visible'>;
30
- */
31
- type RequiredBy<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Required<Pick<T, K>>;
32
- //#endregion
33
- //#region src/dto.d.ts
34
- /**
35
- * `input`/`output` from `zod/v4/core` fall back to `unknown` for schemas
36
- * that don't expose v4-style `_zod` internals (zod v3 schemas, zod-mini
37
- * schemas, or duck-typed `UnknownSchema` objects). For those, fall back to
38
- * the schema's `parse` return type, same as before `Type` existed.
39
- */
40
- type ZodDtoInstance<TSchema extends UnknownSchema, Type extends 'input' | 'output'> = TSchema extends {
41
- _zod: {
42
- input: unknown;
43
- output: unknown;
44
- };
45
- } ? Type extends 'output' ? output<TSchema> : input<TSchema> : ReturnType<TSchema['parse']>;
46
- interface ZodDto<TSchema extends UnknownSchema = UnknownSchema, TCodec extends boolean = boolean, Type extends 'input' | 'output' = 'input'> {
47
- new (): ZodDtoInstance<TSchema, Type>;
48
- isZodDto: true;
49
- schema: TSchema;
50
- codec: TCodec;
51
- create(input: unknown): ZodDtoInstance<TSchema, Type>;
52
- Output: ZodDto<UnknownSchema, TCodec>;
53
- _OPENAPI_METADATA_FACTORY(): unknown;
54
- }
55
- declare function createZodDto<TSchema extends UnknownSchema, TCodec extends boolean = false, Type extends 'input' | 'output' = 'input'>(schema: TSchema, options?: {
56
- codec?: TCodec;
57
- type?: Type;
58
- }): ZodDto<TSchema, TCodec, Type>;
59
- declare function isZodDto(metatype: unknown): metatype is ZodDto<UnknownSchema, boolean, 'input' | 'output'>;
60
- //#endregion
61
- export { UnknownSchema as a, RequiredBy as i, createZodDto as n, isZodDto as r, ZodDto as t };
@@ -1,61 +0,0 @@
1
- import { input, output } from "zod/v4/core";
2
-
3
- //#region src/types.d.ts
4
- interface UnknownSchema {
5
- parse(input: unknown, options?: {
6
- reportInput?: boolean;
7
- [x: string | number | symbol]: unknown;
8
- }): unknown;
9
- encode?(input: unknown, options?: {
10
- reportInput?: boolean;
11
- [x: string | number | symbol]: unknown;
12
- }): unknown;
13
- array?: () => UnknownSchema;
14
- }
15
- /**
16
- * RequiredBy
17
- * @desc From `T` make a set of properties by key `K` become required
18
- * @example
19
- * type Props = {
20
- * name?: string;
21
- * age?: number;
22
- * visible?: boolean;
23
- * };
24
- *
25
- * // Expect: { name: string; age: number; visible: boolean; }
26
- * type Props = RequiredBy<Props>;
27
- *
28
- * // Expect: { name?: string; age: number; visible: boolean; }
29
- * type Props = RequiredBy<Props, 'age' | 'visible'>;
30
- */
31
- type RequiredBy<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Required<Pick<T, K>>;
32
- //#endregion
33
- //#region src/dto.d.ts
34
- /**
35
- * `input`/`output` from `zod/v4/core` fall back to `unknown` for schemas
36
- * that don't expose v4-style `_zod` internals (zod v3 schemas, zod-mini
37
- * schemas, or duck-typed `UnknownSchema` objects). For those, fall back to
38
- * the schema's `parse` return type, same as before `Type` existed.
39
- */
40
- type ZodDtoInstance<TSchema extends UnknownSchema, Type extends 'input' | 'output'> = TSchema extends {
41
- _zod: {
42
- input: unknown;
43
- output: unknown;
44
- };
45
- } ? Type extends 'output' ? output<TSchema> : input<TSchema> : ReturnType<TSchema['parse']>;
46
- interface ZodDto<TSchema extends UnknownSchema = UnknownSchema, TCodec extends boolean = boolean, Type extends 'input' | 'output' = 'input'> {
47
- new (): ZodDtoInstance<TSchema, Type>;
48
- isZodDto: true;
49
- schema: TSchema;
50
- codec: TCodec;
51
- create(input: unknown): ZodDtoInstance<TSchema, Type>;
52
- Output: ZodDto<UnknownSchema, TCodec>;
53
- _OPENAPI_METADATA_FACTORY(): unknown;
54
- }
55
- declare function createZodDto<TSchema extends UnknownSchema, TCodec extends boolean = false, Type extends 'input' | 'output' = 'input'>(schema: TSchema, options?: {
56
- codec?: TCodec;
57
- type?: Type;
58
- }): ZodDto<TSchema, TCodec, Type>;
59
- declare function isZodDto(metatype: unknown): metatype is ZodDto<UnknownSchema, boolean, 'input' | 'output'>;
60
- //#endregion
61
- export { UnknownSchema as a, RequiredBy as i, createZodDto as n, isZodDto as r, ZodDto as t };