@event-driven-io/emmett-postgresql 0.43.0-beta.1 → 0.43.0-beta.3

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
@@ -53,9 +53,20 @@ var _uuid = require('uuid');
53
53
  var _asyncretry = require('async-retry'); var _asyncretry2 = _interopRequireDefault(_asyncretry);
54
54
 
55
55
 
56
+
56
57
  var emmettPrefix = "emt";
57
58
  var defaultTag = `${emmettPrefix}:default`;
58
59
  var unknownTag = `${emmettPrefix}:unknown`;
60
+ var canCreateEventStoreSession = (eventStore) => "withSession" in eventStore;
61
+ var nulloSessionFactory = (eventStore) => ({
62
+ withSession: (callback) => {
63
+ const nulloSession = {
64
+ eventStore,
65
+ close: () => Promise.resolve()
66
+ };
67
+ return callback(nulloSession);
68
+ }
69
+ });
59
70
  var STREAM_EXISTS = "STREAM_EXISTS";
60
71
  var STREAM_DOES_NOT_EXIST = "STREAM_DOES_NOT_EXIST";
61
72
  var NO_CONCURRENCY_CHECK = "NO_CONCURRENCY_CHECK";
@@ -76,6 +87,10 @@ var ExpectedVersionConflictError = class _ExpectedVersionConflictError extends C
76
87
  Object.setPrototypeOf(this, _ExpectedVersionConflictError.prototype);
77
88
  }
78
89
  };
90
+ var isExpectedVersionConflictError = (error) => error instanceof ExpectedVersionConflictError || EmmettError.isInstanceOf(
91
+ error,
92
+ ExpectedVersionConflictError.Codes.ConcurrencyError
93
+ );
79
94
  var isPrimitive = (value) => {
80
95
  const type = typeof value;
81
96
  return value === null || value === void 0 || type === "boolean" || type === "number" || type === "string" || type === "symbol" || type === "bigint";
@@ -302,6 +317,7 @@ var JSONParser = {
302
317
  return _optionalChain([options, 'optionalAccess', _13 => _13.map]) ? options.map(parsed) : parsed;
303
318
  }
304
319
  };
320
+ var NoRetries = { retries: 0 };
305
321
  var asyncRetry = async (fn, opts) => {
306
322
  if (opts === void 0 || opts.retries === 0) return fn();
307
323
  return _asyncretry2.default.call(void 0,
@@ -314,12 +330,12 @@ var asyncRetry = async (fn, opts) => {
314
330
  );
315
331
  }
316
332
  return result;
317
- } catch (error2) {
318
- if (_optionalChain([opts, 'optionalAccess', _15 => _15.shouldRetryError]) && !opts.shouldRetryError(error2)) {
319
- bail(error2);
333
+ } catch (error) {
334
+ if (_optionalChain([opts, 'optionalAccess', _15 => _15.shouldRetryError]) && !opts.shouldRetryError(error)) {
335
+ bail(error);
320
336
  return void 0;
321
337
  }
322
- throw error2;
338
+ throw error;
323
339
  }
324
340
  },
325
341
  _nullishCoalesce(opts, () => ( { retries: 0 }))
