@sanity/client 7.0.0 → 7.0.1-canary.1

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.
@@ -75,7 +75,7 @@ export declare type AssetMetadataType =
75
75
  | 'none'
76
76
 
77
77
  /** @internal */
78
- export declare class AssetsClient {
78
+ export declare class AssetsClient implements AssetsClientType {
79
79
  #private
80
80
  constructor(client: SanityClient, httpRequest: HttpRequest)
81
81
  /**
@@ -116,6 +116,52 @@ export declare class AssetsClient {
116
116
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
117
117
  }
118
118
 
119
+ /**
120
+ * The interface implemented by the `AssetsClient` class.
121
+ * When writing code that wants to take an instance of `AssetsClient` as input it's better to use this type,
122
+ * as the `AssetsClient` class has private properties and thus TypeScript will consider the type incompatible
123
+ * in cases where you might have multiple `@sanity/client` instances in your node_modules.
124
+ * @public
125
+ */
126
+ declare interface AssetsClientType {
127
+ /**
128
+ * Uploads a file asset to the configured dataset
129
+ *
130
+ * @param assetType - Asset type (file)
131
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
132
+ * @param options - Options to use for the upload
133
+ */
134
+ upload(
135
+ assetType: 'file',
136
+ body: UploadBody,
137
+ options?: UploadClientConfig,
138
+ ): Promise<SanityAssetDocument>
139
+ /**
140
+ * Uploads an image asset to the configured dataset
141
+ *
142
+ * @param assetType - Asset type (image)
143
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
144
+ * @param options - Options to use for the upload
145
+ */
146
+ upload(
147
+ assetType: 'image',
148
+ body: UploadBody,
149
+ options?: UploadClientConfig,
150
+ ): Promise<SanityImageAssetDocument>
151
+ /**
152
+ * Uploads a file or an image asset to the configured dataset
153
+ *
154
+ * @param assetType - Asset type (file/image)
155
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
156
+ * @param options - Options to use for the upload
157
+ */
158
+ upload(
159
+ assetType: 'file' | 'image',
160
+ body: UploadBody,
161
+ options?: UploadClientConfig,
162
+ ): Promise<SanityAssetDocument | SanityImageAssetDocument>
163
+ }
164
+
119
165
  /** @internal */
120
166
  export declare type AttributeSet = {
121
167
  [key: string]: Any
@@ -1286,7 +1332,7 @@ export declare type MutationSelectionQueryParams = {
1286
1332
  }
1287
1333
 
1288
1334
  /** @internal */
1289
- export declare class ObservableAssetsClient {
1335
+ export declare class ObservableAssetsClient implements ObservableAssetsClientType {
1290
1336
  #private
1291
1337
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1292
1338
  /**
@@ -1339,6 +1385,64 @@ export declare class ObservableAssetsClient {
1339
1385
  >
1340
1386
  }
1341
1387
 
1388
+ /**
1389
+ * The interface implemented by the `ObservableAssetsClient` class.
1390
+ * When writing code that wants to take an instance of `ObservableAssetsClient` as input it's better to use this type,
1391
+ * as the `ObservableAssetsClient` class has private properties and thus TypeScript will consider the type incompatible
1392
+ * in cases where you might have multiple `@sanity/client` instances in your node_modules.
1393
+ * @public
1394
+ */
1395
+ declare interface ObservableAssetsClientType {
1396
+ /**
1397
+ * Uploads a file asset to the configured dataset
1398
+ *
1399
+ * @param assetType - Asset type (file)
1400
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1401
+ * @param options - Options to use for the upload
1402
+ */
1403
+ upload(
1404
+ assetType: 'file',
1405
+ body: UploadBody,
1406
+ options?: UploadClientConfig,
1407
+ ): Observable<
1408
+ HttpRequestEvent<{
1409
+ document: SanityAssetDocument
1410
+ }>
1411
+ >
1412
+ /**
1413
+ * Uploads an image asset to the configured dataset
1414
+ *
1415
+ * @param assetType - Asset type (image)
1416
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1417
+ * @param options - Options to use for the upload
1418
+ */
1419
+ upload(
1420
+ assetType: 'image',
1421
+ body: UploadBody,
1422
+ options?: UploadClientConfig,
1423
+ ): Observable<
1424
+ HttpRequestEvent<{
1425
+ document: SanityImageAssetDocument
1426
+ }>
1427
+ >
1428
+ /**
1429
+ * Uploads a file or an image asset to the configured dataset
1430
+ *
1431
+ * @param assetType - Asset type (file/image)
1432
+ * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1433
+ * @param options - Options to use for the upload
1434
+ */
1435
+ upload(
1436
+ assetType: 'file' | 'image',
1437
+ body: UploadBody,
1438
+ options?: UploadClientConfig,
1439
+ ): Observable<
1440
+ HttpRequestEvent<{
1441
+ document: SanityAssetDocument | SanityImageAssetDocument
1442
+ }>
1443
+ >
1444
+ }
1445
+
1342
1446
  /** @internal */
1343
1447
  export declare class ObservableDatasetsClient {
1344
1448
  #private
@@ -1455,16 +1559,13 @@ export declare class ObservableProjectsClient {
1455
1559
  }
1456
1560
 
1457
1561
  /** @public */
1458
- export declare class ObservableSanityClient {
1562
+ export declare class ObservableSanityClient implements ObservableSanityClientType {
1459
1563
  #private
1460
1564
  assets: ObservableAssetsClient
1461
1565
  datasets: ObservableDatasetsClient
1462
1566
  live: LiveClient
1463
1567
  projects: ObservableProjectsClient
1464
1568
  users: ObservableUsersClient
1465
- /**
1466
- * Instance properties
1467
- */
1468
1569
  listen: typeof _listen
1469
1570
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1470
1571
  /**
@@ -1523,7 +1624,7 @@ export declare class ObservableSanityClient {
1523
1624
  Q extends QueryWithoutParams | QueryParams = QueryParams,
1524
1625
  const G extends string = string,
1525
1626
  >(
1526
- query: string,
1627
+ query: G,
1527
1628
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1528
1629
  options: UnfilteredResponseQueryOptions,
1529
1630
  ): Observable<RawQueryResponse<ClientReturn<G, R>>>
@@ -1958,442 +2059,1485 @@ export declare class ObservableSanityClient {
1958
2059
  getDataUrl(operation: string, path?: string): string
1959
2060
  }
1960
2061
 
1961
- /** @public */
1962
- export declare class ObservableTransaction extends BaseTransaction {
1963
- #private
1964
- constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2062
+ /**
2063
+ * The interface implemented by the `ObservableSanityClient` class.
2064
+ * When writing code that wants to take an instance of `ObservableSanityClient` as input it's better to use this type,
2065
+ * as the `ObservableSanityClient` class has private properties and thus TypeScrict will consider the type incompatible
2066
+ * in cases where you might have multiple `@sanity/client` instances in your node_modules.
2067
+ * @public
2068
+ */
2069
+ export declare interface ObservableSanityClientType extends SanityClientBase {
2070
+ assets: ObservableAssetsClient
2071
+ datasets: ObservableDatasetsClient
2072
+ projects: ObservableProjectsClient
2073
+ users: ObservableUsersClient
1965
2074
  /**
1966
- * Clones the transaction
2075
+ * Clone the client - returns a new instance
1967
2076
  */
1968
- clone(): ObservableTransaction
2077
+ clone(): ObservableSanityClientType
1969
2078
  /**
1970
- * Commit the transaction, returning an observable that produces the first mutated document
1971
- *
1972
- * @param options - Options for the mutation operation
2079
+ * Returns the current client configuration
1973
2080
  */
1974
- commit<R extends Record<string, Any>>(
1975
- options: TransactionFirstDocumentMutationOptions,
1976
- ): Observable<SanityDocument<R>>
2081
+ config(): InitializedClientConfig
1977
2082
  /**
1978
- * Commit the transaction, returning an observable that produces an array of the mutated documents
1979
- *
1980
- * @param options - Options for the mutation operation
2083
+ * Reconfigure the client. Note that this _mutates_ the current client.
1981
2084
  */
1982
- commit<R extends Record<string, Any>>(
1983
- options: TransactionAllDocumentsMutationOptions,
1984
- ): Observable<SanityDocument<R>[]>
2085
+ config(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
1985
2086
  /**
1986
- * Commit the transaction, returning an observable that produces a mutation result object
2087
+ * Clone the client with a new (partial) configuration.
1987
2088
  *
1988
- * @param options - Options for the mutation operation
2089
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
1989
2090
  */
1990
- commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2091
+ withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
1991
2092
  /**
1992
- * Commit the transaction, returning an observable that produces a mutation result object
2093
+ * Perform a GROQ-query against the configured dataset.
1993
2094
  *
1994
- * @param options - Options for the mutation operation
2095
+ * @param query - GROQ-query to perform
1995
2096
  */
1996
- commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2097
+ fetch<
2098
+ R = Any,
2099
+ Q extends QueryWithoutParams = QueryWithoutParams,
2100
+ const G extends string = string,
2101
+ >(
2102
+ query: G,
2103
+ params?: Q | QueryWithoutParams,
2104
+ ): Observable<ClientReturn<G, R>>
1997
2105
  /**
1998
- * Commit the transaction, returning an observable that produces a mutation result object
2106
+ * Perform a GROQ-query against the configured dataset.
1999
2107
  *
2000
- * @param options - Options for the mutation operation
2108
+ * @param query - GROQ-query to perform
2109
+ * @param params - Optional query parameters
2110
+ * @param options - Optional request options
2001
2111
  */
2002
- commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2112
+ fetch<
2113
+ R = Any,
2114
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2115
+ const G extends string = string,
2116
+ >(
2117
+ query: G,
2118
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2119
+ options?: FilteredResponseQueryOptions,
2120
+ ): Observable<ClientReturn<G, R>>
2003
2121
  /**
2004
- * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2005
- * The operation is added to the current transaction, ready to be commited by `commit()`
2122
+ * Perform a GROQ-query against the configured dataset.
2006
2123
  *
2007
- * @param documentId - Document ID to perform the patch operation on
2008
- * @param patchOps - Operations to perform, or a builder function
2124
+ * @param query - GROQ-query to perform
2125
+ * @param params - Optional query parameters
2126
+ * @param options - Request options
2009
2127
  */
2010
- patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2128
+ fetch<
2129
+ R = Any,
2130
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2131
+ const G extends string = string,
2132
+ >(
2133
+ query: G,
2134
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2135
+ options: UnfilteredResponseQueryOptions,
2136
+ ): Observable<RawQueryResponse<ClientReturn<G, R>>>
2011
2137
  /**
2012
- * Adds the given patch instance to the transaction.
2013
- * The operation is added to the current transaction, ready to be commited by `commit()`
2138
+ * Perform a GROQ-query against the configured dataset.
2014
2139
  *
2015
- * @param patch - ObservablePatch to execute
2140
+ * @param query - GROQ-query to perform
2141
+ * @param params - Optional query parameters
2142
+ * @param options - Request options
2016
2143
  */
2017
- patch(patch: ObservablePatch): this
2018
- }
2019
-
2020
- /** @public */
2021
- export declare class ObservableUsersClient {
2022
- #private
2023
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2144
+ fetch<
2145
+ R = Any,
2146
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
2147
+ const G extends string = string,
2148
+ >(
2149
+ query: G,
2150
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2151
+ options: UnfilteredResponseWithoutQuery,
2152
+ ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2024
2153
  /**
2025
- * Fetch a user by user ID
2154
+ * Fetch a single document with the given ID.
2026
2155
  *
2027
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2156
+ * @param id - Document ID to fetch
2157
+ * @param options - Request options
2028
2158
  */
2029
- getById<T extends 'me' | string>(
2030
- id: T,
2031
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2032
- }
2033
-
2034
- /**
2035
- * The listener connection has been established
2036
- * note: it's usually a better option to use the 'welcome' event
2037
- * @public
2038
- */
2039
- export declare type OpenEvent = {
2040
- type: 'open'
2041
- }
2042
-
2043
- /** @public */
2044
- export declare class Patch extends BasePatch {
2045
- #private
2046
- constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2159
+ getDocument<R extends Record<string, Any> = Record<string, Any>>(
2160
+ id: string,
2161
+ options?: {
2162
+ tag?: string
2163
+ },
2164
+ ): Observable<SanityDocument<R> | undefined>
2047
2165
  /**
2048
- * Clones the patch
2166
+ * Fetch multiple documents in one request.
2167
+ * Should be used sparingly - performing a query is usually a better option.
2168
+ * The order/position of documents is preserved based on the original array of IDs.
2169
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
2170
+ *
2171
+ * @param ids - Document IDs to fetch
2172
+ * @param options - Request options
2049
2173
  */
2050
- clone(): Patch
2174
+ getDocuments<R extends Record<string, Any> = Record<string, Any>>(
2175
+ ids: string[],
2176
+ options?: {
2177
+ tag?: string
2178
+ },
2179
+ ): Observable<(SanityDocument<R> | null)[]>
2051
2180
  /**
2052
- * Commit the patch, returning a promise that resolves to the first patched document
2181
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2182
+ * Returns an observable that resolves to the created document.
2053
2183
  *
2054
- * @param options - Options for the mutation operation
2184
+ * @param document - Document to create
2185
+ * @param options - Mutation options
2055
2186
  */
2056
- commit<R extends Record<string, Any> = Record<string, Any>>(
2187
+ create<R extends Record<string, Any> = Record<string, Any>>(
2188
+ document: SanityDocumentStub<R>,
2057
2189
  options: FirstDocumentMutationOptions,
2058
- ): Promise<SanityDocument<R>>
2190
+ ): Observable<SanityDocument<R>>
2059
2191
  /**
2060
- * Commit the patch, returning a promise that resolves to an array of the mutated documents
2192
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2193
+ * Returns an observable that resolves to an array containing the created document.
2194
+ *
2195
+ * @param document - Document to create
2196
+ * @param options - Mutation options
2197
+ */
2198
+ create<R extends Record<string, Any> = Record<string, Any>>(
2199
+ document: SanityDocumentStub<R>,
2200
+ options: AllDocumentsMutationOptions,
2201
+ ): Observable<SanityDocument<R>[]>
2202
+ /**
2203
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2204
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2205
+ *
2206
+ * @param document - Document to create
2207
+ * @param options - Mutation options
2208
+ */
2209
+ create<R extends Record<string, Any> = Record<string, Any>>(
2210
+ document: SanityDocumentStub<R>,
2211
+ options: FirstDocumentIdMutationOptions,
2212
+ ): Observable<SingleMutationResult>
2213
+ /**
2214
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2215
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2216
+ *
2217
+ * @param document - Document to create
2218
+ * @param options - Mutation options
2219
+ */
2220
+ create<R extends Record<string, Any> = Record<string, Any>>(
2221
+ document: SanityDocumentStub<R>,
2222
+ options: AllDocumentIdsMutationOptions,
2223
+ ): Observable<MultipleMutationResult>
2224
+ /**
2225
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2226
+ * Returns an observable that resolves to the created document.
2227
+ *
2228
+ * @param document - Document to create
2229
+ * @param options - Mutation options
2230
+ */
2231
+ create<R extends Record<string, Any> = Record<string, Any>>(
2232
+ document: SanityDocumentStub<R>,
2233
+ options?: BaseMutationOptions,
2234
+ ): Observable<SanityDocument<R>>
2235
+ /**
2236
+ * Create a document if no document with the same ID already exists.
2237
+ * Returns an observable that resolves to the created document.
2238
+ *
2239
+ * @param document - Document to create
2240
+ * @param options - Mutation options
2241
+ */
2242
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2243
+ document: IdentifiedSanityDocumentStub<R>,
2244
+ options: FirstDocumentMutationOptions,
2245
+ ): Observable<SanityDocument<R>>
2246
+ /**
2247
+ * Create a document if no document with the same ID already exists.
2248
+ * Returns an observable that resolves to an array containing the created document.
2249
+ *
2250
+ * @param document - Document to create
2251
+ * @param options - Mutation options
2252
+ */
2253
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2254
+ document: IdentifiedSanityDocumentStub<R>,
2255
+ options: AllDocumentsMutationOptions,
2256
+ ): Observable<SanityDocument<R>[]>
2257
+ /**
2258
+ * Create a document if no document with the same ID already exists.
2259
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2260
+ *
2261
+ * @param document - Document to create
2262
+ * @param options - Mutation options
2263
+ */
2264
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2265
+ document: IdentifiedSanityDocumentStub<R>,
2266
+ options: FirstDocumentIdMutationOptions,
2267
+ ): Observable<SingleMutationResult>
2268
+ /**
2269
+ * Create a document if no document with the same ID already exists.
2270
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2271
+ *
2272
+ * @param document - Document to create
2273
+ * @param options - Mutation options
2274
+ */
2275
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2276
+ document: IdentifiedSanityDocumentStub<R>,
2277
+ options: AllDocumentIdsMutationOptions,
2278
+ ): Observable<MultipleMutationResult>
2279
+ /**
2280
+ * Create a document if no document with the same ID already exists.
2281
+ * Returns an observable that resolves to the created document.
2282
+ *
2283
+ * @param document - Document to create
2284
+ * @param options - Mutation options
2285
+ */
2286
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2287
+ document: IdentifiedSanityDocumentStub<R>,
2288
+ options?: BaseMutationOptions,
2289
+ ): Observable<SanityDocument<R>>
2290
+ /**
2291
+ * Create a document if it does not exist, or replace a document with the same document ID
2292
+ * Returns an observable that resolves to the created document.
2293
+ *
2294
+ * @param document - Document to either create or replace
2295
+ * @param options - Mutation options
2296
+ */
2297
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2298
+ document: IdentifiedSanityDocumentStub<R>,
2299
+ options: FirstDocumentMutationOptions,
2300
+ ): Observable<SanityDocument<R>>
2301
+ /**
2302
+ * Create a document if it does not exist, or replace a document with the same document ID
2303
+ * Returns an observable that resolves to an array containing the created document.
2304
+ *
2305
+ * @param document - Document to either create or replace
2306
+ * @param options - Mutation options
2307
+ */
2308
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2309
+ document: IdentifiedSanityDocumentStub<R>,
2310
+ options: AllDocumentsMutationOptions,
2311
+ ): Observable<SanityDocument<R>[]>
2312
+ /**
2313
+ * Create a document if it does not exist, or replace a document with the same document ID
2314
+ * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2315
+ *
2316
+ * @param document - Document to either create or replace
2317
+ * @param options - Mutation options
2318
+ */
2319
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2320
+ document: IdentifiedSanityDocumentStub<R>,
2321
+ options: FirstDocumentIdMutationOptions,
2322
+ ): Observable<SingleMutationResult>
2323
+ /**
2324
+ * Create a document if it does not exist, or replace a document with the same document ID
2325
+ * Returns an observable that resolves to a mutation result object containing the created document ID.
2326
+ *
2327
+ * @param document - Document to either create or replace
2328
+ * @param options - Mutation options
2329
+ */
2330
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2331
+ document: IdentifiedSanityDocumentStub<R>,
2332
+ options: AllDocumentIdsMutationOptions,
2333
+ ): Observable<MultipleMutationResult>
2334
+ /**
2335
+ * Create a document if it does not exist, or replace a document with the same document ID
2336
+ * Returns an observable that resolves to the created document.
2337
+ *
2338
+ * @param document - Document to either create or replace
2339
+ * @param options - Mutation options
2340
+ */
2341
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2342
+ document: IdentifiedSanityDocumentStub<R>,
2343
+ options?: BaseMutationOptions,
2344
+ ): Observable<SanityDocument<R>>
2345
+ /**
2346
+ * Deletes a document with the given document ID.
2347
+ * Returns an observable that resolves to the deleted document.
2348
+ *
2349
+ * @param id - Document ID to delete
2350
+ * @param options - Options for the mutation
2351
+ */
2352
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2353
+ id: string,
2354
+ options: FirstDocumentMutationOptions,
2355
+ ): Observable<SanityDocument<R>>
2356
+ /**
2357
+ * Deletes a document with the given document ID.
2358
+ * Returns an observable that resolves to an array containing the deleted document.
2359
+ *
2360
+ * @param id - Document ID to delete
2361
+ * @param options - Options for the mutation
2362
+ */
2363
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2364
+ id: string,
2365
+ options: AllDocumentsMutationOptions,
2366
+ ): Observable<SanityDocument<R>[]>
2367
+ /**
2368
+ * Deletes a document with the given document ID.
2369
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2370
+ *
2371
+ * @param id - Document ID to delete
2372
+ * @param options - Options for the mutation
2373
+ */
2374
+ delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2375
+ /**
2376
+ * Deletes a document with the given document ID.
2377
+ * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2378
+ *
2379
+ * @param id - Document ID to delete
2380
+ * @param options - Options for the mutation
2381
+ */
2382
+ delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2383
+ /**
2384
+ * Deletes a document with the given document ID.
2385
+ * Returns an observable that resolves to the deleted document.
2386
+ *
2387
+ * @param id - Document ID to delete
2388
+ * @param options - Options for the mutation
2389
+ */
2390
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2391
+ id: string,
2392
+ options?: BaseMutationOptions,
2393
+ ): Observable<SanityDocument<R>>
2394
+ /**
2395
+ * Deletes one or more documents matching the given query or document ID.
2396
+ * Returns an observable that resolves to first deleted document.
2397
+ *
2398
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2399
+ * @param options - Options for the mutation
2400
+ */
2401
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2402
+ selection: MutationSelection,
2403
+ options: FirstDocumentMutationOptions,
2404
+ ): Observable<SanityDocument<R>>
2405
+ /**
2406
+ * Deletes one or more documents matching the given query or document ID.
2407
+ * Returns an observable that resolves to an array containing the deleted documents.
2408
+ *
2409
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2410
+ * @param options - Options for the mutation
2411
+ */
2412
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2413
+ selection: MutationSelection,
2414
+ options: AllDocumentsMutationOptions,
2415
+ ): Observable<SanityDocument<R>[]>
2416
+ /**
2417
+ * Deletes one or more documents matching the given query or document ID.
2418
+ * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
2419
+ *
2420
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2421
+ * @param options - Options for the mutation
2422
+ */
2423
+ delete(
2424
+ selection: MutationSelection,
2425
+ options: FirstDocumentIdMutationOptions,
2426
+ ): Observable<SingleMutationResult>
2427
+ /**
2428
+ * Deletes one or more documents matching the given query or document ID.
2429
+ * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
2430
+ *
2431
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2432
+ * @param options - Options for the mutation
2433
+ */
2434
+ delete(
2435
+ selection: MutationSelection,
2436
+ options: AllDocumentIdsMutationOptions,
2437
+ ): Observable<MultipleMutationResult>
2438
+ /**
2439
+ * Deletes one or more documents matching the given query or document ID.
2440
+ * Returns an observable that resolves to first deleted document.
2441
+ *
2442
+ * @param selection - An object with either an `id` or `query` key defining what to delete
2443
+ * @param options - Options for the mutation
2444
+ */
2445
+ delete<R extends Record<string, Any> = Record<string, Any>>(
2446
+ selection: MutationSelection,
2447
+ options?: BaseMutationOptions,
2448
+ ): Observable<SanityDocument<R>>
2449
+ /**
2450
+ * Perform mutation operations against the configured dataset
2451
+ * Returns an observable that resolves to the first mutated document.
2452
+ *
2453
+ * @param operations - Mutation operations to execute
2454
+ * @param options - Mutation options
2455
+ */
2456
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2457
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2458
+ options: FirstDocumentMutationOptions,
2459
+ ): Observable<SanityDocument<R>>
2460
+ /**
2461
+ * Perform mutation operations against the configured dataset.
2462
+ * Returns an observable that resolves to an array of the mutated documents.
2463
+ *
2464
+ * @param operations - Mutation operations to execute
2465
+ * @param options - Mutation options
2466
+ */
2467
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2468
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2469
+ options: AllDocumentsMutationOptions,
2470
+ ): Observable<SanityDocument<R>[]>
2471
+ /**
2472
+ * Perform mutation operations against the configured dataset
2473
+ * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
2474
+ *
2475
+ * @param operations - Mutation operations to execute
2476
+ * @param options - Mutation options
2477
+ */
2478
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2479
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2480
+ options: FirstDocumentIdMutationOptions,
2481
+ ): Observable<SingleMutationResult>
2482
+ /**
2483
+ * Perform mutation operations against the configured dataset
2484
+ * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
2485
+ *
2486
+ * @param operations - Mutation operations to execute
2487
+ * @param options - Mutation options
2488
+ */
2489
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2490
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2491
+ options: AllDocumentIdsMutationOptions,
2492
+ ): Observable<MultipleMutationResult>
2493
+ /**
2494
+ * Perform mutation operations against the configured dataset
2495
+ * Returns an observable that resolves to the first mutated document.
2496
+ *
2497
+ * @param operations - Mutation operations to execute
2498
+ * @param options - Mutation options
2499
+ */
2500
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
2501
+ operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2502
+ options?: BaseMutationOptions,
2503
+ ): Observable<SanityDocument<R>>
2504
+ /**
2505
+ * Create a new buildable patch of operations to perform
2506
+ *
2507
+ * @param documentId - Document ID to patch
2508
+ * @param operations - Optional object of patch operations to initialize the patch instance with
2509
+ * @returns Patch instance - call `.commit()` to perform the operations defined
2510
+ */
2511
+ patch(documentId: string, operations?: PatchOperations): ObservablePatch
2512
+ /**
2513
+ * Create a new buildable patch of operations to perform
2514
+ *
2515
+ * @param documentIds - Array of document IDs to patch
2516
+ * @param operations - Optional object of patch operations to initialize the patch instance with
2517
+ * @returns Patch instance - call `.commit()` to perform the operations defined
2518
+ */
2519
+ patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
2520
+ /**
2521
+ * Create a new buildable patch of operations to perform
2522
+ *
2523
+ * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
2524
+ * @param operations - Optional object of patch operations to initialize the patch instance with
2525
+ * @returns Patch instance - call `.commit()` to perform the operations defined
2526
+ */
2527
+ patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
2528
+ /**
2529
+ * Create a new buildable patch of operations to perform
2530
+ *
2531
+ * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
2532
+ * @param operations - Optional object of patch operations to initialize the patch instance with
2533
+ * @returns Patch instance - call `.commit()` to perform the operations defined
2534
+ */
2535
+ patch(selection: PatchSelection, operations?: PatchOperations): ObservablePatch
2536
+ /**
2537
+ * Create a new transaction of mutations
2538
+ *
2539
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
2540
+ */
2541
+ transaction<R extends Record<string, Any> = Record<string, Any>>(
2542
+ operations?: Mutation<R>[],
2543
+ ): ObservableTransaction
2544
+ /**
2545
+ * Perform action operations against the configured dataset
2546
+ *
2547
+ * @param operations - Action operation(s) to execute
2548
+ * @param options - Action options
2549
+ */
2550
+ action(
2551
+ operations: Action | Action[],
2552
+ options?: BaseActionOptions,
2553
+ ): Observable<SingleActionResult | MultipleActionResult>
2554
+ /**
2555
+ * Perform an HTTP request against the Sanity API
2556
+ *
2557
+ * @param options - Request options
2558
+ */
2559
+ request<R = Any>(options: RawRequestOptions): Observable<R>
2560
+ }
2561
+
2562
+ /** @public */
2563
+ export declare class ObservableTransaction extends BaseTransaction {
2564
+ #private
2565
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2566
+ /**
2567
+ * Clones the transaction
2568
+ */
2569
+ clone(): ObservableTransaction
2570
+ /**
2571
+ * Commit the transaction, returning an observable that produces the first mutated document
2572
+ *
2573
+ * @param options - Options for the mutation operation
2574
+ */
2575
+ commit<R extends Record<string, Any>>(
2576
+ options: TransactionFirstDocumentMutationOptions,
2577
+ ): Observable<SanityDocument<R>>
2578
+ /**
2579
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
2580
+ *
2581
+ * @param options - Options for the mutation operation
2582
+ */
2583
+ commit<R extends Record<string, Any>>(
2584
+ options: TransactionAllDocumentsMutationOptions,
2585
+ ): Observable<SanityDocument<R>[]>
2586
+ /**
2587
+ * Commit the transaction, returning an observable that produces a mutation result object
2588
+ *
2589
+ * @param options - Options for the mutation operation
2590
+ */
2591
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2592
+ /**
2593
+ * Commit the transaction, returning an observable that produces a mutation result object
2594
+ *
2595
+ * @param options - Options for the mutation operation
2596
+ */
2597
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2598
+ /**
2599
+ * Commit the transaction, returning an observable that produces a mutation result object
2600
+ *
2601
+ * @param options - Options for the mutation operation
2602
+ */
2603
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2604
+ /**
2605
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2606
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2607
+ *
2608
+ * @param documentId - Document ID to perform the patch operation on
2609
+ * @param patchOps - Operations to perform, or a builder function
2610
+ */
2611
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2612
+ /**
2613
+ * Adds the given patch instance to the transaction.
2614
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2615
+ *
2616
+ * @param patch - ObservablePatch to execute
2617
+ */
2618
+ patch(patch: ObservablePatch): this
2619
+ }
2620
+
2621
+ /** @public */
2622
+ export declare class ObservableUsersClient {
2623
+ #private
2624
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2625
+ /**
2626
+ * Fetch a user by user ID
2627
+ *
2628
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2629
+ */
2630
+ getById<T extends 'me' | string>(
2631
+ id: T,
2632
+ ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2633
+ }
2634
+
2635
+ /**
2636
+ * The listener connection has been established
2637
+ * note: it's usually a better option to use the 'welcome' event
2638
+ * @public
2639
+ */
2640
+ export declare type OpenEvent = {
2641
+ type: 'open'
2642
+ }
2643
+
2644
+ /** @public */
2645
+ export declare class Patch extends BasePatch {
2646
+ #private
2647
+ constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2648
+ /**
2649
+ * Clones the patch
2650
+ */
2651
+ clone(): Patch
2652
+ /**
2653
+ * Commit the patch, returning a promise that resolves to the first patched document
2654
+ *
2655
+ * @param options - Options for the mutation operation
2656
+ */
2657
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2658
+ options: FirstDocumentMutationOptions,
2659
+ ): Promise<SanityDocument<R>>
2660
+ /**
2661
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
2662
+ *
2663
+ * @param options - Options for the mutation operation
2664
+ */
2665
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2666
+ options: AllDocumentsMutationOptions,
2667
+ ): Promise<SanityDocument<R>[]>
2668
+ /**
2669
+ * Commit the patch, returning a promise that resolves to a mutation result object
2670
+ *
2671
+ * @param options - Options for the mutation operation
2672
+ */
2673
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2674
+ /**
2675
+ * Commit the patch, returning a promise that resolves to a mutation result object
2676
+ *
2677
+ * @param options - Options for the mutation operation
2678
+ */
2679
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2680
+ /**
2681
+ * Commit the patch, returning a promise that resolves to the first patched document
2682
+ *
2683
+ * @param options - Options for the mutation operation
2684
+ */
2685
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2686
+ options?: BaseMutationOptions,
2687
+ ): Promise<SanityDocument<R>>
2688
+ }
2689
+
2690
+ /** @public */
2691
+ export declare type PatchBuilder = (patch: Patch) => Patch
2692
+
2693
+ /** @internal */
2694
+ export declare type PatchMutationOperation = PatchOperations & MutationSelection
2695
+
2696
+ /** @internal */
2697
+ export declare interface PatchOperations {
2698
+ set?: {
2699
+ [key: string]: Any
2700
+ }
2701
+ setIfMissing?: {
2702
+ [key: string]: Any
2703
+ }
2704
+ diffMatchPatch?: {
2705
+ [key: string]: Any
2706
+ }
2707
+ unset?: string[]
2708
+ inc?: {
2709
+ [key: string]: number
2710
+ }
2711
+ dec?: {
2712
+ [key: string]: number
2713
+ }
2714
+ insert?: InsertPatch
2715
+ ifRevisionID?: string
2716
+ }
2717
+
2718
+ /** @internal */
2719
+ export declare type PatchSelection = string | string[] | MutationSelection
2720
+
2721
+ /** @public */
2722
+ declare interface ProgressEvent_2 {
2723
+ type: 'progress'
2724
+ stage: 'upload' | 'download'
2725
+ percent: number
2726
+ total?: number
2727
+ loaded?: number
2728
+ lengthComputable: boolean
2729
+ }
2730
+ export {ProgressEvent_2 as ProgressEvent}
2731
+
2732
+ /** @internal */
2733
+ export declare class ProjectsClient {
2734
+ #private
2735
+ constructor(client: SanityClient, httpRequest: HttpRequest)
2736
+ /**
2737
+ * Fetch a list of projects the authenticated user has access to.
2738
+ *
2739
+ * @param options - Options for the list request
2740
+ * @param options.includeMembers - Whether to include members in the response (default: true)
2741
+ */
2742
+ list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2743
+ list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
2744
+ /**
2745
+ * Fetch a project by project ID
2746
+ *
2747
+ * @param projectId - ID of the project to fetch
2748
+ */
2749
+ getById(projectId: string): Promise<SanityProject>
2750
+ }
2751
+
2752
+ /**
2753
+ * Publishes a draft document.
2754
+ * If a published version of the document already exists this is replaced by the current draft document.
2755
+ * In either case the draft document is deleted.
2756
+ * The optional revision id parameters can be used for optimistic locking to ensure
2757
+ * that the draft and/or published versions of the document have not been changed by another client.
2758
+ *
2759
+ * @public
2760
+ */
2761
+ export declare type PublishAction = {
2762
+ actionType: 'sanity.action.document.publish'
2763
+ /**
2764
+ * Draft document ID to publish
2765
+ */
2766
+ draftId: string
2767
+ /**
2768
+ * Draft revision ID to match
2769
+ */
2770
+ ifDraftRevisionId?: string
2771
+ /**
2772
+ * Published document ID to replace
2773
+ */
2774
+ publishedId: string
2775
+ /**
2776
+ * Published revision ID to match
2777
+ */
2778
+ ifPublishedRevisionId?: string
2779
+ }
2780
+
2781
+ /** @public */
2782
+ export declare type QueryOptions =
2783
+ | FilteredResponseQueryOptions
2784
+ | UnfilteredResponseQueryOptions
2785
+ | UnfilteredResponseWithoutQuery
2786
+
2787
+ /** @public */
2788
+ export declare interface QueryParams {
2789
+ [key: string]: any
2790
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2791
+ body?: never
2792
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2793
+ cache?: 'next' extends keyof RequestInit ? never : any
2794
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2795
+ filterResponse?: never
2796
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2797
+ headers?: never
2798
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2799
+ method?: never
2800
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2801
+ next?: 'next' extends keyof RequestInit ? never : any
2802
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2803
+ perspective?: never
2804
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2805
+ query?: never
2806
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2807
+ resultSourceMap?: never
2808
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2809
+ returnQuery?: never
2810
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2811
+ signal?: never
2812
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2813
+ stega?: never
2814
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2815
+ tag?: never
2816
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2817
+ timeout?: never
2818
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2819
+ token?: never
2820
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2821
+ useCdn?: never
2822
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2823
+ lastLiveEventId?: never
2824
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2825
+ cacheMode?: never
2826
+ }
2827
+
2828
+ /**
2829
+ * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
2830
+ * @public
2831
+ */
2832
+ export declare type QueryWithoutParams = Record<string, never> | undefined
2833
+
2834
+ /** @public */
2835
+ export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
2836
+
2837
+ /** @public */
2838
+ export declare interface RawQueryResponse<R> {
2839
+ query: string
2840
+ ms: number
2841
+ result: R
2842
+ resultSourceMap?: ContentSourceMap
2843
+ /** Requires `apiVersion` to be `2021-03-25` or later. */
2844
+ syncTags?: SyncTag[]
2845
+ }
2846
+
2847
+ /** @internal */
2848
+ export declare interface RawRequestOptions {
2849
+ url?: string
2850
+ uri?: string
2851
+ method?: string
2852
+ token?: string
2853
+ json?: boolean
2854
+ tag?: string
2855
+ useGlobalApi?: boolean
2856
+ withCredentials?: boolean
2857
+ query?: {
2858
+ [key: string]: string | string[]
2859
+ }
2860
+ headers?: {
2861
+ [key: string]: string
2862
+ }
2863
+ timeout?: number
2864
+ proxy?: string
2865
+ body?: Any
2866
+ maxRedirects?: number
2867
+ signal?: AbortSignal
2868
+ }
2869
+
2870
+ /**
2871
+ * The listener has been disconnected, and a reconnect attempt is scheduled.
2872
+ *
2873
+ * @public
2874
+ */
2875
+ export declare type ReconnectEvent = {
2876
+ type: 'reconnect'
2877
+ }
2878
+
2879
+ /**
2880
+ * @public
2881
+ * @deprecated – The `r`-prefix is not required, use `string` instead
2882
+ */
2883
+ export declare type ReleaseId = `r${string}`
2884
+
2885
+ /**
2886
+ * Replaces an existing draft document.
2887
+ * At least one of the draft or published versions of the document must exist.
2888
+ *
2889
+ * @public
2890
+ */
2891
+ export declare type ReplaceDraftAction = {
2892
+ actionType: 'sanity.action.document.replaceDraft'
2893
+ /**
2894
+ * Published document ID to create draft from, if draft does not exist
2895
+ */
2896
+ publishedId: string
2897
+ /**
2898
+ * Document to create if it does not already exist. Requires `_id` and `_type` properties.
2899
+ */
2900
+ attributes: IdentifiedSanityDocumentStub
2901
+ }
2902
+
2903
+ /** @public */
2904
+ export declare const requester: Requester
2905
+
2906
+ /** @internal */
2907
+ export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
2908
+ url?: string
2909
+ uri?: string
2910
+ canUseCdn?: boolean
2911
+ useCdn?: boolean
2912
+ tag?: string
2913
+ returnQuery?: boolean
2914
+ resultSourceMap?: boolean | 'withKeyArraySelector'
2915
+ perspective?: ClientPerspective
2916
+ lastLiveEventId?: string
2917
+ cacheMode?: 'noStale'
2918
+ }
2919
+
2920
+ /** @public */
2921
+ export declare interface RequestOptions {
2922
+ timeout?: number
2923
+ token?: string
2924
+ tag?: string
2925
+ headers?: Record<string, string>
2926
+ method?: string
2927
+ query?: Any
2928
+ body?: Any
2929
+ signal?: AbortSignal
2930
+ }
2931
+
2932
+ export {ResolveStudioUrl}
2933
+
2934
+ /** @public */
2935
+ export declare interface ResponseEvent<T = unknown> {
2936
+ type: 'response'
2937
+ body: T
2938
+ url: string
2939
+ method: string
2940
+ statusCode: number
2941
+ statusMessage?: string
2942
+ headers: Record<string, string>
2943
+ }
2944
+
2945
+ /** @public */
2946
+ export declare interface ResponseQueryOptions extends RequestOptions {
2947
+ perspective?: ClientPerspective
2948
+ resultSourceMap?: boolean | 'withKeyArraySelector'
2949
+ returnQuery?: boolean
2950
+ useCdn?: boolean
2951
+ stega?: boolean | StegaConfig
2952
+ cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
2953
+ next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
2954
+ lastLiveEventId?: string | string[] | null
2955
+ /**
2956
+ * When set to `noStale`, APICDN will not return a cached response if the content is stale.
2957
+ * Tradeoff between latency and freshness of content.
2958
+ *
2959
+ * Only to be used with live content queries and when useCdn is true.
2960
+ */
2961
+ cacheMode?: 'noStale'
2962
+ }
2963
+
2964
+ /** @internal */
2965
+ export declare interface SanityAssetDocument extends SanityDocument {
2966
+ url: string
2967
+ path: string
2968
+ size: number
2969
+ assetId: string
2970
+ mimeType: string
2971
+ sha1hash: string
2972
+ extension: string
2973
+ uploadId?: string
2974
+ originalFilename?: string
2975
+ }
2976
+
2977
+ /** @public */
2978
+ export declare class SanityClient implements SanityClientType {
2979
+ #private
2980
+ assets: AssetsClient
2981
+ datasets: DatasetsClient
2982
+ live: LiveClient
2983
+ projects: ProjectsClient
2984
+ users: UsersClient
2985
+ /**
2986
+ * Observable version of the Sanity client, with the same configuration as the promise-based one
2987
+ */
2988
+ observable: ObservableSanityClient
2989
+ listen: typeof _listen
2990
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
2991
+ /**
2992
+ * Clone the client - returns a new instance
2993
+ */
2994
+ clone(): SanityClient
2995
+ /**
2996
+ * Returns the current client configuration
2997
+ */
2998
+ config(): InitializedClientConfig
2999
+ /**
3000
+ * Reconfigure the client. Note that this _mutates_ the current client.
3001
+ */
3002
+ config(newConfig?: Partial<ClientConfig>): this
3003
+ /**
3004
+ * Clone the client with a new (partial) configuration.
3005
+ *
3006
+ * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3007
+ */
3008
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3009
+ /**
3010
+ * Perform a GROQ-query against the configured dataset.
3011
+ *
3012
+ * @param query - GROQ-query to perform
3013
+ */
3014
+ fetch<
3015
+ R = Any,
3016
+ Q extends QueryWithoutParams = QueryWithoutParams,
3017
+ const G extends string = string,
3018
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3019
+ /**
3020
+ * Perform a GROQ-query against the configured dataset.
3021
+ *
3022
+ * @param query - GROQ-query to perform
3023
+ * @param params - Optional query parameters
3024
+ * @param options - Optional request options
3025
+ */
3026
+ fetch<
3027
+ R = Any,
3028
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
3029
+ const G extends string = string,
3030
+ >(
3031
+ query: G,
3032
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3033
+ options?: FilteredResponseQueryOptions,
3034
+ ): Promise<ClientReturn<G, R>>
3035
+ /**
3036
+ * Perform a GROQ-query against the configured dataset.
3037
+ *
3038
+ * @param query - GROQ-query to perform
3039
+ * @param params - Optional query parameters
3040
+ * @param options - Request options
3041
+ */
3042
+ fetch<
3043
+ R = Any,
3044
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
3045
+ const G extends string = string,
3046
+ >(
3047
+ query: G,
3048
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3049
+ options: UnfilteredResponseQueryOptions,
3050
+ ): Promise<RawQueryResponse<ClientReturn<G, R>>>
3051
+ /**
3052
+ * Perform a GROQ-query against the configured dataset.
3053
+ *
3054
+ * @param query - GROQ-query to perform
3055
+ * @param params - Optional query parameters
3056
+ * @param options - Request options
3057
+ */
3058
+ fetch<
3059
+ R = Any,
3060
+ Q extends QueryWithoutParams | QueryParams = QueryParams,
3061
+ const G extends string = string,
3062
+ >(
3063
+ query: G,
3064
+ params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3065
+ options: UnfilteredResponseWithoutQuery,
3066
+ ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
3067
+ /**
3068
+ * Fetch a single document with the given ID.
3069
+ *
3070
+ * @param id - Document ID to fetch
3071
+ * @param options - Request options
3072
+ */
3073
+ getDocument<R extends Record<string, Any> = Record<string, Any>>(
3074
+ id: string,
3075
+ options?: {
3076
+ signal?: AbortSignal
3077
+ tag?: string
3078
+ },
3079
+ ): Promise<SanityDocument<R> | undefined>
3080
+ /**
3081
+ * Fetch multiple documents in one request.
3082
+ * Should be used sparingly - performing a query is usually a better option.
3083
+ * The order/position of documents is preserved based on the original array of IDs.
3084
+ * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
3085
+ *
3086
+ * @param ids - Document IDs to fetch
3087
+ * @param options - Request options
3088
+ */
3089
+ getDocuments<R extends Record<string, Any> = Record<string, Any>>(
3090
+ ids: string[],
3091
+ options?: {
3092
+ signal?: AbortSignal
3093
+ tag?: string
3094
+ },
3095
+ ): Promise<(SanityDocument<R> | null)[]>
3096
+ /**
3097
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3098
+ * Returns a promise that resolves to the created document.
3099
+ *
3100
+ * @param document - Document to create
3101
+ * @param options - Mutation options
3102
+ */
3103
+ create<R extends Record<string, Any> = Record<string, Any>>(
3104
+ document: SanityDocumentStub<R>,
3105
+ options: FirstDocumentMutationOptions,
3106
+ ): Promise<SanityDocument<R>>
3107
+ /**
3108
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3109
+ * Returns a promise that resolves to an array containing the created document.
3110
+ *
3111
+ * @param document - Document to create
3112
+ * @param options - Mutation options
3113
+ */
3114
+ create<R extends Record<string, Any> = Record<string, Any>>(
3115
+ document: SanityDocumentStub<R>,
3116
+ options: AllDocumentsMutationOptions,
3117
+ ): Promise<SanityDocument<R>[]>
3118
+ /**
3119
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3120
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3121
+ *
3122
+ * @param document - Document to create
3123
+ * @param options - Mutation options
3124
+ */
3125
+ create<R extends Record<string, Any> = Record<string, Any>>(
3126
+ document: SanityDocumentStub<R>,
3127
+ options: FirstDocumentIdMutationOptions,
3128
+ ): Promise<SingleMutationResult>
3129
+ /**
3130
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3131
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3132
+ *
3133
+ * @param document - Document to create
3134
+ * @param options - Mutation options
3135
+ */
3136
+ create<R extends Record<string, Any> = Record<string, Any>>(
3137
+ document: SanityDocumentStub<R>,
3138
+ options: AllDocumentIdsMutationOptions,
3139
+ ): Promise<MultipleMutationResult>
3140
+ /**
3141
+ * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3142
+ * Returns a promise that resolves to the created document.
3143
+ *
3144
+ * @param document - Document to create
3145
+ * @param options - Mutation options
3146
+ */
3147
+ create<R extends Record<string, Any> = Record<string, Any>>(
3148
+ document: SanityDocumentStub<R>,
3149
+ options?: BaseMutationOptions,
3150
+ ): Promise<SanityDocument<R>>
3151
+ /**
3152
+ * Create a document if no document with the same ID already exists.
3153
+ * Returns a promise that resolves to the created document.
3154
+ *
3155
+ * @param document - Document to create
3156
+ * @param options - Mutation options
3157
+ */
3158
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3159
+ document: IdentifiedSanityDocumentStub<R>,
3160
+ options: FirstDocumentMutationOptions,
3161
+ ): Promise<SanityDocument<R>>
3162
+ /**
3163
+ * Create a document if no document with the same ID already exists.
3164
+ * Returns a promise that resolves to an array containing the created document.
3165
+ *
3166
+ * @param document - Document to create
3167
+ * @param options - Mutation options
3168
+ */
3169
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3170
+ document: IdentifiedSanityDocumentStub<R>,
3171
+ options: AllDocumentsMutationOptions,
3172
+ ): Promise<SanityDocument<R>[]>
3173
+ /**
3174
+ * Create a document if no document with the same ID already exists.
3175
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3176
+ *
3177
+ * @param document - Document to create
3178
+ * @param options - Mutation options
3179
+ */
3180
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3181
+ document: IdentifiedSanityDocumentStub<R>,
3182
+ options: FirstDocumentIdMutationOptions,
3183
+ ): Promise<SingleMutationResult>
3184
+ /**
3185
+ * Create a document if no document with the same ID already exists.
3186
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3187
+ *
3188
+ * @param document - Document to create
3189
+ * @param options - Mutation options
3190
+ */
3191
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3192
+ document: IdentifiedSanityDocumentStub<R>,
3193
+ options: AllDocumentIdsMutationOptions,
3194
+ ): Promise<MultipleMutationResult>
3195
+ /**
3196
+ * Create a document if no document with the same ID already exists.
3197
+ * Returns a promise that resolves to the created document.
3198
+ *
3199
+ * @param document - Document to create
3200
+ * @param options - Mutation options
3201
+ */
3202
+ createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3203
+ document: IdentifiedSanityDocumentStub<R>,
3204
+ options?: BaseMutationOptions,
3205
+ ): Promise<SanityDocument<R>>
3206
+ /**
3207
+ * Create a document if it does not exist, or replace a document with the same document ID
3208
+ * Returns a promise that resolves to the created document.
3209
+ *
3210
+ * @param document - Document to either create or replace
3211
+ * @param options - Mutation options
3212
+ */
3213
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3214
+ document: IdentifiedSanityDocumentStub<R>,
3215
+ options: FirstDocumentMutationOptions,
3216
+ ): Promise<SanityDocument<R>>
3217
+ /**
3218
+ * Create a document if it does not exist, or replace a document with the same document ID
3219
+ * Returns a promise that resolves to an array containing the created document.
3220
+ *
3221
+ * @param document - Document to either create or replace
3222
+ * @param options - Mutation options
3223
+ */
3224
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3225
+ document: IdentifiedSanityDocumentStub<R>,
3226
+ options: AllDocumentsMutationOptions,
3227
+ ): Promise<SanityDocument<R>[]>
3228
+ /**
3229
+ * Create a document if it does not exist, or replace a document with the same document ID
3230
+ * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3231
+ *
3232
+ * @param document - Document to either create or replace
3233
+ * @param options - Mutation options
3234
+ */
3235
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3236
+ document: IdentifiedSanityDocumentStub<R>,
3237
+ options: FirstDocumentIdMutationOptions,
3238
+ ): Promise<SingleMutationResult>
3239
+ /**
3240
+ * Create a document if it does not exist, or replace a document with the same document ID
3241
+ * Returns a promise that resolves to a mutation result object containing the created document ID.
3242
+ *
3243
+ * @param document - Document to either create or replace
3244
+ * @param options - Mutation options
3245
+ */
3246
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3247
+ document: IdentifiedSanityDocumentStub<R>,
3248
+ options: AllDocumentIdsMutationOptions,
3249
+ ): Promise<MultipleMutationResult>
3250
+ /**
3251
+ * Create a document if it does not exist, or replace a document with the same document ID
3252
+ * Returns a promise that resolves to the created document.
3253
+ *
3254
+ * @param document - Document to either create or replace
3255
+ * @param options - Mutation options
3256
+ */
3257
+ createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3258
+ document: IdentifiedSanityDocumentStub<R>,
3259
+ options?: BaseMutationOptions,
3260
+ ): Promise<SanityDocument<R>>
3261
+ /**
3262
+ * Deletes a document with the given document ID.
3263
+ * Returns a promise that resolves to the deleted document.
3264
+ *
3265
+ * @param id - Document ID to delete
3266
+ * @param options - Options for the mutation
3267
+ */
3268
+ delete<R extends Record<string, Any> = Record<string, Any>>(
3269
+ id: string,
3270
+ options: FirstDocumentMutationOptions,
3271
+ ): Promise<SanityDocument<R>>
3272
+ /**
3273
+ * Deletes a document with the given document ID.
3274
+ * Returns a promise that resolves to an array containing the deleted document.
3275
+ *
3276
+ * @param id - Document ID to delete
3277
+ * @param options - Options for the mutation
3278
+ */
3279
+ delete<R extends Record<string, Any> = Record<string, Any>>(
3280
+ id: string,
3281
+ options: AllDocumentsMutationOptions,
3282
+ ): Promise<SanityDocument<R>[]>
3283
+ /**
3284
+ * Deletes a document with the given document ID.
3285
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
2061
3286
  *
2062
- * @param options - Options for the mutation operation
3287
+ * @param id - Document ID to delete
3288
+ * @param options - Options for the mutation
2063
3289
  */
