From: Matt Corallo Date: Fri, 22 Jul 2022 21:55:44 +0000 (+0000) Subject: [TS] Add additional node API interface bits for net X-Git-Tag: v0.0.110.0~1^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=458e8606df728b612297b370002edf522ab99eb1;p=ldk-java [TS] Add additional node API interface bits for net --- diff --git a/node-net/node_modules/@types/node b/node-net/node_modules/@types/node new file mode 120000 index 00000000..d80bd63a --- /dev/null +++ b/node-net/node_modules/@types/node @@ -0,0 +1 @@ +../../../ts/node/ \ No newline at end of file diff --git a/node-net/node_modules/lightningdevkit b/node-net/node_modules/lightningdevkit new file mode 120000 index 00000000..2351a940 --- /dev/null +++ b/node-net/node_modules/lightningdevkit @@ -0,0 +1 @@ +../../ts \ No newline at end of file diff --git a/ts/node/buffer.d.ts b/ts/node/buffer.d.ts new file mode 100755 index 00000000..eaba0379 --- /dev/null +++ b/ts/node/buffer.d.ts @@ -0,0 +1,10 @@ +// Minimal part of the Node API which we depend on. +// May be (c) Microsoft licensed under the MIT license, however API's are not generally copyrightable per recent precedent. +declare module 'buffer' { + global { + interface Buffer extends Uint8Array {} + } +} +declare module 'node:buffer' { + export * from 'buffer'; +} diff --git a/ts/node/crypto.d.ts b/ts/node/crypto.d.ts index f7020d4d..5d2a7163 100755 --- a/ts/node/crypto.d.ts +++ b/ts/node/crypto.d.ts @@ -2,7 +2,7 @@ // May be (c) Microsoft licensed under the MIT license, however API's are not generally copyrightable per recent precedent. declare module 'crypto' { namespace webcrypto { - function getRandomValues(TypedArray): void; + function getRandomValues(out: Uint8Array): void; } } declare module 'node:crypto' { diff --git a/ts/node/fs.d.ts b/ts/node/fs.d.ts index 76792ddd..95a17e0b 100755 --- a/ts/node/fs.d.ts +++ b/ts/node/fs.d.ts @@ -1,7 +1,7 @@ // Minimal part of the Node fs API which we depend on. // May be (c) Microsoft licensed under the MIT license, however API's are not generally copyrightable per recent precedent. declare module 'fs' { - export type PathLike = string | Buffer | URL; + export type PathLike = string | URL; export type PathOrFileDescriptor = PathLike | number; export function readFileSync( path: PathOrFileDescriptor, diff --git a/ts/node/index.d.ts b/ts/node/index.d.ts index 3f2f5c77..24931b1b 100755 --- a/ts/node/index.d.ts +++ b/ts/node/index.d.ts @@ -1,4 +1,7 @@ // Minimal part of the Node API which we depend on. // May be (c) Microsoft licensed under the MIT license, however API's are not generally copyrightable per recent precedent. +/// /// /// +/// +/// diff --git a/ts/node/net.d.ts b/ts/node/net.d.ts new file mode 100755 index 00000000..07350ff9 --- /dev/null +++ b/ts/node/net.d.ts @@ -0,0 +1,32 @@ +// Minimal part of the Node fs API which we depend on. +// May be (c) Microsoft licensed under the MIT license, however API's are not generally copyrightable per recent precedent. +declare module 'net' { + import * as stream from 'node:stream'; + class Socket extends stream.Duplex { + constructor(); + write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean; + connect(port: number, host: string, connectionListener?: () => void): this; + pause(): this; + resume(): this; + setNoDelay(noDelay?: boolean): this; + readonly remoteAddress?: string | undefined; + readonly remotePort?: number | undefined; + on(event: 'close', listener: (hadError: boolean) => void): this; + on(event: 'connect', listener: () => void): this; + on(event: 'data', listener: (data: Buffer) => void): this; + on(event: 'drain', listener: () => void): this; + on(event: 'error', listener: (err: Error) => void): this; + } + class Server { + listen(port?: number, hostname?: string, listeningListener?: () => void): this; + close(callback?: (err?: Error) => void): this; + on(event: 'error', listener: (err: Error) => void): this; + on(event: 'listening', listener: () => void): this; + } + function createServer(connectionListener?: (socket: Socket) => void): Server; + function isIPv4(input: string): boolean; + function isIPv6(input: string): boolean; +} +declare module 'node:net' { + export * from 'net'; +} diff --git a/ts/node/stream.d.ts b/ts/node/stream.d.ts new file mode 100755 index 00000000..5a202619 --- /dev/null +++ b/ts/node/stream.d.ts @@ -0,0 +1,35 @@ +/** + * A stream is an abstract interface for working with streaming data in Node.js. + * The `stream` module provides an API for implementing the stream interface. + * + * There are many stream objects provided by Node.js. For instance, a `request to an HTTP server` and `process.stdout` are both stream instances. + * + * Streams can be readable, writable, or both. All streams are instances of `EventEmitter`. + * + * To access the `stream` module: + * + * ```js + * const stream = require('stream'); + * ``` + * + * The `stream` module is useful for creating new types of stream instances. It is + * usually not necessary to use the `stream` module to consume streams. + * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/stream.js) + */ +declare module 'stream' { + namespace internal { + class Stream {} + class Readable extends Stream { + destroy(error?: Error): this; + } + class Writable extends Stream { + destroy(error?: Error): this; + } + class Duplex extends Readable implements Writable {} + } + export = internal; +} +declare module 'node:stream' { + import stream = require('stream'); + export = stream; +}