@luvio/environments 0.62.2 → 0.63.1

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.
@@ -17,6 +17,13 @@ const DefaultDurableSegment = 'DEFAULT';
17
17
  const { keys, create, assign, freeze } = Object;
18
18
  const { isArray } = Array;
19
19
 
20
+ function appendTTLStrategy(storeLookup, ttlStrategy) {
21
+ return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
22
+ }
23
+ function buildNetworkSnapshot(args) {
24
+ const { buildNetworkSnapshot, buildSnapshotContext } = args;
25
+ return buildNetworkSnapshot(buildSnapshotContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
26
+ }
20
27
  function buildTTLStrategy(staleDurationMilliseconds = 0) {
21
28
  return (timestamp, metadata, valueIsError) => {
22
29
  if (metadata !== undefined) {
@@ -34,15 +41,12 @@ function buildTTLStrategy(staleDurationMilliseconds = 0) {
34
41
  }
35
42
  return StoreResolveResultState.Found;
36
43
  };
37
- }
38
- function appendTTLStrategy(storeLookup, ttlStrategy) {
39
- return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
40
44
  }
41
45
 
42
46
  function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
43
47
  return function (args) {
44
48
  funcs.validateNotDisposed();
45
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
49
+ const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup } = args;
46
50
  const staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
47
51
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
48
52
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
@@ -50,10 +54,16 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
50
54
  // data found in L1 cache
51
55
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
52
56
  // kick off network request, do not await it
53
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
57
+ buildNetworkSnapshot$1(buildSnapshotContext);
54
58
  // return the cached snapshot to caller
55
59
  return snapshot;
56
60
  }
61
+ // network request outstanding
62
+ if (snapshot.state === 'Pending') {
63
+ // kick off another network request, do not await it
64
+ buildNetworkSnapshot$1(buildSnapshotContext);
65
+ return args.resolvePendingSnapshot(snapshot);
66
+ }
57
67
  // stale data found in L1 cache
58
68
  if (snapshot.state === 'Stale') {
59
69
  // kick off network request, do not await it
@@ -71,11 +81,15 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
71
81
  if (revivedSnapshot.state === 'Fulfilled' ||
72
82
  revivedSnapshot.state === 'Error') {
73
83
  // kick off network request, do not await it
74
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
84
+ buildNetworkSnapshot$1(buildSnapshotContext);
75
85
  // return the L2 cached snapshot to caller
76
86
  return revivedSnapshot;
77
87
  }
78
- if (revivedSnapshot.state === 'Pending') ;
88
+ if (revivedSnapshot.state === 'Pending') {
89
+ // kick off network request, do not await it
90
+ buildNetworkSnapshot$1(buildSnapshotContext);
91
+ return args.resolvePendingSnapshot(revivedSnapshot);
92
+ }
79
93
  // stale data found in L2 cache
80
94
  if (revivedSnapshot.state === 'Stale') {
81
95
  // kick off network request, do not await it
@@ -85,19 +99,18 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
85
99
  return revivedSnapshot;
86
100
  }
87
101
  // data not found in L2 cache, go to the network
88
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
102
+ return buildNetworkSnapshot(args);
89
103
  });
90
104
  }
91
- if (snapshot.state === 'Pending') ;
92
105
  }
93
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
106
+ return buildNetworkSnapshot(args);
94
107
  };
95
108
  }
96
109
 
97
110
  function buildCacheThenNetworkImplementation(funcs) {
98
111
  return function (args) {
99
112
  funcs.validateNotDisposed();
100
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
113
+ const { buildInMemorySnapshot, buildSnapshotContext, storeLookup } = args;
101
114
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
102
115
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
103
116
  if (snapshot !== undefined) {
@@ -105,7 +118,9 @@ function buildCacheThenNetworkImplementation(funcs) {
105
118
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
106
119
  return snapshot;
107
120
  }
108
- if (snapshot.state === 'Pending') ;
121
+ if (snapshot.state === 'Pending') {
122
+ return args.resolvePendingSnapshot(snapshot);
123
+ }
109
124
  // data not found in L1 cache, try L2 cache
110
125
  return funcs
111
126
  .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
@@ -115,24 +130,22 @@ function buildCacheThenNetworkImplementation(funcs) {
115
130
  revivedSnapshot.state === 'Error') {
116
131
  return revivedSnapshot;
117
132
  }
118
- if (revivedSnapshot.state === 'Pending') ;
133
+ if (revivedSnapshot.state === 'Pending') {
134
+ return args.resolvePendingSnapshot(revivedSnapshot);
135
+ }
119
136
  // data not found in L2 cache, go to the network
120
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
137
+ return buildNetworkSnapshot(args);
121
138
  });
122
139
  }