@@ -423,12 +439,13 @@ var reactor = (options) => {
423
439
  id: processorId,
424
440
  instanceId,
425
441
  type,
442
+ canHandle,
426
443
  init,
427
444
  start: async (startOptions) => {
428
445
  if (isActive) return;
429
446
  await init(startOptions);
430
447
  isActive = true;
431
- closeSignal = onShutdown(() => close({}));
448
+ closeSignal = onShutdown(() => close(startOptions));
432
449
  if (lastCheckpoint !== null)
433
450
  return {
434
451
  lastCheckpoint
@@ -585,6 +602,9 @@ function assertIsNotNull(result) {
585
602
  assertNotEqual(result, null);
586
603
  assertOk(result);
587
604
  }
605
+ function assertIsNull(result) {
606
+ assertEqual(result, null);
607
+ }
588
608
  var assertThatArray = (array) => {
589
609
  return {
590
610
  isEmpty: () => assertEqual(
@@ -690,6 +710,243 @@ var upcastRecordedMessage = (recordedMessage, options) => {
690
710
  };
691
711
  };
692
712
  var projection = (definition) => definition;
713
+ var WorkflowHandlerStreamVersionConflictRetryOptions = {
714
+ retries: 3,
715
+ minTimeout: 100,
716
+ factor: 1.5,
717
+ shouldRetryError: isExpectedVersionConflictError
718
+ };
719
+ var fromWorkflowHandlerRetryOptions = (retryOptions) => {
720
+ if (retryOptions === void 0) return NoRetries;
721
+ if ("onVersionConflict" in retryOptions) {
722
+ if (typeof retryOptions.onVersionConflict === "boolean")
723
+ return WorkflowHandlerStreamVersionConflictRetryOptions;
724
+ else if (typeof retryOptions.onVersionConflict === "number")
725
+ return {
726
+ ...WorkflowHandlerStreamVersionConflictRetryOptions,
727
+ retries: retryOptions.onVersionConflict
728
+ };
729
+ else return retryOptions.onVersionConflict;
730
+ }
731
+ return retryOptions;
732
+ };
733
+ var emptyHandlerResult = (nextExpectedStreamVersion = 0n) => ({
734
+ newMessages: [],
735
+ createdNewStream: false,
736
+ nextExpectedStreamVersion
737
+ });
738
+ var createInputMetadata = (originalMessageId, action) => ({
739
+ originalMessageId,
740
+ input: true,
741
+ action
742
+ });
743
+ var tagOutputMessage = (msg, action) => {
744
+ const existingMetadata = "metadata" in msg && msg.metadata ? msg.metadata : {};
745
+ return {
746
+ ...msg,
747
+ metadata: {
748
+ ...existingMetadata,
749
+ action
750
+ }
751
+ };
752
+ };
753
+ var createWrappedInitialState = (initialState) => {
754
+ return () => ({
755
+ userState: initialState(),
756
+ processedInputIds: /* @__PURE__ */ new Set()
757
+ });
758
+ };
759
+ var createWrappedEvolve = (evolve, workflowName, separateInputInboxFromProcessing) => {
760
+ return (state, event2) => {
761
+ const metadata = event2.metadata;
762
+ let processedInputIds = state.processedInputIds;
763
+ if (_optionalChain([metadata, 'optionalAccess', _35 => _35.input]) === true && typeof _optionalChain([metadata, 'optionalAccess', _36 => _36.originalMessageId]) === "string") {
764
+ processedInputIds = new Set(state.processedInputIds);
765
+ processedInputIds.add(metadata.originalMessageId);
766
+ }
767
+ if (separateInputInboxFromProcessing && _optionalChain([metadata, 'optionalAccess', _37 => _37.input]) === true) {
768
+ return {
769
+ userState: state.userState,
770
+ processedInputIds
771
+ };
772
+ }
773
+ const eventType = event2.type;
774
+ const eventForEvolve = eventType.startsWith(`${workflowName}:`) ? {
775
+ ...event2,
776
+ type: eventType.replace(`${workflowName}:`, "")
777
+ } : event2;
778
+ return {
779
+ userState: evolve(state.userState, eventForEvolve),
780
+ processedInputIds
781
+ };
782
+ };
783
+ };
784
+ var workflowStreamName = ({
785
+ workflowName,
786
+ workflowId
787
+ }) => `emt:workflow:${workflowName}:${workflowId}`;
788
+ var WorkflowHandler = (options) => async (store, message2, handleOptions) => asyncRetry(
789
+ async () => {
790
+ const result = await withSession2(store, async ({ eventStore }) => {
791
+ const {
792
+ workflow: { evolve, initialState, decide, name: workflowName },
793
+ getWorkflowId: getWorkflowId2
794
+ } = options;
795
+ const inputMessageId = (
796
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
797
+ _nullishCoalesce(("metadata" in message2 && _optionalChain([message2, 'access', _38 => _38.metadata, 'optionalAccess', _39 => _39.messageId]) ? (
798
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
799
+ message2.metadata.messageId
800
+ ) : void 0), () => ( _uuid.v7.call(void 0, )))
801
+ );
802
+ const messageWithMetadata = {
803
+ ...message2,
804
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
805
+ metadata: {
806
+ messageId: inputMessageId,
807
+ ...message2.metadata
808
+ }
809
+ };
810
+ const workflowId = getWorkflowId2(messageWithMetadata);
811
+ if (!workflowId) {
812
+ return emptyHandlerResult();
813
+ }
814
+ const streamName = options.mapWorkflowId ? options.mapWorkflowId(workflowId) : workflowStreamName({ workflowName, workflowId });
815
+ const messageType = messageWithMetadata.type;
816
+ const hasWorkflowPrefix = messageType.startsWith(`${workflowName}:`);
817
+ if (options.separateInputInboxFromProcessing && !hasWorkflowPrefix) {
818
+ const inputMetadata2 = createInputMetadata(
819
+ inputMessageId,
820
+ "InitiatedBy"
821
+ );
822
+ const inputToStore2 = {
823
+ type: `${workflowName}:${messageWithMetadata.type}`,
824
+ data: messageWithMetadata.data,
825
+ kind: messageWithMetadata.kind,
826
+ metadata: inputMetadata2
827
+ };
828
+ const appendResult2 = await eventStore.appendToStream(
829
+ streamName,
830
+ [inputToStore2],
831
+ {
832
+ ...handleOptions,
833
+ expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _40 => _40.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
834
+ }
835
+ );
836
+ return {
837
+ ...appendResult2,
838
+ newMessages: []
839
+ };
840
+ }
841
+ const wrappedInitialState = createWrappedInitialState(initialState);
842
+ const wrappedEvolve = createWrappedEvolve(
843
+ evolve,
844
+ workflowName,
845
+ _nullishCoalesce(options.separateInputInboxFromProcessing, () => ( false))
846
+ );
847
+ const aggregationResult = await eventStore.aggregateStream(streamName, {
848
+ evolve: wrappedEvolve,
849
+ initialState: wrappedInitialState,
850
+ read: {
851
+ ...handleOptions,
852
+ // expected stream version is passed to fail fast
853
+ // if stream is in the wrong state
854
+ expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _41 => _41.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
855
+ }
856
+ });
857
+ const { currentStreamVersion } = aggregationResult;
858
+ const { userState: state, processedInputIds } = aggregationResult.state;
859
+ if (processedInputIds.has(inputMessageId)) {
860
+ return emptyHandlerResult(currentStreamVersion);
861
+ }
862
+ const messageForDecide = hasWorkflowPrefix ? {
863
+ ...messageWithMetadata,
864
+ type: messageType.replace(`${workflowName}:`, "")
865
+ } : messageWithMetadata;
866
+ const result2 = decide(messageForDecide, state);
867
+ const inputMetadata = createInputMetadata(
868
+ inputMessageId,
869
+ aggregationResult.streamExists ? "Received" : "InitiatedBy"
870
+ );
871
+ const inputToStore = {
872
+ type: `${workflowName}:${messageWithMetadata.type}`,
873
+ data: messageWithMetadata.data,
874
+ kind: messageWithMetadata.kind,
875
+ metadata: inputMetadata
876
+ };
877
+ const outputMessages = (Array.isArray(result2) ? result2 : [result2]).filter((msg) => msg !== void 0 && msg !== null);
878
+ const outputCommandTypes = _nullishCoalesce(_optionalChain([options, 'access', _42 => _42.outputs, 'optionalAccess', _43 => _43.commands]), () => ( []));
879
+ const taggedOutputMessages = outputMessages.map((msg) => {
880
+ const action = outputCommandTypes.includes(
881
+ msg.type
882
+ ) ? "Sent" : "Published";
883
+ return tagOutputMessage(msg, action);
884
+ });
885
+ const messagesToAppend = options.separateInputInboxFromProcessing && hasWorkflowPrefix ? [...taggedOutputMessages] : [inputToStore, ...taggedOutputMessages];
886
+ if (messagesToAppend.length === 0) {
887
+ return emptyHandlerResult(currentStreamVersion);
888
+ }
889
+ const expectedStreamVersion = _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _44 => _44.expectedStreamVersion]), () => ( (aggregationResult.streamExists ? currentStreamVersion : STREAM_DOES_NOT_EXIST)));
890
+ const appendResult = await eventStore.appendToStream(
891
+ streamName,
892
+ // TODO: Fix this cast
893
+ messagesToAppend,
894
+ {
895
+ ...handleOptions,
896
+ expectedStreamVersion
897
+ }
898
+ );
899
+ return {
900
+ ...appendResult,
901
+ newMessages: outputMessages
902
+ };
903
+ });
904
+ return result;
905
+ },
906
+ fromWorkflowHandlerRetryOptions(
907
+ handleOptions && "retry" in handleOptions ? handleOptions.retry : options.retry
908
+ )
909
+ );
910
+ var withSession2 = (eventStore, callback) => {
911
+ const sessionFactory = canCreateEventStoreSession(eventStore) ? eventStore : nulloSessionFactory(eventStore);
912
+ return sessionFactory.withSession(callback);
913
+ };
914
+ var getWorkflowId = (options) => `emt:processor:workflow:${options.workflowName}`;
915
+ var workflowProcessor = (options) => {
916
+ const { workflow, ...rest } = options;
917
+ const canHandle = options.separateInputInboxFromProcessing ? [
918
+ ...options.inputs.commands,
919
+ ...options.inputs.events,
920
+ ...options.inputs.commands.map((t) => `${workflow.name}:${t}`),
921
+ ...options.inputs.events.map((t) => `${workflow.name}:${t}`)
922
+ ] : [...options.inputs.commands, ...options.inputs.events];
923
+ const handle = WorkflowHandler(options);
924
+ return reactor({
925
+ ...rest,
926
+ processorId: _nullishCoalesce(options.processorId, () => ( getWorkflowId({ workflowName: workflow.name }))),
927
+ canHandle,
928
+ type: MessageProcessorType.PROJECTOR,
929
+ eachMessage: async (message2, context) => {
930
+ const messageType = message2.type;
931
+ if (!canHandle.includes(messageType)) return;
932
+ const result = await handle(
933
+ context.connection.messageStore,
934
+ message2,
935
+ context
936
+ );
937
+ if (options.stopAfter && result.newMessages.length > 0) {
938
+ for (const outputMessage of result.newMessages) {
939
+ if (options.stopAfter(
940
+ outputMessage
941
+ )) {
942
+ return { type: "STOP", reason: "Stop condition reached" };
943
+ }
944
+ }
945
+ }
946
+ return;
947
+ }
948
+ });
949
+ };
693
950
 
694
951
  // src/eventStore/schema/readLastMessageGlobalPosition.ts
695
952
  var _dumbo = require('@event-driven-io/dumbo');
@@ -736,7 +993,7 @@ var readLastMessageGlobalPosition = async (execute, options) => {
736
993
  execute.query(
737
994
  _dumbo.SQL`SELECT global_position
738
995
  FROM ${_dumbo.SQL.identifier(messagesTable.name)}
739
- WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _35 => _35.partition]), () => ( defaultTag2))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
996
+ WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _45 => _45.partition]), () => ( defaultTag2))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
740
997
  ORDER BY transaction_id, global_position
741
998
  LIMIT 1`
742
999
  )
@@ -760,7 +1017,7 @@ var readMessagesBatch = async (execute, options) => {
760
1017
  _dumbo.SQL`
761
1018
  SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
762
1019
  FROM ${_dumbo.SQL.identifier(messagesTable.name)}
763
- WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _36 => _36.partition]), () => ( defaultTag2))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot()) ${fromCondition} ${toCondition}
1020
+ WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _46 => _46.partition]), () => ( defaultTag2))} AND is_archived = FALSE AND transaction_id < pg_snapshot_xmin(pg_current_snapshot()) ${fromCondition} ${toCondition}
764
1021
  ORDER BY transaction_id, global_position
765
1022
  ${limitCondition}`
766
1023
  ),
@@ -816,7 +1073,7 @@ var postgreSQLEventStoreMessageBatchPuller = ({
816
1073
  batchSize
817
1074
  };
818
1075
  let waitTime = 100;
819
- while (isRunning && !_optionalChain([signal, 'optionalAccess', _37 => _37.aborted])) {
1076
+ while (isRunning && !_optionalChain([signal, 'optionalAccess', _47 => _47.aborted])) {
820
1077
  const { messages, currentGlobalPosition, areMessagesLeft } = await readMessagesBatch(executor, readMessagesOptions);
821
1078
  if (messages.length > 0) {
822
1079
  const result = await eachBatch(messages);
@@ -827,7 +1084,7 @@ var postgreSQLEventStoreMessageBatchPuller = ({
827
1084
  }
828
1085
  readMessagesOptions.after = currentGlobalPosition;
829
1086
  await new Promise((resolve) => setTimeout(resolve, waitTime));
830
- if (_optionalChain([stopWhen, 'optionalAccess', _38 => _38.noMessagesLeft]) === true && !areMessagesLeft) {
1087
+ if (_optionalChain([stopWhen, 'optionalAccess', _48 => _48.noMessagesLeft]) === true && !areMessagesLeft) {
831
1088
  isRunning = false;
832
1089
  break;
833
1090
  }
@@ -871,6 +1128,14 @@ var zipPostgreSQLEventStoreMessageBatchPullerStartFrom = (options) => {
871
1128
  // src/eventStore/consumers/postgreSQLProcessor.ts
872
1129
 
873
1130
 
1131
+ // src/eventStore/postgreSQLEventStore.ts
1132
+
1133
+
1134
+
1135
+
1136
+
1137
+
1138
+
874
1139
  // src/eventStore/projections/locks/tryAcquireProjectionLock.ts
875
1140
 
876
1141
 
@@ -1121,9 +1386,9 @@ var tryAcquireProcessorLock = async (execute, options) => {
1121
1386
  version: options.version,
1122
1387
  partition: options.partition,
1123
1388
  processorInstanceId: options.processorInstanceId,
1124
- projectionName: _nullishCoalesce(_optionalChain([options, 'access', _39 => _39.projection, 'optionalAccess', _40 => _40.name]), () => ( null)),
1125
- projectionType: _optionalChain([options, 'access', _41 => _41.projection, 'optionalAccess', _42 => _42.handlingType]) ? options.projection.handlingType === "inline" ? "i" : "a" : null,
1126
- projectionKind: _nullishCoalesce(_optionalChain([options, 'access', _43 => _43.projection, 'optionalAccess', _44 => _44.kind]), () => ( null)),
1389
+ projectionName: _nullishCoalesce(_optionalChain([options, 'access', _49 => _49.projection, 'optionalAccess', _50 => _50.name]), () => ( null)),
1390
+ projectionType: _optionalChain([options, 'access', _51 => _51.projection, 'optionalAccess', _52 => _52.handlingType]) ? options.projection.handlingType === "inline" ? "i" : "a" : null,
1391
+ projectionKind: _nullishCoalesce(_optionalChain([options, 'access', _53 => _53.projection, 'optionalAccess', _54 => _54.kind]), () => ( null)),
1127
1392
  lockTimeoutSeconds: _nullishCoalesce(options.lockTimeoutSeconds, () => ( PROCESSOR_LOCK_DEFAULT_TIMEOUT_SECONDS))
1128
1393
  })
1129
1394
  )
@@ -1175,7 +1440,7 @@ var postgreSQLProcessorLock = (options) => {
1175
1440
  ...options,
1176
1441
  lockKey
1177
1442
  });
1178
- if (!result.acquired && _optionalChain([options, 'access', _45 => _45.lockAcquisitionPolicy, 'optionalAccess', _46 => _46.type]) !== "skip") {
1443
+ if (!result.acquired && _optionalChain([options, 'access', _55 => _55.lockAcquisitionPolicy, 'optionalAccess', _56 => _56.type]) !== "skip") {
1179
1444
  throw new EmmettError(
1180
1445
  `Failed to acquire lock for processor '${options.processorId}'`
1181
1446
  );
@@ -1189,7 +1454,7 @@ var postgreSQLProcessorLock = (options) => {
1189
1454
  await releaseProcessorLock(context.execute, {
1190
1455
  ...releaseOptions,
1191
1456
  lockKey,
1192
- projectionName: _optionalChain([projection2, 'optionalAccess', _47 => _47.name])
1457
+ projectionName: _optionalChain([projection2, 'optionalAccess', _57 => _57.name])
1193
1458
  });
1194
1459
  acquired = false;
1195
1460
  }
@@ -1650,7 +1915,7 @@ var documentDoesNotExist = (options) => (assertOptions) => withCollection(
1650
1915
  const result = await collection.findOne(
1651
1916
  "withId" in options ? { _id: options.withId } : options.matchingFilter
1652
1917
  );
1653
- assertIsNotNull(result);
1918
+ assertIsNull(result);
1654
1919
  },
1655
1920
  { ...options, ...assertOptions }
1656
1921
  );
@@ -1702,44 +1967,282 @@ var expectPongoDocuments = {
1702
1967
 
1703
1968
 
1704
1969
 
1970
+ var PostgreSQLProjectionSpec = {
1971
+ for: (options) => {
1972
+ {
1973
+ const { projection: projection2, ...dumoOptions } = options;
1974
+ const { connectionString } = dumoOptions;
1975
+ let wasInitialised = false;
1976
+ const initialize = async (pool) => {
1977
+ const eventStore = getPostgreSQLEventStore(connectionString, {
1978
+ // TODO: This will need to change when we support other drivers
1979
+ connectionOptions: { dumbo: pool }
1980
+ });
1981
+ if (wasInitialised) return;
1982
+ wasInitialised = true;
1983
+ await eventStore.schema.migrate();
1984
+ if (projection2.init)
1985
+ await pool.withTransaction(async (transaction) => {
1986
+ await projection2.init({
1987
+ registrationType: "async",
1988
+ version: _nullishCoalesce(projection2.version, () => ( 1)),
1989
+ status: "active",
1990
+ context: await transactionToPostgreSQLProjectionHandlerContext(
1991
+ connectionString,
1992
+ pool,
1993
+ transaction
1994
+ )
1995
+ });
1996
+ });
1997
+ };
1998
+ return (givenEvents) => {
1999
+ return {
2000
+ when: (events, options2) => {
2001
+ const allEvents = [];
2002
+ const run = async (pool) => {
2003
+ let globalPosition = 0n;
2004
+ const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _58 => _58.numberOfTimes]), () => ( 1));
2005
+ for (const event of [
2006
+ ...givenEvents,
2007
+ ...Array.from({ length: numberOfTimes }).flatMap(() => events)
2008
+ ]) {
2009
+ const metadata = {
2010
+ checkpoint: bigIntProcessorCheckpoint(++globalPosition),
2011
+ globalPosition,
2012
+ streamPosition: globalPosition,
2013
+ streamName: `test-${_uuid.v4.call(void 0, )}`,
2014
+ messageId: _uuid.v4.call(void 0, )
2015
+ };
2016
+ allEvents.push({
2017
+ ...event,
2018
+ kind: "Event",
2019
+ metadata: {
2020
+ ...metadata,
2021
+ ..."metadata" in event ? _nullishCoalesce(event.metadata, () => ( {})) : {}
2022
+ }
2023
+ });
2024
+ }
2025
+ await initialize(pool);
2026
+ await pool.withTransaction(async (transaction) => {
2027
+ await handleProjections({
2028
+ events: allEvents,
2029
+ projections: [projection2],
2030
+ ...await transactionToPostgreSQLProjectionHandlerContext(
2031
+ connectionString,
2032
+ pool,
2033
+ transaction
2034
+ )
2035
+ });
2036
+ });
2037
+ };
2038
+ return {
2039
+ then: async (assert, message) => {
2040
+ const pool = _dumbo.dumbo.call(void 0, dumoOptions);
2041
+ try {
2042
+ await run(pool);
2043
+ const succeeded = await assert({ pool, connectionString });
2044
+ if (succeeded !== void 0 && succeeded === false)
2045
+ assertFails(
2046
+ _nullishCoalesce(message, () => ( "Projection specification didn't match the criteria"))
2047
+ );
2048
+ } finally {
2049
+ await pool.close();
2050
+ }
2051
+ },
2052
+ thenThrows: async (...args) => {
2053
+ const pool = _dumbo.dumbo.call(void 0, dumoOptions);
2054
+ try {
2055
+ await run(pool);
2056
+ throw new AssertionError("Handler did not fail as expected");
2057
+ } catch (error) {
2058
+ if (error instanceof AssertionError) throw error;
2059
+ if (args.length === 0) return;
2060
+ if (!isErrorConstructor(args[0])) {
2061
+ assertTrue(
2062
+ args[0](error),
2063
+ `Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _59 => _59.toString, 'call', _60 => _60()])}`
2064
+ );
2065
+ return;
2066
+ }
2067
+ assertTrue(
2068
+ error instanceof args[0],
2069
+ `Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _61 => _61.toString, 'call', _62 => _62()])}`
2070
+ );
2071
+ if (args[1]) {
2072
+ assertTrue(
2073
+ args[1](error),
2074
+ `Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _63 => _63.toString, 'call', _64 => _64()])}`
2075
+ );
2076
+ }
2077
+ } finally {
2078
+ await pool.close();
2079
+ }
2080
+ }
2081
+ };
2082
+ }
2083
+ };
2084
+ };
2085
+ }
2086
+ }
2087
+ };
2088
+ var eventInStream = (streamName, event) => {
2089
+ return {
2090
+ ...event,
2091
+ metadata: {
2092
+ ..._nullishCoalesce(event.metadata, () => ( {})),
2093
+ streamName: _nullishCoalesce(_optionalChain([event, 'access', _65 => _65.metadata, 'optionalAccess', _66 => _66.streamName]), () => ( streamName))
2094
+ }
2095
+ };
2096
+ };
2097
+ var eventsInStream = (streamName, events) => {
2098
+ return events.map((e) => eventInStream(streamName, e));
2099
+ };
2100
+ var newEventsInStream = eventsInStream;
2101
+ var assertSQLQueryResultMatches = (sql, rows) => async ({ pool: { execute } }) => {
2102
+ const result = await execute.query(sql);
2103
+ assertThatArray(rows).containsExactlyInAnyOrder(result.rows);
2104
+ };
2105
+ var expectSQL = {
2106
+ query: (sql) => ({
2107
+ resultRows: {
2108
+ toBeTheSame: (rows) => assertSQLQueryResultMatches(sql, rows)
2109
+ }
2110
+ })
2111
+ };
1705
2112
 
1706
- // src/eventStore/postgreSQLEventStore.ts
1707
-
1708
-
1709
-
1710
-
1711
-
1712
-
1713
-
1714
- // src/eventStore/schema/index.ts
1715
-
1716
-
1717
-
1718
-
1719
-
1720
-
1721
- // src/eventStore/schema/appendToStream.ts
1722
-
1723
-
1724
-
1725
-
1726
-
1727
-
1728
-
1729
- var appendToStreamSQL = createFunctionIfDoesNotExistSQL(
1730
- "emt_append_to_stream",
1731
- _dumbo.SQL`CREATE OR REPLACE FUNCTION emt_append_to_stream(
1732
- v_message_ids text[],
1733
- v_messages_data jsonb[],
1734
- v_messages_metadata jsonb[],
1735
- v_message_schema_versions text[],
1736
- v_message_types text[],
1737
- v_message_kinds text[],
1738
- v_stream_id text,
1739
- v_stream_type text,
1740
- v_expected_stream_position bigint DEFAULT NULL,
1741
- v_partition text DEFAULT emt_sanitize_name('default_partition')
1742
- ) RETURNS TABLE (
2113
+ // src/eventStore/projections/postgreSQLProjection.ts
2114
+ var transactionToPostgreSQLProjectionHandlerContext = async (connectionString, pool, transaction) => ({
2115
+ execute: transaction.execute,
2116
+ connection: {
2117
+ connectionString,
2118
+ client: await transaction.connection.open(),
2119
+ transaction,
2120
+ pool
2121
+ }
2122
+ });
2123
+ var handleProjections = async (options) => {
2124
+ const {
2125
+ projections: allProjections,
2126
+ events,
2127
+ connection: { pool, transaction, connectionString },
2128
+ partition = defaultTag2
2129
+ } = options;
2130
+ const eventTypes = events.map((e) => e.type);
2131
+ const projections = allProjections.filter(
2132
+ (p) => p.canHandle.some((type) => eventTypes.includes(type))
2133
+ );
2134
+ const client = await transaction.connection.open();
2135
+ for (const projection2 of projections) {
2136
+ if (projection2.name) {
2137
+ const lockAcquired = await postgreSQLProjectionLock({
2138
+ projectionName: projection2.name,
2139
+ partition,
2140
+ version: _nullishCoalesce(projection2.version, () => ( 1))
2141
+ }).tryAcquire({ execute: transaction.execute });
2142
+ if (!lockAcquired) {
2143
+ continue;
2144
+ }
2145
+ }
2146
+ await projection2.handle(events, {
2147
+ connection: {
2148
+ connectionString,
2149
+ pool,
2150
+ client,
2151
+ transaction
2152
+ },
2153
+ execute: transaction.execute
2154
+ });
2155
+ }
2156
+ };
2157
+ var postgreSQLProjection = (definition) => projection({
2158
+ ...definition,
2159
+ init: async (options) => {
2160
+ await registerProjection(options.context.execute, {
2161
+ // TODO: pass partition from options
2162
+ partition: defaultTag2,
2163
+ status: "active",
2164
+ registration: {
2165
+ type: "async",
2166
+ // TODO: fix this
2167
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
2168
+ projection: definition
2169
+ }
2170
+ });
2171
+ if (definition.init) {
2172
+ await definition.init(options);
2173
+ }
2174
+ }
2175
+ });
2176
+ var postgreSQLRawBatchSQLProjection = (options) => postgreSQLProjection({
2177
+ name: options.name,
2178
+ kind: _nullishCoalesce(options.kind, () => ( "emt:projections:postgresql:raw_sql:batch")),
2179
+ version: options.version,
2180
+ canHandle: options.canHandle,
2181
+ eventsOptions: options.eventsOptions,
2182
+ handle: async (events, context) => {
2183
+ const sqls = await options.evolve(events, context);
2184
+ await context.execute.batchCommand(sqls);
2185
+ },
2186
+ init: async (initOptions) => {
2187
+ const initSQL = options.init ? await options.init(initOptions) : void 0;
2188
+ if (initSQL) {
2189
+ if (Array.isArray(initSQL)) {
2190
+ await initOptions.context.execute.batchCommand(initSQL);
2191
+ } else {
2192
+ await initOptions.context.execute.command(initSQL);
2193
+ }
2194
+ }
2195
+ }
2196
+ });
2197
+ var postgreSQLRawSQLProjection = (options) => {
2198
+ const { evolve, kind, ...rest } = options;
2199
+ return postgreSQLRawBatchSQLProjection({
2200
+ kind: _nullishCoalesce(kind, () => ( "emt:projections:postgresql:raw:_sql:single")),
2201
+ ...rest,
2202
+ evolve: async (events, context) => {
2203
+ const sqls = [];
2204
+ for (const event of events) {
2205
+ const pendingSqls = await evolve(event, context);
2206
+ if (Array.isArray(pendingSqls)) {
2207
+ sqls.push(...pendingSqls);
2208
+ } else {
2209
+ sqls.push(pendingSqls);
2210
+ }
2211
+ }
2212
+ return sqls;
2213
+ }
2214
+ });
2215
+ };
2216
+
2217
+ // src/eventStore/schema/index.ts
2218
+
2219
+
2220
+
2221
+
2222
+
2223
+
2224
+ // src/eventStore/schema/appendToStream.ts
2225
+
2226
+
2227
+
2228
+
2229
+
2230
+
2231
+
2232
+ var appendToStreamSQL = createFunctionIfDoesNotExistSQL(
2233
+ "emt_append_to_stream",
2234
+ _dumbo.SQL`CREATE OR REPLACE FUNCTION emt_append_to_stream(
2235
+ v_message_ids text[],
2236
+ v_messages_data jsonb[],
2237
+ v_messages_metadata jsonb[],
2238
+ v_message_schema_versions text[],
2239
+ v_message_types text[],
2240
+ v_message_kinds text[],
2241
+ v_stream_id text,
2242
+ v_stream_type text,
2243
+ v_expected_stream_position bigint DEFAULT NULL,
2244
+ v_partition text DEFAULT emt_sanitize_name('default_partition')
2245
+ ) RETURNS TABLE (
1743
2246
  success boolean,
1744
2247
  next_stream_position bigint,
1745
2248
  global_positions bigint[],
@@ -1838,7 +2341,7 @@ var appendToStream = (pool, streamName, streamType, messages, options) => pool.w
1838
2341
  return { success: false, result: { success: false } };
1839
2342
  try {
1840
2343
  const expectedStreamVersion = toExpectedVersion(
1841
- _optionalChain([options, 'optionalAccess', _48 => _48.expectedStreamVersion])
2344
+ _optionalChain([options, 'optionalAccess', _67 => _67.expectedStreamVersion])
1842
2345
  );
1843
2346
  const messagesToAppend = messages.map((e) => ({
1844
2347
  ...e,
@@ -1878,7 +2381,7 @@ var appendToStream = (pool, streamName, streamType, messages, options) => pool.w
1878
2381
  globalPosition
1879
2382
  };
1880
2383
  });
1881
- if (_optionalChain([options, 'optionalAccess', _49 => _49.beforeCommitHook]))
2384
+ if (_optionalChain([options, 'optionalAccess', _68 => _68.beforeCommitHook]))
1882
2385
  await options.beforeCommitHook(messagesToAppend, { transaction });
1883
2386
  return {
1884
2387
  success: true,
@@ -1921,8 +2424,8 @@ var appendEventsRaw = (execute, streamId, streamType, messages, options) => _dum
1921
2424
  messageKinds: messages.map((e) => e.kind === "Event" ? "E" : "C"),
1922
2425
  streamId,
1923
2426
  streamType,
1924
- expectedStreamPosition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _50 => _50.expectedStreamVersion]), () => ( null)),
1925
- partition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _51 => _51.partition]), () => ( defaultTag2))
2427
+ expectedStreamPosition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _69 => _69.expectedStreamVersion]), () => ( null)),
2428
+ partition: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _70 => _70.partition]), () => ( defaultTag2))
1926
2429
  })
