@sanity/client 7.0.1-canary.2 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +516 -40
  2. package/dist/_chunks-cjs/config.cjs +14 -0
  3. package/dist/_chunks-cjs/config.cjs.map +1 -1
  4. package/dist/_chunks-es/config.js +15 -1
  5. package/dist/_chunks-es/config.js.map +1 -1
  6. package/dist/index.browser.cjs +850 -7
  7. package/dist/index.browser.cjs.map +1 -1
  8. package/dist/index.browser.d.cts +2601 -1622
  9. package/dist/index.browser.d.ts +2601 -1622
  10. package/dist/index.browser.js +852 -7
  11. package/dist/index.browser.js.map +1 -1
  12. package/dist/index.cjs +839 -8
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +2601 -1622
  15. package/dist/index.d.ts +2601 -1622
  16. package/dist/index.js +842 -9
  17. package/dist/index.js.map +1 -1
  18. package/dist/stega.browser.d.cts +2612 -1633
  19. package/dist/stega.browser.d.ts +2612 -1633
  20. package/dist/stega.d.cts +2612 -1633
  21. package/dist/stega.d.ts +2612 -1633
  22. package/package.json +3 -1
  23. package/src/SanityClient.ts +626 -1106
  24. package/src/agent/actions/AgentActionsClient.ts +111 -0
  25. package/src/agent/actions/commonTypes.ts +336 -0
  26. package/src/agent/actions/generate.ts +274 -0
  27. package/src/agent/actions/transform.ts +215 -0
  28. package/src/agent/actions/translate.ts +165 -0
  29. package/src/assets/AssetsClient.ts +2 -86
  30. package/src/data/dataMethods.ts +127 -3
  31. package/src/data/transaction.ts +1 -1
  32. package/src/datasets/DatasetsClient.ts +2 -64
  33. package/src/projects/ProjectsClient.ts +4 -46
  34. package/src/releases/ReleasesClient.ts +687 -0
  35. package/src/releases/createRelease.ts +53 -0
  36. package/src/types.ts +245 -1
  37. package/src/users/UsersClient.ts +2 -24
  38. package/src/util/createVersionId.ts +79 -0
  39. package/src/validators.ts +23 -1
  40. package/umd/sanityClient.js +915 -6
  41. package/umd/sanityClient.min.js +2 -2
package/dist/stega.d.ts CHANGED
@@ -13,6 +13,8 @@ export declare type Action =
13
13
  | DiscardAction
14
14
  | PublishAction
15
15
  | UnpublishAction
16
+ | VersionAction
17
+ | ReleaseAction
16
18
 
17
19
  /** @internal */
