@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.
@@ -1104,16 +1104,29 @@ export declare interface CreateReleaseAction {
1104
1104
  }
1105
1105
 
1106
1106
  /**
1107
- * Creates a new version of an existing document, attached to the release as given
1108
- * by `document._id`
1107
+ * Creates a new version of an existing document.
1108
+ *
1109
+ * If the `document` is provided, the version is created from the document
1110
+ * attached to the release as given by `document._id`
1111
+ *
1112
+ * If the `baseId` and `versionId` are provided, the version is created from the base document
1113
+ * and the version is attached to the release as given by `publishedId` and `versionId`
1109
1114
  *
1110
1115
  * @public
1111
1116
  */
1112
- export declare interface CreateVersionAction {
1117
+ export declare type CreateVersionAction = {
1113
1118
  actionType: 'sanity.action.document.version.create'
1114
1119
  publishedId: string
1115
- document: IdentifiedSanityDocumentStub
1116
- }
1120
+ } & (
1121
+ | {
1122
+ document: IdentifiedSanityDocumentStub
1123
+ }
1124
+ | {
1125
+ baseId: string
1126
+ versionId: string
1127
+ ifBaseRevisionId?: string
1128
+ }
1129
+ )
1117
1130
 
1118
1131
  /** @public */
1119
1132
  export declare interface CurrentSanityUser {
@@ -3296,6 +3309,15 @@ export declare class ObservableSanityClient {
3296
3309
  },
3297
3310
  options?: BaseActionOptions,
3298
3311
  ): Observable<SingleActionResult | MultipleActionResult>
3312
+ createVersion(
3313
+ args: {
3314
+ baseId: string
3315
+ releaseId: string
3316
+ publishedId: string
3317
+ ifBaseRevisionId?: string
3318
+ },
3319
+ options?: BaseActionOptions,
3320
+ ): Observable<SingleActionResult | MultipleActionResult>
3299
3321
  /**
3300
3322
  * Deletes a document with the given document ID.
3301
3323
  * Returns an observable that resolves to the deleted document.
@@ -5023,7 +5045,8 @@ export declare class SanityClient {
5023
5045
  * Creates a new version of a published document.
5024
5046
  *
5025
5047
  * @remarks
5026
- * * Requires a document with a `_type` property.
5048
+ * * 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.
5049
+ * * If `document` is provided, it must have a `_type` property.
5027
5050
  * * Creating a version with no `releaseId` will create a new draft version of the published document.
5028
5051
  * * 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`.
5029
5052
  * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
@@ -5032,17 +5055,18 @@ export declare class SanityClient {
5032
5055
  * @category Versions
5033
5056
  *
5034
5057
  * @param params - Version action parameters:
5058
+ * - `baseId` - The ID of the published document from which to create a new version from.
5059
+ * - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
5035
5060
  * - `document` - The document to create as a new version (must include `_type`).
5036
5061
  * - `publishedId` - The ID of the published document being versioned.
5037
5062
  * - `releaseId` - The ID of the release to create the version for.
5038
5063
  * @param options - Additional action options.
5039
5064
  * @returns A promise that resolves to the `transactionId`.
5040
5065
  *
5041
- * @example Creating a new version of a published document with a generated version ID
5066
+ * @example Creating a new version of a published document
5042
5067
  * ```ts
5043
5068
  * const transactionId = await client.createVersion({
5044
- * // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
5045
- * document: {_type: 'myDocument', title: 'My Document'},
5069
+ * baseId: 'myDocument',
5046
5070
  * publishedId: 'myDocument',
5047
5071
  * releaseId: 'myRelease',
5048
5072
  * })
@@ -5055,25 +5079,11 @@ export declare class SanityClient {
5055
5079
  * // }
5056
5080
  * ```
5057
5081
  *
5058
- * @example Creating a new version of a published document with a specified version ID
5059
- * ```ts
5060
- * const transactionId = await client.createVersion({
5061
- * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
5062
- * // `publishedId` and `releaseId` are not required since `document._id` has been specified
5063
- * })
5064
- *
5065
- * // The following document will be created:
5066
- * // {
5067
- * // _id: 'versions.myRelease.myDocument',
5068
- * // _type: 'myDocument',
5069
- * // title: 'My Document',
5070
- * // }
5071
- * ```
5072
5082
  *
5073
5083
  * @example Creating a new draft version of a published document
5074
5084
  * ```ts
5075
5085
  * const transactionId = await client.createVersion({
5076
- * document: {_type: 'myDocument', title: 'My Document'},
5086
+ * baseId: 'myDocument',
5077
5087
  * publishedId: 'myDocument',
5078
5088
  * })
5079
5089
  *
@@ -5101,6 +5111,15 @@ export declare class SanityClient {
5101
5111
  },
5102
5112
  options?: BaseActionOptions,
5103
5113
  ): Promise<SingleActionResult | MultipleActionResult>
5114
+ createVersion(
5115
+ args: {
5116
+ publishedId: string
5117
+ baseId: string
5118
+ releaseId: string
5119
+ ifBaseRevisionId?: string
5120
+ },
5121
+ options?: BaseActionOptions,
5122
+ ): Promise<SingleActionResult | MultipleActionResult>
5104
5123
  /**
5105
5124
  * Deletes a document with the given document ID.
5106
5125
  * Returns a promise that resolves to the deleted document.
@@ -1104,16 +1104,29 @@ export declare interface CreateReleaseAction {
1104
1104
  }
1105
1105
 
1106
1106
  /**
1107
- * Creates a new version of an existing document, attached to the release as given
1108
- * by `document._id`
1107
+ * Creates a new version of an existing document.
1108
+ *
1109
+ * If the `document` is provided, the version is created from the document
1110
+ * attached to the release as given by `document._id`
1111
+ *
1112
+ * If the `baseId` and `versionId` are provided, the version is created from the base document
1113
+ * and the version is attached to the release as given by `publishedId` and `versionId`
1109
1114
  *
1110
1115
  * @public
1111
1116
  */
