@event-driven-io/emmett-sqlite 0.43.0-alpha.4 → 0.43.0-beta.1
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/cloudflare.d.cts +1 -1
- package/dist/cloudflare.d.ts +1 -1
- package/dist/index.cjs +514 -222
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -24
- package/dist/index.d.ts +19 -24
- package/dist/index.js +482 -190
- package/dist/index.js.map +1 -1
- package/dist/sqlite3.d.cts +1 -1
- package/dist/sqlite3.d.ts +1 -1
- package/dist/sqliteProjection-V1lU-4KS.d.cts +146 -0
- package/dist/sqliteProjection-V1lU-4KS.d.ts +146 -0
- package/package.json +3 -3
- package/dist/sqliteProjection-CFGjb8aY.d.cts +0 -172
- package/dist/sqliteProjection-CFGjb8aY.d.ts +0 -172
package/dist/sqlite3.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sqlite3DumboDriver, SQLite3DumboOptions } from '@event-driven-io/dumbo/sqlite3';
|
|
2
|
-
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-
|
|
2
|
+
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-V1lU-4KS.cjs';
|
|
3
3
|
import '@event-driven-io/dumbo';
|
|
4
4
|
import '@event-driven-io/dumbo/sqlite';
|
|
5
5
|
import '@event-driven-io/emmett';
|
package/dist/sqlite3.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sqlite3DumboDriver, SQLite3DumboOptions } from '@event-driven-io/dumbo/sqlite3';
|
|
2
|
-
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-
|
|
2
|
+
import { E as EventStoreDriver, S as SQLiteEventStoreOptions } from './sqliteProjection-V1lU-4KS.js';
|
|
3
3
|
import '@event-driven-io/dumbo';
|
|
4
4
|
import '@event-driven-io/dumbo/sqlite';
|
|
5
5
|
import '@event-driven-io/emmett';
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { AnyDumboDatabaseDriver, ExtractDumboDatabaseDriverOptions, SQLExecutor, SQL, Dumbo, DatabaseDriverType } from '@event-driven-io/dumbo';
|
|
2
|
+
import { AnySQLiteConnection } from '@event-driven-io/dumbo/sqlite';
|
|
3
|
+
import { StreamExistsResult, Message, AnyMessage, ReactorOptions, ReadEventMetadataWithGlobalPosition, MessageProcessor, AnyEvent, Event, ProjectorOptions, MessageConsumerOptions, MessageConsumer, ProjectionRegistration, BeforeEventStoreCommitHandler, EventStore, AppendToStreamOptions, AppendToStreamResultWithGlobalPosition, ReadEvent, ProjectionHandler, ProjectionDefinition, CanHandle, ProjectionInitOptions, EventStoreReadSchemaOptions } from '@event-driven-io/emmett';
|
|
4
|
+
|
|
5
|
+
interface EventStoreDriver<DatabaseDriver extends AnyDumboDatabaseDriver = AnyDumboDatabaseDriver, DriverOptions extends AnyEventStoreDriverOptions = AnyEventStoreDriverOptions> {
|
|
6
|
+
driverType: DatabaseDriver['driverType'];
|
|
7
|
+
dumboDriver: DatabaseDriver;
|
|
8
|
+
mapToDumboOptions(driverOptions: DriverOptions): ExtractDumboDatabaseDriverOptions<DatabaseDriver>;
|
|
9
|
+
}
|
|
10
|
+
type EventStoreDriverOptions<Driver extends AnyEventStoreDriver = AnyEventStoreDriver> = {
|
|
11
|
+
connectionOptions?: ExtractDumboDatabaseDriverOptions<Driver['dumboDriver']> | undefined;
|
|
12
|
+
};
|
|
13
|
+
type AnyEventStoreDriverOptions = EventStoreDriverOptions<any>;
|
|
14
|
+
type AnyEventStoreDriver = EventStoreDriver<AnyDumboDatabaseDriver, AnyEventStoreDriverOptions>;
|
|
15
|
+
type InferOptionsFromEventStoreDriver<C extends AnyEventStoreDriver> = C extends EventStoreDriver<any, infer DO> ? DO : never;
|
|
16
|
+
|
|
17
|
+
type SQLiteStreamExistsOptions = {
|
|
18
|
+
partition: string;
|
|
19
|
+
};
|
|
20
|
+
declare const streamExists: (execute: SQLExecutor, streamId: string, options?: SQLiteStreamExistsOptions) => Promise<StreamExistsResult>;
|
|
21
|
+
|
|
22
|
+
declare const streamsTableSQL: SQL;
|
|
23
|
+
declare const messagesTableSQL: SQL;
|
|
24
|
+
declare const processorsTableSQL: SQL;
|
|
25
|
+
declare const projectionsTableSQL: SQL;
|
|
26
|
+
declare const schemaSQL: SQL[];
|
|
27
|
+
type CreateEventStoreSchemaOptions = {
|
|
28
|
+
dryRun?: boolean | undefined;
|
|
29
|
+
ignoreMigrationHashMismatch?: boolean | undefined;
|
|
30
|
+
migrationTimeoutMs?: number | undefined;
|
|
31
|
+
};
|
|
32
|
+
type EventStoreSchemaMigrationOptions = {
|
|
33
|
+
migrationOptions?: CreateEventStoreSchemaOptions;
|
|
34
|
+
};
|
|
35
|
+
declare const createEventStoreSchema: (pool: AnySQLiteConnection, hooks?: SQLiteEventStoreOptions["hooks"]) => Promise<void>;
|
|
36
|
+
|
|
37
|
+
type SQLiteProcessorHandlerContext = {
|
|
38
|
+
execute: SQLExecutor;
|
|
39
|
+
connection: AnySQLiteConnection;
|
|
40
|
+
} & EventStoreSchemaMigrationOptions;
|
|
41
|
+
type SQLiteProcessor<MessageType extends Message = AnyMessage> = MessageProcessor<MessageType, ReadEventMetadataWithGlobalPosition, SQLiteProcessorHandlerContext>;
|
|
42
|
+
type SQLiteProcessorConnectionOptions = {
|
|
43
|
+
connection?: AnySQLiteConnection;
|
|
44
|
+
};
|
|
45
|
+
type SQLiteReactorOptions<MessageType extends Message = Message, MessagePayloadType extends AnyMessage = MessageType> = ReactorOptions<MessageType, ReadEventMetadataWithGlobalPosition, SQLiteProcessorHandlerContext, MessagePayloadType> & SQLiteProcessorConnectionOptions;
|
|
46
|
+
type SQLiteProjectorOptions<EventType extends AnyEvent = AnyEvent, EventPayloadType extends Event = EventType> = ProjectorOptions<EventType, ReadEventMetadataWithGlobalPosition, SQLiteProcessorHandlerContext, EventPayloadType> & SQLiteProcessorConnectionOptions & EventStoreSchemaMigrationOptions;
|
|
47
|
+
|
|
48
|
+
type SQLiteEventStoreConsumerConfig<ConsumerMessageType extends Message = any> = MessageConsumerOptions<ConsumerMessageType> & {
|
|
49
|
+
stopWhen?: {
|
|
50
|
+
noMessagesLeft?: boolean;
|
|
51
|
+
};
|
|
52
|
+
pulling?: {
|
|
53
|
+
batchSize?: number;
|
|
54
|
+
pullingFrequencyInMs?: number;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
type SQLiteEventStoreConsumer<ConsumerMessageType extends AnyMessage = any> = MessageConsumer<ConsumerMessageType> & Readonly<{
|
|
58
|
+
reactor: <MessageType extends AnyMessage = ConsumerMessageType>(options: SQLiteReactorOptions<MessageType>) => SQLiteProcessor<MessageType>;
|
|
59
|
+
}> & (AnyEvent extends ConsumerMessageType ? Readonly<{
|
|
60
|
+
projector: <EventType extends AnyEvent = ConsumerMessageType & AnyEvent>(options: SQLiteProjectorOptions<EventType>) => SQLiteProcessor<EventType>;
|
|
61
|
+
}> : object);
|
|
62
|
+
|
|
63
|
+
type EventHandler<E extends Event = Event> = (eventEnvelope: ReadEvent<E>) => void;
|
|
64
|
+
declare const SQLiteEventStoreDefaultStreamVersion = 0n;
|
|
65
|
+
interface SQLiteEventStore extends EventStore<SQLiteReadEventMetadata> {
|
|
66
|
+
appendToStream<EventType extends Event, EventPayloadType extends Event = EventType>(streamName: string, events: EventType[], options?: AppendToStreamOptions<EventType, EventPayloadType>): Promise<AppendToStreamResultWithGlobalPosition>;
|
|
67
|
+
consumer<ConsumerEventType extends Event = Event>(options?: SQLiteEventStoreConsumerConfig<ConsumerEventType>): SQLiteEventStoreConsumer<ConsumerEventType>;
|
|
68
|
+
streamExists(streamName: string, options?: SQLiteStreamExistsOptions): Promise<StreamExistsResult>;
|
|
69
|
+
close(): Promise<void>;
|
|
70
|
+
schema: {
|
|
71
|
+
sql(): string;
|
|
72
|
+
print(): void;
|
|
73
|
+
migrate(): Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
type SQLiteReadEventMetadata = ReadEventMetadataWithGlobalPosition;
|
|
77
|
+
type SQLiteReadEvent<EventType extends Event = Event> = ReadEvent<EventType, SQLiteReadEventMetadata>;
|
|
78
|
+
type SQLiteEventStoreOptions<EventStoreDriver extends AnyEventStoreDriver = AnyEventStoreDriver> = {
|
|
79
|
+
driver: EventStoreDriver;
|
|
80
|
+
projections?: ProjectionRegistration<'inline', SQLiteReadEventMetadata, SQLiteProjectionHandlerContext>[];
|
|
81
|
+
schema?: {
|
|
82
|
+
autoMigration?: 'None' | 'CreateOrUpdate';
|
|
83
|
+
};
|
|
84
|
+
hooks?: {
|
|
85
|
+
/**
|
|
86
|
+
* This hook will be called **BEFORE** event store schema is created
|
|
87
|
+
*/
|
|
88
|
+
onBeforeSchemaCreated?: (context: {
|
|
89
|
+
connection: AnySQLiteConnection;
|
|
90
|
+
}) => Promise<void> | void;
|
|
91
|
+
/**
|
|
92
|
+
* This hook will be called **BEFORE** events were stored in the event store.
|
|
93
|
+
* @type {BeforeEventStoreCommitHandler<SQLiteEventStore, HandlerContext>}
|
|
94
|
+
*/
|
|
95
|
+
onBeforeCommit?: BeforeEventStoreCommitHandler<SQLiteEventStore, {
|
|
96
|
+
connection: AnySQLiteConnection;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* This hook will be called **AFTER** event store schema was created
|
|
100
|
+
*/
|
|
101
|
+
onAfterSchemaCreated?: () => Promise<void> | void;
|
|
102
|
+
};
|
|
103
|
+
} & {
|
|
104
|
+
pool?: Dumbo;
|
|
105
|
+
} & InferOptionsFromEventStoreDriver<EventStoreDriver>;
|
|
106
|
+
declare const getSQLiteEventStore: <Driver extends AnyEventStoreDriver = AnyEventStoreDriver>(options: SQLiteEventStoreOptions<Driver>) => SQLiteEventStore;
|
|
107
|
+
|
|
108
|
+
type SQLiteProjectionHandlerContext = {
|
|
109
|
+
execute: SQLExecutor;
|
|
110
|
+
connection: AnySQLiteConnection;
|
|
111
|
+
driverType: DatabaseDriverType;
|
|
112
|
+
};
|
|
113
|
+
type SQLiteProjectionHandler<EventType extends Event = Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = ProjectionHandler<EventType, EventMetaDataType, SQLiteProjectionHandlerContext>;
|
|
114
|
+
type SQLiteProjectionDefinition<EventType extends Event = Event, EventPayloadType extends Event = EventType> = ProjectionDefinition<EventType, SQLiteReadEventMetadata, SQLiteProjectionHandlerContext, EventPayloadType>;
|
|
115
|
+
type SQLiteProjectionHandlerOptions<EventType extends Event = Event> = {
|
|
116
|
+
events: ReadEvent<EventType, SQLiteReadEventMetadata>[];
|
|
117
|
+
projections: SQLiteProjectionDefinition<EventType>[];
|
|
118
|
+
} & SQLiteProjectionHandlerContext;
|
|
119
|
+
declare const handleProjections: <EventType extends Event = Event>(options: SQLiteProjectionHandlerOptions<EventType>) => Promise<void>;
|
|
120
|
+
declare const sqliteProjection: <EventType extends Event, EventPayloadType extends Event = EventType>(definition: SQLiteProjectionDefinition<EventType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
|
|
121
|
+
type SQLiteRawBatchSQLProjection<EventType extends Event, EventPayloadType extends Event = EventType> = {
|
|
122
|
+
name: string;
|
|
123
|
+
kind?: string;
|
|
124
|
+
version?: number;
|
|
125
|
+
evolve: (events: EventType[], context: SQLiteProjectionHandlerContext) => Promise<SQL[]> | SQL[];
|
|
126
|
+
canHandle: CanHandle<EventType>;
|
|
127
|
+
init?: (context: ProjectionInitOptions<SQLiteProjectionHandlerContext>) => void | Promise<void> | SQL | Promise<SQL> | Promise<SQL[]> | SQL[];
|
|
128
|
+
eventsOptions?: {
|
|
129
|
+
schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
declare const sqliteRawBatchSQLProjection: <EventType extends Event, EventPayloadType extends Event = EventType>(options: SQLiteRawBatchSQLProjection<EventType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
|
|
133
|
+
type SQLiteRawSQLProjection<EventType extends Event, EventPayloadType extends Event = EventType> = {
|
|
134
|
+
name: string;
|
|
135
|
+
kind?: string;
|
|
136
|
+
version?: number;
|
|
137
|
+
evolve: (events: EventType, context: SQLiteProjectionHandlerContext) => Promise<SQL[]> | SQL[] | Promise<SQL> | SQL;
|
|
138
|
+
canHandle: CanHandle<EventType>;
|
|
139
|
+
init?: (context: ProjectionInitOptions<SQLiteProjectionHandlerContext>) => void | Promise<void> | SQL | Promise<SQL> | Promise<SQL[]> | SQL[];
|
|
140
|
+
eventsOptions?: {
|
|
141
|
+
schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
declare const sqliteRawSQLProjection: <EventType extends Event, EventPayloadType extends Event = EventType>(options: SQLiteRawSQLProjection<EventType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
|
|
145
|
+
|
|
146
|
+
export { type AnyEventStoreDriver as A, type CreateEventStoreSchemaOptions as C, type EventStoreDriver as E, type InferOptionsFromEventStoreDriver as I, type SQLiteEventStoreOptions as S, type SQLiteEventStore as a, type SQLiteReadEventMetadata as b, type SQLiteProjectionDefinition as c, type SQLiteProjectionHandlerContext as d, type SQLiteProjectionHandler as e, type SQLiteProjectionHandlerOptions as f, type SQLiteRawBatchSQLProjection as g, handleProjections as h, sqliteRawBatchSQLProjection as i, type SQLiteRawSQLProjection as j, sqliteRawSQLProjection as k, type SQLiteStreamExistsOptions as l, streamExists as m, streamsTableSQL as n, messagesTableSQL as o, processorsTableSQL as p, projectionsTableSQL as q, schemaSQL as r, sqliteProjection as s, type EventStoreSchemaMigrationOptions as t, createEventStoreSchema as u, type EventHandler as v, SQLiteEventStoreDefaultStreamVersion as w, type SQLiteReadEvent as x, getSQLiteEventStore as y };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { AnyDumboDatabaseDriver, ExtractDumboDatabaseDriverOptions, SQLExecutor, SQL, Dumbo, DatabaseDriverType } from '@event-driven-io/dumbo';
|
|
2
|
+
import { AnySQLiteConnection } from '@event-driven-io/dumbo/sqlite';
|
|
3
|
+
import { StreamExistsResult, Message, AnyMessage, ReactorOptions, ReadEventMetadataWithGlobalPosition, MessageProcessor, AnyEvent, Event, ProjectorOptions, MessageConsumerOptions, MessageConsumer, ProjectionRegistration, BeforeEventStoreCommitHandler, EventStore, AppendToStreamOptions, AppendToStreamResultWithGlobalPosition, ReadEvent, ProjectionHandler, ProjectionDefinition, CanHandle, ProjectionInitOptions, EventStoreReadSchemaOptions } from '@event-driven-io/emmett';
|
|
4
|
+
|
|
5
|
+
interface EventStoreDriver<DatabaseDriver extends AnyDumboDatabaseDriver = AnyDumboDatabaseDriver, DriverOptions extends AnyEventStoreDriverOptions = AnyEventStoreDriverOptions> {
|
|
6
|
+
driverType: DatabaseDriver['driverType'];
|
|
7
|
+
dumboDriver: DatabaseDriver;
|
|
8
|
+
mapToDumboOptions(driverOptions: DriverOptions): ExtractDumboDatabaseDriverOptions<DatabaseDriver>;
|
|
9
|
+
}
|
|
10
|
+
type EventStoreDriverOptions<Driver extends AnyEventStoreDriver = AnyEventStoreDriver> = {
|
|
11
|
+
connectionOptions?: ExtractDumboDatabaseDriverOptions<Driver['dumboDriver']> | undefined;
|
|
12
|
+
};
|
|
13
|
+
type AnyEventStoreDriverOptions = EventStoreDriverOptions<any>;
|
|
14
|
+
type AnyEventStoreDriver = EventStoreDriver<AnyDumboDatabaseDriver, AnyEventStoreDriverOptions>;
|
|
15
|
+
type InferOptionsFromEventStoreDriver<C extends AnyEventStoreDriver> = C extends EventStoreDriver<any, infer DO> ? DO : never;
|
|
16
|
+
|
|
17
|
+
type SQLiteStreamExistsOptions = {
|
|
18
|
+
partition: string;
|
|
19
|
+
};
|
|
20
|
+
declare const streamExists: (execute: SQLExecutor, streamId: string, options?: SQLiteStreamExistsOptions) => Promise<StreamExistsResult>;
|
|
21
|
+
|
|
22
|
+
declare const streamsTableSQL: SQL;
|
|
23
|
+
declare const messagesTableSQL: SQL;
|
|
24
|
+
declare const processorsTableSQL: SQL;
|
|
25
|
+
declare const projectionsTableSQL: SQL;
|
|
26
|
+
declare const schemaSQL: SQL[];
|
|
27
|
+
type CreateEventStoreSchemaOptions = {
|
|
28
|
+
dryRun?: boolean | undefined;
|
|
29
|
+
ignoreMigrationHashMismatch?: boolean | undefined;
|
|
30
|
+
migrationTimeoutMs?: number | undefined;
|
|
31
|
+
};
|
|
32
|
+
type EventStoreSchemaMigrationOptions = {
|
|
33
|
+
migrationOptions?: CreateEventStoreSchemaOptions;
|
|
34
|
+
};
|
|
35
|
+
declare const createEventStoreSchema: (pool: AnySQLiteConnection, hooks?: SQLiteEventStoreOptions["hooks"]) => Promise<void>;
|
|
36
|
+
|
|
37
|
+
type SQLiteProcessorHandlerContext = {
|
|
38
|
+
execute: SQLExecutor;
|
|
39
|
+
connection: AnySQLiteConnection;
|
|
40
|
+
} & EventStoreSchemaMigrationOptions;
|
|
41
|
+
type SQLiteProcessor<MessageType extends Message = AnyMessage> = MessageProcessor<MessageType, ReadEventMetadataWithGlobalPosition, SQLiteProcessorHandlerContext>;
|
|
42
|
+
type SQLiteProcessorConnectionOptions = {
|
|
43
|
+
connection?: AnySQLiteConnection;
|
|
44
|
+
};
|
|
45
|
+
type SQLiteReactorOptions<MessageType extends Message = Message, MessagePayloadType extends AnyMessage = MessageType> = ReactorOptions<MessageType, ReadEventMetadataWithGlobalPosition, SQLiteProcessorHandlerContext, MessagePayloadType> & SQLiteProcessorConnectionOptions;
|
|
46
|
+
type SQLiteProjectorOptions<EventType extends AnyEvent = AnyEvent, EventPayloadType extends Event = EventType> = ProjectorOptions<EventType, ReadEventMetadataWithGlobalPosition, SQLiteProcessorHandlerContext, EventPayloadType> & SQLiteProcessorConnectionOptions & EventStoreSchemaMigrationOptions;
|
|
47
|
+
|
|
48
|
+
type SQLiteEventStoreConsumerConfig<ConsumerMessageType extends Message = any> = MessageConsumerOptions<ConsumerMessageType> & {
|
|
49
|
+
stopWhen?: {
|
|
50
|
+
noMessagesLeft?: boolean;
|
|
51
|
+
};
|
|
52
|
+
pulling?: {
|
|
53
|
+
batchSize?: number;
|
|
54
|
+
pullingFrequencyInMs?: number;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
type SQLiteEventStoreConsumer<ConsumerMessageType extends AnyMessage = any> = MessageConsumer<ConsumerMessageType> & Readonly<{
|
|
58
|
+
reactor: <MessageType extends AnyMessage = ConsumerMessageType>(options: SQLiteReactorOptions<MessageType>) => SQLiteProcessor<MessageType>;
|
|
59
|
+
}> & (AnyEvent extends ConsumerMessageType ? Readonly<{
|
|
60
|
+
projector: <EventType extends AnyEvent = ConsumerMessageType & AnyEvent>(options: SQLiteProjectorOptions<EventType>) => SQLiteProcessor<EventType>;
|
|
61
|
+
}> : object);
|
|
62
|
+
|
|
63
|
+
type EventHandler<E extends Event = Event> = (eventEnvelope: ReadEvent<E>) => void;
|
|
64
|
+
declare const SQLiteEventStoreDefaultStreamVersion = 0n;
|
|
65
|
+
interface SQLiteEventStore extends EventStore<SQLiteReadEventMetadata> {
|
|
66
|
+
appendToStream<EventType extends Event, EventPayloadType extends Event = EventType>(streamName: string, events: EventType[], options?: AppendToStreamOptions<EventType, EventPayloadType>): Promise<AppendToStreamResultWithGlobalPosition>;
|
|
67
|
+
consumer<ConsumerEventType extends Event = Event>(options?: SQLiteEventStoreConsumerConfig<ConsumerEventType>): SQLiteEventStoreConsumer<ConsumerEventType>;
|
|
68
|
+
streamExists(streamName: string, options?: SQLiteStreamExistsOptions): Promise<StreamExistsResult>;
|
|
69
|
+
close(): Promise<void>;
|
|
70
|
+
schema: {
|
|
71
|
+
sql(): string;
|
|
72
|
+
print(): void;
|
|
73
|
+
migrate(): Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
type SQLiteReadEventMetadata = ReadEventMetadataWithGlobalPosition;
|
|
77
|
+
type SQLiteReadEvent<EventType extends Event = Event> = ReadEvent<EventType, SQLiteReadEventMetadata>;
|
|
78
|
+
type SQLiteEventStoreOptions<EventStoreDriver extends AnyEventStoreDriver = AnyEventStoreDriver> = {
|
|
79
|
+
driver: EventStoreDriver;
|
|
80
|
+
projections?: ProjectionRegistration<'inline', SQLiteReadEventMetadata, SQLiteProjectionHandlerContext>[];
|
|
81
|
+
schema?: {
|
|
82
|
+
autoMigration?: 'None' | 'CreateOrUpdate';
|
|
83
|
+
};
|
|
84
|
+
hooks?: {
|
|
85
|
+
/**
|
|
86
|
+
* This hook will be called **BEFORE** event store schema is created
|
|
87
|
+
*/
|
|
88
|
+
onBeforeSchemaCreated?: (context: {
|
|
89
|
+
connection: AnySQLiteConnection;
|
|
90
|
+
}) => Promise<void> | void;
|
|
91
|
+
/**
|
|
92
|
+
* This hook will be called **BEFORE** events were stored in the event store.
|
|
93
|
+
* @type {BeforeEventStoreCommitHandler<SQLiteEventStore, HandlerContext>}
|
|
94
|
+
*/
|
|
95
|
+
onBeforeCommit?: BeforeEventStoreCommitHandler<SQLiteEventStore, {
|
|
96
|
+
connection: AnySQLiteConnection;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* This hook will be called **AFTER** event store schema was created
|
|
100
|
+
*/
|
|
101
|
+
onAfterSchemaCreated?: () => Promise<void> | void;
|
|
102
|
+
};
|
|
103
|
+
} & {
|
|
104
|
+
pool?: Dumbo;
|
|
105
|
+
} & InferOptionsFromEventStoreDriver<EventStoreDriver>;
|
|
106
|
+
declare const getSQLiteEventStore: <Driver extends AnyEventStoreDriver = AnyEventStoreDriver>(options: SQLiteEventStoreOptions<Driver>) => SQLiteEventStore;
|
|
107
|
+
|
|
108
|
+
type SQLiteProjectionHandlerContext = {
|
|
109
|
+
execute: SQLExecutor;
|
|
110
|
+
connection: AnySQLiteConnection;
|
|
111
|
+
driverType: DatabaseDriverType;
|
|
112
|
+
};
|
|
113
|
+
type SQLiteProjectionHandler<EventType extends Event = Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = ProjectionHandler<EventType, EventMetaDataType, SQLiteProjectionHandlerContext>;
|
|
114
|
+
type SQLiteProjectionDefinition<EventType extends Event = Event, EventPayloadType extends Event = EventType> = ProjectionDefinition<EventType, SQLiteReadEventMetadata, SQLiteProjectionHandlerContext, EventPayloadType>;
|
|
115
|
+
type SQLiteProjectionHandlerOptions<EventType extends Event = Event> = {
|
|
116
|
+
events: ReadEvent<EventType, SQLiteReadEventMetadata>[];
|
|
117
|
+
projections: SQLiteProjectionDefinition<EventType>[];
|
|
118
|
+
} & SQLiteProjectionHandlerContext;
|
|
119
|
+
declare const handleProjections: <EventType extends Event = Event>(options: SQLiteProjectionHandlerOptions<EventType>) => Promise<void>;
|
|
120
|
+
declare const sqliteProjection: <EventType extends Event, EventPayloadType extends Event = EventType>(definition: SQLiteProjectionDefinition<EventType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
|
|
121
|
+
type SQLiteRawBatchSQLProjection<EventType extends Event, EventPayloadType extends Event = EventType> = {
|
|
122
|
+
name: string;
|
|
123
|
+
kind?: string;
|
|
124
|
+
version?: number;
|
|
125
|
+
evolve: (events: EventType[], context: SQLiteProjectionHandlerContext) => Promise<SQL[]> | SQL[];
|
|
126
|
+
canHandle: CanHandle<EventType>;
|
|
127
|
+
init?: (context: ProjectionInitOptions<SQLiteProjectionHandlerContext>) => void | Promise<void> | SQL | Promise<SQL> | Promise<SQL[]> | SQL[];
|
|
128
|
+
eventsOptions?: {
|
|
129
|
+
schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
declare const sqliteRawBatchSQLProjection: <EventType extends Event, EventPayloadType extends Event = EventType>(options: SQLiteRawBatchSQLProjection<EventType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
|
|
133
|
+
type SQLiteRawSQLProjection<EventType extends Event, EventPayloadType extends Event = EventType> = {
|
|
134
|
+
name: string;
|
|
135
|
+
kind?: string;
|
|
136
|
+
version?: number;
|
|
137
|
+
evolve: (events: EventType, context: SQLiteProjectionHandlerContext) => Promise<SQL[]> | SQL[] | Promise<SQL> | SQL;
|
|
138
|
+
canHandle: CanHandle<EventType>;
|
|
139
|
+
init?: (context: ProjectionInitOptions<SQLiteProjectionHandlerContext>) => void | Promise<void> | SQL | Promise<SQL> | Promise<SQL[]> | SQL[];
|
|
140
|
+
eventsOptions?: {
|
|
141
|
+
schema?: EventStoreReadSchemaOptions<EventType, EventPayloadType>;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
declare const sqliteRawSQLProjection: <EventType extends Event, EventPayloadType extends Event = EventType>(options: SQLiteRawSQLProjection<EventType, EventPayloadType>) => SQLiteProjectionDefinition<EventType, EventPayloadType>;
|
|
145
|
+
|
|
146
|
+
export { type AnyEventStoreDriver as A, type CreateEventStoreSchemaOptions as C, type EventStoreDriver as E, type InferOptionsFromEventStoreDriver as I, type SQLiteEventStoreOptions as S, type SQLiteEventStore as a, type SQLiteReadEventMetadata as b, type SQLiteProjectionDefinition as c, type SQLiteProjectionHandlerContext as d, type SQLiteProjectionHandler as e, type SQLiteProjectionHandlerOptions as f, type SQLiteRawBatchSQLProjection as g, handleProjections as h, sqliteRawBatchSQLProjection as i, type SQLiteRawSQLProjection as j, sqliteRawSQLProjection as k, type SQLiteStreamExistsOptions as l, streamExists as m, streamsTableSQL as n, messagesTableSQL as o, processorsTableSQL as p, projectionsTableSQL as q, schemaSQL as r, sqliteProjection as s, type EventStoreSchemaMigrationOptions as t, createEventStoreSchema as u, type EventHandler as v, SQLiteEventStoreDefaultStreamVersion as w, type SQLiteReadEvent as x, getSQLiteEventStore as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@event-driven-io/emmett-sqlite",
|
|
3
|
-
"version": "0.43.0-
|
|
3
|
+
"version": "0.43.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Emmett - SQLite - Event Sourcing development made simple",
|
|
6
6
|
"scripts": {
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
"dist"
|
|
93
93
|
],
|
|
94
94
|
"dependencies": {
|
|
95
|
-
"@event-driven-io/emmett": "0.43.0-
|
|
96
|
-
"@event-driven-io/pongo": "0.17.0-beta.
|
|
95
|
+
"@event-driven-io/emmett": "0.43.0-beta.1",
|
|
96
|
+
"@event-driven-io/pongo": "0.17.0-beta.21"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"@cloudflare/workers-types": "^4.20260115.0",
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { AnyDumboDatabaseDriver, ExtractDumboDatabaseDriverOptions, SQLExecutor, Dumbo, SQL } from '@event-driven-io/dumbo';
|
|
2
|
-
import { AnySQLiteConnection } from '@event-driven-io/dumbo/sqlite';
|
|
3
|
-
import { Event, ReadEvent, ReadEventMetadataWithGlobalPosition, EmmettError, StreamExistsResult, ProjectionRegistration, BeforeEventStoreCommitHandler, EventStore, AppendToStreamOptions, BigIntStreamPosition, AppendToStreamResultWithGlobalPosition, ProjectionDefinition, ProjectionHandler, CanHandle, ProjectionInitOptions } from '@event-driven-io/emmett';
|
|
4
|
-
|
|
5
|
-
type SQLiteEventStoreMessageBatchPullerStartFrom = {
|
|
6
|
-
globalPosition: bigint;
|
|
7
|
-
} | 'BEGINNING' | 'END';
|
|
8
|
-
|
|
9
|
-
interface EventStoreDriver<DatabaseDriver extends AnyDumboDatabaseDriver = AnyDumboDatabaseDriver, DriverOptions extends AnyEventStoreDriverOptions = AnyEventStoreDriverOptions> {
|
|
10
|
-
driverType: DatabaseDriver['driverType'];
|
|
11
|
-
dumboDriver: DatabaseDriver;
|
|
12
|
-
mapToDumboOptions(driverOptions: DriverOptions): ExtractDumboDatabaseDriverOptions<DatabaseDriver>;
|
|
13
|
-
}
|
|
14
|
-
type EventStoreDriverOptions<Driver extends AnyEventStoreDriver = AnyEventStoreDriver> = {
|
|
15
|
-
connectionOptions?: ExtractDumboDatabaseDriverOptions<Driver['dumboDriver']> | undefined;
|
|
16
|
-
};
|
|
17
|
-
type AnyEventStoreDriverOptions = EventStoreDriverOptions<any>;
|
|
18
|
-
type AnyEventStoreDriver = EventStoreDriver<AnyDumboDatabaseDriver, AnyEventStoreDriverOptions>;
|
|
19
|
-
type InferOptionsFromEventStoreDriver<C extends AnyEventStoreDriver> = C extends EventStoreDriver<any, infer DO> ? DO : never;
|
|
20
|
-
|
|
21
|
-
type SQLiteProcessorEventsBatch<EventType extends Event = Event> = {
|
|
22
|
-
messages: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>[];
|
|
23
|
-
};
|
|
24
|
-
type SQLiteProcessorHandlerContext = {
|
|
25
|
-
connection: AnySQLiteConnection;
|
|
26
|
-
};
|
|
27
|
-
type SQLiteProcessor<EventType extends Event = Event> = {
|
|
28
|
-
id: string;
|
|
29
|
-
start: (connection: AnySQLiteConnection) => Promise<SQLiteEventStoreMessageBatchPullerStartFrom | undefined>;
|
|
30
|
-
isActive: boolean;
|
|
31
|
-
handle: (messagesBatch: SQLiteProcessorEventsBatch<EventType>, context: {
|
|
32
|
-
connection?: AnySQLiteConnection;
|
|
33
|
-
}) => Promise<SQLiteProcessorMessageHandlerResult>;
|
|
34
|
-
};
|
|
35
|
-
declare const SQLiteProcessor: {
|
|
36
|
-
result: {
|
|
37
|
-
skip: (options?: {
|
|
38
|
-
reason?: string;
|
|
39
|
-
}) => SQLiteProcessorMessageHandlerResult;
|
|
40
|
-
stop: (options?: {
|
|
41
|
-
reason?: string;
|
|
42
|
-
error?: EmmettError;
|
|
43
|
-
}) => SQLiteProcessorMessageHandlerResult;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
type SQLiteProcessorMessageHandlerResult = void | {
|
|
47
|
-
type: 'SKIP';
|
|
48
|
-
reason?: string;
|
|
49
|
-
} | {
|
|
50
|
-
type: 'STOP';
|
|
51
|
-
reason?: string;
|
|
52
|
-
error?: EmmettError;
|
|
53
|
-
};
|
|
54
|
-
type SQLiteProcessorEachMessageHandler<EventType extends Event = Event> = (event: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>, context: SQLiteProcessorHandlerContext) => Promise<SQLiteProcessorMessageHandlerResult> | SQLiteProcessorMessageHandlerResult;
|
|
55
|
-
type SQLiteProcessorStartFrom = SQLiteEventStoreMessageBatchPullerStartFrom | 'CURRENT';
|
|
56
|
-
type SQLiteProcessorConnectionOptions = {
|
|
57
|
-
fileName: string;
|
|
58
|
-
connection?: AnySQLiteConnection;
|
|
59
|
-
};
|
|
60
|
-
type GenericSQLiteProcessorOptions<EventType extends Event = Event> = {
|
|
61
|
-
processorId: string;
|
|
62
|
-
version?: number;
|
|
63
|
-
partition?: string;
|
|
64
|
-
startFrom?: SQLiteProcessorStartFrom;
|
|
65
|
-
stopAfter?: (message: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => boolean;
|
|
66
|
-
eachMessage: SQLiteProcessorEachMessageHandler<EventType>;
|
|
67
|
-
connectionOptions?: SQLiteProcessorConnectionOptions;
|
|
68
|
-
};
|
|
69
|
-
type SQLiteProjectionProcessorOptions<EventType extends Event = Event> = {
|
|
70
|
-
processorId?: string;
|
|
71
|
-
version?: number;
|
|
72
|
-
projection: SQLiteProjectionDefinition<EventType>;
|
|
73
|
-
partition?: string;
|
|
74
|
-
startFrom?: SQLiteProcessorStartFrom;
|
|
75
|
-
stopAfter?: (message: ReadEvent<EventType, ReadEventMetadataWithGlobalPosition>) => boolean;
|
|
76
|
-
};
|
|
77
|
-
type SQLiteProcessorOptions<EventType extends Event = Event> = GenericSQLiteProcessorOptions<EventType> | SQLiteProjectionProcessorOptions<EventType>;
|
|
78
|
-
|
|
79
|
-
type SQLiteEventStoreConsumerConfig<ConsumerEventType extends Event = Event> = {
|
|
80
|
-
processors?: SQLiteProcessor<ConsumerEventType>[];
|
|
81
|
-
pulling?: {
|
|
82
|
-
batchSize?: number;
|
|
83
|
-
pullingFrequencyInMs?: number;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
type SQLiteEventStoreConsumer<ConsumerEventType extends Event = Event> = Readonly<{
|
|
87
|
-
isRunning: boolean;
|
|
88
|
-
processors: SQLiteProcessor<ConsumerEventType>[];
|
|
89
|
-
processor: <EventType extends ConsumerEventType = ConsumerEventType>(options: SQLiteProcessorOptions<EventType>) => SQLiteProcessor<EventType>;
|
|
90
|
-
start: () => Promise<void>;
|
|
91
|
-
stop: () => Promise<void>;
|
|
92
|
-
close: () => Promise<void>;
|
|
93
|
-
}>;
|
|
94
|
-
|
|
95
|
-
type SQLiteStreamExistsOptions = {
|
|
96
|
-
partition: string;
|
|
97
|
-
};
|
|
98
|
-
declare const streamExists: (execute: SQLExecutor, streamId: string, options?: SQLiteStreamExistsOptions) => Promise<StreamExistsResult>;
|
|
99
|
-
|
|
100
|
-
type EventHandler<E extends Event = Event> = (eventEnvelope: ReadEvent<E>) => void;
|
|
101
|
-
declare const SQLiteEventStoreDefaultStreamVersion = 0n;
|
|
102
|
-
interface SQLiteEventStore extends EventStore<SQLiteReadEventMetadata> {
|
|
103
|
-
appendToStream<EventType extends Event, EventPayloadType extends Event = EventType>(streamName: string, events: EventType[], options?: AppendToStreamOptions<BigIntStreamPosition, EventType, EventPayloadType>): Promise<AppendToStreamResultWithGlobalPosition>;
|
|
104
|
-
consumer<ConsumerEventType extends Event = Event>(options?: SQLiteEventStoreConsumerConfig<ConsumerEventType>): SQLiteEventStoreConsumer<ConsumerEventType>;
|
|
105
|
-
streamExists(streamName: string, options?: SQLiteStreamExistsOptions): Promise<StreamExistsResult>;
|
|
106
|
-
close(): Promise<void>;
|
|
107
|
-
schema: {
|
|
108
|
-
sql(): string;
|
|
109
|
-
print(): void;
|
|
110
|
-
migrate(): Promise<void>;
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
type SQLiteReadEventMetadata = ReadEventMetadataWithGlobalPosition;
|
|
114
|
-
type SQLiteReadEvent<EventType extends Event = Event> = ReadEvent<EventType, SQLiteReadEventMetadata>;
|
|
115
|
-
type SQLiteEventStoreOptions<EventStoreDriver extends AnyEventStoreDriver = AnyEventStoreDriver> = {
|
|
116
|
-
driver: EventStoreDriver;
|
|
117
|
-
projections?: ProjectionRegistration<'inline', SQLiteReadEventMetadata, SQLiteProjectionHandlerContext>[];
|
|
118
|
-
schema?: {
|
|
119
|
-
autoMigration?: 'None' | 'CreateOrUpdate';
|
|
120
|
-
};
|
|
121
|
-
hooks?: {
|
|
122
|
-
/**
|
|
123
|
-
* This hook will be called **BEFORE** event store schema is created
|
|
124
|
-
*/
|
|
125
|
-
onBeforeSchemaCreated?: (context: {
|
|
126
|
-
connection: AnySQLiteConnection;
|
|
127
|
-
}) => Promise<void> | void;
|
|
128
|
-
/**
|
|
129
|
-
* This hook will be called **BEFORE** events were stored in the event store.
|
|
130
|
-
* @type {BeforeEventStoreCommitHandler<SQLiteEventStore, HandlerContext>}
|
|
131
|
-
*/
|
|
132
|
-
onBeforeCommit?: BeforeEventStoreCommitHandler<SQLiteEventStore, {
|
|
133
|
-
connection: AnySQLiteConnection;
|
|
134
|
-
}>;
|
|
135
|
-
/**
|
|
136
|
-
* This hook will be called **AFTER** event store schema was created
|
|
137
|
-
*/
|
|
138
|
-
onAfterSchemaCreated?: () => Promise<void> | void;
|
|
139
|
-
};
|
|
140
|
-
} & {
|
|
141
|
-
pool?: Dumbo;
|
|
142
|
-
} & InferOptionsFromEventStoreDriver<EventStoreDriver>;
|
|
143
|
-
declare const getSQLiteEventStore: <Driver extends AnyEventStoreDriver = AnyEventStoreDriver>(options: SQLiteEventStoreOptions<Driver>) => SQLiteEventStore;
|
|
144
|
-
|
|
145
|
-
type SQLiteProjectionHandlerContext = {
|
|
146
|
-
connection: AnySQLiteConnection;
|
|
147
|
-
};
|
|
148
|
-
type SQLiteProjectionHandler<EventType extends Event = Event, EventMetaDataType extends SQLiteReadEventMetadata = SQLiteReadEventMetadata> = ProjectionHandler<EventType, EventMetaDataType, SQLiteProjectionHandlerContext>;
|
|
149
|
-
type SQLiteProjectionDefinition<EventType extends Event = Event> = ProjectionDefinition<EventType, SQLiteReadEventMetadata, SQLiteProjectionHandlerContext>;
|
|
150
|
-
type SQLiteProjectionHandlerOptions<EventType extends Event = Event> = {
|
|
151
|
-
events: ReadEvent<EventType, SQLiteReadEventMetadata>[];
|
|
152
|
-
projections: SQLiteProjectionDefinition<EventType>[];
|
|
153
|
-
connection: AnySQLiteConnection;
|
|
154
|
-
};
|
|
155
|
-
declare const handleProjections: <EventType extends Event = Event>(options: SQLiteProjectionHandlerOptions<EventType>) => Promise<void>;
|
|
156
|
-
declare const sqliteProjection: <EventType extends Event>(definition: SQLiteProjectionDefinition<EventType>) => SQLiteProjectionDefinition<EventType>;
|
|
157
|
-
type SQLiteRawBatchSQLProjection<EventType extends Event> = {
|
|
158
|
-
evolve: (events: EventType[], context: SQLiteProjectionHandlerContext) => Promise<SQL[]> | SQL[];
|
|
159
|
-
canHandle: CanHandle<EventType>;
|
|
160
|
-
initSQL?: SQL | SQL[];
|
|
161
|
-
init?: (context: ProjectionInitOptions<SQLiteProjectionHandlerContext>) => void | Promise<void>;
|
|
162
|
-
};
|
|
163
|
-
declare const sqliteRawBatchSQLProjection: <EventType extends Event>(options: SQLiteRawBatchSQLProjection<EventType>) => SQLiteProjectionDefinition<EventType>;
|
|
164
|
-
type SQLiteRawSQLProjection<EventType extends Event> = {
|
|
165
|
-
evolve: (events: EventType, context: SQLiteProjectionHandlerContext) => Promise<SQL[]> | SQL[] | Promise<SQL> | SQL;
|
|
166
|
-
canHandle: CanHandle<EventType>;
|
|
167
|
-
initSQL?: SQL | SQL[];
|
|
168
|
-
init?: (context: ProjectionInitOptions<SQLiteProjectionHandlerContext>) => void | Promise<void>;
|
|
169
|
-
};
|
|
170
|
-
declare const sqliteRawSQLProjection: <EventType extends Event>(options: SQLiteRawSQLProjection<EventType>) => SQLiteProjectionDefinition<EventType>;
|
|
171
|
-
|
|
172
|
-
export { type AnyEventStoreDriver as A, type EventStoreDriver as E, type InferOptionsFromEventStoreDriver as I, type SQLiteEventStoreOptions as S, type SQLiteEventStore as a, type SQLiteReadEventMetadata as b, type SQLiteProjectionDefinition as c, type SQLiteProjectionHandlerContext as d, type SQLiteProjectionHandler as e, type SQLiteProjectionHandlerOptions as f, type SQLiteRawBatchSQLProjection as g, handleProjections as h, sqliteRawBatchSQLProjection as i, type SQLiteRawSQLProjection as j, sqliteRawSQLProjection as k, type SQLiteStreamExistsOptions as l, streamExists as m, type EventHandler as n, SQLiteEventStoreDefaultStreamVersion as o, type SQLiteReadEvent as p, getSQLiteEventStore as q, sqliteProjection as s };
|