@luvio/environments 0.126.2 → 0.127.1

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.
@@ -58,7 +58,7 @@ export interface DurableStoreChange {
58
58
  */
59
59
  isExternalChange?: boolean;
60
60
  }
61
- export declare type OnDurableStoreChangedListener = (changes: DurableStoreChange[]) => void;
61
+ export declare type OnDurableStoreChangedListener = (changes: DurableStoreChange[]) => Promise<void>;
62
62
  /**
63
63
  * The DurableStore implementation must have the following behaviors:
64
64
  * - It must handle read/write synchronization (ie: reads should wait for any
@@ -513,8 +513,9 @@ function makeDurable(environment, { durableStore, instrumentation }) {
513
513
  // call base environment storeEvict so this evict is not tracked for durable deletion
514
514
  environment.storeEvict(key);
515
515
  }
516
- environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
516
+ return environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
517
517
  }
518
+ return Promise.resolve();
518
519
  });
519
520
  const dispose = function () {
520
521
  validateNotDisposed();
@@ -558,9 +559,10 @@ function makeDurable(environment, { durableStore, instrumentation }) {
558
559
  };
559
560
  const storeBroadcast = function (_rebuildSnapshot, _snapshotDataAvailable) {
560
561
  validateNotDisposed();
561
- // no-op here and wait for the L2 flush to happen in handleSuccessResponse,
562
+ // return resolved promise here and wait for the L2 flush to happen in handleSuccessResponse,
562
563
  // that flush will cause the onChanged handler to fire which will revive
563
564
  // records to the main L1 store and call the base storeBroadcast
565
+ return Promise.resolve();
564
566
  };
565
567
  const publishChangesToDurableStore = function () {
566
568
  validateNotDisposed();
@@ -603,28 +605,28 @@ function makeDurable(environment, { durableStore, instrumentation }) {
603
605
  }
604
606
  return environment.wrapNormalizedGraphNode(normalized, ingestStagingStore);
605
607
  };
606
- const rebuildSnapshot = function (snapshot, onAsyncRebuild) {
608
+ const rebuildSnapshot = function (snapshot, onRebuild) {
607
609
  validateNotDisposed();
608
610
  // try rebuilding from memory
609
- const rebuilt = environment.rebuildSnapshot(snapshot, onAsyncRebuild);
610
- // only try reviving from durable store if snapshot is unfulfilled
611
- if (rebuilt.state !== 'Unfulfilled') {
612
- return rebuilt;
613
- }
614
- // Do an L2 revive and emit to subscriber using the callback.
615
- reviveSnapshot(environment, durableStore, rebuilt, durableStoreErrorHandler, () =>
616
- // reviveSnapshot will revive into L1, and since "records" is a reference
617
- // (and not a copy) to the L1 records we can use it for rebuild
618
- environment.rebuildSnapshot(snapshot, () => { })).then((result) => {
619
- onAsyncRebuild(result.snapshot);
611
+ environment.rebuildSnapshot(snapshot, (rebuilt) => {
612
+ // only try reviving from durable store if snapshot is unfulfilled
613
+ if (rebuilt.state !== 'Unfulfilled') {
614
+ onRebuild(rebuilt);
615
+ return;
616
+ }
617
+ // Do an L2 revive and emit to subscriber using the callback.
618
+ reviveSnapshot(environment, durableStore, rebuilt, durableStoreErrorHandler, () => {
619
+ // reviveSnapshot will revive into L1, and since "records" is a reference
620
+ // (and not a copy) to the L1 records we can use it for rebuild
621
+ let rebuiltSnap;
622
+ environment.rebuildSnapshot(snapshot, (rebuilt) => {
623
+ rebuiltSnap = rebuilt;
624
+ });
625
+ return rebuiltSnap;
626
+ }).then((result) => {
627
+ onRebuild(result.snapshot);
628
+ });
620
629
  });
621
- // synchronously return the base snapshot as Pending if not already
622
- return snapshot.state === 'Pending'
623
- ? snapshot
624
- : {
625
- ...snapshot,
626
- state: 'Pending',
627
- };
628
630
  };
629
631
  const withContext = function (adapter, options) {
630
632
  validateNotDisposed();
@@ -773,7 +775,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
773
775
  },
774
776
  // we don't need to prime metadata
775
777
  () => { });
776
- snapshotFromMemoryIngest = ingestAndBroadcastFunc();
778
+ snapshotFromMemoryIngest = await ingestAndBroadcastFunc();
777
779
  await publishChangesToDurableStore();
778
780
  })();
779
781
  for (const key of keysAsArray) {
@@ -801,7 +803,7 @@ function makeDurable(environment, { durableStore, instrumentation }) {
801
803
  // underlying DurableStore implementation takes care of R/W sync
802
804
  // so all we have to do is ingest then write to L2
803
805
  ingestStagingStore = buildIngestStagingStore(environment);
804
- snapshotFromMemoryIngest = ingestAndBroadcastFunc();
806
+ snapshotFromMemoryIngest = await ingestAndBroadcastFunc();
805
807
  await publishChangesToDurableStore();
806
808
  }
807
809
  if (snapshotFromMemoryIngest === undefined) {
@@ -58,7 +58,7 @@ export interface DurableStoreChange {
58
58
  */