1927
2430
  )
1928
2431
  );
@@ -3984,7 +4487,7 @@ var readProcessorCheckpoint = async (execute, options) => {
3984
4487
  execute.query(
3985
4488
  _dumbo.SQL`SELECT last_processed_checkpoint
3986
4489
  FROM ${_dumbo.SQL.identifier(processorsTable.name)}
3987
- WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _52 => _52.partition]), () => ( defaultTag2))} AND processor_id = ${options.processorId} AND version = ${_nullishCoalesce(options.version, () => ( 1))}
4490
+ WHERE partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.partition]), () => ( defaultTag2))} AND processor_id = ${options.processorId} AND version = ${_nullishCoalesce(options.version, () => ( 1))}
3988
4491
  LIMIT 1`
3989
4492
  )
3990
4493
  );
@@ -3996,16 +4499,16 @@ var readProcessorCheckpoint = async (execute, options) => {
3996
4499
  // src/eventStore/schema/readStream.ts
3997
4500
 
3998
4501
  var readStream = async (execute, streamId, options) => {
3999
- const fromCondition = _optionalChain([options, 'optionalAccess', _53 => _53.from]) ? `AND stream_position >= ${options.from}` : "";
4502
+ const fromCondition = _optionalChain([options, 'optionalAccess', _72 => _72.from]) ? `AND stream_position >= ${options.from}` : "";
4000
4503
  const to = Number(
4001
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _54 => _54.to]), () => ( (_optionalChain([options, 'optionalAccess', _55 => _55.maxCount]) ? (_nullishCoalesce(options.from, () => ( 0n))) + options.maxCount : NaN)))
4504
+ _nullishCoalesce(_optionalChain([options, 'optionalAccess', _73 => _73.to]), () => ( (_optionalChain([options, 'optionalAccess', _74 => _74.maxCount]) ? (_nullishCoalesce(options.from, () => ( 0n))) + options.maxCount : NaN)))
4002
4505
  );