1112
- export declare interface CreateVersionAction {
1117
+ export declare type CreateVersionAction = {
1113
1118
  actionType: 'sanity.action.document.version.create'
1114
1119
  publishedId: string
1115
- document: IdentifiedSanityDocumentStub
1116
- }
1120
+ } & (
1121
+ | {
1122
+ document: IdentifiedSanityDocumentStub
1123
+ }
1124
+ | {
1125
+ baseId: string
1126
+ versionId: string
1127
+ ifBaseRevisionId?: string
1128
+ }
1129
+ )
1117
1130
 
1118
1131
  /** @public */
1119
1132
  export declare interface CurrentSanityUser {
@@ -3296,6 +3309,15 @@ export declare class ObservableSanityClient {
3296
3309
  },
3297
3310
  options?: BaseActionOptions,
3298
3311
  ): Observable<SingleActionResult | MultipleActionResult>
3312
+ createVersion(
3313
+ args: {
3314
+ baseId: string
3315
+ releaseId: string
3316
+ publishedId: string
3317
+ ifBaseRevisionId?: string
3318
+ },
3319
+ options?: BaseActionOptions,
3320
+ ): Observable<SingleActionResult | MultipleActionResult>
3299
3321
  /**
3300
3322
  * Deletes a document with the given document ID.
3301
3323
  * Returns an observable that resolves to the deleted document.
@@ -5023,7 +5045,8 @@ export declare class SanityClient {
5023
5045
  * Creates a new version of a published document.
5024
5046
  *
5025
5047
  * @remarks
5026
- * * Requires a document with a `_type` property.
5048
+ * * 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.
5049
+ * * If `document` is provided, it must have a `_type` property.
5027
5050
  * * Creating a version with no `releaseId` will create a new draft version of the published document.
5028
5051
  * * 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`.
5029
5052
  * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
@@ -5032,17 +5055,18 @@ export declare class SanityClient {
5032
5055
  * @category Versions
5033
5056
  *
5034
5057
  * @param params - Version action parameters:
5058
+ * - `baseId` - The ID of the published document from which to create a new version from.
5059
+ * - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
5035
5060
  * - `document` - The document to create as a new version (must include `_type`).
5036
5061
  * - `publishedId` - The ID of the published document being versioned.
5037
5062
  * - `releaseId` - The ID of the release to create the version for.
5038
5063
  * @param options - Additional action options.
5039
5064
  * @returns A promise that resolves to the `transactionId`.
5040
5065
  *
5041
- * @example Creating a new version of a published document with a generated version ID
5066
+ * @example Creating a new version of a published document
5042
5067
  * ```ts
5043
5068
  * const transactionId = await client.createVersion({
5044
- * // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
5045
- * document: {_type: 'myDocument', title: 'My Document'},
5069
+ * baseId: 'myDocument',
5046
5070
  * publishedId: 'myDocument',
5047
5071
  * releaseId: 'myRelease',
5048
5072
  * })
@@ -5055,25 +5079,11 @@ export declare class SanityClient {
5055
5079
  * // }
5056
5080
  * ```
5057
5081
  *
5058
- * @example Creating a new version of a published document with a specified version ID
5059
- * ```ts
5060
- * const transactionId = await client.createVersion({
5061
- * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
5062
- * // `publishedId` and `releaseId` are not required since `document._id` has been specified
5063
- * })
5064
- *
5065
- * // The following document will be created:
5066
- * // {
5067
- * // _id: 'versions.myRelease.myDocument',
5068
- * // _type: 'myDocument',
5069
- * // title: 'My Document',
5070
- * // }
5071
- * ```
5072
5082
  *
5073
5083
  * @example Creating a new draft version of a published document
5074
5084
  * ```ts
5075
5085
  * const transactionId = await client.createVersion({
5076
- * document: {_type: 'myDocument', title: 'My Document'},
5086
+ * baseId: 'myDocument',
5077
5087
  * publishedId: 'myDocument',
5078
5088
  * })
5079
5089
  *
@@ -5101,6 +5111,15 @@ export declare class SanityClient {
5101
5111
  },
5102
5112
  options?: BaseActionOptions,
5103
5113
  ): Promise<SingleActionResult | MultipleActionResult>
5114
+ createVersion(
5115
+ args: {
5116
+ publishedId: string
5117
+ baseId: string
5118
+ releaseId: string
5119
+ ifBaseRevisionId?: string
5120
+ },
5121
+ options?: BaseActionOptions,
5122
+ ): Promise<SingleActionResult | MultipleActionResult>
5104
5123
  /**
5105
5124
  * Deletes a document with the given document ID.
5106
5125
  * Returns a promise that resolves to the deleted document.
package/dist/stega.d.cts CHANGED
@@ -1104,16 +1104,29 @@ export declare interface CreateReleaseAction {
1104
1104
  }
1105
1105
 
1106
1106
  /**
1107
- * Creates a new version of an existing document, attached to the release as given
1108
- * by `document._id`
1107
+ * Creates a new version of an existing document.
1108
+ *
1109
+ * If the `document` is provided, the version is created from the document
1110
+ * attached to the release as given by `document._id`
1111
+ *
1112
+ * If the `baseId` and `versionId` are provided, the version is created from the base document
1113
+ * and the version is attached to the release as given by `publishedId` and `versionId`
1109
1114
  *
1110
1115
  * @public
1111
1116
  */
