zod-nest 3.0.1 → 3.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/README.md +22 -0
- package/dist/express/index.d.mts +62 -0
- package/dist/express/index.d.ts +62 -0
- package/dist/express/index.js +980 -0
- package/dist/express/index.js.map +1 -0
- package/dist/express/index.mjs +970 -0
- package/dist/express/index.mjs.map +1 -0
- package/dist/fastify/index.d.mts +46 -0
- package/dist/fastify/index.d.ts +46 -0
- package/dist/fastify/index.js +956 -0
- package/dist/fastify/index.js.map +1 -0
- package/dist/fastify/index.mjs +950 -0
- package/dist/fastify/index.mjs.map +1 -0
- package/dist/index.d.mts +3 -77
- package/dist/index.d.ts +3 -77
- package/dist/index.js +44 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -10
- package/dist/index.mjs.map +1 -1
- package/dist/registry-C9xStKa6.d.mts +79 -0
- package/dist/registry-C9xStKa6.d.ts +79 -0
- package/dist/zod-multipart.decorator-CjiQkmkR.d.ts +73 -0
- package/dist/zod-multipart.decorator-CxS2KuSv.d.mts +73 -0
- package/package.json +22 -1
package/README.md
CHANGED
|
@@ -499,6 +499,27 @@ A compact, link-out index. Type signatures and detailed semantics live in the co
|
|
|
499
499
|
|
|
500
500
|
See [`docs/recipes/custom-openapi-overrides.md`](docs/recipes/custom-openapi-overrides.md) for the full catalog and usage patterns.
|
|
501
501
|
|
|
502
|
+
**File uploads** (subpaths: `zod-nest/express`, `zod-nest/fastify`) — [`docs/file-uploads.md`](docs/file-uploads.md)
|
|
503
|
+
|
|
504
|
+
Dedicated helpers per multipart parser, because multer and `@fastify/multipart` disagree on where files land, what they're named, and whether a size is even reported.
|
|
505
|
+
|
|
506
|
+
- **Express / multer**: `multerMemoryFile(options?)`, `multerDiskFile(options?)`, `MulterMemoryFileSchema`, `MulterDiskFileSchema`, `MulterMemoryFileLike`, `MulterDiskFileLike`, `MulterFileOptions`
|
|
507
|
+
- **Fastify / `@fastify/multipart`**: `fastifyMultipartFile(options?)`, `FastifyMultipartFileSchema`, `FastifyMultipartFileLike`, `FastifyMultipartFileOptions` (no `maxSize` — a `MultipartFile` reports no size)
|
|
508
|
+
- **Decorators**: `@ZodMultipart(shape, options?)` declares the whole body and is the source of truth for `@ZodUploadedFile(name)`, `@ZodUploadedFiles(name?)`, and `@ZodMultipartBody()`
|
|
509
|
+
|
|
510
|
+
```ts
|
|
511
|
+
@Post('avatar')
|
|
512
|
+
@UseInterceptors(FileInterceptor('avatar'))
|
|
513
|
+
@ZodMultipart({
|
|
514
|
+
avatar: multerMemoryFile({ maxSize: 2 * 1024 * 1024, mimeTypes: ['image/png'] }),
|
|
515
|
+
name: z.string(),
|
|
516
|
+
})
|
|
517
|
+
upload(
|
|
518
|
+
@ZodUploadedFile('avatar') avatar: MulterMemoryFileLike,
|
|
519
|
+
@ZodMultipartBody() body: { name: string },
|
|
520
|
+
) {}
|
|
521
|
+
```
|
|
522
|
+
|
|
502
523
|
## Documentation
|
|
503
524
|
|
|
504
525
|
| Topic | Doc |
|
|
@@ -510,6 +531,7 @@ See [`docs/recipes/custom-openapi-overrides.md`](docs/recipes/custom-openapi-ove
|
|
|
510
531
|
| Module options reference | [`docs/module-options.md`](docs/module-options.md) |
|
|
511
532
|
| Validation logging | [`docs/logging.md`](docs/logging.md) |
|
|
512
533
|
| Swagger integration & custom emission | [`docs/swagger-integration.md`](docs/swagger-integration.md) |
|
|
534
|
+
| File uploads (multipart/form-data) | [`docs/file-uploads.md`](docs/file-uploads.md) |
|
|
513
535
|
| Composition (experimental) | [`docs/composition.md`](docs/composition.md) |
|
|
514
536
|
| Exception classes | [`docs/exceptions.md`](docs/exceptions.md) |
|
|
515
537
|
| Recipes | [`docs/recipes/`](docs/recipes/) |
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { B as BaseFileOptions, a as MultipartShape, b as ZodMultipartOptions } from '../zod-multipart.decorator-CxS2KuSv.mjs';
|
|
3
|
+
export { M as MULTIPART_CONTENT_TYPE, Z as ZodMultipartBody, c as ZodUploadedFile, d as ZodUploadedFiles } from '../zod-multipart.decorator-CxS2KuSv.mjs';
|
|
4
|
+
import '@nestjs/common';
|
|
5
|
+
import '../registry-C9xStKa6.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Shape multer hands you under **memory storage** (`FileInterceptor`'s
|
|
9
|
+
* default). `buffer` holds the whole file; there is no `path`.
|
|
10
|
+
*/
|
|
11
|
+
interface MulterMemoryFileLike {
|
|
12
|
+
fieldname: string;
|
|
13
|
+
originalname: string;
|
|
14
|
+
encoding: string;
|
|
15
|
+
mimetype: string;
|
|
16
|
+
size: number;
|
|
17
|
+
buffer: Buffer;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Shape multer hands you under **disk storage**. The bytes are on disk at
|
|
21
|
+
* `path`; there is no `buffer`, so byte-level validation isn't possible.
|
|
22
|
+
*/
|
|
23
|
+
interface MulterDiskFileLike {
|
|
24
|
+
fieldname: string;
|
|
25
|
+
originalname: string;
|
|
26
|
+
encoding: string;
|
|
27
|
+
mimetype: string;
|
|
28
|
+
size: number;
|
|
29
|
+
destination: string;
|
|
30
|
+
filename: string;
|
|
31
|
+
path: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Options for the multer file helpers. `maxSize` is checked against multer's
|
|
35
|
+
* reported `size` **after** the file has been read — it documents the limit
|
|
36
|
+
* and adds defence in depth, but the guard that actually stops a large upload
|
|
37
|
+
* is multer's own `limits.fileSize`.
|
|
38
|
+
*
|
|
39
|
+
* `mimeTypes` and `extensions` match the client-supplied values. They are not
|
|
40
|
+
* content sniffing; use `@nestjs/common`'s `FileTypeValidator` when you need
|
|
41
|
+
* magic-number checks.
|
|
42
|
+
*/
|
|
43
|
+
interface MulterFileOptions extends BaseFileOptions {
|
|
44
|
+
readonly maxSize?: number;
|
|
45
|
+
}
|
|
46
|
+
/** Multer memory-storage file, constrained by `options` and emitted as `format: 'binary'`. */
|
|
47
|
+
declare const multerMemoryFile: (options?: MulterFileOptions) => z.ZodType<MulterMemoryFileLike, MulterMemoryFileLike>;
|
|
48
|
+
/** Multer disk-storage file, constrained by `options` and emitted as `format: 'binary'`. */
|
|
49
|
+
declare const multerDiskFile: (options?: MulterFileOptions) => z.ZodType<MulterDiskFileLike, MulterDiskFileLike>;
|
|
50
|
+
/** Unconstrained {@link multerMemoryFile}, for shapes that need no per-field checks. */
|
|
51
|
+
declare const MulterMemoryFileSchema: z.ZodType<MulterMemoryFileLike, MulterMemoryFileLike, z.core.$ZodTypeInternals<MulterMemoryFileLike, MulterMemoryFileLike>>;
|
|
52
|
+
/** Unconstrained {@link multerDiskFile}, for shapes that need no per-field checks. */
|
|
53
|
+
declare const MulterDiskFileSchema: z.ZodType<MulterDiskFileLike, MulterDiskFileLike, z.core.$ZodTypeInternals<MulterDiskFileLike, MulterDiskFileLike>>;
|
|
54
|
+
/**
|
|
55
|
+
* Declares an endpoint's whole `multipart/form-data` body. Emits the flat
|
|
56
|
+
* inline `requestBody` Swagger UI's try-it-out form needs, sets
|
|
57
|
+
* `multipart/form-data` as the consumed type, and is the schema source for
|
|
58
|
+
* `@ZodUploadedFile` / `@ZodUploadedFiles` / `@ZodMultipartBody`.
|
|
59
|
+
*/
|
|
60
|
+
declare const ZodMultipart: (shape: MultipartShape, options?: ZodMultipartOptions) => MethodDecorator;
|
|
61
|
+
|
|
62
|
+
export { type MulterDiskFileLike, MulterDiskFileSchema, type MulterFileOptions, type MulterMemoryFileLike, MulterMemoryFileSchema, MultipartShape, ZodMultipart, ZodMultipartOptions, multerDiskFile, multerMemoryFile };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { B as BaseFileOptions, a as MultipartShape, b as ZodMultipartOptions } from '../zod-multipart.decorator-CjiQkmkR.js';
|
|
3
|
+
export { M as MULTIPART_CONTENT_TYPE, Z as ZodMultipartBody, c as ZodUploadedFile, d as ZodUploadedFiles } from '../zod-multipart.decorator-CjiQkmkR.js';
|
|
4
|
+
import '@nestjs/common';
|
|
5
|
+
import '../registry-C9xStKa6.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Shape multer hands you under **memory storage** (`FileInterceptor`'s
|
|
9
|
+
* default). `buffer` holds the whole file; there is no `path`.
|
|
10
|
+
*/
|
|
11
|
+
interface MulterMemoryFileLike {
|
|
12
|
+
fieldname: string;
|
|
13
|
+
originalname: string;
|
|
14
|
+
encoding: string;
|
|
15
|
+
mimetype: string;
|
|
16
|
+
size: number;
|
|
17
|
+
buffer: Buffer;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Shape multer hands you under **disk storage**. The bytes are on disk at
|
|
21
|
+
* `path`; there is no `buffer`, so byte-level validation isn't possible.
|
|
22
|
+
*/
|
|
23
|
+
interface MulterDiskFileLike {
|
|
24
|
+
fieldname: string;
|
|
25
|
+
originalname: string;
|
|
26
|
+
encoding: string;
|
|
27
|
+
mimetype: string;
|
|
28
|
+
size: number;
|
|
29
|
+
destination: string;
|
|
30
|
+
filename: string;
|
|
31
|
+
path: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Options for the multer file helpers. `maxSize` is checked against multer's
|
|
35
|
+
* reported `size` **after** the file has been read — it documents the limit
|
|
36
|
+
* and adds defence in depth, but the guard that actually stops a large upload
|
|
37
|
+
* is multer's own `limits.fileSize`.
|
|
38
|
+
*
|
|
39
|
+
* `mimeTypes` and `extensions` match the client-supplied values. They are not
|
|
40
|
+
* content sniffing; use `@nestjs/common`'s `FileTypeValidator` when you need
|
|
41
|
+
* magic-number checks.
|
|
42
|
+
*/
|
|
43
|
+
interface MulterFileOptions extends BaseFileOptions {
|
|
44
|
+
readonly maxSize?: number;
|
|
45
|
+
}
|
|
46
|
+
/** Multer memory-storage file, constrained by `options` and emitted as `format: 'binary'`. */
|
|
47
|
+
declare const multerMemoryFile: (options?: MulterFileOptions) => z.ZodType<MulterMemoryFileLike, MulterMemoryFileLike>;
|
|
48
|
+
/** Multer disk-storage file, constrained by `options` and emitted as `format: 'binary'`. */
|
|
49
|
+
declare const multerDiskFile: (options?: MulterFileOptions) => z.ZodType<MulterDiskFileLike, MulterDiskFileLike>;
|
|
50
|
+
/** Unconstrained {@link multerMemoryFile}, for shapes that need no per-field checks. */
|
|
51
|
+
declare const MulterMemoryFileSchema: z.ZodType<MulterMemoryFileLike, MulterMemoryFileLike, z.core.$ZodTypeInternals<MulterMemoryFileLike, MulterMemoryFileLike>>;
|
|
52
|
+
/** Unconstrained {@link multerDiskFile}, for shapes that need no per-field checks. */
|
|
53
|
+
declare const MulterDiskFileSchema: z.ZodType<MulterDiskFileLike, MulterDiskFileLike, z.core.$ZodTypeInternals<MulterDiskFileLike, MulterDiskFileLike>>;
|
|
54
|
+
/**
|
|
55
|
+
* Declares an endpoint's whole `multipart/form-data` body. Emits the flat
|
|
56
|
+
* inline `requestBody` Swagger UI's try-it-out form needs, sets
|
|
57
|
+
* `multipart/form-data` as the consumed type, and is the schema source for
|
|
58
|
+
* `@ZodUploadedFile` / `@ZodUploadedFiles` / `@ZodMultipartBody`.
|
|
59
|
+
*/
|
|
60
|
+
declare const ZodMultipart: (shape: MultipartShape, options?: ZodMultipartOptions) => MethodDecorator;
|
|
61
|
+
|
|
62
|
+
export { type MulterDiskFileLike, MulterDiskFileSchema, type MulterFileOptions, type MulterMemoryFileLike, MulterMemoryFileSchema, MultipartShape, ZodMultipart, ZodMultipartOptions, multerDiskFile, multerMemoryFile };
|