@sanity/client 4.0.1 → 5.0.0-esm.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/index.browser.cjs +1335 -0
  2. package/dist/index.browser.cjs.map +1 -0
  3. package/dist/index.browser.js +1312 -0
  4. package/dist/index.browser.js.map +1 -0
  5. package/dist/index.cjs +1344 -0
  6. package/dist/index.cjs.js +15 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/{sanityClient.d.ts → dist/index.d.ts} +991 -1117
  9. package/dist/index.js +1321 -0
  10. package/dist/index.js.map +1 -0
  11. package/package.json +81 -73
  12. package/src/SanityClient.ts +1261 -0
  13. package/src/assets/AssetsClient.ts +164 -0
  14. package/src/auth/AuthClient.ts +43 -0
  15. package/src/config.ts +95 -0
  16. package/src/data/dataMethods.ts +328 -0
  17. package/src/data/encodeQueryString.ts +28 -0
  18. package/src/data/listen.ts +195 -0
  19. package/src/data/patch.ts +353 -0
  20. package/src/data/transaction.ts +352 -0
  21. package/src/datasets/DatasetsClient.ts +97 -0
  22. package/src/generateHelpUrl.ts +5 -0
  23. package/src/http/browserMiddleware.ts +1 -0
  24. package/src/http/errors.ts +68 -0
  25. package/src/http/nodeMiddleware.ts +11 -0
  26. package/src/http/request.ts +50 -0
  27. package/src/http/requestOptions.ts +31 -0
  28. package/src/index.browser.ts +18 -0
  29. package/src/index.ts +57 -0
  30. package/src/projects/ProjectsClient.ts +45 -0
  31. package/src/types.ts +502 -0
  32. package/src/users/UsersClient.ts +46 -0
  33. package/src/util/defaults.ts +8 -0
  34. package/src/util/getSelection.ts +21 -0
  35. package/src/util/once.ts +12 -0
  36. package/src/util/pick.ts +9 -0
  37. package/src/validators.ts +76 -0
  38. package/src/warnings.ts +25 -0
  39. package/umd/sanityClient.js +5199 -5302
  40. package/umd/sanityClient.min.js +13 -13
  41. package/dist/sanityClient.browser.mjs +0 -2806
  42. package/dist/sanityClient.browser.mjs.map +0 -7
  43. package/index.js +0 -7
  44. package/lib/assets/assetsClient.js +0 -145
  45. package/lib/auth/authClient.js +0 -26
  46. package/lib/config.js +0 -88
  47. package/lib/data/dataMethods.js +0 -205
  48. package/lib/data/encodeQueryString.js +0 -31
  49. package/lib/data/listen.js +0 -164
  50. package/lib/data/patch.js +0 -121
  51. package/lib/data/transaction.js +0 -117
  52. package/lib/datasets/datasetsClient.js +0 -41
  53. package/lib/generateHelpUrl.js +0 -11
  54. package/lib/http/browserMiddleware.js +0 -9
  55. package/lib/http/errors.js +0 -56
  56. package/lib/http/nodeMiddleware.js +0 -22
  57. package/lib/http/queryString.js +0 -17
  58. package/lib/http/request.js +0 -52
  59. package/lib/http/requestOptions.js +0 -30
  60. package/lib/projects/projectsClient.js +0 -25
  61. package/lib/sanityClient.js +0 -118
  62. package/lib/users/usersClient.js +0 -20
  63. package/lib/util/defaults.js +0 -14
  64. package/lib/util/getSelection.js +0 -24
  65. package/lib/util/once.js +0 -20
  66. package/lib/util/pick.js +0 -17
  67. package/lib/validators.js +0 -76
  68. package/lib/warnings.js +0 -27
@@ -1,7 +1,20 @@
1
- /* eslint-disable no-dupe-class-members, @typescript-eslint/no-misused-new */
2
- import type {Observable} from 'rxjs'
1
+ /// <reference types="node" />
3
2
 
4
- export type AssetMetadataType =
3
+ import {BaseError} from 'make-error'
4
+ import {Observable} from 'rxjs'
5
+ import {Requester} from 'get-it'
6
+
7
+ export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
8
+ returnFirst: false
9
+ returnDocuments: false
10
+ }
11
+
12
+ export declare type AllDocumentsMutationOptions = BaseMutationOptions & {
13
+ returnFirst: false
14
+ returnDocuments?: true
15
+ }
16
+
17
+ export declare type AssetMetadataType =
5
18
  | 'location'
6
19
  | 'exif'
7
20
  | 'image'
@@ -9,222 +22,149 @@ export type AssetMetadataType =
9
22
  | 'lqip'
10
23
  | 'blurhash'
11
24
  | 'none'
12
- export type DatasetAclMode = 'public' | 'private' | 'custom'
13
- export type ListenVisibility = 'sync' | 'async' | 'query'
14
- export type ListenEventName = 'mutation' | 'welcome' | 'reconnect'
15
- export type MutationOperation = 'create' | 'delete' | 'update' | 'none'
16
25
 
