import sqlite3 from 'sqlite3'; import { Event, ReadEvent, ReadEventMetadataWithGlobalPosition, EmmettError, EventStore, AppendToStreamOptions, BigIntStreamPosition, AppendToStreamResultWithGlobalPosition, StreamExistsResult, ProjectionRegistration, BeforeEventStoreCommitHandler, ProjectionHandler, ProjectionDefinition, CanHandle, ProjectionInitOptions, ThenThrows, ReadEventMetadata, ReadStreamOptions, ReadStreamResult } from '@event-driven-io/emmett'; type Parameters$1 = object | string | bigint | number | boolean | null; type SQLiteConnection = { close: () => void; command: (sql: string, values?: Parameters$1[]) => Promise; batchCommand: (sqls: string[]) => Promise; query: (sql: string, values?: Parameters$1[]) => Promise; querySingle: (sql: string, values?: Parameters$1[]) => Promise; withTransaction: (fn: () => Promise) => Promise; }; interface SQLiteError extends Error { errno: number; } declare const isSQLiteError: (error: unknown) => error is SQLiteError; type InMemorySharedCacheSQLiteDatabase = 'file::memory:?cache=shared'; declare const InMemorySharedCacheSQLiteDatabase = "file::memory:?cache=shared"; type InMemorySQLiteDatabase = ':memory:'; declare const InMemorySQLiteDatabase = ":memory:"; type SQLiteConnectionOptions = { fileName: InMemorySQLiteDatabase | string | undefined; }; declare const sqliteConnection: (options: SQLiteConnectionOptions) => SQLiteConnection; type SQLiteConnectionPoolOptions = { fileName: InMemorySQLiteDatabase | InMemorySharedCacheSQLiteDatabase | string | undefined; connectionOptions?: { singleton: true; connection?: SQLiteConnection; } | { singleton?: false; connection?: never; }; }; type SQLiteConnectionPool = { connection: () => Promise; withConnection: (handle: (connection: SQLiteConnection) => Promise) => Promise; close: () => Promise; }; declare const SQLiteConnectionPool: (options: SQLiteConnectionPoolOptions) => SQLiteConnectionPool; type SQLiteEventStoreMessageBatchPullerStartFrom = { globalPosition: bigint; } | 'BEGINNING' | 'END'; type SQLiteProcessorEventsBatch = { messages: ReadEvent[]; }; type SQLiteProcessorHandlerContext = { connection: SQLiteConnection; fileName: string; }; type SQLiteProcessor = { id: string; start: (connection: SQLiteConnection) => Promise; isActive: boolean; handle: (messagesBatch: SQLiteProcessorEventsBatch, context: { connection?: SQLiteConnection; fileName?: string; }) => Promise; }; declare const SQLiteProcessor: { result: { skip: (options?: { reason?: string; }) => SQLiteProcessorMessageHandlerResult; stop: (options?: { reason?: string; error?: EmmettError; }) => SQLiteProcessorMessageHandlerResult; }; }; type SQLiteProcessorMessageHandlerResult = void | { type: 'SKIP'; reason?: string; } | { type: 'STOP'; reason?: string; error?: EmmettError; }; type SQLiteProcessorEachMessageHandler = (event: ReadEvent, context: SQLiteProcessorHandlerContext) => Promise | SQLiteProcessorMessageHandlerResult; type SQLiteProcessorStartFrom = SQLiteEventStoreMessageBatchPullerStartFrom | 'CURRENT'; type SQLiteProcessorConnectionOptions = { fileName: string; connection?: SQLiteConnection; }; type GenericSQLiteProcessorOptions = { processorId: string; version?: number; partition?: string; startFrom?: SQLiteProcessorStartFrom; stopAfter?: (message: ReadEvent) => boolean; eachMessage: SQLiteProcessorEachMessageHandler; connectionOptions?: SQLiteProcessorConnectionOptions; }; type SQLiteProjectionProcessorOptions = { processorId?: string; version?: number; projection: SQLiteProjectionDefinition; partition?: string; startFrom?: SQLiteProcessorStartFrom; stopAfter?: (message: ReadEvent) => boolean; }; type SQLiteProcessorOptions = GenericSQLiteProcessorOptions | SQLiteProjectionProcessorOptions; type SQLiteEventStoreConsumerConfig = { processors?: SQLiteProcessor[]; pulling?: { batchSize?: number; pullingFrequencyInMs?: number; }; }; type SQLiteEventStoreConsumer = Readonly<{ isRunning: boolean; processors: SQLiteProcessor[]; processor: (options: SQLiteProcessorOptions) => SQLiteProcessor; start: () => Promise; stop: () => Promise; close: () => Promise; }>; type SQLiteStreamExistsOptions = { partition: string; }; type EventHandler = (eventEnvelope: ReadEvent) => void; declare const SQLiteEventStoreDefaultStreamVersion = 0n; interface SQLiteEventStore extends EventStore { appendToStream(streamName: string, events: EventType[], options?: AppendToStreamOptions): Promise; consumer(options?: SQLiteEventStoreConsumerConfig): SQLiteEventStoreConsumer; streamExists(streamName: string, options?: SQLiteStreamExistsOptions): Promise; schema: { sql(): string; print(): void; migrate(): Promise; }; } type SQLiteReadEventMetadata = ReadEventMetadataWithGlobalPosition; type SQLiteReadEvent = ReadEvent; type SQLiteEventStoreConnectionOptions = { connection: SQLiteConnection; }; type SQLiteEventStoreOptions = { projections?: ProjectionRegistration<'inline', SQLiteReadEventMetadata, SQLiteProjectionHandlerContext>[]; schema?: { autoMigration?: 'None' | 'CreateOrUpdate'; }; hooks?: { /** * This hook will be called **BEFORE** event store schema is created */ onBeforeSchemaCreated?: (context: { connection: SQLiteConnection; }) => Promise | void; /** * This hook will be called **BEFORE** events were stored in the event store. * @type {BeforeEventStoreCommitHandler} */ onBeforeCommit?: BeforeEventStoreCommitHandler; /** * This hook will be called **AFTER** event store schema was created */ onAfterSchemaCreated?: () => Promise | void; }; } & SQLiteConnectionPoolOptions & { pool?: SQLiteConnectionPool; }; declare const getSQLiteEventStore: (options: SQLiteEventStoreOptions) => SQLiteEventStore; type SQLiteProjectionHandlerContext = { connection: SQLiteConnection; }; type SQLiteProjectionHandler = ProjectionHandler; type SQLiteProjectionDefinition = ProjectionDefinition; type SQLiteProjectionHandlerOptions = { events: ReadEvent[]; projections: SQLiteProjectionDefinition[]; connection: SQLiteConnection; }; declare const handleProjections: (options: SQLiteProjectionHandlerOptions) => Promise; declare const sqliteProjection: (definition: SQLiteProjectionDefinition) => SQLiteProjectionDefinition; type SQLiteRawBatchSQLProjection = { evolve: (events: EventType[], context: SQLiteProjectionHandlerContext) => Promise | string[]; canHandle: CanHandle; initSQL?: string | string[]; init?: (context: ProjectionInitOptions) => void | Promise; }; declare const sqliteRawBatchSQLProjection: (options: SQLiteRawBatchSQLProjection) => SQLiteProjectionDefinition; type SQLiteRawSQLProjection = { evolve: (events: EventType, context: SQLiteProjectionHandlerContext) => Promise | string[] | Promise | string; canHandle: CanHandle; initSQL?: string | string[]; init?: (context: ProjectionInitOptions) => void | Promise; }; declare const sqliteRawSQLProjection: (options: SQLiteRawSQLProjection) => SQLiteProjectionDefinition; type SQLiteProjectionSpecEvent = EventType & { metadata?: Partial; }; type SQLiteProjectionSpecWhenOptions = { numberOfTimes: number; }; type SQLiteProjectionAssert = (options: { connection: SQLiteConnection; }) => Promise; type SQLiteProjectionSpecOptions = { fileName?: string; connection?: SQLiteConnection; projection: SQLiteProjectionDefinition; }; type SQLiteProjectionSpec = (givenEvents: SQLiteProjectionSpecEvent[]) => { when: (events: SQLiteProjectionSpecEvent[], options?: SQLiteProjectionSpecWhenOptions) => { then: (assert: SQLiteProjectionAssert, message?: string) => Promise; thenThrows: (...args: Parameters>) => Promise; }; }; declare const SQLiteProjectionSpec: { for: (options: SQLiteProjectionSpecOptions) => SQLiteProjectionSpec; }; declare const eventInStream: (streamName: string, event: SQLiteProjectionSpecEvent) => SQLiteProjectionSpecEvent; declare const eventsInStream: (streamName: string, events: SQLiteProjectionSpecEvent[]) => SQLiteProjectionSpecEvent[]; declare const newEventsInStream: (streamName: string, events: SQLiteProjectionSpecEvent[]) => SQLiteProjectionSpecEvent[]; declare const assertSQLQueryResultMatches: (sql: string, rows: T[]) => SQLiteProjectionAssert; declare const expectSQL: { query: (sql: string) => { resultRows: { toBeTheSame: (rows: T[]) => SQLiteProjectionAssert; }; }; }; type AppendEventResult = { success: true; nextStreamPosition: bigint; lastGlobalPosition: bigint; } | { success: false; }; declare const appendToStream: (connection: SQLiteConnection, streamName: string, streamType: string, messages: MessageType[], options?: AppendToStreamOptions & { partition?: string; onBeforeCommit?: BeforeEventStoreCommitHandler; }) => Promise; type ReadLastMessageGlobalPositionResult = { currentGlobalPosition: bigint | null; }; declare const readLastMessageGlobalPosition: (db: SQLiteConnection, options?: { partition?: string; }) => Promise; type ReadMessagesBatchOptions = { after: bigint; batchSize: number; } | { from: bigint; batchSize: number; } | { to: bigint; batchSize: number; } | { from: bigint; to: bigint; }; type ReadMessagesBatchResult = { currentGlobalPosition: bigint; messages: ReadEvent[]; areEventsLeft: boolean; }; declare const readMessagesBatch: (db: SQLiteConnection, options: ReadMessagesBatchOptions & { partition?: string; }) => Promise>; type ReadProcessorCheckpointResult = { lastProcessedPosition: bigint | null; }; declare const readProcessorCheckpoint: (db: SQLiteConnection, options: { processorId: string; partition?: string; }) => Promise; declare const readStream: (db: SQLiteConnection, streamId: string, options?: ReadStreamOptions & { partition?: string; }) => Promise>; type StoreLastProcessedProcessorPositionResult = { success: true; newPosition: Position; } | { success: false; reason: 'IGNORED' | 'MISMATCH'; }; declare function storeProcessorCheckpoint(db: SQLiteConnection, options: { processorId: string; version: number | undefined; newPosition: bigint | null; lastProcessedPosition: bigint | null; partition?: string; }): Promise>; declare const sql: (sql: string) => string; declare const streamsTableSQL: string; declare const messagesTableSQL: string; declare const processorsTableSQL: string; declare const projectionsTableSQL: string; declare const schemaSQL: string[]; declare const createEventStoreSchema: (connection: SQLiteConnection, hooks?: SQLiteEventStoreOptions["hooks"]) => Promise; declare const emmettPrefix = "emt"; declare const globalTag = "global"; declare const defaultTag = "emt:default"; declare const unknownTag = "emt:unknown"; declare const globalNames: { module: string; }; declare const streamsTable: { name: string; columns: { partition: { name: string; }; isArchived: { name: string; }; }; }; declare const messagesTable: { name: string; columns: { partition: { name: string; }; isArchived: { name: string; }; }; }; declare const processorsTable: { name: string; }; declare const projectionsTable: { name: string; }; declare const schema_0_41_0: string[]; declare const migration_0_42_0_SQLs: string[]; declare const migration_0_42_0_FromSubscriptionsToProcessors: (connection: SQLiteConnection) => Promise; declare const schema_0_42_0: string[]; export { type AppendEventResult, type EventHandler, InMemorySQLiteDatabase, InMemorySharedCacheSQLiteDatabase, type Parameters$1 as Parameters, type ReadLastMessageGlobalPositionResult, type ReadMessagesBatchOptions, type ReadMessagesBatchResult, type ReadProcessorCheckpointResult, type SQLiteConnection, SQLiteConnectionPool, type SQLiteConnectionPoolOptions, type SQLiteError, type SQLiteEventStore, type SQLiteEventStoreConnectionOptions, SQLiteEventStoreDefaultStreamVersion, type SQLiteEventStoreOptions, type SQLiteProjectionAssert, type SQLiteProjectionDefinition, type SQLiteProjectionHandler, type SQLiteProjectionHandlerContext, type SQLiteProjectionHandlerOptions, SQLiteProjectionSpec, type SQLiteProjectionSpecEvent, type SQLiteProjectionSpecOptions, type SQLiteProjectionSpecWhenOptions, type SQLiteRawBatchSQLProjection, type SQLiteRawSQLProjection, type SQLiteReadEvent, type SQLiteReadEventMetadata, type StoreLastProcessedProcessorPositionResult, appendToStream, assertSQLQueryResultMatches, createEventStoreSchema, defaultTag, emmettPrefix, eventInStream, eventsInStream, expectSQL, getSQLiteEventStore, globalNames, globalTag, handleProjections, isSQLiteError, messagesTable, messagesTableSQL, migration_0_42_0_FromSubscriptionsToProcessors, migration_0_42_0_SQLs, newEventsInStream, processorsTable, processorsTableSQL, projectionsTable, projectionsTableSQL, readLastMessageGlobalPosition, readMessagesBatch, readProcessorCheckpoint, readStream, schemaSQL, schema_0_41_0, schema_0_42_0, sql, sqliteConnection, sqliteProjection, sqliteRawBatchSQLProjection, sqliteRawSQLProjection, storeProcessorCheckpoint, streamsTable, streamsTableSQL, unknownTag };