2064
- commit<R extends Record<string, Any> = Record<string, Any>>(
3290
+ delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3291
+ /**
3292
+ * Deletes a document with the given document ID.
3293
+ * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3294
+ *
3295
+ * @param id - Document ID to delete
3296
+ * @param options - Options for the mutation
3297
+ */
3298
+ delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3299
+ /**
3300
+ * Deletes a document with the given document ID.
3301
+ * Returns a promise that resolves to the deleted document.
3302
+ *
3303
+ * @param id - Document ID to delete
3304
+ * @param options - Options for the mutation
3305
+ */
3306
+ delete<R extends Record<string, Any> = Record<string, Any>>(
3307
+ id: string,
3308
+ options?: BaseMutationOptions,
3309
+ ): Promise<SanityDocument<R>>
3310
+ /**
3311
+ * Deletes one or more documents matching the given query or document ID.
3312
+ * Returns a promise that resolves to first deleted document.
3313
+ *
3314
+ * @param selection - An object with either an `id` or `query` key defining what to delete
3315
+ * @param options - Options for the mutation
3316
+ */
3317
+ delete<R extends Record<string, Any> = Record<string, Any>>(
3318
+ selection: MutationSelection,
3319
+ options: FirstDocumentMutationOptions,
3320
+ ): Promise<SanityDocument<R>>
3321
+ /**
3322
+ * Deletes one or more documents matching the given query or document ID.
3323
+ * Returns a promise that resolves to an array containing the deleted documents.
3324
+ *
3325
+ * @param selection - An object with either an `id` or `query` key defining what to delete
3326
+ * @param options - Options for the mutation
3327
+ */
3328
+ delete<R extends Record<string, Any> = Record<string, Any>>(
3329
+ selection: MutationSelection,
2065
3330
  options: AllDocumentsMutationOptions,
2066
3331
  ): Promise<SanityDocument<R>[]>
2067
3332
  /**
2068
- * Commit the patch, returning a promise that resolves to a mutation result object
3333
+ * Deletes one or more documents matching the given query or document ID.
3334
+ * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
2069
3335
  *
2070
- * @param options - Options for the mutation operation
3336
+ * @param selection - An object with either an `id` or `query` key defining what to delete
3337
+ * @param options - Options for the mutation
2071
3338
  */
2072
- commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3339
+ delete(
3340
+ selection: MutationSelection,
3341
+ options: FirstDocumentIdMutationOptions,
3342
+ ): Promise<SingleMutationResult>
2073
3343
  /**
2074
- * Commit the patch, returning a promise that resolves to a mutation result object
3344
+ * Deletes one or more documents matching the given query or document ID.
3345
+ * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
2075
3346
  *
2076
- * @param options - Options for the mutation operation
3347
+ * @param selection - An object with either an `id` or `query` key defining what to delete
3348
+ * @param options - Options for the mutation
2077
3349
  */
2078
- commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3350
+ delete(
3351
+ selection: MutationSelection,
3352
+ options: AllDocumentIdsMutationOptions,
3353
+ ): Promise<MultipleMutationResult>
2079
3354
  /**
2080
- * Commit the patch, returning a promise that resolves to the first patched document
3355
+ * Deletes one or more documents matching the given query or document ID.
3356
+ * Returns a promise that resolves to first deleted document.
2081
3357
  *
2082
- * @param options - Options for the mutation operation
3358
+ * @param selection - An object with either an `id` or `query` key defining what to delete
3359
+ * @param options - Options for the mutation
2083
3360
  */
2084
- commit<R extends Record<string, Any> = Record<string, Any>>(
3361
+ delete<R extends Record<string, Any> = Record<string, Any>>(
3362
+ selection: MutationSelection,
2085
3363
  options?: BaseMutationOptions,
2086
3364
  ): Promise<SanityDocument<R>>
2087
- }
2088
-
2089
- /** @public */
2090
- export declare type PatchBuilder = (patch: Patch) => Patch
2091
-
2092
- /** @internal */
2093
- export declare type PatchMutationOperation = PatchOperations & MutationSelection
2094
-
2095
- /** @internal */
2096
- export declare interface PatchOperations {
2097
- set?: {
2098
- [key: string]: Any
2099
- }
2100
- setIfMissing?: {
2101
- [key: string]: Any
2102
- }
2103
- diffMatchPatch?: {
2104
- [key: string]: Any
2105
- }
2106
- unset?: string[]
2107
- inc?: {
2108
- [key: string]: number
2109
- }
2110
- dec?: {
2111
- [key: string]: number
2112
- }
2113
- insert?: InsertPatch
2114
- ifRevisionID?: string
2115
- }
2116
-
2117
- /** @internal */
2118
- export declare type PatchSelection = string | string[] | MutationSelection
2119
-
2120
- /** @public */
2121
- declare interface ProgressEvent_2 {
2122
- type: 'progress'
2123
- stage: 'upload' | 'download'
2124
- percent: number
2125
- total?: number
2126
- loaded?: number
2127
- lengthComputable: boolean
2128
- }
2129
- export {ProgressEvent_2 as ProgressEvent}
2130
-
2131
- /** @internal */
2132
- export declare class ProjectsClient {
2133
- #private
2134
- constructor(client: SanityClient, httpRequest: HttpRequest)
2135
3365
  /**
2136
- * Fetch a list of projects the authenticated user has access to.
3366
+ * Perform mutation operations against the configured dataset
3367
+ * Returns a promise that resolves to the first mutated document.
2137
3368
  *
2138
- * @param options - Options for the list request
2139
- * @param options.includeMembers - Whether to include members in the response (default: true)
3369
+ * @param operations - Mutation operations to execute
3370
+ * @param options - Mutation options
2140
3371
  */
2141
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2142
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
3372
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
3373
+ operations: Mutation<R>[] | Patch | Transaction,
3374
+ options: FirstDocumentMutationOptions,
3375
+ ): Promise<SanityDocument<R>>
2143
3376
  /**
2144
- * Fetch a project by project ID
3377
+ * Perform mutation operations against the configured dataset.
3378
+ * Returns a promise that resolves to an array of the mutated documents.
2145
3379
  *
2146
- * @param projectId - ID of the project to fetch
3380
+ * @param operations - Mutation operations to execute
3381
+ * @param options - Mutation options
2147
3382
  */
2148
- getById(projectId: string): Promise<SanityProject>
2149
- }
2150
-
2151
- /**
2152
- * Publishes a draft document.
2153
- * If a published version of the document already exists this is replaced by the current draft document.
2154
- * In either case the draft document is deleted.
2155
- * The optional revision id parameters can be used for optimistic locking to ensure
2156
- * that the draft and/or published versions of the document have not been changed by another client.
2157
- *
2158
- * @public
2159
- */
2160
- export declare type PublishAction = {
2161
- actionType: 'sanity.action.document.publish'
3383
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
3384
+ operations: Mutation<R>[] | Patch | Transaction,
3385
+ options: AllDocumentsMutationOptions,
3386
+ ): Promise<SanityDocument<R>[]>
2162
3387
  /**
2163
- * Draft document ID to publish
3388
+ * Perform mutation operations against the configured dataset
3389
+ * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
3390
+ *
3391
+ * @param operations - Mutation operations to execute
3392
+ * @param options - Mutation options
2164
3393
  */
