@sanity/client 7.0.1-canary.2 → 7.1.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.
package/dist/index.d.ts CHANGED
@@ -39,6 +39,262 @@ export declare interface ActionErrorItem {
39
39
  index: number
40
40
  }
41
41
 
42
+ /** @beta */
43
+ declare interface AgentActionAsync {
44
+ /**
45
+ * When async: true, requests responds with status 201 and \{_id\} as response body as soon as the request is validated.
46
+ * The instruction operation will carry on in the background.
47
+ *
48
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
49
+ *
50
+ * async: true is incompatible with noWrite, as async: true does not return the resulting document
51
+ */
52
+ async: true
53
+ }
54
+
55
+ /** @beta */
56
+ export declare type AgentActionParam =
57
+ | string
58
+ | ConstantAgentActionParam
59
+ | FieldAgentActionParam
60
+ | DocumentAgentActionParam
61
+ | GroqAgentActionParam
62
+
63
+ /** @beta */
64
+ export declare type AgentActionParams = Record<string, AgentActionParam>
65
+
66
+ /** @beta */
67
+ export declare type AgentActionPath = AgentActionPathSegment[]
68
+
69
+ /** @beta */
70
+ export declare type AgentActionPathSegment =
71
+ | string
72
+ | {
73
+ _key: string
74
+ }
75
+
76
+ /** @beta */
77
+ declare interface AgentActionRequestBase {
78
+ /** schemaId as reported by sanity deploy / sanity schema store */
79
+ schemaId: string
80
+ /**
81
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
82
+ *
83
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
84
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
85
+ *
86
+ * `conditionalPaths` param allows setting the default conditional value for
87
+ * `hidden` and `readOnly` to false,
88
+ * or individually set `hidden` and `readOnly` state for individual document paths.
89
+ *
90
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
91
+ * and cannot be changed via conditionalPaths
92
+ *
93
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
94
+ *
95
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
96
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
97
+ *
98
+ * @see GenerateRequestBase#target
99
+ */
100
+ conditionalPaths?: {
101
+ defaultReadOnly?: boolean
102
+ defaultHidden?: boolean
103
+ paths?: {
104
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
105
+ path: AgentActionPath
106
+ readOnly: boolean
107
+ hidden: boolean
108
+ }[]
109
+ }
110
+ /**
111
+ * When localeSettings is provided on the request, instruct can write to date and datetime fields.
112
+ * Otherwise, such fields will be ignored.
113
+ */
114
+ localeSettings?: {
115
+ /**
116
+ * A valid Unicode BCP 47 locale identifier used to interpret and format
117
+ * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
118
+ *
119
+ * This affects how phrases like "next Friday" or "in two weeks" are parsed,
120
+ * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
121
+ *
122
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
123
+ */
124
+ locale: string
125
+ /**
126
+ * A valid IANA time zone identifier used to resolve relative and absolute
127
+ * date expressions to a specific point in time. Examples include
128
+ * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
129
+ *
130
+ * This ensures phrases like "tomorrow at 9am" are interpreted correctly
131
+ * based on the user's local time.
132
+ *
133
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
134
+ */
135
+ timeZone: string
136
+ }
137
+ /**
138
+ * Controls how much variance the instructions will run with.
139
+ *
140
+ * Value must be in the range [0, 1] (inclusive).
141
+ *
142
+ * Defaults:
143
+ * - generate: 0.3
144
+ * - translate: 0
145
+ * - transform: 0
146
+ */
147
+ temperature?: number
148
+ }
149
+
150
+ /** @public */
151
+ declare class AgentActionsClient {
152
+ #private
153
+ constructor(client: SanityClient, httpRequest: HttpRequest)
154
+ /**
155
+ * Run an instruction to generate content in a target document.
156
+ * @param request - instruction request
157
+ */
158
+ generate<DocumentShape extends Record<string, Any>>(
159
+ request: GenerateInstruction<DocumentShape>,
160
+ ): Promise<
161
+ (typeof request)['async'] extends true
162
+ ? {
163
+ _id: string
164
+ }
165
+ : IdentifiedSanityDocumentStub & DocumentShape
166
+ >
167
+ /**
168
+ * Transform a target document based on a source.
169
+ * @param request - translation request
170
+ */
171
+ transform<DocumentShape extends Record<string, Any>>(
172
+ request: TransformDocument<DocumentShape>,
173
+ ): Promise<
174
+ (typeof request)['async'] extends true
175
+ ? {
176
+ _id: string
177
+ }
178
+ : IdentifiedSanityDocumentStub & DocumentShape
179
+ >
180
+ /**
181
+ * Translate a target document based on a source.
182
+ * @param request - translation request
183
+ */
184
+ translate<DocumentShape extends Record<string, Any>>(
185
+ request: TranslateDocument<DocumentShape>,
186
+ ): Promise<
187
+ (typeof request)['async'] extends true
188
+ ? {
189
+ _id: string
190
+ }
191
+ : IdentifiedSanityDocumentStub & DocumentShape
192
+ >
193
+ }
194
+
195
+ /** @beta */
196
+ declare interface AgentActionSync {
197
+ /**
198
+ * By default, noWrite: false.
199
+ * Write enabled operations will mutate the target document, and emit AI presence in the studio.
200
+ *
201
+ * When noWrite: true, the api will not mutate any documents nor emit presence.
202
+ * Ie, when true, no changes will be made to content-lake
203
+ *
204
+ * noWrite: true is incompatible with async: true,
205
+ * as noWrite implies that you will use the return value of the operation
206
+ */
207
+ noWrite?: boolean
208
+ /**
209
+ * When async: true, requests responds with status 201 and \{_id\} as response body as soon as the request is validated.
210
+ * The instruction operation will carry on in the background.
211
+ *
212
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
213
+ *
214
+ * async: true is incompatible with noWrite: true, as async: true does not return the resulting document
215
+ */
216
+ async?: false
217
+ }
218
+
219
+ /**
220
+ * @beta
221
+ */
222
+ export declare interface AgentActionTarget {
223
+ /**
224
+ * Root target path.
225
+ *
226
+ * Use this to have the instruction only affect a part of the document.
227
+ *
228
+ * To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
229
+ * and `types.exclude`.
230
+ *
231
+ * Example:
232
+ *
233
+ * `path: ['body', {_key: 'someKey'}, 'nestedObject']`
234
+ *
235
+ * Here, the instruction will only write to fields under the nestedObject.
236
+ *
237
+ * Default: [] = the document itself
238
+ *
239
+ * @see #AgentActionPathSegment
240
+ * @see #AgentActionPath
241
+ * */
242
+ path?: AgentActionPathSegment | AgentActionPath
243
+ /**
244
+ * maxPathDepth controls how deep into the schema from the target root the instruction will affect.
245
+ *
246
+ * Depth is based on path segments:
247
+ * - `title` has depth 1
248
+ * - `array[_key="no"].title` has depth 3
249
+ *
250
+ * Be careful not to set this too high in studios with recursive document schemas, as it could have
251
+ * negative impact on performance; both for runtime and quality of responses.
252
+ *
253
+ * Default: 4
254
+ */
255
+ maxPathDepth?: number
256
+ /**
257
+ * By default, all children up to `target.maxPathDepth` are included.
258
+ * Fields or array items not on the exclude list, are implicitly included.
259
+ */
260
+ exclude?: AgentActionPathSegment[]
261
+ /**
262
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
263
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
264
+ *
265
+ * `types.include` and `types.exclude` are mutually exclusive.
266
+ */
267
+ types?: AgentActionTypeConfig
268
+ }
269
+
270
+ /** @beta */
271
+ declare interface AgentActionTargetInclude {
272
+ path: AgentActionPathSegment | AgentActionPath
273
+ /**
274
+ * By default, all children up to `target.maxPathDepth` are included.
275
+ * Fields or array items not on the exclude list, are implicitly included.
276
+ */
277
+ exclude?: AgentActionPathSegment[]
278
+ /**
279
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
280
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
281
+ *
282
+ * `types.include` and `types.exclude` are mutually exclusive.
283
+ */
284
+ types?: AgentActionTypeConfig
285
+ }
286
+
287
+ /** @beta */
288
+ declare type AgentActionTypeConfig =
289
+ | {
290
+ include: string[]
291
+ exclude?: never
292
+ }
293
+ | {
294
+ exclude: string[]
295
+ include?: never
296
+ }
297
+
42
298
  /** @internal */
43
299
  export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
44
300
  returnFirst: false
@@ -75,7 +331,7 @@ export declare type AssetMetadataType =
75
331
  | 'none'
76
332
 
77
333
  /** @internal */
