@overmap-ai/core 1.0.53-fix-outbox.3 → 1.0.53-fix-outbox.4

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.
@@ -4631,20 +4631,38 @@ var __publicField = (obj, key, value) => {
4631
4631
  return overmapReducer(mutatedState, action);
4632
4632
  };
4633
4633
  let __OUTBOX_COORDINATOR = null;
4634
- function getOutboxCoordinator() {
4634
+ let __resolveOutboxCoordinator = null;
4635
+ const __OUTBOX_COORDINATOR_PROMISE = new Promise((resolve) => {
4636
+ __resolveOutboxCoordinator = resolve;
4637
+ }).then((coordinator) => {
4638
+ __OUTBOX_COORDINATOR = coordinator;
4639
+ return __OUTBOX_COORDINATOR;
4640
+ });
4641
+ function _getOutboxCoordinator() {
4635
4642
  if (!__OUTBOX_COORDINATOR) {
4636
4643
  const clientStore2 = getClientStore();
4637
4644
  if (!clientStore2) {
4638
- console.error(
4639
- "Cannot reload outbox because there is no client store yet. If there is an outbox, it will be broken."
4640
- );
4641
- return new OutboxCoordinator();
4645
+ return null;
4642
4646
  }
4643
4647
  const outbox = clientStore2.getState().offline.outbox;
4644
4648
  __OUTBOX_COORDINATOR = OutboxCoordinator._fromOutbox(outbox);
4649
+ if (!__resolveOutboxCoordinator) {
4650
+ throw new Error("Outbox coordinator promise not set");
4651
+ }
4652
+ __resolveOutboxCoordinator(__OUTBOX_COORDINATOR);
4645
4653
  }
4646
4654
  return __OUTBOX_COORDINATOR;
4647
4655
  }
4656
+ const useOutboxCoordinator = () => {
4657
+ const [coordinator, setCoordinator] = React.useState(null);
4658
+ React.useEffect(() => {
4659
+ async function getCoordinator() {
4660
+ setCoordinator(await __OUTBOX_COORDINATOR_PROMISE);
4661
+ }
4662
+ void getCoordinator();
4663
+ }, []);
4664
+ return coordinator;
4665
+ };
4648
4666
  const persistCallback = (err) => {
4649
4667
  if (err)
4650
4668
  throw err;
@@ -4656,12 +4674,18 @@ var __publicField = (obj, key, value) => {
4656
4674
  }
4657
4675
  };
4658
4676
  const enqueue = (_array, item, _context) => {
4659
- const coordinator = getOutboxCoordinator();
4677
+ const coordinator = _getOutboxCoordinator();
4678
+ if (!coordinator) {
4679
+ throw new Error("Outbox coordinator not set");
4680
+ }
4660
4681
  coordinator.addRequest(item);
4661
4682
  return coordinator.getQueue();
4662
4683
  };
4663
4684
  const dequeue = (_array, item, _context) => {
4664
- const coordinator = getOutboxCoordinator();
4685
+ const coordinator = _getOutboxCoordinator();
4686
+ if (!coordinator) {
4687
+ throw new Error("Outbox coordinator not set");
4688
+ }
4665
4689
  const meta = item.meta;
4666
4690
  const uuid2 = meta.offlineAction.payload.uuid;
4667
4691
  coordinator.remove(uuid2);
@@ -4953,7 +4977,7 @@ var __publicField = (obj, key, value) => {
4953
4977
  const uuid2 = action.payload.uuid;
4954
4978
  function rollbackAndThrow() {
4955
4979
  clientStore2.dispatch(markAsDeleted(uuid2));
4956
- getOutboxCoordinator().remove(action.payload.uuid);
4980
+ _getOutboxCoordinator().remove(action.payload.uuid);
4957
4981
  const rollbackAction = action.meta.offline.rollback;
4958
4982
  if (rollbackAction) {
4959
4983
  console.warn("Rolling back request due to SDK error:", action);
@@ -4984,17 +5008,17 @@ var __publicField = (obj, key, value) => {
4984
5008
  console.error(`Could not display toast for status ${status} because there is no toast handle.`);
4985
5009
  }
4986
5010
  }
4987
- getOutboxCoordinator().remove(action.payload.uuid);
5011
+ _getOutboxCoordinator().remove(action.payload.uuid);
4988
5012
  reason.options.discard = true;
4989
5013
  rollbackAndThrow();
4990
5014
  }
4991
5015
  }
4992
5016
  console.debug("Registering a retry for request:", action.payload.uuid);
4993
- getOutboxCoordinator().registerRetry(action.payload.uuid);
5017
+ _getOutboxCoordinator().registerRetry(action.payload.uuid);
4994
5018
  return false;
4995
5019
  }
4996
5020
  function peek(_array, _item, _context) {
4997
- return getOutboxCoordinator().peek();
5021
+ return _getOutboxCoordinator().peek();
4998
5022
  }
4999
5023
  function retry(_action, _retries) {
5000
5024
  getClientStore().dispatch(_setLatestRetryTime((/* @__PURE__ */ new Date()).getTime()));
@@ -16779,6 +16803,7 @@ var __publicField = (obj, key, value) => {
16779
16803
  exports2.VerificationCodeType = VerificationCodeType;
16780
16804
  exports2.WorkspaceService = WorkspaceService;
16781
16805
  exports2.YELLOW = YELLOW;
16806
+ exports2._getOutboxCoordinator = _getOutboxCoordinator;
16782
16807
  exports2._selectLatestFormRevision = _selectLatestFormRevision;
16783
16808
  exports2._setLatestRetryTime = _setLatestRetryTime;
16784
16809
  exports2.acceptProjectInvite = acceptProjectInvite;
@@ -16920,7 +16945,6 @@ var __publicField = (obj, key, value) => {
16920
16945
  exports2.getLocalDateString = getLocalDateString;
16921
16946
  exports2.getLocalRelativeDateString = getLocalRelativeDateString;
16922
16947
  exports2.getMarkerCoordinates = getMarkerCoordinates;
16923
- exports2.getOutboxCoordinator = getOutboxCoordinator;
16924
16948
  exports2.getRenamedFile = getRenamedFile;
16925
16949
  exports2.getStageColor = getStageColor;
16926
16950
  exports2.hashFile = hashFile;
@@ -17324,6 +17348,7 @@ var __publicField = (obj, key, value) => {
17324
17348
  exports2.useFileViewer = useFileViewer;
17325
17349
  exports2.useFormikInput = useFormikInput;
17326
17350
  exports2.useMemoCompare = useMemoCompare;
17351
+ exports2.useOutboxCoordinator = useOutboxCoordinator;
17327
17352
  exports2.useSDK = useSDK;
17328
17353
  exports2.userReducer = userReducer;
17329
17354
  exports2.userSlice = userSlice;