react-native-mosquito-transport 0.0.37 → 0.0.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-mosquito-transport",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "description": "React native javascript sdk for mosquito-transport (https://github.com/brainbehindx/mosquito-transport)",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -18,7 +18,7 @@ export const listenQueryEntry = (callback, { accessId, builder, config, processI
18
18
  const { projectUrl, dbName, dbUrl, path } = builder;
19
19
  const { episode = 0 } = config || {};
20
20
 
21
- const nodeID = `${projectUrl}${dbName}${dbUrl}${path}`;
21
+ const nodeID = `${projectUrl}_${dbName}_${dbUrl}_${path}`;
22
22
 
23
23
  if (!Scoped.ActiveDatabaseListeners[nodeID])
24
24
  Scoped.ActiveDatabaseListeners[nodeID] = {};
@@ -713,7 +713,7 @@ export const removePendingWrite = async (builder, writeId, revert) => {
713
713
  const pendingData = grab(CacheStore.PendingWrites, [projectUrl, writeId]);
714
714
  if (!pendingData) return;
715
715
 
716
- const pathChanges = revert ? revertChanges(builder, pendingData.editions) : [];
716
+ const pathChanges = revert ? await revertChanges(builder, pendingData.editions) : [];
717
717
 
718
718
  unpoke(CacheStore.PendingWrites, [projectUrl, writeId]);
719
719
  updateCacheStore(['PendingWrites', 'DatabaseStore', 'DatabaseStats']);
@@ -787,7 +787,7 @@ const notifyDatabaseNodeChanges = (builder, changedCollections = []) => {
787
787
  const { projectUrl, dbName, dbUrl } = builder;
788
788
 
789
789
  changedCollections.forEach(path => {
790
- const nodeID = `${projectUrl}${dbName}${dbUrl}${path}`;
790
+ const nodeID = `${projectUrl}_${dbName}_${dbUrl}_${path}`;
791
791
  Object.entries(Scoped.ActiveDatabaseListeners[nodeID] || {})
792
792
  .sort((a, b) => a[1] - b[1])
793
793
  .forEach(([processId]) => {
@@ -721,43 +721,47 @@ const commitData = async (builder, value, type, config) => {
721
721
  return (await sendValue());
722
722
  };
723
723
 
724
- export const trySendPendingWrite = (projectUrl) => {
724
+ export const trySendPendingWrite = async (projectUrl) => {
725
725
  if (Scoped.dispatchingWritesPromise[projectUrl]) return;
726
726
 
727
+ let resolveCallback;
727
728
  Scoped.dispatchingWritesPromise[projectUrl] = new Promise(async resolve => {
728
- const sortedWrite = Object.entries(CacheStore.PendingWrites[projectUrl] || {})
729
- .filter(([k]) => !Scoped.OutgoingWrites[k])
730
- .sort((a, b) => a[1].addedOn - b[1].addedOn);
731
- let resolveCounts = 0;
732
-
733
- for (const [writeId, { snapshot, builder, attempts = 1 }] of sortedWrite) {
734
- try {
735
- await commitData(
736
- { ...Scoped.InitializedProject[projectUrl], ...builder, find: deserializeBSON(builder.find, true)._ },
737
- deserializeBSON(snapshot.value, true)._,
738
- snapshot.type,
739
- { ...snapshot.config, delivery: DELIVERY.NO_CACHE_NO_AWAIT }
740
- );
729
+ resolveCallback = resolve;
730
+ });
731
+
732
+ const sortedWrite = Object.entries(CacheStore.PendingWrites[projectUrl] || {})
733
+ .filter(([k]) => !Scoped.OutgoingWrites[k])
734
+ .sort((a, b) => a[1].addedOn - b[1].addedOn);
735
+ let resolveCounts = 0;
741
736
 
737
+ for (const [writeId, { snapshot, builder, attempts = 1 }] of sortedWrite) {
738
+ try {
739
+ await commitData(
740
+ { ...Scoped.InitializedProject[projectUrl], ...builder, find: deserializeBSON(builder.find, true)._ },
741
+ deserializeBSON(snapshot.value, true)._,
742
+ snapshot.type,
743
+ { ...snapshot.config, delivery: DELIVERY.NO_CACHE_NO_AWAIT }
744
+ );
745
+
746
+ delete CacheStore.PendingWrites[projectUrl][writeId];
747
+ ++resolveCounts;
748
+ } catch (err) {
749
+ const { maxRetries } = builder;
750
+ if (err?.ack || !maxRetries || attempts >= maxRetries) {
742
751
  delete CacheStore.PendingWrites[projectUrl][writeId];
743
752
  ++resolveCounts;
744
- } catch (err) {
745
- const { maxRetries } = builder;
746
- if (err?.ack || !maxRetries || attempts >= maxRetries) {
747
- delete CacheStore.PendingWrites[projectUrl][writeId];
748
- ++resolveCounts;
749
- } else if (CacheStore.PendingWrites[projectUrl]?.[writeId]) {
750
- CacheStore.PendingWrites[projectUrl][writeId].attempts = attempts + 1;
751
- }
753
+ } else if (CacheStore.PendingWrites[projectUrl]?.[writeId]) {
754
+ CacheStore.PendingWrites[projectUrl][writeId].attempts = attempts + 1;
752
755
  }
753
756
  }
754
- resolve();
755
- Scoped.dispatchingWritesPromise[projectUrl] = undefined;
756
- updateCacheStore(['PendingWrites']);
757
-
758
- if (
759
- (sortedWrite.length - resolveCounts) &&
760
- await getReachableServer(projectUrl)
761
- ) trySendPendingWrite(projectUrl);
762
- });
757
+ }
758
+ resolveCallback();
759
+ if (Scoped.dispatchingWritesPromise[projectUrl])
760
+ delete Scoped.dispatchingWritesPromise[projectUrl];
761
+ updateCacheStore(['PendingWrites']);
762
+
763
+ if (
764
+ (sortedWrite.length - resolveCounts) &&
765
+ await getReachableServer(projectUrl)
766
+ ) trySendPendingWrite(projectUrl);
763
767
  };