78
- export declare class AssetsClient implements AssetsClientType {
334
+ export declare class AssetsClient {
79
335
  #private
80
336
  constructor(client: SanityClient, httpRequest: HttpRequest)
81
337
  /**
@@ -116,46 +372,6 @@ export declare class AssetsClient implements AssetsClientType {
116
372
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
117
373
  }
118
374
 
119
- /** @internal */
120
- declare interface AssetsClientType {
121
- /**
122
- * Uploads a file asset to the configured dataset
123
- *
124
- * @param assetType - Asset type (file)
125
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
126
- * @param options - Options to use for the upload
127
- */
128
- upload(
129
- assetType: 'file',
130
- body: UploadBody,
131
- options?: UploadClientConfig,
132
- ): Promise<SanityAssetDocument>
133
- /**
134
- * Uploads an image asset to the configured dataset
135
- *
136
- * @param assetType - Asset type (image)
137
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
138
- * @param options - Options to use for the upload
139
- */
140
- upload(
141
- assetType: 'image',
142
- body: UploadBody,
143
- options?: UploadClientConfig,
144
- ): Promise<SanityImageAssetDocument>
145
- /**
146
- * Uploads a file or an image asset to the configured dataset
147
- *
148
- * @param assetType - Asset type (file/image)
149
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
150
- * @param options - Options to use for the upload
151
- */
152
- upload(
153
- assetType: 'file' | 'image',
154
- body: UploadBody,
155
- options?: UploadClientConfig,
156
- ): Promise<SanityAssetDocument | SanityImageAssetDocument>
157
- }
158
-
159
375
  /** @internal */
160
376
  export declare type AttributeSet = {
161
377
  [key: string]: Any
@@ -515,6 +731,43 @@ export declare class ConnectionFailedError extends Error {
515
731
  readonly name = 'ConnectionFailedError'
516
732
  }
517
733
 
734
+ /**
735
+ * Include a string in the instruction: do not have to escape $ signs in the string.
736
+ *
737
+ * ```ts
738
+ * client.agent.action.generate({
739
+ * schemaId,
740
+ * documentId,
741
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
742
+ * instructionParams: {
743
+ * topic: {
744
+ * type: 'constant',
745
+ * value: 'Grapefruit'
746
+ * },
747
+ * },
748
+ * })
749
+ * ```
750
+ *
751
+ * `type: 'constant'` can also be provided directly as a string, as a shorthand:
752
+ *
753
+ * ```ts
754
+ * client.agent.action.generate({
755
+ * schemaId,
756
+ * documentId,
757
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
758
+ * instructionParams: {
759
+ * topic: 'Grapefruit'
760
+ * },
761
+ * })
762
+ * ```
763
+ *
764
+ * @beta
765
+ * */
766
+ export declare interface ConstantAgentActionParam {
767
+ type: 'constant'
768
+ value: string
769
+ }
770
+
518
771
  /** @public */
519
772
  export declare interface ContentSourceMap {
520
773
  mappings: ContentSourceMapMappings
@@ -657,7 +910,7 @@ export declare type DatasetResponse = {
657
910
  }
658
911
 
659
912
  /** @internal */
660
- export declare class DatasetsClient implements DatasetsClientType {
913
+ export declare class DatasetsClient {
661
914
  #private
662
915
  constructor(client: SanityClient, httpRequest: HttpRequest)
663
916
  /**
@@ -698,46 +951,6 @@ export declare class DatasetsClient implements DatasetsClientType {
698
951
  list(): Promise<DatasetsResponse>
699
952
  }
700
953
 
701
- /** @internal */
702
- declare interface DatasetsClientType {
703
- /**
704
- * Create a new dataset with the given name
705
- *
706
- * @param name - Name of the dataset to create
707
- * @param options - Options for the dataset
708
- */
709
- create(
710
- name: string,
711
- options?: {
712
- aclMode?: DatasetAclMode
713
- },
714
- ): Promise<DatasetResponse>
715
- /**
716
- * Edit a dataset with the given name
717
- *
718
- * @param name - Name of the dataset to edit
719
- * @param options - New options for the dataset
720
- */
721
- edit(
722
- name: string,
723
- options?: {
724
- aclMode?: DatasetAclMode
725
- },
726
- ): Promise<DatasetResponse>
727
- /**
728
- * Delete a dataset with the given name
729
- *
730
- * @param name - Name of the dataset to delete
731
- */
732
- delete(name: string): Promise<{
733
- deleted: true
734
- }>
735
- /**
736
- * Fetch a list of datasets for the configured project
737
- */
738
- list(): Promise<DatasetsResponse>
739
- }
740
-
741
954
  /** @public */
742
955
  export declare type DatasetsResponse = {
743
956
  name: string
@@ -829,6 +1042,34 @@ export declare type DisconnectEvent = {
829
1042
  reason: string
830
1043
  }
831
1044
 
1045
+ /**
1046
+ *
1047
+ * Includes a LLM-friendly version of the document in the instruction
1048
+ *
1049
+ * ```ts
1050
+ * client.agent.action.generate({
1051
+ * schemaId,
1052
+ * documentId,
1053
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
1054
+ * instructionParams: {
1055
+ * document: {
1056
+ * type: 'document',
1057
+ * },
1058
+ * },
1059
+ * target: {path: 'keywords' }
1060
+ * })
1061
+ * ```
1062
+ *
1063
+ * @beta
1064
+ * */
1065
+ export declare interface DocumentAgentActionParam {
1066
+ type: 'document'
1067
+ /**
1068
+ * If omitted, implicitly uses the documentId of the instruction target
1069
+ */
1070
+ documentId?: string
1071
+ }
1072
+
832
1073
  /**
833
1074
  * Modifies an existing draft document.
834
1075
  * It applies the given patch to the document referenced by draftId.
@@ -871,6 +1112,41 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
871
1112
  */
872
1113
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
873
1114
 
1115
+ /**
1116
+ *
1117
+ *
1118
+ * Includes a LLM-friendly version of the field value in the instruction
1119
+ *
1120
+ * ```ts
1121
+ * client.agent.action.generate({
1122
+ * schemaId,
1123
+ * documentId,
1124
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
1125
+ * instructionParams: {
1126
+ * pte: {
1127
+ * type: 'field',
1128
+ * path: ['pteField'],
1129
+ * },
1130
+ * },
1131
+ * target: {path: 'keywords' }
1132
+ * })
1133
+ *
1134
+ * ```
1135
+ *
1136
+ * @beta
1137
+ * */
1138
+ export declare interface FieldAgentActionParam {
1139
+ type: 'field'
1140
+ /**
1141
+ * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1142
+ */
1143
+ path: AgentActionPathSegment | AgentActionPath
1144
+ /**
1145
+ * If omitted, implicitly uses the documentId of the instruction target
1146
+ */
1147
+ documentId?: string
1148
+ }
1149
+
874
1150
  /** @public */
875
1151
  export declare type FilterDefault = (props: {
876
1152
  /**
@@ -937,6 +1213,274 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
937
1213
  returnDocuments?: true
938
1214
  }
939
1215
 
1216
+ /** @beta */
1217
+ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1218
+ | GenerateExistingDocumentRequest
1219
+ | GenerateTargetDocumentRequest<T>
1220
+ ) &
1221
+ GenerateRequestBase &
1222
+ AgentActionAsync
1223
+
1224
+ /**
1225
+ * Instruction for an existing document.
1226
+ * @beta
1227
+ */
1228
+ declare interface GenerateExistingDocumentRequest {
1229
+ documentId: string
1230
+ createDocument?: never
1231
+ }
1232
+
1233
+ /** @beta */
1234
+ export declare type GenerateInstruction<T extends Record<string, Any> = Record<string, Any>> =
1235
+ | GenerateSyncInstruction<T>
1236
+ | GenerateAsyncInstruction<T>
1237
+
1238
+ /** @beta */
1239
+ export declare type GenerateOperation = 'set' | 'append' | 'mixed'
1240
+
1241
+ /** @beta */
1242
+ declare interface GenerateRequestBase extends AgentActionRequestBase {
1243
+ /** schemaId as reported by sanity deploy / sanity schema store */
1244
+ schemaId: string
1245
+ /**
1246
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
1247
+ *
1248
+ * The LLM only has access to information in the instruction, plus the target schema.
1249
+ *
1250
+ * string template using $variable
1251
+ * */
1252
+ instruction: string
1253
+ /**
1254
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
1255
+ *
1256
+ * ### Examples
1257
+ *
1258
+ * #### Constant
1259
+ *
1260
+ * ##### Shorthand
1261
+ * ```ts
1262
+ * client.agent.action.generate({
1263
+ * schemaId,
1264
+ * documentId,
1265
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
1266
+ * instructionParams: {
1267
+ * topic: 'Grapefruit'
1268
+ * },
1269
+ * })
1270
+ * ```
1271
+ * ##### Object-form
1272
+ *
1273
+ * ```ts
1274
+ * client.agent.action.generate({
1275
+ * schemaId,
1276
+ * documentId,
1277
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
1278
+ * instructionParams: {
1279
+ * topic: {
1280
+ * type: 'constant',
1281
+ * value: 'Grapefruit'
1282
+ * },
1283
+ * },
1284
+ * })
1285
+ * ```
1286
+ * #### Field
1287
+ * ```ts
1288
+ * client.agent.action.generate({
1289
+ * schemaId,
1290
+ * documentId,
1291
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
1292
+ * instructionParams: {
1293
+ * pte: {
1294
+ * type: 'field',
1295
+ * path: ['pteField'],
1296
+ * },
1297
+ * },
1298
+ * target: {path: 'keywords' }
1299
+ * })
1300
+ * ```
1301
+ * #### Document
1302
+ * ```ts
1303
+ * client.agent.action.generate({
1304
+ * schemaId,
1305
+ * documentId,
1306
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
1307
+ * instructionParams: {
1308
+ * document: {
1309
+ * type: 'document',
1310
+ * },
1311
+ * },
1312
+ * target: {path: 'keywords' }
1313
+ * })
1314
+ * ```
1315
+ *
1316
+ * #### GROQ
1317
+ * ```ts
1318
+ * client.agent.action.generate({
1319
+ * schemaId,
1320
+ * documentId,
1321
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
1322
+ * instructionParams: {
1323
+ * list: {
1324
+ * type: 'groq',
1325
+ * query: '* [_type==$type].title',
1326
+ * params: {type: 'article'}
1327
+ * },
1328
+ * },
1329
+ * target: {path: 'title' }
1330
+ * })
1331
+ * ```
1332
+ * */
1333
+ instructionParams?: AgentActionParams
1334
+ /**
1335
+ * Target defines which parts of the document will be affected by the instruction.
1336
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
1337
+ *
1338
+ * Omitting target implies that the document itself is the root.
1339
+ *
1340
+ * Notes:
1341
+ * - instruction can only affect fields up to `maxPathDepth`
1342
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1343
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1344
+ *
1345
+ * @see AgentActionRequestBase#conditionalPaths
1346
+ */
1347
+ target?: GenerateTarget | GenerateTarget[]
1348
+ }
1349
+
1350
+ /** @beta */
1351
+ declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1352
+ | GenerateExistingDocumentRequest
1353
+ | GenerateTargetDocumentRequest<T>
1354
+ ) &
1355
+ GenerateRequestBase &
1356
+ AgentActionSync
1357
+
1358
+ /** @beta */
1359
+ export declare interface GenerateTarget extends AgentActionTarget {
1360
+ /**
1361
+ * Sets the default operation for all paths in the target.
1362
+ * Generate runs in `'mixed'` operation mode by default:
1363
+ * Changes are set in all non-array fields, and append to all array fields.
1364
+ *
1365
+ * ### Operation types
1366
+ * - `'set'` – an *overwriting* operation, and replaces the full field value.
1367
+ * - `'append'`:
1368
+ * – array fields: appends new items to the end of the array,
1369
+ * - string fields: '"existing content" "new content"'
1370
+ * - text fields: '"existing content"\\n"new content"'
1371
+ * - number fields: existing + new
1372
+ * - other field types not mentioned will set instead (dates, url)
1373
+ * - `'mixed'` – (default) sets non-array fields, and appends to array fields
1374
+ *
1375
+ * The default operation can be overridden on a per-path basis using `include`.
1376
+ *
1377
+ * Nested fields inherit the operation specified by their parent and falls back to the
1378
+ * top level target operation if not otherwise specified.
1379
+ *
1380
+ * Use `include` to change the `operation` of individual fields or items.
1381
+ *
1382
+ * #### Appending in the middle of arrays
1383
+ * `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
1384
+ *
1385
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
1386
+ * Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
1387
+ *
1388
+ * @see #AgentActionTargetInclude.operation
1389
+ * @see #include
1390
+ * @see #AgentActionTargetInclude.include
1391
+ */
1392
+ operation?: GenerateOperation
1393
+ /**
1394
+ * By default, all children up to `target.maxPathDepth` are included.
1395
+ *
1396
+ * When `include` is specified, only segments explicitly listed will be included.
1397
+ *
1398
+ * Fields or array items not on the include list, are implicitly excluded.
1399
+ */
1400
+ include?: (AgentActionPathSegment | GenerateTargetInclude)[]
1401
+ }
1402
+
1403
+ /** @beta */
1404
+ export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
1405
+ | {
1406
+ operation: 'edit'
1407
+ _id: string
1408
+ }
1409
+ | {
1410
+ operation: 'create'
1411
+ _id?: string
1412
+ _type: string
1413
+ initialValues?: T
1414
+ }
1415
+ | {
1416
+ operation: 'createIfNotExists'
1417
+ _id: string
1418
+ _type: string
1419
+ initialValues?: T
1420
+ }
1421
+ | {
1422
+ operation: 'createOrReplace'
1423
+ _id: string
1424
+ _type: string
1425
+ initialValues?: T
1426
+ }
1427
+
1428
+ /**
1429
+ * Instruction to create a new document
1430
+ * @beta
1431
+ */
1432
+ declare interface GenerateTargetDocumentRequest<
1433
+ T extends Record<string, Any> = Record<string, Any>,
1434
+ > {
1435
+ targetDocument: GenerateTargetDocument<T>
1436
+ documentId?: never
1437
+ }
1438
+
1439
+ /** @beta */
1440
+ export declare interface GenerateTargetInclude extends AgentActionTargetInclude {
1441
+ /**
1442
+ * Sets the operation for this path, and all its children.
1443
+ * This overrides any operation set parents or the root target.
1444
+ * @see #GenerateTarget.operation
1445
+ * @see #include
1446
+ */
1447
+ operation?: GenerateOperation
1448
+ /**
1449
+ * By default, all children up to `target.maxPathDepth` are included.
1450
+ *
1451
+ * When `include` is specified, only segments explicitly listed will be included.
1452
+ *
1453
+ * Fields or array items not on the include list, are implicitly excluded.
1454
+ */
1455
+ include?: (AgentActionPathSegment | GenerateTargetInclude)[]
1456
+ }
1457
+
1458
+ /**
1459
+ * Includes a LLM-friendly version of GROQ query result in the instruction
1460
+ *
1461
+ * ```ts
1462
+ * client.agent.action.generate({
1463
+ * schemaId,
1464
+ * documentId,
1465
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
1466
+ * instructionParams: {
1467
+ * list: {
1468
+ * type: 'groq',
1469
+ * query: '* [_type==$type].title',
1470
+ * params: {type: 'article'}
1471
+ * },
1472
+ * },
1473
+ * target: {path: 'title' }
1474
+ * })
1475
+ * ```
1476
+ * @beta
1477
+ * */
1478
+ export declare interface GroqAgentActionParam {
1479
+ type: 'groq'
1480
+ query: string
1481
+ params?: Record<string, string>
1482
+ }
1483
+
940
1484
  /** @public */
941
1485
  export declare type HttpRequest = {
942
1486
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1066,15 +1610,6 @@ export declare interface ListenOptions {
1066
1610
  * @defaultValue `false`
1067
1611
  */
1068
1612
  includePreviousRevision?: boolean
1069
- /**
1070
- * Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
1071
- * for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
1072
- * If you need events from drafts and versions, set this to `true`.
1073
- * Note: Keep in mind that additional document variants may be introduced in the future, so it's
1074
- * recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
1075
- * explicitly checking whether the event is for a draft or a version.
1076
- * @defaultValue `false`
1077
- */
1078
1613
  includeAllVersions?: boolean
1079
1614
  /**
1080
1615
  * Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
@@ -1369,62 +1904,55 @@ export declare type MutationSelectionQueryParams = {
1369
1904
  [key: string]: Any
1370
1905
  }
1371
1906
 
1372
- /** @internal */
1373
- export declare class ObservableAssetsClient implements ObservableAssetsClientType {
1907
+ /** @public */
1908
+ declare class ObservableAgentsActionClient {
1374
1909
  #private
1375
1910
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1376
1911
  /**
1377
- * Uploads a file asset to the configured dataset
1378
- *
1379
- * @param assetType - Asset type (file)
1380
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1381
- * @param options - Options to use for the upload
1912
+ * Run an instruction to generate content in a target document.
1913
+ * @param request - instruction request
1382
1914
  */
1383
- upload(
1384
- assetType: 'file',
1385
- body: UploadBody,
1386
- options?: UploadClientConfig,
1915
+ generate<DocumentShape extends Record<string, Any>>(
1916
+ request: GenerateInstruction<DocumentShape>,
1387
1917
  ): Observable<
1388
- HttpRequestEvent<{
1389
- document: SanityAssetDocument
1390
- }>
1918
+ (typeof request)['async'] extends true
1919
+ ? {
1920
+ _id: string
1921
+ }
1922
+ : IdentifiedSanityDocumentStub & DocumentShape
1391
1923
  >
1392
1924
  /**
1393
- * Uploads an image asset to the configured dataset
1394
- *
1395
- * @param assetType - Asset type (image)
1396
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1397
- * @param options - Options to use for the upload
1925
+ * Transform a target document based on a source.
1926
+ * @param request - translation request
1398
1927
  */
1399
- upload(
1400
- assetType: 'image',
1401
- body: UploadBody,
1402
- options?: UploadClientConfig,
1928
+ transform<DocumentShape extends Record<string, Any>>(
1929
+ request: TransformDocument<DocumentShape>,
1403
1930
  ): Observable<
1404
- HttpRequestEvent<{
1405
- document: SanityImageAssetDocument
1406
- }>
1931
+ (typeof request)['async'] extends true
1932
+ ? {
1933
+ _id: string
1934
+ }
1935
+ : IdentifiedSanityDocumentStub & DocumentShape
1407
1936
  >
1408
1937
  /**
1409
- * Uploads a file or an image asset to the configured dataset
1410
- *
1411
- * @param assetType - Asset type (file/image)
1412
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1413
- * @param options - Options to use for the upload
1938
+ * Translate a target document based on a source.
1939
+ * @param request - translation request
1414
1940
  */
1415
- upload(
1416
- assetType: 'file' | 'image',
1417
- body: UploadBody,
1418
- options?: UploadClientConfig,
1941
+ translate<DocumentShape extends Record<string, Any>>(
1942
+ request: TranslateDocument<DocumentShape>,
1419
1943
  ): Observable<
1420
- HttpRequestEvent<{
1421
- document: SanityAssetDocument | SanityImageAssetDocument
1422
- }>
1944
+ (typeof request)['async'] extends true
1945
+ ? {
1946
+ _id: string
1947
+ }
1948
+ : IdentifiedSanityDocumentStub & DocumentShape
1423
1949
  >
1424
1950
  }
1425
1951
 
1426
1952
  /** @internal */
1427
- declare interface ObservableAssetsClientType {
1953
+ export declare class ObservableAssetsClient {
1954
+ #private
1955
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1428
1956
  /**
1429
1957
  * Uploads a file asset to the configured dataset
1430
1958
  *
@@ -1476,7 +2004,7 @@ declare interface ObservableAssetsClientType {
1476
2004
  }
1477
2005
 
1478
2006
  /** @internal */
1479
- export declare class ObservableDatasetsClient implements ObservableDatasetsClientType {
2007
+ export declare class ObservableDatasetsClient {
1480
2008
  #private
1481
2009
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1482
2010
  /**
@@ -1517,46 +2045,6 @@ export declare class ObservableDatasetsClient implements ObservableDatasetsClien
1517
2045
  list(): Observable<DatasetsResponse>
1518
2046
  }
1519
2047
 
1520
- /** @internal */
1521
- declare interface ObservableDatasetsClientType {
1522
- /**
1523
- * Create a new dataset with the given name
1524
- *
1525
- * @param name - Name of the dataset to create
1526
- * @param options - Options for the dataset
1527
- */
1528
- create(
1529
- name: string,
1530
- options?: {
1531
- aclMode?: DatasetAclMode
1532
- },
1533
- ): Observable<DatasetResponse>
1534
- /**
1535
- * Edit a dataset with the given name
1536
- *
1537
- * @param name - Name of the dataset to edit
1538
- * @param options - New options for the dataset
1539
- */
1540
- edit(
1541
- name: string,
1542
- options?: {
1543
- aclMode?: DatasetAclMode
1544
- },
1545
- ): Observable<DatasetResponse>
1546
- /**
1547
- * Delete a dataset with the given name
1548
- *
1549
- * @param name - Name of the dataset to delete
1550
- */
1551
- delete(name: string): Observable<{
1552
- deleted: true
1553
- }>
1554
- /**
1555
- * Fetch a list of datasets for the configured project
1556
- */
1557
- list(): Observable<DatasetsResponse>
1558
- }
1559
-
1560
2048
  /** @public */
1561
2049
  export declare class ObservablePatch extends BasePatch {
1562
2050
  #private
@@ -1611,38 +2099,17 @@ export declare class ObservablePatch extends BasePatch {
1611
2099
  export declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
1612
2100
 
1613
2101
  /** @internal */
1614
- export declare class ObservableProjectsClient implements ObservableProjectsClientType {
2102
+ export declare class ObservableProjectsClient {
1615
2103
  #private
1616
2104
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1617
2105
  /**
1618
2106
  * Fetch a list of projects the authenticated user has access to.
1619
2107
  *
1620
2108
  * @param options - Options for the list request
1621
- * @param options.includeMembers - Whether to include members in the response (default: true)
1622
- */
1623
- list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1624
- list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
1625
- /**
1626
- * Fetch a project by project ID
1627
- *
1628
- * @param projectId - ID of the project to fetch
1629
- */
1630
- getById(projectId: string): Observable<SanityProject>
1631
- }
1632
-
1633
- /** @internal */
1634
- declare interface ObservableProjectsClientType {
1635
- /**
1636
- * Fetch a list of projects the authenticated user has access to.
1637
- *
1638
- * @param options - Options for the list request
1639
- * @param options.includeMembers - Whether to include members in the response (default: true)
2109
+ * - `includeMembers` - Whether to include members in the response (default: true)
1640
2110
  */
1641
2111
  list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1642
2112
  list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
1643
- list(options?: {
1644
- includeMembers?: boolean
1645
- }): Observable<SanityProject[] | Omit<SanityProject, 'members'>[]>
1646
2113
  /**
1647
2114
  * Fetch a project by project ID
1648
2115
  *
@@ -1652,13 +2119,19 @@ declare interface ObservableProjectsClientType {
1652
2119
  }
1653
2120
 
1654
2121
  /** @public */
1655
- export declare class ObservableSanityClient implements ObservableSanityClientType {
2122
+ export declare class ObservableSanityClient {
1656
2123
  #private
1657
2124
  assets: ObservableAssetsClient
1658
2125
  datasets: ObservableDatasetsClient
1659
2126
  live: LiveClient
1660
2127
  projects: ObservableProjectsClient
1661
2128
  users: ObservableUsersClient
2129
+ agent: {
2130
+ action: ObservableAgentsActionClient
2131
+ }
2132
+ /**
2133
+ * Instance properties
2134
+ */
1662
2135
  listen: typeof _listen
1663
2136
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1664
2137
  /**
@@ -1717,7 +2190,7 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
1717
2190
  Q extends QueryWithoutParams | QueryParams = QueryParams,
1718
2191
  const G extends string = string,
1719
2192
  >(
1720
- query: G,
2193
+ query: string,
1721
2194
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1722
2195
  options: UnfilteredResponseQueryOptions,
1723
2196
  ): Observable<RawQueryResponse<ClientReturn<G, R>>>
@@ -2152,1516 +2625,445 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
2152
2625
  getDataUrl(operation: string, path?: string): string
2153
2626
  }
2154
2627
 
2155
- /**
2156
- * The interface implemented by the `ObservableSanityClient` class.
2157
- * When writing code that wants to take an instance of `ObservableSanityClient` as input it's better to use this type,
2158
- * as the `ObservableSanityClient` class has private properties and thus TypeScrict will consider the type incompatible
2159
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
2160
- * @public
2161
- */
2162
- export declare interface ObservableSanityClientType extends SanityClientBase {
2163
- assets: ObservableAssetsClientType
2164
- datasets: ObservableDatasetsClientType
2165
- projects: ObservableProjectsClientType
2166
- users: ObservableUsersClientType
2628
+ /** @public */
2629
+ export declare class ObservableTransaction extends BaseTransaction {
2630
+ #private
2631
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2167
2632
  /**
2168
- * Clone the client - returns a new instance
2633
+ * Clones the transaction
2169
2634
  */
2170
- clone(): ObservableSanityClientType
2635
+ clone(): ObservableTransaction
2171
2636
  /**
2172
- * Returns the current client configuration
2637
+ * Commit the transaction, returning an observable that produces the first mutated document
2638
+ *
2639
+ * @param options - Options for the mutation operation
2173
2640
  */
2174
- config(): InitializedClientConfig
2641
+ commit<R extends Record<string, Any>>(
2642
+ options: TransactionFirstDocumentMutationOptions,
2643
+ ): Observable<SanityDocument<R>>
2175
2644
  /**
2176
- * Reconfigure the client. Note that this _mutates_ the current client.
2645
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
2646
+ *
2647
+ * @param options - Options for the mutation operation
2177
2648
  */
2178
- config(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
2649
+ commit<R extends Record<string, Any>>(
2650
+ options: TransactionAllDocumentsMutationOptions,
2651
+ ): Observable<SanityDocument<R>[]>
2179
2652
  /**
2180
- * Clone the client with a new (partial) configuration.
2653
+ * Commit the transaction, returning an observable that produces a mutation result object
2181
2654
  *
2182
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
2655
+ * @param options - Options for the mutation operation
2183
2656
  */
2184
- withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
2657
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2185
2658
  /**
2186
- * Perform a GROQ-query against the configured dataset.
2659
+ * Commit the transaction, returning an observable that produces a mutation result object
2187
2660
  *
2188
- * @param query - GROQ-query to perform
2661
+ * @param options - Options for the mutation operation
2189
2662
  */
2190
- fetch<
2191
- R = Any,
2192
- Q extends QueryWithoutParams = QueryWithoutParams,
2193
- const G extends string = string,
2194
- >(
2195
- query: G,
2196
- params?: Q | QueryWithoutParams,
2197
- ): Observable<ClientReturn<G, R>>
2663
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2198
2664
  /**
2199
- * Perform a GROQ-query against the configured dataset.
2665
+ * Commit the transaction, returning an observable that produces a mutation result object
2200
2666
  *
2201
- * @param query - GROQ-query to perform
2202
- * @param params - Optional query parameters
2203
- * @param options - Optional request options
2667
+ * @param options - Options for the mutation operation
2204
2668
  */
2205
- fetch<
2206
- R = Any,
2207
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2208
- const G extends string = string,
2209
- >(
2210
- query: G,
2211
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2212
- options?: FilteredResponseQueryOptions,
2213
- ): Observable<ClientReturn<G, R>>
2669
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2214
2670
  /**
2215
- * Perform a GROQ-query against the configured dataset.
2671
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2672
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2216
2673
  *
2217
- * @param query - GROQ-query to perform
2218
- * @param params - Optional query parameters
2219
- * @param options - Request options
2674
+ * @param documentId - Document ID to perform the patch operation on
2675
+ * @param patchOps - Operations to perform, or a builder function
2220
2676
  */
2221
- fetch<
2222
- R = Any,
2223
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2224
- const G extends string = string,
2225
- >(
2226
- query: G,
2227
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2228
- options: UnfilteredResponseQueryOptions,
2229
- ): Observable<RawQueryResponse<ClientReturn<G, R>>>
2677
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2230
2678
  /**
2231
- * Perform a GROQ-query against the configured dataset.
2679
+ * Adds the given patch instance to the transaction.
2680
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2232
2681
  *
2233
- * @param query - GROQ-query to perform
2234
- * @param params - Optional query parameters
2235
- * @param options - Request options
2682
+ * @param patch - ObservablePatch to execute
2236
2683
  */
2237
- fetch<
2238
- R = Any,
2239
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2240
- const G extends string = string,
2241
- >(
2242
- query: G,
2243
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2244
- options: UnfilteredResponseWithoutQuery,
2245
- ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
2684
+ patch(patch: ObservablePatch): this
2685
+ }
2686
+
2687
+ /** @public */
2688
+ export declare class ObservableUsersClient {
2689
+ #private
2690
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2246
2691
  /**
2247
- * Fetch a single document with the given ID.
2692
+ * Fetch a user by user ID
2248
2693
  *
2249
- * @param id - Document ID to fetch
2250
- * @param options - Request options
2694
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2251
2695
  */
2252
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
2253
- id: string,
2254
- options?: {
2255
- tag?: string
2256
- },
2257
- ): Observable<SanityDocument<R> | undefined>
2696
+ getById<T extends 'me' | string>(
2697
+ id: T,
2698
+ ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2699
+ }
2700
+
2701
+ /**
2702
+ * The listener connection has been established
2703
+ * note: it's usually a better option to use the 'welcome' event
2704
+ * @public
2705
+ */
2706
+ export declare type OpenEvent = {
2707
+ type: 'open'
2708
+ }
2709
+
2710
+ /** @public */
2711
+ export declare class Patch extends BasePatch {
2712
+ #private
2713
+ constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2258
2714
  /**
2259
- * Fetch multiple documents in one request.
2260
- * Should be used sparingly - performing a query is usually a better option.
2261
- * The order/position of documents is preserved based on the original array of IDs.
2262
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
2263
- *
2264
- * @param ids - Document IDs to fetch
2265
- * @param options - Request options
2715
+ * Clones the patch
2266
2716
  */
2267
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
2268
- ids: string[],
2269
- options?: {
2270
- tag?: string
2271
- },
2272
- ): Observable<(SanityDocument<R> | null)[]>
2717
+ clone(): Patch
2273
2718
  /**
2274
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2275
- * Returns an observable that resolves to the created document.
2719
+ * Commit the patch, returning a promise that resolves to the first patched document
2276
2720
  *
2277
- * @param document - Document to create
2278
- * @param options - Mutation options
2721
+ * @param options - Options for the mutation operation
2279
2722
  */
2280
- create<R extends Record<string, Any> = Record<string, Any>>(
2281
- document: SanityDocumentStub<R>,
2723
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2282
2724
  options: FirstDocumentMutationOptions,
2283
- ): Observable<SanityDocument<R>>
2725
+ ): Promise<SanityDocument<R>>
2284
2726
  /**
2285
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2286
- * Returns an observable that resolves to an array containing the created document.
2727
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
2287
2728
  *
2288
- * @param document - Document to create
2289
- * @param options - Mutation options
2729
+ * @param options - Options for the mutation operation
2290
2730
  */
2291
- create<R extends Record<string, Any> = Record<string, Any>>(
2292
- document: SanityDocumentStub<R>,
2293
- options: AllDocumentsMutationOptions,
2294
- ): Observable<SanityDocument<R>[]>
2295
- /**
2296
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2297
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2298
- *
2299
- * @param document - Document to create
2300
- * @param options - Mutation options
2301
- */
2302
- create<R extends Record<string, Any> = Record<string, Any>>(
2303
- document: SanityDocumentStub<R>,
2304
- options: FirstDocumentIdMutationOptions,
2305
- ): Observable<SingleMutationResult>
2306
- /**
2307
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2308
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2309
- *
2310
- * @param document - Document to create
2311
- * @param options - Mutation options
2312
- */
2313
- create<R extends Record<string, Any> = Record<string, Any>>(
2314
- document: SanityDocumentStub<R>,
2315
- options: AllDocumentIdsMutationOptions,
2316
- ): Observable<MultipleMutationResult>
2317
- /**
2318
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2319
- * Returns an observable that resolves to the created document.
2320
- *
2321
- * @param document - Document to create
2322
- * @param options - Mutation options
2323
- */
2324
- create<R extends Record<string, Any> = Record<string, Any>>(
2325
- document: SanityDocumentStub<R>,
2326
- options?: BaseMutationOptions,
2327
- ): Observable<SanityDocument<R>>
2328
- /**
2329
- * Create a document if no document with the same ID already exists.
2330
- * Returns an observable that resolves to the created document.
2331
- *
2332
- * @param document - Document to create
2333
- * @param options - Mutation options
2334
- */
2335
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2336
- document: IdentifiedSanityDocumentStub<R>,
2337
- options: FirstDocumentMutationOptions,
2338
- ): Observable<SanityDocument<R>>
2339
- /**
2340
- * Create a document if no document with the same ID already exists.
2341
- * Returns an observable that resolves to an array containing the created document.
2342
- *
2343
- * @param document - Document to create
2344
- * @param options - Mutation options
2345
- */
2346
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2347
- document: IdentifiedSanityDocumentStub<R>,
2348
- options: AllDocumentsMutationOptions,
2349
- ): Observable<SanityDocument<R>[]>
2350
- /**
2351
- * Create a document if no document with the same ID already exists.
2352
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2353
- *
2354
- * @param document - Document to create
2355
- * @param options - Mutation options
2356
- */
2357
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2358
- document: IdentifiedSanityDocumentStub<R>,
2359
- options: FirstDocumentIdMutationOptions,
2360
- ): Observable<SingleMutationResult>
2361
- /**
2362
- * Create a document if no document with the same ID already exists.
2363
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2364
- *
2365
- * @param document - Document to create
2366
- * @param options - Mutation options
2367
- */
2368
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2369
- document: IdentifiedSanityDocumentStub<R>,
2370
- options: AllDocumentIdsMutationOptions,
2371
- ): Observable<MultipleMutationResult>
2372
- /**
2373
- * Create a document if no document with the same ID already exists.
2374
- * Returns an observable that resolves to the created document.
2375
- *
2376
- * @param document - Document to create
2377
- * @param options - Mutation options
2378
- */
2379
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2380
- document: IdentifiedSanityDocumentStub<R>,
2381
- options?: BaseMutationOptions,
2382
- ): Observable<SanityDocument<R>>
2383
- /**
2384
- * Create a document if it does not exist, or replace a document with the same document ID
2385
- * Returns an observable that resolves to the created document.
2386
- *
2387
- * @param document - Document to either create or replace
2388
- * @param options - Mutation options
2389
- */
2390
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2391
- document: IdentifiedSanityDocumentStub<R>,
2392
- options: FirstDocumentMutationOptions,
2393
- ): Observable<SanityDocument<R>>
2394
- /**
2395
- * Create a document if it does not exist, or replace a document with the same document ID
2396
- * Returns an observable that resolves to an array containing the created document.
2397
- *
2398
- * @param document - Document to either create or replace
2399
- * @param options - Mutation options
2400
- */
2401
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2402
- document: IdentifiedSanityDocumentStub<R>,
2403
- options: AllDocumentsMutationOptions,
2404
- ): Observable<SanityDocument<R>[]>
2405
- /**
2406
- * Create a document if it does not exist, or replace a document with the same document ID
2407
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2408
- *
2409
- * @param document - Document to either create or replace
2410
- * @param options - Mutation options
2411
- */
2412
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2413
- document: IdentifiedSanityDocumentStub<R>,
2414
- options: FirstDocumentIdMutationOptions,
2415
- ): Observable<SingleMutationResult>
2416
- /**
2417
- * Create a document if it does not exist, or replace a document with the same document ID
2418
- * Returns an observable that resolves to a mutation result object containing the created document ID.
2419
- *
2420
- * @param document - Document to either create or replace
2421
- * @param options - Mutation options
2422
- */
2423
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2424
- document: IdentifiedSanityDocumentStub<R>,
2425
- options: AllDocumentIdsMutationOptions,
2426
- ): Observable<MultipleMutationResult>
2427
- /**
2428
- * Create a document if it does not exist, or replace a document with the same document ID
2429
- * Returns an observable that resolves to the created document.
2430
- *
2431
- * @param document - Document to either create or replace
2432
- * @param options - Mutation options
2433
- */
2434
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2435
- document: IdentifiedSanityDocumentStub<R>,
2436
- options?: BaseMutationOptions,
2437
- ): Observable<SanityDocument<R>>
2438
- /**
2439
- * Deletes a document with the given document ID.
2440
- * Returns an observable that resolves to the deleted document.
2441
- *
2442
- * @param id - Document ID to delete
2443
- * @param options - Options for the mutation
2444
- */
2445
- delete<R extends Record<string, Any> = Record<string, Any>>(
2446
- id: string,
2447
- options: FirstDocumentMutationOptions,
2448
- ): Observable<SanityDocument<R>>
2449
- /**
2450
- * Deletes a document with the given document ID.
2451
- * Returns an observable that resolves to an array containing the deleted document.
2452
- *
2453
- * @param id - Document ID to delete
2454
- * @param options - Options for the mutation
2455
- */
2456
- delete<R extends Record<string, Any> = Record<string, Any>>(
2457
- id: string,
2458
- options: AllDocumentsMutationOptions,
2459
- ): Observable<SanityDocument<R>[]>
2460
- /**
2461
- * Deletes a document with the given document ID.
2462
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2463
- *
2464
- * @param id - Document ID to delete
2465
- * @param options - Options for the mutation
2466
- */
2467
- delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2468
- /**
2469
- * Deletes a document with the given document ID.
2470
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2471
- *
2472
- * @param id - Document ID to delete
2473
- * @param options - Options for the mutation
2474
- */
2475
- delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2476
- /**
2477
- * Deletes a document with the given document ID.
2478
- * Returns an observable that resolves to the deleted document.
2479
- *
2480
- * @param id - Document ID to delete
2481
- * @param options - Options for the mutation
2482
- */
2483
- delete<R extends Record<string, Any> = Record<string, Any>>(
2484
- id: string,
2485
- options?: BaseMutationOptions,
2486
- ): Observable<SanityDocument<R>>
2487
- /**
2488
- * Deletes one or more documents matching the given query or document ID.
2489
- * Returns an observable that resolves to first deleted document.
2490
- *
2491
- * @param selection - An object with either an `id` or `query` key defining what to delete
2492
- * @param options - Options for the mutation
2493
- */
2494
- delete<R extends Record<string, Any> = Record<string, Any>>(
2495
- selection: MutationSelection,
2496
- options: FirstDocumentMutationOptions,
2497
- ): Observable<SanityDocument<R>>
2498
- /**
2499
- * Deletes one or more documents matching the given query or document ID.
2500
- * Returns an observable that resolves to an array containing the deleted documents.
2501
- *
2502
- * @param selection - An object with either an `id` or `query` key defining what to delete
2503
- * @param options - Options for the mutation
2504
- */
2505
- delete<R extends Record<string, Any> = Record<string, Any>>(
2506
- selection: MutationSelection,
2507
- options: AllDocumentsMutationOptions,
2508
- ): Observable<SanityDocument<R>[]>
2509
- /**
2510
- * Deletes one or more documents matching the given query or document ID.
2511
- * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
2512
- *
2513
- * @param selection - An object with either an `id` or `query` key defining what to delete
2514
- * @param options - Options for the mutation
2515
- */
2516
- delete(
2517
- selection: MutationSelection,
2518
- options: FirstDocumentIdMutationOptions,
2519
- ): Observable<SingleMutationResult>
2520
- /**
2521
- * Deletes one or more documents matching the given query or document ID.
2522
- * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
2523
- *
2524
- * @param selection - An object with either an `id` or `query` key defining what to delete
2525
- * @param options - Options for the mutation
2526
- */
2527
- delete(
2528
- selection: MutationSelection,
2529
- options: AllDocumentIdsMutationOptions,
2530
- ): Observable<MultipleMutationResult>
2531
- /**
2532
- * Deletes one or more documents matching the given query or document ID.
2533
- * Returns an observable that resolves to first deleted document.
2534
- *
2535
- * @param selection - An object with either an `id` or `query` key defining what to delete
2536
- * @param options - Options for the mutation
2537
- */
2538
- delete<R extends Record<string, Any> = Record<string, Any>>(
2539
- selection: MutationSelection,
2540
- options?: BaseMutationOptions,
2541
- ): Observable<SanityDocument<R>>
2542
- /**
2543
- * Perform mutation operations against the configured dataset
2544
- * Returns an observable that resolves to the first mutated document.
2545
- *
2546
- * @param operations - Mutation operations to execute
2547
- * @param options - Mutation options
2548
- */
2549
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2550
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2551
- options: FirstDocumentMutationOptions,
2552
- ): Observable<SanityDocument<R>>
2553
- /**
2554
- * Perform mutation operations against the configured dataset.
2555
- * Returns an observable that resolves to an array of the mutated documents.
2556
- *
2557
- * @param operations - Mutation operations to execute
2558
- * @param options - Mutation options
2559
- */
2560
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2561
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2562
- options: AllDocumentsMutationOptions,
2563
- ): Observable<SanityDocument<R>[]>
2564
- /**
2565
- * Perform mutation operations against the configured dataset
2566
- * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
2567
- *
2568
- * @param operations - Mutation operations to execute
2569
- * @param options - Mutation options
2570
- */
2571
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2572
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2573
- options: FirstDocumentIdMutationOptions,
2574
- ): Observable<SingleMutationResult>
2575
- /**
2576
- * Perform mutation operations against the configured dataset
2577
- * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
2578
- *
2579
- * @param operations - Mutation operations to execute
2580
- * @param options - Mutation options
2581
- */
2582
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2583
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2584
- options: AllDocumentIdsMutationOptions,
2585
- ): Observable<MultipleMutationResult>
2586
- /**
2587
- * Perform mutation operations against the configured dataset
2588
- * Returns an observable that resolves to the first mutated document.
2589
- *
2590
- * @param operations - Mutation operations to execute
2591
- * @param options - Mutation options
2592
- */
2593
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2594
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2595
- options?: BaseMutationOptions,
2596
- ): Observable<SanityDocument<R>>
2597
- /**
2598
- * Create a new buildable patch of operations to perform
2599
- *
2600
- * @param documentId - Document ID to patch
2601
- * @param operations - Optional object of patch operations to initialize the patch instance with
2602
- * @returns Patch instance - call `.commit()` to perform the operations defined
2603
- */
2604
- patch(documentId: string, operations?: PatchOperations): ObservablePatch
2605
- /**
2606
- * Create a new buildable patch of operations to perform
2607
- *
2608
- * @param documentIds - Array of document IDs to patch
2609
- * @param operations - Optional object of patch operations to initialize the patch instance with
2610
- * @returns Patch instance - call `.commit()` to perform the operations defined
2611
- */
2612
- patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
2613
- /**
2614
- * Create a new buildable patch of operations to perform
2615
- *
2616
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
2617
- * @param operations - Optional object of patch operations to initialize the patch instance with
2618
- * @returns Patch instance - call `.commit()` to perform the operations defined
2619
- */
2620
- patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
2621
- /**
2622
- * Create a new buildable patch of operations to perform
2623
- *
2624
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
2625
- * @param operations - Optional object of patch operations to initialize the patch instance with
2626
- * @returns Patch instance - call `.commit()` to perform the operations defined
2627
- */
2628
- patch(selection: PatchSelection, operations?: PatchOperations): ObservablePatch
2629
- /**
2630
- * Create a new transaction of mutations
2631
- *
2632
- * @param operations - Optional array of mutation operations to initialize the transaction instance with
2633
- */
2634
- transaction<R extends Record<string, Any> = Record<string, Any>>(
2635
- operations?: Mutation<R>[],
2636
- ): ObservableTransaction
2637
- /**
2638
- * Perform action operations against the configured dataset
2639
- *
2640
- * @param operations - Action operation(s) to execute
2641
- * @param options - Action options
2642
- */
2643
- action(
2644
- operations: Action | Action[],
2645
- options?: BaseActionOptions,
2646
- ): Observable<SingleActionResult | MultipleActionResult>
2647
- /**
2648
- * Perform an HTTP request against the Sanity API
2649
- *
2650
- * @param options - Request options
2651
- */
2652
- request<R = Any>(options: RawRequestOptions): Observable<R>
2653
- }
2654
-
2655
- /** @public */
2656
- export declare class ObservableTransaction extends BaseTransaction {
2657
- #private
2658
- constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2659
- /**
2660
- * Clones the transaction
2661
- */
2662
- clone(): ObservableTransaction
2663
- /**
2664
- * Commit the transaction, returning an observable that produces the first mutated document
2665
- *
2666
- * @param options - Options for the mutation operation
2667
- */
2668
- commit<R extends Record<string, Any>>(
2669
- options: TransactionFirstDocumentMutationOptions,
2670
- ): Observable<SanityDocument<R>>
2671
- /**
2672
- * Commit the transaction, returning an observable that produces an array of the mutated documents
2673
- *
2674
- * @param options - Options for the mutation operation
2675
- */
2676
- commit<R extends Record<string, Any>>(
2677
- options: TransactionAllDocumentsMutationOptions,
2678
- ): Observable<SanityDocument<R>[]>
2679
- /**
2680
- * Commit the transaction, returning an observable that produces a mutation result object
2681
- *
2682
- * @param options - Options for the mutation operation
2683
- */
2684
- commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2685
- /**
2686
- * Commit the transaction, returning an observable that produces a mutation result object
2687
- *
2688
- * @param options - Options for the mutation operation
2689
- */
2690
- commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2691
- /**
2692
- * Commit the transaction, returning an observable that produces a mutation result object
2693
- *
2694
- * @param options - Options for the mutation operation
2695
- */
2696
- commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2697
- /**
2698
- * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2699
- * The operation is added to the current transaction, ready to be commited by `commit()`
2700
- *
2701
- * @param documentId - Document ID to perform the patch operation on
2702
- * @param patchOps - Operations to perform, or a builder function
2703
- */
2704
- patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2705
- /**
2706
- * Adds the given patch instance to the transaction.
2707
- * The operation is added to the current transaction, ready to be commited by `commit()`
2708
- *
2709
- * @param patch - ObservablePatch to execute
2710
- */
2711
- patch(patch: ObservablePatch): this
2712
- }
2713
-
2714
- /** @public */
2715
- export declare class ObservableUsersClient implements ObservableUsersClientType {
2716
- #private
2717
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2718
- /**
2719
- * Fetch a user by user ID
2720
- *
2721
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2722
- */
2723
- getById<T extends 'me' | string>(
2724
- id: T,
2725
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2726
- }
2727
-
2728
- /** @internal */
2729
- declare interface ObservableUsersClientType {
2730
- /**
2731
- * Fetch a user by user ID
2732
- *
2733
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2734
- */
2735
- getById<T extends 'me' | string>(
2736
- id: T,
2737
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2738
- }
2739
-
2740
- /**
2741
- * The listener connection has been established
2742
- * note: it's usually a better option to use the 'welcome' event
2743
- * @public
2744
- */
2745
- export declare type OpenEvent = {
2746
- type: 'open'
2747
- }
2748
-
2749
- /** @public */
2750
- export declare class Patch extends BasePatch {
2751
- #private
2752
- constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2753
- /**
2754
- * Clones the patch
2755
- */
2756
- clone(): Patch
2757
- /**
2758
- * Commit the patch, returning a promise that resolves to the first patched document
2759
- *
2760
- * @param options - Options for the mutation operation
2761
- */
2762
- commit<R extends Record<string, Any> = Record<string, Any>>(
2763
- options: FirstDocumentMutationOptions,
2764
- ): Promise<SanityDocument<R>>
2765
- /**
2766
- * Commit the patch, returning a promise that resolves to an array of the mutated documents
2767
- *
2768
- * @param options - Options for the mutation operation
2769
- */
2770
- commit<R extends Record<string, Any> = Record<string, Any>>(
2771
- options: AllDocumentsMutationOptions,
2772
- ): Promise<SanityDocument<R>[]>
2773
- /**
2774
- * Commit the patch, returning a promise that resolves to a mutation result object
2775
- *
2776
- * @param options - Options for the mutation operation
2777
- */
2778
- commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2779
- /**
2780
- * Commit the patch, returning a promise that resolves to a mutation result object
2781
- *
2782
- * @param options - Options for the mutation operation
2783
- */
2784
- commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2785
- /**
2786
- * Commit the patch, returning a promise that resolves to the first patched document
2787
- *
2788
- * @param options - Options for the mutation operation
2789
- */
2790
- commit<R extends Record<string, Any> = Record<string, Any>>(
2791
- options?: BaseMutationOptions,
2792
- ): Promise<SanityDocument<R>>
2793
- }
2794
-
2795
- /** @public */
2796
- export declare type PatchBuilder = (patch: Patch) => Patch
2797
-
2798
- /** @internal */
2799
- export declare type PatchMutationOperation = PatchOperations & MutationSelection
2800
-
2801
- /** @internal */
2802
- export declare interface PatchOperations {
2803
- set?: {
2804
- [key: string]: Any
2805
- }
2806
- setIfMissing?: {
2807
- [key: string]: Any
2808
- }
2809
- diffMatchPatch?: {
2810
- [key: string]: Any
2811
- }
2812
- unset?: string[]
2813
- inc?: {
2814
- [key: string]: number
2815
- }
2816
- dec?: {
2817
- [key: string]: number
2818
- }
2819
- insert?: InsertPatch
2820
- ifRevisionID?: string
2821
- }
2822
-
2823
- /** @internal */
2824
- export declare type PatchSelection = string | string[] | MutationSelection
2825
-
2826
- /** @public */
2827
- declare interface ProgressEvent_2 {
2828
- type: 'progress'
2829
- stage: 'upload' | 'download'
2830
- percent: number
2831
- total?: number
2832
- loaded?: number
2833
- lengthComputable: boolean
2834
- }
2835
- export {ProgressEvent_2 as ProgressEvent}
2836
-
2837
- /** @internal */
2838
- export declare class ProjectsClient implements ProjectsClientType {
2839
- #private
2840
- constructor(client: SanityClient, httpRequest: HttpRequest)
2841
- /**
2842
- * Fetch a list of projects the authenticated user has access to.
2843
- *
2844
- * @param options - Options for the list request
2845
- * @param options.includeMembers - Whether to include members in the response (default: true)
2846
- */
2847
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2848
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
2849
- /**
2850
- * Fetch a project by project ID
2851
- *
2852
- * @param projectId - ID of the project to fetch
2853
- */
2854
- getById(projectId: string): Promise<SanityProject>
2855
- }
2856
-
2857
- /** @internal */
2858
- declare interface ProjectsClientType {
2859
- /**
2860
- * Fetch a list of projects the authenticated user has access to.
2861
- *
2862
- * @param options - Options for the list request
2863
- * @param options.includeMembers - Whether to include members in the response (default: true)
2864
- */
2865
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2866
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
2867
- list(options?: {includeMembers?: boolean}): Promise<SanityProject[]>
2868
- /**
2869
- * Fetch a project by project ID
2870
- *
2871
- * @param projectId - ID of the project to fetch
2872
- */
2873
- getById(projectId: string): Promise<SanityProject>
2874
- }
2875
-
2876
- /**
2877
- * Publishes a draft document.
2878
- * If a published version of the document already exists this is replaced by the current draft document.
2879
- * In either case the draft document is deleted.
2880
- * The optional revision id parameters can be used for optimistic locking to ensure
2881
- * that the draft and/or published versions of the document have not been changed by another client.
2882
- *
2883
- * @public
2884
- */
2885
- export declare type PublishAction = {
2886
- actionType: 'sanity.action.document.publish'
2887
- /**
2888
- * Draft document ID to publish
2889
- */
2890
- draftId: string
2891
- /**
2892
- * Draft revision ID to match
2893
- */
2894
- ifDraftRevisionId?: string
2895
- /**
2896
- * Published document ID to replace
2897
- */
2898
- publishedId: string
2899
- /**
2900
- * Published revision ID to match
2901
- */
2902
- ifPublishedRevisionId?: string
2903
- }
2904
-
2905
- /** @public */
2906
- export declare type QueryOptions =
2907
- | FilteredResponseQueryOptions
2908
- | UnfilteredResponseQueryOptions
2909
- | UnfilteredResponseWithoutQuery
2910
-
2911
- /** @public */
2912
- export declare interface QueryParams {
2913
- [key: string]: any
2914
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2915
- body?: never
2916
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2917
- cache?: 'next' extends keyof RequestInit ? never : any
2918
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2919
- filterResponse?: never
2920
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2921
- headers?: never
2922
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2923
- method?: never
2924
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2925
- next?: 'next' extends keyof RequestInit ? never : any
2926
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2927
- perspective?: never
2928
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2929
- query?: never
2930
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2931
- resultSourceMap?: never
2932
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2933
- returnQuery?: never
2934
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2935
- signal?: never
2936
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2937
- stega?: never
2938
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2939
- tag?: never
2940
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2941
- timeout?: never
2942
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2943
- token?: never
2944
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2945
- useCdn?: never
2946
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2947
- lastLiveEventId?: never
2948
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2949
- cacheMode?: never
2950
- }
2951
-
2952
- /**
2953
- * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
2954
- * @public
2955
- */
2956
- export declare type QueryWithoutParams = Record<string, never> | undefined
2957
-
2958
- /** @public */
2959
- export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
2960
-
2961
- /** @public */
2962
- export declare interface RawQueryResponse<R> {
2963
- query: string
2964
- ms: number
2965
- result: R
2966
- resultSourceMap?: ContentSourceMap
2967
- /** Requires `apiVersion` to be `2021-03-25` or later. */
2968
- syncTags?: SyncTag[]
2969
- }
2970
-
2971
- /** @internal */
2972
- export declare interface RawRequestOptions {
2973
- url?: string
2974
- uri?: string
2975
- method?: string
2976
- token?: string
2977
- json?: boolean
2978
- tag?: string
2979
- useGlobalApi?: boolean
2980
- withCredentials?: boolean
2981
- query?: {
2982
- [key: string]: string | string[]
2983
- }
2984
- headers?: {
2985
- [key: string]: string
2986
- }
2987
- timeout?: number
2988
- proxy?: string
2989
- body?: Any
2990
- maxRedirects?: number
2991
- signal?: AbortSignal
2992
- }
2993
-
2994
- /**
2995
- * The listener has been disconnected, and a reconnect attempt is scheduled.
2996
- *
2997
- * @public
2998
- */
2999
- export declare type ReconnectEvent = {
3000
- type: 'reconnect'
3001
- }
3002
-
3003
- /**
3004
- * @public
3005
- * @deprecated – The `r`-prefix is not required, use `string` instead
3006
- */
3007
- export declare type ReleaseId = `r${string}`
3008
-
3009
- /**
3010
- * Replaces an existing draft document.
3011
- * At least one of the draft or published versions of the document must exist.
3012
- *
3013
- * @public
3014
- */
3015
- export declare type ReplaceDraftAction = {
3016
- actionType: 'sanity.action.document.replaceDraft'
3017
- /**
3018
- * Published document ID to create draft from, if draft does not exist
3019
- */
3020
- publishedId: string
3021
- /**
3022
- * Document to create if it does not already exist. Requires `_id` and `_type` properties.
3023
- */
3024
- attributes: IdentifiedSanityDocumentStub
3025
- }
3026
-
3027
- /** @public */
3028
- export declare const requester: Requester
3029
-
3030
- /** @internal */
3031
- export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
3032
- url?: string
3033
- uri?: string
3034
- canUseCdn?: boolean
3035
- useCdn?: boolean
3036
- tag?: string
3037
- returnQuery?: boolean
3038
- resultSourceMap?: boolean | 'withKeyArraySelector'
3039
- perspective?: ClientPerspective
3040
- lastLiveEventId?: string
3041
- cacheMode?: 'noStale'
3042
- }
3043
-
3044
- /** @public */
3045
- export declare interface RequestOptions {
3046
- timeout?: number
3047
- token?: string
3048
- tag?: string
3049
- headers?: Record<string, string>
3050
- method?: string
3051
- query?: Any
3052
- body?: Any
3053
- signal?: AbortSignal
3054
- }
3055
-
3056
- export {ResolveStudioUrl}
3057
-
3058
- /** @public */
3059
- export declare interface ResponseEvent<T = unknown> {
3060
- type: 'response'
3061
- body: T
3062
- url: string
3063
- method: string
3064
- statusCode: number
3065
- statusMessage?: string
3066
- headers: Record<string, string>
3067
- }
3068
-
3069
- /** @public */
3070
- export declare interface ResponseQueryOptions extends RequestOptions {
3071
- perspective?: ClientPerspective
3072
- resultSourceMap?: boolean | 'withKeyArraySelector'
3073
- returnQuery?: boolean
3074
- useCdn?: boolean
3075
- stega?: boolean | StegaConfig
3076
- cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
3077
- next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
3078
- lastLiveEventId?: string | string[] | null
3079
- /**
3080
- * When set to `noStale`, APICDN will not return a cached response if the content is stale.
3081
- * Tradeoff between latency and freshness of content.
3082
- *
3083
- * Only to be used with live content queries and when useCdn is true.
3084
- */
3085
- cacheMode?: 'noStale'
3086
- }
3087
-
3088
- /** @internal */
3089
- export declare interface SanityAssetDocument extends SanityDocument {
3090
- url: string
3091
- path: string
3092
- size: number
3093
- assetId: string
3094
- mimeType: string
3095
- sha1hash: string
3096
- extension: string
3097
- uploadId?: string
3098
- originalFilename?: string
3099
- }
3100
-
3101
- /** @public */
3102
- export declare class SanityClient implements SanityClientType {
3103
- #private
3104
- assets: AssetsClient
3105
- datasets: DatasetsClient
3106
- live: LiveClient
3107
- projects: ProjectsClient
3108
- users: UsersClient
3109
- /**
3110
- * Observable version of the Sanity client, with the same configuration as the promise-based one
3111
- */
3112
- observable: ObservableSanityClient
3113
- listen: typeof _listen
3114
- constructor(httpRequest: HttpRequest, config?: ClientConfig)
3115
- /**
3116
- * Clone the client - returns a new instance
3117
- */
3118
- clone(): SanityClient
3119
- /**
3120
- * Returns the current client configuration
3121
- */
3122
- config(): InitializedClientConfig
3123
- /**
3124
- * Reconfigure the client. Note that this _mutates_ the current client.
3125
- */
3126
- config(newConfig?: Partial<ClientConfig>): this
3127
- /**
3128
- * Clone the client with a new (partial) configuration.
3129
- *
3130
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3131
- */
3132
- withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3133
- /**
3134
- * Perform a GROQ-query against the configured dataset.
3135
- *
3136
- * @param query - GROQ-query to perform
3137
- */
3138
- fetch<
3139
- R = Any,
3140
- Q extends QueryWithoutParams = QueryWithoutParams,
3141
- const G extends string = string,
3142
- >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3143
- /**
3144
- * Perform a GROQ-query against the configured dataset.
3145
- *
3146
- * @param query - GROQ-query to perform
3147
- * @param params - Optional query parameters
3148
- * @param options - Optional request options
3149
- */
3150
- fetch<
3151
- R = Any,
3152
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3153
- const G extends string = string,
3154
- >(
3155
- query: G,
3156
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3157
- options?: FilteredResponseQueryOptions,
3158
- ): Promise<ClientReturn<G, R>>
3159
- /**
3160
- * Perform a GROQ-query against the configured dataset.
3161
- *
3162
- * @param query - GROQ-query to perform
3163
- * @param params - Optional query parameters
3164
- * @param options - Request options
3165
- */
3166
- fetch<
3167
- R = Any,
3168
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3169
- const G extends string = string,
3170
- >(
3171
- query: G,
3172
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3173
- options: UnfilteredResponseQueryOptions,
3174
- ): Promise<RawQueryResponse<ClientReturn<G, R>>>
3175
- /**
3176
- * Perform a GROQ-query against the configured dataset.
3177
- *
3178
- * @param query - GROQ-query to perform
3179
- * @param params - Optional query parameters
3180
- * @param options - Request options
3181
- */
3182
- fetch<
3183
- R = Any,
3184
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3185
- const G extends string = string,
3186
- >(
3187
- query: G,
3188
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3189
- options: UnfilteredResponseWithoutQuery,
3190
- ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
3191
- /**
3192
- * Fetch a single document with the given ID.
3193
- *
3194
- * @param id - Document ID to fetch
3195
- * @param options - Request options
3196
- */
3197
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
3198
- id: string,
3199
- options?: {
3200
- signal?: AbortSignal
3201
- tag?: string
3202
- },
3203
- ): Promise<SanityDocument<R> | undefined>
3204
- /**
3205
- * Fetch multiple documents in one request.
3206
- * Should be used sparingly - performing a query is usually a better option.
3207
- * The order/position of documents is preserved based on the original array of IDs.
3208
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
3209
- *
3210
- * @param ids - Document IDs to fetch
3211
- * @param options - Request options
3212
- */
3213
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
3214
- ids: string[],
3215
- options?: {
3216
- signal?: AbortSignal
3217
- tag?: string
3218
- },
3219
- ): Promise<(SanityDocument<R> | null)[]>
3220
- /**
3221
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3222
- * Returns a promise that resolves to the created document.
3223
- *
3224
- * @param document - Document to create
3225
- * @param options - Mutation options
3226
- */
3227
- create<R extends Record<string, Any> = Record<string, Any>>(
3228
- document: SanityDocumentStub<R>,
3229
- options: FirstDocumentMutationOptions,
3230
- ): Promise<SanityDocument<R>>
3231
- /**
3232
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3233
- * Returns a promise that resolves to an array containing the created document.
3234
- *
3235
- * @param document - Document to create
3236
- * @param options - Mutation options
3237
- */
3238
- create<R extends Record<string, Any> = Record<string, Any>>(
3239
- document: SanityDocumentStub<R>,
3240
- options: AllDocumentsMutationOptions,
3241
- ): Promise<SanityDocument<R>[]>
3242
- /**
3243
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3244
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3245
- *
3246
- * @param document - Document to create
3247
- * @param options - Mutation options
3248
- */
3249
- create<R extends Record<string, Any> = Record<string, Any>>(
3250
- document: SanityDocumentStub<R>,
3251
- options: FirstDocumentIdMutationOptions,
3252
- ): Promise<SingleMutationResult>
3253
- /**
3254
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3255
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3256
- *
3257
- * @param document - Document to create
3258
- * @param options - Mutation options
3259
- */
3260
- create<R extends Record<string, Any> = Record<string, Any>>(
3261
- document: SanityDocumentStub<R>,
3262
- options: AllDocumentIdsMutationOptions,
3263
- ): Promise<MultipleMutationResult>
3264
- /**
3265
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3266
- * Returns a promise that resolves to the created document.
3267
- *
3268
- * @param document - Document to create
3269
- * @param options - Mutation options
3270
- */
3271
- create<R extends Record<string, Any> = Record<string, Any>>(
3272
- document: SanityDocumentStub<R>,
3273
- options?: BaseMutationOptions,
3274
- ): Promise<SanityDocument<R>>
3275
- /**
3276
- * Create a document if no document with the same ID already exists.
3277
- * Returns a promise that resolves to the created document.
3278
- *
3279
- * @param document - Document to create
3280
- * @param options - Mutation options
3281
- */
3282
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3283
- document: IdentifiedSanityDocumentStub<R>,
3284
- options: FirstDocumentMutationOptions,
3285
- ): Promise<SanityDocument<R>>
3286
- /**
3287
- * Create a document if no document with the same ID already exists.
3288
- * Returns a promise that resolves to an array containing the created document.
3289
- *
3290
- * @param document - Document to create
3291
- * @param options - Mutation options
3292
- */
3293
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3294
- document: IdentifiedSanityDocumentStub<R>,
3295
- options: AllDocumentsMutationOptions,
3296
- ): Promise<SanityDocument<R>[]>
3297
- /**
3298
- * Create a document if no document with the same ID already exists.
3299
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3300
- *
3301
- * @param document - Document to create
3302
- * @param options - Mutation options
3303
- */
3304
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3305
- document: IdentifiedSanityDocumentStub<R>,
3306
- options: FirstDocumentIdMutationOptions,
3307
- ): Promise<SingleMutationResult>
3308
- /**
3309
- * Create a document if no document with the same ID already exists.
3310
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3311
- *
3312
- * @param document - Document to create
3313
- * @param options - Mutation options
3314
- */
3315
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3316
- document: IdentifiedSanityDocumentStub<R>,
3317
- options: AllDocumentIdsMutationOptions,
3318
- ): Promise<MultipleMutationResult>
3319
- /**
3320
- * Create a document if no document with the same ID already exists.
3321
- * Returns a promise that resolves to the created document.
3322
- *
3323
- * @param document - Document to create
3324
- * @param options - Mutation options
3325
- */
3326
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3327
- document: IdentifiedSanityDocumentStub<R>,
3328
- options?: BaseMutationOptions,
3329
- ): Promise<SanityDocument<R>>
3330
- /**
3331
- * Create a document if it does not exist, or replace a document with the same document ID
3332
- * Returns a promise that resolves to the created document.
3333
- *
3334
- * @param document - Document to either create or replace
3335
- * @param options - Mutation options
3336
- */
3337
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3338
- document: IdentifiedSanityDocumentStub<R>,
3339
- options: FirstDocumentMutationOptions,
3340
- ): Promise<SanityDocument<R>>
3341
- /**
3342
- * Create a document if it does not exist, or replace a document with the same document ID
3343
- * Returns a promise that resolves to an array containing the created document.
3344
- *
3345
- * @param document - Document to either create or replace
3346
- * @param options - Mutation options
3347
- */
3348
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3349
- document: IdentifiedSanityDocumentStub<R>,
3350
- options: AllDocumentsMutationOptions,
3351
- ): Promise<SanityDocument<R>[]>
3352
- /**
3353
- * Create a document if it does not exist, or replace a document with the same document ID
3354
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3355
- *
3356
- * @param document - Document to either create or replace
3357
- * @param options - Mutation options
3358
- */
3359
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3360
- document: IdentifiedSanityDocumentStub<R>,
3361
- options: FirstDocumentIdMutationOptions,
3362
- ): Promise<SingleMutationResult>
3363
- /**
3364
- * Create a document if it does not exist, or replace a document with the same document ID
3365
- * Returns a promise that resolves to a mutation result object containing the created document ID.
3366
- *
3367
- * @param document - Document to either create or replace
3368
- * @param options - Mutation options
3369
- */
3370
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3371
- document: IdentifiedSanityDocumentStub<R>,
3372
- options: AllDocumentIdsMutationOptions,
3373
- ): Promise<MultipleMutationResult>
3374
- /**
3375
- * Create a document if it does not exist, or replace a document with the same document ID
3376
- * Returns a promise that resolves to the created document.
3377
- *
3378
- * @param document - Document to either create or replace
3379
- * @param options - Mutation options
3380
- */
3381
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3382
- document: IdentifiedSanityDocumentStub<R>,
3383
- options?: BaseMutationOptions,
3384
- ): Promise<SanityDocument<R>>
3385
- /**
3386
- * Deletes a document with the given document ID.
3387
- * Returns a promise that resolves to the deleted document.
3388
- *
3389
- * @param id - Document ID to delete
3390
- * @param options - Options for the mutation
3391
- */
3392
- delete<R extends Record<string, Any> = Record<string, Any>>(
3393
- id: string,
3394
- options: FirstDocumentMutationOptions,
3395
- ): Promise<SanityDocument<R>>
3396
- /**
3397
- * Deletes a document with the given document ID.
3398
- * Returns a promise that resolves to an array containing the deleted document.
3399
- *
3400
- * @param id - Document ID to delete
3401
- * @param options - Options for the mutation
3402
- */
3403
- delete<R extends Record<string, Any> = Record<string, Any>>(
3404
- id: string,
3405
- options: AllDocumentsMutationOptions,
3406
- ): Promise<SanityDocument<R>[]>
3407
- /**
3408
- * Deletes a document with the given document ID.
3409
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3410
- *
3411
- * @param id - Document ID to delete
3412
- * @param options - Options for the mutation
3413
- */
3414
- delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3415
- /**
3416
- * Deletes a document with the given document ID.
3417
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3418
- *
3419
- * @param id - Document ID to delete
3420
- * @param options - Options for the mutation
3421
- */
3422
- delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3423
- /**
3424
- * Deletes a document with the given document ID.
3425
- * Returns a promise that resolves to the deleted document.
3426
- *
3427
- * @param id - Document ID to delete
3428
- * @param options - Options for the mutation
3429
- */
3430
- delete<R extends Record<string, Any> = Record<string, Any>>(
3431
- id: string,
3432
- options?: BaseMutationOptions,
3433
- ): Promise<SanityDocument<R>>
3434
- /**
3435
- * Deletes one or more documents matching the given query or document ID.
3436
- * Returns a promise that resolves to first deleted document.
3437
- *
3438
- * @param selection - An object with either an `id` or `query` key defining what to delete
3439
- * @param options - Options for the mutation
3440
- */
3441
- delete<R extends Record<string, Any> = Record<string, Any>>(
3442
- selection: MutationSelection,
3443
- options: FirstDocumentMutationOptions,
3444
- ): Promise<SanityDocument<R>>
3445
- /**
3446
- * Deletes one or more documents matching the given query or document ID.
3447
- * Returns a promise that resolves to an array containing the deleted documents.
3448
- *
3449
- * @param selection - An object with either an `id` or `query` key defining what to delete
3450
- * @param options - Options for the mutation
3451
- */
3452
- delete<R extends Record<string, Any> = Record<string, Any>>(
3453
- selection: MutationSelection,
3454
- options: AllDocumentsMutationOptions,
3455
- ): Promise<SanityDocument<R>[]>
3456
- /**
3457
- * Deletes one or more documents matching the given query or document ID.
3458
- * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
3459
- *
3460
- * @param selection - An object with either an `id` or `query` key defining what to delete
3461
- * @param options - Options for the mutation
3462
- */
3463
- delete(
3464
- selection: MutationSelection,
3465
- options: FirstDocumentIdMutationOptions,
3466
- ): Promise<SingleMutationResult>
3467
- /**
3468
- * Deletes one or more documents matching the given query or document ID.
3469
- * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
3470
- *
3471
- * @param selection - An object with either an `id` or `query` key defining what to delete
3472
- * @param options - Options for the mutation
3473
- */
3474
- delete(
3475
- selection: MutationSelection,
3476
- options: AllDocumentIdsMutationOptions,
3477
- ): Promise<MultipleMutationResult>
3478
- /**
3479
- * Deletes one or more documents matching the given query or document ID.
3480
- * Returns a promise that resolves to first deleted document.
3481
- *
3482
- * @param selection - An object with either an `id` or `query` key defining what to delete
3483
- * @param options - Options for the mutation
3484
- */
3485
- delete<R extends Record<string, Any> = Record<string, Any>>(
3486
- selection: MutationSelection,
3487
- options?: BaseMutationOptions,
3488
- ): Promise<SanityDocument<R>>
3489
- /**
3490
- * Perform mutation operations against the configured dataset
3491
- * Returns a promise that resolves to the first mutated document.
3492
- *
3493
- * @param operations - Mutation operations to execute
3494
- * @param options - Mutation options
3495
- */
3496
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3497
- operations: Mutation<R>[] | Patch | Transaction,
3498
- options: FirstDocumentMutationOptions,
3499
- ): Promise<SanityDocument<R>>
3500
- /**
3501
- * Perform mutation operations against the configured dataset.
3502
- * Returns a promise that resolves to an array of the mutated documents.
3503
- *
3504
- * @param operations - Mutation operations to execute
3505
- * @param options - Mutation options
3506
- */
3507
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3508
- operations: Mutation<R>[] | Patch | Transaction,
2731
+ commit<R extends Record<string, Any> = Record<string, Any>>(
3509
2732
  options: AllDocumentsMutationOptions,
3510
2733
  ): Promise<SanityDocument<R>[]>
