Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions types/node/child_process.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
declare module 'child_process' {
import { BaseEncodingOptions } from 'fs';
import * as events from 'events';
import { EventEmitter, Abortable } from 'events';
import * as net from 'net';
import { Writable, Readable, Stream, Pipe } from 'stream';

type Serializable = string | object | number | boolean;
type SendHandle = net.Socket | net.Server;

interface ChildProcess extends events.EventEmitter {
interface ChildProcess extends EventEmitter {
stdin: Writable | null;
stdout: Readable | null;
stderr: Readable | null;
Expand Down Expand Up @@ -129,7 +129,9 @@ declare module 'child_process' {
keepOpen?: boolean;
}

type StdioOptions = "pipe" | "ignore" | "inherit" | Array<("pipe" | "ipc" | "ignore" | "inherit" | Stream | number | null | undefined)>;
type IOType = "overlapped" | "pipe" | "ignore" | "inherit";

type StdioOptions = IOType | Array<(IOType | "ipc" | Stream | number | null | undefined)>;

type SerializationType = 'json' | 'advanced';

Expand Down Expand Up @@ -159,7 +161,7 @@ declare module 'child_process' {
timeout?: number;
}

interface CommonSpawnOptions extends CommonOptions, MessagingOptions {
interface CommonSpawnOptions extends CommonOptions, MessagingOptions, Abortable {
argv0?: string;
stdio?: StdioOptions;
shell?: boolean | string;
Expand All @@ -171,11 +173,12 @@ declare module 'child_process' {
}

interface SpawnOptionsWithoutStdio extends SpawnOptions {
stdio?: 'pipe' | Array<null | undefined | 'pipe'>;
stdio?: StdioPipeNamed | StdioPipe[];
}

type StdioNull = 'inherit' | 'ignore' | Stream;
type StdioPipe = undefined | null | 'pipe';
type StdioPipeNamed = 'pipe' | 'overlapped';
type StdioPipe = undefined | null | StdioPipeNamed;

interface SpawnOptionsWithStdioTuple<
Stdin extends StdioNull | StdioPipe,
Expand Down Expand Up @@ -330,11 +333,12 @@ declare module 'child_process' {
function __promisify__(command: string, options?: (BaseEncodingOptions & ExecOptions) | null): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
}

interface ExecFileOptions extends CommonOptions {
interface ExecFileOptions extends CommonOptions, Abortable {
maxBuffer?: number;
killSignal?: NodeJS.Signals | number;
windowsVerbatimArguments?: boolean;
shell?: boolean | string;
signal?: AbortSignal;
}
interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
encoding: BufferEncoding;
Expand Down Expand Up @@ -434,7 +438,7 @@ declare module 'child_process' {
): PromiseWithChild<{ stdout: string | Buffer, stderr: string | Buffer }>;
}

interface ForkOptions extends ProcessEnvOptions, MessagingOptions {
interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable {
execPath?: string;
execArgv?: string[];
silent?: boolean;
Expand Down
186 changes: 186 additions & 0 deletions types/node/crypto.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare module 'crypto' {
import * as stream from 'stream';
import { PeerCertificate } from 'tls';

interface Certificate {
/**
Expand Down Expand Up @@ -1267,4 +1268,189 @@ declare module 'crypto' {
* or if the derived key cannot be generated.
*/
function hkdfSync(digest: string, key: BinaryLike | KeyObject, salt: BinaryLike, info: BinaryLike, keylen: number): ArrayBuffer;

interface SecureHeapUsage {
/**
* The total allocated secure heap size as specified using the `--secure-heap=n` command-line flag.
*/
total: number;

/**
* The minimum allocation from the secure heap as specified using the `--secure-heap-min` command-line flag.
*/
min: number;

/**
* The total number of bytes currently allocated from the secure heap.
*/
used: number;

/**
* The calculated ratio of `used` to `total` allocated bytes.
*/
utilization: number;
}

function secureHeapUsed(): SecureHeapUsage;

// TODO: X509Certificate

interface RandomUUIDOptions {
/**
* By default, to improve performance,
* Node.js will pre-emptively generate and persistently cache enough
* random data to generate up to 128 random UUIDs. To generate a UUID
* without using the cache, set `disableEntropyCache` to `true`.
*
* @default `false`
*/
disableEntropyCache?: boolean;
}

function randomUUID(options?: RandomUUIDOptions): string;

interface X509CheckOptions {
/**
* @default 'always'
*/
subject: 'always' | 'never';

/**
* @default true
*/
wildcards: boolean;

/**
* @default true
*/
partialWildcards: boolean;

/**
* @default false
*/
multiLabelWildcards: boolean;

/**
* @default false
*/
singleLabelSubdomains: boolean;
}

class X509Certificate {
/**
* Will be `true` if this is a Certificate Authority (ca) certificate.
*/
readonly ca: boolean;

/**
* The SHA-1 fingerprint of this certificate.
*/
readonly fingerprint: string;

/**
* The SHA-256 fingerprint of this certificate.
*/
readonly fingerprint256: string;

/**
* The complete subject of this certificate.
*/
readonly subject: string;

/**
* The subject alternative name specified for this certificate.
*/
readonly subjectAltName: string;

/**
* The information access content of this certificate.
*/
readonly infoAccess: string;

/**
* An array detailing the key usages for this certificate.
*/
readonly keyUsage: string[];

/**
* The public key for this certificate.
*/
readonly publicKey: KeyObject;

/**
* A `Buffer` containing the DER encoding of this certificate.
*/
readonly raw: Buffer;

/**
* The serial number of this certificate.
*/
readonly serialNumber: string;

/**
* Returns the PEM-encoded certificate.
*/
readonly validFrom: string;

/**
* The date/time from which this certificate is considered valid.
*/
readonly validTo: string;

constructor(buffer: BinaryLike);

/**
* Checks whether the certificate matches the given email address.
*
* Returns `email` if the certificate matches,`undefined` if it does not.
*/
checkEmail(email: string, options?: X509CheckOptions): string | undefined;

/**
* Checks whether the certificate matches the given host name.
*
* Returns `name` if the certificate matches, `undefined` if it does not.
*/
checkHost(name: string, options?: X509CheckOptions): string | undefined;

/**
* Checks whether the certificate matches the given IP address (IPv4 or IPv6).
*
* Returns `ip` if the certificate matches, `undefined` if it does not.
*/
checkIP(ip: string, options?: X509CheckOptions): string | undefined;

/**
* Checks whether this certificate was issued by the given `otherCert`.
*/
checkIssued(otherCert: X509Certificate): boolean;

/**
* Checks whether this certificate was issued by the given `otherCert`.
*/
checkPrivateKey(privateKey: KeyObject): boolean;

/**
* There is no standard JSON encoding for X509 certificates. The
* `toJSON()` method returns a string containing the PEM encoded
* certificate.
*/
toJSON(): string;

/**
* Returns information about this certificate using the legacy [certificate object][] encoding.
*/
toLegacyObject(): PeerCertificate;

/**
* Returns the PEM-encoded certificate.
*/
toString(): string;

/**
* Verifies that this certificate was signed by the given public key.
* Does not perform any other validation checks on the certificate.
*/
verify(publicKey: KeyObject): boolean;
}
}
7 changes: 7 additions & 0 deletions types/node/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ declare module 'events' {
namespace EventEmitter {
// Should just be `export { EventEmitter }`, but that doesn't work in TypeScript 3.4
export { internal as EventEmitter };

export interface Abortable {
/**
* When provided the corresponding `AbortController` can be used to cancel an asynchronous action.
*/
signal?: AbortSignal;
}
}

global {
Expand Down
41 changes: 16 additions & 25 deletions types/node/fs.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'fs' {
import * as stream from 'stream';
import EventEmitter = require('events');
import { Abortable, EventEmitter } from 'events';
import { URL } from 'url';
import * as promises from 'fs/promises';

Expand Down Expand Up @@ -142,11 +142,6 @@ declare module 'fs' {
prependOnceListener(event: "close", listener: () => void): this;
}

// TODO: Move this to a more central location
export interface Abortable {
signal?: AbortSignal;
}

export class ReadStream extends stream.Readable {
close(): void;
bytesRead: number;
Expand Down Expand Up @@ -2067,41 +2062,37 @@ declare module 'fs' {
*/
export function accessSync(path: PathLike, mode?: number): void;

/**
* Returns a new `ReadStream` object.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* URL support is _experimental_.
*/
export function createReadStream(path: PathLike, options?: string | {
interface StreamOptions {
flags?: string;
encoding?: BufferEncoding;
fd?: number;
fd?: number | promises.FileHandle;
mode?: number;
autoClose?: boolean;
/**
* @default false
*/
emitClose?: boolean;
start?: number;
end?: number;
highWaterMark?: number;
}): ReadStream;
}

interface ReadStreamOptions extends StreamOptions {
end?: number;
}

/**
* Returns a new `ReadStream` object.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* URL support is _experimental_.
*/
export function createReadStream(path: PathLike, options?: string | ReadStreamOptions): ReadStream;

/**
* Returns a new `WriteStream` object.
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
* URL support is _experimental_.
*/
export function createWriteStream(path: PathLike, options?: string | {
flags?: string;
encoding?: BufferEncoding;
fd?: number;
mode?: number;
autoClose?: boolean;
emitClose?: boolean;
start?: number;
highWaterMark?: number;
}): WriteStream;
export function createWriteStream(path: PathLike, options?: string | StreamOptions): WriteStream;

/**
* Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
Expand Down
2 changes: 1 addition & 1 deletion types/node/fs/promises.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare module 'fs/promises' {
import { Abortable } from 'events';
import {
Stats,
BigIntStats,
Expand All @@ -16,7 +17,6 @@ declare module 'fs/promises' {
BufferEncodingOption,
OpenMode,
Mode,
Abortable,
} from 'fs';

interface FileHandle {
Expand Down
4 changes: 4 additions & 0 deletions types/node/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ declare namespace NodeJS {
'.node': (m: Module, filename: string) => any;
}
interface Module {
/**
* `true` if the module is running during the Node.js preload
*/
isPreloading: boolean;
exports: any;
require: Require;
id: string;
Expand Down
Loading