DefinitelyTyped/types/ncom/index.d.ts
Daniel Rose 3b611ed646
Update various socketcluster types to newest versions (#42068)
* Add type definitions for async-stream-emitter, consumable-stream, writable-consumable-stream, stream-demux, ag-channel, ag-simple-broker, ncom, async-iterable-stream

* Upgrade sc-broker to 8.0

* Upgrade socketcluster-client to 15.1

* Rename definition files to match module file names

The files in the module were renamed.

* Move socketcluster-server to v14 folder

In preparation for socketcluster-server v15, since the old version is still used by other type packages.

* Update scc-broker-client to 7.0

* Add current socketcluster-server type definitions

Current version is v15.0

* Move sc-broker-cluster to v6 folder

In preparation for sc-broker-cluster v9, since the old version is still used by other type packages.

* Add current sc-broker-cluster type definitions

Current version is v9.0

* Move sc-channel to v1 folder

In preparation for sc-channel v2, since the old version is still used by other type packages.

* Add current sc-channel type definitions

Current version is v2.0

* Include the relevant sc-broker-cluster type-definitions directly in sc-channel

It can be run using older and newer version of sc-broker-cluster, which have differently versioned dependencies.

* Move sc-channel tests to sc-broker-cluster

In the tests we use sc-broker-cluster. If the tests are in sc-channel, they drag in all dependencies for sc-broker-cluster, including esnext.asynciterable, which we don't want.

* Simplify sc-errors tests

In the tests we used socketcluster-server. That dragged in all of its dependencies, including esnext.asynciterable, which we don't want.

* Move sc-channel to v1 folder

In preparation for sc-channel v2, since the old version is still used by other type packages.
2020-02-05 08:59:09 -08:00

135 lines
5.1 KiB
TypeScript

// Type definitions for ncom 1.0
// Project: https://github.com/SocketCluster/ncom
// Definitions by: Daniel Rose <https://github.com/DanielRose>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import { EventEmitter } from 'events';
import { SocketConstructorOpts, Socket, ListenOptions } from 'net';
import { TlsOptions } from 'tls';
export class ComSocket extends EventEmitter {
id: string;
connected: boolean;
batchDuration: number;
socket: Socket;
constructor(options: SocketConstructorOpts | Socket, id: string);
/**
* events.EventEmitter
* 1. error
*/
addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: 'error', listener: (err: Error) => void): this;
emit(event: string | symbol, ...args: any[]): boolean;
emit(event: 'error', err: Error): boolean;
on(event: string, listener: (...args: any[]) => void): this;
on(event: 'error', listener: (err: Error) => void): this;
once(event: string, listener: (...args: any[]) => void): this;
once(event: 'error', listener: (err: Error) => void): this;
prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: 'error', listener: (err: Error) => void): this;
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
removeListener(event: string, listener: (...args: any[]) => void): this;
removeListener(event: 'error', listener: (err: Error) => void): this;
write(data: any, writeOptions?: WriteOptions): void;
end: () => void;
destroy: () => void;
}
export class ComServer extends EventEmitter {
constructor(options?: ComServerOptions);
constructor(options: SecureComServerOptions);
/**
* events.EventEmitter
* 1. error
* 2. connection
*
* All other events are forwarded to net.Server
*/
addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: 'error', listener: (err: Error) => void): this;
addListener(event: 'connection', listener: ConnectionListener): this;
emit(event: string | symbol, ...args: any[]): boolean;
emit(event: 'error', err: Error): boolean;
emit(event: 'connection', listener: ConnectionListener): this;
on(event: string, listener: (...args: any[]) => void): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'connection', listener: ConnectionListener): this;
once(event: string, listener: (...args: any[]) => void): this;
once(event: 'error', listener: (err: Error) => void): this;
once(event: 'connection', listener: ConnectionListener): this;
prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: 'error', listener: (err: Error) => void): this;
prependListener(event: 'connection', listener: ConnectionListener): this;
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
prependOnceListener(event: 'connection', listener: ConnectionListener): this;
removeListener(event: string, listener: (...args: any[]) => void): this;
removeListener(event: 'error', listener: (err: Error) => void): this;
removeListener(event: 'connection', listener: ConnectionListener): this;
/**
* Forwards to net.Server.listen()
*/
// tslint:disable:unified-signatures Copied from net.d.ts, where the rule is disabled
listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;
listen(port?: number, hostname?: string, listeningListener?: () => void): this;
listen(port?: number, backlog?: number, listeningListener?: () => void): this;
listen(port?: number, listeningListener?: () => void): this;
listen(path: string, backlog?: number, listeningListener?: () => void): this;
listen(path: string, listeningListener?: () => void): this;
listen(options: ListenOptions, listeningListener?: () => void): this;
listen(handle: any, backlog?: number, listeningListener?: () => void): this;
listen(handle: any, listeningListener?: () => void): this;
// tslint:enable:unified-signatures
/**
* Forwards to net.Server.close()
*/
close(callback?: (err?: Error) => void): this;
}
export function createServer(options?: ComServerOptions, listener?: ConnectionListener): ComServer;
export function createServer(options: SecureComServerOptions, listener?: ConnectionListener): ComServer;
export function createServer(listener?: ConnectionListener): ComServer;
export interface WriteOptions {
filters?: FilterFunction[];
batch?: boolean;
}
export type FilterFunction = (data: any) => string;
export interface SecureComServerOptions extends TlsOptions {
secure: true;
}
export interface ComServerOptions {
allowHalfOpen?: boolean;
pauseOnConnect?: boolean;
}
export type ConnectionListener = (socket: ComSocket) => void;