@sanity/sdk-react 0.0.0-alpha.2 → 0.0.0-alpha.21
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/README.md +38 -67
- package/dist/index.d.ts +4811 -2
- package/dist/index.js +1069 -2
- package/dist/index.js.map +1 -1
- package/package.json +27 -58
- package/src/_exports/index.ts +66 -10
- package/src/components/Login/LoginLinks.test.tsx +4 -14
- package/src/components/Login/LoginLinks.tsx +16 -31
- package/src/components/SDKProvider.test.tsx +79 -0
- package/src/components/SDKProvider.tsx +42 -0
- package/src/components/SanityApp.test.tsx +156 -0
- package/src/components/SanityApp.tsx +90 -0
- package/src/components/auth/AuthBoundary.test.tsx +6 -19
- package/src/components/auth/AuthBoundary.tsx +20 -4
- package/src/components/auth/Login.test.tsx +2 -16
- package/src/components/auth/Login.tsx +11 -30
- package/src/components/auth/LoginCallback.test.tsx +5 -20
- package/src/components/auth/LoginCallback.tsx +9 -14
- package/src/components/auth/LoginError.test.tsx +2 -17
- package/src/components/auth/LoginError.tsx +11 -16
- package/src/components/auth/LoginFooter.test.tsx +2 -16
- package/src/components/auth/LoginFooter.tsx +8 -24
- package/src/components/auth/LoginLayout.test.tsx +2 -16
- package/src/components/auth/LoginLayout.tsx +8 -38
- package/src/components/auth/authTestHelpers.tsx +11 -0
- package/src/components/utils.ts +22 -0
- package/src/context/SanityInstanceContext.ts +4 -0
- package/src/{components/context → context}/SanityProvider.test.tsx +2 -2
- package/src/context/SanityProvider.tsx +50 -0
- package/src/hooks/_synchronous-groq-js.mjs +4 -0
- package/src/hooks/auth/useAuthState.tsx +4 -5
- package/src/hooks/auth/useAuthToken.tsx +1 -1
- package/src/hooks/auth/useCurrentUser.tsx +28 -4
- package/src/hooks/auth/useDashboardOrganizationId.test.tsx +42 -0
- package/src/hooks/auth/useDashboardOrganizationId.tsx +29 -0
- package/src/hooks/auth/useHandleAuthCallback.test.tsx +16 -0
- package/src/hooks/auth/{useHandleCallback.tsx → useHandleAuthCallback.tsx} +7 -6
- package/src/hooks/auth/useLogOut.test.tsx +2 -2
- package/src/hooks/auth/useLogOut.tsx +1 -1
- package/src/hooks/auth/useLoginUrls.tsx +1 -0
- package/src/hooks/client/useClient.ts +9 -30
- package/src/hooks/comlink/useFrameConnection.test.tsx +167 -0
- package/src/hooks/comlink/useFrameConnection.ts +107 -0
- package/src/hooks/comlink/useManageFavorite.test.ts +111 -0
- package/src/hooks/comlink/useManageFavorite.ts +130 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +81 -0
- package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +106 -0
- package/src/hooks/comlink/useWindowConnection.test.ts +135 -0
- package/src/hooks/comlink/useWindowConnection.ts +122 -0
- package/src/hooks/context/useSanityInstance.test.tsx +2 -2
- package/src/hooks/context/useSanityInstance.ts +24 -8
- package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +178 -0
- package/src/hooks/dashboard/useNavigateToStudioDocument.ts +123 -0
- package/src/hooks/dashboard/useStudioWorkspacesByResourceId.test.tsx +278 -0
- package/src/hooks/dashboard/useStudioWorkspacesByResourceId.ts +92 -0
- package/src/hooks/datasets/useDatasets.ts +40 -0
- package/src/hooks/document/useApplyDocumentActions.test.ts +25 -0
- package/src/hooks/document/useApplyDocumentActions.ts +75 -0
- package/src/hooks/document/useDocument.test.ts +81 -0
- package/src/hooks/document/useDocument.ts +107 -0
- package/src/hooks/document/useDocumentEvent.test.ts +63 -0
- package/src/hooks/document/useDocumentEvent.ts +54 -0
- package/src/hooks/document/useDocumentPermissions.ts +84 -0
- package/src/hooks/document/useDocumentSyncStatus.test.ts +16 -0
- package/src/hooks/document/useDocumentSyncStatus.ts +33 -0
- package/src/hooks/document/useEditDocument.test.ts +179 -0
- package/src/hooks/document/useEditDocument.ts +195 -0
- package/src/hooks/documents/useDocuments.test.tsx +152 -0
- package/src/hooks/documents/useDocuments.ts +174 -0
- package/src/hooks/helpers/createCallbackHook.tsx +3 -2
- package/src/hooks/helpers/createStateSourceHook.test.tsx +66 -0
- package/src/hooks/helpers/createStateSourceHook.tsx +29 -10
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +259 -0
- package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +290 -0
- package/src/hooks/preview/usePreview.test.tsx +19 -10
- package/src/hooks/preview/usePreview.tsx +67 -13
- package/src/hooks/projection/useProjection.test.tsx +218 -0
- package/src/hooks/projection/useProjection.ts +147 -0
- package/src/hooks/projects/useProject.ts +48 -0
- package/src/hooks/projects/useProjects.ts +45 -0
- package/src/hooks/query/useQuery.test.tsx +188 -0
- package/src/hooks/query/useQuery.ts +103 -0
- package/src/hooks/users/useUsers.test.ts +163 -0
- package/src/hooks/users/useUsers.ts +107 -0
- package/src/utils/getEnv.ts +21 -0
- package/src/version.ts +8 -0
- package/src/vite-env.d.ts +10 -0
- package/dist/_chunks-es/useLogOut.js +0 -44
- package/dist/_chunks-es/useLogOut.js.map +0 -1
- package/dist/assets/bundle-CcAyERuZ.css +0 -11
- package/dist/components.d.ts +0 -257
- package/dist/components.js +0 -316
- package/dist/components.js.map +0 -1
- package/dist/hooks.d.ts +0 -187
- package/dist/hooks.js +0 -81
- package/dist/hooks.js.map +0 -1
- package/src/_exports/components.ts +0 -13
- package/src/_exports/hooks.ts +0 -9
- package/src/components/DocumentGridLayout/DocumentGridLayout.stories.tsx +0 -113
- package/src/components/DocumentGridLayout/DocumentGridLayout.test.tsx +0 -42
- package/src/components/DocumentGridLayout/DocumentGridLayout.tsx +0 -21
- package/src/components/DocumentListLayout/DocumentListLayout.stories.tsx +0 -105
- package/src/components/DocumentListLayout/DocumentListLayout.test.tsx +0 -42
- package/src/components/DocumentListLayout/DocumentListLayout.tsx +0 -12
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.md +0 -49
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.stories.tsx +0 -39
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.test.tsx +0 -30
- package/src/components/DocumentPreviewLayout/DocumentPreviewLayout.tsx +0 -171
- package/src/components/context/SanityProvider.tsx +0 -42
- package/src/css/css.config.js +0 -220
- package/src/css/paramour.css +0 -2347
- package/src/css/styles.css +0 -11
- package/src/hooks/auth/useHandleCallback.test.tsx +0 -16
- package/src/hooks/client/useClient.test.tsx +0 -130
- package/src/hooks/documentCollection/useDocuments.test.ts +0 -130
- package/src/hooks/documentCollection/useDocuments.ts +0 -87
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4816 @@
|
|
|
1
|
+
import {ActionsResult} from '@sanity/sdk'
|
|
2
|
+
import {ApplyDocumentActionsOptions} from '@sanity/sdk'
|
|
3
|
+
import {AuthProvider} from '@sanity/sdk'
|
|
4
|
+
import {AuthState} from '@sanity/sdk'
|
|
5
|
+
import {CanvasResource} from '@sanity/message-protocol'
|
|
6
|
+
import {ClientOptions} from '@sanity/sdk'
|
|
7
|
+
import {CurrentUser} from '@sanity/sdk'
|
|
8
|
+
import {DocumentAction} from '@sanity/sdk'
|
|
9
|
+
import {DocumentEvent} from '@sanity/sdk'
|
|
10
|
+
import {DocumentHandle} from '@sanity/sdk'
|
|
11
|
+
import {DocumentPermissionsResult} from '@sanity/sdk'
|
|
12
|
+
import {FallbackProps} from 'react-error-boundary'
|
|
13
|
+
import {FrameMessage} from '@sanity/sdk'
|
|
14
|
+
import {JsonMatch} from '@sanity/sdk'
|
|
15
|
+
import {JsonMatchPath} from '@sanity/sdk'
|
|
16
|
+
import {MediaResource} from '@sanity/message-protocol'
|
|
17
|
+
import {Observable} from 'rxjs'
|
|
18
|
+
import {PreviewValue} from '@sanity/sdk'
|
|
19
|
+
import {QueryOptions} from '@sanity/sdk'
|
|
20
|
+
import {ReactElement} from 'react'
|
|
21
|
+
import {ReactNode} from 'react'
|
|
22
|
+
import {Requester} from 'get-it'
|
|
23
|
+
import {ResourceId} from '@sanity/sdk'
|
|
24
|
+
import {ResourceType} from '@sanity/sdk'
|
|
25
|
+
import {SanityConfig} from '@sanity/sdk'
|
|
26
|
+
import {SanityDocument} from '@sanity/types'
|
|
27
|
+
import {SanityInstance} from '@sanity/sdk'
|
|
28
|
+
import {SanityProject as SanityProject_2} from '@sanity/sdk'
|
|
29
|
+
import {SanityUser as SanityUser_2} from '@sanity/sdk'
|
|
30
|
+
import {SortOrderingItem} from '@sanity/types'
|
|
31
|
+
import {StudioResource} from '@sanity/message-protocol'
|
|
32
|
+
import {ValidProjection} from '@sanity/sdk'
|
|
33
|
+
import {WindowMessage} from '@sanity/sdk'
|
|
34
|
+
|
|
35
|
+
/** @public */
|
|
36
|
+
declare type Action =
|
|
37
|
+
| CreateAction
|
|
38
|
+
| ReplaceDraftAction
|
|
39
|
+
| EditAction
|
|
40
|
+
| DeleteAction
|
|
41
|
+
| DiscardAction
|
|
42
|
+
| PublishAction
|
|
43
|
+
| UnpublishAction
|
|
44
|
+
|
|
45
|
+
/** @internal */
|
|
46
|
+
declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
47
|
+
returnFirst: false
|
|
48
|
+
returnDocuments: false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @internal */
|
|
52
|
+
declare type AllDocumentsMutationOptions = BaseMutationOptions & {
|
|
53
|
+
returnFirst: false
|
|
54
|
+
returnDocuments?: true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
declare type Any = any
|
|
62
|
+
|
|
63
|
+
/** @public */
|
|
64
|
+
declare type AssetMetadataType =
|
|
65
|
+
| 'location'
|
|
66
|
+
| 'exif'
|
|
67
|
+
| 'image'
|
|
68
|
+
| 'palette'
|
|
69
|
+
| 'lqip'
|
|
70
|
+
| 'blurhash'
|
|
71
|
+
| 'none'
|
|
72
|
+
|
|
73
|
+
/** @internal */
|
|
74
|
+
declare class AssetsClient {
|
|
75
|
+
#private
|
|
76
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
77
|
+
/**
|
|
78
|
+
* Uploads a file asset to the configured dataset
|
|
79
|
+
*
|
|
80
|
+
* @param assetType - Asset type (file)
|
|
81
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
82
|
+
* @param options - Options to use for the upload
|
|
83
|
+
*/
|
|
84
|
+
upload(
|
|
85
|
+
assetType: 'file',
|
|
86
|
+
body: UploadBody,
|
|
87
|
+
options?: UploadClientConfig,
|
|
88
|
+
): Promise<SanityAssetDocument>
|
|
89
|
+
/**
|
|
90
|
+
* Uploads an image asset to the configured dataset
|
|
91
|
+
*
|
|
92
|
+
* @param assetType - Asset type (image)
|
|
93
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
94
|
+
* @param options - Options to use for the upload
|
|
95
|
+
*/
|
|
96
|
+
upload(
|
|
97
|
+
assetType: 'image',
|
|
98
|
+
body: UploadBody,
|
|
99
|
+
options?: UploadClientConfig,
|
|
100
|
+
): Promise<SanityImageAssetDocument>
|
|
101
|
+
/**
|
|
102
|
+
* Uploads a file or an image asset to the configured dataset
|
|
103
|
+
*
|
|
104
|
+
* @param assetType - Asset type (file/image)
|
|
105
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
106
|
+
* @param options - Options to use for the upload
|
|
107
|
+
*/
|
|
108
|
+
upload(
|
|
109
|
+
assetType: 'file' | 'image',
|
|
110
|
+
body: UploadBody,
|
|
111
|
+
options?: UploadClientConfig,
|
|
112
|
+
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @internal */
|
|
116
|
+
declare type AttributeSet = {
|
|
117
|
+
[key: string]: Any
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A component that handles authentication flow and error boundaries for a
|
|
122
|
+
* protected section of the application.
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* This component manages different authentication states and renders the
|
|
126
|
+
* appropriate components based on that state.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```tsx
|
|
130
|
+
* function App() {
|
|
131
|
+
* return (
|
|
132
|
+
* <AuthBoundary header={<MyLogo />}>
|
|
133
|
+
* <ProtectedContent />
|
|
134
|
+
* </AuthBoundary>
|
|
135
|
+
* )
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
export declare function AuthBoundary({
|
|
142
|
+
LoginErrorComponent,
|
|
143
|
+
...props
|
|
144
|
+
}: AuthBoundaryProps): React.ReactNode
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
declare interface AuthBoundaryProps extends LoginLayoutProps {
|
|
150
|
+
/**
|
|
151
|
+
* Custom component to render the login screen.
|
|
152
|
+
* Receives all login layout props. Defaults to {@link Login}.
|
|
153
|
+
*/
|
|
154
|
+
LoginComponent?: React.ComponentType<LoginLayoutProps>
|
|
155
|
+
/**
|
|
156
|
+
* Custom component to render during OAuth callback processing.
|
|
157
|
+
* Receives all login layout props. Defaults to {@link LoginCallback}.
|
|
158
|
+
*/
|
|
159
|
+
CallbackComponent?: React.ComponentType<LoginLayoutProps>
|
|
160
|
+
/**
|
|
161
|
+
* Custom component to render when authentication errors occur.
|
|
162
|
+
* Receives login layout props and error boundary props. Defaults to
|
|
163
|
+
* {@link LoginError}
|
|
164
|
+
*/
|
|
165
|
+
LoginErrorComponent?: React.ComponentType<LoginErrorProps>
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** @internal */
|
|
169
|
+
declare type BaseActionOptions = RequestOptions & {
|
|
170
|
+
transactionId?: string
|
|
171
|
+
skipCrossDatasetReferenceValidation?: boolean
|
|
172
|
+
dryRun?: boolean
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** @internal */
|
|
176
|
+
declare type BaseMutationOptions = RequestOptions & {
|
|
177
|
+
visibility?: 'sync' | 'async' | 'deferred'
|
|
178
|
+
returnDocuments?: boolean
|
|
179
|
+
returnFirst?: boolean
|
|
180
|
+
dryRun?: boolean
|
|
181
|
+
autoGenerateArrayKeys?: boolean
|
|
182
|
+
skipCrossDatasetReferenceValidation?: boolean
|
|
183
|
+
transactionId?: string
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** @internal */
|
|
187
|
+
declare class BasePatch {
|
|
188
|
+
protected selection: PatchSelection
|
|
189
|
+
protected operations: PatchOperations
|
|
190
|
+
constructor(selection: PatchSelection, operations?: PatchOperations)
|
|
191
|
+
/**
|
|
192
|
+
* Sets the given attributes to the document. Does NOT merge objects.
|
|
193
|
+
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
194
|
+
*
|
|
195
|
+
* @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
|
|
196
|
+
*/
|
|
197
|
+
set(attrs: AttributeSet): this
|
|
198
|
+
/**
|
|
199
|
+
* Sets the given attributes to the document if they are not currently set. Does NOT merge objects.
|
|
200
|
+
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
201
|
+
*
|
|
202
|
+
* @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
|
|
203
|
+
*/
|
|
204
|
+
setIfMissing(attrs: AttributeSet): this
|
|
205
|
+
/**
|
|
206
|
+
* Performs a "diff-match-patch" operation on the string attributes provided.
|
|
207
|
+
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
208
|
+
*
|
|
209
|
+
* @param attrs - Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "dmp"\}
|
|
210
|
+
*/
|
|
211
|
+
diffMatchPatch(attrs: AttributeSet): this
|
|
212
|
+
/**
|
|
213
|
+
* Unsets the attribute paths provided.
|
|
214
|
+
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
215
|
+
*
|
|
216
|
+
* @param attrs - Attribute paths to unset.
|
|
217
|
+
*/
|
|
218
|
+
unset(attrs: string[]): this
|
|
219
|
+
/**
|
|
220
|
+
* Increment a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
|
|
221
|
+
*
|
|
222
|
+
* @param attrs - Object of attribute paths to increment, values representing the number to increment by.
|
|
223
|
+
*/
|
|
224
|
+
inc(attrs: {[key: string]: number}): this
|
|
225
|
+
/**
|
|
226
|
+
* Decrement a numeric value. Each entry in the argument is either an attribute or a JSON path. The value may be a positive or negative integer or floating-point value. The operation will fail if target value is not a numeric value, or doesn't exist.
|
|
227
|
+
*
|
|
228
|
+
* @param attrs - Object of attribute paths to decrement, values representing the number to decrement by.
|
|
229
|
+
*/
|
|
230
|
+
dec(attrs: {[key: string]: number}): this
|
|
231
|
+
/**
|
|
232
|
+
* Provides methods for modifying arrays, by inserting, appending and replacing elements via a JSONPath expression.
|
|
233
|
+
*
|
|
234
|
+
* @param at - Location to insert at, relative to the given selector, or 'replace' the matched path
|
|
235
|
+
* @param selector - JSONPath expression, eg `comments[-1]` or `blocks[_key=="abc123"]`
|
|
236
|
+
* @param items - Array of items to insert/replace
|
|
237
|
+
*/
|
|
238
|
+
insert(at: 'before' | 'after' | 'replace', selector: string, items: Any[]): this
|
|
239
|
+
/**
|
|
240
|
+
* Append the given items to the array at the given JSONPath
|
|
241
|
+
*
|
|
242
|
+
* @param selector - Attribute/path to append to, eg `comments` or `person.hobbies`
|
|
243
|
+
* @param items - Array of items to append to the array
|
|
244
|
+
*/
|
|
245
|
+
append(selector: string, items: Any[]): this
|
|
246
|
+
/**
|
|
247
|
+
* Prepend the given items to the array at the given JSONPath
|
|
248
|
+
*
|
|
249
|
+
* @param selector - Attribute/path to prepend to, eg `comments` or `person.hobbies`
|
|
250
|
+
* @param items - Array of items to prepend to the array
|
|
251
|
+
*/
|
|
252
|
+
prepend(selector: string, items: Any[]): this
|
|
253
|
+
/**
|
|
254
|
+
* Change the contents of an array by removing existing elements and/or adding new elements.
|
|
255
|
+
*
|
|
256
|
+
* @param selector - Attribute or JSONPath expression for array
|
|
257
|
+
* @param start - Index at which to start changing the array (with origin 0). If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end of the array (with origin -1) and will be set to 0 if absolute value is greater than the length of the array.x
|
|
258
|
+
* @param deleteCount - An integer indicating the number of old array elements to remove.
|
|
259
|
+
* @param items - The elements to add to the array, beginning at the start index. If you don't specify any elements, splice() will only remove elements from the array.
|
|
260
|
+
*/
|
|
261
|
+
splice(selector: string, start: number, deleteCount?: number, items?: Any[]): this
|
|
262
|
+
/**
|
|
263
|
+
* Adds a revision clause, preventing the document from being patched if the `_rev` property does not match the given value
|
|
264
|
+
*
|
|
265
|
+
* @param rev - Revision to lock the patch to
|
|
266
|
+
*/
|
|
267
|
+
ifRevisionId(rev: string): this
|
|
268
|
+
/**
|
|
269
|
+
* Return a plain JSON representation of the patch
|
|
270
|
+
*/
|
|
271
|
+
serialize(): PatchMutationOperation
|
|
272
|
+
/**
|
|
273
|
+
* Return a plain JSON representation of the patch
|
|
274
|
+
*/
|
|
275
|
+
toJSON(): PatchMutationOperation
|
|
276
|
+
/**
|
|
277
|
+
* Clears the patch of all operations
|
|
278
|
+
*/
|
|
279
|
+
reset(): this
|
|
280
|
+
protected _assign(op: keyof PatchOperations, props: Any, merge?: boolean): this
|
|
281
|
+
protected _set(op: keyof PatchOperations, props: Any): this
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** @internal */
|
|
285
|
+
declare class BaseTransaction {
|
|
286
|
+
protected operations: Mutation[]
|
|
287
|
+
protected trxId?: string
|
|
288
|
+
constructor(operations?: Mutation[], transactionId?: string)
|
|
289
|
+
/**
|
|
290
|
+
* Creates a new Sanity document. If `_id` is provided and already exists, the mutation will fail. If no `_id` is given, one will automatically be generated by the database.
|
|
291
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
292
|
+
*
|
|
293
|
+
* @param doc - Document to create. Requires a `_type` property.
|
|
294
|
+
*/
|
|
295
|
+
create<R extends Record<string, Any> = Record<string, Any>>(doc: SanityDocumentStub<R>): this
|
|
296
|
+
/**
|
|
297
|
+
* Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
|
|
298
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
299
|
+
*
|
|
300
|
+
* @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
|
|
301
|
+
*/
|
|
302
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
303
|
+
doc: IdentifiedSanityDocumentStub<R>,
|
|
304
|
+
): this
|
|
305
|
+
/**
|
|
306
|
+
* Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
|
|
307
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
308
|
+
*
|
|
309
|
+
* @param doc - Document to create or replace. Requires `_id` and `_type` properties.
|
|
310
|
+
*/
|
|
311
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
312
|
+
doc: IdentifiedSanityDocumentStub<R>,
|
|
313
|
+
): this
|
|
314
|
+
/**
|
|
315
|
+
* Deletes the document with the given document ID
|
|
316
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
317
|
+
*
|
|
318
|
+
* @param documentId - Document ID to delete
|
|
319
|
+
*/
|
|
320
|
+
delete(documentId: string): this
|
|
321
|
+
/**
|
|
322
|
+
* Gets the current transaction ID, if any
|
|
323
|
+
*/
|
|
324
|
+
transactionId(): string | undefined
|
|
325
|
+
/**
|
|
326
|
+
* Set the ID of this transaction.
|
|
327
|
+
*
|
|
328
|
+
* @param id - Transaction ID
|
|
329
|
+
*/
|
|
330
|
+
transactionId(id: string): this
|
|
331
|
+
/**
|
|
332
|
+
* Return a plain JSON representation of the transaction
|
|
333
|
+
*/
|
|
334
|
+
serialize(): Mutation[]
|
|
335
|
+
/**
|
|
336
|
+
* Return a plain JSON representation of the transaction
|
|
337
|
+
*/
|
|
338
|
+
toJSON(): Mutation[]
|
|
339
|
+
/**
|
|
340
|
+
* Clears the transaction of all operations
|
|
341
|
+
*/
|
|
342
|
+
reset(): this
|
|
343
|
+
protected _add(mut: Mutation): this
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* An error occurred. This is different from a network-level error (which will be emitted as 'error').
|
|
348
|
+
* Possible causes are things such as malformed filters, non-existant datasets or similar.
|
|
349
|
+
*
|
|
350
|
+
* @public
|
|
351
|
+
*/
|
|
352
|
+
declare type ChannelErrorEvent = {
|
|
353
|
+
type: 'channelError'
|
|
354
|
+
message: string
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** @public */
|
|
358
|
+
declare interface ClientConfig {
|
|
359
|
+
projectId?: string
|
|
360
|
+
dataset?: string
|
|
361
|
+
/** @defaultValue true */
|
|
362
|
+
useCdn?: boolean
|
|
363
|
+
token?: string
|
|
364
|
+
/**
|
|
365
|
+
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
366
|
+
* @remarks
|
|
367
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
|
|
368
|
+
* @defaultValue 'published'
|
|
369
|
+
*/
|
|
370
|
+
perspective?: ClientPerspective
|
|
371
|
+
apiHost?: string
|
|
372
|
+
/**
|
|
373
|
+
@remarks
|
|
374
|
+
* As of API version `v2025-02-19`, the default perspective has changed from `raw` to `published`. {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog}
|
|
375
|
+
*/
|
|
376
|
+
apiVersion?: string
|
|
377
|
+
proxy?: string
|
|
378
|
+
/**
|
|
379
|
+
* Optional request tag prefix for all request tags
|
|
380
|
+
*/
|
|
381
|
+
requestTagPrefix?: string
|
|
382
|
+
ignoreBrowserTokenWarning?: boolean
|
|
383
|
+
withCredentials?: boolean
|
|
384
|
+
allowReconfigure?: boolean
|
|
385
|
+
timeout?: number
|
|
386
|
+
/** Number of retries for requests. Defaults to 5. */
|
|
387
|
+
maxRetries?: number
|
|
388
|
+
/**
|
|
389
|
+
* The amount of time, in milliseconds, to wait before retrying, given an attemptNumber (starting at 0).
|
|
390
|
+
*
|
|
391
|
+
* Defaults to exponential back-off, starting at 100ms, doubling for each attempt, together with random
|
|
392
|
+
* jitter between 0 and 100 milliseconds. More specifically the following algorithm is used:
|
|
393
|
+
*
|
|
394
|
+
* Delay = 100 * 2^attemptNumber + randomNumberBetween0and100
|
|
395
|
+
*/
|
|
396
|
+
retryDelay?: (attemptNumber: number) => number
|
|
397
|
+
/**
|
|
398
|
+
* @deprecated Don't use
|
|
399
|
+
*/
|
|
400
|
+
useProjectHostname?: boolean
|
|
401
|
+
/**
|
|
402
|
+
* @deprecated Don't use
|
|
403
|
+
*/
|
|
404
|
+
requester?: Requester
|
|
405
|
+
/**
|
|
406
|
+
* Adds a `resultSourceMap` key to the API response, with the type `ContentSourceMap`
|
|
407
|
+
*/
|
|
408
|
+
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
409
|
+
/**
|
|
410
|
+
*@deprecated set `cache` and `next` options on `client.fetch` instead
|
|
411
|
+
*/
|
|
412
|
+
fetch?:
|
|
413
|
+
| {
|
|
414
|
+
cache?: ResponseQueryOptions['cache']
|
|
415
|
+
next?: ResponseQueryOptions['next']
|
|
416
|
+
}
|
|
417
|
+
| boolean
|
|
418
|
+
/**
|
|
419
|
+
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
420
|
+
*/
|
|
421
|
+
stega?: StegaConfig | boolean
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** @public */
|
|
425
|
+
declare type ClientPerspective =
|
|
426
|
+
| DeprecatedPreviewDrafts
|
|
427
|
+
| 'published'
|
|
428
|
+
| 'drafts'
|
|
429
|
+
| 'raw'
|
|
430
|
+
| StackablePerspective[]
|
|
431
|
+
|
|
432
|
+
/** @public */
|
|
433
|
+
declare type ClientReturn<
|
|
434
|
+
GroqString extends string,
|
|
435
|
+
Fallback = Any,
|
|
436
|
+
> = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* @public
|
|
440
|
+
*/
|
|
441
|
+
export declare type ComlinkStatus = 'idle' | 'handshaking' | 'connected' | 'disconnected'
|
|
442
|
+
|
|
443
|
+
/** @public */
|
|
444
|
+
declare interface ContentSourceMap {
|
|
445
|
+
mappings: ContentSourceMapMappings
|
|
446
|
+
documents: ContentSourceMapDocuments_2
|
|
447
|
+
paths: ContentSourceMapPaths
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** @public */
|
|
451
|
+
declare interface ContentSourceMapDocument extends ContentSourceMapDocumentBase {
|
|
452
|
+
_projectId?: undefined
|
|
453
|
+
_dataset?: undefined
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** @public */
|
|
457
|
+
declare interface ContentSourceMapDocument_2 extends ContentSourceMapDocumentBase_2 {
|
|
458
|
+
_projectId?: undefined
|
|
459
|
+
_dataset?: undefined
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** @public */
|
|
463
|
+
declare interface ContentSourceMapDocumentBase {
|
|
464
|
+
_id: string
|
|
465
|
+
_type: string
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** @public */
|
|
469
|
+
declare interface ContentSourceMapDocumentBase_2 {
|
|
470
|
+
_id: string
|
|
471
|
+
_type: string
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/** @public */
|
|
475
|
+
declare type ContentSourceMapDocuments = (
|
|
476
|
+
| ContentSourceMapDocument
|
|
477
|
+
| ContentSourceMapRemoteDocument
|
|
478
|
+
)[]
|
|
479
|
+
|
|
480
|
+
/** @public */
|
|
481
|
+
declare type ContentSourceMapDocuments_2 = (
|
|
482
|
+
| ContentSourceMapDocument_2
|
|
483
|
+
| ContentSourceMapRemoteDocument_2
|
|
484
|
+
)[]
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* DocumentValueSource is a path to a value within a document
|
|
488
|
+
* @public
|
|
489
|
+
*/
|
|
490
|
+
declare interface ContentSourceMapDocumentValueSource {
|
|
491
|
+
type: 'documentValue'
|
|
492
|
+
document: number
|
|
493
|
+
path: number
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* When a value is not from a source, its a literal
|
|
498
|
+
* @public
|
|
499
|
+
*/
|
|
500
|
+
declare interface ContentSourceMapLiteralSource {
|
|
501
|
+
type: 'literal'
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/** @public */
|
|
505
|
+
declare type ContentSourceMapMapping = ContentSourceMapValueMapping
|
|
506
|
+
|
|
507
|
+
/** @public */
|
|
508
|
+
declare type ContentSourceMapMappings = Record<string, ContentSourceMapMapping>
|
|
509
|
+
|
|
510
|
+
/** @alpha */
|
|
511
|
+
declare type ContentSourceMapParsedPath = (
|
|
512
|
+
| string
|
|
513
|
+
| number
|
|
514
|
+
| ContentSourceMapParsedPathKeyedSegment
|
|
515
|
+
)[]
|
|
516
|
+
|
|
517
|
+
/** @alpha */
|
|
518
|
+
declare type ContentSourceMapParsedPathKeyedSegment = {
|
|
519
|
+
_key: string
|
|
520
|
+
_index: number
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** @public */
|
|
524
|
+
declare type ContentSourceMapPaths = string[]
|
|
525
|
+
|
|
526
|
+
/** @public */
|
|
527
|
+
declare interface ContentSourceMapRemoteDocument extends ContentSourceMapDocumentBase {
|
|
528
|
+
_projectId: string
|
|
529
|
+
_dataset: string
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/** @public */
|
|
533
|
+
declare interface ContentSourceMapRemoteDocument_2 extends ContentSourceMapDocumentBase_2 {
|
|
534
|
+
_projectId: string
|
|
535
|
+
_dataset: string
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** @public */
|
|
539
|
+
declare type ContentSourceMapSource =
|
|
540
|
+
| ContentSourceMapDocumentValueSource
|
|
541
|
+
| ContentSourceMapLiteralSource
|
|
542
|
+
| ContentSourceMapUnknownSource
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* When a field source is unknown
|
|
546
|
+
* @public
|
|
547
|
+
*/
|
|
548
|
+
declare interface ContentSourceMapUnknownSource {
|
|
549
|
+
type: 'unknown'
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* ValueMapping is a mapping when for value that is from a single source value
|
|
554
|
+
* It may refer to a field within a document or a literal value
|
|
555
|
+
* @public
|
|
556
|
+
*/
|
|
557
|
+
declare interface ContentSourceMapValueMapping {
|
|
558
|
+
type: 'value'
|
|
559
|
+
source: ContentSourceMapSource
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Creates a new draft document. The published version of the document must not already exist.
|
|
564
|
+
* If the draft version of the document already exists the action will fail by default, but
|
|
565
|
+
* this can be adjusted to instead leave the existing document in place.
|
|
566
|
+
*
|
|
567
|
+
* @public
|
|
568
|
+
*/
|
|
569
|
+
declare type CreateAction = {
|
|
570
|
+
actionType: 'sanity.action.document.create'
|
|
571
|
+
/**
|
|
572
|
+
* ID of the published document to create a draft for.
|
|
573
|
+
*/
|
|
574
|
+
publishedId: string
|
|
575
|
+
/**
|
|
576
|
+
* Document to create. Requires a `_type` property.
|
|
577
|
+
*/
|
|
578
|
+
attributes: IdentifiedSanityDocumentStub
|
|
579
|
+
/**
|
|
580
|
+
* ifExists controls what to do if the draft already exists
|
|
581
|
+
*/
|
|
582
|
+
ifExists: 'fail' | 'ignore'
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** @public */
|
|
586
|
+
declare interface CurrentSanityUser {
|
|
587
|
+
id: string
|
|
588
|
+
name: string
|
|
589
|
+
email: string
|
|
590
|
+
profileImage: string | null
|
|
591
|
+
role: string
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
export {CurrentUser}
|
|
595
|
+
|
|
596
|
+
/** @public */
|
|
597
|
+
declare type DatasetAclMode = 'public' | 'private' | 'custom'
|
|
598
|
+
|
|
599
|
+
/** @public */
|
|
600
|
+
declare type DatasetResponse = {
|
|
601
|
+
datasetName: string
|
|
602
|
+
aclMode: DatasetAclMode
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** @internal */
|
|
606
|
+
declare class DatasetsClient {
|
|
607
|
+
#private
|
|
608
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
609
|
+
/**
|
|
610
|
+
* Create a new dataset with the given name
|
|
611
|
+
*
|
|
612
|
+
* @param name - Name of the dataset to create
|
|
613
|
+
* @param options - Options for the dataset
|
|
614
|
+
*/
|
|
615
|
+
create(
|
|
616
|
+
name: string,
|
|
617
|
+
options?: {
|
|
618
|
+
aclMode?: DatasetAclMode
|
|
619
|
+
},
|
|
620
|
+
): Promise<DatasetResponse>
|
|
621
|
+
/**
|
|
622
|
+
* Edit a dataset with the given name
|
|
623
|
+
*
|
|
624
|
+
* @param name - Name of the dataset to edit
|
|
625
|
+
* @param options - New options for the dataset
|
|
626
|
+
*/
|
|
627
|
+
edit(
|
|
628
|
+
name: string,
|
|
629
|
+
options?: {
|
|
630
|
+
aclMode?: DatasetAclMode
|
|
631
|
+
},
|
|
632
|
+
): Promise<DatasetResponse>
|
|
633
|
+
/**
|
|
634
|
+
* Delete a dataset with the given name
|
|
635
|
+
*
|
|
636
|
+
* @param name - Name of the dataset to delete
|
|
637
|
+
*/
|
|
638
|
+
delete(name: string): Promise<{
|
|
639
|
+
deleted: true
|
|
640
|
+
}>
|
|
641
|
+
/**
|
|
642
|
+
* Fetch a list of datasets for the configured project
|
|
643
|
+
*/
|
|
644
|
+
list(): Promise<DatasetsResponse>
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/** @public */
|
|
648
|
+
export declare type DatasetsResponse = {
|
|
649
|
+
name: string
|
|
650
|
+
aclMode: DatasetAclMode
|
|
651
|
+
createdAt: string
|
|
652
|
+
createdByUserId: string
|
|
653
|
+
addonFor: string | null
|
|
654
|
+
datasetProfile: string
|
|
655
|
+
features: string[]
|
|
656
|
+
tags: string[]
|
|
657
|
+
}[]
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
661
|
+
* If any draft version exists that is not specified for deletion this is an error.
|
|
662
|
+
* If the purge flag is set then the document history is also deleted.
|
|
663
|
+
*
|
|
664
|
+
* @public
|
|
665
|
+
*/
|
|
666
|
+
declare type DeleteAction = {
|
|
667
|
+
actionType: 'sanity.action.document.delete'
|
|
668
|
+
/**
|
|
669
|
+
* Published document ID to delete
|
|
670
|
+
*/
|
|
671
|
+
publishedId: string
|
|
672
|
+
/**
|
|
673
|
+
* Draft document ID to delete
|
|
674
|
+
*/
|
|
675
|
+
includeDrafts: string[]
|
|
676
|
+
/**
|
|
677
|
+
* Delete document history
|
|
678
|
+
*/
|
|
679
|
+
purge?: boolean
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* @deprecated use 'drafts' instead
|
|
684
|
+
*/
|
|
685
|
+
declare type DeprecatedPreviewDrafts = 'previewDrafts'
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Delete the draft version of a document.
|
|
689
|
+
* It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
|
|
690
|
+
*
|
|
691
|
+
* @public
|
|
692
|
+
*/
|
|
693
|
+
declare type DiscardAction = {
|
|
694
|
+
actionType: 'sanity.action.document.discard'
|
|
695
|
+
/**
|
|
696
|
+
* Draft document ID to delete
|
|
697
|
+
*/
|
|
698
|
+
draftId: string
|
|
699
|
+
/**
|
|
700
|
+
* Delete document history
|
|
701
|
+
*/
|
|
702
|
+
purge?: boolean
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* The listener has been told to explicitly disconnect and not reconnect.
|
|
707
|
+
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
708
|
+
* eg in the case of a deleted dataset, a blocked project or similar events.
|
|
709
|
+
*
|
|
710
|
+
* Note that this is not treated as an error on the observable, but will complete the observable.
|
|
711
|
+
*
|
|
712
|
+
* @public
|
|
713
|
+
*/
|
|
714
|
+
declare type DisconnectEvent = {
|
|
715
|
+
type: 'disconnect'
|
|
716
|
+
reason: string
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
export {DocumentHandle}
|
|
720
|
+
|
|
721
|
+
declare interface DocumentInteractionHistory {
|
|
722
|
+
recordEvent: (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => void
|
|
723
|
+
isConnected: boolean
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Configuration options for the useDocuments hook
|
|
728
|
+
*
|
|
729
|
+
* @beta
|
|
730
|
+
* @category Types
|
|
731
|
+
*/
|
|
732
|
+
export declare interface DocumentsOptions extends QueryOptions {
|
|
733
|
+
/**
|
|
734
|
+
* GROQ filter expression to apply to the query
|
|
735
|
+
*/
|
|
736
|
+
filter?: string
|
|
737
|
+
/**
|
|
738
|
+
* Number of items to load per batch (defaults to 25)
|
|
739
|
+
*/
|
|
740
|
+
batchSize?: number
|
|
741
|
+
/**
|
|
742
|
+
* Sorting configuration for the results
|
|
743
|
+
*/
|
|
744
|
+
orderings?: SortOrderingItem[]
|
|
745
|
+
/**
|
|
746
|
+
* Text search query to filter results
|
|
747
|
+
*/
|
|
748
|
+
search?: string
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Return value from the useDocuments hook
|
|
753
|
+
*
|
|
754
|
+
* @beta
|
|
755
|
+
* @category Types
|
|
756
|
+
*/
|
|
757
|
+
export declare interface DocumentsResponse {
|
|
758
|
+
/**
|
|
759
|
+
* Array of document handles for the current batch
|
|
760
|
+
*/
|
|
761
|
+
data: DocumentHandle[]
|
|
762
|
+
/**
|
|
763
|
+
* Whether there are more items available to load
|
|
764
|
+
*/
|
|
765
|
+
hasMore: boolean
|
|
766
|
+
/**
|
|
767
|
+
* Total count of items matching the query
|
|
768
|
+
*/
|
|
769
|
+
count: number
|
|
770
|
+
/**
|
|
771
|
+
* Whether a query is currently in progress
|
|
772
|
+
*/
|
|
773
|
+
isPending: boolean
|
|
774
|
+
/**
|
|
775
|
+
* Function to load the next batch of results
|
|
776
|
+
*/
|
|
777
|
+
loadMore: () => void
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Modifies an existing draft document.
|
|
782
|
+
* It applies the given patch to the document referenced by draftId.
|
|
783
|
+
* If there is no such document then one is created using the current state of the published version and then that is updated accordingly.
|
|
784
|
+
*
|
|
785
|
+
* @public
|
|
786
|
+
*/
|
|
787
|
+
declare type EditAction = {
|
|
788
|
+
actionType: 'sanity.action.document.edit'
|
|
789
|
+
/**
|
|
790
|
+
* Draft document ID to edit
|
|
791
|
+
*/
|
|
792
|
+
draftId: string
|
|
793
|
+
/**
|
|
794
|
+
* Published document ID to create draft from, if draft does not exist
|
|
795
|
+
*/
|
|
796
|
+
publishedId: string
|
|
797
|
+
/**
|
|
798
|
+
* Patch operations to apply
|
|
799
|
+
*/
|
|
800
|
+
patch: PatchOperations
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/** @public */
|
|
804
|
+
declare type FilterDefault = (props: {
|
|
805
|
+
/**
|
|
806
|
+
* The path to the value in the source document, for example if you queried for a document like this:
|
|
807
|
+
* `*[_type == "author"][0]{"slug": slug.current}`
|
|
808
|
+
* Then the `sourcePath` for `result.slug` would be `['slug', 'current']`.
|
|
809
|
+
*
|
|
810
|
+
*/
|
|
811
|
+
sourcePath: ContentSourceMapParsedPath
|
|
812
|
+
/**
|
|
813
|
+
* If `sourcePath` alone isn't enough to tell you if it's safe to contain stega strings, then you can use `sourceDocument`
|
|
814
|
+
* for additional metadata.
|
|
815
|
+
* It'll always have a `_type` property, which can be used to trace it to the Studio Schema that were used initially.
|
|
816
|
+
* It also has `_id` to help you debug and look at the whole document when troubleshooting.
|
|
817
|
+
* Finally, if the document origins in a Cross Dataset Reference you'll also have `_projectId` and `_dataset` properties to help you trace it.
|
|
818
|
+
*/
|
|
819
|
+
sourceDocument: ContentSourceMapDocuments[number]
|
|
820
|
+
/**
|
|
821
|
+
* If you don't colocate your Studio Schemas with your GROQ queries it might be hard to make sense of `sourcePath`,
|
|
822
|
+
* as it operates on the original shape of a document.
|
|
823
|
+
* In that case `resultPath` can be used, as it mirrors the path to the value in the result.
|
|
824
|
+
* For example in a query like this:
|
|
825
|
+
* `*[_type == "author"][0]{"slug": slug.current}`
|
|
826
|
+
* The `resultPath` for `result.slug` would be `['slug']`, while `sourcePath` will be `['slug', 'current']`.
|
|
827
|
+
*/
|
|
828
|
+
resultPath: ContentSourceMapParsedPath
|
|
829
|
+
/**
|
|
830
|
+
* You can also use your own string validation logic to determine if it's safe.
|
|
831
|
+
*/
|
|
832
|
+
value: string
|
|
833
|
+
/**
|
|
834
|
+
* If you want to keep the default filtering behavior, but only override it for a specific path, you can use `filterDefault` to do that.
|
|
835
|
+
* For example, here all "icon" documents in a Page Builder skips encoding:
|
|
836
|
+
* ```ts
|
|
837
|
+
{
|
|
838
|
+
filter: (props) => {
|
|
839
|
+
switch (props.sourceDocument._type) {
|
|
840
|
+
case 'icon':
|
|
841
|
+
return false
|
|
842
|
+
default:
|
|
843
|
+
return props.filterDefault(props)
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
filterDefault: FilterDefault
|
|
850
|
+
}) => boolean
|
|
851
|
+
|
|
852
|
+
/** @public */
|
|
853
|
+
declare interface FilteredResponseQueryOptions extends ResponseQueryOptions {
|
|
854
|
+
filterResponse?: true
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** @internal */
|
|
858
|
+
declare type FirstDocumentIdMutationOptions = BaseMutationOptions & {
|
|
859
|
+
returnFirst?: true
|
|
860
|
+
returnDocuments: false
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/** @internal */
|
|
864
|
+
declare type FirstDocumentMutationOptions = BaseMutationOptions & {
|
|
865
|
+
returnFirst?: true
|
|
866
|
+
returnDocuments?: true
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* @internal
|
|
871
|
+
*/
|
|
872
|
+
export declare interface FrameConnection<TFrameMessage extends FrameMessage> {
|
|
873
|
+
connect: (frameWindow: Window) => () => void
|
|
874
|
+
sendMessage: <T extends TFrameMessage['type']>(
|
|
875
|
+
...params: Extract<
|
|
876
|
+
TFrameMessage,
|
|
877
|
+
{
|
|
878
|
+
type: T
|
|
879
|
+
}
|
|
880
|
+
>['data'] extends undefined
|
|
881
|
+
? [type: T]
|
|
882
|
+
: [
|
|
883
|
+
type: T,
|
|
884
|
+
data: Extract<
|
|
885
|
+
TFrameMessage,
|
|
886
|
+
{
|
|
887
|
+
type: T
|
|
888
|
+
}
|
|
889
|
+
>['data'],
|
|
890
|
+
]
|
|
891
|
+
) => void
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/** @public */
|
|
895
|
+
declare type HttpRequest = {
|
|
896
|
+
(options: RequestOptions, requester: Requester): ReturnType<Requester>
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/** @public */
|
|
900
|
+
declare type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent_2
|
|
901
|
+
|
|
902
|
+
/** @public */
|
|
903
|
+
declare type IdentifiedSanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
|
|
904
|
+
[P in keyof T]: T[P]
|
|
905
|
+
} & {
|
|
906
|
+
_id: string
|
|
907
|
+
} & SanityDocumentStub
|
|
908
|
+
|
|
909
|
+
/** @public */
|
|
910
|
+
declare interface InitializedClientConfig extends ClientConfig {
|
|
911
|
+
apiHost: string
|
|
912
|
+
apiVersion: string
|
|
913
|
+
useProjectHostname: boolean
|
|
914
|
+
useCdn: boolean
|
|
915
|
+
/**
|
|
916
|
+
* @deprecated Internal, don't use
|
|
917
|
+
*/
|
|
918
|
+
isDefaultApi: boolean
|
|
919
|
+
/**
|
|
920
|
+
* @deprecated Internal, don't use
|
|
921
|
+
*/
|
|
922
|
+
url: string
|
|
923
|
+
/**
|
|
924
|
+
* @deprecated Internal, don't use
|
|
925
|
+
*/
|
|
926
|
+
cdnUrl: string
|
|
927
|
+
/**
|
|
928
|
+
* The fully initialized stega config, can be used to check if stega is enabled
|
|
929
|
+
*/
|
|
930
|
+
stega: InitializedStegaConfig
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** @public */
|
|
934
|
+
declare type InitializedStegaConfig = Omit<StegaConfig, StegaConfigRequiredKeys> &
|
|
935
|
+
Required<Pick<StegaConfig, StegaConfigRequiredKeys>>
|
|
936
|
+
|
|
937
|
+
/** @internal */
|
|
938
|
+
declare type InsertPatch =
|
|
939
|
+
| {
|
|
940
|
+
before: string
|
|
941
|
+
items: Any[]
|
|
942
|
+
}
|
|
943
|
+
| {
|
|
944
|
+
after: string
|
|
945
|
+
items: Any[]
|
|
946
|
+
}
|
|
947
|
+
| {
|
|
948
|
+
replace: string
|
|
949
|
+
items: Any[]
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
954
|
+
*
|
|
955
|
+
* @param query - GROQ-filter to listen to changes for
|
|
956
|
+
* @param params - Optional query parameters
|
|
957
|
+
* @param options - Optional listener options
|
|
958
|
+
* @public
|
|
959
|
+
*/
|
|
960
|
+
declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
961
|
+
this: SanityClient | ObservableSanityClient,
|
|
962
|
+
query: string,
|
|
963
|
+
params?: ListenParams,
|
|
964
|
+
): Observable<MutationEvent_2<R>>
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
968
|
+
*
|
|
969
|
+
* @param query - GROQ-filter to listen to changes for
|
|
970
|
+
* @param params - Optional query parameters
|
|
971
|
+
* @param options - Optional listener options
|
|
972
|
+
* @public
|
|
973
|
+
*/
|
|
974
|
+
declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
975
|
+
this: SanityClient | ObservableSanityClient,
|
|
976
|
+
query: string,
|
|
977
|
+
params?: ListenParams,
|
|
978
|
+
options?: ListenOptions,
|
|
979
|
+
): Observable<ListenEvent<R>>
|
|
980
|
+
|
|
981
|
+
/** @public */
|
|
982
|
+
declare type ListenEvent<R extends Record<string, Any>> =
|
|
983
|
+
| MutationEvent_2<R>
|
|
984
|
+
| ChannelErrorEvent
|
|
985
|
+
| DisconnectEvent
|
|
986
|
+
| ReconnectEvent
|
|
987
|
+
| WelcomeEvent
|
|
988
|
+
| OpenEvent
|
|
989
|
+
|
|
990
|
+
/** @public */
|
|
991
|
+
declare type ListenEventName =
|
|
992
|
+
/** A mutation was performed */
|
|
993
|
+
| 'mutation'
|
|
994
|
+
/** The listener has been (re)established */
|
|
995
|
+
| 'welcome'
|
|
996
|
+
/** The listener has been disconnected, and a reconnect attempt is scheduled */
|
|
997
|
+
| 'reconnect'
|
|
998
|
+
|
|
999
|
+
/** @public */
|
|
1000
|
+
declare interface ListenOptions {
|
|
1001
|
+
/**
|
|
1002
|
+
* Whether or not to include the resulting document in addition to the mutations performed.
|
|
1003
|
+
* If you do not need the actual document, set this to `false` to reduce bandwidth usage.
|
|
1004
|
+
* The result will be available on the `.result` property of the events.
|
|
1005
|
+
* @defaultValue `true`
|
|
1006
|
+
*/
|
|
1007
|
+
includeResult?: boolean
|
|
1008
|
+
/**
|
|
1009
|
+
* Whether or not to include the mutations that was performed.
|
|
1010
|
+
* If you do not need the mutations, set this to `false` to reduce bandwidth usage.
|
|
1011
|
+
* @defaultValue `true`
|
|
1012
|
+
*/
|
|
1013
|
+
includeMutations?: boolean
|
|
1014
|
+
/**
|
|
1015
|
+
* Whether or not to include the document as it looked before the mutation event.
|
|
1016
|
+
* The previous revision will be available on the `.previous` property of the events,
|
|
1017
|
+
* and may be `null` in the case of a new document.
|
|
1018
|
+
* @defaultValue `false`
|
|
1019
|
+
*/
|
|
1020
|
+
includePreviousRevision?: boolean
|
|
1021
|
+
/**
|
|
1022
|
+
* Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
|
|
1023
|
+
* for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
|
|
1024
|
+
* If you need events from drafts and versions, set this to `true`.
|
|
1025
|
+
* Note: Keep in mind that additional document variants may be introduced in the future, so it's
|
|
1026
|
+
* recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
|
|
1027
|
+
* explicitly checking whether the event is for a draft or a version.
|
|
1028
|
+
* @defaultValue `false`
|
|
1029
|
+
*/
|
|
1030
|
+
includeAllVersions?: boolean
|
|
1031
|
+
/**
|
|
1032
|
+
* Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
|
|
1033
|
+
* or only after they are available for queries (query). Note that this is on a best-effort basis,
|
|
1034
|
+
* and listeners with `query` may in certain cases (notably with deferred transactions) receive events
|
|
1035
|
+
* that are not yet visible to queries.
|
|
1036
|
+
*
|
|
1037
|
+
* @defaultValue `'transaction'`
|
|
1038
|
+
*/
|
|
1039
|
+
visibility?: 'transaction' | 'query'
|
|
1040
|
+
/**
|
|
1041
|
+
* Array of event names to include in the observable. By default, only mutation events are included.
|
|
1042
|
+
*
|
|
1043
|
+
* @defaultValue `['mutation']`
|
|
1044
|
+
*/
|
|
1045
|
+
events?: ListenEventName[]
|
|
1046
|
+
/**
|
|
1047
|
+
* Format of "effects", eg the resulting changes of a mutation.
|
|
1048
|
+
* Currently only `mendoza` is supported, and (if set) will include `apply` and `revert` arrays
|
|
1049
|
+
* in the mutation events under the `effects` property.
|
|
1050
|
+
*
|
|
1051
|
+
* See {@link https://github.com/sanity-io/mendoza | The mendoza docs} for more info
|
|
1052
|
+
*
|
|
1053
|
+
* @defaultValue `undefined`
|
|
1054
|
+
*/
|
|
1055
|
+
effectFormat?: 'mendoza'
|
|
1056
|
+
/**
|
|
1057
|
+
* Optional request tag for the listener. Use to identify the request in logs.
|
|
1058
|
+
*
|
|
1059
|
+
* @defaultValue `undefined`
|
|
1060
|
+
*/
|
|
1061
|
+
tag?: string
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/** @public */
|
|
1065
|
+
declare type ListenParams = {
|
|
1066
|
+
[key: string]: Any
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/**
|
|
1070
|
+
* @public
|
|
1071
|
+
*/
|
|
1072
|
+
declare class LiveClient {
|
|
1073
|
+
#private
|
|
1074
|
+
constructor(client: SanityClient | ObservableSanityClient)
|
|
1075
|
+
/**
|
|
1076
|
+
* Requires `apiVersion` to be `2021-03-25` or later.
|
|
1077
|
+
*/
|
|
1078
|
+
events({
|
|
1079
|
+
includeDrafts,
|
|
1080
|
+
tag: _tag,
|
|
1081
|
+
}?: {
|
|
1082
|
+
includeDrafts?: boolean
|
|
1083
|
+
/**
|
|
1084
|
+
* Optional request tag for the listener. Use to identify the request in logs.
|
|
1085
|
+
*
|
|
1086
|
+
* @defaultValue `undefined`
|
|
1087
|
+
*/
|
|
1088
|
+
tag?: string
|
|
1089
|
+
}): Observable<LiveEvent>
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
/** @public */
|
|
1093
|
+
declare type LiveEvent = LiveEventRestart | LiveEventReconnect | LiveEventMessage | LiveEventWelcome
|
|
1094
|
+
|
|
1095
|
+
/** @public */
|
|
1096
|
+
declare interface LiveEventMessage {
|
|
1097
|
+
type: 'message'
|
|
1098
|
+
id: string
|
|
1099
|
+
tags: SyncTag[]
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
/** @public */
|
|
1103
|
+
declare interface LiveEventReconnect {
|
|
1104
|
+
type: 'reconnect'
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
/** @public */
|
|
1108
|
+
declare interface LiveEventRestart {
|
|
1109
|
+
type: 'restart'
|
|
1110
|
+
id: string
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
/** @public */
|
|
1114
|
+
declare interface LiveEventWelcome {
|
|
1115
|
+
type: 'welcome'
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/** @public */
|
|
1119
|
+
declare type Logger =
|
|
1120
|
+
| typeof console
|
|
1121
|
+
| Partial<
|
|
1122
|
+
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
1123
|
+
>
|
|
1124
|
+
|
|
1125
|
+
/**
|
|
1126
|
+
* @alpha
|
|
1127
|
+
*/
|
|
1128
|
+
declare type LoginErrorProps = FallbackProps & LoginLayoutProps
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* @alpha
|
|
1132
|
+
*/
|
|
1133
|
+
declare interface LoginLayoutProps {
|
|
1134
|
+
/** Optional header content rendered at top of card */
|
|
1135
|
+
header?: React.ReactNode
|
|
1136
|
+
/** Optional footer content rendered below card. Defaults to an internal login footer */
|
|
1137
|
+
footer?: React.ReactNode
|
|
1138
|
+
/** Main content rendered in card body */
|
|
1139
|
+
children?: React.ReactNode
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
declare interface ManageFavorite {
|
|
1143
|
+
favorite: () => void
|
|
1144
|
+
unfavorite: () => void
|
|
1145
|
+
isFavorited: boolean
|
|
1146
|
+
isConnected: boolean
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* @public
|
|
1151
|
+
*/
|
|
1152
|
+
declare type MessageData = Record<string, unknown> | undefined
|
|
1153
|
+
|
|
1154
|
+
/**
|
|
1155
|
+
* @internal
|
|
1156
|
+
*/
|
|
1157
|
+
export declare type MessageHandler<TWindowMessage extends WindowMessage> = (
|
|
1158
|
+
event: TWindowMessage['data'],
|
|
1159
|
+
) => TWindowMessage['response'] | Promise<TWindowMessage['response']>
|
|
1160
|
+
|
|
1161
|
+
/** @internal */
|
|
1162
|
+
declare interface MultipleActionResult {
|
|
1163
|
+
transactionId: string
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
/** @internal */
|
|
1167
|
+
declare interface MultipleMutationResult {
|
|
1168
|
+
transactionId: string
|
|
1169
|
+
documentIds: string[]
|
|
1170
|
+
results: {
|
|
1171
|
+
id: string
|
|
1172
|
+
operation: MutationOperation
|
|
1173
|
+
}[]
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/** @public */
|
|
1177
|
+
declare type Mutation<R extends Record<string, Any> = Record<string, Any>> =
|
|
1178
|
+
| {
|
|
1179
|
+
create: SanityDocumentStub<R>
|
|
1180
|
+
}
|
|
1181
|
+
| {
|
|
1182
|
+
createOrReplace: IdentifiedSanityDocumentStub<R>
|
|
1183
|
+
}
|
|
1184
|
+
| {
|
|
1185
|
+
createIfNotExists: IdentifiedSanityDocumentStub<R>
|
|
1186
|
+
}
|
|
1187
|
+
| {
|
|
1188
|
+
delete: MutationSelection
|
|
1189
|
+
}
|
|
1190
|
+
| {
|
|
1191
|
+
patch: PatchMutationOperation
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* A mutation was performed. Note that when updating multiple documents in a transaction,
|
|
1196
|
+
* each document affected will get a separate mutation event.
|
|
1197
|
+
*
|
|
1198
|
+
* @public
|
|
1199
|
+
*/
|
|
1200
|
+
declare type MutationEvent_2<R extends Record<string, Any> = Record<string, Any>> = {
|
|
1201
|
+
type: 'mutation'
|
|
1202
|
+
/**
|
|
1203
|
+
* The ID of the document that was affected
|
|
1204
|
+
*/
|
|
1205
|
+
documentId: string
|
|
1206
|
+
/**
|
|
1207
|
+
* A unique ID for this event
|
|
1208
|
+
*/
|
|
1209
|
+
eventId: string
|
|
1210
|
+
/**
|
|
1211
|
+
* The user ID of the user that performed the mutation
|
|
1212
|
+
*/
|
|
1213
|
+
identity: string
|
|
1214
|
+
/**
|
|
1215
|
+
* An array of mutations that were performed. Note that this can differ slightly from the
|
|
1216
|
+
* mutations sent to the server, as the server may perform some mutations automatically.
|
|
1217
|
+
*/
|
|
1218
|
+
mutations: Mutation[]
|
|
1219
|
+
/**
|
|
1220
|
+
* The revision ID of the document before the mutation was performed
|
|
1221
|
+
*/
|
|
1222
|
+
previousRev?: string
|
|
1223
|
+
/**
|
|
1224
|
+
* The revision ID of the document after the mutation was performed
|
|
1225
|
+
*/
|
|
1226
|
+
resultRev?: string
|
|
1227
|
+
/**
|
|
1228
|
+
* The document as it looked after the mutation was performed. This is only included if
|
|
1229
|
+
* the listener was configured with `includeResult: true`.
|
|
1230
|
+
*/
|
|
1231
|
+
result?: SanityDocument_2<R>
|
|
1232
|
+
/**
|
|
1233
|
+
* The document as it looked before the mutation was performed. This is only included if
|
|
1234
|
+
* the listener was configured with `includePreviousRevision: true`.
|
|
1235
|
+
*/
|
|
1236
|
+
previous?: SanityDocument_2<R> | null
|
|
1237
|
+
/**
|
|
1238
|
+
* The effects of the mutation, if the listener was configured with `effectFormat: 'mendoza'`.
|
|
1239
|
+
* Object with `apply` and `revert` arrays, see {@link https://github.com/sanity-io/mendoza}.
|
|
1240
|
+
*/
|
|
1241
|
+
effects?: {
|
|
1242
|
+
apply: unknown[]
|
|
1243
|
+
revert: unknown[]
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* A timestamp for when the mutation was performed
|
|
1247
|
+
*/
|
|
1248
|
+
timestamp: string
|
|
1249
|
+
/**
|
|
1250
|
+
* The transaction ID for the mutation
|
|
1251
|
+
*/
|
|
1252
|
+
transactionId: string
|
|
1253
|
+
/**
|
|
1254
|
+
* The type of transition the document went through.
|
|
1255
|
+
*
|
|
1256
|
+
* - `update` means the document was previously part of the subscribed set of documents,
|
|
1257
|
+
* and still is.
|
|
1258
|
+
* - `appear` means the document was not previously part of the subscribed set of documents,
|
|
1259
|
+
* but is now. This can happen both on create or if updating to a state where it now matches
|
|
1260
|
+
* the filter provided to the listener.
|
|
1261
|
+
* - `disappear` means the document was previously part of the subscribed set of documents,
|
|
1262
|
+
* but is no longer. This can happen both on delete or if updating to a state where it no
|
|
1263
|
+
* longer matches the filter provided to the listener.
|
|
1264
|
+
*/
|
|
1265
|
+
transition: 'update' | 'appear' | 'disappear'
|
|
1266
|
+
/**
|
|
1267
|
+
* Whether the change that triggered this event is visible to queries (query) or only to
|
|
1268
|
+
* subsequent transactions (transaction). The listener client can specify a preferred visibility
|
|
1269
|
+
* through the `visibility` parameter on the listener, but this is only on a best-effort basis,
|
|
1270
|
+
* and may yet not be accurate.
|
|
1271
|
+
*/
|
|
1272
|
+
visibility: 'query' | 'transaction'
|
|
1273
|
+
/**
|
|
1274
|
+
* The total number of events that will be sent for this transaction.
|
|
1275
|
+
* Note that this may differ from the amount of _documents_ affected by the transaction, as this
|
|
1276
|
+
* number only includes the documents that matches the given filter.
|
|
1277
|
+
*
|
|
1278
|
+
* This can be useful if you need to perform changes to all matched documents atomically,
|
|
1279
|
+
* eg you would wait for `transactionTotalEvents` events with the same `transactionId` before
|
|
1280
|
+
* applying the changes locally.
|
|
1281
|
+
*/
|
|
1282
|
+
transactionTotalEvents: number
|
|
1283
|
+
/**
|
|
1284
|
+
* The index of this event within the transaction. Note that events may be delivered out of order,
|
|
1285
|
+
* and that the index is zero-based.
|
|
1286
|
+
*/
|
|
1287
|
+
transactionCurrentEvent: number
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
/** @internal */
|
|
1291
|
+
declare type MutationOperation = 'create' | 'delete' | 'update' | 'none'
|
|
1292
|
+
|
|
1293
|
+
/** @internal */
|
|
1294
|
+
declare type MutationSelection =
|
|
1295
|
+
| {
|
|
1296
|
+
query: string
|
|
1297
|
+
params?: MutationSelectionQueryParams
|
|
1298
|
+
}
|
|
1299
|
+
| {
|
|
1300
|
+
id: string | string[]
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/** @internal */
|
|
1304
|
+
declare type MutationSelectionQueryParams = {
|
|
1305
|
+
[key: string]: Any
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
declare interface NavigateToStudioResult {
|
|
1309
|
+
navigateToStudioDocument: () => void
|
|
1310
|
+
isConnected: boolean
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
/** @internal */
|
|
1314
|
+
declare class ObservableAssetsClient {
|
|
1315
|
+
#private
|
|
1316
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1317
|
+
/**
|
|
1318
|
+
* Uploads a file asset to the configured dataset
|
|
1319
|
+
*
|
|
1320
|
+
* @param assetType - Asset type (file)
|
|
1321
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
1322
|
+
* @param options - Options to use for the upload
|
|
1323
|
+
*/
|
|
1324
|
+
upload(
|
|
1325
|
+
assetType: 'file',
|
|
1326
|
+
body: UploadBody,
|
|
1327
|
+
options?: UploadClientConfig,
|
|
1328
|
+
): Observable<
|
|
1329
|
+
HttpRequestEvent<{
|
|
1330
|
+
document: SanityAssetDocument
|
|
1331
|
+
}>
|
|
1332
|
+
>
|
|
1333
|
+
/**
|
|
1334
|
+
* Uploads an image asset to the configured dataset
|
|
1335
|
+
*
|
|
1336
|
+
* @param assetType - Asset type (image)
|
|
1337
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
1338
|
+
* @param options - Options to use for the upload
|
|
1339
|
+
*/
|
|
1340
|
+
upload(
|
|
1341
|
+
assetType: 'image',
|
|
1342
|
+
body: UploadBody,
|
|
1343
|
+
options?: UploadClientConfig,
|
|
1344
|
+
): Observable<
|
|
1345
|
+
HttpRequestEvent<{
|
|
1346
|
+
document: SanityImageAssetDocument
|
|
1347
|
+
}>
|
|
1348
|
+
>
|
|
1349
|
+
/**
|
|
1350
|
+
* Uploads a file or an image asset to the configured dataset
|
|
1351
|
+
*
|
|
1352
|
+
* @param assetType - Asset type (file/image)
|
|
1353
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
1354
|
+
* @param options - Options to use for the upload
|
|
1355
|
+
*/
|
|
1356
|
+
upload(
|
|
1357
|
+
assetType: 'file' | 'image',
|
|
1358
|
+
body: UploadBody,
|
|
1359
|
+
options?: UploadClientConfig,
|
|
1360
|
+
): Observable<
|
|
1361
|
+
HttpRequestEvent<{
|
|
1362
|
+
document: SanityAssetDocument | SanityImageAssetDocument
|
|
1363
|
+
}>
|
|
1364
|
+
>
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
/** @internal */
|
|
1368
|
+
declare class ObservableDatasetsClient {
|
|
1369
|
+
#private
|
|
1370
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1371
|
+
/**
|
|
1372
|
+
* Create a new dataset with the given name
|
|
1373
|
+
*
|
|
1374
|
+
* @param name - Name of the dataset to create
|
|
1375
|
+
* @param options - Options for the dataset
|
|
1376
|
+
*/
|
|
1377
|
+
create(
|
|
1378
|
+
name: string,
|
|
1379
|
+
options?: {
|
|
1380
|
+
aclMode?: DatasetAclMode
|
|
1381
|
+
},
|
|
1382
|
+
): Observable<DatasetResponse>
|
|
1383
|
+
/**
|
|
1384
|
+
* Edit a dataset with the given name
|
|
1385
|
+
*
|
|
1386
|
+
* @param name - Name of the dataset to edit
|
|
1387
|
+
* @param options - New options for the dataset
|
|
1388
|
+
*/
|
|
1389
|
+
edit(
|
|
1390
|
+
name: string,
|
|
1391
|
+
options?: {
|
|
1392
|
+
aclMode?: DatasetAclMode
|
|
1393
|
+
},
|
|
1394
|
+
): Observable<DatasetResponse>
|
|
1395
|
+
/**
|
|
1396
|
+
* Delete a dataset with the given name
|
|
1397
|
+
*
|
|
1398
|
+
* @param name - Name of the dataset to delete
|
|
1399
|
+
*/
|
|
1400
|
+
delete(name: string): Observable<{
|
|
1401
|
+
deleted: true
|
|
1402
|
+
}>
|
|
1403
|
+
/**
|
|
1404
|
+
* Fetch a list of datasets for the configured project
|
|
1405
|
+
*/
|
|
1406
|
+
list(): Observable<DatasetsResponse>
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
/** @public */
|
|
1410
|
+
declare class ObservablePatch extends BasePatch {
|
|
1411
|
+
#private
|
|
1412
|
+
constructor(
|
|
1413
|
+
selection: PatchSelection,
|
|
1414
|
+
operations?: PatchOperations,
|
|
1415
|
+
client?: ObservableSanityClient,
|
|
1416
|
+
)
|
|
1417
|
+
/**
|
|
1418
|
+
* Clones the patch
|
|
1419
|
+
*/
|
|
1420
|
+
clone(): ObservablePatch
|
|
1421
|
+
/**
|
|
1422
|
+
* Commit the patch, returning an observable that produces the first patched document
|
|
1423
|
+
*
|
|
1424
|
+
* @param options - Options for the mutation operation
|
|
1425
|
+
*/
|
|
1426
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
1427
|
+
options: FirstDocumentMutationOptions,
|
|
1428
|
+
): Observable<SanityDocument_2<R>>
|
|
1429
|
+
/**
|
|
1430
|
+
* Commit the patch, returning an observable that produces an array of the mutated documents
|
|
1431
|
+
*
|
|
1432
|
+
* @param options - Options for the mutation operation
|
|
1433
|
+
*/
|
|
1434
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
1435
|
+
options: AllDocumentsMutationOptions,
|
|
1436
|
+
): Observable<SanityDocument_2<R>[]>
|
|
1437
|
+
/**
|
|
1438
|
+
* Commit the patch, returning an observable that produces a mutation result object
|
|
1439
|
+
*
|
|
1440
|
+
* @param options - Options for the mutation operation
|
|
1441
|
+
*/
|
|
1442
|
+
commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
1443
|
+
/**
|
|
1444
|
+
* Commit the patch, returning an observable that produces a mutation result object
|
|
1445
|
+
*
|
|
1446
|
+
* @param options - Options for the mutation operation
|
|
1447
|
+
*/
|
|
1448
|
+
commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
1449
|
+
/**
|
|
1450
|
+
* Commit the patch, returning an observable that produces the first patched document
|
|
1451
|
+
*
|
|
1452
|
+
* @param options - Options for the mutation operation
|
|
1453
|
+
*/
|
|
1454
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
1455
|
+
options?: BaseMutationOptions,
|
|
1456
|
+
): Observable<SanityDocument_2<R>>
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/** @public */
|
|
1460
|
+
declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
|
|
1461
|
+
|
|
1462
|
+
/** @internal */
|
|
1463
|
+
declare class ObservableProjectsClient {
|
|
1464
|
+
#private
|
|
1465
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1466
|
+
/**
|
|
1467
|
+
* Fetch a list of projects the authenticated user has access to.
|
|
1468
|
+
*
|
|
1469
|
+
* @param options - Options for the list request
|
|
1470
|
+
* @param options.includeMembers - Whether to include members in the response (default: true)
|
|
1471
|
+
*/
|
|
1472
|
+
list(options?: {includeMembers?: true}): Observable<SanityProject[]>
|
|
1473
|
+
list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
|
|
1474
|
+
/**
|
|
1475
|
+
* Fetch a project by project ID
|
|
1476
|
+
*
|
|
1477
|
+
* @param projectId - ID of the project to fetch
|
|
1478
|
+
*/
|
|
1479
|
+
getById(projectId: string): Observable<SanityProject>
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
/** @public */
|
|
1483
|
+
declare class ObservableSanityClient {
|
|
1484
|
+
#private
|
|
1485
|
+
assets: ObservableAssetsClient
|
|
1486
|
+
datasets: ObservableDatasetsClient
|
|
1487
|
+
live: LiveClient
|
|
1488
|
+
projects: ObservableProjectsClient
|
|
1489
|
+
users: ObservableUsersClient
|
|
1490
|
+
/**
|
|
1491
|
+
* Instance properties
|
|
1492
|
+
*/
|
|
1493
|
+
listen: typeof _listen
|
|
1494
|
+
constructor(httpRequest: HttpRequest, config?: ClientConfig)
|
|
1495
|
+
/**
|
|
1496
|
+
* Clone the client - returns a new instance
|
|
1497
|
+
*/
|
|
1498
|
+
clone(): ObservableSanityClient
|
|
1499
|
+
/**
|
|
1500
|
+
* Returns the current client configuration
|
|
1501
|
+
*/
|
|
1502
|
+
config(): InitializedClientConfig
|
|
1503
|
+
/**
|
|
1504
|
+
* Reconfigure the client. Note that this _mutates_ the current client.
|
|
1505
|
+
*/
|
|
1506
|
+
config(newConfig?: Partial<ClientConfig>): this
|
|
1507
|
+
/**
|
|
1508
|
+
* Clone the client with a new (partial) configuration.
|
|
1509
|
+
*
|
|
1510
|
+
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1511
|
+
*/
|
|
1512
|
+
withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient
|
|
1513
|
+
/**
|
|
1514
|
+
* Perform a GROQ-query against the configured dataset.
|
|
1515
|
+
*
|
|
1516
|
+
* @param query - GROQ-query to perform
|
|
1517
|
+
*/
|
|
1518
|
+
fetch<
|
|
1519
|
+
R = Any,
|
|
1520
|
+
Q extends QueryWithoutParams = QueryWithoutParams,
|
|
1521
|
+
const G extends string = string,
|
|
1522
|
+
>(query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>
|
|
1523
|
+
/**
|
|
1524
|
+
* Perform a GROQ-query against the configured dataset.
|
|
1525
|
+
*
|
|
1526
|
+
* @param query - GROQ-query to perform
|
|
1527
|
+
* @param params - Optional query parameters
|
|
1528
|
+
* @param options - Optional request options
|
|
1529
|
+
*/
|
|
1530
|
+
fetch<
|
|
1531
|
+
R = Any,
|
|
1532
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
1533
|
+
const G extends string = string,
|
|
1534
|
+
>(
|
|
1535
|
+
query: G,
|
|
1536
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1537
|
+
options?: FilteredResponseQueryOptions,
|
|
1538
|
+
): Observable<ClientReturn<G, R>>
|
|
1539
|
+
/**
|
|
1540
|
+
* Perform a GROQ-query against the configured dataset.
|
|
1541
|
+
*
|
|
1542
|
+
* @param query - GROQ-query to perform
|
|
1543
|
+
* @param params - Optional query parameters
|
|
1544
|
+
* @param options - Request options
|
|
1545
|
+
*/
|
|
1546
|
+
fetch<
|
|
1547
|
+
R = Any,
|
|
1548
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
1549
|
+
const G extends string = string,
|
|
1550
|
+
>(
|
|
1551
|
+
query: string,
|
|
1552
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1553
|
+
options: UnfilteredResponseQueryOptions,
|
|
1554
|
+
): Observable<RawQueryResponse<ClientReturn<G, R>>>
|
|
1555
|
+
/**
|
|
1556
|
+
* Perform a GROQ-query against the configured dataset.
|
|
1557
|
+
*
|
|
1558
|
+
* @param query - GROQ-query to perform
|
|
1559
|
+
* @param params - Optional query parameters
|
|
1560
|
+
* @param options - Request options
|
|
1561
|
+
*/
|
|
1562
|
+
fetch<
|
|
1563
|
+
R = Any,
|
|
1564
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
1565
|
+
const G extends string = string,
|
|
1566
|
+
>(
|
|
1567
|
+
query: G,
|
|
1568
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1569
|
+
options: UnfilteredResponseWithoutQuery,
|
|
1570
|
+
): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
|
|
1571
|
+
/**
|
|
1572
|
+
* Fetch a single document with the given ID.
|
|
1573
|
+
*
|
|
1574
|
+
* @param id - Document ID to fetch
|
|
1575
|
+
* @param options - Request options
|
|
1576
|
+
*/
|
|
1577
|
+
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
1578
|
+
id: string,
|
|
1579
|
+
options?: {
|
|
1580
|
+
tag?: string
|
|
1581
|
+
},
|
|
1582
|
+
): Observable<SanityDocument_2<R> | undefined>
|
|
1583
|
+
/**
|
|
1584
|
+
* Fetch multiple documents in one request.
|
|
1585
|
+
* Should be used sparingly - performing a query is usually a better option.
|
|
1586
|
+
* The order/position of documents is preserved based on the original array of IDs.
|
|
1587
|
+
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
1588
|
+
*
|
|
1589
|
+
* @param ids - Document IDs to fetch
|
|
1590
|
+
* @param options - Request options
|
|
1591
|
+
*/
|
|
1592
|
+
getDocuments<R extends Record<string, Any> = Record<string, Any>>(
|
|
1593
|
+
ids: string[],
|
|
1594
|
+
options?: {
|
|
1595
|
+
tag?: string
|
|
1596
|
+
},
|
|
1597
|
+
): Observable<(SanityDocument_2<R> | null)[]>
|
|
1598
|
+
/**
|
|
1599
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1600
|
+
* Returns an observable that resolves to the created document.
|
|
1601
|
+
*
|
|
1602
|
+
* @param document - Document to create
|
|
1603
|
+
* @param options - Mutation options
|
|
1604
|
+
*/
|
|
1605
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1606
|
+
document: SanityDocumentStub<R>,
|
|
1607
|
+
options: FirstDocumentMutationOptions,
|
|
1608
|
+
): Observable<SanityDocument_2<R>>
|
|
1609
|
+
/**
|
|
1610
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1611
|
+
* Returns an observable that resolves to an array containing the created document.
|
|
1612
|
+
*
|
|
1613
|
+
* @param document - Document to create
|
|
1614
|
+
* @param options - Mutation options
|
|
1615
|
+
*/
|
|
1616
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1617
|
+
document: SanityDocumentStub<R>,
|
|
1618
|
+
options: AllDocumentsMutationOptions,
|
|
1619
|
+
): Observable<SanityDocument_2<R>[]>
|
|
1620
|
+
/**
|
|
1621
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1622
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1623
|
+
*
|
|
1624
|
+
* @param document - Document to create
|
|
1625
|
+
* @param options - Mutation options
|
|
1626
|
+
*/
|
|
1627
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1628
|
+
document: SanityDocumentStub<R>,
|
|
1629
|
+
options: FirstDocumentIdMutationOptions,
|
|
1630
|
+
): Observable<SingleMutationResult>
|
|
1631
|
+
/**
|
|
1632
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1633
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1634
|
+
*
|
|
1635
|
+
* @param document - Document to create
|
|
1636
|
+
* @param options - Mutation options
|
|
1637
|
+
*/
|
|
1638
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1639
|
+
document: SanityDocumentStub<R>,
|
|
1640
|
+
options: AllDocumentIdsMutationOptions,
|
|
1641
|
+
): Observable<MultipleMutationResult>
|
|
1642
|
+
/**
|
|
1643
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1644
|
+
* Returns an observable that resolves to the created document.
|
|
1645
|
+
*
|
|
1646
|
+
* @param document - Document to create
|
|
1647
|
+
* @param options - Mutation options
|
|
1648
|
+
*/
|
|
1649
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1650
|
+
document: SanityDocumentStub<R>,
|
|
1651
|
+
options?: BaseMutationOptions,
|
|
1652
|
+
): Observable<SanityDocument_2<R>>
|
|
1653
|
+
/**
|
|
1654
|
+
* Create a document if no document with the same ID already exists.
|
|
1655
|
+
* Returns an observable that resolves to the created document.
|
|
1656
|
+
*
|
|
1657
|
+
* @param document - Document to create
|
|
1658
|
+
* @param options - Mutation options
|
|
1659
|
+
*/
|
|
1660
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1661
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1662
|
+
options: FirstDocumentMutationOptions,
|
|
1663
|
+
): Observable<SanityDocument_2<R>>
|
|
1664
|
+
/**
|
|
1665
|
+
* Create a document if no document with the same ID already exists.
|
|
1666
|
+
* Returns an observable that resolves to an array containing the created document.
|
|
1667
|
+
*
|
|
1668
|
+
* @param document - Document to create
|
|
1669
|
+
* @param options - Mutation options
|
|
1670
|
+
*/
|
|
1671
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1672
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1673
|
+
options: AllDocumentsMutationOptions,
|
|
1674
|
+
): Observable<SanityDocument_2<R>[]>
|
|
1675
|
+
/**
|
|
1676
|
+
* Create a document if no document with the same ID already exists.
|
|
1677
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1678
|
+
*
|
|
1679
|
+
* @param document - Document to create
|
|
1680
|
+
* @param options - Mutation options
|
|
1681
|
+
*/
|
|
1682
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1683
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1684
|
+
options: FirstDocumentIdMutationOptions,
|
|
1685
|
+
): Observable<SingleMutationResult>
|
|
1686
|
+
/**
|
|
1687
|
+
* Create a document if no document with the same ID already exists.
|
|
1688
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1689
|
+
*
|
|
1690
|
+
* @param document - Document to create
|
|
1691
|
+
* @param options - Mutation options
|
|
1692
|
+
*/
|
|
1693
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1694
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1695
|
+
options: AllDocumentIdsMutationOptions,
|
|
1696
|
+
): Observable<MultipleMutationResult>
|
|
1697
|
+
/**
|
|
1698
|
+
* Create a document if no document with the same ID already exists.
|
|
1699
|
+
* Returns an observable that resolves to the created document.
|
|
1700
|
+
*
|
|
1701
|
+
* @param document - Document to create
|
|
1702
|
+
* @param options - Mutation options
|
|
1703
|
+
*/
|
|
1704
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1705
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1706
|
+
options?: BaseMutationOptions,
|
|
1707
|
+
): Observable<SanityDocument_2<R>>
|
|
1708
|
+
/**
|
|
1709
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1710
|
+
* Returns an observable that resolves to the created document.
|
|
1711
|
+
*
|
|
1712
|
+
* @param document - Document to either create or replace
|
|
1713
|
+
* @param options - Mutation options
|
|
1714
|
+
*/
|
|
1715
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1716
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1717
|
+
options: FirstDocumentMutationOptions,
|
|
1718
|
+
): Observable<SanityDocument_2<R>>
|
|
1719
|
+
/**
|
|
1720
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1721
|
+
* Returns an observable that resolves to an array containing the created document.
|
|
1722
|
+
*
|
|
1723
|
+
* @param document - Document to either create or replace
|
|
1724
|
+
* @param options - Mutation options
|
|
1725
|
+
*/
|
|
1726
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1727
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1728
|
+
options: AllDocumentsMutationOptions,
|
|
1729
|
+
): Observable<SanityDocument_2<R>[]>
|
|
1730
|
+
/**
|
|
1731
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1732
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1733
|
+
*
|
|
1734
|
+
* @param document - Document to either create or replace
|
|
1735
|
+
* @param options - Mutation options
|
|
1736
|
+
*/
|
|
1737
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1738
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1739
|
+
options: FirstDocumentIdMutationOptions,
|
|
1740
|
+
): Observable<SingleMutationResult>
|
|
1741
|
+
/**
|
|
1742
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1743
|
+
* Returns an observable that resolves to a mutation result object containing the created document ID.
|
|
1744
|
+
*
|
|
1745
|
+
* @param document - Document to either create or replace
|
|
1746
|
+
* @param options - Mutation options
|
|
1747
|
+
*/
|
|
1748
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1749
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1750
|
+
options: AllDocumentIdsMutationOptions,
|
|
1751
|
+
): Observable<MultipleMutationResult>
|
|
1752
|
+
/**
|
|
1753
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1754
|
+
* Returns an observable that resolves to the created document.
|
|
1755
|
+
*
|
|
1756
|
+
* @param document - Document to either create or replace
|
|
1757
|
+
* @param options - Mutation options
|
|
1758
|
+
*/
|
|
1759
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1760
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1761
|
+
options?: BaseMutationOptions,
|
|
1762
|
+
): Observable<SanityDocument_2<R>>
|
|
1763
|
+
/**
|
|
1764
|
+
* Deletes a document with the given document ID.
|
|
1765
|
+
* Returns an observable that resolves to the deleted document.
|
|
1766
|
+
*
|
|
1767
|
+
* @param id - Document ID to delete
|
|
1768
|
+
* @param options - Options for the mutation
|
|
1769
|
+
*/
|
|
1770
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1771
|
+
id: string,
|
|
1772
|
+
options: FirstDocumentMutationOptions,
|
|
1773
|
+
): Observable<SanityDocument_2<R>>
|
|
1774
|
+
/**
|
|
1775
|
+
* Deletes a document with the given document ID.
|
|
1776
|
+
* Returns an observable that resolves to an array containing the deleted document.
|
|
1777
|
+
*
|
|
1778
|
+
* @param id - Document ID to delete
|
|
1779
|
+
* @param options - Options for the mutation
|
|
1780
|
+
*/
|
|
1781
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1782
|
+
id: string,
|
|
1783
|
+
options: AllDocumentsMutationOptions,
|
|
1784
|
+
): Observable<SanityDocument_2<R>[]>
|
|
1785
|
+
/**
|
|
1786
|
+
* Deletes a document with the given document ID.
|
|
1787
|
+
* Returns an observable that resolves to a mutation result object containing the deleted document ID.
|
|
1788
|
+
*
|
|
1789
|
+
* @param id - Document ID to delete
|
|
1790
|
+
* @param options - Options for the mutation
|
|
1791
|
+
*/
|
|
1792
|
+
delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
1793
|
+
/**
|
|
1794
|
+
* Deletes a document with the given document ID.
|
|
1795
|
+
* Returns an observable that resolves to a mutation result object containing the deleted document ID.
|
|
1796
|
+
*
|
|
1797
|
+
* @param id - Document ID to delete
|
|
1798
|
+
* @param options - Options for the mutation
|
|
1799
|
+
*/
|
|
1800
|
+
delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
1801
|
+
/**
|
|
1802
|
+
* Deletes a document with the given document ID.
|
|
1803
|
+
* Returns an observable that resolves to the deleted document.
|
|
1804
|
+
*
|
|
1805
|
+
* @param id - Document ID to delete
|
|
1806
|
+
* @param options - Options for the mutation
|
|
1807
|
+
*/
|
|
1808
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1809
|
+
id: string,
|
|
1810
|
+
options?: BaseMutationOptions,
|
|
1811
|
+
): Observable<SanityDocument_2<R>>
|
|
1812
|
+
/**
|
|
1813
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1814
|
+
* Returns an observable that resolves to first deleted document.
|
|
1815
|
+
*
|
|
1816
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1817
|
+
* @param options - Options for the mutation
|
|
1818
|
+
*/
|
|
1819
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1820
|
+
selection: MutationSelection,
|
|
1821
|
+
options: FirstDocumentMutationOptions,
|
|
1822
|
+
): Observable<SanityDocument_2<R>>
|
|
1823
|
+
/**
|
|
1824
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1825
|
+
* Returns an observable that resolves to an array containing the deleted documents.
|
|
1826
|
+
*
|
|
1827
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1828
|
+
* @param options - Options for the mutation
|
|
1829
|
+
*/
|
|
1830
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1831
|
+
selection: MutationSelection,
|
|
1832
|
+
options: AllDocumentsMutationOptions,
|
|
1833
|
+
): Observable<SanityDocument_2<R>[]>
|
|
1834
|
+
/**
|
|
1835
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1836
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
|
|
1837
|
+
*
|
|
1838
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1839
|
+
* @param options - Options for the mutation
|
|
1840
|
+
*/
|
|
1841
|
+
delete(
|
|
1842
|
+
selection: MutationSelection,
|
|
1843
|
+
options: FirstDocumentIdMutationOptions,
|
|
1844
|
+
): Observable<SingleMutationResult>
|
|
1845
|
+
/**
|
|
1846
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1847
|
+
* Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
|
|
1848
|
+
*
|
|
1849
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1850
|
+
* @param options - Options for the mutation
|
|
1851
|
+
*/
|
|
1852
|
+
delete(
|
|
1853
|
+
selection: MutationSelection,
|
|
1854
|
+
options: AllDocumentIdsMutationOptions,
|
|
1855
|
+
): Observable<MultipleMutationResult>
|
|
1856
|
+
/**
|
|
1857
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1858
|
+
* Returns an observable that resolves to first deleted document.
|
|
1859
|
+
*
|
|
1860
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1861
|
+
* @param options - Options for the mutation
|
|
1862
|
+
*/
|
|
1863
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1864
|
+
selection: MutationSelection,
|
|
1865
|
+
options?: BaseMutationOptions,
|
|
1866
|
+
): Observable<SanityDocument_2<R>>
|
|
1867
|
+
/**
|
|
1868
|
+
* Perform mutation operations against the configured dataset
|
|
1869
|
+
* Returns an observable that resolves to the first mutated document.
|
|
1870
|
+
*
|
|
1871
|
+
* @param operations - Mutation operations to execute
|
|
1872
|
+
* @param options - Mutation options
|
|
1873
|
+
*/
|
|
1874
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1875
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1876
|
+
options: FirstDocumentMutationOptions,
|
|
1877
|
+
): Observable<SanityDocument_2<R>>
|
|
1878
|
+
/**
|
|
1879
|
+
* Perform mutation operations against the configured dataset.
|
|
1880
|
+
* Returns an observable that resolves to an array of the mutated documents.
|
|
1881
|
+
*
|
|
1882
|
+
* @param operations - Mutation operations to execute
|
|
1883
|
+
* @param options - Mutation options
|
|
1884
|
+
*/
|
|
1885
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1886
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1887
|
+
options: AllDocumentsMutationOptions,
|
|
1888
|
+
): Observable<SanityDocument_2<R>[]>
|
|
1889
|
+
/**
|
|
1890
|
+
* Perform mutation operations against the configured dataset
|
|
1891
|
+
* Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
|
|
1892
|
+
*
|
|
1893
|
+
* @param operations - Mutation operations to execute
|
|
1894
|
+
* @param options - Mutation options
|
|
1895
|
+
*/
|
|
1896
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1897
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1898
|
+
options: FirstDocumentIdMutationOptions,
|
|
1899
|
+
): Observable<SingleMutationResult>
|
|
1900
|
+
/**
|
|
1901
|
+
* Perform mutation operations against the configured dataset
|
|
1902
|
+
* Returns an observable that resolves to a mutation result object containing the mutated document IDs.
|
|
1903
|
+
*
|
|
1904
|
+
* @param operations - Mutation operations to execute
|
|
1905
|
+
* @param options - Mutation options
|
|
1906
|
+
*/
|
|
1907
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1908
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1909
|
+
options: AllDocumentIdsMutationOptions,
|
|
1910
|
+
): Observable<MultipleMutationResult>
|
|
1911
|
+
/**
|
|
1912
|
+
* Perform mutation operations against the configured dataset
|
|
1913
|
+
* Returns an observable that resolves to the first mutated document.
|
|
1914
|
+
*
|
|
1915
|
+
* @param operations - Mutation operations to execute
|
|
1916
|
+
* @param options - Mutation options
|
|
1917
|
+
*/
|
|
1918
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1919
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1920
|
+
options?: BaseMutationOptions,
|
|
1921
|
+
): Observable<SanityDocument_2<R>>
|
|
1922
|
+
/**
|
|
1923
|
+
* Create a new buildable patch of operations to perform
|
|
1924
|
+
*
|
|
1925
|
+
* @param documentId - Document ID to patch
|
|
1926
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1927
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1928
|
+
*/
|
|
1929
|
+
patch(documentId: string, operations?: PatchOperations): ObservablePatch
|
|
1930
|
+
/**
|
|
1931
|
+
* Create a new buildable patch of operations to perform
|
|
1932
|
+
*
|
|
1933
|
+
* @param documentIds - Array of document IDs to patch
|
|
1934
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1935
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1936
|
+
*/
|
|
1937
|
+
patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
|
|
1938
|
+
/**
|
|
1939
|
+
* Create a new buildable patch of operations to perform
|
|
1940
|
+
*
|
|
1941
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
1942
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1943
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1944
|
+
*/
|
|
1945
|
+
patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
|
|
1946
|
+
/**
|
|
1947
|
+
* Create a new transaction of mutations
|
|
1948
|
+
*
|
|
1949
|
+
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
1950
|
+
*/
|
|
1951
|
+
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
1952
|
+
operations?: Mutation<R>[],
|
|
1953
|
+
): ObservableTransaction
|
|
1954
|
+
/**
|
|
1955
|
+
* Perform action operations against the configured dataset
|
|
1956
|
+
*
|
|
1957
|
+
* @param operations - Action operation(s) to execute
|
|
1958
|
+
* @param options - Action options
|
|
1959
|
+
*/
|
|
1960
|
+
action(
|
|
1961
|
+
operations: Action | Action[],
|
|
1962
|
+
options?: BaseActionOptions,
|
|
1963
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
1964
|
+
/**
|
|
1965
|
+
* Perform an HTTP request against the Sanity API
|
|
1966
|
+
*
|
|
1967
|
+
* @param options - Request options
|
|
1968
|
+
*/
|
|
1969
|
+
request<R = Any>(options: RawRequestOptions): Observable<R>
|
|
1970
|
+
/**
|
|
1971
|
+
* Get a Sanity API URL for the URI provided
|
|
1972
|
+
*
|
|
1973
|
+
* @param uri - URI/path to build URL for
|
|
1974
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1975
|
+
*/
|
|
1976
|
+
getUrl(uri: string, canUseCdn?: boolean): string
|
|
1977
|
+
/**
|
|
1978
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1979
|
+
*
|
|
1980
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1981
|
+
* @param path - Path to append after the operation
|
|
1982
|
+
*/
|
|
1983
|
+
getDataUrl(operation: string, path?: string): string
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
/** @public */
|
|
1987
|
+
declare class ObservableTransaction extends BaseTransaction {
|
|
1988
|
+
#private
|
|
1989
|
+
constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
|
|
1990
|
+
/**
|
|
1991
|
+
* Clones the transaction
|
|
1992
|
+
*/
|
|
1993
|
+
clone(): ObservableTransaction
|
|
1994
|
+
/**
|
|
1995
|
+
* Commit the transaction, returning an observable that produces the first mutated document
|
|
1996
|
+
*
|
|
1997
|
+
* @param options - Options for the mutation operation
|
|
1998
|
+
*/
|
|
1999
|
+
commit<R extends Record<string, Any>>(
|
|
2000
|
+
options: TransactionFirstDocumentMutationOptions,
|
|
2001
|
+
): Observable<SanityDocument_2<R>>
|
|
2002
|
+
/**
|
|
2003
|
+
* Commit the transaction, returning an observable that produces an array of the mutated documents
|
|
2004
|
+
*
|
|
2005
|
+
* @param options - Options for the mutation operation
|
|
2006
|
+
*/
|
|
2007
|
+
commit<R extends Record<string, Any>>(
|
|
2008
|
+
options: TransactionAllDocumentsMutationOptions,
|
|
2009
|
+
): Observable<SanityDocument_2<R>[]>
|
|
2010
|
+
/**
|
|
2011
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
2012
|
+
*
|
|
2013
|
+
* @param options - Options for the mutation operation
|
|
2014
|
+
*/
|
|
2015
|
+
commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
2016
|
+
/**
|
|
2017
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
2018
|
+
*
|
|
2019
|
+
* @param options - Options for the mutation operation
|
|
2020
|
+
*/
|
|
2021
|
+
commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
2022
|
+
/**
|
|
2023
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
2024
|
+
*
|
|
2025
|
+
* @param options - Options for the mutation operation
|
|
2026
|
+
*/
|
|
2027
|
+
commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
|
|
2028
|
+
/**
|
|
2029
|
+
* Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
|
|
2030
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
2031
|
+
*
|
|
2032
|
+
* @param documentId - Document ID to perform the patch operation on
|
|
2033
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
2034
|
+
*/
|
|
2035
|
+
patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
|
|
2036
|
+
/**
|
|
2037
|
+
* Adds the given patch instance to the transaction.
|
|
2038
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
2039
|
+
*
|
|
2040
|
+
* @param patch - ObservablePatch to execute
|
|
2041
|
+
*/
|
|
2042
|
+
patch(patch: ObservablePatch): this
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
/** @public */
|
|
2046
|
+
declare class ObservableUsersClient {
|
|
2047
|
+
#private
|
|
2048
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
2049
|
+
/**
|
|
2050
|
+
* Fetch a user by user ID
|
|
2051
|
+
*
|
|
2052
|
+
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
2053
|
+
*/
|
|
2054
|
+
getById<T extends 'me' | string>(
|
|
2055
|
+
id: T,
|
|
2056
|
+
): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
/**
|
|
2060
|
+
* The listener connection has been established
|
|
2061
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
2062
|
+
* @public
|
|
2063
|
+
*/
|
|
2064
|
+
declare type OpenEvent = {
|
|
2065
|
+
type: 'open'
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
/**
|
|
2069
|
+
* Configuration options for the usePaginatedDocuments hook
|
|
2070
|
+
*
|
|
2071
|
+
* @beta
|
|
2072
|
+
* @category Types
|
|
2073
|
+
*/
|
|
2074
|
+
export declare interface PaginatedDocumentsOptions extends QueryOptions {
|
|
2075
|
+
/**
|
|
2076
|
+
* GROQ filter expression to apply to the query
|
|
2077
|
+
*/
|
|
2078
|
+
filter?: string
|
|
2079
|
+
/**
|
|
2080
|
+
* Number of items to display per page (defaults to 25)
|
|
2081
|
+
*/
|
|
2082
|
+
pageSize?: number
|
|
2083
|
+
/**
|
|
2084
|
+
* Sorting configuration for the results
|
|
2085
|
+
*/
|
|
2086
|
+
orderings?: SortOrderingItem[]
|
|
2087
|
+
/**
|
|
2088
|
+
* Text search query to filter results
|
|
2089
|
+
*/
|
|
2090
|
+
search?: string
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
/**
|
|
2094
|
+
* Return value from the usePaginatedDocuments hook
|
|
2095
|
+
*
|
|
2096
|
+
* @beta
|
|
2097
|
+
* @category Types
|
|
2098
|
+
*/
|
|
2099
|
+
export declare interface PaginatedDocumentsResponse {
|
|
2100
|
+
/**
|
|
2101
|
+
* Array of document handles for the current page
|
|
2102
|
+
*/
|
|
2103
|
+
data: DocumentHandle[]
|
|
2104
|
+
/**
|
|
2105
|
+
* Whether a query is currently in progress
|
|
2106
|
+
*/
|
|
2107
|
+
isPending: boolean
|
|
2108
|
+
/**
|
|
2109
|
+
* Number of items displayed per page
|
|
2110
|
+
*/
|
|
2111
|
+
pageSize: number
|
|
2112
|
+
/**
|
|
2113
|
+
* Current page number (1-indexed)
|
|
2114
|
+
*/
|
|
2115
|
+
currentPage: number
|
|
2116
|
+
/**
|
|
2117
|
+
* Total number of pages available
|
|
2118
|
+
*/
|
|
2119
|
+
totalPages: number
|
|
2120
|
+
/**
|
|
2121
|
+
* Starting index of the current page (0-indexed)
|
|
2122
|
+
*/
|
|
2123
|
+
startIndex: number
|
|
2124
|
+
/**
|
|
2125
|
+
* Ending index of the current page (exclusive, 0-indexed)
|
|
2126
|
+
*/
|
|
2127
|
+
endIndex: number
|
|
2128
|
+
/**
|
|
2129
|
+
* Total count of items matching the query
|
|
2130
|
+
*/
|
|
2131
|
+
count: number
|
|
2132
|
+
/**
|
|
2133
|
+
* Navigate to the first page
|
|
2134
|
+
*/
|
|
2135
|
+
firstPage: () => void
|
|
2136
|
+
/**
|
|
2137
|
+
* Whether there is a first page available to navigate to
|
|
2138
|
+
*/
|
|
2139
|
+
hasFirstPage: boolean
|
|
2140
|
+
/**
|
|
2141
|
+
* Navigate to the previous page
|
|
2142
|
+
*/
|
|
2143
|
+
previousPage: () => void
|
|
2144
|
+
/**
|
|
2145
|
+
* Whether there is a previous page available to navigate to
|
|
2146
|
+
*/
|
|
2147
|
+
hasPreviousPage: boolean
|
|
2148
|
+
/**
|
|
2149
|
+
* Navigate to the next page
|
|
2150
|
+
*/
|
|
2151
|
+
nextPage: () => void
|
|
2152
|
+
/**
|
|
2153
|
+
* Whether there is a next page available to navigate to
|
|
2154
|
+
*/
|
|
2155
|
+
hasNextPage: boolean
|
|
2156
|
+
/**
|
|
2157
|
+
* Navigate to the last page
|
|
2158
|
+
*/
|
|
2159
|
+
lastPage: () => void
|
|
2160
|
+
/**
|
|
2161
|
+
* Whether there is a last page available to navigate to
|
|
2162
|
+
*/
|
|
2163
|
+
hasLastPage: boolean
|
|
2164
|
+
/**
|
|
2165
|
+
* Navigate to a specific page number
|
|
2166
|
+
* @param pageNumber - The page number to navigate to (1-indexed)
|
|
2167
|
+
*/
|
|
2168
|
+
goToPage: (pageNumber: number) => void
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
/** @public */
|
|
2172
|
+
declare class Patch extends BasePatch {
|
|
2173
|
+
#private
|
|
2174
|
+
constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
|
|
2175
|
+
/**
|
|
2176
|
+
* Clones the patch
|
|
2177
|
+
*/
|
|
2178
|
+
clone(): Patch
|
|
2179
|
+
/**
|
|
2180
|
+
* Commit the patch, returning a promise that resolves to the first patched document
|
|
2181
|
+
*
|
|
2182
|
+
* @param options - Options for the mutation operation
|
|
2183
|
+
*/
|
|
2184
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
2185
|
+
options: FirstDocumentMutationOptions,
|
|
2186
|
+
): Promise<SanityDocument_2<R>>
|
|
2187
|
+
/**
|
|
2188
|
+
* Commit the patch, returning a promise that resolves to an array of the mutated documents
|
|
2189
|
+
*
|
|
2190
|
+
* @param options - Options for the mutation operation
|
|
2191
|
+
*/
|
|
2192
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
2193
|
+
options: AllDocumentsMutationOptions,
|
|
2194
|
+
): Promise<SanityDocument_2<R>[]>
|
|
2195
|
+
/**
|
|
2196
|
+
* Commit the patch, returning a promise that resolves to a mutation result object
|
|
2197
|
+
*
|
|
2198
|
+
* @param options - Options for the mutation operation
|
|
2199
|
+
*/
|
|
2200
|
+
commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
|
|
2201
|
+
/**
|
|
2202
|
+
* Commit the patch, returning a promise that resolves to a mutation result object
|
|
2203
|
+
*
|
|
2204
|
+
* @param options - Options for the mutation operation
|
|
2205
|
+
*/
|
|
2206
|
+
commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
|
|
2207
|
+
/**
|
|
2208
|
+
* Commit the patch, returning a promise that resolves to the first patched document
|
|
2209
|
+
*
|
|
2210
|
+
* @param options - Options for the mutation operation
|
|
2211
|
+
*/
|
|
2212
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
2213
|
+
options?: BaseMutationOptions,
|
|
2214
|
+
): Promise<SanityDocument_2<R>>
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
/** @public */
|
|
2218
|
+
declare type PatchBuilder = (patch: Patch) => Patch
|
|
2219
|
+
|
|
2220
|
+
/** @internal */
|
|
2221
|
+
declare type PatchMutationOperation = PatchOperations & MutationSelection
|
|
2222
|
+
|
|
2223
|
+
/** @internal */
|
|
2224
|
+
declare interface PatchOperations {
|
|
2225
|
+
set?: {
|
|
2226
|
+
[key: string]: Any
|
|
2227
|
+
}
|
|
2228
|
+
setIfMissing?: {
|
|
2229
|
+
[key: string]: Any
|
|
2230
|
+
}
|
|
2231
|
+
diffMatchPatch?: {
|
|
2232
|
+
[key: string]: Any
|
|
2233
|
+
}
|
|
2234
|
+
unset?: string[]
|
|
2235
|
+
inc?: {
|
|
2236
|
+
[key: string]: number
|
|
2237
|
+
}
|
|
2238
|
+
dec?: {
|
|
2239
|
+
[key: string]: number
|
|
2240
|
+
}
|
|
2241
|
+
insert?: InsertPatch
|
|
2242
|
+
ifRevisionID?: string
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
/** @internal */
|
|
2246
|
+
declare type PatchSelection = string | string[] | MutationSelection
|
|
2247
|
+
|
|
2248
|
+
/** @public */
|
|
2249
|
+
declare interface ProgressEvent_2 {
|
|
2250
|
+
type: 'progress'
|
|
2251
|
+
stage: 'upload' | 'download'
|
|
2252
|
+
percent: number
|
|
2253
|
+
total?: number
|
|
2254
|
+
loaded?: number
|
|
2255
|
+
lengthComputable: boolean
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
/** @internal */
|
|
2259
|
+
declare class ProjectsClient {
|
|
2260
|
+
#private
|
|
2261
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
2262
|
+
/**
|
|
2263
|
+
* Fetch a list of projects the authenticated user has access to.
|
|
2264
|
+
*
|
|
2265
|
+
* @param options - Options for the list request
|
|
2266
|
+
* @param options.includeMembers - Whether to include members in the response (default: true)
|
|
2267
|
+
*/
|
|
2268
|
+
list(options?: {includeMembers?: true}): Promise<SanityProject[]>
|
|
2269
|
+
list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
|
|
2270
|
+
/**
|
|
2271
|
+
* Fetch a project by project ID
|
|
2272
|
+
*
|
|
2273
|
+
* @param projectId - ID of the project to fetch
|
|
2274
|
+
*/
|
|
2275
|
+
getById(projectId: string): Promise<SanityProject>
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
/**
|
|
2279
|
+
* @public
|
|
2280
|
+
* @category Types
|
|
2281
|
+
* @interface
|
|
2282
|
+
*/
|
|
2283
|
+
export declare type ProjectWithoutMembers = Omit<SanityProject, 'members'>
|
|
2284
|
+
|
|
2285
|
+
/**
|
|
2286
|
+
* Publishes a draft document.
|
|
2287
|
+
* If a published version of the document already exists this is replaced by the current draft document.
|
|
2288
|
+
* In either case the draft document is deleted.
|
|
2289
|
+
* The optional revision id parameters can be used for optimistic locking to ensure
|
|
2290
|
+
* that the draft and/or published versions of the document have not been changed by another client.
|
|
2291
|
+
*
|
|
2292
|
+
* @public
|
|
2293
|
+
*/
|
|
2294
|
+
declare type PublishAction = {
|
|
2295
|
+
actionType: 'sanity.action.document.publish'
|
|
2296
|
+
/**
|
|
2297
|
+
* Draft document ID to publish
|
|
2298
|
+
*/
|
|
2299
|
+
draftId: string
|
|
2300
|
+
/**
|
|
2301
|
+
* Draft revision ID to match
|
|
2302
|
+
*/
|
|
2303
|
+
ifDraftRevisionId?: string
|
|
2304
|
+
/**
|
|
2305
|
+
* Published document ID to replace
|
|
2306
|
+
*/
|
|
2307
|
+
publishedId: string
|
|
2308
|
+
/**
|
|
2309
|
+
* Published revision ID to match
|
|
2310
|
+
*/
|
|
2311
|
+
ifPublishedRevisionId?: string
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/** @public */
|
|
2315
|
+
declare interface QueryParams {
|
|
2316
|
+
[key: string]: any
|
|
2317
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2318
|
+
body?: never
|
|
2319
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2320
|
+
cache?: 'next' extends keyof RequestInit ? never : any
|
|
2321
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2322
|
+
filterResponse?: never
|
|
2323
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2324
|
+
headers?: never
|
|
2325
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2326
|
+
method?: never
|
|
2327
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2328
|
+
next?: 'next' extends keyof RequestInit ? never : any
|
|
2329
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2330
|
+
perspective?: never
|
|
2331
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2332
|
+
query?: never
|
|
2333
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2334
|
+
resultSourceMap?: never
|
|
2335
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2336
|
+
returnQuery?: never
|
|
2337
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2338
|
+
signal?: never
|
|
2339
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2340
|
+
stega?: never
|
|
2341
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2342
|
+
tag?: never
|
|
2343
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2344
|
+
timeout?: never
|
|
2345
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2346
|
+
token?: never
|
|
2347
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2348
|
+
useCdn?: never
|
|
2349
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2350
|
+
lastLiveEventId?: never
|
|
2351
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2352
|
+
cacheMode?: never
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
/**
|
|
2356
|
+
* This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
|
|
2357
|
+
* @public
|
|
2358
|
+
*/
|
|
2359
|
+
declare type QueryWithoutParams = Record<string, never> | undefined
|
|
2360
|
+
|
|
2361
|
+
/** @public */
|
|
2362
|
+
declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
|
|
2363
|
+
|
|
2364
|
+
/** @public */
|
|
2365
|
+
declare interface RawQueryResponse<R> {
|
|
2366
|
+
query: string
|
|
2367
|
+
ms: number
|
|
2368
|
+
result: R
|
|
2369
|
+
resultSourceMap?: ContentSourceMap
|
|
2370
|
+
/** Requires `apiVersion` to be `2021-03-25` or later. */
|
|
2371
|
+
syncTags?: SyncTag[]
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
/** @internal */
|
|
2375
|
+
declare interface RawRequestOptions {
|
|
2376
|
+
url?: string
|
|
2377
|
+
uri?: string
|
|
2378
|
+
method?: string
|
|
2379
|
+
token?: string
|
|
2380
|
+
json?: boolean
|
|
2381
|
+
tag?: string
|
|
2382
|
+
useGlobalApi?: boolean
|
|
2383
|
+
withCredentials?: boolean
|
|
2384
|
+
query?: {
|
|
2385
|
+
[key: string]: string | string[]
|
|
2386
|
+
}
|
|
2387
|
+
headers?: {
|
|
2388
|
+
[key: string]: string
|
|
2389
|
+
}
|
|
2390
|
+
timeout?: number
|
|
2391
|
+
proxy?: string
|
|
2392
|
+
body?: Any
|
|
2393
|
+
maxRedirects?: number
|
|
2394
|
+
signal?: AbortSignal
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
/**
|
|
2398
|
+
* This version is provided by pkg-utils at build time
|
|
2399
|
+
* @internal
|
|
2400
|
+
*/
|
|
2401
|
+
export declare const REACT_SDK_VERSION: {}
|
|
2402
|
+
|
|
2403
|
+
/**
|
|
2404
|
+
* The listener has been disconnected, and a reconnect attempt is scheduled.
|
|
2405
|
+
*
|
|
2406
|
+
* @public
|
|
2407
|
+
*/
|
|
2408
|
+
declare type ReconnectEvent = {
|
|
2409
|
+
type: 'reconnect'
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
/**
|
|
2413
|
+
* Replaces an existing draft document.
|
|
2414
|
+
* At least one of the draft or published versions of the document must exist.
|
|
2415
|
+
*
|
|
2416
|
+
* @public
|
|
2417
|
+
*/
|
|
2418
|
+
declare type ReplaceDraftAction = {
|
|
2419
|
+
actionType: 'sanity.action.document.replaceDraft'
|
|
2420
|
+
/**
|
|
2421
|
+
* Published document ID to create draft from, if draft does not exist
|
|
2422
|
+
*/
|
|
2423
|
+
publishedId: string
|
|
2424
|
+
/**
|
|
2425
|
+
* Document to create if it does not already exist. Requires `_id` and `_type` properties.
|
|
2426
|
+
*/
|
|
2427
|
+
attributes: IdentifiedSanityDocumentStub
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
/** @public */
|
|
2431
|
+
declare interface RequestOptions {
|
|
2432
|
+
timeout?: number
|
|
2433
|
+
token?: string
|
|
2434
|
+
tag?: string
|
|
2435
|
+
headers?: Record<string, string>
|
|
2436
|
+
method?: string
|
|
2437
|
+
query?: Any
|
|
2438
|
+
body?: Any
|
|
2439
|
+
signal?: AbortSignal
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
/** @alpha */
|
|
2443
|
+
declare type ResolveStudioUrl = (sourceDocument: ContentSourceMapDocuments[number]) => StudioUrl
|
|
2444
|
+
|
|
2445
|
+
/** @public */
|
|
2446
|
+
declare interface ResponseEvent<T = unknown> {
|
|
2447
|
+
type: 'response'
|
|
2448
|
+
body: T
|
|
2449
|
+
url: string
|
|
2450
|
+
method: string
|
|
2451
|
+
statusCode: number
|
|
2452
|
+
statusMessage?: string
|
|
2453
|
+
headers: Record<string, string>
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
/** @public */
|
|
2457
|
+
declare interface ResponseQueryOptions extends RequestOptions {
|
|
2458
|
+
perspective?: ClientPerspective
|
|
2459
|
+
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2460
|
+
returnQuery?: boolean
|
|
2461
|
+
useCdn?: boolean
|
|
2462
|
+
stega?: boolean | StegaConfig
|
|
2463
|
+
cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
|
|
2464
|
+
next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
|
|
2465
|
+
lastLiveEventId?: string | string[] | null
|
|
2466
|
+
/**
|
|
2467
|
+
* When set to `noStale`, APICDN will not return a cached response if the content is stale.
|
|
2468
|
+
* Tradeoff between latency and freshness of content.
|
|
2469
|
+
*
|
|
2470
|
+
* Only to be used with live content queries and when useCdn is true.
|
|
2471
|
+
*/
|
|
2472
|
+
cacheMode?: 'noStale'
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
/**
|
|
2476
|
+
* @public
|
|
2477
|
+
*
|
|
2478
|
+
* The SanityApp component provides your Sanity application with access to your Sanity configuration,
|
|
2479
|
+
* as well as application context and state which is used by the Sanity React hooks. Your application
|
|
2480
|
+
* must be wrapped with the SanityApp component to function properly.
|
|
2481
|
+
*
|
|
2482
|
+
* @param props - Your Sanity configuration and the React children to render
|
|
2483
|
+
* @returns Your Sanity application, integrated with your Sanity configuration and application context
|
|
2484
|
+
*
|
|
2485
|
+
* @example
|
|
2486
|
+
* ```tsx
|
|
2487
|
+
* import { SanityApp } from '@sanity/sdk-react'
|
|
2488
|
+
*
|
|
2489
|
+
* import MyAppRoot from './Root'
|
|
2490
|
+
*
|
|
2491
|
+
* // Single project configuration
|
|
2492
|
+
* const mySanityConfigs = [
|
|
2493
|
+
* {
|
|
2494
|
+
* projectId: 'my-project-id',
|
|
2495
|
+
* dataset: 'production',
|
|
2496
|
+
* },
|
|
2497
|
+
* ]
|
|
2498
|
+
*
|
|
2499
|
+
* // Or multiple project configurations
|
|
2500
|
+
* const multipleConfigs = [
|
|
2501
|
+
* // Configuration for your main project. This will be used as the default project for all hooks if no resource ID override is provided.
|
|
2502
|
+
* {
|
|
2503
|
+
* projectId: 'marketing-website-project',
|
|
2504
|
+
* dataset: 'production',
|
|
2505
|
+
* },
|
|
2506
|
+
* // Configuration for a separate blog project
|
|
2507
|
+
* {
|
|
2508
|
+
* projectId: 'blog-project',
|
|
2509
|
+
* dataset: 'production',
|
|
2510
|
+
* },
|
|
2511
|
+
* // Configuration for a separate ecommerce project
|
|
2512
|
+
* {
|
|
2513
|
+
* projectId: 'ecommerce-project',
|
|
2514
|
+
* dataset: 'production',
|
|
2515
|
+
* }
|
|
2516
|
+
* ]
|
|
2517
|
+
*
|
|
2518
|
+
* export default function MyApp() {
|
|
2519
|
+
* return (
|
|
2520
|
+
* <SanityApp sanityConfigs={mySanityConfigs}>
|
|
2521
|
+
* <MyAppRoot />
|
|
2522
|
+
* </SanityApp>
|
|
2523
|
+
* )
|
|
2524
|
+
* }
|
|
2525
|
+
* ```
|
|
2526
|
+
*/
|
|
2527
|
+
export declare function SanityApp({sanityConfigs, children, fallback}: SanityAppProps): ReactElement
|
|
2528
|
+
|
|
2529
|
+
/**
|
|
2530
|
+
* @public
|
|
2531
|
+
*/
|
|
2532
|
+
export declare interface SanityAppProps {
|
|
2533
|
+
sanityConfigs: SanityConfig[]
|
|
2534
|
+
children: React.ReactNode
|
|
2535
|
+
fallback: React.ReactNode
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
/** @internal */
|
|
2539
|
+
declare interface SanityAssetDocument extends SanityDocument_2 {
|
|
2540
|
+
url: string
|
|
2541
|
+
path: string
|
|
2542
|
+
size: number
|
|
2543
|
+
assetId: string
|
|
2544
|
+
mimeType: string
|
|
2545
|
+
sha1hash: string
|
|
2546
|
+
extension: string
|
|
2547
|
+
uploadId?: string
|
|
2548
|
+
originalFilename?: string
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
/** @public */
|
|
2552
|
+
declare class SanityClient {
|
|
2553
|
+
#private
|
|
2554
|
+
assets: AssetsClient
|
|
2555
|
+
datasets: DatasetsClient
|
|
2556
|
+
live: LiveClient
|
|
2557
|
+
projects: ProjectsClient
|
|
2558
|
+
users: UsersClient
|
|
2559
|
+
/**
|
|
2560
|
+
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2561
|
+
*/
|
|
2562
|
+
observable: ObservableSanityClient
|
|
2563
|
+
/**
|
|
2564
|
+
* Instance properties
|
|
2565
|
+
*/
|
|
2566
|
+
listen: typeof _listen
|
|
2567
|
+
constructor(httpRequest: HttpRequest, config?: ClientConfig)
|
|
2568
|
+
/**
|
|
2569
|
+
* Clone the client - returns a new instance
|
|
2570
|
+
*/
|
|
2571
|
+
clone(): SanityClient
|
|
2572
|
+
/**
|
|
2573
|
+
* Returns the current client configuration
|
|
2574
|
+
*/
|
|
2575
|
+
config(): InitializedClientConfig
|
|
2576
|
+
/**
|
|
2577
|
+
* Reconfigure the client. Note that this _mutates_ the current client.
|
|
2578
|
+
*/
|
|
2579
|
+
config(newConfig?: Partial<ClientConfig>): this
|
|
2580
|
+
/**
|
|
2581
|
+
* Clone the client with a new (partial) configuration.
|
|
2582
|
+
*
|
|
2583
|
+
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
2584
|
+
*/
|
|
2585
|
+
withConfig(newConfig?: Partial<ClientConfig>): SanityClient
|
|
2586
|
+
/**
|
|
2587
|
+
* Perform a GROQ-query against the configured dataset.
|
|
2588
|
+
*
|
|
2589
|
+
* @param query - GROQ-query to perform
|
|
2590
|
+
*/
|
|
2591
|
+
fetch<
|
|
2592
|
+
R = Any,
|
|
2593
|
+
Q extends QueryWithoutParams = QueryWithoutParams,
|
|
2594
|
+
const G extends string = string,
|
|
2595
|
+
>(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
|
|
2596
|
+
/**
|
|
2597
|
+
* Perform a GROQ-query against the configured dataset.
|
|
2598
|
+
*
|
|
2599
|
+
* @param query - GROQ-query to perform
|
|
2600
|
+
* @param params - Optional query parameters
|
|
2601
|
+
* @param options - Optional request options
|
|
2602
|
+
*/
|
|
2603
|
+
fetch<
|
|
2604
|
+
R = Any,
|
|
2605
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
2606
|
+
const G extends string = string,
|
|
2607
|
+
>(
|
|
2608
|
+
query: G,
|
|
2609
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2610
|
+
options?: FilteredResponseQueryOptions,
|
|
2611
|
+
): Promise<ClientReturn<G, R>>
|
|
2612
|
+
/**
|
|
2613
|
+
* Perform a GROQ-query against the configured dataset.
|
|
2614
|
+
*
|
|
2615
|
+
* @param query - GROQ-query to perform
|
|
2616
|
+
* @param params - Optional query parameters
|
|
2617
|
+
* @param options - Request options
|
|
2618
|
+
*/
|
|
2619
|
+
fetch<
|
|
2620
|
+
R = Any,
|
|
2621
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
2622
|
+
const G extends string = string,
|
|
2623
|
+
>(
|
|
2624
|
+
query: G,
|
|
2625
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2626
|
+
options: UnfilteredResponseQueryOptions,
|
|
2627
|
+
): Promise<RawQueryResponse<ClientReturn<G, R>>>
|
|
2628
|
+
/**
|
|
2629
|
+
* Perform a GROQ-query against the configured dataset.
|
|
2630
|
+
*
|
|
2631
|
+
* @param query - GROQ-query to perform
|
|
2632
|
+
* @param params - Optional query parameters
|
|
2633
|
+
* @param options - Request options
|
|
2634
|
+
*/
|
|
2635
|
+
fetch<
|
|
2636
|
+
R = Any,
|
|
2637
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
2638
|
+
const G extends string = string,
|
|
2639
|
+
>(
|
|
2640
|
+
query: G,
|
|
2641
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2642
|
+
options: UnfilteredResponseWithoutQuery,
|
|
2643
|
+
): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
|
|
2644
|
+
/**
|
|
2645
|
+
* Fetch a single document with the given ID.
|
|
2646
|
+
*
|
|
2647
|
+
* @param id - Document ID to fetch
|
|
2648
|
+
* @param options - Request options
|
|
2649
|
+
*/
|
|
2650
|
+
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
2651
|
+
id: string,
|
|
2652
|
+
options?: {
|
|
2653
|
+
signal?: AbortSignal
|
|
2654
|
+
tag?: string
|
|
2655
|
+
},
|
|
2656
|
+
): Promise<SanityDocument_2<R> | undefined>
|
|
2657
|
+
/**
|
|
2658
|
+
* Fetch multiple documents in one request.
|
|
2659
|
+
* Should be used sparingly - performing a query is usually a better option.
|
|
2660
|
+
* The order/position of documents is preserved based on the original array of IDs.
|
|
2661
|
+
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
2662
|
+
*
|
|
2663
|
+
* @param ids - Document IDs to fetch
|
|
2664
|
+
* @param options - Request options
|
|
2665
|
+
*/
|
|
2666
|
+
getDocuments<R extends Record<string, Any> = Record<string, Any>>(
|
|
2667
|
+
ids: string[],
|
|
2668
|
+
options?: {
|
|
2669
|
+
signal?: AbortSignal
|
|
2670
|
+
tag?: string
|
|
2671
|
+
},
|
|
2672
|
+
): Promise<(SanityDocument_2<R> | null)[]>
|
|
2673
|
+
/**
|
|
2674
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2675
|
+
* Returns a promise that resolves to the created document.
|
|
2676
|
+
*
|
|
2677
|
+
* @param document - Document to create
|
|
2678
|
+
* @param options - Mutation options
|
|
2679
|
+
*/
|
|
2680
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2681
|
+
document: SanityDocumentStub<R>,
|
|
2682
|
+
options: FirstDocumentMutationOptions,
|
|
2683
|
+
): Promise<SanityDocument_2<R>>
|
|
2684
|
+
/**
|
|
2685
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2686
|
+
* Returns a promise that resolves to an array containing the created document.
|
|
2687
|
+
*
|
|
2688
|
+
* @param document - Document to create
|
|
2689
|
+
* @param options - Mutation options
|
|
2690
|
+
*/
|
|
2691
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2692
|
+
document: SanityDocumentStub<R>,
|
|
2693
|
+
options: AllDocumentsMutationOptions,
|
|
2694
|
+
): Promise<SanityDocument_2<R>[]>
|
|
2695
|
+
/**
|
|
2696
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2697
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2698
|
+
*
|
|
2699
|
+
* @param document - Document to create
|
|
2700
|
+
* @param options - Mutation options
|
|
2701
|
+
*/
|
|
2702
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2703
|
+
document: SanityDocumentStub<R>,
|
|
2704
|
+
options: FirstDocumentIdMutationOptions,
|
|
2705
|
+
): Promise<SingleMutationResult>
|
|
2706
|
+
/**
|
|
2707
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2708
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2709
|
+
*
|
|
2710
|
+
* @param document - Document to create
|
|
2711
|
+
* @param options - Mutation options
|
|
2712
|
+
*/
|
|
2713
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2714
|
+
document: SanityDocumentStub<R>,
|
|
2715
|
+
options: AllDocumentIdsMutationOptions,
|
|
2716
|
+
): Promise<MultipleMutationResult>
|
|
2717
|
+
/**
|
|
2718
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2719
|
+
* Returns a promise that resolves to the created document.
|
|
2720
|
+
*
|
|
2721
|
+
* @param document - Document to create
|
|
2722
|
+
* @param options - Mutation options
|
|
2723
|
+
*/
|
|
2724
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2725
|
+
document: SanityDocumentStub<R>,
|
|
2726
|
+
options?: BaseMutationOptions,
|
|
2727
|
+
): Promise<SanityDocument_2<R>>
|
|
2728
|
+
/**
|
|
2729
|
+
* Create a document if no document with the same ID already exists.
|
|
2730
|
+
* Returns a promise that resolves to the created document.
|
|
2731
|
+
*
|
|
2732
|
+
* @param document - Document to create
|
|
2733
|
+
* @param options - Mutation options
|
|
2734
|
+
*/
|
|
2735
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2736
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2737
|
+
options: FirstDocumentMutationOptions,
|
|
2738
|
+
): Promise<SanityDocument_2<R>>
|
|
2739
|
+
/**
|
|
2740
|
+
* Create a document if no document with the same ID already exists.
|
|
2741
|
+
* Returns a promise that resolves to an array containing the created document.
|
|
2742
|
+
*
|
|
2743
|
+
* @param document - Document to create
|
|
2744
|
+
* @param options - Mutation options
|
|
2745
|
+
*/
|
|
2746
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2747
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2748
|
+
options: AllDocumentsMutationOptions,
|
|
2749
|
+
): Promise<SanityDocument_2<R>[]>
|
|
2750
|
+
/**
|
|
2751
|
+
* Create a document if no document with the same ID already exists.
|
|
2752
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2753
|
+
*
|
|
2754
|
+
* @param document - Document to create
|
|
2755
|
+
* @param options - Mutation options
|
|
2756
|
+
*/
|
|
2757
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2758
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2759
|
+
options: FirstDocumentIdMutationOptions,
|
|
2760
|
+
): Promise<SingleMutationResult>
|
|
2761
|
+
/**
|
|
2762
|
+
* Create a document if no document with the same ID already exists.
|
|
2763
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2764
|
+
*
|
|
2765
|
+
* @param document - Document to create
|
|
2766
|
+
* @param options - Mutation options
|
|
2767
|
+
*/
|
|
2768
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2769
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2770
|
+
options: AllDocumentIdsMutationOptions,
|
|
2771
|
+
): Promise<MultipleMutationResult>
|
|
2772
|
+
/**
|
|
2773
|
+
* Create a document if no document with the same ID already exists.
|
|
2774
|
+
* Returns a promise that resolves to the created document.
|
|
2775
|
+
*
|
|
2776
|
+
* @param document - Document to create
|
|
2777
|
+
* @param options - Mutation options
|
|
2778
|
+
*/
|
|
2779
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2780
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2781
|
+
options?: BaseMutationOptions,
|
|
2782
|
+
): Promise<SanityDocument_2<R>>
|
|
2783
|
+
/**
|
|
2784
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2785
|
+
* Returns a promise that resolves to the created document.
|
|
2786
|
+
*
|
|
2787
|
+
* @param document - Document to either create or replace
|
|
2788
|
+
* @param options - Mutation options
|
|
2789
|
+
*/
|
|
2790
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2791
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2792
|
+
options: FirstDocumentMutationOptions,
|
|
2793
|
+
): Promise<SanityDocument_2<R>>
|
|
2794
|
+
/**
|
|
2795
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2796
|
+
* Returns a promise that resolves to an array containing the created document.
|
|
2797
|
+
*
|
|
2798
|
+
* @param document - Document to either create or replace
|
|
2799
|
+
* @param options - Mutation options
|
|
2800
|
+
*/
|
|
2801
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2802
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2803
|
+
options: AllDocumentsMutationOptions,
|
|
2804
|
+
): Promise<SanityDocument_2<R>[]>
|
|
2805
|
+
/**
|
|
2806
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2807
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2808
|
+
*
|
|
2809
|
+
* @param document - Document to either create or replace
|
|
2810
|
+
* @param options - Mutation options
|
|
2811
|
+
*/
|
|
2812
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2813
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2814
|
+
options: FirstDocumentIdMutationOptions,
|
|
2815
|
+
): Promise<SingleMutationResult>
|
|
2816
|
+
/**
|
|
2817
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2818
|
+
* Returns a promise that resolves to a mutation result object containing the created document ID.
|
|
2819
|
+
*
|
|
2820
|
+
* @param document - Document to either create or replace
|
|
2821
|
+
* @param options - Mutation options
|
|
2822
|
+
*/
|
|
2823
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2824
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2825
|
+
options: AllDocumentIdsMutationOptions,
|
|
2826
|
+
): Promise<MultipleMutationResult>
|
|
2827
|
+
/**
|
|
2828
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2829
|
+
* Returns a promise that resolves to the created document.
|
|
2830
|
+
*
|
|
2831
|
+
* @param document - Document to either create or replace
|
|
2832
|
+
* @param options - Mutation options
|
|
2833
|
+
*/
|
|
2834
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2835
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2836
|
+
options?: BaseMutationOptions,
|
|
2837
|
+
): Promise<SanityDocument_2<R>>
|
|
2838
|
+
/**
|
|
2839
|
+
* Deletes a document with the given document ID.
|
|
2840
|
+
* Returns a promise that resolves to the deleted document.
|
|
2841
|
+
*
|
|
2842
|
+
* @param id - Document ID to delete
|
|
2843
|
+
* @param options - Options for the mutation
|
|
2844
|
+
*/
|
|
2845
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2846
|
+
id: string,
|
|
2847
|
+
options: FirstDocumentMutationOptions,
|
|
2848
|
+
): Promise<SanityDocument_2<R>>
|
|
2849
|
+
/**
|
|
2850
|
+
* Deletes a document with the given document ID.
|
|
2851
|
+
* Returns a promise that resolves to an array containing the deleted document.
|
|
2852
|
+
*
|
|
2853
|
+
* @param id - Document ID to delete
|
|
2854
|
+
* @param options - Options for the mutation
|
|
2855
|
+
*/
|
|
2856
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2857
|
+
id: string,
|
|
2858
|
+
options: AllDocumentsMutationOptions,
|
|
2859
|
+
): Promise<SanityDocument_2<R>[]>
|
|
2860
|
+
/**
|
|
2861
|
+
* Deletes a document with the given document ID.
|
|
2862
|
+
* Returns a promise that resolves to a mutation result object containing the deleted document ID.
|
|
2863
|
+
*
|
|
2864
|
+
* @param id - Document ID to delete
|
|
2865
|
+
* @param options - Options for the mutation
|
|
2866
|
+
*/
|
|
2867
|
+
delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
|
|
2868
|
+
/**
|
|
2869
|
+
* Deletes a document with the given document ID.
|
|
2870
|
+
* Returns a promise that resolves to a mutation result object containing the deleted document ID.
|
|
2871
|
+
*
|
|
2872
|
+
* @param id - Document ID to delete
|
|
2873
|
+
* @param options - Options for the mutation
|
|
2874
|
+
*/
|
|
2875
|
+
delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
|
|
2876
|
+
/**
|
|
2877
|
+
* Deletes a document with the given document ID.
|
|
2878
|
+
* Returns a promise that resolves to the deleted document.
|
|
2879
|
+
*
|
|
2880
|
+
* @param id - Document ID to delete
|
|
2881
|
+
* @param options - Options for the mutation
|
|
2882
|
+
*/
|
|
2883
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2884
|
+
id: string,
|
|
2885
|
+
options?: BaseMutationOptions,
|
|
2886
|
+
): Promise<SanityDocument_2<R>>
|
|
2887
|
+
/**
|
|
2888
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2889
|
+
* Returns a promise that resolves to first deleted document.
|
|
2890
|
+
*
|
|
2891
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2892
|
+
* @param options - Options for the mutation
|
|
2893
|
+
*/
|
|
2894
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2895
|
+
selection: MutationSelection,
|
|
2896
|
+
options: FirstDocumentMutationOptions,
|
|
2897
|
+
): Promise<SanityDocument_2<R>>
|
|
2898
|
+
/**
|
|
2899
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2900
|
+
* Returns a promise that resolves to an array containing the deleted documents.
|
|
2901
|
+
*
|
|
2902
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2903
|
+
* @param options - Options for the mutation
|
|
2904
|
+
*/
|
|
2905
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2906
|
+
selection: MutationSelection,
|
|
2907
|
+
options: AllDocumentsMutationOptions,
|
|
2908
|
+
): Promise<SanityDocument_2<R>[]>
|
|
2909
|
+
/**
|
|
2910
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2911
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
|
|
2912
|
+
*
|
|
2913
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2914
|
+
* @param options - Options for the mutation
|
|
2915
|
+
*/
|
|
2916
|
+
delete(
|
|
2917
|
+
selection: MutationSelection,
|
|
2918
|
+
options: FirstDocumentIdMutationOptions,
|
|
2919
|
+
): Promise<SingleMutationResult>
|
|
2920
|
+
/**
|
|
2921
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2922
|
+
* Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
|
|
2923
|
+
*
|
|
2924
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2925
|
+
* @param options - Options for the mutation
|
|
2926
|
+
*/
|
|
2927
|
+
delete(
|
|
2928
|
+
selection: MutationSelection,
|
|
2929
|
+
options: AllDocumentIdsMutationOptions,
|
|
2930
|
+
): Promise<MultipleMutationResult>
|
|
2931
|
+
/**
|
|
2932
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2933
|
+
* Returns a promise that resolves to first deleted document.
|
|
2934
|
+
*
|
|
2935
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2936
|
+
* @param options - Options for the mutation
|
|
2937
|
+
*/
|
|
2938
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2939
|
+
selection: MutationSelection,
|
|
2940
|
+
options?: BaseMutationOptions,
|
|
2941
|
+
): Promise<SanityDocument_2<R>>
|
|
2942
|
+
/**
|
|
2943
|
+
* Perform mutation operations against the configured dataset
|
|
2944
|
+
* Returns a promise that resolves to the first mutated document.
|
|
2945
|
+
*
|
|
2946
|
+
* @param operations - Mutation operations to execute
|
|
2947
|
+
* @param options - Mutation options
|
|
2948
|
+
*/
|
|
2949
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2950
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2951
|
+
options: FirstDocumentMutationOptions,
|
|
2952
|
+
): Promise<SanityDocument_2<R>>
|
|
2953
|
+
/**
|
|
2954
|
+
* Perform mutation operations against the configured dataset.
|
|
2955
|
+
* Returns a promise that resolves to an array of the mutated documents.
|
|
2956
|
+
*
|
|
2957
|
+
* @param operations - Mutation operations to execute
|
|
2958
|
+
* @param options - Mutation options
|
|
2959
|
+
*/
|
|
2960
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2961
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2962
|
+
options: AllDocumentsMutationOptions,
|
|
2963
|
+
): Promise<SanityDocument_2<R>[]>
|
|
2964
|
+
/**
|
|
2965
|
+
* Perform mutation operations against the configured dataset
|
|
2966
|
+
* Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
|
|
2967
|
+
*
|
|
2968
|
+
* @param operations - Mutation operations to execute
|
|
2969
|
+
* @param options - Mutation options
|
|
2970
|
+
*/
|
|
2971
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2972
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2973
|
+
options: FirstDocumentIdMutationOptions,
|
|
2974
|
+
): Promise<SingleMutationResult>
|
|
2975
|
+
/**
|
|
2976
|
+
* Perform mutation operations against the configured dataset
|
|
2977
|
+
* Returns a promise that resolves to a mutation result object containing the mutated document IDs.
|
|
2978
|
+
*
|
|
2979
|
+
* @param operations - Mutation operations to execute
|
|
2980
|
+
* @param options - Mutation options
|
|
2981
|
+
*/
|
|
2982
|
+
mutate<R extends Record<string, Any>>(
|
|
2983
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2984
|
+
options: AllDocumentIdsMutationOptions,
|
|
2985
|
+
): Promise<MultipleMutationResult>
|
|
2986
|
+
/**
|
|
2987
|
+
* Perform mutation operations against the configured dataset
|
|
2988
|
+
* Returns a promise that resolves to the first mutated document.
|
|
2989
|
+
*
|
|
2990
|
+
* @param operations - Mutation operations to execute
|
|
2991
|
+
* @param options - Mutation options
|
|
2992
|
+
*/
|
|
2993
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2994
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2995
|
+
options?: BaseMutationOptions,
|
|
2996
|
+
): Promise<SanityDocument_2<R>>
|
|
2997
|
+
/**
|
|
2998
|
+
* Create a new buildable patch of operations to perform
|
|
2999
|
+
*
|
|
3000
|
+
* @param documentId - Document ID to patch
|
|
3001
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
3002
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
3003
|
+
*/
|
|
3004
|
+
patch(documentId: string, operations?: PatchOperations): Patch
|
|
3005
|
+
/**
|
|
3006
|
+
* Create a new buildable patch of operations to perform
|
|
3007
|
+
*
|
|
3008
|
+
* @param documentIds - Array of document IDs to patch
|
|
3009
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
3010
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
3011
|
+
*/
|
|
3012
|
+
patch(documentIds: string[], operations?: PatchOperations): Patch
|
|
3013
|
+
/**
|
|
3014
|
+
* Create a new buildable patch of operations to perform
|
|
3015
|
+
*
|
|
3016
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
3017
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
3018
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
3019
|
+
*/
|
|
3020
|
+
patch(selection: MutationSelection, operations?: PatchOperations): Patch
|
|
3021
|
+
/**
|
|
3022
|
+
* Create a new transaction of mutations
|
|
3023
|
+
*
|
|
3024
|
+
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
3025
|
+
*/
|
|
3026
|
+
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
3027
|
+
operations?: Mutation<R>[],
|
|
3028
|
+
): Transaction
|
|
3029
|
+
/**
|
|
3030
|
+
* Perform action operations against the configured dataset
|
|
3031
|
+
* Returns a promise that resolves to the transaction result
|
|
3032
|
+
*
|
|
3033
|
+
* @param operations - Action operation(s) to execute
|
|
3034
|
+
* @param options - Action options
|
|
3035
|
+
*/
|
|
3036
|
+
action(
|
|
3037
|
+
operations: Action | Action[],
|
|
3038
|
+
options?: BaseActionOptions,
|
|
3039
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
3040
|
+
/**
|
|
3041
|
+
* Perform a request against the Sanity API
|
|
3042
|
+
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
3043
|
+
*
|
|
3044
|
+
* @param options - Request options
|
|
3045
|
+
* @returns Promise resolving to the response body
|
|
3046
|
+
*/
|
|
3047
|
+
request<R = Any>(options: RawRequestOptions): Promise<R>
|
|
3048
|
+
/**
|
|
3049
|
+
* Perform an HTTP request a `/data` sub-endpoint
|
|
3050
|
+
* NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
|
|
3051
|
+
*
|
|
3052
|
+
* @deprecated - Use `request()` or your own HTTP library instead
|
|
3053
|
+
* @param endpoint - Endpoint to hit (mutate, query etc)
|
|
3054
|
+
* @param body - Request body
|
|
3055
|
+
* @param options - Request options
|
|
3056
|
+
* @internal
|
|
3057
|
+
*/
|
|
3058
|
+
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
|
|
3059
|
+
/**
|
|
3060
|
+
* Get a Sanity API URL for the URI provided
|
|
3061
|
+
*
|
|
3062
|
+
* @param uri - URI/path to build URL for
|
|
3063
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
3064
|
+
*/
|
|
3065
|
+
getUrl(uri: string, canUseCdn?: boolean): string
|
|
3066
|
+
/**
|
|
3067
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
3068
|
+
*
|
|
3069
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
3070
|
+
* @param path - Path to append after the operation
|
|
3071
|
+
*/
|
|
3072
|
+
getDataUrl(operation: string, path?: string): string
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
export {SanityDocument}
|
|
3076
|
+
|
|
3077
|
+
/** @internal */
|
|
3078
|
+
declare type SanityDocument_2<T extends Record<string, Any> = Record<string, Any>> = {
|
|
3079
|
+
[P in keyof T]: T[P]
|
|
3080
|
+
} & {
|
|
3081
|
+
_id: string
|
|
3082
|
+
_rev: string
|
|
3083
|
+
_type: string
|
|
3084
|
+
_createdAt: string
|
|
3085
|
+
_updatedAt: string
|
|
3086
|
+
/**
|
|
3087
|
+
* Present when `perspective` is set to `previewDrafts`
|
|
3088
|
+
*/
|
|
3089
|
+
_originalId?: string
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
/** @public */
|
|
3093
|
+
declare type SanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
|
|
3094
|
+
[P in keyof T]: T[P]
|
|
3095
|
+
} & {
|
|
3096
|
+
_type: string
|
|
3097
|
+
}
|
|
3098
|
+
|
|
3099
|
+
/** @internal */
|
|
3100
|
+
declare interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
3101
|
+
metadata: {
|
|
3102
|
+
_type: 'sanity.imageMetadata'
|
|
3103
|
+
hasAlpha: boolean
|
|
3104
|
+
isOpaque: boolean
|
|
3105
|
+
lqip?: string
|
|
3106
|
+
blurHash?: string
|
|
3107
|
+
dimensions: {
|
|
3108
|
+
_type: 'sanity.imageDimensions'
|
|
3109
|
+
aspectRatio: number
|
|
3110
|
+
height: number
|
|
3111
|
+
width: number
|
|
3112
|
+
}
|
|
3113
|
+
palette?: {
|
|
3114
|
+
_type: 'sanity.imagePalette'
|
|
3115
|
+
darkMuted?: SanityImagePalette
|
|
3116
|
+
darkVibrant?: SanityImagePalette
|
|
3117
|
+
dominant?: SanityImagePalette
|
|
3118
|
+
lightMuted?: SanityImagePalette
|
|
3119
|
+
lightVibrant?: SanityImagePalette
|
|
3120
|
+
muted?: SanityImagePalette
|
|
3121
|
+
vibrant?: SanityImagePalette
|
|
3122
|
+
}
|
|
3123
|
+
image?: {
|
|
3124
|
+
_type: 'sanity.imageExifTags'
|
|
3125
|
+
[key: string]: Any
|
|
3126
|
+
}
|
|
3127
|
+
exif?: {
|
|
3128
|
+
_type: 'sanity.imageExifMetadata'
|
|
3129
|
+
[key: string]: Any
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
|
|
3134
|
+
/** @internal */
|
|
3135
|
+
declare interface SanityImagePalette {
|
|
3136
|
+
background: string
|
|
3137
|
+
foreground: string
|
|
3138
|
+
population: number
|
|
3139
|
+
title: string
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
/** @public */
|
|
3143
|
+
export declare interface SanityProject {
|
|
3144
|
+
id: string
|
|
3145
|
+
displayName: string
|
|
3146
|
+
/**
|
|
3147
|
+
* @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
|
|
3148
|
+
* @see https://www.sanity.io/help/studio-host-user-applications
|
|
3149
|
+
*/
|
|
3150
|
+
studioHost: string | null
|
|
3151
|
+
organizationId: string | null
|
|
3152
|
+
isBlocked: boolean
|
|
3153
|
+
isDisabled: boolean
|
|
3154
|
+
isDisabledByUser: boolean
|
|
3155
|
+
createdAt: string
|
|
3156
|
+
pendingInvites?: number
|
|
3157
|
+
maxRetentionDays?: number
|
|
3158
|
+
members: SanityProjectMember[]
|
|
3159
|
+
metadata: {
|
|
3160
|
+
cliInitializedAt?: string
|
|
3161
|
+
color?: string
|
|
3162
|
+
/**
|
|
3163
|
+
* @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
|
|
3164
|
+
* @see https://www.sanity.io/help/studio-host-user-applications
|
|
3165
|
+
*/
|
|
3166
|
+
externalStudioHost?: string
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
|
|
3170
|
+
/** @public */
|
|
3171
|
+
export declare interface SanityProjectMember {
|
|
3172
|
+
id: string
|
|
3173
|
+
role: string
|
|
3174
|
+
isRobot: boolean
|
|
3175
|
+
isCurrentUser: boolean
|
|
3176
|
+
}
|
|
3177
|
+
|
|
3178
|
+
/**
|
|
3179
|
+
* @internal
|
|
3180
|
+
*
|
|
3181
|
+
* Top-level context provider that provides access to the Sanity configuration instance.
|
|
3182
|
+
* This must wrap any components making use of the Sanity SDK React hooks.
|
|
3183
|
+
*
|
|
3184
|
+
* @remarks In most cases, SanityApp should be used rather than SanityProvider directly; SanityApp bundles both SanityProvider and an authentication layer.
|
|
3185
|
+
* @param props - Sanity project and dataset configuration
|
|
3186
|
+
* @returns Rendered component
|
|
3187
|
+
* @example
|
|
3188
|
+
* ```tsx
|
|
3189
|
+
* import {createSanityInstance} from '@sanity/sdk'
|
|
3190
|
+
* import {SanityProvider} from '@sanity/sdk-react'
|
|
3191
|
+
*
|
|
3192
|
+
* import MyAppRoot from './Root'
|
|
3193
|
+
*
|
|
3194
|
+
* const sanityInstance = createSanityInstance({
|
|
3195
|
+
* projectId: 'your-project-id',
|
|
3196
|
+
* dataset: 'production',
|
|
3197
|
+
* })
|
|
3198
|
+
*
|
|
3199
|
+
* export default function MyApp() {
|
|
3200
|
+
* return (
|
|
3201
|
+
* <SanityProvider sanityInstance={sanityInstance}>
|
|
3202
|
+
* <MyAppRoot />
|
|
3203
|
+
* </SanityProvider>
|
|
3204
|
+
* )
|
|
3205
|
+
* }
|
|
3206
|
+
* ```
|
|
3207
|
+
*/
|
|
3208
|
+
export declare const SanityProvider: ({
|
|
3209
|
+
children,
|
|
3210
|
+
sanityInstances,
|
|
3211
|
+
}: SanityProviderProps) => ReactElement
|
|
3212
|
+
|
|
3213
|
+
/**
|
|
3214
|
+
* @internal
|
|
3215
|
+
*/
|
|
3216
|
+
export declare interface SanityProviderProps {
|
|
3217
|
+
children: React.ReactNode
|
|
3218
|
+
sanityInstances: SanityInstance[]
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3221
|
+
/** @public */
|
|
3222
|
+
declare interface SanityQueries {}
|
|
3223
|
+
|
|
3224
|
+
/** @public */
|
|
3225
|
+
declare interface SanityUser {
|
|
3226
|
+
id: string
|
|
3227
|
+
projectId: string
|
|
3228
|
+
displayName: string
|
|
3229
|
+
familyName: string | null
|
|
3230
|
+
givenName: string | null
|
|
3231
|
+
middleName: string | null
|
|
3232
|
+
imageUrl: string | null
|
|
3233
|
+
createdAt: string
|
|
3234
|
+
updatedAt: string
|
|
3235
|
+
isCurrentUser: boolean
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
/**
|
|
3239
|
+
* @internal
|
|
3240
|
+
*
|
|
3241
|
+
* Top-level context provider that provides access to the Sanity SDK.
|
|
3242
|
+
*/
|
|
3243
|
+
export declare function SDKProvider({
|
|
3244
|
+
children,
|
|
3245
|
+
sanityConfigs,
|
|
3246
|
+
fallback,
|
|
3247
|
+
}: SDKProviderProps): ReactElement
|
|
3248
|
+
|
|
3249
|
+
/**
|
|
3250
|
+
* @internal
|
|
3251
|
+
*/
|
|
3252
|
+
export declare interface SDKProviderProps {
|
|
3253
|
+
children: ReactNode
|
|
3254
|
+
sanityConfigs: SanityConfig[]
|
|
3255
|
+
fallback: ReactNode
|
|
3256
|
+
}
|
|
3257
|
+
|
|
3258
|
+
/** @internal */
|
|
3259
|
+
declare interface SingleActionResult {
|
|
3260
|
+
transactionId: string
|
|
3261
|
+
}
|
|
3262
|
+
|
|
3263
|
+
/** @internal */
|
|
3264
|
+
declare interface SingleMutationResult {
|
|
3265
|
+
transactionId: string
|
|
3266
|
+
documentId: string
|
|
3267
|
+
results: {
|
|
3268
|
+
id: string
|
|
3269
|
+
operation: MutationOperation
|
|
3270
|
+
}[]
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
export {SortOrderingItem}
|
|
3274
|
+
|
|
3275
|
+
/** @public */
|
|
3276
|
+
declare type StackablePerspective = ('published' | 'drafts' | string) & {}
|
|
3277
|
+
|
|
3278
|
+
/** @public */
|
|
3279
|
+
declare interface StegaConfig {
|
|
3280
|
+
/**
|
|
3281
|
+
* Enable or disable stega encoded strings in query results
|
|
3282
|
+
* ```ts
|
|
3283
|
+
{
|
|
3284
|
+
enabled: process.env.VERCEL_ENV !== 'production'
|
|
3285
|
+
}
|
|
3286
|
+
* ```
|
|
3287
|
+
* @defaultValue `false`
|
|
3288
|
+
*/
|
|
3289
|
+
enabled?: boolean
|
|
3290
|
+
/**
|
|
3291
|
+
* Where the Studio is hosted.
|
|
3292
|
+
* If it's embedded in the app, use the base path for example `/studio`.
|
|
3293
|
+
* Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.
|
|
3294
|
+
*
|
|
3295
|
+
*/
|
|
3296
|
+
studioUrl?: StudioUrl | ResolveStudioUrl
|
|
3297
|
+
filter?: FilterDefault
|
|
3298
|
+
/**
|
|
3299
|
+
* Specify a `console.log` compatible logger to see debug logs, which keys are encoded and which are not.
|
|
3300
|
+
*/
|
|
3301
|
+
logger?: Logger
|
|
3302
|
+
/**
|
|
3303
|
+
* Set to `true` to omit cross dataset reference specific data from encoded strings
|
|
3304
|
+
*/
|
|
3305
|
+
omitCrossDatasetReferenceData?: boolean
|
|
3306
|
+
}
|
|
3307
|
+
|
|
3308
|
+
/** @public */
|
|
3309
|
+
declare type StegaConfigRequiredKeys = Extract<keyof StegaConfig, 'enabled'>
|
|
3310
|
+
|
|
3311
|
+
/** @alpha */
|
|
3312
|
+
declare type StudioBaseRoute = {
|
|
3313
|
+
baseUrl: StudioBaseUrl
|
|
3314
|
+
workspace?: string
|
|
3315
|
+
tool?: string
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
/** @alpha */
|
|
3319
|
+
declare type StudioBaseUrl = `/${string}` | `${string}.sanity.studio` | `https://${string}` | string
|
|
3320
|
+
|
|
3321
|
+
/** @alpha */
|
|
3322
|
+
declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
|
|
3323
|
+
|
|
3324
|
+
declare interface StudioWorkspacesResult {
|
|
3325
|
+
workspacesByResourceId: WorkspacesByResourceId
|
|
3326
|
+
error: string | null
|
|
3327
|
+
isConnected: boolean
|
|
3328
|
+
}
|
|
3329
|
+
|
|
3330
|
+
/** @public */
|
|
3331
|
+
declare type SyncTag = `s1:${string}`
|
|
3332
|
+
|
|
3333
|
+
/** @public */
|
|
3334
|
+
declare class Transaction extends BaseTransaction {
|
|
3335
|
+
#private
|
|
3336
|
+
constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
|
|
3337
|
+
/**
|
|
3338
|
+
* Clones the transaction
|
|
3339
|
+
*/
|
|
3340
|
+
clone(): Transaction
|
|
3341
|
+
/**
|
|
3342
|
+
* Commit the transaction, returning a promise that resolves to the first mutated document
|
|
3343
|
+
*
|
|
3344
|
+
* @param options - Options for the mutation operation
|
|
3345
|
+
*/
|
|
3346
|
+
commit<R extends Record<string, Any>>(
|
|
3347
|
+
options: TransactionFirstDocumentMutationOptions,
|
|
3348
|
+
): Promise<SanityDocument_2<R>>
|
|
3349
|
+
/**
|
|
3350
|
+
* Commit the transaction, returning a promise that resolves to an array of the mutated documents
|
|
3351
|
+
*
|
|
3352
|
+
* @param options - Options for the mutation operation
|
|
3353
|
+
*/
|
|
3354
|
+
commit<R extends Record<string, Any>>(
|
|
3355
|
+
options: TransactionAllDocumentsMutationOptions,
|
|
3356
|
+
): Promise<SanityDocument_2<R>[]>
|
|
3357
|
+
/**
|
|
3358
|
+
* Commit the transaction, returning a promise that resolves to a mutation result object
|
|
3359
|
+
*
|
|
3360
|
+
* @param options - Options for the mutation operation
|
|
3361
|
+
*/
|
|
3362
|
+
commit(options: TransactionFirstDocumentIdMutationOptions): Promise<SingleMutationResult>
|
|
3363
|
+
/**
|
|
3364
|
+
* Commit the transaction, returning a promise that resolves to a mutation result object
|
|
3365
|
+
*
|
|
3366
|
+
* @param options - Options for the mutation operation
|
|
3367
|
+
*/
|
|
3368
|
+
commit(options: TransactionAllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
|
|
3369
|
+
/**
|
|
3370
|
+
* Commit the transaction, returning a promise that resolves to a mutation result object
|
|
3371
|
+
*
|
|
3372
|
+
* @param options - Options for the mutation operation
|
|
3373
|
+
*/
|
|
3374
|
+
commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
|
|
3375
|
+
/**
|
|
3376
|
+
* Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
|
|
3377
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
3378
|
+
*
|
|
3379
|
+
* @param documentId - Document ID to perform the patch operation on
|
|
3380
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
3381
|
+
*/
|
|
3382
|
+
patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
|
|
3383
|
+
/**
|
|
3384
|
+
* Performs a patch on the given selection. Can either be a builder function or an object of patch operations.
|
|
3385
|
+
*
|
|
3386
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
3387
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
3388
|
+
*/
|
|
3389
|
+
patch(patch: MutationSelection, patchOps?: PatchBuilder | PatchOperations): this
|
|
3390
|
+
/**
|
|
3391
|
+
* Adds the given patch instance to the transaction.
|
|
3392
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
3393
|
+
*
|
|
3394
|
+
* @param patch - Patch to execute
|
|
3395
|
+
*/
|
|
3396
|
+
patch(patch: Patch): this
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
/** @internal */
|
|
3400
|
+
declare type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
3401
|
+
returnFirst?: false
|
|
3402
|
+
returnDocuments?: false
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
/** @internal */
|
|
3406
|
+
declare type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
|
|
3407
|
+
returnFirst?: false
|
|
3408
|
+
returnDocuments: true
|
|
3409
|
+
}
|
|
3410
|
+
|
|
3411
|
+
/** @internal */
|
|
3412
|
+
declare type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
|
|
3413
|
+
returnFirst: true
|
|
3414
|
+
returnDocuments?: false
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3417
|
+
/** @internal */
|
|
3418
|
+
declare type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
|
|
3419
|
+
returnFirst: true
|
|
3420
|
+
returnDocuments: true
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
/** @public */
|
|
3424
|
+
declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
|
|
3425
|
+
filterResponse: false
|
|
3426
|
+
/**
|
|
3427
|
+
* When `filterResponse` is `false`, `returnQuery` also defaults to `true` for
|
|
3428
|
+
* backwards compatibility (on the client side, not from the content lake API).
|
|
3429
|
+
* Can also explicitly be set to `true`.
|
|
3430
|
+
*/
|
|
3431
|
+
returnQuery?: true
|
|
3432
|
+
}
|
|
3433
|
+
|
|
3434
|
+
/**
|
|
3435
|
+
* When using `filterResponse: false`, but you do not wish to receive back the query from
|
|
3436
|
+
* the content lake API.
|
|
3437
|
+
*
|
|
3438
|
+
* @public
|
|
3439
|
+
*/
|
|
3440
|
+
declare interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
|
|
3441
|
+
filterResponse: false
|
|
3442
|
+
returnQuery: false
|
|
3443
|
+
}
|
|
3444
|
+
|
|
3445
|
+
/**
|
|
3446
|
+
* Retract a published document.
|
|
3447
|
+
* If there is no draft version then this is created from the published version.
|
|
3448
|
+
* In either case the published version is deleted.
|
|
3449
|
+
*
|
|
3450
|
+
* @public
|
|
3451
|
+
*/
|
|
3452
|
+
declare type UnpublishAction = {
|
|
3453
|
+
actionType: 'sanity.action.document.unpublish'
|
|
3454
|
+
/**
|
|
3455
|
+
* Draft document ID to replace the published document with
|
|
3456
|
+
*/
|
|
3457
|
+
draftId: string
|
|
3458
|
+
/**
|
|
3459
|
+
* Published document ID to delete
|
|
3460
|
+
*/
|
|
3461
|
+
publishedId: string
|
|
3462
|
+
}
|
|
3463
|
+
|
|
3464
|
+
declare type Updater<TValue> = TValue | ((nextValue: TValue) => TValue)
|
|
3465
|
+
|
|
3466
|
+
/** @public */
|
|
3467
|
+
declare type UploadBody = File | Blob | Buffer | NodeJS.ReadableStream
|
|
3468
|
+
|
|
3469
|
+
/** @public */
|
|
3470
|
+
declare interface UploadClientConfig {
|
|
3471
|
+
/**
|
|
3472
|
+
* Optional request tag for the upload
|
|
3473
|
+
*/
|
|
3474
|
+
tag?: string
|
|
3475
|
+
/**
|
|
3476
|
+
* Whether or not to preserve the original filename (default: true)
|
|
3477
|
+
*/
|
|
3478
|
+
preserveFilename?: boolean
|
|
3479
|
+
/**
|
|
3480
|
+
* Filename for this file (optional)
|
|
3481
|
+
*/
|
|
3482
|
+
filename?: string
|
|
3483
|
+
/**
|
|
3484
|
+
* Milliseconds to wait before timing the request out
|
|
3485
|
+
*/
|
|
3486
|
+
timeout?: number
|
|
3487
|
+
/**
|
|
3488
|
+
* Mime type of the file
|
|
3489
|
+
*/
|
|
3490
|
+
contentType?: string
|
|
3491
|
+
/**
|
|
3492
|
+
* Array of metadata parts to extract from asset
|
|
3493
|
+
*/
|
|
3494
|
+
extract?: AssetMetadataType[]
|
|
3495
|
+
/**
|
|
3496
|
+
* Optional freeform label for the asset. Generally not used.
|
|
3497
|
+
*/
|
|
3498
|
+
label?: string
|
|
3499
|
+
/**
|
|
3500
|
+
* Optional title for the asset
|
|
3501
|
+
*/
|
|
3502
|
+
title?: string
|
|
3503
|
+
/**
|
|
3504
|
+
* Optional description for the asset
|
|
3505
|
+
*/
|
|
3506
|
+
description?: string
|
|
3507
|
+
/**
|
|
3508
|
+
* The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published
|
|
3509
|
+
*/
|
|
3510
|
+
creditLine?: string
|
|
3511
|
+
/**
|
|
3512
|
+
* Source data (when the asset is from an external service)
|
|
3513
|
+
*/
|
|
3514
|
+
source?: {
|
|
3515
|
+
/**
|
|
3516
|
+
* The (u)id of the asset within the source, i.e. 'i-f323r1E'
|
|
3517
|
+
*/
|
|
3518
|
+
id: string
|
|
3519
|
+
/**
|
|
3520
|
+
* The name of the source, i.e. 'unsplash'
|
|
3521
|
+
*/
|
|
3522
|
+
name: string
|
|
3523
|
+
/**
|
|
3524
|
+
* A url to where to find the asset, or get more info about it in the source
|
|
3525
|
+
*/
|
|
3526
|
+
url?: string
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
|
|
3530
|
+
/**
|
|
3531
|
+
*
|
|
3532
|
+
* @beta
|
|
3533
|
+
*
|
|
3534
|
+
* Provides a callback for applying one or more actions to a document.
|
|
3535
|
+
*
|
|
3536
|
+
* @category Documents
|
|
3537
|
+
* @param resourceId - The resource ID of the document to apply actions to. If not provided, the document will use the default resource.
|
|
3538
|
+
* @returns A function that takes one more more {@link DocumentAction}s and returns a promise that resolves to an {@link ActionsResult}.
|
|
3539
|
+
* @example Publish or unpublish a document
|
|
3540
|
+
* ```
|
|
3541
|
+
* import { publishDocument, unpublishDocument } from '@sanity/sdk'
|
|
3542
|
+
* import { useApplyDocumentActions } from '@sanity/sdk-react'
|
|
3543
|
+
*
|
|
3544
|
+
* const apply = useApplyDocumentActions()
|
|
3545
|
+
* const myDocument = { _id: 'my-document-id', _type: 'my-document-type' }
|
|
3546
|
+
*
|
|
3547
|
+
* return (
|
|
3548
|
+
* <button onClick={() => apply(publishDocument(myDocument))}>Publish</button>
|
|
3549
|
+
* <button onClick={() => apply(unpublishDocument(myDocument))}>Unpublish</button>
|
|
3550
|
+
* )
|
|
3551
|
+
* ```
|
|
3552
|
+
*
|
|
3553
|
+
* @example Create and publish a new document
|
|
3554
|
+
* ```
|
|
3555
|
+
* import { createDocument, publishDocument } from '@sanity/sdk'
|
|
3556
|
+
* import { useApplyDocumentActions } from '@sanity/sdk-react'
|
|
3557
|
+
*
|
|
3558
|
+
* const apply = useApplyDocumentActions()
|
|
3559
|
+
*
|
|
3560
|
+
* const handleCreateAndPublish = () => {
|
|
3561
|
+
* const handle = { _id: window.crypto.randomUUID(), _type: 'my-document-type' }
|
|
3562
|
+
* apply([
|
|
3563
|
+
* createDocument(handle),
|
|
3564
|
+
* publishDocument(handle),
|
|
3565
|
+
* ])
|
|
3566
|
+
* }
|
|
3567
|
+
*
|
|
3568
|
+
* return (
|
|
3569
|
+
* <button onClick={handleCreateAndPublish}>
|
|
3570
|
+
* I’m feeling lucky
|
|
3571
|
+
* </button>
|
|
3572
|
+
* )
|
|
3573
|
+
* ```
|
|
3574
|
+
*/
|
|
3575
|
+
export declare function useApplyDocumentActions(
|
|
3576
|
+
resourceId?: ResourceId,
|
|
3577
|
+
): <TDocument extends SanityDocument>(
|
|
3578
|
+
action: DocumentAction<TDocument> | DocumentAction<TDocument>[],
|
|
3579
|
+
options?: ApplyDocumentActionsOptions,
|
|
3580
|
+
) => Promise<ActionsResult<TDocument>>
|
|
3581
|
+
|
|
3582
|
+
/**
|
|
3583
|
+
* @internal
|
|
3584
|
+
* A React hook that subscribes to authentication state changes.
|
|
3585
|
+
*
|
|
3586
|
+
* This hook provides access to the current authentication state type from the Sanity auth store.
|
|
3587
|
+
* It automatically re-renders when the authentication state changes.
|
|
3588
|
+
*
|
|
3589
|
+
* @remarks
|
|
3590
|
+
* The hook uses `useSyncExternalStore` to safely subscribe to auth state changes
|
|
3591
|
+
* and ensure consistency between server and client rendering.
|
|
3592
|
+
*
|
|
3593
|
+
* @returns The current authentication state type
|
|
3594
|
+
*
|
|
3595
|
+
* @example
|
|
3596
|
+
* ```tsx
|
|
3597
|
+
* function AuthStatus() {
|
|
3598
|
+
* const authState = useAuthState()
|
|
3599
|
+
* return <div>Current auth state: {authState}</div>
|
|
3600
|
+
* }
|
|
3601
|
+
* ```
|
|
3602
|
+
*/
|
|
3603
|
+
export declare const useAuthState: () => AuthState
|
|
3604
|
+
|
|
3605
|
+
/**
|
|
3606
|
+
* Hook to get the currently logged in user
|
|
3607
|
+
* @internal
|
|
3608
|
+
* @returns The current user or null if not authenticated
|
|
3609
|
+
*/
|
|
3610
|
+
export declare const useAuthToken: () => string | null
|
|
3611
|
+
|
|
3612
|
+
/**
|
|
3613
|
+
* A React hook that provides a client that subscribes to changes in your application,
|
|
3614
|
+
* such as user authentication changes.
|
|
3615
|
+
*
|
|
3616
|
+
* @remarks
|
|
3617
|
+
* The hook uses `useSyncExternalStore` to safely subscribe to changes
|
|
3618
|
+
* and ensure consistency between server and client rendering.
|
|
3619
|
+
*
|
|
3620
|
+
* @category Platform
|
|
3621
|
+
* @returns A Sanity client
|
|
3622
|
+
*
|
|
3623
|
+
* @example
|
|
3624
|
+
* ```tsx
|
|
3625
|
+
* function MyComponent() {
|
|
3626
|
+
* const client = useClient({apiVersion: '2024-11-12'})
|
|
3627
|
+
* const [document, setDocument] = useState(null)
|
|
3628
|
+
* useEffect(async () => {
|
|
3629
|
+
* const doc = client.fetch('*[_id == "myDocumentId"]')
|
|
3630
|
+
* setDocument(doc)
|
|
3631
|
+
* }, [])
|
|
3632
|
+
* return <div>{JSON.stringify(document) ?? 'Loading...'}</div>
|
|
3633
|
+
* }
|
|
3634
|
+
* ```
|
|
3635
|
+
*
|
|
3636
|
+
* @public
|
|
3637
|
+
* @function
|
|
3638
|
+
*/
|
|
3639
|
+
export declare const useClient: (e: ClientOptions) => SanityClient
|
|
3640
|
+
|
|
3641
|
+
declare type UseCurrentUser = {
|
|
3642
|
+
/**
|
|
3643
|
+
* @public
|
|
3644
|
+
*
|
|
3645
|
+
* Provides the currently authenticated user’s profile information.
|
|
3646
|
+
*
|
|
3647
|
+
* @category Users
|
|
3648
|
+
* @returns The current user data
|
|
3649
|
+
*
|
|
3650
|
+
* @example Rendering a basic user profile
|
|
3651
|
+
* ```
|
|
3652
|
+
* const user = useCurrentUser()
|
|
3653
|
+
*
|
|
3654
|
+
* return (
|
|
3655
|
+
* <figure>
|
|
3656
|
+
* <img src={user?.profileImage} alt=`Profile image for ${user?.name}` />
|
|
3657
|
+
* <h2>{user?.name}</h2>
|
|
3658
|
+
* </figure>
|
|
3659
|
+
* )
|
|
3660
|
+
* ```
|
|
3661
|
+
*/
|
|
3662
|
+
(): CurrentUser | null
|
|
3663
|
+
}
|
|
3664
|
+
|
|
3665
|
+
/**
|
|
3666
|
+
* @public
|
|
3667
|
+
* @function
|
|
3668
|
+
* @TODO This should not return null — users of a custom app will always be authenticated via Core
|
|
3669
|
+
*/
|
|
3670
|
+
export declare const useCurrentUser: UseCurrentUser
|
|
3671
|
+
|
|
3672
|
+
/**
|
|
3673
|
+
* @remarks
|
|
3674
|
+
* A React hook that retrieves the dashboard organization ID that is currently selected in the Sanity Dashboard.
|
|
3675
|
+
*
|
|
3676
|
+
* @example
|
|
3677
|
+
* ```tsx
|
|
3678
|
+
* function DashboardComponent() {
|
|
3679
|
+
* const orgId = useDashboardOrganizationId()
|
|
3680
|
+
*
|
|
3681
|
+
* if (!orgId) return null
|
|
3682
|
+
*
|
|
3683
|
+
* return <div>Organization ID: {String(orgId)}</div>
|
|
3684
|
+
* }
|
|
3685
|
+
* ```
|
|
3686
|
+
*
|
|
3687
|
+
* @returns The dashboard organization ID (string | undefined)
|
|
3688
|
+
* @public
|
|
3689
|
+
*/
|
|
3690
|
+
export declare function useDashboardOrganizationId(): string | undefined
|
|
3691
|
+
|
|
3692
|
+
declare type UseDatasets = {
|
|
3693
|
+
/**
|
|
3694
|
+
*
|
|
3695
|
+
* Returns metadata for each dataset the current user has access to.
|
|
3696
|
+
*
|
|
3697
|
+
* @category Datasets
|
|
3698
|
+
* @returns The metadata for your the datasets
|
|
3699
|
+
*
|
|
3700
|
+
* @example
|
|
3701
|
+
* ```tsx
|
|
3702
|
+
* const datasets = useDatasets()
|
|
3703
|
+
*
|
|
3704
|
+
* return (
|
|
3705
|
+
* <select>
|
|
3706
|
+
* {datasets.map((dataset) => (
|
|
3707
|
+
* <option key={dataset.name}>{dataset.name}</option>
|
|
3708
|
+
* ))}
|
|
3709
|
+
* </select>
|
|
3710
|
+
* )
|
|
3711
|
+
* ```
|
|
3712
|
+
*
|
|
3713
|
+
*/
|
|
3714
|
+
(): DatasetsResponse
|
|
3715
|
+
}
|
|
3716
|
+
|
|
3717
|
+
/**
|
|
3718
|
+
* @public
|
|
3719
|
+
* @function
|
|
3720
|
+
*/
|
|
3721
|
+
export declare const useDatasets: UseDatasets
|
|
3722
|
+
|
|
3723
|
+
/**
|
|
3724
|
+
* @beta
|
|
3725
|
+
*
|
|
3726
|
+
* ## useDocument(doc, path)
|
|
3727
|
+
* Read and subscribe to nested values in a document
|
|
3728
|
+
* @category Documents
|
|
3729
|
+
* @param doc - The document to read state from. If you pass a `DocumentHandle` with a `resourceId` in the DocumentResourceId format (`document:projectId.dataset:documentId`)
|
|
3730
|
+
* the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.
|
|
3731
|
+
* @param path - The path to the nested value to read from
|
|
3732
|
+
* @returns The value at the specified path
|
|
3733
|
+
* @example
|
|
3734
|
+
* ```tsx
|
|
3735
|
+
* import {type DocumentHandle, useDocument} from '@sanity/sdk-react'
|
|
3736
|
+
*
|
|
3737
|
+
* function OrderLink({documentHandle}: {documentHandle: DocumentHandle}) {
|
|
3738
|
+
* const title = useDocument(documentHandle, 'title')
|
|
3739
|
+
* const id = useDocument(documentHandle, '_id')
|
|
3740
|
+
*
|
|
3741
|
+
* return (
|
|
3742
|
+
* <a href=`/order/${id}`>Order {title} today!</a>
|
|
3743
|
+
* )
|
|
3744
|
+
* }
|
|
3745
|
+
* ```
|
|
3746
|
+
*
|
|
3747
|
+
*/
|
|
3748
|
+
export declare function useDocument<
|
|
3749
|
+
TDocument extends SanityDocument,
|
|
3750
|
+
TPath extends JsonMatchPath<TDocument>,
|
|
3751
|
+
>(doc: DocumentHandle<TDocument>, path: TPath): JsonMatch<TDocument, TPath> | undefined
|
|
3752
|
+
|
|
3753
|
+
/**
|
|
3754
|
+
* @beta
|
|
3755
|
+
* ## useDocument(doc)
|
|
3756
|
+
* Read and subscribe to an entire document
|
|
3757
|
+
* @param doc - The document to read state from
|
|
3758
|
+
* @returns The document state as an object
|
|
3759
|
+
* @example
|
|
3760
|
+
* ```tsx
|
|
3761
|
+
* import {type SanityDocument, type DocumentHandle, useDocument} from '@sanity/sdk-react'
|
|
3762
|
+
*
|
|
3763
|
+
* interface Book extends SanityDocument {
|
|
3764
|
+
* title: string
|
|
3765
|
+
* author: string
|
|
3766
|
+
* summary: string
|
|
3767
|
+
* }
|
|
3768
|
+
*
|
|
3769
|
+
* function DocumentView({documentHandle}: {documentHandle: DocumentHandle}) {
|
|
3770
|
+
* const book = useDocument<Book>(documentHandle)
|
|
3771
|
+
*
|
|
3772
|
+
* return (
|
|
3773
|
+
* <article>
|
|
3774
|
+
* <h1>{book?.title}</h1>
|
|
3775
|
+
* <address>By {book?.author}</address>
|
|
3776
|
+
*
|
|
3777
|
+
* <h2>Summary</h2>
|
|
3778
|
+
* {book?.summary}
|
|
3779
|
+
*
|
|
3780
|
+
* <h2>Order</h2>
|
|
3781
|
+
* <a href=`/order/${book._id}`>Order {book?.title} today!</a>
|
|
3782
|
+
* </article>
|
|
3783
|
+
* )
|
|
3784
|
+
* }
|
|
3785
|
+
* ```
|
|
3786
|
+
*
|
|
3787
|
+
*/
|
|
3788
|
+
export declare function useDocument<TDocument extends SanityDocument>(
|
|
3789
|
+
doc: DocumentHandle<TDocument>,
|
|
3790
|
+
): TDocument | null
|
|
3791
|
+
|
|
3792
|
+
/**
|
|
3793
|
+
*
|
|
3794
|
+
* @beta
|
|
3795
|
+
*
|
|
3796
|
+
* Subscribes an event handler to events in your application’s document store, such as document
|
|
3797
|
+
* creation, deletion, and updates.
|
|
3798
|
+
*
|
|
3799
|
+
* @category Documents
|
|
3800
|
+
* @param handler - The event handler to register.
|
|
3801
|
+
* @param doc - The document to subscribe to events for. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)
|
|
3802
|
+
* the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.
|
|
3803
|
+
* @example
|
|
3804
|
+
* ```
|
|
3805
|
+
* import {useDocumentEvent} from '@sanity/sdk-react'
|
|
3806
|
+
* import {type DocumentEvent} from '@sanity/sdk'
|
|
3807
|
+
*
|
|
3808
|
+
* useDocumentEvent((event) => {
|
|
3809
|
+
* if (event.type === DocumentEvent.DocumentDeletedEvent) {
|
|
3810
|
+
* alert(`Document with ID ${event.documentId} deleted!`)
|
|
3811
|
+
* } else {
|
|
3812
|
+
* console.log(event)
|
|
3813
|
+
* }
|
|
3814
|
+
* })
|
|
3815
|
+
* ```
|
|
3816
|
+
*/
|
|
3817
|
+
export declare function useDocumentEvent(
|
|
3818
|
+
handler: (documentEvent: DocumentEvent) => void,
|
|
3819
|
+
doc: DocumentHandle,
|
|
3820
|
+
): void
|
|
3821
|
+
|
|
3822
|
+
/**
|
|
3823
|
+
*
|
|
3824
|
+
* @beta
|
|
3825
|
+
*
|
|
3826
|
+
* Check if the current user has the specified permissions for the given document actions.
|
|
3827
|
+
*
|
|
3828
|
+
* @category Permissions
|
|
3829
|
+
* @param actions - One more more calls to a particular document action function for a given document
|
|
3830
|
+
* @returns An object that specifies whether the action is allowed; if the action is not allowed, an explanatory message and list of reasons is also provided.
|
|
3831
|
+
*
|
|
3832
|
+
* @example Checking for permission to publish a document
|
|
3833
|
+
* ```ts
|
|
3834
|
+
* import {useDocumentPermissions, useApplyDocumentActions} from '@sanity/sdk-react'
|
|
3835
|
+
* import {publishDocument} from '@sanity/sdk'
|
|
3836
|
+
*
|
|
3837
|
+
* export function PublishButton({doc}: {doc: DocumentHandle}) {
|
|
3838
|
+
* const publishPermissions = useDocumentPermissions(publishDocument(doc))
|
|
3839
|
+
* const applyAction = useApplyDocumentActions()
|
|
3840
|
+
*
|
|
3841
|
+
* return (
|
|
3842
|
+
* <>
|
|
3843
|
+
* <button
|
|
3844
|
+
* disabled={!publishPermissions.allowed}
|
|
3845
|
+
* onClick={() => applyAction(publishDocument(doc))}
|
|
3846
|
+
* popoverTarget={`${publishPermissions.allowed ? undefined : 'publishButtonPopover'}`}
|
|
3847
|
+
* >
|
|
3848
|
+
* Publish
|
|
3849
|
+
* </button>
|
|
3850
|
+
* {!publishPermissions.allowed && (
|
|
3851
|
+
* <div popover id="publishButtonPopover">
|
|
3852
|
+
* {publishPermissions.message}
|
|
3853
|
+
* </div>
|
|
3854
|
+
* )}
|
|
3855
|
+
* </>
|
|
3856
|
+
* )
|
|
3857
|
+
* }
|
|
3858
|
+
* ```
|
|
3859
|
+
*/
|
|
3860
|
+
export declare function useDocumentPermissions(
|
|
3861
|
+
actions: DocumentAction | DocumentAction[],
|
|
3862
|
+
): DocumentPermissionsResult
|
|
3863
|
+
|
|
3864
|
+
/**
|
|
3865
|
+
* Retrieves batches of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
|
|
3866
|
+
* with infinite scrolling support. The number of document handles returned per batch is customizable,
|
|
3867
|
+
* and additional batches can be loaded using the supplied `loadMore` function.
|
|
3868
|
+
*
|
|
3869
|
+
* @beta
|
|
3870
|
+
* @category Documents
|
|
3871
|
+
* @param options - Configuration options for the infinite list
|
|
3872
|
+
* @returns An object containing the list of document handles, the loading state, the total count of retrieved document handles, and a function to load more
|
|
3873
|
+
* @example
|
|
3874
|
+
* ```tsx
|
|
3875
|
+
* const {data, hasMore, isPending, loadMore} = useDocuments({
|
|
3876
|
+
* filter: '_type == "post"',
|
|
3877
|
+
* search: searchTerm,
|
|
3878
|
+
* batchSize: 10,
|
|
3879
|
+
* orderings: [{field: '_createdAt', direction: 'desc'}]
|
|
3880
|
+
* })
|
|
3881
|
+
*
|
|
3882
|
+
* return (
|
|
3883
|
+
* <div>
|
|
3884
|
+
* Total documents: {count}
|
|
3885
|
+
* <ol>
|
|
3886
|
+
* {data.map((doc) => (
|
|
3887
|
+
* <li key={doc._id}>
|
|
3888
|
+
* <MyDocumentComponent doc={doc} />
|
|
3889
|
+
* </li>
|
|
3890
|
+
* ))}
|
|
3891
|
+
* </ol>
|
|
3892
|
+
* {hasMore && <button onClick={loadMore}>Load More</button>}
|
|
3893
|
+
* </div>
|
|
3894
|
+
* )
|
|
3895
|
+
* ```
|
|
3896
|
+
*
|
|
3897
|
+
*/
|
|
3898
|
+
export declare function useDocuments({
|
|
3899
|
+
batchSize,
|
|
3900
|
+
params,
|
|
3901
|
+
search,
|
|
3902
|
+
filter,
|
|
3903
|
+
orderings,
|
|
3904
|
+
...options
|
|
3905
|
+
}: DocumentsOptions): DocumentsResponse
|
|
3906
|
+
|
|
3907
|
+
declare type UseDocumentSyncStatus = {
|
|
3908
|
+
/**
|
|
3909
|
+
* Exposes the document’s sync status between local and remote document states.
|
|
3910
|
+
*
|
|
3911
|
+
* @category Documents
|
|
3912
|
+
* @param doc - The document handle to get sync status for. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)
|
|
3913
|
+
* the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.
|
|
3914
|
+
* @returns `true` if local changes are synced with remote, `false` if the changes are not synced, and `undefined` if the document is not found
|
|
3915
|
+
* @example Disable a Save button when there are no changes to sync
|
|
3916
|
+
* ```
|
|
3917
|
+
* const myDocumentHandle = { _id: 'documentId', _type: 'documentType', resourceId: 'document:projectId:dataset:documentId' }
|
|
3918
|
+
* const documentSynced = useDocumentSyncStatus(myDocumentHandle)
|
|
3919
|
+
*
|
|
3920
|
+
* return (
|
|
3921
|
+
* <button disabled={documentSynced}>
|
|
3922
|
+
* Save Changes
|
|
3923
|
+
* </button>
|
|
3924
|
+
* )
|
|
3925
|
+
* ```
|
|
3926
|
+
*/
|
|
3927
|
+
(doc: DocumentHandle): boolean | undefined
|
|
3928
|
+
}
|
|
3929
|
+
|
|
3930
|
+
/**
|
|
3931
|
+
* @beta
|
|
3932
|
+
* @function
|
|
3933
|
+
*/
|
|
3934
|
+
export declare const useDocumentSyncStatus: UseDocumentSyncStatus
|
|
3935
|
+
|
|
3936
|
+
/**
|
|
3937
|
+
*
|
|
3938
|
+
* @beta
|
|
3939
|
+
*
|
|
3940
|
+
* ## useEditDocument(doc, path)
|
|
3941
|
+
* Edit a nested value within a document
|
|
3942
|
+
*
|
|
3943
|
+
* @category Documents
|
|
3944
|
+
* @param doc - The document to be edited; either as a document handle or the document’s ID a string
|
|
3945
|
+
* @param path - The path to the nested value to be edited
|
|
3946
|
+
* @returns A function to update the nested value. Accepts either a new value, or an updater function that exposes the previous value and returns a new value.
|
|
3947
|
+
* @example Update a document’s name by providing the new value directly
|
|
3948
|
+
* ```
|
|
3949
|
+
* const handle = { _id: 'documentId', _type: 'documentType' }
|
|
3950
|
+
* const name = useDocument(handle, 'name')
|
|
3951
|
+
* const editName = useEditDocument(handle, 'name')
|
|
3952
|
+
*
|
|
3953
|
+
* function handleNameChange(event: React.ChangeEvent<HTMLInputElement>) {
|
|
3954
|
+
* editName(event.target.value)
|
|
3955
|
+
* }
|
|
3956
|
+
*
|
|
3957
|
+
* return (
|
|
3958
|
+
* <input type='text' value={name} onChange={handleNameChange} />
|
|
3959
|
+
* )
|
|
3960
|
+
* ```
|
|
3961
|
+
*
|
|
3962
|
+
* @example Update a count on a document by providing an updater function
|
|
3963
|
+
* ```
|
|
3964
|
+
* const handle = { _id: 'documentId', _type: 'documentType' }
|
|
3965
|
+
* const count = useDocument(handle, 'count')
|
|
3966
|
+
* const editCount = useEditDocument(handle, 'count')
|
|
3967
|
+
*
|
|
3968
|
+
* function incrementCount() {
|
|
3969
|
+
* editCount(previousCount => previousCount + 1)
|
|
3970
|
+
* }
|
|
3971
|
+
*
|
|
3972
|
+
* return (
|
|
3973
|
+
* <>
|
|
3974
|
+
* <button onClick={incrementCount}>
|
|
3975
|
+
* Increment
|
|
3976
|
+
* </button>
|
|
3977
|
+
* Current count: {count}
|
|
3978
|
+
* </>
|
|
3979
|
+
* )
|
|
3980
|
+
* ```
|
|
3981
|
+
*/
|
|
3982
|
+
export declare function useEditDocument<
|
|
3983
|
+
TDocument extends SanityDocument,
|
|
3984
|
+
TPath extends JsonMatchPath<TDocument>,
|
|
3985
|
+
>(
|
|
3986
|
+
doc: DocumentHandle<TDocument>,
|
|
3987
|
+
path: TPath,
|
|
3988
|
+
): (nextValue: Updater<JsonMatch<TDocument, TPath>>) => Promise<ActionsResult<TDocument>>
|
|
3989
|
+
|
|
3990
|
+
/**
|
|
3991
|
+
*
|
|
3992
|
+
* @beta
|
|
3993
|
+
*
|
|
3994
|
+
* ## useEditDocument(doc)
|
|
3995
|
+
* Edit an entire document
|
|
3996
|
+
* @param doc - The document to be edited; either as a document handle or the document’s ID a string. If you pass a `DocumentHandle` with a `resourceId` (in the format of `document:projectId.dataset:documentId`)
|
|
3997
|
+
* the document will be read from the specified Sanity project and dataset that is included in the handle. If no `resourceId` is provided, the default project and dataset from your `SanityApp` configuration will be used.
|
|
3998
|
+
* @returns A function to update the document state. Accepts either a new document state, or an updater function that exposes the previous document state and returns the new document state.
|
|
3999
|
+
* @example
|
|
4000
|
+
* ```
|
|
4001
|
+
* const myDocumentHandle = { _id: 'documentId', _type: 'documentType' }
|
|
4002
|
+
*
|
|
4003
|
+
* const myDocument = useDocument(myDocumentHandle)
|
|
4004
|
+
* const { title, price } = myDocument
|
|
4005
|
+
*
|
|
4006
|
+
* const editMyDocument = useEditDocument(myDocumentHandle)
|
|
4007
|
+
*
|
|
4008
|
+
* function handleFieldChange(e: React.ChangeEvent<HTMLInputElement>) {
|
|
4009
|
+
* const {name, value} = e.currentTarget
|
|
4010
|
+
* // Use an updater function to update the document state based on the previous state
|
|
4011
|
+
* editMyDocument(previousDocument => ({
|
|
4012
|
+
* ...previousDocument,
|
|
4013
|
+
* [name]: value
|
|
4014
|
+
* }))
|
|
4015
|
+
* }
|
|
4016
|
+
*
|
|
4017
|
+
* function handleSaleChange(e: React.ChangeEvent<HTMLInputElement>) {
|
|
4018
|
+
* const { checked } = e.currentTarget
|
|
4019
|
+
* if (checked) {
|
|
4020
|
+
* // Use an updater function to add a new salePrice field;
|
|
4021
|
+
* // set it at a 20% discount off the normal price
|
|
4022
|
+
* editMyDocument(previousDocument => ({
|
|
4023
|
+
* ...previousDocument,
|
|
4024
|
+
* salePrice: previousDocument.price * 0.8,
|
|
4025
|
+
* }))
|
|
4026
|
+
* } else {
|
|
4027
|
+
* // Get the document state without the salePrice field
|
|
4028
|
+
* const { salePrice, ...rest } = myDocument
|
|
4029
|
+
* // Update the document state to remove the salePrice field
|
|
4030
|
+
* editMyDocument(rest)
|
|
4031
|
+
* }
|
|
4032
|
+
* }
|
|
4033
|
+
*
|
|
4034
|
+
* return (
|
|
4035
|
+
* <>
|
|
4036
|
+
* <form onSubmit={e => e.preventDefault()}>
|
|
4037
|
+
* <input name='title' type='text' value={title} onChange={handleFieldChange} />
|
|
4038
|
+
* <input name='price' type='number' value={price} onChange={handleFieldChange} />
|
|
4039
|
+
* <input
|
|
4040
|
+
* name='salePrice'
|
|
4041
|
+
* type='checkbox'
|
|
4042
|
+
* checked={Object(myDocument).hasOwnProperty('salePrice')}
|
|
4043
|
+
* onChange={handleSaleChange}
|
|
4044
|
+
* />
|
|
4045
|
+
* </form>
|
|
4046
|
+
* <pre><code>
|
|
4047
|
+
* {JSON.stringify(myDocument, null, 2)}
|
|
4048
|
+
* </code></pre>
|
|
4049
|
+
* </>
|
|
4050
|
+
* )
|
|
4051
|
+
* ```
|
|
4052
|
+
*/
|
|
4053
|
+
export declare function useEditDocument<TDocument extends SanityDocument>(
|
|
4054
|
+
doc: DocumentHandle<TDocument>,
|
|
4055
|
+
): (nextValue: Updater<TDocument>) => Promise<ActionsResult<TDocument>>
|
|
4056
|
+
|
|
4057
|
+
/**
|
|
4058
|
+
* @internal
|
|
4059
|
+
*/
|
|
4060
|
+
export declare function useFrameConnection<
|
|
4061
|
+
TFrameMessage extends FrameMessage,
|
|
4062
|
+
TWindowMessage extends WindowMessage,
|
|
4063
|
+
>(options: UseFrameConnectionOptions<TWindowMessage>): FrameConnection<TFrameMessage>
|
|
4064
|
+
|
|
4065
|
+
/**
|
|
4066
|
+
* @internal
|
|
4067
|
+
*/
|
|
4068
|
+
export declare interface UseFrameConnectionOptions<TWindowMessage extends WindowMessage> {
|
|
4069
|
+
name: string
|
|
4070
|
+
connectTo: string
|
|
4071
|
+
targetOrigin: string
|
|
4072
|
+
onMessage?: {
|
|
4073
|
+
[K in TWindowMessage['type']]: (
|
|
4074
|
+
data: Extract<
|
|
4075
|
+
TWindowMessage,
|
|
4076
|
+
{
|
|
4077
|
+
type: K
|
|
4078
|
+
}
|
|
4079
|
+
>['data'],
|
|
4080
|
+
) => void
|
|
4081
|
+
}
|
|
4082
|
+
heartbeat?: boolean
|
|
4083
|
+
onStatus?: (status: ComlinkStatus) => void
|
|
4084
|
+
}
|
|
4085
|
+
|
|
4086
|
+
/**
|
|
4087
|
+
* @internal
|
|
4088
|
+
* A React hook that returns a function for handling authentication callbacks.
|
|
4089
|
+
*
|
|
4090
|
+
* @remarks
|
|
4091
|
+
* This hook provides access to the authentication store's callback handler,
|
|
4092
|
+
* which processes auth redirects by extracting the session ID and fetching the
|
|
4093
|
+
* authentication token. If fetching the long-lived token is successful,
|
|
4094
|
+
* `handleAuthCallback` will return a Promise that resolves a new location that
|
|
4095
|
+
* removes the short-lived token from the URL. Use this in combination with
|
|
4096
|
+
* `history.replaceState` or your own router's `replace` function to update the
|
|
4097
|
+
* current location without triggering a reload.
|
|
4098
|
+
*
|
|
4099
|
+
* @example
|
|
4100
|
+
* ```tsx
|
|
4101
|
+
* function AuthCallback() {
|
|
4102
|
+
* const handleAuthCallback = useHandleAuthCallback()
|
|
4103
|
+
* const router = useRouter() // Example router
|
|
4104
|
+
*
|
|
4105
|
+
* useEffect(() => {
|
|
4106
|
+
* async function processCallback() {
|
|
4107
|
+
* // Handle the callback and get the cleaned URL
|
|
4108
|
+
* const newUrl = await handleAuthCallback(window.location.href)
|
|
4109
|
+
*
|
|
4110
|
+
* if (newUrl) {
|
|
4111
|
+
* // Replace URL without triggering navigation
|
|
4112
|
+
* router.replace(newUrl, {shallow: true})
|
|
4113
|
+
* }
|
|
4114
|
+
* }
|
|
4115
|
+
*
|
|
4116
|
+
* processCallback().catch(console.error)
|
|
4117
|
+
* }, [handleAuthCallback, router])
|
|
4118
|
+
*
|
|
4119
|
+
* return <div>Completing login...</div>
|
|
4120
|
+
* }
|
|
4121
|
+
* ```
|
|
4122
|
+
*
|
|
4123
|
+
* @returns A callback handler function that processes OAuth redirects
|
|
4124
|
+
* @public
|
|
4125
|
+
*/
|
|
4126
|
+
export declare const useHandleAuthCallback: () => (
|
|
4127
|
+
locationHref?: string | undefined,
|
|
4128
|
+
) => Promise<string | false>
|
|
4129
|
+
|
|
4130
|
+
/**
|
|
4131
|
+
* @internal
|
|
4132
|
+
* A React hook that retrieves the available authentication provider URLs for login.
|
|
4133
|
+
*
|
|
4134
|
+
* @remarks
|
|
4135
|
+
* This hook fetches the login URLs from the Sanity auth store when the component mounts.
|
|
4136
|
+
* Each provider object contains information about an authentication method, including its URL.
|
|
4137
|
+
* The hook will suspend if the login URLs have not yet loaded.
|
|
4138
|
+
*
|
|
4139
|
+
* @example
|
|
4140
|
+
* ```tsx
|
|
4141
|
+
* // LoginProviders component that uses the hook
|
|
4142
|
+
* function LoginProviders() {
|
|
4143
|
+
* const providers = useLoginUrls()
|
|
4144
|
+
*
|
|
4145
|
+
* return (
|
|
4146
|
+
* <div>
|
|
4147
|
+
* {providers.map((provider) => (
|
|
4148
|
+
* <a key={provider.name} href={provider.url}>
|
|
4149
|
+
* Login with {provider.title}
|
|
4150
|
+
* </a>
|
|
4151
|
+
* ))}
|
|
4152
|
+
* </div>
|
|
4153
|
+
* )
|
|
4154
|
+
* }
|
|
4155
|
+
*
|
|
4156
|
+
* // Parent component with Suspense boundary
|
|
4157
|
+
* function LoginPage() {
|
|
4158
|
+
* return (
|
|
4159
|
+
* <Suspense fallback={<div>Loading authentication providers...</div>}>
|
|
4160
|
+
* <LoginProviders />
|
|
4161
|
+
* </Suspense>
|
|
4162
|
+
* )
|
|
4163
|
+
* }
|
|
4164
|
+
* ```
|
|
4165
|
+
*
|
|
4166
|
+
* @returns An array of {@link AuthProvider} objects containing login URLs and provider information
|
|
4167
|
+
* @public
|
|
4168
|
+
*/
|
|
4169
|
+
export declare function useLoginUrls(): AuthProvider[]
|
|
4170
|
+
|
|
4171
|
+
/**
|
|
4172
|
+
* Hook to log out of the current session
|
|
4173
|
+
* @internal
|
|
4174
|
+
* @returns A function to log out of the current session
|
|
4175
|
+
*/
|
|
4176
|
+
export declare const useLogOut: () => () => Promise<void>
|
|
4177
|
+
|
|
4178
|
+
/**
|
|
4179
|
+
* @beta
|
|
4180
|
+
*
|
|
4181
|
+
* ## useManageFavorite
|
|
4182
|
+
* This hook provides functionality to add and remove documents from favorites,
|
|
4183
|
+
* and tracks the current favorite status of the document.
|
|
4184
|
+
* @category Dashboard Communication
|
|
4185
|
+
* @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
|
|
4186
|
+
* @returns An object containing:
|
|
4187
|
+
* - `favorite` - Function to add document to favorites
|
|
4188
|
+
* - `unfavorite` - Function to remove document from favorites
|
|
4189
|
+
* - `isFavorited` - Boolean indicating if document is currently favorited
|
|
4190
|
+
* - `isConnected` - Boolean indicating if connection to Dashboard UI is established
|
|
4191
|
+
*
|
|
4192
|
+
* @example
|
|
4193
|
+
* ```tsx
|
|
4194
|
+
* function MyDocumentAction(props: DocumentActionProps) {
|
|
4195
|
+
* const {documentId, documentType} = props
|
|
4196
|
+
* const {favorite, unfavorite, isFavorited, isConnected} = useManageFavorite({
|
|
4197
|
+
* documentId,
|
|
4198
|
+
* documentType
|
|
4199
|
+
* })
|
|
4200
|
+
*
|
|
4201
|
+
* return (
|
|
4202
|
+
* <Button
|
|
4203
|
+
* disabled={!isConnected}
|
|
4204
|
+
* onClick={() => isFavorited ? unfavorite() : favorite()}
|
|
4205
|
+
* text={isFavorited ? 'Remove from favorites' : 'Add to favorites'}
|
|
4206
|
+
* />
|
|
4207
|
+
* )
|
|
4208
|
+
* }
|
|
4209
|
+
* ```
|
|
4210
|
+
*/
|
|
4211
|
+
export declare function useManageFavorite({
|
|
4212
|
+
documentId,
|
|
4213
|
+
documentType,
|
|
4214
|
+
resourceId,
|
|
4215
|
+
resourceType,
|
|
4216
|
+
}: UseManageFavoriteProps): ManageFavorite
|
|
4217
|
+
|
|
4218
|
+
declare interface UseManageFavoriteProps {
|
|
4219
|
+
documentId: string
|
|
4220
|
+
documentType: string
|
|
4221
|
+
resourceId?: string
|
|
4222
|
+
resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
|
|
4223
|
+
}
|
|
4224
|
+
|
|
4225
|
+
/**
|
|
4226
|
+
* @public
|
|
4227
|
+
* Hook that provides a function to navigate to a studio document.
|
|
4228
|
+
* Currently, requires a document handle with a resourceId.
|
|
4229
|
+
* That resourceId is currently formatted like: `document:projectId.dataset:documentId`
|
|
4230
|
+
* If the hook you used to retrieve the document handle doesn't provide a resourceId like this,
|
|
4231
|
+
* you can construct it according to the above format with the document handle's _id.
|
|
4232
|
+
*
|
|
4233
|
+
* This will only work if you have deployed a studio with a workspace
|
|
4234
|
+
* with this projectId / dataset combination.
|
|
4235
|
+
* It may be able to take a custom URL in the future.
|
|
4236
|
+
*
|
|
4237
|
+
* This will likely change in the future.
|
|
4238
|
+
* @param documentHandle - The document handle containing document ID, type, and resource ID
|
|
4239
|
+
* @returns An object containing:
|
|
4240
|
+
* - navigateToStudioDocument - Function that when called will navigate to the studio document
|
|
4241
|
+
* - isConnected - Boolean indicating if connection to Dashboard is established
|
|
4242
|
+
*
|
|
4243
|
+
* @example
|
|
4244
|
+
* ```ts
|
|
4245
|
+
* import {navigateToStudioDocument, type DocumentHandle} from '@sanity/sdk'
|
|
4246
|
+
*
|
|
4247
|
+
* function MyComponent({documentHandle}: {documentHandle: DocumentHandle}) {
|
|
4248
|
+
* const {navigateToStudioDocument, isConnected} = useNavigateToStudioDocument(documentHandle)
|
|
4249
|
+
*
|
|
4250
|
+
* return (
|
|
4251
|
+
* <button onClick={navigateToStudioDocument} disabled={!isConnected}>
|
|
4252
|
+
* Navigate to Studio Document
|
|
4253
|
+
* </button>
|
|
4254
|
+
* )
|
|
4255
|
+
* }
|
|
4256
|
+
* ```
|
|
4257
|
+
*/
|
|
4258
|
+
export declare function useNavigateToStudioDocument(
|
|
4259
|
+
documentHandle: DocumentHandle,
|
|
4260
|
+
): NavigateToStudioResult
|
|
4261
|
+
|
|
4262
|
+
/**
|
|
4263
|
+
* Retrieves pages of {@link DocumentHandle}s, narrowed by optional filters, text searches, and custom ordering,
|
|
4264
|
+
* with support for traditional paginated interfaces. The number of document handles returned per page is customizable,
|
|
4265
|
+
* while page navigation is handled via the included navigation functions.
|
|
4266
|
+
*
|
|
4267
|
+
* @beta
|
|
4268
|
+
* @category Documents
|
|
4269
|
+
* @param options - Configuration options for the paginated list
|
|
4270
|
+
* @returns An object containing the current page of document handles, the loading and pagination state, and navigation functions
|
|
4271
|
+
* @example
|
|
4272
|
+
* ```tsx
|
|
4273
|
+
* const {
|
|
4274
|
+
* data,
|
|
4275
|
+
* isPending,
|
|
4276
|
+
* currentPage,
|
|
4277
|
+
* totalPages,
|
|
4278
|
+
* nextPage,
|
|
4279
|
+
* previousPage,
|
|
4280
|
+
* hasNextPage,
|
|
4281
|
+
* hasPreviousPage
|
|
4282
|
+
* } = usePaginatedDocuments({
|
|
4283
|
+
* filter: '_type == "post"',
|
|
4284
|
+
* search: searchTerm,
|
|
4285
|
+
* pageSize: 10,
|
|
4286
|
+
* orderings: [{field: '_createdAt', direction: 'desc'}]
|
|
4287
|
+
* })
|
|
4288
|
+
*
|
|
4289
|
+
* return (
|
|
4290
|
+
* <>
|
|
4291
|
+
* <table>
|
|
4292
|
+
* {data.map(doc => (
|
|
4293
|
+
* <MyTableRowComponent key={doc._id} doc={doc} />
|
|
4294
|
+
* ))}
|
|
4295
|
+
* </table>
|
|
4296
|
+
* <>
|
|
4297
|
+
* {hasPreviousPage && <button onClick={previousPage}>Previous</button>}
|
|
4298
|
+
* {currentPage} / {totalPages}
|
|
4299
|
+
* {hasNextPage && <button onClick={nextPage}>Next</button>}
|
|
4300
|
+
* </>
|
|
4301
|
+
* </>
|
|
4302
|
+
* )
|
|
4303
|
+
* ```
|
|
4304
|
+
*
|
|
4305
|
+
*/
|
|
4306
|
+
export declare function usePaginatedDocuments({
|
|
4307
|
+
filter,
|
|
4308
|
+
pageSize,
|
|
4309
|
+
params,
|
|
4310
|
+
orderings,
|
|
4311
|
+
search,
|
|
4312
|
+
...options
|
|
4313
|
+
}?: PaginatedDocumentsOptions): PaginatedDocumentsResponse
|
|
4314
|
+
|
|
4315
|
+
/**
|
|
4316
|
+
* @beta
|
|
4317
|
+
*
|
|
4318
|
+
* Returns the preview values of a document (specified via a `DocumentHandle`),
|
|
4319
|
+
* including the document’s `title`, `subtitle`, `media`, and `status`. These values are live and will update in realtime.
|
|
4320
|
+
* To reduce unnecessary network requests for resolving the preview values, an optional `ref` can be passed to the hook so that preview
|
|
4321
|
+
* resolution will only occur if the `ref` is intersecting the current viewport.
|
|
4322
|
+
*
|
|
4323
|
+
* @category Documents
|
|
4324
|
+
* @param options - The document handle for the document you want to resolve preview values for, and an optional ref
|
|
4325
|
+
* @returns The preview values for the given document and a boolean to indicate whether the resolution is pending
|
|
4326
|
+
*
|
|
4327
|
+
* @example Combining with useDocuments to render a collection of document previews
|
|
4328
|
+
* ```
|
|
4329
|
+
* // PreviewComponent.jsx
|
|
4330
|
+
* export default function PreviewComponent({ document }) {
|
|
4331
|
+
* const { data: { title, subtitle, media }, isPending } = usePreview({ document })
|
|
4332
|
+
* return (
|
|
4333
|
+
* <article style={{ opacity: isPending ? 0.5 : 1}}>
|
|
4334
|
+
* {media?.type === 'image-asset' ? <img src={media.url} alt='' /> : ''}
|
|
4335
|
+
* <h2>{title}</h2>
|
|
4336
|
+
* <p>{subtitle}</p>
|
|
4337
|
+
* </article>
|
|
4338
|
+
* )
|
|
4339
|
+
* }
|
|
4340
|
+
*
|
|
4341
|
+
* // DocumentList.jsx
|
|
4342
|
+
* const { data } = useDocuments({ filter: '_type == "movie"' })
|
|
4343
|
+
* return (
|
|
4344
|
+
* <div>
|
|
4345
|
+
* <h1>Movies</h1>
|
|
4346
|
+
* <ul>
|
|
4347
|
+
* {data.map(movie => (
|
|
4348
|
+
* <li key={movie._id}>
|
|
4349
|
+
* <Suspense fallback='Loading…'>
|
|
4350
|
+
* <PreviewComponent document={movie} />
|
|
4351
|
+
* </Suspense>
|
|
4352
|
+
* </li>
|
|
4353
|
+
* ))}
|
|
4354
|
+
* </ul>
|
|
4355
|
+
* </div>
|
|
4356
|
+
* )
|
|
4357
|
+
* ```
|
|
4358
|
+
*/
|
|
4359
|
+
export declare function usePreview({
|
|
4360
|
+
document: {_id, _type},
|
|
4361
|
+
ref,
|
|
4362
|
+
}: UsePreviewOptions): UsePreviewResults
|
|
4363
|
+
|
|
4364
|
+
/**
|
|
4365
|
+
* @beta
|
|
4366
|
+
* @category Types
|
|
4367
|
+
*/
|
|
4368
|
+
export declare interface UsePreviewOptions {
|
|
4369
|
+
document: DocumentHandle
|
|
4370
|
+
ref?: React.RefObject<unknown>
|
|
4371
|
+
}
|
|
4372
|
+
|
|
4373
|
+
/**
|
|
4374
|
+
* @beta
|
|
4375
|
+
* @category Types
|
|
4376
|
+
*/
|
|
4377
|
+
export declare interface UsePreviewResults {
|
|
4378
|
+
/** The results of resolving the document’s preview values */
|
|
4379
|
+
data: PreviewValue
|
|
4380
|
+
/** True when preview values are being refreshed */
|
|
4381
|
+
isPending: boolean
|
|
4382
|
+
}
|
|
4383
|
+
|
|
4384
|
+
declare type UseProject = {
|
|
4385
|
+
/**
|
|
4386
|
+
*
|
|
4387
|
+
* Returns metadata for a given project
|
|
4388
|
+
*
|
|
4389
|
+
* @category Projects
|
|
4390
|
+
* @param projectId - The ID of the project to retrieve metadata for
|
|
4391
|
+
* @returns The metadata for the project
|
|
4392
|
+
* @example
|
|
4393
|
+
* ```tsx
|
|
4394
|
+
* function ProjectMetadata({ projectId }: { projectId: string }) {
|
|
4395
|
+
* const project = useProject(projectId)
|
|
4396
|
+
*
|
|
4397
|
+
* return (
|
|
4398
|
+
* <figure style={{ backgroundColor: project.metadata.color || 'lavender'}}>
|
|
4399
|
+
* <h1>{project.displayName}</h1>
|
|
4400
|
+
* </figure>
|
|
4401
|
+
* )
|
|
4402
|
+
* }
|
|
4403
|
+
* ```
|
|
4404
|
+
*/
|
|
4405
|
+
(projectId: string): SanityProject_2
|
|
4406
|
+
}
|
|
4407
|
+
|
|
4408
|
+
/**
|
|
4409
|
+
* @public
|
|
4410
|
+
* @function
|
|
4411
|
+
*/
|
|
4412
|
+
export declare const useProject: UseProject
|
|
4413
|
+
|
|
4414
|
+
/**
|
|
4415
|
+
* @beta
|
|
4416
|
+
*
|
|
4417
|
+
* Returns the projection values of a document (specified via a `DocumentHandle`),
|
|
4418
|
+
* based on the provided projection string. These values are live and will update in realtime.
|
|
4419
|
+
* To reduce unnecessary network requests for resolving the projection values, an optional `ref` can be passed to the hook so that projection
|
|
4420
|
+
* resolution will only occur if the `ref` is intersecting the current viewport.
|
|
4421
|
+
*
|
|
4422
|
+
* @category Documents
|
|
4423
|
+
* @param options - The document handle for the document you want to project values from, the projection string, and an optional ref
|
|
4424
|
+
* @returns The projection values for the given document and a boolean to indicate whether the resolution is pending
|
|
4425
|
+
*
|
|
4426
|
+
* @example Using a projection to render a preview of document
|
|
4427
|
+
* ```
|
|
4428
|
+
* // ProjectionComponent.jsx
|
|
4429
|
+
* export default function ProjectionComponent({ document }) {
|
|
4430
|
+
* const ref = useRef(null)
|
|
4431
|
+
* const { results: { title, coverImage, authors }, isPending } = useProjection({
|
|
4432
|
+
* document,
|
|
4433
|
+
* ref,
|
|
4434
|
+
* projection: `{
|
|
4435
|
+
* title,
|
|
4436
|
+
* 'coverImage': cover.asset->url,
|
|
4437
|
+
* 'authors': array::join(authors[]->{'name': firstName + ' ' + lastName + ' '}.name, ', ')
|
|
4438
|
+
* }`,
|
|
4439
|
+
* })
|
|
4440
|
+
*
|
|
4441
|
+
* return (
|
|
4442
|
+
* <article ref={ref} style={{ opacity: isPending ? 0.5 : 1}}>
|
|
4443
|
+
* <h2>{title}</h2>
|
|
4444
|
+
* <img src={coverImage} alt={title} />
|
|
4445
|
+
* <p>{authors}</p>
|
|
4446
|
+
* </article>
|
|
4447
|
+
* )
|
|
4448
|
+
* }
|
|
4449
|
+
* ```
|
|
4450
|
+
*
|
|
4451
|
+
* @example Combining with useDocuments to render a collection with specific fields
|
|
4452
|
+
* ```
|
|
4453
|
+
* // DocumentList.jsx
|
|
4454
|
+
* const { data } = useDocuments({ filter: '_type == "article"' })
|
|
4455
|
+
* return (
|
|
4456
|
+
* <div>
|
|
4457
|
+
* <h1>Books</h1>
|
|
4458
|
+
* <ul>
|
|
4459
|
+
* {data.map(book => (
|
|
4460
|
+
* <li key={book._id}>
|
|
4461
|
+
* <Suspense fallback='Loading…'>
|
|
4462
|
+
* <ProjectionComponent
|
|
4463
|
+
* document={book}
|
|
4464
|
+
* />
|
|
4465
|
+
* </Suspense>
|
|
4466
|
+
* </li>
|
|
4467
|
+
* ))}
|
|
4468
|
+
* </ul>
|
|
4469
|
+
* </div>
|
|
4470
|
+
* )
|
|
4471
|
+
* ```
|
|
4472
|
+
*/
|
|
4473
|
+
export declare function useProjection<TResult extends object>({
|
|
4474
|
+
document: {_id, _type},
|
|
4475
|
+
projection,
|
|
4476
|
+
ref,
|
|
4477
|
+
}: UseProjectionOptions): UseProjectionResults<TResult>
|
|
4478
|
+
|
|
4479
|
+
/**
|
|
4480
|
+
* @public
|
|
4481
|
+
* @category Types
|
|
4482
|
+
*/
|
|
4483
|
+
export declare interface UseProjectionOptions {
|
|
4484
|
+
document: DocumentHandle
|
|
4485
|
+
projection: ValidProjection
|
|
4486
|
+
ref?: React.RefObject<unknown>
|
|
4487
|
+
}
|
|
4488
|
+
|
|
1
4489
|
/**
|
|
2
|
-
* An example function that will be removed.
|
|
3
4490
|
* @public
|
|
4491
|
+
* @category Types
|
|
4
4492
|
*/
|
|
5
|
-
export declare
|
|
4493
|
+
export declare interface UseProjectionResults<TResult extends object> {
|
|
4494
|
+
data: TResult
|
|
4495
|
+
isPending: boolean
|
|
4496
|
+
}
|
|
4497
|
+
|
|
4498
|
+
declare type UseProjects = {
|
|
4499
|
+
/**
|
|
4500
|
+
*
|
|
4501
|
+
* Returns metadata for each project you have access to.
|
|
4502
|
+
*
|
|
4503
|
+
* @category Projects
|
|
4504
|
+
* @returns An array of metadata (minus the projects’ members) for each project
|
|
4505
|
+
* @example
|
|
4506
|
+
* ```tsx
|
|
4507
|
+
* const projects = useProjects()
|
|
4508
|
+
*
|
|
4509
|
+
* return (
|
|
4510
|
+
* <select>
|
|
4511
|
+
* {projects.map((project) => (
|
|
4512
|
+
* <option key={project.id}>{project.displayName}</option>
|
|
4513
|
+
* ))}
|
|
4514
|
+
* </select>
|
|
4515
|
+
* )
|
|
4516
|
+
* ```
|
|
4517
|
+
*/
|
|
4518
|
+
(): ProjectWithoutMembers[]
|
|
4519
|
+
}
|
|
4520
|
+
|
|
4521
|
+
/**
|
|
4522
|
+
* @public
|
|
4523
|
+
* @function
|
|
4524
|
+
*/
|
|
4525
|
+
export declare const useProjects: UseProjects
|
|
4526
|
+
|
|
4527
|
+
/**
|
|
4528
|
+
* Executes GROQ queries against a Sanity dataset.
|
|
4529
|
+
*
|
|
4530
|
+
* This hook provides a convenient way to fetch and subscribe to real-time updates
|
|
4531
|
+
* for your Sanity content. Changes made to the dataset’s content will trigger
|
|
4532
|
+
* automatic updates.
|
|
4533
|
+
*
|
|
4534
|
+
* @remarks
|
|
4535
|
+
* The returned `isPending` flag indicates when a React transition is in progress,
|
|
4536
|
+
* which can be used to show loading states for query changes.
|
|
4537
|
+
*
|
|
4538
|
+
* @beta
|
|
4539
|
+
* @category GROQ
|
|
4540
|
+
* @param query - GROQ query string to execute
|
|
4541
|
+
* @param options - Optional configuration for the query
|
|
4542
|
+
* @returns Object containing the query result and a pending state flag
|
|
4543
|
+
*
|
|
4544
|
+
* @example Basic usage
|
|
4545
|
+
* ```tsx
|
|
4546
|
+
* const {data, isPending} = useQuery<Movie[]>('*[_type == "movie"]')
|
|
4547
|
+
* ```
|
|
4548
|
+
*
|
|
4549
|
+
* @example Using parameters
|
|
4550
|
+
* ```tsx
|
|
4551
|
+
* // With parameters
|
|
4552
|
+
* const {data} = useQuery<Movie>('*[_type == "movie" && _id == $id][0]', {
|
|
4553
|
+
* params: { id: 'movie-123' }
|
|
4554
|
+
* })
|
|
4555
|
+
* ```
|
|
4556
|
+
*
|
|
4557
|
+
* @example With a loading state for transitions
|
|
4558
|
+
* ```tsx
|
|
4559
|
+
* const {data, isPending} = useQuery<Movie[]>('*[_type == "movie"]')
|
|
4560
|
+
* return (
|
|
4561
|
+
* <div>
|
|
4562
|
+
* {isPending && <div>Updating...</div>}
|
|
4563
|
+
* <ul>
|
|
4564
|
+
* {data.map(movie => <li key={movie._id}>{movie.title}</li>)}
|
|
4565
|
+
* </ul>
|
|
4566
|
+
* </div>
|
|
4567
|
+
* )
|
|
4568
|
+
* ```
|
|
4569
|
+
*
|
|
4570
|
+
*/
|
|
4571
|
+
export declare function useQuery<T>(
|
|
4572
|
+
query: string,
|
|
4573
|
+
options?: QueryOptions,
|
|
4574
|
+
): {
|
|
4575
|
+
data: T
|
|
4576
|
+
isPending: boolean
|
|
4577
|
+
}
|
|
4578
|
+
|
|
4579
|
+
/**
|
|
4580
|
+
* @public
|
|
4581
|
+
* Hook for managing document interaction history in Sanity Studio.
|
|
4582
|
+
* This hook provides functionality to record document interactions.
|
|
4583
|
+
* @category History
|
|
4584
|
+
* @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
|
|
4585
|
+
* @returns An object containing:
|
|
4586
|
+
* - `recordEvent` - Function to record document interactions
|
|
4587
|
+
* - `isConnected` - Boolean indicating if connection to Studio is established
|
|
4588
|
+
*
|
|
4589
|
+
* @example
|
|
4590
|
+
* ```tsx
|
|
4591
|
+
* function MyDocumentAction(props: DocumentActionProps) {
|
|
4592
|
+
* const {documentId, documentType, resourceType, resourceId} = props
|
|
4593
|
+
* const {recordEvent, isConnected} = useRecordDocumentHistoryEvent({
|
|
4594
|
+
* documentId,
|
|
4595
|
+
* documentType,
|
|
4596
|
+
* resourceType,
|
|
4597
|
+
* resourceId,
|
|
4598
|
+
* })
|
|
4599
|
+
*
|
|
4600
|
+
* return (
|
|
4601
|
+
* <Button
|
|
4602
|
+
* disabled={!isConnected}
|
|
4603
|
+
* onClick={() => recordEvent('viewed')}
|
|
4604
|
+
* text={'Viewed'}
|
|
4605
|
+
* />
|
|
4606
|
+
* )
|
|
4607
|
+
* }
|
|
4608
|
+
* ```
|
|
4609
|
+
*/
|
|
4610
|
+
export declare function useRecordDocumentHistoryEvent({
|
|
4611
|
+
documentId,
|
|
4612
|
+
documentType,
|
|
4613
|
+
resourceType,
|
|
4614
|
+
resourceId,
|
|
4615
|
+
}: UseRecordDocumentHistoryEventProps): DocumentInteractionHistory
|
|
4616
|
+
|
|
4617
|
+
/**
|
|
4618
|
+
* @public
|
|
4619
|
+
*/
|
|
4620
|
+
declare interface UseRecordDocumentHistoryEventProps {
|
|
4621
|
+
documentId: string
|
|
4622
|
+
documentType: string
|
|
4623
|
+
resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
|
|
4624
|
+
resourceId?: string
|
|
4625
|
+
}
|
|
4626
|
+
|
|
4627
|
+
/** @public */
|
|
4628
|
+
declare class UsersClient {
|
|
4629
|
+
#private
|
|
4630
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
4631
|
+
/**
|
|
4632
|
+
* Fetch a user by user ID
|
|
4633
|
+
*
|
|
4634
|
+
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
4635
|
+
*/
|
|
4636
|
+
getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
4637
|
+
}
|
|
4638
|
+
|
|
4639
|
+
/**
|
|
4640
|
+
* `useSanityInstance` returns the current Sanity instance from the application context.
|
|
4641
|
+
* This must be called from within a `SanityProvider` component.
|
|
4642
|
+
* @internal
|
|
4643
|
+
*
|
|
4644
|
+
* @param resourceId - The resourceId of the Sanity instance to return (optional)
|
|
4645
|
+
* @returns The current Sanity instance
|
|
4646
|
+
* @example
|
|
4647
|
+
* ```tsx
|
|
4648
|
+
* const instance = useSanityInstance('abc123.production')
|
|
4649
|
+
* ```
|
|
4650
|
+
*/
|
|
4651
|
+
export declare const useSanityInstance: (resourceId?: string) => SanityInstance
|
|
4652
|
+
|
|
4653
|
+
/**
|
|
4654
|
+
* Hook that fetches studio workspaces and organizes them by projectId:dataset
|
|
4655
|
+
* @internal
|
|
4656
|
+
*/
|
|
4657
|
+
export declare function useStudioWorkspacesByResourceId(): StudioWorkspacesResult
|
|
4658
|
+
|
|
4659
|
+
/**
|
|
4660
|
+
*
|
|
4661
|
+
* @public
|
|
4662
|
+
*
|
|
4663
|
+
* Retrieves the users for a given resource (either a project or an organization).
|
|
4664
|
+
*
|
|
4665
|
+
* @category Users
|
|
4666
|
+
* @param params - The resource type and its ID, and the limit of users to fetch
|
|
4667
|
+
* @returns A list of users, a boolean indicating whether there are more users to fetch, and a function to load more users
|
|
4668
|
+
*
|
|
4669
|
+
* @example
|
|
4670
|
+
* ```
|
|
4671
|
+
* const { users, hasMore, loadMore } = useUsers({
|
|
4672
|
+
* resourceType: 'organization',
|
|
4673
|
+
* resourceId: 'my-org-id',
|
|
4674
|
+
* limit: 10,
|
|
4675
|
+
* })
|
|
4676
|
+
*
|
|
4677
|
+
* return (
|
|
4678
|
+
* <div>
|
|
4679
|
+
* {users.map(user => (
|
|
4680
|
+
* <figure key={user.sanityUserId}>
|
|
4681
|
+
* <img src={user.profile.imageUrl} alt='' />
|
|
4682
|
+
* <figcaption>{user.profile.displayName}</figcaption>
|
|
4683
|
+
* <address>{user.profile.email}</address>
|
|
4684
|
+
* </figure>
|
|
4685
|
+
* ))}
|
|
4686
|
+
* {hasMore && <button onClick={loadMore}>Load More</button>}
|
|
4687
|
+
* </div>
|
|
4688
|
+
* )
|
|
4689
|
+
* ```
|
|
4690
|
+
*/
|
|
4691
|
+
export declare function useUsers(params: UseUsersParams): UseUsersResult
|
|
4692
|
+
|
|
4693
|
+
/**
|
|
4694
|
+
* @public
|
|
4695
|
+
* @category Types
|
|
4696
|
+
*/
|
|
4697
|
+
export declare interface UseUsersParams {
|
|
4698
|
+
/**
|
|
4699
|
+
* The type of resource to fetch users for.
|
|
4700
|
+
*/
|
|
4701
|
+
resourceType: ResourceType
|
|
4702
|
+
/**
|
|
4703
|
+
* The ID of the resource to fetch users for.
|
|
4704
|
+
*/
|
|
4705
|
+
resourceId: string
|
|
4706
|
+
/**
|
|
4707
|
+
* The limit of users to fetch.
|
|
4708
|
+
*/
|
|
4709
|
+
limit?: number
|
|
4710
|
+
}
|
|
4711
|
+
|
|
4712
|
+
/**
|
|
4713
|
+
* @public
|
|
4714
|
+
* @category Types
|
|
4715
|
+
*/
|
|
4716
|
+
export declare interface UseUsersResult {
|
|
4717
|
+
/**
|
|
4718
|
+
* The users fetched.
|
|
4719
|
+
*/
|
|
4720
|
+
users: SanityUser_2[]
|
|
4721
|
+
/**
|
|
4722
|
+
* Whether there are more users to fetch.
|
|
4723
|
+
*/
|
|
4724
|
+
hasMore: boolean
|
|
4725
|
+
/**
|
|
4726
|
+
* Load more users.
|
|
4727
|
+
*/
|
|
4728
|
+
loadMore: () => void
|
|
4729
|
+
}
|
|
4730
|
+
|
|
4731
|
+
/**
|
|
4732
|
+
* @internal
|
|
4733
|
+
* Hook to wrap a Comlink node in a React hook.
|
|
4734
|
+
* Our store functionality takes care of the lifecycle of the node,
|
|
4735
|
+
* as well as sharing a single node between invocations if they share the same name.
|
|
4736
|
+
*
|
|
4737
|
+
* Generally not to be used directly, but to be used as a dependency of
|
|
4738
|
+
* Comlink-powered hooks like `useManageFavorite`.
|
|
4739
|
+
*/
|
|
4740
|
+
export declare function useWindowConnection<
|
|
4741
|
+
TWindowMessage extends WindowMessage,
|
|
4742
|
+
TFrameMessage extends FrameMessage,
|
|
4743
|
+
>({
|
|
4744
|
+
name,
|
|
4745
|
+
connectTo,
|
|
4746
|
+
onMessage,
|
|
4747
|
+
onStatus,
|
|
4748
|
+
}: UseWindowConnectionOptions<TFrameMessage>): WindowConnection<TWindowMessage>
|
|
4749
|
+
|
|
4750
|
+
/**
|
|
4751
|
+
* @internal
|
|
4752
|
+
*/
|
|
4753
|
+
export declare interface UseWindowConnectionOptions<TMessage extends FrameMessage> {
|
|
4754
|
+
name: string
|
|
4755
|
+
connectTo: string
|
|
4756
|
+
onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>
|
|
4757
|
+
onStatus?: (status: ComlinkStatus) => void
|
|
4758
|
+
}
|
|
4759
|
+
|
|
4760
|
+
/**
|
|
4761
|
+
* The listener has been established, and will start receiving events.
|
|
4762
|
+
* Note that this is also emitted upon _reconnection_.
|
|
4763
|
+
*
|
|
4764
|
+
* @public
|
|
4765
|
+
*/
|
|
4766
|
+
declare type WelcomeEvent = {
|
|
4767
|
+
type: 'welcome'
|
|
4768
|
+
listenerName: string
|
|
4769
|
+
}
|
|
4770
|
+
|
|
4771
|
+
/**
|
|
4772
|
+
* @internal
|
|
4773
|
+
*/
|
|
4774
|
+
export declare interface WindowConnection<TMessage extends WindowMessage> {
|
|
4775
|
+
sendMessage: <TType extends TMessage['type']>(
|
|
4776
|
+
type: TType,
|
|
4777
|
+
data?: Extract<
|
|
4778
|
+
TMessage,
|
|
4779
|
+
{
|
|
4780
|
+
type: TType
|
|
4781
|
+
}
|
|
4782
|
+
>['data'],
|
|
4783
|
+
) => void
|
|
4784
|
+
fetch: <TResponse>(
|
|
4785
|
+
type: string,
|
|
4786
|
+
data?: MessageData,
|
|
4787
|
+
options?: {
|
|
4788
|
+
signal?: AbortSignal
|
|
4789
|
+
suppressWarnings?: boolean
|
|
4790
|
+
responseTimeout?: number
|
|
4791
|
+
},
|
|
4792
|
+
) => Promise<TResponse>
|
|
4793
|
+
}
|
|
4794
|
+
|
|
4795
|
+
/**
|
|
4796
|
+
* @internal
|
|
4797
|
+
*/
|
|
4798
|
+
export declare type WindowMessageHandler<TFrameMessage extends FrameMessage> = (
|
|
4799
|
+
event: TFrameMessage['data'],
|
|
4800
|
+
) => TFrameMessage['response']
|
|
4801
|
+
|
|
4802
|
+
declare interface Workspace {
|
|
4803
|
+
name: string
|
|
4804
|
+
title: string
|
|
4805
|
+
basePath: string
|
|
4806
|
+
dataset: string
|
|
4807
|
+
userApplicationId: string
|
|
4808
|
+
url: string
|
|
4809
|
+
_ref: string
|
|
4810
|
+
}
|
|
4811
|
+
|
|
4812
|
+
declare interface WorkspacesByResourceId {
|
|
4813
|
+
[key: string]: Workspace[]
|
|
4814
|
+
}
|
|
6
4815
|
|
|
7
4816
|
export {}
|