123
140
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
124
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
141
+ return buildNetworkSnapshot(args);
125
142
  };
126
143
  }
127
144
 
128
145
  function buildNoCacheImplementation(funcs) {
129
146
  return function (args) {
130
147
  funcs.validateNotDisposed();
131
- const { buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest } = args;
132
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest).then((snapshot) => {
133
- if (snapshot.state === 'Pending') ;
134
- return snapshot;
135
- });
148
+ return buildNetworkSnapshot(args);
136
149
  };
137
150
  }
138
151
 
@@ -206,7 +219,7 @@ function buildOnlyIfCachedImplementation(funcs) {
206
219
  function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
207
220
  return function (args) {
208
221
  funcs.validateNotDisposed();
209
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
222
+ const { buildInMemorySnapshot, buildSnapshotContext, storeLookup } = args;
210
223
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationSeconds * 1000));
211
224
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
212
225
  if (snapshot !== undefined) {
@@ -214,11 +227,13 @@ function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
214
227
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
215
228
  return snapshot;
216
229
  }
217
- if (snapshot.state === 'Pending') ;
230
+ if (snapshot.state === 'Pending') {
231
+ return args.resolvePendingSnapshot(snapshot);
232
+ }
218
233
  // stale data found in L1 cache
219
234
  if (snapshot.state === 'Stale') {
220
- // offline environment is already doing this; uncomment once we get rid of offline environment
221
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
235
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
236
+ // buildNetworkSnapshot(args);
222
237
  return snapshot;
223
238
  }
224
239
  // data not found in L1 cache, try L2 cache
@@ -230,19 +245,21 @@ function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
230
245
  revivedSnapshot.state === 'Error') {
231
246
  return revivedSnapshot;
232
247
  }
233
- if (revivedSnapshot.state === 'Pending') ;
248
+ if (revivedSnapshot.state === 'Pending') {
249
+ return args.resolvePendingSnapshot(revivedSnapshot);
250
+ }
234
251
  // stale data found in L2 cache
235
252
  if (revivedSnapshot.state === 'Stale') {
236
- // offline environment is already doing this; uncomment once we get rid of offline environment
237
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
253
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
254
+ // buildNetworkSnapshot(args);
238
255
  return revivedSnapshot;
239
256
  }
240
257
  // data not found in L2 cache, go to the network
241
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
258
+ return buildNetworkSnapshot(args);
242
259
  });
243
260
  }
244
261
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
245
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
262
+ return buildNetworkSnapshot(args);
246
263
  };
247
264
  }
248
265
 
@@ -780,7 +797,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
780
797
  if (ingestStagingStore === null) {
781
798
  ingestStagingStore = new Store();
782
799
  }
783
- return environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
800
+ environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
784
801
  };
