import { SdkSubscriptionErrorContext } from "../shared/subscription-errors.js"; import { ConnectPrivateOrdersParams } from "./private-orders.js"; import { DescMessage, MessageShape } from "@bufbuild/protobuf"; //#region src/realtime/types.d.ts interface SubscribeHandlers { onPublication: (data: T) => void; onSubscribed?: () => void; onUnsubscribed?: () => void; /** Observes subscription failures. Missing authentication throws when omitted. */ onError?: (ctx: SdkSubscriptionErrorContext) => void; } interface ConnectChannelParams { channel: string; schema: T; onPublication: (data: MessageShape) => void; onConnected?: () => void; onDisconnected?: () => void; /** Observes subscription failures. Missing authentication throws when omitted. */ onError?: (ctx: SdkSubscriptionErrorContext) => void; } type RealtimeConnectionState = "connecting" | "connected" | "disconnected"; interface RealtimeConnectionStatus { /** `"disconnected"` also means no socket is open because no channel needs one. */ readonly state: RealtimeConnectionState; /** * Why the socket is not connected, or `null`. Set on the first failure of an outage * while the socket keeps retrying in `"connecting"` (a socket failure after a connection * token failure replaces it), or after it closed for good; cleared once it connects. */ readonly error: Error | null; } /** Status of the public and the private Centrifuge sockets. Replaced, never mutated. */ interface RealtimeConnection { readonly public: RealtimeConnectionStatus; readonly private: RealtimeConnectionStatus; } /** * Structural realtime contract consumed by SDK services. The default * implementation is the Centrifuge-backed {@link ../realtime/client.js RealtimeClient}; * alternative implementations (in-memory mocks, custom stacks) can be injected * via the client config's `realtimeClient` field. */ interface PolyesterRealtime { /** Subscribes to a realtime channel and returns an unsubscribe function. */ subscribe(channel: string, handlers: SubscribeHandlers): () => void; /** Connects to a realtime channel with a custom message decoder. */ connectChannel(params: ConnectChannelParams): () => void; /** Connects to a realtime channel that emits protobuf messages. */ connectProtoChannel(params: ConnectChannelParams): () => void; /** Streams one account's orders over the private WebSocket. */ connectPrivateOrders(params: ConnectPrivateOrdersParams): () => void; /** Disconnects from all active channels. */ disconnect(): void; /** Disconnects authenticated realtime state without touching public channels. */ disconnectPrivate(): void; /** Socket status; private order streams run on their own socket and are not included. */ readonly connection: RealtimeConnection; /** Calls `listener` with the current {@link RealtimeConnection} after it changes, in a microtask; a status replaced before then is skipped. Returns an unsubscribe function. */ onConnectionChange(listener: (connection: RealtimeConnection) => void): () => void; readonly activeChannels: number; readonly totalConsumers: number; } //#endregion export { ConnectChannelParams, PolyesterRealtime, RealtimeConnection, RealtimeConnectionState, RealtimeConnectionStatus, SubscribeHandlers }; //# sourceMappingURL=types.d.ts.map