2165
- draftId: string
3394
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
3395
+ operations: Mutation<R>[] | Patch | Transaction,
3396
+ options: FirstDocumentIdMutationOptions,
3397
+ ): Promise<SingleMutationResult>
2166
3398
  /**
2167
- * Draft revision ID to match
3399
+ * Perform mutation operations against the configured dataset
3400
+ * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
3401
+ *
3402
+ * @param operations - Mutation operations to execute
3403
+ * @param options - Mutation options
3404
+ */
3405
+ mutate<R extends Record<string, Any>>(
3406
+ operations: Mutation<R>[] | Patch | Transaction,
3407
+ options: AllDocumentIdsMutationOptions,
3408
+ ): Promise<MultipleMutationResult>
3409
+ /**
3410
+ * Perform mutation operations against the configured dataset
3411
+ * Returns a promise that resolves to the first mutated document.
3412
+ *
3413
+ * @param operations - Mutation operations to execute
3414
+ * @param options - Mutation options
3415
+ */
3416
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
3417
+ operations: Mutation<R>[] | Patch | Transaction,
3418
+ options?: BaseMutationOptions,
3419
+ ): Promise<SanityDocument<R>>
3420
+ /**
3421
+ * Create a new buildable patch of operations to perform
3422
+ *
3423
+ * @param documentId - Document ID to patch
3424
+ * @param operations - Optional object of patch operations to initialize the patch instance with
3425
+ * @returns Patch instance - call `.commit()` to perform the operations defined
3426
+ */
3427
+ patch(documentId: string, operations?: PatchOperations): Patch
3428
+ /**
3429
+ * Create a new buildable patch of operations to perform
3430
+ *
3431
+ * @param documentIds - Array of document IDs to patch
3432
+ * @param operations - Optional object of patch operations to initialize the patch instance with
3433
+ * @returns Patch instance - call `.commit()` to perform the operations defined
3434
+ */
3435
+ patch(documentIds: string[], operations?: PatchOperations): Patch
3436
+ /**
3437
+ * Create a new buildable patch of operations to perform
3438
+ *
3439
+ * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
3440
+ * @param operations - Optional object of patch operations to initialize the patch instance with
3441
+ * @returns Patch instance - call `.commit()` to perform the operations defined
3442
+ */
3443
+ patch(selection: MutationSelection, operations?: PatchOperations): Patch
3444
+ /**
3445
+ * Create a new transaction of mutations
3446
+ *
3447
+ * @param operations - Optional array of mutation operations to initialize the transaction instance with
3448
+ */
3449
+ transaction<R extends Record<string, Any> = Record<string, Any>>(
3450
+ operations?: Mutation<R>[],
3451
+ ): Transaction
3452
+ /**
3453
+ * Perform action operations against the configured dataset
3454
+ * Returns a promise that resolves to the transaction result
3455
+ *
3456
+ * @param operations - Action operation(s) to execute
3457
+ * @param options - Action options
3458
+ */
3459
+ action(
3460
+ operations: Action | Action[],
3461
+ options?: BaseActionOptions,
3462
+ ): Promise<SingleActionResult | MultipleActionResult>
3463
+ /**
3464
+ * Perform a request against the Sanity API
3465
+ * NOTE: Only use this for Sanity API endpoints, not for your own APIs!
3466
+ *
3467
+ * @param options - Request options
3468
+ * @returns Promise resolving to the response body
3469
+ */
3470
+ request<R = Any>(options: RawRequestOptions): Promise<R>
3471
+ /**
3472
+ * Perform an HTTP request a `/data` sub-endpoint
3473
+ * NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
3474
+ *
3475
+ * @deprecated - Use `request()` or your own HTTP library instead
3476
+ * @param endpoint - Endpoint to hit (mutate, query etc)
3477
+ * @param body - Request body
3478
+ * @param options - Request options
3479
+ * @internal
2168
3480
  */
