@sanity/schema 5.10.0-next.28 → 5.10.0-next.29

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.
@@ -58,15 +58,15 @@ declare const builtinTypes: ({
58
58
  type: string;
59
59
  title: string;
60
60
  readOnly: boolean;
61
- hidden?: undefined;
62
61
  fieldset?: undefined;
62
+ hidden?: undefined;
63
63
  } | {
64
64
  name: string;
65
65
  type: string;
66
66
  title: string;
67
67
  readOnly?: undefined;
68
- hidden?: undefined;
69
68
  fieldset?: undefined;
69
+ hidden?: undefined;
70
70
  } | {
71
71
  name: string;
72
72
  type: string;
@@ -125,15 +125,15 @@ declare const builtinTypes: ({
125
125
  type: string;
126
126
  title: string;
127
127
  readOnly: boolean;
128
- hidden?: undefined;
129
128
  fieldset?: undefined;
129
+ hidden?: undefined;
130
130
  } | {
131
131
  name: string;
132
132
  type: string;
133
133
  title: string;
134
134
  readOnly?: undefined;
135
- hidden?: undefined;
136
135
  fieldset?: undefined;
136
+ hidden?: undefined;
137
137
  } | {
138
138
  name: string;
139
139
  type: string;
package/lib/_internal.js CHANGED
@@ -1035,7 +1035,8 @@ const builtinTypes = [
1035
1035
  CROSS_DATASET_REFERENCE_INVALID: "cross-dataset-reference-invalid",
1036
1036
  GLOBAL_DOCUMENT_REFERENCE_INVALID: "global-document-reference-invalid",
1037
1037
  DEPRECATED_BLOCKEDITOR_KEY: "schema-deprecated-blockeditor-key",
1038
- STANDALONE_BLOCK_TYPE: "schema-standalone-block-type"
1038
+ STANDALONE_BLOCK_TYPE: "schema-standalone-block-type",
1039
+ FIELD_TYPE_IS_DOCUMENT: "schema-field-type-is-document"
1039
1040
  };
1040
1041
  function createValidationResult(severity, message, helpId) {
1041
1042
  if (helpId && !Object.keys(HELP_IDS).some((id) => HELP_IDS[id] === helpId))
@@ -1368,7 +1369,19 @@ var array = (typeDef, visitorContext) => {
1368
1369
  )
1369
1370
  ), {
1370
1371
  ...typeDef,
1371
- of: of.map(visitorContext.visit),
1372
+ of: of.map((ofMember, index) => {
1373
+ const visited = visitorContext.visit(ofMember, index);
1374
+ return ofMember.type && typeof ofMember.type == "string" && visitorContext.getType(ofMember.type)?.type === "document" ? {
1375
+ ...visited,
1376
+ _problems: [
1377
+ ...visited._problems || [],
1378
+ warning(
1379
+ `The type "${ofMember.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.`,
1380
+ HELP_IDS.FIELD_TYPE_IS_DOCUMENT
1381
+ )
1382
+ ]
1383
+ } : visited;
1384
+ }),
1372
1385
  _problems: problems
1373
1386
  };
1374
1387
  };
@@ -1769,7 +1782,7 @@ function validateFieldName(name) {
1769
1782
  )
1770
1783
  ];
1771
1784
  }
1772
- function validateField(field, _visitorContext) {
1785
+ function validateField(field, visitorContext) {
1773
1786
  if (!isPlainObject(field))
1774
1787
  return [
1775
1788
  error(
@@ -1780,7 +1793,12 @@ function validateField(field, _visitorContext) {
1780
1793
  const problems = [];
1781
1794
  return problems.push(
1782
1795
  ..."name" in field ? validateFieldName(field.name) : [error("Missing field name", HELP_IDS.OBJECT_FIELD_NAME_INVALID)]
1783
- ), problems.push(...validateComponent(field)), problems;
1796
+ ), problems.push(...validateComponent(field)), field.type && typeof field.type == "string" && visitorContext.getType(field.type)?.type === "document" && problems.push(
1797
+ warning(
1798
+ `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.`,
1799
+ HELP_IDS.FIELD_TYPE_IS_DOCUMENT
1800
+ )
1801
+ ), problems;
1784
1802
  }
1785
1803
  function getDuplicateFields(array2) {
1786
1804
  const dupes = {};
@@ -1849,7 +1867,7 @@ var object = (typeDef, visitorContext) => {
1849
1867
  return {
1850
1868
  name,
1851
1869
  ...fieldType,
1852
- _problems: validateField(field).concat(_problems || [])
1870
+ _problems: validateField(field, visitorContext).concat(_problems || [])
1853
1871
  };
1854
1872
  }),
1855
1873
  _problems: problems
@@ -1875,7 +1893,7 @@ var object = (typeDef, visitorContext) => {
1875
1893
  return {
1876
1894
  name,
1877
1895
  ...fieldType,
1878
- _problems: validateField(field).concat(_problems || [])
1896
+ _problems: validateField(field, visitorContext).concat(_problems || [])
1879
1897
  };
1880
1898
  }),
1881
1899
  _problems: problems
@@ -2005,7 +2023,7 @@ var image = (typeDef, visitorContext) => {
2005
2023
  return {
2006
2024
  name,
2007
2025
  ...fieldType,
2008
- _problems: validateField(field).concat(_problems || [])
2026
+ _problems: validateField(field, visitorContext).concat(_problems || [])
2009
2027
  };
2010
2028
  }),
2011
2029
  _problems: problems