import type { CommonLogger } from '@naturalcycles/js-lib/log';
import type { AnyObjectWithId, ObjectWithId, StringMap } from '@naturalcycles/js-lib/types';
import type { JsonSchema } from '@naturalcycles/nodejs-lib/ajv';
import { Pipeline } from '@naturalcycles/nodejs-lib/stream';
import type { CommonDB, CommonDBSupport } from '../commondb/common.db.js';
import { CommonDBType } from '../commondb/common.db.js';
import type { CommonDBCreateOptions, CommonDBOptions, CommonDBSaveOptions, CommonDBTransactionOptions, DBOperation, DBTransaction, DBTransactionFn, RunQueryResult } from '../db.model.js';
import type { DBQuery } from '../query/dbQuery.js';
export interface InMemoryDBCfg {
    /**
     * @default ''
     *
     * Allows to support "Namespacing".
     * E.g, pass `ns1_` to it and all tables will be prefixed by it.
     * Reset cache respects this prefix (won't touch other namespaces!)
     */
    tablesPrefix: string;
    /**
     * Many DB implementations (e.g Datastore and Firestore) forbid doing
     * read operations after a write/delete operation was done inside a Transaction.
     *
     * To help spot that type of bug - InMemoryDB by default has this setting to `true`,
     * which will throw on such occasions.
     *
     * Defaults to true.
     */
    forbidTransactionReadAfterWrite?: boolean;
    /**
     * Defaults to `console`.
     */
    logger?: CommonLogger;
}
export declare class InMemoryDB implements CommonDB {
    dbType: CommonDBType;
    support: CommonDBSupport;
    constructor(cfg?: Partial<InMemoryDBCfg>);
    cfg: InMemoryDBCfg;
    data: StringMap<StringMap<AnyObjectWithId>>;
    /**
     * Returns internal "Data snapshot".
     * Deterministic - jsonSorted.
     */
    getDataSnapshot(): StringMap<StringMap<ObjectWithId>>;
    ping(): Promise<void>;
    /**
     * Resets InMemory DB data
     */
    resetCache(_table?: string): Promise<void>;
    getTables(): Promise<string[]>;
    getTableSchema<ROW extends ObjectWithId>(_table: string): Promise<JsonSchema<ROW>>;
    createTable<ROW extends ObjectWithId>(_table: string, _schema: JsonSchema<ROW>, opt?: CommonDBCreateOptions): Promise<void>;
    getByIds<ROW extends ObjectWithId>(_table: string, ids: string[], _opt?: CommonDBOptions): Promise<ROW[]>;
    multiGet<ROW extends ObjectWithId>(map: StringMap<string[]>, _opt?: CommonDBOptions): Promise<StringMap<ROW[]>>;
    saveBatch<ROW extends ObjectWithId>(_table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
    multiSave<ROW extends ObjectWithId>(map: StringMap<ROW[]>, opt?: CommonDBSaveOptions<ROW>): Promise<void>;
    patchById<ROW extends ObjectWithId>(_table: string, id: string, patch: Partial<ROW>, _opt?: CommonDBOptions): Promise<void>;
    deleteByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
    deleteByIds(_table: string, ids: string[], _opt?: CommonDBOptions): Promise<number>;
    multiDelete(map: StringMap<string[]>, _opt?: CommonDBOptions): Promise<number>;
    patchByQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, patch: Partial<ROW>): Promise<number>;
    runQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<RunQueryResult<ROW>>;
    runQueryCount<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Promise<number>;
    streamQuery<ROW extends ObjectWithId>(q: DBQuery<ROW>, _opt?: CommonDBOptions): Pipeline<ROW>;
    runInTransaction(fn: DBTransactionFn, opt?: CommonDBTransactionOptions): Promise<void>;
    createTransaction(opt?: CommonDBTransactionOptions): Promise<DBTransaction>;
    incrementBatch(table: string, prop: string, incrementMap: StringMap<number>, _opt?: CommonDBOptions): Promise<StringMap<number>>;
}
export declare class InMemoryDBTransaction implements DBTransaction {
    private db;
    private opt;
    constructor(db: InMemoryDB, opt: Required<CommonDBTransactionOptions>);
    ops: DBOperation[];
    writeOperationHappened: boolean;
    getByIds<ROW extends ObjectWithId>(table: string, ids: string[], opt?: CommonDBOptions): Promise<ROW[]>;
    saveBatch<ROW extends ObjectWithId>(table: string, rows: ROW[], opt?: CommonDBSaveOptions<ROW>): Promise<void>;
    deleteByIds(table: string, ids: string[], opt?: CommonDBOptions): Promise<number>;
    commit(): Promise<void>;
    rollback(): Promise<void>;
}
