@luvio/environments 0.63.3 → 0.67.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 +19 -71
- package/dist/es/es2018/main.d.ts +0 -1
- package/dist/umd/es2018/environments.js +17 -70
- package/dist/umd/es2018/main.d.ts +0 -1
- package/dist/umd/es5/environments.js +17 -67
- package/dist/umd/es5/main.d.ts +0 -1
- package/package.json +11 -2
- package/dist/es/es2018/makeOffline.d.ts +0 -13
- package/dist/umd/es2018/makeOffline.d.ts +0 -13
- package/dist/umd/es5/makeOffline.d.ts +0 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StoreResolveResultState, HttpStatusCode, Store,
|
|
1
|
+
import { StoreResolveResultState, HttpStatusCode, Store, coerceAdapterRequestContext } from '@luvio/engine';
|
|
2
2
|
|
|
3
3
|
function isDeprecatedDurableStoreEntry(durableRecord) {
|
|
4
4
|
if (durableRecord.expiration !== undefined) {
|
|
@@ -21,8 +21,8 @@ function appendTTLStrategy(storeLookup, ttlStrategy) {
|
|
|
21
21
|
return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
|
|
22
22
|
}
|
|
23
23
|
function buildNetworkSnapshot(args) {
|
|
24
|
-
const { buildNetworkSnapshot, buildSnapshotContext } = args;
|
|
25
|
-
return buildNetworkSnapshot(buildSnapshotContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
|
|
24
|
+
const { buildNetworkSnapshot, buildSnapshotContext, coercedAdapterRequestContext } = args;
|
|
25
|
+
return buildNetworkSnapshot(buildSnapshotContext, coercedAdapterRequestContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
|
|
26
26
|
}
|
|
27
27
|
function buildTTLStrategy(staleDurationMilliseconds = 0) {
|
|
28
28
|
return (timestamp, metadata, valueIsError) => {
|
|
@@ -46,7 +46,7 @@ function buildTTLStrategy(staleDurationMilliseconds = 0) {
|
|
|
46
46
|
function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
|
|
47
47
|
return function (args) {
|
|
48
48
|
funcs.validateNotDisposed();
|
|
49
|
-
const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup } = args;
|
|
49
|
+
const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup, coercedAdapterRequestContext, } = args;
|
|
50
50
|
const staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
|
|
51
51
|
const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
|
|
52
52
|
const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
|
|
@@ -54,21 +54,20 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
|
|
|
54
54
|
// data found in L1 cache
|
|
55
55
|
if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
|
|
56
56
|
// kick off network request, do not await it
|
|
57
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
57
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
58
58
|
// return the cached snapshot to caller
|
|
59
59
|
return snapshot;
|
|
60
60
|
}
|
|
61
61
|
// network request outstanding
|
|
62
62
|
if (snapshot.state === 'Pending') {
|
|
63
63
|
// kick off another network request, do not await it
|
|
64
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
64
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
65
65
|
return args.resolvePendingSnapshot(snapshot);
|
|
66
66
|
}
|
|
67
67
|
// stale data found in L1 cache
|
|
68
68
|
if (snapshot.state === 'Stale') {
|
|
69
69
|
// kick off network request, do not await it
|
|
70
|
-
|
|
71
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
70
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
72
71
|
// return the cached snapshot to caller
|
|
73
72
|
return snapshot;
|
|
74
73
|
}
|
|
@@ -81,20 +80,19 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
|
|
|
81
80
|
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
82
81
|
revivedSnapshot.state === 'Error') {
|
|
83
82
|
// kick off network request, do not await it
|
|
84
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
83
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
85
84
|
// return the L2 cached snapshot to caller
|
|
86
85
|
return revivedSnapshot;
|
|
87
86
|
}
|
|
88
87
|
if (revivedSnapshot.state === 'Pending') {
|
|
89
88
|
// kick off network request, do not await it
|
|
90
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
89
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
91
90
|
return args.resolvePendingSnapshot(revivedSnapshot);
|
|
92
91
|
}
|
|
93
92
|
// stale data found in L2 cache
|
|
94
93
|
if (revivedSnapshot.state === 'Stale') {
|
|
95
94
|
// kick off network request, do not await it
|
|
96
|
-
|
|
97
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
95
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
98
96
|
// return the L2 cached snapshot to caller
|
|
99
97
|
return revivedSnapshot;
|
|
100
98
|
}
|
|
@@ -234,8 +232,7 @@ function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
|
|
|
234
232
|
}
|
|
235
233
|
// stale data found in L1 cache
|
|
236
234
|
if (snapshot.state === 'Stale') {
|
|
237
|
-
|
|
238
|
-
// buildNetworkSnapshot(args);
|
|
235
|
+
buildNetworkSnapshot(args);
|
|
239
236
|
return snapshot;
|
|
240
237
|
}
|
|
241
238
|
// data not found in L1 cache, try L2 cache
|
|
@@ -252,8 +249,7 @@ function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
|
|
|
252
249
|
}
|
|
253
250
|
// stale data found in L2 cache
|
|
254
251
|
if (revivedSnapshot.state === 'Stale') {
|
|
255
|
-
|
|
256
|
-
// buildNetworkSnapshot(args);
|
|
252
|
+
buildNetworkSnapshot(args);
|
|
257
253
|
return revivedSnapshot;
|
|
258
254
|
}
|
|
259
255
|
// data not found in L2 cache, go to the network
|
|
@@ -432,13 +428,12 @@ function publishDurableStoreEntries(durableRecords, publish, publishMetadata) {
|
|
|
432
428
|
}
|
|
433
429
|
// We don't want to revive a cached value if it's an error and it's
|
|
434
430
|
// expirationTimestamp TTL is expired, otherwise we would never hit the network
|
|
435
|
-
// during resolveSnapshot or rebuildSnapshot
|
|
436
|
-
// environment because the way the Reader works.
|
|
431
|
+
// during resolveSnapshot or rebuildSnapshot because the way the Reader works.
|
|
437
432
|
// If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
|
|
438
433
|
// if stale TTL is expired. But it will return ErrorSnapshot (instead of
|
|
439
434
|
// StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
|
|
440
|
-
// In
|
|
441
|
-
//
|
|
435
|
+
// In our environment the stale TTL is maxed out so Reader will always
|
|
436
|
+
// return ErrorSnapshot.
|
|
442
437
|
if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
|
|
443
438
|
continue;
|
|
444
439
|
}
|
|
@@ -995,7 +990,8 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
995
990
|
}
|
|
996
991
|
const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
|
|
997
992
|
validateNotDisposed();
|
|
998
|
-
const
|
|
993
|
+
const { cachePolicy } = adapterRequestContext;
|
|
994
|
+
const cachePolicyImpl = resolveCachePolicy(cachePolicy);
|
|
999
995
|
const resolvePendingSnapshot = (snapshot) => environment.resolvePendingSnapshot(snapshot);
|
|
1000
996
|
const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
|
|
1001
997
|
const applyCachePolicy = () => {
|
|
@@ -1005,6 +1001,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
1005
1001
|
buildSnapshotContext,
|
|
1006
1002
|
resolvePendingSnapshot,
|
|
1007
1003
|
storeLookup,
|
|
1004
|
+
coercedAdapterRequestContext: coerceAdapterRequestContext(adapterRequestContext),
|
|
1008
1005
|
});
|
|
1009
1006
|
};
|
|
1010
1007
|
return isRevivingTTLOverrides !== undefined
|
|
@@ -1065,53 +1062,4 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
1065
1062
|
});
|
|
1066
1063
|
}
|
|
1067
1064
|
|
|
1068
|
-
|
|
1069
|
-
* This environment allows for stale snapshot emits.
|
|
1070
|
-
*
|
|
1071
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
1072
|
-
* emitted is the result of a storeLookup.
|
|
1073
|
-
*
|
|
1074
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
1075
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
1076
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
1077
|
-
* cause a network refresh to happen).
|
|
1078
|
-
*/
|
|
1079
|
-
function makeOffline(environment) {
|
|
1080
|
-
const storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
|
|
1081
|
-
const snapshot = environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
1082
|
-
// if the snapshot is stale we want to kick off a refresh
|
|
1083
|
-
if (snapshot.state === 'Stale') {
|
|
1084
|
-
if (refresh !== undefined) {
|
|
1085
|
-
const { resolve, config } = refresh;
|
|
1086
|
-
resolve(config);
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
return snapshot;
|
|
1090
|
-
};
|
|
1091
|
-
const snapshotAvailable = function (snapshot) {
|
|
1092
|
-
if (snapshot.state === 'Stale') {
|
|
1093
|
-
return true;
|
|
1094
|
-
}
|
|
1095
|
-
return environment.snapshotAvailable(snapshot);
|
|
1096
|
-
};
|
|
1097
|
-
const publishStoreMetadata = function (recordId, storeMetadata) {
|
|
1098
|
-
environment.publishStoreMetadata(recordId, {
|
|
1099
|
-
...storeMetadata,
|
|
1100
|
-
staleTimestamp: Number.MAX_SAFE_INTEGER,
|
|
1101
|
-
});
|
|
1102
|
-
};
|
|
1103
|
-
return create(environment, {
|
|
1104
|
-
defaultCachePolicy: {
|
|
1105
|
-
value: buildStaleWhileRevalidateImplementation$1(Number.MAX_SAFE_INTEGER),
|
|
1106
|
-
},
|
|
1107
|
-
storeLookup: { value: storeLookup },
|
|
1108
|
-
snapshotAvailable: {
|
|
1109
|
-
value: snapshotAvailable,
|
|
1110
|
-
},
|
|
1111
|
-
publishStoreMetadata: {
|
|
1112
|
-
value: publishStoreMetadata,
|
|
1113
|
-
},
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
export { DefaultDurableSegment, DurableStoreOperationType, makeDurable, makeOffline, publishDurableStoreEntries };
|
|
1065
|
+
export { DefaultDurableSegment, DurableStoreOperationType, makeDurable, publishDurableStoreEntries };
|
package/dist/es/es2018/main.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ export { DurableStore, DurableStoreEntries, DurableStoreEntry, DurableStoreChang
|
|
|
2
2
|
export { DurableTTLOverride, DefaultDurableTTLOverride } from './DurableTTLStore';
|
|
3
3
|
export { makeDurable, DurableEnvironment } from './makeDurable';
|
|
4
4
|
export { publishDurableStoreEntries } from './makeDurable/revive';
|
|
5
|
-
export { makeOffline } from './makeOffline';
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
|
|
26
26
|
}
|
|
27
27
|
function buildNetworkSnapshot(args) {
|
|
28
|
-
const { buildNetworkSnapshot, buildSnapshotContext } = args;
|
|
29
|
-
return buildNetworkSnapshot(buildSnapshotContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
|
|
28
|
+
const { buildNetworkSnapshot, buildSnapshotContext, coercedAdapterRequestContext } = args;
|
|
29
|
+
return buildNetworkSnapshot(buildSnapshotContext, coercedAdapterRequestContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
|
|
30
30
|
}
|
|
31
31
|
function buildTTLStrategy(staleDurationMilliseconds = 0) {
|
|
32
32
|
return (timestamp, metadata, valueIsError) => {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
|
|
51
51
|
return function (args) {
|
|
52
52
|
funcs.validateNotDisposed();
|
|
53
|
-
const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup } = args;
|
|
53
|
+
const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup, coercedAdapterRequestContext, } = args;
|
|
54
54
|
const staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
|
|
55
55
|
const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
|
|
56
56
|
const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
|
|
@@ -58,21 +58,20 @@
|
|
|
58
58
|
// data found in L1 cache
|
|
59
59
|
if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
|
|
60
60
|
// kick off network request, do not await it
|
|
61
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
61
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
62
62
|
// return the cached snapshot to caller
|
|
63
63
|
return snapshot;
|
|
64
64
|
}
|
|
65
65
|
// network request outstanding
|
|
66
66
|
if (snapshot.state === 'Pending') {
|
|
67
67
|
// kick off another network request, do not await it
|
|
68
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
68
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
69
69
|
return args.resolvePendingSnapshot(snapshot);
|
|
70
70
|
}
|
|
71
71
|
// stale data found in L1 cache
|
|
72
72
|
if (snapshot.state === 'Stale') {
|
|
73
73
|
// kick off network request, do not await it
|
|
74
|
-
|
|
75
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
74
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
76
75
|
// return the cached snapshot to caller
|
|
77
76
|
return snapshot;
|
|
78
77
|
}
|
|
@@ -85,20 +84,19 @@
|
|
|
85
84
|
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
86
85
|
revivedSnapshot.state === 'Error') {
|
|
87
86
|
// kick off network request, do not await it
|
|
88
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
87
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
89
88
|
// return the L2 cached snapshot to caller
|
|
90
89
|
return revivedSnapshot;
|
|
91
90
|
}
|
|
92
91
|
if (revivedSnapshot.state === 'Pending') {
|
|
93
92
|
// kick off network request, do not await it
|
|
94
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
93
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
95
94
|
return args.resolvePendingSnapshot(revivedSnapshot);
|
|
96
95
|
}
|
|
97
96
|
// stale data found in L2 cache
|
|
98
97
|
if (revivedSnapshot.state === 'Stale') {
|
|
99
98
|
// kick off network request, do not await it
|
|
100
|
-
|
|
101
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
99
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
102
100
|
// return the L2 cached snapshot to caller
|
|
103
101
|
return revivedSnapshot;
|
|
104
102
|
}
|
|
@@ -238,8 +236,7 @@
|
|
|
238
236
|
}
|
|
239
237
|
// stale data found in L1 cache
|
|
240
238
|
if (snapshot.state === 'Stale') {
|
|
241
|
-
|
|
242
|
-
// buildNetworkSnapshot(args);
|
|
239
|
+
buildNetworkSnapshot(args);
|
|
243
240
|
return snapshot;
|
|
244
241
|
}
|
|
245
242
|
// data not found in L1 cache, try L2 cache
|
|
@@ -256,8 +253,7 @@
|
|
|
256
253
|
}
|
|
257
254
|
// stale data found in L2 cache
|
|
258
255
|
if (revivedSnapshot.state === 'Stale') {
|
|
259
|
-
|
|
260
|
-
// buildNetworkSnapshot(args);
|
|
256
|
+
buildNetworkSnapshot(args);
|
|
261
257
|
return revivedSnapshot;
|
|
262
258
|
}
|
|
263
259
|
// data not found in L2 cache, go to the network
|
|
@@ -436,13 +432,12 @@
|
|
|
436
432
|
}
|
|
437
433
|
// We don't want to revive a cached value if it's an error and it's
|
|
438
434
|
// expirationTimestamp TTL is expired, otherwise we would never hit the network
|
|
439
|
-
// during resolveSnapshot or rebuildSnapshot
|
|
440
|
-
// environment because the way the Reader works.
|
|
435
|
+
// during resolveSnapshot or rebuildSnapshot because the way the Reader works.
|
|
441
436
|
// If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
|
|
442
437
|
// if stale TTL is expired. But it will return ErrorSnapshot (instead of
|
|
443
438
|
// StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
|
|
444
|
-
// In
|
|
445
|
-
//
|
|
439
|
+
// In our environment the stale TTL is maxed out so Reader will always
|
|
440
|
+
// return ErrorSnapshot.
|
|
446
441
|
if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
|
|
447
442
|
continue;
|
|
448
443
|
}
|
|
@@ -999,7 +994,8 @@
|
|
|
999
994
|
}
|
|
1000
995
|
const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
|
|
1001
996
|
validateNotDisposed();
|
|
1002
|
-
const
|
|
997
|
+
const { cachePolicy } = adapterRequestContext;
|
|
998
|
+
const cachePolicyImpl = resolveCachePolicy(cachePolicy);
|
|
1003
999
|
const resolvePendingSnapshot = (snapshot) => environment.resolvePendingSnapshot(snapshot);
|
|
1004
1000
|
const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
|
|
1005
1001
|
const applyCachePolicy = () => {
|
|
@@ -1009,6 +1005,7 @@
|
|
|
1009
1005
|
buildSnapshotContext,
|
|
1010
1006
|
resolvePendingSnapshot,
|
|
1011
1007
|
storeLookup,
|
|
1008
|
+
coercedAdapterRequestContext: engine.coerceAdapterRequestContext(adapterRequestContext),
|
|
1012
1009
|
});
|
|
1013
1010
|
};
|
|
1014
1011
|
return isRevivingTTLOverrides !== undefined
|
|
@@ -1069,58 +1066,8 @@
|
|
|
1069
1066
|
});
|
|
1070
1067
|
}
|
|
1071
1068
|
|
|
1072
|
-
/**
|
|
1073
|
-
* This environment allows for stale snapshot emits.
|
|
1074
|
-
*
|
|
1075
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
1076
|
-
* emitted is the result of a storeLookup.
|
|
1077
|
-
*
|
|
1078
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
1079
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
1080
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
1081
|
-
* cause a network refresh to happen).
|
|
1082
|
-
*/
|
|
1083
|
-
function makeOffline(environment) {
|
|
1084
|
-
const storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
|
|
1085
|
-
const snapshot = environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
1086
|
-
// if the snapshot is stale we want to kick off a refresh
|
|
1087
|
-
if (snapshot.state === 'Stale') {
|
|
1088
|
-
if (refresh !== undefined) {
|
|
1089
|
-
const { resolve, config } = refresh;
|
|
1090
|
-
resolve(config);
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
return snapshot;
|
|
1094
|
-
};
|
|
1095
|
-
const snapshotAvailable = function (snapshot) {
|
|
1096
|
-
if (snapshot.state === 'Stale') {
|
|
1097
|
-
return true;
|
|
1098
|
-
}
|
|
1099
|
-
return environment.snapshotAvailable(snapshot);
|
|
1100
|
-
};
|
|
1101
|
-
const publishStoreMetadata = function (recordId, storeMetadata) {
|
|
1102
|
-
environment.publishStoreMetadata(recordId, {
|
|
1103
|
-
...storeMetadata,
|
|
1104
|
-
staleTimestamp: Number.MAX_SAFE_INTEGER,
|
|
1105
|
-
});
|
|
1106
|
-
};
|
|
1107
|
-
return create(environment, {
|
|
1108
|
-
defaultCachePolicy: {
|
|
1109
|
-
value: engine.buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER),
|
|
1110
|
-
},
|
|
1111
|
-
storeLookup: { value: storeLookup },
|
|
1112
|
-
snapshotAvailable: {
|
|
1113
|
-
value: snapshotAvailable,
|
|
1114
|
-
},
|
|
1115
|
-
publishStoreMetadata: {
|
|
1116
|
-
value: publishStoreMetadata,
|
|
1117
|
-
},
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
1069
|
exports.DefaultDurableSegment = DefaultDurableSegment;
|
|
1122
1070
|
exports.makeDurable = makeDurable;
|
|
1123
|
-
exports.makeOffline = makeOffline;
|
|
1124
1071
|
exports.publishDurableStoreEntries = publishDurableStoreEntries;
|
|
1125
1072
|
|
|
1126
1073
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -2,4 +2,3 @@ export { DurableStore, DurableStoreEntries, DurableStoreEntry, DurableStoreChang
|
|
|
2
2
|
export { DurableTTLOverride, DefaultDurableTTLOverride } from './DurableTTLStore';
|
|
3
3
|
export { makeDurable, DurableEnvironment } from './makeDurable';
|
|
4
4
|
export { publishDurableStoreEntries } from './makeDurable/revive';
|
|
5
|
-
export { makeOffline } from './makeOffline';
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
function buildNetworkSnapshot(args) {
|
|
66
|
-
var buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext;
|
|
67
|
-
return buildNetworkSnapshot(buildSnapshotContext).then(function (snapshot) {
|
|
66
|
+
var buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, coercedAdapterRequestContext = args.coercedAdapterRequestContext;
|
|
67
|
+
return buildNetworkSnapshot(buildSnapshotContext, coercedAdapterRequestContext).then(function (snapshot) {
|
|
68
68
|
return snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot;
|
|
69
69
|
});
|
|
70
70
|
}
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
|
|
92
92
|
return function (args) {
|
|
93
93
|
funcs.validateNotDisposed();
|
|
94
|
-
var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot$1 = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
|
|
94
|
+
var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot$1 = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup, coercedAdapterRequestContext = args.coercedAdapterRequestContext;
|
|
95
95
|
var staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
|
|
96
96
|
var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
|
|
97
97
|
var snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
|
|
@@ -99,21 +99,20 @@
|
|
|
99
99
|
// data found in L1 cache
|
|
100
100
|
if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
|
|
101
101
|
// kick off network request, do not await it
|
|
102
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
102
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
103
103
|
// return the cached snapshot to caller
|
|
104
104
|
return snapshot;
|
|
105
105
|
}
|
|
106
106
|
// network request outstanding
|
|
107
107
|
if (snapshot.state === 'Pending') {
|
|
108
108
|
// kick off another network request, do not await it
|
|
109
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
109
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
110
110
|
return args.resolvePendingSnapshot(snapshot);
|
|
111
111
|
}
|
|
112
112
|
// stale data found in L1 cache
|
|
113
113
|
if (snapshot.state === 'Stale') {
|
|
114
114
|
// kick off network request, do not await it
|
|
115
|
-
|
|
116
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
115
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
117
116
|
// return the cached snapshot to caller
|
|
118
117
|
return snapshot;
|
|
119
118
|
}
|
|
@@ -126,20 +125,19 @@
|
|
|
126
125
|
if (revivedSnapshot.state === 'Fulfilled' ||
|
|
127
126
|
revivedSnapshot.state === 'Error') {
|
|
128
127
|
// kick off network request, do not await it
|
|
129
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
128
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
130
129
|
// return the L2 cached snapshot to caller
|
|
131
130
|
return revivedSnapshot;
|
|
132
131
|
}
|
|
133
132
|
if (revivedSnapshot.state === 'Pending') {
|
|
134
133
|
// kick off network request, do not await it
|
|
135
|
-
buildNetworkSnapshot$1(buildSnapshotContext);
|
|
134
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
136
135
|
return args.resolvePendingSnapshot(revivedSnapshot);
|
|
137
136
|
}
|
|
138
137
|
// stale data found in L2 cache
|
|
139
138
|
if (revivedSnapshot.state === 'Stale') {
|
|
140
139
|
// kick off network request, do not await it
|
|
141
|
-
|
|
142
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
140
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
143
141
|
// return the L2 cached snapshot to caller
|
|
144
142
|
return revivedSnapshot;
|
|
145
143
|
}
|
|
@@ -279,8 +277,7 @@
|
|
|
279
277
|
}
|
|
280
278
|
// stale data found in L1 cache
|
|
281
279
|
if (snapshot.state === 'Stale') {
|
|
282
|
-
|
|
283
|
-
// buildNetworkSnapshot(args);
|
|
280
|
+
buildNetworkSnapshot(args);
|
|
284
281
|
return snapshot;
|
|
285
282
|
}
|
|
286
283
|
// data not found in L1 cache, try L2 cache
|
|
@@ -297,8 +294,7 @@
|
|
|
297
294
|
}
|
|
298
295
|
// stale data found in L2 cache
|
|
299
296
|
if (revivedSnapshot.state === 'Stale') {
|
|
300
|
-
|
|
301
|
-
// buildNetworkSnapshot(args);
|
|
297
|
+
buildNetworkSnapshot(args);
|
|
302
298
|
return revivedSnapshot;
|
|
303
299
|
}
|
|
304
300
|
// data not found in L2 cache, go to the network
|
|
@@ -471,13 +467,12 @@
|
|
|
471
467
|
}
|
|
472
468
|
// We don't want to revive a cached value if it's an error and it's
|
|
473
469
|
// expirationTimestamp TTL is expired, otherwise we would never hit the network
|
|
474
|
-
// during resolveSnapshot or rebuildSnapshot
|
|
475
|
-
// environment because the way the Reader works.
|
|
470
|
+
// during resolveSnapshot or rebuildSnapshot because the way the Reader works.
|
|
476
471
|
// If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
|
|
477
472
|
// if stale TTL is expired. But it will return ErrorSnapshot (instead of
|
|
478
473
|
// StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
|
|
479
|
-
// In
|
|
480
|
-
//
|
|
474
|
+
// In our environment the stale TTL is maxed out so Reader will always
|
|
475
|
+
// return ErrorSnapshot.
|
|
481
476
|
if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
|
|
482
477
|
continue;
|
|
483
478
|
}
|
|
@@ -1044,7 +1039,8 @@
|
|
|
1044
1039
|
}
|
|
1045
1040
|
var applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
|
|
1046
1041
|
validateNotDisposed();
|
|
1047
|
-
var
|
|
1042
|
+
var cachePolicy = adapterRequestContext.cachePolicy;
|
|
1043
|
+
var cachePolicyImpl = resolveCachePolicy(cachePolicy);
|
|
1048
1044
|
var resolvePendingSnapshot = function (snapshot) {
|
|
1049
1045
|
return environment.resolvePendingSnapshot(snapshot);
|
|
1050
1046
|
};
|
|
@@ -1056,6 +1052,7 @@
|
|
|
1056
1052
|
buildSnapshotContext: buildSnapshotContext,
|
|
1057
1053
|
resolvePendingSnapshot: resolvePendingSnapshot,
|
|
1058
1054
|
storeLookup: storeLookup,
|
|
1055
|
+
coercedAdapterRequestContext: engine.coerceAdapterRequestContext(adapterRequestContext),
|
|
1059
1056
|
});
|
|
1060
1057
|
};
|
|
1061
1058
|
return isRevivingTTLOverrides !== undefined
|
|
@@ -1118,55 +1115,8 @@
|
|
|
1118
1115
|
});
|
|
1119
1116
|
}
|
|
1120
1117
|
|
|
1121
|
-
/**
|
|
1122
|
-
* This environment allows for stale snapshot emits.
|
|
1123
|
-
*
|
|
1124
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
1125
|
-
* emitted is the result of a storeLookup.
|
|
1126
|
-
*
|
|
1127
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
1128
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
1129
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
1130
|
-
* cause a network refresh to happen).
|
|
1131
|
-
*/
|
|
1132
|
-
function makeOffline(environment) {
|
|
1133
|
-
var storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
|
|
1134
|
-
var snapshot = environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
1135
|
-
// if the snapshot is stale we want to kick off a refresh
|
|
1136
|
-
if (snapshot.state === 'Stale') {
|
|
1137
|
-
if (refresh !== undefined) {
|
|
1138
|
-
var resolve = refresh.resolve, config = refresh.config;
|
|
1139
|
-
resolve(config);
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
return snapshot;
|
|
1143
|
-
};
|
|
1144
|
-
var snapshotAvailable = function (snapshot) {
|
|
1145
|
-
if (snapshot.state === 'Stale') {
|
|
1146
|
-
return true;
|
|
1147
|
-
}
|
|
1148
|
-
return environment.snapshotAvailable(snapshot);
|
|
1149
|
-
};
|
|
1150
|
-
var publishStoreMetadata = function (recordId, storeMetadata) {
|
|
1151
|
-
environment.publishStoreMetadata(recordId, __assign(__assign({}, storeMetadata), { staleTimestamp: Number.MAX_SAFE_INTEGER }));
|
|
1152
|
-
};
|
|
1153
|
-
return create(environment, {
|
|
1154
|
-
defaultCachePolicy: {
|
|
1155
|
-
value: engine.buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER),
|
|
1156
|
-
},
|
|
1157
|
-
storeLookup: { value: storeLookup },
|
|
1158
|
-
snapshotAvailable: {
|
|
1159
|
-
value: snapshotAvailable,
|
|
1160
|
-
},
|
|
1161
|
-
publishStoreMetadata: {
|
|
1162
|
-
value: publishStoreMetadata,
|
|
1163
|
-
},
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
1118
|
exports.DefaultDurableSegment = DefaultDurableSegment;
|
|
1168
1119
|
exports.makeDurable = makeDurable;
|
|
1169
|
-
exports.makeOffline = makeOffline;
|
|
1170
1120
|
exports.publishDurableStoreEntries = publishDurableStoreEntries;
|
|
1171
1121
|
|
|
1172
1122
|
Object.defineProperty(exports, '__esModule', { value: true });
|
package/dist/umd/es5/main.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ export { DurableStore, DurableStoreEntries, DurableStoreEntry, DurableStoreChang
|
|
|
2
2
|
export { DurableTTLOverride, DefaultDurableTTLOverride } from './DurableTTLStore';
|
|
3
3
|
export { makeDurable, DurableEnvironment } from './makeDurable';
|
|
4
4
|
export { publishDurableStoreEntries } from './makeDurable/revive';
|
|
5
|
-
export { makeOffline } from './makeOffline';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luvio/environments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.67.0",
|
|
4
4
|
"description": "Luvio Environments",
|
|
5
5
|
"main": "dist/umd/es2018/environments.js",
|
|
6
6
|
"module": "dist/es/es2018/environments.js",
|
|
@@ -13,10 +13,19 @@
|
|
|
13
13
|
"test": "jest",
|
|
14
14
|
"test:debug": "node --inspect-brk ../../../node_modules/jest/bin/jest.js --config ./jest.config.js --runInBand"
|
|
15
15
|
},
|
|
16
|
+
"nx": {
|
|
17
|
+
"targets": {
|
|
18
|
+
"build": {
|
|
19
|
+
"outputs": [
|
|
20
|
+
"packages/@luvio/environments/dist"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
16
25
|
"files": [
|
|
17
26
|
"dist/"
|
|
18
27
|
],
|
|
19
28
|
"dependencies": {
|
|
20
|
-
"@luvio/engine": "0.
|
|
29
|
+
"@luvio/engine": "0.67.0"
|
|
21
30
|
}
|
|
22
31
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Environment } from '@luvio/engine';
|
|
2
|
-
/**
|
|
3
|
-
* This environment allows for stale snapshot emits.
|
|
4
|
-
*
|
|
5
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
6
|
-
* emitted is the result of a storeLookup.
|
|
7
|
-
*
|
|
8
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
9
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
10
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
11
|
-
* cause a network refresh to happen).
|
|
12
|
-
*/
|
|
13
|
-
export declare function makeOffline(environment: Environment): Environment;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Environment } from '@luvio/engine';
|
|
2
|
-
/**
|
|
3
|
-
* This environment allows for stale snapshot emits.
|
|
4
|
-
*
|
|
5
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
6
|
-
* emitted is the result of a storeLookup.
|
|
7
|
-
*
|
|
8
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
9
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
10
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
11
|
-
* cause a network refresh to happen).
|
|
12
|
-
*/
|
|
13
|
-
export declare function makeOffline(environment: Environment): Environment;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Environment } from '@luvio/engine';
|
|
2
|
-
/**
|
|
3
|
-
* This environment allows for stale snapshot emits.
|
|
4
|
-
*
|
|
5
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
6
|
-
* emitted is the result of a storeLookup.
|
|
7
|
-
*
|
|
8
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
9
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
10
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
11
|
-
* cause a network refresh to happen).
|
|
12
|
-
*/
|
|
13
|
-
export declare function makeOffline(environment: Environment): Environment;
|