@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.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 {
|
|
@@ -3123,6 +3136,15 @@ export declare class ObservableSanityClient {
|
|
|
3123
3136
|
},
|
|
3124
3137
|
options?: BaseActionOptions,
|
|
3125
3138
|
): Observable<SingleActionResult | MultipleActionResult>
|
|
3139
|
+
createVersion(
|
|
3140
|
+
args: {
|
|
3141
|
+
baseId: string
|
|
3142
|
+
releaseId: string
|
|
3143
|
+
publishedId: string
|
|
3144
|
+
ifBaseRevisionId?: string
|
|
3145
|
+
},
|
|
3146
|
+
options?: BaseActionOptions,
|
|
3147
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
3126
3148
|
/**
|
|
3127
3149
|
* Deletes a document with the given document ID.
|
|
3128
3150
|
* Returns an observable that resolves to the deleted document.
|
|
@@ -4838,7 +4860,8 @@ export declare class SanityClient {
|
|
|
4838
4860
|
* Creates a new version of a published document.
|
|
4839
4861
|
*
|
|
4840
4862
|
* @remarks
|
|
4841
|
-
* *
|
|
4863
|
+
* * 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.
|
|
4864
|
+
* * If `document` is provided, it must have a `_type` property.
|
|
4842
4865
|
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
4843
4866
|
* * 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
4867
|
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
@@ -4847,17 +4870,18 @@ export declare class SanityClient {
|
|
|
4847
4870
|
* @category Versions
|
|
4848
4871
|
*
|
|
4849
4872
|
* @param params - Version action parameters:
|
|
4873
|
+
* - `baseId` - The ID of the published document from which to create a new version from.
|
|
4874
|
+
* - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
|
|
4850
4875
|
* - `document` - The document to create as a new version (must include `_type`).
|
|
4851
4876
|
* - `publishedId` - The ID of the published document being versioned.
|
|
4852
4877
|
* - `releaseId` - The ID of the release to create the version for.
|
|
4853
4878
|
* @param options - Additional action options.
|
|
4854
4879
|
* @returns A promise that resolves to the `transactionId`.
|
|
4855
4880
|
*
|
|
4856
|
-
* @example Creating a new version of a published document
|
|
4881
|
+
* @example Creating a new version of a published document
|
|
4857
4882
|
* ```ts
|
|
4858
4883
|
* const transactionId = await client.createVersion({
|
|
4859
|
-
*
|
|
4860
|
-
* document: {_type: 'myDocument', title: 'My Document'},
|
|
4884
|
+
* baseId: 'myDocument',
|
|
4861
4885
|
* publishedId: 'myDocument',
|
|
4862
4886
|
* releaseId: 'myRelease',
|
|
4863
4887
|
* })
|
|
@@ -4870,25 +4894,11 @@ export declare class SanityClient {
|
|
|
4870
4894
|
* // }
|
|
4871
4895
|
* ```
|
|
4872
4896
|
*
|
|
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
4897
|
*
|
|
4888
4898
|
* @example Creating a new draft version of a published document
|
|
4889
4899
|
* ```ts
|
|
4890
4900
|
* const transactionId = await client.createVersion({
|
|
4891
|
-
*
|
|
4901
|
+
* baseId: 'myDocument',
|
|
4892
4902
|
* publishedId: 'myDocument',
|
|
4893
4903
|
* })
|
|
4894
4904
|
*
|
|
@@ -4916,6 +4926,15 @@ export declare class SanityClient {
|
|
|
4916
4926
|
},
|
|
4917
4927
|
options?: BaseActionOptions,
|
|
4918
4928
|
): Promise<SingleActionResult | MultipleActionResult>
|
|
4929
|
+
createVersion(
|
|
4930
|
+
args: {
|
|
4931
|
+
publishedId: string
|
|
4932
|
+
baseId: string
|
|
4933
|
+
releaseId: string
|
|
4934
|
+
ifBaseRevisionId?: string
|
|
4935
|
+
},
|
|
4936
|
+
options?: BaseActionOptions,
|
|
4937
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
4919
4938
|
/**
|
|
4920
4939
|
* Deletes a document with the given document ID.
|
|
4921
4940
|
* 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 {
|
|
@@ -3123,6 +3136,15 @@ export declare class ObservableSanityClient {
|
|
|
3123
3136
|
},
|
|
3124
3137
|
options?: BaseActionOptions,
|
|
3125
3138
|
): Observable<SingleActionResult | MultipleActionResult>
|
|
3139
|
+
createVersion(
|
|
3140
|
+
args: {
|
|
3141
|
+
baseId: string
|
|
3142
|
+
releaseId: string
|
|
3143
|
+
publishedId: string
|
|
3144
|
+
ifBaseRevisionId?: string
|
|
3145
|
+
},
|
|
3146
|
+
options?: BaseActionOptions,
|
|
3147
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
3126
3148
|
/**
|
|
3127
3149
|
* Deletes a document with the given document ID.
|
|
3128
3150
|
* Returns an observable that resolves to the deleted document.
|
|
@@ -4838,7 +4860,8 @@ export declare class SanityClient {
|
|
|
4838
4860
|
* Creates a new version of a published document.
|
|
4839
4861
|
*
|
|
4840
4862
|
* @remarks
|
|
4841
|
-
* *
|
|
4863
|
+
* * 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.
|
|
4864
|
+
* * If `document` is provided, it must have a `_type` property.
|
|
4842
4865
|
* * Creating a version with no `releaseId` will create a new draft version of the published document.
|
|
4843
4866
|
* * 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
4867
|
* * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
|
|
@@ -4847,17 +4870,18 @@ export declare class SanityClient {
|
|
|
4847
4870
|
* @category Versions
|
|
4848
4871
|
*
|
|
4849
4872
|
* @param params - Version action parameters:
|
|
4873
|
+
* - `baseId` - The ID of the published document from which to create a new version from.
|
|
4874
|
+
* - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
|
|
4850
4875
|
* - `document` - The document to create as a new version (must include `_type`).
|
|
4851
4876
|
* - `publishedId` - The ID of the published document being versioned.
|
|
4852
4877
|
* - `releaseId` - The ID of the release to create the version for.
|
|
4853
4878
|
* @param options - Additional action options.
|
|
4854
4879
|
* @returns A promise that resolves to the `transactionId`.
|
|
4855
4880
|
*
|
|
4856
|
-
* @example Creating a new version of a published document
|
|
4881
|
+
* @example Creating a new version of a published document
|
|
4857
4882
|
* ```ts
|
|
4858
4883
|
* const transactionId = await client.createVersion({
|
|
4859
|
-
*
|
|
4860
|
-
* document: {_type: 'myDocument', title: 'My Document'},
|
|
4884
|
+
* baseId: 'myDocument',
|
|
4861
4885
|
* publishedId: 'myDocument',
|
|
4862
4886
|
* releaseId: 'myRelease',
|
|
4863
4887
|
* })
|
|
@@ -4870,25 +4894,11 @@ export declare class SanityClient {
|
|
|
4870
4894
|
* // }
|
|
4871
4895
|
* ```
|
|
4872
4896
|
*
|
|
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
4897
|
*
|
|
4888
4898
|
* @example Creating a new draft version of a published document
|
|
4889
4899
|
* ```ts
|
|
4890
4900
|
* const transactionId = await client.createVersion({
|
|
4891
|
-
*
|
|
4901
|
+
* baseId: 'myDocument',
|
|
4892
4902
|
* publishedId: 'myDocument',
|
|
4893
4903
|
* })
|
|
4894
4904
|
*
|
|
@@ -4916,6 +4926,15 @@ export declare class SanityClient {
|
|
|
4916
4926
|
},
|
|
4917
4927
|
options?: BaseActionOptions,
|
|
4918
4928
|
): Promise<SingleActionResult | MultipleActionResult>
|
|
4929
|
+
createVersion(
|
|
4930
|
+
args: {
|
|
4931
|
+
publishedId: string
|
|
4932
|
+
baseId: string
|
|
4933
|
+
releaseId: string
|
|
4934
|
+
ifBaseRevisionId?: string
|
|
4935
|
+
},
|
|
4936
|
+
options?: BaseActionOptions,
|
|
4937
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
4919
4938
|
/**
|
|
4920
4939
|
* Deletes a document with the given document ID.
|
|
4921
4940
|
* 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.0";
|
|
2523
2564
|
const middleware = [
|
|
2524
2565
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2525
2566
|
headers({ "User-Agent": `${name} ${version}` }),
|