@sanity/schema 6.13.0-next.7 → 6.13.0-next.83
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/_internal.d.ts +14 -14
- package/lib/_internal.js +12 -10
- package/lib/_internal.js.map +1 -1
- package/package.json +3 -2
package/lib/_internal.d.ts
CHANGED
|
@@ -387,17 +387,17 @@ declare const builtinTypes: ({
|
|
|
387
387
|
type: string;
|
|
388
388
|
title: string;
|
|
389
389
|
readOnly: boolean;
|
|
390
|
-
fieldset?: undefined;
|
|
391
390
|
validation?: undefined;
|
|
392
391
|
hidden?: undefined;
|
|
392
|
+
fieldset?: undefined;
|
|
393
393
|
} | {
|
|
394
394
|
name: string;
|
|
395
395
|
type: string;
|
|
396
396
|
title: string;
|
|
397
|
-
fieldset?: undefined;
|
|
398
|
-
readOnly?: undefined;
|
|
399
397
|
validation?: undefined;
|
|
400
398
|
hidden?: undefined;
|
|
399
|
+
readOnly?: undefined;
|
|
400
|
+
fieldset?: undefined;
|
|
401
401
|
} | {
|
|
402
402
|
name: string;
|
|
403
403
|
type: string;
|
|
@@ -412,8 +412,8 @@ declare const builtinTypes: ({
|
|
|
412
412
|
readOnly: boolean;
|
|
413
413
|
hidden: boolean;
|
|
414
414
|
fieldset: string;
|
|
415
|
-
title?: undefined;
|
|
416
415
|
validation?: undefined;
|
|
416
|
+
title?: undefined;
|
|
417
417
|
} | {
|
|
418
418
|
name: string;
|
|
419
419
|
type: string;
|
|
@@ -466,17 +466,17 @@ declare const builtinTypes: ({
|
|
|
466
466
|
type: string;
|
|
467
467
|
title: string;
|
|
468
468
|
readOnly: boolean;
|
|
469
|
-
fieldset?: undefined;
|
|
470
469
|
validation?: undefined;
|
|
471
470
|
hidden?: undefined;
|
|
471
|
+
fieldset?: undefined;
|
|
472
472
|
} | {
|
|
473
473
|
name: string;
|
|
474
474
|
type: string;
|
|
475
475
|
title: string;
|
|
476
|
-
fieldset?: undefined;
|
|
477
|
-
readOnly?: undefined;
|
|
478
476
|
validation?: undefined;
|
|
479
477
|
hidden?: undefined;
|
|
478
|
+
readOnly?: undefined;
|
|
479
|
+
fieldset?: undefined;
|
|
480
480
|
} | {
|
|
481
481
|
name: string;
|
|
482
482
|
type: string;
|
|
@@ -486,21 +486,21 @@ declare const builtinTypes: ({
|
|
|
486
486
|
validation: (Rule: import("@sanity/types").Rule) => import("@sanity/types").Rule;
|
|
487
487
|
hidden?: undefined;
|
|
488
488
|
} | {
|
|
489
|
+
validation?: undefined;
|
|
489
490
|
name: string;
|
|
490
491
|
type: string;
|
|
491
492
|
readOnly: boolean;
|
|
492
493
|
hidden: boolean;
|
|
493
494
|
fieldset: string;
|
|
494
495
|
title?: undefined;
|
|
495
|
-
validation?: undefined;
|
|
496
496
|
} | {
|
|
497
|
+
validation?: undefined;
|
|
498
|
+
hidden?: undefined;
|
|
497
499
|
name: string;
|
|
498
500
|
type: string;
|
|
499
501
|
title: string;
|
|
500
502
|
readOnly: boolean;
|
|
501
503
|
fieldset: string;
|
|
502
|
-
validation?: undefined;
|
|
503
|
-
hidden?: undefined;
|
|
504
504
|
})[];
|
|
505
505
|
preview: {
|
|
506
506
|
select: {
|
|
@@ -550,17 +550,17 @@ declare const builtinTypes: ({
|
|
|
550
550
|
};
|
|
551
551
|
}[];
|
|
552
552
|
fields: ({
|
|
553
|
-
name: string;
|
|
554
|
-
type: string;
|
|
555
|
-
fieldset?: undefined;
|
|
556
553
|
title?: undefined;
|
|
557
554
|
readOnly?: undefined;
|
|
555
|
+
fieldset?: undefined;
|
|
556
|
+
name: string;
|
|
557
|
+
type: string;
|
|
558
558
|
} | {
|
|
559
|
+
readOnly?: undefined;
|
|
559
560
|
name: string;
|
|
560
561
|
title: string;
|
|
561
562
|
type: string;
|
|
562
563
|
fieldset: string;
|
|
563
|
-
readOnly?: undefined;
|
|
564
564
|
} | {
|
|
565
565
|
fieldset?: undefined;
|
|
566
566
|
name: string;
|
package/lib/_internal.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as resolveSearchConfig, d as OWN_PROPS_NAME, f as Rule, l as resolveSearchConfigForBaseFieldPaths, n as Schema$1, s as DEFAULT_MAX_FIELD_DEPTH, u as ALL_FIELDS_GROUP_NAME } from "./Schema-ClAx8eCc.js";
|
|
2
2
|
import { SetBuilder, processSetSynchronization } from "@sanity/descriptors";
|
|
3
3
|
import { isSpanSchemaType } from "@sanity/types";
|
|
4
|
-
import
|
|
4
|
+
import { dequal } from "dequal/lite";
|
|
5
5
|
import isObject from "lodash-es/isObject.js";
|
|
6
6
|
import cloneDeep from "lodash-es/cloneDeep.js";
|
|
7
7
|
import { HttpError, createRequester } from "get-it";
|
|
@@ -400,7 +400,7 @@ function maybeValidations(obj) {
|
|
|
400
400
|
let validation = maybeValidation(rule);
|
|
401
401
|
if (validation === void 0) continue;
|
|
402
402
|
let rulesToAdd = impliedRules.filter((ir) => !validation.rules.some((r) => r.type === ir.type));
|
|
403
|
-
rulesToAdd.length > 0 && validation.rules.unshift(...rulesToAdd), !validations.some((v) =>
|
|
403
|
+
rulesToAdd.length > 0 && validation.rules.unshift(...rulesToAdd), !validations.some((v) => dequal(v, validation)) && validations.push(validation);
|
|
404
404
|
}
|
|
405
405
|
return validations.length > 0 ? validations : void 0;
|
|
406
406
|
}
|
|
@@ -429,7 +429,7 @@ function maybeValidation(val) {
|
|
|
429
429
|
let level = val._level || "error", message = maybeValidationMessage(val._message), rules = [];
|
|
430
430
|
for (let spec of val._rules || []) {
|
|
431
431
|
let convertedRule = convertRuleSpec(spec, val._required === "optional" || void 0);
|
|
432
|
-
convertedRule !== void 0 && (rules.some((r) =>
|
|
432
|
+
convertedRule !== void 0 && (rules.some((r) => dequal(r, convertedRule)) || rules.push(convertedRule));
|
|
433
433
|
}
|
|
434
434
|
return rules.length === 0 ? void 0 : {
|
|
435
435
|
level,
|
|
@@ -609,7 +609,7 @@ function maybeOrdering(val) {
|
|
|
609
609
|
function maybeOrderingBy(val) {
|
|
610
610
|
if (!isObject(val) || Array.isArray(val)) return;
|
|
611
611
|
let field = "field" in val && typeof val.field == "string" ? val.field : void 0, direction = "direction" in val && (val.direction === "asc" || val.direction === "desc") ? val.direction : void 0, nulls = "nulls" in val && (val.nulls === "first" || val.nulls === "last") ? val.nulls : void 0;
|
|
612
|
-
if (
|
|
612
|
+
if (field && direction) return {
|
|
613
613
|
field,
|
|
614
614
|
direction,
|
|
615
615
|
...nulls && { nulls }
|
|
@@ -2108,7 +2108,9 @@ var ValidationError = class extends Error {
|
|
|
2108
2108
|
const builtinSchema = Schema$1.compile({
|
|
2109
2109
|
name: "studio",
|
|
2110
2110
|
types: builtinTypes
|
|
2111
|
-
})
|
|
2111
|
+
}), unavailableValidator = () => {
|
|
2112
|
+
throw Error("This validator is unavailable because it was reconstructed from a serialized schema manifest");
|
|
2113
|
+
};
|
|
2112
2114
|
function createSchemaFromManifestTypes(schemaDef) {
|
|
2113
2115
|
let problems = groupProblems(validateSchema(schemaDef.types).getTypes()).filter((group) => group.problems.some((problem) => problem.severity === "error"));
|
|
2114
2116
|
if (problems.length > 0) throw new ValidationError(problems);
|
|
@@ -2134,10 +2136,10 @@ function traverse(obj) {
|
|
|
2134
2136
|
}
|
|
2135
2137
|
}
|
|
2136
2138
|
function coerceValidation(val) {
|
|
2137
|
-
|
|
2139
|
+
isObject(val) && "validation" in val && (val.validation = (Array.isArray(val.validation) ? val.validation : [val.validation]).map((group) => {
|
|
2138
2140
|
if (isObject(group)) return (baseRule) => {
|
|
2139
2141
|
let rule = baseRule, level = "level" in group ? group.level : void 0, rules = "rules" in group ? group.rules : void 0, message = "message" in group ? group.message : void 0;
|
|
2140
|
-
if (
|
|
2142
|
+
if (rules && Array.isArray(rules)) {
|
|
2141
2143
|
isValidLevel(level) && (message === void 0 || typeof message == "string") && (rule = rule[level](message));
|
|
2142
2144
|
for (let ruleSpec of rules) rule = applyRuleSpec(rule, ruleSpec);
|
|
2143
2145
|
return rule;
|
|
@@ -2148,7 +2150,7 @@ function coerceValidation(val) {
|
|
|
2148
2150
|
function coerceConstraintRule(val) {
|
|
2149
2151
|
if (isObject(val)) return Array.isArray(val) ? val.map(coerceConstraintRule).filter(Boolean) : (baseRule) => {
|
|
2150
2152
|
let rule = baseRule, rules = "_rules" in val ? val._rules : void 0, level = "_level" in val ? val._level : void 0, message = "_message" in val ? val._message : void 0;
|
|
2151
|
-
if (
|
|
2153
|
+
if (rules && Array.isArray(rules)) {
|
|
2152
2154
|
typeof level == "string" && (rule = rule[level](message));
|
|
2153
2155
|
for (let ruleSpec of rules) rule = applyRuleSpec(rule, ruleSpec);
|
|
2154
2156
|
return rule;
|
|
@@ -2215,11 +2217,11 @@ function applyRuleSpec(rule, ruleSpec) {
|
|
|
2215
2217
|
case "all": return rule.all(coerceConstraintRule(constraint));
|
|
2216
2218
|
case "either": return rule.either(coerceConstraintRule(constraint));
|
|
2217
2219
|
case "custom":
|
|
2218
|
-
if (constraint === void 0) return rule.custom(
|
|
2220
|
+
if (constraint === void 0) return rule.custom(unavailableValidator);
|
|
2219
2221
|
if (typeof constraint == "function") return rule.custom(constraint);
|
|
2220
2222
|
break;
|
|
2221
2223
|
case "media":
|
|
2222
|
-
if (constraint === void 0) return rule.media(
|
|
2224
|
+
if (constraint === void 0) return rule.media(unavailableValidator);
|
|
2223
2225
|
if (typeof constraint == "function") return rule.media(constraint);
|
|
2224
2226
|
}
|
|
2225
2227
|
return rule;
|