import type { Filter, TrustedEvent } from "@welshman/util"; import type { DeleteRecord, QueryOptions } from "../../core.js"; export type SqlValue = string | number | null | Uint8Array; /** The synchronous slice of a SQLite connection the engine needs, so any binding can back it. */ export interface SqliteDatabase { exec(sql: string): void; run(sql: string, params?: SqlValue[]): void; all(sql: string, params?: SqlValue[]): T[]; /** Define a deterministic SQL function of one argument on this connection. */ define(name: string, f: (value: SqlValue) => SqlValue): void; } /** Run `f` in a transaction, rolling back if it throws. */ export declare const transaction: (db: SqliteDatabase, f: () => void) => void; /** One step of a write batch. A publish carries whether it was verified and its tracked relays. */ export type WriteOp = ["publish", TrustedEvent, boolean, string[]] | ["remove", string] | ["track", string, string] | ["untrack", string, string]; /** An event as stored, and whether its signature was checked before it was. */ export type StoredEvent = { json: string; verified: boolean; }; /** A change to the deletes, which a client mirroring `DeleteIndex` applies in order. */ export type DeleteChange = ["add", string, DeleteRecord] | ["withdraw", string]; /** What a batch changed, with `restored` carrying the events the caller didn't pass in. */ export type WriteResult = { added: string[]; restored: StoredEvent[]; relays: [string, string[]][]; removed: string[]; deletes: DeleteChange[]; }; /** Events as stored, with every relay each was seen on. */ export type QueryResult = { events: StoredEvent[]; relays: [string, string[]][]; }; /** What a write changed, with the ops that made it, which every connection applies in this order. */ export type WriteChange = { type: "write"; ops: WriteOp[]; result: WriteResult; }; /** A change to the database, which other connections hear about in the order committed. */ export type SqliteChange = WriteChange | { type: "clear"; }; /** The repository's semantics in SQL, answering every query as `MemoryRepository` does. */ export declare class SqliteEngine { readonly db: SqliteDatabase; constructor(db: SqliteDatabase); migrate: () => void; query: (filters: Filter[], options?: QueryOptions) => QueryResult; count: (filters: Filter[], options?: QueryOptions) => number; countTags: (name: string) => [string, number][]; getEvent: (idOrAddress: string) => QueryResult; getDeletes: () => [string, DeleteRecord][]; write: (ops: WriteOp[]) => WriteChange; /** Drop every event matching `filters` outright, with nothing restored in its place. */ evict: (filters: Filter[]) => WriteChange; /** Drops expired events, which nothing else removes. */ prune: () => WriteChange; clear: () => SqliteChange; private transaction; private change; private batch; private selectFilter; private getRelays; private getRow; private exists; private isVisible; private isDeleted; private addRelays; private addDelete; private drop; private evictEvent; private hiddenBy; private uncover; private publish; private remove; } //# sourceMappingURL=engine.d.ts.map