@luvio/environments 0.127.1 → 0.130.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.
@@ -452,7 +452,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
452
452
  throw new Error('This makeDurable instance has been disposed');
453
453
  }
454
454
  };
455
- const unsubscribe = durableStore.registerOnChangedListener((changes) => {
455
+ const unsubscribe = durableStore.registerOnChangedListener(async (changes) => {
456
456
  const defaultSegmentKeys = [];
457
457
  const adapterContextSegmentKeys = [];
458
458
  for (let i = 0, len = changes.length; i < len; i++) {
@@ -481,11 +481,8 @@ function makeDurable(environment, { durableStore, instrumentation }) {
481
481
  }
482
482
  }
483
483
  if (adapterContextKeysFromDifferentInstance.length > 0) {
484
- // change handlers are sync, so kick off L2 read of the changed
485
- // segment keys but we can't await it
486
- durableStore
487
- .getEntries(adapterContextKeysFromDifferentInstance, AdapterContextSegment)
488
- .then((entries) => {
484
+ try {
485
+ const entries = await durableStore.getEntries(adapterContextKeysFromDifferentInstance, AdapterContextSegment);
489
486
  if (entries !== undefined) {
490
487
  const entryKeys = keys(entries);
491
488
  for (let i = 0, len = entryKeys.length; i < len; i++) {
@@ -494,8 +491,10 @@ function makeDurable(environment, { durableStore, instrumentation }) {
494
491
  contextStores[entryKey] = entry.data;
495
492
  }
496
493
  }
497
- })
498
- .catch(durableStoreErrorHandler);
494
+ }
495
+ catch (error) {
496
+ durableStoreErrorHandler(error);
497
+ }
499
498
  }
500
499
  // process default segment changes
501
500
  const defaultSegmentKeysLength = defaultSegmentKeys.length;
@@ -513,9 +512,8 @@ function makeDurable(environment, { durableStore, instrumentation }) {
513
512
  // call base environment storeEvict so this evict is not tracked for durable deletion
514
513
  environment.storeEvict(key);
515
514
  }
516
- return environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
515
+ await environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
517
516
  }
518
- return Promise.resolve();
519
517
  });
520
518
  const dispose = function () {
521
519
  validateNotDisposed();
@@ -456,7 +456,7 @@
456
456
  throw new Error('This makeDurable instance has been disposed');
457
457
  }
458
458
  };
459
- const unsubscribe = durableStore.registerOnChangedListener((changes) => {
459
+ const unsubscribe = durableStore.registerOnChangedListener(async (changes) => {
460
460
  const defaultSegmentKeys = [];
461
461
  const adapterContextSegmentKeys = [];
462
462
  for (let i = 0, len = changes.length; i < len; i++) {
@@ -485,11 +485,8 @@
485
485
  }
486
486
  }
487
487
  if (adapterContextKeysFromDifferentInstance.length > 0) {
488
- // change handlers are sync, so kick off L2 read of the changed
489
- // segment keys but we can't await it
490
- durableStore
491
- .getEntries(adapterContextKeysFromDifferentInstance, AdapterContextSegment)
492
- .then((entries) => {
488
+ try {
489
+ const entries = await durableStore.getEntries(adapterContextKeysFromDifferentInstance, AdapterContextSegment);
493
490
  if (entries !== undefined) {
494
491
  const entryKeys = keys(entries);
495
492
  for (let i = 0, len = entryKeys.length; i < len; i++) {
@@ -498,8 +495,10 @@
498
495
  contextStores[entryKey] = entry.data;
499
496
  }
500
497
  }
501
- })
502
- .catch(durableStoreErrorHandler);
498
+ }
499
+ catch (error) {
500
+ durableStoreErrorHandler(error);
501
+ }
503
502
  }
504
503
  // process default segment changes
505
504
  const defaultSegmentKeysLength = defaultSegmentKeys.length;
@@ -517,9 +516,8 @@
517
516
  // call base environment storeEvict so this evict is not tracked for durable deletion
518
517
  environment.storeEvict(key);
519
518
  }
520
- return environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
519
+ await environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
521
520
  }
522
- return Promise.resolve();
523
521
  });
