@sanity/schema 4.20.0 → 4.20.1-next-major.12

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
@@ -2385,10 +2385,10 @@ function extractSchema(schemaDef, extractOptions = {}) {
2385
2385
  function createObject(schemaType) {
2386
2386
  const attributes = {}, fields = gatherFields(schemaType);
2387
2387
  for (const field of fields) {
2388
- const fieldIsRequired = isFieldRequired(field), value = convertSchemaType(field.type);
2388
+ const fieldIsRequired = isFieldRequired(field?.type?.validation), value = convertSchemaType(field.type);
2389
2389
  if (value === null)
2390
2390
  continue;
2391
- hasAssetRequired(field) && value.type === "object" && (value.attributes.asset.optional = !1);
2391
+ hasAssetRequired(field?.type?.validation) && value.type === "object" && (value.attributes.asset.optional = !1);
2392
2392
  const optional = extractOptions.enforceRequiredFields ? fieldIsRequired === !1 : !0;
2393
2393
  attributes[field.name] = {
2394
2394
  type: "objectAttribute",
@@ -2396,7 +2396,7 @@ function extractSchema(schemaDef, extractOptions = {}) {
2396
2396
  optional
2397
2397
  };
2398
2398
  }
2399
- return Object.keys(attributes).length === 0 ? { type: "unknown" } : (schemaType.type?.name !== "document" && schemaType.name !== "object" && (attributes._type = {
2399
+ return extractOptions.enforceRequiredFields && hasAssetRequired(schemaType.validation) && attributes.asset && (attributes.asset.optional = !1), Object.keys(attributes).length === 0 ? { type: "unknown" } : (schemaType.type?.name !== "document" && schemaType.name !== "object" && (attributes._type = {
2400
2400
  type: "objectAttribute",
2401
2401
  value: {
2402
2402
  type: "string",
@@ -2442,8 +2442,7 @@ function createKeyField() {
2442
2442
  }
2443
2443
  };
2444
2444
  }
2445
- function isFieldRequired(field) {
2446
- const { validation } = field.type;
2445
+ function isFieldRequired(validation) {
2447
2446
  if (!validation)
2448
2447
  return !1;
2449
2448
  const rules = Array.isArray(validation) ? validation : [validation];
@@ -2460,8 +2459,7 @@ function isFieldRequired(field) {
2460
2459
  }
2461
2460
  return !1;
2462
2461
  }
2463
- function hasAssetRequired(field) {
2464
- const { validation } = field.type;
2462
+ function hasAssetRequired(validation) {
2465
2463
  if (!validation)
2466
2464
  return !1;
2467
2465
  const rules = Array.isArray(validation) ? validation : [validation];