59
59
  isExternalChange?: boolean;
60
60
  }
61
- export declare type OnDurableStoreChangedListener = (changes: DurableStoreChange[]) => void;
61
+ export declare type OnDurableStoreChangedListener = (changes: DurableStoreChange[]) => Promise<void>;
62
62
  /**
63
63
  * The DurableStore implementation must have the following behaviors:
64
64
  * - It must handle read/write synchronization (ie: reads should wait for any
@@ -517,8 +517,9 @@
517
517
  // call base environment storeEvict so this evict is not tracked for durable deletion
518
518
  environment.storeEvict(key);
519
519
  }
520
- environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
520
+ return environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
521
521
  }
522
+ return Promise.resolve();
522
523
  });
523
524
  const dispose = function () {
524
525
  validateNotDisposed();
@@ -562,9 +563,10 @@
562
563
  };
563
564
  const storeBroadcast = function (_rebuildSnapshot, _snapshotDataAvailable) {
564
565
  validateNotDisposed();
565
- // no-op here and wait for the L2 flush to happen in handleSuccessResponse,
566
+ // return resolved promise here and wait for the L2 flush to happen in handleSuccessResponse,
566
567
  // that flush will cause the onChanged handler to fire which will revive
567
568
  // records to the main L1 store and call the base storeBroadcast
569
+ return Promise.resolve();
568
570
  };
569
571
  const publishChangesToDurableStore = function () {
570
572
  validateNotDisposed();
@@ -607,28 +609,28 @@
607
609
  }
608
610
  return environment.wrapNormalizedGraphNode(normalized, ingestStagingStore);
609
611
  };
610
- const rebuildSnapshot = function (snapshot, onAsyncRebuild) {
612
+ const rebuildSnapshot = function (snapshot, onRebuild) {
611
613
  validateNotDisposed();
612
614
  // try rebuilding from memory
613
- const rebuilt = environment.rebuildSnapshot(snapshot, onAsyncRebuild);
614
- // only try reviving from durable store if snapshot is unfulfilled
615
- if (rebuilt.state !== 'Unfulfilled') {
616
- return rebuilt;
617
- }
618
- // Do an L2 revive and emit to subscriber using the callback.
619
- reviveSnapshot(environment, durableStore, rebuilt, durableStoreErrorHandler, () =>
620
- // reviveSnapshot will revive into L1, and since "records" is a reference
621
- // (and not a copy) to the L1 records we can use it for rebuild
622
- environment.rebuildSnapshot(snapshot, () => { })).then((result) => {
623
- onAsyncRebuild(result.snapshot);
615
+ environment.rebuildSnapshot(snapshot, (rebuilt) => {
616
+ // only try reviving from durable store if snapshot is unfulfilled
617
+ if (rebuilt.state !== 'Unfulfilled') {
618
+ onRebuild(rebuilt);
619
+ return;
620
+ }
621
+ // Do an L2 revive and emit to subscriber using the callback.
622
+ reviveSnapshot(environment, durableStore, rebuilt, durableStoreErrorHandler, () => {
623
+ // reviveSnapshot will revive into L1, and since "records" is a reference
624
+ // (and not a copy) to the L1 records we can use it for rebuild
625
+ let rebuiltSnap;
626
+ environment.rebuildSnapshot(snapshot, (rebuilt) => {
627
+ rebuiltSnap = rebuilt;
628
+ });
629
+ return rebuiltSnap;
630
+ }).then((result) => {
631
+ onRebuild(result.snapshot);
632
+ });
624
633
  });
625
- // synchronously return the base snapshot as Pending if not already
626
- return snapshot.state === 'Pending'
627
- ? snapshot
628
- : {
629
- ...snapshot,
630
- state: 'Pending',
631
- };
632
634
  };
633
635
  const withContext = function (adapter, options) {
634
636
  validateNotDisposed();
@@ -777,7 +779,7 @@
777
779
  },
778
780
  // we don't need to prime metadata
779
781
  () => { });
780
- snapshotFromMemoryIngest = ingestAndBroadcastFunc();
782
+ snapshotFromMemoryIngest = await ingestAndBroadcastFunc();
781
783
  await publishChangesToDurableStore();
782
784
  })();
783
785
  for (const key of keysAsArray) {
@@ -805,7 +807,7 @@
805
807
  // underlying DurableStore implementation takes care of R/W sync
806
808
  // so all we have to do is ingest then write to L2
807
809
  ingestStagingStore = buildIngestStagingStore(environment);
808
- snapshotFromMemoryIngest = ingestAndBroadcastFunc();
810
+ snapshotFromMemoryIngest = await ingestAndBroadcastFunc();
809
811
  await publishChangesToDurableStore();
810
812
  }
811
813
  if (snapshotFromMemoryIngest === undefined) {
@@ -58,7 +58,7 @@ export interface DurableStoreChange {
58
58
  */
