import { type AbstractType } from "@dao-xyz/borsh"; import type { QueryCacheOptions } from "@peerbit/indexer-cache"; import * as indexerTypes from "@peerbit/indexer-interface"; import { type Change, Entry, type ShallowOrFullEntry, type TrimOptions } from "@peerbit/log"; import { Program, type ProgramEvents } from "@peerbit/program"; import { type EntryReplicated, type ReplicationDomain, type SharedAppendOptions, SharedLog, type SharedLogOptions } from "@peerbit/shared-log"; import type { CustomDocumentDomain } from "./domain.js"; import type { DocumentEvents } from "./events.js"; import { DeleteOperation, type Operation, PutOperation } from "./operation.js"; import { type CanRead, type CanSearch, DocumentIndex, type GetOptions, type PrefetchOptions, type ReachScope, type TransformOptions } from "./search.js"; export declare class OperationError extends Error { constructor(message?: string); } type MaybePromise = Promise | T; export type CountEstimate = { estimate: number; /** * Relative error margin (0..1), where e.g. `0.1` means ~±10%. * * Only non-`undefined` when the replication domain is expected to be uniformly * distributed (currently: `domain.type === "hash"`), and when there is * sufficient local sample information to compute it. * * When `undefined`, the caller should treat `estimate` as unreliable. */ errorMargin: number | undefined; }; type CanPerformPut = { type: "put"; value: T; operation: PutOperation; entry: Entry; }; type CanPerformDelete = { type: "delete"; operation: DeleteOperation; entry: Entry; }; export type CanPerformOperations = CanPerformPut | CanPerformDelete; export type CanPerform = (properties: CanPerformOperations) => MaybePromise; type InferR = D extends ReplicationDomain ? I : "u32"; export type SetupOptions = T extends Record ? T : any, D extends ReplicationDomain = any> = { type: AbstractType; canOpen?: (program: T) => MaybePromise; canPerform?: CanPerform; strictHistory?: boolean; id?: (obj: any) => indexerTypes.IdPrimitive; index?: { canSearch?: CanSearch; canRead?: CanRead; idProperty?: string | string[]; cache?: { resolver?: number; query?: QueryCacheOptions; }; prefetch?: boolean | Partial; includeIndexed?: boolean; } & TransformOptions; log?: { trim?: TrimOptions; }; compatibility?: 6 | 7; domain?: (db: Documents) => CustomDocumentDomain>; keep?: ((entry: ShallowOrFullEntry | EntryReplicated>) => Promise | boolean) | "self"; } & Omit>, "compatibility" | "domain" | "keep">; export type ExtractArgs = T extends ReplicationDomain ? Args : never; export declare class Documents = T extends Record ? T : any, D extends ReplicationDomain = any> extends Program, DocumentEvents & ProgramEvents> { log: SharedLog>; immutable: boolean; private _index; private _clazz; private _optionCanPerform?; private idResolver; private domain?; private strictHistory; canOpen?: (program: T) => Promise | boolean; compatibility: 6 | 7 | undefined; constructor(properties?: { id?: Uint8Array; immutable?: boolean; index?: DocumentIndex>; }); get index(): DocumentIndex; private getLocalIndexedContext; private getExistingContext; get changes(): import("@libp2p/interface").TypedEventTarget & ProgramEvents>; private maybeSubprogramOpen; private keepCache; open(options: SetupOptions): Promise; recover(): Promise; private _resolveEntry; protected canAppend(entry: Entry, reference?: { document: T; operation: PutOperation; }): Promise; protected _canAppend(entry: Entry, reference?: { document: T; operation: PutOperation; }): Promise; put(doc: T, options?: SharedAppendOptions & { unique?: boolean; replicate?: boolean; checkRemote?: boolean; }): Promise<{ entry: Entry; removed: ShallowOrFullEntry[]; }>; get(id: indexerTypes.Ideable | indexerTypes.IdKey, options?: Omit, "resolve">): Promise; del(id: indexerTypes.Ideable | indexerTypes.IdKey, options?: SharedAppendOptions): Promise<{ entry: Entry; removed: ShallowOrFullEntry[]; }>; handleChanges(change: Change, reference?: { document: T; operation: PutOperation; unique?: boolean; }): Promise; /** * Count documents locally (default), or estimate the global count. * * - `count()` / `count({ query })`: exact local count from the index. * - `count({ approximate: true })`: estimated global count from replication metadata (no remote queries) + error margin when available. */ count(options?: { query?: indexerTypes.Query | indexerTypes.QueryLike; approximate?: false | undefined; }): Promise; count(options: { query?: indexerTypes.Query | indexerTypes.QueryLike; approximate: true | { scope?: ReachScope; }; }): Promise; } export {}; //# sourceMappingURL=program.d.ts.map