@event-driven-io/emmett-postgresql 0.29.0 → 0.31.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.cjs +94 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +156 -86
- package/dist/index.d.ts +156 -86
- package/dist/index.js +89 -20
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _event_driven_io_dumbo from '@event-driven-io/dumbo';
|
|
2
2
|
import { SQLExecutor, Dumbo, DumboOptions, QueryResultRow, SQL, NodePostgresClient, NodePostgresTransaction, NodePostgresConnector, NodePostgresPoolClientConnection, NodePostgresClientConnection, NodePostgresPool, MigrationStyle } from '@event-driven-io/dumbo';
|
|
3
|
-
import { Event, ReadEvent, ReadEventMetadataWithGlobalPosition, EmmettError, CanHandle, ThenThrows,
|
|
3
|
+
import { Event, ReadEvent, ReadEventMetadataWithGlobalPosition, EmmettError, CanHandle, ThenThrows, ProjectionDefinition, ProjectionHandler, EventStore, EventStoreSessionFactory, AppendToStreamOptions, AppendToStreamResultWithGlobalPosition, ProjectionRegistration, ReadEventMetadata, ReadStreamOptions, ReadStreamResult } from '@event-driven-io/emmett';
|
|
4
4
|
import pg from 'pg';
|
|
5
5
|
import { PongoDocument, WithId, PongoFilter, PongoClient } from '@event-driven-io/pongo';
|
|
6
6
|
|
|
@@ -35,70 +35,6 @@ type PostgreSQLEventStoreMessageBatchPuller = {
|
|
|
35
35
|
declare const postgreSQLEventStoreMessageBatchPuller: <EventType extends Event = Event>({ executor, batchSize, eachBatch, pullingFrequencyInMs, }: PostgreSQLEventStoreMessageBatchPullerOptions<EventType>) => PostgreSQLEventStoreMessageBatchPuller;
|
|
36
36
|
declare const zipPostgreSQLEventStoreMessageBatchPullerStartFrom: (options: (PostgreSQLEventStoreMessageBatchPullerStartFrom | undefined)[]) => PostgreSQLEventStoreMessageBatchPullerStartFrom;
|
|
37
37
|
|
|
38
|
-
type PostgreSQLProcessorEventsBatch<EventType extends Event = Event> = {
|
|
39
|
-
messages: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[];
|
|
40
|
-
};
|
|
41
|
-
type PostgreSQLProcessor<EventType extends Event = Event> = {
|
|
42
|
-
id: string;
|
|
43
|
-
start: (execute: SQLExecutor) => Promise<PostgreSQLEventStoreMessageBatchPullerStartFrom | undefined>;
|
|
44
|
-
isActive: boolean;
|
|
45
|
-
handle: (messagesBatch: PostgreSQLProcessorEventsBatch<EventType>, context: {
|
|
46
|
-
pool: Dumbo;
|
|
47
|
-
}) => Promise<PostgreSQLProcessorMessageHandlerResult>;
|
|
48
|
-
};
|
|
49
|
-
declare const PostgreSQLProcessor: {
|
|
50
|
-
result: {
|
|
51
|
-
skip: (options?: {
|
|
52
|
-
reason?: string;
|
|
53
|
-
}) => PostgreSQLProcessorMessageHandlerResult;
|
|
54
|
-
stop: (options?: {
|
|
55
|
-
reason?: string;
|
|
56
|
-
error?: EmmettError;
|
|
57
|
-
}) => PostgreSQLProcessorMessageHandlerResult;
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
type PostgreSQLProcessorMessageHandlerResult = void | {
|
|
61
|
-
type: 'SKIP';
|
|
62
|
-
reason?: string;
|
|
63
|
-
} | {
|
|
64
|
-
type: 'STOP';
|
|
65
|
-
reason?: string;
|
|
66
|
-
error?: EmmettError;
|
|
67
|
-
};
|
|
68
|
-
type PostgreSQLProcessorEachMessageHandler<EventType extends Event = Event> = (event: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => Promise<PostgreSQLProcessorMessageHandlerResult> | PostgreSQLProcessorMessageHandlerResult;
|
|
69
|
-
type PostgreSQLProcessorStartFrom = PostgreSQLEventStoreMessageBatchPullerStartFrom | 'CURRENT';
|
|
70
|
-
type PostgreSQLProcessorOptions<EventType extends Event = Event> = {
|
|
71
|
-
processorId: string;
|
|
72
|
-
version?: number;
|
|
73
|
-
partition?: string;
|
|
74
|
-
startFrom?: PostgreSQLProcessorStartFrom;
|
|
75
|
-
stopAfter?: (message: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => boolean;
|
|
76
|
-
eachMessage: PostgreSQLProcessorEachMessageHandler<EventType>;
|
|
77
|
-
};
|
|
78
|
-
declare const postgreSQLProcessor: <EventType extends Event = Event>(options: PostgreSQLProcessorOptions<EventType>) => PostgreSQLProcessor;
|
|
79
|
-
|
|
80
|
-
type PostgreSQLEventStoreConsumerConfig<ConsumerEventType extends Event = Event> = {
|
|
81
|
-
processors?: PostgreSQLProcessor<ConsumerEventType>[];
|
|
82
|
-
pulling?: {
|
|
83
|
-
batchSize?: number;
|
|
84
|
-
pullingFrequencyInMs?: number;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
type PostgreSQLEventStoreConsumerOptions<ConsumerEventType extends Event = Event> = PostgreSQLEventStoreConsumerConfig<ConsumerEventType> & ({
|
|
88
|
-
connectionString: string;
|
|
89
|
-
} | {
|
|
90
|
-
pool: Dumbo;
|
|
91
|
-
});
|
|
92
|
-
type PostgreSQLEventStoreConsumer<ConsumerEventType extends Event = Event> = Readonly<{
|
|
93
|
-
isRunning: boolean;
|
|
94
|
-
processors: PostgreSQLProcessor<ConsumerEventType>[];
|
|
95
|
-
processor: <EventType extends ConsumerEventType = ConsumerEventType>(options: PostgreSQLProcessorOptions<EventType>) => PostgreSQLProcessor<EventType>;
|
|
96
|
-
start: () => Promise<void>;
|
|
97
|
-
stop: () => Promise<void>;
|
|
98
|
-
close: () => Promise<void>;
|
|
99
|
-
}>;
|
|
100
|
-
declare const postgreSQLEventStoreConsumer: <ConsumerEventType extends Event = Event>(options: PostgreSQLEventStoreConsumerOptions<ConsumerEventType>) => PostgreSQLEventStoreConsumer<ConsumerEventType>;
|
|
101
|
-
|
|
102
38
|
type PongoAssertOptions = {
|
|
103
39
|
inCollection: string;
|
|
104
40
|
inDatabase?: string;
|
|
@@ -135,11 +71,11 @@ type PongoProjectionHandlerContext = PostgreSQLProjectionHandlerContext & {
|
|
|
135
71
|
type PongoWithNotNullDocumentEvolve<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata> = ((document: Document, event: ReadEvent<EventType, EventMetaDataType>) => Document | null) | ((document: Document, event: ReadEvent<EventType>) => Promise<Document | null>);
|
|
136
72
|
type PongoWithNullableDocumentEvolve<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata> = ((document: Document | null, event: ReadEvent<EventType, EventMetaDataType>) => Document | null) | ((document: Document | null, event: ReadEvent<EventType>) => Promise<Document | null>);
|
|
137
73
|
type PongoDocumentEvolve<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata> = PongoWithNotNullDocumentEvolve<Document, EventType, EventMetaDataType> | PongoWithNullableDocumentEvolve<Document, EventType, EventMetaDataType>;
|
|
138
|
-
type PongoProjectionOptions<EventType extends Event
|
|
139
|
-
handle: (events: ReadEvent<EventType,
|
|
74
|
+
type PongoProjectionOptions<EventType extends Event> = {
|
|
75
|
+
handle: (events: ReadEvent<EventType, PostgresReadEventMetadata>[], context: PongoProjectionHandlerContext) => Promise<void>;
|
|
140
76
|
canHandle: CanHandle<EventType>;
|
|
141
77
|
};
|
|
142
|
-
declare const pongoProjection: <EventType extends Event
|
|
78
|
+
declare const pongoProjection: <EventType extends Event>({ handle, canHandle, }: PongoProjectionOptions<EventType>) => PostgreSQLProjectionDefinition<EventType>;
|
|
143
79
|
type PongoMultiStreamProjectionOptions<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata> = {
|
|
144
80
|
canHandle: CanHandle<EventType>;
|
|
145
81
|
collectionName: string;
|
|
@@ -150,7 +86,7 @@ type PongoMultiStreamProjectionOptions<Document extends PongoDocument, EventType
|
|
|
150
86
|
evolve: PongoWithNotNullDocumentEvolve<Document, EventType, EventMetaDataType>;
|
|
151
87
|
initialState: () => Document;
|
|
152
88
|
});
|
|
153
|
-
declare const pongoMultiStreamProjection: <Document extends PongoDocument, EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata>(options: PongoMultiStreamProjectionOptions<Document, EventType, EventMetaDataType>) => PostgreSQLProjectionDefinition
|
|
89
|
+
declare const pongoMultiStreamProjection: <Document extends PongoDocument, EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata>(options: PongoMultiStreamProjectionOptions<Document, EventType, EventMetaDataType>) => PostgreSQLProjectionDefinition<EventType>;
|
|
154
90
|
type PongoSingleStreamProjectionOptions<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata> = {
|
|
155
91
|
canHandle: CanHandle<EventType>;
|
|
156
92
|
getDocumentId?: (event: ReadEvent<EventType>) => string;
|
|
@@ -161,7 +97,7 @@ type PongoSingleStreamProjectionOptions<Document extends PongoDocument, EventTyp
|
|
|
161
97
|
evolve: PongoWithNotNullDocumentEvolve<Document, EventType, EventMetaDataType>;
|
|
162
98
|
initialState: () => Document;
|
|
163
99
|
});
|
|
164
|
-
declare const pongoSingleStreamProjection: <Document extends PongoDocument, EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata>(options: PongoSingleStreamProjectionOptions<Document, EventType, EventMetaDataType>) => PostgreSQLProjectionDefinition
|
|
100
|
+
declare const pongoSingleStreamProjection: <Document extends PongoDocument, EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata>(options: PongoSingleStreamProjectionOptions<Document, EventType, EventMetaDataType>) => PostgreSQLProjectionDefinition<EventType>;
|
|
165
101
|
|
|
166
102
|
type PostgreSQLProjectionSpecEvent<EventType extends Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata> = EventType & {
|
|
167
103
|
metadata?: Partial<EventMetaDataType>;
|
|
@@ -173,8 +109,8 @@ type PostgreSQLProjectionAssert = (options: {
|
|
|
173
109
|
pool: Dumbo;
|
|
174
110
|
connectionString: string;
|
|
175
111
|
}) => Promise<void | boolean>;
|
|
176
|
-
type PostgreSQLProjectionSpecOptions = {
|
|
177
|
-
projection: PostgreSQLProjectionDefinition
|
|
112
|
+
type PostgreSQLProjectionSpecOptions<EventType extends Event> = {
|
|
113
|
+
projection: PostgreSQLProjectionDefinition<EventType>;
|
|
178
114
|
} & DumboOptions;
|
|
179
115
|
type PostgreSQLProjectionSpec<EventType extends Event> = (givenEvents: PostgreSQLProjectionSpecEvent<EventType>[]) => {
|
|
180
116
|
when: (events: PostgreSQLProjectionSpecEvent<EventType>[], options?: PostgreSQLProjectionSpecWhenOptions) => {
|
|
@@ -183,7 +119,7 @@ type PostgreSQLProjectionSpec<EventType extends Event> = (givenEvents: PostgreSQ
|
|
|
183
119
|
};
|
|
184
120
|
};
|
|
185
121
|
declare const PostgreSQLProjectionSpec: {
|
|
186
|
-
for: <EventType extends Event>(options: PostgreSQLProjectionSpecOptions) => PostgreSQLProjectionSpec<EventType>;
|
|
122
|
+
for: <EventType extends Event>(options: PostgreSQLProjectionSpecOptions<EventType>) => PostgreSQLProjectionSpec<EventType>;
|
|
187
123
|
};
|
|
188
124
|
declare const eventInStream: <EventType extends Event = Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata>(streamName: string, event: PostgreSQLProjectionSpecEvent<EventType, EventMetaDataType>) => PostgreSQLProjectionSpecEvent<EventType, EventMetaDataType>;
|
|
189
125
|
declare const eventsInStream: <EventType extends Event = Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata>(streamName: string, events: PostgreSQLProjectionSpecEvent<EventType, EventMetaDataType>[]) => PostgreSQLProjectionSpecEvent<EventType, EventMetaDataType>[];
|
|
@@ -198,29 +134,163 @@ declare const expectSQL: {
|
|
|
198
134
|
};
|
|
199
135
|
|
|
200
136
|
type PostgreSQLProjectionHandlerContext = {
|
|
201
|
-
connectionString: string;
|
|
202
|
-
client: NodePostgresClient;
|
|
203
137
|
execute: SQLExecutor;
|
|
204
|
-
|
|
138
|
+
connection: {
|
|
139
|
+
connectionString: string;
|
|
140
|
+
client: NodePostgresClient;
|
|
141
|
+
transaction: NodePostgresTransaction;
|
|
142
|
+
pool: Dumbo;
|
|
143
|
+
};
|
|
205
144
|
};
|
|
206
145
|
type PostgreSQLProjectionHandler<EventType extends Event = Event, EventMetaDataType extends PostgresReadEventMetadata = PostgresReadEventMetadata> = ProjectionHandler<EventType, EventMetaDataType, PostgreSQLProjectionHandlerContext>;
|
|
207
|
-
type PostgreSQLProjectionDefinition<EventType extends Event = Event
|
|
208
|
-
type
|
|
209
|
-
events: ReadEvent<EventType,
|
|
210
|
-
projections: PostgreSQLProjectionDefinition<EventType
|
|
146
|
+
type PostgreSQLProjectionDefinition<EventType extends Event = Event> = ProjectionDefinition<EventType, PostgresReadEventMetadata, PostgreSQLProjectionHandlerContext>;
|
|
147
|
+
type PostgreSQLProjectionHandlerOptions<EventType extends Event = Event> = {
|
|
148
|
+
events: ReadEvent<EventType, PostgresReadEventMetadata>[];
|
|
149
|
+
projections: PostgreSQLProjectionDefinition<EventType>[];
|
|
211
150
|
connection: {
|
|
212
151
|
connectionString: string;
|
|
213
152
|
transaction: NodePostgresTransaction;
|
|
153
|
+
pool: Dumbo;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
declare const handleProjections: <EventType extends Event = Event>(options: PostgreSQLProjectionHandlerOptions<EventType>) => Promise<void>;
|
|
157
|
+
declare const postgreSQLProjection: <EventType extends Event>(definition: PostgreSQLProjectionDefinition<EventType>) => PostgreSQLProjectionDefinition<EventType>;
|
|
158
|
+
declare const postgreSQLRawBatchSQLProjection: <EventType extends Event>(handle: (events: EventType[], context: PostgreSQLProjectionHandlerContext) => Promise<SQL[]> | SQL[], ...canHandle: CanHandle<EventType>) => PostgreSQLProjectionDefinition<EventType>;
|
|
159
|
+
declare const postgreSQLRawSQLProjection: <EventType extends Event>(handle: (event: EventType, context: PostgreSQLProjectionHandlerContext) => Promise<SQL> | SQL, ...canHandle: CanHandle<EventType>) => PostgreSQLProjectionDefinition<EventType>;
|
|
160
|
+
|
|
161
|
+
type PostgreSQLProcessorEventsBatch<EventType extends Event = Event> = {
|
|
162
|
+
messages: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[];
|
|
163
|
+
};
|
|
164
|
+
type PostgreSQLProcessorHandlerContext = {
|
|
165
|
+
execute: SQLExecutor;
|
|
166
|
+
connection: {
|
|
167
|
+
connectionString: string;
|
|
168
|
+
client: NodePostgresClient;
|
|
169
|
+
transaction: NodePostgresTransaction;
|
|
170
|
+
pool: Dumbo;
|
|
214
171
|
};
|
|
215
172
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
173
|
+
type PostgreSQLProcessor<EventType extends Event = Event> = {
|
|
174
|
+
id: string;
|
|
175
|
+
start: (execute: SQLExecutor) => Promise<PostgreSQLEventStoreMessageBatchPullerStartFrom | undefined>;
|
|
176
|
+
isActive: boolean;
|
|
177
|
+
handle: (messagesBatch: PostgreSQLProcessorEventsBatch<EventType>, context: {
|
|
178
|
+
pool?: Dumbo;
|
|
179
|
+
connectionString?: string;
|
|
180
|
+
}) => Promise<PostgreSQLProcessorMessageHandlerResult>;
|
|
181
|
+
};
|
|
182
|
+
declare const PostgreSQLProcessor: {
|
|
183
|
+
result: {
|
|
184
|
+
skip: (options?: {
|
|
185
|
+
reason?: string;
|
|
186
|
+
}) => PostgreSQLProcessorMessageHandlerResult;
|
|
187
|
+
stop: (options?: {
|
|
188
|
+
reason?: string;
|
|
189
|
+
error?: EmmettError;
|
|
190
|
+
}) => PostgreSQLProcessorMessageHandlerResult;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
type PostgreSQLProcessorMessageHandlerResult = void | {
|
|
194
|
+
type: 'SKIP';
|
|
195
|
+
reason?: string;
|
|
196
|
+
} | {
|
|
197
|
+
type: 'STOP';
|
|
198
|
+
reason?: string;
|
|
199
|
+
error?: EmmettError;
|
|
200
|
+
};
|
|
201
|
+
type PostgreSQLProcessorEachMessageHandler<EventType extends Event = Event> = (event: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>, context: PostgreSQLProcessorHandlerContext) => Promise<PostgreSQLProcessorMessageHandlerResult> | PostgreSQLProcessorMessageHandlerResult;
|
|
202
|
+
type PostgreSQLProcessorEachBatchHandler<EventType extends Event = Event> = (event: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[], context: PostgreSQLProcessorHandlerContext) => Promise<PostgreSQLProcessorMessageHandlerResult> | PostgreSQLProcessorMessageHandlerResult;
|
|
203
|
+
type PostgreSQLProcessorStartFrom = PostgreSQLEventStoreMessageBatchPullerStartFrom | 'CURRENT';
|
|
204
|
+
type PostgreSQLProcessorPooledOptions = {
|
|
205
|
+
connector?: NodePostgresConnector;
|
|
206
|
+
database?: string;
|
|
207
|
+
pooled: true;
|
|
208
|
+
pool: pg.Pool;
|
|
209
|
+
} | {
|
|
210
|
+
connector?: NodePostgresConnector;
|
|
211
|
+
database?: string;
|
|
212
|
+
pool: pg.Pool;
|
|
213
|
+
} | {
|
|
214
|
+
connector?: NodePostgresConnector;
|
|
215
|
+
database?: string;
|
|
216
|
+
pooled: true;
|
|
217
|
+
} | {
|
|
218
|
+
connector?: NodePostgresConnector;
|
|
219
|
+
database?: string;
|
|
220
|
+
};
|
|
221
|
+
type PostgreSQLProcessorNotPooledOptions = {
|
|
222
|
+
connector?: NodePostgresConnector;
|
|
223
|
+
database?: string;
|
|
224
|
+
pooled: false;
|
|
225
|
+
client: pg.Client;
|
|
226
|
+
} | {
|
|
227
|
+
connector?: NodePostgresConnector;
|
|
228
|
+
database?: string;
|
|
229
|
+
client: pg.Client;
|
|
230
|
+
} | {
|
|
231
|
+
connector?: NodePostgresConnector;
|
|
232
|
+
database?: string;
|
|
233
|
+
pooled: false;
|
|
234
|
+
} | {
|
|
235
|
+
connector?: NodePostgresConnector;
|
|
236
|
+
database?: string;
|
|
237
|
+
connection: NodePostgresPoolClientConnection | NodePostgresClientConnection;
|
|
238
|
+
pooled?: false;
|
|
239
|
+
} | {
|
|
240
|
+
connector?: NodePostgresConnector;
|
|
241
|
+
database?: string;
|
|
242
|
+
dumbo: NodePostgresPool;
|
|
243
|
+
pooled?: false;
|
|
244
|
+
};
|
|
245
|
+
type PostgreSQLProcessorConnectionOptions = {
|
|
246
|
+
connectionString: string;
|
|
247
|
+
} & (PostgreSQLProcessorPooledOptions | PostgreSQLProcessorNotPooledOptions);
|
|
248
|
+
type GenericPostgreSQLProcessorOptions<EventType extends Event = Event> = {
|
|
249
|
+
processorId: string;
|
|
250
|
+
version?: number;
|
|
251
|
+
partition?: string;
|
|
252
|
+
startFrom?: PostgreSQLProcessorStartFrom;
|
|
253
|
+
stopAfter?: (message: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => boolean;
|
|
254
|
+
eachMessage: PostgreSQLProcessorEachMessageHandler<EventType>;
|
|
255
|
+
connectionOptions?: PostgreSQLProcessorConnectionOptions;
|
|
256
|
+
};
|
|
257
|
+
type PostgreSQLProjectionProcessorOptions<EventType extends Event = Event> = {
|
|
258
|
+
processorId?: string;
|
|
259
|
+
version?: number;
|
|
260
|
+
projection: PostgreSQLProjectionDefinition<EventType>;
|
|
261
|
+
partition?: string;
|
|
262
|
+
startFrom?: PostgreSQLProcessorStartFrom;
|
|
263
|
+
stopAfter?: (message: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => boolean;
|
|
264
|
+
connectionOptions?: PostgreSQLProcessorConnectionOptions;
|
|
265
|
+
};
|
|
266
|
+
type PostgreSQLProcessorOptions<EventType extends Event = Event> = GenericPostgreSQLProcessorOptions<EventType> | PostgreSQLProjectionProcessorOptions<EventType>;
|
|
267
|
+
declare const postgreSQLProjectionProcessor: <EventType extends Event = Event>(options: PostgreSQLProjectionProcessorOptions<EventType>) => PostgreSQLProcessor;
|
|
268
|
+
declare const postgreSQLProcessor: <EventType extends Event = Event>(options: PostgreSQLProcessorOptions<EventType>) => PostgreSQLProcessor;
|
|
269
|
+
|
|
270
|
+
type PostgreSQLEventStoreConsumerConfig<ConsumerEventType extends Event = Event> = {
|
|
271
|
+
processors?: PostgreSQLProcessor<ConsumerEventType>[];
|
|
272
|
+
pulling?: {
|
|
273
|
+
batchSize?: number;
|
|
274
|
+
pullingFrequencyInMs?: number;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
type PostgreSQLEventStoreConsumerOptions<ConsumerEventType extends Event = Event> = PostgreSQLEventStoreConsumerConfig<ConsumerEventType> & {
|
|
278
|
+
connectionString: string;
|
|
279
|
+
pool?: Dumbo;
|
|
280
|
+
};
|
|
281
|
+
type PostgreSQLEventStoreConsumer<ConsumerEventType extends Event = Event> = Readonly<{
|
|
282
|
+
isRunning: boolean;
|
|
283
|
+
processors: PostgreSQLProcessor<ConsumerEventType>[];
|
|
284
|
+
processor: <EventType extends ConsumerEventType = ConsumerEventType>(options: PostgreSQLProcessorOptions<EventType>) => PostgreSQLProcessor<EventType>;
|
|
285
|
+
start: () => Promise<void>;
|
|
286
|
+
stop: () => Promise<void>;
|
|
287
|
+
close: () => Promise<void>;
|
|
288
|
+
}>;
|
|
289
|
+
declare const postgreSQLEventStoreConsumer: <ConsumerEventType extends Event = Event>(options: PostgreSQLEventStoreConsumerOptions<ConsumerEventType>) => PostgreSQLEventStoreConsumer<ConsumerEventType>;
|
|
220
290
|
|
|
221
291
|
interface PostgresEventStore extends EventStore<PostgresReadEventMetadata>, EventStoreSessionFactory<PostgresEventStore> {
|
|
222
292
|
appendToStream<EventType extends Event>(streamName: string, events: EventType[], options?: AppendToStreamOptions): Promise<AppendToStreamResultWithGlobalPosition>;
|
|
223
|
-
consumer<ConsumerEventType extends Event = Event>(options
|
|
293
|
+
consumer<ConsumerEventType extends Event = Event>(options?: PostgreSQLEventStoreConsumerConfig<ConsumerEventType>): PostgreSQLEventStoreConsumer<ConsumerEventType>;
|
|
224
294
|
close(): Promise<void>;
|
|
225
295
|
schema: {
|
|
226
296
|
sql(): string;
|
|
@@ -421,4 +491,4 @@ declare const subscriptionsTable: {
|
|
|
421
491
|
declare const schemaSQL: SQL[];
|
|
422
492
|
declare const createEventStoreSchema: (pool: NodePostgresPool) => Promise<void>;
|
|
423
493
|
|
|
424
|
-
export { type AppendToStreamPreCommitHook, DefaultPostgreSQLEventStoreProcessorBatchSize, DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs, type PongoAssertOptions, type PongoDocumentEvolve, type PongoMultiStreamProjectionOptions, type PongoProjectionHandlerContext, type PongoProjectionOptions, type PongoSingleStreamProjectionOptions, type PongoWithNotNullDocumentEvolve, type PongoWithNullableDocumentEvolve, type PostgreSQLEventStoreConsumer, type PostgreSQLEventStoreConsumerConfig, type PostgreSQLEventStoreConsumerOptions, PostgreSQLEventStoreDefaultStreamVersion, type PostgreSQLEventStoreMessageBatchPuller, type PostgreSQLEventStoreMessageBatchPullerOptions, type PostgreSQLEventStoreMessageBatchPullerStartFrom, type PostgreSQLEventStoreMessageBatchPullerStartOptions, type PostgreSQLEventStoreMessagesBatch, type PostgreSQLEventStoreMessagesBatchHandler, type PostgreSQLEventStoreMessagesBatchHandlerResult, PostgreSQLProcessor, type PostgreSQLProcessorEachMessageHandler, type PostgreSQLProcessorEventsBatch, type PostgreSQLProcessorMessageHandlerResult, type PostgreSQLProcessorOptions, type PostgreSQLProcessorStartFrom, type PostgreSQLProjectionAssert, type PostgreSQLProjectionDefinition, type PostgreSQLProjectionHandler, type PostgreSQLProjectionHandlerContext, PostgreSQLProjectionSpec, type PostgreSQLProjectionSpecEvent, type PostgreSQLProjectionSpecOptions, type PostgreSQLProjectionSpecWhenOptions, type PostgresEventStore, type PostgresEventStoreConnectionOptions, type PostgresEventStoreOptions, type PostgresReadEvent, type PostgresReadEventMetadata, type
|
|
494
|
+
export { type AppendToStreamPreCommitHook, DefaultPostgreSQLEventStoreProcessorBatchSize, DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs, type GenericPostgreSQLProcessorOptions, type PongoAssertOptions, type PongoDocumentEvolve, type PongoMultiStreamProjectionOptions, type PongoProjectionHandlerContext, type PongoProjectionOptions, type PongoSingleStreamProjectionOptions, type PongoWithNotNullDocumentEvolve, type PongoWithNullableDocumentEvolve, type PostgreSQLEventStoreConsumer, type PostgreSQLEventStoreConsumerConfig, type PostgreSQLEventStoreConsumerOptions, PostgreSQLEventStoreDefaultStreamVersion, type PostgreSQLEventStoreMessageBatchPuller, type PostgreSQLEventStoreMessageBatchPullerOptions, type PostgreSQLEventStoreMessageBatchPullerStartFrom, type PostgreSQLEventStoreMessageBatchPullerStartOptions, type PostgreSQLEventStoreMessagesBatch, type PostgreSQLEventStoreMessagesBatchHandler, type PostgreSQLEventStoreMessagesBatchHandlerResult, PostgreSQLProcessor, type PostgreSQLProcessorConnectionOptions, type PostgreSQLProcessorEachBatchHandler, type PostgreSQLProcessorEachMessageHandler, type PostgreSQLProcessorEventsBatch, type PostgreSQLProcessorHandlerContext, type PostgreSQLProcessorMessageHandlerResult, type PostgreSQLProcessorOptions, type PostgreSQLProcessorStartFrom, type PostgreSQLProjectionAssert, type PostgreSQLProjectionDefinition, type PostgreSQLProjectionHandler, type PostgreSQLProjectionHandlerContext, type PostgreSQLProjectionHandlerOptions, type PostgreSQLProjectionProcessorOptions, PostgreSQLProjectionSpec, type PostgreSQLProjectionSpecEvent, type PostgreSQLProjectionSpecOptions, type PostgreSQLProjectionSpecWhenOptions, type PostgresEventStore, type PostgresEventStoreConnectionOptions, type PostgresEventStoreOptions, type PostgresReadEvent, type PostgresReadEventMetadata, type ReadLastMessageGlobalPositionResult, type ReadMessagesBatchOptions, type ReadMessagesBatchResult, type ReadProcessorCheckpointResult, type StoreLastProcessedProcessorPositionResult, addDefaultPartition, addEventsPartitions, addModuleForAllTenantsSQL, addModuleSQL, addTablePartitions, addTenantForAllModulesSQL, addTenantSQL, appendEventsSQL, appendToStream, assertSQLQueryResultMatches, createEventStoreSchema, defaultPostgreSQLOptions, defaultTag, documentDoesNotExist, documentExists, documentMatchingExists, documentsAreTheSame, documentsMatchingHaveCount, emmettPrefix, eventInStream, eventsInStream, eventsTable, eventsTableSQL, expectPongoDocuments, expectSQL, getPostgreSQLEventStore, globalNames, globalTag, handleProjections, newEventsInStream, pongoMultiStreamProjection, pongoProjection, pongoSingleStreamProjection, postgreSQLEventStoreConsumer, postgreSQLEventStoreMessageBatchPuller, postgreSQLProcessor, postgreSQLProjection, postgreSQLProjectionProcessor, postgreSQLRawBatchSQLProjection, postgreSQLRawSQLProjection, readLastMessageGlobalPosition, readMessagesBatch, readProcessorCheckpoint, readStream, sanitizeNameSQL, schemaSQL, storeProcessorCheckpoint, storeSubscriptionCheckpointSQL, streamsTable, streamsTableSQL, subscriptionsTable, subscriptionsTableSQL, zipPostgreSQLEventStoreMessageBatchPullerStartFrom };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/eventStore/postgreSQLEventStore.ts
|
|
2
2
|
import {
|
|
3
|
-
dumbo as
|
|
3
|
+
dumbo as dumbo4
|
|
4
4
|
} from "@event-driven-io/dumbo";
|
|
5
5
|
|
|
6
6
|
// ../emmett/dist/chunk-4E7QLAH5.js
|
|
@@ -605,10 +605,13 @@ var zipPostgreSQLEventStoreMessageBatchPullerStartFrom = (options) => {
|
|
|
605
605
|
};
|
|
606
606
|
|
|
607
607
|
// src/eventStore/consumers/postgreSQLEventStoreConsumer.ts
|
|
608
|
-
import { dumbo } from "@event-driven-io/dumbo";
|
|
608
|
+
import { dumbo as dumbo2 } from "@event-driven-io/dumbo";
|
|
609
609
|
|
|
610
610
|
// src/eventStore/consumers/postgreSQLProcessor.ts
|
|
611
|
-
import
|
|
611
|
+
import {
|
|
612
|
+
dumbo
|
|
613
|
+
} from "@event-driven-io/dumbo";
|
|
614
|
+
import "pg";
|
|
612
615
|
|
|
613
616
|
// src/eventStore/schema/index.ts
|
|
614
617
|
import "@event-driven-io/dumbo";
|
|
@@ -1276,9 +1279,33 @@ var PostgreSQLProcessor = {
|
|
|
1276
1279
|
})
|
|
1277
1280
|
}
|
|
1278
1281
|
};
|
|
1279
|
-
var
|
|
1282
|
+
var genericPostgreSQLProcessor = (options) => {
|
|
1280
1283
|
const { eachMessage } = options;
|
|
1281
1284
|
let isActive = true;
|
|
1285
|
+
const poolOptions = {
|
|
1286
|
+
...options.connectionOptions ? options.connectionOptions : {}
|
|
1287
|
+
};
|
|
1288
|
+
const processorConnectionString = "connectionString" in poolOptions ? poolOptions.connectionString : null;
|
|
1289
|
+
const processorPool = "dumbo" in poolOptions ? poolOptions.dumbo : processorConnectionString ? dumbo({
|
|
1290
|
+
connectionString: processorConnectionString,
|
|
1291
|
+
...poolOptions
|
|
1292
|
+
}) : null;
|
|
1293
|
+
const getPool = (context) => {
|
|
1294
|
+
const connectionString = processorConnectionString ?? context.connectionString;
|
|
1295
|
+
if (!connectionString)
|
|
1296
|
+
throw new EmmettError(
|
|
1297
|
+
`PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
|
|
1298
|
+
);
|
|
1299
|
+
const pool = (!processorConnectionString || connectionString == processorConnectionString ? context?.pool : processorPool) ?? processorPool;
|
|
1300
|
+
if (!pool)
|
|
1301
|
+
throw new EmmettError(
|
|
1302
|
+
`PostgreSQL processor '${options.processorId}' is missing connection string. Ensure that you passed it through options`
|
|
1303
|
+
);
|
|
1304
|
+
return {
|
|
1305
|
+
connectionString,
|
|
1306
|
+
pool
|
|
1307
|
+
};
|
|
1308
|
+
};
|
|
1282
1309
|
return {
|
|
1283
1310
|
id: options.processorId,
|
|
1284
1311
|
start: async (execute) => {
|
|
@@ -1294,15 +1321,25 @@ var postgreSQLProcessor = (options) => {
|
|
|
1294
1321
|
get isActive() {
|
|
1295
1322
|
return isActive;
|
|
1296
1323
|
},
|
|
1297
|
-
handle: async ({ messages },
|
|
1324
|
+
handle: async ({ messages }, context) => {
|
|
1298
1325
|
if (!isActive) return;
|
|
1299
|
-
|
|
1326
|
+
const { pool, connectionString } = getPool(context);
|
|
1327
|
+
return pool.withTransaction(async (transaction) => {
|
|
1300
1328
|
let result = void 0;
|
|
1301
1329
|
let lastProcessedPosition = null;
|
|
1302
1330
|
for (const message of messages) {
|
|
1303
1331
|
const typedMessage = message;
|
|
1304
|
-
const
|
|
1305
|
-
await
|
|
1332
|
+
const client = await transaction.connection.open();
|
|
1333
|
+
const messageProcessingResult = await eachMessage(typedMessage, {
|
|
1334
|
+
execute: transaction.execute,
|
|
1335
|
+
connection: {
|
|
1336
|
+
connectionString,
|
|
1337
|
+
pool,
|
|
1338
|
+
transaction,
|
|
1339
|
+
client
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
await storeProcessorCheckpoint(transaction.execute, {
|
|
1306
1343
|
processorId: options.processorId,
|
|
1307
1344
|
version: options.version,
|
|
1308
1345
|
lastProcessedPosition,
|
|
@@ -1328,6 +1365,23 @@ var postgreSQLProcessor = (options) => {
|
|
|
1328
1365
|
}
|
|
1329
1366
|
};
|
|
1330
1367
|
};
|
|
1368
|
+
var postgreSQLProjectionProcessor = (options) => {
|
|
1369
|
+
const projection2 = options.projection;
|
|
1370
|
+
return genericPostgreSQLProcessor({
|
|
1371
|
+
processorId: options.processorId ?? `projection:${projection2.name}`,
|
|
1372
|
+
eachMessage: async (event, context) => {
|
|
1373
|
+
if (!projection2.canHandle.includes(event.type)) return;
|
|
1374
|
+
await projection2.handle([event], context);
|
|
1375
|
+
},
|
|
1376
|
+
...options
|
|
1377
|
+
});
|
|
1378
|
+
};
|
|
1379
|
+
var postgreSQLProcessor = (options) => {
|
|
1380
|
+
if ("projection" in options) {
|
|
1381
|
+
return postgreSQLProjectionProcessor(options);
|
|
1382
|
+
}
|
|
1383
|
+
return genericPostgreSQLProcessor(options);
|
|
1384
|
+
};
|
|
1331
1385
|
|
|
1332
1386
|
// src/eventStore/consumers/postgreSQLEventStoreConsumer.ts
|
|
1333
1387
|
var postgreSQLEventStoreConsumer = (options) => {
|
|
@@ -1336,7 +1390,7 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
1336
1390
|
const processors = options.processors ?? [];
|
|
1337
1391
|
let start;
|
|
1338
1392
|
let currentMessagePuller;
|
|
1339
|
-
const pool =
|
|
1393
|
+
const pool = options.pool ? options.pool : dumbo2({ connectionString: options.connectionString });
|
|
1340
1394
|
const eachBatch = async (messagesBatch) => {
|
|
1341
1395
|
const activeProcessors = processors.filter((s) => s.isActive);
|
|
1342
1396
|
if (activeProcessors.length === 0)
|
|
@@ -1346,7 +1400,10 @@ var postgreSQLEventStoreConsumer = (options) => {
|
|
|
1346
1400
|
};
|
|
1347
1401
|
const result = await Promise.allSettled(
|
|
1348
1402
|
activeProcessors.map((s) => {
|
|
1349
|
-
return s.handle(messagesBatch, {
|
|
1403
|
+
return s.handle(messagesBatch, {
|
|
1404
|
+
pool,
|
|
1405
|
+
connectionString: options.connectionString
|
|
1406
|
+
});
|
|
1350
1407
|
})
|
|
1351
1408
|
);
|
|
1352
1409
|
return result.some(
|
|
@@ -1554,7 +1611,9 @@ var pongoProjection = ({
|
|
|
1554
1611
|
}) => postgreSQLProjection({
|
|
1555
1612
|
canHandle,
|
|
1556
1613
|
handle: async (events, context) => {
|
|
1557
|
-
const {
|
|
1614
|
+
const {
|
|
1615
|
+
connection: { connectionString, client }
|
|
1616
|
+
} = context;
|
|
1558
1617
|
const pongo = pongoClient2(connectionString, {
|
|
1559
1618
|
connectionOptions: { client }
|
|
1560
1619
|
});
|
|
@@ -1593,7 +1652,7 @@ var pongoSingleStreamProjection = (options) => {
|
|
|
1593
1652
|
|
|
1594
1653
|
// src/eventStore/projections/postgresProjectionSpec.ts
|
|
1595
1654
|
import {
|
|
1596
|
-
dumbo as
|
|
1655
|
+
dumbo as dumbo3
|
|
1597
1656
|
} from "@event-driven-io/dumbo";
|
|
1598
1657
|
import { v4 as uuid5 } from "uuid";
|
|
1599
1658
|
var PostgreSQLProjectionSpec = {
|
|
@@ -1631,6 +1690,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
1631
1690
|
events: allEvents,
|
|
1632
1691
|
projections: [projection2],
|
|
1633
1692
|
connection: {
|
|
1693
|
+
pool,
|
|
1634
1694
|
connectionString,
|
|
1635
1695
|
transaction
|
|
1636
1696
|
}
|
|
@@ -1639,7 +1699,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
1639
1699
|
};
|
|
1640
1700
|
return {
|
|
1641
1701
|
then: async (assert, message) => {
|
|
1642
|
-
const pool =
|
|
1702
|
+
const pool = dumbo3(dumoOptions);
|
|
1643
1703
|
try {
|
|
1644
1704
|
await run(pool);
|
|
1645
1705
|
const succeeded = await assert({ pool, connectionString });
|
|
@@ -1652,7 +1712,7 @@ var PostgreSQLProjectionSpec = {
|
|
|
1652
1712
|
}
|
|
1653
1713
|
},
|
|
1654
1714
|
thenThrows: async (...args) => {
|
|
1655
|
-
const pool =
|
|
1715
|
+
const pool = dumbo3(dumoOptions);
|
|
1656
1716
|
try {
|
|
1657
1717
|
await run(pool);
|
|
1658
1718
|
throw new AssertionError("Handler did not fail as expected");
|
|
@@ -1717,7 +1777,7 @@ var handleProjections = async (options) => {
|
|
|
1717
1777
|
const {
|
|
1718
1778
|
projections: allProjections,
|
|
1719
1779
|
events,
|
|
1720
|
-
connection: { transaction, connectionString }
|
|
1780
|
+
connection: { pool, transaction, connectionString }
|
|
1721
1781
|
} = options;
|
|
1722
1782
|
const eventTypes = events.map((e) => e.type);
|
|
1723
1783
|
const projections = allProjections.filter(
|
|
@@ -1726,9 +1786,12 @@ var handleProjections = async (options) => {
|
|
|
1726
1786
|
const client = await transaction.connection.open();
|
|
1727
1787
|
for (const projection2 of projections) {
|
|
1728
1788
|
await projection2.handle(events, {
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1789
|
+
connection: {
|
|
1790
|
+
connectionString,
|
|
1791
|
+
pool,
|
|
1792
|
+
client,
|
|
1793
|
+
transaction
|
|
1794
|
+
},
|
|
1732
1795
|
execute: transaction.execute
|
|
1733
1796
|
});
|
|
1734
1797
|
}
|
|
@@ -1763,7 +1826,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1763
1826
|
connectionString,
|
|
1764
1827
|
...options.connectionOptions ? options.connectionOptions : {}
|
|
1765
1828
|
};
|
|
1766
|
-
const pool = "dumbo" in poolOptions ? poolOptions.dumbo :
|
|
1829
|
+
const pool = "dumbo" in poolOptions ? poolOptions.dumbo : dumbo4(poolOptions);
|
|
1767
1830
|
let migrateSchema;
|
|
1768
1831
|
const autoGenerateSchema = options.schema?.autoMigration === void 0 || options.schema?.autoMigration !== "None";
|
|
1769
1832
|
const ensureSchemaExists = () => {
|
|
@@ -1778,6 +1841,7 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1778
1841
|
projections: inlineProjections,
|
|
1779
1842
|
connection: {
|
|
1780
1843
|
connectionString,
|
|
1844
|
+
pool,
|
|
1781
1845
|
transaction
|
|
1782
1846
|
},
|
|
1783
1847
|
// TODO: Add proper handling of global data
|
|
@@ -1843,7 +1907,11 @@ var getPostgreSQLEventStore = (connectionString, options = defaultPostgreSQLOpti
|
|
|
1843
1907
|
createdNewStream: appendResult.nextStreamPosition >= BigInt(events.length)
|
|
1844
1908
|
};
|
|
1845
1909
|
},
|
|
1846
|
-
consumer: (options2) => postgreSQLEventStoreConsumer({
|
|
1910
|
+
consumer: (options2) => postgreSQLEventStoreConsumer({
|
|
1911
|
+
...options2 ?? {},
|
|
1912
|
+
pool,
|
|
1913
|
+
connectionString
|
|
1914
|
+
}),
|
|
1847
1915
|
close: () => pool.close(),
|
|
1848
1916
|
async withSession(callback) {
|
|
1849
1917
|
return await pool.withConnection(async (connection) => {
|
|
@@ -1908,6 +1976,7 @@ export {
|
|
|
1908
1976
|
postgreSQLEventStoreMessageBatchPuller,
|
|
1909
1977
|
postgreSQLProcessor,
|
|
1910
1978
|
postgreSQLProjection,
|
|
1979
|
+
postgreSQLProjectionProcessor,
|
|
1911
1980
|
postgreSQLRawBatchSQLProjection,
|
|
1912
1981
|
postgreSQLRawSQLProjection,
|
|
1913
1982
|
readLastMessageGlobalPosition,
|