From c52e7bdf63b7d45f0d551d2534a19a3eea250ba9 Mon Sep 17 00:00:00 2001 From: Paul Loyd Date: Mon, 7 Apr 2014 19:49:19 +0400 Subject: [PATCH] node: now modules depend on stream.* when possible --- browserify/browserify.d.ts | 2 +- highland/highland-tests.ts | 4 +- highland/highland.d.ts | 6 +-- node/node.d.ts | 83 +++++++++++++++++++------------------- promptly/promptly.d.ts | 5 ++- q-io/Q-io.d.ts | 4 +- superagent/superagent.d.ts | 3 +- through/through.d.ts | 4 +- 8 files changed, 57 insertions(+), 54 deletions(-) diff --git a/browserify/browserify.d.ts b/browserify/browserify.d.ts index e725de98c..ebed2a490 100644 --- a/browserify/browserify.d.ts +++ b/browserify/browserify.d.ts @@ -16,7 +16,7 @@ interface BrowserifyObject extends NodeEventEmitter { debug?: boolean; standalone?: string; insertGlobalVars?: any; - }, cb?: (err: any, src: any) => void): ReadableStream; + }, cb?: (err: any, src: any) => void): NodeReadableStream; external(file: string): BrowserifyObject; ignore(file: string): BrowserifyObject; diff --git a/highland/highland-tests.ts b/highland/highland-tests.ts index 3625b3f81..0a724a7fb 100644 --- a/highland/highland-tests.ts +++ b/highland/highland-tests.ts @@ -22,8 +22,8 @@ var strArr: string[]; var numArr: string[]; var funcArr: Function[]; -var readable: ReadableStream; -var writable: WritableStream; +var readable: NodeReadableStream; +var writable: NodeWritableStream; var emitter: NodeEventEmitter; // - - - - - - - - - - - - - - - - - diff --git a/highland/highland.d.ts b/highland/highland.d.ts index 8760a5c2d..3bec0c6eb 100644 --- a/highland/highland.d.ts +++ b/highland/highland.d.ts @@ -62,7 +62,7 @@ interface HighlandStatic { (xs: (push: (err: Error, x?: R) => void, next: () => void) => void): Highland.Stream; (xs: Highland.Stream): Highland.Stream; - (xs: ReadableStream): Highland.Stream; + (xs: NodeReadableStream): Highland.Stream; (xs: NodeEventEmitter): Highland.Stream; // moar (promise for everything?) @@ -419,8 +419,8 @@ declare module Highland { * @api public */ pipe(dest: Stream): Stream; - pipe(dest: ReadWriteStream): Stream; - pipe(dest: WritableStream): void; + pipe(dest: NodeReadWriteStream): Stream; + pipe(dest: NodeWritableStream): void; /** * Destroys a stream by unlinking it from any consumers and sources. This will diff --git a/node/node.d.ts b/node/node.d.ts index 8966fa18b..d0a67ffef 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -55,6 +55,7 @@ declare var SlowBuffer: { byteLength(string: string, encoding?: string): number; concat(list: Buffer[], totalLength?: number): Buffer; }; + declare var Buffer: { new (str: string, encoding?: string): Buffer; new (size: number): Buffer; @@ -89,20 +90,20 @@ interface NodeEventEmitter { emit(event: string, ...args: any[]): boolean; } -interface ReadableStream extends NodeEventEmitter { +interface NodeReadableStream extends NodeEventEmitter { readable: boolean; read(size?: number): any; setEncoding(encoding: string): void; pause(): void; resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; unshift(chunk: string): void; unshift(chunk: Buffer): void; - wrap(oldStream: ReadableStream): ReadableStream; + wrap(oldStream: NodeReadableStream): NodeReadableStream; } -interface WritableStream extends NodeEventEmitter { +interface NodeWritableStream extends NodeEventEmitter { writable: boolean; write(buffer: Buffer, cb?: Function): boolean; write(str: string, cb?: Function): boolean; @@ -113,12 +114,12 @@ interface WritableStream extends NodeEventEmitter { end(str: string, encoding?: string, cb?: Function): void; } -interface ReadWriteStream extends ReadableStream, WritableStream { } +interface NodeReadWriteStream extends NodeReadableStream, NodeWritableStream {} interface NodeProcess extends NodeEventEmitter { - stdout: WritableStream; - stderr: WritableStream; - stdin: ReadableStream; + stdout: NodeWritableStream; + stderr: NodeWritableStream; + stdin: NodeReadableStream; argv: string[]; execPath: string; abort(): void; @@ -264,7 +265,7 @@ declare module "http" { address(): { port: number; family: string; address: string; }; maxHeadersCount: number; } - export interface ServerRequest extends events.EventEmitter, ReadableStream { + export interface ServerRequest extends events.EventEmitter, stream.Readable { method: string; url: string; headers: any; @@ -275,7 +276,7 @@ declare module "http" { resume(): void; connection: net.Socket; } - export interface ServerResponse extends events.EventEmitter, WritableStream { + export interface ServerResponse extends events.EventEmitter, stream.Writable { // Extended base methods write(buffer: Buffer): boolean; write(buffer: Buffer, cb?: Function): boolean; @@ -301,7 +302,7 @@ declare module "http" { end(str: string, encoding?: string, cb?: Function): void; end(data?: any, encoding?: string): void; } - export interface ClientRequest extends events.EventEmitter, WritableStream { + export interface ClientRequest extends events.EventEmitter, stream.Writable { // Extended base methods write(buffer: Buffer): boolean; write(buffer: Buffer, cb?: Function): boolean; @@ -322,7 +323,7 @@ declare module "http" { end(str: string, encoding?: string, cb?: Function): void; end(data?: any, encoding?: string): void; } - export interface ClientResponse extends events.EventEmitter, ReadableStream { + export interface ClientResponse extends events.EventEmitter, stream.Readable { statusCode: number; httpVersion: string; headers: any; @@ -385,13 +386,13 @@ declare module "zlib" { import stream = require("stream"); export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } - export interface Gzip extends ReadWriteStream { } - export interface Gunzip extends ReadWriteStream { } - export interface Deflate extends ReadWriteStream { } - export interface Inflate extends ReadWriteStream { } - export interface DeflateRaw extends ReadWriteStream { } - export interface InflateRaw extends ReadWriteStream { } - export interface Unzip extends ReadWriteStream { } + export interface Gzip extends stream.Transform { } + export interface Gunzip extends stream.Transform { } + export interface Deflate extends stream.Transform { } + export interface Inflate extends stream.Transform { } + export interface DeflateRaw extends stream.Transform { } + export interface InflateRaw extends stream.Transform { } + export interface Unzip extends stream.Transform { } export function createGzip(options?: ZlibOptions): Gzip; export function createGunzip(options?: ZlibOptions): Gunzip; @@ -531,8 +532,8 @@ declare module "repl" { export interface ReplOptions { prompt?: string; - input?: ReadableStream; - output?: WritableStream; + input?: NodeReadableStream; + output?: NodeWritableStream; terminal?: boolean; eval?: Function; useColors?: boolean; @@ -557,8 +558,8 @@ declare module "readline" { write(data: any, key?: any): void; } export interface ReadLineOptions { - input: ReadableStream; - output: WritableStream; + input: NodeReadableStream; + output: NodeWritableStream; completer?: Function; terminal?: boolean; } @@ -583,9 +584,9 @@ declare module "child_process" { import stream = require("stream"); export interface ChildProcess extends events.EventEmitter { - stdin: WritableStream; - stdout: ReadableStream; - stderr: ReadableStream; + stdin: stream.Writable; + stdout: stream.Readable; + stderr: stream.Readable; pid: number; kill(signal?: string): void; send(message: any, sendHandle: any): void; @@ -679,7 +680,7 @@ declare module "dns" { declare module "net" { import stream = require("stream"); - export interface Socket extends ReadWriteStream { + export interface Socket extends stream.Duplex { // Extended base methods write(buffer: Buffer): boolean; write(buffer: Buffer, cb?: Function): boolean; @@ -787,8 +788,8 @@ declare module "fs" { close(): void; } - export interface ReadStream extends ReadableStream { } - export interface WriteStream extends WritableStream { } + export interface ReadStream extends stream.Readable {} + export interface WriteStream extends stream.Writable {} export function rename(oldPath: string, newPath: string, callback?: (err?: NodeErrnoException) => void): void; export function renameSync(oldPath: string, newPath: string): void; @@ -980,7 +981,7 @@ declare module "tls" { connections: number; } - export interface ClearTextStream extends ReadWriteStream { + export interface ClearTextStream extends stream.Duplex { authorized: boolean; authorizationError: Error; getPeerCertificate(): any; @@ -1085,7 +1086,7 @@ declare module "stream" { objectMode?: boolean; } - export class Readable extends events.EventEmitter implements ReadableStream { + export class Readable extends events.EventEmitter implements NodeReadableStream { readable: boolean; constructor(opts?: ReadableOptions); _read(size: number): void; @@ -1093,11 +1094,11 @@ declare module "stream" { setEncoding(encoding: string): void; pause(): void; resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; unshift(chunk: string): void; unshift(chunk: Buffer): void; - wrap(oldStream: ReadableStream): ReadableStream; + wrap(oldStream: NodeReadableStream): NodeReadableStream; push(chunk: any, encoding?: string): boolean; } @@ -1106,7 +1107,7 @@ declare module "stream" { decodeStrings?: boolean; } - export class Writable extends events.EventEmitter implements WritableStream { + export class Writable extends events.EventEmitter implements NodeWritableStream { writable: boolean; constructor(opts?: WritableOptions); _write(data: Buffer, encoding: string, callback: Function): void; @@ -1125,7 +1126,7 @@ declare module "stream" { } // Note: Duplex extends both Readable and Writable. - export class Duplex extends Readable implements ReadWriteStream { + export class Duplex extends Readable implements NodeReadWriteStream { writable: boolean; constructor(opts?: DuplexOptions); _write(data: Buffer, encoding: string, callback: Function): void; @@ -1142,7 +1143,7 @@ declare module "stream" { export interface TransformOptions extends ReadableOptions, WritableOptions {} // Note: Transform lacks the _read and _write methods of Readable/Writable. - export class Transform extends events.EventEmitter implements ReadWriteStream { + export class Transform extends events.EventEmitter implements NodeReadWriteStream { readable: boolean; writable: boolean; constructor(opts?: TransformOptions); @@ -1153,11 +1154,11 @@ declare module "stream" { setEncoding(encoding: string): void; pause(): void; resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; unshift(chunk: string): void; unshift(chunk: Buffer): void; - wrap(oldStream: ReadableStream): ReadableStream; + wrap(oldStream: NodeReadableStream): NodeReadableStream; push(chunk: any, encoding?: string): boolean; write(buffer: Buffer, cb?: Function): boolean; write(str: string, cb?: Function): boolean; diff --git a/promptly/promptly.d.ts b/promptly/promptly.d.ts index 3469ea04a..8999d1cc4 100644 --- a/promptly/promptly.d.ts +++ b/promptly/promptly.d.ts @@ -6,6 +6,7 @@ /// declare module "promptly" { + import stream = require('stream'); interface Callback { (err: Error, value: string): void; @@ -17,8 +18,8 @@ declare module "promptly" { validator?: any; retry?: boolean; silent?: boolean; - input?: ReadableStream; - output?: WritableStream; + input?: NodeReadableStream; + output?: NodeWritableStream; } export function prompt(message: string, fn?: Callback):any; diff --git a/q-io/Q-io.d.ts b/q-io/Q-io.d.ts index f9d1c10d1..cc321e24b 100644 --- a/q-io/Q-io.d.ts +++ b/q-io/Q-io.d.ts @@ -200,7 +200,7 @@ declare module Qio { read(charset:string):Q.Promise; read():Q.Promise; close():void; - node:ReadableStream; + node: NodeReadableStream; } interface Writer { write(content:string):void; @@ -208,7 +208,7 @@ declare module Qio { flush():Q.Promise; close():void; destroy():void; - node:WritableStream; + node: NodeWritableStream; } interface Stream { diff --git a/superagent/superagent.d.ts b/superagent/superagent.d.ts index f416dee81..df0e288e9 100644 --- a/superagent/superagent.d.ts +++ b/superagent/superagent.d.ts @@ -6,6 +6,7 @@ /// declare module "superagent" { + import stream = require('stream'); export interface Response { text: string; body: any; @@ -44,7 +45,7 @@ declare module "superagent" { send(data: Object): Request; write(data: string, encoding: string): boolean; write(data: Buffer, encoding: string): boolean; - pipe(stream: WritableStream, options?: Object): WritableStream; + pipe(stream: NodeWritableStream, options?: Object): stream.Writable; buffer(val: boolean): Request; timeout(ms: number): Request; clearTimeout(): Request; diff --git a/through/through.d.ts b/through/through.d.ts index 8a617c424..1491085a2 100644 --- a/through/through.d.ts +++ b/through/through.d.ts @@ -6,7 +6,7 @@ /// declare module "through" { - import Stream = require("stream"); + import stream = require("stream"); function through(write?: (data) => void, end?: () => void, @@ -15,7 +15,7 @@ declare module "through" { }): through.ThroughStream; module through { - export interface ThroughStream extends ReadWriteStream { + export interface ThroughStream extends stream.Transform { autoDestroy: boolean; } }