tspace-spear 1.2.7 → 1.2.9
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 +299 -146
- package/dist/cli/generators/app/index.d.ts +1 -0
- package/dist/cli/generators/app/index.js +124 -0
- package/dist/cli/generators/app/index.js.map +1 -0
- package/dist/cli/generators/app/template.d.ts +1 -0
- package/dist/cli/{app.js → generators/app/template.js} +22 -8
- package/dist/cli/generators/app/template.js.map +1 -0
- package/dist/cli/generators/client/template.d.ts +1 -0
- package/dist/cli/generators/client/template.js +30 -0
- package/dist/cli/generators/client/template.js.map +1 -0
- package/dist/cli/generators/controller/index.d.ts +1 -0
- package/dist/cli/generators/controller/index.js +78 -0
- package/dist/cli/generators/controller/index.js.map +1 -0
- package/dist/cli/generators/controller/template.d.ts +1 -0
- package/dist/cli/generators/controller/template.js +106 -0
- package/dist/cli/generators/controller/template.js.map +1 -0
- package/dist/cli/generators/dto/index.d.ts +1 -0
- package/dist/cli/generators/dto/index.js +57 -0
- package/dist/cli/generators/dto/index.js.map +1 -0
- package/dist/cli/generators/dto/template.d.ts +1 -0
- package/dist/cli/generators/dto/template.js +32 -0
- package/dist/cli/generators/dto/template.js.map +1 -0
- package/dist/cli/generators/middleware/index.d.ts +1 -0
- package/dist/cli/generators/middleware/index.js +38 -0
- package/dist/cli/generators/middleware/index.js.map +1 -0
- package/dist/cli/generators/middleware/template.d.ts +1 -0
- package/dist/cli/generators/middleware/template.js +16 -0
- package/dist/cli/generators/middleware/template.js.map +1 -0
- package/dist/cli/generators/module/index.d.ts +1 -0
- package/dist/cli/generators/module/index.js +173 -0
- package/dist/cli/generators/module/index.js.map +1 -0
- package/dist/cli/generators/service/index.d.ts +1 -0
- package/dist/cli/generators/service/index.js +53 -0
- package/dist/cli/generators/service/index.js.map +1 -0
- package/dist/cli/generators/service/template.d.ts +1 -0
- package/dist/cli/generators/service/template.js +74 -0
- package/dist/cli/generators/service/template.js.map +1 -0
- package/dist/cli/generators/shared/index.d.ts +3 -0
- package/dist/cli/generators/shared/index.js +22 -0
- package/dist/cli/generators/shared/index.js.map +1 -0
- package/dist/cli/index.js +53 -96
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/core/client/index.d.ts +13 -43
- package/dist/lib/core/client/index.js +47 -26
- package/dist/lib/core/client/index.js.map +1 -1
- package/dist/lib/core/{compiler → client}/types.d.ts +29 -0
- package/dist/lib/core/client/types.js.map +1 -0
- package/dist/lib/core/compiler/generator.d.ts +4 -6
- package/dist/lib/core/compiler/generator.js +186 -39
- package/dist/lib/core/compiler/generator.js.map +1 -1
- package/dist/lib/core/compiler/index.d.ts +2 -2
- package/dist/lib/core/compiler/index.js +2 -2
- package/dist/lib/core/compiler/index.js.map +1 -1
- package/dist/lib/core/compiler/pre-routes.d.ts +170 -34
- package/dist/lib/core/compiler/pre-routes.js +45 -25
- package/dist/lib/core/compiler/pre-routes.js.map +1 -1
- package/dist/lib/core/decorators/context.d.ts +78 -8
- package/dist/lib/core/decorators/context.js +84 -9
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/decorators/statusCode.js +3 -1
- package/dist/lib/core/decorators/statusCode.js.map +1 -1
- package/dist/lib/core/package/index.d.ts +11 -0
- package/dist/lib/core/package/index.js +42 -0
- package/dist/lib/core/package/index.js.map +1 -0
- package/dist/lib/core/server/fast-router.d.ts +2 -2
- package/dist/lib/core/server/fast-router.js +17 -3
- package/dist/lib/core/server/fast-router.js.map +1 -1
- package/dist/lib/core/server/index.js +2 -2
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/server/response.js +21 -1
- package/dist/lib/core/server/response.js.map +1 -1
- package/dist/lib/core/types/index.d.ts +32 -27
- package/package.json +7 -4
- package/dist/cli/app.d.ts +0 -1
- package/dist/cli/app.js.map +0 -1
- package/dist/cli/controller.d.ts +0 -1
- package/dist/cli/controller.js +0 -158
- package/dist/cli/controller.js.map +0 -1
- package/dist/lib/core/compiler/types.js.map +0 -1
- /package/dist/lib/core/{compiler → client}/types.js +0 -0
|
@@ -1,82 +1,149 @@
|
|
|
1
1
|
export declare const appRoutes: {
|
|
2
2
|
"/cats": {
|
|
3
3
|
GET: {
|
|
4
|
-
params:
|
|
4
|
+
params: undefined;
|
|
5
5
|
query: {
|
|
6
|
-
id:
|
|
6
|
+
id: number;
|
|
7
7
|
name: string;
|
|
8
8
|
};
|
|
9
|
-
body:
|
|
10
|
-
files:
|
|
9
|
+
body: undefined;
|
|
10
|
+
files: undefined;
|
|
11
11
|
response: {
|
|
12
|
+
message: string;
|
|
12
13
|
query: {
|
|
13
|
-
id:
|
|
14
|
+
id: number;
|
|
14
15
|
name: string;
|
|
15
16
|
};
|
|
16
17
|
cats: {
|
|
17
|
-
id:
|
|
18
|
+
id: number;
|
|
18
19
|
name: string;
|
|
19
|
-
age:
|
|
20
|
+
age: number;
|
|
20
21
|
}[];
|
|
21
22
|
};
|
|
22
23
|
};
|
|
23
24
|
POST: {
|
|
24
|
-
params:
|
|
25
|
-
query:
|
|
25
|
+
params: undefined;
|
|
26
|
+
query: undefined;
|
|
26
27
|
body: {
|
|
27
28
|
name: string;
|
|
28
|
-
age:
|
|
29
|
+
age: number;
|
|
29
30
|
};
|
|
30
|
-
files:
|
|
31
|
+
files: undefined;
|
|
31
32
|
response: {
|
|
33
|
+
message: string;
|
|
32
34
|
cat: {
|
|
33
35
|
name: string;
|
|
34
|
-
age:
|
|
35
|
-
id:
|
|
36
|
+
age: number;
|
|
37
|
+
id: number;
|
|
36
38
|
};
|
|
37
|
-
message: string;
|
|
38
39
|
};
|
|
39
40
|
};
|
|
40
41
|
};
|
|
41
42
|
"/cats/:id": {
|
|
42
43
|
GET: {
|
|
43
44
|
params: {
|
|
44
|
-
id:
|
|
45
|
+
id: number;
|
|
45
46
|
};
|
|
46
|
-
query:
|
|
47
|
-
body:
|
|
48
|
-
files:
|
|
47
|
+
query: undefined;
|
|
48
|
+
body: undefined;
|
|
49
|
+
files: undefined;
|
|
49
50
|
response: {
|
|
51
|
+
message: string;
|
|
50
52
|
cat: {
|
|
51
|
-
id:
|
|
53
|
+
id: number;
|
|
52
54
|
name: string;
|
|
53
|
-
age:
|
|
55
|
+
age: number;
|
|
54
56
|
};
|
|
55
57
|
};
|
|
56
58
|
};
|
|
57
59
|
PUT: {
|
|
58
60
|
params: {
|
|
59
|
-
id:
|
|
61
|
+
id: number;
|
|
60
62
|
};
|
|
61
|
-
query:
|
|
63
|
+
query: undefined;
|
|
62
64
|
body: {
|
|
63
65
|
name: string;
|
|
64
|
-
age:
|
|
66
|
+
age: number;
|
|
65
67
|
};
|
|
66
|
-
files:
|
|
68
|
+
files: undefined;
|
|
67
69
|
response: {
|
|
68
|
-
|
|
70
|
+
message: string;
|
|
71
|
+
cat: {
|
|
72
|
+
id: number;
|
|
73
|
+
name: string;
|
|
74
|
+
age: number;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
PATCH: {
|
|
79
|
+
params: {
|
|
80
|
+
id: number;
|
|
81
|
+
};
|
|
82
|
+
query: undefined;
|
|
83
|
+
body: {
|
|
84
|
+
name: string;
|
|
85
|
+
age: number;
|
|
86
|
+
};
|
|
87
|
+
files: undefined;
|
|
88
|
+
response: {
|
|
89
|
+
message: string;
|
|
90
|
+
cat: {
|
|
91
|
+
id: number;
|
|
92
|
+
name: string;
|
|
93
|
+
age: number;
|
|
94
|
+
};
|
|
69
95
|
};
|
|
70
96
|
};
|
|
71
97
|
DELETE: {
|
|
72
98
|
params: {
|
|
73
|
-
id:
|
|
99
|
+
id: number;
|
|
74
100
|
};
|
|
75
|
-
query:
|
|
76
|
-
body:
|
|
77
|
-
files:
|
|
101
|
+
query: undefined;
|
|
102
|
+
body: undefined;
|
|
103
|
+
files: undefined;
|
|
78
104
|
response: {
|
|
79
105
|
message: string;
|
|
106
|
+
deleted: boolean;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
"/cats/upload": {
|
|
111
|
+
POST: {
|
|
112
|
+
params: undefined;
|
|
113
|
+
query: undefined;
|
|
114
|
+
body: undefined;
|
|
115
|
+
files: {
|
|
116
|
+
image: {
|
|
117
|
+
size: number;
|
|
118
|
+
sizes: {
|
|
119
|
+
bytes: number;
|
|
120
|
+
kb: number;
|
|
121
|
+
mb: number;
|
|
122
|
+
gb: number;
|
|
123
|
+
};
|
|
124
|
+
tempFilePath: string;
|
|
125
|
+
tempFileName: string;
|
|
126
|
+
mimetype: string;
|
|
127
|
+
extension: string;
|
|
128
|
+
name: string;
|
|
129
|
+
}[];
|
|
130
|
+
};
|
|
131
|
+
response: {
|
|
132
|
+
message: string;
|
|
133
|
+
image: {
|
|
134
|
+
size: number;
|
|
135
|
+
sizes: {
|
|
136
|
+
bytes: number;
|
|
137
|
+
kb: number;
|
|
138
|
+
mb: number;
|
|
139
|
+
gb: number;
|
|
140
|
+
};
|
|
141
|
+
tempFilePath: string;
|
|
142
|
+
tempFileName: string;
|
|
143
|
+
mimetype: string;
|
|
144
|
+
extension: string;
|
|
145
|
+
name: string;
|
|
146
|
+
};
|
|
80
147
|
};
|
|
81
148
|
};
|
|
82
149
|
};
|
|
@@ -89,9 +156,10 @@ export interface AppRoutes {
|
|
|
89
156
|
id?: string;
|
|
90
157
|
name?: string;
|
|
91
158
|
};
|
|
92
|
-
body:
|
|
159
|
+
body: never;
|
|
93
160
|
files: never;
|
|
94
161
|
response: {
|
|
162
|
+
message: string;
|
|
95
163
|
query: {
|
|
96
164
|
id?: string;
|
|
97
165
|
name?: string;
|
|
@@ -112,12 +180,12 @@ export interface AppRoutes {
|
|
|
112
180
|
};
|
|
113
181
|
files: never;
|
|
114
182
|
response: {
|
|
183
|
+
message: string;
|
|
115
184
|
cat: {
|
|
116
185
|
name: string;
|
|
117
186
|
age: number;
|
|
118
187
|
id: number;
|
|
119
188
|
};
|
|
120
|
-
message: string;
|
|
121
189
|
};
|
|
122
190
|
};
|
|
123
191
|
};
|
|
@@ -127,9 +195,10 @@ export interface AppRoutes {
|
|
|
127
195
|
id: number;
|
|
128
196
|
};
|
|
129
197
|
query: never;
|
|
130
|
-
body:
|
|
198
|
+
body: never;
|
|
131
199
|
files: never;
|
|
132
200
|
response: {
|
|
201
|
+
message: string;
|
|
133
202
|
cat: {
|
|
134
203
|
id: number;
|
|
135
204
|
name: string;
|
|
@@ -147,17 +216,84 @@ export interface AppRoutes {
|
|
|
147
216
|
age?: number;
|
|
148
217
|
};
|
|
149
218
|
files: never;
|
|
150
|
-
response:
|
|
219
|
+
response: {
|
|
220
|
+
message: string;
|
|
221
|
+
cat: {
|
|
222
|
+
id: number;
|
|
223
|
+
name: string;
|
|
224
|
+
age: number;
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
PATCH: {
|
|
229
|
+
params: {
|
|
230
|
+
id: number;
|
|
231
|
+
};
|
|
232
|
+
query: never;
|
|
233
|
+
body: {
|
|
234
|
+
name?: string;
|
|
235
|
+
age?: number;
|
|
236
|
+
};
|
|
237
|
+
files: never;
|
|
238
|
+
response: {
|
|
239
|
+
message: string;
|
|
240
|
+
cat: {
|
|
241
|
+
id: number;
|
|
242
|
+
name: string;
|
|
243
|
+
age: number;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
151
246
|
};
|
|
152
247
|
DELETE: {
|
|
153
248
|
params: {
|
|
154
249
|
id: number;
|
|
155
250
|
};
|
|
156
251
|
query: never;
|
|
157
|
-
body:
|
|
252
|
+
body: never;
|
|
158
253
|
files: never;
|
|
159
254
|
response: {
|
|
160
255
|
message: string;
|
|
256
|
+
deleted: boolean;
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
"/cats/upload": {
|
|
261
|
+
POST: {
|
|
262
|
+
params: never;
|
|
263
|
+
query: never;
|
|
264
|
+
body: never;
|
|
265
|
+
files: {
|
|
266
|
+
image: {
|
|
267
|
+
size: number;
|
|
268
|
+
sizes: {
|
|
269
|
+
bytes: number;
|
|
270
|
+
kb: number;
|
|
271
|
+
mb: number;
|
|
272
|
+
gb: number;
|
|
273
|
+
};
|
|
274
|
+
tempFilePath: string;
|
|
275
|
+
tempFileName: string;
|
|
276
|
+
mimetype: string;
|
|
277
|
+
extension: string;
|
|
278
|
+
name: string;
|
|
279
|
+
}[];
|
|
280
|
+
};
|
|
281
|
+
response: {
|
|
282
|
+
message: string;
|
|
283
|
+
image: {
|
|
284
|
+
size: number;
|
|
285
|
+
sizes: {
|
|
286
|
+
bytes: number;
|
|
287
|
+
kb: number;
|
|
288
|
+
mb: number;
|
|
289
|
+
gb: number;
|
|
290
|
+
};
|
|
291
|
+
tempFilePath: string;
|
|
292
|
+
tempFileName: string;
|
|
293
|
+
mimetype: string;
|
|
294
|
+
extension: string;
|
|
295
|
+
name: string;
|
|
296
|
+
};
|
|
161
297
|
};
|
|
162
298
|
};
|
|
163
299
|
};
|
|
@@ -2,47 +2,67 @@
|
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
// AUTO GENERATED FILE
|
|
4
4
|
// DO NOT EDIT
|
|
5
|
+
// **Response values shown here are examples only.
|
|
6
|
+
// **The App is using the configuration:
|
|
7
|
+
// globalPrefix: 'api'
|
|
5
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
9
|
exports.appRoutes = void 0;
|
|
7
10
|
exports.appRoutes = {
|
|
8
11
|
"/cats": {
|
|
9
12
|
GET: {
|
|
10
|
-
params:
|
|
11
|
-
query: {
|
|
12
|
-
body:
|
|
13
|
-
files:
|
|
14
|
-
response: { "query
|
|
13
|
+
params: undefined,
|
|
14
|
+
query: { id: 123, name: "example" },
|
|
15
|
+
body: undefined,
|
|
16
|
+
files: undefined,
|
|
17
|
+
response: { message: "example", query: { id: 123, name: "example" }, cats: [{ id: 123, name: "example", age: 123 }] }
|
|
15
18
|
},
|
|
16
19
|
POST: {
|
|
17
|
-
params:
|
|
18
|
-
query:
|
|
19
|
-
body: {
|
|
20
|
-
files:
|
|
21
|
-
response: { "cat
|
|
20
|
+
params: undefined,
|
|
21
|
+
query: undefined,
|
|
22
|
+
body: { name: "example", age: 123 },
|
|
23
|
+
files: undefined,
|
|
24
|
+
response: { message: "example", cat: { name: "example", age: 123, id: 123 } }
|
|
22
25
|
}
|
|
23
26
|
},
|
|
24
27
|
"/cats/:id": {
|
|
25
28
|
GET: {
|
|
26
|
-
params: {
|
|
27
|
-
query:
|
|
28
|
-
body:
|
|
29
|
-
files:
|
|
30
|
-
response: { "cat
|
|
29
|
+
params: { id: 123 },
|
|
30
|
+
query: undefined,
|
|
31
|
+
body: undefined,
|
|
32
|
+
files: undefined,
|
|
33
|
+
response: { message: "example", cat: { id: 123, name: "example", age: 123 } }
|
|
31
34
|
},
|
|
32
35
|
PUT: {
|
|
33
|
-
params: {
|
|
34
|
-
query:
|
|
35
|
-
body: {
|
|
36
|
-
files:
|
|
37
|
-
response: { "
|
|
36
|
+
params: { id: 123 },
|
|
37
|
+
query: undefined,
|
|
38
|
+
body: { name: "example", age: 123 },
|
|
39
|
+
files: undefined,
|
|
40
|
+
response: { message: "example", cat: { id: 123, name: "example", age: 123 } }
|
|
41
|
+
},
|
|
42
|
+
PATCH: {
|
|
43
|
+
params: { id: 123 },
|
|
44
|
+
query: undefined,
|
|
45
|
+
body: { name: "example", age: 123 },
|
|
46
|
+
files: undefined,
|
|
47
|
+
response: { message: "example", cat: { id: 123, name: "example", age: 123 } }
|
|
38
48
|
},
|
|
39
49
|
DELETE: {
|
|
40
|
-
params: {
|
|
41
|
-
query:
|
|
42
|
-
body:
|
|
43
|
-
files:
|
|
44
|
-
response: {
|
|
50
|
+
params: { id: 123 },
|
|
51
|
+
query: undefined,
|
|
52
|
+
body: undefined,
|
|
53
|
+
files: undefined,
|
|
54
|
+
response: { message: "example", deleted: true }
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"/cats/upload": {
|
|
58
|
+
POST: {
|
|
59
|
+
params: undefined,
|
|
60
|
+
query: undefined,
|
|
61
|
+
body: undefined,
|
|
62
|
+
files: { image: [{ size: 123, sizes: { bytes: 123, kb: 123, mb: 123, gb: 123 }, tempFilePath: "example", tempFileName: "example", mimetype: "example", extension: "example", name: "example" }] },
|
|
63
|
+
response: { message: "example", image: { size: 123, sizes: { bytes: 123, kb: 123, mb: 123, gb: 123 }, tempFilePath: "example", tempFileName: "example", mimetype: "example", extension: "example", name: "example" } }
|
|
45
64
|
}
|
|
46
65
|
}
|
|
47
66
|
};
|
|
67
|
+
;
|
|
48
68
|
//# sourceMappingURL=pre-routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pre-routes.js","sourceRoot":"","sources":["../../../../src/lib/core/compiler/pre-routes.ts"],"names":[],"mappings":";AACA,cAAc;AACd,sBAAsB;AACtB,cAAc;;;
|
|
1
|
+
{"version":3,"file":"pre-routes.js","sourceRoot":"","sources":["../../../../src/lib/core/compiler/pre-routes.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { type T } from '../types';
|
|
2
|
+
type ClassConstructor<T = any> = new (...args: any[]) => T;
|
|
3
|
+
type ZodSchemaLike = {
|
|
4
|
+
parse: (input: unknown) => any;
|
|
5
|
+
parseAsync: (input: unknown) => Promise<any>;
|
|
6
|
+
safeParseAsync: (input: unknown) => Promise<{
|
|
7
|
+
success: boolean;
|
|
8
|
+
data?: any;
|
|
9
|
+
error?: any;
|
|
10
|
+
}>;
|
|
11
|
+
safeParse: (input: unknown) => {
|
|
12
|
+
success: boolean;
|
|
13
|
+
data?: any;
|
|
14
|
+
error?: any;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
type Target = "params" | "query" | "body" | "files";
|
|
2
18
|
export declare function createDtoDecorator(validator: (ctx: T.Context) => void | Promise<void>, onError?: (ctx: T.Context, error: any) => any): MethodDecorator;
|
|
3
19
|
export declare function createContextDecorator(hook: (ctx: T.Context, next: T.NextFunction, meta: {
|
|
4
20
|
target: any;
|
|
@@ -101,10 +117,9 @@ export declare const Cookies: (...keys: string[]) => MethodDecorator;
|
|
|
101
117
|
*
|
|
102
118
|
* @param keys - List of required field names.
|
|
103
119
|
* @param options - Validation options.
|
|
104
|
-
* @
|
|
105
|
-
* Defaults to `"body"`.
|
|
120
|
+
* @property options.target - Request source to validate. defaults to `"body"`.
|
|
106
121
|
*
|
|
107
|
-
* @
|
|
122
|
+
* @property options.required - Enables required-value validation.
|
|
108
123
|
*
|
|
109
124
|
* - `true`
|
|
110
125
|
* - Rejects `null`
|
|
@@ -113,11 +128,9 @@ export declare const Cookies: (...keys: string[]) => MethodDecorator;
|
|
|
113
128
|
* - `object`
|
|
114
129
|
* - Allows customizing required rules.
|
|
115
130
|
*
|
|
116
|
-
* @
|
|
117
|
-
* Default: `false`
|
|
131
|
+
* @property options.required.allowNull - Allow `null` values. Default: `false`
|
|
118
132
|
*
|
|
119
|
-
* @
|
|
120
|
-
* Default: `false`
|
|
133
|
+
* @property options.required.allowEmptyString - Allow empty string values. Default: `false`
|
|
121
134
|
* @returns {MethodDecorator}
|
|
122
135
|
*
|
|
123
136
|
* @throws {Object} Throws a validation error object when
|
|
@@ -139,9 +152,66 @@ export declare const Cookies: (...keys: string[]) => MethodDecorator;
|
|
|
139
152
|
* ```
|
|
140
153
|
*/
|
|
141
154
|
export declare const Validate: (keys: string[], { target, required }?: {
|
|
142
|
-
target?:
|
|
155
|
+
target?: Target;
|
|
143
156
|
required?: boolean | {
|
|
144
157
|
allowNull?: boolean;
|
|
145
158
|
allowEmptyString?: boolean;
|
|
146
159
|
};
|
|
147
160
|
}) => MethodDecorator;
|
|
161
|
+
/**
|
|
162
|
+
* Validate request using either
|
|
163
|
+
* `class-validator` or `zod`.
|
|
164
|
+
*
|
|
165
|
+
* Please install the required validation library before using this decorator.
|
|
166
|
+
* @install
|
|
167
|
+
* npm install class-validator class-transformer
|
|
168
|
+
*
|
|
169
|
+
* npm install zod
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* // class-validator (default)
|
|
173
|
+
* \@ValidateDto(UserDto)
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* // explicit class-validator
|
|
177
|
+
* \@ValidateDto(UserDto, {
|
|
178
|
+
* adaptor: "class-validator"
|
|
179
|
+
* })
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* // zod
|
|
183
|
+
* \@ValidateDto(UserSchema, {
|
|
184
|
+
* adaptor: "zod"
|
|
185
|
+
* })
|
|
186
|
+
*
|
|
187
|
+
* @param schema
|
|
188
|
+
* Validation schema/class.
|
|
189
|
+
*
|
|
190
|
+
* - `class-validator`:
|
|
191
|
+
* Must be a class constructor.
|
|
192
|
+
*
|
|
193
|
+
* - `zod`:
|
|
194
|
+
* Must be a schema containing `.safeParseAsync()`.
|
|
195
|
+
*
|
|
196
|
+
* @param {Object} options Validation options.
|
|
197
|
+
*
|
|
198
|
+
* @property options.adaptor Validation adaptor. default "class-validator"
|
|
199
|
+
* @property options.message Validation error message.
|
|
200
|
+
* @property options.status Validation error status code.
|
|
201
|
+
* @property options.target Request target to validate. default "body"
|
|
202
|
+
*
|
|
203
|
+
* @returns MethodDecorator
|
|
204
|
+
*/
|
|
205
|
+
export declare function ValidateDto(schema: ZodSchemaLike, options: {
|
|
206
|
+
adaptor: "zod";
|
|
207
|
+
message?: string;
|
|
208
|
+
status?: 400 | 422 | 500;
|
|
209
|
+
target?: Target;
|
|
210
|
+
}): MethodDecorator;
|
|
211
|
+
export declare function ValidateDto(schema: ClassConstructor, options?: {
|
|
212
|
+
adaptor: "class-validator";
|
|
213
|
+
message?: string;
|
|
214
|
+
status?: 400 | 422 | 500;
|
|
215
|
+
target?: Target;
|
|
216
|
+
}): MethodDecorator;
|
|
217
|
+
export {};
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Validate = exports.Cookies = exports.Query = exports.Params = exports.Files = exports.Body = void 0;
|
|
4
7
|
exports.createDtoDecorator = createDtoDecorator;
|
|
5
8
|
exports.createContextDecorator = createContextDecorator;
|
|
9
|
+
exports.ValidateDto = ValidateDto;
|
|
10
|
+
const package_1 = __importDefault(require("../package"));
|
|
11
|
+
class ValidateError extends Error {
|
|
12
|
+
issues;
|
|
13
|
+
status;
|
|
14
|
+
constructor(message, { issues = [], status = 400 } = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "ValidateError";
|
|
17
|
+
this.issues = issues;
|
|
18
|
+
this.status = status;
|
|
19
|
+
Object.setPrototypeOf(this, ValidateError.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
6
22
|
function createDtoDecorator(validator, onError) {
|
|
7
23
|
return (_target, _key, descriptor) => {
|
|
8
24
|
const original = descriptor.value;
|
|
@@ -17,7 +33,10 @@ function createDtoDecorator(validator, onError) {
|
|
|
17
33
|
}
|
|
18
34
|
let message = err?.message ?? "Bad Request";
|
|
19
35
|
let issues = err.issues ?? err.errors ?? [];
|
|
20
|
-
let status = 400;
|
|
36
|
+
let status = +(err.status ?? 400);
|
|
37
|
+
if (!Number.isInteger(status) || status < 100 || status > 599) {
|
|
38
|
+
status = 400;
|
|
39
|
+
}
|
|
21
40
|
if (err.name === "ZodError") {
|
|
22
41
|
const zodIssues = err.issues
|
|
23
42
|
.map((i) => ({
|
|
@@ -28,7 +47,9 @@ function createDtoDecorator(validator, onError) {
|
|
|
28
47
|
issues = zodIssues;
|
|
29
48
|
status = 422;
|
|
30
49
|
}
|
|
31
|
-
return ctx.res
|
|
50
|
+
return ctx.res
|
|
51
|
+
.status(status)
|
|
52
|
+
.json({
|
|
32
53
|
message,
|
|
33
54
|
issues,
|
|
34
55
|
});
|
|
@@ -183,10 +204,9 @@ exports.Cookies = Cookies;
|
|
|
183
204
|
*
|
|
184
205
|
* @param keys - List of required field names.
|
|
185
206
|
* @param options - Validation options.
|
|
186
|
-
* @
|
|
187
|
-
* Defaults to `"body"`.
|
|
207
|
+
* @property options.target - Request source to validate. defaults to `"body"`.
|
|
188
208
|
*
|
|
189
|
-
* @
|
|
209
|
+
* @property options.required - Enables required-value validation.
|
|
190
210
|
*
|
|
191
211
|
* - `true`
|
|
192
212
|
* - Rejects `null`
|
|
@@ -195,11 +215,9 @@ exports.Cookies = Cookies;
|
|
|
195
215
|
* - `object`
|
|
196
216
|
* - Allows customizing required rules.
|
|
197
217
|
*
|
|
198
|
-
* @
|
|
199
|
-
* Default: `false`
|
|
218
|
+
* @property options.required.allowNull - Allow `null` values. Default: `false`
|
|
200
219
|
*
|
|
201
|
-
* @
|
|
202
|
-
* Default: `false`
|
|
220
|
+
* @property options.required.allowEmptyString - Allow empty string values. Default: `false`
|
|
203
221
|
* @returns {MethodDecorator}
|
|
204
222
|
*
|
|
205
223
|
* @throws {Object} Throws a validation error object when
|
|
@@ -262,4 +280,61 @@ const Validate = (keys, { target, required } = {}) => {
|
|
|
262
280
|
});
|
|
263
281
|
};
|
|
264
282
|
exports.Validate = Validate;
|
|
283
|
+
function ValidateDto(schema, options) {
|
|
284
|
+
const status = options?.status ?? 422;
|
|
285
|
+
const message = options?.message ?? "Validation failed";
|
|
286
|
+
const adaptor = options?.adaptor ?? "class-validator";
|
|
287
|
+
const target = options?.target ?? "body";
|
|
288
|
+
return createDtoDecorator(async (ctx) => {
|
|
289
|
+
if (adaptor === "zod") {
|
|
290
|
+
const result = await schema.safeParseAsync(ctx[target]);
|
|
291
|
+
if (result.success) {
|
|
292
|
+
ctx[target] = result.data;
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const errors = result.error?.issues;
|
|
296
|
+
const issues = Object
|
|
297
|
+
.values(errors.reduce((acc, issue) => {
|
|
298
|
+
const key = issue.path.join(".");
|
|
299
|
+
if (!acc[key]) {
|
|
300
|
+
acc[key] = {
|
|
301
|
+
path: key,
|
|
302
|
+
constraints: {
|
|
303
|
+
[issue.code]: issue.message
|
|
304
|
+
},
|
|
305
|
+
message: issue.message
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
acc[key].constraints[issue.code] = issue.message;
|
|
310
|
+
acc[key].message += `, ${issue.message}`;
|
|
311
|
+
}
|
|
312
|
+
return acc;
|
|
313
|
+
}, {}));
|
|
314
|
+
throw new ValidateError(message, { issues, status });
|
|
315
|
+
}
|
|
316
|
+
if (adaptor === "class-validator") {
|
|
317
|
+
const dto = package_1.default
|
|
318
|
+
.classTransformer
|
|
319
|
+
.plainToInstance(schema, ctx[target]);
|
|
320
|
+
const errors = await package_1.default
|
|
321
|
+
.classValidator
|
|
322
|
+
.validate(dto);
|
|
323
|
+
if (!errors.length) {
|
|
324
|
+
ctx[target] = dto;
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
const issues = errors.flatMap((error) => {
|
|
328
|
+
const constraints = error.constraints ?? {};
|
|
329
|
+
return {
|
|
330
|
+
path: error.property,
|
|
331
|
+
constraints,
|
|
332
|
+
message: Object.values(constraints).join(","),
|
|
333
|
+
};
|
|
334
|
+
});
|
|
335
|
+
throw new ValidateError(message, { issues, status });
|
|
336
|
+
}
|
|
337
|
+
throw new Error("Invalid validation adaptor specified");
|
|
338
|
+
});
|
|
339
|
+
}
|
|
265
340
|
//# sourceMappingURL=context.js.map
|