4003
4506
  const toCondition = !isNaN(to) ? `AND stream_position <= ${to}` : "";
4004
4507
  const events = await _dumbo.mapRows.call(void 0,
4005
4508
  execute.query(
4006
4509
  _dumbo.SQL`SELECT stream_id, stream_position, global_position, message_data, message_metadata, message_schema_version, message_type, message_id
4007
4510
  FROM ${_dumbo.SQL.identifier(messagesTable.name)}
4008
- WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _56 => _56.partition]), () => ( defaultTag2))} AND is_archived = FALSE ${_dumbo.SQL.plain(fromCondition)} ${_dumbo.SQL.plain(toCondition)}
4511
+ WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _75 => _75.partition]), () => ( defaultTag2))} AND is_archived = FALSE ${_dumbo.SQL.plain(fromCondition)} ${_dumbo.SQL.plain(toCondition)}
4009
4512
  ORDER BY stream_position ASC`
4010
4513
  ),
4011
4514
  (row) => {
@@ -4027,7 +4530,7 @@ var readStream = async (execute, streamId, options) => {
4027
4530
  kind: "Event",
4028
4531
  metadata
4029
4532
  };
4030
- return upcastRecordedMessage(event, _optionalChain([options, 'optionalAccess', _57 => _57.schema, 'optionalAccess', _58 => _58.versioning]));
4533
+ return upcastRecordedMessage(event, _optionalChain([options, 'optionalAccess', _76 => _76.schema, 'optionalAccess', _77 => _77.versioning]));
4031
4534
  }
4032
4535
  );
4033
4536
  return events.length > 0 ? {
@@ -4048,10 +4551,10 @@ var streamExists = async (execute, streamId, options) => {
4048
4551
  _dumbo.SQL`SELECT EXISTS (
4049
4552
  SELECT 1
4050
4553
  from ${_dumbo.SQL.identifier(streamsTable.name)}
4051
- WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _59 => _59.partition]), () => ( defaultTag2))} AND is_archived = FALSE)
4554
+ WHERE stream_id = ${streamId} AND partition = ${_nullishCoalesce(_optionalChain([options, 'optionalAccess', _78 => _78.partition]), () => ( defaultTag2))} AND is_archived = FALSE)
4052
4555
  `
4053
4556
  );
4054
- return _nullishCoalesce(_optionalChain([queryResult, 'access', _60 => _60.rows, 'access', _61 => _61[0], 'optionalAccess', _62 => _62.exists]), () => ( false));
4557
+ return _nullishCoalesce(_optionalChain([queryResult, 'access', _79 => _79.rows, 'access', _80 => _80[0], 'optionalAccess', _81 => _81.exists]), () => ( false));
4055
4558
  };
4056
4559
 
4057
4560
  // src/eventStore/schema/index.ts
@@ -4091,7 +4594,7 @@ var createEventStoreSchema = (connectionString, pool, hooks, options) => {
4091
4594
  );
4092
4595
  const nestedPool = _dumbo.dumbo.call(void 0, { connectionString, connection: tx.connection });
