@sanity/sdk-react 0.0.0-chore-react-18-compat.1 → 0.0.0-chore-react-18-compat.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/index.d.ts +610 -3560
  2. package/dist/index.js +422 -474
  3. package/dist/index.js.map +1 -1
  4. package/package.json +21 -20
  5. package/src/_exports/index.ts +9 -7
  6. package/src/components/SDKProvider.test.tsx +78 -54
  7. package/src/components/SDKProvider.tsx +31 -26
  8. package/src/components/SanityApp.test.tsx +121 -15
  9. package/src/components/SanityApp.tsx +26 -15
  10. package/src/components/auth/AuthBoundary.test.tsx +32 -14
  11. package/src/components/auth/AuthBoundary.tsx +53 -23
  12. package/src/components/auth/LoginCallback.test.tsx +19 -6
  13. package/src/components/auth/LoginCallback.tsx +2 -11
  14. package/src/components/auth/LoginError.test.tsx +12 -4
  15. package/src/components/auth/LoginError.tsx +13 -21
  16. package/src/components/auth/LoginFooter.test.tsx +7 -3
  17. package/src/context/ResourceProvider.test.tsx +157 -0
  18. package/src/context/ResourceProvider.tsx +111 -0
  19. package/src/context/SanityInstanceContext.ts +1 -1
  20. package/src/hooks/auth/useLoginUrl.tsx +14 -0
  21. package/src/hooks/client/useClient.ts +2 -1
  22. package/src/hooks/comlink/useManageFavorite.test.ts +16 -8
  23. package/src/hooks/comlink/useManageFavorite.ts +45 -14
  24. package/src/hooks/comlink/useRecordDocumentHistoryEvent.test.ts +8 -4
  25. package/src/hooks/comlink/useRecordDocumentHistoryEvent.ts +18 -9
  26. package/src/hooks/context/useSanityInstance.test.tsx +157 -15
  27. package/src/hooks/context/useSanityInstance.ts +66 -26
  28. package/src/hooks/dashboard/useNavigateToStudioDocument.test.ts +13 -31
  29. package/src/hooks/dashboard/useNavigateToStudioDocument.ts +26 -50
  30. package/src/hooks/dashboard/{useStudioWorkspacesByResourceId.test.tsx → useStudioWorkspacesByProjectIdDataset.test.tsx} +13 -13
  31. package/src/hooks/dashboard/{useStudioWorkspacesByResourceId.ts → useStudioWorkspacesByProjectIdDataset.ts} +10 -9
  32. package/src/hooks/datasets/useDatasets.ts +15 -4
  33. package/src/hooks/document/useApplyDocumentActions.test.ts +4 -9
  34. package/src/hooks/document/useApplyDocumentActions.ts +6 -31
  35. package/src/hooks/document/useDocument.test.ts +2 -2
  36. package/src/hooks/document/useDocument.ts +40 -19
  37. package/src/hooks/document/useDocumentEvent.test.ts +2 -3
  38. package/src/hooks/document/useDocumentEvent.ts +7 -11
  39. package/src/hooks/document/useDocumentPermissions.test.ts +204 -0
  40. package/src/hooks/document/useDocumentPermissions.ts +31 -23
  41. package/src/hooks/document/useDocumentSyncStatus.ts +5 -4
  42. package/src/hooks/document/useEditDocument.test.ts +2 -3
  43. package/src/hooks/document/useEditDocument.ts +43 -29
  44. package/src/hooks/documents/useDocuments.test.tsx +30 -3
  45. package/src/hooks/documents/useDocuments.ts +29 -12
  46. package/src/hooks/helpers/createCallbackHook.test.tsx +2 -2
  47. package/src/hooks/helpers/createCallbackHook.tsx +2 -3
  48. package/src/hooks/helpers/createStateSourceHook.test.tsx +1 -1
  49. package/src/hooks/helpers/createStateSourceHook.tsx +5 -8
  50. package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +43 -18
  51. package/src/hooks/paginatedDocuments/usePaginatedDocuments.ts +44 -54
  52. package/src/hooks/preview/usePreview.test.tsx +66 -7
  53. package/src/hooks/preview/usePreview.tsx +17 -12
  54. package/src/hooks/projection/useProjection.test.tsx +68 -3
  55. package/src/hooks/projection/useProjection.ts +21 -24
  56. package/src/hooks/projects/useProject.ts +7 -4
  57. package/src/hooks/query/useQuery.ts +32 -14
  58. package/src/hooks/users/useUsers.test.tsx +330 -0
  59. package/src/hooks/users/useUsers.ts +65 -52
  60. package/dist/index.cjs +0 -1064
  61. package/dist/index.cjs.map +0 -1
  62. package/dist/index.d.cts +0 -4816
  63. package/src/components/Login/LoginLinks.test.tsx +0 -90
  64. package/src/components/Login/LoginLinks.tsx +0 -58
  65. package/src/components/auth/Login.test.tsx +0 -27
  66. package/src/components/auth/Login.tsx +0 -39
  67. package/src/components/auth/LoginLayout.test.tsx +0 -19
  68. package/src/components/auth/LoginLayout.tsx +0 -69
  69. package/src/components/auth/authTestHelpers.tsx +0 -11
  70. package/src/context/SanityProvider.test.tsx +0 -25
  71. package/src/context/SanityProvider.tsx +0 -50
  72. package/src/hooks/auth/useLoginUrls.test.tsx +0 -68
  73. package/src/hooks/auth/useLoginUrls.tsx +0 -52
  74. package/src/hooks/users/useUsers.test.ts +0 -163
package/dist/index.d.ts CHANGED
@@ -1,122 +1,36 @@
1
1
  import {ActionsResult} from '@sanity/sdk'
2
2
  import {ApplyDocumentActionsOptions} from '@sanity/sdk'
3
- import {AuthProvider} from '@sanity/sdk'
4
3
  import {AuthState} from '@sanity/sdk'
5
4
  import {CanvasResource} from '@sanity/message-protocol'
6
5
  import {ClientOptions} from '@sanity/sdk'
7
6
  import {CurrentUser} from '@sanity/sdk'
7
+ import {DatasetHandle} from '@sanity/sdk'
8
8
  import {DocumentAction} from '@sanity/sdk'
9
9
  import {DocumentEvent} from '@sanity/sdk'
10
10
  import {DocumentHandle} from '@sanity/sdk'
11
11
  import {DocumentPermissionsResult} from '@sanity/sdk'
12
12
  import {FallbackProps} from 'react-error-boundary'
13
13
  import {FrameMessage} from '@sanity/sdk'
14
+ import {GetUsersOptions} from '@sanity/sdk'
14
15
  import {JsonMatch} from '@sanity/sdk'
15
16
  import {JsonMatchPath} from '@sanity/sdk'
16
17
  import {MediaResource} from '@sanity/message-protocol'
17
- import {Observable} from 'rxjs'
18
18
  import {PreviewValue} from '@sanity/sdk'
19
+ import {ProjectHandle} from '@sanity/sdk'
19
20
  import {QueryOptions} from '@sanity/sdk'
20
21
  import {ReactElement} from 'react'
21
22
  import {ReactNode} from 'react'
22
- import {Requester} from 'get-it'
23
- import {ResourceId} from '@sanity/sdk'
24
- import {ResourceType} from '@sanity/sdk'
23
+ import {SanityClient} from '@sanity/client'
25
24
  import {SanityConfig} from '@sanity/sdk'
26
25
  import {SanityDocument} from '@sanity/types'
27
26
  import {SanityInstance} from '@sanity/sdk'
28
27
  import {SanityProject as SanityProject_2} from '@sanity/sdk'
