import { LangName, StrictSchema } from '@based/schema';
import { SchemaTypesParsed, SchemaTypesParsedById } from '@based/schema/def';
import { createTree } from './csmt/index.js';
import { CsmtNodeRange } from './tree.js';
import { Worker, MessagePort } from 'node:worker_threads';
import { TransformFns } from './migrate/index.js';
import exitHook from 'exit-hook';
export declare const SCHEMA_FILE = "schema.json";
export declare const WRITELOG_FILE = "writelog.json";
declare class SortIndex {
    constructor(buf: Uint8Array, dbCtxExternal: any);
    buf: Uint8Array;
    idx: any;
    cnt: number;
}
export declare class DbWorker {
    constructor(address: BigInt, db: DbServer);
    db: DbServer;
    channel: MessagePort;
    worker: Worker;
    resolvers: any[];
    callback: (resolve: any) => void;
    updateCtx(address: BigInt): Promise<void>;
    getQueryBuf(buf: Uint8Array): Promise<Uint8Array>;
}
type OnSchemaChange = (schema: DbServer['schema']) => void;
export declare class DbServer {
    #private;
    modifyDirtyRanges: Float64Array;
    dbCtxExternal: any;
    schema: StrictSchema & {
        lastId: number;
        hash?: number;
    };
    migrating: number;
    schemaTypesParsed: SchemaTypesParsed;
    schemaTypesParsedById: SchemaTypesParsedById;
    fileSystemPath: string;
    maxModifySize: number;
    merkleTree: ReturnType<typeof createTree<CsmtNodeRange>>;
    dirtyRanges: Set<number>;
    csmtHashFun: {
        update: (buf: Uint8Array) => any;
        digest: (encoding?: "hex") => Uint8Array | string;
        reset: () => void;
    };
    workers: DbWorker[];
    availableWorkerIndex: number;
    processingQueries: number;
    modifyQueue: Uint8Array[];
    queryQueue: Map<Function, Uint8Array>;
    stopped: boolean;
    onSchemaChange: OnSchemaChange;
    unlistenExit: ReturnType<typeof exitHook>;
    saveIntervalInSeconds?: number;
    saveInterval?: NodeJS.Timeout;
    constructor({ path, maxModifySize, onSchemaChange, debug, saveIntervalInSeconds, }: {
        path: string;
        maxModifySize?: number;
        onSchemaChange?: OnSchemaChange;
        debug?: boolean;
        saveIntervalInSeconds?: number;
    });
    start(opts?: {
        clean?: boolean;
        hosted?: boolean;
    }): Promise<void>;
    save(opts?: {
        forceFullDump?: boolean;
    }): Promise<void>;
    createCsmtHashFun: () => {
        update: (buf: Uint8Array) => any;
        digest: (encoding?: "hex") => Uint8Array | string;
        reset: () => void;
    };
    sortIndexes: {
        [type: number]: {
            [field: number]: {
                [start: number]: {
                    [lang: number]: SortIndex;
                };
            };
        };
    };
    cleanupTimer: NodeJS.Timeout;
    cleanup(): void;
    createSortIndex(type: string, field: string, lang?: LangName): SortIndex;
    destroySortIndex(type: string, field: string, lang?: LangName): any;
    getSortIndex(typeId: number, field: number, start: number, lang: number): SortIndex;
    migrateSchema(schema: StrictSchema, transform?: Record<string, (node: Record<string, any>) => Record<string, any> | [string, Record<string, any>]>): Promise<StrictSchema & {
        lastId: number;
        hash?: number;
    }>;
    createSortIndexBuffer(typeId: number, field: number, start: number, lang: number): SortIndex;
    setSchema(strictSchema: StrictSchema, fromStart?: boolean, transformFns?: TransformFns): (StrictSchema & {
        lastId: number;
        hash?: number;
    }) | Promise<StrictSchema & {
        lastId: number;
        hash?: number;
    }>;
    modify(buf: Uint8Array): Record<number, number> | null;
    addToQueryQueue(resolve: any, buf: any): void;
    getQueryBuf(buf: Uint8Array, fromQueue?: boolean): Promise<Uint8Array>;
    onQueryEnd(): void;
    stop(noSave?: boolean): Promise<void>;
    destroy(): Promise<void>;
}
export {};
