@me1a/ui 1.2.1 → 1.2.2
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/{hook-forms/index → example}/hook-forms/index.d.ts +2 -0
- package/dist/example/index.cjs.js.map +1 -0
- package/dist/example/index.es.js.map +1 -0
- package/dist/{index → hook-forms}/hook-forms/index.d.ts +2 -0
- package/dist/hook-forms/{index/index.cjs.js → index.cjs.js} +2780 -21
- package/dist/hook-forms/index.cjs.js.map +1 -0
- package/dist/hook-forms/{index/index.es.js → index.es.js} +2779 -22
- package/dist/hook-forms/index.es.js.map +1 -0
- package/dist/{index/index.cjs.js → index.cjs.js} +2780 -21
- package/dist/index.cjs.js.map +1 -0
- package/dist/{index/index.es.js → index.es.js} +2779 -22
- package/dist/index.es.js.map +1 -0
- package/package.json +21 -2
- package/dist/example/index/hook-forms/index.d.ts +0 -9
- package/dist/example/index/index.cjs.js.map +0 -1
- package/dist/example/index/index.es.js.map +0 -1
- package/dist/hook-forms/index/index.cjs.js.map +0 -1
- package/dist/hook-forms/index/index.es.js.map +0 -1
- package/dist/index/example/index.d.ts +0 -1
- package/dist/index/index.cjs.js.map +0 -1
- package/dist/index/index.es.js.map +0 -1
- /package/dist/example/{index/example → example}/index.d.ts +0 -0
- /package/dist/example/{index/example → example}/simple.d.ts +0 -0
- /package/dist/example/{index/hook-forms → hook-forms}/form-provider.d.ts +0 -0
- /package/dist/example/{index/hook-forms → hook-forms}/rhf-autocomplete.d.ts +0 -0
- /package/dist/example/{index/hook-forms → hook-forms}/rhf-checkbox.d.ts +0 -0
- /package/dist/example/{index/hook-forms → hook-forms}/rhf-radio-group.d.ts +0 -0
- /package/dist/example/{index/hook-forms → hook-forms}/rhf-select.d.ts +0 -0
- /package/dist/example/{index/hook-forms → hook-forms}/rhf-slider.d.ts +0 -0
- /package/dist/example/{index/hook-forms → hook-forms}/rhf-switch.d.ts +0 -0
- /package/dist/example/{index/hook-forms → hook-forms}/rhf-text-field.d.ts +0 -0
- /package/dist/example/{index/index.cjs.js → index.cjs.js} +0 -0
- /package/dist/example/{index/index.d.ts → index.d.ts} +0 -0
- /package/dist/example/{index/index.es.js → index.es.js} +0 -0
- /package/dist/{hook-forms/index/example → example}/simple.d.ts +0 -0
- /package/dist/hook-forms/{index/example → example}/index.d.ts +0 -0
- /package/dist/{index → hook-forms}/example/simple.d.ts +0 -0
- /package/dist/hook-forms/{index/hook-forms/form-provider.d.ts → form-provider.d.ts} +0 -0
- /package/dist/{index → hook-forms}/hook-forms/form-provider.d.ts +0 -0
- /package/dist/hook-forms/{index/hook-forms → hook-forms}/rhf-autocomplete.d.ts +0 -0
- /package/dist/hook-forms/{index/hook-forms → hook-forms}/rhf-checkbox.d.ts +0 -0
- /package/dist/hook-forms/{index/hook-forms → hook-forms}/rhf-radio-group.d.ts +0 -0
- /package/dist/hook-forms/{index/hook-forms → hook-forms}/rhf-select.d.ts +0 -0
- /package/dist/hook-forms/{index/hook-forms → hook-forms}/rhf-slider.d.ts +0 -0
- /package/dist/hook-forms/{index/hook-forms → hook-forms}/rhf-switch.d.ts +0 -0
- /package/dist/hook-forms/{index/hook-forms → hook-forms}/rhf-text-field.d.ts +0 -0
- /package/dist/hook-forms/{index/index.d.ts → index.d.ts} +0 -0
- /package/dist/{index/hook-forms → hook-forms}/rhf-autocomplete.d.ts +0 -0
- /package/dist/{index/hook-forms → hook-forms}/rhf-checkbox.d.ts +0 -0
- /package/dist/{index/hook-forms → hook-forms}/rhf-radio-group.d.ts +0 -0
- /package/dist/{index/hook-forms → hook-forms}/rhf-select.d.ts +0 -0
- /package/dist/{index/hook-forms → hook-forms}/rhf-slider.d.ts +0 -0
- /package/dist/{index/hook-forms → hook-forms}/rhf-switch.d.ts +0 -0
- /package/dist/{index/hook-forms → hook-forms}/rhf-text-field.d.ts +0 -0
- /package/dist/{index/index.d.ts → index.d.ts} +0 -0
|
@@ -30,12 +30,12 @@ var isDateObject = (value) => value instanceof Date;
|
|
|
30
30
|
var isNullOrUndefined = (value) => value == null;
|
|
31
31
|
|
|
32
32
|
const isObjectType = (value) => typeof value === 'object';
|
|
33
|
-
var isObject = (value) => !isNullOrUndefined(value) &&
|
|
33
|
+
var isObject$1 = (value) => !isNullOrUndefined(value) &&
|
|
34
34
|
!Array.isArray(value) &&
|
|
35
35
|
isObjectType(value) &&
|
|
36
36
|
!isDateObject(value);
|
|
37
37
|
|
|
38
|
-
var getEventValue = (event) => isObject(event) && event.target
|
|
38
|
+
var getEventValue = (event) => isObject$1(event) && event.target
|
|
39
39
|
? isCheckBoxInput(event.target)
|
|
40
40
|
? event.target.checked
|
|
41
41
|
: event.target.value
|
|
@@ -47,7 +47,7 @@ var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
|
|
|
47
47
|
|
|
48
48
|
var isPlainObject$1 = (tempObject) => {
|
|
49
49
|
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
|
50
|
-
return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
|
|
50
|
+
return (isObject$1(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
var isWeb = typeof window !== 'undefined' &&
|
|
@@ -64,7 +64,7 @@ function cloneObject(data) {
|
|
|
64
64
|
copy = new Set(data);
|
|
65
65
|
}
|
|
66
66
|
else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
|
|
67
|
-
(isArray || isObject(data))) {
|
|
67
|
+
(isArray || isObject$1(data))) {
|
|
68
68
|
copy = isArray ? [] : {};
|
|
69
69
|
if (!isArray && !isPlainObject$1(data)) {
|
|
70
70
|
copy = data;
|
|
@@ -88,7 +88,7 @@ var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
|
|
88
88
|
var isUndefined = (val) => val === undefined;
|
|
89
89
|
|
|
90
90
|
var get = (object, path, defaultValue) => {
|
|
91
|
-
if (!path || !isObject(object)) {
|
|
91
|
+
if (!path || !isObject$1(object)) {
|
|
92
92
|
return defaultValue;
|
|
93
93
|
}
|
|
94
94
|
const result = compact(path.split(/[,[\].]+?/)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], object);
|
|
@@ -116,7 +116,7 @@ var set = (object, path, value) => {
|
|
|
116
116
|
if (index !== lastIndex) {
|
|
117
117
|
const objValue = object[key];
|
|
118
118
|
newValue =
|
|
119
|
-
isObject(objValue) || Array.isArray(objValue)
|
|
119
|
+
isObject$1(objValue) || Array.isArray(objValue)
|
|
120
120
|
? objValue
|
|
121
121
|
: !isNaN(+tempPath[index + 1])
|
|
122
122
|
? []
|
|
@@ -239,7 +239,7 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
|
|
|
239
239
|
return result;
|
|
240
240
|
};
|
|
241
241
|
|
|
242
|
-
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
|
242
|
+
var isEmptyObject = (value) => isObject$1(value) && !Object.keys(value).length;
|
|
243
243
|
|
|
244
244
|
var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
|
|
245
245
|
updateFormState(formStateData);
|
|
@@ -744,7 +744,7 @@ const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
|
|
|
744
744
|
}
|
|
745
745
|
}
|
|
746
746
|
}
|
|
747
|
-
else if (isObject(currentField)) {
|
|
747
|
+
else if (isObject$1(currentField)) {
|
|
748
748
|
if (iterateFieldsByAction(currentField, action)) {
|
|
749
749
|
break;
|
|
750
750
|
}
|
|
@@ -830,7 +830,7 @@ function getValidateError(result, ref, type = 'validate') {
|
|
|
830
830
|
}
|
|
831
831
|
}
|
|
832
832
|
|
|
833
|
-
var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData)
|
|
833
|
+
var getValueAndMessage = (validationData) => isObject$1(validationData) && !isRegex(validationData)
|
|
834
834
|
? validationData
|
|
835
835
|
: {
|
|
836
836
|
value: validationData,
|
|
@@ -983,7 +983,7 @@ var validateField = async (field, formValues, validateAllFieldCriteria, shouldUs
|
|
|
983
983
|
}
|
|
984
984
|
}
|
|
985
985
|
}
|
|
986
|
-
else if (isObject(validate)) {
|
|
986
|
+
else if (isObject$1(validate)) {
|
|
987
987
|
let validationResult = {};
|
|
988
988
|
for (const key in validate) {
|
|
989
989
|
if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
|
|
@@ -1093,7 +1093,7 @@ function unset(object, path) {
|
|
|
1093
1093
|
delete childObject[key];
|
|
1094
1094
|
}
|
|
1095
1095
|
if (index !== 0 &&
|
|
1096
|
-
((isObject(childObject) && isEmptyObject(childObject)) ||
|
|
1096
|
+
((isObject$1(childObject) && isEmptyObject(childObject)) ||
|
|
1097
1097
|
(Array.isArray(childObject) && isEmptyArray(childObject)))) {
|
|
1098
1098
|
unset(object, paths.slice(0, -1));
|
|
1099
1099
|
}
|
|
@@ -1386,7 +1386,7 @@ function deepEqual(object1, object2) {
|
|
|
1386
1386
|
if (key !== 'ref') {
|
|
1387
1387
|
const val2 = object2[key];
|
|
1388
1388
|
if ((isDateObject(val1) && isDateObject(val2)) ||
|
|
1389
|
-
(isObject(val1) && isObject(val2)) ||
|
|
1389
|
+
(isObject$1(val1) && isObject$1(val2)) ||
|
|
1390
1390
|
(Array.isArray(val1) && Array.isArray(val2))
|
|
1391
1391
|
? !deepEqual(val1, val2)
|
|
1392
1392
|
: val1 !== val2) {
|
|
@@ -1414,10 +1414,10 @@ var objectHasFunction = (data) => {
|
|
|
1414
1414
|
|
|
1415
1415
|
function markFieldsDirty(data, fields = {}) {
|
|
1416
1416
|
const isParentNodeArray = Array.isArray(data);
|
|
1417
|
-
if (isObject(data) || isParentNodeArray) {
|
|
1417
|
+
if (isObject$1(data) || isParentNodeArray) {
|
|
1418
1418
|
for (const key in data) {
|
|
1419
1419
|
if (Array.isArray(data[key]) ||
|
|
1420
|
-
(isObject(data[key]) && !objectHasFunction(data[key]))) {
|
|
1420
|
+
(isObject$1(data[key]) && !objectHasFunction(data[key]))) {
|
|
1421
1421
|
fields[key] = Array.isArray(data[key]) ? [] : {};
|
|
1422
1422
|
markFieldsDirty(data[key], fields[key]);
|
|
1423
1423
|
}
|
|
@@ -1430,10 +1430,10 @@ function markFieldsDirty(data, fields = {}) {
|
|
|
1430
1430
|
}
|
|
1431
1431
|
function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues) {
|
|
1432
1432
|
const isParentNodeArray = Array.isArray(data);
|
|
1433
|
-
if (isObject(data) || isParentNodeArray) {
|
|
1433
|
+
if (isObject$1(data) || isParentNodeArray) {
|
|
1434
1434
|
for (const key in data) {
|
|
1435
1435
|
if (Array.isArray(data[key]) ||
|
|
1436
|
-
(isObject(data[key]) && !objectHasFunction(data[key]))) {
|
|
1436
|
+
(isObject$1(data[key]) && !objectHasFunction(data[key]))) {
|
|
1437
1437
|
if (isUndefined(formValues) ||
|
|
1438
1438
|
isPrimitive(dirtyFieldsFromValues[key])) {
|
|
1439
1439
|
dirtyFieldsFromValues[key] = Array.isArray(data[key])
|
|
@@ -1505,7 +1505,7 @@ var getRuleValue = (rule) => isUndefined(rule)
|
|
|
1505
1505
|
? rule
|
|
1506
1506
|
: isRegex(rule)
|
|
1507
1507
|
? rule.source
|
|
1508
|
-
: isObject(rule)
|
|
1508
|
+
: isObject$1(rule)
|
|
1509
1509
|
? isRegex(rule.value)
|
|
1510
1510
|
? rule.value.source
|
|
1511
1511
|
: rule.value
|
|
@@ -1515,7 +1515,7 @@ const ASYNC_FUNCTION = 'AsyncFunction';
|
|
|
1515
1515
|
var hasPromiseValidation = (fieldReference) => (!fieldReference || !fieldReference.validate) &&
|
|
1516
1516
|
!!((isFunction(fieldReference.validate) &&
|
|
1517
1517
|
fieldReference.validate.constructor.name === ASYNC_FUNCTION) ||
|
|
1518
|
-
(isObject(fieldReference.validate) &&
|
|
1518
|
+
(isObject$1(fieldReference.validate) &&
|
|
1519
1519
|
Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION)));
|
|
1520
1520
|
|
|
1521
1521
|
var hasValidation = (options) => options.mount &&
|
|
@@ -1600,7 +1600,7 @@ function createFormControl(props = {}) {
|
|
|
1600
1600
|
disabled: _options.disabled || false,
|
|
1601
1601
|
};
|
|
1602
1602
|
let _fields = {};
|
|
1603
|
-
let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
|
|
1603
|
+
let _defaultValues = isObject$1(_options.defaultValues) || isObject$1(_options.values)
|
|
1604
1604
|
? cloneObject(_options.defaultValues || _options.values) || {}
|
|
1605
1605
|
: {};
|
|
1606
1606
|
let _formValues = _options.shouldUnregister
|
|
@@ -1935,7 +1935,7 @@ function createFormControl(props = {}) {
|
|
|
1935
1935
|
const fieldName = `${name}.${fieldKey}`;
|
|
1936
1936
|
const field = get(_fields, fieldName);
|
|
1937
1937
|
(_names.array.has(name) ||
|
|
1938
|
-
isObject(fieldValue) ||
|
|
1938
|
+
isObject$1(fieldValue) ||
|
|
1939
1939
|
(field && !field._f)) &&
|
|
1940
1940
|
!isDateObject(fieldValue)
|
|
1941
1941
|
? setValues(fieldName, fieldValue, options)
|
|
@@ -5231,7 +5231,7 @@ function requirePropTypes () {
|
|
|
5231
5231
|
var propTypesExports = /*@__PURE__*/ requirePropTypes();
|
|
5232
5232
|
var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
|
|
5233
5233
|
|
|
5234
|
-
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
|
|
5234
|
+
function r$1(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r$1(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r$1(e))&&(n&&(n+=" "),n+=t);return n}
|
|
5235
5235
|
|
|
5236
5236
|
/* eslint no-restricted-syntax: 0, prefer-template: 0, guard-for-in: 0
|
|
5237
5237
|
---
|
|
@@ -27230,6 +27230,2763 @@ function FormProvider({
|
|
|
27230
27230
|
});
|
|
27231
27231
|
}
|
|
27232
27232
|
|
|
27233
|
+
const s=(e,s,o)=>{if(e&&"reportValidity"in e){const r=get(o,s);e.setCustomValidity(r&&r.message||""),e.reportValidity();}},o$1=(t,e)=>{for(const o in e.fields){const r=e.fields[o];r&&r.ref&&"reportValidity"in r.ref?s(r.ref,o,t):r.refs&&r.refs.forEach(e=>s(e,o,t));}},r=(s,r)=>{r.shouldUseNativeValidation&&o$1(s,r);const f={};for(const o in s){const n=get(r.fields,o),a=Object.assign(s[o]||{},{ref:n&&n.ref});if(i(r.names||Object.keys(s),o)){const s=Object.assign({},get(f,o));set(s,"root",a),set(f,o,s);}else set(f,o,a);}return f},i=(t,e)=>t.some(t=>t.startsWith(e+"."));
|
|
27234
|
+
|
|
27235
|
+
function o(o,n,a){return void 0===n&&(n={}),void 0===a&&(a={}),function(s,i,c){try{return Promise.resolve(function(t,r){try{var u=(n.context&&"development"===process.env.NODE_ENV&&console.warn("You should not used the yup options context. Please, use the 'useForm' context object instead"),Promise.resolve(o["sync"===a.mode?"validateSync":"validate"](s,Object.assign({abortEarly:!1},n,{context:i}))).then(function(t){return c.shouldUseNativeValidation&&o$1({},c),{values:a.raw?s:t,errors:{}}}));}catch(e){return r(e)}return u&&u.then?u.then(void 0,r):u}(0,function(e){if(!e.inner)throw e;return {values:{},errors:r((o=e,n=!c.shouldUseNativeValidation&&"all"===c.criteriaMode,(o.inner||[]).reduce(function(e,t){if(e[t.path]||(e[t.path]={message:t.message,type:t.type}),n){var o=e[t.path].types,a=o&&o[t.type];e[t.path]=appendErrors(t.path,n,e,t.type,a?[].concat(a,t.message):t.message);}return e},{})),c)};var o,n;}))}catch(e){return Promise.reject(e)}}}
|
|
27236
|
+
|
|
27237
|
+
/**
|
|
27238
|
+
* Based on Kendo UI Core expression code <https://github.com/telerik/kendo-ui-core#license-information>
|
|
27239
|
+
*/
|
|
27240
|
+
|
|
27241
|
+
var propertyExpr;
|
|
27242
|
+
var hasRequiredPropertyExpr;
|
|
27243
|
+
|
|
27244
|
+
function requirePropertyExpr () {
|
|
27245
|
+
if (hasRequiredPropertyExpr) return propertyExpr;
|
|
27246
|
+
hasRequiredPropertyExpr = 1;
|
|
27247
|
+
|
|
27248
|
+
function Cache(maxSize) {
|
|
27249
|
+
this._maxSize = maxSize;
|
|
27250
|
+
this.clear();
|
|
27251
|
+
}
|
|
27252
|
+
Cache.prototype.clear = function () {
|
|
27253
|
+
this._size = 0;
|
|
27254
|
+
this._values = Object.create(null);
|
|
27255
|
+
};
|
|
27256
|
+
Cache.prototype.get = function (key) {
|
|
27257
|
+
return this._values[key]
|
|
27258
|
+
};
|
|
27259
|
+
Cache.prototype.set = function (key, value) {
|
|
27260
|
+
this._size >= this._maxSize && this.clear();
|
|
27261
|
+
if (!(key in this._values)) this._size++;
|
|
27262
|
+
|
|
27263
|
+
return (this._values[key] = value)
|
|
27264
|
+
};
|
|
27265
|
+
|
|
27266
|
+
var SPLIT_REGEX = /[^.^\]^[]+|(?=\[\]|\.\.)/g,
|
|
27267
|
+
DIGIT_REGEX = /^\d+$/,
|
|
27268
|
+
LEAD_DIGIT_REGEX = /^\d/,
|
|
27269
|
+
SPEC_CHAR_REGEX = /[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g,
|
|
27270
|
+
CLEAN_QUOTES_REGEX = /^\s*(['"]?)(.*?)(\1)\s*$/,
|
|
27271
|
+
MAX_CACHE_SIZE = 512;
|
|
27272
|
+
|
|
27273
|
+
var pathCache = new Cache(MAX_CACHE_SIZE),
|
|
27274
|
+
setCache = new Cache(MAX_CACHE_SIZE),
|
|
27275
|
+
getCache = new Cache(MAX_CACHE_SIZE);
|
|
27276
|
+
|
|
27277
|
+
propertyExpr = {
|
|
27278
|
+
Cache: Cache,
|
|
27279
|
+
|
|
27280
|
+
split: split,
|
|
27281
|
+
|
|
27282
|
+
normalizePath: normalizePath,
|
|
27283
|
+
|
|
27284
|
+
setter: function (path) {
|
|
27285
|
+
var parts = normalizePath(path);
|
|
27286
|
+
|
|
27287
|
+
return (
|
|
27288
|
+
setCache.get(path) ||
|
|
27289
|
+
setCache.set(path, function setter(obj, value) {
|
|
27290
|
+
var index = 0;
|
|
27291
|
+
var len = parts.length;
|
|
27292
|
+
var data = obj;
|
|
27293
|
+
|
|
27294
|
+
while (index < len - 1) {
|
|
27295
|
+
var part = parts[index];
|
|
27296
|
+
if (
|
|
27297
|
+
part === '__proto__' ||
|
|
27298
|
+
part === 'constructor' ||
|
|
27299
|
+
part === 'prototype'
|
|
27300
|
+
) {
|
|
27301
|
+
return obj
|
|
27302
|
+
}
|
|
27303
|
+
|
|
27304
|
+
data = data[parts[index++]];
|
|
27305
|
+
}
|
|
27306
|
+
data[parts[index]] = value;
|
|
27307
|
+
})
|
|
27308
|
+
)
|
|
27309
|
+
},
|
|
27310
|
+
|
|
27311
|
+
getter: function (path, safe) {
|
|
27312
|
+
var parts = normalizePath(path);
|
|
27313
|
+
return (
|
|
27314
|
+
getCache.get(path) ||
|
|
27315
|
+
getCache.set(path, function getter(data) {
|
|
27316
|
+
var index = 0,
|
|
27317
|
+
len = parts.length;
|
|
27318
|
+
while (index < len) {
|
|
27319
|
+
if (data != null || !safe) data = data[parts[index++]];
|
|
27320
|
+
else return
|
|
27321
|
+
}
|
|
27322
|
+
return data
|
|
27323
|
+
})
|
|
27324
|
+
)
|
|
27325
|
+
},
|
|
27326
|
+
|
|
27327
|
+
join: function (segments) {
|
|
27328
|
+
return segments.reduce(function (path, part) {
|
|
27329
|
+
return (
|
|
27330
|
+
path +
|
|
27331
|
+
(isQuoted(part) || DIGIT_REGEX.test(part)
|
|
27332
|
+
? '[' + part + ']'
|
|
27333
|
+
: (path ? '.' : '') + part)
|
|
27334
|
+
)
|
|
27335
|
+
}, '')
|
|
27336
|
+
},
|
|
27337
|
+
|
|
27338
|
+
forEach: function (path, cb, thisArg) {
|
|
27339
|
+
forEach(Array.isArray(path) ? path : split(path), cb, thisArg);
|
|
27340
|
+
},
|
|
27341
|
+
};
|
|
27342
|
+
|
|
27343
|
+
function normalizePath(path) {
|
|
27344
|
+
return (
|
|
27345
|
+
pathCache.get(path) ||
|
|
27346
|
+
pathCache.set(
|
|
27347
|
+
path,
|
|
27348
|
+
split(path).map(function (part) {
|
|
27349
|
+
return part.replace(CLEAN_QUOTES_REGEX, '$2')
|
|
27350
|
+
})
|
|
27351
|
+
)
|
|
27352
|
+
)
|
|
27353
|
+
}
|
|
27354
|
+
|
|
27355
|
+
function split(path) {
|
|
27356
|
+
return path.match(SPLIT_REGEX) || ['']
|
|
27357
|
+
}
|
|
27358
|
+
|
|
27359
|
+
function forEach(parts, iter, thisArg) {
|
|
27360
|
+
var len = parts.length,
|
|
27361
|
+
part,
|
|
27362
|
+
idx,
|
|
27363
|
+
isArray,
|
|
27364
|
+
isBracket;
|
|
27365
|
+
|
|
27366
|
+
for (idx = 0; idx < len; idx++) {
|
|
27367
|
+
part = parts[idx];
|
|
27368
|
+
|
|
27369
|
+
if (part) {
|
|
27370
|
+
if (shouldBeQuoted(part)) {
|
|
27371
|
+
part = '"' + part + '"';
|
|
27372
|
+
}
|
|
27373
|
+
|
|
27374
|
+
isBracket = isQuoted(part);
|
|
27375
|
+
isArray = !isBracket && /^\d+$/.test(part);
|
|
27376
|
+
|
|
27377
|
+
iter.call(thisArg, part, isBracket, isArray, idx, parts);
|
|
27378
|
+
}
|
|
27379
|
+
}
|
|
27380
|
+
}
|
|
27381
|
+
|
|
27382
|
+
function isQuoted(str) {
|
|
27383
|
+
return (
|
|
27384
|
+
typeof str === 'string' && str && ["'", '"'].indexOf(str.charAt(0)) !== -1
|
|
27385
|
+
)
|
|
27386
|
+
}
|
|
27387
|
+
|
|
27388
|
+
function hasLeadingNumber(part) {
|
|
27389
|
+
return part.match(LEAD_DIGIT_REGEX) && !part.match(DIGIT_REGEX)
|
|
27390
|
+
}
|
|
27391
|
+
|
|
27392
|
+
function hasSpecialChars(part) {
|
|
27393
|
+
return SPEC_CHAR_REGEX.test(part)
|
|
27394
|
+
}
|
|
27395
|
+
|
|
27396
|
+
function shouldBeQuoted(part) {
|
|
27397
|
+
return !isQuoted(part) && (hasLeadingNumber(part) || hasSpecialChars(part))
|
|
27398
|
+
}
|
|
27399
|
+
return propertyExpr;
|
|
27400
|
+
}
|
|
27401
|
+
|
|
27402
|
+
var propertyExprExports = requirePropertyExpr();
|
|
27403
|
+
|
|
27404
|
+
var tinyCase;
|
|
27405
|
+
var hasRequiredTinyCase;
|
|
27406
|
+
|
|
27407
|
+
function requireTinyCase () {
|
|
27408
|
+
if (hasRequiredTinyCase) return tinyCase;
|
|
27409
|
+
hasRequiredTinyCase = 1;
|
|
27410
|
+
const reWords = /[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?:['’](?:d|ll|m|re|s|t|ve))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:D|LL|M|RE|S|T|VE))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:d|ll|m|re|s|t|ve))?|[A-Z\xc0-\xd6\xd8-\xde]+(?:['’](?:D|LL|M|RE|S|T|VE))?|\d*(?:1ST|2ND|3RD|(?![123])\dTH)(?=\b|[a-z_])|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|[A-Z_])|\d+|(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?)*/g;
|
|
27411
|
+
|
|
27412
|
+
const words = (str) => str.match(reWords) || [];
|
|
27413
|
+
|
|
27414
|
+
const upperFirst = (str) => str[0].toUpperCase() + str.slice(1);
|
|
27415
|
+
|
|
27416
|
+
const join = (str, d) => words(str).join(d).toLowerCase();
|
|
27417
|
+
|
|
27418
|
+
const camelCase = (str) =>
|
|
27419
|
+
words(str).reduce(
|
|
27420
|
+
(acc, next) =>
|
|
27421
|
+
`${acc}${
|
|
27422
|
+
!acc
|
|
27423
|
+
? next.toLowerCase()
|
|
27424
|
+
: next[0].toUpperCase() + next.slice(1).toLowerCase()
|
|
27425
|
+
}`,
|
|
27426
|
+
'',
|
|
27427
|
+
);
|
|
27428
|
+
|
|
27429
|
+
const pascalCase = (str) => upperFirst(camelCase(str));
|
|
27430
|
+
|
|
27431
|
+
const snakeCase = (str) => join(str, '_');
|
|
27432
|
+
|
|
27433
|
+
const kebabCase = (str) => join(str, '-');
|
|
27434
|
+
|
|
27435
|
+
const sentenceCase = (str) => upperFirst(join(str, ' '));
|
|
27436
|
+
|
|
27437
|
+
const titleCase = (str) => words(str).map(upperFirst).join(' ');
|
|
27438
|
+
|
|
27439
|
+
tinyCase = {
|
|
27440
|
+
words,
|
|
27441
|
+
upperFirst,
|
|
27442
|
+
camelCase,
|
|
27443
|
+
pascalCase,
|
|
27444
|
+
snakeCase,
|
|
27445
|
+
kebabCase,
|
|
27446
|
+
sentenceCase,
|
|
27447
|
+
titleCase,
|
|
27448
|
+
};
|
|
27449
|
+
return tinyCase;
|
|
27450
|
+
}
|
|
27451
|
+
|
|
27452
|
+
var tinyCaseExports = requireTinyCase();
|
|
27453
|
+
|
|
27454
|
+
var toposort$1 = {exports: {}};
|
|
27455
|
+
|
|
27456
|
+
var hasRequiredToposort;
|
|
27457
|
+
|
|
27458
|
+
function requireToposort () {
|
|
27459
|
+
if (hasRequiredToposort) return toposort$1.exports;
|
|
27460
|
+
hasRequiredToposort = 1;
|
|
27461
|
+
/**
|
|
27462
|
+
* Topological sorting function
|
|
27463
|
+
*
|
|
27464
|
+
* @param {Array} edges
|
|
27465
|
+
* @returns {Array}
|
|
27466
|
+
*/
|
|
27467
|
+
|
|
27468
|
+
toposort$1.exports = function(edges) {
|
|
27469
|
+
return toposort(uniqueNodes(edges), edges)
|
|
27470
|
+
};
|
|
27471
|
+
|
|
27472
|
+
toposort$1.exports.array = toposort;
|
|
27473
|
+
|
|
27474
|
+
function toposort(nodes, edges) {
|
|
27475
|
+
var cursor = nodes.length
|
|
27476
|
+
, sorted = new Array(cursor)
|
|
27477
|
+
, visited = {}
|
|
27478
|
+
, i = cursor
|
|
27479
|
+
// Better data structures make algorithm much faster.
|
|
27480
|
+
, outgoingEdges = makeOutgoingEdges(edges)
|
|
27481
|
+
, nodesHash = makeNodesHash(nodes);
|
|
27482
|
+
|
|
27483
|
+
// check for unknown nodes
|
|
27484
|
+
edges.forEach(function(edge) {
|
|
27485
|
+
if (!nodesHash.has(edge[0]) || !nodesHash.has(edge[1])) {
|
|
27486
|
+
throw new Error('Unknown node. There is an unknown node in the supplied edges.')
|
|
27487
|
+
}
|
|
27488
|
+
});
|
|
27489
|
+
|
|
27490
|
+
while (i--) {
|
|
27491
|
+
if (!visited[i]) visit(nodes[i], i, new Set());
|
|
27492
|
+
}
|
|
27493
|
+
|
|
27494
|
+
return sorted
|
|
27495
|
+
|
|
27496
|
+
function visit(node, i, predecessors) {
|
|
27497
|
+
if(predecessors.has(node)) {
|
|
27498
|
+
var nodeRep;
|
|
27499
|
+
try {
|
|
27500
|
+
nodeRep = ", node was:" + JSON.stringify(node);
|
|
27501
|
+
} catch(e) {
|
|
27502
|
+
nodeRep = "";
|
|
27503
|
+
}
|
|
27504
|
+
throw new Error('Cyclic dependency' + nodeRep)
|
|
27505
|
+
}
|
|
27506
|
+
|
|
27507
|
+
if (!nodesHash.has(node)) {
|
|
27508
|
+
throw new Error('Found unknown node. Make sure to provided all involved nodes. Unknown node: '+JSON.stringify(node))
|
|
27509
|
+
}
|
|
27510
|
+
|
|
27511
|
+
if (visited[i]) return;
|
|
27512
|
+
visited[i] = true;
|
|
27513
|
+
|
|
27514
|
+
var outgoing = outgoingEdges.get(node) || new Set();
|
|
27515
|
+
outgoing = Array.from(outgoing);
|
|
27516
|
+
|
|
27517
|
+
if (i = outgoing.length) {
|
|
27518
|
+
predecessors.add(node);
|
|
27519
|
+
do {
|
|
27520
|
+
var child = outgoing[--i];
|
|
27521
|
+
visit(child, nodesHash.get(child), predecessors);
|
|
27522
|
+
} while (i)
|
|
27523
|
+
predecessors.delete(node);
|
|
27524
|
+
}
|
|
27525
|
+
|
|
27526
|
+
sorted[--cursor] = node;
|
|
27527
|
+
}
|
|
27528
|
+
}
|
|
27529
|
+
|
|
27530
|
+
function uniqueNodes(arr){
|
|
27531
|
+
var res = new Set();
|
|
27532
|
+
for (var i = 0, len = arr.length; i < len; i++) {
|
|
27533
|
+
var edge = arr[i];
|
|
27534
|
+
res.add(edge[0]);
|
|
27535
|
+
res.add(edge[1]);
|
|
27536
|
+
}
|
|
27537
|
+
return Array.from(res)
|
|
27538
|
+
}
|
|
27539
|
+
|
|
27540
|
+
function makeOutgoingEdges(arr){
|
|
27541
|
+
var edges = new Map();
|
|
27542
|
+
for (var i = 0, len = arr.length; i < len; i++) {
|
|
27543
|
+
var edge = arr[i];
|
|
27544
|
+
if (!edges.has(edge[0])) edges.set(edge[0], new Set());
|
|
27545
|
+
if (!edges.has(edge[1])) edges.set(edge[1], new Set());
|
|
27546
|
+
edges.get(edge[0]).add(edge[1]);
|
|
27547
|
+
}
|
|
27548
|
+
return edges
|
|
27549
|
+
}
|
|
27550
|
+
|
|
27551
|
+
function makeNodesHash(arr){
|
|
27552
|
+
var res = new Map();
|
|
27553
|
+
for (var i = 0, len = arr.length; i < len; i++) {
|
|
27554
|
+
res.set(arr[i], i);
|
|
27555
|
+
}
|
|
27556
|
+
return res
|
|
27557
|
+
}
|
|
27558
|
+
return toposort$1.exports;
|
|
27559
|
+
}
|
|
27560
|
+
|
|
27561
|
+
var toposortExports = requireToposort();
|
|
27562
|
+
var toposort = /*@__PURE__*/getDefaultExportFromCjs(toposortExports);
|
|
27563
|
+
|
|
27564
|
+
const toString = Object.prototype.toString;
|
|
27565
|
+
const errorToString = Error.prototype.toString;
|
|
27566
|
+
const regExpToString = RegExp.prototype.toString;
|
|
27567
|
+
const symbolToString = typeof Symbol !== 'undefined' ? Symbol.prototype.toString : () => '';
|
|
27568
|
+
const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
|
|
27569
|
+
function printNumber(val) {
|
|
27570
|
+
if (val != +val) return 'NaN';
|
|
27571
|
+
const isNegativeZero = val === 0 && 1 / val < 0;
|
|
27572
|
+
return isNegativeZero ? '-0' : '' + val;
|
|
27573
|
+
}
|
|
27574
|
+
function printSimpleValue(val, quoteStrings = false) {
|
|
27575
|
+
if (val == null || val === true || val === false) return '' + val;
|
|
27576
|
+
const typeOf = typeof val;
|
|
27577
|
+
if (typeOf === 'number') return printNumber(val);
|
|
27578
|
+
if (typeOf === 'string') return quoteStrings ? `"${val}"` : val;
|
|
27579
|
+
if (typeOf === 'function') return '[Function ' + (val.name || 'anonymous') + ']';
|
|
27580
|
+
if (typeOf === 'symbol') return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
|
|
27581
|
+
const tag = toString.call(val).slice(8, -1);
|
|
27582
|
+
if (tag === 'Date') return isNaN(val.getTime()) ? '' + val : val.toISOString(val);
|
|
27583
|
+
if (tag === 'Error' || val instanceof Error) return '[' + errorToString.call(val) + ']';
|
|
27584
|
+
if (tag === 'RegExp') return regExpToString.call(val);
|
|
27585
|
+
return null;
|
|
27586
|
+
}
|
|
27587
|
+
function printValue(value, quoteStrings) {
|
|
27588
|
+
let result = printSimpleValue(value, quoteStrings);
|
|
27589
|
+
if (result !== null) return result;
|
|
27590
|
+
return JSON.stringify(value, function (key, value) {
|
|
27591
|
+
let result = printSimpleValue(this[key], quoteStrings);
|
|
27592
|
+
if (result !== null) return result;
|
|
27593
|
+
return value;
|
|
27594
|
+
}, 2);
|
|
27595
|
+
}
|
|
27596
|
+
|
|
27597
|
+
function toArray(value) {
|
|
27598
|
+
return value == null ? [] : [].concat(value);
|
|
27599
|
+
}
|
|
27600
|
+
|
|
27601
|
+
let _Symbol$toStringTag, _Symbol$hasInstance, _Symbol$toStringTag2;
|
|
27602
|
+
let strReg = /\$\{\s*(\w+)\s*\}/g;
|
|
27603
|
+
_Symbol$toStringTag = Symbol.toStringTag;
|
|
27604
|
+
class ValidationErrorNoStack {
|
|
27605
|
+
constructor(errorOrErrors, value, field, type) {
|
|
27606
|
+
this.name = void 0;
|
|
27607
|
+
this.message = void 0;
|
|
27608
|
+
this.value = void 0;
|
|
27609
|
+
this.path = void 0;
|
|
27610
|
+
this.type = void 0;
|
|
27611
|
+
this.params = void 0;
|
|
27612
|
+
this.errors = void 0;
|
|
27613
|
+
this.inner = void 0;
|
|
27614
|
+
this[_Symbol$toStringTag] = 'Error';
|
|
27615
|
+
this.name = 'ValidationError';
|
|
27616
|
+
this.value = value;
|
|
27617
|
+
this.path = field;
|
|
27618
|
+
this.type = type;
|
|
27619
|
+
this.errors = [];
|
|
27620
|
+
this.inner = [];
|
|
27621
|
+
toArray(errorOrErrors).forEach(err => {
|
|
27622
|
+
if (ValidationError.isError(err)) {
|
|
27623
|
+
this.errors.push(...err.errors);
|
|
27624
|
+
const innerErrors = err.inner.length ? err.inner : [err];
|
|
27625
|
+
this.inner.push(...innerErrors);
|
|
27626
|
+
} else {
|
|
27627
|
+
this.errors.push(err);
|
|
27628
|
+
}
|
|
27629
|
+
});
|
|
27630
|
+
this.message = this.errors.length > 1 ? `${this.errors.length} errors occurred` : this.errors[0];
|
|
27631
|
+
}
|
|
27632
|
+
}
|
|
27633
|
+
_Symbol$hasInstance = Symbol.hasInstance;
|
|
27634
|
+
_Symbol$toStringTag2 = Symbol.toStringTag;
|
|
27635
|
+
class ValidationError extends Error {
|
|
27636
|
+
static formatError(message, params) {
|
|
27637
|
+
const path = params.label || params.path || 'this';
|
|
27638
|
+
if (path !== params.path) params = Object.assign({}, params, {
|
|
27639
|
+
path
|
|
27640
|
+
});
|
|
27641
|
+
if (typeof message === 'string') return message.replace(strReg, (_, key) => printValue(params[key]));
|
|
27642
|
+
if (typeof message === 'function') return message(params);
|
|
27643
|
+
return message;
|
|
27644
|
+
}
|
|
27645
|
+
static isError(err) {
|
|
27646
|
+
return err && err.name === 'ValidationError';
|
|
27647
|
+
}
|
|
27648
|
+
constructor(errorOrErrors, value, field, type, disableStack) {
|
|
27649
|
+
const errorNoStack = new ValidationErrorNoStack(errorOrErrors, value, field, type);
|
|
27650
|
+
if (disableStack) {
|
|
27651
|
+
return errorNoStack;
|
|
27652
|
+
}
|
|
27653
|
+
super();
|
|
27654
|
+
this.value = void 0;
|
|
27655
|
+
this.path = void 0;
|
|
27656
|
+
this.type = void 0;
|
|
27657
|
+
this.params = void 0;
|
|
27658
|
+
this.errors = [];
|
|
27659
|
+
this.inner = [];
|
|
27660
|
+
this[_Symbol$toStringTag2] = 'Error';
|
|
27661
|
+
this.name = errorNoStack.name;
|
|
27662
|
+
this.message = errorNoStack.message;
|
|
27663
|
+
this.type = errorNoStack.type;
|
|
27664
|
+
this.value = errorNoStack.value;
|
|
27665
|
+
this.path = errorNoStack.path;
|
|
27666
|
+
this.errors = errorNoStack.errors;
|
|
27667
|
+
this.inner = errorNoStack.inner;
|
|
27668
|
+
if (Error.captureStackTrace) {
|
|
27669
|
+
Error.captureStackTrace(this, ValidationError);
|
|
27670
|
+
}
|
|
27671
|
+
}
|
|
27672
|
+
static [_Symbol$hasInstance](inst) {
|
|
27673
|
+
return ValidationErrorNoStack[Symbol.hasInstance](inst) || super[Symbol.hasInstance](inst);
|
|
27674
|
+
}
|
|
27675
|
+
}
|
|
27676
|
+
|
|
27677
|
+
let mixed = {
|
|
27678
|
+
default: '${path} is invalid',
|
|
27679
|
+
required: '${path} is a required field',
|
|
27680
|
+
defined: '${path} must be defined',
|
|
27681
|
+
notNull: '${path} cannot be null',
|
|
27682
|
+
oneOf: '${path} must be one of the following values: ${values}',
|
|
27683
|
+
notOneOf: '${path} must not be one of the following values: ${values}',
|
|
27684
|
+
notType: ({
|
|
27685
|
+
path,
|
|
27686
|
+
type,
|
|
27687
|
+
value,
|
|
27688
|
+
originalValue
|
|
27689
|
+
}) => {
|
|
27690
|
+
const castMsg = originalValue != null && originalValue !== value ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : '.';
|
|
27691
|
+
return type !== 'mixed' ? `${path} must be a \`${type}\` type, ` + `but the final value was: \`${printValue(value, true)}\`` + castMsg : `${path} must match the configured type. ` + `The validated value was: \`${printValue(value, true)}\`` + castMsg;
|
|
27692
|
+
}
|
|
27693
|
+
};
|
|
27694
|
+
let string = {
|
|
27695
|
+
length: '${path} must be exactly ${length} characters',
|
|
27696
|
+
min: '${path} must be at least ${min} characters',
|
|
27697
|
+
max: '${path} must be at most ${max} characters',
|
|
27698
|
+
matches: '${path} must match the following: "${regex}"',
|
|
27699
|
+
email: '${path} must be a valid email',
|
|
27700
|
+
url: '${path} must be a valid URL',
|
|
27701
|
+
uuid: '${path} must be a valid UUID',
|
|
27702
|
+
datetime: '${path} must be a valid ISO date-time',
|
|
27703
|
+
datetime_precision: '${path} must be a valid ISO date-time with a sub-second precision of exactly ${precision} digits',
|
|
27704
|
+
datetime_offset: '${path} must be a valid ISO date-time with UTC "Z" timezone',
|
|
27705
|
+
trim: '${path} must be a trimmed string',
|
|
27706
|
+
lowercase: '${path} must be a lowercase string',
|
|
27707
|
+
uppercase: '${path} must be a upper case string'
|
|
27708
|
+
};
|
|
27709
|
+
let number = {
|
|
27710
|
+
min: '${path} must be greater than or equal to ${min}',
|
|
27711
|
+
max: '${path} must be less than or equal to ${max}',
|
|
27712
|
+
lessThan: '${path} must be less than ${less}',
|
|
27713
|
+
moreThan: '${path} must be greater than ${more}',
|
|
27714
|
+
positive: '${path} must be a positive number',
|
|
27715
|
+
negative: '${path} must be a negative number',
|
|
27716
|
+
integer: '${path} must be an integer'
|
|
27717
|
+
};
|
|
27718
|
+
let date = {
|
|
27719
|
+
min: '${path} field must be later than ${min}',
|
|
27720
|
+
max: '${path} field must be at earlier than ${max}'
|
|
27721
|
+
};
|
|
27722
|
+
let boolean = {
|
|
27723
|
+
isValue: '${path} field must be ${value}'
|
|
27724
|
+
};
|
|
27725
|
+
let object = {
|
|
27726
|
+
noUnknown: '${path} field has unspecified keys: ${unknown}'
|
|
27727
|
+
};
|
|
27728
|
+
let array = {
|
|
27729
|
+
min: '${path} field must have at least ${min} items',
|
|
27730
|
+
max: '${path} field must have less than or equal to ${max} items',
|
|
27731
|
+
length: '${path} must have ${length} items'
|
|
27732
|
+
};
|
|
27733
|
+
let tuple = {
|
|
27734
|
+
notType: params => {
|
|
27735
|
+
const {
|
|
27736
|
+
path,
|
|
27737
|
+
value,
|
|
27738
|
+
spec
|
|
27739
|
+
} = params;
|
|
27740
|
+
const typeLen = spec.types.length;
|
|
27741
|
+
if (Array.isArray(value)) {
|
|
27742
|
+
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)}\``;
|
|
27743
|
+
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)}\``;
|
|
27744
|
+
}
|
|
27745
|
+
return ValidationError.formatError(mixed.notType, params);
|
|
27746
|
+
}
|
|
27747
|
+
};
|
|
27748
|
+
var locale = Object.assign(Object.create(null), {
|
|
27749
|
+
mixed,
|
|
27750
|
+
string,
|
|
27751
|
+
number,
|
|
27752
|
+
date,
|
|
27753
|
+
object,
|
|
27754
|
+
array,
|
|
27755
|
+
boolean,
|
|
27756
|
+
tuple
|
|
27757
|
+
});
|
|
27758
|
+
|
|
27759
|
+
const isSchema = obj => obj && obj.__isYupSchema__;
|
|
27760
|
+
|
|
27761
|
+
class Condition {
|
|
27762
|
+
static fromOptions(refs, config) {
|
|
27763
|
+
if (!config.then && !config.otherwise) throw new TypeError('either `then:` or `otherwise:` is required for `when()` conditions');
|
|
27764
|
+
let {
|
|
27765
|
+
is,
|
|
27766
|
+
then,
|
|
27767
|
+
otherwise
|
|
27768
|
+
} = config;
|
|
27769
|
+
let check = typeof is === 'function' ? is : (...values) => values.every(value => value === is);
|
|
27770
|
+
return new Condition(refs, (values, schema) => {
|
|
27771
|
+
var _branch;
|
|
27772
|
+
let branch = check(...values) ? then : otherwise;
|
|
27773
|
+
return (_branch = branch == null ? void 0 : branch(schema)) != null ? _branch : schema;
|
|
27774
|
+
});
|
|
27775
|
+
}
|
|
27776
|
+
constructor(refs, builder) {
|
|
27777
|
+
this.fn = void 0;
|
|
27778
|
+
this.refs = refs;
|
|
27779
|
+
this.refs = refs;
|
|
27780
|
+
this.fn = builder;
|
|
27781
|
+
}
|
|
27782
|
+
resolve(base, options) {
|
|
27783
|
+
let values = this.refs.map(ref =>
|
|
27784
|
+
// TODO: ? operator here?
|
|
27785
|
+
ref.getValue(options == null ? void 0 : options.value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context));
|
|
27786
|
+
let schema = this.fn(values, base, options);
|
|
27787
|
+
if (schema === undefined ||
|
|
27788
|
+
// @ts-ignore this can be base
|
|
27789
|
+
schema === base) {
|
|
27790
|
+
return base;
|
|
27791
|
+
}
|
|
27792
|
+
if (!isSchema(schema)) throw new TypeError('conditions must return a schema object');
|
|
27793
|
+
return schema.resolve(options);
|
|
27794
|
+
}
|
|
27795
|
+
}
|
|
27796
|
+
|
|
27797
|
+
const prefixes = {
|
|
27798
|
+
context: '$',
|
|
27799
|
+
value: '.'
|
|
27800
|
+
};
|
|
27801
|
+
function create$9(key, options) {
|
|
27802
|
+
return new Reference(key, options);
|
|
27803
|
+
}
|
|
27804
|
+
class Reference {
|
|
27805
|
+
constructor(key, options = {}) {
|
|
27806
|
+
this.key = void 0;
|
|
27807
|
+
this.isContext = void 0;
|
|
27808
|
+
this.isValue = void 0;
|
|
27809
|
+
this.isSibling = void 0;
|
|
27810
|
+
this.path = void 0;
|
|
27811
|
+
this.getter = void 0;
|
|
27812
|
+
this.map = void 0;
|
|
27813
|
+
if (typeof key !== 'string') throw new TypeError('ref must be a string, got: ' + key);
|
|
27814
|
+
this.key = key.trim();
|
|
27815
|
+
if (key === '') throw new TypeError('ref must be a non-empty string');
|
|
27816
|
+
this.isContext = this.key[0] === prefixes.context;
|
|
27817
|
+
this.isValue = this.key[0] === prefixes.value;
|
|
27818
|
+
this.isSibling = !this.isContext && !this.isValue;
|
|
27819
|
+
let prefix = this.isContext ? prefixes.context : this.isValue ? prefixes.value : '';
|
|
27820
|
+
this.path = this.key.slice(prefix.length);
|
|
27821
|
+
this.getter = this.path && propertyExprExports.getter(this.path, true);
|
|
27822
|
+
this.map = options.map;
|
|
27823
|
+
}
|
|
27824
|
+
getValue(value, parent, context) {
|
|
27825
|
+
let result = this.isContext ? context : this.isValue ? value : parent;
|
|
27826
|
+
if (this.getter) result = this.getter(result || {});
|
|
27827
|
+
if (this.map) result = this.map(result);
|
|
27828
|
+
return result;
|
|
27829
|
+
}
|
|
27830
|
+
|
|
27831
|
+
/**
|
|
27832
|
+
*
|
|
27833
|
+
* @param {*} value
|
|
27834
|
+
* @param {Object} options
|
|
27835
|
+
* @param {Object=} options.context
|
|
27836
|
+
* @param {Object=} options.parent
|
|
27837
|
+
*/
|
|
27838
|
+
cast(value, options) {
|
|
27839
|
+
return this.getValue(value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context);
|
|
27840
|
+
}
|
|
27841
|
+
resolve() {
|
|
27842
|
+
return this;
|
|
27843
|
+
}
|
|
27844
|
+
describe() {
|
|
27845
|
+
return {
|
|
27846
|
+
type: 'ref',
|
|
27847
|
+
key: this.key
|
|
27848
|
+
};
|
|
27849
|
+
}
|
|
27850
|
+
toString() {
|
|
27851
|
+
return `Ref(${this.key})`;
|
|
27852
|
+
}
|
|
27853
|
+
static isRef(value) {
|
|
27854
|
+
return value && value.__isYupRef;
|
|
27855
|
+
}
|
|
27856
|
+
}
|
|
27857
|
+
|
|
27858
|
+
// @ts-ignore
|
|
27859
|
+
Reference.prototype.__isYupRef = true;
|
|
27860
|
+
|
|
27861
|
+
const isAbsent = value => value == null;
|
|
27862
|
+
|
|
27863
|
+
function createValidation(config) {
|
|
27864
|
+
function validate({
|
|
27865
|
+
value,
|
|
27866
|
+
path = '',
|
|
27867
|
+
options,
|
|
27868
|
+
originalValue,
|
|
27869
|
+
schema
|
|
27870
|
+
}, panic, next) {
|
|
27871
|
+
const {
|
|
27872
|
+
name,
|
|
27873
|
+
test,
|
|
27874
|
+
params,
|
|
27875
|
+
message,
|
|
27876
|
+
skipAbsent
|
|
27877
|
+
} = config;
|
|
27878
|
+
let {
|
|
27879
|
+
parent,
|
|
27880
|
+
context,
|
|
27881
|
+
abortEarly = schema.spec.abortEarly,
|
|
27882
|
+
disableStackTrace = schema.spec.disableStackTrace
|
|
27883
|
+
} = options;
|
|
27884
|
+
function resolve(item) {
|
|
27885
|
+
return Reference.isRef(item) ? item.getValue(value, parent, context) : item;
|
|
27886
|
+
}
|
|
27887
|
+
function createError(overrides = {}) {
|
|
27888
|
+
const nextParams = Object.assign({
|
|
27889
|
+
value,
|
|
27890
|
+
originalValue,
|
|
27891
|
+
label: schema.spec.label,
|
|
27892
|
+
path: overrides.path || path,
|
|
27893
|
+
spec: schema.spec,
|
|
27894
|
+
disableStackTrace: overrides.disableStackTrace || disableStackTrace
|
|
27895
|
+
}, params, overrides.params);
|
|
27896
|
+
for (const key of Object.keys(nextParams)) nextParams[key] = resolve(nextParams[key]);
|
|
27897
|
+
const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
|
|
27898
|
+
error.params = nextParams;
|
|
27899
|
+
return error;
|
|
27900
|
+
}
|
|
27901
|
+
const invalid = abortEarly ? panic : next;
|
|
27902
|
+
let ctx = {
|
|
27903
|
+
path,
|
|
27904
|
+
parent,
|
|
27905
|
+
type: name,
|
|
27906
|
+
from: options.from,
|
|
27907
|
+
createError,
|
|
27908
|
+
resolve,
|
|
27909
|
+
options,
|
|
27910
|
+
originalValue,
|
|
27911
|
+
schema
|
|
27912
|
+
};
|
|
27913
|
+
const handleResult = validOrError => {
|
|
27914
|
+
if (ValidationError.isError(validOrError)) invalid(validOrError);else if (!validOrError) invalid(createError());else next(null);
|
|
27915
|
+
};
|
|
27916
|
+
const handleError = err => {
|
|
27917
|
+
if (ValidationError.isError(err)) invalid(err);else panic(err);
|
|
27918
|
+
};
|
|
27919
|
+
const shouldSkip = skipAbsent && isAbsent(value);
|
|
27920
|
+
if (shouldSkip) {
|
|
27921
|
+
return handleResult(true);
|
|
27922
|
+
}
|
|
27923
|
+
let result;
|
|
27924
|
+
try {
|
|
27925
|
+
var _result;
|
|
27926
|
+
result = test.call(ctx, value, ctx);
|
|
27927
|
+
if (typeof ((_result = result) == null ? void 0 : _result.then) === 'function') {
|
|
27928
|
+
if (options.sync) {
|
|
27929
|
+
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`);
|
|
27930
|
+
}
|
|
27931
|
+
return Promise.resolve(result).then(handleResult, handleError);
|
|
27932
|
+
}
|
|
27933
|
+
} catch (err) {
|
|
27934
|
+
handleError(err);
|
|
27935
|
+
return;
|
|
27936
|
+
}
|
|
27937
|
+
handleResult(result);
|
|
27938
|
+
}
|
|
27939
|
+
validate.OPTIONS = config;
|
|
27940
|
+
return validate;
|
|
27941
|
+
}
|
|
27942
|
+
|
|
27943
|
+
function getIn(schema, path, value, context = value) {
|
|
27944
|
+
let parent, lastPart, lastPartDebug;
|
|
27945
|
+
|
|
27946
|
+
// root path: ''
|
|
27947
|
+
if (!path) return {
|
|
27948
|
+
parent,
|
|
27949
|
+
parentPath: path,
|
|
27950
|
+
schema
|
|
27951
|
+
};
|
|
27952
|
+
propertyExprExports.forEach(path, (_part, isBracket, isArray) => {
|
|
27953
|
+
let part = isBracket ? _part.slice(1, _part.length - 1) : _part;
|
|
27954
|
+
schema = schema.resolve({
|
|
27955
|
+
context,
|
|
27956
|
+
parent,
|
|
27957
|
+
value
|
|
27958
|
+
});
|
|
27959
|
+
let isTuple = schema.type === 'tuple';
|
|
27960
|
+
let idx = isArray ? parseInt(part, 10) : 0;
|
|
27961
|
+
if (schema.innerType || isTuple) {
|
|
27962
|
+
if (isTuple && !isArray) throw new Error(`Yup.reach cannot implicitly index into a tuple type. the path part "${lastPartDebug}" must contain an index to the tuple element, e.g. "${lastPartDebug}[0]"`);
|
|
27963
|
+
if (value && idx >= value.length) {
|
|
27964
|
+
throw new Error(`Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. ` + `because there is no value at that index. `);
|
|
27965
|
+
}
|
|
27966
|
+
parent = value;
|
|
27967
|
+
value = value && value[idx];
|
|
27968
|
+
schema = isTuple ? schema.spec.types[idx] : schema.innerType;
|
|
27969
|
+
}
|
|
27970
|
+
|
|
27971
|
+
// sometimes the array index part of a path doesn't exist: "nested.arr.child"
|
|
27972
|
+
// in these cases the current part is the next schema and should be processed
|
|
27973
|
+
// in this iteration. For cases where the index signature is included this
|
|
27974
|
+
// check will fail and we'll handle the `child` part on the next iteration like normal
|
|
27975
|
+
if (!isArray) {
|
|
27976
|
+
if (!schema.fields || !schema.fields[part]) throw new Error(`The schema does not contain the path: ${path}. ` + `(failed at: ${lastPartDebug} which is a type: "${schema.type}")`);
|
|
27977
|
+
parent = value;
|
|
27978
|
+
value = value && value[part];
|
|
27979
|
+
schema = schema.fields[part];
|
|
27980
|
+
}
|
|
27981
|
+
lastPart = part;
|
|
27982
|
+
lastPartDebug = isBracket ? '[' + _part + ']' : '.' + _part;
|
|
27983
|
+
});
|
|
27984
|
+
return {
|
|
27985
|
+
schema,
|
|
27986
|
+
parent,
|
|
27987
|
+
parentPath: lastPart
|
|
27988
|
+
};
|
|
27989
|
+
}
|
|
27990
|
+
function reach(obj, path, value, context) {
|
|
27991
|
+
return getIn(obj, path, value, context).schema;
|
|
27992
|
+
}
|
|
27993
|
+
|
|
27994
|
+
class ReferenceSet extends Set {
|
|
27995
|
+
describe() {
|
|
27996
|
+
const description = [];
|
|
27997
|
+
for (const item of this.values()) {
|
|
27998
|
+
description.push(Reference.isRef(item) ? item.describe() : item);
|
|
27999
|
+
}
|
|
28000
|
+
return description;
|
|
28001
|
+
}
|
|
28002
|
+
resolveAll(resolve) {
|
|
28003
|
+
let result = [];
|
|
28004
|
+
for (const item of this.values()) {
|
|
28005
|
+
result.push(resolve(item));
|
|
28006
|
+
}
|
|
28007
|
+
return result;
|
|
28008
|
+
}
|
|
28009
|
+
clone() {
|
|
28010
|
+
return new ReferenceSet(this.values());
|
|
28011
|
+
}
|
|
28012
|
+
merge(newItems, removeItems) {
|
|
28013
|
+
const next = this.clone();
|
|
28014
|
+
newItems.forEach(value => next.add(value));
|
|
28015
|
+
removeItems.forEach(value => next.delete(value));
|
|
28016
|
+
return next;
|
|
28017
|
+
}
|
|
28018
|
+
}
|
|
28019
|
+
|
|
28020
|
+
// tweaked from https://github.com/Kelin2025/nanoclone/blob/0abeb7635bda9b68ef2277093f76dbe3bf3948e1/src/index.js
|
|
28021
|
+
function clone(src, seen = new Map()) {
|
|
28022
|
+
if (isSchema(src) || !src || typeof src !== 'object') return src;
|
|
28023
|
+
if (seen.has(src)) return seen.get(src);
|
|
28024
|
+
let copy;
|
|
28025
|
+
if (src instanceof Date) {
|
|
28026
|
+
// Date
|
|
28027
|
+
copy = new Date(src.getTime());
|
|
28028
|
+
seen.set(src, copy);
|
|
28029
|
+
} else if (src instanceof RegExp) {
|
|
28030
|
+
// RegExp
|
|
28031
|
+
copy = new RegExp(src);
|
|
28032
|
+
seen.set(src, copy);
|
|
28033
|
+
} else if (Array.isArray(src)) {
|
|
28034
|
+
// Array
|
|
28035
|
+
copy = new Array(src.length);
|
|
28036
|
+
seen.set(src, copy);
|
|
28037
|
+
for (let i = 0; i < src.length; i++) copy[i] = clone(src[i], seen);
|
|
28038
|
+
} else if (src instanceof Map) {
|
|
28039
|
+
// Map
|
|
28040
|
+
copy = new Map();
|
|
28041
|
+
seen.set(src, copy);
|
|
28042
|
+
for (const [k, v] of src.entries()) copy.set(k, clone(v, seen));
|
|
28043
|
+
} else if (src instanceof Set) {
|
|
28044
|
+
// Set
|
|
28045
|
+
copy = new Set();
|
|
28046
|
+
seen.set(src, copy);
|
|
28047
|
+
for (const v of src) copy.add(clone(v, seen));
|
|
28048
|
+
} else if (src instanceof Object) {
|
|
28049
|
+
// Object
|
|
28050
|
+
copy = {};
|
|
28051
|
+
seen.set(src, copy);
|
|
28052
|
+
for (const [k, v] of Object.entries(src)) copy[k] = clone(v, seen);
|
|
28053
|
+
} else {
|
|
28054
|
+
throw Error(`Unable to clone ${src}`);
|
|
28055
|
+
}
|
|
28056
|
+
return copy;
|
|
28057
|
+
}
|
|
28058
|
+
|
|
28059
|
+
// If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
|
|
28060
|
+
// loose Record definition allowing free form usage.
|
|
28061
|
+
class Schema {
|
|
28062
|
+
constructor(options) {
|
|
28063
|
+
this.type = void 0;
|
|
28064
|
+
this.deps = [];
|
|
28065
|
+
this.tests = void 0;
|
|
28066
|
+
this.transforms = void 0;
|
|
28067
|
+
this.conditions = [];
|
|
28068
|
+
this._mutate = void 0;
|
|
28069
|
+
this.internalTests = {};
|
|
28070
|
+
this._whitelist = new ReferenceSet();
|
|
28071
|
+
this._blacklist = new ReferenceSet();
|
|
28072
|
+
this.exclusiveTests = Object.create(null);
|
|
28073
|
+
this._typeCheck = void 0;
|
|
28074
|
+
this.spec = void 0;
|
|
28075
|
+
this.tests = [];
|
|
28076
|
+
this.transforms = [];
|
|
28077
|
+
this.withMutation(() => {
|
|
28078
|
+
this.typeError(mixed.notType);
|
|
28079
|
+
});
|
|
28080
|
+
this.type = options.type;
|
|
28081
|
+
this._typeCheck = options.check;
|
|
28082
|
+
this.spec = Object.assign({
|
|
28083
|
+
strip: false,
|
|
28084
|
+
strict: false,
|
|
28085
|
+
abortEarly: true,
|
|
28086
|
+
recursive: true,
|
|
28087
|
+
disableStackTrace: false,
|
|
28088
|
+
nullable: false,
|
|
28089
|
+
optional: true,
|
|
28090
|
+
coerce: true
|
|
28091
|
+
}, options == null ? void 0 : options.spec);
|
|
28092
|
+
this.withMutation(s => {
|
|
28093
|
+
s.nonNullable();
|
|
28094
|
+
});
|
|
28095
|
+
}
|
|
28096
|
+
|
|
28097
|
+
// TODO: remove
|
|
28098
|
+
get _type() {
|
|
28099
|
+
return this.type;
|
|
28100
|
+
}
|
|
28101
|
+
clone(spec) {
|
|
28102
|
+
if (this._mutate) {
|
|
28103
|
+
if (spec) Object.assign(this.spec, spec);
|
|
28104
|
+
return this;
|
|
28105
|
+
}
|
|
28106
|
+
|
|
28107
|
+
// if the nested value is a schema we can skip cloning, since
|
|
28108
|
+
// they are already immutable
|
|
28109
|
+
const next = Object.create(Object.getPrototypeOf(this));
|
|
28110
|
+
|
|
28111
|
+
// @ts-expect-error this is readonly
|
|
28112
|
+
next.type = this.type;
|
|
28113
|
+
next._typeCheck = this._typeCheck;
|
|
28114
|
+
next._whitelist = this._whitelist.clone();
|
|
28115
|
+
next._blacklist = this._blacklist.clone();
|
|
28116
|
+
next.internalTests = Object.assign({}, this.internalTests);
|
|
28117
|
+
next.exclusiveTests = Object.assign({}, this.exclusiveTests);
|
|
28118
|
+
|
|
28119
|
+
// @ts-expect-error this is readonly
|
|
28120
|
+
next.deps = [...this.deps];
|
|
28121
|
+
next.conditions = [...this.conditions];
|
|
28122
|
+
next.tests = [...this.tests];
|
|
28123
|
+
next.transforms = [...this.transforms];
|
|
28124
|
+
next.spec = clone(Object.assign({}, this.spec, spec));
|
|
28125
|
+
return next;
|
|
28126
|
+
}
|
|
28127
|
+
label(label) {
|
|
28128
|
+
let next = this.clone();
|
|
28129
|
+
next.spec.label = label;
|
|
28130
|
+
return next;
|
|
28131
|
+
}
|
|
28132
|
+
meta(...args) {
|
|
28133
|
+
if (args.length === 0) return this.spec.meta;
|
|
28134
|
+
let next = this.clone();
|
|
28135
|
+
next.spec.meta = Object.assign(next.spec.meta || {}, args[0]);
|
|
28136
|
+
return next;
|
|
28137
|
+
}
|
|
28138
|
+
withMutation(fn) {
|
|
28139
|
+
let before = this._mutate;
|
|
28140
|
+
this._mutate = true;
|
|
28141
|
+
let result = fn(this);
|
|
28142
|
+
this._mutate = before;
|
|
28143
|
+
return result;
|
|
28144
|
+
}
|
|
28145
|
+
concat(schema) {
|
|
28146
|
+
if (!schema || schema === this) return this;
|
|
28147
|
+
if (schema.type !== this.type && this.type !== 'mixed') throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${schema.type}`);
|
|
28148
|
+
let base = this;
|
|
28149
|
+
let combined = schema.clone();
|
|
28150
|
+
const mergedSpec = Object.assign({}, base.spec, combined.spec);
|
|
28151
|
+
combined.spec = mergedSpec;
|
|
28152
|
+
combined.internalTests = Object.assign({}, base.internalTests, combined.internalTests);
|
|
28153
|
+
|
|
28154
|
+
// manually merge the blacklist/whitelist (the other `schema` takes
|
|
28155
|
+
// precedence in case of conflicts)
|
|
28156
|
+
combined._whitelist = base._whitelist.merge(schema._whitelist, schema._blacklist);
|
|
28157
|
+
combined._blacklist = base._blacklist.merge(schema._blacklist, schema._whitelist);
|
|
28158
|
+
|
|
28159
|
+
// start with the current tests
|
|
28160
|
+
combined.tests = base.tests;
|
|
28161
|
+
combined.exclusiveTests = base.exclusiveTests;
|
|
28162
|
+
|
|
28163
|
+
// manually add the new tests to ensure
|
|
28164
|
+
// the deduping logic is consistent
|
|
28165
|
+
combined.withMutation(next => {
|
|
28166
|
+
schema.tests.forEach(fn => {
|
|
28167
|
+
next.test(fn.OPTIONS);
|
|
28168
|
+
});
|
|
28169
|
+
});
|
|
28170
|
+
combined.transforms = [...base.transforms, ...combined.transforms];
|
|
28171
|
+
return combined;
|
|
28172
|
+
}
|
|
28173
|
+
isType(v) {
|
|
28174
|
+
if (v == null) {
|
|
28175
|
+
if (this.spec.nullable && v === null) return true;
|
|
28176
|
+
if (this.spec.optional && v === undefined) return true;
|
|
28177
|
+
return false;
|
|
28178
|
+
}
|
|
28179
|
+
return this._typeCheck(v);
|
|
28180
|
+
}
|
|
28181
|
+
resolve(options) {
|
|
28182
|
+
let schema = this;
|
|
28183
|
+
if (schema.conditions.length) {
|
|
28184
|
+
let conditions = schema.conditions;
|
|
28185
|
+
schema = schema.clone();
|
|
28186
|
+
schema.conditions = [];
|
|
28187
|
+
schema = conditions.reduce((prevSchema, condition) => condition.resolve(prevSchema, options), schema);
|
|
28188
|
+
schema = schema.resolve(options);
|
|
28189
|
+
}
|
|
28190
|
+
return schema;
|
|
28191
|
+
}
|
|
28192
|
+
resolveOptions(options) {
|
|
28193
|
+
var _options$strict, _options$abortEarly, _options$recursive, _options$disableStack;
|
|
28194
|
+
return Object.assign({}, options, {
|
|
28195
|
+
from: options.from || [],
|
|
28196
|
+
strict: (_options$strict = options.strict) != null ? _options$strict : this.spec.strict,
|
|
28197
|
+
abortEarly: (_options$abortEarly = options.abortEarly) != null ? _options$abortEarly : this.spec.abortEarly,
|
|
28198
|
+
recursive: (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive,
|
|
28199
|
+
disableStackTrace: (_options$disableStack = options.disableStackTrace) != null ? _options$disableStack : this.spec.disableStackTrace
|
|
28200
|
+
});
|
|
28201
|
+
}
|
|
28202
|
+
|
|
28203
|
+
/**
|
|
28204
|
+
* Run the configured transform pipeline over an input value.
|
|
28205
|
+
*/
|
|
28206
|
+
|
|
28207
|
+
cast(value, options = {}) {
|
|
28208
|
+
let resolvedSchema = this.resolve(Object.assign({
|
|
28209
|
+
value
|
|
28210
|
+
}, options));
|
|
28211
|
+
let allowOptionality = options.assert === 'ignore-optionality';
|
|
28212
|
+
let result = resolvedSchema._cast(value, options);
|
|
28213
|
+
if (options.assert !== false && !resolvedSchema.isType(result)) {
|
|
28214
|
+
if (allowOptionality && isAbsent(result)) {
|
|
28215
|
+
return result;
|
|
28216
|
+
}
|
|
28217
|
+
let formattedValue = printValue(value);
|
|
28218
|
+
let formattedResult = printValue(result);
|
|
28219
|
+
throw new TypeError(`The value of ${options.path || 'field'} could not be cast to a value ` + `that satisfies the schema type: "${resolvedSchema.type}". \n\n` + `attempted value: ${formattedValue} \n` + (formattedResult !== formattedValue ? `result of cast: ${formattedResult}` : ''));
|
|
28220
|
+
}
|
|
28221
|
+
return result;
|
|
28222
|
+
}
|
|
28223
|
+
_cast(rawValue, options) {
|
|
28224
|
+
let value = rawValue === undefined ? rawValue : this.transforms.reduce((prevValue, fn) => fn.call(this, prevValue, rawValue, this), rawValue);
|
|
28225
|
+
if (value === undefined) {
|
|
28226
|
+
value = this.getDefault(options);
|
|
28227
|
+
}
|
|
28228
|
+
return value;
|
|
28229
|
+
}
|
|
28230
|
+
_validate(_value, options = {}, panic, next) {
|
|
28231
|
+
let {
|
|
28232
|
+
path,
|
|
28233
|
+
originalValue = _value,
|
|
28234
|
+
strict = this.spec.strict
|
|
28235
|
+
} = options;
|
|
28236
|
+
let value = _value;
|
|
28237
|
+
if (!strict) {
|
|
28238
|
+
value = this._cast(value, Object.assign({
|
|
28239
|
+
assert: false
|
|
28240
|
+
}, options));
|
|
28241
|
+
}
|
|
28242
|
+
let initialTests = [];
|
|
28243
|
+
for (let test of Object.values(this.internalTests)) {
|
|
28244
|
+
if (test) initialTests.push(test);
|
|
28245
|
+
}
|
|
28246
|
+
this.runTests({
|
|
28247
|
+
path,
|
|
28248
|
+
value,
|
|
28249
|
+
originalValue,
|
|
28250
|
+
options,
|
|
28251
|
+
tests: initialTests
|
|
28252
|
+
}, panic, initialErrors => {
|
|
28253
|
+
// even if we aren't ending early we can't proceed further if the types aren't correct
|
|
28254
|
+
if (initialErrors.length) {
|
|
28255
|
+
return next(initialErrors, value);
|
|
28256
|
+
}
|
|
28257
|
+
this.runTests({
|
|
28258
|
+
path,
|
|
28259
|
+
value,
|
|
28260
|
+
originalValue,
|
|
28261
|
+
options,
|
|
28262
|
+
tests: this.tests
|
|
28263
|
+
}, panic, next);
|
|
28264
|
+
});
|
|
28265
|
+
}
|
|
28266
|
+
|
|
28267
|
+
/**
|
|
28268
|
+
* Executes a set of validations, either schema, produced Tests or a nested
|
|
28269
|
+
* schema validate result.
|
|
28270
|
+
*/
|
|
28271
|
+
runTests(runOptions, panic, next) {
|
|
28272
|
+
let fired = false;
|
|
28273
|
+
let {
|
|
28274
|
+
tests,
|
|
28275
|
+
value,
|
|
28276
|
+
originalValue,
|
|
28277
|
+
path,
|
|
28278
|
+
options
|
|
28279
|
+
} = runOptions;
|
|
28280
|
+
let panicOnce = arg => {
|
|
28281
|
+
if (fired) return;
|
|
28282
|
+
fired = true;
|
|
28283
|
+
panic(arg, value);
|
|
28284
|
+
};
|
|
28285
|
+
let nextOnce = arg => {
|
|
28286
|
+
if (fired) return;
|
|
28287
|
+
fired = true;
|
|
28288
|
+
next(arg, value);
|
|
28289
|
+
};
|
|
28290
|
+
let count = tests.length;
|
|
28291
|
+
let nestedErrors = [];
|
|
28292
|
+
if (!count) return nextOnce([]);
|
|
28293
|
+
let args = {
|
|
28294
|
+
value,
|
|
28295
|
+
originalValue,
|
|
28296
|
+
path,
|
|
28297
|
+
options,
|
|
28298
|
+
schema: this
|
|
28299
|
+
};
|
|
28300
|
+
for (let i = 0; i < tests.length; i++) {
|
|
28301
|
+
const test = tests[i];
|
|
28302
|
+
test(args, panicOnce, function finishTestRun(err) {
|
|
28303
|
+
if (err) {
|
|
28304
|
+
Array.isArray(err) ? nestedErrors.push(...err) : nestedErrors.push(err);
|
|
28305
|
+
}
|
|
28306
|
+
if (--count <= 0) {
|
|
28307
|
+
nextOnce(nestedErrors);
|
|
28308
|
+
}
|
|
28309
|
+
});
|
|
28310
|
+
}
|
|
28311
|
+
}
|
|
28312
|
+
asNestedTest({
|
|
28313
|
+
key,
|
|
28314
|
+
index,
|
|
28315
|
+
parent,
|
|
28316
|
+
parentPath,
|
|
28317
|
+
originalParent,
|
|
28318
|
+
options
|
|
28319
|
+
}) {
|
|
28320
|
+
const k = key != null ? key : index;
|
|
28321
|
+
if (k == null) {
|
|
28322
|
+
throw TypeError('Must include `key` or `index` for nested validations');
|
|
28323
|
+
}
|
|
28324
|
+
const isIndex = typeof k === 'number';
|
|
28325
|
+
let value = parent[k];
|
|
28326
|
+
const testOptions = Object.assign({}, options, {
|
|
28327
|
+
// Nested validations fields are always strict:
|
|
28328
|
+
// 1. parent isn't strict so the casting will also have cast inner values
|
|
28329
|
+
// 2. parent is strict in which case the nested values weren't cast either
|
|
28330
|
+
strict: true,
|
|
28331
|
+
parent,
|
|
28332
|
+
value,
|
|
28333
|
+
originalValue: originalParent[k],
|
|
28334
|
+
// FIXME: tests depend on `index` being passed around deeply,
|
|
28335
|
+
// we should not let the options.key/index bleed through
|
|
28336
|
+
key: undefined,
|
|
28337
|
+
// index: undefined,
|
|
28338
|
+
[isIndex ? 'index' : 'key']: k,
|
|
28339
|
+
path: isIndex || k.includes('.') ? `${parentPath || ''}[${isIndex ? k : `"${k}"`}]` : (parentPath ? `${parentPath}.` : '') + key
|
|
28340
|
+
});
|
|
28341
|
+
return (_, panic, next) => this.resolve(testOptions)._validate(value, testOptions, panic, next);
|
|
28342
|
+
}
|
|
28343
|
+
validate(value, options) {
|
|
28344
|
+
var _options$disableStack2;
|
|
28345
|
+
let schema = this.resolve(Object.assign({}, options, {
|
|
28346
|
+
value
|
|
28347
|
+
}));
|
|
28348
|
+
let disableStackTrace = (_options$disableStack2 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack2 : schema.spec.disableStackTrace;
|
|
28349
|
+
return new Promise((resolve, reject) => schema._validate(value, options, (error, parsed) => {
|
|
28350
|
+
if (ValidationError.isError(error)) error.value = parsed;
|
|
28351
|
+
reject(error);
|
|
28352
|
+
}, (errors, validated) => {
|
|
28353
|
+
if (errors.length) reject(new ValidationError(errors, validated, undefined, undefined, disableStackTrace));else resolve(validated);
|
|
28354
|
+
}));
|
|
28355
|
+
}
|
|
28356
|
+
validateSync(value, options) {
|
|
28357
|
+
var _options$disableStack3;
|
|
28358
|
+
let schema = this.resolve(Object.assign({}, options, {
|
|
28359
|
+
value
|
|
28360
|
+
}));
|
|
28361
|
+
let result;
|
|
28362
|
+
let disableStackTrace = (_options$disableStack3 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack3 : schema.spec.disableStackTrace;
|
|
28363
|
+
schema._validate(value, Object.assign({}, options, {
|
|
28364
|
+
sync: true
|
|
28365
|
+
}), (error, parsed) => {
|
|
28366
|
+
if (ValidationError.isError(error)) error.value = parsed;
|
|
28367
|
+
throw error;
|
|
28368
|
+
}, (errors, validated) => {
|
|
28369
|
+
if (errors.length) throw new ValidationError(errors, value, undefined, undefined, disableStackTrace);
|
|
28370
|
+
result = validated;
|
|
28371
|
+
});
|
|
28372
|
+
return result;
|
|
28373
|
+
}
|
|
28374
|
+
isValid(value, options) {
|
|
28375
|
+
return this.validate(value, options).then(() => true, err => {
|
|
28376
|
+
if (ValidationError.isError(err)) return false;
|
|
28377
|
+
throw err;
|
|
28378
|
+
});
|
|
28379
|
+
}
|
|
28380
|
+
isValidSync(value, options) {
|
|
28381
|
+
try {
|
|
28382
|
+
this.validateSync(value, options);
|
|
28383
|
+
return true;
|
|
28384
|
+
} catch (err) {
|
|
28385
|
+
if (ValidationError.isError(err)) return false;
|
|
28386
|
+
throw err;
|
|
28387
|
+
}
|
|
28388
|
+
}
|
|
28389
|
+
_getDefault(options) {
|
|
28390
|
+
let defaultValue = this.spec.default;
|
|
28391
|
+
if (defaultValue == null) {
|
|
28392
|
+
return defaultValue;
|
|
28393
|
+
}
|
|
28394
|
+
return typeof defaultValue === 'function' ? defaultValue.call(this, options) : clone(defaultValue);
|
|
28395
|
+
}
|
|
28396
|
+
getDefault(options
|
|
28397
|
+
// If schema is defaulted we know it's at least not undefined
|
|
28398
|
+
) {
|
|
28399
|
+
let schema = this.resolve(options || {});
|
|
28400
|
+
return schema._getDefault(options);
|
|
28401
|
+
}
|
|
28402
|
+
default(def) {
|
|
28403
|
+
if (arguments.length === 0) {
|
|
28404
|
+
return this._getDefault();
|
|
28405
|
+
}
|
|
28406
|
+
let next = this.clone({
|
|
28407
|
+
default: def
|
|
28408
|
+
});
|
|
28409
|
+
return next;
|
|
28410
|
+
}
|
|
28411
|
+
strict(isStrict = true) {
|
|
28412
|
+
return this.clone({
|
|
28413
|
+
strict: isStrict
|
|
28414
|
+
});
|
|
28415
|
+
}
|
|
28416
|
+
nullability(nullable, message) {
|
|
28417
|
+
const next = this.clone({
|
|
28418
|
+
nullable
|
|
28419
|
+
});
|
|
28420
|
+
next.internalTests.nullable = createValidation({
|
|
28421
|
+
message,
|
|
28422
|
+
name: 'nullable',
|
|
28423
|
+
test(value) {
|
|
28424
|
+
return value === null ? this.schema.spec.nullable : true;
|
|
28425
|
+
}
|
|
28426
|
+
});
|
|
28427
|
+
return next;
|
|
28428
|
+
}
|
|
28429
|
+
optionality(optional, message) {
|
|
28430
|
+
const next = this.clone({
|
|
28431
|
+
optional
|
|
28432
|
+
});
|
|
28433
|
+
next.internalTests.optionality = createValidation({
|
|
28434
|
+
message,
|
|
28435
|
+
name: 'optionality',
|
|
28436
|
+
test(value) {
|
|
28437
|
+
return value === undefined ? this.schema.spec.optional : true;
|
|
28438
|
+
}
|
|
28439
|
+
});
|
|
28440
|
+
return next;
|
|
28441
|
+
}
|
|
28442
|
+
optional() {
|
|
28443
|
+
return this.optionality(true);
|
|
28444
|
+
}
|
|
28445
|
+
defined(message = mixed.defined) {
|
|
28446
|
+
return this.optionality(false, message);
|
|
28447
|
+
}
|
|
28448
|
+
nullable() {
|
|
28449
|
+
return this.nullability(true);
|
|
28450
|
+
}
|
|
28451
|
+
nonNullable(message = mixed.notNull) {
|
|
28452
|
+
return this.nullability(false, message);
|
|
28453
|
+
}
|
|
28454
|
+
required(message = mixed.required) {
|
|
28455
|
+
return this.clone().withMutation(next => next.nonNullable(message).defined(message));
|
|
28456
|
+
}
|
|
28457
|
+
notRequired() {
|
|
28458
|
+
return this.clone().withMutation(next => next.nullable().optional());
|
|
28459
|
+
}
|
|
28460
|
+
transform(fn) {
|
|
28461
|
+
let next = this.clone();
|
|
28462
|
+
next.transforms.push(fn);
|
|
28463
|
+
return next;
|
|
28464
|
+
}
|
|
28465
|
+
|
|
28466
|
+
/**
|
|
28467
|
+
* Adds a test function to the schema's queue of tests.
|
|
28468
|
+
* tests can be exclusive or non-exclusive.
|
|
28469
|
+
*
|
|
28470
|
+
* - exclusive tests, will replace any existing tests of the same name.
|
|
28471
|
+
* - non-exclusive: can be stacked
|
|
28472
|
+
*
|
|
28473
|
+
* If a non-exclusive test is added to a schema with an exclusive test of the same name
|
|
28474
|
+
* the exclusive test is removed and further tests of the same name will be stacked.
|
|
28475
|
+
*
|
|
28476
|
+
* If an exclusive test is added to a schema with non-exclusive tests of the same name
|
|
28477
|
+
* the previous tests are removed and further tests of the same name will replace each other.
|
|
28478
|
+
*/
|
|
28479
|
+
|
|
28480
|
+
test(...args) {
|
|
28481
|
+
let opts;
|
|
28482
|
+
if (args.length === 1) {
|
|
28483
|
+
if (typeof args[0] === 'function') {
|
|
28484
|
+
opts = {
|
|
28485
|
+
test: args[0]
|
|
28486
|
+
};
|
|
28487
|
+
} else {
|
|
28488
|
+
opts = args[0];
|
|
28489
|
+
}
|
|
28490
|
+
} else if (args.length === 2) {
|
|
28491
|
+
opts = {
|
|
28492
|
+
name: args[0],
|
|
28493
|
+
test: args[1]
|
|
28494
|
+
};
|
|
28495
|
+
} else {
|
|
28496
|
+
opts = {
|
|
28497
|
+
name: args[0],
|
|
28498
|
+
message: args[1],
|
|
28499
|
+
test: args[2]
|
|
28500
|
+
};
|
|
28501
|
+
}
|
|
28502
|
+
if (opts.message === undefined) opts.message = mixed.default;
|
|
28503
|
+
if (typeof opts.test !== 'function') throw new TypeError('`test` is a required parameters');
|
|
28504
|
+
let next = this.clone();
|
|
28505
|
+
let validate = createValidation(opts);
|
|
28506
|
+
let isExclusive = opts.exclusive || opts.name && next.exclusiveTests[opts.name] === true;
|
|
28507
|
+
if (opts.exclusive) {
|
|
28508
|
+
if (!opts.name) throw new TypeError('Exclusive tests must provide a unique `name` identifying the test');
|
|
28509
|
+
}
|
|
28510
|
+
if (opts.name) next.exclusiveTests[opts.name] = !!opts.exclusive;
|
|
28511
|
+
next.tests = next.tests.filter(fn => {
|
|
28512
|
+
if (fn.OPTIONS.name === opts.name) {
|
|
28513
|
+
if (isExclusive) return false;
|
|
28514
|
+
if (fn.OPTIONS.test === validate.OPTIONS.test) return false;
|
|
28515
|
+
}
|
|
28516
|
+
return true;
|
|
28517
|
+
});
|
|
28518
|
+
next.tests.push(validate);
|
|
28519
|
+
return next;
|
|
28520
|
+
}
|
|
28521
|
+
when(keys, options) {
|
|
28522
|
+
if (!Array.isArray(keys) && typeof keys !== 'string') {
|
|
28523
|
+
options = keys;
|
|
28524
|
+
keys = '.';
|
|
28525
|
+
}
|
|
28526
|
+
let next = this.clone();
|
|
28527
|
+
let deps = toArray(keys).map(key => new Reference(key));
|
|
28528
|
+
deps.forEach(dep => {
|
|
28529
|
+
// @ts-ignore readonly array
|
|
28530
|
+
if (dep.isSibling) next.deps.push(dep.key);
|
|
28531
|
+
});
|
|
28532
|
+
next.conditions.push(typeof options === 'function' ? new Condition(deps, options) : Condition.fromOptions(deps, options));
|
|
28533
|
+
return next;
|
|
28534
|
+
}
|
|
28535
|
+
typeError(message) {
|
|
28536
|
+
let next = this.clone();
|
|
28537
|
+
next.internalTests.typeError = createValidation({
|
|
28538
|
+
message,
|
|
28539
|
+
name: 'typeError',
|
|
28540
|
+
skipAbsent: true,
|
|
28541
|
+
test(value) {
|
|
28542
|
+
if (!this.schema._typeCheck(value)) return this.createError({
|
|
28543
|
+
params: {
|
|
28544
|
+
type: this.schema.type
|
|
28545
|
+
}
|
|
28546
|
+
});
|
|
28547
|
+
return true;
|
|
28548
|
+
}
|
|
28549
|
+
});
|
|
28550
|
+
return next;
|
|
28551
|
+
}
|
|
28552
|
+
oneOf(enums, message = mixed.oneOf) {
|
|
28553
|
+
let next = this.clone();
|
|
28554
|
+
enums.forEach(val => {
|
|
28555
|
+
next._whitelist.add(val);
|
|
28556
|
+
next._blacklist.delete(val);
|
|
28557
|
+
});
|
|
28558
|
+
next.internalTests.whiteList = createValidation({
|
|
28559
|
+
message,
|
|
28560
|
+
name: 'oneOf',
|
|
28561
|
+
skipAbsent: true,
|
|
28562
|
+
test(value) {
|
|
28563
|
+
let valids = this.schema._whitelist;
|
|
28564
|
+
let resolved = valids.resolveAll(this.resolve);
|
|
28565
|
+
return resolved.includes(value) ? true : this.createError({
|
|
28566
|
+
params: {
|
|
28567
|
+
values: Array.from(valids).join(', '),
|
|
28568
|
+
resolved
|
|
28569
|
+
}
|
|
28570
|
+
});
|
|
28571
|
+
}
|
|
28572
|
+
});
|
|
28573
|
+
return next;
|
|
28574
|
+
}
|
|
28575
|
+
notOneOf(enums, message = mixed.notOneOf) {
|
|
28576
|
+
let next = this.clone();
|
|
28577
|
+
enums.forEach(val => {
|
|
28578
|
+
next._blacklist.add(val);
|
|
28579
|
+
next._whitelist.delete(val);
|
|
28580
|
+
});
|
|
28581
|
+
next.internalTests.blacklist = createValidation({
|
|
28582
|
+
message,
|
|
28583
|
+
name: 'notOneOf',
|
|
28584
|
+
test(value) {
|
|
28585
|
+
let invalids = this.schema._blacklist;
|
|
28586
|
+
let resolved = invalids.resolveAll(this.resolve);
|
|
28587
|
+
if (resolved.includes(value)) return this.createError({
|
|
28588
|
+
params: {
|
|
28589
|
+
values: Array.from(invalids).join(', '),
|
|
28590
|
+
resolved
|
|
28591
|
+
}
|
|
28592
|
+
});
|
|
28593
|
+
return true;
|
|
28594
|
+
}
|
|
28595
|
+
});
|
|
28596
|
+
return next;
|
|
28597
|
+
}
|
|
28598
|
+
strip(strip = true) {
|
|
28599
|
+
let next = this.clone();
|
|
28600
|
+
next.spec.strip = strip;
|
|
28601
|
+
return next;
|
|
28602
|
+
}
|
|
28603
|
+
|
|
28604
|
+
/**
|
|
28605
|
+
* Return a serialized description of the schema including validations, flags, types etc.
|
|
28606
|
+
*
|
|
28607
|
+
* @param options Provide any needed context for resolving runtime schema alterations (lazy, when conditions, etc).
|
|
28608
|
+
*/
|
|
28609
|
+
describe(options) {
|
|
28610
|
+
const next = (options ? this.resolve(options) : this).clone();
|
|
28611
|
+
const {
|
|
28612
|
+
label,
|
|
28613
|
+
meta,
|
|
28614
|
+
optional,
|
|
28615
|
+
nullable
|
|
28616
|
+
} = next.spec;
|
|
28617
|
+
const description = {
|
|
28618
|
+
meta,
|
|
28619
|
+
label,
|
|
28620
|
+
optional,
|
|
28621
|
+
nullable,
|
|
28622
|
+
default: next.getDefault(options),
|
|
28623
|
+
type: next.type,
|
|
28624
|
+
oneOf: next._whitelist.describe(),
|
|
28625
|
+
notOneOf: next._blacklist.describe(),
|
|
28626
|
+
tests: next.tests.map(fn => ({
|
|
28627
|
+
name: fn.OPTIONS.name,
|
|
28628
|
+
params: fn.OPTIONS.params
|
|
28629
|
+
})).filter((n, idx, list) => list.findIndex(c => c.name === n.name) === idx)
|
|
28630
|
+
};
|
|
28631
|
+
return description;
|
|
28632
|
+
}
|
|
28633
|
+
}
|
|
28634
|
+
// @ts-expect-error
|
|
28635
|
+
Schema.prototype.__isYupSchema__ = true;
|
|
28636
|
+
for (const method of ['validate', 'validateSync']) Schema.prototype[`${method}At`] = function (path, value, options = {}) {
|
|
28637
|
+
const {
|
|
28638
|
+
parent,
|
|
28639
|
+
parentPath,
|
|
28640
|
+
schema
|
|
28641
|
+
} = getIn(this, path, value, options.context);
|
|
28642
|
+
return schema[method](parent && parent[parentPath], Object.assign({}, options, {
|
|
28643
|
+
parent,
|
|
28644
|
+
path
|
|
28645
|
+
}));
|
|
28646
|
+
};
|
|
28647
|
+
for (const alias of ['equals', 'is']) Schema.prototype[alias] = Schema.prototype.oneOf;
|
|
28648
|
+
for (const alias of ['not', 'nope']) Schema.prototype[alias] = Schema.prototype.notOneOf;
|
|
28649
|
+
|
|
28650
|
+
const returnsTrue = () => true;
|
|
28651
|
+
function create$8(spec) {
|
|
28652
|
+
return new MixedSchema(spec);
|
|
28653
|
+
}
|
|
28654
|
+
class MixedSchema extends Schema {
|
|
28655
|
+
constructor(spec) {
|
|
28656
|
+
super(typeof spec === 'function' ? {
|
|
28657
|
+
type: 'mixed',
|
|
28658
|
+
check: spec
|
|
28659
|
+
} : Object.assign({
|
|
28660
|
+
type: 'mixed',
|
|
28661
|
+
check: returnsTrue
|
|
28662
|
+
}, spec));
|
|
28663
|
+
}
|
|
28664
|
+
}
|
|
28665
|
+
create$8.prototype = MixedSchema.prototype;
|
|
28666
|
+
|
|
28667
|
+
function create$7() {
|
|
28668
|
+
return new BooleanSchema();
|
|
28669
|
+
}
|
|
28670
|
+
class BooleanSchema extends Schema {
|
|
28671
|
+
constructor() {
|
|
28672
|
+
super({
|
|
28673
|
+
type: 'boolean',
|
|
28674
|
+
check(v) {
|
|
28675
|
+
if (v instanceof Boolean) v = v.valueOf();
|
|
28676
|
+
return typeof v === 'boolean';
|
|
28677
|
+
}
|
|
28678
|
+
});
|
|
28679
|
+
this.withMutation(() => {
|
|
28680
|
+
this.transform((value, _raw, ctx) => {
|
|
28681
|
+
if (ctx.spec.coerce && !ctx.isType(value)) {
|
|
28682
|
+
if (/^(true|1)$/i.test(String(value))) return true;
|
|
28683
|
+
if (/^(false|0)$/i.test(String(value))) return false;
|
|
28684
|
+
}
|
|
28685
|
+
return value;
|
|
28686
|
+
});
|
|
28687
|
+
});
|
|
28688
|
+
}
|
|
28689
|
+
isTrue(message = boolean.isValue) {
|
|
28690
|
+
return this.test({
|
|
28691
|
+
message,
|
|
28692
|
+
name: 'is-value',
|
|
28693
|
+
exclusive: true,
|
|
28694
|
+
params: {
|
|
28695
|
+
value: 'true'
|
|
28696
|
+
},
|
|
28697
|
+
test(value) {
|
|
28698
|
+
return isAbsent(value) || value === true;
|
|
28699
|
+
}
|
|
28700
|
+
});
|
|
28701
|
+
}
|
|
28702
|
+
isFalse(message = boolean.isValue) {
|
|
28703
|
+
return this.test({
|
|
28704
|
+
message,
|
|
28705
|
+
name: 'is-value',
|
|
28706
|
+
exclusive: true,
|
|
28707
|
+
params: {
|
|
28708
|
+
value: 'false'
|
|
28709
|
+
},
|
|
28710
|
+
test(value) {
|
|
28711
|
+
return isAbsent(value) || value === false;
|
|
28712
|
+
}
|
|
28713
|
+
});
|
|
28714
|
+
}
|
|
28715
|
+
default(def) {
|
|
28716
|
+
return super.default(def);
|
|
28717
|
+
}
|
|
28718
|
+
defined(msg) {
|
|
28719
|
+
return super.defined(msg);
|
|
28720
|
+
}
|
|
28721
|
+
optional() {
|
|
28722
|
+
return super.optional();
|
|
28723
|
+
}
|
|
28724
|
+
required(msg) {
|
|
28725
|
+
return super.required(msg);
|
|
28726
|
+
}
|
|
28727
|
+
notRequired() {
|
|
28728
|
+
return super.notRequired();
|
|
28729
|
+
}
|
|
28730
|
+
nullable() {
|
|
28731
|
+
return super.nullable();
|
|
28732
|
+
}
|
|
28733
|
+
nonNullable(msg) {
|
|
28734
|
+
return super.nonNullable(msg);
|
|
28735
|
+
}
|
|
28736
|
+
strip(v) {
|
|
28737
|
+
return super.strip(v);
|
|
28738
|
+
}
|
|
28739
|
+
}
|
|
28740
|
+
create$7.prototype = BooleanSchema.prototype;
|
|
28741
|
+
|
|
28742
|
+
/**
|
|
28743
|
+
* This file is a modified version of the file from the following repository:
|
|
28744
|
+
* Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
|
|
28745
|
+
* NON-CONFORMANT EDITION.
|
|
28746
|
+
* © 2011 Colin Snover <http://zetafleet.com>
|
|
28747
|
+
* Released under MIT license.
|
|
28748
|
+
*/
|
|
28749
|
+
|
|
28750
|
+
// prettier-ignore
|
|
28751
|
+
// 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
|
|
28752
|
+
const isoReg = /^(\d{4}|[+-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,.](\d{1,}))?)?(?:(Z)|([+-])(\d{2})(?::?(\d{2}))?)?)?$/;
|
|
28753
|
+
function parseIsoDate(date) {
|
|
28754
|
+
const struct = parseDateStruct(date);
|
|
28755
|
+
if (!struct) return Date.parse ? Date.parse(date) : Number.NaN;
|
|
28756
|
+
|
|
28757
|
+
// timestamps without timezone identifiers should be considered local time
|
|
28758
|
+
if (struct.z === undefined && struct.plusMinus === undefined) {
|
|
28759
|
+
return new Date(struct.year, struct.month, struct.day, struct.hour, struct.minute, struct.second, struct.millisecond).valueOf();
|
|
28760
|
+
}
|
|
28761
|
+
let totalMinutesOffset = 0;
|
|
28762
|
+
if (struct.z !== 'Z' && struct.plusMinus !== undefined) {
|
|
28763
|
+
totalMinutesOffset = struct.hourOffset * 60 + struct.minuteOffset;
|
|
28764
|
+
if (struct.plusMinus === '+') totalMinutesOffset = 0 - totalMinutesOffset;
|
|
28765
|
+
}
|
|
28766
|
+
return Date.UTC(struct.year, struct.month, struct.day, struct.hour, struct.minute + totalMinutesOffset, struct.second, struct.millisecond);
|
|
28767
|
+
}
|
|
28768
|
+
function parseDateStruct(date) {
|
|
28769
|
+
var _regexResult$7$length, _regexResult$;
|
|
28770
|
+
const regexResult = isoReg.exec(date);
|
|
28771
|
+
if (!regexResult) return null;
|
|
28772
|
+
|
|
28773
|
+
// use of toNumber() avoids NaN timestamps caused by “undefined”
|
|
28774
|
+
// values being passed to Date constructor
|
|
28775
|
+
return {
|
|
28776
|
+
year: toNumber(regexResult[1]),
|
|
28777
|
+
month: toNumber(regexResult[2], 1) - 1,
|
|
28778
|
+
day: toNumber(regexResult[3], 1),
|
|
28779
|
+
hour: toNumber(regexResult[4]),
|
|
28780
|
+
minute: toNumber(regexResult[5]),
|
|
28781
|
+
second: toNumber(regexResult[6]),
|
|
28782
|
+
millisecond: regexResult[7] ?
|
|
28783
|
+
// allow arbitrary sub-second precision beyond milliseconds
|
|
28784
|
+
toNumber(regexResult[7].substring(0, 3)) : 0,
|
|
28785
|
+
precision: (_regexResult$7$length = (_regexResult$ = regexResult[7]) == null ? void 0 : _regexResult$.length) != null ? _regexResult$7$length : undefined,
|
|
28786
|
+
z: regexResult[8] || undefined,
|
|
28787
|
+
plusMinus: regexResult[9] || undefined,
|
|
28788
|
+
hourOffset: toNumber(regexResult[10]),
|
|
28789
|
+
minuteOffset: toNumber(regexResult[11])
|
|
28790
|
+
};
|
|
28791
|
+
}
|
|
28792
|
+
function toNumber(str, defaultValue = 0) {
|
|
28793
|
+
return Number(str) || defaultValue;
|
|
28794
|
+
}
|
|
28795
|
+
|
|
28796
|
+
// Taken from HTML spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
|
|
28797
|
+
let rEmail =
|
|
28798
|
+
// eslint-disable-next-line
|
|
28799
|
+
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
28800
|
+
let rUrl =
|
|
28801
|
+
// eslint-disable-next-line
|
|
28802
|
+
/^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
|
|
28803
|
+
|
|
28804
|
+
// eslint-disable-next-line
|
|
28805
|
+
let rUUID = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
28806
|
+
let yearMonthDay = '^\\d{4}-\\d{2}-\\d{2}';
|
|
28807
|
+
let hourMinuteSecond = '\\d{2}:\\d{2}:\\d{2}';
|
|
28808
|
+
let zOrOffset = '(([+-]\\d{2}(:?\\d{2})?)|Z)';
|
|
28809
|
+
let rIsoDateTime = new RegExp(`${yearMonthDay}T${hourMinuteSecond}(\\.\\d+)?${zOrOffset}$`);
|
|
28810
|
+
let isTrimmed = value => isAbsent(value) || value === value.trim();
|
|
28811
|
+
let objStringTag = {}.toString();
|
|
28812
|
+
function create$6() {
|
|
28813
|
+
return new StringSchema();
|
|
28814
|
+
}
|
|
28815
|
+
class StringSchema extends Schema {
|
|
28816
|
+
constructor() {
|
|
28817
|
+
super({
|
|
28818
|
+
type: 'string',
|
|
28819
|
+
check(value) {
|
|
28820
|
+
if (value instanceof String) value = value.valueOf();
|
|
28821
|
+
return typeof value === 'string';
|
|
28822
|
+
}
|
|
28823
|
+
});
|
|
28824
|
+
this.withMutation(() => {
|
|
28825
|
+
this.transform((value, _raw, ctx) => {
|
|
28826
|
+
if (!ctx.spec.coerce || ctx.isType(value)) return value;
|
|
28827
|
+
|
|
28828
|
+
// don't ever convert arrays
|
|
28829
|
+
if (Array.isArray(value)) return value;
|
|
28830
|
+
const strValue = value != null && value.toString ? value.toString() : value;
|
|
28831
|
+
|
|
28832
|
+
// no one wants plain objects converted to [Object object]
|
|
28833
|
+
if (strValue === objStringTag) return value;
|
|
28834
|
+
return strValue;
|
|
28835
|
+
});
|
|
28836
|
+
});
|
|
28837
|
+
}
|
|
28838
|
+
required(message) {
|
|
28839
|
+
return super.required(message).withMutation(schema => schema.test({
|
|
28840
|
+
message: message || mixed.required,
|
|
28841
|
+
name: 'required',
|
|
28842
|
+
skipAbsent: true,
|
|
28843
|
+
test: value => !!value.length
|
|
28844
|
+
}));
|
|
28845
|
+
}
|
|
28846
|
+
notRequired() {
|
|
28847
|
+
return super.notRequired().withMutation(schema => {
|
|
28848
|
+
schema.tests = schema.tests.filter(t => t.OPTIONS.name !== 'required');
|
|
28849
|
+
return schema;
|
|
28850
|
+
});
|
|
28851
|
+
}
|
|
28852
|
+
length(length, message = string.length) {
|
|
28853
|
+
return this.test({
|
|
28854
|
+
message,
|
|
28855
|
+
name: 'length',
|
|
28856
|
+
exclusive: true,
|
|
28857
|
+
params: {
|
|
28858
|
+
length
|
|
28859
|
+
},
|
|
28860
|
+
skipAbsent: true,
|
|
28861
|
+
test(value) {
|
|
28862
|
+
return value.length === this.resolve(length);
|
|
28863
|
+
}
|
|
28864
|
+
});
|
|
28865
|
+
}
|
|
28866
|
+
min(min, message = string.min) {
|
|
28867
|
+
return this.test({
|
|
28868
|
+
message,
|
|
28869
|
+
name: 'min',
|
|
28870
|
+
exclusive: true,
|
|
28871
|
+
params: {
|
|
28872
|
+
min
|
|
28873
|
+
},
|
|
28874
|
+
skipAbsent: true,
|
|
28875
|
+
test(value) {
|
|
28876
|
+
return value.length >= this.resolve(min);
|
|
28877
|
+
}
|
|
28878
|
+
});
|
|
28879
|
+
}
|
|
28880
|
+
max(max, message = string.max) {
|
|
28881
|
+
return this.test({
|
|
28882
|
+
name: 'max',
|
|
28883
|
+
exclusive: true,
|
|
28884
|
+
message,
|
|
28885
|
+
params: {
|
|
28886
|
+
max
|
|
28887
|
+
},
|
|
28888
|
+
skipAbsent: true,
|
|
28889
|
+
test(value) {
|
|
28890
|
+
return value.length <= this.resolve(max);
|
|
28891
|
+
}
|
|
28892
|
+
});
|
|
28893
|
+
}
|
|
28894
|
+
matches(regex, options) {
|
|
28895
|
+
let excludeEmptyString = false;
|
|
28896
|
+
let message;
|
|
28897
|
+
let name;
|
|
28898
|
+
if (options) {
|
|
28899
|
+
if (typeof options === 'object') {
|
|
28900
|
+
({
|
|
28901
|
+
excludeEmptyString = false,
|
|
28902
|
+
message,
|
|
28903
|
+
name
|
|
28904
|
+
} = options);
|
|
28905
|
+
} else {
|
|
28906
|
+
message = options;
|
|
28907
|
+
}
|
|
28908
|
+
}
|
|
28909
|
+
return this.test({
|
|
28910
|
+
name: name || 'matches',
|
|
28911
|
+
message: message || string.matches,
|
|
28912
|
+
params: {
|
|
28913
|
+
regex
|
|
28914
|
+
},
|
|
28915
|
+
skipAbsent: true,
|
|
28916
|
+
test: value => value === '' && excludeEmptyString || value.search(regex) !== -1
|
|
28917
|
+
});
|
|
28918
|
+
}
|
|
28919
|
+
email(message = string.email) {
|
|
28920
|
+
return this.matches(rEmail, {
|
|
28921
|
+
name: 'email',
|
|
28922
|
+
message,
|
|
28923
|
+
excludeEmptyString: true
|
|
28924
|
+
});
|
|
28925
|
+
}
|
|
28926
|
+
url(message = string.url) {
|
|
28927
|
+
return this.matches(rUrl, {
|
|
28928
|
+
name: 'url',
|
|
28929
|
+
message,
|
|
28930
|
+
excludeEmptyString: true
|
|
28931
|
+
});
|
|
28932
|
+
}
|
|
28933
|
+
uuid(message = string.uuid) {
|
|
28934
|
+
return this.matches(rUUID, {
|
|
28935
|
+
name: 'uuid',
|
|
28936
|
+
message,
|
|
28937
|
+
excludeEmptyString: false
|
|
28938
|
+
});
|
|
28939
|
+
}
|
|
28940
|
+
datetime(options) {
|
|
28941
|
+
let message = '';
|
|
28942
|
+
let allowOffset;
|
|
28943
|
+
let precision;
|
|
28944
|
+
if (options) {
|
|
28945
|
+
if (typeof options === 'object') {
|
|
28946
|
+
({
|
|
28947
|
+
message = '',
|
|
28948
|
+
allowOffset = false,
|
|
28949
|
+
precision = undefined
|
|
28950
|
+
} = options);
|
|
28951
|
+
} else {
|
|
28952
|
+
message = options;
|
|
28953
|
+
}
|
|
28954
|
+
}
|
|
28955
|
+
return this.matches(rIsoDateTime, {
|
|
28956
|
+
name: 'datetime',
|
|
28957
|
+
message: message || string.datetime,
|
|
28958
|
+
excludeEmptyString: true
|
|
28959
|
+
}).test({
|
|
28960
|
+
name: 'datetime_offset',
|
|
28961
|
+
message: message || string.datetime_offset,
|
|
28962
|
+
params: {
|
|
28963
|
+
allowOffset
|
|
28964
|
+
},
|
|
28965
|
+
skipAbsent: true,
|
|
28966
|
+
test: value => {
|
|
28967
|
+
if (!value || allowOffset) return true;
|
|
28968
|
+
const struct = parseDateStruct(value);
|
|
28969
|
+
if (!struct) return false;
|
|
28970
|
+
return !!struct.z;
|
|
28971
|
+
}
|
|
28972
|
+
}).test({
|
|
28973
|
+
name: 'datetime_precision',
|
|
28974
|
+
message: message || string.datetime_precision,
|
|
28975
|
+
params: {
|
|
28976
|
+
precision
|
|
28977
|
+
},
|
|
28978
|
+
skipAbsent: true,
|
|
28979
|
+
test: value => {
|
|
28980
|
+
if (!value || precision == undefined) return true;
|
|
28981
|
+
const struct = parseDateStruct(value);
|
|
28982
|
+
if (!struct) return false;
|
|
28983
|
+
return struct.precision === precision;
|
|
28984
|
+
}
|
|
28985
|
+
});
|
|
28986
|
+
}
|
|
28987
|
+
|
|
28988
|
+
//-- transforms --
|
|
28989
|
+
ensure() {
|
|
28990
|
+
return this.default('').transform(val => val === null ? '' : val);
|
|
28991
|
+
}
|
|
28992
|
+
trim(message = string.trim) {
|
|
28993
|
+
return this.transform(val => val != null ? val.trim() : val).test({
|
|
28994
|
+
message,
|
|
28995
|
+
name: 'trim',
|
|
28996
|
+
test: isTrimmed
|
|
28997
|
+
});
|
|
28998
|
+
}
|
|
28999
|
+
lowercase(message = string.lowercase) {
|
|
29000
|
+
return this.transform(value => !isAbsent(value) ? value.toLowerCase() : value).test({
|
|
29001
|
+
message,
|
|
29002
|
+
name: 'string_case',
|
|
29003
|
+
exclusive: true,
|
|
29004
|
+
skipAbsent: true,
|
|
29005
|
+
test: value => isAbsent(value) || value === value.toLowerCase()
|
|
29006
|
+
});
|
|
29007
|
+
}
|
|
29008
|
+
uppercase(message = string.uppercase) {
|
|
29009
|
+
return this.transform(value => !isAbsent(value) ? value.toUpperCase() : value).test({
|
|
29010
|
+
message,
|
|
29011
|
+
name: 'string_case',
|
|
29012
|
+
exclusive: true,
|
|
29013
|
+
skipAbsent: true,
|
|
29014
|
+
test: value => isAbsent(value) || value === value.toUpperCase()
|
|
29015
|
+
});
|
|
29016
|
+
}
|
|
29017
|
+
}
|
|
29018
|
+
create$6.prototype = StringSchema.prototype;
|
|
29019
|
+
|
|
29020
|
+
//
|
|
29021
|
+
// String Interfaces
|
|
29022
|
+
//
|
|
29023
|
+
|
|
29024
|
+
let isNaN$1 = value => value != +value;
|
|
29025
|
+
function create$5() {
|
|
29026
|
+
return new NumberSchema();
|
|
29027
|
+
}
|
|
29028
|
+
class NumberSchema extends Schema {
|
|
29029
|
+
constructor() {
|
|
29030
|
+
super({
|
|
29031
|
+
type: 'number',
|
|
29032
|
+
check(value) {
|
|
29033
|
+
if (value instanceof Number) value = value.valueOf();
|
|
29034
|
+
return typeof value === 'number' && !isNaN$1(value);
|
|
29035
|
+
}
|
|
29036
|
+
});
|
|
29037
|
+
this.withMutation(() => {
|
|
29038
|
+
this.transform((value, _raw, ctx) => {
|
|
29039
|
+
if (!ctx.spec.coerce) return value;
|
|
29040
|
+
let parsed = value;
|
|
29041
|
+
if (typeof parsed === 'string') {
|
|
29042
|
+
parsed = parsed.replace(/\s/g, '');
|
|
29043
|
+
if (parsed === '') return NaN;
|
|
29044
|
+
// don't use parseFloat to avoid positives on alpha-numeric strings
|
|
29045
|
+
parsed = +parsed;
|
|
29046
|
+
}
|
|
29047
|
+
|
|
29048
|
+
// null -> NaN isn't useful; treat all nulls as null and let it fail on
|
|
29049
|
+
// nullability check vs TypeErrors
|
|
29050
|
+
if (ctx.isType(parsed) || parsed === null) return parsed;
|
|
29051
|
+
return parseFloat(parsed);
|
|
29052
|
+
});
|
|
29053
|
+
});
|
|
29054
|
+
}
|
|
29055
|
+
min(min, message = number.min) {
|
|
29056
|
+
return this.test({
|
|
29057
|
+
message,
|
|
29058
|
+
name: 'min',
|
|
29059
|
+
exclusive: true,
|
|
29060
|
+
params: {
|
|
29061
|
+
min
|
|
29062
|
+
},
|
|
29063
|
+
skipAbsent: true,
|
|
29064
|
+
test(value) {
|
|
29065
|
+
return value >= this.resolve(min);
|
|
29066
|
+
}
|
|
29067
|
+
});
|
|
29068
|
+
}
|
|
29069
|
+
max(max, message = number.max) {
|
|
29070
|
+
return this.test({
|
|
29071
|
+
message,
|
|
29072
|
+
name: 'max',
|
|
29073
|
+
exclusive: true,
|
|
29074
|
+
params: {
|
|
29075
|
+
max
|
|
29076
|
+
},
|
|
29077
|
+
skipAbsent: true,
|
|
29078
|
+
test(value) {
|
|
29079
|
+
return value <= this.resolve(max);
|
|
29080
|
+
}
|
|
29081
|
+
});
|
|
29082
|
+
}
|
|
29083
|
+
lessThan(less, message = number.lessThan) {
|
|
29084
|
+
return this.test({
|
|
29085
|
+
message,
|
|
29086
|
+
name: 'max',
|
|
29087
|
+
exclusive: true,
|
|
29088
|
+
params: {
|
|
29089
|
+
less
|
|
29090
|
+
},
|
|
29091
|
+
skipAbsent: true,
|
|
29092
|
+
test(value) {
|
|
29093
|
+
return value < this.resolve(less);
|
|
29094
|
+
}
|
|
29095
|
+
});
|
|
29096
|
+
}
|
|
29097
|
+
moreThan(more, message = number.moreThan) {
|
|
29098
|
+
return this.test({
|
|
29099
|
+
message,
|
|
29100
|
+
name: 'min',
|
|
29101
|
+
exclusive: true,
|
|
29102
|
+
params: {
|
|
29103
|
+
more
|
|
29104
|
+
},
|
|
29105
|
+
skipAbsent: true,
|
|
29106
|
+
test(value) {
|
|
29107
|
+
return value > this.resolve(more);
|
|
29108
|
+
}
|
|
29109
|
+
});
|
|
29110
|
+
}
|
|
29111
|
+
positive(msg = number.positive) {
|
|
29112
|
+
return this.moreThan(0, msg);
|
|
29113
|
+
}
|
|
29114
|
+
negative(msg = number.negative) {
|
|
29115
|
+
return this.lessThan(0, msg);
|
|
29116
|
+
}
|
|
29117
|
+
integer(message = number.integer) {
|
|
29118
|
+
return this.test({
|
|
29119
|
+
name: 'integer',
|
|
29120
|
+
message,
|
|
29121
|
+
skipAbsent: true,
|
|
29122
|
+
test: val => Number.isInteger(val)
|
|
29123
|
+
});
|
|
29124
|
+
}
|
|
29125
|
+
truncate() {
|
|
29126
|
+
return this.transform(value => !isAbsent(value) ? value | 0 : value);
|
|
29127
|
+
}
|
|
29128
|
+
round(method) {
|
|
29129
|
+
var _method;
|
|
29130
|
+
let avail = ['ceil', 'floor', 'round', 'trunc'];
|
|
29131
|
+
method = ((_method = method) == null ? void 0 : _method.toLowerCase()) || 'round';
|
|
29132
|
+
|
|
29133
|
+
// this exists for symemtry with the new Math.trunc
|
|
29134
|
+
if (method === 'trunc') return this.truncate();
|
|
29135
|
+
if (avail.indexOf(method.toLowerCase()) === -1) throw new TypeError('Only valid options for round() are: ' + avail.join(', '));
|
|
29136
|
+
return this.transform(value => !isAbsent(value) ? Math[method](value) : value);
|
|
29137
|
+
}
|
|
29138
|
+
}
|
|
29139
|
+
create$5.prototype = NumberSchema.prototype;
|
|
29140
|
+
|
|
29141
|
+
//
|
|
29142
|
+
// Number Interfaces
|
|
29143
|
+
//
|
|
29144
|
+
|
|
29145
|
+
let invalidDate = new Date('');
|
|
29146
|
+
let isDate = obj => Object.prototype.toString.call(obj) === '[object Date]';
|
|
29147
|
+
function create$4() {
|
|
29148
|
+
return new DateSchema();
|
|
29149
|
+
}
|
|
29150
|
+
class DateSchema extends Schema {
|
|
29151
|
+
constructor() {
|
|
29152
|
+
super({
|
|
29153
|
+
type: 'date',
|
|
29154
|
+
check(v) {
|
|
29155
|
+
return isDate(v) && !isNaN(v.getTime());
|
|
29156
|
+
}
|
|
29157
|
+
});
|
|
29158
|
+
this.withMutation(() => {
|
|
29159
|
+
this.transform((value, _raw, ctx) => {
|
|
29160
|
+
// null -> InvalidDate isn't useful; treat all nulls as null and let it fail on
|
|
29161
|
+
// nullability check vs TypeErrors
|
|
29162
|
+
if (!ctx.spec.coerce || ctx.isType(value) || value === null) return value;
|
|
29163
|
+
value = parseIsoDate(value);
|
|
29164
|
+
|
|
29165
|
+
// 0 is a valid timestamp equivalent to 1970-01-01T00:00:00Z(unix epoch) or before.
|
|
29166
|
+
return !isNaN(value) ? new Date(value) : DateSchema.INVALID_DATE;
|
|
29167
|
+
});
|
|
29168
|
+
});
|
|
29169
|
+
}
|
|
29170
|
+
prepareParam(ref, name) {
|
|
29171
|
+
let param;
|
|
29172
|
+
if (!Reference.isRef(ref)) {
|
|
29173
|
+
let cast = this.cast(ref);
|
|
29174
|
+
if (!this._typeCheck(cast)) throw new TypeError(`\`${name}\` must be a Date or a value that can be \`cast()\` to a Date`);
|
|
29175
|
+
param = cast;
|
|
29176
|
+
} else {
|
|
29177
|
+
param = ref;
|
|
29178
|
+
}
|
|
29179
|
+
return param;
|
|
29180
|
+
}
|
|
29181
|
+
min(min, message = date.min) {
|
|
29182
|
+
let limit = this.prepareParam(min, 'min');
|
|
29183
|
+
return this.test({
|
|
29184
|
+
message,
|
|
29185
|
+
name: 'min',
|
|
29186
|
+
exclusive: true,
|
|
29187
|
+
params: {
|
|
29188
|
+
min
|
|
29189
|
+
},
|
|
29190
|
+
skipAbsent: true,
|
|
29191
|
+
test(value) {
|
|
29192
|
+
return value >= this.resolve(limit);
|
|
29193
|
+
}
|
|
29194
|
+
});
|
|
29195
|
+
}
|
|
29196
|
+
max(max, message = date.max) {
|
|
29197
|
+
let limit = this.prepareParam(max, 'max');
|
|
29198
|
+
return this.test({
|
|
29199
|
+
message,
|
|
29200
|
+
name: 'max',
|
|
29201
|
+
exclusive: true,
|
|
29202
|
+
params: {
|
|
29203
|
+
max
|
|
29204
|
+
},
|
|
29205
|
+
skipAbsent: true,
|
|
29206
|
+
test(value) {
|
|
29207
|
+
return value <= this.resolve(limit);
|
|
29208
|
+
}
|
|
29209
|
+
});
|
|
29210
|
+
}
|
|
29211
|
+
}
|
|
29212
|
+
DateSchema.INVALID_DATE = invalidDate;
|
|
29213
|
+
create$4.prototype = DateSchema.prototype;
|
|
29214
|
+
create$4.INVALID_DATE = invalidDate;
|
|
29215
|
+
|
|
29216
|
+
// @ts-expect-error
|
|
29217
|
+
function sortFields(fields, excludedEdges = []) {
|
|
29218
|
+
let edges = [];
|
|
29219
|
+
let nodes = new Set();
|
|
29220
|
+
let excludes = new Set(excludedEdges.map(([a, b]) => `${a}-${b}`));
|
|
29221
|
+
function addNode(depPath, key) {
|
|
29222
|
+
let node = propertyExprExports.split(depPath)[0];
|
|
29223
|
+
nodes.add(node);
|
|
29224
|
+
if (!excludes.has(`${key}-${node}`)) edges.push([key, node]);
|
|
29225
|
+
}
|
|
29226
|
+
for (const key of Object.keys(fields)) {
|
|
29227
|
+
let value = fields[key];
|
|
29228
|
+
nodes.add(key);
|
|
29229
|
+
if (Reference.isRef(value) && value.isSibling) addNode(value.path, key);else if (isSchema(value) && 'deps' in value) value.deps.forEach(path => addNode(path, key));
|
|
29230
|
+
}
|
|
29231
|
+
return toposort.array(Array.from(nodes), edges).reverse();
|
|
29232
|
+
}
|
|
29233
|
+
|
|
29234
|
+
function findIndex(arr, err) {
|
|
29235
|
+
let idx = Infinity;
|
|
29236
|
+
arr.some((key, ii) => {
|
|
29237
|
+
var _err$path;
|
|
29238
|
+
if ((_err$path = err.path) != null && _err$path.includes(key)) {
|
|
29239
|
+
idx = ii;
|
|
29240
|
+
return true;
|
|
29241
|
+
}
|
|
29242
|
+
});
|
|
29243
|
+
return idx;
|
|
29244
|
+
}
|
|
29245
|
+
function sortByKeyOrder(keys) {
|
|
29246
|
+
return (a, b) => {
|
|
29247
|
+
return findIndex(keys, a) - findIndex(keys, b);
|
|
29248
|
+
};
|
|
29249
|
+
}
|
|
29250
|
+
|
|
29251
|
+
const parseJson = (value, _, ctx) => {
|
|
29252
|
+
if (typeof value !== 'string') {
|
|
29253
|
+
return value;
|
|
29254
|
+
}
|
|
29255
|
+
let parsed = value;
|
|
29256
|
+
try {
|
|
29257
|
+
parsed = JSON.parse(value);
|
|
29258
|
+
} catch (err) {
|
|
29259
|
+
/* */
|
|
29260
|
+
}
|
|
29261
|
+
return ctx.isType(parsed) ? parsed : value;
|
|
29262
|
+
};
|
|
29263
|
+
|
|
29264
|
+
// @ts-ignore
|
|
29265
|
+
function deepPartial(schema) {
|
|
29266
|
+
if ('fields' in schema) {
|
|
29267
|
+
const partial = {};
|
|
29268
|
+
for (const [key, fieldSchema] of Object.entries(schema.fields)) {
|
|
29269
|
+
partial[key] = deepPartial(fieldSchema);
|
|
29270
|
+
}
|
|
29271
|
+
return schema.setFields(partial);
|
|
29272
|
+
}
|
|
29273
|
+
if (schema.type === 'array') {
|
|
29274
|
+
const nextArray = schema.optional();
|
|
29275
|
+
if (nextArray.innerType) nextArray.innerType = deepPartial(nextArray.innerType);
|
|
29276
|
+
return nextArray;
|
|
29277
|
+
}
|
|
29278
|
+
if (schema.type === 'tuple') {
|
|
29279
|
+
return schema.optional().clone({
|
|
29280
|
+
types: schema.spec.types.map(deepPartial)
|
|
29281
|
+
});
|
|
29282
|
+
}
|
|
29283
|
+
if ('optional' in schema) {
|
|
29284
|
+
return schema.optional();
|
|
29285
|
+
}
|
|
29286
|
+
return schema;
|
|
29287
|
+
}
|
|
29288
|
+
const deepHas = (obj, p) => {
|
|
29289
|
+
const path = [...propertyExprExports.normalizePath(p)];
|
|
29290
|
+
if (path.length === 1) return path[0] in obj;
|
|
29291
|
+
let last = path.pop();
|
|
29292
|
+
let parent = propertyExprExports.getter(propertyExprExports.join(path), true)(obj);
|
|
29293
|
+
return !!(parent && last in parent);
|
|
29294
|
+
};
|
|
29295
|
+
let isObject = obj => Object.prototype.toString.call(obj) === '[object Object]';
|
|
29296
|
+
function unknown(ctx, value) {
|
|
29297
|
+
let known = Object.keys(ctx.fields);
|
|
29298
|
+
return Object.keys(value).filter(key => known.indexOf(key) === -1);
|
|
29299
|
+
}
|
|
29300
|
+
const defaultSort = sortByKeyOrder([]);
|
|
29301
|
+
function create$3(spec) {
|
|
29302
|
+
return new ObjectSchema(spec);
|
|
29303
|
+
}
|
|
29304
|
+
class ObjectSchema extends Schema {
|
|
29305
|
+
constructor(spec) {
|
|
29306
|
+
super({
|
|
29307
|
+
type: 'object',
|
|
29308
|
+
check(value) {
|
|
29309
|
+
return isObject(value) || typeof value === 'function';
|
|
29310
|
+
}
|
|
29311
|
+
});
|
|
29312
|
+
this.fields = Object.create(null);
|
|
29313
|
+
this._sortErrors = defaultSort;
|
|
29314
|
+
this._nodes = [];
|
|
29315
|
+
this._excludedEdges = [];
|
|
29316
|
+
this.withMutation(() => {
|
|
29317
|
+
if (spec) {
|
|
29318
|
+
this.shape(spec);
|
|
29319
|
+
}
|
|
29320
|
+
});
|
|
29321
|
+
}
|
|
29322
|
+
_cast(_value, options = {}) {
|
|
29323
|
+
var _options$stripUnknown;
|
|
29324
|
+
let value = super._cast(_value, options);
|
|
29325
|
+
|
|
29326
|
+
//should ignore nulls here
|
|
29327
|
+
if (value === undefined) return this.getDefault(options);
|
|
29328
|
+
if (!this._typeCheck(value)) return value;
|
|
29329
|
+
let fields = this.fields;
|
|
29330
|
+
let strip = (_options$stripUnknown = options.stripUnknown) != null ? _options$stripUnknown : this.spec.noUnknown;
|
|
29331
|
+
let props = [].concat(this._nodes, Object.keys(value).filter(v => !this._nodes.includes(v)));
|
|
29332
|
+
let intermediateValue = {}; // is filled during the transform below
|
|
29333
|
+
let innerOptions = Object.assign({}, options, {
|
|
29334
|
+
parent: intermediateValue,
|
|
29335
|
+
__validating: options.__validating || false
|
|
29336
|
+
});
|
|
29337
|
+
let isChanged = false;
|
|
29338
|
+
for (const prop of props) {
|
|
29339
|
+
let field = fields[prop];
|
|
29340
|
+
let exists = (prop in value);
|
|
29341
|
+
if (field) {
|
|
29342
|
+
let fieldValue;
|
|
29343
|
+
let inputValue = value[prop];
|
|
29344
|
+
|
|
29345
|
+
// safe to mutate since this is fired in sequence
|
|
29346
|
+
innerOptions.path = (options.path ? `${options.path}.` : '') + prop;
|
|
29347
|
+
field = field.resolve({
|
|
29348
|
+
value: inputValue,
|
|
29349
|
+
context: options.context,
|
|
29350
|
+
parent: intermediateValue
|
|
29351
|
+
});
|
|
29352
|
+
let fieldSpec = field instanceof Schema ? field.spec : undefined;
|
|
29353
|
+
let strict = fieldSpec == null ? void 0 : fieldSpec.strict;
|
|
29354
|
+
if (fieldSpec != null && fieldSpec.strip) {
|
|
29355
|
+
isChanged = isChanged || prop in value;
|
|
29356
|
+
continue;
|
|
29357
|
+
}
|
|
29358
|
+
fieldValue = !options.__validating || !strict ?
|
|
29359
|
+
// TODO: use _cast, this is double resolving
|
|
29360
|
+
field.cast(value[prop], innerOptions) : value[prop];
|
|
29361
|
+
if (fieldValue !== undefined) {
|
|
29362
|
+
intermediateValue[prop] = fieldValue;
|
|
29363
|
+
}
|
|
29364
|
+
} else if (exists && !strip) {
|
|
29365
|
+
intermediateValue[prop] = value[prop];
|
|
29366
|
+
}
|
|
29367
|
+
if (exists !== prop in intermediateValue || intermediateValue[prop] !== value[prop]) {
|
|
29368
|
+
isChanged = true;
|
|
29369
|
+
}
|
|
29370
|
+
}
|
|
29371
|
+
return isChanged ? intermediateValue : value;
|
|
29372
|
+
}
|
|
29373
|
+
_validate(_value, options = {}, panic, next) {
|
|
29374
|
+
let {
|
|
29375
|
+
from = [],
|
|
29376
|
+
originalValue = _value,
|
|
29377
|
+
recursive = this.spec.recursive
|
|
29378
|
+
} = options;
|
|
29379
|
+
options.from = [{
|
|
29380
|
+
schema: this,
|
|
29381
|
+
value: originalValue
|
|
29382
|
+
}, ...from];
|
|
29383
|
+
// this flag is needed for handling `strict` correctly in the context of
|
|
29384
|
+
// validation vs just casting. e.g strict() on a field is only used when validating
|
|
29385
|
+
options.__validating = true;
|
|
29386
|
+
options.originalValue = originalValue;
|
|
29387
|
+
super._validate(_value, options, panic, (objectErrors, value) => {
|
|
29388
|
+
if (!recursive || !isObject(value)) {
|
|
29389
|
+
next(objectErrors, value);
|
|
29390
|
+
return;
|
|
29391
|
+
}
|
|
29392
|
+
originalValue = originalValue || value;
|
|
29393
|
+
let tests = [];
|
|
29394
|
+
for (let key of this._nodes) {
|
|
29395
|
+
let field = this.fields[key];
|
|
29396
|
+
if (!field || Reference.isRef(field)) {
|
|
29397
|
+
continue;
|
|
29398
|
+
}
|
|
29399
|
+
tests.push(field.asNestedTest({
|
|
29400
|
+
options,
|
|
29401
|
+
key,
|
|
29402
|
+
parent: value,
|
|
29403
|
+
parentPath: options.path,
|
|
29404
|
+
originalParent: originalValue
|
|
29405
|
+
}));
|
|
29406
|
+
}
|
|
29407
|
+
this.runTests({
|
|
29408
|
+
tests,
|
|
29409
|
+
value,
|
|
29410
|
+
originalValue,
|
|
29411
|
+
options
|
|
29412
|
+
}, panic, fieldErrors => {
|
|
29413
|
+
next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value);
|
|
29414
|
+
});
|
|
29415
|
+
});
|
|
29416
|
+
}
|
|
29417
|
+
clone(spec) {
|
|
29418
|
+
const next = super.clone(spec);
|
|
29419
|
+
next.fields = Object.assign({}, this.fields);
|
|
29420
|
+
next._nodes = this._nodes;
|
|
29421
|
+
next._excludedEdges = this._excludedEdges;
|
|
29422
|
+
next._sortErrors = this._sortErrors;
|
|
29423
|
+
return next;
|
|
29424
|
+
}
|
|
29425
|
+
concat(schema) {
|
|
29426
|
+
let next = super.concat(schema);
|
|
29427
|
+
let nextFields = next.fields;
|
|
29428
|
+
for (let [field, schemaOrRef] of Object.entries(this.fields)) {
|
|
29429
|
+
const target = nextFields[field];
|
|
29430
|
+
nextFields[field] = target === undefined ? schemaOrRef : target;
|
|
29431
|
+
}
|
|
29432
|
+
return next.withMutation(s =>
|
|
29433
|
+
// XXX: excludes here is wrong
|
|
29434
|
+
s.setFields(nextFields, [...this._excludedEdges, ...schema._excludedEdges]));
|
|
29435
|
+
}
|
|
29436
|
+
_getDefault(options) {
|
|
29437
|
+
if ('default' in this.spec) {
|
|
29438
|
+
return super._getDefault(options);
|
|
29439
|
+
}
|
|
29440
|
+
|
|
29441
|
+
// if there is no default set invent one
|
|
29442
|
+
if (!this._nodes.length) {
|
|
29443
|
+
return undefined;
|
|
29444
|
+
}
|
|
29445
|
+
let dft = {};
|
|
29446
|
+
this._nodes.forEach(key => {
|
|
29447
|
+
var _innerOptions;
|
|
29448
|
+
const field = this.fields[key];
|
|
29449
|
+
let innerOptions = options;
|
|
29450
|
+
if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
|
|
29451
|
+
innerOptions = Object.assign({}, innerOptions, {
|
|
29452
|
+
parent: innerOptions.value,
|
|
29453
|
+
value: innerOptions.value[key]
|
|
29454
|
+
});
|
|
29455
|
+
}
|
|
29456
|
+
dft[key] = field && 'getDefault' in field ? field.getDefault(innerOptions) : undefined;
|
|
29457
|
+
});
|
|
29458
|
+
return dft;
|
|
29459
|
+
}
|
|
29460
|
+
setFields(shape, excludedEdges) {
|
|
29461
|
+
let next = this.clone();
|
|
29462
|
+
next.fields = shape;
|
|
29463
|
+
next._nodes = sortFields(shape, excludedEdges);
|
|
29464
|
+
next._sortErrors = sortByKeyOrder(Object.keys(shape));
|
|
29465
|
+
// XXX: this carries over edges which may not be what you want
|
|
29466
|
+
if (excludedEdges) next._excludedEdges = excludedEdges;
|
|
29467
|
+
return next;
|
|
29468
|
+
}
|
|
29469
|
+
shape(additions, excludes = []) {
|
|
29470
|
+
return this.clone().withMutation(next => {
|
|
29471
|
+
let edges = next._excludedEdges;
|
|
29472
|
+
if (excludes.length) {
|
|
29473
|
+
if (!Array.isArray(excludes[0])) excludes = [excludes];
|
|
29474
|
+
edges = [...next._excludedEdges, ...excludes];
|
|
29475
|
+
}
|
|
29476
|
+
|
|
29477
|
+
// XXX: excludes here is wrong
|
|
29478
|
+
return next.setFields(Object.assign(next.fields, additions), edges);
|
|
29479
|
+
});
|
|
29480
|
+
}
|
|
29481
|
+
partial() {
|
|
29482
|
+
const partial = {};
|
|
29483
|
+
for (const [key, schema] of Object.entries(this.fields)) {
|
|
29484
|
+
partial[key] = 'optional' in schema && schema.optional instanceof Function ? schema.optional() : schema;
|
|
29485
|
+
}
|
|
29486
|
+
return this.setFields(partial);
|
|
29487
|
+
}
|
|
29488
|
+
deepPartial() {
|
|
29489
|
+
const next = deepPartial(this);
|
|
29490
|
+
return next;
|
|
29491
|
+
}
|
|
29492
|
+
pick(keys) {
|
|
29493
|
+
const picked = {};
|
|
29494
|
+
for (const key of keys) {
|
|
29495
|
+
if (this.fields[key]) picked[key] = this.fields[key];
|
|
29496
|
+
}
|
|
29497
|
+
return this.setFields(picked, this._excludedEdges.filter(([a, b]) => keys.includes(a) && keys.includes(b)));
|
|
29498
|
+
}
|
|
29499
|
+
omit(keys) {
|
|
29500
|
+
const remaining = [];
|
|
29501
|
+
for (const key of Object.keys(this.fields)) {
|
|
29502
|
+
if (keys.includes(key)) continue;
|
|
29503
|
+
remaining.push(key);
|
|
29504
|
+
}
|
|
29505
|
+
return this.pick(remaining);
|
|
29506
|
+
}
|
|
29507
|
+
from(from, to, alias) {
|
|
29508
|
+
let fromGetter = propertyExprExports.getter(from, true);
|
|
29509
|
+
return this.transform(obj => {
|
|
29510
|
+
if (!obj) return obj;
|
|
29511
|
+
let newObj = obj;
|
|
29512
|
+
if (deepHas(obj, from)) {
|
|
29513
|
+
newObj = Object.assign({}, obj);
|
|
29514
|
+
if (!alias) delete newObj[from];
|
|
29515
|
+
newObj[to] = fromGetter(obj);
|
|
29516
|
+
}
|
|
29517
|
+
return newObj;
|
|
29518
|
+
});
|
|
29519
|
+
}
|
|
29520
|
+
|
|
29521
|
+
/** Parse an input JSON string to an object */
|
|
29522
|
+
json() {
|
|
29523
|
+
return this.transform(parseJson);
|
|
29524
|
+
}
|
|
29525
|
+
noUnknown(noAllow = true, message = object.noUnknown) {
|
|
29526
|
+
if (typeof noAllow !== 'boolean') {
|
|
29527
|
+
message = noAllow;
|
|
29528
|
+
noAllow = true;
|
|
29529
|
+
}
|
|
29530
|
+
let next = this.test({
|
|
29531
|
+
name: 'noUnknown',
|
|
29532
|
+
exclusive: true,
|
|
29533
|
+
message: message,
|
|
29534
|
+
test(value) {
|
|
29535
|
+
if (value == null) return true;
|
|
29536
|
+
const unknownKeys = unknown(this.schema, value);
|
|
29537
|
+
return !noAllow || unknownKeys.length === 0 || this.createError({
|
|
29538
|
+
params: {
|
|
29539
|
+
unknown: unknownKeys.join(', ')
|
|
29540
|
+
}
|
|
29541
|
+
});
|
|
29542
|
+
}
|
|
29543
|
+
});
|
|
29544
|
+
next.spec.noUnknown = noAllow;
|
|
29545
|
+
return next;
|
|
29546
|
+
}
|
|
29547
|
+
unknown(allow = true, message = object.noUnknown) {
|
|
29548
|
+
return this.noUnknown(!allow, message);
|
|
29549
|
+
}
|
|
29550
|
+
transformKeys(fn) {
|
|
29551
|
+
return this.transform(obj => {
|
|
29552
|
+
if (!obj) return obj;
|
|
29553
|
+
const result = {};
|
|
29554
|
+
for (const key of Object.keys(obj)) result[fn(key)] = obj[key];
|
|
29555
|
+
return result;
|
|
29556
|
+
});
|
|
29557
|
+
}
|
|
29558
|
+
camelCase() {
|
|
29559
|
+
return this.transformKeys(tinyCaseExports.camelCase);
|
|
29560
|
+
}
|
|
29561
|
+
snakeCase() {
|
|
29562
|
+
return this.transformKeys(tinyCaseExports.snakeCase);
|
|
29563
|
+
}
|
|
29564
|
+
constantCase() {
|
|
29565
|
+
return this.transformKeys(key => tinyCaseExports.snakeCase(key).toUpperCase());
|
|
29566
|
+
}
|
|
29567
|
+
describe(options) {
|
|
29568
|
+
const next = (options ? this.resolve(options) : this).clone();
|
|
29569
|
+
const base = super.describe(options);
|
|
29570
|
+
base.fields = {};
|
|
29571
|
+
for (const [key, value] of Object.entries(next.fields)) {
|
|
29572
|
+
var _innerOptions2;
|
|
29573
|
+
let innerOptions = options;
|
|
29574
|
+
if ((_innerOptions2 = innerOptions) != null && _innerOptions2.value) {
|
|
29575
|
+
innerOptions = Object.assign({}, innerOptions, {
|
|
29576
|
+
parent: innerOptions.value,
|
|
29577
|
+
value: innerOptions.value[key]
|
|
29578
|
+
});
|
|
29579
|
+
}
|
|
29580
|
+
base.fields[key] = value.describe(innerOptions);
|
|
29581
|
+
}
|
|
29582
|
+
return base;
|
|
29583
|
+
}
|
|
29584
|
+
}
|
|
29585
|
+
create$3.prototype = ObjectSchema.prototype;
|
|
29586
|
+
|
|
29587
|
+
function create$2(type) {
|
|
29588
|
+
return new ArraySchema(type);
|
|
29589
|
+
}
|
|
29590
|
+
class ArraySchema extends Schema {
|
|
29591
|
+
constructor(type) {
|
|
29592
|
+
super({
|
|
29593
|
+
type: 'array',
|
|
29594
|
+
spec: {
|
|
29595
|
+
types: type
|
|
29596
|
+
},
|
|
29597
|
+
check(v) {
|
|
29598
|
+
return Array.isArray(v);
|
|
29599
|
+
}
|
|
29600
|
+
});
|
|
29601
|
+
|
|
29602
|
+
// `undefined` specifically means uninitialized, as opposed to "no subtype"
|
|
29603
|
+
this.innerType = void 0;
|
|
29604
|
+
this.innerType = type;
|
|
29605
|
+
}
|
|
29606
|
+
_cast(_value, _opts) {
|
|
29607
|
+
const value = super._cast(_value, _opts);
|
|
29608
|
+
|
|
29609
|
+
// should ignore nulls here
|
|
29610
|
+
if (!this._typeCheck(value) || !this.innerType) {
|
|
29611
|
+
return value;
|
|
29612
|
+
}
|
|
29613
|
+
let isChanged = false;
|
|
29614
|
+
const castArray = value.map((v, idx) => {
|
|
29615
|
+
const castElement = this.innerType.cast(v, Object.assign({}, _opts, {
|
|
29616
|
+
path: `${_opts.path || ''}[${idx}]`
|
|
29617
|
+
}));
|
|
29618
|
+
if (castElement !== v) {
|
|
29619
|
+
isChanged = true;
|
|
29620
|
+
}
|
|
29621
|
+
return castElement;
|
|
29622
|
+
});
|
|
29623
|
+
return isChanged ? castArray : value;
|
|
29624
|
+
}
|
|
29625
|
+
_validate(_value, options = {}, panic, next) {
|
|
29626
|
+
var _options$recursive;
|
|
29627
|
+
// let sync = options.sync;
|
|
29628
|
+
// let path = options.path;
|
|
29629
|
+
let innerType = this.innerType;
|
|
29630
|
+
// let endEarly = options.abortEarly ?? this.spec.abortEarly;
|
|
29631
|
+
let recursive = (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive;
|
|
29632
|
+
options.originalValue != null ? options.originalValue : _value;
|
|
29633
|
+
super._validate(_value, options, panic, (arrayErrors, value) => {
|
|
29634
|
+
var _options$originalValu2;
|
|
29635
|
+
if (!recursive || !innerType || !this._typeCheck(value)) {
|
|
29636
|
+
next(arrayErrors, value);
|
|
29637
|
+
return;
|
|
29638
|
+
}
|
|
29639
|
+
|
|
29640
|
+
// #950 Ensure that sparse array empty slots are validated
|
|
29641
|
+
let tests = new Array(value.length);
|
|
29642
|
+
for (let index = 0; index < value.length; index++) {
|
|
29643
|
+
var _options$originalValu;
|
|
29644
|
+
tests[index] = innerType.asNestedTest({
|
|
29645
|
+
options,
|
|
29646
|
+
index,
|
|
29647
|
+
parent: value,
|
|
29648
|
+
parentPath: options.path,
|
|
29649
|
+
originalParent: (_options$originalValu = options.originalValue) != null ? _options$originalValu : _value
|
|
29650
|
+
});
|
|
29651
|
+
}
|
|
29652
|
+
this.runTests({
|
|
29653
|
+
value,
|
|
29654
|
+
tests,
|
|
29655
|
+
originalValue: (_options$originalValu2 = options.originalValue) != null ? _options$originalValu2 : _value,
|
|
29656
|
+
options
|
|
29657
|
+
}, panic, innerTypeErrors => next(innerTypeErrors.concat(arrayErrors), value));
|
|
29658
|
+
});
|
|
29659
|
+
}
|
|
29660
|
+
clone(spec) {
|
|
29661
|
+
const next = super.clone(spec);
|
|
29662
|
+
// @ts-expect-error readonly
|
|
29663
|
+
next.innerType = this.innerType;
|
|
29664
|
+
return next;
|
|
29665
|
+
}
|
|
29666
|
+
|
|
29667
|
+
/** Parse an input JSON string to an object */
|
|
29668
|
+
json() {
|
|
29669
|
+
return this.transform(parseJson);
|
|
29670
|
+
}
|
|
29671
|
+
concat(schema) {
|
|
29672
|
+
let next = super.concat(schema);
|
|
29673
|
+
|
|
29674
|
+
// @ts-expect-error readonly
|
|
29675
|
+
next.innerType = this.innerType;
|
|
29676
|
+
if (schema.innerType)
|
|
29677
|
+
// @ts-expect-error readonly
|
|
29678
|
+
next.innerType = next.innerType ?
|
|
29679
|
+
// @ts-expect-error Lazy doesn't have concat and will break
|
|
29680
|
+
next.innerType.concat(schema.innerType) : schema.innerType;
|
|
29681
|
+
return next;
|
|
29682
|
+
}
|
|
29683
|
+
of(schema) {
|
|
29684
|
+
// FIXME: this should return a new instance of array without the default to be
|
|
29685
|
+
let next = this.clone();
|
|
29686
|
+
if (!isSchema(schema)) throw new TypeError('`array.of()` sub-schema must be a valid yup schema not: ' + printValue(schema));
|
|
29687
|
+
|
|
29688
|
+
// @ts-expect-error readonly
|
|
29689
|
+
next.innerType = schema;
|
|
29690
|
+
next.spec = Object.assign({}, next.spec, {
|
|
29691
|
+
types: schema
|
|
29692
|
+
});
|
|
29693
|
+
return next;
|
|
29694
|
+
}
|
|
29695
|
+
length(length, message = array.length) {
|
|
29696
|
+
return this.test({
|
|
29697
|
+
message,
|
|
29698
|
+
name: 'length',
|
|
29699
|
+
exclusive: true,
|
|
29700
|
+
params: {
|
|
29701
|
+
length
|
|
29702
|
+
},
|
|
29703
|
+
skipAbsent: true,
|
|
29704
|
+
test(value) {
|
|
29705
|
+
return value.length === this.resolve(length);
|
|
29706
|
+
}
|
|
29707
|
+
});
|
|
29708
|
+
}
|
|
29709
|
+
min(min, message) {
|
|
29710
|
+
message = message || array.min;
|
|
29711
|
+
return this.test({
|
|
29712
|
+
message,
|
|
29713
|
+
name: 'min',
|
|
29714
|
+
exclusive: true,
|
|
29715
|
+
params: {
|
|
29716
|
+
min
|
|
29717
|
+
},
|
|
29718
|
+
skipAbsent: true,
|
|
29719
|
+
// FIXME(ts): Array<typeof T>
|
|
29720
|
+
test(value) {
|
|
29721
|
+
return value.length >= this.resolve(min);
|
|
29722
|
+
}
|
|
29723
|
+
});
|
|
29724
|
+
}
|
|
29725
|
+
max(max, message) {
|
|
29726
|
+
message = message || array.max;
|
|
29727
|
+
return this.test({
|
|
29728
|
+
message,
|
|
29729
|
+
name: 'max',
|
|
29730
|
+
exclusive: true,
|
|
29731
|
+
params: {
|
|
29732
|
+
max
|
|
29733
|
+
},
|
|
29734
|
+
skipAbsent: true,
|
|
29735
|
+
test(value) {
|
|
29736
|
+
return value.length <= this.resolve(max);
|
|
29737
|
+
}
|
|
29738
|
+
});
|
|
29739
|
+
}
|
|
29740
|
+
ensure() {
|
|
29741
|
+
return this.default(() => []).transform((val, original) => {
|
|
29742
|
+
// We don't want to return `null` for nullable schema
|
|
29743
|
+
if (this._typeCheck(val)) return val;
|
|
29744
|
+
return original == null ? [] : [].concat(original);
|
|
29745
|
+
});
|
|
29746
|
+
}
|
|
29747
|
+
compact(rejector) {
|
|
29748
|
+
let reject = !rejector ? v => !!v : (v, i, a) => !rejector(v, i, a);
|
|
29749
|
+
return this.transform(values => values != null ? values.filter(reject) : values);
|
|
29750
|
+
}
|
|
29751
|
+
describe(options) {
|
|
29752
|
+
const next = (options ? this.resolve(options) : this).clone();
|
|
29753
|
+
const base = super.describe(options);
|
|
29754
|
+
if (next.innerType) {
|
|
29755
|
+
var _innerOptions;
|
|
29756
|
+
let innerOptions = options;
|
|
29757
|
+
if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
|
|
29758
|
+
innerOptions = Object.assign({}, innerOptions, {
|
|
29759
|
+
parent: innerOptions.value,
|
|
29760
|
+
value: innerOptions.value[0]
|
|
29761
|
+
});
|
|
29762
|
+
}
|
|
29763
|
+
base.innerType = next.innerType.describe(innerOptions);
|
|
29764
|
+
}
|
|
29765
|
+
return base;
|
|
29766
|
+
}
|
|
29767
|
+
}
|
|
29768
|
+
create$2.prototype = ArraySchema.prototype;
|
|
29769
|
+
|
|
29770
|
+
// @ts-ignore
|
|
29771
|
+
function create$1(schemas) {
|
|
29772
|
+
return new TupleSchema(schemas);
|
|
29773
|
+
}
|
|
29774
|
+
class TupleSchema extends Schema {
|
|
29775
|
+
constructor(schemas) {
|
|
29776
|
+
super({
|
|
29777
|
+
type: 'tuple',
|
|
29778
|
+
spec: {
|
|
29779
|
+
types: schemas
|
|
29780
|
+
},
|
|
29781
|
+
check(v) {
|
|
29782
|
+
const types = this.spec.types;
|
|
29783
|
+
return Array.isArray(v) && v.length === types.length;
|
|
29784
|
+
}
|
|
29785
|
+
});
|
|
29786
|
+
this.withMutation(() => {
|
|
29787
|
+
this.typeError(tuple.notType);
|
|
29788
|
+
});
|
|
29789
|
+
}
|
|
29790
|
+
_cast(inputValue, options) {
|
|
29791
|
+
const {
|
|
29792
|
+
types
|
|
29793
|
+
} = this.spec;
|
|
29794
|
+
const value = super._cast(inputValue, options);
|
|
29795
|
+
if (!this._typeCheck(value)) {
|
|
29796
|
+
return value;
|
|
29797
|
+
}
|
|
29798
|
+
let isChanged = false;
|
|
29799
|
+
const castArray = types.map((type, idx) => {
|
|
29800
|
+
const castElement = type.cast(value[idx], Object.assign({}, options, {
|
|
29801
|
+
path: `${options.path || ''}[${idx}]`
|
|
29802
|
+
}));
|
|
29803
|
+
if (castElement !== value[idx]) isChanged = true;
|
|
29804
|
+
return castElement;
|
|
29805
|
+
});
|
|
29806
|
+
return isChanged ? castArray : value;
|
|
29807
|
+
}
|
|
29808
|
+
_validate(_value, options = {}, panic, next) {
|
|
29809
|
+
let itemTypes = this.spec.types;
|
|
29810
|
+
super._validate(_value, options, panic, (tupleErrors, value) => {
|
|
29811
|
+
var _options$originalValu2;
|
|
29812
|
+
// intentionally not respecting recursive
|
|
29813
|
+
if (!this._typeCheck(value)) {
|
|
29814
|
+
next(tupleErrors, value);
|
|
29815
|
+
return;
|
|
29816
|
+
}
|
|
29817
|
+
let tests = [];
|
|
29818
|
+
for (let [index, itemSchema] of itemTypes.entries()) {
|
|
29819
|
+
var _options$originalValu;
|
|
29820
|
+
tests[index] = itemSchema.asNestedTest({
|
|
29821
|
+
options,
|
|
29822
|
+
index,
|
|
29823
|
+
parent: value,
|
|
29824
|
+
parentPath: options.path,
|
|
29825
|
+
originalParent: (_options$originalValu = options.originalValue) != null ? _options$originalValu : _value
|
|
29826
|
+
});
|
|
29827
|
+
}
|
|
29828
|
+
this.runTests({
|
|
29829
|
+
value,
|
|
29830
|
+
tests,
|
|
29831
|
+
originalValue: (_options$originalValu2 = options.originalValue) != null ? _options$originalValu2 : _value,
|
|
29832
|
+
options
|
|
29833
|
+
}, panic, innerTypeErrors => next(innerTypeErrors.concat(tupleErrors), value));
|
|
29834
|
+
});
|
|
29835
|
+
}
|
|
29836
|
+
describe(options) {
|
|
29837
|
+
const next = (options ? this.resolve(options) : this).clone();
|
|
29838
|
+
const base = super.describe(options);
|
|
29839
|
+
base.innerType = next.spec.types.map((schema, index) => {
|
|
29840
|
+
var _innerOptions;
|
|
29841
|
+
let innerOptions = options;
|
|
29842
|
+
if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
|
|
29843
|
+
innerOptions = Object.assign({}, innerOptions, {
|
|
29844
|
+
parent: innerOptions.value,
|
|
29845
|
+
value: innerOptions.value[index]
|
|
29846
|
+
});
|
|
29847
|
+
}
|
|
29848
|
+
return schema.describe(innerOptions);
|
|
29849
|
+
});
|
|
29850
|
+
return base;
|
|
29851
|
+
}
|
|
29852
|
+
}
|
|
29853
|
+
create$1.prototype = TupleSchema.prototype;
|
|
29854
|
+
|
|
29855
|
+
function create(builder) {
|
|
29856
|
+
return new Lazy(builder);
|
|
29857
|
+
}
|
|
29858
|
+
class Lazy {
|
|
29859
|
+
constructor(builder) {
|
|
29860
|
+
this.type = 'lazy';
|
|
29861
|
+
this.__isYupSchema__ = true;
|
|
29862
|
+
this.spec = void 0;
|
|
29863
|
+
this._resolve = (value, options = {}) => {
|
|
29864
|
+
let schema = this.builder(value, options);
|
|
29865
|
+
if (!isSchema(schema)) throw new TypeError('lazy() functions must return a valid schema');
|
|
29866
|
+
if (this.spec.optional) schema = schema.optional();
|
|
29867
|
+
return schema.resolve(options);
|
|
29868
|
+
};
|
|
29869
|
+
this.builder = builder;
|
|
29870
|
+
this.spec = {
|
|
29871
|
+
meta: undefined,
|
|
29872
|
+
optional: false
|
|
29873
|
+
};
|
|
29874
|
+
}
|
|
29875
|
+
clone(spec) {
|
|
29876
|
+
const next = new Lazy(this.builder);
|
|
29877
|
+
next.spec = Object.assign({}, this.spec, spec);
|
|
29878
|
+
return next;
|
|
29879
|
+
}
|
|
29880
|
+
optionality(optional) {
|
|
29881
|
+
const next = this.clone({
|
|
29882
|
+
optional
|
|
29883
|
+
});
|
|
29884
|
+
return next;
|
|
29885
|
+
}
|
|
29886
|
+
optional() {
|
|
29887
|
+
return this.optionality(true);
|
|
29888
|
+
}
|
|
29889
|
+
resolve(options) {
|
|
29890
|
+
return this._resolve(options.value, options);
|
|
29891
|
+
}
|
|
29892
|
+
cast(value, options) {
|
|
29893
|
+
return this._resolve(value, options).cast(value, options);
|
|
29894
|
+
}
|
|
29895
|
+
asNestedTest(config) {
|
|
29896
|
+
let {
|
|
29897
|
+
key,
|
|
29898
|
+
index,
|
|
29899
|
+
parent,
|
|
29900
|
+
options
|
|
29901
|
+
} = config;
|
|
29902
|
+
let value = parent[index != null ? index : key];
|
|
29903
|
+
return this._resolve(value, Object.assign({}, options, {
|
|
29904
|
+
value,
|
|
29905
|
+
parent
|
|
29906
|
+
})).asNestedTest(config);
|
|
29907
|
+
}
|
|
29908
|
+
validate(value, options) {
|
|
29909
|
+
return this._resolve(value, options).validate(value, options);
|
|
29910
|
+
}
|
|
29911
|
+
validateSync(value, options) {
|
|
29912
|
+
return this._resolve(value, options).validateSync(value, options);
|
|
29913
|
+
}
|
|
29914
|
+
validateAt(path, value, options) {
|
|
29915
|
+
return this._resolve(value, options).validateAt(path, value, options);
|
|
29916
|
+
}
|
|
29917
|
+
validateSyncAt(path, value, options) {
|
|
29918
|
+
return this._resolve(value, options).validateSyncAt(path, value, options);
|
|
29919
|
+
}
|
|
29920
|
+
isValid(value, options) {
|
|
29921
|
+
return this._resolve(value, options).isValid(value, options);
|
|
29922
|
+
}
|
|
29923
|
+
isValidSync(value, options) {
|
|
29924
|
+
return this._resolve(value, options).isValidSync(value, options);
|
|
29925
|
+
}
|
|
29926
|
+
describe(options) {
|
|
29927
|
+
return options ? this.resolve(options).describe(options) : {
|
|
29928
|
+
type: 'lazy',
|
|
29929
|
+
meta: this.spec.meta,
|
|
29930
|
+
label: undefined
|
|
29931
|
+
};
|
|
29932
|
+
}
|
|
29933
|
+
meta(...args) {
|
|
29934
|
+
if (args.length === 0) return this.spec.meta;
|
|
29935
|
+
let next = this.clone();
|
|
29936
|
+
next.spec.meta = Object.assign(next.spec.meta || {}, args[0]);
|
|
29937
|
+
return next;
|
|
29938
|
+
}
|
|
29939
|
+
}
|
|
29940
|
+
|
|
29941
|
+
function setLocale(custom) {
|
|
29942
|
+
Object.keys(custom).forEach(type => {
|
|
29943
|
+
// @ts-ignore
|
|
29944
|
+
Object.keys(custom[type]).forEach(method => {
|
|
29945
|
+
// @ts-ignore
|
|
29946
|
+
locale[type][method] = custom[type][method];
|
|
29947
|
+
});
|
|
29948
|
+
});
|
|
29949
|
+
}
|
|
29950
|
+
|
|
29951
|
+
function addMethod(schemaType, name, fn) {
|
|
29952
|
+
if (!schemaType || !isSchema(schemaType.prototype)) throw new TypeError('You must provide a yup schema constructor function');
|
|
29953
|
+
if (typeof name !== 'string') throw new TypeError('A Method name must be provided');
|
|
29954
|
+
if (typeof fn !== 'function') throw new TypeError('Method function must be provided');
|
|
29955
|
+
schemaType.prototype[name] = fn;
|
|
29956
|
+
}
|
|
29957
|
+
|
|
29958
|
+
var index_esm = /*#__PURE__*/Object.freeze({
|
|
29959
|
+
__proto__: null,
|
|
29960
|
+
ArraySchema: ArraySchema,
|
|
29961
|
+
BooleanSchema: BooleanSchema,
|
|
29962
|
+
DateSchema: DateSchema,
|
|
29963
|
+
MixedSchema: MixedSchema,
|
|
29964
|
+
NumberSchema: NumberSchema,
|
|
29965
|
+
ObjectSchema: ObjectSchema,
|
|
29966
|
+
Schema: Schema,
|
|
29967
|
+
StringSchema: StringSchema,
|
|
29968
|
+
TupleSchema: TupleSchema,
|
|
29969
|
+
ValidationError: ValidationError,
|
|
29970
|
+
addMethod: addMethod,
|
|
29971
|
+
array: create$2,
|
|
29972
|
+
bool: create$7,
|
|
29973
|
+
boolean: create$7,
|
|
29974
|
+
date: create$4,
|
|
29975
|
+
defaultLocale: locale,
|
|
29976
|
+
getIn: getIn,
|
|
29977
|
+
isSchema: isSchema,
|
|
29978
|
+
lazy: create,
|
|
29979
|
+
mixed: create$8,
|
|
29980
|
+
number: create$5,
|
|
29981
|
+
object: create$3,
|
|
29982
|
+
printValue: printValue,
|
|
29983
|
+
reach: reach,
|
|
29984
|
+
ref: create$9,
|
|
29985
|
+
setLocale: setLocale,
|
|
29986
|
+
string: create$6,
|
|
29987
|
+
tuple: create$1
|
|
29988
|
+
});
|
|
29989
|
+
|
|
27233
29990
|
exports.Controller = Controller;
|
|
27234
29991
|
exports.Form = Form;
|
|
27235
29992
|
exports.FormProvider = FormProvider;
|
|
@@ -27241,6 +29998,7 @@ exports.RHFSelect = RHFSelect;
|
|
|
27241
29998
|
exports.RHFSlider = RHFSlider;
|
|
27242
29999
|
exports.RHFSwitch = RHFSwitch;
|
|
27243
30000
|
exports.RHFTextField = RHFTextField;
|
|
30001
|
+
exports.Yup = index_esm;
|
|
27244
30002
|
exports.appendErrors = appendErrors;
|
|
27245
30003
|
exports.get = get;
|
|
27246
30004
|
exports.set = set;
|
|
@@ -27250,4 +30008,5 @@ exports.useForm = useForm;
|
|
|
27250
30008
|
exports.useFormContext = useFormContext;
|
|
27251
30009
|
exports.useFormState = useFormState;
|
|
27252
30010
|
exports.useWatch = useWatch;
|
|
30011
|
+
exports.yupResolver = o;
|
|
27253
30012
|
//# sourceMappingURL=index.cjs.js.map
|