Skip to content

Commit

Permalink
refactor(validation): update pt types
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed Dec 20, 2022
1 parent 5f92213 commit acc0e79
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions packages/@sanity/validation/src/validateDocument.test.ts
@@ -1,5 +1,12 @@
import type {SanityClient} from '@sanity/client'
import {Rule, SchemaType, SanityDocument, Schema, ArraySchemaType, Block} from '@sanity/types'
import {
Rule,
SchemaType,
SanityDocument,
Schema,
ArraySchemaType,
PortableTextTextBlock,
} from '@sanity/types'
import {createSchema} from '../test/createSchema'
import {createMockSanityClient} from '../test/mocks/mockSanityClient'
import validateDocument, {resolveTypeForArrayItem, validateItem} from './validateDocument'
Expand Down Expand Up @@ -346,7 +353,7 @@ describe('validateItem', () => {

expect(schema._validation).toHaveLength(0)

const nestedBlock: Block = {
const nestedBlock: PortableTextTextBlock = {
_type: 'block',
_key: 'nested-block-key',
children: [
Expand All @@ -367,7 +374,7 @@ describe('validateItem', () => {
style: 'normal',
}

const block: Block = {
const block: PortableTextTextBlock = {
_key: 'block-key',
_type: 'block',
children: [
Expand Down
6 changes: 3 additions & 3 deletions packages/@sanity/validation/src/validateDocument.ts
Expand Up @@ -6,9 +6,9 @@ import {
ValidationMarker,
isKeyedObject,
isTypedObject,
isBlock,
isBlockSchemaType,
isSpanSchemaType,
isPortableTextTextBlock,
} from '@sanity/types'
import {concat, defer, merge, Observable, of} from 'rxjs'
import {catchError, map, mergeAll, mergeMap, toArray} from 'rxjs/operators'
Expand Down Expand Up @@ -239,7 +239,7 @@ function validateItemObservable({
// markDefs also do no run nested validation if the parent object is undefined
// for a similar reason to arrays
const shouldRunNestedValidationForMarkDefs =
isBlock(value) && value.markDefs.length && isBlockSchemaType(type)
isPortableTextTextBlock(value) && value.markDefs?.length && isBlockSchemaType(type)

if (shouldRunNestedValidationForMarkDefs) {
const [spanChildrenField] = type.fields
Expand All @@ -254,7 +254,7 @@ function validateItemObservable({
)

nestedChecks = nestedChecks.concat(
value.markDefs.map((markDef) =>
(value.markDefs || []).map((markDef) =>
validateItemObservable({
...restOfContext,
parent: value,
Expand Down

0 comments on commit acc0e79

Please sign in to comment.