/**
 * @since 4.0.0
 */
import type { NonEmptyReadonlyArray } from "../../Array.ts";
import type * as Cause from "../../Cause.ts";
import * as Channel from "../../Channel.ts";
import * as Context from "../../Context.ts";
import type * as Duration from "../../Duration.ts";
import * as Effect from "../../Effect.ts";
import * as Layer from "../../Layer.ts";
import * as Result from "../../Result.ts";
import * as Schema from "../../Schema.ts";
import * as Scope from "../../Scope.ts";
/**
 * @since 4.0.0
 * @category Type IDs
 */
export declare const TypeId = "~effect/socket/Socket";
/**
 * @since 4.0.0
 * @category guards
 */
export declare const isSocket: (u: unknown) => u is Socket;
/**
 * @since 4.0.0
 * @category tags
 */
export declare const Socket: Context.Service<Socket, Socket>;
/**
 * @since 4.0.0
 * @category models
 */
export interface Socket {
    readonly [TypeId]: typeof TypeId;
    readonly run: <_, E = never, R = never>(handler: (_: Uint8Array) => Effect.Effect<_, E, R> | void, options?: {
        readonly onOpen?: Effect.Effect<void> | undefined;
    }) => Effect.Effect<void, SocketError | E, R>;
    readonly runString: <_, E = never, R = never>(handler: (_: string) => Effect.Effect<_, E, R> | void, options?: {
        readonly onOpen?: Effect.Effect<void> | undefined;
    }) => Effect.Effect<void, SocketError | E, R>;
    readonly runRaw: <_, E = never, R = never>(handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void, options?: {
        readonly onOpen?: Effect.Effect<void> | undefined;
    }) => Effect.Effect<void, SocketError | E, R>;
    readonly writer: Effect.Effect<(chunk: Uint8Array | string | CloseEvent) => Effect.Effect<void, SocketError>, never, Scope.Scope>;
}
/**
 * @since 4.0.0
 * @category Constructors
 */
export declare const make: (options: {
    readonly runRaw: <_, E, R>(handler: (_: string | Uint8Array) => Effect.Effect<_, E, R> | void, options?: {
        readonly onOpen?: Effect.Effect<void> | undefined;
    }) => Effect.Effect<void, SocketError | E, R>;
    readonly run?: <_, E, R>(handler: (_: Uint8Array) => Effect.Effect<_, E, R> | void, options?: {
        readonly onOpen?: Effect.Effect<void> | undefined;
    }) => Effect.Effect<void, SocketError | E, R>;
    readonly runString?: <_, E, R>(handler: (_: string) => Effect.Effect<_, E, R> | void, options?: {
        readonly onOpen?: Effect.Effect<void> | undefined;
    }) => Effect.Effect<void, SocketError | E, R>;
    readonly writer: Effect.Effect<(chunk: Uint8Array | string | CloseEvent) => Effect.Effect<void, SocketError>, never, Scope.Scope>;
}) => Socket;
declare const CloseEventTypeId = "~effect/socket/Socket/CloseEvent";
/**
 * @since 4.0.0
 * @category models
 */
export declare class CloseEvent {
    /**
     * @since 4.0.0
     */
    readonly [CloseEventTypeId]: typeof CloseEventTypeId;
    readonly code: number;
    readonly reason?: string | undefined;
    constructor(code?: number, reason?: string);
    /**
     * @since 4.0.0
     */
    toString(): string;
}
/**
 * @since 4.0.0
 * @category refinements
 */
export declare const isCloseEvent: (u: unknown) => u is CloseEvent;
/**
 * @since 4.0.0
 * @category type ids
 */
export type SocketErrorTypeId = "~effect/socket/Socket/SocketError";
/**
 * @since 4.0.0
 * @category type ids
 */
export declare const SocketErrorTypeId: SocketErrorTypeId;
/**
 * @since 4.0.0
 * @category refinements
 */
