@sanity/validation 3.14.3 → 3.14.4
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/lib/dts/src/index.d.ts +3 -3
- package/lib/index.esm.js +10 -10
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +10 -10
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -69,9 +69,9 @@ function pathToString() {
|
|
|
69
69
|
return "".concat(target).concat(separator).concat(segment);
|
|
70
70
|
}
|
|
71
71
|
if (types.isKeyedObject(segment)) {
|
|
72
|
-
return "".concat(target,
|
|
72
|
+
return "".concat(target, '[_key=="').concat(segment._key, '"]');
|
|
73
73
|
}
|
|
74
|
-
throw new Error(
|
|
74
|
+
throw new Error('Unsupported path segment "'.concat(segment, '"'));
|
|
75
75
|
}, "");
|
|
76
76
|
}
|
|
77
77
|
function isNonNullable$1(t) {
|
|
@@ -198,7 +198,7 @@ const genericValidators = {
|
|
|
198
198
|
type: (expected, value, message) => {
|
|
199
199
|
const actualType = typeString(value);
|
|
200
200
|
if (actualType !== expected && actualType !== "undefined") {
|
|
201
|
-
return message ||
|
|
201
|
+
return message || 'Expected type "'.concat(expected, '", got "').concat(actualType, '"');
|
|
202
202
|
}
|
|
203
203
|
return true;
|
|
204
204
|
},
|
|
@@ -235,7 +235,7 @@ const genericValidators = {
|
|
|
235
235
|
}
|
|
236
236
|
const value = (valueType === "number" || valueType === "string") && "".concat(actual);
|
|
237
237
|
const strValue = value && value.length > 30 ? "".concat(value.slice(0, 30), "\u2026") : value;
|
|
238
|
-
const defaultMessage = value ?
|
|
238
|
+
const defaultMessage = value ? 'Value "'.concat(strValue, '" did not match any allowed values') : "Value did not match any allowed values";
|
|
239
239
|
return allowedValues.some(expected => deepEquals(expected, actual)) ? true : message || defaultMessage;
|
|
240
240
|
},
|
|
241
241
|
custom: async (fn, value, message, context) => {
|
|
@@ -382,7 +382,7 @@ const stringValidators = {
|
|
|
382
382
|
name,
|
|
383
383
|
invert
|
|
384
384
|
} = options;
|
|
385
|
-
const regName = name || "
|
|
385
|
+
const regName = name || '"'.concat(pattern.toString(), '"');
|
|
386
386
|
const strValue = value || "";
|
|
387
387
|
const matches = pattern.test(strValue);
|
|
388
388
|
if (!invert && !matches || invert && matches) {
|
|
@@ -555,7 +555,7 @@ function parseDate(date) {
|
|
|
555
555
|
const parsed = new Date(date);
|
|
556
556
|
const isInvalid = isNaN(parsed.getTime());
|
|
557
557
|
if (isInvalid && throwOnError) {
|
|
558
|
-
throw new Error(
|
|
558
|
+
throw new Error('Unable to parse "'.concat(date, '" to a date'));
|
|
559
559
|
}
|
|
560
560
|
return isInvalid ? null : parsed;
|
|
561
561
|
}
|
|
@@ -720,7 +720,7 @@ const Rule = (_a = class {
|
|
|
720
720
|
type(targetType) {
|
|
721
721
|
const type = "".concat(targetType.slice(0, 1).toUpperCase()).concat(targetType.slice(1));
|
|
722
722
|
if (!ruleConstraintTypes$1.includes(type)) {
|
|
723
|
-
throw new Error(
|
|
723
|
+
throw new Error('Unknown type "'.concat(targetType, '"'));
|
|
724
724
|
}
|
|
725
725
|
const rule = this.cloneWithRules([{
|
|
726
726
|
flag: "type",
|
|
@@ -934,8 +934,8 @@ const Rule = (_a = class {
|
|
|
934
934
|
}
|
|
935
935
|
const validator = validators[curr.flag];
|
|
936
936
|
if (!validator) {
|
|
937
|
-
const forType = this._type ?
|
|
938
|
-
throw new Error(
|
|
937
|
+
const forType = this._type ? 'type "'.concat(this._type, '"') : "rule without declared type";
|
|
938
|
+
throw new Error('Validator for flag "'.concat(curr.flag, '" not found for ').concat(forType));
|
|
939
939
|
}
|
|
940
940
|
let specConstraint = "constraint" in curr ? curr.constraint : null;
|
|
941
941
|
if (isFieldRef(specConstraint)) {
|
|
@@ -1027,7 +1027,7 @@ const defaultIsUnique = (slug, context) => {
|
|
|
1027
1027
|
});
|
|
1028
1028
|
};
|
|
1029
1029
|
function warnOnArraySlug(serializedPath) {
|
|
1030
|
-
console.warn(["Slug field at path ".concat(serializedPath, " is within an array and cannot be automatically checked for uniqueness"),
|
|
1030
|
+
console.warn(["Slug field at path ".concat(serializedPath, " is within an array and cannot be automatically checked for uniqueness"), 'If you need to check for uniqueness, provide your own "isUnique" method', "To disable this message, set `disableArrayWarning: true` on the slug `options` field"].join("\n"));
|
|
1031
1031
|
}
|
|
1032
1032
|
const slugValidator = async (value, context) => {
|
|
1033
1033
|
var _a;
|