@luvio/environments 0.62.3 → 0.63.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 (25) hide show
  1. package/dist/es/es2018/environments.js +51 -31
  2. package/dist/es/es2018/makeDurable/cachepolicies/cache-and-network.d.ts +1 -1
  3. package/dist/es/es2018/makeDurable/cachepolicies/cache-then-network.d.ts +1 -1
  4. package/dist/es/es2018/makeDurable/cachepolicies/no-cache.d.ts +1 -1
  5. package/dist/es/es2018/makeDurable/cachepolicies/only-if-cached.d.ts +2 -2
  6. package/dist/es/es2018/makeDurable/cachepolicies/stale-while-revalidate.d.ts +1 -1
  7. package/dist/es/es2018/makeDurable/cachepolicies/utils.d.ts +2 -1
  8. package/dist/es/es2018/utils/language.d.ts +1 -1
  9. package/dist/umd/es2018/environments.js +55 -34
  10. package/dist/umd/es2018/makeDurable/cachepolicies/cache-and-network.d.ts +1 -1
  11. package/dist/umd/es2018/makeDurable/cachepolicies/cache-then-network.d.ts +1 -1
  12. package/dist/umd/es2018/makeDurable/cachepolicies/no-cache.d.ts +1 -1
  13. package/dist/umd/es2018/makeDurable/cachepolicies/only-if-cached.d.ts +2 -2
  14. package/dist/umd/es2018/makeDurable/cachepolicies/stale-while-revalidate.d.ts +1 -1
  15. package/dist/umd/es2018/makeDurable/cachepolicies/utils.d.ts +2 -1
  16. package/dist/umd/es2018/utils/language.d.ts +1 -1
  17. package/dist/umd/es5/environments.js +87 -60
  18. package/dist/umd/es5/makeDurable/cachepolicies/cache-and-network.d.ts +1 -1
  19. package/dist/umd/es5/makeDurable/cachepolicies/cache-then-network.d.ts +1 -1
  20. package/dist/umd/es5/makeDurable/cachepolicies/no-cache.d.ts +1 -1
  21. package/dist/umd/es5/makeDurable/cachepolicies/only-if-cached.d.ts +2 -2
  22. package/dist/umd/es5/makeDurable/cachepolicies/stale-while-revalidate.d.ts +1 -1
  23. package/dist/umd/es5/makeDurable/cachepolicies/utils.d.ts +2 -1
  24. package/dist/umd/es5/utils/language.d.ts +1 -1
  25. package/package.json +2 -2
@@ -17,6 +17,13 @@ const DefaultDurableSegment = 'DEFAULT';
17
17
  const { keys, create, assign, freeze } = Object;
18
18
  const { isArray } = Array;
19
19
 
20
+ function appendTTLStrategy(storeLookup, ttlStrategy) {
21
+ return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
22
+ }
23
+ function buildNetworkSnapshot(args) {
24
+ const { buildNetworkSnapshot, buildSnapshotContext } = args;
25
+ return buildNetworkSnapshot(buildSnapshotContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
26
+ }
20
27
  function buildTTLStrategy(staleDurationMilliseconds = 0) {
21
28
  return (timestamp, metadata, valueIsError) => {
22
29
  if (metadata !== undefined) {
@@ -34,15 +41,12 @@ function buildTTLStrategy(staleDurationMilliseconds = 0) {
34
41
  }
35
42
  return StoreResolveResultState.Found;
36
43
  };
37
- }
38
- function appendTTLStrategy(storeLookup, ttlStrategy) {
39
- return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
40
44
  }
41
45
 
42
46
  function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
43
47
  return function (args) {
44
48
  funcs.validateNotDisposed();
45
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
49
+ const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup } = args;
46
50
  const staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
47
51
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
48
52
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
@@ -50,10 +54,16 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
50
54
  // data found in L1 cache
51
55
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
52
56
  // kick off network request, do not await it
53
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
57
+ buildNetworkSnapshot$1(buildSnapshotContext);
54
58
  // return the cached snapshot to caller
55
59
  return snapshot;
56
60
  }
61
+ // network request outstanding
62
+ if (snapshot.state === 'Pending') {
63
+ // kick off another network request, do not await it
64
+ buildNetworkSnapshot$1(buildSnapshotContext);
65
+ return args.resolvePendingSnapshot(snapshot);
66
+ }
57
67
  // stale data found in L1 cache
58
68
  if (snapshot.state === 'Stale') {
59
69
  // kick off network request, do not await it
@@ -71,11 +81,15 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
71
81
  if (revivedSnapshot.state === 'Fulfilled' ||
72
82
  revivedSnapshot.state === 'Error') {
73
83
  // kick off network request, do not await it
74
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
84
+ buildNetworkSnapshot$1(buildSnapshotContext);
75
85
  // return the L2 cached snapshot to caller
76
86
  return revivedSnapshot;
77
87
  }
78
- if (revivedSnapshot.state === 'Pending') ;
88
+ if (revivedSnapshot.state === 'Pending') {
89
+ // kick off network request, do not await it
90
+ buildNetworkSnapshot$1(buildSnapshotContext);
91
+ return args.resolvePendingSnapshot(revivedSnapshot);
92
+ }
79
93
  // stale data found in L2 cache
80
94
  if (revivedSnapshot.state === 'Stale') {
81
95
  // kick off network request, do not await it
@@ -85,19 +99,18 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
85
99
  return revivedSnapshot;
86
100
  }
87
101
  // data not found in L2 cache, go to the network
88
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
102
+ return buildNetworkSnapshot(args);
89
103
  });
