@luvio/environments 0.61.0 → 0.62.2
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 +32 -9
- package/dist/es/es2018/makeDurable/cachepolicies/index.d.ts +1 -0
- package/dist/es/es2018/makeDurable/cachepolicies/valid-at.d.ts +3 -0
- package/dist/es/es2018/makeDurable.d.ts +1 -1
- package/dist/umd/es2018/environments.js +32 -9
- package/dist/umd/es2018/makeDurable/cachepolicies/index.d.ts +1 -0
- package/dist/umd/es2018/makeDurable/cachepolicies/valid-at.d.ts +3 -0
- package/dist/umd/es2018/makeDurable.d.ts +1 -1
- package/dist/umd/es5/environments.js +31 -9
- package/dist/umd/es5/makeDurable/cachepolicies/index.d.ts +1 -0
- package/dist/umd/es5/makeDurable/cachepolicies/valid-at.d.ts +3 -0
- package/dist/umd/es5/makeDurable.d.ts +1 -1
- package/package.json +4 -3
|
@@ -246,6 +246,28 @@ function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
|
|
|
246
246
|
};
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
function buildValidAtImplementation(funcs, basePolicyImplementation, timestamp) {
|
|
250
|
+
return function validAtImplementation(args) {
|
|
251
|
+
funcs.validateNotDisposed();
|
|
252
|
+
// This somewhat convoluted code is used to force the basePolicyImplementation's
|
|
253
|
+
// TTLStrategy to use the the valid-at cache policy's timestamp. The flow goes:
|
|
254
|
+
//
|
|
255
|
+
// Environment.applyCachePolicy => validAtImplementation (this function) =>
|
|
256
|
+
// basePolicyImplementation => adapter's buildInMemorySnapshot =>
|
|
257
|
+
// basePolicyImplementation's storeLookup => validAtStoreLookup (below) =>
|
|
258
|
+
// Environment.applyCachePolicy's storeLookup => Store/Reader code =>
|
|
259
|
+
// valid-at TTLStrategy (below) =>
|
|
260
|
+
// basePolicyImplementation's TTLStrategy (with valid-at timestamp)
|
|
261
|
+
const validAtStoreLookup = (sel, refresh, ttlStrategy) => args.storeLookup(sel, refresh, (_readerTimestamp, metadata, valueIsError) => ttlStrategy(timestamp, metadata, valueIsError));
|
|
262
|
+
// let basePolicy make all the decisions, but have it use our storeLookup
|
|
263
|
+
// so we can override the timestamp passed to the basePolicy's TTLStrategy
|
|
264
|
+
return basePolicyImplementation({
|
|
265
|
+
...args,
|
|
266
|
+
storeLookup: validAtStoreLookup,
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
249
271
|
//Durable store error instrumentation key
|
|
250
272
|
const DURABLE_STORE_ERROR = 'durable-store-error';
|
|
251
273
|
/**
|
|
@@ -912,13 +934,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
912
934
|
return buildStaleWhileRevalidateImplementation({
|
|
913
935
|
validateNotDisposed,
|
|
914
936
|
reviveSnapshotWithCachePolicy,
|
|
915
|
-
},
|
|
916
|
-
// TODO[@W-10077764]: remove staleDuration once Komaci switches to cache-then-network
|
|
917
|
-
'staleDurationSeconds' in cachePolicy
|
|
918
|
-
? cachePolicy.staleDurationSeconds
|
|
919
|
-
: cachePolicy.staleDuration
|
|
920
|
-
//cachePolicy.staleDurationSeconds
|
|
921
|
-
);
|
|
937
|
+
}, cachePolicy.staleDurationSeconds);
|
|
922
938
|
case 'cache-and-network':
|
|
923
939
|
return buildCacheAndNetworkImplementation({
|
|
924
940
|
validateNotDisposed,
|
|
@@ -939,6 +955,13 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
939
955
|
validateNotDisposed,
|
|
940
956
|
reviveSnapshotWithCachePolicy,
|
|
941
957
|
});
|
|
958
|
+
case 'valid-at': {
|
|
959
|
+
const basePolicy = resolveCachePolicy(cachePolicy.basePolicy);
|
|
960
|
+
return buildValidAtImplementation({
|
|
961
|
+
validateNotDisposed,
|
|
962
|
+
reviveSnapshotWithCachePolicy,
|
|
963
|
+
}, basePolicy, cachePolicy.timestamp);
|
|
964
|
+
}
|
|
942
965
|
default: {
|
|
943
966
|
if (process.env.NODE_ENV !== 'production') {
|
|
944
967
|
throw new Error(`unrecognized cache policy: ${JSON.stringify(cachePolicy)}`);
|
|
@@ -947,9 +970,9 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
947
970
|
}
|
|
948
971
|
}
|
|
949
972
|
}
|
|
950
|
-
const applyCachePolicy = function (
|
|
973
|
+
const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
|
|
951
974
|
validateNotDisposed();
|
|
952
|
-
const cachePolicyImpl = resolveCachePolicy(cachePolicy);
|
|
975
|
+
const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
|
|
953
976
|
const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
|
|
954
977
|
const applyCachePolicy = () => {
|
|
955
978
|
return cachePolicyImpl({
|
|
@@ -3,3 +3,4 @@ export { buildCacheThenNetworkImplementation } from './cache-then-network';
|
|
|
3
3
|
export { buildNoCacheImplementation } from './no-cache';
|
|
4
4
|
export { buildOnlyIfCachedImplementation } from './only-if-cached';
|
|
5
5
|
export { buildStaleWhileRevalidateImplementation } from './stale-while-revalidate';
|
|
6
|
+
export { buildValidAtImplementation } from './valid-at';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CachePolicyImplementation, CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
|
|
2
|
+
import { DurableCachePolicyFunctions } from './utils';
|
|
3
|
+
export declare function buildValidAtImplementation<C, D>(funcs: DurableCachePolicyFunctions, basePolicyImplementation: CachePolicyImplementation<C, D>, timestamp: number): (args: CachePolicyImplementationArgs<C, D>) => Snapshot<D> | Promise<Snapshot<D>>;
|
|
@@ -28,7 +28,7 @@ export interface DurableEnvironment extends Environment {
|
|
|
28
28
|
/**
|
|
29
29
|
* Overload of Environment.handleSuccessResponse that takes in an optional
|
|
30
30
|
* RecordSource to "prime" the ingest staging store with before calling
|
|
31
|
-
* ingest.
|
|
31
|
+
* ingest. Useful for merge-able record types
|
|
32
32
|
*/
|
|
33
33
|
handleSuccessResponse<ResponseType>(ingestAndBroadcastFunc: () => Snapshot<ResponseType>, getResponseCacheKeysFunc: () => CacheKeySet, existingRecords?: RecordSource): Snapshot<ResponseType> | Promise<Snapshot<ResponseType>>;
|
|
34
34
|
}
|
|
@@ -249,6 +249,28 @@
|
|
|
249
249
|
};
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
function buildValidAtImplementation(funcs, basePolicyImplementation, timestamp) {
|
|
253
|
+
return function validAtImplementation(args) {
|
|
254
|
+
funcs.validateNotDisposed();
|
|
255
|
+
// This somewhat convoluted code is used to force the basePolicyImplementation's
|
|
256
|
+
// TTLStrategy to use the the valid-at cache policy's timestamp. The flow goes:
|
|
257
|
+
//
|
|
258
|
+
// Environment.applyCachePolicy => validAtImplementation (this function) =>
|
|
259
|
+
// basePolicyImplementation => adapter's buildInMemorySnapshot =>
|
|
260
|
+
// basePolicyImplementation's storeLookup => validAtStoreLookup (below) =>
|
|
261
|
+
// Environment.applyCachePolicy's storeLookup => Store/Reader code =>
|
|
262
|
+
// valid-at TTLStrategy (below) =>
|
|
263
|
+
// basePolicyImplementation's TTLStrategy (with valid-at timestamp)
|
|
264
|
+
const validAtStoreLookup = (sel, refresh, ttlStrategy) => args.storeLookup(sel, refresh, (_readerTimestamp, metadata, valueIsError) => ttlStrategy(timestamp, metadata, valueIsError));
|
|
265
|
+
// let basePolicy make all the decisions, but have it use our storeLookup
|
|
266
|
+
// so we can override the timestamp passed to the basePolicy's TTLStrategy
|
|
267
|
+
return basePolicyImplementation({
|
|
268
|
+
...args,
|
|
269
|
+
storeLookup: validAtStoreLookup,
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
252
274
|
//Durable store error instrumentation key
|
|
253
275
|
const DURABLE_STORE_ERROR = 'durable-store-error';
|
|
254
276
|
/**
|
|
@@ -915,13 +937,7 @@
|
|
|
915
937
|
return buildStaleWhileRevalidateImplementation({
|
|
916
938
|
validateNotDisposed,
|
|
917
939
|
reviveSnapshotWithCachePolicy,
|
|
918
|
-
},
|
|
919
|
-
// TODO[@W-10077764]: remove staleDuration once Komaci switches to cache-then-network
|
|
920
|
-
'staleDurationSeconds' in cachePolicy
|
|
921
|
-
? cachePolicy.staleDurationSeconds
|
|
922
|
-
: cachePolicy.staleDuration
|
|
923
|
-
//cachePolicy.staleDurationSeconds
|
|
924
|
-
);
|
|
940
|
+
}, cachePolicy.staleDurationSeconds);
|
|
925
941
|
case 'cache-and-network':
|
|
926
942
|
return buildCacheAndNetworkImplementation({
|
|
927
943
|
validateNotDisposed,
|
|
@@ -942,6 +958,13 @@
|
|
|
942
958
|
validateNotDisposed,
|
|
943
959
|
reviveSnapshotWithCachePolicy,
|
|
944
960
|
});
|
|
961
|
+
case 'valid-at': {
|
|
962
|
+
const basePolicy = resolveCachePolicy(cachePolicy.basePolicy);
|
|
963
|
+
return buildValidAtImplementation({
|
|
964
|
+
validateNotDisposed,
|
|
965
|
+
reviveSnapshotWithCachePolicy,
|
|
966
|
+
}, basePolicy, cachePolicy.timestamp);
|
|
967
|
+
}
|
|
945
968
|
default: {
|
|
946
969
|
if (process.env.NODE_ENV !== 'production') {
|
|
947
970
|
throw new Error(`unrecognized cache policy: ${JSON.stringify(cachePolicy)}`);
|
|
@@ -950,9 +973,9 @@
|
|
|
950
973
|
}
|
|
951
974
|
}
|
|
952
975
|
}
|
|
953
|
-
const applyCachePolicy = function (
|
|
976
|
+
const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
|
|
954
977
|
validateNotDisposed();
|
|
955
|
-
const cachePolicyImpl = resolveCachePolicy(cachePolicy);
|
|
978
|
+
const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
|
|
956
979
|
const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
|
|
957
980
|
const applyCachePolicy = () => {
|
|
958
981
|
return cachePolicyImpl({
|
|
@@ -3,3 +3,4 @@ export { buildCacheThenNetworkImplementation } from './cache-then-network';
|
|
|
3
3
|
export { buildNoCacheImplementation } from './no-cache';
|
|
4
4
|
export { buildOnlyIfCachedImplementation } from './only-if-cached';
|
|
5
5
|
export { buildStaleWhileRevalidateImplementation } from './stale-while-revalidate';
|
|
6
|
+
export { buildValidAtImplementation } from './valid-at';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CachePolicyImplementation, CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
|
|
2
|
+
import { DurableCachePolicyFunctions } from './utils';
|
|
3
|
+
export declare function buildValidAtImplementation<C, D>(funcs: DurableCachePolicyFunctions, basePolicyImplementation: CachePolicyImplementation<C, D>, timestamp: number): (args: CachePolicyImplementationArgs<C, D>) => Snapshot<D> | Promise<Snapshot<D>>;
|
|
@@ -28,7 +28,7 @@ export interface DurableEnvironment extends Environment {
|
|
|
28
28
|
/**
|
|
29
29
|
* Overload of Environment.handleSuccessResponse that takes in an optional
|
|
30
30
|
* RecordSource to "prime" the ingest staging store with before calling
|
|
31
|
-
* ingest.
|
|
31
|
+
* ingest. Useful for merge-able record types
|
|
32
32
|
*/
|
|
33
33
|
handleSuccessResponse<ResponseType>(ingestAndBroadcastFunc: () => Snapshot<ResponseType>, getResponseCacheKeysFunc: () => CacheKeySet, existingRecords?: RecordSource): Snapshot<ResponseType> | Promise<Snapshot<ResponseType>>;
|
|
34
34
|
}
|
|
@@ -286,6 +286,27 @@
|
|
|
286
286
|
};
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
function buildValidAtImplementation(funcs, basePolicyImplementation, timestamp) {
|
|
290
|
+
return function validAtImplementation(args) {
|
|
291
|
+
funcs.validateNotDisposed();
|
|
292
|
+
// This somewhat convoluted code is used to force the basePolicyImplementation's
|
|
293
|
+
// TTLStrategy to use the the valid-at cache policy's timestamp. The flow goes:
|
|
294
|
+
//
|
|
295
|
+
// Environment.applyCachePolicy => validAtImplementation (this function) =>
|
|
296
|
+
// basePolicyImplementation => adapter's buildInMemorySnapshot =>
|
|
297
|
+
// basePolicyImplementation's storeLookup => validAtStoreLookup (below) =>
|
|
298
|
+
// Environment.applyCachePolicy's storeLookup => Store/Reader code =>
|
|
299
|
+
// valid-at TTLStrategy (below) =>
|
|
300
|
+
// basePolicyImplementation's TTLStrategy (with valid-at timestamp)
|
|
301
|
+
var validAtStoreLookup = function (sel, refresh, ttlStrategy) {
|
|
302
|
+
return args.storeLookup(sel, refresh, function (_readerTimestamp, metadata, valueIsError) { return ttlStrategy(timestamp, metadata, valueIsError); });
|
|
303
|
+
};
|
|
304
|
+
// let basePolicy make all the decisions, but have it use our storeLookup
|
|
305
|
+
// so we can override the timestamp passed to the basePolicy's TTLStrategy
|
|
306
|
+
return basePolicyImplementation(__assign(__assign({}, args), { storeLookup: validAtStoreLookup }));
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
289
310
|
//Durable store error instrumentation key
|
|
290
311
|
var DURABLE_STORE_ERROR = 'durable-store-error';
|
|
291
312
|
/**
|
|
@@ -957,13 +978,7 @@
|
|
|
957
978
|
return buildStaleWhileRevalidateImplementation({
|
|
958
979
|
validateNotDisposed: validateNotDisposed,
|
|
959
980
|
reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
|
|
960
|
-
},
|
|
961
|
-
// TODO[@W-10077764]: remove staleDuration once Komaci switches to cache-then-network
|
|
962
|
-
'staleDurationSeconds' in cachePolicy
|
|
963
|
-
? cachePolicy.staleDurationSeconds
|
|
964
|
-
: cachePolicy.staleDuration
|
|
965
|
-
//cachePolicy.staleDurationSeconds
|
|
966
|
-
);
|
|
981
|
+
}, cachePolicy.staleDurationSeconds);
|
|
967
982
|
case 'cache-and-network':
|
|
968
983
|
return buildCacheAndNetworkImplementation({
|
|
969
984
|
validateNotDisposed: validateNotDisposed,
|
|
@@ -984,6 +999,13 @@
|
|
|
984
999
|
validateNotDisposed: validateNotDisposed,
|
|
985
1000
|
reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
|
|
986
1001
|
});
|
|
1002
|
+
case 'valid-at': {
|
|
1003
|
+
var basePolicy = resolveCachePolicy(cachePolicy.basePolicy);
|
|
1004
|
+
return buildValidAtImplementation({
|
|
1005
|
+
validateNotDisposed: validateNotDisposed,
|
|
1006
|
+
reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
|
|
1007
|
+
}, basePolicy, cachePolicy.timestamp);
|
|
1008
|
+
}
|
|
987
1009
|
default: {
|
|
988
1010
|
if (process.env.NODE_ENV !== 'production') {
|
|
989
1011
|
throw new Error("unrecognized cache policy: " + JSON.stringify(cachePolicy));
|
|
@@ -992,9 +1014,9 @@
|
|
|
992
1014
|
}
|
|
993
1015
|
}
|
|
994
1016
|
}
|
|
995
|
-
var applyCachePolicy = function (
|
|
1017
|
+
var applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
|
|
996
1018
|
validateNotDisposed();
|
|
997
|
-
var cachePolicyImpl = resolveCachePolicy(cachePolicy);
|
|
1019
|
+
var cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
|
|
998
1020
|
var storeLookup = function (sel, refresh, ttlStrategy) { return environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy); };
|
|
999
1021
|
var applyCachePolicy = function () {
|
|
1000
1022
|
return cachePolicyImpl({
|
|
@@ -3,3 +3,4 @@ export { buildCacheThenNetworkImplementation } from './cache-then-network';
|
|
|
3
3
|
export { buildNoCacheImplementation } from './no-cache';
|
|
4
4
|
export { buildOnlyIfCachedImplementation } from './only-if-cached';
|
|
5
5
|
export { buildStaleWhileRevalidateImplementation } from './stale-while-revalidate';
|
|
6
|
+
export { buildValidAtImplementation } from './valid-at';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CachePolicyImplementation, CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
|
|
2
|
+
import { DurableCachePolicyFunctions } from './utils';
|
|
3
|
+
export declare function buildValidAtImplementation<C, D>(funcs: DurableCachePolicyFunctions, basePolicyImplementation: CachePolicyImplementation<C, D>, timestamp: number): (args: CachePolicyImplementationArgs<C, D>) => Snapshot<D> | Promise<Snapshot<D>>;
|
|
@@ -28,7 +28,7 @@ export interface DurableEnvironment extends Environment {
|
|
|
28
28
|
/**
|
|
29
29
|
* Overload of Environment.handleSuccessResponse that takes in an optional
|
|
30
30
|
* RecordSource to "prime" the ingest staging store with before calling
|
|
31
|
-
* ingest.
|
|
31
|
+
* ingest. Useful for merge-able record types
|
|
32
32
|
*/
|
|
33
33
|
handleSuccessResponse<ResponseType>(ingestAndBroadcastFunc: () => Snapshot<ResponseType>, getResponseCacheKeysFunc: () => CacheKeySet, existingRecords?: RecordSource): Snapshot<ResponseType> | Promise<Snapshot<ResponseType>>;
|
|
34
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luvio/environments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.2",
|
|
4
4
|
"description": "Luvio Environments",
|
|
5
5
|
"main": "dist/umd/es2018/environments.js",
|
|
6
6
|
"module": "dist/es/es2018/environments.js",
|
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
"clean": "rm -rf dist",
|
|
11
11
|
"build": "rollup --config rollup.config.js",
|
|
12
12
|
"watch": "yarn build --watch",
|
|
13
|
-
"test": "jest"
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"test:debug": "node --inspect-brk ../../../node_modules/jest/bin/jest.js --config ./jest.config.js --runInBand"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"dist/"
|
|
17
18
|
],
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@luvio/engine": "0.
|
|
20
|
+
"@luvio/engine": "0.62.2"
|
|
20
21
|
}
|
|
21
22
|
}
|