4093
4596
  try {
4094
- if (_optionalChain([hooks, 'optionalAccess', _63 => _63.onBeforeSchemaCreated])) {
4597
+ if (_optionalChain([hooks, 'optionalAccess', _82 => _82.onBeforeSchemaCreated])) {
4095
4598
  await hooks.onBeforeSchemaCreated(context);
4096
4599
  }
4097
4600
  const result = await _dumbo.runSQLMigrations.call(void 0,
@@ -4099,7 +4602,7 @@ var createEventStoreSchema = (connectionString, pool, hooks, options) => {
4099
4602
  eventStoreSchemaMigrations,
4100
4603
  options
4101
4604
  );
4102
- if (_optionalChain([hooks, 'optionalAccess', _64 => _64.onAfterSchemaCreated])) {
4605
+ if (_optionalChain([hooks, 'optionalAccess', _83 => _83.onAfterSchemaCreated])) {
4103
4606
  await hooks.onAfterSchemaCreated(context);
4104
4607
  }
4105
4608
  return result;
@@ -4118,7 +4621,7 @@ var truncateTables = async (execute, options) => {
4118
4621
  ${_dumbo.SQL.identifier(messagesTable.name)},
4119
4622
  ${_dumbo.SQL.identifier(processorsTable.name)},
4120
4623
  ${_dumbo.SQL.identifier(projectionsTable.name)}
4121
- CASCADE${_dumbo.SQL.plain(_optionalChain([options, 'optionalAccess', _65 => _65.resetSequences]) ? "; ALTER SEQUENCE emt_global_message_position RESTART WITH 1" : "")};`
4624
+ CASCADE${_dumbo.SQL.plain(_optionalChain([options, 'optionalAccess', _84 => _84.resetSequences]) ? "; ALTER SEQUENCE emt_global_message_position RESTART WITH 1" : "")};`
4122
4625
  );
4123
4626
  };
4124
4627
 
@@ -4135,7 +4638,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4135
4638
  };
4136
4639
  const pool = "dumbo" in poolOptions ? poolOptions.dumbo : _dumbo.dumbo.call(void 0, poolOptions);
4137
4640
  let migrateSchema = void 0;
4138
- const autoGenerateSchema = _optionalChain([options, 'access', _66 => _66.schema, 'optionalAccess', _67 => _67.autoMigration]) === void 0 || _optionalChain([options, 'access', _68 => _68.schema, 'optionalAccess', _69 => _69.autoMigration]) !== "None";
4641
+ const autoGenerateSchema = _optionalChain([options, 'access', _85 => _85.schema, 'optionalAccess', _86 => _86.autoMigration]) === void 0 || _optionalChain([options, 'access', _87 => _87.schema, 'optionalAccess', _88 => _88.autoMigration]) !== "None";
4139
4642
  const inlineProjections = (_nullishCoalesce(options.projections, () => ( []))).filter(({ type }) => type === "inline").map(({ projection: projection2 }) => projection2);
4140
4643
  const migrate = async (migrationOptions) => {
4141
4644
  if (!migrateSchema) {
@@ -4144,7 +4647,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4144
4647
  pool,
4145
4648
  {
4146
4649
  onBeforeSchemaCreated: async (context) => {
4147
- if (_optionalChain([options, 'access', _70 => _70.hooks, 'optionalAccess', _71 => _71.onBeforeSchemaCreated])) {
4650
+ if (_optionalChain([options, 'access', _89 => _89.hooks, 'optionalAccess', _90 => _90.onBeforeSchemaCreated])) {
4148
4651
  await options.hooks.onBeforeSchemaCreated(context);
4149
4652
  }
4150
4653
  },
@@ -4159,7 +4662,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4159
4662
  });
4160
4663
  }
4161
4664
  }
4162
- if (_optionalChain([options, 'access', _72 => _72.hooks, 'optionalAccess', _73 => _73.onAfterSchemaCreated])) {
4665
+ if (_optionalChain([options, 'access', _91 => _91.hooks, 'optionalAccess', _92 => _92.onAfterSchemaCreated])) {
4163
4666
  await options.hooks.onAfterSchemaCreated(context);
4164
4667
  }
4165
4668
  }
@@ -4201,13 +4704,13 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4201
4704
  truncate: (truncateOptions) => pool.withTransaction(async (transaction) => {
4202
4705
  await ensureSchemaExists();
4203
4706
  await truncateTables(transaction.execute, truncateOptions);
4204
- if (_optionalChain([truncateOptions, 'optionalAccess', _74 => _74.truncateProjections])) {
4707
+ if (_optionalChain([truncateOptions, 'optionalAccess', _93 => _93.truncateProjections])) {
4205
4708
  const projectionContext = await transactionToPostgreSQLProjectionHandlerContext(
4206
4709
  connectionString,
4207
4710
  pool,
4208
4711
  transaction
4209
4712
  );
4210
- for (const projection2 of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _75 => _75.projections]), () => ( []))) {
4713
+ for (const projection2 of _nullishCoalesce(_optionalChain([options, 'optionalAccess', _94 => _94.projections]), () => ( []))) {
4211
4714
  if (projection2.projection.truncate)
4212
4715
  await projection2.projection.truncate(projectionContext);
4213
4716
  }
@@ -4217,7 +4720,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4217
4720
  },
4218
4721
  async aggregateStream(streamName, options2) {
4219
4722
  const { evolve, initialState, read } = options2;
4220
- const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _76 => _76.expectedStreamVersion]);
4723
+ const expectedStreamVersion = _optionalChain([read, 'optionalAccess', _95 => _95.expectedStreamVersion]);
4221
4724
  let state = initialState();
4222
4725
  const result = await this.readStream(
4223
4726
  streamName,
@@ -4256,7 +4759,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4256
4759
  pool,
4257
4760
  streamName,
4258
4761
  streamType,
4259
- downcastRecordedMessages(events, _optionalChain([options2, 'optionalAccess', _77 => _77.schema, 'optionalAccess', _78 => _78.versioning])),
4762
+ downcastRecordedMessages(events, _optionalChain([options2, 'optionalAccess', _96 => _96.schema, 'optionalAccess', _97 => _97.versioning])),
4260
4763
  {
4261
4764
  ...options2,
4262
4765
  beforeCommitHook
@@ -4266,7 +4769,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4266
4769
  throw new ExpectedVersionConflictError(
4267
4770
  -1n,
4268
4771
  //TODO: Return actual version in case of error
4269
- _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _79 => _79.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
4772
+ _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _98 => _98.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))
4270
4773
  );
4271
4774
  return {
4272
4775
  nextExpectedStreamVersion: appendResult.nextStreamPosition,
@@ -4311,259 +4814,11 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
4311
4814
  };
4312
4815
  };
4313
4816
 
4314
- // src/eventStore/projections/postgresProjectionSpec.ts
4315
- var PostgreSQLProjectionSpec = {
4316
- for: (options) => {
4317
- {
4318
- const { projection: projection2, ...dumoOptions } = options;
4319
- const { connectionString } = dumoOptions;
4320
- let wasInitialised = false;
4321
- const initialize = async (pool) => {
4322
- const eventStore = getPostgreSQLEventStore(connectionString, {
4323
- // TODO: This will need to change when we support other drivers
4324
- connectionOptions: { dumbo: pool }
4325
- });
4326
- if (wasInitialised) return;
4327
- wasInitialised = true;
4328
- await eventStore.schema.migrate();
4329
- if (projection2.init)
4330
- await pool.withTransaction(async (transaction) => {
4331
- await projection2.init({
4332
- registrationType: "async",
4333
- version: _nullishCoalesce(projection2.version, () => ( 1)),
4334
- status: "active",
4335
- context: await transactionToPostgreSQLProjectionHandlerContext(
4336
- connectionString,
4337
- pool,
4338
- transaction
4339
- )
4340
- });
4341
- });
4342
- };
4343
- return (givenEvents) => {
4344
- return {
4345
- when: (events, options2) => {
4346
- const allEvents = [];
4347
- const run = async (pool) => {
4348
- let globalPosition = 0n;
4349
- const numberOfTimes = _nullishCoalesce(_optionalChain([options2, 'optionalAccess', _80 => _80.numberOfTimes]), () => ( 1));
4350
- for (const event of [
4351
- ...givenEvents,
4352
- ...Array.from({ length: numberOfTimes }).flatMap(() => events)
4353
- ]) {
4354
- const metadata = {
4355
- checkpoint: bigIntProcessorCheckpoint(++globalPosition),
4356
- globalPosition,
4357
- streamPosition: globalPosition,
4358
- streamName: `test-${_uuid.v4.call(void 0, )}`,
4359
- messageId: _uuid.v4.call(void 0, )
4360
- };
4361
- allEvents.push({
4362
- ...event,
4363
- kind: "Event",
4364
- metadata: {
4365
- ...metadata,
4366
- ..."metadata" in event ? _nullishCoalesce(event.metadata, () => ( {})) : {}
4367
- }
4368
- });
4369
- }
4370
- await initialize(pool);
4371
- await pool.withTransaction(async (transaction) => {
4372
- await handleProjections({
4373
- events: allEvents,
4374
- projections: [projection2],
4375
- ...await transactionToPostgreSQLProjectionHandlerContext(
4376
- connectionString,
4377
- pool,
4378
- transaction
4379
- )
4380
- });
4381
- });
4382
- };
4383
- return {
4384
- then: async (assert, message) => {
4385
- const pool = _dumbo.dumbo.call(void 0, dumoOptions);
4386
- try {
4387
- await run(pool);
4388
- const succeeded = await assert({ pool, connectionString });
4389
- if (succeeded !== void 0 && succeeded === false)
4390
- assertFails(
4391
- _nullishCoalesce(message, () => ( "Projection specification didn't match the criteria"))
4392
- );
4393
- } finally {
4394
- await pool.close();
4395
- }
4396
- },
4397
- thenThrows: async (...args) => {
4398
- const pool = _dumbo.dumbo.call(void 0, dumoOptions);
4399
- try {
4400
- await run(pool);
4401
- throw new AssertionError("Handler did not fail as expected");
4402
- } catch (error) {
4403
- if (error instanceof AssertionError) throw error;
4404
- if (args.length === 0) return;
4405
- if (!isErrorConstructor(args[0])) {
4406
- assertTrue(
4407
- args[0](error),
4408
- `Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _81 => _81.toString, 'call', _82 => _82()])}`
4409
- );
4410
- return;
4411
- }
4412
- assertTrue(
4413
- error instanceof args[0],
4414
- `Caught error is not an instance of the expected type: ${_optionalChain([error, 'optionalAccess', _83 => _83.toString, 'call', _84 => _84()])}`
4415
- );
4416
- if (args[1]) {
4417
- assertTrue(
4418
- args[1](error),
4419
- `Error didn't match the error condition: ${_optionalChain([error, 'optionalAccess', _85 => _85.toString, 'call', _86 => _86()])}`
4420
- );
4421
- }
4422
- } finally {
4423
- await pool.close();
4424
- }
4425
- }
4426
- };
4427
- }
4428
- };
4429
- };
4430
- }
4431
- }
4432
- };
4433
- var eventInStream = (streamName, event) => {
4434
- return {
4435
- ...event,
4436
- metadata: {
4437
- ..._nullishCoalesce(event.metadata, () => ( {})),
4438
- streamName: _nullishCoalesce(_optionalChain([event, 'access', _87 => _87.metadata, 'optionalAccess', _88 => _88.streamName]), () => ( streamName))
4439
- }
4440
- };
4441
- };
4442
- var eventsInStream = (streamName, events) => {
4443
- return events.map((e) => eventInStream(streamName, e));
4444
- };
4445
- var newEventsInStream = eventsInStream;
4446
- var assertSQLQueryResultMatches = (sql, rows) => async ({ pool: { execute } }) => {
4447
- const result = await execute.query(sql);
4448
- assertThatArray(rows).containsExactlyInAnyOrder(result.rows);
4449
- };
4450
- var expectSQL = {
4451
- query: (sql) => ({
4452
- resultRows: {
4453
- toBeTheSame: (rows) => assertSQLQueryResultMatches(sql, rows)
4454
- }
4455
- })
4456
- };
4457
-
4458
- // src/eventStore/projections/postgreSQLProjection.ts
4459
- var transactionToPostgreSQLProjectionHandlerContext = async (connectionString, pool, transaction) => ({
4460
- execute: transaction.execute,
4461
- connection: {
4462
- connectionString,
4463
- client: await transaction.connection.open(),
4464
- transaction,
4465
- pool
4466
- }
4467
- });
4468
- var handleProjections = async (options) => {
4469
- const {
4470
- projections: allProjections,
4471
- events,
4472
- connection: { pool, transaction, connectionString },
4473
- partition = defaultTag2
4474
- } = options;
4475
- const eventTypes = events.map((e) => e.type);
4476
- const projections = allProjections.filter(
4477
- (p) => p.canHandle.some((type) => eventTypes.includes(type))
4478
- );
4479
- const client = await transaction.connection.open();
4480
- for (const projection2 of projections) {
4481
- if (projection2.name) {
4482
- const lockAcquired = await postgreSQLProjectionLock({
4483
- projectionName: projection2.name,
4484
- partition,
4485
- version: _nullishCoalesce(projection2.version, () => ( 1))
4486
- }).tryAcquire({ execute: transaction.execute });
4487
- if (!lockAcquired) {
4488
- continue;
4489
- }
4490
- }
4491
- await projection2.handle(events, {
4492
- connection: {
4493
- connectionString,
4494
- pool,
4495
- client,
4496
- transaction
4497
- },
4498
- execute: transaction.execute
4499
- });
4500
- }
4501
- };
4502
- var postgreSQLProjection = (definition) => projection({
4503
- ...definition,
4504
- init: async (options) => {
4505
- await registerProjection(options.context.execute, {
4506
- // TODO: pass partition from options
4507
- partition: defaultTag2,
4508
- status: "active",
4509
- registration: {
4510
- type: "async",
4511
- // TODO: fix this
4512
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
4513
- projection: definition
4514
- }
4515
- });
4516
- if (definition.init) {
4517
- await definition.init(options);
4518
- }
4519
- }
4520
- });
4521
- var postgreSQLRawBatchSQLProjection = (options) => postgreSQLProjection({
4522
- name: options.name,
4523
- kind: _nullishCoalesce(options.kind, () => ( "emt:projections:postgresql:raw_sql:batch")),
4524
- version: options.version,
4525
- canHandle: options.canHandle,
4526
- eventsOptions: options.eventsOptions,
4527
- handle: async (events, context) => {
4528
- const sqls = await options.evolve(events, context);
4529
- await context.execute.batchCommand(sqls);
4530
- },
4531
- init: async (initOptions) => {
4532
- const initSQL = options.init ? await options.init(initOptions) : void 0;
4533
- if (initSQL) {
4534
- if (Array.isArray(initSQL)) {
4535
- await initOptions.context.execute.batchCommand(initSQL);
4536
- } else {
4537
- await initOptions.context.execute.command(initSQL);
4538
- }
4539
- }
4540
- }
4541
- });
4542
- var postgreSQLRawSQLProjection = (options) => {
4543
- const { evolve, kind, ...rest } = options;
4544
- return postgreSQLRawBatchSQLProjection({
4545
- kind: _nullishCoalesce(kind, () => ( "emt:projections:postgresql:raw:_sql:single")),
4546
- ...rest,
4547
- evolve: async (events, context) => {
4548
- const sqls = [];
4549
- for (const event of events) {
4550
- const pendingSqls = await evolve(event, context);
4551
- if (Array.isArray(pendingSqls)) {
4552
- sqls.push(...pendingSqls);
4553
- } else {
4554
- sqls.push(pendingSqls);
4555
- }
4556
- }
4557
- return sqls;
4558
- }
4559
- });
4560
- };
4561
-
4562
4817
  // src/eventStore/consumers/postgreSQLProcessor.ts
4563
4818
  var postgreSQLCheckpointer = () => ({
4564
4819
  read: async (options, context) => {
4565
4820
  const result = await readProcessorCheckpoint(context.execute, options);
4566
- return { lastCheckpoint: _optionalChain([result, 'optionalAccess', _89 => _89.lastProcessedCheckpoint]) };
4821
+ return { lastCheckpoint: _optionalChain([result, 'optionalAccess', _99 => _99.lastProcessedCheckpoint]) };
4567
4822
  },
4568
4823
  store: async (options, context) => {
4569
4824
  const newCheckpoint = getCheckpoint(options.message);
@@ -4581,13 +4836,13 @@ var postgreSQLProcessingScope = (options) => {
4581
4836
  const processorConnectionString = options.connectionString;
4582
4837
  const processorPool = options.pool;
4583
4838
  const processingScope = async (handler, partialContext) => {
4584
- const connection = _optionalChain([partialContext, 'optionalAccess', _90 => _90.connection]);
4585
- const connectionString = _nullishCoalesce(processorConnectionString, () => ( _optionalChain([connection, 'optionalAccess', _91 => _91.connectionString])));
4839
+ const connection = _optionalChain([partialContext, 'optionalAccess', _100 => _100.connection]);
4840
+ const connectionString = _nullishCoalesce(processorConnectionString, () => ( _optionalChain([connection, 'optionalAccess', _101 => _101.connectionString])));
4586
4841
  if (!connectionString)
4587
4842
  throw new EmmettError(
4588
4843
  `PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
4589
4844
  );
4590
- const pool = _nullishCoalesce((!processorConnectionString || connectionString == processorConnectionString ? _optionalChain([connection, 'optionalAccess', _92 => _92.pool]) : processorPool), () => ( processorPool));
4845
+ const pool = _nullishCoalesce((!processorConnectionString || connectionString == processorConnectionString ? _optionalChain([connection, 'optionalAccess', _102 => _102.pool]) : processorPool), () => ( processorPool));
4591
4846
  if (!pool)
4592
4847
  throw new EmmettError(
4593
4848
  `PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
@@ -4602,7 +4857,10 @@ var postgreSQLProcessingScope = (options) => {
4602
4857
  connectionString,
4603
4858
  pool,
4604
4859
  client,
4605
- transaction
4860
+ transaction,
4861
+ messageStore: getPostgreSQLEventStore(connectionString, {
4862
+ connectionOptions: { client }
4863
+ })
4606
4864
  }
4607
4865
  });
4608
4866
  });
@@ -4628,11 +4886,11 @@ var wrapHooksWithProcessorLocks = (hooks, processorLock) => ({
4628
4886
  ..._nullishCoalesce(hooks, () => ( {})),
4629
4887
  onStart: async (context) => {
4630
4888
  await processorLock.tryAcquire({ execute: context.execute });
4631
- if (_optionalChain([hooks, 'optionalAccess', _93 => _93.onStart])) await hooks.onStart(context);
4889
+ if (_optionalChain([hooks, 'optionalAccess', _103 => _103.onStart])) await hooks.onStart(context);
4632
4890
  },
4633
- onClose: _optionalChain([hooks, 'optionalAccess', _94 => _94.onClose]) || processorLock ? async (context) => {
4891
+ onClose: _optionalChain([hooks, 'optionalAccess', _104 => _104.onClose]) || processorLock ? async (context) => {
4634
4892
  await processorLock.release({ execute: context.execute });
4635
- if (_optionalChain([hooks, 'optionalAccess', _95 => _95.onClose])) await hooks.onClose(context);
4893
+ if (_optionalChain([hooks, 'optionalAccess', _105 => _105.onClose])) await hooks.onClose(context);
4636
4894
  } : void 0
4637
4895
  });
4638
4896
  var postgreSQLProjector = (options) => {
@@ -4657,13 +4915,13 @@ var postgreSQLProjector = (options) => {
4657
4915
  version: _nullishCoalesce(options.projection.version, () => ( version)),
4658
4916
  handlingType: "async"
4659
4917
  } : void 0,
4660
- lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess', _96 => _96.acquisitionPolicy]), () => ( DefaultPostgreSQLProcessorLockPolicy)),
4661
- lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess', _97 => _97.timeoutSeconds])
4918
+ lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess', _106 => _106.acquisitionPolicy]), () => ( DefaultPostgreSQLProcessorLockPolicy)),
4919
+ lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess', _107 => _107.timeoutSeconds])
4662
4920
  });
4663
4921
  const hooks = wrapHooksWithProcessorLocks(
4664
4922
  {
4665
4923
  ..._nullishCoalesce(options.hooks, () => ( {})),
4666
- onInit: options.projection.init !== void 0 || _optionalChain([options, 'access', _98 => _98.hooks, 'optionalAccess', _99 => _99.onInit]) ? async (context) => {
4924
+ onInit: options.projection.init !== void 0 || _optionalChain([options, 'access', _108 => _108.hooks, 'optionalAccess', _109 => _109.onInit]) ? async (context) => {
4667
4925
  if (options.projection.init)
4668
4926
  await options.projection.init({
4669
4927
  version: _nullishCoalesce(options.projection.version, () => ( version)),
@@ -4674,16 +4932,16 @@ var postgreSQLProjector = (options) => {
4674
4932
  migrationOptions: options.migrationOptions
4675
4933
  }
4676
4934
  });
4677
- if (_optionalChain([options, 'access', _100 => _100.hooks, 'optionalAccess', _101 => _101.onInit]))
4935
+ if (_optionalChain([options, 'access', _110 => _110.hooks, 'optionalAccess', _111 => _111.onInit]))
4678
4936
  await options.hooks.onInit({
4679
4937
  ...context,
4680
4938
  migrationOptions: options.migrationOptions
4681
4939
  });
4682
- } : _optionalChain([options, 'access', _102 => _102.hooks, 'optionalAccess', _103 => _103.onInit]),
4940
+ } : _optionalChain([options, 'access', _112 => _112.hooks, 'optionalAccess', _113 => _113.onInit]),
4683
4941
  onClose: close ? async (context) => {
4684
- if (_optionalChain([options, 'access', _104 => _104.hooks, 'optionalAccess', _105 => _105.onClose])) await _optionalChain([options, 'access', _106 => _106.hooks, 'optionalAccess', _107 => _107.onClose, 'call', _108 => _108(context)]);
4942
+ if (_optionalChain([options, 'access', _114 => _114.hooks, 'optionalAccess', _115 => _115.onClose])) await _optionalChain([options, 'access', _116 => _116.hooks, 'optionalAccess', _117 => _117.onClose, 'call', _118 => _118(context)]);
4685
4943
  if (close) await close();
4686
- } : _optionalChain([options, 'access', _109 => _109.hooks, 'optionalAccess', _110 => _110.onClose])
4944
+ } : _optionalChain([options, 'access', _119 => _119.hooks, 'optionalAccess', _120 => _120.onClose])
4687
4945
  },
4688
4946
  processorLock
4689
4947
  );
@@ -4704,6 +4962,53 @@ var postgreSQLProjector = (options) => {
4704
4962
  });
4705
4963
  return processor;
4706
4964
  };