785
802
  const storeIngestError = function (key, errorSnapshot, storeMetadataParams, _storeOverride) {
786
803
  validateNotDisposed();
@@ -973,14 +990,15 @@ function makeDurable(environment, { durableStore, instrumentation }) {
973
990
  const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
974
991
  validateNotDisposed();
975
992
  const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
993
+ const resolvePendingSnapshot = (snapshot) => environment.resolvePendingSnapshot(snapshot);
976
994
  const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
977
995
  const applyCachePolicy = () => {
978
996
  return cachePolicyImpl({
979
997
  buildInMemorySnapshot,
980
998
  buildNetworkSnapshot,
981
999
  buildSnapshotContext,
1000
+ resolvePendingSnapshot,
982
1001
  storeLookup,
983
- dispatchResourceRequest: environment.dispatchResourceRequest,
984
1002
  });
985
1003
  };
986
1004
  return isRevivingTTLOverrides !== undefined
@@ -3,5 +3,6 @@ export declare type DurableCachePolicyFunctions = {
3
3
  validateNotDisposed: () => void;
4
4
  reviveSnapshotWithCachePolicy: <D, V>(unavailableSnapshot: UnAvailableSnapshot<D, V>, storeLookup: StoreLookup<D, V>) => Promise<Snapshot<D, V>>;
5
5
  };
6
- export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
7
6
  export declare function appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<BuildInMemorySnapshot<C, D>>[1];
7
+ export declare function buildNetworkSnapshot<C, D>(args: CachePolicyImplementationArgs<C, D>): Promise<Snapshot<D, unknown>>;
8
+ export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@luvio/engine')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@luvio/engine'], factory) :
4
- (global = global || self, factory(global.luvioEnvironments = {}, global.luvioEngine));
5
- }(this, (function (exports, engine) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.luvioEnvironments = {}, global.luvioEngine));
5
+ })(this, (function (exports, engine) { 'use strict';
6
6
 
7
7
  function isDeprecatedDurableStoreEntry(durableRecord) {
8
8
  if (durableRecord.expiration !== undefined) {
@@ -11,6 +11,7 @@
11
11
  // Add more deprecated shape checks here
12
12
  return false;
13
13
  }
14
+ exports.DurableStoreOperationType = void 0;
14
15
  (function (DurableStoreOperationType) {
15
16
  DurableStoreOperationType["SetEntries"] = "setEntries";
16
17
  DurableStoreOperationType["EvictEntries"] = "evictEntries";
@@ -20,6 +21,13 @@
20
21
  const { keys, create, assign, freeze } = Object;
21
22
  const { isArray } = Array;
22
23
 
24
+ function appendTTLStrategy(storeLookup, ttlStrategy) {
25
+ return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
26
+ }
27
+ function buildNetworkSnapshot(args) {
28
+ const { buildNetworkSnapshot, buildSnapshotContext } = args;
29
+ return buildNetworkSnapshot(buildSnapshotContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
30
+ }
23
31
  function buildTTLStrategy(staleDurationMilliseconds = 0) {
24
32
  return (timestamp, metadata, valueIsError) => {
25
33
  if (metadata !== undefined) {
@@ -37,15 +45,12 @@
37
45
  }
38
46
  return engine.StoreResolveResultState.Found;
39
47
  };
40
- }
41
- function appendTTLStrategy(storeLookup, ttlStrategy) {
42
- return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
43
48
  }
44
49
 
45
50
  function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
46
51
  return function (args) {
47
52
  funcs.validateNotDisposed();
48
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
53
+ const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup } = args;
49
54
  const staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
50
55
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
51
56
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
@@ -53,10 +58,16 @@
53
58
  // data found in L1 cache
54
59
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
55
60
  // kick off network request, do not await it
56
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
61
+ buildNetworkSnapshot$1(buildSnapshotContext);
57
62
  // return the cached snapshot to caller
58
63
  return snapshot;
59
64
  }
65
+ // network request outstanding
66
+ if (snapshot.state === 'Pending') {
67
+ // kick off another network request, do not await it
68
+ buildNetworkSnapshot$1(buildSnapshotContext);
69
+ return args.resolvePendingSnapshot(snapshot);
70
+ }
60
71
  // stale data found in L1 cache
61
72
  if (snapshot.state === 'Stale') {
62
73
  // kick off network request, do not await it
@@ -74,11 +85,15 @@
74
85
  if (revivedSnapshot.state === 'Fulfilled' ||
75
86
  revivedSnapshot.state === 'Error') {
76
87
  // kick off network request, do not await it
77
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
88
+ buildNetworkSnapshot$1(buildSnapshotContext);
78
89
  // return the L2 cached snapshot to caller
79
90
  return revivedSnapshot;
80
91
  }
81
- if (revivedSnapshot.state === 'Pending') ;
92
+ if (revivedSnapshot.state === 'Pending') {
93
+ // kick off network request, do not await it
94
+ buildNetworkSnapshot$1(buildSnapshotContext);
95
+ return args.resolvePendingSnapshot(revivedSnapshot);
96
+ }
82
97
  // stale data found in L2 cache
83
98
  if (revivedSnapshot.state === 'Stale') {
84
99
  // kick off network request, do not await it
@@ -88,19 +103,18 @@
88
103
  return revivedSnapshot;
89
104
  }
90
105
  // data not found in L2 cache, go to the network
91
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
106
+ return buildNetworkSnapshot(args);
92
107
  });
93
108
  }
94
- if (snapshot.state === 'Pending') ;
95
109
  }
96
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
110
+ return buildNetworkSnapshot(args);
97
111
  };
98
112
  }
99
113
 
100
114
  function buildCacheThenNetworkImplementation(funcs) {
101
115
  return function (args) {
102
116
  funcs.validateNotDisposed();
103
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
117
+ const { buildInMemorySnapshot, buildSnapshotContext, storeLookup } = args;
104
118
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
105
119
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
106
120
  if (snapshot !== undefined) {
@@ -108,7 +122,9 @@
108
122
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
109
123
  return snapshot;
110
124
  }
111
- if (snapshot.state === 'Pending') ;
125
+ if (snapshot.state === 'Pending') {
126
+ return args.resolvePendingSnapshot(snapshot);
127
+ }
112
128
  // data not found in L1 cache, try L2 cache
113
129
  return funcs
114
130
  .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
@@ -118,24 +134,22 @@
118
134
  revivedSnapshot.state === 'Error') {
119
135
  return revivedSnapshot;
120
136
  }
121
- if (revivedSnapshot.state === 'Pending') ;
137
+ if (revivedSnapshot.state === 'Pending') {
138
+ return args.resolvePendingSnapshot(revivedSnapshot);
139
+ }
122
140
  // data not found in L2 cache, go to the network
123
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
141
+ return buildNetworkSnapshot(args);
124
142
  });
