sanity-advanced-validators 0.5.2 → 0.6.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.
Files changed (2) hide show
  1. package/README.md +36 -12
  2. package/package.json +2 -4
package/README.md CHANGED
@@ -9,10 +9,10 @@ This package includes a set of Sanity validators for aggressive and weird edge c
9
9
  - [fileExtension](#fileExtension)
10
10
  - [minDimensions](#minDimensions)
11
11
  - [maxDimensions](#maxDimensions)
12
- - [minCount](#minCount) 🆕
13
- - [maxCount](#maxCount) 🆕
14
- - [requiredIfSiblingEq](#requiredIfSiblingEq)
15
- - [requiredIfSiblingNeq](#requiredIfSiblingNeq)
12
+ - [minCount](#minCount)
13
+ - [maxCount](#maxCount)
14
+ - [requiredIfSiblingEq](#requiredIfSiblingEq) 🆕
15
+ - [requiredIfSiblingNeq](#requiredIfSiblingNeq) 🆕
16
16
  - [requiredIfSlugEq](#requiredIfSlugEq)
17
17
  - [requiredIfSlugNeq](#requiredIfSlugNeq)
18
18
  - [regex](#regex)
@@ -28,6 +28,8 @@ Imagine that you’ve got a document that has an optional video file, but…
28
28
  - and there must be a poster image that's between **1250x800** and **2500x1600** pixels in size
29
29
 
30
30
  ```typescript
31
+ import { requiredIfSlugEq, requiredIfSiblingNeq, minDimensions, maxDimensions } from 'sanity-advanced-validators'
32
+
31
33
  const Page = defineType({
32
34
  name: "page",
33
35
  type: "document",
@@ -78,7 +80,7 @@ message?: string // optional custom error message; replaces {validFileExtension}
78
80
  ```
79
81
 
80
82
  ```typescript
81
- import { fileExtension } from "sanity-advanced-validation"
83
+ import { fileExtension } from "sanity-advanced-validators"
82
84
 
83
85
  const Page = defineType({
84
86
  name: "page",
@@ -116,7 +118,7 @@ message?: string // optional custom error message; replaces {x} and {y} with you
116
118
  ```
117
119
 
118
120
  ```typescript
119
- import { minDimensions } from "sanity-advanced-validation"
121
+ import { minDimensions } from "sanity-advanced-validators"
120
122
 
121
123
  const ImageWithCaption = defineType({
122
124
  name: "article",
@@ -223,6 +225,24 @@ defineField({
223
225
  }),
224
226
  ```
225
227
 
228
+ And of course it can be chained.
229
+
230
+ ```typescript
231
+ defineField({
232
+ name: "thumbnails",
233
+ type: "array",
234
+ of: [ {type: 'image'} ],
235
+ validation: (rule) =>
236
+ rule.required()
237
+ .custom(
238
+ minCount(1, "At least one thumbnail is required.")
239
+ ),
240
+ .custom(
241
+ maxCount(3, "1-3 thumbnails are required.")
242
+ ),
243
+ }),
244
+ ```
245
+
226
246
  ---
227
247
 
228
248
  ### requiredIfSiblingEq
@@ -231,6 +251,8 @@ Mark a field as `required` if a sibling field has a particular value. This is th
231
251
 
232
252
  This is handy if you have a field that is hidden under some circumstances, but is `required()` when it’s visible.
233
253
 
254
+ 🆕 Previously, this would not work for objects that were members of an array. That is fixed now.
255
+
234
256
  _note:_ This does not work for slugs, because they have to match a nested `.current` value. Use the [requiredIfSlugEq validator](#requiredIfSlugEq) instead.
235
257
 
236
258
  ```typescript
@@ -240,7 +262,7 @@ message?: string // optional custom error message; replaces {key} and {operand}
240
262
  ```
241
263
 
242
264
  ```typescript
243
- import {requiredIfSiblingEq} from 'sanity-advanced-validation'
265
+ import {requiredIfSiblingEq} from 'sanity-advanced-validators'
244
266
 
245
267
  defineType({
246
268
  name: 'person',
@@ -343,6 +365,8 @@ defineType({
343
365
 
344
366
  For a given object that has multiple fields, mark a field as `required` if a sibling does _not_ have a particular value (or member of an array of values).
345
367
 
368
+ 🆕 Previously, this would not work for objects that were members of an array. That is fixed now.
369
+
346
370
  _note:_ This does not work for slugs, because they have to match a nested `.current` value. Use the [requiredIfSlugNeq validator](#requiredIfSlugNeq) instead.
347
371
 
348
372
  ```typescript
@@ -352,7 +376,7 @@ message?: string // optional custom error message; replaces {key} and {operand}
352
376
  ```
353
377
 
354
378
  ```typescript
355
- import {requiredIfSiblingNeq} from 'sanity-advanced-validation'
379
+ import {requiredIfSiblingNeq} from 'sanity-advanced-validators'
356
380
 
357
381
  defineType({
358
382
  name: 'person',
@@ -395,7 +419,7 @@ message?: string // optional custom error message; replaces {slugKey} and {opera
395
419
  ```
396
420
 
397
421
  ```typescript
398
- import { requiredIfSlugEq } from "sanity-advanced-validation"
422
+ import { requiredIfSlugEq } from "sanity-advanced-validators"
399
423
 
400
424
  defineType({
401
425
  name: "page",
@@ -444,7 +468,7 @@ message?: string // optional custom error message; replaces {slugKey} and {opera
444
468
  ```
445
469
 
446
470
  ```typescript
447
- import { requiredIfSlugNeq } from "sanity-advanced-validation"
471
+ import { requiredIfSlugNeq } from "sanity-advanced-validators"
448
472
 
449
473
  defineType({
450
474
  name: "page",
@@ -584,12 +608,12 @@ const navLink = defineType({
584
608
 
585
609
  ```typescript
586
610
  maxDepth: number // maximum "depth" of embedding (including parent)
587
- key: string, // name of the field that includes the cursive value (i.e. the field’s own name)
611
+ key: string, // name of the field that includes the recursive value (i.e. the field’s own name)
588
612
  message?: string // optional custom error message; replaces {maxDepth} and {key} with your input
589
613
  ```
590
614
 
591
615
  ```typescript
592
- import { maxDepth } from "sanity-advanced-validation"
616
+ import { maxDepth } from "sanity-advanced-validators"
593
617
 
594
618
  const navLink = defineType({
595
619
  // …
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "package-name": "sanity-advanced-validators",
3
- "version": "0.5.2",
3
+ "version": "0.6.0",
4
4
  "description": "Advanced input validation tools for Sanity CMS.",
5
5
  "author": "Eric_WVGG",
6
6
  "license": "MIT",
@@ -22,11 +22,9 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "@sanity/asset-utils": "^2.2.1",
25
- "lodash-es": "^4.17.0",
26
- "sanity": "^3.9.0"
25
+ "sanity": "^4.9.0"
27
26
  },
28
27
  "devDependencies": {
29
- "@types/lodash-es": "^4.17.0",
30
28
  "tsup": "^8.5.0",
31
29
  "typescript": "^5.8.0",
32
30
  "vitest": "^3.2.4"