3511
2734
  /**
3512
- * Perform mutation operations against the configured dataset
3513
- * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
2735
+ * Commit the patch, returning a promise that resolves to a mutation result object
3514
2736
  *
3515
- * @param operations - Mutation operations to execute
3516
- * @param options - Mutation options
2737
+ * @param options - Options for the mutation operation
3517
2738
  */
3518
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3519
- operations: Mutation<R>[] | Patch | Transaction,
3520
- options: FirstDocumentIdMutationOptions,
3521
- ): Promise<SingleMutationResult>
2739
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3522
2740
  /**
3523
- * Perform mutation operations against the configured dataset
3524
- * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
2741
+ * Commit the patch, returning a promise that resolves to a mutation result object
3525
2742
  *
3526
- * @param operations - Mutation operations to execute
3527
- * @param options - Mutation options
2743
+ * @param options - Options for the mutation operation
3528
2744
  */
3529
- mutate<R extends Record<string, Any>>(
3530
- operations: Mutation<R>[] | Patch | Transaction,
3531
- options: AllDocumentIdsMutationOptions,
3532
- ): Promise<MultipleMutationResult>
2745
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3533
2746
  /**
3534
- * Perform mutation operations against the configured dataset
3535
- * Returns a promise that resolves to the first mutated document.
2747
+ * Commit the patch, returning a promise that resolves to the first patched document
3536
2748
  *
3537
- * @param operations - Mutation operations to execute
3538
- * @param options - Mutation options
2749
+ * @param options - Options for the mutation operation
3539
2750
  */
