@event-driven-io/emmett-sqlite 0.43.0-beta.6 → 0.43.0-beta.7

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,7 +1,8 @@
1
- import { a as SQLiteEventStore, b as SQLiteReadEventMetadata, A as AnyEventStoreDriver, c as SQLiteProjectionDefinition, I as InferOptionsFromEventStoreDriver } from './sqliteProjection-D6WKeuhb.cjs';
2
- export { C as CreateEventStoreSchemaOptions, d as EventHandler, e as EventStoreSchemaMigrationOptions, f as SQLiteEventStoreDefaultStreamVersion, S as SQLiteEventStoreOptions, g as SQLiteProjectionHandler, h as SQLiteProjectionHandlerContext, i as SQLiteProjectionHandlerOptions, j as SQLiteRawBatchSQLProjection, k as SQLiteRawSQLProjection, l as SQLiteReadEvent, m as SQLiteStreamExistsOptions, n as createEventStoreSchema, o as getSQLiteEventStore, p as handleProjections, q as messagesTableSQL, r as processorsTableSQL, s as projectionsTableSQL, t as schemaSQL, u as sqliteProjection, v as sqliteRawBatchSQLProjection, w as sqliteRawSQLProjection, x as streamExists, y as streamsTableSQL } from './sqliteProjection-D6WKeuhb.cjs';
3
1
  import * as _event_driven_io_emmett from '@event-driven-io/emmett';
4
- import { Event, AppendToStreamOptions, BeforeEventStoreCommitHandler, Message, RecordedMessageMetadata, RecordedMessage, RecordedMessageMetadataWithGlobalPosition, ProcessorCheckpoint, ReadStreamOptions, ReadStreamResult, ReadEventMetadataWithGlobalPosition, ThenThrows } from '@event-driven-io/emmett';
2
+ import { Event, AppendToStreamOptions, BeforeEventStoreCommitHandler, Message, RecordedMessageMetadata, RecordedMessage, RecordedMessageMetadataWithGlobalPosition, ProcessorCheckpoint, ReadStreamOptions, ReadStreamResult, ReadEventMetadataWithGlobalPosition, ReadEvent, CanHandle, EventStoreReadSchemaOptions, TruncateProjection, ThenThrows } from '@event-driven-io/emmett';
3
+ import { PongoDocument, PongoDBCollectionOptions, PongoClient, WithId, PongoFilter } from '@event-driven-io/pongo';
4
+ import { a as SQLiteEventStore, b as SQLiteReadEventMetadata, c as SQLiteProjectionHandlerContext, d as SQLiteProjectionDefinition, A as AnyEventStoreDriver, I as InferOptionsFromEventStoreDriver } from './sqliteProjection-BZi2wy1K.cjs';
5
+ export { C as CreateEventStoreSchemaOptions, e as EventHandler, f as EventStoreSchemaMigrationOptions, g as SQLiteEventStoreDefaultStreamVersion, S as SQLiteEventStoreOptions, h as SQLiteProjectionHandler, i as SQLiteProjectionHandlerOptions, j as SQLiteRawBatchSQLProjection, k as SQLiteRawSQLProjection, l as SQLiteReadEvent, m as SQLiteStreamExistsOptions, n as createEventStoreSchema, o as getSQLiteEventStore, p as handleProjections, q as messagesTableSQL, r as processorsTableSQL, s as projectionsTableSQL, t as schemaSQL, u as sqliteProjection, v as sqliteRawBatchSQLProjection, w as sqliteRawSQLProjection, x as streamExists, y as streamsTableSQL } from './sqliteProjection-BZi2wy1K.cjs';
5
6
  import { SQL, SQLExecutor, Dumbo, QueryResultRow } from '@event-driven-io/dumbo';
6
7
  import { AnySQLiteConnection } from '@event-driven-io/dumbo/sqlite';
7
8
 
@@ -119,6 +120,89 @@ declare const projectionsTable: {
119
120
  name: string;
120
121
  };
121
122
 
