@sanity/schema 6.17.0-next.28 → 6.17.0-next.43
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 +10 -10
- package/lib/_internal.js +31 -5
- package/lib/_internal.js.map +1 -1
- package/package.json +4 -6
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
|
-
fieldset?: undefined;
|
|
398
|
-
readOnly?: undefined;
|
|
399
397
|
validation?: undefined;
|
|
400
398
|
hidden?: undefined;
|
|
399
|
+
fieldset?: undefined;
|
|
400
|
+
readOnly?: 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
|
-
fieldset?: undefined;
|
|
477
|
-
readOnly?: undefined;
|
|
478
476
|
validation?: undefined;
|
|
479
477
|
hidden?: undefined;
|
|
478
|
+
fieldset?: undefined;
|
|
479
|
+
readOnly?: 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: {
|
package/lib/_internal.js
CHANGED
|
@@ -17,7 +17,6 @@ import uniq from "lodash-es/uniq.js";
|
|
|
17
17
|
import humanizeList from "humanize-list";
|
|
18
18
|
import partition from "lodash-es/partition.js";
|
|
19
19
|
import leven from "leven";
|
|
20
|
-
import inspect from "object-inspect";
|
|
21
20
|
import { createReferenceTypeNode } from "groq-js";
|
|
22
21
|
const DEFAULT_IMAGE_FIELDS = [
|
|
23
22
|
"asset",
|
|
@@ -1887,7 +1886,34 @@ function getOptionErrors$2(typeDef) {
|
|
|
1887
1886
|
let { options } = typeDef, problems = [];
|
|
1888
1887
|
return problems.push(...["filter", "filterParams"].filter((key) => key in typeDef).map((key) => error(`\`${key}\` is not allowed on a reference type definition - did you mean \`options.${key}\`?`, HELP_IDS.REFERENCE_INVALID_OPTIONS_LOCATION))), options ? isPlainObject(options) ? typeof options.filter == "function" && options.filterParams !== void 0 ? problems.concat(error("`filterParams` cannot be used if `filter` is a function. Either statically define `filter` as a string, or return `params` from the `filter`-function.", HELP_IDS.REFERENCE_INVALID_FILTER_PARAMS_COMBINATION)) : typeof options.filter == "function" || !options.filter && !options.filterParams ? problems : typeof options.filter == "string" ? options.filterParams !== void 0 && !isPlainObject(options.filterParams) ? problems.concat(error("If set, `filterParams` must be an object.")) : options.filterParams ? problems.concat(Object.keys(options.filterParams).filter((key) => key.startsWith("__") || key.startsWith("$")).map((key) => error(`Filter parameter cannot be prefixed with "$" or "__". Got ${key}".`))) : problems : problems.concat(error(`If set, \`filter\` must be a string. Got ${typeof options.filter}`)) : problems.concat(error("The reference type expects `options` to be an object", HELP_IDS.REFERENCE_INVALID_OPTIONS)) : problems;
|
|
1889
1888
|
}
|
|
1890
|
-
|
|
1889
|
+
/** Formats invalid schema values for diagnostics without invoking their serialization hooks. */
|
|
1890
|
+
function inspect(value) {
|
|
1891
|
+
return formatValue(value, []);
|
|
1892
|
+
}
|
|
1893
|
+
function formatValue(value, ancestors) {
|
|
1894
|
+
if (typeof value == "string") return JSON.stringify(value.length > 200 ? `${value.slice(0, 200)}...` : value);
|
|
1895
|
+
if (typeof value == "function") return value.name ? `[Function: ${value.name}]` : "[Function]";
|
|
1896
|
+
if (typeof value == "bigint") return `${value}n`;
|
|
1897
|
+
if (Object.is(value, -0)) return "-0";
|
|
1898
|
+
if (typeof value != "object" || !value) return String(value);
|
|
1899
|
+
if (value instanceof Date) return Date.prototype.toString.call(value);
|
|
1900
|
+
if (value instanceof RegExp) return RegExp.prototype.toString.call(value);
|
|
1901
|
+
if (value instanceof Map) return "[Map]";
|
|
1902
|
+
if (value instanceof Set) return "[Set]";
|
|
1903
|
+
if (ancestors.includes(value)) return "[Circular]";
|
|
1904
|
+
if (ancestors.length >= 3) return Array.isArray(value) ? "[Array]" : "[Object]";
|
|
1905
|
+
let parents = [...ancestors, value];
|
|
1906
|
+
if (Array.isArray(value)) {
|
|
1907
|
+
let entries = Array.from({ length: Math.min(value.length, 10) }, (_, index) => formatProperty(value, String(index), parents));
|
|
1908
|
+
return value.length > 10 && entries.push("..."), entries.length ? `[ ${entries.join(", ")} ]` : "[]";
|
|
1909
|
+
}
|
|
1910
|
+
let keys = Object.keys(value), entries = keys.slice(0, 10).map((key) => `${key.length <= 200 && /^[A-Za-z_$][\w$]*$/.test(key) ? key : formatValue(key, parents)}: ${formatProperty(value, key, parents)}`);
|
|
1911
|
+
return keys.length > 10 && entries.push("..."), entries.length ? `{ ${entries.join(", ")} }` : "{}";
|
|
1912
|
+
}
|
|
1913
|
+
function formatProperty(value, key, ancestors) {
|
|
1914
|
+
let descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1915
|
+
return descriptor ? "value" in descriptor ? formatValue(descriptor.value, ancestors) : descriptor.get ? "[Getter]" : "[Setter]" : "undefined";
|
|
1916
|
+
}
|
|
1891
1917
|
const REACT_SYM_RE = /^Symbol\(react\..+\)$/;
|
|
1892
1918
|
function isComponentLike(value) {
|
|
1893
1919
|
return typeof value == "function" || typeof value?.$$typeof == "symbol" && REACT_SYM_RE.test(String(value?.$$typeof));
|
|
@@ -1896,14 +1922,14 @@ function validateComponent(typeDef) {
|
|
|
1896
1922
|
let components = "components" in typeDef && typeDef.components;
|
|
1897
1923
|
if (!components) return [];
|
|
1898
1924
|
let warnings = [];
|
|
1899
|
-
return components.input && !isComponentLike(components.input) && warnings.push(warning(`The \`components.input\` property is set but does not appear to be a valid React component (expected a function, but saw ${
|
|
1925
|
+
return components.input && !isComponentLike(components.input) && warnings.push(warning(`The \`components.input\` property is set but does not appear to be a valid React component (expected a function, but saw ${inspect(components.input)}). If you have imported a custom input component, please verify that you have imported the correct named/default export.`)), components.field && !isComponentLike(components.field) && warnings.push(warning(`The \`components.field\` property is set but does not appear to be a valid React component (expected a function, but saw ${inspect(components.field)}). If you have imported a custom field component, please verify that you have imported the correct named/default export.`)), components.item && !isComponentLike(components.item) && warnings.push(warning(`The \`components.item\` property is set but does not appear to be a valid React component (expected a function, but saw ${inspect(components.item)}). If you have imported a custom item component, please verify that you have imported the correct named/default export.`)), components.preview && !isComponentLike(components.preview) && warnings.push(warning(`The \`components.preview\` property is set but does not appear to be a valid React component (expected a function, but saw ${inspect(components.preview)}). If you have imported a custom preview component, please verify that you have imported the correct named/default export.`)), warnings;
|
|
1900
1926
|
}
|
|
1901
1927
|
const VALID_FIELD_RE = /^[A-Za-z]+[0-9A-Za-z_]*$/, CONVENTIONAL_FIELD_RE = /^[A-Za-z_]+[0-9A-Za-z_]*$/;
|
|
1902
1928
|
function validateFieldName(name) {
|
|
1903
|
-
return typeof name == "string" ? name.startsWith("_") ? [error(`Invalid field name "${name}". Field names cannot start with underscores "_" as it's reserved for system fields.`, HELP_IDS.OBJECT_FIELD_NAME_INVALID)] : VALID_FIELD_RE.test(name) ? CONVENTIONAL_FIELD_RE.test(name) ? [] : [warning("Thats an interesting field name for sure! But it is... how to put it... a bit... unconventional? It may be wise to keep special characters out of field names for easier access later on."), HELP_IDS.OBJECT_FIELD_NAME_INVALID] : [error(`Invalid field name: "${name}". Fields can only contain characters from A-Z, numbers and underscores and should not start with a number (must pass the regular expression ${String(VALID_FIELD_RE)}).`, HELP_IDS.OBJECT_FIELD_NAME_INVALID)] : [error(`Field names must be strings. Saw "${
|
|
1929
|
+
return typeof name == "string" ? name.startsWith("_") ? [error(`Invalid field name "${name}". Field names cannot start with underscores "_" as it's reserved for system fields.`, HELP_IDS.OBJECT_FIELD_NAME_INVALID)] : VALID_FIELD_RE.test(name) ? CONVENTIONAL_FIELD_RE.test(name) ? [] : [warning("Thats an interesting field name for sure! But it is... how to put it... a bit... unconventional? It may be wise to keep special characters out of field names for easier access later on."), HELP_IDS.OBJECT_FIELD_NAME_INVALID] : [error(`Invalid field name: "${name}". Fields can only contain characters from A-Z, numbers and underscores and should not start with a number (must pass the regular expression ${String(VALID_FIELD_RE)}).`, HELP_IDS.OBJECT_FIELD_NAME_INVALID)] : [error(`Field names must be strings. Saw "${inspect(name)}"`, HELP_IDS.OBJECT_FIELD_NAME_INVALID)];
|
|
1904
1930
|
}
|
|
1905
1931
|
function validateField(field, visitorContext) {
|
|
1906
|
-
if (!isPlainObject(field)) return [error(`Incorrect type for field definition - should be an object, saw ${
|
|
1932
|
+
if (!isPlainObject(field)) return [error(`Incorrect type for field definition - should be an object, saw ${inspect(field)}`, HELP_IDS.OBJECT_FIELD_DEFINITION_INVALID_TYPE)];
|
|
1907
1933
|
let problems = [];
|
|
1908
1934
|
return problems.push(..."name" in field ? validateFieldName(field.name) : [error("Missing field name", HELP_IDS.OBJECT_FIELD_NAME_INVALID)]), problems.push(...validateComponent(field)), field.type && typeof field.type == "string" && visitorContext.getType(field.type)?.type === "document" && problems.push(warning(`The type "${field.type}" is a document type and should not be used as a field type directly. Use a "reference" if you want to create a link to the document, or use "object" if you want to embed fields inline.`, HELP_IDS.FIELD_TYPE_IS_DOCUMENT)), field.title && typeof field.title != "string" && problems.push(warning(`Field "${field.name}" has a non-string title. This is known to cause problems and will not be supported in future versions. Please use a string instead.`)), field.description && typeof field.description != "string" && problems.push(warning(`Field "${field.name}" has a non-string description. This is known to cause problems and will not be supported in future versions. Please use a string instead.`)), problems;
|
|
1909
1935
|
}
|