4965
+ var postgreSQLWorkflowProcessor = (options) => {
4966
+ const {
4967
+ processorId = _nullishCoalesce(options.processorId, () => ( getWorkflowId({
4968
+ workflowName: _nullishCoalesce(options.workflow.name, () => ( "unknown"))
4969
+ }))),
4970
+ processorInstanceId = getProcessorInstanceId(processorId),
4971
+ version = defaultProcessorVersion,
4972
+ partition = defaultProcessorPartition,
4973
+ lock
4974
+ } = options;
4975
+ const { pool, connectionString, close } = getProcessorPool(options);
4976
+ const processorLock = postgreSQLProcessorLock({
4977
+ processorId,
4978
+ version,
4979
+ partition,
4980
+ processorInstanceId,
4981
+ projection: void 0,
4982
+ lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess', _121 => _121.acquisitionPolicy]), () => ( DefaultPostgreSQLProcessorLockPolicy)),
4983
+ lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess', _122 => _122.timeoutSeconds])
4984
+ });
4985
+ const hooks = wrapHooksWithProcessorLocks(
4986
+ {
4987
+ ..._nullishCoalesce(options.hooks, () => ( {})),
4988
+ onClose: close ? async (context) => {
4989
+ if (_optionalChain([options, 'access', _123 => _123.hooks, 'optionalAccess', _124 => _124.onClose]))
4990
+ await _optionalChain([options, 'access', _125 => _125.hooks, 'optionalAccess', _126 => _126.onClose, 'call', _127 => _127(context)]);
4991
+ if (close) await close();
4992
+ } : _optionalChain([options, 'access', _128 => _128.hooks, 'optionalAccess', _129 => _129.onClose])
4993
+ },
4994
+ processorLock
4995
+ );
4996
+ return workflowProcessor({
4997
+ ...options,
4998
+ processorId,
4999
+ processorInstanceId,
5000
+ version,
5001
+ partition,
5002
+ hooks,
5003
+ processingScope: postgreSQLProcessingScope({
5004
+ pool,
5005
+ connectionString,
5006
+ processorId,
5007
+ partition
5008
+ }),
5009
+ checkpoints: postgreSQLCheckpointer()
5010
+ });
5011
+ };
4707
5012
  var postgreSQLReactor = (options) => {
4708
5013
  const {
4709
5014
  processorId = options.processorId,
@@ -4719,16 +5024,16 @@ var postgreSQLReactor = (options) => {
4719
5024
  partition,
4720
5025
  processorInstanceId,
4721
5026
  projection: void 0,
4722
- lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess', _111 => _111.acquisitionPolicy]), () => ( DefaultPostgreSQLProcessorLockPolicy)),
4723
- lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess', _112 => _112.timeoutSeconds])
5027
+ lockAcquisitionPolicy: _nullishCoalesce(_optionalChain([lock, 'optionalAccess', _130 => _130.acquisitionPolicy]), () => ( DefaultPostgreSQLProcessorLockPolicy)),
5028
+ lockTimeoutSeconds: _optionalChain([lock, 'optionalAccess', _131 => _131.timeoutSeconds])
4724
5029
  });
4725
5030
  const hooks = wrapHooksWithProcessorLocks(
4726
5031
  {
4727
5032
  ..._nullishCoalesce(options.hooks, () => ( {})),
4728
5033
  onClose: close ? async (context) => {
4729
- if (_optionalChain([options, 'access', _113 => _113.hooks, 'optionalAccess', _114 => _114.onClose])) await _optionalChain([options, 'access', _115 => _115.hooks, 'optionalAccess', _116 => _116.onClose, 'call', _117 => _117(context)]);
5034
+ if (_optionalChain([options, 'access', _132 => _132.hooks, 'optionalAccess', _133 => _133.onClose])) await _optionalChain([options, 'access', _134 => _134.hooks, 'optionalAccess', _135 => _135.onClose, 'call', _136 => _136(context)]);
4730
5035
  if (close) await close();
4731
- } : _optionalChain([options, 'access', _118 => _118.hooks, 'optionalAccess', _119 => _119.onClose])
5036
+ } : _optionalChain([options, 'access', _137 => _137.hooks, 'optionalAccess', _138 => _138.onClose])
4732
5037
  },
4733
5038
  processorLock
4734
5039
  );
