Skip to content

Conversation

@Semigradsky
Copy link
Contributor

@Semigradsky Semigradsky commented Oct 21, 2020

https://github.com/nodejs/node/releases/tag/v15.0.0

  • QUIC: Node.js 15 comes with experimental support QUIC - WIP
  • assert: add assert/strict alias module
  • dns: add dns/promises alias
  • lib: add EventTarget-related browser globals
  • lib: initial experimental AbortController implementation
  • crypto: refactoring internals, add WebCrypto
  • fs: deprecation warning on recursive rmdir
  • net: remove long deprecated server.connections property
  • stream: add promises version to utility functions
  • timers: introduce timers/promises
  • util: change default value of maxStringLength to 10000
  • crypto: add getCipherInfo method
  • events: allow use of AbortController with on
  • events: allow use of AbortController with once
  • http2: add support for sensitive headers
  • net: add support for resolving DNS CAA records
  • net: introduce net.BlockList
  • timers: allow promisified timeouts/immediates to be canceled

WIP

@typescript-bot
Copy link
Contributor

👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings.

Let’s review the numbers, shall we?

Comparison details 📊
master #48981 diff
Batch compilation
Memory usage (MiB) 109.8 109.3 -0.5%
Type count 17627 17661 0%
Assignability cache size 5047 5047 0%
Language service
Samples taken 28 28 0%
Identifiers in tests 28 28 0%
getCompletionsAtPosition
    Mean duration (ms) 690.2 708.7 +2.7%
    Mean CV 10.3% 11.4%
    Worst duration (ms) 752.8 831.0 +10.4%
    Worst identifier instance instance
getQuickInfoAtPosition
    Mean duration (ms) 679.1 706.8 +4.1%
    Mean CV 9.0% 10.6% +16.8%
    Worst duration (ms) 726.1 806.6 +11.1%
    Worst identifier process instance

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added the Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. label Oct 21, 2020
@justablob
Copy link

justablob commented Oct 21, 2020

I noticed crypto.hkdf and crypto.hkdfSync are missing, I can write typings for them and create a separate PR so it's less work for you.

Edit: Done.

@Semigradsky
Copy link
Contributor Author

I noticed crypto.hkdf and crypto.hkdfSync are missing, I can write typings for them and create a separate PR so it's less work for you.

Thanks! I have added this to PR.

This PR is not ready, it is in progress state. I created it for collect advices and fix mistakes early.

There are many types which should be defined (Crypto, AbortSignal, Event, EventTarget, ...), you can take some if you want to help.

@victorperin
Copy link
Contributor

victorperin commented Oct 24, 2020

Hey @Semigradsky can you change the description to a checklist with the features you already implemented and what needs to be finished? So I can implement what is missing. :)

@Semigradsky
Copy link
Contributor Author

@victorperin hi! I will update description later. You can take types/node/crypto.webcrypto.d.ts

setServers: typeof setServers;
}
}
const promises: typeof dnsPromises;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const promises: typeof dnsPromises;
export { dnsPromises as promises };

unref(): void;
}

const promises: typeof streamPromises;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const promises: typeof streamPromises;
export { streamPromises as promises };

Comment on lines 61 to 216
interface EventInit {
bubbles?: boolean;
cancelable?: boolean;
composed?: boolean;
}

