@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.
@@ -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,17 +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
- return getOutboxCoordinator().peek();
5031
+ return _getOutboxCoordinator().peek();
5008
5032
  }
5009
5033
  function retry(_action, _retries) {
5010
5034
  getClientStore().dispatch(_setLatestRetryTime((/* @__PURE__ */ new Date()).getTime()));
@@ -16790,6 +16814,7 @@ export {
16790
16814
  VerificationCodeType,
16791
16815
  WorkspaceService,
16792
16816
  YELLOW,
16817
+ _getOutboxCoordinator,
16793
16818
  _selectLatestFormRevision,
16794
16819
  _setLatestRetryTime,
16795
16820
  acceptProjectInvite,
@@ -16931,7 +16956,6 @@ export {
16931
16956
  getLocalDateString,
16932
16957
  getLocalRelativeDateString,
16933
16958
  getMarkerCoordinates,
16934
- getOutboxCoordinator,
16935
16959
  getRenamedFile,
16936
16960
  getStageColor,
16937
16961
  hashFile,
@@ -17335,6 +17359,7 @@ export {
17335
17359
  useFileViewer,
17336
17360
  useFormikInput,
17337
17361
  useMemoCompare,
17362
+ useOutboxCoordinator,
17338
17363
  useSDK,
17339
17364
  userReducer,
17340
17365
  userSlice,