/** * watchById() implementation for reactive single-entity queries. * * Thin wrapper over watch() that filters by ID and maps results to T | null. * Emits the entity when it exists, or null when it's deleted or doesn't exist. */ import { Effect, type PubSub, type Ref, Stream } from "effect"; import type { ChangeEvent } from "../types/reactive-types.js"; import { type WatchQueryConfig } from "./watch.js"; /** * Entity constraint: must have a readonly string `id` field. */ type HasId = { readonly id: string; }; /** * Creates a reactive watch stream for a single entity by ID. * * This is a thin wrapper over watch() that: * 1. Filters by `where: { id }` to only match the specific entity * 2. Maps the result array to `T | null` (first element or null if empty) * * The stream: * - Emits the entity immediately if it exists, or null if not * - Re-emits when the entity is created, updated, or deleted * - Emits null when the entity is deleted (result array becomes empty) * - Is scoped: auto-cleanup when scope closes or stream is interrupted * * @param pubsub - The PubSub broadcasting ChangeEvents from mutations * @param ref - The collection Ref containing entities keyed by ID * @param collectionName - Name of the collection to watch (for filtering events) * @param id - The entity ID to watch * @param config - Optional additional watch configuration (debounceMs) * @returns Scoped Effect producing a Stream of T | null * * @example * ```ts * const program = Effect.gen(function* () { * const pubsub = yield* createChangePubSub() * const ref = yield* createCollectionState([ * { id: "1", title: "Dune", author: "Frank Herbert" } * ]) * * const stream = yield* watchById(pubsub, ref, "books", "1") * * // Emits: { id: "1", title: "Dune", author: "Frank Herbert" } * // After delete: emits null * }).pipe(Effect.scoped) * ``` */ export declare const watchById: (pubsub: PubSub.PubSub, ref: Ref.Ref>, collectionName: string, id: string, config?: Pick) => Effect.Effect, never, import("effect").Scope.Scope>; export {}; //# sourceMappingURL=watch-by-id.d.ts.map