@brikka/locations 1.0.3 → 1.0.5
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/index.cjs.js +341 -104
- package/index.esm.js +341 -102
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var jsxRuntime = require('@soperio/jsx-runtime');
|
|
6
4
|
var admin = require('@compill/admin');
|
|
7
5
|
var form = require('@compill/form');
|
|
@@ -27,6 +25,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
27
25
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
28
26
|
PERFORMANCE OF THIS SOFTWARE.
|
|
29
27
|
***************************************************************************** */
|
|
28
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
29
|
+
|
|
30
30
|
|
|
31
31
|
function __rest(s, e) {
|
|
32
32
|
var t = {};
|
|
@@ -45,6 +45,10 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
45
45
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
function getDefaultExportFromCjs (x) {
|
|
49
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
50
|
+
}
|
|
51
|
+
|
|
48
52
|
/**
|
|
49
53
|
* Based on Kendo UI Core expression code <https://github.com/telerik/kendo-ui-core#license-information>
|
|
50
54
|
*/
|
|
@@ -341,7 +345,8 @@ function makeNodesHash(arr){
|
|
|
341
345
|
return res
|
|
342
346
|
}
|
|
343
347
|
|
|
344
|
-
var
|
|
348
|
+
var toposortExports = toposort$2.exports;
|
|
349
|
+
var toposort$1 = /*@__PURE__*/getDefaultExportFromCjs(toposortExports);
|
|
345
350
|
|
|
346
351
|
const toString = Object.prototype.toString;
|
|
347
352
|
const errorToString = Error.prototype.toString;
|
|
@@ -380,28 +385,20 @@ function toArray(value) {
|
|
|
380
385
|
return value == null ? [] : [].concat(value);
|
|
381
386
|
}
|
|
382
387
|
|
|
388
|
+
let _Symbol$toStringTag, _Symbol$hasInstance, _Symbol$toStringTag2;
|
|
383
389
|
let strReg = /\$\{\s*(\w+)\s*\}/g;
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const path = params.label || params.path || 'this';
|
|
387
|
-
if (path !== params.path) params = Object.assign({}, params, {
|
|
388
|
-
path
|
|
389
|
-
});
|
|
390
|
-
if (typeof message === 'string') return message.replace(strReg, (_, key) => printValue(params[key]));
|
|
391
|
-
if (typeof message === 'function') return message(params);
|
|
392
|
-
return message;
|
|
393
|
-
}
|
|
394
|
-
static isError(err) {
|
|
395
|
-
return err && err.name === 'ValidationError';
|
|
396
|
-
}
|
|
390
|
+
_Symbol$toStringTag = Symbol.toStringTag;
|
|
391
|
+
class ValidationErrorNoStack {
|
|
397
392
|
constructor(errorOrErrors, value, field, type) {
|
|
398
|
-
|
|
393
|
+
this.name = void 0;
|
|
394
|
+
this.message = void 0;
|
|
399
395
|
this.value = void 0;
|
|
400
396
|
this.path = void 0;
|
|
401
397
|
this.type = void 0;
|
|
402
|
-
this.errors = void 0;
|
|
403
398
|
this.params = void 0;
|
|
399
|
+
this.errors = void 0;
|
|
404
400
|
this.inner = void 0;
|
|
401
|
+
this[_Symbol$toStringTag] = 'Error';
|
|
405
402
|
this.name = 'ValidationError';
|
|
406
403
|
this.value = value;
|
|
407
404
|
this.path = field;
|
|
@@ -411,13 +408,60 @@ class ValidationError extends Error {
|
|
|
411
408
|
toArray(errorOrErrors).forEach(err => {
|
|
412
409
|
if (ValidationError.isError(err)) {
|
|
413
410
|
this.errors.push(...err.errors);
|
|
414
|
-
|
|
411
|
+
const innerErrors = err.inner.length ? err.inner : [err];
|
|
412
|
+
this.inner.push(...innerErrors);
|
|
415
413
|
} else {
|
|
416
414
|
this.errors.push(err);
|
|
417
415
|
}
|
|
418
416
|
});
|
|
419
417
|
this.message = this.errors.length > 1 ? `${this.errors.length} errors occurred` : this.errors[0];
|
|
420
|
-
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
_Symbol$hasInstance = Symbol.hasInstance;
|
|
421
|
+
_Symbol$toStringTag2 = Symbol.toStringTag;
|
|
422
|
+
class ValidationError extends Error {
|
|
423
|
+
static formatError(message, params) {
|
|
424
|
+
// Attempt to make the path more friendly for error message interpolation.
|
|
425
|
+
const path = params.label || params.path || 'this';
|
|
426
|
+
// Store the original path under `originalPath` so it isn't lost to custom
|
|
427
|
+
// message functions; e.g., ones provided in `setLocale()` calls.
|
|
428
|
+
params = Object.assign({}, params, {
|
|
429
|
+
path,
|
|
430
|
+
originalPath: params.path
|
|
431
|
+
});
|
|
432
|
+
if (typeof message === 'string') return message.replace(strReg, (_, key) => printValue(params[key]));
|
|
433
|
+
if (typeof message === 'function') return message(params);
|
|
434
|
+
return message;
|
|
435
|
+
}
|
|
436
|
+
static isError(err) {
|
|
437
|
+
return err && err.name === 'ValidationError';
|
|
438
|
+
}
|
|
439
|
+
constructor(errorOrErrors, value, field, type, disableStack) {
|
|
440
|
+
const errorNoStack = new ValidationErrorNoStack(errorOrErrors, value, field, type);
|
|
441
|
+
if (disableStack) {
|
|
442
|
+
return errorNoStack;
|
|
443
|
+
}
|
|
444
|
+
super();
|
|
445
|
+
this.value = void 0;
|
|
446
|
+
this.path = void 0;
|
|
447
|
+
this.type = void 0;
|
|
448
|
+
this.params = void 0;
|
|
449
|
+
this.errors = [];
|
|
450
|
+
this.inner = [];
|
|
451
|
+
this[_Symbol$toStringTag2] = 'Error';
|
|
452
|
+
this.name = errorNoStack.name;
|
|
453
|
+
this.message = errorNoStack.message;
|
|
454
|
+
this.type = errorNoStack.type;
|
|
455
|
+
this.value = errorNoStack.value;
|
|
456
|
+
this.path = errorNoStack.path;
|
|
457
|
+
this.errors = errorNoStack.errors;
|
|
458
|
+
this.inner = errorNoStack.inner;
|
|
459
|
+
if (Error.captureStackTrace) {
|
|
460
|
+
Error.captureStackTrace(this, ValidationError);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
static [_Symbol$hasInstance](inst) {
|
|
464
|
+
return ValidationErrorNoStack[Symbol.hasInstance](inst) || super[Symbol.hasInstance](inst);
|
|
421
465
|
}
|
|
422
466
|
}
|
|
423
467
|
|
|
@@ -446,6 +490,9 @@ let string = {
|
|
|
446
490
|
email: '${path} must be a valid email',
|
|
447
491
|
url: '${path} must be a valid URL',
|
|
448
492
|
uuid: '${path} must be a valid UUID',
|
|
493
|
+
datetime: '${path} must be a valid ISO date-time',
|
|
494
|
+
datetime_precision: '${path} must be a valid ISO date-time with a sub-second precision of exactly ${precision} digits',
|
|
495
|
+
datetime_offset: '${path} must be a valid ISO date-time with UTC "Z" timezone',
|
|
449
496
|
trim: '${path} must be a trimmed string',
|
|
450
497
|
lowercase: '${path} must be a lowercase string',
|
|
451
498
|
uppercase: '${path} must be a upper case string'
|
|
@@ -467,13 +514,29 @@ let boolean = {
|
|
|
467
514
|
isValue: '${path} field must be ${value}'
|
|
468
515
|
};
|
|
469
516
|
let object = {
|
|
470
|
-
noUnknown: '${path} field has unspecified keys: ${unknown}'
|
|
517
|
+
noUnknown: '${path} field has unspecified keys: ${unknown}',
|
|
518
|
+
exact: '${path} object contains unknown properties: ${properties}'
|
|
471
519
|
};
|
|
472
520
|
let array = {
|
|
473
521
|
min: '${path} field must have at least ${min} items',
|
|
474
522
|
max: '${path} field must have less than or equal to ${max} items',
|
|
475
523
|
length: '${path} must have ${length} items'
|
|
476
524
|
};
|
|
525
|
+
let tuple = {
|
|
526
|
+
notType: params => {
|
|
527
|
+
const {
|
|
528
|
+
path,
|
|
529
|
+
value,
|
|
530
|
+
spec
|
|
531
|
+
} = params;
|
|
532
|
+
const typeLen = spec.types.length;
|
|
533
|
+
if (Array.isArray(value)) {
|
|
534
|
+
if (value.length < typeLen) return `${path} tuple value has too few items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
|
|
535
|
+
if (value.length > typeLen) return `${path} tuple value has too many items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
|
|
536
|
+
}
|
|
537
|
+
return ValidationError.formatError(mixed.notType, params);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
477
540
|
Object.assign(Object.create(null), {
|
|
478
541
|
mixed,
|
|
479
542
|
string,
|
|
@@ -481,7 +544,8 @@ Object.assign(Object.create(null), {
|
|
|
481
544
|
date,
|
|
482
545
|
object,
|
|
483
546
|
array,
|
|
484
|
-
boolean
|
|
547
|
+
boolean,
|
|
548
|
+
tuple
|
|
485
549
|
});
|
|
486
550
|
|
|
487
551
|
const isSchema = obj => obj && obj.__isYupSchema__;
|
|
@@ -603,21 +667,24 @@ function createValidation(config) {
|
|
|
603
667
|
let {
|
|
604
668
|
parent,
|
|
605
669
|
context,
|
|
606
|
-
abortEarly = schema.spec.abortEarly
|
|
670
|
+
abortEarly = schema.spec.abortEarly,
|
|
671
|
+
disableStackTrace = schema.spec.disableStackTrace
|
|
607
672
|
} = options;
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
673
|
+
const resolveOptions = {
|
|
674
|
+
value,
|
|
675
|
+
parent,
|
|
676
|
+
context
|
|
677
|
+
};
|
|
611
678
|
function createError(overrides = {}) {
|
|
612
|
-
const nextParams = Object.assign({
|
|
679
|
+
const nextParams = resolveParams(Object.assign({
|
|
613
680
|
value,
|
|
614
681
|
originalValue,
|
|
615
682
|
label: schema.spec.label,
|
|
616
683
|
path: overrides.path || path,
|
|
617
|
-
spec: schema.spec
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name);
|
|
684
|
+
spec: schema.spec,
|
|
685
|
+
disableStackTrace: overrides.disableStackTrace || disableStackTrace
|
|
686
|
+
}, params, overrides.params), resolveOptions);
|
|
687
|
+
const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
|
|
621
688
|
error.params = nextParams;
|
|
622
689
|
return error;
|
|
623
690
|
}
|
|
@@ -628,7 +695,9 @@ function createValidation(config) {
|
|
|
628
695
|
type: name,
|
|
629
696
|
from: options.from,
|
|
630
697
|
createError,
|
|
631
|
-
resolve
|
|
698
|
+
resolve(item) {
|
|
699
|
+
return resolveMaybeRef(item, resolveOptions);
|
|
700
|
+
},
|
|
632
701
|
options,
|
|
633
702
|
originalValue,
|
|
634
703
|
schema
|
|
@@ -640,20 +709,18 @@ function createValidation(config) {
|
|
|
640
709
|
if (ValidationError.isError(err)) invalid(err);else panic(err);
|
|
641
710
|
};
|
|
642
711
|
const shouldSkip = skipAbsent && isAbsent(value);
|
|
643
|
-
if (
|
|
644
|
-
|
|
645
|
-
Promise.resolve(!shouldSkip ? test.call(ctx, value, ctx) : true).then(handleResult, handleError);
|
|
646
|
-
} catch (err) {
|
|
647
|
-
handleError(err);
|
|
648
|
-
}
|
|
649
|
-
return;
|
|
712
|
+
if (shouldSkip) {
|
|
713
|
+
return handleResult(true);
|
|
650
714
|
}
|
|
651
715
|
let result;
|
|
652
716
|
try {
|
|
653
717
|
var _result;
|
|
654
|
-
result =
|
|
718
|
+
result = test.call(ctx, value, ctx);
|
|
655
719
|
if (typeof ((_result = result) == null ? void 0 : _result.then) === 'function') {
|
|
656
|
-
|
|
720
|
+
if (options.sync) {
|
|
721
|
+
throw new Error(`Validation test of type: "${ctx.type}" returned a Promise during a synchronous validate. ` + `This test will finish after the validate call has returned`);
|
|
722
|
+
}
|
|
723
|
+
return Promise.resolve(result).then(handleResult, handleError);
|
|
657
724
|
}
|
|
658
725
|
} catch (err) {
|
|
659
726
|
handleError(err);
|
|
@@ -665,6 +732,18 @@ function createValidation(config) {
|
|
|
665
732
|
return validate;
|
|
666
733
|
}
|
|
667
734
|
|
|
735
|
+
// Warning: mutates the input
|
|
736
|
+
function resolveParams(params, options) {
|
|
737
|
+
if (!params) return params;
|
|
738
|
+
for (const key of Object.keys(params)) {
|
|
739
|
+
params[key] = resolveMaybeRef(params[key], options);
|
|
740
|
+
}
|
|
741
|
+
return params;
|
|
742
|
+
}
|
|
743
|
+
function resolveMaybeRef(item, options) {
|
|
744
|
+
return Reference.isRef(item) ? item.getValue(options.value, options.parent, options.context) : item;
|
|
745
|
+
}
|
|
746
|
+
|
|
668
747
|
function getIn(schema, path, value, context = value) {
|
|
669
748
|
let parent, lastPart, lastPartDebug;
|
|
670
749
|
|
|
@@ -778,6 +857,89 @@ function clone(src, seen = new Map()) {
|
|
|
778
857
|
return copy;
|
|
779
858
|
}
|
|
780
859
|
|
|
860
|
+
/**
|
|
861
|
+
* Copied from @standard-schema/spec to avoid having a dependency on it.
|
|
862
|
+
* https://github.com/standard-schema/standard-schema/blob/main/packages/spec/src/index.ts
|
|
863
|
+
*/
|
|
864
|
+
|
|
865
|
+
function createStandardPath(path) {
|
|
866
|
+
if (!(path != null && path.length)) {
|
|
867
|
+
return undefined;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// Array to store the final path segments
|
|
871
|
+
const segments = [];
|
|
872
|
+
// Buffer for building the current segment
|
|
873
|
+
let currentSegment = '';
|
|
874
|
+
// Track if we're inside square brackets (array/property access)
|
|
875
|
+
let inBrackets = false;
|
|
876
|
+
// Track if we're inside quotes (for property names with special chars)
|
|
877
|
+
let inQuotes = false;
|
|
878
|
+
for (let i = 0; i < path.length; i++) {
|
|
879
|
+
const char = path[i];
|
|
880
|
+
if (char === '[' && !inQuotes) {
|
|
881
|
+
// When entering brackets, push any accumulated segment after splitting on dots
|
|
882
|
+
if (currentSegment) {
|
|
883
|
+
segments.push(...currentSegment.split('.').filter(Boolean));
|
|
884
|
+
currentSegment = '';
|
|
885
|
+
}
|
|
886
|
+
inBrackets = true;
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
if (char === ']' && !inQuotes) {
|
|
890
|
+
if (currentSegment) {
|
|
891
|
+
// Handle numeric indices (e.g. arr[0])
|
|
892
|
+
if (/^\d+$/.test(currentSegment)) {
|
|
893
|
+
segments.push(currentSegment);
|
|
894
|
+
} else {
|
|
895
|
+
// Handle quoted property names (e.g. obj["foo.bar"])
|
|
896
|
+
segments.push(currentSegment.replace(/^"|"$/g, ''));
|
|
897
|
+
}
|
|
898
|
+
currentSegment = '';
|
|
899
|
+
}
|
|
900
|
+
inBrackets = false;
|
|
901
|
+
continue;
|
|
902
|
+
}
|
|
903
|
+
if (char === '"') {
|
|
904
|
+
// Toggle quote state for handling quoted property names
|
|
905
|
+
inQuotes = !inQuotes;
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
908
|
+
if (char === '.' && !inBrackets && !inQuotes) {
|
|
909
|
+
// On dots outside brackets/quotes, push current segment
|
|
910
|
+
if (currentSegment) {
|
|
911
|
+
segments.push(currentSegment);
|
|
912
|
+
currentSegment = '';
|
|
913
|
+
}
|
|
914
|
+
continue;
|
|
915
|
+
}
|
|
916
|
+
currentSegment += char;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// Push any remaining segment after splitting on dots
|
|
920
|
+
if (currentSegment) {
|
|
921
|
+
segments.push(...currentSegment.split('.').filter(Boolean));
|
|
922
|
+
}
|
|
923
|
+
return segments;
|
|
924
|
+
}
|
|
925
|
+
function createStandardIssues(error, parentPath) {
|
|
926
|
+
const path = parentPath ? `${parentPath}.${error.path}` : error.path;
|
|
927
|
+
return error.errors.map(err => ({
|
|
928
|
+
message: err,
|
|
929
|
+
path: createStandardPath(path)
|
|
930
|
+
}));
|
|
931
|
+
}
|
|
932
|
+
function issuesFromValidationError(error, parentPath) {
|
|
933
|
+
var _error$inner;
|
|
934
|
+
if (!((_error$inner = error.inner) != null && _error$inner.length) && error.errors.length) {
|
|
935
|
+
return createStandardIssues(error, parentPath);
|
|
936
|
+
}
|
|
937
|
+
const path = parentPath ? `${parentPath}.${error.path}` : error.path;
|
|
938
|
+
return error.inner.flatMap(err => issuesFromValidationError(err, path));
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
// If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
|
|
942
|
+
// loose Record definition allowing free form usage.
|
|
781
943
|
class Schema {
|
|
782
944
|
constructor(options) {
|
|
783
945
|
this.type = void 0;
|
|
@@ -804,6 +966,7 @@ class Schema {
|
|
|
804
966
|
strict: false,
|
|
805
967
|
abortEarly: true,
|
|
806
968
|
recursive: true,
|
|
969
|
+
disableStackTrace: false,
|
|
807
970
|
nullable: false,
|
|
808
971
|
optional: true,
|
|
809
972
|
coerce: true
|
|
@@ -909,12 +1072,13 @@ class Schema {
|
|
|
909
1072
|
return schema;
|
|
910
1073
|
}
|
|
911
1074
|
resolveOptions(options) {
|
|
912
|
-
var _options$strict, _options$abortEarly, _options$recursive;
|
|
1075
|
+
var _options$strict, _options$abortEarly, _options$recursive, _options$disableStack;
|
|
913
1076
|
return Object.assign({}, options, {
|
|
914
1077
|
from: options.from || [],
|
|
915
1078
|
strict: (_options$strict = options.strict) != null ? _options$strict : this.spec.strict,
|
|
916
1079
|
abortEarly: (_options$abortEarly = options.abortEarly) != null ? _options$abortEarly : this.spec.abortEarly,
|
|
917
|
-
recursive: (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive
|
|
1080
|
+
recursive: (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive,
|
|
1081
|
+
disableStackTrace: (_options$disableStack = options.disableStackTrace) != null ? _options$disableStack : this.spec.disableStackTrace
|
|
918
1082
|
});
|
|
919
1083
|
}
|
|
920
1084
|
|
|
@@ -923,9 +1087,12 @@ class Schema {
|
|
|
923
1087
|
*/
|
|
924
1088
|
|
|
925
1089
|
cast(value, options = {}) {
|
|
926
|
-
let resolvedSchema = this.resolve(Object.assign({
|
|
1090
|
+
let resolvedSchema = this.resolve(Object.assign({}, options, {
|
|
927
1091
|
value
|
|
928
|
-
|
|
1092
|
+
// parent: options.parent,
|
|
1093
|
+
// context: options.context,
|
|
1094
|
+
}));
|
|
1095
|
+
|
|
929
1096
|
let allowOptionality = options.assert === 'ignore-optionality';
|
|
930
1097
|
let result = resolvedSchema._cast(value, options);
|
|
931
1098
|
if (options.assert !== false && !resolvedSchema.isType(result)) {
|
|
@@ -939,7 +1106,7 @@ class Schema {
|
|
|
939
1106
|
return result;
|
|
940
1107
|
}
|
|
941
1108
|
_cast(rawValue, options) {
|
|
942
|
-
let value = rawValue === undefined ? rawValue : this.transforms.reduce((prevValue, fn) => fn.call(this, prevValue, rawValue, this), rawValue);
|
|
1109
|
+
let value = rawValue === undefined ? rawValue : this.transforms.reduce((prevValue, fn) => fn.call(this, prevValue, rawValue, this, options), rawValue);
|
|
943
1110
|
if (value === undefined) {
|
|
944
1111
|
value = this.getDefault(options);
|
|
945
1112
|
}
|
|
@@ -1019,7 +1186,7 @@ class Schema {
|
|
|
1019
1186
|
const test = tests[i];
|
|
1020
1187
|
test(args, panicOnce, function finishTestRun(err) {
|
|
1021
1188
|
if (err) {
|
|
1022
|
-
nestedErrors
|
|
1189
|
+
Array.isArray(err) ? nestedErrors.push(...err) : nestedErrors.push(err);
|
|
1023
1190
|
}
|
|
1024
1191
|
if (--count <= 0) {
|
|
1025
1192
|
nextOnce(nestedErrors);
|
|
@@ -1054,33 +1221,37 @@ class Schema {
|
|
|
1054
1221
|
key: undefined,
|
|
1055
1222
|
// index: undefined,
|
|
1056
1223
|
[isIndex ? 'index' : 'key']: k,
|
|
1057
|
-
path: isIndex || k.includes('.') ? `${parentPath || ''}[${
|
|
1224
|
+
path: isIndex || k.includes('.') ? `${parentPath || ''}[${isIndex ? k : `"${k}"`}]` : (parentPath ? `${parentPath}.` : '') + key
|
|
1058
1225
|
});
|
|
1059
1226
|
return (_, panic, next) => this.resolve(testOptions)._validate(value, testOptions, panic, next);
|
|
1060
1227
|
}
|
|
1061
1228
|
validate(value, options) {
|
|
1229
|
+
var _options$disableStack2;
|
|
1062
1230
|
let schema = this.resolve(Object.assign({}, options, {
|
|
1063
1231
|
value
|
|
1064
1232
|
}));
|
|
1233
|
+
let disableStackTrace = (_options$disableStack2 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack2 : schema.spec.disableStackTrace;
|
|
1065
1234
|
return new Promise((resolve, reject) => schema._validate(value, options, (error, parsed) => {
|
|
1066
1235
|
if (ValidationError.isError(error)) error.value = parsed;
|
|
1067
1236
|
reject(error);
|
|
1068
1237
|
}, (errors, validated) => {
|
|
1069
|
-
if (errors.length) reject(new ValidationError(errors, validated));else resolve(validated);
|
|
1238
|
+
if (errors.length) reject(new ValidationError(errors, validated, undefined, undefined, disableStackTrace));else resolve(validated);
|
|
1070
1239
|
}));
|
|
1071
1240
|
}
|
|
1072
1241
|
validateSync(value, options) {
|
|
1242
|
+
var _options$disableStack3;
|
|
1073
1243
|
let schema = this.resolve(Object.assign({}, options, {
|
|
1074
1244
|
value
|
|
1075
1245
|
}));
|
|
1076
1246
|
let result;
|
|
1247
|
+
let disableStackTrace = (_options$disableStack3 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack3 : schema.spec.disableStackTrace;
|
|
1077
1248
|
schema._validate(value, Object.assign({}, options, {
|
|
1078
1249
|
sync: true
|
|
1079
1250
|
}), (error, parsed) => {
|
|
1080
1251
|
if (ValidationError.isError(error)) error.value = parsed;
|
|
1081
1252
|
throw error;
|
|
1082
1253
|
}, (errors, validated) => {
|
|
1083
|
-
if (errors.length) throw new ValidationError(errors, value);
|
|
1254
|
+
if (errors.length) throw new ValidationError(errors, value, undefined, undefined, disableStackTrace);
|
|
1084
1255
|
result = validated;
|
|
1085
1256
|
});
|
|
1086
1257
|
return result;
|
|
@@ -1337,13 +1508,41 @@ class Schema {
|
|
|
1337
1508
|
type: next.type,
|
|
1338
1509
|
oneOf: next._whitelist.describe(),
|
|
1339
1510
|
notOneOf: next._blacklist.describe(),
|
|
1340
|
-
tests: next.tests.map(fn =>
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1511
|
+
tests: next.tests.filter((n, idx, list) => list.findIndex(c => c.OPTIONS.name === n.OPTIONS.name) === idx).map(fn => {
|
|
1512
|
+
const params = fn.OPTIONS.params && options ? resolveParams(Object.assign({}, fn.OPTIONS.params), options) : fn.OPTIONS.params;
|
|
1513
|
+
return {
|
|
1514
|
+
name: fn.OPTIONS.name,
|
|
1515
|
+
params
|
|
1516
|
+
};
|
|
1517
|
+
})
|
|
1344
1518
|
};
|
|
1345
1519
|
return description;
|
|
1346
1520
|
}
|
|
1521
|
+
get ['~standard']() {
|
|
1522
|
+
const schema = this;
|
|
1523
|
+
const standard = {
|
|
1524
|
+
version: 1,
|
|
1525
|
+
vendor: 'yup',
|
|
1526
|
+
async validate(value) {
|
|
1527
|
+
try {
|
|
1528
|
+
const result = await schema.validate(value, {
|
|
1529
|
+
abortEarly: false
|
|
1530
|
+
});
|
|
1531
|
+
return {
|
|
1532
|
+
value: result
|
|
1533
|
+
};
|
|
1534
|
+
} catch (err) {
|
|
1535
|
+
if (err instanceof ValidationError) {
|
|
1536
|
+
return {
|
|
1537
|
+
issues: issuesFromValidationError(err)
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1540
|
+
throw err;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
return standard;
|
|
1545
|
+
}
|
|
1347
1546
|
}
|
|
1348
1547
|
// @ts-expect-error
|
|
1349
1548
|
Schema.prototype.__isYupSchema__ = true;
|
|
@@ -1361,50 +1560,64 @@ for (const method of ['validate', 'validateSync']) Schema.prototype[`${method}At
|
|
|
1361
1560
|
for (const alias of ['equals', 'is']) Schema.prototype[alias] = Schema.prototype.oneOf;
|
|
1362
1561
|
for (const alias of ['not', 'nope']) Schema.prototype[alias] = Schema.prototype.notOneOf;
|
|
1363
1562
|
|
|
1364
|
-
//
|
|
1365
|
-
// Number Interfaces
|
|
1366
|
-
//
|
|
1367
|
-
|
|
1368
|
-
/* eslint-disable */
|
|
1369
1563
|
/**
|
|
1370
|
-
*
|
|
1564
|
+
* This file is a modified version of the file from the following repository:
|
|
1371
1565
|
* Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
|
|
1372
1566
|
* NON-CONFORMANT EDITION.
|
|
1373
1567
|
* © 2011 Colin Snover <http://zetafleet.com>
|
|
1374
1568
|
* Released under MIT license.
|
|
1375
1569
|
*/
|
|
1376
1570
|
|
|
1377
|
-
//
|
|
1378
|
-
|
|
1571
|
+
// prettier-ignore
|
|
1572
|
+
// 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
|
|
1573
|
+
const isoReg = /^(\d{4}|[+-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,.](\d{1,}))?)?(?:(Z)|([+-])(\d{2})(?::?(\d{2}))?)?)?$/;
|
|
1379
1574
|
function parseIsoDate(date) {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
timestamp,
|
|
1383
|
-
struct;
|
|
1384
|
-
if (struct = isoReg.exec(date)) {
|
|
1385
|
-
// avoid NaN timestamps caused by “undefined” values being passed to Date.UTC
|
|
1386
|
-
for (var i = 0, k; k = numericKeys[i]; ++i) struct[k] = +struct[k] || 0;
|
|
1387
|
-
|
|
1388
|
-
// allow undefined days and months
|
|
1389
|
-
struct[2] = (+struct[2] || 1) - 1;
|
|
1390
|
-
struct[3] = +struct[3] || 1;
|
|
1575
|
+
const struct = parseDateStruct(date);
|
|
1576
|
+
if (!struct) return Date.parse ? Date.parse(date) : Number.NaN;
|
|
1391
1577
|
|
|
1392
|
-
|
|
1393
|
-
|
|
1578
|
+
// timestamps without timezone identifiers should be considered local time
|
|
1579
|
+
if (struct.z === undefined && struct.plusMinus === undefined) {
|
|
1580
|
+
return new Date(struct.year, struct.month, struct.day, struct.hour, struct.minute, struct.second, struct.millisecond).valueOf();
|
|
1581
|
+
}
|
|
1582
|
+
let totalMinutesOffset = 0;
|
|
1583
|
+
if (struct.z !== 'Z' && struct.plusMinus !== undefined) {
|
|
1584
|
+
totalMinutesOffset = struct.hourOffset * 60 + struct.minuteOffset;
|
|
1585
|
+
if (struct.plusMinus === '+') totalMinutesOffset = 0 - totalMinutesOffset;
|
|
1586
|
+
}
|
|
1587
|
+
return Date.UTC(struct.year, struct.month, struct.day, struct.hour, struct.minute + totalMinutesOffset, struct.second, struct.millisecond);
|
|
1588
|
+
}
|
|
1589
|
+
function parseDateStruct(date) {
|
|
1590
|
+
var _regexResult$7$length, _regexResult$;
|
|
1591
|
+
const regexResult = isoReg.exec(date);
|
|
1592
|
+
if (!regexResult) return null;
|
|
1394
1593
|
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1594
|
+
// use of toNumber() avoids NaN timestamps caused by “undefined”
|
|
1595
|
+
// values being passed to Date constructor
|
|
1596
|
+
return {
|
|
1597
|
+
year: toNumber(regexResult[1]),
|
|
1598
|
+
month: toNumber(regexResult[2], 1) - 1,
|
|
1599
|
+
day: toNumber(regexResult[3], 1),
|
|
1600
|
+
hour: toNumber(regexResult[4]),
|
|
1601
|
+
minute: toNumber(regexResult[5]),
|
|
1602
|
+
second: toNumber(regexResult[6]),
|
|
1603
|
+
millisecond: regexResult[7] ?
|
|
1604
|
+
// allow arbitrary sub-second precision beyond milliseconds
|
|
1605
|
+
toNumber(regexResult[7].substring(0, 3)) : 0,
|
|
1606
|
+
precision: (_regexResult$7$length = (_regexResult$ = regexResult[7]) == null ? void 0 : _regexResult$.length) != null ? _regexResult$7$length : undefined,
|
|
1607
|
+
z: regexResult[8] || undefined,
|
|
1608
|
+
plusMinus: regexResult[9] || undefined,
|
|
1609
|
+
hourOffset: toNumber(regexResult[10]),
|
|
1610
|
+
minuteOffset: toNumber(regexResult[11])
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
function toNumber(str, defaultValue = 0) {
|
|
1614
|
+
return Number(str) || defaultValue;
|
|
1405
1615
|
}
|
|
1406
1616
|
|
|
1407
|
-
//
|
|
1617
|
+
//
|
|
1618
|
+
// Number Interfaces
|
|
1619
|
+
//
|
|
1620
|
+
|
|
1408
1621
|
let invalidDate = new Date('');
|
|
1409
1622
|
let isDate = obj => Object.prototype.toString.call(obj) === '[object Date]';
|
|
1410
1623
|
class DateSchema extends Schema {
|
|
@@ -1416,10 +1629,10 @@ class DateSchema extends Schema {
|
|
|
1416
1629
|
}
|
|
1417
1630
|
});
|
|
1418
1631
|
this.withMutation(() => {
|
|
1419
|
-
this.transform((value, _raw
|
|
1632
|
+
this.transform((value, _raw) => {
|
|
1420
1633
|
// null -> InvalidDate isn't useful; treat all nulls as null and let it fail on
|
|
1421
1634
|
// nullability check vs TypeErrors
|
|
1422
|
-
if (!
|
|
1635
|
+
if (!this.spec.coerce || this.isType(value) || value === null) return value;
|
|
1423
1636
|
value = parseIsoDate(value);
|
|
1424
1637
|
|
|
1425
1638
|
// 0 is a valid timestamp equivalent to 1970-01-01T00:00:00Z(unix epoch) or before.
|
|
@@ -1470,7 +1683,6 @@ class DateSchema extends Schema {
|
|
|
1470
1683
|
}
|
|
1471
1684
|
}
|
|
1472
1685
|
DateSchema.INVALID_DATE = invalidDate;
|
|
1473
|
-
DateSchema.prototype;
|
|
1474
1686
|
|
|
1475
1687
|
// @ts-expect-error
|
|
1476
1688
|
function sortFields(fields, excludedEdges = []) {
|
|
@@ -1507,7 +1719,7 @@ function sortByKeyOrder(keys) {
|
|
|
1507
1719
|
};
|
|
1508
1720
|
}
|
|
1509
1721
|
|
|
1510
|
-
const parseJson = (value, _,
|
|
1722
|
+
const parseJson = (value, _, schema) => {
|
|
1511
1723
|
if (typeof value !== 'string') {
|
|
1512
1724
|
return value;
|
|
1513
1725
|
}
|
|
@@ -1517,7 +1729,7 @@ const parseJson = (value, _, ctx) => {
|
|
|
1517
1729
|
} catch (err) {
|
|
1518
1730
|
/* */
|
|
1519
1731
|
}
|
|
1520
|
-
return
|
|
1732
|
+
return schema.isType(parsed) ? parsed : value;
|
|
1521
1733
|
};
|
|
1522
1734
|
|
|
1523
1735
|
// @ts-ignore
|
|
@@ -1597,9 +1809,9 @@ class ObjectSchema extends Schema {
|
|
|
1597
1809
|
for (const prop of props) {
|
|
1598
1810
|
let field = fields[prop];
|
|
1599
1811
|
let exists = (prop in value);
|
|
1812
|
+
let inputValue = value[prop];
|
|
1600
1813
|
if (field) {
|
|
1601
1814
|
let fieldValue;
|
|
1602
|
-
let inputValue = value[prop];
|
|
1603
1815
|
|
|
1604
1816
|
// safe to mutate since this is fired in sequence
|
|
1605
1817
|
innerOptions.path = (options.path ? `${options.path}.` : '') + prop;
|
|
@@ -1614,16 +1826,14 @@ class ObjectSchema extends Schema {
|
|
|
1614
1826
|
isChanged = isChanged || prop in value;
|
|
1615
1827
|
continue;
|
|
1616
1828
|
}
|
|
1617
|
-
fieldValue = !options.__validating || !strict ?
|
|
1618
|
-
// TODO: use _cast, this is double resolving
|
|
1619
|
-
field.cast(value[prop], innerOptions) : value[prop];
|
|
1829
|
+
fieldValue = !options.__validating || !strict ? field.cast(inputValue, innerOptions) : inputValue;
|
|
1620
1830
|
if (fieldValue !== undefined) {
|
|
1621
1831
|
intermediateValue[prop] = fieldValue;
|
|
1622
1832
|
}
|
|
1623
1833
|
} else if (exists && !strip) {
|
|
1624
|
-
intermediateValue[prop] =
|
|
1834
|
+
intermediateValue[prop] = inputValue;
|
|
1625
1835
|
}
|
|
1626
|
-
if (exists !== prop in intermediateValue || intermediateValue[prop] !==
|
|
1836
|
+
if (exists !== prop in intermediateValue || intermediateValue[prop] !== inputValue) {
|
|
1627
1837
|
isChanged = true;
|
|
1628
1838
|
}
|
|
1629
1839
|
}
|
|
@@ -1753,14 +1963,15 @@ class ObjectSchema extends Schema {
|
|
|
1753
1963
|
for (const key of keys) {
|
|
1754
1964
|
if (this.fields[key]) picked[key] = this.fields[key];
|
|
1755
1965
|
}
|
|
1756
|
-
return this.setFields(picked);
|
|
1966
|
+
return this.setFields(picked, this._excludedEdges.filter(([a, b]) => keys.includes(a) && keys.includes(b)));
|
|
1757
1967
|
}
|
|
1758
1968
|
omit(keys) {
|
|
1759
|
-
const
|
|
1760
|
-
for (const key of keys) {
|
|
1761
|
-
|
|
1969
|
+
const remaining = [];
|
|
1970
|
+
for (const key of Object.keys(this.fields)) {
|
|
1971
|
+
if (keys.includes(key)) continue;
|
|
1972
|
+
remaining.push(key);
|
|
1762
1973
|
}
|
|
1763
|
-
return this.
|
|
1974
|
+
return this.pick(remaining);
|
|
1764
1975
|
}
|
|
1765
1976
|
from(from, to, alias) {
|
|
1766
1977
|
let fromGetter = propertyExpr.getter(from, true);
|
|
@@ -1780,6 +1991,31 @@ class ObjectSchema extends Schema {
|
|
|
1780
1991
|
json() {
|
|
1781
1992
|
return this.transform(parseJson);
|
|
1782
1993
|
}
|
|
1994
|
+
|
|
1995
|
+
/**
|
|
1996
|
+
* Similar to `noUnknown` but only validates that an object is the right shape without stripping the unknown keys
|
|
1997
|
+
*/
|
|
1998
|
+
exact(message) {
|
|
1999
|
+
return this.test({
|
|
2000
|
+
name: 'exact',
|
|
2001
|
+
exclusive: true,
|
|
2002
|
+
message: message || object.exact,
|
|
2003
|
+
test(value) {
|
|
2004
|
+
if (value == null) return true;
|
|
2005
|
+
const unknownKeys = unknown(this.schema, value);
|
|
2006
|
+
return unknownKeys.length === 0 || this.createError({
|
|
2007
|
+
params: {
|
|
2008
|
+
properties: unknownKeys.join(', ')
|
|
2009
|
+
}
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
});
|
|
2013
|
+
}
|
|
2014
|
+
stripUnknown() {
|
|
2015
|
+
return this.clone({
|
|
2016
|
+
noUnknown: true
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
1783
2019
|
noUnknown(noAllow = true, message = object.noUnknown) {
|
|
1784
2020
|
if (typeof noAllow !== 'boolean') {
|
|
1785
2021
|
message = noAllow;
|
|
@@ -1823,9 +2059,10 @@ class ObjectSchema extends Schema {
|
|
|
1823
2059
|
return this.transformKeys(key => tinyCase.snakeCase(key).toUpperCase());
|
|
1824
2060
|
}
|
|
1825
2061
|
describe(options) {
|
|
1826
|
-
|
|
2062
|
+
const next = (options ? this.resolve(options) : this).clone();
|
|
2063
|
+
const base = super.describe(options);
|
|
1827
2064
|
base.fields = {};
|
|
1828
|
-
for (const [key, value] of Object.entries(
|
|
2065
|
+
for (const [key, value] of Object.entries(next.fields)) {
|
|
1829
2066
|
var _innerOptions2;
|
|
1830
2067
|
let innerOptions = options;
|
|
1831
2068
|
if ((_innerOptions2 = innerOptions) != null && _innerOptions2.value) {
|