@sanity/schema
Advanced tools
Comparing version 3.53.1-styled-fork.4 to 3.54.0
@@ -58,3 +58,3 @@ import difference from "lodash/difference.js"; | ||
function extractSchema(schemaDef, extractOptions = {}) { | ||
const inlineFields = /* @__PURE__ */ new Set(), schema = []; | ||
const inlineFields = /* @__PURE__ */ new Set(), documentTypes = /* @__PURE__ */ new Map(), schema = []; | ||
sortByDependencies(schemaDef).forEach((typeName) => { | ||
@@ -65,3 +65,3 @@ const schemaType = schemaDef.get(typeName); | ||
const base = convertBaseType(schemaType); | ||
base !== null && (base.type === "type" && inlineFields.add(schemaType), schema.push(base)); | ||
base !== null && (base.type === "type" && inlineFields.add(schemaType), base.type === "document" && documentTypes.set(typeName, base), schema.push(base)); | ||
}); | ||
@@ -105,4 +105,2 @@ function convertBaseType(schemaType) { | ||
function convertSchemaType(schemaType) { | ||
if (lastType(schemaType)?.name === "document") | ||
return createReferenceTypeNode(schemaType.name); | ||
if (inlineFields.has(schemaType.type)) | ||
@@ -126,2 +124,6 @@ return { type: "inline", name: schemaType.type.name }; | ||
return createObject(schemaType); | ||
if (lastType(schemaType)?.name === "document") { | ||
const doc = documentTypes.get(schemaType.name); | ||
return doc === void 0 ? { type: "unknown" } : { type: "object", attributes: doc?.attributes }; | ||
} | ||
throw new Error(`Type "${schemaType.name}" not found`); | ||
@@ -128,0 +130,0 @@ } |
@@ -53,3 +53,3 @@ "use strict"; | ||
function extractSchema(schemaDef, extractOptions = {}) { | ||
const inlineFields = /* @__PURE__ */ new Set(), schema = []; | ||
const inlineFields = /* @__PURE__ */ new Set(), documentTypes = /* @__PURE__ */ new Map(), schema = []; | ||
sortByDependencies(schemaDef).forEach((typeName) => { | ||
@@ -60,3 +60,3 @@ const schemaType = schemaDef.get(typeName); | ||
const base = convertBaseType(schemaType); | ||
base !== null && (base.type === "type" && inlineFields.add(schemaType), schema.push(base)); | ||
base !== null && (base.type === "type" && inlineFields.add(schemaType), base.type === "document" && documentTypes.set(typeName, base), schema.push(base)); | ||
}); | ||
@@ -100,4 +100,2 @@ function convertBaseType(schemaType) { | ||
function convertSchemaType(schemaType) { | ||
if (lastType(schemaType)?.name === "document") | ||
return groqJs.createReferenceTypeNode(schemaType.name); | ||
if (inlineFields.has(schemaType.type)) | ||
@@ -121,2 +119,6 @@ return { type: "inline", name: schemaType.type.name }; | ||
return createObject(schemaType); | ||
if (lastType(schemaType)?.name === "document") { | ||
const doc = documentTypes.get(schemaType.name); | ||
return doc === void 0 ? { type: "unknown" } : { type: "object", attributes: doc?.attributes }; | ||
} | ||
throw new Error(`Type "${schemaType.name}" not found`); | ||
@@ -123,0 +125,0 @@ } |
{ | ||
"name": "@sanity/schema", | ||
"version": "3.53.1-styled-fork.4+a93ef546cf", | ||
"version": "3.54.0", | ||
"description": "", | ||
@@ -67,3 +67,3 @@ "keywords": [ | ||
"@sanity/generate-help-url": "^3.0.0", | ||
"@sanity/types": "3.53.1-styled-fork.4+a93ef546cf", | ||
"@sanity/types": "3.54.0", | ||
"arrify": "^1.0.1", | ||
@@ -78,3 +78,3 @@ "groq-js": "^1.12.0", | ||
"@jest/globals": "^29.7.0", | ||
"@repo/package.config": "3.53.0", | ||
"@repo/package.config": "3.54.0", | ||
"@sanity/icons": "^3.3.1", | ||
@@ -86,3 +86,3 @@ "@types/arrify": "^1.0.4", | ||
}, | ||
"gitHead": "a93ef546cf6eada681da73245cfccc934022c51f" | ||
"gitHead": "7531cda80b5a9af691a2b3ccf4b96ed04e64f60e" | ||
} |
@@ -70,2 +70,3 @@ import { | ||
const inlineFields = new Set<SanitySchemaType>() | ||
const documentTypes = new Map<string, DocumentSchemaType>() | ||
const schema: SchemaType = [] | ||
@@ -87,2 +88,5 @@ | ||
} | ||
if (base.type === 'document') { | ||
documentTypes.set(typeName, base) | ||
} | ||
@@ -152,6 +156,2 @@ schema.push(base) | ||
function convertSchemaType(schemaType: SanitySchemaType): TypeNode { | ||
if (lastType(schemaType)?.name === 'document') { | ||
return createReferenceTypeNode(schemaType.name) | ||
} | ||
// if we have already seen the base type, we can just reference it | ||
@@ -198,2 +198,10 @@ if (inlineFields.has(schemaType.type!)) { | ||
if (lastType(schemaType)?.name === 'document') { | ||
const doc = documentTypes.get(schemaType.name) | ||
if (doc === undefined) { | ||
return {type: 'unknown'} satisfies UnknownTypeNode | ||
} | ||
return {type: 'object', attributes: doc?.attributes} satisfies ObjectTypeNode | ||
} | ||
throw new Error(`Type "${schemaType.name}" not found`) | ||
@@ -200,0 +208,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1079107
12495
0
0
+ Added@sanity/client@6.21.3(transitive)
+ Added@sanity/eventsource@5.0.2(transitive)
+ Added@sanity/types@3.54.0(transitive)
+ Added@types/event-source-polyfill@1.0.5(transitive)
+ Added@types/eventsource@1.1.15(transitive)
+ Added@types/follow-redirects@1.14.4(transitive)
+ Added@types/node@22.5.5(transitive)
+ Added@types/progress-stream@2.0.5(transitive)
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@18.3.7(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addeddecompress-response@7.0.0(transitive)
+ Addedevent-source-polyfill@1.0.31(transitive)
+ Addedeventsource@2.0.2(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedget-it@8.6.5(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-retry-allowed@2.2.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmimic-response@3.1.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedprogress-stream@2.0.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedspeedometer@1.0.0(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedtslib@2.7.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedxtend@4.0.2(transitive)
Updated@sanity/types@3.54.0