29
- import {SanityUser as SanityUser_2} from '@sanity/sdk'
28
+ import {SanityUser} from '@sanity/sdk'
30
29
  import {SortOrderingItem} from '@sanity/types'
31
30
  import {StudioResource} from '@sanity/message-protocol'
32
31
  import {ValidProjection} from '@sanity/sdk'
33
32
  import {WindowMessage} from '@sanity/sdk'
34
33
 
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
34
  /**
121
35
  * A component that handles authentication flow and error boundaries for a
122
36
  * protected section of the application.
@@ -144,3389 +58,496 @@ export declare function AuthBoundary({
144
58
  }: AuthBoundaryProps): React.ReactNode
145
59
 
146
60
  /**
147
- * @internal
61
+ * @public
148
62
  */
149
- declare interface AuthBoundaryProps extends LoginLayoutProps {
63
+ declare interface AuthBoundaryProps {
150
64
  /**
151
65
  * Custom component to render the login screen.
152
- * Receives all login layout props. Defaults to {@link Login}.
66
+ * Receives all props. Defaults to {@link Login}.
153
67
  */
154
- LoginComponent?: React.ComponentType<LoginLayoutProps>
68
+ LoginComponent?: React.ComponentType<{
69
+ header?: React.ReactNode
70
+ footer?: React.ReactNode
71
+ }>
155
72
  /**
156
73
  * Custom component to render during OAuth callback processing.
157
- * Receives all login layout props. Defaults to {@link LoginCallback}.
74
+ * Receives all props. Defaults to {@link LoginCallback}.
158
75
  */
159
- CallbackComponent?: React.ComponentType<LoginLayoutProps>
76
+ CallbackComponent?: React.ComponentType<{
77
+ header?: React.ReactNode
78
+ footer?: React.ReactNode
79
+ }>
160
80
  /**
161
81
  * Custom component to render when authentication errors occur.
162
- * Receives login layout props and error boundary props. Defaults to
82
+ * Receives error boundary props and layout props. Defaults to
163
83
  * {@link LoginError}
164
84
  */
165
85
  LoginErrorComponent?: React.ComponentType<LoginErrorProps>
86
+ /** Header content to display */
87
+ header?: React.ReactNode
88
+ /** Footer content to display */
89
+ footer?: React.ReactNode
90
+ /** Protected content to render when authenticated */
91
+ children?: React.ReactNode
166
92
  }
167
93
 
168
- /** @internal */
169
- declare type BaseActionOptions = RequestOptions & {
170
- transactionId?: string
171
- skipCrossDatasetReferenceValidation?: boolean
172
- dryRun?: boolean
173
- }
94
+ /**
95
+ * @public
96
+ */
97
+ export declare type ComlinkStatus = 'idle' | 'handshaking' | 'connected' | 'disconnected'
98
+
99
+ /** @public */
100
+ declare type DatasetAclMode = 'public' | 'private' | 'custom'
101
+
102
+ /** @public */
103
+ export declare type DatasetsResponse = {
104
+ name: string
105
+ aclMode: DatasetAclMode
106
+ createdAt: string
107
+ createdByUserId: string
108
+ addonFor: string | null
109
+ datasetProfile: string
110
+ features: string[]
111
+ tags: string[]
112
+ }[]
174
113
 
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
114
+ declare interface DocumentInteractionHistory {
115
+ recordEvent: (eventType: 'viewed' | 'edited' | 'created' | 'deleted') => void
116
+ isConnected: boolean
184
117
  }
185
118
 
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
119
+ /**
120
+ * Configuration options for the useDocuments hook
121
+ *
122
+ * @beta
123
+ * @category Types
124
+ */
125
+ export declare interface DocumentsOptions extends QueryOptions {
198
126
  /**
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"\}
127
+ * GROQ filter expression to apply to the query
203
128
  */
204
- setIfMissing(attrs: AttributeSet): this
129
+ filter?: string
205
130
  /**
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"\}
131
+ * Number of items to load per batch (defaults to 25)
210
132
  */
211
- diffMatchPatch(attrs: AttributeSet): this
133
+ batchSize?: number
212
134
  /**
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.
135
+ * Sorting configuration for the results
217
136
  */
218
- unset(attrs: string[]): this
137
+ orderings?: SortOrderingItem[]
219
138
  /**
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.
139
+ * Text search query to filter results
223
140
  */
224
- inc(attrs: {[key: string]: number}): this
141
+ search?: string
142
+ }
143
+
144
+ /**
145
+ * Return value from the useDocuments hook
146
+ *
147
+ * @beta
148
+ * @category Types
149
+ */
150
+ export declare interface DocumentsResponse {
225
151
  /**
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.
152
+ * Array of document handles for the current batch
229
153
  */
230
- dec(attrs: {[key: string]: number}): this
154
+ data: DocumentHandle[]
231
155
  /**
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
156
+ * Whether there are more items available to load
237
157
  */
238
- insert(at: 'before' | 'after' | 'replace', selector: string, items: Any[]): this
158
+ hasMore: boolean
239
159
  /**
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
160
+ * Total count of items matching the query
244
161
  */
245
- append(selector: string, items: Any[]): this
162
+ count: number
246
163
  /**
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
164
+ * Whether a query is currently in progress
251
165
  */
252
- prepend(selector: string, items: Any[]): this
166
+ isPending: boolean
253
167
  /**
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.
168
+ * Function to load the next batch of results
260
169
  */
261
- splice(selector: string, start: number, deleteCount?: number, items?: Any[]): this
170
+ loadMore: () => void
171
+ }
172
+
173
+ /**
174
+ * @internal
175
+ */
176
+ export declare interface FrameConnection<TFrameMessage extends FrameMessage> {
177
+ connect: (frameWindow: Window) => () => void
178
+ sendMessage: <T extends TFrameMessage['type']>(
179
+ ...params: Extract<
180
+ TFrameMessage,
181
+ {
182
+ type: T
183
+ }
184
+ >['data'] extends undefined
185
+ ? [type: T]
186
+ : [
187
+ type: T,
188
+ data: Extract<
189
+ TFrameMessage,
190
+ {
191
+ type: T
192
+ }
193
+ >['data'],
194
+ ]
195
+ ) => void
196
+ }
197
+
198
+ /**
199
+ * @alpha
200
+ */
201
+ declare type LoginErrorProps = FallbackProps
202
+
203
+ declare interface ManageFavorite {
204
+ favorite: () => void
205
+ unfavorite: () => void
206
+ isFavorited: boolean
207
+ isConnected: boolean
208
+ }
209
+
210
+ /**
211
+ * @public
212
+ */
213
+ declare type MessageData = Record<string, unknown> | undefined
214
+
215
+ /**
216
+ * @internal
217
+ */
218
+ export declare type MessageHandler<TWindowMessage extends WindowMessage> = (
219
+ event: TWindowMessage['data'],
220
+ ) => TWindowMessage['response'] | Promise<TWindowMessage['response']>
221
+
222
+ /** @public */
223
+ export declare interface NavigateToStudioResult {
224
+ navigateToStudioDocument: () => void
225
+ isConnected: boolean
226
+ }
227
+
228
+ /**
229
+ * Configuration options for the usePaginatedDocuments hook
230
+ *
231
+ * @beta
232
+ * @category Types
233
+ */
234
+ export declare interface PaginatedDocumentsOptions extends QueryOptions {
262
235
  /**
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
236
+ * GROQ filter expression to apply to the query
266
237
  */
267
- ifRevisionId(rev: string): this
238
+ filter?: string
268
239
  /**
269
- * Return a plain JSON representation of the patch
240
+ * Number of items to display per page (defaults to 25)
270
241
  */
271
- serialize(): PatchMutationOperation
242
+ pageSize?: number
272
243
  /**
273
- * Return a plain JSON representation of the patch
244
+ * Sorting configuration for the results
274
245
  */
275
- toJSON(): PatchMutationOperation
246
+ orderings?: SortOrderingItem[]
276
247
  /**
277
- * Clears the patch of all operations
248
+ * Text search query to filter results
278
249
  */
279
- reset(): this
280
- protected _assign(op: keyof PatchOperations, props: Any, merge?: boolean): this
281
- protected _set(op: keyof PatchOperations, props: Any): this
250
+ search?: string
282
251
  }
283
252
 
284
- /** @internal */
285
- declare class BaseTransaction {
286
- protected operations: Mutation[]
287
- protected trxId?: string
288
- constructor(operations?: Mutation[], transactionId?: string)
253
+ /**
254
+ * Return value from the usePaginatedDocuments hook
255
+ *
256
+ * @beta
257
+ * @category Types
258
+ */
259
+ export declare interface PaginatedDocumentsResponse {
289
260
  /**
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.
261
+ * Array of document handles for the current page
294
262
  */
295
- create<R extends Record<string, Any> = Record<string, Any>>(doc: SanityDocumentStub<R>): this
263
+ data: DocumentHandle[]
296
264
  /**
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.
265
+ * Whether a query is currently in progress
301
266
  */
302
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
303
- doc: IdentifiedSanityDocumentStub<R>,
304
- ): this
267
+ isPending: boolean
305
268
  /**
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.
269
+ * Number of items displayed per page
310
270
  */
311
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
312
- doc: IdentifiedSanityDocumentStub<R>,
313
- ): this
271
+ pageSize: number
314
272
  /**
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
273
+ * Current page number (1-indexed)
319
274
  */
320
- delete(documentId: string): this
275
+ currentPage: number
321
276
  /**
322
- * Gets the current transaction ID, if any
277
+ * Total number of pages available
323
278
  */
324
- transactionId(): string | undefined
279
+ totalPages: number
325
280
  /**
326
- * Set the ID of this transaction.
327
- *
328
- * @param id - Transaction ID
281
+ * Starting index of the current page (0-indexed)
329
282
  */
330
- transactionId(id: string): this
283
+ startIndex: number
331
284
  /**
332
- * Return a plain JSON representation of the transaction
285
+ * Ending index of the current page (exclusive, 0-indexed)
333
286
  */
334
- serialize(): Mutation[]
287
+ endIndex: number
335
288
  /**
336
- * Return a plain JSON representation of the transaction
289
+ * Total count of items matching the query
337
290
  */
338
- toJSON(): Mutation[]
291
+ count: number
339
292
  /**
340
- * Clears the transaction of all operations
293
+ * Navigate to the first page
341
294
  */
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
295
+ firstPage: () => void
364
296
  /**
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'
297
+ * Whether there is a first page available to navigate to
369
298
  */
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
299
+ hasFirstPage: boolean
378
300
  /**
379
- * Optional request tag prefix for all request tags
301
+ * Navigate to the previous page
380
302
  */
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
303
+ previousPage: () => void
388
304
  /**
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
305
+ * Whether there is a previous page available to navigate to
395
306
  */
396
- retryDelay?: (attemptNumber: number) => number
307
+ hasPreviousPage: boolean
397
308
  /**
398
- * @deprecated Don't use
309
+ * Navigate to the next page
399
310
  */
400
- useProjectHostname?: boolean
311
+ nextPage: () => void
401
312
  /**
402
- * @deprecated Don't use
313
+ * Whether there is a next page available to navigate to
403
314
  */
404
- requester?: Requester
315
+ hasNextPage: boolean
405
316
  /**
406
- * Adds a `resultSourceMap` key to the API response, with the type `ContentSourceMap`
317
+ * Navigate to the last page
407
318
  */
408
- resultSourceMap?: boolean | 'withKeyArraySelector'
319
+ lastPage: () => void
409
320
  /**
410
- *@deprecated set `cache` and `next` options on `client.fetch` instead
321
+ * Whether there is a last page available to navigate to
411
322
  */
412
- fetch?:
413
- | {
414
- cache?: ResponseQueryOptions['cache']
415
- next?: ResponseQueryOptions['next']
416
- }
417
- | boolean
323
+ hasLastPage: boolean
418
324
  /**
419
- * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
325
+ * Navigate to a specific page number
326
+ * @param pageNumber - The page number to navigate to (1-indexed)
420
327
  */
421
- stega?: StegaConfig | boolean
328
+ goToPage: (pageNumber: number) => void
422
329
  }
