@sanity/client 7.7.0 → 7.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +43 -24
- package/dist/index.browser.d.ts +43 -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 +43 -24
- package/dist/index.d.ts +43 -24
- package/dist/index.js +46 -5
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +43 -24
- package/dist/stega.browser.d.ts +43 -24
- package/dist/stega.d.cts +43 -24
- package/dist/stega.d.ts +43 -24
- package/package.json +1 -1
- package/src/SanityClient.ts +61 -21
- package/src/data/dataMethods.ts +39 -2
- package/src/types.ts +18 -5
- package/src/warnings.ts +4 -0
- package/umd/sanityClient.js +46 -3
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.d.cts
CHANGED
|
@@ -1005,16 +1005,29 @@ export declare interface CreateReleaseAction {
|
|
|
1005
1005
|
}
|
|
1006
1006
|
|
|
1007
1007
|
/**
|
|
1008
|
-
* Creates a new version of an existing document
|
|
1009
|
-
*
|
|
1008
|
+
* Creates a new version of an existing document.
|
|
1009
|
+
*
|
|
1010
|
+
* If the `document` is provided, the version is created from the document
|
|
1011
|
+
* attached to the release as given by `document._id`
|
|
1012
|
+
*
|
|
1013
|
+
* If the `baseId` and `versionId` are provided, the version is created from the base document
|
|
1014
|
+
* and the version is attached to the release as given by `publishedId` and `versionId`
|
|
1010
1015
|
*
|
|
1011
1016
|
* @public
|
|
1012
1017
|
*/
|
|
1013
|
-
export declare
|
|
1018
|
+
export declare type CreateVersionAction = {
|
|
1014
1019
|
actionType: 'sanity.action.document.version.create'
|
|
1015
1020
|
publishedId: string
|
|
1016
|
-
|
|
1017
|
-
|
|
1021
|
+
} & (
|
|
1022
|
+
| {
|
|
1023
|
+
document: IdentifiedSanityDocumentStub
|
|
1024
|
+
}
|
|
1025
|
+
| {
|
|
1026
|
+
baseId: string
|
|
1027
|
+
versionId: string
|
|
1028
|
+
ifBaseRevisionId?: string
|
|
1029
|
+
}
|
|
1030
|
+
)
|
|
1018
1031
|
|
|
1019
1032
|
/** @public */
|
|
1020
1033
|
export declare interface CurrentSanityUser {
|
|
@@ -3119,6 +3132,15 @@ export declare class ObservableSanityClient {
|
|
|
3119
3132
|
},
|
|
3120
3133
|
options?: BaseActionOptions,
|
|
3121
3134
|
): Observable<SingleActionResult | MultipleActionResult>
|
|
3135
|
+
createVersion(
|
|
3136
|
+
args: {
|
|
3137
|
+
baseId: string
|
|
3138
|
+
releaseId: string
|
|
3139
|
+
publishedId: string
|
|
3140
|
+
ifBaseRevisionId?: string
|
|
3141
|
+
},
|
|
3142
|
+
options?: BaseActionOptions,
|
|
3143
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
3122
3144
|
/**
|
|
3123
3145
|
* Deletes a document with the given document ID.
|
|
3124
3146
|
* Returns an observable that resolves to the deleted document.
|
|
@@ -4834,7 +4856,8 @@ export declare class SanityClient {
|
|
|
4834
4856
|
* Creates a new version of a published document.
|
|
4835
4857
|
*
|
|
4836
4858
|
* @remarks
|
|
4837
|
-
* *
|
|
4859
|
+
* * 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.
|
|
4860
|
+
* * If `document` is provided, it must have a `_type` property.
|
|
4838
4861
|
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
4839
4862
|
* * 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`.
|
|
4840
4863
|
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
@@ -4843,17 +4866,18 @@ export declare class SanityClient {
|
|
|
4843
4866
|
* @category Versions
|
|
4844
4867
|
*
|
|
4845
4868
|
* @param params - Version action parameters:
|
|
4869
|
+
* - `baseId` - The ID of the published document from which to create a new version from.
|
|
4870
|
+
* - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
|
|
4846
4871
|
* - `document` - The document to create as a new version (must include `_type`).
|
|
4847
4872
|
* - `publishedId` - The ID of the published document being versioned.
|
|
4848
4873
|
* - `releaseId` - The ID of the release to create the version for.
|
|
4849
4874
|
* @param options - Additional action options.
|
|
4850
4875
|
* @returns A promise that resolves to the `transactionId`.
|
|
4851
4876
|
*
|
|
4852
|
-
* @example Creating a new version of a published document
|
|
4877
|
+
* @example Creating a new version of a published document
|
|
4853
4878
|
* ```ts
|
|
4854
4879
|
* const transactionId = await client.createVersion({
|
|
4855
|
-
*
|
|
4856
|
-
* document: {_type: 'myDocument', title: 'My Document'},
|
|
4880
|
+
* baseId: 'myDocument',
|
|
4857
4881
|
* publishedId: 'myDocument',
|
|
4858
4882
|
* releaseId: 'myRelease',
|
|
4859
4883
|
* })
|
|
@@ -4866,25 +4890,11 @@ export declare class SanityClient {
|
|
|
4866
4890
|
* // }
|
|
4867
4891
|
* ```
|
|
4868
4892
|
*
|
|
4869
|
-
* @example Creating a new version of a published document with a specified version ID
|
|
4870
|
-
* ```ts
|
|
4871
|
-
* const transactionId = await client.createVersion({
|
|
4872
|
-
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
4873
|
-
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
4874
|
-
* })
|
|
4875
|
-
*
|
|
4876
|
-
* // The following document will be created:
|
|
4877
|
-
* // {
|
|
4878
|
-
* // _id: 'versions.myRelease.myDocument',
|
|
4879
|
-
* // _type: 'myDocument',
|
|
4880
|
-
* // title: 'My Document',
|
|
4881
|
-
* // }
|
|
4882
|
-
* ```
|
|
4883
4893
|
*
|
|
4884
4894
|
* @example Creating a new draft version of a published document
|
|
4885
4895
|
* ```ts
|
|
4886
4896
|
* const transactionId = await client.createVersion({
|
|
4887
|
-
*
|
|
4897
|
+
* baseId: 'myDocument',
|
|
4888
4898
|
* publishedId: 'myDocument',
|
|
4889
4899
|
* })
|
|
4890
4900
|
*
|
|
@@ -4912,6 +4922,15 @@ export declare class SanityClient {
|
|
|
4912
4922
|
},
|
|
4913
4923
|
options?: BaseActionOptions,
|
|
4914
4924
|
): Promise<SingleActionResult | MultipleActionResult>
|
|
4925
|
+
createVersion(
|
|
4926
|
+
args: {
|
|
4927
|
+
publishedId: string
|
|
4928
|
+
baseId: string
|
|
4929
|
+
releaseId: string
|
|
4930
|
+
ifBaseRevisionId?: string
|
|
4931
|
+
},
|
|
4932
|
+
options?: BaseActionOptions,
|
|
4933
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
4915
4934
|
/**
|
|
4916
4935
|
* Deletes a document with the given document ID.
|
|
4917
4936
|
* Returns a promise that resolves to the deleted document.
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1005,16 +1005,29 @@ export declare interface CreateReleaseAction {
|
|
|
1005
1005
|
}
|
|
1006
1006
|
|
|
1007
1007
|
/**
|
|
1008
|
-
* Creates a new version of an existing document
|
|
1009
|
-
*
|
|
1008
|
+
* Creates a new version of an existing document.
|
|
1009
|
+
*
|
|
1010
|
+
* If the `document` is provided, the version is created from the document
|
|
1011
|
+
* attached to the release as given by `document._id`
|
|
1012
|
+
*
|
|
1013
|
+
* If the `baseId` and `versionId` are provided, the version is created from the base document
|
|
1014
|
+
* and the version is attached to the release as given by `publishedId` and `versionId`
|
|
1010
1015
|
*
|
|
1011
1016
|
* @public
|
|
1012
1017
|
*/
|
|
1013
|
-
export declare
|
|
1018
|
+
export declare type CreateVersionAction = {
|
|
1014
1019
|
actionType: 'sanity.action.document.version.create'
|
|
1015
1020
|
publishedId: string
|
|
1016
|
-
|
|
1017
|
-
|
|
1021
|
+
} & (
|
|
1022
|
+
| {
|
|
1023
|
+
document: IdentifiedSanityDocumentStub
|
|
1024
|
+
}
|
|
1025
|
+
| {
|
|
1026
|
+
baseId: string
|
|
1027
|
+
versionId: string
|
|
1028
|
+
ifBaseRevisionId?: string
|
|
1029
|
+
}
|
|
1030
|
+
)
|
|
1018
1031
|
|
|
1019
1032
|
/** @public */
|
|
1020
1033
|
export declare interface CurrentSanityUser {
|
|
@@ -3119,6 +3132,15 @@ export declare class ObservableSanityClient {
|
|
|
3119
3132
|
},
|
|
3120
3133
|
options?: BaseActionOptions,
|
|
3121
3134
|
): Observable<SingleActionResult | MultipleActionResult>
|
|
3135
|
+
createVersion(
|
|
3136
|
+
args: {
|
|
3137
|
+
baseId: string
|
|
3138
|
+
releaseId: string
|
|
3139
|
+
publishedId: string
|
|
3140
|
+
ifBaseRevisionId?: string
|
|
3141
|
+
},
|
|
3142
|
+
options?: BaseActionOptions,
|
|
3143
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
3122
3144
|
/**
|
|
3123
3145
|
* Deletes a document with the given document ID.
|
|
3124
3146
|
* Returns an observable that resolves to the deleted document.
|
|
@@ -4834,7 +4856,8 @@ export declare class SanityClient {
|
|
|
4834
4856
|
* Creates a new version of a published document.
|
|
4835
4857
|
*
|
|
4836
4858
|
* @remarks
|
|
4837
|
-
* *
|
|
4859
|
+
* * 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.
|
|
4860
|
+
* * If `document` is provided, it must have a `_type` property.
|
|
4838
4861
|
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
4839
4862
|
* * 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`.
|
|
4840
4863
|
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
@@ -4843,17 +4866,18 @@ export declare class SanityClient {
|
|
|
4843
4866
|
* @category Versions
|
|
4844
4867
|
*
|
|
4845
4868
|
* @param params - Version action parameters:
|
|
4869
|
+
* - `baseId` - The ID of the published document from which to create a new version from.
|
|
4870
|
+
* - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
|
|
4846
4871
|
* - `document` - The document to create as a new version (must include `_type`).
|
|
4847
4872
|
* - `publishedId` - The ID of the published document being versioned.
|
|
4848
4873
|
* - `releaseId` - The ID of the release to create the version for.
|
|
4849
4874
|
* @param options - Additional action options.
|
|
4850
4875
|
* @returns A promise that resolves to the `transactionId`.
|
|
4851
4876
|
*
|
|
4852
|
-
* @example Creating a new version of a published document
|
|
4877
|
+
* @example Creating a new version of a published document
|
|
4853
4878
|
* ```ts
|
|
4854
4879
|
* const transactionId = await client.createVersion({
|
|
4855
|
-
*
|
|
4856
|
-
* document: {_type: 'myDocument', title: 'My Document'},
|
|
4880
|
+
* baseId: 'myDocument',
|
|
4857
4881
|
* publishedId: 'myDocument',
|
|
4858
4882
|
* releaseId: 'myRelease',
|
|
4859
4883
|
* })
|
|
@@ -4866,25 +4890,11 @@ export declare class SanityClient {
|
|
|
4866
4890
|
* // }
|
|
4867
4891
|
* ```
|
|
4868
4892
|
*
|
|
4869
|
-
* @example Creating a new version of a published document with a specified version ID
|
|
4870
|
-
* ```ts
|
|
4871
|
-
* const transactionId = await client.createVersion({
|
|
4872
|
-
* document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
|
|
4873
|
-
* // `publishedId` and `releaseId` are not required since `document._id` has been specified
|
|
4874
|
-
* })
|
|
4875
|
-
*
|
|
4876
|
-
* // The following document will be created:
|
|
4877
|
-
* // {
|
|
4878
|
-
* // _id: 'versions.myRelease.myDocument',
|
|
4879
|
-
* // _type: 'myDocument',
|
|
4880
|
-
* // title: 'My Document',
|
|
4881
|
-
* // }
|
|
4882
|
-
* ```
|
|
4883
4893
|
*
|
|
4884
4894
|
* @example Creating a new draft version of a published document
|
|
4885
4895
|
* ```ts
|
|
4886
4896
|
* const transactionId = await client.createVersion({
|
|
4887
|
-
*
|
|
4897
|
+
* baseId: 'myDocument',
|
|
4888
4898
|
* publishedId: 'myDocument',
|
|
4889
4899
|
* })
|
|
4890
4900
|
*
|
|
@@ -4912,6 +4922,15 @@ export declare class SanityClient {
|
|
|
4912
4922
|
},
|
|
4913
4923
|
options?: BaseActionOptions,
|
|
4914
4924
|
): Promise<SingleActionResult | MultipleActionResult>
|
|
4925
|
+
createVersion(
|
|
4926
|
+
args: {
|
|
4927
|
+
publishedId: string
|
|
4928
|
+
baseId: string
|
|
4929
|
+
releaseId: string
|
|
4930
|
+
ifBaseRevisionId?: string
|
|
4931
|
+
},
|
|
4932
|
+
options?: BaseActionOptions,
|
|
4933
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
4915
4934
|
/**
|
|
4916
4935
|
* Deletes a document with the given document ID.
|
|
4917
4936
|
* Returns a promise that resolves to the deleted document.
|
package/dist/index.browser.js
CHANGED
|
@@ -319,6 +319,8 @@ const createWarningPrinter = (message) => (
|
|
|
319
319
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
320
320
|
]), printNoDefaultExport = createWarningPrinter([
|
|
321
321
|
"The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."
|
|
322
|
+
]), printCreateVersionWithBaseIdWarning = createWarningPrinter([
|
|
323
|
+
"You have called `createVersion()` with a defined `document`. The recommended approach is to provide a `baseId` and `releaseId` instead."
|
|
322
324
|
]), defaultCdnHost = "apicdn.sanity.io", defaultConfig = {
|
|
323
325
|
apiHost: "https://api.sanity.io",
|
|
324
326
|
apiVersion: "1",
|
|
@@ -954,12 +956,27 @@ function _createOrReplace(client, httpRequest, doc, options) {
|
|
|
954
956
|
return requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
955
957
|
}
|
|
956
958
|
function _createVersion(client, httpRequest, doc, publishedId, options) {
|
|
957
|
-
return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), _action(client, httpRequest, {
|
|
959
|
+
return requireDocumentId("createVersion", doc), requireDocumentType("createVersion", doc), printCreateVersionWithBaseIdWarning(), _action(client, httpRequest, {
|
|
958
960
|
actionType: "sanity.action.document.version.create",
|
|
959
961
|
publishedId,
|
|
960
962
|
document: doc
|
|
961
963
|
}, options);
|
|
962
964
|
}
|
|
965
|
+
function _createVersionFromBase(client, httpRequest, publishedId, baseId, releaseId, ifBaseRevisionId, options) {
|
|
966
|
+
if (!baseId)
|
|
967
|
+
throw new Error("`createVersion()` requires `baseId` when no `document` is provided");
|
|
968
|
+
if (!publishedId)
|
|
969
|
+
throw new Error("`createVersion()` requires `publishedId` when `baseId` is provided");
|
|
970
|
+
validateDocumentId("createVersion", baseId), validateDocumentId("createVersion", publishedId);
|
|
971
|
+
const createVersionAction = {
|
|
972
|
+
actionType: "sanity.action.document.version.create",
|
|
973
|
+
publishedId,
|
|
974
|
+
baseId,
|
|
975
|
+
versionId: releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId),
|
|
976
|
+
ifBaseRevisionId
|
|
977
|
+
};
|
|
978
|
+
return _action(client, httpRequest, createVersionAction, options);
|
|
979
|
+
}
|
|
963
980
|
function _delete(client, httpRequest, selection, options) {
|
|
964
981
|
return _dataRequest(
|
|
965
982
|
client,
|
|
@@ -2245,8 +2262,20 @@ class ObservableSanityClient {
|
|
|
2245
2262
|
createVersion({
|
|
2246
2263
|
document,
|
|
2247
2264
|
publishedId,
|
|
2248
|
-
releaseId
|
|
2265
|
+
releaseId,
|
|
2266
|
+
baseId,
|
|
2267
|
+
ifBaseRevisionId
|
|
2249
2268
|
}, options) {
|
|
2269
|
+
if (!document)
|
|
2270
|
+
return _createVersionFromBase(
|
|
2271
|
+
this,
|
|
2272
|
+
this.#httpRequest,
|
|
2273
|
+
publishedId,
|
|
2274
|
+
baseId,
|
|
2275
|
+
releaseId,
|
|
2276
|
+
ifBaseRevisionId,
|
|
2277
|
+
options
|
|
2278
|
+
);
|
|
2250
2279
|
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2251
2280
|
document,
|
|
2252
2281
|
publishedId,
|
|
@@ -2497,8 +2526,22 @@ class SanityClient {
|
|
|
2497
2526
|
createVersion({
|
|
2498
2527
|
document,
|
|
2499
2528
|
publishedId,
|
|
2500
|
-
releaseId
|
|
2529
|
+
releaseId,
|
|
2530
|
+
baseId,
|
|
2531
|
+
ifBaseRevisionId
|
|
2501
2532
|
}, options) {
|
|
2533
|
+
if (!document)
|
|
2534
|
+
return firstValueFrom(
|
|
2535
|
+
_createVersionFromBase(
|
|
2536
|
+
this,
|
|
2537
|
+
this.#httpRequest,
|
|
2538
|
+
publishedId,
|
|
2539
|
+
baseId,
|
|
2540
|
+
releaseId,
|
|
2541
|
+
ifBaseRevisionId,
|
|
2542
|
+
options
|
|
2543
|
+
)
|
|
2544
|
+
);
|
|
2502
2545
|
const documentVersionId = deriveDocumentVersionId("createVersion", {
|
|
2503
2546
|
document,
|
|
2504
2547
|
publishedId,
|