@event-driven-io/emmett-esdb 0.38.7 → 0.39.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.
package/dist/index.cjs CHANGED
@@ -1,30 +1,40 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3;// ../emmett/dist/chunk-O2VMBOV4.js
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// ../emmett/dist/chunk-AZDDB5SF.js
2
2
  var isNumber = (val) => typeof val === "number" && val === val;
3
3
  var isBigint = (val) => typeof val === "bigint" && val === val;
4
4
  var isString = (val) => typeof val === "string";
5
- var EmmettError = class _EmmettError extends Error {
5
+ var EmmettError = (_class = class _EmmettError extends Error {
6
+ static __initStatic() {this.Codes = {
7
+ ValidationError: 400,
8
+ IllegalStateError: 403,
9
+ NotFoundError: 404,
10
+ ConcurrencyError: 412,
11
+ InternalServerError: 500
12
+ }}
6
13
 
7
14
  constructor(options) {
8
- const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : 500;
15
+ const errorCode = options && typeof options === "object" && "errorCode" in options ? options.errorCode : isNumber(options) ? options : _EmmettError.Codes.InternalServerError;
9
16
  const message = options && typeof options === "object" && "message" in options ? options.message : isString(options) ? options : `Error with status code '${errorCode}' ocurred during Emmett processing`;
10
17
  super(message);
11
18
  this.errorCode = errorCode;
12
19
  Object.setPrototypeOf(this, _EmmettError.prototype);
13
20
  }
14
21
  static mapFrom(error) {
15
- if (error instanceof _EmmettError) {
22
+ if (_EmmettError.isInstanceOf(error)) {
16
23
  return error;
17
24
  }
18
25
  return new _EmmettError({
19
- errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : 500,
26
+ errorCode: "errorCode" in error && error.errorCode !== void 0 && error.errorCode !== null ? error.errorCode : _EmmettError.Codes.InternalServerError,
20
27
  message: _nullishCoalesce(error.message, () => ( "An unknown error occurred"))
21
28
  });
22
29
  }
23
- };
30
+ static isInstanceOf(error, errorCode) {
31
+ return typeof error === "object" && error !== null && "errorCode" in error && isNumber(error.errorCode) && (errorCode === void 0 || error.errorCode === errorCode);
32
+ }
33
+ }, _class.__initStatic(), _class);
24
34
  var ConcurrencyError = class _ConcurrencyError extends EmmettError {
25
35
  constructor(current, expected, message) {
26
36
  super({
27
- errorCode: 412,
37
+ errorCode: EmmettError.Codes.ConcurrencyError,
28
38
  message: _nullishCoalesce(message, () => ( `Expected version ${expected.toString()} does not match current ${_optionalChain([current, 'optionalAccess', _2 => _2.toString, 'call', _3 => _3()])}`))
29
39
  });
30
40
  this.current = current;
@@ -35,7 +45,7 @@ var ConcurrencyError = class _ConcurrencyError extends EmmettError {
35
45
  var ConcurrencyInMemoryDatabaseError = class _ConcurrencyInMemoryDatabaseError extends EmmettError {
36
46
  constructor(message) {
37
47
  super({
38
- errorCode: 412,
48
+ errorCode: EmmettError.Codes.ConcurrencyError,
39
49
  message: _nullishCoalesce(message, () => ( `Expected document state does not match current one!`))
40
50
  });
41
51
  Object.setPrototypeOf(this, _ConcurrencyInMemoryDatabaseError.prototype);
@@ -47,23 +57,6 @@ var _uuid = require('uuid');
47
57
 
48
58
  var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
49
59
 
50
- var _webstreamspolyfill = require('web-streams-polyfill');
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
60
  var STREAM_EXISTS = "STREAM_EXISTS";
68
61
  var STREAM_DOES_NOT_EXIST = "STREAM_DOES_NOT_EXIST";
69
62
  var NO_CONCURRENCY_CHECK = "NO_CONCURRENCY_CHECK";
@@ -576,44 +569,6 @@ var getInMemoryDatabase = () => {
576
569
  }
577
570
  };
578
571
  };
579
- var notifyAboutNoActiveReadersStream = (onNoActiveReaderCallback, options = {}) => new NotifyAboutNoActiveReadersStream(onNoActiveReaderCallback, options);
580
- var NotifyAboutNoActiveReadersStream = (_class = class extends _webstreamspolyfill.TransformStream {
581
- constructor(onNoActiveReaderCallback, options = {}) {
582
- super({
583
- cancel: (reason) => {
584
- console.log("Stream was canceled. Reason:", reason);
585
- this.stopChecking();
586
- }
587
- });_class.prototype.__init.call(this);_class.prototype.__init2.call(this);;
588
- this.onNoActiveReaderCallback = onNoActiveReaderCallback;
589
- this.streamId = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _24 => _24.streamId]), () => ( _uuid.v4.call(void 0, )));
590
- this.onNoActiveReaderCallback = onNoActiveReaderCallback;
591
- this.startChecking(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _25 => _25.intervalCheckInMs]), () => ( 20)));
592
- }
593
- __init() {this.checkInterval = null}
594
-
595
- __init2() {this._isStopped = false}
596
- get hasActiveSubscribers() {
597
- return !this._isStopped;
598
- }
599
- startChecking(interval) {
600
- this.checkInterval = setInterval(() => {
601
- this.checkNoActiveReader();
602
- }, interval);
603
- }
604
- stopChecking() {
605
- if (!this.checkInterval) return;
606
- clearInterval(this.checkInterval);
607
- this.checkInterval = null;
608
- this._isStopped = true;
609
- this.onNoActiveReaderCallback(this);
610
- }
611
- checkNoActiveReader() {
612
- if (!this.readable.locked && !this._isStopped) {
613
- this.stopChecking();
614
- }
615
- }
616
- }, _class);
617
572
  var getCheckpoint = (message2) => {
618
573
  return "checkpoint" in message2.metadata && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
619
574
  isBigint(message2.metadata.checkpoint) ? (
@@ -648,7 +603,7 @@ var reactor = (options) => {
648
603
  return {
649
604
  id: options.processorId,
650
605
  type: _nullishCoalesce(options.type, () => ( MessageProcessorType.REACTOR)),
651
- close: () => _optionalChain([options, 'access', _26 => _26.hooks, 'optionalAccess', _27 => _27.onClose]) ? _optionalChain([options, 'access', _28 => _28.hooks, 'optionalAccess', _29 => _29.onClose, 'call', _30 => _30()]) : Promise.resolve(),
606
+ close: () => _optionalChain([options, 'access', _24 => _24.hooks, 'optionalAccess', _25 => _25.onClose]) ? _optionalChain([options, 'access', _26 => _26.hooks, 'optionalAccess', _27 => _27.onClose, 'call', _28 => _28()]) : Promise.resolve(),
652
607
  start: async (startOptions) => {
653
608
  isActive = true;
654
609
  if (lastCheckpoint !== null)
@@ -656,13 +611,13 @@ var reactor = (options) => {
656
611
  lastCheckpoint
657
612
  };
658
613
  return await processingScope(async (context) => {
659
- if (_optionalChain([options, 'access', _31 => _31.hooks, 'optionalAccess', _32 => _32.onStart])) {
660
- await _optionalChain([options, 'access', _33 => _33.hooks, 'optionalAccess', _34 => _34.onStart, 'call', _35 => _35(context)]);
614
+ if (_optionalChain([options, 'access', _29 => _29.hooks, 'optionalAccess', _30 => _30.onStart])) {
615
+ await _optionalChain([options, 'access', _31 => _31.hooks, 'optionalAccess', _32 => _32.onStart, 'call', _33 => _33(context)]);
661
616
  }
662
617
  if (options.startFrom !== "CURRENT" && options.startFrom)
663
618
  return options.startFrom;
664
619
  if (checkpoints) {
665
- const readResult = await _optionalChain([checkpoints, 'optionalAccess', _36 => _36.read, 'call', _37 => _37(
620
+ const readResult = await _optionalChain([checkpoints, 'optionalAccess', _34 => _34.read, 'call', _35 => _35(
666
621
  {
667
622
  processorId,
668
623
  partition
@@ -727,12 +682,12 @@ var projector = (options) => {
727
682
  type: MessageProcessorType.PROJECTOR,
728
683
  processorId: _nullishCoalesce(options.processorId, () => ( `projection:${projection2.name}`)),
729
684
  hooks: {
730
- onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access', _38 => _38.hooks, 'optionalAccess', _39 => _39.onStart]) ? async (context) => {
685
+ onStart: options.truncateOnStart && options.projection.truncate || _optionalChain([options, 'access', _36 => _36.hooks, 'optionalAccess', _37 => _37.onStart]) ? async (context) => {
731
686
  if (options.truncateOnStart && options.projection.truncate)
732
687
  await options.projection.truncate(context);
733
- if (_optionalChain([options, 'access', _40 => _40.hooks, 'optionalAccess', _41 => _41.onStart])) await _optionalChain([options, 'access', _42 => _42.hooks, 'optionalAccess', _43 => _43.onStart, 'call', _44 => _44(context)]);
688
+ if (_optionalChain([options, 'access', _38 => _38.hooks, 'optionalAccess', _39 => _39.onStart])) await _optionalChain([options, 'access', _40 => _40.hooks, 'optionalAccess', _41 => _41.onStart, 'call', _42 => _42(context)]);
734
689
  } : void 0,
735
- onClose: _optionalChain([options, 'access', _45 => _45.hooks, 'optionalAccess', _46 => _46.onClose])
690
+ onClose: _optionalChain([options, 'access', _43 => _43.hooks, 'optionalAccess', _44 => _44.onClose])
736
691
  },
737
692
  eachMessage: async (event2, context) => {
738
693
  if (!projection2.canHandle.includes(event2.type)) return;
@@ -745,7 +700,7 @@ var inMemoryCheckpointer = () => {
745
700
  read: async ({ processorId }, { database }) => {
746
701
  const checkpoint = await database.collection("emt_processor_checkpoints").findOne((d) => d._id === processorId);
747
702
  return Promise.resolve({
748
- lastCheckpoint: _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _47 => _47.lastCheckpoint]), () => ( null))
703
+ lastCheckpoint: _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _45 => _45.lastCheckpoint]), () => ( null))
749
704
  });
750
705
  },
751
706
  store: async (context, { database }) => {
@@ -756,7 +711,7 @@ var inMemoryCheckpointer = () => {
756
711
  const checkpoint = await checkpoints.findOne(
757
712
  (d) => d._id === processorId
758
713
  );
759
- const currentPosition = _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _48 => _48.lastCheckpoint]), () => ( null));
714
+ const currentPosition = _nullishCoalesce(_optionalChain([checkpoint, 'optionalAccess', _46 => _46.lastCheckpoint]), () => ( null));
760
715
  const newCheckpoint = getCheckpoint(message2);
761
716
  if (currentPosition && (currentPosition === newCheckpoint || currentPosition !== lastCheckpoint)) {
762
717
  return {
@@ -776,7 +731,7 @@ var inMemoryCheckpointer = () => {
776
731
  var inMemoryProcessingScope = (options) => {
777
732
  const processorDatabase = options.database;
778
733
  const processingScope = (handler, partialContext) => {
779
- const database = _nullishCoalesce(processorDatabase, () => ( _optionalChain([partialContext, 'optionalAccess', _49 => _49.database])));
734
+ const database = _nullishCoalesce(processorDatabase, () => ( _optionalChain([partialContext, 'optionalAccess', _47 => _47.database])));
780
735
  if (!database)
781
736
  throw new EmmettError(
782
737
  `InMemory processor '${options.processorId}' is missing database. Ensure that you passed it through options`
@@ -786,11 +741,11 @@ var inMemoryProcessingScope = (options) => {
786
741
  return processingScope;
787
742
  };
788
743
  var inMemoryProjector = (options) => {
789
- const database = _nullishCoalesce(_optionalChain([options, 'access', _50 => _50.connectionOptions, 'optionalAccess', _51 => _51.database]), () => ( getInMemoryDatabase()));
744
+ const database = _nullishCoalesce(_optionalChain([options, 'access', _48 => _48.connectionOptions, 'optionalAccess', _49 => _49.database]), () => ( getInMemoryDatabase()));
790
745
  const hooks = {
791
- onStart: _optionalChain([options, 'access', _52 => _52.hooks, 'optionalAccess', _53 => _53.onStart]),
792
- onClose: _optionalChain([options, 'access', _54 => _54.hooks, 'optionalAccess', _55 => _55.onClose]) ? async () => {
793
- if (_optionalChain([options, 'access', _56 => _56.hooks, 'optionalAccess', _57 => _57.onClose])) await _optionalChain([options, 'access', _58 => _58.hooks, 'optionalAccess', _59 => _59.onClose, 'call', _60 => _60()]);
746
+ onStart: _optionalChain([options, 'access', _50 => _50.hooks, 'optionalAccess', _51 => _51.onStart]),
747
+ onClose: _optionalChain([options, 'access', _52 => _52.hooks, 'optionalAccess', _53 => _53.onClose]) ? async () => {
748
+ if (_optionalChain([options, 'access', _54 => _54.hooks, 'optionalAccess', _55 => _55.onClose])) await _optionalChain([options, 'access', _56 => _56.hooks, 'optionalAccess', _57 => _57.onClose, 'call', _58 => _58()]);
794
749
  } : void 0
795
750
  };
796
751
  return {
@@ -807,11 +762,11 @@ var inMemoryProjector = (options) => {
807
762
  };
808
763
  };
809
764
  var inMemoryReactor = (options) => {
810
- const database = _nullishCoalesce(_optionalChain([options, 'access', _61 => _61.connectionOptions, 'optionalAccess', _62 => _62.database]), () => ( getInMemoryDatabase()));
765
+ const database = _nullishCoalesce(_optionalChain([options, 'access', _59 => _59.connectionOptions, 'optionalAccess', _60 => _60.database]), () => ( getInMemoryDatabase()));
811
766
  const hooks = {
812
- onStart: _optionalChain([options, 'access', _63 => _63.hooks, 'optionalAccess', _64 => _64.onStart]),
813
- onClose: _optionalChain([options, 'access', _65 => _65.hooks, 'optionalAccess', _66 => _66.onClose]) ? async () => {
814
- if (_optionalChain([options, 'access', _67 => _67.hooks, 'optionalAccess', _68 => _68.onClose])) await _optionalChain([options, 'access', _69 => _69.hooks, 'optionalAccess', _70 => _70.onClose, 'call', _71 => _71()]);
767
+ onStart: _optionalChain([options, 'access', _61 => _61.hooks, 'optionalAccess', _62 => _62.onStart]),
768
+ onClose: _optionalChain([options, 'access', _63 => _63.hooks, 'optionalAccess', _64 => _64.onClose]) ? async () => {
769
+ if (_optionalChain([options, 'access', _65 => _65.hooks, 'optionalAccess', _66 => _66.onClose])) await _optionalChain([options, 'access', _67 => _67.hooks, 'optionalAccess', _68 => _68.onClose, 'call', _69 => _69()]);
815
770
  } : void 0
816
771
  };
817
772
  return {
@@ -827,147 +782,6 @@ var inMemoryReactor = (options) => {
827
782
  database
828
783
  };
829
784
  };
830
- var filter = (filter2) => new (0, _webstreamspolyfill.TransformStream)({
831
- transform(chunk, controller) {
832
- if (filter2(chunk)) {
833
- controller.enqueue(chunk);
834
- }
835
- }
836
- });
837
- var map = (map2) => new (0, _webstreamspolyfill.TransformStream)({
838
- transform(chunk, controller) {
839
- controller.enqueue(map2(chunk));
840
- }
841
- });
842
- var reduce = (reducer, initialValue) => new ReduceTransformStream(reducer, initialValue);
843
- var ReduceTransformStream = class extends _webstreamspolyfill.TransformStream {
844
-
845
-
846
- constructor(reducer, initialValue) {
847
- super({
848
- transform: (chunk) => {
849
- this.accumulator = this.reducer(this.accumulator, chunk);
850
- },
851
- flush: (controller) => {
852
- controller.enqueue(this.accumulator);
853
- controller.terminate();
854
- }
855
- });
856
- this.accumulator = initialValue;
857
- this.reducer = reducer;
858
- }
859
- };
860
- var retryStream = (createSourceStream, handleChunk2, retryOptions = { forever: true, minTimeout: 25 }) => new (0, _webstreamspolyfill.TransformStream)({
861
- start(controller) {
862
- asyncRetry(
863
- () => onRestream(createSourceStream, handleChunk2, controller),
864
- retryOptions
865
- ).catch((error2) => {
866
- controller.error(error2);
867
- });
868
- }
869
- });
870
- var onRestream = async (createSourceStream, handleChunk2, controller) => {
871
- const sourceStream = createSourceStream();
872
- const reader = sourceStream.getReader();
873
- try {
874
- let done;
875
- do {
876
- const result = await reader.read();
877
- done = result.done;
878
- await handleChunk2(result, controller);
879
- if (done) {
880
- controller.terminate();
881
- }
882
- } while (!done);
883
- } finally {
884
- reader.releaseLock();
885
- }
886
- };
887
- var skip = (limit) => new SkipTransformStream(limit);
888
- var SkipTransformStream = (_class2 = class extends _webstreamspolyfill.TransformStream {
889
- __init3() {this.count = 0}
890
-
891
- constructor(skip2) {
892
- super({
893
- transform: (chunk, controller) => {
894
- this.count++;
895
- if (this.count > this.skip) {
896
- controller.enqueue(chunk);
897
- }
898
- }
899
- });_class2.prototype.__init3.call(this);;
900
- this.skip = skip2;
901
- }
902
- }, _class2);
903
- var stopAfter = (stopCondition) => new (0, _webstreamspolyfill.TransformStream)({
904
- transform(chunk, controller) {
905
- controller.enqueue(chunk);
906
- if (stopCondition(chunk)) {
907
- controller.terminate();
908
- }
909
- }
910
- });
911
- var stopOn = (stopCondition) => new (0, _webstreamspolyfill.TransformStream)({
912
- async transform(chunk, controller) {
913
- if (!stopCondition(chunk)) {
914
- controller.enqueue(chunk);
915
- return;
916
- }
917
- await Promise.resolve();
918
- controller.terminate();
919
- }
920
- });
921
- var take = (limit) => new TakeTransformStream(limit);
922
- var TakeTransformStream = (_class3 = class extends _webstreamspolyfill.TransformStream {
923
- __init4() {this.count = 0}
924
-
925
- constructor(limit) {
926
- super({
927
- transform: (chunk, controller) => {
928
- if (this.count < this.limit) {
929
- this.count++;
930
- controller.enqueue(chunk);
931
- } else {
932
- controller.terminate();
933
- }
934
- }
935
- });_class3.prototype.__init4.call(this);;
936
- this.limit = limit;
937
- }
938
- }, _class3);
939
- var waitAtMost = (waitTimeInMs) => new (0, _webstreamspolyfill.TransformStream)({
940
- start(controller) {
941
- const timeoutId = setTimeout(() => {
942
- controller.terminate();
943
- }, waitTimeInMs);
944
- const originalTerminate = controller.terminate.bind(controller);
945
- controller.terminate = () => {
946
- clearTimeout(timeoutId);
947
- originalTerminate();
948
- };
949
- },
950
- transform(chunk, controller) {
951
- controller.enqueue(chunk);
952
- }
953
- });
954
- var streamTransformations = {
955
- filter,
956
- take,
957
- TakeTransformStream,
958
- skip,
959
- SkipTransformStream,
960
- map,
961
- notifyAboutNoActiveReadersStream,
962
- NotifyAboutNoActiveReadersStream,
963
- reduce,
964
- ReduceTransformStream,
965
- retry: retryStream,
966
- stopAfter,
967
- stopOn,
968
- waitAtMost
969
- };
970
- var { retry: retry2 } = streamTransformations;
971
785
 
972
786
  // src/eventStore/consumers/eventStoreDBEventStoreConsumer.ts
973
787
 
@@ -1003,7 +817,7 @@ var getEventStoreDBEventStore = (eventStore) => {
1003
817
  return {
1004
818
  async aggregateStream(streamName, options) {
1005
819
  const { evolve, initialState, read } = options;
1006
- const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _72 => _72.expectedStreamVersion]);
820
+ const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _70 => _70.expectedStreamVersion]);
1007
821
  let state = initialState();
1008
822
  let currentStreamVersion = EventStoreDBEventStoreDefaultStreamVersion;
1009
823
  let lastEventGlobalPosition = void 0;
@@ -1016,7 +830,7 @@ var getEventStoreDBEventStore = (eventStore) => {
1016
830
  if (!event) continue;
1017
831
  state = evolve(state, mapFromESDBEvent(resolvedEvent));
1018
832
  currentStreamVersion = event.revision;
1019
- lastEventGlobalPosition = _optionalChain([event, 'access', _73 => _73.position, 'optionalAccess', _74 => _74.commit]);
833
+ lastEventGlobalPosition = _optionalChain([event, 'access', _71 => _71.position, 'optionalAccess', _72 => _72.commit]);
1020
834
  }
1021
835
  assertExpectedVersionMatchesCurrent(
1022
836
  currentStreamVersion,
@@ -1077,7 +891,7 @@ var getEventStoreDBEventStore = (eventStore) => {
1077
891
  try {
1078
892
  const serializedEvents = events.map(_dbclient.jsonEvent);
1079
893
  const expectedRevision = toExpectedRevision(
1080
- _optionalChain([options, 'optionalAccess', _75 => _75.expectedStreamVersion])
894
+ _optionalChain([options, 'optionalAccess', _73 => _73.expectedStreamVersion])
1081
895
  );
1082
896
  const appendResult = await eventStore.appendToStream(
1083
897
  streamName,
@@ -1109,7 +923,7 @@ var getEventStoreDBEventStore = (eventStore) => {
1109
923
  };
1110
924
  };
1111
925
  var getCheckpoint2 = (resolvedEvent, from) => {
1112
- return !from || _optionalChain([from, 'optionalAccess', _76 => _76.stream]) === $all ? _nullishCoalesce(_optionalChain([resolvedEvent, 'access', _77 => _77.link, 'optionalAccess', _78 => _78.position, 'optionalAccess', _79 => _79.commit]), () => ( _optionalChain([resolvedEvent, 'access', _80 => _80.event, 'optionalAccess', _81 => _81.position, 'optionalAccess', _82 => _82.commit]))) : _nullishCoalesce(_optionalChain([resolvedEvent, 'access', _83 => _83.link, 'optionalAccess', _84 => _84.revision]), () => ( resolvedEvent.event.revision));
926
+ return !from || _optionalChain([from, 'optionalAccess', _74 => _74.stream]) === $all ? _nullishCoalesce(_optionalChain([resolvedEvent, 'access', _75 => _75.link, 'optionalAccess', _76 => _76.position, 'optionalAccess', _77 => _77.commit]), () => ( _optionalChain([resolvedEvent, 'access', _78 => _78.event, 'optionalAccess', _79 => _79.position, 'optionalAccess', _80 => _80.commit]))) : _nullishCoalesce(_optionalChain([resolvedEvent, 'access', _81 => _81.link, 'optionalAccess', _82 => _82.revision]), () => ( resolvedEvent.event.revision));
1113
927
  };
1114
928
  var mapFromESDBEvent = (resolvedEvent, from) => {
1115
929
  const event = resolvedEvent.event;
@@ -1150,7 +964,7 @@ var toGlobalPosition = (startFrom) => startFrom === "BEGINNING" ? _dbclient.STAR
1150
964
  };
1151
965
  var toStreamPosition = (startFrom) => startFrom === "BEGINNING" ? _dbclient.START : startFrom === "END" ? _dbclient.END : startFrom.lastCheckpoint;
1152
966
  var subscribe = (client, from, options) => from == void 0 || from.stream == $all ? client.subscribeToAll({
1153
- ..._nullishCoalesce(_optionalChain([from, 'optionalAccess', _85 => _85.options]), () => ( {})),
967
+ ..._nullishCoalesce(_optionalChain([from, 'optionalAccess', _83 => _83.options]), () => ( {})),
1154
968
  fromPosition: toGlobalPosition(options.startFrom),
1155
969
  filter: _dbclient.excludeSystemEvents.call(void 0, )
1156
970
  }) : client.subscribeToStream(from.stream, {
@@ -1209,7 +1023,7 @@ var eventStoreDBSubscription = ({
1209
1023
  let start;
1210
1024
  let processor;
1211
1025
  let subscription;
1212
- const resubscribeOptions = _nullishCoalesce(_optionalChain([resilience, 'optionalAccess', _86 => _86.resubscribeOptions]), () => ( {
1026
+ const resubscribeOptions = _nullishCoalesce(_optionalChain([resilience, 'optionalAccess', _84 => _84.resubscribeOptions]), () => ( {
1213
1027
  ...EventStoreDBResubscribeDefaultOptions,
1214
1028
  shouldRetryResult: () => isRunning,
1215
1029
  shouldRetryError: (error) => isRunning && EventStoreDBResubscribeDefaultOptions.shouldRetryError(error)
@@ -1223,11 +1037,11 @@ var eventStoreDBSubscription = ({
1223
1037
  }))));
1224
1038
  };
1225
1039
  const pipeMessages = (options) => {
1226
- let retry3 = 0;
1040
+ let retry2 = 0;
1227
1041
  return asyncRetry(
1228
1042
  () => new Promise((resolve, reject) => {
1229
1043
  console.info(
1230
- `Starting subscription. ${retry3++} retries. From: ${JSONParser.stringify(_nullishCoalesce(from, () => ( "$all")))}, Start from: ${JSONParser.stringify(
1044
+ `Starting subscription. ${retry2++} retries. From: ${JSONParser.stringify(_nullishCoalesce(from, () => ( "$all")))}, Start from: ${JSONParser.stringify(
1231
1045
  options.startFrom
1232
1046
  )}`
1233
1047
  );
@@ -1324,13 +1138,13 @@ var eventStoreDBEventStoreConsumer = (options) => {
1324
1138
  reason: "No active processors"
1325
1139
  };
1326
1140
  const result = await Promise.allSettled(
1327
- activeProcessors.map((s) => {
1328
- return s.handle(messagesBatch, { client });
1141
+ activeProcessors.map(async (s) => {
1142
+ return await s.handle(messagesBatch, { client });
1329
1143
  })
1330
1144
  );
1331
- const error = _optionalChain([result, 'access', _87 => _87.find, 'call', _88 => _88((r) => r.status === "rejected"), 'optionalAccess', _89 => _89.reason]);
1145
+ const error = _optionalChain([result, 'access', _85 => _85.find, 'call', _86 => _86((r) => r.status === "rejected"), 'optionalAccess', _87 => _87.reason]);
1332
1146
  return result.some(
1333
- (r) => r.status === "fulfilled" && _optionalChain([r, 'access', _90 => _90.value, 'optionalAccess', _91 => _91.type]) !== "STOP"
1147
+ (r) => r.status === "fulfilled" && _optionalChain([r, 'access', _88 => _88.value, 'optionalAccess', _89 => _89.type]) !== "STOP"
1334
1148
  ) ? void 0 : {
1335
1149
  type: "STOP",
1336
1150
  error: error ? EmmettError.mapFrom(error) : void 0
@@ -1340,7 +1154,7 @@ var eventStoreDBEventStoreConsumer = (options) => {
1340
1154
  client,
1341
1155
  from: options.from,
1342
1156
  eachBatch,
1343
- batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _92 => _92.batchSize]), () => ( DefaultEventStoreDBEventStoreProcessorBatchSize)),
1157
+ batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _90 => _90.batchSize]), () => ( DefaultEventStoreDBEventStoreProcessorBatchSize)),
1344
1158
  resilience: options.resilience
1345
1159
  });
1346
1160
  const stop = async () => {