@sanity/validation 3.0.7-canary.14 → 3.1.0

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.
@@ -1,5 +1,12 @@
1
1
  import type {SanityClient} from '@sanity/client'
2
- import {Rule, SchemaType, SanityDocument, Schema, ArraySchemaType, Block} from '@sanity/types'
2
+ import {
3
+ Rule,
4
+ SchemaType,
5
+ SanityDocument,
6
+ Schema,
7
+ ArraySchemaType,
8
+ PortableTextTextBlock,
9
+ } from '@sanity/types'
3
10
  import {createSchema} from '../test/createSchema'
4
11
  import {createMockSanityClient} from '../test/mocks/mockSanityClient'
5
12
  import validateDocument, {resolveTypeForArrayItem, validateItem} from './validateDocument'
@@ -346,7 +353,7 @@ describe('validateItem', () => {
346
353
 
347
354
  expect(schema._validation).toHaveLength(0)
348
355
 
349
- const nestedBlock: Block = {
356
+ const nestedBlock: PortableTextTextBlock = {
350
357
  _type: 'block',
351
358
  _key: 'nested-block-key',
352
359
  children: [
@@ -367,7 +374,7 @@ describe('validateItem', () => {
367
374
  style: 'normal',
368
375
  }
369
376
 
370
- const block: Block = {
377
+ const block: PortableTextTextBlock = {
371
378
  _key: 'block-key',
372
379
  _type: 'block',
373
380
  children: [
@@ -6,9 +6,9 @@ import {
6
6
  ValidationMarker,
7
7
  isKeyedObject,
8
8
  isTypedObject,
9
- isBlock,
10
9
  isBlockSchemaType,
11
10
  isSpanSchemaType,
11
+ isPortableTextTextBlock,
12
12
  } from '@sanity/types'
13
13
  import {concat, defer, merge, Observable, of} from 'rxjs'
14
14
  import {catchError, map, mergeAll, mergeMap, toArray} from 'rxjs/operators'
@@ -239,7 +239,7 @@ function validateItemObservable({
239
239
  // markDefs also do no run nested validation if the parent object is undefined
240
240
  // for a similar reason to arrays
241
241
  const shouldRunNestedValidationForMarkDefs =
242
- isBlock(value) && value.markDefs.length && isBlockSchemaType(type)
242
+ isPortableTextTextBlock(value) && value.markDefs?.length && isBlockSchemaType(type)
243
243
 
244
244
  if (shouldRunNestedValidationForMarkDefs) {
245
245
  const [spanChildrenField] = type.fields
@@ -254,7 +254,7 @@ function validateItemObservable({
254
254
  )
255
255
 
256
256
  nestedChecks = nestedChecks.concat(
257
- value.markDefs.map((markDef) =>
257
+ (value.markDefs || []).map((markDef) =>
258
258
  validateItemObservable({
259
259
  ...restOfContext,
260
260
  parent: value,