@types/node 24.2.1 → 24.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
node/test.d.ts CHANGED
@@ -1707,6 +1707,46 @@ declare module "node:test" {
1707
1707
  * @param options Optional configuration options for the mock module.
1708
1708
  */
1709
1709
  module(specifier: string, options?: MockModuleOptions): MockModuleContext;
1710
+ /**
1711
+ * Creates a mock for a property value on an object. This allows you to track and control access to a specific property,
1712
+ * including how many times it is read (getter) or written (setter), and to restore the original value after mocking.
1713
+ *
1714
+ * ```js
1715
+ * test('mocks a property value', (t) => {
1716
+ * const obj = { foo: 42 };
1717
+ * const prop = t.mock.property(obj, 'foo', 100);
1718
+ *
1719
+ * assert.strictEqual(obj.foo, 100);
1720
+ * assert.strictEqual(prop.mock.accessCount(), 1);
1721
+ * assert.strictEqual(prop.mock.accesses[0].type, 'get');
1722
+ * assert.strictEqual(prop.mock.accesses[0].value, 100);
1723
+ *
1724
+ * obj.foo = 200;
1725
+ * assert.strictEqual(prop.mock.accessCount(), 2);
1726
+ * assert.strictEqual(prop.mock.accesses[1].type, 'set');
1727
+ * assert.strictEqual(prop.mock.accesses[1].value, 200);
1728
+ *
1729
+ * prop.mock.restore();
1730
+ * assert.strictEqual(obj.foo, 42);
1731
+ * });
1732
+ * ```
1733
+ * @since v24.3.0
1734
+ * @param object The object whose value is being mocked.
1735
+ * @param propertyName The identifier of the property on `object` to mock.
1736
+ * @param value An optional value used as the mock value
1737
+ * for `object[propertyName]`. **Default:** The original property value.
1738
+ * @returns A proxy to the mocked object. The mocked object contains a
1739
+ * special `mock` property, which is an instance of [`MockPropertyContext`][], and
1740
+ * can be used for inspecting and changing the behavior of the mocked property.
1741
+ */
1742
+ property<
1743
+ MockedObject extends object,
1744
+ PropertyName extends keyof MockedObject,
1745
+ >(
1746
+ object: MockedObject,
1747
+ property: PropertyName,
1748
+ value?: MockedObject[PropertyName],
1749
+ ): MockedObject & { mock: MockPropertyContext<MockedObject[PropertyName]> };
1710
1750
  /**
1711
1751
  * This function restores the default behavior of all mocks that were previously
1712
1752
  * created by this `MockTracker` and disassociates the mocks from the `MockTracker` instance. Once disassociated, the mocks can still be used, but the `MockTracker` instance can no longer be
@@ -1876,6 +1916,70 @@ declare module "node:test" {
1876
1916
  */
1877
1917
  restore(): void;
1878
1918
  }
