@sanity/sdk 2.11.1 → 2.12.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.
Files changed (47) hide show
  1. package/dist/_chunks-dts/utils.d.ts +171 -19
  2. package/dist/_chunks-es/_internal.js +41 -26
  3. package/dist/_chunks-es/_internal.js.map +1 -1
  4. package/dist/_chunks-es/createGroqSearchFilter.js +15 -4
  5. package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -1
  6. package/dist/_chunks-es/telemetryManager.js +25 -19
  7. package/dist/_chunks-es/telemetryManager.js.map +1 -1
  8. package/dist/_chunks-es/version.js +1 -1
  9. package/dist/_exports/_internal.d.ts +27 -11
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +355 -75
  12. package/dist/index.js.map +1 -1
  13. package/package.json +8 -8
  14. package/src/_exports/index.ts +23 -2
  15. package/src/config/sanityConfig.ts +12 -0
  16. package/src/document/actions.test.ts +112 -1
  17. package/src/document/actions.ts +148 -1
  18. package/src/document/applyDocumentActions.ts +4 -3
  19. package/src/document/documentStore.ts +6 -5
  20. package/src/document/events.test.ts +57 -2
  21. package/src/document/events.ts +43 -24
  22. package/src/document/processActions/edit.ts +9 -44
  23. package/src/document/processActions/processActions.ts +44 -3
  24. package/src/document/processActions/releaseArchive.ts +77 -0
  25. package/src/document/processActions/releaseCreate.ts +59 -0
  26. package/src/document/processActions/releaseDelete.ts +65 -0
  27. package/src/document/processActions/releaseEdit.ts +36 -0
  28. package/src/document/processActions/releasePublish.ts +45 -0
  29. package/src/document/processActions/releaseSchedule.ts +87 -0
  30. package/src/document/processActions/releaseUtil.ts +31 -0
  31. package/src/document/processActions/shared.ts +94 -2
  32. package/src/document/processActions.test.ts +423 -1
  33. package/src/document/reducers.ts +40 -5
  34. package/src/releases/getPerspectiveState.test.ts +1 -1
  35. package/src/releases/releasesStore.test.ts +50 -1
  36. package/src/releases/releasesStore.ts +41 -18
  37. package/src/releases/utils/sortReleases.test.ts +2 -2
  38. package/src/releases/utils/sortReleases.ts +1 -1
  39. package/src/telemetry/environment.test.ts +119 -0
  40. package/src/telemetry/environment.ts +92 -0
  41. package/src/telemetry/{__telemetry__/sdk.telemetry.ts → events.ts} +9 -9
  42. package/src/telemetry/initTelemetry.test.ts +240 -16
  43. package/src/telemetry/initTelemetry.ts +39 -16
  44. package/src/telemetry/telemetryManager.test.ts +129 -65
  45. package/src/telemetry/telemetryManager.ts +41 -29
  46. package/src/telemetry/devMode.test.ts +0 -60
  47. package/src/telemetry/devMode.ts +0 -41
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { switchMap, from, firstValueFrom, EMPTY, asapScheduler, distinctUntilChanged, map as map$1, combineLatest, of, concatMap, withLatestFrom, filter as filter$1, concat, timer, throwError, first as first$1, Subject, takeUntil, share, partition, merge, shareReplay, tap as tap$1, catchError as catchError$1, startWith as startWith$1, pairwise as pairwise$1, groupBy as groupBy$1, mergeMap as mergeMap$1, throttle, race, skip, Observable, NEVER, fromEvent, Subscription, debounceTime, defer } from "rxjs";
2
2
  import { createLogger, pickProperties, insecureRandomId, getClientState, bindActionGlobally, createStateSourceAction, setCleanupTimeout, omitProperty, defineStore, authStore, AuthStateType, getCleanedUrl, getTokenFromLocation, createLoggedInAuthState, getAuthCode, REQUEST_TAG_PREFIX, DEFAULT_API_VERSION, getDefaultLocation, isDeepEqual, configureLogging as configureLogging$1, isReleasePerspective, bindActionByResource, isDatasetResource, isMediaLibraryResource, isCanvasResource, getUsersKey, addSubscription, parseUsersKey, getClient, PROJECT_API_VERSION, setUsersError, setUsersData, API_VERSION as API_VERSION$8, getDashboardOrganizationId as getDashboardOrganizationId$1, USERS_STATE_CLEAR_DELAY, removeSubscription, updateLastLoadMoreRequest, cancelRequest, initializeRequest, getTokenState, getQueryState, resolveQuery, bindActionByResourceAndPerspective, PREVIEW_PROJECTION, transformProjectionToPreview } from "./_chunks-es/createGroqSearchFilter.js";
