@sanity/client 7.1.0 → 7.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +516 -40
- package/dist/_chunks-cjs/config.cjs +14 -0
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +15 -1
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +750 -5
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +1282 -1
- package/dist/index.browser.d.ts +1282 -1
- package/dist/index.browser.js +752 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +739 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1282 -1
- package/dist/index.d.ts +1282 -1
- package/dist/index.js +742 -7
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +1282 -1
- package/dist/stega.browser.d.ts +1282 -1
- package/dist/stega.d.cts +1282 -1
- package/dist/stega.d.ts +1282 -1
- package/package.json +2 -1
- package/src/SanityClient.ts +592 -4
- package/src/data/dataMethods.ts +126 -2
- package/src/releases/ReleasesClient.ts +687 -0
- package/src/releases/createRelease.ts +53 -0
- package/src/types.ts +215 -0
- package/src/util/createVersionId.ts +79 -0
- package/src/validators.ts +23 -1
- package/umd/sanityClient.js +814 -4
- package/umd/sanityClient.min.js +2 -2
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
import {lastValueFrom, map, Observable} from 'rxjs'
|
|
2
|
+
|
|
3
|
+
import {_action, _getDocument, _getReleaseDocuments} from '../data/dataMethods'
|
|
4
|
+
import type {ObservableSanityClient, SanityClient} from '../SanityClient'
|
|
5
|
+
import type {
|
|
6
|
+
ArchiveReleaseAction,
|
|
7
|
+
BaseActionOptions,
|
|
8
|
+
BaseMutationOptions,
|
|
9
|
+
DeleteReleaseAction,
|
|
10
|
+
EditReleaseAction,
|
|
11
|
+
HttpRequest,
|
|
12
|
+
PatchOperations,
|
|
13
|
+
PublishReleaseAction,
|
|
14
|
+
RawQueryResponse,
|
|
15
|
+
ReleaseDocument,
|
|
16
|
+
SanityDocument,
|
|
17
|
+
ScheduleReleaseAction,
|
|
18
|
+
SingleActionResult,
|
|
19
|
+
UnarchiveReleaseAction,
|
|
20
|
+
UnscheduleReleaseAction,
|
|
21
|
+
} from '../types'
|
|
22
|
+
import {createRelease} from './createRelease'
|
|
23
|
+
|
|
24
|
+
/** @public */
|
|
25
|
+
export class ObservableReleasesClient {
|
|
26
|
+
#client: ObservableSanityClient
|
|
27
|
+
#httpRequest: HttpRequest
|
|
28
|
+
constructor(client: ObservableSanityClient, httpRequest: HttpRequest) {
|
|
29
|
+
this.#client = client
|
|
30
|
+
this.#httpRequest = httpRequest
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @public
|
|
35
|
+
*
|
|
36
|
+
* Retrieve a release by id.
|
|
37
|
+
*
|
|
38
|
+
* @category Releases
|
|
39
|
+
*
|
|
40
|
+
* @param params - Release action parameters:
|
|
41
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
42
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
43
|
+
* @returns An observable that resolves to the release document {@link ReleaseDocument}.
|
|
44
|
+
*
|
|
45
|
+
* @example Retrieving a release by id
|
|
46
|
+
* ```ts
|
|
47
|
+
* client.observable.releases.get({releaseId: 'my-release'}).pipe(
|
|
48
|
+
* tap((release) => console.log(release)),
|
|
49
|
+
* // {
|
|
50
|
+
* // _id: '_.releases.my-release',
|
|
51
|
+
* // name: 'my-release'
|
|
52
|
+
* // _type: 'system.release',
|
|
53
|
+
* // metadata: {releaseType: 'asap'},
|
|
54
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
55
|
+
* // ...
|
|
56
|
+
* // }
|
|
57
|
+
* ).subscribe()
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
get(
|
|
61
|
+
{releaseId}: {releaseId: string},
|
|
62
|
+
options?: {signal?: AbortSignal; tag?: string},
|
|
63
|
+
): Observable<ReleaseDocument | undefined> {
|
|
64
|
+
return _getDocument<ReleaseDocument>(
|
|
65
|
+
this.#client,
|
|
66
|
+
this.#httpRequest,
|
|
67
|
+
`_.releases.${releaseId}`,
|
|
68
|
+
options,
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @public
|
|
74
|
+
*
|
|
75
|
+
* Creates a new release under the given id, with metadata.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* * If no releaseId is provided, a release id will be generated.
|
|
79
|
+
* * If no metadata is provided, then an `undecided` releaseType will be used.
|
|
80
|
+
*
|
|
81
|
+
* @category Releases
|
|
82
|
+
*
|
|
83
|
+
* @param params - Release action parameters:
|
|
84
|
+
* - `releaseId` - The id of the release to create.
|
|
85
|
+
* - `metadata` - The metadata to associate with the release {@link ReleaseDocument}.
|
|
86
|
+
* @param options - Additional action options.
|
|
87
|
+
* @returns An observable that resolves to the `transactionId` and the release id and metadata.
|
|
88
|
+
*
|
|
89
|
+
* @example Creating a release with a custom id and metadata
|
|
90
|
+
* ```ts
|
|
91
|
+
* const releaseId = 'my-release'
|
|
92
|
+
* const metadata: ReleaseDocument['metadata'] = {
|
|
93
|
+
* releaseType: 'asap',
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* client.observable.releases.create({releaseId, metadata}).pipe(
|
|
97
|
+
* tap(({transactionId, releaseId, metadata}) => console.log(transactionId, releaseId, metadata)),
|
|
98
|
+
* // {
|
|
99
|
+
* // transactionId: 'transaction-id',
|
|
100
|
+
* // releaseId: 'my-release',
|
|
101
|
+
* // metadata: {releaseType: 'asap'},
|
|
102
|
+
* // }
|
|
103
|
+
* ).subscribe()
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example Creating a release with generated id and metadata
|
|
107
|
+
* ```ts
|
|
108
|
+
* client.observable.releases.create().pipe(
|
|
109
|
+
* tap(({metadata}) => console.log(metadata)),
|
|
110
|
+
* // {
|
|
111
|
+
* // metadata: {releaseType: 'undecided'},
|
|
112
|
+
* // }
|
|
113
|
+
* ).subscribe()
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example Creating a release using a custom transaction id
|
|
117
|
+
* ```ts
|
|
118
|
+
* client.observable.releases.create({transactionId: 'my-transaction-id'}).pipe(
|
|
119
|
+
* tap(({transactionId, metadata}) => console.log(transactionId, metadata)),
|
|
120
|
+
* // {
|
|
121
|
+
* // transactionId: 'my-transaction-id',
|
|
122
|
+
* // metadata: {releaseType: 'undecided'},
|
|
123
|
+
* // }
|
|
124
|
+
* ).subscribe()
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
create(
|
|
128
|
+
options: BaseActionOptions,
|
|
129
|
+
): Observable<SingleActionResult & {releaseId: string; metadata: ReleaseDocument['metadata']}>
|
|
130
|
+
create(
|
|
131
|
+
release: {releaseId?: string; metadata?: Partial<ReleaseDocument['metadata']>},
|
|
132
|
+
options?: BaseActionOptions,
|
|
133
|
+
): Observable<SingleActionResult & {releaseId: string; metadata: ReleaseDocument['metadata']}>
|
|
134
|
+
create(
|
|
135
|
+
releaseOrOptions?:
|
|
136
|
+
| {releaseId?: string; metadata?: Partial<ReleaseDocument['metadata']>}
|
|
137
|
+
| BaseActionOptions,
|
|
138
|
+
maybeOptions?: BaseActionOptions,
|
|
139
|
+
): Observable<SingleActionResult & {releaseId: string; metadata: ReleaseDocument['metadata']}> {
|
|
140
|
+
const {action, options} = createRelease(releaseOrOptions, maybeOptions)
|
|
141
|
+
const {releaseId, metadata} = action
|
|
142
|
+
|
|
143
|
+
return _action(this.#client, this.#httpRequest, action, options).pipe(
|
|
144
|
+
map((actionResult) => ({
|
|
145
|
+
...actionResult,
|
|
146
|
+
releaseId,
|
|
147
|
+
metadata,
|
|
148
|
+
})),
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @public
|
|
154
|
+
*
|
|
155
|
+
* Edits an existing release, updating the metadata.
|
|
156
|
+
*
|
|
157
|
+
* @category Releases
|
|
158
|
+
*
|
|
159
|
+
* @param params - Release action parameters:
|
|
160
|
+
* - `releaseId` - The id of the release to edit.
|
|
161
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
162
|
+
* @param options - Additional action options.
|
|
163
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
164
|
+
*/
|
|
165
|
+
edit(
|
|
166
|
+
{releaseId, patch}: {releaseId: string; patch: PatchOperations},
|
|
167
|
+
options?: BaseActionOptions,
|
|
168
|
+
): Observable<SingleActionResult> {
|
|
169
|
+
const editAction: EditReleaseAction = {
|
|
170
|
+
actionType: 'sanity.action.release.edit',
|
|
171
|
+
releaseId,
|
|
172
|
+
patch,
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return _action(this.#client, this.#httpRequest, editAction, options)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @public
|
|
180
|
+
*
|
|
181
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
182
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
183
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
184
|
+
* take some time.
|
|
185
|
+
*
|
|
186
|
+
* During this period both the source and target documents are locked and cannot be
|
|
187
|
+
* modified through any other means.
|
|
188
|
+
*
|
|
189
|
+
* @category Releases
|
|
190
|
+
*
|
|
191
|
+
* @param params - Release action parameters:
|
|
192
|
+
* - `releaseId` - The id of the release to publish.
|
|
193
|
+
* @param options - Additional action options.
|
|
194
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
195
|
+
*/
|
|
196
|
+
publish(
|
|
197
|
+
{releaseId}: {releaseId: string},
|
|
198
|
+
options?: BaseActionOptions,
|
|
199
|
+
): Observable<SingleActionResult> {
|
|
200
|
+
const publishAction: PublishReleaseAction = {
|
|
201
|
+
actionType: 'sanity.action.release.publish',
|
|
202
|
+
releaseId,
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return _action(this.#client, this.#httpRequest, publishAction, options)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @public
|
|
210
|
+
*
|
|
211
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
212
|
+
* are deleted and therefore no longer queryable.
|
|
213
|
+
*
|
|
214
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
215
|
+
*
|
|
216
|
+
* @category Releases
|
|
217
|
+
*
|
|
218
|
+
* @param params - Release action parameters:
|
|
219
|
+
* - `releaseId` - The id of the release to archive.
|
|
220
|
+
* @param options - Additional action options.
|
|
221
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
222
|
+
*/
|
|
223
|
+
archive(
|
|
224
|
+
{releaseId}: {releaseId: string},
|
|
225
|
+
options?: BaseActionOptions,
|
|
226
|
+
): Observable<SingleActionResult> {
|
|
227
|
+
const archiveAction: ArchiveReleaseAction = {
|
|
228
|
+
actionType: 'sanity.action.release.archive',
|
|
229
|
+
releaseId,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return _action(this.#client, this.#httpRequest, archiveAction, options)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @public
|
|
237
|
+
*
|
|
238
|
+
* An unarchive action restores an archived release and all documents
|
|
239
|
+
* with the content they had just prior to archiving.
|
|
240
|
+
*
|
|
241
|
+
* @category Releases
|
|
242
|
+
*
|
|
243
|
+
* @param params - Release action parameters:
|
|
244
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
245
|
+
* @param options - Additional action options.
|
|
246
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
247
|
+
*/
|
|
248
|
+
unarchive(
|
|
249
|
+
{releaseId}: {releaseId: string},
|
|
250
|
+
options?: BaseActionOptions,
|
|
251
|
+
): Observable<SingleActionResult> {
|
|
252
|
+
const unarchiveAction: UnarchiveReleaseAction = {
|
|
253
|
+
actionType: 'sanity.action.release.unarchive',
|
|
254
|
+
releaseId,
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return _action(this.#client, this.#httpRequest, unarchiveAction, options)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @public
|
|
262
|
+
*
|
|
263
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
264
|
+
* The release is locked such that no documents in the release can be modified and
|
|
265
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
266
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
267
|
+
*
|
|
268
|
+
* @category Releases
|
|
269
|
+
*
|
|
270
|
+
* @param params - Release action parameters:
|
|
271
|
+
* - `releaseId` - The id of the release to schedule.
|
|
272
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
273
|
+
* @param options - Additional action options.
|
|
274
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
275
|
+
*/
|
|
276
|
+
schedule(
|
|
277
|
+
{releaseId, publishAt}: {releaseId: string; publishAt: string},
|
|
278
|
+
options?: BaseActionOptions,
|
|
279
|
+
): Observable<SingleActionResult> {
|
|
280
|
+
const scheduleAction: ScheduleReleaseAction = {
|
|
281
|
+
actionType: 'sanity.action.release.schedule',
|
|
282
|
+
releaseId,
|
|
283
|
+
publishAt,
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return _action(this.#client, this.#httpRequest, scheduleAction, options)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @public
|
|
291
|
+
*
|
|
292
|
+
* An unschedule action stops a release from being published.
|
|
293
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
294
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
295
|
+
* has a reference to a document created by this one.
|
|
296
|
+
*
|
|
297
|
+
* @category Releases
|
|
298
|
+
*
|
|
299
|
+
* @param params - Release action parameters:
|
|
300
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
301
|
+
* @param options - Additional action options.
|
|
302
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
303
|
+
*/
|
|
304
|
+
unschedule(
|
|
305
|
+
{releaseId}: {releaseId: string},
|
|
306
|
+
options?: BaseActionOptions,
|
|
307
|
+
): Observable<SingleActionResult> {
|
|
308
|
+
const unscheduleAction: UnscheduleReleaseAction = {
|
|
309
|
+
actionType: 'sanity.action.release.unschedule',
|
|
310
|
+
releaseId,
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return _action(this.#client, this.#httpRequest, unscheduleAction, options)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* @public
|
|
318
|
+
*
|
|
319
|
+
* A delete action removes a published or archived release.
|
|
320
|
+
* The backing system document will be removed from the dataset.
|
|
321
|
+
*
|
|
322
|
+
* @category Releases
|
|
323
|
+
*
|
|
324
|
+
* @param params - Release action parameters:
|
|
325
|
+
* - `releaseId` - The id of the release to delete.
|
|
326
|
+
* @param options - Additional action options.
|
|
327
|
+
* @returns An observable that resolves to the `transactionId`.
|
|
328
|
+
*/
|
|
329
|
+
delete(
|
|
330
|
+
{releaseId}: {releaseId: string},
|
|
331
|
+
options?: BaseActionOptions,
|
|
332
|
+
): Observable<SingleActionResult> {
|
|
333
|
+
const deleteAction: DeleteReleaseAction = {
|
|
334
|
+
actionType: 'sanity.action.release.delete',
|
|
335
|
+
releaseId,
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return _action(this.#client, this.#httpRequest, deleteAction, options)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* @public
|
|
343
|
+
*
|
|
344
|
+
* Fetch the documents in a release by release id.
|
|
345
|
+
*
|
|
346
|
+
* @category Releases
|
|
347
|
+
*
|
|
348
|
+
* @param params - Release action parameters:
|
|
349
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
350
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
351
|
+
* @returns An observable that resolves to the documents in the release.
|
|
352
|
+
*/
|
|
353
|
+
fetchDocuments(
|
|
354
|
+
{releaseId}: {releaseId: string},
|
|
355
|
+
options?: BaseMutationOptions,
|
|
356
|
+
): Observable<RawQueryResponse<SanityDocument[]>> {
|
|
357
|
+
return _getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options)
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** @public */
|
|
362
|
+
export class ReleasesClient {
|
|
363
|
+
#client: SanityClient
|
|
364
|
+
#httpRequest: HttpRequest
|
|
365
|
+
constructor(client: SanityClient, httpRequest: HttpRequest) {
|
|
366
|
+
this.#client = client
|
|
367
|
+
this.#httpRequest = httpRequest
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* @public
|
|
372
|
+
*
|
|
373
|
+
* Retrieve a release by id.
|
|
374
|
+
*
|
|
375
|
+
* @category Releases
|
|
376
|
+
*
|
|
377
|
+
* @param params - Release action parameters:
|
|
378
|
+
* - `releaseId` - The id of the release to retrieve.
|
|
379
|
+
* @param options - Additional query options including abort signal and query tag.
|
|
380
|
+
* @returns A promise that resolves to the release document {@link ReleaseDocument}.
|
|
381
|
+
*
|
|
382
|
+
* @example Retrieving a release by id
|
|
383
|
+
* ```ts
|
|
384
|
+
* const release = await client.releases.get({releaseId: 'my-release'})
|
|
385
|
+
* console.log(release)
|
|
386
|
+
* // {
|
|
387
|
+
* // _id: '_.releases.my-release',
|
|
388
|
+
* // name: 'my-release'
|
|
389
|
+
* // _type: 'system.release',
|
|
390
|
+
* // metadata: {releaseType: 'asap'},
|
|
391
|
+
* // _createdAt: '2021-01-01T00:00:00.000Z',
|
|
392
|
+
* // ...
|
|
393
|
+
* // }
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
get(
|
|
397
|
+
{releaseId}: {releaseId: string},
|
|
398
|
+
options?: {signal?: AbortSignal; tag?: string},
|
|
399
|
+
): Promise<ReleaseDocument | undefined> {
|
|
400
|
+
return lastValueFrom(
|
|
401
|
+
_getDocument<ReleaseDocument>(
|
|
402
|
+
this.#client,
|
|
403
|
+
this.#httpRequest,
|
|
404
|
+
`_.releases.${releaseId}`,
|
|
405
|
+
options,
|
|
406
|
+
),
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @public
|
|
412
|
+
*
|
|
413
|
+
* Creates a new release under the given id, with metadata.
|
|
414
|
+
*
|
|
415
|
+
* @remarks
|
|
416
|
+
* * If no releaseId is provided, a release id will be generated.
|
|
417
|
+
* * If no metadata is provided, then an `undecided` releaseType will be used.
|
|
418
|
+
*
|
|
419
|
+
* @category Releases
|
|
420
|
+
*
|
|
421
|
+
* @param params - Release action parameters:
|
|
422
|
+
* - `releaseId` - The id of the release to create.
|
|
423
|
+
* - `metadata` - The metadata to associate with the release {@link ReleaseDocument}.
|
|
424
|
+
* @param options - Additional action options.
|
|
425
|
+
* @returns A promise that resolves to the `transactionId` and the release id and metadata.
|
|
426
|
+
*
|
|
427
|
+
* @example Creating a release with a custom id and metadata
|
|
428
|
+
* ```ts
|
|
429
|
+
* const releaseId = 'my-release'
|
|
430
|
+
* const releaseMetadata: ReleaseDocument['metadata'] = {
|
|
431
|
+
* releaseType: 'asap',
|
|
432
|
+
* }
|
|
433
|
+
*
|
|
434
|
+
* const result =
|
|
435
|
+
* await client.releases.create({releaseId, metadata: releaseMetadata})
|
|
436
|
+
* console.log(result)
|
|
437
|
+
* // {
|
|
438
|
+
* // transactionId: 'transaction-id',
|
|
439
|
+
* // releaseId: 'my-release',
|
|
440
|
+
* // metadata: {releaseType: 'asap'},
|
|
441
|
+
* // }
|
|
442
|
+
* ```
|
|
443
|
+
*
|
|
444
|
+
* @example Creating a release with generated id and metadata
|
|
445
|
+
* ```ts
|
|
446
|
+
* const {metadata} = await client.releases.create()
|
|
447
|
+
* console.log(metadata.releaseType) // 'undecided'
|
|
448
|
+
* ```
|
|
449
|
+
*
|
|
450
|
+
* @example Creating a release with a custom transaction id
|
|
451
|
+
* ```ts
|
|
452
|
+
* const {transactionId, metadata} = await client.releases.create({transactionId: 'my-transaction-id'})
|
|
453
|
+
* console.log(metadata.releaseType) // 'undecided'
|
|
454
|
+
* console.log(transactionId) // 'my-transaction-id'
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
async create(
|
|
458
|
+
options: BaseActionOptions,
|
|
459
|
+
): Promise<SingleActionResult & {releaseId: string; metadata: ReleaseDocument['metadata']}>
|
|
460
|
+
async create(
|
|
461
|
+
release: {releaseId?: string; metadata?: Partial<ReleaseDocument['metadata']>},
|
|
462
|
+
options?: BaseActionOptions,
|
|
463
|
+
): Promise<SingleActionResult & {releaseId: string; metadata: ReleaseDocument['metadata']}>
|
|
464
|
+
async create(
|
|
465
|
+
releaseOrOptions?:
|
|
466
|
+
| {releaseId?: string; metadata?: Partial<ReleaseDocument['metadata']>}
|
|
467
|
+
| BaseActionOptions,
|
|
468
|
+
maybeOptions?: BaseActionOptions,
|
|
469
|
+
): Promise<SingleActionResult & {releaseId: string; metadata: ReleaseDocument['metadata']}> {
|
|
470
|
+
const {action, options} = createRelease(releaseOrOptions, maybeOptions)
|
|
471
|
+
const {releaseId, metadata} = action
|
|
472
|
+
|
|
473
|
+
const actionResult = await lastValueFrom(
|
|
474
|
+
_action(this.#client, this.#httpRequest, action, options),
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
return {...actionResult, releaseId, metadata}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* @public
|
|
482
|
+
*
|
|
483
|
+
* Edits an existing release, updating the metadata.
|
|
484
|
+
*
|
|
485
|
+
* @category Releases
|
|
486
|
+
*
|
|
487
|
+
* @param params - Release action parameters:
|
|
488
|
+
* - `releaseId` - The id of the release to edit.
|
|
489
|
+
* - `patch` - The patch operation to apply on the release metadata {@link PatchMutationOperation}.
|
|
490
|
+
* @param options - Additional action options.
|
|
491
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
492
|
+
*/
|
|
493
|
+
edit(
|
|
494
|
+
{releaseId, patch}: {releaseId: string; patch: PatchOperations},
|
|
495
|
+
options?: BaseActionOptions,
|
|
496
|
+
): Promise<SingleActionResult> {
|
|
497
|
+
const editAction: EditReleaseAction = {
|
|
498
|
+
actionType: 'sanity.action.release.edit',
|
|
499
|
+
releaseId,
|
|
500
|
+
patch,
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, editAction, options))
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* @public
|
|
508
|
+
*
|
|
509
|
+
* Publishes all documents in a release at once. For larger releases the effect of the publish
|
|
510
|
+
* will be visible immediately when querying but the removal of the `versions.<releasesId>.*`
|
|
511
|
+
* documents and creation of the corresponding published documents with the new content may
|
|
512
|
+
* take some time.
|
|
513
|
+
*
|
|
514
|
+
* During this period both the source and target documents are locked and cannot be
|
|
515
|
+
* modified through any other means.
|
|
516
|
+
*
|
|
517
|
+
* @category Releases
|
|
518
|
+
*
|
|
519
|
+
* @param params - Release action parameters:
|
|
520
|
+
* - `releaseId` - The id of the release to publish.
|
|
521
|
+
* @param options - Additional action options.
|
|
522
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
523
|
+
*/
|
|
524
|
+
publish(
|
|
525
|
+
{releaseId}: {releaseId: string},
|
|
526
|
+
options?: BaseActionOptions,
|
|
527
|
+
): Promise<SingleActionResult> {
|
|
528
|
+
const publishAction: PublishReleaseAction = {
|
|
529
|
+
actionType: 'sanity.action.release.publish',
|
|
530
|
+
releaseId,
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, publishAction, options))
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* @public
|
|
538
|
+
*
|
|
539
|
+
* An archive action removes an active release. The documents that comprise the release
|
|
540
|
+
* are deleted and therefore no longer queryable.
|
|
541
|
+
*
|
|
542
|
+
* While the documents remain in retention the last version can still be accessed using document history endpoint.
|
|
543
|
+
*
|
|
544
|
+
* @category Releases
|
|
545
|
+
*
|
|
546
|
+
* @param params - Release action parameters:
|
|
547
|
+
* - `releaseId` - The id of the release to archive.
|
|
548
|
+
* @param options - Additional action options.
|
|
549
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
550
|
+
*/
|
|
551
|
+
archive(
|
|
552
|
+
{releaseId}: {releaseId: string},
|
|
553
|
+
options?: BaseActionOptions,
|
|
554
|
+
): Promise<SingleActionResult> {
|
|
555
|
+
const archiveAction: ArchiveReleaseAction = {
|
|
556
|
+
actionType: 'sanity.action.release.archive',
|
|
557
|
+
releaseId,
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, archiveAction, options))
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* @public
|
|
565
|
+
*
|
|
566
|
+
* An unarchive action restores an archived release and all documents
|
|
567
|
+
* with the content they had just prior to archiving.
|
|
568
|
+
*
|
|
569
|
+
* @category Releases
|
|
570
|
+
*
|
|
571
|
+
* @param params - Release action parameters:
|
|
572
|
+
* - `releaseId` - The id of the release to unarchive.
|
|
573
|
+
* @param options - Additional action options.
|
|
574
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
575
|
+
*/
|
|
576
|
+
unarchive(
|
|
577
|
+
{releaseId}: {releaseId: string},
|
|
578
|
+
options?: BaseActionOptions,
|
|
579
|
+
): Promise<SingleActionResult> {
|
|
580
|
+
const unarchiveAction: UnarchiveReleaseAction = {
|
|
581
|
+
actionType: 'sanity.action.release.unarchive',
|
|
582
|
+
releaseId,
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, unarchiveAction, options))
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* @public
|
|
590
|
+
*
|
|
591
|
+
* A schedule action queues a release for publishing at the given future time.
|
|
592
|
+
* The release is locked such that no documents in the release can be modified and
|
|
593
|
+
* no documents that it references can be deleted as this would make the publish fail.
|
|
594
|
+
* At the given time, the same logic as for the publish action is triggered.
|
|
595
|
+
*
|
|
596
|
+
* @category Releases
|
|
597
|
+
*
|
|
598
|
+
* @param params - Release action parameters:
|
|
599
|
+
* - `releaseId` - The id of the release to schedule.
|
|
600
|
+
* - `publishAt` - The serialised date and time to publish the release. If the `publishAt` is in the past, the release will be published immediately.
|
|
601
|
+
* @param options - Additional action options.
|
|
602
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
603
|
+
*/
|
|
604
|
+
schedule(
|
|
605
|
+
{releaseId, publishAt}: {releaseId: string; publishAt: string},
|
|
606
|
+
options?: BaseActionOptions,
|
|
607
|
+
): Promise<SingleActionResult> {
|
|
608
|
+
const scheduleAction: ScheduleReleaseAction = {
|
|
609
|
+
actionType: 'sanity.action.release.schedule',
|
|
610
|
+
releaseId,
|
|
611
|
+
publishAt,
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, scheduleAction, options))
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* @public
|
|
619
|
+
*
|
|
620
|
+
* An unschedule action stops a release from being published.
|
|
621
|
+
* The documents in the release are considered unlocked and can be edited again.
|
|
622
|
+
* This may fail if another release is scheduled to be published after this one and
|
|
623
|
+
* has a reference to a document created by this one.
|
|
624
|
+
*
|
|
625
|
+
* @category Releases
|
|
626
|
+
*
|
|
627
|
+
* @param params - Release action parameters:
|
|
628
|
+
* - `releaseId` - The id of the release to unschedule.
|
|
629
|
+
* @param options - Additional action options.
|
|
630
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
631
|
+
*/
|
|
632
|
+
unschedule(
|
|
633
|
+
{releaseId}: {releaseId: string},
|
|
634
|
+
options?: BaseActionOptions,
|
|
635
|
+
): Promise<SingleActionResult> {
|
|
636
|
+
const unscheduleAction: UnscheduleReleaseAction = {
|
|
637
|
+
actionType: 'sanity.action.release.unschedule',
|
|
638
|
+
releaseId,
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, unscheduleAction, options))
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* @public
|
|
646
|
+
*
|
|
647
|
+
* A delete action removes a published or archived release.
|
|
648
|
+
* The backing system document will be removed from the dataset.
|
|
649
|
+
*
|
|
650
|
+
* @category Releases
|
|
651
|
+
*
|
|
652
|
+
* @param params - Release action parameters:
|
|
653
|
+
* - `releaseId` - The id of the release to delete.
|
|
654
|
+
* @param options - Additional action options.
|
|
655
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
656
|
+
*/
|
|
657
|
+
delete(
|
|
658
|
+
{releaseId}: {releaseId: string},
|
|
659
|
+
options?: BaseActionOptions,
|
|
660
|
+
): Promise<SingleActionResult> {
|
|
661
|
+
const deleteAction: DeleteReleaseAction = {
|
|
662
|
+
actionType: 'sanity.action.release.delete',
|
|
663
|
+
releaseId,
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
return lastValueFrom(_action(this.#client, this.#httpRequest, deleteAction, options))
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* @public
|
|
671
|
+
*
|
|
672
|
+
* Fetch the documents in a release by release id.
|
|
673
|
+
*
|
|
674
|
+
* @category Releases
|
|
675
|
+
*
|
|
676
|
+
* @param params - Release action parameters:
|
|
677
|
+
* - `releaseId` - The id of the release to fetch documents for.
|
|
678
|
+
* @param options - Additional mutation options {@link BaseMutationOptions}.
|
|
679
|
+
* @returns A promise that resolves to the documents in the release.
|
|
680
|
+
*/
|
|
681
|
+
fetchDocuments(
|
|
682
|
+
{releaseId}: {releaseId: string},
|
|
683
|
+
options?: BaseMutationOptions,
|
|
684
|
+
): Promise<RawQueryResponse<SanityDocument[]>> {
|
|
685
|
+
return lastValueFrom(_getReleaseDocuments(this.#client, this.#httpRequest, releaseId, options))
|
|
686
|
+
}
|
|
687
|
+
}
|