@luvio/environments 0.63.0 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { StoreResolveResultState, HttpStatusCode, Store, buildStaleWhileRevalidateImplementation as buildStaleWhileRevalidateImplementation$1 } from '@luvio/engine';
1
+ import { StoreResolveResultState, HttpStatusCode, Store, coerceAdapterRequestContext, buildStaleWhileRevalidateImplementation as buildStaleWhileRevalidateImplementation$1 } from '@luvio/engine';
2
2
 
3
3
  function isDeprecatedDurableStoreEntry(durableRecord) {
4
4
  if (durableRecord.expiration !== undefined) {
@@ -21,8 +21,8 @@ function appendTTLStrategy(storeLookup, ttlStrategy) {
21
21
  return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
22
22
  }
23
23
  function buildNetworkSnapshot(args) {
24
- const { buildNetworkSnapshot, buildSnapshotContext } = args;
25
- return buildNetworkSnapshot(buildSnapshotContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
24
+ const { buildNetworkSnapshot, buildSnapshotContext, coercedAdapterRequestContext } = args;
25
+ return buildNetworkSnapshot(buildSnapshotContext, coercedAdapterRequestContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
26
26
  }
27
27
  function buildTTLStrategy(staleDurationMilliseconds = 0) {
28
28
  return (timestamp, metadata, valueIsError) => {
@@ -46,7 +46,7 @@ function buildTTLStrategy(staleDurationMilliseconds = 0) {
46
46
  function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
47
47
  return function (args) {
48
48
  funcs.validateNotDisposed();
49
- const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup } = args;
49
+ const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup, coercedAdapterRequestContext, } = args;
50
50
  const staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
51
51
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
52
52
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
@@ -54,14 +54,14 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
54
54
  // data found in L1 cache
55
55
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
56
56
  // kick off network request, do not await it
57
- buildNetworkSnapshot$1(buildSnapshotContext);
57
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
58
58
  // return the cached snapshot to caller
59
59
  return snapshot;
60
60
  }
61
61
  // network request outstanding
62
62
  if (snapshot.state === 'Pending') {
63
63
  // kick off another network request, do not await it
64
- buildNetworkSnapshot$1(buildSnapshotContext);
64
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
65
65
  return args.resolvePendingSnapshot(snapshot);
66
66
  }
67
67
  // stale data found in L1 cache
@@ -81,13 +81,13 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
81
81
  if (revivedSnapshot.state === 'Fulfilled' ||
82
82
  revivedSnapshot.state === 'Error') {
83
83
  // kick off network request, do not await it
84
- buildNetworkSnapshot$1(buildSnapshotContext);
84
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
85
85
  // return the L2 cached snapshot to caller
86
86
  return revivedSnapshot;
87
87
  }
88
88
  if (revivedSnapshot.state === 'Pending') {
89
89
  // kick off network request, do not await it
90
- buildNetworkSnapshot$1(buildSnapshotContext);
90
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
91
91
  return args.resolvePendingSnapshot(revivedSnapshot);
92
92
  }
93
93
  // stale data found in L2 cache
@@ -182,6 +182,8 @@ function buildNotCachedErrorSnapshot() {
182
182
  error,
183
183
  state: 'Error',
184
184
  data: undefined,
185
+ // TODO[@W-10164067]: copy refresh data from the snapshot returned by buildInMemorySnapshot (if any)
186
+ // refresh: ...
185
187
  };
186
188
  }
187
189
  function buildOnlyIfCachedImplementation(funcs) {
@@ -923,13 +925,17 @@ function makeDurable(environment, { durableStore, instrumentation }) {
923
925
  };
924
926
  const storeSetTTLOverride = function (namespace, representationName, ttl) {
925
927
  validateNotDisposed();
926
- durableTTLStore.setDurableTTLOverride(namespace, representationName, ttl);
927
- environment.storeSetTTLOverride(namespace, representationName, ttl);
928
+ return Promise.all([
929
+ environment.storeSetTTLOverride(namespace, representationName, ttl),
930
+ durableTTLStore.setDurableTTLOverride(namespace, representationName, ttl),
931
+ ]).then();
928
932
  };
929
933
  const storeSetDefaultTTLOverride = function (ttl) {
930
934
  validateNotDisposed();
931
- durableTTLStore.setDefaultDurableTTLOverrides(ttl);
932
- environment.storeSetDefaultTTLOverride(ttl);
935
+ return Promise.all([
936
+ environment.storeSetDefaultTTLOverride(ttl),
937
+ durableTTLStore.setDefaultDurableTTLOverrides(ttl),
938
+ ]).then();
933
939
  };
934
940
  const getDurableTTLOverrides = function () {
935
941
  validateNotDisposed();
@@ -989,7 +995,8 @@ function makeDurable(environment, { durableStore, instrumentation }) {
989
995
  }
990
996
  const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
991
997
  validateNotDisposed();
992
- const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
998
+ const { cachePolicy } = adapterRequestContext;
999
+ const cachePolicyImpl = resolveCachePolicy(cachePolicy);
993
1000
  const resolvePendingSnapshot = (snapshot) => environment.resolvePendingSnapshot(snapshot);
994
1001
  const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
995
1002
  const applyCachePolicy = () => {
@@ -999,6 +1006,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
999
1006
  buildSnapshotContext,
1000
1007
  resolvePendingSnapshot,
1001
1008
  storeLookup,
1009
+ coercedAdapterRequestContext: coerceAdapterRequestContext(adapterRequestContext),
1002
1010
  });
1003
1011
  };
1004
1012
  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>>;
@@ -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";
@@ -24,8 +25,8 @@
24
25
  return (sel, refresh) => storeLookup(sel, refresh, ttlStrategy);
25
26
  }
26
27
  function buildNetworkSnapshot(args) {
27
- const { buildNetworkSnapshot, buildSnapshotContext } = args;
28
- return buildNetworkSnapshot(buildSnapshotContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
28
+ const { buildNetworkSnapshot, buildSnapshotContext, coercedAdapterRequestContext } = args;
29
+ return buildNetworkSnapshot(buildSnapshotContext, coercedAdapterRequestContext).then((snapshot) => snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot);
29
30
  }
30
31
  function buildTTLStrategy(staleDurationMilliseconds = 0) {
31
32
  return (timestamp, metadata, valueIsError) => {
@@ -49,7 +50,7 @@
49
50
  function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
50
51
  return function (args) {
51
52
  funcs.validateNotDisposed();
52
- const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup } = args;
53
+ const { buildInMemorySnapshot, buildNetworkSnapshot: buildNetworkSnapshot$1, buildSnapshotContext, storeLookup, coercedAdapterRequestContext, } = args;
53
54
  const staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
54
55
  const cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
55
56
  const snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
@@ -57,14 +58,14 @@
57
58
  // data found in L1 cache
58
59
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
59
60
  // kick off network request, do not await it
60
- buildNetworkSnapshot$1(buildSnapshotContext);
61
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
61
62
  // return the cached snapshot to caller
62
63
  return snapshot;
63
64
  }
64
65
  // network request outstanding
65
66
  if (snapshot.state === 'Pending') {
66
67
  // kick off another network request, do not await it
67
- buildNetworkSnapshot$1(buildSnapshotContext);
68
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
68
69
  return args.resolvePendingSnapshot(snapshot);
69
70
  }
70
71
  // stale data found in L1 cache
@@ -84,13 +85,13 @@
84
85
  if (revivedSnapshot.state === 'Fulfilled' ||
85
86
  revivedSnapshot.state === 'Error') {
86
87
  // kick off network request, do not await it
87
- buildNetworkSnapshot$1(buildSnapshotContext);
88
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
88
89
  // return the L2 cached snapshot to caller
89
90
  return revivedSnapshot;
90
91
  }
91
92
  if (revivedSnapshot.state === 'Pending') {
92
93
  // kick off network request, do not await it
93
- buildNetworkSnapshot$1(buildSnapshotContext);
94
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
94
95
  return args.resolvePendingSnapshot(revivedSnapshot);
95
96
  }
96
97
  // stale data found in L2 cache
@@ -185,6 +186,8 @@
185
186
  error,
186
187
  state: 'Error',
187
188
  data: undefined,
189
+ // TODO[@W-10164067]: copy refresh data from the snapshot returned by buildInMemorySnapshot (if any)
190
+ // refresh: ...
188
191
  };
189
192
  }
190
193
  function buildOnlyIfCachedImplementation(funcs) {
@@ -926,13 +929,17 @@
926
929
  };
927
930
  const storeSetTTLOverride = function (namespace, representationName, ttl) {
928
931
  validateNotDisposed();
929
- durableTTLStore.setDurableTTLOverride(namespace, representationName, ttl);
930
- environment.storeSetTTLOverride(namespace, representationName, ttl);
932
+ return Promise.all([
933
+ environment.storeSetTTLOverride(namespace, representationName, ttl),
934
+ durableTTLStore.setDurableTTLOverride(namespace, representationName, ttl),
935
+ ]).then();
931
936
  };
932
937
  const storeSetDefaultTTLOverride = function (ttl) {
933
938
  validateNotDisposed();
934
- durableTTLStore.setDefaultDurableTTLOverrides(ttl);
935
- environment.storeSetDefaultTTLOverride(ttl);
939
+ return Promise.all([
940
+ environment.storeSetDefaultTTLOverride(ttl),
941
+ durableTTLStore.setDefaultDurableTTLOverrides(ttl),
942
+ ]).then();
936
943
  };
937
944
  const getDurableTTLOverrides = function () {
938
945
  validateNotDisposed();
@@ -992,7 +999,8 @@
992
999
  }
993
1000
  const applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
994
1001
  validateNotDisposed();
995
- const cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
1002
+ const { cachePolicy } = adapterRequestContext;
1003
+ const cachePolicyImpl = resolveCachePolicy(cachePolicy);
996
1004
  const resolvePendingSnapshot = (snapshot) => environment.resolvePendingSnapshot(snapshot);
997
1005
  const storeLookup = (sel, refresh, ttlStrategy) => environment.storeLookup(sel, environment.createSnapshot, refresh, ttlStrategy);
998
1006
  const applyCachePolicy = () => {
@@ -1002,6 +1010,7 @@
1002
1010
  buildSnapshotContext,
1003
1011
  resolvePendingSnapshot,
1004
1012
  storeLookup,
1013
+ coercedAdapterRequestContext: engine.coerceAdapterRequestContext(adapterRequestContext),
1005
1014
  });
1006
1015
  };
1007
1016
  return isRevivingTTLOverrides !== undefined
@@ -1118,4 +1127,4 @@
1118
1127
 
1119
1128
  Object.defineProperty(exports, '__esModule', { value: true });
1120
1129
 
1121
- })));
1130
+ }));
@@ -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>>;
@@ -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,12 +44,14 @@
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;
@@ -60,8 +63,8 @@
60
63
  };