3
- import { createGroqSearchFilter, getActiveReleasesState, getAuthState, getClientErrorApiBody, getClientErrorApiDescription, getClientErrorApiType, getCurrentUserState, getIsInDashboardState, getLoginUrlState, getPerspectiveState, getQueryKey, isCanvasSource, isDatasetSource, isMediaLibrarySource, isProjectUserNotFoundClientError, isStudioConfig, parseQueryKey, setAuthToken } from "./_chunks-es/createGroqSearchFilter.js";
3
+ import { createGroqSearchFilter, getActiveReleasesState, getAllReleasesState, getAuthState, getClientErrorApiBody, getClientErrorApiDescription, getClientErrorApiType, getCurrentUserState, getIsInDashboardState, getLoginUrlState, getPerspectiveState, getQueryKey, isCanvasSource, isDatasetSource, isMediaLibrarySource, isProjectUserNotFoundClientError, isStudioConfig, parseQueryKey, setAuthToken } from "./_chunks-es/createGroqSearchFilter.js";
4
4
  import { first, switchMap as switchMap$1, groupBy, mergeMap, startWith, pairwise, filter, map, delay, tap, catchError, scan, share as share$1 } from "rxjs/operators";
5
5
  import { createController, createNode } from "@sanity/comlink";
6
6
  import { createSelector } from "reselect";
@@ -642,7 +642,47 @@ function discardDocument(doc) {
642
642
  documentId: effectiveDocumentId
643
643
  };
644
644
  }
645
- const DOCUMENT_STATE_CLEAR_DELAY = 1e3, INITIAL_OUTGOING_THROTTLE_TIME = 1e3, API_VERSION$4 = "v2025-05-06";
645
+ function createRelease(handle, metadata = { releaseType: "undecided" }) {
646
+ return { type: "release.create", ...handle, metadata };
647
+ }
648
+ function editRelease(handle, patch) {
649
+ return { type: "release.edit", ...handle, patch };
650
+ }
651
+ function publishRelease(handle) {
652
+ return { type: "release.publish", ...handle };
653
+ }
654
+ function scheduleRelease(handle, publishAt) {
655
+ return { type: "release.schedule", ...handle, publishAt };
656
+ }
657
+ function unscheduleRelease(handle) {
658
+ return { type: "release.unschedule", ...handle };
659
+ }
660
+ function archiveRelease(handle) {
661
+ return { type: "release.archive", ...handle };
662
+ }
663
+ function unarchiveRelease(handle) {
664
+ return { type: "release.unarchive", ...handle };
665
+ }
666
+ function deleteRelease(handle) {
667
+ return { type: "release.delete", ...handle };
668
+ }
669
+ const DOCUMENT_STATE_CLEAR_DELAY = 1e3, INITIAL_OUTGOING_THROTTLE_TIME = 1e3, API_VERSION$4 = "v2025-05-06", RELEASE_DOCUMENTS_PATH = "_.releases";
670
+ function getReleaseDocumentId(releaseId) {
671
+ return `${RELEASE_DOCUMENTS_PATH}.${releaseId}`;
672
+ }
673
+ const RELEASE_ACTION_TYPES = /* @__PURE__ */ new Set([
674
+ "release.create",
675
+ "release.edit",
676
+ "release.publish",
677
+ "release.schedule",
678
+ "release.unschedule",
679
+ "release.archive",
680
+ "release.unarchive",
681
+ "release.delete"
682
+ ]);
683
+ function isReleaseAction(action) {
684
+ return RELEASE_ACTION_TYPES.has(action.type);
685
+ }
646
686
  function generateArrayKey(length = 12) {
647
687
  const numBytes = Math.ceil(length / 2), bytes = crypto.getRandomValues(new Uint8Array(numBytes));
648
688
  return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, length);
@@ -1290,6 +1330,38 @@ class ActionError extends Error {
1290
1330
  }
1291
1331
  class PermissionActionError extends ActionError {
1292
1332
  }