1112
- export declare interface CreateVersionAction {
1117
+ export declare type CreateVersionAction = {
1113
1118
  actionType: 'sanity.action.document.version.create'
1114
1119
  publishedId: string
1115
- document: IdentifiedSanityDocumentStub
1116
- }
1120
+ } & (
1121
+ | {
1122
+ document: IdentifiedSanityDocumentStub
1123
+ }
1124
+ | {
1125
+ baseId: string
1126
+ versionId: string
1127
+ ifBaseRevisionId?: string
1128
+ }
1129
+ )
1117
1130
 
1118
1131
  /** @public */
1119
1132
  export declare interface CurrentSanityUser {
@@ -3296,6 +3309,15 @@ export declare class ObservableSanityClient {
3296
3309
  },
3297
3310
  options?: BaseActionOptions,
3298
3311
  ): Observable<SingleActionResult | MultipleActionResult>
3312
+ createVersion(
3313
+ args: {
3314
+ baseId: string
3315
+ releaseId: string
3316
+ publishedId: string
3317
+ ifBaseRevisionId?: string
3318
+ },
3319
+ options?: BaseActionOptions,
3320
+ ): Observable<SingleActionResult | MultipleActionResult>
3299
3321
  /**
3300
3322
  * Deletes a document with the given document ID.
3301
3323
  * Returns an observable that resolves to the deleted document.
@@ -5023,7 +5045,8 @@ export declare class SanityClient {
5023
5045
  * Creates a new version of a published document.
5024
5046
  *
5025
5047
  * @remarks
5026
- * * Requires a document with a `_type` property.
5048
+ * * 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.
5049
+ * * If `document` is provided, it must have a `_type` property.
5027
5050
  * * Creating a version with no `releaseId` will create a new draft version of the published document.
5028
5051
  * * 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`.
5029
5052
  * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
@@ -5032,17 +5055,18 @@ export declare class SanityClient {
5032
5055
  * @category Versions
5033
5056
  *
5034
5057
  * @param params - Version action parameters:
5058
+ * - `baseId` - The ID of the published document from which to create a new version from.
5059
+ * - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
5035
5060
  * - `document` - The document to create as a new version (must include `_type`).
5036
5061
  * - `publishedId` - The ID of the published document being versioned.
5037
5062
  * - `releaseId` - The ID of the release to create the version for.
5038
5063
  * @param options - Additional action options.
5039
5064
  * @returns A promise that resolves to the `transactionId`.
5040
5065
  *
5041
- * @example Creating a new version of a published document with a generated version ID
5066
+ * @example Creating a new version of a published document
5042
5067
  * ```ts
5043
5068
  * const transactionId = await client.createVersion({
5044
- * // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
5045
- * document: {_type: 'myDocument', title: 'My Document'},
5069
+ * baseId: 'myDocument',
5046
5070
  * publishedId: 'myDocument',
5047
5071
  * releaseId: 'myRelease',
5048
5072
  * })
@@ -5055,25 +5079,11 @@ export declare class SanityClient {
5055
5079
  * // }
5056
5080
  * ```
5057
5081
  *
5058
- * @example Creating a new version of a published document with a specified version ID
5059
- * ```ts
5060
- * const transactionId = await client.createVersion({
5061
- * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
5062
- * // `publishedId` and `releaseId` are not required since `document._id` has been specified
5063
- * })
5064
- *
5065
- * // The following document will be created:
5066
- * // {
5067
- * // _id: 'versions.myRelease.myDocument',
5068
- * // _type: 'myDocument',
5069
- * // title: 'My Document',
5070
- * // }
5071
- * ```
5072
5082
  *
5073
5083
  * @example Creating a new draft version of a published document
5074
5084
  * ```ts
5075
5085
  * const transactionId = await client.createVersion({
5076
- * document: {_type: 'myDocument', title: 'My Document'},
5086
+ * baseId: 'myDocument',
5077
5087
  * publishedId: 'myDocument',
5078
5088
  * })
5079
5089
  *
@@ -5101,6 +5111,15 @@ export declare class SanityClient {
5101
5111
  },
5102
5112
  options?: BaseActionOptions,
5103
5113
  ): Promise<SingleActionResult | MultipleActionResult>
5114
+ createVersion(
5115
+ args: {
5116
+ publishedId: string
5117
+ baseId: string
5118
+ releaseId: string
5119
+ ifBaseRevisionId?: string
5120
+ },
5121
+ options?: BaseActionOptions,
5122
+ ): Promise<SingleActionResult | MultipleActionResult>
5104
5123
  /**
5105
5124
  * Deletes a document with the given document ID.
5106
5125
  * Returns a promise that resolves to the deleted document.
package/dist/stega.d.ts CHANGED
@@ -1104,16 +1104,29 @@ export declare interface CreateReleaseAction {
1104
1104
  }
1105
1105
 
1106
1106
  /**
1107
- * Creates a new version of an existing document, attached to the release as given
1108
- * by `document._id`
1107
+ * Creates a new version of an existing document.
1108
+ *
1109
+ * If the `document` is provided, the version is created from the document
1110
+ * attached to the release as given by `document._id`
1111
+ *
1112
+ * If the `baseId` and `versionId` are provided, the version is created from the base document
1113
+ * and the version is attached to the release as given by `publishedId` and `versionId`
1109
1114
  *
1110
1115
  * @public
1111
1116
  */