90
104
  }
91
- if (snapshot.state === 'Pending') ;
92
105
  }
93
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
106
+ return buildNetworkSnapshot(args);
94
107
  };
95
108
  }
96
109
 
97
110
  function buildCacheThenNetworkImplementation(funcs) {
98
111
  return function (args) {
99
112
  funcs.validateNotDisposed();
100
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
113
+ const { buildInMemorySnapshot, buildSnapshotContext, storeLookup } = args;
101
114
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
102
115
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
103
116
  if (snapshot !== undefined) {
@@ -105,7 +118,9 @@ function buildCacheThenNetworkImplementation(funcs) {
105
118
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
106
119
  return snapshot;
107
120
  }
108
- if (snapshot.state === 'Pending') ;
121
+ if (snapshot.state === 'Pending') {
122
+ return args.resolvePendingSnapshot(snapshot);
123
+ }
109
124
  // data not found in L1 cache, try L2 cache
110
125
  return funcs
111
126
  .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
@@ -115,24 +130,22 @@ function buildCacheThenNetworkImplementation(funcs) {
115
130
  revivedSnapshot.state === 'Error') {
116
131
  return revivedSnapshot;
117
132
  }
118
- if (revivedSnapshot.state === 'Pending') ;
133
+ if (revivedSnapshot.state === 'Pending') {
134
+ return args.resolvePendingSnapshot(revivedSnapshot);
135
+ }
119
136
  // data not found in L2 cache, go to the network
120
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
137
+ return buildNetworkSnapshot(args);
121
138
  });
122
139
  }
123
140
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
124
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
141
+ return buildNetworkSnapshot(args);
125
142
  };
126
143
  }
127
144
 
128
145
  function buildNoCacheImplementation(funcs) {
129
146
  return function (args) {
130
147
  funcs.validateNotDisposed();
131
- const { buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest } = args;
132
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest).then((snapshot) => {
133
- if (snapshot.state === 'Pending') ;
134
- return snapshot;
135
- });
148
+ return buildNetworkSnapshot(args);
136
149
  };
137
150
  }
138
151
 
@@ -169,6 +182,8 @@ function buildNotCachedErrorSnapshot() {
169
182
  error,
170
183
  state: 'Error',
171
184
  data: undefined,
185
+ // TODO[@W-10164067]: copy refresh data from the snapshot returned by buildInMemorySnapshot (if any)
186
+ // refresh: ...
172
187
  };
173
188
  }
174
189
  function buildOnlyIfCachedImplementation(funcs) {
@@ -206,7 +221,7 @@ function buildOnlyIfCachedImplementation(funcs) {
206
221
  function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
207
222
  return function (args) {
208
223
  funcs.validateNotDisposed();
209
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
224
+ const { buildInMemorySnapshot, buildSnapshotContext, storeLookup } = args;
210
225
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationSeconds * 1000));
211
226
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
212
227
  if (snapshot !== undefined) {
@@ -214,11 +229,13 @@ function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
214
229
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
215
230
  return snapshot;
216
231
  }
217
- if (snapshot.state === 'Pending') ;
232
+ if (snapshot.state === 'Pending') {
233
+ return args.resolvePendingSnapshot(snapshot);
234
+ }
218
235
  // stale data found in L1 cache
219
236
  if (snapshot.state === 'Stale') {
220
- // offline environment is already doing this; uncomment once we get rid of offline environment
221
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
237
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
238
+ // buildNetworkSnapshot(args);
222
239
  return snapshot;
223
240
  }
224
241
  // data not found in L1 cache, try L2 cache
@@ -230,19 +247,21 @@ function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
230
247
  revivedSnapshot.state === 'Error') {
231
248
  return revivedSnapshot;
232
249
  }
233
- if (revivedSnapshot.state === 'Pending') ;
250
+ if (revivedSnapshot.state === 'Pending') {
251
+ return args.resolvePendingSnapshot(revivedSnapshot);
252
+ }
234
253
  // stale data found in L2 cache
235
254
  if (revivedSnapshot.state === 'Stale') {
236
- // offline environment is already doing this; uncomment once we get rid of offline environment
237
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
255
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
256
+ // buildNetworkSnapshot(args);
238
257
  return revivedSnapshot;
239
258
  }
240
259
  // data not found in L2 cache, go to the network
241
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
260
+ return buildNetworkSnapshot(args);
242
261
  });
243
262
  }
244
263
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
245
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
264
+ return buildNetworkSnapshot(args);
246
265
  };
247
266
  }
248
267
 
@@ -780,7 +799,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
780
799
  if (ingestStagingStore === null) {
781
800
  ingestStagingStore = new Store();
782
801
  }
783
- return environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
802
+ environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
784
803
  };
