Primitives / foldkit-primitives/net

websocket

function · packages/primitives/src/net/websocket.ts:124

function websocket<const Name extends string>(config: {
    readonly name: Name;
    readonly createSocket?: ((url: string) => SocketHandle) | undefined;
}): Bundle.Bundle<Name, { readonly url: string; readonly connectTimeoutMs?: number | undefined; }, { readonly url: string; readonly status: "closed" | "open" | "connecting"; readonly lastError: Option.Option<string>; readonly opened: boolean; }, { readonly _tag: "Opened"; } | { readonly _tag: "Closed"; } | { readonly _tag: "Connecting"; } | { readonly _tag: "Failed"; readonly message: string; } | { readonly _tag: "TimedOut"; } | { readonly _tag: "Sent"; readonly data: string; } | { readonly _tag: "Received"; readonly data: string; } | { readonly _tag: "SendFailed"; readonly message: string; }, never, ManagedResource.ManagedResourceService<"websocket">, ManagedResource.ManagedResourceService<"websocket">, NoView, { socket: ManagedResource.Entry<{ readonly url: string; readonly status: "closed" | "open" | "connecting"; readonly lastError: Option.Option<string>; readonly opened: boolean; }, { readonly _tag: "Opened"; } | { readonly _tag: "Closed"; } | { readonly _tag: "Connecting"; } | { readonly _tag: "Failed"; readonly message: string; } | { readonly _tag: "TimedOut"; } | { readonly _tag: "Sent"; readonly data: string; } | { readonly _tag: "Received"; readonly data: string; } | { readonly _tag: "SendFailed"; readonly message: string; }, Option.Option<string>, Acquired, ManagedResource.ManagedResourceService<"websocket">, () => { readonly _tag: "Connecting"; }>; }, { send: (model: WebSocketModel, data: string) => { model: { readonly url: string; readonly status: "closed" | "open" | …;

A WebSocket as a bundle: connection lifecycle in the Model, full duplex through one Managed Resource. The resource owns the socket; a send helper writes through its tag service (lifted to the parent like every helper); a subscription stream reads incoming messages through the same tag. No hidden hub: everything the bundle touches is the Model, the resource registry, or a Message.