423
330
 
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
331
  /**
439
332
  * @public
333
+ * @category Types
334
+ * @interface
440
335
  */
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
- }
336
+ export declare type ProjectWithoutMembers = Omit<SanityProject, 'members'>
455
337
 
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
- }
338
+ /**
339
+ * This version is provided by pkg-utils at build time
340
+ * @internal
341
+ */
342
+ export declare const REACT_SDK_VERSION: {}
3177
343
 
3178
344
  /**
3179
- * @internal
345
+ * Provides a Sanity instance to child components through React Context
3180
346
  *
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.
347
+ * @internal
3183
348
  *
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
349
+ * @remarks
350
+ * The ResourceProvider creates a hierarchical structure of Sanity instances:
351
+ * - When used as a root provider, it creates a new Sanity instance with the given config
352
+ * - When nested inside another ResourceProvider, it creates a child instance that
353
+ * inherits and extends the parent's configuration
354
+ *
355
+ * Features:
356
+ * - Automatically manages the lifecycle of Sanity instances
357
+ * - Disposes instances when the component unmounts
358
+ * - Includes a Suspense boundary for data loading
359
+ * - Enables hierarchical configuration inheritance
360
+ *
361
+ * Use this component to:
362
+ * - Set up project/dataset configuration for an application
363
+ * - Override specific configuration values in a section of your app
364
+ * - Create isolated instance hierarchies for different features
365
+ *
366
+ * @example Creating a root provider
3188
367
  * ```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
- * }
368
+ * <ResourceProvider
369
+ * projectId="your-project-id"
370
+ * dataset="production"
371
+ * fallback={<LoadingSpinner />}
372
+ * >
373
+ * <YourApp />
374
+ * </ResourceProvider>
3206
375
  * ```
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
376
  *
3241
- * Top-level context provider that provides access to the Sanity SDK.
377
+ * @example Creating nested providers with configuration inheritance
378
+ * ```tsx
379
+ * // Root provider with production config with nested provider for preview features with custom dataset
380
+ * <ResourceProvider projectId="abc123" dataset="production" fallback={<Loading />}>
381
+ * <div>...Main app content</div>
382
+ * <Dashboard />
383
+ * <ResourceProvider dataset="preview" fallback={<Loading />}>
384
+ * <PreviewFeatures />
385
+ * </ResourceProvider>
386
+ * </ResourceProvider>
387
+ * ```
3242
388
  */
3243
- export declare function SDKProvider({
389
+ export declare function ResourceProvider({
3244
390
  children,
3245
- sanityConfigs,
3246
391
  fallback,
3247
- }: SDKProviderProps): ReactElement
392
+ ...config
393
+ }: ResourceProviderProps): React.ReactNode
3248
394
 
3249
395
  /**
396
+ * Props for the ResourceProvider component
3250
397
  * @internal
3251
398
  */
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
399
+ export declare interface ResourceProviderProps extends SanityConfig {
3383
400
  /**
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
401
+ * React node to show while content is loading
402
+ * Used as the fallback for the internal Suspense boundary
3395
403
  */
3396
- patch(patch: Patch): this
3397
- }
3398
-
3399
- /** @internal */
3400
- declare type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
3401
- returnFirst?: false
3402
- returnDocuments?: false
404
+ fallback: React.ReactNode
405
+ children: React.ReactNode
3403
406
  }
