xml-model 1.3.0 → 1.3.1

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.
Files changed (39) hide show
  1. package/dist/index.js +2 -42
  2. package/dist/model/index.js +1 -2
  3. package/dist/model/property.js +1 -2
  4. package/package.json +3 -3
  5. package/vite/dist/node_modules/typescript-rtti/dist.esm/common/format.js +2 -0
  6. package/vite/dist/node_modules/typescript-rtti/dist.esm/common/index.js +2 -0
  7. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/api-call-transformer.js +2 -0
  8. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/class-analyzer.js +2 -0
  9. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/compile-error.js +2 -0
  10. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/import-analyzer.js +2 -0
  11. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/interface-analyzer.js +2 -0
  12. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/visitor-base.js +2 -0
  13. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/declarations-emitter.js +2 -0
  14. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/encode-parameter.js +2 -0
  15. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/find-relative-path.js +2 -0
  16. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/flags.js +2 -0
  17. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/forward-ref.js +2 -0
  18. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/get-exports-for-symbol.js +2 -0
  19. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/index.js +2 -0
  20. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/legacy-decorator.js +2 -0
  21. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/legacy-type-encoder.js +2 -0
  22. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/literal-node.js +2 -0
  23. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-collector.js +2 -0
  24. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-decorator.js +2 -0
  25. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-emitter.js +2 -0
  26. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-encoder.js +2 -0
  27. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/rt-helper.js +2 -0
  28. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/rtti-visitor-base.js +2 -0
  29. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/serialize.js +2 -0
  30. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/type-encoder.js +2 -0
  31. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/type-literal.js +3 -1
  32. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/utils.js +4 -2
  33. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/workarounds.js +2 -0
  34. package/dist/node_modules/typescript-rtti/dist.esm/common/format.js +0 -106
  35. package/dist/node_modules/typescript-rtti/dist.esm/index.js +0 -2
  36. package/dist/node_modules/typescript-rtti/dist.esm/lib/get-parameter-names.js +0 -15
  37. package/dist/node_modules/typescript-rtti/dist.esm/lib/index.js +0 -43
  38. package/dist/node_modules/typescript-rtti/dist.esm/lib/reflect.js +0 -2225
  39. package/dist/node_modules/typescript-rtti/dist.esm/lib/sealed.js +0 -13
