@iebh/tera-fy 2.2.6 → 2.2.7
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/CHANGELOG.md +7 -0
- package/dist/lib/syncro/syncro.d.ts +1 -1
- package/dist/lib/syncro/syncro.js +27 -5
- package/dist/lib/syncro/syncro.js.map +1 -1
- package/dist/plugin.vue2.es2019.js +12 -12
- package/lib/syncro/syncro.ts +25 -6
- package/package.json +1 -1
package/lib/syncro/syncro.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import marshal from '@momsfriendlydevco/marshal';
|
|
21
21
|
import {nanoid} from 'nanoid';
|
|
22
22
|
import PromiseRetry from 'p-retry';
|
|
23
|
-
import {FirebaseApp} from 'firebase/app';
|
|
23
|
+
import {FirebaseApp, FirebaseError} from 'firebase/app';
|
|
24
24
|
import { BoundSupabaseyFunction } from '@iebh/supabasey';
|
|
25
25
|
|
|
26
26
|
|
|
@@ -696,7 +696,7 @@ export default class Syncro {
|
|
|
696
696
|
*
|
|
697
697
|
* @returns {Promise} A promise which resolves when the operation has completed
|
|
698
698
|
*/
|
|
699
|
-
setFirestoreState(state: any, options?: { method?: 'merge' | 'set' }): Promise<void> {
|
|
699
|
+
async setFirestoreState(state: any, options?: { method?: 'merge' | 'set' }, retries = 0): Promise<void> {
|
|
700
700
|
let settings = {
|
|
701
701
|
method: 'merge',
|
|
702
702
|
...options,
|
|
@@ -705,10 +705,29 @@ export default class Syncro {
|
|
|
705
705
|
|
|
706
706
|
const firestoreData = Syncro.toFirestore(state);
|
|
707
707
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
708
|
+
try {
|
|
709
|
+
if (settings.method === 'merge') {
|
|
710
|
+
return await FirestoreUpdateDoc(this.docRef, firestoreData);
|
|
711
|
+
} else { // method === 'set'
|
|
712
|
+
return await FirestoreSetDoc(this.docRef, firestoreData);
|
|
713
|
+
}
|
|
714
|
+
} catch(e) {
|
|
715
|
+
if (e instanceof FirebaseError && e.code === 'not-found') {
|
|
716
|
+
if (retries < 3) {
|
|
717
|
+
console.warn('Firebase syncro document does not exist during document update, reinitializing...');
|
|
718
|
+
// TODO: Reinitialize the firestore syncro document
|
|
719
|
+
const response = await fetch(`${this.config.syncroRegistryUrl}/${this.path}?force=1`);
|
|
720
|
+
if (!response.ok) {
|
|
721
|
+
console.error('Failed to reinitialize Syncro');
|
|
722
|
+
}
|
|
723
|
+
// Retry the request
|
|
724
|
+
return await this.setFirestoreState(state, options, retries + 1);
|
|
725
|
+
} else {
|
|
726
|
+
console.warn('Max retries exceeded while trying to recover firestore syncro document, throwing error')
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
console.error(`Error during Firestore operation (${settings.method}) on doc: ${this.docRef.path}`, e);
|
|
730
|
+
throw e;
|
|
712
731
|
}
|
|
713
732
|
}
|
|
714
733
|
|
package/package.json
CHANGED