123
+ type PongoProjectionHandlerContext = SQLiteProjectionHandlerContext & {
124
+ pongo: PongoClient;
125
+ };
126
+ type PongoWithNotNullDocumentEvolve<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = ((document: Document, event: ReadEvent<EventType, EventMetaDataType>) => Document | null) | ((document: Document, event: ReadEvent<EventType>) => Promise<Document | null>);
127
+ type PongoWithNullableDocumentEvolve<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = ((document: Document | null, event: ReadEvent<EventType, EventMetaDataType>) => Document | null) | ((document: Document | null, event: ReadEvent<EventType>) => Promise<Document | null>);
128
+ type PongoDocumentEvolve<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = PongoWithNotNullDocumentEvolve<Document, EventType, EventMetaDataType> | PongoWithNullableDocumentEvolve<Document, EventType, EventMetaDataType>;
129
+ type PongoProjectionOptions<EventType extends Event, EventPayloadType extends Event = EventType> = {
130
+ name: string;
131
+ kind?: string;
132
+ version?: number;
133
+ handle: (events: ReadEvent<EventType, SQLiteReadEventMetadata>[], context: PongoProjectionHandlerContext) => Promise<void>;
134
+ canHandle: CanHandle<EventType>;
135
+ truncate?: TruncateProjection<PongoProjectionHandlerContext>;
136
+ init?: (context: PongoProjectionHandlerContext) => void | Promise<void>;
137
+ eventsOptions?: {
138
+ schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
139
+ };
140
+ };
141
+ declare const pongoProjection: <EventType extends Event, EventPayloadType extends Event = EventType>({ name, kind, version, truncate, handle, canHandle, eventsOptions, }: PongoProjectionOptions<EventType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
142
+ type PongoMultiStreamProjectionOptions<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata, EventPayloadType extends Event = EventType, DocumentPayload extends PongoDocument = Document> = {
143
+ kind?: string;
144
+ canHandle: CanHandle<EventType>;
145
+ version?: number;
146
+ collectionName: string;
147
+ collectionOptions?: PongoDBCollectionOptions<Document, DocumentPayload>;
148
+ eventsOptions?: {
149
+ schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
150
+ };
151
+ getDocumentId: (event: ReadEvent<EventType>) => string;
152
+ } & ({
153
+ evolve: PongoWithNullableDocumentEvolve<Document, EventType, EventMetaDataType>;
154
+ } | {
155
+ evolve: PongoWithNotNullDocumentEvolve<Document, EventType, EventMetaDataType>;
156
+ initialState: () => Document;
157
+ });
158
+ declare const pongoMultiStreamProjection: <Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata, EventPayloadType extends Event = EventType>(options: PongoMultiStreamProjectionOptions<Document, EventType, EventMetaDataType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
159
+ type PongoSingleStreamProjectionOptions<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata, EventPayloadType extends Event = EventType, DocumentPayload extends PongoDocument = Document> = {
160
+ canHandle: CanHandle<EventType>;
161
+ getDocumentId?: (event: ReadEvent<EventType>) => string;
162
+ version?: number;
163
+ collectionName: string;
164
+ collectionOptions?: PongoDBCollectionOptions<Document, DocumentPayload>;
165
+ eventsOptions?: {
166
+ schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
167
+ };
168
+ } & ({
169
+ evolve: PongoWithNullableDocumentEvolve<Document, EventType, EventMetaDataType>;
170
+ } | {
171
+ evolve: PongoWithNotNullDocumentEvolve<Document, EventType, EventMetaDataType>;
172
+ initialState: () => Document;
173
+ });
174
+ declare const pongoSingleStreamProjection: <Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata, EventPayloadType extends Event = EventType>(options: PongoSingleStreamProjectionOptions<Document, EventType, EventMetaDataType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
175
+
176
+ type PongoAssertOptions = {
177
+ inCollection: string;
178
+ inDatabase?: string;
179
+ };
180
+ type FilterOrId<Doc extends PongoDocument | WithId<PongoDocument>> = {
181
+ withId: string;
182
+ } | {
183
+ matchingFilter: PongoFilter<Doc>;
184
+ };
185
+ declare const documentExists: <Doc extends PongoDocument | WithId<PongoDocument>>(document: Doc, options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
186
+ declare const documentsAreTheSame: <Doc extends PongoDocument | WithId<PongoDocument>>(documents: Doc[], options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
187
+ declare const documentsMatchingHaveCount: <Doc extends PongoDocument | WithId<PongoDocument>>(expectedCount: number, options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
188
+ declare const documentMatchingExists: <Doc extends PongoDocument | WithId<PongoDocument>>(options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
189
+ declare const documentDoesNotExist: <Doc extends PongoDocument | WithId<PongoDocument>>(options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
190
+ declare const expectPongoDocuments: {
191
+ fromCollection: <Doc extends PongoDocument | WithId<PongoDocument>>(collectionName: string) => {
192
+ withId: (id: string) => {
193
+ toBeEqual: (document: Doc) => SQLiteProjectionAssert;
194
+ toExist: () => SQLiteProjectionAssert;
195
+ notToExist: () => SQLiteProjectionAssert;
196
+ };
197
+ matching: <Doc_1 extends PongoDocument | WithId<PongoDocument>>(filter: PongoFilter<Doc_1>) => {
198
+ toBeTheSame: (documents: Doc_1[]) => SQLiteProjectionAssert;
199
+ toHaveCount: (expectedCount: number) => SQLiteProjectionAssert;
200
+ toExist: () => SQLiteProjectionAssert;
201
+ notToExist: () => SQLiteProjectionAssert;
202
+ };
203
+ };
204
+ };
205
+
122
206
  type SQLiteProjectionSpecEvent<EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = EventType & {
123
207
  metadata?: Partial<EventMetaDataType>;
124
208
  };
@@ -154,4 +238,4 @@ declare const expectSQL: {
154
238
  };
155
239
  };
156
240
 
157
- export { type AppendEventResult, type ReadLastMessageGlobalPositionResult, type ReadMessagesBatchOptions, type ReadMessagesBatchResult, type ReadProcessorCheckpointResult, SQLiteEventStore, type SQLiteProjectionAssert, SQLiteProjectionDefinition, SQLiteProjectionSpec, type SQLiteProjectionSpecEvent, type SQLiteProjectionSpecOptions, type SQLiteProjectionSpecWhenOptions, SQLiteReadEventMetadata, type StoreProcessorCheckpointResult, appendToStream, assertSQLQueryResultMatches, defaultTag, emmettPrefix, eventInStream, eventsInStream, expectSQL, globalNames, globalTag, messagesTable, migration_0_42_0_FromSubscriptionsToProcessors, migration_0_42_0_SQLs, newEventsInStream, processorsTable, projectionsTable, readLastMessageGlobalPosition, readMessagesBatch, readProcessorCheckpoint, readStream, schema_0_41_0, schema_0_42_0, storeProcessorCheckpoint, streamsTable, unknownTag };
241
+ export { type AppendEventResult, type PongoAssertOptions, type PongoDocumentEvolve, type PongoMultiStreamProjectionOptions, type PongoProjectionHandlerContext, type PongoProjectionOptions, type PongoSingleStreamProjectionOptions, type PongoWithNotNullDocumentEvolve, type PongoWithNullableDocumentEvolve, type ReadLastMessageGlobalPositionResult, type ReadMessagesBatchOptions, type ReadMessagesBatchResult, type ReadProcessorCheckpointResult, SQLiteEventStore, type SQLiteProjectionAssert, SQLiteProjectionDefinition, SQLiteProjectionHandlerContext, SQLiteProjectionSpec, type SQLiteProjectionSpecEvent, type SQLiteProjectionSpecOptions, type SQLiteProjectionSpecWhenOptions, SQLiteReadEventMetadata, type StoreProcessorCheckpointResult, appendToStream, assertSQLQueryResultMatches, defaultTag, documentDoesNotExist, documentExists, documentMatchingExists, documentsAreTheSame, documentsMatchingHaveCount, emmettPrefix, eventInStream, eventsInStream, expectPongoDocuments, expectSQL, globalNames, globalTag, messagesTable, migration_0_42_0_FromSubscriptionsToProcessors, migration_0_42_0_SQLs, newEventsInStream, pongoMultiStreamProjection, pongoProjection, pongoSingleStreamProjection, processorsTable, projectionsTable, readLastMessageGlobalPosition, readMessagesBatch, readProcessorCheckpoint, readStream, schema_0_41_0, schema_0_42_0, storeProcessorCheckpoint, streamsTable, unknownTag };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { a as SQLiteEventStore, b as SQLiteReadEventMetadata, A as AnyEventStoreDriver, c as SQLiteProjectionDefinition, I as InferOptionsFromEventStoreDriver } from './sqliteProjection-D6WKeuhb.js';
2
- export { C as CreateEventStoreSchemaOptions, d as EventHandler, e as EventStoreSchemaMigrationOptions, f as SQLiteEventStoreDefaultStreamVersion, S as SQLiteEventStoreOptions, g as SQLiteProjectionHandler, h as SQLiteProjectionHandlerContext, i as SQLiteProjectionHandlerOptions, j as SQLiteRawBatchSQLProjection, k as SQLiteRawSQLProjection, l as SQLiteReadEvent, m as SQLiteStreamExistsOptions, n as createEventStoreSchema, o as getSQLiteEventStore, p as handleProjections, q as messagesTableSQL, r as processorsTableSQL, s as projectionsTableSQL, t as schemaSQL, u as sqliteProjection, v as sqliteRawBatchSQLProjection, w as sqliteRawSQLProjection, x as streamExists, y as streamsTableSQL } from './sqliteProjection-D6WKeuhb.js';
3
1
  import * as _event_driven_io_emmett from '@event-driven-io/emmett';
4
- import { Event, AppendToStreamOptions, BeforeEventStoreCommitHandler, Message, RecordedMessageMetadata, RecordedMessage, RecordedMessageMetadataWithGlobalPosition, ProcessorCheckpoint, ReadStreamOptions, ReadStreamResult, ReadEventMetadataWithGlobalPosition, ThenThrows } from '@event-driven-io/emmett';
2
+ import { Event, AppendToStreamOptions, BeforeEventStoreCommitHandler, Message, RecordedMessageMetadata, RecordedMessage, RecordedMessageMetadataWithGlobalPosition, ProcessorCheckpoint, ReadStreamOptions, ReadStreamResult, ReadEventMetadataWithGlobalPosition, ReadEvent, CanHandle, EventStoreReadSchemaOptions, TruncateProjection, ThenThrows } from '@event-driven-io/emmett';
3
+ import { PongoDocument, PongoDBCollectionOptions, PongoClient, WithId, PongoFilter } from '@event-driven-io/pongo';
4
+ import { a as SQLiteEventStore, b as SQLiteReadEventMetadata, c as SQLiteProjectionHandlerContext, d as SQLiteProjectionDefinition, A as AnyEventStoreDriver, I as InferOptionsFromEventStoreDriver } from './sqliteProjection-BZi2wy1K.js';
5
+ export { C as CreateEventStoreSchemaOptions, e as EventHandler, f as EventStoreSchemaMigrationOptions, g as SQLiteEventStoreDefaultStreamVersion, S as SQLiteEventStoreOptions, h as SQLiteProjectionHandler, i as SQLiteProjectionHandlerOptions, j as SQLiteRawBatchSQLProjection, k as SQLiteRawSQLProjection, l as SQLiteReadEvent, m as SQLiteStreamExistsOptions, n as createEventStoreSchema, o as getSQLiteEventStore, p as handleProjections, q as messagesTableSQL, r as processorsTableSQL, s as projectionsTableSQL, t as schemaSQL, u as sqliteProjection, v as sqliteRawBatchSQLProjection, w as sqliteRawSQLProjection, x as streamExists, y as streamsTableSQL } from './sqliteProjection-BZi2wy1K.js';
5
6
  import { SQL, SQLExecutor, Dumbo, QueryResultRow } from '@event-driven-io/dumbo';
6
7
  import { AnySQLiteConnection } from '@event-driven-io/dumbo/sqlite';
7
8
 
@@ -119,6 +120,89 @@ declare const projectionsTable: {
119
120
  name: string;
120
121
  };
121
122
 
123
+ type PongoProjectionHandlerContext = SQLiteProjectionHandlerContext & {
124
+ pongo: PongoClient;
125
+ };
126
+ type PongoWithNotNullDocumentEvolve<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = ((document: Document, event: ReadEvent<EventType, EventMetaDataType>) => Document | null) | ((document: Document, event: ReadEvent<EventType>) => Promise<Document | null>);
127
+ type PongoWithNullableDocumentEvolve<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = ((document: Document | null, event: ReadEvent<EventType, EventMetaDataType>) => Document | null) | ((document: Document | null, event: ReadEvent<EventType>) => Promise<Document | null>);
128
+ type PongoDocumentEvolve<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = PongoWithNotNullDocumentEvolve<Document, EventType, EventMetaDataType> | PongoWithNullableDocumentEvolve<Document, EventType, EventMetaDataType>;
129
+ type PongoProjectionOptions<EventType extends Event, EventPayloadType extends Event = EventType> = {
130
+ name: string;
131
+ kind?: string;
132
+ version?: number;
133
+ handle: (events: ReadEvent<EventType, SQLiteReadEventMetadata>[], context: PongoProjectionHandlerContext) => Promise<void>;
134
+ canHandle: CanHandle<EventType>;
135
+ truncate?: TruncateProjection<PongoProjectionHandlerContext>;
136
+ init?: (context: PongoProjectionHandlerContext) => void | Promise<void>;
137
+ eventsOptions?: {
138
+ schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
139
+ };
140
+ };
141
+ declare const pongoProjection: <EventType extends Event, EventPayloadType extends Event = EventType>({ name, kind, version, truncate, handle, canHandle, eventsOptions, }: PongoProjectionOptions<EventType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
142
+ type PongoMultiStreamProjectionOptions<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata, EventPayloadType extends Event = EventType, DocumentPayload extends PongoDocument = Document> = {
143
+ kind?: string;
144
+ canHandle: CanHandle<EventType>;
145
+ version?: number;
146
+ collectionName: string;
147
+ collectionOptions?: PongoDBCollectionOptions<Document, DocumentPayload>;
148
+ eventsOptions?: {
149
+ schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
150
+ };
151
+ getDocumentId: (event: ReadEvent<EventType>) => string;
152
+ } & ({
153
+ evolve: PongoWithNullableDocumentEvolve<Document, EventType, EventMetaDataType>;
154
+ } | {
155
+ evolve: PongoWithNotNullDocumentEvolve<Document, EventType, EventMetaDataType>;
156
+ initialState: () => Document;
157
+ });
158
+ declare const pongoMultiStreamProjection: <Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata, EventPayloadType extends Event = EventType>(options: PongoMultiStreamProjectionOptions<Document, EventType, EventMetaDataType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
159
+ type PongoSingleStreamProjectionOptions<Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata, EventPayloadType extends Event = EventType, DocumentPayload extends PongoDocument = Document> = {
160
+ canHandle: CanHandle<EventType>;
161
+ getDocumentId?: (event: ReadEvent<EventType>) => string;
162
+ version?: number;
163
+ collectionName: string;
164
+ collectionOptions?: PongoDBCollectionOptions<Document, DocumentPayload>;
165
+ eventsOptions?: {
166
+ schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
167
+ };
168
+ } & ({
169
+ evolve: PongoWithNullableDocumentEvolve<Document, EventType, EventMetaDataType>;
170
+ } | {
171
+ evolve: PongoWithNotNullDocumentEvolve<Document, EventType, EventMetaDataType>;
172
+ initialState: () => Document;
173
+ });
174
+ declare const pongoSingleStreamProjection: <Document extends PongoDocument, EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata, EventPayloadType extends Event = EventType>(options: PongoSingleStreamProjectionOptions<Document, EventType, EventMetaDataType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
175
+
176
+ type PongoAssertOptions = {
177
+ inCollection: string;
178
+ inDatabase?: string;
179
+ };
180
+ type FilterOrId<Doc extends PongoDocument | WithId<PongoDocument>> = {
181
+ withId: string;
182
+ } | {
183
+ matchingFilter: PongoFilter<Doc>;
184
+ };
185
+ declare const documentExists: <Doc extends PongoDocument | WithId<PongoDocument>>(document: Doc, options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
186
+ declare const documentsAreTheSame: <Doc extends PongoDocument | WithId<PongoDocument>>(documents: Doc[], options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
187
+ declare const documentsMatchingHaveCount: <Doc extends PongoDocument | WithId<PongoDocument>>(expectedCount: number, options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
188
+ declare const documentMatchingExists: <Doc extends PongoDocument | WithId<PongoDocument>>(options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
189
+ declare const documentDoesNotExist: <Doc extends PongoDocument | WithId<PongoDocument>>(options: PongoAssertOptions & FilterOrId<Doc>) => SQLiteProjectionAssert;
190
+ declare const expectPongoDocuments: {
191
+ fromCollection: <Doc extends PongoDocument | WithId<PongoDocument>>(collectionName: string) => {
192
+ withId: (id: string) => {
193
+ toBeEqual: (document: Doc) => SQLiteProjectionAssert;
194
+ toExist: () => SQLiteProjectionAssert;
195
+ notToExist: () => SQLiteProjectionAssert;
196
+ };
197
+ matching: <Doc_1 extends PongoDocument | WithId<PongoDocument>>(filter: PongoFilter<Doc_1>) => {
198
+ toBeTheSame: (documents: Doc_1[]) => SQLiteProjectionAssert;
199
+ toHaveCount: (expectedCount: number) => SQLiteProjectionAssert;
200
+ toExist: () => SQLiteProjectionAssert;
201
+ notToExist: () => SQLiteProjectionAssert;
202
+ };
203
+ };
204
+ };
205
+
122
206
  type SQLiteProjectionSpecEvent<EventType extends Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = EventType & {
123
207
  metadata?: Partial<EventMetaDataType>;
124
208
  };
@@ -154,4 +238,4 @@ declare const expectSQL: {
154
238
  };
155
239
  };
156
240
 
157
- export { type AppendEventResult, type ReadLastMessageGlobalPositionResult, type ReadMessagesBatchOptions, type ReadMessagesBatchResult, type ReadProcessorCheckpointResult, SQLiteEventStore, type SQLiteProjectionAssert, SQLiteProjectionDefinition, SQLiteProjectionSpec, type SQLiteProjectionSpecEvent, type SQLiteProjectionSpecOptions, type SQLiteProjectionSpecWhenOptions, SQLiteReadEventMetadata, type StoreProcessorCheckpointResult, appendToStream, assertSQLQueryResultMatches, defaultTag, emmettPrefix, eventInStream, eventsInStream, expectSQL, globalNames, globalTag, messagesTable, migration_0_42_0_FromSubscriptionsToProcessors, migration_0_42_0_SQLs, newEventsInStream, processorsTable, projectionsTable, readLastMessageGlobalPosition, readMessagesBatch, readProcessorCheckpoint, readStream, schema_0_41_0, schema_0_42_0, storeProcessorCheckpoint, streamsTable, unknownTag };
241
+ export { type AppendEventResult, type PongoAssertOptions, type PongoDocumentEvolve, type PongoMultiStreamProjectionOptions, type PongoProjectionHandlerContext, type PongoProjectionOptions, type PongoSingleStreamProjectionOptions, type PongoWithNotNullDocumentEvolve, type PongoWithNullableDocumentEvolve, type ReadLastMessageGlobalPositionResult, type ReadMessagesBatchOptions, type ReadMessagesBatchResult, type ReadProcessorCheckpointResult, SQLiteEventStore, type SQLiteProjectionAssert, SQLiteProjectionDefinition, SQLiteProjectionHandlerContext, SQLiteProjectionSpec, type SQLiteProjectionSpecEvent, type SQLiteProjectionSpecOptions, type SQLiteProjectionSpecWhenOptions, SQLiteReadEventMetadata, type StoreProcessorCheckpointResult, appendToStream, assertSQLQueryResultMatches, defaultTag, documentDoesNotExist, documentExists, documentMatchingExists, documentsAreTheSame, documentsMatchingHaveCount, emmettPrefix, eventInStream, eventsInStream, expectPongoDocuments, expectSQL, globalNames, globalTag, messagesTable, migration_0_42_0_FromSubscriptionsToProcessors, migration_0_42_0_SQLs, newEventsInStream, pongoMultiStreamProjection, pongoProjection, pongoSingleStreamProjection, processorsTable, projectionsTable, readLastMessageGlobalPosition, readMessagesBatch, readProcessorCheckpoint, readStream, schema_0_41_0, schema_0_42_0, storeProcessorCheckpoint, streamsTable, unknownTag };
package/dist/index.js CHANGED
@@ -1,3 +1,130 @@
1
+ // src/eventStore/projections/pongo/pongoProjections.ts
2
+ import {
3
+ pongoClient
4
+ } from "@event-driven-io/pongo";
5
+ var pongoProjection = ({
6
+ name,
7
+ kind,
8
+ version,
9
+ truncate,
10
+ handle,
11
+ canHandle,
12
+ eventsOptions
13
+ }) => sqliteProjection({
14
+ name,
15
+ version,
16
+ kind: kind ?? "emt:projections:postgresql:pongo:generic",
17
+ canHandle,
18
+ eventsOptions,
19
+ handle: async (events, context) => {
20
+ const { connection } = context;
21
+ const driver = await pongoDriverRegistry.tryResolve(
22
+ context.driverType
23
+ );
24
+ const pongo = pongoClient({
25
+ driver,
26
+ connectionOptions: { connection }
27
+ });
28
+ try {
29
+ await handle(events, {
30
+ ...context,
31
+ pongo
32
+ });
33
+ } finally {
34
+ await pongo.close();
35
+ }
36
+ },
37
+ truncate: truncate ? async (context) => {
38
+ const { connection } = context;
39
+ const driver = await pongoDriverRegistry.tryResolve(
40
+ context.driverType
41
+ );
42
+ const pongo = pongoClient({
43
+ driver,
44
+ connectionOptions: { connection }
45
+ });
46
+ try {
47
+ await truncate({
48
+ ...context,
49
+ pongo
50
+ });
51
+ } finally {
52
+ await pongo.close();
53
+ }
54
+ } : void 0
55
+ });
56
+ var pongoMultiStreamProjection = (options) => {
57
+ const { collectionName, getDocumentId, canHandle } = options;
58
+ const collectionNameWithVersion = options.version && options.version > 0 ? `${collectionName}_v${options.version}` : collectionName;
59
+ return pongoProjection({
60
+ name: collectionNameWithVersion,
61
+ version: options.version,
62
+ kind: options.kind ?? "emt:projections:postgresql:pongo:multi_stream",
63
+ eventsOptions: options.eventsOptions,
64
+ handle: async (events, { pongo }) => {
65
+ const collection = pongo.db().collection(
66
+ collectionNameWithVersion,
67
+ options.collectionOptions
68
+ );
69
+ for (const event of events) {
70
+ await collection.handle(getDocumentId(event), async (document) => {
71
+ return "initialState" in options ? await options.evolve(
72
+ document ?? options.initialState(),
73
+ event
74
+ ) : await options.evolve(
75
+ document,
76
+ event
77
+ );
78
+ });
79
+ }
80
+ },
81
+ canHandle,
82
+ truncate: async (context) => {
83
+ const { connection } = context;
84
+ const driver = await pongoDriverRegistry.tryResolve(
85
+ context.driverType
86
+ );
87
+ const pongo = pongoClient({
88
+ driver,
89
+ connectionOptions: { connection }
90
+ });
91
+ try {
92
+ await pongo.db().collection(
93
+ collectionNameWithVersion,
94
+ options.collectionOptions
95
+ ).deleteMany();
96
+ } finally {
97
+ await pongo.close();
98
+ }
99
+ },
100
+ init: async (context) => {
101
+ const { connection } = context;
102
+ const driver = await pongoDriverRegistry.tryResolve(
103
+ context.driverType
104
+ );
105
+ const pongo = pongoClient({
106
+ connectionOptions: { connection },
107
+ driver
108
+ });
109
+ try {
110
+ await pongo.db().collection(
111
+ collectionNameWithVersion,
112
+ options.collectionOptions
113
+ ).schema.migrate();
114
+ } finally {
115
+ await pongo.close();
116
+ }
117
+ }
118
+ });
119
+ };
120
+ var pongoSingleStreamProjection = (options) => {
121
+ return pongoMultiStreamProjection({
122
+ ...options,
123
+ kind: "emt:projections:postgresql:pongo:single_stream",
124
+ getDocumentId: options.getDocumentId ?? ((event) => event.metadata.streamName)
125
+ });
126
+ };
127
+
1
128
  // ../emmett/dist/chunk-AZDDB5SF.js
2
129
  var isNumber = (val) => typeof val === "number" && val === val;
3
130
  var isString = (val) => typeof val === "string";
@@ -560,6 +687,15 @@ var isSubset = (superObj, subObj) => {
560
687
  var assertFails = (message2) => {
561
688
  throw new AssertionError(message2 ?? "That should not ever happened, right?");
562
689
  };
690
+ var assertDeepEqual = (actual, expected, message2) => {
691
+ if (!deepEquals(actual, expected))
692
+ throw new AssertionError(
693
+ message2 ?? `subObj:
694
+ ${JSONParser.stringify(expected)}
695
+ is not equal to
696
+ ${JSONParser.stringify(actual)}`
697
+ );
698
+ };
563
699
  function assertTrue(condition, message2) {
564
700
  if (condition !== true)
565
701
  throw new AssertionError(message2 ?? `Condition is false`);
@@ -581,6 +717,13 @@ function assertNotEqual(obj, other, message2) {
581
717
  message2 ?? `Objects are equal: ${JSONParser.stringify(obj)}`
582
718
  );
583
719
  }
720
+ function assertIsNotNull(result) {
721
+ assertNotEqual(result, null);
722
+ assertOk(result);
723
+ }
724
+ function assertIsNull(result) {
725
+ assertEqual(result, null);
726
+ }
584
727
  var assertThatArray = (array) => {
585
728
  return {
586
729
  isEmpty: () => assertEqual(
@@ -924,6 +1067,143 @@ var workflowProcessor = (options) => {
924
1067
  });
925
1068
  };
926
1069
 
1070
+ // src/eventStore/projections/pongo/pongoProjectionSpec.ts
1071
+ import {
1072
+ pongoClient as pongoClient2
1073
+ } from "@event-driven-io/pongo";
1074
+ var withCollection = async (handle, options) => {
1075
+ const { connection, inDatabase, inCollection } = options;
1076
+ const driver = await pongoDriverRegistry.tryResolve(
1077
+ connection.driverType
1078
+ );
1079
+ const pongo = pongoClient2({
1080
+ connectionOptions: { connection },
1081
+ driver
1082
+ });
1083
+ try {
1084
+ const collection = pongo.db(inDatabase).collection(inCollection);
1085
+ return handle(collection);
1086
+ } finally {
1087
+ await pongo.close();
1088
+ }
1089
+ };
1090
+ var withoutIdAndVersion = (doc) => {
1091
+ const { _id, _version, ...without } = doc;
1092
+ return without;
1093
+ };
1094
+ var assertDocumentsEqual = (actual, expected) => {
1095
+ if ("_id" in expected)
1096
+ assertEqual(
1097
+ expected._id,
1098
+ actual._id,
1099
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1100
+ `Document ids are not matching! Expected: ${expected._id}, Actual: ${actual._id}`
1101
+ );
1102
+ return assertDeepEqual(
1103
+ withoutIdAndVersion(actual),
1104
+ withoutIdAndVersion(expected)
1105
+ );
1106
+ };
1107
+ var documentExists = (document, options) => (assertOptions) => withCollection(
1108
+ async (collection) => {
1109
+ const result = await collection.findOne(
1110
+ "withId" in options ? { _id: options.withId } : options.matchingFilter
1111
+ );
1112
+ assertIsNotNull(result);
1113
+ assertDocumentsEqual(result, document);
1114
+ },
1115
+ { ...options, ...assertOptions }
1116
+ );
1117
+ var documentsAreTheSame = (documents, options) => (assertOptions) => withCollection(
1118
+ async (collection) => {
1119
+ const result = await collection.find(
1120
+ "withId" in options ? { _id: options.withId } : options.matchingFilter
1121
+ );
1122
+ assertEqual(
1123
+ documents.length,
1124
+ result.length,
1125
+ "Different Documents Count than expected"
1126
+ );
1127
+ for (let i = 0; i < documents.length; i++) {
1128
+ assertThatArray(result).contains(documents[i]);
1129
+ }
1130
+ },
1131
+ { ...options, ...assertOptions }
1132
+ );
1133
+ var documentsMatchingHaveCount = (expectedCount, options) => (assertOptions) => withCollection(
1134
+ async (collection) => {
1135
+ const result = await collection.find(
1136
+ "withId" in options ? { _id: options.withId } : options.matchingFilter
1137
+ );
1138
+ assertEqual(
1139
+ expectedCount,
1140
+ result.length,
1141
+ "Different Documents Count than expected"
1142
+ );
1143
+ },
1144
+ { ...options, ...assertOptions }
1145
+ );
1146
+ var documentMatchingExists = (options) => (assertOptions) => withCollection(
1147
+ async (collection) => {
1148
+ const result = await collection.find(
1149
+ "withId" in options ? { _id: options.withId } : options.matchingFilter
1150
+ );
1151
+ assertThatArray(result).isNotEmpty();
1152
+ },
1153
+ { ...options, ...assertOptions }
1154
+ );
1155
+ var documentDoesNotExist = (options) => (assertOptions) => withCollection(
1156
+ async (collection) => {
1157
+ const result = await collection.findOne(
1158
+ "withId" in options ? { _id: options.withId } : options.matchingFilter
1159
+ );
1160
+ assertIsNull(result);
1161
+ },
1162
+ { ...options, ...assertOptions }
1163
+ );
1164
+ var expectPongoDocuments = {
1165
+ fromCollection: (collectionName) => {
1166
+ return {
1167
+ withId: (id) => {
1168
+ return {
1169
+ toBeEqual: (document) => documentExists(document, {
1170
+ withId: id,
1171
+ inCollection: collectionName
1172
+ }),
1173
+ toExist: () => documentMatchingExists({
1174
+ withId: id,
1175
+ inCollection: collectionName
1176
+ }),
1177
+ notToExist: () => documentDoesNotExist({
1178
+ withId: id,
1179
+ inCollection: collectionName
1180
+ })
1181
+ };
1182
+ },
1183
+ matching: (filter) => {
1184
+ return {
1185
+ toBeTheSame: (documents) => documentsAreTheSame(documents, {
1186
+ matchingFilter: filter,
1187
+ inCollection: collectionName
1188
+ }),
1189
+ toHaveCount: (expectedCount) => documentsMatchingHaveCount(expectedCount, {
1190
+ matchingFilter: filter,
1191
+ inCollection: collectionName
1192
+ }),
1193
+ toExist: () => documentMatchingExists({
1194
+ matchingFilter: filter,
1195
+ inCollection: collectionName
1196
+ }),
1197
+ notToExist: () => documentDoesNotExist({
1198
+ matchingFilter: filter,
1199
+ inCollection: collectionName
1200
+ })
1201
+ };
1202
+ }
1203
+ };
1204
+ }
1205
+ };
1206
+
927
1207
  // src/eventStore/projections/sqliteProjection.ts
928
1208
  var handleProjections = async (options) => {
929
1209
  const {
@@ -2297,9 +2577,15 @@ export {
2297
2577
  assertSQLQueryResultMatches,
2298
2578
  createEventStoreSchema,
2299
2579
  defaultTag2 as defaultTag,
2580
+ documentDoesNotExist,
2581
+ documentExists,
2582
+ documentMatchingExists,
2583
+ documentsAreTheSame,
2584
+ documentsMatchingHaveCount,
2300
2585
  emmettPrefix2 as emmettPrefix,
2301
2586
  eventInStream,
2302
2587
  eventsInStream,
2588
+ expectPongoDocuments,
2303
2589
  expectSQL,
2304
2590
  getSQLiteEventStore,
2305
2591
  globalNames,
@@ -2310,6 +2596,9 @@ export {
2310
2596
  migration_0_42_0_FromSubscriptionsToProcessors,
2311
2597
  migration_0_42_0_SQLs,
2312
2598
  newEventsInStream,
2599
+ pongoMultiStreamProjection,
2600
+ pongoProjection,
2601
+ pongoSingleStreamProjection,
2313
2602
  processorsTable,
2314
2603
  processorsTableSQL,
2315
2604
  projectionsTable,