3404
407
 
3405
- /** @internal */
3406
- declare type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
3407
- returnFirst?: false
3408
- returnDocuments: true
3409
- }
408
+ /**
409
+ * @public
410
+ *
411
+ * The SanityApp component provides your Sanity application with access to your Sanity configuration,
412
+ * as well as application context and state which is used by the Sanity React hooks. Your application
413
+ * must be wrapped with the SanityApp component to function properly.
414
+ *
415
+ * SanityApp creates a hierarchy of ResourceProviders, each providing a SanityInstance that can be
416
+ * accessed by hooks. The first configuration in the array becomes the default instance.
417
+ *
418
+ * @param props - Your Sanity configuration and the React children to render
419
+ * @returns Your Sanity application, integrated with your Sanity configuration and application context
420
+ *
421
+ * @example
422
+ * ```tsx
423
+ * import { SanityApp } from '@sanity/sdk-react'
424
+ *
425
+ * import MyAppRoot from './Root'
426
+ *
427
+ * // Single project configuration
428
+ * const mySanityConfig = {
429
+ * projectId: 'my-project-id',
430
+ * dataset: 'production',
431
+ * }
432
+ *
433
+ * // Or multiple project configurations
434
+ * const multipleConfigs = [
435
+ * // Configuration for your main project. This will be used as the default project for hooks.
436
+ * {
437
+ * projectId: 'marketing-website-project',
438
+ * dataset: 'production',
439
+ * },
440
+ * // Configuration for a separate blog project
441
+ * {
442
+ * projectId: 'blog-project',
443
+ * dataset: 'production',
444
+ * },
445
+ * // Configuration for a separate ecommerce project
446
+ * {
447
+ * projectId: 'ecommerce-project',
448
+ * dataset: 'production',
449
+ * }
450
+ * ]
451
+ *
452
+ * export default function MyApp() {
453
+ * return (
454
+ * <SanityApp config={mySanityConfig} fallback={<LoadingSpinner />}>
455
+ * <MyAppRoot />
456
+ * </SanityApp>
457
+ * )
458
+ * }
459
+ * ```
460
+ */
461
+ export declare function SanityApp({
462
+ children,
463
+ fallback,
464
+ config,
465
+ sanityConfigs,
466
+ ...props
467
+ }: SanityAppProps): ReactElement
3410
468
 
3411
- /** @internal */
3412
- declare type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
3413
- returnFirst: true
3414
- returnDocuments?: false
469
+ /**
470
+ * @public
471
+ */
472
+ export declare interface SanityAppProps {
473
+ config: SanityConfig | SanityConfig[]
474
+ /** @deprecated use the `config` prop instead. */
475
+ sanityConfigs?: SanityConfig[]
476
+ children: React.ReactNode
477
+ fallback: React.ReactNode
3415
478
  }
3416
479
 
3417
- /** @internal */
3418
- declare type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
3419
- returnFirst: true
3420
- returnDocuments: true
3421
- }
480
+ export {SanityDocument}
3422
481
 
3423
482
  /** @public */
3424
- declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
3425
- filterResponse: false
483
+ export declare interface SanityProject {
484
+ id: string
485
+ displayName: string
3426
486
  /**
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`.
487
+ * @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
488
+ * @see https://www.sanity.io/help/studio-host-user-applications
3430
489
  */
3431
- returnQuery?: true
490
+ studioHost: string | null
491
+ organizationId: string | null
492
+ isBlocked: boolean
493
+ isDisabled: boolean
494
+ isDisabledByUser: boolean
495
+ createdAt: string
496
+ pendingInvites?: number
497
+ maxRetentionDays?: number
498
+ members: SanityProjectMember[]
499
+ metadata: {
500
+ cliInitializedAt?: string
501
+ color?: string
502
+ /**
503
+ * @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
504
+ * @see https://www.sanity.io/help/studio-host-user-applications
505
+ */
506
+ externalStudioHost?: string
507
+ }
508
+ }
509
+
510
+ /** @public */
511
+ export declare interface SanityProjectMember {
512
+ id: string
513
+ role: string
514
+ isRobot: boolean
515
+ isCurrentUser: boolean
3432
516
  }
3433
517
 
3434
518
  /**
3435
- * When using `filterResponse: false`, but you do not wish to receive back the query from
3436
- * the content lake API.
519
+ * @internal
3437
520
  *
3438
- * @public
521
+ * Top-level context provider that provides access to the Sanity SDK.
522
+ * Creates a hierarchy of ResourceProviders, each providing a SanityInstance that can be
523
+ * accessed by hooks. The first configuration in the array becomes the default instance.
3439
524
  */
3440
- declare interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
3441
- filterResponse: false
3442
- returnQuery: false
3443
- }
525
+ export declare function SDKProvider({
526
+ children,
527
+ config,
528
+ fallback,
529
+ ...props
530
+ }: SDKProviderProps): ReactElement
3444
531
 
3445
532
  /**
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
533
+ * @internal
3451
534
  */
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
535
+ export declare interface SDKProviderProps extends AuthBoundaryProps {
536
+ children: ReactNode
537
+ config: SanityConfig | SanityConfig[]
538
+ fallback: ReactNode
3462
539
  }
3463
540
 
3464
- declare type Updater<TValue> = TValue | ((nextValue: TValue) => TValue)
3465
-
3466
- /** @public */
3467
- declare type UploadBody = File | Blob | Buffer | NodeJS.ReadableStream
541
+ export {SortOrderingItem}
3468
542
 
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
- }
543
+ declare interface StudioWorkspacesResult {
544
+ workspacesByProjectIdAndDataset: WorkspacesByProjectIdDataset
545
+ error: string | null
546
+ isConnected: boolean
3528
547
  }
3529
548
 
549
+ declare type Updater<TValue> = TValue | ((nextValue: TValue) => TValue)
550
+
3530
551
  /**
3531
552
  *
3532
553
  * @beta
@@ -3534,7 +555,7 @@ declare interface UploadClientConfig {
3534
555
  * Provides a callback for applying one or more actions to a document.
3535
556
  *
3536
557
  * @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.
558
+ * @param dataset - An optional dataset handle with projectId and dataset. If not provided, the nearest SanityInstance from context will be used.
3538
559
  * @returns A function that takes one more more {@link DocumentAction}s and returns a promise that resolves to an {@link ActionsResult}.
3539
560
  * @example Publish or unpublish a document
3540
561
  * ```
@@ -3542,7 +563,7 @@ declare interface UploadClientConfig {
3542
563
  * import { useApplyDocumentActions } from '@sanity/sdk-react'
3543
564
  *
3544
565
  * const apply = useApplyDocumentActions()
3545
- * const myDocument = { _id: 'my-document-id', _type: 'my-document-type' }
566
+ * const myDocument = { documentId: 'my-document-id', documentType: 'my-document-type' }
3546
567
  *
3547
568
  * return (
3548
569
  * <button onClick={() => apply(publishDocument(myDocument))}>Publish</button>
@@ -3558,7 +579,7 @@ declare interface UploadClientConfig {
3558
579
  * const apply = useApplyDocumentActions()
3559
580
  *
3560
581
  * const handleCreateAndPublish = () => {
3561
- * const handle = { _id: window.crypto.randomUUID(), _type: 'my-document-type' }
582
+ * const handle = { documentId: window.crypto.randomUUID(), documentType: 'my-document-type' }
3562
583
  * apply([
3563
584
  * createDocument(handle),
3564
585
  * publishDocument(handle),
@@ -3567,17 +588,15 @@ declare interface UploadClientConfig {
3567
588
  *
3568
589
  * return (
3569
590
  * <button onClick={handleCreateAndPublish}>
3570
- * Im feeling lucky
591
+ * I'm feeling lucky
3571
592
  * </button>
3572
593
  * )
3573
594
  * ```
3574
595
  */
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>>
596
+ export declare const useApplyDocumentActions: () => (
597
+ action: DocumentAction | DocumentAction[],
598
+ options?: ApplyDocumentActionsOptions | undefined,
599
+ ) => Promise<ActionsResult<SanityDocument>>
3581
600
 
