Skip to content

Commit 610b2de

Browse files
🤖 Merge PR DefinitelyTyped#73445 node: v22.18 by @Renegade334
Co-authored-by: Felipe Santos <[email protected]>
1 parent e4a0720 commit 610b2de

File tree

16 files changed

+218
-83
lines changed

16 files changed

+218
-83
lines changed

types/node/v22/buffer.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ declare module "buffer" {
139139
type?: string | undefined;
140140
}
141141
/**
142-
* A [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) encapsulates immutable, raw data that can be safely shared across
142+
* A `Blob` encapsulates immutable, raw data that can be safely shared across
143143
* multiple worker threads.
144144
* @since v15.7.0, v14.18.0
145145
*/

types/node/v22/child_process.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* the parent Node.js process and the spawned subprocess. These pipes have
2525
* limited (and platform-specific) capacity. If the subprocess writes to
2626
* stdout in excess of that limit without the output being captured, the
27-
* subprocess blocks waiting for the pipe buffer to accept more data. This is
27+
* subprocess blocks, waiting for the pipe buffer to accept more data. This is
2828
* identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }` option if the output will not be consumed.
2929
*
3030
* The command lookup is performed using the `options.env.PATH` environment

types/node/v22/fs.d.ts

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,15 @@ declare module "fs" {
329329
*/
330330
readSync(): Dirent | null;
331331
/**
332-
* Calls `dir.close()` and returns a promise that fulfills when the
333-
* dir is closed.
332+
* Calls `dir.close()` if the directory handle is open, and returns a promise that
333+
* fulfills when disposal is complete.
334334
* @since v22.17.0
335335
* @experimental
336336
*/
337337
[Symbol.asyncDispose](): Promise<void>;
338338
/**
339-
* Calls `dir.closeSync()` and returns `undefined`.
339+
* Calls `dir.closeSync()` if the directory handle is open, and returns
340+
* `undefined`.
340341
* @since v22.17.0
341342
* @experimental
342343
*/
@@ -3340,6 +3341,12 @@ declare module "fs" {
33403341
persistent?: boolean | undefined;
33413342
recursive?: boolean | undefined;
33423343
}
3344+
export interface WatchOptionsWithBufferEncoding extends WatchOptions {
3345+
encoding: "buffer";
3346+
}
3347+
export interface WatchOptionsWithStringEncoding extends WatchOptions {
3348+
encoding?: BufferEncoding | undefined;
3349+
}
33433350
export type WatchEventType = "rename" | "change";
33443351
export type WatchListener<T> = (event: WatchEventType, filename: T | null) => void;
33453352
export type StatsListener = (curr: Stats, prev: Stats) => void;
@@ -3366,44 +3373,20 @@ declare module "fs" {
33663373
*/
33673374
export function watch(
33683375
filename: PathLike,
3369-
options:
3370-
| (WatchOptions & {
3371-
encoding: "buffer";
3372-
})
3373-
| "buffer",
3374-
listener?: WatchListener<Buffer>,
3376+
options?: WatchOptionsWithStringEncoding | BufferEncoding | null,
3377+
listener?: WatchListener<string>,
33753378
): FSWatcher;
3376-
/**
3377-
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
3378-
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3379-
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
3380-
* If `encoding` is not supplied, the default of `'utf8'` is used.
3381-
* If `persistent` is not supplied, the default of `true` is used.
3382-
* If `recursive` is not supplied, the default of `false` is used.
3383-
*/
33843379
export function watch(
33853380
filename: PathLike,
3386-
options?: WatchOptions | BufferEncoding | null,
3387-
listener?: WatchListener<string>,
3381+
options: WatchOptionsWithBufferEncoding | "buffer",
3382+
listener: WatchListener<Buffer>,
33883383
): FSWatcher;
3389-
/**
3390-
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
3391-
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3392-
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
3393-
* If `encoding` is not supplied, the default of `'utf8'` is used.
3394-
* If `persistent` is not supplied, the default of `true` is used.
3395-
* If `recursive` is not supplied, the default of `false` is used.
3396-
*/
33973384
export function watch(
33983385
filename: PathLike,
3399-
options: WatchOptions | string,
3400-
listener?: WatchListener<string | Buffer>,
3386+
options: WatchOptions | BufferEncoding | "buffer" | null,
3387+
listener: WatchListener<string | Buffer>,
34013388
): FSWatcher;
3402-
/**
3403-
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
3404-
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
3405-
*/
3406-
export function watch(filename: PathLike, listener?: WatchListener<string>): FSWatcher;
3389+
export function watch(filename: PathLike, listener: WatchListener<string>): FSWatcher;
34073390
/**
34083391
* Test whether or not the given path exists by checking with the file system.
34093392
* Then call the `callback` argument with either true or false:

types/node/v22/fs/promises.d.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ declare module "fs/promises" {
4040
StatsFs,
4141
TimeLike,
4242
WatchEventType,
43-
WatchOptions,
43+
WatchOptions as _WatchOptions,
4444
WriteStream,
4545
WriteVResult,
4646
} from "node:fs";
@@ -1182,6 +1182,16 @@ declare module "fs/promises" {
11821182
* @return Fulfills with an {fs.Dir}.
11831183
*/
11841184
function opendir(path: PathLike, options?: OpenDirOptions): Promise<Dir>;
1185+
interface WatchOptions extends _WatchOptions {
1186+
maxQueue?: number | undefined;
1187+
overflow?: "ignore" | "throw" | undefined;
1188+
}
1189+
interface WatchOptionsWithBufferEncoding extends WatchOptions {
1190+
encoding: "buffer";
1191+
}
1192+
interface WatchOptionsWithStringEncoding extends WatchOptions {
1193+
encoding?: BufferEncoding | undefined;
1194+
}
11851195
/**
11861196
* Returns an async iterator that watches for changes on `filename`, where `filename`is either a file or a directory.
11871197
*
@@ -1214,33 +1224,16 @@ declare module "fs/promises" {
12141224
*/
12151225
function watch(
12161226
filename: PathLike,
1217-
options:
1218-
| (WatchOptions & {
1219-
encoding: "buffer";
1220-
})
1221-
| "buffer",
1222-
): AsyncIterable<FileChangeInfo<Buffer>>;
1223-
/**
1224-
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1225-
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1226-
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1227-
* If `encoding` is not supplied, the default of `'utf8'` is used.
1228-
* If `persistent` is not supplied, the default of `true` is used.
1229-
* If `recursive` is not supplied, the default of `false` is used.
1230-
*/
1231-
function watch(filename: PathLike, options?: WatchOptions | BufferEncoding): AsyncIterable<FileChangeInfo<string>>;
1232-
/**
1233-
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
1234-
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
1235-
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
1236-
* If `encoding` is not supplied, the default of `'utf8'` is used.
1237-
* If `persistent` is not supplied, the default of `true` is used.
1238-
* If `recursive` is not supplied, the default of `false` is used.
1239-
*/
1227+
options?: WatchOptionsWithStringEncoding | BufferEncoding,
1228+
): NodeJS.AsyncIterator<FileChangeInfo<string>>;
1229+
function watch(
1230+
filename: PathLike,
1231+
options: WatchOptionsWithBufferEncoding | "buffer",
1232+
): NodeJS.AsyncIterator<FileChangeInfo<Buffer>>;
12401233
function watch(
12411234
filename: PathLike,
1242-
options: WatchOptions | string,
1243-
): AsyncIterable<FileChangeInfo<string>> | AsyncIterable<FileChangeInfo<Buffer>>;
1235+
options: WatchOptions | BufferEncoding | "buffer",
1236+
): NodeJS.AsyncIterator<FileChangeInfo<string | Buffer>>;
12441237
/**
12451238
* Asynchronously copies the entire directory structure from `src` to `dest`,
12461239
* including subdirectories and files.

types/node/v22/http.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ declare module "http" {
20282028
*/
20292029
const maxHeaderSize: number;
20302030
/**
2031-
* A browser-compatible implementation of [WebSocket](https://nodejs.org/docs/latest/api/http.html#websocket).
2031+
* A browser-compatible implementation of `WebSocket`.
20322032
* @since v22.5.0
20332033
*/
20342034
const WebSocket: import("undici-types").WebSocket;

types/node/v22/inspector.d.ts

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ declare module 'inspector' {
268268
/**
269269
* Embedder-specific auxiliary data.
270270
*/
271-
auxData?: {} | undefined;
271+
auxData?: object | undefined;
272272
}
273273
/**
274274
* Detailed information about exception (or error) that was thrown during script compilation or execution.
@@ -701,7 +701,7 @@ declare module 'inspector' {
701701
}
702702
interface InspectRequestedEventDataType {
703703
object: RemoteObject;
704-
hints: {};
704+
hints: object;
705705
}
706706
}
707707
namespace Debugger {
@@ -1173,7 +1173,7 @@ declare module 'inspector' {
11731173
/**
11741174
* Embedder-specific auxiliary data.
11751175
*/
1176-
executionContextAuxData?: {} | undefined;
1176+
executionContextAuxData?: object | undefined;
11771177
/**
11781178
* True, if this script is generated as a result of the live edit operation.
11791179
* @experimental
@@ -1237,7 +1237,7 @@ declare module 'inspector' {
12371237
/**
12381238
* Embedder-specific auxiliary data.
12391239
*/
1240-
executionContextAuxData?: {} | undefined;
1240+
executionContextAuxData?: object | undefined;
12411241
/**
12421242
* URL of source map associated with script (if any).
12431243
*/
@@ -1282,7 +1282,7 @@ declare module 'inspector' {
12821282
/**
12831283
* Object containing break-specific auxiliary properties.
12841284
*/
1285-
data?: {} | undefined;
1285+
data?: object | undefined;
12861286
/**
12871287
* Hit breakpoints IDs
12881288
*/
@@ -1649,7 +1649,7 @@ declare module 'inspector' {
16491649
categories: string[];
16501650
}
16511651
interface DataCollectedEventDataType {
1652-
value: Array<{}>;
1652+
value: object[];
16531653
}
16541654
}
16551655
namespace NodeWorker {
@@ -1759,6 +1759,7 @@ declare module 'inspector' {
17591759
url: string;
17601760
method: string;
17611761
headers: Headers;
1762+
hasPostData: boolean;
17621763
}
17631764
/**
17641765
* HTTP response data.
@@ -1776,17 +1777,45 @@ declare module 'inspector' {
17761777
*/
17771778
interface Headers {
17781779
}
1780+
interface GetRequestPostDataParameterType {
1781+
/**
1782+
* Identifier of the network request to get content for.
1783+
*/
1784+
requestId: RequestId;
1785+
}
1786+
interface GetResponseBodyParameterType {
1787+
/**
1788+
* Identifier of the network request to get content for.
1789+
*/
1790+
requestId: RequestId;
1791+
}
17791792
interface StreamResourceContentParameterType {
17801793
/**
17811794
* Identifier of the request to stream.
17821795
*/
17831796
requestId: RequestId;
17841797
}
1798+
interface GetRequestPostDataReturnType {
1799+
/**
1800+
* Request body string, omitting files from multipart requests
1801+
*/
1802+
postData: string;
1803+
}
1804+
interface GetResponseBodyReturnType {
1805+
/**
1806+
* Response body.
1807+
*/
1808+
body: string;
1809+
/**
1810+
* True, if content was sent as base64.
1811+
*/
1812+
base64Encoded: boolean;
1813+
}
17851814
interface StreamResourceContentReturnType {
17861815
/**
17871816
* Data that has been buffered until streaming is enabled.
17881817
*/
1789-
bufferedData: never;
1818+
bufferedData: string;
17901819
}
17911820
interface RequestWillBeSentEventDataType {
17921821
/**
@@ -1877,7 +1906,7 @@ declare module 'inspector' {
18771906
* Data that was received.
18781907
* @experimental
18791908
*/
1880-
data?: never | undefined;
1909+
data?: string | undefined;
18811910
}
18821911
}
18831912
namespace NodeRuntime {
@@ -2285,6 +2314,16 @@ declare module 'inspector' {
22852314
* Enables network tracking, network events will now be delivered to the client.
22862315
*/
22872316
post(method: 'Network.enable', callback?: (err: Error | null) => void): void;
2317+
/**
2318+
* Returns post data sent with the request. Returns an error when no data was sent with the request.
2319+
*/
2320+
post(method: 'Network.getRequestPostData', params?: Network.GetRequestPostDataParameterType, callback?: (err: Error | null, params: Network.GetRequestPostDataReturnType) => void): void;
2321+
post(method: 'Network.getRequestPostData', callback?: (err: Error | null, params: Network.GetRequestPostDataReturnType) => void): void;
2322+
/**
2323+
* Returns content served for the given request.
2324+
*/
2325+
post(method: 'Network.getResponseBody', params?: Network.GetResponseBodyParameterType, callback?: (err: Error | null, params: Network.GetResponseBodyReturnType) => void): void;
2326+
post(method: 'Network.getResponseBody', callback?: (err: Error | null, params: Network.GetResponseBodyReturnType) => void): void;
22882327
/**
22892328
* Enables streaming of the response for the given requestId.
22902329
* If enabled, the dataReceived event contains the data that was received during streaming.
@@ -3049,22 +3088,31 @@ declare module 'inspector' {
30493088

30503089
// DevTools protocol event broadcast methods
30513090
namespace Network {
3091+
/**
3092+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
3093+
*
3094+
* Broadcasts the `Network.requestWillBeSent` event to connected frontends. This event indicates that
3095+
* the application is about to send an HTTP request.
3096+
* @since v22.6.0
3097+
*/
3098+
function requestWillBeSent(params: RequestWillBeSentEventDataType): void;
30523099
/**
30533100
* This feature is only available with the `--experimental-network-inspection` flag enabled.
30543101
*
30553102
* Broadcasts the `Network.dataReceived` event to connected frontends, or buffers the data if
30563103
* `Network.streamResourceContent` command was not invoked for the given request yet.
3104+
*
3105+
* Also enables `Network.getResponseBody` command to retrieve the response data.
30573106
* @since v22.17.0
30583107
*/
30593108
function dataReceived(params: DataReceivedEventDataType): void;
30603109
/**
30613110
* This feature is only available with the `--experimental-network-inspection` flag enabled.
30623111
*
3063-
* Broadcasts the `Network.requestWillBeSent` event to connected frontends. This event indicates that
3064-
* the application is about to send an HTTP request.
3065-
* @since v22.6.0
3112+
* Enables `Network.getRequestPostData` command to retrieve the request data.
3113+
* @since v22.18.0
30663114
*/
3067-
function requestWillBeSent(params: RequestWillBeSentEventDataType): void;
3115+
function dataSent(params: unknown): void;
30683116
/**
30693117
* This feature is only available with the `--experimental-network-inspection` flag enabled.
30703118
*
@@ -3450,6 +3498,14 @@ declare module 'inspector/promises' {
34503498
* Enables network tracking, network events will now be delivered to the client.
34513499
*/
34523500
post(method: 'Network.enable'): Promise<void>;
3501+
/**
3502+
* Returns post data sent with the request. Returns an error when no data was sent with the request.
3503+
*/
3504+
post(method: 'Network.getRequestPostData', params?: Network.GetRequestPostDataParameterType): Promise<Network.GetRequestPostDataReturnType>;
3505+
/**
3506+
* Returns content served for the given request.
3507+
*/
3508+
post(method: 'Network.getResponseBody', params?: Network.GetResponseBodyParameterType): Promise<Network.GetResponseBodyReturnType>;
34533509
/**
34543510
* Enables streaming of the response for the given requestId.
34553511
* If enabled, the dataReceived event contains the data that was received during streaming.

types/node/v22/module.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,30 @@ declare module "module" {
684684
* @returns The absolute URL string that the specifier would resolve to.
685685
*/
686686
resolve(specifier: string, parent?: string | URL): string;
687+
/**
688+
* `true` when the current module is the entry point of the current process; `false` otherwise.
689+
*
690+
* Equivalent to `require.main === module` in CommonJS.
691+
*
692+
* Analogous to Python's `__name__ == "__main__"`.
693+
*
694+
* ```js
695+
* export function foo() {
696+
* return 'Hello, world';
697+
* }
698+
*
699+
* function main() {
700+
* const message = foo();
701+
* console.log(message);
702+
* }
703+
*
704+
* if (import.meta.main) main();
705+
* // `foo` can be imported from another module without possible side-effects from `main`
706+
* ```
707+
* @since v22.18.0
708+
* @experimental
709+
*/
710+
main: boolean;
687711
}
688712
namespace NodeJS {
689713
interface Module {

0 commit comments

Comments
 (0)