@overmap-ai/core 1.0.53-fix-outbox.3 → 1.0.53-fix-outbox.5
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/overmap-core.js +43 -19
- package/dist/overmap-core.js.map +1 -1
- package/dist/overmap-core.umd.cjs +43 -19
- package/dist/overmap-core.umd.cjs.map +1 -1
- package/dist/store/store.d.ts +2 -1
- package/package.json +1 -1
package/dist/overmap-core.js
CHANGED
|
@@ -4544,6 +4544,8 @@ function setClientStore(store) {
|
|
|
4544
4544
|
function getClientStore() {
|
|
4545
4545
|
return clientStore;
|
|
4546
4546
|
}
|
|
4547
|
+
const useAppDispatch = () => useDispatch();
|
|
4548
|
+
const useAppSelector = useSelector;
|
|
4547
4549
|
const VERSION_REDUCER_KEY = "versioning";
|
|
4548
4550
|
const overmapReducers = {
|
|
4549
4551
|
// TODO: attachmentReducer,
|
|
@@ -4640,21 +4642,38 @@ const rootReducer = (state, action) => {
|
|
|
4640
4642
|
}
|
|
4641
4643
|
return overmapReducer(mutatedState, action);
|
|
4642
4644
|
};
|
|
4643
|
-
let
|
|
4644
|
-
|
|
4645
|
-
|
|
4645
|
+
let __resolveOutboxCoordinator = null;
|
|
4646
|
+
let __outboxCoordinator = null;
|
|
4647
|
+
const __OUTBOX_COORDINATOR_PROMISE = new Promise((resolve) => {
|
|
4648
|
+
__resolveOutboxCoordinator = resolve;
|
|
4649
|
+
}).then((coordinator) => {
|
|
4650
|
+
__outboxCoordinator = coordinator;
|
|
4651
|
+
return coordinator;
|
|
4652
|
+
});
|
|
4653
|
+
async function getOutboxCoordinator() {
|
|
4654
|
+
return await __OUTBOX_COORDINATOR_PROMISE;
|
|
4655
|
+
}
|
|
4656
|
+
const useOutboxCoordinator = () => {
|
|
4657
|
+
const [coordinator, setCoordinator] = useState(null);
|
|
4658
|
+
const rehydrated = useAppSelector(selectRehydrated);
|
|
4659
|
+
useEffect(() => {
|
|
4660
|
+
if (!rehydrated) {
|
|
4661
|
+
return;
|
|
4662
|
+
}
|
|
4646
4663
|
const clientStore2 = getClientStore();
|
|
4647
4664
|
if (!clientStore2) {
|
|
4648
|
-
|
|
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();
|
|
4665
|
+
throw new Error("Client store not set");
|
|
4652
4666
|
}
|
|
4653
4667
|
const outbox = clientStore2.getState().offline.outbox;
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4668
|
+
const coordinator2 = OutboxCoordinator._fromOutbox(outbox);
|
|
4669
|
+
setCoordinator(coordinator2);
|
|
4670
|
+
if (!__resolveOutboxCoordinator) {
|
|
4671
|
+
throw new Error("Outbox coordinator promise resolver not set");
|
|
4672
|
+
}
|
|
4673
|
+
__resolveOutboxCoordinator(coordinator2);
|
|
4674
|
+
}, [rehydrated]);
|
|
4675
|
+
return coordinator;
|
|
4676
|
+
};
|
|
4658
4677
|
const persistCallback = (err) => {
|
|
4659
4678
|
if (err)
|
|
4660
4679
|
throw err;
|
|
@@ -4666,12 +4685,18 @@ const persistCallback = (err) => {
|
|
|
4666
4685
|
}
|
|
4667
4686
|
};
|
|
4668
4687
|
const enqueue = (_array, item, _context) => {
|
|
4669
|
-
const coordinator =
|
|
4688
|
+
const coordinator = __outboxCoordinator;
|
|
4689
|
+
if (!coordinator) {
|
|
4690
|
+
throw new Error("Outbox coordinator not set");
|
|
4691
|
+
}
|
|
4670
4692
|
coordinator.addRequest(item);
|
|
4671
4693
|
return coordinator.getQueue();
|
|
4672
4694
|
};
|
|
4673
4695
|
const dequeue = (_array, item, _context) => {
|
|
4674
|
-
const coordinator =
|
|
4696
|
+
const coordinator = __outboxCoordinator;
|
|
4697
|
+
if (!coordinator) {
|
|
4698
|
+
throw new Error("Outbox coordinator not set");
|
|
4699
|
+
}
|
|
4675
4700
|
const meta = item.meta;
|
|
4676
4701
|
const uuid = meta.offlineAction.payload.uuid;
|
|
4677
4702
|
coordinator.remove(uuid);
|
|
@@ -4963,7 +4988,7 @@ function discard(reason, action, retries = 0) {
|
|
|
4963
4988
|
const uuid = action.payload.uuid;
|
|
4964
4989
|
function rollbackAndThrow() {
|
|
4965
4990
|
clientStore2.dispatch(markAsDeleted(uuid));
|
|
4966
|
-
|
|
4991
|
+
__outboxCoordinator.remove(action.payload.uuid);
|
|
4967
4992
|
const rollbackAction = action.meta.offline.rollback;
|
|
4968
4993
|
if (rollbackAction) {
|
|
4969
4994
|
console.warn("Rolling back request due to SDK error:", action);
|
|
@@ -4994,24 +5019,22 @@ function discard(reason, action, retries = 0) {
|
|
|
4994
5019
|
console.error(`Could not display toast for status ${status} because there is no toast handle.`);
|
|
4995
5020
|
}
|
|
4996
5021
|
}
|
|
4997
|
-
|
|
5022
|
+
__outboxCoordinator.remove(action.payload.uuid);
|
|
4998
5023
|
reason.options.discard = true;
|
|
4999
5024
|
rollbackAndThrow();
|
|
5000
5025
|
}
|
|
5001
5026
|
}
|
|
5002
5027
|
console.debug("Registering a retry for request:", action.payload.uuid);
|
|
5003
|
-
|
|
5028
|
+
__outboxCoordinator.registerRetry(action.payload.uuid);
|
|
5004
5029
|
return false;
|
|
5005
5030
|
}
|
|
5006
5031
|
function peek(_array, _item, _context) {
|
|
5007
|
-
return
|
|
5032
|
+
return __outboxCoordinator.peek();
|
|
5008
5033
|
}
|
|
5009
5034
|
function retry(_action, _retries) {
|
|
5010
5035
|
getClientStore().dispatch(_setLatestRetryTime((/* @__PURE__ */ new Date()).getTime()));
|
|
5011
5036
|
return OUTBOX_RETRY_DELAY;
|
|
5012
5037
|
}
|
|
5013
|
-
const useAppDispatch = () => useDispatch();
|
|
5014
|
-
const useAppSelector = useSelector;
|
|
5015
5038
|
const EXPIRING_SOON_THRESHOLD = 1800;
|
|
5016
5039
|
function parseTokens(response) {
|
|
5017
5040
|
if (!response.access)
|
|
@@ -17335,6 +17358,7 @@ export {
|
|
|
17335
17358
|
useFileViewer,
|
|
17336
17359
|
useFormikInput,
|
|
17337
17360
|
useMemoCompare,
|
|
17361
|
+
useOutboxCoordinator,
|
|
17338
17362
|
useSDK,
|
|
17339
17363
|
userReducer,
|
|
17340
17364
|
userSlice,
|