125
143
  }
126
144
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
127
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
145
+ return buildNetworkSnapshot(args);
128
146
  };
129
147
  }
130
148
 
131
149
  function buildNoCacheImplementation(funcs) {
132
150
  return function (args) {
133
151
  funcs.validateNotDisposed();
134
- const { buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest } = args;
135
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest).then((snapshot) => {
136
- if (snapshot.state === 'Pending') ;
137
- return snapshot;
138
- });
152
+ return buildNetworkSnapshot(args);
139
153
  };
140
154
  }
141
155
 
@@ -209,7 +223,7 @@
209
223
  function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
210
224
  return function (args) {
211
225
  funcs.validateNotDisposed();
212
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
226
+ const { buildInMemorySnapshot, buildSnapshotContext, storeLookup } = args;
213
227
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationSeconds * 1000));
214
228
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
215
229
  if (snapshot !== undefined) {
@@ -217,11 +231,13 @@
217
231
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
218
232
  return snapshot;
219
233
  }
220
- if (snapshot.state === 'Pending') ;
234
+ if (snapshot.state === 'Pending') {
235
+ return args.resolvePendingSnapshot(snapshot);
236
+ }
221
237
  // stale data found in L1 cache
222
238
  if (snapshot.state === 'Stale') {
223
- // offline environment is already doing this; uncomment once we get rid of offline environment
224
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
239
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
240
+ // buildNetworkSnapshot(args);
225
241
  return snapshot;
226
242
  }
227
243
  // data not found in L1 cache, try L2 cache
@@ -233,19 +249,21 @@
233
249
  revivedSnapshot.state === 'Error') {
234
250
  return revivedSnapshot;
235
251
  }
236
- if (revivedSnapshot.state === 'Pending') ;
252
+ if (revivedSnapshot.state === 'Pending') {
253
+ return args.resolvePendingSnapshot(revivedSnapshot);
254
+ }
237
255
  // stale data found in L2 cache
238
256
  if (revivedSnapshot.state === 'Stale') {
239
- // offline environment is already doing this; uncomment once we get rid of offline environment
240
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
257
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
258
+ // buildNetworkSnapshot(args);
241
259
  return revivedSnapshot;
242
260
  }
243
261
  // data not found in L2 cache, go to the network
244
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
262
+ return buildNetworkSnapshot(args);
245
263
  });
246
264
  }
247
265
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
248
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
266
+ return buildNetworkSnapshot(args);
249
267
  };
250
268
  }
251
269
 
@@ -783,7 +801,7 @@
783
801
  if (ingestStagingStore === null) {
784
802
  ingestStagingStore = new engine.Store();
785
803
  }
786
- return environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
804
+ environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
787
805
  };
