import type * as Atom from '@effect-atom/atom/Atom'; import * as Effect from 'effect/Effect'; import * as Option from 'effect/Option'; import { type CleanupFn } from '@dxos/async'; import type * as Entity from './Entity'; /** * Individual query result entry. */ export type Entry = { id: string; /** * May not be present for remote results. */ result?: T; match?: { /** * Higher means better match. */ rank: number; }; /** * Query resolution metadata. */ resolution?: { source: 'remote' | 'local' | 'index'; /** * Query resolution time in milliseconds. */ time: number; }; }; /** * Invidual query result entry for a database Entity. */ export type EntityEntry = Entry; export type RunOptions = { timeout?: number; }; export type SubscriptionOptions = { /** * Fire the callback immediately. */ fire?: boolean; }; export interface QueryResult { /** * Currently available results along with their match metadata. */ readonly entries: Entry[]; /** * Currently available results. */ readonly results: T[]; /** * Returns all known results. */ run(opts?: RunOptions): Promise; /** * Returns all known results along with their match metadata. */ runEntries(opts?: RunOptions): Promise[]>; /** * Returns currently available results synchronously. */ runSync(): T[]; /** * Returns currently available results synchronously along with their match metadata. */ runSyncEntries(): Entry[]; /** * Returns first result. */ first(opts?: RunOptions): Promise; /** * Returns first result if there is one. */ firstOrUndefined(opts?: RunOptions): Promise; /** * Subscribes to changes in query results. */ subscribe(callback?: (query: QueryResult) => void, opts?: SubscriptionOptions): CleanupFn; /** * Self-updating atom. Updates automatically when query results change. * * Memoized per QueryResult instance — repeated accesses on the same instance return the same * Atom. Safe only when the QueryResult is itself held stable across re-renders (e.g. behind a * `useMemo`). It must NOT be used in graph-builder connectors/actions or other atom computes, * where `db.query(...)` is called fresh on each re-evaluation: every run constructs a new * QueryResult and so a new atom + subscription, leaking the previous ones. Use the memoized * {@link atom} family there instead. */ readonly atom: Atom.Atom; } /** * Effect that returns a QueryResult when evaluated, but also has shorthand methods for running the query or getting the first result. */ export interface QueryResultEffect extends Effect.Effect, E, R> { run: Effect.Effect; first: Effect.Effect, E, R>; } //# sourceMappingURL=QueryResult.d.ts.map