import { P as Promisable, I as IGenericSqlite } from './type-dQxYJ4xm.js';
import { QueryResult } from 'kysely';

declare const initEvent = "0";
declare const runEvent = "1";
declare const closeEvent = "2";
declare const dataEvent = "3";
type InitMsg<T extends Record<string, unknown>> = [
    type: typeof initEvent,
    data: T
];
type RunMsg = [
    type: typeof runEvent,
    isSelect: boolean,
    sql: string,
    parameters?: readonly unknown[]
];
type StreamMsg = [
    type: typeof dataEvent,
    isSelect: boolean,
    sql: string,
    parameters?: readonly unknown[]
];
type CloseMsg = [type: typeof closeEvent];
type MainToWorkerMsg<T extends Record<string, unknown>> = InitMsg<T> | RunMsg | CloseMsg | StreamMsg;
type WorkerToMainMsg = {
    [K in keyof Events]: [type: `${K}`, data: Events[K], err: unknown];
}[keyof Events];
type Events = {
    0: null;
    1: QueryResult<any> | null;
    2: null;
    3: QueryResult<any>[] | null;
    4: null;
};
interface IGenericWorker {
    postMessage: (message: any) => void;
    terminate: () => void;
}
interface IGenericEventEmitter {
    emit: (eventName: string, ...args: any[]) => void;
    on: (eventName: string, callback: (...value: any[]) => void) => void;
    once: (eventName: string, callback: (...value: any[]) => void) => void;
    /**
     * Clear target or all listeners
     * @param eventName optional event name
     */
    off: (eventName?: string) => void;
}
type HandleMessageFn<T extends IGenericWorker> = (worker: T, cb: (msg: WorkerToMainMsg) => any) => void;
interface IGenericSqliteWorkerExecutor<W extends IGenericWorker, T extends Record<string, unknown>> {
    /**
     * Extra data, as parameter in {@link InitFn}
     */
    data?: T;
    /**
     * Worker creator
     */
    worker: W;
    /**
     * Event emitter that used for dispatch messages from worker
     */
    mitt: IGenericEventEmitter;
    /**
     * Convert data in worker message event callback and send to mitt
     */
    handle: HandleMessageFn<W>;
}
/**
 * Initialize function for {@link createGenericOnMessageCallback}
 */
type InitFn<T extends Record<string, unknown>, DB = unknown> = (data: T) => Promisable<IGenericSqlite<DB>>;
/**
 * Function that handle all message
 */
type MessageHandleFn<DB = unknown> = (exec: IGenericSqlite<DB>, type: string, data1: unknown, data2: unknown, data3: unknown) => Promisable<any>;

export type { HandleMessageFn as H, IGenericWorker as I, MessageHandleFn as M, IGenericSqliteWorkerExecutor as a, InitFn as b, MainToWorkerMsg as c, IGenericEventEmitter as d };
