@sanity/schema 5.8.2-next.2 → 5.8.2-next.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/_internal.js CHANGED
@@ -1022,6 +1022,7 @@ const builtinTypes = [
1022
1022
  ARRAY_OF_ARRAY: "schema-array-of-array",
1023
1023
  ARRAY_OF_INVALID: "schema-array-of-invalid",
1024
1024
  ARRAY_OF_NOT_UNIQUE: "schema-array-of-invalid",
1025
+ ARRAY_OF_DUPLICATE_PRIMITIVE_JSON_TYPE: "schema-array-of-duplicate-primitive-json-type",
1025
1026
  ARRAY_OF_TYPE_GLOBAL_TYPE_CONFLICT: "schema-array-of-type-global-type-conflict",
1026
1027
  ARRAY_OF_TYPE_BUILTIN_TYPE_CONFLICT: "schema-array-of-type-builtin-type-conflict",
1027
1028
  REFERENCE_TO_INVALID: "schema-reference-to-invalid",
@@ -1210,6 +1211,13 @@ function traverseSanitySchema(schemaTypes, visitor) {
1210
1211
  function isPrimitiveTypeName(typeName) {
1211
1212
  return typeName === "string" || typeName === "number" || typeName === "boolean";
1212
1213
  }
1214
+ function resolveJsonType(typeDef, visitorContext) {
1215
+ if ("jsonType" in typeDef)
1216
+ return typeDef.jsonType;
1217
+ const parentType = visitorContext.getType(typeDef.type);
1218
+ if (parentType)
1219
+ return resolveJsonType(parentType, visitorContext);
1220
+ }
1213
1221
  function isAssignable(typeName, type) {
1214
1222
  return (typeof type.name == "string" ? type.name : type.type) === typeName;
1215
1223
  }
@@ -1302,6 +1310,26 @@ var array = (typeDef, visitorContext) => {
1302
1310
  )
1303
1311
  );
1304
1312
  }
1313
+ if (primitiveTypes.length > 1) {
1314
+ const primitivesByJsonType = /* @__PURE__ */ new Map();
1315
+ for (const primitiveType of primitiveTypes) {
1316
+ const jsonType = resolveJsonType(primitiveType, visitorContext);
1317
+ if (jsonType && isPrimitiveTypeName(jsonType)) {
1318
+ const existing = primitivesByJsonType.get(jsonType) || [];
1319
+ existing.push(primitiveType), primitivesByJsonType.set(jsonType, existing);
1320
+ }
1321
+ }
1322
+ for (const [jsonType, types] of primitivesByJsonType)
1323
+ if (types.length > 1) {
1324
+ const typeNames = types.map((t) => t.name || t.type);
1325
+ problems.push(
1326
+ warning(
1327
+ `Array cannot contain multiple members with JSON type "${jsonType}" (${humanizeList(typeNames.map(quote$2))}) as there is no way to distinguish between them`,
1328
+ HELP_IDS.ARRAY_OF_DUPLICATE_PRIMITIVE_JSON_TYPE
1329
+ )
1330
+ );
1331
+ }
1332
+ }
1305
1333
  const list = typeDef?.options?.list;
1306
1334
  return !isMixedArray && Array.isArray(list) && (primitiveTypes.length > 0 ? list.forEach((option) => {
1307
1335
  const value = option?.value ?? option;