@sanity/validation 3.14.2 → 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/dts/src/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare function inferFromSchema(schema: Schema): Schema
|
|
|
22
22
|
export declare function inferFromSchemaType(
|
|
23
23
|
typeDef: SchemaType,
|
|
24
24
|
_schema: Schema,
|
|
25
|
-
_visited?: Set<SchemaType
|
|
25
|
+
_visited?: Set<SchemaType>,
|
|
26
26
|
): SchemaType
|
|
27
27
|
|
|
28
28
|
export declare function inferFromSchemaType(typeDef: SchemaType): SchemaType
|
|
@@ -33,14 +33,14 @@ export declare function validateDocument(
|
|
|
33
33
|
getClient: ValidateItemOptions['getClient'],
|
|
34
34
|
doc: SanityDocument,
|
|
35
35
|
schema: Schema,
|
|
36
|
-
context?: Pick<ValidationContext, 'getDocumentExists'
|
|
36
|
+
context?: Pick<ValidationContext, 'getDocumentExists'>,
|
|
37
37
|
): Promise<ValidationMarker[]>
|
|
38
38
|
|
|
39
39
|
export declare function validateDocumentObservable(
|
|
40
40
|
getClient: ValidateItemOptions['getClient'],
|
|
41
41
|
doc: SanityDocument,
|
|
42
42
|
schema: Schema,
|
|
43
|
-
context?: Pick<ValidationContext, 'getDocumentExists'
|
|
43
|
+
context?: Pick<ValidationContext, 'getDocumentExists'>,
|
|
44
44
|
): Observable<ValidationMarker[]>
|
|
45
45
|
|
|
46
46
|
declare type ValidateItemOptions = {
|
package/lib/index.esm.js
CHANGED
|
@@ -53,9 +53,9 @@ function pathToString() {
|
|
|
53
53
|
return "".concat(target).concat(separator).concat(segment);
|
|
54
54
|
}
|
|
55
55
|
if (isKeyedObject(segment)) {
|
|
56
|
-
return "".concat(target,
|
|
56
|
+
return "".concat(target, '[_key=="').concat(segment._key, '"]');
|
|
57
57
|
}
|
|
58
|
-
throw new Error(
|
|
58
|
+
throw new Error('Unsupported path segment "'.concat(segment, '"'));
|
|
59
59
|
}, "");
|
|
60
60
|
}
|
|
61
61
|
function isNonNullable$1(t) {
|
|
@@ -182,7 +182,7 @@ const genericValidators = {
|
|
|
182
182
|
type: (expected, value, message) => {
|
|
183
183
|
const actualType = typeString(value);
|
|
184
184
|
if (actualType !== expected && actualType !== "undefined") {
|
|
185
|
-
return message ||
|
|
185
|
+
return message || 'Expected type "'.concat(expected, '", got "').concat(actualType, '"');
|
|
186
186
|
}
|
|
187
187
|
return true;
|
|
188
188
|
},
|
|
@@ -219,7 +219,7 @@ const genericValidators = {
|
|
|
219
219
|
}
|
|
220
220
|
const value = (valueType === "number" || valueType === "string") && "".concat(actual);
|
|
221
221
|
const strValue = value && value.length > 30 ? "".concat(value.slice(0, 30), "\u2026") : value;
|
|
222
|
-
const defaultMessage = value ?
|
|
222
|
+
const defaultMessage = value ? 'Value "'.concat(strValue, '" did not match any allowed values') : "Value did not match any allowed values";
|
|
223
223
|
return allowedValues.some(expected => deepEquals(expected, actual)) ? true : message || defaultMessage;
|
|
224
224
|
},
|
|
225
225
|
custom: async (fn, value, message, context) => {
|
|
@@ -366,7 +366,7 @@ const stringValidators = {
|
|
|
366
366
|
name,
|
|
367
367
|
invert
|
|
368
368
|
} = options;
|
|
369
|
-
const regName = name || "
|
|
369
|
+
const regName = name || '"'.concat(pattern.toString(), '"');
|
|
370
370
|
const strValue = value || "";
|
|
371
371
|
const matches = pattern.test(strValue);
|
|
372
372
|
if (!invert && !matches || invert && matches) {
|
|
@@ -539,7 +539,7 @@ function parseDate(date) {
|
|
|
539
539
|
const parsed = new Date(date);
|
|
540
540
|
const isInvalid = isNaN(parsed.getTime());
|
|
541
541
|
if (isInvalid && throwOnError) {
|
|
542
|
-
throw new Error(
|
|
542
|
+
throw new Error('Unable to parse "'.concat(date, '" to a date'));
|
|
543
543
|
}
|
|
544
544
|
return isInvalid ? null : parsed;
|
|
545
545
|
}
|
|
@@ -704,7 +704,7 @@ const Rule = (_a = class {
|
|
|
704
704
|
type(targetType) {
|
|
705
705
|
const type = "".concat(targetType.slice(0, 1).toUpperCase()).concat(targetType.slice(1));
|
|
706
706
|
if (!ruleConstraintTypes$1.includes(type)) {
|
|
707
|
-
throw new Error(
|
|
707
|
+
throw new Error('Unknown type "'.concat(targetType, '"'));
|
|
708
708
|
}
|
|
709
709
|
const rule = this.cloneWithRules([{
|
|
710
710
|
flag: "type",
|
|
@@ -918,8 +918,8 @@ const Rule = (_a = class {
|
|
|
918
918
|
}
|
|
919
919
|
const validator = validators[curr.flag];
|
|
920
920
|
if (!validator) {
|
|
921
|
-
const forType = this._type ?
|
|
922
|
-
throw new Error(
|
|
921
|
+
const forType = this._type ? 'type "'.concat(this._type, '"') : "rule without declared type";
|
|
922
|
+
throw new Error('Validator for flag "'.concat(curr.flag, '" not found for ').concat(forType));
|
|
923
923
|
}
|
|
924
924
|
let specConstraint = "constraint" in curr ? curr.constraint : null;
|
|
925
925
|
if (isFieldRef(specConstraint)) {
|
|
@@ -1011,7 +1011,7 @@ const defaultIsUnique = (slug, context) => {
|
|
|
1011
1011
|
});
|
|
1012
1012
|
};
|
|
1013
1013
|
function warnOnArraySlug(serializedPath) {
|
|
1014
|
-
console.warn(["Slug field at path ".concat(serializedPath, " is within an array and cannot be automatically checked for uniqueness"),
|
|
1014
|
+
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"));
|
|
1015
1015
|
}
|
|
1016
1016
|
const slugValidator = async (value, context) => {
|
|
1017
1017
|
var _a;
|