1333
+ function applySingleDocPatch({
1334
+ base: initialBase,
1335
+ working: initialWorking,
1336
+ documentId,
1337
+ patches,
1338
+ transactionId,
1339
+ timestamp,
1340
+ grants,
1341
+ notFoundMessage = "Cannot edit document because it does not exist.",
1342
+ permissionMessage = `You do not have permission to edit document "${documentId}".`
1343
+ }) {
1344
+ let base = initialBase, working = initialWorking;
1345
+ const userPatches = patches?.map((patch) => ({ patch: { id: documentId, ...patch } }));
1346
+ if (!userPatches?.length)
1347
+ return { base, working, diffedPatches: [], workingMutations: [] };
1348
+ if (!working[documentId] || !base[documentId])
1349
+ throw new ActionError({ documentId, transactionId, message: notFoundMessage });
1350
+ const baseBefore = base[documentId];
1351
+ base = processMutations({ documents: base, transactionId, mutations: userPatches, timestamp });
1352
+ const baseAfter = base[documentId], diffedPatches = diffValue(baseBefore, baseAfter), workingBefore = working[documentId];
1353
+ if (!checkGrant(grants.update, workingBefore))
1354
+ throw new PermissionActionError({ documentId, transactionId, message: permissionMessage });
1355
+ const workingMutations = diffedPatches.map((patch) => ({
1356
+ patch: { id: documentId, ...patch }
1357
+ }));
1358
+ return working = processMutations({
1359
+ documents: working,
1360
+ transactionId,
1361
+ mutations: workingMutations,
1362
+ timestamp
1363
+ }), { base, working, diffedPatches, workingMutations };
1364
+ }
1293
1365
  function handleCreate(action, ctx) {
1294
1366
  const { transactionId, timestamp, grants, outgoingActions, outgoingMutations } = ctx;
1295
1367
  let { base, working } = ctx;
@@ -1452,35 +1524,16 @@ function handleEdit(action, ctx) {
1452
1524
  let { base, working } = ctx;
1453
1525
  const documentId = getId(action.documentId);
1454
1526
  if (action.liveEdit) {
1455
- const userPatches2 = action.patches?.map((patch) => ({ patch: { id: documentId, ...patch } }));
1456
- if (!userPatches2?.length) return { base, working };
1457
- if (!working[documentId] || !base[documentId])
1458
- throw new ActionError({
1459
- documentId,
1460
- transactionId,
1461
- message: "Cannot edit document because it does not exist."
1462
- });
1463
- const baseBefore2 = base[documentId];
1464
- userPatches2 && (base = processMutations({
1465
- documents: base,
1466
- transactionId,
1467
- mutations: userPatches2,
1468
- timestamp
1469
- }));
1470
- const baseAfter2 = base[documentId], patches2 = diffValue(baseBefore2, baseAfter2), workingBefore2 = working[documentId];
1471
- if (!checkGrant(grants.update, workingBefore2))
1472
- throw new PermissionActionError({
1473
- documentId,
1474
- transactionId,
1475
- message: `You do not have permission to edit document "${documentId}".`
1476
- });
1477
- const workingMutations2 = patches2.map((patch) => ({ patch: { id: documentId, ...patch } }));
1478
- return working = processMutations({
1479
- documents: working,
1527
+ const result = applySingleDocPatch({
1528
+ base,
1529
+ working,
1530
+ documentId,
1531
+ patches: action.patches,
1480
1532
  transactionId,
1481
- mutations: workingMutations2,
1482
- timestamp
1483
- }), outgoingMutations.push(...workingMutations2), { base, working };
1533
+ timestamp,
1534
+ grants
1535
+ });
1536
+ return outgoingMutations.push(...result.workingMutations), { base: result.base, working: result.working };
1484
1537
  }
1485
1538
  const versionId = isReleasePerspective(action.perspective) ? getVersionId(DocumentId(documentId), action.perspective.releaseName) : void 0, draftId = getDraftId(DocumentId(documentId)), publishedId = getPublishedId(DocumentId(documentId)), patchDocumentId = isReleasePerspective(action.perspective) ? versionId : draftId, userPatches = action.patches?.map((patch) => ({
1486
1539
  patch: { id: patchDocumentId, ...patch }
@@ -1603,6 +1656,188 @@ function strengthenOnPublish(draft) {
1603
1656
  }
1604
1657
  return strengthen(draft);
1605
1658
  }
1659
+ function handleReleaseArchive(action, ctx) {
1660
+ const { base, working, grants, outgoingActions, transactionId } = ctx, releaseDocumentId = getReleaseDocumentId(action.releaseId), existing = working[releaseDocumentId] ?? base[releaseDocumentId];
1661
+ if (!existing)
1662
+ throw new ActionError({
1663
+ documentId: releaseDocumentId,
1664
+ transactionId,
1665
+ message: `Cannot archive release "${action.releaseId}" because it does not exist.`
1666
+ });
1667
+ if (!checkGrant(grants.update, existing))
1668
+ throw new PermissionActionError({
1669
+ documentId: releaseDocumentId,
1670
+ transactionId,
1671
+ message: `You do not have permission to archive release "${action.releaseId}".`
1672
+ });
1673
+ return outgoingActions.push({
1674
+ actionType: "sanity.action.release.archive",
1675
+ releaseId: action.releaseId
1676
+ }), { base, working };
1677
+ }
1678
+ function handleReleaseUnarchive(action, ctx) {
1679
+ const { base, working, grants, outgoingActions, transactionId } = ctx, releaseDocumentId = getReleaseDocumentId(action.releaseId), existing = working[releaseDocumentId] ?? base[releaseDocumentId];
1680
+ if (!existing)
1681
+ throw new ActionError({
1682
+ documentId: releaseDocumentId,
1683
+ transactionId,
1684
+ message: `Cannot unarchive release "${action.releaseId}" because it does not exist.`
1685
+ });
1686
+ if (!checkGrant(grants.update, existing))
1687
+ throw new PermissionActionError({
1688
+ documentId: releaseDocumentId,
1689
+ transactionId,
1690
+ message: `You do not have permission to unarchive release "${action.releaseId}".`
1691
+ });
1692
+ return outgoingActions.push({
1693
+ actionType: "sanity.action.release.unarchive",
1694
+ releaseId: action.releaseId
1695
+ }), { base, working };
1696
+ }
1697
+ function handleReleaseCreate(action, ctx) {
1698
+ const { transactionId, timestamp, grants, outgoingActions, outgoingMutations } = ctx;
1699
+ let { base, working } = ctx;
1700
+ const releaseDocumentId = getReleaseDocumentId(action.releaseId);
1701
+ if (working[releaseDocumentId] || base[releaseDocumentId])
1702
+ throw new ActionError({
1703
+ documentId: releaseDocumentId,
1704
+ transactionId,
1705
+ message: `A release with id "${action.releaseId}" already exists.`
1706
+ });
1707
+ const mutations = [{ create: {
1708
+ _id: releaseDocumentId,
1709
+ _type: "system.release",
1710
+ name: action.releaseId,
1711
+ state: "active",
1712
+ metadata: action.metadata
1713
+ } }];
1714
+ if (base = processMutations({ documents: base, transactionId, mutations, timestamp }), working = processMutations({ documents: working, transactionId, mutations, timestamp }), !checkGrant(grants.create, working[releaseDocumentId]))
1715
+ throw new PermissionActionError({
1716
+ documentId: releaseDocumentId,
1717
+ transactionId,
1718
+ message: `You do not have permission to create release "${action.releaseId}".`
1719
+ });
1720
+ return outgoingMutations.push(...mutations), outgoingActions.push({
1721
+ actionType: "sanity.action.release.create",
1722
+ releaseId: action.releaseId,
1723
+ metadata: action.metadata
1724
+ }), { base, working };
1725
+ }
1726
+ const DELETABLE_STATES = /* @__PURE__ */ new Set(["archived", "published"]);
1727
+ function handleReleaseDelete(action, ctx) {
1728
+ const { transactionId, timestamp, grants, outgoingActions, outgoingMutations } = ctx;
1729
+ let { base, working } = ctx;
1730
+ const releaseDocumentId = getReleaseDocumentId(action.releaseId), existing = working[releaseDocumentId] ?? base[releaseDocumentId];
1731
+ if (!existing)
1732
+ throw new ActionError({
1733
+ documentId: releaseDocumentId,
1734
+ transactionId,
1735
+ message: `Cannot delete release "${action.releaseId}" because it does not exist.`
1736
+ });
1737
+ const state = existing.state;
1738
+ if (state && typeof state == "string" && !DELETABLE_STATES.has(state))
1739
+ throw new ActionError({
1740
+ documentId: releaseDocumentId,
1741
+ transactionId,
1742
+ message: `Cannot delete release "${action.releaseId}" while it is "${state}". Archive it first.`
1743
+ });
1744
+ if (!checkGrant(grants.update, existing))
1745
+ throw new PermissionActionError({
1746
+ documentId: releaseDocumentId,
1747
+ transactionId,
1748
+ message: `You do not have permission to delete release "${action.releaseId}".`
1749
+ });
1750
+ const mutations = [{ delete: { id: releaseDocumentId } }];
1751
+ return base = processMutations({ documents: base, transactionId, mutations, timestamp }), working = processMutations({ documents: working, transactionId, mutations, timestamp }), outgoingMutations.push(...mutations), outgoingActions.push({
1752
+ actionType: "sanity.action.release.delete",
1753
+ releaseId: action.releaseId
1754
+ }), { base, working };
1755
+ }
1756
+ function handleReleaseEdit(action, ctx) {
1757
+ const { transactionId, timestamp, grants, outgoingActions, outgoingMutations } = ctx, { base, working } = ctx, releaseDocumentId = getReleaseDocumentId(action.releaseId), result = applySingleDocPatch({
1758
+ base,
1759
+ working,
1760
+ documentId: releaseDocumentId,
1761
+ patches: [action.patch],
1762
+ transactionId,
1763
+ timestamp,
1764
+ grants,
1765
+ notFoundMessage: `Cannot edit release "${action.releaseId}" because it does not exist.`,
1766
+ permissionMessage: `You do not have permission to edit release "${action.releaseId}".`
1767
+ });
1768
+ return outgoingMutations.push(...result.workingMutations), outgoingActions.push(
1769
+ ...result.diffedPatches.map((patch) => ({
1770
+ actionType: "sanity.action.release.edit",
1771
+ releaseId: action.releaseId,
1772
+ patch
1773
+ }))
1774
+ ), { base: result.base, working: result.working };
1775
+ }
1776
+ function handleReleasePublish(action, ctx) {
1777
+ const { base, working, grants, outgoingActions, transactionId } = ctx, releaseDocumentId = getReleaseDocumentId(action.releaseId), existing = working[releaseDocumentId] ?? base[releaseDocumentId];
1778
+ if (!existing)
1779
+ throw new ActionError({
1780
+ documentId: releaseDocumentId,
1781
+ transactionId,
1782
+ message: `Cannot publish release "${action.releaseId}" because it does not exist.`
1783
+ });
1784
+ if (!checkGrant(grants.update, existing))
1785
+ throw new PermissionActionError({
1786
+ documentId: releaseDocumentId,
1787
+ transactionId,
1788
+ message: `You do not have permission to publish release "${action.releaseId}".`
1789
+ });
1790
+ return outgoingActions.push({
1791
+ actionType: "sanity.action.release.publish",
1792
+ releaseId: action.releaseId
1793
+ }), { base, working };
1794
+ }
1795
+ function handleReleaseSchedule(action, ctx) {
1796
+ const { base, working, grants, outgoingActions, transactionId } = ctx, releaseDocumentId = getReleaseDocumentId(action.releaseId);
1797
+ if (Number.isNaN(Date.parse(action.publishAt)))
1798
+ throw new ActionError({
1799
+ documentId: releaseDocumentId,
1800
+ transactionId,
1801
+ message: `Cannot schedule release "${action.releaseId}": "publishAt" must be a valid ISO 8601 timestamp (received "${action.publishAt}").`
1802
+ });
1803
+ const existing = working[releaseDocumentId] ?? base[releaseDocumentId];
1804
+ if (!existing)
1805
+ throw new ActionError({
1806
+ documentId: releaseDocumentId,
1807
+ transactionId,
1808
+ message: `Cannot schedule release "${action.releaseId}" because it does not exist.`
1809
+ });
1810
+ if (!checkGrant(grants.update, existing))
1811
+ throw new PermissionActionError({
1812
+ documentId: releaseDocumentId,
1813
+ transactionId,
1814
+ message: `You do not have permission to schedule release "${action.releaseId}".`
1815
+ });
1816
+ return outgoingActions.push({
1817
+ actionType: "sanity.action.release.schedule",
1818
+ releaseId: action.releaseId,
1819
+ publishAt: action.publishAt
1820
+ }), { base, working };
1821
+ }
1822
+ function handleReleaseUnschedule(action, ctx) {
1823
+ const { base, working, grants, outgoingActions, transactionId } = ctx, releaseDocumentId = getReleaseDocumentId(action.releaseId), existing = working[releaseDocumentId] ?? base[releaseDocumentId];
1824
+ if (!existing)
1825
+ throw new ActionError({
1826
+ documentId: releaseDocumentId,
1827
+ transactionId,
1828
+ message: `Cannot unschedule release "${action.releaseId}" because it does not exist.`
1829
+ });
1830
+ if (!checkGrant(grants.update, existing))
1831
+ throw new PermissionActionError({
1832
+ documentId: releaseDocumentId,
1833
+ transactionId,
1834
+ message: `You do not have permission to unschedule release "${action.releaseId}".`
1835
+ });
1836
+ return outgoingActions.push({
1837
+ actionType: "sanity.action.release.unschedule",
1838
+ releaseId: action.releaseId
1839
+ }), { base, working };
1840
+ }
1606
1841
  function handleUnpublish(action, ctx) {
1607
1842
  const { transactionId, timestamp, grants, outgoingActions, outgoingMutations } = ctx;
1608
1843
  let { base, working } = ctx;
@@ -1659,7 +1894,13 @@ function processActions({
1659
1894
  grants
1660
1895
  }) {
1661
1896
  let base = { ...initialBase }, working = { ...initialWorking };
1662
- const outgoingActions = [], outgoingMutations = [];
1897
+ const outgoingActions = [], outgoingMutations = [], liveEditAction = actions.find((action) => !isReleaseAction(action) && action.liveEdit), otherAction = actions.find((action) => isReleaseAction(action) || !action.liveEdit);
1898
+ if (liveEditAction && otherAction)
1899
+ throw new ActionError({
1900
+ documentId: liveEditAction.documentId,
1901
+ transactionId,
1902
+ message: "Cannot combine liveEdit document actions with other actions in the same transaction. Submit them as separate transactions."
1903
+ });
1663
1904
  for (const action of actions) {
1664
1905
  const result = dispatch(action, {
1665
1906
  base,
@@ -1697,6 +1938,22 @@ function dispatch(action, ctx) {
1697
1938
  return handlePublish(action, ctx);
1698
1939
  case "document.unpublish":
1699
1940
  return handleUnpublish(action, ctx);
1941
+ case "release.create":
1942
+ return handleReleaseCreate(action, ctx);
1943
+ case "release.edit":
1944
+ return handleReleaseEdit(action, ctx);
1945
+ case "release.publish":
1946
+ return handleReleasePublish(action, ctx);
1947
+ case "release.schedule":
1948
+ return handleReleaseSchedule(action, ctx);
1949
+ case "release.unschedule":
1950
+ return handleReleaseUnschedule(action, ctx);
1951
+ case "release.archive":
1952
+ return handleReleaseArchive(action, ctx);
1953
+ case "release.unarchive":
1954
+ return handleReleaseUnarchive(action, ctx);
1955
+ case "release.delete":
1956
+ return handleReleaseDelete(action, ctx);
1700
1957
  default:
1701
1958
  throw new Error(
1702
1959
  `Unknown action type: "${// @ts-expect-error invalid input
@@ -1779,29 +2036,31 @@ function batchAppliedTransactions([curr, ...rest]) {
1779
2036
  };
1780
2037
  if (!rest.length) return editAction;
1781
2038
  const next = batchAppliedTransactions(rest);
1782
- if (next)
1783
- return next.disableBatching || !!action.liveEdit != !!next.actions[0]?.liveEdit ? editAction : {
1784
- disableBatching: !1,
1785
- // Use the transactionId from the later (next) transaction.
1786
- transactionId: next.transactionId,
1787
- // Accumulate actions: current action first, then later ones.
1788
- actions: [action, ...next.actions],
1789
- // Merge outgoingActions in order.
1790
- outgoingActions: [...curr.outgoingActions, ...next.outgoingActions],
1791
- // Batched transaction IDs: preserve order by placing curr first.
1792
- batchedTransactionIds: [curr.transactionId, ...next.batchedTransactionIds],
1793
- // Merge outgoingMutations in order.
1794
- outgoingMutations: [...curr.outgoingMutations, ...next.outgoingMutations],
1795
- // Working state reflects the latest optimistic changes: later transactions override earlier.
1796
- working: { ...curr.working, ...next.working },
1797
- // Base state (base, previous, previousRevs) must reflect the original state.
1798
- // Use curr values (the earliest transaction) to override later ones.
1799
- previousRevs: { ...next.previousRevs, ...curr.previousRevs },
1800
- previous: { ...next.previous, ...curr.previous },
1801
- base: { ...next.base, ...curr.base },
1802
- // Use the earliest timestamp from curr.
1803
- timestamp: curr.timestamp ?? next.timestamp
1804
- };
2039
+ if (!next) return;
2040
+ if (next.disableBatching) return editAction;
2041
+ const nextFirst = next.actions[0], nextLiveEdit = nextFirst && "liveEdit" in nextFirst ? nextFirst.liveEdit : !1;
2042
+ return !!action.liveEdit != !!nextLiveEdit ? editAction : {
2043
+ disableBatching: !1,
2044
+ // Use the transactionId from the later (next) transaction.
2045
+ transactionId: next.transactionId,
2046
+ // Accumulate actions: current action first, then later ones.
2047
+ actions: [action, ...next.actions],
2048
+ // Merge outgoingActions in order.
2049
+ outgoingActions: [...curr.outgoingActions, ...next.outgoingActions],
2050
+ // Batched transaction IDs: preserve order by placing curr first.
2051
+ batchedTransactionIds: [curr.transactionId, ...next.batchedTransactionIds],
2052
+ // Merge outgoingMutations in order.
2053
+ outgoingMutations: [...curr.outgoingMutations, ...next.outgoingMutations],
2054
+ // Working state reflects the latest optimistic changes: later transactions override earlier.
2055
+ working: { ...curr.working, ...next.working },
2056
+ // Base state (base, previous, previousRevs) must reflect the original state.
2057
+ // Use curr values (the earliest transaction) to override later ones.
2058
+ previousRevs: { ...next.previousRevs, ...curr.previousRevs },
2059
+ previous: { ...next.previous, ...curr.previous },
2060
+ base: { ...next.base, ...curr.base },
2061
+ // Use the earliest timestamp from curr.
2062
+ timestamp: curr.timestamp ?? next.timestamp
2063
+ };
1805
2064
  }
1806
2065
  function transitionAppliedTransactionsToOutgoing(prev) {
1807
2066
  if (prev.outgoing) return prev;
@@ -1978,32 +2237,43 @@ function manageSubscriberIds({ state }, handles) {
1978
2237
  }
1979
2238
  function getDocumentIdsFromHandleLikes(handles) {
1980
2239
  return handles.flatMap((handle) => {
2240
+ if ("type" in handle && isReleaseAction(handle))
2241
+ return [getReleaseDocumentId(handle.releaseId)];
1981
2242
  const idsForDocument = [];
1982
2243
  return handle.documentId ? handle.liveEdit ? [handle.documentId] : (isReleasePerspective(handle.perspective) && idsForDocument.push(
1983
2244
  getVersionId(DocumentId(handle.documentId), handle.perspective.releaseName)
1984
2245
  ), idsForDocument.push(getPublishedId(DocumentId(handle.documentId))), idsForDocument.push(getDraftId(DocumentId(handle.documentId))), idsForDocument) : [];
1985
2246
  });
1986
2247
  }
2248
+ const actionMap = {
2249
+ "document.create": "created",
2250
+ "document.delete": "deleted",
2251
+ "document.discard": "discarded",
2252
+ "document.edit": "edited",
2253
+ "document.publish": "published",
2254
+ "document.unpublish": "unpublished",
2255
+ "release.create": "created",
2256
+ "release.edit": "edited",
2257
+ "release.delete": "deleted"
2258
+ };
1987
2259
  function getDocumentEvents(outgoing) {
1988
- const documentIdsByAction = Object.entries(
1989
- outgoing.actions.reduce(
1990
- (acc, { type, documentId }) => {
1991
- const ids = acc[type] || /* @__PURE__ */ new Set();
1992
- return documentId && ids.add(documentId), acc[type] = ids, acc;
1993
- },
1994
- {}
1995
- )
1996
- ), actionMap = {
1997
- "document.create": "created",
1998
- "document.delete": "deleted",
1999
- "document.discard": "discarded",
2000
- "document.edit": "edited",
2001
- "document.publish": "published",
2002
- "document.unpublish": "unpublished"
2003
- };
2004
- return documentIdsByAction.flatMap(
2005
- ([actionType, documentIds]) => Array.from(documentIds).map(
2006
- (documentId) => ({ type: actionMap[actionType], documentId, outgoing })
2260
+ const documentIdsByAction = outgoing.actions.reduce(
2261
+ (acc, action) => {
2262
+ if (!(action.type in actionMap)) return acc;
2263
+ const documentId = isReleaseAction(action) ? getReleaseDocumentId(action.releaseId) : action.documentId;
2264
+ if (!documentId) return acc;
2265
+ const type = action.type, ids = acc[type] ?? /* @__PURE__ */ new Set();
2266
+ return ids.add(documentId), acc[type] = ids, acc;
2267
+ },
2268
+ {}
2269
+ );
2270
+ return Object.entries(documentIdsByAction).flatMap(
2271
+ ([actionType, documentIds]) => Array.from(documentIds ?? []).map(
2272
+ (documentId) => ({
2273
+ type: actionMap[actionType],
2274
+ documentId,
2275
+ outgoing
2276
+ })
2007
2277
  )
2008
2278
  );
2009
2279
  }
@@ -2227,7 +2497,7 @@ const _resolveDocument = bindActionByResource(
2227
2497
  result,
2228
2498
  outgoing
2229
2499
  }));
2230
- return outgoing.actions.some((action) => action.liveEdit) ? client.observable.mutate(outgoing.outgoingMutations, {
2500
+ return outgoing.actions.some((action) => !isReleaseAction(action) && action.liveEdit) ? client.observable.mutate(outgoing.outgoingMutations, {
2231
2501
  transactionId: outgoing.transactionId,
2232
2502
  visibility: "async",
2233
2503
  returnDocuments: !1,
@@ -3270,6 +3540,7 @@ export {
3270
3540
  agentTransform,
3271
3541
  agentTranslate,
3272
3542
  applyDocumentActions,
3543
+ archiveRelease,
3273
3544
  configureLogging,
3274
3545
  createDatasetHandle,
3275
3546
  createDocument,
@@ -3277,13 +3548,17 @@ export {
3277
3548
  createDocumentTypeHandle,
3278
3549
  createGroqSearchFilter,
3279
3550
  createProjectHandle,
3551
+ createRelease,
3280
3552
  createSanityInstance,
3281
3553
  defineIntent,
3282
3554
  deleteDocument,
3555
+ deleteRelease,
3283
3556
  destroyController,
3284
3557
  discardDocument,
3285
3558
  editDocument,
3559
+ editRelease,
3286
3560
  getActiveReleasesState,
3561
+ getAllReleasesState,
3287
3562
  getAuthState,
3288
3563
  getClient,
3289
3564
  getClientErrorApiBody,
@@ -3316,6 +3591,7 @@ export {
3316
3591
  getProjectsState,
3317
3592
  getQueryKey,
3318
3593
  getQueryState,
3594
+ getReleaseDocumentId,
3319
3595
  getTokenState,
3320
3596
  getUserState,
3321
3597
  getUsersKey,
@@ -3338,6 +3614,7 @@ export {
3338
3614
  parseQueryKey,
3339
3615
  parseUsersKey,
3340
3616
  publishDocument,
3617
+ publishRelease,
3341
3618
  releaseChannel,
3342
3619
  releaseNode,
3343
3620
  resolveDatasets,
@@ -3353,11 +3630,14 @@ export {
3353
3630
  resolveQuery,
3354
3631
  resolveUser,
3355
3632
  resolveUsers,
3633
+ scheduleRelease,
3356
3634
  setAuthToken,
3357
3635
  slicePath2 as slicePath,
3358
3636
  stringifyPath2 as stringifyPath,
3359
3637
  subscribeDocumentEvents,
3360
3638
  transformProjectionToPreview,
3361
- unpublishDocument
3639
+ unarchiveRelease,
3640
+ unpublishDocument,
3641
+ unscheduleRelease
3362
3642
  };
3363
3643
  //# sourceMappingURL=index.js.map