@luvio/environments 0.71.0 → 0.73.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.
Files changed (31) hide show
  1. package/dist/es/es2018/DurableStore.d.ts +0 -1
  2. package/dist/es/es2018/environments.js +41 -375
  3. package/dist/umd/es2018/DurableStore.d.ts +0 -1
  4. package/dist/umd/es2018/environments.js +40 -374
  5. package/dist/umd/es5/DurableStore.d.ts +0 -1
  6. package/dist/umd/es5/environments.js +39 -384
  7. package/package.json +2 -2
  8. package/dist/es/es2018/makeDurable/cachepolicies/cache-and-network.d.ts +0 -3
  9. package/dist/es/es2018/makeDurable/cachepolicies/cache-then-network.d.ts +0 -3
  10. package/dist/es/es2018/makeDurable/cachepolicies/index.d.ts +0 -6
  11. package/dist/es/es2018/makeDurable/cachepolicies/no-cache.d.ts +0 -3
  12. package/dist/es/es2018/makeDurable/cachepolicies/only-if-cached.d.ts +0 -3
  13. package/dist/es/es2018/makeDurable/cachepolicies/stale-while-revalidate.d.ts +0 -3
  14. package/dist/es/es2018/makeDurable/cachepolicies/utils.d.ts +0 -9
  15. package/dist/es/es2018/makeDurable/cachepolicies/valid-at.d.ts +0 -3
  16. package/dist/umd/es2018/makeDurable/cachepolicies/cache-and-network.d.ts +0 -3
  17. package/dist/umd/es2018/makeDurable/cachepolicies/cache-then-network.d.ts +0 -3
  18. package/dist/umd/es2018/makeDurable/cachepolicies/index.d.ts +0 -6
  19. package/dist/umd/es2018/makeDurable/cachepolicies/no-cache.d.ts +0 -3
  20. package/dist/umd/es2018/makeDurable/cachepolicies/only-if-cached.d.ts +0 -3
  21. package/dist/umd/es2018/makeDurable/cachepolicies/stale-while-revalidate.d.ts +0 -3
  22. package/dist/umd/es2018/makeDurable/cachepolicies/utils.d.ts +0 -9
  23. package/dist/umd/es2018/makeDurable/cachepolicies/valid-at.d.ts +0 -3
  24. package/dist/umd/es5/makeDurable/cachepolicies/cache-and-network.d.ts +0 -3
  25. package/dist/umd/es5/makeDurable/cachepolicies/cache-then-network.d.ts +0 -3
  26. package/dist/umd/es5/makeDurable/cachepolicies/index.d.ts +0 -6
  27. package/dist/umd/es5/makeDurable/cachepolicies/no-cache.d.ts +0 -3
  28. package/dist/umd/es5/makeDurable/cachepolicies/only-if-cached.d.ts +0 -3
  29. package/dist/umd/es5/makeDurable/cachepolicies/stale-while-revalidate.d.ts +0 -3
  30. package/dist/umd/es5/makeDurable/cachepolicies/utils.d.ts +0 -9
  31. package/dist/umd/es5/makeDurable/cachepolicies/valid-at.d.ts +0 -3
@@ -57,297 +57,6 @@
57
57
  var keys = Object.keys, create = Object.create, assign = Object.assign, freeze = Object.freeze;
58
58
  var isArray = Array.isArray;
59
59
 
