Skip to content

Commit

Permalink
Add missing Server type export (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Kasper Isager Dalsgarð <[email protected]>
  • Loading branch information
yassernasc and kasperisager authored Feb 3, 2025
1 parent 0a4cf56 commit 08a02bc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
56 changes: 23 additions & 33 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import EventEmitter, { EventMap } from 'bare-events'
import { Duplex, DuplexEvents } from 'bare-stream'
import PipeError from './lib/errors'
import constants from './lib/constants'

interface PipeEvents extends DuplexEvents {
connect: []
Expand Down Expand Up @@ -42,24 +44,24 @@ declare class Pipe<M extends PipeEvents = PipeEvents> extends Duplex<M> {
constructor(opts?: PipeOptions)
}

interface ServerEvents extends EventMap {
interface PipeServerEvents extends EventMap {
close: []
connection: [pipe: Pipe]
err: [err: Error]
listening: []
}

interface ServerOptions {
interface PipeServerOptions {
readBufferSize?: number
allowHalfOpen?: boolean
}

interface ServerListenOptions {
interface PipeServerListenOptions {
path?: string
backlog?: number
}

interface Server<M extends ServerEvents = ServerEvents>
interface PipeServer<M extends PipeServerEvents = PipeServerEvents>
extends EventEmitter<M> {
readonly listening: boolean

Expand All @@ -68,15 +70,15 @@ interface Server<M extends ServerEvents = ServerEvents>
listen(
path: string,
backlog?: number,
opts?: ServerListenOptions,
opts?: PipeServerListenOptions,
onlistening?: () => void
): this

listen(path: string, backlog: number, onlistening: () => void): this

listen(path: string, onlistening: () => void): this

listen(opts: ServerListenOptions): this
listen(opts: PipeServerListenOptions): this

close(onclose?: () => void): void

Expand All @@ -85,20 +87,14 @@ interface Server<M extends ServerEvents = ServerEvents>
unref(): void
}

declare class Server<
M extends ServerEvents = ServerEvents
declare class PipeServer<
M extends PipeServerEvents = PipeServerEvents
> extends EventEmitter<M> {
constructor(opts?: ServerOptions, onconnection?: () => void)
constructor(opts?: PipeServerOptions, onconnection?: () => void)

constructor(onconnection: () => void)
}

declare class PipeError extends Error {
static PIPE_ALREADY_CONNECTED(msg: string): PipeError
static SERVER_ALREADY_LISTENING(msg: string): PipeError
static SERVER_IS_CLOSED(msg: string): PipeError
}

declare namespace Pipe {
export interface CreateConnectionOptions
extends PipeOptions,
Expand All @@ -118,31 +114,25 @@ declare namespace Pipe {
): Pipe

export function createServer(
opts?: ServerOptions,
opts?: PipeServerOptions,
onconnection?: () => void
): Server
): PipeServer

export function pipe(): [read: number, write: number]

export const constants: {
CONNECTING: number
CONNECTED: number
BINDING: number
BOUND: number
READING: number
CLOSING: number
READABLE: number
WRITABLE: number
}

export {
type PipeEvents,
type PipeOptions,
Pipe,
PipeEvents,
PipeOptions,
PipeConnectOptions,
type PipeConnectOptions,
type PipeServerEvents,
type PipeServerOptions,
type PipeServerListenOptions,
type PipeServer,
PipeServer as Server,
type PipeError,
PipeError as errors,
ServerEvents,
ServerOptions
constants
}
}

Expand Down
12 changes: 12 additions & 0 deletions lib/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare const constants: {
CONNECTING: number
CONNECTED: number
BINDING: number
BOUND: number
READING: number
CLOSING: number
READABLE: number
WRITABLE: number
}

export = constants
7 changes: 7 additions & 0 deletions lib/errors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare class PipeError extends Error {
static PIPE_ALREADY_CONNECTED(msg: string): PipeError
static SERVER_ALREADY_LISTENING(msg: string): PipeError
static SERVER_IS_CLOSED(msg: string): PipeError
}

export = PipeError
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
"version": "4.0.3",
"description": "Native I/O pipes for JavaScript",
"exports": {
"./package": "./package.json",
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./package": "./package.json",
"./constants": "./lib/constants.js",
"./errors": "./lib/errors.js"
"./constants": {
"types": "./lib/constants.d.ts",
"default": "./lib/constants.js"
},
"./errors": {
"types": "./lib/errors.d.ts",
"default": "./lib/errors.js"
}
},
"files": [
"index.js",
Expand Down

0 comments on commit 08a02bc

Please sign in to comment.