@routier/core 0.0.2 → 0.0.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.
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.js +11 -2
- package/dist/plugins/index.js.map +1 -1
- package/package.json +1 -1
package/dist/plugins/index.js
CHANGED
|
@@ -1514,6 +1514,9 @@ class OptimisticReplicationDbPlugin {
|
|
|
1514
1514
|
const sourcePlugin = this.plugins.source;
|
|
1515
1515
|
const collectionSize = getMemoryPluginCollectionSize(this.plugins.read, event.operation.schema);
|
|
1516
1516
|
if (collectionSize === 0 && cache.has(WAS_OPTIMISTIC_DB_HYDRATED_KEY) === false) {
|
|
1517
|
+
// Notify the cache that the db was hydrated right away
|
|
1518
|
+
cache.add(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1519
|
+
console.log('[ROUTIER] - Optimistic Query', cache);
|
|
1517
1520
|
// nothing is hydrated, let's try and hydrate before querying
|
|
1518
1521
|
// Memory plugin might not be hydrated, lets hydrate it for the targeted schema only,
|
|
1519
1522
|
// Other queries will do the same and hydrate if needed
|
|
@@ -1526,14 +1529,20 @@ class OptimisticReplicationDbPlugin {
|
|
|
1526
1529
|
operation: _query__WEBPACK_IMPORTED_MODULE_1__.Query.EMPTY(event.operation.schema)
|
|
1527
1530
|
}, (sourceResult) => {
|
|
1528
1531
|
if (sourceResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
|
|
1532
|
+
// Notify that hydration failed
|
|
1533
|
+
cache.delete(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1529
1534
|
done(sourceResult);
|
|
1530
1535
|
return;
|
|
1531
1536
|
}
|
|
1532
1537
|
if (sourceResult == null || (Array.isArray(sourceResult.data) && sourceResult.data.length === 0)) {
|
|
1538
|
+
// Notify that hydration had no data
|
|
1539
|
+
cache.delete(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1533
1540
|
done(sourceResult);
|
|
1534
1541
|
return;
|
|
1535
1542
|
}
|
|
1536
1543
|
if (Array.isArray(sourceResult.data) === false) {
|
|
1544
|
+
// Notify that hydration failed
|
|
1545
|
+
cache.delete(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1537
1546
|
done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, "Query result is not an array"));
|
|
1538
1547
|
return;
|
|
1539
1548
|
}
|
|
@@ -1548,11 +1557,11 @@ class OptimisticReplicationDbPlugin {
|
|
|
1548
1557
|
source: "collection",
|
|
1549
1558
|
}, (readPersistResult) => {
|
|
1550
1559
|
if (readPersistResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
|
|
1560
|
+
// Notify that hydration failed
|
|
1561
|
+
cache.delete(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1551
1562
|
done(readPersistResult);
|
|
1552
1563
|
return;
|
|
1553
1564
|
}
|
|
1554
|
-
// Notify the cache that the db was hydrated
|
|
1555
|
-
cache.add(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1556
1565
|
// requery the read plugin
|
|
1557
1566
|
readPlugin.query(event, done);
|
|
1558
1567
|
});
|