18
20
  export declare interface ActionError {
@@ -33,6 +35,262 @@ export declare interface ActionErrorItem {
33
35
  index: number
34
36
  }
35
37
 
38
+ /** @beta */
39
+ declare interface AgentActionAsync {
40
+ /**
41
+ * When async: true, requests responds with status 201 and \{_id\} as response body as soon as the request is validated.
42
+ * The instruction operation will carry on in the background.
43
+ *
44
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
45
+ *
46
+ * async: true is incompatible with noWrite, as async: true does not return the resulting document
47
+ */
48
+ async: true
49
+ }
50
+
51
+ /** @beta */
52
+ export declare type AgentActionParam =
53
+ | string
54
+ | ConstantAgentActionParam
55
+ | FieldAgentActionParam
56
+ | DocumentAgentActionParam
57
+ | GroqAgentActionParam
58
+
59
+ /** @beta */
60
+ export declare type AgentActionParams = Record<string, AgentActionParam>
61
+
62
+ /** @beta */
63
+ export declare type AgentActionPath = AgentActionPathSegment[]
64
+
65
+ /** @beta */
66
+ export declare type AgentActionPathSegment =
67
+ | string
68
+ | {
69
+ _key: string
70
+ }
71
+
72
+ /** @beta */
73
+ declare interface AgentActionRequestBase {
74
+ /** schemaId as reported by sanity deploy / sanity schema store */
75
+ schemaId: string
76
+ /**
77
+ * When a type or field in the schema has a function set for `hidden` or `readOnly`, it is conditional.
78
+ *
79
+ * By default, Generate will not output to conditional `readOnly` and `hidden` fields,
80
+ * ie, they are considered to resolve to `readOnly: true` / `hidden: true`.
81
+ *
82
+ * `conditionalPaths` param allows setting the default conditional value for
83
+ * `hidden` and `readOnly` to false,
84
+ * or individually set `hidden` and `readOnly` state for individual document paths.
85
+ *
86
+ * Note: fields and types with explicit readOnly: true or hidden: true in the schema, are not available to Generate,
87
+ * and cannot be changed via conditionalPaths
88
+ *
89
+ * conditionalPaths state only apply to fields and types that have conditional `hidden` or `readOnly` in their schema definition.
90
+ *
91
+ * Consider using `hidden: () => true` in schema config, if a field should be writeable only by Generate and never
92
+ * visible in the studio – then make the field visible to the Generate using `conditionalPaths`.
93
+ *
94
+ * @see GenerateRequestBase#target
95
+ */
96
+ conditionalPaths?: {
97
+ defaultReadOnly?: boolean
98
+ defaultHidden?: boolean
99
+ paths?: {
100
+ /** path here is not a relative path: it must be the full document path, regardless of `path` param used in targets */
101
+ path: AgentActionPath
102
+ readOnly: boolean
103
+ hidden: boolean
104
+ }[]
105
+ }
106
+ /**
107
+ * When localeSettings is provided on the request, instruct can write to date and datetime fields.
108
+ * Otherwise, such fields will be ignored.
109
+ */
110
+ localeSettings?: {
111
+ /**
112
+ * A valid Unicode BCP 47 locale identifier used to interpret and format
113
+ * natural language inputs and date output. Examples include "en-US", "fr-FR", or "ja-JP".
114
+ *
115
+ * This affects how phrases like "next Friday" or "in two weeks" are parsed,
116
+ * and how resulting dates are presented (e.g., 12-hour vs 24-hour format).
117
+ *
118
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#getcanonicalocales
119
+ */
120
+ locale: string
121
+ /**
122
+ * A valid IANA time zone identifier used to resolve relative and absolute
123
+ * date expressions to a specific point in time. Examples include
124
+ * "America/New_York", "Europe/Paris", or "Asia/Tokyo".
125
+ *
126
+ * This ensures phrases like "tomorrow at 9am" are interpreted correctly
127
+ * based on the user's local time.
128
+ *
129
+ * @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
130
+ */
131
+ timeZone: string
132
+ }
133
+ /**
134
+ * Controls how much variance the instructions will run with.
135
+ *
136
+ * Value must be in the range [0, 1] (inclusive).
137
+ *
138
+ * Defaults:
139
+ * - generate: 0.3
140
+ * - translate: 0
141
+ * - transform: 0
142
+ */
143
+ temperature?: number
144
+ }
145
+
146
+ /** @public */
147
+ declare class AgentActionsClient {
148
+ #private
149
+ constructor(client: SanityClient, httpRequest: HttpRequest)
150
+ /**
151
+ * Run an instruction to generate content in a target document.
152
+ * @param request - instruction request
153
+ */
154
+ generate<DocumentShape extends Record<string, Any>>(
155
+ request: GenerateInstruction<DocumentShape>,
156
+ ): Promise<
157
+ (typeof request)['async'] extends true
158
+ ? {
159
+ _id: string
160
+ }
161
+ : IdentifiedSanityDocumentStub & DocumentShape
162
+ >
163
+ /**
164
+ * Transform a target document based on a source.
165
+ * @param request - translation request
166
+ */
167
+ transform<DocumentShape extends Record<string, Any>>(
168
+ request: TransformDocument<DocumentShape>,
169
+ ): Promise<
170
+ (typeof request)['async'] extends true
171
+ ? {
172
+ _id: string
173
+ }
174
+ : IdentifiedSanityDocumentStub & DocumentShape
175
+ >
176
+ /**
177
+ * Translate a target document based on a source.
178
+ * @param request - translation request
179
+ */
180
+ translate<DocumentShape extends Record<string, Any>>(
181
+ request: TranslateDocument<DocumentShape>,
182
+ ): Promise<
183
+ (typeof request)['async'] extends true
184
+ ? {
185
+ _id: string
186
+ }
187
+ : IdentifiedSanityDocumentStub & DocumentShape
188
+ >
189
+ }
190
+
191
+ /** @beta */
192
+ declare interface AgentActionSync {
193
+ /**
194
+ * By default, noWrite: false.
195
+ * Write enabled operations will mutate the target document, and emit AI presence in the studio.
196
+ *
197
+ * When noWrite: true, the api will not mutate any documents nor emit presence.
198
+ * Ie, when true, no changes will be made to content-lake
199
+ *
200
+ * noWrite: true is incompatible with async: true,
201
+ * as noWrite implies that you will use the return value of the operation
202
+ */
203
+ noWrite?: boolean
204
+ /**
205
+ * When async: true, requests responds with status 201 and \{_id\} as response body as soon as the request is validated.
206
+ * The instruction operation will carry on in the background.
207
+ *
208
+ * When async: false (default), requests respond with status 200 and the document value after instruction has been applied.
209
+ *
210
+ * async: true is incompatible with noWrite: true, as async: true does not return the resulting document
211
+ */
212
+ async?: false
213
+ }
214
+
215
+ /**
216
+ * @beta
217
+ */
218
+ export declare interface AgentActionTarget {
219
+ /**
220
+ * Root target path.
221
+ *
222
+ * Use this to have the instruction only affect a part of the document.
223
+ *
224
+ * To further control the behavior of individual paths under the root, use `include`, `exclude`, `types.include`
225
+ * and `types.exclude`.
226
+ *
227
+ * Example:
228
+ *
229
+ * `path: ['body', {_key: 'someKey'}, 'nestedObject']`
230
+ *
231
+ * Here, the instruction will only write to fields under the nestedObject.
232
+ *
233
+ * Default: [] = the document itself
234
+ *
235
+ * @see #AgentActionPathSegment
236
+ * @see #AgentActionPath
237
+ * */
238
+ path?: AgentActionPathSegment | AgentActionPath
239
+ /**
240
+ * maxPathDepth controls how deep into the schema from the target root the instruction will affect.
241
+ *
242
+ * Depth is based on path segments:
243
+ * - `title` has depth 1
244
+ * - `array[_key="no"].title` has depth 3
245
+ *
246
+ * Be careful not to set this too high in studios with recursive document schemas, as it could have
247
+ * negative impact on performance; both for runtime and quality of responses.
248
+ *
249
+ * Default: 4
250
+ */
251
+ maxPathDepth?: number
252
+ /**
253
+ * By default, all children up to `target.maxPathDepth` are included.
254
+ * Fields or array items not on the exclude list, are implicitly included.
255
+ */
256
+ exclude?: AgentActionPathSegment[]
257
+ /**
258
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
259
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
260
+ *
261
+ * `types.include` and `types.exclude` are mutually exclusive.
262
+ */
263
+ types?: AgentActionTypeConfig
264
+ }
265
+
266
+ /** @beta */
267
+ declare interface AgentActionTargetInclude {
268
+ path: AgentActionPathSegment | AgentActionPath
269
+ /**
270
+ * By default, all children up to `target.maxPathDepth` are included.
271
+ * Fields or array items not on the exclude list, are implicitly included.
272
+ */
273
+ exclude?: AgentActionPathSegment[]
274
+ /**
275
+ * Types can be used to exclude array item types or all fields directly under the target path of a certain type.
276
+ * If you do exclude: ['string'] all string fields under the target will be excluded, for instance.
277
+ *
278
+ * `types.include` and `types.exclude` are mutually exclusive.
279
+ */
280
+ types?: AgentActionTypeConfig
281
+ }
282
+
283
+ /** @beta */
284
+ declare type AgentActionTypeConfig =
285
+ | {
286
+ include: string[]
287
+ exclude?: never
288
+ }
289
+ | {
290
+ exclude: string[]
291
+ include?: never
292
+ }
293
+
36
294
  /** @internal */
37
295
  export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
38
296
  returnFirst: false
@@ -58,6 +316,16 @@ export declare interface ApiError {
58
316
  statusCode: number
59
317
  }
60
318
 
319
+ /**
320
+ * Archives an `active` release, and deletes all the release documents.
321
+ *
322
+ * @public
323
+ */
324
+ export declare interface ArchiveReleaseAction {
325
+ actionType: 'sanity.action.release.archive'
326
+ releaseId: string
327
+ }
328
+
61
329
  /** @public */
62
330
  export declare type AssetMetadataType =
63
331
  | 'location'
@@ -69,7 +337,7 @@ export declare type AssetMetadataType =
69
337
  | 'none'
70
338
 
71
339
  /** @internal */
72
- export declare class AssetsClient implements AssetsClientType {
340
+ export declare class AssetsClient {
73
341
  #private
74
342
  constructor(client: SanityClient, httpRequest: HttpRequest)
75
343
  /**
@@ -110,46 +378,6 @@ export declare class AssetsClient implements AssetsClientType {
110
378
  ): Promise<SanityAssetDocument | SanityImageAssetDocument>
111
379
  }
112
380
 
113
- /** @internal */
114
- declare interface AssetsClientType {
115
- /**
116
- * Uploads a file asset to the configured dataset
117
- *
118
- * @param assetType - Asset type (file)
119
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
120
- * @param options - Options to use for the upload
121
- */
122
- upload(
123
- assetType: 'file',
124
- body: UploadBody,
125
- options?: UploadClientConfig,
126
- ): Promise<SanityAssetDocument>
127
- /**
128
- * Uploads an image asset to the configured dataset
129
- *
130
- * @param assetType - Asset type (image)
131
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
132
- * @param options - Options to use for the upload
133
- */
134
- upload(
135
- assetType: 'image',
136
- body: UploadBody,
137
- options?: UploadClientConfig,
138
- ): Promise<SanityImageAssetDocument>
139
- /**
140
- * Uploads a file or an image asset to the configured dataset
141
- *
142
- * @param assetType - Asset type (file/image)
143
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
144
- * @param options - Options to use for the upload
145
- */
146
- upload(
147
- assetType: 'file' | 'image',
148
- body: UploadBody,
149
- options?: UploadClientConfig,
150
- ): Promise<SanityAssetDocument | SanityImageAssetDocument>
151
- }
152
-
153
381
  /** @internal */
154
382
  export declare type AttributeSet = {
155
383
  [key: string]: Any
@@ -515,6 +743,43 @@ export declare class ConnectionFailedError extends Error {
515
743
  readonly name = 'ConnectionFailedError'
516
744
  }
517
745
 
746
+ /**
747
+ * Include a string in the instruction: do not have to escape $ signs in the string.
748
+ *
749
+ * ```ts
750
+ * client.agent.action.generate({
751
+ * schemaId,
752
+ * documentId,
753
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
754
+ * instructionParams: {
755
+ * topic: {
756
+ * type: 'constant',
757
+ * value: 'Grapefruit'
758
+ * },
759
+ * },
760
+ * })
761
+ * ```
762
+ *
763
+ * `type: 'constant'` can also be provided directly as a string, as a shorthand:
764
+ *
765
+ * ```ts
766
+ * client.agent.action.generate({
767
+ * schemaId,
768
+ * documentId,
769
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
770
+ * instructionParams: {
771
+ * topic: 'Grapefruit'
772
+ * },
773
+ * })
774
+ * ```
775
+ *
776
+ * @beta
777
+ * */
778
+ export declare interface ConstantAgentActionParam {
779
+ type: 'constant'
780
+ value: string
781
+ }
782
+
518
783
  /** @public */
519
784
  export declare interface ContentSourceMap {
520
785
  mappings: ContentSourceMapMappings
@@ -733,6 +998,29 @@ export declare type CreateAction = {
733
998
  */
734
999
  export declare const createClient: (config: ClientConfig_2) => SanityClient
735
1000
 
1001
+ /**
1002
+ * Creates a new release under the given id, with metadata.
1003
+ *
1004
+ * @public
1005
+ */
1006
+ export declare interface CreateReleaseAction {
1007
+ actionType: 'sanity.action.release.create'
1008
+ releaseId: string
1009
+ metadata?: Partial<ReleaseDocument['metadata']>
1010
+ }
1011
+
1012
+ /**
1013
+ * Creates a new version of an existing document, attached to the release as given
1014
+ * by `document._id`
1015
+ *
1016
+ * @public
1017
+ */
1018
+ export declare interface CreateVersionAction {
1019
+ actionType: 'sanity.action.document.version.create'
1020
+ publishedId: string
1021
+ document: IdentifiedSanityDocumentStub
1022
+ }
1023
+
736
1024
  /** @public */
737
1025
  export declare interface CurrentSanityUser {
738
1026
  id: string
@@ -752,7 +1040,7 @@ export declare type DatasetResponse = {
752
1040
  }
753
1041
 
754
1042
  /** @internal */
755
- export declare class DatasetsClient implements DatasetsClientType {
1043
+ export declare class DatasetsClient {
756
1044
  #private
757
1045
  constructor(client: SanityClient, httpRequest: HttpRequest)
758
1046
  /**
@@ -793,46 +1081,6 @@ export declare class DatasetsClient implements DatasetsClientType {
793
1081
  list(): Promise<DatasetsResponse>
794
1082
  }
795
1083
 
796
- /** @internal */
797
- declare interface DatasetsClientType {
798
- /**
799
- * Create a new dataset with the given name
800
- *
801
- * @param name - Name of the dataset to create
802
- * @param options - Options for the dataset
803
- */
804
- create(
805
- name: string,
806
- options?: {
807
- aclMode?: DatasetAclMode
808
- },
809
- ): Promise<DatasetResponse>
810
- /**
811
- * Edit a dataset with the given name
812
- *
813
- * @param name - Name of the dataset to edit
814
- * @param options - New options for the dataset
815
- */
816
- edit(
817
- name: string,
818
- options?: {
819
- aclMode?: DatasetAclMode
820
- },
821
- ): Promise<DatasetResponse>
822
- /**
823
- * Delete a dataset with the given name
824
- *
825
- * @param name - Name of the dataset to delete
826
- */
827
- delete(name: string): Promise<{
828
- deleted: true
829
- }>
830
- /**
831
- * Fetch a list of datasets for the configured project
832
- */
833
- list(): Promise<DatasetsResponse>
834
- }
835
-
836
1084
  /** @public */
837
1085
  export declare type DatasetsResponse = {
838
1086
  name: string
@@ -868,6 +1116,16 @@ export declare type DeleteAction = {
868
1116
  purge?: boolean
869
1117
  }
870
1118
 
1119
+ /**
1120
+ * Deletes a `archived` or `published` release, and all the release documents versions.
1121
+ *
1122
+ * @public
1123
+ */
1124
+ export declare interface DeleteReleaseAction {
1125
+ actionType: 'sanity.action.release.delete'
1126
+ releaseId: string
1127
+ }
1128
+
871
1129
  /**
872
1130
  * @deprecated use 'drafts' instead
873
1131
  */
@@ -878,6 +1136,7 @@ declare type DeprecatedPreviewDrafts = 'previewDrafts'
878
1136
  * It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
879
1137
  *
880
1138
  * @public
1139
+ * @deprecated Use {@link DiscardVersionAction} instead
881
1140
  */
882
1141
  export declare type DiscardAction = {
883
1142
  actionType: 'sanity.action.document.discard'
@@ -891,6 +1150,17 @@ export declare type DiscardAction = {
891
1150
  purge?: boolean
892
1151
  }
893
1152
 
1153
+ /**
1154
+ * Delete a version of a document.
1155
+ *
1156
+ * @public
1157
+ */
1158
+ export declare interface DiscardVersionAction {
1159
+ actionType: 'sanity.action.document.version.discard'
1160
+ versionId: string
1161
+ purge?: boolean
1162
+ }
1163
+
894
1164
  /**
895
1165
  * The listener has been told to explicitly disconnect.
896
1166
  * This is a rare situation, but may occur if the API knows reconnect attempts will fail,
@@ -917,6 +1187,43 @@ export declare type DisconnectEvent = {
917
1187
  reason: string
918
1188
  }
919
1189
 
1190
+ /**
1191
+ *
1192
+ * Includes a LLM-friendly version of the document in the instruction
1193
+ *
1194
+ * ```ts
1195
+ * client.agent.action.generate({
1196
+ * schemaId,
1197
+ * documentId,
1198
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
1199
+ * instructionParams: {
1200
+ * document: {
1201
+ * type: 'document',
1202
+ * },
1203
+ * },
1204
+ * target: {path: 'keywords' }
1205
+ * })
1206
+ * ```
1207
+ *
1208
+ * @beta
1209
+ * */
1210
+ export declare interface DocumentAgentActionParam {
1211
+ type: 'document'
1212
+ /**
1213
+ * If omitted, implicitly uses the documentId of the instruction target
1214
+ */
1215
+ documentId?: string
1216
+ }
1217
+
1218
+ /** @internal */
1219
+ export declare type EditableReleaseDocument = Omit<
1220
+ PartialExcept<ReleaseDocument, '_id'>,
1221
+ 'metadata' | '_type'
1222
+ > & {
1223
+ _id: string
1224
+ metadata: Partial<ReleaseDocument['metadata']>
1225
+ }
1226
+
920
1227
  /**
921
1228
  * Modifies an existing draft document.
922
1229
  * It applies the given patch to the document referenced by draftId.
@@ -940,6 +1247,17 @@ export declare type EditAction = {
940
1247
  patch: PatchOperations
941
1248
  }
942
1249
 
1250
+ /**
1251
+ * Edits an existing release, updating the metadata.
1252
+ *
1253
+ * @public
1254
+ */
1255
+ export declare interface EditReleaseAction {
1256
+ actionType: 'sanity.action.release.edit'
1257
+ releaseId: string
1258
+ patch: PatchOperations
1259
+ }
1260
+
943
1261
  /**
944
1262
  * @internal
945
1263
  */
@@ -978,6 +1296,41 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
978
1296
  */
979
1297
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
980
1298
 
1299
+ /**
1300
+ *
1301
+ *
1302
+ * Includes a LLM-friendly version of the field value in the instruction
1303
+ *
1304
+ * ```ts
1305
+ * client.agent.action.generate({
1306
+ * schemaId,
1307
+ * documentId,
1308
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
1309
+ * instructionParams: {
1310
+ * pte: {
1311
+ * type: 'field',
1312
+ * path: ['pteField'],
1313
+ * },
1314
+ * },
1315
+ * target: {path: 'keywords' }
1316
+ * })
1317
+ *
1318
+ * ```
1319
+ *
1320
+ * @beta
1321
+ * */
1322
+ export declare interface FieldAgentActionParam {
1323
+ type: 'field'
1324
+ /**
1325
+ * Examples: 'title', ['array', \{_key: 'arrayItemKey'\}, 'field']
1326
+ */
1327
+ path: AgentActionPathSegment | AgentActionPath
1328
+ /**
1329
+ * If omitted, implicitly uses the documentId of the instruction target
1330
+ */
1331
+ documentId?: string
1332
+ }
1333
+
981
1334
  /** @public */
982
1335
  export declare type FilterDefault = (props: {
983
1336
  /**
@@ -1093,19 +1446,287 @@ export declare type FirstDocumentMutationOptions = BaseMutationOptions & {
1093
1446
  returnDocuments?: true
1094
1447
  }
1095
1448
 
1096
- /** @public */
1097
- export declare type HttpRequest = {
1098
- (options: RequestOptions, requester: Requester): ReturnType<Requester>
1099
- }
1100
-
1101
- /** @public */
1102
- export declare type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent_2
1449
+ /** @beta */
1450
+ declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1451
+ | GenerateExistingDocumentRequest
1452
+ | GenerateTargetDocumentRequest<T>
1453
+ ) &
1454
+ GenerateRequestBase &
1455
+ AgentActionAsync
1103
1456
 
1104
- /** @public */
1105
- export declare type IdentifiedSanityDocumentStub<
1106
- T extends Record<string, Any> = Record<string, Any>,
1107
- > = {
1108
- [P in keyof T]: T[P]
1457
+ /**
1458
+ * Instruction for an existing document.
1459
+ * @beta
1460
+ */
1461
+ declare interface GenerateExistingDocumentRequest {
1462
+ documentId: string
1463
+ createDocument?: never
1464
+ }
1465
+
1466
+ /** @beta */
1467
+ export declare type GenerateInstruction<T extends Record<string, Any> = Record<string, Any>> =
1468
+ | GenerateSyncInstruction<T>
1469
+ | GenerateAsyncInstruction<T>
1470
+
1471
+ /** @beta */
1472
+ export declare type GenerateOperation = 'set' | 'append' | 'mixed'
1473
+
1474
+ /** @beta */
1475
+ declare interface GenerateRequestBase extends AgentActionRequestBase {
1476
+ /** schemaId as reported by sanity deploy / sanity schema store */
1477
+ schemaId: string
1478
+ /**
1479
+ * Instruct the LLM how it should generate content. Be as specific and detailed as needed.
1480
+ *
1481
+ * The LLM only has access to information in the instruction, plus the target schema.
1482
+ *
1483
+ * string template using $variable
1484
+ * */
1485
+ instruction: string
1486
+ /**
1487
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
1488
+ *
1489
+ * ### Examples
1490
+ *
1491
+ * #### Constant
1492
+ *
1493
+ * ##### Shorthand
1494
+ * ```ts
1495
+ * client.agent.action.generate({
1496
+ * schemaId,
1497
+ * documentId,
1498
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
1499
+ * instructionParams: {
1500
+ * topic: 'Grapefruit'
1501
+ * },
1502
+ * })
1503
+ * ```
1504
+ * ##### Object-form
1505
+ *
1506
+ * ```ts
1507
+ * client.agent.action.generate({
1508
+ * schemaId,
1509
+ * documentId,
1510
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
1511
+ * instructionParams: {
1512
+ * topic: {
1513
+ * type: 'constant',
1514
+ * value: 'Grapefruit'
1515
+ * },
1516
+ * },
1517
+ * })
1518
+ * ```
1519
+ * #### Field
1520
+ * ```ts
1521
+ * client.agent.action.generate({
1522
+ * schemaId,
1523
+ * documentId,
1524
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
1525
+ * instructionParams: {
1526
+ * pte: {
1527
+ * type: 'field',
1528
+ * path: ['pteField'],
1529
+ * },
1530
+ * },
1531
+ * target: {path: 'keywords' }
1532
+ * })
1533
+ * ```
1534
+ * #### Document
1535
+ * ```ts
1536
+ * client.agent.action.generate({
1537
+ * schemaId,
1538
+ * documentId,
1539
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
1540
+ * instructionParams: {
1541
+ * document: {
1542
+ * type: 'document',
1543
+ * },
1544
+ * },
1545
+ * target: {path: 'keywords' }
1546
+ * })
1547
+ * ```
1548
+ *
1549
+ * #### GROQ
1550
+ * ```ts
1551
+ * client.agent.action.generate({
1552
+ * schemaId,
1553
+ * documentId,
1554
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
1555
+ * instructionParams: {
1556
+ * list: {
1557
+ * type: 'groq',
1558
+ * query: '* [_type==$type].title',
1559
+ * params: {type: 'article'}
1560
+ * },
1561
+ * },
1562
+ * target: {path: 'title' }
1563
+ * })
1564
+ * ```
1565
+ * */
1566
+ instructionParams?: AgentActionParams
1567
+ /**
1568
+ * Target defines which parts of the document will be affected by the instruction.
1569
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
1570
+ *
1571
+ * Omitting target implies that the document itself is the root.
1572
+ *
1573
+ * Notes:
1574
+ * - instruction can only affect fields up to `maxPathDepth`
1575
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
1576
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
1577
+ *
1578
+ * @see AgentActionRequestBase#conditionalPaths
1579
+ */
1580
+ target?: GenerateTarget | GenerateTarget[]
1581
+ }
1582
+
1583
+ /** @beta */
1584
+ declare type GenerateSyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
1585
+ | GenerateExistingDocumentRequest
1586
+ | GenerateTargetDocumentRequest<T>
1587
+ ) &
1588
+ GenerateRequestBase &
1589
+ AgentActionSync
1590
+
1591
+ /** @beta */
1592
+ export declare interface GenerateTarget extends AgentActionTarget {
1593
+ /**
1594
+ * Sets the default operation for all paths in the target.
1595
+ * Generate runs in `'mixed'` operation mode by default:
1596
+ * Changes are set in all non-array fields, and append to all array fields.
1597
+ *
1598
+ * ### Operation types
1599
+ * - `'set'` – an *overwriting* operation, and replaces the full field value.
1600
+ * - `'append'`:
1601
+ * – array fields: appends new items to the end of the array,
1602
+ * - string fields: '"existing content" "new content"'
1603
+ * - text fields: '"existing content"\\n"new content"'
1604
+ * - number fields: existing + new
1605
+ * - other field types not mentioned will set instead (dates, url)
1606
+ * - `'mixed'` – (default) sets non-array fields, and appends to array fields
1607
+ *
1608
+ * The default operation can be overridden on a per-path basis using `include`.
1609
+ *
1610
+ * Nested fields inherit the operation specified by their parent and falls back to the
1611
+ * top level target operation if not otherwise specified.
1612
+ *
1613
+ * Use `include` to change the `operation` of individual fields or items.
1614
+ *
1615
+ * #### Appending in the middle of arrays
1616
+ * `target: {path: ['array'], operation: 'append'}` will append the output of the instruction to the end of the array.
1617
+ *
1618
+ * To insert in the middle of the array, use `target: {path: ['array', {_key: 'appendAfterKey'}], operation: 'append'}`.
1619
+ * Here, the output of the instruction will be appended after the array item with key `'appendAfterKey'`.
1620
+ *
1621
+ * @see #AgentActionTargetInclude.operation
1622
+ * @see #include
1623
+ * @see #AgentActionTargetInclude.include
1624
+ */
1625
+ operation?: GenerateOperation
1626
+ /**
1627
+ * By default, all children up to `target.maxPathDepth` are included.
1628
+ *
1629
+ * When `include` is specified, only segments explicitly listed will be included.
1630
+ *
1631
+ * Fields or array items not on the include list, are implicitly excluded.
1632
+ */
1633
+ include?: (AgentActionPathSegment | GenerateTargetInclude)[]
1634
+ }
1635
+
1636
+ /** @beta */
1637
+ export declare type GenerateTargetDocument<T extends Record<string, Any> = Record<string, Any>> =
1638
+ | {
1639
+ operation: 'edit'
1640
+ _id: string
1641
+ }
1642
+ | {
1643
+ operation: 'create'
1644
+ _id?: string
1645
+ _type: string
1646
+ initialValues?: T
1647
+ }
1648
+ | {
1649
+ operation: 'createIfNotExists'
1650
+ _id: string
1651
+ _type: string
1652
+ initialValues?: T
1653
+ }
1654
+ | {
1655
+ operation: 'createOrReplace'
1656
+ _id: string
1657
+ _type: string
1658
+ initialValues?: T
1659
+ }
1660
+
1661
+ /**
1662
+ * Instruction to create a new document
1663
+ * @beta
1664
+ */
1665
+ declare interface GenerateTargetDocumentRequest<
1666
+ T extends Record<string, Any> = Record<string, Any>,
1667
+ > {
1668
+ targetDocument: GenerateTargetDocument<T>
1669
+ documentId?: never
1670
+ }
1671
+
1672
+ /** @beta */
1673
+ export declare interface GenerateTargetInclude extends AgentActionTargetInclude {
1674
+ /**
1675
+ * Sets the operation for this path, and all its children.
1676
+ * This overrides any operation set parents or the root target.
1677
+ * @see #GenerateTarget.operation
1678
+ * @see #include
1679
+ */
1680
+ operation?: GenerateOperation
1681
+ /**
1682
+ * By default, all children up to `target.maxPathDepth` are included.
1683
+ *
1684
+ * When `include` is specified, only segments explicitly listed will be included.
1685
+ *
1686
+ * Fields or array items not on the include list, are implicitly excluded.
1687
+ */
1688
+ include?: (AgentActionPathSegment | GenerateTargetInclude)[]
1689
+ }
1690
+
1691
+ /**
1692
+ * Includes a LLM-friendly version of GROQ query result in the instruction
1693
+ *
1694
+ * ```ts
1695
+ * client.agent.action.generate({
1696
+ * schemaId,
1697
+ * documentId,
1698
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
1699
+ * instructionParams: {
1700
+ * list: {
1701
+ * type: 'groq',
1702
+ * query: '* [_type==$type].title',
1703
+ * params: {type: 'article'}
1704
+ * },
1705
+ * },
1706
+ * target: {path: 'title' }
1707
+ * })
1708
+ * ```
1709
+ * @beta
1710
+ * */
1711
+ export declare interface GroqAgentActionParam {
1712
+ type: 'groq'
1713
+ query: string
1714
+ params?: Record<string, string>
1715
+ }
1716
+
1717
+ /** @public */
1718
+ export declare type HttpRequest = {
1719
+ (options: RequestOptions, requester: Requester): ReturnType<Requester>
1720
+ }
1721
+
1722
+ /** @public */
1723
+ export declare type HttpRequestEvent<T = unknown> = ResponseEvent<T> | ProgressEvent_2
1724
+
1725
+ /** @public */
1726
+ export declare type IdentifiedSanityDocumentStub<
1727
+ T extends Record<string, Any> = Record<string, Any>,
1728
+ > = {
1729
+ [P in keyof T]: T[P]
1109
1730
  } & {
1110
1731
  _id: string
1111
1732
  } & SanityDocumentStub
@@ -1232,15 +1853,6 @@ export declare interface ListenOptions {
1232
1853
  * @defaultValue `false`
1233
1854
  */
1234
1855
  includePreviousRevision?: boolean
1235
- /**
1236
- * Whether to include events for drafts and versions. As of API Version >= v2025-02-19, only events
1237
- * for published documents will be included by default (see {@link https://www.sanity.io/changelog/676aaa9d-2da6-44fb-abe5-580f28047c10|Changelog})
1238
- * If you need events from drafts and versions, set this to `true`.
1239
- * Note: Keep in mind that additional document variants may be introduced in the future, so it's
1240
- * recommended to respond to events in a way that's tolerant of potential future variants, e.g. by
1241
- * explicitly checking whether the event is for a draft or a version.
1242
- * @defaultValue `false`
1243
- */
1244
1856
  includeAllVersions?: boolean
1245
1857
  /**
1246
1858
  * Whether events should be sent as soon as a transaction has been committed (`transaction`, default),
@@ -1542,62 +2154,55 @@ export declare type MutationSelectionQueryParams = {
1542
2154
  [key: string]: Any
1543
2155
  }
1544
2156
 
1545
- /** @internal */
1546
- export declare class ObservableAssetsClient implements ObservableAssetsClientType {
2157
+ /** @public */
2158
+ declare class ObservableAgentsActionClient {
1547
2159
  #private
1548
2160
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1549
2161
  /**
1550
- * Uploads a file asset to the configured dataset
1551
- *
1552
- * @param assetType - Asset type (file)
1553
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1554
- * @param options - Options to use for the upload
2162
+ * Run an instruction to generate content in a target document.
2163
+ * @param request - instruction request
1555
2164
  */
1556
- upload(
1557
- assetType: 'file',
1558
- body: UploadBody,
1559
- options?: UploadClientConfig,
2165
+ generate<DocumentShape extends Record<string, Any>>(
2166
+ request: GenerateInstruction<DocumentShape>,
1560
2167
  ): Observable<
1561
- HttpRequestEvent<{
1562
- document: SanityAssetDocument
1563
- }>
2168
+ (typeof request)['async'] extends true
2169
+ ? {
2170
+ _id: string
2171
+ }
2172
+ : IdentifiedSanityDocumentStub & DocumentShape
1564
2173
  >
1565
2174
  /**
1566
- * Uploads an image asset to the configured dataset
1567
- *
1568
- * @param assetType - Asset type (image)
1569
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1570
- * @param options - Options to use for the upload
2175
+ * Transform a target document based on a source.
2176
+ * @param request - translation request
1571
2177
  */
1572
- upload(
1573
- assetType: 'image',
1574
- body: UploadBody,
1575
- options?: UploadClientConfig,
2178
+ transform<DocumentShape extends Record<string, Any>>(
2179
+ request: TransformDocument<DocumentShape>,
1576
2180
  ): Observable<
1577
- HttpRequestEvent<{
1578
- document: SanityImageAssetDocument
1579
- }>
2181
+ (typeof request)['async'] extends true
2182
+ ? {
2183
+ _id: string
2184
+ }
2185
+ : IdentifiedSanityDocumentStub & DocumentShape
1580
2186
  >
1581
2187
  /**
1582
- * Uploads a file or an image asset to the configured dataset
1583
- *
1584
- * @param assetType - Asset type (file/image)
1585
- * @param body - Asset content - can be a browser File instance, a Blob, a Node.js Buffer instance or a Node.js ReadableStream.
1586
- * @param options - Options to use for the upload
2188
+ * Translate a target document based on a source.
2189
+ * @param request - translation request
1587
2190
  */
1588
- upload(
1589
- assetType: 'file' | 'image',
1590
- body: UploadBody,
1591
- options?: UploadClientConfig,
2191
+ translate<DocumentShape extends Record<string, Any>>(
2192
+ request: TranslateDocument<DocumentShape>,
1592
2193
  ): Observable<
1593
- HttpRequestEvent<{
1594
- document: SanityAssetDocument | SanityImageAssetDocument
1595
- }>
2194
+ (typeof request)['async'] extends true
2195
+ ? {
2196
+ _id: string
2197
+ }
2198
+ : IdentifiedSanityDocumentStub & DocumentShape
1596
2199
  >
1597
2200
  }
1598
2201
 
1599
2202
  /** @internal */
1600
- declare interface ObservableAssetsClientType {
2203
+ export declare class ObservableAssetsClient {
2204
+ #private
2205
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1601
2206
  /**
1602
2207
  * Uploads a file asset to the configured dataset
1603
2208
  *
@@ -1649,7 +2254,7 @@ declare interface ObservableAssetsClientType {
1649
2254
  }
1650
2255
 
1651
2256
  /** @internal */
1652
- export declare class ObservableDatasetsClient implements ObservableDatasetsClientType {
2257
+ export declare class ObservableDatasetsClient {
1653
2258
  #private
1654
2259
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1655
2260
  /**
@@ -1690,46 +2295,6 @@ export declare class ObservableDatasetsClient implements ObservableDatasetsClien
1690
2295
  list(): Observable<DatasetsResponse>
1691
2296
  }
1692
2297
 
1693
- /** @internal */
1694
- declare interface ObservableDatasetsClientType {
1695
- /**
1696
- * Create a new dataset with the given name
1697
- *
1698
- * @param name - Name of the dataset to create
1699
- * @param options - Options for the dataset
1700
- */
1701
- create(
1702
- name: string,
1703
- options?: {
1704
- aclMode?: DatasetAclMode
1705
- },
1706
- ): Observable<DatasetResponse>
1707
- /**
1708
- * Edit a dataset with the given name
1709
- *
1710
- * @param name - Name of the dataset to edit
1711
- * @param options - New options for the dataset
1712
- */
1713
- edit(
1714
- name: string,
1715
- options?: {
1716
- aclMode?: DatasetAclMode
1717
- },
1718
- ): Observable<DatasetResponse>
1719
- /**
1720
- * Delete a dataset with the given name
1721
- *
1722
- * @param name - Name of the dataset to delete
1723
- */
1724
- delete(name: string): Observable<{
1725
- deleted: true
1726
- }>
1727
- /**
1728
- * Fetch a list of datasets for the configured project
1729
- */
1730
- list(): Observable<DatasetsResponse>
1731
- }
1732
-
1733
2298
  /** @public */
1734
2299
  export declare class ObservablePatch extends BasePatch {
1735
2300
  #private
@@ -1784,14 +2349,14 @@ export declare class ObservablePatch extends BasePatch {
1784
2349
  export declare type ObservablePatchBuilder = (patch: ObservablePatch) => ObservablePatch
1785
2350
 
1786
2351
  /** @internal */
1787
- export declare class ObservableProjectsClient implements ObservableProjectsClientType {
2352
+ export declare class ObservableProjectsClient {
1788
2353
  #private
1789
2354
  constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1790
2355
  /**
1791
2356
  * Fetch a list of projects the authenticated user has access to.
1792
2357
  *
1793
2358
  * @param options - Options for the list request
1794
- * @param options.includeMembers - Whether to include members in the response (default: true)
2359
+ * - `includeMembers` - Whether to include members in the response (default: true)
1795
2360
  */
1796
2361
  list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1797
2362
  list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
@@ -1803,35 +2368,321 @@ export declare class ObservableProjectsClient implements ObservableProjectsClien
1803
2368
  getById(projectId: string): Observable<SanityProject>
1804
2369
  }
1805
2370
 
1806
- /** @internal */
1807
- declare interface ObservableProjectsClientType {
2371
+ /** @public */
2372
+ declare class ObservableReleasesClient {
2373
+ #private
2374
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
1808
2375
  /**
1809
- * Fetch a list of projects the authenticated user has access to.
2376
+ * @public
2377
+ *
2378
+ * Retrieve a release by id.
2379
+ *
2380
+ * @category Releases
2381
+ *
2382
+ * @param params - Release action parameters:
2383
+ * - `releaseId` - The id of the release to retrieve.
2384
+ * @param options - Additional query options including abort signal and query tag.
2385
+ * @returns An observable that resolves to the release document {@link ReleaseDocument}.
2386
+ *
2387
+ * @example Retrieving a release by id
2388
+ * ```ts
2389
+ * client.observable.releases.get({releaseId: 'my-release'}).pipe(
2390
+ * tap((release) => console.log(release)),
2391
+ * // {
2392
+ * // _id: '_.releases.my-release',
2393
+ * // name: 'my-release'
2394
+ * // _type: 'system.release',
2395
+ * // metadata: {releaseType: 'asap'},
2396
+ * // _createdAt: '2021-01-01T00:00:00.000Z',
2397
+ * // ...
2398
+ * // }
2399
+ * ).subscribe()
2400
+ * ```
2401
+ */
2402
+ get(
2403
+ {
2404
+ releaseId,
2405
+ }: {
2406
+ releaseId: string
2407
+ },
2408
+ options?: {
2409
+ signal?: AbortSignal
2410
+ tag?: string
2411
+ },
2412
+ ): Observable<ReleaseDocument | undefined>
2413
+ /**
2414
+ * @public
1810
2415
  *
1811
- * @param options - Options for the list request
1812
- * @param options.includeMembers - Whether to include members in the response (default: true)
2416
+ * Creates a new release under the given id, with metadata.
2417
+ *
2418
+ * @remarks
2419
+ * * If no releaseId is provided, a release id will be generated.
2420
+ * * If no metadata is provided, then an `undecided` releaseType will be used.
2421
+ *
2422
+ * @category Releases
2423
+ *
2424
+ * @param params - Release action parameters:
2425
+ * - `releaseId` - The id of the release to create.
2426
+ * - `metadata` - The metadata to associate with the release {@link ReleaseDocument}.
2427
+ * @param options - Additional action options.
2428
+ * @returns An observable that resolves to the `transactionId` and the release id and metadata.
2429
+ *
2430
+ * @example Creating a release with a custom id and metadata
2431
+ * ```ts
2432
+ * const releaseId = 'my-release'
2433
+ * const metadata: ReleaseDocument['metadata'] = {
2434
+ * releaseType: 'asap',
2435
+ * }
2436
+ *
2437
+ * client.observable.releases.create({releaseId, metadata}).pipe(
2438
+ * tap(({transactionId, releaseId, metadata}) => console.log(transactionId, releaseId, metadata)),
2439
+ * // {
2440
+ * // transactionId: 'transaction-id',
2441
+ * // releaseId: 'my-release',
2442
+ * // metadata: {releaseType: 'asap'},
2443
+ * // }
2444
+ * ).subscribe()
2445
+ * ```
2446
+ *
2447
+ * @example Creating a release with generated id and metadata
2448
+ * ```ts
2449
+ * client.observable.releases.create().pipe(
2450
+ * tap(({metadata}) => console.log(metadata)),
2451
+ * // {
2452
+ * // metadata: {releaseType: 'undecided'},
2453
+ * // }
2454
+ * ).subscribe()
2455
+ * ```
2456
+ *
2457
+ * @example Creating a release using a custom transaction id
2458
+ * ```ts
2459
+ * client.observable.releases.create({transactionId: 'my-transaction-id'}).pipe(
2460
+ * tap(({transactionId, metadata}) => console.log(transactionId, metadata)),
2461
+ * // {
2462
+ * // transactionId: 'my-transaction-id',
2463
+ * // metadata: {releaseType: 'undecided'},
2464
+ * // }
2465
+ * ).subscribe()
2466
+ * ```
2467
+ */
2468
+ create(options: BaseActionOptions): Observable<
2469
+ SingleActionResult & {
2470
+ releaseId: string
2471
+ metadata: ReleaseDocument['metadata']
2472
+ }
2473
+ >
2474
+ create(
2475
+ release: {
2476
+ releaseId?: string
2477
+ metadata?: Partial<ReleaseDocument['metadata']>
2478
+ },
2479
+ options?: BaseActionOptions,
2480
+ ): Observable<
2481
+ SingleActionResult & {
2482
+ releaseId: string
2483
+ metadata: ReleaseDocument['metadata']
2484
+ }
2485
+ >
2486
+ /**
2487
+ * @public
2488
+ *
2489
+ * Edits an existing release, updating the metadata.
2490
+ *
2491
+ * @category Releases
2492
+ *
2493
+ * @param params - Release action parameters:
2494
+ * - `releaseId` - The id of the release to edit.
2495
+ * - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
2496
+ * @param options - Additional action options.
2497
+ * @returns An observable that resolves to the `transactionId`.
1813
2498
  */
1814
- list(options?: {includeMembers?: true}): Observable<SanityProject[]>
1815
- list(options?: {includeMembers?: false}): Observable<Omit<SanityProject, 'members'>[]>
1816
- list(options?: {
1817
- includeMembers?: boolean
1818
- }): Observable<SanityProject[] | Omit<SanityProject, 'members'>[]>
2499
+ edit(
2500
+ {
2501
+ releaseId,
2502
+ patch,
2503
+ }: {
2504
+ releaseId: string
2505
+ patch: PatchOperations
2506
+ },
2507
+ options?: BaseActionOptions,
2508
+ ): Observable<SingleActionResult>
1819
2509
  /**
1820
- * Fetch a project by project ID
2510
+ * @public
1821
2511
  *
1822
- * @param projectId - ID of the project to fetch
2512
+ * Publishes all documents in a release at once. For larger releases the effect of the publish
2513
+ * will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
2514
+ * documents and creation of the corresponding published documents with the new content may
2515
+ * take some time.
2516
+ *
2517
+ * During this period both the source and target documents are locked and cannot be
2518
+ * modified through any other means.
2519
+ *
2520
+ * @category Releases
2521
+ *
2522
+ * @param params - Release action parameters:
2523
+ * - `releaseId` - The id of the release to publish.
2524
+ * @param options - Additional action options.
2525
+ * @returns An observable that resolves to the `transactionId`.
1823
2526
  */
1824
- getById(projectId: string): Observable<SanityProject>
2527
+ publish(
2528
+ {
2529
+ releaseId,
2530
+ }: {
2531
+ releaseId: string
2532
+ },
2533
+ options?: BaseActionOptions,
2534
+ ): Observable<SingleActionResult>
2535
+ /**
2536
+ * @public
2537
+ *
2538
+ * An archive action removes an active release. The documents that comprise the release
2539
+ * are deleted and therefore no longer queryable.
2540
+ *
2541
+ * While the documents remain in retention the last version can still be accessed using document history endpoint.
2542
+ *
2543
+ * @category Releases
2544
+ *
2545
+ * @param params - Release action parameters:
2546
+ * - `releaseId` - The id of the release to archive.
2547
+ * @param options - Additional action options.
2548
+ * @returns An observable that resolves to the `transactionId`.
2549
+ */
2550
+ archive(
2551
+ {
2552
+ releaseId,
2553
+ }: {
2554
+ releaseId: string
2555
+ },
2556
+ options?: BaseActionOptions,
2557
+ ): Observable<SingleActionResult>
2558
+ /**
2559
+ * @public
2560
+ *
2561
+ * An unarchive action restores an archived release and all documents
2562
+ * with the content they had just prior to archiving.
2563
+ *
2564
+ * @category Releases
2565
+ *
2566
+ * @param params - Release action parameters:
2567
+ * - `releaseId` - The id of the release to unarchive.
2568
+ * @param options - Additional action options.
2569
+ * @returns An observable that resolves to the `transactionId`.
2570
+ */
2571
+ unarchive(
2572
+ {
2573
+ releaseId,
2574
+ }: {
2575
+ releaseId: string
2576
+ },
2577
+ options?: BaseActionOptions,
2578
+ ): Observable<SingleActionResult>
2579
+ /**
2580
+ * @public
2581
+ *
2582
+ * A schedule action queues a release for publishing at the given future time.
2583
+ * The release is locked such that no documents in the release can be modified and
2584
+ * no documents that it references can be deleted as this would make the publish fail.
2585
+ * At the given time, the same logic as for the publish action is triggered.
2586
+ *
2587
+ * @category Releases
2588
+ *
2589
+ * @param params - Release action parameters:
2590
+ * - `releaseId` - The id of the release to schedule.
2591
+ * - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
2592
+ * @param options - Additional action options.
2593
+ * @returns An observable that resolves to the `transactionId`.
2594
+ */
2595
+ schedule(
2596
+ {
2597
+ releaseId,
2598
+ publishAt,
2599
+ }: {
2600
+ releaseId: string
2601
+ publishAt: string
2602
+ },
2603
+ options?: BaseActionOptions,
2604
+ ): Observable<SingleActionResult>
2605
+ /**
2606
+ * @public
2607
+ *
2608
+ * An unschedule action stops a release from being published.
2609
+ * The documents in the release are considered unlocked and can be edited again.
2610
+ * This may fail if another release is scheduled to be published after this one and
2611
+ * has a reference to a document created by this one.
2612
+ *
2613
+ * @category Releases
2614
+ *
2615
+ * @param params - Release action parameters:
2616
+ * - `releaseId` - The id of the release to unschedule.
2617
+ * @param options - Additional action options.
2618
+ * @returns An observable that resolves to the `transactionId`.
2619
+ */
2620
+ unschedule(
2621
+ {
2622
+ releaseId,
2623
+ }: {
2624
+ releaseId: string
2625
+ },
2626
+ options?: BaseActionOptions,
2627
+ ): Observable<SingleActionResult>
2628
+ /**
2629
+ * @public
2630
+ *
2631
+ * A delete action removes a published or archived release.
2632
+ * The backing system document will be removed from the dataset.
2633
+ *
2634
+ * @category Releases
2635
+ *
2636
+ * @param params - Release action parameters:
2637
+ * - `releaseId` - The id of the release to delete.
2638
+ * @param options - Additional action options.
2639
+ * @returns An observable that resolves to the `transactionId`.
2640
+ */
2641
+ delete(
2642
+ {
2643
+ releaseId,
2644
+ }: {
2645
+ releaseId: string
2646
+ },
2647
+ options?: BaseActionOptions,
2648
+ ): Observable<SingleActionResult>
2649
+ /**
2650
+ * @public
2651
+ *
2652
+ * Fetch the documents in a release by release id.
2653
+ *
2654
+ * @category Releases
2655
+ *
2656
+ * @param params - Release action parameters:
2657
+ * - `releaseId` - The id of the release to fetch documents for.
2658
+ * @param options - Additional mutation options {@link BaseMutationOptions}.
2659
+ * @returns An observable that resolves to the documents in the release.
2660
+ */
2661
+ fetchDocuments(
2662
+ {
2663
+ releaseId,
2664
+ }: {
2665
+ releaseId: string
2666
+ },
2667
+ options?: BaseMutationOptions,
2668
+ ): Observable<RawQueryResponse<SanityDocument[]>>
1825
2669
  }
1826
2670
 
1827
2671
  /** @public */
1828
- export declare class ObservableSanityClient implements ObservableSanityClientType {
2672
+ export declare class ObservableSanityClient {
1829
2673
  #private
1830
2674
  assets: ObservableAssetsClient
1831
2675
  datasets: ObservableDatasetsClient
1832
2676
  live: LiveClient
1833
2677
  projects: ObservableProjectsClient
1834
2678
  users: ObservableUsersClient
2679
+ agent: {
2680
+ action: ObservableAgentsActionClient
2681
+ }
2682
+ releases: ObservableReleasesClient
2683
+ /**
2684
+ * Instance properties
2685
+ */
1835
2686
  listen: typeof _listen
1836
2687
  constructor(httpRequest: HttpRequest, config?: ClientConfig)
1837
2688
  /**
@@ -1890,7 +2741,7 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
1890
2741
  Q extends QueryWithoutParams | QueryParams = QueryParams,
1891
2742
  const G extends string = string,
1892
2743
  >(
1893
- query: G,
2744
+ query: string,
1894
2745
  params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
1895
2746
  options: UnfilteredResponseQueryOptions,
1896
2747
  ): Observable<RawQueryResponse<ClientReturn<G, R>>>
@@ -1919,7 +2770,9 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
1919
2770
  getDocument<R extends Record<string, Any> = Record<string, Any>>(
1920
2771
  id: string,
1921
2772
  options?: {
2773
+ signal?: AbortSignal
1922
2774
  tag?: string
2775
+ releaseId?: string
1923
2776
  },
1924
2777
  ): Observable<SanityDocument<R> | undefined>
1925
2778
  /**
@@ -2102,6 +2955,90 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
2102
2955
  document: IdentifiedSanityDocumentStub<R>,
2103
2956
  options?: BaseMutationOptions,
2104
2957
  ): Observable<SanityDocument<R>>
2958
+ /**
2959
+ * @public
2960
+ *
2961
+ * Creates a new version of a published document.
2962
+ *
2963
+ * @remarks
2964
+ * * Requires a document with a `_type` property.
2965
+ * * Creating a version with no `releaseId` will create a new draft version of the published document.
2966
+ * * If the `document._id` is defined, it should be a draft or release version ID that matches the version ID generated from `publishedId` and `releaseId`.
2967
+ * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
2968
+ * * To create a version of an unpublished document, use the `client.create` method.
2969
+ *
2970
+ * @category Versions
2971
+ *
2972
+ * @param params - Version action parameters:
2973
+ * - `document` - The document to create as a new version (must include `_type`).
2974
+ * - `publishedId` - The ID of the published document being versioned.
2975
+ * - `releaseId` - The ID of the release to create the version for.
2976
+ * @param options - Additional action options.
2977
+ * @returns an observable that resolves to the `transactionId`.
2978
+ *
2979
+ * @example Creating a new version of a published document with a generated version ID
2980
+ * ```ts
2981
+ * client.observable.createVersion({
2982
+ * // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
2983
+ * document: {_type: 'myDocument', title: 'My Document'},
2984
+ * publishedId: 'myDocument',
2985
+ * releaseId: 'myRelease',
2986
+ * })
2987
+ *
2988
+ * // The following document will be created:
2989
+ * // {
2990
+ * // _id: 'versions.myRelease.myDocument',
2991
+ * // _type: 'myDocument',
2992
+ * // title: 'My Document',
2993
+ * // }
2994
+ * ```
2995
+ *
2996
+ * @example Creating a new version of a published document with a specified version ID
2997
+ * ```ts
2998
+ * client.observable.createVersion({
2999
+ * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
3000
+ * // `publishedId` and `releaseId` are not required since `document._id` has been specified
3001
+ * })
3002
+ *
3003
+ * // The following document will be created:
3004
+ * // {
3005
+ * // _id: 'versions.myRelease.myDocument',
3006
+ * // _type: 'myDocument',
3007
+ * // title: 'My Document',
3008
+ * // }
3009
+ * ```
3010
+ *
3011
+ * @example Creating a new draft version of a published document
3012
+ * ```ts
3013
+ * client.observable.createVersion({
3014
+ * document: {_type: 'myDocument', title: 'My Document'},
3015
+ * publishedId: 'myDocument',
3016
+ * })
3017
+ *
3018
+ * // The following document will be created:
3019
+ * // {
3020
+ * // _id: 'drafts.myDocument',
3021
+ * // _type: 'myDocument',
3022
+ * // title: 'My Document',
3023
+ * // }
3024
+ * ```
3025
+ */
3026
+ createVersion<R extends Record<string, Any>>(
3027
+ args: {
3028
+ document: SanityDocumentStub<R>
3029
+ publishedId: string
3030
+ releaseId?: string
3031
+ },
3032
+ options?: BaseActionOptions,
3033
+ ): Observable<SingleActionResult | MultipleActionResult>
3034
+ createVersion<R extends Record<string, Any>>(
3035
+ args: {
3036
+ document: IdentifiedSanityDocumentStub<R>
3037
+ publishedId?: string
3038
+ releaseId?: string
3039
+ },
3040
+ options?: BaseActionOptions,
3041
+ ): Observable<SingleActionResult | MultipleActionResult>
2105
3042
  /**
2106
3043
  * Deletes a document with the given document ID.
2107
3044
  * Returns an observable that resolves to the deleted document.
@@ -2206,6 +3143,157 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
2206
3143
  selection: MutationSelection,
2207
3144
  options?: BaseMutationOptions,
2208
3145
  ): Observable<SanityDocument<R>>
3146
+ /**
3147
+ * @public
3148
+ *
3149
+ * Deletes the draft or release version of a document.
3150
+ *
3151
+ * @remarks
3152
+ * * Discarding a version with no `releaseId` will discard the draft version of the published document.
3153
+ * * If the draft or release version does not exist, any error will throw.
3154
+ *
3155
+ * @param params - Version action parameters:
3156
+ * - `releaseId` - The ID of the release to discard the document from.
3157
+ * - `publishedId` - The published ID of the document to discard.
3158
+ * @param purge - if `true` the document history is also discarded.
3159
+ * @param options - Additional action options.
3160
+ * @returns an observable that resolves to the `transactionId`.
3161
+ *
3162
+ * @example Discarding a release version of a document
3163
+ * ```ts
3164
+ * client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
3165
+ * // The document with the ID `versions.myRelease.myDocument` will be discarded.
3166
+ * ```
3167
+ *
3168
+ * @example Discarding a draft version of a document
3169
+ * ```ts
3170
+ * client.observable.discardVersion({publishedId: 'myDocument'})
3171
+ * // The document with the ID `drafts.myDocument` will be discarded.
3172
+ * ```
3173
+ */
3174
+ discardVersion(
3175
+ {
3176
+ releaseId,
3177
+ publishedId,
3178
+ }: {
3179
+ releaseId?: string
3180
+ publishedId: string
3181
+ },
3182
+ purge?: boolean,
3183
+ options?: BaseActionOptions,
3184
+ ): Observable<SingleActionResult | MultipleActionResult>
3185
+ /**
3186
+ * @public
3187
+ *
3188
+ * Replaces an existing version document.
3189
+ *
3190
+ * @remarks
3191
+ * * Requires a document with a `_type` property.
3192
+ * * If the `document._id` is defined, it should be a draft or release version ID that matches the version ID generated from `publishedId` and `releaseId`.
3193
+ * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
3194
+ * * Replacing a version with no `releaseId` will replace the draft version of the published document.
3195
+ * * At least one of the **version** or **published** documents must exist.
3196
+ *
3197
+ * @param params - Version action parameters:
3198
+ * - `document` - The new document to replace the version with.
3199
+ * - `releaseId` - The ID of the release where the document version is replaced.
3200
+ * - `publishedId` - The ID of the published document to replace.
3201
+ * @param options - Additional action options.
3202
+ * @returns an observable that resolves to the `transactionId`.
3203
+ *
3204
+ * @example Replacing a release version of a published document with a generated version ID
3205
+ * ```ts
3206
+ * client.observable.replaceVersion({
3207
+ * document: {_type: 'myDocument', title: 'My Document'},
3208
+ * publishedId: 'myDocument',
3209
+ * releaseId: 'myRelease',
3210
+ * })
3211
+ *
3212
+ * // The following document will be patched:
3213
+ * // {
3214
+ * // _id: 'versions.myRelease.myDocument',
3215
+ * // _type: 'myDocument',
3216
+ * // title: 'My Document',
3217
+ * // }
3218
+ * ```
3219
+ *
3220
+ * @example Replacing a release version of a published document with a specified version ID
3221
+ * ```ts
3222
+ * client.observable.replaceVersion({
3223
+ * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
3224
+ * // `publishedId` and `releaseId` are not required since `document._id` has been specified
3225
+ * })
3226
+ *
3227
+ * // The following document will be patched:
3228
+ * // {
3229
+ * // _id: 'versions.myRelease.myDocument',
3230
+ * // _type: 'myDocument',
3231
+ * // title: 'My Document',
3232
+ * // }
3233
+ * ```
3234
+ *
3235
+ * @example Replacing a draft version of a published document
3236
+ * ```ts
3237
+ * client.observable.replaceVersion({
3238
+ * document: {_type: 'myDocument', title: 'My Document'},
3239
+ * publishedId: 'myDocument',
3240
+ * })
3241
+ *
3242
+ * // The following document will be patched:
3243
+ * // {
3244
+ * // _id: 'drafts.myDocument',
3245
+ * // _type: 'myDocument',
3246
+ * // title: 'My Document',
3247
+ * // }
3248
+ * ```
3249
+ */
3250
+ replaceVersion<R extends Record<string, Any>>(
3251
+ args: {
3252
+ document: SanityDocumentStub<R>
3253
+ publishedId: string
3254
+ releaseId?: string
3255
+ },
3256
+ options?: BaseActionOptions,
3257
+ ): Observable<SingleActionResult | MultipleActionResult>
3258
+ replaceVersion<R extends Record<string, Any>>(
3259
+ args: {
3260
+ document: IdentifiedSanityDocumentStub<R>
3261
+ publishedId?: string
3262
+ releaseId?: string
3263
+ },
3264
+ options?: BaseActionOptions,
3265
+ ): Observable<SingleActionResult | MultipleActionResult>
3266
+ /**
3267
+ * @public
3268
+ *
3269
+ * Used to indicate when a document within a release should be unpublished when
3270
+ * the release is run.
3271
+ *
3272
+ * @remarks
3273
+ * * If the published document does not exist, an error will be thrown.
3274
+ *
3275
+ * @param params - Version action parameters:
3276
+ * - `releaseId` - The ID of the release to unpublish the document from.
3277
+ * - `publishedId` - The published ID of the document to unpublish.
3278
+ * @param options - Additional action options.
3279
+ * @returns an observable that resolves to the `transactionId`.
3280
+ *
3281
+ * @example Unpublishing a release version of a published document
3282
+ * ```ts
3283
+ * client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
3284
+ * // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
3285
+ * ```
3286
+ */
3287
+ unpublishVersion(
3288
+ {
3289
+ releaseId,
3290
+ publishedId,
3291
+ }: {
3292
+ releaseId: string
3293
+ publishedId: string
3294
+ },
3295
+ options?: BaseActionOptions,
3296
+ ): Observable<SingleActionResult | MultipleActionResult>
2209
3297
  /**
2210
3298
  * Perform mutation operations against the configured dataset
2211
3299
  * Returns an observable that resolves to the first mutated document.
@@ -2326,1527 +3414,836 @@ export declare class ObservableSanityClient implements ObservableSanityClientTyp
2326
3414
  }
2327
3415
 
2328
3416
  /**
2329
- * The interface implemented by the `ObservableSanityClient` class.
2330
- * When writing code that wants to take an instance of `ObservableSanityClient` as input it's better to use this type,
2331
- * as the `ObservableSanityClient` class has private properties and thus TypeScrict will consider the type incompatible
2332
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
3417
+ * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead
2333
3418
  * @public
2334
3419
  */
2335
- export declare interface ObservableSanityClientType extends SanityClientBase {
2336
- assets: ObservableAssetsClientType
2337
- datasets: ObservableDatasetsClientType
2338
- projects: ObservableProjectsClientType
2339
- users: ObservableUsersClientType
3420
+ export declare class ObservableSanityStegaClient extends ObservableSanityClient {}
3421
+
3422
+ /** @public */
3423
+ export declare class ObservableTransaction extends BaseTransaction {
3424
+ #private
3425
+ constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2340
3426
  /**
2341
- * Clone the client - returns a new instance
3427
+ * Clones the transaction
2342
3428
  */
2343
- clone(): ObservableSanityClientType
3429
+ clone(): ObservableTransaction
2344
3430
  /**
2345
- * Returns the current client configuration
3431
+ * Commit the transaction, returning an observable that produces the first mutated document
3432
+ *
3433
+ * @param options - Options for the mutation operation
2346
3434
  */
2347
- config(): InitializedClientConfig
3435
+ commit<R extends Record<string, Any>>(
3436
+ options: TransactionFirstDocumentMutationOptions,
3437
+ ): Observable<SanityDocument<R>>
2348
3438
  /**
2349
- * Reconfigure the client. Note that this _mutates_ the current client.
3439
+ * Commit the transaction, returning an observable that produces an array of the mutated documents
3440
+ *
3441
+ * @param options - Options for the mutation operation
2350
3442
  */
2351
- config(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
3443
+ commit<R extends Record<string, Any>>(
3444
+ options: TransactionAllDocumentsMutationOptions,
3445
+ ): Observable<SanityDocument<R>[]>
2352
3446
  /**
2353
- * Clone the client with a new (partial) configuration.
3447
+ * Commit the transaction, returning an observable that produces a mutation result object
2354
3448
  *
2355
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3449
+ * @param options - Options for the mutation operation
2356
3450
  */
2357
- withConfig(newConfig?: Partial<ClientConfig>): ObservableSanityClientType
3451
+ commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2358
3452
  /**
2359
- * Perform a GROQ-query against the configured dataset.
3453
+ * Commit the transaction, returning an observable that produces a mutation result object
2360
3454
  *
2361
- * @param query - GROQ-query to perform
3455
+ * @param options - Options for the mutation operation
2362
3456
  */
2363
- fetch<
2364
- R = Any,
2365
- Q extends QueryWithoutParams = QueryWithoutParams,
2366
- const G extends string = string,
2367
- >(
2368
- query: G,
2369
- params?: Q | QueryWithoutParams,
2370
- ): Observable<ClientReturn<G, R>>
3457
+ commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2371
3458
  /**
2372
- * Perform a GROQ-query against the configured dataset.
3459
+ * Commit the transaction, returning an observable that produces a mutation result object
2373
3460
  *
2374
- * @param query - GROQ-query to perform
2375
- * @param params - Optional query parameters
2376
- * @param options - Optional request options
3461
+ * @param options - Options for the mutation operation
2377
3462
  */
2378
- fetch<
2379
- R = Any,
2380
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2381
- const G extends string = string,
2382
- >(
2383
- query: G,
2384
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2385
- options?: FilteredResponseQueryOptions,
2386
- ): Observable<ClientReturn<G, R>>
3463
+ commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2387
3464
  /**
2388
- * Perform a GROQ-query against the configured dataset.
3465
+ * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
3466
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2389
3467
  *
2390
- * @param query - GROQ-query to perform
2391
- * @param params - Optional query parameters
2392
- * @param options - Request options
3468
+ * @param documentId - Document ID to perform the patch operation on
3469
+ * @param patchOps - Operations to perform, or a builder function
2393
3470
  */
2394
- fetch<
2395
- R = Any,
2396
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2397
- const G extends string = string,
2398
- >(
2399
- query: G,
2400
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2401
- options: UnfilteredResponseQueryOptions,
2402
- ): Observable<RawQueryResponse<ClientReturn<G, R>>>
3471
+ patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2403
3472
  /**
2404
- * Perform a GROQ-query against the configured dataset.
3473
+ * Adds the given patch instance to the transaction.
3474
+ * The operation is added to the current transaction, ready to be commited by `commit()`
2405
3475
  *
2406
- * @param query - GROQ-query to perform
2407
- * @param params - Optional query parameters
2408
- * @param options - Request options
3476
+ * @param patch - ObservablePatch to execute
2409
3477
  */
2410
- fetch<
2411
- R = Any,
2412
- Q extends QueryWithoutParams | QueryParams = QueryParams,
2413
- const G extends string = string,
2414
- >(
2415
- query: G,
2416
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
2417
- options: UnfilteredResponseWithoutQuery,
2418
- ): Observable<RawQuerylessQueryResponse<ClientReturn<G, R>>>
3478
+ patch(patch: ObservablePatch): this
3479
+ }
3480
+
3481
+ /** @public */
3482
+ export declare class ObservableUsersClient {
3483
+ #private
3484
+ constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2419
3485
  /**
2420
- * Fetch a single document with the given ID.
3486
+ * Fetch a user by user ID
2421
3487
  *
2422
- * @param id - Document ID to fetch
2423
- * @param options - Request options
3488
+ * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2424
3489
  */
2425
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
2426
- id: string,
2427
- options?: {
2428
- tag?: string
2429
- },
2430
- ): Observable<SanityDocument<R> | undefined>
3490
+ getById<T extends 'me' | string>(
3491
+ id: T,
3492
+ ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
3493
+ }
3494
+
3495
+ /**
3496
+ * The listener connection has been established
3497
+ * note: it's usually a better option to use the 'welcome' event
3498
+ * @public
3499
+ */
3500
+ export declare type OpenEvent = {
3501
+ type: 'open'
3502
+ }
3503
+
3504
+ /** @internal */
3505
+ export declare type PartialExcept<T, K extends keyof T> = Pick<T, K> & Partial<Omit<T, K>>
3506
+
3507
+ /** @public */
3508
+ export declare class Patch extends BasePatch {
3509
+ #private
3510
+ constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2431
3511
  /**
2432
- * Fetch multiple documents in one request.
2433
- * Should be used sparingly - performing a query is usually a better option.
2434
- * The order/position of documents is preserved based on the original array of IDs.
2435
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
2436
- *
2437
- * @param ids - Document IDs to fetch
2438
- * @param options - Request options
3512
+ * Clones the patch
2439
3513
  */
2440
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
2441
- ids: string[],
2442
- options?: {
2443
- tag?: string
2444
- },
2445
- ): Observable<(SanityDocument<R> | null)[]>
3514
+ clone(): Patch
2446
3515
  /**
2447
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2448
- * Returns an observable that resolves to the created document.
3516
+ * Commit the patch, returning a promise that resolves to the first patched document
2449
3517
  *
2450
- * @param document - Document to create
2451
- * @param options - Mutation options
3518
+ * @param options - Options for the mutation operation
2452
3519
  */
2453
- create<R extends Record<string, Any> = Record<string, Any>>(
2454
- document: SanityDocumentStub<R>,
3520
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2455
3521
  options: FirstDocumentMutationOptions,
2456
- ): Observable<SanityDocument<R>>
3522
+ ): Promise<SanityDocument<R>>
2457
3523
  /**
2458
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2459
- * Returns an observable that resolves to an array containing the created document.
3524
+ * Commit the patch, returning a promise that resolves to an array of the mutated documents
2460
3525
  *
2461
- * @param document - Document to create
2462
- * @param options - Mutation options
3526
+ * @param options - Options for the mutation operation
2463
3527
  */
2464
- create<R extends Record<string, Any> = Record<string, Any>>(
2465
- document: SanityDocumentStub<R>,
3528
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2466
3529
  options: AllDocumentsMutationOptions,
2467
- ): Observable<SanityDocument<R>[]>
3530
+ ): Promise<SanityDocument<R>[]>
2468
3531
  /**
2469
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2470
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
3532
+ * Commit the patch, returning a promise that resolves to a mutation result object
2471
3533
  *
2472
- * @param document - Document to create
2473
- * @param options - Mutation options
3534
+ * @param options - Options for the mutation operation
2474
3535
  */
2475
- create<R extends Record<string, Any> = Record<string, Any>>(
2476
- document: SanityDocumentStub<R>,
2477
- options: FirstDocumentIdMutationOptions,
2478
- ): Observable<SingleMutationResult>
3536
+ commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2479
3537
  /**
2480
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2481
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
3538
+ * Commit the patch, returning a promise that resolves to a mutation result object
2482
3539
  *
2483
- * @param document - Document to create
2484
- * @param options - Mutation options
3540
+ * @param options - Options for the mutation operation
2485
3541
  */
2486
- create<R extends Record<string, Any> = Record<string, Any>>(
2487
- document: SanityDocumentStub<R>,
2488
- options: AllDocumentIdsMutationOptions,
2489
- ): Observable<MultipleMutationResult>
3542
+ commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2490
3543
  /**
2491
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
2492
- * Returns an observable that resolves to the created document.
3544
+ * Commit the patch, returning a promise that resolves to the first patched document
2493
3545
  *
2494
- * @param document - Document to create
2495
- * @param options - Mutation options
3546
+ * @param options - Options for the mutation operation
2496
3547
  */
2497
- create<R extends Record<string, Any> = Record<string, Any>>(
2498
- document: SanityDocumentStub<R>,
3548
+ commit<R extends Record<string, Any> = Record<string, Any>>(
2499
3549
  options?: BaseMutationOptions,
2500
- ): Observable<SanityDocument<R>>
3550
+ ): Promise<SanityDocument<R>>
3551
+ }
3552
+
3553
+ /** @public */
3554
+ export declare type PatchBuilder = (patch: Patch) => Patch
3555
+
3556
+ /** @internal */
3557
+ export declare type PatchMutationOperation = PatchOperations & MutationSelection
3558
+
3559
+ /** @internal */
3560
+ export declare interface PatchOperations {
3561
+ set?: {
3562
+ [key: string]: Any
3563
+ }
3564
+ setIfMissing?: {
3565
+ [key: string]: Any
3566
+ }
3567
+ diffMatchPatch?: {
3568
+ [key: string]: Any
3569
+ }
3570
+ unset?: string[]
3571
+ inc?: {
3572
+ [key: string]: number
3573
+ }
3574
+ dec?: {
3575
+ [key: string]: number
3576
+ }
3577
+ insert?: InsertPatch
3578
+ ifRevisionID?: string
3579
+ }
3580
+
3581
+ /** @internal */
3582
+ export declare type PatchSelection = string | string[] | MutationSelection
3583
+
3584
+ /** @public */
3585
+ declare interface ProgressEvent_2 {
3586
+ type: 'progress'
3587
+ stage: 'upload' | 'download'
3588
+ percent: number
3589
+ total?: number
3590
+ loaded?: number
3591
+ lengthComputable: boolean
3592
+ }
3593
+ export {ProgressEvent_2 as ProgressEvent}
3594
+
3595
+ /** @internal */
3596
+ export declare class ProjectsClient {
3597
+ #private
3598
+ constructor(client: SanityClient, httpRequest: HttpRequest)
2501
3599
  /**
2502
- * Create a document if no document with the same ID already exists.
2503
- * Returns an observable that resolves to the created document.
3600
+ * Fetch a list of projects the authenticated user has access to.
2504
3601
  *
2505
- * @param document - Document to create
2506
- * @param options - Mutation options
3602
+ * @param options - Options for the list request
3603
+ * - `includeMembers` - Whether to include members in the response (default: true)
2507
3604
  */
2508
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2509
- document: IdentifiedSanityDocumentStub<R>,
2510
- options: FirstDocumentMutationOptions,
2511
- ): Observable<SanityDocument<R>>
3605
+ list(options?: {includeMembers?: true}): Promise<SanityProject[]>
3606
+ list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
2512
3607
  /**
2513
- * Create a document if no document with the same ID already exists.
2514
- * Returns an observable that resolves to an array containing the created document.
3608
+ * Fetch a project by project ID
2515
3609
  *
2516
- * @param document - Document to create
2517
- * @param options - Mutation options
3610
+ * @param projectId - ID of the project to fetch
2518
3611
  */
2519
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2520
- document: IdentifiedSanityDocumentStub<R>,
2521
- options: AllDocumentsMutationOptions,
2522
- ): Observable<SanityDocument<R>[]>
2523
- /**
2524
- * Create a document if no document with the same ID already exists.
2525
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2526
- *
2527
- * @param document - Document to create
2528
- * @param options - Mutation options
2529
- */
2530
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2531
- document: IdentifiedSanityDocumentStub<R>,
2532
- options: FirstDocumentIdMutationOptions,
2533
- ): Observable<SingleMutationResult>
2534
- /**
2535
- * Create a document if no document with the same ID already exists.
2536
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2537
- *
2538
- * @param document - Document to create
2539
- * @param options - Mutation options
2540
- */
2541
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2542
- document: IdentifiedSanityDocumentStub<R>,
2543
- options: AllDocumentIdsMutationOptions,
2544
- ): Observable<MultipleMutationResult>
2545
- /**
2546
- * Create a document if no document with the same ID already exists.
2547
- * Returns an observable that resolves to the created document.
2548
- *
2549
- * @param document - Document to create
2550
- * @param options - Mutation options
2551
- */
2552
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
2553
- document: IdentifiedSanityDocumentStub<R>,
2554
- options?: BaseMutationOptions,
2555
- ): Observable<SanityDocument<R>>
2556
- /**
2557
- * Create a document if it does not exist, or replace a document with the same document ID
2558
- * Returns an observable that resolves to the created document.
2559
- *
2560
- * @param document - Document to either create or replace
2561
- * @param options - Mutation options
2562
- */
2563
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2564
- document: IdentifiedSanityDocumentStub<R>,
2565
- options: FirstDocumentMutationOptions,
2566
- ): Observable<SanityDocument<R>>
2567
- /**
2568
- * Create a document if it does not exist, or replace a document with the same document ID
2569
- * Returns an observable that resolves to an array containing the created document.
2570
- *
2571
- * @param document - Document to either create or replace
2572
- * @param options - Mutation options
2573
- */
2574
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2575
- document: IdentifiedSanityDocumentStub<R>,
2576
- options: AllDocumentsMutationOptions,
2577
- ): Observable<SanityDocument<R>[]>
2578
- /**
2579
- * Create a document if it does not exist, or replace a document with the same document ID
2580
- * Returns an observable that resolves to a mutation result object containing the ID of the created document.
2581
- *
2582
- * @param document - Document to either create or replace
2583
- * @param options - Mutation options
2584
- */
2585
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2586
- document: IdentifiedSanityDocumentStub<R>,
2587
- options: FirstDocumentIdMutationOptions,
2588
- ): Observable<SingleMutationResult>
2589
- /**
2590
- * Create a document if it does not exist, or replace a document with the same document ID
2591
- * Returns an observable that resolves to a mutation result object containing the created document ID.
2592
- *
2593
- * @param document - Document to either create or replace
2594
- * @param options - Mutation options
2595
- */
2596
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2597
- document: IdentifiedSanityDocumentStub<R>,
2598
- options: AllDocumentIdsMutationOptions,
2599
- ): Observable<MultipleMutationResult>
2600
- /**
2601
- * Create a document if it does not exist, or replace a document with the same document ID
2602
- * Returns an observable that resolves to the created document.
2603
- *
2604
- * @param document - Document to either create or replace
2605
- * @param options - Mutation options
2606
- */
2607
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
2608
- document: IdentifiedSanityDocumentStub<R>,
2609
- options?: BaseMutationOptions,
2610
- ): Observable<SanityDocument<R>>
2611
- /**
2612
- * Deletes a document with the given document ID.
2613
- * Returns an observable that resolves to the deleted document.
2614
- *
2615
- * @param id - Document ID to delete
2616
- * @param options - Options for the mutation
2617
- */
2618
- delete<R extends Record<string, Any> = Record<string, Any>>(
2619
- id: string,
2620
- options: FirstDocumentMutationOptions,
2621
- ): Observable<SanityDocument<R>>
2622
- /**
2623
- * Deletes a document with the given document ID.
2624
- * Returns an observable that resolves to an array containing the deleted document.
2625
- *
2626
- * @param id - Document ID to delete
2627
- * @param options - Options for the mutation
2628
- */
2629
- delete<R extends Record<string, Any> = Record<string, Any>>(
2630
- id: string,
2631
- options: AllDocumentsMutationOptions,
2632
- ): Observable<SanityDocument<R>[]>
2633
- /**
2634
- * Deletes a document with the given document ID.
2635
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2636
- *
2637
- * @param id - Document ID to delete
2638
- * @param options - Options for the mutation
2639
- */
2640
- delete(id: string, options: FirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2641
- /**
2642
- * Deletes a document with the given document ID.
2643
- * Returns an observable that resolves to a mutation result object containing the deleted document ID.
2644
- *
2645
- * @param id - Document ID to delete
2646
- * @param options - Options for the mutation
2647
- */
2648
- delete(id: string, options: AllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2649
- /**
2650
- * Deletes a document with the given document ID.
2651
- * Returns an observable that resolves to the deleted document.
2652
- *
2653
- * @param id - Document ID to delete
2654
- * @param options - Options for the mutation
2655
- */
2656
- delete<R extends Record<string, Any> = Record<string, Any>>(
2657
- id: string,
2658
- options?: BaseMutationOptions,
2659
- ): Observable<SanityDocument<R>>
2660
- /**
2661
- * Deletes one or more documents matching the given query or document ID.
2662
- * Returns an observable that resolves to first deleted document.
2663
- *
2664
- * @param selection - An object with either an `id` or `query` key defining what to delete
2665
- * @param options - Options for the mutation
2666
- */
2667
- delete<R extends Record<string, Any> = Record<string, Any>>(
2668
- selection: MutationSelection,
2669
- options: FirstDocumentMutationOptions,
2670
- ): Observable<SanityDocument<R>>
2671
- /**
2672
- * Deletes one or more documents matching the given query or document ID.
2673
- * Returns an observable that resolves to an array containing the deleted documents.
2674
- *
2675
- * @param selection - An object with either an `id` or `query` key defining what to delete
2676
- * @param options - Options for the mutation
2677
- */
2678
- delete<R extends Record<string, Any> = Record<string, Any>>(
2679
- selection: MutationSelection,
2680
- options: AllDocumentsMutationOptions,
2681
- ): Observable<SanityDocument<R>[]>
2682
- /**
2683
- * Deletes one or more documents matching the given query or document ID.
2684
- * Returns an observable that resolves to a mutation result object containing the ID of the first deleted document.
2685
- *
2686
- * @param selection - An object with either an `id` or `query` key defining what to delete
2687
- * @param options - Options for the mutation
2688
- */
2689
- delete(
2690
- selection: MutationSelection,
2691
- options: FirstDocumentIdMutationOptions,
2692
- ): Observable<SingleMutationResult>
2693
- /**
2694
- * Deletes one or more documents matching the given query or document ID.
2695
- * Returns an observable that resolves to a mutation result object containing the document IDs that were deleted.
2696
- *
2697
- * @param selection - An object with either an `id` or `query` key defining what to delete
2698
- * @param options - Options for the mutation
2699
- */
2700
- delete(
2701
- selection: MutationSelection,
2702
- options: AllDocumentIdsMutationOptions,
2703
- ): Observable<MultipleMutationResult>
2704
- /**
2705
- * Deletes one or more documents matching the given query or document ID.
2706
- * Returns an observable that resolves to first deleted document.
2707
- *
2708
- * @param selection - An object with either an `id` or `query` key defining what to delete
2709
- * @param options - Options for the mutation
2710
- */
2711
- delete<R extends Record<string, Any> = Record<string, Any>>(
2712
- selection: MutationSelection,
2713
- options?: BaseMutationOptions,
2714
- ): Observable<SanityDocument<R>>
2715
- /**
2716
- * Perform mutation operations against the configured dataset
2717
- * Returns an observable that resolves to the first mutated document.
2718
- *
2719
- * @param operations - Mutation operations to execute
2720
- * @param options - Mutation options
2721
- */
2722
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2723
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2724
- options: FirstDocumentMutationOptions,
2725
- ): Observable<SanityDocument<R>>
2726
- /**
2727
- * Perform mutation operations against the configured dataset.
2728
- * Returns an observable that resolves to an array of the mutated documents.
2729
- *
2730
- * @param operations - Mutation operations to execute
2731
- * @param options - Mutation options
2732
- */
2733
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2734
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2735
- options: AllDocumentsMutationOptions,
2736
- ): Observable<SanityDocument<R>[]>
2737
- /**
2738
- * Perform mutation operations against the configured dataset
2739
- * Returns an observable that resolves to a mutation result object containing the document ID of the first mutated document.
2740
- *
2741
- * @param operations - Mutation operations to execute
2742
- * @param options - Mutation options
2743
- */
2744
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2745
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2746
- options: FirstDocumentIdMutationOptions,
2747
- ): Observable<SingleMutationResult>
2748
- /**
2749
- * Perform mutation operations against the configured dataset
2750
- * Returns an observable that resolves to a mutation result object containing the mutated document IDs.
2751
- *
2752
- * @param operations - Mutation operations to execute
2753
- * @param options - Mutation options
2754
- */
2755
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2756
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2757
- options: AllDocumentIdsMutationOptions,
2758
- ): Observable<MultipleMutationResult>
2759
- /**
2760
- * Perform mutation operations against the configured dataset
2761
- * Returns an observable that resolves to the first mutated document.
2762
- *
2763
- * @param operations - Mutation operations to execute
2764
- * @param options - Mutation options
2765
- */
2766
- mutate<R extends Record<string, Any> = Record<string, Any>>(
2767
- operations: Mutation<R>[] | ObservablePatch | ObservableTransaction,
2768
- options?: BaseMutationOptions,
2769
- ): Observable<SanityDocument<R>>
2770
- /**
2771
- * Create a new buildable patch of operations to perform
2772
- *
2773
- * @param documentId - Document ID to patch
2774
- * @param operations - Optional object of patch operations to initialize the patch instance with
2775
- * @returns Patch instance - call `.commit()` to perform the operations defined
2776
- */
2777
- patch(documentId: string, operations?: PatchOperations): ObservablePatch
2778
- /**
2779
- * Create a new buildable patch of operations to perform
2780
- *
2781
- * @param documentIds - Array of document IDs to patch
2782
- * @param operations - Optional object of patch operations to initialize the patch instance with
2783
- * @returns Patch instance - call `.commit()` to perform the operations defined
2784
- */
2785
- patch(documentIds: string[], operations?: PatchOperations): ObservablePatch
2786
- /**
2787
- * Create a new buildable patch of operations to perform
2788
- *
2789
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
2790
- * @param operations - Optional object of patch operations to initialize the patch instance with
2791
- * @returns Patch instance - call `.commit()` to perform the operations defined
2792
- */
2793
- patch(selection: MutationSelection, operations?: PatchOperations): ObservablePatch
2794
- /**
2795
- * Create a new buildable patch of operations to perform
2796
- *
2797
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
2798
- * @param operations - Optional object of patch operations to initialize the patch instance with
2799
- * @returns Patch instance - call `.commit()` to perform the operations defined
2800
- */
2801
- patch(selection: PatchSelection, operations?: PatchOperations): ObservablePatch
2802
- /**
2803
- * Create a new transaction of mutations
2804
- *
2805
- * @param operations - Optional array of mutation operations to initialize the transaction instance with
2806
- */
2807
- transaction<R extends Record<string, Any> = Record<string, Any>>(
2808
- operations?: Mutation<R>[],
2809
- ): ObservableTransaction
2810
- /**
2811
- * Perform action operations against the configured dataset
2812
- *
2813
- * @param operations - Action operation(s) to execute
2814
- * @param options - Action options
2815
- */
2816
- action(
2817
- operations: Action | Action[],
2818
- options?: BaseActionOptions,
2819
- ): Observable<SingleActionResult | MultipleActionResult>
2820
- /**
2821
- * Perform an HTTP request against the Sanity API
2822
- *
2823
- * @param options - Request options
2824
- */
2825
- request<R = Any>(options: RawRequestOptions): Observable<R>
2826
- }
2827
-
2828
- /**
2829
- * @deprecated -- Use `import {ObservableSanityClient} from '@sanity/client'` instead
2830
- * @public
2831
- */
2832
- export declare class ObservableSanityStegaClient extends ObservableSanityClient {}
2833
-
2834
- /** @public */
2835
- export declare class ObservableTransaction extends BaseTransaction {
2836
- #private
2837
- constructor(operations?: Mutation[], client?: ObservableSanityClient, transactionId?: string)
2838
- /**
2839
- * Clones the transaction
2840
- */
2841
- clone(): ObservableTransaction
2842
- /**
2843
- * Commit the transaction, returning an observable that produces the first mutated document
2844
- *
2845
- * @param options - Options for the mutation operation
2846
- */
2847
- commit<R extends Record<string, Any>>(
2848
- options: TransactionFirstDocumentMutationOptions,
2849
- ): Observable<SanityDocument<R>>
2850
- /**
2851
- * Commit the transaction, returning an observable that produces an array of the mutated documents
2852
- *
2853
- * @param options - Options for the mutation operation
2854
- */
2855
- commit<R extends Record<string, Any>>(
2856
- options: TransactionAllDocumentsMutationOptions,
2857
- ): Observable<SanityDocument<R>[]>
2858
- /**
2859
- * Commit the transaction, returning an observable that produces a mutation result object
2860
- *
2861
- * @param options - Options for the mutation operation
2862
- */
2863
- commit(options: TransactionFirstDocumentIdMutationOptions): Observable<SingleMutationResult>
2864
- /**
2865
- * Commit the transaction, returning an observable that produces a mutation result object
2866
- *
2867
- * @param options - Options for the mutation operation
2868
- */
2869
- commit(options: TransactionAllDocumentIdsMutationOptions): Observable<MultipleMutationResult>
2870
- /**
2871
- * Commit the transaction, returning an observable that produces a mutation result object
2872
- *
2873
- * @param options - Options for the mutation operation
2874
- */
2875
- commit(options?: BaseMutationOptions): Observable<MultipleMutationResult>
2876
- /**
2877
- * Performs a patch on the given document ID. Can either be a builder function or an object of patch operations.
2878
- * The operation is added to the current transaction, ready to be commited by `commit()`
2879
- *
2880
- * @param documentId - Document ID to perform the patch operation on
2881
- * @param patchOps - Operations to perform, or a builder function
2882
- */
2883
- patch(documentId: string, patchOps?: ObservablePatchBuilder | PatchOperations): this
2884
- /**
2885
- * Adds the given patch instance to the transaction.
2886
- * The operation is added to the current transaction, ready to be commited by `commit()`
2887
- *
2888
- * @param patch - ObservablePatch to execute
2889
- */
2890
- patch(patch: ObservablePatch): this
2891
- }
2892
-
2893
- /** @public */
2894
- export declare class ObservableUsersClient implements ObservableUsersClientType {
2895
- #private
2896
- constructor(client: ObservableSanityClient, httpRequest: HttpRequest)
2897
- /**
2898
- * Fetch a user by user ID
2899
- *
2900
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2901
- */
2902
- getById<T extends 'me' | string>(
2903
- id: T,
2904
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2905
- }
2906
-
2907
- /** @internal */
2908
- declare interface ObservableUsersClientType {
2909
- /**
2910
- * Fetch a user by user ID
2911
- *
2912
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
2913
- */
2914
- getById<T extends 'me' | string>(
2915
- id: T,
2916
- ): Observable<T extends 'me' ? CurrentSanityUser : SanityUser>
2917
- }
2918
-
2919
- /**
2920
- * The listener connection has been established
2921
- * note: it's usually a better option to use the 'welcome' event
2922
- * @public
2923
- */
2924
- export declare type OpenEvent = {
2925
- type: 'open'
2926
- }
2927
-
2928
- /** @public */
2929
- export declare class Patch extends BasePatch {
2930
- #private
2931
- constructor(selection: PatchSelection, operations?: PatchOperations, client?: SanityClient)
2932
- /**
2933
- * Clones the patch
2934
- */
2935
- clone(): Patch
2936
- /**
2937
- * Commit the patch, returning a promise that resolves to the first patched document
2938
- *
2939
- * @param options - Options for the mutation operation
2940
- */
2941
- commit<R extends Record<string, Any> = Record<string, Any>>(
2942
- options: FirstDocumentMutationOptions,
2943
- ): Promise<SanityDocument<R>>
2944
- /**
2945
- * Commit the patch, returning a promise that resolves to an array of the mutated documents
2946
- *
2947
- * @param options - Options for the mutation operation
2948
- */
2949
- commit<R extends Record<string, Any> = Record<string, Any>>(
2950
- options: AllDocumentsMutationOptions,
2951
- ): Promise<SanityDocument<R>[]>
2952
- /**
2953
- * Commit the patch, returning a promise that resolves to a mutation result object
2954
- *
2955
- * @param options - Options for the mutation operation
2956
- */
2957
- commit(options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
2958
- /**
2959
- * Commit the patch, returning a promise that resolves to a mutation result object
2960
- *
2961
- * @param options - Options for the mutation operation
2962
- */
2963
- commit(options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
2964
- /**
2965
- * Commit the patch, returning a promise that resolves to the first patched document
2966
- *
2967
- * @param options - Options for the mutation operation
2968
- */
2969
- commit<R extends Record<string, Any> = Record<string, Any>>(
2970
- options?: BaseMutationOptions,
2971
- ): Promise<SanityDocument<R>>
2972
- }
2973
-
2974
- /** @public */
2975
- export declare type PatchBuilder = (patch: Patch) => Patch
2976
-
2977
- /** @internal */
2978
- export declare type PatchMutationOperation = PatchOperations & MutationSelection
2979
-
2980
- /** @internal */
2981
- export declare interface PatchOperations {
2982
- set?: {
2983
- [key: string]: Any
2984
- }
2985
- setIfMissing?: {
2986
- [key: string]: Any
2987
- }
2988
- diffMatchPatch?: {
2989
- [key: string]: Any
2990
- }
2991
- unset?: string[]
2992
- inc?: {
2993
- [key: string]: number
2994
- }
2995
- dec?: {
2996
- [key: string]: number
2997
- }
2998
- insert?: InsertPatch
2999
- ifRevisionID?: string
3000
- }
3001
-
3002
- /** @internal */
3003
- export declare type PatchSelection = string | string[] | MutationSelection
3004
-
3005
- /** @public */
3006
- declare interface ProgressEvent_2 {
3007
- type: 'progress'
3008
- stage: 'upload' | 'download'
3009
- percent: number
3010
- total?: number
3011
- loaded?: number
3012
- lengthComputable: boolean
3013
- }
3014
- export {ProgressEvent_2 as ProgressEvent}
3015
-
3016
- /** @internal */
3017
- export declare class ProjectsClient implements ProjectsClientType {
3018
- #private
3019
- constructor(client: SanityClient, httpRequest: HttpRequest)
3020
- /**
3021
- * Fetch a list of projects the authenticated user has access to.
3022
- *
3023
- * @param options - Options for the list request
3024
- * @param options.includeMembers - Whether to include members in the response (default: true)
3025
- */
3026
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
3027
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
3028
- /**
3029
- * Fetch a project by project ID
3030
- *
3031
- * @param projectId - ID of the project to fetch
3032
- */
3033
- getById(projectId: string): Promise<SanityProject>
3034
- }
3035
-
3036
- /** @internal */
3037
- declare interface ProjectsClientType {
3038
- /**
3039
- * Fetch a list of projects the authenticated user has access to.
3040
- *
3041
- * @param options - Options for the list request
3042
- * @param options.includeMembers - Whether to include members in the response (default: true)
3043
- */
3044
- list(options?: {includeMembers?: true}): Promise<SanityProject[]>
3045
- list(options?: {includeMembers?: false}): Promise<Omit<SanityProject, 'members'>[]>
3046
- list(options?: {includeMembers?: boolean}): Promise<SanityProject[]>
3047
- /**
3048
- * Fetch a project by project ID
3049
- *
3050
- * @param projectId - ID of the project to fetch
3051
- */
3052
- getById(projectId: string): Promise<SanityProject>
3053
- }
3054
-
3055
- /**
3056
- * Publishes a draft document.
3057
- * If a published version of the document already exists this is replaced by the current draft document.
3058
- * In either case the draft document is deleted.
3059
- * The optional revision id parameters can be used for optimistic locking to ensure
3060
- * that the draft and/or published versions of the document have not been changed by another client.
3061
- *
3062
- * @public
3063
- */
3064
- export declare type PublishAction = {
3065
- actionType: 'sanity.action.document.publish'
3066
- /**
3067
- * Draft document ID to publish
3068
- */
3069
- draftId: string
3070
- /**
3071
- * Draft revision ID to match
3072
- */
3073
- ifDraftRevisionId?: string
3074
- /**
3075
- * Published document ID to replace
3076
- */
3077
- publishedId: string
3078
- /**
3079
- * Published revision ID to match
3080
- */
3081
- ifPublishedRevisionId?: string
3082
- }
3083
-
3084
- /** @public */
3085
- export declare type QueryOptions =
3086
- | FilteredResponseQueryOptions
3087
- | UnfilteredResponseQueryOptions
3088
- | UnfilteredResponseWithoutQuery
3089
-
3090
- /** @public */
3091
- export declare interface QueryParams {
3092
- [key: string]: any
3093
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3094
- body?: never
3095
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3096
- cache?: 'next' extends keyof RequestInit ? never : any
3097
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3098
- filterResponse?: never
3099
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3100
- headers?: never
3101
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3102
- method?: never
3103
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3104
- next?: 'next' extends keyof RequestInit ? never : any
3105
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3106
- perspective?: never
3107
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3108
- query?: never
3109
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3110
- resultSourceMap?: never
3111
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3112
- returnQuery?: never
3113
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3114
- signal?: never
3115
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3116
- stega?: never
3117
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3118
- tag?: never
3119
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3120
- timeout?: never
3121
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3122
- token?: never
3123
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3124
- useCdn?: never
3125
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3126
- lastLiveEventId?: never
3127
- /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3128
- cacheMode?: never
3129
- }
3130
-
3131
- /**
3132
- * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
3133
- * @public
3134
- */
3135
- export declare type QueryWithoutParams = Record<string, never> | undefined
3136
-
3137
- /** @public */
3138
- export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
3139
-
3140
- /** @public */
3141
- export declare interface RawQueryResponse<R> {
3142
- query: string
3143
- ms: number
3144
- result: R
3145
- resultSourceMap?: ContentSourceMap
3146
- /** Requires `apiVersion` to be `2021-03-25` or later. */
3147
- syncTags?: SyncTag[]
3148
- }
3149
-
3150
- /** @internal */
3151
- export declare interface RawRequestOptions {
3152
- url?: string
3153
- uri?: string
3154
- method?: string
3155
- token?: string
3156
- json?: boolean
3157
- tag?: string
3158
- useGlobalApi?: boolean
3159
- withCredentials?: boolean
3160
- query?: {
3161
- [key: string]: string | string[]
3162
- }
3163
- headers?: {
3164
- [key: string]: string
3165
- }
3166
- timeout?: number
3167
- proxy?: string
3168
- body?: Any
3169
- maxRedirects?: number
3170
- signal?: AbortSignal
3171
- }
3172
-
3173
- /**
3174
- * The listener has been disconnected, and a reconnect attempt is scheduled.
3175
- *
3176
- * @public
3177
- */
3178
- export declare type ReconnectEvent = {
3179
- type: 'reconnect'
3180
- }
3181
-
3182
- /**
3183
- * @public
3184
- * @deprecated – The `r`-prefix is not required, use `string` instead
3185
- */
3186
- export declare type ReleaseId = `r${string}`
3187
-
3188
- /**
3189
- * Replaces an existing draft document.
3190
- * At least one of the draft or published versions of the document must exist.
3191
- *
3192
- * @public
3193
- */
3194
- export declare type ReplaceDraftAction = {
3195
- actionType: 'sanity.action.document.replaceDraft'
3196
- /**
3197
- * Published document ID to create draft from, if draft does not exist
3198
- */
3199
- publishedId: string
3200
- /**
3201
- * Document to create if it does not already exist. Requires `_id` and `_type` properties.
3202
- */
3203
- attributes: IdentifiedSanityDocumentStub
3204
- }
3205
-
3206
- /**
3207
- * @deprecated -- Use `import {requester} from '@sanity/client'` instead
3208
- * @public
3209
- */
3210
- export declare const requester: Requester
3211
-
3212
- /** @internal */
3213
- export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
3214
- url?: string
3215
- uri?: string
3216
- canUseCdn?: boolean
3217
- useCdn?: boolean
3218
- tag?: string
3219
- returnQuery?: boolean
3220
- resultSourceMap?: boolean | 'withKeyArraySelector'
3221
- perspective?: ClientPerspective
3222
- lastLiveEventId?: string
3223
- cacheMode?: 'noStale'
3224
- }
3225
-
3226
- /** @public */
3227
- export declare interface RequestOptions {
3228
- timeout?: number
3229
- token?: string
3230
- tag?: string
3231
- headers?: Record<string, string>
3232
- method?: string
3233
- query?: Any
3234
- body?: Any
3235
- signal?: AbortSignal
3236
- }
3237
-
3238
- /** @alpha */
3239
- export declare type ResolveStudioUrl = (
3240
- sourceDocument: ContentSourceMapDocuments_2[number],
3241
- ) => StudioUrl
3242
-
3243
- /** @public */
3244
- export declare interface ResponseEvent<T = unknown> {
3245
- type: 'response'
3246
- body: T
3247
- url: string
3248
- method: string
3249
- statusCode: number
3250
- statusMessage?: string
3251
- headers: Record<string, string>
3252
- }
3253
-
3254
- /** @public */
3255
- export declare interface ResponseQueryOptions extends RequestOptions {
3256
- perspective?: ClientPerspective
3257
- resultSourceMap?: boolean | 'withKeyArraySelector'
3258
- returnQuery?: boolean
3259
- useCdn?: boolean
3260
- stega?: boolean | StegaConfig
3261
- cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
3262
- next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
3263
- lastLiveEventId?: string | string[] | null
3264
- /**
3265
- * When set to `noStale`, APICDN will not return a cached response if the content is stale.
3266
- * Tradeoff between latency and freshness of content.
3267
- *
3268
- * Only to be used with live content queries and when useCdn is true.
3269
- */
3270
- cacheMode?: 'noStale'
3271
- }
3272
-
3273
- /** @internal */
3274
- export declare interface SanityAssetDocument extends SanityDocument {
3275
- url: string
3276
- path: string
3277
- size: number
3278
- assetId: string
3279
- mimeType: string
3280
- sha1hash: string
3281
- extension: string
3282
- uploadId?: string
3283
- originalFilename?: string
3284
- }
3285
-
3286
- /** @public */
3287
- export declare class SanityClient implements SanityClientType {
3288
- #private
3289
- assets: AssetsClient
3290
- datasets: DatasetsClient
3291
- live: LiveClient
3292
- projects: ProjectsClient
3293
- users: UsersClient
3294
- /**
3295
- * Observable version of the Sanity client, with the same configuration as the promise-based one
3296
- */
3297
- observable: ObservableSanityClient
3298
- listen: typeof _listen
3299
- constructor(httpRequest: HttpRequest, config?: ClientConfig)
3300
- /**
3301
- * Clone the client - returns a new instance
3302
- */
3303
- clone(): SanityClient
3304
- /**
3305
- * Returns the current client configuration
3306
- */
3307
- config(): InitializedClientConfig
3308
- /**
3309
- * Reconfigure the client. Note that this _mutates_ the current client.
3310
- */
3311
- config(newConfig?: Partial<ClientConfig>): this
3312
- /**
3313
- * Clone the client with a new (partial) configuration.
3314
- *
3315
- * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3316
- */
3317
- withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3318
- /**
3319
- * Perform a GROQ-query against the configured dataset.
3320
- *
3321
- * @param query - GROQ-query to perform
3322
- */
3323
- fetch<
3324
- R = Any,
3325
- Q extends QueryWithoutParams = QueryWithoutParams,
3326
- const G extends string = string,
3327
- >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3328
- /**
3329
- * Perform a GROQ-query against the configured dataset.
3330
- *
3331
- * @param query - GROQ-query to perform
3332
- * @param params - Optional query parameters
3333
- * @param options - Optional request options
3334
- */
3335
- fetch<
3336
- R = Any,
3337
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3338
- const G extends string = string,
3339
- >(
3340
- query: G,
3341
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3342
- options?: FilteredResponseQueryOptions,
3343
- ): Promise<ClientReturn<G, R>>
3344
- /**
3345
- * Perform a GROQ-query against the configured dataset.
3346
- *
3347
- * @param query - GROQ-query to perform
3348
- * @param params - Optional query parameters
3349
- * @param options - Request options
3350
- */
3351
- fetch<
3352
- R = Any,
3353
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3354
- const G extends string = string,
3355
- >(
3356
- query: G,
3357
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3358
- options: UnfilteredResponseQueryOptions,
3359
- ): Promise<RawQueryResponse<ClientReturn<G, R>>>
3360
- /**
3361
- * Perform a GROQ-query against the configured dataset.
3362
- *
3363
- * @param query - GROQ-query to perform
3364
- * @param params - Optional query parameters
3365
- * @param options - Request options
3366
- */
3367
- fetch<
3368
- R = Any,
3369
- Q extends QueryWithoutParams | QueryParams = QueryParams,
3370
- const G extends string = string,
3371
- >(
3372
- query: G,
3373
- params: Q extends QueryWithoutParams ? QueryWithoutParams : Q,
3374
- options: UnfilteredResponseWithoutQuery,
3375
- ): Promise<RawQuerylessQueryResponse<ClientReturn<G, R>>>
3376
- /**
3377
- * Fetch a single document with the given ID.
3378
- *
3379
- * @param id - Document ID to fetch
3380
- * @param options - Request options
3381
- */
3382
- getDocument<R extends Record<string, Any> = Record<string, Any>>(
3383
- id: string,
3384
- options?: {
3385
- signal?: AbortSignal
3386
- tag?: string
3387
- },
3388
- ): Promise<SanityDocument<R> | undefined>
3389
- /**
3390
- * Fetch multiple documents in one request.
3391
- * Should be used sparingly - performing a query is usually a better option.
3392
- * The order/position of documents is preserved based on the original array of IDs.
3393
- * If any of the documents are missing, they will be replaced by a `null` entry in the returned array
3394
- *
3395
- * @param ids - Document IDs to fetch
3396
- * @param options - Request options
3397
- */
3398
- getDocuments<R extends Record<string, Any> = Record<string, Any>>(
3399
- ids: string[],
3400
- options?: {
3401
- signal?: AbortSignal
3402
- tag?: string
3403
- },
3404
- ): Promise<(SanityDocument<R> | null)[]>
3405
- /**
3406
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3407
- * Returns a promise that resolves to the created document.
3408
- *
3409
- * @param document - Document to create
3410
- * @param options - Mutation options
3411
- */
3412
- create<R extends Record<string, Any> = Record<string, Any>>(
3413
- document: SanityDocumentStub<R>,
3414
- options: FirstDocumentMutationOptions,
3415
- ): Promise<SanityDocument<R>>
3416
- /**
3417
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3418
- * Returns a promise that resolves to an array containing the created document.
3419
- *
3420
- * @param document - Document to create
3421
- * @param options - Mutation options
3422
- */
3423
- create<R extends Record<string, Any> = Record<string, Any>>(
3424
- document: SanityDocumentStub<R>,
3425
- options: AllDocumentsMutationOptions,
3426
- ): Promise<SanityDocument<R>[]>
3427
- /**
3428
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3429
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3430
- *
3431
- * @param document - Document to create
3432
- * @param options - Mutation options
3433
- */
3434
- create<R extends Record<string, Any> = Record<string, Any>>(
3435
- document: SanityDocumentStub<R>,
3436
- options: FirstDocumentIdMutationOptions,
3437
- ): Promise<SingleMutationResult>
3438
- /**
3439
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3440
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3441
- *
3442
- * @param document - Document to create
3443
- * @param options - Mutation options
3444
- */
3445
- create<R extends Record<string, Any> = Record<string, Any>>(
3446
- document: SanityDocumentStub<R>,
3447
- options: AllDocumentIdsMutationOptions,
3448
- ): Promise<MultipleMutationResult>
3449
- /**
3450
- * Create a document. Requires a `_type` property. If no `_id` is provided, it will be generated by the database.
3451
- * Returns a promise that resolves to the created document.
3452
- *
3453
- * @param document - Document to create
3454
- * @param options - Mutation options
3455
- */
3456
- create<R extends Record<string, Any> = Record<string, Any>>(
3457
- document: SanityDocumentStub<R>,
3458
- options?: BaseMutationOptions,
3459
- ): Promise<SanityDocument<R>>
3460
- /**
3461
- * Create a document if no document with the same ID already exists.
3462
- * Returns a promise that resolves to the created document.
3463
- *
3464
- * @param document - Document to create
3465
- * @param options - Mutation options
3466
- */
3467
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3468
- document: IdentifiedSanityDocumentStub<R>,
3469
- options: FirstDocumentMutationOptions,
3470
- ): Promise<SanityDocument<R>>
3471
- /**
3472
- * Create a document if no document with the same ID already exists.
3473
- * Returns a promise that resolves to an array containing the created document.
3474
- *
3475
- * @param document - Document to create
3476
- * @param options - Mutation options
3477
- */
3478
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3479
- document: IdentifiedSanityDocumentStub<R>,
3480
- options: AllDocumentsMutationOptions,
3481
- ): Promise<SanityDocument<R>[]>
3482
- /**
3483
- * Create a document if no document with the same ID already exists.
3484
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3485
- *
3486
- * @param document - Document to create
3487
- * @param options - Mutation options
3488
- */
3489
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3490
- document: IdentifiedSanityDocumentStub<R>,
3491
- options: FirstDocumentIdMutationOptions,
3492
- ): Promise<SingleMutationResult>
3493
- /**
3494
- * Create a document if no document with the same ID already exists.
3495
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3496
- *
3497
- * @param document - Document to create
3498
- * @param options - Mutation options
3499
- */
3500
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3501
- document: IdentifiedSanityDocumentStub<R>,
3502
- options: AllDocumentIdsMutationOptions,
3503
- ): Promise<MultipleMutationResult>
3504
- /**
3505
- * Create a document if no document with the same ID already exists.
3506
- * Returns a promise that resolves to the created document.
3507
- *
3508
- * @param document - Document to create
3509
- * @param options - Mutation options
3510
- */
3511
- createIfNotExists<R extends Record<string, Any> = Record<string, Any>>(
3512
- document: IdentifiedSanityDocumentStub<R>,
3513
- options?: BaseMutationOptions,
3514
- ): Promise<SanityDocument<R>>
3515
- /**
3516
- * Create a document if it does not exist, or replace a document with the same document ID
3517
- * Returns a promise that resolves to the created document.
3518
- *
3519
- * @param document - Document to either create or replace
3520
- * @param options - Mutation options
3521
- */
3522
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3523
- document: IdentifiedSanityDocumentStub<R>,
3524
- options: FirstDocumentMutationOptions,
3525
- ): Promise<SanityDocument<R>>
3526
- /**
3527
- * Create a document if it does not exist, or replace a document with the same document ID
3528
- * Returns a promise that resolves to an array containing the created document.
3529
- *
3530
- * @param document - Document to either create or replace
3531
- * @param options - Mutation options
3532
- */
3533
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3534
- document: IdentifiedSanityDocumentStub<R>,
3535
- options: AllDocumentsMutationOptions,
3536
- ): Promise<SanityDocument<R>[]>
3537
- /**
3538
- * Create a document if it does not exist, or replace a document with the same document ID
3539
- * Returns a promise that resolves to a mutation result object containing the ID of the created document.
3540
- *
3541
- * @param document - Document to either create or replace
3542
- * @param options - Mutation options
3543
- */
3544
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3545
- document: IdentifiedSanityDocumentStub<R>,
3546
- options: FirstDocumentIdMutationOptions,
3547
- ): Promise<SingleMutationResult>
3548
- /**
3549
- * Create a document if it does not exist, or replace a document with the same document ID
3550
- * Returns a promise that resolves to a mutation result object containing the created document ID.
3551
- *
3552
- * @param document - Document to either create or replace
3553
- * @param options - Mutation options
3554
- */
3555
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3556
- document: IdentifiedSanityDocumentStub<R>,
3557
- options: AllDocumentIdsMutationOptions,
3558
- ): Promise<MultipleMutationResult>
3559
- /**
3560
- * Create a document if it does not exist, or replace a document with the same document ID
3561
- * Returns a promise that resolves to the created document.
3562
- *
3563
- * @param document - Document to either create or replace
3564
- * @param options - Mutation options
3565
- */
3566
- createOrReplace<R extends Record<string, Any> = Record<string, Any>>(
3567
- document: IdentifiedSanityDocumentStub<R>,
3568
- options?: BaseMutationOptions,
3569
- ): Promise<SanityDocument<R>>
3570
- /**
3571
- * Deletes a document with the given document ID.
3572
- * Returns a promise that resolves to the deleted document.
3573
- *
3574
- * @param id - Document ID to delete
3575
- * @param options - Options for the mutation
3576
- */
3577
- delete<R extends Record<string, Any> = Record<string, Any>>(
3578
- id: string,
3579
- options: FirstDocumentMutationOptions,
3580
- ): Promise<SanityDocument<R>>
3612
+ getById(projectId: string): Promise<SanityProject>
3613
+ }
3614
+
3615
+ /**
3616
+ * Publishes a draft document.
3617
+ * If a published version of the document already exists this is replaced by the current draft document.
3618
+ * In either case the draft document is deleted.
3619
+ * The optional revision id parameters can be used for optimistic locking to ensure
3620
+ * that the draft and/or published versions of the document have not been changed by another client.
3621
+ *
3622
+ * @public
3623
+ */
3624
+ export declare type PublishAction = {
3625
+ actionType: 'sanity.action.document.publish'
3581
3626
  /**
3582
- * Deletes a document with the given document ID.
3583
- * Returns a promise that resolves to an array containing the deleted document.
3584
- *
3585
- * @param id - Document ID to delete
3586
- * @param options - Options for the mutation
3627
+ * Draft document ID to publish
3587
3628
  */
3588
- delete<R extends Record<string, Any> = Record<string, Any>>(
3589
- id: string,
3590
- options: AllDocumentsMutationOptions,
3591
- ): Promise<SanityDocument<R>[]>
3629
+ draftId: string
3592
3630
  /**
3593
- * Deletes a document with the given document ID.
3594
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3595
- *
3596
- * @param id - Document ID to delete
3597
- * @param options - Options for the mutation
3631
+ * Draft revision ID to match
3598
3632
  */
3599
- delete(id: string, options: FirstDocumentIdMutationOptions): Promise<SingleMutationResult>
3633
+ ifDraftRevisionId?: string
3600
3634
  /**
3601
- * Deletes a document with the given document ID.
3602
- * Returns a promise that resolves to a mutation result object containing the deleted document ID.
3603
- *
3604
- * @param id - Document ID to delete
3605
- * @param options - Options for the mutation
3635
+ * Published document ID to replace
3606
3636
  */
3607
- delete(id: string, options: AllDocumentIdsMutationOptions): Promise<MultipleMutationResult>
3637
+ publishedId: string
3608
3638
  /**
3609
- * Deletes a document with the given document ID.
3610
- * Returns a promise that resolves to the deleted document.
3611
- *
3612
- * @param id - Document ID to delete
3613
- * @param options - Options for the mutation
3639
+ * Published revision ID to match
3614
3640
  */
3615
- delete<R extends Record<string, Any> = Record<string, Any>>(
3616
- id: string,
3617
- options?: BaseMutationOptions,
3618
- ): Promise<SanityDocument<R>>
3641
+ ifPublishedRevisionId?: string
3642
+ }
3643
+
3644
+ /**
3645
+ * Publishes all documents in a release at once.
3646
+ *
3647
+ * @public
3648
+ */
3649
+ export declare interface PublishReleaseAction {
3650
+ actionType: 'sanity.action.release.publish'
3651
+ releaseId: string
3652
+ }
3653
+
3654
+ /** @public */
3655
+ export declare type QueryOptions =
3656
+ | FilteredResponseQueryOptions
3657
+ | UnfilteredResponseQueryOptions
3658
+ | UnfilteredResponseWithoutQuery
3659
+
3660
+ /** @public */
3661
+ export declare interface QueryParams {
3662
+ [key: string]: any
3663
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3664
+ body?: never
3665
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3666
+ cache?: 'next' extends keyof RequestInit ? never : any
3667
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3668
+ filterResponse?: never
3669
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3670
+ headers?: never
3671
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3672
+ method?: never
3673
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3674
+ next?: 'next' extends keyof RequestInit ? never : any
3675
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3676
+ perspective?: never
3677
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3678
+ query?: never
3679
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3680
+ resultSourceMap?: never
3681
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3682
+ returnQuery?: never
3683
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3684
+ signal?: never
3685
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3686
+ stega?: never
3687
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3688
+ tag?: never
3689
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3690
+ timeout?: never
3691
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3692
+ token?: never
3693
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3694
+ useCdn?: never
3695
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3696
+ lastLiveEventId?: never
3697
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
3698
+ cacheMode?: never
3699
+ }
3700
+
3701
+ /**
3702
+ * This type can be used with `client.fetch` to indicate that the query has no GROQ parameters.
3703
+ * @public
3704
+ */
3705
+ export declare type QueryWithoutParams = Record<string, never> | undefined
3706
+
3707
+ /** @public */
3708
+ export declare type RawQuerylessQueryResponse<R> = Omit<RawQueryResponse<R>, 'query'>
3709
+
3710
+ /** @public */
3711
+ export declare interface RawQueryResponse<R> {
3712
+ query: string
3713
+ ms: number
3714
+ result: R
3715
+ resultSourceMap?: ContentSourceMap
3716
+ /** Requires `apiVersion` to be `2021-03-25` or later. */
3717
+ syncTags?: SyncTag[]
3718
+ }
3719
+
3720
+ /** @internal */
3721
+ export declare interface RawRequestOptions {
3722
+ url?: string
3723
+ uri?: string
3724
+ method?: string
3725
+ token?: string
3726
+ json?: boolean
3727
+ tag?: string
3728
+ useGlobalApi?: boolean
3729
+ withCredentials?: boolean
3730
+ query?: {
3731
+ [key: string]: string | string[]
3732
+ }
3733
+ headers?: {
3734
+ [key: string]: string
3735
+ }
3736
+ timeout?: number
3737
+ proxy?: string
3738
+ body?: Any
3739
+ maxRedirects?: number
3740
+ signal?: AbortSignal
3741
+ }
3742
+
3743
+ /**
3744
+ * The listener has been disconnected, and a reconnect attempt is scheduled.
3745
+ *
3746
+ * @public
3747
+ */
3748
+ export declare type ReconnectEvent = {
3749
+ type: 'reconnect'
3750
+ }
3751
+
3752
+ /** @public */
3753
+ export declare type ReleaseAction =
3754
+ | CreateReleaseAction
3755
+ | EditReleaseAction
3756
+ | PublishReleaseAction
3757
+ | ArchiveReleaseAction
3758
+ | UnarchiveReleaseAction
3759
+ | ScheduleReleaseAction
3760
+ | UnscheduleReleaseAction
3761
+ | DeleteReleaseAction
3762
+
3763
+ /** @internal */
3764
+ export declare interface ReleaseDocument extends SanityDocument {
3619
3765
  /**
3620
- * Deletes one or more documents matching the given query or document ID.
3621
- * Returns a promise that resolves to first deleted document.
3622
- *
3623
- * @param selection - An object with either an `id` or `query` key defining what to delete
3624
- * @param options - Options for the mutation
3766
+ * typically
3767
+ * `_.releases.<name>`
3625
3768
  */
3626
- delete<R extends Record<string, Any> = Record<string, Any>>(
3627
- selection: MutationSelection,
3628
- options: FirstDocumentMutationOptions,
3629
- ): Promise<SanityDocument<R>>
3769
+ _id: string
3630
3770
  /**
3631
- * Deletes one or more documents matching the given query or document ID.
3632
- * Returns a promise that resolves to an array containing the deleted documents.
3633
- *
3634
- * @param selection - An object with either an `id` or `query` key defining what to delete
3635
- * @param options - Options for the mutation
3771
+ * where a release has _id `_.releases.foo`, the name is `foo`
3636
3772
  */
3637
- delete<R extends Record<string, Any> = Record<string, Any>>(
3638
- selection: MutationSelection,
3639
- options: AllDocumentsMutationOptions,
3640
- ): Promise<SanityDocument<R>[]>
3773
+ name: string
3774
+ _type: 'system.release'
3775
+ _createdAt: string
3776
+ _updatedAt: string
3777
+ _rev: string
3778
+ state: ReleaseState
3779
+ error?: {
3780
+ message: string
3781
+ }
3782
+ finalDocumentStates?: {
3783
+ /** Document ID */
3784
+ id: string
3785
+ }[]
3641
3786
  /**
3642
- * Deletes one or more documents matching the given query or document ID.
3643
- * Returns a promise that resolves to a mutation result object containing the ID of the first deleted document.
3644
- *
3645
- * @param selection - An object with either an `id` or `query` key defining what to delete
3646
- * @param options - Options for the mutation
3787
+ * If defined, it takes precedence over the intendedPublishAt, the state should be 'scheduled'
3647
3788
  */
3648
- delete(
3649
- selection: MutationSelection,
3650
- options: FirstDocumentIdMutationOptions,
3651
- ): Promise<SingleMutationResult>
3789
+ publishAt?: string
3652
3790
  /**
3653
- * Deletes one or more documents matching the given query or document ID.
3654
- * Returns a promise that resolves to a mutation result object containing the document IDs that were deleted.
3655
- *
3656
- * @param selection - An object with either an `id` or `query` key defining what to delete
3657
- * @param options - Options for the mutation
3791
+ * If defined, it provides the time the release was actually published
3658
3792
  */
3659
- delete(
3660
- selection: MutationSelection,
3661
- options: AllDocumentIdsMutationOptions,
3662
- ): Promise<MultipleMutationResult>
3793
+ publishedAt?: string
3794
+ metadata: {
3795
+ title?: string
3796
+ description?: string
3797
+ intendedPublishAt?: string
3798
+ releaseType: ReleaseType
3799
+ }
3800
+ }
3801
+
3802
+ /**
3803
+ * @public
3804
+ * @deprecated – The `r`-prefix is not required, use `string` instead
3805
+ */
3806
+ export declare type ReleaseId = `r${string}`
3807
+
3808
+ /** @public */
3809
+ declare class ReleasesClient {
3810
+ #private
3811
+ constructor(client: SanityClient, httpRequest: HttpRequest)
3663
3812
  /**
3664
- * Deletes one or more documents matching the given query or document ID.
3665
- * Returns a promise that resolves to first deleted document.
3666
- *
3667
- * @param selection - An object with either an `id` or `query` key defining what to delete
3668
- * @param options - Options for the mutation
3669
- */
3670
- delete<R extends Record<string, Any> = Record<string, Any>>(
3671
- selection: MutationSelection,
3672
- options?: BaseMutationOptions,
3673
- ): Promise<SanityDocument<R>>
3813
+ * @public
3814
+ *
3815
+ * Retrieve a release by id.
3816
+ *
3817
+ * @category Releases
3818
+ *
3819
+ * @param params - Release action parameters:
3820
+ * - `releaseId` - The id of the release to retrieve.
3821
+ * @param options - Additional query options including abort signal and query tag.
3822
+ * @returns A promise that resolves to the release document {@link ReleaseDocument}.
3823
+ *
3824
+ * @example Retrieving a release by id
3825
+ * ```ts
3826
+ * const release = await client.releases.get({releaseId: 'my-release'})
3827
+ * console.log(release)
3828
+ * // {
3829
+ * // _id: '_.releases.my-release',
3830
+ * // name: 'my-release'
3831
+ * // _type: 'system.release',
3832
+ * // metadata: {releaseType: 'asap'},
3833
+ * // _createdAt: '2021-01-01T00:00:00.000Z',
3834
+ * // ...
3835
+ * // }
3836
+ * ```
3837
+ */
3838
+ get(
3839
+ {
3840
+ releaseId,
3841
+ }: {
3842
+ releaseId: string
3843
+ },
3844
+ options?: {
3845
+ signal?: AbortSignal
3846
+ tag?: string
3847
+ },
3848
+ ): Promise<ReleaseDocument | undefined>
3674
3849
  /**
3675
- * Perform mutation operations against the configured dataset
3676
- * Returns a promise that resolves to the first mutated document.
3850
+ * @public
3677
3851
  *
3678
- * @param operations - Mutation operations to execute
3679
- * @param options - Mutation options
3680
- */
3681
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3682
- operations: Mutation<R>[] | Patch | Transaction,
3683
- options: FirstDocumentMutationOptions,
3684
- ): Promise<SanityDocument<R>>
3685
- /**
3686
- * Perform mutation operations against the configured dataset.
3687
- * Returns a promise that resolves to an array of the mutated documents.
3852
+ * Creates a new release under the given id, with metadata.
3688
3853
  *
3689
- * @param operations - Mutation operations to execute
3690
- * @param options - Mutation options
3691
- */
3692
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3693
- operations: Mutation<R>[] | Patch | Transaction,
3694
- options: AllDocumentsMutationOptions,
3695
- ): Promise<SanityDocument<R>[]>
3854
+ * @remarks
3855
+ * * If no releaseId is provided, a release id will be generated.
3856
+ * * If no metadata is provided, then an `undecided` releaseType will be used.
3857
+ *
3858
+ * @category Releases
3859
+ *
3860
+ * @param params - Release action parameters:
3861
+ * - `releaseId` - The id of the release to create.
3862
+ * - `metadata` - The metadata to associate with the release {@link ReleaseDocument}.
3863
+ * @param options - Additional action options.
3864
+ * @returns A promise that resolves to the `transactionId` and the release id and metadata.
3865
+ *
3866
+ * @example Creating a release with a custom id and metadata
3867
+ * ```ts
3868
+ * const releaseId = 'my-release'
3869
+ * const releaseMetadata: ReleaseDocument['metadata'] = {
3870
+ * releaseType: 'asap',
3871
+ * }
3872
+ *
3873
+ * const result =
3874
+ * await client.releases.create({releaseId, metadata: releaseMetadata})
3875
+ * console.log(result)
3876
+ * // {
3877
+ * // transactionId: 'transaction-id',
3878
+ * // releaseId: 'my-release',
3879
+ * // metadata: {releaseType: 'asap'},
3880
+ * // }
3881
+ * ```
3882
+ *
3883
+ * @example Creating a release with generated id and metadata
3884
+ * ```ts
3885
+ * const {metadata} = await client.releases.create()
3886
+ * console.log(metadata.releaseType) // 'undecided'
3887
+ * ```
3888
+ *
3889
+ * @example Creating a release with a custom transaction id
3890
+ * ```ts
3891
+ * const {transactionId, metadata} = await client.releases.create({transactionId: 'my-transaction-id'})
3892
+ * console.log(metadata.releaseType) // 'undecided'
3893
+ * console.log(transactionId) // 'my-transaction-id'
3894
+ * ```
3895
+ */
3896
+ create(options: BaseActionOptions): Promise<
3897
+ SingleActionResult & {
3898
+ releaseId: string
3899
+ metadata: ReleaseDocument['metadata']
3900
+ }
3901
+ >
3902
+ create(
3903
+ release: {
3904
+ releaseId?: string
3905
+ metadata?: Partial<ReleaseDocument['metadata']>
3906
+ },
3907
+ options?: BaseActionOptions,
3908
+ ): Promise<
3909
+ SingleActionResult & {
3910
+ releaseId: string
3911
+ metadata: ReleaseDocument['metadata']
3912
+ }
3913
+ >
3696
3914
  /**
3697
- * Perform mutation operations against the configured dataset
3698
- * Returns a promise that resolves to a mutation result object containing the document ID of the first mutated document.
3915
+ * @public
3699
3916
  *
3700
- * @param operations - Mutation operations to execute
3701
- * @param options - Mutation options
3702
- */
3703
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3704
- operations: Mutation<R>[] | Patch | Transaction,
3705
- options: FirstDocumentIdMutationOptions,
3706
- ): Promise<SingleMutationResult>
3707
- /**
3708
- * Perform mutation operations against the configured dataset
3709
- * Returns a promise that resolves to a mutation result object containing the mutated document IDs.
3917
+ * Edits an existing release, updating the metadata.
3710
3918
  *
3711
- * @param operations - Mutation operations to execute
3712
- * @param options - Mutation options
3713
- */
3714
- mutate<R extends Record<string, Any>>(
3715
- operations: Mutation<R>[] | Patch | Transaction,
3716
- options: AllDocumentIdsMutationOptions,
3717
- ): Promise<MultipleMutationResult>
3718
- /**
3719
- * Perform mutation operations against the configured dataset
3720
- * Returns a promise that resolves to the first mutated document.
3919
+ * @category Releases
3721
3920
  *
3722
- * @param operations - Mutation operations to execute
3723
- * @param options - Mutation options
3921
+ * @param params - Release action parameters:
3922
+ * - `releaseId` - The id of the release to edit.
3923
+ * - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
3924
+ * @param options - Additional action options.
3925
+ * @returns A promise that resolves to the `transactionId`.
3724
3926
  */
3725
- mutate<R extends Record<string, Any> = Record<string, Any>>(
3726
- operations: Mutation<R>[] | Patch | Transaction,
3727
- options?: BaseMutationOptions,
3728
- ): Promise<SanityDocument<R>>
3927
+ edit(
3928
+ {
3929
+ releaseId,
3930
+ patch,
3931
+ }: {
3932
+ releaseId: string
3933
+ patch: PatchOperations
3934
+ },
3935
+ options?: BaseActionOptions,
3936
+ ): Promise<SingleActionResult>
3729
3937
  /**
3730
- * Create a new buildable patch of operations to perform
3938
+ * @public
3731
3939
  *
3732
- * @param documentId - Document ID to patch
3733
- * @param operations - Optional object of patch operations to initialize the patch instance with
3734
- * @returns Patch instance - call `.commit()` to perform the operations defined
3735
- */
3736
- patch(documentId: string, operations?: PatchOperations): Patch
3737
- /**
3738
- * Create a new buildable patch of operations to perform
3940
+ * Publishes all documents in a release at once. For larger releases the effect of the publish
3941
+ * will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
3942
+ * documents and creation of the corresponding published documents with the new content may
3943
+ * take some time.
3739
3944
  *
3740
- * @param documentIds - Array of document IDs to patch
3741
- * @param operations - Optional object of patch operations to initialize the patch instance with
3742
- * @returns Patch instance - call `.commit()` to perform the operations defined
3945
+ * During this period both the source and target documents are locked and cannot be
3946
+ * modified through any other means.
3947
+ *
3948
+ * @category Releases
3949
+ *
3950
+ * @param params - Release action parameters:
3951
+ * - `releaseId` - The id of the release to publish.
3952
+ * @param options - Additional action options.
3953
+ * @returns A promise that resolves to the `transactionId`.
3743
3954
  */
3744
- patch(documentIds: string[], operations?: PatchOperations): Patch
3955
+ publish(
3956
+ {
3957
+ releaseId,
3958
+ }: {
3959
+ releaseId: string
3960
+ },
3961
+ options?: BaseActionOptions,
3962
+ ): Promise<SingleActionResult>
3745
3963
  /**
3746
- * Create a new buildable patch of operations to perform
3964
+ * @public
3747
3965
  *
3748
- * @param selection - An object with `query` and optional `params`, defining which document(s) to patch
3749
- * @param operations - Optional object of patch operations to initialize the patch instance with
3750
- * @returns Patch instance - call `.commit()` to perform the operations defined
3966
+ * An archive action removes an active release. The documents that comprise the release
3967
+ * are deleted and therefore no longer queryable.
3968
+ *
3969
+ * While the documents remain in retention the last version can still be accessed using document history endpoint.
3970
+ *
3971
+ * @category Releases
3972
+ *
3973
+ * @param params - Release action parameters:
3974
+ * - `releaseId` - The id of the release to archive.
3975
+ * @param options - Additional action options.
3976
+ * @returns A promise that resolves to the `transactionId`.
3751
3977
  */
3752
- patch(selection: MutationSelection, operations?: PatchOperations): Patch
3978
+ archive(
3979
+ {
3980
+ releaseId,
3981
+ }: {
3982
+ releaseId: string
3983
+ },
3984
+ options?: BaseActionOptions,
3985
+ ): Promise<SingleActionResult>
3753
3986
  /**
3754
- * Create a new transaction of mutations
3987
+ * @public
3755
3988
  *
3756
- * @param operations - Optional array of mutation operations to initialize the transaction instance with
3989
+ * An unarchive action restores an archived release and all documents
3990
+ * with the content they had just prior to archiving.
3991
+ *
3992
+ * @category Releases
3993
+ *
3994
+ * @param params - Release action parameters:
3995
+ * - `releaseId` - The id of the release to unarchive.
3996
+ * @param options - Additional action options.
3997
+ * @returns A promise that resolves to the `transactionId`.
3757
3998
  */
3758
- transaction<R extends Record<string, Any> = Record<string, Any>>(
3759
- operations?: Mutation<R>[],
3760
- ): Transaction
3999
+ unarchive(
4000
+ {
4001
+ releaseId,
4002
+ }: {
4003
+ releaseId: string
4004
+ },
4005
+ options?: BaseActionOptions,
4006
+ ): Promise<SingleActionResult>
4007
+ /**
4008
+ * @public
4009
+ *
4010
+ * A schedule action queues a release for publishing at the given future time.
4011
+ * The release is locked such that no documents in the release can be modified and
4012
+ * no documents that it references can be deleted as this would make the publish fail.
4013
+ * At the given time, the same logic as for the publish action is triggered.
4014
+ *
4015
+ * @category Releases
4016
+ *
4017
+ * @param params - Release action parameters:
4018
+ * - `releaseId` - The id of the release to schedule.
4019
+ * - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
4020
+ * @param options - Additional action options.
4021
+ * @returns A promise that resolves to the `transactionId`.
4022
+ */
4023
+ schedule(
4024
+ {
4025
+ releaseId,
4026
+ publishAt,
4027
+ }: {
4028
+ releaseId: string
4029
+ publishAt: string
4030
+ },
4031
+ options?: BaseActionOptions,
4032
+ ): Promise<SingleActionResult>
3761
4033
  /**
3762
- * Perform action operations against the configured dataset
3763
- * Returns a promise that resolves to the transaction result
4034
+ * @public
3764
4035
  *
3765
- * @param operations - Action operation(s) to execute
3766
- * @param options - Action options
4036
+ * An unschedule action stops a release from being published.
4037
+ * The documents in the release are considered unlocked and can be edited again.
4038
+ * This may fail if another release is scheduled to be published after this one and
4039
+ * has a reference to a document created by this one.
4040
+ *
4041
+ * @category Releases
4042
+ *
4043
+ * @param params - Release action parameters:
4044
+ * - `releaseId` - The id of the release to unschedule.
4045
+ * @param options - Additional action options.
4046
+ * @returns A promise that resolves to the `transactionId`.
3767
4047
  */
3768
- action(
3769
- operations: Action | Action[],
4048
+ unschedule(
4049
+ {
4050
+ releaseId,
4051
+ }: {
4052
+ releaseId: string
4053
+ },
3770
4054
  options?: BaseActionOptions,
3771
- ): Promise<SingleActionResult | MultipleActionResult>
4055
+ ): Promise<SingleActionResult>
3772
4056
  /**
3773
- * Perform a request against the Sanity API
3774
- * NOTE: Only use this for Sanity API endpoints, not for your own APIs!
4057
+ * @public
3775
4058
  *
3776
- * @param options - Request options
3777
- * @returns Promise resolving to the response body
4059
+ * A delete action removes a published or archived release.
4060
+ * The backing system document will be removed from the dataset.
4061
+ *
4062
+ * @category Releases
4063
+ *
4064
+ * @param params - Release action parameters:
4065
+ * - `releaseId` - The id of the release to delete.
4066
+ * @param options - Additional action options.
4067
+ * @returns A promise that resolves to the `transactionId`.
3778
4068
  */
3779
- request<R = Any>(options: RawRequestOptions): Promise<R>
4069
+ delete(
4070
+ {
4071
+ releaseId,
4072
+ }: {
4073
+ releaseId: string
4074
+ },
4075
+ options?: BaseActionOptions,
4076
+ ): Promise<SingleActionResult>
3780
4077
  /**
3781
- * Perform an HTTP request a `/data` sub-endpoint
3782
- * NOTE: Considered internal, thus marked as deprecated. Use `request` instead.
4078
+ * @public
3783
4079
  *
3784
- * @deprecated - Use `request()` or your own HTTP library instead
3785
- * @param endpoint - Endpoint to hit (mutate, query etc)
3786
- * @param body - Request body
3787
- * @param options - Request options
3788
- * @internal
4080
+ * Fetch the documents in a release by release id.
4081
+ *
4082
+ * @category Releases
4083
+ *
4084
+ * @param params - Release action parameters:
4085
+ * - `releaseId` - The id of the release to fetch documents for.
4086
+ * @param options - Additional mutation options {@link BaseMutationOptions}.
4087
+ * @returns A promise that resolves to the documents in the release.
3789
4088
  */
3790
- dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
4089
+ fetchDocuments(
4090
+ {
4091
+ releaseId,
4092
+ }: {
4093
+ releaseId: string
4094
+ },
4095
+ options?: BaseMutationOptions,
4096
+ ): Promise<RawQueryResponse<SanityDocument[]>>
4097
+ }
4098
+
4099
+ /** @beta */
4100
+ export declare type ReleaseState =
4101
+ | 'active'
4102
+ | 'archiving'
4103
+ | 'unarchiving'
4104
+ | 'archived'
4105
+ | 'published'
4106
+ | 'publishing'
4107
+ | 'scheduled'
4108
+ | 'scheduling'
4109
+
4110
+ /** @internal */
4111
+ export declare type ReleaseType = 'asap' | 'scheduled' | 'undecided'
4112
+
4113
+ /**
4114
+ * Replaces an existing draft document.
4115
+ * At least one of the draft or published versions of the document must exist.
4116
+ *
4117
+ * @public
4118
+ * @deprecated Use {@link ReplaceVersionAction} instead
4119
+ */
4120
+ export declare type ReplaceDraftAction = {
4121
+ actionType: 'sanity.action.document.replaceDraft'
3791
4122
  /**
3792
- * Get a Sanity API URL for the URI provided
3793
- *
3794
- * @param uri - URI/path to build URL for
3795
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
4123
+ * Published document ID to create draft from, if draft does not exist
3796
4124
  */
3797
- getUrl(uri: string, canUseCdn?: boolean): string
4125
+ publishedId: string
3798
4126
  /**
3799
- * Get a Sanity API URL for the data operation and path provided
3800
- *
3801
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3802
- * @param path - Path to append after the operation
4127
+ * Document to create if it does not already exist. Requires `_id` and `_type` properties.
3803
4128
  */
3804
- getDataUrl(operation: string, path?: string): string
4129
+ attributes: IdentifiedSanityDocumentStub
4130
+ }
4131
+
4132
+ /**
4133
+ * Replace an existing version of a document.
4134
+ *
4135
+ * @public
4136
+ */
4137
+ export declare interface ReplaceVersionAction {
4138
+ actionType: 'sanity.action.document.version.replace'
4139
+ document: IdentifiedSanityDocumentStub
4140
+ }
4141
+
4142
+ /**
4143
+ * @deprecated -- Use `import {requester} from '@sanity/client'` instead
4144
+ * @public
4145
+ */
4146
+ export declare const requester: Requester
4147
+
4148
+ /** @internal */
4149
+ export declare interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
4150
+ url?: string
4151
+ uri?: string
4152
+ canUseCdn?: boolean
4153
+ useCdn?: boolean
4154
+ tag?: string
4155
+ returnQuery?: boolean
4156
+ resultSourceMap?: boolean | 'withKeyArraySelector'
4157
+ perspective?: ClientPerspective
4158
+ lastLiveEventId?: string
4159
+ cacheMode?: 'noStale'
4160
+ }
4161
+
4162
+ /** @public */
4163
+ export declare interface RequestOptions {
4164
+ timeout?: number
4165
+ token?: string
4166
+ tag?: string
4167
+ headers?: Record<string, string>
4168
+ method?: string
4169
+ query?: Any
4170
+ body?: Any
4171
+ signal?: AbortSignal
3805
4172
  }
3806
4173
 
3807
- /**
3808
- * Shared base type for the `SanityClient` and `ObservableSanityClient` classes.
3809
- * TODO: refactor the Promise and Observable differences to use generics so we no longer suffer from all this duplication in TS docs
3810
- */
3811
- declare interface SanityClientBase {
3812
- live: LiveClient
3813
- listen: typeof _listen
3814
- /**
3815
- * Get a Sanity API URL for the URI provided
3816
- *
3817
- * @param uri - URI/path to build URL for
3818
- * @param canUseCdn - Whether or not to allow using the API CDN for this route
3819
- */
3820
- getUrl(uri: string, canUseCdn?: boolean): string
4174
+ /** @alpha */
4175
+ export declare type ResolveStudioUrl = (
4176
+ sourceDocument: ContentSourceMapDocuments_2[number],
4177
+ ) => StudioUrl
4178
+
4179
+ /** @public */
4180
+ export declare interface ResponseEvent<T = unknown> {
4181
+ type: 'response'
4182
+ body: T
4183
+ url: string
4184
+ method: string
4185
+ statusCode: number
4186
+ statusMessage?: string
4187
+ headers: Record<string, string>
4188
+ }
4189
+
4190
+ /** @public */
4191
+ export declare interface ResponseQueryOptions extends RequestOptions {
4192
+ perspective?: ClientPerspective
4193
+ resultSourceMap?: boolean | 'withKeyArraySelector'
4194
+ returnQuery?: boolean
4195
+ useCdn?: boolean
4196
+ stega?: boolean | StegaConfig
4197
+ cache?: 'next' extends keyof RequestInit ? RequestInit['cache'] : never
4198
+ next?: ('next' extends keyof RequestInit ? RequestInit : never)['next']
4199
+ lastLiveEventId?: string | string[] | null
3821
4200
  /**
3822
- * Get a Sanity API URL for the data operation and path provided
4201
+ * When set to `noStale`, APICDN will not return a cached response if the content is stale.
4202
+ * Tradeoff between latency and freshness of content.
3823
4203
  *
3824
- * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
3825
- * @param path - Path to append after the operation
4204
+ * Only to be used with live content queries and when useCdn is true.
3826
4205
  */
3827
- getDataUrl(operation: string, path?: string): string
4206
+ cacheMode?: 'noStale'
3828
4207
  }
3829
4208
 
3830
- /**
3831
- * The interface implemented by the `SanityClient` class.
3832
- * When writing code that wants to take an instance of `SanityClient` as input it's better to use this type,
3833
- * as the `SanityClient` class has private properties and thus TypeScrict will consider the type incompatible
3834
- * in cases where you might have multiple `@sanity/client` instances in your node_modules.
3835
- * @public
3836
- */
3837
- export declare interface SanityClientType extends SanityClientBase {
3838
- assets: AssetsClientType
3839
- datasets: DatasetsClientType
3840
- projects: ProjectsClientType
3841
- users: UsersClientType
4209
+ /** @internal */
4210
+ export declare interface SanityAssetDocument extends SanityDocument {
4211
+ url: string
4212
+ path: string
4213
+ size: number
4214
+ assetId: string
4215
+ mimeType: string
4216
+ sha1hash: string
4217
+ extension: string
4218
+ uploadId?: string
4219
+ originalFilename?: string
4220
+ }
4221
+
4222
+ /** @public */
4223
+ export declare class SanityClient {
4224
+ #private
4225
+ assets: AssetsClient
4226
+ datasets: DatasetsClient
4227
+ live: LiveClient
4228
+ projects: ProjectsClient
4229
+ users: UsersClient
4230
+ agent: {
4231
+ action: AgentActionsClient
4232
+ }
4233
+ releases: ReleasesClient
3842
4234
  /**
3843
4235
  * Observable version of the Sanity client, with the same configuration as the promise-based one
3844
4236
  */
3845
- observable: ObservableSanityClientType
4237
+ observable: ObservableSanityClient
4238
+ /**
4239
+ * Instance properties
4240
+ */
4241
+ listen: typeof _listen
4242
+ constructor(httpRequest: HttpRequest, config?: ClientConfig)
3846
4243
  /**
3847
4244
  * Clone the client - returns a new instance
3848
4245
  */
3849
- clone(): SanityClientType
4246
+ clone(): SanityClient
3850
4247
  /**
3851
4248
  * Returns the current client configuration
3852
4249
  */
@@ -3854,13 +4251,13 @@ export declare interface SanityClientType extends SanityClientBase {
3854
4251
  /**
3855
4252
  * Reconfigure the client. Note that this _mutates_ the current client.
3856
4253
  */
3857
- config(newConfig?: Partial<ClientConfig>): SanityClientType
4254
+ config(newConfig?: Partial<ClientConfig>): this
3858
4255
  /**
3859
4256
  * Clone the client with a new (partial) configuration.
3860
4257
  *
3861
4258
  * @param newConfig - New client configuration properties, shallowly merged with existing configuration
3862
4259
  */
3863
- withConfig(newConfig?: Partial<ClientConfig>): SanityClientType
4260
+ withConfig(newConfig?: Partial<ClientConfig>): SanityClient
3864
4261
  /**
3865
4262
  * Perform a GROQ-query against the configured dataset.
3866
4263
  *
@@ -3870,10 +4267,7 @@ export declare interface SanityClientType extends SanityClientBase {
3870
4267
  R = Any,
3871
4268
  Q extends QueryWithoutParams = QueryWithoutParams,
3872
4269
  const G extends string = string,
3873
- >(
3874
- query: G,
3875
- params?: Q | QueryWithoutParams,
3876
- ): Promise<ClientReturn<G, R>>
4270
+ >(query: G, params?: Q | QueryWithoutParams): Promise<ClientReturn<G, R>>
3877
4271
  /**
3878
4272
  * Perform a GROQ-query against the configured dataset.
3879
4273
  *
@@ -3933,6 +4327,7 @@ export declare interface SanityClientType extends SanityClientBase {
3933
4327
  options?: {
3934
4328
  signal?: AbortSignal
3935
4329
  tag?: string
4330
+ releaseId?: string
3936
4331
  },
3937
4332
  ): Promise<SanityDocument<R> | undefined>
3938
4333
  /**
@@ -4116,6 +4511,90 @@ export declare interface SanityClientType extends SanityClientBase {
4116
4511
  document: IdentifiedSanityDocumentStub<R>,
4117
4512
  options?: BaseMutationOptions,
4118
4513
  ): Promise<SanityDocument<R>>
4514
+ /**
4515
+ * @public
4516
+ *
4517
+ * Creates a new version of a published document.
4518
+ *
4519
+ * @remarks
4520
+ * * Requires a document with a `_type` property.
4521
+ * * Creating a version with no `releaseId` will create a new draft version of the published document.
4522
+ * * If the `document._id` is defined, it should be a draft or release version ID that matches the version ID generated from `publishedId` and `releaseId`.
4523
+ * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
4524
+ * * To create a version of an unpublished document, use the `client.create` method.
4525
+ *
4526
+ * @category Versions
4527
+ *
4528
+ * @param params - Version action parameters:
4529
+ * - `document` - The document to create as a new version (must include `_type`).
4530
+ * - `publishedId` - The ID of the published document being versioned.
4531
+ * - `releaseId` - The ID of the release to create the version for.
4532
+ * @param options - Additional action options.
4533
+ * @returns A promise that resolves to the `transactionId`.
4534
+ *
4535
+ * @example Creating a new version of a published document with a generated version ID
4536
+ * ```ts
4537
+ * const transactionId = await client.createVersion({
4538
+ * // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
4539
+ * document: {_type: 'myDocument', title: 'My Document'},
4540
+ * publishedId: 'myDocument',
4541
+ * releaseId: 'myRelease',
4542
+ * })
4543
+ *
4544
+ * // The following document will be created:
4545
+ * // {
4546
+ * // _id: 'versions.myRelease.myDocument',
4547
+ * // _type: 'myDocument',
4548
+ * // title: 'My Document',
4549
+ * // }
4550
+ * ```
4551
+ *
4552
+ * @example Creating a new version of a published document with a specified version ID
4553
+ * ```ts
4554
+ * const transactionId = await client.createVersion({
4555
+ * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
4556
+ * // `publishedId` and `releaseId` are not required since `document._id` has been specified
4557
+ * })
4558
+ *
4559
+ * // The following document will be created:
4560
+ * // {
4561
+ * // _id: 'versions.myRelease.myDocument',
4562
+ * // _type: 'myDocument',
4563
+ * // title: 'My Document',
4564
+ * // }
4565
+ * ```
4566
+ *
4567
+ * @example Creating a new draft version of a published document
4568
+ * ```ts
4569
+ * const transactionId = await client.createVersion({
4570
+ * document: {_type: 'myDocument', title: 'My Document'},
4571
+ * publishedId: 'myDocument',
4572
+ * })
4573
+ *
4574
+ * // The following document will be created:
4575
+ * // {
4576
+ * // _id: 'drafts.myDocument',
4577
+ * // _type: 'myDocument',
4578
+ * // title: 'My Document',
4579
+ * // }
4580
+ * ```
4581
+ */
4582
+ createVersion<R extends Record<string, Any>>(
4583
+ args: {
4584
+ document: SanityDocumentStub<R>
4585
+ publishedId: string
4586
+ releaseId?: string
4587
+ },
4588
+ options?: BaseActionOptions,
4589
+ ): Promise<SingleActionResult | MultipleActionResult>
4590
+ createVersion<R extends Record<string, Any>>(
4591
+ args: {
4592
+ document: IdentifiedSanityDocumentStub<R>
4593
+ publishedId?: string
4594
+ releaseId?: string
4595
+ },
4596
+ options?: BaseActionOptions,
4597
+ ): Promise<SingleActionResult | MultipleActionResult>
4119
4598
  /**
4120
4599
  * Deletes a document with the given document ID.
4121
4600
  * Returns a promise that resolves to the deleted document.
@@ -4220,6 +4699,157 @@ export declare interface SanityClientType extends SanityClientBase {
4220
4699
  selection: MutationSelection,
4221
4700
  options?: BaseMutationOptions,
4222
4701
  ): Promise<SanityDocument<R>>
4702
+ /**
4703
+ * @public
4704
+ *
4705
+ * Deletes the draft or release version of a document.
4706
+ *
4707
+ * @remarks
4708
+ * * Discarding a version with no `releaseId` will discard the draft version of the published document.
4709
+ * * If the draft or release version does not exist, any error will throw.
4710
+ *
4711
+ * @param params - Version action parameters:
4712
+ * - `releaseId` - The ID of the release to discard the document from.
4713
+ * - `publishedId` - The published ID of the document to discard.
4714
+ * @param purge - if `true` the document history is also discarded.
4715
+ * @param options - Additional action options.
4716
+ * @returns a promise that resolves to the `transactionId`.
4717
+ *
4718
+ * @example Discarding a release version of a document
4719
+ * ```ts
4720
+ * client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
4721
+ * // The document with the ID `versions.myRelease.myDocument` will be discarded.
4722
+ * ```
4723
+ *
4724
+ * @example Discarding a draft version of a document
4725
+ * ```ts
4726
+ * client.discardVersion({publishedId: 'myDocument'})
4727
+ * // The document with the ID `drafts.myDocument` will be discarded.
4728
+ * ```
4729
+ */
4730
+ discardVersion(
4731
+ {
4732
+ releaseId,
4733
+ publishedId,
4734
+ }: {
4735
+ releaseId?: string
4736
+ publishedId: string
4737
+ },
4738
+ purge?: boolean,
4739
+ options?: BaseActionOptions,
4740
+ ): Promise<SingleActionResult | MultipleActionResult>
4741
+ /**
4742
+ * @public
4743
+ *
4744
+ * Replaces an existing version document.
4745
+ *
4746
+ * @remarks
4747
+ * * Requires a document with a `_type` property.
4748
+ * * If the `document._id` is defined, it should be a draft or release version ID that matches the version ID generated from `publishedId` and `releaseId`.
4749
+ * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
4750
+ * * Replacing a version with no `releaseId` will replace the draft version of the published document.
4751
+ * * At least one of the **version** or **published** documents must exist.
4752
+ *
4753
+ * @param params - Version action parameters:
4754
+ * - `document` - The new document to replace the version with.
4755
+ * - `releaseId` - The ID of the release where the document version is replaced.
4756
+ * - `publishedId` - The ID of the published document to replace.
4757
+ * @param options - Additional action options.
4758
+ * @returns a promise that resolves to the `transactionId`.
4759
+ *
4760
+ * @example Replacing a release version of a published document with a generated version ID
4761
+ * ```ts
4762
+ * await client.replaceVersion({
4763
+ * document: {_type: 'myDocument', title: 'My Document'},
4764
+ * publishedId: 'myDocument',
4765
+ * releaseId: 'myRelease',
4766
+ * })
4767
+ *
4768
+ * // The following document will be patched:
4769
+ * // {
4770
+ * // _id: 'versions.myRelease.myDocument',
4771
+ * // _type: 'myDocument',
4772
+ * // title: 'My Document',
4773
+ * // }
4774
+ * ```
4775
+ *
4776
+ * @example Replacing a release version of a published document with a specified version ID
4777
+ * ```ts
4778
+ * await client.replaceVersion({
4779
+ * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
4780
+ * // `publishedId` and `releaseId` are not required since `document._id` has been specified
4781
+ * })
4782
+ *
4783
+ * // The following document will be patched:
4784
+ * // {
4785
+ * // _id: 'versions.myRelease.myDocument',
4786
+ * // _type: 'myDocument',
4787
+ * // title: 'My Document',
4788
+ * // }
4789
+ * ```
4790
+ *
4791
+ * @example Replacing a draft version of a published document
4792
+ * ```ts
4793
+ * await client.replaceVersion({
4794
+ * document: {_type: 'myDocument', title: 'My Document'},
4795
+ * publishedId: 'myDocument',
4796
+ * })
4797
+ *
4798
+ * // The following document will be patched:
4799
+ * // {
4800
+ * // _id: 'drafts.myDocument',
4801
+ * // _type: 'myDocument',
4802
+ * // title: 'My Document',
4803
+ * // }
4804
+ * ```
4805
+ */
4806
+ replaceVersion<R extends Record<string, Any>>(
4807
+ args: {
4808
+ document: SanityDocumentStub<R>
4809
+ publishedId: string
4810
+ releaseId?: string
4811
+ },
4812
+ options?: BaseActionOptions,
4813
+ ): Promise<SingleActionResult | MultipleActionResult>
4814
+ replaceVersion<R extends Record<string, Any>>(
4815
+ args: {
4816
+ document: IdentifiedSanityDocumentStub<R>
4817
+ publishedId?: string
4818
+ releaseId?: string
4819
+ },
4820
+ options?: BaseActionOptions,
4821
+ ): Promise<SingleActionResult | MultipleActionResult>
4822
+ /**
4823
+ * @public
4824
+ *
4825
+ * Used to indicate when a document within a release should be unpublished when
4826
+ * the release is run.
4827
+ *
4828
+ * @remarks
4829
+ * * If the published document does not exist, an error will be thrown.
4830
+ *
4831
+ * @param params - Version action parameters:
4832
+ * - `releaseId` - The ID of the release to unpublish the document from.
4833
+ * - `publishedId` - The published ID of the document to unpublish.
4834
+ * @param options - Additional action options.
4835
+ * @returns a promise that resolves to the `transactionId`.
4836
+ *
4837
+ * @example Unpublishing a release version of a published document
4838
+ * ```ts
4839
+ * await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
4840
+ * // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
4841
+ * ```
4842
+ */
4843
+ unpublishVersion(
4844
+ {
4845
+ releaseId,
4846
+ publishedId,
4847
+ }: {
4848
+ releaseId: string
4849
+ publishedId: string
4850
+ },
4851
+ options?: BaseActionOptions,
4852
+ ): Promise<SingleActionResult | MultipleActionResult>
4223
4853
  /**
4224
4854
  * Perform mutation operations against the configured dataset
4225
4855
  * Returns a promise that resolves to the first mutated document.
@@ -4260,7 +4890,7 @@ export declare interface SanityClientType extends SanityClientBase {
4260
4890
  * @param operations - Mutation operations to execute
4261
4891
  * @param options - Mutation options
4262
4892
  */
4263
- mutate<R extends Record<string, Any>>(
4893
+ mutate<R extends Record<string, Any> = Record<string, Any>>(
4264
4894
  operations: Mutation<R>[] | Patch | Transaction,
4265
4895
  options: AllDocumentIdsMutationOptions,
4266
4896
  ): Promise<MultipleMutationResult>
@@ -4299,14 +4929,6 @@ export declare interface SanityClientType extends SanityClientBase {
4299
4929
  * @returns Patch instance - call `.commit()` to perform the operations defined
4300
4930
  */
4301
4931
  patch(selection: MutationSelection, operations?: PatchOperations): Patch
4302
- /**
4303
- * Create a new buildable patch of operations to perform
4304
- *
4305
- * @param selection - Document ID, an array of document IDs, or an object with `query` and optional `params`, defining which document(s) to patch
4306
- * @param operations - Optional object of patch operations to initialize the patch instance with
4307
- * @returns Patch instance - call `.commit()` to perform the operations defined
4308
- */
4309
- patch(selection: PatchSelection, operations?: PatchOperations): Patch
4310
4932
  /**
4311
4933
  * Create a new transaction of mutations
4312
4934
  *
@@ -4345,6 +4967,20 @@ export declare interface SanityClientType extends SanityClientBase {
4345
4967
  * @internal
4346
4968
  */
4347
4969
  dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any>
4970
+ /**
4971
+ * Get a Sanity API URL for the URI provided
4972
+ *
4973
+ * @param uri - URI/path to build URL for
4974
+ * @param canUseCdn - Whether or not to allow using the API CDN for this route
4975
+ */
4976
+ getUrl(uri: string, canUseCdn?: boolean): string
4977
+ /**
4978
+ * Get a Sanity API URL for the data operation and path provided
4979
+ *
4980
+ * @param operation - Data operation (eg `query`, `mutate`, `listen` or similar)
4981
+ * @param path - Path to append after the operation
4982
+ */
4983
+ getDataUrl(operation: string, path?: string): string
4348
4984
  }
4349
4985
 
4350
4986
  /** @internal */
@@ -4476,6 +5112,17 @@ export declare interface SanityUser {
4476
5112
  isCurrentUser: boolean
4477
5113
  }
4478
5114
 
5115
+ /**
5116
+ * Queues release for publishing at the given future time.
5117
+ *
5118
+ * @public
5119
+ */
5120
+ export declare interface ScheduleReleaseAction {
5121
+ actionType: 'sanity.action.release.schedule'
5122
+ releaseId: string
5123
+ publishAt: string
5124
+ }
5125
+
4479
5126
  /** @public */
4480
5127
  export declare class ServerError extends Error {
4481
5128
  response: ErrorProps['response']
@@ -4714,6 +5361,319 @@ export declare type TransactionMutationOptions =
4714
5361
  | TransactionAllDocumentsMutationOptions
4715
5362
  | TransactionAllDocumentIdsMutationOptions
4716
5363
 
5364
+ /** @beta */
5365
+ export declare type TransformDocument<T extends Record<string, Any> = Record<string, Any>> =
5366
+ | TransformDocumentSync<T>
5367
+ | TransformDocumentAsync
5368
+
5369
+ /** @beta */
5370
+ declare type TransformDocumentAsync = TransformRequestBase & AgentActionAsync
5371
+
5372
+ /** @beta */
5373
+ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
5374
+ TransformRequestBase & AgentActionSync
5375
+
5376
+ /** @beta */
5377
+ declare interface TransformRequestBase extends AgentActionRequestBase {
5378
+ /** schemaId as reported by sanity deploy / sanity schema store */
5379
+ schemaId: string
5380
+ /**
5381
+ * The source document the transformation will use as input.
5382
+ */
5383
+ documentId: string
5384
+ /**
5385
+ * The source document's content is first copied to the target,
5386
+ * then it is transformed according to the instruction.
5387
+ *
5388
+ * When omitted, the source document (documentId) is also the target document.
5389
+ */
5390
+ targetDocument?: TransformTargetDocument
5391
+ /**
5392
+ * Instruct the LLM how to transform the input to th output.
5393
+ *
5394
+ * String template using $variable from instructionParams.
5395
+ *
5396
+ * Capped to 2000 characters, after variables has been injected.
5397
+ * */
5398
+ instruction: string
5399
+ /**
5400
+ *
5401
+ * param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable"
5402
+ *
5403
+ * ### Examples
5404
+ *
5405
+ * #### Constant
5406
+ *
5407
+ * ##### Shorthand
5408
+ * ```ts
5409
+ * client.agent.action.generate({
5410
+ * schemaId,
5411
+ * documentId,
5412
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
5413
+ * instructionParams: {
5414
+ * topic: 'Grapefruit'
5415
+ * },
5416
+ * })
5417
+ * ```
5418
+ * ##### Object-form
5419
+ *
5420
+ * ```ts
5421
+ * client.agent.action.transform({
5422
+ * schemaId,
5423
+ * documentId,
5424
+ * instruction: 'Give the following topic:\n $topic \n ---\nGenerate the full article.',
5425
+ * instructionParams: {
5426
+ * topic: {
5427
+ * type: 'constant',
5428
+ * value: 'Grapefruit'
5429
+ * },
5430
+ * },
5431
+ * })
5432
+ * ```
5433
+ * #### Field
5434
+ * ```ts
5435
+ * client.agent.action.transform({
5436
+ * schemaId,
5437
+ * documentId,
5438
+ * instruction: 'Give the following field value:\n $pte \n ---\nGenerate keywords.',
5439
+ * instructionParams: {
5440
+ * pte: {
5441
+ * type: 'field',
5442
+ * path: ['pteField'],
5443
+ * },
5444
+ * },
5445
+ * target: {path: 'keywords' }
5446
+ * })
5447
+ * ```
5448
+ * #### Document
5449
+ * ```ts
5450
+ * client.agent.action.transform({
5451
+ * schemaId,
5452
+ * documentId,
5453
+ * instruction: 'Give the following document value:\n $document \n ---\nGenerate keywords.',
5454
+ * instructionParams: {
5455
+ * document: {
5456
+ * type: 'document',
5457
+ * },
5458
+ * },
5459
+ * target: {path: 'keywords' }
5460
+ * })
5461
+ * ```
5462
+ *
5463
+ * #### GROQ
5464
+ * ```ts
5465
+ * client.agent.action.transform({
5466
+ * schemaId,
5467
+ * documentId,
5468
+ * instruction: 'Give the following list of titles:\n $list \n ---\nGenerate a similar title.',
5469
+ * instructionParams: {
5470
+ * list: {
5471
+ * type: 'groq',
5472
+ * query: '* [_type==$type].title',
5473
+ * params: {type: 'article'}
5474
+ * },
5475
+ * },
5476
+ * target: {path: 'title'}
5477
+ * })
5478
+ * ```
5479
+ * */
5480
+ instructionParams?: AgentActionParams
5481
+ /**
5482
+ * Target defines which parts of the document will be affected by the instruction.
5483
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
5484
+ *
5485
+ * Omitting target implies that the document itself is the root.
5486
+ *
5487
+ * Notes:
5488
+ * - instruction can only affect fields up to `maxPathDepth`
5489
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
5490
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
5491
+ *
5492
+ * Default max depth for transform: 12
5493
+ * @see AgentActionRequestBase#conditionalPaths
5494
+ */
5495
+ target?: TransformTarget | TransformTarget[]
5496
+ }
5497
+
5498
+ /** @beta */
5499
+ export declare interface TransformTarget extends AgentActionTarget {
5500
+ /**
5501
+ * Specifies a tailored instruction of this target.
5502
+ *
5503
+ * string template using $variable from instructionParams.
5504
+ * */
5505
+ instruction?: string
5506
+ /**
5507
+ * By default, all children up to `target.maxPathDepth` are included.
5508
+ *
5509
+ * When `include` is specified, only segments explicitly listed will be included.
5510
+ *
5511
+ * Fields or array items not on the include list, are implicitly excluded.
5512
+ */
5513
+ include?: (AgentActionPathSegment | TransformTargetInclude)[]
5514
+ }
5515
+
5516
+ /** @beta */
5517
+ export declare type TransformTargetDocument =
5518
+ | {
5519
+ operation: 'edit'
5520
+ _id: string
5521
+ }
5522
+ | {
5523
+ operation: 'create'
5524
+ _id?: string
5525
+ }
5526
+ | {
5527
+ operation: 'createIfNotExists'
5528
+ _id: string
5529
+ }
5530
+ | {
5531
+ operation: 'createOrReplace'
5532
+ _id: string
5533
+ }
5534
+
5535
+ /** @beta */
5536
+ export declare interface TransformTargetInclude extends AgentActionTargetInclude {
5537
+ /**
5538
+ * Specifies a tailored instruction of this target.
5539
+ *
5540
+ * string template using $variable from instructionParams */
5541
+ instruction?: string
5542
+ /**
5543
+ * By default, all children up to `target.maxPathDepth` are included.
5544
+ *
5545
+ * When `include` is specified, only segments explicitly listed will be included.
5546
+ *
5547
+ * Fields or array items not on the include list, are implicitly excluded.
5548
+ */
5549
+ include?: (AgentActionPathSegment | TransformTargetInclude)[]
5550
+ }
5551
+
5552
+ /** @beta */
5553
+ export declare type TranslateDocument<T extends Record<string, Any> = Record<string, Any>> =
5554
+ | TranslateDocumentSync<T>
5555
+ | TranslateDocumentAsync
5556
+
5557
+ /** @beta */
5558
+ declare type TranslateDocumentAsync = TranslateRequestBase & AgentActionAsync
5559
+
5560
+ /** @beta */
5561
+ declare type TranslateDocumentSync<T extends Record<string, Any> = Record<string, Any>> =
5562
+ TranslateRequestBase & AgentActionSync
5563
+
5564
+ /** @beta */
5565
+ declare interface TranslateLanguage {
5566
+ /**
5567
+ * Language code
5568
+ */
5569
+ id: string
5570
+ /**
5571
+ * While optional, it is recommended to provide a language title
5572
+ */
5573
+ title?: string
5574
+ }
5575
+
5576
+ /** @beta */
5577
+ declare interface TranslateRequestBase extends AgentActionRequestBase {
5578
+ /** schemaId as reported by sanity deploy / sanity schema store */
5579
+ schemaId: string
5580
+ /**
5581
+ * The source document the transformation will use as input.
5582
+ */
5583
+ documentId: string
5584
+ /**
5585
+ * The target document will first get content copied over from the source,
5586
+ * then it is translated according to the instruction.
5587
+ *
5588
+ * When omitted, the source document (documentId) is also the target document.
5589
+ */
5590
+ targetDocument?: TransformTargetDocument
5591
+ /**
5592
+ * While optional, it is recommended
5593
+ */
5594
+ fromLanguage?: TranslateLanguage
5595
+ toLanguage: TranslateLanguage
5596
+ /**
5597
+ * `styleGuide` can be used to tailor how the translation should be preformed.
5598
+ *
5599
+ * String template using $variable from styleGuideParams.
5600
+ *
5601
+ * Capped to 2000 characters, after variables has been injected.
5602
+ *
5603
+ * @see #protectedPhrases
5604
+ */
5605
+ styleGuide?: string
5606
+ /** param values for the string template, keys are the variable name, ie if the template has "$variable", one key must be "variable" */
5607
+ styleGuideParams?: AgentActionParams
5608
+ /**
5609
+ * When the input string contains any phrase from `protectedPhrases`, the LLM will be instructed not
5610
+ * to translate them.
5611
+ *
5612
+ * It is recommended to use `protectedPhrases` instead of `styleGuide` for deny-list words and phrases,
5613
+ * since it keeps token cost low, resulting in faster responses, and limits how much information the LLM
5614
+ * has to process, since only phrases that are actually in the input string will be included in the final prompt.
5615
+ */
5616
+ protectedPhrases?: string[]
5617
+ /**
5618
+ * When specified, the `toLanguage.id` will be stored in the specified path in the target document.
5619
+ *
5620
+ * The file _can_ be hidden: true (unlike other fields in the target, which will be ignored)
5621
+ */
5622
+ languageFieldPath?: AgentActionPathSegment | AgentActionPath
5623
+ /**
5624
+ * Target defines which parts of the document will be affected by the instruction.
5625
+ * It can be an array, so multiple parts of the document can be separately configured in detail.
5626
+ *
5627
+ * Omitting target implies that the document itself is the root.
5628
+ *
5629
+ * Notes:
5630
+ * - instruction can only affect fields up to `maxPathDepth`
5631
+ * - when multiple targets are provided, they will be coalesced into a single target sharing a common target root.
5632
+ * It is therefor an error to provide conflicting include/exclude across targets (ie, include title in one, and exclude it in another)
5633
+ *
5634
+ * @see AgentActionRequestBase#conditionalPaths
5635
+ */
5636
+ target?: TranslateTarget | TranslateTarget[]
5637
+ }
5638
+
5639
+ /** @beta */
5640
+ export declare interface TranslateTarget extends AgentActionTarget {
5641
+ /** string template using $variable from instructionParams */
5642
+ styleGuide?: string
5643
+ /**
5644
+ * By default, all children up to `target.maxPathDepth` are included.
5645
+ *
5646
+ * When `include` is specified, only segments explicitly listed will be included.
5647
+ *
5648
+ * Fields or array items not on the include list, are implicitly excluded.
5649
+ */
5650
+ include?: (AgentActionPathSegment | TranslateTargetInclude)[]
5651
+ }
5652
+
5653
+ /** @beta */
5654
+ export declare interface TranslateTargetInclude extends AgentActionTargetInclude {
5655
+ /** string template using $variable from instructionParams */
5656
+ styleGuide?: string
5657
+ /**
5658
+ * By default, all children up to `target.maxPathDepth` are included.
5659
+ *
5660
+ * When `include` is specified, only segments explicitly listed will be included.
5661
+ *
5662
+ * Fields or array items not on the include list, are implicitly excluded.
5663
+ */
5664
+ include?: (AgentActionPathSegment | TranslateTargetInclude)[]
5665
+ }
5666
+
5667
+ /**
5668
+ * Unarchived an `archived` release, and restores all the release documents.
5669
+ *
5670
+ * @public
5671
+ */
5672
+ export declare interface UnarchiveReleaseAction {
5673
+ actionType: 'sanity.action.release.unarchive'
5674
+ releaseId: string
5675
+ }
5676
+
4717
5677
  /** @public */
4718
5678
  export declare interface UnfilteredResponseQueryOptions extends ResponseQueryOptions {
4719
5679
  filterResponse: false
@@ -4755,6 +5715,28 @@ export declare type UnpublishAction = {
4755
5715
  publishedId: string
4756
5716
  }
4757
5717
 
5718
+ /**
5719
+ * Identify that a version of a document should be unpublished when
5720
+ * the release that version is contained within is published.
5721
+ *
5722
+ * @public
5723
+ */
5724
+ export declare interface UnpublishVersionAction {
5725
+ actionType: 'sanity.action.document.version.unpublish'
5726
+ versionId: string
5727
+ publishedId: string
5728
+ }
5729
+
5730
+ /**
5731
+ * Unschedules a `scheduled` release, stopping it from being published.
5732
+ *
5733
+ * @public
5734
+ */
5735
+ export declare interface UnscheduleReleaseAction {
5736
+ actionType: 'sanity.action.release.unschedule'
5737
+ releaseId: string
5738
+ }
5739
+
4758
5740
  export {unstable__adapter}
4759
5741
 
4760
5742
  export {unstable__environment}
@@ -4824,7 +5806,7 @@ export declare interface UploadClientConfig {
4824
5806
  }
4825
5807
 
4826
5808
  /** @public */
4827
- export declare class UsersClient implements UsersClientType {
5809
+ export declare class UsersClient {
4828
5810
  #private
4829
5811
  constructor(client: SanityClient, httpRequest: HttpRequest)
4830
5812
  /**
@@ -4835,16 +5817,6 @@ export declare class UsersClient implements UsersClientType {
4835
5817
  getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
4836
5818
  }
4837
5819
 
4838
- /** @internal */
4839
- declare interface UsersClientType {
4840
- /**
4841
- * Fetch a user by user ID
4842
- *
4843
- * @param id - User ID of the user to fetch. If `me` is provided, a minimal response including the users role is returned.
4844
- */
4845
- getById<T extends 'me' | string>(id: T): Promise<T extends 'me' ? CurrentSanityUser : SanityUser>
4846
- }
4847
-
4848
5820
  /**
4849
5821
  * @internal - it may have breaking changes in any release
4850
5822
  */
@@ -4860,6 +5832,13 @@ export declare function validateApiPerspective(
4860
5832
  */
4861
5833
  export declare const vercelStegaCleanAll: typeof stegaClean
4862
5834
 
5835
+ /** @public */
5836
+ export declare type VersionAction =
5837
+ | CreateVersionAction
5838
+ | DiscardVersionAction
5839
+ | ReplaceVersionAction
5840
+ | UnpublishVersionAction
5841
+
4863
5842
  /**
4864
5843
  * The listener has been established, and will start receiving events.
4865
5844
  * Note that this is also emitted upon _reconnection_.