@luvio/environments 0.66.0 → 0.70.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, coerceAdapterRequestContext, buildStaleWhileRevalidateImplementation as buildStaleWhileRevalidateImplementation$1 } from '@luvio/engine';
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
- // offline environment is already doing this; uncomment once we get rid of offline environment
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
- // offline environment is already doing this; uncomment once we get rid of offline environment
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
- // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
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
- // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
256
- // buildNetworkSnapshot(args);
252
+ buildNetworkSnapshot(args);
257
253
  return revivedSnapshot;
258
254
  }
259
255
  // data not found in L2 cache, go to the network
@@ -379,9 +375,6 @@ function isStoreEntryError(storeRecord) {
379
375
  return storeRecord.__type === 'error';
380
376
  }
381
377
 
382
- function isStoreEntryExpiredAndError(storeRecord, expirationTimestamp, now) {
383
- return isStoreEntryError(storeRecord) && expirationTimestamp < now;
384
- }
385
378
  /**
386
379
  * Takes a set of entries from DurableStore and publishes them via the passed in funcs.
387
380
  * This respects expiration and checks for valid DurableStore data shapes. This should
@@ -404,7 +397,6 @@ function publishDurableStoreEntries(durableRecords, publish, publishMetadata) {
404
397
  // no records to revive
405
398
  return { revivedKeys, hadUnexpectedShape };
406
399
  }
407
- const now = Date.now();
408
400
  for (let i = 0, len = durableKeys.length; i < len; i += 1) {
409
401
  const key = durableKeys[i];
410
402
  const durableRecord = durableRecords[key];
@@ -420,28 +412,12 @@ function publishDurableStoreEntries(durableRecords, publish, publishMetadata) {
420
412
  continue;
421
413
  }
422
414
  if (metadata !== undefined) {
423
- const { expirationTimestamp, staleTimestamp } = metadata;
415
+ const { expirationTimestamp } = metadata;
424
416
  if (expirationTimestamp === undefined) {
425
417
  // if unexpected expiration data skip reviving
426
418
  hadUnexpectedShape = true;
427
419
  continue;
428
420
  }
429
- // if past stale TTL then don't revive
430
- if (staleTimestamp !== undefined && staleTimestamp < now) {
431
- continue;
432
- }
433
- // We don't want to revive a cached value if it's an error and it's
434
- // expirationTimestamp TTL is expired, otherwise we would never hit the network
435
- // during resolveSnapshot or rebuildSnapshot in the makeOffline
436
- // environment because the way the Reader works.
437
- // If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
438
- // if stale TTL is expired. But it will return ErrorSnapshot (instead of
439
- // StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
440
- // In makeOffline environment the stale TTL is maxed out so Reader
441
- // will always return ErrorSnapshot.
442
- if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
443
- continue;
444
- }
445
421
  publishMetadata(key, metadata);
446
422
  }
447
423
  if (isStoreEntryError(data)) {
@@ -826,15 +802,15 @@ function makeDurable(environment, { durableStore, instrumentation }) {
826
802
  ingestStagingStore = null;
827
803
  return promise;
828
804
  };
829
- const storeLookup = function (sel, createSnapshot, refresh) {
805
+ const storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
830
806
  validateNotDisposed();
831
807
  // if this lookup is right after an ingest there will be a staging store
832
808
  if (ingestStagingStore !== null) {
833
- return ingestStagingStore.lookup(sel, createSnapshot, refresh);
809
+ return ingestStagingStore.lookup(sel, createSnapshot, refresh, ttlStrategy);
834
810
  }
835
811
  // otherwise this is from buildInMemorySnapshot and we should use the luvio
836
812
  // L1 store
837
- return environment.storeLookup(sel, createSnapshot, refresh);
813
+ return environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
838
814
  };
839
815
  const storeEvict = function (key) {
840
816
  validateNotDisposed();
@@ -1034,6 +1010,9 @@ function makeDurable(environment, { durableStore, instrumentation }) {
1034
1010
  ingestStagingStore.records = existingRecords;
1035
1011
  }
1036
1012
  const snapshotFromMemoryIngest = ingestAndBroadcastFunc();
1013
+ if (snapshotFromMemoryIngest === undefined) {
1014
+ return undefined;
1015
+ }
1037
1016
  if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
1038
1017
  return snapshotFromMemoryIngest;
1039
1018
  }
@@ -1067,53 +1046,4 @@ function makeDurable(environment, { durableStore, instrumentation }) {
1067
1046
  });
1068
1047
  }
1069
1048
 
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 };
1049
+ export { DefaultDurableSegment, DurableStoreOperationType, makeDurable, publishDurableStoreEntries };
@@ -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<ResponseType>(ingestAndBroadcastFunc: () => Snapshot<ResponseType>, getResponseCacheKeysFunc: () => CacheKeySet, existingRecords?: RecordSource): Snapshot<ResponseType> | Promise<Snapshot<ResponseType>>;
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
- // offline environment is already doing this; uncomment once we get rid of offline environment
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
- // offline environment is already doing this; uncomment once we get rid of offline environment
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
- // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
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
- // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
260
- // buildNetworkSnapshot(args);
256
+ buildNetworkSnapshot(args);
261
257
  return revivedSnapshot;
262
258
  }
263
259
  // data not found in L2 cache, go to the network
@@ -383,9 +379,6 @@
383
379
  return storeRecord.__type === 'error';
384
380
  }
385
381
 
386
- function isStoreEntryExpiredAndError(storeRecord, expirationTimestamp, now) {
387
- return isStoreEntryError(storeRecord) && expirationTimestamp < now;
388
- }
389
382
  /**
390
383
  * Takes a set of entries from DurableStore and publishes them via the passed in funcs.
391
384
  * This respects expiration and checks for valid DurableStore data shapes. This should
@@ -408,7 +401,6 @@
408
401
  // no records to revive
409
402
  return { revivedKeys, hadUnexpectedShape };
410
403
  }
411
- const now = Date.now();
412
404
  for (let i = 0, len = durableKeys.length; i < len; i += 1) {
413
405
  const key = durableKeys[i];
414
406
  const durableRecord = durableRecords[key];
@@ -424,28 +416,12 @@
424
416
  continue;
425
417
  }
426
418
  if (metadata !== undefined) {
427
- const { expirationTimestamp, staleTimestamp } = metadata;
419
+ const { expirationTimestamp } = metadata;
428
420
  if (expirationTimestamp === undefined) {
429
421
  // if unexpected expiration data skip reviving
430
422
  hadUnexpectedShape = true;
431
423
  continue;
432
424
  }
433
- // if past stale TTL then don't revive
434
- if (staleTimestamp !== undefined && staleTimestamp < now) {
435
- continue;
436
- }
437
- // We don't want to revive a cached value if it's an error and it's
438
- // expirationTimestamp TTL is expired, otherwise we would never hit the network
439
- // during resolveSnapshot or rebuildSnapshot in the makeOffline
440
- // environment because the way the Reader works.
441
- // If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
442
- // if stale TTL is expired. But it will return ErrorSnapshot (instead of
443
- // StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
444
- // In makeOffline environment the stale TTL is maxed out so Reader
445
- // will always return ErrorSnapshot.
446
- if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
447
- continue;
448
- }
449
425
  publishMetadata(key, metadata);
450
426
  }
451
427
  if (isStoreEntryError(data)) {
@@ -830,15 +806,15 @@
830
806
  ingestStagingStore = null;
831
807
  return promise;
832
808
  };
833
- const storeLookup = function (sel, createSnapshot, refresh) {
809
+ const storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
834
810
  validateNotDisposed();
835
811
  // if this lookup is right after an ingest there will be a staging store
836
812
  if (ingestStagingStore !== null) {
837
- return ingestStagingStore.lookup(sel, createSnapshot, refresh);
813
+ return ingestStagingStore.lookup(sel, createSnapshot, refresh, ttlStrategy);
838
814
  }
839
815
  // otherwise this is from buildInMemorySnapshot and we should use the luvio
840
816
  // L1 store
841
- return environment.storeLookup(sel, createSnapshot, refresh);
817
+ return environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
842
818
  };
843
819
  const storeEvict = function (key) {
844
820
  validateNotDisposed();
@@ -1038,6 +1014,9 @@
1038
1014
  ingestStagingStore.records = existingRecords;
1039
1015
  }
1040
1016
  const snapshotFromMemoryIngest = ingestAndBroadcastFunc();
1017
+ if (snapshotFromMemoryIngest === undefined) {
1018
+ return undefined;
1019
+ }
1041
1020
  if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
1042
1021
  return snapshotFromMemoryIngest;
1043
1022
  }
@@ -1071,58 +1050,8 @@
1071
1050
  });
1072
1051
  }
1073
1052
 
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
1053
  exports.DefaultDurableSegment = DefaultDurableSegment;
1124
1054
  exports.makeDurable = makeDurable;
1125
- exports.makeOffline = makeOffline;
1126
1055
  exports.publishDurableStoreEntries = publishDurableStoreEntries;
1127
1056
 
1128
1057
  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<ResponseType>(ingestAndBroadcastFunc: () => Snapshot<ResponseType>, getResponseCacheKeysFunc: () => CacheKeySet, existingRecords?: RecordSource): Snapshot<ResponseType> | Promise<Snapshot<ResponseType>>;
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
- // offline environment is already doing this; uncomment once we get rid of offline environment
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
- // offline environment is already doing this; uncomment once we get rid of offline environment
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
- // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
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
- // TODO [@W-10093408]: offline environment is already doing this; uncomment once we get rid of offline environment
301
- // buildNetworkSnapshot(args);
297
+ buildNetworkSnapshot(args);
302
298
  return revivedSnapshot;
303
299
  }
304
300
  // data not found in L2 cache, go to the network
@@ -418,9 +414,6 @@
418
414
  return storeRecord.__type === 'error';
419
415
  }
420
416
 
421
- function isStoreEntryExpiredAndError(storeRecord, expirationTimestamp, now) {
422
- return isStoreEntryError(storeRecord) && expirationTimestamp < now;
423
- }
424
417
  /**
425
418
  * Takes a set of entries from DurableStore and publishes them via the passed in funcs.
426
419
  * This respects expiration and checks for valid DurableStore data shapes. This should
@@ -443,7 +436,6 @@
443
436
  // no records to revive
444
437
  return { revivedKeys: revivedKeys, hadUnexpectedShape: hadUnexpectedShape };
445
438
  }
446
- var now = Date.now();
447
439
  for (var i = 0, len = durableKeys.length; i < len; i += 1) {
448
440
  var key = durableKeys[i];
449
441
  var durableRecord = durableRecords[key];
@@ -459,28 +451,12 @@
459
451
  continue;
460
452
  }
461
453
  if (metadata !== undefined) {
462
- var expirationTimestamp = metadata.expirationTimestamp, staleTimestamp = metadata.staleTimestamp;
454
+ var expirationTimestamp = metadata.expirationTimestamp;
463
455
  if (expirationTimestamp === undefined) {
464
456
  // if unexpected expiration data skip reviving
465
457
  hadUnexpectedShape = true;
466
458
  continue;
467
459
  }
468
- // if past stale TTL then don't revive
469
- if (staleTimestamp !== undefined && staleTimestamp < now) {
470
- continue;
471
- }
472
- // We don't want to revive a cached value if it's an error and it's
473
- // expirationTimestamp TTL is expired, otherwise we would never hit the network
474
- // during resolveSnapshot or rebuildSnapshot in the makeOffline
475
- // environment because the way the Reader works.
476
- // If a StoreEntry is an error, the Reader will return UnfulfilledSnapshot
477
- // if stale TTL is expired. But it will return ErrorSnapshot (instead of
478
- // StaleSnapshot) if expirationTimestamp TTL is expired (but stale TTL isn't).
479
- // In makeOffline environment the stale TTL is maxed out so Reader
480
- // will always return ErrorSnapshot.
481
- if (isStoreEntryExpiredAndError(data, expirationTimestamp, now)) {
482
- continue;
483
- }
484
460
  publishMetadata(key, metadata);
485
461
  }
486
462
  if (isStoreEntryError(data)) {
@@ -872,15 +848,15 @@
872
848
  ingestStagingStore = null;
873
849
  return promise;
874
850
  };
875
- var storeLookup = function (sel, createSnapshot, refresh) {
851
+ var storeLookup = function (sel, createSnapshot, refresh, ttlStrategy) {
876
852
  validateNotDisposed();
877
853
  // if this lookup is right after an ingest there will be a staging store
878
854
  if (ingestStagingStore !== null) {
879
- return ingestStagingStore.lookup(sel, createSnapshot, refresh);
855
+ return ingestStagingStore.lookup(sel, createSnapshot, refresh, ttlStrategy);
880
856
  }
881
857
  // otherwise this is from buildInMemorySnapshot and we should use the luvio
882
858
  // L1 store
883
- return environment.storeLookup(sel, createSnapshot, refresh);
859
+ return environment.storeLookup(sel, createSnapshot, refresh, ttlStrategy);
884
860
  };
885
861
  var storeEvict = function (key) {
886
862
  validateNotDisposed();
@@ -1085,6 +1061,9 @@
1085
1061
  ingestStagingStore.records = existingRecords;
1086
1062
  }
1087
1063
  var snapshotFromMemoryIngest = ingestAndBroadcastFunc();
1064
+ if (snapshotFromMemoryIngest === undefined) {
1065
+ return undefined;
1066
+ }
1088
1067
  if (snapshotFromMemoryIngest.state !== 'Unfulfilled') {
1089
1068
  return snapshotFromMemoryIngest;
1090
1069
  }
@@ -1120,55 +1099,8 @@
1120
1099
  });
1121
1100
  }
1122
1101
 
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
1102
  exports.DefaultDurableSegment = DefaultDurableSegment;
1170
1103
  exports.makeDurable = makeDurable;
1171
- exports.makeOffline = makeOffline;
1172
1104
  exports.publishDurableStoreEntries = publishDurableStoreEntries;
1173
1105
 
1174
1106
  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<ResponseType>(ingestAndBroadcastFunc: () => Snapshot<ResponseType>, getResponseCacheKeysFunc: () => CacheKeySet, existingRecords?: RecordSource): Snapshot<ResponseType> | Promise<Snapshot<ResponseType>>;
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.66.0",
3
+ "version": "0.70.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.66.0"
29
+ "@luvio/engine": "0.70.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;