3540
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3541
- operations: Mutation<R>[] | Patch | Transaction,
2751
+ commit<R extends Record<string, Any> = Record<string, Any>>(
3542
2752
  options?: BaseMutationOptions,
3543
2753
  ): Promise<SanityDocument<R>>
2754
+ }
2755
+
2756
+ /** @public */
2757
+ export declare type PatchBuilder = (patch: Patch) => Patch
2758
+
2759
+ /** @internal */
2760
+ export declare type PatchMutationOperation = PatchOperations & MutationSelection
2761
+
2762
+ /** @internal */
2763
+ export declare interface PatchOperations {
2764
+ set?: {
2765
+ [key: string]: Any
2766
+ }
2767
+ setIfMissing?: {
2768
+ [key: string]: Any
2769
+ }
2770
+ diffMatchPatch?: {
2771
+ [key: string]: Any
2772
+ }
2773
+ unset?: string[]
2774
+ inc?: {
2775
+ [key: string]: number
2776
+ }
2777
+ dec?: {
2778
+ [key: string]: number
2779
+ }
2780
+ insert?: InsertPatch
2781
+ ifRevisionID?: string
2782
+ }
2783
+
2784
+ /** @internal */
2785
+ export declare type PatchSelection = string | string[] | MutationSelection
2786
+
2787
+ /** @public */
2788
+ declare interface ProgressEvent_2 {
2789
+ type: 'progress'
2790
+ stage: 'upload' | 'download'
2791
+ percent: number
2792
+ total?: number
2793
+ loaded?: number
2794
+ lengthComputable: boolean
2795
+ }
2796
+ export {ProgressEvent_2 as ProgressEvent}
2797
+
2798
+ /** @internal */
2799
+ export declare class ProjectsClient {
2800
+ #private
2801
+ constructor(client: SanityClient, httpRequest: HttpRequest)
3544
2802
  /**
3545
- * Create a new buildable patch of operations to perform
3546
- *
3547
- * @param documentId - Document ID to patch
3548
- * @param operations - Optional object of patch operations to initialize the patch instance with
3549
- * @returns Patch instance - call `.commit()` to perform the operations defined
3550
- */
3551
- patch(documentId: string, operations?: PatchOperations): Patch
3552
- /**
3553
- * Create a new buildable patch of operations to perform
3554
- *
3555
- * @param documentIds - Array of document IDs to patch
3556
- * @param operations - Optional object of patch operations to initialize the patch instance with
3557
- * @returns Patch instance - call `.commit()` to perform the operations defined
3558
- */
3559
- patch(documentIds: string[], operations?: PatchOperations): Patch
3560
- /**
3561
- * Create a new buildable patch of operations to perform
3562
- *
3563
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
3564
- * @param operations - Optional object of patch operations to initialize the patch instance with
3565
- * @returns Patch instance - call `.commit()` to perform the operations defined
3566
- */
3567
- patch(selection: MutationSelection, operations?: PatchOperations): Patch
3568
- /**
3569
- * Create a new transaction of mutations
2803
+ * Fetch a list of projects the authenticated user has access to.
3570
2804
  *
3571
- * @param operations - Optional array of mutation operations to initialize the transaction instance with
2805
+ * @param options - Options for the list request
2806
+ * - `includeMembers` - Whether to include members in the response (default: true)
3572
2807
  */
3573
- transaction<R extends Record<string, Any> = Record<string, Any>>(
3574
- operations?: Mutation<R>[],
3575
- ): Transaction
2808
+ list(options?: {includeMembers?: true}): Promise<SanityProject[]>
2809
+ list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
3576
2810
  /**
3577
- * Perform action operations against the configured dataset
3578
- * Returns a promise that resolves to the transaction result
2811
+ * Fetch a project by project ID
3579
2812
  *
3580
- * @param operations - Action operation(s) to execute
3581
- * @param options - Action options
2813
+ * @param projectId - ID of the project to fetch
3582
2814
  */
3583
- action(
3584
- operations: Action | Action[],
3585
- options?: BaseActionOptions,
3586
- ): Promise<SingleActionResult | MultipleActionResult>
2815
+ getById(projectId: string): Promise<SanityProject>
2816
+ }
2817
+
2818
+ /**
2819
+ * Publishes a draft document.
2820
+ * If a published version of the document already exists this is replaced by the current draft document.
2821
+ * In either case the draft document is deleted.
2822
+ * The optional revision id parameters can be used for optimistic locking to ensure
2823
+ * that the draft and/or published versions of the document have not been changed by another client.
2824
+ *
2825
+ * @public
2826
+ */
2827
+ export declare type PublishAction = {
2828
+ actionType: 'sanity.action.document.publish'
3587
2829
  /**
3588
- * Perform a request against the Sanity API
3589
- * NOTE: Only use this for Sanity API endpoints, not for your own APIs!
3590
- *
3591
- * @param options - Request options
3592
- * @returns Promise resolving to the response body
2830
+ * Draft document ID to publish
3593
2831
  */
3594
- request<R = Any>(options: RawRequestOptions): Promise<R>
2832
+ draftId: string
3595
2833
  /**
3596
- * Perform an HTTP request a `/data` sub-endpoint
3597
- * NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
3598
- *
3599
- * @deprecated - Use `request()` or your own HTTP library instead
3600
- * @param endpoint - Endpoint to hit (mutate, query etc)
3601
- * @param body - Request body
3602
- * @param options - Request options
3603
- * @internal
2834
+ * Draft revision ID to match
3604
2835
  */
3605
- dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
2836
+ ifDraftRevisionId?: string
3606
2837
  /**
3607
- * Get a Sanity API URL for the URI provided
3608
- *
3609
- * @param uri - URI/path to build URL for
3610
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
2838
+ * Published document ID to replace
3611
2839
  */
3612
- getUrl(uri: string, canUseCdn?: boolean): string
2840
+ publishedId: string
3613
2841
  /**
3614
- * Get a Sanity API URL for the data operation and path provided
3615
- *
3616
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3617
- * @param path - Path to append after the operation
2842
+ * Published revision ID to match
3618
2843
  */
3619
- getDataUrl(operation: string, path?: string): string
2844
+ ifPublishedRevisionId?: string
2845
+ }
2846
+
2847
+ /** @public */
2848
+ export declare type QueryOptions =
2849
+ | FilteredResponseQueryOptions
2850
+ | UnfilteredResponseQueryOptions
2851
+ | UnfilteredResponseWithoutQuery
2852
+
2853
+ /** @public */
2854
+ export declare interface QueryParams {
2855
+ [key: string]: any
2856
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2857
+ body?: never
2858
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2859
+ cache?: 'next' extends keyof RequestInit ? never : any
2860
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2861
+ filterResponse?: never
2862
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2863
+ headers?: never
2864
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2865
+ method?: never
2866
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2867
+ next?: 'next' extends keyof RequestInit ? never : any
2868
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2869
+ perspective?: never
2870
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2871
+ query?: never
2872
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2873
+ resultSourceMap?: never
2874
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2875
+ returnQuery?: never
2876
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2877
+ signal?: never
2878
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2879
+ stega?: never
2880
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2881
+ tag?: never
2882
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2883
+ timeout?: never
2884
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2885
+ token?: never
2886
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2887
+ useCdn?: never
2888
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2889
+ lastLiveEventId?: never
2890
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
2891
+ cacheMode?: never
2892
+ }
2893
+
2894
+ /**
2895
+ * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
2896
+ * @public
2897
+ */
2898
+ export declare type QueryWithoutParams = Record<string, never> | undefined
2899
+
2900
+ /** @public */
2901
+ export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
2902
+
2903
+ /** @public */
2904
+ export declare interface RawQueryResponse<R> {
2905
+ query: string
2906
+ ms: number
2907
+ result: R
2908
+ resultSourceMap?: ContentSourceMap
2909
+ /** Requires `apiVersion` to be `2021-03-25` or later. */
2910
+ syncTags?: SyncTag[]
2911
+ }
2912
+
2913
+ /** @internal */
2914
+ export declare interface RawRequestOptions {
2915
+ url?: string
2916
+ uri?: string
2917
+ method?: string
2918
+ token?: string
2919
+ json?: boolean
2920
+ tag?: string
2921
+ useGlobalApi?: boolean
2922
+ withCredentials?: boolean
2923
+ query?: {
2924
+ [key: string]: string | string[]
2925
+ }
2926
+ headers?: {
2927
+ [key: string]: string
2928
+ }
2929
+ timeout?: number
2930
+ proxy?: string
2931
+ body?: Any
2932
+ maxRedirects?: number
2933
+ signal?: AbortSignal
3620
2934
  }