export declare const isSocketError: (u: unknown) => u is SocketError;
declare const SocketReadError_base: Schema.Class<SocketReadError, Schema.Struct<{
    readonly _tag: Schema.tag<"SocketReadError">;
    readonly cause: Schema.Defect;
}>, Cause.YieldableError>;
/**
 * @since 4.0.0
 * @category errors
 */
export declare class SocketReadError extends SocketReadError_base {
    /**
     * @since 4.0.0
     */
    readonly message = "An error occurred during Read";
}
declare const SocketWriteError_base: Schema.Class<SocketWriteError, Schema.Struct<{
    readonly _tag: Schema.tag<"SocketWriteError">;
    readonly cause: Schema.Defect;
}>, Cause.YieldableError>;
/**
 * @since 4.0.0
 * @category errors
 */
export declare class SocketWriteError extends SocketWriteError_base {
    /**
     * @since 4.0.0
     */
    readonly message = "An error occurred during Write";
}
declare const SocketOpenError_base: Schema.Class<SocketOpenError, Schema.Struct<{
    readonly _tag: Schema.tag<"SocketOpenError">;
    readonly kind: Schema.Literals<readonly ["Unknown", "Timeout"]>;
    readonly cause: Schema.Defect;
}>, Cause.YieldableError>;
/**
 * @since 4.0.0
 * @category errors
 */
export declare class SocketOpenError extends SocketOpenError_base {
    /**
     * @since 4.0.0
     */
    get message(): "timeout waiting for \"open\"" | "An error occurred during Open";
}
declare const SocketCloseError_base: Schema.Class<SocketCloseError, Schema.Struct<{
    readonly _tag: Schema.tag<"SocketCloseError">;
    readonly code: Schema.Number;
    readonly closeReason: Schema.optional<Schema.String>;
}>, Cause.YieldableError>;
/**
 * @since 4.0.0
 * @category errors
 */
export declare class SocketCloseError extends SocketCloseError_base {
    /**
     * @since 4.0.0
     */
    static filterClean(isClean: (code: number) => boolean): <E>(u: E) => Result.Result<SocketCloseError, E>;
    get message(): string;
}
/**
 * @since 4.0.0
 * @category errors
 */
export declare const SocketErrorReason: Schema.Union<readonly [typeof SocketReadError, typeof SocketWriteError, typeof SocketOpenError, typeof SocketCloseError]>;
/**
 * @since 4.0.0
 * @category errors
 */
export type SocketErrorReason = SocketReadError | SocketWriteError | SocketOpenError | SocketCloseError;
declare const SocketError_base: Schema.Class<SocketError, Schema.TaggedStruct<"SocketError", {
    readonly _tag: Schema.tag<"SocketError">;
    readonly reason: Schema.Union<readonly [typeof SocketReadError, typeof SocketWriteError, typeof SocketOpenError, typeof SocketCloseError]>;
}>, Cause.YieldableError>;
/**
 * @since 4.0.0
 * @category errors
 */
export declare class SocketError extends SocketError_base {
    constructor(props: {
        readonly reason: SocketReadError | SocketWriteError | SocketOpenError | SocketCloseError;
    });
    /**
     * @since 4.0.0
     */
    readonly [SocketErrorTypeId]: SocketErrorTypeId;
    /**
     * @since 4.0.0
     */
    static is(u: unknown): u is SocketError;
    readonly message: string;
}
/**
 * @since 4.0.0
 * @category combinators
 */
export declare const toChannelMap: <IE, A>(self: Socket, f: (data: Uint8Array | string) => A) => Channel.Channel<NonEmptyReadonlyArray<A>, SocketError | IE, void, NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>, IE>;
/**
 * @since 4.0.0
 * @category combinators
 */
export declare const toChannel: <IE>(self: Socket) => Channel.Channel<NonEmptyReadonlyArray<Uint8Array>, SocketError | IE, void, NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>, IE>;
/**
 * @since 4.0.0
 * @category combinators
 */