2169
- ifDraftRevisionId?: string
3481
+ dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
2170
3482
  /**
2171
- * Published document ID to replace
3483
+ * Get a Sanity API URL for the URI provided
3484
+ *
3485
+ * @param uri - URI/path to build URL for
3486
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
2172
3487
  */
2173
- publishedId: string
3488
+ getUrl(uri: string, canUseCdn?: boolean): string
2174
3489
  /**
2175
- * Published revision ID to match
3490
+ * Get a Sanity API URL for the data operation and path provided
3491
+ *
3492
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3493
+ * @param path - Path to append after the operation
2176
3494
  */
2177
- ifPublishedRevisionId?: string
2178
- }
2179
-
2180
- /** @public */
2181
- export declare type QueryOptions =
2182
- | FilteredResponseQueryOptions
2183
- | UnfilteredResponseQueryOptions
2184
- | UnfilteredResponseWithoutQuery
2185
-
2186
- /** @public */
2187
- export declare interface QueryParams {
2188
- [key: string]: any
2189
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2190
- body?: never
2191
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2192
- cache?: 'next' extends keyof RequestInit ? never : any
2193
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2194
- filterResponse?: never
2195
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2196
- headers?: never
2197
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2198
- method?: never
2199
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2200
- next?: 'next' extends keyof RequestInit ? never : any
2201
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2202
- perspective?: never
2203
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2204
- query?: never
2205
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2206
- resultSourceMap?: never
2207
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2208
- returnQuery?: never
2209
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2210
- signal?: never
2211
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2212
- stega?: never
2213
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2214
- tag?: never
2215
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2216
- timeout?: never
2217
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2218
- token?: never
2219
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2220
- useCdn?: never
2221
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2222
- lastLiveEventId?: never
2223
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2224
- cacheMode?: never
2225
- }
2226
-
2227
- /**
2228
- * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
2229
- * @public
2230
- */
2231
- export declare type QueryWithoutParams = Record<string, never> | undefined
2232
-
2233
- /** @public */
2234
- export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
2235
-
2236
- /** @public */
2237
- export declare interface RawQueryResponse<R> {
2238
- query: string
2239
- ms: number
2240
- result: R
2241
- resultSourceMap?: ContentSourceMap
2242
- /** Requires `apiVersion` to be `2021-03-25` or later. */
2243
- syncTags?: SyncTag[]
2244
- }
2245
-
2246
- /** @internal */
2247
- export declare interface RawRequestOptions {
2248
- url?: string
2249
- uri?: string
2250
- method?: string
2251
- token?: string
2252
- json?: boolean
2253
- tag?: string
2254
- useGlobalApi?: boolean
2255
- withCredentials?: boolean
2256
- query?: {
2257
- [key: string]: string | string[]
2258
- }
2259
- headers?: {
2260
- [key: string]: string
2261
- }
2262
- timeout?: number
2263
- proxy?: string
2264
- body?: Any
2265
- maxRedirects?: number
2266
- signal?: AbortSignal
2267
- }
2268
-
2269
- /**
2270
- * The listener has been disconnected, and a reconnect attempt is scheduled.
2271
- *
2272
- * @public
2273
- */
2274
- export declare type ReconnectEvent = {
2275
- type: 'reconnect'
3495
+ getDataUrl(operation: string, path?: string): string
2276
3496
  }
