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
13 changes: 9 additions & 4 deletions types/node/child_process.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare module 'child_process' {
import * as net from 'net';
import { Writable, Readable, Stream, Pipe } from 'stream';

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

interface ChildProcess extends EventEmitter {
Expand All @@ -20,7 +20,7 @@ declare module 'child_process' {
Readable | Writable | null | undefined // extra
];
readonly killed: boolean;
readonly pid: number;
readonly pid?: number;
readonly connected: boolean;
readonly exitCode: number | null;
readonly signalCode: NodeJS.Signals | null;
Expand Down Expand Up @@ -135,12 +135,18 @@ declare module 'child_process' {

type SerializationType = 'json' | 'advanced';

interface MessagingOptions {
interface MessagingOptions extends Abortable {
/**
* Specify the kind of serialization used for sending messages between processes.
* @default 'json'
*/
serialization?: SerializationType;

/**
* The signal value to be used when the spawned process will be killed by the abort signal.
* @default 'SIGTERM'
*/
killSignal?: NodeJS.Signals | number;
}

interface ProcessEnvOptions {
Expand Down Expand Up @@ -451,7 +457,6 @@ declare module 'child_process' {

interface SpawnSyncOptions extends CommonSpawnOptions {
input?: string | NodeJS.ArrayBufferView;
killSignal?: NodeJS.Signals | number;
maxBuffer?: number;
encoding?: BufferEncoding | 'buffer' | null;
}
Expand Down
59 changes: 59 additions & 0 deletions types/node/crypto.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,45 @@ declare module 'crypto' {
passphrase?: string | Buffer;
}

interface JwkKeyExportOptions {
format: 'jwk';
}

interface JsonWebKey {
crv?: string;
d?: string;
dp?: string;
dq?: string;
e?: string;
k?: string;
kty?: string;
n?: string;
p?: string;
q?: string;
qi?: string;
x?: string;
y?: string;
}

interface AsymmetricKeyDetails {
/**
* Key size in bits (RSA, DSA).
*/
modulusLength?: number;
/**
* Public exponent (RSA).
*/
publicExponent?: bigint;
/**
* Size of q in bits (DSA).
*/
divisorLength?: number;
/**
* Name of the curve (EC).
*/
namedCurve?: string;
}

class KeyObject {
private constructor();
asymmetricKeyType?: KeyType;
Expand All @@ -205,6 +244,13 @@ declare module 'crypto' {
* bytes. This property is `undefined` for symmetric keys.
*/
asymmetricKeySize?: number;
/**
* This property exists only on asymmetric keys. Depending on the type of the key,
* this object contains information about the key. None of the information obtained
* through this property can be used to uniquely identify a key or to compromise the
* security of the key.
*/
asymmetricKeyDetails?: AsymmetricKeyDetails;
export(options: KeyExportOptions<'pem'>): string | Buffer;
export(options?: KeyExportOptions<'der'>): Buffer;
symmetricKeySize?: number;
Expand Down Expand Up @@ -1171,6 +1217,12 @@ declare module 'crypto' {
data: NodeJS.ArrayBufferView,
key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput,
): Buffer;
function sign(
algorithm: string | null | undefined,
data: NodeJS.ArrayBufferView,
key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput,
callback: (error: Error | null, data: Buffer) => void
): void;

/**
* Calculates and returns the signature for `data` using the given private key and
Expand All @@ -1186,6 +1238,13 @@ declare module 'crypto' {
key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
signature: NodeJS.ArrayBufferView,
): boolean;
function verify(
algorithm: string | null | undefined,
data: NodeJS.ArrayBufferView,
key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
signature: NodeJS.ArrayBufferView,
callback: (error: Error | null, result: boolean) => void
): void;

/**
* Computes the Diffie-Hellman secret based on a privateKey and a publicKey.
Expand Down
12 changes: 9 additions & 3 deletions types/node/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ interface ImportMeta {
------------------------------------------------*/

// For backwards compability
interface NodeRequire extends NodeJS.Require {}
interface RequireResolve extends NodeJS.RequireResolve {}
interface NodeModule extends NodeJS.Module {}
interface NodeRequire extends NodeJS.Require { }
interface RequireResolve extends NodeJS.RequireResolve { }
interface NodeModule extends NodeJS.Module { }

declare var process: NodeJS.Process;
declare var console: Console;
Expand Down Expand Up @@ -318,6 +318,7 @@ interface AbortController {
/**
* Returns the AbortSignal object associated with this object.
*/

readonly signal: AbortSignal;
/**
* Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
Expand All @@ -331,6 +332,11 @@ interface AbortSignal {
* Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.
*/
readonly aborted: boolean;

/**
* Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
*/
abort(): void;
Copy link
Contributor

@achingbrain achingbrain Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is being treated as an instance method which I'm not sure is correct.

There's nothing on the node docs for an abort() instance method on AbortSignal, only a static AbortSignal.abort() method. There's also nothing on the MDN docs for this method and it's not in the node.js source for AbortSignal either.

TS compilation with @types/[email protected] fails with:

 Argument of type 'import("/path/to/node_modules/abort-controller/dist/abort-controller").AbortSignal' is not assignable to parameter of type 'AbortSignal'.
  Property 'abort' is missing in type 'import("/path/to/node_modules/abort-controller/dist/abort-controller").AbortSignal' but required in type 'AbortSignal'.

  node_modules/@types/node/globals.d.ts:339:5
    339     abort(): void;
            ~~~~~~~~~~~~~~
    'abort' is declared here.

node_modules/abort-controller is the abort-controller module, on which the node implementation is closely based.

@types/[email protected] works as expected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR was already merged. you might wanna open an issue or better create a PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yea I read the changelog wrong, I will file a PR asap.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I cannot make it static as this will conflict with the lib dom typings, I will remove the method entirely for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is here for anyone with power to approve.

}

declare var AbortController: {
Expand Down
7 changes: 7 additions & 0 deletions types/node/http2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ declare module 'http2' {
paddingStrategy?: number;
peerMaxConcurrentStreams?: number;
settings?: Settings;
/**
* Specifies a timeout in milliseconds that
* a server should wait when an [`'unknownProtocol'`][] is emitted. If the
* socket has not been destroyed by that time the server will destroy it.
* @default 100000
*/
unknownProtocolTimeout?: number;

selectPadding?(frameLen: number, maxFrameLen: number): number;
createConnection?(authority: url.URL, option: SessionOptions): stream.Duplex;
Expand Down
12 changes: 6 additions & 6 deletions types/node/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for non-npm package Node.js 15.9
// Type definitions for non-npm package Node.js 15.12
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
Expand Down Expand Up @@ -50,9 +50,9 @@

// NOTE: TypeScript version-specific augmentations can be found in the following paths:
// - ~/base.d.ts - Shared definitions common to all TypeScript versions
// - ~/index.d.ts - Definitions specific to TypeScript 2.8
// - ~/ts3.5/index.d.ts - Definitions specific to TypeScript 3.5
// - ~/index.d.ts - Definitions specific to TypeScript 3.7
// - ~/ts3.6/index.d.ts - Definitions specific to TypeScript 3.6

// NOTE: Augmentations for TypeScript 3.5 and later should use individual files for overrides
// within the respective ~/ts3.5 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.5, so the older definitions will be found here.
// NOTE: Augmentations for TypeScript 3.6 and later should use individual files for overrides
// within the respective ~/ts3.6 (or later) folder. However, this is disallowed for versions
// prior to TypeScript 3.6, so the older definitions will be found here.
2 changes: 1 addition & 1 deletion types/node/stream.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ declare module 'stream' {
*/
function addAbortSignal<T extends Stream>(signal: AbortSignal, stream: T): T;

interface FinishedOptions {
interface FinishedOptions extends Abortable {
error?: boolean;
readable?: boolean;
writable?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion types/node/test/child_process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Writable, Readable, Pipe } from 'stream';
childProcess.exec("echo test");
childProcess.exec("echo test", { windowsHide: true });
childProcess.spawn("echo");
childProcess.spawn("echo", { windowsHide: true, signal: new AbortSignal() });
childProcess.spawn("echo", { windowsHide: true, signal: new AbortSignal(), killSignal: "SIGABRT" });
childProcess.spawn("echo", ["test"], { windowsHide: true });
childProcess.spawn("echo", ["test"], { windowsHide: true, argv0: "echo-test" });
childProcess.spawn("echo", ["test"], { stdio: [0xdeadbeef, "inherit", undefined, "pipe"] });
Expand Down Expand Up @@ -55,6 +55,7 @@ import { Writable, Readable, Pipe } from 'stream';
execPath: '',
execArgv: ['asda'],
signal: new AbortSignal(),
killSignal: "SIGABRT"
});
const ipc: Pipe = forked.channel!;
const hasRef: boolean = ipc.hasRef();
Expand Down
25 changes: 25 additions & 0 deletions types/node/test/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,11 @@ import { promisify } from 'util';

{
const sig: Buffer = crypto.sign('md5', Buffer.from(''), 'mykey');

crypto.sign('md5', Buffer.from(''), 'mykey', (error: Error | null, data: Buffer) => { });

const correct: boolean = crypto.verify('md5', sig, 'mykey', sig);
crypto.verify('md5', sig, 'mykey', sig, (error: Error | null, result: boolean) => { });
}

{
Expand Down Expand Up @@ -1035,3 +1039,24 @@ import { promisify } from 'util';
crypto.checkPrimeSync(123n); // $ExpectType boolean
crypto.checkPrimeSync(123n, { checks: 123 }); // $ExpectType boolean
}

{
crypto.generateKeyPair('ec', { namedCurve: 'P-256' }, (err, publicKey, privateKey) => {
for (const keyObject of [publicKey, privateKey]) {
if (keyObject.asymmetricKeyDetails) {
if (keyObject.asymmetricKeyDetails.modulusLength) {
const modulusLength: number = keyObject.asymmetricKeyDetails.modulusLength;
}
if (keyObject.asymmetricKeyDetails.publicExponent) {
const publicExponent: bigint = keyObject.asymmetricKeyDetails.publicExponent;
}
if (keyObject.asymmetricKeyDetails.divisorLength) {
const divisorLength: number = keyObject.asymmetricKeyDetails.divisorLength;
}
if (keyObject.asymmetricKeyDetails.namedCurve) {
const namedCurve: string = keyObject.asymmetricKeyDetails.namedCurve;
}
}
}
});
}
3 changes: 2 additions & 1 deletion types/node/test/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ import { URL } from 'url';
paddingStrategy: 0,
peerMaxConcurrentStreams: 0,
selectPadding: (frameLen: number, maxFrameLen: number) => 0,
settings
settings,
unknownProtocolTimeout: 123,
};
// tslint:disable-next-line prefer-object-spread (ts2.1 feature)
const secureServerOptions: SecureServerOptions = Object.assign({}, serverOptions);
Expand Down
2 changes: 1 addition & 1 deletion types/node/test/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function streamPipelineFinished() {
let cancel = finished(process.stdin, (err?: Error | null) => {});
cancel();

cancel = finished(process.stdin, { readable: false }, (err?: Error | null) => {});
cancel = finished(process.stdin, { readable: false, signal: new AbortSignal() }, (err?: Error | null) => {});
cancel();

pipeline(process.stdin, process.stdout, (err?: Error | null) => {});
Expand Down
7 changes: 7 additions & 0 deletions types/node/test/worker_threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,10 @@ import { EventLoopUtilization } from 'perf_hooks';
bc.onmessage = (msg: unknown) => { };
bc.onmessageerror = (msg: unknown) => { };
}

{
workerThreads.setEnvironmentData('test', 1);
workerThreads.setEnvironmentData(123, { a: 1 });
workerThreads.getEnvironmentData('test'); // $ExpectType Serializable
workerThreads.getEnvironmentData(1); // $ExpectType Serializable
}
8 changes: 4 additions & 4 deletions types/node/ts3.6/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// NOTE: TypeScript version-specific augmentations can be found in the following paths:
// - ~/base.d.ts - Shared definitions common to all TypeScript versions
// - ~/index.d.ts - Definitions specific to TypeScript 3.7 and above
// - ~/ts3.5/base.d.ts - Definitions specific to TypeScript 3.6 and earlier
// - ~/ts3.5/index.d.ts - Definitions specific to TypeScript 3.6 and earlier with assert pulled in
// - ~/ts3.6/base.d.ts - Definitions specific to TypeScript 3.6 and earlier
// - ~/ts3.6/index.d.ts - Definitions specific to TypeScript 3.6 and earlier with assert pulled in

// Reference required types from the default lib:
/// <reference lib="es2018" />
Expand Down Expand Up @@ -61,8 +61,8 @@
/// <reference path="../worker_threads.d.ts" />
/// <reference path="../zlib.d.ts" />

// TypeScript 3.5-specific augmentations:
// TypeScript 3.6-specific augmentations:
/// <reference path="../globals.global.d.ts" />

// TypeScript 3.5-specific augmentations:
// TypeScript 3.6-specific augmentations:
/// <reference path="../wasi.d.ts" />
2 changes: 1 addition & 1 deletion types/node/ts3.6/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// NOTE: These definitions support NodeJS and TypeScript 3.5 - 3.6.
// NOTE: These definitions support NodeJS and TypeScript 3.6.
// This is required to enable typing assert in ts3.7 without causing errors
// Typically type modifications should be made in base.d.ts instead of here

Expand Down
17 changes: 17 additions & 0 deletions types/node/worker_threads.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,21 @@ declare module 'worker_threads' {
* `MessagePort`’s queue.
*/
function receiveMessageOnPort(port: MessagePort): { message: any } | undefined;

type Serializable = string | object | number | boolean | bigint;

/**
* @param key Any arbitrary, cloneable JavaScript value that can be used as a {Map} key.
* @experimental
*/
function getEnvironmentData(key: Serializable): Serializable;

/**
* @param key Any arbitrary, cloneable JavaScript value that can be used as a {Map} key.
* @param value Any arbitrary, cloneable JavaScript value that will be cloned
* and passed automatically to all new `Worker` instances. If `value` is passed
* as `undefined`, any previously set value for the `key` will be deleted.
* @experimental
*/
function setEnvironmentData(key: Serializable, value: Serializable): void;
}