@event-driven-io/emmett-esdb 0.38.6 → 0.39.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/index.js CHANGED
@@ -43,27 +43,10 @@ var ConcurrencyInMemoryDatabaseError = class _ConcurrencyInMemoryDatabaseError e
43
43
  };
44
44
 
45
45
  // ../emmett/dist/index.js
46
- import { v4 as uuid5 } from "uuid";
46
+ import { v4 as uuid3 } from "uuid";
47
47
  import { v7 as uuid } from "uuid";
48
48
  import retry from "async-retry";
49
49
  import { v4 as uuid2 } from "uuid";
50
- import { TransformStream } from "web-streams-polyfill";
51
- import { v4 as uuid4 } from "uuid";
52
- import { v4 as uuid3 } from "uuid";
53
- import { TransformStream as TransformStream2 } from "web-streams-polyfill";
54
- import { ReadableStream } from "web-streams-polyfill";
55
- import "web-streams-polyfill";
56
- import { TransformStream as TransformStream3 } from "web-streams-polyfill";
57
- import { TransformStream as TransformStream4 } from "web-streams-polyfill";
58
- import { TransformStream as TransformStream5 } from "web-streams-polyfill";
59
- import {
60
- TransformStream as TransformStream6
61
- } from "web-streams-polyfill";
62
- import { TransformStream as TransformStream7 } from "web-streams-polyfill";
63
- import { TransformStream as TransformStream8 } from "web-streams-polyfill";
64
- import { TransformStream as TransformStream9 } from "web-streams-polyfill";
65
- import { TransformStream as TransformStream10 } from "web-streams-polyfill";
66
- import { TransformStream as TransformStream11 } from "web-streams-polyfill";
67
50
  var STREAM_EXISTS = "STREAM_EXISTS";
68
51
  var STREAM_DOES_NOT_EXIST = "STREAM_DOES_NOT_EXIST";
69
52
  var NO_CONCURRENCY_CHECK = "NO_CONCURRENCY_CHECK";
@@ -576,44 +559,6 @@ var getInMemoryDatabase = () => {
576
559
  }
577
560
  };
578
561
  };
579
- var notifyAboutNoActiveReadersStream = (onNoActiveReaderCallback, options = {}) => new NotifyAboutNoActiveReadersStream(onNoActiveReaderCallback, options);
580
- var NotifyAboutNoActiveReadersStream = class extends TransformStream2 {
581
- constructor(onNoActiveReaderCallback, options = {}) {
582
- super({
583
- cancel: (reason) => {
584
- console.log("Stream was canceled. Reason:", reason);
585
- this.stopChecking();
586
- }
587
- });
588
- this.onNoActiveReaderCallback = onNoActiveReaderCallback;
589
- this.streamId = options?.streamId ?? uuid3();
590
- this.onNoActiveReaderCallback = onNoActiveReaderCallback;
591
- this.startChecking(options?.intervalCheckInMs ?? 20);
592
- }
593
- checkInterval = null;
594
- streamId;
595
- _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
- };
617
562
  var getCheckpoint = (message2) => {
618
563
  return "checkpoint" in message2.metadata && // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
619
564
  isBigint(message2.metadata.checkpoint) ? (
@@ -827,153 +772,12 @@ var inMemoryReactor = (options) => {
827
772
  database
828
773
  };
829
774
  };
830
- var filter = (filter2) => new TransformStream3({
831
- transform(chunk, controller) {
832
- if (filter2(chunk)) {
833
- controller.enqueue(chunk);
834
- }
835
- }
836
- });
837
- var map = (map2) => new TransformStream4({
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 TransformStream5 {
844
- accumulator;
845
- reducer;
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 TransformStream6({
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 = class extends TransformStream7 {
889
- count = 0;
890
- skip;
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
- });
900
- this.skip = skip2;
901
- }
902
- };
903
- var stopAfter = (stopCondition) => new TransformStream8({
904
- transform(chunk, controller) {
905
- controller.enqueue(chunk);
906
- if (stopCondition(chunk)) {
907
- controller.terminate();
908
- }
909
- }
910
- });
911
- var stopOn = (stopCondition) => new TransformStream9({
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 = class extends TransformStream10 {
923
- count = 0;
924
- limit;
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
- });
936
- this.limit = limit;
937
- }
938
- };
939
- var waitAtMost = (waitTimeInMs) => new TransformStream11({
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
775
 
972
776
  // src/eventStore/consumers/eventStoreDBEventStoreConsumer.ts
973
777
  import {
974
778
  EventStoreDBClient as EventStoreDBClient3
975
779
  } from "@eventstore/db-client";
976
- import { v7 as uuid6 } from "uuid";
780
+ import { v7 as uuid4 } from "uuid";
977
781
 
978
782
  // src/eventStore/consumers/subscriptions/index.ts
979
783
  import {
@@ -1223,11 +1027,11 @@ var eventStoreDBSubscription = ({
1223
1027
  }));
1224
1028
  };
1225
1029
  const pipeMessages = (options) => {
1226
- let retry3 = 0;
1030
+ let retry2 = 0;
1227
1031
  return asyncRetry(
1228
1032
  () => new Promise((resolve, reject) => {
1229
1033
  console.info(
1230
- `Starting subscription. ${retry3++} retries. From: ${JSONParser.stringify(from ?? "$all")}, Start from: ${JSONParser.stringify(
1034
+ `Starting subscription. ${retry2++} retries. From: ${JSONParser.stringify(from ?? "$all")}, Start from: ${JSONParser.stringify(
1231
1035
  options.startFrom
1232
1036
  )}`
1233
1037
  );
@@ -1324,8 +1128,8 @@ var eventStoreDBEventStoreConsumer = (options) => {
1324
1128
  reason: "No active processors"
1325
1129
  };
1326
1130
  const result = await Promise.allSettled(
1327
- activeProcessors.map((s) => {
1328
- return s.handle(messagesBatch, { client });
1131
+ activeProcessors.map(async (s) => {
1132
+ return await s.handle(messagesBatch, { client });
1329
1133
  })
1330
1134
  );
1331
1135
  const error = result.find((r) => r.status === "rejected")?.reason;
@@ -1353,7 +1157,7 @@ var eventStoreDBEventStoreConsumer = (options) => {
1353
1157
  await start;
1354
1158
  };
1355
1159
  return {
1356
- consumerId: options.consumerId ?? uuid6(),
1160
+ consumerId: options.consumerId ?? uuid4(),
1357
1161
  get isRunning() {
1358
1162
  return isRunning;
1359
1163
  },