788
806
  const storeIngestError = function (key, errorSnapshot, storeMetadataParams, _storeOverride) {
789
807
  validateNotDisposed();
@@ -976,14 +994,15 @@
976
994
  const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
977
995
  validateNotDisposed();
978
996
  const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
997
+ const resolvePendingSnapshot = (snapshot) => environment.resolvePendingSnapshot(snapshot);
979
998
  const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
980
999
  const applyCachePolicy = () => {
981
1000
  return cachePolicyImpl({
982
1001
  buildInMemorySnapshot,
983
1002
  buildNetworkSnapshot,
984
1003
  buildSnapshotContext,
1004
+ resolvePendingSnapshot,
985
1005
  storeLookup,
986
- dispatchResourceRequest: environment.dispatchResourceRequest,
987
1006
  });
988
1007
  };
989
1008
  return isRevivingTTLOverrides !== undefined
@@ -1100,4 +1119,4 @@
1100
1119
 
1101
1120
  Object.defineProperty(exports, '__esModule', { value: true });
1102
1121
 
1103
- })));
1122
+ }));
@@ -3,5 +3,6 @@ export declare type DurableCachePolicyFunctions = {
3
3
  validateNotDisposed: () => void;
4
4
  reviveSnapshotWithCachePolicy: <D, V>(unavailableSnapshot: UnAvailableSnapshot<D, V>, storeLookup: StoreLookup<D, V>) => Promise<Snapshot<D, V>>;
5
5
  };
6
- export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
7
6
  export declare function appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<BuildInMemorySnapshot<C, D>>[1];
7
+ export declare function buildNetworkSnapshot<C, D>(args: CachePolicyImplementationArgs<C, D>): Promise<Snapshot<D, unknown>>;
8
+ export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@luvio/engine')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@luvio/engine'], factory) :
4
- (global = global || self, factory(global.luvioEnvironments = {}, global.luvioEngine));
5
- }(this, (function (exports, engine) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.luvioEnvironments = {}, global.luvioEngine));
5
+ })(this, (function (exports, engine) { 'use strict';
6
6
 
7
7
  function isDeprecatedDurableStoreEntry(durableRecord) {
8
8
  if (durableRecord.expiration !== undefined) {
@@ -11,6 +11,7 @@
11
11
  // Add more deprecated shape checks here
12
12
  return false;
13
13
  }
14
+ exports.DurableStoreOperationType = void 0;
14
15
  (function (DurableStoreOperationType) {
15
16
  DurableStoreOperationType["SetEntries"] = "setEntries";
16
17
  DurableStoreOperationType["EvictEntries"] = "evictEntries";
@@ -54,6 +55,17 @@
54
55
  var keys = Object.keys, create = Object.create, assign = Object.assign, freeze = Object.freeze;
55
56
  var isArray = Array.isArray;
56
57
 
58
+ function appendTTLStrategy(storeLookup, ttlStrategy) {
59
+ return function (sel, refresh) {
60
+ return storeLookup(sel, refresh, ttlStrategy);
61
+ };
62
+ }
63
+ function buildNetworkSnapshot(args) {
64
+ var buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext;
65
+ return buildNetworkSnapshot(buildSnapshotContext).then(function (snapshot) {
66
+ return snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot;
67
+ });
68
+ }
57
69
  function buildTTLStrategy(staleDurationMilliseconds) {
58
70
  if (staleDurationMilliseconds === void 0) { staleDurationMilliseconds = 0; }
59
71
  return function (timestamp, metadata, valueIsError) {
@@ -72,17 +84,12 @@
72
84
  }
73
85
  return engine.StoreResolveResultState.Found;
74
86
  };
75
- }
76
- function appendTTLStrategy(storeLookup, ttlStrategy) {
77
- return function (sel, refresh) {
78
- return storeLookup(sel, refresh, ttlStrategy);
79
- };
80
87
  }
81
88
 
82
89
  function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
83
90
  return function (args) {
84
91
  funcs.validateNotDisposed();
85
- var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, dispatchResourceRequest = args.dispatchResourceRequest, storeLookup = args.storeLookup;
92
+ var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot$1 = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
86
93
  var staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
87
94
  var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
88
95
  var snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
@@ -90,10 +97,16 @@
90
97
  // data found in L1 cache
91
98
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
92
99
  // kick off network request, do not await it
93
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
100
+ buildNetworkSnapshot$1(buildSnapshotContext);
94
101
  // return the cached snapshot to caller
95
102
  return snapshot;
96
103
  }
104
+ // network request outstanding
105
+ if (snapshot.state === 'Pending') {
106
+ // kick off another network request, do not await it
107
+ buildNetworkSnapshot$1(buildSnapshotContext);
108
+ return args.resolvePendingSnapshot(snapshot);
109
+ }
97
110
  // stale data found in L1 cache
98
111
  if (snapshot.state === 'Stale') {
99
112
  // kick off network request, do not await it
@@ -111,11 +124,15 @@
111
124
  if (revivedSnapshot.state === 'Fulfilled' ||
112
125
  revivedSnapshot.state === 'Error') {
113
126
  // kick off network request, do not await it
114
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
127
+ buildNetworkSnapshot$1(buildSnapshotContext);
115
128
  // return the L2 cached snapshot to caller
116
129
  return revivedSnapshot;
117
130
  }
118
- if (revivedSnapshot.state === 'Pending') ;
131
+ if (revivedSnapshot.state === 'Pending') {
132
+ // kick off network request, do not await it
133
+ buildNetworkSnapshot$1(buildSnapshotContext);
134
+ return args.resolvePendingSnapshot(revivedSnapshot);
135
+ }
119
136
  // stale data found in L2 cache
120
137
  if (revivedSnapshot.state === 'Stale') {
121
138
  // kick off network request, do not await it
@@ -125,19 +142,18 @@
125
142
  return revivedSnapshot;
126
143
  }
127
144
  // data not found in L2 cache, go to the network
128
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
145
+ return buildNetworkSnapshot(args);
129
146
  });
130
147
  }
131
- if (snapshot.state === 'Pending') ;
132
148
  }
133
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
149
+ return buildNetworkSnapshot(args);
134
150
  };
135
151
  }
