@sanity/client 7.7.0 → 7.8.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 +6 -1
- package/dist/_chunks-cjs/config.cjs +3 -0
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +3 -0
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +46 -3
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +44 -24
- package/dist/index.browser.d.ts +44 -24
- package/dist/index.browser.js +46 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +45 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -24
- package/dist/index.d.ts +44 -24
- package/dist/index.js +46 -5
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +44 -24
- package/dist/stega.browser.d.ts +44 -24
- package/dist/stega.d.cts +44 -24
- package/dist/stega.d.ts +44 -24
- package/package.json +1 -1
- package/src/SanityClient.ts +61 -21
- package/src/data/dataMethods.ts +39 -2
- package/src/types.ts +19 -5
- package/src/warnings.ts +4 -0
- package/umd/sanityClient.js +46 -3
- package/umd/sanityClient.min.js +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1009,16 +1009,29 @@ export declare interface CreateReleaseAction {
|
|
|
1009
1009
|
}
|
|
1010
1010
|
|
|
1011
1011
|
/**
|
|
1012
|
-
* Creates a new version of an existing document
|
|
1013
|
-
*
|
|
1012
|
+
* Creates a new version of an existing document.
|
|
1013
|
+
*
|
|
1014
|
+
* If the `document` is provided, the version is created from the document
|
|
1015
|
+
* attached to the release as given by `document._id`
|
|
1016
|
+
*
|
|
1017
|
+
* If the `baseId` and `versionId` are provided, the version is created from the base document
|
|
1018
|
+
* and the version is attached to the release as given by `publishedId` and `versionId`
|
|
1014
1019
|
*
|
|
1015
1020
|
* @public
|
|
1016
1021
|
*/
|
|
1017
|
-
export declare
|
|
1022
|
+
export declare type CreateVersionAction = {
|
|
1018
1023
|
actionType: 'sanity.action.document.version.create'
|
|
1019
1024
|
publishedId: string
|
|
1020
|
-
|
|
1021
|
-
|
|
1025
|
+
} & (
|
|
1026
|
+
| {
|
|
1027
|
+
document: IdentifiedSanityDocumentStub
|
|
1028
|
+
}
|
|
1029
|
+
| {
|
|
1030
|
+
baseId: string
|
|
1031
|
+
versionId: string
|
|
1032
|
+
ifBaseRevisionId?: string
|
|
1033
|
+
}
|
|
1034
|
+
)
|
|
1022
1035
|
|
|
1023
1036
|
/** @public */
|
|
1024
1037
|
export declare interface CurrentSanityUser {
|
|
@@ -1027,6 +1040,7 @@ export declare interface CurrentSanityUser {
|
|
|
1027
1040
|
email: string
|
|
1028
1041
|
profileImage: string | null
|
|
1029
1042
|
role: string
|
|
1043
|
+
provider: string
|
|
1030
1044
|
}
|
|
1031
1045
|
|
|
1032
1046
|
/** @public */
|
|
@@ -3123,6 +3137,15 @@ export declare class ObservableSanityClient {
|
|
|
3123
3137
|
},
|
|
3124
3138
|
options?: BaseActionOptions,
|
|
3125
3139
|
): Observable<SingleActionResult | MultipleActionResult>
|
|
3140
|
+
createVersion(
|
|
3141
|
+
args: {
|
|
3142
|
+
baseId: string
|
|
3143
|
+
releaseId: string
|
|
3144
|
+
publishedId: string
|
|
3145
|
+
ifBaseRevisionId?: string
|
|
3146
|
+
},
|
|
3147
|
+
options?: BaseActionOptions,
|
|
3148
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
3126
3149
|
/**
|
|
3127
3150
|
* Deletes a document with the given document ID.
|
|
3128
3151
|
* Returns an observable that resolves to the deleted document.
|
|
@@ -4838,7 +4861,8 @@ export declare class SanityClient {
|
|
|
4838
4861
|
* Creates a new version of a published document.
|
|
4839
4862
|
*
|
|
4840
4863
|
* @remarks
|
|
4841
|
-
* *
|
|
4864
|
+
* * The preferred approach is to use `baseId` to refer to the existing published document, but it is also possible to provide a complete `document` instead.
|
|
4865
|
+
* * If `document` is provided, it must have a `_type` property.
|
|
4842
4866
|
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
4843
4867
|
* * 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`.
|
|
4844
4868
|
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
@@ -4847,17 +4871,18 @@ export declare class SanityClient {
|
|
|
4847
4871
|
* @category Versions
|
|
4848
4872
|
*
|
|
4849
4873
|
* @param params - Version action parameters:
|
|
4874
|
+
* - `baseId` - The ID of the published document from which to create a new version from.
|
|
4875
|
+
* - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
|
|
4850
4876
|
* - `document` - The document to create as a new version (must include `_type`).
|
|
4851
4877
|
* - `publishedId` - The ID of the published document being versioned.
|
|
4852
4878
|
* - `releaseId` - The ID of the release to create the version for.
|
|
4853
4879
|
* @param options - Additional action options.
|
|
4854
4880
|
* @returns A promise that resolves to the `transactionId`.
|
|
4855
4881
|
*
|
|
4856
|
-
* @example Creating a new version of a published document
|
|
4882
|
+
* @example Creating a new version of a published document
|
|
4857
4883
|
* ```ts
|
|
4858
4884
|
* const transactionId = await client.createVersion({
|
|
4859
|
-
*
|
|
4860
|
-
* document: {_type: 'myDocument', title: 'My Document'},
|
|
4885
|
+
* baseId: 'myDocument',
|
|
4861
4886
|
* publishedId: 'myDocument',
|
|
4862
4887
|
* releaseId: 'myRelease',
|
|
4863
4888
|
* })
|
|
@@ -4870,25 +4895,11 @@ export declare class SanityClient {
|
|
|
4870
4895
|
* // }
|
|
4871
4896
|
* ```
|
|
4872
4897
|
*
|
|
4873
|
-
* @example Creating a new version of a published document with a specified version ID
|
|
4874
|
-
* ```ts
|
|
4875
|
-
* const transactionId = await client.createVersion({
|
|
4876
|
-
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
4877
|
-
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
4878
|
-
* })
|
|
4879
|
-
*
|
|
4880
|
-
* // The following document will be created:
|
|
4881
|
-
* // {
|
|
4882
|
-
* // _id: 'versions.myRelease.myDocument',
|
|
4883
|
-
* // _type: 'myDocument',
|
|
4884
|
-
* // title: 'My Document',
|
|
4885
|
-
* // }
|
|
4886
|
-
* ```
|
|
4887
4898
|
*
|
|
4888
4899
|
* @example Creating a new draft version of a published document
|
|
4889
4900
|
* ```ts
|
|
4890
4901
|
* const transactionId = await client.createVersion({
|
|
4891
|
-
*
|
|
4902
|
+
* baseId: 'myDocument',
|
|
4892
4903
|
* publishedId: 'myDocument',
|
|
4893
4904
|
* })
|
|
4894
4905
|
*
|
|
@@ -4916,6 +4927,15 @@ export declare class SanityClient {
|
|
|
4916
4927
|
},
|
|
4917
4928
|
options?: BaseActionOptions,
|
|
4918
4929
|
): Promise<SingleActionResult | MultipleActionResult>
|
|
4930
|
+
createVersion(
|
|
4931
|
+
args: {
|
|
4932
|
+
publishedId: string
|
|
4933
|
+
baseId: string
|
|
4934
|
+
releaseId: string
|
|
4935
|
+
ifBaseRevisionId?: string
|
|
4936
|
+
},
|
|
4937
|
+
options?: BaseActionOptions,
|
|
4938
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
4919
4939
|
/**
|
|
4920
4940
|
* Deletes a document with the given document ID.
|
|
4921
4941
|
* Returns a promise that resolves to the deleted document.
|
package/dist/index.d.ts
CHANGED
|
@@ -1009,16 +1009,29 @@ export declare interface CreateReleaseAction {
|
|
|
1009
1009
|
}
|
|
1010
1010
|
|
|
1011
1011
|
/**
|
|
1012
|
-
* Creates a new version of an existing document
|
|
1013
|
-
*
|
|
1012
|
+
* Creates a new version of an existing document.
|
|
1013
|
+
*
|
|
1014
|
+
* If the `document` is provided, the version is created from the document
|
|
1015
|
+
* attached to the release as given by `document._id`
|
|
1016
|
+
*
|
|
1017
|
+
* If the `baseId` and `versionId` are provided, the version is created from the base document
|
|
1018
|
+
* and the version is attached to the release as given by `publishedId` and `versionId`
|
|
1014
1019
|
*
|
|
1015
1020
|
* @public
|
|
1016
1021
|
*/
|
|
1017
|
-
export declare
|
|
1022
|
+
export declare type CreateVersionAction = {
|
|
1018
1023
|
actionType: 'sanity.action.document.version.create'
|
|
1019
1024
|
publishedId: string
|
|
1020
|
-
|
|
1021
|
-
|
|
1025
|
+
} & (
|
|
1026
|
+
| {
|
|
1027
|
+
document: IdentifiedSanityDocumentStub
|
|
1028
|
+
}
|
|
1029
|
+
| {
|
|
1030
|
+
baseId: string
|
|
1031
|
+
versionId: string
|
|
1032
|
+
ifBaseRevisionId?: string
|
|
1033
|
+
}
|
|
1034
|
+
)
|
|
1022
1035
|
|
|
1023
1036
|
/** @public */
|
|
1024
1037
|
export declare interface CurrentSanityUser {
|
|
@@ -1027,6 +1040,7 @@ export declare interface CurrentSanityUser {
|
|
|
1027
1040
|
email: string
|
|
1028
1041
|
profileImage: string | null
|
|
1029
1042
|
role: string
|
|
1043
|
+
provider: string
|
|
1030
1044
|
}
|
|
1031
1045
|
|
|
1032
1046
|
/** @public */
|
|
@@ -3123,6 +3137,15 @@ export declare class ObservableSanityClient {
|
|
|
3123
3137
|
},
|
|
3124
3138
|
options?: BaseActionOptions,
|
|
3125
3139
|
): Observable<SingleActionResult | MultipleActionResult>
|
|
3140
|
+
createVersion(
|
|
3141
|
+
args: {
|
|
3142
|
+
baseId: string
|
|
3143
|
+
releaseId: string
|
|
3144
|
+
publishedId: string
|
|
3145
|
+
ifBaseRevisionId?: string
|
|
3146
|
+
},
|
|
3147
|
+
options?: BaseActionOptions,
|
|
3148
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
3126
3149
|
/**
|
|
3127
3150
|
* Deletes a document with the given document ID.
|
|
3128
3151
|
* Returns an observable that resolves to the deleted document.
|
|
@@ -4838,7 +4861,8 @@ export declare class SanityClient {
|
|
|
4838
4861
|
* Creates a new version of a published document.
|
|
4839
4862
|
*
|
|
4840
4863
|
* @remarks
|
|
4841
|
-
* *
|
|
4864
|
+
* * The preferred approach is to use `baseId` to refer to the existing published document, but it is also possible to provide a complete `document` instead.
|
|
4865
|
+
* * If `document` is provided, it must have a `_type` property.
|
|
4842
4866
|
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
4843
4867
|
* * 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`.
|
|
4844
4868
|
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
@@ -4847,17 +4871,18 @@ export declare class SanityClient {
|
|
|
4847
4871
|
* @category Versions
|
|
4848
4872
|
*
|
|
4849
4873
|
* @param params - Version action parameters:
|
|
4874
|
+
* - `baseId` - The ID of the published document from which to create a new version from.
|
|
4875
|
+
* - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
|
|
4850
4876
|
* - `document` - The document to create as a new version (must include `_type`).
|
|
4851
4877
|
* - `publishedId` - The ID of the published document being versioned.
|
|
4852
4878
|
* - `releaseId` - The ID of the release to create the version for.
|
|
4853
4879
|
* @param options - Additional action options.
|
|
4854
4880
|
* @returns A promise that resolves to the `transactionId`.
|
|
4855
4881
|
*
|
|
4856
|
-
* @example Creating a new version of a published document
|
|
4882
|
+
* @example Creating a new version of a published document
|
|
4857
4883
|
* ```ts
|
|
4858
4884
|
* const transactionId = await client.createVersion({
|
|
4859
|
-
*
|
|
4860
|
-
* document: {_type: 'myDocument', title: 'My Document'},
|
|
4885
|
+
* baseId: 'myDocument',
|
|
4861
4886
|
* publishedId: 'myDocument',
|
|
4862
4887
|
* releaseId: 'myRelease',
|
|
4863
4888
|
* })
|
|
@@ -4870,25 +4895,11 @@ export declare class SanityClient {
|
|
|
4870
4895
|
* // }
|
|
4871
4896
|
* ```
|
|
4872
4897
|
*
|
|
4873
|
-
* @example Creating a new version of a published document with a specified version ID
|
|
4874
|
-
* ```ts
|
|
4875
|
-
* const transactionId = await client.createVersion({
|
|
4876
|
-
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
4877
|
-
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
4878
|
-
* })
|
|
4879
|
-
*
|
|
4880
|
-
* // The following document will be created:
|
|
4881
|
-
* // {
|
|
4882
|
-
* // _id: 'versions.myRelease.myDocument',
|
|
4883
|
-
* // _type: 'myDocument',
|
|
4884
|
-
* // title: 'My Document',
|
|
4885
|
-
* // }
|
|
4886
|
-
* ```
|
|
4887
4898
|
*
|
|
4888
4899
|
* @example Creating a new draft version of a published document
|
|
4889
4900
|
* ```ts
|
|
4890
4901
|
* const transactionId = await client.createVersion({
|
|
4891
|
-
*
|
|
4902
|
+
* baseId: 'myDocument',
|
|
4892
4903
|
* publishedId: 'myDocument',
|
|
4893
4904
|
* })
|
|
4894
4905
|
*
|
|
@@ -4916,6 +4927,15 @@ export declare class SanityClient {
|
|
|
4916
4927
|
},
|
|
4917
4928
|
options?: BaseActionOptions,
|
|
4918
4929
|
): Promise<SingleActionResult | MultipleActionResult>
|
|
4930
|
+
createVersion(
|
|
4931
|
+
args: {
|
|
4932
|
+
publishedId: string
|
|
4933
|
+
baseId: string
|
|
4934
|
+
releaseId: string
|
|
4935
|
+
ifBaseRevisionId?: string
|
|
4936
|
+
},
|
|
4937
|
+
options?: BaseActionOptions,
|
|
4938
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
4919
4939
|
/**
|
|
4920
4940
|
* Deletes a document with the given document ID.
|
|
4921
4941
|
* Returns a promise that resolves to the deleted document.
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { stegaClean } from "./_chunks-es/stegaClean.js";
|
|
|
7
7
|
import { combineLatestWith, map, filter, finalize as finalize$1 } from "rxjs/operators";
|
|
8
8
|
import { getVersionFromId, isDraftId, getVersionId, getDraftId, isVersionId, getPublishedId } from "@sanity/client/csm";
|
|
9
9
|
import { customAlphabet } from "nanoid";
|
|
10
|
-
import { validateObject, validateInsert, requireDocumentId, validateDocumentId, requireDocumentType, resourceConfig, hasDataset, requestTag, printPreviewDraftsDeprecationWarning, validateApiPerspective, printCdnPreviewDraftsWarning, validateAssetType, resourceGuard, dataset, validateVersionIdMatch, defaultConfig, initConfig, printNoDefaultExport } from "./_chunks-es/config.js";
|
|
10
|
+
import { validateObject, validateInsert, requireDocumentId, validateDocumentId, requireDocumentType, printCreateVersionWithBaseIdWarning, resourceConfig, hasDataset, requestTag, printPreviewDraftsDeprecationWarning, validateApiPerspective, printCdnPreviewDraftsWarning, validateAssetType, resourceGuard, dataset, validateVersionIdMatch, defaultConfig, initConfig, printNoDefaultExport } from "./_chunks-es/config.js";
|
|
11
11
|
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
12
12
|
function codeFrame(query, location2, message) {
|
|
13
13
|
const lines = query.split(NEWLINE), loc = {
|
|
@@ -787,12 +787,27 @@ function _createOrReplace(client, httpRequest, doc, options) {
|
|
|
787
787
|
return requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
788
788
|
}
|
|
789
789
|
function _createVersion(client, httpRequest, doc, publishedId, options) {
|
|
790
|
-
return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), _action(client, httpRequest, {
|
|
790
|
+
return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), printCreateVersionWithBaseIdWarning(), _action(client, httpRequest, {
|
|
791
791
|
actionType: "sanity.action.document.version.create",
|
|
792
792
|
publishedId,
|
|
793
793
|
document: doc
|
|
794
794
|
}, options);
|
|
795
795
|
}
|
|
796
|
+
function _createVersionFromBase(client, httpRequest, publishedId, baseId, releaseId, ifBaseRevisionId, options) {
|
|
797
|
+
if (!baseId)
|
|
798
|
+
throw new Error("`createVersion()` requires `baseId` when no `document` is provided");
|
|
799
|
+
if (!publishedId)
|
|
800
|
+
throw new Error("`createVersion()` requires `publishedId` when `baseId` is provided");
|
|
801
|
+
validateDocumentId("createVersion", baseId), validateDocumentId("createVersion", publishedId);
|
|
802
|
+
const createVersionAction = {
|
|
803
|
+
actionType: "sanity.action.document.version.create",
|
|
804
|
+
publishedId,
|
|
805
|
+
baseId,
|
|
806
|
+
versionId: releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId),
|
|
807
|
+
ifBaseRevisionId
|
|
808
|
+
};
|
|
809
|
+
return _action(client, httpRequest, createVersionAction, options);
|
|
810
|
+
}
|
|
796
811
|
function _delete(client, httpRequest, selection, options) {
|
|
797
812
|
return _dataRequest(
|
|
798
813
|
client,
|
|
@@ -2078,8 +2093,20 @@ class ObservableSanityClient {
|
|
|
2078
2093
|
createVersion({
|
|
2079
2094
|
document,
|
|
2080
2095
|
publishedId,
|
|
2081
|
-
releaseId
|
|
2096
|
+
releaseId,
|
|
2097
|
+
baseId,
|
|
2098
|
+
ifBaseRevisionId
|
|
2082
2099
|
}, options) {
|
|
2100
|
+
if (!document)
|
|
2101
|
+
return _createVersionFromBase(
|
|
2102
|
+
this,
|
|
2103
|
+
this.#httpRequest,
|
|
2104
|
+
publishedId,
|
|
2105
|
+
baseId,
|
|
2106
|
+
releaseId,
|
|
2107
|
+
ifBaseRevisionId,
|
|
2108
|
+
options
|
|
2109
|
+
);
|
|
2083
2110
|
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2084
2111
|
document,
|
|
2085
2112
|
publishedId,
|
|
@@ -2330,8 +2357,22 @@ class SanityClient {
|
|
|
2330
2357
|
createVersion({
|
|
2331
2358
|
document,
|
|
2332
2359
|
publishedId,
|
|
2333
|
-
releaseId
|
|
2360
|
+
releaseId,
|
|
2361
|
+
baseId,
|
|
2362
|
+
ifBaseRevisionId
|
|
2334
2363
|
}, options) {
|
|
2364
|
+
if (!document)
|
|
2365
|
+
return firstValueFrom(
|
|
2366
|
+
_createVersionFromBase(
|
|
2367
|
+
this,
|
|
2368
|
+
this.#httpRequest,
|
|
2369
|
+
publishedId,
|
|
2370
|
+
baseId,
|
|
2371
|
+
releaseId,
|
|
2372
|
+
ifBaseRevisionId,
|
|
2373
|
+
options
|
|
2374
|
+
)
|
|
2375
|
+
);
|
|
2335
2376
|
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2336
2377
|
document,
|
|
2337
2378
|
publishedId,
|
|
@@ -2519,7 +2560,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2519
2560
|
return printNoDefaultExport(), createClient2(config);
|
|
2520
2561
|
};
|
|
2521
2562
|
}
|
|
2522
|
-
var name = "@sanity/client", version = "7.
|
|
2563
|
+
var name = "@sanity/client", version = "7.8.1";
|
|
2523
2564
|
const middleware = [
|
|
2524
2565
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2525
2566
|
headers({ "User-Agent": `${name} ${version}` }),
|