@ne1410s/codl 0.0.34 → 0.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ne14_codl.cjs.min.js +46 -46
- package/dist/ne14_codl.esm.min.js +46 -46
- package/dist/ne14_codl.umd.min.js +48 -48
- package/package.json +7 -6
|
@@ -136,7 +136,7 @@ var Metadata = /** @class */ (function () {
|
|
|
136
136
|
/** Associates a child's prototype data on the parent in which it appears. */
|
|
137
137
|
Metadata.model = function (ctor) {
|
|
138
138
|
return function (trg, key) {
|
|
139
|
-
Reflect.defineMetadata(MetadataKey.MODEL
|
|
139
|
+
Reflect.defineMetadata("".concat(MetadataKey.MODEL, ":").concat(key.toString()), ctor, trg);
|
|
140
140
|
};
|
|
141
141
|
};
|
|
142
142
|
return Metadata;
|
|
@@ -147,19 +147,19 @@ var Type = /** @class */ (function () {
|
|
|
147
147
|
function Type() {
|
|
148
148
|
}
|
|
149
149
|
Type.boolean = function (trg, key) {
|
|
150
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
150
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
151
151
|
Reflect.defineMetadata(ValidationKey.TYPE, 'boolean', trg, key);
|
|
152
152
|
};
|
|
153
153
|
Type.date = function (trg, key) {
|
|
154
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
154
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
155
155
|
Reflect.defineMetadata(ValidationKey.TYPE, 'date', trg, key);
|
|
156
156
|
};
|
|
157
157
|
Type.integer = function (trg, key) {
|
|
158
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
158
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
159
159
|
Reflect.defineMetadata(ValidationKey.TYPE, 'integer', trg, key);
|
|
160
160
|
};
|
|
161
161
|
Type.number = function (trg, key) {
|
|
162
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
162
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
163
163
|
Reflect.defineMetadata(ValidationKey.TYPE, 'number', trg, key);
|
|
164
164
|
};
|
|
165
165
|
return Type;
|
|
@@ -174,7 +174,7 @@ var Validation = /** @class */ (function () {
|
|
|
174
174
|
* invalid, as is NaN. Anything else is valid (including: 0, 0n, false).
|
|
175
175
|
*/
|
|
176
176
|
Validation.required = function (trg, key) {
|
|
177
|
-
Reflect.defineMetadata(ValidationKey.REQUIRED
|
|
177
|
+
Reflect.defineMetadata("".concat(ValidationKey.REQUIRED, ":").concat(key.toString()), key, trg);
|
|
178
178
|
Reflect.defineMetadata(ValidationKey.REQUIRED, true, trg, key);
|
|
179
179
|
};
|
|
180
180
|
/**
|
|
@@ -182,7 +182,7 @@ var Validation = /** @class */ (function () {
|
|
|
182
182
|
* valid. Anything else is considered invalid (including: 0, 0n, false).
|
|
183
183
|
*/
|
|
184
184
|
Validation.forbidden = function (trg, key) {
|
|
185
|
-
Reflect.defineMetadata(ValidationKey.FORBIDDEN
|
|
185
|
+
Reflect.defineMetadata("".concat(ValidationKey.FORBIDDEN, ":").concat(key.toString()), key, trg);
|
|
186
186
|
Reflect.defineMetadata(ValidationKey.FORBIDDEN, true, trg, key);
|
|
187
187
|
};
|
|
188
188
|
/**
|
|
@@ -193,7 +193,7 @@ var Validation = /** @class */ (function () {
|
|
|
193
193
|
*/
|
|
194
194
|
Validation.minLength = function (lBound) {
|
|
195
195
|
return function (trg, key) {
|
|
196
|
-
Reflect.defineMetadata(ValidationKey.MIN_LENGTH
|
|
196
|
+
Reflect.defineMetadata("".concat(ValidationKey.MIN_LENGTH, ":").concat(key.toString()), key, trg);
|
|
197
197
|
Reflect.defineMetadata(ValidationKey.MIN_LENGTH, lBound, trg, key);
|
|
198
198
|
};
|
|
199
199
|
};
|
|
@@ -205,7 +205,7 @@ var Validation = /** @class */ (function () {
|
|
|
205
205
|
*/
|
|
206
206
|
Validation.maxLength = function (uBound) {
|
|
207
207
|
return function (trg, key) {
|
|
208
|
-
Reflect.defineMetadata(ValidationKey.MAX_LENGTH
|
|
208
|
+
Reflect.defineMetadata("".concat(ValidationKey.MAX_LENGTH, ":").concat(key.toString()), key, trg);
|
|
209
209
|
Reflect.defineMetadata(ValidationKey.MAX_LENGTH, uBound, trg, key);
|
|
210
210
|
};
|
|
211
211
|
};
|
|
@@ -224,8 +224,8 @@ var Validation = /** @class */ (function () {
|
|
|
224
224
|
else
|
|
225
225
|
throw new TypeError('Unable to infer type key from: ' + lBound);
|
|
226
226
|
return function (trg, key) {
|
|
227
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
228
|
-
Reflect.defineMetadata(ValidationKey.MIN
|
|
227
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
228
|
+
Reflect.defineMetadata("".concat(ValidationKey.MIN, ":").concat(key.toString()), key, trg);
|
|
229
229
|
Reflect.defineMetadata(ValidationKey.TYPE, typekey, trg, key);
|
|
230
230
|
Reflect.defineMetadata(ValidationKey.MIN, lBound, trg, key);
|
|
231
231
|
};
|
|
@@ -245,8 +245,8 @@ var Validation = /** @class */ (function () {
|
|
|
245
245
|
else
|
|
246
246
|
throw new TypeError('Unable to infer type key from: ' + uBound);
|
|
247
247
|
return function (trg, key) {
|
|
248
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
249
|
-
Reflect.defineMetadata(ValidationKey.MAX
|
|
248
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
249
|
+
Reflect.defineMetadata("".concat(ValidationKey.MAX, ":").concat(key.toString()), key, trg);
|
|
250
250
|
Reflect.defineMetadata(ValidationKey.TYPE, typekey, trg, key);
|
|
251
251
|
Reflect.defineMetadata(ValidationKey.MAX, uBound, trg, key);
|
|
252
252
|
};
|
|
@@ -266,9 +266,9 @@ var Validation = /** @class */ (function () {
|
|
|
266
266
|
else
|
|
267
267
|
throw new TypeError('Unable to infer type key from: ' + lBound);
|
|
268
268
|
return function (trg, key) {
|
|
269
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
270
|
-
Reflect.defineMetadata(ValidationKey.MIN
|
|
271
|
-
Reflect.defineMetadata(ValidationKey.MAX
|
|
269
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
270
|
+
Reflect.defineMetadata("".concat(ValidationKey.MIN, ":").concat(key.toString()), key, trg);
|
|
271
|
+
Reflect.defineMetadata("".concat(ValidationKey.MAX, ":").concat(key.toString()), key, trg);
|
|
272
272
|
Reflect.defineMetadata(ValidationKey.TYPE, typekey, trg, key);
|
|
273
273
|
Reflect.defineMetadata(ValidationKey.MIN, lBound, trg, key);
|
|
274
274
|
Reflect.defineMetadata(ValidationKey.MAX, uBound, trg, key);
|
|
@@ -282,7 +282,7 @@ var Validation = /** @class */ (function () {
|
|
|
282
282
|
*/
|
|
283
283
|
Validation.regex = function (regex) {
|
|
284
284
|
return function (trg, key) {
|
|
285
|
-
Reflect.defineMetadata(ValidationKey.REGEX
|
|
285
|
+
Reflect.defineMetadata("".concat(ValidationKey.REGEX, ":").concat(key.toString()), key, trg);
|
|
286
286
|
Reflect.defineMetadata(ValidationKey.REGEX, regex, trg, key);
|
|
287
287
|
};
|
|
288
288
|
};
|
|
@@ -296,7 +296,7 @@ var Validation = /** @class */ (function () {
|
|
|
296
296
|
opts[_i] = arguments[_i];
|
|
297
297
|
}
|
|
298
298
|
return function (trg, key) {
|
|
299
|
-
Reflect.defineMetadata(ValidationKey.OPTIONS
|
|
299
|
+
Reflect.defineMetadata("".concat(ValidationKey.OPTIONS, ":").concat(key.toString()), key, trg);
|
|
300
300
|
Reflect.defineMetadata(ValidationKey.OPTIONS, opts, trg, key);
|
|
301
301
|
};
|
|
302
302
|
};
|
|
@@ -310,7 +310,7 @@ var Validation = /** @class */ (function () {
|
|
|
310
310
|
*/
|
|
311
311
|
Validation.custom = function (fn) {
|
|
312
312
|
return function (trg, key) {
|
|
313
|
-
Reflect.defineMetadata(ValidationKey.CUSTOM
|
|
313
|
+
Reflect.defineMetadata("".concat(ValidationKey.CUSTOM, ":").concat(key.toString()), key, trg);
|
|
314
314
|
Reflect.defineMetadata(ValidationKey.CUSTOM, fn, trg, key);
|
|
315
315
|
};
|
|
316
316
|
};
|
|
@@ -385,7 +385,7 @@ var RequiredValidator = function (trg, key, proto) {
|
|
|
385
385
|
var required = Reflect.getMetadata(ValidationKey.REQUIRED, proto, key) === true;
|
|
386
386
|
if (required) {
|
|
387
387
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
388
|
-
retVal.message = name_1
|
|
388
|
+
retVal.message = "".concat(name_1, " is required");
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
391
|
retVal.valid = !retVal.message;
|
|
@@ -400,10 +400,10 @@ var RegexValidator = function (trg, key, proto) {
|
|
|
400
400
|
var regex_1 = new RegExp(Reflect.getMetadata(ValidationKey.REGEX, proto, key));
|
|
401
401
|
var isArray = Array.isArray(value);
|
|
402
402
|
var tests = isArray ? value : [value];
|
|
403
|
-
var allOk = tests.every(function (test) { return regex_1.test(""
|
|
403
|
+
var allOk = tests.every(function (test) { return regex_1.test("".concat(test)); });
|
|
404
404
|
if (!allOk) {
|
|
405
405
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
406
|
-
retVal.message = isArray ? name_1
|
|
406
|
+
retVal.message = isArray ? "".concat(name_1, " contains an invalid item") : "".concat(name_1, " is invalid");
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
retVal.valid = !retVal.message;
|
|
@@ -411,7 +411,7 @@ var RegexValidator = function (trg, key, proto) {
|
|
|
411
411
|
};
|
|
412
412
|
|
|
413
413
|
var BooleanParser = function (obj) {
|
|
414
|
-
var str =
|
|
414
|
+
var str = "".concat(obj).toLowerCase();
|
|
415
415
|
if (['1', 'true'].indexOf(str) !== -1)
|
|
416
416
|
return true;
|
|
417
417
|
if (['0', 'false'].indexOf(str) !== -1)
|
|
@@ -429,13 +429,13 @@ var DateParser = function (obj) {
|
|
|
429
429
|
};
|
|
430
430
|
|
|
431
431
|
var IntegerParser = function (obj) {
|
|
432
|
-
var asInt = parseInt(""
|
|
433
|
-
if (!isNaN(asInt) && asInt.toFixed(8) === parseFloat(""
|
|
432
|
+
var asInt = parseInt("".concat(obj), 10);
|
|
433
|
+
if (!isNaN(asInt) && asInt.toFixed(8) === parseFloat("".concat(obj)).toFixed(8))
|
|
434
434
|
return asInt;
|
|
435
435
|
};
|
|
436
436
|
|
|
437
437
|
var NumberParser = function (obj) {
|
|
438
|
-
var test = parseFloat(""
|
|
438
|
+
var test = parseFloat("".concat(obj));
|
|
439
439
|
if (!isNaN(test))
|
|
440
440
|
return test;
|
|
441
441
|
};
|
|
@@ -473,7 +473,7 @@ var ReflectType = /** @class */ (function () {
|
|
|
473
473
|
case 'number':
|
|
474
474
|
return NumberParser;
|
|
475
475
|
default:
|
|
476
|
-
throw new RangeError("No parser implemented for "
|
|
476
|
+
throw new RangeError("No parser implemented for ".concat(type));
|
|
477
477
|
}
|
|
478
478
|
};
|
|
479
479
|
return ReflectType;
|
|
@@ -502,10 +502,10 @@ var RangeValidator = function (trg, key, proto) {
|
|
|
502
502
|
var boundImperative = isArray ? 'have a value' : 'be';
|
|
503
503
|
retVal.message =
|
|
504
504
|
hasMin_1 && hasMax_1
|
|
505
|
-
? name_1
|
|
505
|
+
? "".concat(name_1, " must ").concat(rangeImperative, " between ").concat(fmtMin, " and ").concat(fmtMax)
|
|
506
506
|
: hasMin_1
|
|
507
|
-
? name_1
|
|
508
|
-
: name_1
|
|
507
|
+
? "".concat(name_1, " cannot ").concat(boundImperative, " ").concat(compareLT, " ").concat(fmtMin)
|
|
508
|
+
: "".concat(name_1, " cannot ").concat(boundImperative, " ").concat(compareGT, " ").concat(fmtMax);
|
|
509
509
|
}
|
|
510
510
|
retVal.valid = !retVal.message;
|
|
511
511
|
}
|
|
@@ -529,10 +529,10 @@ var LengthRangeValidator = function (trg, key, proto) {
|
|
|
529
529
|
var pluraliser = value.length === 1 ? '' : 's';
|
|
530
530
|
retVal.message =
|
|
531
531
|
hasMinLen && hasMaxLen
|
|
532
|
-
? name_1
|
|
532
|
+
? "".concat(name_1, " must contain between ").concat(minLength, " and ").concat(maxLength, " ").concat(noun, "s")
|
|
533
533
|
: hasMinLen
|
|
534
|
-
? name_1
|
|
535
|
-
: name_1
|
|
534
|
+
? "".concat(name_1, " cannot contain fewer than ").concat(minLength, " ").concat(noun).concat(pluraliser)
|
|
535
|
+
: "".concat(name_1, " cannot contain more than ").concat(maxLength, " ").concat(noun).concat(pluraliser);
|
|
536
536
|
}
|
|
537
537
|
retVal.valid = !retVal.message;
|
|
538
538
|
}
|
|
@@ -552,8 +552,8 @@ var TypeValidator = function (trg, key, proto) {
|
|
|
552
552
|
if (!allOk) {
|
|
553
553
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
554
554
|
retVal.message = isArray
|
|
555
|
-
? name_1
|
|
556
|
-
: name_1
|
|
555
|
+
? "".concat(name_1, " contains an invalid ").concat(type)
|
|
556
|
+
: "".concat(name_1, " is not a valid ").concat(type);
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
559
|
retVal.valid = !retVal.message;
|
|
@@ -571,7 +571,7 @@ var CustValidator = function (trg, key, proto) {
|
|
|
571
571
|
retVal.message = result;
|
|
572
572
|
else if (result === false) {
|
|
573
573
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
574
|
-
retVal.message = name_1
|
|
574
|
+
retVal.message = "".concat(name_1, " is invalid");
|
|
575
575
|
}
|
|
576
576
|
retVal.valid = !retVal.message;
|
|
577
577
|
return retVal;
|
|
@@ -585,7 +585,7 @@ var ForbiddenValidator = function (trg, key, proto) {
|
|
|
585
585
|
var forbidden = Reflect.getMetadata(ValidationKey.FORBIDDEN, proto, key) === true;
|
|
586
586
|
if (forbidden) {
|
|
587
587
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
588
|
-
retVal.message = name_1
|
|
588
|
+
retVal.message = "".concat(name_1, " is forbidden");
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
591
|
retVal.valid = !retVal.message;
|
|
@@ -604,8 +604,8 @@ var OptionsValidator = function (trg, key, proto) {
|
|
|
604
604
|
if (!allOk) {
|
|
605
605
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
606
606
|
retVal.message = isArray
|
|
607
|
-
? name_1
|
|
608
|
-
: name_1
|
|
607
|
+
? "".concat(name_1, " contains an invalid option")
|
|
608
|
+
: "".concat(name_1, " is an invalid option");
|
|
609
609
|
}
|
|
610
610
|
}
|
|
611
611
|
retVal.valid = !retVal.message;
|
|
@@ -665,7 +665,7 @@ var ReflectValidation = /** @class */ (function () {
|
|
|
665
665
|
case ValidationKey.CUSTOM:
|
|
666
666
|
return CustValidator;
|
|
667
667
|
default:
|
|
668
|
-
throw new RangeError("No validator implemented for "
|
|
668
|
+
throw new RangeError("No validator implemented for ".concat(key));
|
|
669
669
|
}
|
|
670
670
|
};
|
|
671
671
|
/** Prepares a sequence of validation instructions. */
|
|
@@ -681,12 +681,12 @@ var ReflectValidation = /** @class */ (function () {
|
|
|
681
681
|
: 0;
|
|
682
682
|
};
|
|
683
683
|
return Reflect.getMetadataKeys(proto)
|
|
684
|
-
.map(function (k) { return ""
|
|
684
|
+
.map(function (k) { return "".concat(k); })
|
|
685
685
|
.reduce(function (acc, cur) {
|
|
686
686
|
var valDef = allChecks.filter(function (dg) { return cur.indexOf(dg.meta + ':') === 0; })[0];
|
|
687
687
|
if (valDef) {
|
|
688
688
|
var key = cur.replace(valDef.meta + ':', '');
|
|
689
|
-
var navkey_1 = pfx ? pfx
|
|
689
|
+
var navkey_1 = pfx ? "".concat(pfx, ".").concat(key) : key;
|
|
690
690
|
var prior = acc.filter(function (a) { return a.navkey === navkey_1 && a.fn === valDef.fn; })[0];
|
|
691
691
|
if (prior) {
|
|
692
692
|
prior.tests.push(valDef.test);
|
|
@@ -702,18 +702,18 @@ var ReflectValidation = /** @class */ (function () {
|
|
|
702
702
|
});
|
|
703
703
|
}
|
|
704
704
|
}
|
|
705
|
-
else if (cur.indexOf(MetadataKey.MODEL
|
|
706
|
-
var subkey_1 = cur.replace(MetadataKey.MODEL
|
|
705
|
+
else if (cur.indexOf("".concat(MetadataKey.MODEL, ":")) === 0) {
|
|
706
|
+
var subkey_1 = cur.replace("".concat(MetadataKey.MODEL, ":"), '');
|
|
707
707
|
var subproto_1 = Reflect.getMetadata(cur, proto).prototype;
|
|
708
708
|
var subobj = (trg || {})[subkey_1];
|
|
709
709
|
if (Array.isArray(subobj)) {
|
|
710
710
|
subobj.forEach(function (subitem, i) {
|
|
711
|
-
var subpfx = pfx ? pfx
|
|
711
|
+
var subpfx = pfx ? "".concat(pfx, ".").concat(subkey_1, "[").concat(i, "]") : "".concat(subkey_1, "[").concat(i, "]");
|
|
712
712
|
acc.push.apply(acc, ReflectValidation.getTestInstructions(allChecks, subproto_1, subitem || {}, subpfx));
|
|
713
713
|
});
|
|
714
714
|
}
|
|
715
715
|
else if (subobj) {
|
|
716
|
-
var subpfx = pfx ? pfx
|
|
716
|
+
var subpfx = pfx ? "".concat(pfx, ".").concat(subkey_1) : subkey_1;
|
|
717
717
|
acc.push.apply(acc, ReflectValidation.getTestInstructions(allChecks, subproto_1, subobj, subpfx));
|
|
718
718
|
}
|
|
719
719
|
}
|
|
@@ -132,7 +132,7 @@ var Metadata = /** @class */ (function () {
|
|
|
132
132
|
/** Associates a child's prototype data on the parent in which it appears. */
|
|
133
133
|
Metadata.model = function (ctor) {
|
|
134
134
|
return function (trg, key) {
|
|
135
|
-
Reflect.defineMetadata(MetadataKey.MODEL
|
|
135
|
+
Reflect.defineMetadata("".concat(MetadataKey.MODEL, ":").concat(key.toString()), ctor, trg);
|
|
136
136
|
};
|
|
137
137
|
};
|
|
138
138
|
return Metadata;
|
|
@@ -143,19 +143,19 @@ var Type = /** @class */ (function () {
|
|
|
143
143
|
function Type() {
|
|
144
144
|
}
|
|
145
145
|
Type.boolean = function (trg, key) {
|
|
146
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
146
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
147
147
|
Reflect.defineMetadata(ValidationKey.TYPE, 'boolean', trg, key);
|
|
148
148
|
};
|
|
149
149
|
Type.date = function (trg, key) {
|
|
150
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
150
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
151
151
|
Reflect.defineMetadata(ValidationKey.TYPE, 'date', trg, key);
|
|
152
152
|
};
|
|
153
153
|
Type.integer = function (trg, key) {
|
|
154
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
154
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
155
155
|
Reflect.defineMetadata(ValidationKey.TYPE, 'integer', trg, key);
|
|
156
156
|
};
|
|
157
157
|
Type.number = function (trg, key) {
|
|
158
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
158
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
159
159
|
Reflect.defineMetadata(ValidationKey.TYPE, 'number', trg, key);
|
|
160
160
|
};
|
|
161
161
|
return Type;
|
|
@@ -170,7 +170,7 @@ var Validation = /** @class */ (function () {
|
|
|
170
170
|
* invalid, as is NaN. Anything else is valid (including: 0, 0n, false).
|
|
171
171
|
*/
|
|
172
172
|
Validation.required = function (trg, key) {
|
|
173
|
-
Reflect.defineMetadata(ValidationKey.REQUIRED
|
|
173
|
+
Reflect.defineMetadata("".concat(ValidationKey.REQUIRED, ":").concat(key.toString()), key, trg);
|
|
174
174
|
Reflect.defineMetadata(ValidationKey.REQUIRED, true, trg, key);
|
|
175
175
|
};
|
|
176
176
|
/**
|
|
@@ -178,7 +178,7 @@ var Validation = /** @class */ (function () {
|
|
|
178
178
|
* valid. Anything else is considered invalid (including: 0, 0n, false).
|
|
179
179
|
*/
|
|
180
180
|
Validation.forbidden = function (trg, key) {
|
|
181
|
-
Reflect.defineMetadata(ValidationKey.FORBIDDEN
|
|
181
|
+
Reflect.defineMetadata("".concat(ValidationKey.FORBIDDEN, ":").concat(key.toString()), key, trg);
|
|
182
182
|
Reflect.defineMetadata(ValidationKey.FORBIDDEN, true, trg, key);
|
|
183
183
|
};
|
|
184
184
|
/**
|
|
@@ -189,7 +189,7 @@ var Validation = /** @class */ (function () {
|
|
|
189
189
|
*/
|
|
190
190
|
Validation.minLength = function (lBound) {
|
|
191
191
|
return function (trg, key) {
|
|
192
|
-
Reflect.defineMetadata(ValidationKey.MIN_LENGTH
|
|
192
|
+
Reflect.defineMetadata("".concat(ValidationKey.MIN_LENGTH, ":").concat(key.toString()), key, trg);
|
|
193
193
|
Reflect.defineMetadata(ValidationKey.MIN_LENGTH, lBound, trg, key);
|
|
194
194
|
};
|
|
195
195
|
};
|
|
@@ -201,7 +201,7 @@ var Validation = /** @class */ (function () {
|
|
|
201
201
|
*/
|
|
202
202
|
Validation.maxLength = function (uBound) {
|
|
203
203
|
return function (trg, key) {
|
|
204
|
-
Reflect.defineMetadata(ValidationKey.MAX_LENGTH
|
|
204
|
+
Reflect.defineMetadata("".concat(ValidationKey.MAX_LENGTH, ":").concat(key.toString()), key, trg);
|
|
205
205
|
Reflect.defineMetadata(ValidationKey.MAX_LENGTH, uBound, trg, key);
|
|
206
206
|
};
|
|
207
207
|
};
|
|
@@ -220,8 +220,8 @@ var Validation = /** @class */ (function () {
|
|
|
220
220
|
else
|
|
221
221
|
throw new TypeError('Unable to infer type key from: ' + lBound);
|
|
222
222
|
return function (trg, key) {
|
|
223
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
224
|
-
Reflect.defineMetadata(ValidationKey.MIN
|
|
223
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
224
|
+
Reflect.defineMetadata("".concat(ValidationKey.MIN, ":").concat(key.toString()), key, trg);
|
|
225
225
|
Reflect.defineMetadata(ValidationKey.TYPE, typekey, trg, key);
|
|
226
226
|
Reflect.defineMetadata(ValidationKey.MIN, lBound, trg, key);
|
|
227
227
|
};
|
|
@@ -241,8 +241,8 @@ var Validation = /** @class */ (function () {
|
|
|
241
241
|
else
|
|
242
242
|
throw new TypeError('Unable to infer type key from: ' + uBound);
|
|
243
243
|
return function (trg, key) {
|
|
244
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
245
|
-
Reflect.defineMetadata(ValidationKey.MAX
|
|
244
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
245
|
+
Reflect.defineMetadata("".concat(ValidationKey.MAX, ":").concat(key.toString()), key, trg);
|
|
246
246
|
Reflect.defineMetadata(ValidationKey.TYPE, typekey, trg, key);
|
|
247
247
|
Reflect.defineMetadata(ValidationKey.MAX, uBound, trg, key);
|
|
248
248
|
};
|
|
@@ -262,9 +262,9 @@ var Validation = /** @class */ (function () {
|
|
|
262
262
|
else
|
|
263
263
|
throw new TypeError('Unable to infer type key from: ' + lBound);
|
|
264
264
|
return function (trg, key) {
|
|
265
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
266
|
-
Reflect.defineMetadata(ValidationKey.MIN
|
|
267
|
-
Reflect.defineMetadata(ValidationKey.MAX
|
|
265
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
266
|
+
Reflect.defineMetadata("".concat(ValidationKey.MIN, ":").concat(key.toString()), key, trg);
|
|
267
|
+
Reflect.defineMetadata("".concat(ValidationKey.MAX, ":").concat(key.toString()), key, trg);
|
|
268
268
|
Reflect.defineMetadata(ValidationKey.TYPE, typekey, trg, key);
|
|
269
269
|
Reflect.defineMetadata(ValidationKey.MIN, lBound, trg, key);
|
|
270
270
|
Reflect.defineMetadata(ValidationKey.MAX, uBound, trg, key);
|
|
@@ -278,7 +278,7 @@ var Validation = /** @class */ (function () {
|
|
|
278
278
|
*/
|
|
279
279
|
Validation.regex = function (regex) {
|
|
280
280
|
return function (trg, key) {
|
|
281
|
-
Reflect.defineMetadata(ValidationKey.REGEX
|
|
281
|
+
Reflect.defineMetadata("".concat(ValidationKey.REGEX, ":").concat(key.toString()), key, trg);
|
|
282
282
|
Reflect.defineMetadata(ValidationKey.REGEX, regex, trg, key);
|
|
283
283
|
};
|
|
284
284
|
};
|
|
@@ -292,7 +292,7 @@ var Validation = /** @class */ (function () {
|
|
|
292
292
|
opts[_i] = arguments[_i];
|
|
293
293
|
}
|
|
294
294
|
return function (trg, key) {
|
|
295
|
-
Reflect.defineMetadata(ValidationKey.OPTIONS
|
|
295
|
+
Reflect.defineMetadata("".concat(ValidationKey.OPTIONS, ":").concat(key.toString()), key, trg);
|
|
296
296
|
Reflect.defineMetadata(ValidationKey.OPTIONS, opts, trg, key);
|
|
297
297
|
};
|
|
298
298
|
};
|
|
@@ -306,7 +306,7 @@ var Validation = /** @class */ (function () {
|
|
|
306
306
|
*/
|
|
307
307
|
Validation.custom = function (fn) {
|
|
308
308
|
return function (trg, key) {
|
|
309
|
-
Reflect.defineMetadata(ValidationKey.CUSTOM
|
|
309
|
+
Reflect.defineMetadata("".concat(ValidationKey.CUSTOM, ":").concat(key.toString()), key, trg);
|
|
310
310
|
Reflect.defineMetadata(ValidationKey.CUSTOM, fn, trg, key);
|
|
311
311
|
};
|
|
312
312
|
};
|
|
@@ -381,7 +381,7 @@ var RequiredValidator = function (trg, key, proto) {
|
|
|
381
381
|
var required = Reflect.getMetadata(ValidationKey.REQUIRED, proto, key) === true;
|
|
382
382
|
if (required) {
|
|
383
383
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
384
|
-
retVal.message = name_1
|
|
384
|
+
retVal.message = "".concat(name_1, " is required");
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
retVal.valid = !retVal.message;
|
|
@@ -396,10 +396,10 @@ var RegexValidator = function (trg, key, proto) {
|
|
|
396
396
|
var regex_1 = new RegExp(Reflect.getMetadata(ValidationKey.REGEX, proto, key));
|
|
397
397
|
var isArray = Array.isArray(value);
|
|
398
398
|
var tests = isArray ? value : [value];
|
|
399
|
-
var allOk = tests.every(function (test) { return regex_1.test(""
|
|
399
|
+
var allOk = tests.every(function (test) { return regex_1.test("".concat(test)); });
|
|
400
400
|
if (!allOk) {
|
|
401
401
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
402
|
-
retVal.message = isArray ? name_1
|
|
402
|
+
retVal.message = isArray ? "".concat(name_1, " contains an invalid item") : "".concat(name_1, " is invalid");
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
retVal.valid = !retVal.message;
|
|
@@ -407,7 +407,7 @@ var RegexValidator = function (trg, key, proto) {
|
|
|
407
407
|
};
|
|
408
408
|
|
|
409
409
|
var BooleanParser = function (obj) {
|
|
410
|
-
var str =
|
|
410
|
+
var str = "".concat(obj).toLowerCase();
|
|
411
411
|
if (['1', 'true'].indexOf(str) !== -1)
|
|
412
412
|
return true;
|
|
413
413
|
if (['0', 'false'].indexOf(str) !== -1)
|
|
@@ -425,13 +425,13 @@ var DateParser = function (obj) {
|
|
|
425
425
|
};
|
|
426
426
|
|
|
427
427
|
var IntegerParser = function (obj) {
|
|
428
|
-
var asInt = parseInt(""
|
|
429
|
-
if (!isNaN(asInt) && asInt.toFixed(8) === parseFloat(""
|
|
428
|
+
var asInt = parseInt("".concat(obj), 10);
|
|
429
|
+
if (!isNaN(asInt) && asInt.toFixed(8) === parseFloat("".concat(obj)).toFixed(8))
|
|
430
430
|
return asInt;
|
|
431
431
|
};
|
|
432
432
|
|
|
433
433
|
var NumberParser = function (obj) {
|
|
434
|
-
var test = parseFloat(""
|
|
434
|
+
var test = parseFloat("".concat(obj));
|
|
435
435
|
if (!isNaN(test))
|
|
436
436
|
return test;
|
|
437
437
|
};
|
|
@@ -469,7 +469,7 @@ var ReflectType = /** @class */ (function () {
|
|
|
469
469
|
case 'number':
|
|
470
470
|
return NumberParser;
|
|
471
471
|
default:
|
|
472
|
-
throw new RangeError("No parser implemented for "
|
|
472
|
+
throw new RangeError("No parser implemented for ".concat(type));
|
|
473
473
|
}
|
|
474
474
|
};
|
|
475
475
|
return ReflectType;
|
|
@@ -498,10 +498,10 @@ var RangeValidator = function (trg, key, proto) {
|
|
|
498
498
|
var boundImperative = isArray ? 'have a value' : 'be';
|
|
499
499
|
retVal.message =
|
|
500
500
|
hasMin_1 && hasMax_1
|
|
501
|
-
? name_1
|
|
501
|
+
? "".concat(name_1, " must ").concat(rangeImperative, " between ").concat(fmtMin, " and ").concat(fmtMax)
|
|
502
502
|
: hasMin_1
|
|
503
|
-
? name_1
|
|
504
|
-
: name_1
|
|
503
|
+
? "".concat(name_1, " cannot ").concat(boundImperative, " ").concat(compareLT, " ").concat(fmtMin)
|
|
504
|
+
: "".concat(name_1, " cannot ").concat(boundImperative, " ").concat(compareGT, " ").concat(fmtMax);
|
|
505
505
|
}
|
|
506
506
|
retVal.valid = !retVal.message;
|
|
507
507
|
}
|
|
@@ -525,10 +525,10 @@ var LengthRangeValidator = function (trg, key, proto) {
|
|
|
525
525
|
var pluraliser = value.length === 1 ? '' : 's';
|
|
526
526
|
retVal.message =
|
|
527
527
|
hasMinLen && hasMaxLen
|
|
528
|
-
? name_1
|
|
528
|
+
? "".concat(name_1, " must contain between ").concat(minLength, " and ").concat(maxLength, " ").concat(noun, "s")
|
|
529
529
|
: hasMinLen
|
|
530
|
-
? name_1
|
|
531
|
-
: name_1
|
|
530
|
+
? "".concat(name_1, " cannot contain fewer than ").concat(minLength, " ").concat(noun).concat(pluraliser)
|
|
531
|
+
: "".concat(name_1, " cannot contain more than ").concat(maxLength, " ").concat(noun).concat(pluraliser);
|
|
532
532
|
}
|
|
533
533
|
retVal.valid = !retVal.message;
|
|
534
534
|
}
|
|
@@ -548,8 +548,8 @@ var TypeValidator = function (trg, key, proto) {
|
|
|
548
548
|
if (!allOk) {
|
|
549
549
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
550
550
|
retVal.message = isArray
|
|
551
|
-
? name_1
|
|
552
|
-
: name_1
|
|
551
|
+
? "".concat(name_1, " contains an invalid ").concat(type)
|
|
552
|
+
: "".concat(name_1, " is not a valid ").concat(type);
|
|
553
553
|
}
|
|
554
554
|
}
|
|
555
555
|
retVal.valid = !retVal.message;
|
|
@@ -567,7 +567,7 @@ var CustValidator = function (trg, key, proto) {
|
|
|
567
567
|
retVal.message = result;
|
|
568
568
|
else if (result === false) {
|
|
569
569
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
570
|
-
retVal.message = name_1
|
|
570
|
+
retVal.message = "".concat(name_1, " is invalid");
|
|
571
571
|
}
|
|
572
572
|
retVal.valid = !retVal.message;
|
|
573
573
|
return retVal;
|
|
@@ -581,7 +581,7 @@ var ForbiddenValidator = function (trg, key, proto) {
|
|
|
581
581
|
var forbidden = Reflect.getMetadata(ValidationKey.FORBIDDEN, proto, key) === true;
|
|
582
582
|
if (forbidden) {
|
|
583
583
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
584
|
-
retVal.message = name_1
|
|
584
|
+
retVal.message = "".concat(name_1, " is forbidden");
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
587
|
retVal.valid = !retVal.message;
|
|
@@ -600,8 +600,8 @@ var OptionsValidator = function (trg, key, proto) {
|
|
|
600
600
|
if (!allOk) {
|
|
601
601
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
602
602
|
retVal.message = isArray
|
|
603
|
-
? name_1
|
|
604
|
-
: name_1
|
|
603
|
+
? "".concat(name_1, " contains an invalid option")
|
|
604
|
+
: "".concat(name_1, " is an invalid option");
|
|
605
605
|
}
|
|
606
606
|
}
|
|
607
607
|
retVal.valid = !retVal.message;
|
|
@@ -661,7 +661,7 @@ var ReflectValidation = /** @class */ (function () {
|
|
|
661
661
|
case ValidationKey.CUSTOM:
|
|
662
662
|
return CustValidator;
|
|
663
663
|
default:
|
|
664
|
-
throw new RangeError("No validator implemented for "
|
|
664
|
+
throw new RangeError("No validator implemented for ".concat(key));
|
|
665
665
|
}
|
|
666
666
|
};
|
|
667
667
|
/** Prepares a sequence of validation instructions. */
|
|
@@ -677,12 +677,12 @@ var ReflectValidation = /** @class */ (function () {
|
|
|
677
677
|
: 0;
|
|
678
678
|
};
|
|
679
679
|
return Reflect.getMetadataKeys(proto)
|
|
680
|
-
.map(function (k) { return ""
|
|
680
|
+
.map(function (k) { return "".concat(k); })
|
|
681
681
|
.reduce(function (acc, cur) {
|
|
682
682
|
var valDef = allChecks.filter(function (dg) { return cur.indexOf(dg.meta + ':') === 0; })[0];
|
|
683
683
|
if (valDef) {
|
|
684
684
|
var key = cur.replace(valDef.meta + ':', '');
|
|
685
|
-
var navkey_1 = pfx ? pfx
|
|
685
|
+
var navkey_1 = pfx ? "".concat(pfx, ".").concat(key) : key;
|
|
686
686
|
var prior = acc.filter(function (a) { return a.navkey === navkey_1 && a.fn === valDef.fn; })[0];
|
|
687
687
|
if (prior) {
|
|
688
688
|
prior.tests.push(valDef.test);
|
|
@@ -698,18 +698,18 @@ var ReflectValidation = /** @class */ (function () {
|
|
|
698
698
|
});
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
|
-
else if (cur.indexOf(MetadataKey.MODEL
|
|
702
|
-
var subkey_1 = cur.replace(MetadataKey.MODEL
|
|
701
|
+
else if (cur.indexOf("".concat(MetadataKey.MODEL, ":")) === 0) {
|
|
702
|
+
var subkey_1 = cur.replace("".concat(MetadataKey.MODEL, ":"), '');
|
|
703
703
|
var subproto_1 = Reflect.getMetadata(cur, proto).prototype;
|
|
704
704
|
var subobj = (trg || {})[subkey_1];
|
|
705
705
|
if (Array.isArray(subobj)) {
|
|
706
706
|
subobj.forEach(function (subitem, i) {
|
|
707
|
-
var subpfx = pfx ? pfx
|
|
707
|
+
var subpfx = pfx ? "".concat(pfx, ".").concat(subkey_1, "[").concat(i, "]") : "".concat(subkey_1, "[").concat(i, "]");
|
|
708
708
|
acc.push.apply(acc, ReflectValidation.getTestInstructions(allChecks, subproto_1, subitem || {}, subpfx));
|
|
709
709
|
});
|
|
710
710
|
}
|
|
711
711
|
else if (subobj) {
|
|
712
|
-
var subpfx = pfx ? pfx
|
|
712
|
+
var subpfx = pfx ? "".concat(pfx, ".").concat(subkey_1) : subkey_1;
|
|
713
713
|
acc.push.apply(acc, ReflectValidation.getTestInstructions(allChecks, subproto_1, subobj, subpfx));
|
|
714
714
|
}
|
|
715
715
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('reflect-metadata')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'reflect-metadata'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ne_codl = {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Whether a value is considered as having been provided.
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
/** Associates a child's prototype data on the parent in which it appears. */
|
|
137
137
|
Metadata.model = function (ctor) {
|
|
138
138
|
return function (trg, key) {
|
|
139
|
-
Reflect.defineMetadata(MetadataKey.MODEL
|
|
139
|
+
Reflect.defineMetadata("".concat(MetadataKey.MODEL, ":").concat(key.toString()), ctor, trg);
|
|
140
140
|
};
|
|
141
141
|
};
|
|
142
142
|
return Metadata;
|
|
@@ -147,19 +147,19 @@
|
|
|
147
147
|
function Type() {
|
|
148
148
|
}
|
|
149
149
|
Type.boolean = function (trg, key) {
|
|
150
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
150
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
151
151
|
Reflect.defineMetadata(ValidationKey.TYPE, 'boolean', trg, key);
|
|
152
152
|
};
|
|
153
153
|
Type.date = function (trg, key) {
|
|
154
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
154
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
155
155
|
Reflect.defineMetadata(ValidationKey.TYPE, 'date', trg, key);
|
|
156
156
|
};
|
|
157
157
|
Type.integer = function (trg, key) {
|
|
158
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
158
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
159
159
|
Reflect.defineMetadata(ValidationKey.TYPE, 'integer', trg, key);
|
|
160
160
|
};
|
|
161
161
|
Type.number = function (trg, key) {
|
|
162
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
162
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
163
163
|
Reflect.defineMetadata(ValidationKey.TYPE, 'number', trg, key);
|
|
164
164
|
};
|
|
165
165
|
return Type;
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
* invalid, as is NaN. Anything else is valid (including: 0, 0n, false).
|
|
175
175
|
*/
|
|
176
176
|
Validation.required = function (trg, key) {
|
|
177
|
-
Reflect.defineMetadata(ValidationKey.REQUIRED
|
|
177
|
+
Reflect.defineMetadata("".concat(ValidationKey.REQUIRED, ":").concat(key.toString()), key, trg);
|
|
178
178
|
Reflect.defineMetadata(ValidationKey.REQUIRED, true, trg, key);
|
|
179
179
|
};
|
|
180
180
|
/**
|
|
@@ -182,7 +182,7 @@
|
|
|
182
182
|
* valid. Anything else is considered invalid (including: 0, 0n, false).
|
|
183
183
|
*/
|
|
184
184
|
Validation.forbidden = function (trg, key) {
|
|
185
|
-
Reflect.defineMetadata(ValidationKey.FORBIDDEN
|
|
185
|
+
Reflect.defineMetadata("".concat(ValidationKey.FORBIDDEN, ":").concat(key.toString()), key, trg);
|
|
186
186
|
Reflect.defineMetadata(ValidationKey.FORBIDDEN, true, trg, key);
|
|
187
187
|
};
|
|
188
188
|
/**
|
|
@@ -193,7 +193,7 @@
|
|
|
193
193
|
*/
|
|
194
194
|
Validation.minLength = function (lBound) {
|
|
195
195
|
return function (trg, key) {
|
|
196
|
-
Reflect.defineMetadata(ValidationKey.MIN_LENGTH
|
|
196
|
+
Reflect.defineMetadata("".concat(ValidationKey.MIN_LENGTH, ":").concat(key.toString()), key, trg);
|
|
197
197
|
Reflect.defineMetadata(ValidationKey.MIN_LENGTH, lBound, trg, key);
|
|
198
198
|
};
|
|
199
199
|
};
|
|
@@ -205,7 +205,7 @@
|
|
|
205
205
|
*/
|
|
206
206
|
Validation.maxLength = function (uBound) {
|
|
207
207
|
return function (trg, key) {
|
|
208
|
-
Reflect.defineMetadata(ValidationKey.MAX_LENGTH
|
|
208
|
+
Reflect.defineMetadata("".concat(ValidationKey.MAX_LENGTH, ":").concat(key.toString()), key, trg);
|
|
209
209
|
Reflect.defineMetadata(ValidationKey.MAX_LENGTH, uBound, trg, key);
|
|
210
210
|
};
|
|
211
211
|
};
|
|
@@ -224,8 +224,8 @@
|
|
|
224
224
|
else
|
|
225
225
|
throw new TypeError('Unable to infer type key from: ' + lBound);
|
|
226
226
|
return function (trg, key) {
|
|
227
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
228
|
-
Reflect.defineMetadata(ValidationKey.MIN
|
|
227
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
228
|
+
Reflect.defineMetadata("".concat(ValidationKey.MIN, ":").concat(key.toString()), key, trg);
|
|
229
229
|
Reflect.defineMetadata(ValidationKey.TYPE, typekey, trg, key);
|
|
230
230
|
Reflect.defineMetadata(ValidationKey.MIN, lBound, trg, key);
|
|
231
231
|
};
|
|
@@ -245,8 +245,8 @@
|
|
|
245
245
|
else
|
|
246
246
|
throw new TypeError('Unable to infer type key from: ' + uBound);
|
|
247
247
|
return function (trg, key) {
|
|
248
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
249
|
-
Reflect.defineMetadata(ValidationKey.MAX
|
|
248
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
249
|
+
Reflect.defineMetadata("".concat(ValidationKey.MAX, ":").concat(key.toString()), key, trg);
|
|
250
250
|
Reflect.defineMetadata(ValidationKey.TYPE, typekey, trg, key);
|
|
251
251
|
Reflect.defineMetadata(ValidationKey.MAX, uBound, trg, key);
|
|
252
252
|
};
|
|
@@ -266,9 +266,9 @@
|
|
|
266
266
|
else
|
|
267
267
|
throw new TypeError('Unable to infer type key from: ' + lBound);
|
|
268
268
|
return function (trg, key) {
|
|
269
|
-
Reflect.defineMetadata(ValidationKey.TYPE
|
|
270
|
-
Reflect.defineMetadata(ValidationKey.MIN
|
|
271
|
-
Reflect.defineMetadata(ValidationKey.MAX
|
|
269
|
+
Reflect.defineMetadata("".concat(ValidationKey.TYPE, ":").concat(key.toString()), key, trg);
|
|
270
|
+
Reflect.defineMetadata("".concat(ValidationKey.MIN, ":").concat(key.toString()), key, trg);
|
|
271
|
+
Reflect.defineMetadata("".concat(ValidationKey.MAX, ":").concat(key.toString()), key, trg);
|
|
272
272
|
Reflect.defineMetadata(ValidationKey.TYPE, typekey, trg, key);
|
|
273
273
|
Reflect.defineMetadata(ValidationKey.MIN, lBound, trg, key);
|
|
274
274
|
Reflect.defineMetadata(ValidationKey.MAX, uBound, trg, key);
|
|
@@ -282,7 +282,7 @@
|
|
|
282
282
|
*/
|
|
283
283
|
Validation.regex = function (regex) {
|
|
284
284
|
return function (trg, key) {
|
|
285
|
-
Reflect.defineMetadata(ValidationKey.REGEX
|
|
285
|
+
Reflect.defineMetadata("".concat(ValidationKey.REGEX, ":").concat(key.toString()), key, trg);
|
|
286
286
|
Reflect.defineMetadata(ValidationKey.REGEX, regex, trg, key);
|
|
287
287
|
};
|
|
288
288
|
};
|
|
@@ -296,7 +296,7 @@
|
|
|
296
296
|
opts[_i] = arguments[_i];
|
|
297
297
|
}
|
|
298
298
|
return function (trg, key) {
|
|
299
|
-
Reflect.defineMetadata(ValidationKey.OPTIONS
|
|
299
|
+
Reflect.defineMetadata("".concat(ValidationKey.OPTIONS, ":").concat(key.toString()), key, trg);
|
|
300
300
|
Reflect.defineMetadata(ValidationKey.OPTIONS, opts, trg, key);
|
|
301
301
|
};
|
|
302
302
|
};
|
|
@@ -310,7 +310,7 @@
|
|
|
310
310
|
*/
|
|
311
311
|
Validation.custom = function (fn) {
|
|
312
312
|
return function (trg, key) {
|
|
313
|
-
Reflect.defineMetadata(ValidationKey.CUSTOM
|
|
313
|
+
Reflect.defineMetadata("".concat(ValidationKey.CUSTOM, ":").concat(key.toString()), key, trg);
|
|
314
314
|
Reflect.defineMetadata(ValidationKey.CUSTOM, fn, trg, key);
|
|
315
315
|
};
|
|
316
316
|
};
|
|
@@ -385,7 +385,7 @@
|
|
|
385
385
|
var required = Reflect.getMetadata(ValidationKey.REQUIRED, proto, key) === true;
|
|
386
386
|
if (required) {
|
|
387
387
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
388
|
-
retVal.message = name_1
|
|
388
|
+
retVal.message = "".concat(name_1, " is required");
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
391
|
retVal.valid = !retVal.message;
|
|
@@ -400,10 +400,10 @@
|
|
|
400
400
|
var regex_1 = new RegExp(Reflect.getMetadata(ValidationKey.REGEX, proto, key));
|
|
401
401
|
var isArray = Array.isArray(value);
|
|
402
402
|
var tests = isArray ? value : [value];
|
|
403
|
-
var allOk = tests.every(function (test) { return regex_1.test(""
|
|
403
|
+
var allOk = tests.every(function (test) { return regex_1.test("".concat(test)); });
|
|
404
404
|
if (!allOk) {
|
|
405
405
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
406
|
-
retVal.message = isArray ? name_1
|
|
406
|
+
retVal.message = isArray ? "".concat(name_1, " contains an invalid item") : "".concat(name_1, " is invalid");
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
retVal.valid = !retVal.message;
|
|
@@ -411,7 +411,7 @@
|
|
|
411
411
|
};
|
|
412
412
|
|
|
413
413
|
var BooleanParser = function (obj) {
|
|
414
|
-
var str =
|
|
414
|
+
var str = "".concat(obj).toLowerCase();
|
|
415
415
|
if (['1', 'true'].indexOf(str) !== -1)
|
|
416
416
|
return true;
|
|
417
417
|
if (['0', 'false'].indexOf(str) !== -1)
|
|
@@ -429,13 +429,13 @@
|
|
|
429
429
|
};
|
|
430
430
|
|
|
431
431
|
var IntegerParser = function (obj) {
|
|
432
|
-
var asInt = parseInt(""
|
|
433
|
-
if (!isNaN(asInt) && asInt.toFixed(8) === parseFloat(""
|
|
432
|
+
var asInt = parseInt("".concat(obj), 10);
|
|
433
|
+
if (!isNaN(asInt) && asInt.toFixed(8) === parseFloat("".concat(obj)).toFixed(8))
|
|
434
434
|
return asInt;
|
|
435
435
|
};
|
|
436
436
|
|
|
437
437
|
var NumberParser = function (obj) {
|
|
438
|
-
var test = parseFloat(""
|
|
438
|
+
var test = parseFloat("".concat(obj));
|
|
439
439
|
if (!isNaN(test))
|
|
440
440
|
return test;
|
|
441
441
|
};
|
|
@@ -473,7 +473,7 @@
|
|
|
473
473
|
case 'number':
|
|
474
474
|
return NumberParser;
|
|
475
475
|
default:
|
|
476
|
-
throw new RangeError("No parser implemented for "
|
|
476
|
+
throw new RangeError("No parser implemented for ".concat(type));
|
|
477
477
|
}
|
|
478
478
|
};
|
|
479
479
|
return ReflectType;
|
|
@@ -502,10 +502,10 @@
|
|
|
502
502
|
var boundImperative = isArray ? 'have a value' : 'be';
|
|
503
503
|
retVal.message =
|
|
504
504
|
hasMin_1 && hasMax_1
|
|
505
|
-
? name_1
|
|
505
|
+
? "".concat(name_1, " must ").concat(rangeImperative, " between ").concat(fmtMin, " and ").concat(fmtMax)
|
|
506
506
|
: hasMin_1
|
|
507
|
-
? name_1
|
|
508
|
-
: name_1
|
|
507
|
+
? "".concat(name_1, " cannot ").concat(boundImperative, " ").concat(compareLT, " ").concat(fmtMin)
|
|
508
|
+
: "".concat(name_1, " cannot ").concat(boundImperative, " ").concat(compareGT, " ").concat(fmtMax);
|
|
509
509
|
}
|
|
510
510
|
retVal.valid = !retVal.message;
|
|
511
511
|
}
|
|
@@ -529,10 +529,10 @@
|
|
|
529
529
|
var pluraliser = value.length === 1 ? '' : 's';
|
|
530
530
|
retVal.message =
|
|
531
531
|
hasMinLen && hasMaxLen
|
|
532
|
-
? name_1
|
|
532
|
+
? "".concat(name_1, " must contain between ").concat(minLength, " and ").concat(maxLength, " ").concat(noun, "s")
|
|
533
533
|
: hasMinLen
|
|
534
|
-
? name_1
|
|
535
|
-
: name_1
|
|
534
|
+
? "".concat(name_1, " cannot contain fewer than ").concat(minLength, " ").concat(noun).concat(pluraliser)
|
|
535
|
+
: "".concat(name_1, " cannot contain more than ").concat(maxLength, " ").concat(noun).concat(pluraliser);
|
|
536
536
|
}
|
|
537
537
|
retVal.valid = !retVal.message;
|
|
538
538
|
}
|
|
@@ -552,8 +552,8 @@
|
|
|
552
552
|
if (!allOk) {
|
|
553
553
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
554
554
|
retVal.message = isArray
|
|
555
|
-
? name_1
|
|
556
|
-
: name_1
|
|
555
|
+
? "".concat(name_1, " contains an invalid ").concat(type)
|
|
556
|
+
: "".concat(name_1, " is not a valid ").concat(type);
|
|
557
557
|
}
|
|
558
558
|
}
|
|
559
559
|
retVal.valid = !retVal.message;
|
|
@@ -571,7 +571,7 @@
|
|
|
571
571
|
retVal.message = result;
|
|
572
572
|
else if (result === false) {
|
|
573
573
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
574
|
-
retVal.message = name_1
|
|
574
|
+
retVal.message = "".concat(name_1, " is invalid");
|
|
575
575
|
}
|
|
576
576
|
retVal.valid = !retVal.message;
|
|
577
577
|
return retVal;
|
|
@@ -585,7 +585,7 @@
|
|
|
585
585
|
var forbidden = Reflect.getMetadata(ValidationKey.FORBIDDEN, proto, key) === true;
|
|
586
586
|
if (forbidden) {
|
|
587
587
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
588
|
-
retVal.message = name_1
|
|
588
|
+
retVal.message = "".concat(name_1, " is forbidden");
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
591
|
retVal.valid = !retVal.message;
|
|
@@ -604,8 +604,8 @@
|
|
|
604
604
|
if (!allOk) {
|
|
605
605
|
var name_1 = ReflectMetadata.getDisplayName(proto, key);
|
|
606
606
|
retVal.message = isArray
|
|
607
|
-
? name_1
|
|
608
|
-
: name_1
|
|
607
|
+
? "".concat(name_1, " contains an invalid option")
|
|
608
|
+
: "".concat(name_1, " is an invalid option");
|
|
609
609
|
}
|
|
610
610
|
}
|
|
611
611
|
retVal.valid = !retVal.message;
|
|
@@ -665,7 +665,7 @@
|
|
|
665
665
|
case ValidationKey.CUSTOM:
|
|
666
666
|
return CustValidator;
|
|
667
667
|
default:
|
|
668
|
-
throw new RangeError("No validator implemented for "
|
|
668
|
+
throw new RangeError("No validator implemented for ".concat(key));
|
|
669
669
|
}
|
|
670
670
|
};
|
|
671
671
|
/** Prepares a sequence of validation instructions. */
|
|
@@ -681,12 +681,12 @@
|
|
|
681
681
|
: 0;
|
|
682
682
|
};
|
|
683
683
|
return Reflect.getMetadataKeys(proto)
|
|
684
|
-
.map(function (k) { return ""
|
|
684
|
+
.map(function (k) { return "".concat(k); })
|
|
685
685
|
.reduce(function (acc, cur) {
|
|
686
686
|
var valDef = allChecks.filter(function (dg) { return cur.indexOf(dg.meta + ':') === 0; })[0];
|
|
687
687
|
if (valDef) {
|
|
688
688
|
var key = cur.replace(valDef.meta + ':', '');
|
|
689
|
-
var navkey_1 = pfx ? pfx
|
|
689
|
+
var navkey_1 = pfx ? "".concat(pfx, ".").concat(key) : key;
|
|
690
690
|
var prior = acc.filter(function (a) { return a.navkey === navkey_1 && a.fn === valDef.fn; })[0];
|
|
691
691
|
if (prior) {
|
|
692
692
|
prior.tests.push(valDef.test);
|
|
@@ -702,18 +702,18 @@
|
|
|
702
702
|
});
|
|
703
703
|
}
|
|
704
704
|
}
|
|
705
|
-
else if (cur.indexOf(MetadataKey.MODEL
|
|
706
|
-
var subkey_1 = cur.replace(MetadataKey.MODEL
|
|
705
|
+
else if (cur.indexOf("".concat(MetadataKey.MODEL, ":")) === 0) {
|
|
706
|
+
var subkey_1 = cur.replace("".concat(MetadataKey.MODEL, ":"), '');
|
|
707
707
|
var subproto_1 = Reflect.getMetadata(cur, proto).prototype;
|
|
708
708
|
var subobj = (trg || {})[subkey_1];
|
|
709
709
|
if (Array.isArray(subobj)) {
|
|
710
710
|
subobj.forEach(function (subitem, i) {
|
|
711
|
-
var subpfx = pfx ? pfx
|
|
711
|
+
var subpfx = pfx ? "".concat(pfx, ".").concat(subkey_1, "[").concat(i, "]") : "".concat(subkey_1, "[").concat(i, "]");
|
|
712
712
|
acc.push.apply(acc, ReflectValidation.getTestInstructions(allChecks, subproto_1, subitem || {}, subpfx));
|
|
713
713
|
});
|
|
714
714
|
}
|
|
715
715
|
else if (subobj) {
|
|
716
|
-
var subpfx = pfx ? pfx
|
|
716
|
+
var subpfx = pfx ? "".concat(pfx, ".").concat(subkey_1) : subkey_1;
|
|
717
717
|
acc.push.apply(acc, ReflectValidation.getTestInstructions(allChecks, subproto_1, subobj, subpfx));
|
|
718
718
|
}
|
|
719
719
|
}
|
|
@@ -803,4 +803,4 @@
|
|
|
803
803
|
|
|
804
804
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
805
805
|
|
|
806
|
-
}))
|
|
806
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ne1410s/codl",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"description": "Indulge your apps with codl: a component model library",
|
|
5
5
|
"main": "dist/ne14_codl.cjs.min.js",
|
|
6
6
|
"module": "dist/ne14_codl.esm.min.js",
|
|
@@ -38,12 +38,13 @@
|
|
|
38
38
|
"homepage": "https://github.com/ne1410s/core.codl#readme",
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"chai": "^4.3.4",
|
|
41
|
-
"mocha": "^9.
|
|
42
|
-
"prettier": "^2.
|
|
41
|
+
"mocha": "^9.1.3",
|
|
42
|
+
"prettier": "^2.5.1",
|
|
43
43
|
"rimraf": "^3.0.2",
|
|
44
|
-
"rollup": "^2.
|
|
45
|
-
"rollup-plugin-typescript2": "^0.
|
|
46
|
-
"
|
|
44
|
+
"rollup": "^2.61.1",
|
|
45
|
+
"rollup-plugin-typescript2": "^0.31.1",
|
|
46
|
+
"tslib": "^2.3.1",
|
|
47
|
+
"typescript": "^4.5.3"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
50
|
"reflect-metadata": "^0.1.13"
|