@@ -4777,7 +5082,7 @@ var postgreSQLEventStoreConsumer = (options) => {
4777
5082
  })
4778
5083
  );
4779
5084
  return result.some(
4780
- (r) => r.status === "fulfilled" && _optionalChain([r, 'access', _120 => _120.value, 'optionalAccess', _121 => _121.type]) !== "STOP"
5085
+ (r) => r.status === "fulfilled" && _optionalChain([r, 'access', _139 => _139.value, 'optionalAccess', _140 => _140.type]) !== "STOP"
4781
5086
  ) ? void 0 : {
4782
5087
  type: "STOP"
4783
5088
  };
@@ -4788,7 +5093,8 @@ var postgreSQLEventStoreConsumer = (options) => {
4788
5093
  connectionString: options.connectionString,
4789
5094
  pool,
4790
5095
  client: void 0,
4791
- transaction: void 0
5096
+ transaction: void 0,
5097
+ messageStore: void 0
4792
5098
  }
4793
5099
  };
4794
5100
  const stopProcessors = () => Promise.all(processors.map((p) => p.close(processorContext)));
@@ -4796,7 +5102,7 @@ var postgreSQLEventStoreConsumer = (options) => {
4796
5102
  if (!isRunning) return;
4797
5103
  isRunning = false;
4798
5104
  if (messagePuller) {
4799
- _optionalChain([abortController, 'optionalAccess', _122 => _122.abort, 'call', _123 => _123()]);
5105
+ _optionalChain([abortController, 'optionalAccess', _141 => _141.abort, 'call', _142 => _142()]);
4800
5106
  await messagePuller.stop();
4801
5107
  messagePuller = void 0;
4802
5108
  abortController = null;
@@ -4837,6 +5143,14 @@ var postgreSQLEventStoreConsumer = (options) => {
4837
5143
  );
4838
5144
  return processor;
4839
5145
  },
5146
+ workflowProcessor: (options2) => {
5147
+ const processor = postgreSQLWorkflowProcessor(options2);
5148
+ processors.push(
5149
+ // TODO: change that
5150
+ processor
5151
+ );
5152
+ return processor;
5153
+ },
4840
5154
  start: () => {
4841
5155
  if (isRunning) return start;
4842
5156
  if (processors.length === 0)
@@ -4849,8 +5163,8 @@ var postgreSQLEventStoreConsumer = (options) => {
4849
5163
  stopWhen: options.stopWhen,
4850
5164
  executor: pool.execute,
4851
5165
  eachBatch,
4852
- batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _124 => _124.batchSize]), () => ( DefaultPostgreSQLEventStoreProcessorBatchSize)),
4853
- pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _125 => _125.pullingFrequencyInMs]), () => ( DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs)),
5166
+ batchSize: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _143 => _143.batchSize]), () => ( DefaultPostgreSQLEventStoreProcessorBatchSize)),
5167
+ pullingFrequencyInMs: _nullishCoalesce(_optionalChain([pulling, 'optionalAccess', _144 => _144.pullingFrequencyInMs]), () => ( DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs)),
4854
5168
  signal: abortController.signal
4855
5169
  });