@@ -1,2225 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
4
- import { T_FUNCTION, T_OBJECT, T_TRUE, T_FALSE, T_ENUM, T_MAPPED, T_UNDEFINED, T_NULL, T_VOID, T_GENERIC, T_ARRAY, T_TUPLE, T_INTERSECTION, T_UNION, T_ANY, T_UNKNOWN, F_READONLY, F_ABSTRACT, F_PUBLIC, F_PRIVATE, F_PROTECTED, F_PROPERTY, F_METHOD, F_CLASS, F_INTERFACE, F_OPTIONAL, F_REST, F_ASYNC, F_EXPORTED, F_INFERRED, F_OMITTED, F_ARRAY_BINDING, F_OBJECT_BINDING, F_FUNCTION } from "../common/format.js";
5
- import { getParameterNames } from "./get-parameter-names.js";
6
- import { Sealed } from "./sealed.js";
7
- var __decorate = function(decorators, target, key, desc) {
8
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11
- return c > 3 && r && Object.defineProperty(target, key, r), r;
12
- };
13
- var __metadata = function(k, v) {
14
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
15
- };
16
- var ReflectedClass_1;
17
- const NotProvided = /* @__PURE__ */ Symbol();
18
- function reify(callSite) {
19
- if (!isCallSite(callSite))
20
- throw new Error(`reify<T>() can only be used when project is built with the typescript-rtti transformer`);
21
- let param = reflect(callSite).typeParameters[0];
22
- if (param.is("interface"))
23
- return param.token;
24
- throw new Error(`reify<${param}>(): Type parameter must be an interface reference, not an arbitrary type`);
25
- }
26
- __name(reify, "reify");
27
- function isCallSite(callSite) {
28
- return (callSite === null || callSite === void 0 ? void 0 : callSite.TΦ) === "c";
29
- }
30
- __name(isCallSite, "isCallSite");
31
- function Flag(value) {
32
- return (target, propertyKey) => {
33
- if (!target.flagToProperty)
34
- target.flagToProperty = {};
35
- if (!target.propertyToFlag)
36
- target.propertyToFlag = {};
37
- target.flagToProperty[value] = propertyKey;
38
- target.propertyToFlag[propertyKey] = value;
39
- };
40
- }
41
- __name(Flag, "Flag");
42
- const TYPE_REF_KIND_EXPANSION = {
43
- [T_UNKNOWN]: "unknown",
44
- [T_ANY]: "any",
45
- [T_UNION]: "union",
46
- [T_INTERSECTION]: "intersection",
47
- [T_TUPLE]: "tuple",
48
- [T_ARRAY]: "array",
49
- [T_GENERIC]: "generic",
50
- [T_VOID]: "void",
51
- [T_NULL]: "null",
52
- [T_UNDEFINED]: "undefined",
53
- [T_MAPPED]: "mapped",
54
- [T_ENUM]: "enum",
55
- [T_FALSE]: "false",
56
- [T_TRUE]: "true",
57
- [T_OBJECT]: "object",
58
- [T_FUNCTION]: "function"
59
- };
60
- const _ReflectedTypeRef = class _ReflectedTypeRef {
61
- /** @internal */
62
- constructor(_ref) {
63
- this._ref = _ref;
64
- }
65
- toString() {
66
- return `[${this.kind} type]`;
67
- }
68
- /** @internal */
69
- static Kind(kind) {
70
- return (target) => {
71
- _ReflectedTypeRef.kinds[kind] = target;
72
- };
73
- }
74
- /**
75
- * Check if the given value matches this type reference. Collects any errors into the `errors` list.
76
- * @param value
77
- * @param errors
78
- * @param context
79
- * @returns
80
- */
81
- matchesValue(value, options) {
82
- var _a2;
83
- options !== null && options !== void 0 ? options : options = {};
84
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
85
- options.errors.push(new Error(`No validation available for type with kind '${this.kind}'`));
86
- return false;
87
- }
88
- /**
89
- * Check if the given type reference is equivalent to this type reference.
90
- * @param ref
91
- * @returns
92
- */
93
- equals(ref) {
94
- if (this === ref)
95
- return true;
96
- if (ref.constructor !== this.constructor)
97
- return false;
98
- return this.matches(ref);
99
- }
100
- matches(ref) {
101
- return true;
102
- }
103
- get kind() {
104
- let ref = this._ref;
105
- if (ref === null || ["string", "number", "bigint"].includes(typeof ref))
106
- return "literal";
107
- if (typeof ref === "object" && "TΦ" in ref)
108
- return TYPE_REF_KIND_EXPANSION[ref.TΦ];
109
- if (typeof ref === "object")
110
- return "interface";
111
- return "class";
112
- }
113
- /** @internal */
114
- get ref() {
115
- return this._ref;
116
- }
117
- /**
118
- * Checks if this type reference is a Promise, optionally a Promise of a specific type.
119
- * If the type reference does not specify a type of Promise but you have provided a type
120
- * to check for, this will return false.
121
- * @param klass The type of promise to check for. Would be String when looking for Promise<string>
122
- */
123
- isPromise(klass) {
124
- if (this.isClass(Promise))
125
- return !klass;
126
- if (this.isGeneric(Promise)) {
127
- if (klass)
128
- return this.typeParameters.length > 0 && this.typeParameters[0].isClass(klass);
129
- return true;
130
- }
131
- return false;
132
- }
133
- /**
134
- * Checks if this type reference is a class. Note: If the class reference has type parameters,
135
- * (ie it is generic) this check will fail, and instead isGeneric() will succeed.
136
- * @param klass
137
- */
138
- isClass(klass) {
139
- let literalTypes = {
140
- "string": String,
141
- "number": Number,
142
- "boolean": Boolean,
143
- "object": Object,
144
- "bigint": BigInt
145
- };
146
- if (this.kind === "function" && klass === Function)
147
- return true;
148
- if (this.kind === "literal")
149
- return literalTypes[typeof this.ref] === klass;
150
- if (this.kind === "null")
151
- return Object === klass;
152
- if (["true", "false"].includes(this.kind))
153
- return Boolean === klass;
154
- return this.kind === "class" && (!klass || this.ref === klass);
155
- }
156
- isInterface(interfaceType) {
157
- if (interfaceType)
158
- return this.isInterface() && this.ref.identity === interfaceType.identity;
159
- else
160
- return this.kind === "interface";
161
- }
162
- isLiteral(value = NotProvided) {
163
- if (value === null)
164
- return this.isNull();
165
- if (value === true)
166
- return this.isTrue();
167
- if (value === false)
168
- return this.isFalse();
169
- return this.kind === "literal" && (value === NotProvided || this.ref === value);
170
- }
171
- is(kind) {
172
- if (typeof kind === "function")
173
- return this instanceof kind;
174
- else if (typeof kind === "string")
175
- return this.kind === kind;
176
- }
177
- as(subclass) {
178
- if (typeof subclass === "function" && !(this instanceof subclass))
179
- throw new TypeError(`Value of type ${this.constructor.name} cannot be converted to ${subclass.name}`);
180
- else if (typeof subclass === "string" && this.kind !== subclass)
181
- throw new TypeError(`Type has kind ${this.kind}, expected ${subclass}`);
182
- return this;
183
- }
184
- isVoid() {
185
- return this.kind === "void";
186
- }
187
- isNull() {
188
- return this.kind === "null";
189
- }
190
- isUndefined() {
191
- return this.kind === "undefined";
192
- }
193
- isTrue() {
194
- return this.kind === "true";
195
- }
196
- isFalse() {
197
- return this.kind === "false";
198
- }
199
- isStringLiteral() {
200
- return this.kind === "literal" && typeof this.ref === "string";
201
- }
202
- isNumberLiteral() {
203
- return this.kind === "literal" && typeof this.ref === "number";
204
- }
205
- isBigIntLiteral() {
206
- return this.kind === "literal" && typeof this.ref === "bigint";
207
- }
208
- isBooleanLiteral() {
209
- return this.isTrue() || this.isFalse();
210
- }
211
- /**
212
- * Check if this type reference is a generic type, optionally checking if the generic's
213
- * base type is the given class. For instance isGeneric(Promise) is true for Promise<string>.
214
- * @param klass
215
- */
216
- isGeneric(klass) {
217
- if (this.kind === "generic") {
218
- let rtGeneric = this.ref;
219
- if (!rtGeneric.t["TΦ"]) {
220
- return !klass || rtGeneric.t === klass;
221
- }
222
- return true;
223
- }
224
- return false;
225
- }
226
- isUnion(elementDiscriminator) {
227
- return elementDiscriminator ? this.isUnion() && this.types.every((e) => elementDiscriminator(e)) : this.kind === "union";
228
- }
229
- isIntersection(elementDiscriminator) {
230
- return elementDiscriminator ? this.isIntersection() && this.types.every((e) => elementDiscriminator(e)) : this.kind === "intersection";
231
- }
232
- isArray(elementDiscriminator) {
233
- return elementDiscriminator ? this.isArray() && elementDiscriminator(this.elementType) : this.kind === "array";
234
- }
235
- isTuple(elementDiscriminators) {
236
- return elementDiscriminators ? this.isTuple() && this.elements.every((e, i) => elementDiscriminators[i](e)) : this.kind === "tuple";
237
- }
238
- isUnknown() {
239
- return this.kind === "unknown";
240
- }
241
- isAny() {
242
- return this.kind === "any";
243
- }
244
- /**
245
- * Creates an "unknown"
246
- * @internal
247
- */
248
- static createUnknown() {
249
- return this.createFromRtRef({ TΦ: T_UNKNOWN });
250
- }
251
- /** @internal */
252
- static createFromRtRef(ref) {
253
- let kind;
254
- if (ref === null || !["object", "function"].includes(typeof ref))
255
- kind = "literal";
256
- else if (typeof ref === "object" && "TΦ" in ref)
257
- kind = TYPE_REF_KIND_EXPANSION[ref.TΦ];
258
- else if (typeof ref === "object")
259
- kind = "interface";
260
- else
261
- kind = "class";
262
- return new (_ReflectedTypeRef.kinds[kind] || _ReflectedTypeRef)(ref);
263
- }
264
- };
265
- __name(_ReflectedTypeRef, "ReflectedTypeRef");
266
- let ReflectedTypeRef = _ReflectedTypeRef;
267
- ReflectedTypeRef.kinds = {};
268
- let ReflectedClassRef = (_a = class extends ReflectedTypeRef {
269
- get kind() {
270
- return "class";
271
- }
272
- get class() {
273
- return this.ref;
274
- }
275
- get reflectedClass() {
276
- return ReflectedClass.for(this.class);
277
- }
278
- toString() {
279
- return `class ${this.class.name}`;
280
- }
281
- matches(ref) {
282
- return this.class === ref.class;
283
- }
284
- matchesValue(value, options) {
285
- var _a2;
286
- options !== null && options !== void 0 ? options : options = {};
287
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
288
- if (this.ref === String)
289
- return typeof value === "string";
290
- else if (this.ref === Number)
291
- return typeof value === "number";
292
- else if (this.ref === Boolean)
293
- return typeof value === "boolean";
294
- else if (this.ref === Object)
295
- return typeof value === "object";
296
- else if (this.ref === Function)
297
- return typeof value === "function";
298
- else if (this.ref === Symbol)
299
- return typeof value === "symbol";
300
- else if (this.ref === BigInt)
301
- return typeof value === "bigint";
302
- return ReflectedClass.for(this.ref).matchesValue(value, options);
303
- }
304
- }, __name(_a, "ReflectedClassRef"), _a);
305
- ReflectedClassRef = __decorate([
306
- ReflectedTypeRef.Kind("class")
307
- ], ReflectedClassRef);
308
- const _ReflectedObjectMember = class _ReflectedObjectMember {
309
- constructor(ref) {
310
- this.ref = ref;
311
- this.name = ref.n;
312
- this.type = ReflectedTypeRef.createFromRtRef(this.ref.t);
313
- }
314
- get flags() {
315
- if (!this._flags)
316
- this._flags = new ReflectedFlags(this.ref.f);
317
- return this._flags;
318
- }
319
- get isOptional() {
320
- return this.flags.isOptional;
321
- }
322
- equals(member) {
323
- return this.name === member.name && this.type.equals(member.type);
324
- }
325
- toString() {
326
- var _a2, _b2;
327
- return `${this.name}: ${(_b2 = (_a2 = this.type) === null || _a2 === void 0 ? void 0 : _a2.toString()) !== null && _b2 !== void 0 ? _b2 : "<error>"}`;
328
- }
329
- };
330
- __name(_ReflectedObjectMember, "ReflectedObjectMember");
331
- let ReflectedObjectMember = _ReflectedObjectMember;
332
- let ReflectedObjectRef = (_b = class extends ReflectedTypeRef {
333
- get kind() {
334
- return "object";
335
- }
336
- get members() {
337
- if (!this._members)
338
- this._members = this.ref.m.map((m) => new ReflectedObjectMember(m));
339
- return this._members;
340
- }
341
- toString() {
342
- return `{ ${this.members.map((m) => m.toString()).join(", ")} }`;
343
- }
344
- matches(ref) {
345
- if (this.members.length !== ref.members.length)
346
- return false;
347
- for (let member of this.members) {
348
- let matchingMember = ref.members.find((x) => x.name);
349
- if (!member.equals(matchingMember))
350
- return false;
351
- }
352
- return true;
353
- }
354
- matchesValue(value, options) {
355
- var _a2;
356
- options !== null && options !== void 0 ? options : options = {};
357
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
358
- if (typeof value !== "object")
359
- return false;
360
- let matches = true;
361
- for (let member of this.members) {
362
- let hasValue = member.name in value;
363
- if (!hasValue) {
364
- if (!member.isOptional) {
365
- options.errors.push(new TypeError(`Missing value for member ${member.toString()}`));
366
- matches = false;
367
- }
368
- continue;
369
- }
370
- let memberValue = value[member.name];
371
- let memberErrors = [];
372
- if (!member.type.matchesValue(memberValue, Object.assign(Object.assign({}, options), { errors: memberErrors }))) {
373
- options.errors.push(new TypeError(`Value for member ${member.toString()} is invalid`));
374
- options.errors.push(...memberErrors);
375
- matches = false;
376
- }
377
- }
378
- let unaccountedProperties = Object.keys(value).filter((x) => !this.members.some((y) => y.name === x));
379
- if (options.allowExtraProperties !== true && unaccountedProperties.length > 0) {
380
- options.errors.push(new Error(`Object contains the following undeclared properties: ${unaccountedProperties.join(", ")}`));
381
- matches = false;
382
- }
383
- return matches;
384
- }
385
- }, __name(_b, "ReflectedObjectRef"), _b);
386
- ReflectedObjectRef = __decorate([
387
- ReflectedTypeRef.Kind("object")
388
- ], ReflectedObjectRef);
389
- let ReflectedInterfaceRef = (_c = class extends ReflectedTypeRef {
390
- get kind() {
391
- return "interface";
392
- }
393
- get token() {
394
- return this.ref;
395
- }
396
- get reflectedInterface() {
397
- return ReflectedClass.for(this.token);
398
- }
399
- toString() {
400
- return `interface ${this.token.name}`;
401
- }
402
- matches(ref) {
403
- return this.token === ref.token;
404
- }
405
- matchesValue(value, options) {
406
- var _a2;
407
- options !== null && options !== void 0 ? options : options = {};
408
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
409
- return ReflectedClass.for(this.ref).matchesValue(value);
410
- }
411
- }, __name(_c, "ReflectedInterfaceRef"), _c);
412
- ReflectedInterfaceRef = __decorate([
413
- ReflectedTypeRef.Kind("interface")
414
- ], ReflectedInterfaceRef);
415
- let ReflectedLiteralRef = (_d = class extends ReflectedTypeRef {
416
- get kind() {
417
- return "literal";
418
- }
419
- get value() {
420
- return this.ref;
421
- }
422
- toString() {
423
- return JSON.stringify(this.value);
424
- }
425
- matches(ref) {
426
- return this.value === ref.value;
427
- }
428
- matchesValue(value, options) {
429
- var _a2;
430
- options !== null && options !== void 0 ? options : options = {};
431
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
432
- return this.ref === value;
433
- }
434
- }, __name(_d, "ReflectedLiteralRef"), _d);
435
- ReflectedLiteralRef = __decorate([
436
- ReflectedTypeRef.Kind("literal")
437
- ], ReflectedLiteralRef);
438
- let ReflectedUnionRef = (_e = class extends ReflectedTypeRef {
439
- get kind() {
440
- return "union";
441
- }
442
- toString() {
443
- return `[${this.types.join(" | ")}]`;
444
- }
445
- get types() {
446
- if (this._types)
447
- return this._types;
448
- return this._types = (this.ref.t || []).map((t) => ReflectedTypeRef.createFromRtRef(t));
449
- }
450
- matches(ref) {
451
- if (this.types.length !== ref.types.length)
452
- return false;
453
- for (let type of this.types) {
454
- if (!ref.types.some((x) => type.equals(x)))
455
- return false;
456
- }
457
- return true;
458
- }
459
- matchesValue(value, options) {
460
- var _a2;
461
- options !== null && options !== void 0 ? options : options = {};
462
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
463
- return this.types.some((t) => t.matchesValue(value, options));
464
- }
465
- }, __name(_e, "ReflectedUnionRef"), _e);
466
- ReflectedUnionRef = __decorate([
467
- ReflectedTypeRef.Kind("union")
468
- ], ReflectedUnionRef);
469
- let ReflectedIntersectionRef = (_f = class extends ReflectedTypeRef {
470
- get kind() {
471
- return "intersection";
472
- }
473
- toString() {
474
- return `${this.types.join(" & ")}`;
475
- }
476
- get types() {
477
- if (this._types)
478
- return this._types;
479
- return this._types = (this.ref.t || []).map((t) => ReflectedTypeRef.createFromRtRef(t));
480
- }
481
- matches(ref) {
482
- if (this.types.length !== ref.types.length)
483
- return false;
484
- for (let type of this.types) {
485
- if (!ref.types.some((x) => type.equals(x)))
486
- return false;
487
- }
488
- return true;
489
- }
490
- matchesValue(value, options) {
491
- var _a2;
492
- options !== null && options !== void 0 ? options : options = {};
493
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
494
- return this.types.every((t) => t.matchesValue(value, options));
495
- }
496
- }, __name(_f, "ReflectedIntersectionRef"), _f);
497
- ReflectedIntersectionRef = __decorate([
498
- ReflectedTypeRef.Kind("intersection")
499
- ], ReflectedIntersectionRef);
500
- let ReflectedArrayRef = (_g = class extends ReflectedTypeRef {
501
- get kind() {
502
- return "array";
503
- }
504
- toString() {
505
- return `${this.elementType}[]`;
506
- }
507
- get elementType() {
508
- if (this._elementType)
509
- return this._elementType;
510
- return this._elementType = ReflectedTypeRef.createFromRtRef(this.ref.e);
511
- }
512
- matches(ref) {
513
- return this.elementType.equals(ref.elementType);
514
- }
515
- matchesValue(value, options) {
516
- var _a2;
517
- options !== null && options !== void 0 ? options : options = {};
518
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
519
- if (!Array.isArray(value)) {
520
- options.errors.push(new TypeError(`Value should be an array`));
521
- return false;
522
- }
523
- return value.every((value2) => this.elementType.matchesValue(value2, options));
524
- }
525
- }, __name(_g, "ReflectedArrayRef"), _g);
526
- ReflectedArrayRef = __decorate([
527
- ReflectedTypeRef.Kind("array")
528
- ], ReflectedArrayRef);
529
- let ReflectedVoidRef = (_h = class extends ReflectedTypeRef {
530
- get kind() {
531
- return "void";
532
- }
533
- toString() {
534
- return `void`;
535
- }
536
- matchesValue(value, options) {
537
- var _a2;
538
- options !== null && options !== void 0 ? options : options = {};
539
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
540
- if (value !== void 0) {
541
- options.errors.push(new Error(`Value must not be present`));
542
- return false;
543
- }
544
- return true;
545
- }
546
- }, __name(_h, "ReflectedVoidRef"), _h);
547
- ReflectedVoidRef = __decorate([
548
- ReflectedTypeRef.Kind("void")
549
- ], ReflectedVoidRef);
550
- let ReflectedNullRef = (_i = class extends ReflectedTypeRef {
551
- get kind() {
552
- return "null";
553
- }
554
- toString() {
555
- return `null`;
556
- }
557
- matchesValue(value, options) {
558
- var _a2;
559
- options !== null && options !== void 0 ? options : options = {};
560
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
561
- return value === null;
562
- }
563
- }, __name(_i, "ReflectedNullRef"), _i);
564
- ReflectedNullRef = __decorate([
565
- ReflectedTypeRef.Kind("null")
566
- ], ReflectedNullRef);
567
- let ReflectedUndefinedRef = (_j = class extends ReflectedTypeRef {
568
- get kind() {
569
- return "undefined";
570
- }
571
- toString() {
572
- return `undefined`;
573
- }
574
- matchesValue(value, options) {
575
- var _a2;
576
- options !== null && options !== void 0 ? options : options = {};
577
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
578
- return value === void 0;
579
- }
580
- }, __name(_j, "ReflectedUndefinedRef"), _j);
581
- ReflectedUndefinedRef = __decorate([
582
- ReflectedTypeRef.Kind("undefined")
583
- ], ReflectedUndefinedRef);
584
- let ReflectedFalseRef = (_k = class extends ReflectedTypeRef {
585
- get kind() {
586
- return "false";
587
- }
588
- toString() {
589
- return `false`;
590
- }
591
- matchesValue(value, options) {
592
- var _a2;
593
- options !== null && options !== void 0 ? options : options = {};
594
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
595
- return value === false;
596
- }
597
- }, __name(_k, "ReflectedFalseRef"), _k);
598
- ReflectedFalseRef = __decorate([
599
- ReflectedTypeRef.Kind("false")
600
- ], ReflectedFalseRef);
601
- let ReflectedTrueRef = (_l = class extends ReflectedTypeRef {
602
- get kind() {
603
- return "true";
604
- }
605
- toString() {
606
- return `true`;
607
- }
608
- matchesValue(value, options) {
609
- var _a2;
610
- options !== null && options !== void 0 ? options : options = {};
611
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
612
- return value === true;
613
- }
614
- }, __name(_l, "ReflectedTrueRef"), _l);
615
- ReflectedTrueRef = __decorate([
616
- ReflectedTypeRef.Kind("true")
617
- ], ReflectedTrueRef);
618
- let ReflectedUnknownRef = (_m = class extends ReflectedTypeRef {
619
- get kind() {
620
- return "unknown";
621
- }
622
- toString() {
623
- return `unknown`;
624
- }
625
- matchesValue(value, options) {
626
- var _a2;
627
- options !== null && options !== void 0 ? options : options = {};
628
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
629
- return true;
630
- }
631
- }, __name(_m, "ReflectedUnknownRef"), _m);
632
- ReflectedUnknownRef = __decorate([
633
- ReflectedTypeRef.Kind("unknown")
634
- ], ReflectedUnknownRef);
635
- let ReflectedAnyRef = (_n = class extends ReflectedTypeRef {
636
- get kind() {
637
- return "any";
638
- }
639
- toString() {
640
- return `any`;
641
- }
642
- matchesValue(value, options) {
643
- var _a2;
644
- options !== null && options !== void 0 ? options : options = {};
645
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
646
- return true;
647
- }
648
- }, __name(_n, "ReflectedAnyRef"), _n);
649
- ReflectedAnyRef = __decorate([
650
- ReflectedTypeRef.Kind("any")
651
- ], ReflectedAnyRef);
652
- let ReflectedTupleRef = (_o = class extends ReflectedTypeRef {
653
- get kind() {
654
- return "tuple";
655
- }
656
- toString() {
657
- return `[${this.elements.join(", ")}]`;
658
- }
659
- get elements() {
660
- if (this._elements)
661
- return this._elements;
662
- return this._elements = (this.ref.e || []).map((e) => new ReflectedTupleElement(e));
663
- }
664
- matches(ref) {
665
- if (this.elements.length !== ref.elements.length)
666
- return false;
667
- return this.elements.every((x, i) => x.name === ref.elements[i].name && x.type.equals(ref.elements[i].type));
668
- }
669
- matchesValue(value, options) {
670
- var _a2;
671
- options !== null && options !== void 0 ? options : options = {};
672
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
673
- if (!Array.isArray(value)) {
674
- options.errors.push(new Error(`Value must be an array`));
675
- return false;
676
- }
677
- let array = value;
678
- if (array.length !== this.elements.length) {
679
- options.errors.push(new Error(`Array must have ${this.elements.length} values to match tuple type`));
680
- return false;
681
- }
682
- return this.elements.every((v, i) => v.type.matchesValue(array[i], options));
683
- }
684
- }, __name(_o, "ReflectedTupleRef"), _o);
685
- ReflectedTupleRef = __decorate([
686
- ReflectedTypeRef.Kind("tuple")
687
- ], ReflectedTupleRef);
688
- let ReflectedGenericRef = (_p = class extends ReflectedTypeRef {
689
- get kind() {
690
- return "generic";
691
- }
692
- toString() {
693
- return `${this.baseType}<${this.typeParameters.join(", ")}>`;
694
- }
695
- get baseType() {
696
- if (this._baseType)
697
- return this._baseType;
698
- return this._baseType = ReflectedTypeRef.createFromRtRef(this.ref.t);
699
- }
700
- get typeParameters() {
701
- if (this._typeParameters)
702
- return this._typeParameters;
703
- return this._typeParameters = this.ref.p.map((p) => ReflectedTypeRef.createFromRtRef(p));
704
- }
705
- matches(ref) {
706
- if (this.typeParameters.length !== ref.typeParameters.length)
707
- return false;
708
- return this.typeParameters.every((x, i) => x.equals(ref.typeParameters[i]));
709
- }
710
- matchesValue(value, options) {
711
- var _a2;
712
- options !== null && options !== void 0 ? options : options = {};
713
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
714
- return this.baseType.matchesValue(value, options);
715
- }
716
- }, __name(_p, "ReflectedGenericRef"), _p);
717
- ReflectedGenericRef = __decorate([
718
- ReflectedTypeRef.Kind("generic")
719
- ], ReflectedGenericRef);
720
- let ReflectedEnumRef = (_q = class extends ReflectedTypeRef {
721
- get kind() {
722
- return "enum";
723
- }
724
- toString() {
725
- return `enum`;
726
- }
727
- // TODO: name of enum?
728
- get enum() {
729
- if (!this._enum)
730
- this._enum = this.ref.e;
731
- return this._enum;
732
- }
733
- get name() {
734
- if (!this._name)
735
- this._name = this.ref.n;
736
- return this._name;
737
- }
738
- get values() {
739
- if (!this._values) {
740
- this._values = Object.keys(this.enum).filter((x) => !/^\d+$/.test(x)).map((name) => ({ name, value: this.enum[name] }));
741
- }
742
- return this._values;
743
- }
744
- matches(ref) {
745
- return this.enum === ref.enum;
746
- }
747
- matchesValue(value, options) {
748
- var _a2;
749
- options !== null && options !== void 0 ? options : options = {};
750
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
751
- return value in this.enum;
752
- }
753
- }, __name(_q, "ReflectedEnumRef"), _q);
754
- ReflectedEnumRef = __decorate([
755
- ReflectedTypeRef.Kind("enum")
756
- ], ReflectedEnumRef);
757
- let ReflectedFunctionRef = (_r = class extends ReflectedTypeRef {
758
- get kind() {
759
- return "function";
760
- }
761
- toString() {
762
- return `function`;
763
- }
764
- // TODO: details
765
- get returnType() {
766
- var _a2;
767
- return (_a2 = this._returnType) !== null && _a2 !== void 0 ? _a2 : this._returnType = ReflectedTypeRef.createFromRtRef(this.ref.r);
768
- }
769
- get parameters() {
770
- var _a2, _b2;
771
- return (_a2 = this._parameters) !== null && _a2 !== void 0 ? _a2 : this._parameters = ((_b2 = this.ref.p) !== null && _b2 !== void 0 ? _b2 : []).map((p, i) => new ReflectedParameter(p, i));
772
- }
773
- /**
774
- * No use for this yet, reserved for future use
775
- * @internal
776
- */
777
- get flags() {
778
- var _a2;
779
- return (_a2 = this._flags) !== null && _a2 !== void 0 ? _a2 : this._flags = new ReflectedFlags(this.ref.f);
780
- }
781
- matches(ref) {
782
- return this.returnType.equals(ref.returnType) && this.parameters.every((p, i) => p.equals(ref.parameters[i])) && this.flags.toString() === ref.flags.toString();
783
- }
784
- matchesValue(value, options) {
785
- var _a2;
786
- options !== null && options !== void 0 ? options : options = {};
787
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
788
- return this.matches(ReflectedFunction.for(value));
789
- }
790
- }, __name(_r, "ReflectedFunctionRef"), _r);
791
- ReflectedFunctionRef = __decorate([
792
- ReflectedTypeRef.Kind("function")
793
- ], ReflectedFunctionRef);
794
- let ReflectedMappedRef = (_s = class extends ReflectedTypeRef {
795
- get kind() {
796
- return "mapped";
797
- }
798
- toString() {
799
- return `${this.baseType}<${this.typeParameters.join(", ")}>`;
800
- }
801
- get baseType() {
802
- if (this._baseType)
803
- return this._baseType;
804
- return this._baseType = ReflectedTypeRef.createFromRtRef(this.ref.t);
805
- }
806
- get typeParameters() {
807
- if (this._typeParameters)
808
- return this._typeParameters;
809
- return this._typeParameters = this.ref.p.map((p) => ReflectedTypeRef.createFromRtRef(p));
810
- }
811
- get members() {
812
- if (!this._members)
813
- this._members = this.ref.m.map((m) => new ReflectedObjectMember(m));
814
- return this._members;
815
- }
816
- matches(ref) {
817
- if (this.typeParameters.length !== ref.typeParameters.length)
818
- return false;
819
- return this.typeParameters.every((x, i) => x.equals(ref.typeParameters[i]));
820
- }
821
- matchesValue(value, options) {
822
- var _a2;
823
- options !== null && options !== void 0 ? options : options = {};
824
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
825
- if (!this.ref.m)
826
- return this.baseType.matchesValue(value, options);
827
- if (typeof value !== "object")
828
- return false;
829
- let matches = true;
830
- for (let member of this.members) {
831
- let hasValue = member.name in value;
832
- if (!hasValue) {
833
- if (!member.isOptional) {
834
- options.errors.push(new TypeError(`Missing value for member ${member.toString()}`));
835
- matches = false;
836
- }
837
- continue;
838
- }
839
- let memberValue = value[member.name];
840
- let memberErrors = [];
841
- if (!member.type.matchesValue(memberValue, Object.assign(Object.assign({}, options), { errors: memberErrors }))) {
842
- options.errors.push(new TypeError(`Value for member ${member.toString()} is invalid`));
843
- options.errors.push(...memberErrors);
844
- matches = false;
845
- }
846
- }
847
- return matches;
848
- }
849
- }, __name(_s, "ReflectedMappedRef"), _s);
850
- ReflectedMappedRef = __decorate([
851
- ReflectedTypeRef.Kind("mapped")
852
- ], ReflectedMappedRef);
853
- const _ReflectedTupleElement = class _ReflectedTupleElement {
854
- constructor(ref) {
855
- this.ref = ref;
856
- }
857
- toString() {
858
- return `${this.name} : ${this.type}`;
859
- }
860
- get name() {
861
- return this.ref.n;
862
- }
863
- get type() {
864
- if (this._type)
865
- return this._type;
866
- return this._type = ReflectedTypeRef.createFromRtRef(this.ref.t);
867
- }
868
- };
869
- __name(_ReflectedTupleElement, "ReflectedTupleElement");
870
- let ReflectedTupleElement = _ReflectedTupleElement;
871
- const _ReflectedFlags = class _ReflectedFlags {
872
- constructor(flags) {
873
- if (!flags)
874
- flags = "";
875
- Object.keys(this.flagToProperty).forEach((flag) => this[this.flagToProperty[flag]] = flags.includes(flag));
876
- }
877
- toString() {
878
- return Object.keys(this.propertyToFlag).map((property) => this[property] ? this.propertyToFlag[property] : "").join("");
879
- }
880
- };
881
- __name(_ReflectedFlags, "ReflectedFlags");
882
- let ReflectedFlags = _ReflectedFlags;
883
- __decorate([
884
- Flag(F_READONLY),
885
- __metadata("design:type", Boolean)
886
- ], ReflectedFlags.prototype, "isReadonly", void 0);
887
- __decorate([
888
- Flag(F_ABSTRACT),
889
- __metadata("design:type", Boolean)
890
- ], ReflectedFlags.prototype, "isAbstract", void 0);
891
- __decorate([
892
- Flag(F_PUBLIC),
893
- __metadata("design:type", Boolean)
894
- ], ReflectedFlags.prototype, "isPublic", void 0);
895
- __decorate([
896
- Flag(F_PRIVATE),
897
- __metadata("design:type", Boolean)
898
- ], ReflectedFlags.prototype, "isPrivate", void 0);
899
- __decorate([
900
- Flag(F_PROTECTED),
901
- __metadata("design:type", Boolean)
902
- ], ReflectedFlags.prototype, "isProtected", void 0);
903
- __decorate([
904
- Flag(F_PROPERTY),
905
- __metadata("design:type", Boolean)
906
- ], ReflectedFlags.prototype, "isProperty", void 0);
907
- __decorate([
908
- Flag(F_METHOD),
909
- __metadata("design:type", Boolean)
910
- ], ReflectedFlags.prototype, "isMethod", void 0);
911
- __decorate([
912
- Flag(F_CLASS),
913
- __metadata("design:type", Boolean)
914
- ], ReflectedFlags.prototype, "isClass", void 0);
915
- __decorate([
916
- Flag(F_INTERFACE),
917
- __metadata("design:type", Boolean)
918
- ], ReflectedFlags.prototype, "isInterface", void 0);
919
- __decorate([
920
- Flag(F_OPTIONAL),
921
- __metadata("design:type", Boolean)
922
- ], ReflectedFlags.prototype, "isOptional", void 0);
923
- __decorate([
924
- Flag(F_REST),
925
- __metadata("design:type", Boolean)
926
- ], ReflectedFlags.prototype, "isRest", void 0);
927
- __decorate([
928
- Flag(F_ASYNC),
929
- __metadata("design:type", Boolean)
930
- ], ReflectedFlags.prototype, "isAsync", void 0);
931
- __decorate([
932
- Flag(F_EXPORTED),
933
- __metadata("design:type", Boolean)
934
- ], ReflectedFlags.prototype, "isExported", void 0);
935
- __decorate([
936
- Flag(F_INFERRED),
937
- __metadata("design:type", Boolean)
938
- ], ReflectedFlags.prototype, "isInferred", void 0);
939
- __decorate([
940
- Flag(F_OMITTED),
941
- __metadata("design:type", Boolean)
942
- ], ReflectedFlags.prototype, "isOmitted", void 0);
943
- __decorate([
944
- Flag(F_ARRAY_BINDING),
945
- __metadata("design:type", Boolean)
946
- ], ReflectedFlags.prototype, "isArrayBinding", void 0);
947
- __decorate([
948
- Flag(F_OBJECT_BINDING),
949
- __metadata("design:type", Boolean)
950
- ], ReflectedFlags.prototype, "isObjectBinding", void 0);
951
- const _ReflectedParameter = class _ReflectedParameter {
952
- constructor(rawMetadata, index) {
953
- this.rawMetadata = rawMetadata;
954
- this.index = index;
955
- }
956
- get isBinding() {
957
- return this.isArrayBinding || this.isObjectBinding;
958
- }
959
- /**
960
- * True if this parameter is an array binding expression (destructured assignment).
961
- */
962
- get isArrayBinding() {
963
- return this.flags.isArrayBinding;
964
- }
965
- /**
966
- * True if this parameter is an object binding expression (destructured assignment).
967
- */
968
- get isObjectBinding() {
969
- return this.flags.isObjectBinding;
970
- }
971
- /**
972
- * True if this parameter is an omitted slot within an array binding expression.
973
- * ie, if the user declares [foo, ,bar], then the second binding will have isOmitted true.
974
- * See: destructured assignment.
975
- */
976
- get isOmitted() {
977
- return this.flags.isOmitted;
978
- }
979
- /**
980
- * If this is an object/array binding (ie destructured assignment),
981
- * this will return the individual bindings that are part of this declaration.
982
- */
983
- get bindings() {
984
- if (!this.isBinding)
985
- return void 0;
986
- if (!this._bindings) {
987
- (this.rawMetadata.b || []).map((bindingElement, i) => new _ReflectedParameter(bindingElement, i));
988
- }
989
- return this._bindings;
990
- }
991
- /**
992
- * Get the unmangled original name for this parameter. This may be undefined if the parameter is an array/object
993
- * binding expression (destructured assignment).
994
- */
995
- get name() {
996
- return this.rawMetadata.n;
997
- }
998
- /**
999
- * Get the reflected type of this parameter
1000
- */
1001
- get type() {
1002
- if (this._type)
1003
- return this._type;
1004
- return this._type = ReflectedTypeRef.createFromRtRef(this.rawMetadata.t());
1005
- }
1006
- /**
1007
- * Get flags that define aspects of this property.
1008
- */
1009
- get flags() {
1010
- if (this._flags)
1011
- return this._flags;
1012
- return this._flags = new ReflectedFlags(this.rawMetadata.f);
1013
- }
1014
- /**
1015
- * True if this parameter is optional
1016
- */
1017
- get isOptional() {
1018
- return this.flags.isOptional;
1019
- }
1020
- /**
1021
- * True if this parameter is a rest parameter
1022
- */
1023
- get isRest() {
1024
- return this.flags.isRest;
1025
- }
1026
- /**
1027
- * Retrieve the initializer for this parameter. Invoking the initializer produces the
1028
- * default value for the parameter. Caution: The initializer depends on the value of 'this'.
1029
- * Use evaluateInitializer() to properly invoke the initializer.
1030
- */
1031
- get initializer() {
1032
- return this.rawMetadata.v;
1033
- }
1034
- /**
1035
- * Evaluate the initializer for this parameter with the given value for 'this'. If not provided,
1036
- * 'this' is an empty object. This is suitable for constructor parameters but instance method parameters
1037
- * may reference properties of the object, and so getting the correct value may require passing an
1038
- * appropriate instance.
1039
- *
1040
- * @param thisObject
1041
- * @returns
1042
- */
1043
- evaluateInitializer(thisObject = {}) {
1044
- return this.initializer.apply(thisObject, []);
1045
- }
1046
- /**
1047
- * Check if this parameter declaration is identical to another parameter declaration (including its name).
1048
- *
1049
- * @param other The other parameter to check against
1050
- * @param checkName If true, the name is checked, otherwise it is ignored
1051
- * @returns
1052
- */
1053
- equals(other, checkName = true) {
1054
- return (!checkName || this.name === other.name) && this.type.equals(other.type) && this.flags.toString() === other.flags.toString();
1055
- }
1056
- };
1057
- __name(_ReflectedParameter, "ReflectedParameter");
1058
- let ReflectedParameter = _ReflectedParameter;
1059
- const _ReflectedMethodParameter = class _ReflectedMethodParameter extends ReflectedParameter {
1060
- constructor(method, rawMetadata, index) {
1061
- super(rawMetadata, index);
1062
- this.method = method;
1063
- this.rawMetadata = rawMetadata;
1064
- this.index = index;
1065
- }
1066
- get parent() {
1067
- return this.method;
1068
- }
1069
- get class() {
1070
- return this.method.class;
1071
- }
1072
- };
1073
- __name(_ReflectedMethodParameter, "ReflectedMethodParameter");
1074
- let ReflectedMethodParameter = _ReflectedMethodParameter;
1075
- const _ReflectedFunctionParameter = class _ReflectedFunctionParameter extends ReflectedParameter {
1076
- constructor(func, rawMetadata, index) {
1077
- super(rawMetadata, index);
1078
- this.func = func;
1079
- this.rawMetadata = rawMetadata;
1080
- this.index = index;
1081
- }
1082
- get parent() {
1083
- return this.func;
1084
- }
1085
- };
1086
- __name(_ReflectedFunctionParameter, "ReflectedFunctionParameter");
1087
- let ReflectedFunctionParameter = _ReflectedFunctionParameter;
1088
- const _ReflectedConstructorParameter = class _ReflectedConstructorParameter extends ReflectedParameter {
1089
- constructor(reflectedClass, rawMetadata, index) {
1090
- super(rawMetadata, index);
1091
- this.reflectedClass = reflectedClass;
1092
- this.rawMetadata = rawMetadata;
1093
- this.index = index;
1094
- this._class = reflectedClass;
1095
- }
1096
- get parent() {
1097
- return this.class;
1098
- }
1099
- /**
1100
- * Retrieve the reflected class that this constructor parameter is defined on.
1101
- */
1102
- get class() {
1103
- return this._class;
1104
- }
1105
- /**
1106
- * True if this constructor parameter is declared readonly, meaning it is
1107
- * also an instance property of the class.
1108
- */
1109
- get isReadonly() {
1110
- return this.flags.isReadonly;
1111
- }
1112
- /**
1113
- * True if this constructor parameter is declared public, meaning it is
1114
- * also an instance property of the class.
1115
- */
1116
- get isPublic() {
1117
- return this.flags.isPublic;
1118
- }
1119
- /**
1120
- * True if this constructor parameter is declared protected, meaning it is
1121
- * also an instance property of the class.
1122
- */
1123
- get isProtected() {
1124
- return this.flags.isProtected;
1125
- }
1126
- /**
1127
- * True if this constructor parameter is declared private, meaning it is
1128
- * also an instance property of the class.
1129
- */
1130
- get isPrivate() {
1131
- return this.flags.isPrivate;
1132
- }
1133
- /**
1134
- * Get visibility of this constructor parameter. If the constructor
1135
- * parameter has no visibility modifiers, this is null.
1136
- */
1137
- get visibility() {
1138
- return this.isPublic ? "public" : this.isProtected ? "protected" : this.isPrivate ? "private" : null;
1139
- }
1140
- /**
1141
- * True if the constructor parameter is also a property.
1142
- */
1143
- get isProperty() {
1144
- return this.visibility !== null || this.isReadonly;
1145
- }
1146
- };
1147
- __name(_ReflectedConstructorParameter, "ReflectedConstructorParameter");
1148
- let ReflectedConstructorParameter = _ReflectedConstructorParameter;
1149
- const _ReflectedMember = class _ReflectedMember {
1150
- constructor(reflectedClass, name, isStatic) {
1151
- this.name = name;
1152
- this.isStatic = isStatic;
1153
- this._class = reflectedClass;
1154
- }
1155
- /**
1156
- * Get the given metadata key for this member. This is equivalent to
1157
- * Reflect.getMetadata(key, this.host, this.name)
1158
- * @param key
1159
- * @returns
1160
- */
1161
- getMetadata(key) {
1162
- return Reflect.getMetadata(key, this.host, this.name);
1163
- }
1164
- /**
1165
- * Define a metadata key for this member. This is equivalent to
1166
- * Reflect.defineMetadata(key, value, this.host, this.name)
1167
- * @param key
1168
- * @returns
1169
- */
1170
- defineMetadata(key, value) {
1171
- Reflect.defineMetadata(key, value, this.host, this.name);
1172
- return value;
1173
- }
1174
- /**
1175
- * Get or define a metadata item for this member. If the key already exists, its
1176
- * value is returned without calling the passed function. Otherwise the passed function
1177
- * is called and its value is saved to the given metadata key.
1178
- *
1179
- * @param key The metadata key to fetch
1180
- * @param definer A function which will define the value of the metadata
1181
- * @returns The value of the existing metadata key or the new value returned by the definer function
1182
- * which will also be defined as the appropriate metadata item on this member.
1183
- */
1184
- metadata(key, definer) {
1185
- if (this.hasMetadata(key))
1186
- return this.getMetadata(key);
1187
- let value = definer();
1188
- this.defineMetadata(key, value);
1189
- return value;
1190
- }
1191
- /**
1192
- * Check if a metadata key exists for this member. This is equivalent to
1193
- * Reflect.hasMetadata(key, this.host, this.name)
1194
- * @param key
1195
- * @returns
1196
- */
1197
- hasMetadata(key) {
1198
- return Reflect.hasMetadata(key, this.host, this.name);
1199
- }
1200
- /**
1201
- * Get the host object for this method. For static members this is the
1202
- * class constructor. For instance members this is the class's prototype.
1203
- */
1204
- get host() {
1205
- return this.isStatic ? this.class.class : this.class.prototype;
1206
- }
1207
- /**
1208
- * Get the reflected class that hosts this member
1209
- */
1210
- get class() {
1211
- return this._class;
1212
- }
1213
- /**
1214
- * Get the flags for this member. Includes modifiers and other properties about
1215
- * the member.
1216
- */
1217
- get flags() {
1218
- if (this._flags)
1219
- return this._flags;
1220
- return this._flags = new ReflectedFlags(this.getMetadata("rt:f"));
1221
- }
1222
- /**
1223
- * True if this member is abstract.
1224
- */
1225
- get isAbstract() {
1226
- return this.flags.isAbstract;
1227
- }
1228
- /**
1229
- * True if this member has private visibility.
1230
- */
1231
- get isPrivate() {
1232
- return this.flags.isPrivate;
1233
- }
1234
- /**
1235
- * True if this member has public visibility.
1236
- */
1237
- get isPublic() {
1238
- return this.visibility === "public";
1239
- }
1240
- /**
1241
- * True if this member is specifically marked as public
1242
- * (as opposed to default visibility).
1243
- */
1244
- get isMarkedPublic() {
1245
- return this.flags.isPublic;
1246
- }
1247
- /**
1248
- * True if this member has protected visibility.
1249
- */
1250
- get isProtected() {
1251
- return this.flags.isProtected;
1252
- }
1253
- /**
1254
- * Get the visibility (accessibility) of this member.
1255
- * Can be 'public', 'protected', or 'private'
1256
- */
1257
- get visibility() {
1258
- return this.isMarkedPublic ? "public" : this.isProtected ? "protected" : this.isPrivate ? "private" : "public";
1259
- }
1260
- /**
1261
- * Whether this member is marked as optional.
1262
- */
1263
- get isOptional() {
1264
- return this.flags.isOptional;
1265
- }
1266
- };
1267
- __name(_ReflectedMember, "ReflectedMember");
1268
- let ReflectedMember = _ReflectedMember;
1269
- const _ReflectedFunction = class _ReflectedFunction {
1270
- constructor(func) {
1271
- this.func = func;
1272
- }
1273
- static for(func) {
1274
- if (typeof func !== "function")
1275
- throw new TypeError(`Passed value is not a function`);
1276
- let existing = this.reflectedFunctions.get(func);
1277
- if (!existing) {
1278
- this.reflectedFunctions.set(func, existing = new _ReflectedFunction(func));
1279
- }
1280
- return existing;
1281
- }
1282
- /**
1283
- * Create a new ReflectedClass instance for the given type without sharing. Used during testing.
1284
- * @internal
1285
- **/
1286
- static new(func) {
1287
- return new _ReflectedFunction(func);
1288
- }
1289
- matchesValue(object, errors = [], context) {
1290
- return object === this.func;
1291
- }
1292
- /**
1293
- * Check if the function has the given metadata key defined. This is equivalent
1294
- * to Reflect.hasMetadata(key, value, this.func)
1295
- * @param key
1296
- * @returns
1297
- */
1298
- hasMetadata(key) {
1299
- return Reflect.hasMetadata(key, this.func);
1300
- }
1301
- /**
1302
- * Get the specified metadata key for this function. This is equivalent
1303
- * to Reflect.getMetadata(key, value, this.func)
1304
- * @param key
1305
- * @returns
1306
- */
1307
- getMetadata(key) {
1308
- return Reflect.getMetadata(key, this.func);
1309
- }
1310
- /**
1311
- * Define a metadata key for this function. This is equivalent
1312
- * to Reflect.defineMetadata(key, value, this.func)
1313
- * @param key The metadata key to define.
1314
- * @param value
1315
- */
1316
- defineMetadata(key, value) {
1317
- Reflect.defineMetadata(key, value, this.func);
1318
- return value;
1319
- }
1320
- /**
1321
- * Get or define a metadata item for this function. If the key already exists, its
1322
- * value is returned without calling the passed function. Otherwise the passed function
1323
- * is called and its value is saved to the given metadata key.
1324
- *
1325
- * @param key The metadata key to fetch
1326
- * @param definer A function which will define the value of the metadata
1327
- * @returns The value of the existing metadata key or the new value returned by the definer function
1328
- * which will also be defined as the appropriate metadata item on this function.
1329
- */
1330
- metadata(key, definer) {
1331
- if (this.hasMetadata(key))
1332
- return this.getMetadata(key);
1333
- let value = definer();
1334
- this.defineMetadata(key, value);
1335
- return value;
1336
- }
1337
- /**
1338
- * Get the flags for this function.
1339
- */
1340
- get flags() {
1341
- if (this._flags)
1342
- return this._flags;
1343
- return this._flags = new ReflectedFlags(this.getMetadata("rt:f"));
1344
- }
1345
- /**
1346
- * @internal
1347
- */
1348
- get rawParameterMetadata() {
1349
- if (this._rawParameterMetadata)
1350
- return this._rawParameterMetadata;
1351
- return this._rawParameterMetadata = this.getMetadata("rt:p") || [];
1352
- }
1353
- /**
1354
- * Names of the parameters for this function.
1355
- */
1356
- get parameterNames() {
1357
- return this.rawParameterMetadata.map((x) => x.n);
1358
- }
1359
- /**
1360
- * Types for the parameter types of this function.
1361
- */
1362
- get parameterTypes() {
1363
- if (this._parameterTypes !== void 0)
1364
- return this._parameterTypes;
1365
- if (this.rawParameterMetadata !== void 0) {
1366
- return this._parameterTypes = this.rawParameterMetadata.map((param) => {
1367
- return param.t ? ReflectedTypeRef.createFromRtRef(param.t()) : ReflectedTypeRef.createUnknown();
1368
- });
1369
- } else if (this.hasMetadata("design:paramtypes")) {
1370
- let params = this.getMetadata("design:paramtypes");
1371
- return this._parameterTypes = (params || []).map((t) => ReflectedTypeRef.createFromRtRef(() => t));
1372
- }
1373
- return [];
1374
- }
1375
- /**
1376
- * Retrieve the set of reflected parameters for this method.
1377
- */
1378
- get parameters() {
1379
- if (this._parameters)
1380
- return this._parameters;
1381
- return this._parameters = this.rawParameterMetadata.map((x, i) => new ReflectedFunctionParameter(this, x, i));
1382
- }
1383
- /**
1384
- * Get the parameter with the specified name
1385
- * @param name
1386
- * @returns The reflected parameter
1387
- */
1388
- getParameter(name) {
1389
- return this.parameters.find((x) => x.name === name);
1390
- }
1391
- /**
1392
- * Retrieve the return type of this function.
1393
- */
1394
- get returnType() {
1395
- if (this._returnType !== void 0)
1396
- return this._returnType;
1397
- let typeResolver = this.getMetadata("rt:t");
1398
- if (!typeResolver && this.hasMetadata("design:returntype")) {
1399
- let designReturnType = this.getMetadata("design:returntype");
1400
- typeResolver = /* @__PURE__ */ __name(() => designReturnType || null, "typeResolver");
1401
- }
1402
- if (!typeResolver)
1403
- return ReflectedTypeRef.createUnknown();
1404
- return this._returnType = ReflectedTypeRef.createFromRtRef(typeResolver());
1405
- }
1406
- /**
1407
- * True if the return type was inferred using the Typescript type checker. False if
1408
- * the return type was defined explicitly.
1409
- */
1410
- get returnTypeInferred() {
1411
- return this.flags.isInferred;
1412
- }
1413
- /**
1414
- * True if this function is declared as async.
1415
- */
1416
- get isAsync() {
1417
- return this.flags.isAsync;
1418
- }
1419
- /**
1420
- * True if this function is a variadic function.
1421
- */
1422
- get isVariadic() {
1423
- return this.parameters.find((v) => v.isRest) !== void 0;
1424
- }
1425
- };
1426
- __name(_ReflectedFunction, "ReflectedFunction");
1427
- let ReflectedFunction = _ReflectedFunction;
1428
- ReflectedFunction.reflectedFunctions = /* @__PURE__ */ new WeakMap();
1429
- const _ReflectedMethod = class _ReflectedMethod extends ReflectedMember {
1430
- matchesValue(object, errors = [], context) {
1431
- return object === this.func;
1432
- }
1433
- get func() {
1434
- if (this.isStatic)
1435
- return this.class[this.name];
1436
- else
1437
- return this.class.prototype[this.name];
1438
- }
1439
- /**
1440
- * @internal
1441
- */
1442
- get rawParameterMetadata() {
1443
- if (this._rawParameterMetadata)
1444
- return this._rawParameterMetadata;
1445
- return this._rawParameterMetadata = this.getMetadata("rt:p") || [];
1446
- }
1447
- /**
1448
- * Retrieve the reflected method for the given method function.
1449
- * If the function is not a method, a TypeError is thrown.
1450
- * @param method
1451
- */
1452
- static for(method) {
1453
- if (!hasAnyFlag(method, [F_METHOD]))
1454
- throw new TypeError(`The function is not a method, or the class is not annotated with runtime type metadata`);
1455
- if (!Reflect.hasMetadata("rt:h", method))
1456
- throw new TypeError(`The function is a method, but is not annotated with a host class`);
1457
- let host = Reflect.getMetadata("rt:h", method);
1458
- if (!host)
1459
- throw new TypeError(`The method has a defined host, but it is null/undefined`);
1460
- return ReflectedClass.for(host()).getMethod(method.name);
1461
- }
1462
- /**
1463
- * Retrieve an array with the parameter names for this method.
1464
- */
1465
- get parameterNames() {
1466
- return this.rawParameterMetadata.map((x) => x.n);
1467
- }
1468
- /**
1469
- * Retrieve an array with the parameter types for this method.
1470
- */
1471
- get parameterTypes() {
1472
- if (this._parameterTypes !== void 0)
1473
- return this._parameterTypes;
1474
- if (this.rawParameterMetadata !== void 0) {
1475
- return this._parameterTypes = this.rawParameterMetadata.map((param) => {
1476
- return param.t ? ReflectedTypeRef.createFromRtRef(param.t()) : ReflectedTypeRef.createUnknown();
1477
- });
1478
- } else if (this.hasMetadata("design:paramtypes")) {
1479
- let params = this.getMetadata("design:paramtypes");
1480
- return this._parameterTypes = (params || []).map((t) => ReflectedTypeRef.createFromRtRef(() => t));
1481
- }
1482
- return [];
1483
- }
1484
- /**
1485
- * Retrieve the set of reflected parameters for this method.
1486
- */
1487
- get parameters() {
1488
- if (this._parameters)
1489
- return this._parameters;
1490
- return this._parameters = this.rawParameterMetadata.map((x, i) => new ReflectedMethodParameter(this, x, i));
1491
- }
1492
- /**
1493
- * Get a reflected parameter by name
1494
- * @param name
1495
- * @returns The reflected parameter
1496
- */
1497
- getParameter(name) {
1498
- return this.parameters.find((x) => x.name === name);
1499
- }
1500
- /**
1501
- * Get the return type of this method.
1502
- */
1503
- get returnType() {
1504
- if (this._returnType !== void 0)
1505
- return this._returnType;
1506
- let typeResolver = this.getMetadata("rt:t");
1507
- if (!typeResolver && this.hasMetadata("design:returntype")) {
1508
- let designReturnType = this.getMetadata("design:returntype");
1509
- typeResolver = /* @__PURE__ */ __name(() => designReturnType || null, "typeResolver");
1510
- }
1511
- if (!typeResolver)
1512
- return ReflectedTypeRef.createUnknown();
1513
- return this._returnType = ReflectedTypeRef.createFromRtRef(typeResolver());
1514
- }
1515
- /**
1516
- * True if the return type was inferred using the Typescript type checker. False if
1517
- * the return type was defined explicitly.
1518
- */
1519
- get returnTypeInferred() {
1520
- return this.flags.isInferred;
1521
- }
1522
- /**
1523
- * True if this method is declared as async.
1524
- */
1525
- get isAsync() {
1526
- return this.flags.isAsync;
1527
- }
1528
- /**
1529
- * True if this function is a variadic function.
1530
- */
1531
- get isVariadic() {
1532
- return this.parameters.find((v) => v.isRest) !== void 0;
1533
- }
1534
- };
1535
- __name(_ReflectedMethod, "ReflectedMethod");
1536
- let ReflectedMethod = _ReflectedMethod;
1537
- const _ReflectedProperty = class _ReflectedProperty extends ReflectedMember {
1538
- /**
1539
- * Get the type of this property.
1540
- */
1541
- get type() {
1542
- if (this._type !== void 0)
1543
- return this._type;
1544
- let typeResolver;
1545
- if (this.hasMetadata("rt:t")) {
1546
- typeResolver = this.getMetadata("rt:t");
1547
- } else if (this.hasMetadata("design:type")) {
1548
- let designType = this.getMetadata("design:type");
1549
- typeResolver = /* @__PURE__ */ __name(() => designType, "typeResolver");
1550
- }
1551
- if (!typeResolver)
1552
- return this._type = ReflectedTypeRef.createUnknown();
1553
- return this._type = ReflectedTypeRef.createFromRtRef(typeResolver());
1554
- }
1555
- /**
1556
- * True if this property is marked readonly.
1557
- */
1558
- get isReadonly() {
1559
- return this.flags.isReadonly;
1560
- }
1561
- /**
1562
- * Check if the given value matches the type of this property, and would
1563
- * thus be a valid assignment.
1564
- * @param object
1565
- * @param errors
1566
- * @returns
1567
- */
1568
- matchesValue(object, options) {
1569
- var _a2;
1570
- options !== null && options !== void 0 ? options : options = {};
1571
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
1572
- return this.type.matchesValue(object, options);
1573
- }
1574
- };
1575
- __name(_ReflectedProperty, "ReflectedProperty");
1576
- let ReflectedProperty = _ReflectedProperty;
1577
- function getFlags(value) {
1578
- if (!Reflect.hasMetadata("rt:f", value))
1579
- return "";
1580
- let flagsValue = Reflect.getMetadata("rt:f", value);
1581
- if (typeof flagsValue === "string")
1582
- return flagsValue;
1583
- return "";
1584
- }
1585
- __name(getFlags, "getFlags");
1586
- function hasAnyFlag(value, desiredFlags) {
1587
- let flags = getFlags(value);
1588
- return desiredFlags.some((x) => flags.includes(x));
1589
- }
1590
- __name(hasAnyFlag, "hasAnyFlag");
1591
- function hasAllFlags(value, desiredFlags) {
1592
- let flags = getFlags(value);
1593
- return desiredFlags.every((x) => flags.includes(x));
1594
- }
1595
- __name(hasAllFlags, "hasAllFlags");
1596
- let ReflectedClass = ReflectedClass_1 = (_t = class {
1597
- /**
1598
- * Constructs a new ReflectedClass. Use ReflectedClass.for() to obtain a ReflectedClass.
1599
- */
1600
- constructor(klass) {
1601
- this._hasPropertyNamesMeta = false;
1602
- this._hasStaticPropertyNameMeta = false;
1603
- this._dynamicStaticProperties = /* @__PURE__ */ new Map();
1604
- this._dynamicProperties = /* @__PURE__ */ new Map();
1605
- this._class = klass;
1606
- }
1607
- /**
1608
- * Obtain a ReflectedClass for the given class constructor, Interface value or instance.
1609
- * @param constructorOrValue Can be a class constructor, Interface, or an instance of a class (in which case the
1610
- * instance's constructor will be used)
1611
- * @returns The ReflectedClass.
1612
- */
1613
- static for(constructorOrValue) {
1614
- let flags = getFlags(constructorOrValue);
1615
- if (flags.includes(F_INTERFACE))
1616
- return this.forConstructorOrInterface(constructorOrValue);
1617
- else if (flags.includes(F_CLASS))
1618
- return this.forConstructorOrInterface(constructorOrValue);
1619
- else if (flags.includes(F_FUNCTION))
1620
- throw new TypeError(`Value is a function, use ReflectedFunction.for() or reflect(func) instead`);
1621
- if (typeof constructorOrValue === "function" || "name" in constructorOrValue && "prototype" in constructorOrValue && typeof constructorOrValue.identity === "symbol")
1622
- return this.forConstructorOrInterface(constructorOrValue);
1623
- return this.forConstructorOrInterface(constructorOrValue.constructor);
1624
- }
1625
- /**
1626
- * Create a new ReflectedClass instance for the given type without sharing. Used during testing.
1627
- * @internal
1628
- **/
1629
- static new(constructorOrInterface) {
1630
- return new ReflectedClass_1(constructorOrInterface);
1631
- }
1632
- static forConstructorOrInterface(constructorOrInterface) {
1633
- let existing = this.reflectedClasses.get(constructorOrInterface);
1634
- if (!existing) {
1635
- this.reflectedClasses.set(constructorOrInterface, existing = new ReflectedClass_1(constructorOrInterface));
1636
- }
1637
- return existing;
1638
- }
1639
- /**
1640
- * Get the interfaces that this class implements, or that this interface extends.
1641
- * Note that if the class implements another class as an interface, you will receive
1642
- * a class type reference for that, not an interface type reference.
1643
- */
1644
- get interfaces() {
1645
- if (this._interfaces !== void 0)
1646
- return this._interfaces;
1647
- if (this.hasMetadata("rt:i")) {
1648
- return this._interfaces = this.getMetadata("rt:i").map((resolver) => resolver()).filter((x) => !!x).map((ref) => ReflectedTypeRef.createFromRtRef(ref));
1649
- }
1650
- return [];
1651
- }
1652
- /**
1653
- * Check if this class implements the given interface. The parameter can be a reified interface
1654
- * reference or a class reference. Note that implementing a class is not the same as extending a class.
1655
- * Note that this will return true only if this class explicitly declares that an interface is implemented.
1656
- *
1657
- * @param interfaceType
1658
- * @returns boolean
1659
- */
1660
- implements(interfaceType) {
1661
- return !!this.interfaces.find((i) => typeof interfaceType === "function" ? i.isClass(interfaceType) : i.isInterface(interfaceType));
1662
- }
1663
- /**
1664
- * Check if the given value matches the shape of this type, and thus would be a valid assignment.
1665
- * @param object
1666
- * @param errors
1667
- * @returns
1668
- */
1669
- matchesValue(object, options) {
1670
- var _a2;
1671
- options !== null && options !== void 0 ? options : options = {};
1672
- (_a2 = options.errors) !== null && _a2 !== void 0 ? _a2 : options.errors = [];
1673
- if (object === null || object === void 0) {
1674
- options.errors.push(new Error(`Value is undefined`));
1675
- return false;
1676
- }
1677
- if (typeof object !== "object") {
1678
- options.errors.push(new Error(`Value must be an object`));
1679
- return false;
1680
- }
1681
- let matches = true;
1682
- if (globalThis.RTTI_TRACE === true)
1683
- console.log(`Type checking value against type '${this.class.name}'`);
1684
- for (let prop of this.properties) {
1685
- let hasValue = prop.name in object;
1686
- let value = object[prop.name];
1687
- if (!hasValue && !prop.isOptional) {
1688
- options.errors.push(new Error(`Property '${prop.name}' is missing in value`));
1689
- matches = false;
1690
- }
1691
- if (!hasValue)
1692
- continue;
1693
- let propMatch = prop.matchesValue(value, options);
1694
- if (globalThis.RTTI_TRACE === true)
1695
- console.log(` - ${this.class.name}#${prop.name} : ${prop.type} | valid(${JSON.stringify(value)}) => ${propMatch}`);
1696
- matches && (matches = propMatch);
1697
- }
1698
- let unaccountedProperties = Object.keys(object).filter((x) => !this.properties.some((y) => y.name === x) && !this.methods.some((y) => y.name === x));
1699
- if (options.allowExtraProperties !== true && unaccountedProperties.length > 0) {
1700
- options.errors.push(new Error(`Object contains the following undeclared properties: ${unaccountedProperties.join(", ")}`));
1701
- matches = false;
1702
- }
1703
- return matches;
1704
- }
1705
- /**
1706
- * Get the prototype object for this reflected class.
1707
- */
1708
- get prototype() {
1709
- return this._class.prototype;
1710
- }
1711
- /**
1712
- * Get the class constructor for this reflected class.
1713
- */
1714
- get class() {
1715
- return this._class;
1716
- }
1717
- /**
1718
- * Get the reflected superclass for this class. If this is an interface,
1719
- * this will always be undefined. If you are looking to access the classes/interfaces that
1720
- * an interface extends, use the "interfaces" property.
1721
- */
1722
- get super() {
1723
- var _a2, _b2;
1724
- if (this._super !== void 0)
1725
- return this._super;
1726
- let parentClass = (_b2 = (_a2 = Object.getPrototypeOf(this.class.prototype)) === null || _a2 === void 0 ? void 0 : _a2.constructor) !== null && _b2 !== void 0 ? _b2 : Object;
1727
- if (parentClass === Object)
1728
- return this._super = null;
1729
- else
1730
- return this._super = ReflectedClass_1.for(parentClass);
1731
- }
1732
- /**
1733
- * Check if the function has the given metadata key defined. This is equivalent
1734
- * to Reflect.hasMetadata(key, this.class)
1735
- * @param key
1736
- * @returns
1737
- */
1738
- hasMetadata(key) {
1739
- return Reflect.hasMetadata(key, this.class);
1740
- }
1741
- /**
1742
- * Get the specified metadata key. This is equivalent to Reflect.getMetadata(key, this.class).
1743
- * @param key
1744
- * @returns
1745
- */
1746
- getMetadata(key) {
1747
- return Reflect.getMetadata(key, this.class);
1748
- }
1749
- /**
1750
- * Define a metadata key on this class. This is equivalent to Reflect.defineMetadata(key, value, this.class).
1751
- * @param key
1752
- * @param value
1753
- * @returns
1754
- */
1755
- defineMetadata(key, value) {
1756
- Reflect.defineMetadata(key, value, this.class);
1757
- return value;
1758
- }
1759
- /**
1760
- * Get or define a metadata item for this class/interface. If the key already exists, its
1761
- * value is returned without calling the passed function. Otherwise the passed function
1762
- * is called and its value is saved to the given metadata key.
1763
- *
1764
- * @param key The metadata key to fetch
1765
- * @param definer A function which will define the value of the metadata
1766
- * @returns The value of the existing metadata key or the new value returned by the definer function
1767
- * which will also be defined as the appropriate metadata item on this class/interface.
1768
- */
1769
- metadata(key, definer) {
1770
- if (this.hasMetadata(key))
1771
- return this.getMetadata(key);
1772
- let value = definer();
1773
- this.defineMetadata(key, value);
1774
- return value;
1775
- }
1776
- /**
1777
- * Define a metadata key on this class's prototype object. This is equivalent to Reflect.defineMetadata(key, value, this.class.prototype)
1778
- * @param key
1779
- * @param value
1780
- * @returns
1781
- */
1782
- definePrototypeMetadata(key, value) {
1783
- Reflect.defineMetadata(key, value, this.class.prototype);
1784
- return value;
1785
- }
1786
- /**
1787
- * Retrieve the set of property names that are defined directly on this class, excluding
1788
- * those which are inherited.
1789
- */
1790
- get ownPropertyNames() {
1791
- if (this._ownPropertyNames)
1792
- return this._ownPropertyNames;
1793
- let propertyNames;
1794
- if (this.hasMetadata("rt:P")) {
1795
- propertyNames = this.getMetadata("rt:P");
1796
- this._hasPropertyNamesMeta = !!propertyNames;
1797
- } else {
1798
- propertyNames = Object.getOwnPropertyNames(this.class.prototype).filter((x) => x !== "constructor").filter((x) => {
1799
- let descriptor = Object.getOwnPropertyDescriptor(this.class.prototype, x);
1800
- if (descriptor.get)
1801
- return true;
1802
- return typeof this.class.prototype[x] === "function";
1803
- });
1804
- }
1805
- return this._ownPropertyNames = propertyNames || [];
1806
- }
1807
- /**
1808
- * Retrieve the set of method names that are defined directly on this class, excluding
1809
- * those which are inherited.
1810
- */
1811
- get ownMethodNames() {
1812
- if (this._ownMethodNames)
1813
- return this._ownMethodNames;
1814
- let methodNames = this.getMetadata("rt:m");
1815
- if (!methodNames) {
1816
- methodNames = Object.getOwnPropertyNames(this.class.prototype).filter((x) => x !== "constructor").filter((x) => {
1817
- let descriptor = Object.getOwnPropertyDescriptor(this.class.prototype, x);
1818
- if (descriptor.get)
1819
- return false;
1820
- return typeof this.class.prototype[x] === "function";
1821
- });
1822
- }
1823
- return this._ownMethodNames = methodNames;
1824
- }
1825
- /**
1826
- * Retrieve the set of static property names that are defined directly on this class, excluding
1827
- * those which are inherited. Always empty for interfaces.
1828
- */
1829
- get ownStaticPropertyNames() {
1830
- if (this._ownStaticPropertyNames)
1831
- return this._ownStaticPropertyNames;
1832
- let ownStaticPropertyNames = this.getMetadata("rt:SP");
1833
- this._hasStaticPropertyNameMeta = !!ownStaticPropertyNames;
1834
- if (!ownStaticPropertyNames) {
1835
- this._hasStaticPropertyNameMeta = false;
1836
- ownStaticPropertyNames = Object.getOwnPropertyNames(this.class).filter((x) => !["length", "prototype", "name"].includes(x)).filter((x) => typeof this.class[x] !== "function");
1837
- }
1838
- return this._ownStaticPropertyNames = ownStaticPropertyNames;
1839
- }
1840
- /**
1841
- * Retrieve the set of static method names that are defined directly on this class,
1842
- * excluding those which are inherited. Always empty for interfaces
1843
- */
1844
- get ownStaticMethodNames() {
1845
- if (this._ownStaticMethodNames)
1846
- return this._ownStaticMethodNames;
1847
- let ownStaticMethodNames = this.getMetadata("rt:Sm");
1848
- if (!ownStaticMethodNames) {
1849
- ownStaticMethodNames = Object.getOwnPropertyNames(this.class).filter((x) => !["length", "prototype", "name"].includes(x)).filter((x) => typeof this.class[x] === "function");
1850
- }
1851
- return this._ownStaticMethodNames = ownStaticMethodNames;
1852
- }
1853
- /**
1854
- * Retrieve the set of flags for this class/interface. Use this to check for modifiers or other properties
1855
- * of the class/interface.
1856
- */
1857
- get flags() {
1858
- if (this._flags)
1859
- return this._flags;
1860
- return this._flags = new ReflectedFlags(this.getMetadata("rt:f"));
1861
- }
1862
- /**
1863
- * True if the class is marked abstract.
1864
- */
1865
- get isAbstract() {
1866
- return this.flags.isAbstract;
1867
- }
1868
- /**
1869
- * Get the instance method names for this reflected class/interface.
1870
- */
1871
- get methodNames() {
1872
- var _a2, _b2;
1873
- if (this._methodNames)
1874
- return this._methodNames;
1875
- return this._methodNames = superMergeNames(this.ownMethodNames, (_b2 = (_a2 = this.super) === null || _a2 === void 0 ? void 0 : _a2.methodNames) !== null && _b2 !== void 0 ? _b2 : []);
1876
- }
1877
- /**
1878
- * Get the static property names defined for this reflected class. Always empty for interfaces.
1879
- */
1880
- get staticPropertyNames() {
1881
- var _a2, _b2;
1882
- if (this._staticPropertyNames)
1883
- return this._staticPropertyNames;
1884
- return this._staticPropertyNames = superMergeNames(this.ownStaticPropertyNames, (_b2 = (_a2 = this.super) === null || _a2 === void 0 ? void 0 : _a2.staticPropertyNames) !== null && _b2 !== void 0 ? _b2 : []);
1885
- }
1886
- /**
1887
- * Retrieve an array of the names of static methods defined on this reflected class.
1888
- * Always empty for interfaces.
1889
- */
1890
- get staticMethodNames() {
1891
- var _a2, _b2;
1892
- if (this._staticMethodNames)
1893
- return this._staticMethodNames;
1894
- return this._staticMethodNames = superMergeNames(this.ownStaticMethodNames, (_b2 = (_a2 = this.super) === null || _a2 === void 0 ? void 0 : _a2.staticMethodNames) !== null && _b2 !== void 0 ? _b2 : []);
1895
- }
1896
- /**
1897
- * Retrieve an array of the names of instance properties defined on this class/interface
1898
- */
1899
- get propertyNames() {
1900
- var _a2, _b2;
1901
- if (this._propertyNames)
1902
- return this._propertyNames;
1903
- return this._propertyNames = superMergeNames(this.ownPropertyNames, (_b2 = (_a2 = this.super) === null || _a2 === void 0 ? void 0 : _a2.propertyNames) !== null && _b2 !== void 0 ? _b2 : []);
1904
- }
1905
- /**
1906
- * Retrieve the set of reflected methods defined directly on this class/interface.
1907
- */
1908
- get ownMethods() {
1909
- if (this._ownMethods)
1910
- return this._ownMethods;
1911
- return this._ownMethods = this.ownMethodNames.map((name) => new ReflectedMethod(this, name, false));
1912
- }
1913
- /**
1914
- * Retrieve the set of reflected static properties defined directly on this class. Always empty
1915
- * for interfaces.
1916
- */
1917
- get ownStaticProperties() {
1918
- if (this._ownStaticProperties)
1919
- return this._ownStaticProperties;
1920
- return this._ownStaticProperties = this.staticPropertyNames.map((x) => new ReflectedProperty(this, x, true));
1921
- }
1922
- /**
1923
- * Retrieve the set of reflected static methods defined directly on this class. Always
1924
- * empty for interfaces.
1925
- */
1926
- get ownStaticMethods() {
1927
- if (this._ownStaticMethods)
1928
- return this._ownStaticMethods;
1929
- return this._ownStaticMethods = this.ownStaticMethodNames.map((name) => new ReflectedMethod(this, name, true));
1930
- }
1931
- /**
1932
- * Retrieve the set of reflected instance methods defined on this class/interface.
1933
- */
1934
- get methods() {
1935
- var _a2, _b2;
1936
- if (this._methods)
1937
- return this._methods;
1938
- return this._methods = superMergeElements(this.ownMethods, (_b2 = (_a2 = this.super) === null || _a2 === void 0 ? void 0 : _a2.methods) !== null && _b2 !== void 0 ? _b2 : []);
1939
- }
1940
- /**
1941
- * Retrieve the set of reflected static properties defined on this class. Always
1942
- * empty for interfaces.
1943
- */
1944
- get staticProperties() {
1945
- var _a2, _b2;
1946
- if (this._staticProperties)
1947
- return this._staticProperties;
1948
- return this._staticProperties = superMergeElements(this.ownStaticProperties, (_b2 = (_a2 = this.super) === null || _a2 === void 0 ? void 0 : _a2.staticProperties) !== null && _b2 !== void 0 ? _b2 : []);
1949
- }
1950
- /**
1951
- * Retrieve the set of reflected static methods defined on this class. Always
1952
- * empty for interfaces
1953
- */
1954
- get staticMethods() {
1955
- var _a2, _b2;
1956
- if (this._staticMethods)
1957
- return this._staticMethods;
1958
- return this._staticMethods = superMergeElements(this.ownStaticMethods, (_b2 = (_a2 = this.super) === null || _a2 === void 0 ? void 0 : _a2.staticMethods) !== null && _b2 !== void 0 ? _b2 : []);
1959
- }
1960
- /**
1961
- * Retrieve the set of reflected instance properties defined directly on this class/interface
1962
- */
1963
- get ownProperties() {
1964
- if (this._ownProperties)
1965
- return this._ownProperties;
1966
- return this._ownProperties = this.ownPropertyNames.map((name) => new ReflectedProperty(this, name, false));
1967
- }
1968
- /**
1969
- * Retrieve the set of reflected instance methods defined on this class/interface
1970
- */
1971
- get properties() {
1972
- var _a2, _b2;
1973
- if (this._properties)
1974
- return this._properties;
1975
- return this._properties = superMergeElements(this.ownProperties, (_b2 = (_a2 = this.super) === null || _a2 === void 0 ? void 0 : _a2.properties) !== null && _b2 !== void 0 ? _b2 : []);
1976
- }
1977
- get rawParameterMetadata() {
1978
- if (this._rawParameterMetadata)
1979
- return this._rawParameterMetadata;
1980
- let rawParams = this.getMetadata("rt:p");
1981
- if (rawParams === void 0 && this.hasMetadata("design:paramtypes")) {
1982
- let types = this.getMetadata("design:paramtypes");
1983
- let names = getParameterNames(this.class);
1984
- rawParams = names.map((n, i) => ({ n, t: /* @__PURE__ */ __name(() => types[i], "t") }));
1985
- }
1986
- return this._rawParameterMetadata = rawParams || [];
1987
- }
1988
- /**
1989
- * Retrieve an array of the parameter names for this class's constructor.
1990
- */
1991
- get parameterNames() {
1992
- return this.rawParameterMetadata.map((x) => x.n);
1993
- }
1994
- /**
1995
- * Retrieve an array of the types for the parameters of this class's
1996
- * constructor.
1997
- */
1998
- get parameterTypes() {
1999
- return this.rawParameterMetadata.map((x) => x.t);
2000
- }
2001
- /**
2002
- * Retrieve the set of reflected parameters for this class's constructor.
2003
- */
2004
- get parameters() {
2005
- if (this._parameters)
2006
- return this._parameters;
2007
- return this._parameters = this.rawParameterMetadata.map((x, i) => new ReflectedConstructorParameter(this, x, i));
2008
- }
2009
- /**
2010
- * Get a reflected constructor parameter by name.
2011
- * @param name
2012
- * @returns
2013
- */
2014
- getParameter(name) {
2015
- return this.parameters.find((x) => x.name === name);
2016
- }
2017
- /**
2018
- * Get a reflected instance method (declared directly on this class) by name
2019
- * @param name
2020
- * @returns
2021
- */
2022
- getOwnMethod(name) {
2023
- return this.ownMethods.find((x) => x.name === name);
2024
- }
2025
- /**
2026
- * Get a reflected instance method by name
2027
- * @param name
2028
- * @returns
2029
- */
2030
- getMethod(name) {
2031
- return this.methods.find((x) => x.name === name);
2032
- }
2033
- /**
2034
- * Get a reflected static method by name
2035
- * @param name
2036
- * @returns
2037
- */
2038
- getStaticMethod(name) {
2039
- return this.staticMethods.find((x) => x.name === name);
2040
- }
2041
- /**
2042
- * Get a reflected static property (declared directly on this class) by name
2043
- * @param name
2044
- * @returns
2045
- */
2046
- getOwnStaticProperty(name) {
2047
- let matchingProp = this.ownStaticProperties.find((x) => x.name === name);
2048
- if (matchingProp)
2049
- return matchingProp;
2050
- if (!this._hasStaticPropertyNameMeta) {
2051
- if (this._dynamicStaticProperties.has(name))
2052
- return this._dynamicStaticProperties.get(name);
2053
- let prop = new ReflectedProperty(this, name, true);
2054
- this._dynamicStaticProperties.set(name, prop);
2055
- return prop;
2056
- }
2057
- }
2058
- /**
2059
- * Get a reflected static property by name
2060
- * @param name
2061
- * @returns
2062
- */
2063
- getStaticProperty(name) {
2064
- let matchingProp = this.staticProperties.find((x) => x.name === name);
2065
- if (matchingProp)
2066
- return matchingProp;
2067
- if (!this._hasStaticPropertyNameMeta) {
2068
- if (this._dynamicStaticProperties.has(name))
2069
- return this._dynamicStaticProperties.get(name);
2070
- let prop = new ReflectedProperty(this, name, true);
2071
- this._dynamicStaticProperties.set(name, prop);
2072
- return prop;
2073
- }
2074
- }
2075
- /**
2076
- * Get a reflected instance property (declared directly on this class) by name
2077
- * @param name
2078
- * @returns
2079
- */
2080
- getOwnProperty(name) {
2081
- let matchingProp = this.ownProperties.find((x) => x.name === name);
2082
- if (matchingProp)
2083
- return matchingProp;
2084
- if (!this._hasPropertyNamesMeta) {
2085
- if (this._dynamicProperties.has(name))
2086
- return this._dynamicProperties.get(name);
2087
- let prop = new ReflectedProperty(this, name, false);
2088
- this._dynamicProperties.set(name, prop);
2089
- return prop;
2090
- }
2091
- }
2092
- /**
2093
- * Get a reflected instance property by name
2094
- * @param name
2095
- * @returns
2096
- */
2097
- getProperty(name) {
2098
- let matchingProp = this.properties.find((x) => x.name === name);
2099
- if (matchingProp)
2100
- return matchingProp;
2101
- if (!this._hasPropertyNamesMeta) {
2102
- if (this._dynamicProperties.has(name))
2103
- return this._dynamicProperties.get(name);
2104
- let prop = new ReflectedProperty(this, name, false);
2105
- this._dynamicProperties.set(name, prop);
2106
- return prop;
2107
- }
2108
- }
2109
- }, __name(_t, "ReflectedClass"), _t);
2110
- ReflectedClass.reflectedClasses = /* @__PURE__ */ new WeakMap();
2111
- ReflectedClass = ReflectedClass_1 = __decorate([
2112
- Sealed(),
2113
- __metadata("design:paramtypes", [Object])
2114
- ], ReflectedClass);
2115
- function implementsInterface(value, interfaceType) {
2116
- if (value === null || value === void 0 || !["object", "function"].includes(typeof value))
2117
- return false;
2118
- if (interfaceType === null || interfaceType === void 0)
2119
- throw new TypeError(`Interface type must not be undefined`);
2120
- if (typeof value === "object")
2121
- return ReflectedClass.for(value.constructor).implements(interfaceType);
2122
- else if (typeof value === "function")
2123
- return ReflectedClass.for(value).implements(interfaceType);
2124
- }
2125
- __name(implementsInterface, "implementsInterface");
2126
- function matchesShape(value, interfaceType) {
2127
- if (interfaceType === null || interfaceType === void 0)
2128
- throw new TypeError(`Interface type must not be undefined`);
2129
- return ReflectedClass.for(interfaceType).matchesValue(value);
2130
- }
2131
- __name(matchesShape, "matchesShape");
2132
- function reflect(value = NotProvided, callSite) {
2133
- if (value === NotProvided && !callSite) {
2134
- throw new Error(`reflect<T>() can only be used when project is built with the typescript-rtti transformer`);
2135
- }
2136
- if (!value)
2137
- throw new TypeError(`Could not reflect on null/undefined`);
2138
- if (isCallSite(value))
2139
- return new ReflectedCallSite(value);
2140
- if (value === NotProvided && isCallSite(callSite))
2141
- return new ReflectedCallSite(callSite).typeParameters[0];
2142
- if (!["object", "function"].includes(typeof value)) {
2143
- return reflect(value.constructor);
2144
- }
2145
- let flags = getFlags(value);
2146
- if (flags.includes(F_FUNCTION))
2147
- return ReflectedFunction.for(value);
2148
- if (flags.includes(F_METHOD))
2149
- return ReflectedMethod.for(value);
2150
- if (typeof value === "function" && !value.prototype)
2151
- return ReflectedFunction.for(value);
2152
- return ReflectedClass.for(value);
2153
- }
2154
- __name(reflect, "reflect");
2155
- const _ReflectedCallSite = class _ReflectedCallSite {
2156
- constructor(callSite) {
2157
- this.callSite = callSite;
2158
- }
2159
- get parameters() {
2160
- if (!this._parameters)
2161
- this._parameters = this.callSite.p.map((x) => ReflectedTypeRef.createFromRtRef(x));
2162
- return this._parameters;
2163
- }
2164
- get typeParameters() {
2165
- if (!this._typeParameters) {
2166
- this._typeParameters = this.callSite.tp.map((x) => ReflectedTypeRef.createFromRtRef(x));
2167
- }
2168
- return this._typeParameters;
2169
- }
2170
- };
2171
- __name(_ReflectedCallSite, "ReflectedCallSite");
2172
- let ReflectedCallSite = _ReflectedCallSite;
2173
- function superMergeElements(ownSet, superSet) {
2174
- return superSet.map((superItem) => {
2175
- var _a2;
2176
- return (_a2 = ownSet.find((ownItem) => ownItem.name === superItem.name)) !== null && _a2 !== void 0 ? _a2 : superItem;
2177
- }).concat(ownSet.filter((ownItem) => !superSet.some((superItem) => ownItem.name === superItem.name)));
2178
- }
2179
- __name(superMergeElements, "superMergeElements");
2180
- function superMergeNames(ownSet, superSet) {
2181
- return superSet.concat(ownSet.filter((x) => !superSet.includes(x)));
2182
- }
2183
- __name(superMergeNames, "superMergeNames");
2184
- export {
2185
- ReflectedAnyRef,
2186
- ReflectedArrayRef,
2187
- ReflectedCallSite,
2188
- ReflectedClass,
2189
- ReflectedClassRef,
2190
- ReflectedConstructorParameter,
2191
- ReflectedEnumRef,
2192
- ReflectedFalseRef,
2193
- ReflectedFlags,
2194
- ReflectedFunction,
2195
- ReflectedFunctionParameter,
2196
- ReflectedFunctionRef,
2197
- ReflectedGenericRef,
2198
- ReflectedInterfaceRef,
2199
- ReflectedIntersectionRef,
2200
- ReflectedLiteralRef,
2201
- ReflectedMappedRef,
2202
- ReflectedMember,
2203
- ReflectedMethod,
2204
- ReflectedMethodParameter,
2205
- ReflectedNullRef,
2206
- ReflectedObjectMember,
2207
- ReflectedObjectRef,
2208
- ReflectedParameter,
2209
- ReflectedProperty,
2210
- ReflectedTrueRef,
2211
- ReflectedTupleElement,
2212
- ReflectedTupleRef,
2213
- ReflectedTypeRef,
2214
- ReflectedUndefinedRef,
2215
- ReflectedUnionRef,
2216
- ReflectedUnknownRef,
2217
- ReflectedVoidRef,
2218
- TYPE_REF_KIND_EXPANSION,
2219
- implementsInterface,
2220
- isCallSite,
2221
- matchesShape,
2222
- reflect,
2223
- reify
2224
- };
2225
- //# sourceMappingURL=reflect.js.map