Skip to content

Commit

Permalink
feat(node): v12 (DefinitelyTyped#34952)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSchick authored and Konch Roman committed Aug 13, 2019
1 parent fa72e6b commit 0cec958
Show file tree
Hide file tree
Showing 86 changed files with 18,966 additions and 28 deletions.
12 changes: 0 additions & 12 deletions types/node/async_hooks.d.ts
Expand Up @@ -101,18 +101,6 @@ declare module "async_hooks" {
*/
constructor(type: string, triggerAsyncId?: number|AsyncResourceOptions);

/**
* Call AsyncHooks before callbacks.
* @deprecated since 9.6 - Use asyncResource.runInAsyncScope() instead.
*/
emitBefore(): void;

/**
* Call AsyncHooks after callbacks.
* @deprecated since 9.6 - Use asyncResource.runInAsyncScope() instead.
*/
emitAfter(): void;

/**
* Call the provided function with the provided arguments in the
* execution context of the async resource. This will establish the
Expand Down
36 changes: 35 additions & 1 deletion types/node/crypto.d.ts
Expand Up @@ -145,6 +145,11 @@ declare module "crypto" {
class KeyObject {
private constructor();
asymmetricKeyType?: KeyType;
/**
* For asymmetric keys, this property represents the size of the embedded key in
* bytes. This property is `undefined` for symmetric keys.
*/
asymmetricKeySize?: number;
export(options: KeyExportOptions<'pem'>): string | Buffer;
export(options?: KeyExportOptions<'der'>): Buffer;
symmetricSize?: number;
Expand Down Expand Up @@ -269,11 +274,17 @@ declare module "crypto" {

function createSign(algorithm: string, options?: stream.WritableOptions): Signer;

interface SignPrivateKeyInput extends PrivateKeyInput {
interface SigningOptions {
/**
* @See crypto.constants.RSA_PKCS1_PADDING
*/
padding?: number;
saltLength?: number;
}

interface SignPrivateKeyInput extends PrivateKeyInput, SigningOptions {
}

type KeyLike = string | Buffer | KeyObject;

class Signer extends stream.Writable {
Expand Down Expand Up @@ -565,4 +576,27 @@ declare module "crypto" {
function __promisify__(type: "ec", options: ECKeyPairOptions<'der', 'der'>): Promise<{ publicKey: Buffer, privateKey: Buffer }>;
function __promisify__(type: "ec", options: ECKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
}

/**
* Calculates and returns the signature for `data` using the given private key and
* algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is
* dependent upon the key type (especially Ed25519 and Ed448).
*
* If `key` is not a [`KeyObject`][], this function behaves as if `key` had been
* passed to [`crypto.createPrivateKey()`][].
*/
function sign(algorithm: string | null | undefined, data: Binary, key: KeyLike | SignPrivateKeyInput): Buffer;

interface VerifyKeyWithOptions extends KeyObject, SigningOptions {
}

/**
* Calculates and returns the signature for `data` using the given private key and
* algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is
* dependent upon the key type (especially Ed25519 and Ed448).
*
* If `key` is not a [`KeyObject`][], this function behaves as if `key` had been
* passed to [`crypto.createPublicKey()`][].
*/
function verify(algorithm: string | null | undefined, data: Binary, key: KeyLike | VerifyKeyWithOptions, signature: Binary): Buffer;
}
2 changes: 1 addition & 1 deletion types/node/index.d.ts
@@ -1,4 +1,4 @@
// Type definitions for non-npm package Node.js 11.13
// Type definitions for non-npm package Node.js 12.0
// Project: http://nodejs.org/
// Definitions by: Microsoft TypeScript <https://github.com/Microsoft>
// DefinitelyTyped <https://github.com/DefinitelyTyped>
Expand Down
5 changes: 5 additions & 0 deletions types/node/test/crypto.ts
Expand Up @@ -594,3 +594,8 @@ import { promisify } from 'util';
str = crypto.constants.defaultCoreCipherList;
str = crypto.constants.defaultCipherList;
}

{
const sig: Buffer = crypto.sign('md5', Buffer.from(''), 'mykey');
const correct: Buffer = crypto.verify('md5', sig, 'mykey', sig);
}
11 changes: 11 additions & 0 deletions types/node/ts3.2/globals.d.ts
Expand Up @@ -6,3 +6,14 @@ declare namespace NodeJS {
bigint(): bigint;
}
}

interface Buffer extends Uint8Array {
readBigUInt64BE(offset?: number): bigint;
readBigUInt64LE(offset?: number): bigint;
readBigInt64BE(offset?: number): bigint;
readBigInt64LE(offset?: number): bigint;
writeBigInt64BE(value: bigint, offset?: number): number;
writeBigInt64LE(value: bigint, offset?: number): number;
writeBigUInt64BE(value: bigint, offset?: number): number;
writeBigUInt64LE(value: bigint, offset?: number): number;
}
18 changes: 15 additions & 3 deletions types/node/ts3.2/node-tests.ts
Expand Up @@ -35,9 +35,7 @@ import { types } from 'util';
process.allowedNodeEnvironmentFlags.has('asdf');
}

//////////////////////////////////////////////////////////
/// Util Tests ///
//////////////////////////////////////////////////////////
// Util Tests
{
const value: BigInt64Array | BigUint64Array | number = [] as any;
if (types.isBigInt64Array(value)) {
Expand All @@ -51,3 +49,17 @@ import { types } from 'util';
const b = value;
}
}

// Global Tests

{
const a = Buffer.alloc(1000);
a.writeBigInt64BE(123n);
a.writeBigInt64LE(123n);
a.writeBigUInt64BE(123n);
a.writeBigUInt64LE(123n);
let b: bigint = a.readBigInt64BE(123);
b = a.readBigInt64LE(123);
b = a.readBigUInt64LE(123);
b = a.readBigUInt64BE(123);
}
2 changes: 1 addition & 1 deletion types/node/ts3.2/tsconfig.json
Expand Up @@ -5,7 +5,7 @@
],
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"target": "esnext",
"lib": [
"es6",
"dom"
Expand Down
8 changes: 0 additions & 8 deletions types/node/util.d.ts
Expand Up @@ -2,14 +2,6 @@ declare module "util" {
interface InspectOptions extends NodeJS.InspectOptions { }
function format(format: any, ...param: any[]): string;
function formatWithOptions(inspectOptions: InspectOptions, format: string, ...param: any[]): string;
/** @deprecated since v0.11.3 - use `console.error()` instead. */
function debug(string: string): void;
/** @deprecated since v0.11.3 - use `console.error()` instead. */
function error(...param: any[]): void;
/** @deprecated since v0.11.3 - use `console.log()` instead. */
function puts(...param: any[]): void;
/** @deprecated since v0.11.3 - use `console.log()` instead. */
function print(...param: any[]): void;
/** @deprecated since v0.11.3 - use a third party module instead. */
function log(string: string): void;
function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
Expand Down
52 changes: 52 additions & 0 deletions types/node/v11/assert.d.ts
@@ -0,0 +1,52 @@
declare module "assert" {
function internal(value: any, message?: string | Error): void;
namespace internal {
class AssertionError implements Error {
name: string;
message: string;
actual: any;
expected: any;
operator: string;
generatedMessage: boolean;
code: 'ERR_ASSERTION';

constructor(options?: {
message?: string; actual?: any; expected?: any;
operator?: string; stackStartFn?: Function
});
}

function fail(message?: string | Error): never;
/** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
function fail(actual: any, expected: any, message?: string | Error, operator?: string, stackStartFn?: Function): never;
function ok(value: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use strictEqual() instead. */
function equal(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use notStrictEqual() instead. */
function notEqual(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use deepStrictEqual() instead. */
function deepEqual(actual: any, expected: any, message?: string | Error): void;
/** @deprecated since v9.9.0 - use notDeepStrictEqual() instead. */
function notDeepEqual(actual: any, expected: any, message?: string | Error): void;
function strictEqual(actual: any, expected: any, message?: string | Error): void;
function notStrictEqual(actual: any, expected: any, message?: string | Error): void;
function deepStrictEqual(actual: any, expected: any, message?: string | Error): void;
function notDeepStrictEqual(actual: any, expected: any, message?: string | Error): void;

function throws(block: () => any, message?: string | Error): void;
function throws(block: () => any, error: RegExp | Function | Object | Error, message?: string | Error): void;
function doesNotThrow(block: () => any, message?: string | Error): void;
function doesNotThrow(block: () => any, error: RegExp | Function, message?: string | Error): void;

function ifError(value: any): void;

function rejects(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
function rejects(block: (() => Promise<any>) | Promise<any>, error: RegExp | Function | Object | Error, message?: string | Error): Promise<void>;
function doesNotReject(block: (() => Promise<any>) | Promise<any>, message?: string | Error): Promise<void>;
function doesNotReject(block: (() => Promise<any>) | Promise<any>, error: RegExp | Function, message?: string | Error): Promise<void>;

const strict: typeof internal;
}

export = internal;
}
144 changes: 144 additions & 0 deletions types/node/v11/async_hooks.d.ts
@@ -0,0 +1,144 @@
/**
* Async Hooks module: https://nodejs.org/api/async_hooks.html
*/
declare module "async_hooks" {
/**
* Returns the asyncId of the current execution context.
*/
function executionAsyncId(): number;

/**
* Returns the ID of the resource responsible for calling the callback that is currently being executed.
*/
function triggerAsyncId(): number;

interface HookCallbacks {
/**
* Called when a class is constructed that has the possibility to emit an asynchronous event.
* @param asyncId a unique ID for the async resource
* @param type the type of the async resource
* @param triggerAsyncId the unique ID of the async resource in whose execution context this async resource was created
* @param resource reference to the resource representing the async operation, needs to be released during destroy
*/
init?(asyncId: number, type: string, triggerAsyncId: number, resource: Object): void;

/**
* When an asynchronous operation is initiated or completes a callback is called to notify the user.
* The before callback is called just before said callback is executed.
* @param asyncId the unique identifier assigned to the resource about to execute the callback.
*/
before?(asyncId: number): void;

/**
* Called immediately after the callback specified in before is completed.
* @param asyncId the unique identifier assigned to the resource which has executed the callback.
*/
after?(asyncId: number): void;

/**
* Called when a promise has resolve() called. This may not be in the same execution id
* as the promise itself.
* @param asyncId the unique id for the promise that was resolve()d.
*/
promiseResolve?(asyncId: number): void;

/**
* Called after the resource corresponding to asyncId is destroyed
* @param asyncId a unique ID for the async resource
*/
destroy?(asyncId: number): void;
}

interface AsyncHook {
/**
* Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
*/
enable(): this;

/**
* Disable the callbacks for a given AsyncHook instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disabled it will not be called again until enabled.
*/
disable(): this;
}

/**
* Registers functions to be called for different lifetime events of each async operation.
* @param options the callbacks to register
* @return an AsyncHooks instance used for disabling and enabling hooks
*/
function createHook(options: HookCallbacks): AsyncHook;

interface AsyncResourceOptions {
/**
* The ID of the execution context that created this async event.
* Default: `executionAsyncId()`
*/
triggerAsyncId?: number;

/**
* Disables automatic `emitDestroy` when the object is garbage collected.
* This usually does not need to be set (even if `emitDestroy` is called
* manually), unless the resource's `asyncId` is retrieved and the
* sensitive API's `emitDestroy` is called with it.
* Default: `false`
*/
requireManualDestroy?: boolean;
}

/**
* The class AsyncResource was designed to be extended by the embedder's async resources.
* Using this users can easily trigger the lifetime events of their own resources.
*/
class AsyncResource {
/**
* AsyncResource() is meant to be extended. Instantiating a
* new AsyncResource() also triggers init. If triggerAsyncId is omitted then
* async_hook.executionAsyncId() is used.
* @param type The type of async event.
* @param triggerAsyncId The ID of the execution context that created
* this async event (default: `executionAsyncId()`), or an
* AsyncResourceOptions object (since 9.3)
*/
constructor(type: string, triggerAsyncId?: number|AsyncResourceOptions);

/**
* Call AsyncHooks before callbacks.
* @deprecated since 9.6 - Use asyncResource.runInAsyncScope() instead.
*/
emitBefore(): void;

/**
* Call AsyncHooks after callbacks.
* @deprecated since 9.6 - Use asyncResource.runInAsyncScope() instead.
*/
emitAfter(): void;

/**
* Call the provided function with the provided arguments in the
* execution context of the async resource. This will establish the
* context, trigger the AsyncHooks before callbacks, call the function,
* trigger the AsyncHooks after callbacks, and then restore the original
* execution context.
* @param fn The function to call in the execution context of this
* async resource.
* @param thisArg The receiver to be used for the function call.
* @param args Optional arguments to pass to the function.
*/
runInAsyncScope<This, Result>(fn: (this: This, ...args: any[]) => Result, thisArg?: This, ...args: any[]): Result;

/**
* Call AsyncHooks destroy callbacks.
*/
emitDestroy(): void;

/**
* @return the unique ID assigned to this AsyncResource instance.
*/
asyncId(): number;

/**
* @return the trigger ID for this AsyncResource instance.
*/
triggerAsyncId(): number;
}
}

0 comments on commit 0cec958

Please sign in to comment.