@luvio/environments 0.65.0 → 0.69.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.
- package/dist/es/es2018/environments.js +15 -66
- package/dist/es/es2018/main.d.ts +0 -1
- package/dist/es/es2018/makeDurable.d.ts +1 -1
- package/dist/umd/es2018/environments.js +13 -65
- package/dist/umd/es2018/main.d.ts +0 -1
- package/dist/umd/es2018/makeDurable.d.ts +1 -1
- package/dist/umd/es5/environments.js +13 -62
- package/dist/umd/es5/main.d.ts +0 -1
- package/dist/umd/es5/makeDurable.d.ts +1 -1
- package/package.json +11 -2
- package/dist/es/es2018/makeOffline.d.ts +0 -13
- package/dist/umd/es2018/makeOffline.d.ts +0 -13
- package/dist/umd/es5/makeOffline.d.ts +0 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StoreResolveResultState, HttpStatusCode, Store, coerceAdapterRequestContext
|
|
1
|
+
import { StoreResolveResultState, HttpStatusCode, Store, coerceAdapterRequestContext } from '@luvio/engine';
|
|
2
2
|
|
|
3
3
|
function isDeprecatedDurableStoreEntry(durableRecord) {
|
|
4
4
|
if (durableRecord.expiration !== undefined) {
|
|
@@ -67,8 +67,7 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
|
|
|
67
67
|
// stale data found in L1 cache
|
|
68
68
|
if (snapshot.state === 'Stale') {
|
|
69
69
|
// kick off network request, do not await it
|
|
70
|
-
|
|
71
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
70
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
72
71
|
// return the cached snapshot to caller
|
|
73
72
|
return snapshot;
|
|
74
73
|
}
|
|
@@ -93,8 +92,7 @@ function buildCacheAndNetworkImplementation(funcs, staleDurationSeconds) {
|
|
|
93
92
|
// stale data found in L2 cache
|
|
94
93
|
if (revivedSnapshot.state === 'Stale') {
|
|
95
94
|
// kick off network request, do not await it
|
|
96
|
-
|
|
97
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
95
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
98
96
|
// return the L2 cached snapshot to caller
|
|
99
97
|
return revivedSnapshot;
|
|
100
98
|
}
|
|
@@ -234,8 +232,7 @@ function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
|
|
|
234
232
|
}
|
|
235
233
|
// stale data found in L1 cache
|
|
236
234
|
if (snapshot.state === 'Stale') {
|
|
237
|
-
|
|
238
|
-
// buildNetworkSnapshot(args);
|
|
235
|
+
buildNetworkSnapshot(args);
|
|
239
236
|
return snapshot;
|
|
240
237
|
}
|
|
241
238
|
// data not found in L1 cache, try L2 cache
|
|
@@ -252,8 +249,7 @@ function buildStaleWhileRevalidateImplementation(funcs, staleDurationSeconds) {
|
|
|
252
249
|
}
|
|
253
250
|
// stale data found in L2 cache
|
|
254
251
|
if (revivedSnapshot.state === 'Stale') {
|
|
255
|
-
|
|
256
|
-
// buildNetworkSnapshot(args);
|
|
252
|
+
buildNetworkSnapshot(args);
|
|
257
253
|
return revivedSnapshot;
|
|
258
254
|
}
|
|
259
255
|
// data not found in L2 cache, go to the network
|
|
@@ -432,13 +428,12 @@ function publishDurableStoreEntries(durableRecords, publish, publishMetadata) {
|
|
|
432
428
|
}
|
|
433
429
|
// We don't want to revive a cached value if it's an error and it's
|
|
434
430
|
// expirationTimestamp TTL is expired, otherwise we would never hit the network
|
|
435
|
-
// during resolveSnapshot or rebuildSnapshot
|
|
436
|
-
// environment because the way the Reader works.
|
|
431
|
+
// during resolveSnapshot or rebuildSnapshot because the way the Reader works.
|
|
437
432
|
// If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
|
|
438
433
|
// if stale TTL is expired. But it will return ErrorSnapshot (instead of
|
|
439
434
|
// StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
|
|
440
|
-
// In
|
|
441
|
-
//
|
|
435
|
+
// In our environment the stale TTL is maxed out so Reader will always
|
|
436
|
+
// return ErrorSnapshot.
|
|
442
437
|
if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
|
|
443
438
|
continue;
|
|
444
439
|
}
|
|
@@ -826,15 +821,15 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
826
821
|
ingestStagingStore = null;
|
|
827
822
|
return promise;
|
|
828
823
|
};
|
|
829
|
-
const storeLookup = function (sel, createSnapshot, refresh) {
|
|
824
|
+
const storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
|
|
830
825
|
validateNotDisposed();
|
|
831
826
|
// if this lookup is right after an ingest there will be a staging store
|
|
832
827
|
if (ingestStagingStore !== null) {
|
|
833
|
-
return ingestStagingStore.lookup(sel, createSnapshot, refresh);
|
|
828
|
+
return ingestStagingStore.lookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
834
829
|
}
|
|
835
830
|
// otherwise this is from buildInMemorySnapshot and we should use the luvio
|
|
836
831
|
// L1 store
|
|
837
|
-
return environment.storeLookup(sel, createSnapshot, refresh);
|
|
832
|
+
return environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
838
833
|
};
|
|
839
834
|
const storeEvict = function (key) {
|
|
840
835
|
validateNotDisposed();
|
|
@@ -1034,6 +1029,9 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
1034
1029
|
ingestStagingStore.records = existingRecords;
|
|
1035
1030
|
}
|
|
1036
1031
|
const snapshotFromMemoryIngest = ingestAndBroadcastFunc();
|
|
1032
|
+
if (snapshotFromMemoryIngest === undefined) {
|
|
1033
|
+
return undefined;
|
|
1034
|
+
}
|
|
1037
1035
|
if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
|
|
1038
1036
|
return snapshotFromMemoryIngest;
|
|
1039
1037
|
}
|
|
@@ -1067,53 +1065,4 @@ function makeDurable(environment, { durableStore, instrumentation }) {
|
|
|
1067
1065
|
});
|
|
1068
1066
|
}
|
|
1069
1067
|
|
|
1070
|
-
|
|
1071
|
-
* This environment allows for stale snapshot emits.
|
|
1072
|
-
*
|
|
1073
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
1074
|
-
* emitted is the result of a storeLookup.
|
|
1075
|
-
*
|
|
1076
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
1077
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
1078
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
1079
|
-
* cause a network refresh to happen).
|
|
1080
|
-
*/
|
|
1081
|
-
function makeOffline(environment) {
|
|
1082
|
-
const storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
|
|
1083
|
-
const snapshot = environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
1084
|
-
// if the snapshot is stale we want to kick off a refresh
|
|
1085
|
-
if (snapshot.state === 'Stale') {
|
|
1086
|
-
if (refresh !== undefined) {
|
|
1087
|
-
const { resolve, config } = refresh;
|
|
1088
|
-
resolve(config);
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
return snapshot;
|
|
1092
|
-
};
|
|
1093
|
-
const snapshotAvailable = function (snapshot) {
|
|
1094
|
-
if (snapshot.state === 'Stale') {
|
|
1095
|
-
return true;
|
|
1096
|
-
}
|
|
1097
|
-
return environment.snapshotAvailable(snapshot);
|
|
1098
|
-
};
|
|
1099
|
-
const publishStoreMetadata = function (recordId, storeMetadata) {
|
|
1100
|
-
environment.publishStoreMetadata(recordId, {
|
|
1101
|
-
...storeMetadata,
|
|
1102
|
-
staleTimestamp: Number.MAX_SAFE_INTEGER,
|
|
1103
|
-
});
|
|
1104
|
-
};
|
|
1105
|
-
return create(environment, {
|
|
1106
|
-
defaultCachePolicy: {
|
|
1107
|
-
value: buildStaleWhileRevalidateImplementation$1(Number.MAX_SAFE_INTEGER),
|
|
1108
|
-
},
|
|
1109
|
-
storeLookup: { value: storeLookup },
|
|
1110
|
-
snapshotAvailable: {
|
|
1111
|
-
value: snapshotAvailable,
|
|
1112
|
-
},
|
|
1113
|
-
publishStoreMetadata: {
|
|
1114
|
-
value: publishStoreMetadata,
|
|
1115
|
-
},
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
export { DefaultDurableSegment, DurableStoreOperationType, makeDurable, makeOffline, publishDurableStoreEntries };
|
|
1068
|
+
export { DefaultDurableSegment, DurableStoreOperationType, makeDurable, publishDurableStoreEntries };
|
package/dist/es/es2018/main.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ export { DurableStore, DurableStoreEntries, DurableStoreEntry, DurableStoreChang
|
|
|
2
2
|
export { DurableTTLOverride, DefaultDurableTTLOverride } from './DurableTTLStore';
|
|
3
3
|
export { makeDurable, DurableEnvironment } from './makeDurable';
|
|
4
4
|
export { publishDurableStoreEntries } from './makeDurable/revive';
|
|
5
|
-
export { makeOffline } from './makeOffline';
|
|
@@ -30,7 +30,7 @@ export interface DurableEnvironment extends Environment {
|
|
|
30
30
|
* RecordSource to "prime" the ingest staging store with before calling
|
|
31
31
|
* ingest. Useful for merge-able record types
|
|
32
32
|
*/
|
|
33
|
-
handleSuccessResponse<
|
|
33
|
+
handleSuccessResponse<IngestionReturnType extends Snapshot<D, V> | undefined, D, V = unknown>(ingestAndBroadcastFunc: () => IngestionReturnType, getResponseCacheKeysFunc: () => CacheKeySet, existingRecords?: RecordSource): IngestionReturnType | Promise<IngestionReturnType>;
|
|
34
34
|
}
|
|
35
35
|
export declare const AdapterContextSegment = "ADAPTER-CONTEXT";
|
|
36
36
|
export declare const ADAPTER_CONTEXT_ID_SUFFIX = "__NAMED_CONTEXT";
|
|
@@ -71,8 +71,7 @@
|
|
|
71
71
|
// stale data found in L1 cache
|
|
72
72
|
if (snapshot.state === 'Stale') {
|
|
73
73
|
// kick off network request, do not await it
|
|
74
|
-
|
|
75
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
74
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
76
75
|
// return the cached snapshot to caller
|
|
77
76
|
return snapshot;
|
|
78
77
|
}
|
|
@@ -97,8 +96,7 @@
|
|
|
97
96
|
// stale data found in L2 cache
|
|
98
97
|
if (revivedSnapshot.state === 'Stale') {
|
|
99
98
|
// kick off network request, do not await it
|
|
100
|
-
|
|
101
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
99
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
102
100
|
// return the L2 cached snapshot to caller
|
|
103
101
|
return revivedSnapshot;
|
|
104
102
|
}
|
|
@@ -238,8 +236,7 @@
|
|
|
238
236
|
}
|
|
239
237
|
// stale data found in L1 cache
|
|
240
238
|
if (snapshot.state === 'Stale') {
|
|
241
|
-
|
|
242
|
-
// buildNetworkSnapshot(args);
|
|
239
|
+
buildNetworkSnapshot(args);
|
|
243
240
|
return snapshot;
|
|
244
241
|
}
|
|
245
242
|
// data not found in L1 cache, try L2 cache
|
|
@@ -256,8 +253,7 @@
|
|
|
256
253
|
}
|
|
257
254
|
// stale data found in L2 cache
|
|
258
255
|
if (revivedSnapshot.state === 'Stale') {
|
|
259
|
-
|
|
260
|
-
// buildNetworkSnapshot(args);
|
|
256
|
+
buildNetworkSnapshot(args);
|
|
261
257
|
return revivedSnapshot;
|
|
262
258
|
}
|
|
263
259
|
// data not found in L2 cache, go to the network
|
|
@@ -436,13 +432,12 @@
|
|
|
436
432
|
}
|
|
437
433
|
// We don't want to revive a cached value if it's an error and it's
|
|
438
434
|
// expirationTimestamp TTL is expired, otherwise we would never hit the network
|
|
439
|
-
// during resolveSnapshot or rebuildSnapshot
|
|
440
|
-
// environment because the way the Reader works.
|
|
435
|
+
// during resolveSnapshot or rebuildSnapshot because the way the Reader works.
|
|
441
436
|
// If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
|
|
442
437
|
// if stale TTL is expired. But it will return ErrorSnapshot (instead of
|
|
443
438
|
// StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
|
|
444
|
-
// In
|
|
445
|
-
//
|
|
439
|
+
// In our environment the stale TTL is maxed out so Reader will always
|
|
440
|
+
// return ErrorSnapshot.
|
|
446
441
|
if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
|
|
447
442
|
continue;
|
|
448
443
|
}
|
|
@@ -830,15 +825,15 @@
|
|
|
830
825
|
ingestStagingStore = null;
|
|
831
826
|
return promise;
|
|
832
827
|
};
|
|
833
|
-
const storeLookup = function (sel, createSnapshot, refresh) {
|
|
828
|
+
const storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
|
|
834
829
|
validateNotDisposed();
|
|
835
830
|
// if this lookup is right after an ingest there will be a staging store
|
|
836
831
|
if (ingestStagingStore !== null) {
|
|
837
|
-
return ingestStagingStore.lookup(sel, createSnapshot, refresh);
|
|
832
|
+
return ingestStagingStore.lookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
838
833
|
}
|
|
839
834
|
// otherwise this is from buildInMemorySnapshot and we should use the luvio
|
|
840
835
|
// L1 store
|
|
841
|
-
return environment.storeLookup(sel, createSnapshot, refresh);
|
|
836
|
+
return environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
842
837
|
};
|
|
843
838
|
const storeEvict = function (key) {
|
|
844
839
|
validateNotDisposed();
|
|
@@ -1038,6 +1033,9 @@
|
|
|
1038
1033
|
ingestStagingStore.records = existingRecords;
|
|
1039
1034
|
}
|
|
1040
1035
|
const snapshotFromMemoryIngest = ingestAndBroadcastFunc();
|
|
1036
|
+
if (snapshotFromMemoryIngest === undefined) {
|
|
1037
|
+
return undefined;
|
|
1038
|
+
}
|
|
1041
1039
|
if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
|
|
1042
1040
|
return snapshotFromMemoryIngest;
|
|
1043
1041
|
}
|
|
@@ -1071,58 +1069,8 @@
|
|
|
1071
1069
|
});
|
|
1072
1070
|
}
|
|
1073
1071
|
|
|
1074
|
-
/**
|
|
1075
|
-
* This environment allows for stale snapshot emits.
|
|
1076
|
-
*
|
|
1077
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
1078
|
-
* emitted is the result of a storeLookup.
|
|
1079
|
-
*
|
|
1080
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
1081
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
1082
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
1083
|
-
* cause a network refresh to happen).
|
|
1084
|
-
*/
|
|
1085
|
-
function makeOffline(environment) {
|
|
1086
|
-
const storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
|
|
1087
|
-
const snapshot = environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
1088
|
-
// if the snapshot is stale we want to kick off a refresh
|
|
1089
|
-
if (snapshot.state === 'Stale') {
|
|
1090
|
-
if (refresh !== undefined) {
|
|
1091
|
-
const { resolve, config } = refresh;
|
|
1092
|
-
resolve(config);
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
return snapshot;
|
|
1096
|
-
};
|
|
1097
|
-
const snapshotAvailable = function (snapshot) {
|
|
1098
|
-
if (snapshot.state === 'Stale') {
|
|
1099
|
-
return true;
|
|
1100
|
-
}
|
|
1101
|
-
return environment.snapshotAvailable(snapshot);
|
|
1102
|
-
};
|
|
1103
|
-
const publishStoreMetadata = function (recordId, storeMetadata) {
|
|
1104
|
-
environment.publishStoreMetadata(recordId, {
|
|
1105
|
-
...storeMetadata,
|
|
1106
|
-
staleTimestamp: Number.MAX_SAFE_INTEGER,
|
|
1107
|
-
});
|
|
1108
|
-
};
|
|
1109
|
-
return create(environment, {
|
|
1110
|
-
defaultCachePolicy: {
|
|
1111
|
-
value: engine.buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER),
|
|
1112
|
-
},
|
|
1113
|
-
storeLookup: { value: storeLookup },
|
|
1114
|
-
snapshotAvailable: {
|
|
1115
|
-
value: snapshotAvailable,
|
|
1116
|
-
},
|
|
1117
|
-
publishStoreMetadata: {
|
|
1118
|
-
value: publishStoreMetadata,
|
|
1119
|
-
},
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
1072
|
exports.DefaultDurableSegment = DefaultDurableSegment;
|
|
1124
1073
|
exports.makeDurable = makeDurable;
|
|
1125
|
-
exports.makeOffline = makeOffline;
|
|
1126
1074
|
exports.publishDurableStoreEntries = publishDurableStoreEntries;
|
|
1127
1075
|
|
|
1128
1076
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -2,4 +2,3 @@ export { DurableStore, DurableStoreEntries, DurableStoreEntry, DurableStoreChang
|
|
|
2
2
|
export { DurableTTLOverride, DefaultDurableTTLOverride } from './DurableTTLStore';
|
|
3
3
|
export { makeDurable, DurableEnvironment } from './makeDurable';
|
|
4
4
|
export { publishDurableStoreEntries } from './makeDurable/revive';
|
|
5
|
-
export { makeOffline } from './makeOffline';
|
|
@@ -30,7 +30,7 @@ export interface DurableEnvironment extends Environment {
|
|
|
30
30
|
* RecordSource to "prime" the ingest staging store with before calling
|
|
31
31
|
* ingest. Useful for merge-able record types
|
|
32
32
|
*/
|
|
33
|
-
handleSuccessResponse<
|
|
33
|
+
handleSuccessResponse<IngestionReturnType extends Snapshot<D, V> | undefined, D, V = unknown>(ingestAndBroadcastFunc: () => IngestionReturnType, getResponseCacheKeysFunc: () => CacheKeySet, existingRecords?: RecordSource): IngestionReturnType | Promise<IngestionReturnType>;
|
|
34
34
|
}
|
|
35
35
|
export declare const AdapterContextSegment = "ADAPTER-CONTEXT";
|
|
36
36
|
export declare const ADAPTER_CONTEXT_ID_SUFFIX = "__NAMED_CONTEXT";
|
|
@@ -112,8 +112,7 @@
|
|
|
112
112
|
// stale data found in L1 cache
|
|
113
113
|
if (snapshot.state === 'Stale') {
|
|
114
114
|
// kick off network request, do not await it
|
|
115
|
-
|
|
116
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
115
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
117
116
|
// return the cached snapshot to caller
|
|
118
117
|
return snapshot;
|
|
119
118
|
}
|
|
@@ -138,8 +137,7 @@
|
|
|
138
137
|
// stale data found in L2 cache
|
|
139
138
|
if (revivedSnapshot.state === 'Stale') {
|
|
140
139
|
// kick off network request, do not await it
|
|
141
|
-
|
|
142
|
-
// buildNetworkSnapshot(buildSnapshotContext, dispatchResourceRequest);
|
|
140
|
+
buildNetworkSnapshot$1(buildSnapshotContext, coercedAdapterRequestContext);
|
|
143
141
|
// return the L2 cached snapshot to caller
|
|
144
142
|
return revivedSnapshot;
|
|
145
143
|
}
|
|
@@ -279,8 +277,7 @@
|
|
|
279
277
|
}
|
|
280
278
|
// stale data found in L1 cache
|
|
281
279
|
if (snapshot.state === 'Stale') {
|
|
282
|
-
|
|
283
|
-
// buildNetworkSnapshot(args);
|
|
280
|
+
buildNetworkSnapshot(args);
|
|
284
281
|
return snapshot;
|
|
285
282
|
}
|
|
286
283
|
// data not found in L1 cache, try L2 cache
|
|
@@ -297,8 +294,7 @@
|
|
|
297
294
|
}
|
|
298
295
|
// stale data found in L2 cache
|
|
299
296
|
if (revivedSnapshot.state === 'Stale') {
|
|
300
|
-
|
|
301
|
-
// buildNetworkSnapshot(args);
|
|
297
|
+
buildNetworkSnapshot(args);
|
|
302
298
|
return revivedSnapshot;
|
|
303
299
|
}
|
|
304
300
|
// data not found in L2 cache, go to the network
|
|
@@ -471,13 +467,12 @@
|
|
|
471
467
|
}
|
|
472
468
|
// We don't want to revive a cached value if it's an error and it's
|
|
473
469
|
// expirationTimestamp TTL is expired, otherwise we would never hit the network
|
|
474
|
-
// during resolveSnapshot or rebuildSnapshot
|
|
475
|
-
// environment because the way the Reader works.
|
|
470
|
+
// during resolveSnapshot or rebuildSnapshot because the way the Reader works.
|
|
476
471
|
// If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
|
|
477
472
|
// if stale TTL is expired. But it will return ErrorSnapshot (instead of
|
|
478
473
|
// StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
|
|
479
|
-
// In
|
|
480
|
-
//
|
|
474
|
+
// In our environment the stale TTL is maxed out so Reader will always
|
|
475
|
+
// return ErrorSnapshot.
|
|
481
476
|
if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
|
|
482
477
|
continue;
|
|
483
478
|
}
|
|
@@ -872,15 +867,15 @@
|
|
|
872
867
|
ingestStagingStore = null;
|
|
873
868
|
return promise;
|
|
874
869
|
};
|
|
875
|
-
var storeLookup = function (sel, createSnapshot, refresh) {
|
|
870
|
+
var storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
|
|
876
871
|
validateNotDisposed();
|
|
877
872
|
// if this lookup is right after an ingest there will be a staging store
|
|
878
873
|
if (ingestStagingStore !== null) {
|
|
879
|
-
return ingestStagingStore.lookup(sel, createSnapshot, refresh);
|
|
874
|
+
return ingestStagingStore.lookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
880
875
|
}
|
|
881
876
|
// otherwise this is from buildInMemorySnapshot and we should use the luvio
|
|
882
877
|
// L1 store
|
|
883
|
-
return environment.storeLookup(sel, createSnapshot, refresh);
|
|
878
|
+
return environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
884
879
|
};
|
|
885
880
|
var storeEvict = function (key) {
|
|
886
881
|
validateNotDisposed();
|
|
@@ -1085,6 +1080,9 @@
|
|
|
1085
1080
|
ingestStagingStore.records = existingRecords;
|
|
1086
1081
|
}
|
|
1087
1082
|
var snapshotFromMemoryIngest = ingestAndBroadcastFunc();
|
|
1083
|
+
if (snapshotFromMemoryIngest === undefined) {
|
|
1084
|
+
return undefined;
|
|
1085
|
+
}
|
|
1088
1086
|
if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
|
|
1089
1087
|
return snapshotFromMemoryIngest;
|
|
1090
1088
|
}
|
|
@@ -1120,55 +1118,8 @@
|
|
|
1120
1118
|
});
|
|
1121
1119
|
}
|
|
1122
1120
|
|
|
1123
|
-
/**
|
|
1124
|
-
* This environment allows for stale snapshot emits.
|
|
1125
|
-
*
|
|
1126
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
1127
|
-
* emitted is the result of a storeLookup.
|
|
1128
|
-
*
|
|
1129
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
1130
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
1131
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
1132
|
-
* cause a network refresh to happen).
|
|
1133
|
-
*/
|
|
1134
|
-
function makeOffline(environment) {
|
|
1135
|
-
var storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
|
|
1136
|
-
var snapshot = environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
|
|
1137
|
-
// if the snapshot is stale we want to kick off a refresh
|
|
1138
|
-
if (snapshot.state === 'Stale') {
|
|
1139
|
-
if (refresh !== undefined) {
|
|
1140
|
-
var resolve = refresh.resolve, config = refresh.config;
|
|
1141
|
-
resolve(config);
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
return snapshot;
|
|
1145
|
-
};
|
|
1146
|
-
var snapshotAvailable = function (snapshot) {
|
|
1147
|
-
if (snapshot.state === 'Stale') {
|
|
1148
|
-
return true;
|
|
1149
|
-
}
|
|
1150
|
-
return environment.snapshotAvailable(snapshot);
|
|
1151
|
-
};
|
|
1152
|
-
var publishStoreMetadata = function (recordId, storeMetadata) {
|
|
1153
|
-
environment.publishStoreMetadata(recordId, __assign(__assign({}, storeMetadata), { staleTimestamp: Number.MAX_SAFE_INTEGER }));
|
|
1154
|
-
};
|
|
1155
|
-
return create(environment, {
|
|
1156
|
-
defaultCachePolicy: {
|
|
1157
|
-
value: engine.buildStaleWhileRevalidateImplementation(Number.MAX_SAFE_INTEGER),
|
|
1158
|
-
},
|
|
1159
|
-
storeLookup: { value: storeLookup },
|
|
1160
|
-
snapshotAvailable: {
|
|
1161
|
-
value: snapshotAvailable,
|
|
1162
|
-
},
|
|
1163
|
-
publishStoreMetadata: {
|
|
1164
|
-
value: publishStoreMetadata,
|
|
1165
|
-
},
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
1121
|
exports.DefaultDurableSegment = DefaultDurableSegment;
|
|
1170
1122
|
exports.makeDurable = makeDurable;
|
|
1171
|
-
exports.makeOffline = makeOffline;
|
|
1172
1123
|
exports.publishDurableStoreEntries = publishDurableStoreEntries;
|
|
1173
1124
|
|
|
1174
1125
|
Object.defineProperty(exports, '__esModule', { value: true });
|
package/dist/umd/es5/main.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ export { DurableStore, DurableStoreEntries, DurableStoreEntry, DurableStoreChang
|
|
|
2
2
|
export { DurableTTLOverride, DefaultDurableTTLOverride } from './DurableTTLStore';
|
|
3
3
|
export { makeDurable, DurableEnvironment } from './makeDurable';
|
|
4
4
|
export { publishDurableStoreEntries } from './makeDurable/revive';
|
|
5
|
-
export { makeOffline } from './makeOffline';
|
|
@@ -30,7 +30,7 @@ export interface DurableEnvironment extends Environment {
|
|
|
30
30
|
* RecordSource to "prime" the ingest staging store with before calling
|
|
31
31
|
* ingest. Useful for merge-able record types
|
|
32
32
|
*/
|
|
33
|
-
handleSuccessResponse<
|
|
33
|
+
handleSuccessResponse<IngestionReturnType extends Snapshot<D, V> | undefined, D, V = unknown>(ingestAndBroadcastFunc: () => IngestionReturnType, getResponseCacheKeysFunc: () => CacheKeySet, existingRecords?: RecordSource): IngestionReturnType | Promise<IngestionReturnType>;
|
|
34
34
|
}
|
|
35
35
|
export declare const AdapterContextSegment = "ADAPTER-CONTEXT";
|
|
36
36
|
export declare const ADAPTER_CONTEXT_ID_SUFFIX = "__NAMED_CONTEXT";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luvio/environments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.69.0",
|
|
4
4
|
"description": "Luvio Environments",
|
|
5
5
|
"main": "dist/umd/es2018/environments.js",
|
|
6
6
|
"module": "dist/es/es2018/environments.js",
|
|
@@ -13,10 +13,19 @@
|
|
|
13
13
|
"test": "jest",
|
|
14
14
|
"test:debug": "node --inspect-brk ../../../node_modules/jest/bin/jest.js --config ./jest.config.js --runInBand"
|
|
15
15
|
},
|
|
16
|
+
"nx": {
|
|
17
|
+
"targets": {
|
|
18
|
+
"build": {
|
|
19
|
+
"outputs": [
|
|
20
|
+
"packages/@luvio/environments/dist"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
16
25
|
"files": [
|
|
17
26
|
"dist/"
|
|
18
27
|
],
|
|
19
28
|
"dependencies": {
|
|
20
|
-
"@luvio/engine": "0.
|
|
29
|
+
"@luvio/engine": "0.69.0"
|
|
21
30
|
}
|
|
22
31
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Environment } from '@luvio/engine';
|
|
2
|
-
/**
|
|
3
|
-
* This environment allows for stale snapshot emits.
|
|
4
|
-
*
|
|
5
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
6
|
-
* emitted is the result of a storeLookup.
|
|
7
|
-
*
|
|
8
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
9
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
10
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
11
|
-
* cause a network refresh to happen).
|
|
12
|
-
*/
|
|
13
|
-
export declare function makeOffline(environment: Environment): Environment;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Environment } from '@luvio/engine';
|
|
2
|
-
/**
|
|
3
|
-
* This environment allows for stale snapshot emits.
|
|
4
|
-
*
|
|
5
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
6
|
-
* emitted is the result of a storeLookup.
|
|
7
|
-
*
|
|
8
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
9
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
10
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
11
|
-
* cause a network refresh to happen).
|
|
12
|
-
*/
|
|
13
|
-
export declare function makeOffline(environment: Environment): Environment;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Environment } from '@luvio/engine';
|
|
2
|
-
/**
|
|
3
|
-
* This environment allows for stale snapshot emits.
|
|
4
|
-
*
|
|
5
|
-
* This environment will also kick off a network refresh if the snapshot being
|
|
6
|
-
* emitted is the result of a storeLookup.
|
|
7
|
-
*
|
|
8
|
-
* Note: network refreshes are not kicked off if the snapshot is not a result of
|
|
9
|
-
* a storeLookup (for example, makeDurable calls snapshotAvailable in its
|
|
10
|
-
* rebuildSnapshot, which is supposed to ignore expirations/ttl, so it will not
|
|
11
|
-
* cause a network refresh to happen).
|
|
12
|
-
*/
|
|
13
|
-
export declare function makeOffline(environment: Environment): Environment;
|