1919
+ /**
1920
+ * @since v24.3.0
1921
+ */
1922
+ class MockPropertyContext<PropertyType = any> {
1923
+ /**
1924
+ * A getter that returns a copy of the internal array used to track accesses (get/set) to
1925
+ * the mocked property. Each entry in the array is an object with the following properties:
1926
+ */
1927
+ readonly accesses: Array<{
1928
+ type: "get" | "set";
1929
+ value: PropertyType;
1930
+ stack: Error;
1931
+ }>;
1932
+ /**
1933
+ * This function returns the number of times that the property was accessed.
1934
+ * This function is more efficient than checking `ctx.accesses.length` because
1935
+ * `ctx.accesses` is a getter that creates a copy of the internal access tracking array.
1936
+ * @returns The number of times that the property was accessed (read or written).
1937
+ */
1938
+ accessCount(): number;
1939
+ /**
1940
+ * This function is used to change the value returned by the mocked property getter.
1941
+ * @param value The new value to be set as the mocked property value.
1942
+ */
1943
+ mockImplementation(value: PropertyType): void;
1944
+ /**
1945
+ * This function is used to change the behavior of an existing mock for a single
1946
+ * invocation. Once invocation `onAccess` has occurred, the mock will revert to
1947
+ * whatever behavior it would have used had `mockImplementationOnce()` not been
1948
+ * called.
1949
+ *
1950
+ * The following example creates a mock function using `t.mock.property()`, calls the
1951
+ * mock property, changes the mock implementation to a different value for the
1952
+ * next invocation, and then resumes its previous behavior.
1953
+ *
1954
+ * ```js
1955
+ * test('changes a mock behavior once', (t) => {
1956
+ * const obj = { foo: 1 };
1957
+ *
1958
+ * const prop = t.mock.property(obj, 'foo', 5);
1959
+ *
1960
+ * assert.strictEqual(obj.foo, 5);
1961
+ * prop.mock.mockImplementationOnce(25);
1962
+ * assert.strictEqual(obj.foo, 25);
1963
+ * assert.strictEqual(obj.foo, 5);
1964
+ * });
1965
+ * ```
1966
+ * @param value The value to be used as the mock's
1967
+ * implementation for the invocation number specified by `onAccess`.
1968
+ * @param onAccess The invocation number that will use `value`. If
1969
+ * the specified invocation has already occurred then an exception is thrown.
1970
+ * **Default:** The number of the next invocation.
1971
+ */
1972
+ mockImplementationOnce(value: PropertyType, onAccess?: number): void;
1973
+ /**
1974
+ * Resets the access history of the mocked property.
1975
+ */
1976
+ resetAccesses(): void;
1977
+ /**
1978
+ * Resets the implementation of the mock property to its original behavior. The
1979
+ * mock can still be used after calling this function.
1980
+ */
1981
+ restore(): void;
1982
+ }
1879
1983
  interface MockTimersOptions {
1880
1984
  apis: ReadonlyArray<"setInterval" | "setTimeout" | "setImmediate" | "Date">;
1881
1985
  now?: number | Date | undefined;
node/ts5.6/index.d.ts CHANGED
@@ -40,6 +40,12 @@
40
40
 
41
41
  // Definitions for Node.js modules that are not specific to any version of TypeScript:
42
42
  /// <reference path="../globals.d.ts" />
43
+ /// <reference path="../web-globals/abortcontroller.d.ts" />
44
+ /// <reference path="../web-globals/domexception.d.ts" />
45
+ /// <reference path="../web-globals/events.d.ts" />
46
+ /// <reference path="../web-globals/fetch.d.ts" />
47
+ /// <reference path="../web-globals/navigator.d.ts" />
48
+ /// <reference path="../web-globals/storage.d.ts" />
43
49
  /// <reference path="../assert.d.ts" />
44
50
  /// <reference path="../assert/strict.d.ts" />
45
51
  /// <reference path="../async_hooks.d.ts" />
@@ -55,7 +61,6 @@
55
61
  /// <reference path="../dns/promises.d.ts" />
56
62
  /// <reference path="../dns/promises.d.ts" />
57
63
  /// <reference path="../domain.d.ts" />
58
- /// <reference path="../dom-events.d.ts" />
59
64
  /// <reference path="../events.d.ts" />
60
65
  /// <reference path="../fs.d.ts" />
61
66
  /// <reference path="../fs/promises.d.ts" />
node/ts5.7/index.d.ts CHANGED
@@ -40,6 +40,12 @@
40
40
 
41
41
  // Definitions for Node.js modules that are not specific to any version of TypeScript:
42
42
  /// <reference path="../globals.d.ts" />
43
+ /// <reference path="../web-globals/abortcontroller.d.ts" />
44
+ /// <reference path="../web-globals/domexception.d.ts" />
45
+ /// <reference path="../web-globals/events.d.ts" />
46
+ /// <reference path="../web-globals/fetch.d.ts" />
47
+ /// <reference path="../web-globals/navigator.d.ts" />
48
+ /// <reference path="../web-globals/storage.d.ts" />
43
49
  /// <reference path="../assert.d.ts" />
44
50
  /// <reference path="../assert/strict.d.ts" />
45
51
  /// <reference path="../async_hooks.d.ts" />
@@ -55,7 +61,6 @@
55
61
  /// <reference path="../dns/promises.d.ts" />
56
62
  /// <reference path="../dns/promises.d.ts" />
57
63
  /// <reference path="../domain.d.ts" />
58
- /// <reference path="../dom-events.d.ts" />
59
64
  /// <reference path="../events.d.ts" />
60
65
  /// <reference path="../fs.d.ts" />
61
66
  /// <reference path="../fs/promises.d.ts" />
node/url.d.ts CHANGED
@@ -315,6 +315,17 @@ declare module "url" {
315
315
  * @return The fully-resolved platform-specific Node.js file path.
316
316
  */
317
317
  function fileURLToPath(url: string | URL, options?: FileUrlToPathOptions): string;
318
+ /**
319
+ * Like `url.fileURLToPath(...)` except that instead of returning a string
320
+ * representation of the path, a `Buffer` is returned. This conversion is
321
+ * helpful when the input URL contains percent-encoded segments that are
322
+ * not valid UTF-8 / Unicode sequences.
323
+ * @since v24.3.0
324
+ * @param url The file URL string or URL object to convert to a path.
325
+ * @returns The fully-resolved platform-specific Node.js file path
326
+ * as a `Buffer`.
327
+ */
328
+ function fileURLToPathBuffer(url: string | URL, options?: FileUrlToPathOptions): Buffer;
318
329
  /**
319
330
  * This function ensures that `path` is resolved absolutely, and that the URL
320
331
  * control characters are correctly encoded when converting into a File URL.
@@ -0,0 +1,34 @@
1
+ export {};
2
+
3
+ type _AbortController = typeof globalThis extends { onmessage: any } ? {} : AbortController;
4
+ interface AbortController {
5
+ readonly signal: AbortSignal;
6
+ abort(reason?: any): void;
7
+ }
8
+
9
+ type _AbortSignal = typeof globalThis extends { onmessage: any } ? {} : AbortSignal;
10
+ interface AbortSignal extends EventTarget {
11
+ readonly aborted: boolean;
12
+ onabort: ((this: AbortSignal, ev: Event) => any) | null;
13
+ readonly reason: any;
14
+ throwIfAborted(): void;
15
+ }
16
+
17
+ declare global {
18
+ interface AbortController extends _AbortController {}
19
+ var AbortController: typeof globalThis extends { onmessage: any; AbortController: infer T } ? T
20
+ : {
21
+ prototype: AbortController;
22
+ new(): AbortController;
23
+ };
24
+
25
+ interface AbortSignal extends _AbortSignal {}
26
+ var AbortSignal: typeof globalThis extends { onmessage: any; AbortSignal: infer T } ? T
27
+ : {
28
+ prototype: AbortSignal;
29
+ new(): AbortSignal;
30
+ abort(reason?: any): AbortSignal;
31
+ any(signals: AbortSignal[]): AbortSignal;
32
+ timeout(milliseconds: number): AbortSignal;
33
+ };
34
+ }
@@ -0,0 +1,68 @@
1
+ export {};
2
+
3
+ type _DOMException = typeof globalThis extends { onmessage: any } ? {} : DOMException;
4
+ interface DOMException extends Error {
5
+ readonly code: number;
6
+ readonly message: string;
7
+ readonly name: string;
8
+ readonly INDEX_SIZE_ERR: 1;
9
+ readonly DOMSTRING_SIZE_ERR: 2;
10
+ readonly HIERARCHY_REQUEST_ERR: 3;
11
+ readonly WRONG_DOCUMENT_ERR: 4;
12
+ readonly INVALID_CHARACTER_ERR: 5;
13
+ readonly NO_DATA_ALLOWED_ERR: 6;
14
+ readonly NO_MODIFICATION_ALLOWED_ERR: 7;
15
+ readonly NOT_FOUND_ERR: 8;
16
+ readonly NOT_SUPPORTED_ERR: 9;
17
+ readonly INUSE_ATTRIBUTE_ERR: 10;
18
+ readonly INVALID_STATE_ERR: 11;
19
+ readonly SYNTAX_ERR: 12;
20
+ readonly INVALID_MODIFICATION_ERR: 13;
21
+ readonly NAMESPACE_ERR: 14;
22
+ readonly INVALID_ACCESS_ERR: 15;
23
+ readonly VALIDATION_ERR: 16;
24
+ readonly TYPE_MISMATCH_ERR: 17;
25
+ readonly SECURITY_ERR: 18;
26
+ readonly NETWORK_ERR: 19;
27
+ readonly ABORT_ERR: 20;
28
+ readonly URL_MISMATCH_ERR: 21;
29
+ readonly QUOTA_EXCEEDED_ERR: 22;
30
+ readonly TIMEOUT_ERR: 23;
31
+ readonly INVALID_NODE_TYPE_ERR: 24;
32
+ readonly DATA_CLONE_ERR: 25;
33
+ }
34
+
35
+ declare global {
36
+ interface DOMException extends _DOMException {}
37
+ var DOMException: typeof globalThis extends { onmessage: any; DOMException: infer T } ? T
38
+ : {
39
+ prototype: DOMException;
40
+ new(message?: string, name?: string): DOMException;
41
+ new(message?: string, options?: { name?: string; cause?: unknown }): DOMException;
42
+ readonly INDEX_SIZE_ERR: 1;
43
+ readonly DOMSTRING_SIZE_ERR: 2;
44
+ readonly HIERARCHY_REQUEST_ERR: 3;
45
+ readonly WRONG_DOCUMENT_ERR: 4;
46
+ readonly INVALID_CHARACTER_ERR: 5;
47
+ readonly NO_DATA_ALLOWED_ERR: 6;
48
+ readonly NO_MODIFICATION_ALLOWED_ERR: 7;
49
+ readonly NOT_FOUND_ERR: 8;
50
+ readonly NOT_SUPPORTED_ERR: 9;
51
+ readonly INUSE_ATTRIBUTE_ERR: 10;
52
+ readonly INVALID_STATE_ERR: 11;
53
+ readonly SYNTAX_ERR: 12;
54
+ readonly INVALID_MODIFICATION_ERR: 13;
55
+ readonly NAMESPACE_ERR: 14;
56
+ readonly INVALID_ACCESS_ERR: 15;
57
+ readonly VALIDATION_ERR: 16;
58
+ readonly TYPE_MISMATCH_ERR: 17;
59
+ readonly SECURITY_ERR: 18;
60
+ readonly NETWORK_ERR: 19;
61
+ readonly ABORT_ERR: 20;
62
+ readonly URL_MISMATCH_ERR: 21;
63
+ readonly QUOTA_EXCEEDED_ERR: 22;
64
+ readonly TIMEOUT_ERR: 23;
65
+ readonly INVALID_NODE_TYPE_ERR: 24;
66
+ readonly DATA_CLONE_ERR: 25;
67
+ };
68
+ }
@@ -1,37 +1,61 @@
1
- // Make this a module
2
1
  export {};
3
2
 
4
- // Conditional type aliases, which are later merged into the global scope.
5
- // Will either be empty if the relevant web library is already present, or the @types/node definition otherwise.
3
+ interface AddEventListenerOptions extends EventListenerOptions {
4
+ once?: boolean;
5
+ passive?: boolean;
6
+ signal?: AbortSignal;
7
+ }
6
8
 
7
- type __Event = typeof globalThis extends { onmessage: any } ? {} : Event;
9
+ type _CustomEvent<T = any> = typeof globalThis extends { onmessage: any } ? {} : CustomEvent<T>;
10
+ interface CustomEvent<T = any> extends Event {
11
+ readonly detail: T;
12
+ }
13
+
14
+ interface CustomEventInit<T = any> extends EventInit {
15
+ detail?: T;
16
+ }
17
+
18
+ type _Event = typeof globalThis extends { onmessage: any } ? {} : Event;
8
19
  interface Event {
9
20
  readonly bubbles: boolean;
10
21
  cancelBubble: boolean;
11
22
  readonly cancelable: boolean;
12
23
  readonly composed: boolean;
13
- composedPath(): [EventTarget?];
14
24
  readonly currentTarget: EventTarget | null;
15
25
  readonly defaultPrevented: boolean;
16
26
  readonly eventPhase: 0 | 2;
17
- initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
18
27
  readonly isTrusted: boolean;
19
- preventDefault(): void;
20
- readonly returnValue: boolean;
28
+ returnValue: boolean;
21
29
  readonly srcElement: EventTarget | null;
22
- stopImmediatePropagation(): void;
23
- stopPropagation(): void;
24
30
  readonly target: EventTarget | null;
25
31
  readonly timeStamp: number;
26
32
  readonly type: string;
33
+ composedPath(): [EventTarget?];
34
+ initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
35
+ preventDefault(): void;
36
+ stopImmediatePropagation(): void;
37
+ stopPropagation(): void;
27
38
  }
28
39
 
29
- type __CustomEvent<T = any> = typeof globalThis extends { onmessage: any } ? {} : CustomEvent<T>;
30
- interface CustomEvent<T = any> extends Event {
31
- readonly detail: T;
40
+ interface EventInit {
41
+ bubbles?: boolean;
42
+ cancelable?: boolean;
43
+ composed?: boolean;
44
+ }
45
+
46
+ interface EventListener {
47
+ (evt: Event): void;
48
+ }
49
+
50
+ interface EventListenerObject {
51
+ handleEvent(object: Event): void;
52
+ }
53
+
54
+ interface EventListenerOptions {
55
+ capture?: boolean;
32
56
  }
33
57
 
34
- type __EventTarget = typeof globalThis extends { onmessage: any } ? {} : EventTarget;
58
+ type _EventTarget = typeof globalThis extends { onmessage: any } ? {} : EventTarget;
35
59
  interface EventTarget {
36
60
  addEventListener(
37
61
  type: string,
@@ -46,51 +70,22 @@ interface EventTarget {
46
70
  ): void;
47
71
  }
48
72
 
49
- interface EventInit {
50
- bubbles?: boolean;
51
- cancelable?: boolean;
52
- composed?: boolean;
53
- }
54
-
55
- interface CustomEventInit<T = any> extends EventInit {
56
- detail?: T;
57
- }
58
-
59
- interface EventListenerOptions {
60
- capture?: boolean;
61
- }
62
-
63
- interface AddEventListenerOptions extends EventListenerOptions {
64
- once?: boolean;
65
- passive?: boolean;
66
- signal?: AbortSignal;
67
- }
68
-
69
- interface EventListener {
70
- (evt: Event): void;
71
- }
72
-
73
- interface EventListenerObject {
74
- handleEvent(object: Event): void;
75
- }
76
-
77
- // Merge conditional interfaces into global scope, and conditionally declare global constructors.
78
73
  declare global {
79
- interface Event extends __Event {}
80
- var Event: typeof globalThis extends { onmessage: any; Event: infer T } ? T
81
- : {
82
- prototype: Event;
83
- new(type: string, eventInitDict?: EventInit): Event;
84
- };
85
-
86
- interface CustomEvent<T = any> extends __CustomEvent<T> {}
74
+ interface CustomEvent<T = any> extends _CustomEvent<T> {}
87
75
  var CustomEvent: typeof globalThis extends { onmessage: any; CustomEvent: infer T } ? T
88
76
  : {
89
77
  prototype: CustomEvent;
90
78
  new<T>(type: string, eventInitDict?: CustomEventInit<T>): CustomEvent<T>;
91
79
  };
92
80
 
93
- interface EventTarget extends __EventTarget {}
81
+ interface Event extends _Event {}
82
+ var Event: typeof globalThis extends { onmessage: any; Event: infer T } ? T
83
+ : {
84
+ prototype: Event;
85
+ new(type: string, eventInitDict?: EventInit): Event;
86
+ };
87
+
88
+ interface EventTarget extends _EventTarget {}
94
89
  var EventTarget: typeof globalThis extends { onmessage: any; EventTarget: infer T } ? T
95
90
  : {
96
91
  prototype: EventTarget;
@@ -0,0 +1,50 @@
1
+ export {};
2
+
3
+ import * as undici from "undici-types";
4
+
5
+ type _CloseEvent = typeof globalThis extends { onmessage: any } ? {} : undici.CloseEvent;
6
+ type _EventSource = typeof globalThis extends { onmessage: any } ? {} : undici.EventSource;
7
+ type _FormData = typeof globalThis extends { onmessage: any } ? {} : undici.FormData;
8
+ type _Headers = typeof globalThis extends { onmessage: any } ? {} : undici.Headers;
9
+ type _MessageEvent = typeof globalThis extends { onmessage: any } ? {} : undici.MessageEvent;
10
+ type _Request = typeof globalThis extends { onmessage: any } ? {} : undici.Request;
11
+ type _RequestInit = typeof globalThis extends { onmessage: any } ? {} : undici.RequestInit;
12
+ type _Response = typeof globalThis extends { onmessage: any } ? {} : undici.Response;
13
+ type _ResponseInit = typeof globalThis extends { onmessage: any } ? {} : undici.ResponseInit;
14
+ type _WebSocket = typeof globalThis extends { onmessage: any } ? {} : undici.WebSocket;
15
+
16
+ declare global {
17
+ function fetch(
18
+ input: string | URL | Request,
19
+ init?: RequestInit,
20
+ ): Promise<Response>;
21
+
22
+ interface CloseEvent extends _CloseEvent {}
23
+ var CloseEvent: typeof globalThis extends { onmessage: any; CloseEvent: infer T } ? T : typeof undici.CloseEvent;
24
+
25
+ interface EventSource extends _EventSource {}
26
+ var EventSource: typeof globalThis extends { onmessage: any; EventSource: infer T } ? T : typeof undici.EventSource;
27
+
28
+ interface FormData extends _FormData {}
29
+ var FormData: typeof globalThis extends { onmessage: any; FormData: infer T } ? T : typeof undici.FormData;
30
+
31
+ interface Headers extends _Headers {}
32
+ var Headers: typeof globalThis extends { onmessage: any; Headers: infer T } ? T : typeof undici.Headers;
33
+
34
+ interface MessageEvent extends _MessageEvent {}
35
+ var MessageEvent: typeof globalThis extends { onmessage: any; MessageEvent: infer T } ? T
36
+ : typeof undici.MessageEvent;
37
+
38
+ interface Request extends _Request {}
39
+ var Request: typeof globalThis extends { onmessage: any; Request: infer T } ? T : typeof undici.Request;
40
+
41
+ interface RequestInit extends _RequestInit {}
42
+
43
+ interface Response extends _Response {}
44
+ var Response: typeof globalThis extends { onmessage: any; Response: infer T } ? T : typeof undici.Response;
45
+
46
+ interface ResponseInit extends _ResponseInit {}
47
+
48
+ interface WebSocket extends _WebSocket {}
49
+ var WebSocket: typeof globalThis extends { onmessage: any; WebSocket: infer T } ? T : typeof undici.WebSocket;
50
+ }
@@ -0,0 +1,22 @@
1
+ export {};
2
+
3
+ // lib.webworker has `WorkerNavigator` rather than `Navigator`, so conditionals use `onabort` instead of `onmessage`
4
+ type _Navigator = typeof globalThis extends { onabort: any } ? {} : Navigator;
5
+ interface Navigator {
6
+ readonly hardwareConcurrency: number;
7
+ readonly language: string;
8
+ readonly languages: readonly string[];
9
+ readonly platform: string;
10
+ readonly userAgent: string;
11
+ }
12
+
13
+ declare global {
14
+ interface Navigator extends _Navigator {}
15
+ var Navigator: typeof globalThis extends { onabort: any; Navigator: infer T } ? T : {
16
+ prototype: Navigator;
17
+ new(): Navigator;
18
+ };
19
+
20
+ // Needs conditional inference for lib.dom and lib.webworker compatibility
21
+ var navigator: typeof globalThis extends { onmessage: any; navigator: infer T } ? T : Navigator;
22
+ }
@@ -0,0 +1,24 @@
1
+ export {};
2
+
3
+ // These interfaces are absent from lib.webworker, so the conditionals use `onabort` rather than `onmessage`
4
+ type _Storage = typeof globalThis extends { onabort: any } ? {} : Storage;
5
+ interface Storage {
6
+ readonly length: number;
7
+ clear(): void;
8
+ getItem(key: string): string | null;
9
+ key(index: number): string | null;
10
+ removeItem(key: string): void;
11
+ setItem(key: string, value: string): void;
12
+ [key: string]: any;
13
+ }
14
+
15
+ declare global {
16
+ interface Storage extends _Storage {}
17
+ var Storage: typeof globalThis extends { onabort: any; Storage: infer T } ? T : {
18
+ prototype: Storage;
19
+ new(): Storage;
20
+ };
21
+
22
+ var localStorage: Storage;
23
+ var sessionStorage: Storage;
24
+ }