60
- function appendTTLStrategy(storeLookup, ttlStrategy) {
61
- var returnStoreLookup = function (sel, refresh) {
62
- return storeLookup(sel, refresh, ttlStrategy);
63
- };
64
- // append ttlStrategy to storeLookup function (in cases where custom adapter
65
- // wants to perform it's own lookup)
66
- returnStoreLookup.ttlStrategy = ttlStrategy;
67
- return returnStoreLookup;
68
- }
69
- function buildNetworkSnapshot(args) {
70
- var buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, coercedAdapterRequestContext = args.coercedAdapterRequestContext;
71
- return buildNetworkSnapshot(buildSnapshotContext, coercedAdapterRequestContext).then(function (snapshot) {
72
- return snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot;
73
- });
74
- }
75
- function buildTTLStrategy(staleDurationMilliseconds) {
76
- if (staleDurationMilliseconds === void 0) { staleDurationMilliseconds = 0; }
77
- return function (timestamp, metadata, valueIsError) {
78
- if (metadata !== undefined) {
79
- var expirationTimestamp = metadata.expirationTimestamp;
80
- if (timestamp > expirationTimestamp) {
81
- if (timestamp <= expirationTimestamp + staleDurationMilliseconds &&
82
- valueIsError !== true) {
83
- return engine.StoreResolveResultState.Stale;
84
- }
85
- return engine.StoreResolveResultState.NotPresent;
86
- }
87
- }
88
- if (valueIsError === true) {
89
- return engine.StoreResolveResultState.Error;
90
- }
91
- return engine.StoreResolveResultState.Found;
92
- };
93
- }
94
- // TODO - update userland-facing APIs to return `AvailableSnapshot` instead of `Snapshot`
95
- // and then the signatures here can be updated as well
96
- function buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, availableSnapshotFunc) {
97
- if (isPromise(cachedSnapshot)) {
98
- return cachedSnapshot.then(availableSnapshotFunc);
99
- }
100
- return availableSnapshotFunc(cachedSnapshot);
101
- }
102
- function isPromise(value) {
103
- if (value === undefined) {
104
- return false;
105
- }
106
- // check for Thenable due to test frameworks using custom Promise impls
107
- return value.then !== undefined;
108
- }
109
-
110
- function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
111
- if (staleDurationSeconds === void 0) { staleDurationSeconds = 0; }
112
- return function (args) {
113
- funcs.validateNotDisposed();
114
- var buildCachedSnapshot = args.buildCachedSnapshot, buildNetworkSnapshot$1 = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup, coercedAdapterRequestContext = args.coercedAdapterRequestContext;
115
- var staleDurationMilliseconds = staleDurationSeconds * 1000;
116
- var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
117
- var cachedSnapshot = buildCachedSnapshot(buildSnapshotContext, cachePolicyStoreLookup);
118
- return buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, function (snapshot) {
119
- if (snapshot !== undefined) {
120
- // data found in L1 cache
121
- if (snapshot.state === 'Fulfilled' ||
122
- snapshot.state === 'Error' ||
123
- snapshot.state === 'Stale') {
124
- // kick off network request, do not await it
125
- buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
126
- // return the cached snapshot to caller
127
- return snapshot;
128
- }
129
- // network request outstanding
130
- if (snapshot.state === 'Pending') {
131
- // kick off another network request, do not await it
132
- buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
133
- return args.resolvePendingSnapshot(snapshot);
134
- }
135
- // if unfulfilled we have enough info to do an L2 lookup
136
- if (snapshot.state === 'Unfulfilled') {
137
- return funcs
138
- .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
139
- .then(function (revivedSnapshot) {
140
- // data found in L2 cache
141
- if (revivedSnapshot.state === 'Fulfilled' ||
142
- revivedSnapshot.state === 'Error' ||
143
- revivedSnapshot.state === 'Stale') {
144
- // kick off network request, do not await it
145
- buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
146
- // return the L2 cached snapshot to caller
147
- return revivedSnapshot;
148
- }
149
- if (revivedSnapshot.state === 'Pending') {
150
- // kick off network request, do not await it
151
- buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
152
- return args.resolvePendingSnapshot(revivedSnapshot);
153
- }
154
- // data not found in L2 cache, go to the network
155
- return buildNetworkSnapshot(args);
156
- });
157
- }
158
- }
159
- return buildNetworkSnapshot(args);
160
- });
161
- };
162
- }
163
-
164
- function buildCacheThenNetworkImplementation(funcs) {
165
- return function (args) {
166
- funcs.validateNotDisposed();
167
- var buildCachedSnapshot = args.buildCachedSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
168
- var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
169
- var cachedSnapshot = buildCachedSnapshot(buildSnapshotContext, cachePolicyStoreLookup);
170
- return buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, function (snapshot) {
171
- if (snapshot !== undefined) {
172
- // data found in L1 cache
173
- if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
174
- return snapshot;
175
- }
176
- if (snapshot.state === 'Pending') {
177
- return args.resolvePendingSnapshot(snapshot);
178
- }
179
- // if unfulfilled we have enough info to do an L2 lookup
180
- if (snapshot.state === 'Unfulfilled') {
181
- return funcs
182
- .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
183
- .then(function (revivedSnapshot) {
184
- // data found in L2 cache
185
- if (revivedSnapshot.state === 'Fulfilled' ||
186
- revivedSnapshot.state === 'Error') {
187
- return revivedSnapshot;
188
- }
189
- if (revivedSnapshot.state === 'Pending') {
190
- return args.resolvePendingSnapshot(revivedSnapshot);
191
- }
192
- // data not found in L2 cache, go to the network
193
- return buildNetworkSnapshot(args);
194
- });
195
- }
196
- }
197
- // L1 lookup could not find enough information to even construct a snapshot, go to the network
198
- return buildNetworkSnapshot(args);
199
- });
200
- };
201
- }
202
-
203
- function buildNoCacheImplementation(funcs) {
204
- return function (args) {
205
- funcs.validateNotDisposed();
206
- return buildNetworkSnapshot(args);
207
- };
208
- }
209
-
210
- function deepFreeze(value) {
211
- // No need to freeze primitives
212
- if (typeof value !== 'object' || value === null) {
213
- return;
214
- }
215
- if (isArray(value)) {
216
- for (var i = 0, len = value.length; i < len; i += 1) {
217
- deepFreeze(value[i]);
218
- }
219
- }
220
- else {
221
- var keys$1 = keys(value);
222
- for (var i = 0, len = keys$1.length; i < len; i += 1) {
223
- deepFreeze(value[keys$1[i]]);
224
- }
225
- }
226
- freeze(value);
227
- }
228
-
229
- // TODO[@W-10165595]: consolidate this code with the corresponding logic in the default environment's only-if-cached.ts
230
- function buildNotCachedErrorSnapshot() {
231
- var error = {
232
- body: undefined,
233
- headers: {},
234
- ok: false,
235
- status: engine.HttpStatusCode.GatewayTimeout,
236
- statusText: 'Gateway Timeout',
237
- };
238
- deepFreeze(error);
239
- return {
240
- error: error,
241
- state: 'Error',
242
- data: undefined,
243
- // TODO[@W-10164067]: copy refresh data from the snapshot returned by buildCachedSnapshot (if any)
244
- // refresh: ...
245
- };
246
- }
247
- function buildOnlyIfCachedImplementation(funcs) {
248
- return function (args) {
249
- funcs.validateNotDisposed();
250
- var buildCachedSnapshot = args.buildCachedSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
251
- var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
252
- var cachedSnapshot = buildCachedSnapshot(buildSnapshotContext, cachePolicyStoreLookup);
253
- return buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, function (snapshot) {
254
- if (snapshot !== undefined) {
255
- // data found in L1 cache
256
- if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
257
- return snapshot;
258
- }
259
- // network request outstanding, data is not cached
260
- if (snapshot.state === 'Pending') {
261
- return buildNotCachedErrorSnapshot();
262
- }
263
- // if unfulfilled we have enough info to do an L2 lookup
264
- if (snapshot.state === 'Unfulfilled') {
265
- return funcs
266
- .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
267
- .then(function (revivedSnapshot) {
268
- // data found in L2 cache
269
- if (revivedSnapshot.state === 'Fulfilled' ||
270
- revivedSnapshot.state === 'Error') {
271
- return revivedSnapshot;
272
- }
273
- // data is not cached
274
- return buildNotCachedErrorSnapshot();
275
- });
276
- }
277
- }
278
- return buildNotCachedErrorSnapshot();
279
- });
280
- };
281
- }
282
-
283
- function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
284
- return function (args) {
285
- funcs.validateNotDisposed();
286
- var buildCachedSnapshot = args.buildCachedSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
287
- var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationSeconds * 1000));
288
- var cachedSnapshot = buildCachedSnapshot(buildSnapshotContext, cachePolicyStoreLookup);
289
- return buildAvailableSnapshotFromCachedSnapshotResponse(cachedSnapshot, function (snapshot) {
290
- if (snapshot !== undefined) {
291
- // data found in L1 cache
292
- if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
293
- return snapshot;
294
- }
295
- if (snapshot.state === 'Pending') {
296
- return args.resolvePendingSnapshot(snapshot);
297
- }
298
- // stale data found in L1 cache
299
- if (snapshot.state === 'Stale') {
300
- buildNetworkSnapshot(args);
301
- return snapshot;
302
- }
303
- // data not found in L1 cache, try L2 cache
304
- return funcs
305
- .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
306
- .then(function (revivedSnapshot) {
307
- // data found in L2 cache
308
- if (revivedSnapshot.state === 'Fulfilled' ||
309
- revivedSnapshot.state === 'Error') {
310
- return revivedSnapshot;
311
- }
312
- if (revivedSnapshot.state === 'Pending') {
313
- return args.resolvePendingSnapshot(revivedSnapshot);
314
- }
315
- // stale data found in L2 cache
316
- if (revivedSnapshot.state === 'Stale') {
317
- buildNetworkSnapshot(args);
318
- return revivedSnapshot;
319
- }
320
- // data not found in L2 cache, go to the network
321
- return buildNetworkSnapshot(args);
322
- });
323
- }
324
- // L1 lookup could not find enough information to even construct a snapshot, go to the network
325
- return buildNetworkSnapshot(args);
326
- });
327
- };
328
- }
329
-
330
- function buildValidAtImplementation(funcs, basePolicyImplementation, timestamp) {
331
- return function validAtImplementation(args) {
332
- funcs.validateNotDisposed();
333
- // This somewhat convoluted code is used to force the basePolicyImplementation's
334
- // TTLStrategy to use the the valid-at cache policy's timestamp. The flow goes:
335
- //
336
- // Environment.applyCachePolicy => validAtImplementation (this function) =>
337
- // basePolicyImplementation => adapter's buildCachedSnapshot =>
338
- // basePolicyImplementation's storeLookup => validAtStoreLookup (below) =>
339
- // Environment.applyCachePolicy's storeLookup => Store/Reader code =>
340
- // valid-at TTLStrategy (below) =>
341
- // basePolicyImplementation's TTLStrategy (with valid-at timestamp)
342
- var validAtStoreLookup = function (sel, refresh, ttlStrategy) {
343
- return args.storeLookup(sel, refresh, function (_readerTimestamp, metadata, valueIsError) { return ttlStrategy(timestamp, metadata, valueIsError); });
344
- };
345
- // let basePolicy make all the decisions, but have it use our storeLookup
346
- // so we can override the timestamp passed to the basePolicy's TTLStrategy
347
- return basePolicyImplementation(__assign(__assign({}, args), { storeLookup: validAtStoreLookup }));
348
- };
349
- }
350
-
351
60
  //Durable store error instrumentation key