17
- export interface ResponseEvent<T = unknown> {
18
- type: 'response'
19
- body: T
20
- url: string
21
- method: string
22
- statusCode: number
23
- statusMessage?: string
24
- headers: Record<string, string>
26
+ export declare class AssetsClient {
27
+ #private
28
+ constructor(client: SanityClient, httpRequest: HttpRequest)
29
+ /**
30
+ * Uploads a file asset to the configured dataset
31
+ *
32
+ * @param assetType Asset type (file/image)
33
+ * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
34
+ * @param options Options to use for the upload
35
+ */
36
+ upload(
37
+ assetType: 'file',
38
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
39
+ options?: UploadClientConfig
40
+ ): Promise<SanityAssetDocument>
41
+ /**
42
+ * Uploads an image asset to the configured dataset
43
+ *
44
+ * @param assetType Asset type (file/image)
45
+ * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
46
+ * @param options Options to use for the upload
47
+ */
48
+ upload(
49
+ assetType: 'image',
50
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
51
+ options?: UploadClientConfig
52
+ ): Promise<SanityImageAssetDocument>
25
53
  }
26
54
 
27
- export interface ProgressEvent {
28
- type: 'progress'
29
- stage: 'upload' | 'download'
30
- percent: number
31
- total?: number
32
- loaded?: number
33
- lengthComputable: boolean
55
+ export declare type AttributeSet = {
56
+ [key: string]: any
34
57
  }
35
58
 
36
- type AttributeSet = {[key: string]: any}
37
- type QueryParams = {[key: string]: any}
38
- type MutationSelection = {query: string; params?: QueryParams} | {id: string}
39
- type SanityReference = {_ref: string}
40
-
41
- interface RawRequestOptions {
42
- url?: string
43
- uri?: string
44
- method?: string
45
- token?: string
46
- json?: boolean
47
- tag?: string
48
- useGlobalApi?: boolean
49
- withCredentials?: boolean
50
- query?: {[key: string]: string | string[]}
51
- headers?: {[key: string]: string}
52
- timeout?: number
53
- proxy?: string
54
- body?: any
55
- maxRedirects?: number
59
+ export declare class AuthClient extends BaseAuthClient {
60
+ client: SanityClient
61
+ constructor(client: SanityClient)
56
62
  }
57
63
 
58
- interface AuthProvider {
64
+ export declare interface AuthProvider {
59
65
  name: string
60
66
  title: string
61
67
  url: string
62
68
  }
63
69
 
64
- interface SanityUser {
65
- id: string
66
- projectId: string
67
- displayName: string
68
- familyName: string | null
69
- givenName: string | null
70
- middleName: string | null
71
- imageUrl: string | null
72
- createdAt: string
73
- updatedAt: string
74
- isCurrentUser: boolean
75
- }
76
-
77
- interface CurrentSanityUser {
78
- id: string
79
- name: string
80
- email: string
81
- profileImage: string | null
82
- role: string
83
- }
84
-
85
- interface SanityProjectMember {
86
- id: string
87
- role: string
88
- isRobot: boolean
89
- isCurrentUser: boolean
90
- }
91
-
92
- interface SanityProject {
93
- id: string
94
- displayName: string
95
- studioHost: string | null
96
- organizationId: string | null
97
- isBlocked: boolean
98
- isDisabled: boolean
99
- isDisabledByUser: boolean
100
- createdAt: string
101
- pendingInvites?: number
102
- maxRetentionDays?: number
103
- members: SanityProjectMember[]
104
- metadata: {
105
- color?: string
106
- externalStudioHost?: string
107
- }
108
- }
109
-
110
- type GetItRequester = {
111
- use: (middleware: any) => GetItRequester
112
- clone(): GetItRequester
70
+ export declare type AuthProviderResponse = {
71
+ providers: AuthProvider[]
113
72
  }
114
73
 
115
- export interface UploadOptions {
116
- /**
117
- * Optional request tag for the upload
118
- */
119
- tag?: string
120
-
121
- /**
122
- * Whether or not to preserve the original filename (default: true)
123
- */
124
- preserveFilename?: boolean
125
-
126
- /**
127
- * Filename for this file (optional)
128
- */
129
- filename?: string
130
-
131
- /**
132
- * Milliseconds to wait before timing the request out
133
- */
134
- timeout?: number
135
-
136
- /**
137
- * Mime type of the file
138
- */
139
- contentType?: string
140
-
74
+ export declare class BaseAuthClient {
75
+ client: SanityClient | ObservableSanityClient
141
76
  /**
142
- * Array of metadata parts to extract from asset
77
+ * Fetch available login providers
143
78
  */
144
- extract?: AssetMetadataType[]
145
-
79
+ getLoginProviders(this: AuthClient): Promise<AuthProviderResponse>
80
+ getLoginProviders(this: ObservableAuthClient): Observable<AuthProviderResponse>
146
81
  /**
147
- * Optional freeform label for the asset. Generally not used.
82
+ * Revoke the configured session/token
148
83
  */
149
- label?: string
84
+ logout(this: AuthClient): Promise<any>
85
+ logout(this: ObservableAuthClient): Observable<any>
86
+ }
150
87
 
88
+ export declare class BaseDatasetsClient {
89
+ #private
90
+ client: SanityClient | ObservableSanityClient
151
91
  /**
152
- * Optional title for the asset
92
+ * Create a new dataset with the given name
93
+ *
94
+ * @param name - Name of the dataset to create
95
+ * @param options - Options for the dataset
153
96
  */
154
- title?: string
155
-
97
+ create(
98
+ this: DatasetsClient,
99
+ name: string,
100
+ options?: {
101
+ aclMode?: DatasetAclMode
102
+ }
103
+ ): Promise<DatasetResponse>
104
+ create(
105
+ this: ObservableDatasetsClient,
106
+ name: string,
107
+ options?: {
108
+ aclMode?: DatasetAclMode
109
+ }
110
+ ): Observable<DatasetResponse>
156
111
  /**
157
- * Optional description for the asset
112
+ * Edit a dataset with the given name
113
+ *
114
+ * @param name - Name of the dataset to edit
115
+ * @param options - New options for the dataset
158
116
  */
159
- description?: string
160
-
117
+ edit(
118
+ this: DatasetsClient,
119
+ name: string,
120
+ options?: {
121
+ aclMode?: DatasetAclMode
122
+ }
123
+ ): Promise<DatasetResponse>
124
+ edit(
125
+ this: ObservableDatasetsClient,
126
+ name: string,
127
+ options?: {
128
+ aclMode?: DatasetAclMode
129
+ }
130
+ ): Observable<DatasetResponse>
161
131
  /**
162
- * The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published
132
+ * Delete a dataset with the given name
133
+ *
134
+ * @param name - Name of the dataset to delete
163
135
  */
164
- creditLine?: string
165
-
136
+ delete(
137
+ this: DatasetsClient,
138
+ name: string
139
+ ): Promise<{
140
+ deleted: true
141
+ }>
142
+ delete(
143
+ this: ObservableDatasetsClient,
144
+ name: string
145
+ ): Observable<{
146
+ deleted: true
147
+ }>
166
148
  /**
167
- * Source data (when the asset is from an external service)
149
+ * Fetch a list of datasets for the configured project
168
150
  */
169
- source?: {
170
- /**
171
- * The (u)id of the asset within the source, i.e. 'i-f323r1E'
172
- */
173
- id: string
174
-
175
- /**
176
- * The name of the source, i.e. 'unsplash'
177
- */
178
- name: string
179
-
180
- /**
181
- * A url to where to find the asset, or get more info about it in the source
182
- */
183
- url?: string
184
- }
185
- }
186
-
187
- export type InsertPatch =
188
- | {before: string; items: any[]}
189
- | {after: string; items: any[]}
190
- | {replace: string; items: any[]}
191
-
192
- // Note: this is actually incorrect/invalid, but implemented as-is for backwards compatibility
193
- export interface PatchOperations {
194
- set?: {[key: string]: any}
195
- setIfMissing?: {[key: string]: any}
196
- diffMatchPatch?: {[key: string]: any}
197
- unset?: string[]
198
- inc?: {[key: string]: number}
199
- dec?: {[key: string]: number}
200
- insert?: InsertPatch
201
- ifRevisionID?: string
202
- }
203
-
204
- export type PatchBuilder = (patch: Patch) => Patch
205
-
206
- export type PatchMutationOperation = PatchOperations & MutationSelection
207
-
208
- export type Mutation<R extends Record<string, any> = Record<string, any>> =
209
- | {create: SanityDocumentStub<R>}
210
- | {createOrReplace: IdentifiedSanityDocumentStub<R>}
211
- | {createIfNotExists: IdentifiedSanityDocumentStub<R>}
212
- | {delete: MutationSelection}
213
- | {patch: PatchMutationOperation}
214
-
215
- export interface SingleMutationResult {
216
- transactionId: string
217
- documentId: string
218
- results: {id: string; operation: MutationOperation}[]
151
+ list(this: DatasetsClient): Promise<DatasetsResponse>
152
+ list(this: ObservableDatasetsClient): Observable<DatasetsResponse>
219
153
  }
220
154
 
221
- export interface MultipleMutationResult {
222
- transactionId: string
223
- documentIds: string[]
224
- results: {id: string; operation: MutationOperation}[]
155
+ export declare type BaseMutationOptions = RequestOptions & {
156
+ visibility?: 'sync' | 'async' | 'deferred'
157
+ returnDocuments?: boolean
158
+ returnFirst?: boolean
159
+ dryRun?: boolean
160
+ autoGenerateArrayKeys?: boolean
161
+ skipCrossDatasetReferenceValidation?: boolean
225
162
  }
226
163
 
227
- export abstract class BasePatch {
164
+ export declare class BasePatch {
165
+ protected selection: PatchSelection
166
+ protected operations: PatchOperations
167
+ constructor(selection: PatchSelection, operations?: PatchOperations)
228
168
  /**
229
169
  * DEPRECATED: Don't use.
230
170
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -233,7 +173,6 @@ export abstract class BasePatch {
233
173
  * @param attrs Attributes to replace
234
174
  */
235
175
  replace(attrs: AttributeSet): this
236
-
237
176
  /**
238
177
  * Sets the given attributes to the document. Does NOT merge objects.
239
178
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -241,7 +180,6 @@ export abstract class BasePatch {
241
180
  * @param attrs Attributes to set. To set a deep attribute, use JSONMatch, eg: {"nested.prop": "value"}
242
181
  */
243
182
  set(attrs: AttributeSet): this
244
-
245
183
  /**
246
184
  * Sets the given attributes to the document if they are not currently set. Does NOT merge objects.
247
185
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -249,7 +187,6 @@ export abstract class BasePatch {
249
187
  * @param attrs Attributes to set. To set a deep attribute, use JSONMatch, eg: {"nested.prop": "value"}
250
188
  */
251
189
  setIfMissing(attrs: AttributeSet): this
252
-
253
190
  /**
254
191
  * Performs a "diff-match-patch" operation on the string attributes provided.
255
192
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -257,7 +194,6 @@ export abstract class BasePatch {
257
194
  * @param attrs Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: {"nested.prop": "dmp"}
258
195
  */
259
196
  diffMatchPatch(attrs: AttributeSet): this
260
-
261
197
  /**
262
198
  * Unsets the attribute paths provided.
263
199
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -265,21 +201,18 @@ export abstract class BasePatch {
265
201
  * @param attrs Attribute paths to unset.
266
202
  */
267
203
  unset(attrs: string[]): this
268
-
269
204
  /**
270
205
  * 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.
271
206
  *
272
207
  * @param attrs Object of attribute paths to increment, values representing the number to increment by.
273
208
  */
274
209
  inc(attrs: {[key: string]: number}): this
275
-
276
210
  /**
277
211
  * 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.
278
212
  *
279
213
  * @param attrs Object of attribute paths to decrement, values representing the number to decrement by.
280
214
  */
281
215
  dec(attrs: {[key: string]: number}): this
282
-
283
216
  /**
284
217
  * Provides methods for modifying arrays, by inserting, appending and replacing elements via a JSONPath expression.
285
218
  *
@@ -288,7 +221,6 @@ export abstract class BasePatch {
288
221
  * @param items Array of items to insert/replace
289
222
  */
290
223
  insert(at: 'before' | 'after' | 'replace', selector: string, items: any[]): this
291
-
292
224
  /**
293
225
  * Append the given items to the array at the given JSONPath
294
226
  *
@@ -296,7 +228,6 @@ export abstract class BasePatch {
296
228
  * @param items Array of items to append to the array
297
229
  */
298
230
  append(selector: string, items: any[]): this
299
-
300
231
  /**
301
232
  * Prepend the given items to the array at the given JSONPath
302
233
  *
@@ -304,7 +235,6 @@ export abstract class BasePatch {
304
235
  * @param items Array of items to prepend to the array
305
236
  */
306
237
  prepend(selector: string, items: any[]): this
307
-
308
238
  /**
309
239
  * Change the contents of an array by removing existing elements and/or adding new elements.
310
240
  *
@@ -314,306 +244,157 @@ export abstract class BasePatch {
314
244
  * @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.
315
245
  */
316
246
  splice(selector: string, start: number, deleteCount: number, items: any[]): this
317
-
318
247
  /**
319
248
  * Adds a revision clause, preventing the document from being patched if the `_rev` property does not match the given value
320
249
  *
321
250
  * @param rev Revision to lock the patch to
322
251
  */
323
252
  ifRevisionId(rev: string): this
324
-
325
253
  /**
326
254
  * Return a plain JSON representation of the patch
327
255
  */
328
256
  serialize(): PatchMutationOperation
329
-
330
257
  /**
331
258
  * Return a plain JSON representation of the patch
332
259
  */
333
260
  toJSON(): PatchMutationOperation
334
-
335
261
  /**
336
262
  * Clears the patch of all operations
337
263
  */
338
264
  reset(): this
265
+ protected _assign(op: keyof PatchOperations, props: any, merge?: boolean): this
266
+ protected _set(op: keyof PatchOperations, props: any): this
339
267
  }
340
268
 
341
- export class Patch extends BasePatch {
342
- constructor(documentId: string, operations?: PatchOperations, client?: SanityClient)
343
-
269
+ export declare class BaseProjectsClient {
270
+ client: SanityClient | ObservableSanityClient
344
271
  /**
345
- * Clones the patch
272
+ * Fetch a list of projects the authenticated user has access to
346
273
  */
347
- clone(): Patch
348
-
274
+ list(this: ProjectsClient): Promise<SanityProject[]>
275
+ list(this: ObservableProjectsClient): Observable<SanityProject[]>
349
276
  /**
350
- * Commit the patch, returning a promise that resolves to the first patched document
277
+ * Fetch a project by project ID
351
278
  *
352
- * @param options Options for the mutation operation
279
+ * @param projectId - ID of the project to fetch
353
280
  */
354
- commit<R extends Record<string, any> = Record<string, any>>(
355
- options: FirstDocumentMutationOptions
356
- ): Promise<SanityDocument<R>>
281
+ getById(this: ProjectsClient, projectId: string): Promise<SanityProject>
282
+ getById(this: ObservableProjectsClient, projectId: string): Observable<SanityProject>
283
+ }
357
284
 
285
+ export declare class BaseSanityClient {
286
+ #private
287
+ constructor(config: ClientConfig)
288
+ /** @internal */
289
+ protected config(newConfig?: Partial<ClientConfig>): ClientConfig | this
358
290
  /**
359
- * Commit the patch, returning a promise that resolves to an array of the mutated documents
360
- *
361
- * @param options Options for the mutation operation
291
+ * Returns whether or not this client is using the Promise API (otherwise it is using observables)
292
+ * @internal
293
+ * @deprecated Internals, should not be used externally
362
294
  */
363
- commit<R extends Record<string, any> = Record<string, any>>(
364
- options: AllDocumentsMutationOptions
365
- ): Promise<SanityDocument<R>[]>
366
-
295
+ isPromiseAPI(): this is SanityClient
367
296
  /**
368
- * Commit the patch, returning a promise that resolves to a mutation result object
297
+ * DEPRECATED: Get a Sanity API URL for the URI provided
369
298
  *
370
- * @param options Options for the mutation operation
299
+ * @deprecated Should be an internal concern
300
+ * @param uri URI/path to build URL for
301
+ * @param canUseCdn Whether or not to allow using the API CDN for this route
371
302
  */
372
- commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
373
-
303
+ getUrl(uri: string, canUseCdn?: boolean): string
374
304
  /**
375
- * Commit the patch, returning a promise that resolves to a mutation result object
305
+ * DEPRECATED: Get a Sanity API URL for the data operation and path provided
376
306
  *
377
- * @param options Options for the mutation operation
307
+ * @deprecated Should be an internal concern
308
+ * @param operation Data operation
309
+ * @param path Path to append
378
310
  */
379
- commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
311
+ getDataUrl(operation: string, path?: string): string
312
+ }
380
313
 
314
+ export declare class BaseTransaction {
315
+ protected operations: Mutation[]
316
+ protected trxId?: string
317
+ constructor(operations?: Mutation[], transactionId?: string)
381
318
  /**
382
- * Commit the patch, returning a promise that resolves to the first patched document
319
+ * 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.
320
+ * The operation is added to the current transaction, ready to be commited by `commit()`
383
321
  *
384
- * @param options Options for the mutation operation
322
+ * @param doc - Document to create. Requires a `_type` property.
385
323
  */
386
- commit<R extends Record<string, any> = Record<string, any>>(
387
- options?: BaseMutationOptions
388
- ): Promise<SanityDocument<R>>
389
- }
390
-
391
- export class ObservablePatch extends BasePatch {
392
- constructor(documentId: string, operations?: PatchOperations, client?: ObservableSanityClient)
393
-
324
+ create<R extends Record<string, any> = Record<string, any>>(doc: SanityDocumentStub<R>): this
394
325
  /**
395
- * Clones the patch
326
+ * Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
327
+ * The operation is added to the current transaction, ready to be commited by `commit()`
328
+ *
329
+ * @param doc - Document to create if it does not already exist. Requires `_id` and `_type` properties.
396
330
  */
397
- clone(): ObservablePatch
398
-
331
+ createIfNotExists<R extends Record<string, any> = Record<string, any>>(
332
+ doc: IdentifiedSanityDocumentStub<R>
333
+ ): this
399
334
  /**
400
- * Commit the patch, returning an observable that produces the first patched document
335
+ * Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
336
+ * The operation is added to the current transaction, ready to be commited by `commit()`
401
337
  *
402
- * @param options Options for the mutation operation
338
+ * @param doc - Document to create or replace. Requires `_id` and `_type` properties.
403
339
  */
404
- commit<R extends Record<string, any> = Record<string, any>>(
405
- options: FirstDocumentMutationOptions
406
- ): Observable<SanityDocument<R>>
407
-
340
+ createOrReplace<R extends Record<string, any> = Record<string, any>>(
341
+ doc: IdentifiedSanityDocumentStub<R>
342
+ ): this
408
343
  /**
409
- * Commit the patch, returning an observable that produces an array of the mutated documents
344
+ * Deletes the document with the given document ID
345
+ * The operation is added to the current transaction, ready to be commited by `commit()`
410
346
  *
411
- * @param options Options for the mutation operation
412
- */
413
- commit<R extends Record<string, any> = Record<string, any>>(
414
- options: AllDocumentsMutationOptions
415
- ): Observable<SanityDocument<R>[]>
416
-
417
- /**
418
- * Commit the patch, returning an observable that produces a mutation result object
419
- *
420
- * @param options Options for the mutation operation
421
- */
422
- commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
423
-
424
- /**
425
- * Commit the patch, returning an observable that produces a mutation result object
426
- *
427
- * @param options Options for the mutation operation
428
- */
429
- commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
430
-
431
- /**
432
- * Commit the patch, returning an observable that produces the first patched document
433
- *
434
- * @param options Options for the mutation operation
435
- */
436
- commit<R extends Record<string, any> = Record<string, any>>(
437
- options?: BaseMutationOptions
438
- ): Observable<SanityDocument<R>>
439
- }
440
-
441
- export abstract class BaseTransaction {
442
- /**
443
- * 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.
444
- * The operation is added to the current transaction, ready to be commited by `commit()`
445
- *
446
- * @param doc Document to create. Requires a `_type` property.
447
- */
448
- create<R extends Record<string, any> = Record<string, any>>(doc: SanityDocumentStub<R>): this
449
-
450
- /**
451
- * Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
452
- * The operation is added to the current transaction, ready to be commited by `commit()`
453
- *
454
- * @param doc Document to create if it does not already exist. Requires `_id` and `_type` properties.
455
- */
456
- createIfNotExists<R extends Record<string, any> = Record<string, any>>(
457
- doc: IdentifiedSanityDocumentStub<R>
458
- ): this
459
-
460
- /**
461
- * Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
462
- * The operation is added to the current transaction, ready to be commited by `commit()`
463
- *
464
- * @param doc Document to create or replace. Requires `_id` and `_type` properties.
465
- */
466
- createOrReplace<R extends Record<string, any> = Record<string, any>>(
467
- doc: IdentifiedSanityDocumentStub<R>
468
- ): this
469
-
470
- /**
471
- * Deletes the document with the given document ID
472
- * The operation is added to the current transaction, ready to be commited by `commit()`
473
- *
474
- * @param documentId Document ID to delete
347
+ * @param documentId - Document ID to delete
475
348
  */
476
349
  delete(documentId: string): this
477
-
478
- /**
479
- * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
480
- * The operation is added to the current transaction, ready to be commited by `commit()`
481
- *
482
- * @param documentId Document ID to perform the patch operation on
483
- * @param patchOps Operations to perform, or a builder function
484
- */
485
- patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
486
-
487
350
  /**
488
- * Adds the given patch instance to the transaction.
489
- * The operation is added to the current transaction, ready to be commited by `commit()`
490
- *
491
- * @param patch Patch to execute
351
+ * Gets the current transaction ID, if any
492
352
  */
493
- patch(patch: Patch): this
494
-
353
+ transactionId(): string | undefined
495
354
  /**
496
- * Set or gets the ID of this transaction.
497
- * Should generally not be specified.
498
- * If no ID is specified, the currently configured ID will be returned, if any.
355
+ * Set the ID of this transaction.
499
356
  *
500
- * @param id Transaction ID
357
+ * @param id - Transaction ID
501
358
  */
502
- transactionId<T extends string | undefined>(id: T): T extends string ? this : string | undefined
503
-
359
+ transactionId(id: string): this
504
360
  /**
505
361
  * Return a plain JSON representation of the transaction
506
362
  */
507
363
  serialize(): Mutation[]
508
-
509
364
  /**
510
365
  * Return a plain JSON representation of the transaction
511
366
  */
512
367
  toJSON(): Mutation[]
513
-
514
368
  /**
515
369
  * Clears the transaction of all operations
516
370
  */
517
371
  reset(): this
372
+ protected _add(mut: Mutation): this
518
373
  }
519
374
 
520
- export class Transaction extends BaseTransaction {
521
- constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
522
-
523
- /**
524
- * Clones the transaction
525
- */
526
- clone(): Transaction
527
-
528
- /**
529
- * Commit the transaction, returning a promise that resolves to the first mutated document
530
- *
531
- * @param options Options for the mutation operation
532
- */
533
- commit<R extends Record<string, any>>(
534
- options: TransactionFirstDocumentMutationOptions
535
- ): Promise<SanityDocument<R>>
536
-
537
- /**
538
- * Commit the transaction, returning a promise that resolves to an array of the mutated documents
539
- *
540
- * @param options Options for the mutation operation
541
- */
542
- commit<R extends Record<string, any>>(
543
- options: TransactionAllDocumentsMutationOptions
544
- ): Promise<SanityDocument<R>[]>
545
-
546
- /**
547
- * Commit the transaction, returning a promise that resolves to a mutation result object
548
- *
549
- * @param options Options for the mutation operation
550
- */
551
- commit(options: TransactionFirstDocumentIdMutationOptions): Promise<SingleMutationResult>
552
-
553
- /**
554
- * Commit the transaction, returning a promise that resolves to a mutation result object
555
- *
556
- * @param options Options for the mutation operation
557
- */
558
- commit(options: TransactionAllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
559
-
375
+ export declare class BaseUsersClient {
376
+ client: SanityClient | ObservableSanityClient
560
377
  /**
561
- * Commit the transaction, returning a promise that resolves to a mutation result object
378
+ * Fetch a user by user ID
562
379
  *
563
- * @param options Options for the mutation operation
380
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
564
381
  */
565
- commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
382
+ getById<T extends 'me' | string>(
383
+ this: UsersClient,
384
+ id: T
385
+ ): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
386
+ getById<T extends 'me' | string>(
387
+ this: ObservableUsersClient,
388
+ id: T
389
+ ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
566
390
  }
567
391
 
568
- export class ObservableTransaction extends BaseTransaction {
569
- constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
570
-
571
- /**
572
- * Clones the transaction
573
- */
574
- clone(): ObservableTransaction
575
-
576
- /**
577
- * Commit the transaction, returning an observable that produces the first mutated document
578
- *
579
- * @param options Options for the mutation operation
580
- */
581
- commit<R extends Record<string, any>>(
582
- options: TransactionFirstDocumentMutationOptions
583
- ): Observable<SanityDocument<R>>
584
-
585
- /**
586
- * Commit the transaction, returning an observable that produces an array of the mutated documents
587
- *
588
- * @param options Options for the mutation operation
589
- */
590
- commit<R extends Record<string, any>>(
591
- options: TransactionAllDocumentsMutationOptions
592
- ): Observable<SanityDocument<R>[]>
593
-
594
- /**
595
- * Commit the transaction, returning an observable that produces a mutation result object
596
- *
597
- * @param options Options for the mutation operation
598
- */
599
- commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
600
-
601
- /**
602
- * Commit the transaction, returning an observable that produces a mutation result object
603
- *
604
- * @param options Options for the mutation operation
605
- */
606
- commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
607
-
608
- /**
609
- * Commit the transaction, returning an observable that produces a mutation result object
610
- *
611
- * @param options Options for the mutation operation
612
- */
613
- commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
392
+ export declare type ChannelErrorEvent = {
393
+ type: 'channelError'
394
+ message: string
614
395
  }
615
396
 
616
- export interface ClientConfig {
397
+ export declare interface ClientConfig {
617
398
  projectId?: string
618
399
  dataset?: string
619
400
  useCdn?: boolean
@@ -626,90 +407,165 @@ export interface ClientConfig {
626
407
  withCredentials?: boolean
627
408
  allowReconfigure?: boolean
628
409
  timeout?: number
629
-
630
410
  /**
631
411
  * @deprecated Don't use
632
412
  */
633
413
  useProjectHostname?: boolean
634
-
635
414
  /**
636
415
  * @deprecated Don't use
637
416
  */
638
- requester?: GetItRequester
417
+ requester?: Requester
639
418
  }
640
419
 
641
- /**
642
- * @deprecated Don't use
643
- */
644
- export type ProjectlessClientConfig = ClientConfig & {useProjectHostname: false}
420
+ export declare class ClientError extends BaseError {
421
+ response: ErrorProps['response']
422
+ statusCode: ErrorProps['statusCode']
423
+ responseBody: ErrorProps['responseBody']
424
+ details: ErrorProps['details']
425
+ constructor(res: any)
426
+ }
645
427
 
646
- /**
647
- * @deprecated Don't use
648
- */
649
- export type ProjectClientConfig = ClientConfig & {
650
- useProjectHostname?: true
651
- projectId: string
428
+ export declare function createClient(config: ClientConfig): SanityClient
429
+
430
+ export declare interface CurrentSanityUser {
431
+ id: string
432
+ name: string
433
+ email: string
434
+ profileImage: string | null
435
+ role: string
652
436
  }
653
437
 
654
- export interface RequestOptions {
655
- timeout?: number
656
- token?: string
657
- tag?: string
658
- headers?: Record<string, string>
438
+ export declare type DatasetAclMode = 'public' | 'private' | 'custom'
439
+
440
+ export declare type DatasetResponse = {
441
+ datasetName: string
442
+ aclMode: DatasetAclMode
659
443
  }
660
444
 
661
- type BaseMutationOptions = RequestOptions & {
662
- visibility?: 'sync' | 'async' | 'deferred'
663
- returnDocuments?: boolean
664
- returnFirst?: boolean
665
- dryRun?: boolean
666
- autoGenerateArrayKeys?: boolean
667
- skipCrossDatasetReferenceValidation?: boolean
445
+ export declare class DatasetsClient extends BaseDatasetsClient {
446
+ client: SanityClient
447
+ constructor(client: SanityClient)
668
448
  }
669
449
 
670
- export type MutationEvent<R extends Record<string, any> = Record<string, any>> = {
671
- type: 'mutation'
672
- documentId: string
673
- eventId: string
674
- identity: string
675
- mutations: Mutation[]
676
- previousRev?: string
677
- resultRev?: string
678
- result?: SanityDocument<R>
679
- previous?: SanityDocument<R> | null
680
- effects?: {apply: unknown[]; revert: unknown[]}
681
- timestamp: string
682
- transactionId: string
683
- transition: 'update' | 'appear' | 'disappear'
684
- visibility: 'query' | 'transaction'
450
+ export declare type DatasetsResponse = {
451
+ name: string
452
+ aclMode: DatasetAclMode
453
+ }[]
454
+
455
+ export declare type DisconnectEvent = {
456
+ type: 'disconnect'
457
+ reason: string
685
458
  }
686
459
 
687
- export type ChannelErrorEvent = {
688
- type: 'channelError'
460
+ export declare interface ErrorProps {
689
461
  message: string
462
+ response: any
463
+ statusCode: number
464
+ responseBody: any
465
+ details: any
690
466
  }
691
467
 
692
- export type DisconnectEvent = {
693
- type: 'disconnect'
694
- reason: string
468
+ export declare type FilteredResponseQueryOptions = RequestOptions & {
469
+ filterResponse?: true
695
470
  }
696
471
 
697
- export type ReconnectEvent = {
698
- type: 'reconnect'
472
+ export declare type FirstDocumentIdMutationOptions = BaseMutationOptions & {
473
+ returnFirst?: true
474
+ returnDocuments: false
699
475
  }
700
476
 
701
- export type WelcomeEvent = {
702
- type: 'welcome'
477
+ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
478
+ returnFirst?: true
479
+ returnDocuments?: true
480
+ }
481
+
482
+ export declare type HttpRequest = {
483
+ defaultRequester: Requester
484
+ (options: RequestOptions, requester: Requester): ReturnType<Requester>
485
+ }
486
+
487
+ export declare type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent_2
488
+
489
+ export declare type IdentifiedSanityDocumentStub<
490
+ T extends Record<string, any> = Record<string, any>
491
+ > = {
492
+ [P in keyof T]: T[P]
493
+ } & {
494
+ _id: string
495
+ } & SanityDocumentStub
496
+
497
+ export declare interface InitializedClientConfig extends ClientConfig {
498
+ apiHost: string
499
+ apiVersion: string
500
+ useProjectHostname: boolean
501
+ useCdn: boolean
502
+ /**
503
+ * @deprecated Don't use
504
+ */
505
+ isDefaultApi: boolean
506
+ /**
507
+ * @deprecated Don't use
508
+ */
509
+ url: string
510
+ /**
511
+ * @deprecated Don't use
512
+ */
513
+ cdnUrl: string
703
514
  }
704
515
 
705
- export type ListenEvent<R extends Record<string, any>> =
706
- | MutationEvent<R>
516
+ export declare type InsertPatch =
517
+ | {
518
+ before: string
519
+ items: any[]
520
+ }
521
+ | {
522
+ after: string
523
+ items: any[]
524
+ }
525
+ | {
526
+ replace: string
527
+ items: any[]
528
+ }
529
+
530
+ /**
531
+ * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
532
+ *
533
+ * @param query GROQ-filter to listen to changes for
534
+ * @param params Optional query parameters
535
+ * @param options Listener options
536
+ * @internal
537
+ */
538
+ export declare function _listen<R extends Record<string, any> = Record<string, any>>(
539
+ this: SanityClient,
540
+ query: string,
541
+ params?: QueryParams
542
+ ): Observable<MutationEvent_2<R>>
543
+
544
+ /**
545
+ * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
546
+ *
547
+ * @param query GROQ-filter to listen to changes for
548
+ * @param params Optional query parameters
549
+ * @param options Listener options
550
+ * @internal
551
+ */
552
+ export declare function _listen<R extends Record<string, any> = Record<string, any>>(
553
+ this: SanityClient,
554
+ query: string,
555
+ params?: QueryParams,
556
+ options?: ListenOptions
557
+ ): Observable<ListenEvent<R>>
558
+
559
+ export declare type ListenEvent<R extends Record<string, any>> =
560
+ | MutationEvent_2<R>
707
561
  | ChannelErrorEvent
708
562
  | DisconnectEvent
709
563
  | ReconnectEvent
710
564
  | WelcomeEvent
711
565
 
712
- export interface ListenOptions {
566
+ export declare type ListenEventName = 'mutation' | 'welcome' | 'reconnect'
567
+
568
+ export declare interface ListenOptions {
713
569
  includeResult?: boolean
714
570
  includePreviousRevision?: boolean
715
571
  visibility?: 'sync' | 'async' | 'query'
@@ -718,384 +574,199 @@ export interface ListenOptions {
718
574
  tag?: string
719
575
  }
720
576
 
721
- export type PreviousNextListenOptions = ListenOptions & {
722
- includeResult: true
723
- includePreviousRevision: true
724
- }
725
-
726
- export type PreviousListenOptions = ListenOptions & {
727
- includePreviousRevision: true
728
- includeResult: false
729
- }
730
-
731
- export type NextListenOptions = ListenOptions & {
732
- includePreviousRevision: false
733
- includeResult: true
577
+ export declare interface MultipleMutationResult {
578
+ transactionId: string
579
+ documentIds: string[]
580
+ results: {
581
+ id: string
582
+ operation: MutationOperation
583
+ }[]
734
584
  }
735
585
 
736
- export type ResultlessListenOptions = ListenOptions & {
737
- includeResult: false
738
- includePreviousRevision: false
739
- }
740
-
741
- export type FilteredResponseQueryOptions = RequestOptions & {
742
- filterResponse?: true
743
- }
744
-
745
- export type UnfilteredResponseQueryOptions = RequestOptions & {
746
- filterResponse: false
747
- }
748
-
749
- export type QueryOptions = FilteredResponseQueryOptions | UnfilteredResponseQueryOptions
750
-
751
- type FirstDocumentMutationOptions = BaseMutationOptions & {
752
- returnFirst?: true
753
- returnDocuments?: true
754
- }
755
-
756
- type FirstDocumentIdMutationOptions = BaseMutationOptions & {
757
- returnFirst?: true
758
- returnDocuments: false
759
- }
760
-
761
- type AllDocumentsMutationOptions = BaseMutationOptions & {
762
- returnFirst: false
763
- returnDocuments?: true
764
- }
765
-
766
- type AllDocumentIdsMutationOptions = BaseMutationOptions & {
767
- returnFirst: false
768
- returnDocuments: false
769
- }
770
-
771
- export type MutationOptions =
772
- | FirstDocumentMutationOptions
773
- | FirstDocumentIdMutationOptions
774
- | AllDocumentsMutationOptions
775
- | AllDocumentIdsMutationOptions
776
-
777
- type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
778
- returnFirst: true
779
- returnDocuments: true
780
- }
781
-
782
- type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
783
- returnFirst: true
784
- returnDocuments?: false
785
- }
786
-
787
- type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
788
- returnFirst?: false
789
- returnDocuments: true
790
- }
586
+ export declare type Mutation<R extends Record<string, any> = Record<string, any>> =
587
+ | {
588
+ create: SanityDocumentStub<R>
589
+ }
590
+ | {
591
+ createOrReplace: IdentifiedSanityDocumentStub<R>
592
+ }
593
+ | {
594
+ createIfNotExists: IdentifiedSanityDocumentStub<R>
595
+ }
596
+ | {
597
+ delete: MutationSelection
598
+ }
599
+ | {
600
+ patch: PatchMutationOperation
601
+ }
791
602
 
792
- type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
793
- returnFirst?: false
794
- returnDocuments?: false
603
+ declare type MutationEvent_2<R extends Record<string, any> = Record<string, any>> = {
604
+ type: 'mutation'
605
+ documentId: string
606
+ eventId: string
607
+ identity: string
608
+ mutations: Mutation[]
609
+ previousRev?: string
610
+ resultRev?: string
611
+ result?: SanityDocument<R>
612
+ previous?: SanityDocument<R> | null
613
+ effects?: {
614
+ apply: unknown[]
615
+ revert: unknown[]
616
+ }
617
+ timestamp: string
618
+ transactionId: string
619
+ transition: 'update' | 'appear' | 'disappear'
620
+ visibility: 'query' | 'transaction'
795
621
  }
622
+ export {MutationEvent_2 as MutationEvent}
796
623
 
797
- export type TransactionMutationOptions =
798
- | TransactionFirstDocumentMutationOptions
799
- | TransactionFirstDocumentIdMutationOptions
800
- | TransactionAllDocumentsMutationOptions
801
- | TransactionAllDocumentIdsMutationOptions
802
-
803
- export interface RawQueryResponse<R> {
804
- q: string
805
- ms: number
806
- result: R
807
- }
624
+ export declare type MutationOperation = 'create' | 'delete' | 'update' | 'none'
808
625
 
809
- export type SanityDocument<T extends Record<string, any> = Record<string, any>> = {
810
- [P in keyof T]: T[P]
811
- } & {
812
- _id: string
813
- _rev: string
814
- _type: string
815
- _createdAt: string
816
- _updatedAt: string
817
- }
626
+ export declare type MutationSelection =
627
+ | {
628
+ query: string
629
+ params?: QueryParams
630
+ }
631
+ | {
632
+ id: string | string[]
633
+ }
818
634
 
819
- export type SanityDocumentStub<T extends Record<string, any> = Record<string, any>> = {
820
- [P in keyof T]: T[P]
821
- } & {
822
- _type: string
635
+ export declare class ObservableAssetsClient {
636
+ #private
637
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
638
+ /**
639
+ * Uploads a file asset to the configured dataset
640
+ *
641
+ * @param assetType Asset type (file/image)
642
+ * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
643
+ * @param options Options to use for the upload
644
+ */
645
+ upload(
646
+ assetType: 'file',
647
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
648
+ options?: UploadClientConfig
649
+ ): Observable<
650
+ HttpRequestEvent<{
651
+ document: SanityAssetDocument
652
+ }>
653
+ >
654
+ /**
655
+ * Uploads an image asset to the configured dataset
656
+ *
657
+ * @param assetType Asset type (file/image)
658
+ * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
659
+ * @param options Options to use for the upload
660
+ */
661
+ upload(
662
+ assetType: 'image',
663
+ body: File | Blob | Buffer | NodeJS.ReadableStream,
664
+ options?: UploadClientConfig
665
+ ): Observable<
666
+ HttpRequestEvent<{
667
+ document: SanityImageAssetDocument
668
+ }>
669
+ >
823
670
  }
824
671
 
825
- export type IdentifiedSanityDocumentStub<T extends Record<string, any> = Record<string, any>> = {
826
- [P in keyof T]: T[P]
827
- } & {
828
- _id: string
829
- } & SanityDocumentStub
830
-
831
- export interface SanityAssetDocument extends SanityDocument {
832
- url: string
833
- path: string
834
- size: number
835
- assetId: string
836
- mimeType: string
837
- sha1hash: string
838
- extension: string
839
- uploadId?: string
840
- originalFilename?: string
672
+ export declare class ObservableAuthClient extends BaseAuthClient {
673
+ client: ObservableSanityClient
674
+ constructor(client: ObservableSanityClient)
841
675
  }
842
676
 
843
- export interface SanityImagePalette {
844
- background: string
845
- foreground: string
846
- population: number
847
- title: string
677
+ export declare class ObservableDatasetsClient extends BaseDatasetsClient {
678
+ client: ObservableSanityClient
679
+ constructor(client: ObservableSanityClient)
848
680
  }
849
681
 
850
- export interface SanityImageAssetDocument extends SanityAssetDocument {
851
- metadata: {
852
- _type: 'sanity.imageMetadata'
853
- hasAlpha: boolean
854
- isOpaque: boolean
855
- lqip?: string
856
- blurHash?: string
857
- dimensions: {
858
- _type: 'sanity.imageDimensions'
859
- aspectRatio: number
860
- height: number
861
- width: number
862
- }
863
- palette?: {
864
- _type: 'sanity.imagePalette'
865
- darkMuted?: SanityImagePalette
866
- darkVibrant?: SanityImagePalette
867
- dominant?: SanityImagePalette
868
- lightMuted?: SanityImagePalette
869
- lightVibrant?: SanityImagePalette
870
- muted?: SanityImagePalette
871
- vibrant?: SanityImagePalette
872
- }
873
- image?: {
874
- _type: 'sanity.imageExifTags'
875
- [key: string]: any
876
- }
877
- exif?: {
878
- _type: 'sanity.imageExifMetadata'
879
- [key: string]: any
880
- }
881
- }
682
+ export declare class ObservablePatch extends BasePatch {
683
+ #private
684
+ constructor(
685
+ selection: PatchSelection,
686
+ operations?: PatchOperations,
687
+ client?: ObservableSanityClient
688
+ )
689
+ /**
690
+ * Clones the patch
691
+ */
692
+ clone(): ObservablePatch
693
+ /**
694
+ * Commit the patch, returning an observable that produces the first patched document
695
+ *
696
+ * @param options Options for the mutation operation
697
+ */
698
+ commit<R extends Record<string, any> = Record<string, any>>(
699
+ options: FirstDocumentMutationOptions
700
+ ): Observable<SanityDocument<R>>
701
+ /**
702
+ * Commit the patch, returning an observable that produces an array of the mutated documents
703
+ *
704
+ * @param options Options for the mutation operation
705
+ */
706
+ commit<R extends Record<string, any> = Record<string, any>>(
707
+ options: AllDocumentsMutationOptions
708
+ ): Observable<SanityDocument<R>[]>
709
+ /**
710
+ * Commit the patch, returning an observable that produces a mutation result object
711
+ *
712
+ * @param options Options for the mutation operation
713
+ */
714
+ commit(options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
715
+ /**
716
+ * Commit the patch, returning an observable that produces a mutation result object
717
+ *
718
+ * @param options Options for the mutation operation
719
+ */
720
+ commit(options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
721
+ /**
722
+ * Commit the patch, returning an observable that produces the first patched document
723
+ *
724
+ * @param options Options for the mutation operation
725
+ */
726
+ commit<R extends Record<string, any> = Record<string, any>>(
727
+ options?: BaseMutationOptions
728
+ ): Observable<SanityDocument<R>>
882
729
  }
883
730
 
884
- export class ClientError extends Error {
885
- response: any
886
- statusCode: number
887
- responseBody?: any
888
- details?: any
889
- }
731
+ export declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
890
732
 
891
- export class ServerError extends Error {
892
- response: any
893
- statusCode: number
894
- responseBody?: any
895
- details?: any
733
+ export declare class ObservableProjectsClient extends BaseProjectsClient {
734
+ client: ObservableSanityClient
735
+ constructor(client: ObservableSanityClient)
896
736
  }
897
737
 
898
- export class ObservableSanityClient {
899
- static Patch: typeof Patch
900
- static Transaction: typeof Transaction
901
- static ClientError: typeof ClientError
902
- static ServerError: typeof ServerError
903
- static requester: GetItRequester
904
-
905
- // Client/configuration
906
- constructor(config: ClientConfig)
907
-
738
+ export declare class ObservableSanityClient extends BaseSanityClient {
739
+ #private
740
+ assets: ObservableAssetsClient
741
+ auth: ObservableAuthClient
742
+ datasets: ObservableDatasetsClient
743
+ projects: ObservableProjectsClient
744
+ users: ObservableUsersClient
745
+ constructor(httpRequest: HttpRequest, config: ClientConfig)
908
746
  /**
909
747
  * Clone the client - returns a new instance
910
748
  */
911
749
  clone(): ObservableSanityClient
912
-
913
750
  /**
914
751
  * Returns the current client configuration
915
752
  */
916
- config(): ClientConfig
917
-
753
+ config(): InitializedClientConfig
918
754
  /**
919
755
  * Reconfigure the client. Note that this _mutates_ the current client.
920
- *
921
- * @param newConfig New client configuration properties
922
756
  */
923
757
  config(newConfig?: Partial<ClientConfig>): this
924
-
925
758
  /**
926
759
  * Clone the client with a new (partial) configuration.
927
760
  *
928
761
  * @param newConfig New client configuration properties, shallowly merged with existing configuration
929
762
  */
930
763
  withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClient
931
-
932
- /**
933
- * @deprecated Use `client.config()` instead
934
- */
935
- clientConfig: ClientConfig
936
-
937
- assets: {
938
- /**
939
- * Uploads a file asset to the configured dataset
940
- *
941
- * @param assetType Asset type (file/image)
942
- * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
943
- * @param options Options to use for the upload
944
- */
945
- upload(
946
- assetType: 'file' | 'image',
947
- body: File | Blob | Buffer | NodeJS.ReadableStream,
948
- options?: UploadOptions
949
- ): Observable<
950
- ResponseEvent<{document: SanityAssetDocument | SanityImageAssetDocument}> | ProgressEvent
951
- >
952
-
953
- /**
954
- * Uploads a file asset to the configured dataset
955
- *
956
- * @param assetType Asset type (file/image)
957
- * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
958
- * @param options Options to use for the upload
959
- */
960
- upload(
961
- assetType: 'file',
962
- body: File | Blob | Buffer | NodeJS.ReadableStream,
963
- options?: UploadOptions
964
- ): Observable<ResponseEvent<{document: SanityAssetDocument}> | ProgressEvent>
965
-
966
- /**
967
- * Uploads an image asset to the configured dataset
968
- *
969
- * @param assetType Asset type (file/image)
970
- * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
971
- * @param options Options to use for the upload
972
- */
973
- upload(
974
- assetType: 'image',
975
- body: File | Blob | Buffer | NodeJS.ReadableStream,
976
- options?: UploadOptions
977
- ): Observable<ResponseEvent<{document: SanityImageAssetDocument}> | ProgressEvent>
978
-
979
- /**
980
- * DEPRECATED: Deletes an asset of the given type and ID
981
- *
982
- * @deprecated Use `client.delete(assetDocumentId)` instead
983
- * @param assetType Asset type (file/image)
984
- * @param id Document ID or asset document to delete
985
- */
986
- delete(
987
- assetType: 'file' | 'image',
988
- id: string | IdentifiedSanityDocumentStub
989
- ): Observable<SanityAssetDocument | undefined>
990
-
991
- /**
992
- * DEPRECATED: Returns the URL for an asset with a given document ID
993
- *
994
- * @deprecated Use the `@sanity/image-url` module instead
995
- * @param id Document ID or asset reference to get URL for
996
- * @param query Optional object of query string parameters to append
997
- */
998
- getImageUrl(id: string | SanityReference, query: {[key: string]: string | number}): string
999
- }
1000
-
1001
- datasets: {
1002
- /**
1003
- * Create a new dataset with the given name
1004
- *
1005
- * @param name Name of the dataset to create
1006
- * @param options Options for the dataset
1007
- */
1008
- create(
1009
- name: string,
1010
- options?: {aclMode?: DatasetAclMode}
1011
- ): Observable<{datasetName: string; aclMode: DatasetAclMode}>
1012
-
1013
- /**
1014
- * Edit a dataset with the given name
1015
- *
1016
- * @param name Name of the dataset to edit
1017
- * @param options New options for the dataset
1018
- */
1019
- edit(
1020
- name: string,
1021
- options: {aclMode?: DatasetAclMode}
1022
- ): Observable<{datasetName: string; aclMode: DatasetAclMode}>
1023
-
1024
- /**
1025
- * Delete a dataset with the given name
1026
- *
1027
- * @param name Name of the dataset to delete
1028
- */
1029
- delete(name: string): Observable<{deleted: true}>
1030
-
1031
- /**
1032
- * Fetch a list of datasets for the configured project
1033
- */
1034
- list(): Observable<{name: string; aclMode: DatasetAclMode}[]>
1035
- }
1036
-
1037
- projects: {
1038
- /**
1039
- * Fetch a list of projects the authenticated user has access to
1040
- */
1041
- list(): Observable<SanityProject[]>
1042
-
1043
- /**
1044
- * Fetch a project by project ID
1045
- *
1046
- * @param projectId ID of the project to fetch
1047
- */
1048
- getById(projectId: string): Observable<SanityProject>
1049
- }
1050
-
1051
- users: {
1052
- /**
1053
- * Fetch a user by user ID
1054
- *
1055
- * @param id User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
1056
- */
1057
- getById<T extends 'me' | string>(
1058
- id: T
1059
- ): T extends 'me' ? Observable<CurrentSanityUser> : Observable<SanityUser>
1060
- }
1061
-
1062
- auth: {
1063
- /**
1064
- * Fetch available login providers
1065
- */
1066
- getLoginProviders(): Observable<{providers: AuthProvider[]}>
1067
-
1068
- /**
1069
- * Revoke the configured session/token
1070
- */
1071
- logout(): Observable<any>
1072
- }
1073
-
1074
- /**
1075
- * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1076
- *
1077
- * @param query GROQ-filter to listen to changes for
1078
- * @param params Optional query parameters
1079
- * @param options Listener options
1080
- */
1081
- listen(query: string, params?: QueryParams): Observable<MutationEvent>
1082
-
1083
- /**
1084
- * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1085
- *
1086
- * @param query GROQ-filter to listen to changes for
1087
- * @param params Optional query parameters
1088
- * @param options Listener options
1089
- */
1090
- listen(query: string, params?: QueryParams, options?: ListenOptions): Observable<ListenEvent<any>>
1091
-
1092
764
  /**
1093
765
  * Perform a GROQ-query against the configured dataset.
1094
766
  *
1095
767
  * @param query GROQ-query to perform
1096
768
  */
1097
769
  fetch<R = any>(query: string): Observable<R>
1098
-
1099
770
  /**
1100
771
  * Perform a GROQ-query against the configured dataset.
1101
772
  *
@@ -1103,7 +774,6 @@ export class ObservableSanityClient {
1103
774
  * @param params Query parameters
1104
775
  */
1105
776
  fetch<R = any>(query: string, params: QueryParams): Observable<R>
1106
-
1107
777
  /**
1108
778
  * Perform a GROQ-query against the configured dataset.
1109
779
  *
@@ -1116,7 +786,6 @@ export class ObservableSanityClient {
1116
786
  params: QueryParams | undefined,
1117
787
  options: FilteredResponseQueryOptions
1118
788
  ): Observable<R>
1119
-
1120
789
  /**
1121
790
  * Perform a GROQ-query against the configured dataset.
1122
791
  *
@@ -1129,7 +798,6 @@ export class ObservableSanityClient {
1129
798
  params: QueryParams | undefined,
1130
799
  options: UnfilteredResponseQueryOptions
1131
800
  ): Observable<RawQueryResponse<R>>
1132
-
1133
801
  /**
1134
802
  * Fetch a single document with the given ID.
1135
803
  *
@@ -1138,9 +806,10 @@ export class ObservableSanityClient {
1138
806
  */
1139
807
  getDocument<R extends Record<string, any> = Record<string, any>>(
1140
808
  id: string,
1141
- options?: {tag?: string}
809
+ options?: {
810
+ tag?: string
811
+ }
1142
812
  ): Observable<SanityDocument<R> | undefined>
1143
-
1144
813
  /**
1145
814
  * Fetch multiple documents in one request.
1146
815
  * Should be used sparingly - performing a query is usually a better option.
@@ -1152,9 +821,10 @@ export class ObservableSanityClient {
1152
821
  */
1153
822
  getDocuments<R extends Record<string, any> = Record<string, any>>(
1154
823
  ids: string[],
1155
- options?: {tag?: string}
824
+ options?: {
825
+ tag?: string
826
+ }
1156
827
  ): Observable<(SanityDocument<R> | null)[]>
1157
-
1158
828
  /**
1159
829
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1160
830
  * Returns an observable that resolves to the created document.
@@ -1166,7 +836,6 @@ export class ObservableSanityClient {
1166
836
  document: SanityDocumentStub<R>,
1167
837
  options: FirstDocumentMutationOptions
1168
838
  ): Observable<SanityDocument<R>>
1169
-
1170
839
  /**
1171
840
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1172
841
  * Returns an observable that resolves to an array containing the created document.
@@ -1178,7 +847,6 @@ export class ObservableSanityClient {
1178
847
  document: SanityDocumentStub<R>,
1179
848
  options: AllDocumentsMutationOptions
1180
849
  ): Observable<SanityDocument<R>[]>
1181
-
1182
850
  /**
1183
851
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1184
852
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
@@ -1190,7 +858,6 @@ export class ObservableSanityClient {
1190
858
  document: SanityDocumentStub<R>,
1191
859
  options: FirstDocumentIdMutationOptions
1192
860
  ): Observable<SingleMutationResult>
1193
-
1194
861
  /**
1195
862
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1196
863
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
@@ -1202,7 +869,6 @@ export class ObservableSanityClient {
1202
869
  document: SanityDocumentStub<R>,
1203
870
  options: AllDocumentIdsMutationOptions
1204
871
  ): Observable<MultipleMutationResult>
1205
-
1206
872
  /**
1207
873
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1208
874
  * Returns an observable that resolves to the created document.
@@ -1214,7 +880,6 @@ export class ObservableSanityClient {
1214
880
  document: SanityDocumentStub<R>,
1215
881
  options?: BaseMutationOptions
1216
882
  ): Observable<SanityDocument<R>>
1217
-
1218
883
  /**
1219
884
  * Create a document if no document with the same ID already exists.
1220
885
  * Returns an observable that resolves to the created document.
@@ -1226,7 +891,6 @@ export class ObservableSanityClient {
1226
891
  document: IdentifiedSanityDocumentStub<R>,
1227
892
  options: FirstDocumentMutationOptions
1228
893
  ): Observable<SanityDocument<R>>
1229
-
1230
894
  /**
1231
895
  * Create a document if no document with the same ID already exists.
1232
896
  * Returns an observable that resolves to an array containing the created document.
@@ -1238,7 +902,6 @@ export class ObservableSanityClient {
1238
902
  document: IdentifiedSanityDocumentStub<R>,
1239
903
  options: AllDocumentsMutationOptions
1240
904
  ): Observable<SanityDocument<R>[]>
1241
-
1242
905
  /**
1243
906
  * Create a document if no document with the same ID already exists.
1244
907
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
@@ -1250,7 +913,6 @@ export class ObservableSanityClient {
1250
913
  document: IdentifiedSanityDocumentStub<R>,
1251
914
  options: FirstDocumentIdMutationOptions
1252
915
  ): Observable<SingleMutationResult>
1253
-
1254
916
  /**
1255
917
  * Create a document if no document with the same ID already exists.
1256
918
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
@@ -1262,7 +924,6 @@ export class ObservableSanityClient {
1262
924
  document: IdentifiedSanityDocumentStub<R>,
1263
925
  options: AllDocumentIdsMutationOptions
1264
926
  ): Observable<MultipleMutationResult>
1265
-
1266
927
  /**
1267
928
  * Create a document if no document with the same ID already exists.
1268
929
  * Returns an observable that resolves to the created document.
@@ -1274,7 +935,6 @@ export class ObservableSanityClient {
1274
935
  document: IdentifiedSanityDocumentStub<R>,
1275
936
  options?: BaseMutationOptions
1276
937
  ): Observable<SanityDocument<R>>
1277
-
1278
938
  /**
1279
939
  * Create a document if it does not exist, or replace a document with the same document ID
1280
940
  * Returns an observable that resolves to the created document.
@@ -1286,7 +946,6 @@ export class ObservableSanityClient {
1286
946
  document: IdentifiedSanityDocumentStub<R>,
1287
947
  options: FirstDocumentMutationOptions
1288
948
  ): Observable<SanityDocument<R>>
1289
-
1290
949
  /**
1291
950
  * Create a document if it does not exist, or replace a document with the same document ID
1292
951
  * Returns an observable that resolves to an array containing the created document.
@@ -1298,7 +957,6 @@ export class ObservableSanityClient {
1298
957
  document: IdentifiedSanityDocumentStub<R>,
1299
958
  options: AllDocumentsMutationOptions
1300
959
  ): Observable<SanityDocument<R>[]>
1301
-
1302
960
  /**
1303
961
  * Create a document if it does not exist, or replace a document with the same document ID
1304
962
  * Returns an observable that resolves to a mutation result object containing the ID of the created document.
@@ -1310,7 +968,6 @@ export class ObservableSanityClient {
1310
968
  document: IdentifiedSanityDocumentStub<R>,
1311
969
  options: FirstDocumentIdMutationOptions
1312
970
  ): Observable<SingleMutationResult>
1313
-
1314
971
  /**
1315
972
  * Create a document if it does not exist, or replace a document with the same document ID
1316
973
  * Returns an observable that resolves to a mutation result object containing the created document ID.
@@ -1322,7 +979,6 @@ export class ObservableSanityClient {
1322
979
  document: IdentifiedSanityDocumentStub<R>,
1323
980
  options: AllDocumentIdsMutationOptions
1324
981
  ): Observable<MultipleMutationResult>
1325
-
1326
982
  /**
1327
983
  * Create a document if it does not exist, or replace a document with the same document ID
1328
984
  * Returns an observable that resolves to the created document.
@@ -1334,7 +990,6 @@ export class ObservableSanityClient {
1334
990
  document: IdentifiedSanityDocumentStub<R>,
1335
991
  options?: BaseMutationOptions
1336
992
  ): Observable<SanityDocument<R>>
1337
-
1338
993
  /**
1339
994
  * Deletes a document with the given document ID.
1340
995
  * Returns an observable that resolves to the deleted document.
@@ -1346,7 +1001,6 @@ export class ObservableSanityClient {
1346
1001
  id: string,
1347
1002
  options: FirstDocumentMutationOptions
1348
1003
  ): Observable<SanityDocument<R>>
1349
-
1350
1004
  /**
1351
1005
  * Deletes a document with the given document ID.
1352
1006
  * Returns an observable that resolves to an array containing the deleted document.
@@ -1358,7 +1012,6 @@ export class ObservableSanityClient {
1358
1012
  id: string,
1359
1013
  options: AllDocumentsMutationOptions
1360
1014
  ): Observable<SanityDocument<R>[]>
1361
-
1362
1015
  /**
1363
1016
  * Deletes a document with the given document ID.
1364
1017
  * Returns an observable that resolves to a mutation result object containing the deleted document ID.
@@ -1367,7 +1020,6 @@ export class ObservableSanityClient {
1367
1020
  * @param options Options for the mutation
1368
1021
  */
1369
1022
  delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
1370
-
1371
1023
  /**
1372
1024
  * Deletes a document with the given document ID.
1373
1025
  * Returns an observable that resolves to a mutation result object containing the deleted document ID.
@@ -1376,7 +1028,6 @@ export class ObservableSanityClient {
1376
1028
  * @param options Options for the mutation
1377
1029
  */
1378
1030
  delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
1379
-
1380
1031
  /**
1381
1032
  * Deletes a document with the given document ID.
1382
1033
  * Returns an observable that resolves to the deleted document.
@@ -1388,7 +1039,6 @@ export class ObservableSanityClient {
1388
1039
  id: string,
1389
1040
  options?: BaseMutationOptions
1390
1041
  ): Observable<SanityDocument<R>>
1391
-
1392
1042
  /**
1393
1043
  * Deletes one or more documents matching the given query or document ID.
1394
1044
  * Returns an observable that resolves to first deleted document.
@@ -1400,7 +1050,6 @@ export class ObservableSanityClient {
1400
1050
  selection: MutationSelection,
1401
1051
  options: FirstDocumentMutationOptions
1402
1052
  ): Observable<SanityDocument<R>>
1403
-
1404
1053
  /**
1405
1054
  * Deletes one or more documents matching the given query or document ID.
1406
1055
  * Returns an observable that resolves to an array containing the deleted documents.
@@ -1412,7 +1061,6 @@ export class ObservableSanityClient {
1412
1061
  selection: MutationSelection,
1413
1062
  options: AllDocumentsMutationOptions
1414
1063
  ): Observable<SanityDocument<R>[]>
1415
-
1416
1064
  /**
1417
1065
  * Deletes one or more documents matching the given query or document ID.
1418
1066
  * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
@@ -1424,7 +1072,6 @@ export class ObservableSanityClient {
1424
1072
  selection: MutationSelection,
1425
1073
  options: FirstDocumentIdMutationOptions
1426
1074
  ): Observable<SingleMutationResult>
1427
-
1428
1075
  /**
1429
1076
  * Deletes one or more documents matching the given query or document ID.
1430
1077
  * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
@@ -1436,7 +1083,6 @@ export class ObservableSanityClient {
1436
1083
  selection: MutationSelection,
1437
1084
  options: AllDocumentIdsMutationOptions
1438
1085
  ): Observable<MultipleMutationResult>
1439
-
1440
1086
  /**
1441
1087
  * Deletes one or more documents matching the given query or document ID.
1442
1088
  * Returns an observable that resolves to first deleted document.
@@ -1448,7 +1094,6 @@ export class ObservableSanityClient {
1448
1094
  selection: MutationSelection,
1449
1095
  options?: BaseMutationOptions
1450
1096
  ): Observable<SanityDocument<R>>
1451
-
1452
1097
  /**
1453
1098
  * Perform mutation operations against the configured dataset
1454
1099
  * Returns an observable that resolves to the first mutated document.
@@ -1457,10 +1102,9 @@ export class ObservableSanityClient {
1457
1102
  * @param options Mutation options
1458
1103
  */
1459
1104
  mutate<R extends Record<string, any> = Record<string, any>>(
1460
- operations: Mutation<R>[] | Patch | Transaction,
1105
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1461
1106
  options: FirstDocumentMutationOptions
1462
1107
  ): Observable<SanityDocument<R>>
1463
-
1464
1108
  /**
1465
1109
  * Perform mutation operations against the configured dataset.
1466
1110
  * Returns an observable that resolves to an array of the mutated documents.
@@ -1469,10 +1113,9 @@ export class ObservableSanityClient {
1469
1113
  * @param options Mutation options
1470
1114
  */
1471
1115
  mutate<R extends Record<string, any> = Record<string, any>>(
1472
- operations: Mutation<R>[] | Patch | Transaction,
1116
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1473
1117
  options: AllDocumentsMutationOptions
1474
1118
  ): Observable<SanityDocument<R>[]>
1475
-
1476
1119
  /**
1477
1120
  * Perform mutation operations against the configured dataset
1478
1121
  * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
@@ -1481,10 +1124,9 @@ export class ObservableSanityClient {
1481
1124
  * @param options Mutation options
1482
1125
  */
1483
1126
  mutate<R extends Record<string, any> = Record<string, any>>(
1484
- operations: Mutation<R>[] | Patch | Transaction,
1127
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1485
1128
  options: FirstDocumentIdMutationOptions
1486
1129
  ): Observable<SingleMutationResult>
1487
-
1488
1130
  /**
1489
1131
  * Perform mutation operations against the configured dataset
1490
1132
  * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
@@ -1493,10 +1135,9 @@ export class ObservableSanityClient {
1493
1135
  * @param options Mutation options
1494
1136
  */
1495
1137
  mutate<R extends Record<string, any> = Record<string, any>>(
1496
- operations: Mutation<R>[] | Patch | Transaction,
1138
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1497
1139
  options: AllDocumentIdsMutationOptions
1498
1140
  ): Observable<MultipleMutationResult>
1499
-
1500
1141
  /**
1501
1142
  * Perform mutation operations against the configured dataset
1502
1143
  * Returns an observable that resolves to the first mutated document.
@@ -1505,10 +1146,9 @@ export class ObservableSanityClient {
1505
1146
  * @param options Mutation options
1506
1147
  */
1507
1148
  mutate<R extends Record<string, any> = Record<string, any>>(
1508
- operations: Mutation<R>[] | Patch | Transaction,
1149
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
1509
1150
  options?: BaseMutationOptions
1510
1151
  ): Observable<SanityDocument<R>>
1511
-
1512
1152
  /**
1513
1153
  * Create a new buildable patch of operations to perform
1514
1154
  *
@@ -1516,7 +1156,6 @@ export class ObservableSanityClient {
1516
1156
  * @param operations Optional object of patch operations to initialize the patch instance with
1517
1157
  */
1518
1158
  patch(documentId: string | MutationSelection, operations?: PatchOperations): ObservablePatch
1519
-
1520
1159
  /**
1521
1160
  * Create a new transaction of mutations
1522
1161
  *
@@ -1525,247 +1164,281 @@ export class ObservableSanityClient {
1525
1164
  transaction<R extends Record<string, any> = Record<string, any>>(
1526
1165
  operations?: Mutation<R>[]
1527
1166
  ): ObservableTransaction
1528
-
1529
- // "Internals", should generally not be used externally
1530
1167
  /**
1531
- * DEPRECATED: Returns whether or not this client is using the Observable API (otherwise it is using observables)
1168
+ * DEPRECATED: Perform an HTTP request against the Sanity API
1532
1169
  *
1533
- * @deprecated Should be an internal concern
1170
+ * @deprecated Use your own request library!
1171
+ * @param options Request options
1534
1172
  */
1535
- isObservableAPI(): boolean
1173
+ request<R = any>(options: RawRequestOptions): Observable<R>
1174
+ }
1536
1175
 
1176
+ export declare class ObservableTransaction extends BaseTransaction {
1177
+ #private
1178
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
1537
1179
  /**
1538
- * DEPRECATED: Get a Sanity API URL for the URI provided
1180
+ * Clones the transaction
1181
+ */
1182
+ clone(): ObservableTransaction
1183
+ /**
1184
+ * Commit the transaction, returning an observable that produces the first mutated document
1539
1185
  *
1540
- * @deprecated Should be an internal concern
1541
- * @param uri URI/path to build URL for
1542
- * @param canUseCdn Whether or not to allow using the API CDN for this route
1186
+ * @param options - Options for the mutation operation
1543
1187
  */
1544
- getUrl(uri: string, canUseCdn?: boolean): string
1545
-
1188
+ commit<R extends Record<string, any>>(
1189
+ options: TransactionFirstDocumentMutationOptions
1190
+ ): Observable<SanityDocument<R>>
1546
1191
  /**
1547
- * DEPRECATED: Get a Sanity API URL for the data operation and path provided
1192
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
1548
1193
  *
1549
- * @deprecated Should be an internal concern
1550
- * @param operation Data operation
1551
- * @param path Path to append
1194
+ * @param options - Options for the mutation operation
1552
1195
  */
1553
- getDataUrl(operation: string, path?: string): string
1554
-
1196
+ commit<R extends Record<string, any>>(
1197
+ options: TransactionAllDocumentsMutationOptions
1198
+ ): Observable<SanityDocument<R>[]>
1555
1199
  /**
1556
- * DEPRECATED: Perform an HTTP request against the Sanity API
1200
+ * Commit the transaction, returning an observable that produces a mutation result object
1557
1201
  *
1558
- * @deprecated Use your own request library!
1559
- * @param options Request options
1202
+ * @param options - Options for the mutation operation
1560
1203
  */
1561
- request<T = any>(options: RawRequestOptions): Observable<T>
1204
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
1205
+ /**
1206
+ * Commit the transaction, returning an observable that produces a mutation result object
1207
+ *
1208
+ * @param options - Options for the mutation operation
1209
+ */
1210
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
1211
+ /**
1212
+ * Commit the transaction, returning an observable that produces a mutation result object
1213
+ *
1214
+ * @param options - Options for the mutation operation
1215
+ */
1216
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
1217
+ /**
1218
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
1219
+ * The operation is added to the current transaction, ready to be commited by `commit()`
1220
+ *
1221
+ * @param documentId - Document ID to perform the patch operation on
1222
+ * @param patchOps - Operations to perform, or a builder function
1223
+ */
1224
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
1225
+ /**
1226
+ * Adds the given patch instance to the transaction.
1227
+ * The operation is added to the current transaction, ready to be commited by `commit()`
1228
+ *
1229
+ * @param patch - ObservablePatch to execute
1230
+ */
1231
+ patch(patch: ObservablePatch): this
1562
1232
  }
1563
1233
 
1564
- export interface SanityClient {
1565
- // Client/configuration
1566
- constructor(config: ClientConfig): SanityClient
1234
+ export declare class ObservableUsersClient extends BaseUsersClient {
1235
+ client: ObservableSanityClient
1236
+ constructor(client: ObservableSanityClient)
1237
+ }
1567
1238
 
1239
+ export declare class Patch extends BasePatch {
1240
+ #private
1241
+ constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
1568
1242
  /**
1569
- * Clone the client - returns a new instance
1243
+ * Clones the patch
1570
1244
  */
1571
- clone(): SanityClient
1572
-
1245
+ clone(): Patch
1573
1246
  /**
1574
- * Returns the current client configuration
1247
+ * Commit the patch, returning a promise that resolves to the first patched document
1248
+ *
1249
+ * @param options Options for the mutation operation
1575
1250
  */
1576
- config(): ClientConfig
1577
-
1251
+ commit<R extends Record<string, any> = Record<string, any>>(
1252
+ options: FirstDocumentMutationOptions
1253
+ ): Promise<SanityDocument<R>>
1578
1254
  /**
1579
- * Reconfigure the client. Note that this _mutates_ the current client.
1255
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
1580
1256
  *
1581
- * @param newConfig New client configuration properties
1257
+ * @param options Options for the mutation operation
1582
1258
  */
1583
- config(newConfig?: Partial<ClientConfig>): this
1584
-
1259
+ commit<R extends Record<string, any> = Record<string, any>>(
1260
+ options: AllDocumentsMutationOptions
1261
+ ): Promise<SanityDocument<R>[]>
1585
1262
  /**
1586
- * Clone the client with a new (partial) configuration.
1263
+ * Commit the patch, returning a promise that resolves to a mutation result object
1587
1264
  *
1588
- * @param newConfig New client configuration properties, shallowly merged with existing configuration
1265
+ * @param options Options for the mutation operation
1589
1266
  */
1590
- withConfig(newConfig?: Partial<ClientConfig>): SanityClient
1591
-
1267
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
1592
1268
  /**
1593
- * @deprecated Use `client.config()` instead
1269
+ * Commit the patch, returning a promise that resolves to a mutation result object
1270
+ *
1271
+ * @param options Options for the mutation operation
1594
1272
  */
1595
- clientConfig: ClientConfig
1596
-
1273
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
1597
1274
  /**
1598
- * Observable version of the Sanity client, with the same configuration as the promise-based one
1275
+ * Commit the patch, returning a promise that resolves to the first patched document
1276
+ *
1277
+ * @param options Options for the mutation operation
1599
1278
  */
1600
- observable: ObservableSanityClient
1279
+ commit<R extends Record<string, any> = Record<string, any>>(
1280
+ options?: BaseMutationOptions
1281
+ ): Promise<SanityDocument<R>>
1282
+ }
1601
1283
 
1602
- assets: {
1603
- /**
1604
- * Uploads a file asset to the configured dataset
1605
- *
1606
- * @param assetType Asset type (file/image)
1607
- * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1608
- * @param options Options to use for the upload
1609
- */
1610
- upload(
1611
- assetType: 'file' | 'image',
1612
- body: File | Blob | Buffer | NodeJS.ReadableStream,
1613
- options?: UploadOptions
1614
- ): Promise<SanityAssetDocument | SanityImageAssetDocument>
1284
+ export declare type PatchBuilder = (patch: Patch) => Patch
1615
1285
 
1616
- /**
1617
- * Uploads a file asset to the configured dataset
1618
- *
1619
- * @param assetType Asset type (file/image)
1620
- * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1621
- * @param options Options to use for the upload
1622
- */
1623
- upload(
1624
- assetType: 'file',
1625
- body: File | Blob | Buffer | NodeJS.ReadableStream,
1626
- options?: UploadOptions
1627
- ): Promise<SanityAssetDocument>
1286
+ export declare type PatchMutationOperation = PatchOperations & MutationSelection
1628
1287
 
1629
- /**
1630
- * Uploads an image asset to the configured dataset
1631
- *
1632
- * @param assetType Asset type (file/image)
1633
- * @param body Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1634
- * @param options Options to use for the upload
1635
- */
1636
- upload(
1637
- assetType: 'image',
1638
- body: File | Blob | Buffer | NodeJS.ReadableStream,
1639
- options?: UploadOptions
1640
- ): Promise<SanityImageAssetDocument>
1288
+ export declare interface PatchOperations {
1289
+ set?: {
1290
+ [key: string]: any
1291
+ }
1292
+ setIfMissing?: {
1293
+ [key: string]: any
1294
+ }
1295
+ diffMatchPatch?: {
1296
+ [key: string]: any
1297
+ }
1298
+ unset?: string[]
1299
+ inc?: {
1300
+ [key: string]: number
1301
+ }
1302
+ dec?: {
1303
+ [key: string]: number
1304
+ }
1305
+ insert?: InsertPatch
1306
+ ifRevisionID?: string
1307
+ }
1641
1308
 
1642
- /**
1643
- * DEPRECATED: Deletes an asset of the given type and ID
1644
- *
1645
- * @deprecated Use `client.delete(assetDocumentId)` instead
1646
- * @param assetType Asset type (file/image)
1647
- * @param id Document ID or asset document to delete
1648
- */
1649
- delete(
1650
- assetType: 'file' | 'image',
1651
- id: string | IdentifiedSanityDocumentStub
1652
- ): Promise<SanityAssetDocument | undefined>
1309
+ export declare type PatchSelection = string | string[] | MutationSelection
1653
1310
 
1654
- /**
1655
- * DEPRECATED: Returns the URL for an asset with a given document ID
1656
- *
1657
- * @deprecated Use the `@sanity/image-url` module instead
1658
- * @param id Document ID or asset reference to get URL for
1659
- * @param query Optional object of query string parameters to append
1660
- */
1661
- getImageUrl(id: string | SanityReference, query: {[key: string]: string | number}): string
1662
- }
1311
+ declare interface ProgressEvent_2 {
1312
+ type: 'progress'
1313
+ stage: 'upload' | 'download'
1314
+ percent: number
1315
+ total?: number
1316
+ loaded?: number
1317
+ lengthComputable: boolean
1318
+ }
1319
+ export {ProgressEvent_2 as ProgressEvent}
1663
1320
 
1664
- datasets: {
1665
- /**
1666
- * Create a new dataset with the given name
1667
- *
1668
- * @param name Name of the dataset to create
1669
- * @param options Options for the dataset
1670
- */
1671
- create(
1672
- name: string,
1673
- options?: {aclMode?: DatasetAclMode}
1674
- ): Promise<{datasetName: string; aclMode: DatasetAclMode}>
1321
+ export declare class ProjectsClient extends BaseProjectsClient {
1322
+ client: SanityClient
1323
+ constructor(client: SanityClient)
1324
+ }
1675
1325
 
1676
- /**
1677
- * Edit a dataset with the given name
1678
- *
1679
- * @param name Name of the dataset to edit
1680
- * @param options New options for the dataset
1681
- */
1682
- edit(
1683
- name: string,
1684
- options: {aclMode?: DatasetAclMode}
1685
- ): Promise<{datasetName: string; aclMode: DatasetAclMode}>
1326
+ export declare type QueryParams = {
1327
+ [key: string]: any
1328
+ }
1686
1329
 
1687
- /**
1688
- * Delete a dataset with the given name
1689
- *
1690
- * @param name Name of the dataset to delete
1691
- */
1692
- delete(name: string): Promise<{deleted: true}>
1330
+ export declare interface RawQueryResponse<R> {
1331
+ q: string
1332
+ ms: number
1333
+ result: R
1334
+ }
1693
1335
 
1694
- /**
1695
- * Fetch a list of datasets for the configured project
1696
- */
1697
- list(): Promise<{name: string; aclMode: DatasetAclMode}[]>
1336
+ export declare interface RawRequestOptions {
1337
+ url?: string
1338
+ uri?: string
1339
+ method?: string
1340
+ token?: string
1341
+ json?: boolean
1342
+ tag?: string
1343
+ useGlobalApi?: boolean
1344
+ withCredentials?: boolean
1345
+ query?: {
1346
+ [key: string]: string | string[]
1347
+ }
1348
+ headers?: {
1349
+ [key: string]: string
1698
1350
  }
1351
+ timeout?: number
1352
+ proxy?: string
1353
+ body?: any
1354
+ maxRedirects?: number
1355
+ }
1699
1356
 
1700
- projects: {
1701
- /**
1702
- * Fetch a list of projects the authenticated user has access to
1703
- */
1704
- list(): Promise<SanityProject[]>
1357
+ export declare type ReconnectEvent = {
1358
+ type: 'reconnect'
1359
+ }
1705
1360
 
1706
- /**
1707
- * Fetch a project by project ID
1708
- *
1709
- * @param projectId ID of the project to fetch
1710
- */
1711
- getById(projectId: string): Promise<SanityProject>
1712
- }
1361
+ export declare const requester: Requester
1713
1362
 
1714
- users: {
1715
- /**
1716
- * Fetch a user by user ID
1717
- *
1718
- * @param id User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
1719
- */
1720
- getById<T extends 'me' | string>(
1721
- id: T
1722
- ): T extends 'me' ? Promise<CurrentSanityUser> : Promise<SanityUser>
1723
- }
1363
+ export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
1364
+ url?: string
1365
+ uri?: string
1366
+ canUseCdn?: boolean
1367
+ tag?: string
1368
+ }
1724
1369
 
1725
- auth: {
1726
- /**
1727
- * Fetch available login providers
1728
- */
1729
- getLoginProviders(): Promise<{providers: AuthProvider[]}>
1370
+ export declare interface RequestOptions {
1371
+ timeout?: number
1372
+ token?: string
1373
+ tag?: string
1374
+ headers?: Record<string, string>
1375
+ method?: string
1376
+ query?: any
1377
+ body?: any
1378
+ }
1730
1379
 
1731
- /**
1732
- * Revoke the configured session/token
1733
- */
1734
- logout(): Promise<any>
1735
- }
1380
+ export declare interface ResponseEvent<T = unknown> {
1381
+ type: 'response'
1382
+ body: T
1383
+ url: string
1384
+ method: string
1385
+ statusCode: number
1386
+ statusMessage?: string
1387
+ headers: Record<string, string>
1388
+ }
1389
+
1390
+ export declare interface SanityAssetDocument extends SanityDocument {
1391
+ url: string
1392
+ path: string
1393
+ size: number
1394
+ assetId: string
1395
+ mimeType: string
1396
+ sha1hash: string
1397
+ extension: string
1398
+ uploadId?: string
1399
+ originalFilename?: string
1400
+ }
1736
1401
 
1402
+ export declare class SanityClient extends BaseSanityClient {
1403
+ #private
1404
+ assets: AssetsClient
1405
+ auth: AuthClient
1406
+ datasets: DatasetsClient
1407
+ projects: ProjectsClient
1408
+ users: UsersClient
1737
1409
  /**
1738
- * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1739
- *
1740
- * @param query GROQ-filter to listen to changes for
1741
- * @param params Optional query parameters
1742
- * @param options Listener options
1410
+ * Observable version of the Sanity client, with the same configuration as the promise-based one
1743
1411
  */
1744
- listen<R extends Record<string, any> = Record<string, any>>(
1745
- query: string,
1746
- params?: QueryParams
1747
- ): Observable<MutationEvent<R>>
1748
-
1412
+ observable: ObservableSanityClient
1413
+ /**
1414
+ * Instance properties
1415
+ */
1416
+ listen: typeof _listen
1417
+ constructor(httpRequest: HttpRequest, config: ClientConfig)
1418
+ /**
1419
+ * Clone the client - returns a new instance
1420
+ */
1421
+ clone(): SanityClient
1749
1422
  /**
1750
- * Set up a listener that will be notified when mutations occur on documents matching the provided query/filter.
1423
+ * Returns the current client configuration
1424
+ */
1425
+ config(): InitializedClientConfig
1426
+ /**
1427
+ * Reconfigure the client. Note that this _mutates_ the current client.
1428
+ */
1429
+ config(newConfig?: Partial<ClientConfig>): this
1430
+ /**
1431
+ * Clone the client with a new (partial) configuration.
1751
1432
  *
1752
- * @param query GROQ-filter to listen to changes for
1753
- * @param params Optional query parameters
1754
- * @param options Listener options
1433
+ * @param newConfig New client configuration properties, shallowly merged with existing configuration
1755
1434
  */
1756
- listen<R extends Record<string, any> = Record<string, any>>(
1757
- query: string,
1758
- params?: QueryParams,
1759
- options?: ListenOptions
1760
- ): Observable<ListenEvent<R>>
1761
-
1435
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
1762
1436
  /**
1763
1437
  * Perform a GROQ-query against the configured dataset.
1764
1438
  *
1765
1439
  * @param query GROQ-query to perform
1766
1440
  */
1767
1441
  fetch<R = any>(query: string): Promise<R>
1768
-
1769
1442
  /**
1770
1443
  * Perform a GROQ-query against the configured dataset.
1771
1444
  *
@@ -1773,7 +1446,6 @@ export interface SanityClient {
1773
1446
  * @param params Optional query parameters
1774
1447
  */
1775
1448
  fetch<R = any>(query: string, params: QueryParams): Promise<R>
1776
-
1777
1449
  /**
1778
1450
  * Perform a GROQ-query against the configured dataset.
1779
1451
  *
@@ -1786,7 +1458,6 @@ export interface SanityClient {
1786
1458
  params: QueryParams | undefined,
1787
1459
  options: FilteredResponseQueryOptions
1788
1460
  ): Promise<R>
1789
-
1790
1461
  /**
1791
1462
  * Perform a GROQ-query against the configured dataset.
1792
1463
  *
@@ -1799,7 +1470,6 @@ export interface SanityClient {
1799
1470
  params: QueryParams | undefined,
1800
1471
  options: UnfilteredResponseQueryOptions
1801
1472
  ): Promise<RawQueryResponse<R>>
1802
-
1803
1473
  /**
1804
1474
  * Fetch a single document with the given ID.
1805
1475
  *
@@ -1808,9 +1478,10 @@ export interface SanityClient {
1808
1478
  */
1809
1479
  getDocument<R extends Record<string, any> = Record<string, any>>(
1810
1480
  id: string,
1811
- options?: {tag?: string}
1481
+ options?: {
1482
+ tag?: string
1483
+ }
1812
1484
  ): Promise<SanityDocument<R> | undefined>
1813
-
1814
1485
  /**
1815
1486
  * Fetch multiple documents in one request.
1816
1487
  * Should be used sparingly - performing a query is usually a better option.
@@ -1822,9 +1493,10 @@ export interface SanityClient {
1822
1493
  */
1823
1494
  getDocuments<R extends Record<string, any> = Record<string, any>>(
1824
1495
  ids: string[],
1825
- options?: {tag?: string}
1496
+ options?: {
1497
+ tag?: string
1498
+ }
1826
1499
  ): Promise<(SanityDocument<R> | null)[]>
1827
-
1828
1500
  /**
1829
1501
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1830
1502
  * Returns a promise that resolves to the created document.
@@ -1836,7 +1508,6 @@ export interface SanityClient {
1836
1508
  document: SanityDocumentStub<R>,
1837
1509
  options: FirstDocumentMutationOptions
1838
1510
  ): Promise<SanityDocument<R>>
1839
-
1840
1511
  /**
1841
1512
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1842
1513
  * Returns a promise that resolves to an array containing the created document.
@@ -1848,7 +1519,6 @@ export interface SanityClient {
1848
1519
  document: SanityDocumentStub<R>,
1849
1520
  options: AllDocumentsMutationOptions
1850
1521
  ): Promise<SanityDocument<R>[]>
1851
-
1852
1522
  /**
1853
1523
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1854
1524
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
@@ -1860,7 +1530,6 @@ export interface SanityClient {
1860
1530
  document: SanityDocumentStub<R>,
1861
1531
  options: FirstDocumentIdMutationOptions
1862
1532
  ): Promise<SingleMutationResult>
1863
-
1864
1533
  /**
1865
1534
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1866
1535
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
@@ -1872,7 +1541,6 @@ export interface SanityClient {
1872
1541
  document: SanityDocumentStub<R>,
1873
1542
  options: AllDocumentIdsMutationOptions
1874
1543
  ): Promise<MultipleMutationResult>
1875
-
1876
1544
  /**
1877
1545
  * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
1878
1546
  * Returns a promise that resolves to the created document.
@@ -1884,7 +1552,6 @@ export interface SanityClient {
1884
1552
  document: SanityDocumentStub<R>,
1885
1553
  options?: BaseMutationOptions
1886
1554
  ): Promise<SanityDocument<R>>
1887
-
1888
1555
  /**
1889
1556
  * Create a document if no document with the same ID already exists.
1890
1557
  * Returns a promise that resolves to the created document.
@@ -1896,7 +1563,6 @@ export interface SanityClient {
1896
1563
  document: IdentifiedSanityDocumentStub<R>,
1897
1564
  options: FirstDocumentMutationOptions
1898
1565
  ): Promise<SanityDocument<R>>
1899
-
1900
1566
  /**
1901
1567
  * Create a document if no document with the same ID already exists.
1902
1568
  * Returns a promise that resolves to an array containing the created document.
@@ -1908,7 +1574,6 @@ export interface SanityClient {
1908
1574
  document: IdentifiedSanityDocumentStub<R>,
1909
1575
  options: AllDocumentsMutationOptions
1910
1576
  ): Promise<SanityDocument<R>[]>
1911
-
1912
1577
  /**
1913
1578
  * Create a document if no document with the same ID already exists.
1914
1579
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
@@ -1920,7 +1585,6 @@ export interface SanityClient {
1920
1585
  document: IdentifiedSanityDocumentStub<R>,
1921
1586
  options: FirstDocumentIdMutationOptions
1922
1587
  ): Promise<SingleMutationResult>
1923
-
1924
1588
  /**
1925
1589
  * Create a document if no document with the same ID already exists.
1926
1590
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
@@ -1932,7 +1596,6 @@ export interface SanityClient {
1932
1596
  document: IdentifiedSanityDocumentStub<R>,
1933
1597
  options: AllDocumentIdsMutationOptions
1934
1598
  ): Promise<MultipleMutationResult>
1935
-
1936
1599
  /**
1937
1600
  * Create a document if no document with the same ID already exists.
1938
1601
  * Returns a promise that resolves to the created document.
@@ -1944,7 +1607,6 @@ export interface SanityClient {
1944
1607
  document: IdentifiedSanityDocumentStub<R>,
1945
1608
  options?: BaseMutationOptions
1946
1609
  ): Promise<SanityDocument<R>>
1947
-
1948
1610
  /**
1949
1611
  * Create a document if it does not exist, or replace a document with the same document ID
1950
1612
  * Returns a promise that resolves to the created document.
@@ -1956,7 +1618,6 @@ export interface SanityClient {
1956
1618
  document: IdentifiedSanityDocumentStub<R>,
1957
1619
  options: FirstDocumentMutationOptions
1958
1620
  ): Promise<SanityDocument<R>>
1959
-
1960
1621
  /**
1961
1622
  * Create a document if it does not exist, or replace a document with the same document ID
1962
1623
  * Returns a promise that resolves to an array containing the created document.
@@ -1968,7 +1629,6 @@ export interface SanityClient {
1968
1629
  document: IdentifiedSanityDocumentStub<R>,
1969
1630
  options: AllDocumentsMutationOptions
1970
1631
  ): Promise<SanityDocument<R>[]>
1971
-
1972
1632
  /**
1973
1633
  * Create a document if it does not exist, or replace a document with the same document ID
1974
1634
  * Returns a promise that resolves to a mutation result object containing the ID of the created document.
@@ -1980,7 +1640,6 @@ export interface SanityClient {
1980
1640
  document: IdentifiedSanityDocumentStub<R>,
1981
1641
  options: FirstDocumentIdMutationOptions
1982
1642
  ): Promise<SingleMutationResult>
1983
-
1984
1643
  /**
1985
1644
  * Create a document if it does not exist, or replace a document with the same document ID
1986
1645
  * Returns a promise that resolves to a mutation result object containing the created document ID.
@@ -1992,7 +1651,6 @@ export interface SanityClient {
1992
1651
  document: IdentifiedSanityDocumentStub<R>,
1993
1652
  options: AllDocumentIdsMutationOptions
1994
1653
  ): Promise<MultipleMutationResult>
1995
-
1996
1654
  /**
1997
1655
  * Create a document if it does not exist, or replace a document with the same document ID
1998
1656
  * Returns a promise that resolves to the created document.
@@ -2004,7 +1662,6 @@ export interface SanityClient {
2004
1662
  document: IdentifiedSanityDocumentStub<R>,
2005
1663
  options?: BaseMutationOptions
2006
1664
  ): Promise<SanityDocument<R>>
2007
-
2008
1665
  /**
2009
1666
  * Deletes a document with the given document ID.
2010
1667
  * Returns a promise that resolves to the deleted document.
@@ -2016,7 +1673,6 @@ export interface SanityClient {
2016
1673
  id: string,
2017
1674
  options: FirstDocumentMutationOptions
2018
1675
  ): Promise<SanityDocument<R>>
2019
-
2020
1676
  /**
2021
1677
  * Deletes a document with the given document ID.
2022
1678
  * Returns a promise that resolves to an array containing the deleted document.
@@ -2028,7 +1684,6 @@ export interface SanityClient {
2028
1684
  id: string,
2029
1685
  options: AllDocumentsMutationOptions
2030
1686
  ): Promise<SanityDocument<R>[]>
2031
-
2032
1687
  /**
2033
1688
  * Deletes a document with the given document ID.
2034
1689
  * Returns a promise that resolves to a mutation result object containing the deleted document ID.
@@ -2037,7 +1692,6 @@ export interface SanityClient {
2037
1692
  * @param options Options for the mutation
2038
1693
  */
2039
1694
  delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2040
-
2041
1695
  /**
2042
1696
  * Deletes a document with the given document ID.
2043
1697
  * Returns a promise that resolves to a mutation result object containing the deleted document ID.
@@ -2046,7 +1700,6 @@ export interface SanityClient {
2046
1700
  * @param options Options for the mutation
2047
1701
  */
2048
1702
  delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2049
-
2050
1703
  /**
2051
1704
  * Deletes a document with the given document ID.
2052
1705
  * Returns a promise that resolves to the deleted document.
@@ -2058,7 +1711,6 @@ export interface SanityClient {
2058
1711
  id: string,
2059
1712
  options?: BaseMutationOptions
2060
1713
  ): Promise<SanityDocument<R>>
2061
-
2062
1714
  /**
2063
1715
  * Deletes one or more documents matching the given query or document ID.
2064
1716
  * Returns a promise that resolves to first deleted document.
@@ -2070,7 +1722,6 @@ export interface SanityClient {
2070
1722
  selection: MutationSelection,
2071
1723
  options: FirstDocumentMutationOptions
2072
1724
  ): Promise<SanityDocument<R>>
2073
-
2074
1725
  /**
2075
1726
  * Deletes one or more documents matching the given query or document ID.
2076
1727
  * Returns a promise that resolves to an array containing the deleted documents.
@@ -2082,7 +1733,6 @@ export interface SanityClient {
2082
1733
  selection: MutationSelection,
2083
1734
  options: AllDocumentsMutationOptions
2084
1735
  ): Promise<SanityDocument<R>[]>
2085
-
2086
1736
  /**
2087
1737
  * Deletes one or more documents matching the given query or document ID.
2088
1738
  * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
@@ -2094,7 +1744,6 @@ export interface SanityClient {
2094
1744
  selection: MutationSelection,
2095
1745
  options: FirstDocumentIdMutationOptions
2096
1746
  ): Promise<SingleMutationResult>
2097
-
2098
1747
  /**
2099
1748
  * Deletes one or more documents matching the given query or document ID.
2100
1749
  * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
@@ -2106,7 +1755,6 @@ export interface SanityClient {
2106
1755
  selection: MutationSelection,
2107
1756
  options: AllDocumentIdsMutationOptions
2108
1757
  ): Promise<MultipleMutationResult>
2109
-
2110
1758
  /**
2111
1759
  * Deletes one or more documents matching the given query or document ID.
2112
1760
  * Returns a promise that resolves to first deleted document.
@@ -2118,7 +1766,6 @@ export interface SanityClient {
2118
1766
  selection: MutationSelection,
2119
1767
  options?: BaseMutationOptions
2120
1768
  ): Promise<SanityDocument<R>>
2121
-
2122
1769
  /**
2123
1770
  * Perform mutation operations against the configured dataset
2124
1771
  * Returns a promise that resolves to the first mutated document.
@@ -2130,7 +1777,6 @@ export interface SanityClient {
2130
1777
  operations: Mutation<R>[] | Patch | Transaction,
2131
1778
  options: FirstDocumentMutationOptions
2132
1779
  ): Promise<SanityDocument<R>>
2133
-
2134
1780
  /**
2135
1781
  * Perform mutation operations against the configured dataset.
2136
1782
  * Returns a promise that resolves to an array of the mutated documents.
@@ -2142,7 +1788,6 @@ export interface SanityClient {
2142
1788
  operations: Mutation<R>[] | Patch | Transaction,
2143
1789
  options: AllDocumentsMutationOptions
2144
1790
  ): Promise<SanityDocument<R>[]>
2145
-
2146
1791
  /**
2147
1792
  * Perform mutation operations against the configured dataset
2148
1793
  * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
@@ -2154,7 +1799,6 @@ export interface SanityClient {
2154
1799
  operations: Mutation<R>[] | Patch | Transaction,
2155
1800
  options: FirstDocumentIdMutationOptions
2156
1801
  ): Promise<SingleMutationResult>
2157
-
2158
1802
  /**
2159
1803
  * Perform mutation operations against the configured dataset
2160
1804
  * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
@@ -2166,7 +1810,6 @@ export interface SanityClient {
2166
1810
  operations: Mutation<R>[] | Patch | Transaction,
2167
1811
  options: AllDocumentIdsMutationOptions
2168
1812
  ): Promise<MultipleMutationResult>
2169
-
2170
1813
  /**
2171
1814
  * Perform mutation operations against the configured dataset
2172
1815
  * Returns a promise that resolves to the first mutated document.
@@ -2178,7 +1821,6 @@ export interface SanityClient {
2178
1821
  operations: Mutation<R>[] | Patch | Transaction,
2179
1822
  options?: BaseMutationOptions
2180
1823
  ): Promise<SanityDocument<R>>
2181
-
2182
1824
  /**
2183
1825
  * Create a new buildable patch of operations to perform
2184
1826
  *
@@ -2186,7 +1828,6 @@ export interface SanityClient {
2186
1828
  * @param operations Optional object of patch operations to initialize the patch instance with
2187
1829
  */
2188
1830
  patch(documentId: string | MutationSelection, operations?: PatchOperations): Patch
2189
-
2190
1831
  /**
2191
1832
  * Create a new transaction of mutations
2192
1833
  *
@@ -2195,62 +1836,295 @@ export interface SanityClient {
2195
1836
  transaction<R extends Record<string, any> = Record<string, any>>(
2196
1837
  operations?: Mutation<R>[]
2197
1838
  ): Transaction
2198
-
2199
- // "Internals", should generally not be used externally
2200
1839
  /**
2201
- * DEPRECATED: Returns whether or not this client is using the Promise API (otherwise it is using observables)
1840
+ * DEPRECATED: Perform an HTTP request against the Sanity API
2202
1841
  *
2203
- * @deprecated Should be an internal concern
1842
+ * @deprecated Use your own request library!
1843
+ * @param options Request options
2204
1844
  */
2205
- isPromiseAPI(): boolean
2206
-
1845
+ request<R = any>(options: RawRequestOptions): Promise<R>
2207
1846
  /**
2208
- * DEPRECATED: Get a Sanity API URL for the URI provided
1847
+ * DEPRECATED: Perform an HTTP request a `/data` sub-endpoint
2209
1848
  *
2210
- * @deprecated Should be an internal concern
2211
- * @param uri URI/path to build URL for
2212
- * @param canUseCdn Whether or not to allow using the API CDN for this route
1849
+ * @deprecated Use your own request library!
1850
+ * @param endpoint Endpoint to hit (mutate, query etc)
1851
+ * @param body Request body
1852
+ * @param options Request options
2213
1853
  */
2214
- getUrl(uri: string, canUseCdn?: boolean): string
1854
+ dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<any>
1855
+ }
1856
+
1857
+ export declare type SanityDocument<T extends Record<string, any> = Record<string, any>> = {
1858
+ [P in keyof T]: T[P]
1859
+ } & {
1860
+ _id: string
1861
+ _rev: string
1862
+ _type: string
1863
+ _createdAt: string
1864
+ _updatedAt: string
1865
+ }
1866
+
1867
+ export declare type SanityDocumentStub<T extends Record<string, any> = Record<string, any>> = {
1868
+ [P in keyof T]: T[P]
1869
+ } & {
1870
+ _type: string
1871
+ }
2215
1872
 
1873
+ export declare interface SanityImageAssetDocument extends SanityAssetDocument {
1874
+ metadata: {
1875
+ _type: 'sanity.imageMetadata'
1876
+ hasAlpha: boolean
1877
+ isOpaque: boolean
1878
+ lqip?: string
1879
+ blurHash?: string
1880
+ dimensions: {
1881
+ _type: 'sanity.imageDimensions'
1882
+ aspectRatio: number
1883
+ height: number
1884
+ width: number
1885
+ }
1886
+ palette?: {
1887
+ _type: 'sanity.imagePalette'
1888
+ darkMuted?: SanityImagePalette
1889
+ darkVibrant?: SanityImagePalette
1890
+ dominant?: SanityImagePalette
1891
+ lightMuted?: SanityImagePalette
1892
+ lightVibrant?: SanityImagePalette
1893
+ muted?: SanityImagePalette
1894
+ vibrant?: SanityImagePalette
1895
+ }
1896
+ image?: {
1897
+ _type: 'sanity.imageExifTags'
1898
+ [key: string]: any
1899
+ }
1900
+ exif?: {
1901
+ _type: 'sanity.imageExifMetadata'
1902
+ [key: string]: any
1903
+ }
1904
+ }
1905
+ }
1906
+
1907
+ export declare interface SanityImagePalette {
1908
+ background: string
1909
+ foreground: string
1910
+ population: number
1911
+ title: string
1912
+ }
1913
+
1914
+ export declare interface SanityProject {
1915
+ id: string
1916
+ displayName: string
1917
+ studioHost: string | null
1918
+ organizationId: string | null
1919
+ isBlocked: boolean
1920
+ isDisabled: boolean
1921
+ isDisabledByUser: boolean
1922
+ createdAt: string
1923
+ pendingInvites?: number
1924
+ maxRetentionDays?: number
1925
+ members: SanityProjectMember[]
1926
+ metadata: {
1927
+ color?: string
1928
+ externalStudioHost?: string
1929
+ }
1930
+ }
1931
+
1932
+ export declare interface SanityProjectMember {
1933
+ id: string
1934
+ role: string
1935
+ isRobot: boolean
1936
+ isCurrentUser: boolean
1937
+ }
1938
+
1939
+ export declare interface SanityReference {
1940
+ _ref: string
1941
+ }
1942
+
1943
+ export declare interface SanityUser {
1944
+ id: string
1945
+ projectId: string
1946
+ displayName: string
1947
+ familyName: string | null
1948
+ givenName: string | null
1949
+ middleName: string | null
1950
+ imageUrl: string | null
1951
+ createdAt: string
1952
+ updatedAt: string
1953
+ isCurrentUser: boolean
1954
+ }
1955
+
1956
+ export declare class ServerError extends BaseError {
1957
+ response: ErrorProps['response']
1958
+ statusCode: ErrorProps['statusCode']
1959
+ responseBody: ErrorProps['responseBody']
1960
+ details: ErrorProps['details']
1961
+ constructor(res: any)
1962
+ }
1963
+
1964
+ export declare interface SingleMutationResult {
1965
+ transactionId: string
1966
+ documentId: string
1967
+ results: {
1968
+ id: string
1969
+ operation: MutationOperation
1970
+ }[]
1971
+ }
1972
+
1973
+ export declare class Transaction extends BaseTransaction {
1974
+ #private
1975
+ constructor(operations?: Mutation[], client?: SanityClient, transactionId?: string)
2216
1976
  /**
2217
- * DEPRECATED: Get a Sanity API URL for the data operation and path provided
1977
+ * Clones the transaction
1978
+ */
1979
+ clone(): Transaction
1980
+ /**
1981
+ * Commit the transaction, returning a promise that resolves to the first mutated document
2218
1982
  *
2219
- * @deprecated Should be an internal concern
2220
- * @param operation Data operation
2221
- * @param path Path to append
1983
+ * @param options - Options for the mutation operation
2222
1984
  */
2223
- getDataUrl(operation: string, path?: string): string
2224
-
1985
+ commit<R extends Record<string, any>>(
1986
+ options: TransactionFirstDocumentMutationOptions
1987
+ ): Promise<SanityDocument<R>>
2225
1988
  /**
2226
- * DEPRECATED: Perform an HTTP request against the Sanity API
1989
+ * Commit the transaction, returning a promise that resolves to an array of the mutated documents
2227
1990
  *
2228
- * @deprecated Use your own request library!
2229
- * @param options Request options
1991
+ * @param options - Options for the mutation operation
2230
1992
  */
2231
- request<T = any>(options: RawRequestOptions): Promise<T>
2232
-
1993
+ commit<R extends Record<string, any>>(
1994
+ options: TransactionAllDocumentsMutationOptions
1995
+ ): Promise<SanityDocument<R>[]>
2233
1996
  /**
2234
- * DEPRECATED: Perform an HTTP request a `/data` sub-endpoint
1997
+ * Commit the transaction, returning a promise that resolves to a mutation result object
2235
1998
  *
2236
- * @deprecated Use your own request library!
2237
- * @param endpoint Endpoint to hit (mutate, query etc)
2238
- * @param body Request body
2239
- * @param options Request options
1999
+ * @param options - Options for the mutation operation
2240
2000
  */
2241
- dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<any>
2001
+ commit(options: TransactionFirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2002
+ /**
2003
+ * Commit the transaction, returning a promise that resolves to a mutation result object
2004
+ *
2005
+ * @param options - Options for the mutation operation
2006
+ */
2007
+ commit(options: TransactionAllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2008
+ /**
2009
+ * Commit the transaction, returning a promise that resolves to a mutation result object
2010
+ *
2011
+ * @param options - Options for the mutation operation
2012
+ */
2013
+ commit(options?: BaseMutationOptions): Promise<MultipleMutationResult>
2014
+ /**
2015
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2016
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2017
+ *
2018
+ * @param documentId - Document ID to perform the patch operation on
2019
+ * @param patchOps - Operations to perform, or a builder function
2020
+ */
2021
+ patch(documentId: string, patchOps?: PatchBuilder | PatchOperations): this
2022
+ /**
2023
+ * Adds the given patch instance to the transaction.
2024
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2025
+ *
2026
+ * @param patch - Patch to execute
2027
+ */
2028
+ patch(patch: Patch): this
2029
+ }
2030
+
2031
+ export declare type TransactionAllDocumentIdsMutationOptions = BaseMutationOptions & {
2032
+ returnFirst?: false
2033
+ returnDocuments?: false
2034
+ }
2035
+
2036
+ export declare type TransactionAllDocumentsMutationOptions = BaseMutationOptions & {
2037
+ returnFirst?: false
2038
+ returnDocuments: true
2039
+ }
2040
+
2041
+ export declare type TransactionFirstDocumentIdMutationOptions = BaseMutationOptions & {
2042
+ returnFirst: true
2043
+ returnDocuments?: false
2044
+ }
2045
+
2046
+ export declare type TransactionFirstDocumentMutationOptions = BaseMutationOptions & {
2047
+ returnFirst: true
2048
+ returnDocuments: true
2049
+ }
2050
+
2051
+ export declare type TransactionMutationOptions =
2052
+ | TransactionFirstDocumentMutationOptions
2053
+ | TransactionFirstDocumentIdMutationOptions
2054
+ | TransactionAllDocumentsMutationOptions
2055
+ | TransactionAllDocumentIdsMutationOptions
2056
+
2057
+ export declare type UnfilteredResponseQueryOptions = RequestOptions & {
2058
+ filterResponse: false
2059
+ }
2060
+
2061
+ export declare interface UploadClientConfig {
2062
+ /**
2063
+ * Optional request tag for the upload
2064
+ */
2065
+ tag?: string
2066
+ /**
2067
+ * Whether or not to preserve the original filename (default: true)
2068
+ */
2069
+ preserveFilename?: boolean
2070
+ /**
2071
+ * Filename for this file (optional)
2072
+ */
2073
+ filename?: string
2074
+ /**
2075
+ * Milliseconds to wait before timing the request out
2076
+ */
2077
+ timeout?: number
2078
+ /**
2079
+ * Mime type of the file
2080
+ */
2081
+ contentType?: string
2082
+ /**
2083
+ * Array of metadata parts to extract from asset
2084
+ */
2085
+ extract?: AssetMetadataType[]
2086
+ /**
2087
+ * Optional freeform label for the asset. Generally not used.
2088
+ */
2089
+ label?: string
2090
+ /**
2091
+ * Optional title for the asset
2092
+ */
2093
+ title?: string
2094
+ /**
2095
+ * Optional description for the asset
2096
+ */
2097
+ description?: string
2098
+ /**
2099
+ * The credit to person(s) and/or organization(s) required by the supplier of the asset to be used when published
2100
+ */
2101
+ creditLine?: string
2102
+ /**
2103
+ * Source data (when the asset is from an external service)
2104
+ */
2105
+ source?: {
2106
+ /**
2107
+ * The (u)id of the asset within the source, i.e. 'i-f323r1E'
2108
+ */
2109
+ id: string
2110
+ /**
2111
+ * The name of the source, i.e. 'unsplash'
2112
+ */
2113
+ name: string
2114
+ /**
2115
+ * A url to where to find the asset, or get more info about it in the source
2116
+ */
2117
+ url?: string
2118
+ }
2242
2119
  }
2243
2120
 
2244
- export interface ClientConstructor {
2245
- Patch: typeof Patch
2246
- Transaction: typeof Transaction
2247
- ClientError: typeof ClientError
2248
- ServerError: typeof ServerError
2249
- requester: GetItRequester
2121
+ export declare class UsersClient extends BaseUsersClient {
2122
+ client: SanityClient
2123
+ constructor(client: SanityClient)
2124
+ }
2250
2125
 
2251
- new (config: ClientConfig): SanityClient
2252
- (config: ClientConfig): SanityClient
2126
+ export declare type WelcomeEvent = {
2127
+ type: 'welcome'
2253
2128
  }
2254
2129
 
2255
- declare const SanityClientConstructor: ClientConstructor
2256
- export default SanityClientConstructor
2130
+ export {}