524
522
  const dispose = function () {
525
523
  validateNotDisposed();
@@ -535,6 +535,7 @@
535
535
  * @param instrumentation An instrumentation function implementation
536
536
  */
537
537
  function makeDurable(environment, _a) {
538
+ var _this = this;
538
539
  var durableStore = _a.durableStore, instrumentation = _a.instrumentation;
539
540
  var ingestStagingStore = null;
540
541
  var durableTTLStore = new DurableTTLStore(durableStore);
@@ -559,72 +560,82 @@
559
560
  throw new Error('This makeDurable instance has been disposed');
560
561
  }
561
562
  };
562
- var unsubscribe = durableStore.registerOnChangedListener(function (changes) {
563
- var defaultSegmentKeys = [];
564
- var adapterContextSegmentKeys = [];
565
- for (var i = 0, len = changes.length; i < len; i++) {
566
- var change = changes[i];
567
- // we only care about changes to the data which is stored in the default
568
- // segment or the adapter context
569
- if (change.segment === DefaultDurableSegment) {
570
- defaultSegmentKeys.push.apply(defaultSegmentKeys, change.ids);
571
- }
572
- else if (change.segment === AdapterContextSegment) {
573
- adapterContextSegmentKeys.push.apply(adapterContextSegmentKeys, change.ids);
574
- }
575
- }
576
- // process adapter context changes
577
- var adapterContextKeysFromDifferentInstance = [];
578
- for (var _i = 0, adapterContextSegmentKeys_1 = adapterContextSegmentKeys; _i < adapterContextSegmentKeys_1.length; _i++) {
579
- var key = adapterContextSegmentKeys_1[_i];
580
- if (pendingContextStoreKeys.has(key)) {
581
- // if this instance caused the L2 write then remove from the
582
- // "pending" Set and move on
583
- pendingContextStoreKeys.delete(key);
584
- }
585
- else {
586
- // else it came from another luvio instance and we need to
587
- // read from L2
588
- adapterContextKeysFromDifferentInstance.push(key);
589
- }
590
- }
591
- if (adapterContextKeysFromDifferentInstance.length > 0) {
592
- // change handlers are sync, so kick off L2 read of the changed
593
- // segment keys but we can't await it
594
- durableStore
595
- .getEntries(adapterContextKeysFromDifferentInstance, AdapterContextSegment)
596
- .then(function (entries) {
597
- if (entries !== undefined) {
598
- var entryKeys = keys(entries);
599
- for (var i = 0, len = entryKeys.length; i < len; i++) {
600
- var entryKey = entryKeys[i];
601
- var entry = entries[entryKey];
602
- contextStores[entryKey] = entry.data;
563
+ var unsubscribe = durableStore.registerOnChangedListener(function (changes) { return __awaiter(_this, void 0, void 0, function () {
564
+ var defaultSegmentKeys, adapterContextSegmentKeys, i, len, change, adapterContextKeysFromDifferentInstance, _i, adapterContextSegmentKeys_1, key, entries, entryKeys, i, len, entryKey, entry, error_2, defaultSegmentKeysLength, i, key, canonical;
565
+ return __generator(this, function (_a) {
566
+ switch (_a.label) {
567
+ case 0:
568
+ defaultSegmentKeys = [];
569
+ adapterContextSegmentKeys = [];
570
+ for (i = 0, len = changes.length; i < len; i++) {
571
+ change = changes[i];
572
+ // we only care about changes to the data which is stored in the default
573
+ // segment or the adapter context
574
+ if (change.segment === DefaultDurableSegment) {
575
+ defaultSegmentKeys.push.apply(defaultSegmentKeys, change.ids);
576
+ }
577
+ else if (change.segment === AdapterContextSegment) {
578
+ adapterContextSegmentKeys.push.apply(adapterContextSegmentKeys, change.ids);
579
+ }
603
580
  }
604
- }
605
- })
606
- .catch(durableStoreErrorHandler);
607
- }
608
- // process default segment changes
609
- var defaultSegmentKeysLength = defaultSegmentKeys.length;
610
- if (defaultSegmentKeysLength > 0) {
611
- for (var i = 0; i < defaultSegmentKeysLength; i++) {
612
- var key = defaultSegmentKeys[i];
613
- var canonical = environment.storeGetCanonicalKey(key);
614
- if (canonical !== key) {
615
- continue;
616
- }
617
- // TODO: W-8909393 If expiration is the only thing that changed we should not evict the data... so
618
- // if we stored expiration and data at different keys (or same keys in different segments)
619
- // then we could know if only the expiration has changed and we wouldn't need to evict
620
- // and go through an entire broadcast/revive cycle for unchanged data
621
- // call base environment storeEvict so this evict is not tracked for durable deletion
622
- environment.storeEvict(key);
581
+ adapterContextKeysFromDifferentInstance = [];
582
+ for (_i = 0, adapterContextSegmentKeys_1 = adapterContextSegmentKeys; _i < adapterContextSegmentKeys_1.length; _i++) {
583
+ key = adapterContextSegmentKeys_1[_i];
584
+ if (pendingContextStoreKeys.has(key)) {
585
+ // if this instance caused the L2 write then remove from the
586
+ // "pending" Set and move on
587
+ pendingContextStoreKeys.delete(key);
588
+ }
589
+ else {
590
+ // else it came from another luvio instance and we need to
591
+ // read from L2
592
+ adapterContextKeysFromDifferentInstance.push(key);
593
+ }
594
+ }
595
+ if (!(adapterContextKeysFromDifferentInstance.length > 0)) return [3 /*break*/, 4];
596
+ _a.label = 1;
597
+ case 1:
598
+ _a.trys.push([1, 3, , 4]);
599
+ return [4 /*yield*/, durableStore.getEntries(adapterContextKeysFromDifferentInstance, AdapterContextSegment)];
600
+ case 2:
601
+ entries = _a.sent();
602
+ if (entries !== undefined) {
603
+ entryKeys = keys(entries);
604
+ for (i = 0, len = entryKeys.length; i < len; i++) {
605
+ entryKey = entryKeys[i];
606
+ entry = entries[entryKey];
607
+ contextStores[entryKey] = entry.data;
608
+ }
609
+ }
610
+ return [3 /*break*/, 4];
611
+ case 3:
612
+ error_2 = _a.sent();
613
+ durableStoreErrorHandler(error_2);
614
+ return [3 /*break*/, 4];
615
+ case 4:
616
+ defaultSegmentKeysLength = defaultSegmentKeys.length;
617
+ if (!(defaultSegmentKeysLength > 0)) return [3 /*break*/, 6];
618
+ for (i = 0; i < defaultSegmentKeysLength; i++) {
619
+ key = defaultSegmentKeys[i];
620
+ canonical = environment.storeGetCanonicalKey(key);
621
+ if (canonical !== key) {
622
+ continue;
623
+ }
624
+ // TODO: W-8909393 If expiration is the only thing that changed we should not evict the data... so
625
+ // if we stored expiration and data at different keys (or same keys in different segments)
626
+ // then we could know if only the expiration has changed and we wouldn't need to evict
627
+ // and go through an entire broadcast/revive cycle for unchanged data
628
+ // call base environment storeEvict so this evict is not tracked for durable deletion
629
+ environment.storeEvict(key);
630
+ }
631
+ return [4 /*yield*/, environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable)];
632
+ case 5:
633
+ _a.sent();
634
+ _a.label = 6;
635
+ case 6: return [2 /*return*/];
623
636
  }
624
- return environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
625
- }
626
- return Promise.resolve();
627
- });
637
+ });
638
+ }); });
628
639
  var dispose = function () {
629
640
  validateNotDisposed();
630
641
  disposed = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/environments",
3
- "version": "0.127.1",
3
+ "version": "0.130.0",
4
4
  "description": "Luvio Environments",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,7 +23,7 @@
23
23
  "watch": "yarn build --watch"
24
24
  },
25
25
  "dependencies": {
26
- "@luvio/engine": "0.127.1"
26
+ "@luvio/engine": "0.130.0"
27
27
  },
28
28
  "bundlesize": [
29
29
  {