785
804
  const storeIngestError = function (key, errorSnapshot, storeMetadataParams, _storeOverride) {
786
805
  validateNotDisposed();
@@ -973,14 +992,15 @@ function makeDurable(environment, { durableStore, instrumentation }) {
973
992
  const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
974
993
  validateNotDisposed();
975
994
  const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
995
+ const resolvePendingSnapshot = (snapshot) => environment.resolvePendingSnapshot(snapshot);
976
996
  const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
977
997
  const applyCachePolicy = () => {
978
998
  return cachePolicyImpl({
979
999
  buildInMemorySnapshot,
980
1000
  buildNetworkSnapshot,
981
1001
  buildSnapshotContext,
1002
+ resolvePendingSnapshot,
982
1003
  storeLookup,
983
- dispatchResourceRequest: environment.dispatchResourceRequest,
984
1004
  });
985
1005
  };
986
1006
  return isRevivingTTLOverrides !== undefined
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheAndNetworkImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds?: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildCacheAndNetworkImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds?: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheThenNetworkImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildCacheThenNetworkImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildNoCacheImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildNoCacheImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
- import { CachePolicyImplementationArgs, ErrorSnapshot, Snapshot } from '@luvio/engine';
1
+ import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildOnlyIfCachedImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildOnlyIfCachedImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildStaleWhileRevalidateImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildStaleWhileRevalidateImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -3,5 +3,6 @@ export declare type DurableCachePolicyFunctions = {
3
3
  validateNotDisposed: () => void;
4
4
  reviveSnapshotWithCachePolicy: <D, V>(unavailableSnapshot: UnAvailableSnapshot<D, V>, storeLookup: StoreLookup<D, V>) => Promise<Snapshot<D, V>>;
5
5
  };
6
- export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
7
6
  export declare function appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<BuildInMemorySnapshot<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;
@@ -14,6 +14,6 @@ declare const keys: {
14
14
  <T_1 extends Function>(f: T_1): T_1;
15
15
  <T_2>(o: T_2): Readonly<T_2>;
16
16
  };
17
- declare const hasOwnProperty: (v: string | number | symbol) => boolean;
17
+ declare const hasOwnProperty: (v: PropertyKey) => boolean;
18
18
  declare const isArray: (arg: any) => arg is any[];
19
19
  export { create as ObjectCreate, keys as ObjectKeys, assign as ObjectAssign, freeze as ObjectFreeze, hasOwnProperty as ObjectPrototypeHasOwnProperty, isArray as ArrayIsArray, };
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@luvio/engine')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@luvio/engine'], factory) :
4
- (global = global || self, factory(global.luvioEnvironments = {}, global.luvioEngine));
5
- }(this, (function (exports, engine) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.luvioEnvironments = {}, global.luvioEngine));
5
+ })(this, (function (exports, engine) { 'use strict';
6
6
 
7
7
  function isDeprecatedDurableStoreEntry(durableRecord) {
8
8
  if (durableRecord.expiration !== undefined) {
@@ -11,6 +11,7 @@
11
11
  // Add more deprecated shape checks here
12
12
  return false;
13
13
  }
14
+ exports.DurableStoreOperationType = void 0;
14
15
  (function (DurableStoreOperationType) {
15
16
  DurableStoreOperationType["SetEntries"] = "setEntries";
16
17
  DurableStoreOperationType["EvictEntries"] = "evictEntries";
@@ -20,6 +21,13 @@
20
21
  const { keys, create, assign, freeze } = Object;
21
22
  const { isArray } = Array;
22
23
 
24
+ function appendTTLStrategy(storeLookup, ttlStrategy) {
25
+ return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
26
+ }
27
+ function buildNetworkSnapshot(args) {
28
+ const { buildNetworkSnapshot, buildSnapshotContext } = args;
29
+ return buildNetworkSnapshot(buildSnapshotContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
30
+ }
23
31
  function buildTTLStrategy(staleDurationMilliseconds = 0) {
24
32
  return (timestamp, metadata, valueIsError) => {
25
33
  if (metadata !== undefined) {
@@ -37,15 +45,12 @@
37
45
  }
38
46
  return engine.StoreResolveResultState.Found;
39
47
  };
40
- }
41
- function appendTTLStrategy(storeLookup, ttlStrategy) {
42
- return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
43
48
  }
44
49
 
45
50
  function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
46
51
  return function (args) {
47
52
  funcs.validateNotDisposed();
48
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
53
+ const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup } = args;
49
54
  const staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
50
55
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
51
56
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
@@ -53,10 +58,16 @@
53
58
  // data found in L1 cache
54
59
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
55
60
  // kick off network request, do not await it
56
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
61
+ buildNetworkSnapshot$1(buildSnapshotContext);
57
62
  // return the cached snapshot to caller
58
63
  return snapshot;
59
64
  }
65
+ // network request outstanding
66
+ if (snapshot.state === 'Pending') {
67
+ // kick off another network request, do not await it
68
+ buildNetworkSnapshot$1(buildSnapshotContext);
69
+ return args.resolvePendingSnapshot(snapshot);
70
+ }
60
71
  // stale data found in L1 cache
61
72
  if (snapshot.state === 'Stale') {
62
73
  // kick off network request, do not await it
@@ -74,11 +85,15 @@
74
85
  if (revivedSnapshot.state === 'Fulfilled' ||
75
86
  revivedSnapshot.state === 'Error') {
76
87
  // kick off network request, do not await it
77
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
88
+ buildNetworkSnapshot$1(buildSnapshotContext);
78
89
  // return the L2 cached snapshot to caller
79
90
  return revivedSnapshot;
80
91
  }
81
- if (revivedSnapshot.state === 'Pending') ;
92
+ if (revivedSnapshot.state === 'Pending') {
93
+ // kick off network request, do not await it
94
+ buildNetworkSnapshot$1(buildSnapshotContext);
95
+ return args.resolvePendingSnapshot(revivedSnapshot);
96
+ }
82
97
  // stale data found in L2 cache
83
98
  if (revivedSnapshot.state === 'Stale') {
84
99
  // kick off network request, do not await it
@@ -88,19 +103,18 @@
88
103
  return revivedSnapshot;
89
104
  }
90
105
  // data not found in L2 cache, go to the network
91
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
106
+ return buildNetworkSnapshot(args);
92
107
  });
93
108
  }
94
- if (snapshot.state === 'Pending') ;
95
109
  }
96
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
110
+ return buildNetworkSnapshot(args);
97
111
  };
98
112
  }
99
113
 
100
114
  function buildCacheThenNetworkImplementation(funcs) {
101
115
  return function (args) {
102
116
  funcs.validateNotDisposed();
103
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
117
+ const { buildInMemorySnapshot, buildSnapshotContext, storeLookup } = args;
104
118
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
105
119
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
106
120
  if (snapshot !== undefined) {
@@ -108,7 +122,9 @@
108
122
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
109
123
  return snapshot;
110
124
  }
111
- if (snapshot.state === 'Pending') ;
125
+ if (snapshot.state === 'Pending') {
126
+ return args.resolvePendingSnapshot(snapshot);
127
+ }
112
128
  // data not found in L1 cache, try L2 cache
113
129
  return funcs
114
130
  .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
@@ -118,24 +134,22 @@
118
134
  revivedSnapshot.state === 'Error') {
119
135
  return revivedSnapshot;
120
136
  }
121
- if (revivedSnapshot.state === 'Pending') ;
137
+ if (revivedSnapshot.state === 'Pending') {
138
+ return args.resolvePendingSnapshot(revivedSnapshot);
139
+ }
122
140
  // data not found in L2 cache, go to the network
123
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
141
+ return buildNetworkSnapshot(args);
124
142
  });