3582
601
  /**
3583
602
  * @internal
@@ -3636,7 +655,7 @@ export declare const useAuthToken: () => string | null
3636
655
  * @public
3637
656
  * @function
3638
657
  */
3639
- export declare const useClient: (e: ClientOptions) => SanityClient
658
+ export declare const useClient: (x: ClientOptions) => SanityClient
3640
659
 
3641
660
  declare type UseCurrentUser = {
3642
661
  /**
@@ -3726,20 +745,26 @@ export declare const useDatasets: UseDatasets
3726
745
  * ## useDocument(doc, path)
3727
746
  * Read and subscribe to nested values in a document
3728
747
  * @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.
748
+ * @param doc - The document to read state from, specified as a DocumentHandle
3731
749
  * @param path - The path to the nested value to read from
3732
750
  * @returns The value at the specified path
3733
751
  * @example
3734
752
  * ```tsx
3735
- * import {type DocumentHandle, useDocument} from '@sanity/sdk-react'
753
+ * import {useDocument} from '@sanity/sdk-react'
3736
754
  *
3737
- * function OrderLink({documentHandle}: {documentHandle: DocumentHandle}) {
755
+ * const documentHandle = {
756
+ * documentId: 'order-123',
757
+ * documentType: 'order',
758
+ * projectId: 'abc123',
759
+ * dataset: 'production'
760
+ * }
761
+ *
762
+ * function OrderLink() {
3738
763
  * const title = useDocument(documentHandle, 'title')
3739
764
  * const id = useDocument(documentHandle, '_id')
3740
765
  *
3741
766
  * return (
3742
- * <a href=`/order/${id}`>Order {title} today!</a>
767
+ * <a href={`/order/${id}`}>Order {title} today!</a>
3743
768
  * )
3744
769
  * }
3745
770
  * ```
@@ -3754,11 +779,11 @@ export declare function useDocument<
3754
779
  * @beta
3755
780
  * ## useDocument(doc)
3756
781
  * Read and subscribe to an entire document
3757
- * @param doc - The document to read state from
782
+ * @param doc - The document to read state from, specified as a DocumentHandle
3758
783
  * @returns The document state as an object
3759
784
  * @example
3760
785
  * ```tsx
3761
- * import {type SanityDocument, type DocumentHandle, useDocument} from '@sanity/sdk-react'
786
+ * import {type SanityDocument, useDocument} from '@sanity/sdk-react'
3762
787
  *
3763
788
  * interface Book extends SanityDocument {
3764
789
  * title: string
@@ -3766,19 +791,30 @@ export declare function useDocument<
3766
791
  * summary: string
3767
792
  * }
3768
793
  *
3769
- * function DocumentView({documentHandle}: {documentHandle: DocumentHandle}) {
794
+ * const documentHandle = {
795
+ * documentId: 'book-123',
796
+ * documentType: 'book',
797
+ * projectId: 'abc123',
798
+ * dataset: 'production'
799
+ * }
800
+ *
801
+ * function DocumentView() {
3770
802
  * const book = useDocument<Book>(documentHandle)
3771
803
  *
804
+ * if (!book) {
805
+ * return <div>Loading...</div>
806
+ * }
807
+ *
3772
808
  * return (
3773
809
  * <article>
3774
- * <h1>{book?.title}</h1>
3775
- * <address>By {book?.author}</address>
810
+ * <h1>{book.title}</h1>
811
+ * <address>By {book.author}</address>
3776
812
  *
3777
813
  * <h2>Summary</h2>
3778
- * {book?.summary}
814
+ * {book.summary}
3779
815
  *
3780
816
  * <h2>Order</h2>
3781
- * <a href=`/order/${book._id}`>Order {book?.title} today!</a>
817
+ * <a href={`/order/${book._id}`}>Order {book.title} today!</a>
3782
818
  * </article>
3783
819
  * )
3784
820
  * }
@@ -3793,13 +829,14 @@ export declare function useDocument<TDocument extends SanityDocument>(
3793
829
  *
3794
830
  * @beta
3795
831
  *
3796
- * Subscribes an event handler to events in your applications document store, such as document
832
+ * Subscribes an event handler to events in your application's document store, such as document
3797
833
  * creation, deletion, and updates.
3798
834
  *
3799
835
  * @category Documents
3800
836
  * @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.
837
+ * @param doc - The document to subscribe to events for. If you pass a `DocumentHandle` with specified `projectId` and `dataset`,
838
+ * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `projectId` or `dataset` is provided,
839
+ * the document will use the nearest instance from context.
3803
840
  * @example
3804
841
  * ```
3805
842
  * import {useDocumentEvent} from '@sanity/sdk-react'
@@ -3816,7 +853,7 @@ export declare function useDocument<TDocument extends SanityDocument>(
3816
853
  */
3817
854
  export declare function useDocumentEvent(
3818
855
  handler: (documentEvent: DocumentEvent) => void,
3819
- doc: DocumentHandle,
856
+ dataset: DatasetHandle,
3820
857
  ): void
3821
858
 
3822
859
  /**
@@ -3826,7 +863,7 @@ export declare function useDocumentEvent(
3826
863
  * Check if the current user has the specified permissions for the given document actions.
3827
864
  *
3828
865
  * @category Permissions
3829
- * @param actions - One more more calls to a particular document action function for a given document
866
+ * @param actionOrActions - One more more calls to a particular document action function for a given document
3830
867
  * @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
868
  *
3832
869
  * @example Checking for permission to publish a document
@@ -3858,7 +895,7 @@ export declare function useDocumentEvent(
3858
895
  * ```
3859
896
  */
3860
897
  export declare function useDocumentPermissions(
3861
- actions: DocumentAction | DocumentAction[],
898
+ actionOrActions: DocumentAction | DocumentAction[],
3862
899
  ): DocumentPermissionsResult
3863
900
 
3864
901
  /**
@@ -3870,9 +907,15 @@ export declare function useDocumentPermissions(
3870
907
  * @category Documents
3871
908
  * @param options - Configuration options for the infinite list
3872
909
  * @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
910
+ *
911
+ * @remarks
912
+ * - The returned document handles include projectId and dataset information from the current Sanity instance
913
+ * - This makes them ready to use with document operations and other document hooks
914
+ * - The hook automatically uses the correct Sanity instance based on the projectId and dataset in the options
915
+ *
916
+ * @example Basic infinite list with loading more
3874
917
  * ```tsx
3875
- * const {data, hasMore, isPending, loadMore} = useDocuments({
918
+ * const { data, hasMore, isPending, loadMore, count } = useDocuments({
3876
919
  * filter: '_type == "post"',
3877
920
  * search: searchTerm,
3878
921
  * batchSize: 10,
@@ -3884,16 +927,17 @@ export declare function useDocumentPermissions(
3884
927
  * Total documents: {count}
3885
928
  * <ol>
3886
929
  * {data.map((doc) => (
3887
- * <li key={doc._id}>
930
+ * <li key={doc.documentId}>
3888
931
  * <MyDocumentComponent doc={doc} />
3889
932
  * </li>
3890
933
  * ))}
3891
934
  * </ol>
3892
- * {hasMore && <button onClick={loadMore}>Load More</button>}
935
+ * {hasMore && <button onClick={loadMore} disabled={isPending}>
936
+ * {isPending ? 'Loading...' : 'Load More'}
937
+ * </button>}
3893
938
  * </div>
3894
939
  * )
3895
940
  * ```
3896
- *
3897
941
  */
3898
942
  export declare function useDocuments({
3899
943
  batchSize,
@@ -3906,15 +950,16 @@ export declare function useDocuments({
3906
950
 
3907
951
  declare type UseDocumentSyncStatus = {
3908
952
  /**
3909
- * Exposes the documents sync status between local and remote document states.
953
+ * Exposes the document's sync status between local and remote document states.
3910
954
  *
3911
955
  * @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.
956
+ * @param doc - The document handle to get sync status for. If you pass a `DocumentHandle` with specified `projectId` and `dataset`,
957
+ * the document will be read from the specified Sanity project and dataset that is included in the handle. If no `projectId` or `dataset` is provided,
958
+ * the document will use the nearest instance from context.
3914
959
  * @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
960
  * @example Disable a Save button when there are no changes to sync
3916
961
  * ```
3917
- * const myDocumentHandle = { _id: 'documentId', _type: 'documentType', resourceId: 'document:projectId:dataset:documentId' }
962
+ * const myDocumentHandle = { documentId: 'documentId', documentType: 'documentType', projectId: 'projectId', dataset: 'dataset' }
3918
963
  * const documentSynced = useDocumentSyncStatus(myDocumentHandle)
3919
964
  *
3920
965
  * return (
@@ -3941,12 +986,18 @@ export declare const useDocumentSyncStatus: UseDocumentSyncStatus
3941
986
  * Edit a nested value within a document
3942
987
  *
3943
988
  * @category Documents
3944
- * @param doc - The document to be edited; either as a document handle or the document’s ID a string
989
+ * @param docHandle - The document to be edited, specified as a DocumentHandle
3945
990
  * @param path - The path to the nested value to be edited
3946
991
  * @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 documents name by providing the new value directly
3948
- * ```
3949
- * const handle = { _id: 'documentId', _type: 'documentType' }
992
+ * @example Update a document's name by providing the new value directly
993
+ * ```tsx
994
+ * const handle = {
995
+ * documentId: 'movie-123',
996
+ * documentType: 'movie',
997
+ * projectId: 'abc123',
998
+ * dataset: 'production'
999
+ * }
1000
+ *
3950
1001
  * const name = useDocument(handle, 'name')
3951
1002
  * const editName = useEditDocument(handle, 'name')
3952
1003
  *
@@ -3960,8 +1011,14 @@ export declare const useDocumentSyncStatus: UseDocumentSyncStatus
3960
1011
  * ```
3961
1012
  *
3962
1013
  * @example Update a count on a document by providing an updater function
3963
- * ```
3964
- * const handle = { _id: 'documentId', _type: 'documentType' }
1014
+ * ```tsx
1015
+ * const handle = {
1016
+ * documentId: 'counter-123',
1017
+ * documentType: 'counter',
1018
+ * projectId: 'abc123',
1019
+ * dataset: 'production'
1020
+ * }
1021
+ *
3965
1022
  * const count = useDocument(handle, 'count')
3966
1023
  * const editCount = useEditDocument(handle, 'count')
3967
1024
  *
@@ -3983,7 +1040,7 @@ export declare function useEditDocument<
3983
1040
  TDocument extends SanityDocument,
3984
1041
  TPath extends JsonMatchPath<TDocument>,
3985
1042
  >(
3986
- doc: DocumentHandle<TDocument>,
1043
+ docHandle: DocumentHandle<TDocument>,
3987
1044
  path: TPath,
3988
1045
  ): (nextValue: Updater<JsonMatch<TDocument, TPath>>) => Promise<ActionsResult<TDocument>>
3989
1046
 
@@ -3993,15 +1050,20 @@ export declare function useEditDocument<
3993
1050
  *
3994
1051
  * ## useEditDocument(doc)
3995
1052
  * 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.
1053
+ * @param docHandle - The document to be edited, specified as a DocumentHandle.
1054
+ * The hook will automatically use the Sanity instance that matches the project and dataset specified in the handle.
3998
1055
  * @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
1056
  * @example
4000
- * ```
4001
- * const myDocumentHandle = { _id: 'documentId', _type: 'documentType' }
1057
+ * ```tsx
1058
+ * const myDocumentHandle = {
1059
+ * documentId: 'product-123',
1060
+ * documentType: 'product',
1061
+ * projectId: 'abc123',
1062
+ * dataset: 'production'
1063
+ * }
4002
1064
  *
4003
1065
  * const myDocument = useDocument(myDocumentHandle)
4004
- * const { title, price } = myDocument
1066
+ * const { title, price } = myDocument ?? {}
4005
1067
  *
4006
1068
  * const editMyDocument = useEditDocument(myDocumentHandle)
4007
1069
  *
@@ -4039,7 +1101,7 @@ export declare function useEditDocument<
4039
1101
  * <input
4040
1102
  * name='salePrice'
4041
1103
  * type='checkbox'
4042
- * checked={Object(myDocument).hasOwnProperty('salePrice')}
1104
+ * checked={myDocument && 'salePrice' in myDocument}
4043
1105
  * onChange={handleSaleChange}
4044
1106
  * />
4045
1107
  * </form>
@@ -4051,7 +1113,7 @@ export declare function useEditDocument<
4051
1113
  * ```
4052
1114
  */
4053
1115
  export declare function useEditDocument<TDocument extends SanityDocument>(
4054
- doc: DocumentHandle<TDocument>,
1116
+ docHandle: DocumentHandle<TDocument>,
4055
1117
  ): (nextValue: Updater<TDocument>) => Promise<ActionsResult<TDocument>>
4056
1118
 
4057
1119
  /**
@@ -4128,45 +1190,9 @@ export declare const useHandleAuthCallback: () => (
4128
1190
  ) => Promise<string | false>
4129
1191
 
4130
1192
  /**
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
1193
  * @public
4168
1194
  */
4169
- export declare function useLoginUrls(): AuthProvider[]
1195
+ export declare function useLoginUrl(): string
4170
1196
 
4171
1197
  /**
4172
1198
  * Hook to log out of the current session
@@ -4211,38 +1237,41 @@ export declare const useLogOut: () => () => Promise<void>
4211
1237
  export declare function useManageFavorite({
4212
1238
  documentId,
4213
1239
  documentType,
4214
- resourceId,
1240
+ projectId: paramProjectId,
1241
+ dataset: paramDataset,
1242
+ resourceId: paramResourceId,
4215
1243
  resourceType,
1244
+ schemaName,
4216
1245
  }: UseManageFavoriteProps): ManageFavorite
4217
1246
 
4218
- declare interface UseManageFavoriteProps {
4219
- documentId: string
4220
- documentType: string
1247
+ declare interface UseManageFavoriteProps extends DocumentHandle {
4221
1248
  resourceId?: string
4222
1249
  resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
1250
+ /**
1251
+ * The name of the schema collection this document belongs to.
1252
+ * Typically is the name of the workspace when used in the context of a studio.
1253
+ */
1254
+ schemaName?: string
4223
1255
  }
4224
1256
 
4225
1257
  /**
4226
1258
  * @public
4227
1259
  * 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
1260
  *
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.
1261
+ * Uses the `projectId` and `dataset` properties of the {@link DocumentHandle} you provide to resolve the correct Studio.
1262
+ * This will only work if you have deployed a studio with a workspace with this `projectId` / `dataset` combination.
4236
1263
  *
4237
- * This will likely change in the future.
4238
- * @param documentHandle - The document handle containing document ID, type, and resource ID
1264
+ * @remarks If you write your own Document Handle to pass to this hook (as opposed to a Document Handle generated by another hook),
1265
+ * it must include values for `documentId`, `documentType`, `projectId`, and `dataset`.
1266
+ *
1267
+ * @param documentHandle - The document handle for the document to navigate to
4239
1268
  * @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
1269
+ * - `navigateToStudioDocument` - Function that when called will navigate to the studio document
1270
+ * - `isConnected` - Boolean indicating if connection to Dashboard is established
4242
1271
  *
4243
1272
  * @example
4244
1273
  * ```ts
4245
- * import {navigateToStudioDocument, type DocumentHandle} from '@sanity/sdk'
1274
+ * import {useNavigateToStudioDocument, type DocumentHandle} from '@sanity/sdk-react'
4246
1275
  *
4247
1276
  * function MyComponent({documentHandle}: {documentHandle: DocumentHandle}) {
4248
1277
  * const {navigateToStudioDocument, isConnected} = useNavigateToStudioDocument(documentHandle)
@@ -4268,7 +1297,13 @@ export declare function useNavigateToStudioDocument(
4268
1297
  * @category Documents
4269
1298
  * @param options - Configuration options for the paginated list
4270
1299
  * @returns An object containing the current page of document handles, the loading and pagination state, and navigation functions
4271
- * @example
1300
+ *
1301
+ * @remarks
1302
+ * - The returned document handles include projectId and dataset information from the current Sanity instance
1303
+ * - This makes them ready to use with document operations and other document hooks
1304
+ * - The hook automatically uses the correct Sanity instance based on the projectId and dataset in the options
1305
+ *
1306
+ * @example Basic usage
4272
1307
  * ```tsx
4273
1308
  * const {
4274
1309
  * data,
@@ -4290,14 +1325,12 @@ export declare function useNavigateToStudioDocument(
4290
1325
  * <>
4291
1326
  * <table>
4292
1327
  * {data.map(doc => (
4293
- * <MyTableRowComponent key={doc._id} doc={doc} />
1328
+ * <MyTableRowComponent key={doc.documentId} doc={doc} />
4294
1329
  * ))}
4295
1330
  * </table>
4296
- * <>
4297
- * {hasPreviousPage && <button onClick={previousPage}>Previous</button>}
4298
- * {currentPage} / {totalPages}
4299
- * {hasNextPage && <button onClick={nextPage}>Next</button>}
4300
- * </>
1331
+ * {hasPreviousPage && <button onClick={previousPage}>Previous</button>}
1332
+ * {currentPage} / {totalPages}
1333
+ * {hasNextPage && <button onClick={nextPage}>Next</button>}
4301
1334
  * </>
4302
1335
  * )
4303
1336
  * ```
@@ -4310,7 +1343,7 @@ export declare function usePaginatedDocuments({
4310
1343
  orderings,
4311
1344
  search,
4312
1345
  ...options
4313
- }?: PaginatedDocumentsOptions): PaginatedDocumentsResponse
1346
+ }: PaginatedDocumentsOptions): PaginatedDocumentsResponse
4314
1347
 
4315
1348
  /**
4316
1349
  * @beta
@@ -4356,17 +1389,17 @@ export declare function usePaginatedDocuments({
4356
1389
  * )
4357
1390
  * ```
4358
1391
  */
4359
- export declare function usePreview({
4360
- document: {_id, _type},
4361
- ref,
4362
- }: UsePreviewOptions): UsePreviewResults
1392
+ export declare function usePreview({ref, ...docHandle}: UsePreviewOptions): UsePreviewResults
4363
1393
 
4364
1394
  /**
4365
1395
  * @beta
4366
1396
  * @category Types
4367
1397
  */
4368
- export declare interface UsePreviewOptions {
4369
- document: DocumentHandle
1398
+ export declare interface UsePreviewOptions extends DocumentHandle {
1399
+ /**
1400
+ * Optional ref object to track visibility. When provided, preview resolution
1401
+ * only occurs when the referenced element is visible in the viewport.
1402
+ */
4370
1403
  ref?: React.RefObject<unknown>
4371
1404
  }
4372
1405
 
@@ -4402,7 +1435,7 @@ declare type UseProject = {
4402
1435
  * }
4403
1436
  * ```
4404
1437
  */
4405
- (projectId: string): SanityProject_2
1438
+ (projectHandle?: ProjectHandle): SanityProject_2
4406
1439
  }
4407
1440
 
4408
1441
  /**
@@ -4470,28 +1503,27 @@ export declare const useProject: UseProject
4470
1503
  * )
4471
1504
  * ```
4472
1505
  */
4473
- export declare function useProjection<TResult extends object>({
4474
- document: {_id, _type},
4475
- projection,
1506
+ export declare function useProjection<TData extends object>({
4476
1507
  ref,
4477
- }: UseProjectionOptions): UseProjectionResults<TResult>
1508
+ projection,
1509
+ ...docHandle
1510
+ }: UseProjectionOptions): UseProjectionResults<TData>
4478
1511
 
4479
1512
  /**
4480
1513
  * @public
4481
1514
  * @category Types
4482
1515
  */
4483
- export declare interface UseProjectionOptions {
4484
- document: DocumentHandle
4485
- projection: ValidProjection
1516
+ export declare interface UseProjectionOptions extends DocumentHandle {
4486
1517
  ref?: React.RefObject<unknown>
1518
+ projection: ValidProjection
4487
1519
  }
4488
1520
 
4489
1521
  /**
4490
1522
  * @public
4491
1523
  * @category Types
4492
1524
  */
4493
- export declare interface UseProjectionResults<TResult extends object> {
4494
- data: TResult
1525
+ export declare interface UseProjectionResults<TData extends object> {
1526
+ data: TData
4495
1527
  isPending: boolean
4496
1528
  }
4497
1529
 
@@ -4528,7 +1560,7 @@ export declare const useProjects: UseProjects
4528
1560
  * Executes GROQ queries against a Sanity dataset.
4529
1561
  *
4530
1562
  * This hook provides a convenient way to fetch and subscribe to real-time updates
4531
- * for your Sanity content. Changes made to the datasets content will trigger
1563
+ * for your Sanity content. Changes made to the dataset's content will trigger
4532
1564
  * automatic updates.
4533
1565
  *
4534
1566
  * @remarks
@@ -4538,7 +1570,7 @@ export declare const useProjects: UseProjects
4538
1570
  * @beta
4539
1571
  * @category GROQ
4540
1572
  * @param query - GROQ query string to execute
4541
- * @param options - Optional configuration for the query
1573
+ * @param options - Optional configuration for the query, including projectId and dataset
4542
1574
  * @returns Object containing the query result and a pending state flag
4543
1575
  *
4544
1576
  * @example Basic usage
@@ -4554,6 +1586,15 @@ export declare const useProjects: UseProjects
4554
1586
  * })
4555
1587
  * ```
4556
1588
  *
1589
+ * @example Query from a specific project/dataset
1590
+ * ```tsx
1591
+ * // Specify which project and dataset to query
1592
+ * const {data} = useQuery<Movie[]>('*[_type == "movie"]', {
1593
+ * projectId: 'abc123',
1594
+ * dataset: 'production'
1595
+ * })
1596
+ * ```
1597
+ *
4557
1598
  * @example With a loading state for transitions
4558
1599
  * ```tsx
4559
1600
  * const {data, isPending} = useQuery<Movie[]>('*[_type == "movie"]')
@@ -4612,49 +1653,105 @@ export declare function useRecordDocumentHistoryEvent({
4612
1653
  documentType,
4613
1654
  resourceType,
4614
1655
  resourceId,
1656
+ schemaName,
4615
1657
  }: UseRecordDocumentHistoryEventProps): DocumentInteractionHistory
4616
1658
 
4617
1659
  /**
4618
1660
  * @public
4619
1661
  */
4620
- declare interface UseRecordDocumentHistoryEventProps {
4621
- documentId: string
4622
- documentType: string
1662
+ declare interface UseRecordDocumentHistoryEventProps extends DocumentHandle {
4623
1663
  resourceType: StudioResource['type'] | MediaResource['type'] | CanvasResource['type']
4624
1664
  resourceId?: string
1665
+ /**
1666
+ * The name of the schema collection this document belongs to.
1667
+ * Typically is the name of the workspace when used in the context of a studio.
1668
+ */
1669
+ schemaName?: string
4625
1670
  }
4626
1671
 
4627
- /** @public */
4628
- declare class UsersClient {
4629
- #private
4630
- constructor(client: SanityClient, httpRequest: HttpRequest)
1672
+ /**
1673
+ * @public
1674
+ * @category Types
1675
+ */
1676
+ export declare interface UsersResult {
4631
1677
  /**
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.
1678
+ * The users fetched.
1679
+ */
1680
+ data: SanityUser[]
1681
+ /**
1682
+ * Whether there are more users to fetch.
1683
+ */
1684
+ hasMore: boolean
1685
+ /**
1686
+ * Whether a users request is currently in progress
1687
+ */
1688
+ isPending: boolean
1689
+ /**
1690
+ * Load more users.
4635
1691
  */
4636
- getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
1692
+ loadMore: () => void
4637
1693
  }
4638
1694
 
4639
1695
  /**
4640
- * `useSanityInstance` returns the current Sanity instance from the application context.
4641
- * This must be called from within a `SanityProvider` component.
4642
- * @internal
1696
+ * Retrieves the current Sanity instance or finds a matching instance from the hierarchy
4643
1697
  *
4644
- * @param resourceId - The resourceId of the Sanity instance to return (optional)
4645
- * @returns The current Sanity instance
4646
- * @example
1698
+ * @public
1699
+ *
1700
+ * @param config - Optional configuration to match against when finding an instance
1701
+ * @returns The current or matching Sanity instance
1702
+ *
1703
+ * @remarks
1704
+ * This hook accesses the nearest Sanity instance from the React context. When provided with
1705
+ * a configuration object, it traverses up the instance hierarchy to find the closest instance
1706
+ * that matches the specified configuration using shallow comparison of properties.
1707
+ *
1708
+ * The hook must be used within a component wrapped by a `ResourceProvider` or `SanityApp`.
1709
+ *
1710
+ * Use this hook when you need to:
1711
+ * - Access the current SanityInstance from context
1712
+ * - Find a specific instance with matching project/dataset configuration
1713
+ * - Access a parent instance with specific configuration values
1714
+ *
1715
+ * @example Get the current instance
4647
1716
  * ```tsx
4648
- * const instance = useSanityInstance('abc123.production')
1717
+ * // Get the current instance from context
1718
+ * const instance = useSanityInstance()
1719
+ * console.log(instance.config.projectId)
4649
1720
  * ```
1721
+ *
1722
+ * @example Find an instance with specific configuration
1723
+ * ```tsx
1724
+ * // Find an instance matching the given project and dataset
1725
+ * const instance = useSanityInstance({
1726
+ * projectId: 'abc123',
1727
+ * dataset: 'production'
1728
+ * })
1729
+ *
1730
+ * // Use instance for API calls
1731
+ * const fetchDocument = (docId) => {
1732
+ * // Instance is guaranteed to have the matching config
1733
+ * return client.fetch(`*[_id == $id][0]`, { id: docId })
1734
+ * }
1735
+ * ```
1736
+ *
1737
+ * @example Match partial configuration
1738
+ * ```tsx
1739
+ * // Find an instance with specific auth configuration
1740
+ * const instance = useSanityInstance({
1741
+ * auth: { requireLogin: true }
1742
+ * })
1743
+ * ```
1744
+ *
1745
+ * @throws Error if no SanityInstance is found in context
1746
+ * @throws Error if no matching instance is found for the provided config
4650
1747
  */
4651
- export declare const useSanityInstance: (resourceId?: string) => SanityInstance
1748
+ export declare const useSanityInstance: (config?: SanityConfig) => SanityInstance
4652
1749
 
4653
1750
  /**
4654
1751
  * Hook that fetches studio workspaces and organizes them by projectId:dataset
4655
1752
  * @internal
4656
1753
  */
4657
- export declare function useStudioWorkspacesByResourceId(): StudioWorkspacesResult
1754
+ export declare function useStudioWorkspacesByProjectIdDataset(): StudioWorkspacesResult
4658
1755
 
4659
1756
  /**
4660
1757
  *
@@ -4663,70 +1760,32 @@ export declare function useStudioWorkspacesByResourceId(): StudioWorkspacesResul
4663
1760
  * Retrieves the users for a given resource (either a project or an organization).
4664
1761
  *
4665
1762
  * @category Users
4666
- * @param params - The resource type and its ID, and the limit of users to fetch
1763
+ * @param params - The resource type, project ID, and the limit of users to fetch
4667
1764
  * @returns A list of users, a boolean indicating whether there are more users to fetch, and a function to load more users
4668
1765
  *
4669
1766
  * @example
4670
1767
  * ```
4671
- * const { users, hasMore, loadMore } = useUsers({
1768
+ * const { data, hasMore, loadMore, isPending } = useUsers({
4672
1769
  * resourceType: 'organization',
4673
- * resourceId: 'my-org-id',
4674
- * limit: 10,
1770
+ * organizationId: 'my-org-id',
1771
+ * batchSize: 10,
4675
1772
  * })
4676
1773
  *
4677
1774
  * return (
4678
1775
  * <div>
4679
- * {users.map(user => (
1776
+ * {data.map(user => (
4680
1777
  * <figure key={user.sanityUserId}>
4681
1778
  * <img src={user.profile.imageUrl} alt='' />
4682
1779
  * <figcaption>{user.profile.displayName}</figcaption>
4683
1780
  * <address>{user.profile.email}</address>
4684
1781
  * </figure>
4685
1782
  * ))}
4686
- * {hasMore && <button onClick={loadMore}>Load More</button>}
1783
+ * {hasMore && <button onClick={loadMore}>{isPending ? 'Loading...' : 'Load More'</button>}
4687
1784
  * </div>
4688
1785
  * )
4689
1786
  * ```
4690
1787
  */
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
- }
1788
+ export declare function useUsers(options?: GetUsersOptions): UsersResult
4730
1789
 
4731
1790
  /**
4732
1791
  * @internal
@@ -4757,17 +1816,6 @@ export declare interface UseWindowConnectionOptions<TMessage extends FrameMessag
4757
1816
  onStatus?: (status: ComlinkStatus) => void
4758
1817
  }
4759
1818
 
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
1819
  /**
4772
1820
  * @internal
4773
1821
  */
@@ -4809,8 +1857,10 @@ declare interface Workspace {
4809
1857
  _ref: string
4810
1858
  }
4811
1859
 
4812
- declare interface WorkspacesByResourceId {
4813
- [key: string]: Workspace[]
1860
+ declare interface WorkspacesByProjectIdDataset {
1861
+ [key: `${string}:${string}`]: Workspace[]
4814
1862
  }
4815
1863
 
1864
+ export * from '@sanity/sdk'
1865
+
4816
1866
  export {}