Socket overview
Added in v1.0.0
Table of contents
combinators
toChannel
Signature
export declare const toChannel: <IE>(
self: Socket
) => Channel.Channel<
Chunk.Chunk<Uint8Array>,
Chunk.Chunk<Uint8Array | string | CloseEvent>,
SocketError | IE,
IE,
void,
unknown
>
Added in v1.0.0
toChannelMap
Signature
export declare const toChannelMap: <IE, A>(
self: Socket,
f: (data: Uint8Array | string) => A
) => Channel.Channel<Chunk.Chunk<A>, Chunk.Chunk<Uint8Array | string | CloseEvent>, SocketError | IE, IE, void, unknown>
Added in v1.0.0
toChannelString
Signature
export declare const toChannelString: {
(
encoding?: string | undefined
): <IE>(
self: Socket
) => Channel.Channel<
Chunk.Chunk<string>,
Chunk.Chunk<Uint8Array | string | CloseEvent>,
SocketError | IE,
IE,
void,
unknown
>
<IE>(
self: Socket,
encoding?: string | undefined
): Channel.Channel<
Chunk.Chunk<string>,
Chunk.Chunk<Uint8Array | string | CloseEvent>,
SocketError | IE,
IE,
void,
unknown
>
}
Added in v1.0.0
toChannelWith
Signature
export declare const toChannelWith: <IE = never>() => (
self: Socket
) => Channel.Channel<
Chunk.Chunk<Uint8Array>,
Chunk.Chunk<Uint8Array | string | CloseEvent>,
SocketError | IE,
IE,
void,
unknown
>
Added in v1.0.0
constructors
fromTransformStream
Signature
export declare const fromTransformStream: <R>(
acquire: Effect.Effect<InputTransformStream, SocketError, R>,
options?: { readonly closeCodeIsError?: (code: number) => boolean }
) => Effect.Effect<Socket, never, Exclude<R, Scope.Scope>>
Added in v1.0.0
fromWebSocket
Signature
export declare const fromWebSocket: <RO>(
acquire: Effect.Effect<globalThis.WebSocket, SocketError, RO>,
options?: { readonly closeCodeIsError?: (code: number) => boolean; readonly openTimeout?: DurationInput }
) => Effect.Effect<Socket, never, Exclude<RO, Scope.Scope>>
Added in v1.0.0
makeChannel
Signature
export declare const makeChannel: <IE = never>() => Channel.Channel<
Chunk.Chunk<Uint8Array>,
Chunk.Chunk<Uint8Array | string | CloseEvent>,
SocketError | IE,
IE,
void,
unknown,
Socket
>
Added in v1.0.0
makeWebSocket
Signature
export declare const makeWebSocket: (
url: string | Effect.Effect<string>,
options?: {
readonly closeCodeIsError?: ((code: number) => boolean) | undefined
readonly openTimeout?: DurationInput | undefined
readonly protocols?: string | Array<string> | undefined
}
) => Effect.Effect<Socket, never, WebSocketConstructor>
Added in v1.0.0
makeWebSocketChannel
Signature
export declare const makeWebSocketChannel: <IE = never>(
url: string,
options?: { readonly closeCodeIsError?: (code: number) => boolean }
) => Channel.Channel<
Chunk.Chunk<Uint8Array>,
Chunk.Chunk<Uint8Array | string | CloseEvent>,
SocketError | IE,
IE,
void,
unknown,
WebSocketConstructor
>
Added in v1.0.0
errors
SocketCloseError (class)
Signature
export declare class SocketCloseError
Added in v1.0.0
is (static method)
Signature
static is(u: unknown): u is SocketCloseError
Added in v1.0.0
isClean (static method)
Signature
static isClean(isClean: (code: number) => boolean)
Added in v1.0.0
SocketError (type alias)
Signature
export type SocketError = SocketGenericError | SocketCloseError
Added in v1.0.0
SocketGenericError (class)
Signature
export declare class SocketGenericError
Added in v1.0.0
fiber refs
currentSendQueueCapacity
Signature
export declare const currentSendQueueCapacity: FiberRef.FiberRef<number>
Added in v1.0.0
guards
isSocket
Signature
export declare const isSocket: (u: unknown) => u is Socket
Added in v1.0.0
layers
layerWebSocket
Signature
export declare const layerWebSocket: (
url: string,
options?: { readonly closeCodeIsError?: (code: number) => boolean }
) => Layer.Layer<Socket, never, WebSocketConstructor>
Added in v1.0.0
layerWebSocketConstructorGlobal
Signature
export declare const layerWebSocketConstructorGlobal: Layer.Layer<WebSocketConstructor>
Added in v1.0.0
models
CloseEvent (class)
Signature
export declare class CloseEvent { constructor(readonly code = 1000, readonly reason?: string) }
Added in v1.0.0
toString (method)
Signature
toString()
Added in v1.0.0
[CloseEventTypeId] (property)
Signature
readonly [CloseEventTypeId]: typeof CloseEventTypeId
Added in v1.0.0
InputTransformStream (interface)
Signature
export interface InputTransformStream {
readonly readable: ReadableStream<Uint8Array> | ReadableStream<string> | ReadableStream<Uint8Array | string>
readonly writable: WritableStream<Uint8Array>
}
Added in v1.0.0
Socket (interface)
Signature
export interface Socket {
readonly [TypeId]: TypeId
readonly run: <_, E = never, R = never>(
handler: (_: Uint8Array) => Effect.Effect<_, E, R> | void
) => Effect.Effect<void, SocketError | E, R>
readonly runRaw: <_, E = never, R = never>(
handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void
) => Effect.Effect<void, SocketError | E, R>
readonly writer: Effect.Effect<
(chunk: Uint8Array | string | CloseEvent) => Effect.Effect<void, SocketError>,
never,
Scope.Scope
>
}
Added in v1.0.0
refinements
isCloseEvent
Signature
export declare const isCloseEvent: (u: unknown) => u is CloseEvent
Added in v1.0.0
isSocketError
Signature
export declare const isSocketError: (u: unknown) => u is SocketError
Added in v1.0.0
tags
Socket
Signature
export declare const Socket: Context.Tag<Socket, Socket>
Added in v1.0.0
WebSocket
Signature
export declare const WebSocket: Context.Tag<WebSocket, globalThis.WebSocket>
Added in v1.0.0
WebSocket (interface)
Signature
export interface WebSocket {
readonly _: unique symbol
}
Added in v1.0.0
WebSocketConstructor
Signature
export declare const WebSocketConstructor: Context.Tag<
WebSocketConstructor,
(url: string, protocols?: string | Array<string> | undefined) => globalThis.WebSocket
>
Added in v1.0.0
WebSocketConstructor (interface)
Signature
export interface WebSocketConstructor {
readonly _: unique symbol
}
Added in v1.0.0
type ids
CloseEventTypeId
Signature
export declare const CloseEventTypeId: typeof CloseEventTypeId
Added in v1.0.0
CloseEventTypeId (type alias)
Signature
export type CloseEventTypeId = typeof CloseEventTypeId
Added in v1.0.0
SocketErrorTypeId
Signature
export declare const SocketErrorTypeId: typeof SocketErrorTypeId
Added in v1.0.0
SocketErrorTypeId (type alias)
Signature
export type SocketErrorTypeId = typeof SocketErrorTypeId
Added in v1.0.0
TypeId
Signature
export declare const TypeId: typeof TypeId
Added in v1.0.0
TypeId (type alias)
Signature
export type TypeId = typeof TypeId
Added in v1.0.0
utils
defaultCloseCodeIsError
Signature
export declare const defaultCloseCodeIsError: (code: number) => boolean
Added in v1.0.0