2277
3497
 
2278
3498
  /**
2279
- * @public
2280
- * @deprecated The `r`-prefix is not required, use `string` instead
2281
- */
2282
- export declare type ReleaseId = `r${string}`
2283
-
2284
- /**
2285
- * Replaces an existing draft document.
2286
- * At least one of the draft or published versions of the document must exist.
2287
- *
2288
- * @public
3499
+ * Shared base type for the `SanityClient` and `ObservableSanityClient` classes.
3500
+ * TODO: refactor the Promise and Observable differences to use generics so we no longer suffer from all this duplication in TS docs
2289
3501
  */
2290
- export declare type ReplaceDraftAction = {
2291
- actionType: 'sanity.action.document.replaceDraft'
2292
- /**
2293
- * Published document ID to create draft from, if draft does not exist
2294
- */
2295
- publishedId: string
3502
+ declare interface SanityClientBase {
3503
+ live: LiveClient
3504
+ listen: typeof _listen
2296
3505
  /**
2297
- * Document to create if it does not already exist. Requires `_id` and `_type` properties.
3506
+ * Get a Sanity API URL for the URI provided
3507
+ *
3508
+ * @param uri - URI/path to build URL for
3509
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
2298
3510
  */
2299
- attributes: IdentifiedSanityDocumentStub
2300
- }
2301
-
2302
- /** @public */
2303
- export declare const requester: Requester
2304
-
2305
- /** @internal */
2306
- export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
2307
- url?: string
2308
- uri?: string
2309
- canUseCdn?: boolean
2310
- useCdn?: boolean
2311
- tag?: string
2312
- returnQuery?: boolean
2313
- resultSourceMap?: boolean | 'withKeyArraySelector'
2314
- perspective?: ClientPerspective
2315
- lastLiveEventId?: string
2316
- cacheMode?: 'noStale'
2317
- }
2318
-
2319
- /** @public */
2320
- export declare interface RequestOptions {
2321
- timeout?: number
2322
- token?: string
2323
- tag?: string
2324
- headers?: Record<string, string>
2325
- method?: string
2326
- query?: Any
2327
- body?: Any
2328
- signal?: AbortSignal
2329
- }
2330
-
2331
- export {ResolveStudioUrl}
2332
-
2333
- /** @public */
2334
- export declare interface ResponseEvent<T = unknown> {
2335
- type: 'response'
2336
- body: T
2337
- url: string
2338
- method: string
2339
- statusCode: number
2340
- statusMessage?: string
2341
- headers: Record<string, string>
2342
- }
2343
-
2344
- /** @public */
2345
- export declare interface ResponseQueryOptions extends RequestOptions {
2346
- perspective?: ClientPerspective
2347
- resultSourceMap?: boolean | 'withKeyArraySelector'
2348
- returnQuery?: boolean
2349
- useCdn?: boolean
2350
- stega?: boolean | StegaConfig
2351
- cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
2352
- next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
2353
- lastLiveEventId?: string | string[] | null
3511
+ getUrl(uri: string, canUseCdn?: boolean): string
2354
3512
  /**
2355
- * When set to `noStale`, APICDN will not return a cached response if the content is stale.
2356
- * Tradeoff between latency and freshness of content.
3513
+ * Get a Sanity API URL for the data operation and path provided
2357
3514
  *
2358
- * Only to be used with live content queries and when useCdn is true.
3515
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3516
+ * @param path - Path to append after the operation
2359
3517
  */
2360
- cacheMode?: 'noStale'
2361
- }
2362
-
2363
- /** @internal */
2364
- export declare interface SanityAssetDocument extends SanityDocument {
2365
- url: string
2366
- path: string
2367
- size: number
2368
- assetId: string
2369
- mimeType: string
2370
- sha1hash: string
2371
- extension: string
2372
- uploadId?: string
2373
- originalFilename?: string
3518
+ getDataUrl(operation: string, path?: string): string
2374
3519
  }
