@luvio/environments 0.76.1 → 0.78.0

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.
@@ -618,23 +618,49 @@ function makeDurable(environment, { durableStore, instrumentation }) {
618
618
  }
619
619
  return {};
620
620
  };
621
- const handleSuccessResponse = function (ingestAndBroadcastFunc, _getResponseCacheKeysFunc, existingRecords) {
621
+ const handleSuccessResponse = function (ingestAndBroadcastFunc, getResponseCacheKeysFunc, existingRecords) {
622
622
  validateNotDisposed();
623
- ingestStagingStore = new Store();
624
- if (existingRecords !== undefined) {
625
- ingestStagingStore.records = existingRecords;
626
- }
627
- const snapshotFromMemoryIngest = ingestAndBroadcastFunc();
628
- // now that ingestion is done flush staging store values to L2
629
- return publishChangesToDurableStore().then(() => {
630
- if (snapshotFromMemoryIngest === undefined) {
631
- return undefined;
623
+ const cacheKeySet = getResponseCacheKeysFunc();
624
+ const cacheKeys = new Set(keys(cacheKeySet));
625
+ const keysToRevive = {};
626
+ cacheKeys.forEach((cacheKey) => {
627
+ const key = cacheKeySet[cacheKey];
628
+ if (key.mergeable === true &&
629
+ (existingRecords === undefined || existingRecords[cacheKey] === undefined)) {
630
+ keysToRevive[cacheKey] = true;
632
631
  }
633
- if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
634
- return snapshotFromMemoryIngest;
635
- }
636
- // if snapshot from staging store lookup is unfulfilled then do an L2 lookup
637
- return reviveSnapshot(environment, durableStore, snapshotFromMemoryIngest, durableStoreErrorHandler, () => environment.storeLookup(snapshotFromMemoryIngest.select, environment.createSnapshot, snapshotFromMemoryIngest.refresh));
632
+ });
633
+ const ingestAndPublish = (revivedRecords) => {
634
+ const toPrime = existingRecords !== undefined
635
+ ? { ...revivedRecords, ...existingRecords }
636
+ : revivedRecords;
637
+ ingestStagingStore = new Store();
638
+ ingestStagingStore.records = toPrime;
639
+ const snapshotFromMemoryIngest = ingestAndBroadcastFunc();
640
+ return publishChangesToDurableStore().then(() => {
641
+ if (snapshotFromMemoryIngest === undefined) {
642
+ return undefined;
643
+ }
644
+ if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
645
+ return snapshotFromMemoryIngest;
646
+ }
647
+ // if snapshot from staging store lookup is unfulfilled then do an L2 lookup
648
+ return reviveSnapshot(environment, durableStore, snapshotFromMemoryIngest, durableStoreErrorHandler, () => environment.storeLookup(snapshotFromMemoryIngest.select, environment.createSnapshot, snapshotFromMemoryIngest.refresh));
649
+ });
650
+ };
651
+ if (keys(keysToRevive).length === 0) {
652
+ return ingestAndPublish({});
653
+ }
654
+ return durableStore
655
+ .getEntries(keys(keysToRevive), DefaultDurableSegment)
656
+ .then((entries) => {
657
+ const existingL2Records = create(null);
658
+ publishDurableStoreEntries(entries, (key, record) => {
659
+ existingL2Records[key] = record;
660
+ },
661
+ // we don't need to prime metadata
662
+ () => { });
663
+ return ingestAndPublish(existingL2Records);
638
664
  });
639
665
  };
640
666
  const handleErrorResponse = function (ingestAndBroadcastFunc) {
@@ -622,23 +622,49 @@
622
622
  }
623
623
  return {};
624
624
  };
625
- const handleSuccessResponse = function (ingestAndBroadcastFunc, _getResponseCacheKeysFunc, existingRecords) {
625
+ const handleSuccessResponse = function (ingestAndBroadcastFunc, getResponseCacheKeysFunc, existingRecords) {
626
626
  validateNotDisposed();
627
- ingestStagingStore = new engine.Store();
628
- if (existingRecords !== undefined) {
629
- ingestStagingStore.records = existingRecords;
630
- }
631
- const snapshotFromMemoryIngest = ingestAndBroadcastFunc();
632
- // now that ingestion is done flush staging store values to L2
633
- return publishChangesToDurableStore().then(() => {
634
- if (snapshotFromMemoryIngest === undefined) {
635
- return undefined;
627
+ const cacheKeySet = getResponseCacheKeysFunc();
628
+ const cacheKeys = new Set(keys(cacheKeySet));
629
+ const keysToRevive = {};
630
+ cacheKeys.forEach((cacheKey) => {
631
+ const key = cacheKeySet[cacheKey];
632
+ if (key.mergeable === true &&
633
+ (existingRecords === undefined || existingRecords[cacheKey] === undefined)) {
634
+ keysToRevive[cacheKey] = true;
636
635
  }
637
- if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
638
- return snapshotFromMemoryIngest;
639
- }
640
- // if snapshot from staging store lookup is unfulfilled then do an L2 lookup
641
- return reviveSnapshot(environment, durableStore, snapshotFromMemoryIngest, durableStoreErrorHandler, () => environment.storeLookup(snapshotFromMemoryIngest.select, environment.createSnapshot, snapshotFromMemoryIngest.refresh));
636
+ });
637
+ const ingestAndPublish = (revivedRecords) => {
638
+ const toPrime = existingRecords !== undefined
639
+ ? { ...revivedRecords, ...existingRecords }
640
+ : revivedRecords;
641
+ ingestStagingStore = new engine.Store();
642
+ ingestStagingStore.records = toPrime;
643
+ const snapshotFromMemoryIngest = ingestAndBroadcastFunc();
644
+ return publishChangesToDurableStore().then(() => {
645
+ if (snapshotFromMemoryIngest === undefined) {
646
+ return undefined;
647
+ }
648
+ if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
649
+ return snapshotFromMemoryIngest;
650
+ }
651
+ // if snapshot from staging store lookup is unfulfilled then do an L2 lookup
652
+ return reviveSnapshot(environment, durableStore, snapshotFromMemoryIngest, durableStoreErrorHandler, () => environment.storeLookup(snapshotFromMemoryIngest.select, environment.createSnapshot, snapshotFromMemoryIngest.refresh));
653
+ });
654
+ };
655
+ if (keys(keysToRevive).length === 0) {
656
+ return ingestAndPublish({});
657
+ }
658
+ return durableStore
659
+ .getEntries(keys(keysToRevive), DefaultDurableSegment)
660
+ .then((entries) => {
661
+ const existingL2Records = create(null);
662
+ publishDurableStoreEntries(entries, (key, record) => {
663
+ existingL2Records[key] = record;
664
+ },
665
+ // we don't need to prime metadata
666
+ () => { });
667
+ return ingestAndPublish(existingL2Records);
642
668
  });
643
669
  };
644
670
  const handleErrorResponse = function (ingestAndBroadcastFunc) {
@@ -665,25 +665,50 @@
665
665
  }
666
666
  return {};
667
667
  };
668
- var handleSuccessResponse = function (ingestAndBroadcastFunc, _getResponseCacheKeysFunc, existingRecords) {
668
+ var handleSuccessResponse = function (ingestAndBroadcastFunc, getResponseCacheKeysFunc, existingRecords) {
669
669
  validateNotDisposed();
670
- ingestStagingStore = new engine.Store();
671
- if (existingRecords !== undefined) {
672
- ingestStagingStore.records = existingRecords;
673
- }
674
- var snapshotFromMemoryIngest = ingestAndBroadcastFunc();
675
- // now that ingestion is done flush staging store values to L2
676
- return publishChangesToDurableStore().then(function () {
677
- if (snapshotFromMemoryIngest === undefined) {
678
- return undefined;
670
+ var cacheKeySet = getResponseCacheKeysFunc();
671
+ var cacheKeys = new Set(keys(cacheKeySet));
672
+ var keysToRevive = {};
673
+ cacheKeys.forEach(function (cacheKey) {
674
+ var key = cacheKeySet[cacheKey];
675
+ if (key.mergeable === true &&
676
+ (existingRecords === undefined || existingRecords[cacheKey] === undefined)) {
677
+ keysToRevive[cacheKey] = true;
679
678
  }
680
- if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
681
- return snapshotFromMemoryIngest;
682
- }
683
- // if snapshot from staging store lookup is unfulfilled then do an L2 lookup
684
- return reviveSnapshot(environment, durableStore, snapshotFromMemoryIngest, durableStoreErrorHandler, function () {
685
- return environment.storeLookup(snapshotFromMemoryIngest.select, environment.createSnapshot, snapshotFromMemoryIngest.refresh);
679
+ });
680
+ var ingestAndPublish = function (revivedRecords) {
681
+ var toPrime = existingRecords !== undefined
682
+ ? __assign(__assign({}, revivedRecords), existingRecords) : revivedRecords;
683
+ ingestStagingStore = new engine.Store();
684
+ ingestStagingStore.records = toPrime;
685
+ var snapshotFromMemoryIngest = ingestAndBroadcastFunc();
686
+ return publishChangesToDurableStore().then(function () {
687
+ if (snapshotFromMemoryIngest === undefined) {
688
+ return undefined;
689
+ }
690
+ if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
691
+ return snapshotFromMemoryIngest;
692
+ }
693
+ // if snapshot from staging store lookup is unfulfilled then do an L2 lookup
694
+ return reviveSnapshot(environment, durableStore, snapshotFromMemoryIngest, durableStoreErrorHandler, function () {
695
+ return environment.storeLookup(snapshotFromMemoryIngest.select, environment.createSnapshot, snapshotFromMemoryIngest.refresh);
696
+ });
686
697
  });
698
+ };
699
+ if (keys(keysToRevive).length === 0) {
700
+ return ingestAndPublish({});
701
+ }
702
+ return durableStore
703
+ .getEntries(keys(keysToRevive), DefaultDurableSegment)
704
+ .then(function (entries) {
705
+ var existingL2Records = create(null);
706
+ publishDurableStoreEntries(entries, function (key, record) {
707
+ existingL2Records[key] = record;
708
+ },
709
+ // we don't need to prime metadata
710
+ function () { });
711
+ return ingestAndPublish(existingL2Records);
687
712
  });
688
713
  };
689
714
  var handleErrorResponse = function (ingestAndBroadcastFunc) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/environments",
3
- "version": "0.76.1",
3
+ "version": "0.78.0",
4
4
  "description": "Luvio Environments",
5
5
  "main": "dist/umd/es2018/environments.js",
6
6
  "module": "dist/es/es2018/environments.js",
@@ -27,7 +27,7 @@
27
27
  "dist/"
28
28
  ],
29
29
  "dependencies": {
30
- "@luvio/engine": "0.76.1"
30
+ "@luvio/engine": "0.78.0"
31
31
  },
32
32
  "bundlesize": [
33
33
  {