sprint-es 0.0.164 → 0.0.165
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/cjs/modules/schemas/index.cjs +86 -111
- package/dist/esm/modules/schemas/index.js +86 -111
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/schemas/index.d.ts +5 -25
- package/dist/types/modules/schemas/index.d.ts.map +1 -1
- package/dist/types/modules/schemas/types.d.ts +17 -7
- package/dist/types/modules/schemas/types.d.ts.map +1 -1
- package/dist/types/types.d.ts +1 -13
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -10,67 +10,84 @@ function normalizeMimeTypes(mime) {
|
|
|
10
10
|
if (!mime) return [];
|
|
11
11
|
return (Array.isArray(mime) ? mime : [mime]).map((m) => m.toLowerCase());
|
|
12
12
|
}
|
|
13
|
-
function createFileSchema(options = {}) {
|
|
13
|
+
function createFileSchema(options = {}, isStream = false) {
|
|
14
14
|
const extensions = normalizeExtensions(options.ext);
|
|
15
15
|
const mimeTypes = normalizeMimeTypes(options.mimeType);
|
|
16
|
-
const
|
|
16
|
+
const finalIsStream = options._isStream || isStream;
|
|
17
|
+
const baseSchema = {
|
|
17
18
|
fieldname: zod.z.string(),
|
|
18
19
|
originalname: zod.z.string(),
|
|
19
20
|
encoding: zod.z.string(),
|
|
20
21
|
mimetype: zod.z.string(),
|
|
21
|
-
size: zod.z.number()
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
22
|
+
size: zod.z.number()
|
|
23
|
+
};
|
|
24
|
+
const extendedSchema = finalIsStream ? { ...baseSchema, file: zod.z.instanceof(stream.Readable).optional() } : { ...baseSchema, buffer: zod.z.instanceof(Buffer).optional() };
|
|
25
|
+
const fileSchema = zod.z.object(extendedSchema);
|
|
26
|
+
let schemaWithValidations = fileSchema;
|
|
27
|
+
if (extensions.length > 0) {
|
|
28
|
+
schemaWithValidations = schemaWithValidations.refine(
|
|
29
|
+
(file) => {
|
|
30
|
+
const fileExt = file.originalname.toLowerCase().substring(file.originalname.lastIndexOf("."));
|
|
31
|
+
return extensions.includes(fileExt);
|
|
32
|
+
},
|
|
33
|
+
{ message: `Invalid file extension. Allowed: ${extensions.join(", ")}`, path: ["originalname"] }
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (mimeTypes.length > 0) {
|
|
37
|
+
schemaWithValidations = schemaWithValidations.refine(
|
|
38
|
+
(file) => mimeTypes.includes(file.mimetype.toLowerCase()),
|
|
39
|
+
{ message: `Invalid mime type. Allowed: ${mimeTypes.join(", ")}`, path: ["mimetype"] }
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
if (options.maxSize !== void 0) {
|
|
43
|
+
schemaWithValidations = schemaWithValidations.refine(
|
|
44
|
+
(file) => file.size <= options.maxSize,
|
|
45
|
+
{ message: `File size exceeds maximum of ${options.maxSize} bytes`, path: ["size"] }
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (options.minSize !== void 0) {
|
|
49
|
+
schemaWithValidations = schemaWithValidations.refine(
|
|
50
|
+
(file) => file.size >= options.minSize,
|
|
51
|
+
{ message: `File size must be at least ${options.minSize} bytes`, path: ["size"] }
|
|
52
|
+
);
|
|
53
|
+
}
|
|
50
54
|
const chainedSchema = Object.create(schemaWithValidations);
|
|
51
|
-
chainedSchema.format = (ext) => createFileSchema({ ...options, ext: normalizeExtensions(ext) });
|
|
52
|
-
chainedSchema.mimeType = (mime) => createFileSchema({ ...options, mimeType: normalizeMimeTypes(mime) });
|
|
53
|
-
chainedSchema.maxSize = (size) => createFileSchema({ ...options, maxSize: size });
|
|
54
|
-
chainedSchema.minSize = (size) => createFileSchema({ ...options, minSize: size });
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
chainedSchema.
|
|
72
|
-
|
|
73
|
-
|
|
55
|
+
chainedSchema.format = (ext) => createFileSchema({ ...options, ext: normalizeExtensions(ext), _isStream: finalIsStream }, finalIsStream);
|
|
56
|
+
chainedSchema.mimeType = (mime) => createFileSchema({ ...options, mimeType: normalizeMimeTypes(mime), _isStream: finalIsStream }, finalIsStream);
|
|
57
|
+
chainedSchema.maxSize = (size) => createFileSchema({ ...options, maxSize: size, _isStream: finalIsStream }, finalIsStream);
|
|
58
|
+
chainedSchema.minSize = (size) => createFileSchema({ ...options, minSize: size, _isStream: finalIsStream }, finalIsStream);
|
|
59
|
+
chainedSchema.stream = () => createFileSchema({ ...options, _isStream: true }, true);
|
|
60
|
+
chainedSchema.image = () => createFileSchema({
|
|
61
|
+
mimeType: ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"],
|
|
62
|
+
ext: ["jpg", "jpeg", "png", "gif", "webp", "svg"],
|
|
63
|
+
_isStream: finalIsStream
|
|
64
|
+
}, finalIsStream);
|
|
65
|
+
chainedSchema.document = () => createFileSchema({
|
|
66
|
+
mimeType: ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain"],
|
|
67
|
+
ext: ["pdf", "doc", "docx", "txt"],
|
|
68
|
+
_isStream: finalIsStream
|
|
69
|
+
}, finalIsStream);
|
|
70
|
+
chainedSchema.video = () => createFileSchema({
|
|
71
|
+
mimeType: ["video/mp4", "video/webm", "video/ogg"],
|
|
72
|
+
ext: ["mp4", "webm", "ogg"],
|
|
73
|
+
_isStream: finalIsStream
|
|
74
|
+
}, finalIsStream);
|
|
75
|
+
chainedSchema.audio = () => createFileSchema({
|
|
76
|
+
mimeType: ["audio/mpeg", "audio/wav", "audio/ogg", "audio/webm"],
|
|
77
|
+
ext: ["mp3", "wav", "ogg", "webm"],
|
|
78
|
+
_isStream: finalIsStream
|
|
79
|
+
}, finalIsStream);
|
|
80
|
+
chainedSchema.archive = () => createFileSchema({
|
|
81
|
+
mimeType: ["application/zip", "application/x-rar-compressed", "application/x-7z-compressed"],
|
|
82
|
+
ext: ["zip", "rar", "7z"],
|
|
83
|
+
_isStream: finalIsStream
|
|
84
|
+
}, finalIsStream);
|
|
85
|
+
chainedSchema.any = () => createFileSchema({ ...options, _isStream: finalIsStream }, finalIsStream);
|
|
86
|
+
chainedSchema._isStream = finalIsStream;
|
|
87
|
+
chainedSchema._extensions = extensions;
|
|
88
|
+
chainedSchema._mimeTypes = mimeTypes;
|
|
89
|
+
chainedSchema._maxSize = options.maxSize;
|
|
90
|
+
chainedSchema._minSize = options.minSize;
|
|
74
91
|
return chainedSchema;
|
|
75
92
|
}
|
|
76
93
|
function createFilesArraySchema(fieldName, options = {}) {
|
|
@@ -80,59 +97,19 @@ function createFilesArraySchema(fieldName, options = {}) {
|
|
|
80
97
|
});
|
|
81
98
|
}
|
|
82
99
|
const fileValidators = {
|
|
83
|
-
format: (ext) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
},
|
|
97
|
-
stream: () => {
|
|
98
|
-
return createStreamFileSchema({});
|
|
99
|
-
},
|
|
100
|
-
image: () => {
|
|
101
|
-
return createFileSchema({
|
|
102
|
-
mimeType: ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"],
|
|
103
|
-
ext: ["jpg", "jpeg", "png", "gif", "webp", "svg"]
|
|
104
|
-
});
|
|
105
|
-
},
|
|
106
|
-
document: () => {
|
|
107
|
-
return createFileSchema({
|
|
108
|
-
mimeType: ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain"],
|
|
109
|
-
ext: ["pdf", "doc", "docx", "txt"]
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
|
-
video: () => {
|
|
113
|
-
return createFileSchema({
|
|
114
|
-
mimeType: ["video/mp4", "video/webm", "video/ogg"],
|
|
115
|
-
ext: ["mp4", "webm", "ogg"]
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
audio: () => {
|
|
119
|
-
return createFileSchema({
|
|
120
|
-
mimeType: ["audio/mpeg", "audio/wav", "audio/ogg", "audio/webm"],
|
|
121
|
-
ext: ["mp3", "wav", "ogg", "webm"]
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
archive: () => {
|
|
125
|
-
return createFileSchema({
|
|
126
|
-
mimeType: ["application/zip", "application/x-rar-compressed", "application/x-7z-compressed"],
|
|
127
|
-
ext: ["zip", "rar", "7z"]
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
|
-
any: () => {
|
|
131
|
-
return createFileSchema({});
|
|
132
|
-
},
|
|
133
|
-
field: (fieldName, options) => {
|
|
134
|
-
return createFilesArraySchema(fieldName, options);
|
|
135
|
-
}
|
|
100
|
+
format: (ext) => createFileSchema({ ext: normalizeExtensions(ext) }),
|
|
101
|
+
mimeType: (mimeType) => createFileSchema({ mimeType: normalizeMimeTypes(mimeType) }),
|
|
102
|
+
maxSize: (maxSize) => createFileSchema({ maxSize }),
|
|
103
|
+
minSize: (minSize) => createFileSchema({ minSize }),
|
|
104
|
+
stream: () => createFileSchema({ _isStream: true }, true),
|
|
105
|
+
image: () => createFileSchema({ mimeType: ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"], ext: ["jpg", "jpeg", "png", "gif", "webp", "svg"] }),
|
|
106
|
+
document: () => createFileSchema({ mimeType: ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain"], ext: ["pdf", "doc", "docx", "txt"] }),
|
|
107
|
+
video: () => createFileSchema({ mimeType: ["video/mp4", "video/webm", "video/ogg"], ext: ["mp4", "webm", "ogg"] }),
|
|
108
|
+
audio: () => createFileSchema({ mimeType: ["audio/mpeg", "audio/wav", "audio/ogg", "audio/webm"], ext: ["mp3", "wav", "ogg", "webm"] }),
|
|
109
|
+
archive: () => createFileSchema({ mimeType: ["application/zip", "application/x-rar-compressed", "application/x-7z-compressed"], ext: ["zip", "rar", "7z"] }),
|
|
110
|
+
any: () => createFileSchema({}),
|
|
111
|
+
field: (fieldName, options) => createFilesArraySchema(fieldName, options),
|
|
112
|
+
_isStream: false
|
|
136
113
|
};
|
|
137
114
|
function normalizeHeadersSchema(schema) {
|
|
138
115
|
const shape = schema.shape ?? schema._def?.shape?.();
|
|
@@ -178,7 +155,7 @@ function parseSchema(schema, data) {
|
|
|
178
155
|
function defineRouteSchema(schema) {
|
|
179
156
|
const headersSchema = schema.headers ? normalizeHeadersSchema(schema.headers) : null;
|
|
180
157
|
const fileFields = schema.files ? Object.keys(schema.files) : [];
|
|
181
|
-
const hasStreaming = !!(schema.files && typeof schema.files === "object" && Object.values(schema.files).some((f) => f.
|
|
158
|
+
const hasStreaming = !!(schema.files && typeof schema.files === "object" && Object.values(schema.files).some((f) => !!f._isStream));
|
|
182
159
|
const middleware = (req, res, next) => {
|
|
183
160
|
const errors = [];
|
|
184
161
|
const method = req.method.toUpperCase();
|
|
@@ -207,9 +184,7 @@ function defineRouteSchema(schema) {
|
|
|
207
184
|
const isOptional = fieldSchema.isOptional ? fieldSchema.isOptional() : false;
|
|
208
185
|
if (filesArray.length > 0 || isOptional) {
|
|
209
186
|
const result = parseSchema(fieldSchema, filesArray);
|
|
210
|
-
if (!result.success) {
|
|
211
|
-
errors.push(...result.errors.map((e) => ({ location: "files", path: fieldName, message: `${e.path || fieldName}: ${e.message}` })));
|
|
212
|
-
}
|
|
187
|
+
if (!result.success) errors.push(...result.errors.map((e) => ({ location: "files", path: fieldName, message: `${e.path || fieldName}: ${e.message}` })));
|
|
213
188
|
}
|
|
214
189
|
}
|
|
215
190
|
}
|
|
@@ -8,67 +8,84 @@ function normalizeMimeTypes(mime) {
|
|
|
8
8
|
if (!mime) return [];
|
|
9
9
|
return (Array.isArray(mime) ? mime : [mime]).map((m) => m.toLowerCase());
|
|
10
10
|
}
|
|
11
|
-
function createFileSchema(options = {}) {
|
|
11
|
+
function createFileSchema(options = {}, isStream = false) {
|
|
12
12
|
const extensions = normalizeExtensions(options.ext);
|
|
13
13
|
const mimeTypes = normalizeMimeTypes(options.mimeType);
|
|
14
|
-
const
|
|
14
|
+
const finalIsStream = options._isStream || isStream;
|
|
15
|
+
const baseSchema = {
|
|
15
16
|
fieldname: z.string(),
|
|
16
17
|
originalname: z.string(),
|
|
17
18
|
encoding: z.string(),
|
|
18
19
|
mimetype: z.string(),
|
|
19
|
-
size: z.number()
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
20
|
+
size: z.number()
|
|
21
|
+
};
|
|
22
|
+
const extendedSchema = finalIsStream ? { ...baseSchema, file: z.instanceof(Readable).optional() } : { ...baseSchema, buffer: z.instanceof(Buffer).optional() };
|
|
23
|
+
const fileSchema = z.object(extendedSchema);
|
|
24
|
+
let schemaWithValidations = fileSchema;
|
|
25
|
+
if (extensions.length > 0) {
|
|
26
|
+
schemaWithValidations = schemaWithValidations.refine(
|
|
27
|
+
(file) => {
|
|
28
|
+
const fileExt = file.originalname.toLowerCase().substring(file.originalname.lastIndexOf("."));
|
|
29
|
+
return extensions.includes(fileExt);
|
|
30
|
+
},
|
|
31
|
+
{ message: `Invalid file extension. Allowed: ${extensions.join(", ")}`, path: ["originalname"] }
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (mimeTypes.length > 0) {
|
|
35
|
+
schemaWithValidations = schemaWithValidations.refine(
|
|
36
|
+
(file) => mimeTypes.includes(file.mimetype.toLowerCase()),
|
|
37
|
+
{ message: `Invalid mime type. Allowed: ${mimeTypes.join(", ")}`, path: ["mimetype"] }
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
if (options.maxSize !== void 0) {
|
|
41
|
+
schemaWithValidations = schemaWithValidations.refine(
|
|
42
|
+
(file) => file.size <= options.maxSize,
|
|
43
|
+
{ message: `File size exceeds maximum of ${options.maxSize} bytes`, path: ["size"] }
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (options.minSize !== void 0) {
|
|
47
|
+
schemaWithValidations = schemaWithValidations.refine(
|
|
48
|
+
(file) => file.size >= options.minSize,
|
|
49
|
+
{ message: `File size must be at least ${options.minSize} bytes`, path: ["size"] }
|
|
50
|
+
);
|
|
51
|
+
}
|
|
48
52
|
const chainedSchema = Object.create(schemaWithValidations);
|
|
49
|
-
chainedSchema.format = (ext) => createFileSchema({ ...options, ext: normalizeExtensions(ext) });
|
|
50
|
-
chainedSchema.mimeType = (mime) => createFileSchema({ ...options, mimeType: normalizeMimeTypes(mime) });
|
|
51
|
-
chainedSchema.maxSize = (size) => createFileSchema({ ...options, maxSize: size });
|
|
52
|
-
chainedSchema.minSize = (size) => createFileSchema({ ...options, minSize: size });
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
chainedSchema.
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
chainedSchema.format = (ext) => createFileSchema({ ...options, ext: normalizeExtensions(ext), _isStream: finalIsStream }, finalIsStream);
|
|
54
|
+
chainedSchema.mimeType = (mime) => createFileSchema({ ...options, mimeType: normalizeMimeTypes(mime), _isStream: finalIsStream }, finalIsStream);
|
|
55
|
+
chainedSchema.maxSize = (size) => createFileSchema({ ...options, maxSize: size, _isStream: finalIsStream }, finalIsStream);
|
|
56
|
+
chainedSchema.minSize = (size) => createFileSchema({ ...options, minSize: size, _isStream: finalIsStream }, finalIsStream);
|
|
57
|
+
chainedSchema.stream = () => createFileSchema({ ...options, _isStream: true }, true);
|
|
58
|
+
chainedSchema.image = () => createFileSchema({
|
|
59
|
+
mimeType: ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"],
|
|
60
|
+
ext: ["jpg", "jpeg", "png", "gif", "webp", "svg"],
|
|
61
|
+
_isStream: finalIsStream
|
|
62
|
+
}, finalIsStream);
|
|
63
|
+
chainedSchema.document = () => createFileSchema({
|
|
64
|
+
mimeType: ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain"],
|
|
65
|
+
ext: ["pdf", "doc", "docx", "txt"],
|
|
66
|
+
_isStream: finalIsStream
|
|
67
|
+
}, finalIsStream);
|
|
68
|
+
chainedSchema.video = () => createFileSchema({
|
|
69
|
+
mimeType: ["video/mp4", "video/webm", "video/ogg"],
|
|
70
|
+
ext: ["mp4", "webm", "ogg"],
|
|
71
|
+
_isStream: finalIsStream
|
|
72
|
+
}, finalIsStream);
|
|
73
|
+
chainedSchema.audio = () => createFileSchema({
|
|
74
|
+
mimeType: ["audio/mpeg", "audio/wav", "audio/ogg", "audio/webm"],
|
|
75
|
+
ext: ["mp3", "wav", "ogg", "webm"],
|
|
76
|
+
_isStream: finalIsStream
|
|
77
|
+
}, finalIsStream);
|
|
78
|
+
chainedSchema.archive = () => createFileSchema({
|
|
79
|
+
mimeType: ["application/zip", "application/x-rar-compressed", "application/x-7z-compressed"],
|
|
80
|
+
ext: ["zip", "rar", "7z"],
|
|
81
|
+
_isStream: finalIsStream
|
|
82
|
+
}, finalIsStream);
|
|
83
|
+
chainedSchema.any = () => createFileSchema({ ...options, _isStream: finalIsStream }, finalIsStream);
|
|
84
|
+
chainedSchema._isStream = finalIsStream;
|
|
85
|
+
chainedSchema._extensions = extensions;
|
|
86
|
+
chainedSchema._mimeTypes = mimeTypes;
|
|
87
|
+
chainedSchema._maxSize = options.maxSize;
|
|
88
|
+
chainedSchema._minSize = options.minSize;
|
|
72
89
|
return chainedSchema;
|
|
73
90
|
}
|
|
74
91
|
function createFilesArraySchema(fieldName, options = {}) {
|
|
@@ -78,59 +95,19 @@ function createFilesArraySchema(fieldName, options = {}) {
|
|
|
78
95
|
});
|
|
79
96
|
}
|
|
80
97
|
const fileValidators = {
|
|
81
|
-
format: (ext) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
},
|
|
95
|
-
stream: () => {
|
|
96
|
-
return createStreamFileSchema({});
|
|
97
|
-
},
|
|
98
|
-
image: () => {
|
|
99
|
-
return createFileSchema({
|
|
100
|
-
mimeType: ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"],
|
|
101
|
-
ext: ["jpg", "jpeg", "png", "gif", "webp", "svg"]
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
document: () => {
|
|
105
|
-
return createFileSchema({
|
|
106
|
-
mimeType: ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain"],
|
|
107
|
-
ext: ["pdf", "doc", "docx", "txt"]
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
video: () => {
|
|
111
|
-
return createFileSchema({
|
|
112
|
-
mimeType: ["video/mp4", "video/webm", "video/ogg"],
|
|
113
|
-
ext: ["mp4", "webm", "ogg"]
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
audio: () => {
|
|
117
|
-
return createFileSchema({
|
|
118
|
-
mimeType: ["audio/mpeg", "audio/wav", "audio/ogg", "audio/webm"],
|
|
119
|
-
ext: ["mp3", "wav", "ogg", "webm"]
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
archive: () => {
|
|
123
|
-
return createFileSchema({
|
|
124
|
-
mimeType: ["application/zip", "application/x-rar-compressed", "application/x-7z-compressed"],
|
|
125
|
-
ext: ["zip", "rar", "7z"]
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
any: () => {
|
|
129
|
-
return createFileSchema({});
|
|
130
|
-
},
|
|
131
|
-
field: (fieldName, options) => {
|
|
132
|
-
return createFilesArraySchema(fieldName, options);
|
|
133
|
-
}
|
|
98
|
+
format: (ext) => createFileSchema({ ext: normalizeExtensions(ext) }),
|
|
99
|
+
mimeType: (mimeType) => createFileSchema({ mimeType: normalizeMimeTypes(mimeType) }),
|
|
100
|
+
maxSize: (maxSize) => createFileSchema({ maxSize }),
|
|
101
|
+
minSize: (minSize) => createFileSchema({ minSize }),
|
|
102
|
+
stream: () => createFileSchema({ _isStream: true }, true),
|
|
103
|
+
image: () => createFileSchema({ mimeType: ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"], ext: ["jpg", "jpeg", "png", "gif", "webp", "svg"] }),
|
|
104
|
+
document: () => createFileSchema({ mimeType: ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain"], ext: ["pdf", "doc", "docx", "txt"] }),
|
|
105
|
+
video: () => createFileSchema({ mimeType: ["video/mp4", "video/webm", "video/ogg"], ext: ["mp4", "webm", "ogg"] }),
|
|
106
|
+
audio: () => createFileSchema({ mimeType: ["audio/mpeg", "audio/wav", "audio/ogg", "audio/webm"], ext: ["mp3", "wav", "ogg", "webm"] }),
|
|
107
|
+
archive: () => createFileSchema({ mimeType: ["application/zip", "application/x-rar-compressed", "application/x-7z-compressed"], ext: ["zip", "rar", "7z"] }),
|
|
108
|
+
any: () => createFileSchema({}),
|
|
109
|
+
field: (fieldName, options) => createFilesArraySchema(fieldName, options),
|
|
110
|
+
_isStream: false
|
|
134
111
|
};
|
|
135
112
|
function normalizeHeadersSchema(schema) {
|
|
136
113
|
const shape = schema.shape ?? schema._def?.shape?.();
|
|
@@ -176,7 +153,7 @@ function parseSchema(schema, data) {
|
|
|
176
153
|
function defineRouteSchema(schema) {
|
|
177
154
|
const headersSchema = schema.headers ? normalizeHeadersSchema(schema.headers) : null;
|
|
178
155
|
const fileFields = schema.files ? Object.keys(schema.files) : [];
|
|
179
|
-
const hasStreaming = !!(schema.files && typeof schema.files === "object" && Object.values(schema.files).some((f) => f.
|
|
156
|
+
const hasStreaming = !!(schema.files && typeof schema.files === "object" && Object.values(schema.files).some((f) => !!f._isStream));
|
|
180
157
|
const middleware = (req, res, next) => {
|
|
181
158
|
const errors = [];
|
|
182
159
|
const method = req.method.toUpperCase();
|
|
@@ -205,9 +182,7 @@ function defineRouteSchema(schema) {
|
|
|
205
182
|
const isOptional = fieldSchema.isOptional ? fieldSchema.isOptional() : false;
|
|
206
183
|
if (filesArray.length > 0 || isOptional) {
|
|
207
184
|
const result = parseSchema(fieldSchema, filesArray);
|
|
208
|
-
if (!result.success) {
|
|
209
|
-
errors.push(...result.errors.map((e) => ({ location: "files", path: fieldName, message: `${e.path || fieldName}: ${e.message}` })));
|
|
210
|
-
}
|
|
185
|
+
if (!result.success) errors.push(...result.errors.map((e) => ({ location: "files", path: fieldName, message: `${e.path || fieldName}: ${e.message}` })));
|
|
211
186
|
}
|
|
212
187
|
}
|
|
213
188
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { Sprint, isDevelopment, isProduction } from './sprint';
|
|
|
3
3
|
export { defineMiddleware } from './middleware';
|
|
4
4
|
export { __filename, __dirname } from './utils';
|
|
5
5
|
export type { Handler, AsyncRequestHandler, MiddlewareConfig, SprintOptions, LoadedMiddleware, AuthorizationSource, SprintRequest, SprintResponse, NextFunction } from './types';
|
|
6
|
+
export type { FileObject, SprintFiles } from './modules/schemas/types';
|
|
6
7
|
export declare const Router: () => import('express-serve-static-core').Router;
|
|
7
8
|
export default Sprint;
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGhD,YAAY,EAAE,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGjL,eAAO,MAAM,MAAM,kDAAwB,CAAC;AAG5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,eAAe,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGhD,YAAY,EAAE,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAGjL,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGvE,eAAO,MAAM,MAAM,kDAAwB,CAAC;AAG5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,eAAe,MAAM,CAAC"}
|
|
@@ -1,33 +1,13 @@
|
|
|
1
1
|
import { RequestHandler } from 'express';
|
|
2
2
|
import { z, ZodSchema as ZodSchemaType, ZodTypeDef } from 'zod';
|
|
3
|
-
import { FileObject, FileSchemaType,
|
|
3
|
+
import { FileObject, FileSchemaType, FileValidationOptions } from './types';
|
|
4
4
|
export type AuthorizationSource = `query:${string}` | `headers:${string}`;
|
|
5
5
|
export interface SprintAuthorizationOptions {
|
|
6
6
|
sources?: AuthorizationSource | AuthorizationSource[];
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
ext?: string | string[];
|
|
10
|
-
mimeType?: string | string[];
|
|
11
|
-
maxSize?: number;
|
|
12
|
-
minSize?: number;
|
|
13
|
-
required?: boolean;
|
|
14
|
-
}
|
|
15
|
-
declare function createFileSchema(options?: FileValidationOptions): FileSchemaType;
|
|
8
|
+
declare function createFileSchema(options?: FileValidationOptions, isStream?: boolean): FileSchemaType;
|
|
16
9
|
declare function createFilesArraySchema(fieldName: string, options?: FileValidationOptions): ZodSchemaType<FileObject[], ZodTypeDef, FileObject[]>;
|
|
17
|
-
declare const fileValidators:
|
|
18
|
-
format: (ext: string | string[]) => FileSchemaType;
|
|
19
|
-
mimeType: (mimeType: string | string[]) => FileSchemaType;
|
|
20
|
-
maxSize: (maxSize: number) => FileSchemaType;
|
|
21
|
-
minSize: (minSize: number) => FileSchemaType;
|
|
22
|
-
stream: () => StreamFileSchemaType;
|
|
23
|
-
image: () => FileSchemaType;
|
|
24
|
-
document: () => FileSchemaType;
|
|
25
|
-
video: () => FileSchemaType;
|
|
26
|
-
audio: () => FileSchemaType;
|
|
27
|
-
archive: () => FileSchemaType;
|
|
28
|
-
any: () => FileSchemaType;
|
|
29
|
-
field: (fieldName: string, options?: FileValidationOptions) => z.ZodType<FileObject[], z.ZodTypeDef, FileObject[]>;
|
|
30
|
-
};
|
|
10
|
+
declare const fileValidators: FileSchemaType;
|
|
31
11
|
export declare function normalizeHeadersSchema(schema: any): any;
|
|
32
12
|
declare function createSprintAuthorizationSchema(options?: SprintAuthorizationOptions): ZodSchemaType<string, ZodTypeDef, string>;
|
|
33
13
|
declare const sprintBuilder: {
|
|
@@ -46,7 +26,7 @@ export { proxyZ as z };
|
|
|
46
26
|
export { sprintBuilder as sprint };
|
|
47
27
|
export { fileValidators as files };
|
|
48
28
|
export { createFileSchema, createFilesArraySchema };
|
|
49
|
-
export type { FileSchemaType } from './types';
|
|
29
|
+
export type { FileSchemaType, SprintFiles } from './types';
|
|
50
30
|
export interface RouteSchemaOptions {
|
|
51
31
|
body?: ZodSchemaType<any, ZodTypeDef, any>;
|
|
52
32
|
queryParams?: ZodSchemaType<any, ZodTypeDef, any>;
|
|
@@ -63,5 +43,5 @@ export declare function defineRouteSchema<T extends RouteSchemaOptions>(schema:
|
|
|
63
43
|
getFileFields?: () => string[];
|
|
64
44
|
hasStreamingFiles?: () => boolean;
|
|
65
45
|
};
|
|
66
|
-
export type { ZodSchema, ZodMiddlewareOptions } from './types';
|
|
46
|
+
export type { ZodSchema, ZodMiddlewareOptions, FileValidationOptions } from './types';
|
|
67
47
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/schemas/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/schemas/index.ts"],"names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EAAE,aAAa,IAAI,MAAM,EAAE,CAAC;AACnC,OAAO,EAAE,cAAc,IAAI,KAAK,EAAE,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,CAAC;AAEpD,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IAC/B,IAAI,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC3C,WAAW,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAClD,MAAM,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAC9C,KAAK,CAAC,EAAE;QACJ,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;KAC5D,CAAC;IACF,MAAM,CAAC,EAAE;QACL,aAAa,CAAC,EAAE,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;KAC7D,CAAC;CACL;AAqBD,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,cAAc,GAAG;IACzF,aAAa,CAAC,EAAE,MAAM,MAAM,EAAE,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC;CACrC,CAgGA;AAED,YAAY,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -16,6 +16,7 @@ export interface FileValidationOptions {
|
|
|
16
16
|
maxSize?: number;
|
|
17
17
|
minSize?: number;
|
|
18
18
|
required?: boolean;
|
|
19
|
+
_isStream?: boolean;
|
|
19
20
|
}
|
|
20
21
|
export type FileObject = {
|
|
21
22
|
fieldname: string;
|
|
@@ -24,6 +25,7 @@ export type FileObject = {
|
|
|
24
25
|
mimetype: string;
|
|
25
26
|
size: number;
|
|
26
27
|
buffer?: Buffer;
|
|
28
|
+
file?: NodeJS.ReadableStream;
|
|
27
29
|
};
|
|
28
30
|
export type StreamFileObject = {
|
|
29
31
|
fieldName: string;
|
|
@@ -37,13 +39,21 @@ export type FileSchemaType = ZodType<FileObject, ZodTypeDef, FileObject> & {
|
|
|
37
39
|
mimeType(mimeType: string | string[]): FileSchemaType;
|
|
38
40
|
maxSize(maxSize: number): FileSchemaType;
|
|
39
41
|
minSize(minSize: number): FileSchemaType;
|
|
40
|
-
stream():
|
|
42
|
+
stream(): FileSchemaType;
|
|
43
|
+
image(): FileSchemaType;
|
|
44
|
+
document(): FileSchemaType;
|
|
45
|
+
video(): FileSchemaType;
|
|
46
|
+
audio(): FileSchemaType;
|
|
47
|
+
archive(): FileSchemaType;
|
|
48
|
+
any(): FileSchemaType;
|
|
49
|
+
_isStream?: boolean;
|
|
50
|
+
_extensions?: string[];
|
|
51
|
+
_mimeTypes?: string[];
|
|
52
|
+
_maxSize?: number;
|
|
53
|
+
_minSize?: number;
|
|
41
54
|
};
|
|
42
|
-
export type StreamFileSchemaType =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
maxSize(maxSize: number): StreamFileSchemaType;
|
|
46
|
-
minSize(minSize: number): StreamFileSchemaType;
|
|
47
|
-
stream(): StreamFileSchemaType;
|
|
55
|
+
export type StreamFileSchemaType = FileSchemaType;
|
|
56
|
+
export type SprintFiles = {
|
|
57
|
+
[fieldname: string]: FileObject[];
|
|
48
58
|
};
|
|
49
59
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/modules/schemas/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KA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tB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAElD,MAAM,MAAM,WAAW,GAAG;IACtB,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,EAAE,CAAC;CACrC,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction, RequestHandler } from 'express';
|
|
2
|
-
import { ZodSchema
|
|
2
|
+
import { ZodSchema } from './modules/schemas/types';
|
|
3
3
|
export type AsyncRequestHandler = (req: SprintRequest, res: SprintResponse, next: NextFunction) => Promise<any>;
|
|
4
4
|
export type Handler = (req: SprintRequest, res: SprintResponse, next: NextFunction) => any;
|
|
5
5
|
export type AuthorizationSource = `query:${string}` | `headers:${string}`;
|
|
@@ -9,10 +9,6 @@ export type SprintRequest = Request & {
|
|
|
9
9
|
authorization?: string;
|
|
10
10
|
};
|
|
11
11
|
custom: any;
|
|
12
|
-
file?: FileObject;
|
|
13
|
-
files?: {
|
|
14
|
-
[fieldname: string]: FileObject[];
|
|
15
|
-
} | FileObject[];
|
|
16
12
|
};
|
|
17
13
|
export type SprintResponse = Response;
|
|
18
14
|
declare global {
|
|
@@ -26,14 +22,6 @@ declare global {
|
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
}
|
|
29
|
-
declare module "express-serve-static-core" {
|
|
30
|
-
interface Request {
|
|
31
|
-
file?: FileObject;
|
|
32
|
-
files?: {
|
|
33
|
-
[fieldname: string]: FileObject[];
|
|
34
|
-
} | FileObject[];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
25
|
export interface MiddlewareSchema {
|
|
38
26
|
body?: ZodSchema;
|
|
39
27
|
queryParams?: ZodSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,MAAM,MAAM,mBAAmB,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAChH,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,YAAY,KAAK,GAAG,CAAC;AAE3F,MAAM,MAAM,mBAAmB,GACzB,SAAS,MAAM,EAAE,GACjB,WAAW,MAAM,EAAE,CAAC;AAE1B,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IAClC,MAAM,EAAE;QACJ,gBAAgB,EAAE,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,mBAAmB,EAAE,KAAK,MAAM,GAAG,SAAS,CAAC;QAChG,aAAa,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,MAAM,EAAE,GAAG,CAAC;CACf,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEtC,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC;QACd,UAAU,OAAO;YACb,MAAM,EAAE;gBACJ,gBAAgB,EAAE,CAAC,OAAO,CAAC,EAAE,mBAA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