@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "7.1
|
|
3
|
+
"version": "7.2.1",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -121,6 +121,7 @@
|
|
|
121
121
|
"dependencies": {
|
|
122
122
|
"@sanity/eventsource": "^5.0.2",
|
|
123
123
|
"get-it": "^8.6.7",
|
|
124
|
+
"nanoid": "^3.3.11",
|
|
124
125
|
"rxjs": "^7.0.0"
|
|
125
126
|
},
|
|
126
127
|
"devDependencies": {
|
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, this.#httpRequest, id, options)
|
|
232
237
|
}
|
|
@@ -454,6 +459,120 @@ export class ObservableSanityClient {
|
|
|
454
459
|
return dataMethods._createOrReplace<R>(this, this.#httpRequest, document, options)
|
|
455
460
|
}
|
|
456
461
|
|
|
462
|
+
/**
|
|
463
|
+
* @public
|
|
464
|
+
*
|
|
465
|
+
* Creates a new version of a published document.
|
|
466
|
+
*
|
|
467
|
+
* @remarks
|
|
468
|
+
* * Requires a document with a `_type` property.
|
|
469
|
+
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
470
|
+
* * 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`.
|
|
471
|
+
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
472
|
+
* * To create a version of an unpublished document, use the `client.create` method.
|
|
473
|
+
*
|
|
474
|
+
* @category Versions
|
|
475
|
+
*
|
|
476
|
+
* @param params - Version action parameters:
|
|
477
|
+
* - `document` - The document to create as a new version (must include `_type`).
|
|
478
|
+
* - `publishedId` - The ID of the published document being versioned.
|
|
479
|
+
* - `releaseId` - The ID of the release to create the version for.
|
|
480
|
+
* @param options - Additional action options.
|
|
481
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
482
|
+
*
|
|
483
|
+
* @example Creating a new version of a published document with a generated version ID
|
|
484
|
+
* ```ts
|
|
485
|
+
* client.observable.createVersion({
|
|
486
|
+
* // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
|
|
487
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
488
|
+
* publishedId: 'myDocument',
|
|
489
|
+
* releaseId: 'myRelease',
|
|
490
|
+
* })
|
|
491
|
+
*
|
|
492
|
+
* // The following document will be created:
|
|
493
|
+
* // {
|
|
494
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
495
|
+
* // _type: 'myDocument',
|
|
496
|
+
* // title: 'My Document',
|
|
497
|
+
* // }
|
|
498
|
+
* ```
|
|
499
|
+
*
|
|
500
|
+
* @example Creating a new version of a published document with a specified version ID
|
|
501
|
+
* ```ts
|
|
502
|
+
* client.observable.createVersion({
|
|
503
|
+
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
504
|
+
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
505
|
+
* })
|
|
506
|
+
*
|
|
507
|
+
* // The following document will be created:
|
|
508
|
+
* // {
|
|
509
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
510
|
+
* // _type: 'myDocument',
|
|
511
|
+
* // title: 'My Document',
|
|
512
|
+
* // }
|
|
513
|
+
* ```
|
|
514
|
+
*
|
|
515
|
+
* @example Creating a new draft version of a published document
|
|
516
|
+
* ```ts
|
|
517
|
+
* client.observable.createVersion({
|
|
518
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
519
|
+
* publishedId: 'myDocument',
|
|
520
|
+
* })
|
|
521
|
+
*
|
|
522
|
+
* // The following document will be created:
|
|
523
|
+
* // {
|
|
524
|
+
* // _id: 'drafts.myDocument',
|
|
525
|
+
* // _type: 'myDocument',
|
|
526
|
+
* // title: 'My Document',
|
|
527
|
+
* // }
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
createVersion<R extends Record<string, Any>>(
|
|
531
|
+
args: {
|
|
532
|
+
document: SanityDocumentStub<R>
|
|
533
|
+
publishedId: string
|
|
534
|
+
releaseId?: string
|
|
535
|
+
},
|
|
536
|
+
options?: BaseActionOptions,
|
|
537
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
538
|
+
createVersion<R extends Record<string, Any>>(
|
|
539
|
+
args: {
|
|
540
|
+
document: IdentifiedSanityDocumentStub<R>
|
|
541
|
+
publishedId?: string
|
|
542
|
+
releaseId?: string
|
|
543
|
+
},
|
|
544
|
+
options?: BaseActionOptions,
|
|
545
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
546
|
+
createVersion<R extends Record<string, Any>>(
|
|
547
|
+
{
|
|
548
|
+
document,
|
|
549
|
+
publishedId,
|
|
550
|
+
releaseId,
|
|
551
|
+
}: {
|
|
552
|
+
document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
|
|
553
|
+
publishedId?: string
|
|
554
|
+
releaseId?: string
|
|
555
|
+
},
|
|
556
|
+
options?: BaseActionOptions,
|
|
557
|
+
): Observable<SingleActionResult | MultipleActionResult> {
|
|
558
|
+
const documentVersionId = deriveDocumentVersionId('createVersion', {
|
|
559
|
+
document,
|
|
560
|
+
publishedId,
|
|
561
|
+
releaseId,
|
|
562
|
+
})
|
|
563
|
+
|
|
564
|
+
const documentVersion = {...document, _id: documentVersionId}
|
|
565
|
+
const versionPublishedId = publishedId || getPublishedId(document._id)
|
|
566
|
+
|
|
567
|
+
return dataMethods._createVersion<R>(
|
|
568
|
+
this,
|
|
569
|
+
this.#httpRequest,
|
|
570
|
+
documentVersion,
|
|
571
|
+
versionPublishedId,
|
|
572
|
+
options,
|
|
573
|
+
)
|
|
574
|
+
}
|
|
575
|
+
|
|
457
576
|
/**
|
|
458
577
|
* Deletes a document with the given document ID.
|
|
459
578
|
* Returns an observable that resolves to the deleted document.
|
|
@@ -572,6 +691,178 @@ export class ObservableSanityClient {
|
|
|
572
691
|
return dataMethods._delete<R>(this, this.#httpRequest, selection, options)
|
|
573
692
|
}
|
|
574
693
|
|
|
694
|
+
/**
|
|
695
|
+
* @public
|
|
696
|
+
*
|
|
697
|
+
* Deletes the draft or release version of a document.
|
|
698
|
+
*
|
|
699
|
+
* @remarks
|
|
700
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
701
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
702
|
+
*
|
|
703
|
+
* @param params - Version action parameters:
|
|
704
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
705
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
706
|
+
* @param purge - if `true` the document history is also discarded.
|
|
707
|
+
* @param options - Additional action options.
|
|
708
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
709
|
+
*
|
|
710
|
+
* @example Discarding a release version of a document
|
|
711
|
+
* ```ts
|
|
712
|
+
* client.observable.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
713
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
714
|
+
* ```
|
|
715
|
+
*
|
|
716
|
+
* @example Discarding a draft version of a document
|
|
717
|
+
* ```ts
|
|
718
|
+
* client.observable.discardVersion({publishedId: 'myDocument'})
|
|
719
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
720
|
+
* ```
|
|
721
|
+
*/
|
|
722
|
+
discardVersion(
|
|
723
|
+
{releaseId, publishedId}: {releaseId?: string; publishedId: string},
|
|
724
|
+
purge?: boolean,
|
|
725
|
+
options?: BaseActionOptions,
|
|
726
|
+
): Observable<SingleActionResult | MultipleActionResult> {
|
|
727
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId)
|
|
728
|
+
|
|
729
|
+
return dataMethods._discardVersion(this, this.#httpRequest, documentVersionId, purge, options)
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* @public
|
|
734
|
+
*
|
|
735
|
+
* Replaces an existing version document.
|
|
736
|
+
*
|
|
737
|
+
* @remarks
|
|
738
|
+
* * Requires a document with a `_type` property.
|
|
739
|
+
* * 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`.
|
|
740
|
+
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
741
|
+
* * Replacing a version with no `releaseId` will replace the draft version of the published document.
|
|
742
|
+
* * At least one of the **version** or **published** documents must exist.
|
|
743
|
+
*
|
|
744
|
+
* @param params - Version action parameters:
|
|
745
|
+
* - `document` - The new document to replace the version with.
|
|
746
|
+
* - `releaseId` - The ID of the release where the document version is replaced.
|
|
747
|
+
* - `publishedId` - The ID of the published document to replace.
|
|
748
|
+
* @param options - Additional action options.
|
|
749
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
750
|
+
*
|
|
751
|
+
* @example Replacing a release version of a published document with a generated version ID
|
|
752
|
+
* ```ts
|
|
753
|
+
* client.observable.replaceVersion({
|
|
754
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
755
|
+
* publishedId: 'myDocument',
|
|
756
|
+
* releaseId: 'myRelease',
|
|
757
|
+
* })
|
|
758
|
+
*
|
|
759
|
+
* // The following document will be patched:
|
|
760
|
+
* // {
|
|
761
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
762
|
+
* // _type: 'myDocument',
|
|
763
|
+
* // title: 'My Document',
|
|
764
|
+
* // }
|
|
765
|
+
* ```
|
|
766
|
+
*
|
|
767
|
+
* @example Replacing a release version of a published document with a specified version ID
|
|
768
|
+
* ```ts
|
|
769
|
+
* client.observable.replaceVersion({
|
|
770
|
+
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
771
|
+
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
772
|
+
* })
|
|
773
|
+
*
|
|
774
|
+
* // The following document will be patched:
|
|
775
|
+
* // {
|
|
776
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
777
|
+
* // _type: 'myDocument',
|
|
778
|
+
* // title: 'My Document',
|
|
779
|
+
* // }
|
|
780
|
+
* ```
|
|
781
|
+
*
|
|
782
|
+
* @example Replacing a draft version of a published document
|
|
783
|
+
* ```ts
|
|
784
|
+
* client.observable.replaceVersion({
|
|
785
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
786
|
+
* publishedId: 'myDocument',
|
|
787
|
+
* })
|
|
788
|
+
*
|
|
789
|
+
* // The following document will be patched:
|
|
790
|
+
* // {
|
|
791
|
+
* // _id: 'drafts.myDocument',
|
|
792
|
+
* // _type: 'myDocument',
|
|
793
|
+
* // title: 'My Document',
|
|
794
|
+
* // }
|
|
795
|
+
* ```
|
|
796
|
+
*/
|
|
797
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
798
|
+
args: {
|
|
799
|
+
document: SanityDocumentStub<R>
|
|
800
|
+
publishedId: string
|
|
801
|
+
releaseId?: string
|
|
802
|
+
},
|
|
803
|
+
options?: BaseActionOptions,
|
|
804
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
805
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
806
|
+
args: {
|
|
807
|
+
document: IdentifiedSanityDocumentStub<R>
|
|
808
|
+
publishedId?: string
|
|
809
|
+
releaseId?: string
|
|
810
|
+
},
|
|
811
|
+
options?: BaseActionOptions,
|
|
812
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
813
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
814
|
+
{
|
|
815
|
+
document,
|
|
816
|
+
publishedId,
|
|
817
|
+
releaseId,
|
|
818
|
+
}: {
|
|
819
|
+
document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
|
|
820
|
+
publishedId?: string
|
|
821
|
+
releaseId?: string
|
|
822
|
+
},
|
|
823
|
+
options?: BaseActionOptions,
|
|
824
|
+
): Observable<SingleActionResult | MultipleActionResult> {
|
|
825
|
+
const documentVersionId = deriveDocumentVersionId('replaceVersion', {
|
|
826
|
+
document,
|
|
827
|
+
publishedId,
|
|
828
|
+
releaseId,
|
|
829
|
+
})
|
|
830
|
+
|
|
831
|
+
const documentVersion = {...document, _id: documentVersionId}
|
|
832
|
+
|
|
833
|
+
return dataMethods._replaceVersion<R>(this, this.#httpRequest, documentVersion, options)
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* @public
|
|
838
|
+
*
|
|
839
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
840
|
+
* the release is run.
|
|
841
|
+
*
|
|
842
|
+
* @remarks
|
|
843
|
+
* * If the published document does not exist, an error will be thrown.
|
|
844
|
+
*
|
|
845
|
+
* @param params - Version action parameters:
|
|
846
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
847
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
848
|
+
* @param options - Additional action options.
|
|
849
|
+
* @returns an observable that resolves to the `transactionId`.
|
|
850
|
+
*
|
|
851
|
+
* @example Unpublishing a release version of a published document
|
|
852
|
+
* ```ts
|
|
853
|
+
* client.observable.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
854
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
855
|
+
* ```
|
|
856
|
+
*/
|
|
857
|
+
unpublishVersion(
|
|
858
|
+
{releaseId, publishedId}: {releaseId: string; publishedId: string},
|
|
859
|
+
options?: BaseActionOptions,
|
|
860
|
+
): Observable<SingleActionResult | MultipleActionResult> {
|
|
861
|
+
const versionId = getVersionId(publishedId, releaseId)
|
|
862
|
+
|
|
863
|
+
return dataMethods._unpublishVersion(this, this.#httpRequest, versionId, publishedId, options)
|
|
864
|
+
}
|
|
865
|
+
|
|
575
866
|
/**
|
|
576
867
|
* Perform mutation operations against the configured dataset
|
|
577
868
|
* Returns an observable that resolves to the first mutated document.
|
|
@@ -743,6 +1034,7 @@ export class SanityClient {
|
|
|
743
1034
|
agent: {
|
|
744
1035
|
action: AgentActionsClient
|
|
745
1036
|
}
|
|
1037
|
+
releases: ReleasesClient
|
|
746
1038
|
|
|
747
1039
|
/**
|
|
748
1040
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
@@ -773,6 +1065,7 @@ export class SanityClient {
|
|
|
773
1065
|
this.agent = {
|
|
774
1066
|
action: new AgentActionsClient(this, this.#httpRequest),
|
|
775
1067
|
}
|
|
1068
|
+
this.releases = new ReleasesClient(this, this.#httpRequest)
|
|
776
1069
|
|
|
777
1070
|
this.observable = new ObservableSanityClient(httpRequest, config)
|
|
778
1071
|
}
|
|
@@ -913,7 +1206,7 @@ export class SanityClient {
|
|
|
913
1206
|
*/
|
|
914
1207
|
getDocument<R extends Record<string, Any> = Record<string, Any>>(
|
|
915
1208
|
id: string,
|
|
916
|
-
options?: {signal?: AbortSignal; tag?: string},
|
|
1209
|
+
options?: {signal?: AbortSignal; tag?: string; releaseId?: string},
|
|
917
1210
|
): Promise<SanityDocument<R> | undefined> {
|
|
918
1211
|
return lastValueFrom(dataMethods._getDocument<R>(this, this.#httpRequest, id, options))
|
|
919
1212
|
}
|
|
@@ -1147,6 +1440,122 @@ export class SanityClient {
|
|
|
1147
1440
|
)
|
|
1148
1441
|
}
|
|
1149
1442
|
|
|
1443
|
+
/**
|
|
1444
|
+
* @public
|
|
1445
|
+
*
|
|
1446
|
+
* Creates a new version of a published document.
|
|
1447
|
+
*
|
|
1448
|
+
* @remarks
|
|
1449
|
+
* * Requires a document with a `_type` property.
|
|
1450
|
+
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
1451
|
+
* * 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`.
|
|
1452
|
+
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
1453
|
+
* * To create a version of an unpublished document, use the `client.create` method.
|
|
1454
|
+
*
|
|
1455
|
+
* @category Versions
|
|
1456
|
+
*
|
|
1457
|
+
* @param params - Version action parameters:
|
|
1458
|
+
* - `document` - The document to create as a new version (must include `_type`).
|
|
1459
|
+
* - `publishedId` - The ID of the published document being versioned.
|
|
1460
|
+
* - `releaseId` - The ID of the release to create the version for.
|
|
1461
|
+
* @param options - Additional action options.
|
|
1462
|
+
* @returns A promise that resolves to the `transactionId`.
|
|
1463
|
+
*
|
|
1464
|
+
* @example Creating a new version of a published document with a generated version ID
|
|
1465
|
+
* ```ts
|
|
1466
|
+
* const transactionId = await client.createVersion({
|
|
1467
|
+
* // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
|
|
1468
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
1469
|
+
* publishedId: 'myDocument',
|
|
1470
|
+
* releaseId: 'myRelease',
|
|
1471
|
+
* })
|
|
1472
|
+
*
|
|
1473
|
+
* // The following document will be created:
|
|
1474
|
+
* // {
|
|
1475
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
1476
|
+
* // _type: 'myDocument',
|
|
1477
|
+
* // title: 'My Document',
|
|
1478
|
+
* // }
|
|
1479
|
+
* ```
|
|
1480
|
+
*
|
|
1481
|
+
* @example Creating a new version of a published document with a specified version ID
|
|
1482
|
+
* ```ts
|
|
1483
|
+
* const transactionId = await client.createVersion({
|
|
1484
|
+
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
1485
|
+
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
1486
|
+
* })
|
|
1487
|
+
*
|
|
1488
|
+
* // The following document will be created:
|
|
1489
|
+
* // {
|
|
1490
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
1491
|
+
* // _type: 'myDocument',
|
|
1492
|
+
* // title: 'My Document',
|
|
1493
|
+
* // }
|
|
1494
|
+
* ```
|
|
1495
|
+
*
|
|
1496
|
+
* @example Creating a new draft version of a published document
|
|
1497
|
+
* ```ts
|
|
1498
|
+
* const transactionId = await client.createVersion({
|
|
1499
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
1500
|
+
* publishedId: 'myDocument',
|
|
1501
|
+
* })
|
|
1502
|
+
*
|
|
1503
|
+
* // The following document will be created:
|
|
1504
|
+
* // {
|
|
1505
|
+
* // _id: 'drafts.myDocument',
|
|
1506
|
+
* // _type: 'myDocument',
|
|
1507
|
+
* // title: 'My Document',
|
|
1508
|
+
* // }
|
|
1509
|
+
* ```
|
|
1510
|
+
*/
|
|
1511
|
+
createVersion<R extends Record<string, Any>>(
|
|
1512
|
+
args: {
|
|
1513
|
+
document: SanityDocumentStub<R>
|
|
1514
|
+
publishedId: string
|
|
1515
|
+
releaseId?: string
|
|
1516
|
+
},
|
|
1517
|
+
options?: BaseActionOptions,
|
|
1518
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
1519
|
+
createVersion<R extends Record<string, Any>>(
|
|
1520
|
+
args: {
|
|
1521
|
+
document: IdentifiedSanityDocumentStub<R>
|
|
1522
|
+
publishedId?: string
|
|
1523
|
+
releaseId?: string
|
|
1524
|
+
},
|
|
1525
|
+
options?: BaseActionOptions,
|
|
1526
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
1527
|
+
createVersion<R extends Record<string, Any>>(
|
|
1528
|
+
{
|
|
1529
|
+
document,
|
|
1530
|
+
publishedId,
|
|
1531
|
+
releaseId,
|
|
1532
|
+
}: {
|
|
1533
|
+
document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
|
|
1534
|
+
publishedId?: string
|
|
1535
|
+
releaseId?: string
|
|
1536
|
+
},
|
|
1537
|
+
options?: BaseActionOptions,
|
|
1538
|
+
): Promise<SingleActionResult | MultipleActionResult> {
|
|
1539
|
+
const documentVersionId = deriveDocumentVersionId('createVersion', {
|
|
1540
|
+
document,
|
|
1541
|
+
publishedId,
|
|
1542
|
+
releaseId,
|
|
1543
|
+
})
|
|
1544
|
+
|
|
1545
|
+
const documentVersion = {...document, _id: documentVersionId}
|
|
1546
|
+
const versionPublishedId = publishedId || getPublishedId(document._id)
|
|
1547
|
+
|
|
1548
|
+
return firstValueFrom(
|
|
1549
|
+
dataMethods._createVersion<R>(
|
|
1550
|
+
this,
|
|
1551
|
+
this.#httpRequest,
|
|
1552
|
+
documentVersion,
|
|
1553
|
+
versionPublishedId,
|
|
1554
|
+
options,
|
|
1555
|
+
),
|
|
1556
|
+
)
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1150
1559
|
/**
|
|
1151
1560
|
* Deletes a document with the given document ID.
|
|
1152
1561
|
* Returns a promise that resolves to the deleted document.
|
|
@@ -1265,6 +1674,185 @@ export class SanityClient {
|
|
|
1265
1674
|
return lastValueFrom(dataMethods._delete<R>(this, this.#httpRequest, selection, options))
|
|
1266
1675
|
}
|
|
1267
1676
|
|
|
1677
|
+
/**
|
|
1678
|
+
* @public
|
|
1679
|
+
*
|
|
1680
|
+
* Deletes the draft or release version of a document.
|
|
1681
|
+
*
|
|
1682
|
+
* @remarks
|
|
1683
|
+
* * Discarding a version with no `releaseId` will discard the draft version of the published document.
|
|
1684
|
+
* * If the draft or release version does not exist, any error will throw.
|
|
1685
|
+
*
|
|
1686
|
+
* @param params - Version action parameters:
|
|
1687
|
+
* - `releaseId` - The ID of the release to discard the document from.
|
|
1688
|
+
* - `publishedId` - The published ID of the document to discard.
|
|
1689
|
+
* @param purge - if `true` the document history is also discarded.
|
|
1690
|
+
* @param options - Additional action options.
|
|
1691
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1692
|
+
*
|
|
1693
|
+
* @example Discarding a release version of a document
|
|
1694
|
+
* ```ts
|
|
1695
|
+
* client.discardVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1696
|
+
* // The document with the ID `versions.myRelease.myDocument` will be discarded.
|
|
1697
|
+
* ```
|
|
1698
|
+
*
|
|
1699
|
+
* @example Discarding a draft version of a document
|
|
1700
|
+
* ```ts
|
|
1701
|
+
* client.discardVersion({publishedId: 'myDocument'})
|
|
1702
|
+
* // The document with the ID `drafts.myDocument` will be discarded.
|
|
1703
|
+
* ```
|
|
1704
|
+
*/
|
|
1705
|
+
discardVersion(
|
|
1706
|
+
{releaseId, publishedId}: {releaseId?: string; publishedId: string},
|
|
1707
|
+
purge?: boolean,
|
|
1708
|
+
options?: BaseActionOptions,
|
|
1709
|
+
): Promise<SingleActionResult | MultipleActionResult> {
|
|
1710
|
+
const documentVersionId = getDocumentVersionId(publishedId, releaseId)
|
|
1711
|
+
|
|
1712
|
+
return lastValueFrom(
|
|
1713
|
+
dataMethods._discardVersion(this, this.#httpRequest, documentVersionId, purge, options),
|
|
1714
|
+
)
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
/**
|
|
1718
|
+
* @public
|
|
1719
|
+
*
|
|
1720
|
+
* Replaces an existing version document.
|
|
1721
|
+
*
|
|
1722
|
+
* @remarks
|
|
1723
|
+
* * Requires a document with a `_type` property.
|
|
1724
|
+
* * 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`.
|
|
1725
|
+
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
1726
|
+
* * Replacing a version with no `releaseId` will replace the draft version of the published document.
|
|
1727
|
+
* * At least one of the **version** or **published** documents must exist.
|
|
1728
|
+
*
|
|
1729
|
+
* @param params - Version action parameters:
|
|
1730
|
+
* - `document` - The new document to replace the version with.
|
|
1731
|
+
* - `releaseId` - The ID of the release where the document version is replaced.
|
|
1732
|
+
* - `publishedId` - The ID of the published document to replace.
|
|
1733
|
+
* @param options - Additional action options.
|
|
1734
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1735
|
+
*
|
|
1736
|
+
* @example Replacing a release version of a published document with a generated version ID
|
|
1737
|
+
* ```ts
|
|
1738
|
+
* await client.replaceVersion({
|
|
1739
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
1740
|
+
* publishedId: 'myDocument',
|
|
1741
|
+
* releaseId: 'myRelease',
|
|
1742
|
+
* })
|
|
1743
|
+
*
|
|
1744
|
+
* // The following document will be patched:
|
|
1745
|
+
* // {
|
|
1746
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
1747
|
+
* // _type: 'myDocument',
|
|
1748
|
+
* // title: 'My Document',
|
|
1749
|
+
* // }
|
|
1750
|
+
* ```
|
|
1751
|
+
*
|
|
1752
|
+
* @example Replacing a release version of a published document with a specified version ID
|
|
1753
|
+
* ```ts
|
|
1754
|
+
* await client.replaceVersion({
|
|
1755
|
+
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
1756
|
+
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
1757
|
+
* })
|
|
1758
|
+
*
|
|
1759
|
+
* // The following document will be patched:
|
|
1760
|
+
* // {
|
|
1761
|
+
* // _id: 'versions.myRelease.myDocument',
|
|
1762
|
+
* // _type: 'myDocument',
|
|
1763
|
+
* // title: 'My Document',
|
|
1764
|
+
* // }
|
|
1765
|
+
* ```
|
|
1766
|
+
*
|
|
1767
|
+
* @example Replacing a draft version of a published document
|
|
1768
|
+
* ```ts
|
|
1769
|
+
* await client.replaceVersion({
|
|
1770
|
+
* document: {_type: 'myDocument', title: 'My Document'},
|
|
1771
|
+
* publishedId: 'myDocument',
|
|
1772
|
+
* })
|
|
1773
|
+
*
|
|
1774
|
+
* // The following document will be patched:
|
|
1775
|
+
* // {
|
|
1776
|
+
* // _id: 'drafts.myDocument',
|
|
1777
|
+
* // _type: 'myDocument',
|
|
1778
|
+
* // title: 'My Document',
|
|
1779
|
+
* // }
|
|
1780
|
+
* ```
|
|
1781
|
+
*/
|
|
1782
|
+
|
|
1783
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
1784
|
+
args: {
|
|
1785
|
+
document: SanityDocumentStub<R>
|
|
1786
|
+
publishedId: string
|
|
1787
|
+
releaseId?: string
|
|
1788
|
+
},
|
|
1789
|
+
options?: BaseActionOptions,
|
|
1790
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
1791
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
1792
|
+
args: {
|
|
1793
|
+
document: IdentifiedSanityDocumentStub<R>
|
|
1794
|
+
publishedId?: string
|
|
1795
|
+
releaseId?: string
|
|
1796
|
+
},
|
|
1797
|
+
options?: BaseActionOptions,
|
|
1798
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
1799
|
+
replaceVersion<R extends Record<string, Any>>(
|
|
1800
|
+
{
|
|
1801
|
+
document,
|
|
1802
|
+
publishedId,
|
|
1803
|
+
releaseId,
|
|
1804
|
+
}: {
|
|
1805
|
+
document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
|
|
1806
|
+
publishedId?: string
|
|
1807
|
+
releaseId?: string
|
|
1808
|
+
},
|
|
1809
|
+
options?: BaseActionOptions,
|
|
1810
|
+
): Promise<SingleActionResult | MultipleActionResult> {
|
|
1811
|
+
const documentVersionId = deriveDocumentVersionId('replaceVersion', {
|
|
1812
|
+
document,
|
|
1813
|
+
publishedId,
|
|
1814
|
+
releaseId,
|
|
1815
|
+
})
|
|
1816
|
+
|
|
1817
|
+
const documentVersion = {...document, _id: documentVersionId}
|
|
1818
|
+
|
|
1819
|
+
return firstValueFrom(
|
|
1820
|
+
dataMethods._replaceVersion<R>(this, this.#httpRequest, documentVersion, options),
|
|
1821
|
+
)
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
/**
|
|
1825
|
+
* @public
|
|
1826
|
+
*
|
|
1827
|
+
* Used to indicate when a document within a release should be unpublished when
|
|
1828
|
+
* the release is run.
|
|
1829
|
+
*
|
|
1830
|
+
* @remarks
|
|
1831
|
+
* * If the published document does not exist, an error will be thrown.
|
|
1832
|
+
*
|
|
1833
|
+
* @param params - Version action parameters:
|
|
1834
|
+
* - `releaseId` - The ID of the release to unpublish the document from.
|
|
1835
|
+
* - `publishedId` - The published ID of the document to unpublish.
|
|
1836
|
+
* @param options - Additional action options.
|
|
1837
|
+
* @returns a promise that resolves to the `transactionId`.
|
|
1838
|
+
*
|
|
1839
|
+
* @example Unpublishing a release version of a published document
|
|
1840
|
+
* ```ts
|
|
1841
|
+
* await client.unpublishVersion({publishedId: 'myDocument', releaseId: 'myRelease'})
|
|
1842
|
+
* // The document with the ID `versions.myRelease.myDocument` will be unpublished. when `myRelease` is run.
|
|
1843
|
+
* ```
|
|
1844
|
+
*/
|
|
1845
|
+
unpublishVersion(
|
|
1846
|
+
{releaseId, publishedId}: {releaseId: string; publishedId: string},
|
|
1847
|
+
options?: BaseActionOptions,
|
|
1848
|
+
): Promise<SingleActionResult | MultipleActionResult> {
|
|
1849
|
+
const versionId = getVersionId(publishedId, releaseId)
|
|
1850
|
+
|
|
1851
|
+
return lastValueFrom(
|
|
1852
|
+
dataMethods._unpublishVersion(this, this.#httpRequest, versionId, publishedId, options),
|
|
1853
|
+
)
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1268
1856
|
/**
|
|
1269
1857
|
* Perform mutation operations against the configured dataset
|
|
1270
1858
|
* Returns a promise that resolves to the first mutated document.
|
|
@@ -1305,7 +1893,7 @@ export class SanityClient {
|
|
|
1305
1893
|
* @param operations - Mutation operations to execute
|
|
1306
1894
|
* @param options - Mutation options
|
|
1307
1895
|
*/
|
|
1308
|
-
mutate<R extends Record<string, Any>>(
|
|
1896
|
+
mutate<R extends Record<string, Any> = Record<string, Any>>(
|
|
1309
1897
|
operations: Mutation<R>[] | Patch | Transaction,
|
|
1310
1898
|
options: AllDocumentIdsMutationOptions,
|
|
1311
1899
|
): Promise<MultipleMutationResult>
|