exisjs 0.7.6 → 0.7.8
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/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +12 -0
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/clean.d.ts +5 -0
- package/dist/cli/commands/clean.d.ts.map +1 -0
- package/dist/cli/commands/clean.js +30 -0
- package/dist/cli/commands/clean.js.map +1 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +15 -1
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +6 -1
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +57 -2
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/index.js +16 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/manifest.d.ts +1 -0
- package/dist/cli/manifest.d.ts.map +1 -1
- package/dist/cli/manifest.js +161 -23
- package/dist/cli/manifest.js.map +1 -1
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +9 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/types.d.ts +4 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/cron/expressions.d.ts +45 -0
- package/dist/cron/expressions.d.ts.map +1 -0
- package/dist/cron/expressions.js +87 -0
- package/dist/cron/expressions.js.map +1 -0
- package/dist/cron/index.d.ts +6 -0
- package/dist/cron/index.d.ts.map +1 -0
- package/dist/cron/index.js +22 -0
- package/dist/cron/index.js.map +1 -0
- package/dist/cron/job.d.ts +50 -0
- package/dist/cron/job.d.ts.map +1 -0
- package/dist/cron/job.js +247 -0
- package/dist/cron/job.js.map +1 -0
- package/dist/cron/manager.d.ts +105 -0
- package/dist/cron/manager.d.ts.map +1 -0
- package/dist/cron/manager.js +245 -0
- package/dist/cron/manager.js.map +1 -0
- package/dist/cron/parser.d.ts +22 -0
- package/dist/cron/parser.d.ts.map +1 -0
- package/dist/cron/parser.js +269 -0
- package/dist/cron/parser.js.map +1 -0
- package/dist/cron/types.d.ts +76 -0
- package/dist/cron/types.d.ts.map +1 -0
- package/dist/cron/types.js +3 -0
- package/dist/cron/types.js.map +1 -0
- package/dist/decorators/constants.d.ts +2 -0
- package/dist/decorators/constants.d.ts.map +1 -1
- package/dist/decorators/constants.js +3 -1
- package/dist/decorators/constants.js.map +1 -1
- package/dist/decorators/core.d.ts +29 -11
- package/dist/decorators/core.d.ts.map +1 -1
- package/dist/decorators/core.js +49 -11
- package/dist/decorators/core.js.map +1 -1
- package/dist/decorators/cron.d.ts +57 -0
- package/dist/decorators/cron.d.ts.map +1 -0
- package/dist/decorators/cron.js +143 -0
- package/dist/decorators/cron.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +2 -0
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/params.d.ts +97 -2
- package/dist/decorators/params.d.ts.map +1 -1
- package/dist/decorators/params.js +94 -2
- package/dist/decorators/params.js.map +1 -1
- package/dist/decorators/routing.d.ts +81 -16
- package/dist/decorators/routing.d.ts.map +1 -1
- package/dist/decorators/routing.js +81 -16
- package/dist/decorators/routing.js.map +1 -1
- package/dist/docs/content/cron.mdx +196 -0
- package/dist/docs/content/errors.mdx +58 -9
- package/dist/docs/content/structure.mdx +1 -1
- package/dist/docs/content/swagger.mdx +289 -0
- package/dist/docs/reference/cron.mdx +300 -0
- package/dist/docs/reference/decorators.mdx +8 -0
- package/dist/docs/reference/error.mdx +44 -0
- package/dist/docs/reference/swagger.mdx +226 -0
- package/dist/docs/reference/validator.mdx +1 -1
- package/dist/router/boundary.d.ts +24 -2
- package/dist/router/boundary.d.ts.map +1 -1
- package/dist/router/boundary.js +24 -2
- package/dist/router/boundary.js.map +1 -1
- package/dist/router/controller-registrar.d.ts.map +1 -1
- package/dist/router/controller-registrar.js +52 -3
- package/dist/router/controller-registrar.js.map +1 -1
- package/dist/router/route-builder.d.ts +196 -33
- package/dist/router/route-builder.d.ts.map +1 -1
- package/dist/router/route-builder.js +171 -11
- package/dist/router/route-builder.js.map +1 -1
- package/dist/router/route-scanner.d.ts +6 -0
- package/dist/router/route-scanner.d.ts.map +1 -1
- package/dist/router/route-scanner.js +69 -812
- package/dist/router/route-scanner.js.map +1 -1
- package/dist/router/router.d.ts.map +1 -1
- package/dist/router/router.js +27 -0
- package/dist/router/router.js.map +1 -1
- package/dist/router/scanner/boundary-loader.d.ts +18 -0
- package/dist/router/scanner/boundary-loader.d.ts.map +1 -0
- package/dist/router/scanner/boundary-loader.js +539 -0
- package/dist/router/scanner/boundary-loader.js.map +1 -0
- package/dist/router/scanner/cron-mounter.d.ts +15 -0
- package/dist/router/scanner/cron-mounter.d.ts.map +1 -0
- package/dist/router/scanner/cron-mounter.js +216 -0
- package/dist/router/scanner/cron-mounter.js.map +1 -0
- package/dist/router/scanner/error-mounter.d.ts +14 -0
- package/dist/router/scanner/error-mounter.d.ts.map +1 -0
- package/dist/router/scanner/error-mounter.js +200 -0
- package/dist/router/scanner/error-mounter.js.map +1 -0
- package/dist/router/scanner/fs-scanner.d.ts +25 -0
- package/dist/router/scanner/fs-scanner.d.ts.map +1 -0
- package/dist/router/scanner/fs-scanner.js +115 -0
- package/dist/router/scanner/fs-scanner.js.map +1 -0
- package/dist/router/scanner/functional-compiler.d.ts +9 -0
- package/dist/router/scanner/functional-compiler.d.ts.map +1 -0
- package/dist/router/scanner/functional-compiler.js +233 -0
- package/dist/router/scanner/functional-compiler.js.map +1 -0
- package/dist/router/scanner/index.d.ts +9 -0
- package/dist/router/scanner/index.d.ts.map +1 -0
- package/dist/router/scanner/index.js +19 -0
- package/dist/router/scanner/index.js.map +1 -0
- package/dist/router/types.d.ts +15 -0
- package/dist/router/types.d.ts.map +1 -1
- package/dist/server/app.d.ts +2 -0
- package/dist/server/app.d.ts.map +1 -1
- package/dist/server/app.js +3 -0
- package/dist/server/app.js.map +1 -1
- package/dist/server/helpers/body-parser.d.ts +18 -0
- package/dist/server/helpers/body-parser.d.ts.map +1 -0
- package/dist/server/helpers/body-parser.js +246 -0
- package/dist/server/helpers/body-parser.js.map +1 -0
- package/dist/server/helpers/cookie.d.ts +4 -0
- package/dist/server/helpers/cookie.d.ts.map +1 -0
- package/dist/server/helpers/cookie.js +61 -0
- package/dist/server/helpers/cookie.js.map +1 -0
- package/dist/server/helpers/etag.d.ts +3 -0
- package/dist/server/helpers/etag.d.ts.map +1 -0
- package/dist/server/helpers/etag.js +25 -0
- package/dist/server/helpers/etag.js.map +1 -0
- package/dist/server/helpers/index.d.ts +6 -0
- package/dist/server/helpers/index.d.ts.map +1 -0
- package/dist/server/helpers/index.js +21 -0
- package/dist/server/helpers/index.js.map +1 -0
- package/dist/server/helpers/ip.d.ts +9 -0
- package/dist/server/helpers/ip.d.ts.map +1 -0
- package/dist/server/helpers/ip.js +62 -0
- package/dist/server/helpers/ip.js.map +1 -0
- package/dist/server/helpers/stream.d.ts +4 -0
- package/dist/server/helpers/stream.d.ts.map +1 -0
- package/dist/server/helpers/stream.js +193 -0
- package/dist/server/helpers/stream.js.map +1 -0
- package/dist/server/request.d.ts +1 -139
- package/dist/server/request.d.ts.map +1 -1
- package/dist/server/request.js +19 -433
- package/dist/server/request.js.map +1 -1
- package/dist/server/response.d.ts +105 -158
- package/dist/server/response.d.ts.map +1 -1
- package/dist/server/response.js +121 -423
- package/dist/server/response.js.map +1 -1
- package/dist/swagger/decorators.d.ts +81 -0
- package/dist/swagger/decorators.d.ts.map +1 -0
- package/dist/swagger/decorators.js +172 -0
- package/dist/swagger/decorators.js.map +1 -0
- package/dist/swagger/generator.d.ts +19 -0
- package/dist/swagger/generator.d.ts.map +1 -0
- package/dist/swagger/generator.js +344 -0
- package/dist/swagger/generator.js.map +1 -0
- package/dist/swagger/index.d.ts +31 -0
- package/dist/swagger/index.d.ts.map +1 -0
- package/dist/swagger/index.js +53 -0
- package/dist/swagger/index.js.map +1 -0
- package/dist/swagger/mounter.d.ts +7 -0
- package/dist/swagger/mounter.d.ts.map +1 -0
- package/dist/swagger/mounter.js +56 -0
- package/dist/swagger/mounter.js.map +1 -0
- package/dist/swagger/types.d.ts +190 -0
- package/dist/swagger/types.d.ts.map +1 -0
- package/dist/swagger/types.js +3 -0
- package/dist/swagger/types.js.map +1 -0
- package/dist/swagger/ui.d.ts +6 -0
- package/dist/swagger/ui.d.ts.map +1 -0
- package/dist/swagger/ui.js +118 -0
- package/dist/swagger/ui.js.map +1 -0
- package/dist/validator/builder.d.ts +223 -0
- package/dist/validator/builder.d.ts.map +1 -0
- package/dist/validator/builder.js +517 -0
- package/dist/validator/builder.js.map +1 -0
- package/dist/validator/engine.d.ts +19 -0
- package/dist/validator/engine.d.ts.map +1 -0
- package/dist/validator/engine.js +568 -0
- package/dist/validator/engine.js.map +1 -0
- package/dist/validator/error.d.ts +12 -0
- package/dist/validator/error.d.ts.map +1 -0
- package/dist/validator/error.js +63 -0
- package/dist/validator/error.js.map +1 -0
- package/dist/validator/pagination.d.ts +40 -0
- package/dist/validator/pagination.d.ts.map +1 -0
- package/dist/validator/pagination.js +60 -0
- package/dist/validator/pagination.js.map +1 -0
- package/dist/validator/tex.d.ts +6 -158
- package/dist/validator/tex.d.ts.map +1 -1
- package/dist/validator/tex.js +14 -971
- package/dist/validator/tex.js.map +1 -1
- package/dist/validator/types.d.ts +83 -0
- package/dist/validator/types.d.ts.map +1 -0
- package/dist/validator/types.js +3 -0
- package/dist/validator/types.js.map +1 -0
- package/package.json +9 -1
package/dist/validator/tex.js
CHANGED
|
@@ -1,974 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (opts?.min !== undefined)
|
|
18
|
-
base += ` | min:${opts.min}`;
|
|
19
|
-
if (opts?.max !== undefined)
|
|
20
|
-
base += ` | max:${opts.max}`;
|
|
21
|
-
if (opts?.trim)
|
|
22
|
-
base += ' | trim';
|
|
23
|
-
if (opts?.collapseWhitespace)
|
|
24
|
-
base += ' | collapseWhitespace';
|
|
25
|
-
if (opts?.toLowerCase)
|
|
26
|
-
base += ' | lowercase';
|
|
27
|
-
if (opts?.toUpperCase)
|
|
28
|
-
base += ' | uppercase';
|
|
29
|
-
if (opts?.escapeHtml)
|
|
30
|
-
base += ' | escapeHtml';
|
|
31
|
-
if (opts?.stripHtml)
|
|
32
|
-
base += ' | stripHtml';
|
|
33
|
-
if (opts?.slugify)
|
|
34
|
-
base += ' | slugify';
|
|
35
|
-
if (opts?.mask)
|
|
36
|
-
base += ' | mask';
|
|
37
|
-
if (opts?.preventSql)
|
|
38
|
-
base += ' | preventSql';
|
|
39
|
-
if (opts?.preventTraversal)
|
|
40
|
-
base += ' | preventTraversal';
|
|
41
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
42
|
-
}
|
|
43
|
-
number(opts) {
|
|
44
|
-
let base = 'number';
|
|
45
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
46
|
-
base += '?';
|
|
47
|
-
if (opts?.nullable)
|
|
48
|
-
base += ' | nullable';
|
|
49
|
-
if (opts?.nullish)
|
|
50
|
-
base += ' | nullish';
|
|
51
|
-
if (opts?.coerce)
|
|
52
|
-
base += ' | coerce';
|
|
53
|
-
if (opts?.min !== undefined)
|
|
54
|
-
base += ` | min:${opts.min}`;
|
|
55
|
-
if (opts?.max !== undefined)
|
|
56
|
-
base += ` | max:${opts.max}`;
|
|
57
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
58
|
-
}
|
|
59
|
-
boolean(opts) {
|
|
60
|
-
let base = 'boolean';
|
|
61
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
62
|
-
base += '?';
|
|
63
|
-
if (opts?.nullable)
|
|
64
|
-
base += ' | nullable';
|
|
65
|
-
if (opts?.nullish)
|
|
66
|
-
base += ' | nullish';
|
|
67
|
-
if (opts?.coerce)
|
|
68
|
-
base += ' | coerce';
|
|
69
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
70
|
-
}
|
|
71
|
-
email(opts) {
|
|
72
|
-
let base = 'email';
|
|
73
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
74
|
-
base += '?';
|
|
75
|
-
if (opts?.nullable)
|
|
76
|
-
base += ' | nullable';
|
|
77
|
-
if (opts?.nullish)
|
|
78
|
-
base += ' | nullish';
|
|
79
|
-
if (opts?.trim)
|
|
80
|
-
base += ' | trim';
|
|
81
|
-
if (opts?.toLowerCase)
|
|
82
|
-
base += ' | lowercase';
|
|
83
|
-
if (opts?.mask)
|
|
84
|
-
base += ' | mask';
|
|
85
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
86
|
-
}
|
|
87
|
-
uuid(opts) {
|
|
88
|
-
let base = 'uuid';
|
|
89
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
90
|
-
base += '?';
|
|
91
|
-
if (opts?.nullable)
|
|
92
|
-
base += ' | nullable';
|
|
93
|
-
if (opts?.nullish)
|
|
94
|
-
base += ' | nullish';
|
|
95
|
-
if (opts?.version)
|
|
96
|
-
base += ` | version:${opts.version}`;
|
|
97
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
98
|
-
}
|
|
99
|
-
cuid(opts) {
|
|
100
|
-
let base = 'cuid';
|
|
101
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
102
|
-
base += '?';
|
|
103
|
-
if (opts?.nullable)
|
|
104
|
-
base += ' | nullable';
|
|
105
|
-
if (opts?.nullish)
|
|
106
|
-
base += ' | nullish';
|
|
107
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
108
|
-
}
|
|
109
|
-
creditCard(opts) {
|
|
110
|
-
let base = 'creditcard';
|
|
111
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
112
|
-
base += '?';
|
|
113
|
-
if (opts?.nullable)
|
|
114
|
-
base += ' | nullable';
|
|
115
|
-
if (opts?.nullish)
|
|
116
|
-
base += ' | nullish';
|
|
117
|
-
if (opts?.mask)
|
|
118
|
-
base += ' | mask';
|
|
119
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
120
|
-
}
|
|
121
|
-
password(opts) {
|
|
122
|
-
let base = 'password';
|
|
123
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
124
|
-
base += '?';
|
|
125
|
-
if (opts?.nullable)
|
|
126
|
-
base += ' | nullable';
|
|
127
|
-
if (opts?.nullish)
|
|
128
|
-
base += ' | nullish';
|
|
129
|
-
if (opts?.min !== undefined)
|
|
130
|
-
base += ` | min:${opts.min}`;
|
|
131
|
-
if (opts?.max !== undefined)
|
|
132
|
-
base += ` | max:${opts.max}`;
|
|
133
|
-
if (opts?.requireNumbers)
|
|
134
|
-
base += ' | requireNumbers';
|
|
135
|
-
if (opts?.requireSymbols)
|
|
136
|
-
base += ' | requireSymbols';
|
|
137
|
-
if (opts?.requireUppercase)
|
|
138
|
-
base += ' | requireUppercase';
|
|
139
|
-
if (opts?.requireLowercase)
|
|
140
|
-
base += ' | requireLowercase';
|
|
141
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
142
|
-
}
|
|
143
|
-
array(schema, opts) {
|
|
144
|
-
let resolvedItem = schema;
|
|
145
|
-
if (typeof schema === 'object' &&
|
|
146
|
-
schema !== null &&
|
|
147
|
-
!(schema instanceof tex_types_1.TexType) &&
|
|
148
|
-
!(schema instanceof TexEngine)) {
|
|
149
|
-
resolvedItem = this.object(schema);
|
|
150
|
-
}
|
|
151
|
-
const itemSchema = resolvedItem instanceof TexEngine
|
|
152
|
-
? `object<${JSON.stringify(resolvedItem.getCompiledSchema())}>`
|
|
153
|
-
: resolvedItem instanceof tex_types_1.TexType
|
|
154
|
-
? resolvedItem._raw
|
|
155
|
-
: resolvedItem;
|
|
156
|
-
let base = `array<${itemSchema}>`;
|
|
157
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
158
|
-
base += '?';
|
|
159
|
-
if (opts?.nullable)
|
|
160
|
-
base += ' | nullable';
|
|
161
|
-
if (opts?.nullish)
|
|
162
|
-
base += ' | nullish';
|
|
163
|
-
if (opts?.min !== undefined)
|
|
164
|
-
base += ` | min:${opts.min}`;
|
|
165
|
-
if (opts?.max !== undefined)
|
|
166
|
-
base += ` | max:${opts.max}`;
|
|
167
|
-
if (opts?.dedupe)
|
|
168
|
-
base += ' | dedupe';
|
|
169
|
-
if (opts?.coerce)
|
|
170
|
-
base += ' | coerce';
|
|
171
|
-
const res = new tex_types_1.TexType(base, opts?.default);
|
|
172
|
-
res._item = resolvedItem;
|
|
173
|
-
return res;
|
|
174
|
-
}
|
|
175
|
-
enum(values, opts) {
|
|
176
|
-
let base = `enum:${values.join(',')}`;
|
|
177
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
178
|
-
base += '?';
|
|
179
|
-
if (opts?.nullable)
|
|
180
|
-
base += ' | nullable';
|
|
181
|
-
if (opts?.nullish)
|
|
182
|
-
base += ' | nullish';
|
|
183
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
184
|
-
}
|
|
185
|
-
literal(value, opts) {
|
|
186
|
-
let base = `literal:${value}`;
|
|
187
|
-
if (opts?.optional)
|
|
188
|
-
base += '?';
|
|
189
|
-
if (opts?.nullable)
|
|
190
|
-
base += ' | nullable';
|
|
191
|
-
if (opts?.nullish)
|
|
192
|
-
base += ' | nullish';
|
|
193
|
-
return new tex_types_1.TexType(base);
|
|
194
|
-
}
|
|
195
|
-
union(schemas, opts) {
|
|
196
|
-
const items = schemas.map((s) => (s instanceof tex_types_1.TexType ? s._raw : s));
|
|
197
|
-
let base = items.join(' || ');
|
|
198
|
-
if (opts?.optional)
|
|
199
|
-
base = `(${base})?`;
|
|
200
|
-
if (opts?.nullable)
|
|
201
|
-
base += ' | nullable';
|
|
202
|
-
if (opts?.nullish)
|
|
203
|
-
base += ' | nullish';
|
|
204
|
-
return new tex_types_1.TexType(base);
|
|
205
|
-
}
|
|
206
|
-
date(opts) {
|
|
207
|
-
let base = 'date';
|
|
208
|
-
if (opts?.optional || opts?.default !== undefined)
|
|
209
|
-
base += '?';
|
|
210
|
-
if (opts?.nullable)
|
|
211
|
-
base += ' | nullable';
|
|
212
|
-
if (opts?.nullish)
|
|
213
|
-
base += ' | nullish';
|
|
214
|
-
if (opts?.coerce)
|
|
215
|
-
base += ' | coerce';
|
|
216
|
-
if (opts?.minDate)
|
|
217
|
-
base += ` | minDate:${opts.minDate}`;
|
|
218
|
-
if (opts?.maxDate)
|
|
219
|
-
base += ` | maxDate:${opts.maxDate}`;
|
|
220
|
-
return new tex_types_1.TexType(base, opts?.default);
|
|
221
|
-
}
|
|
222
|
-
record(schema, opts) {
|
|
223
|
-
const itemSchema = schema instanceof tex_types_1.TexType ? schema._raw : schema;
|
|
224
|
-
let base = `record<${itemSchema}>`;
|
|
225
|
-
if (opts?.optional)
|
|
226
|
-
base += '?';
|
|
227
|
-
if (opts?.nullable)
|
|
228
|
-
base += ' | nullable';
|
|
229
|
-
if (opts?.nullish)
|
|
230
|
-
base += ' | nullish';
|
|
231
|
-
return new tex_types_1.TexType(base);
|
|
232
|
-
}
|
|
233
|
-
any(opts) {
|
|
234
|
-
let base = 'any';
|
|
235
|
-
if (opts?.optional)
|
|
236
|
-
base += '?';
|
|
237
|
-
if (opts?.nullable)
|
|
238
|
-
base += ' | nullable';
|
|
239
|
-
if (opts?.nullish)
|
|
240
|
-
base += ' | nullish';
|
|
241
|
-
return new tex_types_1.TexType(base);
|
|
242
|
-
}
|
|
243
|
-
file(opts) {
|
|
244
|
-
let base = 'file';
|
|
245
|
-
if (opts?.optional)
|
|
246
|
-
base += '?';
|
|
247
|
-
if (opts?.nullable)
|
|
248
|
-
base += ' | nullable';
|
|
249
|
-
if (opts?.nullish)
|
|
250
|
-
base += ' | nullish';
|
|
251
|
-
if (opts?.maxSize)
|
|
252
|
-
base += ` | maxSize:${opts.maxSize}`;
|
|
253
|
-
if (opts?.mimeTypes)
|
|
254
|
-
base += ` | mimeTypes:${opts.mimeTypes.join(',')}`;
|
|
255
|
-
return new tex_types_1.TexType(base);
|
|
256
|
-
}
|
|
257
|
-
object(schema, opts) {
|
|
258
|
-
const compiledSchema = {};
|
|
259
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
260
|
-
if (value instanceof TexEngine) {
|
|
261
|
-
compiledSchema[key] =
|
|
262
|
-
`object<${JSON.stringify(value.getCompiledSchema())}>`;
|
|
263
|
-
}
|
|
264
|
-
else if (value instanceof tex_types_1.TexType) {
|
|
265
|
-
compiledSchema[key] = value._raw;
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
compiledSchema[key] = value;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return new TexEngine(compiledSchema, schema, opts?.strict);
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Dedicated Environment Schema parser (tex.env).
|
|
275
|
-
* Automatically coerces numbers, booleans, dates, and arrays from process.env string values,
|
|
276
|
-
* while preserving strict type validation and defaults.
|
|
277
|
-
*/
|
|
278
|
-
env(schema, opts) {
|
|
279
|
-
const coercedSchema = {};
|
|
280
|
-
for (const [key, value] of Object.entries(schema)) {
|
|
281
|
-
if (value instanceof tex_types_1.TexType) {
|
|
282
|
-
let raw = value._raw;
|
|
283
|
-
// Auto-inject coercion if not already present
|
|
284
|
-
if ((raw.startsWith('number') ||
|
|
285
|
-
raw.startsWith('boolean') ||
|
|
286
|
-
raw.startsWith('date') ||
|
|
287
|
-
raw.startsWith('array<')) &&
|
|
288
|
-
!raw.includes('coerce')) {
|
|
289
|
-
raw = `${raw} | coerce`;
|
|
290
|
-
}
|
|
291
|
-
const cloned = new tex_types_1.TexType(raw, value.defaultValue);
|
|
292
|
-
cloned.sanitizers = [...value.sanitizers];
|
|
293
|
-
cloned.refinements = [...value.refinements];
|
|
294
|
-
if (value._item) {
|
|
295
|
-
;
|
|
296
|
-
cloned._item = value._item;
|
|
297
|
-
}
|
|
298
|
-
coercedSchema[key] = cloned;
|
|
299
|
-
}
|
|
300
|
-
else if (value instanceof TexEngine) {
|
|
301
|
-
coercedSchema[key] = value;
|
|
302
|
-
}
|
|
303
|
-
else if (typeof value === 'string') {
|
|
304
|
-
let raw = value;
|
|
305
|
-
if ((raw.startsWith('number') ||
|
|
306
|
-
raw.startsWith('boolean') ||
|
|
307
|
-
raw.startsWith('date') ||
|
|
308
|
-
raw.startsWith('array<')) &&
|
|
309
|
-
!raw.includes('coerce')) {
|
|
310
|
-
raw = `${raw} | coerce`;
|
|
311
|
-
}
|
|
312
|
-
coercedSchema[key] = new tex_types_1.TexType(raw);
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
coercedSchema[key] = value;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return this.object(coercedSchema, opts);
|
|
319
|
-
}
|
|
320
|
-
pagination(options) {
|
|
321
|
-
const defaultLimit = options?.defaultLimit ?? 10;
|
|
322
|
-
const maxLimit = options?.maxLimit ?? 100;
|
|
323
|
-
return this.object({
|
|
324
|
-
page: this.number({ optional: true, coerce: true, min: 1, default: 1 }),
|
|
325
|
-
limit: this.number({
|
|
326
|
-
optional: true,
|
|
327
|
-
coerce: true,
|
|
328
|
-
min: 1,
|
|
329
|
-
max: maxLimit,
|
|
330
|
-
default: defaultLimit,
|
|
331
|
-
}),
|
|
332
|
-
sort: this.string({ optional: true, trim: true }),
|
|
333
|
-
order: this.enum(['asc', 'desc'], { optional: true }),
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
exports.TexBuilder = TexBuilder;
|
|
338
|
-
function getNestedValue(obj, path) {
|
|
339
|
-
if (!obj || typeof obj !== 'object' || !path)
|
|
340
|
-
return undefined;
|
|
341
|
-
if (path in obj)
|
|
342
|
-
return obj[path];
|
|
343
|
-
try {
|
|
344
|
-
const keys = path.replace(/\[(\w+)\]/g, '.$1').split('.');
|
|
345
|
-
let curr = obj;
|
|
346
|
-
for (const k of keys) {
|
|
347
|
-
if (curr === undefined || curr === null)
|
|
348
|
-
return undefined;
|
|
349
|
-
curr = curr[k];
|
|
350
|
-
}
|
|
351
|
-
return curr;
|
|
352
|
-
}
|
|
353
|
-
catch {
|
|
354
|
-
return undefined;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
function formatReceivedValue(val) {
|
|
358
|
-
if (val === undefined)
|
|
359
|
-
return 'undefined';
|
|
360
|
-
if (val === null)
|
|
361
|
-
return 'null';
|
|
362
|
-
if (typeof val === 'string')
|
|
363
|
-
return JSON.stringify(val);
|
|
364
|
-
if (typeof val === 'number' || typeof val === 'boolean')
|
|
365
|
-
return String(val);
|
|
366
|
-
if (Array.isArray(val)) {
|
|
367
|
-
try {
|
|
368
|
-
const str = JSON.stringify(val);
|
|
369
|
-
return str.length > 30 ? `Array(${val.length})` : str;
|
|
370
|
-
}
|
|
371
|
-
catch {
|
|
372
|
-
return `Array(${val.length})`;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
if (typeof val === 'object') {
|
|
376
|
-
try {
|
|
377
|
-
const str = JSON.stringify(val);
|
|
378
|
-
return str.length > 30 ? '[object Object]' : str;
|
|
379
|
-
}
|
|
380
|
-
catch {
|
|
381
|
-
return '[object Object]';
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return String(val);
|
|
385
|
-
}
|
|
386
|
-
class ValidatorError extends Error {
|
|
387
|
-
constructor(errors) {
|
|
388
|
-
super('Validation Error: ' +
|
|
389
|
-
errors.map((e) => `${e.path}: ${e.message}`).join(', '));
|
|
390
|
-
this.name = 'ValidatorError';
|
|
391
|
-
this.errors = errors;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
exports.ValidatorError = ValidatorError;
|
|
395
|
-
class TexEngine {
|
|
396
|
-
constructor(schema, rawSchema, strict = false, isOptional = false) {
|
|
397
|
-
this._isOptional = false;
|
|
398
|
-
this.schema = schema;
|
|
399
|
-
this.rawSchema = rawSchema;
|
|
400
|
-
this.strict = strict;
|
|
401
|
-
this._isOptional = isOptional;
|
|
402
|
-
this.validator = new rs_1.TexValidator(schema, strict);
|
|
403
|
-
}
|
|
404
|
-
getCompiledSchema() {
|
|
405
|
-
return this.schema;
|
|
406
|
-
}
|
|
407
|
-
optional() {
|
|
408
|
-
return new TexEngine(this.schema, this.rawSchema, this.strict, true);
|
|
409
|
-
}
|
|
410
|
-
partial() {
|
|
411
|
-
const newSchema = {};
|
|
412
|
-
const newRaw = {};
|
|
413
|
-
for (const [key, val] of Object.entries(this.schema)) {
|
|
414
|
-
newSchema[key] = val.includes('?') ? val : `${val}?`;
|
|
415
|
-
const rawVal = this.rawSchema[key];
|
|
416
|
-
if (rawVal instanceof tex_types_1.TexType) {
|
|
417
|
-
newRaw[key] = new tex_types_1.TexType(newSchema[key]);
|
|
418
|
-
newRaw[key].sanitizers = rawVal.sanitizers;
|
|
419
|
-
newRaw[key].refinements = rawVal.refinements;
|
|
420
|
-
}
|
|
421
|
-
else if (rawVal instanceof TexEngine) {
|
|
422
|
-
newRaw[key] = rawVal.optional();
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
newRaw[key] = newSchema[key];
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
return new TexEngine(newSchema, newRaw, this.strict, this._isOptional);
|
|
429
|
-
}
|
|
430
|
-
pick(keys) {
|
|
431
|
-
const newSchema = {};
|
|
432
|
-
const newRaw = {};
|
|
433
|
-
for (const key of keys) {
|
|
434
|
-
if (this.schema[key]) {
|
|
435
|
-
newSchema[key] = this.schema[key];
|
|
436
|
-
newRaw[key] = this.rawSchema[key];
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
return new TexEngine(newSchema, newRaw, this.strict, this._isOptional);
|
|
440
|
-
}
|
|
441
|
-
omit(keys) {
|
|
442
|
-
const newSchema = {};
|
|
443
|
-
const newRaw = {};
|
|
444
|
-
for (const [key, val] of Object.entries(this.schema)) {
|
|
445
|
-
if (!keys.includes(key)) {
|
|
446
|
-
newSchema[key] = val;
|
|
447
|
-
newRaw[key] = this.rawSchema[key];
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
return new TexEngine(newSchema, newRaw, this.strict, this._isOptional);
|
|
451
|
-
}
|
|
452
|
-
parse(data) {
|
|
453
|
-
// 1. Apply defaults and run pre-validation sanitizers on the raw payload (if it's an object)
|
|
454
|
-
if (data && typeof data === 'object') {
|
|
455
|
-
for (const [key, val] of Object.entries(this.rawSchema)) {
|
|
456
|
-
// Apply default value / lazy factory function if field is omitted or undefined
|
|
457
|
-
if (data[key] === undefined) {
|
|
458
|
-
if (val instanceof tex_types_1.TexType && val.defaultValue !== undefined) {
|
|
459
|
-
data[key] =
|
|
460
|
-
typeof val.defaultValue === 'function'
|
|
461
|
-
? val.defaultValue()
|
|
462
|
-
: val.defaultValue;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
if (typeof data[key] === 'string' && data[key].trim() === '') {
|
|
466
|
-
const raw = val instanceof tex_types_1.TexType ? val._raw : String(val);
|
|
467
|
-
if (raw.includes('optional') ||
|
|
468
|
-
raw.includes('nullable') ||
|
|
469
|
-
raw.includes('nullish') ||
|
|
470
|
-
raw.includes('?') ||
|
|
471
|
-
val?._isOptional) {
|
|
472
|
-
if (raw.includes('nullable') &&
|
|
473
|
-
!raw.includes('optional') &&
|
|
474
|
-
!raw.includes('nullish')) {
|
|
475
|
-
data[key] = null;
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
delete data[key];
|
|
479
|
-
// If deleted but default is defined, apply default
|
|
480
|
-
if (val instanceof tex_types_1.TexType && val.defaultValue !== undefined) {
|
|
481
|
-
data[key] =
|
|
482
|
-
typeof val.defaultValue === 'function'
|
|
483
|
-
? val.defaultValue()
|
|
484
|
-
: val.defaultValue;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (data[key] !== undefined && data[key] !== null) {
|
|
490
|
-
if (val instanceof tex_types_1.TexType && val._raw.startsWith('date')) {
|
|
491
|
-
if (val._raw.includes('coerce')) {
|
|
492
|
-
if (typeof data[key] === 'string' ||
|
|
493
|
-
typeof data[key] === 'number') {
|
|
494
|
-
const d = new Date(data[key]);
|
|
495
|
-
if (isNaN(d.getTime())) {
|
|
496
|
-
throw new ValidatorError([
|
|
497
|
-
{
|
|
498
|
-
path: key,
|
|
499
|
-
message: 'Must be a valid date',
|
|
500
|
-
expected: 'valid date string or timestamp',
|
|
501
|
-
received: formatReceivedValue(data[key]),
|
|
502
|
-
code: 'INVALID_DATE',
|
|
503
|
-
},
|
|
504
|
-
]);
|
|
505
|
-
}
|
|
506
|
-
data[key] = d;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
if (!(data[key] instanceof Date) &&
|
|
510
|
-
typeof data[key] !== 'string' &&
|
|
511
|
-
typeof data[key] !== 'number') {
|
|
512
|
-
throw new ValidatorError([
|
|
513
|
-
{
|
|
514
|
-
path: key,
|
|
515
|
-
message: 'Must be a valid date',
|
|
516
|
-
expected: 'valid date or date string',
|
|
517
|
-
received: formatReceivedValue(data[key]),
|
|
518
|
-
code: 'INVALID_TYPE',
|
|
519
|
-
},
|
|
520
|
-
]);
|
|
521
|
-
}
|
|
522
|
-
if (data[key] instanceof Date && isNaN(data[key].getTime())) {
|
|
523
|
-
throw new ValidatorError([
|
|
524
|
-
{
|
|
525
|
-
path: key,
|
|
526
|
-
message: 'Must be a valid date',
|
|
527
|
-
expected: 'valid date string or timestamp',
|
|
528
|
-
received: formatReceivedValue(data[key]),
|
|
529
|
-
code: 'INVALID_DATE',
|
|
530
|
-
},
|
|
531
|
-
]);
|
|
532
|
-
}
|
|
533
|
-
if (val._raw.includes('minDate:')) {
|
|
534
|
-
const minStr = val._raw.match(/minDate:([^\s|]+)/)?.[1];
|
|
535
|
-
if (minStr &&
|
|
536
|
-
new Date(data[key]).getTime() < new Date(minStr).getTime()) {
|
|
537
|
-
throw new ValidatorError([
|
|
538
|
-
{
|
|
539
|
-
path: key,
|
|
540
|
-
message: `Date must be after ${minStr}`,
|
|
541
|
-
expected: `>= ${minStr}`,
|
|
542
|
-
received: formatReceivedValue(data[key]),
|
|
543
|
-
code: 'DATE_TOO_EARLY',
|
|
544
|
-
},
|
|
545
|
-
]);
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
if (val._raw.includes('maxDate:')) {
|
|
549
|
-
const maxStr = val._raw.match(/maxDate:([^\s|]+)/)?.[1];
|
|
550
|
-
if (maxStr &&
|
|
551
|
-
new Date(data[key]).getTime() > new Date(maxStr).getTime()) {
|
|
552
|
-
throw new ValidatorError([
|
|
553
|
-
{
|
|
554
|
-
path: key,
|
|
555
|
-
message: `Date must be before ${maxStr}`,
|
|
556
|
-
expected: `<= ${maxStr}`,
|
|
557
|
-
received: formatReceivedValue(data[key]),
|
|
558
|
-
code: 'DATE_TOO_LATE',
|
|
559
|
-
},
|
|
560
|
-
]);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
if (val instanceof tex_types_1.TexType &&
|
|
565
|
-
val._raw.startsWith('array<') &&
|
|
566
|
-
val._raw.includes('coerce')) {
|
|
567
|
-
if (!Array.isArray(data[key])) {
|
|
568
|
-
if (typeof data[key] === 'string') {
|
|
569
|
-
const parts = data[key].includes(',')
|
|
570
|
-
? data[key].split(',').map((s) => s.trim())
|
|
571
|
-
: [data[key]];
|
|
572
|
-
if (val._raw.startsWith('array<number')) {
|
|
573
|
-
data[key] = parts.map((p) => {
|
|
574
|
-
const n = Number(p);
|
|
575
|
-
return isNaN(n) ? p : n;
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
else if (val._raw.startsWith('array<boolean')) {
|
|
579
|
-
data[key] = parts.map((p) => {
|
|
580
|
-
if (p.toLowerCase() === 'true')
|
|
581
|
-
return true;
|
|
582
|
-
if (p.toLowerCase() === 'false')
|
|
583
|
-
return false;
|
|
584
|
-
return p;
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
588
|
-
data[key] = parts;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
data[key] = [data[key]];
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
else {
|
|
596
|
-
if (val._raw.startsWith('array<number')) {
|
|
597
|
-
data[key] = data[key].map((item) => {
|
|
598
|
-
if (typeof item === 'string') {
|
|
599
|
-
const n = Number(item);
|
|
600
|
-
return isNaN(n) ? item : n;
|
|
601
|
-
}
|
|
602
|
-
return item;
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
else if (val._raw.startsWith('array<boolean')) {
|
|
606
|
-
data[key] = data[key].map((item) => {
|
|
607
|
-
if (typeof item === 'string') {
|
|
608
|
-
if (item.toLowerCase() === 'true')
|
|
609
|
-
return true;
|
|
610
|
-
if (item.toLowerCase() === 'false')
|
|
611
|
-
return false;
|
|
612
|
-
}
|
|
613
|
-
return item;
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
if (val instanceof tex_types_1.TexType && val.sanitizers.length > 0) {
|
|
619
|
-
for (const s of val.sanitizers) {
|
|
620
|
-
if (data[key] === undefined || data[key] === null)
|
|
621
|
-
break;
|
|
622
|
-
data[key] = s(data[key]);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
const itemSchema = val?._item;
|
|
626
|
-
if (itemSchema && Array.isArray(data[key])) {
|
|
627
|
-
if (itemSchema instanceof tex_types_1.TexType &&
|
|
628
|
-
itemSchema.sanitizers.length > 0) {
|
|
629
|
-
for (let i = 0; i < data[key].length; i++) {
|
|
630
|
-
if (data[key][i] !== undefined && data[key][i] !== null) {
|
|
631
|
-
for (const s of itemSchema.sanitizers) {
|
|
632
|
-
if (data[key][i] === undefined || data[key][i] === null)
|
|
633
|
-
break;
|
|
634
|
-
data[key][i] = s(data[key][i]);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
// 2. Rust Validation
|
|
644
|
-
let parsedData;
|
|
645
|
-
try {
|
|
646
|
-
parsedData = this.validator.parse(data);
|
|
647
|
-
}
|
|
648
|
-
catch (err) {
|
|
649
|
-
if (data === process.env &&
|
|
650
|
-
(process.env.__EXIS_SKIP_ENV_CHECK === 'true' ||
|
|
651
|
-
process.env.EXIS_SKIP_ENV_CHECK === 'true')) {
|
|
652
|
-
const mock = { ...data };
|
|
653
|
-
for (const [key, val] of Object.entries(this.rawSchema)) {
|
|
654
|
-
if (mock[key] === undefined) {
|
|
655
|
-
const raw = val instanceof tex_types_1.TexType ? val._raw : String(val);
|
|
656
|
-
if (raw.includes('number'))
|
|
657
|
-
mock[key] = 0;
|
|
658
|
-
else if (raw.includes('boolean'))
|
|
659
|
-
mock[key] = false;
|
|
660
|
-
else if (raw.includes('array'))
|
|
661
|
-
mock[key] = [];
|
|
662
|
-
else
|
|
663
|
-
mock[key] = `mock_${key}`;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
return mock;
|
|
667
|
-
}
|
|
668
|
-
let path = 'root';
|
|
669
|
-
let message = err.message || 'Validation failed';
|
|
670
|
-
let expected;
|
|
671
|
-
let code = 'VALIDATION_ERROR';
|
|
672
|
-
if (message.startsWith('Missing required field: ')) {
|
|
673
|
-
path = message.replace('Missing required field: ', '').trim();
|
|
674
|
-
message = 'Expected value, received undefined';
|
|
675
|
-
expected = 'defined';
|
|
676
|
-
code = 'MISSING_REQUIRED_FIELD';
|
|
677
|
-
}
|
|
678
|
-
else if (message.startsWith("Field '")) {
|
|
679
|
-
const match = message.match(/Field '([^']+)' (.+)/);
|
|
680
|
-
if (match) {
|
|
681
|
-
path = match[1];
|
|
682
|
-
const constraint = match[2];
|
|
683
|
-
message = constraint.charAt(0).toUpperCase() + constraint.slice(1);
|
|
684
|
-
if (constraint.startsWith('must be a string')) {
|
|
685
|
-
expected = 'string';
|
|
686
|
-
code = 'INVALID_TYPE';
|
|
687
|
-
}
|
|
688
|
-
else if (constraint.startsWith('must be a number')) {
|
|
689
|
-
expected = 'number';
|
|
690
|
-
code = 'INVALID_TYPE';
|
|
691
|
-
}
|
|
692
|
-
else if (constraint.startsWith('must be a boolean')) {
|
|
693
|
-
expected = 'boolean';
|
|
694
|
-
code = 'INVALID_TYPE';
|
|
695
|
-
}
|
|
696
|
-
else if (constraint.startsWith('must be an array') ||
|
|
697
|
-
constraint.includes('array must have') ||
|
|
698
|
-
constraint.includes('array exceeds')) {
|
|
699
|
-
expected = 'array';
|
|
700
|
-
code = constraint.includes('array must have')
|
|
701
|
-
? 'ARRAY_TOO_SHORT'
|
|
702
|
-
: constraint.includes('array exceeds')
|
|
703
|
-
? 'ARRAY_TOO_LONG'
|
|
704
|
-
: 'INVALID_TYPE';
|
|
705
|
-
}
|
|
706
|
-
else if (constraint.startsWith('must be an object')) {
|
|
707
|
-
expected = 'object';
|
|
708
|
-
code = 'INVALID_TYPE';
|
|
709
|
-
}
|
|
710
|
-
else if (constraint.startsWith('must be a valid email')) {
|
|
711
|
-
expected = 'valid email address';
|
|
712
|
-
code = 'INVALID_EMAIL';
|
|
713
|
-
}
|
|
714
|
-
else if (constraint.startsWith('must be one of')) {
|
|
715
|
-
expected = constraint.replace('must be one of', '').trim();
|
|
716
|
-
code = 'INVALID_ENUM_VALUE';
|
|
717
|
-
}
|
|
718
|
-
else if (constraint.startsWith('must be at least') ||
|
|
719
|
-
constraint.startsWith('must be >=')) {
|
|
720
|
-
expected = constraint;
|
|
721
|
-
code = 'VALUE_TOO_SMALL';
|
|
722
|
-
}
|
|
723
|
-
else if (constraint.startsWith('must be at most') ||
|
|
724
|
-
constraint.startsWith('must be <=')) {
|
|
725
|
-
expected = constraint;
|
|
726
|
-
code = 'VALUE_TOO_LARGE';
|
|
727
|
-
}
|
|
728
|
-
else if (constraint.startsWith('must contain a number')) {
|
|
729
|
-
expected = 'must contain at least one digit';
|
|
730
|
-
code = 'PASSWORD_REQUIRES_NUMBER';
|
|
731
|
-
}
|
|
732
|
-
else if (constraint.startsWith('must contain an uppercase')) {
|
|
733
|
-
expected = 'must contain at least one uppercase letter';
|
|
734
|
-
code = 'PASSWORD_REQUIRES_UPPERCASE';
|
|
735
|
-
}
|
|
736
|
-
else if (constraint.startsWith('must contain a lowercase')) {
|
|
737
|
-
expected = 'must contain at least one lowercase letter';
|
|
738
|
-
code = 'PASSWORD_REQUIRES_LOWERCASE';
|
|
739
|
-
}
|
|
740
|
-
else if (constraint.startsWith('must contain a symbol')) {
|
|
741
|
-
expected = 'must contain at least one symbol';
|
|
742
|
-
code = 'PASSWORD_REQUIRES_SYMBOL';
|
|
743
|
-
}
|
|
744
|
-
else {
|
|
745
|
-
expected = constraint;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
else if (message.startsWith("Strict mode error: Unknown field '")) {
|
|
750
|
-
const match = message.match(/Strict mode error: Unknown field '([^']+)'(?: at path '([^']*)')?/);
|
|
751
|
-
if (match) {
|
|
752
|
-
const key = match[1];
|
|
753
|
-
const parentPath = match[2];
|
|
754
|
-
path =
|
|
755
|
-
parentPath && parentPath.length > 0 ? `${parentPath}.${key}` : key;
|
|
756
|
-
message = 'Unknown field not allowed in strict mode';
|
|
757
|
-
expected = 'undefined (field omitted)';
|
|
758
|
-
code = 'UNRECOGNIZED_KEYS';
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
const receivedRaw = getNestedValue(data, path);
|
|
762
|
-
const received = formatReceivedValue(receivedRaw);
|
|
763
|
-
throw new ValidatorError([{ path, message, expected, received, code }]);
|
|
764
|
-
}
|
|
765
|
-
// Preserve Date objects and ensure defaults are applied
|
|
766
|
-
if (parsedData && typeof parsedData === 'object') {
|
|
767
|
-
for (const [key, val] of Object.entries(this.rawSchema)) {
|
|
768
|
-
if (parsedData[key] === undefined &&
|
|
769
|
-
val instanceof tex_types_1.TexType &&
|
|
770
|
-
val.defaultValue !== undefined) {
|
|
771
|
-
parsedData[key] =
|
|
772
|
-
typeof val.defaultValue === 'function'
|
|
773
|
-
? val.defaultValue()
|
|
774
|
-
: val.defaultValue;
|
|
775
|
-
}
|
|
776
|
-
if (val instanceof tex_types_1.TexType &&
|
|
777
|
-
val._raw.startsWith('date') &&
|
|
778
|
-
data &&
|
|
779
|
-
data[key] instanceof Date) {
|
|
780
|
-
parsedData[key] = data[key];
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
// 3. Post-validation synchronous refinements
|
|
785
|
-
const errors = [];
|
|
786
|
-
if (parsedData && typeof parsedData === 'object') {
|
|
787
|
-
for (const [key, val] of Object.entries(this.rawSchema)) {
|
|
788
|
-
if (parsedData[key] !== undefined) {
|
|
789
|
-
const isNullableField = val instanceof tex_types_1.TexType &&
|
|
790
|
-
(val._raw.includes('nullable') || val._raw.includes('nullish'));
|
|
791
|
-
if (parsedData[key] === null && isNullableField) {
|
|
792
|
-
continue;
|
|
793
|
-
}
|
|
794
|
-
if (val instanceof tex_types_1.TexType && val.refinements.length > 0) {
|
|
795
|
-
for (const r of val.refinements) {
|
|
796
|
-
if (!r.async && !r.fn(parsedData[key])) {
|
|
797
|
-
const msg = typeof r.message === 'function'
|
|
798
|
-
? r.message(parsedData[key])
|
|
799
|
-
: r.message || 'Invalid value';
|
|
800
|
-
errors.push({
|
|
801
|
-
path: key,
|
|
802
|
-
message: msg,
|
|
803
|
-
expected: 'custom refinement rule',
|
|
804
|
-
received: formatReceivedValue(parsedData[key]),
|
|
805
|
-
code: 'CUSTOM_VALIDATION',
|
|
806
|
-
});
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
const itemSchema = val?._item;
|
|
811
|
-
if (itemSchema && Array.isArray(parsedData[key])) {
|
|
812
|
-
if (itemSchema instanceof tex_types_1.TexType &&
|
|
813
|
-
itemSchema.refinements.length > 0) {
|
|
814
|
-
const isItemNullable = itemSchema._raw.includes('nullable') ||
|
|
815
|
-
itemSchema._raw.includes('nullish');
|
|
816
|
-
for (let i = 0; i < parsedData[key].length; i++) {
|
|
817
|
-
if (parsedData[key][i] === null && isItemNullable)
|
|
818
|
-
continue;
|
|
819
|
-
for (const r of itemSchema.refinements) {
|
|
820
|
-
if (!r.async && !r.fn(parsedData[key][i])) {
|
|
821
|
-
const msg = typeof r.message === 'function'
|
|
822
|
-
? r.message(parsedData[key][i])
|
|
823
|
-
: r.message || 'Invalid value';
|
|
824
|
-
errors.push({
|
|
825
|
-
path: `${key}[${i}]`,
|
|
826
|
-
message: msg,
|
|
827
|
-
expected: 'custom refinement rule',
|
|
828
|
-
received: formatReceivedValue(parsedData[key][i]),
|
|
829
|
-
code: 'CUSTOM_VALIDATION',
|
|
830
|
-
});
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
if (errors.length > 0)
|
|
840
|
-
throw new ValidatorError(errors);
|
|
841
|
-
return parsedData;
|
|
842
|
-
}
|
|
843
|
-
async parseAsync(data) {
|
|
844
|
-
const parsed = this.parse(data); // Handles sync sanitizers + rust + sync refine
|
|
845
|
-
const errors = [];
|
|
846
|
-
if (parsed && typeof parsed === 'object') {
|
|
847
|
-
await Promise.all(Object.entries(this.rawSchema).map(async ([key, val]) => {
|
|
848
|
-
const valData = parsed[key];
|
|
849
|
-
const isNullableField = val instanceof tex_types_1.TexType &&
|
|
850
|
-
(val._raw.includes('nullable') || val._raw.includes('nullish'));
|
|
851
|
-
if (valData === null && isNullableField)
|
|
852
|
-
return;
|
|
853
|
-
if (valData !== undefined &&
|
|
854
|
-
val instanceof tex_types_1.TexType &&
|
|
855
|
-
val.refinements.length > 0) {
|
|
856
|
-
for (const r of val.refinements) {
|
|
857
|
-
if (r.async && !(await r.fn(valData))) {
|
|
858
|
-
const msg = typeof r.message === 'function'
|
|
859
|
-
? r.message(valData)
|
|
860
|
-
: r.message || 'Invalid value';
|
|
861
|
-
errors.push({
|
|
862
|
-
path: key,
|
|
863
|
-
message: msg,
|
|
864
|
-
expected: 'custom async refinement rule',
|
|
865
|
-
received: formatReceivedValue(valData),
|
|
866
|
-
code: 'CUSTOM_VALIDATION',
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
}));
|
|
872
|
-
}
|
|
873
|
-
if (errors.length > 0)
|
|
874
|
-
throw new ValidatorError(errors);
|
|
875
|
-
return parsed;
|
|
876
|
-
}
|
|
877
|
-
toMongoSchema() {
|
|
878
|
-
const schemaDef = {};
|
|
879
|
-
for (const [key, rawDef] of Object.entries(this.schema)) {
|
|
880
|
-
const typeStr = rawDef.split('|')[0].trim();
|
|
881
|
-
const isOptional = typeStr.endsWith('?');
|
|
882
|
-
const baseType = typeStr.replace('?', '');
|
|
883
|
-
const field = {};
|
|
884
|
-
if (baseType.startsWith('string') ||
|
|
885
|
-
baseType.startsWith('email') ||
|
|
886
|
-
baseType.startsWith('uuid') ||
|
|
887
|
-
baseType.startsWith('cuid') ||
|
|
888
|
-
baseType.startsWith('password'))
|
|
889
|
-
field.type = String;
|
|
890
|
-
else if (baseType.startsWith('number'))
|
|
891
|
-
field.type = Number;
|
|
892
|
-
else if (baseType.startsWith('boolean'))
|
|
893
|
-
field.type = Boolean;
|
|
894
|
-
else if (baseType.startsWith('date'))
|
|
895
|
-
field.type = Date;
|
|
896
|
-
else
|
|
897
|
-
field.type = Object; // 'Mixed' essentially or nested
|
|
898
|
-
if (!isOptional)
|
|
899
|
-
field.required = true;
|
|
900
|
-
schemaDef[key] = field;
|
|
901
|
-
}
|
|
902
|
-
return schemaDef;
|
|
903
|
-
}
|
|
904
|
-
toOpenApi() {
|
|
905
|
-
const properties = {};
|
|
906
|
-
const required = [];
|
|
907
|
-
for (const [key, rawDef] of Object.entries(this.schema)) {
|
|
908
|
-
const typeStr = rawDef.split('|')[0].trim();
|
|
909
|
-
const isOptional = typeStr.endsWith('?');
|
|
910
|
-
const baseType = typeStr.replace('?', '');
|
|
911
|
-
const prop = {};
|
|
912
|
-
if (baseType.startsWith('string') ||
|
|
913
|
-
baseType.startsWith('uuid') ||
|
|
914
|
-
baseType.startsWith('cuid') ||
|
|
915
|
-
baseType.startsWith('password'))
|
|
916
|
-
prop.type = 'string';
|
|
917
|
-
else if (baseType.startsWith('email')) {
|
|
918
|
-
prop.type = 'string';
|
|
919
|
-
prop.format = 'email';
|
|
920
|
-
}
|
|
921
|
-
else if (baseType.startsWith('number'))
|
|
922
|
-
prop.type = 'number';
|
|
923
|
-
else if (baseType.startsWith('boolean'))
|
|
924
|
-
prop.type = 'boolean';
|
|
925
|
-
else if (baseType.startsWith('date'))
|
|
926
|
-
prop.type = 'string';
|
|
927
|
-
else if (baseType.startsWith('array<'))
|
|
928
|
-
prop.type = 'array';
|
|
929
|
-
else if (baseType.startsWith('enum:'))
|
|
930
|
-
prop.type = 'string'; // Simplification
|
|
931
|
-
else
|
|
932
|
-
prop.type = 'object';
|
|
933
|
-
properties[key] = prop;
|
|
934
|
-
if (!isOptional)
|
|
935
|
-
required.push(key);
|
|
936
|
-
}
|
|
937
|
-
const result = { type: 'object', properties };
|
|
938
|
-
if (required.length > 0)
|
|
939
|
-
result.required = required;
|
|
940
|
-
return result;
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
exports.TexEngine = TexEngine;
|
|
944
|
-
exports.tex = new TexBuilder();
|
|
945
|
-
function paginate(data, total, options = {}) {
|
|
946
|
-
const page = Math.max(1, Number(options.page) || 1);
|
|
947
|
-
const limit = Math.max(1, Number(options.limit) || 20);
|
|
948
|
-
const totalPages = Math.ceil(total / limit);
|
|
949
|
-
const hasNext = page < totalPages;
|
|
950
|
-
const hasPrev = page > 1;
|
|
951
|
-
return {
|
|
952
|
-
data,
|
|
953
|
-
pagination: {
|
|
954
|
-
page,
|
|
955
|
-
limit,
|
|
956
|
-
total,
|
|
957
|
-
totalPages,
|
|
958
|
-
hasNextPage: hasNext,
|
|
959
|
-
hasPrevPage: hasPrev,
|
|
960
|
-
hasNext,
|
|
961
|
-
hasPrev,
|
|
962
|
-
},
|
|
963
|
-
};
|
|
964
|
-
}
|
|
965
|
-
function getPaginationSkip(query = {}) {
|
|
966
|
-
const page = Math.max(1, Number(query.page) || 1);
|
|
967
|
-
const limit = Math.max(1, Number(query.limit) || 20);
|
|
968
|
-
return {
|
|
969
|
-
skip: (page - 1) * limit,
|
|
970
|
-
limit,
|
|
971
|
-
page,
|
|
972
|
-
};
|
|
973
|
-
}
|
|
3
|
+
exports.getPaginationSkip = exports.paginate = exports.formatReceivedValue = exports.getNestedValue = exports.ValidatorError = exports.TexEngine = exports.tex = exports.TexBuilder = void 0;
|
|
4
|
+
const builder_1 = require("./builder");
|
|
5
|
+
var builder_2 = require("./builder");
|
|
6
|
+
Object.defineProperty(exports, "TexBuilder", { enumerable: true, get: function () { return builder_2.TexBuilder; } });
|
|
7
|
+
exports.tex = new builder_1.TexBuilder();
|
|
8
|
+
var engine_1 = require("./engine");
|
|
9
|
+
Object.defineProperty(exports, "TexEngine", { enumerable: true, get: function () { return engine_1.TexEngine; } });
|
|
10
|
+
var error_1 = require("./error");
|
|
11
|
+
Object.defineProperty(exports, "ValidatorError", { enumerable: true, get: function () { return error_1.ValidatorError; } });
|
|
12
|
+
Object.defineProperty(exports, "getNestedValue", { enumerable: true, get: function () { return error_1.getNestedValue; } });
|
|
13
|
+
Object.defineProperty(exports, "formatReceivedValue", { enumerable: true, get: function () { return error_1.formatReceivedValue; } });
|
|
14
|
+
var pagination_1 = require("./pagination");
|
|
15
|
+
Object.defineProperty(exports, "paginate", { enumerable: true, get: function () { return pagination_1.paginate; } });
|
|
16
|
+
Object.defineProperty(exports, "getPaginationSkip", { enumerable: true, get: function () { return pagination_1.getPaginationSkip; } });
|
|
974
17
|
//# sourceMappingURL=tex.js.map
|