Skip to content
TypeWire

@tahanabavi/typesocket

v2.2.0

Contract-driven, type-safe Socket.IO client — one Zod contract validated in both directions, with acks, middleware, queueing and a devtools instrumentation seam.

API reference

Client

MemberDescription
new SocketClient(config, contracts, options?)Builds the client. Throws on an invalid contract.
createSocketClient(config, contracts, options?)Same, and connects unless autoConnect: false.
.modulesThe generated surface — modules.<module>.<event>.
.connect() / .disconnect() / .reconnect()Connection control. connect() is idempotent.
.destroy()Disconnect and drop every handler, middleware and hook.
.use(middleware)Attach middleware. Returns a remover.
.instrument(hook)Attach an instrumentation hook. Returns a detacher.
.onConnect/.onDisconnect/.onConnectError(fn)Lifecycle subscriptions. Each returns an unsubscribe.
.connected · .id · .raw · .queueSize · .eventsIntrospection.

client->server events

MemberDescription
(input, options?)Validate and emit. Promise<Ack> when ack is declared, else void.
.queue(input)Validate now, send on the next connect.
.eventId · .event · .defMetadata for tooling. .def.permission carries the optional requirement.

server->client events

MemberDescription
.on(handler) / .once(handler)Subscribe. Returns an unsubscribe.
.off(handler) / .offAll()Detach.
.wait(options?)Resolve on the next valid (optionally filtered) payload.
.listenerCountLive handler count.
.eventId · .event · .defMetadata for tooling.

Contract helpers

defineSocketContracts · listSocketEvents · validateSocketContracts · isClientToServer · isServerToClient · makeEventId · resolveEventName