@sanity/client 7.1.0-views.0 → 7.1.0-views.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 +668 -40
- package/dist/_chunks-cjs/config.cjs +14 -0
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-cjs/dataMethods.cjs +197 -32
- package/dist/_chunks-cjs/dataMethods.cjs.map +1 -1
- package/dist/_chunks-cjs/isRecord.cjs +6 -0
- package/dist/_chunks-cjs/isRecord.cjs.map +1 -0
- package/dist/_chunks-cjs/resolveEditInfo.cjs +3 -5
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +4 -0
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +2 -5
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/config.js +15 -1
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/_chunks-es/dataMethods.js +200 -33
- package/dist/_chunks-es/dataMethods.js.map +1 -1
- package/dist/_chunks-es/isRecord.js +7 -0
- package/dist/_chunks-es/isRecord.js.map +1 -0
- package/dist/_chunks-es/resolveEditInfo.js +1 -3
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +4 -0
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -4
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/index.browser.cjs +1019 -59
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +1948 -149
- package/dist/index.browser.d.ts +1948 -149
- package/dist/index.browser.js +1021 -60
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +825 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1948 -149
- package/dist/index.d.ts +1948 -149
- package/dist/index.js +826 -31
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +1948 -149
- package/dist/stega.browser.d.ts +1948 -149
- package/dist/stega.d.cts +1948 -149
- package/dist/stega.d.ts +1948 -149
- package/dist/views.cjs +13 -5
- package/dist/views.cjs.map +1 -1
- package/dist/views.d.cts +51 -36
- package/dist/views.d.ts +51 -36
- package/dist/views.js +14 -5
- package/dist/views.js.map +1 -1
- package/package.json +2 -1
- package/src/SanityClient.ts +652 -12
- package/src/agent/actions/AgentActionsClient.ts +29 -2
- package/src/agent/actions/commonTypes.ts +57 -17
- package/src/agent/actions/generate.ts +36 -2
- package/src/agent/actions/patch.ts +136 -0
- package/src/agent/actions/prompt.ts +145 -0
- package/src/agent/actions/transform.ts +105 -7
- package/src/agent/actions/translate.ts +5 -2
- package/src/config.ts +3 -1
- package/src/csm/walkMap.ts +1 -1
- package/src/data/dataMethods.ts +170 -12
- package/src/data/encodeQueryString.ts +1 -1
- package/src/data/eventsource.ts +16 -7
- package/src/data/listen.ts +10 -4
- package/src/data/live.ts +13 -5
- package/src/datasets/DatasetsClient.ts +4 -1
- package/src/defineCreateClient.ts +7 -1
- package/src/http/errors.ts +92 -27
- package/src/http/request.ts +3 -3
- package/src/http/requestOptions.ts +4 -0
- package/src/projects/ProjectsClient.ts +6 -2
- package/src/releases/ReleasesClient.ts +693 -0
- package/src/releases/createRelease.ts +53 -0
- package/src/types.ts +291 -10
- package/src/users/UsersClient.ts +7 -3
- package/src/util/codeFrame.ts +174 -0
- package/src/util/createVersionId.ts +79 -0
- package/src/{csm → util}/isRecord.ts +1 -1
- package/src/validators.ts +23 -1
- package/src/views/index.ts +51 -15
- package/umd/sanityClient.js +1067 -61
- package/umd/sanityClient.min.js +2 -2
package/src/SanityClient.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {getPublishedId, getVersionId} from '@sanity/client/csm'
|
|
2
|
+
import {firstValueFrom, lastValueFrom, Observable} from 'rxjs'
|
|
2
3
|
|
|
3
4
|
import {AgentActionsClient, ObservableAgentsActionClient} from './agent/actions/AgentActionsClient'
|
|
4
5
|
import {AssetsClient, ObservableAssetsClient} from './assets/AssetsClient'
|
|
@@ -10,6 +11,7 @@ import {ObservablePatch, Patch} from './data/patch'
|
|
|
10
11
|
import {ObservableTransaction, Transaction} from './data/transaction'
|
|
11
12
|
import {DatasetsClient, ObservableDatasetsClient} from './datasets/DatasetsClient'
|
|
12
13
|
import {ObservableProjectsClient, ProjectsClient} from './projects/ProjectsClient'
|
|
14
|
+
import {ObservableReleasesClient, ReleasesClient} from './releases/ReleasesClient'
|
|
13
15
|
import type {
|
|
14
16
|
Action,
|
|
15
17
|
AllDocumentIdsMutationOptions,
|
|
@@ -45,6 +47,7 @@ import type {
|
|
|
45
47
|
UnfilteredResponseWithoutQuery,
|
|
46
48
|
} from './types'
|
|
47
49
|
import {ObservableUsersClient, UsersClient} from './users/UsersClient'
|
|
50
|
+
import {deriveDocumentVersionId, getDocumentVersionId} from './util/createVersionId'
|
|
48
51
|
|
|
49
52
|
export type {
|
|
50
53
|
_listen,
|
|
@@ -69,6 +72,7 @@ export class ObservableSanityClient {
|
|
|
69
72
|
agent: {
|
|
70
73
|
action: ObservableAgentsActionClient
|
|
71
74
|
}
|
|
75
|
+
releases: ObservableReleasesClient
|
|
72
76
|
|
|
73
77
|
/**
|
|
74
78
|
* Private properties
|
|
@@ -94,6 +98,7 @@ export class ObservableSanityClient {
|
|
|
94
98
|
this.agent = {
|
|
95
99
|
action: new ObservableAgentsActionClient(this, this.#httpRequest),
|
|
96
100
|
}
|
|
101
|
+
this.releases = new ObservableReleasesClient(this, this.#httpRequest)
|
|
97
102
|
}
|
|
98
103
|
|
|
99
104
|
/**
|
|
@@ -226,7 +231,7 @@ export class ObservableSanityClient {
|
|
|
226
231
|
*/
|
|
227
232
|
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
228
233
|
id: string,
|
|
229
|
-
options?: {tag?: string},
|
|
234
|
+
options?: {signal?: AbortSignal; tag?: string; releaseId?: string},
|
|
230
235
|
): Observable<SanityDocument<R> | undefined> {
|
|
231
236
|
return dataMethods._getDocument<R>(this.#clientConfig, this.#httpRequest, id, options)
|
|
232
237
|
}
|
|
@@ -313,7 +318,13 @@ export class ObservableSanityClient {
|
|
|
313
318
|
): Observable<
|
|
314
319
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
315
320
|
> {
|
|
316
|
-
return dataMethods._create<R>(
|
|
321
|
+
return dataMethods._create<R>(
|
|
322
|
+
this.#clientConfig,
|
|
323
|
+
this.#httpRequest,
|
|
324
|
+
document,
|
|
325
|
+
'create',
|
|
326
|
+
options,
|
|
327
|
+
)
|
|
317
328
|
}
|
|
318
329
|
|
|
319
330
|
/**
|
|
@@ -382,7 +393,12 @@ export class ObservableSanityClient {
|
|
|
382
393
|
): Observable<
|
|
383
394
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
384
395
|
> {
|
|
385
|
-
return dataMethods._createIfNotExists<R>(
|
|
396
|
+
return dataMethods._createIfNotExists<R>(
|
|
397
|
+
this.#clientConfig,
|
|
398
|
+
this.#httpRequest,
|
|
399
|
+
document,
|
|
400
|
+
options,
|
|
401
|
+
)
|
|
386
402
|
}
|
|
387
403
|
|
|
388
404
|
/**
|
|
@@ -454,6 +470,120 @@ export class ObservableSanityClient {
|
|
|
454
470
|
return dataMethods._createOrReplace<R>(this.#clientConfig, this.#httpRequest, document, options)
|
|
455
471
|
}
|
|
456
472
|
|
|
473
|
+
/**
|
|
474
|
+
* @public
|
|
475
|
+
*
|
|
476
|
+
* Creates a new version of a published document.
|
|
477
|
+
*
|
|
478
|
+
* @remarks
|
|
479
|
+
* * Requires a document with a `_type` property.
|
|
480
|
+
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
481
|
+
* * 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`.
|
|
482
|
+
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
483
|
+
* * To create a version of an unpublished document, use the `client.create` method.
|
|
484
|
+
*
|
|
485
|
+
* @category Versions
|
|
486
|
+
*
|
|
487
|
+
* @param params - Version action parameters:
|
|
488
|
+
* - `document` - The document to create as a new version (must include `_type`).
|
|
489
|
+
* - `publishedId` - The ID of the published document being versioned.
|
|
490
|
+
* - `releaseId` - The ID of the release to create the version for.
|
|
491
|
+
* @param options - Additional action options.
|
|
492
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
493
|
+
*
|
|
494
|
+
* @example Creating a new version of a published document with a generated version ID
|
|
495
|
+
* ```ts
|
|
496
|
+
* client.observable.createVersion({
|
|
497
|
+
* // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
|
|
498
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
499
|
+
* publishedId: 'myDocument',
|
|
500
|
+
* releaseId: 'myRelease',
|
|
501
|
+
* })
|
|
502
|
+
*
|
|
503
|
+
* // The following document will be created:
|
|
504
|
+
* // {
|
|
505
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
506
|
+
* // _type: 'myDocument',
|
|
507
|
+
* // title: 'My Document',
|
|
508
|
+
* // }
|
|
509
|
+
* ```
|
|
510
|
+
*
|
|
511
|
+
* @example Creating a new version of a published document with a specified version ID
|
|
512
|
+
* ```ts
|
|
513
|
+
* client.observable.createVersion({
|
|
514
|
+
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
515
|
+
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
516
|
+
* })
|
|
517
|
+
*
|
|
518
|
+
* // The following document will be created:
|
|
519
|
+
* // {
|
|
520
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
521
|
+
* // _type: 'myDocument',
|
|
522
|
+
* // title: 'My Document',
|
|
523
|
+
* // }
|
|
524
|
+
* ```
|
|
525
|
+
*
|
|
526
|
+
* @example Creating a new draft version of a published document
|
|
527
|
+
* ```ts
|
|
528
|
+
* client.observable.createVersion({
|
|
529
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
530
|
+
* publishedId: 'myDocument',
|
|
531
|
+
* })
|
|
532
|
+
*
|
|
533
|
+
* // The following document will be created:
|
|
534
|
+
* // {
|
|
535
|
+
* // _id: 'drafts.myDocument',
|
|
536
|
+
* // _type: 'myDocument',
|
|
537
|
+
* // title: 'My Document',
|
|
538
|
+
* // }
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
541
|
+
createVersion<R extends Record<string, Any>>(
|
|
542
|
+
args: {
|
|
543
|
+
document: SanityDocumentStub<R>
|
|
544
|
+
publishedId: string
|
|
545
|
+
releaseId?: string
|
|
546
|
+
},
|
|
547
|
+
options?: BaseActionOptions,
|
|
548
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
549
|
+
createVersion<R extends Record<string, Any>>(
|
|
550
|
+
args: {
|
|
551
|
+
document: IdentifiedSanityDocumentStub<R>
|
|
552
|
+
publishedId?: string
|
|
553
|
+
releaseId?: string
|
|
554
|
+
},
|
|
555
|
+
options?: BaseActionOptions,
|
|
556
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
557
|
+
createVersion<R extends Record<string, Any>>(
|
|
558
|
+
{
|
|
559
|
+
document,
|
|
560
|
+
publishedId,
|
|
561
|
+
releaseId,
|
|
562
|
+
}: {
|
|
563
|
+
document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
|
|
564
|
+
publishedId?: string
|
|
565
|
+
releaseId?: string
|
|
566
|
+
},
|
|
567
|
+
options?: BaseActionOptions,
|
|
568
|
+
): Observable<SingleActionResult | MultipleActionResult> {
|
|
569
|
+
const documentVersionId = deriveDocumentVersionId('createVersion', {
|
|
570
|
+
document,
|
|
571
|
+
publishedId,
|
|
572
|
+
releaseId,
|
|
573
|
+
})
|
|
574
|
+
|
|
575
|
+
const documentVersion = {...document, _id: documentVersionId}
|
|
576
|
+
const versionPublishedId = publishedId || getPublishedId(document._id)
|
|
577
|
+
|
|
578
|
+
return dataMethods._createVersion<R>(
|
|
579
|
+
this.config(),
|
|
580
|
+
this.#httpRequest,
|
|
581
|
+
documentVersion,
|
|
582
|
+
versionPublishedId,
|
|
583
|
+
options,
|
|
584
|
+
)
|
|
585
|
+
}
|
|
586
|
+
|
|
457
587
|
/**
|
|
458
588
|
* Deletes a document with the given document ID.
|
|
459
589
|
* Returns an observable that resolves to the deleted document.
|
|
@@ -572,6 +702,195 @@ export class ObservableSanityClient {
|
|
|
572
702
|
return dataMethods._delete<R>(this.#clientConfig, this.#httpRequest, selection, options)
|
|
573
703
|
}
|
|
574
704
|
|
|
705
|
+
/**
|
|
706
|
+
* @public
|
|
707
|
+
*
|
|
708
|
+
* Deletes the draft or release version of a document.
|
|
709
|
+
*
|
|
710
|
+
* @remarks
|
|
711
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
712
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
713
|
+
*
|
|
714
|
+
* @param params - Version action parameters:
|
|
715
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
716
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
717
|
+
* @param purge - if `true` the document history is also discarded.
|
|
718
|
+
* @param options - Additional action options.
|
|
719
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
720
|
+
*
|
|
721
|
+
* @example Discarding a release version of a document
|
|
722
|
+
* ```ts
|
|
723
|
+
* client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
724
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
725
|
+
* ```
|
|
726
|
+
*
|
|
727
|
+
* @example Discarding a draft version of a document
|
|
728
|
+
* ```ts
|
|
729
|
+
* client.observable.discardVersion({publishedId: 'myDocument'})
|
|
730
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
731
|
+
* ```
|
|
732
|
+
*/
|
|
733
|
+
discardVersion(
|
|
734
|
+
{releaseId, publishedId}: {releaseId?: string; publishedId: string},
|
|
735
|
+
purge?: boolean,
|
|
736
|
+
options?: BaseActionOptions,
|
|
737
|
+
): Observable<SingleActionResult | MultipleActionResult> {
|
|
738
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId)
|
|
739
|
+
|
|
740
|
+
return dataMethods._discardVersion(
|
|
741
|
+
this.config(),
|
|
742
|
+
this.#httpRequest,
|
|
743
|
+
documentVersionId,
|
|
744
|
+
purge,
|
|
745
|
+
options,
|
|
746
|
+
)
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* @public
|
|
751
|
+
*
|
|
752
|
+
* Replaces an existing version document.
|
|
753
|
+
*
|
|
754
|
+
* @remarks
|
|
755
|
+
* * Requires a document with a `_type` property.
|
|
756
|
+
* * 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`.
|
|
757
|
+
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
758
|
+
* * Replacing a version with no `releaseId` will replace the draft version of the published document.
|
|
759
|
+
* * At least one of the **version** or **published** documents must exist.
|
|
760
|
+
*
|
|
761
|
+
* @param params - Version action parameters:
|
|
762
|
+
* - `document` - The new document to replace the version with.
|
|
763
|
+
* - `releaseId` - The ID of the release where the document version is replaced.
|
|
764
|
+
* - `publishedId` - The ID of the published document to replace.
|
|
765
|
+
* @param options - Additional action options.
|
|
766
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
767
|
+
*
|
|
768
|
+
* @example Replacing a release version of a published document with a generated version ID
|
|
769
|
+
* ```ts
|
|
770
|
+
* client.observable.replaceVersion({
|
|
771
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
772
|
+
* publishedId: 'myDocument',
|
|
773
|
+
* releaseId: 'myRelease',
|
|
774
|
+
* })
|
|
775
|
+
*
|
|
776
|
+
* // The following document will be patched:
|
|
777
|
+
* // {
|
|
778
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
779
|
+
* // _type: 'myDocument',
|
|
780
|
+
* // title: 'My Document',
|
|
781
|
+
* // }
|
|
782
|
+
* ```
|
|
783
|
+
*
|
|
784
|
+
* @example Replacing a release version of a published document with a specified version ID
|
|
785
|
+
* ```ts
|
|
786
|
+
* client.observable.replaceVersion({
|
|
787
|
+
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
788
|
+
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
789
|
+
* })
|
|
790
|
+
*
|
|
791
|
+
* // The following document will be patched:
|
|
792
|
+
* // {
|
|
793
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
794
|
+
* // _type: 'myDocument',
|
|
795
|
+
* // title: 'My Document',
|
|
796
|
+
* // }
|
|
797
|
+
* ```
|
|
798
|
+
*
|
|
799
|
+
* @example Replacing a draft version of a published document
|
|
800
|
+
* ```ts
|
|
801
|
+
* client.observable.replaceVersion({
|
|
802
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
803
|
+
* publishedId: 'myDocument',
|
|
804
|
+
* })
|
|
805
|
+
*
|
|
806
|
+
* // The following document will be patched:
|
|
807
|
+
* // {
|
|
808
|
+
* // _id: 'drafts.myDocument',
|
|
809
|
+
* // _type: 'myDocument',
|
|
810
|
+
* // title: 'My Document',
|
|
811
|
+
* // }
|
|
812
|
+
* ```
|
|
813
|
+
*/
|
|
814
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
815
|
+
args: {
|
|
816
|
+
document: SanityDocumentStub<R>
|
|
817
|
+
publishedId: string
|
|
818
|
+
releaseId?: string
|
|
819
|
+
},
|
|
820
|
+
options?: BaseActionOptions,
|
|
821
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
822
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
823
|
+
args: {
|
|
824
|
+
document: IdentifiedSanityDocumentStub<R>
|
|
825
|
+
publishedId?: string
|
|
826
|
+
releaseId?: string
|
|
827
|
+
},
|
|
828
|
+
options?: BaseActionOptions,
|
|
829
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
830
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
831
|
+
{
|
|
832
|
+
document,
|
|
833
|
+
publishedId,
|
|
834
|
+
releaseId,
|
|
835
|
+
}: {
|
|
836
|
+
document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
|
|
837
|
+
publishedId?: string
|
|
838
|
+
releaseId?: string
|
|
839
|
+
},
|
|
840
|
+
options?: BaseActionOptions,
|
|
841
|
+
): Observable<SingleActionResult | MultipleActionResult> {
|
|
842
|
+
const documentVersionId = deriveDocumentVersionId('replaceVersion', {
|
|
843
|
+
document,
|
|
844
|
+
publishedId,
|
|
845
|
+
releaseId,
|
|
846
|
+
})
|
|
847
|
+
|
|
848
|
+
const documentVersion = {...document, _id: documentVersionId}
|
|
849
|
+
|
|
850
|
+
return dataMethods._replaceVersion<R>(
|
|
851
|
+
this.config(),
|
|
852
|
+
this.#httpRequest,
|
|
853
|
+
documentVersion,
|
|
854
|
+
options,
|
|
855
|
+
)
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* @public
|
|
860
|
+
*
|
|
861
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
862
|
+
* the release is run.
|
|
863
|
+
*
|
|
864
|
+
* @remarks
|
|
865
|
+
* * If the published document does not exist, an error will be thrown.
|
|
866
|
+
*
|
|
867
|
+
* @param params - Version action parameters:
|
|
868
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
869
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
870
|
+
* @param options - Additional action options.
|
|
871
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
872
|
+
*
|
|
873
|
+
* @example Unpublishing a release version of a published document
|
|
874
|
+
* ```ts
|
|
875
|
+
* client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
876
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
877
|
+
* ```
|
|
878
|
+
*/
|
|
879
|
+
unpublishVersion(
|
|
880
|
+
{releaseId, publishedId}: {releaseId: string; publishedId: string},
|
|
881
|
+
options?: BaseActionOptions,
|
|
882
|
+
): Observable<SingleActionResult | MultipleActionResult> {
|
|
883
|
+
const versionId = getVersionId(publishedId, releaseId)
|
|
884
|
+
|
|
885
|
+
return dataMethods._unpublishVersion(
|
|
886
|
+
this.config(),
|
|
887
|
+
this.#httpRequest,
|
|
888
|
+
versionId,
|
|
889
|
+
publishedId,
|
|
890
|
+
options,
|
|
891
|
+
)
|
|
892
|
+
}
|
|
893
|
+
|
|
575
894
|
/**
|
|
576
895
|
* Perform mutation operations against the configured dataset
|
|
577
896
|
* Returns an observable that resolves to the first mutated document.
|
|
@@ -743,6 +1062,7 @@ export class SanityClient {
|
|
|
743
1062
|
agent: {
|
|
744
1063
|
action: AgentActionsClient
|
|
745
1064
|
}
|
|
1065
|
+
releases: ReleasesClient
|
|
746
1066
|
|
|
747
1067
|
/**
|
|
748
1068
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
@@ -773,6 +1093,7 @@ export class SanityClient {
|
|
|
773
1093
|
this.agent = {
|
|
774
1094
|
action: new AgentActionsClient(this, this.#httpRequest),
|
|
775
1095
|
}
|
|
1096
|
+
this.releases = new ReleasesClient(this, this.#httpRequest)
|
|
776
1097
|
|
|
777
1098
|
this.observable = new ObservableSanityClient(httpRequest, config)
|
|
778
1099
|
}
|
|
@@ -913,9 +1234,11 @@ export class SanityClient {
|
|
|
913
1234
|
*/
|
|
914
1235
|
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
915
1236
|
id: string,
|
|
916
|
-
options?: {signal?: AbortSignal; tag?: string},
|
|
1237
|
+
options?: {signal?: AbortSignal; tag?: string; releaseId?: string},
|
|
917
1238
|
): Promise<SanityDocument<R> | undefined> {
|
|
918
|
-
return lastValueFrom(
|
|
1239
|
+
return lastValueFrom(
|
|
1240
|
+
dataMethods._getDocument<R>(this.#clientConfig, this.#httpRequest, id, options),
|
|
1241
|
+
)
|
|
919
1242
|
}
|
|
920
1243
|
|
|
921
1244
|
/**
|
|
@@ -931,7 +1254,9 @@ export class SanityClient {
|
|
|
931
1254
|
ids: string[],
|
|
932
1255
|
options?: {signal?: AbortSignal; tag?: string},
|
|
933
1256
|
): Promise<(SanityDocument<R> | null)[]> {
|
|
934
|
-
return lastValueFrom(
|
|
1257
|
+
return lastValueFrom(
|
|
1258
|
+
dataMethods._getDocuments<R>(this.#clientConfig, this.#httpRequest, ids, options),
|
|
1259
|
+
)
|
|
935
1260
|
}
|
|
936
1261
|
|
|
937
1262
|
/**
|
|
@@ -1147,6 +1472,122 @@ export class SanityClient {
|
|
|
1147
1472
|
)
|
|
1148
1473
|
}
|
|
1149
1474
|
|
|
1475
|
+
/**
|
|
1476
|
+
* @public
|
|
1477
|
+
*
|
|
1478
|
+
* Creates a new version of a published document.
|
|
1479
|
+
*
|
|
1480
|
+
* @remarks
|
|
1481
|
+
* * Requires a document with a `_type` property.
|
|
1482
|
+
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
1483
|
+
* * 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`.
|
|
1484
|
+
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
1485
|
+
* * To create a version of an unpublished document, use the `client.create` method.
|
|
1486
|
+
*
|
|
1487
|
+
* @category Versions
|
|
1488
|
+
*
|
|
1489
|
+
* @param params - Version action parameters:
|
|
1490
|
+
* - `document` - The document to create as a new version (must include `_type`).
|
|
1491
|
+
* - `publishedId` - The ID of the published document being versioned.
|
|
1492
|
+
* - `releaseId` - The ID of the release to create the version for.
|
|
1493
|
+
* @param options - Additional action options.
|
|
1494
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1495
|
+
*
|
|
1496
|
+
* @example Creating a new version of a published document with a generated version ID
|
|
1497
|
+
* ```ts
|
|
1498
|
+
* const transactionId = await client.createVersion({
|
|
1499
|
+
* // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
|
|
1500
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
1501
|
+
* publishedId: 'myDocument',
|
|
1502
|
+
* releaseId: 'myRelease',
|
|
1503
|
+
* })
|
|
1504
|
+
*
|
|
1505
|
+
* // The following document will be created:
|
|
1506
|
+
* // {
|
|
1507
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
1508
|
+
* // _type: 'myDocument',
|
|
1509
|
+
* // title: 'My Document',
|
|
1510
|
+
* // }
|
|
1511
|
+
* ```
|
|
1512
|
+
*
|
|
1513
|
+
* @example Creating a new version of a published document with a specified version ID
|
|
1514
|
+
* ```ts
|
|
1515
|
+
* const transactionId = await client.createVersion({
|
|
1516
|
+
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
1517
|
+
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
1518
|
+
* })
|
|
1519
|
+
*
|
|
1520
|
+
* // The following document will be created:
|
|
1521
|
+
* // {
|
|
1522
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
1523
|
+
* // _type: 'myDocument',
|
|
1524
|
+
* // title: 'My Document',
|
|
1525
|
+
* // }
|
|
1526
|
+
* ```
|
|
1527
|
+
*
|
|
1528
|
+
* @example Creating a new draft version of a published document
|
|
1529
|
+
* ```ts
|
|
1530
|
+
* const transactionId = await client.createVersion({
|
|
1531
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
1532
|
+
* publishedId: 'myDocument',
|
|
1533
|
+
* })
|
|
1534
|
+
*
|
|
1535
|
+
* // The following document will be created:
|
|
1536
|
+
* // {
|
|
1537
|
+
* // _id: 'drafts.myDocument',
|
|
1538
|
+
* // _type: 'myDocument',
|
|
1539
|
+
* // title: 'My Document',
|
|
1540
|
+
* // }
|
|
1541
|
+
* ```
|
|
1542
|
+
*/
|
|
1543
|
+
createVersion<R extends Record<string, Any>>(
|
|
1544
|
+
args: {
|
|
1545
|
+
document: SanityDocumentStub<R>
|
|
1546
|
+
publishedId: string
|
|
1547
|
+
releaseId?: string
|
|
1548
|
+
},
|
|
1549
|
+
options?: BaseActionOptions,
|
|
1550
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
1551
|
+
createVersion<R extends Record<string, Any>>(
|
|
1552
|
+
args: {
|
|
1553
|
+
document: IdentifiedSanityDocumentStub<R>
|
|
1554
|
+
publishedId?: string
|
|
1555
|
+
releaseId?: string
|
|
1556
|
+
},
|
|
1557
|
+
options?: BaseActionOptions,
|
|
1558
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
1559
|
+
createVersion<R extends Record<string, Any>>(
|
|
1560
|
+
{
|
|
1561
|
+
document,
|
|
1562
|
+
publishedId,
|
|
1563
|
+
releaseId,
|
|
1564
|
+
}: {
|
|
1565
|
+
document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
|
|
1566
|
+
publishedId?: string
|
|
1567
|
+
releaseId?: string
|
|
1568
|
+
},
|
|
1569
|
+
options?: BaseActionOptions,
|
|
1570
|
+
): Promise<SingleActionResult | MultipleActionResult> {
|
|
1571
|
+
const documentVersionId = deriveDocumentVersionId('createVersion', {
|
|
1572
|
+
document,
|
|
1573
|
+
publishedId,
|
|
1574
|
+
releaseId,
|
|
1575
|
+
})
|
|
1576
|
+
|
|
1577
|
+
const documentVersion = {...document, _id: documentVersionId}
|
|
1578
|
+
const versionPublishedId = publishedId || getPublishedId(document._id)
|
|
1579
|
+
|
|
1580
|
+
return firstValueFrom(
|
|
1581
|
+
dataMethods._createVersion<R>(
|
|
1582
|
+
this.config(),
|
|
1583
|
+
this.#httpRequest,
|
|
1584
|
+
documentVersion,
|
|
1585
|
+
versionPublishedId,
|
|
1586
|
+
options,
|
|
1587
|
+
),
|
|
1588
|
+
)
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1150
1591
|
/**
|
|
1151
1592
|
* Deletes a document with the given document ID.
|
|
1152
1593
|
* Returns a promise that resolves to the deleted document.
|
|
@@ -1262,7 +1703,200 @@ export class SanityClient {
|
|
|
1262
1703
|
): Promise<
|
|
1263
1704
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
1264
1705
|
> {
|
|
1265
|
-
return lastValueFrom(
|
|
1706
|
+
return lastValueFrom(
|
|
1707
|
+
dataMethods._delete<R>(this.#clientConfig, this.#httpRequest, selection, options),
|
|
1708
|
+
)
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
/**
|
|
1712
|
+
* @public
|
|
1713
|
+
*
|
|
1714
|
+
* Deletes the draft or release version of a document.
|
|
1715
|
+
*
|
|
1716
|
+
* @remarks
|
|
1717
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
1718
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
1719
|
+
*
|
|
1720
|
+
* @param params - Version action parameters:
|
|
1721
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
1722
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
1723
|
+
* @param purge - if `true` the document history is also discarded.
|
|
1724
|
+
* @param options - Additional action options.
|
|
1725
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1726
|
+
*
|
|
1727
|
+
* @example Discarding a release version of a document
|
|
1728
|
+
* ```ts
|
|
1729
|
+
* client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1730
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
1731
|
+
* ```
|
|
1732
|
+
*
|
|
1733
|
+
* @example Discarding a draft version of a document
|
|
1734
|
+
* ```ts
|
|
1735
|
+
* client.discardVersion({publishedId: 'myDocument'})
|
|
1736
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
1737
|
+
* ```
|
|
1738
|
+
*/
|
|
1739
|
+
discardVersion(
|
|
1740
|
+
{releaseId, publishedId}: {releaseId?: string; publishedId: string},
|
|
1741
|
+
purge?: boolean,
|
|
1742
|
+
options?: BaseActionOptions,
|
|
1743
|
+
): Promise<SingleActionResult | MultipleActionResult> {
|
|
1744
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId)
|
|
1745
|
+
|
|
1746
|
+
return lastValueFrom(
|
|
1747
|
+
dataMethods._discardVersion(
|
|
1748
|
+
this.config(),
|
|
1749
|
+
this.#httpRequest,
|
|
1750
|
+
documentVersionId,
|
|
1751
|
+
purge,
|
|
1752
|
+
options,
|
|
1753
|
+
),
|
|
1754
|
+
)
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
/**
|
|
1758
|
+
* @public
|
|
1759
|
+
*
|
|
1760
|
+
* Replaces an existing version document.
|
|
1761
|
+
*
|
|
1762
|
+
* @remarks
|
|
1763
|
+
* * Requires a document with a `_type` property.
|
|
1764
|
+
* * 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`.
|
|
1765
|
+
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
1766
|
+
* * Replacing a version with no `releaseId` will replace the draft version of the published document.
|
|
1767
|
+
* * At least one of the **version** or **published** documents must exist.
|
|
1768
|
+
*
|
|
1769
|
+
* @param params - Version action parameters:
|
|
1770
|
+
* - `document` - The new document to replace the version with.
|
|
1771
|
+
* - `releaseId` - The ID of the release where the document version is replaced.
|
|
1772
|
+
* - `publishedId` - The ID of the published document to replace.
|
|
1773
|
+
* @param options - Additional action options.
|
|
1774
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1775
|
+
*
|
|
1776
|
+
* @example Replacing a release version of a published document with a generated version ID
|
|
1777
|
+
* ```ts
|
|
1778
|
+
* await client.replaceVersion({
|
|
1779
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
1780
|
+
* publishedId: 'myDocument',
|
|
1781
|
+
* releaseId: 'myRelease',
|
|
1782
|
+
* })
|
|
1783
|
+
*
|
|
1784
|
+
* // The following document will be patched:
|
|
1785
|
+
* // {
|
|
1786
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
1787
|
+
* // _type: 'myDocument',
|
|
1788
|
+
* // title: 'My Document',
|
|
1789
|
+
* // }
|
|
1790
|
+
* ```
|
|
1791
|
+
*
|
|
1792
|
+
* @example Replacing a release version of a published document with a specified version ID
|
|
1793
|
+
* ```ts
|
|
1794
|
+
* await client.replaceVersion({
|
|
1795
|
+
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
1796
|
+
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
1797
|
+
* })
|
|
1798
|
+
*
|
|
1799
|
+
* // The following document will be patched:
|
|
1800
|
+
* // {
|
|
1801
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
1802
|
+
* // _type: 'myDocument',
|
|
1803
|
+
* // title: 'My Document',
|
|
1804
|
+
* // }
|
|
1805
|
+
* ```
|
|
1806
|
+
*
|
|
1807
|
+
* @example Replacing a draft version of a published document
|
|
1808
|
+
* ```ts
|
|
1809
|
+
* await client.replaceVersion({
|
|
1810
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
1811
|
+
* publishedId: 'myDocument',
|
|
1812
|
+
* })
|
|
1813
|
+
*
|
|
1814
|
+
* // The following document will be patched:
|
|
1815
|
+
* // {
|
|
1816
|
+
* // _id: 'drafts.myDocument',
|
|
1817
|
+
* // _type: 'myDocument',
|
|
1818
|
+
* // title: 'My Document',
|
|
1819
|
+
* // }
|
|
1820
|
+
* ```
|
|
1821
|
+
*/
|
|
1822
|
+
|
|
1823
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
1824
|
+
args: {
|
|
1825
|
+
document: SanityDocumentStub<R>
|
|
1826
|
+
publishedId: string
|
|
1827
|
+
releaseId?: string
|
|
1828
|
+
},
|
|
1829
|
+
options?: BaseActionOptions,
|
|
1830
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
1831
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
1832
|
+
args: {
|
|
1833
|
+
document: IdentifiedSanityDocumentStub<R>
|
|
1834
|
+
publishedId?: string
|
|
1835
|
+
releaseId?: string
|
|
1836
|
+
},
|
|
1837
|
+
options?: BaseActionOptions,
|
|
1838
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
1839
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
1840
|
+
{
|
|
1841
|
+
document,
|
|
1842
|
+
publishedId,
|
|
1843
|
+
releaseId,
|
|
1844
|
+
}: {
|
|
1845
|
+
document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
|
|
1846
|
+
publishedId?: string
|
|
1847
|
+
releaseId?: string
|
|
1848
|
+
},
|
|
1849
|
+
options?: BaseActionOptions,
|
|
1850
|
+
): Promise<SingleActionResult | MultipleActionResult> {
|
|
1851
|
+
const documentVersionId = deriveDocumentVersionId('replaceVersion', {
|
|
1852
|
+
document,
|
|
1853
|
+
publishedId,
|
|
1854
|
+
releaseId,
|
|
1855
|
+
})
|
|
1856
|
+
|
|
1857
|
+
const documentVersion = {...document, _id: documentVersionId}
|
|
1858
|
+
|
|
1859
|
+
return firstValueFrom(
|
|
1860
|
+
dataMethods._replaceVersion<R>(this.config(), this.#httpRequest, documentVersion, options),
|
|
1861
|
+
)
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
/**
|
|
1865
|
+
* @public
|
|
1866
|
+
*
|
|
1867
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
1868
|
+
* the release is run.
|
|
1869
|
+
*
|
|
1870
|
+
* @remarks
|
|
1871
|
+
* * If the published document does not exist, an error will be thrown.
|
|
1872
|
+
*
|
|
1873
|
+
* @param params - Version action parameters:
|
|
1874
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
1875
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
1876
|
+
* @param options - Additional action options.
|
|
1877
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1878
|
+
*
|
|
1879
|
+
* @example Unpublishing a release version of a published document
|
|
1880
|
+
* ```ts
|
|
1881
|
+
* await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1882
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
1883
|
+
* ```
|
|
1884
|
+
*/
|
|
1885
|
+
unpublishVersion(
|
|
1886
|
+
{releaseId, publishedId}: {releaseId: string; publishedId: string},
|
|
1887
|
+
options?: BaseActionOptions,
|
|
1888
|
+
): Promise<SingleActionResult | MultipleActionResult> {
|
|
1889
|
+
const versionId = getVersionId(publishedId, releaseId)
|
|
1890
|
+
|
|
1891
|
+
return lastValueFrom(
|
|
1892
|
+
dataMethods._unpublishVersion(
|
|
1893
|
+
this.config(),
|
|
1894
|
+
this.#httpRequest,
|
|
1895
|
+
versionId,
|
|
1896
|
+
publishedId,
|
|
1897
|
+
options,
|
|
1898
|
+
),
|
|
1899
|
+
)
|
|
1266
1900
|
}
|
|
1267
1901
|
|
|
1268
1902
|
/**
|
|
@@ -1305,7 +1939,7 @@ export class SanityClient {
|
|
|
1305
1939
|
* @param operations - Mutation operations to execute
|
|
1306
1940
|
* @param options - Mutation options
|
|
1307
1941
|
*/
|
|
1308
|
-
mutate<R extends Record<string, Any>>(
|
|
1942
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1309
1943
|
operations: Mutation<R>[] | Patch | Transaction,
|
|
1310
1944
|
options: AllDocumentIdsMutationOptions,
|
|
1311
1945
|
): Promise<MultipleMutationResult>
|
|
@@ -1331,7 +1965,9 @@ export class SanityClient {
|
|
|
1331
1965
|
): Promise<
|
|
1332
1966
|
SanityDocument<R> | SanityDocument<R>[] | SingleMutationResult | MultipleMutationResult
|
|
1333
1967
|
> {
|
|
1334
|
-
return lastValueFrom(
|
|
1968
|
+
return lastValueFrom(
|
|
1969
|
+
dataMethods._mutate<R>(this.#clientConfig, this.#httpRequest, operations, options),
|
|
1970
|
+
)
|
|
1335
1971
|
}
|
|
1336
1972
|
|
|
1337
1973
|
/**
|
|
@@ -1394,7 +2030,9 @@ export class SanityClient {
|
|
|
1394
2030
|
operations: Action | Action[],
|
|
1395
2031
|
options?: BaseActionOptions,
|
|
1396
2032
|
): Promise<SingleActionResult | MultipleActionResult> {
|
|
1397
|
-
return lastValueFrom(
|
|
2033
|
+
return lastValueFrom(
|
|
2034
|
+
dataMethods._action(this.#clientConfig, this.#httpRequest, operations, options),
|
|
2035
|
+
)
|
|
1398
2036
|
}
|
|
1399
2037
|
|
|
1400
2038
|
/**
|
|
@@ -1419,7 +2057,9 @@ export class SanityClient {
|
|
|
1419
2057
|
* @internal
|
|
1420
2058
|
*/
|
|
1421
2059
|
dataRequest(endpoint: string, body: unknown, options?: BaseMutationOptions): Promise<Any> {
|
|
1422
|
-
return lastValueFrom(
|
|
2060
|
+
return lastValueFrom(
|
|
2061
|
+
dataMethods._dataRequest(this.#clientConfig, this.#httpRequest, endpoint, body, options),
|
|
2062
|
+
)
|
|
1423
2063
|
}
|
|
1424
2064
|
|
|
1425
2065
|
/**
|