1112
- export declare interface CreateVersionAction {
1117
+ export declare type CreateVersionAction = {
1113
1118
  actionType: 'sanity.action.document.version.create'
1114
1119
  publishedId: string
1115
- document: IdentifiedSanityDocumentStub
1116
- }
1120
+ } & (
1121
+ | {
1122
+ document: IdentifiedSanityDocumentStub
1123
+ }
1124
+ | {
1125
+ baseId: string
1126
+ versionId: string
1127
+ ifBaseRevisionId?: string
1128
+ }
1129
+ )
1117
1130
 
1118
1131
  /** @public */
1119
1132
  export declare interface CurrentSanityUser {
@@ -3296,6 +3309,15 @@ export declare class ObservableSanityClient {
3296
3309
  },
3297
3310
  options?: BaseActionOptions,
3298
3311
  ): Observable<SingleActionResult | MultipleActionResult>
3312
+ createVersion(
3313
+ args: {
3314
+ baseId: string
3315
+ releaseId: string
3316
+ publishedId: string
3317
+ ifBaseRevisionId?: string
3318
+ },
3319
+ options?: BaseActionOptions,
3320
+ ): Observable<SingleActionResult | MultipleActionResult>
3299
3321
  /**
3300
3322
  * Deletes a document with the given document ID.
3301
3323
  * Returns an observable that resolves to the deleted document.
@@ -5023,7 +5045,8 @@ export declare class SanityClient {
5023
5045
  * Creates a new version of a published document.
5024
5046
  *
5025
5047
  * @remarks
5026
- * * Requires a document with a `_type` property.
5048
+ * * 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.
5049
+ * * If `document` is provided, it must have a `_type` property.
5027
5050
  * * Creating a version with no `releaseId` will create a new draft version of the published document.
5028
5051
  * * 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`.
5029
5052
  * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
@@ -5032,17 +5055,18 @@ export declare class SanityClient {
5032
5055
  * @category Versions
5033
5056
  *
5034
5057
  * @param params - Version action parameters:
5058
+ * - `baseId` - The ID of the published document from which to create a new version from.
5059
+ * - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
5035
5060
  * - `document` - The document to create as a new version (must include `_type`).
5036
5061
  * - `publishedId` - The ID of the published document being versioned.
5037
5062
  * - `releaseId` - The ID of the release to create the version for.
5038
5063
  * @param options - Additional action options.
5039
5064
  * @returns A promise that resolves to the `transactionId`.
5040
5065
  *
5041
- * @example Creating a new version of a published document with a generated version ID
5066
+ * @example Creating a new version of a published document
5042
5067
  * ```ts
5043
5068
  * const transactionId = await client.createVersion({
5044
- * // The document does not need to include an `_id` property since it will be generated from `publishedId` and `releaseId`
5045
- * document: {_type: 'myDocument', title: 'My Document'},
5069
+ * baseId: 'myDocument',
5046
5070
  * publishedId: 'myDocument',
5047
5071
  * releaseId: 'myRelease',
5048
5072
  * })
@@ -5055,25 +5079,11 @@ export declare class SanityClient {
5055
5079
  * // }
5056
5080
  * ```
5057
5081
  *
5058
- * @example Creating a new version of a published document with a specified version ID
5059
- * ```ts
5060
- * const transactionId = await client.createVersion({
5061
- * document: {_type: 'myDocument', _id: 'versions.myRelease.myDocument', title: 'My Document'},
5062
- * // `publishedId` and `releaseId` are not required since `document._id` has been specified
5063
- * })
5064
- *
5065
- * // The following document will be created:
5066
- * // {
5067
- * // _id: 'versions.myRelease.myDocument',
5068
- * // _type: 'myDocument',
5069
- * // title: 'My Document',
5070
- * // }
5071
- * ```
5072
5082
  *
5073
5083
  * @example Creating a new draft version of a published document
5074
5084
  * ```ts
5075
5085
  * const transactionId = await client.createVersion({
5076
- * document: {_type: 'myDocument', title: 'My Document'},
5086
+ * baseId: 'myDocument',
5077
5087
  * publishedId: 'myDocument',
5078
5088
  * })
5079
5089
  *
@@ -5101,6 +5111,15 @@ export declare class SanityClient {
5101
5111
  },
5102
5112
  options?: BaseActionOptions,
5103
5113
  ): Promise<SingleActionResult | MultipleActionResult>
5114
+ createVersion(
5115
+ args: {
5116
+ publishedId: string
5117
+ baseId: string
5118
+ releaseId: string
5119
+ ifBaseRevisionId?: string
5120
+ },
5121
+ options?: BaseActionOptions,
5122
+ ): Promise<SingleActionResult | MultipleActionResult>
5104
5123
  /**
5105
5124
  * Deletes a document with the given document ID.
5106
5125
  * Returns a promise that resolves to the deleted document.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "7.7.0",
3
+ "version": "7.8.0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -543,18 +543,43 @@ export class ObservableSanityClient {
543
543
  },
544
544
  options?: BaseActionOptions,
545
545
  ): Observable<SingleActionResult | MultipleActionResult>
546
+ createVersion(
547
+ args: {
548
+ baseId: string
549
+ releaseId: string
550
+ publishedId: string
551
+ ifBaseRevisionId?: string
552
+ },
553
+ options?: BaseActionOptions,
554
+ ): Observable<SingleActionResult | MultipleActionResult>
546
555
  createVersion<R extends Record<string, Any>>(
547
556
  {
548
557
  document,
549
558
  publishedId,
550
559
  releaseId,
560
+ baseId,
561
+ ifBaseRevisionId,
551
562
  }: {
552
- document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
563
+ document?: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
553
564
  publishedId?: string
554
565
  releaseId?: string
566
+ baseId?: string
567
+ ifBaseRevisionId?: string
555
568
  },
556
569
  options?: BaseActionOptions,
557
570
  ): Observable<SingleActionResult | MultipleActionResult> {
571
+ if (!document) {
572
+ return dataMethods._createVersionFromBase(
573
+ this,
574
+ this.#httpRequest,
575
+ publishedId,
576
+ baseId,
577
+ releaseId,
578
+ ifBaseRevisionId,
579
+ options,
580
+ )
581
+ }
582
+
558
583
  const documentVersionId = deriveDocumentVersionId('createVersion', {
559
584
  document,
560
585
  publishedId,
@@ -1446,7 +1471,8 @@ export class SanityClient {
1446
1471
  * Creates a new version of a published document.
1447
1472
  *
1448
1473
  * @remarks
1449
- * * Requires a document with a `_type` property.
1474
+ * * 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.
1475
+ * * If `document` is provided, it must have a `_type` property.
1450
1476
  * * Creating a version with no `releaseId` will create a new draft version of the published document.
1451
1477
  * * 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
1478
  * * If the `document._id` is not defined, it will be generated from `publishedId` and `releaseId`.
@@ -1455,17 +1481,18 @@ export class SanityClient {
1455
1481
  * @category Versions
1456
1482
  *
1457
1483
  * @param params - Version action parameters:
1484
+ * - `baseId` - The ID of the published document from which to create a new version from.
1485
+ * - `ifBaseRevisionId` - If `baseId` is provided, this ensures the `baseId`'s revision Id is as expected before creating the new version from it.
1458
1486
  * - `document` - The document to create as a new version (must include `_type`).
1459
1487
  * - `publishedId` - The ID of the published document being versioned.
1460
1488
  * - `releaseId` - The ID of the release to create the version for.
1461
1489
  * @param options - Additional action options.
1462
1490
  * @returns A promise that resolves to the `transactionId`.
1463
1491
  *
1464
- * @example Creating a new version of a published document with a generated version ID
1492
+ * @example Creating a new version of a published document
1465
1493
  * ```ts
1466
1494
  * 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'},
1495
+ * baseId: 'myDocument',
1469
1496
  * publishedId: 'myDocument',
1470
1497
  * releaseId: 'myRelease',
1471
1498
  * })
@@ -1478,25 +1505,11 @@ export class SanityClient {
1478
1505
  * // }
1479
1506
  * ```
1480
1507
  *
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
1508
  *
1496
1509
  * @example Creating a new draft version of a published document
1497
1510
  * ```ts
1498
1511
  * const transactionId = await client.createVersion({
1499
- * document: {_type: 'myDocument', title: 'My Document'},
1512
+ * baseId: 'myDocument',
1500
1513
  * publishedId: 'myDocument',
1501
1514
  * })
1502
1515
  *
@@ -1524,18 +1537,45 @@ export class SanityClient {
1524
1537
  },
1525
1538
  options?: BaseActionOptions,
1526
1539
  ): Promise<SingleActionResult | MultipleActionResult>
1540
+ createVersion(
1541
+ args: {
1542
+ publishedId: string
1543
+ baseId: string
1544
+ releaseId: string
1545
+ ifBaseRevisionId?: string
1546
+ },
1547
+ options?: BaseActionOptions,
1548
+ ): Promise<SingleActionResult | MultipleActionResult>
1527
1549
  createVersion<R extends Record<string, Any>>(
1528
1550
  {
1529
1551
  document,
1530
1552
  publishedId,
1531
1553
  releaseId,
1554
+ baseId,
1555
+ ifBaseRevisionId,
1532
1556
  }: {
1533
- document: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
1557
+ document?: SanityDocumentStub<R> | IdentifiedSanityDocumentStub<R>
1534
1558
  publishedId?: string
1535
1559
  releaseId?: string
1560
+ baseId?: string
1561
+ ifBaseRevisionId?: string
1536
1562
  },
1537
1563
  options?: BaseActionOptions,
1538
1564
  ): Promise<SingleActionResult | MultipleActionResult> {
1565
+ if (!document) {
1566
+ return firstValueFrom(
1567
+ dataMethods._createVersionFromBase(
1568
+ this,
1569
+ this.#httpRequest,
1570
+ publishedId,
1571
+ baseId,
1572
+ releaseId,
1573
+ ifBaseRevisionId,
1574
+ options,
1575
+ ),
1576
+ )
1577
+ }
1578
+
1539
1579
  const documentVersionId = deriveDocumentVersionId('createVersion', {
1540
1580
  document,
1541
1581
  publishedId,