@overmap-ai/core 1.0.53-fix-outbox.2 → 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.
@@ -4641,20 +4641,38 @@ const rootReducer = (state, action) => {
4641
4641
  return overmapReducer(mutatedState, action);
4642
4642
  };
4643
4643
  let __OUTBOX_COORDINATOR = null;
4644
- function getOutboxCoordinator() {
4644
+ let __resolveOutboxCoordinator = null;
4645
+ const __OUTBOX_COORDINATOR_PROMISE = new Promise((resolve) => {
4646
+ __resolveOutboxCoordinator = resolve;
4647
+ }).then((coordinator) => {
4648
+ __OUTBOX_COORDINATOR = coordinator;
4649
+ return __OUTBOX_COORDINATOR;
4650
+ });
4651
+ function _getOutboxCoordinator() {
4645
4652
  if (!__OUTBOX_COORDINATOR) {
4646
4653
  const clientStore2 = getClientStore();
4647
4654
  if (!clientStore2) {
4648
- console.error(
4649
- "Cannot reload outbox because there is no client store yet. If there is an outbox, it will be broken."
4650
- );
4651
- return new OutboxCoordinator();
4655
+ return null;
4652
4656
  }
4653
4657
  const outbox = clientStore2.getState().offline.outbox;
4654
4658
  __OUTBOX_COORDINATOR = OutboxCoordinator._fromOutbox(outbox);
4659
+ if (!__resolveOutboxCoordinator) {
4660
+ throw new Error("Outbox coordinator promise not set");
4661
+ }
4662
+ __resolveOutboxCoordinator(__OUTBOX_COORDINATOR);
4655
4663
  }
4656
4664
  return __OUTBOX_COORDINATOR;
4657
4665
  }
4666
+ const useOutboxCoordinator = () => {
4667
+ const [coordinator, setCoordinator] = useState(null);
4668
+ useEffect(() => {
4669
+ async function getCoordinator() {
4670
+ setCoordinator(await __OUTBOX_COORDINATOR_PROMISE);
4671
+ }
4672
+ void getCoordinator();
4673
+ }, []);
4674
+ return coordinator;
4675
+ };
4658
4676
  const persistCallback = (err) => {
4659
4677
  if (err)
4660
4678
  throw err;
@@ -4666,12 +4684,18 @@ const persistCallback = (err) => {
4666
4684
  }
4667
4685
  };
4668
4686
  const enqueue = (_array, item, _context) => {
4669
- const coordinator = getOutboxCoordinator();
4687
+ const coordinator = _getOutboxCoordinator();
4688
+ if (!coordinator) {
4689
+ throw new Error("Outbox coordinator not set");
4690
+ }
4670
4691
  coordinator.addRequest(item);
4671
4692
  return coordinator.getQueue();
4672
4693
  };
4673
4694
  const dequeue = (_array, item, _context) => {
4674
- const coordinator = getOutboxCoordinator();
4695
+ const coordinator = _getOutboxCoordinator();
4696
+ if (!coordinator) {
4697
+ throw new Error("Outbox coordinator not set");
4698
+ }
4675
4699
  const meta = item.meta;
4676
4700
  const uuid = meta.offlineAction.payload.uuid;
4677
4701
  coordinator.remove(uuid);
@@ -4963,7 +4987,7 @@ function discard(reason, action, retries = 0) {
4963
4987
  const uuid = action.payload.uuid;
4964
4988
  function rollbackAndThrow() {
4965
4989
  clientStore2.dispatch(markAsDeleted(uuid));
4966
- getOutboxCoordinator().remove(action.payload.uuid);
4990
+ _getOutboxCoordinator().remove(action.payload.uuid);
4967
4991
  const rollbackAction = action.meta.offline.rollback;
4968
4992
  if (rollbackAction) {
4969
4993
  console.warn("Rolling back request due to SDK error:", action);
@@ -4994,21 +5018,17 @@ function discard(reason, action, retries = 0) {
4994
5018
  console.error(`Could not display toast for status ${status} because there is no toast handle.`);
4995
5019
  }
4996
5020
  }
4997
- getOutboxCoordinator().remove(action.payload.uuid);
5021
+ _getOutboxCoordinator().remove(action.payload.uuid);
4998
5022
  reason.options.discard = true;
4999
5023
  rollbackAndThrow();
5000
5024
  }
5001
5025
  }
5002
5026
  console.debug("Registering a retry for request:", action.payload.uuid);
5003
- getOutboxCoordinator().registerRetry(action.payload.uuid);
5027
+ _getOutboxCoordinator().registerRetry(action.payload.uuid);
5004
5028
  return false;
5005
5029
  }
5006
5030
  function peek(_array, _item, _context) {
5007
- const ret = getOutboxCoordinator().peek();
5008
- if (!ret) {
5009
- throw new Error(`Peek returned ${ret}`);
5010
- }
5011
- return ret;
5031
+ return _getOutboxCoordinator().peek();
5012
5032
  }
5013
5033
  function retry(_action, _retries) {
5014
5034
  getClientStore().dispatch(_setLatestRetryTime((/* @__PURE__ */ new Date()).getTime()));
@@ -16794,6 +16814,7 @@ export {
16794
16814
  VerificationCodeType,
16795
16815
  WorkspaceService,
16796
16816
  YELLOW,
16817
+ _getOutboxCoordinator,
16797
16818
  _selectLatestFormRevision,
16798
16819
  _setLatestRetryTime,
16799
16820
  acceptProjectInvite,
@@ -16935,7 +16956,6 @@ export {
16935
16956
  getLocalDateString,
16936
16957
  getLocalRelativeDateString,
16937
16958
  getMarkerCoordinates,
16938
- getOutboxCoordinator,
16939
16959
  getRenamedFile,
16940
16960
  getStageColor,
16941
16961
  hashFile,
@@ -17339,6 +17359,7 @@ export {
17339
17359
  useFileViewer,
17340
17360
  useFormikInput,
17341
17361
  useMemoCompare,
17362
+ useOutboxCoordinator,
17342
17363
  useSDK,
17343
17364
  userReducer,
17344
17365
  userSlice,