koatty_validation 1.3.2 → 1.3.6
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/.rollup.config.js +59 -62
- package/CHANGELOG.md +75 -76
- package/LICENSE +29 -29
- package/README.md +116 -116
- package/dist/LICENSE +29 -29
- package/dist/README.md +116 -116
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1483 -147
- package/dist/index.mjs +1469 -133
- package/dist/package.json +94 -89
- package/package.json +94 -89
- package/.vscode/launch.json +0 -81
package/dist/index.js
CHANGED
|
@@ -1,36 +1,1445 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @Author: richen
|
|
3
|
-
* @Date: 2024-
|
|
3
|
+
* @Date: 2024-11-06 10:51:17
|
|
4
4
|
* @License: BSD (3-Clause)
|
|
5
5
|
* @Copyright (c) - <richenlin(at)gmail.com>
|
|
6
6
|
* @HomePage: https://koatty.org/
|
|
7
7
|
*/
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
+
var classValidator = require('class-validator');
|
|
10
11
|
var helper = require('koatty_lib');
|
|
11
|
-
require('reflect-metadata');
|
|
12
12
|
var koatty_container = require('koatty_container');
|
|
13
|
-
var classValidator = require('class-validator');
|
|
14
13
|
|
|
15
14
|
function _interopNamespaceDefault(e) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
var helper__namespace = /*#__PURE__*/_interopNamespaceDefault(helper);
|
|
33
32
|
|
|
33
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
34
|
+
|
|
35
|
+
var _Reflect = {};
|
|
36
|
+
|
|
37
|
+
/*! *****************************************************************************
|
|
38
|
+
Copyright (C) Microsoft. All rights reserved.
|
|
39
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
40
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
41
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
42
|
+
|
|
43
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
44
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
45
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
46
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
47
|
+
|
|
48
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
49
|
+
and limitations under the License.
|
|
50
|
+
***************************************************************************** */
|
|
51
|
+
|
|
52
|
+
var hasRequired_Reflect;
|
|
53
|
+
|
|
54
|
+
function require_Reflect () {
|
|
55
|
+
if (hasRequired_Reflect) return _Reflect;
|
|
56
|
+
hasRequired_Reflect = 1;
|
|
57
|
+
var Reflect;
|
|
58
|
+
(function (Reflect) {
|
|
59
|
+
// Metadata Proposal
|
|
60
|
+
// https://rbuckton.github.io/reflect-metadata/
|
|
61
|
+
(function (factory) {
|
|
62
|
+
var root = typeof globalThis === "object" ? globalThis :
|
|
63
|
+
typeof commonjsGlobal === "object" ? commonjsGlobal :
|
|
64
|
+
typeof self === "object" ? self :
|
|
65
|
+
typeof this === "object" ? this :
|
|
66
|
+
sloppyModeThis();
|
|
67
|
+
var exporter = makeExporter(Reflect);
|
|
68
|
+
if (typeof root.Reflect !== "undefined") {
|
|
69
|
+
exporter = makeExporter(root.Reflect, exporter);
|
|
70
|
+
}
|
|
71
|
+
factory(exporter, root);
|
|
72
|
+
if (typeof root.Reflect === "undefined") {
|
|
73
|
+
root.Reflect = Reflect;
|
|
74
|
+
}
|
|
75
|
+
function makeExporter(target, previous) {
|
|
76
|
+
return function (key, value) {
|
|
77
|
+
Object.defineProperty(target, key, { configurable: true, writable: true, value: value });
|
|
78
|
+
if (previous)
|
|
79
|
+
previous(key, value);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function functionThis() {
|
|
83
|
+
try {
|
|
84
|
+
return Function("return this;")();
|
|
85
|
+
}
|
|
86
|
+
catch (_) { }
|
|
87
|
+
}
|
|
88
|
+
function indirectEvalThis() {
|
|
89
|
+
try {
|
|
90
|
+
return (void 0, eval)("(function() { return this; })()");
|
|
91
|
+
}
|
|
92
|
+
catch (_) { }
|
|
93
|
+
}
|
|
94
|
+
function sloppyModeThis() {
|
|
95
|
+
return functionThis() || indirectEvalThis();
|
|
96
|
+
}
|
|
97
|
+
})(function (exporter, root) {
|
|
98
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
99
|
+
// feature test for Symbol support
|
|
100
|
+
var supportsSymbol = typeof Symbol === "function";
|
|
101
|
+
var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
|
|
102
|
+
var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
|
|
103
|
+
var supportsCreate = typeof Object.create === "function"; // feature test for Object.create support
|
|
104
|
+
var supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support
|
|
105
|
+
var downLevel = !supportsCreate && !supportsProto;
|
|
106
|
+
var HashMap = {
|
|
107
|
+
// create an object in dictionary mode (a.k.a. "slow" mode in v8)
|
|
108
|
+
create: supportsCreate
|
|
109
|
+
? function () { return MakeDictionary(Object.create(null)); }
|
|
110
|
+
: supportsProto
|
|
111
|
+
? function () { return MakeDictionary({ __proto__: null }); }
|
|
112
|
+
: function () { return MakeDictionary({}); },
|
|
113
|
+
has: downLevel
|
|
114
|
+
? function (map, key) { return hasOwn.call(map, key); }
|
|
115
|
+
: function (map, key) { return key in map; },
|
|
116
|
+
get: downLevel
|
|
117
|
+
? function (map, key) { return hasOwn.call(map, key) ? map[key] : undefined; }
|
|
118
|
+
: function (map, key) { return map[key]; },
|
|
119
|
+
};
|
|
120
|
+
// Load global or shim versions of Map, Set, and WeakMap
|
|
121
|
+
var functionPrototype = Object.getPrototypeOf(Function);
|
|
122
|
+
var _Map = typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
|
|
123
|
+
var _Set = typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
|
|
124
|
+
var _WeakMap = typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
|
|
125
|
+
var registrySymbol = supportsSymbol ? Symbol.for("@reflect-metadata:registry") : undefined;
|
|
126
|
+
var metadataRegistry = GetOrCreateMetadataRegistry();
|
|
127
|
+
var metadataProvider = CreateMetadataProvider(metadataRegistry);
|
|
128
|
+
/**
|
|
129
|
+
* Applies a set of decorators to a property of a target object.
|
|
130
|
+
* @param decorators An array of decorators.
|
|
131
|
+
* @param target The target object.
|
|
132
|
+
* @param propertyKey (Optional) The property key to decorate.
|
|
133
|
+
* @param attributes (Optional) The property descriptor for the target key.
|
|
134
|
+
* @remarks Decorators are applied in reverse order.
|
|
135
|
+
* @example
|
|
136
|
+
*
|
|
137
|
+
* class Example {
|
|
138
|
+
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
139
|
+
* // static staticProperty;
|
|
140
|
+
* // property;
|
|
141
|
+
*
|
|
142
|
+
* constructor(p) { }
|
|
143
|
+
* static staticMethod(p) { }
|
|
144
|
+
* method(p) { }
|
|
145
|
+
* }
|
|
146
|
+
*
|
|
147
|
+
* // constructor
|
|
148
|
+
* Example = Reflect.decorate(decoratorsArray, Example);
|
|
149
|
+
*
|
|
150
|
+
* // property (on constructor)
|
|
151
|
+
* Reflect.decorate(decoratorsArray, Example, "staticProperty");
|
|
152
|
+
*
|
|
153
|
+
* // property (on prototype)
|
|
154
|
+
* Reflect.decorate(decoratorsArray, Example.prototype, "property");
|
|
155
|
+
*
|
|
156
|
+
* // method (on constructor)
|
|
157
|
+
* Object.defineProperty(Example, "staticMethod",
|
|
158
|
+
* Reflect.decorate(decoratorsArray, Example, "staticMethod",
|
|
159
|
+
* Object.getOwnPropertyDescriptor(Example, "staticMethod")));
|
|
160
|
+
*
|
|
161
|
+
* // method (on prototype)
|
|
162
|
+
* Object.defineProperty(Example.prototype, "method",
|
|
163
|
+
* Reflect.decorate(decoratorsArray, Example.prototype, "method",
|
|
164
|
+
* Object.getOwnPropertyDescriptor(Example.prototype, "method")));
|
|
165
|
+
*
|
|
166
|
+
*/
|
|
167
|
+
function decorate(decorators, target, propertyKey, attributes) {
|
|
168
|
+
if (!IsUndefined(propertyKey)) {
|
|
169
|
+
if (!IsArray(decorators))
|
|
170
|
+
throw new TypeError();
|
|
171
|
+
if (!IsObject(target))
|
|
172
|
+
throw new TypeError();
|
|
173
|
+
if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
|
|
174
|
+
throw new TypeError();
|
|
175
|
+
if (IsNull(attributes))
|
|
176
|
+
attributes = undefined;
|
|
177
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
178
|
+
return DecorateProperty(decorators, target, propertyKey, attributes);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
if (!IsArray(decorators))
|
|
182
|
+
throw new TypeError();
|
|
183
|
+
if (!IsConstructor(target))
|
|
184
|
+
throw new TypeError();
|
|
185
|
+
return DecorateConstructor(decorators, target);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exporter("decorate", decorate);
|
|
189
|
+
// 4.1.2 Reflect.metadata(metadataKey, metadataValue)
|
|
190
|
+
// https://rbuckton.github.io/reflect-metadata/#reflect.metadata
|
|
191
|
+
/**
|
|
192
|
+
* A default metadata decorator factory that can be used on a class, class member, or parameter.
|
|
193
|
+
* @param metadataKey The key for the metadata entry.
|
|
194
|
+
* @param metadataValue The value for the metadata entry.
|
|
195
|
+
* @returns A decorator function.
|
|
196
|
+
* @remarks
|
|
197
|
+
* If `metadataKey` is already defined for the target and target key, the
|
|
198
|
+
* metadataValue for that key will be overwritten.
|
|
199
|
+
* @example
|
|
200
|
+
*
|
|
201
|
+
* // constructor
|
|
202
|
+
* @Reflect.metadata(key, value)
|
|
203
|
+
* class Example {
|
|
204
|
+
* }
|
|
205
|
+
*
|
|
206
|
+
* // property (on constructor, TypeScript only)
|
|
207
|
+
* class Example {
|
|
208
|
+
* @Reflect.metadata(key, value)
|
|
209
|
+
* static staticProperty;
|
|
210
|
+
* }
|
|
211
|
+
*
|
|
212
|
+
* // property (on prototype, TypeScript only)
|
|
213
|
+
* class Example {
|
|
214
|
+
* @Reflect.metadata(key, value)
|
|
215
|
+
* property;
|
|
216
|
+
* }
|
|
217
|
+
*
|
|
218
|
+
* // method (on constructor)
|
|
219
|
+
* class Example {
|
|
220
|
+
* @Reflect.metadata(key, value)
|
|
221
|
+
* static staticMethod() { }
|
|
222
|
+
* }
|
|
223
|
+
*
|
|
224
|
+
* // method (on prototype)
|
|
225
|
+
* class Example {
|
|
226
|
+
* @Reflect.metadata(key, value)
|
|
227
|
+
* method() { }
|
|
228
|
+
* }
|
|
229
|
+
*
|
|
230
|
+
*/
|
|
231
|
+
function metadata(metadataKey, metadataValue) {
|
|
232
|
+
function decorator(target, propertyKey) {
|
|
233
|
+
if (!IsObject(target))
|
|
234
|
+
throw new TypeError();
|
|
235
|
+
if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
|
|
236
|
+
throw new TypeError();
|
|
237
|
+
OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
|
|
238
|
+
}
|
|
239
|
+
return decorator;
|
|
240
|
+
}
|
|
241
|
+
exporter("metadata", metadata);
|
|
242
|
+
/**
|
|
243
|
+
* Define a unique metadata entry on the target.
|
|
244
|
+
* @param metadataKey A key used to store and retrieve metadata.
|
|
245
|
+
* @param metadataValue A value that contains attached metadata.
|
|
246
|
+
* @param target The target object on which to define metadata.
|
|
247
|
+
* @param propertyKey (Optional) The property key for the target.
|
|
248
|
+
* @example
|
|
249
|
+
*
|
|
250
|
+
* class Example {
|
|
251
|
+
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
252
|
+
* // static staticProperty;
|
|
253
|
+
* // property;
|
|
254
|
+
*
|
|
255
|
+
* constructor(p) { }
|
|
256
|
+
* static staticMethod(p) { }
|
|
257
|
+
* method(p) { }
|
|
258
|
+
* }
|
|
259
|
+
*
|
|
260
|
+
* // constructor
|
|
261
|
+
* Reflect.defineMetadata("custom:annotation", options, Example);
|
|
262
|
+
*
|
|
263
|
+
* // property (on constructor)
|
|
264
|
+
* Reflect.defineMetadata("custom:annotation", options, Example, "staticProperty");
|
|
265
|
+
*
|
|
266
|
+
* // property (on prototype)
|
|
267
|
+
* Reflect.defineMetadata("custom:annotation", options, Example.prototype, "property");
|
|
268
|
+
*
|
|
269
|
+
* // method (on constructor)
|
|
270
|
+
* Reflect.defineMetadata("custom:annotation", options, Example, "staticMethod");
|
|
271
|
+
*
|
|
272
|
+
* // method (on prototype)
|
|
273
|
+
* Reflect.defineMetadata("custom:annotation", options, Example.prototype, "method");
|
|
274
|
+
*
|
|
275
|
+
* // decorator factory as metadata-producing annotation.
|
|
276
|
+
* function MyAnnotation(options): Decorator {
|
|
277
|
+
* return (target, key?) => Reflect.defineMetadata("custom:annotation", options, target, key);
|
|
278
|
+
* }
|
|
279
|
+
*
|
|
280
|
+
*/
|
|
281
|
+
function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
|
|
282
|
+
if (!IsObject(target))
|
|
283
|
+
throw new TypeError();
|
|
284
|
+
if (!IsUndefined(propertyKey))
|
|
285
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
286
|
+
return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
|
|
287
|
+
}
|
|
288
|
+
exporter("defineMetadata", defineMetadata);
|
|
289
|
+
/**
|
|
290
|
+
* Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
|
|
291
|
+
* @param metadataKey A key used to store and retrieve metadata.
|
|
292
|
+
* @param target The target object on which the metadata is defined.
|
|
293
|
+
* @param propertyKey (Optional) The property key for the target.
|
|
294
|
+
* @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
|
|
295
|
+
* @example
|
|
296
|
+
*
|
|
297
|
+
* class Example {
|
|
298
|
+
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
299
|
+
* // static staticProperty;
|
|
300
|
+
* // property;
|
|
301
|
+
*
|
|
302
|
+
* constructor(p) { }
|
|
303
|
+
* static staticMethod(p) { }
|
|
304
|
+
* method(p) { }
|
|
305
|
+
* }
|
|
306
|
+
*
|
|
307
|
+
* // constructor
|
|
308
|
+
* result = Reflect.hasMetadata("custom:annotation", Example);
|
|
309
|
+
*
|
|
310
|
+
* // property (on constructor)
|
|
311
|
+
* result = Reflect.hasMetadata("custom:annotation", Example, "staticProperty");
|
|
312
|
+
*
|
|
313
|
+
* // property (on prototype)
|
|
314
|
+
* result = Reflect.hasMetadata("custom:annotation", Example.prototype, "property");
|
|
315
|
+
*
|
|
316
|
+
* // method (on constructor)
|
|
317
|
+
* result = Reflect.hasMetadata("custom:annotation", Example, "staticMethod");
|
|
318
|
+
*
|
|
319
|
+
* // method (on prototype)
|
|
320
|
+
* result = Reflect.hasMetadata("custom:annotation", Example.prototype, "method");
|
|
321
|
+
*
|
|
322
|
+
*/
|
|
323
|
+
function hasMetadata(metadataKey, target, propertyKey) {
|
|
324
|
+
if (!IsObject(target))
|
|
325
|
+
throw new TypeError();
|
|
326
|
+
if (!IsUndefined(propertyKey))
|
|
327
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
328
|
+
return OrdinaryHasMetadata(metadataKey, target, propertyKey);
|
|
329
|
+
}
|
|
330
|
+
exporter("hasMetadata", hasMetadata);
|
|
331
|
+
/**
|
|
332
|
+
* Gets a value indicating whether the target object has the provided metadata key defined.
|
|
333
|
+
* @param metadataKey A key used to store and retrieve metadata.
|
|
334
|
+
* @param target The target object on which the metadata is defined.
|
|
335
|
+
* @param propertyKey (Optional) The property key for the target.
|
|
336
|
+
* @returns `true` if the metadata key was defined on the target object; otherwise, `false`.
|
|
337
|
+
* @example
|
|
338
|
+
*
|
|
339
|
+
* class Example {
|
|
340
|
+
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
341
|
+
* // static staticProperty;
|
|
342
|
+
* // property;
|
|
343
|
+
*
|
|
344
|
+
* constructor(p) { }
|
|
345
|
+
* static staticMethod(p) { }
|
|
346
|
+
* method(p) { }
|
|
347
|
+
* }
|
|
348
|
+
*
|
|
349
|
+
* // constructor
|
|
350
|
+
* result = Reflect.hasOwnMetadata("custom:annotation", Example);
|
|
351
|
+
*
|
|
352
|
+
* // property (on constructor)
|
|
353
|
+
* result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticProperty");
|
|
354
|
+
*
|
|
355
|
+
* // property (on prototype)
|
|
356
|
+
* result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "property");
|
|
357
|
+
*
|
|
358
|
+
* // method (on constructor)
|
|
359
|
+
* result = Reflect.hasOwnMetadata("custom:annotation", Example, "staticMethod");
|
|
360
|
+
*
|
|
361
|
+
* // method (on prototype)
|
|
362
|
+
* result = Reflect.hasOwnMetadata("custom:annotation", Example.prototype, "method");
|
|
363
|
+
*
|
|
364
|
+
*/
|
|
365
|
+
function hasOwnMetadata(metadataKey, target, propertyKey) {
|
|
366
|
+
if (!IsObject(target))
|
|
367
|
+
throw new TypeError();
|
|
368
|
+
if (!IsUndefined(propertyKey))
|
|
369
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
370
|
+
return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
|
|
371
|
+
}
|
|
372
|
+
exporter("hasOwnMetadata", hasOwnMetadata);
|
|
373
|
+
/**
|
|
374
|
+
* Gets the metadata value for the provided metadata key on the target object or its prototype chain.
|
|
375
|
+
* @param metadataKey A key used to store and retrieve metadata.
|
|
376
|
+
* @param target The target object on which the metadata is defined.
|
|
377
|
+
* @param propertyKey (Optional) The property key for the target.
|
|
378
|
+
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
379
|
+
* @example
|
|
380
|
+
*
|
|
381
|
+
* class Example {
|
|
382
|
+
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
383
|
+
* // static staticProperty;
|
|
384
|
+
* // property;
|
|
385
|
+
*
|
|
386
|
+
* constructor(p) { }
|
|
387
|
+
* static staticMethod(p) { }
|
|
388
|
+
* method(p) { }
|
|
389
|
+
* }
|
|
390
|
+
*
|
|
391
|
+
* // constructor
|
|
392
|
+
* result = Reflect.getMetadata("custom:annotation", Example);
|
|
393
|
+
*
|
|
394
|
+
* // property (on constructor)
|
|
395
|
+
* result = Reflect.getMetadata("custom:annotation", Example, "staticProperty");
|
|
396
|
+
*
|
|
397
|
+
* // property (on prototype)
|
|
398
|
+
* result = Reflect.getMetadata("custom:annotation", Example.prototype, "property");
|
|
399
|
+
*
|
|
400
|
+
* // method (on constructor)
|
|
401
|
+
* result = Reflect.getMetadata("custom:annotation", Example, "staticMethod");
|
|
402
|
+
*
|
|
403
|
+
* // method (on prototype)
|
|
404
|
+
* result = Reflect.getMetadata("custom:annotation", Example.prototype, "method");
|
|
405
|
+
*
|
|
406
|
+
*/
|
|
407
|
+
function getMetadata(metadataKey, target, propertyKey) {
|
|
408
|
+
if (!IsObject(target))
|
|
409
|
+
throw new TypeError();
|
|
410
|
+
if (!IsUndefined(propertyKey))
|
|
411
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
412
|
+
return OrdinaryGetMetadata(metadataKey, target, propertyKey);
|
|
413
|
+
}
|
|
414
|
+
exporter("getMetadata", getMetadata);
|
|
415
|
+
/**
|
|
416
|
+
* Gets the metadata value for the provided metadata key on the target object.
|
|
417
|
+
* @param metadataKey A key used to store and retrieve metadata.
|
|
418
|
+
* @param target The target object on which the metadata is defined.
|
|
419
|
+
* @param propertyKey (Optional) The property key for the target.
|
|
420
|
+
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
421
|
+
* @example
|
|
422
|
+
*
|
|
423
|
+
* class Example {
|
|
424
|
+
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
425
|
+
* // static staticProperty;
|
|
426
|
+
* // property;
|
|
427
|
+
*
|
|
428
|
+
* constructor(p) { }
|
|
429
|
+
* static staticMethod(p) { }
|
|
430
|
+
* method(p) { }
|
|
431
|
+
* }
|
|
432
|
+
*
|
|
433
|
+
* // constructor
|
|
434
|
+
* result = Reflect.getOwnMetadata("custom:annotation", Example);
|
|
435
|
+
*
|
|
436
|
+
* // property (on constructor)
|
|
437
|
+
* result = Reflect.getOwnMetadata("custom:annotation", Example, "staticProperty");
|
|
438
|
+
*
|
|
439
|
+
* // property (on prototype)
|
|
440
|
+
* result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "property");
|
|
441
|
+
*
|
|
442
|
+
* // method (on constructor)
|
|
443
|
+
* result = Reflect.getOwnMetadata("custom:annotation", Example, "staticMethod");
|
|
444
|
+
*
|
|
445
|
+
* // method (on prototype)
|
|
446
|
+
* result = Reflect.getOwnMetadata("custom:annotation", Example.prototype, "method");
|
|
447
|
+
*
|
|
448
|
+
*/
|
|
449
|
+
function getOwnMetadata(metadataKey, target, propertyKey) {
|
|
450
|
+
if (!IsObject(target))
|
|
451
|
+
throw new TypeError();
|
|
452
|
+
if (!IsUndefined(propertyKey))
|
|
453
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
454
|
+
return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
|
|
455
|
+
}
|
|
456
|
+
exporter("getOwnMetadata", getOwnMetadata);
|
|
457
|
+
/**
|
|
458
|
+
* Gets the metadata keys defined on the target object or its prototype chain.
|
|
459
|
+
* @param target The target object on which the metadata is defined.
|
|
460
|
+
* @param propertyKey (Optional) The property key for the target.
|
|
461
|
+
* @returns An array of unique metadata keys.
|
|
462
|
+
* @example
|
|
463
|
+
*
|
|
464
|
+
* class Example {
|
|
465
|
+
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
466
|
+
* // static staticProperty;
|
|
467
|
+
* // property;
|
|
468
|
+
*
|
|
469
|
+
* constructor(p) { }
|
|
470
|
+
* static staticMethod(p) { }
|
|
471
|
+
* method(p) { }
|
|
472
|
+
* }
|
|
473
|
+
*
|
|
474
|
+
* // constructor
|
|
475
|
+
* result = Reflect.getMetadataKeys(Example);
|
|
476
|
+
*
|
|
477
|
+
* // property (on constructor)
|
|
478
|
+
* result = Reflect.getMetadataKeys(Example, "staticProperty");
|
|
479
|
+
*
|
|
480
|
+
* // property (on prototype)
|
|
481
|
+
* result = Reflect.getMetadataKeys(Example.prototype, "property");
|
|
482
|
+
*
|
|
483
|
+
* // method (on constructor)
|
|
484
|
+
* result = Reflect.getMetadataKeys(Example, "staticMethod");
|
|
485
|
+
*
|
|
486
|
+
* // method (on prototype)
|
|
487
|
+
* result = Reflect.getMetadataKeys(Example.prototype, "method");
|
|
488
|
+
*
|
|
489
|
+
*/
|
|
490
|
+
function getMetadataKeys(target, propertyKey) {
|
|
491
|
+
if (!IsObject(target))
|
|
492
|
+
throw new TypeError();
|
|
493
|
+
if (!IsUndefined(propertyKey))
|
|
494
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
495
|
+
return OrdinaryMetadataKeys(target, propertyKey);
|
|
496
|
+
}
|
|
497
|
+
exporter("getMetadataKeys", getMetadataKeys);
|
|
498
|
+
/**
|
|
499
|
+
* Gets the unique metadata keys defined on the target object.
|
|
500
|
+
* @param target The target object on which the metadata is defined.
|
|
501
|
+
* @param propertyKey (Optional) The property key for the target.
|
|
502
|
+
* @returns An array of unique metadata keys.
|
|
503
|
+
* @example
|
|
504
|
+
*
|
|
505
|
+
* class Example {
|
|
506
|
+
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
507
|
+
* // static staticProperty;
|
|
508
|
+
* // property;
|
|
509
|
+
*
|
|
510
|
+
* constructor(p) { }
|
|
511
|
+
* static staticMethod(p) { }
|
|
512
|
+
* method(p) { }
|
|
513
|
+
* }
|
|
514
|
+
*
|
|
515
|
+
* // constructor
|
|
516
|
+
* result = Reflect.getOwnMetadataKeys(Example);
|
|
517
|
+
*
|
|
518
|
+
* // property (on constructor)
|
|
519
|
+
* result = Reflect.getOwnMetadataKeys(Example, "staticProperty");
|
|
520
|
+
*
|
|
521
|
+
* // property (on prototype)
|
|
522
|
+
* result = Reflect.getOwnMetadataKeys(Example.prototype, "property");
|
|
523
|
+
*
|
|
524
|
+
* // method (on constructor)
|
|
525
|
+
* result = Reflect.getOwnMetadataKeys(Example, "staticMethod");
|
|
526
|
+
*
|
|
527
|
+
* // method (on prototype)
|
|
528
|
+
* result = Reflect.getOwnMetadataKeys(Example.prototype, "method");
|
|
529
|
+
*
|
|
530
|
+
*/
|
|
531
|
+
function getOwnMetadataKeys(target, propertyKey) {
|
|
532
|
+
if (!IsObject(target))
|
|
533
|
+
throw new TypeError();
|
|
534
|
+
if (!IsUndefined(propertyKey))
|
|
535
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
536
|
+
return OrdinaryOwnMetadataKeys(target, propertyKey);
|
|
537
|
+
}
|
|
538
|
+
exporter("getOwnMetadataKeys", getOwnMetadataKeys);
|
|
539
|
+
/**
|
|
540
|
+
* Deletes the metadata entry from the target object with the provided key.
|
|
541
|
+
* @param metadataKey A key used to store and retrieve metadata.
|
|
542
|
+
* @param target The target object on which the metadata is defined.
|
|
543
|
+
* @param propertyKey (Optional) The property key for the target.
|
|
544
|
+
* @returns `true` if the metadata entry was found and deleted; otherwise, false.
|
|
545
|
+
* @example
|
|
546
|
+
*
|
|
547
|
+
* class Example {
|
|
548
|
+
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
549
|
+
* // static staticProperty;
|
|
550
|
+
* // property;
|
|
551
|
+
*
|
|
552
|
+
* constructor(p) { }
|
|
553
|
+
* static staticMethod(p) { }
|
|
554
|
+
* method(p) { }
|
|
555
|
+
* }
|
|
556
|
+
*
|
|
557
|
+
* // constructor
|
|
558
|
+
* result = Reflect.deleteMetadata("custom:annotation", Example);
|
|
559
|
+
*
|
|
560
|
+
* // property (on constructor)
|
|
561
|
+
* result = Reflect.deleteMetadata("custom:annotation", Example, "staticProperty");
|
|
562
|
+
*
|
|
563
|
+
* // property (on prototype)
|
|
564
|
+
* result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "property");
|
|
565
|
+
*
|
|
566
|
+
* // method (on constructor)
|
|
567
|
+
* result = Reflect.deleteMetadata("custom:annotation", Example, "staticMethod");
|
|
568
|
+
*
|
|
569
|
+
* // method (on prototype)
|
|
570
|
+
* result = Reflect.deleteMetadata("custom:annotation", Example.prototype, "method");
|
|
571
|
+
*
|
|
572
|
+
*/
|
|
573
|
+
function deleteMetadata(metadataKey, target, propertyKey) {
|
|
574
|
+
if (!IsObject(target))
|
|
575
|
+
throw new TypeError();
|
|
576
|
+
if (!IsUndefined(propertyKey))
|
|
577
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
578
|
+
if (!IsObject(target))
|
|
579
|
+
throw new TypeError();
|
|
580
|
+
if (!IsUndefined(propertyKey))
|
|
581
|
+
propertyKey = ToPropertyKey(propertyKey);
|
|
582
|
+
var provider = GetMetadataProvider(target, propertyKey, /*Create*/ false);
|
|
583
|
+
if (IsUndefined(provider))
|
|
584
|
+
return false;
|
|
585
|
+
return provider.OrdinaryDeleteMetadata(metadataKey, target, propertyKey);
|
|
586
|
+
}
|
|
587
|
+
exporter("deleteMetadata", deleteMetadata);
|
|
588
|
+
function DecorateConstructor(decorators, target) {
|
|
589
|
+
for (var i = decorators.length - 1; i >= 0; --i) {
|
|
590
|
+
var decorator = decorators[i];
|
|
591
|
+
var decorated = decorator(target);
|
|
592
|
+
if (!IsUndefined(decorated) && !IsNull(decorated)) {
|
|
593
|
+
if (!IsConstructor(decorated))
|
|
594
|
+
throw new TypeError();
|
|
595
|
+
target = decorated;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return target;
|
|
599
|
+
}
|
|
600
|
+
function DecorateProperty(decorators, target, propertyKey, descriptor) {
|
|
601
|
+
for (var i = decorators.length - 1; i >= 0; --i) {
|
|
602
|
+
var decorator = decorators[i];
|
|
603
|
+
var decorated = decorator(target, propertyKey, descriptor);
|
|
604
|
+
if (!IsUndefined(decorated) && !IsNull(decorated)) {
|
|
605
|
+
if (!IsObject(decorated))
|
|
606
|
+
throw new TypeError();
|
|
607
|
+
descriptor = decorated;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
return descriptor;
|
|
611
|
+
}
|
|
612
|
+
// 3.1.1.1 OrdinaryHasMetadata(MetadataKey, O, P)
|
|
613
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinaryhasmetadata
|
|
614
|
+
function OrdinaryHasMetadata(MetadataKey, O, P) {
|
|
615
|
+
var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
|
|
616
|
+
if (hasOwn)
|
|
617
|
+
return true;
|
|
618
|
+
var parent = OrdinaryGetPrototypeOf(O);
|
|
619
|
+
if (!IsNull(parent))
|
|
620
|
+
return OrdinaryHasMetadata(MetadataKey, parent, P);
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
// 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
|
|
624
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
|
|
625
|
+
function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
|
|
626
|
+
var provider = GetMetadataProvider(O, P, /*Create*/ false);
|
|
627
|
+
if (IsUndefined(provider))
|
|
628
|
+
return false;
|
|
629
|
+
return ToBoolean(provider.OrdinaryHasOwnMetadata(MetadataKey, O, P));
|
|
630
|
+
}
|
|
631
|
+
// 3.1.3.1 OrdinaryGetMetadata(MetadataKey, O, P)
|
|
632
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinarygetmetadata
|
|
633
|
+
function OrdinaryGetMetadata(MetadataKey, O, P) {
|
|
634
|
+
var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);
|
|
635
|
+
if (hasOwn)
|
|
636
|
+
return OrdinaryGetOwnMetadata(MetadataKey, O, P);
|
|
637
|
+
var parent = OrdinaryGetPrototypeOf(O);
|
|
638
|
+
if (!IsNull(parent))
|
|
639
|
+
return OrdinaryGetMetadata(MetadataKey, parent, P);
|
|
640
|
+
return undefined;
|
|
641
|
+
}
|
|
642
|
+
// 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
|
|
643
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
|
|
644
|
+
function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
|
|
645
|
+
var provider = GetMetadataProvider(O, P, /*Create*/ false);
|
|
646
|
+
if (IsUndefined(provider))
|
|
647
|
+
return;
|
|
648
|
+
return provider.OrdinaryGetOwnMetadata(MetadataKey, O, P);
|
|
649
|
+
}
|
|
650
|
+
// 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
|
|
651
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
|
|
652
|
+
function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
|
|
653
|
+
var provider = GetMetadataProvider(O, P, /*Create*/ true);
|
|
654
|
+
provider.OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P);
|
|
655
|
+
}
|
|
656
|
+
// 3.1.6.1 OrdinaryMetadataKeys(O, P)
|
|
657
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinarymetadatakeys
|
|
658
|
+
function OrdinaryMetadataKeys(O, P) {
|
|
659
|
+
var ownKeys = OrdinaryOwnMetadataKeys(O, P);
|
|
660
|
+
var parent = OrdinaryGetPrototypeOf(O);
|
|
661
|
+
if (parent === null)
|
|
662
|
+
return ownKeys;
|
|
663
|
+
var parentKeys = OrdinaryMetadataKeys(parent, P);
|
|
664
|
+
if (parentKeys.length <= 0)
|
|
665
|
+
return ownKeys;
|
|
666
|
+
if (ownKeys.length <= 0)
|
|
667
|
+
return parentKeys;
|
|
668
|
+
var set = new _Set();
|
|
669
|
+
var keys = [];
|
|
670
|
+
for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {
|
|
671
|
+
var key = ownKeys_1[_i];
|
|
672
|
+
var hasKey = set.has(key);
|
|
673
|
+
if (!hasKey) {
|
|
674
|
+
set.add(key);
|
|
675
|
+
keys.push(key);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {
|
|
679
|
+
var key = parentKeys_1[_a];
|
|
680
|
+
var hasKey = set.has(key);
|
|
681
|
+
if (!hasKey) {
|
|
682
|
+
set.add(key);
|
|
683
|
+
keys.push(key);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
return keys;
|
|
687
|
+
}
|
|
688
|
+
// 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
|
|
689
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
|
|
690
|
+
function OrdinaryOwnMetadataKeys(O, P) {
|
|
691
|
+
var provider = GetMetadataProvider(O, P, /*create*/ false);
|
|
692
|
+
if (!provider) {
|
|
693
|
+
return [];
|
|
694
|
+
}
|
|
695
|
+
return provider.OrdinaryOwnMetadataKeys(O, P);
|
|
696
|
+
}
|
|
697
|
+
// 6 ECMAScript Data Typ0es and Values
|
|
698
|
+
// https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values
|
|
699
|
+
function Type(x) {
|
|
700
|
+
if (x === null)
|
|
701
|
+
return 1 /* Null */;
|
|
702
|
+
switch (typeof x) {
|
|
703
|
+
case "undefined": return 0 /* Undefined */;
|
|
704
|
+
case "boolean": return 2 /* Boolean */;
|
|
705
|
+
case "string": return 3 /* String */;
|
|
706
|
+
case "symbol": return 4 /* Symbol */;
|
|
707
|
+
case "number": return 5 /* Number */;
|
|
708
|
+
case "object": return x === null ? 1 /* Null */ : 6 /* Object */;
|
|
709
|
+
default: return 6 /* Object */;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
// 6.1.1 The Undefined Type
|
|
713
|
+
// https://tc39.github.io/ecma262/#sec-ecmascript-language-types-undefined-type
|
|
714
|
+
function IsUndefined(x) {
|
|
715
|
+
return x === undefined;
|
|
716
|
+
}
|
|
717
|
+
// 6.1.2 The Null Type
|
|
718
|
+
// https://tc39.github.io/ecma262/#sec-ecmascript-language-types-null-type
|
|
719
|
+
function IsNull(x) {
|
|
720
|
+
return x === null;
|
|
721
|
+
}
|
|
722
|
+
// 6.1.5 The Symbol Type
|
|
723
|
+
// https://tc39.github.io/ecma262/#sec-ecmascript-language-types-symbol-type
|
|
724
|
+
function IsSymbol(x) {
|
|
725
|
+
return typeof x === "symbol";
|
|
726
|
+
}
|
|
727
|
+
// 6.1.7 The Object Type
|
|
728
|
+
// https://tc39.github.io/ecma262/#sec-object-type
|
|
729
|
+
function IsObject(x) {
|
|
730
|
+
return typeof x === "object" ? x !== null : typeof x === "function";
|
|
731
|
+
}
|
|
732
|
+
// 7.1 Type Conversion
|
|
733
|
+
// https://tc39.github.io/ecma262/#sec-type-conversion
|
|
734
|
+
// 7.1.1 ToPrimitive(input [, PreferredType])
|
|
735
|
+
// https://tc39.github.io/ecma262/#sec-toprimitive
|
|
736
|
+
function ToPrimitive(input, PreferredType) {
|
|
737
|
+
switch (Type(input)) {
|
|
738
|
+
case 0 /* Undefined */: return input;
|
|
739
|
+
case 1 /* Null */: return input;
|
|
740
|
+
case 2 /* Boolean */: return input;
|
|
741
|
+
case 3 /* String */: return input;
|
|
742
|
+
case 4 /* Symbol */: return input;
|
|
743
|
+
case 5 /* Number */: return input;
|
|
744
|
+
}
|
|
745
|
+
var hint = "string" ;
|
|
746
|
+
var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
|
|
747
|
+
if (exoticToPrim !== undefined) {
|
|
748
|
+
var result = exoticToPrim.call(input, hint);
|
|
749
|
+
if (IsObject(result))
|
|
750
|
+
throw new TypeError();
|
|
751
|
+
return result;
|
|
752
|
+
}
|
|
753
|
+
return OrdinaryToPrimitive(input);
|
|
754
|
+
}
|
|
755
|
+
// 7.1.1.1 OrdinaryToPrimitive(O, hint)
|
|
756
|
+
// https://tc39.github.io/ecma262/#sec-ordinarytoprimitive
|
|
757
|
+
function OrdinaryToPrimitive(O, hint) {
|
|
758
|
+
var valueOf, result; {
|
|
759
|
+
var toString_1 = O.toString;
|
|
760
|
+
if (IsCallable(toString_1)) {
|
|
761
|
+
var result = toString_1.call(O);
|
|
762
|
+
if (!IsObject(result))
|
|
763
|
+
return result;
|
|
764
|
+
}
|
|
765
|
+
var valueOf = O.valueOf;
|
|
766
|
+
if (IsCallable(valueOf)) {
|
|
767
|
+
var result = valueOf.call(O);
|
|
768
|
+
if (!IsObject(result))
|
|
769
|
+
return result;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
throw new TypeError();
|
|
773
|
+
}
|
|
774
|
+
// 7.1.2 ToBoolean(argument)
|
|
775
|
+
// https://tc39.github.io/ecma262/2016/#sec-toboolean
|
|
776
|
+
function ToBoolean(argument) {
|
|
777
|
+
return !!argument;
|
|
778
|
+
}
|
|
779
|
+
// 7.1.12 ToString(argument)
|
|
780
|
+
// https://tc39.github.io/ecma262/#sec-tostring
|
|
781
|
+
function ToString(argument) {
|
|
782
|
+
return "" + argument;
|
|
783
|
+
}
|
|
784
|
+
// 7.1.14 ToPropertyKey(argument)
|
|
785
|
+
// https://tc39.github.io/ecma262/#sec-topropertykey
|
|
786
|
+
function ToPropertyKey(argument) {
|
|
787
|
+
var key = ToPrimitive(argument);
|
|
788
|
+
if (IsSymbol(key))
|
|
789
|
+
return key;
|
|
790
|
+
return ToString(key);
|
|
791
|
+
}
|
|
792
|
+
// 7.2 Testing and Comparison Operations
|
|
793
|
+
// https://tc39.github.io/ecma262/#sec-testing-and-comparison-operations
|
|
794
|
+
// 7.2.2 IsArray(argument)
|
|
795
|
+
// https://tc39.github.io/ecma262/#sec-isarray
|
|
796
|
+
function IsArray(argument) {
|
|
797
|
+
return Array.isArray
|
|
798
|
+
? Array.isArray(argument)
|
|
799
|
+
: argument instanceof Object
|
|
800
|
+
? argument instanceof Array
|
|
801
|
+
: Object.prototype.toString.call(argument) === "[object Array]";
|
|
802
|
+
}
|
|
803
|
+
// 7.2.3 IsCallable(argument)
|
|
804
|
+
// https://tc39.github.io/ecma262/#sec-iscallable
|
|
805
|
+
function IsCallable(argument) {
|
|
806
|
+
// NOTE: This is an approximation as we cannot check for [[Call]] internal method.
|
|
807
|
+
return typeof argument === "function";
|
|
808
|
+
}
|
|
809
|
+
// 7.2.4 IsConstructor(argument)
|
|
810
|
+
// https://tc39.github.io/ecma262/#sec-isconstructor
|
|
811
|
+
function IsConstructor(argument) {
|
|
812
|
+
// NOTE: This is an approximation as we cannot check for [[Construct]] internal method.
|
|
813
|
+
return typeof argument === "function";
|
|
814
|
+
}
|
|
815
|
+
// 7.2.7 IsPropertyKey(argument)
|
|
816
|
+
// https://tc39.github.io/ecma262/#sec-ispropertykey
|
|
817
|
+
function IsPropertyKey(argument) {
|
|
818
|
+
switch (Type(argument)) {
|
|
819
|
+
case 3 /* String */: return true;
|
|
820
|
+
case 4 /* Symbol */: return true;
|
|
821
|
+
default: return false;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
function SameValueZero(x, y) {
|
|
825
|
+
return x === y || x !== x && y !== y;
|
|
826
|
+
}
|
|
827
|
+
// 7.3 Operations on Objects
|
|
828
|
+
// https://tc39.github.io/ecma262/#sec-operations-on-objects
|
|
829
|
+
// 7.3.9 GetMethod(V, P)
|
|
830
|
+
// https://tc39.github.io/ecma262/#sec-getmethod
|
|
831
|
+
function GetMethod(V, P) {
|
|
832
|
+
var func = V[P];
|
|
833
|
+
if (func === undefined || func === null)
|
|
834
|
+
return undefined;
|
|
835
|
+
if (!IsCallable(func))
|
|
836
|
+
throw new TypeError();
|
|
837
|
+
return func;
|
|
838
|
+
}
|
|
839
|
+
// 7.4 Operations on Iterator Objects
|
|
840
|
+
// https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects
|
|
841
|
+
function GetIterator(obj) {
|
|
842
|
+
var method = GetMethod(obj, iteratorSymbol);
|
|
843
|
+
if (!IsCallable(method))
|
|
844
|
+
throw new TypeError(); // from Call
|
|
845
|
+
var iterator = method.call(obj);
|
|
846
|
+
if (!IsObject(iterator))
|
|
847
|
+
throw new TypeError();
|
|
848
|
+
return iterator;
|
|
849
|
+
}
|
|
850
|
+
// 7.4.4 IteratorValue(iterResult)
|
|
851
|
+
// https://tc39.github.io/ecma262/2016/#sec-iteratorvalue
|
|
852
|
+
function IteratorValue(iterResult) {
|
|
853
|
+
return iterResult.value;
|
|
854
|
+
}
|
|
855
|
+
// 7.4.5 IteratorStep(iterator)
|
|
856
|
+
// https://tc39.github.io/ecma262/#sec-iteratorstep
|
|
857
|
+
function IteratorStep(iterator) {
|
|
858
|
+
var result = iterator.next();
|
|
859
|
+
return result.done ? false : result;
|
|
860
|
+
}
|
|
861
|
+
// 7.4.6 IteratorClose(iterator, completion)
|
|
862
|
+
// https://tc39.github.io/ecma262/#sec-iteratorclose
|
|
863
|
+
function IteratorClose(iterator) {
|
|
864
|
+
var f = iterator["return"];
|
|
865
|
+
if (f)
|
|
866
|
+
f.call(iterator);
|
|
867
|
+
}
|
|
868
|
+
// 9.1 Ordinary Object Internal Methods and Internal Slots
|
|
869
|
+
// https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
|
|
870
|
+
// 9.1.1.1 OrdinaryGetPrototypeOf(O)
|
|
871
|
+
// https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof
|
|
872
|
+
function OrdinaryGetPrototypeOf(O) {
|
|
873
|
+
var proto = Object.getPrototypeOf(O);
|
|
874
|
+
if (typeof O !== "function" || O === functionPrototype)
|
|
875
|
+
return proto;
|
|
876
|
+
// TypeScript doesn't set __proto__ in ES5, as it's non-standard.
|
|
877
|
+
// Try to determine the superclass constructor. Compatible implementations
|
|
878
|
+
// must either set __proto__ on a subclass constructor to the superclass constructor,
|
|
879
|
+
// or ensure each class has a valid `constructor` property on its prototype that
|
|
880
|
+
// points back to the constructor.
|
|
881
|
+
// If this is not the same as Function.[[Prototype]], then this is definately inherited.
|
|
882
|
+
// This is the case when in ES6 or when using __proto__ in a compatible browser.
|
|
883
|
+
if (proto !== functionPrototype)
|
|
884
|
+
return proto;
|
|
885
|
+
// If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage.
|
|
886
|
+
var prototype = O.prototype;
|
|
887
|
+
var prototypeProto = prototype && Object.getPrototypeOf(prototype);
|
|
888
|
+
if (prototypeProto == null || prototypeProto === Object.prototype)
|
|
889
|
+
return proto;
|
|
890
|
+
// If the constructor was not a function, then we cannot determine the heritage.
|
|
891
|
+
var constructor = prototypeProto.constructor;
|
|
892
|
+
if (typeof constructor !== "function")
|
|
893
|
+
return proto;
|
|
894
|
+
// If we have some kind of self-reference, then we cannot determine the heritage.
|
|
895
|
+
if (constructor === O)
|
|
896
|
+
return proto;
|
|
897
|
+
// we have a pretty good guess at the heritage.
|
|
898
|
+
return constructor;
|
|
899
|
+
}
|
|
900
|
+
// Global metadata registry
|
|
901
|
+
// - Allows `import "reflect-metadata"` and `import "reflect-metadata/no-conflict"` to interoperate.
|
|
902
|
+
// - Uses isolated metadata if `Reflect` is frozen before the registry can be installed.
|
|
903
|
+
/**
|
|
904
|
+
* Creates a registry used to allow multiple `reflect-metadata` providers.
|
|
905
|
+
*/
|
|
906
|
+
function CreateMetadataRegistry() {
|
|
907
|
+
var fallback;
|
|
908
|
+
if (!IsUndefined(registrySymbol) &&
|
|
909
|
+
typeof root.Reflect !== "undefined" &&
|
|
910
|
+
!(registrySymbol in root.Reflect) &&
|
|
911
|
+
typeof root.Reflect.defineMetadata === "function") {
|
|
912
|
+
// interoperate with older version of `reflect-metadata` that did not support a registry.
|
|
913
|
+
fallback = CreateFallbackProvider(root.Reflect);
|
|
914
|
+
}
|
|
915
|
+
var first;
|
|
916
|
+
var second;
|
|
917
|
+
var rest;
|
|
918
|
+
var targetProviderMap = new _WeakMap();
|
|
919
|
+
var registry = {
|
|
920
|
+
registerProvider: registerProvider,
|
|
921
|
+
getProvider: getProvider,
|
|
922
|
+
setProvider: setProvider,
|
|
923
|
+
};
|
|
924
|
+
return registry;
|
|
925
|
+
function registerProvider(provider) {
|
|
926
|
+
if (!Object.isExtensible(registry)) {
|
|
927
|
+
throw new Error("Cannot add provider to a frozen registry.");
|
|
928
|
+
}
|
|
929
|
+
switch (true) {
|
|
930
|
+
case fallback === provider: break;
|
|
931
|
+
case IsUndefined(first):
|
|
932
|
+
first = provider;
|
|
933
|
+
break;
|
|
934
|
+
case first === provider: break;
|
|
935
|
+
case IsUndefined(second):
|
|
936
|
+
second = provider;
|
|
937
|
+
break;
|
|
938
|
+
case second === provider: break;
|
|
939
|
+
default:
|
|
940
|
+
if (rest === undefined)
|
|
941
|
+
rest = new _Set();
|
|
942
|
+
rest.add(provider);
|
|
943
|
+
break;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
function getProviderNoCache(O, P) {
|
|
947
|
+
if (!IsUndefined(first)) {
|
|
948
|
+
if (first.isProviderFor(O, P))
|
|
949
|
+
return first;
|
|
950
|
+
if (!IsUndefined(second)) {
|
|
951
|
+
if (second.isProviderFor(O, P))
|
|
952
|
+
return first;
|
|
953
|
+
if (!IsUndefined(rest)) {
|
|
954
|
+
var iterator = GetIterator(rest);
|
|
955
|
+
while (true) {
|
|
956
|
+
var next = IteratorStep(iterator);
|
|
957
|
+
if (!next) {
|
|
958
|
+
return undefined;
|
|
959
|
+
}
|
|
960
|
+
var provider = IteratorValue(next);
|
|
961
|
+
if (provider.isProviderFor(O, P)) {
|
|
962
|
+
IteratorClose(iterator);
|
|
963
|
+
return provider;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
if (!IsUndefined(fallback) && fallback.isProviderFor(O, P)) {
|
|
970
|
+
return fallback;
|
|
971
|
+
}
|
|
972
|
+
return undefined;
|
|
973
|
+
}
|
|
974
|
+
function getProvider(O, P) {
|
|
975
|
+
var providerMap = targetProviderMap.get(O);
|
|
976
|
+
var provider;
|
|
977
|
+
if (!IsUndefined(providerMap)) {
|
|
978
|
+
provider = providerMap.get(P);
|
|
979
|
+
}
|
|
980
|
+
if (!IsUndefined(provider)) {
|
|
981
|
+
return provider;
|
|
982
|
+
}
|
|
983
|
+
provider = getProviderNoCache(O, P);
|
|
984
|
+
if (!IsUndefined(provider)) {
|
|
985
|
+
if (IsUndefined(providerMap)) {
|
|
986
|
+
providerMap = new _Map();
|
|
987
|
+
targetProviderMap.set(O, providerMap);
|
|
988
|
+
}
|
|
989
|
+
providerMap.set(P, provider);
|
|
990
|
+
}
|
|
991
|
+
return provider;
|
|
992
|
+
}
|
|
993
|
+
function hasProvider(provider) {
|
|
994
|
+
if (IsUndefined(provider))
|
|
995
|
+
throw new TypeError();
|
|
996
|
+
return first === provider || second === provider || !IsUndefined(rest) && rest.has(provider);
|
|
997
|
+
}
|
|
998
|
+
function setProvider(O, P, provider) {
|
|
999
|
+
if (!hasProvider(provider)) {
|
|
1000
|
+
throw new Error("Metadata provider not registered.");
|
|
1001
|
+
}
|
|
1002
|
+
var existingProvider = getProvider(O, P);
|
|
1003
|
+
if (existingProvider !== provider) {
|
|
1004
|
+
if (!IsUndefined(existingProvider)) {
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
var providerMap = targetProviderMap.get(O);
|
|
1008
|
+
if (IsUndefined(providerMap)) {
|
|
1009
|
+
providerMap = new _Map();
|
|
1010
|
+
targetProviderMap.set(O, providerMap);
|
|
1011
|
+
}
|
|
1012
|
+
providerMap.set(P, provider);
|
|
1013
|
+
}
|
|
1014
|
+
return true;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Gets or creates the shared registry of metadata providers.
|
|
1019
|
+
*/
|
|
1020
|
+
function GetOrCreateMetadataRegistry() {
|
|
1021
|
+
var metadataRegistry;
|
|
1022
|
+
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
|
|
1023
|
+
metadataRegistry = root.Reflect[registrySymbol];
|
|
1024
|
+
}
|
|
1025
|
+
if (IsUndefined(metadataRegistry)) {
|
|
1026
|
+
metadataRegistry = CreateMetadataRegistry();
|
|
1027
|
+
}
|
|
1028
|
+
if (!IsUndefined(registrySymbol) && IsObject(root.Reflect) && Object.isExtensible(root.Reflect)) {
|
|
1029
|
+
Object.defineProperty(root.Reflect, registrySymbol, {
|
|
1030
|
+
enumerable: false,
|
|
1031
|
+
configurable: false,
|
|
1032
|
+
writable: false,
|
|
1033
|
+
value: metadataRegistry
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
return metadataRegistry;
|
|
1037
|
+
}
|
|
1038
|
+
function CreateMetadataProvider(registry) {
|
|
1039
|
+
// [[Metadata]] internal slot
|
|
1040
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots
|
|
1041
|
+
var metadata = new _WeakMap();
|
|
1042
|
+
var provider = {
|
|
1043
|
+
isProviderFor: function (O, P) {
|
|
1044
|
+
var targetMetadata = metadata.get(O);
|
|
1045
|
+
if (IsUndefined(targetMetadata))
|
|
1046
|
+
return false;
|
|
1047
|
+
return targetMetadata.has(P);
|
|
1048
|
+
},
|
|
1049
|
+
OrdinaryDefineOwnMetadata: OrdinaryDefineOwnMetadata,
|
|
1050
|
+
OrdinaryHasOwnMetadata: OrdinaryHasOwnMetadata,
|
|
1051
|
+
OrdinaryGetOwnMetadata: OrdinaryGetOwnMetadata,
|
|
1052
|
+
OrdinaryOwnMetadataKeys: OrdinaryOwnMetadataKeys,
|
|
1053
|
+
OrdinaryDeleteMetadata: OrdinaryDeleteMetadata,
|
|
1054
|
+
};
|
|
1055
|
+
metadataRegistry.registerProvider(provider);
|
|
1056
|
+
return provider;
|
|
1057
|
+
function GetOrCreateMetadataMap(O, P, Create) {
|
|
1058
|
+
var targetMetadata = metadata.get(O);
|
|
1059
|
+
var createdTargetMetadata = false;
|
|
1060
|
+
if (IsUndefined(targetMetadata)) {
|
|
1061
|
+
if (!Create)
|
|
1062
|
+
return undefined;
|
|
1063
|
+
targetMetadata = new _Map();
|
|
1064
|
+
metadata.set(O, targetMetadata);
|
|
1065
|
+
createdTargetMetadata = true;
|
|
1066
|
+
}
|
|
1067
|
+
var metadataMap = targetMetadata.get(P);
|
|
1068
|
+
if (IsUndefined(metadataMap)) {
|
|
1069
|
+
if (!Create)
|
|
1070
|
+
return undefined;
|
|
1071
|
+
metadataMap = new _Map();
|
|
1072
|
+
targetMetadata.set(P, metadataMap);
|
|
1073
|
+
if (!registry.setProvider(O, P, provider)) {
|
|
1074
|
+
targetMetadata.delete(P);
|
|
1075
|
+
if (createdTargetMetadata) {
|
|
1076
|
+
metadata.delete(O);
|
|
1077
|
+
}
|
|
1078
|
+
throw new Error("Wrong provider for target.");
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
return metadataMap;
|
|
1082
|
+
}
|
|
1083
|
+
// 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)
|
|
1084
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata
|
|
1085
|
+
function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
|
|
1086
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
|
|
1087
|
+
if (IsUndefined(metadataMap))
|
|
1088
|
+
return false;
|
|
1089
|
+
return ToBoolean(metadataMap.has(MetadataKey));
|
|
1090
|
+
}
|
|
1091
|
+
// 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)
|
|
1092
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata
|
|
1093
|
+
function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
|
|
1094
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
|
|
1095
|
+
if (IsUndefined(metadataMap))
|
|
1096
|
+
return undefined;
|
|
1097
|
+
return metadataMap.get(MetadataKey);
|
|
1098
|
+
}
|
|
1099
|
+
// 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)
|
|
1100
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata
|
|
1101
|
+
function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
|
|
1102
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ true);
|
|
1103
|
+
metadataMap.set(MetadataKey, MetadataValue);
|
|
1104
|
+
}
|
|
1105
|
+
// 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)
|
|
1106
|
+
// https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys
|
|
1107
|
+
function OrdinaryOwnMetadataKeys(O, P) {
|
|
1108
|
+
var keys = [];
|
|
1109
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
|
|
1110
|
+
if (IsUndefined(metadataMap))
|
|
1111
|
+
return keys;
|
|
1112
|
+
var keysObj = metadataMap.keys();
|
|
1113
|
+
var iterator = GetIterator(keysObj);
|
|
1114
|
+
var k = 0;
|
|
1115
|
+
while (true) {
|
|
1116
|
+
var next = IteratorStep(iterator);
|
|
1117
|
+
if (!next) {
|
|
1118
|
+
keys.length = k;
|
|
1119
|
+
return keys;
|
|
1120
|
+
}
|
|
1121
|
+
var nextValue = IteratorValue(next);
|
|
1122
|
+
try {
|
|
1123
|
+
keys[k] = nextValue;
|
|
1124
|
+
}
|
|
1125
|
+
catch (e) {
|
|
1126
|
+
try {
|
|
1127
|
+
IteratorClose(iterator);
|
|
1128
|
+
}
|
|
1129
|
+
finally {
|
|
1130
|
+
throw e;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
k++;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
function OrdinaryDeleteMetadata(MetadataKey, O, P) {
|
|
1137
|
+
var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);
|
|
1138
|
+
if (IsUndefined(metadataMap))
|
|
1139
|
+
return false;
|
|
1140
|
+
if (!metadataMap.delete(MetadataKey))
|
|
1141
|
+
return false;
|
|
1142
|
+
if (metadataMap.size === 0) {
|
|
1143
|
+
var targetMetadata = metadata.get(O);
|
|
1144
|
+
if (!IsUndefined(targetMetadata)) {
|
|
1145
|
+
targetMetadata.delete(P);
|
|
1146
|
+
if (targetMetadata.size === 0) {
|
|
1147
|
+
metadata.delete(targetMetadata);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
return true;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
function CreateFallbackProvider(reflect) {
|
|
1155
|
+
var defineMetadata = reflect.defineMetadata, hasOwnMetadata = reflect.hasOwnMetadata, getOwnMetadata = reflect.getOwnMetadata, getOwnMetadataKeys = reflect.getOwnMetadataKeys, deleteMetadata = reflect.deleteMetadata;
|
|
1156
|
+
var metadataOwner = new _WeakMap();
|
|
1157
|
+
var provider = {
|
|
1158
|
+
isProviderFor: function (O, P) {
|
|
1159
|
+
var metadataPropertySet = metadataOwner.get(O);
|
|
1160
|
+
if (!IsUndefined(metadataPropertySet)) {
|
|
1161
|
+
return metadataPropertySet.has(P);
|
|
1162
|
+
}
|
|
1163
|
+
if (getOwnMetadataKeys(O, P).length) {
|
|
1164
|
+
if (IsUndefined(metadataPropertySet)) {
|
|
1165
|
+
metadataPropertySet = new _Set();
|
|
1166
|
+
metadataOwner.set(O, metadataPropertySet);
|
|
1167
|
+
}
|
|
1168
|
+
metadataPropertySet.add(P);
|
|
1169
|
+
return true;
|
|
1170
|
+
}
|
|
1171
|
+
return false;
|
|
1172
|
+
},
|
|
1173
|
+
OrdinaryDefineOwnMetadata: defineMetadata,
|
|
1174
|
+
OrdinaryHasOwnMetadata: hasOwnMetadata,
|
|
1175
|
+
OrdinaryGetOwnMetadata: getOwnMetadata,
|
|
1176
|
+
OrdinaryOwnMetadataKeys: getOwnMetadataKeys,
|
|
1177
|
+
OrdinaryDeleteMetadata: deleteMetadata,
|
|
1178
|
+
};
|
|
1179
|
+
return provider;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Gets the metadata provider for an object. If the object has no metadata provider and this is for a create operation,
|
|
1183
|
+
* then this module's metadata provider is assigned to the object.
|
|
1184
|
+
*/
|
|
1185
|
+
function GetMetadataProvider(O, P, Create) {
|
|
1186
|
+
var registeredProvider = metadataRegistry.getProvider(O, P);
|
|
1187
|
+
if (!IsUndefined(registeredProvider)) {
|
|
1188
|
+
return registeredProvider;
|
|
1189
|
+
}
|
|
1190
|
+
if (Create) {
|
|
1191
|
+
if (metadataRegistry.setProvider(O, P, metadataProvider)) {
|
|
1192
|
+
return metadataProvider;
|
|
1193
|
+
}
|
|
1194
|
+
throw new Error("Illegal state.");
|
|
1195
|
+
}
|
|
1196
|
+
return undefined;
|
|
1197
|
+
}
|
|
1198
|
+
// naive Map shim
|
|
1199
|
+
function CreateMapPolyfill() {
|
|
1200
|
+
var cacheSentinel = {};
|
|
1201
|
+
var arraySentinel = [];
|
|
1202
|
+
var MapIterator = /** @class */ (function () {
|
|
1203
|
+
function MapIterator(keys, values, selector) {
|
|
1204
|
+
this._index = 0;
|
|
1205
|
+
this._keys = keys;
|
|
1206
|
+
this._values = values;
|
|
1207
|
+
this._selector = selector;
|
|
1208
|
+
}
|
|
1209
|
+
MapIterator.prototype["@@iterator"] = function () { return this; };
|
|
1210
|
+
MapIterator.prototype[iteratorSymbol] = function () { return this; };
|
|
1211
|
+
MapIterator.prototype.next = function () {
|
|
1212
|
+
var index = this._index;
|
|
1213
|
+
if (index >= 0 && index < this._keys.length) {
|
|
1214
|
+
var result = this._selector(this._keys[index], this._values[index]);
|
|
1215
|
+
if (index + 1 >= this._keys.length) {
|
|
1216
|
+
this._index = -1;
|
|
1217
|
+
this._keys = arraySentinel;
|
|
1218
|
+
this._values = arraySentinel;
|
|
1219
|
+
}
|
|
1220
|
+
else {
|
|
1221
|
+
this._index++;
|
|
1222
|
+
}
|
|
1223
|
+
return { value: result, done: false };
|
|
1224
|
+
}
|
|
1225
|
+
return { value: undefined, done: true };
|
|
1226
|
+
};
|
|
1227
|
+
MapIterator.prototype.throw = function (error) {
|
|
1228
|
+
if (this._index >= 0) {
|
|
1229
|
+
this._index = -1;
|
|
1230
|
+
this._keys = arraySentinel;
|
|
1231
|
+
this._values = arraySentinel;
|
|
1232
|
+
}
|
|
1233
|
+
throw error;
|
|
1234
|
+
};
|
|
1235
|
+
MapIterator.prototype.return = function (value) {
|
|
1236
|
+
if (this._index >= 0) {
|
|
1237
|
+
this._index = -1;
|
|
1238
|
+
this._keys = arraySentinel;
|
|
1239
|
+
this._values = arraySentinel;
|
|
1240
|
+
}
|
|
1241
|
+
return { value: value, done: true };
|
|
1242
|
+
};
|
|
1243
|
+
return MapIterator;
|
|
1244
|
+
}());
|
|
1245
|
+
var Map = /** @class */ (function () {
|
|
1246
|
+
function Map() {
|
|
1247
|
+
this._keys = [];
|
|
1248
|
+
this._values = [];
|
|
1249
|
+
this._cacheKey = cacheSentinel;
|
|
1250
|
+
this._cacheIndex = -2;
|
|
1251
|
+
}
|
|
1252
|
+
Object.defineProperty(Map.prototype, "size", {
|
|
1253
|
+
get: function () { return this._keys.length; },
|
|
1254
|
+
enumerable: true,
|
|
1255
|
+
configurable: true
|
|
1256
|
+
});
|
|
1257
|
+
Map.prototype.has = function (key) { return this._find(key, /*insert*/ false) >= 0; };
|
|
1258
|
+
Map.prototype.get = function (key) {
|
|
1259
|
+
var index = this._find(key, /*insert*/ false);
|
|
1260
|
+
return index >= 0 ? this._values[index] : undefined;
|
|
1261
|
+
};
|
|
1262
|
+
Map.prototype.set = function (key, value) {
|
|
1263
|
+
var index = this._find(key, /*insert*/ true);
|
|
1264
|
+
this._values[index] = value;
|
|
1265
|
+
return this;
|
|
1266
|
+
};
|
|
1267
|
+
Map.prototype.delete = function (key) {
|
|
1268
|
+
var index = this._find(key, /*insert*/ false);
|
|
1269
|
+
if (index >= 0) {
|
|
1270
|
+
var size = this._keys.length;
|
|
1271
|
+
for (var i = index + 1; i < size; i++) {
|
|
1272
|
+
this._keys[i - 1] = this._keys[i];
|
|
1273
|
+
this._values[i - 1] = this._values[i];
|
|
1274
|
+
}
|
|
1275
|
+
this._keys.length--;
|
|
1276
|
+
this._values.length--;
|
|
1277
|
+
if (SameValueZero(key, this._cacheKey)) {
|
|
1278
|
+
this._cacheKey = cacheSentinel;
|
|
1279
|
+
this._cacheIndex = -2;
|
|
1280
|
+
}
|
|
1281
|
+
return true;
|
|
1282
|
+
}
|
|
1283
|
+
return false;
|
|
1284
|
+
};
|
|
1285
|
+
Map.prototype.clear = function () {
|
|
1286
|
+
this._keys.length = 0;
|
|
1287
|
+
this._values.length = 0;
|
|
1288
|
+
this._cacheKey = cacheSentinel;
|
|
1289
|
+
this._cacheIndex = -2;
|
|
1290
|
+
};
|
|
1291
|
+
Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); };
|
|
1292
|
+
Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); };
|
|
1293
|
+
Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); };
|
|
1294
|
+
Map.prototype["@@iterator"] = function () { return this.entries(); };
|
|
1295
|
+
Map.prototype[iteratorSymbol] = function () { return this.entries(); };
|
|
1296
|
+
Map.prototype._find = function (key, insert) {
|
|
1297
|
+
if (!SameValueZero(this._cacheKey, key)) {
|
|
1298
|
+
this._cacheIndex = -1;
|
|
1299
|
+
for (var i = 0; i < this._keys.length; i++) {
|
|
1300
|
+
if (SameValueZero(this._keys[i], key)) {
|
|
1301
|
+
this._cacheIndex = i;
|
|
1302
|
+
break;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
if (this._cacheIndex < 0 && insert) {
|
|
1307
|
+
this._cacheIndex = this._keys.length;
|
|
1308
|
+
this._keys.push(key);
|
|
1309
|
+
this._values.push(undefined);
|
|
1310
|
+
}
|
|
1311
|
+
return this._cacheIndex;
|
|
1312
|
+
};
|
|
1313
|
+
return Map;
|
|
1314
|
+
}());
|
|
1315
|
+
return Map;
|
|
1316
|
+
function getKey(key, _) {
|
|
1317
|
+
return key;
|
|
1318
|
+
}
|
|
1319
|
+
function getValue(_, value) {
|
|
1320
|
+
return value;
|
|
1321
|
+
}
|
|
1322
|
+
function getEntry(key, value) {
|
|
1323
|
+
return [key, value];
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
// naive Set shim
|
|
1327
|
+
function CreateSetPolyfill() {
|
|
1328
|
+
var Set = /** @class */ (function () {
|
|
1329
|
+
function Set() {
|
|
1330
|
+
this._map = new _Map();
|
|
1331
|
+
}
|
|
1332
|
+
Object.defineProperty(Set.prototype, "size", {
|
|
1333
|
+
get: function () { return this._map.size; },
|
|
1334
|
+
enumerable: true,
|
|
1335
|
+
configurable: true
|
|
1336
|
+
});
|
|
1337
|
+
Set.prototype.has = function (value) { return this._map.has(value); };
|
|
1338
|
+
Set.prototype.add = function (value) { return this._map.set(value, value), this; };
|
|
1339
|
+
Set.prototype.delete = function (value) { return this._map.delete(value); };
|
|
1340
|
+
Set.prototype.clear = function () { this._map.clear(); };
|
|
1341
|
+
Set.prototype.keys = function () { return this._map.keys(); };
|
|
1342
|
+
Set.prototype.values = function () { return this._map.keys(); };
|
|
1343
|
+
Set.prototype.entries = function () { return this._map.entries(); };
|
|
1344
|
+
Set.prototype["@@iterator"] = function () { return this.keys(); };
|
|
1345
|
+
Set.prototype[iteratorSymbol] = function () { return this.keys(); };
|
|
1346
|
+
return Set;
|
|
1347
|
+
}());
|
|
1348
|
+
return Set;
|
|
1349
|
+
}
|
|
1350
|
+
// naive WeakMap shim
|
|
1351
|
+
function CreateWeakMapPolyfill() {
|
|
1352
|
+
var UUID_SIZE = 16;
|
|
1353
|
+
var keys = HashMap.create();
|
|
1354
|
+
var rootKey = CreateUniqueKey();
|
|
1355
|
+
return /** @class */ (function () {
|
|
1356
|
+
function WeakMap() {
|
|
1357
|
+
this._key = CreateUniqueKey();
|
|
1358
|
+
}
|
|
1359
|
+
WeakMap.prototype.has = function (target) {
|
|
1360
|
+
var table = GetOrCreateWeakMapTable(target, /*create*/ false);
|
|
1361
|
+
return table !== undefined ? HashMap.has(table, this._key) : false;
|
|
1362
|
+
};
|
|
1363
|
+
WeakMap.prototype.get = function (target) {
|
|
1364
|
+
var table = GetOrCreateWeakMapTable(target, /*create*/ false);
|
|
1365
|
+
return table !== undefined ? HashMap.get(table, this._key) : undefined;
|
|
1366
|
+
};
|
|
1367
|
+
WeakMap.prototype.set = function (target, value) {
|
|
1368
|
+
var table = GetOrCreateWeakMapTable(target, /*create*/ true);
|
|
1369
|
+
table[this._key] = value;
|
|
1370
|
+
return this;
|
|
1371
|
+
};
|
|
1372
|
+
WeakMap.prototype.delete = function (target) {
|
|
1373
|
+
var table = GetOrCreateWeakMapTable(target, /*create*/ false);
|
|
1374
|
+
return table !== undefined ? delete table[this._key] : false;
|
|
1375
|
+
};
|
|
1376
|
+
WeakMap.prototype.clear = function () {
|
|
1377
|
+
// NOTE: not a real clear, just makes the previous data unreachable
|
|
1378
|
+
this._key = CreateUniqueKey();
|
|
1379
|
+
};
|
|
1380
|
+
return WeakMap;
|
|
1381
|
+
}());
|
|
1382
|
+
function CreateUniqueKey() {
|
|
1383
|
+
var key;
|
|
1384
|
+
do
|
|
1385
|
+
key = "@@WeakMap@@" + CreateUUID();
|
|
1386
|
+
while (HashMap.has(keys, key));
|
|
1387
|
+
keys[key] = true;
|
|
1388
|
+
return key;
|
|
1389
|
+
}
|
|
1390
|
+
function GetOrCreateWeakMapTable(target, create) {
|
|
1391
|
+
if (!hasOwn.call(target, rootKey)) {
|
|
1392
|
+
if (!create)
|
|
1393
|
+
return undefined;
|
|
1394
|
+
Object.defineProperty(target, rootKey, { value: HashMap.create() });
|
|
1395
|
+
}
|
|
1396
|
+
return target[rootKey];
|
|
1397
|
+
}
|
|
1398
|
+
function FillRandomBytes(buffer, size) {
|
|
1399
|
+
for (var i = 0; i < size; ++i)
|
|
1400
|
+
buffer[i] = Math.random() * 0xff | 0;
|
|
1401
|
+
return buffer;
|
|
1402
|
+
}
|
|
1403
|
+
function GenRandomBytes(size) {
|
|
1404
|
+
if (typeof Uint8Array === "function") {
|
|
1405
|
+
if (typeof crypto !== "undefined")
|
|
1406
|
+
return crypto.getRandomValues(new Uint8Array(size));
|
|
1407
|
+
if (typeof msCrypto !== "undefined")
|
|
1408
|
+
return msCrypto.getRandomValues(new Uint8Array(size));
|
|
1409
|
+
return FillRandomBytes(new Uint8Array(size), size);
|
|
1410
|
+
}
|
|
1411
|
+
return FillRandomBytes(new Array(size), size);
|
|
1412
|
+
}
|
|
1413
|
+
function CreateUUID() {
|
|
1414
|
+
var data = GenRandomBytes(UUID_SIZE);
|
|
1415
|
+
// mark as random - RFC 4122 § 4.4
|
|
1416
|
+
data[6] = data[6] & 0x4f | 0x40;
|
|
1417
|
+
data[8] = data[8] & 0xbf | 0x80;
|
|
1418
|
+
var result = "";
|
|
1419
|
+
for (var offset = 0; offset < UUID_SIZE; ++offset) {
|
|
1420
|
+
var byte = data[offset];
|
|
1421
|
+
if (offset === 4 || offset === 6 || offset === 8)
|
|
1422
|
+
result += "-";
|
|
1423
|
+
if (byte < 16)
|
|
1424
|
+
result += "0";
|
|
1425
|
+
result += byte.toString(16).toLowerCase();
|
|
1426
|
+
}
|
|
1427
|
+
return result;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
// uses a heuristic used by v8 and chakra to force an object into dictionary mode.
|
|
1431
|
+
function MakeDictionary(obj) {
|
|
1432
|
+
obj.__ = undefined;
|
|
1433
|
+
delete obj.__;
|
|
1434
|
+
return obj;
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
})(Reflect || (Reflect = {}));
|
|
1438
|
+
return _Reflect;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
require_Reflect();
|
|
1442
|
+
|
|
34
1443
|
/**
|
|
35
1444
|
* @ author: richen
|
|
36
1445
|
* @ copyright: Copyright (c) - <richenlin(at)gmail.com>
|
|
@@ -204,6 +1613,7 @@ function convertParamsType(param, type) {
|
|
|
204
1613
|
default: //any
|
|
205
1614
|
return param;
|
|
206
1615
|
}
|
|
1616
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
207
1617
|
}
|
|
208
1618
|
catch (err) {
|
|
209
1619
|
return param;
|
|
@@ -353,7 +1763,7 @@ function plateNumber(value) {
|
|
|
353
1763
|
* @Usage:
|
|
354
1764
|
* @Author: richen
|
|
355
1765
|
* @Date: 2021-11-25 10:47:04
|
|
356
|
-
* @LastEditTime: 2024-
|
|
1766
|
+
* @LastEditTime: 2024-10-31 16:57:28
|
|
357
1767
|
*/
|
|
358
1768
|
// constant
|
|
359
1769
|
const PARAM_TYPE_KEY = 'PARAM_TYPE_KEY';
|
|
@@ -390,6 +1800,7 @@ exports.paramterTypes = void 0;
|
|
|
390
1800
|
paramterTypes[paramterTypes["undefined"] = 19] = "undefined";
|
|
391
1801
|
})(exports.paramterTypes || (exports.paramterTypes = {}));
|
|
392
1802
|
class ValidateClass {
|
|
1803
|
+
static instance;
|
|
393
1804
|
constructor() {
|
|
394
1805
|
}
|
|
395
1806
|
/**
|
|
@@ -412,20 +1823,10 @@ class ValidateClass {
|
|
|
412
1823
|
* @memberof ValidateClass
|
|
413
1824
|
*/
|
|
414
1825
|
async valid(Clazz, data, convert = false) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
else {
|
|
420
|
-
obj = plainToClass(Clazz, data, convert);
|
|
421
|
-
}
|
|
422
|
-
let errors = [];
|
|
423
|
-
if (convert) {
|
|
424
|
-
errors = await classValidator.validate(obj);
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
errors = await classValidator.validate(obj, { skipMissingProperties: true });
|
|
428
|
-
}
|
|
1826
|
+
const obj = data instanceof Clazz ? data : plainToClass(Clazz, data, convert);
|
|
1827
|
+
const errors = convert
|
|
1828
|
+
? await classValidator.validate(obj)
|
|
1829
|
+
: await classValidator.validate(obj, { skipMissingProperties: true });
|
|
429
1830
|
if (errors.length > 0) {
|
|
430
1831
|
throw new Error(Object.values(errors[0].constraints)[0]);
|
|
431
1832
|
}
|
|
@@ -598,71 +1999,7 @@ const ValidFuncs = {
|
|
|
598
1999
|
* @param {(string | ValidOtpions)} [options]
|
|
599
2000
|
* @returns {*}
|
|
600
2001
|
*/
|
|
601
|
-
const FunctionValidator = {
|
|
602
|
-
IsNotEmpty: function (value, options) {
|
|
603
|
-
throw new Error("Function not implemented.");
|
|
604
|
-
},
|
|
605
|
-
IsDate: function (value, options) {
|
|
606
|
-
throw new Error("Function not implemented.");
|
|
607
|
-
},
|
|
608
|
-
IsEmail: function (value, options) {
|
|
609
|
-
throw new Error("Function not implemented.");
|
|
610
|
-
},
|
|
611
|
-
IsIP: function (value, options) {
|
|
612
|
-
throw new Error("Function not implemented.");
|
|
613
|
-
},
|
|
614
|
-
IsPhoneNumber: function (value, options) {
|
|
615
|
-
throw new Error("Function not implemented.");
|
|
616
|
-
},
|
|
617
|
-
IsUrl: function (value, options) {
|
|
618
|
-
throw new Error("Function not implemented.");
|
|
619
|
-
},
|
|
620
|
-
IsHash: function (value, options) {
|
|
621
|
-
throw new Error("Function not implemented.");
|
|
622
|
-
},
|
|
623
|
-
IsCnName: function (value, options) {
|
|
624
|
-
throw new Error("Function not implemented.");
|
|
625
|
-
},
|
|
626
|
-
IsIdNumber: function (value, options) {
|
|
627
|
-
throw new Error("Function not implemented.");
|
|
628
|
-
},
|
|
629
|
-
IsZipCode: function (value, options) {
|
|
630
|
-
throw new Error("Function not implemented.");
|
|
631
|
-
},
|
|
632
|
-
IsMobile: function (value, options) {
|
|
633
|
-
throw new Error("Function not implemented.");
|
|
634
|
-
},
|
|
635
|
-
IsPlateNumber: function (value, options) {
|
|
636
|
-
throw new Error("Function not implemented.");
|
|
637
|
-
},
|
|
638
|
-
Equals: function (value, options) {
|
|
639
|
-
throw new Error("Function not implemented.");
|
|
640
|
-
},
|
|
641
|
-
NotEquals: function (value, options) {
|
|
642
|
-
throw new Error("Function not implemented.");
|
|
643
|
-
},
|
|
644
|
-
Contains: function (value, options) {
|
|
645
|
-
throw new Error("Function not implemented.");
|
|
646
|
-
},
|
|
647
|
-
IsIn: function (value, options) {
|
|
648
|
-
throw new Error("Function not implemented.");
|
|
649
|
-
},
|
|
650
|
-
IsNotIn: function (value, options) {
|
|
651
|
-
throw new Error("Function not implemented.");
|
|
652
|
-
},
|
|
653
|
-
Gt: function (value, options) {
|
|
654
|
-
throw new Error("Function not implemented.");
|
|
655
|
-
},
|
|
656
|
-
Lt: function (value, options) {
|
|
657
|
-
throw new Error("Function not implemented.");
|
|
658
|
-
},
|
|
659
|
-
Gte: function (value, options) {
|
|
660
|
-
throw new Error("Function not implemented.");
|
|
661
|
-
},
|
|
662
|
-
Lte: function (value, options) {
|
|
663
|
-
throw new Error("Function not implemented.");
|
|
664
|
-
}
|
|
665
|
-
};
|
|
2002
|
+
const FunctionValidator = {};
|
|
666
2003
|
Object.keys(ValidFuncs).forEach((key) => {
|
|
667
2004
|
FunctionValidator[key] = (value, options) => {
|
|
668
2005
|
if (helper__namespace.isString(options)) {
|
|
@@ -679,7 +2016,7 @@ Object.keys(ValidFuncs).forEach((key) => {
|
|
|
679
2016
|
* @Usage:
|
|
680
2017
|
* @Author: richen
|
|
681
2018
|
* @Date: 2021-11-25 10:46:57
|
|
682
|
-
* @LastEditTime: 2024-
|
|
2019
|
+
* @LastEditTime: 2024-10-31 16:49:26
|
|
683
2020
|
*/
|
|
684
2021
|
/**
|
|
685
2022
|
* Validation parameter's type and values.
|
|
@@ -699,10 +2036,9 @@ function Valid(rule, options) {
|
|
|
699
2036
|
rules = rule;
|
|
700
2037
|
}
|
|
701
2038
|
return (target, propertyKey, descriptor) => {
|
|
702
|
-
var _a;
|
|
703
2039
|
// 获取成员参数类型
|
|
704
2040
|
const paramTypes = Reflect.getMetadata("design:paramtypes", target, propertyKey);
|
|
705
|
-
const type = (
|
|
2041
|
+
const type = (paramTypes[descriptor]?.name) ? paramTypes[descriptor].name : 'object';
|
|
706
2042
|
if (helper__namespace.isString(options)) {
|
|
707
2043
|
options = { message: options, value: null };
|
|
708
2044
|
}
|
|
@@ -722,7 +2058,7 @@ function Valid(rule, options) {
|
|
|
722
2058
|
* @returns {MethodDecorator}
|
|
723
2059
|
*/
|
|
724
2060
|
function Validated() {
|
|
725
|
-
return (target, propertyKey,
|
|
2061
|
+
return (target, propertyKey, _descriptor) => {
|
|
726
2062
|
//
|
|
727
2063
|
koatty_container.IOCContainer.savePropertyData(PARAM_CHECK_KEY, {
|
|
728
2064
|
dtoCheck: 1
|
|
@@ -794,10 +2130,10 @@ function IsCnName(validationOptions) {
|
|
|
794
2130
|
propertyName,
|
|
795
2131
|
options: validationOptions,
|
|
796
2132
|
validator: {
|
|
797
|
-
validate(value,
|
|
2133
|
+
validate(value, _args) {
|
|
798
2134
|
return cnName(value);
|
|
799
2135
|
},
|
|
800
|
-
defaultMessage(
|
|
2136
|
+
defaultMessage(_args) {
|
|
801
2137
|
return "invalid parameter ($property).";
|
|
802
2138
|
}
|
|
803
2139
|
}
|
|
@@ -821,10 +2157,10 @@ function IsIdNumber(validationOptions) {
|
|
|
821
2157
|
propertyName,
|
|
822
2158
|
options: validationOptions,
|
|
823
2159
|
validator: {
|
|
824
|
-
validate(value,
|
|
2160
|
+
validate(value, _args) {
|
|
825
2161
|
return idNumber(value);
|
|
826
2162
|
},
|
|
827
|
-
defaultMessage(
|
|
2163
|
+
defaultMessage(_args) {
|
|
828
2164
|
return "invalid parameter ($property).";
|
|
829
2165
|
}
|
|
830
2166
|
}
|
|
@@ -848,10 +2184,10 @@ function IsZipCode(validationOptions) {
|
|
|
848
2184
|
propertyName,
|
|
849
2185
|
options: validationOptions,
|
|
850
2186
|
validator: {
|
|
851
|
-
validate(value,
|
|
2187
|
+
validate(value, _args) {
|
|
852
2188
|
return zipCode(value);
|
|
853
2189
|
},
|
|
854
|
-
defaultMessage(
|
|
2190
|
+
defaultMessage(_args) {
|
|
855
2191
|
return "invalid parameter ($property).";
|
|
856
2192
|
}
|
|
857
2193
|
}
|
|
@@ -875,10 +2211,10 @@ function IsMobile(validationOptions) {
|
|
|
875
2211
|
propertyName,
|
|
876
2212
|
options: validationOptions,
|
|
877
2213
|
validator: {
|
|
878
|
-
validate(value,
|
|
2214
|
+
validate(value, _args) {
|
|
879
2215
|
return mobile(value);
|
|
880
2216
|
},
|
|
881
|
-
defaultMessage(
|
|
2217
|
+
defaultMessage(_args) {
|
|
882
2218
|
return "invalid parameter ($property).";
|
|
883
2219
|
}
|
|
884
2220
|
}
|
|
@@ -902,10 +2238,10 @@ function IsPlateNumber(validationOptions) {
|
|
|
902
2238
|
propertyName,
|
|
903
2239
|
options: validationOptions,
|
|
904
2240
|
validator: {
|
|
905
|
-
validate(value,
|
|
2241
|
+
validate(value, _args) {
|
|
906
2242
|
return plateNumber(value);
|
|
907
2243
|
},
|
|
908
|
-
defaultMessage(
|
|
2244
|
+
defaultMessage(_args) {
|
|
909
2245
|
return "invalid parameter ($property).";
|
|
910
2246
|
}
|
|
911
2247
|
}
|
|
@@ -928,10 +2264,10 @@ function IsNotEmpty(validationOptions) {
|
|
|
928
2264
|
propertyName,
|
|
929
2265
|
options: validationOptions,
|
|
930
2266
|
validator: {
|
|
931
|
-
validate(value,
|
|
2267
|
+
validate(value, _args) {
|
|
932
2268
|
return !helper__namespace.isEmpty(value);
|
|
933
2269
|
},
|
|
934
|
-
defaultMessage(
|
|
2270
|
+
defaultMessage(_args) {
|
|
935
2271
|
return "invalid parameter ($property).";
|
|
936
2272
|
}
|
|
937
2273
|
}
|
|
@@ -955,10 +2291,10 @@ function Equals(comparison, validationOptions) {
|
|
|
955
2291
|
propertyName,
|
|
956
2292
|
options: validationOptions,
|
|
957
2293
|
validator: {
|
|
958
|
-
validate(value,
|
|
2294
|
+
validate(value, _args) {
|
|
959
2295
|
return classValidator.equals(value, comparison);
|
|
960
2296
|
},
|
|
961
|
-
defaultMessage(
|
|
2297
|
+
defaultMessage(_args) {
|
|
962
2298
|
return `invalid parameter, ($property) must be equals ${comparison}.`;
|
|
963
2299
|
}
|
|
964
2300
|
}
|
|
@@ -982,10 +2318,10 @@ function NotEquals(comparison, validationOptions) {
|
|
|
982
2318
|
propertyName,
|
|
983
2319
|
options: validationOptions,
|
|
984
2320
|
validator: {
|
|
985
|
-
validate(value,
|
|
2321
|
+
validate(value, _args) {
|
|
986
2322
|
return classValidator.notEquals(value, comparison);
|
|
987
2323
|
},
|
|
988
|
-
defaultMessage(
|
|
2324
|
+
defaultMessage(_args) {
|
|
989
2325
|
return `invalid parameter, ($property) must be not equals ${comparison}.`;
|
|
990
2326
|
}
|
|
991
2327
|
}
|
|
@@ -1009,11 +2345,11 @@ function Contains(seed, validationOptions) {
|
|
|
1009
2345
|
propertyName,
|
|
1010
2346
|
options: validationOptions,
|
|
1011
2347
|
validator: {
|
|
1012
|
-
validate(value,
|
|
2348
|
+
validate(value, _args) {
|
|
1013
2349
|
return classValidator.contains(value, seed);
|
|
1014
2350
|
// return typeof value === "string" && (value.indexOf(seed) > -1);
|
|
1015
2351
|
},
|
|
1016
|
-
defaultMessage(
|
|
2352
|
+
defaultMessage(_args) {
|
|
1017
2353
|
return `invalid parameter, ($property) must be contains ${seed}.`;
|
|
1018
2354
|
}
|
|
1019
2355
|
}
|
|
@@ -1037,10 +2373,10 @@ function IsIn(possibleValues, validationOptions) {
|
|
|
1037
2373
|
propertyName,
|
|
1038
2374
|
options: validationOptions,
|
|
1039
2375
|
validator: {
|
|
1040
|
-
validate(value,
|
|
2376
|
+
validate(value, _args) {
|
|
1041
2377
|
return classValidator.isIn(value, possibleValues);
|
|
1042
2378
|
},
|
|
1043
|
-
defaultMessage(
|
|
2379
|
+
defaultMessage(_args) {
|
|
1044
2380
|
return `invalid parameter ($property).`;
|
|
1045
2381
|
}
|
|
1046
2382
|
}
|
|
@@ -1064,10 +2400,10 @@ function IsNotIn(possibleValues, validationOptions) {
|
|
|
1064
2400
|
propertyName,
|
|
1065
2401
|
options: validationOptions,
|
|
1066
2402
|
validator: {
|
|
1067
|
-
validate(value,
|
|
2403
|
+
validate(value, _args) {
|
|
1068
2404
|
return classValidator.isNotIn(value, possibleValues);
|
|
1069
2405
|
},
|
|
1070
|
-
defaultMessage(
|
|
2406
|
+
defaultMessage(_args) {
|
|
1071
2407
|
return `invalid parameter ($property).`;
|
|
1072
2408
|
}
|
|
1073
2409
|
}
|
|
@@ -1090,10 +2426,10 @@ function IsDate(validationOptions) {
|
|
|
1090
2426
|
propertyName,
|
|
1091
2427
|
options: validationOptions,
|
|
1092
2428
|
validator: {
|
|
1093
|
-
validate(value,
|
|
2429
|
+
validate(value, _args) {
|
|
1094
2430
|
return classValidator.isDate(value);
|
|
1095
2431
|
},
|
|
1096
|
-
defaultMessage(
|
|
2432
|
+
defaultMessage(_args) {
|
|
1097
2433
|
return `invalid parameter ($property).`;
|
|
1098
2434
|
}
|
|
1099
2435
|
}
|
|
@@ -1117,10 +2453,10 @@ function Gt(min, validationOptions) {
|
|
|
1117
2453
|
propertyName,
|
|
1118
2454
|
options: validationOptions,
|
|
1119
2455
|
validator: {
|
|
1120
|
-
validate(value,
|
|
2456
|
+
validate(value, _args) {
|
|
1121
2457
|
return helper__namespace.toNumber(value) > min;
|
|
1122
2458
|
},
|
|
1123
|
-
defaultMessage(
|
|
2459
|
+
defaultMessage(_args) {
|
|
1124
2460
|
return `invalid parameter ($property).`;
|
|
1125
2461
|
}
|
|
1126
2462
|
}
|
|
@@ -1144,10 +2480,10 @@ function Lt(max, validationOptions) {
|
|
|
1144
2480
|
propertyName,
|
|
1145
2481
|
options: validationOptions,
|
|
1146
2482
|
validator: {
|
|
1147
|
-
validate(value,
|
|
2483
|
+
validate(value, _args) {
|
|
1148
2484
|
return helper__namespace.toNumber(value) < max;
|
|
1149
2485
|
},
|
|
1150
|
-
defaultMessage(
|
|
2486
|
+
defaultMessage(_args) {
|
|
1151
2487
|
return `invalid parameter ($property).`;
|
|
1152
2488
|
}
|
|
1153
2489
|
}
|
|
@@ -1171,10 +2507,10 @@ function Gte(min, validationOptions) {
|
|
|
1171
2507
|
propertyName,
|
|
1172
2508
|
options: validationOptions,
|
|
1173
2509
|
validator: {
|
|
1174
|
-
validate(value,
|
|
2510
|
+
validate(value, _args) {
|
|
1175
2511
|
return helper__namespace.toNumber(value) >= min;
|
|
1176
2512
|
},
|
|
1177
|
-
defaultMessage(
|
|
2513
|
+
defaultMessage(_args) {
|
|
1178
2514
|
return `invalid parameter ($property).`;
|
|
1179
2515
|
}
|
|
1180
2516
|
}
|
|
@@ -1198,10 +2534,10 @@ function Lte(max, validationOptions) {
|
|
|
1198
2534
|
propertyName,
|
|
1199
2535
|
options: validationOptions,
|
|
1200
2536
|
validator: {
|
|
1201
|
-
validate(value,
|
|
2537
|
+
validate(value, _args) {
|
|
1202
2538
|
return helper__namespace.toNumber(value) <= max;
|
|
1203
2539
|
},
|
|
1204
|
-
defaultMessage(
|
|
2540
|
+
defaultMessage(_args) {
|
|
1205
2541
|
return `invalid parameter ($property).`;
|
|
1206
2542
|
}
|
|
1207
2543
|
}
|
|
@@ -1227,10 +2563,10 @@ function Length(min, max, validationOptions) {
|
|
|
1227
2563
|
propertyName,
|
|
1228
2564
|
options: validationOptions,
|
|
1229
2565
|
validator: {
|
|
1230
|
-
validate(value,
|
|
2566
|
+
validate(value, _args) {
|
|
1231
2567
|
return classValidator.length(value, min, max);
|
|
1232
2568
|
},
|
|
1233
|
-
defaultMessage(
|
|
2569
|
+
defaultMessage(_args) {
|
|
1234
2570
|
return `invalid parameter ($property).`;
|
|
1235
2571
|
}
|
|
1236
2572
|
}
|
|
@@ -1254,10 +2590,10 @@ function IsEmail(options, validationOptions) {
|
|
|
1254
2590
|
propertyName,
|
|
1255
2591
|
options: validationOptions,
|
|
1256
2592
|
validator: {
|
|
1257
|
-
validate(value,
|
|
2593
|
+
validate(value, _args) {
|
|
1258
2594
|
return classValidator.isEmail(value);
|
|
1259
2595
|
},
|
|
1260
|
-
defaultMessage(
|
|
2596
|
+
defaultMessage(_args) {
|
|
1261
2597
|
return `invalid parameter ($property).`;
|
|
1262
2598
|
}
|
|
1263
2599
|
}
|
|
@@ -1281,10 +2617,10 @@ function IsIP(version, validationOptions) {
|
|
|
1281
2617
|
propertyName,
|
|
1282
2618
|
options: validationOptions,
|
|
1283
2619
|
validator: {
|
|
1284
|
-
validate(value,
|
|
2620
|
+
validate(value, _args) {
|
|
1285
2621
|
return classValidator.isIP(value, version);
|
|
1286
2622
|
},
|
|
1287
|
-
defaultMessage(
|
|
2623
|
+
defaultMessage(_args) {
|
|
1288
2624
|
return `invalid parameter ($property).`;
|
|
1289
2625
|
}
|
|
1290
2626
|
}
|
|
@@ -1311,10 +2647,10 @@ function IsPhoneNumber(region, validationOptions) {
|
|
|
1311
2647
|
propertyName,
|
|
1312
2648
|
options: validationOptions,
|
|
1313
2649
|
validator: {
|
|
1314
|
-
validate(value,
|
|
2650
|
+
validate(value, _args) {
|
|
1315
2651
|
return classValidator.isPhoneNumber(value, region);
|
|
1316
2652
|
},
|
|
1317
|
-
defaultMessage(
|
|
2653
|
+
defaultMessage(_args) {
|
|
1318
2654
|
return `invalid parameter ($property).`;
|
|
1319
2655
|
}
|
|
1320
2656
|
}
|
|
@@ -1338,10 +2674,10 @@ function IsUrl(options, validationOptions) {
|
|
|
1338
2674
|
propertyName,
|
|
1339
2675
|
options: validationOptions,
|
|
1340
2676
|
validator: {
|
|
1341
|
-
validate(value,
|
|
2677
|
+
validate(value, _args) {
|
|
1342
2678
|
return classValidator.isURL(value, options);
|
|
1343
2679
|
},
|
|
1344
|
-
defaultMessage(
|
|
2680
|
+
defaultMessage(_args) {
|
|
1345
2681
|
return `invalid parameter ($property).`;
|
|
1346
2682
|
}
|
|
1347
2683
|
}
|
|
@@ -1366,10 +2702,10 @@ function IsHash(algorithm, validationOptions) {
|
|
|
1366
2702
|
propertyName,
|
|
1367
2703
|
options: validationOptions,
|
|
1368
2704
|
validator: {
|
|
1369
|
-
validate(value,
|
|
2705
|
+
validate(value, _args) {
|
|
1370
2706
|
return classValidator.isHash(value, algorithm);
|
|
1371
2707
|
},
|
|
1372
|
-
defaultMessage(
|
|
2708
|
+
defaultMessage(_args) {
|
|
1373
2709
|
return `invalid parameter, ($property) must be is an ${algorithm} Hash string.`;
|
|
1374
2710
|
}
|
|
1375
2711
|
}
|
|
@@ -1391,10 +2727,10 @@ function CheckFunc(func, validationOptions) {
|
|
|
1391
2727
|
propertyName,
|
|
1392
2728
|
options: validationOptions,
|
|
1393
2729
|
validator: {
|
|
1394
|
-
validate(value,
|
|
2730
|
+
validate(value, _args) {
|
|
1395
2731
|
return func(value);
|
|
1396
2732
|
},
|
|
1397
|
-
defaultMessage(
|
|
2733
|
+
defaultMessage(_args) {
|
|
1398
2734
|
return `invalid parameter ($property).`;
|
|
1399
2735
|
}
|
|
1400
2736
|
}
|