@event-driven-io/emmett-postgresql 0.27.0 → 0.29.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.d.cts CHANGED
@@ -1,9 +1,104 @@
1
1
  import * as _event_driven_io_dumbo from '@event-driven-io/dumbo';
2
- import { Dumbo, DumboOptions, QueryResultRow, SQL, NodePostgresClient, SQLExecutor, NodePostgresTransaction, MigrationStyle, NodePostgresConnector, NodePostgresPoolClientConnection, NodePostgresClientConnection, NodePostgresPool } from '@event-driven-io/dumbo';
3
- import { Event, ReadEvent, CanHandle, ThenThrows, ProjectionHandler, TypedProjectionDefinition, EventStore, EventStoreSessionFactory, AppendToStreamOptions, AppendToStreamResultWithGlobalPosition, ReadEventMetadataWithGlobalPosition, ProjectionRegistration, ReadEventMetadata, ReadStreamOptions, ReadStreamResult, EmmettError } from '@event-driven-io/emmett';
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, TypedProjectionDefinition, 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
 
7
+ declare const DefaultPostgreSQLEventStoreProcessorBatchSize = 100;
8
+ declare const DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs = 50;
9
+ type PostgreSQLEventStoreMessagesBatch<EventType extends Event = Event> = {
10
+ messages: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[];
11
+ };
12
+ type PostgreSQLEventStoreMessagesBatchHandlerResult = void | {
13
+ type: 'STOP';
14
+ reason?: string;
15
+ error?: EmmettError;
16
+ };
17
+ type PostgreSQLEventStoreMessagesBatchHandler<EventType extends Event = Event> = (messagesBatch: PostgreSQLEventStoreMessagesBatch<EventType>) => Promise<PostgreSQLEventStoreMessagesBatchHandlerResult> | PostgreSQLEventStoreMessagesBatchHandlerResult;
18
+ type PostgreSQLEventStoreMessageBatchPullerOptions<EventType extends Event = Event> = {
19
+ executor: SQLExecutor;
20
+ pullingFrequencyInMs: number;
21
+ batchSize: number;
22
+ eachBatch: PostgreSQLEventStoreMessagesBatchHandler<EventType>;
23
+ };
24
+ type PostgreSQLEventStoreMessageBatchPullerStartFrom = {
25
+ globalPosition: bigint;
26
+ } | 'BEGINNING' | 'END';
27
+ type PostgreSQLEventStoreMessageBatchPullerStartOptions = {
28
+ startFrom: PostgreSQLEventStoreMessageBatchPullerStartFrom;
29
+ };
30
+ type PostgreSQLEventStoreMessageBatchPuller = {
31
+ isRunning: boolean;
32
+ start(options: PostgreSQLEventStoreMessageBatchPullerStartOptions): Promise<void>;
33
+ stop(): Promise<void>;
34
+ };
35
+ declare const postgreSQLEventStoreMessageBatchPuller: <EventType extends Event = Event>({ executor, batchSize, eachBatch, pullingFrequencyInMs, }: PostgreSQLEventStoreMessageBatchPullerOptions<EventType>) => PostgreSQLEventStoreMessageBatchPuller;
36
+ declare const zipPostgreSQLEventStoreMessageBatchPullerStartFrom: (options: (PostgreSQLEventStoreMessageBatchPullerStartFrom | undefined)[]) => PostgreSQLEventStoreMessageBatchPullerStartFrom;
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
+
7
102
  type PongoAssertOptions = {
8
103
  inCollection: string;
9
104
  inDatabase?: string;
@@ -125,6 +220,7 @@ declare const postgreSQLRawSQLProjection: <EventType extends Event>(handle: (eve
125
220
 
126
221
  interface PostgresEventStore extends EventStore<PostgresReadEventMetadata>, EventStoreSessionFactory<PostgresEventStore> {
127
222
  appendToStream<EventType extends Event>(streamName: string, events: EventType[], options?: AppendToStreamOptions): Promise<AppendToStreamResultWithGlobalPosition>;
223
+ consumer<ConsumerEventType extends Event = Event>(options: PostgreSQLEventStoreConsumerConfig<ConsumerEventType>): PostgreSQLEventStoreConsumer<ConsumerEventType>;
128
224
  close(): Promise<void>;
129
225
  schema: {
130
226
  sql(): string;
@@ -246,36 +342,36 @@ declare const readStream: <EventType extends Event>(execute: SQLExecutor, stream
246
342
  partition?: string;
247
343
  }) => Promise<ReadStreamResult<EventType, ReadEventMetadataWithGlobalPosition>>;
248
344
 
249
- type ReadSubscriptionCheckpointResult = {
345
+ type ReadProcessorCheckpointResult = {
250
346
  lastProcessedPosition: bigint | null;
251
347
  };
252
- declare const readSubscriptionCheckpoint: (execute: SQLExecutor, options: {
253
- subscriptionId: string;
348
+ declare const readProcessorCheckpoint: (execute: SQLExecutor, options: {
349
+ processorId: string;
254
350
  partition?: string;
255
- }) => Promise<ReadSubscriptionCheckpointResult>;
351
+ }) => Promise<ReadProcessorCheckpointResult>;
256
352
 
257
353
  declare const storeSubscriptionCheckpointSQL: _event_driven_io_dumbo.SQL;
258
- type StoreLastProcessedSubscriptionPositionResult<Position extends bigint | null = bigint> = {
354
+ type StoreLastProcessedProcessorPositionResult<Position extends bigint | null = bigint> = {
259
355
  success: true;
260
356
  newPosition: Position;
261
357
  } | {
262
358
  success: false;
263
359
  reason: 'IGNORED' | 'MISMATCH';
264
360
  };
265
- declare function storeSubscriptionCheckpoint(execute: SQLExecutor, options: {
266
- subscriptionId: string;
361
+ declare function storeProcessorCheckpoint(execute: SQLExecutor, options: {
362
+ processorId: string;
267
363
  version: number | undefined;
268
364
  newPosition: bigint | null;
269
365
  lastProcessedPosition: bigint | null;
270
366
  partition?: string;
271
- }): Promise<StoreLastProcessedSubscriptionPositionResult<bigint | null>>;
272
- declare function storeSubscriptionCheckpoint(execute: SQLExecutor, options: {
273
- subscriptionId: string;
367
+ }): Promise<StoreLastProcessedProcessorPositionResult<bigint | null>>;
368
+ declare function storeProcessorCheckpoint(execute: SQLExecutor, options: {
369
+ processorId: string;
274
370
  version: number | undefined;
275
371
  newPosition: bigint;
276
372
  lastProcessedPosition: bigint | null;
277
373
  partition?: string;
278
- }): Promise<StoreLastProcessedSubscriptionPositionResult<bigint>>;
374
+ }): Promise<StoreLastProcessedProcessorPositionResult<bigint>>;
279
375
 
280
376
  declare const streamsTableSQL: _event_driven_io_dumbo.SQL;
281
377
  declare const eventsTableSQL: _event_driven_io_dumbo.SQL;
@@ -325,96 +421,4 @@ declare const subscriptionsTable: {
325
421
  declare const schemaSQL: SQL[];
326
422
  declare const createEventStoreSchema: (pool: NodePostgresPool) => Promise<void>;
327
423
 
328
- declare const DefaultPostgreSQLEventStoreSubscriptionBatchSize = 100;
329
- declare const DefaultPostgreSQLEventStoreSubscriptionPullingFrequencyInMs = 50;
330
- type PostgreSQLEventStoreMessagesBatch<EventType extends Event = Event> = {
331
- messages: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[];
332
- };
333
- type PostgreSQLEventStoreMessagesBatchHandlerResult = void | {
334
- type: 'STOP';
335
- reason?: string;
336
- error?: EmmettError;
337
- };
338
- type PostgreSQLEventStoreMessagesBatchHandler<EventType extends Event = Event> = (messagesBatch: PostgreSQLEventStoreMessagesBatch<EventType>) => Promise<PostgreSQLEventStoreMessagesBatchHandlerResult> | PostgreSQLEventStoreMessagesBatchHandlerResult;
339
- type PostgreSQLEventStoreMessageBatchPullerOptions<EventType extends Event = Event> = {
340
- executor: SQLExecutor;
341
- pullingFrequencyInMs: number;
342
- batchSize: number;
343
- eachBatch: PostgreSQLEventStoreMessagesBatchHandler<EventType>;
344
- };
345
- type PostgreSQLEventStoreMessageBatchPullerStartFrom = {
346
- globalPosition: bigint;
347
- } | 'BEGINNING' | 'END';
348
- type PostgreSQLEventStoreMessageBatchPullerStartOptions = {
349
- startFrom: PostgreSQLEventStoreMessageBatchPullerStartFrom;
350
- };
351
- type PostgreSQLEventStoreMessageBatchPuller = {
352
- isRunning: boolean;
353
- start(options: PostgreSQLEventStoreMessageBatchPullerStartOptions): Promise<void>;
354
- stop(): Promise<void>;
355
- };
356
- declare const postgreSQLEventStoreMessageBatchPuller: <EventType extends Event = Event>({ executor, batchSize, eachBatch, pullingFrequencyInMs, }: PostgreSQLEventStoreMessageBatchPullerOptions<EventType>) => PostgreSQLEventStoreMessageBatchPuller;
357
- declare const zipPostgreSQLEventStoreMessageBatchPullerStartFrom: (options: (PostgreSQLEventStoreMessageBatchPullerStartFrom | undefined)[]) => PostgreSQLEventStoreMessageBatchPullerStartFrom;
358
-
359
- type PostgreSQLEventStoreSubscriptionEventsBatch<EventType extends Event = Event> = {
360
- messages: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[];
361
- };
362
- type PostgreSQLEventStoreSubscription<EventType extends Event = Event> = {
363
- id: string;
364
- start: (execute: SQLExecutor) => Promise<PostgreSQLEventStoreMessageBatchPullerStartFrom | undefined>;
365
- isActive: boolean;
366
- handle: (messagesBatch: PostgreSQLEventStoreSubscriptionEventsBatch<EventType>, context: {
367
- pool: Dumbo;
368
- }) => Promise<PostgreSQLEventStoreSubscriptionMessageHandlerResult>;
369
- };
370
- declare const PostgreSQLEventStoreSubscription: {
371
- result: {
372
- skip: (options?: {
373
- reason?: string;
374
- }) => PostgreSQLEventStoreSubscriptionMessageHandlerResult;
375
- stop: (options?: {
376
- reason?: string;
377
- error?: EmmettError;
378
- }) => PostgreSQLEventStoreSubscriptionMessageHandlerResult;
379
- };
380
- };
381
- type PostgreSQLEventStoreSubscriptionMessageHandlerResult = void | {
382
- type: 'SKIP';
383
- reason?: string;
384
- } | {
385
- type: 'STOP';
386
- reason?: string;
387
- error?: EmmettError;
388
- };
389
- type PostgreSQLEventStoreSubscriptionEachMessageHandler<EventType extends Event = Event> = (event: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => Promise<PostgreSQLEventStoreSubscriptionMessageHandlerResult> | PostgreSQLEventStoreSubscriptionMessageHandlerResult;
390
- type PostgreSQLEventStoreSubscriptionStartFrom = PostgreSQLEventStoreMessageBatchPullerStartFrom | 'CURRENT';
391
- type PostgreSQLEventStoreSubscriptionOptions<EventType extends Event = Event> = {
392
- subscriptionId: string;
393
- version?: number;
394
- partition?: string;
395
- startFrom?: PostgreSQLEventStoreSubscriptionStartFrom;
396
- stopAfter?: (message: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => boolean;
397
- eachMessage: PostgreSQLEventStoreSubscriptionEachMessageHandler<EventType>;
398
- };
399
- declare const postgreSQLEventStoreSubscription: <EventType extends Event = Event>(options: PostgreSQLEventStoreSubscriptionOptions<EventType>) => PostgreSQLEventStoreSubscription;
400
-
401
- type PostgreSQLEventStoreConsumerOptions = {
402
- connectionString: string;
403
- subscriptions?: PostgreSQLEventStoreSubscription[];
404
- pooling?: {
405
- batchSize?: number;
406
- pullingFrequencyInMs?: number;
407
- };
408
- };
409
- type PostgreSQLEventStoreConsumer = Readonly<{
410
- connectionString: string;
411
- isRunning: boolean;
412
- subscriptions: PostgreSQLEventStoreSubscription[];
413
- subscribe: <EventType extends Event = Event>(options: PostgreSQLEventStoreSubscriptionOptions<EventType>) => PostgreSQLEventStoreSubscription<EventType>;
414
- start: () => Promise<void>;
415
- stop: () => Promise<void>;
416
- close: () => Promise<void>;
417
- }>;
418
- declare const postgreSQLEventStoreConsumer: (options: PostgreSQLEventStoreConsumerOptions) => PostgreSQLEventStoreConsumer;
419
-
420
- export { type AppendToStreamPreCommitHook, DefaultPostgreSQLEventStoreSubscriptionBatchSize, DefaultPostgreSQLEventStoreSubscriptionPullingFrequencyInMs, type PongoAssertOptions, type PongoDocumentEvolve, type PongoMultiStreamProjectionOptions, type PongoProjectionHandlerContext, type PongoProjectionOptions, type PongoSingleStreamProjectionOptions, type PongoWithNotNullDocumentEvolve, type PongoWithNullableDocumentEvolve, type PostgreSQLEventStoreConsumer, type PostgreSQLEventStoreConsumerOptions, PostgreSQLEventStoreDefaultStreamVersion, type PostgreSQLEventStoreMessageBatchPuller, type PostgreSQLEventStoreMessageBatchPullerOptions, type PostgreSQLEventStoreMessageBatchPullerStartFrom, type PostgreSQLEventStoreMessageBatchPullerStartOptions, type PostgreSQLEventStoreMessagesBatch, type PostgreSQLEventStoreMessagesBatchHandler, type PostgreSQLEventStoreMessagesBatchHandlerResult, PostgreSQLEventStoreSubscription, type PostgreSQLEventStoreSubscriptionEachMessageHandler, type PostgreSQLEventStoreSubscriptionEventsBatch, type PostgreSQLEventStoreSubscriptionMessageHandlerResult, type PostgreSQLEventStoreSubscriptionOptions, type PostgreSQLEventStoreSubscriptionStartFrom, 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 ProjectionHandlerOptions, type ReadLastMessageGlobalPositionResult, type ReadMessagesBatchOptions, type ReadMessagesBatchResult, type ReadSubscriptionCheckpointResult, type StoreLastProcessedSubscriptionPositionResult, 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, postgreSQLEventStoreSubscription, postgreSQLProjection, postgreSQLRawBatchSQLProjection, postgreSQLRawSQLProjection, readLastMessageGlobalPosition, readMessagesBatch, readStream, readSubscriptionCheckpoint, sanitizeNameSQL, schemaSQL, storeSubscriptionCheckpoint, storeSubscriptionCheckpointSQL, streamsTable, streamsTableSQL, subscriptionsTable, subscriptionsTableSQL, zipPostgreSQLEventStoreMessageBatchPullerStartFrom };
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 ProjectionHandlerOptions, 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, postgreSQLRawBatchSQLProjection, postgreSQLRawSQLProjection, readLastMessageGlobalPosition, readMessagesBatch, readProcessorCheckpoint, readStream, sanitizeNameSQL, schemaSQL, storeProcessorCheckpoint, storeSubscriptionCheckpointSQL, streamsTable, streamsTableSQL, subscriptionsTable, subscriptionsTableSQL, zipPostgreSQLEventStoreMessageBatchPullerStartFrom };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,104 @@
1
1
  import * as _event_driven_io_dumbo from '@event-driven-io/dumbo';
2
- import { Dumbo, DumboOptions, QueryResultRow, SQL, NodePostgresClient, SQLExecutor, NodePostgresTransaction, MigrationStyle, NodePostgresConnector, NodePostgresPoolClientConnection, NodePostgresClientConnection, NodePostgresPool } from '@event-driven-io/dumbo';
3
- import { Event, ReadEvent, CanHandle, ThenThrows, ProjectionHandler, TypedProjectionDefinition, EventStore, EventStoreSessionFactory, AppendToStreamOptions, AppendToStreamResultWithGlobalPosition, ReadEventMetadataWithGlobalPosition, ProjectionRegistration, ReadEventMetadata, ReadStreamOptions, ReadStreamResult, EmmettError } from '@event-driven-io/emmett';
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, TypedProjectionDefinition, 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
 
7
+ declare const DefaultPostgreSQLEventStoreProcessorBatchSize = 100;
8
+ declare const DefaultPostgreSQLEventStoreProcessorPullingFrequencyInMs = 50;
9
+ type PostgreSQLEventStoreMessagesBatch<EventType extends Event = Event> = {
10
+ messages: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[];
11
+ };
12
+ type PostgreSQLEventStoreMessagesBatchHandlerResult = void | {
13
+ type: 'STOP';
14
+ reason?: string;
15
+ error?: EmmettError;
16
+ };
17
+ type PostgreSQLEventStoreMessagesBatchHandler<EventType extends Event = Event> = (messagesBatch: PostgreSQLEventStoreMessagesBatch<EventType>) => Promise<PostgreSQLEventStoreMessagesBatchHandlerResult> | PostgreSQLEventStoreMessagesBatchHandlerResult;
18
+ type PostgreSQLEventStoreMessageBatchPullerOptions<EventType extends Event = Event> = {
19
+ executor: SQLExecutor;
20
+ pullingFrequencyInMs: number;
21
+ batchSize: number;
22
+ eachBatch: PostgreSQLEventStoreMessagesBatchHandler<EventType>;
23
+ };
24
+ type PostgreSQLEventStoreMessageBatchPullerStartFrom = {
25
+ globalPosition: bigint;
26
+ } | 'BEGINNING' | 'END';
27
+ type PostgreSQLEventStoreMessageBatchPullerStartOptions = {
28
+ startFrom: PostgreSQLEventStoreMessageBatchPullerStartFrom;
29
+ };
30
+ type PostgreSQLEventStoreMessageBatchPuller = {
31
+ isRunning: boolean;
32
+ start(options: PostgreSQLEventStoreMessageBatchPullerStartOptions): Promise<void>;
33
+ stop(): Promise<void>;
34
+ };
35
+ declare const postgreSQLEventStoreMessageBatchPuller: <EventType extends Event = Event>({ executor, batchSize, eachBatch, pullingFrequencyInMs, }: PostgreSQLEventStoreMessageBatchPullerOptions<EventType>) => PostgreSQLEventStoreMessageBatchPuller;
36
+ declare const zipPostgreSQLEventStoreMessageBatchPullerStartFrom: (options: (PostgreSQLEventStoreMessageBatchPullerStartFrom | undefined)[]) => PostgreSQLEventStoreMessageBatchPullerStartFrom;
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
+
7
102
  type PongoAssertOptions = {
8
103
  inCollection: string;
9
104
  inDatabase?: string;
@@ -125,6 +220,7 @@ declare const postgreSQLRawSQLProjection: <EventType extends Event>(handle: (eve
125
220
 
126
221
  interface PostgresEventStore extends EventStore<PostgresReadEventMetadata>, EventStoreSessionFactory<PostgresEventStore> {
127
222
  appendToStream<EventType extends Event>(streamName: string, events: EventType[], options?: AppendToStreamOptions): Promise<AppendToStreamResultWithGlobalPosition>;
223
+ consumer<ConsumerEventType extends Event = Event>(options: PostgreSQLEventStoreConsumerConfig<ConsumerEventType>): PostgreSQLEventStoreConsumer<ConsumerEventType>;
128
224
  close(): Promise<void>;
129
225
  schema: {
130
226
  sql(): string;
@@ -246,36 +342,36 @@ declare const readStream: <EventType extends Event>(execute: SQLExecutor, stream
246
342
  partition?: string;
247
343
  }) => Promise<ReadStreamResult<EventType, ReadEventMetadataWithGlobalPosition>>;
248
344
 
249
- type ReadSubscriptionCheckpointResult = {
345
+ type ReadProcessorCheckpointResult = {
250
346
  lastProcessedPosition: bigint | null;
251
347
  };
252
- declare const readSubscriptionCheckpoint: (execute: SQLExecutor, options: {
253
- subscriptionId: string;
348
+ declare const readProcessorCheckpoint: (execute: SQLExecutor, options: {
349
+ processorId: string;
254
350
  partition?: string;
255
- }) => Promise<ReadSubscriptionCheckpointResult>;
351
+ }) => Promise<ReadProcessorCheckpointResult>;
256
352
 
257
353
  declare const storeSubscriptionCheckpointSQL: _event_driven_io_dumbo.SQL;
258
- type StoreLastProcessedSubscriptionPositionResult<Position extends bigint | null = bigint> = {
354
+ type StoreLastProcessedProcessorPositionResult<Position extends bigint | null = bigint> = {
259
355
  success: true;
260
356
  newPosition: Position;
261
357
  } | {
262
358
  success: false;
263
359
  reason: 'IGNORED' | 'MISMATCH';
264
360
  };
265
- declare function storeSubscriptionCheckpoint(execute: SQLExecutor, options: {
266
- subscriptionId: string;
361
+ declare function storeProcessorCheckpoint(execute: SQLExecutor, options: {
362
+ processorId: string;
267
363
  version: number | undefined;
268
364
  newPosition: bigint | null;
269
365
  lastProcessedPosition: bigint | null;
270
366
  partition?: string;
271
- }): Promise<StoreLastProcessedSubscriptionPositionResult<bigint | null>>;
272
- declare function storeSubscriptionCheckpoint(execute: SQLExecutor, options: {
273
- subscriptionId: string;
367
+ }): Promise<StoreLastProcessedProcessorPositionResult<bigint | null>>;
368
+ declare function storeProcessorCheckpoint(execute: SQLExecutor, options: {
369
+ processorId: string;
274
370
  version: number | undefined;
275
371
  newPosition: bigint;
276
372
  lastProcessedPosition: bigint | null;
277
373
  partition?: string;
278
- }): Promise<StoreLastProcessedSubscriptionPositionResult<bigint>>;
374
+ }): Promise<StoreLastProcessedProcessorPositionResult<bigint>>;
279
375
 
280
376
  declare const streamsTableSQL: _event_driven_io_dumbo.SQL;
281
377
  declare const eventsTableSQL: _event_driven_io_dumbo.SQL;
@@ -325,96 +421,4 @@ declare const subscriptionsTable: {
325
421
  declare const schemaSQL: SQL[];
326
422
  declare const createEventStoreSchema: (pool: NodePostgresPool) => Promise<void>;
327
423
 
328
- declare const DefaultPostgreSQLEventStoreSubscriptionBatchSize = 100;
329
- declare const DefaultPostgreSQLEventStoreSubscriptionPullingFrequencyInMs = 50;
330
- type PostgreSQLEventStoreMessagesBatch<EventType extends Event = Event> = {
331
- messages: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[];
332
- };
333
- type PostgreSQLEventStoreMessagesBatchHandlerResult = void | {
334
- type: 'STOP';
335
- reason?: string;
336
- error?: EmmettError;
337
- };
338
- type PostgreSQLEventStoreMessagesBatchHandler<EventType extends Event = Event> = (messagesBatch: PostgreSQLEventStoreMessagesBatch<EventType>) => Promise<PostgreSQLEventStoreMessagesBatchHandlerResult> | PostgreSQLEventStoreMessagesBatchHandlerResult;
339
- type PostgreSQLEventStoreMessageBatchPullerOptions<EventType extends Event = Event> = {
340
- executor: SQLExecutor;
341
- pullingFrequencyInMs: number;
342
- batchSize: number;
343
- eachBatch: PostgreSQLEventStoreMessagesBatchHandler<EventType>;
344
- };
345
- type PostgreSQLEventStoreMessageBatchPullerStartFrom = {
346
- globalPosition: bigint;
347
- } | 'BEGINNING' | 'END';
348
- type PostgreSQLEventStoreMessageBatchPullerStartOptions = {
349
- startFrom: PostgreSQLEventStoreMessageBatchPullerStartFrom;
350
- };
351
- type PostgreSQLEventStoreMessageBatchPuller = {
352
- isRunning: boolean;
353
- start(options: PostgreSQLEventStoreMessageBatchPullerStartOptions): Promise<void>;
354
- stop(): Promise<void>;
355
- };
356
- declare const postgreSQLEventStoreMessageBatchPuller: <EventType extends Event = Event>({ executor, batchSize, eachBatch, pullingFrequencyInMs, }: PostgreSQLEventStoreMessageBatchPullerOptions<EventType>) => PostgreSQLEventStoreMessageBatchPuller;
357
- declare const zipPostgreSQLEventStoreMessageBatchPullerStartFrom: (options: (PostgreSQLEventStoreMessageBatchPullerStartFrom | undefined)[]) => PostgreSQLEventStoreMessageBatchPullerStartFrom;
358
-
359
- type PostgreSQLEventStoreSubscriptionEventsBatch<EventType extends Event = Event> = {
360
- messages: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[];
361
- };
362
- type PostgreSQLEventStoreSubscription<EventType extends Event = Event> = {
363
- id: string;
364
- start: (execute: SQLExecutor) => Promise<PostgreSQLEventStoreMessageBatchPullerStartFrom | undefined>;
365
- isActive: boolean;
366
- handle: (messagesBatch: PostgreSQLEventStoreSubscriptionEventsBatch<EventType>, context: {
367
- pool: Dumbo;
368
- }) => Promise<PostgreSQLEventStoreSubscriptionMessageHandlerResult>;
369
- };
370
- declare const PostgreSQLEventStoreSubscription: {
371
- result: {
372
- skip: (options?: {
373
- reason?: string;
374
- }) => PostgreSQLEventStoreSubscriptionMessageHandlerResult;
375
- stop: (options?: {
376
- reason?: string;
377
- error?: EmmettError;
378
- }) => PostgreSQLEventStoreSubscriptionMessageHandlerResult;
379
- };
380
- };
381
- type PostgreSQLEventStoreSubscriptionMessageHandlerResult = void | {
382
- type: 'SKIP';
383
- reason?: string;
384
- } | {
385
- type: 'STOP';
386
- reason?: string;
387
- error?: EmmettError;
388
- };
389
- type PostgreSQLEventStoreSubscriptionEachMessageHandler<EventType extends Event = Event> = (event: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => Promise<PostgreSQLEventStoreSubscriptionMessageHandlerResult> | PostgreSQLEventStoreSubscriptionMessageHandlerResult;
390
- type PostgreSQLEventStoreSubscriptionStartFrom = PostgreSQLEventStoreMessageBatchPullerStartFrom | 'CURRENT';
391
- type PostgreSQLEventStoreSubscriptionOptions<EventType extends Event = Event> = {
392
- subscriptionId: string;
393
- version?: number;
394
- partition?: string;
395
- startFrom?: PostgreSQLEventStoreSubscriptionStartFrom;
396
- stopAfter?: (message: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => boolean;
397
- eachMessage: PostgreSQLEventStoreSubscriptionEachMessageHandler<EventType>;
398
- };
399
- declare const postgreSQLEventStoreSubscription: <EventType extends Event = Event>(options: PostgreSQLEventStoreSubscriptionOptions<EventType>) => PostgreSQLEventStoreSubscription;
400
-
401
- type PostgreSQLEventStoreConsumerOptions = {
402
- connectionString: string;
403
- subscriptions?: PostgreSQLEventStoreSubscription[];
404
- pooling?: {
405
- batchSize?: number;
406
- pullingFrequencyInMs?: number;
407
- };
408
- };
409
- type PostgreSQLEventStoreConsumer = Readonly<{
410
- connectionString: string;
411
- isRunning: boolean;
412
- subscriptions: PostgreSQLEventStoreSubscription[];
413
- subscribe: <EventType extends Event = Event>(options: PostgreSQLEventStoreSubscriptionOptions<EventType>) => PostgreSQLEventStoreSubscription<EventType>;
414
- start: () => Promise<void>;
415
- stop: () => Promise<void>;
416
- close: () => Promise<void>;
417
- }>;
418
- declare const postgreSQLEventStoreConsumer: (options: PostgreSQLEventStoreConsumerOptions) => PostgreSQLEventStoreConsumer;
419
-
420
- export { type AppendToStreamPreCommitHook, DefaultPostgreSQLEventStoreSubscriptionBatchSize, DefaultPostgreSQLEventStoreSubscriptionPullingFrequencyInMs, type PongoAssertOptions, type PongoDocumentEvolve, type PongoMultiStreamProjectionOptions, type PongoProjectionHandlerContext, type PongoProjectionOptions, type PongoSingleStreamProjectionOptions, type PongoWithNotNullDocumentEvolve, type PongoWithNullableDocumentEvolve, type PostgreSQLEventStoreConsumer, type PostgreSQLEventStoreConsumerOptions, PostgreSQLEventStoreDefaultStreamVersion, type PostgreSQLEventStoreMessageBatchPuller, type PostgreSQLEventStoreMessageBatchPullerOptions, type PostgreSQLEventStoreMessageBatchPullerStartFrom, type PostgreSQLEventStoreMessageBatchPullerStartOptions, type PostgreSQLEventStoreMessagesBatch, type PostgreSQLEventStoreMessagesBatchHandler, type PostgreSQLEventStoreMessagesBatchHandlerResult, PostgreSQLEventStoreSubscription, type PostgreSQLEventStoreSubscriptionEachMessageHandler, type PostgreSQLEventStoreSubscriptionEventsBatch, type PostgreSQLEventStoreSubscriptionMessageHandlerResult, type PostgreSQLEventStoreSubscriptionOptions, type PostgreSQLEventStoreSubscriptionStartFrom, 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 ProjectionHandlerOptions, type ReadLastMessageGlobalPositionResult, type ReadMessagesBatchOptions, type ReadMessagesBatchResult, type ReadSubscriptionCheckpointResult, type StoreLastProcessedSubscriptionPositionResult, 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, postgreSQLEventStoreSubscription, postgreSQLProjection, postgreSQLRawBatchSQLProjection, postgreSQLRawSQLProjection, readLastMessageGlobalPosition, readMessagesBatch, readStream, readSubscriptionCheckpoint, sanitizeNameSQL, schemaSQL, storeSubscriptionCheckpoint, storeSubscriptionCheckpointSQL, streamsTable, streamsTableSQL, subscriptionsTable, subscriptionsTableSQL, zipPostgreSQLEventStoreMessageBatchPullerStartFrom };
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 ProjectionHandlerOptions, 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, postgreSQLRawBatchSQLProjection, postgreSQLRawSQLProjection, readLastMessageGlobalPosition, readMessagesBatch, readProcessorCheckpoint, readStream, sanitizeNameSQL, schemaSQL, storeProcessorCheckpoint, storeSubscriptionCheckpointSQL, streamsTable, streamsTableSQL, subscriptionsTable, subscriptionsTableSQL, zipPostgreSQLEventStoreMessageBatchPullerStartFrom };