@sanity/validation 3.0.7-canary.7 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/validation",
3
- "version": "3.0.7-canary.7+5827f2126",
3
+ "version": "3.1.0",
4
4
  "description": "Validation and warning infrastructure for Sanity projects",
5
5
  "types": "./lib/dts/src/index.d.ts",
6
6
  "source": "./src/index.ts",
@@ -43,17 +43,17 @@
43
43
  "directory": "packages/@sanity/validation"
44
44
  },
45
45
  "dependencies": {
46
- "@sanity/types": "3.0.7-canary.7+5827f2126",
46
+ "@sanity/types": "3.1.0",
47
47
  "date-fns": "^2.26.1",
48
48
  "lodash": "^4.17.21",
49
49
  "rxjs": "^6.5.3"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@sanity/client": "^3.4.1",
53
- "@sanity/schema": "3.0.7-canary.7+5827f2126"
53
+ "@sanity/schema": "3.1.0"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@sanity/client": "^3.4.1"
57
57
  },
58
- "gitHead": "5827f2126326ad677d3733c3565f16e4ae80c1aa"
58
+ "gitHead": "2ac9ccf6c91d452c86e89b450e8a545b13cc69c8"
59
59
  }
package/src/Rule.ts CHANGED
@@ -10,7 +10,6 @@ import {
10
10
  ValidationMarker,
11
11
  RuleTypeConstraint,
12
12
  Validator,
13
- Block,
14
13
  } from '@sanity/types'
15
14
  import {cloneDeep, get} from 'lodash'
16
15
  import ValidationErrorClass from './ValidationError'
@@ -226,13 +225,6 @@ const Rule: RuleClass = class Rule implements IRule {
226
225
  return this.cloneWithRules([{flag: 'custom', constraint: fn as CustomValidator}])
227
226
  }
228
227
 
229
- /**
230
- * @deprecated use `Rule.custom` instead
231
- */
232
- block(fn: CustomValidator<Block>): Rule {
233
- return this.cloneWithRules([{flag: 'custom', constraint: fn as CustomValidator}])
234
- }
235
-
236
228
  min(len: number): Rule {
237
229
  return this.cloneWithRules([{flag: 'min', constraint: len}])
238
230
  }
@@ -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,