@sanity/types 5.0.0-next.0-9b570ece82-202507150640 → 5.0.0-next.6

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/lib/index.d.mts DELETED
@@ -1,3893 +0,0 @@
1
- import {Asset as Asset_2} from '@sanity/media-library-types'
2
- import {AssetInstanceDocument} from '@sanity/media-library-types'
3
- import {ClientPerspective} from '@sanity/client'
4
- import {ComponentType} from 'react'
5
- import {ElementType} from 'react'
6
- import {ReactNode} from 'react'
7
- import {SanityClient} from '@sanity/client'
8
-
9
- /**
10
- * Types of array actions that can be performed
11
- * @beta
12
- */
13
- export declare type ArrayActionName =
14
- /**
15
- * Add any item to the array at any position
16
- */
17
- | 'add'
18
- /**
19
- * Add item after an existing item
20
- */
21
- | 'addBefore'
22
- /**
23
- * Add item after an existing item
24
- */
25
- | 'addAfter'
26
- /**
27
- * Remove any item
28
- */
29
- | 'remove'
30
- /**
31
- * Duplicate item
32
- */
33
- | 'duplicate'
34
- /**
35
- * Copy item
36
- */
37
- | 'copy'
38
-
39
- /** @public */
40
- export declare interface ArrayDefinition extends BaseSchemaDefinition {
41
- type: 'array'
42
- of: ArrayOfType[]
43
- initialValue?: InitialValueProperty<any, unknown[]>
44
- validation?: ValidationBuilder<ArrayRule<unknown[]>, unknown[]>
45
- options?: ArrayOptions
46
- }
47
-
48
- /** @public */
49
- export declare type ArrayOfEntry<T> = Omit<T, 'name' | 'hidden'> & {
50
- name?: string
51
- }
52
-
53
- /** @public */
54
- export declare type ArrayOfType<
55
- TType extends IntrinsicTypeName = IntrinsicTypeName,
56
- TAlias extends IntrinsicTypeName | undefined = undefined,
57
- > = IntrinsicArrayOfDefinition[TType] | ArrayOfEntry<TypeAliasDefinition<string, TAlias>>
58
-
59
- /** @public */
60
- export declare interface ArrayOptions<V = unknown>
61
- extends SearchConfiguration,
62
- BaseSchemaTypeOptions {
63
- list?: TitledListValue<V>[] | V[]
64
- layout?: 'list' | 'tags' | 'grid'
65
- /** @deprecated This option does not have any effect anymore */
66
- direction?: 'horizontal' | 'vertical'
67
- sortable?: boolean
68
- modal?: {
69
- type?: 'dialog' | 'popover'
70
- width?: number | 'auto'
71
- }
72
- /** @alpha This API may change */
73
- insertMenu?: InsertMenuOptions
74
- /**
75
- * A boolean flag to enable or disable tree editing for the array.
76
- * If there are any nested arrays, they will inherit this value.
77
- * @deprecated tree editing beta feature has been disabled
78
- */
79
- treeEditing?: boolean
80
- /**
81
- * A list of array actions to disable
82
- * Possible options are defined by {@link ArrayActionName}
83
- * @beta
84
- */
85
- disableActions?: ArrayActionName[]
86
- }
87
-
88
- /** @public */
89
- export declare interface ArrayRule<Value> extends RuleDef<ArrayRule<Value>, Value> {
90
- min: (length: number | FieldReference) => ArrayRule<Value>
91
- max: (length: number | FieldReference) => ArrayRule<Value>
92
- length: (length: number | FieldReference) => ArrayRule<Value>
93
- unique: () => ArrayRule<Value>
94
- }
95
-
96
- /** @public */
97
- export declare interface ArraySchemaType<V = unknown> extends BaseSchemaType {
98
- jsonType: 'array'
99
- of: (Exclude<SchemaType, ArraySchemaType> | ReferenceSchemaType)[]
100
- options?: ArrayOptions<V> & {
101
- layout?: V extends string ? 'tag' : 'grid'
102
- }
103
- }
104
-
105
- /** @internal */
106
- export declare type ArraySchemaTypeOf<TSchemaType extends ArraySchemaType['of'][number]> = Omit<
107
- ArraySchemaType,
108
- 'of'
109
- > & {
110
- of: TSchemaType[]
111
- }
112
-
113
- /** @public */
114
- export declare interface Asset extends SanityDocument {
115
- url: string
116
- path: string
117
- assetId: string
118
- extension: string
119
- mimeType: string
120
- sha1hash: string
121
- size: number
122
- originalFilename?: string
123
- label?: string
124
- title?: string
125
- description?: string
126
- creditLine?: string
127
- source?: AssetSourceSpec
128
- }
129
-
130
- /** @public */
131
- export declare type AssetFromSource = {
132
- kind: 'assetDocumentId' | 'file' | 'base64' | 'url'
133
- value: string | File_2
134
- assetDocumentProps?: ImageAsset
135
- mediaLibraryProps?: {
136
- mediaLibraryId: string
137
- assetId: string
138
- assetInstanceId: string
139
- }
140
- }
141
-
142
- /** @public */
143
- export declare type AssetMetadataType =
144
- | 'location'
145
- | 'exif'
146
- | 'image'
147
- | 'palette'
148
- | 'lqip'
149
- | 'blurhash'
150
- | 'none'
151
-
152
- /** @public */
153
- export declare interface AssetSchemaTypeOptions {
154
- accept?: string
155
- storeOriginalFilename?: boolean
156
- }
157
-
158
- /** @public */
159
- export declare interface AssetSource {
160
- name: string
161
- /** @deprecated provide `i18nKey` instead */
162
- title?: string
163
- i18nKey?: string
164
- component: ComponentType<AssetSourceComponentProps>
165
- icon?: ComponentType<EmptyProps>
166
- /** @beta */
167
- Uploader?: AssetSourceUploaderClass
168
- }
169
-
170
- /** @public */
171
- export declare interface AssetSourceComponentProps {
172
- action?: 'select' | 'upload'
173
- assetSource: AssetSource
174
- assetType?: 'file' | 'image' | 'sanity.video'
175
- accept: string
176
- selectionType: 'single'
177
- dialogHeaderTitle?: React.ReactNode
178
- selectedAssets: Asset[]
179
- onClose: () => void
180
- onSelect: (assetFromSource: AssetFromSource[]) => void
181
- schemaType?: ImageSchemaType | FileSchemaType
182
- /** @beta */
183
- uploader?: AssetSourceUploader
184
- }
185
-
186
- /** @public */
187
- export declare interface AssetSourceSpec {
188
- id: string
189
- name: string
190
- url?: string
191
- }
192
-
193
- /** @beta */
194
- export declare interface AssetSourceUploader {
195
- upload(
196
- files: globalThis.File[],
197
- options?: {
198
- /**
199
- * The schema type of the field the asset is being uploaded to.
200
- * May be of interest to the uploader to read file and image options.
201
- */
202
- schemaType?: SchemaType
203
- /**
204
- * The uploader may send patches directly to the field
205
- * Typed 'unknown' as we don't have patch definitions in sanity/types yet.
206
- */
207
- onChange?: (patch: unknown) => void
208
- },
209
- ): AssetSourceUploadFile[]
210
- /**
211
- * Abort the upload of a file
212
- */
213
- abort(file?: AssetSourceUploadFile): void
214
- /**
215
- * Get the files that are currently being uploaded
216
- */
217
- getFiles(): AssetSourceUploadFile[]
218
- /**
219
- * Subscribe to upload events from the uploader
220
- */
221
- subscribe(subscriber: (event: AssetSourceUploadEvent) => void): () => void
222
- /**
223
- * Update the status of a file. Will be emitted to subscribers.
224
- */
225
- updateFile(
226
- fileId: string,
227
- data: {
228
- progress?: number
229
- status?: string
230
- error?: Error
231
- },
232
- ): void
233
- /**
234
- * Reset the uploader (clear files). Should be called by the uploader when all files are done.
235
- */
236
- reset(): void
237
- }
238
-
239
- /** @beta */
240
- export declare type AssetSourceUploaderClass = new (...args: any[]) => AssetSourceUploader
241
-
242
- /** @beta */
243
- export declare type AssetSourceUploadEvent =
244
- | AssetSourceUploadEventProgress
245
- | AssetSourceUploadEventStatus
246
- | AssetSourceUploadEventAllComplete
247
- | AssetSourceUploadEventError
248
- | AssetSourceUploadEventAbort
249
-
250
- /**
251
- * Emitted when all files are done, either successfully, aborted or with errors
252
- * @beta */
253
- export declare type AssetSourceUploadEventAbort = {
254
- type: 'abort'
255
- /**
256
- * Files aborted
257
- */
258
- files: AssetSourceUploadFile[]
259
- }
260
-
261
- /**
262
- * Emitted when all files are done, either successfully, aborted or with errors
263
- * @beta */
264
- export declare type AssetSourceUploadEventAllComplete = {
265
- type: 'all-complete'
266
- files: AssetSourceUploadFile[]
267
- }
268
-
269
- /**
270
- * Emitted when all files are done, either successfully, aborted or with errors
271
- * @beta */
272
- export declare type AssetSourceUploadEventError = {
273
- type: 'error'
274
- /**
275
- * Files errored
276
- */
277
- files: AssetSourceUploadFile[]
278
- }
279
-
280
- /**
281
- * Emitted when a file upload is progressing
282
- * @beta */
283
- export declare type AssetSourceUploadEventProgress = {
284
- type: 'progress'
285
- file: AssetSourceUploadFile
286
- progress: number
287
- }
288
-
289
- /**
290
- * Emitted when a file upload is changing status
291
- * @beta */
292
- export declare type AssetSourceUploadEventStatus = {
293
- type: 'status'
294
- file: AssetSourceUploadFile
295
- status: AssetSourceUploadFile['status']
296
- }
297
-
298
- /** @beta */
299
- export declare interface AssetSourceUploadFile {
300
- id: string
301
- file: globalThis.File
302
- progress: number
303
- status: 'pending' | 'uploading' | 'complete' | 'error' | 'aborted'
304
- error?: Error
305
- result?: unknown
306
- }
307
-
308
- /** @beta */
309
- export declare type AssetSourceUploadSubscriber = (event: AssetSourceUploadEvent) => void
310
-
311
- /**
312
- * Enhances VSCode autocomplete by using a distinct type for strings.
313
- *
314
- * `AllowOtherStrings` is defined as `string & {}`, an intersection that behaves
315
- * like `string` but is treated differently by TypeScript's type system for
316
- * internal processing. This helps in improving the specificity and relevance of
317
- * autocomplete suggestions by potentially prioritizing `IntrinsicTypeName`
318
- * over general string inputs, addressing issues where `string` type suggestions
319
- * might overshadow more useful specific literals.
320
- *
321
- * @beta
322
- */
323
- export declare type AutocompleteString = string & {}
324
-
325
- /** @public */
326
- export declare interface BaseSchemaDefinition {
327
- name: string
328
- title?: string
329
- description?: string | React.JSX.Element
330
- hidden?: ConditionalProperty
331
- readOnly?: ConditionalProperty
332
- icon?: ComponentType | ReactNode
333
- validation?: unknown
334
- initialValue?: unknown
335
- deprecated?: DeprecatedProperty
336
- }
337
-
338
- /** @public */
339
- export declare interface BaseSchemaType extends Partial<DeprecationConfiguration> {
340
- name: string
341
- title?: string
342
- description?: string
343
- type?: SchemaType
344
- liveEdit?: boolean
345
- readOnly?: ConditionalProperty
346
- hidden?: ConditionalProperty
347
- icon?: ComponentType
348
- initialValue?: InitialValueProperty<any, any>
349
- validation?: SchemaValidationValue
350
- preview?: PreviewConfig
351
- /** @beta */
352
- components?: {
353
- block?: ComponentType<any>
354
- inlineBlock?: ComponentType<any>
355
- annotation?: ComponentType<any>
356
- diff?: ComponentType<any>
357
- field?: ComponentType<any>
358
- input?: ComponentType<any>
359
- item?: ComponentType<any>
360
- preview?: ComponentType<any>
361
- portableText?: {
362
- plugins?: ComponentType<any>
363
- }
364
- }
365
- /**
366
- * @deprecated This will be removed.
367
- */
368
- placeholder?: string
369
- }
370
-
371
- /**
372
- * `BaseOptions` applies to all type options.
373
- *
374
- * It can be extended by interface declaration merging in plugins to provide generic options to all types and fields.
375
- *
376
- * @public
377
- * */
378
- export declare interface BaseSchemaTypeOptions {
379
- sanityCreate?: SanityCreateOptions
380
- canvasApp?: CanvasAppOptions
381
- }
382
-
383
- /**
384
- * Schema definition for a text block annotation object.
385
- *
386
- * @public
387
- * @example The default link annotation
388
- * ```ts
389
- * {
390
- * name: 'blockContent',
391
- * title: 'Content',
392
- * type: 'array',
393
- * of: [
394
- * {
395
- * type: 'block',
396
- * marks: {
397
- * annotations: [
398
- * {
399
- * type: 'object',
400
- * name: 'link',
401
- * fields: [
402
- * {
403
- * type: 'string',
404
- * name: 'href',
405
- * },
406
- * ],
407
- * },
408
- * ]
409
- * },
410
- * }
411
- * ]
412
- * }
413
- * ```
414
- */
415
- export declare interface BlockAnnotationDefinition extends ObjectDefinition {
416
- icon?: ReactNode | ComponentType
417
- }
418
-
419
- /**
420
- * The specific `children` field of a `block` type (`BlockSchemaType`)
421
- * @see BlockSchemaType
422
- *
423
- * @internal
424
- */
425
- export declare type BlockChildrenObjectField = {
426
- name: 'children'
427
- } & ObjectField<ArraySchemaType>
428
-
429
- /**
430
- * Schema definition for text block decorators.
431
- *
432
- * @public
433
- * @example The default set of decorators
434
- * ```ts
435
- * {
436
- * name: 'blockContent',
437
- * title: 'Content',
438
- * type: 'array',
439
- * of: [
440
- * {
441
- * type: 'block',
442
- * marks: {
443
- * decorators: [
444
- * {title: 'Strong', value: 'strong'},
445
- * {title: 'Emphasis', value: 'em'},
446
- * {title: 'Underline', value: 'underline'},
447
- * {title: 'Strike', value: 'strike'},
448
- * {title: 'Code', value: 'code'},
449
- * ]
450
- * }
451
- * }
452
- * ]
453
- * }
454
- * ```
455
- */
456
- export declare interface BlockDecoratorDefinition {
457
- title: string
458
- i18nTitleKey?: string
459
- value: string
460
- icon?: ReactNode | ComponentType
461
- }
462
-
463
- /**
464
- * Schema definition for text blocks.
465
- *
466
- * @public
467
- * @example the default block definition
468
- * ```ts
469
- * {
470
- * name: 'blockContent',
471
- * title: 'Content',
472
- * type: 'array',
473
- * of: [
474
- * {
475
- * type: 'block',
476
- * marks: {
477
- * decorators: [
478
- * {title: 'Strong', value: 'strong'},
479
- * {title: 'Emphasis', value: 'em'},
480
- * {title: 'Underline', value: 'underline'},
481
- * {title: 'Strike', value: 'strike'},
482
- * {title: 'Code', value: 'code'},
483
- * ],
484
- * annotations: [
485
- * {
486
- * type: 'object',
487
- * name: 'link',
488
- * fields: [
489
- * {
490
- * type: 'string',
491
- * name: 'href',
492
- * },
493
- * ],
494
- * },
495
- * ]
496
- * },
497
- * styles: [
498
- * {title: 'Normal', value: 'normal'},
499
- * {title: 'H1', value: 'h1'},
500
- * {title: 'H2', value: 'h2'},
501
- * {title: 'H3', value: 'h3'},
502
- * {title: 'H4', value: 'h4'},
503
- * {title: 'H5', value: 'h5'},
504
- * {title: 'H6', value: 'h6'},
505
- * {title: 'Quote', value: 'blockquote'}
506
- * ],
507
- * lists: [
508
- * {title: 'Bullet', value: 'bullet'},
509
- * {title: 'Number', value: 'number'},
510
- * ],
511
- * },
512
- * ]
513
- * }
514
- * ```
515
- */
516
- export declare interface BlockDefinition extends BaseSchemaDefinition {
517
- type: 'block'
518
- styles?: BlockStyleDefinition[]
519
- lists?: BlockListDefinition[]
520
- marks?: BlockMarksDefinition
521
- of?: ArrayOfType<'object' | 'reference'>[]
522
- initialValue?: InitialValueProperty<any, any[]>
523
- options?: BlockOptions
524
- validation?: ValidationBuilder<BlockRule, any[]>
525
- }
526
-
527
- /**
528
- * Schema definition for a text block list style.
529
- *
530
- * @public
531
- * @example The defaults lists
532
- * ```ts
533
- * {
534
- * name: 'blockContent',
535
- * title: 'Content',
536
- * type: 'array',
537
- * of: [
538
- * {
539
- * type: 'block',
540
- * lists: [
541
- * {title: 'Bullet', value: 'bullet'},
542
- * {title: 'Number', value: 'number'},
543
- * ]
544
- * }
545
- * ]
546
- * }
547
- * ```
548
- */
549
- export declare interface BlockListDefinition {
550
- title: string
551
- i18nTitleKey?: string
552
- value: string
553
- icon?: ReactNode | ComponentType
554
- }
555
-
556
- /**
557
- * A specific `ObjectField` for `list` in `BlockSchemaType`
558
- * @see BlockSchemaType
559
- *
560
- * @internal
561
- */
562
- export declare type BlockListObjectField = {
563
- name: 'list'
564
- } & ObjectField<StringSchemaType>
565
-
566
- /**
567
- * Schema definition for text block marks (decorators and annotations).
568
- *
569
- * @public */
570
- export declare interface BlockMarksDefinition {
571
- decorators?: BlockDecoratorDefinition[]
572
- annotations?: ArrayOfType<'object' | 'reference'>[]
573
- }
574
-
575
- /**
576
- * Schema options for a Block schema definition
577
- * @public */
578
- export declare interface BlockOptions extends BaseSchemaTypeOptions {
579
- /**
580
- * Turn on or off the builtin browser spellchecking. Default is on.
581
- */
582
- spellCheck?: boolean
583
- unstable_whitespaceOnPasteMode?: 'preserve' | 'normalize' | 'remove'
584
- /**
585
- * When enabled, the editor will restrict all line breaks and soft breaks,
586
- * forcing content to remain on a single line. This will also update
587
- * the styling of the editor to reflect the single-line constraint.
588
- *
589
- * Pasting content that is on multiple lines will be normalized to a single line, if possible.
590
- *
591
- * @defaultValue false
592
- */
593
- oneLine?: boolean
594
- }
595
-
596
- /** @public */
597
- export declare interface BlockRule extends RuleDef<BlockRule, any[]> {}
598
-
599
- /**
600
- * Represents the compiled schema shape for `block`s for portable text.
601
- *
602
- * Note: this does _not_ represent the schema definition shape.
603
- *
604
- * @internal
605
- */
606
- export declare interface BlockSchemaType extends ObjectSchemaType {
607
- fields: [BlockChildrenObjectField, BlockStyleObjectField, BlockListObjectField, ...ObjectField[]]
608
- options?: BlockOptions
609
- }
610
-
611
- /**
612
- * Schema definition for a text block style.
613
- * A text block may have a block style like 'header', 'normal', 'lead'
614
- * attached to it, which is stored on the `.style` property for that block.
615
- *
616
- * @public
617
- * @remarks The first defined style will become the default style.´´
618
- * @example The default set of styles
619
- * ```ts
620
- * {
621
- * name: 'blockContent',
622
- * title: 'Content',
623
- * type: 'array',
624
- * of: [
625
- * {
626
- * type: 'block',
627
- * styles: [
628
- * {title: 'Normal', value: 'normal'},
629
- * {title: 'H1', value: 'h1'},
630
- * {title: 'H2', value: 'h2'},
631
- * {title: 'H3', value: 'h3'},
632
- * {title: 'H4', value: 'h4'},
633
- * {title: 'H5', value: 'h5'},
634
- * {title: 'H6', value: 'h6'},
635
- * {title: 'Quote', value: 'blockquote'}
636
- * ]
637
- * }
638
- * ]
639
- * }
640
- * ```
641
- * @example Example of defining a block type with custom styles and render components.
642
- * ```ts
643
- * defineArrayMember({
644
- * type: 'block',
645
- * styles: [
646
- * {
647
- * title: 'Paragraph',
648
- * value: 'paragraph',
649
- * component: ParagraphStyle,
650
- * },
651
- * {
652
- * title: 'Lead',
653
- * value: 'lead',
654
- * component: LeadStyle,
655
- * },
656
- * {
657
- * title: 'Heading',
658
- * value: 'heading',
659
- * component: HeadingStyle,
660
- * },
661
- * ],
662
- * })
663
- * ```
664
- */
665
- export declare interface BlockStyleDefinition {
666
- title: string
667
- value: string
668
- i18nTitleKey?: string
669
- icon?: ReactNode | ComponentType
670
- }
671
-
672
- /**
673
- * A specific `ObjectField` for `style` in `BlockSchemaType`
674
- * @see BlockSchemaType
675
- *
676
- * @internal
677
- */
678
- export declare type BlockStyleObjectField = {
679
- name: 'style'
680
- } & ObjectField<StringSchemaType>
681
-
682
- /** @public */
683
- export declare interface BooleanDefinition extends BaseSchemaDefinition {
684
- type: 'boolean'
685
- options?: BooleanOptions
686
- initialValue?: InitialValueProperty<any, boolean>
687
- validation?: ValidationBuilder<BooleanRule, boolean>
688
- }
689
-
690
- /** @public */
691
- export declare interface BooleanOptions extends BaseSchemaTypeOptions {
692
- layout?: 'switch' | 'checkbox'
693
- }
694
-
695
- /** @public */
696
- export declare interface BooleanRule extends RuleDef<BooleanRule, boolean> {}
697
-
698
- /** @public */
699
- export declare interface BooleanSchemaType extends BaseSchemaType {
700
- jsonType: 'boolean'
701
- options?: BooleanOptions
702
- initialValue?: InitialValueProperty<any, boolean>
703
- }
704
-
705
- /**
706
- * Options for configuring how Canvas app interfaces with the type or field.
707
- *
708
- * @public
709
- */
710
- export declare interface CanvasAppOptions {
711
- /** Set to true to exclude a type or field from appearing in Canvas */
712
- exclude?: boolean
713
- /**
714
- * A short description of what the type or field is used for.
715
- * Purpose can be used to improve how and when content mapping uses the field.
716
- * */
717
- purpose?: string
718
- }
719
-
720
- /** @public */
721
- export declare interface CollapseOptions {
722
- collapsed?: boolean
723
- collapsible?: boolean
724
- /**
725
- * @deprecated Use `collapsible` instead
726
- */
727
- collapsable?: boolean
728
- }
729
-
730
- /**
731
- * this is used to get allow index access (e.g. `RuleSpec['constraint']`) to
732
- * constraint when a rule spec might not have a `constraint` prop
733
- *
734
- * @internal
735
- */
736
- export declare type ConditionalIndexAccess<T, U> = U extends keyof T ? T[U] : undefined
737
-
738
- /** @public */
739
- export declare type ConditionalProperty = boolean | ConditionalPropertyCallback | undefined
740
-
741
- /** @public */
742
- export declare type ConditionalPropertyCallback = (
743
- context: ConditionalPropertyCallbackContext,
744
- ) => boolean
745
-
746
- /** @public */
747
- export declare interface ConditionalPropertyCallbackContext {
748
- document: SanityDocument | undefined
749
- parent: any
750
- value: any
751
- currentUser: Omit<CurrentUser, 'role'> | null
752
- }
753
-
754
- /** @internal */
755
- export declare interface CreateIfNotExistsMutation {
756
- createIfNotExists: {
757
- _id: string
758
- _type: string
759
- [key: string]: unknown
760
- }
761
- }
762
-
763
- /** @internal */
764
- export declare interface CreateMutation {
765
- create: {
766
- _id?: string
767
- _type: string
768
- [key: string]: unknown
769
- }
770
- }
771
-
772
- /** @internal */
773
- export declare interface CreateOrReplaceMutation {
774
- createOrReplace: {
775
- _id: string
776
- _type: string
777
- [key: string]: unknown
778
- }
779
- }
780
-
781
- /**
782
- * Mutation type used when the document has passed the threshold of the
783
- * "history retention" - any transactions done prior to the threshold gets "squashed"
784
- * into a single "create" transaction.
785
- *
786
- * @internal
787
- */
788
- export declare interface CreateSquashedMutation {
789
- createSquashed: {
790
- /**
791
- * The user IDs of all the users who contributed to the document prior to the squashing
792
- */
793
- authors: string[]
794
- /**
795
- * User ID of the person who initially created the document
796
- */
797
- createdBy: string
798
- /**
799
- * ISO-formatted timestamp (zulu-time) of when the document as initially created
800
- */
801
- createdAt: string
802
- /**
803
- * The document as it exists after squashing has occurred
804
- */
805
- document: {
806
- _id: string
807
- _type: string
808
- [key: string]: unknown
809
- }
810
- }
811
- }
812
-
813
- /** @public */
814
- export declare interface CrossDatasetReferenceDefinition extends BaseSchemaDefinition {
815
- type: 'crossDatasetReference'
816
- weak?: boolean
817
- to: {
818
- type: string
819
- title?: string
820
- icon?: ComponentType
821
- preview?: PreviewConfig
822
- /**
823
- * @deprecated Unused. Configuring search is no longer supported.
824
- */
825
- __experimental_search?: {
826
- path: string | string[]
827
- weight?: number
828
- mapWith?: string
829
- }[]
830
- }[]
831
- dataset: string
832
- studioUrl?: (document: {id: string; type?: string}) => string | null
833
- tokenId?: string
834
- options?: ReferenceOptions
835
- /**
836
- * @deprecated Cross-project references are no longer supported, only cross-dataset
837
- */
838
- projectId?: string
839
- }
840
-
841
- /** @beta */
842
- export declare type CrossDatasetReferenceFilterResolver = (options: {
843
- document: SanityDocument
844
- parent?: Record<string, unknown> | Record<string, unknown>[]
845
- parentPath: Path
846
- }) => CrossDatasetReferenceFilterSearchOptions | Promise<CrossDatasetReferenceFilterSearchOptions>
847
-
848
- /** @beta */
849
- export declare type CrossDatasetReferenceFilterSearchOptions = {
850
- filter?: string
851
- params?: Record<string, unknown>
852
- tag?: string
853
- }
854
-
855
- /** @beta */
856
- export declare interface CrossDatasetReferenceSchemaType extends Omit<ObjectSchemaType, 'options'> {
857
- jsonType: 'object'
858
- to: CrossDatasetType[]
859
- dataset: string
860
- studioUrl?: (document: {id: string; type?: string}) => string | null
861
- weak?: boolean
862
- options?: ReferenceFilterOptions
863
- }
864
-
865
- /** @beta */
866
- export declare interface CrossDatasetReferenceValue {
867
- _type: string
868
- _dataset: string
869
- _projectId: string
870
- _ref: string
871
- _key?: string
872
- _weak?: boolean
873
- }
874
-
875
- /** @beta */
876
- export declare interface CrossDatasetType {
877
- type: string
878
- title?: string
879
- icon: ComponentType
880
- preview: PreviewConfig
881
- /** @deprecated Unused. Configuring search is no longer supported for cross-dataset references. */
882
- __experimental_search: ObjectSchemaType['__experimental_search']
883
- }
884
-
885
- /** @public */
886
- export declare interface CurrentUser {
887
- id: string
888
- name: string
889
- email: string
890
- profileImage?: string
891
- provider?: string
892
- /** @deprecated use `roles` instead */
893
- role: string
894
- roles: Role[]
895
- }
896
-
897
- /** @public */
898
- export declare interface CustomValidator<T = unknown> {
899
- (value: T, context: ValidationContext): CustomValidatorResult | Promise<CustomValidatorResult>
900
- bypassConcurrencyLimit?: boolean
901
- }
902
-
903
- /** @public */
904
- export declare type CustomValidatorResult =
905
- | true
906
- | string
907
- | ValidationError
908
- | ValidationError[]
909
- | LocalizedValidationMessages
910
-
911
- /** @public */
912
- export declare interface DateDefinition extends BaseSchemaDefinition {
913
- type: 'date'
914
- options?: DateOptions
915
- placeholder?: string
916
- validation?: ValidationBuilder<DateRule, string>
917
- initialValue?: InitialValueProperty<any, string>
918
- }
919
-
920
- /** @public */
921
- export declare interface DateOptions extends BaseSchemaTypeOptions {
922
- dateFormat?: string
923
- }
924
-
925
- /** @public */
926
- export declare interface DateRule extends RuleDef<DateRule, string> {
927
- /**
928
- * @param minDate - Minimum date (inclusive). minDate should be in ISO 8601 format.
929
- */
930
- min: (minDate: string | FieldReference) => DateRule
931
- /**
932
- * @param maxDate - Maximum date (inclusive). maxDate should be in ISO 8601 format.
933
- */
934
- max: (maxDate: string | FieldReference) => DateRule
935
- }
936
-
937
- /** @public */
938
- export declare interface DatetimeDefinition extends BaseSchemaDefinition {
939
- type: 'datetime'
940
- options?: DatetimeOptions
941
- placeholder?: string
942
- validation?: ValidationBuilder<DatetimeRule, string>
943
- initialValue?: InitialValueProperty<any, string>
944
- }
945
-
946
- /** @public */
947
- export declare interface DatetimeOptions extends BaseSchemaTypeOptions {
948
- dateFormat?: string
949
- timeFormat?: string
950
- timeStep?: number
951
- displayTimeZone?: string
952
- allowTimeZoneSwitch?: boolean
953
- }
954
-
955
- /** @public */
956
- export declare interface DatetimeRule extends RuleDef<DatetimeRule, string> {
957
- /**
958
- * @param minDate - Minimum date (inclusive). minDate should be in ISO 8601 format.
959
- */
960
- min: (minDate: string | FieldReference) => DatetimeRule
961
- /**
962
- * @param maxDate - Maximum date (inclusive). maxDate should be in ISO 8601 format.
963
- */
964
- max: (maxDate: string | FieldReference) => DatetimeRule
965
- }
966
-
967
- /**
968
- * Define an array item member type within an array definition `of`-array.
969
- *
970
- * This function will narrow the schema type down to fields and options based on the provided
971
- * `type` string.
972
- *
973
- * Using `defineArrayMember` is optional, but should provide improved autocompletion in your IDE, when building your schema.
974
- * Field properties like `validation` and `initialValue` will also be more specific.
975
- *
976
- * See {@link defineType} for example usage.
977
- *
978
- * @param arrayOfSchema - should be a valid `array.of` member definition.
979
- * @param defineOptions - optional param to provide type hints for `arrayOfSchema`.
980
- *
981
- * @see defineType
982
- * @see defineField
983
- * @see typed
984
- *
985
- * @beta
986
- */
987
- export declare function defineArrayMember<
988
- const TType extends IntrinsicTypeName | AutocompleteString,
989
- const TName extends string,
990
- TSelect extends Record<string, string> | undefined,
991
- TPrepareValue extends Record<keyof TSelect, any> | undefined,
992
- TAlias extends IntrinsicTypeName | undefined,
993
- TStrict extends StrictDefinition,
994
- >(
995
- arrayOfSchema: {
996
- type: TType
997
- /**
998
- * When provided, `name` is used as `_type` for the array item when stored.
999
- *
1000
- * Necessary when an array contains multiple entries with the same `type`, each with
1001
- * different configuration (title and initialValue for instance).
1002
- */
1003
- name?: TName
1004
- } & DefineArrayMemberBase<TType, TAlias> &
1005
- NarrowPreview<TType, TAlias, TSelect, TPrepareValue> &
1006
- MaybeAllowUnknownProps<TStrict>,
1007
- defineOptions?: DefineSchemaOptions<TStrict, TAlias>,
1008
- ): typeof arrayOfSchema & WidenValidation & WidenInitialValue
1009
-
1010
- /** @beta */
1011
- export declare type DefineArrayMemberBase<
1012
- TType extends string,
1013
- TAlias extends IntrinsicTypeName | undefined,
1014
- > = TType extends IntrinsicTypeName
1015
- ? IntrinsicArrayOfBase[TType]
1016
- : ArrayOfEntry<TypeAliasDefinition<string, TAlias>>
1017
-
1018
- /**
1019
- * Define a Media Library asset aspect.
1020
- *
1021
- * Aspects can be deployed using the `sanity media deploy-aspect` CLI command.
1022
- *
1023
- * @public
1024
- * @beta
1025
- */
1026
- export declare function defineAssetAspect(
1027
- definition: MediaLibraryAssetAspectDefinition,
1028
- ): MediaLibraryAssetAspectDocument
1029
-
1030
- /**
1031
- * Define a field within a document, object, image or file definition `fields` array.
1032
- *
1033
- * This function will narrow the schema type down to fields and options based on the provided
1034
- * type-string.
1035
- *
1036
- * Using `defineField` is optional, but should provide improved autocompletion in your IDE, when building your schema.
1037
- * Field-properties like `validation` and `initialValue`will also be more specific.
1038
- *
1039
- * See {@link defineType} for more examples.
1040
- *
1041
- * @param schemaField - should be a valid field type definition.
1042
- * @param defineOptions - optional param to provide type hints for `schemaField`.
1043
- *
1044
- * @see defineField
1045
- * @see defineArrayMember
1046
- * @see typed
1047
- *
1048
- * @beta
1049
- */
1050
- export declare function defineField<
1051
- const TType extends IntrinsicTypeName | AutocompleteString,
1052
- const TName extends string,
1053
- TSelect extends Record<string, string> | undefined,
1054
- TPrepareValue extends Record<keyof TSelect, any> | undefined,
1055
- TAlias extends IntrinsicTypeName | undefined,
1056
- TStrict extends StrictDefinition,
1057
- >(
1058
- schemaField: {
1059
- type: TType
1060
- name: TName
1061
- } & DefineSchemaBase<TType, TAlias> &
1062
- NarrowPreview<TType, TAlias, TSelect, TPrepareValue> &
1063
- MaybeAllowUnknownProps<TStrict> &
1064
- FieldDefinitionBase,
1065
- defineOptions?: DefineSchemaOptions<TStrict, TAlias>,
1066
- ): typeof schemaField & WidenValidation & WidenInitialValue
1067
-
1068
- /** @beta */
1069
- export declare type DefineSchemaBase<
1070
- TType extends string,
1071
- TAlias extends IntrinsicTypeName | undefined,
1072
- > = TType extends IntrinsicTypeName ? IntrinsicBase[TType] : TypeAliasDefinition<TType, TAlias>
1073
-
1074
- /** @beta */
1075
- export declare interface DefineSchemaOptions<
1076
- TStrict extends StrictDefinition,
1077
- TAlias extends IntrinsicTypeName | undefined,
1078
- > {
1079
- /**
1080
- * `strict: false` allows unknown properties in the schema.
1081
- * Use this when adding customizations to the schema that are not part of sanity core.
1082
- *
1083
- * If you want to extend the Sanity Schema types with your own properties or options to make them typesafe,
1084
- * you can use [TypeScript declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html).
1085
- *
1086
- * See {@link defineType} for more.
1087
- *
1088
- * @see defineType
1089
- */
1090
- strict?: TStrict
1091
- /** Should be provided when type is a non-intrinsic type, ie type is a type alias */
1092
- aliasFor?: TAlias extends IntrinsicTypeName ? TAlias : never
1093
- }
1094
-
1095
- /** @beta */
1096
- export declare type DefineSchemaType<
1097
- TType extends string,
1098
- TAlias extends IntrinsicTypeName | undefined,
1099
- > = TType extends IntrinsicTypeName
1100
- ? IntrinsicDefinitions[TType]
1101
- : TypeAliasDefinition<TType, TAlias>
1102
-
1103
- /**
1104
- * Helper function for defining a Sanity type definition. This function does not do anything on its own;
1105
- * it exists to check that your schema definition is correct, and help autocompletion in your IDE.
1106
- *
1107
- * This function will narrow the schema type down to fields and options based on the provided type-string.
1108
- *
1109
- * Schema types defined using `defineType` should typically be added to the Studio config under `schema.types`.
1110
- * Defined types can be referenced by their `name`. This is referred to as a type-alias.
1111
- *
1112
- * When using type-aliases as `type`, `defineType` cannot know the base-type, so type-safety will be reduced.
1113
- * If you know the base type of the type-alias, provide `defineOptions.aliasFor: <base type name>`.
1114
- * This will enforce that the schema definition conforms with the provided type.
1115
- *
1116
- * By default, `defineType` only allows known properties and options.
1117
- * Use `defineOptions.strict: false` to allow unknown properties and options.
1118
- *
1119
- * ### Basic usage
1120
- *
1121
- * ```ts
1122
- * defineType({
1123
- * type: 'object',
1124
- * name: 'custom-object',
1125
- * fields: [ {type: 'string', name: 'title', title: 'Title'}],
1126
- * })
1127
- * ```
1128
- *
1129
- * ### Usage with aliasFor narrowing
1130
- *
1131
- * ```ts
1132
- * defineType({
1133
- * type: 'custom-object',
1134
- * name: 'redefined-custom-object',
1135
- * options: {
1136
- * columns: 2
1137
- * }
1138
- * }, {aliasFor: 'object' })
1139
- * ```
1140
- *
1141
- * ### Allow unknown properties
1142
- *
1143
- * ```ts
1144
- * defineType({
1145
- * type: 'custom-object',
1146
- * name: 'redefined-custom-object',
1147
- * allowsUnknownProperties: true
1148
- * options: {
1149
- * columns: 2,
1150
- * allowsUnknownOptions: true
1151
- * }
1152
- * }, {strict: false})
1153
- * ```
1154
- * ### Maximum safety and best autocompletion
1155
- *
1156
- * Use {@link defineType}, {@link defineField} and {@link defineArrayMember}:
1157
- *
1158
- * ```ts
1159
- * defineType({
1160
- * type: 'object',
1161
- * name: 'custom-object',
1162
- * fields: [
1163
- * defineField({
1164
- * type: 'array',
1165
- * name: 'arrayField',
1166
- * title: 'Things',
1167
- * of: [
1168
- * defineArrayMember({
1169
- * type: 'object',
1170
- * name: 'type-name-in-array',
1171
- * fields: [defineField({type: 'string', name: 'title', title: 'Title'})],
1172
- * }),
1173
- * ],
1174
- * }),
1175
- * ],
1176
- * })
1177
- * ```
1178
- *
1179
- * ## Note on type-safety in the current implementation
1180
- *
1181
- * Type-safety inside array-like properties (schema properties like `fields` and `of`) can only be guaranteed when
1182
- * {@link defineField} and {@link defineArrayMember} are used to wrap each value in the array.
1183
- *
1184
- * For array-values without a function-wrapper, TypeScript will resolve to a union type of all possible properties across
1185
- * all schema types. This result in less precise typing.
1186
- *
1187
- * ### Extending the Sanity Schema types
1188
- *
1189
- * If you want to extend the Sanity Schema types with your own properties or options to make them typesafe,
1190
- * you can use [TypeScript declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html).
1191
- *
1192
- * With declaration merging, properties and options will be available in a type-safe manner, and
1193
- * `strict: false` will not be necessary.
1194
- *
1195
- * #### Example: Add option to StringOptions
1196
- *
1197
- * ```ts
1198
- * // string.ts
1199
- *
1200
- * //redeclare the sanity module
1201
- * declare module 'sanity' {
1202
- * // redeclare StringOptions; it will be merged with StringOptions in the sanity module
1203
- * export interface StringOptions {
1204
- * myCustomOption?: boolean
1205
- * }
1206
- * }
1207
- *
1208
- * // the option is now part of the StringOptions type, just as if it was declared in the sanity codebase:
1209
- * defineType({
1210
- * type: 'string',
1211
- * name: 'my-string',
1212
- * options: {
1213
- * myCustomOption: true // this does not give an error anymore
1214
- * }
1215
- * })
1216
- *
1217
- * ```
1218
- *
1219
- * #### Example: Add a schema definition to "intrinsic-types"
1220
- *
1221
- * ```ts
1222
- * //my-custom-type-definition.ts
1223
- *
1224
- * // create a new schema definition based on object (we remove the ability to assign field, change the type add some options)
1225
- * export type MagicallyAddedDefinition = Omit<Schema.ObjectDefinition, 'type' | 'fields'> & {
1226
- * type: 'magically-added-type'
1227
- * options?: {
1228
- * sparkles?: boolean
1229
- * }
1230
- * }
1231
- *
1232
- * // redeclares sanity module so we can add interfaces props to it
1233
- * declare module 'sanity' {
1234
- * // redeclares IntrinsicDefinitions and adds a named definition to it
1235
- * // it is important that the key is the same as the type in the definition ('magically-added-type')
1236
- * export interface IntrinsicDefinitions {
1237
- * 'magically-added-type': MagicallyAddedDefinition
1238
- * }
1239
- * }
1240
- *
1241
- * // defineType will now narrow `type: 'magically-added-type'` to `MagicallyAddedDefinition`
1242
- * defineType({
1243
- * type: 'magically-added-type'
1244
- * name: 'magic',
1245
- * options: {
1246
- * sparkles: true // this is allowed,
1247
- * //@ts-expect-error this is not allowed in MagicallyAddedDefinition.options
1248
- * sparks: true
1249
- * }
1250
- * })
1251
- * ```
1252
- *
1253
- * @param schemaDefinition - should be a valid schema type definition.
1254
- * @param defineOptions - optional param to provide type hints for `schemaDefinition`.
1255
- *
1256
- * @see defineField
1257
- * @see defineArrayMember
1258
- * @see typed
1259
- *
1260
- * @beta
1261
- */
1262
- export declare function defineType<
1263
- const TType extends IntrinsicTypeName | AutocompleteString,
1264
- const TName extends string,
1265
- TSelect extends Record<string, string> | undefined,
1266
- TPrepareValue extends Record<keyof TSelect, any> | undefined,
1267
- TAlias extends IntrinsicTypeName | undefined,
1268
- TStrict extends StrictDefinition,
1269
- >(
1270
- schemaDefinition: {
1271
- type: TType
1272
- name: TName
1273
- } & DefineSchemaBase<TType, TAlias> &
1274
- NarrowPreview<TType, TAlias, TSelect, TPrepareValue> &
1275
- MaybeAllowUnknownProps<TStrict>,
1276
- defineOptions?: DefineSchemaOptions<TStrict, TAlias>,
1277
- ): typeof schemaDefinition
1278
-
1279
- /** @internal */
1280
- export declare interface DeleteMutation {
1281
- delete: MutationSelection
1282
- }
1283
-
1284
- /** @public */
1285
- export declare interface DeprecatedProperty {
1286
- reason: string
1287
- }
1288
-
1289
- /** @public */
1290
- export declare type DeprecatedSchemaType<TSchemaType extends BaseSchemaType = BaseSchemaType> =
1291
- TSchemaType & DeprecationConfiguration
1292
-
1293
- /**
1294
- * @public
1295
- */
1296
- export declare interface DeprecationConfiguration {
1297
- deprecated: DeprecatedProperty
1298
- }
1299
-
1300
- /** @public */
1301
- export declare interface DocumentDefinition extends Omit<ObjectDefinition, 'type'> {
1302
- type: 'document'
1303
- liveEdit?: boolean
1304
- /** @beta */
1305
- orderings?: SortOrdering[]
1306
- options?: DocumentOptions
1307
- validation?: ValidationBuilder<DocumentRule, SanityDocument>
1308
- initialValue?: InitialValueProperty<any, Record<string, unknown>>
1309
- /** @deprecated Unused. Use the new field-level search config. */
1310
- __experimental_search?: {
1311
- path: string
1312
- weight: number
1313
- mapWith?: string
1314
- }[]
1315
- /** @alpha */
1316
- __experimental_omnisearch_visibility?: boolean
1317
- /**
1318
- * Determines whether the large preview title is displayed in the document pane form
1319
- * @alpha
1320
- * */
1321
- __experimental_formPreviewTitle?: boolean
1322
- }
1323
-
1324
- /**
1325
- * This exists only to allow for extensions using declaration-merging.
1326
- *
1327
- * @public
1328
- */
1329
- export declare interface DocumentOptions extends BaseSchemaTypeOptions {}
1330
-
1331
- /** @public */
1332
- export declare interface DocumentRule extends RuleDef<DocumentRule, SanityDocument> {}
1333
-
1334
- /** @public */
1335
- export declare interface EmailDefinition extends BaseSchemaDefinition {
1336
- type: 'email'
1337
- options?: EmailOptions
1338
- placeholder?: string
1339
- validation?: ValidationBuilder<EmailRule, string>
1340
- initialValue?: InitialValueProperty<any, string>
1341
- }
1342
-
1343
- /** @public */
1344
- export declare interface EmailOptions extends BaseSchemaTypeOptions {}
1345
-
1346
- /** @public */
1347
- export declare interface EmailRule extends RuleDef<EmailRule, string> {}
1348
-
1349
- /** @public */
1350
- export declare interface EmptyProps {}
1351
-
1352
- /** @public */
1353
- export declare interface EnumListProps<V = unknown> {
1354
- list?: Array<TitledListValue<V> | V>
1355
- layout?: 'radio' | 'dropdown'
1356
- direction?: 'horizontal' | 'vertical'
1357
- }
1358
-
1359
- /**
1360
- * The shape of a field definition. Note, it's recommended to use the
1361
- * `defineField` function instead of using this type directly.
1362
- *
1363
- * Where `defineField` infers the exact field type,
1364
- * FieldDefinition is a compromise union of all types a field can have.
1365
- *
1366
- * A field definition can be a reference to another registered top-level type
1367
- * or a inline type definition.
1368
- *
1369
- * @public
1370
- */
1371
- export declare type FieldDefinition<
1372
- TType extends IntrinsicTypeName = IntrinsicTypeName,
1373
- TAlias extends IntrinsicTypeName | undefined = undefined,
1374
- > = (InlineFieldDefinition[TType] | TypeAliasDefinition<string, TAlias>) & FieldDefinitionBase
1375
-
1376
- /** @public */
1377
- export declare interface FieldDefinitionBase {
1378
- fieldset?: string
1379
- group?: string | string[]
1380
- }
1381
-
1382
- /** @public */
1383
- export declare interface FieldGroup {
1384
- name: string
1385
- icon?: ComponentType
1386
- title?: string
1387
- description?: string
1388
- i18n?: I18nTextRecord<'title'>
1389
- hidden?: ConditionalProperty
1390
- default?: boolean
1391
- fields?: ObjectField[]
1392
- }
1393
-
1394
- /** @public */
1395
- export declare type FieldGroupDefinition = {
1396
- name: string
1397
- title?: string
1398
- hidden?: ConditionalProperty
1399
- icon?: ComponentType
1400
- default?: boolean
1401
- i18n?: I18nTextRecord<'title'>
1402
- }
1403
-
1404
- /**
1405
- * Holds a reference to a different field
1406
- * NOTE: Only use this through {@link Rule.valueOfField}
1407
- *
1408
- * @public
1409
- */
1410
- export declare interface FieldReference {
1411
- type: symbol
1412
- path: string | string[]
1413
- }
1414
-
1415
- /** @public */
1416
- export declare type FieldRules = {
1417
- [fieldKey: string]: SchemaValidationValue
1418
- }
1419
-
1420
- /** @public */
1421
- export declare type Fieldset = SingleFieldSet | MultiFieldSet
1422
-
1423
- /** @public */
1424
- export declare type FieldsetDefinition = {
1425
- name: string
1426
- title?: string
1427
- description?: string
1428
- group?: string
1429
- hidden?: ConditionalProperty
1430
- readOnly?: ConditionalProperty
1431
- options?: ObjectOptions
1432
- }
1433
-
1434
- /** @public */
1435
- declare interface File_2 {
1436
- [key: string]: unknown
1437
- asset?: Reference
1438
- }
1439
- export {File_2 as File}
1440
-
1441
- /** @public */
1442
- export declare interface FileAsset extends Asset {
1443
- _type: 'sanity.fileAsset'
1444
- metadata: Record<string, unknown>
1445
- }
1446
-
1447
- /** @public */
1448
- export declare interface FileDefinition
1449
- extends Omit<ObjectDefinition, 'type' | 'fields' | 'options' | 'groups' | 'validation'> {
1450
- type: 'file'
1451
- fields?: ObjectDefinition['fields']
1452
- options?: FileOptions
1453
- validation?: ValidationBuilder<FileRule, FileValue>
1454
- initialValue?: InitialValueProperty<any, FileValue>
1455
- }
1456
-
1457
- /** @public */
1458
- export declare interface FileOptions extends ObjectOptions {
1459
- storeOriginalFilename?: boolean
1460
- accept?: string
1461
- sources?: AssetSource[]
1462
- }
1463
-
1464
- /** @public */
1465
- export declare interface FileRule extends RuleDef<FileRule, FileValue> {
1466
- /**
1467
- * Require a file field has an asset.
1468
- *
1469
- * @example
1470
- * ```ts
1471
- * defineField({
1472
- * name: 'file',
1473
- * title: 'File',
1474
- * type: 'file',
1475
- * validation: (Rule) => Rule.required().assetRequired(),
1476
- * })
1477
- * ```
1478
- */
1479
- assetRequired(): FileRule
1480
- }
1481
-
1482
- /** @public */
1483
- export declare interface FileSchemaType extends Omit<ObjectSchemaType, 'options'> {
1484
- options?: FileOptions
1485
- }
1486
-
1487
- /** @public */
1488
- export declare interface FileValue {
1489
- asset?: Reference
1490
- [index: string]: unknown
1491
- }
1492
-
1493
- /** @public */
1494
- export declare interface FormNodeValidation {
1495
- level: 'error' | 'warning' | 'info'
1496
- message: string
1497
- path: Path
1498
- }
1499
-
1500
- /** @public */
1501
- export declare interface GeopointDefinition extends BaseSchemaDefinition {
1502
- type: 'geopoint'
1503
- options?: GeopointOptions
1504
- validation?: ValidationBuilder<GeopointRule, GeopointValue>
1505
- initialValue?: InitialValueProperty<any, Omit<GeopointValue, '_type'>>
1506
- }
1507
-
1508
- /** @public */
1509
- export declare interface GeopointOptions extends BaseSchemaTypeOptions {}
1510
-
1511
- /** @public */
1512
- export declare interface GeopointRule extends RuleDef<GeopointRule, GeopointValue> {}
1513
-
1514
- /**
1515
- * Geographical point representing a pair of latitude and longitude coordinates,
1516
- * stored as degrees, in the World Geodetic System 1984 (WGS 84) format. Also
1517
- * includes an optional `alt` property representing the altitude in meters.
1518
- *
1519
- * @public
1520
- */
1521
- export declare interface GeopointValue {
1522
- /**
1523
- * Type of the object. Must be `geopoint`.
1524
- */
1525
- _type: 'geopoint'
1526
- /**
1527
- * Latitude in degrees
1528
- */
1529
- lat: number
1530
- /**
1531
- * Longitude in degrees
1532
- */
1533
- lng: number
1534
- /**
1535
- * Altitude in meters
1536
- */
1537
- alt?: number
1538
- }
1539
-
1540
- /** @public */
1541
- export declare interface GlobalDocumentReferenceDefinition extends BaseSchemaDefinition {
1542
- type: 'globalDocumentReference'
1543
- weak?: boolean
1544
- to: {
1545
- type: string
1546
- title?: string
1547
- icon?: ComponentType
1548
- preview?: PreviewConfig
1549
- }[]
1550
- resourceType: string
1551
- resourceId: string
1552
- options?: ReferenceOptions
1553
- studioUrl?: string | ((document: {id: string; type?: string}) => string | null)
1554
- }
1555
-
1556
- /** @beta */
1557
- export declare type GlobalDocumentReferenceFilterResolver = (options: {
1558
- document: SanityDocument
1559
- parent?: Record<string, unknown> | Record<string, unknown>[]
1560
- parentPath: Path
1561
- }) =>
1562
- | GlobalDocumentReferenceFilterSearchOptions
1563
- | Promise<GlobalDocumentReferenceFilterSearchOptions>
1564
-
1565
- /** @beta */
1566
- export declare type GlobalDocumentReferenceFilterSearchOptions = {
1567
- filter?: string
1568
- params?: Record<string, unknown>
1569
- tag?: string
1570
- }
1571
-
1572
- /** @beta */
1573
- export declare interface GlobalDocumentReferenceSchemaType
1574
- extends Omit<ObjectSchemaType, 'options'> {
1575
- jsonType: 'object'
1576
- to: GlobalDocumentReferenceType[]
1577
- resourceType: string
1578
- resourceId: string
1579
- studioUrl?: string | ((document: {id: string; type?: string}) => string | null)
1580
- weak?: boolean
1581
- options?: ReferenceFilterOptions
1582
- }
1583
-
1584
- /** @beta */
1585
- export declare interface GlobalDocumentReferenceType {
1586
- type: string
1587
- title?: string
1588
- icon: ComponentType
1589
- preview: PreviewConfig
1590
- /** @deprecated Unused. It's only here for the type to be compatible with createSearchQuery.ts */
1591
- __experimental_search: never
1592
- }
1593
-
1594
- /** @beta */
1595
- export declare interface GlobalDocumentReferenceValue {
1596
- _type: string
1597
- /** The reference to the document. This is a string of the form `a:b:c`,
1598
- * where:
1599
- * - `a` is the resource type, for example `dataset` or `media-library`
1600
- * - `b` is the resource ID, for example data set name or media library ID
1601
- * - `c` is the document ID */
1602
- _ref: `${string}:${string}:${string}`
1603
- _key?: string
1604
- _weak?: boolean
1605
- }
1606
-
1607
- /** @public */
1608
- export declare interface HotspotOptions {
1609
- previews?: HotspotPreview[]
1610
- }
1611
-
1612
- /** @public */
1613
- export declare interface HotspotPreview {
1614
- title: string
1615
- aspectRatio: number
1616
- }
1617
-
1618
- /** @public */
1619
- export declare type I18nTextRecord<K extends string> = {
1620
- [P in K]?: {
1621
- key: string
1622
- ns: string
1623
- }
1624
- }
1625
-
1626
- /** @public */
1627
- export declare interface I18nTitledListValue<V = unknown> {
1628
- _key?: string
1629
- title: string
1630
- i18nTitleKey?: string
1631
- value?: V
1632
- }
1633
-
1634
- /** @public */
1635
- declare interface Image_2 {
1636
- [key: string]: unknown
1637
- asset?: Reference
1638
- crop?: ImageCrop
1639
- hotspot?: ImageHotspot
1640
- }
1641
- export {Image_2 as Image}
1642
-
1643
- /** @public */
1644
- export declare interface ImageAsset extends Asset {
1645
- _type: 'sanity.imageAsset'
1646
- metadata: ImageMetadata
1647
- }
1648
-
1649
- /** @public */
1650
- export declare interface ImageCrop {
1651
- _type?: 'sanity.imageCrop'
1652
- left: number
1653
- bottom: number
1654
- right: number
1655
- top: number
1656
- }
1657
-
1658
- /** @public */
1659
- export declare interface ImageDefinition
1660
- extends Omit<ObjectDefinition, 'type' | 'fields' | 'options' | 'groups' | 'validation'> {
1661
- type: 'image'
1662
- fields?: FieldDefinition[]
1663
- options?: ImageOptions
1664
- validation?: ValidationBuilder<ImageRule, ImageValue>
1665
- initialValue?: InitialValueProperty<any, ImageValue>
1666
- }
1667
-
1668
- /** @public */
1669
- export declare interface ImageDimensions {
1670
- _type: 'sanity.imageDimensions'
1671
- height: number
1672
- width: number
1673
- aspectRatio: number
1674
- }
1675
-
1676
- /** @public */
1677
- export declare interface ImageHotspot {
1678
- _type?: 'sanity.imageHotspot'
1679
- width: number
1680
- height: number
1681
- x: number
1682
- y: number
1683
- }
1684
-
1685
- /** @public */
1686
- export declare interface ImageMetadata {
1687
- [key: string]: unknown
1688
- _type: 'sanity.imageMetadata'
1689
- dimensions: ImageDimensions
1690
- palette?: ImagePalette
1691
- lqip?: string
1692
- blurHash?: string
1693
- hasAlpha: boolean
1694
- isOpaque: boolean
1695
- }
1696
-
1697
- /** @public */
1698
- export declare type ImageMetadataType =
1699
- | 'blurhash'
1700
- | 'lqip'
1701
- | 'palette'
1702
- | 'exif'
1703
- | 'image'
1704
- | 'location'
1705
-
1706
- /** @public */
1707
- export declare interface ImageOptions extends FileOptions {
1708
- metadata?: ImageMetadataType[]
1709
- hotspot?: boolean | HotspotOptions
1710
- }
1711
-
1712
- /** @public */
1713
- export declare interface ImagePalette {
1714
- _type: 'sanity.imagePalette'
1715
- darkMuted?: ImageSwatch
1716
- darkVibrant?: ImageSwatch
1717
- dominant?: ImageSwatch
1718
- lightMuted?: ImageSwatch
1719
- lightVibrant?: ImageSwatch
1720
- muted?: ImageSwatch
1721
- vibrant?: ImageSwatch
1722
- }
1723
-
1724
- /** @public */
1725
- export declare interface ImageRule extends RuleDef<ImageRule, ImageValue> {
1726
- /**
1727
- * Require an image field has an asset.
1728
- *
1729
- * @example
1730
- * ```ts
1731
- * defineField({
1732
- * name: 'image',
1733
- * title: 'Image',
1734
- * type: 'image',
1735
- * validation: (Rule) => Rule.required().assetRequired(),
1736
- * })
1737
- * ```
1738
- */
1739
- assetRequired(): ImageRule
1740
- }
1741
-
1742
- /** @public */
1743
- export declare interface ImageSchemaType extends Omit<ObjectSchemaType, 'options'> {
1744
- options?: ImageOptions
1745
- }
1746
-
1747
- /** @public */
1748
- export declare interface ImageSwatch {
1749
- _type: 'sanity.imagePaletteSwatch'
1750
- background: string
1751
- foreground: string
1752
- population: number
1753
- title?: string
1754
- }
1755
-
1756
- /** @internal */
1757
- export declare type ImageUrlAutoMode = 'format'
1758
-
1759
- /** @internal */
1760
- export declare type ImageUrlCropMode =
1761
- | 'top'
1762
- | 'bottom'
1763
- | 'left'
1764
- | 'right'
1765
- | 'center'
1766
- | 'focalpoint'
1767
- | 'entropy'
1768
-
1769
- /** @internal */
1770
- export declare type ImageUrlFitMode = 'clip' | 'crop' | 'fill' | 'fillmax' | 'max' | 'scale' | 'min'
1771
-
1772
- /** @internal */
1773
- export declare type ImageUrlFormat = 'jpg' | 'pjpg' | 'png' | 'webp'
1774
-
1775
- /** @internal */
1776
- export declare type ImageUrlOrientation = '0' | '90' | '180' | '270'
1777
-
1778
- /**
1779
- * NOTE: These are query parameters, so they will eventually be encoded as strings.
1780
- * However, since most/all query parameter encoders will accept numbers and encode
1781
- * them as strings, we'll use `string| number` where applicable, as it makes it easier
1782
- * to use in places that do calculations and such.
1783
- *
1784
- * @internal
1785
- */
1786
- export declare interface ImageUrlParams {
1787
- 'bg'?: string
1788
- 'dpr'?: number | string
1789
- 'w'?: number | string
1790
- 'h'?: number | string
1791
- 'q'?: number | string
1792
- 'dl'?: string
1793
- 'dlRaw'?: string
1794
- 'fp-x'?: number | string
1795
- 'fp-y'?: number | string
1796
- 'max-w'?: number | string
1797
- 'max-h'?: number | string
1798
- 'min-w'?: number | string
1799
- 'min-h'?: number | string
1800
- 'blur'?: number | string
1801
- 'sharp'?: number | string
1802
- 'rect'?: string
1803
- 'fm'?: ImageUrlFormat
1804
- 'or'?: ImageUrlOrientation
1805
- 'fit'?: ImageUrlFitMode
1806
- 'crop'?: ImageUrlCropMode
1807
- 'auto'?: ImageUrlAutoMode
1808
- 'invert'?: 'true' | 'false'
1809
- 'quality'?: number | string
1810
- 'flip'?: 'h' | 'v' | 'hv'
1811
- 'sat'?: number | string
1812
- 'pad'?: number | string
1813
- 'colorquant'?: number | string
1814
- 'border'?: string
1815
- }
1816
-
1817
- /** @public */
1818
- export declare interface ImageValue extends FileValue {
1819
- crop?: ImageCrop
1820
- hotspot?: ImageHotspot
1821
- [index: string]: unknown
1822
- }
1823
-
1824
- /** @public */
1825
- export declare type IndexTuple = [number | '', number | '']
1826
-
1827
- /** @public */
1828
- export declare type InitialValueProperty<Params, Value> =
1829
- | Value
1830
- | InitialValueResolver<Params, Value>
1831
- | undefined
1832
-
1833
- /** @public */
1834
- export declare type InitialValueResolver<Params, Value> = (
1835
- params: Params | undefined,
1836
- context: InitialValueResolverContext,
1837
- ) => Promise<Value> | Value
1838
-
1839
- /** @public */
1840
- export declare interface InitialValueResolverContext {
1841
- projectId: string
1842
- dataset: string
1843
- schema: Schema
1844
- currentUser: CurrentUser | null
1845
- getClient: (options: {apiVersion: string}) => SanityClient
1846
- }
1847
-
1848
- /** @public */
1849
- export declare type InlineFieldDefinition = {
1850
- [K in keyof IntrinsicDefinitions]: Omit<
1851
- IntrinsicDefinitions[K],
1852
- 'initialValue' | 'validation'
1853
- > & {
1854
- validation?: SchemaValidationValue
1855
- initialValue?: InitialValueProperty<any, any>
1856
- }
1857
- }
1858
-
1859
- /** @alpha This API may change */
1860
- export declare interface InsertMenuOptions {
1861
- /**
1862
- * @defaultValue `'auto'`
1863
- * `filter: 'auto'` automatically turns on filtering if there are more than 5
1864
- * schema types added to the menu.
1865
- */
1866
- filter?: 'auto' | boolean
1867
- groups?: Array<{
1868
- name: string
1869
- title?: string
1870
- of?: Array<string>
1871
- }>
1872
- /** defaultValue `true` */
1873
- showIcons?: boolean
1874
- /** @defaultValue `[{name: 'list'}]` */
1875
- views?: Array<
1876
- | {
1877
- name: 'list'
1878
- }
1879
- | {
1880
- name: 'grid'
1881
- previewImageUrl?: (schemaTypeName: string) => string | undefined
1882
- }
1883
- >
1884
- }
1885
-
1886
- /** @internal */
1887
- export declare type InsertPatch =
1888
- | {
1889
- before: string
1890
- items: unknown[]
1891
- }
1892
- | {
1893
- after: string
1894
- items: unknown[]
1895
- }
1896
- | {
1897
- replace: string
1898
- items: unknown[]
1899
- }
1900
-
1901
- /** @beta */
1902
- export declare type IntrinsicArrayOfBase = {
1903
- [K in keyof IntrinsicDefinitions]: Omit<ArrayOfEntry<IntrinsicDefinitions[K]>, 'preview'>
1904
- }
1905
-
1906
- /** @public */
1907
- export declare type IntrinsicArrayOfDefinition = {
1908
- [K in keyof IntrinsicDefinitions]: Omit<
1909
- ArrayOfEntry<IntrinsicDefinitions[K]>,
1910
- 'validation' | 'initialValue'
1911
- > & {
1912
- validation?: SchemaValidationValue
1913
- initialValue?: InitialValueProperty<any, any>
1914
- }
1915
- }
1916
-
1917
- /** @beta */
1918
- export declare type IntrinsicBase = {
1919
- [K in keyof IntrinsicDefinitions]: Omit<IntrinsicDefinitions[K], 'preview'>
1920
- }
1921
-
1922
- /**
1923
- * `IntrinsicDefinitions` is a lookup map for "predefined" schema definitions.
1924
- * Schema types in `IntrinsicDefinitions` will have good type-completion and type-safety in {@link defineType},
1925
- * {@link defineField} and {@link defineArrayMember} once the `type` property is provided.
1926
- *
1927
- * By default, `IntrinsicDefinitions` contains all standard Sanity schema types (`array`, `string`, `number` ect),
1928
- * but it is an interface and as such, open for extension.
1929
- *
1930
- * This type can be extended using declaration merging; this way new entries can be added.
1931
- * See {@link defineType} for examples on how this can be accomplished.
1932
- *
1933
- * @see defineType
1934
- *
1935
- * @public
1936
- */
1937
- export declare interface IntrinsicDefinitions {
1938
- array: ArrayDefinition
1939
- block: BlockDefinition
1940
- boolean: BooleanDefinition
1941
- date: DateDefinition
1942
- datetime: DatetimeDefinition
1943
- document: DocumentDefinition
1944
- file: FileDefinition
1945
- geopoint: GeopointDefinition
1946
- image: ImageDefinition
1947
- number: NumberDefinition
1948
- object: ObjectDefinition
1949
- reference: ReferenceDefinition
1950
- crossDatasetReference: CrossDatasetReferenceDefinition
1951
- globalDocumentReference: GlobalDocumentReferenceDefinition
1952
- slug: SlugDefinition
1953
- string: StringDefinition
1954
- text: TextDefinition
1955
- url: UrlDefinition
1956
- email: EmailDefinition
1957
- }
1958
-
1959
- /**
1960
- * A union of all intrinsic types allowed natively in the schema.
1961
- *
1962
- * @see IntrinsicDefinitions
1963
- *
1964
- * @public
1965
- */
1966
- export declare type IntrinsicTypeName = IntrinsicDefinitions[keyof IntrinsicDefinitions]['type']
1967
-
1968
- /** @internal */
1969
- export declare function isArrayOfBlocksSchemaType(
1970
- type: unknown,
1971
- ): type is ArraySchemaType<ObjectSchemaType>
1972
-
1973
- /** @internal */
1974
- export declare function isArrayOfObjectsSchemaType(
1975
- type: unknown,
1976
- ): type is ArraySchemaType<ObjectSchemaType>
1977
-
1978
- /** @internal */
1979
- export declare function isArrayOfPrimitivesSchemaType(type: unknown): type is ArraySchemaType
1980
-
1981
- /** @internal */
1982
- export declare function isArraySchemaType(type: unknown): type is ArraySchemaType
1983
-
1984
- /**
1985
- * Check whether the provided value resembles a Media Library asset aspect document.
1986
- *
1987
- * Note: This function does not perform a comprehensive check.
1988
- *
1989
- * @see validateMediaLibraryAssetAspect
1990
- *
1991
- * @internal
1992
- */
1993
- export declare function isAssetAspect(
1994
- maybeAssetAspect: unknown,
1995
- ): maybeAssetAspect is MediaLibraryAssetAspectDocument
1996
-
1997
- /** @internal */
1998
- export declare function isBlockChildrenObjectField(
1999
- field: unknown,
2000
- ): field is BlockChildrenObjectField
2001
-
2002
- /** @internal */
2003
- export declare function isBlockListObjectField(field: unknown): field is BlockListObjectField
2004
-
2005
- /** @internal */
2006
- export declare function isBlockSchemaType(type: unknown): type is BlockSchemaType
2007
-
2008
- /** @internal */
2009
- export declare function isBlockStyleObjectField(field: unknown): field is BlockStyleObjectField
2010
-
2011
- /** @internal */
2012
- export declare function isBooleanSchemaType(type: unknown): type is BooleanSchemaType
2013
-
2014
- /** @internal */
2015
- export declare function isCreateIfNotExistsMutation(
2016
- mutation: Mutation | TransactionLogMutation,
2017
- ): mutation is CreateIfNotExistsMutation
2018
-
2019
- /** @internal */
2020
- export declare function isCreateMutation(
2021
- mutation: Mutation | TransactionLogMutation,
2022
- ): mutation is CreateMutation
2023
-
2024
- /** @internal */
2025
- export declare function isCreateOrReplaceMutation(
2026
- mutation: Mutation | TransactionLogMutation,
2027
- ): mutation is CreateOrReplaceMutation
2028
-
2029
- /** @internal */
2030
- export declare function isCreateSquashedMutation(
2031
- mutation: Mutation | TransactionLogMutation,
2032
- ): mutation is CreateSquashedMutation
2033
-
2034
- /** @beta */
2035
- export declare function isCrossDatasetReference(
2036
- reference: unknown,
2037
- ): reference is CrossDatasetReferenceValue
2038
-
2039
- /** @internal */
2040
- export declare function isCrossDatasetReferenceSchemaType(
2041
- type: unknown,
2042
- ): type is CrossDatasetReferenceSchemaType
2043
-
2044
- /** @internal */
2045
- export declare function isDateTimeSchemaType(type: unknown): type is StringSchemaType
2046
-
2047
- /** @internal */
2048
- export declare function isDeleteMutation(
2049
- mutation: Mutation | TransactionLogMutation,
2050
- ): mutation is DeleteMutation
2051
-
2052
- /** @internal */
2053
- export declare function isDeprecatedSchemaType<TSchemaType extends BaseSchemaType>(
2054
- type: TSchemaType,
2055
- ): type is DeprecatedSchemaType<TSchemaType>
2056
-
2057
- /** @internal */
2058
- export declare function isDeprecationConfiguration(type: unknown): type is DeprecationConfiguration
2059
-
2060
- /**
2061
- * Returns wether or not the given type is a document type
2062
- * (eg that it was defined as `type: 'document'`)
2063
- *
2064
- * @param type - Schema type to test
2065
- * @returns True if type is a document type, false otherwise
2066
- *
2067
- * @public
2068
- */
2069
- export declare function isDocumentSchemaType(type: unknown): type is ObjectSchemaType
2070
-
2071
- /** @internal */
2072
- export declare function isFileSchemaType(type: unknown): type is FileSchemaType
2073
-
2074
- /** @beta */
2075
- export declare function isGlobalDocumentReference(
2076
- reference: unknown,
2077
- ): reference is GlobalDocumentReferenceValue
2078
-
2079
- /** @public */
2080
- export declare function isImage(value: unknown): value is Image_2
2081
-
2082
- /** @internal */
2083
- export declare function isImageSchemaType(type: unknown): type is ImageSchemaType
2084
-
2085
- /** @internal */
2086
- export declare function isIndexSegment(segment: PathSegment): segment is number
2087
-
2088
- /** @internal */
2089
- export declare function isIndexTuple(segment: PathSegment): segment is IndexTuple
2090
-
2091
- /** @public */
2092
- export declare function isKeyedObject(obj: unknown): obj is KeyedObject
2093
-
2094
- /** @internal */
2095
- export declare function isKeySegment(segment: PathSegment): segment is KeyedSegment
2096
-
2097
- /** @internal */
2098
- export declare function isNumberSchemaType(type: unknown): type is NumberSchemaType
2099
-
2100
- /** @internal */
2101
- export declare function isObjectSchemaType(type: unknown): type is ObjectSchemaType
2102
-
2103
- /** @internal */
2104
- export declare function isPatchMutation(
2105
- mutation: Mutation | TransactionLogMutation,
2106
- ): mutation is PatchMutation
2107
-
2108
- /**
2109
- * Assert that a given object is a portable-text list-text-block-type object
2110
- *
2111
- * @remarks
2112
- * Uses `isPortableTextTextBlock` and checks for `listItem` and `level`
2113
- *
2114
- * @see isPortableTextTextBlock
2115
- *
2116
- * @alpha
2117
- */
2118
- export declare function isPortableTextListBlock<T = PortableTextSpan | PortableTextObject>(
2119
- value: unknown,
2120
- ): value is PortableTextTextBlock<T>
2121
-
2122
- /**
2123
- * Assert that a given object is a portable-text span-type object
2124
- *
2125
- * @remarks
2126
- * The `marks` property of a block is optional.
2127
- *
2128
- * @alpha
2129
- */
2130
- export declare function isPortableTextSpan(value: unknown): value is PortableTextSpan
2131
-
2132
- /**
2133
- * Assert that a given object is a portable-text text-block type object
2134
- *
2135
- * @remarks
2136
- * * The `markDefs` and `style` property of a block is optional.
2137
- * * Block types can be named, so expect anything of the _type property.
2138
- *
2139
- * @alpha
2140
- */
2141
- export declare function isPortableTextTextBlock<T = PortableTextSpan | PortableTextObject>(
2142
- value: unknown,
2143
- ): value is PortableTextTextBlock<T>
2144
-
2145
- /** @internal */
2146
- export declare function isPrimitiveSchemaType(
2147
- type: unknown,
2148
- ): type is BooleanSchemaType | StringSchemaType | NumberSchemaType
2149
-
2150
- /** @internal */
2151
- export declare function isReference(reference: unknown): reference is Reference
2152
-
2153
- /** @internal */
2154
- export declare function isReferenceSchemaType(type: unknown): type is ReferenceSchemaType
2155
-
2156
- /** @public */
2157
- export declare function isSanityDocument(document: unknown): document is SanityDocument
2158
-
2159
- /**
2160
- * @internal
2161
- */
2162
- export declare function isSearchStrategy(
2163
- maybeSearchStrategy: unknown,
2164
- ): maybeSearchStrategy is SearchStrategy
2165
-
2166
- /**
2167
- * Checks whether the given `thing` is a slug, eg an object with a `current` string property.
2168
- *
2169
- * @param thing - The thing to check
2170
- * @returns True if slug, false otherwise
2171
- * @public
2172
- */
2173
- export declare function isSlug(thing: unknown): thing is Slug
2174
-
2175
- /** @internal */
2176
- export declare function isSpanSchemaType(type: unknown): type is SpanSchemaType
2177
-
2178
- /** @internal */
2179
- export declare function isStringSchemaType(type: unknown): type is StringSchemaType
2180
-
2181
- /** @internal */
2182
- export declare function isTitledListValue(item: unknown): item is TitledListValue
2183
-
2184
- /** @public */
2185
- export declare function isTypedObject(obj: unknown): obj is TypedObject
2186
-
2187
- /** @internal */
2188
- export declare function isValidationError(node: FormNodeValidation): node is FormNodeValidation & {
2189
- level: 'error'
2190
- }
2191
-
2192
- /** @internal */
2193
- export declare function isValidationErrorMarker(
2194
- marker: ValidationMarker,
2195
- ): marker is ValidationMarker & {
2196
- level: 'error'
2197
- }
2198
-
2199
- /** @internal */
2200
- export declare function isValidationInfo(node: FormNodeValidation): node is FormNodeValidation & {
2201
- level: 'info'
2202
- }
2203
-
2204
- /** @internal */
2205
- export declare function isValidationInfoMarker(
2206
- marker: ValidationMarker,
2207
- ): marker is ValidationMarker & {
2208
- level: 'info'
2209
- }
2210
-
2211
- /** @internal */
2212
- export declare function isValidationWarning(
2213
- node: FormNodeValidation,
2214
- ): node is FormNodeValidation & {
2215
- level: 'warning'
2216
- }
2217
-
2218
- /** @internal */
2219
- export declare function isValidationWarningMarker(
2220
- marker: ValidationMarker,
2221
- ): marker is ValidationMarker & {
2222
- level: 'warning'
2223
- }
2224
-
2225
- /** @public */
2226
- export declare interface KeyedObject {
2227
- [key: string]: unknown
2228
- _key: string
2229
- }
2230
-
2231
- /** @public */
2232
- export declare type KeyedSegment = {
2233
- _key: string
2234
- }
2235
-
2236
- /**
2237
- * Holds localized validation messages for a given field.
2238
- *
2239
- * @example Custom message for English (US) and Norwegian (Bokmål):
2240
- * ```
2241
- * {
2242
- * 'en-US': 'Needs to start with a capital letter',
2243
- * 'no-NB': 'Må starte med stor bokstav',
2244
- * }
2245
- * ```
2246
- * @public
2247
- */
2248
- export declare interface LocalizedValidationMessages {
2249
- [locale: string]: string
2250
- }
2251
-
2252
- /** @beta */
2253
- export declare type MaybeAllowUnknownProps<TStrict extends StrictDefinition> = TStrict extends false
2254
- ? {
2255
- options?: {
2256
- [index: string]: any
2257
- }
2258
- [index: string]: any
2259
- }
2260
- : unknown
2261
-
2262
- /** @beta */
2263
- export declare type MaybePreview<
2264
- Select extends Record<string, string> | undefined,
2265
- PrepareValue extends Record<keyof Select, any> | undefined,
2266
- > =
2267
- Select extends Record<string, string>
2268
- ? PrepareValue extends Record<keyof Select, any>
2269
- ? PreviewConfig<Select, PrepareValue>
2270
- : never
2271
- : never
2272
-
2273
- /**
2274
- * @public
2275
- */
2276
- export declare const MEDIA_LIBRARY_ASSET_ASPECT_TYPE_NAME = 'sanity.asset.aspect'
2277
-
2278
- /** @public */
2279
- export declare type MediaAssetTypes = AssetInstanceDocument['_type']
2280
-
2281
- /**
2282
- * @public
2283
- */
2284
- export declare type MediaLibraryAssetAspectDefinition =
2285
- MediaLibraryAssetAspectSupportedFieldDefinitions & {
2286
- assetType?: MediaLibraryAssetType | MediaLibraryAssetType[]
2287
- }
2288
-
2289
- /**
2290
- * A document representing a Media Library asset aspect.
2291
- *
2292
- * Each aspect provides a schema describing custom data that can be assigned to assets.
2293
- *
2294
- * @public
2295
- */
2296
- export declare interface MediaLibraryAssetAspectDocument extends SanityDocumentLike {
2297
- _type: MediaLibraryAssetAspectTypeName
2298
- /**
2299
- * Asset types the aspect can be assigned to.
2300
- *
2301
- * If no `assetType` is defined, the aspect may be assigned to any asset type.
2302
- */
2303
- assetType?: MediaLibraryAssetType[]
2304
- definition: FieldDefinition
2305
- }
2306
-
2307
- /**
2308
- * @public
2309
- */
2310
- export declare type MediaLibraryAssetAspectSupportedFieldDefinitions = FieldDefinition<
2311
- Exclude<IntrinsicTypeName, 'document' | 'image' | 'file' | 'reference' | 'crossDatasetReference'>
2312
- >
2313
-
2314
- /**
2315
- * @public
2316
- */
2317
- export declare type MediaLibraryAssetAspectTypeName = typeof MEDIA_LIBRARY_ASSET_ASPECT_TYPE_NAME
2318
-
2319
- /**
2320
- * @public
2321
- */
2322
- export declare type MediaLibraryAssetType = ImageAsset['_type'] | FileAsset['_type']
2323
-
2324
- /** @public */
2325
- export declare interface MediaValidationValue<T extends MediaAssetTypes = MediaAssetTypes> {
2326
- /**
2327
- * Media information
2328
- */
2329
- media: {
2330
- /**
2331
- * The Media Library Asset.
2332
- */
2333
- asset: Asset_2 & {
2334
- currentVersion: Extract<
2335
- AssetInstanceDocument,
2336
- {
2337
- _type: T
2338
- }
2339
- >
2340
- }
2341
- }
2342
- /**
2343
- * The field value which the media is used in.
2344
- */
2345
- value: unknown
2346
- }
2347
-
2348
- /** @public */
2349
- export declare interface MediaValidator<T extends MediaAssetTypes = MediaAssetTypes> {
2350
- (
2351
- value: MediaValidationValue<T>,
2352
- context: ValidationContext,
2353
- ): CustomValidatorResult | Promise<CustomValidatorResult>
2354
- }
2355
-
2356
- /**
2357
- * A pair of mendoza patches that can either be _applied_ (to perform the effect),
2358
- * or _reverted_ (to undo the effect). Requires the exact, previous version of the
2359
- * document when applying - any difference might have unexpected consequences.
2360
- *
2361
- * @internal
2362
- */
2363
- export declare interface MendozaEffectPair {
2364
- apply: MendozaPatch
2365
- revert: MendozaPatch
2366
- }
2367
-
2368
- /**
2369
- * A mendoza patch. These are not human-readable patches, but are optimized to
2370
- * take as little space as possible, while still being represented by plain JSON.
2371
- * See {@link https://www.sanity.io/blog/mendoza}
2372
- *
2373
- * @internal
2374
- */
2375
- export declare type MendozaPatch = unknown[]
2376
-
2377
- /** @public */
2378
- export declare interface MultiFieldSet {
2379
- name: string
2380
- title?: string
2381
- description?: string
2382
- single?: false
2383
- group?: string | string[]
2384
- options?: CollapseOptions & {
2385
- columns?: number
2386
- }
2387
- fields: ObjectField[]
2388
- hidden?: ConditionalProperty
2389
- readOnly?: ConditionalProperty
2390
- }
2391
-
2392
- /** @internal */
2393
- export declare interface MultipleMutationResult {
2394
- transactionId: string
2395
- documentIds: string[]
2396
- results: {
2397
- id: string
2398
- }[]
2399
- }
2400
-
2401
- /** @internal */
2402
- export declare type Mutation =
2403
- | CreateMutation
2404
- | CreateOrReplaceMutation
2405
- | CreateIfNotExistsMutation
2406
- | DeleteMutation
2407
- | PatchMutation
2408
-
2409
- /** @internal */
2410
- export declare type MutationOperationName =
2411
- | 'create'
2412
- | 'createOrReplace'
2413
- | 'createIfNotExists'
2414
- | 'delete'
2415
- | 'patch'
2416
-
2417
- /** @internal */
2418
- export declare type MutationSelection =
2419
- | {
2420
- query: string
2421
- params?: Record<string, unknown>
2422
- }
2423
- | {
2424
- id: string
2425
- }
2426
-
2427
- /** @beta */
2428
- export declare type NarrowPreview<
2429
- TType extends string,
2430
- TAlias extends IntrinsicTypeName | undefined,
2431
- TSelect extends Record<string, string> | undefined,
2432
- TPrepareValue extends Record<keyof TSelect, any> | undefined,
2433
- > =
2434
- DefineSchemaType<TType, TAlias> extends {
2435
- preview?: Record<string, any>
2436
- }
2437
- ? {
2438
- preview?: MaybePreview<TSelect, TPrepareValue>
2439
- }
2440
- : unknown
2441
-
2442
- /** @public */
2443
- export declare interface NumberDefinition extends BaseSchemaDefinition {
2444
- type: 'number'
2445
- options?: NumberOptions
2446
- placeholder?: string
2447
- validation?: ValidationBuilder<NumberRule, number>
2448
- initialValue?: InitialValueProperty<any, number>
2449
- }
2450
-
2451
- /** @public */
2452
- export declare interface NumberOptions extends EnumListProps<number>, BaseSchemaTypeOptions {}
2453
-
2454
- /** @public */
2455
- export declare interface NumberRule extends RuleDef<NumberRule, number> {
2456
- min: (minNumber: number | FieldReference) => NumberRule
2457
- max: (maxNumber: number | FieldReference) => NumberRule
2458
- lessThan: (limit: number | FieldReference) => NumberRule
2459
- greaterThan: (limit: number | FieldReference) => NumberRule
2460
- integer: () => NumberRule
2461
- precision: (limit: number | FieldReference) => NumberRule
2462
- positive: () => NumberRule
2463
- negative: () => NumberRule
2464
- }
2465
-
2466
- /** @public */
2467
- export declare interface NumberSchemaType extends BaseSchemaType {
2468
- jsonType: 'number'
2469
- options?: NumberOptions
2470
- initialValue?: InitialValueProperty<any, number>
2471
- }
2472
-
2473
- /** @public */
2474
- export declare interface ObjectDefinition extends BaseSchemaDefinition {
2475
- type: 'object'
2476
- /**
2477
- * Object must have at least one field. This is validated at Studio startup.
2478
- */
2479
- fields: FieldDefinition[]
2480
- groups?: FieldGroupDefinition[]
2481
- fieldsets?: FieldsetDefinition[]
2482
- preview?: PreviewConfig
2483
- options?: ObjectOptions
2484
- validation?: ValidationBuilder<ObjectRule, Record<string, unknown>>
2485
- initialValue?: InitialValueProperty<any, Record<string, unknown>>
2486
- }
2487
-
2488
- /** @public */
2489
- export declare interface ObjectField<T extends SchemaType = SchemaType> {
2490
- name: string
2491
- fieldset?: string
2492
- group?: string | string[]
2493
- type: ObjectFieldType<T>
2494
- }
2495
-
2496
- /** @public */
2497
- export declare type ObjectFieldType<T extends SchemaType = SchemaType> = T & {
2498
- hidden?: ConditionalProperty
2499
- readOnly?: ConditionalProperty
2500
- }
2501
-
2502
- /** @public */
2503
- export declare interface ObjectOptions extends BaseSchemaTypeOptions {
2504
- collapsible?: boolean
2505
- collapsed?: boolean
2506
- columns?: number
2507
- modal?: {
2508
- type?: 'dialog' | 'popover'
2509
- width?: number | number[] | 'auto'
2510
- }
2511
- }
2512
-
2513
- /** @public */
2514
- export declare interface ObjectRule extends RuleDef<ObjectRule, Record<string, unknown>> {}
2515
-
2516
- /** @public */
2517
- export declare interface ObjectSchemaType extends BaseSchemaType {
2518
- jsonType: 'object'
2519
- fields: ObjectField[]
2520
- groups?: FieldGroup[]
2521
- fieldsets?: Fieldset[]
2522
- initialValue?: InitialValueProperty<any, Record<string, unknown>>
2523
- weak?: boolean
2524
- /** @deprecated Unused. Use the new field-level search config. */
2525
- __experimental_search?: {
2526
- path: (string | number)[]
2527
- weight: number
2528
- mapWith?: string
2529
- }[]
2530
- /** @alpha */
2531
- __experimental_omnisearch_visibility?: boolean
2532
- /** @alpha */
2533
- __experimental_actions?: string[]
2534
- /** @alpha */
2535
- __experimental_formPreviewTitle?: boolean
2536
- /**
2537
- * @beta
2538
- */
2539
- orderings?: SortOrdering[]
2540
- options?: any
2541
- }
2542
-
2543
- /** @internal */
2544
- export declare interface ObjectSchemaTypeWithOptions extends Omit<ObjectSchemaType, 'options'> {
2545
- options?: CollapseOptions & {
2546
- columns?: number
2547
- }
2548
- }
2549
-
2550
- /** @internal */
2551
- export declare interface PatchMutation {
2552
- patch: PatchMutationOperation
2553
- }
2554
-
2555
- /** @internal */
2556
- export declare type PatchMutationOperation = PatchOperations & MutationSelection
2557
-
2558
- /**
2559
- * NOTE: this is actually incorrect/invalid, but implemented as-is for backwards compatibility
2560
- *
2561
- * @internal
2562
- */
2563
- export declare interface PatchOperations {
2564
- set?: {
2565
- [key: string]: unknown
2566
- }
2567
- setIfMissing?: {
2568
- [key: string]: unknown
2569
- }
2570
- merge?: {
2571
- [key: string]: unknown
2572
- }
2573
- diffMatchPatch?: {
2574
- [key: string]: string
2575
- }
2576
- unset?: string[]
2577
- inc?: {
2578
- [key: string]: number
2579
- }
2580
- dec?: {
2581
- [key: string]: number
2582
- }
2583
- insert?: InsertPatch
2584
- ifRevisionID?: string
2585
- }
2586
-
2587
- /** @public */
2588
- export declare type Path = PathSegment[]
2589
-
2590
- /** @public */
2591
- export declare type PathSegment = string | number | KeyedSegment | IndexTuple
2592
-
2593
- /** @alpha */
2594
- export declare type PortableTextBlock = PortableTextTextBlock | PortableTextObject
2595
-
2596
- /** @alpha */
2597
- export declare type PortableTextChild = PortableTextObject | PortableTextSpan
2598
-
2599
- /** @alpha */
2600
- export declare interface PortableTextListBlock extends PortableTextTextBlock {
2601
- listItem: string
2602
- level: number
2603
- }
2604
-
2605
- /** @alpha */
2606
- export declare interface PortableTextObject {
2607
- _type: string
2608
- _key: string
2609
- [other: string]: unknown
2610
- }
2611
-
2612
- /** @alpha */
2613
- export declare interface PortableTextSpan {
2614
- _key: string
2615
- _type: 'span'
2616
- text: string
2617
- marks?: string[]
2618
- }
2619
-
2620
- /** @alpha */
2621
- export declare interface PortableTextTextBlock<TChild = PortableTextSpan | PortableTextObject> {
2622
- _type: string
2623
- _key: string
2624
- children: TChild[]
2625
- markDefs?: PortableTextObject[]
2626
- listItem?: string
2627
- style?: string
2628
- level?: number
2629
- }
2630
-
2631
- /** @public */
2632
- export declare interface PrepareViewOptions {
2633
- /** @beta */
2634
- ordering?: SortOrdering
2635
- }
2636
-
2637
- /** @public */
2638
- export declare interface PreviewConfig<
2639
- Select extends Record<string, string> = Record<string, string>,
2640
- PrepareValue extends Record<keyof Select, any> = Record<keyof Select, any>,
2641
- > {
2642
- select?: Select
2643
- prepare?: (value: PrepareValue, viewOptions?: PrepareViewOptions) => PreviewValue
2644
- }
2645
-
2646
- /** @public */
2647
- export declare interface PreviewValue {
2648
- _id?: string
2649
- _createdAt?: string
2650
- _updatedAt?: string
2651
- title?: string
2652
- subtitle?: string
2653
- description?: string
2654
- media?: ReactNode | ElementType
2655
- imageUrl?: string
2656
- }
2657
-
2658
- /** @public */
2659
- export declare interface Reference {
2660
- _type: string
2661
- _ref: string
2662
- _key?: string
2663
- _weak?: boolean
2664
- _strengthenOnPublish?: {
2665
- type: string
2666
- weak?: boolean
2667
- template?: {
2668
- id: string
2669
- params: Record<string, string | number | boolean>
2670
- }
2671
- }
2672
- }
2673
-
2674
- /** @public */
2675
- export declare interface ReferenceBaseOptions extends BaseSchemaTypeOptions {
2676
- disableNew?: boolean
2677
- }
2678
-
2679
- /** @public */
2680
- export declare interface ReferenceDefinition extends BaseSchemaDefinition {
2681
- type: 'reference'
2682
- to: ReferenceTo
2683
- weak?: boolean
2684
- options?: ReferenceOptions
2685
- validation?: ValidationBuilder<ReferenceRule, ReferenceValue>
2686
- initialValue?: InitialValueProperty<any, Omit<ReferenceValue, '_type'>>
2687
- }
2688
-
2689
- /** @public */
2690
- export declare type ReferenceFilterOptions =
2691
- | ReferenceFilterResolverOptions
2692
- | ReferenceFilterQueryOptions
2693
-
2694
- /** @public */
2695
- export declare interface ReferenceFilterQueryOptions {
2696
- filter: string
2697
- filterParams?: Record<string, unknown>
2698
- }
2699
-
2700
- /** @public */
2701
- export declare type ReferenceFilterResolver = (
2702
- context: ReferenceFilterResolverContext,
2703
- ) => ReferenceFilterSearchOptions | Promise<ReferenceFilterSearchOptions>
2704
-
2705
- /** @public */
2706
- export declare interface ReferenceFilterResolverContext {
2707
- document: SanityDocument
2708
- parent?: Record<string, unknown> | Record<string, unknown>[]
2709
- parentPath: Path
2710
- getClient: (options: {apiVersion: string}) => SanityClient
2711
- }
2712
-
2713
- /** @public */
2714
- export declare interface ReferenceFilterResolverOptions {
2715
- filter?: ReferenceFilterResolver
2716
- filterParams?: never
2717
- }
2718
-
2719
- /** @public */
2720
- export declare type ReferenceFilterSearchOptions = {
2721
- filter?: string
2722
- params?: Record<string, unknown>
2723
- tag?: string
2724
- maxFieldDepth?: number
2725
- strategy?: SearchStrategy
2726
- perspective?: ClientPerspective
2727
- }
2728
-
2729
- /**
2730
- * Types are closed for extension. To add properties via declaration merging to this type,
2731
- * redeclare and add the properties to the interfaces that make up ReferenceOptions type.
2732
- *
2733
- * @see ReferenceFilterOptions
2734
- * @see ReferenceFilterResolverOptions
2735
- * @see ReferenceBaseOptions
2736
- *
2737
- * @public
2738
- */
2739
- export declare type ReferenceOptions = ReferenceBaseOptions & ReferenceFilterOptions
2740
-
2741
- /** @public */
2742
- export declare interface ReferenceRule extends RuleDef<ReferenceRule, ReferenceValue> {}
2743
-
2744
- /** @public */
2745
- export declare interface ReferenceSchemaType extends Omit<ObjectSchemaType, 'options'> {
2746
- jsonType: 'object'
2747
- to: ObjectSchemaType[]
2748
- weak?: boolean
2749
- options?: ReferenceOptions
2750
- }
2751
-
2752
- /** @public */
2753
- export declare type ReferenceTo =
2754
- | SchemaTypeDefinition
2755
- | TypeReference
2756
- | Array<SchemaTypeDefinition | TypeReference>
2757
-
2758
- /** @public */
2759
- export declare type ReferenceValue = Reference
2760
-
2761
- /** @public */
2762
- export declare interface Role {
2763
- name: string
2764
- title: string
2765
- description?: string
2766
- }
2767
-
2768
- /** @public */
2769
- export declare interface Rule {
2770
- /**
2771
- * @internal
2772
- * @deprecated internal use only
2773
- */
2774
- _type: RuleTypeConstraint | undefined
2775
- /**
2776
- * @internal
2777
- * @deprecated internal use only
2778
- */
2779
- _level: 'error' | 'warning' | 'info' | undefined
2780
- /**
2781
- * @internal
2782
- * @deprecated internal use only
2783
- */
2784
- _required: 'required' | 'optional' | undefined
2785
- /**
2786
- * @internal
2787
- * @deprecated internal use only
2788
- */
2789
- _typeDef: SchemaType | undefined
2790
- /**
2791
- * @internal
2792
- * @deprecated internal use only
2793
- */
2794
- _message: string | LocalizedValidationMessages | undefined
2795
- /**
2796
- * @internal
2797
- * @deprecated internal use only
2798
- */
2799
- _rules: RuleSpec[]
2800
- /**
2801
- * @internal
2802
- * @deprecated internal use only
2803
- */
2804
- _fieldRules: FieldRules | undefined
2805
- /**
2806
- * Takes in a path and returns an object with a symbol.
2807
- *
2808
- * When the validation lib sees this symbol, it will use the provided path to
2809
- * get a value from the current field's parent and use that value as the input
2810
- * to the Rule.
2811
- *
2812
- * The path that's given is forwarded to `lodash/get`
2813
- *
2814
- * ```js
2815
- * fields: [
2816
- * // ...
2817
- * {
2818
- * // ...
2819
- * name: 'highestTemperature',
2820
- * type: 'number',
2821
- * validation: (Rule) => Rule.positive().min(Rule.valueOfField('lowestTemperature')),
2822
- * // ...
2823
- * },
2824
- * ]
2825
- * ```
2826
- */
2827
- valueOfField: (path: string | string[]) => FieldReference
2828
- error(message?: string | LocalizedValidationMessages): Rule
2829
- warning(message?: string | LocalizedValidationMessages): Rule
2830
- info(message?: string | LocalizedValidationMessages): Rule
2831
- reset(): this
2832
- isRequired(): boolean
2833
- clone(): Rule
2834
- cloneWithRules(rules: RuleSpec[]): Rule
2835
- merge(rule: Rule): Rule
2836
- type(targetType: RuleTypeConstraint | Lowercase<RuleTypeConstraint>): Rule
2837
- all(children: Rule[]): Rule
2838
- either(children: Rule[]): Rule
2839
- optional(): Rule
2840
- required(): Rule
2841
- custom<T = unknown>(
2842
- fn: CustomValidator<T>,
2843
- options?: {
2844
- bypassConcurrencyLimit?: boolean
2845
- },
2846
- ): Rule
2847
- media<T extends MediaAssetTypes = MediaAssetTypes>(fn: MediaValidator<T>): Rule
2848
- min(len: number | string | FieldReference): Rule
2849
- max(len: number | string | FieldReference): Rule
2850
- length(len: number | FieldReference): Rule
2851
- valid(value: unknown | unknown[]): Rule
2852
- integer(): Rule
2853
- precision(limit: number | FieldReference): Rule
2854
- positive(): Rule
2855
- negative(): Rule
2856
- greaterThan(num: number | FieldReference): Rule
2857
- lessThan(num: number | FieldReference): Rule
2858
- uppercase(): Rule
2859
- lowercase(): Rule
2860
- regex(
2861
- pattern: RegExp,
2862
- name: string,
2863
- options: {
2864
- name?: string
2865
- invert?: boolean
2866
- },
2867
- ): Rule
2868
- regex(
2869
- pattern: RegExp,
2870
- options: {
2871
- name?: string
2872
- invert?: boolean
2873
- },
2874
- ): Rule
2875
- regex(pattern: RegExp, name: string): Rule
2876
- regex(pattern: RegExp): Rule
2877
- email(): Rule
2878
- uri(options?: UriValidationOptions): Rule
2879
- unique(): Rule
2880
- reference(): Rule
2881
- fields(rules: FieldRules): Rule
2882
- assetRequired(): Rule
2883
- validate(
2884
- value: unknown,
2885
- options: ValidationContext & {
2886
- /**
2887
- * @deprecated Internal use only
2888
- * @internal
2889
- */
2890
- __internal?: {
2891
- customValidationConcurrencyLimiter?: {
2892
- ready: () => Promise<void>
2893
- release: () => void
2894
- }
2895
- }
2896
- },
2897
- ): Promise<ValidationMarker[]>
2898
- }
2899
-
2900
- /** @public */
2901
- export declare type RuleBuilder<T extends RuleDef<T, FieldValue>, FieldValue = unknown> = T | T[]
2902
-
2903
- /**
2904
- * Note: `RuleClass` and `Rule` are split to fit the current `@sanity/types`
2905
- * setup. Classes are a bit weird in the `@sanity/types` package because classes
2906
- * create an actual javascript class while simultaneously creating a type
2907
- * definition.
2908
- *
2909
- * This implicitly creates two types:
2910
- * 1. the instance type — `Rule` and
2911
- * 2. the static/class type - `RuleClass`
2912
- *
2913
- * The `RuleClass` type contains the static methods and the `Rule` instance
2914
- * contains the instance methods. Downstream in the validation package, the Rule
2915
- * implementation asserts the class declaration is of this type.
2916
- *
2917
- * @internal
2918
- */
2919
- export declare interface RuleClass {
2920
- FIELD_REF: symbol
2921
- array: (def?: SchemaType) => Rule
2922
- object: (def?: SchemaType) => Rule
2923
- string: (def?: SchemaType) => Rule
2924
- number: (def?: SchemaType) => Rule
2925
- boolean: (def?: SchemaType) => Rule
2926
- dateTime: (def?: SchemaType) => Rule
2927
- valueOfField: Rule['valueOfField']
2928
- new (typeDef?: SchemaType): Rule
2929
- }
2930
-
2931
- /** @public */
2932
- export declare interface RuleDef<T, FieldValue = unknown> {
2933
- required: () => T
2934
- custom: <LenientFieldValue extends FieldValue>(
2935
- fn: CustomValidator<LenientFieldValue | undefined>,
2936
- ) => T
2937
- info: (message?: string | LocalizedValidationMessages) => T
2938
- error: (message?: string | LocalizedValidationMessages) => T
2939
- warning: (message?: string | LocalizedValidationMessages) => T
2940
- valueOfField: (path: string | string[]) => FieldReference
2941
- }
2942
-
2943
- /** @public */
2944
- export declare type RuleSpec =
2945
- | {
2946
- flag: 'integer'
2947
- }
2948
- | {
2949
- flag: 'email'
2950
- }
2951
- | {
2952
- flag: 'unique'
2953
- }
2954
- | {
2955
- flag: 'reference'
2956
- }
2957
- | {
2958
- flag: 'type'
2959
- constraint: RuleTypeConstraint
2960
- }
2961
- | {
2962
- flag: 'all'
2963
- constraint: Rule[]
2964
- }
2965
- | {
2966
- flag: 'either'
2967
- constraint: Rule[]
2968
- }
2969
- | {
2970
- flag: 'presence'
2971
- constraint: 'optional' | 'required'
2972
- }
2973
- | {
2974
- flag: 'custom'
2975
- constraint: CustomValidator
2976
- }
2977
- | {
2978
- flag: 'min'
2979
- constraint: number | string | FieldReference
2980
- }
2981
- | {
2982
- flag: 'max'
2983
- constraint: number | string | FieldReference
2984
- }
2985
- | {
2986
- flag: 'length'
2987
- constraint: number | FieldReference
2988
- }
2989
- | {
2990
- flag: 'valid'
2991
- constraint: unknown[]
2992
- }
2993
- | {
2994
- flag: 'precision'
2995
- constraint: number | FieldReference
2996
- }
2997
- | {
2998
- flag: 'lessThan'
2999
- constraint: number | FieldReference
3000
- }
3001
- | {
3002
- flag: 'greaterThan'
3003
- constraint: number | FieldReference
3004
- }
3005
- | {
3006
- flag: 'stringCasing'
3007
- constraint: 'uppercase' | 'lowercase'
3008
- }
3009
- | {
3010
- flag: 'assetRequired'
3011
- constraint: {
3012
- assetType: 'asset' | 'image' | 'file'
3013
- }
3014
- }
3015
- | {
3016
- flag: 'media'
3017
- constraint: MediaValidator<any>
3018
- }
3019
- | {
3020
- flag: 'regex'
3021
- constraint: {
3022
- pattern: RegExp
3023
- name?: string
3024
- invert: boolean
3025
- }
3026
- }
3027
- | {
3028
- flag: 'uri'
3029
- constraint: {
3030
- options: {
3031
- scheme: RegExp[]
3032
- allowRelative: boolean
3033
- relativeOnly: boolean
3034
- allowCredentials: boolean
3035
- }
3036
- }
3037
- }
3038
-
3039
- /** @internal */
3040
- export declare type RuleSpecConstraint<T extends RuleSpec['flag']> = ConditionalIndexAccess<
3041
- Extract<
3042
- RuleSpec,
3043
- {
3044
- flag: T
3045
- }
3046
- >,
3047
- 'constraint'
3048
- >
3049
-
3050
- /** @public */
3051
- export declare type RuleTypeConstraint =
3052
- | 'Array'
3053
- | 'Boolean'
3054
- | 'Date'
3055
- | 'Number'
3056
- | 'Object'
3057
- | 'String'
3058
-
3059
- /**
3060
- * Options for configuring how Sanity Create interfaces with the type or field.
3061
- *
3062
- * @public
3063
- */
3064
- export declare interface SanityCreateOptions {
3065
- /** Set to true to exclude a type or field from appearing in Sanity Create */
3066
- exclude?: boolean
3067
- /**
3068
- * A short description of what the type or field is used for.
3069
- * Purpose can be used to improve how and when content mapping uses the field.
3070
- * */
3071
- purpose?: string
3072
- }
3073
-
3074
- /** @public */
3075
- export declare interface SanityDocument {
3076
- _id: string
3077
- _type: string
3078
- _createdAt: string
3079
- _updatedAt: string
3080
- _rev: string
3081
- [key: string]: unknown
3082
- }
3083
-
3084
- /**
3085
- * Similar to `SanityDocument` but only requires the `_id` and `_type`
3086
- *
3087
- * @see SanityDocument
3088
- *
3089
- * @public
3090
- */
3091
- export declare interface SanityDocumentLike {
3092
- _id: string
3093
- _type: string
3094
- _createdAt?: string
3095
- _updatedAt?: string
3096
- _rev?: string
3097
- _system?: {
3098
- delete?: boolean
3099
- }
3100
- [key: string]: unknown
3101
- }
3102
-
3103
- /** @public */
3104
- export declare interface Schema {
3105
- /** @internal */
3106
- _original?: {
3107
- name: string
3108
- types: SchemaTypeDefinition[]
3109
- }
3110
- /** @internal */
3111
- _registry: {
3112
- [typeName: string]: any
3113
- }
3114
- /** @internal */
3115
- _validation?: SchemaValidationProblemGroup[]
3116
- name: string
3117
- get: (name: string) => SchemaType | undefined
3118
- has: (name: string) => boolean
3119
- getTypeNames: () => string[]
3120
- /**
3121
- * Returns the types which were explicitly defined in this schema,
3122
- * as opposed to the types which were inherited from the parent.
3123
- */
3124
- getLocalTypeNames: () => string[]
3125
- /**
3126
- * Returns the parent schema.
3127
- */
3128
- parent?: Schema
3129
- }
3130
-
3131
- /**
3132
- * Note: you probably want `SchemaTypeDefinition` instead
3133
- * @see SchemaTypeDefinition
3134
- *
3135
- * @public
3136
- */
3137
- export declare type SchemaType =
3138
- | ArraySchemaType
3139
- | BooleanSchemaType
3140
- | FileSchemaType
3141
- | NumberSchemaType
3142
- | ObjectSchemaType
3143
- | StringSchemaType
3144
- | ReferenceSchemaType
3145
-
3146
- /**
3147
- * Represents a Sanity schema type definition with an optional type parameter.
3148
- *
3149
- * It's recommend to use the `defineType` helper instead of this type by
3150
- * itself.
3151
- *
3152
- * @see defineType
3153
- *
3154
- * @public
3155
- */
3156
- export declare type SchemaTypeDefinition<TType extends IntrinsicTypeName = IntrinsicTypeName> =
3157
- | IntrinsicDefinitions[IntrinsicTypeName]
3158
- | TypeAliasDefinition<string, TType>
3159
-
3160
- /** @public */
3161
- export declare interface SchemaValidationError {
3162
- helpId?: string
3163
- message: string
3164
- severity: 'error'
3165
- }
3166
-
3167
- /** @internal */
3168
- export declare type SchemaValidationProblem = SchemaValidationError | SchemaValidationWarning
3169
-
3170
- /** @internal */
3171
- export declare interface SchemaValidationProblemGroup {
3172
- path: SchemaValidationProblemPath
3173
- problems: SchemaValidationProblem[]
3174
- }
3175
-
3176
- /** @internal */
3177
- export declare type SchemaValidationProblemPath = Array<
3178
- | {
3179
- kind: 'type'
3180
- type: string
3181
- name?: string
3182
- }
3183
- | {
3184
- kind: 'property'
3185
- name: string
3186
- }
3187
- >
3188
-
3189
- /**
3190
- * Represents the possible values of a schema type's `validation` field.
3191
- *
3192
- * If the schema has not been run through `inferFromSchema` from
3193
- * `sanity/validation` then value could be a function.
3194
- *
3195
- * `inferFromSchema` mutates the schema converts this value to an array of
3196
- * `Rule` instances.
3197
- *
3198
- * @privateRemarks
3199
- *
3200
- * Usage of the schema inside the studio will almost always be from the compiled
3201
- * `createSchema` function. In this case, you can cast the value or throw to
3202
- * narrow the type. E.g.:
3203
- *
3204
- * ```ts
3205
- * if (typeof type.validation === 'function') {
3206
- * throw new Error(
3207
- * `Schema type "${type.name}"'s \`validation\` was not run though \`inferFromSchema\``
3208
- * )
3209
- * }
3210
- * ```
3211
- *
3212
- * @public
3213
- */
3214
- export declare type SchemaValidationValue =
3215
- | false
3216
- | undefined
3217
- | Rule
3218
- | SchemaValidationValue[]
3219
- | ((rule: Rule) => SchemaValidationValue)
3220
-
3221
- /** @internal */
3222
- export declare interface SchemaValidationWarning {
3223
- helpId?: string
3224
- message: string
3225
- severity: 'warning'
3226
- }
3227
-
3228
- /** @public */
3229
- export declare interface SearchConfiguration {
3230
- search?: {
3231
- /**
3232
- * Defines a search weight for this field to prioritize its importance
3233
- * during search operations in the Studio. This setting allows the specified
3234
- * field to be ranked higher in search results compared to other fields.
3235
- *
3236
- * By default, all fields are assigned a weight of 1. However, if a field is
3237
- * chosen as the `title` in the preview configuration's `select` option, it
3238
- * will automatically receive a default weight of 10. Similarly, if selected
3239
- * as the `subtitle`, the default weight is 5. Fields marked as
3240
- * `hidden: true` (no function) are assigned a weight of 0 by default.
3241
- *
3242
- * Note: Search weight configuration is currently supported only for fields
3243
- * of type string or portable text arrays.
3244
- */
3245
- weight?: number
3246
- }
3247
- }
3248
-
3249
- /**
3250
- * @public
3251
- */
3252
- export declare const searchStrategies: readonly ['groqLegacy', 'groq2024']
3253
-
3254
- /**
3255
- * @public
3256
- */
3257
- export declare type SearchStrategy = (typeof searchStrategies)[number]
3258
-
3259
- /** @public */
3260
- export declare interface SingleFieldSet {
3261
- single: true
3262
- field: ObjectField
3263
- hidden?: ConditionalProperty
3264
- readOnly?: ConditionalProperty
3265
- group?: string | string[]
3266
- }
3267
-
3268
- /** @internal */
3269
- export declare interface SingleMutationResult {
3270
- transactionId: string
3271
- documentId: string
3272
- results: {
3273
- id: string
3274
- }[]
3275
- }
3276
-
3277
- /**
3278
- * A slug object, currently holding a `current` property
3279
- *
3280
- * In the future, this may be extended with a `history` property
3281
- *
3282
- * @public
3283
- */
3284
- export declare interface Slug {
3285
- _type: 'slug'
3286
- current: string
3287
- }
3288
-
3289
- /** @public */
3290
- export declare interface SlugDefinition extends BaseSchemaDefinition {
3291
- type: 'slug'
3292
- options?: SlugOptions
3293
- validation?: ValidationBuilder<SlugRule, SlugValue>
3294
- initialValue?: InitialValueProperty<any, Omit<SlugValue, '_type'>>
3295
- }
3296
-
3297
- /** @public */
3298
- export declare type SlugifierFn = (
3299
- source: string,
3300
- schemaType: SlugSchemaType,
3301
- context: SlugSourceContext,
3302
- ) => string | Promise<string>
3303
-
3304
- /** @public */
3305
- export declare type SlugIsUniqueValidator = (
3306
- slug: string,
3307
- context: SlugValidationContext,
3308
- ) => boolean | Promise<boolean>
3309
-
3310
- /** @public */
3311
- export declare interface SlugOptions extends SearchConfiguration, BaseSchemaTypeOptions {
3312
- source?: string | Path | SlugSourceFn
3313
- maxLength?: number
3314
- slugify?: SlugifierFn
3315
- isUnique?: SlugIsUniqueValidator
3316
- disableArrayWarning?: boolean
3317
- }
3318
-
3319
- /** @public */
3320
- export declare type SlugParent = Record<string, unknown> | Record<string, unknown>[]
3321
-
3322
- /** @public */
3323
- export declare interface SlugRule extends RuleDef<SlugRule, SlugValue> {}
3324
-
3325
- /** @public */
3326
- export declare interface SlugSchemaType extends ObjectSchemaType {
3327
- jsonType: 'object'
3328
- options?: SlugOptions
3329
- }
3330
-
3331
- /** @public */
3332
- export declare interface SlugSourceContext {
3333
- parentPath: Path
3334
- parent: SlugParent
3335
- projectId: string
3336
- dataset: string
3337
- schema: Schema
3338
- currentUser: CurrentUser | null
3339
- getClient: (options: {apiVersion: string}) => SanityClient
3340
- }
3341
-
3342
- /** @public */
3343
- export declare type SlugSourceFn = (
3344
- document: SanityDocument,
3345
- context: SlugSourceContext,
3346
- ) => string | Promise<string>
3347
-
3348
- /** @public */
3349
- export declare interface SlugValidationContext extends ValidationContext {
3350
- parent: SlugParent
3351
- type: SlugSchemaType
3352
- defaultIsUnique: SlugIsUniqueValidator
3353
- }
3354
-
3355
- /** @public */
3356
- export declare interface SlugValue {
3357
- _type: 'slug'
3358
- current?: string
3359
- }
3360
-
3361
- /** @beta */
3362
- export declare type SortOrdering = {
3363
- title: string
3364
- i18n?: I18nTextRecord<'title'>
3365
- name: string
3366
- by: SortOrderingItem[]
3367
- }
3368
-
3369
- /** @beta */
3370
- export declare interface SortOrderingItem {
3371
- field: string
3372
- direction: 'asc' | 'desc'
3373
- }
3374
-
3375
- /**
3376
- * A specific `ObjectField` for `marks` in `SpanSchemaType`
3377
- * @see SpanSchemaType
3378
- *
3379
- * @internal
3380
- */
3381
- export declare type SpanMarksObjectField = {
3382
- name: 'marks'
3383
- } & ObjectField<ArraySchemaTypeOf<StringSchemaType>>
3384
-
3385
- /**
3386
- * Represents the compiled schema shape for `span`s for portable text.
3387
- *
3388
- * Note: this does _not_ represent the schema definition shape.
3389
- *
3390
- * @internal
3391
- */
3392
- export declare interface SpanSchemaType extends Omit<ObjectSchemaType, 'fields'> {
3393
- annotations: (ObjectSchemaType & {
3394
- icon?: string | ComponentType
3395
- components?: {
3396
- item?: ComponentType
3397
- }
3398
- })[]
3399
- decorators: BlockDecoratorDefinition[]
3400
- fields: [SpanMarksObjectField, SpanTextObjectField]
3401
- }
3402
-
3403
- /**
3404
- * A specific `ObjectField` for `text` in `SpanSchemaType`
3405
- * @see SpanSchemaType
3406
- *
3407
- * @internal
3408
- */
3409
- export declare type SpanTextObjectField = {
3410
- name: 'text'
3411
- } & ObjectField<TextSchemaType>
3412
-
3413
- /** @beta */
3414
- export declare type StrictDefinition = boolean | undefined
3415
-
3416
- /** @public */
3417
- export declare interface StringDefinition extends BaseSchemaDefinition {
3418
- type: 'string'
3419
- options?: StringOptions
3420
- placeholder?: string
3421
- validation?: ValidationBuilder<StringRule, string>
3422
- initialValue?: InitialValueProperty<any, string>
3423
- }
3424
-
3425
- /** @public */
3426
- export declare interface StringOptions
3427
- extends EnumListProps<string>,
3428
- SearchConfiguration,
3429
- BaseSchemaTypeOptions {}
3430
-
3431
- /** @public */
3432
- export declare interface StringRule extends RuleDef<StringRule, string> {
3433
- min: (minNumber: number | FieldReference) => StringRule
3434
- max: (maxNumber: number | FieldReference) => StringRule
3435
- length: (exactLength: number | FieldReference) => StringRule
3436
- uppercase: () => StringRule
3437
- lowercase: () => StringRule
3438
- regex(
3439
- pattern: RegExp,
3440
- name: string,
3441
- options: {
3442
- name?: string
3443
- invert?: boolean
3444
- },
3445
- ): StringRule
3446
- regex(
3447
- pattern: RegExp,
3448
- options: {
3449
- name?: string
3450
- invert?: boolean
3451
- },
3452
- ): StringRule
3453
- regex(pattern: RegExp, name: string): StringRule
3454
- regex(pattern: RegExp): StringRule
3455
- email(): StringRule
3456
- }
3457
-
3458
- /**
3459
- * This is used for string, text, date and datetime.
3460
- * This interface represent the compiled version at runtime, when accessed through Schema.
3461
- *
3462
- * @public
3463
- */
3464
- export declare interface StringSchemaType extends BaseSchemaType {
3465
- jsonType: 'string'
3466
- options?: StringOptions & TextOptions & DateOptions & DatetimeOptions
3467
- initialValue?: InitialValueProperty<any, string>
3468
- }
3469
-
3470
- /** @public */
3471
- export declare type SwatchName =
3472
- | 'darkMuted'
3473
- | 'darkVibrant'
3474
- | 'dominant'
3475
- | 'lightMuted'
3476
- | 'lightVibrant'
3477
- | 'muted'
3478
- | 'vibrant'
3479
-
3480
- /** @public */
3481
- export declare interface TextDefinition extends BaseSchemaDefinition {
3482
- type: 'text'
3483
- rows?: number
3484
- options?: TextOptions
3485
- placeholder?: string
3486
- validation?: ValidationBuilder<TextRule, string>
3487
- initialValue?: InitialValueProperty<any, string>
3488
- }
3489
-
3490
- /** @public */
3491
- export declare interface TextOptions extends StringOptions {}
3492
-
3493
- /** @public */
3494
- export declare interface TextRule extends StringRule {}
3495
-
3496
- /** @public */
3497
- export declare interface TextSchemaType extends StringSchemaType {
3498
- rows?: number
3499
- }
3500
-
3501
- /** @public */
3502
- export declare interface TitledListValue<V = unknown> {
3503
- _key?: string
3504
- title: string
3505
- value?: V
3506
- }
3507
-
3508
- /**
3509
- * An entry in the transaction log
3510
- *
3511
- * @internal
3512
- */
3513
- export declare interface TransactionLogEvent {
3514
- /**
3515
- * ID of transaction
3516
- */
3517
- id: string
3518
- /**
3519
- * ISO-formatted timestamp (zulu-time) of when the transaction happened
3520
- */
3521
- timestamp: string
3522
- /**
3523
- * User ID of the user who performed the transaction
3524
- */
3525
- author: string
3526
- /**
3527
- * Document IDs involved in this transaction
3528
- */
3529
- documentIDs: string[]
3530
- }
3531
-
3532
- /**
3533
- * An entry in the transaction log that includes the effects of the transaction.
3534
- * Used when asking the transaction log to include effects in mendoza format,
3535
- * eg `?effectFormat=mendoza`
3536
- *
3537
- * @internal
3538
- */
3539
- export declare interface TransactionLogEventWithEffects extends TransactionLogEvent {
3540
- /**
3541
- * Object of effects, where the key is the document ID affected and the value
3542
- * is the effect pair, eg `{apply: MendozaPatch, revert: MendozaPatch}`
3543
- */
3544
- effects: Record<string, MendozaEffectPair | undefined>
3545
- }
3546
-
3547
- /**
3548
- * An entry in the transaction log that includes the mutations that were performed.
3549
- * Used when asking the transaction log not to exclude the mutations,
3550
- * eg `excludeMutations=false`
3551
- *
3552
- * @internal
3553
- */
3554
- export declare interface TransactionLogEventWithMutations extends TransactionLogEvent {
3555
- /**
3556
- * Array of mutations that occurred in this transaction. Note that the transaction
3557
- * log has an additional mutation type not typically seen in other APIs;
3558
- * `createSquashed` ({@link CreateSquashedMutation}).
3559
- */
3560
- mutations: TransactionLogMutation[]
3561
- }
3562
-
3563
- /**
3564
- * A mutation that can occur in the transaction log, which includes the
3565
- * {@link CreateSquashedMutation} mutation type.
3566
- *
3567
- * @internal
3568
- */
3569
- export declare type TransactionLogMutation = Mutation | CreateSquashedMutation
3570
-
3571
- /**
3572
- * Represents a type definition that is an alias/extension of an existing type
3573
- * in your schema. Creating a type alias will re-register that existing type
3574
- * under a different name. You can also override the default type options with
3575
- * a type alias definition.
3576
- *
3577
- * @public
3578
- */
3579
- export declare interface TypeAliasDefinition<
3580
- TType extends string,
3581
- TAlias extends IntrinsicTypeName | undefined,
3582
- > extends BaseSchemaDefinition {
3583
- type: TType
3584
- options?: TAlias extends IntrinsicTypeName ? IntrinsicDefinitions[TAlias]['options'] : unknown
3585
- validation?: SchemaValidationValue
3586
- initialValue?: InitialValueProperty<any, any>
3587
- preview?: PreviewConfig
3588
- components?: {
3589
- annotation?: ComponentType<any>
3590
- block?: ComponentType<any>
3591
- inlineBlock?: ComponentType<any>
3592
- diff?: ComponentType<any>
3593
- field?: ComponentType<any>
3594
- input?: ComponentType<any>
3595
- item?: ComponentType<any>
3596
- preview?: ComponentType<any>
3597
- }
3598
- }
3599
-
3600
- /**
3601
- * `typed` can be used to ensure that an object conforms to an exact interface.
3602
- *
3603
- * It can be useful when working with `defineType` and `defineField` on occasions where a wider type with
3604
- * custom options or properties is required.
3605
- *
3606
- * ## Example usage
3607
- * ```ts
3608
- * defineField({
3609
- * type: 'string',
3610
- * name: 'nestedField',
3611
- * options: typed<StringOptions & {myCustomOption: boolean}>({
3612
- * layout: 'radio',
3613
- * // allowed
3614
- * myCustomOption: true,
3615
- * //@ts-expect-error unknownProp is not part of StringOptions & {myCustomOption: boolean}
3616
- * unknownProp: 'not allowed in typed context',
3617
- * }),
3618
- * }),
3619
- * ```
3620
- *
3621
- * @param input - returned directly
3622
- *
3623
- * @internal
3624
- */
3625
- export declare function typed<T>(input: T): T
3626
-
3627
- /** @public */
3628
- export declare interface TypedObject {
3629
- [key: string]: unknown
3630
- _type: string
3631
- }
3632
-
3633
- /**
3634
- * Represents a reference to another type registered top-level in your schema.
3635
- *
3636
- * @public
3637
- */
3638
- export declare interface TypeReference {
3639
- type: string
3640
- name?: string
3641
- icon?: ComponentType | ReactNode
3642
- options?: {
3643
- [key: string]: unknown
3644
- }
3645
- }
3646
-
3647
- /** @internal */
3648
- export declare interface UploadState {
3649
- progress: number
3650
- /** @deprecated use createdAt instead */
3651
- initiated?: string
3652
- /** @deprecated use updatedAt instead */
3653
- updated?: string
3654
- createdAt: string
3655
- updatedAt: string
3656
- file: {
3657
- name: string
3658
- type: string
3659
- }
3660
- previewImage?: string
3661
- }
3662
-
3663
- /** @public */
3664
- export declare interface UriValidationOptions {
3665
- scheme?: (string | RegExp) | Array<string | RegExp>
3666
- allowRelative?: boolean
3667
- relativeOnly?: boolean
3668
- allowCredentials?: boolean
3669
- }
3670
-
3671
- /** @public */
3672
- export declare interface UrlDefinition extends BaseSchemaDefinition {
3673
- type: 'url'
3674
- options?: UrlOptions
3675
- placeholder?: string
3676
- validation?: ValidationBuilder<UrlRule, string>
3677
- initialValue?: InitialValueProperty<any, string>
3678
- }
3679
-
3680
- /** @public */
3681
- export declare interface UrlOptions extends BaseSchemaTypeOptions {}
3682
-
3683
- /** @public */
3684
- export declare interface UrlRule extends RuleDef<UrlRule, string> {
3685
- uri(options: UriValidationOptions): UrlRule
3686
- }
3687
-
3688
- /** @public */
3689
- export declare interface User {
3690
- id: string
3691
- displayName?: string
3692
- imageUrl?: string
3693
- email?: string
3694
- }
3695
-
3696
- /** @public */
3697
- export declare type ValidationBuilder<T extends RuleDef<T, FieldValue>, FieldValue = unknown> = (
3698
- rule: T,
3699
- ) => RuleBuilder<T, FieldValue>
3700
-
3701
- /**
3702
- * A context object passed around during validation. This includes the
3703
- * `Rule.custom` context.
3704
- *
3705
- * e.g.
3706
- *
3707
- * ```js
3708
- * Rule.custom((_, validationContext) => {
3709
- * // ...
3710
- * })`
3711
- * ```
3712
- *
3713
- * @public
3714
- */
3715
- export declare interface ValidationContext {
3716
- getClient: (options: {apiVersion: string}) => SanityClient
3717
- schema: Schema
3718
- parent?: unknown
3719
- type?: SchemaType
3720
- document?: SanityDocument
3721
- path?: Path
3722
- getDocumentExists?: (options: {id: string}) => Promise<boolean>
3723
- environment: 'cli' | 'studio'
3724
- }
3725
-
3726
- /**
3727
- * The shape that can be returned from a custom validator to be converted into
3728
- * a validation marker by the validation logic. Inside of a custom validator,
3729
- * you can return an array of these in order to specify multiple paths within
3730
- * an object or array.
3731
- *
3732
- * @public
3733
- */
3734
- export declare interface ValidationError {
3735
- /**
3736
- * The message describing why the value is not valid. This message will be
3737
- * included in the validation markers after validation has finished running.
3738
- */
3739
- message: string
3740
- /**
3741
- * If writing a custom validator, you can return validation messages to
3742
- * specific path inside of the current value (object or array) by populating
3743
- * this `path` prop.
3744
- *
3745
- * NOTE: This path is relative to the current value and _not_ relative to
3746
- * the document.
3747
- */
3748
- path?: Path
3749
- /**
3750
- * Same as `path` but allows more than one value. If provided, the same
3751
- * message will create two markers from each path with the same message
3752
- * provided.
3753
- *
3754
- * @deprecated prefer `path`
3755
- */
3756
- paths?: Path[]
3757
- /**
3758
- * @deprecated Unused. Was used to store the results from `.either()` /`.all()`
3759
- */
3760
- children?: ValidationMarker[]
3761
- /**
3762
- * @deprecated Unused. Was used to signal if this error came from an `.either()`/`.all()`.
3763
- */
3764
- operation?: 'AND' | 'OR'
3765
- /**
3766
- * @deprecated Unused. Was relevant when validation error was used as a class.
3767
- */
3768
- cloneWithMessage?(message: string): ValidationError
3769
- }
3770
-
3771
- /**
3772
- * This follows the same pattern as `RuleClass` and `Rule` above
3773
- * Note: this class does not actually extend `Error` since it's never thrown
3774
- * within the validation library
3775
- *
3776
- * @deprecated It is preferred to a plain object that adheres to `ValidationError`
3777
- * @internal
3778
- */
3779
- export declare interface ValidationErrorClass {
3780
- new (message: string, options?: ValidationErrorOptions): ValidationError
3781
- }
3782
-
3783
- /** @internal */
3784
- export declare interface ValidationErrorOptions {
3785
- paths?: Path[]
3786
- children?: ValidationMarker[]
3787
- operation?: 'AND' | 'OR'
3788
- }
3789
-
3790
- /** @public */
3791
- export declare interface ValidationMarker {
3792
- level: 'error' | 'warning' | 'info'
3793
- /**
3794
- * The validation message for this marker. E.g. "Must be greater than 0"
3795
- */
3796
- message: string
3797
- /**
3798
- * @deprecated use `message` instead
3799
- */
3800
- item?: ValidationError
3801
- /**
3802
- * The sanity path _relative to the root of the current document_ to this
3803
- * marker.
3804
- *
3805
- * NOTE: Sanity paths may contain keyed segments (i.e. `{_key: string}`) that
3806
- * are not compatible with deep getters like lodash/get
3807
- */
3808
- path: Path
3809
- }
3810
-
3811
- /**
3812
- * The base type for all validators in the validation library. Takes in a
3813
- * `RuleSpec`'s constraint, the value to check, an optional override message,
3814
- * and the validation context.
3815
- *
3816
- * @see Rule.validate from `sanity/src/core/validation/Rule`
3817
- *
3818
- * @internal
3819
- */
3820
- export declare type Validator<T = any, Value = any> = (
3821
- constraint: T,
3822
- value: Value,
3823
- message: string | undefined,
3824
- context: ValidationContext,
3825
- ) =>
3826
- | ValidationError[]
3827
- | ValidationError
3828
- | string
3829
- | true
3830
- | Promise<ValidationError[] | ValidationError | string | true>
3831
-
3832
- /**
3833
- * A type helper used to define a group of validators. The type of the
3834
- * `RuleSpec` constraint is inferred via the key.
3835
- *
3836
- * E.g.
3837
- *
3838
- * ```ts
3839
- * const booleanValidators: Validators = {
3840
- * ...genericValidator,
3841
- *
3842
- * presence: (v, value, message) => {
3843
- * if (v === 'required' && typeof value !== 'boolean') return message || 'Required'
3844
- * return true
3845
- * },
3846
- * }
3847
- * ```
3848
- *
3849
- * @internal
3850
- */
3851
- export declare type Validators = Partial<{
3852
- [P in RuleSpec['flag']]: Validator<
3853
- Exclude<
3854
- ConditionalIndexAccess<
3855
- Extract<
3856
- RuleSpec,
3857
- {
3858
- flag: P
3859
- }
3860
- >,
3861
- 'constraint'
3862
- >,
3863
- FieldReference
3864
- >
3865
- >
3866
- }>
3867
-
3868
- /** @beta */
3869
- export declare interface WeakCrossDatasetReferenceValue extends CrossDatasetReferenceValue {
3870
- _weak: true
3871
- }
3872
-
3873
- /** @beta */
3874
- export declare interface WeakGlobalDocumentReferenceValue extends GlobalDocumentReferenceValue {
3875
- _weak: true
3876
- }
3877
-
3878
- /** @internal */
3879
- export declare interface WeakReference extends Reference {
3880
- _weak: true
3881
- }
3882
-
3883
- /** @beta */
3884
- export declare interface WidenInitialValue {
3885
- initialValue?: InitialValueProperty<any, any>
3886
- }
3887
-
3888
- /** @beta */
3889
- export declare interface WidenValidation {
3890
- validation?: SchemaValidationValue
3891
- }
3892
-
3893
- export {}