@luvio/environments 0.61.1 → 0.62.3

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.
@@ -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
  /**
@@ -933,6 +955,13 @@ function makeDurable(environment, { durableStore, instrumentation }) {
933
955
  validateNotDisposed,
934
956
  reviveSnapshotWithCachePolicy,
935
957
  });
958
+ case 'valid-at': {
959
+ const basePolicy = resolveCachePolicy(cachePolicy.basePolicy);
960
+ return buildValidAtImplementation({
961
+ validateNotDisposed,
962
+ reviveSnapshotWithCachePolicy,
963
+ }, basePolicy, cachePolicy.timestamp);
964
+ }
936
965
  default: {
937
966
  if (process.env.NODE_ENV !== 'production') {
938
967
  throw new Error(`unrecognized cache policy: ${JSON.stringify(cachePolicy)}`);
@@ -941,9 +970,9 @@ function makeDurable(environment, { durableStore, instrumentation }) {
941
970
  }
942
971
  }
943
972
  }
944
- const applyCachePolicy = function (cachePolicy, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
973
+ const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
945
974
  validateNotDisposed();
946
- const cachePolicyImpl = resolveCachePolicy(cachePolicy);
975
+ const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
947
976
  const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
948
977
  const applyCachePolicy = () => {
949
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. Useful for merge-able record types
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
  /**
@@ -936,6 +958,13 @@
936
958
  validateNotDisposed,
937
959
  reviveSnapshotWithCachePolicy,
938
960
  });
961
+ case 'valid-at': {
962
+ const basePolicy = resolveCachePolicy(cachePolicy.basePolicy);
963
+ return buildValidAtImplementation({
964
+ validateNotDisposed,
965
+ reviveSnapshotWithCachePolicy,
966
+ }, basePolicy, cachePolicy.timestamp);
967
+ }
939
968
  default: {
940
969
  if (process.env.NODE_ENV !== 'production') {
941
970
  throw new Error(`unrecognized cache policy: ${JSON.stringify(cachePolicy)}`);
@@ -944,9 +973,9 @@
944
973
  }
945
974
  }
946
975
  }
947
- const applyCachePolicy = function (cachePolicy, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
976
+ const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
948
977
  validateNotDisposed();
949
- const cachePolicyImpl = resolveCachePolicy(cachePolicy);
978
+ const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
950
979
  const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
951
980
  const applyCachePolicy = () => {
952
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. Useful for merge-able record types
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
  /**
@@ -978,6 +999,13 @@
978
999
  validateNotDisposed: validateNotDisposed,
979
1000
  reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
980
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
+ }
981
1009
  default: {
982
1010
  if (process.env.NODE_ENV !== 'production') {
983
1011
  throw new Error("unrecognized cache policy: " + JSON.stringify(cachePolicy));
@@ -986,9 +1014,9 @@
986
1014
  }
987
1015
  }
988
1016
  }
989
- var applyCachePolicy = function (cachePolicy, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
1017
+ var applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
990
1018
  validateNotDisposed();
991
- var cachePolicyImpl = resolveCachePolicy(cachePolicy);
1019
+ var cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
992
1020
  var storeLookup = function (sel, refresh, ttlStrategy) { return environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy); };
993
1021
  var applyCachePolicy = function () {
994
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. Useful for merge-able record types
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.61.1",
3
+ "version": "0.62.3",
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.61.1"
20
+ "@luvio/engine": "0.62.3"
20
21
  }
21
22
  }