export declare const toChannelString: {
    /**
     * @since 4.0.0
     * @category combinators
     */
    (encoding?: string | undefined): <IE>(self: Socket) => Channel.Channel<NonEmptyReadonlyArray<string>, SocketError | IE, void, NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>, IE>;
    /**
     * @since 4.0.0
     * @category combinators
     */
    <IE>(self: Socket, encoding?: string | undefined): Channel.Channel<NonEmptyReadonlyArray<string>, SocketError | IE, void, NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>, IE>;
};
/**
 * @since 4.0.0
 * @category combinators
 */
export declare const toChannelWith: <IE = never>() => (self: Socket) => Channel.Channel<NonEmptyReadonlyArray<Uint8Array>, SocketError | IE, void, NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>, IE>;
/**
 * @since 4.0.0
 * @category constructors
 */
export declare const makeChannel: <IE = never>() => Channel.Channel<NonEmptyReadonlyArray<Uint8Array>, SocketError | IE, void, NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>, IE, unknown, Socket>;
/**
 * @since 4.0.0
 */
export declare const defaultCloseCodeIsError: (_code: number) => boolean;
declare const WebSocket_base: Context.ServiceClass<WebSocket, "~effect/socket/Socket/WebSocket", globalThis.WebSocket>;
/**
 * @since 4.0.0
 * @category tags
 */
export declare class WebSocket extends WebSocket_base {
}
declare const WebSocketConstructor_base: Context.ServiceClass<WebSocketConstructor, "@effect/platform/Socket/WebSocketConstructor", (url: string, protocols?: string | Array<string> | undefined) => globalThis.WebSocket>;
/**
 * @since 4.0.0
 * @category tags
 */
export declare class WebSocketConstructor extends WebSocketConstructor_base {
}
/**
 * @since 4.0.0
 * @category layers
 */
export declare const layerWebSocketConstructorGlobal: Layer.Layer<WebSocketConstructor>;
/**
 * @since 4.0.0
 * @category constructors
 */
export declare const makeWebSocket: (url: string | Effect.Effect<string>, options?: {
    readonly closeCodeIsError?: ((code: number) => boolean) | undefined;
    readonly openTimeout?: Duration.Input | undefined;
    readonly protocols?: string | Array<string> | undefined;
}) => Effect.Effect<Socket, never, WebSocketConstructor>;
/**
 * @since 4.0.0
 * @category constructors
 */
export declare const fromWebSocket: <RO>(acquire: Effect.Effect<globalThis.WebSocket, SocketError, RO>, options?: {
    readonly closeCodeIsError?: ((code: number) => boolean) | undefined;
    readonly openTimeout?: Duration.Input | undefined;
} | undefined) => Effect.Effect<Socket, never, Exclude<RO, Scope.Scope>>;
/**
 * @since 4.0.0
 * @category constructors
 */
export declare const makeWebSocketChannel: <IE = never>(url: string, options?: {
    readonly closeCodeIsError?: (code: number) => boolean;
}) => Channel.Channel<NonEmptyReadonlyArray<Uint8Array>, SocketError | IE, void, NonEmptyReadonlyArray<Uint8Array | string | CloseEvent>, IE, unknown, WebSocketConstructor>;
/**
 * @since 4.0.0
 * @category layers
 */
export declare const layerWebSocket: (url: string | Effect.Effect<string>, options?: {
    readonly closeCodeIsError?: ((code: number) => boolean) | undefined;
    readonly openTimeout?: Duration.Input | undefined;
    readonly protocols?: string | Array<string> | undefined;
} | undefined) => Layer.Layer<Socket, never, WebSocketConstructor>;
/**
 * @since 4.0.0
 * @category fiber refs
 */
export declare const SendQueueCapacity: Context.Reference<number>;
/**
 * @since 4.0.0
 * @category models
 */
export interface InputTransformStream {
    readonly readable: ReadableStream<Uint8Array> | ReadableStream<string> | ReadableStream<Uint8Array | string>;
    readonly writable: WritableStream<Uint8Array>;
}
/**
 * @since 4.0.0
 * @category constructors
 */
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>>;
export {};
//# sourceMappingURL=Socket.d.ts.map