61
64
  }
62
65
  function buildNetworkSnapshot(args) {
63
- var buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext;
64
- return buildNetworkSnapshot(buildSnapshotContext).then(function (snapshot) {
66
+ var buildNetworkSnapshot = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, coercedAdapterRequestContext = args.coercedAdapterRequestContext;
67
+ return buildNetworkSnapshot(buildSnapshotContext, coercedAdapterRequestContext).then(function (snapshot) {
65
68
  return snapshot.state === 'Pending' ? args.resolvePendingSnapshot(snapshot) : snapshot;
66
69
  });
67
70
  }
@@ -88,7 +91,7 @@
88
91
  function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
89
92
  return function (args) {
90
93
  funcs.validateNotDisposed();
91
- var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot$1 = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup;
94
+ var buildInMemorySnapshot = args.buildInMemorySnapshot, buildNetworkSnapshot$1 = args.buildNetworkSnapshot, buildSnapshotContext = args.buildSnapshotContext, storeLookup = args.storeLookup, coercedAdapterRequestContext = args.coercedAdapterRequestContext;
92
95
  var staleDurationMilliseconds = staleDurationSeconds === undefined ? undefined : staleDurationSeconds * 1000;
93
96
  var cachePolicyStoreLookup = appendTTLStrategy(storeLookup, buildTTLStrategy(staleDurationMilliseconds));
94
97
  var snapshot = buildInMemorySnapshot(buildSnapshotContext, cachePolicyStoreLookup);
@@ -96,14 +99,14 @@
96
99
  // data found in L1 cache
97
100
  if (snapshot.state === 'Fulfilled' || snapshot.state === 'Error') {
98
101
  // kick off network request, do not await it
99
- buildNetworkSnapshot$1(buildSnapshotContext);
102
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
100
103
  // return the cached snapshot to caller
101
104
  return snapshot;
102
105
  }
103
106
  // network request outstanding
104
107
  if (snapshot.state === 'Pending') {
105
108
  // kick off another network request, do not await it
106
- buildNetworkSnapshot$1(buildSnapshotContext);
109
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
107
110
  return args.resolvePendingSnapshot(snapshot);
108
111
  }
109
112
  // stale data found in L1 cache
@@ -123,13 +126,13 @@
123
126
  if (revivedSnapshot.state === 'Fulfilled' ||
124
127
  revivedSnapshot.state === 'Error') {
125
128
  // kick off network request, do not await it
126
- buildNetworkSnapshot$1(buildSnapshotContext);
129
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
127
130
  // return the L2 cached snapshot to caller
128
131
  return revivedSnapshot;
129
132
  }
130
133
  if (revivedSnapshot.state === 'Pending') {
131
134
  // kick off network request, do not await it
132
- buildNetworkSnapshot$1(buildSnapshotContext);
135
+ buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
133
136
  return args.resolvePendingSnapshot(revivedSnapshot);
134
137
  }
135
138
  // stale data found in L2 cache
@@ -224,6 +227,8 @@
224
227
  error: error,
225
228
  state: 'Error',
226
229
  data: undefined,
230
+ // TODO[@W-10164067]: copy refresh data from the snapshot returned by buildInMemorySnapshot (if any)
231
+ // refresh: ...
227
232
  };
228
233
  }
229
234
  function buildOnlyIfCachedImplementation(funcs) {
@@ -365,16 +370,16 @@
365
370
  for (var i = 0, len = selections.length; i < len; i++) {
366
371
  var selection = selections[i];
367
372
  if (selection.kind === 'Object') {
368
- nestedSelections = __spreadArrays(nestedSelections, getSelections(selection.selections));
373
+ nestedSelections = __spreadArray(__spreadArray([], nestedSelections, true), getSelections(selection.selections), true);
369
374
  }
370
375
  else if (selection.kind === 'Link') {
371
- nestedSelections = __spreadArrays(nestedSelections, getSelectionsFromFragment(selection.fragment));
376
+ nestedSelections = __spreadArray(__spreadArray([], nestedSelections, true), getSelectionsFromFragment(selection.fragment), true);
372
377
  }
373
378
  else {
374
379
  nonNestedSelections.push(selection);
375
380
  }
376
381
  }
377
- return __spreadArrays(nestedSelections, nonNestedSelections);
382
+ return __spreadArray(__spreadArray([], nestedSelections, true), nonNestedSelections, true);
378
383
  }
379
384
  function getSelectionsFromFragment(fragment) {
380
385
  var selections = [];
@@ -384,7 +389,7 @@
384
389
  var unionKeys = keys(unionSelections);
385
390
  for (var i = 0, len = unionKeys.length; i < len; i++) {
386
391
  var key = unionKeys[i];
387
- selections = __spreadArrays(selections, unionSelections[key].selections);
392
+ selections = __spreadArray(__spreadArray([], selections, true), unionSelections[key].selections, true);
388
393
  }
389
394
  }
390
395
  // if fragment has selections properties then get them
@@ -565,7 +570,7 @@
565
570
  var TTL_DURABLE_SEGMENT = 'TTL_DURABLE_SEGMENT';
566
571
  var TTL_DEFAULT_KEY = 'TTL_DEFAULT_KEY';
567
572
  function buildDurableTTLOverrideStoreKey(namespace, representationName) {
568
- return namespace + "::" + representationName;
573
+ return "".concat(namespace, "::").concat(representationName);
569
574
  }
570
575
  function isEntryDurableTTLOverride(entry) {
571
576
  if (typeof entry === 'object' && entry !== undefined && entry !== null) {
@@ -648,7 +653,7 @@
648
653
  }
649
654
  if (isArray(source)) {
650
655
  // TS doesn't trust that this new array is an array unless we cast it
651
- return __spreadArrays(source);
656
+ return __spreadArray([], source, true);
652
657
  }
653
658
  return __assign({}, source);
654
659
  }
@@ -946,7 +951,7 @@
946
951
  validateNotDisposed();
947
952
  var contextId = options.contextId, onContextLoaded = options.onContextLoaded;
948
953
  var context = undefined;
949
- 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);
950
955
  return function (config, requestContext) {
951
956
  if (context === undefined) {
952
957
  return contextAsPromise.then(function (revivedContext) {
@@ -967,13 +972,17 @@
967
972
  };
968
973
  var storeSetTTLOverride = function (namespace, representationName, ttl) {
969
974
  validateNotDisposed();
970
- durableTTLStore.setDurableTTLOverride(namespace, representationName, ttl);
971
- environment.storeSetTTLOverride(namespace, representationName, ttl);
975
+ return Promise.all([
976
+ environment.storeSetTTLOverride(namespace, representationName, ttl),
977
+ durableTTLStore.setDurableTTLOverride(namespace, representationName, ttl),
978
+ ]).then();
972
979
  };
973
980
  var storeSetDefaultTTLOverride = function (ttl) {
974
981
  validateNotDisposed();
975
- durableTTLStore.setDefaultDurableTTLOverrides(ttl);
976
- environment.storeSetDefaultTTLOverride(ttl);
982
+ return Promise.all([
983
+ environment.storeSetDefaultTTLOverride(ttl),
984
+ durableTTLStore.setDefaultDurableTTLOverrides(ttl),
985
+ ]).then();
977
986
  };
978
987
  var getDurableTTLOverrides = function () {
979
988
  validateNotDisposed();
@@ -1027,7 +1036,7 @@
1027
1036
  }
1028
1037
  default: {
1029
1038
  if (process.env.NODE_ENV !== 'production') {
1030
- throw new Error("unrecognized cache policy: " + JSON.stringify(cachePolicy));
1039
+ throw new Error("unrecognized cache policy: ".concat(JSON.stringify(cachePolicy)));
1031
1040
  }
1032
1041
  return defaultCachePolicy;
1033
1042
  }
@@ -1035,7 +1044,8 @@
1035
1044
  }
1036
1045
  var applyCachePolicy = function (adapterRequestContext, buildSnapshotContext, buildInMemorySnapshot, buildNetworkSnapshot) {
1037
1046
  validateNotDisposed();
1038
- var cachePolicyImpl = resolveCachePolicy(adapterRequestContext.cachePolicy);
1047
+ var cachePolicy = adapterRequestContext.cachePolicy;
1048
+ var cachePolicyImpl = resolveCachePolicy(cachePolicy);
1039
1049
  var resolvePendingSnapshot = function (snapshot) {
1040
1050
  return environment.resolvePendingSnapshot(snapshot);
1041
1051
  };
@@ -1047,6 +1057,7 @@
1047
1057
  buildSnapshotContext: buildSnapshotContext,
1048
1058
  resolvePendingSnapshot: resolvePendingSnapshot,
1049
1059
  storeLookup: storeLookup,
1060
+ coercedAdapterRequestContext: engine.coerceAdapterRequestContext(adapterRequestContext),
1050
1061
  });
1051
1062
  };
1052
1063
  return isRevivingTTLOverrides !== undefined
@@ -1162,4 +1173,4 @@
1162
1173
 
1163
1174
  Object.defineProperty(exports, '__esModule', { value: true });
1164
1175
 
1165
- })));
1176
+ }));
@@ -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>>;
@@ -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.63.0",
3
+ "version": "0.64.0",
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.63.0"
20
+ "@luvio/engine": "0.64.0"
21
21
  }
22
22
  }