/** * Realtime Manager - WebSocket subscription support * @generated by @constructive-io/graphql-codegen * DO NOT EDIT - changes will be overwritten */ interface WsGraphQLError { readonly message: string; readonly [key: string]: unknown; } interface WsExecutionResult> { data?: TData | null; errors?: readonly WsGraphQLError[]; extensions?: Record; } interface WsSink { next(value: T): void; error(error: unknown): void; complete(): void; } /** * Minimal interface matching the graphql-ws Client. * Consumers pass a concrete instance via RealtimeConfig.client. */ export interface WsClient { subscribe>(payload: { query: string; variables?: Record; }, sink: WsSink>): () => void; dispose(): void; } /** The DML operation that triggered the subscription event */ export type SubscriptionOperation = 'INSERT' | 'UPDATE' | 'DELETE'; /** Connection state of the WebSocket */ export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'reconnecting'; /** Listener for connection state changes */ export type ConnectionStateListener = (state: ConnectionState) => void; /** Function returned by subscribe() to cancel the subscription */ export type Unsubscribe = () => void; /** * A realtime subscription event delivered to the client. * * @typeParam T - The row type of the subscribed table */ export interface SubscriptionEvent { /** The DML operation that triggered this event */ operation: SubscriptionOperation; /** The current row data (null for DELETE if row is no longer visible) */ data: T | null; /** Previous field values (populated on UPDATE when available) */ previousValues?: Partial; /** Server-side timestamp of when the change occurred */ timestamp: string; } /** * Options for creating a subscription. * * @typeParam T - The row type of the subscribed table * @typeParam TFilter - The filter type for the table */ export interface SubscribeOptions> { /** Server-side filter to limit which events are delivered */ filter?: TFilter; /** Called when a subscription event is received */ onEvent: (event: SubscriptionEvent) => void; /** Called when the subscription encounters an error */ onError?: (error: Error) => void; /** Called when the subscription completes (server-initiated close) */ onComplete?: () => void; } /** * Metadata about a subscription field, used internally to map * table names to GraphQL subscription field names and types. */ export interface SubscriptionFieldMeta { /** The GraphQL subscription field name (e.g., 'onContactChanged') */ fieldName: string; /** The table name in the source schema (e.g., 'contact') */ tableName: string; /** The data field name inside the subscription payload (e.g., 'contact') */ dataFieldName: string; } /** * Configuration for the realtime (WebSocket) connection. * Pass this as the `realtime` option in OrmClientConfig. * * @example * ```ts * import { createClient } from 'graphql-ws'; * * const client = createOrmClient({ * endpoint: 'https://api.example.com/graphql', * realtime: { * client: createClient({ url: 'wss://api.example.com/graphql' }), * }, * }); * ``` */ export interface RealtimeConfig { /** * A graphql-ws Client instance (or any object satisfying WsClient). * The consumer creates this themselves, giving full control over * connection options, auth, and transport. * * @example * ```ts * import { createClient } from 'graphql-ws'; * const wsClient = createClient({ url: 'wss://...' }); * ``` */ client: WsClient; } /** * Manages a graphql-ws WebSocket client and multiplexes * subscriptions over it. Created by OrmClient when `realtime` * config is provided. */ export declare class RealtimeManager { private wsClient; private connectionState; private stateListeners; private activeSubscriptions; constructor(config: RealtimeConfig); /** * Subscribe to a GraphQL subscription operation. * Models call this with typed metadata and documents. */ subscribe(meta: SubscriptionFieldMeta, document: string, variables: Record, options: { onEvent: (event: SubscriptionEvent) => void; onError?: (error: Error) => void; onComplete?: () => void; }): Unsubscribe; /** Register a listener for connection state changes */ onConnectionStateChange(listener: ConnectionStateListener): Unsubscribe; /** Get current connection state */ getConnectionState(): ConnectionState; /** Number of active subscriptions */ getActiveSubscriptionCount(): number; /** Dispose the manager and close the WebSocket connection */ dispose(): void; private setConnectionState; } export {};