3621
2935
 
3622
2936
  /**
3623
- * Shared base type for the `SanityClient` and `ObservableSanityClient` classes.
3624
- * TODO: refactor the Promise and Observable differences to use generics so we no longer suffer from all this duplication in TS docs
2937
+ * The listener has been disconnected, and a reconnect attempt is scheduled.
2938
+ *
2939
+ * @public
3625
2940
  */
3626
- declare interface SanityClientBase {
3627
- live: LiveClient
3628
- listen: typeof _listen
2941
+ export declare type ReconnectEvent = {
2942
+ type: 'reconnect'
2943
+ }
2944
+
2945
+ /**
2946
+ * @public
2947
+ * @deprecated – The `r`-prefix is not required, use `string` instead
2948
+ */
2949
+ export declare type ReleaseId = `r${string}`
2950
+
2951
+ /**
2952
+ * Replaces an existing draft document.
2953
+ * At least one of the draft or published versions of the document must exist.
2954
+ *
2955
+ * @public
2956
+ */
2957
+ export declare type ReplaceDraftAction = {
2958
+ actionType: 'sanity.action.document.replaceDraft'
3629
2959
  /**
3630
- * Get a Sanity API URL for the URI provided
3631
- *
3632
- * @param uri - URI/path to build URL for
3633
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
2960
+ * Published document ID to create draft from, if draft does not exist
3634
2961
  */
3635
- getUrl(uri: string, canUseCdn?: boolean): string
2962
+ publishedId: string
3636
2963
  /**
3637
- * Get a Sanity API URL for the data operation and path provided
2964
+ * Document to create if it does not already exist. Requires `_id` and `_type` properties.
2965
+ */
2966
+ attributes: IdentifiedSanityDocumentStub
2967
+ }
2968
+
2969
+ /** @public */
2970
+ export declare const requester: Requester
2971
+
2972
+ /** @internal */
2973
+ export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
2974
+ url?: string
2975
+ uri?: string
2976
+ canUseCdn?: boolean
2977
+ useCdn?: boolean
2978
+ tag?: string
2979
+ returnQuery?: boolean
2980
+ resultSourceMap?: boolean | 'withKeyArraySelector'
2981
+ perspective?: ClientPerspective
2982
+ lastLiveEventId?: string
2983
+ cacheMode?: 'noStale'
2984
+ }
2985
+
2986
+ /** @public */
2987
+ export declare interface RequestOptions {
2988
+ timeout?: number
2989
+ token?: string
2990
+ tag?: string
2991
+ headers?: Record<string, string>
2992
+ method?: string
2993
+ query?: Any
2994
+ body?: Any
2995
+ signal?: AbortSignal
2996
+ }
2997
+
2998
+ export {ResolveStudioUrl}
2999
+
3000
+ /** @public */
3001
+ export declare interface ResponseEvent<T = unknown> {
3002
+ type: 'response'
3003
+ body: T
3004
+ url: string
3005
+ method: string
3006
+ statusCode: number
3007
+ statusMessage?: string
3008
+ headers: Record<string, string>
3009
+ }
3010
+
3011
+ /** @public */
3012
+ export declare interface ResponseQueryOptions extends RequestOptions {
3013
+ perspective?: ClientPerspective
3014
+ resultSourceMap?: boolean | 'withKeyArraySelector'
3015
+ returnQuery?: boolean
3016
+ useCdn?: boolean
3017
+ stega?: boolean | StegaConfig
3018
+ cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
3019
+ next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
3020
+ lastLiveEventId?: string | string[] | null
3021
+ /**
3022
+ * When set to `noStale`, APICDN will not return a cached response if the content is stale.
3023
+ * Tradeoff between latency and freshness of content.
3638
3024
  *
3639
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3640
- * @param path - Path to append after the operation
3025
+ * Only to be used with live content queries and when useCdn is true.
3641
3026
  */
3642
- getDataUrl(operation: string, path?: string): string
3027
+ cacheMode?: 'noStale'
3643
3028
  }
