@routier/core 0.0.1 → 0.0.3
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 +13 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.js +13 -1
- package/dist/plugins/index.js.map +1 -1
- package/dist/schema/index.js.map +1 -1
- package/package.json +1 -1
package/dist/plugins/index.js
CHANGED
|
@@ -1488,6 +1488,8 @@ const getMemoryPluginCollectionSize = (plugin, schema) => {
|
|
|
1488
1488
|
}
|
|
1489
1489
|
throw new Error("Cannot get size of collection for MemoryPlugin, not an instance of MemoryPlugin");
|
|
1490
1490
|
};
|
|
1491
|
+
const WAS_OPTIMISTIC_DB_HYDRATED_KEY = "was-hydrated";
|
|
1492
|
+
const cache = new Set();
|
|
1491
1493
|
class OptimisticReplicationDbPlugin {
|
|
1492
1494
|
plugins;
|
|
1493
1495
|
constructor(plugins) {
|
|
@@ -1511,7 +1513,9 @@ class OptimisticReplicationDbPlugin {
|
|
|
1511
1513
|
const readPlugin = this.plugins.read;
|
|
1512
1514
|
const sourcePlugin = this.plugins.source;
|
|
1513
1515
|
const collectionSize = getMemoryPluginCollectionSize(this.plugins.read, event.operation.schema);
|
|
1514
|
-
if (collectionSize === 0) {
|
|
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);
|
|
1515
1519
|
// nothing is hydrated, let's try and hydrate before querying
|
|
1516
1520
|
// Memory plugin might not be hydrated, lets hydrate it for the targeted schema only,
|
|
1517
1521
|
// Other queries will do the same and hydrate if needed
|
|
@@ -1524,14 +1528,20 @@ class OptimisticReplicationDbPlugin {
|
|
|
1524
1528
|
operation: _query__WEBPACK_IMPORTED_MODULE_1__.Query.EMPTY(event.operation.schema)
|
|
1525
1529
|
}, (sourceResult) => {
|
|
1526
1530
|
if (sourceResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
|
|
1531
|
+
// Notify that hydration failed
|
|
1532
|
+
cache.delete(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1527
1533
|
done(sourceResult);
|
|
1528
1534
|
return;
|
|
1529
1535
|
}
|
|
1530
1536
|
if (sourceResult == null || (Array.isArray(sourceResult.data) && sourceResult.data.length === 0)) {
|
|
1537
|
+
// Notify that hydration had no data
|
|
1538
|
+
cache.delete(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1531
1539
|
done(sourceResult);
|
|
1532
1540
|
return;
|
|
1533
1541
|
}
|
|
1534
1542
|
if (Array.isArray(sourceResult.data) === false) {
|
|
1543
|
+
// Notify that hydration failed
|
|
1544
|
+
cache.delete(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1535
1545
|
done(_results__WEBPACK_IMPORTED_MODULE_2__.PluginEventResult.error(event.id, "Query result is not an array"));
|
|
1536
1546
|
return;
|
|
1537
1547
|
}
|
|
@@ -1546,6 +1556,8 @@ class OptimisticReplicationDbPlugin {
|
|
|
1546
1556
|
source: "collection",
|
|
1547
1557
|
}, (readPersistResult) => {
|
|
1548
1558
|
if (readPersistResult.ok === _results__WEBPACK_IMPORTED_MODULE_2__.Result.ERROR) {
|
|
1559
|
+
// Notify that hydration failed
|
|
1560
|
+
cache.delete(WAS_OPTIMISTIC_DB_HYDRATED_KEY);
|
|
1549
1561
|
done(readPersistResult);
|
|
1550
1562
|
return;
|
|
1551
1563
|
}
|