2375
3520
 
2376
- /** @public */
2377
- export declare class SanityClient {
2378
- #private
3521
+ /**
3522
+ * The interface implemented by the `SanityClient` class.
3523
+ * When writing code that wants to take an instance of `SanityClient` as input it's better to use this type,
3524
+ * as the `SanityClient` class has private properties and thus TypeScrict will consider the type incompatible
3525
+ * in cases where you might have multiple `@sanity/client` instances in your node_modules.
3526
+ * @public
3527
+ */
3528
+ export declare interface SanityClientType extends SanityClientBase {
2379
3529
  assets: AssetsClient
2380
3530
  datasets: DatasetsClient
2381
- live: LiveClient
2382
3531
  projects: ProjectsClient
2383
3532
  users: UsersClient
2384
3533
  /**
2385
3534
  * Observable version of the Sanity client, with the same configuration as the promise-based one
2386
3535
  */
2387
- observable: ObservableSanityClient
2388
- /**
2389
- * Instance properties
2390
- */
2391
- listen: typeof _listen
2392
- constructor(httpRequest: HttpRequest, config?: ClientConfig)
3536
+ observable: ObservableSanityClientType
2393
3537
  /**
2394
3538
  * Clone the client - returns a new instance
2395
3539
  */
2396
- clone(): SanityClient
3540
+ clone(): SanityClientType
2397
3541
  /**
2398
3542
  * Returns the current client configuration
2399
3543
  */
@@ -2401,13 +3545,13 @@ export declare class SanityClient {
2401
3545
  /**
2402
3546
  * Reconfigure the client. Note that this _mutates_ the current client.
2403
3547
  */
2404
- config(newConfig?: Partial<ClientConfig>): this
3548
+ config(newConfig?: Partial<ClientConfig>): SanityClientType
2405
3549
  /**
2406
3550
  * Clone the client with a new (partial) configuration.
2407
3551
  *
2408
3552
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
2409
3553
  */
2410
- withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3554
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClientType
2411
3555
  /**
2412
3556
  * Perform a GROQ-query against the configured dataset.
2413
3557
  *
@@ -2417,7 +3561,10 @@ export declare class SanityClient {
2417
3561
  R = Any,
2418
3562
  Q extends QueryWithoutParams = QueryWithoutParams,
2419
3563
  const G extends string = string,
2420
- >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3564
+ >(
3565
+ query: G,
3566
+ params?: Q | QueryWithoutParams,
3567
+ ): Promise<ClientReturn<G, R>>
2421
3568
  /**
2422
3569
  * Perform a GROQ-query against the configured dataset.
2423
3570
  *
@@ -2843,6 +3990,14 @@ export declare class SanityClient {
2843
3990
  * @returns Patch instance - call `.commit()` to perform the operations defined
2844
3991
  */
2845
3992
  patch(selection: MutationSelection, operations?: PatchOperations): Patch
3993
+ /**
3994
+ * Create a new buildable patch of operations to perform
3995
+ *
3996
+ * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
3997
+ * @param operations - Optional object of patch operations to initialize the patch instance with
3998
+ * @returns Patch instance - call `.commit()` to perform the operations defined
3999
+ */
4000
+ patch(selection: PatchSelection, operations?: PatchOperations): Patch
2846
4001
  /**
2847
4002
  * Create a new transaction of mutations
2848
4003
  *
@@ -2881,20 +4036,6 @@ export declare class SanityClient {
2881
4036
  * @internal
2882
4037
  */
2883
4038
  dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
2884
- /**
2885
- * Get a Sanity API URL for the URI provided
2886
- *
2887
- * @param uri - URI/path to build URL for
2888
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
2889
- */
2890
- getUrl(uri: string, canUseCdn?: boolean): string
2891
- /**
2892
- * Get a Sanity API URL for the data operation and path provided
2893
- *
2894
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
2895
- * @param path - Path to append after the operation
2896
- */
2897
- getDataUrl(operation: string, path?: string): string
2898
4039
  }
2899
4040
 
2900
4041
  /** @internal */