125
143
  }
126
144
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
127
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
145
+ return buildNetworkSnapshot(args);
128
146
  };
129
147
  }
130
148
 
131
149
  function buildNoCacheImplementation(funcs) {
132
150
  return function (args) {
133
151
  funcs.validateNotDisposed();
134
- const { buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest } = args;
135
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest).then((snapshot) => {
136
- if (snapshot.state === 'Pending') ;
137
- return snapshot;
138
- });
152
+ return buildNetworkSnapshot(args);
139
153
  };
140
154
  }
141
155
 
@@ -172,6 +186,8 @@
172
186
  error,
173
187
  state: 'Error',
174
188
  data: undefined,
189
+ // TODO[@W-10164067]: copy refresh data from the snapshot returned by buildInMemorySnapshot (if any)
190
+ // refresh: ...
175
191
  };
176
192
  }
177
193
  function buildOnlyIfCachedImplementation(funcs) {
@@ -209,7 +225,7 @@
209
225
  function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
210
226
  return function (args) {
211
227
  funcs.validateNotDisposed();
212
- const { buildInMemorySnapshot, buildNetworkSnapshot, buildSnapshotContext, dispatchResourceRequest, storeLookup, } = args;
228
+ const { buildInMemorySnapshot, buildSnapshotContext, storeLookup } = args;
213
229
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationSeconds * 1000));
214
230
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
215
231
  if (snapshot !== undefined) {
@@ -217,11 +233,13 @@
217
233
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
218
234
  return snapshot;
219
235
  }
220
- if (snapshot.state === 'Pending') ;
236
+ if (snapshot.state === 'Pending') {
237
+ return args.resolvePendingSnapshot(snapshot);
238
+ }
221
239
  // stale data found in L1 cache
222
240
  if (snapshot.state === 'Stale') {
223
- // offline environment is already doing this; uncomment once we get rid of offline environment
224
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
241
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
242
+ // buildNetworkSnapshot(args);
225
243
  return snapshot;
226
244
  }
227
245
  // data not found in L1 cache, try L2 cache
@@ -233,19 +251,21 @@
233
251
  revivedSnapshot.state === 'Error') {
234
252
  return revivedSnapshot;
235
253
  }
236
- if (revivedSnapshot.state === 'Pending') ;
254
+ if (revivedSnapshot.state === 'Pending') {
255
+ return args.resolvePendingSnapshot(revivedSnapshot);
256
+ }
237
257
  // stale data found in L2 cache
238
258
  if (revivedSnapshot.state === 'Stale') {
239
- // offline environment is already doing this; uncomment once we get rid of offline environment
240
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
259
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
260
+ // buildNetworkSnapshot(args);
241
261
  return revivedSnapshot;
242
262
  }
243
263
  // data not found in L2 cache, go to the network
244
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
264
+ return buildNetworkSnapshot(args);
245
265
  });
246
266
  }
247
267
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
248
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
268
+ return buildNetworkSnapshot(args);
249
269
  };
250
270
  }
251
271
 
@@ -783,7 +803,7 @@
783
803
  if (ingestStagingStore === null) {
784
804
  ingestStagingStore = new engine.Store();
785
805
  }
786
- return environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
806
+ environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
787
807
  };
788
808
  const storeIngestError = function (key, errorSnapshot, storeMetadataParams, _storeOverride) {
789
809
  validateNotDisposed();
@@ -976,14 +996,15 @@
976
996
  const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
977
997
  validateNotDisposed();
978
998
  const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
999
+ const resolvePendingSnapshot = (snapshot) => environment.resolvePendingSnapshot(snapshot);
979
1000
  const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
980
1001
  const applyCachePolicy = () => {
981
1002
  return cachePolicyImpl({
982
1003
  buildInMemorySnapshot,
983
1004
  buildNetworkSnapshot,
984
1005
  buildSnapshotContext,
1006
+ resolvePendingSnapshot,
985
1007
  storeLookup,
986
- dispatchResourceRequest: environment.dispatchResourceRequest,
987
1008
  });
988
1009
  };
989
1010
  return isRevivingTTLOverrides !== undefined
@@ -1100,4 +1121,4 @@
1100
1121
 
1101
1122
  Object.defineProperty(exports, '__esModule', { value: true });
1102
1123
 
1103
- })));
1124
+ }));
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheAndNetworkImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds?: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildCacheAndNetworkImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds?: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheThenNetworkImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildCacheThenNetworkImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildNoCacheImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildNoCacheImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
- import { CachePolicyImplementationArgs, ErrorSnapshot, Snapshot } from '@luvio/engine';
1
+ import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildOnlyIfCachedImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildOnlyIfCachedImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildStaleWhileRevalidateImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildStaleWhileRevalidateImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -3,5 +3,6 @@ export declare type DurableCachePolicyFunctions = {
3
3
  validateNotDisposed: () => void;
4
4
  reviveSnapshotWithCachePolicy: <D, V>(unavailableSnapshot: UnAvailableSnapshot<D, V>, storeLookup: StoreLookup<D, V>) => Promise<Snapshot<D, V>>;
5
5
  };
6
- export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
7
6
  export declare function appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<BuildInMemorySnapshot<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;
@@ -14,6 +14,6 @@ declare const keys: {
14
14
  <T_1 extends Function>(f: T_1): T_1;
15
15
  <T_2>(o: T_2): Readonly<T_2>;
16
16
  };
17
- declare const hasOwnProperty: (v: string | number | symbol) => boolean;
17
+ declare const hasOwnProperty: (v: PropertyKey) => boolean;
18
18
  declare const isArray: (arg: any) => arg is any[];
19
19
  export { create as ObjectCreate, keys as ObjectKeys, assign as ObjectAssign, freeze as ObjectFreeze, hasOwnProperty as ObjectPrototypeHasOwnProperty, isArray as ArrayIsArray, };
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@luvio/engine')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@luvio/engine'], factory) :
4
- (global = global || self, factory(global.luvioEnvironments = {}, global.luvioEngine));
5
- }(this, (function (exports, engine) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.luvioEnvironments = {}, global.luvioEngine));
5
+ })(this, (function (exports, engine) { 'use strict';
6
6
 
7
7
  function isDeprecatedDurableStoreEntry(durableRecord) {
8
8
  if (durableRecord.expiration !== undefined) {
@@ -11,6 +11,7 @@
11
11
  // Add more deprecated shape checks here
12
12
  return false;
13
13
  }
14
+ exports.DurableStoreOperationType = void 0;
14
15
  (function (DurableStoreOperationType) {
15
16
  DurableStoreOperationType["SetEntries"] = "setEntries";
16
17
  DurableStoreOperationType["EvictEntries"] = "evictEntries";
@@ -18,18 +19,18 @@
18
19
  var DefaultDurableSegment = 'DEFAULT';
19
20
 
20
21
  /*! *****************************************************************************
21
- Copyright (c) Microsoft Corporation. All rights reserved.
22
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
23
- this file except in compliance with the License. You may obtain a copy of the
24
- License at http://www.apache.org/licenses/LICENSE-2.0
22
+ Copyright (c) Microsoft Corporation.
25
23
 
26
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
27
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
28
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
29
- MERCHANTABLITY OR NON-INFRINGEMENT.
24
+ Permission to use, copy, modify, and/or distribute this software for any
25
+ purpose with or without fee is hereby granted.
30
26
 
31
- See the Apache Version 2.0 License for specific language governing permissions
32
- and limitations under the License.
27
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
28
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
30
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
31
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
32
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
33
+ PERFORMANCE OF THIS SOFTWARE.
33
34
  ***************************************************************************** */
34
35
 
35
36
  var __assign = function() {
@@ -43,17 +44,30 @@
43
44
  return __assign.apply(this, arguments);
44
45
  };
45
46
 
46
- function __spreadArrays() {
47
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
48
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
49
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
50
- r[k] = a[j];
51
- return r;
47
+ function __spreadArray(to, from, pack) {
48
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
49
+ if (ar || !(i in from)) {
50
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
51
+ ar[i] = from[i];
52
+ }
53
+ }
54
+ return to.concat(ar || Array.prototype.slice.call(from));
52
55
  }
53
56
 
54
57
  var keys = Object.keys, create = Object.create, assign = Object.assign, freeze = Object.freeze;
55
58
  var isArray = Array.isArray;
56
59
 
60
+ function appendTTLStrategy(storeLookup, ttlStrategy) {
61
+ return function (sel, refresh) {
62
+ return storeLookup(sel, refresh, ttlStrategy);
63
+ };
64
+ }
65
+ function buildNetworkSnapshot(args) {
66
+ var buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext;
67
+ return buildNetworkSnapshot(buildSnapshotContext).then(function (snapshot) {
68
+ return snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot;
69
+ });
70
+ }
57
71
  function buildTTLStrategy(staleDurationMilliseconds) {
58
72
  if (staleDurationMilliseconds === void 0) { staleDurationMilliseconds = 0; }
59
73
  return function (timestamp, metadata, valueIsError) {
@@ -72,17 +86,12 @@
72
86
  }
73
87
  return engine.StoreResolveResultState.Found;
74
88
  };
75
- }
76
- function appendTTLStrategy(storeLookup, ttlStrategy) {
77
- return function (sel, refresh) {
78
- return storeLookup(sel, refresh, ttlStrategy);
79
- };
80
89
  }
81
90
 
82
91
  function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
83
92
  return function (args) {
84
93
  funcs.validateNotDisposed();
85
- var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, dispatchResourceRequest = args.dispatchResourceRequest, storeLookup = args.storeLookup;
94
+ var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot$1 = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
86
95
  var staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
87
96
  var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
88
97
  var snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
@@ -90,10 +99,16 @@
90
99
  // data found in L1 cache
91
100
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
92
101
  // kick off network request, do not await it
93
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
102
+ buildNetworkSnapshot$1(buildSnapshotContext);
94
103
  // return the cached snapshot to caller
95
104
  return snapshot;
96
105
  }
106
+ // network request outstanding
107
+ if (snapshot.state === 'Pending') {
108
+ // kick off another network request, do not await it
109
+ buildNetworkSnapshot$1(buildSnapshotContext);
110
+ return args.resolvePendingSnapshot(snapshot);
111
+ }
97
112
  // stale data found in L1 cache
98
113
  if (snapshot.state === 'Stale') {
99
114
  // kick off network request, do not await it
@@ -111,11 +126,15 @@
111
126
  if (revivedSnapshot.state === 'Fulfilled' ||
112
127
  revivedSnapshot.state === 'Error') {
113
128
  // kick off network request, do not await it
114
- buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
129
+ buildNetworkSnapshot$1(buildSnapshotContext);
115
130
  // return the L2 cached snapshot to caller
116
131
  return revivedSnapshot;
117
132
  }
118
- if (revivedSnapshot.state === 'Pending') ;
133
+ if (revivedSnapshot.state === 'Pending') {
134
+ // kick off network request, do not await it
135
+ buildNetworkSnapshot$1(buildSnapshotContext);
136
+ return args.resolvePendingSnapshot(revivedSnapshot);
137
+ }
119
138
  // stale data found in L2 cache
120
139
  if (revivedSnapshot.state === 'Stale') {
121
140
  // kick off network request, do not await it
@@ -125,19 +144,18 @@
125
144
  return revivedSnapshot;
126
145
  }
127
146
  // data not found in L2 cache, go to the network
128
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
147
+ return buildNetworkSnapshot(args);
129
148
  });
130
149
  }
131
- if (snapshot.state === 'Pending') ;
132
150
  }
133
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
151
+ return buildNetworkSnapshot(args);
134
152
  };
135
153
  }
136
154
 
137
155
  function buildCacheThenNetworkImplementation(funcs) {
138
156
  return function (args) {
139
157
  funcs.validateNotDisposed();
140
- var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, dispatchResourceRequest = args.dispatchResourceRequest, storeLookup = args.storeLookup;
158
+ var buildInMemorySnapshot = args.buildInMemorySnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
141
159
  var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy());
142
160
  var snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
143
161
  if (snapshot !== undefined) {
@@ -145,7 +163,9 @@
145
163
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
146
164
  return snapshot;
147
165
  }
148
- if (snapshot.state === 'Pending') ;
166
+ if (snapshot.state === 'Pending') {
167
+ return args.resolvePendingSnapshot(snapshot);
168
+ }
149
169
  // data not found in L1 cache, try L2 cache
150
170
  return funcs
151
171
  .reviveSnapshotWithCachePolicy(snapshot, cachePolicyStoreLookup)
@@ -155,24 +175,22 @@
155
175
  revivedSnapshot.state === 'Error') {
156
176
  return revivedSnapshot;
157
177
  }
158
- if (revivedSnapshot.state === 'Pending') ;
178
+ if (revivedSnapshot.state === 'Pending') {
179
+ return args.resolvePendingSnapshot(revivedSnapshot);
180
+ }
159
181
  // data not found in L2 cache, go to the network
160
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
182
+ return buildNetworkSnapshot(args);
161
183
  });
162
184
  }
163
185
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
164
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
186
+ return buildNetworkSnapshot(args);
165
187
  };
166
188
  }
167
189
 
168
190
  function buildNoCacheImplementation(funcs) {
169
191
  return function (args) {
170
192
  funcs.validateNotDisposed();
171
- var buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, dispatchResourceRequest = args.dispatchResourceRequest;
172
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest).then(function (snapshot) {
173
- if (snapshot.state === 'Pending') ;
174
- return snapshot;
175
- });
193
+ return buildNetworkSnapshot(args);
176
194
  };
177
195
  }
178
196
 
@@ -209,6 +227,8 @@
209
227
  error: error,
210
228
  state: 'Error',
211
229
  data: undefined,
230
+ // TODO[@W-10164067]: copy refresh data from the snapshot returned by buildInMemorySnapshot (if any)
231
+ // refresh: ...
212
232
  };
213
233
  }
214
234
  function buildOnlyIfCachedImplementation(funcs) {
@@ -246,7 +266,7 @@
246
266
  function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
247
267
  return function (args) {
248
268
  funcs.validateNotDisposed();
249
- var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, dispatchResourceRequest = args.dispatchResourceRequest, storeLookup = args.storeLookup;
269
+ var buildInMemorySnapshot = args.buildInMemorySnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
250
270
  var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationSeconds * 1000));
251
271
  var snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
252
272
  if (snapshot !== undefined) {
@@ -254,11 +274,13 @@
254
274
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
255
275
  return snapshot;
256
276
  }
257
- if (snapshot.state === 'Pending') ;
277
+ if (snapshot.state === 'Pending') {
278
+ return args.resolvePendingSnapshot(snapshot);
279
+ }
258
280
  // stale data found in L1 cache
259
281
  if (snapshot.state === 'Stale') {
260
- // offline environment is already doing this; uncomment once we get rid of offline environment
261
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
282
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
283
+ // buildNetworkSnapshot(args);
262
284
  return snapshot;
263
285
  }
264
286
  // data not found in L1 cache, try L2 cache
@@ -270,19 +292,21 @@
270
292
  revivedSnapshot.state === 'Error') {
271
293
  return revivedSnapshot;
272
294
  }
273
- if (revivedSnapshot.state === 'Pending') ;
295
+ if (revivedSnapshot.state === 'Pending') {
296
+ return args.resolvePendingSnapshot(revivedSnapshot);
297
+ }
274
298
  // stale data found in L2 cache
275
299
  if (revivedSnapshot.state === 'Stale') {
276
- // offline environment is already doing this; uncomment once we get rid of offline environment
277
- // buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
300
+ // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
301
+ // buildNetworkSnapshot(args);
278
302
  return revivedSnapshot;
279
303
  }
280
304
  // data not found in L2 cache, go to the network
281
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
305
+ return buildNetworkSnapshot(args);
282
306
  });
283
307
  }
284
308
  // L1 lookup could not find enough information to even construct a snapshot, go to the network
285
- return buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
309
+ return buildNetworkSnapshot(args);
286
310
  };
287
311
  }
288
312
 
@@ -346,16 +370,16 @@
346
370
  for (var i = 0, len = selections.length; i < len; i++) {
347
371
  var selection = selections[i];
348
372
  if (selection.kind === 'Object') {
349
- nestedSelections = __spreadArrays(nestedSelections, getSelections(selection.selections));
373
+ nestedSelections = __spreadArray(__spreadArray([], nestedSelections, true), getSelections(selection.selections), true);
350
374
  }
351
375
  else if (selection.kind === 'Link') {
352
- nestedSelections = __spreadArrays(nestedSelections, getSelectionsFromFragment(selection.fragment));
376
+ nestedSelections = __spreadArray(__spreadArray([], nestedSelections, true), getSelectionsFromFragment(selection.fragment), true);
353
377
  }
354
378
  else {
355
379
  nonNestedSelections.push(selection);
356
380
  }
357
381
  }
358
- return __spreadArrays(nestedSelections, nonNestedSelections);
382
+ return __spreadArray(__spreadArray([], nestedSelections, true), nonNestedSelections, true);
359
383
  }
360
384
  function getSelectionsFromFragment(fragment) {
361
385
  var selections = [];
@@ -365,7 +389,7 @@
365
389
  var unionKeys = keys(unionSelections);
366
390
  for (var i = 0, len = unionKeys.length; i < len; i++) {
367
391
  var key = unionKeys[i];
368
- selections = __spreadArrays(selections, unionSelections[key].selections);
392
+ selections = __spreadArray(__spreadArray([], selections, true), unionSelections[key].selections, true);
369
393
  }
370
394
  }
371
395
  // if fragment has selections properties then get them
@@ -546,7 +570,7 @@
546
570
  var TTL_DURABLE_SEGMENT = 'TTL_DURABLE_SEGMENT';
547
571
  var TTL_DEFAULT_KEY = 'TTL_DEFAULT_KEY';
548
572
  function buildDurableTTLOverrideStoreKey(namespace, representationName) {
549
- return namespace + "::" + representationName;
573
+ return "".concat(namespace, "::").concat(representationName);
550
574
  }
551
575
  function isEntryDurableTTLOverride(entry) {
552
576
  if (typeof entry === 'object' && entry !== undefined && entry !== null) {
@@ -629,7 +653,7 @@
629
653
  }
630
654
  if (isArray(source)) {
631
655
  // TS doesn't trust that this new array is an array unless we cast it
632
- return __spreadArrays(source);
656
+ return __spreadArray([], source, true);
633
657
  }
634
658
  return __assign({}, source);
635
659
  }
@@ -821,7 +845,7 @@
821
845
  if (ingestStagingStore === null) {
822
846
  ingestStagingStore = new engine.Store();
823
847
  }
824
- return environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
848
+ environment.storeIngest(key, ingest, response, luvio, ingestStagingStore);
825
849
  };
826
850
  var storeIngestError = function (key, errorSnapshot, storeMetadataParams, _storeOverride) {
827
851
  validateNotDisposed();
@@ -927,7 +951,7 @@
927
951
  validateNotDisposed();
928
952
  var contextId = options.contextId, onContextLoaded = options.onContextLoaded;
929
953
  var context = undefined;
930
- var contextAsPromise = reviveOrCreateContext(contextId === undefined ? adapter.name : "" + contextId + ADAPTER_CONTEXT_ID_SUFFIX, durableStore, durableStoreErrorHandler, onContextLoaded);
954
+ var contextAsPromise = reviveOrCreateContext(contextId === undefined ? adapter.name : "".concat(contextId).concat(ADAPTER_CONTEXT_ID_SUFFIX), durableStore, durableStoreErrorHandler, onContextLoaded);
931
955
  return function (config, requestContext) {
932
956
  if (context === undefined) {
933
957
  return contextAsPromise.then(function (revivedContext) {
@@ -1008,7 +1032,7 @@
1008
1032
  }
1009
1033
  default: {
1010
1034
  if (process.env.NODE_ENV !== 'production') {
1011
- throw new Error("unrecognized cache policy: " + JSON.stringify(cachePolicy));
1035
+ throw new Error("unrecognized cache policy: ".concat(JSON.stringify(cachePolicy)));
1012
1036
  }
1013
1037
  return defaultCachePolicy;
1014
1038
  }
@@ -1017,14 +1041,17 @@
1017
1041
  var applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
1018
1042
  validateNotDisposed();
1019
1043
  var cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
1044
+ var resolvePendingSnapshot = function (snapshot) {
1045
+ return environment.resolvePendingSnapshot(snapshot);
1046
+ };
1020
1047
  var storeLookup = function (sel, refresh, ttlStrategy) { return environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy); };
1021
1048
  var applyCachePolicy = function () {
1022
1049
  return cachePolicyImpl({
1023
1050
  buildInMemorySnapshot: buildInMemorySnapshot,
1024
1051
  buildNetworkSnapshot: buildNetworkSnapshot,
1025
1052
  buildSnapshotContext: buildSnapshotContext,
1053
+ resolvePendingSnapshot: resolvePendingSnapshot,
1026
1054
  storeLookup: storeLookup,
1027
- dispatchResourceRequest: environment.dispatchResourceRequest,
1028
1055
  });
1029
1056
  };
1030
1057
  return isRevivingTTLOverrides !== undefined
@@ -1140,4 +1167,4 @@
1140
1167
 
1141
1168
  Object.defineProperty(exports, '__esModule', { value: true });
1142
1169
 
1143
- })));
1170
+ }));
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheAndNetworkImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds?: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildCacheAndNetworkImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds?: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildCacheThenNetworkImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildCacheThenNetworkImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildNoCacheImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildNoCacheImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
- import { CachePolicyImplementationArgs, ErrorSnapshot, Snapshot } from '@luvio/engine';
1
+ import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildOnlyIfCachedImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildOnlyIfCachedImplementation(funcs: DurableCachePolicyFunctions): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -1,3 +1,3 @@
1
1
  import { CachePolicyImplementationArgs, Snapshot } from '@luvio/engine';
2
2
  import { DurableCachePolicyFunctions } from './utils';
3
- export declare function buildStaleWhileRevalidateImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => import("@luvio/engine").ErrorSnapshot | import("@luvio/engine").FulfilledSnapshot<D, unknown> | import("@luvio/engine").UnfulfilledSnapshot<D, unknown> | import("@luvio/engine").StaleSnapshot<D, unknown> | import("@luvio/engine").PendingSnapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
3
+ export declare function buildStaleWhileRevalidateImplementation(funcs: DurableCachePolicyFunctions, staleDurationSeconds: number): <C, D>(args: CachePolicyImplementationArgs<C, D>) => Snapshot<D, unknown> | Promise<Snapshot<D, unknown>>;
@@ -3,5 +3,6 @@ export declare type DurableCachePolicyFunctions = {
3
3
  validateNotDisposed: () => void;
4
4
  reviveSnapshotWithCachePolicy: <D, V>(unavailableSnapshot: UnAvailableSnapshot<D, V>, storeLookup: StoreLookup<D, V>) => Promise<Snapshot<D, V>>;
5
5
  };
6
- export declare function buildTTLStrategy(staleDurationMilliseconds?: number): TTLStrategy;
7
6
  export declare function appendTTLStrategy<C, D>(storeLookup: CachePolicyImplementationArgs<C, D>['storeLookup'], ttlStrategy: TTLStrategy): Parameters<BuildInMemorySnapshot<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;
@@ -14,6 +14,6 @@ declare const keys: {
14
14
  <T_1 extends Function>(f: T_1): T_1;
15
15
  <T_2>(o: T_2): Readonly<T_2>;
16
16
  };
17
- declare const hasOwnProperty: (v: string | number | symbol) => boolean;
17
+ declare const hasOwnProperty: (v: PropertyKey) => boolean;
18
18
  declare const isArray: (arg: any) => arg is any[];
19
19
  export { create as ObjectCreate, keys as ObjectKeys, assign as ObjectAssign, freeze as ObjectFreeze, hasOwnProperty as ObjectPrototypeHasOwnProperty, isArray as ArrayIsArray, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/environments",
3
- "version": "0.62.3",
3
+ "version": "0.63.2",
4
4
  "description": "Luvio Environments",
5
5
  "main": "dist/umd/es2018/environments.js",
6
6
  "module": "dist/es/es2018/environments.js",
@@ -17,6 +17,6 @@
17
17
  "dist/"
18
18
  ],
19
19
  "dependencies": {
20
- "@luvio/engine": "0.62.3"
20
+ "@luvio/engine": "0.63.2"
21
21
  }
22
22
  }