/**
* The `Event` object is an adaptation of the `Event Web API`.
* Instances are created internally by Node.js.
*/
class Event {
constructor(type: string, eventInitDict?: EventInit);
/**
* Always returns `false`.
*
* This is not used in Node.js and is provided purely for completeness.
*/
readonly bubbles: boolean;
/**
* Alias for `event.stopPropagation()`.
*
* This is not used in Node.js and is provided purely for completeness.
*/
cancelBubble(): void;
/**
* True if the event was created with the `cancelable` option.
*/
readonly cancelable: boolean;
/**
* Always returns `false`.
*
* This is not used in Node.js and is provided purely for completeness.
*/
readonly composed: boolean;
/**
* Returns an array containing the current `EventTarget` as the only entry
* or empty if the event is not being dispatched.
*
* This is not used in Node.js and is provided purely for completeness.
*/
composedPath(): EventTarget[];
/**
* The `EventTarget` dispatching the event.
*
* Alias for `event.target`.
*/
readonly currentTarget: EventTarget | null;
/**
* Is true if `cancelable` is true and `event.preventDefault()` has been called.
*/
readonly defaultPrevented: boolean;
/**
* Returns `0` while an event is not being dispatched, `2` while it is being dispatched.
*
* This is not used in Node.js and is provided purely for completeness.
*/
readonly eventPhase: number;
/**
* Always returns `false`.
*
* This is not used in Node.js and is provided purely for completeness.
*/
readonly isTrusted: boolean;
/**
* Sets the `defaultPrevented` property to `true` if `cancelable` is `true`.
*/
preventDefault(): void;
/**
* True if the event has not been canceled.
*
* This is not used in Node.js and is provided purely for completeness.
*/
returnValue: boolean;
/**
* The `EventTarget` dispatching the event.
*
* Alias for `event.target`.
*/
readonly srcElement: EventTarget;
/**
* Stops the invocation of event listeners after the current one completes.
*/
stopImmediatePropagation(): void;
/**
* This is not used in Node.js and is provided purely for completeness.
*/
stopPropagation(): void;
/**
* The `EventTarget` dispatching the event.
*/
readonly target: EventTarget;
/**
* The millisecond timestamp when the `Event` object was created.
*/
readonly timeStamp: number;
/**
* The event type identifier.
*/
readonly type: string;

static readonly NONE: 0;
static readonly CAPTURING_PHASE: 1;
static readonly AT_TARGET: 2;
static readonly BUBBLING_PHASE: 3;
}

interface EventLike {
type: string;
}

interface EventListenerOptions {
/**
* Not directly used by Node.js. Added for API completeness.
*/
capture?: boolean;
}

interface AddEventListenerOptions extends EventListenerOptions {
/**
* When `true`, the listener is automatically removed when it is first invoked
*/
once?: boolean;
/**
* When `true`, serves as a hint that the listener will not call
* the `Event object's `preventDefault()` method.
*/
passive?: boolean;
}

type EventListener = ((event: Event) => void) | { handleEvent(event: Event): void; };