59
59
  isExternalChange?: boolean;
60
60
  }
61
- export declare type OnDurableStoreChangedListener = (changes: DurableStoreChange[]) => void;
61
+ export declare type OnDurableStoreChangedListener = (changes: DurableStoreChange[]) => Promise<void>;
62
62
  /**
63
63
  * The DurableStore implementation must have the following behaviors:
64
64
  * - It must handle read/write synchronization (ie: reads should wait for any
@@ -621,8 +621,9 @@
621
621
  // call base environment storeEvict so this evict is not tracked for durable deletion
622
622
  environment.storeEvict(key);
623
623
  }
624
- environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
624
+ return environment.storeBroadcast(rebuildSnapshot, environment.snapshotAvailable);
625
625
  }
626
+ return Promise.resolve();
626
627
  });
627
628
  var dispose = function () {
628
629
  validateNotDisposed();
@@ -666,9 +667,10 @@
666
667
  };
667
668
  var storeBroadcast = function (_rebuildSnapshot, _snapshotDataAvailable) {
668
669
  validateNotDisposed();
669
- // no-op here and wait for the L2 flush to happen in handleSuccessResponse,
670
+ // return resolved promise here and wait for the L2 flush to happen in handleSuccessResponse,
670
671
  // that flush will cause the onChanged handler to fire which will revive
671
672
  // records to the main L1 store and call the base storeBroadcast
673
+ return Promise.resolve();
672
674
  };
673
675
  var publishChangesToDurableStore = function () {
674
676
  validateNotDisposed();
@@ -711,26 +713,28 @@
711
713
  }
712
714
  return environment.wrapNormalizedGraphNode(normalized, ingestStagingStore);
713
715
  };
714
- var rebuildSnapshot = function (snapshot, onAsyncRebuild) {
716
+ var rebuildSnapshot = function (snapshot, onRebuild) {
715
717
  validateNotDisposed();
716
718
  // try rebuilding from memory
717
- var rebuilt = environment.rebuildSnapshot(snapshot, onAsyncRebuild);
718
- // only try reviving from durable store if snapshot is unfulfilled
719
- if (rebuilt.state !== 'Unfulfilled') {
720
- return rebuilt;
721
- }
722
- // Do an L2 revive and emit to subscriber using the callback.
723
- reviveSnapshot(environment, durableStore, rebuilt, durableStoreErrorHandler, function () {
724
- // reviveSnapshot will revive into L1, and since "records" is a reference
725
- // (and not a copy) to the L1 records we can use it for rebuild
726
- return environment.rebuildSnapshot(snapshot, function () { });
727
- }).then(function (result) {
728
- onAsyncRebuild(result.snapshot);
719
+ environment.rebuildSnapshot(snapshot, function (rebuilt) {
720
+ // only try reviving from durable store if snapshot is unfulfilled
721
+ if (rebuilt.state !== 'Unfulfilled') {
722
+ onRebuild(rebuilt);
723
+ return;
724
+ }
725
+ // Do an L2 revive and emit to subscriber using the callback.
726
+ reviveSnapshot(environment, durableStore, rebuilt, durableStoreErrorHandler, function () {
727
+ // reviveSnapshot will revive into L1, and since "records" is a reference
728
+ // (and not a copy) to the L1 records we can use it for rebuild
729
+ var rebuiltSnap;
730
+ environment.rebuildSnapshot(snapshot, function (rebuilt) {
731
+ rebuiltSnap = rebuilt;
732
+ });
733
+ return rebuiltSnap;
734
+ }).then(function (result) {
735
+ onRebuild(result.snapshot);
736
+ });
729
737
  });
730
- // synchronously return the base snapshot as Pending if not already
731
- return snapshot.state === 'Pending'
732
- ? snapshot
733
- : __assign(__assign({}, snapshot), { state: 'Pending' });
734
738
  };
735
739
  var withContext = function (adapter, options) {
736
740
  validateNotDisposed();
@@ -899,9 +903,11 @@
899
903
  },
900
904
  // we don't need to prime metadata
901
905
  function () { });
902
- snapshotFromMemoryIngest = ingestAndBroadcastFunc();
903
- return [4 /*yield*/, publishChangesToDurableStore()];
906
+ return [4 /*yield*/, ingestAndBroadcastFunc()];
904
907
  case 3:
908
+ snapshotFromMemoryIngest = _a.sent();
909
+ return [4 /*yield*/, publishChangesToDurableStore()];
910
+ case 4:
905
911
  _a.sent();
906
912
  return [2 /*return*/];
907
913
  }
@@ -932,18 +938,20 @@
932
938
  }
933
939
  }
934
940
  return [7 /*endfinally*/];
935
- case 4: return [3 /*break*/, 7];
941
+ case 4: return [3 /*break*/, 8];
936
942
  case 5:
937
943
  // we aren't doing any merging so we don't have to synchronize, the
938
944
  // underlying DurableStore implementation takes care of R/W sync
939
945
  // so all we have to do is ingest then write to L2
940
946
  ingestStagingStore = buildIngestStagingStore(environment);
941
- snapshotFromMemoryIngest = ingestAndBroadcastFunc();
942
- return [4 /*yield*/, publishChangesToDurableStore()];
947
+ return [4 /*yield*/, ingestAndBroadcastFunc()];
943
948
  case 6:
944
- _d.sent();
945
- _d.label = 7;
949
+ snapshotFromMemoryIngest = _d.sent();
950
+ return [4 /*yield*/, publishChangesToDurableStore()];
946
951
  case 7:
952
+ _d.sent();
953
+ _d.label = 8;
954
+ case 8:
947
955
  if (snapshotFromMemoryIngest === undefined) {
948
956
  return [2 /*return*/, undefined];
949
957
  }
@@ -952,7 +960,7 @@
952
960
  }
953
961
  _c = snapshotFromMemoryIngest, select = _c.select, refresh = _c.refresh;
954
962
  return [4 /*yield*/, reviveSnapshot(environment, durableStore, snapshotFromMemoryIngest, durableStoreErrorHandler, function () { return environment.storeLookup(select, environment.createSnapshot, refresh); })];
955
- case 8:
963
+ case 9:
956
964
  result = _d.sent();
957
965
  return [2 /*return*/, result.snapshot];
958
966
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/environments",
3
- "version": "0.126.2",
3
+ "version": "0.127.1",
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.126.2"
26
+ "@luvio/engine": "0.127.1"
27
27
  },
28
28
  "bundlesize": [
29
29
  {