@sanity/schema 6.19.0-next.37 → 6.19.0-next.69
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 +12 -11
- package/lib/_internal.js +15 -11
- package/lib/_internal.js.map +1 -1
- package/package.json +3 -3
package/lib/_internal.d.ts
CHANGED
|
@@ -387,17 +387,17 @@ export 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
|
-
readOnly?: undefined;
|
|
398
|
-
fieldset?: 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 @@ export 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 @@ export 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
|
-
readOnly?: undefined;
|
|
477
|
-
fieldset?: 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 @@ export 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: {
|
|
@@ -616,13 +616,14 @@ declare const typeVisitors: {
|
|
|
616
616
|
globalDocumentReference: (typeDef: any, visitorContext: any) => any;
|
|
617
617
|
};
|
|
618
618
|
interface Options {
|
|
619
|
+
parentTypes?: _FIXME_[];
|
|
619
620
|
transformTypeVisitors?: (visitors: typeof typeVisitors) => Partial<typeof typeVisitors>;
|
|
620
621
|
transformCommonVisitors?: (visitors: any[]) => any[];
|
|
621
622
|
}
|
|
622
623
|
/**
|
|
623
624
|
* @internal
|
|
624
625
|
*/
|
|
625
|
-
export declare function validateSchema(schemaTypes: _FIXME_, { transformTypeVisitors, transformCommonVisitors }?: Options): {
|
|
626
|
+
export declare function validateSchema(schemaTypes: _FIXME_, { parentTypes, transformTypeVisitors, transformCommonVisitors }?: Options): {
|
|
626
627
|
get(typeName: string): any;
|
|
627
628
|
has(typeName: string): boolean;
|
|
628
629
|
getTypeNames(): string[];
|
package/lib/_internal.js
CHANGED
|
@@ -1454,22 +1454,24 @@ const NOOP_VISITOR = (typeDef) => typeDef, TYPE_TYPE = {
|
|
|
1454
1454
|
"time",
|
|
1455
1455
|
"date"
|
|
1456
1456
|
];
|
|
1457
|
-
function traverseSchema(types = [], coreTypes = [], visitor = NOOP_VISITOR) {
|
|
1458
|
-
let coreTypesRegistry = Object.create(null), registry = Object.create(null), coreTypeNames = coreTypes.map((typeDef) => typeDef.name), reservedTypeNames = FUTURE_RESERVED.concat(coreTypeNames), typeNames = types.map((typeDef) => typeDef && typeDef.name).filter(Boolean);
|
|
1457
|
+
function traverseSchema(types = [], coreTypes = [], visitor = NOOP_VISITOR, parentTypes = []) {
|
|
1458
|
+
let coreTypesRegistry = Object.create(null), registry = Object.create(null), parentTypesRegistry = Object.create(null), coreTypeNames = coreTypes.map((typeDef) => typeDef.name), parentTypeNames = parentTypes.map((typeDef) => typeDef.name), reservedTypeNames = FUTURE_RESERVED.concat(coreTypeNames, parentTypeNames), typeNames = types.map((typeDef) => typeDef && typeDef.name).filter(Boolean);
|
|
1459
1459
|
coreTypes.forEach((coreType) => {
|
|
1460
1460
|
coreTypesRegistry[coreType.name] = coreType;
|
|
1461
|
+
}), parentTypes.forEach((type) => {
|
|
1462
|
+
parentTypesRegistry[type.name] = {};
|
|
1461
1463
|
}), types.forEach((type, i) => {
|
|
1462
1464
|
registry[type && type.name || `__unnamed_${i}`] = {};
|
|
1463
1465
|
});
|
|
1464
1466
|
function getType(typeName) {
|
|
1465
|
-
return typeName === "type" ? TYPE_TYPE : coreTypesRegistry[typeName] || registry[typeName] || null;
|
|
1467
|
+
return typeName === "type" ? TYPE_TYPE : coreTypesRegistry[typeName] || registry[typeName] || parentTypesRegistry[typeName] || null;
|
|
1466
1468
|
}
|
|
1467
1469
|
let duplicateNames = uniq(flatten(getDupes(typeNames)));
|
|
1468
1470
|
function isDuplicate(typeName) {
|
|
1469
1471
|
return duplicateNames.includes(typeName);
|
|
1470
1472
|
}
|
|
1471
1473
|
function getTypeNames() {
|
|
1472
|
-
return typeNames.concat(coreTypeNames);
|
|
1474
|
+
return typeNames.concat(parentTypeNames, coreTypeNames);
|
|
1473
1475
|
}
|
|
1474
1476
|
function isReserved(typeName) {
|
|
1475
1477
|
return typeName === "type" || reservedTypeNames.includes(typeName);
|
|
@@ -1485,16 +1487,18 @@ function traverseSchema(types = [], coreTypes = [], visitor = NOOP_VISITOR) {
|
|
|
1485
1487
|
});
|
|
1486
1488
|
return coreTypes.forEach((coreTypeDef) => {
|
|
1487
1489
|
Object.assign(coreTypesRegistry[coreTypeDef.name], visitType(coreTypeDef));
|
|
1490
|
+
}), parentTypes.forEach((typeDef, i) => {
|
|
1491
|
+
Object.assign(parentTypesRegistry[typeDef.name], visitType(!1)(typeDef, i));
|
|
1488
1492
|
}), types.forEach((typeDef, i) => {
|
|
1489
1493
|
Object.assign(registry[typeDef && typeDef.name || `__unnamed_${i}`], visitType(!0)(typeDef, i));
|
|
1490
1494
|
}), {
|
|
1491
1495
|
get(typeName) {
|
|
1492
|
-
let res = registry[typeName] || coreTypesRegistry[typeName];
|
|
1496
|
+
let res = registry[typeName] || parentTypesRegistry[typeName] || coreTypesRegistry[typeName];
|
|
1493
1497
|
if (res) return res;
|
|
1494
1498
|
throw Error(`No such type: ${typeName}`);
|
|
1495
1499
|
},
|
|
1496
1500
|
has(typeName) {
|
|
1497
|
-
return typeName in registry || typeName in coreTypesRegistry;
|
|
1501
|
+
return typeName in registry || typeName in parentTypesRegistry || typeName in coreTypesRegistry;
|
|
1498
1502
|
},
|
|
1499
1503
|
getTypeNames() {
|
|
1500
1504
|
return Object.keys(registry);
|
|
@@ -1614,8 +1618,8 @@ const coreTypes = [
|
|
|
1614
1618
|
type: "type"
|
|
1615
1619
|
}
|
|
1616
1620
|
], coreTypeNames = coreTypes.map((t) => t.name);
|
|
1617
|
-
function traverseSanitySchema(schemaTypes, visitor) {
|
|
1618
|
-
return traverseSchema(schemaTypes, coreTypes, visitor);
|
|
1621
|
+
function traverseSanitySchema(schemaTypes, parentTypes, visitor) {
|
|
1622
|
+
return traverseSchema(schemaTypes, coreTypes, visitor, parentTypes);
|
|
1619
1623
|
}
|
|
1620
1624
|
function isPrimitiveTypeName(typeName) {
|
|
1621
1625
|
return typeName === "string" || typeName === "number" || typeName === "boolean";
|
|
@@ -2119,8 +2123,8 @@ function combine(...visitors) {
|
|
|
2119
2123
|
/**
|
|
2120
2124
|
* @internal
|
|
2121
2125
|
*/
|
|
2122
|
-
function validateSchema(schemaTypes, { transformTypeVisitors = (visitors) => visitors, transformCommonVisitors = (visitors) => visitors } = {}) {
|
|
2123
|
-
return traverseSanitySchema(schemaTypes, (schemaDef, visitorContext) => {
|
|
2126
|
+
function validateSchema(schemaTypes, { parentTypes = [], transformTypeVisitors = (visitors) => visitors, transformCommonVisitors = (visitors) => visitors } = {}) {
|
|
2127
|
+
return traverseSanitySchema(schemaTypes, parentTypes, (schemaDef, visitorContext) => {
|
|
2124
2128
|
let typeVisitor = schemaDef && schemaDef.type && transformTypeVisitors(typeVisitors)[schemaDef.type] || getNoopVisitor(visitorContext), commonVisitors = transformCommonVisitors([common_default]);
|
|
2125
2129
|
return visitorContext.isRoot ? combine(rootType_default, ...commonVisitors, typeVisitor)(schemaDef, visitorContext) : combine(...commonVisitors, typeVisitor)(schemaDef, visitorContext);
|
|
2126
2130
|
});
|
|
@@ -2138,7 +2142,7 @@ const builtinSchema = Schema$1.compile({
|
|
|
2138
2142
|
throw Error("This validator is unavailable because it was reconstructed from a serialized schema manifest");
|
|
2139
2143
|
};
|
|
2140
2144
|
function createSchemaFromManifestTypes(schemaDef) {
|
|
2141
|
-
let problems = groupProblems(validateSchema(schemaDef.types).getTypes()).filter((group) => group.problems.some((problem) => problem.severity === "error"));
|
|
2145
|
+
let problems = groupProblems(validateSchema(schemaDef.types, { parentTypes: builtinTypes }).getTypes()).filter((group) => group.problems.some((problem) => problem.severity === "error"));
|
|
2142
2146
|
if (problems.length > 0) throw new ValidationError(problems);
|
|
2143
2147
|
return Schema$1.compile({
|
|
2144
2148
|
name: schemaDef.name,
|