136
152
 
137
153
  function buildCacheThenNetworkImplementation(funcs) {
138
154
  return function (args) {
139
155
  funcs.validateNotDisposed();
140
- var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, dispatchResourceRequest = args.dispatchResourceRequest, storeLookup = args.storeLookup;
156
+ var buildInMemorySnapshot = args.buildInMemorySnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
141
157
  var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
142
158
  var snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
143
159
  if (snapshot !== undefined) {
@@ -145,7 +161,9 @@
145
161
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
146
162
  return snapshot;
147
163
  }
148
- if (snapshot.state === 'Pending') ;
164
+ if (snapshot.state === 'Pending') {
165
+ return args.resolvePendingSnapshot(snapshot);
166
+ }
149
167
  // data not found in L1 cache, try L2 cache
150
168
  return funcs
151
169
  .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
@@ -155,24 +173,22 @@
155
173
  revivedSnapshot.state === 'Error') {
156
174
  return revivedSnapshot;
157
175
  }
158
- if (revivedSnapshot.state === 'Pending') ;
176
+ if (revivedSnapshot.state === 'Pending') {
177
+ return args.resolvePendingSnapshot(revivedSnapshot);
178
+ }
159
179
  // data not found in L2 cache, go to the network
160
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
180
+ return buildNetworkSnapshot(args);
161
181
  });
162
182
  }
163
183
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
164
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
184
+ return buildNetworkSnapshot(args);
165
185
  };
166
186
  }
167
187
 
168
188
  function buildNoCacheImplementation(funcs) {
169
189
  return function (args) {
170
190
  funcs.validateNotDisposed();
171
- var buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, dispatchResourceRequest = args.dispatchResourceRequest;
172
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest).then(function (snapshot) {
173
- if (snapshot.state === 'Pending') ;
174
- return snapshot;
175
- });
191
+ return buildNetworkSnapshot(args);
176
192
  };
177
193
  }
178
194
 
@@ -246,7 +262,7 @@
246
262
  function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
247
263
  return function (args) {
248
264
  funcs.validateNotDisposed();
249
- var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, dispatchResourceRequest = args.dispatchResourceRequest, storeLookup = args.storeLookup;
265
+ var buildInMemorySnapshot = args.buildInMemorySnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
250
266
  var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationSeconds * 1000));
251
267
  var snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
252
268
  if (snapshot !== undefined) {
@@ -254,11 +270,13 @@
254
270
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
255
271
  return snapshot;
256
272
  }
