@sanity/sdk-react 0.0.0-alpha.7 → 0.0.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks.d.ts +3088 -0
- package/dist/hooks.js +18 -2
- package/dist/hooks.js.map +1 -1
- package/package.json +3 -3
- package/src/_exports/hooks.ts +1 -0
package/dist/hooks.d.ts
CHANGED
|
@@ -1,15 +1,633 @@
|
|
|
1
1
|
import {AuthProvider} from '@sanity/sdk'
|
|
2
2
|
import {AuthState} from '@sanity/sdk'
|
|
3
|
+
import {ClientOptions} from '@sanity/sdk'
|
|
3
4
|
import {CurrentUser} from '@sanity/sdk'
|
|
4
5
|
import {DocumentHandle} from '@sanity/sdk'
|
|
5
6
|
import {DocumentListOptions} from '@sanity/sdk'
|
|
6
7
|
import {FrameMessage} from '@sanity/sdk'
|
|
8
|
+
import {Observable} from 'rxjs'
|
|
7
9
|
import {PreviewValue} from '@sanity/sdk'
|
|
10
|
+
import {Requester} from 'get-it'
|
|
8
11
|
import {SanityInstance} from '@sanity/sdk'
|
|
9
12
|
import {WindowMessage} from '@sanity/sdk'
|
|
10
13
|
|
|
14
|
+
/** @public */
|
|
15
|
+
declare type Action =
|
|
16
|
+
| CreateAction
|
|
17
|
+
| ReplaceDraftAction
|
|
18
|
+
| EditAction
|
|
19
|
+
| DeleteAction
|
|
20
|
+
| DiscardAction
|
|
21
|
+
| PublishAction
|
|
22
|
+
| UnpublishAction
|
|
23
|
+
|
|
24
|
+
/** @internal */
|
|
25
|
+
declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
26
|
+
returnFirst: false
|
|
27
|
+
returnDocuments: false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @internal */
|
|
31
|
+
declare type AllDocumentsMutationOptions = BaseMutationOptions & {
|
|
32
|
+
returnFirst: false
|
|
33
|
+
returnDocuments?: true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Used to tag types that is set to `any` as a temporary measure, but should be replaced with proper typings in the future
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
declare type Any = any
|
|
41
|
+
|
|
42
|
+
/** @public */
|
|
43
|
+
declare type AssetMetadataType =
|
|
44
|
+
| 'location'
|
|
45
|
+
| 'exif'
|
|
46
|
+
| 'image'
|
|
47
|
+
| 'palette'
|
|
48
|
+
| 'lqip'
|
|
49
|
+
| 'blurhash'
|
|
50
|
+
| 'none'
|
|
51
|
+
|
|
52
|
+
/** @internal */
|
|
53
|
+
declare class AssetsClient {
|
|
54
|
+
#private
|
|
55
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
56
|
+
/**
|
|
57
|
+
* Uploads a file asset to the configured dataset
|
|
58
|
+
*
|
|
59
|
+
* @param assetType - Asset type (file)
|
|
60
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
61
|
+
* @param options - Options to use for the upload
|
|
62
|
+
*/
|
|
63
|
+
upload(
|
|
64
|
+
assetType: 'file',
|
|
65
|
+
body: UploadBody,
|
|
66
|
+
options?: UploadClientConfig,
|
|
67
|
+
): Promise<SanityAssetDocument>
|
|
68
|
+
/**
|
|
69
|
+
* Uploads an image asset to the configured dataset
|
|
70
|
+
*
|
|
71
|
+
* @param assetType - Asset type (image)
|
|
72
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
73
|
+
* @param options - Options to use for the upload
|
|
74
|
+
*/
|
|
75
|
+
upload(
|
|
76
|
+
assetType: 'image',
|
|
77
|
+
body: UploadBody,
|
|
78
|
+
options?: UploadClientConfig,
|
|
79
|
+
): Promise<SanityImageAssetDocument>
|
|
80
|
+
/**
|
|
81
|
+
* Uploads a file or an image asset to the configured dataset
|
|
82
|
+
*
|
|
83
|
+
* @param assetType - Asset type (file/image)
|
|
84
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
85
|
+
* @param options - Options to use for the upload
|
|
86
|
+
*/
|
|
87
|
+
upload(
|
|
88
|
+
assetType: 'file' | 'image',
|
|
89
|
+
body: UploadBody,
|
|
90
|
+
options?: UploadClientConfig,
|
|
91
|
+
): Promise<SanityAssetDocument | SanityImageAssetDocument>
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @internal */
|
|
95
|
+
declare type AttributeSet = {
|
|
96
|
+
[key: string]: Any
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** @internal */
|
|
100
|
+
declare type BaseActionOptions = RequestOptions & {
|
|
101
|
+
transactionId?: string
|
|
102
|
+
skipCrossDatasetReferenceValidation?: boolean
|
|
103
|
+
dryRun?: boolean
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @internal */
|
|
107
|
+
declare type BaseMutationOptions = RequestOptions & {
|
|
108
|
+
visibility?: 'sync' | 'async' | 'deferred'
|
|
109
|
+
returnDocuments?: boolean
|
|
110
|
+
returnFirst?: boolean
|
|
111
|
+
dryRun?: boolean
|
|
112
|
+
autoGenerateArrayKeys?: boolean
|
|
113
|
+
skipCrossDatasetReferenceValidation?: boolean
|
|
114
|
+
transactionId?: string
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** @internal */
|
|
118
|
+
declare class BasePatch {
|
|
119
|
+
protected selection: PatchSelection
|
|
120
|
+
protected operations: PatchOperations
|
|
121
|
+
constructor(selection: PatchSelection, operations?: PatchOperations)
|
|
122
|
+
/**
|
|
123
|
+
* Sets the given attributes to the document. Does NOT merge objects.
|
|
124
|
+
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
125
|
+
*
|
|
126
|
+
* @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
|
|
127
|
+
*/
|
|
128
|
+
set(attrs: AttributeSet): this
|
|
129
|
+
/**
|
|
130
|
+
* Sets the given attributes to the document if they are not currently set. Does NOT merge objects.
|
|
131
|
+
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
132
|
+
*
|
|
133
|
+
* @param attrs - Attributes to set. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "value"\}
|
|
134
|
+
*/
|
|
135
|
+
setIfMissing(attrs: AttributeSet): this
|
|
136
|
+
/**
|
|
137
|
+
* Performs a "diff-match-patch" operation on the string attributes provided.
|
|
138
|
+
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
139
|
+
*
|
|
140
|
+
* @param attrs - Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "dmp"\}
|
|
141
|
+
*/
|
|
142
|
+
diffMatchPatch(attrs: AttributeSet): this
|
|
143
|
+
/**
|
|
144
|
+
* Unsets the attribute paths provided.
|
|
145
|
+
* The operation is added to the current patch, ready to be commited by `commit()`
|
|
146
|
+
*
|
|
147
|
+
* @param attrs - Attribute paths to unset.
|
|
148
|
+
*/
|
|
149
|
+
unset(attrs: string[]): this
|
|
150
|
+
/**
|
|
151
|
+
* 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.
|
|
152
|
+
*
|
|
153
|
+
* @param attrs - Object of attribute paths to increment, values representing the number to increment by.
|
|
154
|
+
*/
|
|
155
|
+
inc(attrs: {[key: string]: number}): this
|
|
156
|
+
/**
|
|
157
|
+
* 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.
|
|
158
|
+
*
|
|
159
|
+
* @param attrs - Object of attribute paths to decrement, values representing the number to decrement by.
|
|
160
|
+
*/
|
|
161
|
+
dec(attrs: {[key: string]: number}): this
|
|
162
|
+
/**
|
|
163
|
+
* Provides methods for modifying arrays, by inserting, appending and replacing elements via a JSONPath expression.
|
|
164
|
+
*
|
|
165
|
+
* @param at - Location to insert at, relative to the given selector, or 'replace' the matched path
|
|
166
|
+
* @param selector - JSONPath expression, eg `comments[-1]` or `blocks[_key=="abc123"]`
|
|
167
|
+
* @param items - Array of items to insert/replace
|
|
168
|
+
*/
|
|
169
|
+
insert(at: 'before' | 'after' | 'replace', selector: string, items: Any[]): this
|
|
170
|
+
/**
|
|
171
|
+
* Append the given items to the array at the given JSONPath
|
|
172
|
+
*
|
|
173
|
+
* @param selector - Attribute/path to append to, eg `comments` or `person.hobbies`
|
|
174
|
+
* @param items - Array of items to append to the array
|
|
175
|
+
*/
|
|
176
|
+
append(selector: string, items: Any[]): this
|
|
177
|
+
/**
|
|
178
|
+
* Prepend the given items to the array at the given JSONPath
|
|
179
|
+
*
|
|
180
|
+
* @param selector - Attribute/path to prepend to, eg `comments` or `person.hobbies`
|
|
181
|
+
* @param items - Array of items to prepend to the array
|
|
182
|
+
*/
|
|
183
|
+
prepend(selector: string, items: Any[]): this
|
|
184
|
+
/**
|
|
185
|
+
* Change the contents of an array by removing existing elements and/or adding new elements.
|
|
186
|
+
*
|
|
187
|
+
* @param selector - Attribute or JSONPath expression for array
|
|
188
|
+
* @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
|
|
189
|
+
* @param deleteCount - An integer indicating the number of old array elements to remove.
|
|
190
|
+
* @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.
|
|
191
|
+
*/
|
|
192
|
+
splice(selector: string, start: number, deleteCount?: number, items?: Any[]): this
|
|
193
|
+
/**
|
|
194
|
+
* Adds a revision clause, preventing the document from being patched if the `_rev` property does not match the given value
|
|
195
|
+
*
|
|
196
|
+
* @param rev - Revision to lock the patch to
|
|
197
|
+
*/
|
|
198
|
+
ifRevisionId(rev: string): this
|
|
199
|
+
/**
|
|
200
|
+
* Return a plain JSON representation of the patch
|
|
201
|
+
*/
|
|
202
|
+
serialize(): PatchMutationOperation
|
|
203
|
+
/**
|
|
204
|
+
* Return a plain JSON representation of the patch
|
|
205
|
+
*/
|
|
206
|
+
toJSON(): PatchMutationOperation
|
|
207
|
+
/**
|
|
208
|
+
* Clears the patch of all operations
|
|
209
|
+
*/
|
|
210
|
+
reset(): this
|
|
211
|
+
protected _assign(op: keyof PatchOperations, props: Any, merge?: boolean): this
|
|
212
|
+
protected _set(op: keyof PatchOperations, props: Any): this
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** @internal */
|
|
216
|
+
declare class BaseTransaction {
|
|
217
|
+
protected operations: Mutation[]
|
|
218
|
+
protected trxId?: string
|
|
219
|
+
constructor(operations?: Mutation[], transactionId?: string)
|
|
220
|
+
/**
|
|
221
|
+
* 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.
|
|
222
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
223
|
+
*
|
|
224
|
+
* @param doc - Document to create. Requires a `_type` property.
|
|
225
|
+
*/
|
|
226
|
+
create<R extends Record<string, Any> = Record<string, Any>>(doc: SanityDocumentStub<R>): this
|
|
227
|
+
/**
|
|
228
|
+
* Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
|
|
229
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
230
|
+
*
|
|
231
|
+
* @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
|
|
232
|
+
*/
|
|
233
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
234
|
+
doc: IdentifiedSanityDocumentStub<R>,
|
|
235
|
+
): this
|
|
236
|
+
/**
|
|
237
|
+
* Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
|
|
238
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
239
|
+
*
|
|
240
|
+
* @param doc - Document to create or replace. Requires `_id` and `_type` properties.
|
|
241
|
+
*/
|
|
242
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
243
|
+
doc: IdentifiedSanityDocumentStub<R>,
|
|
244
|
+
): this
|
|
245
|
+
/**
|
|
246
|
+
* Deletes the document with the given document ID
|
|
247
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
248
|
+
*
|
|
249
|
+
* @param documentId - Document ID to delete
|
|
250
|
+
*/
|
|
251
|
+
delete(documentId: string): this
|
|
252
|
+
/**
|
|
253
|
+
* Gets the current transaction ID, if any
|
|
254
|
+
*/
|
|
255
|
+
transactionId(): string | undefined
|
|
256
|
+
/**
|
|
257
|
+
* Set the ID of this transaction.
|
|
258
|
+
*
|
|
259
|
+
* @param id - Transaction ID
|
|
260
|
+
*/
|
|
261
|
+
transactionId(id: string): this
|
|
262
|
+
/**
|
|
263
|
+
* Return a plain JSON representation of the transaction
|
|
264
|
+
*/
|
|
265
|
+
serialize(): Mutation[]
|
|
266
|
+
/**
|
|
267
|
+
* Return a plain JSON representation of the transaction
|
|
268
|
+
*/
|
|
269
|
+
toJSON(): Mutation[]
|
|
270
|
+
/**
|
|
271
|
+
* Clears the transaction of all operations
|
|
272
|
+
*/
|
|
273
|
+
reset(): this
|
|
274
|
+
protected _add(mut: Mutation): this
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* An error occurred. This is different from a network-level error (which will be emitted as 'error').
|
|
279
|
+
* Possible causes are things such as malformed filters, non-existant datasets or similar.
|
|
280
|
+
*
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
declare type ChannelErrorEvent = {
|
|
284
|
+
type: 'channelError'
|
|
285
|
+
message: string
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** @public */
|
|
289
|
+
declare interface ClientConfig {
|
|
290
|
+
projectId?: string
|
|
291
|
+
dataset?: string
|
|
292
|
+
/** @defaultValue true */
|
|
293
|
+
useCdn?: boolean
|
|
294
|
+
token?: string
|
|
295
|
+
/** @defaultValue 'raw' */
|
|
296
|
+
perspective?: ClientPerspective
|
|
297
|
+
apiHost?: string
|
|
298
|
+
apiVersion?: string
|
|
299
|
+
proxy?: string
|
|
300
|
+
/**
|
|
301
|
+
* Optional request tag prefix for all request tags
|
|
302
|
+
*/
|
|
303
|
+
requestTagPrefix?: string
|
|
304
|
+
ignoreBrowserTokenWarning?: boolean
|
|
305
|
+
withCredentials?: boolean
|
|
306
|
+
allowReconfigure?: boolean
|
|
307
|
+
timeout?: number
|
|
308
|
+
/** Number of retries for requests. Defaults to 5. */
|
|
309
|
+
maxRetries?: number
|
|
310
|
+
/**
|
|
311
|
+
* The amount of time, in milliseconds, to wait before retrying, given an attemptNumber (starting at 0).
|
|
312
|
+
*
|
|
313
|
+
* Defaults to exponential back-off, starting at 100ms, doubling for each attempt, together with random
|
|
314
|
+
* jitter between 0 and 100 milliseconds. More specifically the following algorithm is used:
|
|
315
|
+
*
|
|
316
|
+
* Delay = 100 * 2^attemptNumber + randomNumberBetween0and100
|
|
317
|
+
*/
|
|
318
|
+
retryDelay?: (attemptNumber: number) => number
|
|
319
|
+
/**
|
|
320
|
+
* @deprecated Don't use
|
|
321
|
+
*/
|
|
322
|
+
useProjectHostname?: boolean
|
|
323
|
+
/**
|
|
324
|
+
* @deprecated Don't use
|
|
325
|
+
*/
|
|
326
|
+
requester?: Requester
|
|
327
|
+
/**
|
|
328
|
+
* Adds a `resultSourceMap` key to the API response, with the type `ContentSourceMap`
|
|
329
|
+
*/
|
|
330
|
+
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
331
|
+
/**
|
|
332
|
+
*@deprecated set `cache` and `next` options on `client.fetch` instead
|
|
333
|
+
*/
|
|
334
|
+
fetch?:
|
|
335
|
+
| {
|
|
336
|
+
cache?: ResponseQueryOptions['cache']
|
|
337
|
+
next?: ResponseQueryOptions['next']
|
|
338
|
+
}
|
|
339
|
+
| boolean
|
|
340
|
+
/**
|
|
341
|
+
* Options for how, if enabled, Content Source Maps are encoded into query results using steganography
|
|
342
|
+
*/
|
|
343
|
+
stega?: StegaConfig | boolean
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** @public */
|
|
347
|
+
declare type ClientPerspective =
|
|
348
|
+
| 'previewDrafts'
|
|
349
|
+
| 'published'
|
|
350
|
+
| 'drafts'
|
|
351
|
+
| 'raw'
|
|
352
|
+
| ('published' | 'drafts' | ReleaseId)[]
|
|
353
|
+
|
|
354
|
+
/** @public */
|
|
355
|
+
declare type ClientReturn<
|
|
356
|
+
GroqString extends string,
|
|
357
|
+
Fallback = Any,
|
|
358
|
+
> = GroqString extends keyof SanityQueries ? SanityQueries[GroqString] : Fallback
|
|
359
|
+
|
|
360
|
+
/** @public */
|
|
361
|
+
declare interface ContentSourceMap {
|
|
362
|
+
mappings: ContentSourceMapMappings
|
|
363
|
+
documents: ContentSourceMapDocuments_2
|
|
364
|
+
paths: ContentSourceMapPaths
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** @public */
|
|
368
|
+
declare interface ContentSourceMapDocument extends ContentSourceMapDocumentBase {
|
|
369
|
+
_projectId?: undefined
|
|
370
|
+
_dataset?: undefined
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** @public */
|
|
374
|
+
declare interface ContentSourceMapDocument_2 extends ContentSourceMapDocumentBase_2 {
|
|
375
|
+
_projectId?: undefined
|
|
376
|
+
_dataset?: undefined
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** @public */
|
|
380
|
+
declare interface ContentSourceMapDocumentBase {
|
|
381
|
+
_id: string
|
|
382
|
+
_type: string
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** @public */
|
|
386
|
+
declare interface ContentSourceMapDocumentBase_2 {
|
|
387
|
+
_id: string
|
|
388
|
+
_type: string
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** @public */
|
|
392
|
+
declare type ContentSourceMapDocuments = (
|
|
393
|
+
| ContentSourceMapDocument
|
|
394
|
+
| ContentSourceMapRemoteDocument
|
|
395
|
+
)[]
|
|
396
|
+
|
|
397
|
+
/** @public */
|
|
398
|
+
declare type ContentSourceMapDocuments_2 = (
|
|
399
|
+
| ContentSourceMapDocument_2
|
|
400
|
+
| ContentSourceMapRemoteDocument_2
|
|
401
|
+
)[]
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* DocumentValueSource is a path to a value within a document
|
|
405
|
+
* @public
|
|
406
|
+
*/
|
|
407
|
+
declare interface ContentSourceMapDocumentValueSource {
|
|
408
|
+
type: 'documentValue'
|
|
409
|
+
document: number
|
|
410
|
+
path: number
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* When a value is not from a source, its a literal
|
|
415
|
+
* @public
|
|
416
|
+
*/
|
|
417
|
+
declare interface ContentSourceMapLiteralSource {
|
|
418
|
+
type: 'literal'
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** @public */
|
|
422
|
+
declare type ContentSourceMapMapping = ContentSourceMapValueMapping
|
|
423
|
+
|
|
424
|
+
/** @public */
|
|
425
|
+
declare type ContentSourceMapMappings = Record<string, ContentSourceMapMapping>
|
|
426
|
+
|
|
427
|
+
/** @alpha */
|
|
428
|
+
declare type ContentSourceMapParsedPath = (
|
|
429
|
+
| string
|
|
430
|
+
| number
|
|
431
|
+
| ContentSourceMapParsedPathKeyedSegment
|
|
432
|
+
)[]
|
|
433
|
+
|
|
434
|
+
/** @alpha */
|
|
435
|
+
declare type ContentSourceMapParsedPathKeyedSegment = {
|
|
436
|
+
_key: string
|
|
437
|
+
_index: number
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** @public */
|
|
441
|
+
declare type ContentSourceMapPaths = string[]
|
|
442
|
+
|
|
443
|
+
/** @public */
|
|
444
|
+
declare interface ContentSourceMapRemoteDocument extends ContentSourceMapDocumentBase {
|
|
445
|
+
_projectId: string
|
|
446
|
+
_dataset: string
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** @public */
|
|
450
|
+
declare interface ContentSourceMapRemoteDocument_2 extends ContentSourceMapDocumentBase_2 {
|
|
451
|
+
_projectId: string
|
|
452
|
+
_dataset: string
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** @public */
|
|
456
|
+
declare type ContentSourceMapSource =
|
|
457
|
+
| ContentSourceMapDocumentValueSource
|
|
458
|
+
| ContentSourceMapLiteralSource
|
|
459
|
+
| ContentSourceMapUnknownSource
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* When a field source is unknown
|
|
463
|
+
* @public
|
|
464
|
+
*/
|
|
465
|
+
declare interface ContentSourceMapUnknownSource {
|
|
466
|
+
type: 'unknown'
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* ValueMapping is a mapping when for value that is from a single source value
|
|
471
|
+
* It may refer to a field within a document or a literal value
|
|
472
|
+
* @public
|
|
473
|
+
*/
|
|
474
|
+
declare interface ContentSourceMapValueMapping {
|
|
475
|
+
type: 'value'
|
|
476
|
+
source: ContentSourceMapSource
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Creates a new draft document. The published version of the document must not already exist.
|
|
481
|
+
* If the draft version of the document already exists the action will fail by default, but
|
|
482
|
+
* this can be adjusted to instead leave the existing document in place.
|
|
483
|
+
*
|
|
484
|
+
* @public
|
|
485
|
+
*/
|
|
486
|
+
declare type CreateAction = {
|
|
487
|
+
actionType: 'sanity.action.document.create'
|
|
488
|
+
/**
|
|
489
|
+
* ID of the published document to create a draft for.
|
|
490
|
+
*/
|
|
491
|
+
publishedId: string
|
|
492
|
+
/**
|
|
493
|
+
* Document to create. Requires a `_type` property.
|
|
494
|
+
*/
|
|
495
|
+
attributes: IdentifiedSanityDocumentStub
|
|
496
|
+
/**
|
|
497
|
+
* ifExists controls what to do if the draft already exists
|
|
498
|
+
*/
|
|
499
|
+
ifExists: 'fail' | 'ignore'
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** @internal */
|
|
503
|
+
declare interface CurrentSanityUser {
|
|
504
|
+
id: string
|
|
505
|
+
name: string
|
|
506
|
+
email: string
|
|
507
|
+
profileImage: string | null
|
|
508
|
+
role: string
|
|
509
|
+
}
|
|
510
|
+
|
|
11
511
|
export {CurrentUser}
|
|
12
512
|
|
|
513
|
+
/** @internal */
|
|
514
|
+
declare type DatasetAclMode = 'public' | 'private' | 'custom'
|
|
515
|
+
|
|
516
|
+
/** @internal */
|
|
517
|
+
declare type DatasetResponse = {
|
|
518
|
+
datasetName: string
|
|
519
|
+
aclMode: DatasetAclMode
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** @internal */
|
|
523
|
+
declare class DatasetsClient {
|
|
524
|
+
#private
|
|
525
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
526
|
+
/**
|
|
527
|
+
* Create a new dataset with the given name
|
|
528
|
+
*
|
|
529
|
+
* @param name - Name of the dataset to create
|
|
530
|
+
* @param options - Options for the dataset
|
|
531
|
+
*/
|
|
532
|
+
create(
|
|
533
|
+
name: string,
|
|
534
|
+
options?: {
|
|
535
|
+
aclMode?: DatasetAclMode
|
|
536
|
+
},
|
|
537
|
+
): Promise<DatasetResponse>
|
|
538
|
+
/**
|
|
539
|
+
* Edit a dataset with the given name
|
|
540
|
+
*
|
|
541
|
+
* @param name - Name of the dataset to edit
|
|
542
|
+
* @param options - New options for the dataset
|
|
543
|
+
*/
|
|
544
|
+
edit(
|
|
545
|
+
name: string,
|
|
546
|
+
options?: {
|
|
547
|
+
aclMode?: DatasetAclMode
|
|
548
|
+
},
|
|
549
|
+
): Promise<DatasetResponse>
|
|
550
|
+
/**
|
|
551
|
+
* Delete a dataset with the given name
|
|
552
|
+
*
|
|
553
|
+
* @param name - Name of the dataset to delete
|
|
554
|
+
*/
|
|
555
|
+
delete(name: string): Promise<{
|
|
556
|
+
deleted: true
|
|
557
|
+
}>
|
|
558
|
+
/**
|
|
559
|
+
* Fetch a list of datasets for the configured project
|
|
560
|
+
*/
|
|
561
|
+
list(): Promise<DatasetsResponse>
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** @internal */
|
|
565
|
+
declare type DatasetsResponse = {
|
|
566
|
+
name: string
|
|
567
|
+
aclMode: DatasetAclMode
|
|
568
|
+
createdAt: string
|
|
569
|
+
createdByUserId: string
|
|
570
|
+
addonFor: string | null
|
|
571
|
+
datasetProfile: string
|
|
572
|
+
features: string[]
|
|
573
|
+
tags: string[]
|
|
574
|
+
}[]
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
578
|
+
* If any draft version exists that is not specified for deletion this is an error.
|
|
579
|
+
* If the purge flag is set then the document history is also deleted.
|
|
580
|
+
*
|
|
581
|
+
* @public
|
|
582
|
+
*/
|
|
583
|
+
declare type DeleteAction = {
|
|
584
|
+
actionType: 'sanity.action.document.delete'
|
|
585
|
+
/**
|
|
586
|
+
* Published document ID to delete
|
|
587
|
+
*/
|
|
588
|
+
publishedId: string
|
|
589
|
+
/**
|
|
590
|
+
* Draft document ID to delete
|
|
591
|
+
*/
|
|
592
|
+
includeDrafts: string[]
|
|
593
|
+
/**
|
|
594
|
+
* Delete document history
|
|
595
|
+
*/
|
|
596
|
+
purge?: boolean
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Delete the draft version of a document.
|
|
601
|
+
* It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
|
|
602
|
+
*
|
|
603
|
+
* @public
|
|
604
|
+
*/
|
|
605
|
+
declare type DiscardAction = {
|
|
606
|
+
actionType: 'sanity.action.document.discard'
|
|
607
|
+
/**
|
|
608
|
+
* Draft document ID to delete
|
|
609
|
+
*/
|
|
610
|
+
draftId: string
|
|
611
|
+
/**
|
|
612
|
+
* Delete document history
|
|
613
|
+
*/
|
|
614
|
+
purge?: boolean
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* The listener has been told to explicitly disconnect and not reconnect.
|
|
619
|
+
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
620
|
+
* eg in the case of a deleted dataset, a blocked project or similar events.
|
|
621
|
+
*
|
|
622
|
+
* Note that this is not treated as an error on the observable, but will complete the observable.
|
|
623
|
+
*
|
|
624
|
+
* @public
|
|
625
|
+
*/
|
|
626
|
+
declare type DisconnectEvent = {
|
|
627
|
+
type: 'disconnect'
|
|
628
|
+
reason: string
|
|
629
|
+
}
|
|
630
|
+
|
|
13
631
|
/**
|
|
14
632
|
* @public
|
|
15
633
|
*/
|
|
@@ -26,6 +644,95 @@ export declare interface DocumentCollection {
|
|
|
26
644
|
count: number
|
|
27
645
|
}
|
|
28
646
|
|
|
647
|
+
/**
|
|
648
|
+
* Modifies an existing draft document.
|
|
649
|
+
* It applies the given patch to the document referenced by draftId.
|
|
650
|
+
* If there is no such document then one is created using the current state of the published version and then that is updated accordingly.
|
|
651
|
+
*
|
|
652
|
+
* @public
|
|
653
|
+
*/
|
|
654
|
+
declare type EditAction = {
|
|
655
|
+
actionType: 'sanity.action.document.edit'
|
|
656
|
+
/**
|
|
657
|
+
* Draft document ID to edit
|
|
658
|
+
*/
|
|
659
|
+
draftId: string
|
|
660
|
+
/**
|
|
661
|
+
* Published document ID to create draft from, if draft does not exist
|
|
662
|
+
*/
|
|
663
|
+
publishedId: string
|
|
664
|
+
/**
|
|
665
|
+
* Patch operations to apply
|
|
666
|
+
*/
|
|
667
|
+
patch: PatchOperations
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/** @public */
|
|
671
|
+
declare type FilterDefault = (props: {
|
|
672
|
+
/**
|
|
673
|
+
* The path to the value in the source document, for example if you queried for a document like this:
|
|
674
|
+
* `*[_type == "author"][0]{"slug": slug.current}`
|
|
675
|
+
* Then the `sourcePath` for `result.slug` would be `['slug', 'current']`.
|
|
676
|
+
*
|
|
677
|
+
*/
|
|
678
|
+
sourcePath: ContentSourceMapParsedPath
|
|
679
|
+
/**
|
|
680
|
+
* If `sourcePath` alone isn't enough to tell you if it's safe to contain stega strings, then you can use `sourceDocument`
|
|
681
|
+
* for additional metadata.
|
|
682
|
+
* It'll always have a `_type` property, which can be used to trace it to the Studio Schema that were used initially.
|
|
683
|
+
* It also has `_id` to help you debug and look at the whole document when troubleshooting.
|
|
684
|
+
* Finally, if the document origins in a Cross Dataset Reference you'll also have `_projectId` and `_dataset` properties to help you trace it.
|
|
685
|
+
*/
|
|
686
|
+
sourceDocument: ContentSourceMapDocuments[number]
|
|
687
|
+
/**
|
|
688
|
+
* If you don't colocate your Studio Schemas with your GROQ queries it might be hard to make sense of `sourcePath`,
|
|
689
|
+
* as it operates on the original shape of a document.
|
|
690
|
+
* In that case `resultPath` can be used, as it mirrors the path to the value in the result.
|
|
691
|
+
* For example in a query like this:
|
|
692
|
+
* `*[_type == "author"][0]{"slug": slug.current}`
|
|
693
|
+
* The `resultPath` for `result.slug` would be `['slug']`, while `sourcePath` will be `['slug', 'current']`.
|
|
694
|
+
*/
|
|
695
|
+
resultPath: ContentSourceMapParsedPath
|
|
696
|
+
/**
|
|
697
|
+
* You can also use your own string validation logic to determine if it's safe.
|
|
698
|
+
*/
|
|
699
|
+
value: string
|
|
700
|
+
/**
|
|
701
|
+
* If you want to keep the default filtering behavior, but only override it for a specific path, you can use `filterDefault` to do that.
|
|
702
|
+
* For example, here all "icon" documents in a Page Builder skips encoding:
|
|
703
|
+
* ```ts
|
|
704
|
+
{
|
|
705
|
+
filter: (props) => {
|
|
706
|
+
switch (props.sourceDocument._type) {
|
|
707
|
+
case 'icon':
|
|
708
|
+
return false
|
|
709
|
+
default:
|
|
710
|
+
return props.filterDefault(props)
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
716
|
+
filterDefault: FilterDefault
|
|
717
|
+
}) => boolean
|
|
718
|
+
|
|
719
|
+
/** @public */
|
|
720
|
+
declare interface FilteredResponseQueryOptions extends ResponseQueryOptions {
|
|
721
|
+
filterResponse?: true
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/** @internal */
|
|
725
|
+
declare type FirstDocumentIdMutationOptions = BaseMutationOptions & {
|
|
726
|
+
returnFirst?: true
|
|
727
|
+
returnDocuments: false
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
/** @internal */
|
|
731
|
+
declare type FirstDocumentMutationOptions = BaseMutationOptions & {
|
|
732
|
+
returnFirst?: true
|
|
733
|
+
returnDocuments?: true
|
|
734
|
+
}
|
|
735
|
+
|
|
29
736
|
/**
|
|
30
737
|
* @internal
|
|
31
738
|
*/
|
|
@@ -51,6 +758,227 @@ export declare interface FrameConnection<TFrameMessage extends FrameMessage> {
|
|
|
51
758
|
) => void
|
|
52
759
|
}
|
|
53
760
|
|
|
761
|
+
/** @public */
|
|
762
|
+
declare type HttpRequest = {
|
|
763
|
+
(options: RequestOptions, requester: Requester): ReturnType<Requester>
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/** @public */
|
|
767
|
+
declare type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent_2
|
|
768
|
+
|
|
769
|
+
/** @public */
|
|
770
|
+
declare type IdentifiedSanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
|
|
771
|
+
[P in keyof T]: T[P]
|
|
772
|
+
} & {
|
|
773
|
+
_id: string
|
|
774
|
+
} & SanityDocumentStub
|
|
775
|
+
|
|
776
|
+
/** @public */
|
|
777
|
+
declare interface InitializedClientConfig extends ClientConfig {
|
|
778
|
+
apiHost: string
|
|
779
|
+
apiVersion: string
|
|
780
|
+
useProjectHostname: boolean
|
|
781
|
+
useCdn: boolean
|
|
782
|
+
/**
|
|
783
|
+
* @deprecated Internal, don't use
|
|
784
|
+
*/
|
|
785
|
+
isDefaultApi: boolean
|
|
786
|
+
/**
|
|
787
|
+
* @deprecated Internal, don't use
|
|
788
|
+
*/
|
|
789
|
+
url: string
|
|
790
|
+
/**
|
|
791
|
+
* @deprecated Internal, don't use
|
|
792
|
+
*/
|
|
793
|
+
cdnUrl: string
|
|
794
|
+
/**
|
|
795
|
+
* The fully initialized stega config, can be used to check if stega is enabled
|
|
796
|
+
*/
|
|
797
|
+
stega: InitializedStegaConfig
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/** @public */
|
|
801
|
+
declare type InitializedStegaConfig = Omit<StegaConfig, StegaConfigRequiredKeys> &
|
|
802
|
+
Required<Pick<StegaConfig, StegaConfigRequiredKeys>>
|
|
803
|
+
|
|
804
|
+
/** @internal */
|
|
805
|
+
declare type InsertPatch =
|
|
806
|
+
| {
|
|
807
|
+
before: string
|
|
808
|
+
items: Any[]
|
|
809
|
+
}
|
|
810
|
+
| {
|
|
811
|
+
after: string
|
|
812
|
+
items: Any[]
|
|
813
|
+
}
|
|
814
|
+
| {
|
|
815
|
+
replace: string
|
|
816
|
+
items: Any[]
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
821
|
+
*
|
|
822
|
+
* @param query - GROQ-filter to listen to changes for
|
|
823
|
+
* @param params - Optional query parameters
|
|
824
|
+
* @param options - Optional listener options
|
|
825
|
+
* @public
|
|
826
|
+
*/
|
|
827
|
+
declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
828
|
+
this: SanityClient | ObservableSanityClient,
|
|
829
|
+
query: string,
|
|
830
|
+
params?: ListenParams,
|
|
831
|
+
): Observable<MutationEvent_2<R>>
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
|
|
835
|
+
*
|
|
836
|
+
* @param query - GROQ-filter to listen to changes for
|
|
837
|
+
* @param params - Optional query parameters
|
|
838
|
+
* @param options - Optional listener options
|
|
839
|
+
* @public
|
|
840
|
+
*/
|
|
841
|
+
declare function _listen<R extends Record<string, Any> = Record<string, Any>>(
|
|
842
|
+
this: SanityClient | ObservableSanityClient,
|
|
843
|
+
query: string,
|
|
844
|
+
params?: ListenParams,
|
|
845
|
+
options?: ListenOptions,
|
|
846
|
+
): Observable<ListenEvent<R>>
|
|
847
|
+
|
|
848
|
+
/** @public */
|
|
849
|
+
declare type ListenEvent<R extends Record<string, Any>> =
|
|
850
|
+
| MutationEvent_2<R>
|
|
851
|
+
| ChannelErrorEvent
|
|
852
|
+
| DisconnectEvent
|
|
853
|
+
| ReconnectEvent
|
|
854
|
+
| WelcomeEvent
|
|
855
|
+
| OpenEvent
|
|
856
|
+
|
|
857
|
+
/** @public */
|
|
858
|
+
declare type ListenEventName =
|
|
859
|
+
/** A mutation was performed */
|
|
860
|
+
| 'mutation'
|
|
861
|
+
/** The listener has been (re)established */
|
|
862
|
+
| 'welcome'
|
|
863
|
+
/** The listener has been disconnected, and a reconnect attempt is scheduled */
|
|
864
|
+
| 'reconnect'
|
|
865
|
+
|
|
866
|
+
/** @public */
|
|
867
|
+
declare interface ListenOptions {
|
|
868
|
+
/**
|
|
869
|
+
* Whether or not to include the resulting document in addition to the mutations performed.
|
|
870
|
+
* If you do not need the actual document, set this to `false` to reduce bandwidth usage.
|
|
871
|
+
* The result will be available on the `.result` property of the events.
|
|
872
|
+
* @defaultValue `true`
|
|
873
|
+
*/
|
|
874
|
+
includeResult?: boolean
|
|
875
|
+
/**
|
|
876
|
+
* Whether or not to include the mutations that was performed.
|
|
877
|
+
* If you do not need the mutations, set this to `false` to reduce bandwidth usage.
|
|
878
|
+
* @defaultValue `true`
|
|
879
|
+
*/
|
|
880
|
+
includeMutations?: boolean
|
|
881
|
+
/**
|
|
882
|
+
* Whether or not to include the document as it looked before the mutation event.
|
|
883
|
+
* The previous revision will be available on the `.previous` property of the events,
|
|
884
|
+
* and may be `null` in the case of a new document.
|
|
885
|
+
* @defaultValue `false`
|
|
886
|
+
*/
|
|
887
|
+
includePreviousRevision?: boolean
|
|
888
|
+
/**
|
|
889
|
+
* Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
|
|
890
|
+
* or only after they are available for queries (query). Note that this is on a best-effort basis,
|
|
891
|
+
* and listeners with `query` may in certain cases (notably with deferred transactions) receive events
|
|
892
|
+
* that are not yet visible to queries.
|
|
893
|
+
*
|
|
894
|
+
* @defaultValue `'transaction'`
|
|
895
|
+
*/
|
|
896
|
+
visibility?: 'transaction' | 'query'
|
|
897
|
+
/**
|
|
898
|
+
* Array of event names to include in the observable. By default, only mutation events are included.
|
|
899
|
+
*
|
|
900
|
+
* @defaultValue `['mutation']`
|
|
901
|
+
*/
|
|
902
|
+
events?: ListenEventName[]
|
|
903
|
+
/**
|
|
904
|
+
* Format of "effects", eg the resulting changes of a mutation.
|
|
905
|
+
* Currently only `mendoza` is supported, and (if set) will include `apply` and `revert` arrays
|
|
906
|
+
* in the mutation events under the `effects` property.
|
|
907
|
+
*
|
|
908
|
+
* See {@link https://github.com/sanity-io/mendoza | The mendoza docs} for more info
|
|
909
|
+
*
|
|
910
|
+
* @defaultValue `undefined`
|
|
911
|
+
*/
|
|
912
|
+
effectFormat?: 'mendoza'
|
|
913
|
+
/**
|
|
914
|
+
* Optional request tag for the listener. Use to identify the request in logs.
|
|
915
|
+
*
|
|
916
|
+
* @defaultValue `undefined`
|
|
917
|
+
*/
|
|
918
|
+
tag?: string
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/** @public */
|
|
922
|
+
declare type ListenParams = {
|
|
923
|
+
[key: string]: Any
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* @public
|
|
928
|
+
*/
|
|
929
|
+
declare class LiveClient {
|
|
930
|
+
#private
|
|
931
|
+
constructor(client: SanityClient | ObservableSanityClient)
|
|
932
|
+
/**
|
|
933
|
+
* Requires `apiVersion` to be `2021-03-25` or later.
|
|
934
|
+
*/
|
|
935
|
+
events({
|
|
936
|
+
includeDrafts,
|
|
937
|
+
tag: _tag,
|
|
938
|
+
}?: {
|
|
939
|
+
includeDrafts?: boolean
|
|
940
|
+
/**
|
|
941
|
+
* Optional request tag for the listener. Use to identify the request in logs.
|
|
942
|
+
*
|
|
943
|
+
* @defaultValue `undefined`
|
|
944
|
+
*/
|
|
945
|
+
tag?: string
|
|
946
|
+
}): Observable<LiveEvent>
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/** @public */
|
|
950
|
+
declare type LiveEvent = LiveEventRestart | LiveEventReconnect | LiveEventMessage | LiveEventWelcome
|
|
951
|
+
|
|
952
|
+
/** @public */
|
|
953
|
+
declare interface LiveEventMessage {
|
|
954
|
+
type: 'message'
|
|
955
|
+
id: string
|
|
956
|
+
tags: SyncTag[]
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/** @public */
|
|
960
|
+
declare interface LiveEventReconnect {
|
|
961
|
+
type: 'reconnect'
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/** @public */
|
|
965
|
+
declare interface LiveEventRestart {
|
|
966
|
+
type: 'restart'
|
|
967
|
+
id: string
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/** @public */
|
|
971
|
+
declare interface LiveEventWelcome {
|
|
972
|
+
type: 'welcome'
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/** @public */
|
|
976
|
+
declare type Logger =
|
|
977
|
+
| typeof console
|
|
978
|
+
| Partial<
|
|
979
|
+
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
980
|
+
>
|
|
981
|
+
|
|
54
982
|
/**
|
|
55
983
|
* @internal
|
|
56
984
|
*/
|
|
@@ -58,6 +986,2116 @@ export declare type MessageHandler<TWindowMessage extends WindowMessage> = (
|
|
|
58
986
|
event: TWindowMessage['data'],
|
|
59
987
|
) => TWindowMessage['response'] | Promise<TWindowMessage['response']>
|
|
60
988
|
|
|
989
|
+
/** @internal */
|
|
990
|
+
declare interface MultipleActionResult {
|
|
991
|
+
transactionId: string
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
/** @internal */
|
|
995
|
+
declare interface MultipleMutationResult {
|
|
996
|
+
transactionId: string
|
|
997
|
+
documentIds: string[]
|
|
998
|
+
results: {
|
|
999
|
+
id: string
|
|
1000
|
+
operation: MutationOperation
|
|
1001
|
+
}[]
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/** @public */
|
|
1005
|
+
declare type Mutation<R extends Record<string, Any> = Record<string, Any>> =
|
|
1006
|
+
| {
|
|
1007
|
+
create: SanityDocumentStub<R>
|
|
1008
|
+
}
|
|
1009
|
+
| {
|
|
1010
|
+
createOrReplace: IdentifiedSanityDocumentStub<R>
|
|
1011
|
+
}
|
|
1012
|
+
| {
|
|
1013
|
+
createIfNotExists: IdentifiedSanityDocumentStub<R>
|
|
1014
|
+
}
|
|
1015
|
+
| {
|
|
1016
|
+
delete: MutationSelection
|
|
1017
|
+
}
|
|
1018
|
+
| {
|
|
1019
|
+
patch: PatchMutationOperation
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* A mutation was performed. Note that when updating multiple documents in a transaction,
|
|
1024
|
+
* each document affected will get a separate mutation event.
|
|
1025
|
+
*
|
|
1026
|
+
* @public
|
|
1027
|
+
*/
|
|
1028
|
+
declare type MutationEvent_2<R extends Record<string, Any> = Record<string, Any>> = {
|
|
1029
|
+
type: 'mutation'
|
|
1030
|
+
/**
|
|
1031
|
+
* The ID of the document that was affected
|
|
1032
|
+
*/
|
|
1033
|
+
documentId: string
|
|
1034
|
+
/**
|
|
1035
|
+
* A unique ID for this event
|
|
1036
|
+
*/
|
|
1037
|
+
eventId: string
|
|
1038
|
+
/**
|
|
1039
|
+
* The user ID of the user that performed the mutation
|
|
1040
|
+
*/
|
|
1041
|
+
identity: string
|
|
1042
|
+
/**
|
|
1043
|
+
* An array of mutations that were performed. Note that this can differ slightly from the
|
|
1044
|
+
* mutations sent to the server, as the server may perform some mutations automatically.
|
|
1045
|
+
*/
|
|
1046
|
+
mutations: Mutation[]
|
|
1047
|
+
/**
|
|
1048
|
+
* The revision ID of the document before the mutation was performed
|
|
1049
|
+
*/
|
|
1050
|
+
previousRev?: string
|
|
1051
|
+
/**
|
|
1052
|
+
* The revision ID of the document after the mutation was performed
|
|
1053
|
+
*/
|
|
1054
|
+
resultRev?: string
|
|
1055
|
+
/**
|
|
1056
|
+
* The document as it looked after the mutation was performed. This is only included if
|
|
1057
|
+
* the listener was configured with `includeResult: true`.
|
|
1058
|
+
*/
|
|
1059
|
+
result?: SanityDocument<R>
|
|
1060
|
+
/**
|
|
1061
|
+
* The document as it looked before the mutation was performed. This is only included if
|
|
1062
|
+
* the listener was configured with `includePreviousRevision: true`.
|
|
1063
|
+
*/
|
|
1064
|
+
previous?: SanityDocument<R> | null
|
|
1065
|
+
/**
|
|
1066
|
+
* The effects of the mutation, if the listener was configured with `effectFormat: 'mendoza'`.
|
|
1067
|
+
* Object with `apply` and `revert` arrays, see {@link https://github.com/sanity-io/mendoza}.
|
|
1068
|
+
*/
|
|
1069
|
+
effects?: {
|
|
1070
|
+
apply: unknown[]
|
|
1071
|
+
revert: unknown[]
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* A timestamp for when the mutation was performed
|
|
1075
|
+
*/
|
|
1076
|
+
timestamp: string
|
|
1077
|
+
/**
|
|
1078
|
+
* The transaction ID for the mutation
|
|
1079
|
+
*/
|
|
1080
|
+
transactionId: string
|
|
1081
|
+
/**
|
|
1082
|
+
* The type of transition the document went through.
|
|
1083
|
+
*
|
|
1084
|
+
* - `update` means the document was previously part of the subscribed set of documents,
|
|
1085
|
+
* and still is.
|
|
1086
|
+
* - `appear` means the document was not previously part of the subscribed set of documents,
|
|
1087
|
+
* but is now. This can happen both on create or if updating to a state where it now matches
|
|
1088
|
+
* the filter provided to the listener.
|
|
1089
|
+
* - `disappear` means the document was previously part of the subscribed set of documents,
|
|
1090
|
+
* but is no longer. This can happen both on delete or if updating to a state where it no
|
|
1091
|
+
* longer matches the filter provided to the listener.
|
|
1092
|
+
*/
|
|
1093
|
+
transition: 'update' | 'appear' | 'disappear'
|
|
1094
|
+
/**
|
|
1095
|
+
* Whether the change that triggered this event is visible to queries (query) or only to
|
|
1096
|
+
* subsequent transactions (transaction). The listener client can specify a preferred visibility
|
|
1097
|
+
* through the `visibility` parameter on the listener, but this is only on a best-effort basis,
|
|
1098
|
+
* and may yet not be accurate.
|
|
1099
|
+
*/
|
|
1100
|
+
visibility: 'query' | 'transaction'
|
|
1101
|
+
/**
|
|
1102
|
+
* The total number of events that will be sent for this transaction.
|
|
1103
|
+
* Note that this may differ from the amount of _documents_ affected by the transaction, as this
|
|
1104
|
+
* number only includes the documents that matches the given filter.
|
|
1105
|
+
*
|
|
1106
|
+
* This can be useful if you need to perform changes to all matched documents atomically,
|
|
1107
|
+
* eg you would wait for `transactionTotalEvents` events with the same `transactionId` before
|
|
1108
|
+
* applying the changes locally.
|
|
1109
|
+
*/
|
|
1110
|
+
transactionTotalEvents: number
|
|
1111
|
+
/**
|
|
1112
|
+
* The index of this event within the transaction. Note that events may be delivered out of order,
|
|
1113
|
+
* and that the index is zero-based.
|
|
1114
|
+
*/
|
|
1115
|
+
transactionCurrentEvent: number
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/** @internal */
|
|
1119
|
+
declare type MutationOperation = 'create' | 'delete' | 'update' | 'none'
|
|
1120
|
+
|
|
1121
|
+
/** @internal */
|
|
1122
|
+
declare type MutationSelection =
|
|
1123
|
+
| {
|
|
1124
|
+
query: string
|
|
1125
|
+
params?: MutationSelectionQueryParams
|
|
1126
|
+
}
|
|
1127
|
+
| {
|
|
1128
|
+
id: string | string[]
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/** @internal */
|
|
1132
|
+
declare type MutationSelectionQueryParams = {
|
|
1133
|
+
[key: string]: Any
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
/** @internal */
|
|
1137
|
+
declare class ObservableAssetsClient {
|
|
1138
|
+
#private
|
|
1139
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1140
|
+
/**
|
|
1141
|
+
* Uploads a file asset to the configured dataset
|
|
1142
|
+
*
|
|
1143
|
+
* @param assetType - Asset type (file)
|
|
1144
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
1145
|
+
* @param options - Options to use for the upload
|
|
1146
|
+
*/
|
|
1147
|
+
upload(
|
|
1148
|
+
assetType: 'file',
|
|
1149
|
+
body: UploadBody,
|
|
1150
|
+
options?: UploadClientConfig,
|
|
1151
|
+
): Observable<
|
|
1152
|
+
HttpRequestEvent<{
|
|
1153
|
+
document: SanityAssetDocument
|
|
1154
|
+
}>
|
|
1155
|
+
>
|
|
1156
|
+
/**
|
|
1157
|
+
* Uploads an image asset to the configured dataset
|
|
1158
|
+
*
|
|
1159
|
+
* @param assetType - Asset type (image)
|
|
1160
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
1161
|
+
* @param options - Options to use for the upload
|
|
1162
|
+
*/
|
|
1163
|
+
upload(
|
|
1164
|
+
assetType: 'image',
|
|
1165
|
+
body: UploadBody,
|
|
1166
|
+
options?: UploadClientConfig,
|
|
1167
|
+
): Observable<
|
|
1168
|
+
HttpRequestEvent<{
|
|
1169
|
+
document: SanityImageAssetDocument
|
|
1170
|
+
}>
|
|
1171
|
+
>
|
|
1172
|
+
/**
|
|
1173
|
+
* Uploads a file or an image asset to the configured dataset
|
|
1174
|
+
*
|
|
1175
|
+
* @param assetType - Asset type (file/image)
|
|
1176
|
+
* @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
|
|
1177
|
+
* @param options - Options to use for the upload
|
|
1178
|
+
*/
|
|
1179
|
+
upload(
|
|
1180
|
+
assetType: 'file' | 'image',
|
|
1181
|
+
body: UploadBody,
|
|
1182
|
+
options?: UploadClientConfig,
|
|
1183
|
+
): Observable<
|
|
1184
|
+
HttpRequestEvent<{
|
|
1185
|
+
document: SanityAssetDocument | SanityImageAssetDocument
|
|
1186
|
+
}>
|
|
1187
|
+
>
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/** @internal */
|
|
1191
|
+
declare class ObservableDatasetsClient {
|
|
1192
|
+
#private
|
|
1193
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1194
|
+
/**
|
|
1195
|
+
* Create a new dataset with the given name
|
|
1196
|
+
*
|
|
1197
|
+
* @param name - Name of the dataset to create
|
|
1198
|
+
* @param options - Options for the dataset
|
|
1199
|
+
*/
|
|
1200
|
+
create(
|
|
1201
|
+
name: string,
|
|
1202
|
+
options?: {
|
|
1203
|
+
aclMode?: DatasetAclMode
|
|
1204
|
+
},
|
|
1205
|
+
): Observable<DatasetResponse>
|
|
1206
|
+
/**
|
|
1207
|
+
* Edit a dataset with the given name
|
|
1208
|
+
*
|
|
1209
|
+
* @param name - Name of the dataset to edit
|
|
1210
|
+
* @param options - New options for the dataset
|
|
1211
|
+
*/
|
|
1212
|
+
edit(
|
|
1213
|
+
name: string,
|
|
1214
|
+
options?: {
|
|
1215
|
+
aclMode?: DatasetAclMode
|
|
1216
|
+
},
|
|
1217
|
+
): Observable<DatasetResponse>
|
|
1218
|
+
/**
|
|
1219
|
+
* Delete a dataset with the given name
|
|
1220
|
+
*
|
|
1221
|
+
* @param name - Name of the dataset to delete
|
|
1222
|
+
*/
|
|
1223
|
+
delete(name: string): Observable<{
|
|
1224
|
+
deleted: true
|
|
1225
|
+
}>
|
|
1226
|
+
/**
|
|
1227
|
+
* Fetch a list of datasets for the configured project
|
|
1228
|
+
*/
|
|
1229
|
+
list(): Observable<DatasetsResponse>
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
/** @public */
|
|
1233
|
+
declare class ObservablePatch extends BasePatch {
|
|
1234
|
+
#private
|
|
1235
|
+
constructor(
|
|
1236
|
+
selection: PatchSelection,
|
|
1237
|
+
operations?: PatchOperations,
|
|
1238
|
+
client?: ObservableSanityClient,
|
|
1239
|
+
)
|
|
1240
|
+
/**
|
|
1241
|
+
* Clones the patch
|
|
1242
|
+
*/
|
|
1243
|
+
clone(): ObservablePatch
|
|
1244
|
+
/**
|
|
1245
|
+
* Commit the patch, returning an observable that produces the first patched document
|
|
1246
|
+
*
|
|
1247
|
+
* @param options - Options for the mutation operation
|
|
1248
|
+
*/
|
|
1249
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
1250
|
+
options: FirstDocumentMutationOptions,
|
|
1251
|
+
): Observable<SanityDocument<R>>
|
|
1252
|
+
/**
|
|
1253
|
+
* Commit the patch, returning an observable that produces an array of the mutated documents
|
|
1254
|
+
*
|
|
1255
|
+
* @param options - Options for the mutation operation
|
|
1256
|
+
*/
|
|
1257
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
1258
|
+
options: AllDocumentsMutationOptions,
|
|
1259
|
+
): Observable<SanityDocument<R>[]>
|
|
1260
|
+
/**
|
|
1261
|
+
* Commit the patch, returning an observable that produces a mutation result object
|
|
1262
|
+
*
|
|
1263
|
+
* @param options - Options for the mutation operation
|
|
1264
|
+
*/
|
|
1265
|
+
commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
1266
|
+
/**
|
|
1267
|
+
* Commit the patch, returning an observable that produces a mutation result object
|
|
1268
|
+
*
|
|
1269
|
+
* @param options - Options for the mutation operation
|
|
1270
|
+
*/
|
|
1271
|
+
commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
1272
|
+
/**
|
|
1273
|
+
* Commit the patch, returning an observable that produces the first patched document
|
|
1274
|
+
*
|
|
1275
|
+
* @param options - Options for the mutation operation
|
|
1276
|
+
*/
|
|
1277
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
1278
|
+
options?: BaseMutationOptions,
|
|
1279
|
+
): Observable<SanityDocument<R>>
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
/** @public */
|
|
1283
|
+
declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
|
|
1284
|
+
|
|
1285
|
+
/** @internal */
|
|
1286
|
+
declare class ObservableProjectsClient {
|
|
1287
|
+
#private
|
|
1288
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1289
|
+
/**
|
|
1290
|
+
* Fetch a list of projects the authenticated user has access to.
|
|
1291
|
+
*
|
|
1292
|
+
* @param options - Options for the list request
|
|
1293
|
+
* @param options.includeMembers - Whether to include members in the response (default: true)
|
|
1294
|
+
*/
|
|
1295
|
+
list(options?: {includeMembers?: true}): Observable<SanityProject[]>
|
|
1296
|
+
list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
|
|
1297
|
+
/**
|
|
1298
|
+
* Fetch a project by project ID
|
|
1299
|
+
*
|
|
1300
|
+
* @param projectId - ID of the project to fetch
|
|
1301
|
+
*/
|
|
1302
|
+
getById(projectId: string): Observable<SanityProject>
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
/** @public */
|
|
1306
|
+
declare class ObservableSanityClient {
|
|
1307
|
+
#private
|
|
1308
|
+
assets: ObservableAssetsClient
|
|
1309
|
+
datasets: ObservableDatasetsClient
|
|
1310
|
+
live: LiveClient
|
|
1311
|
+
projects: ObservableProjectsClient
|
|
1312
|
+
users: ObservableUsersClient
|
|
1313
|
+
/**
|
|
1314
|
+
* Instance properties
|
|
1315
|
+
*/
|
|
1316
|
+
listen: typeof _listen
|
|
1317
|
+
constructor(httpRequest: HttpRequest, config?: ClientConfig)
|
|
1318
|
+
/**
|
|
1319
|
+
* Clone the client - returns a new instance
|
|
1320
|
+
*/
|
|
1321
|
+
clone(): ObservableSanityClient
|
|
1322
|
+
/**
|
|
1323
|
+
* Returns the current client configuration
|
|
1324
|
+
*/
|
|
1325
|
+
config(): InitializedClientConfig
|
|
1326
|
+
/**
|
|
1327
|
+
* Reconfigure the client. Note that this _mutates_ the current client.
|
|
1328
|
+
*/
|
|
1329
|
+
config(newConfig?: Partial<ClientConfig>): this
|
|
1330
|
+
/**
|
|
1331
|
+
* Clone the client with a new (partial) configuration.
|
|
1332
|
+
*
|
|
1333
|
+
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
1334
|
+
*/
|
|
1335
|
+
withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient
|
|
1336
|
+
/**
|
|
1337
|
+
* Perform a GROQ-query against the configured dataset.
|
|
1338
|
+
*
|
|
1339
|
+
* @param query - GROQ-query to perform
|
|
1340
|
+
*/
|
|
1341
|
+
fetch<
|
|
1342
|
+
R = Any,
|
|
1343
|
+
Q extends QueryWithoutParams = QueryWithoutParams,
|
|
1344
|
+
const G extends string = string,
|
|
1345
|
+
>(query: G, params?: Q | QueryWithoutParams): Observable<ClientReturn<G, R>>
|
|
1346
|
+
/**
|
|
1347
|
+
* Perform a GROQ-query against the configured dataset.
|
|
1348
|
+
*
|
|
1349
|
+
* @param query - GROQ-query to perform
|
|
1350
|
+
* @param params - Optional query parameters
|
|
1351
|
+
* @param options - Optional request options
|
|
1352
|
+
*/
|
|
1353
|
+
fetch<
|
|
1354
|
+
R = Any,
|
|
1355
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
1356
|
+
const G extends string = string,
|
|
1357
|
+
>(
|
|
1358
|
+
query: G,
|
|
1359
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1360
|
+
options?: FilteredResponseQueryOptions,
|
|
1361
|
+
): Observable<ClientReturn<G, R>>
|
|
1362
|
+
/**
|
|
1363
|
+
* Perform a GROQ-query against the configured dataset.
|
|
1364
|
+
*
|
|
1365
|
+
* @param query - GROQ-query to perform
|
|
1366
|
+
* @param params - Optional query parameters
|
|
1367
|
+
* @param options - Request options
|
|
1368
|
+
*/
|
|
1369
|
+
fetch<
|
|
1370
|
+
R = Any,
|
|
1371
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
1372
|
+
const G extends string = string,
|
|
1373
|
+
>(
|
|
1374
|
+
query: string,
|
|
1375
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1376
|
+
options: UnfilteredResponseQueryOptions,
|
|
1377
|
+
): Observable<RawQueryResponse<ClientReturn<G, R>>>
|
|
1378
|
+
/**
|
|
1379
|
+
* Perform a GROQ-query against the configured dataset.
|
|
1380
|
+
*
|
|
1381
|
+
* @param query - GROQ-query to perform
|
|
1382
|
+
* @param params - Optional query parameters
|
|
1383
|
+
* @param options - Request options
|
|
1384
|
+
*/
|
|
1385
|
+
fetch<
|
|
1386
|
+
R = Any,
|
|
1387
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
1388
|
+
const G extends string = string,
|
|
1389
|
+
>(
|
|
1390
|
+
query: G,
|
|
1391
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
1392
|
+
options: UnfilteredResponseWithoutQuery,
|
|
1393
|
+
): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
|
|
1394
|
+
/**
|
|
1395
|
+
* Fetch a single document with the given ID.
|
|
1396
|
+
*
|
|
1397
|
+
* @param id - Document ID to fetch
|
|
1398
|
+
* @param options - Request options
|
|
1399
|
+
*/
|
|
1400
|
+
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
1401
|
+
id: string,
|
|
1402
|
+
options?: {
|
|
1403
|
+
tag?: string
|
|
1404
|
+
},
|
|
1405
|
+
): Observable<SanityDocument<R> | undefined>
|
|
1406
|
+
/**
|
|
1407
|
+
* Fetch multiple documents in one request.
|
|
1408
|
+
* Should be used sparingly - performing a query is usually a better option.
|
|
1409
|
+
* The order/position of documents is preserved based on the original array of IDs.
|
|
1410
|
+
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
1411
|
+
*
|
|
1412
|
+
* @param ids - Document IDs to fetch
|
|
1413
|
+
* @param options - Request options
|
|
1414
|
+
*/
|
|
1415
|
+
getDocuments<R extends Record<string, Any> = Record<string, Any>>(
|
|
1416
|
+
ids: string[],
|
|
1417
|
+
options?: {
|
|
1418
|
+
tag?: string
|
|
1419
|
+
},
|
|
1420
|
+
): Observable<(SanityDocument<R> | null)[]>
|
|
1421
|
+
/**
|
|
1422
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1423
|
+
* Returns an observable that resolves to the created document.
|
|
1424
|
+
*
|
|
1425
|
+
* @param document - Document to create
|
|
1426
|
+
* @param options - Mutation options
|
|
1427
|
+
*/
|
|
1428
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1429
|
+
document: SanityDocumentStub<R>,
|
|
1430
|
+
options: FirstDocumentMutationOptions,
|
|
1431
|
+
): Observable<SanityDocument<R>>
|
|
1432
|
+
/**
|
|
1433
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1434
|
+
* Returns an observable that resolves to an array containing the created document.
|
|
1435
|
+
*
|
|
1436
|
+
* @param document - Document to create
|
|
1437
|
+
* @param options - Mutation options
|
|
1438
|
+
*/
|
|
1439
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1440
|
+
document: SanityDocumentStub<R>,
|
|
1441
|
+
options: AllDocumentsMutationOptions,
|
|
1442
|
+
): Observable<SanityDocument<R>[]>
|
|
1443
|
+
/**
|
|
1444
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1445
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1446
|
+
*
|
|
1447
|
+
* @param document - Document to create
|
|
1448
|
+
* @param options - Mutation options
|
|
1449
|
+
*/
|
|
1450
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1451
|
+
document: SanityDocumentStub<R>,
|
|
1452
|
+
options: FirstDocumentIdMutationOptions,
|
|
1453
|
+
): Observable<SingleMutationResult>
|
|
1454
|
+
/**
|
|
1455
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1456
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1457
|
+
*
|
|
1458
|
+
* @param document - Document to create
|
|
1459
|
+
* @param options - Mutation options
|
|
1460
|
+
*/
|
|
1461
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1462
|
+
document: SanityDocumentStub<R>,
|
|
1463
|
+
options: AllDocumentIdsMutationOptions,
|
|
1464
|
+
): Observable<MultipleMutationResult>
|
|
1465
|
+
/**
|
|
1466
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
1467
|
+
* Returns an observable that resolves to the created document.
|
|
1468
|
+
*
|
|
1469
|
+
* @param document - Document to create
|
|
1470
|
+
* @param options - Mutation options
|
|
1471
|
+
*/
|
|
1472
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
1473
|
+
document: SanityDocumentStub<R>,
|
|
1474
|
+
options?: BaseMutationOptions,
|
|
1475
|
+
): Observable<SanityDocument<R>>
|
|
1476
|
+
/**
|
|
1477
|
+
* Create a document if no document with the same ID already exists.
|
|
1478
|
+
* Returns an observable that resolves to the created document.
|
|
1479
|
+
*
|
|
1480
|
+
* @param document - Document to create
|
|
1481
|
+
* @param options - Mutation options
|
|
1482
|
+
*/
|
|
1483
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1484
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1485
|
+
options: FirstDocumentMutationOptions,
|
|
1486
|
+
): Observable<SanityDocument<R>>
|
|
1487
|
+
/**
|
|
1488
|
+
* Create a document if no document with the same ID already exists.
|
|
1489
|
+
* Returns an observable that resolves to an array containing the created document.
|
|
1490
|
+
*
|
|
1491
|
+
* @param document - Document to create
|
|
1492
|
+
* @param options - Mutation options
|
|
1493
|
+
*/
|
|
1494
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1495
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1496
|
+
options: AllDocumentsMutationOptions,
|
|
1497
|
+
): Observable<SanityDocument<R>[]>
|
|
1498
|
+
/**
|
|
1499
|
+
* Create a document if no document with the same ID already exists.
|
|
1500
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1501
|
+
*
|
|
1502
|
+
* @param document - Document to create
|
|
1503
|
+
* @param options - Mutation options
|
|
1504
|
+
*/
|
|
1505
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1506
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1507
|
+
options: FirstDocumentIdMutationOptions,
|
|
1508
|
+
): Observable<SingleMutationResult>
|
|
1509
|
+
/**
|
|
1510
|
+
* Create a document if no document with the same ID already exists.
|
|
1511
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1512
|
+
*
|
|
1513
|
+
* @param document - Document to create
|
|
1514
|
+
* @param options - Mutation options
|
|
1515
|
+
*/
|
|
1516
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1517
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1518
|
+
options: AllDocumentIdsMutationOptions,
|
|
1519
|
+
): Observable<MultipleMutationResult>
|
|
1520
|
+
/**
|
|
1521
|
+
* Create a document if no document with the same ID already exists.
|
|
1522
|
+
* Returns an observable that resolves to the created document.
|
|
1523
|
+
*
|
|
1524
|
+
* @param document - Document to create
|
|
1525
|
+
* @param options - Mutation options
|
|
1526
|
+
*/
|
|
1527
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
1528
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1529
|
+
options?: BaseMutationOptions,
|
|
1530
|
+
): Observable<SanityDocument<R>>
|
|
1531
|
+
/**
|
|
1532
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1533
|
+
* Returns an observable that resolves to the created document.
|
|
1534
|
+
*
|
|
1535
|
+
* @param document - Document to either create or replace
|
|
1536
|
+
* @param options - Mutation options
|
|
1537
|
+
*/
|
|
1538
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1539
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1540
|
+
options: FirstDocumentMutationOptions,
|
|
1541
|
+
): Observable<SanityDocument<R>>
|
|
1542
|
+
/**
|
|
1543
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1544
|
+
* Returns an observable that resolves to an array containing the created document.
|
|
1545
|
+
*
|
|
1546
|
+
* @param document - Document to either create or replace
|
|
1547
|
+
* @param options - Mutation options
|
|
1548
|
+
*/
|
|
1549
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1550
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1551
|
+
options: AllDocumentsMutationOptions,
|
|
1552
|
+
): Observable<SanityDocument<R>[]>
|
|
1553
|
+
/**
|
|
1554
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1555
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the created document.
|
|
1556
|
+
*
|
|
1557
|
+
* @param document - Document to either create or replace
|
|
1558
|
+
* @param options - Mutation options
|
|
1559
|
+
*/
|
|
1560
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1561
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1562
|
+
options: FirstDocumentIdMutationOptions,
|
|
1563
|
+
): Observable<SingleMutationResult>
|
|
1564
|
+
/**
|
|
1565
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1566
|
+
* Returns an observable that resolves to a mutation result object containing the created document ID.
|
|
1567
|
+
*
|
|
1568
|
+
* @param document - Document to either create or replace
|
|
1569
|
+
* @param options - Mutation options
|
|
1570
|
+
*/
|
|
1571
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1572
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1573
|
+
options: AllDocumentIdsMutationOptions,
|
|
1574
|
+
): Observable<MultipleMutationResult>
|
|
1575
|
+
/**
|
|
1576
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
1577
|
+
* Returns an observable that resolves to the created document.
|
|
1578
|
+
*
|
|
1579
|
+
* @param document - Document to either create or replace
|
|
1580
|
+
* @param options - Mutation options
|
|
1581
|
+
*/
|
|
1582
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
1583
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
1584
|
+
options?: BaseMutationOptions,
|
|
1585
|
+
): Observable<SanityDocument<R>>
|
|
1586
|
+
/**
|
|
1587
|
+
* Deletes a document with the given document ID.
|
|
1588
|
+
* Returns an observable that resolves to the deleted document.
|
|
1589
|
+
*
|
|
1590
|
+
* @param id - Document ID to delete
|
|
1591
|
+
* @param options - Options for the mutation
|
|
1592
|
+
*/
|
|
1593
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1594
|
+
id: string,
|
|
1595
|
+
options: FirstDocumentMutationOptions,
|
|
1596
|
+
): Observable<SanityDocument<R>>
|
|
1597
|
+
/**
|
|
1598
|
+
* Deletes a document with the given document ID.
|
|
1599
|
+
* Returns an observable that resolves to an array containing the deleted document.
|
|
1600
|
+
*
|
|
1601
|
+
* @param id - Document ID to delete
|
|
1602
|
+
* @param options - Options for the mutation
|
|
1603
|
+
*/
|
|
1604
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1605
|
+
id: string,
|
|
1606
|
+
options: AllDocumentsMutationOptions,
|
|
1607
|
+
): Observable<SanityDocument<R>[]>
|
|
1608
|
+
/**
|
|
1609
|
+
* Deletes a document with the given document ID.
|
|
1610
|
+
* Returns an observable that resolves to a mutation result object containing the deleted document ID.
|
|
1611
|
+
*
|
|
1612
|
+
* @param id - Document ID to delete
|
|
1613
|
+
* @param options - Options for the mutation
|
|
1614
|
+
*/
|
|
1615
|
+
delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
1616
|
+
/**
|
|
1617
|
+
* Deletes a document with the given document ID.
|
|
1618
|
+
* Returns an observable that resolves to a mutation result object containing the deleted document ID.
|
|
1619
|
+
*
|
|
1620
|
+
* @param id - Document ID to delete
|
|
1621
|
+
* @param options - Options for the mutation
|
|
1622
|
+
*/
|
|
1623
|
+
delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
1624
|
+
/**
|
|
1625
|
+
* Deletes a document with the given document ID.
|
|
1626
|
+
* Returns an observable that resolves to the deleted document.
|
|
1627
|
+
*
|
|
1628
|
+
* @param id - Document ID to delete
|
|
1629
|
+
* @param options - Options for the mutation
|
|
1630
|
+
*/
|
|
1631
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1632
|
+
id: string,
|
|
1633
|
+
options?: BaseMutationOptions,
|
|
1634
|
+
): Observable<SanityDocument<R>>
|
|
1635
|
+
/**
|
|
1636
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1637
|
+
* Returns an observable that resolves to first deleted document.
|
|
1638
|
+
*
|
|
1639
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1640
|
+
* @param options - Options for the mutation
|
|
1641
|
+
*/
|
|
1642
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1643
|
+
selection: MutationSelection,
|
|
1644
|
+
options: FirstDocumentMutationOptions,
|
|
1645
|
+
): Observable<SanityDocument<R>>
|
|
1646
|
+
/**
|
|
1647
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1648
|
+
* Returns an observable that resolves to an array containing the deleted documents.
|
|
1649
|
+
*
|
|
1650
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1651
|
+
* @param options - Options for the mutation
|
|
1652
|
+
*/
|
|
1653
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1654
|
+
selection: MutationSelection,
|
|
1655
|
+
options: AllDocumentsMutationOptions,
|
|
1656
|
+
): Observable<SanityDocument<R>[]>
|
|
1657
|
+
/**
|
|
1658
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1659
|
+
* Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
|
|
1660
|
+
*
|
|
1661
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1662
|
+
* @param options - Options for the mutation
|
|
1663
|
+
*/
|
|
1664
|
+
delete(
|
|
1665
|
+
selection: MutationSelection,
|
|
1666
|
+
options: FirstDocumentIdMutationOptions,
|
|
1667
|
+
): Observable<SingleMutationResult>
|
|
1668
|
+
/**
|
|
1669
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1670
|
+
* Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
|
|
1671
|
+
*
|
|
1672
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1673
|
+
* @param options - Options for the mutation
|
|
1674
|
+
*/
|
|
1675
|
+
delete(
|
|
1676
|
+
selection: MutationSelection,
|
|
1677
|
+
options: AllDocumentIdsMutationOptions,
|
|
1678
|
+
): Observable<MultipleMutationResult>
|
|
1679
|
+
/**
|
|
1680
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
1681
|
+
* Returns an observable that resolves to first deleted document.
|
|
1682
|
+
*
|
|
1683
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
1684
|
+
* @param options - Options for the mutation
|
|
1685
|
+
*/
|
|
1686
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
1687
|
+
selection: MutationSelection,
|
|
1688
|
+
options?: BaseMutationOptions,
|
|
1689
|
+
): Observable<SanityDocument<R>>
|
|
1690
|
+
/**
|
|
1691
|
+
* Perform mutation operations against the configured dataset
|
|
1692
|
+
* Returns an observable that resolves to the first mutated document.
|
|
1693
|
+
*
|
|
1694
|
+
* @param operations - Mutation operations to execute
|
|
1695
|
+
* @param options - Mutation options
|
|
1696
|
+
*/
|
|
1697
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1698
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1699
|
+
options: FirstDocumentMutationOptions,
|
|
1700
|
+
): Observable<SanityDocument<R>>
|
|
1701
|
+
/**
|
|
1702
|
+
* Perform mutation operations against the configured dataset.
|
|
1703
|
+
* Returns an observable that resolves to an array of the mutated documents.
|
|
1704
|
+
*
|
|
1705
|
+
* @param operations - Mutation operations to execute
|
|
1706
|
+
* @param options - Mutation options
|
|
1707
|
+
*/
|
|
1708
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1709
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1710
|
+
options: AllDocumentsMutationOptions,
|
|
1711
|
+
): Observable<SanityDocument<R>[]>
|
|
1712
|
+
/**
|
|
1713
|
+
* Perform mutation operations against the configured dataset
|
|
1714
|
+
* Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
|
|
1715
|
+
*
|
|
1716
|
+
* @param operations - Mutation operations to execute
|
|
1717
|
+
* @param options - Mutation options
|
|
1718
|
+
*/
|
|
1719
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1720
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1721
|
+
options: FirstDocumentIdMutationOptions,
|
|
1722
|
+
): Observable<SingleMutationResult>
|
|
1723
|
+
/**
|
|
1724
|
+
* Perform mutation operations against the configured dataset
|
|
1725
|
+
* Returns an observable that resolves to a mutation result object containing the mutated document IDs.
|
|
1726
|
+
*
|
|
1727
|
+
* @param operations - Mutation operations to execute
|
|
1728
|
+
* @param options - Mutation options
|
|
1729
|
+
*/
|
|
1730
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1731
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1732
|
+
options: AllDocumentIdsMutationOptions,
|
|
1733
|
+
): Observable<MultipleMutationResult>
|
|
1734
|
+
/**
|
|
1735
|
+
* Perform mutation operations against the configured dataset
|
|
1736
|
+
* Returns an observable that resolves to the first mutated document.
|
|
1737
|
+
*
|
|
1738
|
+
* @param operations - Mutation operations to execute
|
|
1739
|
+
* @param options - Mutation options
|
|
1740
|
+
*/
|
|
1741
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1742
|
+
operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
|
|
1743
|
+
options?: BaseMutationOptions,
|
|
1744
|
+
): Observable<SanityDocument<R>>
|
|
1745
|
+
/**
|
|
1746
|
+
* Create a new buildable patch of operations to perform
|
|
1747
|
+
*
|
|
1748
|
+
* @param documentId - Document ID to patch
|
|
1749
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1750
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1751
|
+
*/
|
|
1752
|
+
patch(documentId: string, operations?: PatchOperations): ObservablePatch
|
|
1753
|
+
/**
|
|
1754
|
+
* Create a new buildable patch of operations to perform
|
|
1755
|
+
*
|
|
1756
|
+
* @param documentIds - Array of document IDs to patch
|
|
1757
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1758
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1759
|
+
*/
|
|
1760
|
+
patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
|
|
1761
|
+
/**
|
|
1762
|
+
* Create a new buildable patch of operations to perform
|
|
1763
|
+
*
|
|
1764
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
1765
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
1766
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
1767
|
+
*/
|
|
1768
|
+
patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
|
|
1769
|
+
/**
|
|
1770
|
+
* Create a new transaction of mutations
|
|
1771
|
+
*
|
|
1772
|
+
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
1773
|
+
*/
|
|
1774
|
+
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
1775
|
+
operations?: Mutation<R>[],
|
|
1776
|
+
): ObservableTransaction
|
|
1777
|
+
/**
|
|
1778
|
+
* Perform action operations against the configured dataset
|
|
1779
|
+
*
|
|
1780
|
+
* @param operations - Action operation(s) to execute
|
|
1781
|
+
* @param options - Action options
|
|
1782
|
+
*/
|
|
1783
|
+
action(
|
|
1784
|
+
operations: Action | Action[],
|
|
1785
|
+
options?: BaseActionOptions,
|
|
1786
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
1787
|
+
/**
|
|
1788
|
+
* Perform an HTTP request against the Sanity API
|
|
1789
|
+
*
|
|
1790
|
+
* @param options - Request options
|
|
1791
|
+
*/
|
|
1792
|
+
request<R = Any>(options: RawRequestOptions): Observable<R>
|
|
1793
|
+
/**
|
|
1794
|
+
* Get a Sanity API URL for the URI provided
|
|
1795
|
+
*
|
|
1796
|
+
* @param uri - URI/path to build URL for
|
|
1797
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
1798
|
+
*/
|
|
1799
|
+
getUrl(uri: string, canUseCdn?: boolean): string
|
|
1800
|
+
/**
|
|
1801
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
1802
|
+
*
|
|
1803
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
1804
|
+
* @param path - Path to append after the operation
|
|
1805
|
+
*/
|
|
1806
|
+
getDataUrl(operation: string, path?: string): string
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
/** @public */
|
|
1810
|
+
declare class ObservableTransaction extends BaseTransaction {
|
|
1811
|
+
#private
|
|
1812
|
+
constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
|
|
1813
|
+
/**
|
|
1814
|
+
* Clones the transaction
|
|
1815
|
+
*/
|
|
1816
|
+
clone(): ObservableTransaction
|
|
1817
|
+
/**
|
|
1818
|
+
* Commit the transaction, returning an observable that produces the first mutated document
|
|
1819
|
+
*
|
|
1820
|
+
* @param options - Options for the mutation operation
|
|
1821
|
+
*/
|
|
1822
|
+
commit<R extends Record<string, Any>>(
|
|
1823
|
+
options: TransactionFirstDocumentMutationOptions,
|
|
1824
|
+
): Observable<SanityDocument<R>>
|
|
1825
|
+
/**
|
|
1826
|
+
* Commit the transaction, returning an observable that produces an array of the mutated documents
|
|
1827
|
+
*
|
|
1828
|
+
* @param options - Options for the mutation operation
|
|
1829
|
+
*/
|
|
1830
|
+
commit<R extends Record<string, Any>>(
|
|
1831
|
+
options: TransactionAllDocumentsMutationOptions,
|
|
1832
|
+
): Observable<SanityDocument<R>[]>
|
|
1833
|
+
/**
|
|
1834
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
1835
|
+
*
|
|
1836
|
+
* @param options - Options for the mutation operation
|
|
1837
|
+
*/
|
|
1838
|
+
commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
|
|
1839
|
+
/**
|
|
1840
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
1841
|
+
*
|
|
1842
|
+
* @param options - Options for the mutation operation
|
|
1843
|
+
*/
|
|
1844
|
+
commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
|
|
1845
|
+
/**
|
|
1846
|
+
* Commit the transaction, returning an observable that produces a mutation result object
|
|
1847
|
+
*
|
|
1848
|
+
* @param options - Options for the mutation operation
|
|
1849
|
+
*/
|
|
1850
|
+
commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
|
|
1851
|
+
/**
|
|
1852
|
+
* Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
|
|
1853
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
1854
|
+
*
|
|
1855
|
+
* @param documentId - Document ID to perform the patch operation on
|
|
1856
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
1857
|
+
*/
|
|
1858
|
+
patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
|
|
1859
|
+
/**
|
|
1860
|
+
* Adds the given patch instance to the transaction.
|
|
1861
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
1862
|
+
*
|
|
1863
|
+
* @param patch - ObservablePatch to execute
|
|
1864
|
+
*/
|
|
1865
|
+
patch(patch: ObservablePatch): this
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
/** @public */
|
|
1869
|
+
declare class ObservableUsersClient {
|
|
1870
|
+
#private
|
|
1871
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
|
|
1872
|
+
/**
|
|
1873
|
+
* Fetch a user by user ID
|
|
1874
|
+
*
|
|
1875
|
+
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
1876
|
+
*/
|
|
1877
|
+
getById<T extends 'me' | string>(
|
|
1878
|
+
id: T,
|
|
1879
|
+
): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
/**
|
|
1883
|
+
* The listener connection has been established
|
|
1884
|
+
* note: it's usually a better option to use the 'welcome' event
|
|
1885
|
+
* @public
|
|
1886
|
+
*/
|
|
1887
|
+
declare type OpenEvent = {
|
|
1888
|
+
type: 'open'
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
/** @public */
|
|
1892
|
+
declare class Patch extends BasePatch {
|
|
1893
|
+
#private
|
|
1894
|
+
constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
|
|
1895
|
+
/**
|
|
1896
|
+
* Clones the patch
|
|
1897
|
+
*/
|
|
1898
|
+
clone(): Patch
|
|
1899
|
+
/**
|
|
1900
|
+
* Commit the patch, returning a promise that resolves to the first patched document
|
|
1901
|
+
*
|
|
1902
|
+
* @param options - Options for the mutation operation
|
|
1903
|
+
*/
|
|
1904
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
1905
|
+
options: FirstDocumentMutationOptions,
|
|
1906
|
+
): Promise<SanityDocument<R>>
|
|
1907
|
+
/**
|
|
1908
|
+
* Commit the patch, returning a promise that resolves to an array of the mutated documents
|
|
1909
|
+
*
|
|
1910
|
+
* @param options - Options for the mutation operation
|
|
1911
|
+
*/
|
|
1912
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
1913
|
+
options: AllDocumentsMutationOptions,
|
|
1914
|
+
): Promise<SanityDocument<R>[]>
|
|
1915
|
+
/**
|
|
1916
|
+
* Commit the patch, returning a promise that resolves to a mutation result object
|
|
1917
|
+
*
|
|
1918
|
+
* @param options - Options for the mutation operation
|
|
1919
|
+
*/
|
|
1920
|
+
commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
|
|
1921
|
+
/**
|
|
1922
|
+
* Commit the patch, returning a promise that resolves to a mutation result object
|
|
1923
|
+
*
|
|
1924
|
+
* @param options - Options for the mutation operation
|
|
1925
|
+
*/
|
|
1926
|
+
commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
|
|
1927
|
+
/**
|
|
1928
|
+
* Commit the patch, returning a promise that resolves to the first patched document
|
|
1929
|
+
*
|
|
1930
|
+
* @param options - Options for the mutation operation
|
|
1931
|
+
*/
|
|
1932
|
+
commit<R extends Record<string, Any> = Record<string, Any>>(
|
|
1933
|
+
options?: BaseMutationOptions,
|
|
1934
|
+
): Promise<SanityDocument<R>>
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
/** @public */
|
|
1938
|
+
declare type PatchBuilder = (patch: Patch) => Patch
|
|
1939
|
+
|
|
1940
|
+
/** @internal */
|
|
1941
|
+
declare type PatchMutationOperation = PatchOperations & MutationSelection
|
|
1942
|
+
|
|
1943
|
+
/** @internal */
|
|
1944
|
+
declare interface PatchOperations {
|
|
1945
|
+
set?: {
|
|
1946
|
+
[key: string]: Any
|
|
1947
|
+
}
|
|
1948
|
+
setIfMissing?: {
|
|
1949
|
+
[key: string]: Any
|
|
1950
|
+
}
|
|
1951
|
+
diffMatchPatch?: {
|
|
1952
|
+
[key: string]: Any
|
|
1953
|
+
}
|
|
1954
|
+
unset?: string[]
|
|
1955
|
+
inc?: {
|
|
1956
|
+
[key: string]: number
|
|
1957
|
+
}
|
|
1958
|
+
dec?: {
|
|
1959
|
+
[key: string]: number
|
|
1960
|
+
}
|
|
1961
|
+
insert?: InsertPatch
|
|
1962
|
+
ifRevisionID?: string
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
/** @internal */
|
|
1966
|
+
declare type PatchSelection = string | string[] | MutationSelection
|
|
1967
|
+
|
|
1968
|
+
/** @public */
|
|
1969
|
+
declare interface ProgressEvent_2 {
|
|
1970
|
+
type: 'progress'
|
|
1971
|
+
stage: 'upload' | 'download'
|
|
1972
|
+
percent: number
|
|
1973
|
+
total?: number
|
|
1974
|
+
loaded?: number
|
|
1975
|
+
lengthComputable: boolean
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
/** @internal */
|
|
1979
|
+
declare class ProjectsClient {
|
|
1980
|
+
#private
|
|
1981
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
1982
|
+
/**
|
|
1983
|
+
* Fetch a list of projects the authenticated user has access to.
|
|
1984
|
+
*
|
|
1985
|
+
* @param options - Options for the list request
|
|
1986
|
+
* @param options.includeMembers - Whether to include members in the response (default: true)
|
|
1987
|
+
*/
|
|
1988
|
+
list(options?: {includeMembers?: true}): Promise<SanityProject[]>
|
|
1989
|
+
list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
|
|
1990
|
+
/**
|
|
1991
|
+
* Fetch a project by project ID
|
|
1992
|
+
*
|
|
1993
|
+
* @param projectId - ID of the project to fetch
|
|
1994
|
+
*/
|
|
1995
|
+
getById(projectId: string): Promise<SanityProject>
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* Publishes a draft document.
|
|
2000
|
+
* If a published version of the document already exists this is replaced by the current draft document.
|
|
2001
|
+
* In either case the draft document is deleted.
|
|
2002
|
+
* The optional revision id parameters can be used for optimistic locking to ensure
|
|
2003
|
+
* that the draft and/or published versions of the document have not been changed by another client.
|
|
2004
|
+
*
|
|
2005
|
+
* @public
|
|
2006
|
+
*/
|
|
2007
|
+
declare type PublishAction = {
|
|
2008
|
+
actionType: 'sanity.action.document.publish'
|
|
2009
|
+
/**
|
|
2010
|
+
* Draft document ID to publish
|
|
2011
|
+
*/
|
|
2012
|
+
draftId: string
|
|
2013
|
+
/**
|
|
2014
|
+
* Draft revision ID to match
|
|
2015
|
+
*/
|
|
2016
|
+
ifDraftRevisionId?: string
|
|
2017
|
+
/**
|
|
2018
|
+
* Published document ID to replace
|
|
2019
|
+
*/
|
|
2020
|
+
publishedId: string
|
|
2021
|
+
/**
|
|
2022
|
+
* Published revision ID to match
|
|
2023
|
+
*/
|
|
2024
|
+
ifPublishedRevisionId?: string
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
/** @public */
|
|
2028
|
+
declare interface QueryParams {
|
|
2029
|
+
[key: string]: any
|
|
2030
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2031
|
+
body?: never
|
|
2032
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2033
|
+
cache?: 'next' extends keyof RequestInit ? never : any
|
|
2034
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2035
|
+
filterResponse?: never
|
|
2036
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2037
|
+
headers?: never
|
|
2038
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2039
|
+
method?: never
|
|
2040
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2041
|
+
next?: 'next' extends keyof RequestInit ? never : any
|
|
2042
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2043
|
+
perspective?: never
|
|
2044
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2045
|
+
query?: never
|
|
2046
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2047
|
+
resultSourceMap?: never
|
|
2048
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2049
|
+
returnQuery?: never
|
|
2050
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2051
|
+
signal?: never
|
|
2052
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2053
|
+
stega?: never
|
|
2054
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2055
|
+
tag?: never
|
|
2056
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2057
|
+
timeout?: never
|
|
2058
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2059
|
+
token?: never
|
|
2060
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2061
|
+
useCdn?: never
|
|
2062
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2063
|
+
lastLiveEventId?: never
|
|
2064
|
+
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
|
|
2065
|
+
cacheMode?: never
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
/**
|
|
2069
|
+
* This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
|
|
2070
|
+
* @public
|
|
2071
|
+
*/
|
|
2072
|
+
declare type QueryWithoutParams = Record<string, never> | undefined
|
|
2073
|
+
|
|
2074
|
+
/** @public */
|
|
2075
|
+
declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
|
|
2076
|
+
|
|
2077
|
+
/** @public */
|
|
2078
|
+
declare interface RawQueryResponse<R> {
|
|
2079
|
+
query: string
|
|
2080
|
+
ms: number
|
|
2081
|
+
result: R
|
|
2082
|
+
resultSourceMap?: ContentSourceMap
|
|
2083
|
+
/** Requires `apiVersion` to be `2021-03-25` or later. */
|
|
2084
|
+
syncTags?: SyncTag[]
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
/** @internal */
|
|
2088
|
+
declare interface RawRequestOptions {
|
|
2089
|
+
url?: string
|
|
2090
|
+
uri?: string
|
|
2091
|
+
method?: string
|
|
2092
|
+
token?: string
|
|
2093
|
+
json?: boolean
|
|
2094
|
+
tag?: string
|
|
2095
|
+
useGlobalApi?: boolean
|
|
2096
|
+
withCredentials?: boolean
|
|
2097
|
+
query?: {
|
|
2098
|
+
[key: string]: string | string[]
|
|
2099
|
+
}
|
|
2100
|
+
headers?: {
|
|
2101
|
+
[key: string]: string
|
|
2102
|
+
}
|
|
2103
|
+
timeout?: number
|
|
2104
|
+
proxy?: string
|
|
2105
|
+
body?: Any
|
|
2106
|
+
maxRedirects?: number
|
|
2107
|
+
signal?: AbortSignal
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
/**
|
|
2111
|
+
* The listener has been disconnected, and a reconnect attempt is scheduled.
|
|
2112
|
+
*
|
|
2113
|
+
* @public
|
|
2114
|
+
*/
|
|
2115
|
+
declare type ReconnectEvent = {
|
|
2116
|
+
type: 'reconnect'
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
/** @public */
|
|
2120
|
+
declare type ReleaseId = `r${string}`
|
|
2121
|
+
|
|
2122
|
+
/**
|
|
2123
|
+
* Replaces an existing draft document.
|
|
2124
|
+
* At least one of the draft or published versions of the document must exist.
|
|
2125
|
+
*
|
|
2126
|
+
* @public
|
|
2127
|
+
*/
|
|
2128
|
+
declare type ReplaceDraftAction = {
|
|
2129
|
+
actionType: 'sanity.action.document.replaceDraft'
|
|
2130
|
+
/**
|
|
2131
|
+
* Published document ID to create draft from, if draft does not exist
|
|
2132
|
+
*/
|
|
2133
|
+
publishedId: string
|
|
2134
|
+
/**
|
|
2135
|
+
* Document to create if it does not already exist. Requires `_id` and `_type` properties.
|
|
2136
|
+
*/
|
|
2137
|
+
attributes: IdentifiedSanityDocumentStub
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
/** @public */
|
|
2141
|
+
declare interface RequestOptions {
|
|
2142
|
+
timeout?: number
|
|
2143
|
+
token?: string
|
|
2144
|
+
tag?: string
|
|
2145
|
+
headers?: Record<string, string>
|
|
2146
|
+
method?: string
|
|
2147
|
+
query?: Any
|
|
2148
|
+
body?: Any
|
|
2149
|
+
signal?: AbortSignal
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
/** @alpha */
|
|
2153
|
+
declare type ResolveStudioUrl = (sourceDocument: ContentSourceMapDocuments[number]) => StudioUrl
|
|
2154
|
+
|
|
2155
|
+
/** @public */
|
|
2156
|
+
declare interface ResponseEvent<T = unknown> {
|
|
2157
|
+
type: 'response'
|
|
2158
|
+
body: T
|
|
2159
|
+
url: string
|
|
2160
|
+
method: string
|
|
2161
|
+
statusCode: number
|
|
2162
|
+
statusMessage?: string
|
|
2163
|
+
headers: Record<string, string>
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
/** @public */
|
|
2167
|
+
declare interface ResponseQueryOptions extends RequestOptions {
|
|
2168
|
+
perspective?: ClientPerspective
|
|
2169
|
+
resultSourceMap?: boolean | 'withKeyArraySelector'
|
|
2170
|
+
returnQuery?: boolean
|
|
2171
|
+
useCdn?: boolean
|
|
2172
|
+
stega?: boolean | StegaConfig
|
|
2173
|
+
cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
|
|
2174
|
+
next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
|
|
2175
|
+
lastLiveEventId?: string | string[] | null
|
|
2176
|
+
/**
|
|
2177
|
+
* When set to `noStale`, APICDN will not return a cached response if the content is stale.
|
|
2178
|
+
* Tradeoff between latency and freshness of content.
|
|
2179
|
+
*
|
|
2180
|
+
* Only to be used with live content queries and when useCdn is true.
|
|
2181
|
+
*/
|
|
2182
|
+
cacheMode?: 'noStale'
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
/** @internal */
|
|
2186
|
+
declare interface SanityAssetDocument extends SanityDocument {
|
|
2187
|
+
url: string
|
|
2188
|
+
path: string
|
|
2189
|
+
size: number
|
|
2190
|
+
assetId: string
|
|
2191
|
+
mimeType: string
|
|
2192
|
+
sha1hash: string
|
|
2193
|
+
extension: string
|
|
2194
|
+
uploadId?: string
|
|
2195
|
+
originalFilename?: string
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
/** @public */
|
|
2199
|
+
declare class SanityClient {
|
|
2200
|
+
#private
|
|
2201
|
+
assets: AssetsClient
|
|
2202
|
+
datasets: DatasetsClient
|
|
2203
|
+
live: LiveClient
|
|
2204
|
+
projects: ProjectsClient
|
|
2205
|
+
users: UsersClient
|
|
2206
|
+
/**
|
|
2207
|
+
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
2208
|
+
*/
|
|
2209
|
+
observable: ObservableSanityClient
|
|
2210
|
+
/**
|
|
2211
|
+
* Instance properties
|
|
2212
|
+
*/
|
|
2213
|
+
listen: typeof _listen
|
|
2214
|
+
constructor(httpRequest: HttpRequest, config?: ClientConfig)
|
|
2215
|
+
/**
|
|
2216
|
+
* Clone the client - returns a new instance
|
|
2217
|
+
*/
|
|
2218
|
+
clone(): SanityClient
|
|
2219
|
+
/**
|
|
2220
|
+
* Returns the current client configuration
|
|
2221
|
+
*/
|
|
2222
|
+
config(): InitializedClientConfig
|
|
2223
|
+
/**
|
|
2224
|
+
* Reconfigure the client. Note that this _mutates_ the current client.
|
|
2225
|
+
*/
|
|
2226
|
+
config(newConfig?: Partial<ClientConfig>): this
|
|
2227
|
+
/**
|
|
2228
|
+
* Clone the client with a new (partial) configuration.
|
|
2229
|
+
*
|
|
2230
|
+
* @param newConfig - New client configuration properties, shallowly merged with existing configuration
|
|
2231
|
+
*/
|
|
2232
|
+
withConfig(newConfig?: Partial<ClientConfig>): SanityClient
|
|
2233
|
+
/**
|
|
2234
|
+
* Perform a GROQ-query against the configured dataset.
|
|
2235
|
+
*
|
|
2236
|
+
* @param query - GROQ-query to perform
|
|
2237
|
+
*/
|
|
2238
|
+
fetch<
|
|
2239
|
+
R = Any,
|
|
2240
|
+
Q extends QueryWithoutParams = QueryWithoutParams,
|
|
2241
|
+
const G extends string = string,
|
|
2242
|
+
>(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
|
|
2243
|
+
/**
|
|
2244
|
+
* Perform a GROQ-query against the configured dataset.
|
|
2245
|
+
*
|
|
2246
|
+
* @param query - GROQ-query to perform
|
|
2247
|
+
* @param params - Optional query parameters
|
|
2248
|
+
* @param options - Optional request options
|
|
2249
|
+
*/
|
|
2250
|
+
fetch<
|
|
2251
|
+
R = Any,
|
|
2252
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
2253
|
+
const G extends string = string,
|
|
2254
|
+
>(
|
|
2255
|
+
query: G,
|
|
2256
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2257
|
+
options?: FilteredResponseQueryOptions,
|
|
2258
|
+
): Promise<ClientReturn<G, R>>
|
|
2259
|
+
/**
|
|
2260
|
+
* Perform a GROQ-query against the configured dataset.
|
|
2261
|
+
*
|
|
2262
|
+
* @param query - GROQ-query to perform
|
|
2263
|
+
* @param params - Optional query parameters
|
|
2264
|
+
* @param options - Request options
|
|
2265
|
+
*/
|
|
2266
|
+
fetch<
|
|
2267
|
+
R = Any,
|
|
2268
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
2269
|
+
const G extends string = string,
|
|
2270
|
+
>(
|
|
2271
|
+
query: G,
|
|
2272
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2273
|
+
options: UnfilteredResponseQueryOptions,
|
|
2274
|
+
): Promise<RawQueryResponse<ClientReturn<G, R>>>
|
|
2275
|
+
/**
|
|
2276
|
+
* Perform a GROQ-query against the configured dataset.
|
|
2277
|
+
*
|
|
2278
|
+
* @param query - GROQ-query to perform
|
|
2279
|
+
* @param params - Optional query parameters
|
|
2280
|
+
* @param options - Request options
|
|
2281
|
+
*/
|
|
2282
|
+
fetch<
|
|
2283
|
+
R = Any,
|
|
2284
|
+
Q extends QueryWithoutParams | QueryParams = QueryParams,
|
|
2285
|
+
const G extends string = string,
|
|
2286
|
+
>(
|
|
2287
|
+
query: G,
|
|
2288
|
+
params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
|
|
2289
|
+
options: UnfilteredResponseWithoutQuery,
|
|
2290
|
+
): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
|
|
2291
|
+
/**
|
|
2292
|
+
* Fetch a single document with the given ID.
|
|
2293
|
+
*
|
|
2294
|
+
* @param id - Document ID to fetch
|
|
2295
|
+
* @param options - Request options
|
|
2296
|
+
*/
|
|
2297
|
+
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
2298
|
+
id: string,
|
|
2299
|
+
options?: {
|
|
2300
|
+
signal?: AbortSignal
|
|
2301
|
+
tag?: string
|
|
2302
|
+
},
|
|
2303
|
+
): Promise<SanityDocument<R> | undefined>
|
|
2304
|
+
/**
|
|
2305
|
+
* Fetch multiple documents in one request.
|
|
2306
|
+
* Should be used sparingly - performing a query is usually a better option.
|
|
2307
|
+
* The order/position of documents is preserved based on the original array of IDs.
|
|
2308
|
+
* If any of the documents are missing, they will be replaced by a `null` entry in the returned array
|
|
2309
|
+
*
|
|
2310
|
+
* @param ids - Document IDs to fetch
|
|
2311
|
+
* @param options - Request options
|
|
2312
|
+
*/
|
|
2313
|
+
getDocuments<R extends Record<string, Any> = Record<string, Any>>(
|
|
2314
|
+
ids: string[],
|
|
2315
|
+
options?: {
|
|
2316
|
+
signal?: AbortSignal
|
|
2317
|
+
tag?: string
|
|
2318
|
+
},
|
|
2319
|
+
): Promise<(SanityDocument<R> | null)[]>
|
|
2320
|
+
/**
|
|
2321
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2322
|
+
* Returns a promise that resolves to the created document.
|
|
2323
|
+
*
|
|
2324
|
+
* @param document - Document to create
|
|
2325
|
+
* @param options - Mutation options
|
|
2326
|
+
*/
|
|
2327
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2328
|
+
document: SanityDocumentStub<R>,
|
|
2329
|
+
options: FirstDocumentMutationOptions,
|
|
2330
|
+
): Promise<SanityDocument<R>>
|
|
2331
|
+
/**
|
|
2332
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2333
|
+
* Returns a promise that resolves to an array containing the created document.
|
|
2334
|
+
*
|
|
2335
|
+
* @param document - Document to create
|
|
2336
|
+
* @param options - Mutation options
|
|
2337
|
+
*/
|
|
2338
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2339
|
+
document: SanityDocumentStub<R>,
|
|
2340
|
+
options: AllDocumentsMutationOptions,
|
|
2341
|
+
): Promise<SanityDocument<R>[]>
|
|
2342
|
+
/**
|
|
2343
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2344
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2345
|
+
*
|
|
2346
|
+
* @param document - Document to create
|
|
2347
|
+
* @param options - Mutation options
|
|
2348
|
+
*/
|
|
2349
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2350
|
+
document: SanityDocumentStub<R>,
|
|
2351
|
+
options: FirstDocumentIdMutationOptions,
|
|
2352
|
+
): Promise<SingleMutationResult>
|
|
2353
|
+
/**
|
|
2354
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2355
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2356
|
+
*
|
|
2357
|
+
* @param document - Document to create
|
|
2358
|
+
* @param options - Mutation options
|
|
2359
|
+
*/
|
|
2360
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2361
|
+
document: SanityDocumentStub<R>,
|
|
2362
|
+
options: AllDocumentIdsMutationOptions,
|
|
2363
|
+
): Promise<MultipleMutationResult>
|
|
2364
|
+
/**
|
|
2365
|
+
* Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
|
|
2366
|
+
* Returns a promise that resolves to the created document.
|
|
2367
|
+
*
|
|
2368
|
+
* @param document - Document to create
|
|
2369
|
+
* @param options - Mutation options
|
|
2370
|
+
*/
|
|
2371
|
+
create<R extends Record<string, Any> = Record<string, Any>>(
|
|
2372
|
+
document: SanityDocumentStub<R>,
|
|
2373
|
+
options?: BaseMutationOptions,
|
|
2374
|
+
): Promise<SanityDocument<R>>
|
|
2375
|
+
/**
|
|
2376
|
+
* Create a document if no document with the same ID already exists.
|
|
2377
|
+
* Returns a promise that resolves to the created document.
|
|
2378
|
+
*
|
|
2379
|
+
* @param document - Document to create
|
|
2380
|
+
* @param options - Mutation options
|
|
2381
|
+
*/
|
|
2382
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2383
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2384
|
+
options: FirstDocumentMutationOptions,
|
|
2385
|
+
): Promise<SanityDocument<R>>
|
|
2386
|
+
/**
|
|
2387
|
+
* Create a document if no document with the same ID already exists.
|
|
2388
|
+
* Returns a promise that resolves to an array containing the created document.
|
|
2389
|
+
*
|
|
2390
|
+
* @param document - Document to create
|
|
2391
|
+
* @param options - Mutation options
|
|
2392
|
+
*/
|
|
2393
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2394
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2395
|
+
options: AllDocumentsMutationOptions,
|
|
2396
|
+
): Promise<SanityDocument<R>[]>
|
|
2397
|
+
/**
|
|
2398
|
+
* Create a document if no document with the same ID already exists.
|
|
2399
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2400
|
+
*
|
|
2401
|
+
* @param document - Document to create
|
|
2402
|
+
* @param options - Mutation options
|
|
2403
|
+
*/
|
|
2404
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2405
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2406
|
+
options: FirstDocumentIdMutationOptions,
|
|
2407
|
+
): Promise<SingleMutationResult>
|
|
2408
|
+
/**
|
|
2409
|
+
* Create a document if no document with the same ID already exists.
|
|
2410
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2411
|
+
*
|
|
2412
|
+
* @param document - Document to create
|
|
2413
|
+
* @param options - Mutation options
|
|
2414
|
+
*/
|
|
2415
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2416
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2417
|
+
options: AllDocumentIdsMutationOptions,
|
|
2418
|
+
): Promise<MultipleMutationResult>
|
|
2419
|
+
/**
|
|
2420
|
+
* Create a document if no document with the same ID already exists.
|
|
2421
|
+
* Returns a promise that resolves to the created document.
|
|
2422
|
+
*
|
|
2423
|
+
* @param document - Document to create
|
|
2424
|
+
* @param options - Mutation options
|
|
2425
|
+
*/
|
|
2426
|
+
createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
|
|
2427
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2428
|
+
options?: BaseMutationOptions,
|
|
2429
|
+
): Promise<SanityDocument<R>>
|
|
2430
|
+
/**
|
|
2431
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2432
|
+
* Returns a promise that resolves to the created document.
|
|
2433
|
+
*
|
|
2434
|
+
* @param document - Document to either create or replace
|
|
2435
|
+
* @param options - Mutation options
|
|
2436
|
+
*/
|
|
2437
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2438
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2439
|
+
options: FirstDocumentMutationOptions,
|
|
2440
|
+
): Promise<SanityDocument<R>>
|
|
2441
|
+
/**
|
|
2442
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2443
|
+
* Returns a promise that resolves to an array containing the created document.
|
|
2444
|
+
*
|
|
2445
|
+
* @param document - Document to either create or replace
|
|
2446
|
+
* @param options - Mutation options
|
|
2447
|
+
*/
|
|
2448
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2449
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2450
|
+
options: AllDocumentsMutationOptions,
|
|
2451
|
+
): Promise<SanityDocument<R>[]>
|
|
2452
|
+
/**
|
|
2453
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2454
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the created document.
|
|
2455
|
+
*
|
|
2456
|
+
* @param document - Document to either create or replace
|
|
2457
|
+
* @param options - Mutation options
|
|
2458
|
+
*/
|
|
2459
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2460
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2461
|
+
options: FirstDocumentIdMutationOptions,
|
|
2462
|
+
): Promise<SingleMutationResult>
|
|
2463
|
+
/**
|
|
2464
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2465
|
+
* Returns a promise that resolves to a mutation result object containing the created document ID.
|
|
2466
|
+
*
|
|
2467
|
+
* @param document - Document to either create or replace
|
|
2468
|
+
* @param options - Mutation options
|
|
2469
|
+
*/
|
|
2470
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2471
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2472
|
+
options: AllDocumentIdsMutationOptions,
|
|
2473
|
+
): Promise<MultipleMutationResult>
|
|
2474
|
+
/**
|
|
2475
|
+
* Create a document if it does not exist, or replace a document with the same document ID
|
|
2476
|
+
* Returns a promise that resolves to the created document.
|
|
2477
|
+
*
|
|
2478
|
+
* @param document - Document to either create or replace
|
|
2479
|
+
* @param options - Mutation options
|
|
2480
|
+
*/
|
|
2481
|
+
createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
|
|
2482
|
+
document: IdentifiedSanityDocumentStub<R>,
|
|
2483
|
+
options?: BaseMutationOptions,
|
|
2484
|
+
): Promise<SanityDocument<R>>
|
|
2485
|
+
/**
|
|
2486
|
+
* Deletes a document with the given document ID.
|
|
2487
|
+
* Returns a promise that resolves to the deleted document.
|
|
2488
|
+
*
|
|
2489
|
+
* @param id - Document ID to delete
|
|
2490
|
+
* @param options - Options for the mutation
|
|
2491
|
+
*/
|
|
2492
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2493
|
+
id: string,
|
|
2494
|
+
options: FirstDocumentMutationOptions,
|
|
2495
|
+
): Promise<SanityDocument<R>>
|
|
2496
|
+
/**
|
|
2497
|
+
* Deletes a document with the given document ID.
|
|
2498
|
+
* Returns a promise that resolves to an array containing the deleted document.
|
|
2499
|
+
*
|
|
2500
|
+
* @param id - Document ID to delete
|
|
2501
|
+
* @param options - Options for the mutation
|
|
2502
|
+
*/
|
|
2503
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2504
|
+
id: string,
|
|
2505
|
+
options: AllDocumentsMutationOptions,
|
|
2506
|
+
): Promise<SanityDocument<R>[]>
|
|
2507
|
+
/**
|
|
2508
|
+
* Deletes a document with the given document ID.
|
|
2509
|
+
* Returns a promise that resolves to a mutation result object containing the deleted document ID.
|
|
2510
|
+
*
|
|
2511
|
+
* @param id - Document ID to delete
|
|
2512
|
+
* @param options - Options for the mutation
|
|
2513
|
+
*/
|
|
2514
|
+
delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
|
|
2515
|
+
/**
|
|
2516
|
+
* Deletes a document with the given document ID.
|
|
2517
|
+
* Returns a promise that resolves to a mutation result object containing the deleted document ID.
|
|
2518
|
+
*
|
|
2519
|
+
* @param id - Document ID to delete
|
|
2520
|
+
* @param options - Options for the mutation
|
|
2521
|
+
*/
|
|
2522
|
+
delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
|
|
2523
|
+
/**
|
|
2524
|
+
* Deletes a document with the given document ID.
|
|
2525
|
+
* Returns a promise that resolves to the deleted document.
|
|
2526
|
+
*
|
|
2527
|
+
* @param id - Document ID to delete
|
|
2528
|
+
* @param options - Options for the mutation
|
|
2529
|
+
*/
|
|
2530
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2531
|
+
id: string,
|
|
2532
|
+
options?: BaseMutationOptions,
|
|
2533
|
+
): Promise<SanityDocument<R>>
|
|
2534
|
+
/**
|
|
2535
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2536
|
+
* Returns a promise that resolves to first deleted document.
|
|
2537
|
+
*
|
|
2538
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2539
|
+
* @param options - Options for the mutation
|
|
2540
|
+
*/
|
|
2541
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2542
|
+
selection: MutationSelection,
|
|
2543
|
+
options: FirstDocumentMutationOptions,
|
|
2544
|
+
): Promise<SanityDocument<R>>
|
|
2545
|
+
/**
|
|
2546
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2547
|
+
* Returns a promise that resolves to an array containing the deleted documents.
|
|
2548
|
+
*
|
|
2549
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2550
|
+
* @param options - Options for the mutation
|
|
2551
|
+
*/
|
|
2552
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2553
|
+
selection: MutationSelection,
|
|
2554
|
+
options: AllDocumentsMutationOptions,
|
|
2555
|
+
): Promise<SanityDocument<R>[]>
|
|
2556
|
+
/**
|
|
2557
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2558
|
+
* Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
|
|
2559
|
+
*
|
|
2560
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2561
|
+
* @param options - Options for the mutation
|
|
2562
|
+
*/
|
|
2563
|
+
delete(
|
|
2564
|
+
selection: MutationSelection,
|
|
2565
|
+
options: FirstDocumentIdMutationOptions,
|
|
2566
|
+
): Promise<SingleMutationResult>
|
|
2567
|
+
/**
|
|
2568
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2569
|
+
* Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
|
|
2570
|
+
*
|
|
2571
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2572
|
+
* @param options - Options for the mutation
|
|
2573
|
+
*/
|
|
2574
|
+
delete(
|
|
2575
|
+
selection: MutationSelection,
|
|
2576
|
+
options: AllDocumentIdsMutationOptions,
|
|
2577
|
+
): Promise<MultipleMutationResult>
|
|
2578
|
+
/**
|
|
2579
|
+
* Deletes one or more documents matching the given query or document ID.
|
|
2580
|
+
* Returns a promise that resolves to first deleted document.
|
|
2581
|
+
*
|
|
2582
|
+
* @param selection - An object with either an `id` or `query` key defining what to delete
|
|
2583
|
+
* @param options - Options for the mutation
|
|
2584
|
+
*/
|
|
2585
|
+
delete<R extends Record<string, Any> = Record<string, Any>>(
|
|
2586
|
+
selection: MutationSelection,
|
|
2587
|
+
options?: BaseMutationOptions,
|
|
2588
|
+
): Promise<SanityDocument<R>>
|
|
2589
|
+
/**
|
|
2590
|
+
* Perform mutation operations against the configured dataset
|
|
2591
|
+
* Returns a promise that resolves to the first mutated document.
|
|
2592
|
+
*
|
|
2593
|
+
* @param operations - Mutation operations to execute
|
|
2594
|
+
* @param options - Mutation options
|
|
2595
|
+
*/
|
|
2596
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2597
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2598
|
+
options: FirstDocumentMutationOptions,
|
|
2599
|
+
): Promise<SanityDocument<R>>
|
|
2600
|
+
/**
|
|
2601
|
+
* Perform mutation operations against the configured dataset.
|
|
2602
|
+
* Returns a promise that resolves to an array of the mutated documents.
|
|
2603
|
+
*
|
|
2604
|
+
* @param operations - Mutation operations to execute
|
|
2605
|
+
* @param options - Mutation options
|
|
2606
|
+
*/
|
|
2607
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2608
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2609
|
+
options: AllDocumentsMutationOptions,
|
|
2610
|
+
): Promise<SanityDocument<R>[]>
|
|
2611
|
+
/**
|
|
2612
|
+
* Perform mutation operations against the configured dataset
|
|
2613
|
+
* Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
|
|
2614
|
+
*
|
|
2615
|
+
* @param operations - Mutation operations to execute
|
|
2616
|
+
* @param options - Mutation options
|
|
2617
|
+
*/
|
|
2618
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2619
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2620
|
+
options: FirstDocumentIdMutationOptions,
|
|
2621
|
+
): Promise<SingleMutationResult>
|
|
2622
|
+
/**
|
|
2623
|
+
* Perform mutation operations against the configured dataset
|
|
2624
|
+
* Returns a promise that resolves to a mutation result object containing the mutated document IDs.
|
|
2625
|
+
*
|
|
2626
|
+
* @param operations - Mutation operations to execute
|
|
2627
|
+
* @param options - Mutation options
|
|
2628
|
+
*/
|
|
2629
|
+
mutate<R extends Record<string, Any>>(
|
|
2630
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2631
|
+
options: AllDocumentIdsMutationOptions,
|
|
2632
|
+
): Promise<MultipleMutationResult>
|
|
2633
|
+
/**
|
|
2634
|
+
* Perform mutation operations against the configured dataset
|
|
2635
|
+
* Returns a promise that resolves to the first mutated document.
|
|
2636
|
+
*
|
|
2637
|
+
* @param operations - Mutation operations to execute
|
|
2638
|
+
* @param options - Mutation options
|
|
2639
|
+
*/
|
|
2640
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
2641
|
+
operations: Mutation<R>[] | Patch | Transaction,
|
|
2642
|
+
options?: BaseMutationOptions,
|
|
2643
|
+
): Promise<SanityDocument<R>>
|
|
2644
|
+
/**
|
|
2645
|
+
* Create a new buildable patch of operations to perform
|
|
2646
|
+
*
|
|
2647
|
+
* @param documentId - Document ID to patch
|
|
2648
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
2649
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
2650
|
+
*/
|
|
2651
|
+
patch(documentId: string, operations?: PatchOperations): Patch
|
|
2652
|
+
/**
|
|
2653
|
+
* Create a new buildable patch of operations to perform
|
|
2654
|
+
*
|
|
2655
|
+
* @param documentIds - Array of document IDs to patch
|
|
2656
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
2657
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
2658
|
+
*/
|
|
2659
|
+
patch(documentIds: string[], operations?: PatchOperations): Patch
|
|
2660
|
+
/**
|
|
2661
|
+
* Create a new buildable patch of operations to perform
|
|
2662
|
+
*
|
|
2663
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
2664
|
+
* @param operations - Optional object of patch operations to initialize the patch instance with
|
|
2665
|
+
* @returns Patch instance - call `.commit()` to perform the operations defined
|
|
2666
|
+
*/
|
|
2667
|
+
patch(selection: MutationSelection, operations?: PatchOperations): Patch
|
|
2668
|
+
/**
|
|
2669
|
+
* Create a new transaction of mutations
|
|
2670
|
+
*
|
|
2671
|
+
* @param operations - Optional array of mutation operations to initialize the transaction instance with
|
|
2672
|
+
*/
|
|
2673
|
+
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
2674
|
+
operations?: Mutation<R>[],
|
|
2675
|
+
): Transaction
|
|
2676
|
+
/**
|
|
2677
|
+
* Perform action operations against the configured dataset
|
|
2678
|
+
* Returns a promise that resolves to the transaction result
|
|
2679
|
+
*
|
|
2680
|
+
* @param operations - Action operation(s) to execute
|
|
2681
|
+
* @param options - Action options
|
|
2682
|
+
*/
|
|
2683
|
+
action(
|
|
2684
|
+
operations: Action | Action[],
|
|
2685
|
+
options?: BaseActionOptions,
|
|
2686
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
2687
|
+
/**
|
|
2688
|
+
* Perform a request against the Sanity API
|
|
2689
|
+
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
2690
|
+
*
|
|
2691
|
+
* @param options - Request options
|
|
2692
|
+
* @returns Promise resolving to the response body
|
|
2693
|
+
*/
|
|
2694
|
+
request<R = Any>(options: RawRequestOptions): Promise<R>
|
|
2695
|
+
/**
|
|
2696
|
+
* Perform an HTTP request a `/data` sub-endpoint
|
|
2697
|
+
* NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
|
|
2698
|
+
*
|
|
2699
|
+
* @deprecated - Use `request()` or your own HTTP library instead
|
|
2700
|
+
* @param endpoint - Endpoint to hit (mutate, query etc)
|
|
2701
|
+
* @param body - Request body
|
|
2702
|
+
* @param options - Request options
|
|
2703
|
+
* @internal
|
|
2704
|
+
*/
|
|
2705
|
+
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
|
|
2706
|
+
/**
|
|
2707
|
+
* Get a Sanity API URL for the URI provided
|
|
2708
|
+
*
|
|
2709
|
+
* @param uri - URI/path to build URL for
|
|
2710
|
+
* @param canUseCdn - Whether or not to allow using the API CDN for this route
|
|
2711
|
+
*/
|
|
2712
|
+
getUrl(uri: string, canUseCdn?: boolean): string
|
|
2713
|
+
/**
|
|
2714
|
+
* Get a Sanity API URL for the data operation and path provided
|
|
2715
|
+
*
|
|
2716
|
+
* @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
|
|
2717
|
+
* @param path - Path to append after the operation
|
|
2718
|
+
*/
|
|
2719
|
+
getDataUrl(operation: string, path?: string): string
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2722
|
+
/** @internal */
|
|
2723
|
+
declare type SanityDocument<T extends Record<string, Any> = Record<string, Any>> = {
|
|
2724
|
+
[P in keyof T]: T[P]
|
|
2725
|
+
} & {
|
|
2726
|
+
_id: string
|
|
2727
|
+
_rev: string
|
|
2728
|
+
_type: string
|
|
2729
|
+
_createdAt: string
|
|
2730
|
+
_updatedAt: string
|
|
2731
|
+
/**
|
|
2732
|
+
* Present when `perspective` is set to `previewDrafts`
|
|
2733
|
+
*/
|
|
2734
|
+
_originalId?: string
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
/** @public */
|
|
2738
|
+
declare type SanityDocumentStub<T extends Record<string, Any> = Record<string, Any>> = {
|
|
2739
|
+
[P in keyof T]: T[P]
|
|
2740
|
+
} & {
|
|
2741
|
+
_type: string
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
/** @internal */
|
|
2745
|
+
declare interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
2746
|
+
metadata: {
|
|
2747
|
+
_type: 'sanity.imageMetadata'
|
|
2748
|
+
hasAlpha: boolean
|
|
2749
|
+
isOpaque: boolean
|
|
2750
|
+
lqip?: string
|
|
2751
|
+
blurHash?: string
|
|
2752
|
+
dimensions: {
|
|
2753
|
+
_type: 'sanity.imageDimensions'
|
|
2754
|
+
aspectRatio: number
|
|
2755
|
+
height: number
|
|
2756
|
+
width: number
|
|
2757
|
+
}
|
|
2758
|
+
palette?: {
|
|
2759
|
+
_type: 'sanity.imagePalette'
|
|
2760
|
+
darkMuted?: SanityImagePalette
|
|
2761
|
+
darkVibrant?: SanityImagePalette
|
|
2762
|
+
dominant?: SanityImagePalette
|
|
2763
|
+
lightMuted?: SanityImagePalette
|
|
2764
|
+
lightVibrant?: SanityImagePalette
|
|
2765
|
+
muted?: SanityImagePalette
|
|
2766
|
+
vibrant?: SanityImagePalette
|
|
2767
|
+
}
|
|
2768
|
+
image?: {
|
|
2769
|
+
_type: 'sanity.imageExifTags'
|
|
2770
|
+
[key: string]: Any
|
|
2771
|
+
}
|
|
2772
|
+
exif?: {
|
|
2773
|
+
_type: 'sanity.imageExifMetadata'
|
|
2774
|
+
[key: string]: Any
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
/** @internal */
|
|
2780
|
+
declare interface SanityImagePalette {
|
|
2781
|
+
background: string
|
|
2782
|
+
foreground: string
|
|
2783
|
+
population: number
|
|
2784
|
+
title: string
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
/** @internal */
|
|
2788
|
+
declare interface SanityProject {
|
|
2789
|
+
id: string
|
|
2790
|
+
displayName: string
|
|
2791
|
+
/**
|
|
2792
|
+
* @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
|
|
2793
|
+
* @see https://www.sanity.io/help/studio-host-user-applications
|
|
2794
|
+
*/
|
|
2795
|
+
studioHost: string | null
|
|
2796
|
+
organizationId: string | null
|
|
2797
|
+
isBlocked: boolean
|
|
2798
|
+
isDisabled: boolean
|
|
2799
|
+
isDisabledByUser: boolean
|
|
2800
|
+
createdAt: string
|
|
2801
|
+
pendingInvites?: number
|
|
2802
|
+
maxRetentionDays?: number
|
|
2803
|
+
members: SanityProjectMember[]
|
|
2804
|
+
metadata: {
|
|
2805
|
+
cliInitializedAt?: string
|
|
2806
|
+
color?: string
|
|
2807
|
+
/**
|
|
2808
|
+
* @deprecated Use the `/user-applications` endpoint instead, which lists all deployed studios/applications
|
|
2809
|
+
* @see https://www.sanity.io/help/studio-host-user-applications
|
|
2810
|
+
*/
|
|
2811
|
+
externalStudioHost?: string
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2815
|
+
/** @internal */
|
|
2816
|
+
declare interface SanityProjectMember {
|
|
2817
|
+
id: string
|
|
2818
|
+
role: string
|
|
2819
|
+
isRobot: boolean
|
|
2820
|
+
isCurrentUser: boolean
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
/** @public */
|
|
2824
|
+
declare interface SanityQueries {}
|
|
2825
|
+
|
|
2826
|
+
/** @internal */
|
|
2827
|
+
declare interface SanityUser {
|
|
2828
|
+
id: string
|
|
2829
|
+
projectId: string
|
|
2830
|
+
displayName: string
|
|
2831
|
+
familyName: string | null
|
|
2832
|
+
givenName: string | null
|
|
2833
|
+
middleName: string | null
|
|
2834
|
+
imageUrl: string | null
|
|
2835
|
+
createdAt: string
|
|
2836
|
+
updatedAt: string
|
|
2837
|
+
isCurrentUser: boolean
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
/** @internal */
|
|
2841
|
+
declare interface SingleActionResult {
|
|
2842
|
+
transactionId: string
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
/** @internal */
|
|
2846
|
+
declare interface SingleMutationResult {
|
|
2847
|
+
transactionId: string
|
|
2848
|
+
documentId: string
|
|
2849
|
+
results: {
|
|
2850
|
+
id: string
|
|
2851
|
+
operation: MutationOperation
|
|
2852
|
+
}[]
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
/** @public */
|
|
2856
|
+
declare interface StegaConfig {
|
|
2857
|
+
/**
|
|
2858
|
+
* Enable or disable stega encoded strings in query results
|
|
2859
|
+
* ```ts
|
|
2860
|
+
{
|
|
2861
|
+
enabled: process.env.VERCEL_ENV !== 'production'
|
|
2862
|
+
}
|
|
2863
|
+
* ```
|
|
2864
|
+
* @defaultValue `false`
|
|
2865
|
+
*/
|
|
2866
|
+
enabled?: boolean
|
|
2867
|
+
/**
|
|
2868
|
+
* Where the Studio is hosted.
|
|
2869
|
+
* If it's embedded in the app, use the base path for example `/studio`.
|
|
2870
|
+
* Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.
|
|
2871
|
+
*
|
|
2872
|
+
*/
|
|
2873
|
+
studioUrl?: StudioUrl | ResolveStudioUrl
|
|
2874
|
+
filter?: FilterDefault
|
|
2875
|
+
/**
|
|
2876
|
+
* Specify a `console.log` compatible logger to see debug logs, which keys are encoded and which are not.
|
|
2877
|
+
*/
|
|
2878
|
+
logger?: Logger
|
|
2879
|
+
/**
|
|
2880
|
+
* Set to `true` to omit cross dataset reference specific data from encoded strings
|
|
2881
|
+
*/
|
|
2882
|
+
omitCrossDatasetReferenceData?: boolean
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
/** @public */
|
|
2886
|
+
declare type StegaConfigRequiredKeys = Extract<keyof StegaConfig, 'enabled'>
|
|
2887
|
+
|
|
2888
|
+
/** @alpha */
|
|
2889
|
+
declare type StudioBaseRoute = {
|
|
2890
|
+
baseUrl: StudioBaseUrl
|
|
2891
|
+
workspace?: string
|
|
2892
|
+
tool?: string
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
/** @alpha */
|
|
2896
|
+
declare type StudioBaseUrl = `/${string}` | `${string}.sanity.studio` | `https://${string}` | string
|
|
2897
|
+
|
|
2898
|
+
/** @alpha */
|
|
2899
|
+
declare type StudioUrl = StudioBaseUrl | StudioBaseRoute
|
|
2900
|
+
|
|
2901
|
+
/** @public */
|
|
2902
|
+
declare type SyncTag = `s1:${string}`
|
|
2903
|
+
|
|
2904
|
+
/** @public */
|
|
2905
|
+
declare class Transaction extends BaseTransaction {
|
|
2906
|
+
#private
|
|
2907
|
+
constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
|
|
2908
|
+
/**
|
|
2909
|
+
* Clones the transaction
|
|
2910
|
+
*/
|
|
2911
|
+
clone(): Transaction
|
|
2912
|
+
/**
|
|
2913
|
+
* Commit the transaction, returning a promise that resolves to the first mutated document
|
|
2914
|
+
*
|
|
2915
|
+
* @param options - Options for the mutation operation
|
|
2916
|
+
*/
|
|
2917
|
+
commit<R extends Record<string, Any>>(
|
|
2918
|
+
options: TransactionFirstDocumentMutationOptions,
|
|
2919
|
+
): Promise<SanityDocument<R>>
|
|
2920
|
+
/**
|
|
2921
|
+
* Commit the transaction, returning a promise that resolves to an array of the mutated documents
|
|
2922
|
+
*
|
|
2923
|
+
* @param options - Options for the mutation operation
|
|
2924
|
+
*/
|
|
2925
|
+
commit<R extends Record<string, Any>>(
|
|
2926
|
+
options: TransactionAllDocumentsMutationOptions,
|
|
2927
|
+
): Promise<SanityDocument<R>[]>
|
|
2928
|
+
/**
|
|
2929
|
+
* Commit the transaction, returning a promise that resolves to a mutation result object
|
|
2930
|
+
*
|
|
2931
|
+
* @param options - Options for the mutation operation
|
|
2932
|
+
*/
|
|
2933
|
+
commit(options: TransactionFirstDocumentIdMutationOptions): Promise<SingleMutationResult>
|
|
2934
|
+
/**
|
|
2935
|
+
* Commit the transaction, returning a promise that resolves to a mutation result object
|
|
2936
|
+
*
|
|
2937
|
+
* @param options - Options for the mutation operation
|
|
2938
|
+
*/
|
|
2939
|
+
commit(options: TransactionAllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
|
|
2940
|
+
/**
|
|
2941
|
+
* Commit the transaction, returning a promise that resolves to a mutation result object
|
|
2942
|
+
*
|
|
2943
|
+
* @param options - Options for the mutation operation
|
|
2944
|
+
*/
|
|
2945
|
+
commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
|
|
2946
|
+
/**
|
|
2947
|
+
* Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
|
|
2948
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
2949
|
+
*
|
|
2950
|
+
* @param documentId - Document ID to perform the patch operation on
|
|
2951
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
2952
|
+
*/
|
|
2953
|
+
patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
|
|
2954
|
+
/**
|
|
2955
|
+
* Performs a patch on the given selection. Can either be a builder function or an object of patch operations.
|
|
2956
|
+
*
|
|
2957
|
+
* @param selection - An object with `query` and optional `params`, defining which document(s) to patch
|
|
2958
|
+
* @param patchOps - Operations to perform, or a builder function
|
|
2959
|
+
*/
|
|
2960
|
+
patch(patch: MutationSelection, patchOps?: PatchBuilder | PatchOperations): this
|
|
2961
|
+
/**
|
|
2962
|
+
* Adds the given patch instance to the transaction.
|
|
2963
|
+
* The operation is added to the current transaction, ready to be commited by `commit()`
|
|
2964
|
+
*
|
|
2965
|
+
* @param patch - Patch to execute
|
|
2966
|
+
*/
|
|
2967
|
+
patch(patch: Patch): this
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
/** @internal */
|
|
2971
|
+
declare type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
2972
|
+
returnFirst?: false
|
|
2973
|
+
returnDocuments?: false
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
/** @internal */
|
|
2977
|
+
declare type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
|
|
2978
|
+
returnFirst?: false
|
|
2979
|
+
returnDocuments: true
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
/** @internal */
|
|
2983
|
+
declare type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
|
|
2984
|
+
returnFirst: true
|
|
2985
|
+
returnDocuments?: false
|
|
2986
|
+
}
|
|
2987
|
+
|
|
2988
|
+
/** @internal */
|
|
2989
|
+
declare type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
|
|
2990
|
+
returnFirst: true
|
|
2991
|
+
returnDocuments: true
|
|
2992
|
+
}
|
|
2993
|
+
|
|
2994
|
+
/** @public */
|
|
2995
|
+
declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
|
|
2996
|
+
filterResponse: false
|
|
2997
|
+
/**
|
|
2998
|
+
* When `filterResponse` is `false`, `returnQuery` also defaults to `true` for
|
|
2999
|
+
* backwards compatibility (on the client side, not from the content lake API).
|
|
3000
|
+
* Can also explicitly be set to `true`.
|
|
3001
|
+
*/
|
|
3002
|
+
returnQuery?: true
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
/**
|
|
3006
|
+
* When using `filterResponse: false`, but you do not wish to receive back the query from
|
|
3007
|
+
* the content lake API.
|
|
3008
|
+
*
|
|
3009
|
+
* @public
|
|
3010
|
+
*/
|
|
3011
|
+
declare interface UnfilteredResponseWithoutQuery extends ResponseQueryOptions {
|
|
3012
|
+
filterResponse: false
|
|
3013
|
+
returnQuery: false
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
/**
|
|
3017
|
+
* Retract a published document.
|
|
3018
|
+
* If there is no draft version then this is created from the published version.
|
|
3019
|
+
* In either case the published version is deleted.
|
|
3020
|
+
*
|
|
3021
|
+
* @public
|
|
3022
|
+
*/
|
|
3023
|
+
declare type UnpublishAction = {
|
|
3024
|
+
actionType: 'sanity.action.document.unpublish'
|
|
3025
|
+
/**
|
|
3026
|
+
* Draft document ID to replace the published document with
|
|
3027
|
+
*/
|
|
3028
|
+
draftId: string
|
|
3029
|
+
/**
|
|
3030
|
+
* Published document ID to delete
|
|
3031
|
+
*/
|
|
3032
|
+
publishedId: string
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
/** @public */
|
|
3036
|
+
declare type UploadBody = File | Blob | Buffer | NodeJS.ReadableStream
|
|
3037
|
+
|
|
3038
|
+
/** @public */
|
|
3039
|
+
declare interface UploadClientConfig {
|
|
3040
|
+
/**
|
|
3041
|
+
* Optional request tag for the upload
|
|
3042
|
+
*/
|
|
3043
|
+
tag?: string
|
|
3044
|
+
/**
|
|
3045
|
+
* Whether or not to preserve the original filename (default: true)
|
|
3046
|
+
*/
|
|
3047
|
+
preserveFilename?: boolean
|
|
3048
|
+
/**
|
|
3049
|
+
* Filename for this file (optional)
|
|
3050
|
+
*/
|
|
3051
|
+
filename?: string
|
|
3052
|
+
/**
|
|
3053
|
+
* Milliseconds to wait before timing the request out
|
|
3054
|
+
*/
|
|
3055
|
+
timeout?: number
|
|
3056
|
+
/**
|
|
3057
|
+
* Mime type of the file
|
|
3058
|
+
*/
|
|
3059
|
+
contentType?: string
|
|
3060
|
+
/**
|
|
3061
|
+
* Array of metadata parts to extract from asset
|
|
3062
|
+
*/
|
|
3063
|
+
extract?: AssetMetadataType[]
|
|
3064
|
+
/**
|
|
3065
|
+
* Optional freeform label for the asset. Generally not used.
|
|
3066
|
+
*/
|
|
3067
|
+
label?: string
|
|
3068
|
+
/**
|
|
3069
|
+
* Optional title for the asset
|
|
3070
|
+
*/
|
|
3071
|
+
title?: string
|
|
3072
|
+
/**
|
|
3073
|
+
* Optional description for the asset
|
|
3074
|
+
*/
|
|
3075
|
+
description?: string
|
|
3076
|
+
/**
|
|
3077
|
+
* The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published
|
|
3078
|
+
*/
|
|
3079
|
+
creditLine?: string
|
|
3080
|
+
/**
|
|
3081
|
+
* Source data (when the asset is from an external service)
|
|
3082
|
+
*/
|
|
3083
|
+
source?: {
|
|
3084
|
+
/**
|
|
3085
|
+
* The (u)id of the asset within the source, i.e. 'i-f323r1E'
|
|
3086
|
+
*/
|
|
3087
|
+
id: string
|
|
3088
|
+
/**
|
|
3089
|
+
* The name of the source, i.e. 'unsplash'
|
|
3090
|
+
*/
|
|
3091
|
+
name: string
|
|
3092
|
+
/**
|
|
3093
|
+
* A url to where to find the asset, or get more info about it in the source
|
|
3094
|
+
*/
|
|
3095
|
+
url?: string
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
|
|
61
3099
|
/**
|
|
62
3100
|
* @internal
|
|
63
3101
|
* A React hook that subscribes to authentication state changes.
|
|
@@ -90,6 +3128,33 @@ export declare const useAuthState: () => AuthState
|
|
|
90
3128
|
*/
|
|
91
3129
|
export declare const useAuthToken: () => string | null
|
|
92
3130
|
|
|
3131
|
+
/**
|
|
3132
|
+
* A React hook that provides a client that subscribes to changes in your application,
|
|
3133
|
+
* such as user authentication changes.
|
|
3134
|
+
*
|
|
3135
|
+
* @remarks
|
|
3136
|
+
* The hook uses `useSyncExternalStore` to safely subscribe to changes
|
|
3137
|
+
* and ensure consistency between server and client rendering.
|
|
3138
|
+
*
|
|
3139
|
+
* @returns A Sanity client
|
|
3140
|
+
*
|
|
3141
|
+
* @example
|
|
3142
|
+
* ```tsx
|
|
3143
|
+
* function MyComponent() {
|
|
3144
|
+
* const client = useClient()
|
|
3145
|
+
* const [document, setDocument] = useState(null)
|
|
3146
|
+
* useEffect(async () => {
|
|
3147
|
+
* const doc = client.fetch('*[_id == "myDocumentId"]')
|
|
3148
|
+
* setDocument(doc)
|
|
3149
|
+
* }, [])
|
|
3150
|
+
* return <div>{JSON.stringify(document) ?? 'Loading...'}</div>
|
|
3151
|
+
* }
|
|
3152
|
+
* ```
|
|
3153
|
+
*
|
|
3154
|
+
* @public
|
|
3155
|
+
*/
|
|
3156
|
+
export declare function useClient(options: ClientOptions): SanityClient
|
|
3157
|
+
|
|
93
3158
|
/**
|
|
94
3159
|
* @TODO This should suspend! And possibly not return `null`?
|
|
95
3160
|
*
|
|
@@ -343,6 +3408,18 @@ export declare interface UsePreviewResults {
|
|
|
343
3408
|
isPending: boolean
|
|
344
3409
|
}
|
|
345
3410
|
|
|
3411
|
+
/** @public */
|
|
3412
|
+
declare class UsersClient {
|
|
3413
|
+
#private
|
|
3414
|
+
constructor(client: SanityClient, httpRequest: HttpRequest)
|
|
3415
|
+
/**
|
|
3416
|
+
* Fetch a user by user ID
|
|
3417
|
+
*
|
|
3418
|
+
* @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
|
|
3419
|
+
*/
|
|
3420
|
+
getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
|
|
3421
|
+
}
|
|
3422
|
+
|
|
346
3423
|
/**
|
|
347
3424
|
* `useSanityInstance` returns the current Sanity instance from the application context.
|
|
348
3425
|
* This must be called from within a `SanityProvider` component.
|
|
@@ -372,6 +3449,17 @@ export declare interface UseWindowConnectionOptions<TMessage extends FrameMessag
|
|
|
372
3449
|
onMessage?: Record<TMessage['type'], WindowMessageHandler<TMessage>>
|
|
373
3450
|
}
|
|
374
3451
|
|
|
3452
|
+
/**
|
|
3453
|
+
* The listener has been established, and will start receiving events.
|
|
3454
|
+
* Note that this is also emitted upon _reconnection_.
|
|
3455
|
+
*
|
|
3456
|
+
* @public
|
|
3457
|
+
*/
|
|
3458
|
+
declare type WelcomeEvent = {
|
|
3459
|
+
type: 'welcome'
|
|
3460
|
+
listenerName: string
|
|
3461
|
+
}
|
|
3462
|
+
|
|
375
3463
|
/**
|
|
376
3464
|
* @internal
|
|
377
3465
|
*/
|