@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/dist/index.cjs CHANGED
@@ -801,12 +801,27 @@ function _createOrReplace(client, httpRequest, doc, options) {
801
801
  return config.requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
802
802
  }
803
803
  function _createVersion(client, httpRequest, doc, publishedId, options) {
804
- return config.requireDocumentId("createVersion", doc), config.requireDocumentType("createVersion", doc), _action(client, httpRequest, {
804
+ return config.requireDocumentId("createVersion", doc), config.requireDocumentType("createVersion", doc), config.printCreateVersionWithBaseIdWarning(), _action(client, httpRequest, {
805
805
  actionType: "sanity.action.document.version.create",
806
806
  publishedId,
807
807
  document: doc
808
808
  }, options);
809
809
  }
810
+ function _createVersionFromBase(client, httpRequest, publishedId, baseId, releaseId, ifBaseRevisionId, options) {
811
+ if (!baseId)
812
+ throw new Error("`createVersion()` requires `baseId` when no `document` is provided");
813
+ if (!publishedId)
814
+ throw new Error("`createVersion()` requires `publishedId` when `baseId` is provided");
815
+ config.validateDocumentId("createVersion", baseId), config.validateDocumentId("createVersion", publishedId);
816
+ const createVersionAction = {
817
+ actionType: "sanity.action.document.version.create",
818
+ publishedId,
819
+ baseId,
820
+ versionId: releaseId ? csm.getVersionId(publishedId, releaseId) : csm.getDraftId(publishedId),
821
+ ifBaseRevisionId
822
+ };
823
+ return _action(client, httpRequest, createVersionAction, options);
824
+ }
810
825
  function _delete(client, httpRequest, selection, options) {
811
826
  return _dataRequest(
812
827
  client,
@@ -2092,8 +2107,20 @@ class ObservableSanityClient {
2092
2107
  createVersion({
2093
2108
  document,
2094
2109
  publishedId,
2095
- releaseId
2110
+ releaseId,
2111
+ baseId,
2112
+ ifBaseRevisionId
2096
2113
  }, options) {
2114
+ if (!document)
2115
+ return _createVersionFromBase(
2116
+ this,
2117
+ this.#httpRequest,
2118
+ publishedId,
2119
+ baseId,
2120
+ releaseId,
2121
+ ifBaseRevisionId,
2122
+ options
2123
+ );
2097
2124
  const documentVersionId = deriveDocumentVersionId("createVersion", {
2098
2125
  document,
2099
2126
  publishedId,
@@ -2344,8 +2371,22 @@ class SanityClient {
2344
2371
  createVersion({
2345
2372
  document,
2346
2373
  publishedId,
2347
- releaseId
2374
+ releaseId,
2375
+ baseId,
2376
+ ifBaseRevisionId
2348
2377
  }, options) {
2378
+ if (!document)
2379
+ return rxjs.firstValueFrom(
2380
+ _createVersionFromBase(
2381
+ this,
2382
+ this.#httpRequest,
2383
+ publishedId,
2384
+ baseId,
2385
+ releaseId,
2386
+ ifBaseRevisionId,
2387
+ options
2388
+ )
2389
+ );
2349
2390
  const documentVersionId = deriveDocumentVersionId("createVersion", {
2350
2391
  document,
2351
2392
  publishedId,
@@ -2533,7 +2574,7 @@ function defineDeprecatedCreateClient(createClient2) {
2533
2574
  return config.printNoDefaultExport(), createClient2(config$1);
2534
2575
  };
2535
2576
  }
2536
- var name = "@sanity/client", version = "7.7.0";
2577
+ var name = "@sanity/client", version = "7.8.1";
2537
2578
  const middleware = [
2538
2579
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
2539
2580
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),