@zyno-io/ts-reflection 26.803.2224
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 +13 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +966 -0
- package/dist/reflection/annotations.d.ts +15 -0
- package/dist/reflection/annotations.d.ts.map +1 -0
- package/dist/reflection/compact-metadata.d.ts +18 -0
- package/dist/reflection/compact-metadata.d.ts.map +1 -0
- package/dist/reflection/conversion.d.ts +15 -0
- package/dist/reflection/conversion.d.ts.map +1 -0
- package/dist/reflection/deserializer.d.ts +15 -0
- package/dist/reflection/deserializer.d.ts.map +1 -0
- package/dist/reflection/errors.d.ts +8 -0
- package/dist/reflection/errors.d.ts.map +1 -0
- package/dist/reflection/index.d.ts +10 -0
- package/dist/reflection/index.d.ts.map +1 -0
- package/dist/reflection/metadata-store.d.ts +20 -0
- package/dist/reflection/metadata-store.d.ts.map +1 -0
- package/dist/reflection/model.d.ts +273 -0
- package/dist/reflection/model.d.ts.map +1 -0
- package/dist/reflection/primitive-conversion.d.ts +2 -0
- package/dist/reflection/primitive-conversion.d.ts.map +1 -0
- package/dist/reflection/reflection-class.d.ts +60 -0
- package/dist/reflection/reflection-class.d.ts.map +1 -0
- package/dist/reflection/type-utils.d.ts +34 -0
- package/dist/reflection/type-utils.d.ts.map +1 -0
- package/dist/type-compiler/download-prebuilt.cjs +114 -0
- package/dist/type-compiler/go/ast_expression.go +187 -0
- package/dist/type-compiler/go/ast_metadata.go +388 -0
- package/dist/type-compiler/go/collect.go +963 -0
- package/dist/type-compiler/go/compact_metadata.go +553 -0
- package/dist/type-compiler/go/emission_plan.go +340 -0
- package/dist/type-compiler/go/emit_ast.go +557 -0
- package/dist/type-compiler/go/emit_ast_test.go +558 -0
- package/dist/type-compiler/go/go.mod +10 -0
- package/dist/type-compiler/go/plugin.go +359 -0
- package/dist/type-compiler/go/plugin_test.go +1206 -0
- package/dist/type-compiler/go/precompute.go +86 -0
- package/dist/type-compiler/go/receive_type.go +912 -0
- package/dist/type-compiler/go/resolve.go +265 -0
- package/dist/type-compiler/go/source_scan.go +51 -0
- package/dist/type-compiler/go/text_parse.go +734 -0
- package/dist/type-compiler/go/type_expr.go +1291 -0
- package/dist/type-compiler/go/typia_expr.go +2316 -0
- package/dist/type-compiler/index.cjs +43 -0
- package/dist/type-compiler/pnp.cjs +474 -0
- package/dist/type-compiler/prebuilt.cjs +324 -0
- package/dist/type-metadata-runtime.cjs +1 -0
- package/dist/type-metadata-runtime.d.ts +2 -0
- package/dist/type-metadata-runtime.d.ts.map +1 -0
- package/dist/type-metadata-runtime.js +107 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/primitives.d.ts +33 -0
- package/dist/types/primitives.d.ts.map +1 -0
- package/dist/types/runtime.d.ts +2 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/type-annotations.d.ts +28 -0
- package/dist/types/type-annotations.d.ts.map +1 -0
- package/package.json +47 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,966 @@
|
|
|
1
|
+
//#region src/reflection/model.ts
|
|
2
|
+
var e = /* @__PURE__ */ function(e) {
|
|
3
|
+
return e[e.never = 0] = "never", e[e.any = 1] = "any", e[e.unknown = 2] = "unknown", e[e.void = 3] = "void", e[e.undefined = 4] = "undefined", e[e.null = 5] = "null", e[e.string = 6] = "string", e[e.number = 7] = "number", e[e.boolean = 8] = "boolean", e[e.bigint = 9] = "bigint", e[e.literal = 10] = "literal", e[e.enum = 11] = "enum", e[e.union = 12] = "union", e[e.intersection = 13] = "intersection", e[e.array = 14] = "array", e[e.tuple = 15] = "tuple", e[e.class = 16] = "class", e[e.object = 17] = "object", e[e.objectLiteral = 18] = "objectLiteral", e[e.property = 19] = "property", e[e.propertySignature = 20] = "propertySignature", e[e.method = 21] = "method", e[e.promise = 22] = "promise", e[e.templateLiteral = 23] = "templateLiteral", e;
|
|
4
|
+
}({});
|
|
5
|
+
function t(e) {
|
|
6
|
+
return !!e && typeof e == "object" && typeof e.kind == "number";
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/reflection/errors.ts
|
|
10
|
+
var n = class extends Error {
|
|
11
|
+
code;
|
|
12
|
+
path;
|
|
13
|
+
errors;
|
|
14
|
+
constructor(e, t, n = "") {
|
|
15
|
+
super(t), this.code = e, this.path = n, this.errors = [this];
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(n, "name", {
|
|
19
|
+
configurable: !0,
|
|
20
|
+
value: "ValidatorError"
|
|
21
|
+
});
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/reflection/deserializer.ts
|
|
24
|
+
var r = class {
|
|
25
|
+
decorators = [];
|
|
26
|
+
addDecorator(e, t) {
|
|
27
|
+
this.decorators.push({
|
|
28
|
+
predicate: e,
|
|
29
|
+
handler: t
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
apply(e, t) {
|
|
33
|
+
let n = t;
|
|
34
|
+
for (let t of this.decorators) {
|
|
35
|
+
if (!t.predicate(e)) continue;
|
|
36
|
+
let r = new i();
|
|
37
|
+
t.handler(e, r), n = r.apply(n);
|
|
38
|
+
}
|
|
39
|
+
return n;
|
|
40
|
+
}
|
|
41
|
+
}, i = class {
|
|
42
|
+
transforms = [];
|
|
43
|
+
addTransform(e) {
|
|
44
|
+
this.transforms.push(e);
|
|
45
|
+
}
|
|
46
|
+
apply(e) {
|
|
47
|
+
return this.transforms.reduce((e, t) => t(e), e);
|
|
48
|
+
}
|
|
49
|
+
}, a = new r();
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/reflection/primitive-conversion.ts
|
|
52
|
+
function o(e) {
|
|
53
|
+
if (typeof e == "boolean") return e;
|
|
54
|
+
if (typeof e == "number") return e !== 0;
|
|
55
|
+
if (typeof e == "bigint") return e !== 0n;
|
|
56
|
+
if (typeof e == "string") {
|
|
57
|
+
if (e === "true" || e === "1") return !0;
|
|
58
|
+
if (e === "false" || e === "0") return !1;
|
|
59
|
+
}
|
|
60
|
+
return e;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/reflection/type-utils.ts
|
|
64
|
+
function s(t) {
|
|
65
|
+
if (t.kind === e.union) {
|
|
66
|
+
let n = t.types.filter((t) => t.kind !== e.undefined && t.kind !== e.null);
|
|
67
|
+
return n.length === 1 ? s(n[0]) : t;
|
|
68
|
+
}
|
|
69
|
+
if (t.kind === e.intersection) {
|
|
70
|
+
let e = c(t);
|
|
71
|
+
if (e) return e;
|
|
72
|
+
let n = t.types.find((e) => !p(e));
|
|
73
|
+
return n ? s(n) : t;
|
|
74
|
+
}
|
|
75
|
+
return t;
|
|
76
|
+
}
|
|
77
|
+
function c(t) {
|
|
78
|
+
if (t.kind !== e.intersection || !l(t)) return;
|
|
79
|
+
let n = u(t);
|
|
80
|
+
if (n.length !== 0) return {
|
|
81
|
+
kind: e.objectLiteral,
|
|
82
|
+
typeName: t.typeName,
|
|
83
|
+
types: n
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function l(t) {
|
|
87
|
+
return t.kind === e.intersection && t.types.every((t) => p(t) ? !0 : t.kind === e.intersection ? l(t) : t.kind === e.objectLiteral);
|
|
88
|
+
}
|
|
89
|
+
function u(t) {
|
|
90
|
+
let n = [], r = /* @__PURE__ */ new Map(), i = (t) => {
|
|
91
|
+
let i = String(t.name);
|
|
92
|
+
r.has(i) || n.push(i), r.set(i, {
|
|
93
|
+
kind: e.propertySignature,
|
|
94
|
+
name: t.name,
|
|
95
|
+
type: t.type,
|
|
96
|
+
optional: t.optional
|
|
97
|
+
});
|
|
98
|
+
}, a = (t) => {
|
|
99
|
+
if (!p(t)) {
|
|
100
|
+
if (t.kind === e.intersection) {
|
|
101
|
+
for (let e of t.types) a(e);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (t.kind === e.objectLiteral) {
|
|
105
|
+
for (let e of d(t)) i(e);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
return a(t), n.map((e) => r.get(e));
|
|
111
|
+
}
|
|
112
|
+
function d(t, n = /* @__PURE__ */ new Set()) {
|
|
113
|
+
if (n.has(t) || p(t)) return [];
|
|
114
|
+
n.add(t);
|
|
115
|
+
let r = [];
|
|
116
|
+
for (let i of t.implements ?? []) {
|
|
117
|
+
let t = s(i);
|
|
118
|
+
n.has(t) || (t.kind === e.objectLiteral ? r.push(...d(t, n)) : t.kind === e.intersection ? r.push(...u(t)) : t.kind === e.class && r.push(...C(t)));
|
|
119
|
+
}
|
|
120
|
+
return w([...r, ...t.types.map(T)]);
|
|
121
|
+
}
|
|
122
|
+
function f(t, n = /* @__PURE__ */ new Set()) {
|
|
123
|
+
if (t.index) return t.index;
|
|
124
|
+
if (!n.has(t)) {
|
|
125
|
+
n.add(t);
|
|
126
|
+
for (let r of t.implements ?? []) {
|
|
127
|
+
let t = s(r);
|
|
128
|
+
if (t.kind === e.objectLiteral) {
|
|
129
|
+
let e = f(t, n);
|
|
130
|
+
if (e) return e;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function p(e) {
|
|
136
|
+
return !!(e.annotations || e.validation || e.database || ee(e) || ne(e));
|
|
137
|
+
}
|
|
138
|
+
function ee(t) {
|
|
139
|
+
return te(t.typeName) ? t.kind === e.unknown || t.kind === e.class && !g(t.classType) : !1;
|
|
140
|
+
}
|
|
141
|
+
function te(e) {
|
|
142
|
+
switch (e) {
|
|
143
|
+
case "ApiName":
|
|
144
|
+
case "AutoIncrement":
|
|
145
|
+
case "DatabaseField":
|
|
146
|
+
case "GreaterThan":
|
|
147
|
+
case "HasDefault":
|
|
148
|
+
case "Index":
|
|
149
|
+
case "Length":
|
|
150
|
+
case "LessThan":
|
|
151
|
+
case "Maximum":
|
|
152
|
+
case "MaxLength":
|
|
153
|
+
case "Minimum":
|
|
154
|
+
case "MinLength":
|
|
155
|
+
case "MySQL":
|
|
156
|
+
case "OnUpdate":
|
|
157
|
+
case "Pattern":
|
|
158
|
+
case "PrimaryKey":
|
|
159
|
+
case "Reference":
|
|
160
|
+
case "TypeAnnotation":
|
|
161
|
+
case "Unique": return !0;
|
|
162
|
+
default: return !1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function ne(t) {
|
|
166
|
+
return t.kind === e.objectLiteral && t.types.length > 0 && t.types.every((t) => t.kind === e.propertySignature && String(t.name) === "typia.tag");
|
|
167
|
+
}
|
|
168
|
+
function m(t) {
|
|
169
|
+
return t.kind === e.any || t.kind === e.undefined || t.kind === e.union && t.types.some(m);
|
|
170
|
+
}
|
|
171
|
+
function h(t) {
|
|
172
|
+
return t.kind === e.any || t.kind === e.null || t.kind === e.union && t.types.some(h);
|
|
173
|
+
}
|
|
174
|
+
function re(e) {
|
|
175
|
+
let t = g(e);
|
|
176
|
+
if (!t) throw Error("Target is not a constructor");
|
|
177
|
+
return t;
|
|
178
|
+
}
|
|
179
|
+
function g(e) {
|
|
180
|
+
if (v(e)) return e;
|
|
181
|
+
try {
|
|
182
|
+
let t = e();
|
|
183
|
+
return v(t) ? t : void 0;
|
|
184
|
+
} catch {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function _(t, n = /* @__PURE__ */ new Set()) {
|
|
189
|
+
if (!t || typeof t != "object" || n.has(t)) return;
|
|
190
|
+
n.add(t);
|
|
191
|
+
let r = t;
|
|
192
|
+
if (r.kind === e.class && typeof r.classType == "function" && !v(r.classType)) try {
|
|
193
|
+
let e = r.classType();
|
|
194
|
+
v(e) && (r.classType = e);
|
|
195
|
+
} catch {}
|
|
196
|
+
for (let e of Object.values(r)) if (typeof e != "function") if (Array.isArray(e)) for (let t of e) _(t, n);
|
|
197
|
+
else _(e, n);
|
|
198
|
+
ie(r), ce(r);
|
|
199
|
+
}
|
|
200
|
+
function ie(n) {
|
|
201
|
+
if (n.kind !== e.intersection || !Array.isArray(n.types)) return;
|
|
202
|
+
let r = n.types.filter(t);
|
|
203
|
+
if (r.length !== n.types.length) return;
|
|
204
|
+
let i = r.filter((t) => t.kind === e.union);
|
|
205
|
+
if (i.length === 0 || i.length === 1 && r.every((e) => e === i[0] || p(e))) return;
|
|
206
|
+
let a = [[]];
|
|
207
|
+
for (let e of r) {
|
|
208
|
+
let t = ae(e);
|
|
209
|
+
a = a.flatMap((e) => t.map((t) => [...e, ...t]));
|
|
210
|
+
}
|
|
211
|
+
n.kind = e.union, n.types = a.map(se);
|
|
212
|
+
}
|
|
213
|
+
function ae(t) {
|
|
214
|
+
if (t.kind !== e.union) return [[t]];
|
|
215
|
+
let n = oe(t);
|
|
216
|
+
return t.types.flatMap((e) => ae(e).map((e) => n ? [...e, n] : e));
|
|
217
|
+
}
|
|
218
|
+
function oe(t) {
|
|
219
|
+
if (!(!t.annotations && !t.validation && !t.database)) return {
|
|
220
|
+
kind: e.unknown,
|
|
221
|
+
annotations: t.annotations,
|
|
222
|
+
validation: t.validation,
|
|
223
|
+
database: t.database
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function se(t) {
|
|
227
|
+
return t.some((t) => t.kind === e.never) ? { kind: e.never } : t.length === 1 ? t[0] : {
|
|
228
|
+
kind: e.intersection,
|
|
229
|
+
types: t
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function v(e) {
|
|
233
|
+
return !!(typeof e == "function" && e.prototype && e.prototype.constructor === e);
|
|
234
|
+
}
|
|
235
|
+
function ce(n) {
|
|
236
|
+
let r = de(n);
|
|
237
|
+
if (!r) return;
|
|
238
|
+
let i = Array.isArray(n.typeArguments) ? n.typeArguments : [];
|
|
239
|
+
if (r === "Record") {
|
|
240
|
+
if (n.kind !== e.objectLiteral || (n.types ?? []).length > 0) return;
|
|
241
|
+
let r = i[0], a = i[1];
|
|
242
|
+
if (!t(r) || !t(a)) return;
|
|
243
|
+
let o = le(r, a);
|
|
244
|
+
o.length > 0 ? (n.types = o, delete n.index) : n.index = a;
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if ((n.types ?? []).length > 0) return;
|
|
248
|
+
let a = i[0];
|
|
249
|
+
if (!t(a)) return;
|
|
250
|
+
if (r === "Extract") {
|
|
251
|
+
let r = i[1];
|
|
252
|
+
if (n.kind !== e.union || !t(r)) return;
|
|
253
|
+
n.types = y(a).filter((e) => b(e, r));
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (n.kind !== e.objectLiteral) return;
|
|
257
|
+
let o = C(a), s = a.kind === e.objectLiteral ? f(a) : void 0;
|
|
258
|
+
if (o.length === 0) {
|
|
259
|
+
s && (n.index = s);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
let c = new Set((Array.isArray(n.utilityKeys) ? n.utilityKeys : []).filter((e) => typeof e == "string")), l = o.map(T);
|
|
263
|
+
r === "Pick" ? l = l.filter((e) => c.has(String(e.name))) : r === "Omit" ? l = l.filter((e) => !c.has(String(e.name))) : r === "Partial" ? l = l.map((e) => ({
|
|
264
|
+
...e,
|
|
265
|
+
optional: !0
|
|
266
|
+
})) : r === "Required" ? l = l.map((e) => ({
|
|
267
|
+
...e,
|
|
268
|
+
optional: void 0
|
|
269
|
+
})) : r === "OptionalNulls" && (l = l.map((e) => h(e.type) ? {
|
|
270
|
+
...e,
|
|
271
|
+
optional: !0
|
|
272
|
+
} : e)), n.types = l, s && (n.index = s);
|
|
273
|
+
}
|
|
274
|
+
function le(t, n) {
|
|
275
|
+
return ue(t).map((t) => ({
|
|
276
|
+
kind: e.propertySignature,
|
|
277
|
+
name: t,
|
|
278
|
+
type: n,
|
|
279
|
+
optional: void 0
|
|
280
|
+
}));
|
|
281
|
+
}
|
|
282
|
+
function ue(t) {
|
|
283
|
+
let n = [];
|
|
284
|
+
for (let r of y(t)) {
|
|
285
|
+
if (r.kind !== e.literal || typeof r.literal != "string" && typeof r.literal != "number") return [];
|
|
286
|
+
n.push(r.literal);
|
|
287
|
+
}
|
|
288
|
+
return n;
|
|
289
|
+
}
|
|
290
|
+
function y(t) {
|
|
291
|
+
return t.kind === e.union ? t.types.flatMap(y) : [t];
|
|
292
|
+
}
|
|
293
|
+
function b(t, n) {
|
|
294
|
+
let r = s(t), i = s(n);
|
|
295
|
+
if (i.kind === e.union) return i.types.some((e) => b(r, e));
|
|
296
|
+
if (r.kind === e.union) return r.types.every((e) => b(e, i));
|
|
297
|
+
if (i.kind === e.objectLiteral) {
|
|
298
|
+
let t = d(i).filter((e) => !e.optional && !m(e.type));
|
|
299
|
+
if (t.length === 0) return r.kind === e.objectLiteral || r.kind === e.class;
|
|
300
|
+
let n = C(r);
|
|
301
|
+
return n.length !== 0 && t.every((e) => {
|
|
302
|
+
let t = n.find((t) => String(t.name) === String(e.name));
|
|
303
|
+
return t ? x(t.type, e.type) : !1;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return x(r, i);
|
|
307
|
+
}
|
|
308
|
+
function x(t, n) {
|
|
309
|
+
let r = s(t), i = s(n);
|
|
310
|
+
return r.kind === e.any || r.kind === e.unknown || i.kind === e.any || i.kind === e.unknown ? !0 : r.kind === e.union ? r.types.some((e) => x(e, i)) : i.kind === e.union ? i.types.some((e) => x(r, e)) : r.kind === e.literal && i.kind === e.literal ? r.literal === i.literal : r.kind === e.literal ? S(r.literal, i) : i.kind === e.literal ? S(i.literal, r) : r.kind === i.kind;
|
|
311
|
+
}
|
|
312
|
+
function S(t, n) {
|
|
313
|
+
return t === null ? n.kind === e.null : t === void 0 ? n.kind === e.undefined : typeof t == "string" ? n.kind === e.string || n.kind === e.templateLiteral : typeof t == "number" ? n.kind === e.number : typeof t == "boolean" ? n.kind === e.boolean : typeof t == "bigint" && n.kind === e.bigint;
|
|
314
|
+
}
|
|
315
|
+
function C(t) {
|
|
316
|
+
if (t.kind === e.class) {
|
|
317
|
+
let n = g(t.classType);
|
|
318
|
+
if (!n) return [];
|
|
319
|
+
try {
|
|
320
|
+
return G.from(n).getProperties().map((t) => ({
|
|
321
|
+
kind: e.propertySignature,
|
|
322
|
+
name: t.name,
|
|
323
|
+
type: t.getType(),
|
|
324
|
+
optional: t.isOptional() ? !0 : void 0,
|
|
325
|
+
description: t.getDescription() || void 0
|
|
326
|
+
}));
|
|
327
|
+
} catch (e) {
|
|
328
|
+
if (e instanceof Error && e.message.startsWith("No runtime type metadata for ")) return [];
|
|
329
|
+
throw e;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return t.kind === e.objectLiteral ? d(t) : t.kind === e.intersection ? w(t.types.flatMap(C)) : [];
|
|
333
|
+
}
|
|
334
|
+
function w(e) {
|
|
335
|
+
let t = [], n = /* @__PURE__ */ new Map();
|
|
336
|
+
for (let r of e) {
|
|
337
|
+
let e = String(r.name);
|
|
338
|
+
n.has(e) || t.push(e), n.set(e, T(r));
|
|
339
|
+
}
|
|
340
|
+
return t.map((e) => n.get(e));
|
|
341
|
+
}
|
|
342
|
+
function T(t) {
|
|
343
|
+
return {
|
|
344
|
+
kind: e.propertySignature,
|
|
345
|
+
name: t.name,
|
|
346
|
+
type: t.type,
|
|
347
|
+
optional: t.optional ? !0 : void 0,
|
|
348
|
+
description: t.description
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function E(e) {
|
|
352
|
+
return e === "Pick" || e === "Omit" || e === "Partial" || e === "Required" || e === "Extract" || e === "Record" || e === "OptionalNulls";
|
|
353
|
+
}
|
|
354
|
+
function de(e) {
|
|
355
|
+
if (E(e.utilityType)) return e.utilityType;
|
|
356
|
+
if (E(e.typeName)) return e.typeName;
|
|
357
|
+
}
|
|
358
|
+
function D(t, n) {
|
|
359
|
+
if (n(t), (t.kind === e.union || t.kind === e.intersection) && "types" in t) for (let e of t.types) D(e, n);
|
|
360
|
+
else if ((t.kind === e.array || t.kind === e.promise) && "type" in t) D(t.type, n);
|
|
361
|
+
else if (t.kind === e.objectLiteral && "types" in t) {
|
|
362
|
+
for (let e of t.types) D(e.type, n);
|
|
363
|
+
t.index && D(t.index, n);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function O(t, n) {
|
|
367
|
+
if (n(t), (t.kind === e.union || t.kind === e.intersection) && "types" in t) for (let e of t.types) O(e, n);
|
|
368
|
+
}
|
|
369
|
+
function fe(e, t) {
|
|
370
|
+
let n;
|
|
371
|
+
return D(e, (r) => {
|
|
372
|
+
n !== void 0 || r === e || (n = t(r));
|
|
373
|
+
}), n;
|
|
374
|
+
}
|
|
375
|
+
function k(e, t) {
|
|
376
|
+
let n;
|
|
377
|
+
return O(e, (r) => {
|
|
378
|
+
n !== void 0 || r === e || (n = t(r));
|
|
379
|
+
}), n;
|
|
380
|
+
}
|
|
381
|
+
function pe(e, t) {
|
|
382
|
+
let n = !1;
|
|
383
|
+
return D(e, (e) => {
|
|
384
|
+
n ||= t(e);
|
|
385
|
+
}), n;
|
|
386
|
+
}
|
|
387
|
+
function A(t) {
|
|
388
|
+
return t?.kind === e.literal && typeof t.literal == "number" ? t.literal : void 0;
|
|
389
|
+
}
|
|
390
|
+
function j(t) {
|
|
391
|
+
if (!t) return;
|
|
392
|
+
let n = t.runtime;
|
|
393
|
+
if (n !== void 0) return typeof n == "function" ? n() : n;
|
|
394
|
+
if (t.kind === e.literal) return t.literal;
|
|
395
|
+
}
|
|
396
|
+
function M(e, t) {
|
|
397
|
+
return e ? `${e}.${t}` : t;
|
|
398
|
+
}
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region src/reflection/annotations.ts
|
|
401
|
+
function me(t) {
|
|
402
|
+
let n = N.getType(t, "tsf:type");
|
|
403
|
+
return n?.kind === e.literal && (n.literal === "uuid" || n.literal === "uuidString");
|
|
404
|
+
}
|
|
405
|
+
function he(t) {
|
|
406
|
+
let n = N.getType(t, "tsf:type");
|
|
407
|
+
return n?.kind === e.literal && n.literal === "uuid";
|
|
408
|
+
}
|
|
409
|
+
var N = {
|
|
410
|
+
getType(e, t) {
|
|
411
|
+
return e.annotations?.[t] || (k(e, (e) => e.annotations?.[t]) ?? ve(e, t));
|
|
412
|
+
},
|
|
413
|
+
getOption(e, t) {
|
|
414
|
+
return this.getType(e, t);
|
|
415
|
+
}
|
|
416
|
+
}, ge = { getAnnotations(e) {
|
|
417
|
+
let t = [], n = /* @__PURE__ */ new Set();
|
|
418
|
+
return O(e, (e) => {
|
|
419
|
+
if (e.validation) for (let r of e.validation) {
|
|
420
|
+
let e = Ee(r);
|
|
421
|
+
n.has(e) || (n.add(e), t.push(r));
|
|
422
|
+
}
|
|
423
|
+
let r = be(e);
|
|
424
|
+
if (r) {
|
|
425
|
+
let e = Ee(r);
|
|
426
|
+
n.has(e) || (n.add(e), t.push(r));
|
|
427
|
+
}
|
|
428
|
+
}), t;
|
|
429
|
+
} }, P = { getDatabase(t, n) {
|
|
430
|
+
let r = t.database?.[n] ?? (n === "*" ? void 0 : t.database?.["*"]);
|
|
431
|
+
if (r) return r;
|
|
432
|
+
if (t.kind === e.union) {
|
|
433
|
+
let r = t.types.filter((t) => t.kind !== e.null && t.kind !== e.undefined);
|
|
434
|
+
return r.length === 1 ? this.getDatabase(r[0], n) : void 0;
|
|
435
|
+
}
|
|
436
|
+
let i = k(t, (e) => e.database?.[n] ?? (n === "*" ? void 0 : e.database?.["*"]));
|
|
437
|
+
if (i) return i;
|
|
438
|
+
let a = xe(t, n);
|
|
439
|
+
if (a) return a;
|
|
440
|
+
} }, F = { kind: e.undefined };
|
|
441
|
+
function _e(t) {
|
|
442
|
+
return {
|
|
443
|
+
kind: e.literal,
|
|
444
|
+
literal: t
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
function I(e, ...t) {
|
|
448
|
+
return {
|
|
449
|
+
name: e,
|
|
450
|
+
args: t
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
function ve(e, t) {
|
|
454
|
+
return we(e, (e) => ye(e, t));
|
|
455
|
+
}
|
|
456
|
+
function ye(e, t) {
|
|
457
|
+
let n = L(e);
|
|
458
|
+
if (!(!n || n.kind !== t) && !(!n.kind.startsWith("tsf:") && !n.kind.startsWith("openapi:"))) return n.value ?? F;
|
|
459
|
+
}
|
|
460
|
+
function be(e) {
|
|
461
|
+
let t = L(e);
|
|
462
|
+
if (t) switch (t.kind) {
|
|
463
|
+
case "minLength":
|
|
464
|
+
case "maxLength":
|
|
465
|
+
case "minimum":
|
|
466
|
+
case "greaterThan":
|
|
467
|
+
case "maximum":
|
|
468
|
+
case "lessThan": return t.value ? I(t.kind, t.value) : void 0;
|
|
469
|
+
case "pattern": return I("pattern", t.value ?? R(t.schema, "pattern") ?? F);
|
|
470
|
+
case "format": {
|
|
471
|
+
let e = B(t.value) ?? B(R(t.schema, "format")), n = e ? Te(e) : void 0;
|
|
472
|
+
return n ? I("pattern", _e(n)) : void 0;
|
|
473
|
+
}
|
|
474
|
+
case "tsf:validator": return I("validator", t.value ?? F);
|
|
475
|
+
default: return;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
function xe(e, t) {
|
|
479
|
+
return we(e, (e) => Se(e, t));
|
|
480
|
+
}
|
|
481
|
+
function Se(e, t) {
|
|
482
|
+
let n = L(e);
|
|
483
|
+
if (!n) return;
|
|
484
|
+
let r = V(n.schema) ?? V(n.value);
|
|
485
|
+
if (r && (n.kind === "database:field" || n.kind === "database:mysql" && t === "mysql")) return r;
|
|
486
|
+
}
|
|
487
|
+
function L(t) {
|
|
488
|
+
if (t.kind !== e.objectLiteral) return;
|
|
489
|
+
let n = t.types.find((e) => String(e.name) === "typia.tag");
|
|
490
|
+
if (!n) return;
|
|
491
|
+
let r = z(n.type);
|
|
492
|
+
if (r.kind !== e.objectLiteral) return;
|
|
493
|
+
let i = B(R(r, "kind"));
|
|
494
|
+
if (i) return {
|
|
495
|
+
kind: i,
|
|
496
|
+
value: R(r, "value"),
|
|
497
|
+
schema: R(r, "schema")
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function R(t, n) {
|
|
501
|
+
let r = t ? z(t) : void 0;
|
|
502
|
+
if (!(!r || r.kind !== e.objectLiteral)) return r.types.find((e) => String(e.name) === n)?.type;
|
|
503
|
+
}
|
|
504
|
+
function z(t) {
|
|
505
|
+
if (t.kind !== e.union) return t;
|
|
506
|
+
let n = t.types.filter((t) => t.kind !== e.undefined && t.kind !== e.null);
|
|
507
|
+
return n.length === 1 ? n[0] : t;
|
|
508
|
+
}
|
|
509
|
+
function B(t) {
|
|
510
|
+
return t?.kind === e.literal && typeof t.literal == "string" ? t.literal : void 0;
|
|
511
|
+
}
|
|
512
|
+
function V(t) {
|
|
513
|
+
let n = t ? z(t) : void 0;
|
|
514
|
+
if (!n || n.kind !== e.objectLiteral) return;
|
|
515
|
+
let r = {};
|
|
516
|
+
for (let e of n.types) {
|
|
517
|
+
let t = Ce(e.type);
|
|
518
|
+
t !== void 0 && (r[String(e.name)] = t);
|
|
519
|
+
}
|
|
520
|
+
return r;
|
|
521
|
+
}
|
|
522
|
+
function Ce(t) {
|
|
523
|
+
let n = z(t);
|
|
524
|
+
if (n.kind === e.literal) return n.literal;
|
|
525
|
+
if (n.kind !== e.undefined && n.kind === e.objectLiteral) return V(n);
|
|
526
|
+
}
|
|
527
|
+
function we(e, t) {
|
|
528
|
+
let n;
|
|
529
|
+
return O(e, (e) => {
|
|
530
|
+
n === void 0 && (n = t(e));
|
|
531
|
+
}), n;
|
|
532
|
+
}
|
|
533
|
+
function Te(e) {
|
|
534
|
+
switch (e) {
|
|
535
|
+
case "date": return "^\\d{4}-\\d{2}-\\d{2}$";
|
|
536
|
+
case "email": return "^[a-zA-Z0-9_+.-]+@[a-zA-Z0-9-.]+\\.[a-zA-Z]+$";
|
|
537
|
+
case "uuid": return "^(?:urn:uuid:)?[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$";
|
|
538
|
+
default: return;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
function Ee(e) {
|
|
542
|
+
return `${e.name}:${e.args.map(De).join("|")}`;
|
|
543
|
+
}
|
|
544
|
+
function De(t) {
|
|
545
|
+
if (t.kind === e.literal && "literal" in t) return `literal:${String(t.literal)}`;
|
|
546
|
+
let n = t.runtime;
|
|
547
|
+
return n ? `runtime:${String(n)}` : `${t.kind}:${t.typeName ?? ""}`;
|
|
548
|
+
}
|
|
549
|
+
function Oe(t) {
|
|
550
|
+
let n = N.getType(t, "tsf:type");
|
|
551
|
+
if (n?.kind === e.literal) {
|
|
552
|
+
if (n.literal === "integer") return e.number;
|
|
553
|
+
if (typeof n.literal == "string") return e.string;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
//#endregion
|
|
557
|
+
//#region src/reflection/metadata-store.ts
|
|
558
|
+
var H = /* @__PURE__ */ new WeakMap(), U = /* @__PURE__ */ new WeakMap();
|
|
559
|
+
function W(e, t) {
|
|
560
|
+
t && (t.collectionName && (e.collectionName = t.collectionName), t.indexes?.length && (e.indexes = [...t.indexes]), t.excludeMigration && (e.excludeMigration = !0));
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
563
|
+
//#region src/reflection/reflection-class.ts
|
|
564
|
+
function ke(e) {
|
|
565
|
+
if (!e) throw Error("typeOf<T>() was not transformed by the metadata compiler");
|
|
566
|
+
return _(e), e;
|
|
567
|
+
}
|
|
568
|
+
function Ae(e, t) {
|
|
569
|
+
t.classType = e, W(t, U.get(e)), H.set(e, t);
|
|
570
|
+
}
|
|
571
|
+
var G = class t {
|
|
572
|
+
classType;
|
|
573
|
+
name;
|
|
574
|
+
indexes;
|
|
575
|
+
metadata;
|
|
576
|
+
constructor(e, t) {
|
|
577
|
+
this.classType = e, this.metadata = t, this.name = t.name || e.name;
|
|
578
|
+
let n = t.properties.flatMap((e) => {
|
|
579
|
+
let t = [];
|
|
580
|
+
return e.index && t.push({
|
|
581
|
+
names: [e.name],
|
|
582
|
+
options: e.index
|
|
583
|
+
}), e.unique && t.push({
|
|
584
|
+
names: [e.name],
|
|
585
|
+
options: {
|
|
586
|
+
...e.unique,
|
|
587
|
+
unique: !0
|
|
588
|
+
}
|
|
589
|
+
}), t;
|
|
590
|
+
});
|
|
591
|
+
this.indexes = [...t.indexes ?? [], ...n];
|
|
592
|
+
}
|
|
593
|
+
static from(e) {
|
|
594
|
+
let n = J(e);
|
|
595
|
+
if (!n) throw Error(`No runtime type metadata for ${e.name}. Did the tsf metadata compiler run?`);
|
|
596
|
+
return new t(e, n);
|
|
597
|
+
}
|
|
598
|
+
getClassType() {
|
|
599
|
+
return this.classType;
|
|
600
|
+
}
|
|
601
|
+
getCollectionName() {
|
|
602
|
+
return this.metadata.collectionName ?? U.get(this.classType)?.collectionName;
|
|
603
|
+
}
|
|
604
|
+
isDatabaseMigrationSkipped(e) {
|
|
605
|
+
return this.metadata.excludeMigration === !0 || U.get(this.classType)?.excludeMigration === !0;
|
|
606
|
+
}
|
|
607
|
+
getProperties() {
|
|
608
|
+
return Y(this.classType, this.metadata).map((e) => new K(e));
|
|
609
|
+
}
|
|
610
|
+
getProperty(e) {
|
|
611
|
+
let t = Y(this.classType, this.metadata).find((t) => t.name === e);
|
|
612
|
+
if (!t) throw Error(`Property ${String(e)} does not exist on ${this.name}`);
|
|
613
|
+
return new K(t);
|
|
614
|
+
}
|
|
615
|
+
getPrimary() {
|
|
616
|
+
let e = Y(this.classType, this.metadata).find((e) => e.primaryKey);
|
|
617
|
+
if (!e) throw Error(`Class ${this.name} has no primary key`);
|
|
618
|
+
return new K(e);
|
|
619
|
+
}
|
|
620
|
+
getMethod(e) {
|
|
621
|
+
let t = Me(this.classType, this.metadata).find((t) => t.name === e || String(t.name) === String(e));
|
|
622
|
+
if (!t) throw Error(`Method ${String(e)} does not exist on ${this.name}`);
|
|
623
|
+
return new q(t);
|
|
624
|
+
}
|
|
625
|
+
getConstructorOrUndefined() {
|
|
626
|
+
let t = Ne(this.classType, this.metadata);
|
|
627
|
+
if (t.length) return new q({
|
|
628
|
+
name: "constructor",
|
|
629
|
+
parameters: t,
|
|
630
|
+
returnType: { kind: e.void }
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}, K = class {
|
|
634
|
+
metadata;
|
|
635
|
+
type;
|
|
636
|
+
name;
|
|
637
|
+
constructor(e) {
|
|
638
|
+
this.metadata = e, this.type = e.type, this.name = e.name;
|
|
639
|
+
}
|
|
640
|
+
getNameAsString() {
|
|
641
|
+
return String(this.name);
|
|
642
|
+
}
|
|
643
|
+
getType() {
|
|
644
|
+
return this.type;
|
|
645
|
+
}
|
|
646
|
+
getDescription() {
|
|
647
|
+
return this.metadata.description ?? "";
|
|
648
|
+
}
|
|
649
|
+
isPublic() {
|
|
650
|
+
return !0;
|
|
651
|
+
}
|
|
652
|
+
isPrimaryKey() {
|
|
653
|
+
return this.metadata.primaryKey === !0;
|
|
654
|
+
}
|
|
655
|
+
isAutoIncrement() {
|
|
656
|
+
return this.metadata.autoIncrement === !0;
|
|
657
|
+
}
|
|
658
|
+
isOptional() {
|
|
659
|
+
return this.metadata.optional === !0 || m(this.type);
|
|
660
|
+
}
|
|
661
|
+
isNullable() {
|
|
662
|
+
return h(this.type);
|
|
663
|
+
}
|
|
664
|
+
getDatabase(e = "*") {
|
|
665
|
+
return P.getDatabase(this.type, e) || P.getDatabase(this.type, "*");
|
|
666
|
+
}
|
|
667
|
+
isBackReference() {
|
|
668
|
+
return !1;
|
|
669
|
+
}
|
|
670
|
+
isDatabaseSkipped(e) {
|
|
671
|
+
return !1;
|
|
672
|
+
}
|
|
673
|
+
isDatabaseMigrationSkipped(e) {
|
|
674
|
+
return !1;
|
|
675
|
+
}
|
|
676
|
+
isReference() {
|
|
677
|
+
return this.metadata.reference !== void 0;
|
|
678
|
+
}
|
|
679
|
+
getReference() {
|
|
680
|
+
return this.metadata.reference;
|
|
681
|
+
}
|
|
682
|
+
getResolvedReflectionClass() {
|
|
683
|
+
let t = s(this.type);
|
|
684
|
+
if (t.kind !== e.class) throw Error(`Property ${String(this.name)} is not a class reference`);
|
|
685
|
+
return G.from(re(t.classType));
|
|
686
|
+
}
|
|
687
|
+
}, q = class {
|
|
688
|
+
metadata;
|
|
689
|
+
constructor(e) {
|
|
690
|
+
this.metadata = e;
|
|
691
|
+
}
|
|
692
|
+
getDescription() {
|
|
693
|
+
return this.metadata.description ?? "";
|
|
694
|
+
}
|
|
695
|
+
getParameters() {
|
|
696
|
+
return this.metadata.parameters.map((e) => new je(e));
|
|
697
|
+
}
|
|
698
|
+
getReturnType() {
|
|
699
|
+
return this.metadata.returnType;
|
|
700
|
+
}
|
|
701
|
+
}, je = class {
|
|
702
|
+
metadata;
|
|
703
|
+
constructor(e) {
|
|
704
|
+
this.metadata = e;
|
|
705
|
+
}
|
|
706
|
+
getName() {
|
|
707
|
+
return this.metadata.name;
|
|
708
|
+
}
|
|
709
|
+
getType() {
|
|
710
|
+
return this.metadata.type;
|
|
711
|
+
}
|
|
712
|
+
isOptional() {
|
|
713
|
+
return this.metadata.optional === !0 || m(this.metadata.type);
|
|
714
|
+
}
|
|
715
|
+
hasDefault() {
|
|
716
|
+
return this.metadata.default === !0;
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
function J(t) {
|
|
720
|
+
let n = H.get(t);
|
|
721
|
+
if (n) return _(n), n;
|
|
722
|
+
let r = Object.prototype.hasOwnProperty.call(t, "__tsfType") ? t.__tsfType : void 0;
|
|
723
|
+
if (!r) {
|
|
724
|
+
if (!X(t)) return;
|
|
725
|
+
let n = {
|
|
726
|
+
kind: e.class,
|
|
727
|
+
classType: t,
|
|
728
|
+
name: t.name,
|
|
729
|
+
typeName: t.name,
|
|
730
|
+
properties: [],
|
|
731
|
+
methods: [],
|
|
732
|
+
constructorParameters: [],
|
|
733
|
+
hasConstructor: !0
|
|
734
|
+
};
|
|
735
|
+
return W(n, U.get(t)), H.set(t, n), n;
|
|
736
|
+
}
|
|
737
|
+
return W(r, U.get(t)), _(r), H.set(t, r), r;
|
|
738
|
+
}
|
|
739
|
+
function Y(e, t) {
|
|
740
|
+
let n = X(e), r = n ? Y(n.classType, n.metadata) : [], i = new Set(t.properties.map((e) => e.name));
|
|
741
|
+
return [...r.filter((e) => !i.has(e.name)), ...t.properties];
|
|
742
|
+
}
|
|
743
|
+
function Me(e, t) {
|
|
744
|
+
let n = X(e), r = n ? Me(n.classType, n.metadata) : [], i = new Set(t.methods.map((e) => e.name));
|
|
745
|
+
return [...r.filter((e) => !i.has(e.name)), ...t.methods];
|
|
746
|
+
}
|
|
747
|
+
function Ne(e, t) {
|
|
748
|
+
if (t.constructorParameters.length || t.hasConstructor) return t.constructorParameters;
|
|
749
|
+
let n = X(e);
|
|
750
|
+
return n ? Ne(n.classType, n.metadata) : [];
|
|
751
|
+
}
|
|
752
|
+
function X(e) {
|
|
753
|
+
let t = (e.prototype ? Object.getPrototypeOf(e.prototype) : void 0)?.constructor;
|
|
754
|
+
if (!t || t === Object || t === e) return;
|
|
755
|
+
let n = J(t);
|
|
756
|
+
return n ? {
|
|
757
|
+
classType: t,
|
|
758
|
+
metadata: n
|
|
759
|
+
} : void 0;
|
|
760
|
+
}
|
|
761
|
+
//#endregion
|
|
762
|
+
//#region src/reflection/conversion.ts
|
|
763
|
+
var Pe = /* @__PURE__ */ new Map(), Z = {
|
|
764
|
+
register(e, t) {
|
|
765
|
+
Pe.set(e, t);
|
|
766
|
+
},
|
|
767
|
+
get(e) {
|
|
768
|
+
return Pe.get(e);
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
function Fe(e, t) {
|
|
772
|
+
let n = He(e, t);
|
|
773
|
+
return n ? Q(e, n) : [];
|
|
774
|
+
}
|
|
775
|
+
function Ie(e, t) {
|
|
776
|
+
if (!t) throw Error("deserialize<T>() was not transformed by the metadata compiler");
|
|
777
|
+
return _(t), $(e, t);
|
|
778
|
+
}
|
|
779
|
+
function Le(e, t, n, r, i) {
|
|
780
|
+
if (!i) throw Error("validatedDeserialize<T>() requires reflected type metadata");
|
|
781
|
+
_(i);
|
|
782
|
+
let a = $(e, i), o = Q(a, i);
|
|
783
|
+
if (o.length) throw o[0];
|
|
784
|
+
return a;
|
|
785
|
+
}
|
|
786
|
+
function Re(e, t, n) {
|
|
787
|
+
if (!n) throw Error("assert<T>() requires explicit reflected type metadata");
|
|
788
|
+
_(n);
|
|
789
|
+
let r = Q(e, n);
|
|
790
|
+
if (r.length) throw r[0];
|
|
791
|
+
}
|
|
792
|
+
function ze(e, t, n) {
|
|
793
|
+
if (!n) throw Error("is<T>() requires explicit reflected type metadata");
|
|
794
|
+
return _(n), Q(e, n).length === 0;
|
|
795
|
+
}
|
|
796
|
+
function Be(e, t, n, r, i) {
|
|
797
|
+
if (!i) throw Error("cast<T>() requires explicit reflected type metadata");
|
|
798
|
+
return _(i), $(e, i);
|
|
799
|
+
}
|
|
800
|
+
function Ve(e) {
|
|
801
|
+
if (t(e)) return e;
|
|
802
|
+
throw Error("Unsupported receive type payload");
|
|
803
|
+
}
|
|
804
|
+
function He(e, n) {
|
|
805
|
+
if (t(n)) return _(n), n;
|
|
806
|
+
if (typeof n == "function") return J(n);
|
|
807
|
+
if (e && typeof e == "object") return J(e.constructor);
|
|
808
|
+
}
|
|
809
|
+
function Q(t, r, i = "") {
|
|
810
|
+
let a = [], o = s(r), c = Oe(o);
|
|
811
|
+
if (t === void 0) return m(r) || a.push(new n("required", "The value is required.", i)), a;
|
|
812
|
+
if (t === null) return h(r) || a.push(new n("required", "The value cannot be null.", i)), a;
|
|
813
|
+
if (c === e.string) typeof t != "string" && a.push(new n("type", "The value must be a string.", i));
|
|
814
|
+
else if (c === e.number) (typeof t != "number" || Number.isNaN(t)) && a.push(new n("type", "The value must be a number.", i));
|
|
815
|
+
else if (c === e.boolean) typeof t != "boolean" && a.push(new n("type", "The value must be a boolean.", i));
|
|
816
|
+
else if (o.kind === e.undefined || o.kind === e.null || o.kind === e.never) a.push(new n("type", "The value does not match the required type.", i));
|
|
817
|
+
else if (o.kind === e.string || o.kind === e.templateLiteral) typeof t != "string" && a.push(new n("type", "The value must be a string.", i));
|
|
818
|
+
else if (o.kind === e.number) (typeof t != "number" || Number.isNaN(t)) && a.push(new n("type", "The value must be a number.", i));
|
|
819
|
+
else if (o.kind === e.boolean) typeof t != "boolean" && a.push(new n("type", "The value must be a boolean.", i));
|
|
820
|
+
else if (o.kind === e.array) Array.isArray(t) ? t.forEach((e, t) => {
|
|
821
|
+
a.push(...Q(e, o.type, M(i, String(t))));
|
|
822
|
+
}) : a.push(new n("type", "The value must be an array.", i));
|
|
823
|
+
else if (o.kind === e.tuple) Array.isArray(t) ? o.types.forEach((e, n) => {
|
|
824
|
+
a.push(...Q(t[n], e.type, M(i, String(n))));
|
|
825
|
+
}) : a.push(new n("type", "The value must be an array.", i));
|
|
826
|
+
else if (o.kind === e.union) {
|
|
827
|
+
let e = o.types.map((e) => Q(t, e, i));
|
|
828
|
+
if (!e.some((e) => e.length === 0)) {
|
|
829
|
+
let t = e.filter((e) => e.length > 0).sort((e, t) => e.length - t.length)[0];
|
|
830
|
+
t?.length ? a.push(...t) : a.push(new n("type", "The value does not match any allowed type.", i));
|
|
831
|
+
}
|
|
832
|
+
} else if (o.kind === e.objectLiteral) {
|
|
833
|
+
if (!t || typeof t != "object" || Array.isArray(t)) return a.push(new n("type", "The value must be an object.", i)), a;
|
|
834
|
+
let e = t, r = /* @__PURE__ */ new Set();
|
|
835
|
+
for (let t of d(o)) {
|
|
836
|
+
r.add(String(t.name));
|
|
837
|
+
let n = M(i, String(t.name));
|
|
838
|
+
e[t.name] === void 0 && t.optional || a.push(...Q(e[t.name], t.type, n));
|
|
839
|
+
}
|
|
840
|
+
let s = f(o);
|
|
841
|
+
if (s) for (let [t, n] of Object.entries(e)) r.has(t) || a.push(...Q(n, s, M(i, t)));
|
|
842
|
+
} else if (o.kind === e.literal) t !== o.literal && a.push(new n("type", `The value must be ${String(o.literal)}.`, i));
|
|
843
|
+
else if (o.kind === e.enum) o.values.includes(t) || a.push(new n("type", "The value does not match any allowed enum value.", i));
|
|
844
|
+
else if (o.kind === e.class) {
|
|
845
|
+
let e = g(o.classType);
|
|
846
|
+
if (!e) return (!t || typeof t != "object" || Array.isArray(t)) && a.push(new n("type", "The value must be an object.", i)), a;
|
|
847
|
+
if (e !== Date) {
|
|
848
|
+
let n = G.from(e), r = t;
|
|
849
|
+
for (let e of n.getProperties()) r[String(e.name)] === void 0 && e.isOptional() || a.push(...Q(r[String(e.name)], e.getType(), M(i, String(e.name))));
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
for (let e of ge.getAnnotations(r)) if (e.name === "minLength" && typeof t == "string") {
|
|
853
|
+
let r = A(e.args[0]);
|
|
854
|
+
r !== void 0 && t.length < r && a.push(new n("minLength", `The value must be at least ${r} characters.`, i));
|
|
855
|
+
} else if (e.name === "maxLength" && typeof t == "string") {
|
|
856
|
+
let r = A(e.args[0]);
|
|
857
|
+
r !== void 0 && t.length > r && a.push(new n("maxLength", `The value must be at most ${r} characters.`, i));
|
|
858
|
+
} else if (e.name === "minimum" && typeof t == "number") {
|
|
859
|
+
let r = A(e.args[0]);
|
|
860
|
+
r !== void 0 && t < r && a.push(new n("minimum", `The value must be at least ${r}.`, i));
|
|
861
|
+
} else if (e.name === "greaterThan" && typeof t == "number") {
|
|
862
|
+
let r = A(e.args[0]);
|
|
863
|
+
r !== void 0 && t <= r && a.push(new n("greaterThan", `The value must be greater than ${r}.`, i));
|
|
864
|
+
} else if (e.name === "maximum" && typeof t == "number") {
|
|
865
|
+
let r = A(e.args[0]);
|
|
866
|
+
r !== void 0 && t > r && a.push(new n("maximum", `The value must be at most ${r}.`, i));
|
|
867
|
+
} else if (e.name === "lessThan" && typeof t == "number") {
|
|
868
|
+
let r = A(e.args[0]);
|
|
869
|
+
r !== void 0 && t >= r && a.push(new n("lessThan", `The value must be less than ${r}.`, i));
|
|
870
|
+
} else if (e.name === "pattern" && typeof t == "string") {
|
|
871
|
+
let r = j(e.args[0]), o = typeof r == "string" ? new RegExp(r) : r instanceof RegExp ? r : void 0;
|
|
872
|
+
o && !o.test(t) && a.push(new n("pattern", "The value does not match the required pattern.", i));
|
|
873
|
+
} else if (e.name === "validate") {
|
|
874
|
+
let r = j(e.args[0]);
|
|
875
|
+
if (typeof r == "function") {
|
|
876
|
+
let e = r(t);
|
|
877
|
+
e instanceof n && a.push(new n(e.code, e.message, i));
|
|
878
|
+
}
|
|
879
|
+
} else if (e.name === "validator") {
|
|
880
|
+
let r = j(e.args[0]), o = typeof r == "string" ? Z.get(r) : void 0;
|
|
881
|
+
if (o) {
|
|
882
|
+
let e = o(t);
|
|
883
|
+
e instanceof n && a.push(new n(e.code, e.message, i));
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return a;
|
|
887
|
+
}
|
|
888
|
+
function $(t, n) {
|
|
889
|
+
if (t == null) return t;
|
|
890
|
+
if (n.kind === e.intersection) {
|
|
891
|
+
let e = c(n);
|
|
892
|
+
if (e && t && typeof t == "object" && !Array.isArray(t) && !(t instanceof Date)) return a.apply(n, $(t, e));
|
|
893
|
+
let r = t;
|
|
894
|
+
if (t && typeof t == "object" && !Array.isArray(t) && !(t instanceof Date)) {
|
|
895
|
+
let e = {}, i = !1;
|
|
896
|
+
for (let r of n.types) {
|
|
897
|
+
let n = $(t, r);
|
|
898
|
+
n && typeof n == "object" && !Array.isArray(n) && !(n instanceof Date) && (Object.assign(e, n), i = !0);
|
|
899
|
+
}
|
|
900
|
+
r = i ? e : t;
|
|
901
|
+
} else for (let e of n.types) r = $(r, e);
|
|
902
|
+
return a.apply(n, r);
|
|
903
|
+
}
|
|
904
|
+
let r = s(n), i = t;
|
|
905
|
+
if (r.kind === e.number && typeof t == "string" && t.trim() !== "") i = Number(t);
|
|
906
|
+
else if (r.kind === e.boolean) i = o(t);
|
|
907
|
+
else if (r.kind === e.enum && typeof t == "string") {
|
|
908
|
+
let e = Number(t);
|
|
909
|
+
!Number.isNaN(e) && r.values.includes(e) && (i = e);
|
|
910
|
+
} else if (r.kind === e.array && Array.isArray(t)) i = t.map((e) => $(e, r.type));
|
|
911
|
+
else if (r.kind === e.tuple && Array.isArray(t)) i = r.types.map((e, n) => $(t[n], e.type));
|
|
912
|
+
else if (r.kind === e.union) for (let e of r.types) {
|
|
913
|
+
let n = $(t, e);
|
|
914
|
+
if (Q(n, e).length === 0) {
|
|
915
|
+
i = n;
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
else if (r.kind === e.class) {
|
|
920
|
+
let e = g(r.classType);
|
|
921
|
+
if (!e) return a.apply(n, t);
|
|
922
|
+
if (e === Date) return a.apply(n, t instanceof Date ? t : new Date(t));
|
|
923
|
+
if (typeof t != "object") return a.apply(n, t);
|
|
924
|
+
let o = new e(), s = t;
|
|
925
|
+
for (let t of G.from(e).getProperties()) o[String(t.name)] = $(s[String(t.name)], t.getType());
|
|
926
|
+
i = o;
|
|
927
|
+
} else if (r.kind === e.objectLiteral && typeof t == "object") {
|
|
928
|
+
let e = d(r), o = f(r);
|
|
929
|
+
if (e.length === 0 && !o) return a.apply(n, t);
|
|
930
|
+
let s = t, c = {}, l = /* @__PURE__ */ new Set();
|
|
931
|
+
for (let t of e) {
|
|
932
|
+
let e = String(t.name);
|
|
933
|
+
l.add(e), c[e] = $(s[e], t.type);
|
|
934
|
+
}
|
|
935
|
+
if (o) for (let [e, t] of Object.entries(s)) l.has(e) || (c[e] = $(t, o));
|
|
936
|
+
i = c;
|
|
937
|
+
}
|
|
938
|
+
return a.apply(n, i);
|
|
939
|
+
}
|
|
940
|
+
//#endregion
|
|
941
|
+
//#region src/types/type-annotations.ts
|
|
942
|
+
var Ue = class {
|
|
943
|
+
x;
|
|
944
|
+
y;
|
|
945
|
+
};
|
|
946
|
+
function We(e) {
|
|
947
|
+
if (!(e instanceof Date) || Number.isNaN(e.getTime())) return new n("invalidDate", "The date is invalid.");
|
|
948
|
+
}
|
|
949
|
+
Z.register("validDate", We);
|
|
950
|
+
function Ge(e, ...t) {
|
|
951
|
+
for (let n of t) {
|
|
952
|
+
let t = N.getType(e, n);
|
|
953
|
+
if (t) return t;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
a.addDecorator((e) => Ge(e, "tsf:trim") !== void 0, (e, t) => {
|
|
957
|
+
t.addTransform((e) => typeof e == "string" ? e.trim() : e);
|
|
958
|
+
});
|
|
959
|
+
var Ke = /^[a-z0-9_+.-]+@[a-z0-9-.]+\.[a-z]+$/i;
|
|
960
|
+
//#endregion
|
|
961
|
+
//#region src/types/runtime.ts
|
|
962
|
+
function qe(e) {
|
|
963
|
+
return typeof e == "function" ? e.name || "anonymous class" : e && typeof e == "object" ? e.constructor?.name || "anonymous class" : String(e);
|
|
964
|
+
}
|
|
965
|
+
//#endregion
|
|
966
|
+
export { Ue as Coordinate, r as DeserializerRegistry, i as DeserializerState, Ke as EMAIL_REGEX, G as ReflectionClass, e as ReflectionKind, q as ReflectionMethod, je as ReflectionParameter, K as ReflectionProperty, n as ValidationError, n as ValidatorError, h as allowsNull, m as allowsUndefined, W as applyMetadataOptions, Re as assert, Be as cast, H as classMetadata, U as classOptions, T as cloneUtilityProperty, o as coerceBooleanValue, P as databaseAnnotation, Ie as deserialize, a as deserializer, ce as expandUtilityTypeMetadata, fe as findNested, k as findNestedSurface, y as flattenRuntimeUnionTypes, qe as getClassName, Ge as getFirstTypeAnnotation, de as getUtilityTypeName, pe as hasNestedType, ze as is, v as isClass, he as isDatabaseUUIDType, b as isExtractAssignable, p as isMarkerType, t as isReflectedType, me as isUUIDType, E as isUtilityTypeName, M as joinPath, Oe as knownPrimitiveKind, S as literalMatchesType, A as literalNumber, u as mergeStructuredProperties, w as mergeUtilityProperties, c as mergedIntersectionObjectLiteral, _ as normalizeTypeMetadata, f as objectLiteralIndexType, d as objectLiteralPropertiesFromType, J as readClassMetadata, ue as recordLiteralKeysFromType, le as recordPropertiesFromKeyType, Ae as registerClassMetadata, re as resolveClassType, Ve as resolveReceiveType, j as resolveRuntimeValue, g as tryResolveClassType, N as typeAnnotation, ke as typeOf, x as typesOverlap, s as unwrapValueType, C as utilitySourcePropertiesFromType, Fe as validate, Le as validatedDeserialize, ge as validationAnnotation, Z as validationRegistry, D as visitType, O as visitTypeSurface };
|