import { AtomicCheck, AtomicOperation, Kv, KvCommitError, KvCommitResult, KvConsistencyLevel, KvEntry, KvEntryMaybe, KvKey, KvListIterator, KvListOptions, KvListSelector } from "./kv_types.js";
import { _KvU64 } from "./kv_u64.js";
export type EncodeV8 = (value: unknown) => Uint8Array;
export type DecodeV8 = (bytes: Uint8Array) => unknown;
export type KvValueEncoding = "VE_UNSPECIFIED" | "VE_V8" | "VE_LE64" | "VE_BYTES";
export type KvValue = {
    data: Uint8Array;
    encoding: KvValueEncoding;
};
export type KvMutation = {
    key: KvKey;
} & ({
    type: "set";
    value: unknown;
    expireIn?: number;
} | {
    type: "delete";
} | {
    type: "sum";
    value: {
        readonly value: bigint;
    };
} | {
    type: "max";
    value: {
        readonly value: bigint;
    };
} | {
    type: "min";
    value: {
        readonly value: bigint;
    };
});
export declare function unpackKvu(bytes: Uint8Array): _KvU64;
export declare function packKvu(value: _KvU64): Uint8Array;
export declare function readValue(bytes: Uint8Array, encoding: KvValueEncoding, decodeV8: DecodeV8): unknown;
export declare function packKvValue(value: unknown, encodeV8: EncodeV8): KvValue;
export type Cursor = {
    lastYieldedKeyBytes: Uint8Array;
};
export declare function packCursor({ lastYieldedKeyBytes }: Cursor): string;
export declare function unpackCursor(str: string): Cursor;
export declare function checkListSelector(selector: KvListSelector): void;
export declare function checkListOptions(options: KvListOptions): KvListOptions;
export declare const packVersionstamp: (version: number) => string;
export declare const unpackVersionstamp: (versionstamp: string) => number;
export declare const isValidVersionstamp: (versionstamp: string) => boolean;
export declare const replacer: (_this: unknown, v: unknown) => unknown;
export declare class CursorHolder {
    private cursor;
    get(): string;
    set(cursor: string): void;
}
export declare class GenericKvListIterator<T> implements KvListIterator<T> {
    private readonly generator;
    private readonly _cursor;
    constructor(generator: AsyncGenerator<KvEntry<T>>, cursor: () => string);
    get cursor(): string;
    next(): Promise<IteratorResult<KvEntry<T>, undefined>>;
    [Symbol.asyncIterator](): AsyncIterableIterator<KvEntry<T>>;
    return?(value?: any): Promise<IteratorResult<KvEntry<T>, any>>;
    throw?(e?: any): Promise<IteratorResult<KvEntry<T>, any>>;
}
export type Enqueue = {
    value: unknown;
    opts?: {
        delay?: number;
        keysIfUndelivered?: KvKey[];
    };
};
type CommitFn = (checks: AtomicCheck[], mutations: KvMutation[], enqueues: Enqueue[]) => Promise<KvCommitResult | KvCommitError>;
export declare class GenericAtomicOperation implements AtomicOperation {
    private readonly commitFn;
    private readonly checks;
    private readonly mutations;
    private readonly enqueues;
    constructor(commit: CommitFn);
    check(...checks: AtomicCheck[]): this;
    mutate(...mutations: KvMutation[]): this;
    sum(key: KvKey, n: bigint): this;
    min(key: KvKey, n: bigint): this;
    max(key: KvKey, n: bigint): this;
    set(key: KvKey, value: unknown, { expireIn }?: {
        expireIn?: number;
    }): this;
    delete(key: KvKey): this;
    enqueue(value: unknown, opts?: {
        delay?: number;
        keysIfUndelivered?: KvKey[];
    }): this;
    commit(): Promise<KvCommitResult | KvCommitError>;
}
export declare abstract class BaseKv implements Kv {
    protected readonly debug: boolean;
    private closed;
    protected constructor({ debug }: {
        debug: boolean;
    });
    get<T = unknown>(key: KvKey, { consistency }?: {
        consistency?: KvConsistencyLevel;
    }): Promise<KvEntryMaybe<T>>;
    getMany<T>(keys: readonly KvKey[], { consistency }?: {
        consistency?: KvConsistencyLevel;
    }): Promise<any>;
    set(key: KvKey, value: unknown, { expireIn }?: {
        expireIn?: number;
    }): Promise<KvCommitResult>;
    delete(key: KvKey): Promise<void>;
    enqueue(value: unknown, opts?: {
        delay?: number;
        keysIfUndelivered?: KvKey[];
    }): Promise<KvCommitResult>;
    list<T = unknown>(selector: KvListSelector, options?: KvListOptions): KvListIterator<T>;
    listenQueue(handler: (value: unknown) => void | Promise<void>): Promise<void>;
    atomic(additionalWork?: () => void): AtomicOperation;
    watch<T>(keys: readonly KvKey[], options?: {
        raw?: boolean;
    }): ReadableStream<any>;
    close(): void;
    [Symbol.dispose](): void;
    protected abstract get_<T = unknown>(key: KvKey, consistency: KvConsistencyLevel | undefined): Promise<KvEntryMaybe<T>>;
    protected abstract getMany_(keys: readonly KvKey[], consistency: KvConsistencyLevel | undefined): Promise<KvEntryMaybe<unknown>[]>;
    protected abstract listStream<T>(outCursor: CursorHolder, selector: KvListSelector, opts: KvListOptions): AsyncGenerator<KvEntry<T>>;
    protected abstract listenQueue_(handler: (value: unknown) => void | Promise<void>): Promise<void>;
    protected abstract commit(checks: AtomicCheck[], mutations: KvMutation[], enqueues: Enqueue[], additionalWork?: () => void): Promise<KvCommitResult | KvCommitError>;
    protected abstract watch_(keys: readonly KvKey[], raw: boolean | undefined): ReadableStream<KvEntryMaybe<unknown>[]>;
    protected abstract close_(): void;
    private checkOpen;
}
export declare class Expirer {
    private readonly debug;
    private readonly expireFn;
    private minExpires;
    private expirerTimeout;
    constructor(debug: boolean, expireFn: () => number | undefined);
    init(minExpires: number | undefined): void;
    rescheduleExpirer(expires: number): void;
    finalize(): void;
    private runExpirer;
}
export type QueueHandler = (value: unknown) => void | Promise<void>;
export declare class QueueWorker {
    private readonly workerFn;
    private workerTimeout;
    private queueHandler?;
    private queueHandlerPromise?;
    constructor(workerFn: (queueHandler?: QueueHandler) => void);
    listen(handler: QueueHandler): Promise<void>;
    rescheduleWorker(delay?: number): void;
    finalize(): void;
}
export {};
