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