@luvio/environments 0.68.0 → 0.72.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/DurableStore.d.ts +0 -1
- package/dist/es/es2018/environments.js +166 -165
- package/dist/es/es2018/makeDurable/cachepolicies/utils.d.ts +3 -2
- package/dist/umd/es2018/DurableStore.d.ts +0 -1
- package/dist/umd/es2018/environments.js +166 -165
- package/dist/umd/es2018/makeDurable/cachepolicies/utils.d.ts +3 -2
- package/dist/umd/es5/DurableStore.d.ts +0 -1
- package/dist/umd/es5/environments.js +166 -164
- package/dist/umd/es5/makeDurable/cachepolicies/utils.d.ts +3 -2
- package/package.json +2 -2
|
@@ -18,7 +18,11 @@ const { keys, create, assign, freeze } = Object;
|
|
|
18
18
|
const { isArray } = Array;
|
|
19
19
|
|
|
20
20
|
function appendTTLStrategy(storeLookup, ttlStrategy) {
|
|
21
|
-
|
|
21
|
+
const returnStoreLookup = (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
|
|
22
|
+
// append ttlStrategy to storeLookup function (in cases where custom adapter
|
|
23
|
+
// wants to perform it's own lookup)
|
|
24
|
+
returnStoreLookup.ttlStrategy = ttlStrategy;
|
|
25
|
+
return returnStoreLookup;
|
|
22
26
|
}
|
|
23
27
|
function buildNetworkSnapshot(args) {
|
|
24
28
|
const { buildNetworkSnapshot, buildSnapshotContext, coercedAdapterRequestContext } = args;
|
|
@@ -41,102 +45,112 @@ function buildTTLStrategy(staleDurationMilliseconds = 0) {
|
|
|
41
45
|
}
|
|
42
46
|
return StoreResolveResultState.Found;
|
|
43
47
|
};
|
|
48
|
+
}
|
|
49
|
+
// TODO - update userland-facing APIs to return `AvailableSnapshot` instead of `Snapshot`
|
|
50
|
+
// and then the signatures here can be updated as well
|
|
51
|
+
function buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, availableSnapshotFunc) {
|
|
52
|
+
if (isPromise(cachedSnapshot)) {
|
|
53
|
+
return cachedSnapshot.then(availableSnapshotFunc);
|
|
54
|
+
}
|
|
55
|
+
return availableSnapshotFunc(cachedSnapshot);
|
|
56
|
+
}
|
|
57
|
+
function isPromise(value) {
|
|
58
|
+
if (value === undefined) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
// check for Thenable due to test frameworks using custom Promise impls
|
|
62
|
+
return value.then !== undefined;
|
|
44
63
|
}
|
|
45
64
|
|
|
46
|
-
function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
|
|
65
|
+
function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds = 0) {
|
|
47
66
|
return function (args) {
|
|
48
67
|
funcs.validateNotDisposed();
|
|
49
|
-
const {
|
|
50
|
-
const staleDurationMilliseconds = staleDurationSeconds
|
|
68
|
+
const { buildCachedSnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup, coercedAdapterRequestContext, } = args;
|
|
69
|
+
const staleDurationMilliseconds = staleDurationSeconds * 1000;
|
|
51
70
|
const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return args
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (revivedSnapshot.state === 'Stale') {
|
|
94
|
-
// kick off network request, do not await it
|
|
95
|
-
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
96
|
-
// return the L2 cached snapshot to caller
|
|
97
|
-
return revivedSnapshot;
|
|
98
|
-
}
|
|
99
|
-
// data not found in L2 cache, go to the network
|
|
100
|
-
return buildNetworkSnapshot(args);
|
|
101
|
-
});
|
|
71
|
+
const cachedSnapshot = buildCachedSnapshot(buildSnapshotContext, cachePolicyStoreLookup);
|
|
72
|
+
return buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, (snapshot) => {
|
|
73
|
+
if (snapshot !== undefined) {
|
|
74
|
+
// data found in L1 cache
|
|
75
|
+
if (snapshot.state === 'Fulfilled' ||
|
|
76
|
+
snapshot.state === 'Error' ||
|
|
77
|
+
snapshot.state === 'Stale') {
|
|
78
|
+
// kick off network request, do not await it
|
|
79
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
80
|
+
// return the cached snapshot to caller
|
|
81
|
+
return snapshot;
|
|
82
|
+
}
|
|
83
|
+
// network request outstanding
|
|
84
|
+
if (snapshot.state === 'Pending') {
|
|
85
|
+
// kick off another network request, do not await it
|
|
86
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
87
|
+
return args.resolvePendingSnapshot(snapshot);
|
|
88
|
+
}
|
|
89
|
+
// if unfulfilled we have enough info to do an L2 lookup
|
|
90
|
+
if (snapshot.state === 'Unfulfilled') {
|
|
91
|
+
return funcs
|
|
92
|
+
.reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
|
|
93
|
+
.then((revivedSnapshot) => {
|
|
94
|
+
// data found in L2 cache
|
|
95
|
+
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
96
|
+
revivedSnapshot.state === 'Error' ||
|
|
97
|
+
revivedSnapshot.state === 'Stale') {
|
|
98
|
+
// kick off network request, do not await it
|
|
99
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
100
|
+
// return the L2 cached snapshot to caller
|
|
101
|
+
return revivedSnapshot;
|
|
102
|
+
}
|
|
103
|
+
if (revivedSnapshot.state === 'Pending') {
|
|
104
|
+
// kick off network request, do not await it
|
|
105
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
106
|
+
return args.resolvePendingSnapshot(revivedSnapshot);
|
|
107
|
+
}
|
|
108
|
+
// data not found in L2 cache, go to the network
|
|
109
|
+
return buildNetworkSnapshot(args);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
102
112
|
}
|
|
103
|
-
|
|
104
|
-
|
|
113
|
+
return buildNetworkSnapshot(args);
|
|
114
|
+
});
|
|
105
115
|
};
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
function buildCacheThenNetworkImplementation(funcs) {
|
|
109
119
|
return function (args) {
|
|
110
120
|
funcs.validateNotDisposed();
|
|
111
|
-
const {
|
|
121
|
+
const { buildCachedSnapshot, buildSnapshotContext, storeLookup } = args;
|
|
112
122
|
const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (snapshot.state === 'Pending') {
|
|
120
|
-
return args.resolvePendingSnapshot(snapshot);
|
|
121
|
-
}
|
|
122
|
-
// data not found in L1 cache, try L2 cache
|
|
123
|
-
return funcs
|
|
124
|
-
.reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
|
|
125
|
-
.then((revivedSnapshot) => {
|
|
126
|
-
// data found in L2 cache
|
|
127
|
-
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
128
|
-
revivedSnapshot.state === 'Error') {
|
|
129
|
-
return revivedSnapshot;
|
|
123
|
+
const cachedSnapshot = buildCachedSnapshot(buildSnapshotContext, cachePolicyStoreLookup);
|
|
124
|
+
return buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, (snapshot) => {
|
|
125
|
+
if (snapshot !== undefined) {
|
|
126
|
+
// data found in L1 cache
|
|
127
|
+
if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
|
|
128
|
+
return snapshot;
|
|
130
129
|
}
|
|
131
|
-
if (
|
|
132
|
-
return args.resolvePendingSnapshot(
|
|
130
|
+
if (snapshot.state === 'Pending') {
|
|
131
|
+
return args.resolvePendingSnapshot(snapshot);
|
|
133
132
|
}
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
// if unfulfilled we have enough info to do an L2 lookup
|
|
134
|
+
if (snapshot.state === 'Unfulfilled') {
|
|
135
|
+
return funcs
|
|
136
|
+
.reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
|
|
137
|
+
.then((revivedSnapshot) => {
|
|
138
|
+
// data found in L2 cache
|
|
139
|
+
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
140
|
+
revivedSnapshot.state === 'Error') {
|
|
141
|
+
return revivedSnapshot;
|
|
142
|
+
}
|
|
143
|
+
if (revivedSnapshot.state === 'Pending') {
|
|
144
|
+
return args.resolvePendingSnapshot(revivedSnapshot);
|
|
145
|
+
}
|
|
146
|
+
// data not found in L2 cache, go to the network
|
|
147
|
+
return buildNetworkSnapshot(args);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// L1 lookup could not find enough information to even construct a snapshot, go to the network
|
|
152
|
+
return buildNetworkSnapshot(args);
|
|
153
|
+
});
|
|
140
154
|
};
|
|
141
155
|
}
|
|
142
156
|
|
|
@@ -180,84 +194,90 @@ function buildNotCachedErrorSnapshot() {
|
|
|
180
194
|
error,
|
|
181
195
|
state: 'Error',
|
|
182
196
|
data: undefined,
|
|
183
|
-
// TODO[@W-10164067]: copy refresh data from the snapshot returned by
|
|
197
|
+
// TODO[@W-10164067]: copy refresh data from the snapshot returned by buildCachedSnapshot (if any)
|
|
184
198
|
// refresh: ...
|
|
185
199
|
};
|
|
186
200
|
}
|
|
187
201
|
function buildOnlyIfCachedImplementation(funcs) {
|
|
188
202
|
return function (args) {
|
|
189
203
|
funcs.validateNotDisposed();
|
|
190
|
-
const {
|
|
204
|
+
const { buildCachedSnapshot, buildSnapshotContext, storeLookup } = args;
|
|
191
205
|
const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
// network request outstanding, data is not cached
|
|
199
|
-
if (snapshot.state === 'Pending') {
|
|
200
|
-
return buildNotCachedErrorSnapshot();
|
|
201
|
-
}
|
|
202
|
-
// data not found in L1 cache, try L2 cache
|
|
203
|
-
return funcs
|
|
204
|
-
.reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
|
|
205
|
-
.then((revivedSnapshot) => {
|
|
206
|
-
// data found in L2 cache
|
|
207
|
-
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
208
|
-
revivedSnapshot.state === 'Error') {
|
|
209
|
-
return revivedSnapshot;
|
|
206
|
+
const cachedSnapshot = buildCachedSnapshot(buildSnapshotContext, cachePolicyStoreLookup);
|
|
207
|
+
return buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, (snapshot) => {
|
|
208
|
+
if (snapshot !== undefined) {
|
|
209
|
+
// data found in L1 cache
|
|
210
|
+
if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
|
|
211
|
+
return snapshot;
|
|
210
212
|
}
|
|
211
|
-
// data is not cached
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
// network request outstanding, data is not cached
|
|
214
|
+
if (snapshot.state === 'Pending') {
|
|
215
|
+
return buildNotCachedErrorSnapshot();
|
|
216
|
+
}
|
|
217
|
+
// if unfulfilled we have enough info to do an L2 lookup
|
|
218
|
+
if (snapshot.state === 'Unfulfilled') {
|
|
219
|
+
return funcs
|
|
220
|
+
.reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
|
|
221
|
+
.then((revivedSnapshot) => {
|
|
222
|
+
// data found in L2 cache
|
|
223
|
+
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
224
|
+
revivedSnapshot.state === 'Error') {
|
|
225
|
+
return revivedSnapshot;
|
|
226
|
+
}
|
|
227
|
+
// data is not cached
|
|
228
|
+
return buildNotCachedErrorSnapshot();
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return buildNotCachedErrorSnapshot();
|
|
233
|
+
});
|
|
216
234
|
};
|
|
217
235
|
}
|
|
218
236
|
|
|
219
237
|
function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
|
|
220
238
|
return function (args) {
|
|
221
239
|
funcs.validateNotDisposed();
|
|
222
|
-
const {
|
|
240
|
+
const { buildCachedSnapshot, buildSnapshotContext, storeLookup } = args;
|
|
223
241
|
const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationSeconds * 1000));
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (snapshot.state === 'Pending') {
|
|
231
|
-
return args.resolvePendingSnapshot(snapshot);
|
|
232
|
-
}
|
|
233
|
-
// stale data found in L1 cache
|
|
234
|
-
if (snapshot.state === 'Stale') {
|
|
235
|
-
buildNetworkSnapshot(args);
|
|
236
|
-
return snapshot;
|
|
237
|
-
}
|
|
238
|
-
// data not found in L1 cache, try L2 cache
|
|
239
|
-
return funcs
|
|
240
|
-
.reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
|
|
241
|
-
.then((revivedSnapshot) => {
|
|
242
|
-
// data found in L2 cache
|
|
243
|
-
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
244
|
-
revivedSnapshot.state === 'Error') {
|
|
245
|
-
return revivedSnapshot;
|
|
242
|
+
const cachedSnapshot = buildCachedSnapshot(buildSnapshotContext, cachePolicyStoreLookup);
|
|
243
|
+
return buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, (snapshot) => {
|
|
244
|
+
if (snapshot !== undefined) {
|
|
245
|
+
// data found in L1 cache
|
|
246
|
+
if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
|
|
247
|
+
return snapshot;
|
|
246
248
|
}
|
|
247
|
-
if (
|
|
248
|
-
return args.resolvePendingSnapshot(
|
|
249
|
+
if (snapshot.state === 'Pending') {
|
|
250
|
+
return args.resolvePendingSnapshot(snapshot);
|
|
249
251
|
}
|
|
250
|
-
// stale data found in
|
|
251
|
-
if (
|
|
252
|
+
// stale data found in L1 cache
|
|
253
|
+
if (snapshot.state === 'Stale') {
|
|
252
254
|
buildNetworkSnapshot(args);
|
|
253
|
-
return
|
|
255
|
+
return snapshot;
|
|
254
256
|
}
|
|
255
|
-
// data not found in
|
|
256
|
-
return
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
// data not found in L1 cache, try L2 cache
|
|
258
|
+
return funcs
|
|
259
|
+
.reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
|
|
260
|
+
.then((revivedSnapshot) => {
|
|
261
|
+
// data found in L2 cache
|
|
262
|
+
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
263
|
+
revivedSnapshot.state === 'Error') {
|
|
264
|
+
return revivedSnapshot;
|
|
265
|
+
}
|
|
266
|
+
if (revivedSnapshot.state === 'Pending') {
|
|
267
|
+
return args.resolvePendingSnapshot(revivedSnapshot);
|
|
268
|
+
}
|
|
269
|
+
// stale data found in L2 cache
|
|
270
|
+
if (revivedSnapshot.state === 'Stale') {
|
|
271
|
+
buildNetworkSnapshot(args);
|
|
272
|
+
return revivedSnapshot;
|
|
273
|
+
}
|
|
274
|
+
// data not found in L2 cache, go to the network
|
|
275
|
+
return buildNetworkSnapshot(args);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
// L1 lookup could not find enough information to even construct a snapshot, go to the network
|
|
279
|
+
return buildNetworkSnapshot(args);
|
|
280
|
+
});
|
|
261
281
|
};
|
|
262
282
|
}
|
|
263
283
|
|
|
@@ -268,7 +288,7 @@ function buildValidAtImplementation(funcs, basePolicyImplementation, timestamp)
|
|
|
268
288
|
// TTLStrategy to use the the valid-at cache policy's timestamp. The flow goes:
|
|
269
289
|
//
|
|
270
290
|
// Environment.applyCachePolicy => validAtImplementation (this function) =>
|
|
271
|
-
// basePolicyImplementation => adapter's
|
|
291
|
+
// basePolicyImplementation => adapter's buildCachedSnapshot =>
|
|
272
292
|
// basePolicyImplementation's storeLookup => validAtStoreLookup (below) =>
|
|
273
293
|
// Environment.applyCachePolicy's storeLookup => Store/Reader code =>
|
|
274
294
|
// valid-at TTLStrategy (below) =>
|
|
@@ -375,9 +395,6 @@ function isStoreEntryError(storeRecord) {
|
|
|
375
395
|
return storeRecord.__type === 'error';
|
|
376
396
|
}
|
|
377
397
|
|
|
378
|
-
function isStoreEntryExpiredAndError(storeRecord, expirationTimestamp, now) {
|
|
379
|
-
return isStoreEntryError(storeRecord) && expirationTimestamp < now;
|
|
380
|
-
}
|
|
381
398
|
/**
|
|
382
399
|
* Takes a set of entries from DurableStore and publishes them via the passed in funcs.
|
|
383
400
|
* This respects expiration and checks for valid DurableStore data shapes. This should
|
|
@@ -400,7 +417,6 @@ function publishDurableStoreEntries(durableRecords, publish, publishMetadata) {
|
|
|
400
417
|
// no records to revive
|
|
401
418
|
return { revivedKeys, hadUnexpectedShape };
|
|
402
419
|
}
|
|
403
|
-
const now = Date.now();
|
|
404
420
|
for (let i = 0, len = durableKeys.length; i < len; i += 1) {
|
|
405
421
|
const key = durableKeys[i];
|
|
406
422
|
const durableRecord = durableRecords[key];
|
|
@@ -416,27 +432,12 @@ function publishDurableStoreEntries(durableRecords, publish, publishMetadata) {
|
|
|
416
432
|
continue;
|
|
417
433
|
}
|
|
418
434
|
if (metadata !== undefined) {
|
|
419
|
-
const { expirationTimestamp
|
|
435
|
+
const { expirationTimestamp } = metadata;
|
|
420
436
|
if (expirationTimestamp === undefined) {
|
|
421
437
|
// if unexpected expiration data skip reviving
|
|
422
438
|
hadUnexpectedShape = true;
|
|
423
439
|
continue;
|
|
424
440
|
}
|
|
425
|
-
// if past stale TTL then don't revive
|
|
426
|
-
if (staleTimestamp !== undefined && staleTimestamp < now) {
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
// We don't want to revive a cached value if it's an error and it's
|
|
430
|
-
// expirationTimestamp TTL is expired, otherwise we would never hit the network
|
|
431
|
-
// during resolveSnapshot or rebuildSnapshot because the way the Reader works.
|
|
432
|
-
// If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
|
|
433
|
-
// if stale TTL is expired. But it will return ErrorSnapshot (instead of
|
|
434
|
-
// StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
|
|
435
|
-
// In our environment the stale TTL is maxed out so Reader will always
|
|
436
|
-
// return ErrorSnapshot.
|
|
437
|
-
if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
441
|
publishMetadata(key, metadata);
|
|
441
442
|
}
|
|
442
443
|
if (isStoreEntryError(data)) {
|
|
@@ -827,7 +828,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
827
828
|
if (ingestStagingStore !== null) {
|
|
828
829
|
return ingestStagingStore.lookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
829
830
|
}
|
|
830
|
-
// otherwise this is from
|
|
831
|
+
// otherwise this is from buildCachedSnapshot and we should use the luvio
|
|
831
832
|
// L1 store
|
|
832
833
|
return environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
833
834
|
};
|
|
@@ -988,7 +989,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
988
989
|
}
|
|
989
990
|
}
|
|
990
991
|
}
|
|
991
|
-
const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext,
|
|
992
|
+
const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot) {
|
|
992
993
|
validateNotDisposed();
|
|
993
994
|
const { cachePolicy } = adapterRequestContext;
|
|
994
995
|
const cachePolicyImpl = resolveCachePolicy(cachePolicy);
|
|
@@ -996,7 +997,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
996
997
|
const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
|
|
997
998
|
const applyCachePolicy = () => {
|
|
998
999
|
return cachePolicyImpl({
|
|
999
|
-
|
|
1000
|
+
buildCachedSnapshot,
|
|
1000
1001
|
buildNetworkSnapshot,
|
|
1001
1002
|
buildSnapshotContext,
|
|
1002
1003
|
resolvePendingSnapshot,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BuildCachedSnapshot, CachePolicyImplementationArgs, Snapshot, StoreLookup, TTLStrategy, UnAvailableSnapshot } from '@luvio/engine';
|
|
2
2
|
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 appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<
|
|
6
|
+
export declare function appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<BuildCachedSnapshot<C, D>>[1];
|
|
7
7
|
export declare function buildNetworkSnapshot<C, D>(args: CachePolicyImplementationArgs<C, D>): Promise<Snapshot<D, unknown>>;
|
|
8
8
|
export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
|
|
9
|
+
export declare function buildAvailableSnapshotFromCachedSnapshotResponse<C, D>(cachedSnapshot: ReturnType<BuildCachedSnapshot<C, D>>, availableSnapshotFunc: (snapshot: Snapshot<D> | undefined) => Snapshot<D> | Promise<Snapshot<D>>): Snapshot<D> | Promise<Snapshot<D>>;
|