257
- if (snapshot.state === 'Pending') ;
273
+ if (snapshot.state === 'Pending') {
274
+ return args.resolvePendingSnapshot(snapshot);
275
+ }
258
276
  // stale data found in L1 cache
259
277
  if (snapshot.state === 'Stale') {
260
- // offline environment is already doing this; uncomment once we get rid of offline environment
261
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
278
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
279
+ // buildNetworkSnapshot(args);
262
280
  return snapshot;
263
281
  }
264
282
  // data not found in L1 cache, try L2 cache
@@ -270,19 +288,21 @@
270
288
  revivedSnapshot.state === 'Error') {
271
289
  return revivedSnapshot;
272
290
  }
273
- if (revivedSnapshot.state === 'Pending') ;
291
+ if (revivedSnapshot.state === 'Pending') {
292
+ return args.resolvePendingSnapshot(revivedSnapshot);
293
+ }
274
294
  // stale data found in L2 cache
275
295
  if (revivedSnapshot.state === 'Stale') {
276
- // offline environment is already doing this; uncomment once we get rid of offline environment
277
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
296
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
297
+ // buildNetworkSnapshot(args);
278
298
  return revivedSnapshot;
279
299
  }
280
300
  // data not found in L2 cache, go to the network
281
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
301
+ return buildNetworkSnapshot(args);
282
302
  });
283
303
  }
284
304
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
285
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
305
+ return buildNetworkSnapshot(args);
286
306
  };
287
307
  }
288
308
 
@@ -821,7 +841,7 @@
821
841
  if (ingestStagingStore === null) {
822
842
  ingestStagingStore = new engine.Store();
823
843
  }
824
- return environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
844
+ environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
825
845
  };
826
846
  var storeIngestError = function (key, errorSnapshot, storeMetadataParams, _storeOverride) {
827
847
  validateNotDisposed();
@@ -1017,14 +1037,17 @@
1017
1037
  var applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
1018
1038
  validateNotDisposed();
1019
1039
  var cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
1040
+ var resolvePendingSnapshot = function (snapshot) {
1041
+ return environment.resolvePendingSnapshot(snapshot);
1042
+ };
1020
1043
  var storeLookup = function (sel, refresh, ttlStrategy) { return environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy); };
1021
1044
  var applyCachePolicy = function () {
1022
1045
  return cachePolicyImpl({
1023
1046
  buildInMemorySnapshot: buildInMemorySnapshot,
1024
1047
  buildNetworkSnapshot: buildNetworkSnapshot,
1025
1048
  buildSnapshotContext: buildSnapshotContext,
1049
+ resolvePendingSnapshot: resolvePendingSnapshot,
1026
1050
  storeLookup: storeLookup,
1027
- dispatchResourceRequest: environment.dispatchResourceRequest,
1028
1051
  });
1029
1052
  };
1030
1053
  return isRevivingTTLOverrides !== undefined
@@ -1140,4 +1163,4 @@
1140
1163
 
1141
1164
  Object.defineProperty(exports, '__esModule', { value: true });
1142
1165
 
1143
- })));
1166
+ }));
@@ -3,5 +3,6 @@ export declare type DurableCachePolicyFunctions = {
3
3
  validateNotDisposed: () => void;
4
4
  reviveSnapshotWithCachePolicy: <D, V>(unavailableSnapshot: UnAvailableSnapshot<D, V>, storeLookup: StoreLookup<D, V>) => Promise<Snapshot<D, V>>;
5
5
  };
6
- export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
7
6
  export declare function appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<BuildInMemorySnapshot<C, D>>[1];
7
+ export declare function buildNetworkSnapshot<C, D>(args: CachePolicyImplementationArgs<C, D>): Promise<Snapshot<D, unknown>>;
8
+ export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/environments",
3
- "version": "0.62.2",
3
+ "version": "0.63.1",
4
4
  "description": "Luvio Environments",
5
5
  "main": "dist/umd/es2018/environments.js",
6
6
  "module": "dist/es/es2018/environments.js",
@@ -17,6 +17,6 @@
17
17
  "dist/"
18
18
  ],
19
19
  "dependencies": {
20
- "@luvio/engine": "0.62.2"
20
+ "@luvio/engine": "0.63.1"
21
21
  }
22
22
  }