3644
3029
 
3645
- /**
3646
- * The interface implemented by the `SanityClient` class.
3647
- * When writing code that wants to take an instance of `SanityClient` as input it's better to use this type,
3648
- * as the `SanityClient` class has private properties and thus TypeScrict will consider the type incompatible
3649
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
3650
- * @public
3651
- */
3652
- export declare interface SanityClientType extends SanityClientBase {
3653
- assets: AssetsClientType
3654
- datasets: DatasetsClientType
3655
- projects: ProjectsClientType
3656
- users: UsersClientType
3030
+ /** @internal */
3031
+ export declare interface SanityAssetDocument extends SanityDocument {
3032
+ url: string
3033
+ path: string
3034
+ size: number
3035
+ assetId: string
3036
+ mimeType: string
3037
+ sha1hash: string
3038
+ extension: string
3039
+ uploadId?: string
3040
+ originalFilename?: string
3041
+ }
3042
+
3043
+ /** @public */
3044
+ export declare class SanityClient {
3045
+ #private
3046
+ assets: AssetsClient
3047
+ datasets: DatasetsClient
3048
+ live: LiveClient
3049
+ projects: ProjectsClient
3050
+ users: UsersClient
3051
+ agent: {
3052
+ action: AgentActionsClient
3053
+ }
3657
3054
  /**
3658
3055
  * Observable version of the Sanity client, with the same configuration as the promise-based one
3659
3056
  */
3660
- observable: ObservableSanityClientType
3057
+ observable: ObservableSanityClient
3058
+ /**
3059
+ * Instance properties
3060
+ */
3061
+ listen: typeof _listen
3062
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
3661
3063
  /**
3662
3064
  * Clone the client - returns a new instance
3663
3065
  */
3664
- clone(): SanityClientType
3066
+ clone(): SanityClient
3665
3067
  /**
3666
3068
  * Returns the current client configuration
3667
3069
  */
@@ -3669,13 +3071,13 @@ export declare interface SanityClientType extends SanityClientBase {
3669
3071
  /**
3670
3072
  * Reconfigure the client. Note that this _mutates_ the current client.
3671
3073
  */
3672
- config(newConfig?: Partial<ClientConfig>): SanityClientType
3074
+ config(newConfig?: Partial<ClientConfig>): this
3673
3075
  /**
3674
3076
  * Clone the client with a new (partial) configuration.
3675
3077
  *
3676
3078
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3677
3079
  */
3678
- withConfig(newConfig?: Partial<ClientConfig>): SanityClientType
3080
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3679
3081
  /**
3680
3082
  * Perform a GROQ-query against the configured dataset.
3681
3083
  *
@@ -3685,10 +3087,7 @@ export declare interface SanityClientType extends SanityClientBase {
3685
3087
  R = Any,
3686
3088
  Q extends QueryWithoutParams = QueryWithoutParams,
3687
3089
  const G extends string = string,
3688
- >(
3689
- query: G,
3690
- params?: Q | QueryWithoutParams,
3691
- ): Promise<ClientReturn<G, R>>
3090
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3692
3091
  /**
3693
3092
  * Perform a GROQ-query against the configured dataset.
3694
3093
  *
@@ -4114,14 +3513,6 @@ export declare interface SanityClientType extends SanityClientBase {
4114
3513
  * @returns Patch instance - call `.commit()` to perform the operations defined
4115
3514
  */
4116
3515
  patch(selection: MutationSelection, operations?: PatchOperations): Patch
4117
- /**
4118
- * Create a new buildable patch of operations to perform
4119
- *
4120
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
4121
- * @param operations - Optional object of patch operations to initialize the patch instance with
4122
- * @returns Patch instance - call `.commit()` to perform the operations defined
4123
- */
4124
- patch(selection: PatchSelection, operations?: PatchOperations): Patch
4125
3516
  /**
4126
3517
  * Create a new transaction of mutations
4127
3518
  *
@@ -4160,6 +3551,20 @@ export declare interface SanityClientType extends SanityClientBase {
4160
3551
  * @internal
4161
3552
  */
4162
3553
  dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
3554
+ /**
3555
+ * Get a Sanity API URL for the URI provided
3556
+ *
3557
+ * @param uri - URI/path to build URL for
3558
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
3559
+ */
3560
+ getUrl(uri: string, canUseCdn?: boolean): string
3561
+ /**
3562
+ * Get a Sanity API URL for the data operation and path provided
3563
+ *
3564
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3565
+ * @param path - Path to append after the operation
3566
+ */
3567
+ getDataUrl(operation: string, path?: string): string
4163
3568
  }
4164
3569
 
4165
3570
  /** @internal */
@@ -4460,6 +3865,309 @@ export declare type TransactionMutationOptions =
4460
3865
  | TransactionAllDocumentsMutationOptions
4461
3866
  | TransactionAllDocumentIdsMutationOptions
4462
3867
 
3868
+ /** @beta */
3869
+ export declare type TransformDocument<T extends Record<string, Any> = Record<string, Any>> =
3870
+ | TransformDocumentSync<T>
3871
+ | TransformDocumentAsync
3872
+
3873
+ /** @beta */
3874
+ declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
3875
+
3876
+ /** @beta */
3877
+ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
3878
+ TransformRequestBase & AgentActionSync
3879
+
3880
+ /** @beta */
3881
+ declare interface TransformRequestBase extends AgentActionRequestBase {
3882
+ /** schemaId as reported by sanity deploy / sanity schema store */
3883
+ schemaId: string
3884
+ /**
3885
+ * The source document the transformation will use as input.
3886
+ */
3887
+ documentId: string
3888
+ /**
3889
+ * The source document's content is first copied to the target,
3890
+ * then it is transformed according to the instruction.
3891
+ *
3892
+ * When omitted, the source document (documentId) is also the target document.
3893
+ */
3894
+ targetDocument?: TransformTargetDocument
3895
+ /**
3896
+ * Instruct the LLM how to transform the input to th output.
3897
+ *
3898
+ * String template using $variable from instructionParams.
3899
+ *
3900
+ * Capped to 2000 characters, after variables has been injected.
3901
+ * */
3902
+ instruction: string
3903
+ /**
3904
+ *
3905
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
3906
+ *
3907
+ * ### Examples
3908
+ *
3909
+ * #### Constant
3910
+ *
3911
+ * ##### Shorthand
3912
+ * ```ts
3913
+ * client.agent.action.generate({
3914
+ * schemaId,
3915
+ * documentId,
3916
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
3917
+ * instructionParams: {
3918
+ * topic: 'Grapefruit'
3919
+ * },
3920
+ * })
3921
+ * ```
3922
+ * ##### Object-form
3923
+ *
3924
+ * ```ts
3925
+ * client.agent.action.transform({
3926
+ * schemaId,
3927
+ * documentId,
3928
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
3929
+ * instructionParams: {
3930
+ * topic: {
3931
+ * type: 'constant',
3932
+ * value: 'Grapefruit'
3933
+ * },
3934
+ * },
3935
+ * })
3936
+ * ```
3937
+ * #### Field
3938
+ * ```ts
3939
+ * client.agent.action.transform({
3940
+ * schemaId,
3941
+ * documentId,
3942
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
3943
+ * instructionParams: {
3944
+ * pte: {
3945
+ * type: 'field',
3946
+ * path: ['pteField'],
3947
+ * },
3948
+ * },
3949
+ * target: {path: 'keywords' }
3950
+ * })
3951
+ * ```
3952
+ * #### Document
3953
+ * ```ts
3954
+ * client.agent.action.transform({
3955
+ * schemaId,
3956
+ * documentId,
3957
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
3958
+ * instructionParams: {
3959
+ * document: {
3960
+ * type: 'document',
3961
+ * },
3962
+ * },
3963
+ * target: {path: 'keywords' }
3964
+ * })
3965
+ * ```
3966
+ *
3967
+ * #### GROQ
3968
+ * ```ts
3969
+ * client.agent.action.transform({
3970
+ * schemaId,
3971
+ * documentId,
3972
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
3973
+ * instructionParams: {
3974
+ * list: {
3975
+ * type: 'groq',
3976
+ * query: '* [_type==$type].title',
3977
+ * params: {type: 'article'}
3978
+ * },
3979
+ * },
3980
+ * target: {path: 'title'}
3981
+ * })
3982
+ * ```
3983
+ * */
3984
+ instructionParams?: AgentActionParams
3985
+ /**
3986
+ * Target defines which parts of the document will be affected by the instruction.
3987
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
3988
+ *
3989
+ * Omitting target implies that the document itself is the root.
3990
+ *
3991
+ * Notes:
3992
+ * - instruction can only affect fields up to `maxPathDepth`
3993
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
3994
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
3995
+ *
3996
+ * Default max depth for transform: 12
3997
+ * @see AgentActionRequestBase#conditionalPaths
3998
+ */
3999
+ target?: TransformTarget | TransformTarget[]
4000
+ }
4001
+
4002
+ /** @beta */
4003
+ export declare interface TransformTarget extends AgentActionTarget {
4004
+ /**
4005
+ * Specifies a tailored instruction of this target.
4006
+ *
4007
+ * string template using $variable from instructionParams.
4008
+ * */
4009
+ instruction?: string
4010
+ /**
4011
+ * By default, all children up to `target.maxPathDepth` are included.
4012
+ *
4013
+ * When `include` is specified, only segments explicitly listed will be included.
4014
+ *
4015
+ * Fields or array items not on the include list, are implicitly excluded.
4016
+ */
4017
+ include?: (AgentActionPathSegment | TransformTargetInclude)[]
4018
+ }
4019
+
4020
+ /** @beta */
4021
+ export declare type TransformTargetDocument =
4022
+ | {
4023
+ operation: 'edit'
4024
+ _id: string
4025
+ }
4026
+ | {
4027
+ operation: 'create'
4028
+ _id?: string
4029
+ }
4030
+ | {
4031
+ operation: 'createIfNotExists'
4032
+ _id: string
4033
+ }
4034
+ | {
4035
+ operation: 'createOrReplace'
4036
+ _id: string
4037
+ }
4038
+
4039
+ /** @beta */
4040
+ export declare interface TransformTargetInclude extends AgentActionTargetInclude {
4041
+ /**
4042
+ * Specifies a tailored instruction of this target.
4043
+ *
4044
+ * string template using $variable from instructionParams */
4045
+ instruction?: string
4046
+ /**
4047
+ * By default, all children up to `target.maxPathDepth` are included.
4048
+ *
4049
+ * When `include` is specified, only segments explicitly listed will be included.
4050
+ *
4051
+ * Fields or array items not on the include list, are implicitly excluded.
4052
+ */
4053
+ include?: (AgentActionPathSegment | TransformTargetInclude)[]
4054
+ }
4055
+
4056
+ /** @beta */
4057
+ export declare type TranslateDocument<T extends Record<string, Any> = Record<string, Any>> =
4058
+ | TranslateDocumentSync<T>
4059
+ | TranslateDocumentAsync
4060
+
4061
+ /** @beta */
4062
+ declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
4063
+
4064
+ /** @beta */
4065
+ declare type TranslateDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
4066
+ TranslateRequestBase & AgentActionSync
4067
+
4068
+ /** @beta */
4069
+ declare interface TranslateLanguage {
4070
+ /**
4071
+ * Language code
4072
+ */
4073
+ id: string
4074
+ /**
4075
+ * While optional, it is recommended to provide a language title
4076
+ */
4077
+ title?: string
4078
+ }
4079
+
4080
+ /** @beta */
4081
+ declare interface TranslateRequestBase extends AgentActionRequestBase {
4082
+ /** schemaId as reported by sanity deploy / sanity schema store */
4083
+ schemaId: string
4084
+ /**
4085
+ * The source document the transformation will use as input.
4086
+ */
4087
+ documentId: string
4088
+ /**
4089
+ * The target document will first get content copied over from the source,
4090
+ * then it is translated according to the instruction.
4091
+ *
4092
+ * When omitted, the source document (documentId) is also the target document.
4093
+ */
4094
+ targetDocument?: TransformTargetDocument
4095
+ /**
4096
+ * While optional, it is recommended
4097
+ */
4098
+ fromLanguage?: TranslateLanguage
4099
+ toLanguage: TranslateLanguage
4100
+ /**
4101
+ * `styleGuide` can be used to tailor how the translation should be preformed.
4102
+ *
4103
+ * String template using $variable from styleGuideParams.
4104
+ *
4105
+ * Capped to 2000 characters, after variables has been injected.
4106
+ *
4107
+ * @see #protectedPhrases
4108
+ */
4109
+ styleGuide?: string
4110
+ /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
4111
+ styleGuideParams?: AgentActionParams
4112
+ /**
4113
+ * When the input string contains any phrase from `protectedPhrases`, the LLM will be instructed not
4114
+ * to translate them.
4115
+ *
4116
+ * It is recommended to use `protectedPhrases` instead of `styleGuide` for deny-list words and phrases,
4117
+ * since it keeps token cost low, resulting in faster responses, and limits how much information the LLM
4118
+ * has to process, since only phrases that are actually in the input string will be included in the final prompt.
4119
+ */
4120
+ protectedPhrases?: string[]
4121
+ /**
4122
+ * When specified, the `toLanguage.id` will be stored in the specified path in the target document.
4123
+ *
4124
+ * The file _can_ be hidden: true (unlike other fields in the target, which will be ignored)
4125
+ */
4126
+ languageFieldPath?: AgentActionPathSegment | AgentActionPath
4127
+ /**
4128
+ * Target defines which parts of the document will be affected by the instruction.
4129
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
4130
+ *
4131
+ * Omitting target implies that the document itself is the root.
4132
+ *
4133
+ * Notes:
4134
+ * - instruction can only affect fields up to `maxPathDepth`
4135
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
4136
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
4137
+ *
4138
+ * @see AgentActionRequestBase#conditionalPaths
4139
+ */
4140
+ target?: TranslateTarget | TranslateTarget[]
4141
+ }
4142
+
4143
+ /** @beta */
4144
+ export declare interface TranslateTarget extends AgentActionTarget {
4145
+ /** string template using $variable from instructionParams */
4146
+ styleGuide?: string
4147
+ /**
4148
+ * By default, all children up to `target.maxPathDepth` are included.
4149
+ *
4150
+ * When `include` is specified, only segments explicitly listed will be included.
4151
+ *
4152
+ * Fields or array items not on the include list, are implicitly excluded.
4153
+ */
4154
+ include?: (AgentActionPathSegment | TranslateTargetInclude)[]
4155
+ }
4156
+
4157
+ /** @beta */
4158
+ export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
4159
+ /** string template using $variable from instructionParams */
4160
+ styleGuide?: string
4161
+ /**
4162
+ * By default, all children up to `target.maxPathDepth` are included.
4163
+ *
4164
+ * When `include` is specified, only segments explicitly listed will be included.
4165
+ *
4166
+ * Fields or array items not on the include list, are implicitly excluded.
4167
+ */
4168
+ include?: (AgentActionPathSegment | TranslateTargetInclude)[]
4169
+ }
4170
+
4463
4171
  /** @public */
4464
4172
  export declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
4465
4173
  filterResponse: false
@@ -4570,7 +4278,7 @@ export declare interface UploadClientConfig {
4570
4278
  }
4571
4279
 
4572
4280
  /** @public */
4573
- export declare class UsersClient implements UsersClientType {
4281
+ export declare class UsersClient {
4574
4282
  #private
4575
4283
  constructor(client: SanityClient, httpRequest: HttpRequest)
4576
4284
  /**
@@ -4581,16 +4289,6 @@ export declare class UsersClient implements UsersClientType {
4581
4289
  getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
4582
4290
  }
4583
4291
 
4584
- /** @internal */
4585
- declare interface UsersClientType {
4586
- /**
4587
- * Fetch a user by user ID
4588
- *
4589
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
4590
- */
4591
- getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
4592
- }
4593
-
4594
4292
  /**
4595
4293
  * @internal - it may have breaking changes in any release
4596
4294
  */