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