Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions packages/@sanity/schema/src/descriptors/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,8 @@ const MAX_DEPTH_UKNOWN = 5
type UnknownRecord<T> = {[P in keyof T]: unknown}

export class DescriptorConverter {
opts: Options
cache: WeakMap<Schema, SetSynchronization<RegistryType>> = new WeakMap()

constructor(opts: Options) {
this.opts = opts
}

/**
* Returns a synchronization object for a schema.
*
Expand All @@ -69,7 +64,7 @@ export class DescriptorConverter {

const builder = new SetBuilder()
for (const name of schema.getLocalTypeNames()) {
const typeDef = convertTypeDef(schema.get(name)!, this.opts)
const typeDef = convertTypeDef(schema.get(name)!, {})
builder.addObject('sanity.schema.namedType', {name, typeDef})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async function main() {
let serializedDebug: ValidateSchemaWorkerResult['serializedDebug']

if (debugSerialize) {
const conv = new DescriptorConverter({})
const conv = new DescriptorConverter()
const set = conv.get(schema)
serializedDebug = getSeralizedSchemaDebug(set)
}
Expand Down
19 changes: 1 addition & 18 deletions packages/sanity/src/core/schema/descriptors.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
import {DescriptorConverter} from '@sanity/schema/_internal'
import {type Rule, type SchemaValidationValue} from '@sanity/types'

import {Rule as RuleClass} from '../validation'

export const DESCRIPTOR_CONVERTER = new DescriptorConverter({
ruleClass: RuleClass,
validationExtractor: normalizeValidationValue,
})

function normalizeValidationValue(validation: SchemaValidationValue): Rule[] {
if (!validation) return []

if (Array.isArray(validation)) {
return validation.flatMap((inner) => normalizeValidationValue(inner))
} else if (typeof validation === 'object') {
return [validation]
}
return normalizeValidationValue(validation(new RuleClass()))
}
export const DESCRIPTOR_CONVERTER = new DescriptorConverter()
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {describe, test} from 'vitest'

import {expectManifestSchemaConversion} from './utils'

const DESCRIPTOR_CONVERTER = new DescriptorConverter({})
const DESCRIPTOR_CONVERTER = new DescriptorConverter()

function validate(schema: Schema) {
expectManifestSchemaConversion(schema, DESCRIPTOR_CONVERTER.get(schema))
Expand Down
Loading