@luvio/environments 0.130.0 → 0.132.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.
@@ -1,4 +1,4 @@
1
- import { emitAdapterEvent, buildStaleWhileRevalidateImplementation, Reader } from '@luvio/engine';
1
+ import { emitAdapterEvent, StoreKeyMap, buildStaleWhileRevalidateImplementation, Reader, StoreKeySet } from '@luvio/engine';
2
2
 
3
3
  // the last version the metadata shape was altered
4
4
  const DURABLE_METADATA_VERSION = '0.111.0';
@@ -290,7 +290,7 @@ function copy(source) {
290
290
  function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler) {
291
291
  const durableRecords = create(null);
292
292
  const evictedRecords = create(null);
293
- const { records, metadata: storeMetadata, visitedIds, refreshedIds } = store;
293
+ const { records, metadata: storeMetadata, visitedIds, refreshedIds, } = store.fallbackStringKeyInMemoryStore;
294
294
  // TODO: W-8909393 Once metadata is stored in its own segment we need to
295
295
  // call setEntries for the visitedIds on default segment and call setEntries
296
296
  // on the metadata segment for the refreshedIds
@@ -431,7 +431,7 @@ function isUnfulfilledSnapshot(cachedSnapshotResult) {
431
431
  function makeDurable(environment, { durableStore, instrumentation }) {
432
432
  let ingestStagingStore = null;
433
433
  const durableTTLStore = new DurableTTLStore(durableStore);
434
- const mergeKeysPromiseMap = new Map();
434
+ const mergeKeysPromiseMap = new StoreKeyMap();
435
435
  // When a context store is mutated we write it to L2, which causes DS on change
436
436
  // event. If this instance of makeDurable caused that L2 write we can ignore that
437
437
  // on change event. This Set helps us do that.
@@ -723,37 +723,38 @@ function makeDurable(environment, { durableStore, instrumentation }) {
723
723
  const getIngestStagingStoreRecords = function () {
724
724
  validateNotDisposed();
725
725
  if (ingestStagingStore !== null) {
726
- return ingestStagingStore.records;
726
+ return ingestStagingStore.fallbackStringKeyInMemoryStore.records;
727
727
  }
728
728
  return {};
729
729
  };
730
730
  const getIngestStagingStoreMetadata = function () {
731
731
  validateNotDisposed();
732
732
  if (ingestStagingStore !== null) {
733
- return ingestStagingStore.metadata;
733
+ return ingestStagingStore.fallbackStringKeyInMemoryStore.metadata;
734
734
  }
735
735
  return {};
736
736
  };
737
737
  const handleSuccessResponse = async function (ingestAndBroadcastFunc, getResponseCacheKeysFunc) {
738
738
  validateNotDisposed();
739
- const cacheKeySet = getResponseCacheKeysFunc();
740
- const cacheKeySetKeys = keys(cacheKeySet);
741
- const keysToRevive = {};
742
- for (const cacheKeySetKey of cacheKeySetKeys) {
743
- const cacheKey = cacheKeySet[cacheKeySetKey];
739
+ const cacheKeyMap = getResponseCacheKeysFunc();
740
+ const cacheKeyMapKeys = Array.from(cacheKeyMap.keys());
741
+ const keysToRevive = new StoreKeySet();
742
+ for (const cacheKeyMapKey of cacheKeyMapKeys) {
743
+ const cacheKey = cacheKeyMap.get(cacheKeyMapKey);
744
744
  if (cacheKey.mergeable === true) {
745
- keysToRevive[cacheKeySetKey] = true;
745
+ keysToRevive.add(cacheKeyMapKey);
746
746
  }
747
747
  }
748
748
  let snapshotFromMemoryIngest = undefined;
749
- const keysAsArray = keys(keysToRevive);
750
- if (keysAsArray.length > 0) {
749
+ // Once these are structured keys, we will call the serializeStructuredKey() utility method
750
+ const keysToReviveAsArray = Array.from(keysToRevive.keysAsStrings());
751
+ if (keysToReviveAsArray.length > 0) {
751
752
  // if we need to do an L2 read then L2 write then we need to synchronize
752
753
  // our read/merge/ingest/write Promise based on the keys so we don't
753
754
  // stomp over any data
754
755
  const readWritePromise = (async () => {
755
756
  const pendingPromises = [];
756
- for (const key of keysAsArray) {
757
+ for (const key of keysToReviveAsArray) {
757
758
  const pendingPromise = mergeKeysPromiseMap.get(key);
758
759
  if (pendingPromise !== undefined) {
759
760
  // IMPORTANT: while on the synchronous code path we get a
@@ -766,17 +767,17 @@ function makeDurable(environment, { durableStore, instrumentation }) {
766
767
  }
767
768
  }
768
769
  await Promise.all(pendingPromises);
769
- const entries = await durableStore.getEntries(keysAsArray, DefaultDurableSegment);
770
+ const entries = await durableStore.getEntries(keysToReviveAsArray, DefaultDurableSegment);
770
771
  ingestStagingStore = buildIngestStagingStore(environment);
771
772
  publishDurableStoreEntries(entries, (key, record) => {
772
- ingestStagingStore.records[key] = record;
773
+ ingestStagingStore.fallbackStringKeyInMemoryStore.records[key] = record;
773
774
  },
774
775
  // we don't need to prime metadata
775
776
  () => { });
776
777
  snapshotFromMemoryIngest = await ingestAndBroadcastFunc();
777
778
  await publishChangesToDurableStore();
778
779
  })();
779
- for (const key of keysAsArray) {
780
+ for (const key of keysToReviveAsArray) {
780
781
  // we are overwriting the previous promise at this key, but that
781
782
  // is ok because we got a handle to it earlier (see the IMPORTANT
782
783
  // comment about 35 lines up)
@@ -786,7 +787,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
786
787
  await readWritePromise;
787
788
  }
788
789
  finally {
789
- for (const key of keysAsArray) {
790
+ for (const key of keysToReviveAsArray) {
790
791
  const pendingPromise = mergeKeysPromiseMap.get(key);
791
792
  // cleanup the entry from the map if this is the last promise
792
793
  // for that key
@@ -24,7 +24,7 @@ export interface DurableEnvironment extends Environment {
24
24
  * Gets the ingest staging store metadata if called during the ingestion
25
25
  * flow, otherwise returns an empty object.
26
26
  */
27
- getIngestStagingStoreMetadata(): InMemoryStore['metadata'];
27
+ getIngestStagingStoreMetadata(): InMemoryStore['fallbackStringKeyInMemoryStore']['metadata'];
28
28
  }
29
29
  export declare const AdapterContextSegment = "ADAPTER-CONTEXT";
30
30
  export declare const ADAPTER_CONTEXT_ID_SUFFIX = "__NAMED_CONTEXT";
@@ -294,7 +294,7 @@
294
294
  function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler) {
295
295
  const durableRecords = create(null);
296
296
  const evictedRecords = create(null);
297
- const { records, metadata: storeMetadata, visitedIds, refreshedIds } = store;
297
+ const { records, metadata: storeMetadata, visitedIds, refreshedIds, } = store.fallbackStringKeyInMemoryStore;
298
298
  // TODO: W-8909393 Once metadata is stored in its own segment we need to
299
299
  // call setEntries for the visitedIds on default segment and call setEntries
300
300
  // on the metadata segment for the refreshedIds
@@ -435,7 +435,7 @@
435
435
  function makeDurable(environment, { durableStore, instrumentation }) {
436
436
  let ingestStagingStore = null;
437
437
  const durableTTLStore = new DurableTTLStore(durableStore);
438
- const mergeKeysPromiseMap = new Map();
438
+ const mergeKeysPromiseMap = new engine.StoreKeyMap();
439
439
  // When a context store is mutated we write it to L2, which causes DS on change
440
440
  // event. If this instance of makeDurable caused that L2 write we can ignore that
441
441
  // on change event. This Set helps us do that.
@@ -727,37 +727,38 @@
727
727
  const getIngestStagingStoreRecords = function () {
728
728
  validateNotDisposed();
729
729
  if (ingestStagingStore !== null) {
730
- return ingestStagingStore.records;
730
+ return ingestStagingStore.fallbackStringKeyInMemoryStore.records;
731
731
  }
732
732
  return {};
733
733
  };
734
734
  const getIngestStagingStoreMetadata = function () {
735
735
  validateNotDisposed();
736
736
  if (ingestStagingStore !== null) {
737
- return ingestStagingStore.metadata;
737
+ return ingestStagingStore.fallbackStringKeyInMemoryStore.metadata;
738
738
  }
739
739
  return {};
740
740
  };
741
741
  const handleSuccessResponse = async function (ingestAndBroadcastFunc, getResponseCacheKeysFunc) {
742
742
  validateNotDisposed();
743
- const cacheKeySet = getResponseCacheKeysFunc();
744
- const cacheKeySetKeys = keys(cacheKeySet);
745
- const keysToRevive = {};
746
- for (const cacheKeySetKey of cacheKeySetKeys) {
747
- const cacheKey = cacheKeySet[cacheKeySetKey];
743
+ const cacheKeyMap = getResponseCacheKeysFunc();
744
+ const cacheKeyMapKeys = Array.from(cacheKeyMap.keys());
745
+ const keysToRevive = new engine.StoreKeySet();
746
+ for (const cacheKeyMapKey of cacheKeyMapKeys) {
747
+ const cacheKey = cacheKeyMap.get(cacheKeyMapKey);
748
748
  if (cacheKey.mergeable === true) {
749
- keysToRevive[cacheKeySetKey] = true;
749
+ keysToRevive.add(cacheKeyMapKey);
750
750
  }
751
751
  }
752
752
  let snapshotFromMemoryIngest = undefined;
753
- const keysAsArray = keys(keysToRevive);
754
- if (keysAsArray.length > 0) {
753
+ // Once these are structured keys, we will call the serializeStructuredKey() utility method
754
+ const keysToReviveAsArray = Array.from(keysToRevive.keysAsStrings());
755
+ if (keysToReviveAsArray.length > 0) {
755
756
  // if we need to do an L2 read then L2 write then we need to synchronize
756
757
  // our read/merge/ingest/write Promise based on the keys so we don't
757
758
  // stomp over any data
758
759
  const readWritePromise = (async () => {
759
760
  const pendingPromises = [];
760
- for (const key of keysAsArray) {
761
+ for (const key of keysToReviveAsArray) {
761
762
  const pendingPromise = mergeKeysPromiseMap.get(key);
762
763
  if (pendingPromise !== undefined) {
763
764
  // IMPORTANT: while on the synchronous code path we get a
@@ -770,17 +771,17 @@
770
771
  }
771
772
  }
772
773
  await Promise.all(pendingPromises);
773
- const entries = await durableStore.getEntries(keysAsArray, DefaultDurableSegment);
774
+ const entries = await durableStore.getEntries(keysToReviveAsArray, DefaultDurableSegment);
774
775
  ingestStagingStore = buildIngestStagingStore(environment);
775
776
  publishDurableStoreEntries(entries, (key, record) => {
776
- ingestStagingStore.records[key] = record;
777
+ ingestStagingStore.fallbackStringKeyInMemoryStore.records[key] = record;
777
778
  },
778
779
  // we don't need to prime metadata
779
780
  () => { });
780
781
  snapshotFromMemoryIngest = await ingestAndBroadcastFunc();
781
782
  await publishChangesToDurableStore();
782
783
  })();
783
- for (const key of keysAsArray) {
784
+ for (const key of keysToReviveAsArray) {
784
785
  // we are overwriting the previous promise at this key, but that
785
786
  // is ok because we got a handle to it earlier (see the IMPORTANT
786
787
  // comment about 35 lines up)
@@ -790,7 +791,7 @@
790
791
  await readWritePromise;
791
792
  }
792
793
  finally {
793
- for (const key of keysAsArray) {
794
+ for (const key of keysToReviveAsArray) {
794
795
  const pendingPromise = mergeKeysPromiseMap.get(key);
795
796
  // cleanup the entry from the map if this is the last promise
796
797
  // for that key
@@ -24,7 +24,7 @@ export interface DurableEnvironment extends Environment {
24
24
  * Gets the ingest staging store metadata if called during the ingestion
25
25
  * flow, otherwise returns an empty object.
26
26
  */
27
- getIngestStagingStoreMetadata(): InMemoryStore['metadata'];
27
+ getIngestStagingStoreMetadata(): InMemoryStore['fallbackStringKeyInMemoryStore']['metadata'];
28
28
  }
29
29
  export declare const AdapterContextSegment = "ADAPTER-CONTEXT";
30
30
  export declare const ADAPTER_CONTEXT_ID_SUFFIX = "__NAMED_CONTEXT";
@@ -23,7 +23,7 @@
23
23
  }
24
24
  var DefaultDurableSegment = 'DEFAULT';
25
25
 
26
- /*! *****************************************************************************
26
+ /******************************************************************************
27
27
  Copyright (c) Microsoft Corporation.
28
28
 
29
29
  Permission to use, copy, modify, and/or distribute this software for any
@@ -65,7 +65,7 @@
65
65
  function verb(n) { return function (v) { return step([n, v]); }; }
66
66
  function step(op) {
67
67
  if (f) throw new TypeError("Generator is already executing.");
68
- while (_) try {
68
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
69
69
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
70
70
  if (y = 0, t) op = [op[0] & 2, t.value];
71
71
  switch (op[0]) {
@@ -375,7 +375,7 @@
375
375
  function flushInMemoryStoreValuesToDurableStore(store, durableStore, durableStoreErrorHandler) {
376
376
  var durableRecords = create(null);
377
377
  var evictedRecords = create(null);
378
- var records = store.records, storeMetadata = store.metadata, visitedIds = store.visitedIds, refreshedIds = store.refreshedIds;
378
+ var _a = store.fallbackStringKeyInMemoryStore, records = _a.records, storeMetadata = _a.metadata, visitedIds = _a.visitedIds, refreshedIds = _a.refreshedIds;
379
379
  // TODO: W-8909393 Once metadata is stored in its own segment we need to
380
380
  // call setEntries for the visitedIds on default segment and call setEntries
381
381
  // on the metadata segment for the refreshedIds
@@ -539,7 +539,7 @@
539
539
  var durableStore = _a.durableStore, instrumentation = _a.instrumentation;
540
540
  var ingestStagingStore = null;
541
541
  var durableTTLStore = new DurableTTLStore(durableStore);
542
- var mergeKeysPromiseMap = new Map();
542
+ var mergeKeysPromiseMap = new engine.StoreKeyMap();
543
543
  // When a context store is mutated we write it to L2, which causes DS on change
544
544
  // event. If this instance of makeDurable caused that L2 write we can ignore that
545
545
  // on change event. This Set helps us do that.
@@ -851,46 +851,46 @@
851
851
  var getIngestStagingStoreRecords = function () {
852
852
  validateNotDisposed();
853
853
  if (ingestStagingStore !== null) {
854
- return ingestStagingStore.records;
854
+ return ingestStagingStore.fallbackStringKeyInMemoryStore.records;
855
855
  }
856
856
  return {};
857
857
  };
858
858
  var getIngestStagingStoreMetadata = function () {
859
859
  validateNotDisposed();
860
860
  if (ingestStagingStore !== null) {
861
- return ingestStagingStore.metadata;
861
+ return ingestStagingStore.fallbackStringKeyInMemoryStore.metadata;
862
862
  }
863
863
  return {};
864
864
  };
865
865
  var handleSuccessResponse = function (ingestAndBroadcastFunc, getResponseCacheKeysFunc) {
866
866
  return __awaiter(this, void 0, void 0, function () {
867
- var cacheKeySet, cacheKeySetKeys, keysToRevive, _i, cacheKeySetKeys_1, cacheKeySetKey, cacheKey, snapshotFromMemoryIngest, keysAsArray, readWritePromise, _a, keysAsArray_1, key, _b, keysAsArray_2, key, pendingPromise, _c, select, refresh, result;
867
+ var cacheKeyMap, cacheKeyMapKeys, keysToRevive, _i, cacheKeyMapKeys_1, cacheKeyMapKey, cacheKey, snapshotFromMemoryIngest, keysToReviveAsArray, readWritePromise, _a, keysToReviveAsArray_1, key, _b, keysToReviveAsArray_2, key, pendingPromise, _c, select, refresh, result;
868
868
  var _this = this;
869
869
  return __generator(this, function (_d) {
870
870
  switch (_d.label) {
871
871
  case 0:
872
872
  validateNotDisposed();
873
- cacheKeySet = getResponseCacheKeysFunc();
874
- cacheKeySetKeys = keys(cacheKeySet);
875
- keysToRevive = {};
876
- for (_i = 0, cacheKeySetKeys_1 = cacheKeySetKeys; _i < cacheKeySetKeys_1.length; _i++) {
877
- cacheKeySetKey = cacheKeySetKeys_1[_i];
878
- cacheKey = cacheKeySet[cacheKeySetKey];
873
+ cacheKeyMap = getResponseCacheKeysFunc();
874
+ cacheKeyMapKeys = Array.from(cacheKeyMap.keys());
875
+ keysToRevive = new engine.StoreKeySet();
876
+ for (_i = 0, cacheKeyMapKeys_1 = cacheKeyMapKeys; _i < cacheKeyMapKeys_1.length; _i++) {
877
+ cacheKeyMapKey = cacheKeyMapKeys_1[_i];
878
+ cacheKey = cacheKeyMap.get(cacheKeyMapKey);
879
879
  if (cacheKey.mergeable === true) {
880
- keysToRevive[cacheKeySetKey] = true;
880
+ keysToRevive.add(cacheKeyMapKey);
881
881
  }
882
882
  }
883
883
  snapshotFromMemoryIngest = undefined;
884
- keysAsArray = keys(keysToRevive);
885
- if (!(keysAsArray.length > 0)) return [3 /*break*/, 5];
884
+ keysToReviveAsArray = Array.from(keysToRevive.keysAsStrings());
885
+ if (!(keysToReviveAsArray.length > 0)) return [3 /*break*/, 5];
886
886
  readWritePromise = (function () { return __awaiter(_this, void 0, void 0, function () {
887
- var pendingPromises, _i, keysAsArray_3, key, pendingPromise, entries;
887
+ var pendingPromises, _i, keysToReviveAsArray_3, key, pendingPromise, entries;
888
888
  return __generator(this, function (_a) {
889
889
  switch (_a.label) {
890
890
  case 0:
891
891
  pendingPromises = [];
892
- for (_i = 0, keysAsArray_3 = keysAsArray; _i < keysAsArray_3.length; _i++) {
893
- key = keysAsArray_3[_i];
892
+ for (_i = 0, keysToReviveAsArray_3 = keysToReviveAsArray; _i < keysToReviveAsArray_3.length; _i++) {
893
+ key = keysToReviveAsArray_3[_i];
894
894
  pendingPromise = mergeKeysPromiseMap.get(key);
895
895
  if (pendingPromise !== undefined) {
896
896
  // IMPORTANT: while on the synchronous code path we get a
@@ -905,12 +905,12 @@
905
905
  return [4 /*yield*/, Promise.all(pendingPromises)];
906
906
  case 1:
907
907
  _a.sent();
908
- return [4 /*yield*/, durableStore.getEntries(keysAsArray, DefaultDurableSegment)];
908
+ return [4 /*yield*/, durableStore.getEntries(keysToReviveAsArray, DefaultDurableSegment)];
909
909
  case 2:
910
910
  entries = _a.sent();
911
911
  ingestStagingStore = buildIngestStagingStore(environment);
912
912
  publishDurableStoreEntries(entries, function (key, record) {
913
- ingestStagingStore.records[key] = record;
913
+ ingestStagingStore.fallbackStringKeyInMemoryStore.records[key] = record;
914
914
  },
915
915
  // we don't need to prime metadata
916
916
  function () { });
@@ -924,8 +924,8 @@
924
924
  }
925
925
  });
926
926
  }); })();
927
- for (_a = 0, keysAsArray_1 = keysAsArray; _a < keysAsArray_1.length; _a++) {
928
- key = keysAsArray_1[_a];
927
+ for (_a = 0, keysToReviveAsArray_1 = keysToReviveAsArray; _a < keysToReviveAsArray_1.length; _a++) {
928
+ key = keysToReviveAsArray_1[_a];
929
929
  // we are overwriting the previous promise at this key, but that
930
930
  // is ok because we got a handle to it earlier (see the IMPORTANT
931
931
  // comment about 35 lines up)
@@ -939,8 +939,8 @@
939
939
  _d.sent();
940
940
  return [3 /*break*/, 4];
941
941
  case 3:
942
- for (_b = 0, keysAsArray_2 = keysAsArray; _b < keysAsArray_2.length; _b++) {
943
- key = keysAsArray_2[_b];
942
+ for (_b = 0, keysToReviveAsArray_2 = keysToReviveAsArray; _b < keysToReviveAsArray_2.length; _b++) {
943
+ key = keysToReviveAsArray_2[_b];
944
944
  pendingPromise = mergeKeysPromiseMap.get(key);
945
945
  // cleanup the entry from the map if this is the last promise
946
946
  // for that key
@@ -24,7 +24,7 @@ export interface DurableEnvironment extends Environment {
24
24
  * Gets the ingest staging store metadata if called during the ingestion
25
25
  * flow, otherwise returns an empty object.
26
26
  */
27
- getIngestStagingStoreMetadata(): InMemoryStore['metadata'];
27
+ getIngestStagingStoreMetadata(): InMemoryStore['fallbackStringKeyInMemoryStore']['metadata'];
28
28
  }
29
29
  export declare const AdapterContextSegment = "ADAPTER-CONTEXT";
30
30
  export declare const ADAPTER_CONTEXT_ID_SUFFIX = "__NAMED_CONTEXT";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/environments",
3
- "version": "0.130.0",
3
+ "version": "0.132.0",
4
4
  "description": "Luvio Environments",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,7 +23,7 @@
23
23
  "watch": "yarn build --watch"
24
24
  },
25
25
  "dependencies": {
26
- "@luvio/engine": "0.130.0"
26
+ "@luvio/engine": "0.132.0"
27
27
  },
28
28
  "bundlesize": [
29
29
  {