UNPKG

@sanity/types

Version:

Type definitions for common Sanity data structures

1,915 lines (1,767 loc) โ€ข 101 kB
import {Asset as Asset_2} from '@sanity/media-library-types' import {AssetInstanceDocument} from '@sanity/media-library-types' import {ClientPerspective} from '@sanity/client' import {ComponentType} from 'react' import {ElementType} from 'react' import {ReactNode} from 'react' import {SanityClient} from '@sanity/client' /** * Types of array actions that can be performed * @beta */ export declare type ArrayActionName = /** * Add any item to the array at any position */ | 'add' /** * Add item after an existing item */ | 'addBefore' /** * Add item after an existing item */ | 'addAfter' /** * Remove any item */ | 'remove' /** * Duplicate item */ | 'duplicate' /** * Copy item */ | 'copy' /** @public */ export declare interface ArrayDefinition extends BaseSchemaDefinition { type: 'array' of: ArrayOfType[] initialValue?: InitialValueProperty<any, unknown[]> validation?: ValidationBuilder<ArrayRule<unknown[]>, unknown[]> options?: ArrayOptions } /** @public */ export declare type ArrayOfEntry<T> = Omit<T, 'name' | 'hidden'> & { name?: string } /** @public */ export declare type ArrayOfType< TType extends IntrinsicTypeName = IntrinsicTypeName, TAlias extends IntrinsicTypeName | undefined = undefined, > = IntrinsicArrayOfDefinition[TType] | ArrayOfEntry<TypeAliasDefinition<string, TAlias>> /** @public */ export declare interface ArrayOptions<V = unknown> extends SearchConfiguration, BaseSchemaTypeOptions { list?: TitledListValue<V>[] | V[] layout?: 'list' | 'tags' | 'grid' /** @deprecated This option does not have any effect anymore */ direction?: 'horizontal' | 'vertical' sortable?: boolean modal?: { type?: 'dialog' | 'popover' width?: number | 'auto' } /** @alpha This API may change */ insertMenu?: InsertMenuOptions /** * A boolean flag to enable or disable tree editing for the array. * If there are any nested arrays, they will inherit this value. * @deprecated tree editing beta feature has been disabled */ treeEditing?: boolean /** * A list of array actions to disable * Possible options are defined by {@link ArrayActionName} * @beta */ disableActions?: ArrayActionName[] } /** @public */ export declare interface ArrayRule<Value> extends RuleDef<ArrayRule<Value>, Value> { min: (length: number | FieldReference) => ArrayRule<Value> max: (length: number | FieldReference) => ArrayRule<Value> length: (length: number | FieldReference) => ArrayRule<Value> unique: () => ArrayRule<Value> } /** @public */ export declare interface ArraySchemaType<V = unknown> extends BaseSchemaType { jsonType: 'array' of: (Exclude<SchemaType, ArraySchemaType> | ReferenceSchemaType)[] options?: ArrayOptions<V> & { layout?: V extends string ? 'tag' : 'grid' } } /** @internal */ export declare type ArraySchemaTypeOf<TSchemaType extends ArraySchemaType['of'][number]> = Omit< ArraySchemaType, 'of' > & { of: TSchemaType[] } /** @public */ export declare interface Asset extends SanityDocument { url: string path: string assetId: string extension: string mimeType: string sha1hash: string size: number originalFilename?: string label?: string title?: string description?: string creditLine?: string source?: AssetSourceSpec } /** @public */ export declare type AssetFromSource = { kind: 'assetDocumentId' | 'file' | 'base64' | 'url' value: string | File_2 assetDocumentProps?: ImageAsset mediaLibraryProps?: { mediaLibraryId: string assetId: string assetInstanceId: string } } /** @public */ export declare type AssetMetadataType = | 'location' | 'exif' | 'image' | 'palette' | 'lqip' | 'blurhash' | 'none' /** @public */ export declare interface AssetSchemaTypeOptions { accept?: string storeOriginalFilename?: boolean } /** @public */ export declare interface AssetSource { name: string /** @deprecated provide `i18nKey` instead */ title?: string i18nKey?: string component: ComponentType<AssetSourceComponentProps> icon?: ComponentType<EmptyProps> /** @beta */ Uploader?: AssetSourceUploaderClass } /** @public */ export declare interface AssetSourceComponentProps { action?: 'select' | 'upload' assetSource: AssetSource assetType?: 'file' | 'image' | 'sanity.video' accept: string selectionType: 'single' dialogHeaderTitle?: React.ReactNode selectedAssets: Asset[] onClose: () => void onSelect: (assetFromSource: AssetFromSource[]) => void schemaType?: ImageSchemaType | FileSchemaType /** @beta */ uploader?: AssetSourceUploader } /** @public */ export declare interface AssetSourceSpec { id: string name: string url?: string } /** @beta */ export declare interface AssetSourceUploader { upload( files: globalThis.File[], options?: { /** * The schema type of the field the asset is being uploaded to. * May be of interest to the uploader to read file and image options. */ schemaType?: SchemaType /** * The uploader may send patches directly to the field * Typed 'unknown' as we don't have patch definitions in sanity/types yet. */ onChange?: (patch: unknown) => void }, ): AssetSourceUploadFile[] /** * Abort the upload of a file */ abort(file?: AssetSourceUploadFile): void /** * Get the files that are currently being uploaded */ getFiles(): AssetSourceUploadFile[] /** * Subscribe to upload events from the uploader */ subscribe(subscriber: (event: AssetSourceUploadEvent) => void): () => void /** * Update the status of a file. Will be emitted to subscribers. */ updateFile( fileId: string, data: { progress?: number status?: string error?: Error }, ): void /** * Reset the uploader (clear files). Should be called by the uploader when all files are done. */ reset(): void } /** @beta */ export declare type AssetSourceUploaderClass = new (...args: any[]) => AssetSourceUploader /** @beta */ export declare type AssetSourceUploadEvent = | AssetSourceUploadEventProgress | AssetSourceUploadEventStatus | AssetSourceUploadEventAllComplete | AssetSourceUploadEventError | AssetSourceUploadEventAbort /** * Emitted when all files are done, either successfully, aborted or with errors * @beta */ export declare type AssetSourceUploadEventAbort = { type: 'abort' /** * Files aborted */ files: AssetSourceUploadFile[] } /** * Emitted when all files are done, either successfully, aborted or with errors * @beta */ export declare type AssetSourceUploadEventAllComplete = { type: 'all-complete' files: AssetSourceUploadFile[] } /** * Emitted when all files are done, either successfully, aborted or with errors * @beta */ export declare type AssetSourceUploadEventError = { type: 'error' /** * Files errored */ files: AssetSourceUploadFile[] } /** * Emitted when a file upload is progressing * @beta */ export declare type AssetSourceUploadEventProgress = { type: 'progress' file: AssetSourceUploadFile progress: number } /** * Emitted when a file upload is changing status * @beta */ export declare type AssetSourceUploadEventStatus = { type: 'status' file: AssetSourceUploadFile status: AssetSourceUploadFile['status'] } /** @beta */ export declare interface AssetSourceUploadFile { id: string file: globalThis.File progress: number status: 'pending' | 'uploading' | 'complete' | 'error' | 'aborted' | 'alreadyExists' error?: Error result?: unknown } /** @beta */ export declare type AssetSourceUploadSubscriber = (event: AssetSourceUploadEvent) => void /** * Enhances VSCode autocomplete by using a distinct type for strings. * * `AllowOtherStrings` is defined as `string & {}`, an intersection that behaves * like `string` but is treated differently by TypeScript's type system for * internal processing. This helps in improving the specificity and relevance of * autocomplete suggestions by potentially prioritizing `IntrinsicTypeName` * over general string inputs, addressing issues where `string` type suggestions * might overshadow more useful specific literals. * * @beta */ export declare type AutocompleteString = string & {} /** @public */ export declare interface BaseSchemaDefinition { name: string title?: string description?: string | React.JSX.Element hidden?: ConditionalProperty readOnly?: ConditionalProperty icon?: ComponentType | ReactNode validation?: unknown initialValue?: unknown deprecated?: DeprecatedProperty } /** @public */ export declare interface BaseSchemaType extends Partial<DeprecationConfiguration> { name: string title?: string description?: string type?: SchemaType liveEdit?: boolean readOnly?: ConditionalProperty hidden?: ConditionalProperty icon?: ComponentType initialValue?: InitialValueProperty<any, any> validation?: SchemaValidationValue preview?: PreviewConfig /** @beta */ components?: { block?: ComponentType<any> inlineBlock?: ComponentType<any> annotation?: ComponentType<any> diff?: ComponentType<any> field?: ComponentType<any> input?: ComponentType<any> item?: ComponentType<any> preview?: ComponentType<any> portableText?: { plugins?: ComponentType<any> } } /** * @deprecated This will be removed. */ placeholder?: string } /** * `BaseOptions` applies to all type options. * * It can be extended by interface declaration merging in plugins to provide generic options to all types and fields. * * @public * */ export declare interface BaseSchemaTypeOptions { sanityCreate?: SanityCreateOptions canvasApp?: CanvasAppOptions } /** * Schema definition for a text block annotation object. * * @public * @example The default link annotation * ```ts * { * name: 'blockContent', * title: 'Content', * type: 'array', * of: [ * { * type: 'block', * marks: { * annotations: [ * { * type: 'object', * name: 'link', * fields: [ * { * type: 'string', * name: 'href', * }, * ], * }, * ] * }, * } * ] * } * ``` */ export declare interface BlockAnnotationDefinition extends ObjectDefinition { icon?: ReactNode | ComponentType } /** * The specific `children` field of a `block` type (`BlockSchemaType`) * @see BlockSchemaType * * @internal */ export declare type BlockChildrenObjectField = { name: 'children' } & ObjectField<ArraySchemaType> /** * Schema definition for text block decorators. * * @public * @example The default set of decorators * ```ts * { * name: 'blockContent', * title: 'Content', * type: 'array', * of: [ * { * type: 'block', * marks: { * decorators: [ * {title: 'Strong', value: 'strong'}, * {title: 'Emphasis', value: 'em'}, * {title: 'Underline', value: 'underline'}, * {title: 'Strike', value: 'strike-through'}, * {title: 'Code', value: 'code'}, * ] * } * } * ] * } * ``` */ export declare interface BlockDecoratorDefinition { title: string i18nTitleKey?: string value: string icon?: ReactNode | ComponentType } /** * Schema definition for text blocks. * * @public * @example the default block definition * ```ts * { * name: 'blockContent', * title: 'Content', * type: 'array', * of: [ * { * type: 'block', * marks: { * decorators: [ * {title: 'Strong', value: 'strong'}, * {title: 'Emphasis', value: 'em'}, * {title: 'Underline', value: 'underline'}, * {title: 'Strike', value: 'strike-through'}, * {title: 'Code', value: 'code'}, * ], * annotations: [ * { * type: 'object', * name: 'link', * fields: [ * { * type: 'string', * name: 'href', * }, * ], * }, * ] * }, * styles: [ * {title: 'Normal', value: 'normal'}, * {title: 'H1', value: 'h1'}, * {title: 'H2', value: 'h2'}, * {title: 'H3', value: 'h3'}, * {title: 'H4', value: 'h4'}, * {title: 'H5', value: 'h5'}, * {title: 'H6', value: 'h6'}, * {title: 'Quote', value: 'blockquote'} * ], * lists: [ * {title: 'Bullet', value: 'bullet'}, * {title: 'Number', value: 'number'}, * ], * }, * ] * } * ``` */ export declare interface BlockDefinition extends BaseSchemaDefinition { type: 'block' styles?: BlockStyleDefinition[] lists?: BlockListDefinition[] marks?: BlockMarksDefinition of?: ArrayOfType<'object' | 'reference'>[] initialValue?: InitialValueProperty<any, any[]> options?: BlockOptions validation?: ValidationBuilder<BlockRule, any[]> } /** * Schema definition for a text block list style. * * @public * @example The defaults lists * ```ts * { * name: 'blockContent', * title: 'Content', * type: 'array', * of: [ * { * type: 'block', * lists: [ * {title: 'Bullet', value: 'bullet'}, * {title: 'Number', value: 'number'}, * ] * } * ] * } * ``` */ export declare interface BlockListDefinition { title: string i18nTitleKey?: string value: string icon?: ReactNode | ComponentType } /** * A specific `ObjectField` for `list` in `BlockSchemaType` * @see BlockSchemaType * * @internal */ export declare type BlockListObjectField = { name: 'list' } & ObjectField<StringSchemaType> /** * Schema definition for text block marks (decorators and annotations). * * @public */ export declare interface BlockMarksDefinition { decorators?: BlockDecoratorDefinition[] annotations?: ArrayOfType<'object' | 'reference'>[] } /** * Schema options for a Block schema definition * @public */ export declare interface BlockOptions extends BaseSchemaTypeOptions { /** * Turn on or off the builtin browser spellchecking. Default is on. */ spellCheck?: boolean unstable_whitespaceOnPasteMode?: 'preserve' | 'normalize' | 'remove' /** * When enabled, the editor will restrict all line breaks and soft breaks, * forcing content to remain on a single line. This will also update * the styling of the editor to reflect the single-line constraint. * * Pasting content that is on multiple lines will be normalized to a single line, if possible. * * @defaultValue false */ oneLine?: boolean } /** @public */ export declare interface BlockRule extends RuleDef<BlockRule, any[]> {} /** * Represents the compiled schema shape for `block`s for portable text. * * Note: this does _not_ represent the schema definition shape. * * @internal */ export declare interface BlockSchemaType extends ObjectSchemaType { fields: [BlockChildrenObjectField, BlockStyleObjectField, BlockListObjectField, ...ObjectField[]] options?: BlockOptions } /** * Schema definition for a text block style. * A text block may have a block style like 'header', 'normal', 'lead' * attached to it, which is stored on the `.style` property for that block. * * @public * @remarks The first defined style will become the default style.ยดยด * @example The default set of styles * ```ts * { * name: 'blockContent', * title: 'Content', * type: 'array', * of: [ * { * type: 'block', * styles: [ * {title: 'Normal', value: 'normal'}, * {title: 'H1', value: 'h1'}, * {title: 'H2', value: 'h2'}, * {title: 'H3', value: 'h3'}, * {title: 'H4', value: 'h4'}, * {title: 'H5', value: 'h5'}, * {title: 'H6', value: 'h6'}, * {title: 'Quote', value: 'blockquote'} * ] * } * ] * } * ``` * @example Example of defining a block type with custom styles and render components. * ```ts * defineArrayMember({ * type: 'block', * styles: [ * { * title: 'Paragraph', * value: 'paragraph', * component: ParagraphStyle, * }, * { * title: 'Lead', * value: 'lead', * component: LeadStyle, * }, * { * title: 'Heading', * value: 'heading', * component: HeadingStyle, * }, * ], * }) * ``` */ export declare interface BlockStyleDefinition { title: string value: string i18nTitleKey?: string icon?: ReactNode | ComponentType } /** * A specific `ObjectField` for `style` in `BlockSchemaType` * @see BlockSchemaType * * @internal */ export declare type BlockStyleObjectField = { name: 'style' } & ObjectField<StringSchemaType> /** @public */ export declare interface BooleanDefinition extends BaseSchemaDefinition { type: 'boolean' options?: BooleanOptions initialValue?: InitialValueProperty<any, boolean> validation?: ValidationBuilder<BooleanRule, boolean> } /** @public */ export declare interface BooleanOptions extends BaseSchemaTypeOptions { layout?: 'switch' | 'checkbox' } /** @public */ export declare interface BooleanRule extends RuleDef<BooleanRule, boolean> {} /** @public */ export declare interface BooleanSchemaType extends BaseSchemaType { jsonType: 'boolean' options?: BooleanOptions initialValue?: InitialValueProperty<any, boolean> } /** * Options for configuring how Canvas app interfaces with the type or field. * * @public */ export declare interface CanvasAppOptions { /** Set to true to exclude a type or field from appearing in Canvas */ exclude?: boolean /** * A short description of what the type or field is used for. * Purpose can be used to improve how and when content mapping uses the field. * */ purpose?: string } /** * @internal * Payload that will be passed by canvas to our notifications system to display the notification in canvas. * */ export declare interface CanvasNotificationPayload extends DashboardNotificationPayload { applicationType: 'canvas' link: { type: 'dashboard' path: string } } /** @public */ export declare interface CollapseOptions { collapsed?: boolean collapsible?: boolean /** * @deprecated Use `collapsible` instead */ collapsable?: boolean } /** * this is used to get allow index access (e.g. `RuleSpec['constraint']`) to * constraint when a rule spec might not have a `constraint` prop * * @internal */ export declare type ConditionalIndexAccess<T, U> = U extends keyof T ? T[U] : undefined /** @public */ export declare type ConditionalProperty = boolean | ConditionalPropertyCallback | undefined /** @public */ export declare type ConditionalPropertyCallback = ( context: ConditionalPropertyCallbackContext, ) => boolean /** @public */ export declare interface ConditionalPropertyCallbackContext { document: SanityDocument | undefined parent: any value: any currentUser: Omit<CurrentUser, 'role'> | null } /** @internal */ export declare interface CreateIfNotExistsMutation { createIfNotExists: { _id: string _type: string [key: string]: unknown } } /** @internal */ export declare interface CreateMutation { create: { _id?: string _type: string [key: string]: unknown } } /** @internal */ export declare interface CreateOrReplaceMutation { createOrReplace: { _id: string _type: string [key: string]: unknown } } /** * Mutation type used when the document has passed the threshold of the * "history retention" - any transactions done prior to the threshold gets "squashed" * into a single "create" transaction. * * @internal */ export declare interface CreateSquashedMutation { createSquashed: { /** * The user IDs of all the users who contributed to the document prior to the squashing */ authors: string[] /** * User ID of the person who initially created the document */ createdBy: string /** * ISO-formatted timestamp (zulu-time) of when the document as initially created */ createdAt: string /** * The document as it exists after squashing has occurred */ document: { _id: string _type: string [key: string]: unknown } } } /** @public */ export declare interface CrossDatasetReferenceDefinition extends BaseSchemaDefinition { type: 'crossDatasetReference' weak?: boolean to: { type: string title?: string icon?: ComponentType preview?: PreviewConfig /** * @deprecated Unused. Configuring search is no longer supported. */ __experimental_search?: { path: string | string[] weight?: number mapWith?: string }[] }[] dataset: string studioUrl?: (document: {id: string; type?: string}) => string | null tokenId?: string options?: ReferenceOptions /** * @deprecated Cross-project references are no longer supported, only cross-dataset */ projectId?: string } /** @beta */ export declare type CrossDatasetReferenceFilterResolver = (options: { document: SanityDocument parent?: Record<string, unknown> | Record<string, unknown>[] parentPath: Path }) => CrossDatasetReferenceFilterSearchOptions | Promise<CrossDatasetReferenceFilterSearchOptions> /** @beta */ export declare type CrossDatasetReferenceFilterSearchOptions = { filter?: string params?: Record<string, unknown> tag?: string } /** @beta */ export declare interface CrossDatasetReferenceSchemaType extends Omit<ObjectSchemaType, 'options'> { jsonType: 'object' to: CrossDatasetType[] dataset: string studioUrl?: (document: {id: string; type?: string}) => string | null weak?: boolean options?: ReferenceFilterOptions } /** @beta */ export declare interface CrossDatasetReferenceValue { _type: string _dataset: string _projectId: string _ref: string _key?: string _weak?: boolean } /** @beta */ export declare interface CrossDatasetType { type: string title?: string icon: ComponentType preview: PreviewConfig /** @deprecated Unused. Configuring search is no longer supported for cross-dataset references. */ __experimental_search: ObjectSchemaType['__experimental_search'] } /** @public */ export declare interface CurrentUser { id: string name: string email: string profileImage?: string provider?: string /** @deprecated use `roles` instead */ role: string roles: Role[] } /** @public */ export declare interface CustomValidator<T = unknown> { (value: T, context: ValidationContext): CustomValidatorResult | Promise<CustomValidatorResult> bypassConcurrencyLimit?: boolean } /** @public */ export declare type CustomValidatorResult = | true | string | ValidationError | ValidationError[] | LocalizedValidationMessages /** * @internal * Payload notifications have to provide to the notification system in order to display correctly in dashboard */ export declare interface DashboardNotificationPayload { version: '1.0.0' applicationType: string createdAt: string /** * The user who took the action which triggered the notification. */ actor: User title: PortableTextBlock[] body: PortableTextBlock[] | undefined organizationId: string applicationId?: string workspaceName?: string link: | { type: 'url' url: string } | { type: 'dashboard' path: string } } /** @public */ export declare interface DateDefinition extends BaseSchemaDefinition { type: 'date' options?: DateOptions placeholder?: string validation?: ValidationBuilder<DateRule, string> initialValue?: InitialValueProperty<any, string> } /** @public */ export declare interface DateOptions extends BaseSchemaTypeOptions { dateFormat?: string } /** @public */ export declare interface DateRule extends RuleDef<DateRule, string> { /** * @param minDate - Minimum date (inclusive). minDate should be in ISO 8601 format. */ min: (minDate: string | FieldReference) => DateRule /** * @param maxDate - Maximum date (inclusive). maxDate should be in ISO 8601 format. */ max: (maxDate: string | FieldReference) => DateRule } /** @public */ export declare interface DatetimeDefinition extends BaseSchemaDefinition { type: 'datetime' options?: DatetimeOptions placeholder?: string validation?: ValidationBuilder<DatetimeRule, string> initialValue?: InitialValueProperty<any, string> } /** @public */ export declare interface DatetimeOptions extends BaseSchemaTypeOptions { dateFormat?: string timeFormat?: string timeStep?: number displayTimeZone?: string allowTimeZoneSwitch?: boolean } /** @public */ export declare interface DatetimeRule extends RuleDef<DatetimeRule, string> { /** * @param minDate - Minimum date (inclusive). minDate should be in ISO 8601 format. */ min: (minDate: string | FieldReference) => DatetimeRule /** * @param maxDate - Maximum date (inclusive). maxDate should be in ISO 8601 format. */ max: (maxDate: string | FieldReference) => DatetimeRule } /** * Define an array item member type within an array definition `of`-array. * * This function will narrow the schema type down to fields and options based on the provided * `type` string. * * Using `defineArrayMember` is optional, but should provide improved autocompletion in your IDE, when building your schema. * Field properties like `validation` and `initialValue` will also be more specific. * * See {@link defineType} for example usage. * * @param arrayOfSchema - should be a valid `array.of` member definition. * @param defineOptions - optional param to provide type hints for `arrayOfSchema`. * * @see defineType * @see defineField * @see typed * * @beta */ export declare function defineArrayMember< const TType extends IntrinsicTypeName | AutocompleteString, const TName extends string, TSelect extends Record<string, string> | undefined, TPrepareValue extends Record<keyof TSelect, any> | undefined, TAlias extends IntrinsicTypeName | undefined, TStrict extends StrictDefinition, >( arrayOfSchema: { type: TType /** * When provided, `name` is used as `_type` for the array item when stored. * * Necessary when an array contains multiple entries with the same `type`, each with * different configuration (title and initialValue for instance). */ name?: TName } & DefineArrayMemberBase<TType, TAlias> & NarrowPreview<TType, TAlias, TSelect, TPrepareValue> & MaybeAllowUnknownProps<TStrict>, defineOptions?: DefineSchemaOptions<TStrict, TAlias>, ): typeof arrayOfSchema & WidenValidation & WidenInitialValue /** @beta */ export declare type DefineArrayMemberBase< TType extends string, TAlias extends IntrinsicTypeName | undefined, > = TType extends IntrinsicTypeName ? IntrinsicArrayOfBase[TType] : ArrayOfEntry<TypeAliasDefinition<string, TAlias>> /** * Define a Media Library asset aspect. * * Aspects can be deployed using the `sanity media deploy-aspect` CLI command. * * @public * @beta */ export declare function defineAssetAspect( definition: MediaLibraryAssetAspectDefinition, ): MediaLibraryAssetAspectDocument /** * Define a field within a document, object, image or file definition `fields` array. * * This function will narrow the schema type down to fields and options based on the provided * type-string. * * Using `defineField` is optional, but should provide improved autocompletion in your IDE, when building your schema. * Field-properties like `validation` and `initialValue`will also be more specific. * * See {@link defineType} for more examples. * * @param schemaField - should be a valid field type definition. * @param defineOptions - optional param to provide type hints for `schemaField`. * * @see defineField * @see defineArrayMember * @see typed * * @beta */ export declare function defineField< const TType extends IntrinsicTypeName | AutocompleteString, const TName extends string, TSelect extends Record<string, string> | undefined, TPrepareValue extends Record<keyof TSelect, any> | undefined, TAlias extends IntrinsicTypeName | undefined, TStrict extends StrictDefinition, >( schemaField: { type: TType name: TName } & DefineSchemaBase<TType, TAlias> & NarrowPreview<TType, TAlias, TSelect, TPrepareValue> & MaybeAllowUnknownProps<TStrict> & FieldDefinitionBase, defineOptions?: DefineSchemaOptions<TStrict, TAlias>, ): typeof schemaField & WidenValidation & WidenInitialValue /** @beta */ export declare type DefineSchemaBase< TType extends string, TAlias extends IntrinsicTypeName | undefined, > = TType extends IntrinsicTypeName ? IntrinsicBase[TType] : TypeAliasDefinition<TType, TAlias> /** @beta */ export declare interface DefineSchemaOptions< TStrict extends StrictDefinition, TAlias extends IntrinsicTypeName | undefined, > { /** * `strict: false` allows unknown properties in the schema. * Use this when adding customizations to the schema that are not part of sanity core. * * If you want to extend the Sanity Schema types with your own properties or options to make them typesafe, * you can use [TypeScript declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html). * * See {@link defineType} for more. * * @see defineType */ strict?: TStrict /** Should be provided when type is a non-intrinsic type, ie type is a type alias */ aliasFor?: TAlias extends IntrinsicTypeName ? TAlias : never } /** @beta */ export declare type DefineSchemaType< TType extends string, TAlias extends IntrinsicTypeName | undefined, > = TType extends IntrinsicTypeName ? IntrinsicDefinitions[TType] : TypeAliasDefinition<TType, TAlias> /** * Helper function for defining a Sanity type definition. This function does not do anything on its own; * it exists to check that your schema definition is correct, and help autocompletion in your IDE. * * This function will narrow the schema type down to fields and options based on the provided type-string. * * Schema types defined using `defineType` should typically be added to the Studio config under `schema.types`. * Defined types can be referenced by their `name`. This is referred to as a type-alias. * * When using type-aliases as `type`, `defineType` cannot know the base-type, so type-safety will be reduced. * If you know the base type of the type-alias, provide `defineOptions.aliasFor: <base type name>`. * This will enforce that the schema definition conforms with the provided type. * * By default, `defineType` only allows known properties and options. * Use `defineOptions.strict: false` to allow unknown properties and options. * * ### Basic usage * * ```ts * defineType({ * type: 'object', * name: 'custom-object', * fields: [ {type: 'string', name: 'title', title: 'Title'}], * }) * ``` * * ### Usage with aliasFor narrowing * * ```ts * defineType({ * type: 'custom-object', * name: 'redefined-custom-object', * options: { * columns: 2 * } * }, {aliasFor: 'object' }) * ``` * * ### Allow unknown properties * * ```ts * defineType({ * type: 'custom-object', * name: 'redefined-custom-object', * allowsUnknownProperties: true * options: { * columns: 2, * allowsUnknownOptions: true * } * }, {strict: false}) * ``` * ### Maximum safety and best autocompletion * * Use {@link defineType}, {@link defineField} and {@link defineArrayMember}: * * ```ts * defineType({ * type: 'object', * name: 'custom-object', * fields: [ * defineField({ * type: 'array', * name: 'arrayField', * title: 'Things', * of: [ * defineArrayMember({ * type: 'object', * name: 'type-name-in-array', * fields: [defineField({type: 'string', name: 'title', title: 'Title'})], * }), * ], * }), * ], * }) * ``` * * ## Note on type-safety in the current implementation * * Type-safety inside array-like properties (schema properties like `fields` and `of`) can only be guaranteed when * {@link defineField} and {@link defineArrayMember} are used to wrap each value in the array. * * For array-values without a function-wrapper, TypeScript will resolve to a union type of all possible properties across * all schema types. This result in less precise typing. * * ### Extending the Sanity Schema types * * If you want to extend the Sanity Schema types with your own properties or options to make them typesafe, * you can use [TypeScript declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html). * * With declaration merging, properties and options will be available in a type-safe manner, and * `strict: false` will not be necessary. * * #### Example: Add option to StringOptions * * ```ts * // string.ts * * //redeclare the sanity module * declare module 'sanity' { * // redeclare StringOptions; it will be merged with StringOptions in the sanity module * export interface StringOptions { * myCustomOption?: boolean * } * } * * // the option is now part of the StringOptions type, just as if it was declared in the sanity codebase: * defineType({ * type: 'string', * name: 'my-string', * options: { * myCustomOption: true // this does not give an error anymore * } * }) * * ``` * * #### Example: Add a schema definition to "intrinsic-types" * * ```ts * //my-custom-type-definition.ts * * // create a new schema definition based on object (we remove the ability to assign field, change the type add some options) * export type MagicallyAddedDefinition = Omit<Schema.ObjectDefinition, 'type' | 'fields'> & { * type: 'magically-added-type' * options?: { * sparkles?: boolean * } * } * * // redeclares sanity module so we can add interfaces props to it * declare module 'sanity' { * // redeclares IntrinsicDefinitions and adds a named definition to it * // it is important that the key is the same as the type in the definition ('magically-added-type') * export interface IntrinsicDefinitions { * 'magically-added-type': MagicallyAddedDefinition * } * } * * // defineType will now narrow `type: 'magically-added-type'` to `MagicallyAddedDefinition` * defineType({ * type: 'magically-added-type' * name: 'magic', * options: { * sparkles: true // this is allowed, * //@ts-expect-error this is not allowed in MagicallyAddedDefinition.options * sparks: true * } * }) * ``` * * @param schemaDefinition - should be a valid schema type definition. * @param defineOptions - optional param to provide type hints for `schemaDefinition`. * * @see defineField * @see defineArrayMember * @see typed * * @beta */ export declare function defineType< const TType extends IntrinsicTypeName | AutocompleteString, const TName extends string, TSelect extends Record<string, string> | undefined, TPrepareValue extends Record<keyof TSelect, any> | undefined, TAlias extends IntrinsicTypeName | undefined, TStrict extends StrictDefinition, >( schemaDefinition: { type: TType name: TName } & DefineSchemaBase<TType, TAlias> & NarrowPreview<TType, TAlias, TSelect, TPrepareValue> & MaybeAllowUnknownProps<TStrict>, defineOptions?: DefineSchemaOptions<TStrict, TAlias>, ): typeof schemaDefinition /** @internal */ export declare interface DeleteMutation { delete: MutationSelection } /** @public */ export declare interface DeprecatedProperty { reason: string } /** @public */ export declare type DeprecatedSchemaType<TSchemaType extends BaseSchemaType = BaseSchemaType> = TSchemaType & DeprecationConfiguration /** * @public */ export declare interface DeprecationConfiguration { deprecated: DeprecatedProperty } /** @public */ export declare interface DocumentDefinition extends Omit<ObjectDefinition, 'type'> { type: 'document' liveEdit?: boolean /** @beta */ orderings?: SortOrdering[] options?: DocumentOptions validation?: ValidationBuilder<DocumentRule, SanityDocument> initialValue?: InitialValueProperty<any, Record<string, unknown>> /** @deprecated Unused. Use the new field-level search config. */ __experimental_search?: { path: string weight: number mapWith?: string }[] /** @alpha */ __experimental_omnisearch_visibility?: boolean /** * Determines whether the large preview title is displayed in the document pane form * @alpha * */ __experimental_formPreviewTitle?: boolean } /** * This exists only to allow for extensions using declaration-merging. * * @public */ export declare interface DocumentOptions extends BaseSchemaTypeOptions {} /** @public */ export declare interface DocumentRule extends RuleDef<DocumentRule, SanityDocument> {} /** @public */ export declare interface EmailDefinition extends BaseSchemaDefinition { type: 'email' options?: EmailOptions placeholder?: string validation?: ValidationBuilder<EmailRule, string> initialValue?: InitialValueProperty<any, string> } /** @public */ export declare interface EmailOptions extends BaseSchemaTypeOptions {} /** @public */ export declare interface EmailRule extends RuleDef<EmailRule, string> {} /** @public */ export declare interface EmptyProps {} /** @public */ export declare interface EnumListProps<V = unknown> { list?: Array<TitledListValue<V> | V> layout?: 'radio' | 'dropdown' direction?: 'horizontal' | 'vertical' } /** * The shape of a field definition. Note, it's recommended to use the * `defineField` function instead of using this type directly. * * Where `defineField` infers the exact field type, * FieldDefinition is a compromise union of all types a field can have. * * A field definition can be a reference to another registered top-level type * or a inline type definition. * * @public */ export declare type FieldDefinition< TType extends IntrinsicTypeName = IntrinsicTypeName, TAlias extends IntrinsicTypeName | undefined = undefined, > = (InlineFieldDefinition[TType] | TypeAliasDefinition<string, TAlias>) & FieldDefinitionBase /** @public */ export declare interface FieldDefinitionBase { fieldset?: string group?: string | string[] } /** @public */ export declare interface FieldGroup { name: string icon?: ComponentType title?: string description?: string i18n?: I18nTextRecord<'title'> hidden?: ConditionalProperty default?: boolean fields?: ObjectField[] } /** @public */ export declare type FieldGroupDefinition = { name: string title?: string hidden?: ConditionalProperty icon?: ComponentType default?: boolean i18n?: I18nTextRecord<'title'> } /** * Holds a reference to a different field * NOTE: Only use this through {@link Rule.valueOfField} * * @public */ export declare interface FieldReference { type: symbol path: string | string[] } /** @public */ export declare type FieldRules = { [fieldKey: string]: SchemaValidationValue } /** @public */ export declare type Fieldset = SingleFieldSet | MultiFieldSet /** @public */ export declare type FieldsetDefinition = { name: string title?: string description?: string group?: string hidden?: ConditionalProperty readOnly?: ConditionalProperty options?: ObjectOptions } /** @public */ declare interface File_2 { [key: string]: unknown asset?: Reference } export {File_2 as File} /** @public */ export declare interface FileAsset extends Asset { _type: 'sanity.fileAsset' metadata: Record<string, unknown> } /** @public */ export declare interface FileDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options' | 'groups' | 'validation'> { type: 'file' fields?: ObjectDefinition['fields'] options?: FileOptions validation?: ValidationBuilder<FileRule, FileValue> initialValue?: InitialValueProperty<any, FileValue> } /** @public */ export declare interface FileOptions extends ObjectOptions { storeOriginalFilename?: boolean accept?: string sources?: AssetSource[] mediaLibrary?: MediaLibraryOptions } /** @public */ export declare interface FileRule extends RuleDef<FileRule, FileValue> { /** * Require a file field has an asset. * * @example * ```ts * defineField({ * name: 'file', * title: 'File', * type: 'file', * validation: (Rule) => Rule.required().assetRequired(), * }) * ``` */ assetRequired(): FileRule } /** @public */ export declare interface FileSchemaType extends Omit<ObjectSchemaType, 'options'> { options?: FileOptions } /** @public */ export declare interface FileValue { asset?: Reference [index: string]: unknown } /** @public */ export declare interface FormNodeValidation { level: 'error' | 'warning' | 'info' message: string path: Path } /** @public */ export declare interface GeopointDefinition extends BaseSchemaDefinition { type: 'geopoint' options?: GeopointOptions validation?: ValidationBuilder<GeopointRule, GeopointValue> initialValue?: InitialValueProperty<any, Omit<GeopointValue, '_type'>> } /** @public */ export declare interface GeopointOptions extends BaseSchemaTypeOptions {} /** @public */ export declare interface GeopointRule extends RuleDef<GeopointRule, GeopointValue> {} /** * Geographical point representing a pair of latitude and longitude coordinates, * stored as degrees, in the World Geodetic System 1984 (WGS 84) format. Also * includes an optional `alt` property representing the altitude in meters. * * @public */ export declare interface GeopointValue { /** * Type of the object. Must be `geopoint`. */ _type: 'geopoint' /** * Latitude in degrees */ lat: number /** * Longitude in degrees */ lng: number /** * Altitude in meters */ alt?: number } /** @public */ export declare interface GlobalDocumentReferenceDefinition extends BaseSchemaDefinition { type: 'globalDocumentReference' weak?: boolean to: { type: string title?: string icon?: ComponentType preview?: PreviewConfig }[] resourceType: string resourceId: string options?: ReferenceOptions studioUrl?: string | ((document: {id: string; type?: string}) => string | null) } /** @beta */ export declare type GlobalDocumentReferenceFilterResolver = (options: { document: SanityDocument parent?: Record<string, unknown> | Record<string, unknown>[] parentPath: Path }) => | GlobalDocumentReferenceFilterSearchOptions | Promise<GlobalDocumentReferenceFilterSearchOptions> /** @beta */ export declare type GlobalDocumentReferenceFilterSearchOptions = { filter?: string params?: Record<string, unknown> tag?: string } /** @beta */ export declare interface GlobalDocumentReferenceSchemaType extends Omit<ObjectSchemaType, 'options'> { jsonType: 'object' to: GlobalDocumentReferenceType[] resourceType: string resourceId: string studioUrl?: string | ((document: {id: string; type?: string}) => string | null) weak?: boolean options?: ReferenceFilterOptions } /** @beta */ export declare interface GlobalDocumentReferenceType { type: string title?: string icon: ComponentType preview: PreviewConfig /** @deprecated Unused. It's only here for the type to be compatible with createSearchQuery.ts */ __experimental_search: never } /** @beta */ export declare interface GlobalDocumentReferenceValue { _type: string /** The reference to the document. This is a string of the form `a:b:c`, * where: * - `a` is the resource type, for example `dataset` or `media-library` * - `b` is the resource ID, for example data set name or media library ID * - `c` is the document ID */ _ref: `${string}:${string}:${string}` _key?: string _weak?: boolean } /** @public */ export declare interface HotspotOptions { previews?: HotspotPreview[] } /** @public */ export declare interface HotspotPreview { title: string aspectRatio: number } /** @public */ export declare type I18nTextRecord<K extends string> = { [P in K]?: { key: string ns: string } } /** @public */ export declare interface I18nTitledListValue<V = unknown> { _key?: string title: string i18nTitleKey?: string value?: V } /** @public */ declare interface Image_2 { [key: string]: unknown asset?: Reference crop?: ImageCrop hotspot?: ImageHotspot } export {Image_2 as Image} /** @public */ export declare interface ImageAsset extends Asset { _type: 'sanity.imageAsset' metadata: ImageMetadata } /** @public */ export declare interface ImageCrop { _type?: 'sanity.imageCrop' left: number bottom: number right: number top: number } /** @public */ export declare interface ImageDefinition extends Omit<ObjectDefinition, 'type' | 'fields' | 'options' | 'groups' | 'validation'> { type: 'image' fields?: FieldDefinition[] options?: ImageOptions validation?: ValidationBuilder<ImageRule, ImageValue> initialValue?: InitialValueProperty<any, ImageValue> } /** @public */ export declare interface ImageDimensions { _type: 'sanity.imageDimensions' height: number width: number aspectRatio: number } /** @public */ export declare interface ImageHotspot { _type?: 'sanity.imageHotspot' width: number height: number x: number y: number } /** @public */ export declare interface ImageMetadata { [key: string]: unknown _type: 'sanity.imageMetadata' dimensions: ImageDimensions palette?: ImagePalette lqip?: string blurHash?: string hasAlpha: boolean isOpaque: boolean } /** @public */ export declare type ImageMetadataType = | 'blurhash' | 'lqip' | 'palette' | 'exif' | 'image' | 'location' /** @public */ export declare interface ImageOptions extends FileOptions { metadata?: ImageMetadataType[] hotspot?: boolean | HotspotOptions } /** @public */ export declare interface ImagePalette { _type: 'sanity.imagePalette' darkMuted?: ImageSwatch darkVibrant?: ImageSwatch dominant?: ImageSwatch lightMuted?: ImageSwatch lightVibrant?: ImageSwatch muted?: ImageSwatch vibrant?: ImageSwatch } /** @public */ export declare interface ImageRule extends RuleDef<ImageRule, ImageValue> { /** * Require an image field has an asset. * * @example * ```ts * defineField({ * name: 'image', * title: 'Image', * type: 'image', * validation: (Rule) => Rule.required().assetRequired(), * }) * ``` */ assetRequired(): ImageRule } /** @public */ export declare interface ImageSchemaType extends Omit<ObjectSchemaType, 'options'> { options?: ImageOptions } /** @public */ export declare interface ImageSwatch { _type: 'sanity.imagePaletteSwatch' background: string foreground: string population: number title?: string } /** @internal */ export declare type ImageUrlAutoMode = 'format' /** @internal */ export declare type ImageUrlCropMode = | 'top' | 'bottom' | 'left' | 'right' | 'center' | 'focalpoint' | 'entropy' /** @internal */ export declare type ImageUrlFitMode = 'clip' | 'crop' | 'fill' | 'fillmax' | 'max' | 'scale' | 'min' /** @internal */ export declare type ImageUrlFormat = 'jpg' | 'pjpg' | 'png' | 'webp' /** @internal */ export declare type ImageUrlOrientation = '0' | '90' | '180' | '270' /** * NOTE: These are query parameters, so they will eventually be encoded as strings. * However, since most/all query parameter encoders will accept numbers and encode * them as strings, we'll use `string| number` where applicable, as it makes it easier * to use in places that do calculations and such. * * @internal */ export declare interface ImageUrlParams { 'bg'?: string 'dpr'?: number | string 'w'?: number | string 'h'?: number | string 'q'?: number | string 'dl'?: string 'dlRaw'?: string 'fp-x'?: number | string 'fp-y'?: number | string 'max-w'?: number | string 'max-h'?: number | string 'min-w'?: number | string 'min-h'?: number | string 'blur'?: number | string 'sharp'?: number | string 'rect'?: string 'fm'?: ImageUrlFormat 'or'?: ImageUrlOrientation 'fit'?: ImageUrlFitMode 'crop'?: ImageUrlCropMode 'auto'?: ImageUrlAutoMode 'invert'?: 'true' | 'false' 'quality'?: number | string 'flip'?: 'h' | 'v' | 'hv' 'sat'?: number | string 'pad'?: number | string 'colorquant'?: number | string 'border'?: string } /** @public */ export declare interface ImageValue extends FileValue { crop?: ImageCrop hotspot?: ImageHotspot [index: string]: unknown } /** @public */ export declare type IndexTuple = [number | '', number | ''] /** @public */ export declare type InitialValueProperty<Params, Value> = | Value | InitialValueResolver<Params, Value> | undefined /** @public */ export declare type InitialValueResolver<Params, Value> = ( params: Params | undefined, context: InitialValueResolverContext, ) => Promise<Value> | Value /** @public */ export declare interface InitialValueResolverContext { projectId: string dataset: string schema: Schema currentUser: CurrentUser | null getClient: (options: {apiVersion: string}) => SanityClient } /** @public */ export declare type InlineFieldDefinition = { [K in keyof IntrinsicDefinitions]: Omit< IntrinsicDefinitions[K], 'initialValue' | 'validation' > & { validation?: SchemaValidationValue initialValue?: InitialValueProperty<any, any> } } /** @alpha This API may change */ export declare interface InsertMenuOptions { /** * @defaultValue `'auto'` * `filter: 'auto'` automatically turns on filtering if there are more than 5 * schema types added to the menu. */ filter?: 'auto' | boolean | undefined groups?: | Array<{ name: string title?: string of?: Array<string> }> | undefined /**