4856
5170
  start = (async () => {
@@ -5014,5 +5328,6 @@ var rebuildPostgreSQLProjections = (options) => {
5014
5328
 
5015
5329
 
5016
5330
 
5017
- exports.DefaultPostgreSQLEventStoreProcessorBatchSize = DefaultPostgreSQLEventStoreProcessorBatchSize; exports.DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs = DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs; exports.DefaultPostgreSQLProcessorLockPolicy = DefaultPostgreSQLProcessorLockPolicy; exports.PostgreSQLEventStoreDefaultStreamVersion = PostgreSQLEventStoreDefaultStreamVersion; exports.PostgreSQLProjectionSpec = PostgreSQLProjectionSpec; exports.activateProjection = activateProjection; exports.activateProjectionSQL = activateProjectionSQL; exports.addDefaultPartitionSQL = addDefaultPartitionSQL; exports.addModuleForAllTenantsSQL = addModuleForAllTenantsSQL; exports.addModuleSQL = addModuleSQL; exports.addPartitionSQL = addPartitionSQL; exports.addTablePartitions = addTablePartitions; exports.addTenantForAllModulesSQL = addTenantForAllModulesSQL; exports.addTenantSQL = addTenantSQL; exports.appendToStream = appendToStream; exports.appendToStreamSQL = appendToStreamSQL; exports.assertSQLQueryResultMatches = assertSQLQueryResultMatches; exports.callActivateProjection = callActivateProjection; exports.callAppendToStream = callAppendToStream; exports.callDeactivateProjection = callDeactivateProjection; exports.callRegisterProjection = callRegisterProjection; exports.callReleaseProcessorLock = callReleaseProcessorLock; exports.callStoreProcessorCheckpoint = callStoreProcessorCheckpoint; exports.callTryAcquireProcessorLock = callTryAcquireProcessorLock; exports.callTryAcquireProjectionLock = callTryAcquireProjectionLock; exports.cleanupLegacySubscriptionTables = cleanupLegacySubscriptionTables; exports.createEventStoreSchema = createEventStoreSchema; exports.deactivateProjection = deactivateProjection; exports.deactivateProjectionSQL = deactivateProjectionSQL; exports.defaultPostgreSQLOptions = defaultPostgreSQLOptions; exports.defaultTag = defaultTag2; exports.documentDoesNotExist = documentDoesNotExist; exports.documentExists = documentExists; exports.documentMatchingExists = documentMatchingExists; exports.documentsAreTheSame = documentsAreTheSame; exports.documentsMatchingHaveCount = documentsMatchingHaveCount; exports.emmettPrefix = emmettPrefix2; exports.eventInStream = eventInStream; exports.eventStoreSchemaMigrations = eventStoreSchemaMigrations; exports.eventsInStream = eventsInStream; exports.expectPongoDocuments = expectPongoDocuments; exports.expectSQL = expectSQL; exports.getPostgreSQLEventStore = getPostgreSQLEventStore; exports.globalNames = globalNames; exports.globalTag = globalTag; exports.handleProjections = handleProjections; exports.messagesTable = messagesTable; exports.messagesTableSQL = messagesTableSQL; exports.newEventsInStream = newEventsInStream; exports.pongoMultiStreamProjection = pongoMultiStreamProjection; exports.pongoProjection = pongoProjection; exports.pongoSingleStreamProjection = pongoSingleStreamProjection; exports.postgreSQLCheckpointer = postgreSQLCheckpointer; exports.postgreSQLEventStoreConsumer = postgreSQLEventStoreConsumer; exports.postgreSQLEventStoreMessageBatchPuller = postgreSQLEventStoreMessageBatchPuller; exports.postgreSQLProcessorLock = postgreSQLProcessorLock; exports.postgreSQLProjection = postgreSQLProjection; exports.postgreSQLProjectionLock = postgreSQLProjectionLock; exports.postgreSQLProjector = postgreSQLProjector; exports.postgreSQLRawBatchSQLProjection = postgreSQLRawBatchSQLProjection; exports.postgreSQLRawSQLProjection = postgreSQLRawSQLProjection; exports.postgreSQLReactor = postgreSQLReactor; exports.processorsTable = processorsTable; exports.processorsTableSQL = processorsTableSQL; exports.projectionsTable = projectionsTable; exports.projectionsTableSQL = projectionsTableSQL; exports.readLastMessageGlobalPosition = readLastMessageGlobalPosition; exports.readMessagesBatch = readMessagesBatch; exports.readProcessorCheckpoint = readProcessorCheckpoint; exports.readProjectionInfo = readProjectionInfo; exports.readStream = readStream; exports.rebuildPostgreSQLProjections = rebuildPostgreSQLProjections; exports.registerProjection = registerProjection; exports.registerProjectionSQL = registerProjectionSQL; exports.releaseProcessorLockSQL = releaseProcessorLockSQL; exports.sanitizeNameSQL = sanitizeNameSQL; exports.schemaMigration = schemaMigration; exports.schemaSQL = schemaSQL; exports.storeProcessorCheckpoint = storeProcessorCheckpoint; exports.storeSubscriptionCheckpointSQL = storeSubscriptionCheckpointSQL; exports.streamExists = streamExists; exports.streamsTable = streamsTable; exports.streamsTableSQL = streamsTableSQL; exports.toProcessorLockKey = toProcessorLockKey; exports.toProjectionLockKey = toProjectionLockKey; exports.transactionToPostgreSQLProjectionHandlerContext = transactionToPostgreSQLProjectionHandlerContext; exports.tryAcquireProcessorLockSQL = tryAcquireProcessorLockSQL; exports.tryAcquireProjectionLockSQL = tryAcquireProjectionLockSQL; exports.unknownTag = unknownTag2; exports.zipPostgreSQLEventStoreMessageBatchPullerStartFrom = zipPostgreSQLEventStoreMessageBatchPullerStartFrom;
5331
+
5332
+ exports.DefaultPostgreSQLEventStoreProcessorBatchSize = DefaultPostgreSQLEventStoreProcessorBatchSize; exports.DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs = DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs; exports.DefaultPostgreSQLProcessorLockPolicy = DefaultPostgreSQLProcessorLockPolicy; exports.PostgreSQLEventStoreDefaultStreamVersion = PostgreSQLEventStoreDefaultStreamVersion; exports.PostgreSQLProjectionSpec = PostgreSQLProjectionSpec; exports.activateProjection = activateProjection; exports.activateProjectionSQL = activateProjectionSQL; exports.addDefaultPartitionSQL = addDefaultPartitionSQL; exports.addModuleForAllTenantsSQL = addModuleForAllTenantsSQL; exports.addModuleSQL = addModuleSQL; exports.addPartitionSQL = addPartitionSQL; exports.addTablePartitions = addTablePartitions; exports.addTenantForAllModulesSQL = addTenantForAllModulesSQL; exports.addTenantSQL = addTenantSQL; exports.appendToStream = appendToStream; exports.appendToStreamSQL = appendToStreamSQL; exports.assertSQLQueryResultMatches = assertSQLQueryResultMatches; exports.callActivateProjection = callActivateProjection; exports.callAppendToStream = callAppendToStream; exports.callDeactivateProjection = callDeactivateProjection; exports.callRegisterProjection = callRegisterProjection; exports.callReleaseProcessorLock = callReleaseProcessorLock; exports.callStoreProcessorCheckpoint = callStoreProcessorCheckpoint; exports.callTryAcquireProcessorLock = callTryAcquireProcessorLock; exports.callTryAcquireProjectionLock = callTryAcquireProjectionLock; exports.cleanupLegacySubscriptionTables = cleanupLegacySubscriptionTables; exports.createEventStoreSchema = createEventStoreSchema; exports.deactivateProjection = deactivateProjection; exports.deactivateProjectionSQL = deactivateProjectionSQL; exports.defaultPostgreSQLOptions = defaultPostgreSQLOptions; exports.defaultTag = defaultTag2; exports.documentDoesNotExist = documentDoesNotExist; exports.documentExists = documentExists; exports.documentMatchingExists = documentMatchingExists; exports.documentsAreTheSame = documentsAreTheSame; exports.documentsMatchingHaveCount = documentsMatchingHaveCount; exports.emmettPrefix = emmettPrefix2; exports.eventInStream = eventInStream; exports.eventStoreSchemaMigrations = eventStoreSchemaMigrations; exports.eventsInStream = eventsInStream; exports.expectPongoDocuments = expectPongoDocuments; exports.expectSQL = expectSQL; exports.getPostgreSQLEventStore = getPostgreSQLEventStore; exports.globalNames = globalNames; exports.globalTag = globalTag; exports.handleProjections = handleProjections; exports.messagesTable = messagesTable; exports.messagesTableSQL = messagesTableSQL; exports.newEventsInStream = newEventsInStream; exports.pongoMultiStreamProjection = pongoMultiStreamProjection; exports.pongoProjection = pongoProjection; exports.pongoSingleStreamProjection = pongoSingleStreamProjection; exports.postgreSQLCheckpointer = postgreSQLCheckpointer; exports.postgreSQLEventStoreConsumer = postgreSQLEventStoreConsumer; exports.postgreSQLEventStoreMessageBatchPuller = postgreSQLEventStoreMessageBatchPuller; exports.postgreSQLProcessorLock = postgreSQLProcessorLock; exports.postgreSQLProjection = postgreSQLProjection; exports.postgreSQLProjectionLock = postgreSQLProjectionLock; exports.postgreSQLProjector = postgreSQLProjector; exports.postgreSQLRawBatchSQLProjection = postgreSQLRawBatchSQLProjection; exports.postgreSQLRawSQLProjection = postgreSQLRawSQLProjection; exports.postgreSQLReactor = postgreSQLReactor; exports.postgreSQLWorkflowProcessor = postgreSQLWorkflowProcessor; exports.processorsTable = processorsTable; exports.processorsTableSQL = processorsTableSQL; exports.projectionsTable = projectionsTable; exports.projectionsTableSQL = projectionsTableSQL; exports.readLastMessageGlobalPosition = readLastMessageGlobalPosition; exports.readMessagesBatch = readMessagesBatch; exports.readProcessorCheckpoint = readProcessorCheckpoint; exports.readProjectionInfo = readProjectionInfo; exports.readStream = readStream; exports.rebuildPostgreSQLProjections = rebuildPostgreSQLProjections; exports.registerProjection = registerProjection; exports.registerProjectionSQL = registerProjectionSQL; exports.releaseProcessorLockSQL = releaseProcessorLockSQL; exports.sanitizeNameSQL = sanitizeNameSQL; exports.schemaMigration = schemaMigration; exports.schemaSQL = schemaSQL; exports.storeProcessorCheckpoint = storeProcessorCheckpoint; exports.storeSubscriptionCheckpointSQL = storeSubscriptionCheckpointSQL; exports.streamExists = streamExists; exports.streamsTable = streamsTable; exports.streamsTableSQL = streamsTableSQL; exports.toProcessorLockKey = toProcessorLockKey; exports.toProjectionLockKey = toProjectionLockKey; exports.transactionToPostgreSQLProjectionHandlerContext = transactionToPostgreSQLProjectionHandlerContext; exports.tryAcquireProcessorLockSQL = tryAcquireProcessorLockSQL; exports.tryAcquireProjectionLockSQL = tryAcquireProjectionLockSQL; exports.unknownTag = unknownTag2; exports.zipPostgreSQLEventStoreMessageBatchPullerStartFrom = zipPostgreSQLEventStoreMessageBatchPullerStartFrom;
5018
5333
  //# sourceMappingURL=index.cjs.map