352
61
  var DURABLE_STORE_ERROR = 'durable-store-error';
353
62
  /**
@@ -373,6 +82,25 @@
373
82
  };
374
83
  }
375
84
 
85
+ function deepFreeze(value) {
86
+ // No need to freeze primitives
87
+ if (typeof value !== 'object' || value === null) {
88
+ return;
89
+ }
90
+ if (isArray(value)) {
91
+ for (var i = 0, len = value.length; i < len; i += 1) {
92
+ deepFreeze(value[i]);
93
+ }
94
+ }
95
+ else {
96
+ var keys$1 = keys(value);
97
+ for (var i = 0, len = keys$1.length; i < len; i += 1) {
98
+ deepFreeze(value[keys$1[i]]);
99
+ }
100
+ }
101
+ freeze(value);
102
+ }
103
+
376
104
  var SELECTOR_PAGINATION_TOKEN = 'tokenDataKey';
377
105
  function isFragmentUnionSelection(sel) {
378
106
  return sel.union === true;
@@ -742,6 +470,15 @@
742
470
  return contextReturn();
743
471
  });
744
472
  }
473
+ function isUnfulfilledSnapshot(cachedSnapshotResult) {
474
+ if (cachedSnapshotResult === undefined) {
475
+ return false;
476
+ }
477
+ if ('then' in cachedSnapshotResult) {
478
+ return false;
479
+ }
480
+ return cachedSnapshotResult.state === 'Unfulfilled';
481
+ }
745
482
  /**
746
483
  * Configures the environment to persist data into a durable store and attempt to resolve
747
484
  * data from the persistent store before hitting the network.
@@ -900,30 +637,6 @@
900
637
  }
901
638
  return environment.wrapNormalizedGraphNode(normalized, ingestStagingStore);
902
639
  };
903
- var resolveSnapshot = function (snapshot, refresh) {
904
- validateNotDisposed();
905
- // if the snapshot is already pending then no need to kick off another
906
- // revive, just wait for the pending refresh to broadcast
907
- if (snapshot.state === 'Pending') {
908
- return environment.resolvePendingSnapshot(snapshot);
909
- }
910
- var resolve = refresh.resolve, config = refresh.config;
911
- var refreshFunc = function () { return resolve(config); };
912
- // if the snapshot is unfulfilled we can do an L2 lookup
913
- if (snapshot.state === 'Unfulfilled') {
914
- return reviveSnapshot(environment, durableStore, snapshot, durableStoreErrorHandler, function () {
915
- return environment.storeLookup(snapshot.select, environment.createSnapshot, snapshot.refresh);
916
- }).then(function (durableSnapshot) {
917
- if (environment.snapshotAvailable(durableSnapshot)) {
918
- // L2 cache hit
919
- return durableSnapshot;
920
- }
921
- // else have to hit network
922
- return refreshFunc();
923
- });
924
- }
925
- return refreshFunc();
926
- };
927
640
  var rebuildSnapshot = function (snapshot, records, storeMetadataMap, redirects, onAsyncRebuild) {
928
641
  validateNotDisposed();
929
642
  // try rebuilding from memory
@@ -985,77 +698,20 @@
985
698
  validateNotDisposed();
986
699
  return durableTTLStore.getDurableTTLOverrides();
987
700
  };
988
- // reviveSnapshot wrapper to let cache policies revive data from L2 and
989
- // access the revived data via their own storeLookups
990
- var reviveSnapshotWithCachePolicy = function (unavailableSnapshot, storeLookup) {
991
- return reviveSnapshot(environment, durableStore, unavailableSnapshot, durableStoreErrorHandler, function () { return storeLookup(unavailableSnapshot.select, unavailableSnapshot.refresh); });
992
- };
993
- var defaultCachePolicy = buildStaleWhileRevalidateImplementation({
994
- validateNotDisposed: validateNotDisposed,
995
- reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
996
- }, Number.MAX_SAFE_INTEGER);
997
- function resolveCachePolicy(cachePolicy) {
998
- if (cachePolicy === undefined) {
999
- return defaultCachePolicy;
1000
- }
1001
- switch (cachePolicy.type) {
1002
- case 'stale-while-revalidate':
1003
- return buildStaleWhileRevalidateImplementation({
1004
- validateNotDisposed: validateNotDisposed,
1005
- reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
1006
- }, cachePolicy.staleDurationSeconds);
1007
- case 'cache-and-network':
1008
- return buildCacheAndNetworkImplementation({
1009
- validateNotDisposed: validateNotDisposed,
1010
- reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
1011
- }, cachePolicy.staleDurationSeconds);
1012
- case 'cache-then-network':
1013
- return buildCacheThenNetworkImplementation({
1014
- validateNotDisposed: validateNotDisposed,
1015
- reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
1016
- });
1017
- case 'no-cache':
1018
- return buildNoCacheImplementation({
1019
- validateNotDisposed: validateNotDisposed,
1020
- reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
1021
- });
1022
- case 'only-if-cached':
1023
- return buildOnlyIfCachedImplementation({
1024
- validateNotDisposed: validateNotDisposed,
1025
- reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
1026
- });
1027
- case 'valid-at': {
1028
- var basePolicy = resolveCachePolicy(cachePolicy.basePolicy);
1029
- return buildValidAtImplementation({
1030
- validateNotDisposed: validateNotDisposed,
1031
- reviveSnapshotWithCachePolicy: reviveSnapshotWithCachePolicy,
1032
- }, basePolicy, cachePolicy.timestamp);
1033
- }
1034
- default: {
1035
- if (process.env.NODE_ENV !== 'production') {
1036
- throw new Error("unrecognized cache policy: ".concat(JSON.stringify(cachePolicy)));
1037
- }
1038
- return defaultCachePolicy;
1039
- }
1040
- }
1041
- }
1042
701
  var applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildCachedSnapshot, buildNetworkSnapshot) {
1043
702
  validateNotDisposed();
1044
- var cachePolicy = adapterRequestContext.cachePolicy;
1045
- var cachePolicyImpl = resolveCachePolicy(cachePolicy);
1046
- var resolvePendingSnapshot = function (snapshot) {
1047
- return environment.resolvePendingSnapshot(snapshot);
703
+ var wrappedCacheLookup = function (buildSnapshotContext, storeLookup) {
704
+ var snapshot = buildCachedSnapshot(buildSnapshotContext, storeLookup);
705
+ // if the adapter attempted to do an L1 lookup and it was unfulfilled
706
+ // then we can attempt an L2 lookup
707
+ if (isUnfulfilledSnapshot(snapshot)) {
708
+ return reviveSnapshot(environment, durableStore, snapshot, durableStoreErrorHandler, function () { return storeLookup(snapshot.select, snapshot.refresh); });
709
+ }
710
+ // otherwise just return what buildCachedSnapshot gave us
711
+ return snapshot;
1048
712
  };
1049
- var storeLookup = function (sel, refresh, ttlStrategy) { return environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy); };
1050
713
  var applyCachePolicy = function () {
1051
- return cachePolicyImpl({
1052
- buildCachedSnapshot: buildCachedSnapshot,
1053
- buildNetworkSnapshot: buildNetworkSnapshot,
1054
- buildSnapshotContext: buildSnapshotContext,
1055
- resolvePendingSnapshot: resolvePendingSnapshot,
1056
- storeLookup: storeLookup,
1057
- coercedAdapterRequestContext: engine.coerceAdapterRequestContext(adapterRequestContext),
1058
- });
714
+ return environment.applyCachePolicy(adapterRequestContext, buildSnapshotContext, wrappedCacheLookup, buildNetworkSnapshot);
1059
715
  };
1060
716
  return isRevivingTTLOverrides !== undefined
1061
717
  ? isRevivingTTLOverrides.then(applyCachePolicy)
@@ -1093,6 +749,7 @@
1093
749
  return environment.storeLookup(snapshotFromMemoryIngest.select, environment.createSnapshot, snapshotFromMemoryIngest.refresh);
1094
750
  });
1095
751
  };
752
+ environment.defaultCachePolicy = engine.buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER);
1096
753
  return create(environment, {
1097
754
  publishStoreMetadata: { value: publishStoreMetadata },
1098
755
  storeIngest: { value: storeIngest },
@@ -1102,7 +759,6 @@
1102
759
  storeEvict: { value: storeEvict },
1103
760
  wrapNormalizedGraphNode: { value: wrapNormalizedGraphNode },
1104
761
  getNode: { value: getNode },
1105
- resolveSnapshot: { value: resolveSnapshot },
1106
762
  rebuildSnapshot: { value: rebuildSnapshot },
1107
763
  withContext: { value: withContext },
1108
764
  storeSetTTLOverride: { value: storeSetTTLOverride },
@@ -1112,7 +768,6 @@
1112
768
  dispose: { value: dispose },
1113
769
  publishChangesToDurableStore: { value: publishChangesToDurableStore },
1114
770
  getDurableTTLOverrides: { value: getDurableTTLOverrides },
1115
- defaultCachePolicy: { value: defaultCachePolicy },
1116
771
  applyCachePolicy: { value: applyCachePolicy },
1117
772
  getIngestStagingStoreRecords: { value: getIngestStagingStoreRecords },
1118
773
  getIngestStagingStoreMetadata: { value: getIngestStagingStoreMetadata },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/environments",
3
- "version": "0.71.0",
3
+ "version": "0.73.2",
4
4
  "description": "Luvio Environments",
5
5
  "main": "dist/umd/es2018/environments.js",
6
6
  "module": "dist/es/es2018/environments.js",
@@ -26,6 +26,6 @@
26
26
  "dist/"
27
27
  ],
28
28
  "dependencies": {
29
- "@luvio/engine": "0.71.0"
29
+ "@luvio/engine": "0.73.2"
30
30
  }
31
31
  }
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheAndNetworkImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds?: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheThenNetworkImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,6 +0,0 @@
1
- export { buildCacheAndNetworkImplementation } from './cache-and-network';
2
- export { buildCacheThenNetworkImplementation } from './cache-then-network';
3
- export { buildNoCacheImplementation } from './no-cache';
4
- export { buildOnlyIfCachedImplementation } from './only-if-cached';
5
- export { buildStaleWhileRevalidateImplementation } from './stale-while-revalidate';
6
- export { buildValidAtImplementation } from './valid-at';
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildNoCacheImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildOnlyIfCachedImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildStaleWhileRevalidateImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,9 +0,0 @@
1
- import { BuildCachedSnapshot, CachePolicyImplementationArgs, Snapshot, StoreLookup, TTLStrategy, UnAvailableSnapshot } from '@luvio/engine';
2
- export declare type DurableCachePolicyFunctions = {
3
- validateNotDisposed: () => void;
4
- reviveSnapshotWithCachePolicy: <D, V>(unavailableSnapshot: UnAvailableSnapshot<D, V>, storeLookup: StoreLookup<D, V>) => Promise<Snapshot<D, V>>;
5
- };
6
- export declare function appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<BuildCachedSnapshot<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;
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>>;
@@ -1,3 +0,0 @@
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>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheAndNetworkImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds?: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheThenNetworkImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,6 +0,0 @@
1
- export { buildCacheAndNetworkImplementation } from './cache-and-network';
2
- export { buildCacheThenNetworkImplementation } from './cache-then-network';
3
- export { buildNoCacheImplementation } from './no-cache';
4
- export { buildOnlyIfCachedImplementation } from './only-if-cached';
5
- export { buildStaleWhileRevalidateImplementation } from './stale-while-revalidate';
6
- export { buildValidAtImplementation } from './valid-at';
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildNoCacheImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildOnlyIfCachedImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildStaleWhileRevalidateImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,9 +0,0 @@
1
- import { BuildCachedSnapshot, CachePolicyImplementationArgs, Snapshot, StoreLookup, TTLStrategy, UnAvailableSnapshot } from '@luvio/engine';
2
- export declare type DurableCachePolicyFunctions = {
3
- validateNotDisposed: () => void;
4
- reviveSnapshotWithCachePolicy: <D, V>(unavailableSnapshot: UnAvailableSnapshot<D, V>, storeLookup: StoreLookup<D, V>) => Promise<Snapshot<D, V>>;
5
- };
6
- export declare function appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<BuildCachedSnapshot<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;
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>>;
@@ -1,3 +0,0 @@
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>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheAndNetworkImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds?: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheThenNetworkImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,6 +0,0 @@
1
- export { buildCacheAndNetworkImplementation } from './cache-and-network';
2
- export { buildCacheThenNetworkImplementation } from './cache-then-network';
3
- export { buildNoCacheImplementation } from './no-cache';
4
- export { buildOnlyIfCachedImplementation } from './only-if-cached';
5
- export { buildStaleWhileRevalidateImplementation } from './stale-while-revalidate';
6
- export { buildValidAtImplementation } from './valid-at';
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildNoCacheImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildOnlyIfCachedImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +0,0 @@
1
- import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
- import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildStaleWhileRevalidateImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;