class EventTarget {
constructor();
/**
* Adds a new handler for the `type` event. Any given `listener` is added
* only once per `type` and per `capture` option value.
*
* If the `once` option is `true`, the `listener` is removed after the next time a `type` event is dispatched.
*
* The `capture` option is not used by Node.js in any functional way other than
* tracking registered event listeners per the `EventTarget` specification.
* Specifically, the `capture` option is used as part of the key when registering a `listener`.
* Any individual `listener` may be added once with `capture = false`, and once with `capture = true`.
*/
addEventListener(type: string, listener: EventListener, options?: boolean | AddEventListenerOptions): void;
/**
* Dispatches the `event` to the list of handlers for `event.type`.
*
* The registered event listeners is synchronously invoked in the order they were registered.
*/
dispatchEvent(event: Event | EventLike): boolean;
/**
* Removes the `listener` from the list of handlers for event `type`.
*/
removeEventListener(type: string, callback: EventListener, options?: EventListenerOptions | boolean): void;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These need to be moved to the top‑level of global, since otherwise they won’t be accessible through the identifiers or globalThis, and the NodeJS namespace doesn’t exist at runtime.

Comment on lines 472 to 501
/**
* A utility class used to signal cancelation in selected `Promise`-based APIs.
* The API is based on the Web API `AbortController`.
*/
class AbortController {
/**
* Returns the AbortSignal object associated with this object.
*/
readonly signal: AbortSignal;
/**
* Triggers the abort signal, causing the `abortController.signal` to emit the `'abort'` event.
*/
abort(): void;
}

/**
* The `AbortSignal` is used to notify observers when
* the `abortController.abort()` method is called.
*/
class AbortSignal extends EventTarget {
/**
* True after the `AbortController` has been aborted.
*/
readonly aborted: boolean;
/**
* An optional callback function that may be set by user code
* to be notified when the `abortController.abort()` function has been called.
*/
onabort: ((event: Event) => void) | null;
}
Copy link
Contributor

@ExE-Boss ExE-Boss Oct 25, 2020

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@Semigradsky Semigradsky Oct 25, 2020

Choose a reason for hiding this comment

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

In this case I have errors:

Duplicate identifier 'AbortController'.ts(2300)
lib.dom.d.ts(1931, 11): 'AbortController' was also declared here.
lib.dom.d.ts(1942, 13): and here.

Any ideas how to fix this?

The same with MessageEvent and others

Comment on lines 241 to 259
/** A message received by a target object. */
class MessageEvent<T = any> extends Event {
/**
* Returns the data of the message.
*/
readonly data: T;
/**
* Returns the last event ID string, for server-sent events.
*/
readonly lastEventId: string;
/**
* Returns the origin of the message, for server-sent events and cross-document messaging.
*/
readonly origin: string;
/**
* Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging.
*/
readonly ports: ReadonlyArray<MessagePort>;
}
Copy link
Contributor

@ExE-Boss ExE-Boss Oct 25, 2020

Choose a reason for hiding this comment

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

Comment on lines 1 to 10
declare module "crypto" {
// TODO: Define `Crypto`
type Crypto = any;

const webCrypto: Crypto;
}
Copy link
Contributor

@panva panva Oct 29, 2020

Choose a reason for hiding this comment

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

Suggested change
declare module "crypto" {
// TODO: Define `Crypto`
type Crypto = any;
const webCrypto: Crypto;
}
interface NodeCrypto extends Crypto {
readonly CryptoKey: typeof CryptoKey
}
declare module 'crypto' {
const webcrypto: NodeCrypto
}

Crypto is already defined in TS's lib.dom.d.ts. This just adds the "webcrypto" (you mistyped the property name, capitalizing the C) property as a crypto export and also adds the CryptoKey class instance.

Note: i'm not taking the node.js specific extensions into account here.


{
(async () => {
const key = await crypto.webCrypto.subtle.generateKey({
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const key = await crypto.webCrypto.subtle.generateKey({
const key = await crypto.webcrypto.subtle.generateKey({

- QUIC: Node.js 15 comes with experimental support QUIC - WIP
- assert: add assert/strict alias module
- dns: add dns/promises alias
- lib: add EventTarget-related browser globals
- lib: initial experimental AbortController implementation
- crypto: refactoring internals, add WebCrypto
- fs: deprecation warning on recursive rmdir
- net: remove long deprecated server.connections property
- stream: add promises version to utility functions
- timers: introduce timers/promises
- util: change default value of maxStringLength to 10000
- crypto: add getCipherInfo method
- events: allow use of AbortController with on
- events: allow use of AbortController with once
- http2: add support for sensitive headers
- net: add support for resolving DNS CAA records
- net: introduce net.BlockList
- timers: allow promisified timeouts/immediates to be canceled

WIP
@ExE-Boss ExE-Boss mentioned this pull request Nov 12, 2020
4 tasks
@ZYSzys
Copy link
Contributor

ZYSzys commented Dec 25, 2020

@Semigradsky Hi, what's the status of this PR, would you like continue doing this so that we can move forward ?

@Semigradsky
Copy link
Contributor Author

@ZYSzys feel free to use my changes in your PR 👍

@Semigradsky
Copy link
Contributor Author

Closed in favor of #52357

@Semigradsky Semigradsky deleted the node-15.0.0 branch April 23, 2021 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants