Upload 522 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +36 -35
- Dockerfile +13 -0
- README.md +83 -1
- clone/bun.lockb +0 -0
- clone/clone.ts +110 -0
- clone/node_modules/.bin/nanoid +3 -0
- clone/node_modules/.bin/which +3 -0
- clone/node_modules/.package-lock.json +165 -0
- clone/node_modules/@types/fluent-ffmpeg/LICENSE +21 -0
- clone/node_modules/@types/fluent-ffmpeg/README.md +15 -0
- clone/node_modules/@types/fluent-ffmpeg/index.d.ts +508 -0
- clone/node_modules/@types/fluent-ffmpeg/package.json +48 -0
- clone/node_modules/@types/node/LICENSE +21 -0
- clone/node_modules/@types/node/README.md +15 -0
- clone/node_modules/@types/node/assert.d.ts +1040 -0
- clone/node_modules/@types/node/assert/strict.d.ts +8 -0
- clone/node_modules/@types/node/async_hooks.d.ts +541 -0
- clone/node_modules/@types/node/buffer.buffer.d.ts +385 -0
- clone/node_modules/@types/node/buffer.d.ts +1933 -0
- clone/node_modules/@types/node/child_process.d.ts +1549 -0
- clone/node_modules/@types/node/cluster.d.ts +579 -0
- clone/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
- clone/node_modules/@types/node/compatibility/index.d.ts +9 -0
- clone/node_modules/@types/node/compatibility/indexable.d.ts +23 -0
- clone/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- clone/node_modules/@types/node/console.d.ts +452 -0
- clone/node_modules/@types/node/constants.d.ts +19 -0
- clone/node_modules/@types/node/crypto.d.ts +0 -0
- clone/node_modules/@types/node/dgram.d.ts +596 -0
- clone/node_modules/@types/node/diagnostics_channel.d.ts +554 -0
- clone/node_modules/@types/node/dns.d.ts +865 -0
- clone/node_modules/@types/node/dns/promises.d.ts +476 -0
- clone/node_modules/@types/node/dom-events.d.ts +124 -0
- clone/node_modules/@types/node/domain.d.ts +170 -0
- clone/node_modules/@types/node/events.d.ts +931 -0
- clone/node_modules/@types/node/fs.d.ts +0 -0
- clone/node_modules/@types/node/fs/promises.d.ts +1275 -0
- clone/node_modules/@types/node/globals.d.ts +511 -0
- clone/node_modules/@types/node/globals.typedarray.d.ts +21 -0
- clone/node_modules/@types/node/http.d.ts +1958 -0
- clone/node_modules/@types/node/http2.d.ts +0 -0
- clone/node_modules/@types/node/https.d.ts +543 -0
- clone/node_modules/@types/node/index.d.ts +92 -0
- clone/node_modules/@types/node/inspector.d.ts +0 -0
- clone/node_modules/@types/node/module.d.ts +621 -0
- clone/node_modules/@types/node/net.d.ts +1004 -0
- clone/node_modules/@types/node/os.d.ts +495 -0
- clone/node_modules/@types/node/package.json +220 -0
- clone/node_modules/@types/node/path.d.ts +200 -0
- clone/node_modules/@types/node/perf_hooks.d.ts +965 -0
.gitattributes
CHANGED
@@ -1,35 +1,36 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
clone/sample1.mp3 filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use the official PostgreSQL image from the Docker Hub
|
2 |
+
FROM postgres:latest
|
3 |
+
|
4 |
+
# Set environment variables for PostgreSQL
|
5 |
+
ENV POSTGRES_USER=postgres
|
6 |
+
ENV POSTGRES_PASSWORD=goat
|
7 |
+
ENV POSTGRES_DB=postgres
|
8 |
+
|
9 |
+
# Expose the PostgreSQL port
|
10 |
+
# Expose the PostgreSQL port
|
11 |
+
EXPOSE 5432
|
12 |
+
|
13 |
+
# The init.sql file should contain the SQL commands to create the schema
|
README.md
CHANGED
@@ -7,4 +7,86 @@ sdk: docker
|
|
7 |
pinned: false
|
8 |
---
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
pinned: false
|
8 |
---
|
9 |
|
10 |
+
|
11 |
+
# **AI-Powered Question & Answer Generator with Voice Cloning**
|
12 |
+
|
13 |
+
---
|
14 |
+
|
15 |
+
## **Overview**
|
16 |
+
|
17 |
+
This project leverages cutting-edge AI technologies to create an interactive experience where AI-generated answers are delivered using a cloned voice. The primary components of the project include:
|
18 |
+
|
19 |
+
1. **Text Generation**: Based on a fine-tuned model, Mistral-7B-v0.1, we generate realistic and human-like answers to user-provided questions.
|
20 |
+
2. **Voice Cloning**: Using the ElevenLabs API, we clone a voice and synthesize the AI-generated answers into natural-sounding speech.
|
21 |
+
3. **Deception for Interaction**: The system is designed to "tromper" (mislead) players by making the responses appear as if they are coming from a real human.
|
22 |
+
|
23 |
+
---
|
24 |
+
|
25 |
+
## **Key Features**
|
26 |
+
|
27 |
+
1. **Fine-Tuned Model for Text Generation**:
|
28 |
+
- The project utilizes the **Mistral-7B-v0.1** model fine-tuned on a custom dataset.
|
29 |
+
- The model generates contextually accurate, human-like responses to a wide range of questions.
|
30 |
+
|
31 |
+
2. **Voice Cloning with ElevenLabs**:
|
32 |
+
- ElevenLabs’ **Speech-to-Text and Voice Cloning API** is used to replicate a target voice.
|
33 |
+
- The cloned voice delivers the AI-generated answers in a natural and believable manner.
|
34 |
+
|
35 |
+
3. **Integration for Immersion**:
|
36 |
+
- The generated answers and synthesized speech are integrated to provide seamless interaction.
|
37 |
+
- Designed for applications in gaming, interactive storytelling, or prank scenarios.
|
38 |
+
|
39 |
+
---
|
40 |
+
|
41 |
+
## **How It Works**
|
42 |
+
|
43 |
+
### 1. **Question Input**:
|
44 |
+
- Users provide a question in text form (e.g., "What’s the best way to prepare for a long flight?").
|
45 |
+
- Alternatively, voice input can be transcribed to text using ElevenLabs’ speech-to-text feature.
|
46 |
+
|
47 |
+
### 2. **Text Generation**:
|
48 |
+
- The Mistral-7B-v0.1 model processes the input question and generates a natural response.
|
49 |
+
- Example:
|
50 |
+
- **Question**: "What’s your favorite place to relax?"
|
51 |
+
- **Answer**: "My room, where I can unwind and enjoy some quiet time."
|
52 |
+
|
53 |
+
### 3. **Voice Cloning**:
|
54 |
+
- The generated text is sent to ElevenLabs’ API, where it is converted into speech using a cloned voice.
|
55 |
+
- The voice sounds human, complete with natural intonation and emotion.
|
56 |
+
|
57 |
+
### 4. **Output Delivery**:
|
58 |
+
- The final output is an audio response delivered in the cloned voice, making it indistinguishable from a real human speaker.
|
59 |
+
|
60 |
+
---
|
61 |
+
|
62 |
+
## **Applications**
|
63 |
+
|
64 |
+
- **Gaming**: Use in trivia or role-playing games to simulate human-like NPCs.
|
65 |
+
- **Storytelling**: Create immersive audio experiences by combining generated text with realistic voiceovers.
|
66 |
+
- **Social Experiments**: Test human reactions to AI-generated, voice-synthesized responses in various scenarios.
|
67 |
+
- **Entertainment/Pranks**: Surprise players or audiences with a system that convincingly mimics a real human.
|
68 |
+
|
69 |
+
---
|
70 |
+
|
71 |
+
## **Technologies Used**
|
72 |
+
|
73 |
+
1. **Mistral-7B-v0.1**:
|
74 |
+
- A fine-tuned large language model specializing in text generation.
|
75 |
+
- Delivers contextually accurate and relatable answers.
|
76 |
+
|
77 |
+
2. **ElevenLabs API**:
|
78 |
+
- **Speech-to-Text**: Converts spoken questions into text for the model to process.
|
79 |
+
- **Voice Cloning**: Synthesizes text into speech using a cloned voice.
|
80 |
+
|
81 |
+
3. **Python**:
|
82 |
+
- Backend logic for integrating text generation, voice synthesis, and API calls.
|
83 |
+
- Frameworks and libraries include `transformers`, `torch`, and API wrappers for ElevenLabs.
|
84 |
+
|
85 |
+
---
|
86 |
+
|
87 |
+
## **Setup Instructions**
|
88 |
+
|
89 |
+
### 1. **Clone the Repository**:
|
90 |
+
```bash
|
91 |
+
git clone https://github.com/Lirone/NotMe.git
|
92 |
+
cd NotMe
|
clone/bun.lockb
ADDED
Binary file (7.36 kB). View file
|
|
clone/clone.ts
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import "dotenv/config";
|
2 |
+
import FormData from "form-data";
|
3 |
+
import axios from "axios";
|
4 |
+
import fs from "fs";
|
5 |
+
|
6 |
+
interface ICloneVoiceParams {
|
7 |
+
description: string;
|
8 |
+
name: string;
|
9 |
+
fileUrls: string[];
|
10 |
+
labels: Record<string, string>;
|
11 |
+
}
|
12 |
+
|
13 |
+
const handleStreamEnd = (stream: fs.ReadStream): Promise<void> => {
|
14 |
+
return new Promise((resolve) => {
|
15 |
+
if (!stream || stream?.closed) {
|
16 |
+
resolve();
|
17 |
+
return;
|
18 |
+
}
|
19 |
+
|
20 |
+
stream.once("end", () => {
|
21 |
+
resolve();
|
22 |
+
});
|
23 |
+
stream.once("close", () => {
|
24 |
+
resolve();
|
25 |
+
});
|
26 |
+
});
|
27 |
+
};
|
28 |
+
|
29 |
+
const cloneVoiceHandler = async (
|
30 |
+
params: ICloneVoiceParams
|
31 |
+
): Promise<string> => {
|
32 |
+
const { name, description, fileUrls = [], labels = {} } = params;
|
33 |
+
const formData = new FormData();
|
34 |
+
const streams: fs.ReadStream[] = [];
|
35 |
+
|
36 |
+
console.log("Début du clonage de voix...");
|
37 |
+
console.log("Fichiers à traiter:", fileUrls);
|
38 |
+
|
39 |
+
for (let i = 0; i < fileUrls.length; i++) {
|
40 |
+
try {
|
41 |
+
const filePath = fileUrls[i];
|
42 |
+
console.log(`Traitement du fichier ${filePath}...`);
|
43 |
+
|
44 |
+
const fileStream = fs.createReadStream(filePath);
|
45 |
+
streams.push(fileStream);
|
46 |
+
|
47 |
+
formData.append("files", fileStream, {
|
48 |
+
filename: "sample1.mp3",
|
49 |
+
contentType: "audio/mpeg",
|
50 |
+
});
|
51 |
+
} catch (err) {
|
52 |
+
console.error("Erreur lors du traitement du fichier:", err);
|
53 |
+
throw err;
|
54 |
+
}
|
55 |
+
}
|
56 |
+
|
57 |
+
formData.append("name", name);
|
58 |
+
formData.append("description", description);
|
59 |
+
|
60 |
+
if (typeof labels === "object" && labels) {
|
61 |
+
formData.append("labels", JSON.stringify(labels));
|
62 |
+
}
|
63 |
+
|
64 |
+
try {
|
65 |
+
const elevenlabsUrl = "https://api.elevenlabs.io/v1/voices/add";
|
66 |
+
const elevenLabsApiKey = process.env.ELEVENLABS_API_KEY || "";
|
67 |
+
console.log("Envoi de la requête à ElevenLabs...");
|
68 |
+
|
69 |
+
const elevenLabsResponse = await axios.post(elevenlabsUrl, formData, {
|
70 |
+
headers: {
|
71 |
+
...formData.getHeaders(),
|
72 |
+
Accept: "application/json",
|
73 |
+
"xi-api-key": elevenLabsApiKey,
|
74 |
+
},
|
75 |
+
});
|
76 |
+
|
77 |
+
console.log("Réponse d'ElevenLabs:", elevenLabsResponse.data);
|
78 |
+
return elevenLabsResponse.data?.voice_id || "";
|
79 |
+
} catch (err) {
|
80 |
+
console.error(
|
81 |
+
"Erreur lors de l'appel à ElevenLabs:",
|
82 |
+
err.response?.data || err
|
83 |
+
);
|
84 |
+
throw err;
|
85 |
+
} finally {
|
86 |
+
// Fermer tous les streams
|
87 |
+
for (const stream of streams) {
|
88 |
+
stream.destroy();
|
89 |
+
}
|
90 |
+
}
|
91 |
+
};
|
92 |
+
|
93 |
+
const params = {
|
94 |
+
name: "test",
|
95 |
+
description: "Voix française calme",
|
96 |
+
fileUrls: [
|
97 |
+
"./sample1.mp3", // Notez le ./ pour indiquer le dossier courant
|
98 |
+
],
|
99 |
+
labels: {
|
100 |
+
accent: "français",
|
101 |
+
type: "calme",
|
102 |
+
},
|
103 |
+
};
|
104 |
+
|
105 |
+
try {
|
106 |
+
const voiceId = await cloneVoiceHandler(params);
|
107 |
+
console.log("Voice ID obtenu:", voiceId);
|
108 |
+
} catch (error) {
|
109 |
+
console.error("Erreur globale:", error);
|
110 |
+
}
|
clone/node_modules/.bin/nanoid
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:da2f613755db5bd49fa1fb3566b0931e4cd0b847107acec93f6e2450f6405598
|
3 |
+
size 23
|
clone/node_modules/.bin/which
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0936f5b2ad8f7d7c0c7edbb7a20e7065c8b4725bc7b0e83b04c70794e1479bf4
|
3 |
+
size 18
|
clone/node_modules/.package-lock.json
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "clone",
|
3 |
+
"lockfileVersion": 3,
|
4 |
+
"requires": true,
|
5 |
+
"packages": {
|
6 |
+
"node_modules/@types/fluent-ffmpeg": {
|
7 |
+
"version": "2.1.27",
|
8 |
+
"license": "MIT",
|
9 |
+
"dependencies": {
|
10 |
+
"@types/node": "*"
|
11 |
+
}
|
12 |
+
},
|
13 |
+
"node_modules/@types/node": {
|
14 |
+
"version": "22.10.10",
|
15 |
+
"license": "MIT",
|
16 |
+
"dependencies": {
|
17 |
+
"undici-types": "~6.20.0"
|
18 |
+
}
|
19 |
+
},
|
20 |
+
"node_modules/async": {
|
21 |
+
"version": "0.2.10"
|
22 |
+
},
|
23 |
+
"node_modules/asynckit": {
|
24 |
+
"version": "0.4.0",
|
25 |
+
"license": "MIT"
|
26 |
+
},
|
27 |
+
"node_modules/axios": {
|
28 |
+
"version": "1.7.9",
|
29 |
+
"license": "MIT",
|
30 |
+
"dependencies": {
|
31 |
+
"follow-redirects": "^1.15.6",
|
32 |
+
"form-data": "^4.0.0",
|
33 |
+
"proxy-from-env": "^1.1.0"
|
34 |
+
}
|
35 |
+
},
|
36 |
+
"node_modules/combined-stream": {
|
37 |
+
"version": "1.0.8",
|
38 |
+
"license": "MIT",
|
39 |
+
"dependencies": {
|
40 |
+
"delayed-stream": "~1.0.0"
|
41 |
+
},
|
42 |
+
"engines": {
|
43 |
+
"node": ">= 0.8"
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"node_modules/delayed-stream": {
|
47 |
+
"version": "1.0.0",
|
48 |
+
"license": "MIT",
|
49 |
+
"engines": {
|
50 |
+
"node": ">=0.4.0"
|
51 |
+
}
|
52 |
+
},
|
53 |
+
"node_modules/dotenv": {
|
54 |
+
"version": "16.4.7",
|
55 |
+
"license": "BSD-2-Clause",
|
56 |
+
"engines": {
|
57 |
+
"node": ">=12"
|
58 |
+
},
|
59 |
+
"funding": {
|
60 |
+
"url": "https://dotenvx.com"
|
61 |
+
}
|
62 |
+
},
|
63 |
+
"node_modules/fluent-ffmpeg": {
|
64 |
+
"version": "2.1.3",
|
65 |
+
"license": "MIT",
|
66 |
+
"dependencies": {
|
67 |
+
"async": "^0.2.9",
|
68 |
+
"which": "^1.1.1"
|
69 |
+
},
|
70 |
+
"engines": {
|
71 |
+
"node": ">=18"
|
72 |
+
}
|
73 |
+
},
|
74 |
+
"node_modules/follow-redirects": {
|
75 |
+
"version": "1.15.9",
|
76 |
+
"funding": [
|
77 |
+
{
|
78 |
+
"type": "individual",
|
79 |
+
"url": "https://github.com/sponsors/RubenVerborgh"
|
80 |
+
}
|
81 |
+
],
|
82 |
+
"license": "MIT",
|
83 |
+
"engines": {
|
84 |
+
"node": ">=4.0"
|
85 |
+
},
|
86 |
+
"peerDependenciesMeta": {
|
87 |
+
"debug": {
|
88 |
+
"optional": true
|
89 |
+
}
|
90 |
+
}
|
91 |
+
},
|
92 |
+
"node_modules/form-data": {
|
93 |
+
"version": "4.0.1",
|
94 |
+
"license": "MIT",
|
95 |
+
"dependencies": {
|
96 |
+
"asynckit": "^0.4.0",
|
97 |
+
"combined-stream": "^1.0.8",
|
98 |
+
"mime-types": "^2.1.12"
|
99 |
+
},
|
100 |
+
"engines": {
|
101 |
+
"node": ">= 6"
|
102 |
+
}
|
103 |
+
},
|
104 |
+
"node_modules/fs": {
|
105 |
+
"version": "0.0.1-security",
|
106 |
+
"license": "ISC"
|
107 |
+
},
|
108 |
+
"node_modules/isexe": {
|
109 |
+
"version": "2.0.0",
|
110 |
+
"license": "ISC"
|
111 |
+
},
|
112 |
+
"node_modules/mime-db": {
|
113 |
+
"version": "1.52.0",
|
114 |
+
"license": "MIT",
|
115 |
+
"engines": {
|
116 |
+
"node": ">= 0.6"
|
117 |
+
}
|
118 |
+
},
|
119 |
+
"node_modules/mime-types": {
|
120 |
+
"version": "2.1.35",
|
121 |
+
"license": "MIT",
|
122 |
+
"dependencies": {
|
123 |
+
"mime-db": "1.52.0"
|
124 |
+
},
|
125 |
+
"engines": {
|
126 |
+
"node": ">= 0.6"
|
127 |
+
}
|
128 |
+
},
|
129 |
+
"node_modules/nanoid": {
|
130 |
+
"version": "5.0.9",
|
131 |
+
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.0.9.tgz",
|
132 |
+
"integrity": "sha512-Aooyr6MXU6HpvvWXKoVoXwKMs/KyVakWwg7xQfv5/S/RIgJMy0Ifa45H9qqYy7pTCszrHzP21Uk4PZq2HpEM8Q==",
|
133 |
+
"funding": [
|
134 |
+
{
|
135 |
+
"type": "github",
|
136 |
+
"url": "https://github.com/sponsors/ai"
|
137 |
+
}
|
138 |
+
],
|
139 |
+
"bin": {
|
140 |
+
"nanoid": "bin/nanoid.js"
|
141 |
+
},
|
142 |
+
"engines": {
|
143 |
+
"node": "^18 || >=20"
|
144 |
+
}
|
145 |
+
},
|
146 |
+
"node_modules/proxy-from-env": {
|
147 |
+
"version": "1.1.0",
|
148 |
+
"license": "MIT"
|
149 |
+
},
|
150 |
+
"node_modules/undici-types": {
|
151 |
+
"version": "6.20.0",
|
152 |
+
"license": "MIT"
|
153 |
+
},
|
154 |
+
"node_modules/which": {
|
155 |
+
"version": "1.3.1",
|
156 |
+
"license": "ISC",
|
157 |
+
"dependencies": {
|
158 |
+
"isexe": "^2.0.0"
|
159 |
+
},
|
160 |
+
"bin": {
|
161 |
+
"which": "bin/which"
|
162 |
+
}
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
clone/node_modules/@types/fluent-ffmpeg/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) Microsoft Corporation.
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE
|
clone/node_modules/@types/fluent-ffmpeg/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Installation
|
2 |
+
> `npm install --save @types/fluent-ffmpeg`
|
3 |
+
|
4 |
+
# Summary
|
5 |
+
This package contains type definitions for fluent-ffmpeg (https://github.com/fluent-ffmpeg/node-fluent-ffmpeg).
|
6 |
+
|
7 |
+
# Details
|
8 |
+
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/fluent-ffmpeg.
|
9 |
+
|
10 |
+
### Additional Details
|
11 |
+
* Last updated: Sat, 26 Oct 2024 09:02:18 GMT
|
12 |
+
* Dependencies: [@types/node](https://npmjs.com/package/@types/node)
|
13 |
+
|
14 |
+
# Credits
|
15 |
+
These definitions were written by [KIM Jaesuck a.k.a. gim tcaesvk](https://github.com/tcaesvk), [DingWeizhe](https://github.com/DingWeizhe), [Mounir Abid](https://github.com/mabidina), [Doyoung Ha](https://github.com/hados99), and [Prasad Nayak](https://github.com/buzzertech).
|
clone/node_modules/@types/fluent-ffmpeg/index.d.ts
ADDED
@@ -0,0 +1,508 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/// <reference types="node" />
|
2 |
+
|
3 |
+
import * as events from "events";
|
4 |
+
import * as stream from "stream";
|
5 |
+
|
6 |
+
declare namespace Ffmpeg {
|
7 |
+
interface FfmpegCommandLogger {
|
8 |
+
error(...data: any[]): void;
|
9 |
+
warn(...data: any[]): void;
|
10 |
+
info(...data: any[]): void;
|
11 |
+
debug(...data: any[]): void;
|
12 |
+
}
|
13 |
+
|
14 |
+
interface FfmpegCommandOptions {
|
15 |
+
logger?: FfmpegCommandLogger | undefined;
|
16 |
+
niceness?: number | undefined;
|
17 |
+
priority?: number | undefined;
|
18 |
+
presets?: string | undefined;
|
19 |
+
preset?: string | undefined;
|
20 |
+
stdoutLines?: number | undefined;
|
21 |
+
timeout?: number | undefined;
|
22 |
+
source?: string | stream.Readable | undefined;
|
23 |
+
cwd?: string | undefined;
|
24 |
+
}
|
25 |
+
|
26 |
+
interface FilterSpecification {
|
27 |
+
filter: string;
|
28 |
+
inputs?: string | string[] | undefined;
|
29 |
+
outputs?: string | string[] | undefined;
|
30 |
+
options?: any | string | any[] | undefined;
|
31 |
+
}
|
32 |
+
|
33 |
+
type PresetFunction = (command: FfmpegCommand) => void;
|
34 |
+
|
35 |
+
interface Filter {
|
36 |
+
description: string;
|
37 |
+
input: string;
|
38 |
+
multipleInputs: boolean;
|
39 |
+
output: string;
|
40 |
+
multipleOutputs: boolean;
|
41 |
+
}
|
42 |
+
interface Filters {
|
43 |
+
[key: string]: Filter;
|
44 |
+
}
|
45 |
+
type FiltersCallback = (err: Error, filters: Filters) => void;
|
46 |
+
|
47 |
+
interface Codec {
|
48 |
+
type: string;
|
49 |
+
description: string;
|
50 |
+
canDecode: boolean;
|
51 |
+
canEncode: boolean;
|
52 |
+
drawHorizBand?: boolean | undefined;
|
53 |
+
directRendering?: boolean | undefined;
|
54 |
+
weirdFrameTruncation?: boolean | undefined;
|
55 |
+
intraFrameOnly?: boolean | undefined;
|
56 |
+
isLossy?: boolean | undefined;
|
57 |
+
isLossless?: boolean | undefined;
|
58 |
+
}
|
59 |
+
interface Codecs {
|
60 |
+
[key: string]: Codec;
|
61 |
+
}
|
62 |
+
type CodecsCallback = (err: Error, codecs: Codecs) => void;
|
63 |
+
|
64 |
+
interface Encoder {
|
65 |
+
type: string;
|
66 |
+
description: string;
|
67 |
+
frameMT: boolean;
|
68 |
+
sliceMT: boolean;
|
69 |
+
experimental: boolean;
|
70 |
+
drawHorizBand: boolean;
|
71 |
+
directRendering: boolean;
|
72 |
+
}
|
73 |
+
interface Encoders {
|
74 |
+
[key: string]: Encoder;
|
75 |
+
}
|
76 |
+
type EncodersCallback = (err: Error, encoders: Encoders) => void;
|
77 |
+
|
78 |
+
interface Format {
|
79 |
+
description: string;
|
80 |
+
canDemux: boolean;
|
81 |
+
canMux: boolean;
|
82 |
+
}
|
83 |
+
interface Formats {
|
84 |
+
[key: string]: Format;
|
85 |
+
}
|
86 |
+
type FormatsCallback = (err: Error, formats: Formats) => void;
|
87 |
+
|
88 |
+
interface FfprobeData {
|
89 |
+
streams: FfprobeStream[];
|
90 |
+
format: FfprobeFormat;
|
91 |
+
chapters: any[];
|
92 |
+
}
|
93 |
+
|
94 |
+
interface FfprobeStream {
|
95 |
+
[key: string]: any;
|
96 |
+
index: number;
|
97 |
+
codec_name?: string | undefined;
|
98 |
+
codec_long_name?: string | undefined;
|
99 |
+
profile?: number | undefined;
|
100 |
+
codec_type?: string | undefined;
|
101 |
+
codec_time_base?: string | undefined;
|
102 |
+
codec_tag_string?: string | undefined;
|
103 |
+
codec_tag?: string | undefined;
|
104 |
+
width?: number | undefined;
|
105 |
+
height?: number | undefined;
|
106 |
+
coded_width?: number | undefined;
|
107 |
+
coded_height?: number | undefined;
|
108 |
+
has_b_frames?: number | undefined;
|
109 |
+
sample_aspect_ratio?: string | undefined;
|
110 |
+
display_aspect_ratio?: string | undefined;
|
111 |
+
pix_fmt?: string | undefined;
|
112 |
+
level?: string | undefined;
|
113 |
+
color_range?: string | undefined;
|
114 |
+
color_space?: string | undefined;
|
115 |
+
color_transfer?: string | undefined;
|
116 |
+
color_primaries?: string | undefined;
|
117 |
+
chroma_location?: string | undefined;
|
118 |
+
field_order?: string | undefined;
|
119 |
+
timecode?: string | undefined;
|
120 |
+
refs?: number | undefined;
|
121 |
+
id?: string | undefined;
|
122 |
+
r_frame_rate?: string | undefined;
|
123 |
+
avg_frame_rate?: string | undefined;
|
124 |
+
time_base?: string | undefined;
|
125 |
+
start_pts?: number | undefined;
|
126 |
+
start_time?: number | undefined;
|
127 |
+
duration_ts?: string | undefined;
|
128 |
+
duration?: string | undefined;
|
129 |
+
bit_rate?: string | undefined;
|
130 |
+
max_bit_rate?: string | undefined;
|
131 |
+
bits_per_raw_sample?: string | undefined;
|
132 |
+
nb_frames?: string | undefined;
|
133 |
+
nb_read_frames?: string | undefined;
|
134 |
+
nb_read_packets?: string | undefined;
|
135 |
+
sample_fmt?: string | undefined;
|
136 |
+
sample_rate?: number | undefined;
|
137 |
+
channels?: number | undefined;
|
138 |
+
channel_layout?: string | undefined;
|
139 |
+
bits_per_sample?: number | undefined;
|
140 |
+
disposition?: FfprobeStreamDisposition | undefined;
|
141 |
+
rotation?: string | number | undefined;
|
142 |
+
}
|
143 |
+
|
144 |
+
interface FfprobeStreamDisposition {
|
145 |
+
[key: string]: any;
|
146 |
+
default?: number | undefined;
|
147 |
+
dub?: number | undefined;
|
148 |
+
original?: number | undefined;
|
149 |
+
comment?: number | undefined;
|
150 |
+
lyrics?: number | undefined;
|
151 |
+
karaoke?: number | undefined;
|
152 |
+
forced?: number | undefined;
|
153 |
+
hearing_impaired?: number | undefined;
|
154 |
+
visual_impaired?: number | undefined;
|
155 |
+
clean_effects?: number | undefined;
|
156 |
+
attached_pic?: number | undefined;
|
157 |
+
timed_thumbnails?: number | undefined;
|
158 |
+
}
|
159 |
+
|
160 |
+
interface FfprobeFormat {
|
161 |
+
[key: string]: any;
|
162 |
+
filename?: string | undefined;
|
163 |
+
nb_streams?: number | undefined;
|
164 |
+
nb_programs?: number | undefined;
|
165 |
+
format_name?: string | undefined;
|
166 |
+
format_long_name?: string | undefined;
|
167 |
+
start_time?: number | undefined;
|
168 |
+
duration?: number | undefined;
|
169 |
+
size?: number | undefined;
|
170 |
+
bit_rate?: number | undefined;
|
171 |
+
probe_score?: number | undefined;
|
172 |
+
tags?: Record<string, string | number> | undefined;
|
173 |
+
}
|
174 |
+
|
175 |
+
interface ScreenshotsConfig {
|
176 |
+
count?: number | undefined;
|
177 |
+
folder?: string | undefined;
|
178 |
+
filename?: string | undefined;
|
179 |
+
timemarks?: number[] | string[] | undefined;
|
180 |
+
timestamps?: number[] | string[] | undefined;
|
181 |
+
fastSeek?: boolean | undefined;
|
182 |
+
size?: string | undefined;
|
183 |
+
}
|
184 |
+
|
185 |
+
interface AudioVideoFilter {
|
186 |
+
filter: string;
|
187 |
+
options: string | string[] | {};
|
188 |
+
}
|
189 |
+
|
190 |
+
// static methods
|
191 |
+
function setFfmpegPath(path: string): FfmpegCommand;
|
192 |
+
function setFfprobePath(path: string): FfmpegCommand;
|
193 |
+
function setFlvtoolPath(path: string): FfmpegCommand;
|
194 |
+
function availableFilters(callback: FiltersCallback): void;
|
195 |
+
function getAvailableFilters(callback: FiltersCallback): void;
|
196 |
+
function availableCodecs(callback: CodecsCallback): void;
|
197 |
+
function getAvailableCodecs(callback: CodecsCallback): void;
|
198 |
+
function availableEncoders(callback: EncodersCallback): void;
|
199 |
+
function getAvailableEncoders(callback: EncodersCallback): void;
|
200 |
+
function availableFormats(callback: FormatsCallback): void;
|
201 |
+
function getAvailableFormats(callback: FormatsCallback): void;
|
202 |
+
|
203 |
+
class FfmpegCommand extends events.EventEmitter {
|
204 |
+
constructor(options?: FfmpegCommandOptions);
|
205 |
+
constructor(input?: string | stream.Readable, options?: FfmpegCommandOptions);
|
206 |
+
|
207 |
+
// options/inputs
|
208 |
+
mergeAdd(source: string | stream.Readable): FfmpegCommand;
|
209 |
+
addInput(source: string | stream.Readable): FfmpegCommand;
|
210 |
+
input(source: string | stream.Readable): FfmpegCommand;
|
211 |
+
withInputFormat(format: string): FfmpegCommand;
|
212 |
+
inputFormat(format: string): FfmpegCommand;
|
213 |
+
fromFormat(format: string): FfmpegCommand;
|
214 |
+
withInputFps(fps: number): FfmpegCommand;
|
215 |
+
withInputFPS(fps: number): FfmpegCommand;
|
216 |
+
withFpsInput(fps: number): FfmpegCommand;
|
217 |
+
withFPSInput(fps: number): FfmpegCommand;
|
218 |
+
inputFPS(fps: number): FfmpegCommand;
|
219 |
+
inputFps(fps: number): FfmpegCommand;
|
220 |
+
fpsInput(fps: number): FfmpegCommand;
|
221 |
+
FPSInput(fps: number): FfmpegCommand;
|
222 |
+
nativeFramerate(): FfmpegCommand;
|
223 |
+
withNativeFramerate(): FfmpegCommand;
|
224 |
+
native(): FfmpegCommand;
|
225 |
+
setStartTime(seek: string | number): FfmpegCommand;
|
226 |
+
seekInput(seek: string | number): FfmpegCommand;
|
227 |
+
loop(duration?: string | number): FfmpegCommand;
|
228 |
+
|
229 |
+
// options/audio
|
230 |
+
withNoAudio(): FfmpegCommand;
|
231 |
+
noAudio(): FfmpegCommand;
|
232 |
+
withAudioCodec(codec: string): FfmpegCommand;
|
233 |
+
audioCodec(codec: string): FfmpegCommand;
|
234 |
+
withAudioBitrate(bitrate: string | number): FfmpegCommand;
|
235 |
+
audioBitrate(bitrate: string | number): FfmpegCommand;
|
236 |
+
withAudioChannels(channels: number): FfmpegCommand;
|
237 |
+
audioChannels(channels: number): FfmpegCommand;
|
238 |
+
withAudioFrequency(freq: number): FfmpegCommand;
|
239 |
+
audioFrequency(freq: number): FfmpegCommand;
|
240 |
+
withAudioQuality(quality: number): FfmpegCommand;
|
241 |
+
audioQuality(quality: number): FfmpegCommand;
|
242 |
+
withAudioFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
243 |
+
withAudioFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
244 |
+
audioFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
245 |
+
audioFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
246 |
+
|
247 |
+
// options/video;
|
248 |
+
withNoVideo(): FfmpegCommand;
|
249 |
+
noVideo(): FfmpegCommand;
|
250 |
+
withVideoCodec(codec: string): FfmpegCommand;
|
251 |
+
videoCodec(codec: string): FfmpegCommand;
|
252 |
+
withVideoBitrate(bitrate: string | number, constant?: boolean): FfmpegCommand;
|
253 |
+
videoBitrate(bitrate: string | number, constant?: boolean): FfmpegCommand;
|
254 |
+
withVideoFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
255 |
+
withVideoFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
256 |
+
videoFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
257 |
+
videoFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
258 |
+
withOutputFps(fps: number): FfmpegCommand;
|
259 |
+
withOutputFPS(fps: number): FfmpegCommand;
|
260 |
+
withFpsOutput(fps: number): FfmpegCommand;
|
261 |
+
withFPSOutput(fps: number): FfmpegCommand;
|
262 |
+
withFps(fps: number): FfmpegCommand;
|
263 |
+
withFPS(fps: number): FfmpegCommand;
|
264 |
+
outputFPS(fps: number): FfmpegCommand;
|
265 |
+
outputFps(fps: number): FfmpegCommand;
|
266 |
+
fpsOutput(fps: number): FfmpegCommand;
|
267 |
+
FPSOutput(fps: number): FfmpegCommand;
|
268 |
+
fps(fps: number): FfmpegCommand;
|
269 |
+
FPS(fps: number): FfmpegCommand;
|
270 |
+
takeFrames(frames: number): FfmpegCommand;
|
271 |
+
withFrames(frames: number): FfmpegCommand;
|
272 |
+
frames(frames: number): FfmpegCommand;
|
273 |
+
|
274 |
+
// options/videosize
|
275 |
+
keepPixelAspect(): FfmpegCommand;
|
276 |
+
keepDisplayAspect(): FfmpegCommand;
|
277 |
+
keepDisplayAspectRatio(): FfmpegCommand;
|
278 |
+
keepDAR(): FfmpegCommand;
|
279 |
+
withSize(size: string): FfmpegCommand;
|
280 |
+
setSize(size: string): FfmpegCommand;
|
281 |
+
size(size: string): FfmpegCommand;
|
282 |
+
withAspect(aspect: string | number): FfmpegCommand;
|
283 |
+
withAspectRatio(aspect: string | number): FfmpegCommand;
|
284 |
+
setAspect(aspect: string | number): FfmpegCommand;
|
285 |
+
setAspectRatio(aspect: string | number): FfmpegCommand;
|
286 |
+
aspect(aspect: string | number): FfmpegCommand;
|
287 |
+
aspectRatio(aspect: string | number): FfmpegCommand;
|
288 |
+
applyAutopadding(pad?: boolean, color?: string): FfmpegCommand;
|
289 |
+
applyAutoPadding(pad?: boolean, color?: string): FfmpegCommand;
|
290 |
+
applyAutopad(pad?: boolean, color?: string): FfmpegCommand;
|
291 |
+
applyAutoPad(pad?: boolean, color?: string): FfmpegCommand;
|
292 |
+
withAutopadding(pad?: boolean, color?: string): FfmpegCommand;
|
293 |
+
withAutoPadding(pad?: boolean, color?: string): FfmpegCommand;
|
294 |
+
withAutopad(pad?: boolean, color?: string): FfmpegCommand;
|
295 |
+
withAutoPad(pad?: boolean, color?: string): FfmpegCommand;
|
296 |
+
autoPad(pad?: boolean, color?: string): FfmpegCommand;
|
297 |
+
autopad(pad?: boolean, color?: string): FfmpegCommand;
|
298 |
+
|
299 |
+
// options/output
|
300 |
+
addOutput(target: string | stream.Writable, pipeopts?: { end?: boolean | undefined }): FfmpegCommand;
|
301 |
+
output(target: string | stream.Writable, pipeopts?: { end?: boolean | undefined }): FfmpegCommand;
|
302 |
+
seekOutput(seek: string | number): FfmpegCommand;
|
303 |
+
seek(seek: string | number): FfmpegCommand;
|
304 |
+
withDuration(duration: string | number): FfmpegCommand;
|
305 |
+
setDuration(duration: string | number): FfmpegCommand;
|
306 |
+
duration(duration: string | number): FfmpegCommand;
|
307 |
+
toFormat(format: string): FfmpegCommand;
|
308 |
+
withOutputFormat(format: string): FfmpegCommand;
|
309 |
+
outputFormat(format: string): FfmpegCommand;
|
310 |
+
format(format: string): FfmpegCommand;
|
311 |
+
map(spec: string): FfmpegCommand;
|
312 |
+
updateFlvMetadata(): FfmpegCommand;
|
313 |
+
flvmeta(): FfmpegCommand;
|
314 |
+
|
315 |
+
// options/custom
|
316 |
+
addInputOption(options: string[]): FfmpegCommand;
|
317 |
+
addInputOption(...options: string[]): FfmpegCommand;
|
318 |
+
addInputOptions(options: string[]): FfmpegCommand;
|
319 |
+
addInputOptions(...options: string[]): FfmpegCommand;
|
320 |
+
withInputOption(options: string[]): FfmpegCommand;
|
321 |
+
withInputOption(...options: string[]): FfmpegCommand;
|
322 |
+
withInputOptions(options: string[]): FfmpegCommand;
|
323 |
+
withInputOptions(...options: string[]): FfmpegCommand;
|
324 |
+
inputOption(options: string[]): FfmpegCommand;
|
325 |
+
inputOption(...options: string[]): FfmpegCommand;
|
326 |
+
inputOptions(options: string[]): FfmpegCommand;
|
327 |
+
inputOptions(...options: string[]): FfmpegCommand;
|
328 |
+
addOutputOption(options: string[]): FfmpegCommand;
|
329 |
+
addOutputOption(...options: string[]): FfmpegCommand;
|
330 |
+
addOutputOptions(options: string[]): FfmpegCommand;
|
331 |
+
addOutputOptions(...options: string[]): FfmpegCommand;
|
332 |
+
addOption(options: string[]): FfmpegCommand;
|
333 |
+
addOption(...options: string[]): FfmpegCommand;
|
334 |
+
addOptions(options: string[]): FfmpegCommand;
|
335 |
+
addOptions(...options: string[]): FfmpegCommand;
|
336 |
+
withOutputOption(options: string[]): FfmpegCommand;
|
337 |
+
withOutputOption(...options: string[]): FfmpegCommand;
|
338 |
+
withOutputOptions(options: string[]): FfmpegCommand;
|
339 |
+
withOutputOptions(...options: string[]): FfmpegCommand;
|
340 |
+
withOption(options: string[]): FfmpegCommand;
|
341 |
+
withOption(...options: string[]): FfmpegCommand;
|
342 |
+
withOptions(options: string[]): FfmpegCommand;
|
343 |
+
withOptions(...options: string[]): FfmpegCommand;
|
344 |
+
outputOption(options: string[]): FfmpegCommand;
|
345 |
+
outputOption(...options: string[]): FfmpegCommand;
|
346 |
+
outputOptions(options: string[]): FfmpegCommand;
|
347 |
+
outputOptions(...options: string[]): FfmpegCommand;
|
348 |
+
filterGraph(
|
349 |
+
spec: string | FilterSpecification | Array<string | FilterSpecification>,
|
350 |
+
map?: string[] | string,
|
351 |
+
): FfmpegCommand;
|
352 |
+
complexFilter(
|
353 |
+
spec: string | FilterSpecification | Array<string | FilterSpecification>,
|
354 |
+
map?: string[] | string,
|
355 |
+
): FfmpegCommand;
|
356 |
+
|
357 |
+
// options/misc
|
358 |
+
usingPreset(preset: string | PresetFunction): FfmpegCommand;
|
359 |
+
preset(preset: string | PresetFunction): FfmpegCommand;
|
360 |
+
|
361 |
+
// processor
|
362 |
+
renice(niceness: number): FfmpegCommand;
|
363 |
+
kill(signal: string): FfmpegCommand;
|
364 |
+
_getArguments(): string[];
|
365 |
+
|
366 |
+
// capabilities
|
367 |
+
setFfmpegPath(path: string): FfmpegCommand;
|
368 |
+
setFfprobePath(path: string): FfmpegCommand;
|
369 |
+
setFlvtoolPath(path: string): FfmpegCommand;
|
370 |
+
availableFilters(callback: FiltersCallback): void;
|
371 |
+
getAvailableFilters(callback: FiltersCallback): void;
|
372 |
+
availableCodecs(callback: CodecsCallback): void;
|
373 |
+
getAvailableCodecs(callback: CodecsCallback): void;
|
374 |
+
availableEncoders(callback: EncodersCallback): void;
|
375 |
+
getAvailableEncoders(callback: EncodersCallback): void;
|
376 |
+
availableFormats(callback: FormatsCallback): void;
|
377 |
+
getAvailableFormats(callback: FormatsCallback): void;
|
378 |
+
|
379 |
+
// ffprobe
|
380 |
+
ffprobe(callback: (err: any, data: FfprobeData) => void): void;
|
381 |
+
ffprobe(index: number, callback: (err: any, data: FfprobeData) => void): void;
|
382 |
+
ffprobe(options: string[], callback: (err: any, data: FfprobeData) => void): void; // tslint:disable-line unified-signatures
|
383 |
+
ffprobe(index: number, options: string[], callback: (err: any, data: FfprobeData) => void): void;
|
384 |
+
|
385 |
+
// event listeners
|
386 |
+
/**
|
387 |
+
* Emitted just after ffmpeg has been spawned.
|
388 |
+
*
|
389 |
+
* @event FfmpegCommand#start
|
390 |
+
* @param command ffmpeg command line
|
391 |
+
*/
|
392 |
+
on(event: "start", listener: (command: string) => void): this;
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Emitted when ffmpeg reports progress information
|
396 |
+
*
|
397 |
+
* @event FfmpegCommand#progress
|
398 |
+
* @param progress progress object
|
399 |
+
* @param progress.frames number of frames transcoded
|
400 |
+
* @param progress.currentFps current processing speed in frames per second
|
401 |
+
* @param progress.currentKbps current output generation speed in kilobytes per second
|
402 |
+
* @param progress.targetSize current output file size
|
403 |
+
* @param progress.timemark current video timemark
|
404 |
+
* @param [progress.percent] processing progress (may not be available depending on input)
|
405 |
+
*/
|
406 |
+
on(
|
407 |
+
event: "progress",
|
408 |
+
listener: (progress: {
|
409 |
+
frames: number;
|
410 |
+
currentFps: number;
|
411 |
+
currentKbps: number;
|
412 |
+
targetSize: number;
|
413 |
+
timemark: string;
|
414 |
+
percent?: number | undefined;
|
415 |
+
}) => void,
|
416 |
+
): this;
|
417 |
+
|
418 |
+
/**
|
419 |
+
* Emitted when ffmpeg outputs to stderr
|
420 |
+
*
|
421 |
+
* @event FfmpegCommand#stderr
|
422 |
+
* @param line stderr output line
|
423 |
+
*/
|
424 |
+
on(event: "stderr", listener: (line: string) => void): this;
|
425 |
+
|
426 |
+
/**
|
427 |
+
* Emitted when ffmpeg reports input codec data
|
428 |
+
*
|
429 |
+
* @event FfmpegCommand#codecData
|
430 |
+
* @param codecData codec data object
|
431 |
+
* @param codecData.format input format name
|
432 |
+
* @param codecData.audio input audio codec name
|
433 |
+
* @param codecData.audio_details input audio codec parameters
|
434 |
+
* @param codecData.video input video codec name
|
435 |
+
* @param codecData.video_details input video codec parameters
|
436 |
+
* @param codecData.duration input video duration
|
437 |
+
*/
|
438 |
+
on(
|
439 |
+
event: "codecData",
|
440 |
+
listener: (codecData: {
|
441 |
+
format: string;
|
442 |
+
audio: string;
|
443 |
+
audio_details: string[];
|
444 |
+
video: string;
|
445 |
+
video_details: string[];
|
446 |
+
duration: string;
|
447 |
+
}) => void,
|
448 |
+
): this;
|
449 |
+
|
450 |
+
/**
|
451 |
+
* Emitted when an error happens when preparing or running a command
|
452 |
+
*
|
453 |
+
* @event FfmpegCommand#error
|
454 |
+
* @param error error object, with optional properties 'inputStreamError' / 'outputStreamError' for errors on their respective streams
|
455 |
+
* @param stdout ffmpeg stdout, unless outputting to a stream
|
456 |
+
* @param stderr ffmpeg stderr
|
457 |
+
*/
|
458 |
+
on(event: "error", listener: (error: Error, stdout: string | null, stderr: string | null) => void): this;
|
459 |
+
|
460 |
+
/**
|
461 |
+
* Emitted when a taking screenshots
|
462 |
+
*
|
463 |
+
* @event FfmpegCommand#filenames
|
464 |
+
* @param filenames generated filenames when taking screenshots
|
465 |
+
*/
|
466 |
+
on(event: "filenames", listener: (filenames: string[]) => void): this;
|
467 |
+
|
468 |
+
/**
|
469 |
+
* Emitted when a command finishes processing
|
470 |
+
*
|
471 |
+
* @event FfmpegCommand#end
|
472 |
+
* @param stdout ffmpeg stdout when not outputting to a stream, null otherwise
|
473 |
+
* @param stderr ffmpeg stderr
|
474 |
+
*/
|
475 |
+
on(event: "end", listener: (stdout: string | null, stderr: string | null) => void): this;
|
476 |
+
|
477 |
+
// recipes
|
478 |
+
saveToFile(output: string): FfmpegCommand;
|
479 |
+
save(output: string): FfmpegCommand;
|
480 |
+
writeToStream(stream: stream.Writable, options?: { end?: boolean | undefined }): stream.Writable;
|
481 |
+
pipe(stream?: stream.Writable, options?: { end?: boolean | undefined }): stream.Writable | stream.PassThrough;
|
482 |
+
stream(stream: stream.Writable, options?: { end?: boolean | undefined }): stream.Writable;
|
483 |
+
takeScreenshots(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
|
484 |
+
thumbnail(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
|
485 |
+
thumbnails(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
|
486 |
+
screenshot(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
|
487 |
+
screenshots(config: number | ScreenshotsConfig, folder?: string): FfmpegCommand;
|
488 |
+
mergeToFile(target: string | stream.Writable, tmpFolder: string): FfmpegCommand;
|
489 |
+
concatenate(target: string | stream.Writable, options?: { end?: boolean | undefined }): FfmpegCommand;
|
490 |
+
concat(target: string | stream.Writable, options?: { end?: boolean | undefined }): FfmpegCommand;
|
491 |
+
clone(): FfmpegCommand;
|
492 |
+
run(): void;
|
493 |
+
}
|
494 |
+
|
495 |
+
function ffprobe(file: string, callback: (err: any, data: FfprobeData) => void): void;
|
496 |
+
function ffprobe(file: string, index: number, callback: (err: any, data: FfprobeData) => void): void;
|
497 |
+
function ffprobe(file: string, options: string[], callback: (err: any, data: FfprobeData) => void): void; // tslint:disable-line unified-signatures
|
498 |
+
function ffprobe(
|
499 |
+
file: string,
|
500 |
+
index: number,
|
501 |
+
options: string[],
|
502 |
+
callback: (err: any, data: FfprobeData) => void,
|
503 |
+
): void;
|
504 |
+
}
|
505 |
+
declare function Ffmpeg(options?: Ffmpeg.FfmpegCommandOptions): Ffmpeg.FfmpegCommand;
|
506 |
+
declare function Ffmpeg(input?: string | stream.Readable, options?: Ffmpeg.FfmpegCommandOptions): Ffmpeg.FfmpegCommand;
|
507 |
+
|
508 |
+
export = Ffmpeg;
|
clone/node_modules/@types/fluent-ffmpeg/package.json
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@types/fluent-ffmpeg",
|
3 |
+
"version": "2.1.27",
|
4 |
+
"description": "TypeScript definitions for fluent-ffmpeg",
|
5 |
+
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/fluent-ffmpeg",
|
6 |
+
"license": "MIT",
|
7 |
+
"contributors": [
|
8 |
+
{
|
9 |
+
"name": "KIM Jaesuck a.k.a. gim tcaesvk",
|
10 |
+
"githubUsername": "tcaesvk",
|
11 |
+
"url": "https://github.com/tcaesvk"
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"name": "DingWeizhe",
|
15 |
+
"githubUsername": "DingWeizhe",
|
16 |
+
"url": "https://github.com/DingWeizhe"
|
17 |
+
},
|
18 |
+
{
|
19 |
+
"name": "Mounir Abid",
|
20 |
+
"githubUsername": "mabidina",
|
21 |
+
"url": "https://github.com/mabidina"
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"name": "Doyoung Ha",
|
25 |
+
"githubUsername": "hados99",
|
26 |
+
"url": "https://github.com/hados99"
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"name": "Prasad Nayak",
|
30 |
+
"githubUsername": "buzzertech",
|
31 |
+
"url": "https://github.com/buzzertech"
|
32 |
+
}
|
33 |
+
],
|
34 |
+
"main": "",
|
35 |
+
"types": "index.d.ts",
|
36 |
+
"repository": {
|
37 |
+
"type": "git",
|
38 |
+
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
39 |
+
"directory": "types/fluent-ffmpeg"
|
40 |
+
},
|
41 |
+
"scripts": {},
|
42 |
+
"dependencies": {
|
43 |
+
"@types/node": "*"
|
44 |
+
},
|
45 |
+
"peerDependencies": {},
|
46 |
+
"typesPublisherContentHash": "d4b5f12a5ceab07664481cac21a1d61a55eeadf6bbb95f0ba5f4875918d102d1",
|
47 |
+
"typeScriptVersion": "4.8"
|
48 |
+
}
|
clone/node_modules/@types/node/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) Microsoft Corporation.
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE
|
clone/node_modules/@types/node/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Installation
|
2 |
+
> `npm install --save @types/node`
|
3 |
+
|
4 |
+
# Summary
|
5 |
+
This package contains type definitions for node (https://nodejs.org/).
|
6 |
+
|
7 |
+
# Details
|
8 |
+
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
|
9 |
+
|
10 |
+
### Additional Details
|
11 |
+
* Last updated: Thu, 23 Jan 2025 18:02:27 GMT
|
12 |
+
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)
|
13 |
+
|
14 |
+
# Credits
|
15 |
+
These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [Alberto Schiabel](https://github.com/jkomyno), [Alvis HT Tang](https://github.com/alvis), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [Chigozirim C.](https://github.com/smac89), [David Junger](https://github.com/touffy), [Deividas Bakanas](https://github.com/DeividasBakanas), [Eugene Y. Q. Shen](https://github.com/eyqs), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Huw](https://github.com/hoo29), [Kelvin Jin](https://github.com/kjin), [Klaus Meinhardt](https://github.com/ajafff), [Lishude](https://github.com/islishude), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [Mohsen Azimi](https://github.com/mohsen1), [Nikita Galkin](https://github.com/galkin), [Parambir Singh](https://github.com/parambirs), [Sebastian Silbermann](https://github.com/eps1lon), [Thomas den Hollander](https://github.com/ThomasdenH), [Wilco Bakker](https://github.com/WilcoBakker), [wwwy3y3](https://github.com/wwwy3y3), [Samuel Ainsworth](https://github.com/samuela), [Kyle Uehlein](https://github.com/kuehlein), [Thanik Bhongbhibhat](https://github.com/bhongy), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), [ExE Boss](https://github.com/ExE-Boss), [Piotr Błażejewicz](https://github.com/peterblazejewicz), [Anna Henningsen](https://github.com/addaleax), [Victor Perin](https://github.com/victorperin), [NodeJS Contributors](https://github.com/NodeJS), [Linus Unnebäck](https://github.com/LinusU), [wafuwafu13](https://github.com/wafuwafu13), [Matteo Collina](https://github.com/mcollina), and [Dmitry Semigradsky](https://github.com/Semigradsky).
|
clone/node_modules/@types/node/assert.d.ts
ADDED
@@ -0,0 +1,1040 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* The `node:assert` module provides a set of assertion functions for verifying
|
3 |
+
* invariants.
|
4 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/assert.js)
|
5 |
+
*/
|
6 |
+
declare module "assert" {
|
7 |
+
/**
|
8 |
+
* An alias of {@link ok}.
|
9 |
+
* @since v0.5.9
|
10 |
+
* @param value The input that is checked for being truthy.
|
11 |
+
*/
|
12 |
+
function assert(value: unknown, message?: string | Error): asserts value;
|
13 |
+
namespace assert {
|
14 |
+
/**
|
15 |
+
* Indicates the failure of an assertion. All errors thrown by the `node:assert` module will be instances of the `AssertionError` class.
|
16 |
+
*/
|
17 |
+
class AssertionError extends Error {
|
18 |
+
/**
|
19 |
+
* Set to the `actual` argument for methods such as {@link assert.strictEqual()}.
|
20 |
+
*/
|
21 |
+
actual: unknown;
|
22 |
+
/**
|
23 |
+
* Set to the `expected` argument for methods such as {@link assert.strictEqual()}.
|
24 |
+
*/
|
25 |
+
expected: unknown;
|
26 |
+
/**
|
27 |
+
* Set to the passed in operator value.
|
28 |
+
*/
|
29 |
+
operator: string;
|
30 |
+
/**
|
31 |
+
* Indicates if the message was auto-generated (`true`) or not.
|
32 |
+
*/
|
33 |
+
generatedMessage: boolean;
|
34 |
+
/**
|
35 |
+
* Value is always `ERR_ASSERTION` to show that the error is an assertion error.
|
36 |
+
*/
|
37 |
+
code: "ERR_ASSERTION";
|
38 |
+
constructor(options?: {
|
39 |
+
/** If provided, the error message is set to this value. */
|
40 |
+
message?: string | undefined;
|
41 |
+
/** The `actual` property on the error instance. */
|
42 |
+
actual?: unknown | undefined;
|
43 |
+
/** The `expected` property on the error instance. */
|
44 |
+
expected?: unknown | undefined;
|
45 |
+
/** The `operator` property on the error instance. */
|
46 |
+
operator?: string | undefined;
|
47 |
+
/** If provided, the generated stack trace omits frames before this function. */
|
48 |
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
49 |
+
stackStartFn?: Function | undefined;
|
50 |
+
});
|
51 |
+
}
|
52 |
+
/**
|
53 |
+
* This feature is deprecated and will be removed in a future version.
|
54 |
+
* Please consider using alternatives such as the `mock` helper function.
|
55 |
+
* @since v14.2.0, v12.19.0
|
56 |
+
* @deprecated Deprecated
|
57 |
+
*/
|
58 |
+
class CallTracker {
|
59 |
+
/**
|
60 |
+
* The wrapper function is expected to be called exactly `exact` times. If the
|
61 |
+
* function has not been called exactly `exact` times when `tracker.verify()` is called, then `tracker.verify()` will throw an
|
62 |
+
* error.
|
63 |
+
*
|
64 |
+
* ```js
|
65 |
+
* import assert from 'node:assert';
|
66 |
+
*
|
67 |
+
* // Creates call tracker.
|
68 |
+
* const tracker = new assert.CallTracker();
|
69 |
+
*
|
70 |
+
* function func() {}
|
71 |
+
*
|
72 |
+
* // Returns a function that wraps func() that must be called exact times
|
73 |
+
* // before tracker.verify().
|
74 |
+
* const callsfunc = tracker.calls(func);
|
75 |
+
* ```
|
76 |
+
* @since v14.2.0, v12.19.0
|
77 |
+
* @param [fn='A no-op function']
|
78 |
+
* @param [exact=1]
|
79 |
+
* @return A function that wraps `fn`.
|
80 |
+
*/
|
81 |
+
calls(exact?: number): () => void;
|
82 |
+
calls<Func extends (...args: any[]) => any>(fn?: Func, exact?: number): Func;
|
83 |
+
/**
|
84 |
+
* Example:
|
85 |
+
*
|
86 |
+
* ```js
|
87 |
+
* import assert from 'node:assert';
|
88 |
+
*
|
89 |
+
* const tracker = new assert.CallTracker();
|
90 |
+
*
|
91 |
+
* function func() {}
|
92 |
+
* const callsfunc = tracker.calls(func);
|
93 |
+
* callsfunc(1, 2, 3);
|
94 |
+
*
|
95 |
+
* assert.deepStrictEqual(tracker.getCalls(callsfunc),
|
96 |
+
* [{ thisArg: undefined, arguments: [1, 2, 3] }]);
|
97 |
+
* ```
|
98 |
+
* @since v18.8.0, v16.18.0
|
99 |
+
* @return An array with all the calls to a tracked function.
|
100 |
+
*/
|
101 |
+
getCalls(fn: Function): CallTrackerCall[];
|
102 |
+
/**
|
103 |
+
* The arrays contains information about the expected and actual number of calls of
|
104 |
+
* the functions that have not been called the expected number of times.
|
105 |
+
*
|
106 |
+
* ```js
|
107 |
+
* import assert from 'node:assert';
|
108 |
+
*
|
109 |
+
* // Creates call tracker.
|
110 |
+
* const tracker = new assert.CallTracker();
|
111 |
+
*
|
112 |
+
* function func() {}
|
113 |
+
*
|
114 |
+
* // Returns a function that wraps func() that must be called exact times
|
115 |
+
* // before tracker.verify().
|
116 |
+
* const callsfunc = tracker.calls(func, 2);
|
117 |
+
*
|
118 |
+
* // Returns an array containing information on callsfunc()
|
119 |
+
* console.log(tracker.report());
|
120 |
+
* // [
|
121 |
+
* // {
|
122 |
+
* // message: 'Expected the func function to be executed 2 time(s) but was
|
123 |
+
* // executed 0 time(s).',
|
124 |
+
* // actual: 0,
|
125 |
+
* // expected: 2,
|
126 |
+
* // operator: 'func',
|
127 |
+
* // stack: stack trace
|
128 |
+
* // }
|
129 |
+
* // ]
|
130 |
+
* ```
|
131 |
+
* @since v14.2.0, v12.19.0
|
132 |
+
* @return An array of objects containing information about the wrapper functions returned by {@link tracker.calls()}.
|
133 |
+
*/
|
134 |
+
report(): CallTrackerReportInformation[];
|
135 |
+
/**
|
136 |
+
* Reset calls of the call tracker. If a tracked function is passed as an argument, the calls will be reset for it.
|
137 |
+
* If no arguments are passed, all tracked functions will be reset.
|
138 |
+
*
|
139 |
+
* ```js
|
140 |
+
* import assert from 'node:assert';
|
141 |
+
*
|
142 |
+
* const tracker = new assert.CallTracker();
|
143 |
+
*
|
144 |
+
* function func() {}
|
145 |
+
* const callsfunc = tracker.calls(func);
|
146 |
+
*
|
147 |
+
* callsfunc();
|
148 |
+
* // Tracker was called once
|
149 |
+
* assert.strictEqual(tracker.getCalls(callsfunc).length, 1);
|
150 |
+
*
|
151 |
+
* tracker.reset(callsfunc);
|
152 |
+
* assert.strictEqual(tracker.getCalls(callsfunc).length, 0);
|
153 |
+
* ```
|
154 |
+
* @since v18.8.0, v16.18.0
|
155 |
+
* @param fn a tracked function to reset.
|
156 |
+
*/
|
157 |
+
reset(fn?: Function): void;
|
158 |
+
/**
|
159 |
+
* Iterates through the list of functions passed to {@link tracker.calls()} and will throw an error for functions that
|
160 |
+
* have not been called the expected number of times.
|
161 |
+
*
|
162 |
+
* ```js
|
163 |
+
* import assert from 'node:assert';
|
164 |
+
*
|
165 |
+
* // Creates call tracker.
|
166 |
+
* const tracker = new assert.CallTracker();
|
167 |
+
*
|
168 |
+
* function func() {}
|
169 |
+
*
|
170 |
+
* // Returns a function that wraps func() that must be called exact times
|
171 |
+
* // before tracker.verify().
|
172 |
+
* const callsfunc = tracker.calls(func, 2);
|
173 |
+
*
|
174 |
+
* callsfunc();
|
175 |
+
*
|
176 |
+
* // Will throw an error since callsfunc() was only called once.
|
177 |
+
* tracker.verify();
|
178 |
+
* ```
|
179 |
+
* @since v14.2.0, v12.19.0
|
180 |
+
*/
|
181 |
+
verify(): void;
|
182 |
+
}
|
183 |
+
interface CallTrackerCall {
|
184 |
+
thisArg: object;
|
185 |
+
arguments: unknown[];
|
186 |
+
}
|
187 |
+
interface CallTrackerReportInformation {
|
188 |
+
message: string;
|
189 |
+
/** The actual number of times the function was called. */
|
190 |
+
actual: number;
|
191 |
+
/** The number of times the function was expected to be called. */
|
192 |
+
expected: number;
|
193 |
+
/** The name of the function that is wrapped. */
|
194 |
+
operator: string;
|
195 |
+
/** A stack trace of the function. */
|
196 |
+
stack: object;
|
197 |
+
}
|
198 |
+
type AssertPredicate = RegExp | (new() => object) | ((thrown: unknown) => boolean) | object | Error;
|
199 |
+
/**
|
200 |
+
* Throws an `AssertionError` with the provided error message or a default
|
201 |
+
* error message. If the `message` parameter is an instance of an `Error` then
|
202 |
+
* it will be thrown instead of the `AssertionError`.
|
203 |
+
*
|
204 |
+
* ```js
|
205 |
+
* import assert from 'node:assert/strict';
|
206 |
+
*
|
207 |
+
* assert.fail();
|
208 |
+
* // AssertionError [ERR_ASSERTION]: Failed
|
209 |
+
*
|
210 |
+
* assert.fail('boom');
|
211 |
+
* // AssertionError [ERR_ASSERTION]: boom
|
212 |
+
*
|
213 |
+
* assert.fail(new TypeError('need array'));
|
214 |
+
* // TypeError: need array
|
215 |
+
* ```
|
216 |
+
*
|
217 |
+
* Using `assert.fail()` with more than two arguments is possible but deprecated.
|
218 |
+
* See below for further details.
|
219 |
+
* @since v0.1.21
|
220 |
+
* @param [message='Failed']
|
221 |
+
*/
|
222 |
+
function fail(message?: string | Error): never;
|
223 |
+
/** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
|
224 |
+
function fail(
|
225 |
+
actual: unknown,
|
226 |
+
expected: unknown,
|
227 |
+
message?: string | Error,
|
228 |
+
operator?: string,
|
229 |
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
230 |
+
stackStartFn?: Function,
|
231 |
+
): never;
|
232 |
+
/**
|
233 |
+
* Tests if `value` is truthy. It is equivalent to `assert.equal(!!value, true, message)`.
|
234 |
+
*
|
235 |
+
* If `value` is not truthy, an `AssertionError` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is `undefined`, a default
|
236 |
+
* error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
237 |
+
* If no arguments are passed in at all `message` will be set to the string:`` 'No value argument passed to `assert.ok()`' ``.
|
238 |
+
*
|
239 |
+
* Be aware that in the `repl` the error message will be different to the one
|
240 |
+
* thrown in a file! See below for further details.
|
241 |
+
*
|
242 |
+
* ```js
|
243 |
+
* import assert from 'node:assert/strict';
|
244 |
+
*
|
245 |
+
* assert.ok(true);
|
246 |
+
* // OK
|
247 |
+
* assert.ok(1);
|
248 |
+
* // OK
|
249 |
+
*
|
250 |
+
* assert.ok();
|
251 |
+
* // AssertionError: No value argument passed to `assert.ok()`
|
252 |
+
*
|
253 |
+
* assert.ok(false, 'it\'s false');
|
254 |
+
* // AssertionError: it's false
|
255 |
+
*
|
256 |
+
* // In the repl:
|
257 |
+
* assert.ok(typeof 123 === 'string');
|
258 |
+
* // AssertionError: false == true
|
259 |
+
*
|
260 |
+
* // In a file (e.g. test.js):
|
261 |
+
* assert.ok(typeof 123 === 'string');
|
262 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
263 |
+
* //
|
264 |
+
* // assert.ok(typeof 123 === 'string')
|
265 |
+
*
|
266 |
+
* assert.ok(false);
|
267 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
268 |
+
* //
|
269 |
+
* // assert.ok(false)
|
270 |
+
*
|
271 |
+
* assert.ok(0);
|
272 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
273 |
+
* //
|
274 |
+
* // assert.ok(0)
|
275 |
+
* ```
|
276 |
+
*
|
277 |
+
* ```js
|
278 |
+
* import assert from 'node:assert/strict';
|
279 |
+
*
|
280 |
+
* // Using `assert()` works the same:
|
281 |
+
* assert(0);
|
282 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
283 |
+
* //
|
284 |
+
* // assert(0)
|
285 |
+
* ```
|
286 |
+
* @since v0.1.21
|
287 |
+
*/
|
288 |
+
function ok(value: unknown, message?: string | Error): asserts value;
|
289 |
+
/**
|
290 |
+
* **Strict assertion mode**
|
291 |
+
*
|
292 |
+
* An alias of {@link strictEqual}.
|
293 |
+
*
|
294 |
+
* **Legacy assertion mode**
|
295 |
+
*
|
296 |
+
* > Stability: 3 - Legacy: Use {@link strictEqual} instead.
|
297 |
+
*
|
298 |
+
* Tests shallow, coercive equality between the `actual` and `expected` parameters
|
299 |
+
* using the [`==` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality). `NaN` is specially handled
|
300 |
+
* and treated as being identical if both sides are `NaN`.
|
301 |
+
*
|
302 |
+
* ```js
|
303 |
+
* import assert from 'node:assert';
|
304 |
+
*
|
305 |
+
* assert.equal(1, 1);
|
306 |
+
* // OK, 1 == 1
|
307 |
+
* assert.equal(1, '1');
|
308 |
+
* // OK, 1 == '1'
|
309 |
+
* assert.equal(NaN, NaN);
|
310 |
+
* // OK
|
311 |
+
*
|
312 |
+
* assert.equal(1, 2);
|
313 |
+
* // AssertionError: 1 == 2
|
314 |
+
* assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
|
315 |
+
* // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
|
316 |
+
* ```
|
317 |
+
*
|
318 |
+
* If the values are not equal, an `AssertionError` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default
|
319 |
+
* error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
320 |
+
* @since v0.1.21
|
321 |
+
*/
|
322 |
+
function equal(actual: unknown, expected: unknown, message?: string | Error): void;
|
323 |
+
/**
|
324 |
+
* **Strict assertion mode**
|
325 |
+
*
|
326 |
+
* An alias of {@link notStrictEqual}.
|
327 |
+
*
|
328 |
+
* **Legacy assertion mode**
|
329 |
+
*
|
330 |
+
* > Stability: 3 - Legacy: Use {@link notStrictEqual} instead.
|
331 |
+
*
|
332 |
+
* Tests shallow, coercive inequality with the [`!=` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality). `NaN` is
|
333 |
+
* specially handled and treated as being identical if both sides are `NaN`.
|
334 |
+
*
|
335 |
+
* ```js
|
336 |
+
* import assert from 'node:assert';
|
337 |
+
*
|
338 |
+
* assert.notEqual(1, 2);
|
339 |
+
* // OK
|
340 |
+
*
|
341 |
+
* assert.notEqual(1, 1);
|
342 |
+
* // AssertionError: 1 != 1
|
343 |
+
*
|
344 |
+
* assert.notEqual(1, '1');
|
345 |
+
* // AssertionError: 1 != '1'
|
346 |
+
* ```
|
347 |
+
*
|
348 |
+
* If the values are equal, an `AssertionError` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default error
|
349 |
+
* message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
350 |
+
* @since v0.1.21
|
351 |
+
*/
|
352 |
+
function notEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
353 |
+
/**
|
354 |
+
* **Strict assertion mode**
|
355 |
+
*
|
356 |
+
* An alias of {@link deepStrictEqual}.
|
357 |
+
*
|
358 |
+
* **Legacy assertion mode**
|
359 |
+
*
|
360 |
+
* > Stability: 3 - Legacy: Use {@link deepStrictEqual} instead.
|
361 |
+
*
|
362 |
+
* Tests for deep equality between the `actual` and `expected` parameters. Consider
|
363 |
+
* using {@link deepStrictEqual} instead. {@link deepEqual} can have
|
364 |
+
* surprising results.
|
365 |
+
*
|
366 |
+
* _Deep equality_ means that the enumerable "own" properties of child objects
|
367 |
+
* are also recursively evaluated by the following rules.
|
368 |
+
* @since v0.1.21
|
369 |
+
*/
|
370 |
+
function deepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
371 |
+
/**
|
372 |
+
* **Strict assertion mode**
|
373 |
+
*
|
374 |
+
* An alias of {@link notDeepStrictEqual}.
|
375 |
+
*
|
376 |
+
* **Legacy assertion mode**
|
377 |
+
*
|
378 |
+
* > Stability: 3 - Legacy: Use {@link notDeepStrictEqual} instead.
|
379 |
+
*
|
380 |
+
* Tests for any deep inequality. Opposite of {@link deepEqual}.
|
381 |
+
*
|
382 |
+
* ```js
|
383 |
+
* import assert from 'node:assert';
|
384 |
+
*
|
385 |
+
* const obj1 = {
|
386 |
+
* a: {
|
387 |
+
* b: 1,
|
388 |
+
* },
|
389 |
+
* };
|
390 |
+
* const obj2 = {
|
391 |
+
* a: {
|
392 |
+
* b: 2,
|
393 |
+
* },
|
394 |
+
* };
|
395 |
+
* const obj3 = {
|
396 |
+
* a: {
|
397 |
+
* b: 1,
|
398 |
+
* },
|
399 |
+
* };
|
400 |
+
* const obj4 = { __proto__: obj1 };
|
401 |
+
*
|
402 |
+
* assert.notDeepEqual(obj1, obj1);
|
403 |
+
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
404 |
+
*
|
405 |
+
* assert.notDeepEqual(obj1, obj2);
|
406 |
+
* // OK
|
407 |
+
*
|
408 |
+
* assert.notDeepEqual(obj1, obj3);
|
409 |
+
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
410 |
+
*
|
411 |
+
* assert.notDeepEqual(obj1, obj4);
|
412 |
+
* // OK
|
413 |
+
* ```
|
414 |
+
*
|
415 |
+
* If the values are deeply equal, an `AssertionError` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a default
|
416 |
+
* error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown
|
417 |
+
* instead of the `AssertionError`.
|
418 |
+
* @since v0.1.21
|
419 |
+
*/
|
420 |
+
function notDeepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
421 |
+
/**
|
422 |
+
* Tests strict equality between the `actual` and `expected` parameters as
|
423 |
+
* determined by [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
424 |
+
*
|
425 |
+
* ```js
|
426 |
+
* import assert from 'node:assert/strict';
|
427 |
+
*
|
428 |
+
* assert.strictEqual(1, 2);
|
429 |
+
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
430 |
+
* //
|
431 |
+
* // 1 !== 2
|
432 |
+
*
|
433 |
+
* assert.strictEqual(1, 1);
|
434 |
+
* // OK
|
435 |
+
*
|
436 |
+
* assert.strictEqual('Hello foobar', 'Hello World!');
|
437 |
+
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
438 |
+
* // + actual - expected
|
439 |
+
* //
|
440 |
+
* // + 'Hello foobar'
|
441 |
+
* // - 'Hello World!'
|
442 |
+
* // ^
|
443 |
+
*
|
444 |
+
* const apples = 1;
|
445 |
+
* const oranges = 2;
|
446 |
+
* assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`);
|
447 |
+
* // AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2
|
448 |
+
*
|
449 |
+
* assert.strictEqual(1, '1', new TypeError('Inputs are not identical'));
|
450 |
+
* // TypeError: Inputs are not identical
|
451 |
+
* ```
|
452 |
+
*
|
453 |
+
* If the values are not strictly equal, an `AssertionError` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a
|
454 |
+
* default error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown
|
455 |
+
* instead of the `AssertionError`.
|
456 |
+
* @since v0.1.21
|
457 |
+
*/
|
458 |
+
function strictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
459 |
+
/**
|
460 |
+
* Tests strict inequality between the `actual` and `expected` parameters as
|
461 |
+
* determined by [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
462 |
+
*
|
463 |
+
* ```js
|
464 |
+
* import assert from 'node:assert/strict';
|
465 |
+
*
|
466 |
+
* assert.notStrictEqual(1, 2);
|
467 |
+
* // OK
|
468 |
+
*
|
469 |
+
* assert.notStrictEqual(1, 1);
|
470 |
+
* // AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to:
|
471 |
+
* //
|
472 |
+
* // 1
|
473 |
+
*
|
474 |
+
* assert.notStrictEqual(1, '1');
|
475 |
+
* // OK
|
476 |
+
* ```
|
477 |
+
*
|
478 |
+
* If the values are strictly equal, an `AssertionError` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is undefined, a
|
479 |
+
* default error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown
|
480 |
+
* instead of the `AssertionError`.
|
481 |
+
* @since v0.1.21
|
482 |
+
*/
|
483 |
+
function notStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
484 |
+
/**
|
485 |
+
* Tests for deep equality between the `actual` and `expected` parameters.
|
486 |
+
* "Deep" equality means that the enumerable "own" properties of child objects
|
487 |
+
* are recursively evaluated also by the following rules.
|
488 |
+
* @since v1.2.0
|
489 |
+
*/
|
490 |
+
function deepStrictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
491 |
+
/**
|
492 |
+
* Tests for deep strict inequality. Opposite of {@link deepStrictEqual}.
|
493 |
+
*
|
494 |
+
* ```js
|
495 |
+
* import assert from 'node:assert/strict';
|
496 |
+
*
|
497 |
+
* assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
|
498 |
+
* // OK
|
499 |
+
* ```
|
500 |
+
*
|
501 |
+
* If the values are deeply and strictly equal, an `AssertionError` is thrown
|
502 |
+
* with a `message` property set equal to the value of the `message` parameter. If
|
503 |
+
* the `message` parameter is undefined, a default error message is assigned. If
|
504 |
+
* the `message` parameter is an instance of an `Error` then it will be thrown
|
505 |
+
* instead of the `AssertionError`.
|
506 |
+
* @since v1.2.0
|
507 |
+
*/
|
508 |
+
function notDeepStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
509 |
+
/**
|
510 |
+
* Expects the function `fn` to throw an error.
|
511 |
+
*
|
512 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
513 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
|
514 |
+
* a validation object where each property will be tested for strict deep equality,
|
515 |
+
* or an instance of error where each property will be tested for strict deep
|
516 |
+
* equality including the non-enumerable `message` and `name` properties. When
|
517 |
+
* using an object, it is also possible to use a regular expression, when
|
518 |
+
* validating against a string property. See below for examples.
|
519 |
+
*
|
520 |
+
* If specified, `message` will be appended to the message provided by the `AssertionError` if the `fn` call fails to throw or in case the error validation
|
521 |
+
* fails.
|
522 |
+
*
|
523 |
+
* Custom validation object/error instance:
|
524 |
+
*
|
525 |
+
* ```js
|
526 |
+
* import assert from 'node:assert/strict';
|
527 |
+
*
|
528 |
+
* const err = new TypeError('Wrong value');
|
529 |
+
* err.code = 404;
|
530 |
+
* err.foo = 'bar';
|
531 |
+
* err.info = {
|
532 |
+
* nested: true,
|
533 |
+
* baz: 'text',
|
534 |
+
* };
|
535 |
+
* err.reg = /abc/i;
|
536 |
+
*
|
537 |
+
* assert.throws(
|
538 |
+
* () => {
|
539 |
+
* throw err;
|
540 |
+
* },
|
541 |
+
* {
|
542 |
+
* name: 'TypeError',
|
543 |
+
* message: 'Wrong value',
|
544 |
+
* info: {
|
545 |
+
* nested: true,
|
546 |
+
* baz: 'text',
|
547 |
+
* },
|
548 |
+
* // Only properties on the validation object will be tested for.
|
549 |
+
* // Using nested objects requires all properties to be present. Otherwise
|
550 |
+
* // the validation is going to fail.
|
551 |
+
* },
|
552 |
+
* );
|
553 |
+
*
|
554 |
+
* // Using regular expressions to validate error properties:
|
555 |
+
* assert.throws(
|
556 |
+
* () => {
|
557 |
+
* throw err;
|
558 |
+
* },
|
559 |
+
* {
|
560 |
+
* // The `name` and `message` properties are strings and using regular
|
561 |
+
* // expressions on those will match against the string. If they fail, an
|
562 |
+
* // error is thrown.
|
563 |
+
* name: /^TypeError$/,
|
564 |
+
* message: /Wrong/,
|
565 |
+
* foo: 'bar',
|
566 |
+
* info: {
|
567 |
+
* nested: true,
|
568 |
+
* // It is not possible to use regular expressions for nested properties!
|
569 |
+
* baz: 'text',
|
570 |
+
* },
|
571 |
+
* // The `reg` property contains a regular expression and only if the
|
572 |
+
* // validation object contains an identical regular expression, it is going
|
573 |
+
* // to pass.
|
574 |
+
* reg: /abc/i,
|
575 |
+
* },
|
576 |
+
* );
|
577 |
+
*
|
578 |
+
* // Fails due to the different `message` and `name` properties:
|
579 |
+
* assert.throws(
|
580 |
+
* () => {
|
581 |
+
* const otherErr = new Error('Not found');
|
582 |
+
* // Copy all enumerable properties from `err` to `otherErr`.
|
583 |
+
* for (const [key, value] of Object.entries(err)) {
|
584 |
+
* otherErr[key] = value;
|
585 |
+
* }
|
586 |
+
* throw otherErr;
|
587 |
+
* },
|
588 |
+
* // The error's `message` and `name` properties will also be checked when using
|
589 |
+
* // an error as validation object.
|
590 |
+
* err,
|
591 |
+
* );
|
592 |
+
* ```
|
593 |
+
*
|
594 |
+
* Validate instanceof using constructor:
|
595 |
+
*
|
596 |
+
* ```js
|
597 |
+
* import assert from 'node:assert/strict';
|
598 |
+
*
|
599 |
+
* assert.throws(
|
600 |
+
* () => {
|
601 |
+
* throw new Error('Wrong value');
|
602 |
+
* },
|
603 |
+
* Error,
|
604 |
+
* );
|
605 |
+
* ```
|
606 |
+
*
|
607 |
+
* Validate error message using [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions):
|
608 |
+
*
|
609 |
+
* Using a regular expression runs `.toString` on the error object, and will
|
610 |
+
* therefore also include the error name.
|
611 |
+
*
|
612 |
+
* ```js
|
613 |
+
* import assert from 'node:assert/strict';
|
614 |
+
*
|
615 |
+
* assert.throws(
|
616 |
+
* () => {
|
617 |
+
* throw new Error('Wrong value');
|
618 |
+
* },
|
619 |
+
* /^Error: Wrong value$/,
|
620 |
+
* );
|
621 |
+
* ```
|
622 |
+
*
|
623 |
+
* Custom error validation:
|
624 |
+
*
|
625 |
+
* The function must return `true` to indicate all internal validations passed.
|
626 |
+
* It will otherwise fail with an `AssertionError`.
|
627 |
+
*
|
628 |
+
* ```js
|
629 |
+
* import assert from 'node:assert/strict';
|
630 |
+
*
|
631 |
+
* assert.throws(
|
632 |
+
* () => {
|
633 |
+
* throw new Error('Wrong value');
|
634 |
+
* },
|
635 |
+
* (err) => {
|
636 |
+
* assert(err instanceof Error);
|
637 |
+
* assert(/value/.test(err));
|
638 |
+
* // Avoid returning anything from validation functions besides `true`.
|
639 |
+
* // Otherwise, it's not clear what part of the validation failed. Instead,
|
640 |
+
* // throw an error about the specific validation that failed (as done in this
|
641 |
+
* // example) and add as much helpful debugging information to that error as
|
642 |
+
* // possible.
|
643 |
+
* return true;
|
644 |
+
* },
|
645 |
+
* 'unexpected error',
|
646 |
+
* );
|
647 |
+
* ```
|
648 |
+
*
|
649 |
+
* `error` cannot be a string. If a string is provided as the second
|
650 |
+
* argument, then `error` is assumed to be omitted and the string will be used for `message` instead. This can lead to easy-to-miss mistakes. Using the same
|
651 |
+
* message as the thrown error message is going to result in an `ERR_AMBIGUOUS_ARGUMENT` error. Please read the example below carefully if using
|
652 |
+
* a string as the second argument gets considered:
|
653 |
+
*
|
654 |
+
* ```js
|
655 |
+
* import assert from 'node:assert/strict';
|
656 |
+
*
|
657 |
+
* function throwingFirst() {
|
658 |
+
* throw new Error('First');
|
659 |
+
* }
|
660 |
+
*
|
661 |
+
* function throwingSecond() {
|
662 |
+
* throw new Error('Second');
|
663 |
+
* }
|
664 |
+
*
|
665 |
+
* function notThrowing() {}
|
666 |
+
*
|
667 |
+
* // The second argument is a string and the input function threw an Error.
|
668 |
+
* // The first case will not throw as it does not match for the error message
|
669 |
+
* // thrown by the input function!
|
670 |
+
* assert.throws(throwingFirst, 'Second');
|
671 |
+
* // In the next example the message has no benefit over the message from the
|
672 |
+
* // error and since it is not clear if the user intended to actually match
|
673 |
+
* // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.
|
674 |
+
* assert.throws(throwingSecond, 'Second');
|
675 |
+
* // TypeError [ERR_AMBIGUOUS_ARGUMENT]
|
676 |
+
*
|
677 |
+
* // The string is only used (as message) in case the function does not throw:
|
678 |
+
* assert.throws(notThrowing, 'Second');
|
679 |
+
* // AssertionError [ERR_ASSERTION]: Missing expected exception: Second
|
680 |
+
*
|
681 |
+
* // If it was intended to match for the error message do this instead:
|
682 |
+
* // It does not throw because the error messages match.
|
683 |
+
* assert.throws(throwingSecond, /Second$/);
|
684 |
+
*
|
685 |
+
* // If the error message does not match, an AssertionError is thrown.
|
686 |
+
* assert.throws(throwingFirst, /Second$/);
|
687 |
+
* // AssertionError [ERR_ASSERTION]
|
688 |
+
* ```
|
689 |
+
*
|
690 |
+
* Due to the confusing error-prone notation, avoid a string as the second
|
691 |
+
* argument.
|
692 |
+
* @since v0.1.21
|
693 |
+
*/
|
694 |
+
function throws(block: () => unknown, message?: string | Error): void;
|
695 |
+
function throws(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
|
696 |
+
/**
|
697 |
+
* Asserts that the function `fn` does not throw an error.
|
698 |
+
*
|
699 |
+
* Using `assert.doesNotThrow()` is actually not useful because there
|
700 |
+
* is no benefit in catching an error and then rethrowing it. Instead, consider
|
701 |
+
* adding a comment next to the specific code path that should not throw and keep
|
702 |
+
* error messages as expressive as possible.
|
703 |
+
*
|
704 |
+
* When `assert.doesNotThrow()` is called, it will immediately call the `fn` function.
|
705 |
+
*
|
706 |
+
* If an error is thrown and it is the same type as that specified by the `error` parameter, then an `AssertionError` is thrown. If the error is of a
|
707 |
+
* different type, or if the `error` parameter is undefined, the error is
|
708 |
+
* propagated back to the caller.
|
709 |
+
*
|
710 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
711 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), or a validation
|
712 |
+
* function. See {@link throws} for more details.
|
713 |
+
*
|
714 |
+
* The following, for instance, will throw the `TypeError` because there is no
|
715 |
+
* matching error type in the assertion:
|
716 |
+
*
|
717 |
+
* ```js
|
718 |
+
* import assert from 'node:assert/strict';
|
719 |
+
*
|
720 |
+
* assert.doesNotThrow(
|
721 |
+
* () => {
|
722 |
+
* throw new TypeError('Wrong value');
|
723 |
+
* },
|
724 |
+
* SyntaxError,
|
725 |
+
* );
|
726 |
+
* ```
|
727 |
+
*
|
728 |
+
* However, the following will result in an `AssertionError` with the message
|
729 |
+
* 'Got unwanted exception...':
|
730 |
+
*
|
731 |
+
* ```js
|
732 |
+
* import assert from 'node:assert/strict';
|
733 |
+
*
|
734 |
+
* assert.doesNotThrow(
|
735 |
+
* () => {
|
736 |
+
* throw new TypeError('Wrong value');
|
737 |
+
* },
|
738 |
+
* TypeError,
|
739 |
+
* );
|
740 |
+
* ```
|
741 |
+
*
|
742 |
+
* If an `AssertionError` is thrown and a value is provided for the `message` parameter, the value of `message` will be appended to the `AssertionError` message:
|
743 |
+
*
|
744 |
+
* ```js
|
745 |
+
* import assert from 'node:assert/strict';
|
746 |
+
*
|
747 |
+
* assert.doesNotThrow(
|
748 |
+
* () => {
|
749 |
+
* throw new TypeError('Wrong value');
|
750 |
+
* },
|
751 |
+
* /Wrong value/,
|
752 |
+
* 'Whoops',
|
753 |
+
* );
|
754 |
+
* // Throws: AssertionError: Got unwanted exception: Whoops
|
755 |
+
* ```
|
756 |
+
* @since v0.1.21
|
757 |
+
*/
|
758 |
+
function doesNotThrow(block: () => unknown, message?: string | Error): void;
|
759 |
+
function doesNotThrow(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
|
760 |
+
/**
|
761 |
+
* Throws `value` if `value` is not `undefined` or `null`. This is useful when
|
762 |
+
* testing the `error` argument in callbacks. The stack trace contains all frames
|
763 |
+
* from the error passed to `ifError()` including the potential new frames for `ifError()` itself.
|
764 |
+
*
|
765 |
+
* ```js
|
766 |
+
* import assert from 'node:assert/strict';
|
767 |
+
*
|
768 |
+
* assert.ifError(null);
|
769 |
+
* // OK
|
770 |
+
* assert.ifError(0);
|
771 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0
|
772 |
+
* assert.ifError('error');
|
773 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'
|
774 |
+
* assert.ifError(new Error());
|
775 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error
|
776 |
+
*
|
777 |
+
* // Create some random error frames.
|
778 |
+
* let err;
|
779 |
+
* (function errorFrame() {
|
780 |
+
* err = new Error('test error');
|
781 |
+
* })();
|
782 |
+
*
|
783 |
+
* (function ifErrorFrame() {
|
784 |
+
* assert.ifError(err);
|
785 |
+
* })();
|
786 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
|
787 |
+
* // at ifErrorFrame
|
788 |
+
* // at errorFrame
|
789 |
+
* ```
|
790 |
+
* @since v0.1.97
|
791 |
+
*/
|
792 |
+
function ifError(value: unknown): asserts value is null | undefined;
|
793 |
+
/**
|
794 |
+
* Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
|
795 |
+
* calls the function and awaits the returned promise to complete. It will then
|
796 |
+
* check that the promise is rejected.
|
797 |
+
*
|
798 |
+
* If `asyncFn` is a function and it throws an error synchronously, `assert.rejects()` will return a rejected `Promise` with that error. If the
|
799 |
+
* function does not return a promise, `assert.rejects()` will return a rejected `Promise` with an [ERR_INVALID_RETURN_VALUE](https://nodejs.org/docs/latest-v22.x/api/errors.html#err_invalid_return_value)
|
800 |
+
* error. In both cases the error handler is skipped.
|
801 |
+
*
|
802 |
+
* Besides the async nature to await the completion behaves identically to {@link throws}.
|
803 |
+
*
|
804 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
805 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
|
806 |
+
* an object where each property will be tested for, or an instance of error where
|
807 |
+
* each property will be tested for including the non-enumerable `message` and `name` properties.
|
808 |
+
*
|
809 |
+
* If specified, `message` will be the message provided by the `{@link AssertionError}` if the `asyncFn` fails to reject.
|
810 |
+
*
|
811 |
+
* ```js
|
812 |
+
* import assert from 'node:assert/strict';
|
813 |
+
*
|
814 |
+
* await assert.rejects(
|
815 |
+
* async () => {
|
816 |
+
* throw new TypeError('Wrong value');
|
817 |
+
* },
|
818 |
+
* {
|
819 |
+
* name: 'TypeError',
|
820 |
+
* message: 'Wrong value',
|
821 |
+
* },
|
822 |
+
* );
|
823 |
+
* ```
|
824 |
+
*
|
825 |
+
* ```js
|
826 |
+
* import assert from 'node:assert/strict';
|
827 |
+
*
|
828 |
+
* await assert.rejects(
|
829 |
+
* async () => {
|
830 |
+
* throw new TypeError('Wrong value');
|
831 |
+
* },
|
832 |
+
* (err) => {
|
833 |
+
* assert.strictEqual(err.name, 'TypeError');
|
834 |
+
* assert.strictEqual(err.message, 'Wrong value');
|
835 |
+
* return true;
|
836 |
+
* },
|
837 |
+
* );
|
838 |
+
* ```
|
839 |
+
*
|
840 |
+
* ```js
|
841 |
+
* import assert from 'node:assert/strict';
|
842 |
+
*
|
843 |
+
* assert.rejects(
|
844 |
+
* Promise.reject(new Error('Wrong value')),
|
845 |
+
* Error,
|
846 |
+
* ).then(() => {
|
847 |
+
* // ...
|
848 |
+
* });
|
849 |
+
* ```
|
850 |
+
*
|
851 |
+
* `error` cannot be a string. If a string is provided as the second argument, then `error` is assumed to
|
852 |
+
* be omitted and the string will be used for `message` instead. This can lead to easy-to-miss mistakes. Please read the
|
853 |
+
* example in {@link throws} carefully if using a string as the second argument gets considered.
|
854 |
+
* @since v10.0.0
|
855 |
+
*/
|
856 |
+
function rejects(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
|
857 |
+
function rejects(
|
858 |
+
block: (() => Promise<unknown>) | Promise<unknown>,
|
859 |
+
error: AssertPredicate,
|
860 |
+
message?: string | Error,
|
861 |
+
): Promise<void>;
|
862 |
+
/**
|
863 |
+
* Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
|
864 |
+
* calls the function and awaits the returned promise to complete. It will then
|
865 |
+
* check that the promise is not rejected.
|
866 |
+
*
|
867 |
+
* If `asyncFn` is a function and it throws an error synchronously, `assert.doesNotReject()` will return a rejected `Promise` with that error. If
|
868 |
+
* the function does not return a promise, `assert.doesNotReject()` will return a
|
869 |
+
* rejected `Promise` with an [ERR_INVALID_RETURN_VALUE](https://nodejs.org/docs/latest-v22.x/api/errors.html#err_invalid_return_value) error. In both cases
|
870 |
+
* the error handler is skipped.
|
871 |
+
*
|
872 |
+
* Using `assert.doesNotReject()` is actually not useful because there is little
|
873 |
+
* benefit in catching a rejection and then rejecting it again. Instead, consider
|
874 |
+
* adding a comment next to the specific code path that should not reject and keep
|
875 |
+
* error messages as expressive as possible.
|
876 |
+
*
|
877 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
878 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), or a validation
|
879 |
+
* function. See {@link throws} for more details.
|
880 |
+
*
|
881 |
+
* Besides the async nature to await the completion behaves identically to {@link doesNotThrow}.
|
882 |
+
*
|
883 |
+
* ```js
|
884 |
+
* import assert from 'node:assert/strict';
|
885 |
+
*
|
886 |
+
* await assert.doesNotReject(
|
887 |
+
* async () => {
|
888 |
+
* throw new TypeError('Wrong value');
|
889 |
+
* },
|
890 |
+
* SyntaxError,
|
891 |
+
* );
|
892 |
+
* ```
|
893 |
+
*
|
894 |
+
* ```js
|
895 |
+
* import assert from 'node:assert/strict';
|
896 |
+
*
|
897 |
+
* assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
|
898 |
+
* .then(() => {
|
899 |
+
* // ...
|
900 |
+
* });
|
901 |
+
* ```
|
902 |
+
* @since v10.0.0
|
903 |
+
*/
|
904 |
+
function doesNotReject(
|
905 |
+
block: (() => Promise<unknown>) | Promise<unknown>,
|
906 |
+
message?: string | Error,
|
907 |
+
): Promise<void>;
|
908 |
+
function doesNotReject(
|
909 |
+
block: (() => Promise<unknown>) | Promise<unknown>,
|
910 |
+
error: AssertPredicate,
|
911 |
+
message?: string | Error,
|
912 |
+
): Promise<void>;
|
913 |
+
/**
|
914 |
+
* Expects the `string` input to match the regular expression.
|
915 |
+
*
|
916 |
+
* ```js
|
917 |
+
* import assert from 'node:assert/strict';
|
918 |
+
*
|
919 |
+
* assert.match('I will fail', /pass/);
|
920 |
+
* // AssertionError [ERR_ASSERTION]: The input did not match the regular ...
|
921 |
+
*
|
922 |
+
* assert.match(123, /pass/);
|
923 |
+
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
924 |
+
*
|
925 |
+
* assert.match('I will pass', /pass/);
|
926 |
+
* // OK
|
927 |
+
* ```
|
928 |
+
*
|
929 |
+
* If the values do not match, or if the `string` argument is of another type than `string`, an `{@link AssertionError}` is thrown with a `message` property set equal
|
930 |
+
* to the value of the `message` parameter. If the `message` parameter is
|
931 |
+
* undefined, a default error message is assigned. If the `message` parameter is an
|
932 |
+
* instance of an [Error](https://nodejs.org/docs/latest-v22.x/api/errors.html#class-error) then it will be thrown instead of the `{@link AssertionError}`.
|
933 |
+
* @since v13.6.0, v12.16.0
|
934 |
+
*/
|
935 |
+
function match(value: string, regExp: RegExp, message?: string | Error): void;
|
936 |
+
/**
|
937 |
+
* Expects the `string` input not to match the regular expression.
|
938 |
+
*
|
939 |
+
* ```js
|
940 |
+
* import assert from 'node:assert/strict';
|
941 |
+
*
|
942 |
+
* assert.doesNotMatch('I will fail', /fail/);
|
943 |
+
* // AssertionError [ERR_ASSERTION]: The input was expected to not match the ...
|
944 |
+
*
|
945 |
+
* assert.doesNotMatch(123, /pass/);
|
946 |
+
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
947 |
+
*
|
948 |
+
* assert.doesNotMatch('I will pass', /different/);
|
949 |
+
* // OK
|
950 |
+
* ```
|
951 |
+
*
|
952 |
+
* If the values do match, or if the `string` argument is of another type than `string`, an `{@link AssertionError}` is thrown with a `message` property set equal
|
953 |
+
* to the value of the `message` parameter. If the `message` parameter is
|
954 |
+
* undefined, a default error message is assigned. If the `message` parameter is an
|
955 |
+
* instance of an [Error](https://nodejs.org/docs/latest-v22.x/api/errors.html#class-error) then it will be thrown instead of the `{@link AssertionError}`.
|
956 |
+
* @since v13.6.0, v12.16.0
|
957 |
+
*/
|
958 |
+
function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
|
959 |
+
/**
|
960 |
+
* In strict assertion mode, non-strict methods behave like their corresponding strict methods. For example,
|
961 |
+
* {@link deepEqual} will behave like {@link deepStrictEqual}.
|
962 |
+
*
|
963 |
+
* In strict assertion mode, error messages for objects display a diff. In legacy assertion mode, error
|
964 |
+
* messages for objects display the objects, often truncated.
|
965 |
+
*
|
966 |
+
* To use strict assertion mode:
|
967 |
+
*
|
968 |
+
* ```js
|
969 |
+
* import { strict as assert } from 'node:assert';
|
970 |
+
* import assert from 'node:assert/strict';
|
971 |
+
* ```
|
972 |
+
*
|
973 |
+
* Example error diff:
|
974 |
+
*
|
975 |
+
* ```js
|
976 |
+
* import { strict as assert } from 'node:assert';
|
977 |
+
*
|
978 |
+
* assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);
|
979 |
+
* // AssertionError: Expected inputs to be strictly deep-equal:
|
980 |
+
* // + actual - expected ... Lines skipped
|
981 |
+
* //
|
982 |
+
* // [
|
983 |
+
* // [
|
984 |
+
* // ...
|
985 |
+
* // 2,
|
986 |
+
* // + 3
|
987 |
+
* // - '3'
|
988 |
+
* // ],
|
989 |
+
* // ...
|
990 |
+
* // 5
|
991 |
+
* // ]
|
992 |
+
* ```
|
993 |
+
*
|
994 |
+
* To deactivate the colors, use the `NO_COLOR` or `NODE_DISABLE_COLORS` environment variables. This will also
|
995 |
+
* deactivate the colors in the REPL. For more on color support in terminal environments, read the tty
|
996 |
+
* `getColorDepth()` documentation.
|
997 |
+
*
|
998 |
+
* @since v15.0.0, v13.9.0, v12.16.2, v9.9.0
|
999 |
+
*/
|
1000 |
+
namespace strict {
|
1001 |
+
type AssertionError = assert.AssertionError;
|
1002 |
+
type AssertPredicate = assert.AssertPredicate;
|
1003 |
+
type CallTrackerCall = assert.CallTrackerCall;
|
1004 |
+
type CallTrackerReportInformation = assert.CallTrackerReportInformation;
|
1005 |
+
}
|
1006 |
+
const strict:
|
1007 |
+
& Omit<
|
1008 |
+
typeof assert,
|
1009 |
+
| "equal"
|
1010 |
+
| "notEqual"
|
1011 |
+
| "deepEqual"
|
1012 |
+
| "notDeepEqual"
|
1013 |
+
| "ok"
|
1014 |
+
| "strictEqual"
|
1015 |
+
| "deepStrictEqual"
|
1016 |
+
| "ifError"
|
1017 |
+
| "strict"
|
1018 |
+
>
|
1019 |
+
& {
|
1020 |
+
(value: unknown, message?: string | Error): asserts value;
|
1021 |
+
equal: typeof strictEqual;
|
1022 |
+
notEqual: typeof notStrictEqual;
|
1023 |
+
deepEqual: typeof deepStrictEqual;
|
1024 |
+
notDeepEqual: typeof notDeepStrictEqual;
|
1025 |
+
// Mapped types and assertion functions are incompatible?
|
1026 |
+
// TS2775: Assertions require every name in the call target
|
1027 |
+
// to be declared with an explicit type annotation.
|
1028 |
+
ok: typeof ok;
|
1029 |
+
strictEqual: typeof strictEqual;
|
1030 |
+
deepStrictEqual: typeof deepStrictEqual;
|
1031 |
+
ifError: typeof ifError;
|
1032 |
+
strict: typeof strict;
|
1033 |
+
};
|
1034 |
+
}
|
1035 |
+
export = assert;
|
1036 |
+
}
|
1037 |
+
declare module "node:assert" {
|
1038 |
+
import assert = require("assert");
|
1039 |
+
export = assert;
|
1040 |
+
}
|
clone/node_modules/@types/node/assert/strict.d.ts
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
declare module "assert/strict" {
|
2 |
+
import { strict } from "node:assert";
|
3 |
+
export = strict;
|
4 |
+
}
|
5 |
+
declare module "node:assert/strict" {
|
6 |
+
import { strict } from "node:assert";
|
7 |
+
export = strict;
|
8 |
+
}
|
clone/node_modules/@types/node/async_hooks.d.ts
ADDED
@@ -0,0 +1,541 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* We strongly discourage the use of the `async_hooks` API.
|
3 |
+
* Other APIs that can cover most of its use cases include:
|
4 |
+
*
|
5 |
+
* * [`AsyncLocalStorage`](https://nodejs.org/docs/latest-v22.x/api/async_context.html#class-asynclocalstorage) tracks async context
|
6 |
+
* * [`process.getActiveResourcesInfo()`](https://nodejs.org/docs/latest-v22.x/api/process.html#processgetactiveresourcesinfo) tracks active resources
|
7 |
+
*
|
8 |
+
* The `node:async_hooks` module provides an API to track asynchronous resources.
|
9 |
+
* It can be accessed using:
|
10 |
+
*
|
11 |
+
* ```js
|
12 |
+
* import async_hooks from 'node:async_hooks';
|
13 |
+
* ```
|
14 |
+
* @experimental
|
15 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/async_hooks.js)
|
16 |
+
*/
|
17 |
+
declare module "async_hooks" {
|
18 |
+
/**
|
19 |
+
* ```js
|
20 |
+
* import { executionAsyncId } from 'node:async_hooks';
|
21 |
+
* import fs from 'node:fs';
|
22 |
+
*
|
23 |
+
* console.log(executionAsyncId()); // 1 - bootstrap
|
24 |
+
* const path = '.';
|
25 |
+
* fs.open(path, 'r', (err, fd) => {
|
26 |
+
* console.log(executionAsyncId()); // 6 - open()
|
27 |
+
* });
|
28 |
+
* ```
|
29 |
+
*
|
30 |
+
* The ID returned from `executionAsyncId()` is related to execution timing, not
|
31 |
+
* causality (which is covered by `triggerAsyncId()`):
|
32 |
+
*
|
33 |
+
* ```js
|
34 |
+
* const server = net.createServer((conn) => {
|
35 |
+
* // Returns the ID of the server, not of the new connection, because the
|
36 |
+
* // callback runs in the execution scope of the server's MakeCallback().
|
37 |
+
* async_hooks.executionAsyncId();
|
38 |
+
*
|
39 |
+
* }).listen(port, () => {
|
40 |
+
* // Returns the ID of a TickObject (process.nextTick()) because all
|
41 |
+
* // callbacks passed to .listen() are wrapped in a nextTick().
|
42 |
+
* async_hooks.executionAsyncId();
|
43 |
+
* });
|
44 |
+
* ```
|
45 |
+
*
|
46 |
+
* Promise contexts may not get precise `executionAsyncIds` by default.
|
47 |
+
* See the section on [promise execution tracking](https://nodejs.org/docs/latest-v22.x/api/async_hooks.html#promise-execution-tracking).
|
48 |
+
* @since v8.1.0
|
49 |
+
* @return The `asyncId` of the current execution context. Useful to track when something calls.
|
50 |
+
*/
|
51 |
+
function executionAsyncId(): number;
|
52 |
+
/**
|
53 |
+
* Resource objects returned by `executionAsyncResource()` are most often internal
|
54 |
+
* Node.js handle objects with undocumented APIs. Using any functions or properties
|
55 |
+
* on the object is likely to crash your application and should be avoided.
|
56 |
+
*
|
57 |
+
* Using `executionAsyncResource()` in the top-level execution context will
|
58 |
+
* return an empty object as there is no handle or request object to use,
|
59 |
+
* but having an object representing the top-level can be helpful.
|
60 |
+
*
|
61 |
+
* ```js
|
62 |
+
* import { open } from 'node:fs';
|
63 |
+
* import { executionAsyncId, executionAsyncResource } from 'node:async_hooks';
|
64 |
+
*
|
65 |
+
* console.log(executionAsyncId(), executionAsyncResource()); // 1 {}
|
66 |
+
* open(new URL(import.meta.url), 'r', (err, fd) => {
|
67 |
+
* console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap
|
68 |
+
* });
|
69 |
+
* ```
|
70 |
+
*
|
71 |
+
* This can be used to implement continuation local storage without the
|
72 |
+
* use of a tracking `Map` to store the metadata:
|
73 |
+
*
|
74 |
+
* ```js
|
75 |
+
* import { createServer } from 'node:http';
|
76 |
+
* import {
|
77 |
+
* executionAsyncId,
|
78 |
+
* executionAsyncResource,
|
79 |
+
* createHook,
|
80 |
+
* } from 'node:async_hooks';
|
81 |
+
* const sym = Symbol('state'); // Private symbol to avoid pollution
|
82 |
+
*
|
83 |
+
* createHook({
|
84 |
+
* init(asyncId, type, triggerAsyncId, resource) {
|
85 |
+
* const cr = executionAsyncResource();
|
86 |
+
* if (cr) {
|
87 |
+
* resource[sym] = cr[sym];
|
88 |
+
* }
|
89 |
+
* },
|
90 |
+
* }).enable();
|
91 |
+
*
|
92 |
+
* const server = createServer((req, res) => {
|
93 |
+
* executionAsyncResource()[sym] = { state: req.url };
|
94 |
+
* setTimeout(function() {
|
95 |
+
* res.end(JSON.stringify(executionAsyncResource()[sym]));
|
96 |
+
* }, 100);
|
97 |
+
* }).listen(3000);
|
98 |
+
* ```
|
99 |
+
* @since v13.9.0, v12.17.0
|
100 |
+
* @return The resource representing the current execution. Useful to store data within the resource.
|
101 |
+
*/
|
102 |
+
function executionAsyncResource(): object;
|
103 |
+
/**
|
104 |
+
* ```js
|
105 |
+
* const server = net.createServer((conn) => {
|
106 |
+
* // The resource that caused (or triggered) this callback to be called
|
107 |
+
* // was that of the new connection. Thus the return value of triggerAsyncId()
|
108 |
+
* // is the asyncId of "conn".
|
109 |
+
* async_hooks.triggerAsyncId();
|
110 |
+
*
|
111 |
+
* }).listen(port, () => {
|
112 |
+
* // Even though all callbacks passed to .listen() are wrapped in a nextTick()
|
113 |
+
* // the callback itself exists because the call to the server's .listen()
|
114 |
+
* // was made. So the return value would be the ID of the server.
|
115 |
+
* async_hooks.triggerAsyncId();
|
116 |
+
* });
|
117 |
+
* ```
|
118 |
+
*
|
119 |
+
* Promise contexts may not get valid `triggerAsyncId`s by default. See
|
120 |
+
* the section on [promise execution tracking](https://nodejs.org/docs/latest-v22.x/api/async_hooks.html#promise-execution-tracking).
|
121 |
+
* @return The ID of the resource responsible for calling the callback that is currently being executed.
|
122 |
+
*/
|
123 |
+
function triggerAsyncId(): number;
|
124 |
+
interface HookCallbacks {
|
125 |
+
/**
|
126 |
+
* Called when a class is constructed that has the possibility to emit an asynchronous event.
|
127 |
+
* @param asyncId A unique ID for the async resource
|
128 |
+
* @param type The type of the async resource
|
129 |
+
* @param triggerAsyncId The unique ID of the async resource in whose execution context this async resource was created
|
130 |
+
* @param resource Reference to the resource representing the async operation, needs to be released during destroy
|
131 |
+
*/
|
132 |
+
init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
|
133 |
+
/**
|
134 |
+
* When an asynchronous operation is initiated or completes a callback is called to notify the user.
|
135 |
+
* The before callback is called just before said callback is executed.
|
136 |
+
* @param asyncId the unique identifier assigned to the resource about to execute the callback.
|
137 |
+
*/
|
138 |
+
before?(asyncId: number): void;
|
139 |
+
/**
|
140 |
+
* Called immediately after the callback specified in `before` is completed.
|
141 |
+
*
|
142 |
+
* If an uncaught exception occurs during execution of the callback, then `after` will run after the `'uncaughtException'` event is emitted or a `domain`'s handler runs.
|
143 |
+
* @param asyncId the unique identifier assigned to the resource which has executed the callback.
|
144 |
+
*/
|
145 |
+
after?(asyncId: number): void;
|
146 |
+
/**
|
147 |
+
* Called when a promise has resolve() called. This may not be in the same execution id
|
148 |
+
* as the promise itself.
|
149 |
+
* @param asyncId the unique id for the promise that was resolve()d.
|
150 |
+
*/
|
151 |
+
promiseResolve?(asyncId: number): void;
|
152 |
+
/**
|
153 |
+
* Called after the resource corresponding to asyncId is destroyed
|
154 |
+
* @param asyncId a unique ID for the async resource
|
155 |
+
*/
|
156 |
+
destroy?(asyncId: number): void;
|
157 |
+
}
|
158 |
+
interface AsyncHook {
|
159 |
+
/**
|
160 |
+
* Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
|
161 |
+
*/
|
162 |
+
enable(): this;
|
163 |
+
/**
|
164 |
+
* 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.
|
165 |
+
*/
|
166 |
+
disable(): this;
|
167 |
+
}
|
168 |
+
/**
|
169 |
+
* Registers functions to be called for different lifetime events of each async
|
170 |
+
* operation.
|
171 |
+
*
|
172 |
+
* The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the
|
173 |
+
* respective asynchronous event during a resource's lifetime.
|
174 |
+
*
|
175 |
+
* All callbacks are optional. For example, if only resource cleanup needs to
|
176 |
+
* be tracked, then only the `destroy` callback needs to be passed. The
|
177 |
+
* specifics of all functions that can be passed to `callbacks` is in the `Hook Callbacks` section.
|
178 |
+
*
|
179 |
+
* ```js
|
180 |
+
* import { createHook } from 'node:async_hooks';
|
181 |
+
*
|
182 |
+
* const asyncHook = createHook({
|
183 |
+
* init(asyncId, type, triggerAsyncId, resource) { },
|
184 |
+
* destroy(asyncId) { },
|
185 |
+
* });
|
186 |
+
* ```
|
187 |
+
*
|
188 |
+
* The callbacks will be inherited via the prototype chain:
|
189 |
+
*
|
190 |
+
* ```js
|
191 |
+
* class MyAsyncCallbacks {
|
192 |
+
* init(asyncId, type, triggerAsyncId, resource) { }
|
193 |
+
* destroy(asyncId) {}
|
194 |
+
* }
|
195 |
+
*
|
196 |
+
* class MyAddedCallbacks extends MyAsyncCallbacks {
|
197 |
+
* before(asyncId) { }
|
198 |
+
* after(asyncId) { }
|
199 |
+
* }
|
200 |
+
*
|
201 |
+
* const asyncHook = async_hooks.createHook(new MyAddedCallbacks());
|
202 |
+
* ```
|
203 |
+
*
|
204 |
+
* Because promises are asynchronous resources whose lifecycle is tracked
|
205 |
+
* via the async hooks mechanism, the `init()`, `before()`, `after()`, and`destroy()` callbacks _must not_ be async functions that return promises.
|
206 |
+
* @since v8.1.0
|
207 |
+
* @param callbacks The `Hook Callbacks` to register
|
208 |
+
* @return Instance used for disabling and enabling hooks
|
209 |
+
*/
|
210 |
+
function createHook(callbacks: HookCallbacks): AsyncHook;
|
211 |
+
interface AsyncResourceOptions {
|
212 |
+
/**
|
213 |
+
* The ID of the execution context that created this async event.
|
214 |
+
* @default executionAsyncId()
|
215 |
+
*/
|
216 |
+
triggerAsyncId?: number | undefined;
|
217 |
+
/**
|
218 |
+
* Disables automatic `emitDestroy` when the object is garbage collected.
|
219 |
+
* This usually does not need to be set (even if `emitDestroy` is called
|
220 |
+
* manually), unless the resource's `asyncId` is retrieved and the
|
221 |
+
* sensitive API's `emitDestroy` is called with it.
|
222 |
+
* @default false
|
223 |
+
*/
|
224 |
+
requireManualDestroy?: boolean | undefined;
|
225 |
+
}
|
226 |
+
/**
|
227 |
+
* The class `AsyncResource` is designed to be extended by the embedder's async
|
228 |
+
* resources. Using this, users can easily trigger the lifetime events of their
|
229 |
+
* own resources.
|
230 |
+
*
|
231 |
+
* The `init` hook will trigger when an `AsyncResource` is instantiated.
|
232 |
+
*
|
233 |
+
* The following is an overview of the `AsyncResource` API.
|
234 |
+
*
|
235 |
+
* ```js
|
236 |
+
* import { AsyncResource, executionAsyncId } from 'node:async_hooks';
|
237 |
+
*
|
238 |
+
* // AsyncResource() is meant to be extended. Instantiating a
|
239 |
+
* // new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
240 |
+
* // async_hook.executionAsyncId() is used.
|
241 |
+
* const asyncResource = new AsyncResource(
|
242 |
+
* type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false },
|
243 |
+
* );
|
244 |
+
*
|
245 |
+
* // Run a function in the execution context of the resource. This will
|
246 |
+
* // * establish the context of the resource
|
247 |
+
* // * trigger the AsyncHooks before callbacks
|
248 |
+
* // * call the provided function `fn` with the supplied arguments
|
249 |
+
* // * trigger the AsyncHooks after callbacks
|
250 |
+
* // * restore the original execution context
|
251 |
+
* asyncResource.runInAsyncScope(fn, thisArg, ...args);
|
252 |
+
*
|
253 |
+
* // Call AsyncHooks destroy callbacks.
|
254 |
+
* asyncResource.emitDestroy();
|
255 |
+
*
|
256 |
+
* // Return the unique ID assigned to the AsyncResource instance.
|
257 |
+
* asyncResource.asyncId();
|
258 |
+
*
|
259 |
+
* // Return the trigger ID for the AsyncResource instance.
|
260 |
+
* asyncResource.triggerAsyncId();
|
261 |
+
* ```
|
262 |
+
*/
|
263 |
+
class AsyncResource {
|
264 |
+
/**
|
265 |
+
* AsyncResource() is meant to be extended. Instantiating a
|
266 |
+
* new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
267 |
+
* async_hook.executionAsyncId() is used.
|
268 |
+
* @param type The type of async event.
|
269 |
+
* @param triggerAsyncId The ID of the execution context that created
|
270 |
+
* this async event (default: `executionAsyncId()`), or an
|
271 |
+
* AsyncResourceOptions object (since v9.3.0)
|
272 |
+
*/
|
273 |
+
constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions);
|
274 |
+
/**
|
275 |
+
* Binds the given function to the current execution context.
|
276 |
+
* @since v14.8.0, v12.19.0
|
277 |
+
* @param fn The function to bind to the current execution context.
|
278 |
+
* @param type An optional name to associate with the underlying `AsyncResource`.
|
279 |
+
*/
|
280 |
+
static bind<Func extends (this: ThisArg, ...args: any[]) => any, ThisArg>(
|
281 |
+
fn: Func,
|
282 |
+
type?: string,
|
283 |
+
thisArg?: ThisArg,
|
284 |
+
): Func;
|
285 |
+
/**
|
286 |
+
* Binds the given function to execute to this `AsyncResource`'s scope.
|
287 |
+
* @since v14.8.0, v12.19.0
|
288 |
+
* @param fn The function to bind to the current `AsyncResource`.
|
289 |
+
*/
|
290 |
+
bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
291 |
+
/**
|
292 |
+
* Call the provided function with the provided arguments in the execution context
|
293 |
+
* of the async resource. This will establish the context, trigger the AsyncHooks
|
294 |
+
* before callbacks, call the function, trigger the AsyncHooks after callbacks, and
|
295 |
+
* then restore the original execution context.
|
296 |
+
* @since v9.6.0
|
297 |
+
* @param fn The function to call in the execution context of this async resource.
|
298 |
+
* @param thisArg The receiver to be used for the function call.
|
299 |
+
* @param args Optional arguments to pass to the function.
|
300 |
+
*/
|
301 |
+
runInAsyncScope<This, Result>(
|
302 |
+
fn: (this: This, ...args: any[]) => Result,
|
303 |
+
thisArg?: This,
|
304 |
+
...args: any[]
|
305 |
+
): Result;
|
306 |
+
/**
|
307 |
+
* Call all `destroy` hooks. This should only ever be called once. An error will
|
308 |
+
* be thrown if it is called more than once. This **must** be manually called. If
|
309 |
+
* the resource is left to be collected by the GC then the `destroy` hooks will
|
310 |
+
* never be called.
|
311 |
+
* @return A reference to `asyncResource`.
|
312 |
+
*/
|
313 |
+
emitDestroy(): this;
|
314 |
+
/**
|
315 |
+
* @return The unique `asyncId` assigned to the resource.
|
316 |
+
*/
|
317 |
+
asyncId(): number;
|
318 |
+
/**
|
319 |
+
* @return The same `triggerAsyncId` that is passed to the `AsyncResource` constructor.
|
320 |
+
*/
|
321 |
+
triggerAsyncId(): number;
|
322 |
+
}
|
323 |
+
/**
|
324 |
+
* This class creates stores that stay coherent through asynchronous operations.
|
325 |
+
*
|
326 |
+
* While you can create your own implementation on top of the `node:async_hooks` module, `AsyncLocalStorage` should be preferred as it is a performant and memory
|
327 |
+
* safe implementation that involves significant optimizations that are non-obvious
|
328 |
+
* to implement.
|
329 |
+
*
|
330 |
+
* The following example uses `AsyncLocalStorage` to build a simple logger
|
331 |
+
* that assigns IDs to incoming HTTP requests and includes them in messages
|
332 |
+
* logged within each request.
|
333 |
+
*
|
334 |
+
* ```js
|
335 |
+
* import http from 'node:http';
|
336 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
337 |
+
*
|
338 |
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
339 |
+
*
|
340 |
+
* function logWithId(msg) {
|
341 |
+
* const id = asyncLocalStorage.getStore();
|
342 |
+
* console.log(`${id !== undefined ? id : '-'}:`, msg);
|
343 |
+
* }
|
344 |
+
*
|
345 |
+
* let idSeq = 0;
|
346 |
+
* http.createServer((req, res) => {
|
347 |
+
* asyncLocalStorage.run(idSeq++, () => {
|
348 |
+
* logWithId('start');
|
349 |
+
* // Imagine any chain of async operations here
|
350 |
+
* setImmediate(() => {
|
351 |
+
* logWithId('finish');
|
352 |
+
* res.end();
|
353 |
+
* });
|
354 |
+
* });
|
355 |
+
* }).listen(8080);
|
356 |
+
*
|
357 |
+
* http.get('http://localhost:8080');
|
358 |
+
* http.get('http://localhost:8080');
|
359 |
+
* // Prints:
|
360 |
+
* // 0: start
|
361 |
+
* // 1: start
|
362 |
+
* // 0: finish
|
363 |
+
* // 1: finish
|
364 |
+
* ```
|
365 |
+
*
|
366 |
+
* Each instance of `AsyncLocalStorage` maintains an independent storage context.
|
367 |
+
* Multiple instances can safely exist simultaneously without risk of interfering
|
368 |
+
* with each other's data.
|
369 |
+
* @since v13.10.0, v12.17.0
|
370 |
+
*/
|
371 |
+
class AsyncLocalStorage<T> {
|
372 |
+
/**
|
373 |
+
* Binds the given function to the current execution context.
|
374 |
+
* @since v19.8.0
|
375 |
+
* @experimental
|
376 |
+
* @param fn The function to bind to the current execution context.
|
377 |
+
* @return A new function that calls `fn` within the captured execution context.
|
378 |
+
*/
|
379 |
+
static bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
380 |
+
/**
|
381 |
+
* Captures the current execution context and returns a function that accepts a
|
382 |
+
* function as an argument. Whenever the returned function is called, it
|
383 |
+
* calls the function passed to it within the captured context.
|
384 |
+
*
|
385 |
+
* ```js
|
386 |
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
387 |
+
* const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot());
|
388 |
+
* const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore()));
|
389 |
+
* console.log(result); // returns 123
|
390 |
+
* ```
|
391 |
+
*
|
392 |
+
* AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple
|
393 |
+
* async context tracking purposes, for example:
|
394 |
+
*
|
395 |
+
* ```js
|
396 |
+
* class Foo {
|
397 |
+
* #runInAsyncScope = AsyncLocalStorage.snapshot();
|
398 |
+
*
|
399 |
+
* get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); }
|
400 |
+
* }
|
401 |
+
*
|
402 |
+
* const foo = asyncLocalStorage.run(123, () => new Foo());
|
403 |
+
* console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123
|
404 |
+
* ```
|
405 |
+
* @since v19.8.0
|
406 |
+
* @experimental
|
407 |
+
* @return A new function with the signature `(fn: (...args) : R, ...args) : R`.
|
408 |
+
*/
|
409 |
+
static snapshot(): <R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R;
|
410 |
+
/**
|
411 |
+
* Disables the instance of `AsyncLocalStorage`. All subsequent calls
|
412 |
+
* to `asyncLocalStorage.getStore()` will return `undefined` until `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again.
|
413 |
+
*
|
414 |
+
* When calling `asyncLocalStorage.disable()`, all current contexts linked to the
|
415 |
+
* instance will be exited.
|
416 |
+
*
|
417 |
+
* Calling `asyncLocalStorage.disable()` is required before the `asyncLocalStorage` can be garbage collected. This does not apply to stores
|
418 |
+
* provided by the `asyncLocalStorage`, as those objects are garbage collected
|
419 |
+
* along with the corresponding async resources.
|
420 |
+
*
|
421 |
+
* Use this method when the `asyncLocalStorage` is not in use anymore
|
422 |
+
* in the current process.
|
423 |
+
* @since v13.10.0, v12.17.0
|
424 |
+
* @experimental
|
425 |
+
*/
|
426 |
+
disable(): void;
|
427 |
+
/**
|
428 |
+
* Returns the current store.
|
429 |
+
* If called outside of an asynchronous context initialized by
|
430 |
+
* calling `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()`, it
|
431 |
+
* returns `undefined`.
|
432 |
+
* @since v13.10.0, v12.17.0
|
433 |
+
*/
|
434 |
+
getStore(): T | undefined;
|
435 |
+
/**
|
436 |
+
* Runs a function synchronously within a context and returns its
|
437 |
+
* return value. The store is not accessible outside of the callback function.
|
438 |
+
* The store is accessible to any asynchronous operations created within the
|
439 |
+
* callback.
|
440 |
+
*
|
441 |
+
* The optional `args` are passed to the callback function.
|
442 |
+
*
|
443 |
+
* If the callback function throws an error, the error is thrown by `run()` too.
|
444 |
+
* The stacktrace is not impacted by this call and the context is exited.
|
445 |
+
*
|
446 |
+
* Example:
|
447 |
+
*
|
448 |
+
* ```js
|
449 |
+
* const store = { id: 2 };
|
450 |
+
* try {
|
451 |
+
* asyncLocalStorage.run(store, () => {
|
452 |
+
* asyncLocalStorage.getStore(); // Returns the store object
|
453 |
+
* setTimeout(() => {
|
454 |
+
* asyncLocalStorage.getStore(); // Returns the store object
|
455 |
+
* }, 200);
|
456 |
+
* throw new Error();
|
457 |
+
* });
|
458 |
+
* } catch (e) {
|
459 |
+
* asyncLocalStorage.getStore(); // Returns undefined
|
460 |
+
* // The error will be caught here
|
461 |
+
* }
|
462 |
+
* ```
|
463 |
+
* @since v13.10.0, v12.17.0
|
464 |
+
*/
|
465 |
+
run<R>(store: T, callback: () => R): R;
|
466 |
+
run<R, TArgs extends any[]>(store: T, callback: (...args: TArgs) => R, ...args: TArgs): R;
|
467 |
+
/**
|
468 |
+
* Runs a function synchronously outside of a context and returns its
|
469 |
+
* return value. The store is not accessible within the callback function or
|
470 |
+
* the asynchronous operations created within the callback. Any `getStore()` call done within the callback function will always return `undefined`.
|
471 |
+
*
|
472 |
+
* The optional `args` are passed to the callback function.
|
473 |
+
*
|
474 |
+
* If the callback function throws an error, the error is thrown by `exit()` too.
|
475 |
+
* The stacktrace is not impacted by this call and the context is re-entered.
|
476 |
+
*
|
477 |
+
* Example:
|
478 |
+
*
|
479 |
+
* ```js
|
480 |
+
* // Within a call to run
|
481 |
+
* try {
|
482 |
+
* asyncLocalStorage.getStore(); // Returns the store object or value
|
483 |
+
* asyncLocalStorage.exit(() => {
|
484 |
+
* asyncLocalStorage.getStore(); // Returns undefined
|
485 |
+
* throw new Error();
|
486 |
+
* });
|
487 |
+
* } catch (e) {
|
488 |
+
* asyncLocalStorage.getStore(); // Returns the same object or value
|
489 |
+
* // The error will be caught here
|
490 |
+
* }
|
491 |
+
* ```
|
492 |
+
* @since v13.10.0, v12.17.0
|
493 |
+
* @experimental
|
494 |
+
*/
|
495 |
+
exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R;
|
496 |
+
/**
|
497 |
+
* Transitions into the context for the remainder of the current
|
498 |
+
* synchronous execution and then persists the store through any following
|
499 |
+
* asynchronous calls.
|
500 |
+
*
|
501 |
+
* Example:
|
502 |
+
*
|
503 |
+
* ```js
|
504 |
+
* const store = { id: 1 };
|
505 |
+
* // Replaces previous store with the given store object
|
506 |
+
* asyncLocalStorage.enterWith(store);
|
507 |
+
* asyncLocalStorage.getStore(); // Returns the store object
|
508 |
+
* someAsyncOperation(() => {
|
509 |
+
* asyncLocalStorage.getStore(); // Returns the same object
|
510 |
+
* });
|
511 |
+
* ```
|
512 |
+
*
|
513 |
+
* This transition will continue for the _entire_ synchronous execution.
|
514 |
+
* This means that if, for example, the context is entered within an event
|
515 |
+
* handler subsequent event handlers will also run within that context unless
|
516 |
+
* specifically bound to another context with an `AsyncResource`. That is why `run()` should be preferred over `enterWith()` unless there are strong reasons
|
517 |
+
* to use the latter method.
|
518 |
+
*
|
519 |
+
* ```js
|
520 |
+
* const store = { id: 1 };
|
521 |
+
*
|
522 |
+
* emitter.on('my-event', () => {
|
523 |
+
* asyncLocalStorage.enterWith(store);
|
524 |
+
* });
|
525 |
+
* emitter.on('my-event', () => {
|
526 |
+
* asyncLocalStorage.getStore(); // Returns the same object
|
527 |
+
* });
|
528 |
+
*
|
529 |
+
* asyncLocalStorage.getStore(); // Returns undefined
|
530 |
+
* emitter.emit('my-event');
|
531 |
+
* asyncLocalStorage.getStore(); // Returns the same object
|
532 |
+
* ```
|
533 |
+
* @since v13.11.0, v12.17.0
|
534 |
+
* @experimental
|
535 |
+
*/
|
536 |
+
enterWith(store: T): void;
|
537 |
+
}
|
538 |
+
}
|
539 |
+
declare module "node:async_hooks" {
|
540 |
+
export * from "async_hooks";
|
541 |
+
}
|
clone/node_modules/@types/node/buffer.buffer.d.ts
ADDED
@@ -0,0 +1,385 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
declare module "buffer" {
|
2 |
+
global {
|
3 |
+
interface BufferConstructor {
|
4 |
+
// see buffer.d.ts for implementation shared with all TypeScript versions
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Allocates a new buffer containing the given {str}.
|
8 |
+
*
|
9 |
+
* @param str String to store in buffer.
|
10 |
+
* @param encoding encoding to use, optional. Default is 'utf8'
|
11 |
+
* @deprecated since v10.0.0 - Use `Buffer.from(string[, encoding])` instead.
|
12 |
+
*/
|
13 |
+
new(str: string, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
|
14 |
+
/**
|
15 |
+
* Allocates a new buffer of {size} octets.
|
16 |
+
*
|
17 |
+
* @param size count of octets to allocate.
|
18 |
+
* @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`).
|
19 |
+
*/
|
20 |
+
new(size: number): Buffer<ArrayBuffer>;
|
21 |
+
/**
|
22 |
+
* Allocates a new buffer containing the given {array} of octets.
|
23 |
+
*
|
24 |
+
* @param array The octets to store.
|
25 |
+
* @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
|
26 |
+
*/
|
27 |
+
new(array: Uint8Array): Buffer<ArrayBuffer>;
|
28 |
+
/**
|
29 |
+
* Produces a Buffer backed by the same allocated memory as
|
30 |
+
* the given {ArrayBuffer}/{SharedArrayBuffer}.
|
31 |
+
*
|
32 |
+
* @param arrayBuffer The ArrayBuffer with which to share memory.
|
33 |
+
* @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead.
|
34 |
+
*/
|
35 |
+
new<TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: TArrayBuffer): Buffer<TArrayBuffer>;
|
36 |
+
/**
|
37 |
+
* Allocates a new buffer containing the given {array} of octets.
|
38 |
+
*
|
39 |
+
* @param array The octets to store.
|
40 |
+
* @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
|
41 |
+
*/
|
42 |
+
new(array: readonly any[]): Buffer<ArrayBuffer>;
|
43 |
+
/**
|
44 |
+
* Copies the passed {buffer} data onto a new {Buffer} instance.
|
45 |
+
*
|
46 |
+
* @param buffer The buffer to copy.
|
47 |
+
* @deprecated since v10.0.0 - Use `Buffer.from(buffer)` instead.
|
48 |
+
*/
|
49 |
+
new(buffer: Buffer): Buffer<ArrayBuffer>;
|
50 |
+
/**
|
51 |
+
* Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`.
|
52 |
+
* Array entries outside that range will be truncated to fit into it.
|
53 |
+
*
|
54 |
+
* ```js
|
55 |
+
* import { Buffer } from 'node:buffer';
|
56 |
+
*
|
57 |
+
* // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
|
58 |
+
* const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
|
59 |
+
* ```
|
60 |
+
*
|
61 |
+
* If `array` is an `Array`\-like object (that is, one with a `length` property of
|
62 |
+
* type `number`), it is treated as if it is an array, unless it is a `Buffer` or
|
63 |
+
* a `Uint8Array`. This means all other `TypedArray` variants get treated as an `Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use `Buffer.copyBytesFrom()`.
|
64 |
+
*
|
65 |
+
* A `TypeError` will be thrown if `array` is not an `Array` or another type
|
66 |
+
* appropriate for `Buffer.from()` variants.
|
67 |
+
*
|
68 |
+
* `Buffer.from(array)` and `Buffer.from(string)` may also use the internal `Buffer` pool like `Buffer.allocUnsafe()` does.
|
69 |
+
* @since v5.10.0
|
70 |
+
*/
|
71 |
+
from<TArrayBuffer extends ArrayBufferLike>(
|
72 |
+
arrayBuffer: WithImplicitCoercion<TArrayBuffer>,
|
73 |
+
byteOffset?: number,
|
74 |
+
length?: number,
|
75 |
+
): Buffer<TArrayBuffer>;
|
76 |
+
/**
|
77 |
+
* Creates a new Buffer using the passed {data}
|
78 |
+
* @param data data to create a new Buffer
|
79 |
+
*/
|
80 |
+
from(data: Uint8Array | readonly number[]): Buffer<ArrayBuffer>;
|
81 |
+
from(data: WithImplicitCoercion<Uint8Array | readonly number[] | string>): Buffer<ArrayBuffer>;
|
82 |
+
/**
|
83 |
+
* Creates a new Buffer containing the given JavaScript string {str}.
|
84 |
+
* If provided, the {encoding} parameter identifies the character encoding.
|
85 |
+
* If not provided, {encoding} defaults to 'utf8'.
|
86 |
+
*/
|
87 |
+
from(
|
88 |
+
str:
|
89 |
+
| WithImplicitCoercion<string>
|
90 |
+
| {
|
91 |
+
[Symbol.toPrimitive](hint: "string"): string;
|
92 |
+
},
|
93 |
+
encoding?: BufferEncoding,
|
94 |
+
): Buffer<ArrayBuffer>;
|
95 |
+
/**
|
96 |
+
* Creates a new Buffer using the passed {data}
|
97 |
+
* @param values to create a new Buffer
|
98 |
+
*/
|
99 |
+
of(...items: number[]): Buffer<ArrayBuffer>;
|
100 |
+
/**
|
101 |
+
* Returns a new `Buffer` which is the result of concatenating all the `Buffer` instances in the `list` together.
|
102 |
+
*
|
103 |
+
* If the list has no items, or if the `totalLength` is 0, then a new zero-length `Buffer` is returned.
|
104 |
+
*
|
105 |
+
* If `totalLength` is not provided, it is calculated from the `Buffer` instances
|
106 |
+
* in `list` by adding their lengths.
|
107 |
+
*
|
108 |
+
* If `totalLength` is provided, it is coerced to an unsigned integer. If the
|
109 |
+
* combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is
|
110 |
+
* truncated to `totalLength`.
|
111 |
+
*
|
112 |
+
* ```js
|
113 |
+
* import { Buffer } from 'node:buffer';
|
114 |
+
*
|
115 |
+
* // Create a single `Buffer` from a list of three `Buffer` instances.
|
116 |
+
*
|
117 |
+
* const buf1 = Buffer.alloc(10);
|
118 |
+
* const buf2 = Buffer.alloc(14);
|
119 |
+
* const buf3 = Buffer.alloc(18);
|
120 |
+
* const totalLength = buf1.length + buf2.length + buf3.length;
|
121 |
+
*
|
122 |
+
* console.log(totalLength);
|
123 |
+
* // Prints: 42
|
124 |
+
*
|
125 |
+
* const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
|
126 |
+
*
|
127 |
+
* console.log(bufA);
|
128 |
+
* // Prints: <Buffer 00 00 00 00 ...>
|
129 |
+
* console.log(bufA.length);
|
130 |
+
* // Prints: 42
|
131 |
+
* ```
|
132 |
+
*
|
133 |
+
* `Buffer.concat()` may also use the internal `Buffer` pool like `Buffer.allocUnsafe()` does.
|
134 |
+
* @since v0.7.11
|
135 |
+
* @param list List of `Buffer` or {@link Uint8Array} instances to concatenate.
|
136 |
+
* @param totalLength Total length of the `Buffer` instances in `list` when concatenated.
|
137 |
+
*/
|
138 |
+
concat(list: readonly Uint8Array[], totalLength?: number): Buffer<ArrayBuffer>;
|
139 |
+
/**
|
140 |
+
* Copies the underlying memory of `view` into a new `Buffer`.
|
141 |
+
*
|
142 |
+
* ```js
|
143 |
+
* const u16 = new Uint16Array([0, 0xffff]);
|
144 |
+
* const buf = Buffer.copyBytesFrom(u16, 1, 1);
|
145 |
+
* u16[1] = 0;
|
146 |
+
* console.log(buf.length); // 2
|
147 |
+
* console.log(buf[0]); // 255
|
148 |
+
* console.log(buf[1]); // 255
|
149 |
+
* ```
|
150 |
+
* @since v19.8.0
|
151 |
+
* @param view The {TypedArray} to copy.
|
152 |
+
* @param [offset=0] The starting offset within `view`.
|
153 |
+
* @param [length=view.length - offset] The number of elements from `view` to copy.
|
154 |
+
*/
|
155 |
+
copyBytesFrom(view: NodeJS.TypedArray, offset?: number, length?: number): Buffer<ArrayBuffer>;
|
156 |
+
/**
|
157 |
+
* Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the`Buffer` will be zero-filled.
|
158 |
+
*
|
159 |
+
* ```js
|
160 |
+
* import { Buffer } from 'node:buffer';
|
161 |
+
*
|
162 |
+
* const buf = Buffer.alloc(5);
|
163 |
+
*
|
164 |
+
* console.log(buf);
|
165 |
+
* // Prints: <Buffer 00 00 00 00 00>
|
166 |
+
* ```
|
167 |
+
*
|
168 |
+
* If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.
|
169 |
+
*
|
170 |
+
* If `fill` is specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill)`.
|
171 |
+
*
|
172 |
+
* ```js
|
173 |
+
* import { Buffer } from 'node:buffer';
|
174 |
+
*
|
175 |
+
* const buf = Buffer.alloc(5, 'a');
|
176 |
+
*
|
177 |
+
* console.log(buf);
|
178 |
+
* // Prints: <Buffer 61 61 61 61 61>
|
179 |
+
* ```
|
180 |
+
*
|
181 |
+
* If both `fill` and `encoding` are specified, the allocated `Buffer` will be
|
182 |
+
* initialized by calling `buf.fill(fill, encoding)`.
|
183 |
+
*
|
184 |
+
* ```js
|
185 |
+
* import { Buffer } from 'node:buffer';
|
186 |
+
*
|
187 |
+
* const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
|
188 |
+
*
|
189 |
+
* console.log(buf);
|
190 |
+
* // Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
|
191 |
+
* ```
|
192 |
+
*
|
193 |
+
* Calling `Buffer.alloc()` can be measurably slower than the alternative `Buffer.allocUnsafe()` but ensures that the newly created `Buffer` instance
|
194 |
+
* contents will never contain sensitive data from previous allocations, including
|
195 |
+
* data that might not have been allocated for `Buffer`s.
|
196 |
+
*
|
197 |
+
* A `TypeError` will be thrown if `size` is not a number.
|
198 |
+
* @since v5.10.0
|
199 |
+
* @param size The desired length of the new `Buffer`.
|
200 |
+
* @param [fill=0] A value to pre-fill the new `Buffer` with.
|
201 |
+
* @param [encoding='utf8'] If `fill` is a string, this is its encoding.
|
202 |
+
*/
|
203 |
+
alloc(size: number, fill?: string | Uint8Array | number, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
|
204 |
+
/**
|
205 |
+
* Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.
|
206 |
+
*
|
207 |
+
* The underlying memory for `Buffer` instances created in this way is _not_
|
208 |
+
* _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `Buffer.alloc()` instead to initialize`Buffer` instances with zeroes.
|
209 |
+
*
|
210 |
+
* ```js
|
211 |
+
* import { Buffer } from 'node:buffer';
|
212 |
+
*
|
213 |
+
* const buf = Buffer.allocUnsafe(10);
|
214 |
+
*
|
215 |
+
* console.log(buf);
|
216 |
+
* // Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
|
217 |
+
*
|
218 |
+
* buf.fill(0);
|
219 |
+
*
|
220 |
+
* console.log(buf);
|
221 |
+
* // Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>
|
222 |
+
* ```
|
223 |
+
*
|
224 |
+
* A `TypeError` will be thrown if `size` is not a number.
|
225 |
+
*
|
226 |
+
* The `Buffer` module pre-allocates an internal `Buffer` instance of
|
227 |
+
* size `Buffer.poolSize` that is used as a pool for the fast allocation of new `Buffer` instances created using `Buffer.allocUnsafe()`, `Buffer.from(array)`,
|
228 |
+
* and `Buffer.concat()` only when `size` is less than `Buffer.poolSize >>> 1` (floor of `Buffer.poolSize` divided by two).
|
229 |
+
*
|
230 |
+
* Use of this pre-allocated internal memory pool is a key difference between
|
231 |
+
* calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
|
232 |
+
* Specifically, `Buffer.alloc(size, fill)` will _never_ use the internal `Buffer`pool, while `Buffer.allocUnsafe(size).fill(fill)`_will_ use the internal`Buffer` pool if `size` is less
|
233 |
+
* than or equal to half `Buffer.poolSize`. The
|
234 |
+
* difference is subtle but can be important when an application requires the
|
235 |
+
* additional performance that `Buffer.allocUnsafe()` provides.
|
236 |
+
* @since v5.10.0
|
237 |
+
* @param size The desired length of the new `Buffer`.
|
238 |
+
*/
|
239 |
+
allocUnsafe(size: number): Buffer<ArrayBuffer>;
|
240 |
+
/**
|
241 |
+
* Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown. A zero-length `Buffer` is created if
|
242 |
+
* `size` is 0.
|
243 |
+
*
|
244 |
+
* The underlying memory for `Buffer` instances created in this way is _not_
|
245 |
+
* _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `buf.fill(0)` to initialize
|
246 |
+
* such `Buffer` instances with zeroes.
|
247 |
+
*
|
248 |
+
* When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
|
249 |
+
* allocations under 4 KiB are sliced from a single pre-allocated `Buffer`. This
|
250 |
+
* allows applications to avoid the garbage collection overhead of creating many
|
251 |
+
* individually allocated `Buffer` instances. This approach improves both
|
252 |
+
* performance and memory usage by eliminating the need to track and clean up as
|
253 |
+
* many individual `ArrayBuffer` objects.
|
254 |
+
*
|
255 |
+
* However, in the case where a developer may need to retain a small chunk of
|
256 |
+
* memory from a pool for an indeterminate amount of time, it may be appropriate
|
257 |
+
* to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and
|
258 |
+
* then copying out the relevant bits.
|
259 |
+
*
|
260 |
+
* ```js
|
261 |
+
* import { Buffer } from 'node:buffer';
|
262 |
+
*
|
263 |
+
* // Need to keep around a few small chunks of memory.
|
264 |
+
* const store = [];
|
265 |
+
*
|
266 |
+
* socket.on('readable', () => {
|
267 |
+
* let data;
|
268 |
+
* while (null !== (data = readable.read())) {
|
269 |
+
* // Allocate for retained data.
|
270 |
+
* const sb = Buffer.allocUnsafeSlow(10);
|
271 |
+
*
|
272 |
+
* // Copy the data into the new allocation.
|
273 |
+
* data.copy(sb, 0, 0, 10);
|
274 |
+
*
|
275 |
+
* store.push(sb);
|
276 |
+
* }
|
277 |
+
* });
|
278 |
+
* ```
|
279 |
+
*
|
280 |
+
* A `TypeError` will be thrown if `size` is not a number.
|
281 |
+
* @since v5.12.0
|
282 |
+
* @param size The desired length of the new `Buffer`.
|
283 |
+
*/
|
284 |
+
allocUnsafeSlow(size: number): Buffer<ArrayBuffer>;
|
285 |
+
}
|
286 |
+
interface Buffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> extends Uint8Array<TArrayBuffer> {
|
287 |
+
// see buffer.d.ts for implementation shared with all TypeScript versions
|
288 |
+
|
289 |
+
/**
|
290 |
+
* Returns a new `Buffer` that references the same memory as the original, but
|
291 |
+
* offset and cropped by the `start` and `end` indices.
|
292 |
+
*
|
293 |
+
* This method is not compatible with the `Uint8Array.prototype.slice()`,
|
294 |
+
* which is a superclass of `Buffer`. To copy the slice, use`Uint8Array.prototype.slice()`.
|
295 |
+
*
|
296 |
+
* ```js
|
297 |
+
* import { Buffer } from 'node:buffer';
|
298 |
+
*
|
299 |
+
* const buf = Buffer.from('buffer');
|
300 |
+
*
|
301 |
+
* const copiedBuf = Uint8Array.prototype.slice.call(buf);
|
302 |
+
* copiedBuf[0]++;
|
303 |
+
* console.log(copiedBuf.toString());
|
304 |
+
* // Prints: cuffer
|
305 |
+
*
|
306 |
+
* console.log(buf.toString());
|
307 |
+
* // Prints: buffer
|
308 |
+
*
|
309 |
+
* // With buf.slice(), the original buffer is modified.
|
310 |
+
* const notReallyCopiedBuf = buf.slice();
|
311 |
+
* notReallyCopiedBuf[0]++;
|
312 |
+
* console.log(notReallyCopiedBuf.toString());
|
313 |
+
* // Prints: cuffer
|
314 |
+
* console.log(buf.toString());
|
315 |
+
* // Also prints: cuffer (!)
|
316 |
+
* ```
|
317 |
+
* @since v0.3.0
|
318 |
+
* @deprecated Use `subarray` instead.
|
319 |
+
* @param [start=0] Where the new `Buffer` will start.
|
320 |
+
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
321 |
+
*/
|
322 |
+
slice(start?: number, end?: number): Buffer<ArrayBuffer>;
|
323 |
+
/**
|
324 |
+
* Returns a new `Buffer` that references the same memory as the original, but
|
325 |
+
* offset and cropped by the `start` and `end` indices.
|
326 |
+
*
|
327 |
+
* Specifying `end` greater than `buf.length` will return the same result as
|
328 |
+
* that of `end` equal to `buf.length`.
|
329 |
+
*
|
330 |
+
* This method is inherited from [`TypedArray.prototype.subarray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray).
|
331 |
+
*
|
332 |
+
* Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap.
|
333 |
+
*
|
334 |
+
* ```js
|
335 |
+
* import { Buffer } from 'node:buffer';
|
336 |
+
*
|
337 |
+
* // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte
|
338 |
+
* // from the original `Buffer`.
|
339 |
+
*
|
340 |
+
* const buf1 = Buffer.allocUnsafe(26);
|
341 |
+
*
|
342 |
+
* for (let i = 0; i < 26; i++) {
|
343 |
+
* // 97 is the decimal ASCII value for 'a'.
|
344 |
+
* buf1[i] = i + 97;
|
345 |
+
* }
|
346 |
+
*
|
347 |
+
* const buf2 = buf1.subarray(0, 3);
|
348 |
+
*
|
349 |
+
* console.log(buf2.toString('ascii', 0, buf2.length));
|
350 |
+
* // Prints: abc
|
351 |
+
*
|
352 |
+
* buf1[0] = 33;
|
353 |
+
*
|
354 |
+
* console.log(buf2.toString('ascii', 0, buf2.length));
|
355 |
+
* // Prints: !bc
|
356 |
+
* ```
|
357 |
+
*
|
358 |
+
* Specifying negative indexes causes the slice to be generated relative to the
|
359 |
+
* end of `buf` rather than the beginning.
|
360 |
+
*
|
361 |
+
* ```js
|
362 |
+
* import { Buffer } from 'node:buffer';
|
363 |
+
*
|
364 |
+
* const buf = Buffer.from('buffer');
|
365 |
+
*
|
366 |
+
* console.log(buf.subarray(-6, -1).toString());
|
367 |
+
* // Prints: buffe
|
368 |
+
* // (Equivalent to buf.subarray(0, 5).)
|
369 |
+
*
|
370 |
+
* console.log(buf.subarray(-6, -2).toString());
|
371 |
+
* // Prints: buff
|
372 |
+
* // (Equivalent to buf.subarray(0, 4).)
|
373 |
+
*
|
374 |
+
* console.log(buf.subarray(-5, -2).toString());
|
375 |
+
* // Prints: uff
|
376 |
+
* // (Equivalent to buf.subarray(1, 4).)
|
377 |
+
* ```
|
378 |
+
* @since v3.0.0
|
379 |
+
* @param [start=0] Where the new `Buffer` will start.
|
380 |
+
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
381 |
+
*/
|
382 |
+
subarray(start?: number, end?: number): Buffer<TArrayBuffer>;
|
383 |
+
}
|
384 |
+
}
|
385 |
+
}
|
clone/node_modules/@types/node/buffer.d.ts
ADDED
@@ -0,0 +1,1933 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// If lib.dom.d.ts or lib.webworker.d.ts is loaded, then use the global types.
|
2 |
+
// Otherwise, use the types from node.
|
3 |
+
type _Blob = typeof globalThis extends { onmessage: any; Blob: any } ? {} : import("buffer").Blob;
|
4 |
+
type _File = typeof globalThis extends { onmessage: any; File: any } ? {} : import("buffer").File;
|
5 |
+
|
6 |
+
/**
|
7 |
+
* `Buffer` objects are used to represent a fixed-length sequence of bytes. Many
|
8 |
+
* Node.js APIs support `Buffer`s.
|
9 |
+
*
|
10 |
+
* The `Buffer` class is a subclass of JavaScript's [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) class and
|
11 |
+
* extends it with methods that cover additional use cases. Node.js APIs accept
|
12 |
+
* plain [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) s wherever `Buffer`s are supported as well.
|
13 |
+
*
|
14 |
+
* While the `Buffer` class is available within the global scope, it is still
|
15 |
+
* recommended to explicitly reference it via an import or require statement.
|
16 |
+
*
|
17 |
+
* ```js
|
18 |
+
* import { Buffer } from 'node:buffer';
|
19 |
+
*
|
20 |
+
* // Creates a zero-filled Buffer of length 10.
|
21 |
+
* const buf1 = Buffer.alloc(10);
|
22 |
+
*
|
23 |
+
* // Creates a Buffer of length 10,
|
24 |
+
* // filled with bytes which all have the value `1`.
|
25 |
+
* const buf2 = Buffer.alloc(10, 1);
|
26 |
+
*
|
27 |
+
* // Creates an uninitialized buffer of length 10.
|
28 |
+
* // This is faster than calling Buffer.alloc() but the returned
|
29 |
+
* // Buffer instance might contain old data that needs to be
|
30 |
+
* // overwritten using fill(), write(), or other functions that fill the Buffer's
|
31 |
+
* // contents.
|
32 |
+
* const buf3 = Buffer.allocUnsafe(10);
|
33 |
+
*
|
34 |
+
* // Creates a Buffer containing the bytes [1, 2, 3].
|
35 |
+
* const buf4 = Buffer.from([1, 2, 3]);
|
36 |
+
*
|
37 |
+
* // Creates a Buffer containing the bytes [1, 1, 1, 1] – the entries
|
38 |
+
* // are all truncated using `(value & 255)` to fit into the range 0–255.
|
39 |
+
* const buf5 = Buffer.from([257, 257.5, -255, '1']);
|
40 |
+
*
|
41 |
+
* // Creates a Buffer containing the UTF-8-encoded bytes for the string 'tést':
|
42 |
+
* // [0x74, 0xc3, 0xa9, 0x73, 0x74] (in hexadecimal notation)
|
43 |
+
* // [116, 195, 169, 115, 116] (in decimal notation)
|
44 |
+
* const buf6 = Buffer.from('tést');
|
45 |
+
*
|
46 |
+
* // Creates a Buffer containing the Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
|
47 |
+
* const buf7 = Buffer.from('tést', 'latin1');
|
48 |
+
* ```
|
49 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/buffer.js)
|
50 |
+
*/
|
51 |
+
declare module "buffer" {
|
52 |
+
import { BinaryLike } from "node:crypto";
|
53 |
+
import { ReadableStream as WebReadableStream } from "node:stream/web";
|
54 |
+
/**
|
55 |
+
* This function returns `true` if `input` contains only valid UTF-8-encoded data,
|
56 |
+
* including the case in which `input` is empty.
|
57 |
+
*
|
58 |
+
* Throws if the `input` is a detached array buffer.
|
59 |
+
* @since v19.4.0, v18.14.0
|
60 |
+
* @param input The input to validate.
|
61 |
+
*/
|
62 |
+
export function isUtf8(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean;
|
63 |
+
/**
|
64 |
+
* This function returns `true` if `input` contains only valid ASCII-encoded data,
|
65 |
+
* including the case in which `input` is empty.
|
66 |
+
*
|
67 |
+
* Throws if the `input` is a detached array buffer.
|
68 |
+
* @since v19.6.0, v18.15.0
|
69 |
+
* @param input The input to validate.
|
70 |
+
*/
|
71 |
+
export function isAscii(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean;
|
72 |
+
export const INSPECT_MAX_BYTES: number;
|
73 |
+
export const kMaxLength: number;
|
74 |
+
export const kStringMaxLength: number;
|
75 |
+
export const constants: {
|
76 |
+
MAX_LENGTH: number;
|
77 |
+
MAX_STRING_LENGTH: number;
|
78 |
+
};
|
79 |
+
export type TranscodeEncoding =
|
80 |
+
| "ascii"
|
81 |
+
| "utf8"
|
82 |
+
| "utf-8"
|
83 |
+
| "utf16le"
|
84 |
+
| "utf-16le"
|
85 |
+
| "ucs2"
|
86 |
+
| "ucs-2"
|
87 |
+
| "latin1"
|
88 |
+
| "binary";
|
89 |
+
/**
|
90 |
+
* Re-encodes the given `Buffer` or `Uint8Array` instance from one character
|
91 |
+
* encoding to another. Returns a new `Buffer` instance.
|
92 |
+
*
|
93 |
+
* Throws if the `fromEnc` or `toEnc` specify invalid character encodings or if
|
94 |
+
* conversion from `fromEnc` to `toEnc` is not permitted.
|
95 |
+
*
|
96 |
+
* Encodings supported by `buffer.transcode()` are: `'ascii'`, `'utf8'`, `'utf16le'`, `'ucs2'`, `'latin1'`, and `'binary'`.
|
97 |
+
*
|
98 |
+
* The transcoding process will use substitution characters if a given byte
|
99 |
+
* sequence cannot be adequately represented in the target encoding. For instance:
|
100 |
+
*
|
101 |
+
* ```js
|
102 |
+
* import { Buffer, transcode } from 'node:buffer';
|
103 |
+
*
|
104 |
+
* const newBuf = transcode(Buffer.from('€'), 'utf8', 'ascii');
|
105 |
+
* console.log(newBuf.toString('ascii'));
|
106 |
+
* // Prints: '?'
|
107 |
+
* ```
|
108 |
+
*
|
109 |
+
* Because the Euro (`€`) sign is not representable in US-ASCII, it is replaced
|
110 |
+
* with `?` in the transcoded `Buffer`.
|
111 |
+
* @since v7.1.0
|
112 |
+
* @param source A `Buffer` or `Uint8Array` instance.
|
113 |
+
* @param fromEnc The current encoding.
|
114 |
+
* @param toEnc To target encoding.
|
115 |
+
*/
|
116 |
+
export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer;
|
117 |
+
export const SlowBuffer: {
|
118 |
+
/** @deprecated since v6.0.0, use `Buffer.allocUnsafeSlow()` */
|
119 |
+
new(size: number): Buffer;
|
120 |
+
prototype: Buffer;
|
121 |
+
};
|
122 |
+
/**
|
123 |
+
* Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using
|
124 |
+
* a prior call to `URL.createObjectURL()`.
|
125 |
+
* @since v16.7.0
|
126 |
+
* @experimental
|
127 |
+
* @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
|
128 |
+
*/
|
129 |
+
export function resolveObjectURL(id: string): Blob | undefined;
|
130 |
+
export { Buffer };
|
131 |
+
/**
|
132 |
+
* @experimental
|
133 |
+
*/
|
134 |
+
export interface BlobOptions {
|
135 |
+
/**
|
136 |
+
* One of either `'transparent'` or `'native'`. When set to `'native'`, line endings in string source parts
|
137 |
+
* will be converted to the platform native line-ending as specified by `import { EOL } from 'node:os'`.
|
138 |
+
*/
|
139 |
+
endings?: "transparent" | "native";
|
140 |
+
/**
|
141 |
+
* The Blob content-type. The intent is for `type` to convey
|
142 |
+
* the MIME media type of the data, however no validation of the type format
|
143 |
+
* is performed.
|
144 |
+
*/
|
145 |
+
type?: string | undefined;
|
146 |
+
}
|
147 |
+
/**
|
148 |
+
* A [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) encapsulates immutable, raw data that can be safely shared across
|
149 |
+
* multiple worker threads.
|
150 |
+
* @since v15.7.0, v14.18.0
|
151 |
+
*/
|
152 |
+
export class Blob {
|
153 |
+
/**
|
154 |
+
* The total size of the `Blob` in bytes.
|
155 |
+
* @since v15.7.0, v14.18.0
|
156 |
+
*/
|
157 |
+
readonly size: number;
|
158 |
+
/**
|
159 |
+
* The content-type of the `Blob`.
|
160 |
+
* @since v15.7.0, v14.18.0
|
161 |
+
*/
|
162 |
+
readonly type: string;
|
163 |
+
/**
|
164 |
+
* Creates a new `Blob` object containing a concatenation of the given sources.
|
165 |
+
*
|
166 |
+
* {ArrayBuffer}, {TypedArray}, {DataView}, and {Buffer} sources are copied into
|
167 |
+
* the 'Blob' and can therefore be safely modified after the 'Blob' is created.
|
168 |
+
*
|
169 |
+
* String sources are also copied into the `Blob`.
|
170 |
+
*/
|
171 |
+
constructor(sources: Array<ArrayBuffer | BinaryLike | Blob>, options?: BlobOptions);
|
172 |
+
/**
|
173 |
+
* Returns a promise that fulfills with an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) containing a copy of
|
174 |
+
* the `Blob` data.
|
175 |
+
* @since v15.7.0, v14.18.0
|
176 |
+
*/
|
177 |
+
arrayBuffer(): Promise<ArrayBuffer>;
|
178 |
+
/**
|
179 |
+
* The `blob.bytes()` method returns the byte of the `Blob` object as a `Promise<Uint8Array>`.
|
180 |
+
*
|
181 |
+
* ```js
|
182 |
+
* const blob = new Blob(['hello']);
|
183 |
+
* blob.bytes().then((bytes) => {
|
184 |
+
* console.log(bytes); // Outputs: Uint8Array(5) [ 104, 101, 108, 108, 111 ]
|
185 |
+
* });
|
186 |
+
* ```
|
187 |
+
*/
|
188 |
+
bytes(): Promise<Uint8Array>;
|
189 |
+
/**
|
190 |
+
* Creates and returns a new `Blob` containing a subset of this `Blob` objects
|
191 |
+
* data. The original `Blob` is not altered.
|
192 |
+
* @since v15.7.0, v14.18.0
|
193 |
+
* @param start The starting index.
|
194 |
+
* @param end The ending index.
|
195 |
+
* @param type The content-type for the new `Blob`
|
196 |
+
*/
|
197 |
+
slice(start?: number, end?: number, type?: string): Blob;
|
198 |
+
/**
|
199 |
+
* Returns a promise that fulfills with the contents of the `Blob` decoded as a
|
200 |
+
* UTF-8 string.
|
201 |
+
* @since v15.7.0, v14.18.0
|
202 |
+
*/
|
203 |
+
text(): Promise<string>;
|
204 |
+
/**
|
205 |
+
* Returns a new `ReadableStream` that allows the content of the `Blob` to be read.
|
206 |
+
* @since v16.7.0
|
207 |
+
*/
|
208 |
+
stream(): WebReadableStream;
|
209 |
+
}
|
210 |
+
export interface FileOptions {
|
211 |
+
/**
|
212 |
+
* One of either `'transparent'` or `'native'`. When set to `'native'`, line endings in string source parts will be
|
213 |
+
* converted to the platform native line-ending as specified by `import { EOL } from 'node:os'`.
|
214 |
+
*/
|
215 |
+
endings?: "native" | "transparent";
|
216 |
+
/** The File content-type. */
|
217 |
+
type?: string;
|
218 |
+
/** The last modified date of the file. `Default`: Date.now(). */
|
219 |
+
lastModified?: number;
|
220 |
+
}
|
221 |
+
/**
|
222 |
+
* A [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) provides information about files.
|
223 |
+
* @since v19.2.0, v18.13.0
|
224 |
+
*/
|
225 |
+
export class File extends Blob {
|
226 |
+
constructor(sources: Array<BinaryLike | Blob>, fileName: string, options?: FileOptions);
|
227 |
+
/**
|
228 |
+
* The name of the `File`.
|
229 |
+
* @since v19.2.0, v18.13.0
|
230 |
+
*/
|
231 |
+
readonly name: string;
|
232 |
+
/**
|
233 |
+
* The last modified date of the `File`.
|
234 |
+
* @since v19.2.0, v18.13.0
|
235 |
+
*/
|
236 |
+
readonly lastModified: number;
|
237 |
+
}
|
238 |
+
export import atob = globalThis.atob;
|
239 |
+
export import btoa = globalThis.btoa;
|
240 |
+
|
241 |
+
global {
|
242 |
+
namespace NodeJS {
|
243 |
+
export { BufferEncoding };
|
244 |
+
}
|
245 |
+
// Buffer class
|
246 |
+
type BufferEncoding =
|
247 |
+
| "ascii"
|
248 |
+
| "utf8"
|
249 |
+
| "utf-8"
|
250 |
+
| "utf16le"
|
251 |
+
| "utf-16le"
|
252 |
+
| "ucs2"
|
253 |
+
| "ucs-2"
|
254 |
+
| "base64"
|
255 |
+
| "base64url"
|
256 |
+
| "latin1"
|
257 |
+
| "binary"
|
258 |
+
| "hex";
|
259 |
+
type WithImplicitCoercion<T> =
|
260 |
+
| T
|
261 |
+
| {
|
262 |
+
valueOf(): T;
|
263 |
+
};
|
264 |
+
/**
|
265 |
+
* Raw data is stored in instances of the Buffer class.
|
266 |
+
* A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized.
|
267 |
+
* Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'base64url'|'binary'(deprecated)|'hex'
|
268 |
+
*/
|
269 |
+
interface BufferConstructor {
|
270 |
+
// see buffer.buffer.d.ts for implementation specific to TypeScript 5.7 and later
|
271 |
+
// see ts5.6/buffer.buffer.d.ts for implementation specific to TypeScript 5.6 and earlier
|
272 |
+
|
273 |
+
/**
|
274 |
+
* Returns `true` if `obj` is a `Buffer`, `false` otherwise.
|
275 |
+
*
|
276 |
+
* ```js
|
277 |
+
* import { Buffer } from 'node:buffer';
|
278 |
+
*
|
279 |
+
* Buffer.isBuffer(Buffer.alloc(10)); // true
|
280 |
+
* Buffer.isBuffer(Buffer.from('foo')); // true
|
281 |
+
* Buffer.isBuffer('a string'); // false
|
282 |
+
* Buffer.isBuffer([]); // false
|
283 |
+
* Buffer.isBuffer(new Uint8Array(1024)); // false
|
284 |
+
* ```
|
285 |
+
* @since v0.1.101
|
286 |
+
*/
|
287 |
+
isBuffer(obj: any): obj is Buffer;
|
288 |
+
/**
|
289 |
+
* Returns `true` if `encoding` is the name of a supported character encoding,
|
290 |
+
* or `false` otherwise.
|
291 |
+
*
|
292 |
+
* ```js
|
293 |
+
* import { Buffer } from 'node:buffer';
|
294 |
+
*
|
295 |
+
* console.log(Buffer.isEncoding('utf8'));
|
296 |
+
* // Prints: true
|
297 |
+
*
|
298 |
+
* console.log(Buffer.isEncoding('hex'));
|
299 |
+
* // Prints: true
|
300 |
+
*
|
301 |
+
* console.log(Buffer.isEncoding('utf/8'));
|
302 |
+
* // Prints: false
|
303 |
+
*
|
304 |
+
* console.log(Buffer.isEncoding(''));
|
305 |
+
* // Prints: false
|
306 |
+
* ```
|
307 |
+
* @since v0.9.1
|
308 |
+
* @param encoding A character encoding name to check.
|
309 |
+
*/
|
310 |
+
isEncoding(encoding: string): encoding is BufferEncoding;
|
311 |
+
/**
|
312 |
+
* Returns the byte length of a string when encoded using `encoding`.
|
313 |
+
* This is not the same as [`String.prototype.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length), which does not account
|
314 |
+
* for the encoding that is used to convert the string into bytes.
|
315 |
+
*
|
316 |
+
* For `'base64'`, `'base64url'`, and `'hex'`, this function assumes valid input.
|
317 |
+
* For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
|
318 |
+
* return value might be greater than the length of a `Buffer` created from the
|
319 |
+
* string.
|
320 |
+
*
|
321 |
+
* ```js
|
322 |
+
* import { Buffer } from 'node:buffer';
|
323 |
+
*
|
324 |
+
* const str = '\u00bd + \u00bc = \u00be';
|
325 |
+
*
|
326 |
+
* console.log(`${str}: ${str.length} characters, ` +
|
327 |
+
* `${Buffer.byteLength(str, 'utf8')} bytes`);
|
328 |
+
* // Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
|
329 |
+
* ```
|
330 |
+
*
|
331 |
+
* When `string` is a
|
332 |
+
* `Buffer`/[`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)/[`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/-
|
333 |
+
* Reference/Global_Objects/TypedArray)/[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)/[`SharedArrayBuffer`](https://develop-
|
334 |
+
* er.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer), the byte length as reported by `.byteLength`is returned.
|
335 |
+
* @since v0.1.90
|
336 |
+
* @param string A value to calculate the length of.
|
337 |
+
* @param [encoding='utf8'] If `string` is a string, this is its encoding.
|
338 |
+
* @return The number of bytes contained within `string`.
|
339 |
+
*/
|
340 |
+
byteLength(
|
341 |
+
string: string | Buffer | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer,
|
342 |
+
encoding?: BufferEncoding,
|
343 |
+
): number;
|
344 |
+
/**
|
345 |
+
* Compares `buf1` to `buf2`, typically for the purpose of sorting arrays of `Buffer` instances. This is equivalent to calling `buf1.compare(buf2)`.
|
346 |
+
*
|
347 |
+
* ```js
|
348 |
+
* import { Buffer } from 'node:buffer';
|
349 |
+
*
|
350 |
+
* const buf1 = Buffer.from('1234');
|
351 |
+
* const buf2 = Buffer.from('0123');
|
352 |
+
* const arr = [buf1, buf2];
|
353 |
+
*
|
354 |
+
* console.log(arr.sort(Buffer.compare));
|
355 |
+
* // Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
|
356 |
+
* // (This result is equal to: [buf2, buf1].)
|
357 |
+
* ```
|
358 |
+
* @since v0.11.13
|
359 |
+
* @return Either `-1`, `0`, or `1`, depending on the result of the comparison. See `compare` for details.
|
360 |
+
*/
|
361 |
+
compare(buf1: Uint8Array, buf2: Uint8Array): -1 | 0 | 1;
|
362 |
+
/**
|
363 |
+
* This is the size (in bytes) of pre-allocated internal `Buffer` instances used
|
364 |
+
* for pooling. This value may be modified.
|
365 |
+
* @since v0.11.3
|
366 |
+
*/
|
367 |
+
poolSize: number;
|
368 |
+
}
|
369 |
+
interface Buffer {
|
370 |
+
// see buffer.buffer.d.ts for implementation specific to TypeScript 5.7 and later
|
371 |
+
// see ts5.6/buffer.buffer.d.ts for implementation specific to TypeScript 5.6 and earlier
|
372 |
+
|
373 |
+
/**
|
374 |
+
* Writes `string` to `buf` at `offset` according to the character encoding in`encoding`. The `length` parameter is the number of bytes to write. If `buf` did
|
375 |
+
* not contain enough space to fit the entire string, only part of `string` will be
|
376 |
+
* written. However, partially encoded characters will not be written.
|
377 |
+
*
|
378 |
+
* ```js
|
379 |
+
* import { Buffer } from 'node:buffer';
|
380 |
+
*
|
381 |
+
* const buf = Buffer.alloc(256);
|
382 |
+
*
|
383 |
+
* const len = buf.write('\u00bd + \u00bc = \u00be', 0);
|
384 |
+
*
|
385 |
+
* console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
|
386 |
+
* // Prints: 12 bytes: ½ + ¼ = ¾
|
387 |
+
*
|
388 |
+
* const buffer = Buffer.alloc(10);
|
389 |
+
*
|
390 |
+
* const length = buffer.write('abcd', 8);
|
391 |
+
*
|
392 |
+
* console.log(`${length} bytes: ${buffer.toString('utf8', 8, 10)}`);
|
393 |
+
* // Prints: 2 bytes : ab
|
394 |
+
* ```
|
395 |
+
* @since v0.1.90
|
396 |
+
* @param string String to write to `buf`.
|
397 |
+
* @param [offset=0] Number of bytes to skip before starting to write `string`.
|
398 |
+
* @param [length=buf.length - offset] Maximum number of bytes to write (written bytes will not exceed `buf.length - offset`).
|
399 |
+
* @param [encoding='utf8'] The character encoding of `string`.
|
400 |
+
* @return Number of bytes written.
|
401 |
+
*/
|
402 |
+
write(string: string, encoding?: BufferEncoding): number;
|
403 |
+
write(string: string, offset: number, encoding?: BufferEncoding): number;
|
404 |
+
write(string: string, offset: number, length: number, encoding?: BufferEncoding): number;
|
405 |
+
/**
|
406 |
+
* Decodes `buf` to a string according to the specified character encoding in`encoding`. `start` and `end` may be passed to decode only a subset of `buf`.
|
407 |
+
*
|
408 |
+
* If `encoding` is `'utf8'` and a byte sequence in the input is not valid UTF-8,
|
409 |
+
* then each invalid byte is replaced with the replacement character `U+FFFD`.
|
410 |
+
*
|
411 |
+
* The maximum length of a string instance (in UTF-16 code units) is available
|
412 |
+
* as {@link constants.MAX_STRING_LENGTH}.
|
413 |
+
*
|
414 |
+
* ```js
|
415 |
+
* import { Buffer } from 'node:buffer';
|
416 |
+
*
|
417 |
+
* const buf1 = Buffer.allocUnsafe(26);
|
418 |
+
*
|
419 |
+
* for (let i = 0; i < 26; i++) {
|
420 |
+
* // 97 is the decimal ASCII value for 'a'.
|
421 |
+
* buf1[i] = i + 97;
|
422 |
+
* }
|
423 |
+
*
|
424 |
+
* console.log(buf1.toString('utf8'));
|
425 |
+
* // Prints: abcdefghijklmnopqrstuvwxyz
|
426 |
+
* console.log(buf1.toString('utf8', 0, 5));
|
427 |
+
* // Prints: abcde
|
428 |
+
*
|
429 |
+
* const buf2 = Buffer.from('tést');
|
430 |
+
*
|
431 |
+
* console.log(buf2.toString('hex'));
|
432 |
+
* // Prints: 74c3a97374
|
433 |
+
* console.log(buf2.toString('utf8', 0, 3));
|
434 |
+
* // Prints: té
|
435 |
+
* console.log(buf2.toString(undefined, 0, 3));
|
436 |
+
* // Prints: té
|
437 |
+
* ```
|
438 |
+
* @since v0.1.90
|
439 |
+
* @param [encoding='utf8'] The character encoding to use.
|
440 |
+
* @param [start=0] The byte offset to start decoding at.
|
441 |
+
* @param [end=buf.length] The byte offset to stop decoding at (not inclusive).
|
442 |
+
*/
|
443 |
+
toString(encoding?: BufferEncoding, start?: number, end?: number): string;
|
444 |
+
/**
|
445 |
+
* Returns a JSON representation of `buf`. [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) implicitly calls
|
446 |
+
* this function when stringifying a `Buffer` instance.
|
447 |
+
*
|
448 |
+
* `Buffer.from()` accepts objects in the format returned from this method.
|
449 |
+
* In particular, `Buffer.from(buf.toJSON())` works like `Buffer.from(buf)`.
|
450 |
+
*
|
451 |
+
* ```js
|
452 |
+
* import { Buffer } from 'node:buffer';
|
453 |
+
*
|
454 |
+
* const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);
|
455 |
+
* const json = JSON.stringify(buf);
|
456 |
+
*
|
457 |
+
* console.log(json);
|
458 |
+
* // Prints: {"type":"Buffer","data":[1,2,3,4,5]}
|
459 |
+
*
|
460 |
+
* const copy = JSON.parse(json, (key, value) => {
|
461 |
+
* return value && value.type === 'Buffer' ?
|
462 |
+
* Buffer.from(value) :
|
463 |
+
* value;
|
464 |
+
* });
|
465 |
+
*
|
466 |
+
* console.log(copy);
|
467 |
+
* // Prints: <Buffer 01 02 03 04 05>
|
468 |
+
* ```
|
469 |
+
* @since v0.9.2
|
470 |
+
*/
|
471 |
+
toJSON(): {
|
472 |
+
type: "Buffer";
|
473 |
+
data: number[];
|
474 |
+
};
|
475 |
+
/**
|
476 |
+
* Returns `true` if both `buf` and `otherBuffer` have exactly the same bytes,`false` otherwise. Equivalent to `buf.compare(otherBuffer) === 0`.
|
477 |
+
*
|
478 |
+
* ```js
|
479 |
+
* import { Buffer } from 'node:buffer';
|
480 |
+
*
|
481 |
+
* const buf1 = Buffer.from('ABC');
|
482 |
+
* const buf2 = Buffer.from('414243', 'hex');
|
483 |
+
* const buf3 = Buffer.from('ABCD');
|
484 |
+
*
|
485 |
+
* console.log(buf1.equals(buf2));
|
486 |
+
* // Prints: true
|
487 |
+
* console.log(buf1.equals(buf3));
|
488 |
+
* // Prints: false
|
489 |
+
* ```
|
490 |
+
* @since v0.11.13
|
491 |
+
* @param otherBuffer A `Buffer` or {@link Uint8Array} with which to compare `buf`.
|
492 |
+
*/
|
493 |
+
equals(otherBuffer: Uint8Array): boolean;
|
494 |
+
/**
|
495 |
+
* Compares `buf` with `target` and returns a number indicating whether `buf`comes before, after, or is the same as `target` in sort order.
|
496 |
+
* Comparison is based on the actual sequence of bytes in each `Buffer`.
|
497 |
+
*
|
498 |
+
* * `0` is returned if `target` is the same as `buf`
|
499 |
+
* * `1` is returned if `target` should come _before_`buf` when sorted.
|
500 |
+
* * `-1` is returned if `target` should come _after_`buf` when sorted.
|
501 |
+
*
|
502 |
+
* ```js
|
503 |
+
* import { Buffer } from 'node:buffer';
|
504 |
+
*
|
505 |
+
* const buf1 = Buffer.from('ABC');
|
506 |
+
* const buf2 = Buffer.from('BCD');
|
507 |
+
* const buf3 = Buffer.from('ABCD');
|
508 |
+
*
|
509 |
+
* console.log(buf1.compare(buf1));
|
510 |
+
* // Prints: 0
|
511 |
+
* console.log(buf1.compare(buf2));
|
512 |
+
* // Prints: -1
|
513 |
+
* console.log(buf1.compare(buf3));
|
514 |
+
* // Prints: -1
|
515 |
+
* console.log(buf2.compare(buf1));
|
516 |
+
* // Prints: 1
|
517 |
+
* console.log(buf2.compare(buf3));
|
518 |
+
* // Prints: 1
|
519 |
+
* console.log([buf1, buf2, buf3].sort(Buffer.compare));
|
520 |
+
* // Prints: [ <Buffer 41 42 43>, <Buffer 41 42 43 44>, <Buffer 42 43 44> ]
|
521 |
+
* // (This result is equal to: [buf1, buf3, buf2].)
|
522 |
+
* ```
|
523 |
+
*
|
524 |
+
* The optional `targetStart`, `targetEnd`, `sourceStart`, and `sourceEnd` arguments can be used to limit the comparison to specific ranges within `target` and `buf` respectively.
|
525 |
+
*
|
526 |
+
* ```js
|
527 |
+
* import { Buffer } from 'node:buffer';
|
528 |
+
*
|
529 |
+
* const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
530 |
+
* const buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);
|
531 |
+
*
|
532 |
+
* console.log(buf1.compare(buf2, 5, 9, 0, 4));
|
533 |
+
* // Prints: 0
|
534 |
+
* console.log(buf1.compare(buf2, 0, 6, 4));
|
535 |
+
* // Prints: -1
|
536 |
+
* console.log(buf1.compare(buf2, 5, 6, 5));
|
537 |
+
* // Prints: 1
|
538 |
+
* ```
|
539 |
+
*
|
540 |
+
* `ERR_OUT_OF_RANGE` is thrown if `targetStart < 0`, `sourceStart < 0`, `targetEnd > target.byteLength`, or `sourceEnd > source.byteLength`.
|
541 |
+
* @since v0.11.13
|
542 |
+
* @param target A `Buffer` or {@link Uint8Array} with which to compare `buf`.
|
543 |
+
* @param [targetStart=0] The offset within `target` at which to begin comparison.
|
544 |
+
* @param [targetEnd=target.length] The offset within `target` at which to end comparison (not inclusive).
|
545 |
+
* @param [sourceStart=0] The offset within `buf` at which to begin comparison.
|
546 |
+
* @param [sourceEnd=buf.length] The offset within `buf` at which to end comparison (not inclusive).
|
547 |
+
*/
|
548 |
+
compare(
|
549 |
+
target: Uint8Array,
|
550 |
+
targetStart?: number,
|
551 |
+
targetEnd?: number,
|
552 |
+
sourceStart?: number,
|
553 |
+
sourceEnd?: number,
|
554 |
+
): -1 | 0 | 1;
|
555 |
+
/**
|
556 |
+
* Copies data from a region of `buf` to a region in `target`, even if the `target`memory region overlaps with `buf`.
|
557 |
+
*
|
558 |
+
* [`TypedArray.prototype.set()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set) performs the same operation, and is available
|
559 |
+
* for all TypedArrays, including Node.js `Buffer`s, although it takes
|
560 |
+
* different function arguments.
|
561 |
+
*
|
562 |
+
* ```js
|
563 |
+
* import { Buffer } from 'node:buffer';
|
564 |
+
*
|
565 |
+
* // Create two `Buffer` instances.
|
566 |
+
* const buf1 = Buffer.allocUnsafe(26);
|
567 |
+
* const buf2 = Buffer.allocUnsafe(26).fill('!');
|
568 |
+
*
|
569 |
+
* for (let i = 0; i < 26; i++) {
|
570 |
+
* // 97 is the decimal ASCII value for 'a'.
|
571 |
+
* buf1[i] = i + 97;
|
572 |
+
* }
|
573 |
+
*
|
574 |
+
* // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
|
575 |
+
* buf1.copy(buf2, 8, 16, 20);
|
576 |
+
* // This is equivalent to:
|
577 |
+
* // buf2.set(buf1.subarray(16, 20), 8);
|
578 |
+
*
|
579 |
+
* console.log(buf2.toString('ascii', 0, 25));
|
580 |
+
* // Prints: !!!!!!!!qrst!!!!!!!!!!!!!
|
581 |
+
* ```
|
582 |
+
*
|
583 |
+
* ```js
|
584 |
+
* import { Buffer } from 'node:buffer';
|
585 |
+
*
|
586 |
+
* // Create a `Buffer` and copy data from one region to an overlapping region
|
587 |
+
* // within the same `Buffer`.
|
588 |
+
*
|
589 |
+
* const buf = Buffer.allocUnsafe(26);
|
590 |
+
*
|
591 |
+
* for (let i = 0; i < 26; i++) {
|
592 |
+
* // 97 is the decimal ASCII value for 'a'.
|
593 |
+
* buf[i] = i + 97;
|
594 |
+
* }
|
595 |
+
*
|
596 |
+
* buf.copy(buf, 0, 4, 10);
|
597 |
+
*
|
598 |
+
* console.log(buf.toString());
|
599 |
+
* // Prints: efghijghijklmnopqrstuvwxyz
|
600 |
+
* ```
|
601 |
+
* @since v0.1.90
|
602 |
+
* @param target A `Buffer` or {@link Uint8Array} to copy into.
|
603 |
+
* @param [targetStart=0] The offset within `target` at which to begin writing.
|
604 |
+
* @param [sourceStart=0] The offset within `buf` from which to begin copying.
|
605 |
+
* @param [sourceEnd=buf.length] The offset within `buf` at which to stop copying (not inclusive).
|
606 |
+
* @return The number of bytes copied.
|
607 |
+
*/
|
608 |
+
copy(target: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
|
609 |
+
/**
|
610 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian.
|
611 |
+
*
|
612 |
+
* `value` is interpreted and written as a two's complement signed integer.
|
613 |
+
*
|
614 |
+
* ```js
|
615 |
+
* import { Buffer } from 'node:buffer';
|
616 |
+
*
|
617 |
+
* const buf = Buffer.allocUnsafe(8);
|
618 |
+
*
|
619 |
+
* buf.writeBigInt64BE(0x0102030405060708n, 0);
|
620 |
+
*
|
621 |
+
* console.log(buf);
|
622 |
+
* // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
623 |
+
* ```
|
624 |
+
* @since v12.0.0, v10.20.0
|
625 |
+
* @param value Number to be written to `buf`.
|
626 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
627 |
+
* @return `offset` plus the number of bytes written.
|
628 |
+
*/
|
629 |
+
writeBigInt64BE(value: bigint, offset?: number): number;
|
630 |
+
/**
|
631 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian.
|
632 |
+
*
|
633 |
+
* `value` is interpreted and written as a two's complement signed integer.
|
634 |
+
*
|
635 |
+
* ```js
|
636 |
+
* import { Buffer } from 'node:buffer';
|
637 |
+
*
|
638 |
+
* const buf = Buffer.allocUnsafe(8);
|
639 |
+
*
|
640 |
+
* buf.writeBigInt64LE(0x0102030405060708n, 0);
|
641 |
+
*
|
642 |
+
* console.log(buf);
|
643 |
+
* // Prints: <Buffer 08 07 06 05 04 03 02 01>
|
644 |
+
* ```
|
645 |
+
* @since v12.0.0, v10.20.0
|
646 |
+
* @param value Number to be written to `buf`.
|
647 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
648 |
+
* @return `offset` plus the number of bytes written.
|
649 |
+
*/
|
650 |
+
writeBigInt64LE(value: bigint, offset?: number): number;
|
651 |
+
/**
|
652 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian.
|
653 |
+
*
|
654 |
+
* This function is also available under the `writeBigUint64BE` alias.
|
655 |
+
*
|
656 |
+
* ```js
|
657 |
+
* import { Buffer } from 'node:buffer';
|
658 |
+
*
|
659 |
+
* const buf = Buffer.allocUnsafe(8);
|
660 |
+
*
|
661 |
+
* buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
|
662 |
+
*
|
663 |
+
* console.log(buf);
|
664 |
+
* // Prints: <Buffer de ca fa fe ca ce fa de>
|
665 |
+
* ```
|
666 |
+
* @since v12.0.0, v10.20.0
|
667 |
+
* @param value Number to be written to `buf`.
|
668 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
669 |
+
* @return `offset` plus the number of bytes written.
|
670 |
+
*/
|
671 |
+
writeBigUInt64BE(value: bigint, offset?: number): number;
|
672 |
+
/**
|
673 |
+
* @alias Buffer.writeBigUInt64BE
|
674 |
+
* @since v14.10.0, v12.19.0
|
675 |
+
*/
|
676 |
+
writeBigUint64BE(value: bigint, offset?: number): number;
|
677 |
+
/**
|
678 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian
|
679 |
+
*
|
680 |
+
* ```js
|
681 |
+
* import { Buffer } from 'node:buffer';
|
682 |
+
*
|
683 |
+
* const buf = Buffer.allocUnsafe(8);
|
684 |
+
*
|
685 |
+
* buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
|
686 |
+
*
|
687 |
+
* console.log(buf);
|
688 |
+
* // Prints: <Buffer de fa ce ca fe fa ca de>
|
689 |
+
* ```
|
690 |
+
*
|
691 |
+
* This function is also available under the `writeBigUint64LE` alias.
|
692 |
+
* @since v12.0.0, v10.20.0
|
693 |
+
* @param value Number to be written to `buf`.
|
694 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
695 |
+
* @return `offset` plus the number of bytes written.
|
696 |
+
*/
|
697 |
+
writeBigUInt64LE(value: bigint, offset?: number): number;
|
698 |
+
/**
|
699 |
+
* @alias Buffer.writeBigUInt64LE
|
700 |
+
* @since v14.10.0, v12.19.0
|
701 |
+
*/
|
702 |
+
writeBigUint64LE(value: bigint, offset?: number): number;
|
703 |
+
/**
|
704 |
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
|
705 |
+
* when `value` is anything other than an unsigned integer.
|
706 |
+
*
|
707 |
+
* This function is also available under the `writeUintLE` alias.
|
708 |
+
*
|
709 |
+
* ```js
|
710 |
+
* import { Buffer } from 'node:buffer';
|
711 |
+
*
|
712 |
+
* const buf = Buffer.allocUnsafe(6);
|
713 |
+
*
|
714 |
+
* buf.writeUIntLE(0x1234567890ab, 0, 6);
|
715 |
+
*
|
716 |
+
* console.log(buf);
|
717 |
+
* // Prints: <Buffer ab 90 78 56 34 12>
|
718 |
+
* ```
|
719 |
+
* @since v0.5.5
|
720 |
+
* @param value Number to be written to `buf`.
|
721 |
+
* @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
722 |
+
* @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
723 |
+
* @return `offset` plus the number of bytes written.
|
724 |
+
*/
|
725 |
+
writeUIntLE(value: number, offset: number, byteLength: number): number;
|
726 |
+
/**
|
727 |
+
* @alias Buffer.writeUIntLE
|
728 |
+
* @since v14.9.0, v12.19.0
|
729 |
+
*/
|
730 |
+
writeUintLE(value: number, offset: number, byteLength: number): number;
|
731 |
+
/**
|
732 |
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined
|
733 |
+
* when `value` is anything other than an unsigned integer.
|
734 |
+
*
|
735 |
+
* This function is also available under the `writeUintBE` alias.
|
736 |
+
*
|
737 |
+
* ```js
|
738 |
+
* import { Buffer } from 'node:buffer';
|
739 |
+
*
|
740 |
+
* const buf = Buffer.allocUnsafe(6);
|
741 |
+
*
|
742 |
+
* buf.writeUIntBE(0x1234567890ab, 0, 6);
|
743 |
+
*
|
744 |
+
* console.log(buf);
|
745 |
+
* // Prints: <Buffer 12 34 56 78 90 ab>
|
746 |
+
* ```
|
747 |
+
* @since v0.5.5
|
748 |
+
* @param value Number to be written to `buf`.
|
749 |
+
* @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
750 |
+
* @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
751 |
+
* @return `offset` plus the number of bytes written.
|
752 |
+
*/
|
753 |
+
writeUIntBE(value: number, offset: number, byteLength: number): number;
|
754 |
+
/**
|
755 |
+
* @alias Buffer.writeUIntBE
|
756 |
+
* @since v14.9.0, v12.19.0
|
757 |
+
*/
|
758 |
+
writeUintBE(value: number, offset: number, byteLength: number): number;
|
759 |
+
/**
|
760 |
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
|
761 |
+
* when `value` is anything other than a signed integer.
|
762 |
+
*
|
763 |
+
* ```js
|
764 |
+
* import { Buffer } from 'node:buffer';
|
765 |
+
*
|
766 |
+
* const buf = Buffer.allocUnsafe(6);
|
767 |
+
*
|
768 |
+
* buf.writeIntLE(0x1234567890ab, 0, 6);
|
769 |
+
*
|
770 |
+
* console.log(buf);
|
771 |
+
* // Prints: <Buffer ab 90 78 56 34 12>
|
772 |
+
* ```
|
773 |
+
* @since v0.11.15
|
774 |
+
* @param value Number to be written to `buf`.
|
775 |
+
* @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
776 |
+
* @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
777 |
+
* @return `offset` plus the number of bytes written.
|
778 |
+
*/
|
779 |
+
writeIntLE(value: number, offset: number, byteLength: number): number;
|
780 |
+
/**
|
781 |
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined when`value` is anything other than a
|
782 |
+
* signed integer.
|
783 |
+
*
|
784 |
+
* ```js
|
785 |
+
* import { Buffer } from 'node:buffer';
|
786 |
+
*
|
787 |
+
* const buf = Buffer.allocUnsafe(6);
|
788 |
+
*
|
789 |
+
* buf.writeIntBE(0x1234567890ab, 0, 6);
|
790 |
+
*
|
791 |
+
* console.log(buf);
|
792 |
+
* // Prints: <Buffer 12 34 56 78 90 ab>
|
793 |
+
* ```
|
794 |
+
* @since v0.11.15
|
795 |
+
* @param value Number to be written to `buf`.
|
796 |
+
* @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
797 |
+
* @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
798 |
+
* @return `offset` plus the number of bytes written.
|
799 |
+
*/
|
800 |
+
writeIntBE(value: number, offset: number, byteLength: number): number;
|
801 |
+
/**
|
802 |
+
* Reads an unsigned, big-endian 64-bit integer from `buf` at the specified`offset`.
|
803 |
+
*
|
804 |
+
* This function is also available under the `readBigUint64BE` alias.
|
805 |
+
*
|
806 |
+
* ```js
|
807 |
+
* import { Buffer } from 'node:buffer';
|
808 |
+
*
|
809 |
+
* const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
|
810 |
+
*
|
811 |
+
* console.log(buf.readBigUInt64BE(0));
|
812 |
+
* // Prints: 4294967295n
|
813 |
+
* ```
|
814 |
+
* @since v12.0.0, v10.20.0
|
815 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
816 |
+
*/
|
817 |
+
readBigUInt64BE(offset?: number): bigint;
|
818 |
+
/**
|
819 |
+
* @alias Buffer.readBigUInt64BE
|
820 |
+
* @since v14.10.0, v12.19.0
|
821 |
+
*/
|
822 |
+
readBigUint64BE(offset?: number): bigint;
|
823 |
+
/**
|
824 |
+
* Reads an unsigned, little-endian 64-bit integer from `buf` at the specified`offset`.
|
825 |
+
*
|
826 |
+
* This function is also available under the `readBigUint64LE` alias.
|
827 |
+
*
|
828 |
+
* ```js
|
829 |
+
* import { Buffer } from 'node:buffer';
|
830 |
+
*
|
831 |
+
* const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
|
832 |
+
*
|
833 |
+
* console.log(buf.readBigUInt64LE(0));
|
834 |
+
* // Prints: 18446744069414584320n
|
835 |
+
* ```
|
836 |
+
* @since v12.0.0, v10.20.0
|
837 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
838 |
+
*/
|
839 |
+
readBigUInt64LE(offset?: number): bigint;
|
840 |
+
/**
|
841 |
+
* @alias Buffer.readBigUInt64LE
|
842 |
+
* @since v14.10.0, v12.19.0
|
843 |
+
*/
|
844 |
+
readBigUint64LE(offset?: number): bigint;
|
845 |
+
/**
|
846 |
+
* Reads a signed, big-endian 64-bit integer from `buf` at the specified `offset`.
|
847 |
+
*
|
848 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed
|
849 |
+
* values.
|
850 |
+
* @since v12.0.0, v10.20.0
|
851 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
852 |
+
*/
|
853 |
+
readBigInt64BE(offset?: number): bigint;
|
854 |
+
/**
|
855 |
+
* Reads a signed, little-endian 64-bit integer from `buf` at the specified`offset`.
|
856 |
+
*
|
857 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed
|
858 |
+
* values.
|
859 |
+
* @since v12.0.0, v10.20.0
|
860 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
861 |
+
*/
|
862 |
+
readBigInt64LE(offset?: number): bigint;
|
863 |
+
/**
|
864 |
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an unsigned, little-endian integer supporting
|
865 |
+
* up to 48 bits of accuracy.
|
866 |
+
*
|
867 |
+
* This function is also available under the `readUintLE` alias.
|
868 |
+
*
|
869 |
+
* ```js
|
870 |
+
* import { Buffer } from 'node:buffer';
|
871 |
+
*
|
872 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
873 |
+
*
|
874 |
+
* console.log(buf.readUIntLE(0, 6).toString(16));
|
875 |
+
* // Prints: ab9078563412
|
876 |
+
* ```
|
877 |
+
* @since v0.11.15
|
878 |
+
* @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
879 |
+
* @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
880 |
+
*/
|
881 |
+
readUIntLE(offset: number, byteLength: number): number;
|
882 |
+
/**
|
883 |
+
* @alias Buffer.readUIntLE
|
884 |
+
* @since v14.9.0, v12.19.0
|
885 |
+
*/
|
886 |
+
readUintLE(offset: number, byteLength: number): number;
|
887 |
+
/**
|
888 |
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an unsigned big-endian integer supporting
|
889 |
+
* up to 48 bits of accuracy.
|
890 |
+
*
|
891 |
+
* This function is also available under the `readUintBE` alias.
|
892 |
+
*
|
893 |
+
* ```js
|
894 |
+
* import { Buffer } from 'node:buffer';
|
895 |
+
*
|
896 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
897 |
+
*
|
898 |
+
* console.log(buf.readUIntBE(0, 6).toString(16));
|
899 |
+
* // Prints: 1234567890ab
|
900 |
+
* console.log(buf.readUIntBE(1, 6).toString(16));
|
901 |
+
* // Throws ERR_OUT_OF_RANGE.
|
902 |
+
* ```
|
903 |
+
* @since v0.11.15
|
904 |
+
* @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
905 |
+
* @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
906 |
+
*/
|
907 |
+
readUIntBE(offset: number, byteLength: number): number;
|
908 |
+
/**
|
909 |
+
* @alias Buffer.readUIntBE
|
910 |
+
* @since v14.9.0, v12.19.0
|
911 |
+
*/
|
912 |
+
readUintBE(offset: number, byteLength: number): number;
|
913 |
+
/**
|
914 |
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a little-endian, two's complement signed value
|
915 |
+
* supporting up to 48 bits of accuracy.
|
916 |
+
*
|
917 |
+
* ```js
|
918 |
+
* import { Buffer } from 'node:buffer';
|
919 |
+
*
|
920 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
921 |
+
*
|
922 |
+
* console.log(buf.readIntLE(0, 6).toString(16));
|
923 |
+
* // Prints: -546f87a9cbee
|
924 |
+
* ```
|
925 |
+
* @since v0.11.15
|
926 |
+
* @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
927 |
+
* @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
928 |
+
*/
|
929 |
+
readIntLE(offset: number, byteLength: number): number;
|
930 |
+
/**
|
931 |
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a big-endian, two's complement signed value
|
932 |
+
* supporting up to 48 bits of accuracy.
|
933 |
+
*
|
934 |
+
* ```js
|
935 |
+
* import { Buffer } from 'node:buffer';
|
936 |
+
*
|
937 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
938 |
+
*
|
939 |
+
* console.log(buf.readIntBE(0, 6).toString(16));
|
940 |
+
* // Prints: 1234567890ab
|
941 |
+
* console.log(buf.readIntBE(1, 6).toString(16));
|
942 |
+
* // Throws ERR_OUT_OF_RANGE.
|
943 |
+
* console.log(buf.readIntBE(1, 0).toString(16));
|
944 |
+
* // Throws ERR_OUT_OF_RANGE.
|
945 |
+
* ```
|
946 |
+
* @since v0.11.15
|
947 |
+
* @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
948 |
+
* @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
949 |
+
*/
|
950 |
+
readIntBE(offset: number, byteLength: number): number;
|
951 |
+
/**
|
952 |
+
* Reads an unsigned 8-bit integer from `buf` at the specified `offset`.
|
953 |
+
*
|
954 |
+
* This function is also available under the `readUint8` alias.
|
955 |
+
*
|
956 |
+
* ```js
|
957 |
+
* import { Buffer } from 'node:buffer';
|
958 |
+
*
|
959 |
+
* const buf = Buffer.from([1, -2]);
|
960 |
+
*
|
961 |
+
* console.log(buf.readUInt8(0));
|
962 |
+
* // Prints: 1
|
963 |
+
* console.log(buf.readUInt8(1));
|
964 |
+
* // Prints: 254
|
965 |
+
* console.log(buf.readUInt8(2));
|
966 |
+
* // Throws ERR_OUT_OF_RANGE.
|
967 |
+
* ```
|
968 |
+
* @since v0.5.0
|
969 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
|
970 |
+
*/
|
971 |
+
readUInt8(offset?: number): number;
|
972 |
+
/**
|
973 |
+
* @alias Buffer.readUInt8
|
974 |
+
* @since v14.9.0, v12.19.0
|
975 |
+
*/
|
976 |
+
readUint8(offset?: number): number;
|
977 |
+
/**
|
978 |
+
* Reads an unsigned, little-endian 16-bit integer from `buf` at the specified `offset`.
|
979 |
+
*
|
980 |
+
* This function is also available under the `readUint16LE` alias.
|
981 |
+
*
|
982 |
+
* ```js
|
983 |
+
* import { Buffer } from 'node:buffer';
|
984 |
+
*
|
985 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56]);
|
986 |
+
*
|
987 |
+
* console.log(buf.readUInt16LE(0).toString(16));
|
988 |
+
* // Prints: 3412
|
989 |
+
* console.log(buf.readUInt16LE(1).toString(16));
|
990 |
+
* // Prints: 5634
|
991 |
+
* console.log(buf.readUInt16LE(2).toString(16));
|
992 |
+
* // Throws ERR_OUT_OF_RANGE.
|
993 |
+
* ```
|
994 |
+
* @since v0.5.5
|
995 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
996 |
+
*/
|
997 |
+
readUInt16LE(offset?: number): number;
|
998 |
+
/**
|
999 |
+
* @alias Buffer.readUInt16LE
|
1000 |
+
* @since v14.9.0, v12.19.0
|
1001 |
+
*/
|
1002 |
+
readUint16LE(offset?: number): number;
|
1003 |
+
/**
|
1004 |
+
* Reads an unsigned, big-endian 16-bit integer from `buf` at the specified`offset`.
|
1005 |
+
*
|
1006 |
+
* This function is also available under the `readUint16BE` alias.
|
1007 |
+
*
|
1008 |
+
* ```js
|
1009 |
+
* import { Buffer } from 'node:buffer';
|
1010 |
+
*
|
1011 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56]);
|
1012 |
+
*
|
1013 |
+
* console.log(buf.readUInt16BE(0).toString(16));
|
1014 |
+
* // Prints: 1234
|
1015 |
+
* console.log(buf.readUInt16BE(1).toString(16));
|
1016 |
+
* // Prints: 3456
|
1017 |
+
* ```
|
1018 |
+
* @since v0.5.5
|
1019 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
1020 |
+
*/
|
1021 |
+
readUInt16BE(offset?: number): number;
|
1022 |
+
/**
|
1023 |
+
* @alias Buffer.readUInt16BE
|
1024 |
+
* @since v14.9.0, v12.19.0
|
1025 |
+
*/
|
1026 |
+
readUint16BE(offset?: number): number;
|
1027 |
+
/**
|
1028 |
+
* Reads an unsigned, little-endian 32-bit integer from `buf` at the specified`offset`.
|
1029 |
+
*
|
1030 |
+
* This function is also available under the `readUint32LE` alias.
|
1031 |
+
*
|
1032 |
+
* ```js
|
1033 |
+
* import { Buffer } from 'node:buffer';
|
1034 |
+
*
|
1035 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
|
1036 |
+
*
|
1037 |
+
* console.log(buf.readUInt32LE(0).toString(16));
|
1038 |
+
* // Prints: 78563412
|
1039 |
+
* console.log(buf.readUInt32LE(1).toString(16));
|
1040 |
+
* // Throws ERR_OUT_OF_RANGE.
|
1041 |
+
* ```
|
1042 |
+
* @since v0.5.5
|
1043 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1044 |
+
*/
|
1045 |
+
readUInt32LE(offset?: number): number;
|
1046 |
+
/**
|
1047 |
+
* @alias Buffer.readUInt32LE
|
1048 |
+
* @since v14.9.0, v12.19.0
|
1049 |
+
*/
|
1050 |
+
readUint32LE(offset?: number): number;
|
1051 |
+
/**
|
1052 |
+
* Reads an unsigned, big-endian 32-bit integer from `buf` at the specified`offset`.
|
1053 |
+
*
|
1054 |
+
* This function is also available under the `readUint32BE` alias.
|
1055 |
+
*
|
1056 |
+
* ```js
|
1057 |
+
* import { Buffer } from 'node:buffer';
|
1058 |
+
*
|
1059 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
|
1060 |
+
*
|
1061 |
+
* console.log(buf.readUInt32BE(0).toString(16));
|
1062 |
+
* // Prints: 12345678
|
1063 |
+
* ```
|
1064 |
+
* @since v0.5.5
|
1065 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1066 |
+
*/
|
1067 |
+
readUInt32BE(offset?: number): number;
|
1068 |
+
/**
|
1069 |
+
* @alias Buffer.readUInt32BE
|
1070 |
+
* @since v14.9.0, v12.19.0
|
1071 |
+
*/
|
1072 |
+
readUint32BE(offset?: number): number;
|
1073 |
+
/**
|
1074 |
+
* Reads a signed 8-bit integer from `buf` at the specified `offset`.
|
1075 |
+
*
|
1076 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1077 |
+
*
|
1078 |
+
* ```js
|
1079 |
+
* import { Buffer } from 'node:buffer';
|
1080 |
+
*
|
1081 |
+
* const buf = Buffer.from([-1, 5]);
|
1082 |
+
*
|
1083 |
+
* console.log(buf.readInt8(0));
|
1084 |
+
* // Prints: -1
|
1085 |
+
* console.log(buf.readInt8(1));
|
1086 |
+
* // Prints: 5
|
1087 |
+
* console.log(buf.readInt8(2));
|
1088 |
+
* // Throws ERR_OUT_OF_RANGE.
|
1089 |
+
* ```
|
1090 |
+
* @since v0.5.0
|
1091 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
|
1092 |
+
*/
|
1093 |
+
readInt8(offset?: number): number;
|
1094 |
+
/**
|
1095 |
+
* Reads a signed, little-endian 16-bit integer from `buf` at the specified`offset`.
|
1096 |
+
*
|
1097 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1098 |
+
*
|
1099 |
+
* ```js
|
1100 |
+
* import { Buffer } from 'node:buffer';
|
1101 |
+
*
|
1102 |
+
* const buf = Buffer.from([0, 5]);
|
1103 |
+
*
|
1104 |
+
* console.log(buf.readInt16LE(0));
|
1105 |
+
* // Prints: 1280
|
1106 |
+
* console.log(buf.readInt16LE(1));
|
1107 |
+
* // Throws ERR_OUT_OF_RANGE.
|
1108 |
+
* ```
|
1109 |
+
* @since v0.5.5
|
1110 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
1111 |
+
*/
|
1112 |
+
readInt16LE(offset?: number): number;
|
1113 |
+
/**
|
1114 |
+
* Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`.
|
1115 |
+
*
|
1116 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1117 |
+
*
|
1118 |
+
* ```js
|
1119 |
+
* import { Buffer } from 'node:buffer';
|
1120 |
+
*
|
1121 |
+
* const buf = Buffer.from([0, 5]);
|
1122 |
+
*
|
1123 |
+
* console.log(buf.readInt16BE(0));
|
1124 |
+
* // Prints: 5
|
1125 |
+
* ```
|
1126 |
+
* @since v0.5.5
|
1127 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
1128 |
+
*/
|
1129 |
+
readInt16BE(offset?: number): number;
|
1130 |
+
/**
|
1131 |
+
* Reads a signed, little-endian 32-bit integer from `buf` at the specified`offset`.
|
1132 |
+
*
|
1133 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1134 |
+
*
|
1135 |
+
* ```js
|
1136 |
+
* import { Buffer } from 'node:buffer';
|
1137 |
+
*
|
1138 |
+
* const buf = Buffer.from([0, 0, 0, 5]);
|
1139 |
+
*
|
1140 |
+
* console.log(buf.readInt32LE(0));
|
1141 |
+
* // Prints: 83886080
|
1142 |
+
* console.log(buf.readInt32LE(1));
|
1143 |
+
* // Throws ERR_OUT_OF_RANGE.
|
1144 |
+
* ```
|
1145 |
+
* @since v0.5.5
|
1146 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1147 |
+
*/
|
1148 |
+
readInt32LE(offset?: number): number;
|
1149 |
+
/**
|
1150 |
+
* Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`.
|
1151 |
+
*
|
1152 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
1153 |
+
*
|
1154 |
+
* ```js
|
1155 |
+
* import { Buffer } from 'node:buffer';
|
1156 |
+
*
|
1157 |
+
* const buf = Buffer.from([0, 0, 0, 5]);
|
1158 |
+
*
|
1159 |
+
* console.log(buf.readInt32BE(0));
|
1160 |
+
* // Prints: 5
|
1161 |
+
* ```
|
1162 |
+
* @since v0.5.5
|
1163 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1164 |
+
*/
|
1165 |
+
readInt32BE(offset?: number): number;
|
1166 |
+
/**
|
1167 |
+
* Reads a 32-bit, little-endian float from `buf` at the specified `offset`.
|
1168 |
+
*
|
1169 |
+
* ```js
|
1170 |
+
* import { Buffer } from 'node:buffer';
|
1171 |
+
*
|
1172 |
+
* const buf = Buffer.from([1, 2, 3, 4]);
|
1173 |
+
*
|
1174 |
+
* console.log(buf.readFloatLE(0));
|
1175 |
+
* // Prints: 1.539989614439558e-36
|
1176 |
+
* console.log(buf.readFloatLE(1));
|
1177 |
+
* // Throws ERR_OUT_OF_RANGE.
|
1178 |
+
* ```
|
1179 |
+
* @since v0.11.15
|
1180 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1181 |
+
*/
|
1182 |
+
readFloatLE(offset?: number): number;
|
1183 |
+
/**
|
1184 |
+
* Reads a 32-bit, big-endian float from `buf` at the specified `offset`.
|
1185 |
+
*
|
1186 |
+
* ```js
|
1187 |
+
* import { Buffer } from 'node:buffer';
|
1188 |
+
*
|
1189 |
+
* const buf = Buffer.from([1, 2, 3, 4]);
|
1190 |
+
*
|
1191 |
+
* console.log(buf.readFloatBE(0));
|
1192 |
+
* // Prints: 2.387939260590663e-38
|
1193 |
+
* ```
|
1194 |
+
* @since v0.11.15
|
1195 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
1196 |
+
*/
|
1197 |
+
readFloatBE(offset?: number): number;
|
1198 |
+
/**
|
1199 |
+
* Reads a 64-bit, little-endian double from `buf` at the specified `offset`.
|
1200 |
+
*
|
1201 |
+
* ```js
|
1202 |
+
* import { Buffer } from 'node:buffer';
|
1203 |
+
*
|
1204 |
+
* const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
1205 |
+
*
|
1206 |
+
* console.log(buf.readDoubleLE(0));
|
1207 |
+
* // Prints: 5.447603722011605e-270
|
1208 |
+
* console.log(buf.readDoubleLE(1));
|
1209 |
+
* // Throws ERR_OUT_OF_RANGE.
|
1210 |
+
* ```
|
1211 |
+
* @since v0.11.15
|
1212 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
|
1213 |
+
*/
|
1214 |
+
readDoubleLE(offset?: number): number;
|
1215 |
+
/**
|
1216 |
+
* Reads a 64-bit, big-endian double from `buf` at the specified `offset`.
|
1217 |
+
*
|
1218 |
+
* ```js
|
1219 |
+
* import { Buffer } from 'node:buffer';
|
1220 |
+
*
|
1221 |
+
* const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
1222 |
+
*
|
1223 |
+
* console.log(buf.readDoubleBE(0));
|
1224 |
+
* // Prints: 8.20788039913184e-304
|
1225 |
+
* ```
|
1226 |
+
* @since v0.11.15
|
1227 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
|
1228 |
+
*/
|
1229 |
+
readDoubleBE(offset?: number): number;
|
1230 |
+
reverse(): this;
|
1231 |
+
/**
|
1232 |
+
* Interprets `buf` as an array of unsigned 16-bit integers and swaps the
|
1233 |
+
* byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 2.
|
1234 |
+
*
|
1235 |
+
* ```js
|
1236 |
+
* import { Buffer } from 'node:buffer';
|
1237 |
+
*
|
1238 |
+
* const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
1239 |
+
*
|
1240 |
+
* console.log(buf1);
|
1241 |
+
* // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
1242 |
+
*
|
1243 |
+
* buf1.swap16();
|
1244 |
+
*
|
1245 |
+
* console.log(buf1);
|
1246 |
+
* // Prints: <Buffer 02 01 04 03 06 05 08 07>
|
1247 |
+
*
|
1248 |
+
* const buf2 = Buffer.from([0x1, 0x2, 0x3]);
|
1249 |
+
*
|
1250 |
+
* buf2.swap16();
|
1251 |
+
* // Throws ERR_INVALID_BUFFER_SIZE.
|
1252 |
+
* ```
|
1253 |
+
*
|
1254 |
+
* One convenient use of `buf.swap16()` is to perform a fast in-place conversion
|
1255 |
+
* between UTF-16 little-endian and UTF-16 big-endian:
|
1256 |
+
*
|
1257 |
+
* ```js
|
1258 |
+
* import { Buffer } from 'node:buffer';
|
1259 |
+
*
|
1260 |
+
* const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
|
1261 |
+
* buf.swap16(); // Convert to big-endian UTF-16 text.
|
1262 |
+
* ```
|
1263 |
+
* @since v5.10.0
|
1264 |
+
* @return A reference to `buf`.
|
1265 |
+
*/
|
1266 |
+
swap16(): this;
|
1267 |
+
/**
|
1268 |
+
* Interprets `buf` as an array of unsigned 32-bit integers and swaps the
|
1269 |
+
* byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 4.
|
1270 |
+
*
|
1271 |
+
* ```js
|
1272 |
+
* import { Buffer } from 'node:buffer';
|
1273 |
+
*
|
1274 |
+
* const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
1275 |
+
*
|
1276 |
+
* console.log(buf1);
|
1277 |
+
* // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
1278 |
+
*
|
1279 |
+
* buf1.swap32();
|
1280 |
+
*
|
1281 |
+
* console.log(buf1);
|
1282 |
+
* // Prints: <Buffer 04 03 02 01 08 07 06 05>
|
1283 |
+
*
|
1284 |
+
* const buf2 = Buffer.from([0x1, 0x2, 0x3]);
|
1285 |
+
*
|
1286 |
+
* buf2.swap32();
|
1287 |
+
* // Throws ERR_INVALID_BUFFER_SIZE.
|
1288 |
+
* ```
|
1289 |
+
* @since v5.10.0
|
1290 |
+
* @return A reference to `buf`.
|
1291 |
+
*/
|
1292 |
+
swap32(): this;
|
1293 |
+
/**
|
1294 |
+
* Interprets `buf` as an array of 64-bit numbers and swaps byte order _in-place_.
|
1295 |
+
* Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 8.
|
1296 |
+
*
|
1297 |
+
* ```js
|
1298 |
+
* import { Buffer } from 'node:buffer';
|
1299 |
+
*
|
1300 |
+
* const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
1301 |
+
*
|
1302 |
+
* console.log(buf1);
|
1303 |
+
* // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
1304 |
+
*
|
1305 |
+
* buf1.swap64();
|
1306 |
+
*
|
1307 |
+
* console.log(buf1);
|
1308 |
+
* // Prints: <Buffer 08 07 06 05 04 03 02 01>
|
1309 |
+
*
|
1310 |
+
* const buf2 = Buffer.from([0x1, 0x2, 0x3]);
|
1311 |
+
*
|
1312 |
+
* buf2.swap64();
|
1313 |
+
* // Throws ERR_INVALID_BUFFER_SIZE.
|
1314 |
+
* ```
|
1315 |
+
* @since v6.3.0
|
1316 |
+
* @return A reference to `buf`.
|
1317 |
+
*/
|
1318 |
+
swap64(): this;
|
1319 |
+
/**
|
1320 |
+
* Writes `value` to `buf` at the specified `offset`. `value` must be a
|
1321 |
+
* valid unsigned 8-bit integer. Behavior is undefined when `value` is anything
|
1322 |
+
* other than an unsigned 8-bit integer.
|
1323 |
+
*
|
1324 |
+
* This function is also available under the `writeUint8` alias.
|
1325 |
+
*
|
1326 |
+
* ```js
|
1327 |
+
* import { Buffer } from 'node:buffer';
|
1328 |
+
*
|
1329 |
+
* const buf = Buffer.allocUnsafe(4);
|
1330 |
+
*
|
1331 |
+
* buf.writeUInt8(0x3, 0);
|
1332 |
+
* buf.writeUInt8(0x4, 1);
|
1333 |
+
* buf.writeUInt8(0x23, 2);
|
1334 |
+
* buf.writeUInt8(0x42, 3);
|
1335 |
+
*
|
1336 |
+
* console.log(buf);
|
1337 |
+
* // Prints: <Buffer 03 04 23 42>
|
1338 |
+
* ```
|
1339 |
+
* @since v0.5.0
|
1340 |
+
* @param value Number to be written to `buf`.
|
1341 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
|
1342 |
+
* @return `offset` plus the number of bytes written.
|
1343 |
+
*/
|
1344 |
+
writeUInt8(value: number, offset?: number): number;
|
1345 |
+
/**
|
1346 |
+
* @alias Buffer.writeUInt8
|
1347 |
+
* @since v14.9.0, v12.19.0
|
1348 |
+
*/
|
1349 |
+
writeUint8(value: number, offset?: number): number;
|
1350 |
+
/**
|
1351 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 16-bit integer. Behavior is undefined when `value` is
|
1352 |
+
* anything other than an unsigned 16-bit integer.
|
1353 |
+
*
|
1354 |
+
* This function is also available under the `writeUint16LE` alias.
|
1355 |
+
*
|
1356 |
+
* ```js
|
1357 |
+
* import { Buffer } from 'node:buffer';
|
1358 |
+
*
|
1359 |
+
* const buf = Buffer.allocUnsafe(4);
|
1360 |
+
*
|
1361 |
+
* buf.writeUInt16LE(0xdead, 0);
|
1362 |
+
* buf.writeUInt16LE(0xbeef, 2);
|
1363 |
+
*
|
1364 |
+
* console.log(buf);
|
1365 |
+
* // Prints: <Buffer ad de ef be>
|
1366 |
+
* ```
|
1367 |
+
* @since v0.5.5
|
1368 |
+
* @param value Number to be written to `buf`.
|
1369 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
1370 |
+
* @return `offset` plus the number of bytes written.
|
1371 |
+
*/
|
1372 |
+
writeUInt16LE(value: number, offset?: number): number;
|
1373 |
+
/**
|
1374 |
+
* @alias Buffer.writeUInt16LE
|
1375 |
+
* @since v14.9.0, v12.19.0
|
1376 |
+
*/
|
1377 |
+
writeUint16LE(value: number, offset?: number): number;
|
1378 |
+
/**
|
1379 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 16-bit integer. Behavior is undefined when `value`is anything other than an
|
1380 |
+
* unsigned 16-bit integer.
|
1381 |
+
*
|
1382 |
+
* This function is also available under the `writeUint16BE` alias.
|
1383 |
+
*
|
1384 |
+
* ```js
|
1385 |
+
* import { Buffer } from 'node:buffer';
|
1386 |
+
*
|
1387 |
+
* const buf = Buffer.allocUnsafe(4);
|
1388 |
+
*
|
1389 |
+
* buf.writeUInt16BE(0xdead, 0);
|
1390 |
+
* buf.writeUInt16BE(0xbeef, 2);
|
1391 |
+
*
|
1392 |
+
* console.log(buf);
|
1393 |
+
* // Prints: <Buffer de ad be ef>
|
1394 |
+
* ```
|
1395 |
+
* @since v0.5.5
|
1396 |
+
* @param value Number to be written to `buf`.
|
1397 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
1398 |
+
* @return `offset` plus the number of bytes written.
|
1399 |
+
*/
|
1400 |
+
writeUInt16BE(value: number, offset?: number): number;
|
1401 |
+
/**
|
1402 |
+
* @alias Buffer.writeUInt16BE
|
1403 |
+
* @since v14.9.0, v12.19.0
|
1404 |
+
*/
|
1405 |
+
writeUint16BE(value: number, offset?: number): number;
|
1406 |
+
/**
|
1407 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid unsigned 32-bit integer. Behavior is undefined when `value` is
|
1408 |
+
* anything other than an unsigned 32-bit integer.
|
1409 |
+
*
|
1410 |
+
* This function is also available under the `writeUint32LE` alias.
|
1411 |
+
*
|
1412 |
+
* ```js
|
1413 |
+
* import { Buffer } from 'node:buffer';
|
1414 |
+
*
|
1415 |
+
* const buf = Buffer.allocUnsafe(4);
|
1416 |
+
*
|
1417 |
+
* buf.writeUInt32LE(0xfeedface, 0);
|
1418 |
+
*
|
1419 |
+
* console.log(buf);
|
1420 |
+
* // Prints: <Buffer ce fa ed fe>
|
1421 |
+
* ```
|
1422 |
+
* @since v0.5.5
|
1423 |
+
* @param value Number to be written to `buf`.
|
1424 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1425 |
+
* @return `offset` plus the number of bytes written.
|
1426 |
+
*/
|
1427 |
+
writeUInt32LE(value: number, offset?: number): number;
|
1428 |
+
/**
|
1429 |
+
* @alias Buffer.writeUInt32LE
|
1430 |
+
* @since v14.9.0, v12.19.0
|
1431 |
+
*/
|
1432 |
+
writeUint32LE(value: number, offset?: number): number;
|
1433 |
+
/**
|
1434 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid unsigned 32-bit integer. Behavior is undefined when `value`is anything other than an
|
1435 |
+
* unsigned 32-bit integer.
|
1436 |
+
*
|
1437 |
+
* This function is also available under the `writeUint32BE` alias.
|
1438 |
+
*
|
1439 |
+
* ```js
|
1440 |
+
* import { Buffer } from 'node:buffer';
|
1441 |
+
*
|
1442 |
+
* const buf = Buffer.allocUnsafe(4);
|
1443 |
+
*
|
1444 |
+
* buf.writeUInt32BE(0xfeedface, 0);
|
1445 |
+
*
|
1446 |
+
* console.log(buf);
|
1447 |
+
* // Prints: <Buffer fe ed fa ce>
|
1448 |
+
* ```
|
1449 |
+
* @since v0.5.5
|
1450 |
+
* @param value Number to be written to `buf`.
|
1451 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1452 |
+
* @return `offset` plus the number of bytes written.
|
1453 |
+
*/
|
1454 |
+
writeUInt32BE(value: number, offset?: number): number;
|
1455 |
+
/**
|
1456 |
+
* @alias Buffer.writeUInt32BE
|
1457 |
+
* @since v14.9.0, v12.19.0
|
1458 |
+
*/
|
1459 |
+
writeUint32BE(value: number, offset?: number): number;
|
1460 |
+
/**
|
1461 |
+
* Writes `value` to `buf` at the specified `offset`. `value` must be a valid
|
1462 |
+
* signed 8-bit integer. Behavior is undefined when `value` is anything other than
|
1463 |
+
* a signed 8-bit integer.
|
1464 |
+
*
|
1465 |
+
* `value` is interpreted and written as a two's complement signed integer.
|
1466 |
+
*
|
1467 |
+
* ```js
|
1468 |
+
* import { Buffer } from 'node:buffer';
|
1469 |
+
*
|
1470 |
+
* const buf = Buffer.allocUnsafe(2);
|
1471 |
+
*
|
1472 |
+
* buf.writeInt8(2, 0);
|
1473 |
+
* buf.writeInt8(-2, 1);
|
1474 |
+
*
|
1475 |
+
* console.log(buf);
|
1476 |
+
* // Prints: <Buffer 02 fe>
|
1477 |
+
* ```
|
1478 |
+
* @since v0.5.0
|
1479 |
+
* @param value Number to be written to `buf`.
|
1480 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
|
1481 |
+
* @return `offset` plus the number of bytes written.
|
1482 |
+
*/
|
1483 |
+
writeInt8(value: number, offset?: number): number;
|
1484 |
+
/**
|
1485 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 16-bit integer. Behavior is undefined when `value` is
|
1486 |
+
* anything other than a signed 16-bit integer.
|
1487 |
+
*
|
1488 |
+
* The `value` is interpreted and written as a two's complement signed integer.
|
1489 |
+
*
|
1490 |
+
* ```js
|
1491 |
+
* import { Buffer } from 'node:buffer';
|
1492 |
+
*
|
1493 |
+
* const buf = Buffer.allocUnsafe(2);
|
1494 |
+
*
|
1495 |
+
* buf.writeInt16LE(0x0304, 0);
|
1496 |
+
*
|
1497 |
+
* console.log(buf);
|
1498 |
+
* // Prints: <Buffer 04 03>
|
1499 |
+
* ```
|
1500 |
+
* @since v0.5.5
|
1501 |
+
* @param value Number to be written to `buf`.
|
1502 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
1503 |
+
* @return `offset` plus the number of bytes written.
|
1504 |
+
*/
|
1505 |
+
writeInt16LE(value: number, offset?: number): number;
|
1506 |
+
/**
|
1507 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 16-bit integer. Behavior is undefined when `value` is
|
1508 |
+
* anything other than a signed 16-bit integer.
|
1509 |
+
*
|
1510 |
+
* The `value` is interpreted and written as a two's complement signed integer.
|
1511 |
+
*
|
1512 |
+
* ```js
|
1513 |
+
* import { Buffer } from 'node:buffer';
|
1514 |
+
*
|
1515 |
+
* const buf = Buffer.allocUnsafe(2);
|
1516 |
+
*
|
1517 |
+
* buf.writeInt16BE(0x0102, 0);
|
1518 |
+
*
|
1519 |
+
* console.log(buf);
|
1520 |
+
* // Prints: <Buffer 01 02>
|
1521 |
+
* ```
|
1522 |
+
* @since v0.5.5
|
1523 |
+
* @param value Number to be written to `buf`.
|
1524 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
1525 |
+
* @return `offset` plus the number of bytes written.
|
1526 |
+
*/
|
1527 |
+
writeInt16BE(value: number, offset?: number): number;
|
1528 |
+
/**
|
1529 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 32-bit integer. Behavior is undefined when `value` is
|
1530 |
+
* anything other than a signed 32-bit integer.
|
1531 |
+
*
|
1532 |
+
* The `value` is interpreted and written as a two's complement signed integer.
|
1533 |
+
*
|
1534 |
+
* ```js
|
1535 |
+
* import { Buffer } from 'node:buffer';
|
1536 |
+
*
|
1537 |
+
* const buf = Buffer.allocUnsafe(4);
|
1538 |
+
*
|
1539 |
+
* buf.writeInt32LE(0x05060708, 0);
|
1540 |
+
*
|
1541 |
+
* console.log(buf);
|
1542 |
+
* // Prints: <Buffer 08 07 06 05>
|
1543 |
+
* ```
|
1544 |
+
* @since v0.5.5
|
1545 |
+
* @param value Number to be written to `buf`.
|
1546 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1547 |
+
* @return `offset` plus the number of bytes written.
|
1548 |
+
*/
|
1549 |
+
writeInt32LE(value: number, offset?: number): number;
|
1550 |
+
/**
|
1551 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 32-bit integer. Behavior is undefined when `value` is
|
1552 |
+
* anything other than a signed 32-bit integer.
|
1553 |
+
*
|
1554 |
+
* The `value` is interpreted and written as a two's complement signed integer.
|
1555 |
+
*
|
1556 |
+
* ```js
|
1557 |
+
* import { Buffer } from 'node:buffer';
|
1558 |
+
*
|
1559 |
+
* const buf = Buffer.allocUnsafe(4);
|
1560 |
+
*
|
1561 |
+
* buf.writeInt32BE(0x01020304, 0);
|
1562 |
+
*
|
1563 |
+
* console.log(buf);
|
1564 |
+
* // Prints: <Buffer 01 02 03 04>
|
1565 |
+
* ```
|
1566 |
+
* @since v0.5.5
|
1567 |
+
* @param value Number to be written to `buf`.
|
1568 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1569 |
+
* @return `offset` plus the number of bytes written.
|
1570 |
+
*/
|
1571 |
+
writeInt32BE(value: number, offset?: number): number;
|
1572 |
+
/**
|
1573 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian. Behavior is
|
1574 |
+
* undefined when `value` is anything other than a JavaScript number.
|
1575 |
+
*
|
1576 |
+
* ```js
|
1577 |
+
* import { Buffer } from 'node:buffer';
|
1578 |
+
*
|
1579 |
+
* const buf = Buffer.allocUnsafe(4);
|
1580 |
+
*
|
1581 |
+
* buf.writeFloatLE(0xcafebabe, 0);
|
1582 |
+
*
|
1583 |
+
* console.log(buf);
|
1584 |
+
* // Prints: <Buffer bb fe 4a 4f>
|
1585 |
+
* ```
|
1586 |
+
* @since v0.11.15
|
1587 |
+
* @param value Number to be written to `buf`.
|
1588 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1589 |
+
* @return `offset` plus the number of bytes written.
|
1590 |
+
*/
|
1591 |
+
writeFloatLE(value: number, offset?: number): number;
|
1592 |
+
/**
|
1593 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian. Behavior is
|
1594 |
+
* undefined when `value` is anything other than a JavaScript number.
|
1595 |
+
*
|
1596 |
+
* ```js
|
1597 |
+
* import { Buffer } from 'node:buffer';
|
1598 |
+
*
|
1599 |
+
* const buf = Buffer.allocUnsafe(4);
|
1600 |
+
*
|
1601 |
+
* buf.writeFloatBE(0xcafebabe, 0);
|
1602 |
+
*
|
1603 |
+
* console.log(buf);
|
1604 |
+
* // Prints: <Buffer 4f 4a fe bb>
|
1605 |
+
* ```
|
1606 |
+
* @since v0.11.15
|
1607 |
+
* @param value Number to be written to `buf`.
|
1608 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
1609 |
+
* @return `offset` plus the number of bytes written.
|
1610 |
+
*/
|
1611 |
+
writeFloatBE(value: number, offset?: number): number;
|
1612 |
+
/**
|
1613 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything
|
1614 |
+
* other than a JavaScript number.
|
1615 |
+
*
|
1616 |
+
* ```js
|
1617 |
+
* import { Buffer } from 'node:buffer';
|
1618 |
+
*
|
1619 |
+
* const buf = Buffer.allocUnsafe(8);
|
1620 |
+
*
|
1621 |
+
* buf.writeDoubleLE(123.456, 0);
|
1622 |
+
*
|
1623 |
+
* console.log(buf);
|
1624 |
+
* // Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>
|
1625 |
+
* ```
|
1626 |
+
* @since v0.11.15
|
1627 |
+
* @param value Number to be written to `buf`.
|
1628 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
|
1629 |
+
* @return `offset` plus the number of bytes written.
|
1630 |
+
*/
|
1631 |
+
writeDoubleLE(value: number, offset?: number): number;
|
1632 |
+
/**
|
1633 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything
|
1634 |
+
* other than a JavaScript number.
|
1635 |
+
*
|
1636 |
+
* ```js
|
1637 |
+
* import { Buffer } from 'node:buffer';
|
1638 |
+
*
|
1639 |
+
* const buf = Buffer.allocUnsafe(8);
|
1640 |
+
*
|
1641 |
+
* buf.writeDoubleBE(123.456, 0);
|
1642 |
+
*
|
1643 |
+
* console.log(buf);
|
1644 |
+
* // Prints: <Buffer 40 5e dd 2f 1a 9f be 77>
|
1645 |
+
* ```
|
1646 |
+
* @since v0.11.15
|
1647 |
+
* @param value Number to be written to `buf`.
|
1648 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
|
1649 |
+
* @return `offset` plus the number of bytes written.
|
1650 |
+
*/
|
1651 |
+
writeDoubleBE(value: number, offset?: number): number;
|
1652 |
+
/**
|
1653 |
+
* Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
|
1654 |
+
* the entire `buf` will be filled:
|
1655 |
+
*
|
1656 |
+
* ```js
|
1657 |
+
* import { Buffer } from 'node:buffer';
|
1658 |
+
*
|
1659 |
+
* // Fill a `Buffer` with the ASCII character 'h'.
|
1660 |
+
*
|
1661 |
+
* const b = Buffer.allocUnsafe(50).fill('h');
|
1662 |
+
*
|
1663 |
+
* console.log(b.toString());
|
1664 |
+
* // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
|
1665 |
+
*
|
1666 |
+
* // Fill a buffer with empty string
|
1667 |
+
* const c = Buffer.allocUnsafe(5).fill('');
|
1668 |
+
*
|
1669 |
+
* console.log(c.fill(''));
|
1670 |
+
* // Prints: <Buffer 00 00 00 00 00>
|
1671 |
+
* ```
|
1672 |
+
*
|
1673 |
+
* `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or
|
1674 |
+
* integer. If the resulting integer is greater than `255` (decimal), `buf` will be
|
1675 |
+
* filled with `value & 255`.
|
1676 |
+
*
|
1677 |
+
* If the final write of a `fill()` operation falls on a multi-byte character,
|
1678 |
+
* then only the bytes of that character that fit into `buf` are written:
|
1679 |
+
*
|
1680 |
+
* ```js
|
1681 |
+
* import { Buffer } from 'node:buffer';
|
1682 |
+
*
|
1683 |
+
* // Fill a `Buffer` with character that takes up two bytes in UTF-8.
|
1684 |
+
*
|
1685 |
+
* console.log(Buffer.allocUnsafe(5).fill('\u0222'));
|
1686 |
+
* // Prints: <Buffer c8 a2 c8 a2 c8>
|
1687 |
+
* ```
|
1688 |
+
*
|
1689 |
+
* If `value` contains invalid characters, it is truncated; if no valid
|
1690 |
+
* fill data remains, an exception is thrown:
|
1691 |
+
*
|
1692 |
+
* ```js
|
1693 |
+
* import { Buffer } from 'node:buffer';
|
1694 |
+
*
|
1695 |
+
* const buf = Buffer.allocUnsafe(5);
|
1696 |
+
*
|
1697 |
+
* console.log(buf.fill('a'));
|
1698 |
+
* // Prints: <Buffer 61 61 61 61 61>
|
1699 |
+
* console.log(buf.fill('aazz', 'hex'));
|
1700 |
+
* // Prints: <Buffer aa aa aa aa aa>
|
1701 |
+
* console.log(buf.fill('zz', 'hex'));
|
1702 |
+
* // Throws an exception.
|
1703 |
+
* ```
|
1704 |
+
* @since v0.5.0
|
1705 |
+
* @param value The value with which to fill `buf`. Empty value (string, Uint8Array, Buffer) is coerced to `0`.
|
1706 |
+
* @param [offset=0] Number of bytes to skip before starting to fill `buf`.
|
1707 |
+
* @param [end=buf.length] Where to stop filling `buf` (not inclusive).
|
1708 |
+
* @param [encoding='utf8'] The encoding for `value` if `value` is a string.
|
1709 |
+
* @return A reference to `buf`.
|
1710 |
+
*/
|
1711 |
+
fill(value: string | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): this;
|
1712 |
+
/**
|
1713 |
+
* If `value` is:
|
1714 |
+
*
|
1715 |
+
* * a string, `value` is interpreted according to the character encoding in `encoding`.
|
1716 |
+
* * a `Buffer` or [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), `value` will be used in its entirety.
|
1717 |
+
* To compare a partial `Buffer`, use `buf.subarray`.
|
1718 |
+
* * a number, `value` will be interpreted as an unsigned 8-bit integer
|
1719 |
+
* value between `0` and `255`.
|
1720 |
+
*
|
1721 |
+
* ```js
|
1722 |
+
* import { Buffer } from 'node:buffer';
|
1723 |
+
*
|
1724 |
+
* const buf = Buffer.from('this is a buffer');
|
1725 |
+
*
|
1726 |
+
* console.log(buf.indexOf('this'));
|
1727 |
+
* // Prints: 0
|
1728 |
+
* console.log(buf.indexOf('is'));
|
1729 |
+
* // Prints: 2
|
1730 |
+
* console.log(buf.indexOf(Buffer.from('a buffer')));
|
1731 |
+
* // Prints: 8
|
1732 |
+
* console.log(buf.indexOf(97));
|
1733 |
+
* // Prints: 8 (97 is the decimal ASCII value for 'a')
|
1734 |
+
* console.log(buf.indexOf(Buffer.from('a buffer example')));
|
1735 |
+
* // Prints: -1
|
1736 |
+
* console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));
|
1737 |
+
* // Prints: 8
|
1738 |
+
*
|
1739 |
+
* const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
|
1740 |
+
*
|
1741 |
+
* console.log(utf16Buffer.indexOf('\u03a3', 0, 'utf16le'));
|
1742 |
+
* // Prints: 4
|
1743 |
+
* console.log(utf16Buffer.indexOf('\u03a3', -4, 'utf16le'));
|
1744 |
+
* // Prints: 6
|
1745 |
+
* ```
|
1746 |
+
*
|
1747 |
+
* If `value` is not a string, number, or `Buffer`, this method will throw a `TypeError`. If `value` is a number, it will be coerced to a valid byte value,
|
1748 |
+
* an integer between 0 and 255.
|
1749 |
+
*
|
1750 |
+
* If `byteOffset` is not a number, it will be coerced to a number. If the result
|
1751 |
+
* of coercion is `NaN` or `0`, then the entire buffer will be searched. This
|
1752 |
+
* behavior matches [`String.prototype.indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf).
|
1753 |
+
*
|
1754 |
+
* ```js
|
1755 |
+
* import { Buffer } from 'node:buffer';
|
1756 |
+
*
|
1757 |
+
* const b = Buffer.from('abcdef');
|
1758 |
+
*
|
1759 |
+
* // Passing a value that's a number, but not a valid byte.
|
1760 |
+
* // Prints: 2, equivalent to searching for 99 or 'c'.
|
1761 |
+
* console.log(b.indexOf(99.9));
|
1762 |
+
* console.log(b.indexOf(256 + 99));
|
1763 |
+
*
|
1764 |
+
* // Passing a byteOffset that coerces to NaN or 0.
|
1765 |
+
* // Prints: 1, searching the whole buffer.
|
1766 |
+
* console.log(b.indexOf('b', undefined));
|
1767 |
+
* console.log(b.indexOf('b', {}));
|
1768 |
+
* console.log(b.indexOf('b', null));
|
1769 |
+
* console.log(b.indexOf('b', []));
|
1770 |
+
* ```
|
1771 |
+
*
|
1772 |
+
* If `value` is an empty string or empty `Buffer` and `byteOffset` is less
|
1773 |
+
* than `buf.length`, `byteOffset` will be returned. If `value` is empty and`byteOffset` is at least `buf.length`, `buf.length` will be returned.
|
1774 |
+
* @since v1.5.0
|
1775 |
+
* @param value What to search for.
|
1776 |
+
* @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
|
1777 |
+
* @param [encoding='utf8'] If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`.
|
1778 |
+
* @return The index of the first occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
|
1779 |
+
*/
|
1780 |
+
indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
|
1781 |
+
/**
|
1782 |
+
* Identical to `buf.indexOf()`, except the last occurrence of `value` is found
|
1783 |
+
* rather than the first occurrence.
|
1784 |
+
*
|
1785 |
+
* ```js
|
1786 |
+
* import { Buffer } from 'node:buffer';
|
1787 |
+
*
|
1788 |
+
* const buf = Buffer.from('this buffer is a buffer');
|
1789 |
+
*
|
1790 |
+
* console.log(buf.lastIndexOf('this'));
|
1791 |
+
* // Prints: 0
|
1792 |
+
* console.log(buf.lastIndexOf('buffer'));
|
1793 |
+
* // Prints: 17
|
1794 |
+
* console.log(buf.lastIndexOf(Buffer.from('buffer')));
|
1795 |
+
* // Prints: 17
|
1796 |
+
* console.log(buf.lastIndexOf(97));
|
1797 |
+
* // Prints: 15 (97 is the decimal ASCII value for 'a')
|
1798 |
+
* console.log(buf.lastIndexOf(Buffer.from('yolo')));
|
1799 |
+
* // Prints: -1
|
1800 |
+
* console.log(buf.lastIndexOf('buffer', 5));
|
1801 |
+
* // Prints: 5
|
1802 |
+
* console.log(buf.lastIndexOf('buffer', 4));
|
1803 |
+
* // Prints: -1
|
1804 |
+
*
|
1805 |
+
* const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
|
1806 |
+
*
|
1807 |
+
* console.log(utf16Buffer.lastIndexOf('\u03a3', undefined, 'utf16le'));
|
1808 |
+
* // Prints: 6
|
1809 |
+
* console.log(utf16Buffer.lastIndexOf('\u03a3', -5, 'utf16le'));
|
1810 |
+
* // Prints: 4
|
1811 |
+
* ```
|
1812 |
+
*
|
1813 |
+
* If `value` is not a string, number, or `Buffer`, this method will throw a `TypeError`. If `value` is a number, it will be coerced to a valid byte value,
|
1814 |
+
* an integer between 0 and 255.
|
1815 |
+
*
|
1816 |
+
* If `byteOffset` is not a number, it will be coerced to a number. Any arguments
|
1817 |
+
* that coerce to `NaN`, like `{}` or `undefined`, will search the whole buffer.
|
1818 |
+
* This behavior matches [`String.prototype.lastIndexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf).
|
1819 |
+
*
|
1820 |
+
* ```js
|
1821 |
+
* import { Buffer } from 'node:buffer';
|
1822 |
+
*
|
1823 |
+
* const b = Buffer.from('abcdef');
|
1824 |
+
*
|
1825 |
+
* // Passing a value that's a number, but not a valid byte.
|
1826 |
+
* // Prints: 2, equivalent to searching for 99 or 'c'.
|
1827 |
+
* console.log(b.lastIndexOf(99.9));
|
1828 |
+
* console.log(b.lastIndexOf(256 + 99));
|
1829 |
+
*
|
1830 |
+
* // Passing a byteOffset that coerces to NaN.
|
1831 |
+
* // Prints: 1, searching the whole buffer.
|
1832 |
+
* console.log(b.lastIndexOf('b', undefined));
|
1833 |
+
* console.log(b.lastIndexOf('b', {}));
|
1834 |
+
*
|
1835 |
+
* // Passing a byteOffset that coerces to 0.
|
1836 |
+
* // Prints: -1, equivalent to passing 0.
|
1837 |
+
* console.log(b.lastIndexOf('b', null));
|
1838 |
+
* console.log(b.lastIndexOf('b', []));
|
1839 |
+
* ```
|
1840 |
+
*
|
1841 |
+
* If `value` is an empty string or empty `Buffer`, `byteOffset` will be returned.
|
1842 |
+
* @since v6.0.0
|
1843 |
+
* @param value What to search for.
|
1844 |
+
* @param [byteOffset=buf.length - 1] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
|
1845 |
+
* @param [encoding='utf8'] If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`.
|
1846 |
+
* @return The index of the last occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
|
1847 |
+
*/
|
1848 |
+
lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
|
1849 |
+
/**
|
1850 |
+
* Equivalent to `buf.indexOf() !== -1`.
|
1851 |
+
*
|
1852 |
+
* ```js
|
1853 |
+
* import { Buffer } from 'node:buffer';
|
1854 |
+
*
|
1855 |
+
* const buf = Buffer.from('this is a buffer');
|
1856 |
+
*
|
1857 |
+
* console.log(buf.includes('this'));
|
1858 |
+
* // Prints: true
|
1859 |
+
* console.log(buf.includes('is'));
|
1860 |
+
* // Prints: true
|
1861 |
+
* console.log(buf.includes(Buffer.from('a buffer')));
|
1862 |
+
* // Prints: true
|
1863 |
+
* console.log(buf.includes(97));
|
1864 |
+
* // Prints: true (97 is the decimal ASCII value for 'a')
|
1865 |
+
* console.log(buf.includes(Buffer.from('a buffer example')));
|
1866 |
+
* // Prints: false
|
1867 |
+
* console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
|
1868 |
+
* // Prints: true
|
1869 |
+
* console.log(buf.includes('this', 4));
|
1870 |
+
* // Prints: false
|
1871 |
+
* ```
|
1872 |
+
* @since v5.3.0
|
1873 |
+
* @param value What to search for.
|
1874 |
+
* @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
|
1875 |
+
* @param [encoding='utf8'] If `value` is a string, this is its encoding.
|
1876 |
+
* @return `true` if `value` was found in `buf`, `false` otherwise.
|
1877 |
+
*/
|
1878 |
+
includes(value: string | number | Buffer, byteOffset?: number, encoding?: BufferEncoding): boolean;
|
1879 |
+
}
|
1880 |
+
var Buffer: BufferConstructor;
|
1881 |
+
/**
|
1882 |
+
* Decodes a string of Base64-encoded data into bytes, and encodes those bytes
|
1883 |
+
* into a string using Latin-1 (ISO-8859-1).
|
1884 |
+
*
|
1885 |
+
* The `data` may be any JavaScript-value that can be coerced into a string.
|
1886 |
+
*
|
1887 |
+
* **This function is only provided for compatibility with legacy web platform APIs**
|
1888 |
+
* **and should never be used in new code, because they use strings to represent**
|
1889 |
+
* **binary data and predate the introduction of typed arrays in JavaScript.**
|
1890 |
+
* **For code running using Node.js APIs, converting between base64-encoded strings**
|
1891 |
+
* **and binary data should be performed using `Buffer.from(str, 'base64')` and `buf.toString('base64')`.**
|
1892 |
+
* @since v15.13.0, v14.17.0
|
1893 |
+
* @legacy Use `Buffer.from(data, 'base64')` instead.
|
1894 |
+
* @param data The Base64-encoded input string.
|
1895 |
+
*/
|
1896 |
+
function atob(data: string): string;
|
1897 |
+
/**
|
1898 |
+
* Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes
|
1899 |
+
* into a string using Base64.
|
1900 |
+
*
|
1901 |
+
* The `data` may be any JavaScript-value that can be coerced into a string.
|
1902 |
+
*
|
1903 |
+
* **This function is only provided for compatibility with legacy web platform APIs**
|
1904 |
+
* **and should never be used in new code, because they use strings to represent**
|
1905 |
+
* **binary data and predate the introduction of typed arrays in JavaScript.**
|
1906 |
+
* **For code running using Node.js APIs, converting between base64-encoded strings**
|
1907 |
+
* **and binary data should be performed using `Buffer.from(str, 'base64')` and `buf.toString('base64')`.**
|
1908 |
+
* @since v15.13.0, v14.17.0
|
1909 |
+
* @legacy Use `buf.toString('base64')` instead.
|
1910 |
+
* @param data An ASCII (Latin1) string.
|
1911 |
+
*/
|
1912 |
+
function btoa(data: string): string;
|
1913 |
+
interface Blob extends _Blob {}
|
1914 |
+
/**
|
1915 |
+
* `Blob` class is a global reference for `import { Blob } from 'node:buffer'`
|
1916 |
+
* https://nodejs.org/api/buffer.html#class-blob
|
1917 |
+
* @since v18.0.0
|
1918 |
+
*/
|
1919 |
+
var Blob: typeof globalThis extends { onmessage: any; Blob: infer T } ? T
|
1920 |
+
: typeof import("buffer").Blob;
|
1921 |
+
interface File extends _File {}
|
1922 |
+
/**
|
1923 |
+
* `File` class is a global reference for `import { File } from 'node:buffer'`
|
1924 |
+
* https://nodejs.org/api/buffer.html#class-file
|
1925 |
+
* @since v20.0.0
|
1926 |
+
*/
|
1927 |
+
var File: typeof globalThis extends { onmessage: any; File: infer T } ? T
|
1928 |
+
: typeof import("buffer").File;
|
1929 |
+
}
|
1930 |
+
}
|
1931 |
+
declare module "node:buffer" {
|
1932 |
+
export * from "buffer";
|
1933 |
+
}
|
clone/node_modules/@types/node/child_process.d.ts
ADDED
@@ -0,0 +1,1549 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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module provides the ability to spawn subprocesses in
|
3 |
+
* a manner that is similar, but not identical, to [`popen(3)`](http://man7.org/linux/man-pages/man3/popen.3.html). This capability
|
4 |
+
* is primarily provided by the {@link spawn} function:
|
5 |
+
*
|
6 |
+
* ```js
|
7 |
+
* import { spawn } from 'node:child_process';
|
8 |
+
* const ls = spawn('ls', ['-lh', '/usr']);
|
9 |
+
*
|
10 |
+
* ls.stdout.on('data', (data) => {
|
11 |
+
* console.log(`stdout: ${data}`);
|
12 |
+
* });
|
13 |
+
*
|
14 |
+
* ls.stderr.on('data', (data) => {
|
15 |
+
* console.error(`stderr: ${data}`);
|
16 |
+
* });
|
17 |
+
*
|
18 |
+
* ls.on('close', (code) => {
|
19 |
+
* console.log(`child process exited with code ${code}`);
|
20 |
+
* });
|
21 |
+
* ```
|
22 |
+
*
|
23 |
+
* By default, pipes for `stdin`, `stdout`, and `stderr` are established between
|
24 |
+
* the parent Node.js process and the spawned subprocess. These pipes have
|
25 |
+
* limited (and platform-specific) capacity. If the subprocess writes to
|
26 |
+
* 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
|
28 |
+
* identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }` option if the output will not be consumed.
|
29 |
+
*
|
30 |
+
* The command lookup is performed using the `options.env.PATH` environment
|
31 |
+
* variable if `env` is in the `options` object. Otherwise, `process.env.PATH` is
|
32 |
+
* used. If `options.env` is set without `PATH`, lookup on Unix is performed
|
33 |
+
* on a default search path search of `/usr/bin:/bin` (see your operating system's
|
34 |
+
* manual for execvpe/execvp), on Windows the current processes environment
|
35 |
+
* variable `PATH` is used.
|
36 |
+
*
|
37 |
+
* On Windows, environment variables are case-insensitive. Node.js
|
38 |
+
* lexicographically sorts the `env` keys and uses the first one that
|
39 |
+
* case-insensitively matches. Only first (in lexicographic order) entry will be
|
40 |
+
* passed to the subprocess. This might lead to issues on Windows when passing
|
41 |
+
* objects to the `env` option that have multiple variants of the same key, such as `PATH` and `Path`.
|
42 |
+
*
|
43 |
+
* The {@link spawn} method spawns the child process asynchronously,
|
44 |
+
* without blocking the Node.js event loop. The {@link spawnSync} function provides equivalent functionality in a synchronous manner that blocks
|
45 |
+
* the event loop until the spawned process either exits or is terminated.
|
46 |
+
*
|
47 |
+
* For convenience, the `node:child_process` module provides a handful of
|
48 |
+
* synchronous and asynchronous alternatives to {@link spawn} and {@link spawnSync}. Each of these alternatives are implemented on
|
49 |
+
* top of {@link spawn} or {@link spawnSync}.
|
50 |
+
*
|
51 |
+
* * {@link exec}: spawns a shell and runs a command within that
|
52 |
+
* shell, passing the `stdout` and `stderr` to a callback function when
|
53 |
+
* complete.
|
54 |
+
* * {@link execFile}: similar to {@link exec} except
|
55 |
+
* that it spawns the command directly without first spawning a shell by
|
56 |
+
* default.
|
57 |
+
* * {@link fork}: spawns a new Node.js process and invokes a
|
58 |
+
* specified module with an IPC communication channel established that allows
|
59 |
+
* sending messages between parent and child.
|
60 |
+
* * {@link execSync}: a synchronous version of {@link exec} that will block the Node.js event loop.
|
61 |
+
* * {@link execFileSync}: a synchronous version of {@link execFile} that will block the Node.js event loop.
|
62 |
+
*
|
63 |
+
* For certain use cases, such as automating shell scripts, the `synchronous counterparts` may be more convenient. In many cases, however,
|
64 |
+
* the synchronous methods can have significant impact on performance due to
|
65 |
+
* stalling the event loop while spawned processes complete.
|
66 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/child_process.js)
|
67 |
+
*/
|
68 |
+
declare module "child_process" {
|
69 |
+
import { ObjectEncodingOptions } from "node:fs";
|
70 |
+
import { Abortable, EventEmitter } from "node:events";
|
71 |
+
import * as dgram from "node:dgram";
|
72 |
+
import * as net from "node:net";
|
73 |
+
import { Pipe, Readable, Stream, Writable } from "node:stream";
|
74 |
+
import { URL } from "node:url";
|
75 |
+
type Serializable = string | object | number | boolean | bigint;
|
76 |
+
type SendHandle = net.Socket | net.Server | dgram.Socket | undefined;
|
77 |
+
/**
|
78 |
+
* Instances of the `ChildProcess` represent spawned child processes.
|
79 |
+
*
|
80 |
+
* Instances of `ChildProcess` are not intended to be created directly. Rather,
|
81 |
+
* use the {@link spawn}, {@link exec},{@link execFile}, or {@link fork} methods to create
|
82 |
+
* instances of `ChildProcess`.
|
83 |
+
* @since v2.2.0
|
84 |
+
*/
|
85 |
+
class ChildProcess extends EventEmitter {
|
86 |
+
/**
|
87 |
+
* A `Writable Stream` that represents the child process's `stdin`.
|
88 |
+
*
|
89 |
+
* If a child process waits to read all of its input, the child will not continue
|
90 |
+
* until this stream has been closed via `end()`.
|
91 |
+
*
|
92 |
+
* If the child was spawned with `stdio[0]` set to anything other than `'pipe'`,
|
93 |
+
* then this will be `null`.
|
94 |
+
*
|
95 |
+
* `subprocess.stdin` is an alias for `subprocess.stdio[0]`. Both properties will
|
96 |
+
* refer to the same value.
|
97 |
+
*
|
98 |
+
* The `subprocess.stdin` property can be `null` or `undefined` if the child process could not be successfully spawned.
|
99 |
+
* @since v0.1.90
|
100 |
+
*/
|
101 |
+
stdin: Writable | null;
|
102 |
+
/**
|
103 |
+
* A `Readable Stream` that represents the child process's `stdout`.
|
104 |
+
*
|
105 |
+
* If the child was spawned with `stdio[1]` set to anything other than `'pipe'`,
|
106 |
+
* then this will be `null`.
|
107 |
+
*
|
108 |
+
* `subprocess.stdout` is an alias for `subprocess.stdio[1]`. Both properties will
|
109 |
+
* refer to the same value.
|
110 |
+
*
|
111 |
+
* ```js
|
112 |
+
* import { spawn } from 'node:child_process';
|
113 |
+
*
|
114 |
+
* const subprocess = spawn('ls');
|
115 |
+
*
|
116 |
+
* subprocess.stdout.on('data', (data) => {
|
117 |
+
* console.log(`Received chunk ${data}`);
|
118 |
+
* });
|
119 |
+
* ```
|
120 |
+
*
|
121 |
+
* The `subprocess.stdout` property can be `null` or `undefined` if the child process could not be successfully spawned.
|
122 |
+
* @since v0.1.90
|
123 |
+
*/
|
124 |
+
stdout: Readable | null;
|
125 |
+
/**
|
126 |
+
* A `Readable Stream` that represents the child process's `stderr`.
|
127 |
+
*
|
128 |
+
* If the child was spawned with `stdio[2]` set to anything other than `'pipe'`,
|
129 |
+
* then this will be `null`.
|
130 |
+
*
|
131 |
+
* `subprocess.stderr` is an alias for `subprocess.stdio[2]`. Both properties will
|
132 |
+
* refer to the same value.
|
133 |
+
*
|
134 |
+
* The `subprocess.stderr` property can be `null` or `undefined` if the child process could not be successfully spawned.
|
135 |
+
* @since v0.1.90
|
136 |
+
*/
|
137 |
+
stderr: Readable | null;
|
138 |
+
/**
|
139 |
+
* The `subprocess.channel` property is a reference to the child's IPC channel. If
|
140 |
+
* no IPC channel exists, this property is `undefined`.
|
141 |
+
* @since v7.1.0
|
142 |
+
*/
|
143 |
+
readonly channel?: Pipe | null | undefined;
|
144 |
+
/**
|
145 |
+
* A sparse array of pipes to the child process, corresponding with positions in
|
146 |
+
* the `stdio` option passed to {@link spawn} that have been set
|
147 |
+
* to the value `'pipe'`. `subprocess.stdio[0]`, `subprocess.stdio[1]`, and `subprocess.stdio[2]` are also available as `subprocess.stdin`, `subprocess.stdout`, and `subprocess.stderr`,
|
148 |
+
* respectively.
|
149 |
+
*
|
150 |
+
* In the following example, only the child's fd `1` (stdout) is configured as a
|
151 |
+
* pipe, so only the parent's `subprocess.stdio[1]` is a stream, all other values
|
152 |
+
* in the array are `null`.
|
153 |
+
*
|
154 |
+
* ```js
|
155 |
+
* import assert from 'node:assert';
|
156 |
+
* import fs from 'node:fs';
|
157 |
+
* import child_process from 'node:child_process';
|
158 |
+
*
|
159 |
+
* const subprocess = child_process.spawn('ls', {
|
160 |
+
* stdio: [
|
161 |
+
* 0, // Use parent's stdin for child.
|
162 |
+
* 'pipe', // Pipe child's stdout to parent.
|
163 |
+
* fs.openSync('err.out', 'w'), // Direct child's stderr to a file.
|
164 |
+
* ],
|
165 |
+
* });
|
166 |
+
*
|
167 |
+
* assert.strictEqual(subprocess.stdio[0], null);
|
168 |
+
* assert.strictEqual(subprocess.stdio[0], subprocess.stdin);
|
169 |
+
*
|
170 |
+
* assert(subprocess.stdout);
|
171 |
+
* assert.strictEqual(subprocess.stdio[1], subprocess.stdout);
|
172 |
+
*
|
173 |
+
* assert.strictEqual(subprocess.stdio[2], null);
|
174 |
+
* assert.strictEqual(subprocess.stdio[2], subprocess.stderr);
|
175 |
+
* ```
|
176 |
+
*
|
177 |
+
* The `subprocess.stdio` property can be `undefined` if the child process could
|
178 |
+
* not be successfully spawned.
|
179 |
+
* @since v0.7.10
|
180 |
+
*/
|
181 |
+
readonly stdio: [
|
182 |
+
Writable | null,
|
183 |
+
// stdin
|
184 |
+
Readable | null,
|
185 |
+
// stdout
|
186 |
+
Readable | null,
|
187 |
+
// stderr
|
188 |
+
Readable | Writable | null | undefined,
|
189 |
+
// extra
|
190 |
+
Readable | Writable | null | undefined, // extra
|
191 |
+
];
|
192 |
+
/**
|
193 |
+
* The `subprocess.killed` property indicates whether the child process
|
194 |
+
* successfully received a signal from `subprocess.kill()`. The `killed` property
|
195 |
+
* does not indicate that the child process has been terminated.
|
196 |
+
* @since v0.5.10
|
197 |
+
*/
|
198 |
+
readonly killed: boolean;
|
199 |
+
/**
|
200 |
+
* Returns the process identifier (PID) of the child process. If the child process
|
201 |
+
* fails to spawn due to errors, then the value is `undefined` and `error` is
|
202 |
+
* emitted.
|
203 |
+
*
|
204 |
+
* ```js
|
205 |
+
* import { spawn } from 'node:child_process';
|
206 |
+
* const grep = spawn('grep', ['ssh']);
|
207 |
+
*
|
208 |
+
* console.log(`Spawned child pid: ${grep.pid}`);
|
209 |
+
* grep.stdin.end();
|
210 |
+
* ```
|
211 |
+
* @since v0.1.90
|
212 |
+
*/
|
213 |
+
readonly pid?: number | undefined;
|
214 |
+
/**
|
215 |
+
* The `subprocess.connected` property indicates whether it is still possible to
|
216 |
+
* send and receive messages from a child process. When `subprocess.connected` is `false`, it is no longer possible to send or receive messages.
|
217 |
+
* @since v0.7.2
|
218 |
+
*/
|
219 |
+
readonly connected: boolean;
|
220 |
+
/**
|
221 |
+
* The `subprocess.exitCode` property indicates the exit code of the child process.
|
222 |
+
* If the child process is still running, the field will be `null`.
|
223 |
+
*/
|
224 |
+
readonly exitCode: number | null;
|
225 |
+
/**
|
226 |
+
* The `subprocess.signalCode` property indicates the signal received by
|
227 |
+
* the child process if any, else `null`.
|
228 |
+
*/
|
229 |
+
readonly signalCode: NodeJS.Signals | null;
|
230 |
+
/**
|
231 |
+
* The `subprocess.spawnargs` property represents the full list of command-line
|
232 |
+
* arguments the child process was launched with.
|
233 |
+
*/
|
234 |
+
readonly spawnargs: string[];
|
235 |
+
/**
|
236 |
+
* The `subprocess.spawnfile` property indicates the executable file name of
|
237 |
+
* the child process that is launched.
|
238 |
+
*
|
239 |
+
* For {@link fork}, its value will be equal to `process.execPath`.
|
240 |
+
* For {@link spawn}, its value will be the name of
|
241 |
+
* the executable file.
|
242 |
+
* For {@link exec}, its value will be the name of the shell
|
243 |
+
* in which the child process is launched.
|
244 |
+
*/
|
245 |
+
readonly spawnfile: string;
|
246 |
+
/**
|
247 |
+
* The `subprocess.kill()` method sends a signal to the child process. If no
|
248 |
+
* argument is given, the process will be sent the `'SIGTERM'` signal. See [`signal(7)`](http://man7.org/linux/man-pages/man7/signal.7.html) for a list of available signals. This function
|
249 |
+
* returns `true` if [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) succeeds, and `false` otherwise.
|
250 |
+
*
|
251 |
+
* ```js
|
252 |
+
* import { spawn } from 'node:child_process';
|
253 |
+
* const grep = spawn('grep', ['ssh']);
|
254 |
+
*
|
255 |
+
* grep.on('close', (code, signal) => {
|
256 |
+
* console.log(
|
257 |
+
* `child process terminated due to receipt of signal ${signal}`);
|
258 |
+
* });
|
259 |
+
*
|
260 |
+
* // Send SIGHUP to process.
|
261 |
+
* grep.kill('SIGHUP');
|
262 |
+
* ```
|
263 |
+
*
|
264 |
+
* The `ChildProcess` object may emit an `'error'` event if the signal
|
265 |
+
* cannot be delivered. Sending a signal to a child process that has already exited
|
266 |
+
* is not an error but may have unforeseen consequences. Specifically, if the
|
267 |
+
* process identifier (PID) has been reassigned to another process, the signal will
|
268 |
+
* be delivered to that process instead which can have unexpected results.
|
269 |
+
*
|
270 |
+
* While the function is called `kill`, the signal delivered to the child process
|
271 |
+
* may not actually terminate the process.
|
272 |
+
*
|
273 |
+
* See [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) for reference.
|
274 |
+
*
|
275 |
+
* On Windows, where POSIX signals do not exist, the `signal` argument will be
|
276 |
+
* ignored, and the process will be killed forcefully and abruptly (similar to `'SIGKILL'`).
|
277 |
+
* See `Signal Events` for more details.
|
278 |
+
*
|
279 |
+
* On Linux, child processes of child processes will not be terminated
|
280 |
+
* when attempting to kill their parent. This is likely to happen when running a
|
281 |
+
* new process in a shell or with the use of the `shell` option of `ChildProcess`:
|
282 |
+
*
|
283 |
+
* ```js
|
284 |
+
* 'use strict';
|
285 |
+
* import { spawn } from 'node:child_process';
|
286 |
+
*
|
287 |
+
* const subprocess = spawn(
|
288 |
+
* 'sh',
|
289 |
+
* [
|
290 |
+
* '-c',
|
291 |
+
* `node -e "setInterval(() => {
|
292 |
+
* console.log(process.pid, 'is alive')
|
293 |
+
* }, 500);"`,
|
294 |
+
* ], {
|
295 |
+
* stdio: ['inherit', 'inherit', 'inherit'],
|
296 |
+
* },
|
297 |
+
* );
|
298 |
+
*
|
299 |
+
* setTimeout(() => {
|
300 |
+
* subprocess.kill(); // Does not terminate the Node.js process in the shell.
|
301 |
+
* }, 2000);
|
302 |
+
* ```
|
303 |
+
* @since v0.1.90
|
304 |
+
*/
|
305 |
+
kill(signal?: NodeJS.Signals | number): boolean;
|
306 |
+
/**
|
307 |
+
* Calls {@link ChildProcess.kill} with `'SIGTERM'`.
|
308 |
+
* @since v20.5.0
|
309 |
+
*/
|
310 |
+
[Symbol.dispose](): void;
|
311 |
+
/**
|
312 |
+
* When an IPC channel has been established between the parent and child (
|
313 |
+
* i.e. when using {@link fork}), the `subprocess.send()` method can
|
314 |
+
* be used to send messages to the child process. When the child process is a
|
315 |
+
* Node.js instance, these messages can be received via the `'message'` event.
|
316 |
+
*
|
317 |
+
* The message goes through serialization and parsing. The resulting
|
318 |
+
* message might not be the same as what is originally sent.
|
319 |
+
*
|
320 |
+
* For example, in the parent script:
|
321 |
+
*
|
322 |
+
* ```js
|
323 |
+
* import cp from 'node:child_process';
|
324 |
+
* const n = cp.fork(`${__dirname}/sub.js`);
|
325 |
+
*
|
326 |
+
* n.on('message', (m) => {
|
327 |
+
* console.log('PARENT got message:', m);
|
328 |
+
* });
|
329 |
+
*
|
330 |
+
* // Causes the child to print: CHILD got message: { hello: 'world' }
|
331 |
+
* n.send({ hello: 'world' });
|
332 |
+
* ```
|
333 |
+
*
|
334 |
+
* And then the child script, `'sub.js'` might look like this:
|
335 |
+
*
|
336 |
+
* ```js
|
337 |
+
* process.on('message', (m) => {
|
338 |
+
* console.log('CHILD got message:', m);
|
339 |
+
* });
|
340 |
+
*
|
341 |
+
* // Causes the parent to print: PARENT got message: { foo: 'bar', baz: null }
|
342 |
+
* process.send({ foo: 'bar', baz: NaN });
|
343 |
+
* ```
|
344 |
+
*
|
345 |
+
* Child Node.js processes will have a `process.send()` method of their own
|
346 |
+
* that allows the child to send messages back to the parent.
|
347 |
+
*
|
348 |
+
* There is a special case when sending a `{cmd: 'NODE_foo'}` message. Messages
|
349 |
+
* containing a `NODE_` prefix in the `cmd` property are reserved for use within
|
350 |
+
* Node.js core and will not be emitted in the child's `'message'` event. Rather, such messages are emitted using the `'internalMessage'` event and are consumed internally by Node.js.
|
351 |
+
* Applications should avoid using such messages or listening for `'internalMessage'` events as it is subject to change without notice.
|
352 |
+
*
|
353 |
+
* The optional `sendHandle` argument that may be passed to `subprocess.send()` is
|
354 |
+
* for passing a TCP server or socket object to the child process. The child will
|
355 |
+
* receive the object as the second argument passed to the callback function
|
356 |
+
* registered on the `'message'` event. Any data that is received and buffered in
|
357 |
+
* the socket will not be sent to the child. Sending IPC sockets is not supported on Windows.
|
358 |
+
*
|
359 |
+
* The optional `callback` is a function that is invoked after the message is
|
360 |
+
* sent but before the child may have received it. The function is called with a
|
361 |
+
* single argument: `null` on success, or an `Error` object on failure.
|
362 |
+
*
|
363 |
+
* If no `callback` function is provided and the message cannot be sent, an `'error'` event will be emitted by the `ChildProcess` object. This can
|
364 |
+
* happen, for instance, when the child process has already exited.
|
365 |
+
*
|
366 |
+
* `subprocess.send()` will return `false` if the channel has closed or when the
|
367 |
+
* backlog of unsent messages exceeds a threshold that makes it unwise to send
|
368 |
+
* more. Otherwise, the method returns `true`. The `callback` function can be
|
369 |
+
* used to implement flow control.
|
370 |
+
*
|
371 |
+
* #### Example: sending a server object
|
372 |
+
*
|
373 |
+
* The `sendHandle` argument can be used, for instance, to pass the handle of
|
374 |
+
* a TCP server object to the child process as illustrated in the example below:
|
375 |
+
*
|
376 |
+
* ```js
|
377 |
+
* import { createServer } from 'node:net';
|
378 |
+
* import { fork } from 'node:child_process';
|
379 |
+
* const subprocess = fork('subprocess.js');
|
380 |
+
*
|
381 |
+
* // Open up the server object and send the handle.
|
382 |
+
* const server = createServer();
|
383 |
+
* server.on('connection', (socket) => {
|
384 |
+
* socket.end('handled by parent');
|
385 |
+
* });
|
386 |
+
* server.listen(1337, () => {
|
387 |
+
* subprocess.send('server', server);
|
388 |
+
* });
|
389 |
+
* ```
|
390 |
+
*
|
391 |
+
* The child would then receive the server object as:
|
392 |
+
*
|
393 |
+
* ```js
|
394 |
+
* process.on('message', (m, server) => {
|
395 |
+
* if (m === 'server') {
|
396 |
+
* server.on('connection', (socket) => {
|
397 |
+
* socket.end('handled by child');
|
398 |
+
* });
|
399 |
+
* }
|
400 |
+
* });
|
401 |
+
* ```
|
402 |
+
*
|
403 |
+
* Once the server is now shared between the parent and child, some connections
|
404 |
+
* can be handled by the parent and some by the child.
|
405 |
+
*
|
406 |
+
* While the example above uses a server created using the `node:net` module, `node:dgram` module servers use exactly the same workflow with the exceptions of
|
407 |
+
* listening on a `'message'` event instead of `'connection'` and using `server.bind()` instead of `server.listen()`. This is, however, only
|
408 |
+
* supported on Unix platforms.
|
409 |
+
*
|
410 |
+
* #### Example: sending a socket object
|
411 |
+
*
|
412 |
+
* Similarly, the `sendHandler` argument can be used to pass the handle of a
|
413 |
+
* socket to the child process. The example below spawns two children that each
|
414 |
+
* handle connections with "normal" or "special" priority:
|
415 |
+
*
|
416 |
+
* ```js
|
417 |
+
* import { createServer } from 'node:net';
|
418 |
+
* import { fork } from 'node:child_process';
|
419 |
+
* const normal = fork('subprocess.js', ['normal']);
|
420 |
+
* const special = fork('subprocess.js', ['special']);
|
421 |
+
*
|
422 |
+
* // Open up the server and send sockets to child. Use pauseOnConnect to prevent
|
423 |
+
* // the sockets from being read before they are sent to the child process.
|
424 |
+
* const server = createServer({ pauseOnConnect: true });
|
425 |
+
* server.on('connection', (socket) => {
|
426 |
+
*
|
427 |
+
* // If this is special priority...
|
428 |
+
* if (socket.remoteAddress === '74.125.127.100') {
|
429 |
+
* special.send('socket', socket);
|
430 |
+
* return;
|
431 |
+
* }
|
432 |
+
* // This is normal priority.
|
433 |
+
* normal.send('socket', socket);
|
434 |
+
* });
|
435 |
+
* server.listen(1337);
|
436 |
+
* ```
|
437 |
+
*
|
438 |
+
* The `subprocess.js` would receive the socket handle as the second argument
|
439 |
+
* passed to the event callback function:
|
440 |
+
*
|
441 |
+
* ```js
|
442 |
+
* process.on('message', (m, socket) => {
|
443 |
+
* if (m === 'socket') {
|
444 |
+
* if (socket) {
|
445 |
+
* // Check that the client socket exists.
|
446 |
+
* // It is possible for the socket to be closed between the time it is
|
447 |
+
* // sent and the time it is received in the child process.
|
448 |
+
* socket.end(`Request handled with ${process.argv[2]} priority`);
|
449 |
+
* }
|
450 |
+
* }
|
451 |
+
* });
|
452 |
+
* ```
|
453 |
+
*
|
454 |
+
* Do not use `.maxConnections` on a socket that has been passed to a subprocess.
|
455 |
+
* The parent cannot track when the socket is destroyed.
|
456 |
+
*
|
457 |
+
* Any `'message'` handlers in the subprocess should verify that `socket` exists,
|
458 |
+
* as the connection may have been closed during the time it takes to send the
|
459 |
+
* connection to the child.
|
460 |
+
* @since v0.5.9
|
461 |
+
* @param sendHandle `undefined`, or a [`net.Socket`](https://nodejs.org/docs/latest-v22.x/api/net.html#class-netsocket), [`net.Server`](https://nodejs.org/docs/latest-v22.x/api/net.html#class-netserver), or [`dgram.Socket`](https://nodejs.org/docs/latest-v22.x/api/dgram.html#class-dgramsocket) object.
|
462 |
+
* @param options The `options` argument, if present, is an object used to parameterize the sending of certain types of handles. `options` supports the following properties:
|
463 |
+
*/
|
464 |
+
send(message: Serializable, callback?: (error: Error | null) => void): boolean;
|
465 |
+
send(message: Serializable, sendHandle?: SendHandle, callback?: (error: Error | null) => void): boolean;
|
466 |
+
send(
|
467 |
+
message: Serializable,
|
468 |
+
sendHandle?: SendHandle,
|
469 |
+
options?: MessageOptions,
|
470 |
+
callback?: (error: Error | null) => void,
|
471 |
+
): boolean;
|
472 |
+
/**
|
473 |
+
* Closes the IPC channel between parent and child, allowing the child to exit
|
474 |
+
* gracefully once there are no other connections keeping it alive. After calling
|
475 |
+
* this method the `subprocess.connected` and `process.connected` properties in
|
476 |
+
* both the parent and child (respectively) will be set to `false`, and it will be
|
477 |
+
* no longer possible to pass messages between the processes.
|
478 |
+
*
|
479 |
+
* The `'disconnect'` event will be emitted when there are no messages in the
|
480 |
+
* process of being received. This will most often be triggered immediately after
|
481 |
+
* calling `subprocess.disconnect()`.
|
482 |
+
*
|
483 |
+
* When the child process is a Node.js instance (e.g. spawned using {@link fork}), the `process.disconnect()` method can be invoked
|
484 |
+
* within the child process to close the IPC channel as well.
|
485 |
+
* @since v0.7.2
|
486 |
+
*/
|
487 |
+
disconnect(): void;
|
488 |
+
/**
|
489 |
+
* By default, the parent will wait for the detached child to exit. To prevent the
|
490 |
+
* parent from waiting for a given `subprocess` to exit, use the `subprocess.unref()` method. Doing so will cause the parent's event loop to not
|
491 |
+
* include the child in its reference count, allowing the parent to exit
|
492 |
+
* independently of the child, unless there is an established IPC channel between
|
493 |
+
* the child and the parent.
|
494 |
+
*
|
495 |
+
* ```js
|
496 |
+
* import { spawn } from 'node:child_process';
|
497 |
+
*
|
498 |
+
* const subprocess = spawn(process.argv[0], ['child_program.js'], {
|
499 |
+
* detached: true,
|
500 |
+
* stdio: 'ignore',
|
501 |
+
* });
|
502 |
+
*
|
503 |
+
* subprocess.unref();
|
504 |
+
* ```
|
505 |
+
* @since v0.7.10
|
506 |
+
*/
|
507 |
+
unref(): void;
|
508 |
+
/**
|
509 |
+
* Calling `subprocess.ref()` after making a call to `subprocess.unref()` will
|
510 |
+
* restore the removed reference count for the child process, forcing the parent
|
511 |
+
* to wait for the child to exit before exiting itself.
|
512 |
+
*
|
513 |
+
* ```js
|
514 |
+
* import { spawn } from 'node:child_process';
|
515 |
+
*
|
516 |
+
* const subprocess = spawn(process.argv[0], ['child_program.js'], {
|
517 |
+
* detached: true,
|
518 |
+
* stdio: 'ignore',
|
519 |
+
* });
|
520 |
+
*
|
521 |
+
* subprocess.unref();
|
522 |
+
* subprocess.ref();
|
523 |
+
* ```
|
524 |
+
* @since v0.7.10
|
525 |
+
*/
|
526 |
+
ref(): void;
|
527 |
+
/**
|
528 |
+
* events.EventEmitter
|
529 |
+
* 1. close
|
530 |
+
* 2. disconnect
|
531 |
+
* 3. error
|
532 |
+
* 4. exit
|
533 |
+
* 5. message
|
534 |
+
* 6. spawn
|
535 |
+
*/
|
536 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
537 |
+
addListener(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
538 |
+
addListener(event: "disconnect", listener: () => void): this;
|
539 |
+
addListener(event: "error", listener: (err: Error) => void): this;
|
540 |
+
addListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
541 |
+
addListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
542 |
+
addListener(event: "spawn", listener: () => void): this;
|
543 |
+
emit(event: string | symbol, ...args: any[]): boolean;
|
544 |
+
emit(event: "close", code: number | null, signal: NodeJS.Signals | null): boolean;
|
545 |
+
emit(event: "disconnect"): boolean;
|
546 |
+
emit(event: "error", err: Error): boolean;
|
547 |
+
emit(event: "exit", code: number | null, signal: NodeJS.Signals | null): boolean;
|
548 |
+
emit(event: "message", message: Serializable, sendHandle: SendHandle): boolean;
|
549 |
+
emit(event: "spawn", listener: () => void): boolean;
|
550 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
551 |
+
on(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
552 |
+
on(event: "disconnect", listener: () => void): this;
|
553 |
+
on(event: "error", listener: (err: Error) => void): this;
|
554 |
+
on(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
555 |
+
on(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
556 |
+
on(event: "spawn", listener: () => void): this;
|
557 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
558 |
+
once(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
559 |
+
once(event: "disconnect", listener: () => void): this;
|
560 |
+
once(event: "error", listener: (err: Error) => void): this;
|
561 |
+
once(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
562 |
+
once(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
563 |
+
once(event: "spawn", listener: () => void): this;
|
564 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
565 |
+
prependListener(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
566 |
+
prependListener(event: "disconnect", listener: () => void): this;
|
567 |
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
568 |
+
prependListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
569 |
+
prependListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
570 |
+
prependListener(event: "spawn", listener: () => void): this;
|
571 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
572 |
+
prependOnceListener(
|
573 |
+
event: "close",
|
574 |
+
listener: (code: number | null, signal: NodeJS.Signals | null) => void,
|
575 |
+
): this;
|
576 |
+
prependOnceListener(event: "disconnect", listener: () => void): this;
|
577 |
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
578 |
+
prependOnceListener(
|
579 |
+
event: "exit",
|
580 |
+
listener: (code: number | null, signal: NodeJS.Signals | null) => void,
|
581 |
+
): this;
|
582 |
+
prependOnceListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
583 |
+
prependOnceListener(event: "spawn", listener: () => void): this;
|
584 |
+
}
|
585 |
+
// return this object when stdio option is undefined or not specified
|
586 |
+
interface ChildProcessWithoutNullStreams extends ChildProcess {
|
587 |
+
stdin: Writable;
|
588 |
+
stdout: Readable;
|
589 |
+
stderr: Readable;
|
590 |
+
readonly stdio: [
|
591 |
+
Writable,
|
592 |
+
Readable,
|
593 |
+
Readable,
|
594 |
+
// stderr
|
595 |
+
Readable | Writable | null | undefined,
|
596 |
+
// extra, no modification
|
597 |
+
Readable | Writable | null | undefined, // extra, no modification
|
598 |
+
];
|
599 |
+
}
|
600 |
+
// return this object when stdio option is a tuple of 3
|
601 |
+
interface ChildProcessByStdio<I extends null | Writable, O extends null | Readable, E extends null | Readable>
|
602 |
+
extends ChildProcess
|
603 |
+
{
|
604 |
+
stdin: I;
|
605 |
+
stdout: O;
|
606 |
+
stderr: E;
|
607 |
+
readonly stdio: [
|
608 |
+
I,
|
609 |
+
O,
|
610 |
+
E,
|
611 |
+
Readable | Writable | null | undefined,
|
612 |
+
// extra, no modification
|
613 |
+
Readable | Writable | null | undefined, // extra, no modification
|
614 |
+
];
|
615 |
+
}
|
616 |
+
interface MessageOptions {
|
617 |
+
keepOpen?: boolean | undefined;
|
618 |
+
}
|
619 |
+
type IOType = "overlapped" | "pipe" | "ignore" | "inherit";
|
620 |
+
type StdioOptions = IOType | Array<IOType | "ipc" | Stream | number | null | undefined>;
|
621 |
+
type SerializationType = "json" | "advanced";
|
622 |
+
interface MessagingOptions extends Abortable {
|
623 |
+
/**
|
624 |
+
* Specify the kind of serialization used for sending messages between processes.
|
625 |
+
* @default 'json'
|
626 |
+
*/
|
627 |
+
serialization?: SerializationType | undefined;
|
628 |
+
/**
|
629 |
+
* The signal value to be used when the spawned process will be killed by the abort signal.
|
630 |
+
* @default 'SIGTERM'
|
631 |
+
*/
|
632 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
633 |
+
/**
|
634 |
+
* In milliseconds the maximum amount of time the process is allowed to run.
|
635 |
+
*/
|
636 |
+
timeout?: number | undefined;
|
637 |
+
}
|
638 |
+
interface ProcessEnvOptions {
|
639 |
+
uid?: number | undefined;
|
640 |
+
gid?: number | undefined;
|
641 |
+
cwd?: string | URL | undefined;
|
642 |
+
env?: NodeJS.ProcessEnv | undefined;
|
643 |
+
}
|
644 |
+
interface CommonOptions extends ProcessEnvOptions {
|
645 |
+
/**
|
646 |
+
* @default false
|
647 |
+
*/
|
648 |
+
windowsHide?: boolean | undefined;
|
649 |
+
/**
|
650 |
+
* @default 0
|
651 |
+
*/
|
652 |
+
timeout?: number | undefined;
|
653 |
+
}
|
654 |
+
interface CommonSpawnOptions extends CommonOptions, MessagingOptions, Abortable {
|
655 |
+
argv0?: string | undefined;
|
656 |
+
/**
|
657 |
+
* Can be set to 'pipe', 'inherit', 'overlapped', or 'ignore', or an array of these strings.
|
658 |
+
* If passed as an array, the first element is used for `stdin`, the second for
|
659 |
+
* `stdout`, and the third for `stderr`. A fourth element can be used to
|
660 |
+
* specify the `stdio` behavior beyond the standard streams. See
|
661 |
+
* {@link ChildProcess.stdio} for more information.
|
662 |
+
*
|
663 |
+
* @default 'pipe'
|
664 |
+
*/
|
665 |
+
stdio?: StdioOptions | undefined;
|
666 |
+
shell?: boolean | string | undefined;
|
667 |
+
windowsVerbatimArguments?: boolean | undefined;
|
668 |
+
}
|
669 |
+
interface SpawnOptions extends CommonSpawnOptions {
|
670 |
+
detached?: boolean | undefined;
|
671 |
+
}
|
672 |
+
interface SpawnOptionsWithoutStdio extends SpawnOptions {
|
673 |
+
stdio?: StdioPipeNamed | StdioPipe[] | undefined;
|
674 |
+
}
|
675 |
+
type StdioNull = "inherit" | "ignore" | Stream;
|
676 |
+
type StdioPipeNamed = "pipe" | "overlapped";
|
677 |
+
type StdioPipe = undefined | null | StdioPipeNamed;
|
678 |
+
interface SpawnOptionsWithStdioTuple<
|
679 |
+
Stdin extends StdioNull | StdioPipe,
|
680 |
+
Stdout extends StdioNull | StdioPipe,
|
681 |
+
Stderr extends StdioNull | StdioPipe,
|
682 |
+
> extends SpawnOptions {
|
683 |
+
stdio: [Stdin, Stdout, Stderr];
|
684 |
+
}
|
685 |
+
/**
|
686 |
+
* The `child_process.spawn()` method spawns a new process using the given `command`, with command-line arguments in `args`. If omitted, `args` defaults
|
687 |
+
* to an empty array.
|
688 |
+
*
|
689 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
690 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
691 |
+
* **arbitrary command execution.**
|
692 |
+
*
|
693 |
+
* A third argument may be used to specify additional options, with these defaults:
|
694 |
+
*
|
695 |
+
* ```js
|
696 |
+
* const defaults = {
|
697 |
+
* cwd: undefined,
|
698 |
+
* env: process.env,
|
699 |
+
* };
|
700 |
+
* ```
|
701 |
+
*
|
702 |
+
* Use `cwd` to specify the working directory from which the process is spawned.
|
703 |
+
* If not given, the default is to inherit the current working directory. If given,
|
704 |
+
* but the path does not exist, the child process emits an `ENOENT` error
|
705 |
+
* and exits immediately. `ENOENT` is also emitted when the command
|
706 |
+
* does not exist.
|
707 |
+
*
|
708 |
+
* Use `env` to specify environment variables that will be visible to the new
|
709 |
+
* process, the default is `process.env`.
|
710 |
+
*
|
711 |
+
* `undefined` values in `env` will be ignored.
|
712 |
+
*
|
713 |
+
* Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the
|
714 |
+
* exit code:
|
715 |
+
*
|
716 |
+
* ```js
|
717 |
+
* import { spawn } from 'node:child_process';
|
718 |
+
* const ls = spawn('ls', ['-lh', '/usr']);
|
719 |
+
*
|
720 |
+
* ls.stdout.on('data', (data) => {
|
721 |
+
* console.log(`stdout: ${data}`);
|
722 |
+
* });
|
723 |
+
*
|
724 |
+
* ls.stderr.on('data', (data) => {
|
725 |
+
* console.error(`stderr: ${data}`);
|
726 |
+
* });
|
727 |
+
*
|
728 |
+
* ls.on('close', (code) => {
|
729 |
+
* console.log(`child process exited with code ${code}`);
|
730 |
+
* });
|
731 |
+
* ```
|
732 |
+
*
|
733 |
+
* Example: A very elaborate way to run `ps ax | grep ssh`
|
734 |
+
*
|
735 |
+
* ```js
|
736 |
+
* import { spawn } from 'node:child_process';
|
737 |
+
* const ps = spawn('ps', ['ax']);
|
738 |
+
* const grep = spawn('grep', ['ssh']);
|
739 |
+
*
|
740 |
+
* ps.stdout.on('data', (data) => {
|
741 |
+
* grep.stdin.write(data);
|
742 |
+
* });
|
743 |
+
*
|
744 |
+
* ps.stderr.on('data', (data) => {
|
745 |
+
* console.error(`ps stderr: ${data}`);
|
746 |
+
* });
|
747 |
+
*
|
748 |
+
* ps.on('close', (code) => {
|
749 |
+
* if (code !== 0) {
|
750 |
+
* console.log(`ps process exited with code ${code}`);
|
751 |
+
* }
|
752 |
+
* grep.stdin.end();
|
753 |
+
* });
|
754 |
+
*
|
755 |
+
* grep.stdout.on('data', (data) => {
|
756 |
+
* console.log(data.toString());
|
757 |
+
* });
|
758 |
+
*
|
759 |
+
* grep.stderr.on('data', (data) => {
|
760 |
+
* console.error(`grep stderr: ${data}`);
|
761 |
+
* });
|
762 |
+
*
|
763 |
+
* grep.on('close', (code) => {
|
764 |
+
* if (code !== 0) {
|
765 |
+
* console.log(`grep process exited with code ${code}`);
|
766 |
+
* }
|
767 |
+
* });
|
768 |
+
* ```
|
769 |
+
*
|
770 |
+
* Example of checking for failed `spawn`:
|
771 |
+
*
|
772 |
+
* ```js
|
773 |
+
* import { spawn } from 'node:child_process';
|
774 |
+
* const subprocess = spawn('bad_command');
|
775 |
+
*
|
776 |
+
* subprocess.on('error', (err) => {
|
777 |
+
* console.error('Failed to start subprocess.');
|
778 |
+
* });
|
779 |
+
* ```
|
780 |
+
*
|
781 |
+
* Certain platforms (macOS, Linux) will use the value of `argv[0]` for the process
|
782 |
+
* title while others (Windows, SunOS) will use `command`.
|
783 |
+
*
|
784 |
+
* Node.js overwrites `argv[0]` with `process.execPath` on startup, so `process.argv[0]` in a Node.js child process will not match the `argv0` parameter passed to `spawn` from the parent. Retrieve
|
785 |
+
* it with the `process.argv0` property instead.
|
786 |
+
*
|
787 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except
|
788 |
+
* the error passed to the callback will be an `AbortError`:
|
789 |
+
*
|
790 |
+
* ```js
|
791 |
+
* import { spawn } from 'node:child_process';
|
792 |
+
* const controller = new AbortController();
|
793 |
+
* const { signal } = controller;
|
794 |
+
* const grep = spawn('grep', ['ssh'], { signal });
|
795 |
+
* grep.on('error', (err) => {
|
796 |
+
* // This will be called with err being an AbortError if the controller aborts
|
797 |
+
* });
|
798 |
+
* controller.abort(); // Stops the child process
|
799 |
+
* ```
|
800 |
+
* @since v0.1.90
|
801 |
+
* @param command The command to run.
|
802 |
+
* @param args List of string arguments.
|
803 |
+
*/
|
804 |
+
function spawn(command: string, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
805 |
+
function spawn(
|
806 |
+
command: string,
|
807 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
808 |
+
): ChildProcessByStdio<Writable, Readable, Readable>;
|
809 |
+
function spawn(
|
810 |
+
command: string,
|
811 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
812 |
+
): ChildProcessByStdio<Writable, Readable, null>;
|
813 |
+
function spawn(
|
814 |
+
command: string,
|
815 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
816 |
+
): ChildProcessByStdio<Writable, null, Readable>;
|
817 |
+
function spawn(
|
818 |
+
command: string,
|
819 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
820 |
+
): ChildProcessByStdio<null, Readable, Readable>;
|
821 |
+
function spawn(
|
822 |
+
command: string,
|
823 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
824 |
+
): ChildProcessByStdio<Writable, null, null>;
|
825 |
+
function spawn(
|
826 |
+
command: string,
|
827 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
828 |
+
): ChildProcessByStdio<null, Readable, null>;
|
829 |
+
function spawn(
|
830 |
+
command: string,
|
831 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
832 |
+
): ChildProcessByStdio<null, null, Readable>;
|
833 |
+
function spawn(
|
834 |
+
command: string,
|
835 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
836 |
+
): ChildProcessByStdio<null, null, null>;
|
837 |
+
function spawn(command: string, options: SpawnOptions): ChildProcess;
|
838 |
+
// overloads of spawn with 'args'
|
839 |
+
function spawn(
|
840 |
+
command: string,
|
841 |
+
args?: readonly string[],
|
842 |
+
options?: SpawnOptionsWithoutStdio,
|
843 |
+
): ChildProcessWithoutNullStreams;
|
844 |
+
function spawn(
|
845 |
+
command: string,
|
846 |
+
args: readonly string[],
|
847 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
848 |
+
): ChildProcessByStdio<Writable, Readable, Readable>;
|
849 |
+
function spawn(
|
850 |
+
command: string,
|
851 |
+
args: readonly string[],
|
852 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
853 |
+
): ChildProcessByStdio<Writable, Readable, null>;
|
854 |
+
function spawn(
|
855 |
+
command: string,
|
856 |
+
args: readonly string[],
|
857 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
858 |
+
): ChildProcessByStdio<Writable, null, Readable>;
|
859 |
+
function spawn(
|
860 |
+
command: string,
|
861 |
+
args: readonly string[],
|
862 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
863 |
+
): ChildProcessByStdio<null, Readable, Readable>;
|
864 |
+
function spawn(
|
865 |
+
command: string,
|
866 |
+
args: readonly string[],
|
867 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
868 |
+
): ChildProcessByStdio<Writable, null, null>;
|
869 |
+
function spawn(
|
870 |
+
command: string,
|
871 |
+
args: readonly string[],
|
872 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
873 |
+
): ChildProcessByStdio<null, Readable, null>;
|
874 |
+
function spawn(
|
875 |
+
command: string,
|
876 |
+
args: readonly string[],
|
877 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
878 |
+
): ChildProcessByStdio<null, null, Readable>;
|
879 |
+
function spawn(
|
880 |
+
command: string,
|
881 |
+
args: readonly string[],
|
882 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
883 |
+
): ChildProcessByStdio<null, null, null>;
|
884 |
+
function spawn(command: string, args: readonly string[], options: SpawnOptions): ChildProcess;
|
885 |
+
interface ExecOptions extends CommonOptions {
|
886 |
+
shell?: string | undefined;
|
887 |
+
signal?: AbortSignal | undefined;
|
888 |
+
maxBuffer?: number | undefined;
|
889 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
890 |
+
}
|
891 |
+
interface ExecOptionsWithStringEncoding extends ExecOptions {
|
892 |
+
encoding: BufferEncoding;
|
893 |
+
}
|
894 |
+
interface ExecOptionsWithBufferEncoding extends ExecOptions {
|
895 |
+
encoding: BufferEncoding | null; // specify `null`.
|
896 |
+
}
|
897 |
+
interface ExecException extends Error {
|
898 |
+
cmd?: string | undefined;
|
899 |
+
killed?: boolean | undefined;
|
900 |
+
code?: number | undefined;
|
901 |
+
signal?: NodeJS.Signals | undefined;
|
902 |
+
stdout?: string;
|
903 |
+
stderr?: string;
|
904 |
+
}
|
905 |
+
/**
|
906 |
+
* Spawns a shell then executes the `command` within that shell, buffering any
|
907 |
+
* generated output. The `command` string passed to the exec function is processed
|
908 |
+
* directly by the shell and special characters (vary based on [shell](https://en.wikipedia.org/wiki/List_of_command-line_interpreters))
|
909 |
+
* need to be dealt with accordingly:
|
910 |
+
*
|
911 |
+
* ```js
|
912 |
+
* import { exec } from 'node:child_process';
|
913 |
+
*
|
914 |
+
* exec('"/path/to/test file/test.sh" arg1 arg2');
|
915 |
+
* // Double quotes are used so that the space in the path is not interpreted as
|
916 |
+
* // a delimiter of multiple arguments.
|
917 |
+
*
|
918 |
+
* exec('echo "The \\$HOME variable is $HOME"');
|
919 |
+
* // The $HOME variable is escaped in the first instance, but not in the second.
|
920 |
+
* ```
|
921 |
+
*
|
922 |
+
* **Never pass unsanitized user input to this function. Any input containing shell**
|
923 |
+
* **metacharacters may be used to trigger arbitrary command execution.**
|
924 |
+
*
|
925 |
+
* If a `callback` function is provided, it is called with the arguments `(error, stdout, stderr)`. On success, `error` will be `null`. On error, `error` will be an instance of `Error`. The
|
926 |
+
* `error.code` property will be
|
927 |
+
* the exit code of the process. By convention, any exit code other than `0` indicates an error. `error.signal` will be the signal that terminated the
|
928 |
+
* process.
|
929 |
+
*
|
930 |
+
* The `stdout` and `stderr` arguments passed to the callback will contain the
|
931 |
+
* stdout and stderr output of the child process. By default, Node.js will decode
|
932 |
+
* the output as UTF-8 and pass strings to the callback. The `encoding` option
|
933 |
+
* can be used to specify the character encoding used to decode the stdout and
|
934 |
+
* stderr output. If `encoding` is `'buffer'`, or an unrecognized character
|
935 |
+
* encoding, `Buffer` objects will be passed to the callback instead.
|
936 |
+
*
|
937 |
+
* ```js
|
938 |
+
* import { exec } from 'node:child_process';
|
939 |
+
* exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {
|
940 |
+
* if (error) {
|
941 |
+
* console.error(`exec error: ${error}`);
|
942 |
+
* return;
|
943 |
+
* }
|
944 |
+
* console.log(`stdout: ${stdout}`);
|
945 |
+
* console.error(`stderr: ${stderr}`);
|
946 |
+
* });
|
947 |
+
* ```
|
948 |
+
*
|
949 |
+
* If `timeout` is greater than `0`, the parent will send the signal
|
950 |
+
* identified by the `killSignal` property (the default is `'SIGTERM'`) if the
|
951 |
+
* child runs longer than `timeout` milliseconds.
|
952 |
+
*
|
953 |
+
* Unlike the [`exec(3)`](http://man7.org/linux/man-pages/man3/exec.3.html) POSIX system call, `child_process.exec()` does not replace
|
954 |
+
* the existing process and uses a shell to execute the command.
|
955 |
+
*
|
956 |
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
957 |
+
* a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned `ChildProcess` instance is attached to the `Promise` as a `child` property. In
|
958 |
+
* case of an error (including any error resulting in an exit code other than 0), a
|
959 |
+
* rejected promise is returned, with the same `error` object given in the
|
960 |
+
* callback, but with two additional properties `stdout` and `stderr`.
|
961 |
+
*
|
962 |
+
* ```js
|
963 |
+
* import util from 'node:util';
|
964 |
+
* import child_process from 'node:child_process';
|
965 |
+
* const exec = util.promisify(child_process.exec);
|
966 |
+
*
|
967 |
+
* async function lsExample() {
|
968 |
+
* const { stdout, stderr } = await exec('ls');
|
969 |
+
* console.log('stdout:', stdout);
|
970 |
+
* console.error('stderr:', stderr);
|
971 |
+
* }
|
972 |
+
* lsExample();
|
973 |
+
* ```
|
974 |
+
*
|
975 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except
|
976 |
+
* the error passed to the callback will be an `AbortError`:
|
977 |
+
*
|
978 |
+
* ```js
|
979 |
+
* import { exec } from 'node:child_process';
|
980 |
+
* const controller = new AbortController();
|
981 |
+
* const { signal } = controller;
|
982 |
+
* const child = exec('grep ssh', { signal }, (error) => {
|
983 |
+
* console.error(error); // an AbortError
|
984 |
+
* });
|
985 |
+
* controller.abort();
|
986 |
+
* ```
|
987 |
+
* @since v0.1.90
|
988 |
+
* @param command The command to run, with space-separated arguments.
|
989 |
+
* @param callback called with the output when process terminates.
|
990 |
+
*/
|
991 |
+
function exec(
|
992 |
+
command: string,
|
993 |
+
callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
|
994 |
+
): ChildProcess;
|
995 |
+
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
996 |
+
function exec(
|
997 |
+
command: string,
|
998 |
+
options: {
|
999 |
+
encoding: "buffer" | null;
|
1000 |
+
} & ExecOptions,
|
1001 |
+
callback?: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void,
|
1002 |
+
): ChildProcess;
|
1003 |
+
// `options` with well known `encoding` means stdout/stderr are definitely `string`.
|
1004 |
+
function exec(
|
1005 |
+
command: string,
|
1006 |
+
options: {
|
1007 |
+
encoding: BufferEncoding;
|
1008 |
+
} & ExecOptions,
|
1009 |
+
callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
|
1010 |
+
): ChildProcess;
|
1011 |
+
// `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
|
1012 |
+
// There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
|
1013 |
+
function exec(
|
1014 |
+
command: string,
|
1015 |
+
options: {
|
1016 |
+
encoding: BufferEncoding;
|
1017 |
+
} & ExecOptions,
|
1018 |
+
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
1019 |
+
): ChildProcess;
|
1020 |
+
// `options` without an `encoding` means stdout/stderr are definitely `string`.
|
1021 |
+
function exec(
|
1022 |
+
command: string,
|
1023 |
+
options: ExecOptions,
|
1024 |
+
callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
|
1025 |
+
): ChildProcess;
|
1026 |
+
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
1027 |
+
function exec(
|
1028 |
+
command: string,
|
1029 |
+
options: (ObjectEncodingOptions & ExecOptions) | undefined | null,
|
1030 |
+
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
1031 |
+
): ChildProcess;
|
1032 |
+
interface PromiseWithChild<T> extends Promise<T> {
|
1033 |
+
child: ChildProcess;
|
1034 |
+
}
|
1035 |
+
namespace exec {
|
1036 |
+
function __promisify__(command: string): PromiseWithChild<{
|
1037 |
+
stdout: string;
|
1038 |
+
stderr: string;
|
1039 |
+
}>;
|
1040 |
+
function __promisify__(
|
1041 |
+
command: string,
|
1042 |
+
options: {
|
1043 |
+
encoding: "buffer" | null;
|
1044 |
+
} & ExecOptions,
|
1045 |
+
): PromiseWithChild<{
|
1046 |
+
stdout: Buffer;
|
1047 |
+
stderr: Buffer;
|
1048 |
+
}>;
|
1049 |
+
function __promisify__(
|
1050 |
+
command: string,
|
1051 |
+
options: {
|
1052 |
+
encoding: BufferEncoding;
|
1053 |
+
} & ExecOptions,
|
1054 |
+
): PromiseWithChild<{
|
1055 |
+
stdout: string;
|
1056 |
+
stderr: string;
|
1057 |
+
}>;
|
1058 |
+
function __promisify__(
|
1059 |
+
command: string,
|
1060 |
+
options: ExecOptions,
|
1061 |
+
): PromiseWithChild<{
|
1062 |
+
stdout: string;
|
1063 |
+
stderr: string;
|
1064 |
+
}>;
|
1065 |
+
function __promisify__(
|
1066 |
+
command: string,
|
1067 |
+
options?: (ObjectEncodingOptions & ExecOptions) | null,
|
1068 |
+
): PromiseWithChild<{
|
1069 |
+
stdout: string | Buffer;
|
1070 |
+
stderr: string | Buffer;
|
1071 |
+
}>;
|
1072 |
+
}
|
1073 |
+
interface ExecFileOptions extends CommonOptions, Abortable {
|
1074 |
+
maxBuffer?: number | undefined;
|
1075 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
1076 |
+
windowsVerbatimArguments?: boolean | undefined;
|
1077 |
+
shell?: boolean | string | undefined;
|
1078 |
+
signal?: AbortSignal | undefined;
|
1079 |
+
}
|
1080 |
+
interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
|
1081 |
+
encoding: BufferEncoding;
|
1082 |
+
}
|
1083 |
+
interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions {
|
1084 |
+
encoding: "buffer" | null;
|
1085 |
+
}
|
1086 |
+
interface ExecFileOptionsWithOtherEncoding extends ExecFileOptions {
|
1087 |
+
encoding: BufferEncoding;
|
1088 |
+
}
|
1089 |
+
type ExecFileException =
|
1090 |
+
& Omit<ExecException, "code">
|
1091 |
+
& Omit<NodeJS.ErrnoException, "code">
|
1092 |
+
& { code?: string | number | undefined | null };
|
1093 |
+
/**
|
1094 |
+
* The `child_process.execFile()` function is similar to {@link exec} except that it does not spawn a shell by default. Rather, the specified
|
1095 |
+
* executable `file` is spawned directly as a new process making it slightly more
|
1096 |
+
* efficient than {@link exec}.
|
1097 |
+
*
|
1098 |
+
* The same options as {@link exec} are supported. Since a shell is
|
1099 |
+
* not spawned, behaviors such as I/O redirection and file globbing are not
|
1100 |
+
* supported.
|
1101 |
+
*
|
1102 |
+
* ```js
|
1103 |
+
* import { execFile } from 'node:child_process';
|
1104 |
+
* const child = execFile('node', ['--version'], (error, stdout, stderr) => {
|
1105 |
+
* if (error) {
|
1106 |
+
* throw error;
|
1107 |
+
* }
|
1108 |
+
* console.log(stdout);
|
1109 |
+
* });
|
1110 |
+
* ```
|
1111 |
+
*
|
1112 |
+
* The `stdout` and `stderr` arguments passed to the callback will contain the
|
1113 |
+
* stdout and stderr output of the child process. By default, Node.js will decode
|
1114 |
+
* the output as UTF-8 and pass strings to the callback. The `encoding` option
|
1115 |
+
* can be used to specify the character encoding used to decode the stdout and
|
1116 |
+
* stderr output. If `encoding` is `'buffer'`, or an unrecognized character
|
1117 |
+
* encoding, `Buffer` objects will be passed to the callback instead.
|
1118 |
+
*
|
1119 |
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
1120 |
+
* a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned `ChildProcess` instance is attached to the `Promise` as a `child` property. In
|
1121 |
+
* case of an error (including any error resulting in an exit code other than 0), a
|
1122 |
+
* rejected promise is returned, with the same `error` object given in the
|
1123 |
+
* callback, but with two additional properties `stdout` and `stderr`.
|
1124 |
+
*
|
1125 |
+
* ```js
|
1126 |
+
* import util from 'node:util';
|
1127 |
+
* import child_process from 'node:child_process';
|
1128 |
+
* const execFile = util.promisify(child_process.execFile);
|
1129 |
+
* async function getVersion() {
|
1130 |
+
* const { stdout } = await execFile('node', ['--version']);
|
1131 |
+
* console.log(stdout);
|
1132 |
+
* }
|
1133 |
+
* getVersion();
|
1134 |
+
* ```
|
1135 |
+
*
|
1136 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
1137 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
1138 |
+
* **arbitrary command execution.**
|
1139 |
+
*
|
1140 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except
|
1141 |
+
* the error passed to the callback will be an `AbortError`:
|
1142 |
+
*
|
1143 |
+
* ```js
|
1144 |
+
* import { execFile } from 'node:child_process';
|
1145 |
+
* const controller = new AbortController();
|
1146 |
+
* const { signal } = controller;
|
1147 |
+
* const child = execFile('node', ['--version'], { signal }, (error) => {
|
1148 |
+
* console.error(error); // an AbortError
|
1149 |
+
* });
|
1150 |
+
* controller.abort();
|
1151 |
+
* ```
|
1152 |
+
* @since v0.1.91
|
1153 |
+
* @param file The name or path of the executable file to run.
|
1154 |
+
* @param args List of string arguments.
|
1155 |
+
* @param callback Called with the output when process terminates.
|
1156 |
+
*/
|
1157 |
+
function execFile(file: string): ChildProcess;
|
1158 |
+
function execFile(
|
1159 |
+
file: string,
|
1160 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1161 |
+
): ChildProcess;
|
1162 |
+
function execFile(file: string, args?: readonly string[] | null): ChildProcess;
|
1163 |
+
function execFile(
|
1164 |
+
file: string,
|
1165 |
+
args: readonly string[] | undefined | null,
|
1166 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1167 |
+
): ChildProcess;
|
1168 |
+
// no `options` definitely means stdout/stderr are `string`.
|
1169 |
+
function execFile(
|
1170 |
+
file: string,
|
1171 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1172 |
+
): ChildProcess;
|
1173 |
+
function execFile(
|
1174 |
+
file: string,
|
1175 |
+
args: readonly string[] | undefined | null,
|
1176 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1177 |
+
): ChildProcess;
|
1178 |
+
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
1179 |
+
function execFile(
|
1180 |
+
file: string,
|
1181 |
+
options: ExecFileOptionsWithBufferEncoding,
|
1182 |
+
callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void,
|
1183 |
+
): ChildProcess;
|
1184 |
+
function execFile(
|
1185 |
+
file: string,
|
1186 |
+
args: readonly string[] | undefined | null,
|
1187 |
+
options: ExecFileOptionsWithBufferEncoding,
|
1188 |
+
callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void,
|
1189 |
+
): ChildProcess;
|
1190 |
+
// `options` with well known `encoding` means stdout/stderr are definitely `string`.
|
1191 |
+
function execFile(
|
1192 |
+
file: string,
|
1193 |
+
options: ExecFileOptionsWithStringEncoding,
|
1194 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1195 |
+
): ChildProcess;
|
1196 |
+
function execFile(
|
1197 |
+
file: string,
|
1198 |
+
args: readonly string[] | undefined | null,
|
1199 |
+
options: ExecFileOptionsWithStringEncoding,
|
1200 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1201 |
+
): ChildProcess;
|
1202 |
+
// `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
|
1203 |
+
// There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
|
1204 |
+
function execFile(
|
1205 |
+
file: string,
|
1206 |
+
options: ExecFileOptionsWithOtherEncoding,
|
1207 |
+
callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
1208 |
+
): ChildProcess;
|
1209 |
+
function execFile(
|
1210 |
+
file: string,
|
1211 |
+
args: readonly string[] | undefined | null,
|
1212 |
+
options: ExecFileOptionsWithOtherEncoding,
|
1213 |
+
callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
1214 |
+
): ChildProcess;
|
1215 |
+
// `options` without an `encoding` means stdout/stderr are definitely `string`.
|
1216 |
+
function execFile(
|
1217 |
+
file: string,
|
1218 |
+
options: ExecFileOptions,
|
1219 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1220 |
+
): ChildProcess;
|
1221 |
+
function execFile(
|
1222 |
+
file: string,
|
1223 |
+
args: readonly string[] | undefined | null,
|
1224 |
+
options: ExecFileOptions,
|
1225 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1226 |
+
): ChildProcess;
|
1227 |
+
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
1228 |
+
function execFile(
|
1229 |
+
file: string,
|
1230 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1231 |
+
callback:
|
1232 |
+
| ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void)
|
1233 |
+
| undefined
|
1234 |
+
| null,
|
1235 |
+
): ChildProcess;
|
1236 |
+
function execFile(
|
1237 |
+
file: string,
|
1238 |
+
args: readonly string[] | undefined | null,
|
1239 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1240 |
+
callback:
|
1241 |
+
| ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void)
|
1242 |
+
| undefined
|
1243 |
+
| null,
|
1244 |
+
): ChildProcess;
|
1245 |
+
namespace execFile {
|
1246 |
+
function __promisify__(file: string): PromiseWithChild<{
|
1247 |
+
stdout: string;
|
1248 |
+
stderr: string;
|
1249 |
+
}>;
|
1250 |
+
function __promisify__(
|
1251 |
+
file: string,
|
1252 |
+
args: readonly string[] | undefined | null,
|
1253 |
+
): PromiseWithChild<{
|
1254 |
+
stdout: string;
|
1255 |
+
stderr: string;
|
1256 |
+
}>;
|
1257 |
+
function __promisify__(
|
1258 |
+
file: string,
|
1259 |
+
options: ExecFileOptionsWithBufferEncoding,
|
1260 |
+
): PromiseWithChild<{
|
1261 |
+
stdout: Buffer;
|
1262 |
+
stderr: Buffer;
|
1263 |
+
}>;
|
1264 |
+
function __promisify__(
|
1265 |
+
file: string,
|
1266 |
+
args: readonly string[] | undefined | null,
|
1267 |
+
options: ExecFileOptionsWithBufferEncoding,
|
1268 |
+
): PromiseWithChild<{
|
1269 |
+
stdout: Buffer;
|
1270 |
+
stderr: Buffer;
|
1271 |
+
}>;
|
1272 |
+
function __promisify__(
|
1273 |
+
file: string,
|
1274 |
+
options: ExecFileOptionsWithStringEncoding,
|
1275 |
+
): PromiseWithChild<{
|
1276 |
+
stdout: string;
|
1277 |
+
stderr: string;
|
1278 |
+
}>;
|
1279 |
+
function __promisify__(
|
1280 |
+
file: string,
|
1281 |
+
args: readonly string[] | undefined | null,
|
1282 |
+
options: ExecFileOptionsWithStringEncoding,
|
1283 |
+
): PromiseWithChild<{
|
1284 |
+
stdout: string;
|
1285 |
+
stderr: string;
|
1286 |
+
}>;
|
1287 |
+
function __promisify__(
|
1288 |
+
file: string,
|
1289 |
+
options: ExecFileOptionsWithOtherEncoding,
|
1290 |
+
): PromiseWithChild<{
|
1291 |
+
stdout: string | Buffer;
|
1292 |
+
stderr: string | Buffer;
|
1293 |
+
}>;
|
1294 |
+
function __promisify__(
|
1295 |
+
file: string,
|
1296 |
+
args: readonly string[] | undefined | null,
|
1297 |
+
options: ExecFileOptionsWithOtherEncoding,
|
1298 |
+
): PromiseWithChild<{
|
1299 |
+
stdout: string | Buffer;
|
1300 |
+
stderr: string | Buffer;
|
1301 |
+
}>;
|
1302 |
+
function __promisify__(
|
1303 |
+
file: string,
|
1304 |
+
options: ExecFileOptions,
|
1305 |
+
): PromiseWithChild<{
|
1306 |
+
stdout: string;
|
1307 |
+
stderr: string;
|
1308 |
+
}>;
|
1309 |
+
function __promisify__(
|
1310 |
+
file: string,
|
1311 |
+
args: readonly string[] | undefined | null,
|
1312 |
+
options: ExecFileOptions,
|
1313 |
+
): PromiseWithChild<{
|
1314 |
+
stdout: string;
|
1315 |
+
stderr: string;
|
1316 |
+
}>;
|
1317 |
+
function __promisify__(
|
1318 |
+
file: string,
|
1319 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1320 |
+
): PromiseWithChild<{
|
1321 |
+
stdout: string | Buffer;
|
1322 |
+
stderr: string | Buffer;
|
1323 |
+
}>;
|
1324 |
+
function __promisify__(
|
1325 |
+
file: string,
|
1326 |
+
args: readonly string[] | undefined | null,
|
1327 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1328 |
+
): PromiseWithChild<{
|
1329 |
+
stdout: string | Buffer;
|
1330 |
+
stderr: string | Buffer;
|
1331 |
+
}>;
|
1332 |
+
}
|
1333 |
+
interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable {
|
1334 |
+
execPath?: string | undefined;
|
1335 |
+
execArgv?: string[] | undefined;
|
1336 |
+
silent?: boolean | undefined;
|
1337 |
+
/**
|
1338 |
+
* Can be set to 'pipe', 'inherit', 'overlapped', or 'ignore', or an array of these strings.
|
1339 |
+
* If passed as an array, the first element is used for `stdin`, the second for
|
1340 |
+
* `stdout`, and the third for `stderr`. A fourth element can be used to
|
1341 |
+
* specify the `stdio` behavior beyond the standard streams. See
|
1342 |
+
* {@link ChildProcess.stdio} for more information.
|
1343 |
+
*
|
1344 |
+
* @default 'pipe'
|
1345 |
+
*/
|
1346 |
+
stdio?: StdioOptions | undefined;
|
1347 |
+
detached?: boolean | undefined;
|
1348 |
+
windowsVerbatimArguments?: boolean | undefined;
|
1349 |
+
}
|
1350 |
+
/**
|
1351 |
+
* The `child_process.fork()` method is a special case of {@link spawn} used specifically to spawn new Node.js processes.
|
1352 |
+
* Like {@link spawn}, a `ChildProcess` object is returned. The
|
1353 |
+
* returned `ChildProcess` will have an additional communication channel
|
1354 |
+
* built-in that allows messages to be passed back and forth between the parent and
|
1355 |
+
* child. See `subprocess.send()` for details.
|
1356 |
+
*
|
1357 |
+
* Keep in mind that spawned Node.js child processes are
|
1358 |
+
* independent of the parent with exception of the IPC communication channel
|
1359 |
+
* that is established between the two. Each process has its own memory, with
|
1360 |
+
* their own V8 instances. Because of the additional resource allocations
|
1361 |
+
* required, spawning a large number of child Node.js processes is not
|
1362 |
+
* recommended.
|
1363 |
+
*
|
1364 |
+
* By default, `child_process.fork()` will spawn new Node.js instances using the `process.execPath` of the parent process. The `execPath` property in the `options` object allows for an alternative
|
1365 |
+
* execution path to be used.
|
1366 |
+
*
|
1367 |
+
* Node.js processes launched with a custom `execPath` will communicate with the
|
1368 |
+
* parent process using the file descriptor (fd) identified using the
|
1369 |
+
* environment variable `NODE_CHANNEL_FD` on the child process.
|
1370 |
+
*
|
1371 |
+
* Unlike the [`fork(2)`](http://man7.org/linux/man-pages/man2/fork.2.html) POSIX system call, `child_process.fork()` does not clone the
|
1372 |
+
* current process.
|
1373 |
+
*
|
1374 |
+
* The `shell` option available in {@link spawn} is not supported by `child_process.fork()` and will be ignored if set.
|
1375 |
+
*
|
1376 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except
|
1377 |
+
* the error passed to the callback will be an `AbortError`:
|
1378 |
+
*
|
1379 |
+
* ```js
|
1380 |
+
* if (process.argv[2] === 'child') {
|
1381 |
+
* setTimeout(() => {
|
1382 |
+
* console.log(`Hello from ${process.argv[2]}!`);
|
1383 |
+
* }, 1_000);
|
1384 |
+
* } else {
|
1385 |
+
* import { fork } from 'node:child_process';
|
1386 |
+
* const controller = new AbortController();
|
1387 |
+
* const { signal } = controller;
|
1388 |
+
* const child = fork(__filename, ['child'], { signal });
|
1389 |
+
* child.on('error', (err) => {
|
1390 |
+
* // This will be called with err being an AbortError if the controller aborts
|
1391 |
+
* });
|
1392 |
+
* controller.abort(); // Stops the child process
|
1393 |
+
* }
|
1394 |
+
* ```
|
1395 |
+
* @since v0.5.0
|
1396 |
+
* @param modulePath The module to run in the child.
|
1397 |
+
* @param args List of string arguments.
|
1398 |
+
*/
|
1399 |
+
function fork(modulePath: string | URL, options?: ForkOptions): ChildProcess;
|
1400 |
+
function fork(modulePath: string | URL, args?: readonly string[], options?: ForkOptions): ChildProcess;
|
1401 |
+
interface SpawnSyncOptions extends CommonSpawnOptions {
|
1402 |
+
input?: string | NodeJS.ArrayBufferView | undefined;
|
1403 |
+
maxBuffer?: number | undefined;
|
1404 |
+
encoding?: BufferEncoding | "buffer" | null | undefined;
|
1405 |
+
}
|
1406 |
+
interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions {
|
1407 |
+
encoding: BufferEncoding;
|
1408 |
+
}
|
1409 |
+
interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions {
|
1410 |
+
encoding?: "buffer" | null | undefined;
|
1411 |
+
}
|
1412 |
+
interface SpawnSyncReturns<T> {
|
1413 |
+
pid: number;
|
1414 |
+
output: Array<T | null>;
|
1415 |
+
stdout: T;
|
1416 |
+
stderr: T;
|
1417 |
+
status: number | null;
|
1418 |
+
signal: NodeJS.Signals | null;
|
1419 |
+
error?: Error | undefined;
|
1420 |
+
}
|
1421 |
+
/**
|
1422 |
+
* The `child_process.spawnSync()` method is generally identical to {@link spawn} with the exception that the function will not return
|
1423 |
+
* until the child process has fully closed. When a timeout has been encountered
|
1424 |
+
* and `killSignal` is sent, the method won't return until the process has
|
1425 |
+
* completely exited. If the process intercepts and handles the `SIGTERM` signal
|
1426 |
+
* and doesn't exit, the parent process will wait until the child process has
|
1427 |
+
* exited.
|
1428 |
+
*
|
1429 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
1430 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
1431 |
+
* **arbitrary command execution.**
|
1432 |
+
* @since v0.11.12
|
1433 |
+
* @param command The command to run.
|
1434 |
+
* @param args List of string arguments.
|
1435 |
+
*/
|
1436 |
+
function spawnSync(command: string): SpawnSyncReturns<Buffer>;
|
1437 |
+
function spawnSync(command: string, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
|
1438 |
+
function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
|
1439 |
+
function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns<string | Buffer>;
|
1440 |
+
function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns<Buffer>;
|
1441 |
+
function spawnSync(
|
1442 |
+
command: string,
|
1443 |
+
args: readonly string[],
|
1444 |
+
options: SpawnSyncOptionsWithStringEncoding,
|
1445 |
+
): SpawnSyncReturns<string>;
|
1446 |
+
function spawnSync(
|
1447 |
+
command: string,
|
1448 |
+
args: readonly string[],
|
1449 |
+
options: SpawnSyncOptionsWithBufferEncoding,
|
1450 |
+
): SpawnSyncReturns<Buffer>;
|
1451 |
+
function spawnSync(
|
1452 |
+
command: string,
|
1453 |
+
args?: readonly string[],
|
1454 |
+
options?: SpawnSyncOptions,
|
1455 |
+
): SpawnSyncReturns<string | Buffer>;
|
1456 |
+
interface CommonExecOptions extends CommonOptions {
|
1457 |
+
input?: string | NodeJS.ArrayBufferView | undefined;
|
1458 |
+
/**
|
1459 |
+
* Can be set to 'pipe', 'inherit, or 'ignore', or an array of these strings.
|
1460 |
+
* If passed as an array, the first element is used for `stdin`, the second for
|
1461 |
+
* `stdout`, and the third for `stderr`. A fourth element can be used to
|
1462 |
+
* specify the `stdio` behavior beyond the standard streams. See
|
1463 |
+
* {@link ChildProcess.stdio} for more information.
|
1464 |
+
*
|
1465 |
+
* @default 'pipe'
|
1466 |
+
*/
|
1467 |
+
stdio?: StdioOptions | undefined;
|
1468 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
1469 |
+
maxBuffer?: number | undefined;
|
1470 |
+
encoding?: BufferEncoding | "buffer" | null | undefined;
|
1471 |
+
}
|
1472 |
+
interface ExecSyncOptions extends CommonExecOptions {
|
1473 |
+
shell?: string | undefined;
|
1474 |
+
}
|
1475 |
+
interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
|
1476 |
+
encoding: BufferEncoding;
|
1477 |
+
}
|
1478 |
+
interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
|
1479 |
+
encoding?: "buffer" | null | undefined;
|
1480 |
+
}
|
1481 |
+
/**
|
1482 |
+
* The `child_process.execSync()` method is generally identical to {@link exec} with the exception that the method will not return
|
1483 |
+
* until the child process has fully closed. When a timeout has been encountered
|
1484 |
+
* and `killSignal` is sent, the method won't return until the process has
|
1485 |
+
* completely exited. If the child process intercepts and handles the `SIGTERM` signal and doesn't exit, the parent process will wait until the child process
|
1486 |
+
* has exited.
|
1487 |
+
*
|
1488 |
+
* If the process times out or has a non-zero exit code, this method will throw.
|
1489 |
+
* The `Error` object will contain the entire result from {@link spawnSync}.
|
1490 |
+
*
|
1491 |
+
* **Never pass unsanitized user input to this function. Any input containing shell**
|
1492 |
+
* **metacharacters may be used to trigger arbitrary command execution.**
|
1493 |
+
* @since v0.11.12
|
1494 |
+
* @param command The command to run.
|
1495 |
+
* @return The stdout from the command.
|
1496 |
+
*/
|
1497 |
+
function execSync(command: string): Buffer;
|
1498 |
+
function execSync(command: string, options: ExecSyncOptionsWithStringEncoding): string;
|
1499 |
+
function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): Buffer;
|
1500 |
+
function execSync(command: string, options?: ExecSyncOptions): string | Buffer;
|
1501 |
+
interface ExecFileSyncOptions extends CommonExecOptions {
|
1502 |
+
shell?: boolean | string | undefined;
|
1503 |
+
}
|
1504 |
+
interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
|
1505 |
+
encoding: BufferEncoding;
|
1506 |
+
}
|
1507 |
+
interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
|
1508 |
+
encoding?: "buffer" | null; // specify `null`.
|
1509 |
+
}
|
1510 |
+
/**
|
1511 |
+
* The `child_process.execFileSync()` method is generally identical to {@link execFile} with the exception that the method will not
|
1512 |
+
* return until the child process has fully closed. When a timeout has been
|
1513 |
+
* encountered and `killSignal` is sent, the method won't return until the process
|
1514 |
+
* has completely exited.
|
1515 |
+
*
|
1516 |
+
* If the child process intercepts and handles the `SIGTERM` signal and
|
1517 |
+
* does not exit, the parent process will still wait until the child process has
|
1518 |
+
* exited.
|
1519 |
+
*
|
1520 |
+
* If the process times out or has a non-zero exit code, this method will throw an `Error` that will include the full result of the underlying {@link spawnSync}.
|
1521 |
+
*
|
1522 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
1523 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
1524 |
+
* **arbitrary command execution.**
|
1525 |
+
* @since v0.11.12
|
1526 |
+
* @param file The name or path of the executable file to run.
|
1527 |
+
* @param args List of string arguments.
|
1528 |
+
* @return The stdout from the command.
|
1529 |
+
*/
|
1530 |
+
function execFileSync(file: string): Buffer;
|
1531 |
+
function execFileSync(file: string, options: ExecFileSyncOptionsWithStringEncoding): string;
|
1532 |
+
function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): Buffer;
|
1533 |
+
function execFileSync(file: string, options?: ExecFileSyncOptions): string | Buffer;
|
1534 |
+
function execFileSync(file: string, args: readonly string[]): Buffer;
|
1535 |
+
function execFileSync(
|
1536 |
+
file: string,
|
1537 |
+
args: readonly string[],
|
1538 |
+
options: ExecFileSyncOptionsWithStringEncoding,
|
1539 |
+
): string;
|
1540 |
+
function execFileSync(
|
1541 |
+
file: string,
|
1542 |
+
args: readonly string[],
|
1543 |
+
options: ExecFileSyncOptionsWithBufferEncoding,
|
1544 |
+
): Buffer;
|
1545 |
+
function execFileSync(file: string, args?: readonly string[], options?: ExecFileSyncOptions): string | Buffer;
|
1546 |
+
}
|
1547 |
+
declare module "node:child_process" {
|
1548 |
+
export * from "child_process";
|
1549 |
+
}
|
clone/node_modules/@types/node/cluster.d.ts
ADDED
@@ -0,0 +1,579 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Clusters of Node.js processes can be used to run multiple instances of Node.js
|
3 |
+
* that can distribute workloads among their application threads. When process isolation
|
4 |
+
* is not needed, use the [`worker_threads`](https://nodejs.org/docs/latest-v22.x/api/worker_threads.html)
|
5 |
+
* module instead, which allows running multiple application threads within a single Node.js instance.
|
6 |
+
*
|
7 |
+
* The cluster module allows easy creation of child processes that all share
|
8 |
+
* server ports.
|
9 |
+
*
|
10 |
+
* ```js
|
11 |
+
* import cluster from 'node:cluster';
|
12 |
+
* import http from 'node:http';
|
13 |
+
* import { availableParallelism } from 'node:os';
|
14 |
+
* import process from 'node:process';
|
15 |
+
*
|
16 |
+
* const numCPUs = availableParallelism();
|
17 |
+
*
|
18 |
+
* if (cluster.isPrimary) {
|
19 |
+
* console.log(`Primary ${process.pid} is running`);
|
20 |
+
*
|
21 |
+
* // Fork workers.
|
22 |
+
* for (let i = 0; i < numCPUs; i++) {
|
23 |
+
* cluster.fork();
|
24 |
+
* }
|
25 |
+
*
|
26 |
+
* cluster.on('exit', (worker, code, signal) => {
|
27 |
+
* console.log(`worker ${worker.process.pid} died`);
|
28 |
+
* });
|
29 |
+
* } else {
|
30 |
+
* // Workers can share any TCP connection
|
31 |
+
* // In this case it is an HTTP server
|
32 |
+
* http.createServer((req, res) => {
|
33 |
+
* res.writeHead(200);
|
34 |
+
* res.end('hello world\n');
|
35 |
+
* }).listen(8000);
|
36 |
+
*
|
37 |
+
* console.log(`Worker ${process.pid} started`);
|
38 |
+
* }
|
39 |
+
* ```
|
40 |
+
*
|
41 |
+
* Running Node.js will now share port 8000 between the workers:
|
42 |
+
*
|
43 |
+
* ```console
|
44 |
+
* $ node server.js
|
45 |
+
* Primary 3596 is running
|
46 |
+
* Worker 4324 started
|
47 |
+
* Worker 4520 started
|
48 |
+
* Worker 6056 started
|
49 |
+
* Worker 5644 started
|
50 |
+
* ```
|
51 |
+
*
|
52 |
+
* On Windows, it is not yet possible to set up a named pipe server in a worker.
|
53 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/cluster.js)
|
54 |
+
*/
|
55 |
+
declare module "cluster" {
|
56 |
+
import * as child from "node:child_process";
|
57 |
+
import EventEmitter = require("node:events");
|
58 |
+
import * as net from "node:net";
|
59 |
+
type SerializationType = "json" | "advanced";
|
60 |
+
export interface ClusterSettings {
|
61 |
+
/**
|
62 |
+
* List of string arguments passed to the Node.js executable.
|
63 |
+
* @default process.execArgv
|
64 |
+
*/
|
65 |
+
execArgv?: string[] | undefined;
|
66 |
+
/**
|
67 |
+
* File path to worker file.
|
68 |
+
* @default process.argv[1]
|
69 |
+
*/
|
70 |
+
exec?: string | undefined;
|
71 |
+
/**
|
72 |
+
* String arguments passed to worker.
|
73 |
+
* @default process.argv.slice(2)
|
74 |
+
*/
|
75 |
+
args?: string[] | undefined;
|
76 |
+
/**
|
77 |
+
* Whether or not to send output to parent's stdio.
|
78 |
+
* @default false
|
79 |
+
*/
|
80 |
+
silent?: boolean | undefined;
|
81 |
+
/**
|
82 |
+
* Configures the stdio of forked processes. Because the cluster module relies on IPC to function, this configuration must
|
83 |
+
* contain an `'ipc'` entry. When this option is provided, it overrides `silent`. See [`child_prcess.spawn()`](https://nodejs.org/docs/latest-v22.x/api/child_process.html#child_processspawncommand-args-options)'s
|
84 |
+
* [`stdio`](https://nodejs.org/docs/latest-v22.x/api/child_process.html#optionsstdio).
|
85 |
+
*/
|
86 |
+
stdio?: any[] | undefined;
|
87 |
+
/**
|
88 |
+
* Sets the user identity of the process. (See [`setuid(2)`](https://man7.org/linux/man-pages/man2/setuid.2.html).)
|
89 |
+
*/
|
90 |
+
uid?: number | undefined;
|
91 |
+
/**
|
92 |
+
* Sets the group identity of the process. (See [`setgid(2)`](https://man7.org/linux/man-pages/man2/setgid.2.html).)
|
93 |
+
*/
|
94 |
+
gid?: number | undefined;
|
95 |
+
/**
|
96 |
+
* Sets inspector port of worker. This can be a number, or a function that takes no arguments and returns a number.
|
97 |
+
* By default each worker gets its own port, incremented from the primary's `process.debugPort`.
|
98 |
+
*/
|
99 |
+
inspectPort?: number | (() => number) | undefined;
|
100 |
+
/**
|
101 |
+
* Specify the kind of serialization used for sending messages between processes. Possible values are `'json'` and `'advanced'`.
|
102 |
+
* See [Advanced serialization for `child_process`](https://nodejs.org/docs/latest-v22.x/api/child_process.html#advanced-serialization) for more details.
|
103 |
+
* @default false
|
104 |
+
*/
|
105 |
+
serialization?: SerializationType | undefined;
|
106 |
+
/**
|
107 |
+
* Current working directory of the worker process.
|
108 |
+
* @default undefined (inherits from parent process)
|
109 |
+
*/
|
110 |
+
cwd?: string | undefined;
|
111 |
+
/**
|
112 |
+
* Hide the forked processes console window that would normally be created on Windows systems.
|
113 |
+
* @default false
|
114 |
+
*/
|
115 |
+
windowsHide?: boolean | undefined;
|
116 |
+
}
|
117 |
+
export interface Address {
|
118 |
+
address: string;
|
119 |
+
port: number;
|
120 |
+
/**
|
121 |
+
* The `addressType` is one of:
|
122 |
+
*
|
123 |
+
* * `4` (TCPv4)
|
124 |
+
* * `6` (TCPv6)
|
125 |
+
* * `-1` (Unix domain socket)
|
126 |
+
* * `'udp4'` or `'udp6'` (UDPv4 or UDPv6)
|
127 |
+
*/
|
128 |
+
addressType: 4 | 6 | -1 | "udp4" | "udp6";
|
129 |
+
}
|
130 |
+
/**
|
131 |
+
* A `Worker` object contains all public information and method about a worker.
|
132 |
+
* In the primary it can be obtained using `cluster.workers`. In a worker
|
133 |
+
* it can be obtained using `cluster.worker`.
|
134 |
+
* @since v0.7.0
|
135 |
+
*/
|
136 |
+
export class Worker extends EventEmitter {
|
137 |
+
/**
|
138 |
+
* Each new worker is given its own unique id, this id is stored in the `id`.
|
139 |
+
*
|
140 |
+
* While a worker is alive, this is the key that indexes it in `cluster.workers`.
|
141 |
+
* @since v0.8.0
|
142 |
+
*/
|
143 |
+
id: number;
|
144 |
+
/**
|
145 |
+
* All workers are created using [`child_process.fork()`](https://nodejs.org/docs/latest-v22.x/api/child_process.html#child_processforkmodulepath-args-options), the returned object
|
146 |
+
* from this function is stored as `.process`. In a worker, the global `process` is stored.
|
147 |
+
*
|
148 |
+
* See: [Child Process module](https://nodejs.org/docs/latest-v22.x/api/child_process.html#child_processforkmodulepath-args-options).
|
149 |
+
*
|
150 |
+
* Workers will call `process.exit(0)` if the `'disconnect'` event occurs
|
151 |
+
* on `process` and `.exitedAfterDisconnect` is not `true`. This protects against
|
152 |
+
* accidental disconnection.
|
153 |
+
* @since v0.7.0
|
154 |
+
*/
|
155 |
+
process: child.ChildProcess;
|
156 |
+
/**
|
157 |
+
* Send a message to a worker or primary, optionally with a handle.
|
158 |
+
*
|
159 |
+
* In the primary, this sends a message to a specific worker. It is identical to [`ChildProcess.send()`](https://nodejs.org/docs/latest-v22.x/api/child_process.html#subprocesssendmessage-sendhandle-options-callback).
|
160 |
+
*
|
161 |
+
* In a worker, this sends a message to the primary. It is identical to `process.send()`.
|
162 |
+
*
|
163 |
+
* This example will echo back all messages from the primary:
|
164 |
+
*
|
165 |
+
* ```js
|
166 |
+
* if (cluster.isPrimary) {
|
167 |
+
* const worker = cluster.fork();
|
168 |
+
* worker.send('hi there');
|
169 |
+
*
|
170 |
+
* } else if (cluster.isWorker) {
|
171 |
+
* process.on('message', (msg) => {
|
172 |
+
* process.send(msg);
|
173 |
+
* });
|
174 |
+
* }
|
175 |
+
* ```
|
176 |
+
* @since v0.7.0
|
177 |
+
* @param options The `options` argument, if present, is an object used to parameterize the sending of certain types of handles.
|
178 |
+
*/
|
179 |
+
send(message: child.Serializable, callback?: (error: Error | null) => void): boolean;
|
180 |
+
send(
|
181 |
+
message: child.Serializable,
|
182 |
+
sendHandle: child.SendHandle,
|
183 |
+
callback?: (error: Error | null) => void,
|
184 |
+
): boolean;
|
185 |
+
send(
|
186 |
+
message: child.Serializable,
|
187 |
+
sendHandle: child.SendHandle,
|
188 |
+
options?: child.MessageOptions,
|
189 |
+
callback?: (error: Error | null) => void,
|
190 |
+
): boolean;
|
191 |
+
/**
|
192 |
+
* This function will kill the worker. In the primary worker, it does this by
|
193 |
+
* disconnecting the `worker.process`, and once disconnected, killing with `signal`. In the worker, it does it by killing the process with `signal`.
|
194 |
+
*
|
195 |
+
* The `kill()` function kills the worker process without waiting for a graceful
|
196 |
+
* disconnect, it has the same behavior as `worker.process.kill()`.
|
197 |
+
*
|
198 |
+
* This method is aliased as `worker.destroy()` for backwards compatibility.
|
199 |
+
*
|
200 |
+
* In a worker, `process.kill()` exists, but it is not this function;
|
201 |
+
* it is [`kill()`](https://nodejs.org/docs/latest-v22.x/api/process.html#processkillpid-signal).
|
202 |
+
* @since v0.9.12
|
203 |
+
* @param [signal='SIGTERM'] Name of the kill signal to send to the worker process.
|
204 |
+
*/
|
205 |
+
kill(signal?: string): void;
|
206 |
+
destroy(signal?: string): void;
|
207 |
+
/**
|
208 |
+
* In a worker, this function will close all servers, wait for the `'close'` event
|
209 |
+
* on those servers, and then disconnect the IPC channel.
|
210 |
+
*
|
211 |
+
* In the primary, an internal message is sent to the worker causing it to call `.disconnect()` on itself.
|
212 |
+
*
|
213 |
+
* Causes `.exitedAfterDisconnect` to be set.
|
214 |
+
*
|
215 |
+
* After a server is closed, it will no longer accept new connections,
|
216 |
+
* but connections may be accepted by any other listening worker. Existing
|
217 |
+
* connections will be allowed to close as usual. When no more connections exist,
|
218 |
+
* see `server.close()`, the IPC channel to the worker will close allowing it
|
219 |
+
* to die gracefully.
|
220 |
+
*
|
221 |
+
* The above applies _only_ to server connections, client connections are not
|
222 |
+
* automatically closed by workers, and disconnect does not wait for them to close
|
223 |
+
* before exiting.
|
224 |
+
*
|
225 |
+
* In a worker, `process.disconnect` exists, but it is not this function;
|
226 |
+
* it is `disconnect()`.
|
227 |
+
*
|
228 |
+
* Because long living server connections may block workers from disconnecting, it
|
229 |
+
* may be useful to send a message, so application specific actions may be taken to
|
230 |
+
* close them. It also may be useful to implement a timeout, killing a worker if
|
231 |
+
* the `'disconnect'` event has not been emitted after some time.
|
232 |
+
*
|
233 |
+
* ```js
|
234 |
+
* import net from 'node:net';
|
235 |
+
*
|
236 |
+
* if (cluster.isPrimary) {
|
237 |
+
* const worker = cluster.fork();
|
238 |
+
* let timeout;
|
239 |
+
*
|
240 |
+
* worker.on('listening', (address) => {
|
241 |
+
* worker.send('shutdown');
|
242 |
+
* worker.disconnect();
|
243 |
+
* timeout = setTimeout(() => {
|
244 |
+
* worker.kill();
|
245 |
+
* }, 2000);
|
246 |
+
* });
|
247 |
+
*
|
248 |
+
* worker.on('disconnect', () => {
|
249 |
+
* clearTimeout(timeout);
|
250 |
+
* });
|
251 |
+
*
|
252 |
+
* } else if (cluster.isWorker) {
|
253 |
+
* const server = net.createServer((socket) => {
|
254 |
+
* // Connections never end
|
255 |
+
* });
|
256 |
+
*
|
257 |
+
* server.listen(8000);
|
258 |
+
*
|
259 |
+
* process.on('message', (msg) => {
|
260 |
+
* if (msg === 'shutdown') {
|
261 |
+
* // Initiate graceful close of any connections to server
|
262 |
+
* }
|
263 |
+
* });
|
264 |
+
* }
|
265 |
+
* ```
|
266 |
+
* @since v0.7.7
|
267 |
+
* @return A reference to `worker`.
|
268 |
+
*/
|
269 |
+
disconnect(): void;
|
270 |
+
/**
|
271 |
+
* This function returns `true` if the worker is connected to its primary via its
|
272 |
+
* IPC channel, `false` otherwise. A worker is connected to its primary after it
|
273 |
+
* has been created. It is disconnected after the `'disconnect'` event is emitted.
|
274 |
+
* @since v0.11.14
|
275 |
+
*/
|
276 |
+
isConnected(): boolean;
|
277 |
+
/**
|
278 |
+
* This function returns `true` if the worker's process has terminated (either
|
279 |
+
* because of exiting or being signaled). Otherwise, it returns `false`.
|
280 |
+
*
|
281 |
+
* ```js
|
282 |
+
* import cluster from 'node:cluster';
|
283 |
+
* import http from 'node:http';
|
284 |
+
* import { availableParallelism } from 'node:os';
|
285 |
+
* import process from 'node:process';
|
286 |
+
*
|
287 |
+
* const numCPUs = availableParallelism();
|
288 |
+
*
|
289 |
+
* if (cluster.isPrimary) {
|
290 |
+
* console.log(`Primary ${process.pid} is running`);
|
291 |
+
*
|
292 |
+
* // Fork workers.
|
293 |
+
* for (let i = 0; i < numCPUs; i++) {
|
294 |
+
* cluster.fork();
|
295 |
+
* }
|
296 |
+
*
|
297 |
+
* cluster.on('fork', (worker) => {
|
298 |
+
* console.log('worker is dead:', worker.isDead());
|
299 |
+
* });
|
300 |
+
*
|
301 |
+
* cluster.on('exit', (worker, code, signal) => {
|
302 |
+
* console.log('worker is dead:', worker.isDead());
|
303 |
+
* });
|
304 |
+
* } else {
|
305 |
+
* // Workers can share any TCP connection. In this case, it is an HTTP server.
|
306 |
+
* http.createServer((req, res) => {
|
307 |
+
* res.writeHead(200);
|
308 |
+
* res.end(`Current process\n ${process.pid}`);
|
309 |
+
* process.kill(process.pid);
|
310 |
+
* }).listen(8000);
|
311 |
+
* }
|
312 |
+
* ```
|
313 |
+
* @since v0.11.14
|
314 |
+
*/
|
315 |
+
isDead(): boolean;
|
316 |
+
/**
|
317 |
+
* This property is `true` if the worker exited due to `.disconnect()`.
|
318 |
+
* If the worker exited any other way, it is `false`. If the
|
319 |
+
* worker has not exited, it is `undefined`.
|
320 |
+
*
|
321 |
+
* The boolean `worker.exitedAfterDisconnect` allows distinguishing between
|
322 |
+
* voluntary and accidental exit, the primary may choose not to respawn a worker
|
323 |
+
* based on this value.
|
324 |
+
*
|
325 |
+
* ```js
|
326 |
+
* cluster.on('exit', (worker, code, signal) => {
|
327 |
+
* if (worker.exitedAfterDisconnect === true) {
|
328 |
+
* console.log('Oh, it was just voluntary – no need to worry');
|
329 |
+
* }
|
330 |
+
* });
|
331 |
+
*
|
332 |
+
* // kill worker
|
333 |
+
* worker.kill();
|
334 |
+
* ```
|
335 |
+
* @since v6.0.0
|
336 |
+
*/
|
337 |
+
exitedAfterDisconnect: boolean;
|
338 |
+
/**
|
339 |
+
* events.EventEmitter
|
340 |
+
* 1. disconnect
|
341 |
+
* 2. error
|
342 |
+
* 3. exit
|
343 |
+
* 4. listening
|
344 |
+
* 5. message
|
345 |
+
* 6. online
|
346 |
+
*/
|
347 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
348 |
+
addListener(event: "disconnect", listener: () => void): this;
|
349 |
+
addListener(event: "error", listener: (error: Error) => void): this;
|
350 |
+
addListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
351 |
+
addListener(event: "listening", listener: (address: Address) => void): this;
|
352 |
+
addListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
353 |
+
addListener(event: "online", listener: () => void): this;
|
354 |
+
emit(event: string | symbol, ...args: any[]): boolean;
|
355 |
+
emit(event: "disconnect"): boolean;
|
356 |
+
emit(event: "error", error: Error): boolean;
|
357 |
+
emit(event: "exit", code: number, signal: string): boolean;
|
358 |
+
emit(event: "listening", address: Address): boolean;
|
359 |
+
emit(event: "message", message: any, handle: net.Socket | net.Server): boolean;
|
360 |
+
emit(event: "online"): boolean;
|
361 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
362 |
+
on(event: "disconnect", listener: () => void): this;
|
363 |
+
on(event: "error", listener: (error: Error) => void): this;
|
364 |
+
on(event: "exit", listener: (code: number, signal: string) => void): this;
|
365 |
+
on(event: "listening", listener: (address: Address) => void): this;
|
366 |
+
on(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
367 |
+
on(event: "online", listener: () => void): this;
|
368 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
369 |
+
once(event: "disconnect", listener: () => void): this;
|
370 |
+
once(event: "error", listener: (error: Error) => void): this;
|
371 |
+
once(event: "exit", listener: (code: number, signal: string) => void): this;
|
372 |
+
once(event: "listening", listener: (address: Address) => void): this;
|
373 |
+
once(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
374 |
+
once(event: "online", listener: () => void): this;
|
375 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
376 |
+
prependListener(event: "disconnect", listener: () => void): this;
|
377 |
+
prependListener(event: "error", listener: (error: Error) => void): this;
|
378 |
+
prependListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
379 |
+
prependListener(event: "listening", listener: (address: Address) => void): this;
|
380 |
+
prependListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
381 |
+
prependListener(event: "online", listener: () => void): this;
|
382 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
383 |
+
prependOnceListener(event: "disconnect", listener: () => void): this;
|
384 |
+
prependOnceListener(event: "error", listener: (error: Error) => void): this;
|
385 |
+
prependOnceListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
386 |
+
prependOnceListener(event: "listening", listener: (address: Address) => void): this;
|
387 |
+
prependOnceListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
388 |
+
prependOnceListener(event: "online", listener: () => void): this;
|
389 |
+
}
|
390 |
+
export interface Cluster extends EventEmitter {
|
391 |
+
disconnect(callback?: () => void): void;
|
392 |
+
/**
|
393 |
+
* Spawn a new worker process.
|
394 |
+
*
|
395 |
+
* This can only be called from the primary process.
|
396 |
+
* @param env Key/value pairs to add to worker process environment.
|
397 |
+
* @since v0.6.0
|
398 |
+
*/
|
399 |
+
fork(env?: any): Worker;
|
400 |
+
/** @deprecated since v16.0.0 - use isPrimary. */
|
401 |
+
readonly isMaster: boolean;
|
402 |
+
/**
|
403 |
+
* True if the process is a primary. This is determined by the `process.env.NODE_UNIQUE_ID`. If `process.env.NODE_UNIQUE_ID`
|
404 |
+
* is undefined, then `isPrimary` is `true`.
|
405 |
+
* @since v16.0.0
|
406 |
+
*/
|
407 |
+
readonly isPrimary: boolean;
|
408 |
+
/**
|
409 |
+
* True if the process is not a primary (it is the negation of `cluster.isPrimary`).
|
410 |
+
* @since v0.6.0
|
411 |
+
*/
|
412 |
+
readonly isWorker: boolean;
|
413 |
+
/**
|
414 |
+
* The scheduling policy, either `cluster.SCHED_RR` for round-robin or `cluster.SCHED_NONE` to leave it to the operating system. This is a
|
415 |
+
* global setting and effectively frozen once either the first worker is spawned, or [`.setupPrimary()`](https://nodejs.org/docs/latest-v22.x/api/cluster.html#clustersetupprimarysettings)
|
416 |
+
* is called, whichever comes first.
|
417 |
+
*
|
418 |
+
* `SCHED_RR` is the default on all operating systems except Windows. Windows will change to `SCHED_RR` once libuv is able to effectively distribute
|
419 |
+
* IOCP handles without incurring a large performance hit.
|
420 |
+
*
|
421 |
+
* `cluster.schedulingPolicy` can also be set through the `NODE_CLUSTER_SCHED_POLICY` environment variable. Valid values are `'rr'` and `'none'`.
|
422 |
+
* @since v0.11.2
|
423 |
+
*/
|
424 |
+
schedulingPolicy: number;
|
425 |
+
/**
|
426 |
+
* After calling [`.setupPrimary()`](https://nodejs.org/docs/latest-v22.x/api/cluster.html#clustersetupprimarysettings)
|
427 |
+
* (or [`.fork()`](https://nodejs.org/docs/latest-v22.x/api/cluster.html#clusterforkenv)) this settings object will contain
|
428 |
+
* the settings, including the default values.
|
429 |
+
*
|
430 |
+
* This object is not intended to be changed or set manually.
|
431 |
+
* @since v0.7.1
|
432 |
+
*/
|
433 |
+
readonly settings: ClusterSettings;
|
434 |
+
/** @deprecated since v16.0.0 - use [`.setupPrimary()`](https://nodejs.org/docs/latest-v22.x/api/cluster.html#clustersetupprimarysettings) instead. */
|
435 |
+
setupMaster(settings?: ClusterSettings): void;
|
436 |
+
/**
|
437 |
+
* `setupPrimary` is used to change the default 'fork' behavior. Once called, the settings will be present in `cluster.settings`.
|
438 |
+
*
|
439 |
+
* Any settings changes only affect future calls to [`.fork()`](https://nodejs.org/docs/latest-v22.x/api/cluster.html#clusterforkenv)
|
440 |
+
* and have no effect on workers that are already running.
|
441 |
+
*
|
442 |
+
* The only attribute of a worker that cannot be set via `.setupPrimary()` is the `env` passed to
|
443 |
+
* [`.fork()`](https://nodejs.org/docs/latest-v22.x/api/cluster.html#clusterforkenv).
|
444 |
+
*
|
445 |
+
* The defaults above apply to the first call only; the defaults for later calls are the current values at the time of
|
446 |
+
* `cluster.setupPrimary()` is called.
|
447 |
+
*
|
448 |
+
* ```js
|
449 |
+
* import cluster from 'node:cluster';
|
450 |
+
*
|
451 |
+
* cluster.setupPrimary({
|
452 |
+
* exec: 'worker.js',
|
453 |
+
* args: ['--use', 'https'],
|
454 |
+
* silent: true,
|
455 |
+
* });
|
456 |
+
* cluster.fork(); // https worker
|
457 |
+
* cluster.setupPrimary({
|
458 |
+
* exec: 'worker.js',
|
459 |
+
* args: ['--use', 'http'],
|
460 |
+
* });
|
461 |
+
* cluster.fork(); // http worker
|
462 |
+
* ```
|
463 |
+
*
|
464 |
+
* This can only be called from the primary process.
|
465 |
+
* @since v16.0.0
|
466 |
+
*/
|
467 |
+
setupPrimary(settings?: ClusterSettings): void;
|
468 |
+
/**
|
469 |
+
* A reference to the current worker object. Not available in the primary process.
|
470 |
+
*
|
471 |
+
* ```js
|
472 |
+
* import cluster from 'node:cluster';
|
473 |
+
*
|
474 |
+
* if (cluster.isPrimary) {
|
475 |
+
* console.log('I am primary');
|
476 |
+
* cluster.fork();
|
477 |
+
* cluster.fork();
|
478 |
+
* } else if (cluster.isWorker) {
|
479 |
+
* console.log(`I am worker #${cluster.worker.id}`);
|
480 |
+
* }
|
481 |
+
* ```
|
482 |
+
* @since v0.7.0
|
483 |
+
*/
|
484 |
+
readonly worker?: Worker | undefined;
|
485 |
+
/**
|
486 |
+
* A hash that stores the active worker objects, keyed by `id` field. This makes it easy to loop through all the workers. It is only available in the primary process.
|
487 |
+
*
|
488 |
+
* A worker is removed from `cluster.workers` after the worker has disconnected _and_ exited. The order between these two events cannot be determined in advance. However, it
|
489 |
+
* is guaranteed that the removal from the `cluster.workers` list happens before the last `'disconnect'` or `'exit'` event is emitted.
|
490 |
+
*
|
491 |
+
* ```js
|
492 |
+
* import cluster from 'node:cluster';
|
493 |
+
*
|
494 |
+
* for (const worker of Object.values(cluster.workers)) {
|
495 |
+
* worker.send('big announcement to all workers');
|
496 |
+
* }
|
497 |
+
* ```
|
498 |
+
* @since v0.7.0
|
499 |
+
*/
|
500 |
+
readonly workers?: NodeJS.Dict<Worker> | undefined;
|
501 |
+
readonly SCHED_NONE: number;
|
502 |
+
readonly SCHED_RR: number;
|
503 |
+
/**
|
504 |
+
* events.EventEmitter
|
505 |
+
* 1. disconnect
|
506 |
+
* 2. exit
|
507 |
+
* 3. fork
|
508 |
+
* 4. listening
|
509 |
+
* 5. message
|
510 |
+
* 6. online
|
511 |
+
* 7. setup
|
512 |
+
*/
|
513 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
514 |
+
addListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
515 |
+
addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
516 |
+
addListener(event: "fork", listener: (worker: Worker) => void): this;
|
517 |
+
addListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
518 |
+
addListener(
|
519 |
+
event: "message",
|
520 |
+
listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void,
|
521 |
+
): this; // the handle is a net.Socket or net.Server object, or undefined.
|
522 |
+
addListener(event: "online", listener: (worker: Worker) => void): this;
|
523 |
+
addListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
524 |
+
emit(event: string | symbol, ...args: any[]): boolean;
|
525 |
+
emit(event: "disconnect", worker: Worker): boolean;
|
526 |
+
emit(event: "exit", worker: Worker, code: number, signal: string): boolean;
|
527 |
+
emit(event: "fork", worker: Worker): boolean;
|
528 |
+
emit(event: "listening", worker: Worker, address: Address): boolean;
|
529 |
+
emit(event: "message", worker: Worker, message: any, handle: net.Socket | net.Server): boolean;
|
530 |
+
emit(event: "online", worker: Worker): boolean;
|
531 |
+
emit(event: "setup", settings: ClusterSettings): boolean;
|
532 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
533 |
+
on(event: "disconnect", listener: (worker: Worker) => void): this;
|
534 |
+
on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
535 |
+
on(event: "fork", listener: (worker: Worker) => void): this;
|
536 |
+
on(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
537 |
+
on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
538 |
+
on(event: "online", listener: (worker: Worker) => void): this;
|
539 |
+
on(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
540 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
541 |
+
once(event: "disconnect", listener: (worker: Worker) => void): this;
|
542 |
+
once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
543 |
+
once(event: "fork", listener: (worker: Worker) => void): this;
|
544 |
+
once(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
545 |
+
once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
546 |
+
once(event: "online", listener: (worker: Worker) => void): this;
|
547 |
+
once(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
548 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
549 |
+
prependListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
550 |
+
prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
551 |
+
prependListener(event: "fork", listener: (worker: Worker) => void): this;
|
552 |
+
prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
553 |
+
// the handle is a net.Socket or net.Server object, or undefined.
|
554 |
+
prependListener(
|
555 |
+
event: "message",
|
556 |
+
listener: (worker: Worker, message: any, handle?: net.Socket | net.Server) => void,
|
557 |
+
): this;
|
558 |
+
prependListener(event: "online", listener: (worker: Worker) => void): this;
|
559 |
+
prependListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
560 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
561 |
+
prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
562 |
+
prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
563 |
+
prependOnceListener(event: "fork", listener: (worker: Worker) => void): this;
|
564 |
+
prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
565 |
+
// the handle is a net.Socket or net.Server object, or undefined.
|
566 |
+
prependOnceListener(
|
567 |
+
event: "message",
|
568 |
+
listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void,
|
569 |
+
): this;
|
570 |
+
prependOnceListener(event: "online", listener: (worker: Worker) => void): this;
|
571 |
+
prependOnceListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
572 |
+
}
|
573 |
+
const cluster: Cluster;
|
574 |
+
export default cluster;
|
575 |
+
}
|
576 |
+
declare module "node:cluster" {
|
577 |
+
export * from "cluster";
|
578 |
+
export { default as default } from "cluster";
|
579 |
+
}
|
clone/node_modules/@types/node/compatibility/disposable.d.ts
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Polyfills for the explicit resource management types added in TypeScript 5.2.
|
2 |
+
// TODO: remove once this package no longer supports TS 5.1, and replace with a
|
3 |
+
// <reference> to TypeScript's disposable library in index.d.ts.
|
4 |
+
|
5 |
+
interface SymbolConstructor {
|
6 |
+
readonly dispose: unique symbol;
|
7 |
+
readonly asyncDispose: unique symbol;
|
8 |
+
}
|
9 |
+
|
10 |
+
interface Disposable {
|
11 |
+
[Symbol.dispose](): void;
|
12 |
+
}
|
13 |
+
|
14 |
+
interface AsyncDisposable {
|
15 |
+
[Symbol.asyncDispose](): PromiseLike<void>;
|
16 |
+
}
|
clone/node_modules/@types/node/compatibility/index.d.ts
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Declaration files in this directory contain types relating to TypeScript library features
|
2 |
+
// that are not included in all TypeScript versions supported by DefinitelyTyped, but
|
3 |
+
// which can be made backwards-compatible without needing `typesVersions`.
|
4 |
+
// If adding declarations to this directory, please specify which versions of TypeScript require them,
|
5 |
+
// so that they can be removed when no longer needed.
|
6 |
+
|
7 |
+
/// <reference path="disposable.d.ts" />
|
8 |
+
/// <reference path="indexable.d.ts" />
|
9 |
+
/// <reference path="iterators.d.ts" />
|
clone/node_modules/@types/node/compatibility/indexable.d.ts
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Polyfill for ES2022's .at() method on string/array prototypes, added to TypeScript in 4.6.
|
2 |
+
// TODO: these methods are not used within @types/node, and should be removed at the next
|
3 |
+
// major @types/node version; users should include the es2022 TypeScript libraries
|
4 |
+
// if they need these features.
|
5 |
+
|
6 |
+
interface RelativeIndexable<T> {
|
7 |
+
at(index: number): T | undefined;
|
8 |
+
}
|
9 |
+
|
10 |
+
interface String extends RelativeIndexable<string> {}
|
11 |
+
interface Array<T> extends RelativeIndexable<T> {}
|
12 |
+
interface ReadonlyArray<T> extends RelativeIndexable<T> {}
|
13 |
+
interface Int8Array extends RelativeIndexable<number> {}
|
14 |
+
interface Uint8Array extends RelativeIndexable<number> {}
|
15 |
+
interface Uint8ClampedArray extends RelativeIndexable<number> {}
|
16 |
+
interface Int16Array extends RelativeIndexable<number> {}
|
17 |
+
interface Uint16Array extends RelativeIndexable<number> {}
|
18 |
+
interface Int32Array extends RelativeIndexable<number> {}
|
19 |
+
interface Uint32Array extends RelativeIndexable<number> {}
|
20 |
+
interface Float32Array extends RelativeIndexable<number> {}
|
21 |
+
interface Float64Array extends RelativeIndexable<number> {}
|
22 |
+
interface BigInt64Array extends RelativeIndexable<bigint> {}
|
23 |
+
interface BigUint64Array extends RelativeIndexable<bigint> {}
|
clone/node_modules/@types/node/compatibility/iterators.d.ts
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Backwards-compatible iterator interfaces, augmented with iterator helper methods by lib.esnext.iterator in TypeScript 5.6.
|
2 |
+
// The IterableIterator interface does not contain these methods, which creates assignability issues in places where IteratorObjects
|
3 |
+
// are expected (eg. DOM-compatible APIs) if lib.esnext.iterator is loaded.
|
4 |
+
// Also ensures that iterators returned by the Node API, which inherit from Iterator.prototype, correctly expose the iterator helper methods
|
5 |
+
// if lib.esnext.iterator is loaded.
|
6 |
+
// TODO: remove once this package no longer supports TS 5.5, and replace NodeJS.BuiltinIteratorReturn with BuiltinIteratorReturn.
|
7 |
+
|
8 |
+
// Placeholders for TS <5.6
|
9 |
+
interface IteratorObject<T, TReturn, TNext> {}
|
10 |
+
interface AsyncIteratorObject<T, TReturn, TNext> {}
|
11 |
+
|
12 |
+
declare namespace NodeJS {
|
13 |
+
// Populate iterator methods for TS <5.6
|
14 |
+
interface Iterator<T, TReturn, TNext> extends globalThis.Iterator<T, TReturn, TNext> {}
|
15 |
+
interface AsyncIterator<T, TReturn, TNext> extends globalThis.AsyncIterator<T, TReturn, TNext> {}
|
16 |
+
|
17 |
+
// Polyfill for TS 5.6's instrinsic BuiltinIteratorReturn type, required for DOM-compatible iterators
|
18 |
+
type BuiltinIteratorReturn = ReturnType<any[][typeof Symbol.iterator]> extends
|
19 |
+
globalThis.Iterator<any, infer TReturn> ? TReturn
|
20 |
+
: any;
|
21 |
+
}
|
clone/node_modules/@types/node/console.d.ts
ADDED
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* The `node:console` module provides a simple debugging console that is similar to
|
3 |
+
* the JavaScript console mechanism provided by web browsers.
|
4 |
+
*
|
5 |
+
* The module exports two specific components:
|
6 |
+
*
|
7 |
+
* * A `Console` class with methods such as `console.log()`, `console.error()`, and `console.warn()` that can be used to write to any Node.js stream.
|
8 |
+
* * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and
|
9 |
+
* [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
|
10 |
+
*
|
11 |
+
* _**Warning**_: The global console object's methods are neither consistently
|
12 |
+
* synchronous like the browser APIs they resemble, nor are they consistently
|
13 |
+
* asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for
|
14 |
+
* more information.
|
15 |
+
*
|
16 |
+
* Example using the global `console`:
|
17 |
+
*
|
18 |
+
* ```js
|
19 |
+
* console.log('hello world');
|
20 |
+
* // Prints: hello world, to stdout
|
21 |
+
* console.log('hello %s', 'world');
|
22 |
+
* // Prints: hello world, to stdout
|
23 |
+
* console.error(new Error('Whoops, something bad happened'));
|
24 |
+
* // Prints error message and stack trace to stderr:
|
25 |
+
* // Error: Whoops, something bad happened
|
26 |
+
* // at [eval]:5:15
|
27 |
+
* // at Script.runInThisContext (node:vm:132:18)
|
28 |
+
* // at Object.runInThisContext (node:vm:309:38)
|
29 |
+
* // at node:internal/process/execution:77:19
|
30 |
+
* // at [eval]-wrapper:6:22
|
31 |
+
* // at evalScript (node:internal/process/execution:76:60)
|
32 |
+
* // at node:internal/main/eval_string:23:3
|
33 |
+
*
|
34 |
+
* const name = 'Will Robinson';
|
35 |
+
* console.warn(`Danger ${name}! Danger!`);
|
36 |
+
* // Prints: Danger Will Robinson! Danger!, to stderr
|
37 |
+
* ```
|
38 |
+
*
|
39 |
+
* Example using the `Console` class:
|
40 |
+
*
|
41 |
+
* ```js
|
42 |
+
* const out = getStreamSomehow();
|
43 |
+
* const err = getStreamSomehow();
|
44 |
+
* const myConsole = new console.Console(out, err);
|
45 |
+
*
|
46 |
+
* myConsole.log('hello world');
|
47 |
+
* // Prints: hello world, to out
|
48 |
+
* myConsole.log('hello %s', 'world');
|
49 |
+
* // Prints: hello world, to out
|
50 |
+
* myConsole.error(new Error('Whoops, something bad happened'));
|
51 |
+
* // Prints: [Error: Whoops, something bad happened], to err
|
52 |
+
*
|
53 |
+
* const name = 'Will Robinson';
|
54 |
+
* myConsole.warn(`Danger ${name}! Danger!`);
|
55 |
+
* // Prints: Danger Will Robinson! Danger!, to err
|
56 |
+
* ```
|
57 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/console.js)
|
58 |
+
*/
|
59 |
+
declare module "console" {
|
60 |
+
import console = require("node:console");
|
61 |
+
export = console;
|
62 |
+
}
|
63 |
+
declare module "node:console" {
|
64 |
+
import { InspectOptions } from "node:util";
|
65 |
+
global {
|
66 |
+
// This needs to be global to avoid TS2403 in case lib.dom.d.ts is present in the same build
|
67 |
+
interface Console {
|
68 |
+
Console: console.ConsoleConstructor;
|
69 |
+
/**
|
70 |
+
* `console.assert()` writes a message if `value` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) or omitted. It only
|
71 |
+
* writes a message and does not otherwise affect execution. The output always
|
72 |
+
* starts with `"Assertion failed"`. If provided, `message` is formatted using
|
73 |
+
* [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args).
|
74 |
+
*
|
75 |
+
* If `value` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), nothing happens.
|
76 |
+
*
|
77 |
+
* ```js
|
78 |
+
* console.assert(true, 'does nothing');
|
79 |
+
*
|
80 |
+
* console.assert(false, 'Whoops %s work', 'didn\'t');
|
81 |
+
* // Assertion failed: Whoops didn't work
|
82 |
+
*
|
83 |
+
* console.assert();
|
84 |
+
* // Assertion failed
|
85 |
+
* ```
|
86 |
+
* @since v0.1.101
|
87 |
+
* @param value The value tested for being truthy.
|
88 |
+
* @param message All arguments besides `value` are used as error message.
|
89 |
+
*/
|
90 |
+
assert(value: any, message?: string, ...optionalParams: any[]): void;
|
91 |
+
/**
|
92 |
+
* When `stdout` is a TTY, calling `console.clear()` will attempt to clear the
|
93 |
+
* TTY. When `stdout` is not a TTY, this method does nothing.
|
94 |
+
*
|
95 |
+
* The specific operation of `console.clear()` can vary across operating systems
|
96 |
+
* and terminal types. For most Linux operating systems, `console.clear()` operates similarly to the `clear` shell command. On Windows, `console.clear()` will clear only the output in the
|
97 |
+
* current terminal viewport for the Node.js
|
98 |
+
* binary.
|
99 |
+
* @since v8.3.0
|
100 |
+
*/
|
101 |
+
clear(): void;
|
102 |
+
/**
|
103 |
+
* Maintains an internal counter specific to `label` and outputs to `stdout` the
|
104 |
+
* number of times `console.count()` has been called with the given `label`.
|
105 |
+
*
|
106 |
+
* ```js
|
107 |
+
* > console.count()
|
108 |
+
* default: 1
|
109 |
+
* undefined
|
110 |
+
* > console.count('default')
|
111 |
+
* default: 2
|
112 |
+
* undefined
|
113 |
+
* > console.count('abc')
|
114 |
+
* abc: 1
|
115 |
+
* undefined
|
116 |
+
* > console.count('xyz')
|
117 |
+
* xyz: 1
|
118 |
+
* undefined
|
119 |
+
* > console.count('abc')
|
120 |
+
* abc: 2
|
121 |
+
* undefined
|
122 |
+
* > console.count()
|
123 |
+
* default: 3
|
124 |
+
* undefined
|
125 |
+
* >
|
126 |
+
* ```
|
127 |
+
* @since v8.3.0
|
128 |
+
* @param [label='default'] The display label for the counter.
|
129 |
+
*/
|
130 |
+
count(label?: string): void;
|
131 |
+
/**
|
132 |
+
* Resets the internal counter specific to `label`.
|
133 |
+
*
|
134 |
+
* ```js
|
135 |
+
* > console.count('abc');
|
136 |
+
* abc: 1
|
137 |
+
* undefined
|
138 |
+
* > console.countReset('abc');
|
139 |
+
* undefined
|
140 |
+
* > console.count('abc');
|
141 |
+
* abc: 1
|
142 |
+
* undefined
|
143 |
+
* >
|
144 |
+
* ```
|
145 |
+
* @since v8.3.0
|
146 |
+
* @param [label='default'] The display label for the counter.
|
147 |
+
*/
|
148 |
+
countReset(label?: string): void;
|
149 |
+
/**
|
150 |
+
* The `console.debug()` function is an alias for {@link log}.
|
151 |
+
* @since v8.0.0
|
152 |
+
*/
|
153 |
+
debug(message?: any, ...optionalParams: any[]): void;
|
154 |
+
/**
|
155 |
+
* Uses [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) on `obj` and prints the resulting string to `stdout`.
|
156 |
+
* This function bypasses any custom `inspect()` function defined on `obj`.
|
157 |
+
* @since v0.1.101
|
158 |
+
*/
|
159 |
+
dir(obj: any, options?: InspectOptions): void;
|
160 |
+
/**
|
161 |
+
* This method calls `console.log()` passing it the arguments received.
|
162 |
+
* This method does not produce any XML formatting.
|
163 |
+
* @since v8.0.0
|
164 |
+
*/
|
165 |
+
dirxml(...data: any[]): void;
|
166 |
+
/**
|
167 |
+
* Prints to `stderr` with newline. Multiple arguments can be passed, with the
|
168 |
+
* first used as the primary message and all additional used as substitution
|
169 |
+
* values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
|
170 |
+
* (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)).
|
171 |
+
*
|
172 |
+
* ```js
|
173 |
+
* const code = 5;
|
174 |
+
* console.error('error #%d', code);
|
175 |
+
* // Prints: error #5, to stderr
|
176 |
+
* console.error('error', code);
|
177 |
+
* // Prints: error 5, to stderr
|
178 |
+
* ```
|
179 |
+
*
|
180 |
+
* If formatting elements (e.g. `%d`) are not found in the first string then
|
181 |
+
* [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options) is called on each argument and the
|
182 |
+
* resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)
|
183 |
+
* for more information.
|
184 |
+
* @since v0.1.100
|
185 |
+
*/
|
186 |
+
error(message?: any, ...optionalParams: any[]): void;
|
187 |
+
/**
|
188 |
+
* Increases indentation of subsequent lines by spaces for `groupIndentation` length.
|
189 |
+
*
|
190 |
+
* If one or more `label`s are provided, those are printed first without the
|
191 |
+
* additional indentation.
|
192 |
+
* @since v8.5.0
|
193 |
+
*/
|
194 |
+
group(...label: any[]): void;
|
195 |
+
/**
|
196 |
+
* An alias for {@link group}.
|
197 |
+
* @since v8.5.0
|
198 |
+
*/
|
199 |
+
groupCollapsed(...label: any[]): void;
|
200 |
+
/**
|
201 |
+
* Decreases indentation of subsequent lines by spaces for `groupIndentation` length.
|
202 |
+
* @since v8.5.0
|
203 |
+
*/
|
204 |
+
groupEnd(): void;
|
205 |
+
/**
|
206 |
+
* The `console.info()` function is an alias for {@link log}.
|
207 |
+
* @since v0.1.100
|
208 |
+
*/
|
209 |
+
info(message?: any, ...optionalParams: any[]): void;
|
210 |
+
/**
|
211 |
+
* Prints to `stdout` with newline. Multiple arguments can be passed, with the
|
212 |
+
* first used as the primary message and all additional used as substitution
|
213 |
+
* values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
|
214 |
+
* (the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)).
|
215 |
+
*
|
216 |
+
* ```js
|
217 |
+
* const count = 5;
|
218 |
+
* console.log('count: %d', count);
|
219 |
+
* // Prints: count: 5, to stdout
|
220 |
+
* console.log('count:', count);
|
221 |
+
* // Prints: count: 5, to stdout
|
222 |
+
* ```
|
223 |
+
*
|
224 |
+
* See [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args) for more information.
|
225 |
+
* @since v0.1.100
|
226 |
+
*/
|
227 |
+
log(message?: any, ...optionalParams: any[]): void;
|
228 |
+
/**
|
229 |
+
* Try to construct a table with the columns of the properties of `tabularData` (or use `properties`) and rows of `tabularData` and log it. Falls back to just
|
230 |
+
* logging the argument if it can't be parsed as tabular.
|
231 |
+
*
|
232 |
+
* ```js
|
233 |
+
* // These can't be parsed as tabular data
|
234 |
+
* console.table(Symbol());
|
235 |
+
* // Symbol()
|
236 |
+
*
|
237 |
+
* console.table(undefined);
|
238 |
+
* // undefined
|
239 |
+
*
|
240 |
+
* console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }]);
|
241 |
+
* // ┌─────────┬─────┬─────┐
|
242 |
+
* // │ (index) │ a │ b │
|
243 |
+
* // ├─────────┼─────┼─────┤
|
244 |
+
* // │ 0 │ 1 │ 'Y' │
|
245 |
+
* // │ 1 │ 'Z' │ 2 │
|
246 |
+
* // └─────────┴─────┴─────┘
|
247 |
+
*
|
248 |
+
* console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ['a']);
|
249 |
+
* // ┌─────────┬─────┐
|
250 |
+
* // │ (index) │ a │
|
251 |
+
* // ├─────────┼─────┤
|
252 |
+
* // │ 0 │ 1 │
|
253 |
+
* // │ 1 │ 'Z' │
|
254 |
+
* // └─────────┴─────┘
|
255 |
+
* ```
|
256 |
+
* @since v10.0.0
|
257 |
+
* @param properties Alternate properties for constructing the table.
|
258 |
+
*/
|
259 |
+
table(tabularData: any, properties?: readonly string[]): void;
|
260 |
+
/**
|
261 |
+
* Starts a timer that can be used to compute the duration of an operation. Timers
|
262 |
+
* are identified by a unique `label`. Use the same `label` when calling {@link timeEnd} to stop the timer and output the elapsed time in
|
263 |
+
* suitable time units to `stdout`. For example, if the elapsed
|
264 |
+
* time is 3869ms, `console.timeEnd()` displays "3.869s".
|
265 |
+
* @since v0.1.104
|
266 |
+
* @param [label='default']
|
267 |
+
*/
|
268 |
+
time(label?: string): void;
|
269 |
+
/**
|
270 |
+
* Stops a timer that was previously started by calling {@link time} and
|
271 |
+
* prints the result to `stdout`:
|
272 |
+
*
|
273 |
+
* ```js
|
274 |
+
* console.time('bunch-of-stuff');
|
275 |
+
* // Do a bunch of stuff.
|
276 |
+
* console.timeEnd('bunch-of-stuff');
|
277 |
+
* // Prints: bunch-of-stuff: 225.438ms
|
278 |
+
* ```
|
279 |
+
* @since v0.1.104
|
280 |
+
* @param [label='default']
|
281 |
+
*/
|
282 |
+
timeEnd(label?: string): void;
|
283 |
+
/**
|
284 |
+
* For a timer that was previously started by calling {@link time}, prints
|
285 |
+
* the elapsed time and other `data` arguments to `stdout`:
|
286 |
+
*
|
287 |
+
* ```js
|
288 |
+
* console.time('process');
|
289 |
+
* const value = expensiveProcess1(); // Returns 42
|
290 |
+
* console.timeLog('process', value);
|
291 |
+
* // Prints "process: 365.227ms 42".
|
292 |
+
* doExpensiveProcess2(value);
|
293 |
+
* console.timeEnd('process');
|
294 |
+
* ```
|
295 |
+
* @since v10.7.0
|
296 |
+
* @param [label='default']
|
297 |
+
*/
|
298 |
+
timeLog(label?: string, ...data: any[]): void;
|
299 |
+
/**
|
300 |
+
* Prints to `stderr` the string `'Trace: '`, followed by the [`util.format()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilformatformat-args)
|
301 |
+
* formatted message and stack trace to the current position in the code.
|
302 |
+
*
|
303 |
+
* ```js
|
304 |
+
* console.trace('Show me');
|
305 |
+
* // Prints: (stack trace will vary based on where trace is called)
|
306 |
+
* // Trace: Show me
|
307 |
+
* // at repl:2:9
|
308 |
+
* // at REPLServer.defaultEval (repl.js:248:27)
|
309 |
+
* // at bound (domain.js:287:14)
|
310 |
+
* // at REPLServer.runBound [as eval] (domain.js:300:12)
|
311 |
+
* // at REPLServer.<anonymous> (repl.js:412:12)
|
312 |
+
* // at emitOne (events.js:82:20)
|
313 |
+
* // at REPLServer.emit (events.js:169:7)
|
314 |
+
* // at REPLServer.Interface._onLine (readline.js:210:10)
|
315 |
+
* // at REPLServer.Interface._line (readline.js:549:8)
|
316 |
+
* // at REPLServer.Interface._ttyWrite (readline.js:826:14)
|
317 |
+
* ```
|
318 |
+
* @since v0.1.104
|
319 |
+
*/
|
320 |
+
trace(message?: any, ...optionalParams: any[]): void;
|
321 |
+
/**
|
322 |
+
* The `console.warn()` function is an alias for {@link error}.
|
323 |
+
* @since v0.1.100
|
324 |
+
*/
|
325 |
+
warn(message?: any, ...optionalParams: any[]): void;
|
326 |
+
// --- Inspector mode only ---
|
327 |
+
/**
|
328 |
+
* This method does not display anything unless used in the inspector. The `console.profile()`
|
329 |
+
* method starts a JavaScript CPU profile with an optional label until {@link profileEnd}
|
330 |
+
* is called. The profile is then added to the Profile panel of the inspector.
|
331 |
+
*
|
332 |
+
* ```js
|
333 |
+
* console.profile('MyLabel');
|
334 |
+
* // Some code
|
335 |
+
* console.profileEnd('MyLabel');
|
336 |
+
* // Adds the profile 'MyLabel' to the Profiles panel of the inspector.
|
337 |
+
* ```
|
338 |
+
* @since v8.0.0
|
339 |
+
*/
|
340 |
+
profile(label?: string): void;
|
341 |
+
/**
|
342 |
+
* This method does not display anything unless used in the inspector. Stops the current
|
343 |
+
* JavaScript CPU profiling session if one has been started and prints the report to the
|
344 |
+
* Profiles panel of the inspector. See {@link profile} for an example.
|
345 |
+
*
|
346 |
+
* If this method is called without a label, the most recently started profile is stopped.
|
347 |
+
* @since v8.0.0
|
348 |
+
*/
|
349 |
+
profileEnd(label?: string): void;
|
350 |
+
/**
|
351 |
+
* This method does not display anything unless used in the inspector. The `console.timeStamp()`
|
352 |
+
* method adds an event with the label `'label'` to the Timeline panel of the inspector.
|
353 |
+
* @since v8.0.0
|
354 |
+
*/
|
355 |
+
timeStamp(label?: string): void;
|
356 |
+
}
|
357 |
+
/**
|
358 |
+
* The `console` module provides a simple debugging console that is similar to the
|
359 |
+
* JavaScript console mechanism provided by web browsers.
|
360 |
+
*
|
361 |
+
* The module exports two specific components:
|
362 |
+
*
|
363 |
+
* * A `Console` class with methods such as `console.log()`, `console.error()` and `console.warn()` that can be used to write to any Node.js stream.
|
364 |
+
* * A global `console` instance configured to write to [`process.stdout`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstdout) and
|
365 |
+
* [`process.stderr`](https://nodejs.org/docs/latest-v22.x/api/process.html#processstderr). The global `console` can be used without importing the `node:console` module.
|
366 |
+
*
|
367 |
+
* _**Warning**_: The global console object's methods are neither consistently
|
368 |
+
* synchronous like the browser APIs they resemble, nor are they consistently
|
369 |
+
* asynchronous like all other Node.js streams. See the [`note on process I/O`](https://nodejs.org/docs/latest-v22.x/api/process.html#a-note-on-process-io) for
|
370 |
+
* more information.
|
371 |
+
*
|
372 |
+
* Example using the global `console`:
|
373 |
+
*
|
374 |
+
* ```js
|
375 |
+
* console.log('hello world');
|
376 |
+
* // Prints: hello world, to stdout
|
377 |
+
* console.log('hello %s', 'world');
|
378 |
+
* // Prints: hello world, to stdout
|
379 |
+
* console.error(new Error('Whoops, something bad happened'));
|
380 |
+
* // Prints error message and stack trace to stderr:
|
381 |
+
* // Error: Whoops, something bad happened
|
382 |
+
* // at [eval]:5:15
|
383 |
+
* // at Script.runInThisContext (node:vm:132:18)
|
384 |
+
* // at Object.runInThisContext (node:vm:309:38)
|
385 |
+
* // at node:internal/process/execution:77:19
|
386 |
+
* // at [eval]-wrapper:6:22
|
387 |
+
* // at evalScript (node:internal/process/execution:76:60)
|
388 |
+
* // at node:internal/main/eval_string:23:3
|
389 |
+
*
|
390 |
+
* const name = 'Will Robinson';
|
391 |
+
* console.warn(`Danger ${name}! Danger!`);
|
392 |
+
* // Prints: Danger Will Robinson! Danger!, to stderr
|
393 |
+
* ```
|
394 |
+
*
|
395 |
+
* Example using the `Console` class:
|
396 |
+
*
|
397 |
+
* ```js
|
398 |
+
* const out = getStreamSomehow();
|
399 |
+
* const err = getStreamSomehow();
|
400 |
+
* const myConsole = new console.Console(out, err);
|
401 |
+
*
|
402 |
+
* myConsole.log('hello world');
|
403 |
+
* // Prints: hello world, to out
|
404 |
+
* myConsole.log('hello %s', 'world');
|
405 |
+
* // Prints: hello world, to out
|
406 |
+
* myConsole.error(new Error('Whoops, something bad happened'));
|
407 |
+
* // Prints: [Error: Whoops, something bad happened], to err
|
408 |
+
*
|
409 |
+
* const name = 'Will Robinson';
|
410 |
+
* myConsole.warn(`Danger ${name}! Danger!`);
|
411 |
+
* // Prints: Danger Will Robinson! Danger!, to err
|
412 |
+
* ```
|
413 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/console.js)
|
414 |
+
*/
|
415 |
+
namespace console {
|
416 |
+
interface ConsoleConstructorOptions {
|
417 |
+
stdout: NodeJS.WritableStream;
|
418 |
+
stderr?: NodeJS.WritableStream | undefined;
|
419 |
+
/**
|
420 |
+
* Ignore errors when writing to the underlying streams.
|
421 |
+
* @default true
|
422 |
+
*/
|
423 |
+
ignoreErrors?: boolean | undefined;
|
424 |
+
/**
|
425 |
+
* Set color support for this `Console` instance. Setting to true enables coloring while inspecting
|
426 |
+
* values. Setting to `false` disables coloring while inspecting values. Setting to `'auto'` makes color
|
427 |
+
* support depend on the value of the `isTTY` property and the value returned by `getColorDepth()` on the
|
428 |
+
* respective stream. This option can not be used, if `inspectOptions.colors` is set as well.
|
429 |
+
* @default auto
|
430 |
+
*/
|
431 |
+
colorMode?: boolean | "auto" | undefined;
|
432 |
+
/**
|
433 |
+
* Specifies options that are passed along to
|
434 |
+
* [`util.inspect()`](https://nodejs.org/docs/latest-v22.x/api/util.html#utilinspectobject-options).
|
435 |
+
*/
|
436 |
+
inspectOptions?: InspectOptions | undefined;
|
437 |
+
/**
|
438 |
+
* Set group indentation.
|
439 |
+
* @default 2
|
440 |
+
*/
|
441 |
+
groupIndentation?: number | undefined;
|
442 |
+
}
|
443 |
+
interface ConsoleConstructor {
|
444 |
+
prototype: Console;
|
445 |
+
new(stdout: NodeJS.WritableStream, stderr?: NodeJS.WritableStream, ignoreErrors?: boolean): Console;
|
446 |
+
new(options: ConsoleConstructorOptions): Console;
|
447 |
+
}
|
448 |
+
}
|
449 |
+
var console: Console;
|
450 |
+
}
|
451 |
+
export = globalThis.console;
|
452 |
+
}
|
clone/node_modules/@types/node/constants.d.ts
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/** @deprecated since v6.3.0 - use constants property exposed by the relevant module instead. */
|
2 |
+
declare module "constants" {
|
3 |
+
import { constants as osConstants, SignalConstants } from "node:os";
|
4 |
+
import { constants as cryptoConstants } from "node:crypto";
|
5 |
+
import { constants as fsConstants } from "node:fs";
|
6 |
+
|
7 |
+
const exp:
|
8 |
+
& typeof osConstants.errno
|
9 |
+
& typeof osConstants.priority
|
10 |
+
& SignalConstants
|
11 |
+
& typeof cryptoConstants
|
12 |
+
& typeof fsConstants;
|
13 |
+
export = exp;
|
14 |
+
}
|
15 |
+
|
16 |
+
declare module "node:constants" {
|
17 |
+
import constants = require("constants");
|
18 |
+
export = constants;
|
19 |
+
}
|
clone/node_modules/@types/node/crypto.d.ts
ADDED
The diff for this file is too large to render.
See raw diff
|
|
clone/node_modules/@types/node/dgram.d.ts
ADDED
@@ -0,0 +1,596 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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6 |
+
*
|
7 |
+
* const server = dgram.createSocket('udp4');
|
8 |
+
*
|
9 |
+
* server.on('error', (err) => {
|
10 |
+
* console.error(`server error:\n${err.stack}`);
|
11 |
+
* server.close();
|
12 |
+
* });
|
13 |
+
*
|
14 |
+
* server.on('message', (msg, rinfo) => {
|
15 |
+
* console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
|
16 |
+
* });
|
17 |
+
*
|
18 |
+
* server.on('listening', () => {
|
19 |
+
* const address = server.address();
|
20 |
+
* console.log(`server listening ${address.address}:${address.port}`);
|
21 |
+
* });
|
22 |
+
*
|
23 |
+
* server.bind(41234);
|
24 |
+
* // Prints: server listening 0.0.0.0:41234
|
25 |
+
* ```
|
26 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/dgram.js)
|
27 |
+
*/
|
28 |
+
declare module "dgram" {
|
29 |
+
import { AddressInfo } from "node:net";
|
30 |
+
import * as dns from "node:dns";
|
31 |
+
import { Abortable, EventEmitter } from "node:events";
|
32 |
+
interface RemoteInfo {
|
33 |
+
address: string;
|
34 |
+
family: "IPv4" | "IPv6";
|
35 |
+
port: number;
|
36 |
+
size: number;
|
37 |
+
}
|
38 |
+
interface BindOptions {
|
39 |
+
port?: number | undefined;
|
40 |
+
address?: string | undefined;
|
41 |
+
exclusive?: boolean | undefined;
|
42 |
+
fd?: number | undefined;
|
43 |
+
}
|
44 |
+
type SocketType = "udp4" | "udp6";
|
45 |
+
interface SocketOptions extends Abortable {
|
46 |
+
type: SocketType;
|
47 |
+
reuseAddr?: boolean | undefined;
|
48 |
+
/**
|
49 |
+
* @default false
|
50 |
+
*/
|
51 |
+
ipv6Only?: boolean | undefined;
|
52 |
+
recvBufferSize?: number | undefined;
|
53 |
+
sendBufferSize?: number | undefined;
|
54 |
+
lookup?:
|
55 |
+
| ((
|
56 |
+
hostname: string,
|
57 |
+
options: dns.LookupOneOptions,
|
58 |
+
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
59 |
+
) => void)
|
60 |
+
| undefined;
|
61 |
+
}
|
62 |
+
/**
|
63 |
+
* Creates a `dgram.Socket` object. Once the socket is created, calling `socket.bind()` will instruct the socket to begin listening for datagram
|
64 |
+
* messages. When `address` and `port` are not passed to `socket.bind()` the
|
65 |
+
* method will bind the socket to the "all interfaces" address on a random port
|
66 |
+
* (it does the right thing for both `udp4` and `udp6` sockets). The bound address
|
67 |
+
* and port can be retrieved using `socket.address().address` and `socket.address().port`.
|
68 |
+
*
|
69 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.close()` on the socket:
|
70 |
+
*
|
71 |
+
* ```js
|
72 |
+
* const controller = new AbortController();
|
73 |
+
* const { signal } = controller;
|
74 |
+
* const server = dgram.createSocket({ type: 'udp4', signal });
|
75 |
+
* server.on('message', (msg, rinfo) => {
|
76 |
+
* console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
|
77 |
+
* });
|
78 |
+
* // Later, when you want to close the server.
|
79 |
+
* controller.abort();
|
80 |
+
* ```
|
81 |
+
* @since v0.11.13
|
82 |
+
* @param options Available options are:
|
83 |
+
* @param callback Attached as a listener for `'message'` events. Optional.
|
84 |
+
*/
|
85 |
+
function createSocket(type: SocketType, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket;
|
86 |
+
function createSocket(options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket;
|
87 |
+
/**
|
88 |
+
* Encapsulates the datagram functionality.
|
89 |
+
*
|
90 |
+
* New instances of `dgram.Socket` are created using {@link createSocket}.
|
91 |
+
* The `new` keyword is not to be used to create `dgram.Socket` instances.
|
92 |
+
* @since v0.1.99
|
93 |
+
*/
|
94 |
+
class Socket extends EventEmitter {
|
95 |
+
/**
|
96 |
+
* Tells the kernel to join a multicast group at the given `multicastAddress` and `multicastInterface` using the `IP_ADD_MEMBERSHIP` socket option. If the `multicastInterface` argument is not
|
97 |
+
* specified, the operating system will choose
|
98 |
+
* one interface and will add membership to it. To add membership to every
|
99 |
+
* available interface, call `addMembership` multiple times, once per interface.
|
100 |
+
*
|
101 |
+
* When called on an unbound socket, this method will implicitly bind to a random
|
102 |
+
* port, listening on all interfaces.
|
103 |
+
*
|
104 |
+
* When sharing a UDP socket across multiple `cluster` workers, the`socket.addMembership()` function must be called only once or an`EADDRINUSE` error will occur:
|
105 |
+
*
|
106 |
+
* ```js
|
107 |
+
* import cluster from 'node:cluster';
|
108 |
+
* import dgram from 'node:dgram';
|
109 |
+
*
|
110 |
+
* if (cluster.isPrimary) {
|
111 |
+
* cluster.fork(); // Works ok.
|
112 |
+
* cluster.fork(); // Fails with EADDRINUSE.
|
113 |
+
* } else {
|
114 |
+
* const s = dgram.createSocket('udp4');
|
115 |
+
* s.bind(1234, () => {
|
116 |
+
* s.addMembership('224.0.0.114');
|
117 |
+
* });
|
118 |
+
* }
|
119 |
+
* ```
|
120 |
+
* @since v0.6.9
|
121 |
+
*/
|
122 |
+
addMembership(multicastAddress: string, multicastInterface?: string): void;
|
123 |
+
/**
|
124 |
+
* Returns an object containing the address information for a socket.
|
125 |
+
* For UDP sockets, this object will contain `address`, `family`, and `port` properties.
|
126 |
+
*
|
127 |
+
* This method throws `EBADF` if called on an unbound socket.
|
128 |
+
* @since v0.1.99
|
129 |
+
*/
|
130 |
+
address(): AddressInfo;
|
131 |
+
/**
|
132 |
+
* For UDP sockets, causes the `dgram.Socket` to listen for datagram
|
133 |
+
* messages on a named `port` and optional `address`. If `port` is not
|
134 |
+
* specified or is `0`, the operating system will attempt to bind to a
|
135 |
+
* random port. If `address` is not specified, the operating system will
|
136 |
+
* attempt to listen on all addresses. Once binding is complete, a `'listening'` event is emitted and the optional `callback` function is
|
137 |
+
* called.
|
138 |
+
*
|
139 |
+
* Specifying both a `'listening'` event listener and passing a `callback` to the `socket.bind()` method is not harmful but not very
|
140 |
+
* useful.
|
141 |
+
*
|
142 |
+
* A bound datagram socket keeps the Node.js process running to receive
|
143 |
+
* datagram messages.
|
144 |
+
*
|
145 |
+
* If binding fails, an `'error'` event is generated. In rare case (e.g.
|
146 |
+
* attempting to bind with a closed socket), an `Error` may be thrown.
|
147 |
+
*
|
148 |
+
* Example of a UDP server listening on port 41234:
|
149 |
+
*
|
150 |
+
* ```js
|
151 |
+
* import dgram from 'node:dgram';
|
152 |
+
*
|
153 |
+
* const server = dgram.createSocket('udp4');
|
154 |
+
*
|
155 |
+
* server.on('error', (err) => {
|
156 |
+
* console.error(`server error:\n${err.stack}`);
|
157 |
+
* server.close();
|
158 |
+
* });
|
159 |
+
*
|
160 |
+
* server.on('message', (msg, rinfo) => {
|
161 |
+
* console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
|
162 |
+
* });
|
163 |
+
*
|
164 |
+
* server.on('listening', () => {
|
165 |
+
* const address = server.address();
|
166 |
+
* console.log(`server listening ${address.address}:${address.port}`);
|
167 |
+
* });
|
168 |
+
*
|
169 |
+
* server.bind(41234);
|
170 |
+
* // Prints: server listening 0.0.0.0:41234
|
171 |
+
* ```
|
172 |
+
* @since v0.1.99
|
173 |
+
* @param callback with no parameters. Called when binding is complete.
|
174 |
+
*/
|
175 |
+
bind(port?: number, address?: string, callback?: () => void): this;
|
176 |
+
bind(port?: number, callback?: () => void): this;
|
177 |
+
bind(callback?: () => void): this;
|
178 |
+
bind(options: BindOptions, callback?: () => void): this;
|
179 |
+
/**
|
180 |
+
* Close the underlying socket and stop listening for data on it. If a callback is
|
181 |
+
* provided, it is added as a listener for the `'close'` event.
|
182 |
+
* @since v0.1.99
|
183 |
+
* @param callback Called when the socket has been closed.
|
184 |
+
*/
|
185 |
+
close(callback?: () => void): this;
|
186 |
+
/**
|
187 |
+
* Associates the `dgram.Socket` to a remote address and port. Every
|
188 |
+
* message sent by this handle is automatically sent to that destination. Also,
|
189 |
+
* the socket will only receive messages from that remote peer.
|
190 |
+
* Trying to call `connect()` on an already connected socket will result
|
191 |
+
* in an `ERR_SOCKET_DGRAM_IS_CONNECTED` exception. If `address` is not
|
192 |
+
* provided, `'127.0.0.1'` (for `udp4` sockets) or `'::1'` (for `udp6` sockets)
|
193 |
+
* will be used by default. Once the connection is complete, a `'connect'` event
|
194 |
+
* is emitted and the optional `callback` function is called. In case of failure,
|
195 |
+
* the `callback` is called or, failing this, an `'error'` event is emitted.
|
196 |
+
* @since v12.0.0
|
197 |
+
* @param callback Called when the connection is completed or on error.
|
198 |
+
*/
|
199 |
+
connect(port: number, address?: string, callback?: () => void): void;
|
200 |
+
connect(port: number, callback: () => void): void;
|
201 |
+
/**
|
202 |
+
* A synchronous function that disassociates a connected `dgram.Socket` from
|
203 |
+
* its remote address. Trying to call `disconnect()` on an unbound or already
|
204 |
+
* disconnected socket will result in an `ERR_SOCKET_DGRAM_NOT_CONNECTED` exception.
|
205 |
+
* @since v12.0.0
|
206 |
+
*/
|
207 |
+
disconnect(): void;
|
208 |
+
/**
|
209 |
+
* Instructs the kernel to leave a multicast group at `multicastAddress` using the `IP_DROP_MEMBERSHIP` socket option. This method is automatically called by the
|
210 |
+
* kernel when the socket is closed or the process terminates, so most apps will
|
211 |
+
* never have reason to call this.
|
212 |
+
*
|
213 |
+
* If `multicastInterface` is not specified, the operating system will attempt to
|
214 |
+
* drop membership on all valid interfaces.
|
215 |
+
* @since v0.6.9
|
216 |
+
*/
|
217 |
+
dropMembership(multicastAddress: string, multicastInterface?: string): void;
|
218 |
+
/**
|
219 |
+
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket.
|
220 |
+
* @since v8.7.0
|
221 |
+
* @return the `SO_RCVBUF` socket receive buffer size in bytes.
|
222 |
+
*/
|
223 |
+
getRecvBufferSize(): number;
|
224 |
+
/**
|
225 |
+
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket.
|
226 |
+
* @since v8.7.0
|
227 |
+
* @return the `SO_SNDBUF` socket send buffer size in bytes.
|
228 |
+
*/
|
229 |
+
getSendBufferSize(): number;
|
230 |
+
/**
|
231 |
+
* @since v18.8.0, v16.19.0
|
232 |
+
* @return Number of bytes queued for sending.
|
233 |
+
*/
|
234 |
+
getSendQueueSize(): number;
|
235 |
+
/**
|
236 |
+
* @since v18.8.0, v16.19.0
|
237 |
+
* @return Number of send requests currently in the queue awaiting to be processed.
|
238 |
+
*/
|
239 |
+
getSendQueueCount(): number;
|
240 |
+
/**
|
241 |
+
* By default, binding a socket will cause it to block the Node.js process from
|
242 |
+
* exiting as long as the socket is open. The `socket.unref()` method can be used
|
243 |
+
* to exclude the socket from the reference counting that keeps the Node.js
|
244 |
+
* process active. The `socket.ref()` method adds the socket back to the reference
|
245 |
+
* counting and restores the default behavior.
|
246 |
+
*
|
247 |
+
* Calling `socket.ref()` multiples times will have no additional effect.
|
248 |
+
*
|
249 |
+
* The `socket.ref()` method returns a reference to the socket so calls can be
|
250 |
+
* chained.
|
251 |
+
* @since v0.9.1
|
252 |
+
*/
|
253 |
+
ref(): this;
|
254 |
+
/**
|
255 |
+
* Returns an object containing the `address`, `family`, and `port` of the remote
|
256 |
+
* endpoint. This method throws an `ERR_SOCKET_DGRAM_NOT_CONNECTED` exception
|
257 |
+
* if the socket is not connected.
|
258 |
+
* @since v12.0.0
|
259 |
+
*/
|
260 |
+
remoteAddress(): AddressInfo;
|
261 |
+
/**
|
262 |
+
* Broadcasts a datagram on the socket.
|
263 |
+
* For connectionless sockets, the destination `port` and `address` must be
|
264 |
+
* specified. Connected sockets, on the other hand, will use their associated
|
265 |
+
* remote endpoint, so the `port` and `address` arguments must not be set.
|
266 |
+
*
|
267 |
+
* The `msg` argument contains the message to be sent.
|
268 |
+
* Depending on its type, different behavior can apply. If `msg` is a `Buffer`,
|
269 |
+
* any `TypedArray` or a `DataView`,
|
270 |
+
* the `offset` and `length` specify the offset within the `Buffer` where the
|
271 |
+
* message begins and the number of bytes in the message, respectively.
|
272 |
+
* If `msg` is a `String`, then it is automatically converted to a `Buffer` with `'utf8'` encoding. With messages that
|
273 |
+
* contain multi-byte characters, `offset` and `length` will be calculated with
|
274 |
+
* respect to `byte length` and not the character position.
|
275 |
+
* If `msg` is an array, `offset` and `length` must not be specified.
|
276 |
+
*
|
277 |
+
* The `address` argument is a string. If the value of `address` is a host name,
|
278 |
+
* DNS will be used to resolve the address of the host. If `address` is not
|
279 |
+
* provided or otherwise nullish, `'127.0.0.1'` (for `udp4` sockets) or `'::1'` (for `udp6` sockets) will be used by default.
|
280 |
+
*
|
281 |
+
* If the socket has not been previously bound with a call to `bind`, the socket
|
282 |
+
* is assigned a random port number and is bound to the "all interfaces" address
|
283 |
+
* (`'0.0.0.0'` for `udp4` sockets, `'::0'` for `udp6` sockets.)
|
284 |
+
*
|
285 |
+
* An optional `callback` function may be specified to as a way of reporting
|
286 |
+
* DNS errors or for determining when it is safe to reuse the `buf` object.
|
287 |
+
* DNS lookups delay the time to send for at least one tick of the
|
288 |
+
* Node.js event loop.
|
289 |
+
*
|
290 |
+
* The only way to know for sure that the datagram has been sent is by using a `callback`. If an error occurs and a `callback` is given, the error will be
|
291 |
+
* passed as the first argument to the `callback`. If a `callback` is not given,
|
292 |
+
* the error is emitted as an `'error'` event on the `socket` object.
|
293 |
+
*
|
294 |
+
* Offset and length are optional but both _must_ be set if either are used.
|
295 |
+
* They are supported only when the first argument is a `Buffer`, a `TypedArray`,
|
296 |
+
* or a `DataView`.
|
297 |
+
*
|
298 |
+
* This method throws `ERR_SOCKET_BAD_PORT` if called on an unbound socket.
|
299 |
+
*
|
300 |
+
* Example of sending a UDP packet to a port on `localhost`;
|
301 |
+
*
|
302 |
+
* ```js
|
303 |
+
* import dgram from 'node:dgram';
|
304 |
+
* import { Buffer } from 'node:buffer';
|
305 |
+
*
|
306 |
+
* const message = Buffer.from('Some bytes');
|
307 |
+
* const client = dgram.createSocket('udp4');
|
308 |
+
* client.send(message, 41234, 'localhost', (err) => {
|
309 |
+
* client.close();
|
310 |
+
* });
|
311 |
+
* ```
|
312 |
+
*
|
313 |
+
* Example of sending a UDP packet composed of multiple buffers to a port on`127.0.0.1`;
|
314 |
+
*
|
315 |
+
* ```js
|
316 |
+
* import dgram from 'node:dgram';
|
317 |
+
* import { Buffer } from 'node:buffer';
|
318 |
+
*
|
319 |
+
* const buf1 = Buffer.from('Some ');
|
320 |
+
* const buf2 = Buffer.from('bytes');
|
321 |
+
* const client = dgram.createSocket('udp4');
|
322 |
+
* client.send([buf1, buf2], 41234, (err) => {
|
323 |
+
* client.close();
|
324 |
+
* });
|
325 |
+
* ```
|
326 |
+
*
|
327 |
+
* Sending multiple buffers might be faster or slower depending on the
|
328 |
+
* application and operating system. Run benchmarks to
|
329 |
+
* determine the optimal strategy on a case-by-case basis. Generally speaking,
|
330 |
+
* however, sending multiple buffers is faster.
|
331 |
+
*
|
332 |
+
* Example of sending a UDP packet using a socket connected to a port on `localhost`:
|
333 |
+
*
|
334 |
+
* ```js
|
335 |
+
* import dgram from 'node:dgram';
|
336 |
+
* import { Buffer } from 'node:buffer';
|
337 |
+
*
|
338 |
+
* const message = Buffer.from('Some bytes');
|
339 |
+
* const client = dgram.createSocket('udp4');
|
340 |
+
* client.connect(41234, 'localhost', (err) => {
|
341 |
+
* client.send(message, (err) => {
|
342 |
+
* client.close();
|
343 |
+
* });
|
344 |
+
* });
|
345 |
+
* ```
|
346 |
+
* @since v0.1.99
|
347 |
+
* @param msg Message to be sent.
|
348 |
+
* @param offset Offset in the buffer where the message starts.
|
349 |
+
* @param length Number of bytes in the message.
|
350 |
+
* @param port Destination port.
|
351 |
+
* @param address Destination host name or IP address.
|
352 |
+
* @param callback Called when the message has been sent.
|
353 |
+
*/
|
354 |
+
send(
|
355 |
+
msg: string | NodeJS.ArrayBufferView | readonly any[],
|
356 |
+
port?: number,
|
357 |
+
address?: string,
|
358 |
+
callback?: (error: Error | null, bytes: number) => void,
|
359 |
+
): void;
|
360 |
+
send(
|
361 |
+
msg: string | NodeJS.ArrayBufferView | readonly any[],
|
362 |
+
port?: number,
|
363 |
+
callback?: (error: Error | null, bytes: number) => void,
|
364 |
+
): void;
|
365 |
+
send(
|
366 |
+
msg: string | NodeJS.ArrayBufferView | readonly any[],
|
367 |
+
callback?: (error: Error | null, bytes: number) => void,
|
368 |
+
): void;
|
369 |
+
send(
|
370 |
+
msg: string | NodeJS.ArrayBufferView,
|
371 |
+
offset: number,
|
372 |
+
length: number,
|
373 |
+
port?: number,
|
374 |
+
address?: string,
|
375 |
+
callback?: (error: Error | null, bytes: number) => void,
|
376 |
+
): void;
|
377 |
+
send(
|
378 |
+
msg: string | NodeJS.ArrayBufferView,
|
379 |
+
offset: number,
|
380 |
+
length: number,
|
381 |
+
port?: number,
|
382 |
+
callback?: (error: Error | null, bytes: number) => void,
|
383 |
+
): void;
|
384 |
+
send(
|
385 |
+
msg: string | NodeJS.ArrayBufferView,
|
386 |
+
offset: number,
|
387 |
+
length: number,
|
388 |
+
callback?: (error: Error | null, bytes: number) => void,
|
389 |
+
): void;
|
390 |
+
/**
|
391 |
+
* Sets or clears the `SO_BROADCAST` socket option. When set to `true`, UDP
|
392 |
+
* packets may be sent to a local interface's broadcast address.
|
393 |
+
*
|
394 |
+
* This method throws `EBADF` if called on an unbound socket.
|
395 |
+
* @since v0.6.9
|
396 |
+
*/
|
397 |
+
setBroadcast(flag: boolean): void;
|
398 |
+
/**
|
399 |
+
* _All references to scope in this section are referring to [IPv6 Zone Indices](https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses), which are defined by [RFC
|
400 |
+
* 4007](https://tools.ietf.org/html/rfc4007). In string form, an IP_
|
401 |
+
* _with a scope index is written as `'IP%scope'` where scope is an interface name_
|
402 |
+
* _or interface number._
|
403 |
+
*
|
404 |
+
* Sets the default outgoing multicast interface of the socket to a chosen
|
405 |
+
* interface or back to system interface selection. The `multicastInterface` must
|
406 |
+
* be a valid string representation of an IP from the socket's family.
|
407 |
+
*
|
408 |
+
* For IPv4 sockets, this should be the IP configured for the desired physical
|
409 |
+
* interface. All packets sent to multicast on the socket will be sent on the
|
410 |
+
* interface determined by the most recent successful use of this call.
|
411 |
+
*
|
412 |
+
* For IPv6 sockets, `multicastInterface` should include a scope to indicate the
|
413 |
+
* interface as in the examples that follow. In IPv6, individual `send` calls can
|
414 |
+
* also use explicit scope in addresses, so only packets sent to a multicast
|
415 |
+
* address without specifying an explicit scope are affected by the most recent
|
416 |
+
* successful use of this call.
|
417 |
+
*
|
418 |
+
* This method throws `EBADF` if called on an unbound socket.
|
419 |
+
*
|
420 |
+
* #### Example: IPv6 outgoing multicast interface
|
421 |
+
*
|
422 |
+
* On most systems, where scope format uses the interface name:
|
423 |
+
*
|
424 |
+
* ```js
|
425 |
+
* const socket = dgram.createSocket('udp6');
|
426 |
+
*
|
427 |
+
* socket.bind(1234, () => {
|
428 |
+
* socket.setMulticastInterface('::%eth1');
|
429 |
+
* });
|
430 |
+
* ```
|
431 |
+
*
|
432 |
+
* On Windows, where scope format uses an interface number:
|
433 |
+
*
|
434 |
+
* ```js
|
435 |
+
* const socket = dgram.createSocket('udp6');
|
436 |
+
*
|
437 |
+
* socket.bind(1234, () => {
|
438 |
+
* socket.setMulticastInterface('::%2');
|
439 |
+
* });
|
440 |
+
* ```
|
441 |
+
*
|
442 |
+
* #### Example: IPv4 outgoing multicast interface
|
443 |
+
*
|
444 |
+
* All systems use an IP of the host on the desired physical interface:
|
445 |
+
*
|
446 |
+
* ```js
|
447 |
+
* const socket = dgram.createSocket('udp4');
|
448 |
+
*
|
449 |
+
* socket.bind(1234, () => {
|
450 |
+
* socket.setMulticastInterface('10.0.0.2');
|
451 |
+
* });
|
452 |
+
* ```
|
453 |
+
* @since v8.6.0
|
454 |
+
*/
|
455 |
+
setMulticastInterface(multicastInterface: string): void;
|
456 |
+
/**
|
457 |
+
* Sets or clears the `IP_MULTICAST_LOOP` socket option. When set to `true`,
|
458 |
+
* multicast packets will also be received on the local interface.
|
459 |
+
*
|
460 |
+
* This method throws `EBADF` if called on an unbound socket.
|
461 |
+
* @since v0.3.8
|
462 |
+
*/
|
463 |
+
setMulticastLoopback(flag: boolean): boolean;
|
464 |
+
/**
|
465 |
+
* Sets the `IP_MULTICAST_TTL` socket option. While TTL generally stands for
|
466 |
+
* "Time to Live", in this context it specifies the number of IP hops that a
|
467 |
+
* packet is allowed to travel through, specifically for multicast traffic. Each
|
468 |
+
* router or gateway that forwards a packet decrements the TTL. If the TTL is
|
469 |
+
* decremented to 0 by a router, it will not be forwarded.
|
470 |
+
*
|
471 |
+
* The `ttl` argument may be between 0 and 255\. The default on most systems is `1`.
|
472 |
+
*
|
473 |
+
* This method throws `EBADF` if called on an unbound socket.
|
474 |
+
* @since v0.3.8
|
475 |
+
*/
|
476 |
+
setMulticastTTL(ttl: number): number;
|
477 |
+
/**
|
478 |
+
* Sets the `SO_RCVBUF` socket option. Sets the maximum socket receive buffer
|
479 |
+
* in bytes.
|
480 |
+
*
|
481 |
+
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket.
|
482 |
+
* @since v8.7.0
|
483 |
+
*/
|
484 |
+
setRecvBufferSize(size: number): void;
|
485 |
+
/**
|
486 |
+
* Sets the `SO_SNDBUF` socket option. Sets the maximum socket send buffer
|
487 |
+
* in bytes.
|
488 |
+
*
|
489 |
+
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket.
|
490 |
+
* @since v8.7.0
|
491 |
+
*/
|
492 |
+
setSendBufferSize(size: number): void;
|
493 |
+
/**
|
494 |
+
* Sets the `IP_TTL` socket option. While TTL generally stands for "Time to Live",
|
495 |
+
* in this context it specifies the number of IP hops that a packet is allowed to
|
496 |
+
* travel through. Each router or gateway that forwards a packet decrements the
|
497 |
+
* TTL. If the TTL is decremented to 0 by a router, it will not be forwarded.
|
498 |
+
* Changing TTL values is typically done for network probes or when multicasting.
|
499 |
+
*
|
500 |
+
* The `ttl` argument may be between 1 and 255\. The default on most systems
|
501 |
+
* is 64.
|
502 |
+
*
|
503 |
+
* This method throws `EBADF` if called on an unbound socket.
|
504 |
+
* @since v0.1.101
|
505 |
+
*/
|
506 |
+
setTTL(ttl: number): number;
|
507 |
+
/**
|
508 |
+
* By default, binding a socket will cause it to block the Node.js process from
|
509 |
+
* exiting as long as the socket is open. The `socket.unref()` method can be used
|
510 |
+
* to exclude the socket from the reference counting that keeps the Node.js
|
511 |
+
* process active, allowing the process to exit even if the socket is still
|
512 |
+
* listening.
|
513 |
+
*
|
514 |
+
* Calling `socket.unref()` multiple times will have no additional effect.
|
515 |
+
*
|
516 |
+
* The `socket.unref()` method returns a reference to the socket so calls can be
|
517 |
+
* chained.
|
518 |
+
* @since v0.9.1
|
519 |
+
*/
|
520 |
+
unref(): this;
|
521 |
+
/**
|
522 |
+
* Tells the kernel to join a source-specific multicast channel at the given `sourceAddress` and `groupAddress`, using the `multicastInterface` with the `IP_ADD_SOURCE_MEMBERSHIP` socket
|
523 |
+
* option. If the `multicastInterface` argument
|
524 |
+
* is not specified, the operating system will choose one interface and will add
|
525 |
+
* membership to it. To add membership to every available interface, call `socket.addSourceSpecificMembership()` multiple times, once per interface.
|
526 |
+
*
|
527 |
+
* When called on an unbound socket, this method will implicitly bind to a random
|
528 |
+
* port, listening on all interfaces.
|
529 |
+
* @since v13.1.0, v12.16.0
|
530 |
+
*/
|
531 |
+
addSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string): void;
|
532 |
+
/**
|
533 |
+
* Instructs the kernel to leave a source-specific multicast channel at the given `sourceAddress` and `groupAddress` using the `IP_DROP_SOURCE_MEMBERSHIP` socket option. This method is
|
534 |
+
* automatically called by the kernel when the
|
535 |
+
* socket is closed or the process terminates, so most apps will never have
|
536 |
+
* reason to call this.
|
537 |
+
*
|
538 |
+
* If `multicastInterface` is not specified, the operating system will attempt to
|
539 |
+
* drop membership on all valid interfaces.
|
540 |
+
* @since v13.1.0, v12.16.0
|
541 |
+
*/
|
542 |
+
dropSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string): void;
|
543 |
+
/**
|
544 |
+
* events.EventEmitter
|
545 |
+
* 1. close
|
546 |
+
* 2. connect
|
547 |
+
* 3. error
|
548 |
+
* 4. listening
|
549 |
+
* 5. message
|
550 |
+
*/
|
551 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
552 |
+
addListener(event: "close", listener: () => void): this;
|
553 |
+
addListener(event: "connect", listener: () => void): this;
|
554 |
+
addListener(event: "error", listener: (err: Error) => void): this;
|
555 |
+
addListener(event: "listening", listener: () => void): this;
|
556 |
+
addListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this;
|
557 |
+
emit(event: string | symbol, ...args: any[]): boolean;
|
558 |
+
emit(event: "close"): boolean;
|
559 |
+
emit(event: "connect"): boolean;
|
560 |
+
emit(event: "error", err: Error): boolean;
|
561 |
+
emit(event: "listening"): boolean;
|
562 |
+
emit(event: "message", msg: Buffer, rinfo: RemoteInfo): boolean;
|
563 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
564 |
+
on(event: "close", listener: () => void): this;
|
565 |
+
on(event: "connect", listener: () => void): this;
|
566 |
+
on(event: "error", listener: (err: Error) => void): this;
|
567 |
+
on(event: "listening", listener: () => void): this;
|
568 |
+
on(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this;
|
569 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
570 |
+
once(event: "close", listener: () => void): this;
|
571 |
+
once(event: "connect", listener: () => void): this;
|
572 |
+
once(event: "error", listener: (err: Error) => void): this;
|
573 |
+
once(event: "listening", listener: () => void): this;
|
574 |
+
once(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this;
|
575 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
576 |
+
prependListener(event: "close", listener: () => void): this;
|
577 |
+
prependListener(event: "connect", listener: () => void): this;
|
578 |
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
579 |
+
prependListener(event: "listening", listener: () => void): this;
|
580 |
+
prependListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this;
|
581 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
582 |
+
prependOnceListener(event: "close", listener: () => void): this;
|
583 |
+
prependOnceListener(event: "connect", listener: () => void): this;
|
584 |
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
585 |
+
prependOnceListener(event: "listening", listener: () => void): this;
|
586 |
+
prependOnceListener(event: "message", listener: (msg: Buffer, rinfo: RemoteInfo) => void): this;
|
587 |
+
/**
|
588 |
+
* Calls `socket.close()` and returns a promise that fulfills when the socket has closed.
|
589 |
+
* @since v20.5.0
|
590 |
+
*/
|
591 |
+
[Symbol.asyncDispose](): Promise<void>;
|
592 |
+
}
|
593 |
+
}
|
594 |
+
declare module "node:dgram" {
|
595 |
+
export * from "dgram";
|
596 |
+
}
|
clone/node_modules/@types/node/diagnostics_channel.d.ts
ADDED
@@ -0,0 +1,554 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* The `node:diagnostics_channel` module provides an API to create named channels
|
3 |
+
* to report arbitrary message data for diagnostics purposes.
|
4 |
+
*
|
5 |
+
* It can be accessed using:
|
6 |
+
*
|
7 |
+
* ```js
|
8 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
9 |
+
* ```
|
10 |
+
*
|
11 |
+
* It is intended that a module writer wanting to report diagnostics messages
|
12 |
+
* will create one or many top-level channels to report messages through.
|
13 |
+
* Channels may also be acquired at runtime but it is not encouraged
|
14 |
+
* due to the additional overhead of doing so. Channels may be exported for
|
15 |
+
* convenience, but as long as the name is known it can be acquired anywhere.
|
16 |
+
*
|
17 |
+
* If you intend for your module to produce diagnostics data for others to
|
18 |
+
* consume it is recommended that you include documentation of what named
|
19 |
+
* channels are used along with the shape of the message data. Channel names
|
20 |
+
* should generally include the module name to avoid collisions with data from
|
21 |
+
* other modules.
|
22 |
+
* @since v15.1.0, v14.17.0
|
23 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/diagnostics_channel.js)
|
24 |
+
*/
|
25 |
+
declare module "diagnostics_channel" {
|
26 |
+
import { AsyncLocalStorage } from "node:async_hooks";
|
27 |
+
/**
|
28 |
+
* Check if there are active subscribers to the named channel. This is helpful if
|
29 |
+
* the message you want to send might be expensive to prepare.
|
30 |
+
*
|
31 |
+
* This API is optional but helpful when trying to publish messages from very
|
32 |
+
* performance-sensitive code.
|
33 |
+
*
|
34 |
+
* ```js
|
35 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
36 |
+
*
|
37 |
+
* if (diagnostics_channel.hasSubscribers('my-channel')) {
|
38 |
+
* // There are subscribers, prepare and publish message
|
39 |
+
* }
|
40 |
+
* ```
|
41 |
+
* @since v15.1.0, v14.17.0
|
42 |
+
* @param name The channel name
|
43 |
+
* @return If there are active subscribers
|
44 |
+
*/
|
45 |
+
function hasSubscribers(name: string | symbol): boolean;
|
46 |
+
/**
|
47 |
+
* This is the primary entry-point for anyone wanting to publish to a named
|
48 |
+
* channel. It produces a channel object which is optimized to reduce overhead at
|
49 |
+
* publish time as much as possible.
|
50 |
+
*
|
51 |
+
* ```js
|
52 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
53 |
+
*
|
54 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
55 |
+
* ```
|
56 |
+
* @since v15.1.0, v14.17.0
|
57 |
+
* @param name The channel name
|
58 |
+
* @return The named channel object
|
59 |
+
*/
|
60 |
+
function channel(name: string | symbol): Channel;
|
61 |
+
type ChannelListener = (message: unknown, name: string | symbol) => void;
|
62 |
+
/**
|
63 |
+
* Register a message handler to subscribe to this channel. This message handler
|
64 |
+
* will be run synchronously whenever a message is published to the channel. Any
|
65 |
+
* errors thrown in the message handler will trigger an `'uncaughtException'`.
|
66 |
+
*
|
67 |
+
* ```js
|
68 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
69 |
+
*
|
70 |
+
* diagnostics_channel.subscribe('my-channel', (message, name) => {
|
71 |
+
* // Received data
|
72 |
+
* });
|
73 |
+
* ```
|
74 |
+
* @since v18.7.0, v16.17.0
|
75 |
+
* @param name The channel name
|
76 |
+
* @param onMessage The handler to receive channel messages
|
77 |
+
*/
|
78 |
+
function subscribe(name: string | symbol, onMessage: ChannelListener): void;
|
79 |
+
/**
|
80 |
+
* Remove a message handler previously registered to this channel with {@link subscribe}.
|
81 |
+
*
|
82 |
+
* ```js
|
83 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
84 |
+
*
|
85 |
+
* function onMessage(message, name) {
|
86 |
+
* // Received data
|
87 |
+
* }
|
88 |
+
*
|
89 |
+
* diagnostics_channel.subscribe('my-channel', onMessage);
|
90 |
+
*
|
91 |
+
* diagnostics_channel.unsubscribe('my-channel', onMessage);
|
92 |
+
* ```
|
93 |
+
* @since v18.7.0, v16.17.0
|
94 |
+
* @param name The channel name
|
95 |
+
* @param onMessage The previous subscribed handler to remove
|
96 |
+
* @return `true` if the handler was found, `false` otherwise.
|
97 |
+
*/
|
98 |
+
function unsubscribe(name: string | symbol, onMessage: ChannelListener): boolean;
|
99 |
+
/**
|
100 |
+
* Creates a `TracingChannel` wrapper for the given `TracingChannel Channels`. If a name is given, the corresponding tracing
|
101 |
+
* channels will be created in the form of `tracing:${name}:${eventType}` where `eventType` corresponds to the types of `TracingChannel Channels`.
|
102 |
+
*
|
103 |
+
* ```js
|
104 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
105 |
+
*
|
106 |
+
* const channelsByName = diagnostics_channel.tracingChannel('my-channel');
|
107 |
+
*
|
108 |
+
* // or...
|
109 |
+
*
|
110 |
+
* const channelsByCollection = diagnostics_channel.tracingChannel({
|
111 |
+
* start: diagnostics_channel.channel('tracing:my-channel:start'),
|
112 |
+
* end: diagnostics_channel.channel('tracing:my-channel:end'),
|
113 |
+
* asyncStart: diagnostics_channel.channel('tracing:my-channel:asyncStart'),
|
114 |
+
* asyncEnd: diagnostics_channel.channel('tracing:my-channel:asyncEnd'),
|
115 |
+
* error: diagnostics_channel.channel('tracing:my-channel:error'),
|
116 |
+
* });
|
117 |
+
* ```
|
118 |
+
* @since v19.9.0
|
119 |
+
* @experimental
|
120 |
+
* @param nameOrChannels Channel name or object containing all the `TracingChannel Channels`
|
121 |
+
* @return Collection of channels to trace with
|
122 |
+
*/
|
123 |
+
function tracingChannel<
|
124 |
+
StoreType = unknown,
|
125 |
+
ContextType extends object = StoreType extends object ? StoreType : object,
|
126 |
+
>(
|
127 |
+
nameOrChannels: string | TracingChannelCollection<StoreType, ContextType>,
|
128 |
+
): TracingChannel<StoreType, ContextType>;
|
129 |
+
/**
|
130 |
+
* The class `Channel` represents an individual named channel within the data
|
131 |
+
* pipeline. It is used to track subscribers and to publish messages when there
|
132 |
+
* are subscribers present. It exists as a separate object to avoid channel
|
133 |
+
* lookups at publish time, enabling very fast publish speeds and allowing
|
134 |
+
* for heavy use while incurring very minimal cost. Channels are created with {@link channel}, constructing a channel directly
|
135 |
+
* with `new Channel(name)` is not supported.
|
136 |
+
* @since v15.1.0, v14.17.0
|
137 |
+
*/
|
138 |
+
class Channel<StoreType = unknown, ContextType = StoreType> {
|
139 |
+
readonly name: string | symbol;
|
140 |
+
/**
|
141 |
+
* Check if there are active subscribers to this channel. This is helpful if
|
142 |
+
* the message you want to send might be expensive to prepare.
|
143 |
+
*
|
144 |
+
* This API is optional but helpful when trying to publish messages from very
|
145 |
+
* performance-sensitive code.
|
146 |
+
*
|
147 |
+
* ```js
|
148 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
149 |
+
*
|
150 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
151 |
+
*
|
152 |
+
* if (channel.hasSubscribers) {
|
153 |
+
* // There are subscribers, prepare and publish message
|
154 |
+
* }
|
155 |
+
* ```
|
156 |
+
* @since v15.1.0, v14.17.0
|
157 |
+
*/
|
158 |
+
readonly hasSubscribers: boolean;
|
159 |
+
private constructor(name: string | symbol);
|
160 |
+
/**
|
161 |
+
* Publish a message to any subscribers to the channel. This will trigger
|
162 |
+
* message handlers synchronously so they will execute within the same context.
|
163 |
+
*
|
164 |
+
* ```js
|
165 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
166 |
+
*
|
167 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
168 |
+
*
|
169 |
+
* channel.publish({
|
170 |
+
* some: 'message',
|
171 |
+
* });
|
172 |
+
* ```
|
173 |
+
* @since v15.1.0, v14.17.0
|
174 |
+
* @param message The message to send to the channel subscribers
|
175 |
+
*/
|
176 |
+
publish(message: unknown): void;
|
177 |
+
/**
|
178 |
+
* Register a message handler to subscribe to this channel. This message handler
|
179 |
+
* will be run synchronously whenever a message is published to the channel. Any
|
180 |
+
* errors thrown in the message handler will trigger an `'uncaughtException'`.
|
181 |
+
*
|
182 |
+
* ```js
|
183 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
184 |
+
*
|
185 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
186 |
+
*
|
187 |
+
* channel.subscribe((message, name) => {
|
188 |
+
* // Received data
|
189 |
+
* });
|
190 |
+
* ```
|
191 |
+
* @since v15.1.0, v14.17.0
|
192 |
+
* @deprecated Since v18.7.0,v16.17.0 - Use {@link subscribe(name, onMessage)}
|
193 |
+
* @param onMessage The handler to receive channel messages
|
194 |
+
*/
|
195 |
+
subscribe(onMessage: ChannelListener): void;
|
196 |
+
/**
|
197 |
+
* Remove a message handler previously registered to this channel with `channel.subscribe(onMessage)`.
|
198 |
+
*
|
199 |
+
* ```js
|
200 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
201 |
+
*
|
202 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
203 |
+
*
|
204 |
+
* function onMessage(message, name) {
|
205 |
+
* // Received data
|
206 |
+
* }
|
207 |
+
*
|
208 |
+
* channel.subscribe(onMessage);
|
209 |
+
*
|
210 |
+
* channel.unsubscribe(onMessage);
|
211 |
+
* ```
|
212 |
+
* @since v15.1.0, v14.17.0
|
213 |
+
* @deprecated Since v18.7.0,v16.17.0 - Use {@link unsubscribe(name, onMessage)}
|
214 |
+
* @param onMessage The previous subscribed handler to remove
|
215 |
+
* @return `true` if the handler was found, `false` otherwise.
|
216 |
+
*/
|
217 |
+
unsubscribe(onMessage: ChannelListener): void;
|
218 |
+
/**
|
219 |
+
* When `channel.runStores(context, ...)` is called, the given context data
|
220 |
+
* will be applied to any store bound to the channel. If the store has already been
|
221 |
+
* bound the previous `transform` function will be replaced with the new one.
|
222 |
+
* The `transform` function may be omitted to set the given context data as the
|
223 |
+
* context directly.
|
224 |
+
*
|
225 |
+
* ```js
|
226 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
227 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
228 |
+
*
|
229 |
+
* const store = new AsyncLocalStorage();
|
230 |
+
*
|
231 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
232 |
+
*
|
233 |
+
* channel.bindStore(store, (data) => {
|
234 |
+
* return { data };
|
235 |
+
* });
|
236 |
+
* ```
|
237 |
+
* @since v19.9.0
|
238 |
+
* @experimental
|
239 |
+
* @param store The store to which to bind the context data
|
240 |
+
* @param transform Transform context data before setting the store context
|
241 |
+
*/
|
242 |
+
bindStore(store: AsyncLocalStorage<StoreType>, transform?: (context: ContextType) => StoreType): void;
|
243 |
+
/**
|
244 |
+
* Remove a message handler previously registered to this channel with `channel.bindStore(store)`.
|
245 |
+
*
|
246 |
+
* ```js
|
247 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
248 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
249 |
+
*
|
250 |
+
* const store = new AsyncLocalStorage();
|
251 |
+
*
|
252 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
253 |
+
*
|
254 |
+
* channel.bindStore(store);
|
255 |
+
* channel.unbindStore(store);
|
256 |
+
* ```
|
257 |
+
* @since v19.9.0
|
258 |
+
* @experimental
|
259 |
+
* @param store The store to unbind from the channel.
|
260 |
+
* @return `true` if the store was found, `false` otherwise.
|
261 |
+
*/
|
262 |
+
unbindStore(store: any): void;
|
263 |
+
/**
|
264 |
+
* Applies the given data to any AsyncLocalStorage instances bound to the channel
|
265 |
+
* for the duration of the given function, then publishes to the channel within
|
266 |
+
* the scope of that data is applied to the stores.
|
267 |
+
*
|
268 |
+
* If a transform function was given to `channel.bindStore(store)` it will be
|
269 |
+
* applied to transform the message data before it becomes the context value for
|
270 |
+
* the store. The prior storage context is accessible from within the transform
|
271 |
+
* function in cases where context linking is required.
|
272 |
+
*
|
273 |
+
* The context applied to the store should be accessible in any async code which
|
274 |
+
* continues from execution which began during the given function, however
|
275 |
+
* there are some situations in which `context loss` may occur.
|
276 |
+
*
|
277 |
+
* ```js
|
278 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
279 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
280 |
+
*
|
281 |
+
* const store = new AsyncLocalStorage();
|
282 |
+
*
|
283 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
284 |
+
*
|
285 |
+
* channel.bindStore(store, (message) => {
|
286 |
+
* const parent = store.getStore();
|
287 |
+
* return new Span(message, parent);
|
288 |
+
* });
|
289 |
+
* channel.runStores({ some: 'message' }, () => {
|
290 |
+
* store.getStore(); // Span({ some: 'message' })
|
291 |
+
* });
|
292 |
+
* ```
|
293 |
+
* @since v19.9.0
|
294 |
+
* @experimental
|
295 |
+
* @param context Message to send to subscribers and bind to stores
|
296 |
+
* @param fn Handler to run within the entered storage context
|
297 |
+
* @param thisArg The receiver to be used for the function call.
|
298 |
+
* @param args Optional arguments to pass to the function.
|
299 |
+
*/
|
300 |
+
runStores(): void;
|
301 |
+
}
|
302 |
+
interface TracingChannelSubscribers<ContextType extends object> {
|
303 |
+
start: (message: ContextType) => void;
|
304 |
+
end: (
|
305 |
+
message: ContextType & {
|
306 |
+
error?: unknown;
|
307 |
+
result?: unknown;
|
308 |
+
},
|
309 |
+
) => void;
|
310 |
+
asyncStart: (
|
311 |
+
message: ContextType & {
|
312 |
+
error?: unknown;
|
313 |
+
result?: unknown;
|
314 |
+
},
|
315 |
+
) => void;
|
316 |
+
asyncEnd: (
|
317 |
+
message: ContextType & {
|
318 |
+
error?: unknown;
|
319 |
+
result?: unknown;
|
320 |
+
},
|
321 |
+
) => void;
|
322 |
+
error: (
|
323 |
+
message: ContextType & {
|
324 |
+
error: unknown;
|
325 |
+
},
|
326 |
+
) => void;
|
327 |
+
}
|
328 |
+
interface TracingChannelCollection<StoreType = unknown, ContextType = StoreType> {
|
329 |
+
start: Channel<StoreType, ContextType>;
|
330 |
+
end: Channel<StoreType, ContextType>;
|
331 |
+
asyncStart: Channel<StoreType, ContextType>;
|
332 |
+
asyncEnd: Channel<StoreType, ContextType>;
|
333 |
+
error: Channel<StoreType, ContextType>;
|
334 |
+
}
|
335 |
+
/**
|
336 |
+
* The class `TracingChannel` is a collection of `TracingChannel Channels` which
|
337 |
+
* together express a single traceable action. It is used to formalize and
|
338 |
+
* simplify the process of producing events for tracing application flow. {@link tracingChannel} is used to construct a `TracingChannel`. As with `Channel` it is recommended to create and reuse a
|
339 |
+
* single `TracingChannel` at the top-level of the file rather than creating them
|
340 |
+
* dynamically.
|
341 |
+
* @since v19.9.0
|
342 |
+
* @experimental
|
343 |
+
*/
|
344 |
+
class TracingChannel<StoreType = unknown, ContextType extends object = {}> implements TracingChannelCollection {
|
345 |
+
start: Channel<StoreType, ContextType>;
|
346 |
+
end: Channel<StoreType, ContextType>;
|
347 |
+
asyncStart: Channel<StoreType, ContextType>;
|
348 |
+
asyncEnd: Channel<StoreType, ContextType>;
|
349 |
+
error: Channel<StoreType, ContextType>;
|
350 |
+
/**
|
351 |
+
* Helper to subscribe a collection of functions to the corresponding channels.
|
352 |
+
* This is the same as calling `channel.subscribe(onMessage)` on each channel
|
353 |
+
* individually.
|
354 |
+
*
|
355 |
+
* ```js
|
356 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
357 |
+
*
|
358 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
359 |
+
*
|
360 |
+
* channels.subscribe({
|
361 |
+
* start(message) {
|
362 |
+
* // Handle start message
|
363 |
+
* },
|
364 |
+
* end(message) {
|
365 |
+
* // Handle end message
|
366 |
+
* },
|
367 |
+
* asyncStart(message) {
|
368 |
+
* // Handle asyncStart message
|
369 |
+
* },
|
370 |
+
* asyncEnd(message) {
|
371 |
+
* // Handle asyncEnd message
|
372 |
+
* },
|
373 |
+
* error(message) {
|
374 |
+
* // Handle error message
|
375 |
+
* },
|
376 |
+
* });
|
377 |
+
* ```
|
378 |
+
* @since v19.9.0
|
379 |
+
* @experimental
|
380 |
+
* @param subscribers Set of `TracingChannel Channels` subscribers
|
381 |
+
*/
|
382 |
+
subscribe(subscribers: TracingChannelSubscribers<ContextType>): void;
|
383 |
+
/**
|
384 |
+
* Helper to unsubscribe a collection of functions from the corresponding channels.
|
385 |
+
* This is the same as calling `channel.unsubscribe(onMessage)` on each channel
|
386 |
+
* individually.
|
387 |
+
*
|
388 |
+
* ```js
|
389 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
390 |
+
*
|
391 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
392 |
+
*
|
393 |
+
* channels.unsubscribe({
|
394 |
+
* start(message) {
|
395 |
+
* // Handle start message
|
396 |
+
* },
|
397 |
+
* end(message) {
|
398 |
+
* // Handle end message
|
399 |
+
* },
|
400 |
+
* asyncStart(message) {
|
401 |
+
* // Handle asyncStart message
|
402 |
+
* },
|
403 |
+
* asyncEnd(message) {
|
404 |
+
* // Handle asyncEnd message
|
405 |
+
* },
|
406 |
+
* error(message) {
|
407 |
+
* // Handle error message
|
408 |
+
* },
|
409 |
+
* });
|
410 |
+
* ```
|
411 |
+
* @since v19.9.0
|
412 |
+
* @experimental
|
413 |
+
* @param subscribers Set of `TracingChannel Channels` subscribers
|
414 |
+
* @return `true` if all handlers were successfully unsubscribed, and `false` otherwise.
|
415 |
+
*/
|
416 |
+
unsubscribe(subscribers: TracingChannelSubscribers<ContextType>): void;
|
417 |
+
/**
|
418 |
+
* Trace a synchronous function call. This will always produce a `start event` and `end event` around the execution and may produce an `error event` if the given function throws an error.
|
419 |
+
* This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all
|
420 |
+
* events should have any bound stores set to match this trace context.
|
421 |
+
*
|
422 |
+
* To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions
|
423 |
+
* which are added after the trace begins will not receive future events from that trace, only future traces will be seen.
|
424 |
+
*
|
425 |
+
* ```js
|
426 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
427 |
+
*
|
428 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
429 |
+
*
|
430 |
+
* channels.traceSync(() => {
|
431 |
+
* // Do something
|
432 |
+
* }, {
|
433 |
+
* some: 'thing',
|
434 |
+
* });
|
435 |
+
* ```
|
436 |
+
* @since v19.9.0
|
437 |
+
* @experimental
|
438 |
+
* @param fn Function to wrap a trace around
|
439 |
+
* @param context Shared object to correlate events through
|
440 |
+
* @param thisArg The receiver to be used for the function call
|
441 |
+
* @param args Optional arguments to pass to the function
|
442 |
+
* @return The return value of the given function
|
443 |
+
*/
|
444 |
+
traceSync<ThisArg = any, Args extends any[] = any[]>(
|
445 |
+
fn: (this: ThisArg, ...args: Args) => any,
|
446 |
+
context?: ContextType,
|
447 |
+
thisArg?: ThisArg,
|
448 |
+
...args: Args
|
449 |
+
): void;
|
450 |
+
/**
|
451 |
+
* Trace a promise-returning function call. This will always produce a `start event` and `end event` around the synchronous portion of the
|
452 |
+
* function execution, and will produce an `asyncStart event` and `asyncEnd event` when a promise continuation is reached. It may also
|
453 |
+
* produce an `error event` if the given function throws an error or the
|
454 |
+
* returned promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all
|
455 |
+
* events should have any bound stores set to match this trace context.
|
456 |
+
*
|
457 |
+
* To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions
|
458 |
+
* which are added after the trace begins will not receive future events from that trace, only future traces will be seen.
|
459 |
+
*
|
460 |
+
* ```js
|
461 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
462 |
+
*
|
463 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
464 |
+
*
|
465 |
+
* channels.tracePromise(async () => {
|
466 |
+
* // Do something
|
467 |
+
* }, {
|
468 |
+
* some: 'thing',
|
469 |
+
* });
|
470 |
+
* ```
|
471 |
+
* @since v19.9.0
|
472 |
+
* @experimental
|
473 |
+
* @param fn Promise-returning function to wrap a trace around
|
474 |
+
* @param context Shared object to correlate trace events through
|
475 |
+
* @param thisArg The receiver to be used for the function call
|
476 |
+
* @param args Optional arguments to pass to the function
|
477 |
+
* @return Chained from promise returned by the given function
|
478 |
+
*/
|
479 |
+
tracePromise<ThisArg = any, Args extends any[] = any[]>(
|
480 |
+
fn: (this: ThisArg, ...args: Args) => Promise<any>,
|
481 |
+
context?: ContextType,
|
482 |
+
thisArg?: ThisArg,
|
483 |
+
...args: Args
|
484 |
+
): void;
|
485 |
+
/**
|
486 |
+
* Trace a callback-receiving function call. This will always produce a `start event` and `end event` around the synchronous portion of the
|
487 |
+
* function execution, and will produce a `asyncStart event` and `asyncEnd event` around the callback execution. It may also produce an `error event` if the given function throws an error or
|
488 |
+
* the returned
|
489 |
+
* promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all
|
490 |
+
* events should have any bound stores set to match this trace context.
|
491 |
+
*
|
492 |
+
* The `position` will be -1 by default to indicate the final argument should
|
493 |
+
* be used as the callback.
|
494 |
+
*
|
495 |
+
* ```js
|
496 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
497 |
+
*
|
498 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
499 |
+
*
|
500 |
+
* channels.traceCallback((arg1, callback) => {
|
501 |
+
* // Do something
|
502 |
+
* callback(null, 'result');
|
503 |
+
* }, 1, {
|
504 |
+
* some: 'thing',
|
505 |
+
* }, thisArg, arg1, callback);
|
506 |
+
* ```
|
507 |
+
*
|
508 |
+
* The callback will also be run with `channel.runStores(context, ...)` which
|
509 |
+
* enables context loss recovery in some cases.
|
510 |
+
*
|
511 |
+
* To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions
|
512 |
+
* which are added after the trace begins will not receive future events from that trace, only future traces will be seen.
|
513 |
+
*
|
514 |
+
* ```js
|
515 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
516 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
517 |
+
*
|
518 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
519 |
+
* const myStore = new AsyncLocalStorage();
|
520 |
+
*
|
521 |
+
* // The start channel sets the initial store data to something
|
522 |
+
* // and stores that store data value on the trace context object
|
523 |
+
* channels.start.bindStore(myStore, (data) => {
|
524 |
+
* const span = new Span(data);
|
525 |
+
* data.span = span;
|
526 |
+
* return span;
|
527 |
+
* });
|
528 |
+
*
|
529 |
+
* // Then asyncStart can restore from that data it stored previously
|
530 |
+
* channels.asyncStart.bindStore(myStore, (data) => {
|
531 |
+
* return data.span;
|
532 |
+
* });
|
533 |
+
* ```
|
534 |
+
* @since v19.9.0
|
535 |
+
* @experimental
|
536 |
+
* @param fn callback using function to wrap a trace around
|
537 |
+
* @param position Zero-indexed argument position of expected callback
|
538 |
+
* @param context Shared object to correlate trace events through
|
539 |
+
* @param thisArg The receiver to be used for the function call
|
540 |
+
* @param args Optional arguments to pass to the function
|
541 |
+
* @return The return value of the given function
|
542 |
+
*/
|
543 |
+
traceCallback<Fn extends (this: any, ...args: any[]) => any>(
|
544 |
+
fn: Fn,
|
545 |
+
position?: number,
|
546 |
+
context?: ContextType,
|
547 |
+
thisArg?: any,
|
548 |
+
...args: Parameters<Fn>
|
549 |
+
): void;
|
550 |
+
}
|
551 |
+
}
|
552 |
+
declare module "node:diag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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* The `node:dns` module enables name resolution. For example, use it to look up IP
|
3 |
+
* addresses of host names.
|
4 |
+
*
|
5 |
+
* Although named for the [Domain Name System (DNS)](https://en.wikipedia.org/wiki/Domain_Name_System), it does not always use the
|
6 |
+
* DNS protocol for lookups. {@link lookup} uses the operating system
|
7 |
+
* facilities to perform name resolution. It may not need to perform any network
|
8 |
+
* communication. To perform name resolution the way other applications on the same
|
9 |
+
* system do, use {@link lookup}.
|
10 |
+
*
|
11 |
+
* ```js
|
12 |
+
* import dns from 'node:dns';
|
13 |
+
*
|
14 |
+
* dns.lookup('example.org', (err, address, family) => {
|
15 |
+
* console.log('address: %j family: IPv%s', address, family);
|
16 |
+
* });
|
17 |
+
* // address: "93.184.216.34" family: IPv4
|
18 |
+
* ```
|
19 |
+
*
|
20 |
+
* All other functions in the `node:dns` module connect to an actual DNS server to
|
21 |
+
* perform name resolution. They will always use the network to perform DNS
|
22 |
+
* queries. These functions do not use the same set of configuration files used by {@link lookup} (e.g. `/etc/hosts`). Use these functions to always perform
|
23 |
+
* DNS queries, bypassing other name-resolution facilities.
|
24 |
+
*
|
25 |
+
* ```js
|
26 |
+
* import dns from 'node:dns';
|
27 |
+
*
|
28 |
+
* dns.resolve4('archive.org', (err, addresses) => {
|
29 |
+
* if (err) throw err;
|
30 |
+
*
|
31 |
+
* console.log(`addresses: ${JSON.stringify(addresses)}`);
|
32 |
+
*
|
33 |
+
* addresses.forEach((a) => {
|
34 |
+
* dns.reverse(a, (err, hostnames) => {
|
35 |
+
* if (err) {
|
36 |
+
* throw err;
|
37 |
+
* }
|
38 |
+
* console.log(`reverse for ${a}: ${JSON.stringify(hostnames)}`);
|
39 |
+
* });
|
40 |
+
* });
|
41 |
+
* });
|
42 |
+
* ```
|
43 |
+
*
|
44 |
+
* See the [Implementation considerations section](https://nodejs.org/docs/latest-v22.x/api/dns.html#implementation-considerations) for more information.
|
45 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/dns.js)
|
46 |
+
*/
|
47 |
+
declare module "dns" {
|
48 |
+
import * as dnsPromises from "node:dns/promises";
|
49 |
+
// Supported getaddrinfo flags.
|
50 |
+
/**
|
51 |
+
* Limits returned address types to the types of non-loopback addresses configured on the system. For example, IPv4 addresses are
|
52 |
+
* only returned if the current system has at least one IPv4 address configured.
|
53 |
+
*/
|
54 |
+
export const ADDRCONFIG: number;
|
55 |
+
/**
|
56 |
+
* If the IPv6 family was specified, but no IPv6 addresses were found, then return IPv4 mapped IPv6 addresses. It is not supported
|
57 |
+
* on some operating systems (e.g. FreeBSD 10.1).
|
58 |
+
*/
|
59 |
+
export const V4MAPPED: number;
|
60 |
+
/**
|
61 |
+
* If `dns.V4MAPPED` is specified, return resolved IPv6 addresses as
|
62 |
+
* well as IPv4 mapped IPv6 addresses.
|
63 |
+
*/
|
64 |
+
export const ALL: number;
|
65 |
+
export interface LookupOptions {
|
66 |
+
/**
|
67 |
+
* The record family. Must be `4`, `6`, or `0`. For backward compatibility reasons, `'IPv4'` and `'IPv6'` are interpreted
|
68 |
+
* as `4` and `6` respectively. The value 0 indicates that either an IPv4 or IPv6 address is returned. If the value `0` is used
|
69 |
+
* with `{ all: true } (see below)`, both IPv4 and IPv6 addresses are returned.
|
70 |
+
* @default 0
|
71 |
+
*/
|
72 |
+
family?: number | "IPv4" | "IPv6" | undefined;
|
73 |
+
/**
|
74 |
+
* One or more [supported `getaddrinfo`](https://nodejs.org/docs/latest-v22.x/api/dns.html#supported-getaddrinfo-flags) flags. Multiple flags may be
|
75 |
+
* passed by bitwise `OR`ing their values.
|
76 |
+
*/
|
77 |
+
hints?: number | undefined;
|
78 |
+
/**
|
79 |
+
* When `true`, the callback returns all resolved addresses in an array. Otherwise, returns a single address.
|
80 |
+
* @default false
|
81 |
+
*/
|
82 |
+
all?: boolean | undefined;
|
83 |
+
/**
|
84 |
+
* When `verbatim`, the resolved addresses are return unsorted. When `ipv4first`, the resolved addresses are sorted
|
85 |
+
* by placing IPv4 addresses before IPv6 addresses. When `ipv6first`, the resolved addresses are sorted by placing IPv6
|
86 |
+
* addresses before IPv4 addresses. Default value is configurable using
|
87 |
+
* {@link setDefaultResultOrder} or [`--dns-result-order`](https://nodejs.org/docs/latest-v22.x/api/cli.html#--dns-result-orderorder).
|
88 |
+
* @default `verbatim` (addresses are not reordered)
|
89 |
+
* @since v22.1.0
|
90 |
+
*/
|
91 |
+
order?: "ipv4first" | "ipv6first" | "verbatim" | undefined;
|
92 |
+
/**
|
93 |
+
* When `true`, the callback receives IPv4 and IPv6 addresses in the order the DNS resolver returned them. When `false`, IPv4
|
94 |
+
* addresses are placed before IPv6 addresses. This option will be deprecated in favor of `order`. When both are specified,
|
95 |
+
* `order` has higher precedence. New code should only use `order`. Default value is configurable using {@link setDefaultResultOrder}
|
96 |
+
* @default true (addresses are not reordered)
|
97 |
+
* @deprecated Please use `order` option
|
98 |
+
*/
|
99 |
+
verbatim?: boolean | undefined;
|
100 |
+
}
|
101 |
+
export interface LookupOneOptions extends LookupOptions {
|
102 |
+
all?: false | undefined;
|
103 |
+
}
|
104 |
+
export interface LookupAllOptions extends LookupOptions {
|
105 |
+
all: true;
|
106 |
+
}
|
107 |
+
export interface LookupAddress {
|
108 |
+
/**
|
109 |
+
* A string representation of an IPv4 or IPv6 address.
|
110 |
+
*/
|
111 |
+
address: string;
|
112 |
+
/**
|
113 |
+
* `4` or `6`, denoting the family of `address`, or `0` if the address is not an IPv4 or IPv6 address. `0` is a likely indicator of a
|
114 |
+
* bug in the name resolution service used by the operating system.
|
115 |
+
*/
|
116 |
+
family: number;
|
117 |
+
}
|
118 |
+
/**
|
119 |
+
* Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
|
120 |
+
* AAAA (IPv6) record. All `option` properties are optional. If `options` is an
|
121 |
+
* integer, then it must be `4` or `6` – if `options` is `0` or not provided, then
|
122 |
+
* IPv4 and IPv6 addresses are both returned if found.
|
123 |
+
*
|
124 |
+
* With the `all` option set to `true`, the arguments for `callback` change to `(err, addresses)`, with `addresses` being an array of objects with the
|
125 |
+
* properties `address` and `family`.
|
126 |
+
*
|
127 |
+
* On error, `err` is an `Error` object, where `err.code` is the error code.
|
128 |
+
* Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
|
129 |
+
* the host name does not exist but also when the lookup fails in other ways
|
130 |
+
* such as no available file descriptors.
|
131 |
+
*
|
132 |
+
* `dns.lookup()` does not necessarily have anything to do with the DNS protocol.
|
133 |
+
* The implementation uses an operating system facility that can associate names
|
134 |
+
* with addresses and vice versa. This implementation can have subtle but
|
135 |
+
* important consequences on the behavior of any Node.js program. Please take some
|
136 |
+
* time to consult the [Implementation considerations section](https://nodejs.org/docs/latest-v22.x/api/dns.html#implementation-considerations)
|
137 |
+
* before using `dns.lookup()`.
|
138 |
+
*
|
139 |
+
* Example usage:
|
140 |
+
*
|
141 |
+
* ```js
|
142 |
+
* import dns from 'node:dns';
|
143 |
+
* const options = {
|
144 |
+
* family: 6,
|
145 |
+
* hints: dns.ADDRCONFIG | dns.V4MAPPED,
|
146 |
+
* };
|
147 |
+
* dns.lookup('example.com', options, (err, address, family) =>
|
148 |
+
* console.log('address: %j family: IPv%s', address, family));
|
149 |
+
* // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
|
150 |
+
*
|
151 |
+
* // When options.all is true, the result will be an Array.
|
152 |
+
* options.all = true;
|
153 |
+
* dns.lookup('example.com', options, (err, addresses) =>
|
154 |
+
* console.log('addresses: %j', addresses));
|
155 |
+
* // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
|
156 |
+
* ```
|
157 |
+
*
|
158 |
+
* If this method is invoked as its [util.promisify()](https://nodejs.org/docs/latest-v22.x/api/util.html#utilpromisifyoriginal) ed
|
159 |
+
* version, and `all` is not set to `true`, it returns a `Promise` for an `Object` with `address` and `family` properties.
|
160 |
+
* @since v0.1.90
|
161 |
+
*/
|
162 |
+
export function lookup(
|
163 |
+
hostname: string,
|
164 |
+
family: number,
|
165 |
+
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
166 |
+
): void;
|
167 |
+
export function lookup(
|
168 |
+
hostname: string,
|
169 |
+
options: LookupOneOptions,
|
170 |
+
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
171 |
+
): void;
|
172 |
+
export function lookup(
|
173 |
+
hostname: string,
|
174 |
+
options: LookupAllOptions,
|
175 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void,
|
176 |
+
): void;
|
177 |
+
export function lookup(
|
178 |
+
hostname: string,
|
179 |
+
options: LookupOptions,
|
180 |
+
callback: (err: NodeJS.ErrnoException | null, address: string | LookupAddress[], family: number) => void,
|
181 |
+
): void;
|
182 |
+
export function lookup(
|
183 |
+
hostname: string,
|
184 |
+
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
185 |
+
): void;
|
186 |
+
export namespace lookup {
|
187 |
+
function __promisify__(hostname: string, options: LookupAllOptions): Promise<LookupAddress[]>;
|
188 |
+
function __promisify__(hostname: string, options?: LookupOneOptions | number): Promise<LookupAddress>;
|
189 |
+
function __promisify__(hostname: string, options: LookupOptions): Promise<LookupAddress | LookupAddress[]>;
|
190 |
+
}
|
191 |
+
/**
|
192 |
+
* Resolves the given `address` and `port` into a host name and service using
|
193 |
+
* the operating system's underlying `getnameinfo` implementation.
|
194 |
+
*
|
195 |
+
* If `address` is not a valid IP address, a `TypeError` will be thrown.
|
196 |
+
* The `port` will be coerced to a number. If it is not a legal port, a `TypeError` will be thrown.
|
197 |
+
*
|
198 |
+
* On an error, `err` is an [`Error`](https://nodejs.org/docs/latest-v22.x/api/errors.html#class-error) object,
|
199 |
+
* where `err.code` is the error code.
|
200 |
+
*
|
201 |
+
* ```js
|
202 |
+
* import dns from 'node:dns';
|
203 |
+
* dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
|
204 |
+
* console.log(hostname, service);
|
205 |
+
* // Prints: localhost ssh
|
206 |
+
* });
|
207 |
+
* ```
|
208 |
+
*
|
209 |
+
* If this method is invoked as its [util.promisify()](https://nodejs.org/docs/latest-v22.x/api/util.html#utilpromisifyoriginal) ed
|
210 |
+
* version, it returns a `Promise` for an `Object` with `hostname` and `service` properties.
|
211 |
+
* @since v0.11.14
|
212 |
+
*/
|
213 |
+
export function lookupService(
|
214 |
+
address: string,
|
215 |
+
port: number,
|
216 |
+
callback: (err: NodeJS.ErrnoException | null, hostname: string, service: string) => void,
|
217 |
+
): void;
|
218 |
+
export namespace lookupService {
|
219 |
+
function __promisify__(
|
220 |
+
address: string,
|
221 |
+
port: number,
|
222 |
+
): Promise<{
|
223 |
+
hostname: string;
|
224 |
+
service: string;
|
225 |
+
}>;
|
226 |
+
}
|
227 |
+
export interface ResolveOptions {
|
228 |
+
ttl: boolean;
|
229 |
+
}
|
230 |
+
export interface ResolveWithTtlOptions extends ResolveOptions {
|
231 |
+
ttl: true;
|
232 |
+
}
|
233 |
+
export interface RecordWithTtl {
|
234 |
+
address: string;
|
235 |
+
ttl: number;
|
236 |
+
}
|
237 |
+
/** @deprecated Use `AnyARecord` or `AnyAaaaRecord` instead. */
|
238 |
+
export type AnyRecordWithTtl = AnyARecord | AnyAaaaRecord;
|
239 |
+
export interface AnyARecord extends RecordWithTtl {
|
240 |
+
type: "A";
|
241 |
+
}
|
242 |
+
export interface AnyAaaaRecord extends RecordWithTtl {
|
243 |
+
type: "AAAA";
|
244 |
+
}
|
245 |
+
export interface CaaRecord {
|
246 |
+
critical: number;
|
247 |
+
issue?: string | undefined;
|
248 |
+
issuewild?: string | undefined;
|
249 |
+
iodef?: string | undefined;
|
250 |
+
contactemail?: string | undefined;
|
251 |
+
contactphone?: string | undefined;
|
252 |
+
}
|
253 |
+
export interface MxRecord {
|
254 |
+
priority: number;
|
255 |
+
exchange: string;
|
256 |
+
}
|
257 |
+
export interface AnyMxRecord extends MxRecord {
|
258 |
+
type: "MX";
|
259 |
+
}
|
260 |
+
export interface NaptrRecord {
|
261 |
+
flags: string;
|
262 |
+
service: string;
|
263 |
+
regexp: string;
|
264 |
+
replacement: string;
|
265 |
+
order: number;
|
266 |
+
preference: number;
|
267 |
+
}
|
268 |
+
export interface AnyNaptrRecord extends NaptrRecord {
|
269 |
+
type: "NAPTR";
|
270 |
+
}
|
271 |
+
export interface SoaRecord {
|
272 |
+
nsname: string;
|
273 |
+
hostmaster: string;
|
274 |
+
serial: number;
|
275 |
+
refresh: number;
|
276 |
+
retry: number;
|
277 |
+
expire: number;
|
278 |
+
minttl: number;
|
279 |
+
}
|
280 |
+
export interface AnySoaRecord extends SoaRecord {
|
281 |
+
type: "SOA";
|
282 |
+
}
|
283 |
+
export interface SrvRecord {
|
284 |
+
priority: number;
|
285 |
+
weight: number;
|
286 |
+
port: number;
|
287 |
+
name: string;
|
288 |
+
}
|
289 |
+
export interface AnySrvRecord extends SrvRecord {
|
290 |
+
type: "SRV";
|
291 |
+
}
|
292 |
+
export interface AnyTxtRecord {
|
293 |
+
type: "TXT";
|
294 |
+
entries: string[];
|
295 |
+
}
|
296 |
+
export interface AnyNsRecord {
|
297 |
+
type: "NS";
|
298 |
+
value: string;
|
299 |
+
}
|
300 |
+
export interface AnyPtrRecord {
|
301 |
+
type: "PTR";
|
302 |
+
value: string;
|
303 |
+
}
|
304 |
+
export interface AnyCnameRecord {
|
305 |
+
type: "CNAME";
|
306 |
+
value: string;
|
307 |
+
}
|
308 |
+
export type AnyRecord =
|
309 |
+
| AnyARecord
|
310 |
+
| AnyAaaaRecord
|
311 |
+
| AnyCnameRecord
|
312 |
+
| AnyMxRecord
|
313 |
+
| AnyNaptrRecord
|
314 |
+
| AnyNsRecord
|
315 |
+
| AnyPtrRecord
|
316 |
+
| AnySoaRecord
|
317 |
+
| AnySrvRecord
|
318 |
+
| AnyTxtRecord;
|
319 |
+
/**
|
320 |
+
* Uses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array
|
321 |
+
* of the resource records. The `callback` function has arguments `(err, records)`. When successful, `records` will be an array of resource
|
322 |
+
* records. The type and structure of individual results varies based on `rrtype`:
|
323 |
+
*
|
324 |
+
* <omitted>
|
325 |
+
*
|
326 |
+
* On error, `err` is an [`Error`](https://nodejs.org/docs/latest-v22.x/api/errors.html#class-error) object,
|
327 |
+
* where `err.code` is one of the `DNS error codes`.
|
328 |
+
* @since v0.1.27
|
329 |
+
* @param hostname Host name to resolve.
|
330 |
+
* @param [rrtype='A'] Resource record type.
|
331 |
+
*/
|
332 |
+
export function resolve(
|
333 |
+
hostname: string,
|
334 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
335 |
+
): void;
|
336 |
+
export function resolve(
|
337 |
+
hostname: string,
|
338 |
+
rrtype: "A",
|
339 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
340 |
+
): void;
|
341 |
+
export function resolve(
|
342 |
+
hostname: string,
|
343 |
+
rrtype: "AAAA",
|
344 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
345 |
+
): void;
|
346 |
+
export function resolve(
|
347 |
+
hostname: string,
|
348 |
+
rrtype: "ANY",
|
349 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: AnyRecord[]) => void,
|
350 |
+
): void;
|
351 |
+
export function resolve(
|
352 |
+
hostname: string,
|
353 |
+
rrtype: "CNAME",
|
354 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
355 |
+
): void;
|
356 |
+
export function resolve(
|
357 |
+
hostname: string,
|
358 |
+
rrtype: "MX",
|
359 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: MxRecord[]) => void,
|
360 |
+
): void;
|
361 |
+
export function resolve(
|
362 |
+
hostname: string,
|
363 |
+
rrtype: "NAPTR",
|
364 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: NaptrRecord[]) => void,
|
365 |
+
): void;
|
366 |
+
export function resolve(
|
367 |
+
hostname: string,
|
368 |
+
rrtype: "NS",
|
369 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
370 |
+
): void;
|
371 |
+
export function resolve(
|
372 |
+
hostname: string,
|
373 |
+
rrtype: "PTR",
|
374 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
375 |
+
): void;
|
376 |
+
export function resolve(
|
377 |
+
hostname: string,
|
378 |
+
rrtype: "SOA",
|
379 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: SoaRecord) => void,
|
380 |
+
): void;
|
381 |
+
export function resolve(
|
382 |
+
hostname: string,
|
383 |
+
rrtype: "SRV",
|
384 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: SrvRecord[]) => void,
|
385 |
+
): void;
|
386 |
+
export function resolve(
|
387 |
+
hostname: string,
|
388 |
+
rrtype: "TXT",
|
389 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[][]) => void,
|
390 |
+
): void;
|
391 |
+
export function resolve(
|
392 |
+
hostname: string,
|
393 |
+
rrtype: string,
|
394 |
+
callback: (
|
395 |
+
err: NodeJS.ErrnoException | null,
|
396 |
+
addresses: string[] | MxRecord[] | NaptrRecord[] | SoaRecord | SrvRecord[] | string[][] | AnyRecord[],
|
397 |
+
) => void,
|
398 |
+
): void;
|
399 |
+
export namespace resolve {
|
400 |
+
function __promisify__(hostname: string, rrtype?: "A" | "AAAA" | "CNAME" | "NS" | "PTR"): Promise<string[]>;
|
401 |
+
function __promisify__(hostname: string, rrtype: "ANY"): Promise<AnyRecord[]>;
|
402 |
+
function __promisify__(hostname: string, rrtype: "MX"): Promise<MxRecord[]>;
|
403 |
+
function __promisify__(hostname: string, rrtype: "NAPTR"): Promise<NaptrRecord[]>;
|
404 |
+
function __promisify__(hostname: string, rrtype: "SOA"): Promise<SoaRecord>;
|
405 |
+
function __promisify__(hostname: string, rrtype: "SRV"): Promise<SrvRecord[]>;
|
406 |
+
function __promisify__(hostname: string, rrtype: "TXT"): Promise<string[][]>;
|
407 |
+
function __promisify__(
|
408 |
+
hostname: string,
|
409 |
+
rrtype: string,
|
410 |
+
): Promise<string[] | MxRecord[] | NaptrRecord[] | SoaRecord | SrvRecord[] | string[][] | AnyRecord[]>;
|
411 |
+
}
|
412 |
+
/**
|
413 |
+
* Uses the DNS protocol to resolve a IPv4 addresses (`A` records) for the `hostname`. The `addresses` argument passed to the `callback` function
|
414 |
+
* will contain an array of IPv4 addresses (e.g.`['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
|
415 |
+
* @since v0.1.16
|
416 |
+
* @param hostname Host name to resolve.
|
417 |
+
*/
|
418 |
+
export function resolve4(
|
419 |
+
hostname: string,
|
420 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
421 |
+
): void;
|
422 |
+
export function resolve4(
|
423 |
+
hostname: string,
|
424 |
+
options: ResolveWithTtlOptions,
|
425 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: RecordWithTtl[]) => void,
|
426 |
+
): void;
|
427 |
+
export function resolve4(
|
428 |
+
hostname: string,
|
429 |
+
options: ResolveOptions,
|
430 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[] | RecordWithTtl[]) => void,
|
431 |
+
): void;
|
432 |
+
export namespace resolve4 {
|
433 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
434 |
+
function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
|
435 |
+
function __promisify__(hostname: string, options?: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
|
436 |
+
}
|
437 |
+
/**
|
438 |
+
* Uses the DNS protocol to resolve IPv6 addresses (`AAAA` records) for the `hostname`. The `addresses` argument passed to the `callback` function
|
439 |
+
* will contain an array of IPv6 addresses.
|
440 |
+
* @since v0.1.16
|
441 |
+
* @param hostname Host name to resolve.
|
442 |
+
*/
|
443 |
+
export function resolve6(
|
444 |
+
hostname: string,
|
445 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
446 |
+
): void;
|
447 |
+
export function resolve6(
|
448 |
+
hostname: string,
|
449 |
+
options: ResolveWithTtlOptions,
|
450 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: RecordWithTtl[]) => void,
|
451 |
+
): void;
|
452 |
+
export function resolve6(
|
453 |
+
hostname: string,
|
454 |
+
options: ResolveOptions,
|
455 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[] | RecordWithTtl[]) => void,
|
456 |
+
): void;
|
457 |
+
export namespace resolve6 {
|
458 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
459 |
+
function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
|
460 |
+
function __promisify__(hostname: string, options?: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
|
461 |
+
}
|
462 |
+
/**
|
463 |
+
* Uses the DNS protocol to resolve `CNAME` records for the `hostname`. The `addresses` argument passed to the `callback` function
|
464 |
+
* will contain an array of canonical name records available for the `hostname` (e.g. `['bar.example.com']`).
|
465 |
+
* @since v0.3.2
|
466 |
+
*/
|
467 |
+
export function resolveCname(
|
468 |
+
hostname: string,
|
469 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
470 |
+
): void;
|
471 |
+
export namespace resolveCname {
|
472 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
473 |
+
}
|
474 |
+
/**
|
475 |
+
* Uses the DNS protocol to resolve `CAA` records for the `hostname`. The `addresses` argument passed to the `callback` function
|
476 |
+
* will contain an array of certification authority authorization records
|
477 |
+
* available for the `hostname` (e.g. `[{critical: 0, iodef: 'mailto:[email protected]'}, {critical: 128, issue: 'pki.example.com'}]`).
|
478 |
+
* @since v15.0.0, v14.17.0
|
479 |
+
*/
|
480 |
+
export function resolveCaa(
|
481 |
+
hostname: string,
|
482 |
+
callback: (err: NodeJS.ErrnoException | null, records: CaaRecord[]) => void,
|
483 |
+
): void;
|
484 |
+
export namespace resolveCaa {
|
485 |
+
function __promisify__(hostname: string): Promise<CaaRecord[]>;
|
486 |
+
}
|
487 |
+
/**
|
488 |
+
* Uses the DNS protocol to resolve mail exchange records (`MX` records) for the `hostname`. The `addresses` argument passed to the `callback` function will
|
489 |
+
* contain an array of objects containing both a `priority` and `exchange` property (e.g. `[{priority: 10, exchange: 'mx.example.com'}, ...]`).
|
490 |
+
* @since v0.1.27
|
491 |
+
*/
|
492 |
+
export function resolveMx(
|
493 |
+
hostname: string,
|
494 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: MxRecord[]) => void,
|
495 |
+
): void;
|
496 |
+
export namespace resolveMx {
|
497 |
+
function __promisify__(hostname: string): Promise<MxRecord[]>;
|
498 |
+
}
|
499 |
+
/**
|
500 |
+
* Uses the DNS protocol to resolve regular expression-based records (`NAPTR` records) for the `hostname`. The `addresses` argument passed to the `callback` function will contain an array of
|
501 |
+
* objects with the following properties:
|
502 |
+
*
|
503 |
+
* * `flags`
|
504 |
+
* * `service`
|
505 |
+
* * `regexp`
|
506 |
+
* * `replacement`
|
507 |
+
* * `order`
|
508 |
+
* * `preference`
|
509 |
+
*
|
510 |
+
* ```js
|
511 |
+
* {
|
512 |
+
* flags: 's',
|
513 |
+
* service: 'SIP+D2U',
|
514 |
+
* regexp: '',
|
515 |
+
* replacement: '_sip._udp.example.com',
|
516 |
+
* order: 30,
|
517 |
+
* preference: 100
|
518 |
+
* }
|
519 |
+
* ```
|
520 |
+
* @since v0.9.12
|
521 |
+
*/
|
522 |
+
export function resolveNaptr(
|
523 |
+
hostname: string,
|
524 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: NaptrRecord[]) => void,
|
525 |
+
): void;
|
526 |
+
export namespace resolveNaptr {
|
527 |
+
function __promisify__(hostname: string): Promise<NaptrRecord[]>;
|
528 |
+
}
|
529 |
+
/**
|
530 |
+
* Uses the DNS protocol to resolve name server records (`NS` records) for the `hostname`. The `addresses` argument passed to the `callback` function will
|
531 |
+
* contain an array of name server records available for `hostname` (e.g. `['ns1.example.com', 'ns2.example.com']`).
|
532 |
+
* @since v0.1.90
|
533 |
+
*/
|
534 |
+
export function resolveNs(
|
535 |
+
hostname: string,
|
536 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
537 |
+
): void;
|
538 |
+
export namespace resolveNs {
|
539 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
540 |
+
}
|
541 |
+
/**
|
542 |
+
* Uses the DNS protocol to resolve pointer records (`PTR` records) for the `hostname`. The `addresses` argument passed to the `callback` function will
|
543 |
+
* be an array of strings containing the reply records.
|
544 |
+
* @since v6.0.0
|
545 |
+
*/
|
546 |
+
export function resolvePtr(
|
547 |
+
hostname: string,
|
548 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
549 |
+
): void;
|
550 |
+
export namespace resolvePtr {
|
551 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
552 |
+
}
|
553 |
+
/**
|
554 |
+
* Uses the DNS protocol to resolve a start of authority record (`SOA` record) for
|
555 |
+
* the `hostname`. The `address` argument passed to the `callback` function will
|
556 |
+
* be an object with the following properties:
|
557 |
+
*
|
558 |
+
* * `nsname`
|
559 |
+
* * `hostmaster`
|
560 |
+
* * `serial`
|
561 |
+
* * `refresh`
|
562 |
+
* * `retry`
|
563 |
+
* * `expire`
|
564 |
+
* * `minttl`
|
565 |
+
*
|
566 |
+
* ```js
|
567 |
+
* {
|
568 |
+
* nsname: 'ns.example.com',
|
569 |
+
* hostmaster: 'root.example.com',
|
570 |
+
* serial: 2013101809,
|
571 |
+
* refresh: 10000,
|
572 |
+
* retry: 2400,
|
573 |
+
* expire: 604800,
|
574 |
+
* minttl: 3600
|
575 |
+
* }
|
576 |
+
* ```
|
577 |
+
* @since v0.11.10
|
578 |
+
*/
|
579 |
+
export function resolveSoa(
|
580 |
+
hostname: string,
|
581 |
+
callback: (err: NodeJS.ErrnoException | null, address: SoaRecord) => void,
|
582 |
+
): void;
|
583 |
+
export namespace resolveSoa {
|
584 |
+
function __promisify__(hostname: string): Promise<SoaRecord>;
|
585 |
+
}
|
586 |
+
/**
|
587 |
+
* Uses the DNS protocol to resolve service records (`SRV` records) for the `hostname`. The `addresses` argument passed to the `callback` function will
|
588 |
+
* be an array of objects with the following properties:
|
589 |
+
*
|
590 |
+
* * `priority`
|
591 |
+
* * `weight`
|
592 |
+
* * `port`
|
593 |
+
* * `name`
|
594 |
+
*
|
595 |
+
* ```js
|
596 |
+
* {
|
597 |
+
* priority: 10,
|
598 |
+
* weight: 5,
|
599 |
+
* port: 21223,
|
600 |
+
* name: 'service.example.com'
|
601 |
+
* }
|
602 |
+
* ```
|
603 |
+
* @since v0.1.27
|
604 |
+
*/
|
605 |
+
export function resolveSrv(
|
606 |
+
hostname: string,
|
607 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: SrvRecord[]) => void,
|
608 |
+
): void;
|
609 |
+
export namespace resolveSrv {
|
610 |
+
function __promisify__(hostname: string): Promise<SrvRecord[]>;
|
611 |
+
}
|
612 |
+
/**
|
613 |
+
* Uses the DNS protocol to resolve text queries (`TXT` records) for the `hostname`. The `records` argument passed to the `callback` function is a
|
614 |
+
* two-dimensional array of the text records available for `hostname` (e.g.`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of
|
615 |
+
* one record. Depending on the use case, these could be either joined together or
|
616 |
+
* treated separately.
|
617 |
+
* @since v0.1.27
|
618 |
+
*/
|
619 |
+
export function resolveTxt(
|
620 |
+
hostname: string,
|
621 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[][]) => void,
|
622 |
+
): void;
|
623 |
+
export namespace resolveTxt {
|
624 |
+
function __promisify__(hostname: string): Promise<string[][]>;
|
625 |
+
}
|
626 |
+
/**
|
627 |
+
* Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
|
628 |
+
* The `ret` argument passed to the `callback` function will be an array containing
|
629 |
+
* various types of records. Each object has a property `type` that indicates the
|
630 |
+
* type of the current record. And depending on the `type`, additional properties
|
631 |
+
* will be present on the object:
|
632 |
+
*
|
633 |
+
* <omitted>
|
634 |
+
*
|
635 |
+
* Here is an example of the `ret` object passed to the callback:
|
636 |
+
*
|
637 |
+
* ```js
|
638 |
+
* [ { type: 'A', address: '127.0.0.1', ttl: 299 },
|
639 |
+
* { type: 'CNAME', value: 'example.com' },
|
640 |
+
* { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
|
641 |
+
* { type: 'NS', value: 'ns1.example.com' },
|
642 |
+
* { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
|
643 |
+
* { type: 'SOA',
|
644 |
+
* nsname: 'ns1.example.com',
|
645 |
+
* hostmaster: 'admin.example.com',
|
646 |
+
* serial: 156696742,
|
647 |
+
* refresh: 900,
|
648 |
+
* retry: 900,
|
649 |
+
* expire: 1800,
|
650 |
+
* minttl: 60 } ]
|
651 |
+
* ```
|
652 |
+
*
|
653 |
+
* DNS server operators may choose not to respond to `ANY` queries. It may be better to call individual methods like {@link resolve4}, {@link resolveMx}, and so on. For more details, see
|
654 |
+
* [RFC 8482](https://tools.ietf.org/html/rfc8482).
|
655 |
+
*/
|
656 |
+
export function resolveAny(
|
657 |
+
hostname: string,
|
658 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: AnyRecord[]) => void,
|
659 |
+
): void;
|
660 |
+
export namespace resolveAny {
|
661 |
+
function __promisify__(hostname: string): Promise<AnyRecord[]>;
|
662 |
+
}
|
663 |
+
/**
|
664 |
+
* Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
|
665 |
+
* array of host names.
|
666 |
+
*
|
667 |
+
* On error, `err` is an [`Error`](https://nodejs.org/docs/latest-v22.x/api/errors.html#class-error) object, where `err.code` is
|
668 |
+
* one of the [DNS error codes](https://nodejs.org/docs/latest-v22.x/api/dns.html#error-codes).
|
669 |
+
* @since v0.1.16
|
670 |
+
*/
|
671 |
+
export function reverse(
|
672 |
+
ip: string,
|
673 |
+
callback: (err: NodeJS.ErrnoException | null, hostnames: string[]) => void,
|
674 |
+
): void;
|
675 |
+
/**
|
676 |
+
* Get the default value for `order` in {@link lookup} and [`dnsPromises.lookup()`](https://nodejs.org/docs/latest-v22.x/api/dns.html#dnspromiseslookuphostname-options).
|
677 |
+
* The value could be:
|
678 |
+
*
|
679 |
+
* * `ipv4first`: for `order` defaulting to `ipv4first`.
|
680 |
+
* * `ipv6first`: for `order` defaulting to `ipv6first`.
|
681 |
+
* * `verbatim`: for `order` defaulting to `verbatim`.
|
682 |
+
* @since v18.17.0
|
683 |
+
*/
|
684 |
+
export function getDefaultResultOrder(): "ipv4first" | "ipv6first" | "verbatim";
|
685 |
+
/**
|
686 |
+
* Sets the IP address and port of servers to be used when performing DNS
|
687 |
+
* resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted
|
688 |
+
* addresses. If the port is the IANA default DNS port (53) it can be omitted.
|
689 |
+
*
|
690 |
+
* ```js
|
691 |
+
* dns.setServers([
|
692 |
+
* '4.4.4.4',
|
693 |
+
* '[2001:4860:4860::8888]',
|
694 |
+
* '4.4.4.4:1053',
|
695 |
+
* '[2001:4860:4860::8888]:1053',
|
696 |
+
* ]);
|
697 |
+
* ```
|
698 |
+
*
|
699 |
+
* An error will be thrown if an invalid address is provided.
|
700 |
+
*
|
701 |
+
* The `dns.setServers()` method must not be called while a DNS query is in
|
702 |
+
* progress.
|
703 |
+
*
|
704 |
+
* The {@link setServers} method affects only {@link resolve}, `dns.resolve*()` and {@link reverse} (and specifically _not_ {@link lookup}).
|
705 |
+
*
|
706 |
+
* This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
|
707 |
+
* That is, if attempting to resolve with the first server provided results in a `NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with
|
708 |
+
* subsequent servers provided. Fallback DNS servers will only be used if the
|
709 |
+
* earlier ones time out or result in some other error.
|
710 |
+
* @since v0.11.3
|
711 |
+
* @param servers array of [RFC 5952](https://datatracker.ietf.org/doc/html/rfc5952#section-6) formatted addresses
|
712 |
+
*/
|
713 |
+
export function setServers(servers: readonly string[]): void;
|
714 |
+
/**
|
715 |
+
* Returns an array of IP address strings, formatted according to [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6),
|
716 |
+
* that are currently configured for DNS resolution. A string will include a port
|
717 |
+
* section if a custom port is used.
|
718 |
+
*
|
719 |
+
* ```js
|
720 |
+
* [
|
721 |
+
* '4.4.4.4',
|
722 |
+
* '2001:4860:4860::8888',
|
723 |
+
* '4.4.4.4:1053',
|
724 |
+
* '[2001:4860:4860::8888]:1053',
|
725 |
+
* ]
|
726 |
+
* ```
|
727 |
+
* @since v0.11.3
|
728 |
+
*/
|
729 |
+
export function getServers(): string[];
|
730 |
+
/**
|
731 |
+
* Set the default value of `order` in {@link lookup} and [`dnsPromises.lookup()`](https://nodejs.org/docs/latest-v22.x/api/dns.html#dnspromiseslookuphostname-options).
|
732 |
+
* The value could be:
|
733 |
+
*
|
734 |
+
* * `ipv4first`: sets default `order` to `ipv4first`.
|
735 |
+
* * `ipv6first`: sets default `order` to `ipv6first`.
|
736 |
+
* * `verbatim`: sets default `order` to `verbatim`.
|
737 |
+
*
|
738 |
+
* The default is `verbatim` and {@link setDefaultResultOrder} have higher
|
739 |
+
* priority than [`--dns-result-order`](https://nodejs.org/docs/latest-v22.x/api/cli.html#--dns-result-orderorder). When using
|
740 |
+
* [worker threads](https://nodejs.org/docs/latest-v22.x/api/worker_threads.html), {@link setDefaultResultOrder} from the main
|
741 |
+
* thread won't affect the default dns orders in workers.
|
742 |
+
* @since v16.4.0, v14.18.0
|
743 |
+
* @param order must be `'ipv4first'`, `'ipv6first'` or `'verbatim'`.
|
744 |
+
*/
|
745 |
+
export function setDefaultResultOrder(order: "ipv4first" | "ipv6first" | "verbatim"): void;
|
746 |
+
// Error codes
|
747 |
+
export const NODATA: "ENODATA";
|
748 |
+
export const FORMERR: "EFORMERR";
|
749 |
+
export const SERVFAIL: "ESERVFAIL";
|
750 |
+
export const NOTFOUND: "ENOTFOUND";
|
751 |
+
export const NOTIMP: "ENOTIMP";
|
752 |
+
export const REFUSED: "EREFUSED";
|
753 |
+
export const BADQUERY: "EBADQUERY";
|
754 |
+
export const BADNAME: "EBADNAME";
|
755 |
+
export const BADFAMILY: "EBADFAMILY";
|
756 |
+
export const BADRESP: "EBADRESP";
|
757 |
+
export const CONNREFUSED: "ECONNREFUSED";
|
758 |
+
export const TIMEOUT: "ETIMEOUT";
|
759 |
+
export const EOF: "EOF";
|
760 |
+
export const FILE: "EFILE";
|
761 |
+
export const NOMEM: "ENOMEM";
|
762 |
+
export const DESTRUCTION: "EDESTRUCTION";
|
763 |
+
export const BADSTR: "EBADSTR";
|
764 |
+
export const BADFLAGS: "EBADFLAGS";
|
765 |
+
export const NONAME: "ENONAME";
|
766 |
+
export const BADHINTS: "EBADHINTS";
|
767 |
+
export const NOTINITIALIZED: "ENOTINITIALIZED";
|
768 |
+
export const LOADIPHLPAPI: "ELOADIPHLPAPI";
|
769 |
+
export const ADDRGETNETWORKPARAMS: "EADDRGETNETWORKPARAMS";
|
770 |
+
export const CANCELLED: "ECANCELLED";
|
771 |
+
export interface ResolverOptions {
|
772 |
+
/**
|
773 |
+
* Query timeout in milliseconds, or `-1` to use the default timeout.
|
774 |
+
*/
|
775 |
+
timeout?: number | undefined;
|
776 |
+
/**
|
777 |
+
* The number of tries the resolver will try contacting each name server before giving up.
|
778 |
+
* @default 4
|
779 |
+
*/
|
780 |
+
tries?: number;
|
781 |
+
}
|
782 |
+
/**
|
783 |
+
* An independent resolver for DNS requests.
|
784 |
+
*
|
785 |
+
* Creating a new resolver uses the default server settings. Setting
|
786 |
+
* the servers used for a resolver using [`resolver.setServers()`](https://nodejs.org/docs/latest-v22.x/api/dns.html#dnssetserversservers) does not affect
|
787 |
+
* other resolvers:
|
788 |
+
*
|
789 |
+
* ```js
|
790 |
+
* import { Resolver } from 'node:dns';
|
791 |
+
* const resolver = new Resolver();
|
792 |
+
* resolver.setServers(['4.4.4.4']);
|
793 |
+
*
|
794 |
+
* // This request will use the server at 4.4.4.4, independent of global settings.
|
795 |
+
* resolver.resolve4('example.org', (err, addresses) => {
|
796 |
+
* // ...
|
797 |
+
* });
|
798 |
+
* ```
|
799 |
+
*
|
800 |
+
* The following methods from the `node:dns` module are available:
|
801 |
+
*
|
802 |
+
* * `resolver.getServers()`
|
803 |
+
* * `resolver.resolve()`
|
804 |
+
* * `resolver.resolve4()`
|
805 |
+
* * `resolver.resolve6()`
|
806 |
+
* * `resolver.resolveAny()`
|
807 |
+
* * `resolver.resolveCaa()`
|
808 |
+
* * `resolver.resolveCname()`
|
809 |
+
* * `resolver.resolveMx()`
|
810 |
+
* * `resolver.resolveNaptr()`
|
811 |
+
* * `resolver.resolveNs()`
|
812 |
+
* * `resolver.resolvePtr()`
|
813 |
+
* * `resolver.resolveSoa()`
|
814 |
+
* * `resolver.resolveSrv()`
|
815 |
+
* * `resolver.resolveTxt()`
|
816 |
+
* * `resolver.reverse()`
|
817 |
+
* * `resolver.setServers()`
|
818 |
+
* @since v8.3.0
|
819 |
+
*/
|
820 |
+
export class Resolver {
|
821 |
+
constructor(options?: ResolverOptions);
|
822 |
+
/**
|
823 |
+
* Cancel all outstanding DNS queries made by this resolver. The corresponding
|
824 |
+
* callbacks will be called with an error with code `ECANCELLED`.
|
825 |
+
* @since v8.3.0
|
826 |
+
*/
|
827 |
+
cancel(): void;
|
828 |
+
getServers: typeof getServers;
|
829 |
+
resolve: typeof resolve;
|
830 |
+
resolve4: typeof resolve4;
|
831 |
+
resolve6: typeof resolve6;
|
832 |
+
resolveAny: typeof resolveAny;
|
833 |
+
resolveCaa: typeof resolveCaa;
|
834 |
+
resolveCname: typeof resolveCname;
|
835 |
+
resolveMx: typeof resolveMx;
|
836 |
+
resolveNaptr: typeof resolveNaptr;
|
837 |
+
resolveNs: typeof resolveNs;
|
838 |
+
resolvePtr: typeof resolvePtr;
|
839 |
+
resolveSoa: typeof resolveSoa;
|
840 |
+
resolveSrv: typeof resolveSrv;
|
841 |
+
resolveTxt: typeof resolveTxt;
|
842 |
+
reverse: typeof reverse;
|
843 |
+
/**
|
844 |
+
* The resolver instance will send its requests from the specified IP address.
|
845 |
+
* This allows programs to specify outbound interfaces when used on multi-homed
|
846 |
+
* systems.
|
847 |
+
*
|
848 |
+
* If a v4 or v6 address is not specified, it is set to the default and the
|
849 |
+
* operating system will choose a local address automatically.
|
850 |
+
*
|
851 |
+
* The resolver will use the v4 local address when making requests to IPv4 DNS
|
852 |
+
* servers, and the v6 local address when making requests to IPv6 DNS servers.
|
853 |
+
* The `rrtype` of resolution requests has no impact on the local address used.
|
854 |
+
* @since v15.1.0, v14.17.0
|
855 |
+
* @param [ipv4='0.0.0.0'] A string representation of an IPv4 address.
|
856 |
+
* @param [ipv6='::0'] A string representation of an IPv6 address.
|
857 |
+
*/
|
858 |
+
setLocalAddress(ipv4?: string, ipv6?: string): void;
|
859 |
+
setServers: typeof setServers;
|
860 |
+
}
|
861 |
+
export { dnsPromises as promises };
|
862 |
+
}
|
863 |
+
declare module "node:dns" {
|
864 |
+
export * from "dns";
|
865 |
+
}
|
clone/node_modules/@types/node/dns/promises.d.ts
ADDED
@@ -0,0 +1,476 @@
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* The `dns.promises` API provides an alternative set of asynchronous DNS methods
|
3 |
+
* that return `Promise` objects rather than using callbacks. The API is accessible
|
4 |
+
* via `import { promises as dnsPromises } from 'node:dns'` or `import dnsPromises from 'node:dns/promises'`.
|
5 |
+
* @since v10.6.0
|
6 |
+
*/
|
7 |
+
declare module "dns/promises" {
|
8 |
+
import {
|
9 |
+
AnyRecord,
|
10 |
+
CaaRecord,
|
11 |
+
LookupAddress,
|
12 |
+
LookupAllOptions,
|
13 |
+
LookupOneOptions,
|
14 |
+
LookupOptions,
|
15 |
+
MxRecord,
|
16 |
+
NaptrRecord,
|
17 |
+
RecordWithTtl,
|
18 |
+
ResolveOptions,
|
19 |
+
ResolverOptions,
|
20 |
+
ResolveWithTtlOptions,
|
21 |
+
SoaRecord,
|
22 |
+
SrvRecord,
|
23 |
+
} from "node:dns";
|
24 |
+
/**
|
25 |
+
* Returns an array of IP address strings, formatted according to [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6),
|
26 |
+
* that are currently configured for DNS resolution. A string will include a port
|
27 |
+
* section if a custom port is used.
|
28 |
+
*
|
29 |
+
* ```js
|
30 |
+
* [
|
31 |
+
* '4.4.4.4',
|
32 |
+
* '2001:4860:4860::8888',
|
33 |
+
* '4.4.4.4:1053',
|
34 |
+
* '[2001:4860:4860::8888]:1053',
|
35 |
+
* ]
|
36 |
+
* ```
|
37 |
+
* @since v10.6.0
|
38 |
+
*/
|
39 |
+
function getServers(): string[];
|
40 |
+
/**
|
41 |
+
* Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
|
42 |
+
* AAAA (IPv6) record. All `option` properties are optional. If `options` is an
|
43 |
+
* integer, then it must be `4` or `6` – if `options` is not provided, then IPv4
|
44 |
+
* and IPv6 addresses are both returned if found.
|
45 |
+
*
|
46 |
+
* With the `all` option set to `true`, the `Promise` is resolved with `addresses` being an array of objects with the properties `address` and `family`.
|
47 |
+
*
|
48 |
+
* On error, the `Promise` is rejected with an [`Error`](https://nodejs.org/docs/latest-v20.x/api/errors.html#class-error) object, where `err.code` is the error code.
|
49 |
+
* Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
|
50 |
+
* the host name does not exist but also when the lookup fails in other ways
|
51 |
+
* such as no available file descriptors.
|
52 |
+
*
|
53 |
+
* [`dnsPromises.lookup()`](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromiseslookuphostname-options) does not necessarily have anything to do with the DNS
|
54 |
+
* protocol. The implementation uses an operating system facility that can
|
55 |
+
* associate names with addresses and vice versa. This implementation can have
|
56 |
+
* subtle but important consequences on the behavior of any Node.js program. Please
|
57 |
+
* take some time to consult the [Implementation considerations section](https://nodejs.org/docs/latest-v20.x/api/dns.html#implementation-considerations) before
|
58 |
+
* using `dnsPromises.lookup()`.
|
59 |
+
*
|
60 |
+
* Example usage:
|
61 |
+
*
|
62 |
+
* ```js
|
63 |
+
* import dns from 'node:dns';
|
64 |
+
* const dnsPromises = dns.promises;
|
65 |
+
* const options = {
|
66 |
+
* family: 6,
|
67 |
+
* hints: dns.ADDRCONFIG | dns.V4MAPPED,
|
68 |
+
* };
|
69 |
+
*
|
70 |
+
* dnsPromises.lookup('example.com', options).then((result) => {
|
71 |
+
* console.log('address: %j family: IPv%s', result.address, result.family);
|
72 |
+
* // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
|
73 |
+
* });
|
74 |
+
*
|
75 |
+
* // When options.all is true, the result will be an Array.
|
76 |
+
* options.all = true;
|
77 |
+
* dnsPromises.lookup('example.com', options).then((result) => {
|
78 |
+
* console.log('addresses: %j', result);
|
79 |
+
* // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
|
80 |
+
* });
|
81 |
+
* ```
|
82 |
+
* @since v10.6.0
|
83 |
+
*/
|
84 |
+
function lookup(hostname: string, family: number): Promise<LookupAddress>;
|
85 |
+
function lookup(hostname: string, options: LookupOneOptions): Promise<LookupAddress>;
|
86 |
+
function lookup(hostname: string, options: LookupAllOptions): Promise<LookupAddress[]>;
|
87 |
+
function lookup(hostname: string, options: LookupOptions): Promise<LookupAddress | LookupAddress[]>;
|
88 |
+
function lookup(hostname: string): Promise<LookupAddress>;
|
89 |
+
/**
|
90 |
+
* Resolves the given `address` and `port` into a host name and service using
|
91 |
+
* the operating system's underlying `getnameinfo` implementation.
|
92 |
+
*
|
93 |
+
* If `address` is not a valid IP address, a `TypeError` will be thrown.
|
94 |
+
* The `port` will be coerced to a number. If it is not a legal port, a `TypeError` will be thrown.
|
95 |
+
*
|
96 |
+
* On error, the `Promise` is rejected with an [`Error`](https://nodejs.org/docs/latest-v20.x/api/errors.html#class-error) object, where `err.code` is the error code.
|
97 |
+
*
|
98 |
+
* ```js
|
99 |
+
* import dnsPromises from 'node:dns';
|
100 |
+
* dnsPromises.lookupService('127.0.0.1', 22).then((result) => {
|
101 |
+
* console.log(result.hostname, result.service);
|
102 |
+
* // Prints: localhost ssh
|
103 |
+
* });
|
104 |
+
* ```
|
105 |
+
* @since v10.6.0
|
106 |
+
*/
|
107 |
+
function lookupService(
|
108 |
+
address: string,
|
109 |
+
port: number,
|
110 |
+
): Promise<{
|
111 |
+
hostname: string;
|
112 |
+
service: string;
|
113 |
+
}>;
|
114 |
+
/**
|
115 |
+
* Uses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array
|
116 |
+
* of the resource records. When successful, the `Promise` is resolved with an
|
117 |
+
* array of resource records. The type and structure of individual results vary
|
118 |
+
* based on `rrtype`:
|
119 |
+
*
|
120 |
+
* <omitted>
|
121 |
+
*
|
122 |
+
* On error, the `Promise` is rejected with an [`Error`](https://nodejs.org/docs/latest-v20.x/api/errors.html#class-error) object, where `err.code`
|
123 |
+
* is one of the [DNS error codes](https://nodejs.org/docs/latest-v20.x/api/dns.html#error-codes).
|
124 |
+
* @since v10.6.0
|
125 |
+
* @param hostname Host name to resolve.
|
126 |
+
* @param [rrtype='A'] Resource record type.
|
127 |
+
*/
|
128 |
+
function resolve(hostname: string): Promise<string[]>;
|
129 |
+
function resolve(hostname: string, rrtype: "A"): Promise<string[]>;
|
130 |
+
function resolve(hostname: string, rrtype: "AAAA"): Promise<string[]>;
|
131 |
+
function resolve(hostname: string, rrtype: "ANY"): Promise<AnyRecord[]>;
|
132 |
+
function resolve(hostname: string, rrtype: "CAA"): Promise<CaaRecord[]>;
|
133 |
+
function resolve(hostname: string, rrtype: "CNAME"): Promise<string[]>;
|
134 |
+
function resolve(hostname: string, rrtype: "MX"): Promise<MxRecord[]>;
|
135 |
+
function resolve(hostname: string, rrtype: "NAPTR"): Promise<NaptrRecord[]>;
|
136 |
+
function resolve(hostname: string, rrtype: "NS"): Promise<string[]>;
|
137 |
+
function resolve(hostname: string, rrtype: "PTR"): Promise<string[]>;
|
138 |
+
function resolve(hostname: string, rrtype: "SOA"): Promise<SoaRecord>;
|
139 |
+
function resolve(hostname: string, rrtype: "SRV"): Promise<SrvRecord[]>;
|
140 |
+
function resolve(hostname: string, rrtype: "TXT"): Promise<string[][]>;
|
141 |
+
function resolve(
|
142 |
+
hostname: string,
|
143 |
+
rrtype: string,
|
144 |
+
): Promise<string[] | MxRecord[] | NaptrRecord[] | SoaRecord | SrvRecord[] | string[][] | AnyRecord[]>;
|
145 |
+
/**
|
146 |
+
* Uses the DNS protocol to resolve IPv4 addresses (`A` records) for the `hostname`. On success, the `Promise` is resolved with an array of IPv4
|
147 |
+
* addresses (e.g. `['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
|
148 |
+
* @since v10.6.0
|
149 |
+
* @param hostname Host name to resolve.
|
150 |
+
*/
|
151 |
+
function resolve4(hostname: string): Promise<string[]>;
|
152 |
+
function resolve4(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
|
153 |
+
function resolve4(hostname: string, options: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
|
154 |
+
/**
|
155 |
+
* Uses the DNS protocol to resolve IPv6 addresses (`AAAA` records) for the `hostname`. On success, the `Promise` is resolved with an array of IPv6
|
156 |
+
* addresses.
|
157 |
+
* @since v10.6.0
|
158 |
+
* @param hostname Host name to resolve.
|
159 |
+
*/
|
160 |
+
function resolve6(hostname: string): Promise<string[]>;
|
161 |
+
function resolve6(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
|
162 |
+
function resolve6(hostname: string, options: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
|
163 |
+
/**
|
164 |
+
* Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
|
165 |
+
* On success, the `Promise` is resolved with an array containing various types of
|
166 |
+
* records. Each object has a property `type` that indicates the type of the
|
167 |
+
* current record. And depending on the `type`, additional properties will be
|
168 |
+
* present on the object:
|
169 |
+
*
|
170 |
+
* <omitted>
|
171 |
+
*
|
172 |
+
* Here is an example of the result object:
|
173 |
+
*
|
174 |
+
* ```js
|
175 |
+
* [ { type: 'A', address: '127.0.0.1', ttl: 299 },
|
176 |
+
* { type: 'CNAME', value: 'example.com' },
|
177 |
+
* { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
|
178 |
+
* { type: 'NS', value: 'ns1.example.com' },
|
179 |
+
* { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
|
180 |
+
* { type: 'SOA',
|
181 |
+
* nsname: 'ns1.example.com',
|
182 |
+
* hostmaster: 'admin.example.com',
|
183 |
+
* serial: 156696742,
|
184 |
+
* refresh: 900,
|
185 |
+
* retry: 900,
|
186 |
+
* expire: 1800,
|
187 |
+
* minttl: 60 } ]
|
188 |
+
* ```
|
189 |
+
* @since v10.6.0
|
190 |
+
*/
|
191 |
+
function resolveAny(hostname: string): Promise<AnyRecord[]>;
|
192 |
+
/**
|
193 |
+
* Uses the DNS protocol to resolve `CAA` records for the `hostname`. On success,
|
194 |
+
* the `Promise` is resolved with an array of objects containing available
|
195 |
+
* certification authority authorization records available for the `hostname` (e.g. `[{critical: 0, iodef: 'mailto:[email protected]'},{critical: 128, issue: 'pki.example.com'}]`).
|
196 |
+
* @since v15.0.0, v14.17.0
|
197 |
+
*/
|
198 |
+
function resolveCaa(hostname: string): Promise<CaaRecord[]>;
|
199 |
+
/**
|
200 |
+
* Uses the DNS protocol to resolve `CNAME` records for the `hostname`. On success,
|
201 |
+
* the `Promise` is resolved with an array of canonical name records available for
|
202 |
+
* the `hostname` (e.g. `['bar.example.com']`).
|
203 |
+
* @since v10.6.0
|
204 |
+
*/
|
205 |
+
function resolveCname(hostname: string): Promise<string[]>;
|
206 |
+
/**
|
207 |
+
* Uses the DNS protocol to resolve mail exchange records (`MX` records) for the `hostname`. On success, the `Promise` is resolved with an array of objects
|
208 |
+
* containing both a `priority` and `exchange` property (e.g.`[{priority: 10, exchange: 'mx.example.com'}, ...]`).
|
209 |
+
* @since v10.6.0
|
210 |
+
*/
|
211 |
+
function resolveMx(hostname: string): Promise<MxRecord[]>;
|
212 |
+
/**
|
213 |
+
* Uses the DNS protocol to resolve regular expression-based records (`NAPTR` records) for the `hostname`. On success, the `Promise` is resolved with an array
|
214 |
+
* of objects with the following properties:
|
215 |
+
*
|
216 |
+
* * `flags`
|
217 |
+
* * `service`
|
218 |
+
* * `regexp`
|
219 |
+
* * `replacement`
|
220 |
+
* * `order`
|
221 |
+
* * `preference`
|
222 |
+
*
|
223 |
+
* ```js
|
224 |
+
* {
|
225 |
+
* flags: 's',
|
226 |
+
* service: 'SIP+D2U',
|
227 |
+
* regexp: '',
|
228 |
+
* replacement: '_sip._udp.example.com',
|
229 |
+
* order: 30,
|
230 |
+
* preference: 100
|
231 |
+
* }
|
232 |
+
* ```
|
233 |
+
* @since v10.6.0
|
234 |
+
*/
|
235 |
+
function resolveNaptr(hostname: string): Promise<NaptrRecord[]>;
|
236 |
+
/**
|
237 |
+
* Uses the DNS protocol to resolve name server records (`NS` records) for the `hostname`. On success, the `Promise` is resolved with an array of name server
|
238 |
+
* records available for `hostname` (e.g.`['ns1.example.com', 'ns2.example.com']`).
|
239 |
+
* @since v10.6.0
|
240 |
+
*/
|
241 |
+
function resolveNs(hostname: string): Promise<string[]>;
|
242 |
+
/**
|
243 |
+
* Uses the DNS protocol to resolve pointer records (`PTR` records) for the `hostname`. On success, the `Promise` is resolved with an array of strings
|
244 |
+
* containing the reply records.
|
245 |
+
* @since v10.6.0
|
246 |
+
*/
|
247 |
+
function resolvePtr(hostname: string): Promise<string[]>;
|
248 |
+
/**
|
249 |
+
* Uses the DNS protocol to resolve a start of authority record (`SOA` record) for
|
250 |
+
* the `hostname`. On success, the `Promise` is resolved with an object with the
|
251 |
+
* following properties:
|
252 |
+
*
|
253 |
+
* * `nsname`
|
254 |
+
* * `hostmaster`
|
255 |
+
* * `serial`
|
256 |
+
* * `refresh`
|
257 |
+
* * `retry`
|
258 |
+
* * `expire`
|
259 |
+
* * `minttl`
|
260 |
+
*
|
261 |
+
* ```js
|
262 |
+
* {
|
263 |
+
* nsname: 'ns.example.com',
|
264 |
+
* hostmaster: 'root.example.com',
|
265 |
+
* serial: 2013101809,
|
266 |
+
* refresh: 10000,
|
267 |
+
* retry: 2400,
|
268 |
+
* expire: 604800,
|
269 |
+
* minttl: 3600
|
270 |
+
* }
|
271 |
+
* ```
|
272 |
+
* @since v10.6.0
|
273 |
+
*/
|
274 |
+
function resolveSoa(hostname: string): Promise<SoaRecord>;
|
275 |
+
/**
|
276 |
+
* Uses the DNS protocol to resolve service records (`SRV` records) for the `hostname`. On success, the `Promise` is resolved with an array of objects with
|
277 |
+
* the following properties:
|
278 |
+
*
|
279 |
+
* * `priority`
|
280 |
+
* * `weight`
|
281 |
+
* * `port`
|
282 |
+
* * `name`
|
283 |
+
*
|
284 |
+
* ```js
|
285 |
+
* {
|
286 |
+
* priority: 10,
|
287 |
+
* weight: 5,
|
288 |
+
* port: 21223,
|
289 |
+
* name: 'service.example.com'
|
290 |
+
* }
|
291 |
+
* ```
|
292 |
+
* @since v10.6.0
|
293 |
+
*/
|
294 |
+
function resolveSrv(hostname: string): Promise<SrvRecord[]>;
|
295 |
+
/**
|
296 |
+
* Uses the DNS protocol to resolve text queries (`TXT` records) for the `hostname`. On success, the `Promise` is resolved with a two-dimensional array
|
297 |
+
* of the text records available for `hostname` (e.g.`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of
|
298 |
+
* one record. Depending on the use case, these could be either joined together or
|
299 |
+
* treated separately.
|
300 |
+
* @since v10.6.0
|
301 |
+
*/
|
302 |
+
function resolveTxt(hostname: string): Promise<string[][]>;
|
303 |
+
/**
|
304 |
+
* Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
|
305 |
+
* array of host names.
|
306 |
+
*
|
307 |
+
* On error, the `Promise` is rejected with an [`Error`](https://nodejs.org/docs/latest-v20.x/api/errors.html#class-error) object, where `err.code`
|
308 |
+
* is one of the [DNS error codes](https://nodejs.org/docs/latest-v20.x/api/dns.html#error-codes).
|
309 |
+
* @since v10.6.0
|
310 |
+
*/
|
311 |
+
function reverse(ip: string): Promise<string[]>;
|
312 |
+
/**
|
313 |
+
* Get the default value for `verbatim` in {@link lookup} and [dnsPromises.lookup()](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromiseslookuphostname-options).
|
314 |
+
* The value could be:
|
315 |
+
*
|
316 |
+
* * `ipv4first`: for `verbatim` defaulting to `false`.
|
317 |
+
* * `verbatim`: for `verbatim` defaulting to `true`.
|
318 |
+
* @since v20.1.0
|
319 |
+
*/
|
320 |
+
function getDefaultResultOrder(): "ipv4first" | "verbatim";
|
321 |
+
/**
|
322 |
+
* Sets the IP address and port of servers to be used when performing DNS
|
323 |
+
* resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted
|
324 |
+
* addresses. If the port is the IANA default DNS port (53) it can be omitted.
|
325 |
+
*
|
326 |
+
* ```js
|
327 |
+
* dnsPromises.setServers([
|
328 |
+
* '4.4.4.4',
|
329 |
+
* '[2001:4860:4860::8888]',
|
330 |
+
* '4.4.4.4:1053',
|
331 |
+
* '[2001:4860:4860::8888]:1053',
|
332 |
+
* ]);
|
333 |
+
* ```
|
334 |
+
*
|
335 |
+
* An error will be thrown if an invalid address is provided.
|
336 |
+
*
|
337 |
+
* The `dnsPromises.setServers()` method must not be called while a DNS query is in
|
338 |
+
* progress.
|
339 |
+
*
|
340 |
+
* This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
|
341 |
+
* That is, if attempting to resolve with the first server provided results in a `NOTFOUND` error, the `resolve()` method will _not_ attempt to resolve with
|
342 |
+
* subsequent servers provided. Fallback DNS servers will only be used if the
|
343 |
+
* earlier ones time out or result in some other error.
|
344 |
+
* @since v10.6.0
|
345 |
+
* @param servers array of `RFC 5952` formatted addresses
|
346 |
+
*/
|
347 |
+
function setServers(servers: readonly string[]): void;
|
348 |
+
/**
|
349 |
+
* Set the default value of `order` in `dns.lookup()` and `{@link lookup}`. The value could be:
|
350 |
+
*
|
351 |
+
* * `ipv4first`: sets default `order` to `ipv4first`.
|
352 |
+
* * `ipv6first`: sets default `order` to `ipv6first`.
|
353 |
+
* * `verbatim`: sets default `order` to `verbatim`.
|
354 |
+
*
|
355 |
+
* The default is `verbatim` and [dnsPromises.setDefaultResultOrder()](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromisessetdefaultresultorderorder)
|
356 |
+
* have higher priority than [`--dns-result-order`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--dns-result-orderorder).
|
357 |
+
* When using [worker threads](https://nodejs.org/docs/latest-v20.x/api/worker_threads.html), [`dnsPromises.setDefaultResultOrder()`](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromisessetdefaultresultorderorder)
|
358 |
+
* from the main thread won't affect the default dns orders in workers.
|
359 |
+
* @since v16.4.0, v14.18.0
|
360 |
+
* @param order must be `'ipv4first'`, `'ipv6first'` or `'verbatim'`.
|
361 |
+
*/
|
362 |
+
function setDefaultResultOrder(order: "ipv4first" | "ipv6first" | "verbatim"): void;
|
363 |
+
// Error codes
|
364 |
+
const NODATA: "ENODATA";
|
365 |
+
const FORMERR: "EFORMERR";
|
366 |
+
const SERVFAIL: "ESERVFAIL";
|
367 |
+
const NOTFOUND: "ENOTFOUND";
|
368 |
+
const NOTIMP: "ENOTIMP";
|
369 |
+
const REFUSED: "EREFUSED";
|
370 |
+
const BADQUERY: "EBADQUERY";
|
371 |
+
const BADNAME: "EBADNAME";
|
372 |
+
const BADFAMILY: "EBADFAMILY";
|
373 |
+
const BADRESP: "EBADRESP";
|
374 |
+
const CONNREFUSED: "ECONNREFUSED";
|
375 |
+
const TIMEOUT: "ETIMEOUT";
|
376 |
+
const EOF: "EOF";
|
377 |
+
const FILE: "EFILE";
|
378 |
+
const NOMEM: "ENOMEM";
|
379 |
+
const DESTRUCTION: "EDESTRUCTION";
|
380 |
+
const BADSTR: "EBADSTR";
|
381 |
+
const BADFLAGS: "EBADFLAGS";
|
382 |
+
const NONAME: "ENONAME";
|
383 |
+
const BADHINTS: "EBADHINTS";
|
384 |
+
const NOTINITIALIZED: "ENOTINITIALIZED";
|
385 |
+
const LOADIPHLPAPI: "ELOADIPHLPAPI";
|
386 |
+
const ADDRGETNETWORKPARAMS: "EADDRGETNETWORKPARAMS";
|
387 |
+
const CANCELLED: "ECANCELLED";
|
388 |
+
|
389 |
+
/**
|
390 |
+
* An independent resolver for DNS requests.
|
391 |
+
*
|
392 |
+
* Creating a new resolver uses the default server settings. Setting
|
393 |
+
* the servers used for a resolver using [`resolver.setServers()`](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromisessetserversservers) does not affect
|
394 |
+
* other resolvers:
|
395 |
+
*
|
396 |
+
* ```js
|
397 |
+
* import { promises } from 'node:dns';
|
398 |
+
* const resolver = new promises.Resolver();
|
399 |
+
* resolver.setServers(['4.4.4.4']);
|
400 |
+
*
|
401 |
+
* // This request will use the server at 4.4.4.4, independent of global settings.
|
402 |
+
* resolver.resolve4('example.org').then((addresses) => {
|
403 |
+
* // ...
|
404 |
+
* });
|
405 |
+
*
|
406 |
+
* // Alternatively, the same code can be written using async-await style.
|
407 |
+
* (async function() {
|
408 |
+
* const addresses = await resolver.resolve4('example.org');
|
409 |
+
* })();
|
410 |
+
* ```
|
411 |
+
*
|
412 |
+
* The following methods from the `dnsPromises` API are available:
|
413 |
+
*
|
414 |
+
* * `resolver.getServers()`
|
415 |
+
* * `resolver.resolve()`
|
416 |
+
* * `resolver.resolve4()`
|
417 |
+
* * `resolver.resolve6()`
|
418 |
+
* * `resolver.resolveAny()`
|
419 |
+
* * `resolver.resolveCaa()`
|
420 |
+
* * `resolver.resolveCname()`
|
421 |
+
* * `resolver.resolveMx()`
|
422 |
+
* * `resolver.resolveNaptr()`
|
423 |
+
* * `resolver.resolveNs()`
|
424 |
+
* * `resolver.resolvePtr()`
|
425 |
+
* * `resolver.resolveSoa()`
|
426 |
+
* * `resolver.resolveSrv()`
|
427 |
+
* * `resolver.resolveTxt()`
|
428 |
+
* * `resolver.reverse()`
|
429 |
+
* * `resolver.setServers()`
|
430 |
+
* @since v10.6.0
|
431 |
+
*/
|
432 |
+
class Resolver {
|
433 |
+
constructor(options?: ResolverOptions);
|
434 |
+
/**
|
435 |
+
* Cancel all outstanding DNS queries made by this resolver. The corresponding
|
436 |
+
* callbacks will be called with an error with code `ECANCELLED`.
|
437 |
+
* @since v8.3.0
|
438 |
+
*/
|
439 |
+
cancel(): void;
|
440 |
+
getServers: typeof getServers;
|
441 |
+
resolve: typeof resolve;
|
442 |
+
resolve4: typeof resolve4;
|
443 |
+
resolve6: typeof resolve6;
|
444 |
+
resolveAny: typeof resolveAny;
|
445 |
+
resolveCaa: typeof resolveCaa;
|
446 |
+
resolveCname: typeof resolveCname;
|
447 |
+
resolveMx: typeof resolveMx;
|
448 |
+
resolveNaptr: typeof resolveNaptr;
|
449 |
+
resolveNs: typeof resolveNs;
|
450 |
+
resolvePtr: typeof resolvePtr;
|
451 |
+
resolveSoa: typeof resolveSoa;
|
452 |
+
resolveSrv: typeof resolveSrv;
|
453 |
+
resolveTxt: typeof resolveTxt;
|
454 |
+
reverse: typeof reverse;
|
455 |
+
/**
|
456 |
+
* The resolver instance will send its requests from the specified IP address.
|
457 |
+
* This allows programs to specify outbound interfaces when used on multi-homed
|
458 |
+
* systems.
|
459 |
+
*
|
460 |
+
* If a v4 or v6 address is not specified, it is set to the default and the
|
461 |
+
* operating system will choose a local address automatically.
|
462 |
+
*
|
463 |
+
* The resolver will use the v4 local address when making requests to IPv4 DNS
|
464 |
+
* servers, and the v6 local address when making requests to IPv6 DNS servers.
|
465 |
+
* The `rrtype` of resolution requests has no impact on the local address used.
|
466 |
+
* @since v15.1.0, v14.17.0
|
467 |
+
* @param [ipv4='0.0.0.0'] A string representation of an IPv4 address.
|
468 |
+
* @param [ipv6='::0'] A string representation of an IPv6 address.
|
469 |
+
*/
|
470 |
+
setLocalAddress(ipv4?: string, ipv6?: string): void;
|
471 |
+
setServers: typeof setServers;
|
472 |
+
}
|
473 |
+
}
|
474 |
+
declare module "node:dns/promises" {
|
475 |
+
export * from "dns/promises";
|
476 |
+
}
|
clone/node_modules/@types/node/dom-events.d.ts
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export {}; // Don't export anything!
|
2 |
+
|
3 |
+
//// DOM-like Events
|
4 |
+
// NB: The Event / EventTarget / EventListener implementations below were copied
|
5 |
+
// from lib.dom.d.ts, then edited to reflect Node's documentation at
|
6 |
+
// https://nodejs.org/api/events.html#class-eventtarget.
|
7 |
+
// Please read that link to understand important implementation differences.
|
8 |
+
|
9 |
+
// This conditional type will be the existing global Event in a browser, or
|
10 |
+
// the copy below in a Node environment.
|
11 |
+
type __Event = typeof globalThis extends { onmessage: any; Event: any } ? {}
|
12 |
+
: {
|
13 |
+
/** This is not used in Node.js and is provided purely for completeness. */
|
14 |
+
readonly bubbles: boolean;
|
15 |
+
/** Alias for event.stopPropagation(). This is not used in Node.js and is provided purely for completeness. */
|
16 |
+
cancelBubble: () => void;
|
17 |
+
/** True if the event was created with the cancelable option */
|
18 |
+
readonly cancelable: boolean;
|
19 |
+
/** This is not used in Node.js and is provided purely for completeness. */
|
20 |
+
readonly composed: boolean;
|
21 |
+
/** 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. */
|
22 |
+
composedPath(): [EventTarget?];
|
23 |
+
/** Alias for event.target. */
|
24 |
+
readonly currentTarget: EventTarget | null;
|
25 |
+
/** Is true if cancelable is true and event.preventDefault() has been called. */
|
26 |
+
readonly defaultPrevented: boolean;
|
27 |
+
/** This is not used in Node.js and is provided purely for completeness. */
|
28 |
+
readonly eventPhase: 0 | 2;
|
29 |
+
/** The `AbortSignal` "abort" event is emitted with `isTrusted` set to `true`. The value is `false` in all other cases. */
|
30 |
+
readonly isTrusted: boolean;
|
31 |
+
/** Sets the `defaultPrevented` property to `true` if `cancelable` is `true`. */
|
32 |
+
preventDefault(): void;
|
33 |
+
/** This is not used in Node.js and is provided purely for completeness. */
|
34 |
+
returnValue: boolean;
|
35 |
+
/** Alias for event.target. */
|
36 |
+
readonly srcElement: EventTarget | null;
|
37 |
+
/** Stops the invocation of event listeners after the current one completes. */
|
38 |
+
stopImmediatePropagation(): void;
|
39 |
+
/** This is not used in Node.js and is provided purely for completeness. */
|
40 |
+
stopPropagation(): void;
|
41 |
+
/** The `EventTarget` dispatching the event */
|
42 |
+
readonly target: EventTarget | null;
|
43 |
+
/** The millisecond timestamp when the Event object was created. */
|
44 |
+
readonly timeStamp: number;
|
45 |
+
/** Returns the type of event, e.g. "click", "hashchange", or "submit". */
|
46 |
+
readonly type: string;
|
47 |
+
};
|
48 |
+
|
49 |
+
// See comment above explaining conditional type
|
50 |
+
type __EventTarget = typeof globalThis extends { onmessage: any; EventTarget: any } ? {}
|
51 |
+
: {
|
52 |
+
/**
|
53 |
+
* Adds a new handler for the `type` event. Any given `listener` is added only once per `type` and per `capture` option value.
|
54 |
+
*
|
55 |
+
* If the `once` option is true, the `listener` is removed after the next time a `type` event is dispatched.
|
56 |
+
*
|
57 |
+
* The `capture` option is not used by Node.js in any functional way other than tracking registered event listeners per the `EventTarget` specification.
|
58 |
+
* Specifically, the `capture` option is used as part of the key when registering a `listener`.
|
59 |
+
* Any individual `listener` may be added once with `capture = false`, and once with `capture = true`.
|
60 |
+
*/
|
61 |
+
addEventListener(
|
62 |
+
type: string,
|
63 |
+
listener: EventListener | EventListenerObject,
|
64 |
+
options?: AddEventListenerOptions | boolean,
|
65 |
+
): void;
|
66 |
+
/** Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. */
|
67 |
+
dispatchEvent(event: Event): boolean;
|
68 |
+
/** Removes the event listener in target's event listener list with the same type, callback, and options. */
|
69 |
+
removeEventListener(
|
70 |
+
type: string,
|
71 |
+
listener: EventListener | EventListenerObject,
|
72 |
+
options?: EventListenerOptions | boolean,
|
73 |
+
): void;
|
74 |
+
};
|
75 |
+
|
76 |
+
interface EventInit {
|
77 |
+
bubbles?: boolean;
|
78 |
+
cancelable?: boolean;
|
79 |
+
composed?: boolean;
|
80 |
+
}
|
81 |
+
|
82 |
+
interface EventListenerOptions {
|
83 |
+
/** Not directly used by Node.js. Added for API completeness. Default: `false`. */
|
84 |
+
capture?: boolean;
|
85 |
+
}
|
86 |
+
|
87 |
+
interface AddEventListenerOptions extends EventListenerOptions {
|
88 |
+
/** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */
|
89 |
+
once?: boolean;
|
90 |
+
/** When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. Default: false. */
|
91 |
+
passive?: boolean;
|
92 |
+
/** The listener will be removed when the given AbortSignal object's `abort()` method is called. */
|
93 |
+
signal?: AbortSignal;
|
94 |
+
}
|
95 |
+
|
96 |
+
interface EventListener {
|
97 |
+
(evt: Event): void;
|
98 |
+
}
|
99 |
+
|
100 |
+
interface EventListenerObject {
|
101 |
+
handleEvent(object: Event): void;
|
102 |
+
}
|
103 |
+
|
104 |
+
import {} from "events"; // Make this an ambient declaration
|
105 |
+
declare global {
|
106 |
+
/** An event which takes place in the DOM. */
|
107 |
+
interface Event extends __Event {}
|
108 |
+
var Event: typeof globalThis extends { onmessage: any; Event: infer T } ? T
|
109 |
+
: {
|
110 |
+
prototype: __Event;
|
111 |
+
new(type: string, eventInitDict?: EventInit): __Event;
|
112 |
+
};
|
113 |
+
|
114 |
+
/**
|
115 |
+
* EventTarget is a DOM interface implemented by objects that can
|
116 |
+
* receive events and may have listeners for them.
|
117 |
+
*/
|
118 |
+
interface EventTarget extends __EventTarget {}
|
119 |
+
var EventTarget: typeof globalThis extends { onmessage: any; EventTarget: infer T } ? T
|
120 |
+
: {
|
121 |
+
prototype: __EventTarget;
|
122 |
+
new(): __EventTarget;
|
123 |
+
};
|
124 |
+
}
|
clone/node_modules/@types/node/domain.d.ts
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* **This module is pending deprecation.** Once a replacement API has been
|
3 |
+
* finalized, this module will be fully deprecated. Most developers should
|
4 |
+
* **not** have cause to use this module. Users who absolutely must have
|
5 |
+
* the functionality that domains provide may rely on it for the time being
|
6 |
+
* but should expect to have to migrate to a different solution
|
7 |
+
* in the future.
|
8 |
+
*
|
9 |
+
* Domains provide a way to handle multiple different IO operations as a
|
10 |
+
* single group. If any of the event emitters or callbacks registered to a
|
11 |
+
* domain emit an `'error'` event, or throw an error, then the domain object
|
12 |
+
* will be notified, rather than losing the context of the error in the `process.on('uncaughtException')` handler, or causing the program to
|
13 |
+
* exit immediately with an error code.
|
14 |
+
* @deprecated Since v1.4.2 - Deprecated
|
15 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/domain.js)
|
16 |
+
*/
|
17 |
+
declare module "domain" {
|
18 |
+
import EventEmitter = require("node:events");
|
19 |
+
/**
|
20 |
+
* The `Domain` class encapsulates the functionality of routing errors and
|
21 |
+
* uncaught exceptions to the active `Domain` object.
|
22 |
+
*
|
23 |
+
* To handle the errors that it catches, listen to its `'error'` event.
|
24 |
+
*/
|
25 |
+
class Domain extends EventEmitter {
|
26 |
+
/**
|
27 |
+
* An array of timers and event emitters that have been explicitly added
|
28 |
+
* to the domain.
|
29 |
+
*/
|
30 |
+
members: Array<EventEmitter | NodeJS.Timer>;
|
31 |
+
/**
|
32 |
+
* The `enter()` method is plumbing used by the `run()`, `bind()`, and `intercept()` methods to set the active domain. It sets `domain.active` and `process.domain` to the domain, and implicitly
|
33 |
+
* pushes the domain onto the domain
|
34 |
+
* stack managed by the domain module (see {@link exit} for details on the
|
35 |
+
* domain stack). The call to `enter()` delimits the beginning of a chain of
|
36 |
+
* asynchronous calls and I/O operations bound to a domain.
|
37 |
+
*
|
38 |
+
* Calling `enter()` changes only the active domain, and does not alter the domain
|
39 |
+
* itself. `enter()` and `exit()` can be called an arbitrary number of times on a
|
40 |
+
* single domain.
|
41 |
+
*/
|
42 |
+
enter(): void;
|
43 |
+
/**
|
44 |
+
* The `exit()` method exits the current domain, popping it off the domain stack.
|
45 |
+
* Any time execution is going to switch to the context of a different chain of
|
46 |
+
* asynchronous calls, it's important to ensure that the current domain is exited.
|
47 |
+
* The call to `exit()` delimits either the end of or an interruption to the chain
|
48 |
+
* of asynchronous calls and I/O operations bound to a domain.
|
49 |
+
*
|
50 |
+
* If there are multiple, nested domains bound to the current execution context, `exit()` will exit any domains nested within this domain.
|
51 |
+
*
|
52 |
+
* Calling `exit()` changes only the active domain, and does not alter the domain
|
53 |
+
* itself. `enter()` and `exit()` can be called an arbitrary number of times on a
|
54 |
+
* single domain.
|
55 |
+
*/
|
56 |
+
exit(): void;
|
57 |
+
/**
|
58 |
+
* Run the supplied function in the context of the domain, implicitly
|
59 |
+
* binding all event emitters, timers, and low-level requests that are
|
60 |
+
* created in that context. Optionally, arguments can be passed to
|
61 |
+
* the function.
|
62 |
+
*
|
63 |
+
* This is the most basic way to use a domain.
|
64 |
+
*
|
65 |
+
* ```js
|
66 |
+
* import domain from 'node:domain';
|
67 |
+
* import fs from 'node:fs';
|
68 |
+
* const d = domain.create();
|
69 |
+
* d.on('error', (er) => {
|
70 |
+
* console.error('Caught error!', er);
|
71 |
+
* });
|
72 |
+
* d.run(() => {
|
73 |
+
* process.nextTick(() => {
|
74 |
+
* setTimeout(() => { // Simulating some various async stuff
|
75 |
+
* fs.open('non-existent file', 'r', (er, fd) => {
|
76 |
+
* if (er) throw er;
|
77 |
+
* // proceed...
|
78 |
+
* });
|
79 |
+
* }, 100);
|
80 |
+
* });
|
81 |
+
* });
|
82 |
+
* ```
|
83 |
+
*
|
84 |
+
* In this example, the `d.on('error')` handler will be triggered, rather
|
85 |
+
* than crashing the program.
|
86 |
+
*/
|
87 |
+
run<T>(fn: (...args: any[]) => T, ...args: any[]): T;
|
88 |
+
/**
|
89 |
+
* Explicitly adds an emitter to the domain. If any event handlers called by
|
90 |
+
* the emitter throw an error, or if the emitter emits an `'error'` event, it
|
91 |
+
* will be routed to the domain's `'error'` event, just like with implicit
|
92 |
+
* binding.
|
93 |
+
*
|
94 |
+
* This also works with timers that are returned from `setInterval()` and `setTimeout()`. If their callback function throws, it will be caught by
|
95 |
+
* the domain `'error'` handler.
|
96 |
+
*
|
97 |
+
* If the Timer or `EventEmitter` was already bound to a domain, it is removed
|
98 |
+
* from that one, and bound to this one instead.
|
99 |
+
* @param emitter emitter or timer to be added to the domain
|
100 |
+
*/
|
101 |
+
add(emitter: EventEmitter | NodeJS.Timer): void;
|
102 |
+
/**
|
103 |
+
* The opposite of {@link add}. Removes domain handling from the
|
104 |
+
* specified emitter.
|
105 |
+
* @param emitter emitter or timer to be removed from the domain
|
106 |
+
*/
|
107 |
+
remove(emitter: EventEmitter | NodeJS.Timer): void;
|
108 |
+
/**
|
109 |
+
* The returned function will be a wrapper around the supplied callback
|
110 |
+
* function. When the returned function is called, any errors that are
|
111 |
+
* thrown will be routed to the domain's `'error'` event.
|
112 |
+
*
|
113 |
+
* ```js
|
114 |
+
* const d = domain.create();
|
115 |
+
*
|
116 |
+
* function readSomeFile(filename, cb) {
|
117 |
+
* fs.readFile(filename, 'utf8', d.bind((er, data) => {
|
118 |
+
* // If this throws, it will also be passed to the domain.
|
119 |
+
* return cb(er, data ? JSON.parse(data) : null);
|
120 |
+
* }));
|
121 |
+
* }
|
122 |
+
*
|
123 |
+
* d.on('error', (er) => {
|
124 |
+
* // An error occurred somewhere. If we throw it now, it will crash the program
|
125 |
+
* // with the normal line number and stack message.
|
126 |
+
* });
|
127 |
+
* ```
|
128 |
+
* @param callback The callback function
|
129 |
+
* @return The bound function
|
130 |
+
*/
|
131 |
+
bind<T extends Function>(callback: T): T;
|
132 |
+
/**
|
133 |
+
* This method is almost identical to {@link bind}. However, in
|
134 |
+
* addition to catching thrown errors, it will also intercept `Error` objects sent as the first argument to the function.
|
135 |
+
*
|
136 |
+
* In this way, the common `if (err) return callback(err);` pattern can be replaced
|
137 |
+
* with a single error handler in a single place.
|
138 |
+
*
|
139 |
+
* ```js
|
140 |
+
* const d = domain.create();
|
141 |
+
*
|
142 |
+
* function readSomeFile(filename, cb) {
|
143 |
+
* fs.readFile(filename, 'utf8', d.intercept((data) => {
|
144 |
+
* // Note, the first argument is never passed to the
|
145 |
+
* // callback since it is assumed to be the 'Error' argument
|
146 |
+
* // and thus intercepted by the domain.
|
147 |
+
*
|
148 |
+
* // If this throws, it will also be passed to the domain
|
149 |
+
* // so the error-handling logic can be moved to the 'error'
|
150 |
+
* // event on the domain instead of being repeated throughout
|
151 |
+
* // the program.
|
152 |
+
* return cb(null, JSON.parse(data));
|
153 |
+
* }));
|
154 |
+
* }
|
155 |
+
*
|
156 |
+
* d.on('error', (er) => {
|
157 |
+
* // An error occurred somewhere. If we throw it now, it will crash the program
|
158 |
+
* // with the normal line number and stack message.
|
159 |
+
* });
|
160 |
+
* ```
|
161 |
+
* @param callback The callback function
|
162 |
+
* @return The intercepted function
|
163 |
+
*/
|
164 |
+
intercept<T extends Function>(callback: T): T;
|
165 |
+
}
|
166 |
+
function create(): Domain;
|
167 |
+
}
|
168 |
+
declare module "node:domain" {
|
169 |
+
export * from "domain";
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Much of the Node.js core API is built around an idiomatic asynchronous
|
3 |
+
* event-driven architecture in which certain kinds of objects (called "emitters")
|
4 |
+
* emit named events that cause `Function` objects ("listeners") to be called.
|
5 |
+
*
|
6 |
+
* For instance: a `net.Server` object emits an event each time a peer
|
7 |
+
* connects to it; a `fs.ReadStream` emits an event when the file is opened;
|
8 |
+
* a `stream` emits an event whenever data is available to be read.
|
9 |
+
*
|
10 |
+
* All objects that emit events are instances of the `EventEmitter` class. These
|
11 |
+
* objects expose an `eventEmitter.on()` function that allows one or more
|
12 |
+
* functions to be attached to named events emitted by the object. Typically,
|
13 |
+
* event names are camel-cased strings but any valid JavaScript property key
|
14 |
+
* can be used.
|
15 |
+
*
|
16 |
+
* When the `EventEmitter` object emits an event, all of the functions attached
|
17 |
+
* to that specific event are called _synchronously_. Any values returned by the
|
18 |
+
* called listeners are _ignored_ and discarded.
|
19 |
+
*
|
20 |
+
* The following example shows a simple `EventEmitter` instance with a single
|
21 |
+
* listener. The `eventEmitter.on()` method is used to register listeners, while
|
22 |
+
* the `eventEmitter.emit()` method is used to trigger the event.
|
23 |
+
*
|
24 |
+
* ```js
|
25 |
+
* import { EventEmitter } from 'node:events';
|
26 |
+
*
|
27 |
+
* class MyEmitter extends EventEmitter {}
|
28 |
+
*
|
29 |
+
* const myEmitter = new MyEmitter();
|
30 |
+
* myEmitter.on('event', () => {
|
31 |
+
* console.log('an event occurred!');
|
32 |
+
* });
|
33 |
+
* myEmitter.emit('event');
|
34 |
+
* ```
|
35 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/events.js)
|
36 |
+
*/
|
37 |
+
declare module "events" {
|
38 |
+
import { AsyncResource, AsyncResourceOptions } from "node:async_hooks";
|
39 |
+
// NOTE: This class is in the docs but is **not actually exported** by Node.
|
40 |
+
// If https://github.com/nodejs/node/issues/39903 gets resolved and Node
|
41 |
+
// actually starts exporting the class, uncomment below.
|
42 |
+
// import { EventListener, EventListenerObject } from '__dom-events';
|
43 |
+
// /** The NodeEventTarget is a Node.js-specific extension to EventTarget that emulates a subset of the EventEmitter API. */
|
44 |
+
// interface NodeEventTarget extends EventTarget {
|
45 |
+
// /**
|
46 |
+
// * Node.js-specific extension to the `EventTarget` class that emulates the equivalent `EventEmitter` API.
|
47 |
+
// * The only difference between `addListener()` and `addEventListener()` is that addListener() will return a reference to the EventTarget.
|
48 |
+
// */
|
49 |
+
// addListener(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
|
50 |
+
// /** Node.js-specific extension to the `EventTarget` class that returns an array of event `type` names for which event listeners are registered. */
|
51 |
+
// eventNames(): string[];
|
52 |
+
// /** Node.js-specific extension to the `EventTarget` class that returns the number of event listeners registered for the `type`. */
|
53 |
+
// listenerCount(type: string): number;
|
54 |
+
// /** Node.js-specific alias for `eventTarget.removeListener()`. */
|
55 |
+
// off(type: string, listener: EventListener | EventListenerObject): this;
|
56 |
+
// /** Node.js-specific alias for `eventTarget.addListener()`. */
|
57 |
+
// on(type: string, listener: EventListener | EventListenerObject, options?: { once: boolean }): this;
|
58 |
+
// /** Node.js-specific extension to the `EventTarget` class that adds a `once` listener for the given event `type`. This is equivalent to calling `on` with the `once` option set to `true`. */
|
59 |
+
// once(type: string, listener: EventListener | EventListenerObject): this;
|
60 |
+
// /**
|
61 |
+
// * Node.js-specific extension to the `EventTarget` class.
|
62 |
+
// * If `type` is specified, removes all registered listeners for `type`,
|
63 |
+
// * otherwise removes all registered listeners.
|
64 |
+
// */
|
65 |
+
// removeAllListeners(type: string): this;
|
66 |
+
// /**
|
67 |
+
// * Node.js-specific extension to the `EventTarget` class that removes the listener for the given `type`.
|
68 |
+
// * The only difference between `removeListener()` and `removeEventListener()` is that `removeListener()` will return a reference to the `EventTarget`.
|
69 |
+
// */
|
70 |
+
// removeListener(type: string, listener: EventListener | EventListenerObject): this;
|
71 |
+
// }
|
72 |
+
interface EventEmitterOptions {
|
73 |
+
/**
|
74 |
+
* Enables automatic capturing of promise rejection.
|
75 |
+
*/
|
76 |
+
captureRejections?: boolean | undefined;
|
77 |
+
}
|
78 |
+
interface StaticEventEmitterOptions {
|
79 |
+
/**
|
80 |
+
* Can be used to cancel awaiting events.
|
81 |
+
*/
|
82 |
+
signal?: AbortSignal | undefined;
|
83 |
+
}
|
84 |
+
interface StaticEventEmitterIteratorOptions extends StaticEventEmitterOptions {
|
85 |
+
/**
|
86 |
+
* Names of events that will end the iteration.
|
87 |
+
*/
|
88 |
+
close?: string[] | undefined;
|
89 |
+
/**
|
90 |
+
* The high watermark. The emitter is paused every time the size of events being buffered is higher than it.
|
91 |
+
* Supported only on emitters implementing `pause()` and `resume()` methods.
|
92 |
+
* @default Number.MAX_SAFE_INTEGER
|
93 |
+
*/
|
94 |
+
highWaterMark?: number | undefined;
|
95 |
+
/**
|
96 |
+
* The low watermark. The emitter is resumed every time the size of events being buffered is lower than it.
|
97 |
+
* Supported only on emitters implementing `pause()` and `resume()` methods.
|
98 |
+
* @default 1
|
99 |
+
*/
|
100 |
+
lowWaterMark?: number | undefined;
|
101 |
+
}
|
102 |
+
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> extends NodeJS.EventEmitter<T> {}
|
103 |
+
type EventMap<T> = Record<keyof T, any[]> | DefaultEventMap;
|
104 |
+
type DefaultEventMap = [never];
|
105 |
+
type AnyRest = [...args: any[]];
|
106 |
+
type Args<K, T> = T extends DefaultEventMap ? AnyRest : (
|
107 |
+
K extends keyof T ? T[K] : never
|
108 |
+
);
|
109 |
+
type Key<K, T> = T extends DefaultEventMap ? string | symbol : K | keyof T;
|
110 |
+
type Key2<K, T> = T extends DefaultEventMap ? string | symbol : K & keyof T;
|
111 |
+
type Listener<K, T, F> = T extends DefaultEventMap ? F : (
|
112 |
+
K extends keyof T ? (
|
113 |
+
T[K] extends unknown[] ? (...args: T[K]) => void : never
|
114 |
+
)
|
115 |
+
: never
|
116 |
+
);
|
117 |
+
type Listener1<K, T> = Listener<K, T, (...args: any[]) => void>;
|
118 |
+
type Listener2<K, T> = Listener<K, T, Function>;
|
119 |
+
|
120 |
+
/**
|
121 |
+
* The `EventEmitter` class is defined and exposed by the `node:events` module:
|
122 |
+
*
|
123 |
+
* ```js
|
124 |
+
* import { EventEmitter } from 'node:events';
|
125 |
+
* ```
|
126 |
+
*
|
127 |
+
* All `EventEmitter`s emit the event `'newListener'` when new listeners are
|
128 |
+
* added and `'removeListener'` when existing listeners are removed.
|
129 |
+
*
|
130 |
+
* It supports the following option:
|
131 |
+
* @since v0.1.26
|
132 |
+
*/
|
133 |
+
class EventEmitter<T extends EventMap<T> = DefaultEventMap> {
|
134 |
+
constructor(options?: EventEmitterOptions);
|
135 |
+
|
136 |
+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
|
140 |
+
* event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
|
141 |
+
* The `Promise` will resolve with an array of all the arguments emitted to the
|
142 |
+
* given event.
|
143 |
+
*
|
144 |
+
* This method is intentionally generic and works with the web platform [EventTarget](https://dom.spec.whatwg.org/#interface-eventtarget) interface, which has no special`'error'` event
|
145 |
+
* semantics and does not listen to the `'error'` event.
|
146 |
+
*
|
147 |
+
* ```js
|
148 |
+
* import { once, EventEmitter } from 'node:events';
|
149 |
+
* import process from 'node:process';
|
150 |
+
*
|
151 |
+
* const ee = new EventEmitter();
|
152 |
+
*
|
153 |
+
* process.nextTick(() => {
|
154 |
+
* ee.emit('myevent', 42);
|
155 |
+
* });
|
156 |
+
*
|
157 |
+
* const [value] = await once(ee, 'myevent');
|
158 |
+
* console.log(value);
|
159 |
+
*
|
160 |
+
* const err = new Error('kaboom');
|
161 |
+
* process.nextTick(() => {
|
162 |
+
* ee.emit('error', err);
|
163 |
+
* });
|
164 |
+
*
|
165 |
+
* try {
|
166 |
+
* await once(ee, 'myevent');
|
167 |
+
* } catch (err) {
|
168 |
+
* console.error('error happened', err);
|
169 |
+
* }
|
170 |
+
* ```
|
171 |
+
*
|
172 |
+
* The special handling of the `'error'` event is only used when `events.once()` is used to wait for another event. If `events.once()` is used to wait for the
|
173 |
+
* '`error'` event itself, then it is treated as any other kind of event without
|
174 |
+
* special handling:
|
175 |
+
*
|
176 |
+
* ```js
|
177 |
+
* import { EventEmitter, once } from 'node:events';
|
178 |
+
*
|
179 |
+
* const ee = new EventEmitter();
|
180 |
+
*
|
181 |
+
* once(ee, 'error')
|
182 |
+
* .then(([err]) => console.log('ok', err.message))
|
183 |
+
* .catch((err) => console.error('error', err.message));
|
184 |
+
*
|
185 |
+
* ee.emit('error', new Error('boom'));
|
186 |
+
*
|
187 |
+
* // Prints: ok boom
|
188 |
+
* ```
|
189 |
+
*
|
190 |
+
* An `AbortSignal` can be used to cancel waiting for the event:
|
191 |
+
*
|
192 |
+
* ```js
|
193 |
+
* import { EventEmitter, once } from 'node:events';
|
194 |
+
*
|
195 |
+
* const ee = new EventEmitter();
|
196 |
+
* const ac = new AbortController();
|
197 |
+
*
|
198 |
+
* async function foo(emitter, event, signal) {
|
199 |
+
* try {
|
200 |
+
* await once(emitter, event, { signal });
|
201 |
+
* console.log('event emitted!');
|
202 |
+
* } catch (error) {
|
203 |
+
* if (error.name === 'AbortError') {
|
204 |
+
* console.error('Waiting for the event was canceled!');
|
205 |
+
* } else {
|
206 |
+
* console.error('There was an error', error.message);
|
207 |
+
* }
|
208 |
+
* }
|
209 |
+
* }
|
210 |
+
*
|
211 |
+
* foo(ee, 'foo', ac.signal);
|
212 |
+
* ac.abort(); // Abort waiting for the event
|
213 |
+
* ee.emit('foo'); // Prints: Waiting for the event was canceled!
|
214 |
+
* ```
|
215 |
+
* @since v11.13.0, v10.16.0
|
216 |
+
*/
|
217 |
+
static once(
|
218 |
+
emitter: NodeJS.EventEmitter,
|
219 |
+
eventName: string | symbol,
|
220 |
+
options?: StaticEventEmitterOptions,
|
221 |
+
): Promise<any[]>;
|
222 |
+
static once(emitter: EventTarget, eventName: string, options?: StaticEventEmitterOptions): Promise<any[]>;
|
223 |
+
/**
|
224 |
+
* ```js
|
225 |
+
* import { on, EventEmitter } from 'node:events';
|
226 |
+
* import process from 'node:process';
|
227 |
+
*
|
228 |
+
* const ee = new EventEmitter();
|
229 |
+
*
|
230 |
+
* // Emit later on
|
231 |
+
* process.nextTick(() => {
|
232 |
+
* ee.emit('foo', 'bar');
|
233 |
+
* ee.emit('foo', 42);
|
234 |
+
* });
|
235 |
+
*
|
236 |
+
* for await (const event of on(ee, 'foo')) {
|
237 |
+
* // The execution of this inner block is synchronous and it
|
238 |
+
* // processes one event at a time (even with await). Do not use
|
239 |
+
* // if concurrent execution is required.
|
240 |
+
* console.log(event); // prints ['bar'] [42]
|
241 |
+
* }
|
242 |
+
* // Unreachable here
|
243 |
+
* ```
|
244 |
+
*
|
245 |
+
* Returns an `AsyncIterator` that iterates `eventName` events. It will throw
|
246 |
+
* if the `EventEmitter` emits `'error'`. It removes all listeners when
|
247 |
+
* exiting the loop. The `value` returned by each iteration is an array
|
248 |
+
* composed of the emitted event arguments.
|
249 |
+
*
|
250 |
+
* An `AbortSignal` can be used to cancel waiting on events:
|
251 |
+
*
|
252 |
+
* ```js
|
253 |
+
* import { on, EventEmitter } from 'node:events';
|
254 |
+
* import process from 'node:process';
|
255 |
+
*
|
256 |
+
* const ac = new AbortController();
|
257 |
+
*
|
258 |
+
* (async () => {
|
259 |
+
* const ee = new EventEmitter();
|
260 |
+
*
|
261 |
+
* // Emit later on
|
262 |
+
* process.nextTick(() => {
|
263 |
+
* ee.emit('foo', 'bar');
|
264 |
+
* ee.emit('foo', 42);
|
265 |
+
* });
|
266 |
+
*
|
267 |
+
* for await (const event of on(ee, 'foo', { signal: ac.signal })) {
|
268 |
+
* // The execution of this inner block is synchronous and it
|
269 |
+
* // processes one event at a time (even with await). Do not use
|
270 |
+
* // if concurrent execution is required.
|
271 |
+
* console.log(event); // prints ['bar'] [42]
|
272 |
+
* }
|
273 |
+
* // Unreachable here
|
274 |
+
* })();
|
275 |
+
*
|
276 |
+
* process.nextTick(() => ac.abort());
|
277 |
+
* ```
|
278 |
+
*
|
279 |
+
* Use the `close` option to specify an array of event names that will end the iteration:
|
280 |
+
*
|
281 |
+
* ```js
|
282 |
+
* import { on, EventEmitter } from 'node:events';
|
283 |
+
* import process from 'node:process';
|
284 |
+
*
|
285 |
+
* const ee = new EventEmitter();
|
286 |
+
*
|
287 |
+
* // Emit later on
|
288 |
+
* process.nextTick(() => {
|
289 |
+
* ee.emit('foo', 'bar');
|
290 |
+
* ee.emit('foo', 42);
|
291 |
+
* ee.emit('close');
|
292 |
+
* });
|
293 |
+
*
|
294 |
+
* for await (const event of on(ee, 'foo', { close: ['close'] })) {
|
295 |
+
* console.log(event); // prints ['bar'] [42]
|
296 |
+
* }
|
297 |
+
* // the loop will exit after 'close' is emitted
|
298 |
+
* console.log('done'); // prints 'done'
|
299 |
+
* ```
|
300 |
+
* @since v13.6.0, v12.16.0
|
301 |
+
* @return An `AsyncIterator` that iterates `eventName` events emitted by the `emitter`
|
302 |
+
*/
|
303 |
+
static on(
|
304 |
+
emitter: NodeJS.EventEmitter,
|
305 |
+
eventName: string | symbol,
|
306 |
+
options?: StaticEventEmitterIteratorOptions,
|
307 |
+
): NodeJS.AsyncIterator<any[]>;
|
308 |
+
static on(
|
309 |
+
emitter: EventTarget,
|
310 |
+
eventName: string,
|
311 |
+
options?: StaticEventEmitterIteratorOptions,
|
312 |
+
): NodeJS.AsyncIterator<any[]>;
|
313 |
+
/**
|
314 |
+
* A class method that returns the number of listeners for the given `eventName` registered on the given `emitter`.
|
315 |
+
*
|
316 |
+
* ```js
|
317 |
+
* import { EventEmitter, listenerCount } from 'node:events';
|
318 |
+
*
|
319 |
+
* const myEmitter = new EventEmitter();
|
320 |
+
* myEmitter.on('event', () => {});
|
321 |
+
* myEmitter.on('event', () => {});
|
322 |
+
* console.log(listenerCount(myEmitter, 'event'));
|
323 |
+
* // Prints: 2
|
324 |
+
* ```
|
325 |
+
* @since v0.9.12
|
326 |
+
* @deprecated Since v3.2.0 - Use `listenerCount` instead.
|
327 |
+
* @param emitter The emitter to query
|
328 |
+
* @param eventName The event name
|
329 |
+
*/
|
330 |
+
static listenerCount(emitter: NodeJS.EventEmitter, eventName: string | symbol): number;
|
331 |
+
/**
|
332 |
+
* Returns a copy of the array of listeners for the event named `eventName`.
|
333 |
+
*
|
334 |
+
* For `EventEmitter`s this behaves exactly the same as calling `.listeners` on
|
335 |
+
* the emitter.
|
336 |
+
*
|
337 |
+
* For `EventTarget`s this is the only way to get the event listeners for the
|
338 |
+
* event target. This is useful for debugging and diagnostic purposes.
|
339 |
+
*
|
340 |
+
* ```js
|
341 |
+
* import { getEventListeners, EventEmitter } from 'node:events';
|
342 |
+
*
|
343 |
+
* {
|
344 |
+
* const ee = new EventEmitter();
|
345 |
+
* const listener = () => console.log('Events are fun');
|
346 |
+
* ee.on('foo', listener);
|
347 |
+
* console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
|
348 |
+
* }
|
349 |
+
* {
|
350 |
+
* const et = new EventTarget();
|
351 |
+
* const listener = () => console.log('Events are fun');
|
352 |
+
* et.addEventListener('foo', listener);
|
353 |
+
* console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
|
354 |
+
* }
|
355 |
+
* ```
|
356 |
+
* @since v15.2.0, v14.17.0
|
357 |
+
*/
|
358 |
+
static getEventListeners(emitter: EventTarget | NodeJS.EventEmitter, name: string | symbol): Function[];
|
359 |
+
/**
|
360 |
+
* Returns the currently set max amount of listeners.
|
361 |
+
*
|
362 |
+
* For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on
|
363 |
+
* the emitter.
|
364 |
+
*
|
365 |
+
* For `EventTarget`s this is the only way to get the max event listeners for the
|
366 |
+
* event target. If the number of event handlers on a single EventTarget exceeds
|
367 |
+
* the max set, the EventTarget will print a warning.
|
368 |
+
*
|
369 |
+
* ```js
|
370 |
+
* import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
|
371 |
+
*
|
372 |
+
* {
|
373 |
+
* const ee = new EventEmitter();
|
374 |
+
* console.log(getMaxListeners(ee)); // 10
|
375 |
+
* setMaxListeners(11, ee);
|
376 |
+
* console.log(getMaxListeners(ee)); // 11
|
377 |
+
* }
|
378 |
+
* {
|
379 |
+
* const et = new EventTarget();
|
380 |
+
* console.log(getMaxListeners(et)); // 10
|
381 |
+
* setMaxListeners(11, et);
|
382 |
+
* console.log(getMaxListeners(et)); // 11
|
383 |
+
* }
|
384 |
+
* ```
|
385 |
+
* @since v19.9.0
|
386 |
+
*/
|
387 |
+
static getMaxListeners(emitter: EventTarget | NodeJS.EventEmitter): number;
|
388 |
+
/**
|
389 |
+
* ```js
|
390 |
+
* import { setMaxListeners, EventEmitter } from 'node:events';
|
391 |
+
*
|
392 |
+
* const target = new EventTarget();
|
393 |
+
* const emitter = new EventEmitter();
|
394 |
+
*
|
395 |
+
* setMaxListeners(5, target, emitter);
|
396 |
+
* ```
|
397 |
+
* @since v15.4.0
|
398 |
+
* @param n A non-negative number. The maximum number of listeners per `EventTarget` event.
|
399 |
+
* @param eventTargets Zero or more {EventTarget} or {EventEmitter} instances. If none are specified, `n` is set as the default max for all newly created {EventTarget} and {EventEmitter}
|
400 |
+
* objects.
|
401 |
+
*/
|
402 |
+
static setMaxListeners(n?: number, ...eventTargets: Array<EventTarget | NodeJS.EventEmitter>): void;
|
403 |
+
/**
|
404 |
+
* Listens once to the `abort` event on the provided `signal`.
|
405 |
+
*
|
406 |
+
* Listening to the `abort` event on abort signals is unsafe and may
|
407 |
+
* lead to resource leaks since another third party with the signal can
|
408 |
+
* call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
|
409 |
+
* this since it would violate the web standard. Additionally, the original
|
410 |
+
* API makes it easy to forget to remove listeners.
|
411 |
+
*
|
412 |
+
* This API allows safely using `AbortSignal`s in Node.js APIs by solving these
|
413 |
+
* two issues by listening to the event such that `stopImmediatePropagation` does
|
414 |
+
* not prevent the listener from running.
|
415 |
+
*
|
416 |
+
* Returns a disposable so that it may be unsubscribed from more easily.
|
417 |
+
*
|
418 |
+
* ```js
|
419 |
+
* import { addAbortListener } from 'node:events';
|
420 |
+
*
|
421 |
+
* function example(signal) {
|
422 |
+
* let disposable;
|
423 |
+
* try {
|
424 |
+
* signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
|
425 |
+
* disposable = addAbortListener(signal, (e) => {
|
426 |
+
* // Do something when signal is aborted.
|
427 |
+
* });
|
428 |
+
* } finally {
|
429 |
+
* disposable?.[Symbol.dispose]();
|
430 |
+
* }
|
431 |
+
* }
|
432 |
+
* ```
|
433 |
+
* @since v20.5.0
|
434 |
+
* @experimental
|
435 |
+
* @return Disposable that removes the `abort` listener.
|
436 |
+
*/
|
437 |
+
static addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
|
438 |
+
/**
|
439 |
+
* This symbol shall be used to install a listener for only monitoring `'error'` events. Listeners installed using this symbol are called before the regular `'error'` listeners are called.
|
440 |
+
*
|
441 |
+
* Installing a listener using this symbol does not change the behavior once an `'error'` event is emitted. Therefore, the process will still crash if no
|
442 |
+
* regular `'error'` listener is installed.
|
443 |
+
* @since v13.6.0, v12.17.0
|
444 |
+
*/
|
445 |
+
static readonly errorMonitor: unique symbol;
|
446 |
+
/**
|
447 |
+
* Value: `Symbol.for('nodejs.rejection')`
|
448 |
+
*
|
449 |
+
* See how to write a custom `rejection handler`.
|
450 |
+
* @since v13.4.0, v12.16.0
|
451 |
+
*/
|
452 |
+
static readonly captureRejectionSymbol: unique symbol;
|
453 |
+
/**
|
454 |
+
* Value: [boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
|
455 |
+
*
|
456 |
+
* Change the default `captureRejections` option on all new `EventEmitter` objects.
|
457 |
+
* @since v13.4.0, v12.16.0
|
458 |
+
*/
|
459 |
+
static captureRejections: boolean;
|
460 |
+
/**
|
461 |
+
* By default, a maximum of `10` listeners can be registered for any single
|
462 |
+
* event. This limit can be changed for individual `EventEmitter` instances
|
463 |
+
* using the `emitter.setMaxListeners(n)` method. To change the default
|
464 |
+
* for _all_`EventEmitter` instances, the `events.defaultMaxListeners` property
|
465 |
+
* can be used. If this value is not a positive number, a `RangeError` is thrown.
|
466 |
+
*
|
467 |
+
* Take caution when setting the `events.defaultMaxListeners` because the
|
468 |
+
* change affects _all_ `EventEmitter` instances, including those created before
|
469 |
+
* the change is made. However, calling `emitter.setMaxListeners(n)` still has
|
470 |
+
* precedence over `events.defaultMaxListeners`.
|
471 |
+
*
|
472 |
+
* This is not a hard limit. The `EventEmitter` instance will allow
|
473 |
+
* more listeners to be added but will output a trace warning to stderr indicating
|
474 |
+
* that a "possible EventEmitter memory leak" has been detected. For any single
|
475 |
+
* `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()` methods can be used to
|
476 |
+
* temporarily avoid this warning:
|
477 |
+
*
|
478 |
+
* ```js
|
479 |
+
* import { EventEmitter } from 'node:events';
|
480 |
+
* const emitter = new EventEmitter();
|
481 |
+
* emitter.setMaxListeners(emitter.getMaxListeners() + 1);
|
482 |
+
* emitter.once('event', () => {
|
483 |
+
* // do stuff
|
484 |
+
* emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
|
485 |
+
* });
|
486 |
+
* ```
|
487 |
+
*
|
488 |
+
* The `--trace-warnings` command-line flag can be used to display the
|
489 |
+
* stack trace for such warnings.
|
490 |
+
*
|
491 |
+
* The emitted warning can be inspected with `process.on('warning')` and will
|
492 |
+
* have the additional `emitter`, `type`, and `count` properties, referring to
|
493 |
+
* the event emitter instance, the event's name and the number of attached
|
494 |
+
* listeners, respectively.
|
495 |
+
* Its `name` property is set to `'MaxListenersExceededWarning'`.
|
496 |
+
* @since v0.11.2
|
497 |
+
*/
|
498 |
+
static defaultMaxListeners: number;
|
499 |
+
}
|
500 |
+
import internal = require("node:events");
|
501 |
+
namespace EventEmitter {
|
502 |
+
// Should just be `export { EventEmitter }`, but that doesn't work in TypeScript 3.4
|
503 |
+
export { internal as EventEmitter };
|
504 |
+
export interface Abortable {
|
505 |
+
/**
|
506 |
+
* When provided the corresponding `AbortController` can be used to cancel an asynchronous action.
|
507 |
+
*/
|
508 |
+
signal?: AbortSignal | undefined;
|
509 |
+
}
|
510 |
+
|
511 |
+
export interface EventEmitterReferencingAsyncResource extends AsyncResource {
|
512 |
+
readonly eventEmitter: EventEmitterAsyncResource;
|
513 |
+
}
|
514 |
+
|
515 |
+
export interface EventEmitterAsyncResourceOptions extends AsyncResourceOptions, EventEmitterOptions {
|
516 |
+
/**
|
517 |
+
* The type of async event, this is required when instantiating `EventEmitterAsyncResource`
|
518 |
+
* directly rather than as a child class.
|
519 |
+
* @default new.target.name if instantiated as a child class.
|
520 |
+
*/
|
521 |
+
name?: string;
|
522 |
+
}
|
523 |
+
|
524 |
+
/**
|
525 |
+
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that
|
526 |
+
* require manual async tracking. Specifically, all events emitted by instances
|
527 |
+
* of `events.EventEmitterAsyncResource` will run within its `async context`.
|
528 |
+
*
|
529 |
+
* ```js
|
530 |
+
* import { EventEmitterAsyncResource, EventEmitter } from 'node:events';
|
531 |
+
* import { notStrictEqual, strictEqual } from 'node:assert';
|
532 |
+
* import { executionAsyncId, triggerAsyncId } from 'node:async_hooks';
|
533 |
+
*
|
534 |
+
* // Async tracking tooling will identify this as 'Q'.
|
535 |
+
* const ee1 = new EventEmitterAsyncResource({ name: 'Q' });
|
536 |
+
*
|
537 |
+
* // 'foo' listeners will run in the EventEmitters async context.
|
538 |
+
* ee1.on('foo', () => {
|
539 |
+
* strictEqual(executionAsyncId(), ee1.asyncId);
|
540 |
+
* strictEqual(triggerAsyncId(), ee1.triggerAsyncId);
|
541 |
+
* });
|
542 |
+
*
|
543 |
+
* const ee2 = new EventEmitter();
|
544 |
+
*
|
545 |
+
* // 'foo' listeners on ordinary EventEmitters that do not track async
|
546 |
+
* // context, however, run in the same async context as the emit().
|
547 |
+
* ee2.on('foo', () => {
|
548 |
+
* notStrictEqual(executionAsyncId(), ee2.asyncId);
|
549 |
+
* notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId);
|
550 |
+
* });
|
551 |
+
*
|
552 |
+
* Promise.resolve().then(() => {
|
553 |
+
* ee1.emit('foo');
|
554 |
+
* ee2.emit('foo');
|
555 |
+
* });
|
556 |
+
* ```
|
557 |
+
*
|
558 |
+
* The `EventEmitterAsyncResource` class has the same methods and takes the
|
559 |
+
* same options as `EventEmitter` and `AsyncResource` themselves.
|
560 |
+
* @since v17.4.0, v16.14.0
|
561 |
+
*/
|
562 |
+
export class EventEmitterAsyncResource extends EventEmitter {
|
563 |
+
/**
|
564 |
+
* @param options Only optional in child class.
|
565 |
+
*/
|
566 |
+
constructor(options?: EventEmitterAsyncResourceOptions);
|
567 |
+
/**
|
568 |
+
* Call all `destroy` hooks. This should only ever be called once. An error will
|
569 |
+
* be thrown if it is called more than once. This **must** be manually called. If
|
570 |
+
* the resource is left to be collected by the GC then the `destroy` hooks will
|
571 |
+
* never be called.
|
572 |
+
*/
|
573 |
+
emitDestroy(): void;
|
574 |
+
/**
|
575 |
+
* The unique `asyncId` assigned to the resource.
|
576 |
+
*/
|
577 |
+
readonly asyncId: number;
|
578 |
+
/**
|
579 |
+
* The same triggerAsyncId that is passed to the AsyncResource constructor.
|
580 |
+
*/
|
581 |
+
readonly triggerAsyncId: number;
|
582 |
+
/**
|
583 |
+
* The returned `AsyncResource` object has an additional `eventEmitter` property
|
584 |
+
* that provides a reference to this `EventEmitterAsyncResource`.
|
585 |
+
*/
|
586 |
+
readonly asyncResource: EventEmitterReferencingAsyncResource;
|
587 |
+
}
|
588 |
+
}
|
589 |
+
global {
|
590 |
+
namespace NodeJS {
|
591 |
+
interface EventEmitter<T extends EventMap<T> = DefaultEventMap> {
|
592 |
+
[EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: Key<K, T>, ...args: Args<K, T>): void;
|
593 |
+
/**
|
594 |
+
* Alias for `emitter.on(eventName, listener)`.
|
595 |
+
* @since v0.1.26
|
596 |
+
*/
|
597 |
+
addListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
598 |
+
/**
|
599 |
+
* Adds the `listener` function to the end of the listeners array for the event
|
600 |
+
* named `eventName`. No checks are made to see if the `listener` has already
|
601 |
+
* been added. Multiple calls passing the same combination of `eventName` and
|
602 |
+
* `listener` will result in the `listener` being added, and called, multiple times.
|
603 |
+
*
|
604 |
+
* ```js
|
605 |
+
* server.on('connection', (stream) => {
|
606 |
+
* console.log('someone connected!');
|
607 |
+
* });
|
608 |
+
* ```
|
609 |
+
*
|
610 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
611 |
+
*
|
612 |
+
* By default, event listeners are invoked in the order they are added. The `emitter.prependListener()` method can be used as an alternative to add the
|
613 |
+
* event listener to the beginning of the listeners array.
|
614 |
+
*
|
615 |
+
* ```js
|
616 |
+
* import { EventEmitter } from 'node:events';
|
617 |
+
* const myEE = new EventEmitter();
|
618 |
+
* myEE.on('foo', () => console.log('a'));
|
619 |
+
* myEE.prependListener('foo', () => console.log('b'));
|
620 |
+
* myEE.emit('foo');
|
621 |
+
* // Prints:
|
622 |
+
* // b
|
623 |
+
* // a
|
624 |
+
* ```
|
625 |
+
* @since v0.1.101
|
626 |
+
* @param eventName The name of the event.
|
627 |
+
* @param listener The callback function
|
628 |
+
*/
|
629 |
+
on<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
630 |
+
/**
|
631 |
+
* Adds a **one-time** `listener` function for the event named `eventName`. The
|
632 |
+
* next time `eventName` is triggered, this listener is removed and then invoked.
|
633 |
+
*
|
634 |
+
* ```js
|
635 |
+
* server.once('connection', (stream) => {
|
636 |
+
* console.log('Ah, we have our first user!');
|
637 |
+
* });
|
638 |
+
* ```
|
639 |
+
*
|
640 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
641 |
+
*
|
642 |
+
* By default, event listeners are invoked in the order they are added. The `emitter.prependOnceListener()` method can be used as an alternative to add the
|
643 |
+
* event listener to the beginning of the listeners array.
|
644 |
+
*
|
645 |
+
* ```js
|
646 |
+
* import { EventEmitter } from 'node:events';
|
647 |
+
* const myEE = new EventEmitter();
|
648 |
+
* myEE.once('foo', () => console.log('a'));
|
649 |
+
* myEE.prependOnceListener('foo', () => console.log('b'));
|
650 |
+
* myEE.emit('foo');
|
651 |
+
* // Prints:
|
652 |
+
* // b
|
653 |
+
* // a
|
654 |
+
* ```
|
655 |
+
* @since v0.3.0
|
656 |
+
* @param eventName The name of the event.
|
657 |
+
* @param listener The callback function
|
658 |
+
*/
|
659 |
+
once<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
660 |
+
/**
|
661 |
+
* Removes the specified `listener` from the listener array for the event named `eventName`.
|
662 |
+
*
|
663 |
+
* ```js
|
664 |
+
* const callback = (stream) => {
|
665 |
+
* console.log('someone connected!');
|
666 |
+
* };
|
667 |
+
* server.on('connection', callback);
|
668 |
+
* // ...
|
669 |
+
* server.removeListener('connection', callback);
|
670 |
+
* ```
|
671 |
+
*
|
672 |
+
* `removeListener()` will remove, at most, one instance of a listener from the
|
673 |
+
* listener array. If any single listener has been added multiple times to the
|
674 |
+
* listener array for the specified `eventName`, then `removeListener()` must be
|
675 |
+
* called multiple times to remove each instance.
|
676 |
+
*
|
677 |
+
* Once an event is emitted, all listeners attached to it at the
|
678 |
+
* time of emitting are called in order. This implies that any `removeListener()` or `removeAllListeners()` calls _after_ emitting and _before_ the last listener finishes execution
|
679 |
+
* will not remove them from`emit()` in progress. Subsequent events behave as expected.
|
680 |
+
*
|
681 |
+
* ```js
|
682 |
+
* import { EventEmitter } from 'node:events';
|
683 |
+
* class MyEmitter extends EventEmitter {}
|
684 |
+
* const myEmitter = new MyEmitter();
|
685 |
+
*
|
686 |
+
* const callbackA = () => {
|
687 |
+
* console.log('A');
|
688 |
+
* myEmitter.removeListener('event', callbackB);
|
689 |
+
* };
|
690 |
+
*
|
691 |
+
* const callbackB = () => {
|
692 |
+
* console.log('B');
|
693 |
+
* };
|
694 |
+
*
|
695 |
+
* myEmitter.on('event', callbackA);
|
696 |
+
*
|
697 |
+
* myEmitter.on('event', callbackB);
|
698 |
+
*
|
699 |
+
* // callbackA removes listener callbackB but it will still be called.
|
700 |
+
* // Internal listener array at time of emit [callbackA, callbackB]
|
701 |
+
* myEmitter.emit('event');
|
702 |
+
* // Prints:
|
703 |
+
* // A
|
704 |
+
* // B
|
705 |
+
*
|
706 |
+
* // callbackB is now removed.
|
707 |
+
* // Internal listener array [callbackA]
|
708 |
+
* myEmitter.emit('event');
|
709 |
+
* // Prints:
|
710 |
+
* // A
|
711 |
+
* ```
|
712 |
+
*
|
713 |
+
* Because listeners are managed using an internal array, calling this will
|
714 |
+
* change the position indices of any listener registered _after_ the listener
|
715 |
+
* being removed. This will not impact the order in which listeners are called,
|
716 |
+
* but it means that any copies of the listener array as returned by
|
717 |
+
* the `emitter.listeners()` method will need to be recreated.
|
718 |
+
*
|
719 |
+
* When a single function has been added as a handler multiple times for a single
|
720 |
+
* event (as in the example below), `removeListener()` will remove the most
|
721 |
+
* recently added instance. In the example the `once('ping')` listener is removed:
|
722 |
+
*
|
723 |
+
* ```js
|
724 |
+
* import { EventEmitter } from 'node:events';
|
725 |
+
* const ee = new EventEmitter();
|
726 |
+
*
|
727 |
+
* function pong() {
|
728 |
+
* console.log('pong');
|
729 |
+
* }
|
730 |
+
*
|
731 |
+
* ee.on('ping', pong);
|
732 |
+
* ee.once('ping', pong);
|
733 |
+
* ee.removeListener('ping', pong);
|
734 |
+
*
|
735 |
+
* ee.emit('ping');
|
736 |
+
* ee.emit('ping');
|
737 |
+
* ```
|
738 |
+
*
|
739 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
740 |
+
* @since v0.1.26
|
741 |
+
*/
|
742 |
+
removeListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
743 |
+
/**
|
744 |
+
* Alias for `emitter.removeListener()`.
|
745 |
+
* @since v10.0.0
|
746 |
+
*/
|
747 |
+
off<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
748 |
+
/**
|
749 |
+
* Removes all listeners, or those of the specified `eventName`.
|
750 |
+
*
|
751 |
+
* It is bad practice to remove listeners added elsewhere in the code,
|
752 |
+
* particularly when the `EventEmitter` instance was created by some other
|
753 |
+
* component or module (e.g. sockets or file streams).
|
754 |
+
*
|
755 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
756 |
+
* @since v0.1.26
|
757 |
+
*/
|
758 |
+
removeAllListeners(eventName?: Key<unknown, T>): this;
|
759 |
+
/**
|
760 |
+
* By default `EventEmitter`s will print a warning if more than `10` listeners are
|
761 |
+
* added for a particular event. This is a useful default that helps finding
|
762 |
+
* memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
|
763 |
+
* modified for this specific `EventEmitter` instance. The value can be set to `Infinity` (or `0`) to indicate an unlimited number of listeners.
|
764 |
+
*
|
765 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
766 |
+
* @since v0.3.5
|
767 |
+
*/
|
768 |
+
setMaxListeners(n: number): this;
|
769 |
+
/**
|
770 |
+
* Returns the current max listener value for the `EventEmitter` which is either
|
771 |
+
* set by `emitter.setMaxListeners(n)` or defaults to {@link EventEmitter.defaultMaxListeners}.
|
772 |
+
* @since v1.0.0
|
773 |
+
*/
|
774 |
+
getMaxListeners(): number;
|
775 |
+
/**
|
776 |
+
* Returns a copy of the array of listeners for the event named `eventName`.
|
777 |
+
*
|
778 |
+
* ```js
|
779 |
+
* server.on('connection', (stream) => {
|
780 |
+
* console.log('someone connected!');
|
781 |
+
* });
|
782 |
+
* console.log(util.inspect(server.listeners('connection')));
|
783 |
+
* // Prints: [ [Function] ]
|
784 |
+
* ```
|
785 |
+
* @since v0.1.26
|
786 |
+
*/
|
787 |
+
listeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
|
788 |
+
/**
|
789 |
+
* Returns a copy of the array of listeners for the event named `eventName`,
|
790 |
+
* including any wrappers (such as those created by `.once()`).
|
791 |
+
*
|
792 |
+
* ```js
|
793 |
+
* import { EventEmitter } from 'node:events';
|
794 |
+
* const emitter = new EventEmitter();
|
795 |
+
* emitter.once('log', () => console.log('log once'));
|
796 |
+
*
|
797 |
+
* // Returns a new Array with a function `onceWrapper` which has a property
|
798 |
+
* // `listener` which contains the original listener bound above
|
799 |
+
* const listeners = emitter.rawListeners('log');
|
800 |
+
* const logFnWrapper = listeners[0];
|
801 |
+
*
|
802 |
+
* // Logs "log once" to the console and does not unbind the `once` event
|
803 |
+
* logFnWrapper.listener();
|
804 |
+
*
|
805 |
+
* // Logs "log once" to the console and removes the listener
|
806 |
+
* logFnWrapper();
|
807 |
+
*
|
808 |
+
* emitter.on('log', () => console.log('log persistently'));
|
809 |
+
* // Will return a new Array with a single function bound by `.on()` above
|
810 |
+
* const newListeners = emitter.rawListeners('log');
|
811 |
+
*
|
812 |
+
* // Logs "log persistently" twice
|
813 |
+
* newListeners[0]();
|
814 |
+
* emitter.emit('log');
|
815 |
+
* ```
|
816 |
+
* @since v9.4.0
|
817 |
+
*/
|
818 |
+
rawListeners<K>(eventName: Key<K, T>): Array<Listener2<K, T>>;
|
819 |
+
/**
|
820 |
+
* Synchronously calls each of the listeners registered for the event named `eventName`, in the order they were registered, passing the supplied arguments
|
821 |
+
* to each.
|
822 |
+
*
|
823 |
+
* Returns `true` if the event had listeners, `false` otherwise.
|
824 |
+
*
|
825 |
+
* ```js
|
826 |
+
* import { EventEmitter } from 'node:events';
|
827 |
+
* const myEmitter = new EventEmitter();
|
828 |
+
*
|
829 |
+
* // First listener
|
830 |
+
* myEmitter.on('event', function firstListener() {
|
831 |
+
* console.log('Helloooo! first listener');
|
832 |
+
* });
|
833 |
+
* // Second listener
|
834 |
+
* myEmitter.on('event', function secondListener(arg1, arg2) {
|
835 |
+
* console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
|
836 |
+
* });
|
837 |
+
* // Third listener
|
838 |
+
* myEmitter.on('event', function thirdListener(...args) {
|
839 |
+
* const parameters = args.join(', ');
|
840 |
+
* console.log(`event with parameters ${parameters} in third listener`);
|
841 |
+
* });
|
842 |
+
*
|
843 |
+
* console.log(myEmitter.listeners('event'));
|
844 |
+
*
|
845 |
+
* myEmitter.emit('event', 1, 2, 3, 4, 5);
|
846 |
+
*
|
847 |
+
* // Prints:
|
848 |
+
* // [
|
849 |
+
* // [Function: firstListener],
|
850 |
+
* // [Function: secondListener],
|
851 |
+
* // [Function: thirdListener]
|
852 |
+
* // ]
|
853 |
+
* // Helloooo! first listener
|
854 |
+
* // event with parameters 1, 2 in second listener
|
855 |
+
* // event with parameters 1, 2, 3, 4, 5 in third listener
|
856 |
+
* ```
|
857 |
+
* @since v0.1.26
|
858 |
+
*/
|
859 |
+
emit<K>(eventName: Key<K, T>, ...args: Args<K, T>): boolean;
|
860 |
+
/**
|
861 |
+
* Returns the number of listeners listening for the event named `eventName`.
|
862 |
+
* If `listener` is provided, it will return how many times the listener is found
|
863 |
+
* in the list of the listeners of the event.
|
864 |
+
* @since v3.2.0
|
865 |
+
* @param eventName The name of the event being listened for
|
866 |
+
* @param listener The event handler function
|
867 |
+
*/
|
868 |
+
listenerCount<K>(eventName: Key<K, T>, listener?: Listener2<K, T>): number;
|
869 |
+
/**
|
870 |
+
* Adds the `listener` function to the _beginning_ of the listeners array for the
|
871 |
+
* event named `eventName`. No checks are made to see if the `listener` has
|
872 |
+
* already been added. Multiple calls passing the same combination of `eventName`
|
873 |
+
* and `listener` will result in the `listener` being added, and called, multiple times.
|
874 |
+
*
|
875 |
+
* ```js
|
876 |
+
* server.prependListener('connection', (stream) => {
|
877 |
+
* console.log('someone connected!');
|
878 |
+
* });
|
879 |
+
* ```
|
880 |
+
*
|
881 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
882 |
+
* @since v6.0.0
|
883 |
+
* @param eventName The name of the event.
|
884 |
+
* @param listener The callback function
|
885 |
+
*/
|
886 |
+
prependListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
887 |
+
/**
|
888 |
+
* Adds a **one-time**`listener` function for the event named `eventName` to the _beginning_ of the listeners array. The next time `eventName` is triggered, this
|
889 |
+
* listener is removed, and then invoked.
|
890 |
+
*
|
891 |
+
* ```js
|
892 |
+
* server.prependOnceListener('connection', (stream) => {
|
893 |
+
* console.log('Ah, we have our first user!');
|
894 |
+
* });
|
895 |
+
* ```
|
896 |
+
*
|
897 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
898 |
+
* @since v6.0.0
|
899 |
+
* @param eventName The name of the event.
|
900 |
+
* @param listener The callback function
|
901 |
+
*/
|
902 |
+
prependOnceListener<K>(eventName: Key<K, T>, listener: Listener1<K, T>): this;
|
903 |
+
/**
|
904 |
+
* Returns an array listing the events for which the emitter has registered
|
905 |
+
* listeners. The values in the array are strings or `Symbol`s.
|
906 |
+
*
|
907 |
+
* ```js
|
908 |
+
* import { EventEmitter } from 'node:events';
|
909 |
+
*
|
910 |
+
* const myEE = new EventEmitter();
|
911 |
+
* myEE.on('foo', () => {});
|
912 |
+
* myEE.on('bar', () => {});
|
913 |
+
*
|
914 |
+
* const sym = Symbol('symbol');
|
915 |
+
* myEE.on(sym, () => {});
|
916 |
+
*
|
917 |
+
* console.log(myEE.eventNames());
|
918 |
+
* // Prints: [ 'foo', 'bar', Symbol(symbol) ]
|
919 |
+
* ```
|
920 |
+
* @since v6.0.0
|
921 |
+
*/
|
922 |
+
eventNames(): Array<(string | symbol) & Key2<unknown, T>>;
|
923 |
+
}
|
924 |
+
}
|
925 |
+
}
|
926 |
+
export = EventEmitter;
|
927 |
+
}
|
928 |
+
declare module "node:events" {
|
929 |
+
import events = require("events");
|
930 |
+
export = events;
|
931 |
+
}
|
clone/node_modules/@types/node/fs.d.ts
ADDED
The diff for this file is too large to render.
See raw diff
|
|
clone/node_modules/@types/node/fs/promises.d.ts
ADDED
@@ -0,0 +1,1275 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* The `fs/promises` API provides asynchronous file system methods that return
|
3 |
+
* promises.
|
4 |
+
*
|
5 |
+
* The promise APIs use the underlying Node.js threadpool to perform file
|
6 |
+
* system operations off the event loop thread. These operations are not
|
7 |
+
* synchronized or threadsafe. Care must be taken when performing multiple
|
8 |
+
* concurrent modifications on the same file or data corruption may occur.
|
9 |
+
* @since v10.0.0
|
10 |
+
*/
|
11 |
+
declare module "fs/promises" {
|
12 |
+
import { Abortable } from "node:events";
|
13 |
+
import { Stream } from "node:stream";
|
14 |
+
import { ReadableStream } from "node:stream/web";
|
15 |
+
import {
|
16 |
+
BigIntStats,
|
17 |
+
BigIntStatsFs,
|
18 |
+
BufferEncodingOption,
|
19 |
+
constants as fsConstants,
|
20 |
+
CopyOptions,
|
21 |
+
Dir,
|
22 |
+
Dirent,
|
23 |
+
GlobOptions,
|
24 |
+
GlobOptionsWithFileTypes,
|
25 |
+
GlobOptionsWithoutFileTypes,
|
26 |
+
MakeDirectoryOptions,
|
27 |
+
Mode,
|
28 |
+
ObjectEncodingOptions,
|
29 |
+
OpenDirOptions,
|
30 |
+
OpenMode,
|
31 |
+
PathLike,
|
32 |
+
ReadStream,
|
33 |
+
ReadVResult,
|
34 |
+
RmDirOptions,
|
35 |
+
RmOptions,
|
36 |
+
StatFsOptions,
|
37 |
+
StatOptions,
|
38 |
+
Stats,
|
39 |
+
StatsFs,
|
40 |
+
TimeLike,
|
41 |
+
WatchEventType,
|
42 |
+
WatchOptions,
|
43 |
+
WriteStream,
|
44 |
+
WriteVResult,
|
45 |
+
} from "node:fs";
|
46 |
+
import { Interface as ReadlineInterface } from "node:readline";
|
47 |
+
interface FileChangeInfo<T extends string | Buffer> {
|
48 |
+
eventType: WatchEventType;
|
49 |
+
filename: T | null;
|
50 |
+
}
|
51 |
+
interface FlagAndOpenMode {
|
52 |
+
mode?: Mode | undefined;
|
53 |
+
flag?: OpenMode | undefined;
|
54 |
+
}
|
55 |
+
interface FileReadResult<T extends NodeJS.ArrayBufferView> {
|
56 |
+
bytesRead: number;
|
57 |
+
buffer: T;
|
58 |
+
}
|
59 |
+
interface FileReadOptions<T extends NodeJS.ArrayBufferView = Buffer> {
|
60 |
+
/**
|
61 |
+
* @default `Buffer.alloc(0xffff)`
|
62 |
+
*/
|
63 |
+
buffer?: T;
|
64 |
+
/**
|
65 |
+
* @default 0
|
66 |
+
*/
|
67 |
+
offset?: number | null;
|
68 |
+
/**
|
69 |
+
* @default `buffer.byteLength`
|
70 |
+
*/
|
71 |
+
length?: number | null;
|
72 |
+
position?: number | null;
|
73 |
+
}
|
74 |
+
interface CreateReadStreamOptions extends Abortable {
|
75 |
+
encoding?: BufferEncoding | null | undefined;
|
76 |
+
autoClose?: boolean | undefined;
|
77 |
+
emitClose?: boolean | undefined;
|
78 |
+
start?: number | undefined;
|
79 |
+
end?: number | undefined;
|
80 |
+
highWaterMark?: number | undefined;
|
81 |
+
}
|
82 |
+
interface CreateWriteStreamOptions {
|
83 |
+
encoding?: BufferEncoding | null | undefined;
|
84 |
+
autoClose?: boolean | undefined;
|
85 |
+
emitClose?: boolean | undefined;
|
86 |
+
start?: number | undefined;
|
87 |
+
highWaterMark?: number | undefined;
|
88 |
+
flush?: boolean | undefined;
|
89 |
+
}
|
90 |
+
interface ReadableWebStreamOptions {
|
91 |
+
/**
|
92 |
+
* Whether to open a normal or a `'bytes'` stream.
|
93 |
+
* @since v20.0.0
|
94 |
+
*/
|
95 |
+
type?: "bytes" | undefined;
|
96 |
+
}
|
97 |
+
// TODO: Add `EventEmitter` close
|
98 |
+
interface FileHandle {
|
99 |
+
/**
|
100 |
+
* The numeric file descriptor managed by the {FileHandle} object.
|
101 |
+
* @since v10.0.0
|
102 |
+
*/
|
103 |
+
readonly fd: number;
|
104 |
+
/**
|
105 |
+
* Alias of `filehandle.writeFile()`.
|
106 |
+
*
|
107 |
+
* When operating on file handles, the mode cannot be changed from what it was set
|
108 |
+
* to with `fsPromises.open()`. Therefore, this is equivalent to `filehandle.writeFile()`.
|
109 |
+
* @since v10.0.0
|
110 |
+
* @return Fulfills with `undefined` upon success.
|
111 |
+
*/
|
112 |
+
appendFile(
|
113 |
+
data: string | Uint8Array,
|
114 |
+
options?:
|
115 |
+
| (ObjectEncodingOptions & FlagAndOpenMode & { flush?: boolean | undefined })
|
116 |
+
| BufferEncoding
|
117 |
+
| null,
|
118 |
+
): Promise<void>;
|
119 |
+
/**
|
120 |
+
* Changes the ownership of the file. A wrapper for [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html).
|
121 |
+
* @since v10.0.0
|
122 |
+
* @param uid The file's new owner's user id.
|
123 |
+
* @param gid The file's new group's group id.
|
124 |
+
* @return Fulfills with `undefined` upon success.
|
125 |
+
*/
|
126 |
+
chown(uid: number, gid: number): Promise<void>;
|
127 |
+
/**
|
128 |
+
* Modifies the permissions on the file. See [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html).
|
129 |
+
* @since v10.0.0
|
130 |
+
* @param mode the file mode bit mask.
|
131 |
+
* @return Fulfills with `undefined` upon success.
|
132 |
+
*/
|
133 |
+
chmod(mode: Mode): Promise<void>;
|
134 |
+
/**
|
135 |
+
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
|
136 |
+
* returned by this method has a default `highWaterMark` of 64 KiB.
|
137 |
+
*
|
138 |
+
* `options` can include `start` and `end` values to read a range of bytes from
|
139 |
+
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
140 |
+
* start counting at 0, allowed values are in the
|
141 |
+
* \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. If `start` is
|
142 |
+
* omitted or `undefined`, `filehandle.createReadStream()` reads sequentially from
|
143 |
+
* the current file position. The `encoding` can be any one of those accepted by `Buffer`.
|
144 |
+
*
|
145 |
+
* If the `FileHandle` points to a character device that only supports blocking
|
146 |
+
* reads (such as keyboard or sound card), read operations do not finish until data
|
147 |
+
* is available. This can prevent the process from exiting and the stream from
|
148 |
+
* closing naturally.
|
149 |
+
*
|
150 |
+
* By default, the stream will emit a `'close'` event after it has been
|
151 |
+
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
152 |
+
*
|
153 |
+
* ```js
|
154 |
+
* import { open } from 'node:fs/promises';
|
155 |
+
*
|
156 |
+
* const fd = await open('/dev/input/event0');
|
157 |
+
* // Create a stream from some character device.
|
158 |
+
* const stream = fd.createReadStream();
|
159 |
+
* setTimeout(() => {
|
160 |
+
* stream.close(); // This may not close the stream.
|
161 |
+
* // Artificially marking end-of-stream, as if the underlying resource had
|
162 |
+
* // indicated end-of-file by itself, allows the stream to close.
|
163 |
+
* // This does not cancel pending read operations, and if there is such an
|
164 |
+
* // operation, the process may still not be able to exit successfully
|
165 |
+
* // until it finishes.
|
166 |
+
* stream.push(null);
|
167 |
+
* stream.read(0);
|
168 |
+
* }, 100);
|
169 |
+
* ```
|
170 |
+
*
|
171 |
+
* If `autoClose` is false, then the file descriptor won't be closed, even if
|
172 |
+
* there's an error. It is the application's responsibility to close it and make
|
173 |
+
* sure there's no file descriptor leak. If `autoClose` is set to true (default
|
174 |
+
* behavior), on `'error'` or `'end'` the file descriptor will be closed
|
175 |
+
* automatically.
|
176 |
+
*
|
177 |
+
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
178 |
+
*
|
179 |
+
* ```js
|
180 |
+
* import { open } from 'node:fs/promises';
|
181 |
+
*
|
182 |
+
* const fd = await open('sample.txt');
|
183 |
+
* fd.createReadStream({ start: 90, end: 99 });
|
184 |
+
* ```
|
185 |
+
* @since v16.11.0
|
186 |
+
*/
|
187 |
+
createReadStream(options?: CreateReadStreamOptions): ReadStream;
|
188 |
+
/**
|
189 |
+
* `options` may also include a `start` option to allow writing data at some
|
190 |
+
* position past the beginning of the file, allowed values are in the
|
191 |
+
* \[0, [`Number.MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)\] range. Modifying a file rather than
|
192 |
+
* replacing it may require the `flags` `open` option to be set to `r+` rather than
|
193 |
+
* the default `r`. The `encoding` can be any one of those accepted by `Buffer`.
|
194 |
+
*
|
195 |
+
* If `autoClose` is set to true (default behavior) on `'error'` or `'finish'` the file descriptor will be closed automatically. If `autoClose` is false,
|
196 |
+
* then the file descriptor won't be closed, even if there's an error.
|
197 |
+
* It is the application's responsibility to close it and make sure there's no
|
198 |
+
* file descriptor leak.
|
199 |
+
*
|
200 |
+
* By default, the stream will emit a `'close'` event after it has been
|
201 |
+
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
202 |
+
* @since v16.11.0
|
203 |
+
*/
|
204 |
+
createWriteStream(options?: CreateWriteStreamOptions): WriteStream;
|
205 |
+
/**
|
206 |
+
* Forces all currently queued I/O operations associated with the file to the
|
207 |
+
* operating system's synchronized I/O completion state. Refer to the POSIX [`fdatasync(2)`](http://man7.org/linux/man-pages/man2/fdatasync.2.html) documentation for details.
|
208 |
+
*
|
209 |
+
* Unlike `filehandle.sync` this method does not flush modified metadata.
|
210 |
+
* @since v10.0.0
|
211 |
+
* @return Fulfills with `undefined` upon success.
|
212 |
+
*/
|
213 |
+
datasync(): Promise<void>;
|
214 |
+
/**
|
215 |
+
* Request that all data for the open file descriptor is flushed to the storage
|
216 |
+
* device. The specific implementation is operating system and device specific.
|
217 |
+
* Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail.
|
218 |
+
* @since v10.0.0
|
219 |
+
* @return Fulfills with `undefined` upon success.
|
220 |
+
*/
|
221 |
+
sync(): Promise<void>;
|
222 |
+
/**
|
223 |
+
* Reads data from the file and stores that in the given buffer.
|
224 |
+
*
|
225 |
+
* If the file is not modified concurrently, the end-of-file is reached when the
|
226 |
+
* number of bytes read is zero.
|
227 |
+
* @since v10.0.0
|
228 |
+
* @param buffer A buffer that will be filled with the file data read.
|
229 |
+
* @param offset The location in the buffer at which to start filling.
|
230 |
+
* @param length The number of bytes to read.
|
231 |
+
* @param position The location where to begin reading data from the file. If `null`, data will be read from the current file position, and the position will be updated. If `position` is an
|
232 |
+
* integer, the current file position will remain unchanged.
|
233 |
+
* @return Fulfills upon success with an object with two properties:
|
234 |
+
*/
|
235 |
+
read<T extends NodeJS.ArrayBufferView>(
|
236 |
+
buffer: T,
|
237 |
+
offset?: number | null,
|
238 |
+
length?: number | null,
|
239 |
+
position?: number | null,
|
240 |
+
): Promise<FileReadResult<T>>;
|
241 |
+
read<T extends NodeJS.ArrayBufferView = Buffer>(
|
242 |
+
buffer: T,
|
243 |
+
options?: FileReadOptions<T>,
|
244 |
+
): Promise<FileReadResult<T>>;
|
245 |
+
read<T extends NodeJS.ArrayBufferView = Buffer>(options?: FileReadOptions<T>): Promise<FileReadResult<T>>;
|
246 |
+
/**
|
247 |
+
* Returns a `ReadableStream` that may be used to read the files data.
|
248 |
+
*
|
249 |
+
* An error will be thrown if this method is called more than once or is called
|
250 |
+
* after the `FileHandle` is closed or closing.
|
251 |
+
*
|
252 |
+
* ```js
|
253 |
+
* import {
|
254 |
+
* open,
|
255 |
+
* } from 'node:fs/promises';
|
256 |
+
*
|
257 |
+
* const file = await open('./some/file/to/read');
|
258 |
+
*
|
259 |
+
* for await (const chunk of file.readableWebStream())
|
260 |
+
* console.log(chunk);
|
261 |
+
*
|
262 |
+
* await file.close();
|
263 |
+
* ```
|
264 |
+
*
|
265 |
+
* While the `ReadableStream` will read the file to completion, it will not
|
266 |
+
* close the `FileHandle` automatically. User code must still call the`fileHandle.close()` method.
|
267 |
+
* @since v17.0.0
|
268 |
+
* @experimental
|
269 |
+
*/
|
270 |
+
readableWebStream(options?: ReadableWebStreamOptions): ReadableStream;
|
271 |
+
/**
|
272 |
+
* Asynchronously reads the entire contents of a file.
|
273 |
+
*
|
274 |
+
* If `options` is a string, then it specifies the `encoding`.
|
275 |
+
*
|
276 |
+
* The `FileHandle` has to support reading.
|
277 |
+
*
|
278 |
+
* If one or more `filehandle.read()` calls are made on a file handle and then a `filehandle.readFile()` call is made, the data will be read from the current
|
279 |
+
* position till the end of the file. It doesn't always read from the beginning
|
280 |
+
* of the file.
|
281 |
+
* @since v10.0.0
|
282 |
+
* @return Fulfills upon a successful read with the contents of the file. If no encoding is specified (using `options.encoding`), the data is returned as a {Buffer} object. Otherwise, the
|
283 |
+
* data will be a string.
|
284 |
+
*/
|
285 |
+
readFile(
|
286 |
+
options?: {
|
287 |
+
encoding?: null | undefined;
|
288 |
+
flag?: OpenMode | undefined;
|
289 |
+
} | null,
|
290 |
+
): Promise<Buffer>;
|
291 |
+
/**
|
292 |
+
* Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
|
293 |
+
* The `FileHandle` must have been opened for reading.
|
294 |
+
* @param options An object that may contain an optional flag.
|
295 |
+
* If a flag is not provided, it defaults to `'r'`.
|
296 |
+
*/
|
297 |
+
readFile(
|
298 |
+
options:
|
299 |
+
| {
|
300 |
+
encoding: BufferEncoding;
|
301 |
+
flag?: OpenMode | undefined;
|
302 |
+
}
|
303 |
+
| BufferEncoding,
|
304 |
+
): Promise<string>;
|
305 |
+
/**
|
306 |
+
* Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
|
307 |
+
* The `FileHandle` must have been opened for reading.
|
308 |
+
* @param options An object that may contain an optional flag.
|
309 |
+
* If a flag is not provided, it defaults to `'r'`.
|
310 |
+
*/
|
311 |
+
readFile(
|
312 |
+
options?:
|
313 |
+
| (ObjectEncodingOptions & {
|
314 |
+
flag?: OpenMode | undefined;
|
315 |
+
})
|
316 |
+
| BufferEncoding
|
317 |
+
| null,
|
318 |
+
): Promise<string | Buffer>;
|
319 |
+
/**
|
320 |
+
* Convenience method to create a `readline` interface and stream over the file.
|
321 |
+
* See `filehandle.createReadStream()` for the options.
|
322 |
+
*
|
323 |
+
* ```js
|
324 |
+
* import { open } from 'node:fs/promises';
|
325 |
+
*
|
326 |
+
* const file = await open('./some/file/to/read');
|
327 |
+
*
|
328 |
+
* for await (const line of file.readLines()) {
|
329 |
+
* console.log(line);
|
330 |
+
* }
|
331 |
+
* ```
|
332 |
+
* @since v18.11.0
|
333 |
+
*/
|
334 |
+
readLines(options?: CreateReadStreamOptions): ReadlineInterface;
|
335 |
+
/**
|
336 |
+
* @since v10.0.0
|
337 |
+
* @return Fulfills with an {fs.Stats} for the file.
|
338 |
+
*/
|
339 |
+
stat(
|
340 |
+
opts?: StatOptions & {
|
341 |
+
bigint?: false | undefined;
|
342 |
+
},
|
343 |
+
): Promise<Stats>;
|
344 |
+
stat(
|
345 |
+
opts: StatOptions & {
|
346 |
+
bigint: true;
|
347 |
+
},
|
348 |
+
): Promise<BigIntStats>;
|
349 |
+
stat(opts?: StatOptions): Promise<Stats | BigIntStats>;
|
350 |
+
/**
|
351 |
+
* Truncates the file.
|
352 |
+
*
|
353 |
+
* If the file was larger than `len` bytes, only the first `len` bytes will be
|
354 |
+
* retained in the file.
|
355 |
+
*
|
356 |
+
* The following example retains only the first four bytes of the file:
|
357 |
+
*
|
358 |
+
* ```js
|
359 |
+
* import { open } from 'node:fs/promises';
|
360 |
+
*
|
361 |
+
* let filehandle = null;
|
362 |
+
* try {
|
363 |
+
* filehandle = await open('temp.txt', 'r+');
|
364 |
+
* await filehandle.truncate(4);
|
365 |
+
* } finally {
|
366 |
+
* await filehandle?.close();
|
367 |
+
* }
|
368 |
+
* ```
|
369 |
+
*
|
370 |
+
* If the file previously was shorter than `len` bytes, it is extended, and the
|
371 |
+
* extended part is filled with null bytes (`'\0'`):
|
372 |
+
*
|
373 |
+
* If `len` is negative then `0` will be used.
|
374 |
+
* @since v10.0.0
|
375 |
+
* @param [len=0]
|
376 |
+
* @return Fulfills with `undefined` upon success.
|
377 |
+
*/
|
378 |
+
truncate(len?: number): Promise<void>;
|
379 |
+
/**
|
380 |
+
* Change the file system timestamps of the object referenced by the `FileHandle` then fulfills the promise with no arguments upon success.
|
381 |
+
* @since v10.0.0
|
382 |
+
*/
|
383 |
+
utimes(atime: TimeLike, mtime: TimeLike): Promise<void>;
|
384 |
+
/**
|
385 |
+
* Asynchronously writes data to a file, replacing the file if it already exists. `data` can be a string, a buffer, an
|
386 |
+
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an
|
387 |
+
* [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
|
388 |
+
* The promise is fulfilled with no arguments upon success.
|
389 |
+
*
|
390 |
+
* If `options` is a string, then it specifies the `encoding`.
|
391 |
+
*
|
392 |
+
* The `FileHandle` has to support writing.
|
393 |
+
*
|
394 |
+
* It is unsafe to use `filehandle.writeFile()` multiple times on the same file
|
395 |
+
* without waiting for the promise to be fulfilled (or rejected).
|
396 |
+
*
|
397 |
+
* If one or more `filehandle.write()` calls are made on a file handle and then a`filehandle.writeFile()` call is made, the data will be written from the
|
398 |
+
* current position till the end of the file. It doesn't always write from the
|
399 |
+
* beginning of the file.
|
400 |
+
* @since v10.0.0
|
401 |
+
*/
|
402 |
+
writeFile(
|
403 |
+
data: string | Uint8Array,
|
404 |
+
options?:
|
405 |
+
| (ObjectEncodingOptions & FlagAndOpenMode & Abortable & { flush?: boolean | undefined })
|
406 |
+
| BufferEncoding
|
407 |
+
| null,
|
408 |
+
): Promise<void>;
|
409 |
+
/**
|
410 |
+
* Write `buffer` to the file.
|
411 |
+
*
|
412 |
+
* The promise is fulfilled with an object containing two properties:
|
413 |
+
*
|
414 |
+
* It is unsafe to use `filehandle.write()` multiple times on the same file
|
415 |
+
* without waiting for the promise to be fulfilled (or rejected). For this
|
416 |
+
* scenario, use `filehandle.createWriteStream()`.
|
417 |
+
*
|
418 |
+
* On Linux, positional writes do not work when the file is opened in append mode.
|
419 |
+
* The kernel ignores the position argument and always appends the data to
|
420 |
+
* the end of the file.
|
421 |
+
* @since v10.0.0
|
422 |
+
* @param offset The start position from within `buffer` where the data to write begins.
|
423 |
+
* @param [length=buffer.byteLength - offset] The number of bytes from `buffer` to write.
|
424 |
+
* @param [position='null'] The offset from the beginning of the file where the data from `buffer` should be written. If `position` is not a `number`, the data will be written at the current
|
425 |
+
* position. See the POSIX pwrite(2) documentation for more detail.
|
426 |
+
*/
|
427 |
+
write<TBuffer extends Uint8Array>(
|
428 |
+
buffer: TBuffer,
|
429 |
+
offset?: number | null,
|
430 |
+
length?: number | null,
|
431 |
+
position?: number | null,
|
432 |
+
): Promise<{
|
433 |
+
bytesWritten: number;
|
434 |
+
buffer: TBuffer;
|
435 |
+
}>;
|
436 |
+
write<TBuffer extends Uint8Array>(
|
437 |
+
buffer: TBuffer,
|
438 |
+
options?: { offset?: number; length?: number; position?: number },
|
439 |
+
): Promise<{
|
440 |
+
bytesWritten: number;
|
441 |
+
buffer: TBuffer;
|
442 |
+
}>;
|
443 |
+
write(
|
444 |
+
data: string,
|
445 |
+
position?: number | null,
|
446 |
+
encoding?: BufferEncoding | null,
|
447 |
+
): Promise<{
|
448 |
+
bytesWritten: number;
|
449 |
+
buffer: string;
|
450 |
+
}>;
|
451 |
+
/**
|
452 |
+
* Write an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s to the file.
|
453 |
+
*
|
454 |
+
* The promise is fulfilled with an object containing a two properties:
|
455 |
+
*
|
456 |
+
* It is unsafe to call `writev()` multiple times on the same file without waiting
|
457 |
+
* for the promise to be fulfilled (or rejected).
|
458 |
+
*
|
459 |
+
* On Linux, positional writes don't work when the file is opened in append mode.
|
460 |
+
* The kernel ignores the position argument and always appends the data to
|
461 |
+
* the end of the file.
|
462 |
+
* @since v12.9.0
|
463 |
+
* @param [position='null'] The offset from the beginning of the file where the data from `buffers` should be written. If `position` is not a `number`, the data will be written at the current
|
464 |
+
* position.
|
465 |
+
*/
|
466 |
+
writev(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise<WriteVResult>;
|
467 |
+
/**
|
468 |
+
* Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s
|
469 |
+
* @since v13.13.0, v12.17.0
|
470 |
+
* @param [position='null'] The offset from the beginning of the file where the data should be read from. If `position` is not a `number`, the data will be read from the current position.
|
471 |
+
* @return Fulfills upon success an object containing two properties:
|
472 |
+
*/
|
473 |
+
readv(buffers: readonly NodeJS.ArrayBufferView[], position?: number): Promise<ReadVResult>;
|
474 |
+
/**
|
475 |
+
* Closes the file handle after waiting for any pending operation on the handle to
|
476 |
+
* complete.
|
477 |
+
*
|
478 |
+
* ```js
|
479 |
+
* import { open } from 'node:fs/promises';
|
480 |
+
*
|
481 |
+
* let filehandle;
|
482 |
+
* try {
|
483 |
+
* filehandle = await open('thefile.txt', 'r');
|
484 |
+
* } finally {
|
485 |
+
* await filehandle?.close();
|
486 |
+
* }
|
487 |
+
* ```
|
488 |
+
* @since v10.0.0
|
489 |
+
* @return Fulfills with `undefined` upon success.
|
490 |
+
*/
|
491 |
+
close(): Promise<void>;
|
492 |
+
/**
|
493 |
+
* An alias for {@link FileHandle.close()}.
|
494 |
+
* @since v20.4.0
|
495 |
+
*/
|
496 |
+
[Symbol.asyncDispose](): Promise<void>;
|
497 |
+
}
|
498 |
+
const constants: typeof fsConstants;
|
499 |
+
/**
|
500 |
+
* Tests a user's permissions for the file or directory specified by `path`.
|
501 |
+
* The `mode` argument is an optional integer that specifies the accessibility
|
502 |
+
* checks to be performed. `mode` should be either the value `fs.constants.F_OK` or a mask consisting of the bitwise OR of any of `fs.constants.R_OK`, `fs.constants.W_OK`, and `fs.constants.X_OK`
|
503 |
+
* (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
|
504 |
+
* possible values of `mode`.
|
505 |
+
*
|
506 |
+
* If the accessibility check is successful, the promise is fulfilled with no
|
507 |
+
* value. If any of the accessibility checks fail, the promise is rejected
|
508 |
+
* with an [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object. The following example checks if the file`/etc/passwd` can be read and
|
509 |
+
* written by the current process.
|
510 |
+
*
|
511 |
+
* ```js
|
512 |
+
* import { access, constants } from 'node:fs/promises';
|
513 |
+
*
|
514 |
+
* try {
|
515 |
+
* await access('/etc/passwd', constants.R_OK | constants.W_OK);
|
516 |
+
* console.log('can access');
|
517 |
+
* } catch {
|
518 |
+
* console.error('cannot access');
|
519 |
+
* }
|
520 |
+
* ```
|
521 |
+
*
|
522 |
+
* Using `fsPromises.access()` to check for the accessibility of a file before
|
523 |
+
* calling `fsPromises.open()` is not recommended. Doing so introduces a race
|
524 |
+
* condition, since other processes may change the file's state between the two
|
525 |
+
* calls. Instead, user code should open/read/write the file directly and handle
|
526 |
+
* the error raised if the file is not accessible.
|
527 |
+
* @since v10.0.0
|
528 |
+
* @param [mode=fs.constants.F_OK]
|
529 |
+
* @return Fulfills with `undefined` upon success.
|
530 |
+
*/
|
531 |
+
function access(path: PathLike, mode?: number): Promise<void>;
|
532 |
+
/**
|
533 |
+
* Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it
|
534 |
+
* already exists.
|
535 |
+
*
|
536 |
+
* No guarantees are made about the atomicity of the copy operation. If an
|
537 |
+
* error occurs after the destination file has been opened for writing, an attempt
|
538 |
+
* will be made to remove the destination.
|
539 |
+
*
|
540 |
+
* ```js
|
541 |
+
* import { copyFile, constants } from 'node:fs/promises';
|
542 |
+
*
|
543 |
+
* try {
|
544 |
+
* await copyFile('source.txt', 'destination.txt');
|
545 |
+
* console.log('source.txt was copied to destination.txt');
|
546 |
+
* } catch {
|
547 |
+
* console.error('The file could not be copied');
|
548 |
+
* }
|
549 |
+
*
|
550 |
+
* // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
|
551 |
+
* try {
|
552 |
+
* await copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
|
553 |
+
* console.log('source.txt was copied to destination.txt');
|
554 |
+
* } catch {
|
555 |
+
* console.error('The file could not be copied');
|
556 |
+
* }
|
557 |
+
* ```
|
558 |
+
* @since v10.0.0
|
559 |
+
* @param src source filename to copy
|
560 |
+
* @param dest destination filename of the copy operation
|
561 |
+
* @param [mode=0] Optional modifiers that specify the behavior of the copy operation. It is possible to create a mask consisting of the bitwise OR of two or more values (e.g.
|
562 |
+
* `fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`)
|
563 |
+
* @return Fulfills with `undefined` upon success.
|
564 |
+
*/
|
565 |
+
function copyFile(src: PathLike, dest: PathLike, mode?: number): Promise<void>;
|
566 |
+
/**
|
567 |
+
* Opens a `FileHandle`.
|
568 |
+
*
|
569 |
+
* Refer to the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more detail.
|
570 |
+
*
|
571 |
+
* Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
|
572 |
+
* by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
|
573 |
+
* a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).
|
574 |
+
* @since v10.0.0
|
575 |
+
* @param [flags='r'] See `support of file system `flags``.
|
576 |
+
* @param [mode=0o666] Sets the file mode (permission and sticky bits) if the file is created.
|
577 |
+
* @return Fulfills with a {FileHandle} object.
|
578 |
+
*/
|
579 |
+
function open(path: PathLike, flags?: string | number, mode?: Mode): Promise<FileHandle>;
|
580 |
+
/**
|
581 |
+
* Renames `oldPath` to `newPath`.
|
582 |
+
* @since v10.0.0
|
583 |
+
* @return Fulfills with `undefined` upon success.
|
584 |
+
*/
|
585 |
+
function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
586 |
+
/**
|
587 |
+
* Truncates (shortens or extends the length) of the content at `path` to `len` bytes.
|
588 |
+
* @since v10.0.0
|
589 |
+
* @param [len=0]
|
590 |
+
* @return Fulfills with `undefined` upon success.
|
591 |
+
*/
|
592 |
+
function truncate(path: PathLike, len?: number): Promise<void>;
|
593 |
+
/**
|
594 |
+
* Removes the directory identified by `path`.
|
595 |
+
*
|
596 |
+
* Using `fsPromises.rmdir()` on a file (not a directory) results in the
|
597 |
+
* promise being rejected with an `ENOENT` error on Windows and an `ENOTDIR` error on POSIX.
|
598 |
+
*
|
599 |
+
* To get a behavior similar to the `rm -rf` Unix command, use `fsPromises.rm()` with options `{ recursive: true, force: true }`.
|
600 |
+
* @since v10.0.0
|
601 |
+
* @return Fulfills with `undefined` upon success.
|
602 |
+
*/
|
603 |
+
function rmdir(path: PathLike, options?: RmDirOptions): Promise<void>;
|
604 |
+
/**
|
605 |
+
* Removes files and directories (modeled on the standard POSIX `rm` utility).
|
606 |
+
* @since v14.14.0
|
607 |
+
* @return Fulfills with `undefined` upon success.
|
608 |
+
*/
|
609 |
+
function rm(path: PathLike, options?: RmOptions): Promise<void>;
|
610 |
+
/**
|
611 |
+
* Asynchronously creates a directory.
|
612 |
+
*
|
613 |
+
* The optional `options` argument can be an integer specifying `mode` (permission
|
614 |
+
* and sticky bits), or an object with a `mode` property and a `recursive` property indicating whether parent directories should be created. Calling `fsPromises.mkdir()` when `path` is a directory
|
615 |
+
* that exists results in a
|
616 |
+
* rejection only when `recursive` is false.
|
617 |
+
*
|
618 |
+
* ```js
|
619 |
+
* import { mkdir } from 'node:fs/promises';
|
620 |
+
*
|
621 |
+
* try {
|
622 |
+
* const projectFolder = new URL('./test/project/', import.meta.url);
|
623 |
+
* const createDir = await mkdir(projectFolder, { recursive: true });
|
624 |
+
*
|
625 |
+
* console.log(`created ${createDir}`);
|
626 |
+
* } catch (err) {
|
627 |
+
* console.error(err.message);
|
628 |
+
* }
|
629 |
+
* ```
|
630 |
+
* @since v10.0.0
|
631 |
+
* @return Upon success, fulfills with `undefined` if `recursive` is `false`, or the first directory path created if `recursive` is `true`.
|
632 |
+
*/
|
633 |
+
function mkdir(
|
634 |
+
path: PathLike,
|
635 |
+
options: MakeDirectoryOptions & {
|
636 |
+
recursive: true;
|
637 |
+
},
|
638 |
+
): Promise<string | undefined>;
|
639 |
+
/**
|
640 |
+
* Asynchronous mkdir(2) - create a directory.
|
641 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
642 |
+
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
643 |
+
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
644 |
+
*/
|
645 |
+
function mkdir(
|
646 |
+
path: PathLike,
|
647 |
+
options?:
|
648 |
+
| Mode
|
649 |
+
| (MakeDirectoryOptions & {
|
650 |
+
recursive?: false | undefined;
|
651 |
+
})
|
652 |
+
| null,
|
653 |
+
): Promise<void>;
|
654 |
+
/**
|
655 |
+
* Asynchronous mkdir(2) - create a directory.
|
656 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
657 |
+
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
658 |
+
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
659 |
+
*/
|
660 |
+
function mkdir(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
|
661 |
+
/**
|
662 |
+
* Reads the contents of a directory.
|
663 |
+
*
|
664 |
+
* The optional `options` argument can be a string specifying an encoding, or an
|
665 |
+
* object with an `encoding` property specifying the character encoding to use for
|
666 |
+
* the filenames. If the `encoding` is set to `'buffer'`, the filenames returned
|
667 |
+
* will be passed as `Buffer` objects.
|
668 |
+
*
|
669 |
+
* If `options.withFileTypes` is set to `true`, the returned array will contain `fs.Dirent` objects.
|
670 |
+
*
|
671 |
+
* ```js
|
672 |
+
* import { readdir } from 'node:fs/promises';
|
673 |
+
*
|
674 |
+
* try {
|
675 |
+
* const files = await readdir(path);
|
676 |
+
* for (const file of files)
|
677 |
+
* console.log(file);
|
678 |
+
* } catch (err) {
|
679 |
+
* console.error(err);
|
680 |
+
* }
|
681 |
+
* ```
|
682 |
+
* @since v10.0.0
|
683 |
+
* @return Fulfills with an array of the names of the files in the directory excluding `'.'` and `'..'`.
|
684 |
+
*/
|
685 |
+
function readdir(
|
686 |
+
path: PathLike,
|
687 |
+
options?:
|
688 |
+
| (ObjectEncodingOptions & {
|
689 |
+
withFileTypes?: false | undefined;
|
690 |
+
recursive?: boolean | undefined;
|
691 |
+
})
|
692 |
+
| BufferEncoding
|
693 |
+
| null,
|
694 |
+
): Promise<string[]>;
|
695 |
+
/**
|
696 |
+
* Asynchronous readdir(3) - read a directory.
|
697 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
698 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
699 |
+
*/
|
700 |
+
function readdir(
|
701 |
+
path: PathLike,
|
702 |
+
options:
|
703 |
+
| {
|
704 |
+
encoding: "buffer";
|
705 |
+
withFileTypes?: false | undefined;
|
706 |
+
recursive?: boolean | undefined;
|
707 |
+
}
|
708 |
+
| "buffer",
|
709 |
+
): Promise<Buffer[]>;
|
710 |
+
/**
|
711 |
+
* Asynchronous readdir(3) - read a directory.
|
712 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
713 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
714 |
+
*/
|
715 |
+
function readdir(
|
716 |
+
path: PathLike,
|
717 |
+
options?:
|
718 |
+
| (ObjectEncodingOptions & {
|
719 |
+
withFileTypes?: false | undefined;
|
720 |
+
recursive?: boolean | undefined;
|
721 |
+
})
|
722 |
+
| BufferEncoding
|
723 |
+
| null,
|
724 |
+
): Promise<string[] | Buffer[]>;
|
725 |
+
/**
|
726 |
+
* Asynchronous readdir(3) - read a directory.
|
727 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
728 |
+
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
|
729 |
+
*/
|
730 |
+
function readdir(
|
731 |
+
path: PathLike,
|
732 |
+
options: ObjectEncodingOptions & {
|
733 |
+
withFileTypes: true;
|
734 |
+
recursive?: boolean | undefined;
|
735 |
+
},
|
736 |
+
): Promise<Dirent[]>;
|
737 |
+
/**
|
738 |
+
* Reads the contents of the symbolic link referred to by `path`. See the POSIX [`readlink(2)`](http://man7.org/linux/man-pages/man2/readlink.2.html) documentation for more detail. The promise is
|
739 |
+
* fulfilled with the`linkString` upon success.
|
740 |
+
*
|
741 |
+
* The optional `options` argument can be a string specifying an encoding, or an
|
742 |
+
* object with an `encoding` property specifying the character encoding to use for
|
743 |
+
* the link path returned. If the `encoding` is set to `'buffer'`, the link path
|
744 |
+
* returned will be passed as a `Buffer` object.
|
745 |
+
* @since v10.0.0
|
746 |
+
* @return Fulfills with the `linkString` upon success.
|
747 |
+
*/
|
748 |
+
function readlink(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
749 |
+
/**
|
750 |
+
* Asynchronous readlink(2) - read value of a symbolic link.
|
751 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
752 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
753 |
+
*/
|
754 |
+
function readlink(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
|
755 |
+
/**
|
756 |
+
* Asynchronous readlink(2) - read value of a symbolic link.
|
757 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
758 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
759 |
+
*/
|
760 |
+
function readlink(path: PathLike, options?: ObjectEncodingOptions | string | null): Promise<string | Buffer>;
|
761 |
+
/**
|
762 |
+
* Creates a symbolic link.
|
763 |
+
*
|
764 |
+
* The `type` argument is only used on Windows platforms and can be one of `'dir'`, `'file'`, or `'junction'`. If the `type` argument is not a string, Node.js will
|
765 |
+
* autodetect `target` type and use `'file'` or `'dir'`. If the `target` does not
|
766 |
+
* exist, `'file'` will be used. Windows junction points require the destination
|
767 |
+
* path to be absolute. When using `'junction'`, the `target` argument will
|
768 |
+
* automatically be normalized to absolute path. Junction points on NTFS volumes
|
769 |
+
* can only point to directories.
|
770 |
+
* @since v10.0.0
|
771 |
+
* @param [type='null']
|
772 |
+
* @return Fulfills with `undefined` upon success.
|
773 |
+
*/
|
774 |
+
function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
|
775 |
+
/**
|
776 |
+
* Equivalent to `fsPromises.stat()` unless `path` refers to a symbolic link,
|
777 |
+
* in which case the link itself is stat-ed, not the file that it refers to.
|
778 |
+
* Refer to the POSIX [`lstat(2)`](http://man7.org/linux/man-pages/man2/lstat.2.html) document for more detail.
|
779 |
+
* @since v10.0.0
|
780 |
+
* @return Fulfills with the {fs.Stats} object for the given symbolic link `path`.
|
781 |
+
*/
|
782 |
+
function lstat(
|
783 |
+
path: PathLike,
|
784 |
+
opts?: StatOptions & {
|
785 |
+
bigint?: false | undefined;
|
786 |
+
},
|
787 |
+
): Promise<Stats>;
|
788 |
+
function lstat(
|
789 |
+
path: PathLike,
|
790 |
+
opts: StatOptions & {
|
791 |
+
bigint: true;
|
792 |
+
},
|
793 |
+
): Promise<BigIntStats>;
|
794 |
+
function lstat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
|
795 |
+
/**
|
796 |
+
* @since v10.0.0
|
797 |
+
* @return Fulfills with the {fs.Stats} object for the given `path`.
|
798 |
+
*/
|
799 |
+
function stat(
|
800 |
+
path: PathLike,
|
801 |
+
opts?: StatOptions & {
|
802 |
+
bigint?: false | undefined;
|
803 |
+
},
|
804 |
+
): Promise<Stats>;
|
805 |
+
function stat(
|
806 |
+
path: PathLike,
|
807 |
+
opts: StatOptions & {
|
808 |
+
bigint: true;
|
809 |
+
},
|
810 |
+
): Promise<BigIntStats>;
|
811 |
+
function stat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
|
812 |
+
/**
|
813 |
+
* @since v19.6.0, v18.15.0
|
814 |
+
* @return Fulfills with the {fs.StatFs} object for the given `path`.
|
815 |
+
*/
|
816 |
+
function statfs(
|
817 |
+
path: PathLike,
|
818 |
+
opts?: StatFsOptions & {
|
819 |
+
bigint?: false | undefined;
|
820 |
+
},
|
821 |
+
): Promise<StatsFs>;
|
822 |
+
function statfs(
|
823 |
+
path: PathLike,
|
824 |
+
opts: StatFsOptions & {
|
825 |
+
bigint: true;
|
826 |
+
},
|
827 |
+
): Promise<BigIntStatsFs>;
|
828 |
+
function statfs(path: PathLike, opts?: StatFsOptions): Promise<StatsFs | BigIntStatsFs>;
|
829 |
+
/**
|
830 |
+
* Creates a new link from the `existingPath` to the `newPath`. See the POSIX [`link(2)`](http://man7.org/linux/man-pages/man2/link.2.html) documentation for more detail.
|
831 |
+
* @since v10.0.0
|
832 |
+
* @return Fulfills with `undefined` upon success.
|
833 |
+
*/
|
834 |
+
function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
|
835 |
+
/**
|
836 |
+
* If `path` refers to a symbolic link, then the link is removed without affecting
|
837 |
+
* the file or directory to which that link refers. If the `path` refers to a file
|
838 |
+
* path that is not a symbolic link, the file is deleted. See the POSIX [`unlink(2)`](http://man7.org/linux/man-pages/man2/unlink.2.html) documentation for more detail.
|
839 |
+
* @since v10.0.0
|
840 |
+
* @return Fulfills with `undefined` upon success.
|
841 |
+
*/
|
842 |
+
function unlink(path: PathLike): Promise<void>;
|
843 |
+
/**
|
844 |
+
* Changes the permissions of a file.
|
845 |
+
* @since v10.0.0
|
846 |
+
* @return Fulfills with `undefined` upon success.
|
847 |
+
*/
|
848 |
+
function chmod(path: PathLike, mode: Mode): Promise<void>;
|
849 |
+
/**
|
850 |
+
* Changes the permissions on a symbolic link.
|
851 |
+
*
|
852 |
+
* This method is only implemented on macOS.
|
853 |
+
* @deprecated Since v10.0.0
|
854 |
+
* @return Fulfills with `undefined` upon success.
|
855 |
+
*/
|
856 |
+
function lchmod(path: PathLike, mode: Mode): Promise<void>;
|
857 |
+
/**
|
858 |
+
* Changes the ownership on a symbolic link.
|
859 |
+
* @since v10.0.0
|
860 |
+
* @return Fulfills with `undefined` upon success.
|
861 |
+
*/
|
862 |
+
function lchown(path: PathLike, uid: number, gid: number): Promise<void>;
|
863 |
+
/**
|
864 |
+
* Changes the access and modification times of a file in the same way as `fsPromises.utimes()`, with the difference that if the path refers to a
|
865 |
+
* symbolic link, then the link is not dereferenced: instead, the timestamps of
|
866 |
+
* the symbolic link itself are changed.
|
867 |
+
* @since v14.5.0, v12.19.0
|
868 |
+
* @return Fulfills with `undefined` upon success.
|
869 |
+
*/
|
870 |
+
function lutimes(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
871 |
+
/**
|
872 |
+
* Changes the ownership of a file.
|
873 |
+
* @since v10.0.0
|
874 |
+
* @return Fulfills with `undefined` upon success.
|
875 |
+
*/
|
876 |
+
function chown(path: PathLike, uid: number, gid: number): Promise<void>;
|
877 |
+
/**
|
878 |
+
* Change the file system timestamps of the object referenced by `path`.
|
879 |
+
*
|
880 |
+
* The `atime` and `mtime` arguments follow these rules:
|
881 |
+
*
|
882 |
+
* * Values can be either numbers representing Unix epoch time, `Date`s, or a
|
883 |
+
* numeric string like `'123456789.0'`.
|
884 |
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity`, or `-Infinity`, an `Error` will be thrown.
|
885 |
+
* @since v10.0.0
|
886 |
+
* @return Fulfills with `undefined` upon success.
|
887 |
+
*/
|
888 |
+
function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
889 |
+
/**
|
890 |
+
* Determines the actual location of `path` using the same semantics as the `fs.realpath.native()` function.
|
891 |
+
*
|
892 |
+
* Only paths that can be converted to UTF8 strings are supported.
|
893 |
+
*
|
894 |
+
* The optional `options` argument can be a string specifying an encoding, or an
|
895 |
+
* object with an `encoding` property specifying the character encoding to use for
|
896 |
+
* the path. If the `encoding` is set to `'buffer'`, the path returned will be
|
897 |
+
* passed as a `Buffer` object.
|
898 |
+
*
|
899 |
+
* On Linux, when Node.js is linked against musl libc, the procfs file system must
|
900 |
+
* be mounted on `/proc` in order for this function to work. Glibc does not have
|
901 |
+
* this restriction.
|
902 |
+
* @since v10.0.0
|
903 |
+
* @return Fulfills with the resolved path upon success.
|
904 |
+
*/
|
905 |
+
function realpath(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
906 |
+
/**
|
907 |
+
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
908 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
909 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
910 |
+
*/
|
911 |
+
function realpath(path: PathLike, options: BufferEncodingOption): Promise<Buffer>;
|
912 |
+
/**
|
913 |
+
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
914 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
915 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
916 |
+
*/
|
917 |
+
function realpath(
|
918 |
+
path: PathLike,
|
919 |
+
options?: ObjectEncodingOptions | BufferEncoding | null,
|
920 |
+
): Promise<string | Buffer>;
|
921 |
+
/**
|
922 |
+
* Creates a unique temporary directory. A unique directory name is generated by
|
923 |
+
* appending six random characters to the end of the provided `prefix`. Due to
|
924 |
+
* platform inconsistencies, avoid trailing `X` characters in `prefix`. Some
|
925 |
+
* platforms, notably the BSDs, can return more than six random characters, and
|
926 |
+
* replace trailing `X` characters in `prefix` with random characters.
|
927 |
+
*
|
928 |
+
* The optional `options` argument can be a string specifying an encoding, or an
|
929 |
+
* object with an `encoding` property specifying the character encoding to use.
|
930 |
+
*
|
931 |
+
* ```js
|
932 |
+
* import { mkdtemp } from 'node:fs/promises';
|
933 |
+
* import { join } from 'node:path';
|
934 |
+
* import { tmpdir } from 'node:os';
|
935 |
+
*
|
936 |
+
* try {
|
937 |
+
* await mkdtemp(join(tmpdir(), 'foo-'));
|
938 |
+
* } catch (err) {
|
939 |
+
* console.error(err);
|
940 |
+
* }
|
941 |
+
* ```
|
942 |
+
*
|
943 |
+
* The `fsPromises.mkdtemp()` method will append the six randomly selected
|
944 |
+
* characters directly to the `prefix` string. For instance, given a directory `/tmp`, if the intention is to create a temporary directory _within_ `/tmp`, the `prefix` must end with a trailing
|
945 |
+
* platform-specific path separator
|
946 |
+
* (`import { sep } from 'node:path'`).
|
947 |
+
* @since v10.0.0
|
948 |
+
* @return Fulfills with a string containing the file system path of the newly created temporary directory.
|
949 |
+
*/
|
950 |
+
function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
951 |
+
/**
|
952 |
+
* Asynchronously creates a unique temporary directory.
|
953 |
+
* Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
|
954 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
955 |
+
*/
|
956 |
+
function mkdtemp(prefix: string, options: BufferEncodingOption): Promise<Buffer>;
|
957 |
+
/**
|
958 |
+
* Asynchronously creates a unique temporary directory.
|
959 |
+
* Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
|
960 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
961 |
+
*/
|
962 |
+
function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string | Buffer>;
|
963 |
+
/**
|
964 |
+
* Asynchronously writes data to a file, replacing the file if it already exists. `data` can be a string, a buffer, an
|
965 |
+
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an
|
966 |
+
* [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
|
967 |
+
*
|
968 |
+
* The `encoding` option is ignored if `data` is a buffer.
|
969 |
+
*
|
970 |
+
* If `options` is a string, then it specifies the encoding.
|
971 |
+
*
|
972 |
+
* The `mode` option only affects the newly created file. See `fs.open()` for more details.
|
973 |
+
*
|
974 |
+
* Any specified `FileHandle` has to support writing.
|
975 |
+
*
|
976 |
+
* It is unsafe to use `fsPromises.writeFile()` multiple times on the same file
|
977 |
+
* without waiting for the promise to be settled.
|
978 |
+
*
|
979 |
+
* Similarly to `fsPromises.readFile` \- `fsPromises.writeFile` is a convenience
|
980 |
+
* method that performs multiple `write` calls internally to write the buffer
|
981 |
+
* passed to it. For performance sensitive code consider using `fs.createWriteStream()` or `filehandle.createWriteStream()`.
|
982 |
+
*
|
983 |
+
* It is possible to use an `AbortSignal` to cancel an `fsPromises.writeFile()`.
|
984 |
+
* Cancelation is "best effort", and some amount of data is likely still
|
985 |
+
* to be written.
|
986 |
+
*
|
987 |
+
* ```js
|
988 |
+
* import { writeFile } from 'node:fs/promises';
|
989 |
+
* import { Buffer } from 'node:buffer';
|
990 |
+
*
|
991 |
+
* try {
|
992 |
+
* const controller = new AbortController();
|
993 |
+
* const { signal } = controller;
|
994 |
+
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
995 |
+
* const promise = writeFile('message.txt', data, { signal });
|
996 |
+
*
|
997 |
+
* // Abort the request before the promise settles.
|
998 |
+
* controller.abort();
|
999 |
+
*
|
1000 |
+
* await promise;
|
1001 |
+
* } catch (err) {
|
1002 |
+
* // When a request is aborted - err is an AbortError
|
1003 |
+
* console.error(err);
|
1004 |
+
* }
|
1005 |
+
* ```
|
1006 |
+
*
|
1007 |
+
* Aborting an ongoing request does not abort individual operating
|
1008 |
+
* system requests but rather the internal buffering `fs.writeFile` performs.
|
1009 |
+
* @since v10.0.0
|
1010 |
+
* @param file filename or `FileHandle`
|
1011 |
+
* @return Fulfills with `undefined` upon success.
|
1012 |
+
*/
|
1013 |
+
function writeFile(
|
1014 |
+
file: PathLike | FileHandle,
|
1015 |
+
data:
|
1016 |
+
| string
|
1017 |
+
| NodeJS.ArrayBufferView
|
1018 |
+
| Iterable<string | NodeJS.ArrayBufferView>
|
1019 |
+
| AsyncIterable<string | NodeJS.ArrayBufferView>
|
1020 |
+
| Stream,
|
1021 |
+
options?:
|
1022 |
+
| (ObjectEncodingOptions & {
|
1023 |
+
mode?: Mode | undefined;
|
1024 |
+
flag?: OpenMode | undefined;
|
1025 |
+
/**
|
1026 |
+
* If all data is successfully written to the file, and `flush`
|
1027 |
+
* is `true`, `filehandle.sync()` is used to flush the data.
|
1028 |
+
* @default false
|
1029 |
+
*/
|
1030 |
+
flush?: boolean | undefined;
|
1031 |
+
} & Abortable)
|
1032 |
+
| BufferEncoding
|
1033 |
+
| null,
|
1034 |
+
): Promise<void>;
|
1035 |
+
/**
|
1036 |
+
* Asynchronously append data to a file, creating the file if it does not yet
|
1037 |
+
* exist. `data` can be a string or a `Buffer`.
|
1038 |
+
*
|
1039 |
+
* If `options` is a string, then it specifies the `encoding`.
|
1040 |
+
*
|
1041 |
+
* The `mode` option only affects the newly created file. See `fs.open()` for more details.
|
1042 |
+
*
|
1043 |
+
* The `path` may be specified as a `FileHandle` that has been opened
|
1044 |
+
* for appending (using `fsPromises.open()`).
|
1045 |
+
* @since v10.0.0
|
1046 |
+
* @param path filename or {FileHandle}
|
1047 |
+
* @return Fulfills with `undefined` upon success.
|
1048 |
+
*/
|
1049 |
+
function appendFile(
|
1050 |
+
path: PathLike | FileHandle,
|
1051 |
+
data: string | Uint8Array,
|
1052 |
+
options?: (ObjectEncodingOptions & FlagAndOpenMode & { flush?: boolean | undefined }) | BufferEncoding | null,
|
1053 |
+
): Promise<void>;
|
1054 |
+
/**
|
1055 |
+
* Asynchronously reads the entire contents of a file.
|
1056 |
+
*
|
1057 |
+
* If no encoding is specified (using `options.encoding`), the data is returned
|
1058 |
+
* as a `Buffer` object. Otherwise, the data will be a string.
|
1059 |
+
*
|
1060 |
+
* If `options` is a string, then it specifies the encoding.
|
1061 |
+
*
|
1062 |
+
* When the `path` is a directory, the behavior of `fsPromises.readFile()` is
|
1063 |
+
* platform-specific. On macOS, Linux, and Windows, the promise will be rejected
|
1064 |
+
* with an error. On FreeBSD, a representation of the directory's contents will be
|
1065 |
+
* returned.
|
1066 |
+
*
|
1067 |
+
* An example of reading a `package.json` file located in the same directory of the
|
1068 |
+
* running code:
|
1069 |
+
*
|
1070 |
+
* ```js
|
1071 |
+
* import { readFile } from 'node:fs/promises';
|
1072 |
+
* try {
|
1073 |
+
* const filePath = new URL('./package.json', import.meta.url);
|
1074 |
+
* const contents = await readFile(filePath, { encoding: 'utf8' });
|
1075 |
+
* console.log(contents);
|
1076 |
+
* } catch (err) {
|
1077 |
+
* console.error(err.message);
|
1078 |
+
* }
|
1079 |
+
* ```
|
1080 |
+
*
|
1081 |
+
* It is possible to abort an ongoing `readFile` using an `AbortSignal`. If a
|
1082 |
+
* request is aborted the promise returned is rejected with an `AbortError`:
|
1083 |
+
*
|
1084 |
+
* ```js
|
1085 |
+
* import { readFile } from 'node:fs/promises';
|
1086 |
+
*
|
1087 |
+
* try {
|
1088 |
+
* const controller = new AbortController();
|
1089 |
+
* const { signal } = controller;
|
1090 |
+
* const promise = readFile(fileName, { signal });
|
1091 |
+
*
|
1092 |
+
* // Abort the request before the promise settles.
|
1093 |
+
* controller.abort();
|
1094 |
+
*
|
1095 |
+
* await promise;
|
1096 |
+
* } catch (err) {
|
1097 |
+
* // When a request is aborted - err is an AbortError
|
1098 |
+
* console.error(err);
|
1099 |
+
* }
|
1100 |
+
* ```
|
1101 |
+
*
|
1102 |
+
* Aborting an ongoing request does not abort individual operating
|
1103 |
+
* system requests but rather the internal buffering `fs.readFile` performs.
|
1104 |
+
*
|
1105 |
+
* Any specified `FileHandle` has to support reading.
|
1106 |
+
* @since v10.0.0
|
1107 |
+
* @param path filename or `FileHandle`
|
1108 |
+
* @return Fulfills with the contents of the file.
|
1109 |
+
*/
|
1110 |
+
function readFile(
|
1111 |
+
path: PathLike | FileHandle,
|
1112 |
+
options?:
|
1113 |
+
| ({
|
1114 |
+
encoding?: null | undefined;
|
1115 |
+
flag?: OpenMode | undefined;
|
1116 |
+
} & Abortable)
|
1117 |
+
| null,
|
1118 |
+
): Promise<Buffer>;
|
1119 |
+
/**
|
1120 |
+
* Asynchronously reads the entire contents of a file.
|
1121 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
1122 |
+
* If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
|
1123 |
+
* @param options An object that may contain an optional flag.
|
1124 |
+
* If a flag is not provided, it defaults to `'r'`.
|
1125 |
+
*/
|
1126 |
+
function readFile(
|
1127 |
+
path: PathLike | FileHandle,
|
1128 |
+
options:
|
1129 |
+
| ({
|
1130 |
+
encoding: BufferEncoding;
|
1131 |
+
flag?: OpenMode | undefined;
|
1132 |
+
} & Abortable)
|
1133 |
+
| BufferEncoding,
|
1134 |
+
): Promise<string>;
|
1135 |
+
/**
|
1136 |
+
* Asynchronously reads the entire contents of a file.
|
1137 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
1138 |
+
* If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
|
1139 |
+
* @param options An object that may contain an optional flag.
|
1140 |
+
* If a flag is not provided, it defaults to `'r'`.
|
1141 |
+
*/
|
1142 |
+
function readFile(
|
1143 |
+
path: PathLike | FileHandle,
|
1144 |
+
options?:
|
1145 |
+
| (
|
1146 |
+
& ObjectEncodingOptions
|
1147 |
+
& Abortable
|
1148 |
+
& {
|
1149 |
+
flag?: OpenMode | undefined;
|
1150 |
+
}
|
1151 |
+
)
|
1152 |
+
| BufferEncoding
|
1153 |
+
| null,
|
1154 |
+
): Promise<string | Buffer>;
|
1155 |
+
/**
|
1156 |
+
* Asynchronously open a directory for iterative scanning. See the POSIX [`opendir(3)`](http://man7.org/linux/man-pages/man3/opendir.3.html) documentation for more detail.
|
1157 |
+
*
|
1158 |
+
* Creates an `fs.Dir`, which contains all further functions for reading from
|
1159 |
+
* and cleaning up the directory.
|
1160 |
+
*
|
1161 |
+
* The `encoding` option sets the encoding for the `path` while opening the
|
1162 |
+
* directory and subsequent read operations.
|
1163 |
+
*
|
1164 |
+
* Example using async iteration:
|
1165 |
+
*
|
1166 |
+
* ```js
|
1167 |
+
* import { opendir } from 'node:fs/promises';
|
1168 |
+
*
|
1169 |
+
* try {
|
1170 |
+
* const dir = await opendir('./');
|
1171 |
+
* for await (const dirent of dir)
|
1172 |
+
* console.log(dirent.name);
|
1173 |
+
* } catch (err) {
|
1174 |
+
* console.error(err);
|
1175 |
+
* }
|
1176 |
+
* ```
|
1177 |
+
*
|
1178 |
+
* When using the async iterator, the `fs.Dir` object will be automatically
|
1179 |
+
* closed after the iterator exits.
|
1180 |
+
* @since v12.12.0
|
1181 |
+
* @return Fulfills with an {fs.Dir}.
|
1182 |
+
*/
|
1183 |
+
function opendir(path: PathLike, options?: OpenDirOptions): Promise<Dir>;
|
1184 |
+
/**
|
1185 |
+
* Returns an async iterator that watches for changes on `filename`, where `filename`is either a file or a directory.
|
1186 |
+
*
|
1187 |
+
* ```js
|
1188 |
+
* import { watch } from 'node:fs/promises';
|
1189 |
+
*
|
1190 |
+
* const ac = new AbortController();
|
1191 |
+
* const { signal } = ac;
|
1192 |
+
* setTimeout(() => ac.abort(), 10000);
|
1193 |
+
*
|
1194 |
+
* (async () => {
|
1195 |
+
* try {
|
1196 |
+
* const watcher = watch(__filename, { signal });
|
1197 |
+
* for await (const event of watcher)
|
1198 |
+
* console.log(event);
|
1199 |
+
* } catch (err) {
|
1200 |
+
* if (err.name === 'AbortError')
|
1201 |
+
* return;
|
1202 |
+
* throw err;
|
1203 |
+
* }
|
1204 |
+
* })();
|
1205 |
+
* ```
|
1206 |
+
*
|
1207 |
+
* On most platforms, `'rename'` is emitted whenever a filename appears or
|
1208 |
+
* disappears in the directory.
|
1209 |
+
*
|
1210 |
+
* All the `caveats` for `fs.watch()` also apply to `fsPromises.watch()`.
|
1211 |
+
* @since v15.9.0, v14.18.0
|
1212 |
+
* @return of objects with the properties:
|
1213 |
+
*/
|
1214 |
+
function watch(
|
1215 |
+
filename: PathLike,
|
1216 |
+
options:
|
1217 |
+
| (WatchOptions & {
|
1218 |
+
encoding: "buffer";
|
1219 |
+
})
|
1220 |
+
| "buffer",
|
1221 |
+
): AsyncIterable<FileChangeInfo<Buffer>>;
|
1222 |
+
/**
|
1223 |
+
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
1224 |
+
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
1225 |
+
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
|
1226 |
+
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
1227 |
+
* If `persistent` is not supplied, the default of `true` is used.
|
1228 |
+
* If `recursive` is not supplied, the default of `false` is used.
|
1229 |
+
*/
|
1230 |
+
function watch(filename: PathLike, options?: WatchOptions | BufferEncoding): AsyncIterable<FileChangeInfo<string>>;
|
1231 |
+
/**
|
1232 |
+
* Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
|
1233 |
+
* @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
|
1234 |
+
* @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
|
1235 |
+
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
1236 |
+
* If `persistent` is not supplied, the default of `true` is used.
|
1237 |
+
* If `recursive` is not supplied, the default of `false` is used.
|
1238 |
+
*/
|
1239 |
+
function watch(
|
1240 |
+
filename: PathLike,
|
1241 |
+
options: WatchOptions | string,
|
1242 |
+
): AsyncIterable<FileChangeInfo<string>> | AsyncIterable<FileChangeInfo<Buffer>>;
|
1243 |
+
/**
|
1244 |
+
* Asynchronously copies the entire directory structure from `src` to `dest`,
|
1245 |
+
* including subdirectories and files.
|
1246 |
+
*
|
1247 |
+
* When copying a directory to another directory, globs are not supported and
|
1248 |
+
* behavior is similar to `cp dir1/ dir2/`.
|
1249 |
+
* @since v16.7.0
|
1250 |
+
* @experimental
|
1251 |
+
* @param src source path to copy.
|
1252 |
+
* @param dest destination path to copy to.
|
1253 |
+
* @return Fulfills with `undefined` upon success.
|
1254 |
+
*/
|
1255 |
+
function cp(source: string | URL, destination: string | URL, opts?: CopyOptions): Promise<void>;
|
1256 |
+
/**
|
1257 |
+
* Retrieves the files matching the specified pattern.
|
1258 |
+
*/
|
1259 |
+
function glob(pattern: string | string[]): NodeJS.AsyncIterator<string>;
|
1260 |
+
function glob(
|
1261 |
+
pattern: string | string[],
|
1262 |
+
opt: GlobOptionsWithFileTypes,
|
1263 |
+
): NodeJS.AsyncIterator<Dirent>;
|
1264 |
+
function glob(
|
1265 |
+
pattern: string | string[],
|
1266 |
+
opt: GlobOptionsWithoutFileTypes,
|
1267 |
+
): NodeJS.AsyncIterator<string>;
|
1268 |
+
function glob(
|
1269 |
+
pattern: string | string[],
|
1270 |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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export {}; // Make this a module
|
2 |
+
|
3 |
+
// #region Fetch and friends
|
4 |
+
// Conditional type aliases, used at the end of this file.
|
5 |
+
// Will either be empty if lib.dom (or lib.webworker) is included, or the undici version otherwise.
|
6 |
+
type _Request = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Request;
|
7 |
+
type _Response = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Response;
|
8 |
+
type _FormData = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").FormData;
|
9 |
+
type _Headers = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").Headers;
|
10 |
+
type _MessageEvent = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").MessageEvent;
|
11 |
+
type _RequestInit = typeof globalThis extends { onmessage: any } ? {}
|
12 |
+
: import("undici-types").RequestInit;
|
13 |
+
type _ResponseInit = typeof globalThis extends { onmessage: any } ? {}
|
14 |
+
: import("undici-types").ResponseInit;
|
15 |
+
type _WebSocket = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").WebSocket;
|
16 |
+
type _EventSource = typeof globalThis extends { onmessage: any } ? {} : import("undici-types").EventSource;
|
17 |
+
// #endregion Fetch and friends
|
18 |
+
|
19 |
+
// Conditional type definitions for webstorage interface, which conflicts with lib.dom otherwise.
|
20 |
+
type _Storage = typeof globalThis extends { onabort: any } ? {} : {
|
21 |
+
/**
|
22 |
+
* Returns the number of key/value pairs.
|
23 |
+
*
|
24 |
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Storage/length)
|
25 |
+
*/
|
26 |
+
readonly length: number;
|
27 |
+
/**
|
28 |
+
* Removes all key/value pairs, if there are any.
|
29 |
+
*
|
30 |
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Storage/clear)
|
31 |
+
*/
|
32 |
+
clear(): void;
|
33 |
+
/**
|
34 |
+
* Returns the current value associated with the given key, or null if the given key does not exist.
|
35 |
+
*
|
36 |
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Storage/getItem)
|
37 |
+
*/
|
38 |
+
getItem(key: string): string | null;
|
39 |
+
/**
|
40 |
+
* Returns the name of the nth key, or null if n is greater than or equal to the number of key/value pairs.
|
41 |
+
*
|
42 |
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Storage/key)
|
43 |
+
*/
|
44 |
+
key(index: number): string | null;
|
45 |
+
/**
|
46 |
+
* Removes the key/value pair with the given key, if a key/value pair with the given key exists.
|
47 |
+
*
|
48 |
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Storage/removeItem)
|
49 |
+
*/
|
50 |
+
removeItem(key: string): void;
|
51 |
+
/**
|
52 |
+
* Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
|
53 |
+
*
|
54 |
+
* Throws a "QuotaExceededError" DOMException exception if the new value couldn't be set.
|
55 |
+
*
|
56 |
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Storage/setItem)
|
57 |
+
*/
|
58 |
+
setItem(key: string, value: string): void;
|
59 |
+
[key: string]: any;
|
60 |
+
};
|
61 |
+
|
62 |
+
// #region DOMException
|
63 |
+
type _DOMException = typeof globalThis extends { onmessage: any } ? {} : NodeDOMException;
|
64 |
+
interface NodeDOMException extends Error {
|
65 |
+
/**
|
66 |
+
* @deprecated
|
67 |
+
*
|
68 |
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/code)
|
69 |
+
*/
|
70 |
+
readonly code: number;
|
71 |
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/message) */
|
72 |
+
readonly message: string;
|
73 |
+
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException/name) */
|
74 |
+
readonly name: string;
|
75 |
+
readonly INDEX_SIZE_ERR: 1;
|
76 |
+
readonly DOMSTRING_SIZE_ERR: 2;
|
77 |
+
readonly HIERARCHY_REQUEST_ERR: 3;
|
78 |
+
readonly WRONG_DOCUMENT_ERR: 4;
|
79 |
+
readonly INVALID_CHARACTER_ERR: 5;
|
80 |
+
readonly NO_DATA_ALLOWED_ERR: 6;
|
81 |
+
readonly NO_MODIFICATION_ALLOWED_ERR: 7;
|
82 |
+
readonly NOT_FOUND_ERR: 8;
|
83 |
+
readonly NOT_SUPPORTED_ERR: 9;
|
84 |
+
readonly INUSE_ATTRIBUTE_ERR: 10;
|
85 |
+
readonly INVALID_STATE_ERR: 11;
|
86 |
+
readonly SYNTAX_ERR: 12;
|
87 |
+
readonly INVALID_MODIFICATION_ERR: 13;
|
88 |
+
readonly NAMESPACE_ERR: 14;
|
89 |
+
readonly INVALID_ACCESS_ERR: 15;
|
90 |
+
readonly VALIDATION_ERR: 16;
|
91 |
+
readonly TYPE_MISMATCH_ERR: 17;
|
92 |
+
readonly SECURITY_ERR: 18;
|
93 |
+
readonly NETWORK_ERR: 19;
|
94 |
+
readonly ABORT_ERR: 20;
|
95 |
+
readonly URL_MISMATCH_ERR: 21;
|
96 |
+
readonly QUOTA_EXCEEDED_ERR: 22;
|
97 |
+
readonly TIMEOUT_ERR: 23;
|
98 |
+
readonly INVALID_NODE_TYPE_ERR: 24;
|
99 |
+
readonly DATA_CLONE_ERR: 25;
|
100 |
+
}
|
101 |
+
interface NodeDOMExceptionConstructor {
|
102 |
+
prototype: DOMException;
|
103 |
+
new(message?: string, nameOrOptions?: string | { name?: string; cause?: unknown }): DOMException;
|
104 |
+
readonly INDEX_SIZE_ERR: 1;
|
105 |
+
readonly DOMSTRING_SIZE_ERR: 2;
|
106 |
+
readonly HIERARCHY_REQUEST_ERR: 3;
|
107 |
+
readonly WRONG_DOCUMENT_ERR: 4;
|
108 |
+
readonly INVALID_CHARACTER_ERR: 5;
|
109 |
+
readonly NO_DATA_ALLOWED_ERR: 6;
|
110 |
+
readonly NO_MODIFICATION_ALLOWED_ERR: 7;
|
111 |
+
readonly NOT_FOUND_ERR: 8;
|
112 |
+
readonly NOT_SUPPORTED_ERR: 9;
|
113 |
+
readonly INUSE_ATTRIBUTE_ERR: 10;
|
114 |
+
readonly INVALID_STATE_ERR: 11;
|
115 |
+
readonly SYNTAX_ERR: 12;
|
116 |
+
readonly INVALID_MODIFICATION_ERR: 13;
|
117 |
+
readonly NAMESPACE_ERR: 14;
|
118 |
+
readonly INVALID_ACCESS_ERR: 15;
|
119 |
+
readonly VALIDATION_ERR: 16;
|
120 |
+
readonly TYPE_MISMATCH_ERR: 17;
|
121 |
+
readonly SECURITY_ERR: 18;
|
122 |
+
readonly NETWORK_ERR: 19;
|
123 |
+
readonly ABORT_ERR: 20;
|
124 |
+
readonly URL_MISMATCH_ERR: 21;
|
125 |
+
readonly QUOTA_EXCEEDED_ERR: 22;
|
126 |
+
readonly TIMEOUT_ERR: 23;
|
127 |
+
readonly INVALID_NODE_TYPE_ERR: 24;
|
128 |
+
readonly DATA_CLONE_ERR: 25;
|
129 |
+
}
|
130 |
+
// #endregion DOMException
|
131 |
+
|
132 |
+
declare global {
|
133 |
+
// Declare "static" methods in Error
|
134 |
+
interface ErrorConstructor {
|
135 |
+
/** Create .stack property on a target object */
|
136 |
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Optional override for formatting stack traces
|
140 |
+
*
|
141 |
+
* @see https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
142 |
+
*/
|
143 |
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
144 |
+
|
145 |
+
stackTraceLimit: number;
|
146 |
+
}
|
147 |
+
|
148 |
+
/*-----------------------------------------------*
|
149 |
+
* *
|
150 |
+
* GLOBAL *
|
151 |
+
* *
|
152 |
+
------------------------------------------------*/
|
153 |
+
|
154 |
+
var global: typeof globalThis;
|
155 |
+
|
156 |
+
var process: NodeJS.Process;
|
157 |
+
var console: Console;
|
158 |
+
|
159 |
+
interface GCFunction {
|
160 |
+
(options: {
|
161 |
+
execution?: "sync";
|
162 |
+
flavor?: "regular" | "last-resort";
|
163 |
+
type?: "major-snapshot" | "major" | "minor";
|
164 |
+
filename?: string;
|
165 |
+
}): void;
|
166 |
+
(options: {
|
167 |
+
execution: "async";
|
168 |
+
flavor?: "regular" | "last-resort";
|
169 |
+
type?: "major-snapshot" | "major" | "minor";
|
170 |
+
filename?: string;
|
171 |
+
}): Promise<void>;
|
172 |
+
(options?: boolean): void;
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Only available if `--expose-gc` is passed to the process.
|
177 |
+
*/
|
178 |
+
var gc: undefined | GCFunction;
|
179 |
+
|
180 |
+
// #region borrowed
|
181 |
+
// from https://github.com/microsoft/TypeScript/blob/38da7c600c83e7b31193a62495239a0fe478cb67/lib/lib.webworker.d.ts#L633 until moved to separate lib
|
182 |
+
/** A controller object that allows you to abort one or more DOM requests as and when desired. */
|
183 |
+
interface AbortController {
|
184 |
+
/**
|
185 |
+
* Returns the AbortSignal object associated with this object.
|
186 |
+
*/
|
187 |
+
|
188 |
+
readonly signal: AbortSignal;
|
189 |
+
/**
|
190 |
+
* 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.
|
191 |
+
*/
|
192 |
+
abort(reason?: any): void;
|
193 |
+
}
|
194 |
+
|
195 |
+
/** A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. */
|
196 |
+
interface AbortSignal extends EventTarget {
|
197 |
+
/**
|
198 |
+
* Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.
|
199 |
+
*/
|
200 |
+
readonly aborted: boolean;
|
201 |
+
readonly reason: any;
|
202 |
+
onabort: null | ((this: AbortSignal, event: Event) => any);
|
203 |
+
throwIfAborted(): void;
|
204 |
+
}
|
205 |
+
|
206 |
+
var AbortController: typeof globalThis extends { onmessage: any; AbortController: infer T } ? T
|
207 |
+
: {
|
208 |
+
prototype: AbortController;
|
209 |
+
new(): AbortController;
|
210 |
+
};
|
211 |
+
|
212 |
+
var AbortSignal: typeof globalThis extends { onmessage: any; AbortSignal: infer T } ? T
|
213 |
+
: {
|
214 |
+
prototype: AbortSignal;
|
215 |
+
new(): AbortSignal;
|
216 |
+
abort(reason?: any): AbortSignal;
|
217 |
+
timeout(milliseconds: number): AbortSignal;
|
218 |
+
any(signals: AbortSignal[]): AbortSignal;
|
219 |
+
};
|
220 |
+
// #endregion borrowed
|
221 |
+
|
222 |
+
// #region Storage
|
223 |
+
/**
|
224 |
+
* This Web Storage API interface provides access to a particular domain's session or local storage. It allows, for example, the addition, modification, or deletion of stored data items.
|
225 |
+
*
|
226 |
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Storage)
|
227 |
+
*/
|
228 |
+
interface Storage extends _Storage {}
|
229 |
+
|
230 |
+
// Conditional on `onabort` rather than `onmessage`, in order to exclude lib.webworker
|
231 |
+
var Storage: typeof globalThis extends { onabort: any; Storage: infer T } ? T
|
232 |
+
: {
|
233 |
+
prototype: Storage;
|
234 |
+
new(): Storage;
|
235 |
+
};
|
236 |
+
|
237 |
+
/**
|
238 |
+
* A browser-compatible implementation of [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage). Data is stored
|
239 |
+
* unencrypted in the file specified by the `--localstorage-file` CLI flag.
|
240 |
+
* The maximum amount of data that can be stored is 10 MB.
|
241 |
+
* Any modification of this data outside of the Web Storage API is not supported.
|
242 |
+
* Enable this API with the `--experimental-webstorage` CLI flag.
|
243 |
+
* `localStorage` data is not stored per user or per request when used in the context
|
244 |
+
* of a server, it is shared across all users and requests.
|
245 |
+
* @since v22.4.0
|
246 |
+
*/
|
247 |
+
var localStorage: Storage;
|
248 |
+
|
249 |
+
/**
|
250 |
+
* A browser-compatible implementation of [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage). Data is stored in
|
251 |
+
* memory, with a storage quota of 10 MB. `sessionStorage` data persists only within
|
252 |
+
* the currently running process, and is not shared between workers.
|
253 |
+
* @since v22.4.0
|
254 |
+
*/
|
255 |
+
var sessionStorage: Storage;
|
256 |
+
// #endregion Storage
|
257 |
+
|
258 |
+
/**
|
259 |
+
* @since v17.0.0
|
260 |
+
*
|
261 |
+
* Creates a deep clone of an object.
|
262 |
+
*/
|
263 |
+
function structuredClone<T>(
|
264 |
+
value: T,
|
265 |
+
transfer?: { transfer: ReadonlyArray<import("worker_threads").TransferListItem> },
|
266 |
+
): T;
|
267 |
+
|
268 |
+
// #region DOMException
|
269 |
+
/**
|
270 |
+
* @since v17.0.0
|
271 |
+
* An abnormal event (called an exception) which occurs as a result of calling a method or accessing a property of a web API.
|
272 |
+
*
|
273 |
+
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/DOMException)
|
274 |
+
*/
|
275 |
+
interface DOMException extends _DOMException {}
|
276 |
+
|
277 |
+
/**
|
278 |
+
* @since v17.0.0
|
279 |
+
*
|
280 |
+
* The WHATWG `DOMException` class. See [DOMException](https://developer.mozilla.org/docs/Web/API/DOMException) for more details.
|
281 |
+
*/
|
282 |
+
var DOMException: typeof globalThis extends { onmessage: any; DOMException: infer T } ? T
|
283 |
+
: NodeDOMExceptionConstructor;
|
284 |
+
// #endregion DOMException
|
285 |
+
|
286 |
+
/*----------------------------------------------*
|
287 |
+
* *
|
288 |
+
* GLOBAL INTERFACES *
|
289 |
+
* *
|
290 |
+
*-----------------------------------------------*/
|
291 |
+
namespace NodeJS {
|
292 |
+
interface CallSite {
|
293 |
+
/**
|
294 |
+
* Value of "this"
|
295 |
+
*/
|
296 |
+
getThis(): unknown;
|
297 |
+
|
298 |
+
/**
|
299 |
+
* Type of "this" as a string.
|
300 |
+
* This is the name of the function stored in the constructor field of
|
301 |
+
* "this", if available. Otherwise the object's [[Class]] internal
|
302 |
+
* property.
|
303 |
+
*/
|
304 |
+
getTypeName(): string | null;
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Current function
|
308 |
+
*/
|
309 |
+
getFunction(): Function | undefined;
|
310 |
+
|
311 |
+
/**
|
312 |
+
* Name of the current function, typically its name property.
|
313 |
+
* If a name property is not available an attempt will be made to try
|
314 |
+
* to infer a name from the function's context.
|
315 |
+
*/
|
316 |
+
getFunctionName(): string | null;
|
317 |
+
|
318 |
+
/**
|
319 |
+
* Name of the property [of "this" or one of its prototypes] that holds
|
320 |
+
* the current function
|
321 |
+
*/
|
322 |
+
getMethodName(): string | null;
|
323 |
+
|
324 |
+
/**
|
325 |
+
* Name of the script [if this function was defined in a script]
|
326 |
+
*/
|
327 |
+
getFileName(): string | undefined;
|
328 |
+
|
329 |
+
/**
|
330 |
+
* Current line number [if this function was defined in a script]
|
331 |
+
*/
|
332 |
+
getLineNumber(): number | null;
|
333 |
+
|
334 |
+
/**
|
335 |
+
* Current column number [if this function was defined in a script]
|
336 |
+
*/
|
337 |
+
getColumnNumber(): number | null;
|
338 |
+
|
339 |
+
/**
|
340 |
+
* A call site object representing the location where eval was called
|
341 |
+
* [if this function was created using a call to eval]
|
342 |
+
*/
|
343 |
+
getEvalOrigin(): string | undefined;
|
344 |
+
|
345 |
+
/**
|
346 |
+
* Is this a toplevel invocation, that is, is "this" the global object?
|
347 |
+
*/
|
348 |
+
isToplevel(): boolean;
|
349 |
+
|
350 |
+
/**
|
351 |
+
* Does this call take place in code defined by a call to eval?
|
352 |
+
*/
|
353 |
+
isEval(): boolean;
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Is this call in native V8 code?
|
357 |
+
*/
|
358 |
+
isNative(): boolean;
|
359 |
+
|
360 |
+
/**
|
361 |
+
* Is this a constructor call?
|
362 |
+
*/
|
363 |
+
isConstructor(): boolean;
|
364 |
+
|
365 |
+
/**
|
366 |
+
* is this an async call (i.e. await, Promise.all(), or Promise.any())?
|
367 |
+
*/
|
368 |
+
isAsync(): boolean;
|
369 |
+
|
370 |
+
/**
|
371 |
+
* is this an async call to Promise.all()?
|
372 |
+
*/
|
373 |
+
isPromiseAll(): boolean;
|
374 |
+
|
375 |
+
/**
|
376 |
+
* returns the index of the promise element that was followed in
|
377 |
+
* Promise.all() or Promise.any() for async stack traces, or null
|
378 |
+
* if the CallSite is not an async
|
379 |
+
*/
|
380 |
+
getPromiseIndex(): number | null;
|
381 |
+
|
382 |
+
getScriptNameOrSourceURL(): string;
|
383 |
+
getScriptHash(): string;
|
384 |
+
|
385 |
+
getEnclosingColumnNumber(): number;
|
386 |
+
getEnclosingLineNumber(): number;
|
387 |
+
getPosition(): number;
|
388 |
+
|
389 |
+
toString(): string;
|
390 |
+
}
|
391 |
+
|
392 |
+
interface ErrnoException extends Error {
|
393 |
+
errno?: number | undefined;
|
394 |
+
code?: string | undefined;
|
395 |
+
path?: string | undefined;
|
396 |
+
syscall?: string | undefined;
|
397 |
+
}
|
398 |
+
|
399 |
+
interface ReadableStream extends EventEmitter {
|
400 |
+
readable: boolean;
|
401 |
+
read(size?: number): string | Buffer;
|
402 |
+
setEncoding(encoding: BufferEncoding): this;
|
403 |
+
pause(): this;
|
404 |
+
resume(): this;
|
405 |
+
isPaused(): boolean;
|
406 |
+
pipe<T extends WritableStream>(destination: T, options?: { end?: boolean | undefined }): T;
|
407 |
+
unpipe(destination?: WritableStream): this;
|
408 |
+
unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void;
|
409 |
+
wrap(oldStream: ReadableStream): this;
|
410 |
+
[Symbol.asyncIterator](): NodeJS.AsyncIterator<string | Buffer>;
|
411 |
+
}
|
412 |
+
|
413 |
+
interface WritableStream extends EventEmitter {
|
414 |
+
writable: boolean;
|
415 |
+
write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
|
416 |
+
write(str: string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
|
417 |
+
end(cb?: () => void): this;
|
418 |
+
end(data: string | Uint8Array, cb?: () => void): this;
|
419 |
+
end(str: string, encoding?: BufferEncoding, cb?: () => void): this;
|
420 |
+
}
|
421 |
+
|
422 |
+
interface ReadWriteStream extends ReadableStream, WritableStream {}
|
423 |
+
|
424 |
+
interface RefCounted {
|
425 |
+
ref(): this;
|
426 |
+
unref(): this;
|
427 |
+
}
|
428 |
+
|
429 |
+
interface Dict<T> {
|
430 |
+
[key: string]: T | undefined;
|
431 |
+
}
|
432 |
+
|
433 |
+
interface ReadOnlyDict<T> {
|
434 |
+
readonly [key: string]: T | undefined;
|
435 |
+
}
|
436 |
+
|
437 |
+
/** An iterable iterator returned by the Node.js API. */
|
438 |
+
// Default TReturn/TNext in v22 is `any`, for compatibility with the previously-used IterableIterator.
|
439 |
+
// TODO: In next major @types/node version, change default TReturn to undefined.
|
440 |
+
interface Iterator<T, TReturn = any, TNext = any> extends IteratorObject<T, TReturn, TNext> {
|
441 |
+
[Symbol.iterator](): NodeJS.Iterator<T, TReturn, TNext>;
|
442 |
+
}
|
443 |
+
|
444 |
+
/** An async iterable iterator returned by the Node.js API. */
|
445 |
+
// Default TReturn/TNext in v22 is `any`, for compatibility with the previously-used AsyncIterableIterator.
|
446 |
+
// TODO: In next major @types/node version, change default TReturn to undefined.
|
447 |
+
interface AsyncIterator<T, TReturn = any, TNext = any> extends AsyncIteratorObject<T, TReturn, TNext> {
|
448 |
+
[Symbol.asyncIterator](): NodeJS.AsyncIterator<T, TReturn, TNext>;
|
449 |
+
}
|
450 |
+
}
|
451 |
+
|
452 |
+
interface RequestInit extends _RequestInit {}
|
453 |
+
|
454 |
+
function fetch(
|
455 |
+
input: string | URL | globalThis.Request,
|
456 |
+
init?: RequestInit,
|
457 |
+
): Promise<Response>;
|
458 |
+
|
459 |
+
interface Request extends _Request {}
|
460 |
+
var Request: typeof globalThis extends {
|
461 |
+
onmessage: any;
|
462 |
+
Request: infer T;
|
463 |
+
} ? T
|
464 |
+
: typeof import("undici-types").Request;
|
465 |
+
|
466 |
+
interface ResponseInit extends _ResponseInit {}
|
467 |
+
|
468 |
+
interface Response extends _Response {}
|
469 |
+
var Response: typeof globalThis extends {
|
470 |
+
onmessage: any;
|
471 |
+
Response: infer T;
|
472 |
+
} ? T
|
473 |
+
: typeof import("undici-types").Response;
|
474 |
+
|
475 |
+
interface FormData extends _FormData {}
|
476 |
+
var FormData: typeof globalThis extends {
|
477 |
+
onmessage: any;
|
478 |
+
FormData: infer T;
|
479 |
+
} ? T
|
480 |
+
: typeof import("undici-types").FormData;
|
481 |
+
|
482 |
+
interface Headers extends _Headers {}
|
483 |
+
var Headers: typeof globalThis extends {
|
484 |
+
onmessage: any;
|
485 |
+
Headers: infer T;
|
486 |
+
} ? T
|
487 |
+
: typeof import("undici-types").Headers;
|
488 |
+
|
489 |
+
interface MessageEvent extends _MessageEvent {}
|
490 |
+
/**
|
491 |
+
* @since v15.0.0
|
492 |
+
*/
|
493 |
+
var MessageEvent: typeof globalThis extends {
|
494 |
+
onmessage: any;
|
495 |
+
MessageEvent: infer T;
|
496 |
+
} ? T
|
497 |
+
: typeof import("undici-types").MessageEvent;
|
498 |
+
|
499 |
+
interface WebSocket extends _WebSocket {}
|
500 |
+
var WebSocket: typeof globalThis extends { onmessage: any; WebSocket: infer T } ? T
|
501 |
+
: typeof import("undici-types").WebSocket;
|
502 |
+
|
503 |
+
interface EventSource extends _EventSource {}
|
504 |
+
/**
|
505 |
+
* Only available through the [--experimental-eventsource](https://nodejs.org/api/cli.html#--experimental-eventsource) flag.
|
506 |
+
*
|
507 |
+
* @since v22.3.0
|
508 |
+
*/
|
509 |
+
var EventSource: typeof globalThis extends { onmessage: any; EventSource: infer T } ? T
|
510 |
+
: typeof import("undici-types").EventSource;
|
511 |
+
}
|
clone/node_modules/@types/node/globals.typedarray.d.ts
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export {}; // Make this a module
|
2 |
+
|
3 |
+
declare global {
|
4 |
+
namespace NodeJS {
|
5 |
+
type TypedArray<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> =
|
6 |
+
| Uint8Array<TArrayBuffer>
|
7 |
+
| Uint8ClampedArray<TArrayBuffer>
|
8 |
+
| Uint16Array<TArrayBuffer>
|
9 |
+
| Uint32Array<TArrayBuffer>
|
10 |
+
| Int8Array<TArrayBuffer>
|
11 |
+
| Int16Array<TArrayBuffer>
|
12 |
+
| Int32Array<TArrayBuffer>
|
13 |
+
| BigUint64Array<TArrayBuffer>
|
14 |
+
| BigInt64Array<TArrayBuffer>
|
15 |
+
| Float32Array<TArrayBuffer>
|
16 |
+
| Float64Array<TArrayBuffer>;
|
17 |
+
type ArrayBufferView<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> =
|
18 |
+
| TypedArray<TArrayBuffer>
|
19 |
+
| DataView<TArrayBuffer>;
|
20 |
+
}
|
21 |
+
}
|
clone/node_modules/@types/node/http.d.ts
ADDED
@@ -0,0 +1,1958 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* To use the HTTP server and client one must import the `node:http` module.
|
3 |
+
*
|
4 |
+
* The HTTP interfaces in Node.js are designed to support many features
|
5 |
+
* of the protocol which have been traditionally difficult to use.
|
6 |
+
* In particular, large, possibly chunk-encoded, messages. The interface is
|
7 |
+
* careful to never buffer entire requests or responses, so the
|
8 |
+
* user is able to stream data.
|
9 |
+
*
|
10 |
+
* HTTP message headers are represented by an object like this:
|
11 |
+
*
|
12 |
+
* ```json
|
13 |
+
* { "content-length": "123",
|
14 |
+
* "content-type": "text/plain",
|
15 |
+
* "connection": "keep-alive",
|
16 |
+
* "host": "example.com",
|
17 |
+
* "accept": "*" }
|
18 |
+
* ```
|
19 |
+
*
|
20 |
+
* Keys are lowercased. Values are not modified.
|
21 |
+
*
|
22 |
+
* In order to support the full spectrum of possible HTTP applications, the Node.js
|
23 |
+
* HTTP API is very low-level. It deals with stream handling and message
|
24 |
+
* parsing only. It parses a message into headers and body but it does not
|
25 |
+
* parse the actual headers or the body.
|
26 |
+
*
|
27 |
+
* See `message.headers` for details on how duplicate headers are handled.
|
28 |
+
*
|
29 |
+
* The raw headers as they were received are retained in the `rawHeaders` property, which is an array of `[key, value, key2, value2, ...]`. For
|
30 |
+
* example, the previous message header object might have a `rawHeaders` list like the following:
|
31 |
+
*
|
32 |
+
* ```js
|
33 |
+
* [ 'ConTent-Length', '123456',
|
34 |
+
* 'content-LENGTH', '123',
|
35 |
+
* 'content-type', 'text/plain',
|
36 |
+
* 'CONNECTION', 'keep-alive',
|
37 |
+
* 'Host', 'example.com',
|
38 |
+
* 'accepT', '*' ]
|
39 |
+
* ```
|
40 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/http.js)
|
41 |
+
*/
|
42 |
+
declare module "http" {
|
43 |
+
import * as stream from "node:stream";
|
44 |
+
import { URL } from "node:url";
|
45 |
+
import { LookupOptions } from "node:dns";
|
46 |
+
import { EventEmitter } from "node:events";
|
47 |
+
import { LookupFunction, Server as NetServer, Socket, TcpSocketConnectOpts } from "node:net";
|
48 |
+
// incoming headers will never contain number
|
49 |
+
interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
|
50 |
+
accept?: string | undefined;
|
51 |
+
"accept-language"?: string | undefined;
|
52 |
+
"accept-patch"?: string | undefined;
|
53 |
+
"accept-ranges"?: string | undefined;
|
54 |
+
"access-control-allow-credentials"?: string | undefined;
|
55 |
+
"access-control-allow-headers"?: string | undefined;
|
56 |
+
"access-control-allow-methods"?: string | undefined;
|
57 |
+
"access-control-allow-origin"?: string | undefined;
|
58 |
+
"access-control-expose-headers"?: string | undefined;
|
59 |
+
"access-control-max-age"?: string | undefined;
|
60 |
+
"access-control-request-headers"?: string | undefined;
|
61 |
+
"access-control-request-method"?: string | undefined;
|
62 |
+
age?: string | undefined;
|
63 |
+
allow?: string | undefined;
|
64 |
+
"alt-svc"?: string | undefined;
|
65 |
+
authorization?: string | undefined;
|
66 |
+
"cache-control"?: string | undefined;
|
67 |
+
connection?: string | undefined;
|
68 |
+
"content-disposition"?: string | undefined;
|
69 |
+
"content-encoding"?: string | undefined;
|
70 |
+
"content-language"?: string | undefined;
|
71 |
+
"content-length"?: string | undefined;
|
72 |
+
"content-location"?: string | undefined;
|
73 |
+
"content-range"?: string | undefined;
|
74 |
+
"content-type"?: string | undefined;
|
75 |
+
cookie?: string | undefined;
|
76 |
+
date?: string | undefined;
|
77 |
+
etag?: string | undefined;
|
78 |
+
expect?: string | undefined;
|
79 |
+
expires?: string | undefined;
|
80 |
+
forwarded?: string | undefined;
|
81 |
+
from?: string | undefined;
|
82 |
+
host?: string | undefined;
|
83 |
+
"if-match"?: string | undefined;
|
84 |
+
"if-modified-since"?: string | undefined;
|
85 |
+
"if-none-match"?: string | undefined;
|
86 |
+
"if-unmodified-since"?: string | undefined;
|
87 |
+
"last-modified"?: string | undefined;
|
88 |
+
location?: string | undefined;
|
89 |
+
origin?: string | undefined;
|
90 |
+
pragma?: string | undefined;
|
91 |
+
"proxy-authenticate"?: string | undefined;
|
92 |
+
"proxy-authorization"?: string | undefined;
|
93 |
+
"public-key-pins"?: string | undefined;
|
94 |
+
range?: string | undefined;
|
95 |
+
referer?: string | undefined;
|
96 |
+
"retry-after"?: string | undefined;
|
97 |
+
"sec-websocket-accept"?: string | undefined;
|
98 |
+
"sec-websocket-extensions"?: string | undefined;
|
99 |
+
"sec-websocket-key"?: string | undefined;
|
100 |
+
"sec-websocket-protocol"?: string | undefined;
|
101 |
+
"sec-websocket-version"?: string | undefined;
|
102 |
+
"set-cookie"?: string[] | undefined;
|
103 |
+
"strict-transport-security"?: string | undefined;
|
104 |
+
tk?: string | undefined;
|
105 |
+
trailer?: string | undefined;
|
106 |
+
"transfer-encoding"?: string | undefined;
|
107 |
+
upgrade?: string | undefined;
|
108 |
+
"user-agent"?: string | undefined;
|
109 |
+
vary?: string | undefined;
|
110 |
+
via?: string | undefined;
|
111 |
+
warning?: string | undefined;
|
112 |
+
"www-authenticate"?: string | undefined;
|
113 |
+
}
|
114 |
+
// outgoing headers allows numbers (as they are converted internally to strings)
|
115 |
+
type OutgoingHttpHeader = number | string | string[];
|
116 |
+
interface OutgoingHttpHeaders extends NodeJS.Dict<OutgoingHttpHeader> {
|
117 |
+
accept?: string | string[] | undefined;
|
118 |
+
"accept-charset"?: string | string[] | undefined;
|
119 |
+
"accept-encoding"?: string | string[] | undefined;
|
120 |
+
"accept-language"?: string | string[] | undefined;
|
121 |
+
"accept-ranges"?: string | undefined;
|
122 |
+
"access-control-allow-credentials"?: string | undefined;
|
123 |
+
"access-control-allow-headers"?: string | undefined;
|
124 |
+
"access-control-allow-methods"?: string | undefined;
|
125 |
+
"access-control-allow-origin"?: string | undefined;
|
126 |
+
"access-control-expose-headers"?: string | undefined;
|
127 |
+
"access-control-max-age"?: string | undefined;
|
128 |
+
"access-control-request-headers"?: string | undefined;
|
129 |
+
"access-control-request-method"?: string | undefined;
|
130 |
+
age?: string | undefined;
|
131 |
+
allow?: string | undefined;
|
132 |
+
authorization?: string | undefined;
|
133 |
+
"cache-control"?: string | undefined;
|
134 |
+
"cdn-cache-control"?: string | undefined;
|
135 |
+
connection?: string | string[] | undefined;
|
136 |
+
"content-disposition"?: string | undefined;
|
137 |
+
"content-encoding"?: string | undefined;
|
138 |
+
"content-language"?: string | undefined;
|
139 |
+
"content-length"?: string | number | undefined;
|
140 |
+
"content-location"?: string | undefined;
|
141 |
+
"content-range"?: string | undefined;
|
142 |
+
"content-security-policy"?: string | undefined;
|
143 |
+
"content-security-policy-report-only"?: string | undefined;
|
144 |
+
"content-type"?: string | undefined;
|
145 |
+
cookie?: string | string[] | undefined;
|
146 |
+
dav?: string | string[] | undefined;
|
147 |
+
dnt?: string | undefined;
|
148 |
+
date?: string | undefined;
|
149 |
+
etag?: string | undefined;
|
150 |
+
expect?: string | undefined;
|
151 |
+
expires?: string | undefined;
|
152 |
+
forwarded?: string | undefined;
|
153 |
+
from?: string | undefined;
|
154 |
+
host?: string | undefined;
|
155 |
+
"if-match"?: string | undefined;
|
156 |
+
"if-modified-since"?: string | undefined;
|
157 |
+
"if-none-match"?: string | undefined;
|
158 |
+
"if-range"?: string | undefined;
|
159 |
+
"if-unmodified-since"?: string | undefined;
|
160 |
+
"last-modified"?: string | undefined;
|
161 |
+
link?: string | string[] | undefined;
|
162 |
+
location?: string | undefined;
|
163 |
+
"max-forwards"?: string | undefined;
|
164 |
+
origin?: string | undefined;
|
165 |
+
pragma?: string | string[] | undefined;
|
166 |
+
"proxy-authenticate"?: string | string[] | undefined;
|
167 |
+
"proxy-authorization"?: string | undefined;
|
168 |
+
"public-key-pins"?: string | undefined;
|
169 |
+
"public-key-pins-report-only"?: string | undefined;
|
170 |
+
range?: string | undefined;
|
171 |
+
referer?: string | undefined;
|
172 |
+
"referrer-policy"?: string | undefined;
|
173 |
+
refresh?: string | undefined;
|
174 |
+
"retry-after"?: string | undefined;
|
175 |
+
"sec-websocket-accept"?: string | undefined;
|
176 |
+
"sec-websocket-extensions"?: string | string[] | undefined;
|
177 |
+
"sec-websocket-key"?: string | undefined;
|
178 |
+
"sec-websocket-protocol"?: string | string[] | undefined;
|
179 |
+
"sec-websocket-version"?: string | undefined;
|
180 |
+
server?: string | undefined;
|
181 |
+
"set-cookie"?: string | string[] | undefined;
|
182 |
+
"strict-transport-security"?: string | undefined;
|
183 |
+
te?: string | undefined;
|
184 |
+
trailer?: string | undefined;
|
185 |
+
"transfer-encoding"?: string | undefined;
|
186 |
+
"user-agent"?: string | undefined;
|
187 |
+
upgrade?: string | undefined;
|
188 |
+
"upgrade-insecure-requests"?: string | undefined;
|
189 |
+
vary?: string | undefined;
|
190 |
+
via?: string | string[] | undefined;
|
191 |
+
warning?: string | undefined;
|
192 |
+
"www-authenticate"?: string | string[] | undefined;
|
193 |
+
"x-content-type-options"?: string | undefined;
|
194 |
+
"x-dns-prefetch-control"?: string | undefined;
|
195 |
+
"x-frame-options"?: string | undefined;
|
196 |
+
"x-xss-protection"?: string | undefined;
|
197 |
+
}
|
198 |
+
interface ClientRequestArgs {
|
199 |
+
_defaultAgent?: Agent | undefined;
|
200 |
+
agent?: Agent | boolean | undefined;
|
201 |
+
auth?: string | null | undefined;
|
202 |
+
createConnection?:
|
203 |
+
| ((
|
204 |
+
options: ClientRequestArgs,
|
205 |
+
oncreate: (err: Error | null, socket: stream.Duplex) => void,
|
206 |
+
) => stream.Duplex | null | undefined)
|
207 |
+
| undefined;
|
208 |
+
defaultPort?: number | string | undefined;
|
209 |
+
family?: number | undefined;
|
210 |
+
headers?: OutgoingHttpHeaders | undefined;
|
211 |
+
hints?: LookupOptions["hints"];
|
212 |
+
host?: string | null | undefined;
|
213 |
+
hostname?: string | null | undefined;
|
214 |
+
insecureHTTPParser?: boolean | undefined;
|
215 |
+
localAddress?: string | undefined;
|
216 |
+
localPort?: number | undefined;
|
217 |
+
lookup?: LookupFunction | undefined;
|
218 |
+
/**
|
219 |
+
* @default 16384
|
220 |
+
*/
|
221 |
+
maxHeaderSize?: number | undefined;
|
222 |
+
method?: string | undefined;
|
223 |
+
path?: string | null | undefined;
|
224 |
+
port?: number | string | null | undefined;
|
225 |
+
protocol?: string | null | undefined;
|
226 |
+
setHost?: boolean | undefined;
|
227 |
+
signal?: AbortSignal | undefined;
|
228 |
+
socketPath?: string | undefined;
|
229 |
+
timeout?: number | undefined;
|
230 |
+
uniqueHeaders?: Array<string | string[]> | undefined;
|
231 |
+
joinDuplicateHeaders?: boolean;
|
232 |
+
}
|
233 |
+
interface ServerOptions<
|
234 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
235 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
236 |
+
> {
|
237 |
+
/**
|
238 |
+
* Specifies the `IncomingMessage` class to be used. Useful for extending the original `IncomingMessage`.
|
239 |
+
*/
|
240 |
+
IncomingMessage?: Request | undefined;
|
241 |
+
/**
|
242 |
+
* Specifies the `ServerResponse` class to be used. Useful for extending the original `ServerResponse`.
|
243 |
+
*/
|
244 |
+
ServerResponse?: Response | undefined;
|
245 |
+
/**
|
246 |
+
* Sets the timeout value in milliseconds for receiving the entire request from the client.
|
247 |
+
* @see Server.requestTimeout for more information.
|
248 |
+
* @default 300000
|
249 |
+
* @since v18.0.0
|
250 |
+
*/
|
251 |
+
requestTimeout?: number | undefined;
|
252 |
+
/**
|
253 |
+
* It joins the field line values of multiple headers in a request with `, ` instead of discarding the duplicates.
|
254 |
+
* @default false
|
255 |
+
* @since v18.14.0
|
256 |
+
*/
|
257 |
+
joinDuplicateHeaders?: boolean;
|
258 |
+
/**
|
259 |
+
* The number of milliseconds of inactivity a server needs to wait for additional incoming data,
|
260 |
+
* after it has finished writing the last response, before a socket will be destroyed.
|
261 |
+
* @see Server.keepAliveTimeout for more information.
|
262 |
+
* @default 5000
|
263 |
+
* @since v18.0.0
|
264 |
+
*/
|
265 |
+
keepAliveTimeout?: number | undefined;
|
266 |
+
/**
|
267 |
+
* Sets the interval value in milliseconds to check for request and headers timeout in incomplete requests.
|
268 |
+
* @default 30000
|
269 |
+
*/
|
270 |
+
connectionsCheckingInterval?: number | undefined;
|
271 |
+
/**
|
272 |
+
* Optionally overrides all `socket`s' `readableHighWaterMark` and `writableHighWaterMark`.
|
273 |
+
* This affects `highWaterMark` property of both `IncomingMessage` and `ServerResponse`.
|
274 |
+
* Default: @see stream.getDefaultHighWaterMark().
|
275 |
+
* @since v20.1.0
|
276 |
+
*/
|
277 |
+
highWaterMark?: number | undefined;
|
278 |
+
/**
|
279 |
+
* Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
|
280 |
+
* Using the insecure parser should be avoided.
|
281 |
+
* See --insecure-http-parser for more information.
|
282 |
+
* @default false
|
283 |
+
*/
|
284 |
+
insecureHTTPParser?: boolean | undefined;
|
285 |
+
/**
|
286 |
+
* Optionally overrides the value of `--max-http-header-size` for requests received by
|
287 |
+
* this server, i.e. the maximum length of request headers in bytes.
|
288 |
+
* @default 16384
|
289 |
+
* @since v13.3.0
|
290 |
+
*/
|
291 |
+
maxHeaderSize?: number | undefined;
|
292 |
+
/**
|
293 |
+
* If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
|
294 |
+
* @default true
|
295 |
+
* @since v16.5.0
|
296 |
+
*/
|
297 |
+
noDelay?: boolean | undefined;
|
298 |
+
/**
|
299 |
+
* If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
|
300 |
+
* similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
|
301 |
+
* @default false
|
302 |
+
* @since v16.5.0
|
303 |
+
*/
|
304 |
+
keepAlive?: boolean | undefined;
|
305 |
+
/**
|
306 |
+
* If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
|
307 |
+
* @default 0
|
308 |
+
* @since v16.5.0
|
309 |
+
*/
|
310 |
+
keepAliveInitialDelay?: number | undefined;
|
311 |
+
/**
|
312 |
+
* A list of response headers that should be sent only once.
|
313 |
+
* If the header's value is an array, the items will be joined using `; `.
|
314 |
+
*/
|
315 |
+
uniqueHeaders?: Array<string | string[]> | undefined;
|
316 |
+
}
|
317 |
+
type RequestListener<
|
318 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
319 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
320 |
+
> = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;
|
321 |
+
/**
|
322 |
+
* @since v0.1.17
|
323 |
+
*/
|
324 |
+
class Server<
|
325 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
326 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
327 |
+
> extends NetServer {
|
328 |
+
constructor(requestListener?: RequestListener<Request, Response>);
|
329 |
+
constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
|
330 |
+
/**
|
331 |
+
* Sets the timeout value for sockets, and emits a `'timeout'` event on
|
332 |
+
* the Server object, passing the socket as an argument, if a timeout
|
333 |
+
* occurs.
|
334 |
+
*
|
335 |
+
* If there is a `'timeout'` event listener on the Server object, then it
|
336 |
+
* will be called with the timed-out socket as an argument.
|
337 |
+
*
|
338 |
+
* By default, the Server does not timeout sockets. However, if a callback
|
339 |
+
* is assigned to the Server's `'timeout'` event, timeouts must be handled
|
340 |
+
* explicitly.
|
341 |
+
* @since v0.9.12
|
342 |
+
* @param [msecs=0 (no timeout)]
|
343 |
+
*/
|
344 |
+
setTimeout(msecs?: number, callback?: () => void): this;
|
345 |
+
setTimeout(callback: () => void): this;
|
346 |
+
/**
|
347 |
+
* Limits maximum incoming headers count. If set to 0, no limit will be applied.
|
348 |
+
* @since v0.7.0
|
349 |
+
*/
|
350 |
+
maxHeadersCount: number | null;
|
351 |
+
/**
|
352 |
+
* The maximum number of requests socket can handle
|
353 |
+
* before closing keep alive connection.
|
354 |
+
*
|
355 |
+
* A value of `0` will disable the limit.
|
356 |
+
*
|
357 |
+
* When the limit is reached it will set the `Connection` header value to `close`,
|
358 |
+
* but will not actually close the connection, subsequent requests sent
|
359 |
+
* after the limit is reached will get `503 Service Unavailable` as a response.
|
360 |
+
* @since v16.10.0
|
361 |
+
*/
|
362 |
+
maxRequestsPerSocket: number | null;
|
363 |
+
/**
|
364 |
+
* The number of milliseconds of inactivity before a socket is presumed
|
365 |
+
* to have timed out.
|
366 |
+
*
|
367 |
+
* A value of `0` will disable the timeout behavior on incoming connections.
|
368 |
+
*
|
369 |
+
* The socket timeout logic is set up on connection, so changing this
|
370 |
+
* value only affects new connections to the server, not any existing connections.
|
371 |
+
* @since v0.9.12
|
372 |
+
*/
|
373 |
+
timeout: number;
|
374 |
+
/**
|
375 |
+
* Limit the amount of time the parser will wait to receive the complete HTTP
|
376 |
+
* headers.
|
377 |
+
*
|
378 |
+
* If the timeout expires, the server responds with status 408 without
|
379 |
+
* forwarding the request to the request listener and then closes the connection.
|
380 |
+
*
|
381 |
+
* It must be set to a non-zero value (e.g. 120 seconds) to protect against
|
382 |
+
* potential Denial-of-Service attacks in case the server is deployed without a
|
383 |
+
* reverse proxy in front.
|
384 |
+
* @since v11.3.0, v10.14.0
|
385 |
+
*/
|
386 |
+
headersTimeout: number;
|
387 |
+
/**
|
388 |
+
* The number of milliseconds of inactivity a server needs to wait for additional
|
389 |
+
* incoming data, after it has finished writing the last response, before a socket
|
390 |
+
* will be destroyed. If the server receives new data before the keep-alive
|
391 |
+
* timeout has fired, it will reset the regular inactivity timeout, i.e., `server.timeout`.
|
392 |
+
*
|
393 |
+
* A value of `0` will disable the keep-alive timeout behavior on incoming
|
394 |
+
* connections.
|
395 |
+
* A value of `0` makes the http server behave similarly to Node.js versions prior
|
396 |
+
* to 8.0.0, which did not have a keep-alive timeout.
|
397 |
+
*
|
398 |
+
* The socket timeout logic is set up on connection, so changing this value only
|
399 |
+
* affects new connections to the server, not any existing connections.
|
400 |
+
* @since v8.0.0
|
401 |
+
*/
|
402 |
+
keepAliveTimeout: number;
|
403 |
+
/**
|
404 |
+
* Sets the timeout value in milliseconds for receiving the entire request from
|
405 |
+
* the client.
|
406 |
+
*
|
407 |
+
* If the timeout expires, the server responds with status 408 without
|
408 |
+
* forwarding the request to the request listener and then closes the connection.
|
409 |
+
*
|
410 |
+
* It must be set to a non-zero value (e.g. 120 seconds) to protect against
|
411 |
+
* potential Denial-of-Service attacks in case the server is deployed without a
|
412 |
+
* reverse proxy in front.
|
413 |
+
* @since v14.11.0
|
414 |
+
*/
|
415 |
+
requestTimeout: number;
|
416 |
+
/**
|
417 |
+
* Closes all connections connected to this server.
|
418 |
+
* @since v18.2.0
|
419 |
+
*/
|
420 |
+
closeAllConnections(): void;
|
421 |
+
/**
|
422 |
+
* Closes all connections connected to this server which are not sending a request
|
423 |
+
* or waiting for a response.
|
424 |
+
* @since v18.2.0
|
425 |
+
*/
|
426 |
+
closeIdleConnections(): void;
|
427 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
428 |
+
addListener(event: "close", listener: () => void): this;
|
429 |
+
addListener(event: "connection", listener: (socket: Socket) => void): this;
|
430 |
+
addListener(event: "error", listener: (err: Error) => void): this;
|
431 |
+
addListener(event: "listening", listener: () => void): this;
|
432 |
+
addListener(event: "checkContinue", listener: RequestListener<Request, Response>): this;
|
433 |
+
addListener(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
|
434 |
+
addListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
|
435 |
+
addListener(
|
436 |
+
event: "connect",
|
437 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
438 |
+
): this;
|
439 |
+
addListener(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
440 |
+
addListener(event: "request", listener: RequestListener<Request, Response>): this;
|
441 |
+
addListener(
|
442 |
+
event: "upgrade",
|
443 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
444 |
+
): this;
|
445 |
+
emit(event: string, ...args: any[]): boolean;
|
446 |
+
emit(event: "close"): boolean;
|
447 |
+
emit(event: "connection", socket: Socket): boolean;
|
448 |
+
emit(event: "error", err: Error): boolean;
|
449 |
+
emit(event: "listening"): boolean;
|
450 |
+
emit(
|
451 |
+
event: "checkContinue",
|
452 |
+
req: InstanceType<Request>,
|
453 |
+
res: InstanceType<Response> & { req: InstanceType<Request> },
|
454 |
+
): boolean;
|
455 |
+
emit(
|
456 |
+
event: "checkExpectation",
|
457 |
+
req: InstanceType<Request>,
|
458 |
+
res: InstanceType<Response> & { req: InstanceType<Request> },
|
459 |
+
): boolean;
|
460 |
+
emit(event: "clientError", err: Error, socket: stream.Duplex): boolean;
|
461 |
+
emit(event: "connect", req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
|
462 |
+
emit(event: "dropRequest", req: InstanceType<Request>, socket: stream.Duplex): boolean;
|
463 |
+
emit(
|
464 |
+
event: "request",
|
465 |
+
req: InstanceType<Request>,
|
466 |
+
res: InstanceType<Response> & { req: InstanceType<Request> },
|
467 |
+
): boolean;
|
468 |
+
emit(event: "upgrade", req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
|
469 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
470 |
+
on(event: "close", listener: () => void): this;
|
471 |
+
on(event: "connection", listener: (socket: Socket) => void): this;
|
472 |
+
on(event: "error", listener: (err: Error) => void): this;
|
473 |
+
on(event: "listening", listener: () => void): this;
|
474 |
+
on(event: "checkContinue", listener: RequestListener<Request, Response>): this;
|
475 |
+
on(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
|
476 |
+
on(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
|
477 |
+
on(event: "connect", listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
478 |
+
on(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
479 |
+
on(event: "request", listener: RequestListener<Request, Response>): this;
|
480 |
+
on(event: "upgrade", listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
481 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
482 |
+
once(event: "close", listener: () => void): this;
|
483 |
+
once(event: "connection", listener: (socket: Socket) => void): this;
|
484 |
+
once(event: "error", listener: (err: Error) => void): this;
|
485 |
+
once(event: "listening", listener: () => void): this;
|
486 |
+
once(event: "checkContinue", listener: RequestListener<Request, Response>): this;
|
487 |
+
once(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
|
488 |
+
once(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
|
489 |
+
once(
|
490 |
+
event: "connect",
|
491 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
492 |
+
): this;
|
493 |
+
once(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
494 |
+
once(event: "request", listener: RequestListener<Request, Response>): this;
|
495 |
+
once(
|
496 |
+
event: "upgrade",
|
497 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
498 |
+
): this;
|
499 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
500 |
+
prependListener(event: "close", listener: () => void): this;
|
501 |
+
prependListener(event: "connection", listener: (socket: Socket) => void): this;
|
502 |
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
503 |
+
prependListener(event: "listening", listener: () => void): this;
|
504 |
+
prependListener(event: "checkContinue", listener: RequestListener<Request, Response>): this;
|
505 |
+
prependListener(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
|
506 |
+
prependListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
|
507 |
+
prependListener(
|
508 |
+
event: "connect",
|
509 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
510 |
+
): this;
|
511 |
+
prependListener(
|
512 |
+
event: "dropRequest",
|
513 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,
|
514 |
+
): this;
|
515 |
+
prependListener(event: "request", listener: RequestListener<Request, Response>): this;
|
516 |
+
prependListener(
|
517 |
+
event: "upgrade",
|
518 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
519 |
+
): this;
|
520 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
521 |
+
prependOnceListener(event: "close", listener: () => void): this;
|
522 |
+
prependOnceListener(event: "connection", listener: (socket: Socket) => void): this;
|
523 |
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
524 |
+
prependOnceListener(event: "listening", listener: () => void): this;
|
525 |
+
prependOnceListener(event: "checkContinue", listener: RequestListener<Request, Response>): this;
|
526 |
+
prependOnceListener(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
|
527 |
+
prependOnceListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
|
528 |
+
prependOnceListener(
|
529 |
+
event: "connect",
|
530 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
531 |
+
): this;
|
532 |
+
prependOnceListener(
|
533 |
+
event: "dropRequest",
|
534 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,
|
535 |
+
): this;
|
536 |
+
prependOnceListener(event: "request", listener: RequestListener<Request, Response>): this;
|
537 |
+
prependOnceListener(
|
538 |
+
event: "upgrade",
|
539 |
+
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
540 |
+
): this;
|
541 |
+
}
|
542 |
+
/**
|
543 |
+
* This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract outgoing message from
|
544 |
+
* the perspective of the participants of an HTTP transaction.
|
545 |
+
* @since v0.1.17
|
546 |
+
*/
|
547 |
+
class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
|
548 |
+
readonly req: Request;
|
549 |
+
chunkedEncoding: boolean;
|
550 |
+
shouldKeepAlive: boolean;
|
551 |
+
useChunkedEncodingByDefault: boolean;
|
552 |
+
sendDate: boolean;
|
553 |
+
/**
|
554 |
+
* @deprecated Use `writableEnded` instead.
|
555 |
+
*/
|
556 |
+
finished: boolean;
|
557 |
+
/**
|
558 |
+
* Read-only. `true` if the headers were sent, otherwise `false`.
|
559 |
+
* @since v0.9.3
|
560 |
+
*/
|
561 |
+
readonly headersSent: boolean;
|
562 |
+
/**
|
563 |
+
* Alias of `outgoingMessage.socket`.
|
564 |
+
* @since v0.3.0
|
565 |
+
* @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
|
566 |
+
*/
|
567 |
+
readonly connection: Socket | null;
|
568 |
+
/**
|
569 |
+
* Reference to the underlying socket. Usually, users will not want to access
|
570 |
+
* this property.
|
571 |
+
*
|
572 |
+
* After calling `outgoingMessage.end()`, this property will be nulled.
|
573 |
+
* @since v0.3.0
|
574 |
+
*/
|
575 |
+
readonly socket: Socket | null;
|
576 |
+
constructor();
|
577 |
+
/**
|
578 |
+
* Once a socket is associated with the message and is connected, `socket.setTimeout()` will be called with `msecs` as the first parameter.
|
579 |
+
* @since v0.9.12
|
580 |
+
* @param callback Optional function to be called when a timeout occurs. Same as binding to the `timeout` event.
|
581 |
+
*/
|
582 |
+
setTimeout(msecs: number, callback?: () => void): this;
|
583 |
+
/**
|
584 |
+
* Sets a single header value. If the header already exists in the to-be-sent
|
585 |
+
* headers, its value will be replaced. Use an array of strings to send multiple
|
586 |
+
* headers with the same name.
|
587 |
+
* @since v0.4.0
|
588 |
+
* @param name Header name
|
589 |
+
* @param value Header value
|
590 |
+
*/
|
591 |
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
592 |
+
/**
|
593 |
+
* Sets multiple header values for implicit headers. headers must be an instance of
|
594 |
+
* `Headers` or `Map`, if a header already exists in the to-be-sent headers, its
|
595 |
+
* value will be replaced.
|
596 |
+
*
|
597 |
+
* ```js
|
598 |
+
* const headers = new Headers({ foo: 'bar' });
|
599 |
+
* outgoingMessage.setHeaders(headers);
|
600 |
+
* ```
|
601 |
+
*
|
602 |
+
* or
|
603 |
+
*
|
604 |
+
* ```js
|
605 |
+
* const headers = new Map([['foo', 'bar']]);
|
606 |
+
* outgoingMessage.setHeaders(headers);
|
607 |
+
* ```
|
608 |
+
*
|
609 |
+
* When headers have been set with `outgoingMessage.setHeaders()`, they will be
|
610 |
+
* merged with any headers passed to `response.writeHead()`, with the headers passed
|
611 |
+
* to `response.writeHead()` given precedence.
|
612 |
+
*
|
613 |
+
* ```js
|
614 |
+
* // Returns content-type = text/plain
|
615 |
+
* const server = http.createServer((req, res) => {
|
616 |
+
* const headers = new Headers({ 'Content-Type': 'text/html' });
|
617 |
+
* res.setHeaders(headers);
|
618 |
+
* res.writeHead(200, { 'Content-Type': 'text/plain' });
|
619 |
+
* res.end('ok');
|
620 |
+
* });
|
621 |
+
* ```
|
622 |
+
*
|
623 |
+
* @since v19.6.0, v18.15.0
|
624 |
+
* @param name Header name
|
625 |
+
* @param value Header value
|
626 |
+
*/
|
627 |
+
setHeaders(headers: Headers | Map<string, number | string | readonly string[]>): this;
|
628 |
+
/**
|
629 |
+
* Append a single header value to the header object.
|
630 |
+
*
|
631 |
+
* If the value is an array, this is equivalent to calling this method multiple
|
632 |
+
* times.
|
633 |
+
*
|
634 |
+
* If there were no previous values for the header, this is equivalent to calling `outgoingMessage.setHeader(name, value)`.
|
635 |
+
*
|
636 |
+
* Depending of the value of `options.uniqueHeaders` when the client request or the
|
637 |
+
* server were created, this will end up in the header being sent multiple times or
|
638 |
+
* a single time with values joined using `; `.
|
639 |
+
* @since v18.3.0, v16.17.0
|
640 |
+
* @param name Header name
|
641 |
+
* @param value Header value
|
642 |
+
*/
|
643 |
+
appendHeader(name: string, value: string | readonly string[]): this;
|
644 |
+
/**
|
645 |
+
* Gets the value of the HTTP header with the given name. If that header is not
|
646 |
+
* set, the returned value will be `undefined`.
|
647 |
+
* @since v0.4.0
|
648 |
+
* @param name Name of header
|
649 |
+
*/
|
650 |
+
getHeader(name: string): number | string | string[] | undefined;
|
651 |
+
/**
|
652 |
+
* Returns a shallow copy of the current outgoing headers. Since a shallow
|
653 |
+
* copy is used, array values may be mutated without additional calls to
|
654 |
+
* various header-related HTTP module methods. The keys of the returned
|
655 |
+
* object are the header names and the values are the respective header
|
656 |
+
* values. All header names are lowercase.
|
657 |
+
*
|
658 |
+
* The object returned by the `outgoingMessage.getHeaders()` method does
|
659 |
+
* not prototypically inherit from the JavaScript `Object`. This means that
|
660 |
+
* typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,
|
661 |
+
* and others are not defined and will not work.
|
662 |
+
*
|
663 |
+
* ```js
|
664 |
+
* outgoingMessage.setHeader('Foo', 'bar');
|
665 |
+
* outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
666 |
+
*
|
667 |
+
* const headers = outgoingMessage.getHeaders();
|
668 |
+
* // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
|
669 |
+
* ```
|
670 |
+
* @since v7.7.0
|
671 |
+
*/
|
672 |
+
getHeaders(): OutgoingHttpHeaders;
|
673 |
+
/**
|
674 |
+
* Returns an array containing the unique names of the current outgoing headers.
|
675 |
+
* All names are lowercase.
|
676 |
+
* @since v7.7.0
|
677 |
+
*/
|
678 |
+
getHeaderNames(): string[];
|
679 |
+
/**
|
680 |
+
* Returns `true` if the header identified by `name` is currently set in the
|
681 |
+
* outgoing headers. The header name is case-insensitive.
|
682 |
+
*
|
683 |
+
* ```js
|
684 |
+
* const hasContentType = outgoingMessage.hasHeader('content-type');
|
685 |
+
* ```
|
686 |
+
* @since v7.7.0
|
687 |
+
*/
|
688 |
+
hasHeader(name: string): boolean;
|
689 |
+
/**
|
690 |
+
* Removes a header that is queued for implicit sending.
|
691 |
+
*
|
692 |
+
* ```js
|
693 |
+
* outgoingMessage.removeHeader('Content-Encoding');
|
694 |
+
* ```
|
695 |
+
* @since v0.4.0
|
696 |
+
* @param name Header name
|
697 |
+
*/
|
698 |
+
removeHeader(name: string): void;
|
699 |
+
/**
|
700 |
+
* Adds HTTP trailers (headers but at the end of the message) to the message.
|
701 |
+
*
|
702 |
+
* Trailers will **only** be emitted if the message is chunked encoded. If not,
|
703 |
+
* the trailers will be silently discarded.
|
704 |
+
*
|
705 |
+
* HTTP requires the `Trailer` header to be sent to emit trailers,
|
706 |
+
* with a list of header field names in its value, e.g.
|
707 |
+
*
|
708 |
+
* ```js
|
709 |
+
* message.writeHead(200, { 'Content-Type': 'text/plain',
|
710 |
+
* 'Trailer': 'Content-MD5' });
|
711 |
+
* message.write(fileData);
|
712 |
+
* message.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });
|
713 |
+
* message.end();
|
714 |
+
* ```
|
715 |
+
*
|
716 |
+
* Attempting to set a header field name or value that contains invalid characters
|
717 |
+
* will result in a `TypeError` being thrown.
|
718 |
+
* @since v0.3.0
|
719 |
+
*/
|
720 |
+
addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
|
721 |
+
/**
|
722 |
+
* Flushes the message headers.
|
723 |
+
*
|
724 |
+
* For efficiency reason, Node.js normally buffers the message headers
|
725 |
+
* until `outgoingMessage.end()` is called or the first chunk of message data
|
726 |
+
* is written. It then tries to pack the headers and data into a single TCP
|
727 |
+
* packet.
|
728 |
+
*
|
729 |
+
* It is usually desired (it saves a TCP round-trip), but not when the first
|
730 |
+
* data is not sent until possibly much later. `outgoingMessage.flushHeaders()` bypasses the optimization and kickstarts the message.
|
731 |
+
* @since v1.6.0
|
732 |
+
*/
|
733 |
+
flushHeaders(): void;
|
734 |
+
}
|
735 |
+
/**
|
736 |
+
* This object is created internally by an HTTP server, not by the user. It is
|
737 |
+
* passed as the second parameter to the `'request'` event.
|
738 |
+
* @since v0.1.17
|
739 |
+
*/
|
740 |
+
class ServerResponse<Request extends IncomingMessage = IncomingMessage> extends OutgoingMessage<Request> {
|
741 |
+
/**
|
742 |
+
* When using implicit headers (not calling `response.writeHead()` explicitly),
|
743 |
+
* this property controls the status code that will be sent to the client when
|
744 |
+
* the headers get flushed.
|
745 |
+
*
|
746 |
+
* ```js
|
747 |
+
* response.statusCode = 404;
|
748 |
+
* ```
|
749 |
+
*
|
750 |
+
* After response header was sent to the client, this property indicates the
|
751 |
+
* status code which was sent out.
|
752 |
+
* @since v0.4.0
|
753 |
+
*/
|
754 |
+
statusCode: number;
|
755 |
+
/**
|
756 |
+
* When using implicit headers (not calling `response.writeHead()` explicitly),
|
757 |
+
* this property controls the status message that will be sent to the client when
|
758 |
+
* the headers get flushed. If this is left as `undefined` then the standard
|
759 |
+
* message for the status code will be used.
|
760 |
+
*
|
761 |
+
* ```js
|
762 |
+
* response.statusMessage = 'Not found';
|
763 |
+
* ```
|
764 |
+
*
|
765 |
+
* After response header was sent to the client, this property indicates the
|
766 |
+
* status message which was sent out.
|
767 |
+
* @since v0.11.8
|
768 |
+
*/
|
769 |
+
statusMessage: string;
|
770 |
+
/**
|
771 |
+
* If set to `true`, Node.js will check whether the `Content-Length` header value and the size of the body, in bytes, are equal.
|
772 |
+
* Mismatching the `Content-Length` header value will result
|
773 |
+
* in an `Error` being thrown, identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
|
774 |
+
* @since v18.10.0, v16.18.0
|
775 |
+
*/
|
776 |
+
strictContentLength: boolean;
|
777 |
+
constructor(req: Request);
|
778 |
+
assignSocket(socket: Socket): void;
|
779 |
+
detachSocket(socket: Socket): void;
|
780 |
+
/**
|
781 |
+
* Sends an HTTP/1.1 100 Continue message to the client, indicating that
|
782 |
+
* the request body should be sent. See the `'checkContinue'` event on `Server`.
|
783 |
+
* @since v0.3.0
|
784 |
+
*/
|
785 |
+
writeContinue(callback?: () => void): void;
|
786 |
+
/**
|
787 |
+
* Sends an HTTP/1.1 103 Early Hints message to the client with a Link header,
|
788 |
+
* indicating that the user agent can preload/preconnect the linked resources.
|
789 |
+
* The `hints` is an object containing the values of headers to be sent with
|
790 |
+
* early hints message. The optional `callback` argument will be called when
|
791 |
+
* the response message has been written.
|
792 |
+
*
|
793 |
+
* **Example**
|
794 |
+
*
|
795 |
+
* ```js
|
796 |
+
* const earlyHintsLink = '</styles.css>; rel=preload; as=style';
|
797 |
+
* response.writeEarlyHints({
|
798 |
+
* 'link': earlyHintsLink,
|
799 |
+
* });
|
800 |
+
*
|
801 |
+
* const earlyHintsLinks = [
|
802 |
+
* '</styles.css>; rel=preload; as=style',
|
803 |
+
* '</scripts.js>; rel=preload; as=script',
|
804 |
+
* ];
|
805 |
+
* response.writeEarlyHints({
|
806 |
+
* 'link': earlyHintsLinks,
|
807 |
+
* 'x-trace-id': 'id for diagnostics',
|
808 |
+
* });
|
809 |
+
*
|
810 |
+
* const earlyHintsCallback = () => console.log('early hints message sent');
|
811 |
+
* response.writeEarlyHints({
|
812 |
+
* 'link': earlyHintsLinks,
|
813 |
+
* }, earlyHintsCallback);
|
814 |
+
* ```
|
815 |
+
* @since v18.11.0
|
816 |
+
* @param hints An object containing the values of headers
|
817 |
+
* @param callback Will be called when the response message has been written
|
818 |
+
*/
|
819 |
+
writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;
|
820 |
+
/**
|
821 |
+
* Sends a response header to the request. The status code is a 3-digit HTTP
|
822 |
+
* status code, like `404`. The last argument, `headers`, are the response headers.
|
823 |
+
* Optionally one can give a human-readable `statusMessage` as the second
|
824 |
+
* argument.
|
825 |
+
*
|
826 |
+
* `headers` may be an `Array` where the keys and values are in the same list.
|
827 |
+
* It is _not_ a list of tuples. So, the even-numbered offsets are key values,
|
828 |
+
* and the odd-numbered offsets are the associated values. The array is in the same
|
829 |
+
* format as `request.rawHeaders`.
|
830 |
+
*
|
831 |
+
* Returns a reference to the `ServerResponse`, so that calls can be chained.
|
832 |
+
*
|
833 |
+
* ```js
|
834 |
+
* const body = 'hello world';
|
835 |
+
* response
|
836 |
+
* .writeHead(200, {
|
837 |
+
* 'Content-Length': Buffer.byteLength(body),
|
838 |
+
* 'Content-Type': 'text/plain',
|
839 |
+
* })
|
840 |
+
* .end(body);
|
841 |
+
* ```
|
842 |
+
*
|
843 |
+
* This method must only be called once on a message and it must
|
844 |
+
* be called before `response.end()` is called.
|
845 |
+
*
|
846 |
+
* If `response.write()` or `response.end()` are called before calling
|
847 |
+
* this, the implicit/mutable headers will be calculated and call this function.
|
848 |
+
*
|
849 |
+
* When headers have been set with `response.setHeader()`, they will be merged
|
850 |
+
* with any headers passed to `response.writeHead()`, with the headers passed
|
851 |
+
* to `response.writeHead()` given precedence.
|
852 |
+
*
|
853 |
+
* If this method is called and `response.setHeader()` has not been called,
|
854 |
+
* it will directly write the supplied header values onto the network channel
|
855 |
+
* without caching internally, and the `response.getHeader()` on the header
|
856 |
+
* will not yield the expected result. If progressive population of headers is
|
857 |
+
* desired with potential future retrieval and modification, use `response.setHeader()` instead.
|
858 |
+
*
|
859 |
+
* ```js
|
860 |
+
* // Returns content-type = text/plain
|
861 |
+
* const server = http.createServer((req, res) => {
|
862 |
+
* res.setHeader('Content-Type', 'text/html');
|
863 |
+
* res.setHeader('X-Foo', 'bar');
|
864 |
+
* res.writeHead(200, { 'Content-Type': 'text/plain' });
|
865 |
+
* res.end('ok');
|
866 |
+
* });
|
867 |
+
* ```
|
868 |
+
*
|
869 |
+
* `Content-Length` is read in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js
|
870 |
+
* will check whether `Content-Length` and the length of the body which has
|
871 |
+
* been transmitted are equal or not.
|
872 |
+
*
|
873 |
+
* Attempting to set a header field name or value that contains invalid characters
|
874 |
+
* will result in a \[`Error`\]\[\] being thrown.
|
875 |
+
* @since v0.1.30
|
876 |
+
*/
|
877 |
+
writeHead(
|
878 |
+
statusCode: number,
|
879 |
+
statusMessage?: string,
|
880 |
+
headers?: OutgoingHttpHeaders | OutgoingHttpHeader[],
|
881 |
+
): this;
|
882 |
+
writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
|
883 |
+
/**
|
884 |
+
* Sends a HTTP/1.1 102 Processing message to the client, indicating that
|
885 |
+
* the request body should be sent.
|
886 |
+
* @since v10.0.0
|
887 |
+
*/
|
888 |
+
writeProcessing(): void;
|
889 |
+
}
|
890 |
+
interface InformationEvent {
|
891 |
+
statusCode: number;
|
892 |
+
statusMessage: string;
|
893 |
+
httpVersion: string;
|
894 |
+
httpVersionMajor: number;
|
895 |
+
httpVersionMinor: number;
|
896 |
+
headers: IncomingHttpHeaders;
|
897 |
+
rawHeaders: string[];
|
898 |
+
}
|
899 |
+
/**
|
900 |
+
* This object is created internally and returned from {@link request}. It
|
901 |
+
* represents an _in-progress_ request whose header has already been queued. The
|
902 |
+
* header is still mutable using the `setHeader(name, value)`, `getHeader(name)`, `removeHeader(name)` API. The actual header will
|
903 |
+
* be sent along with the first data chunk or when calling `request.end()`.
|
904 |
+
*
|
905 |
+
* To get the response, add a listener for `'response'` to the request object. `'response'` will be emitted from the request object when the response
|
906 |
+
* headers have been received. The `'response'` event is executed with one
|
907 |
+
* argument which is an instance of {@link IncomingMessage}.
|
908 |
+
*
|
909 |
+
* During the `'response'` event, one can add listeners to the
|
910 |
+
* response object; particularly to listen for the `'data'` event.
|
911 |
+
*
|
912 |
+
* If no `'response'` handler is added, then the response will be
|
913 |
+
* entirely discarded. However, if a `'response'` event handler is added,
|
914 |
+
* then the data from the response object **must** be consumed, either by
|
915 |
+
* calling `response.read()` whenever there is a `'readable'` event, or
|
916 |
+
* by adding a `'data'` handler, or by calling the `.resume()` method.
|
917 |
+
* Until the data is consumed, the `'end'` event will not fire. Also, until
|
918 |
+
* the data is read it will consume memory that can eventually lead to a
|
919 |
+
* 'process out of memory' error.
|
920 |
+
*
|
921 |
+
* For backward compatibility, `res` will only emit `'error'` if there is an `'error'` listener registered.
|
922 |
+
*
|
923 |
+
* Set `Content-Length` header to limit the response body size.
|
924 |
+
* If `response.strictContentLength` is set to `true`, mismatching the `Content-Length` header value will result in an `Error` being thrown,
|
925 |
+
* identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
|
926 |
+
*
|
927 |
+
* `Content-Length` value should be in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes.
|
928 |
+
* @since v0.1.17
|
929 |
+
*/
|
930 |
+
class ClientRequest extends OutgoingMessage {
|
931 |
+
/**
|
932 |
+
* The `request.aborted` property will be `true` if the request has
|
933 |
+
* been aborted.
|
934 |
+
* @since v0.11.14
|
935 |
+
* @deprecated Since v17.0.0, v16.12.0 - Check `destroyed` instead.
|
936 |
+
*/
|
937 |
+
aborted: boolean;
|
938 |
+
/**
|
939 |
+
* The request host.
|
940 |
+
* @since v14.5.0, v12.19.0
|
941 |
+
*/
|
942 |
+
host: string;
|
943 |
+
/**
|
944 |
+
* The request protocol.
|
945 |
+
* @since v14.5.0, v12.19.0
|
946 |
+
*/
|
947 |
+
protocol: string;
|
948 |
+
/**
|
949 |
+
* When sending request through a keep-alive enabled agent, the underlying socket
|
950 |
+
* might be reused. But if server closes connection at unfortunate time, client
|
951 |
+
* may run into a 'ECONNRESET' error.
|
952 |
+
*
|
953 |
+
* ```js
|
954 |
+
* import http from 'node:http';
|
955 |
+
*
|
956 |
+
* // Server has a 5 seconds keep-alive timeout by default
|
957 |
+
* http
|
958 |
+
* .createServer((req, res) => {
|
959 |
+
* res.write('hello\n');
|
960 |
+
* res.end();
|
961 |
+
* })
|
962 |
+
* .listen(3000);
|
963 |
+
*
|
964 |
+
* setInterval(() => {
|
965 |
+
* // Adapting a keep-alive agent
|
966 |
+
* http.get('http://localhost:3000', { agent }, (res) => {
|
967 |
+
* res.on('data', (data) => {
|
968 |
+
* // Do nothing
|
969 |
+
* });
|
970 |
+
* });
|
971 |
+
* }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout
|
972 |
+
* ```
|
973 |
+
*
|
974 |
+
* By marking a request whether it reused socket or not, we can do
|
975 |
+
* automatic error retry base on it.
|
976 |
+
*
|
977 |
+
* ```js
|
978 |
+
* import http from 'node:http';
|
979 |
+
* const agent = new http.Agent({ keepAlive: true });
|
980 |
+
*
|
981 |
+
* function retriableRequest() {
|
982 |
+
* const req = http
|
983 |
+
* .get('http://localhost:3000', { agent }, (res) => {
|
984 |
+
* // ...
|
985 |
+
* })
|
986 |
+
* .on('error', (err) => {
|
987 |
+
* // Check if retry is needed
|
988 |
+
* if (req.reusedSocket && err.code === 'ECONNRESET') {
|
989 |
+
* retriableRequest();
|
990 |
+
* }
|
991 |
+
* });
|
992 |
+
* }
|
993 |
+
*
|
994 |
+
* retriableRequest();
|
995 |
+
* ```
|
996 |
+
* @since v13.0.0, v12.16.0
|
997 |
+
*/
|
998 |
+
reusedSocket: boolean;
|
999 |
+
/**
|
1000 |
+
* Limits maximum response headers count. If set to 0, no limit will be applied.
|
1001 |
+
*/
|
1002 |
+
maxHeadersCount: number;
|
1003 |
+
constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);
|
1004 |
+
/**
|
1005 |
+
* The request method.
|
1006 |
+
* @since v0.1.97
|
1007 |
+
*/
|
1008 |
+
method: string;
|
1009 |
+
/**
|
1010 |
+
* The request path.
|
1011 |
+
* @since v0.4.0
|
1012 |
+
*/
|
1013 |
+
path: string;
|
1014 |
+
/**
|
1015 |
+
* Marks the request as aborting. Calling this will cause remaining data
|
1016 |
+
* in the response to be dropped and the socket to be destroyed.
|
1017 |
+
* @since v0.3.8
|
1018 |
+
* @deprecated Since v14.1.0,v13.14.0 - Use `destroy` instead.
|
1019 |
+
*/
|
1020 |
+
abort(): void;
|
1021 |
+
onSocket(socket: Socket): void;
|
1022 |
+
/**
|
1023 |
+
* Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called.
|
1024 |
+
* @since v0.5.9
|
1025 |
+
* @param timeout Milliseconds before a request times out.
|
1026 |
+
* @param callback Optional function to be called when a timeout occurs. Same as binding to the `'timeout'` event.
|
1027 |
+
*/
|
1028 |
+
setTimeout(timeout: number, callback?: () => void): this;
|
1029 |
+
/**
|
1030 |
+
* Once a socket is assigned to this request and is connected `socket.setNoDelay()` will be called.
|
1031 |
+
* @since v0.5.9
|
1032 |
+
*/
|
1033 |
+
setNoDelay(noDelay?: boolean): void;
|
1034 |
+
/**
|
1035 |
+
* Once a socket is assigned to this request and is connected `socket.setKeepAlive()` will be called.
|
1036 |
+
* @since v0.5.9
|
1037 |
+
*/
|
1038 |
+
setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
|
1039 |
+
/**
|
1040 |
+
* Returns an array containing the unique names of the current outgoing raw
|
1041 |
+
* headers. Header names are returned with their exact casing being set.
|
1042 |
+
*
|
1043 |
+
* ```js
|
1044 |
+
* request.setHeader('Foo', 'bar');
|
1045 |
+
* request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
1046 |
+
*
|
1047 |
+
* const headerNames = request.getRawHeaderNames();
|
1048 |
+
* // headerNames === ['Foo', 'Set-Cookie']
|
1049 |
+
* ```
|
1050 |
+
* @since v15.13.0, v14.17.0
|
1051 |
+
*/
|
1052 |
+
getRawHeaderNames(): string[];
|
1053 |
+
/**
|
1054 |
+
* @deprecated
|
1055 |
+
*/
|
1056 |
+
addListener(event: "abort", listener: () => void): this;
|
1057 |
+
addListener(
|
1058 |
+
event: "connect",
|
1059 |
+
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
1060 |
+
): this;
|
1061 |
+
addListener(event: "continue", listener: () => void): this;
|
1062 |
+
addListener(event: "information", listener: (info: InformationEvent) => void): this;
|
1063 |
+
addListener(event: "response", listener: (response: IncomingMessage) => void): this;
|
1064 |
+
addListener(event: "socket", listener: (socket: Socket) => void): this;
|
1065 |
+
addListener(event: "timeout", listener: () => void): this;
|
1066 |
+
addListener(
|
1067 |
+
event: "upgrade",
|
1068 |
+
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
1069 |
+
): this;
|
1070 |
+
addListener(event: "close", listener: () => void): this;
|
1071 |
+
addListener(event: "drain", listener: () => void): this;
|
1072 |
+
addListener(event: "error", listener: (err: Error) => void): this;
|
1073 |
+
addListener(event: "finish", listener: () => void): this;
|
1074 |
+
addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
|
1075 |
+
addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
1076 |
+
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
1077 |
+
/**
|
1078 |
+
* @deprecated
|
1079 |
+
*/
|
1080 |
+
on(event: "abort", listener: () => void): this;
|
1081 |
+
on(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
1082 |
+
on(event: "continue", listener: () => void): this;
|
1083 |
+
on(event: "information", listener: (info: InformationEvent) => void): this;
|
1084 |
+
on(event: "response", listener: (response: IncomingMessage) => void): this;
|
1085 |
+
on(event: "socket", listener: (socket: Socket) => void): this;
|
1086 |
+
on(event: "timeout", listener: () => void): this;
|
1087 |
+
on(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
1088 |
+
on(event: "close", listener: () => void): this;
|
1089 |
+
on(event: "drain", listener: () => void): this;
|
1090 |
+
on(event: "error", listener: (err: Error) => void): this;
|
1091 |
+
on(event: "finish", listener: () => void): this;
|
1092 |
+
on(event: "pipe", listener: (src: stream.Readable) => void): this;
|
1093 |
+
on(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
1094 |
+
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
1095 |
+
/**
|
1096 |
+
* @deprecated
|
1097 |
+
*/
|
1098 |
+
once(event: "abort", listener: () => void): this;
|
1099 |
+
once(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
1100 |
+
once(event: "continue", listener: () => void): this;
|
1101 |
+
once(event: "information", listener: (info: InformationEvent) => void): this;
|
1102 |
+
once(event: "response", listener: (response: IncomingMessage) => void): this;
|
1103 |
+
once(event: "socket", listener: (socket: Socket) => void): this;
|
1104 |
+
once(event: "timeout", listener: () => void): this;
|
1105 |
+
once(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
1106 |
+
once(event: "close", listener: () => void): this;
|
1107 |
+
once(event: "drain", listener: () => void): this;
|
1108 |
+
once(event: "error", listener: (err: Error) => void): this;
|
1109 |
+
once(event: "finish", listener: () => void): this;
|
1110 |
+
once(event: "pipe", listener: (src: stream.Readable) => void): this;
|
1111 |
+
once(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
1112 |
+
once(event: string | symbol, listener: (...args: any[]) => void): this;
|
1113 |
+
/**
|
1114 |
+
* @deprecated
|
1115 |
+
*/
|
1116 |
+
prependListener(event: "abort", listener: () => void): this;
|
1117 |
+
prependListener(
|
1118 |
+
event: "connect",
|
1119 |
+
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
1120 |
+
): this;
|
1121 |
+
prependListener(event: "continue", listener: () => void): this;
|
1122 |
+
prependListener(event: "information", listener: (info: InformationEvent) => void): this;
|
1123 |
+
prependListener(event: "response", listener: (response: IncomingMessage) => void): this;
|
1124 |
+
prependListener(event: "socket", listener: (socket: Socket) => void): this;
|
1125 |
+
prependListener(event: "timeout", listener: () => void): this;
|
1126 |
+
prependListener(
|
1127 |
+
event: "upgrade",
|
1128 |
+
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
1129 |
+
): this;
|
1130 |
+
prependListener(event: "close", listener: () => void): this;
|
1131 |
+
prependListener(event: "drain", listener: () => void): this;
|
1132 |
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
1133 |
+
prependListener(event: "finish", listener: () => void): this;
|
1134 |
+
prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
|
1135 |
+
prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
1136 |
+
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
1137 |
+
/**
|
1138 |
+
* @deprecated
|
1139 |
+
*/
|
1140 |
+
prependOnceListener(event: "abort", listener: () => void): this;
|
1141 |
+
prependOnceListener(
|
1142 |
+
event: "connect",
|
1143 |
+
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
1144 |
+
): this;
|
1145 |
+
prependOnceListener(event: "continue", listener: () => void): this;
|
1146 |
+
prependOnceListener(event: "information", listener: (info: InformationEvent) => void): this;
|
1147 |
+
prependOnceListener(event: "response", listener: (response: IncomingMessage) => void): this;
|
1148 |
+
prependOnceListener(event: "socket", listener: (socket: Socket) => void): this;
|
1149 |
+
prependOnceListener(event: "timeout", listener: () => void): this;
|
1150 |
+
prependOnceListener(
|
1151 |
+
event: "upgrade",
|
1152 |
+
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
1153 |
+
): this;
|
1154 |
+
prependOnceListener(event: "close", listener: () => void): this;
|
1155 |
+
prependOnceListener(event: "drain", listener: () => void): this;
|
1156 |
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
1157 |
+
prependOnceListener(event: "finish", listener: () => void): this;
|
1158 |
+
prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this;
|
1159 |
+
prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
|
1160 |
+
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
1161 |
+
}
|
1162 |
+
/**
|
1163 |
+
* An `IncomingMessage` object is created by {@link Server} or {@link ClientRequest} and passed as the first argument to the `'request'` and `'response'` event respectively. It may be used to
|
1164 |
+
* access response
|
1165 |
+
* status, headers, and data.
|
1166 |
+
*
|
1167 |
+
* Different from its `socket` value which is a subclass of `stream.Duplex`, the `IncomingMessage` itself extends `stream.Readable` and is created separately to
|
1168 |
+
* parse and emit the incoming HTTP headers and payload, as the underlying socket
|
1169 |
+
* may be reused multiple times in case of keep-alive.
|
1170 |
+
* @since v0.1.17
|
1171 |
+
*/
|
1172 |
+
class IncomingMessage extends stream.Readable {
|
1173 |
+
constructor(socket: Socket);
|
1174 |
+
/**
|
1175 |
+
* The `message.aborted` property will be `true` if the request has
|
1176 |
+
* been aborted.
|
1177 |
+
* @since v10.1.0
|
1178 |
+
* @deprecated Since v17.0.0,v16.12.0 - Check `message.destroyed` from <a href="stream.html#class-streamreadable" class="type">stream.Readable</a>.
|
1179 |
+
*/
|
1180 |
+
aborted: boolean;
|
1181 |
+
/**
|
1182 |
+
* In case of server request, the HTTP version sent by the client. In the case of
|
1183 |
+
* client response, the HTTP version of the connected-to server.
|
1184 |
+
* Probably either `'1.1'` or `'1.0'`.
|
1185 |
+
*
|
1186 |
+
* Also `message.httpVersionMajor` is the first integer and `message.httpVersionMinor` is the second.
|
1187 |
+
* @since v0.1.1
|
1188 |
+
*/
|
1189 |
+
httpVersion: string;
|
1190 |
+
httpVersionMajor: number;
|
1191 |
+
httpVersionMinor: number;
|
1192 |
+
/**
|
1193 |
+
* The `message.complete` property will be `true` if a complete HTTP message has
|
1194 |
+
* been received and successfully parsed.
|
1195 |
+
*
|
1196 |
+
* This property is particularly useful as a means of determining if a client or
|
1197 |
+
* server fully transmitted a message before a connection was terminated:
|
1198 |
+
*
|
1199 |
+
* ```js
|
1200 |
+
* const req = http.request({
|
1201 |
+
* host: '127.0.0.1',
|
1202 |
+
* port: 8080,
|
1203 |
+
* method: 'POST',
|
1204 |
+
* }, (res) => {
|
1205 |
+
* res.resume();
|
1206 |
+
* res.on('end', () => {
|
1207 |
+
* if (!res.complete)
|
1208 |
+
* console.error(
|
1209 |
+
* 'The connection was terminated while the message was still being sent');
|
1210 |
+
* });
|
1211 |
+
* });
|
1212 |
+
* ```
|
1213 |
+
* @since v0.3.0
|
1214 |
+
*/
|
1215 |
+
complete: boolean;
|
1216 |
+
/**
|
1217 |
+
* Alias for `message.socket`.
|
1218 |
+
* @since v0.1.90
|
1219 |
+
* @deprecated Since v16.0.0 - Use `socket`.
|
1220 |
+
*/
|
1221 |
+
connection: Socket;
|
1222 |
+
/**
|
1223 |
+
* The `net.Socket` object associated with the connection.
|
1224 |
+
*
|
1225 |
+
* With HTTPS support, use `request.socket.getPeerCertificate()` to obtain the
|
1226 |
+
* client's authentication details.
|
1227 |
+
*
|
1228 |
+
* This property is guaranteed to be an instance of the `net.Socket` class,
|
1229 |
+
* a subclass of `stream.Duplex`, unless the user specified a socket
|
1230 |
+
* type other than `net.Socket` or internally nulled.
|
1231 |
+
* @since v0.3.0
|
1232 |
+
*/
|
1233 |
+
socket: Socket;
|
1234 |
+
/**
|
1235 |
+
* The request/response headers object.
|
1236 |
+
*
|
1237 |
+
* Key-value pairs of header names and values. Header names are lower-cased.
|
1238 |
+
*
|
1239 |
+
* ```js
|
1240 |
+
* // Prints something like:
|
1241 |
+
* //
|
1242 |
+
* // { 'user-agent': 'curl/7.22.0',
|
1243 |
+
* // host: '127.0.0.1:8000',
|
1244 |
+
* // accept: '*' }
|
1245 |
+
* console.log(request.headers);
|
1246 |
+
* ```
|
1247 |
+
*
|
1248 |
+
* Duplicates in raw headers are handled in the following ways, depending on the
|
1249 |
+
* header name:
|
1250 |
+
*
|
1251 |
+
* * Duplicates of `age`, `authorization`, `content-length`, `content-type`, `etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`, `last-modified`, `location`,
|
1252 |
+
* `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, `server`, or `user-agent` are discarded.
|
1253 |
+
* To allow duplicate values of the headers listed above to be joined,
|
1254 |
+
* use the option `joinDuplicateHeaders` in {@link request} and {@link createServer}. See RFC 9110 Section 5.3 for more
|
1255 |
+
* information.
|
1256 |
+
* * `set-cookie` is always an array. Duplicates are added to the array.
|
1257 |
+
* * For duplicate `cookie` headers, the values are joined together with `; `.
|
1258 |
+
* * For all other headers, the values are joined together with `, `.
|
1259 |
+
* @since v0.1.5
|
1260 |
+
*/
|
1261 |
+
headers: IncomingHttpHeaders;
|
1262 |
+
/**
|
1263 |
+
* Similar to `message.headers`, but there is no join logic and the values are
|
1264 |
+
* always arrays of strings, even for headers received just once.
|
1265 |
+
*
|
1266 |
+
* ```js
|
1267 |
+
* // Prints something like:
|
1268 |
+
* //
|
1269 |
+
* // { 'user-agent': ['curl/7.22.0'],
|
1270 |
+
* // host: ['127.0.0.1:8000'],
|
1271 |
+
* // accept: ['*'] }
|
1272 |
+
* console.log(request.headersDistinct);
|
1273 |
+
* ```
|
1274 |
+
* @since v18.3.0, v16.17.0
|
1275 |
+
*/
|
1276 |
+
headersDistinct: NodeJS.Dict<string[]>;
|
1277 |
+
/**
|
1278 |
+
* The raw request/response headers list exactly as they were received.
|
1279 |
+
*
|
1280 |
+
* The keys and values are in the same list. It is _not_ a
|
1281 |
+
* list of tuples. So, the even-numbered offsets are key values, and the
|
1282 |
+
* odd-numbered offsets are the associated values.
|
1283 |
+
*
|
1284 |
+
* Header names are not lowercased, and duplicates are not merged.
|
1285 |
+
*
|
1286 |
+
* ```js
|
1287 |
+
* // Prints something like:
|
1288 |
+
* //
|
1289 |
+
* // [ 'user-agent',
|
1290 |
+
* // 'this is invalid because there can be only one',
|
1291 |
+
* // 'User-Agent',
|
1292 |
+
* // 'curl/7.22.0',
|
1293 |
+
* // 'Host',
|
1294 |
+
* // '127.0.0.1:8000',
|
1295 |
+
* // 'ACCEPT',
|
1296 |
+
* // '*' ]
|
1297 |
+
* console.log(request.rawHeaders);
|
1298 |
+
* ```
|
1299 |
+
* @since v0.11.6
|
1300 |
+
*/
|
1301 |
+
rawHeaders: string[];
|
1302 |
+
/**
|
1303 |
+
* The request/response trailers object. Only populated at the `'end'` event.
|
1304 |
+
* @since v0.3.0
|
1305 |
+
*/
|
1306 |
+
trailers: NodeJS.Dict<string>;
|
1307 |
+
/**
|
1308 |
+
* Similar to `message.trailers`, but there is no join logic and the values are
|
1309 |
+
* always arrays of strings, even for headers received just once.
|
1310 |
+
* Only populated at the `'end'` event.
|
1311 |
+
* @since v18.3.0, v16.17.0
|
1312 |
+
*/
|
1313 |
+
trailersDistinct: NodeJS.Dict<string[]>;
|
1314 |
+
/**
|
1315 |
+
* The raw request/response trailer keys and values exactly as they were
|
1316 |
+
* received. Only populated at the `'end'` event.
|
1317 |
+
* @since v0.11.6
|
1318 |
+
*/
|
1319 |
+
rawTrailers: string[];
|
1320 |
+
/**
|
1321 |
+
* Calls `message.socket.setTimeout(msecs, callback)`.
|
1322 |
+
* @since v0.5.9
|
1323 |
+
*/
|
1324 |
+
setTimeout(msecs: number, callback?: () => void): this;
|
1325 |
+
/**
|
1326 |
+
* **Only valid for request obtained from {@link Server}.**
|
1327 |
+
*
|
1328 |
+
* The request method as a string. Read only. Examples: `'GET'`, `'DELETE'`.
|
1329 |
+
* @since v0.1.1
|
1330 |
+
*/
|
1331 |
+
method?: string | undefined;
|
1332 |
+
/**
|
1333 |
+
* **Only valid for request obtained from {@link Server}.**
|
1334 |
+
*
|
1335 |
+
* Request URL string. This contains only the URL that is present in the actual
|
1336 |
+
* HTTP request. Take the following request:
|
1337 |
+
*
|
1338 |
+
* ```http
|
1339 |
+
* GET /status?name=ryan HTTP/1.1
|
1340 |
+
* Accept: text/plain
|
1341 |
+
* ```
|
1342 |
+
*
|
1343 |
+
* To parse the URL into its parts:
|
1344 |
+
*
|
1345 |
+
* ```js
|
1346 |
+
* new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);
|
1347 |
+
* ```
|
1348 |
+
*
|
1349 |
+
* When `request.url` is `'/status?name=ryan'` and `process.env.HOST` is undefined:
|
1350 |
+
*
|
1351 |
+
* ```console
|
1352 |
+
* $ node
|
1353 |
+
* > new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);
|
1354 |
+
* URL {
|
1355 |
+
* href: 'http://localhost/status?name=ryan',
|
1356 |
+
* origin: 'http://localhost',
|
1357 |
+
* protocol: 'http:',
|
1358 |
+
* username: '',
|
1359 |
+
* password: '',
|
1360 |
+
* host: 'localhost',
|
1361 |
+
* hostname: 'localhost',
|
1362 |
+
* port: '',
|
1363 |
+
* pathname: '/status',
|
1364 |
+
* search: '?name=ryan',
|
1365 |
+
* searchParams: URLSearchParams { 'name' => 'ryan' },
|
1366 |
+
* hash: ''
|
1367 |
+
* }
|
1368 |
+
* ```
|
1369 |
+
*
|
1370 |
+
* Ensure that you set `process.env.HOST` to the server's host name, or consider replacing this part entirely. If using `req.headers.host`, ensure proper
|
1371 |
+
* validation is used, as clients may specify a custom `Host` header.
|
1372 |
+
* @since v0.1.90
|
1373 |
+
*/
|
1374 |
+
url?: string | undefined;
|
1375 |
+
/**
|
1376 |
+
* **Only valid for response obtained from {@link ClientRequest}.**
|
1377 |
+
*
|
1378 |
+
* The 3-digit HTTP response status code. E.G. `404`.
|
1379 |
+
* @since v0.1.1
|
1380 |
+
*/
|
1381 |
+
statusCode?: number | undefined;
|
1382 |
+
/**
|
1383 |
+
* **Only valid for response obtained from {@link ClientRequest}.**
|
1384 |
+
*
|
1385 |
+
* The HTTP response status message (reason phrase). E.G. `OK` or `Internal Server Error`.
|
1386 |
+
* @since v0.11.10
|
1387 |
+
*/
|
1388 |
+
statusMessage?: string | undefined;
|
1389 |
+
/**
|
1390 |
+
* Calls `destroy()` on the socket that received the `IncomingMessage`. If `error` is provided, an `'error'` event is emitted on the socket and `error` is passed
|
1391 |
+
* as an argument to any listeners on the event.
|
1392 |
+
* @since v0.3.0
|
1393 |
+
*/
|
1394 |
+
destroy(error?: Error): this;
|
1395 |
+
}
|
1396 |
+
interface AgentOptions extends Partial<TcpSocketConnectOpts> {
|
1397 |
+
/**
|
1398 |
+
* Keep sockets around in a pool to be used by other requests in the future. Default = false
|
1399 |
+
*/
|
1400 |
+
keepAlive?: boolean | undefined;
|
1401 |
+
/**
|
1402 |
+
* When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
|
1403 |
+
* Only relevant if keepAlive is set to true.
|
1404 |
+
*/
|
1405 |
+
keepAliveMsecs?: number | undefined;
|
1406 |
+
/**
|
1407 |
+
* Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
|
1408 |
+
*/
|
1409 |
+
maxSockets?: number | undefined;
|
1410 |
+
/**
|
1411 |
+
* Maximum number of sockets allowed for all hosts in total. Each request will use a new socket until the maximum is reached. Default: Infinity.
|
1412 |
+
*/
|
1413 |
+
maxTotalSockets?: number | undefined;
|
1414 |
+
/**
|
1415 |
+
* Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
|
1416 |
+
*/
|
1417 |
+
maxFreeSockets?: number | undefined;
|
1418 |
+
/**
|
1419 |
+
* Socket timeout in milliseconds. This will set the timeout after the socket is connected.
|
1420 |
+
*/
|
1421 |
+
timeout?: number | undefined;
|
1422 |
+
/**
|
1423 |
+
* Scheduling strategy to apply when picking the next free socket to use.
|
1424 |
+
* @default `lifo`
|
1425 |
+
*/
|
1426 |
+
scheduling?: "fifo" | "lifo" | undefined;
|
1427 |
+
}
|
1428 |
+
/**
|
1429 |
+
* An `Agent` is responsible for managing connection persistence
|
1430 |
+
* and reuse for HTTP clients. It maintains a queue of pending requests
|
1431 |
+
* for a given host and port, reusing a single socket connection for each
|
1432 |
+
* until the queue is empty, at which time the socket is either destroyed
|
1433 |
+
* or put into a pool where it is kept to be used again for requests to the
|
1434 |
+
* same host and port. Whether it is destroyed or pooled depends on the `keepAlive` `option`.
|
1435 |
+
*
|
1436 |
+
* Pooled connections have TCP Keep-Alive enabled for them, but servers may
|
1437 |
+
* still close idle connections, in which case they will be removed from the
|
1438 |
+
* pool and a new connection will be made when a new HTTP request is made for
|
1439 |
+
* that host and port. Servers may also refuse to allow multiple requests
|
1440 |
+
* over the same connection, in which case the connection will have to be
|
1441 |
+
* remade for every request and cannot be pooled. The `Agent` will still make
|
1442 |
+
* the requests to that server, but each one will occur over a new connection.
|
1443 |
+
*
|
1444 |
+
* When a connection is closed by the client or the server, it is removed
|
1445 |
+
* from the pool. Any unused sockets in the pool will be unrefed so as not
|
1446 |
+
* to keep the Node.js process running when there are no outstanding requests.
|
1447 |
+
* (see `socket.unref()`).
|
1448 |
+
*
|
1449 |
+
* It is good practice, to `destroy()` an `Agent` instance when it is no
|
1450 |
+
* longer in use, because unused sockets consume OS resources.
|
1451 |
+
*
|
1452 |
+
* Sockets are removed from an agent when the socket emits either
|
1453 |
+
* a `'close'` event or an `'agentRemove'` event. When intending to keep one
|
1454 |
+
* HTTP request open for a long time without keeping it in the agent, something
|
1455 |
+
* like the following may be done:
|
1456 |
+
*
|
1457 |
+
* ```js
|
1458 |
+
* http.get(options, (res) => {
|
1459 |
+
* // Do stuff
|
1460 |
+
* }).on('socket', (socket) => {
|
1461 |
+
* socket.emit('agentRemove');
|
1462 |
+
* });
|
1463 |
+
* ```
|
1464 |
+
*
|
1465 |
+
* An agent may also be used for an individual request. By providing `{agent: false}` as an option to the `http.get()` or `http.request()` functions, a one-time use `Agent` with default options
|
1466 |
+
* will be used
|
1467 |
+
* for the client connection.
|
1468 |
+
*
|
1469 |
+
* `agent:false`:
|
1470 |
+
*
|
1471 |
+
* ```js
|
1472 |
+
* http.get({
|
1473 |
+
* hostname: 'localhost',
|
1474 |
+
* port: 80,
|
1475 |
+
* path: '/',
|
1476 |
+
* agent: false, // Create a new agent just for this one request
|
1477 |
+
* }, (res) => {
|
1478 |
+
* // Do stuff with response
|
1479 |
+
* });
|
1480 |
+
* ```
|
1481 |
+
*
|
1482 |
+
* `options` in [`socket.connect()`](https://nodejs.org/docs/latest-v22.x/api/net.html#socketconnectoptions-connectlistener) are also supported.
|
1483 |
+
*
|
1484 |
+
* To configure any of them, a custom {@link Agent} instance must be created.
|
1485 |
+
*
|
1486 |
+
* ```js
|
1487 |
+
* import http from 'node:http';
|
1488 |
+
* const keepAliveAgent = new http.Agent({ keepAlive: true });
|
1489 |
+
* options.agent = keepAliveAgent;
|
1490 |
+
* http.request(options, onResponseCallback)
|
1491 |
+
* ```
|
1492 |
+
* @since v0.3.4
|
1493 |
+
*/
|
1494 |
+
class Agent extends EventEmitter {
|
1495 |
+
/**
|
1496 |
+
* By default set to 256. For agents with `keepAlive` enabled, this
|
1497 |
+
* sets the maximum number of sockets that will be left open in the free
|
1498 |
+
* state.
|
1499 |
+
* @since v0.11.7
|
1500 |
+
*/
|
1501 |
+
maxFreeSockets: number;
|
1502 |
+
/**
|
1503 |
+
* By default set to `Infinity`. Determines how many concurrent sockets the agent
|
1504 |
+
* can have open per origin. Origin is the returned value of `agent.getName()`.
|
1505 |
+
* @since v0.3.6
|
1506 |
+
*/
|
1507 |
+
maxSockets: number;
|
1508 |
+
/**
|
1509 |
+
* By default set to `Infinity`. Determines how many concurrent sockets the agent
|
1510 |
+
* can have open. Unlike `maxSockets`, this parameter applies across all origins.
|
1511 |
+
* @since v14.5.0, v12.19.0
|
1512 |
+
*/
|
1513 |
+
maxTotalSockets: number;
|
1514 |
+
/**
|
1515 |
+
* An object which contains arrays of sockets currently awaiting use by
|
1516 |
+
* the agent when `keepAlive` is enabled. Do not modify.
|
1517 |
+
*
|
1518 |
+
* Sockets in the `freeSockets` list will be automatically destroyed and
|
1519 |
+
* removed from the array on `'timeout'`.
|
1520 |
+
* @since v0.11.4
|
1521 |
+
*/
|
1522 |
+
readonly freeSockets: NodeJS.ReadOnlyDict<Socket[]>;
|
1523 |
+
/**
|
1524 |
+
* An object which contains arrays of sockets currently in use by the
|
1525 |
+
* agent. Do not modify.
|
1526 |
+
* @since v0.3.6
|
1527 |
+
*/
|
1528 |
+
readonly sockets: NodeJS.ReadOnlyDict<Socket[]>;
|
1529 |
+
/**
|
1530 |
+
* An object which contains queues of requests that have not yet been assigned to
|
1531 |
+
* sockets. Do not modify.
|
1532 |
+
* @since v0.5.9
|
1533 |
+
*/
|
1534 |
+
readonly requests: NodeJS.ReadOnlyDict<IncomingMessage[]>;
|
1535 |
+
constructor(opts?: AgentOptions);
|
1536 |
+
/**
|
1537 |
+
* Destroy any sockets that are currently in use by the agent.
|
1538 |
+
*
|
1539 |
+
* It is usually not necessary to do this. However, if using an
|
1540 |
+
* agent with `keepAlive` enabled, then it is best to explicitly shut down
|
1541 |
+
* the agent when it is no longer needed. Otherwise,
|
1542 |
+
* sockets might stay open for quite a long time before the server
|
1543 |
+
* terminates them.
|
1544 |
+
* @since v0.11.4
|
1545 |
+
*/
|
1546 |
+
destroy(): void;
|
1547 |
+
}
|
1548 |
+
const METHODS: string[];
|
1549 |
+
const STATUS_CODES: {
|
1550 |
+
[errorCode: number]: string | undefined;
|
1551 |
+
[errorCode: string]: string | undefined;
|
1552 |
+
};
|
1553 |
+
/**
|
1554 |
+
* Returns a new instance of {@link Server}.
|
1555 |
+
*
|
1556 |
+
* The `requestListener` is a function which is automatically
|
1557 |
+
* added to the `'request'` event.
|
1558 |
+
*
|
1559 |
+
* ```js
|
1560 |
+
* import http from 'node:http';
|
1561 |
+
*
|
1562 |
+
* // Create a local server to receive data from
|
1563 |
+
* const server = http.createServer((req, res) => {
|
1564 |
+
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
1565 |
+
* res.end(JSON.stringify({
|
1566 |
+
* data: 'Hello World!',
|
1567 |
+
* }));
|
1568 |
+
* });
|
1569 |
+
*
|
1570 |
+
* server.listen(8000);
|
1571 |
+
* ```
|
1572 |
+
*
|
1573 |
+
* ```js
|
1574 |
+
* import http from 'node:http';
|
1575 |
+
*
|
1576 |
+
* // Create a local server to receive data from
|
1577 |
+
* const server = http.createServer();
|
1578 |
+
*
|
1579 |
+
* // Listen to the request event
|
1580 |
+
* server.on('request', (request, res) => {
|
1581 |
+
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
1582 |
+
* res.end(JSON.stringify({
|
1583 |
+
* data: 'Hello World!',
|
1584 |
+
* }));
|
1585 |
+
* });
|
1586 |
+
*
|
1587 |
+
* server.listen(8000);
|
1588 |
+
* ```
|
1589 |
+
* @since v0.1.13
|
1590 |
+
*/
|
1591 |
+
function createServer<
|
1592 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
1593 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
1594 |
+
>(requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
|
1595 |
+
function createServer<
|
1596 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
1597 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
1598 |
+
>(
|
1599 |
+
options: ServerOptions<Request, Response>,
|
1600 |
+
requestListener?: RequestListener<Request, Response>,
|
1601 |
+
): Server<Request, Response>;
|
1602 |
+
// although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
|
1603 |
+
// create interface RequestOptions would make the naming more clear to developers
|
1604 |
+
interface RequestOptions extends ClientRequestArgs {}
|
1605 |
+
/**
|
1606 |
+
* `options` in `socket.connect()` are also supported.
|
1607 |
+
*
|
1608 |
+
* Node.js maintains several connections per server to make HTTP requests.
|
1609 |
+
* This function allows one to transparently issue requests.
|
1610 |
+
*
|
1611 |
+
* `url` can be a string or a `URL` object. If `url` is a
|
1612 |
+
* string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
|
1613 |
+
*
|
1614 |
+
* If both `url` and `options` are specified, the objects are merged, with the `options` properties taking precedence.
|
1615 |
+
*
|
1616 |
+
* The optional `callback` parameter will be added as a one-time listener for
|
1617 |
+
* the `'response'` event.
|
1618 |
+
*
|
1619 |
+
* `http.request()` returns an instance of the {@link ClientRequest} class. The `ClientRequest` instance is a writable stream. If one needs to
|
1620 |
+
* upload a file with a POST request, then write to the `ClientRequest` object.
|
1621 |
+
*
|
1622 |
+
* ```js
|
1623 |
+
* import http from 'node:http';
|
1624 |
+
* import { Buffer } from 'node:buffer';
|
1625 |
+
*
|
1626 |
+
* const postData = JSON.stringify({
|
1627 |
+
* 'msg': 'Hello World!',
|
1628 |
+
* });
|
1629 |
+
*
|
1630 |
+
* const options = {
|
1631 |
+
* hostname: 'www.google.com',
|
1632 |
+
* port: 80,
|
1633 |
+
* path: '/upload',
|
1634 |
+
* method: 'POST',
|
1635 |
+
* headers: {
|
1636 |
+
* 'Content-Type': 'application/json',
|
1637 |
+
* 'Content-Length': Buffer.byteLength(postData),
|
1638 |
+
* },
|
1639 |
+
* };
|
1640 |
+
*
|
1641 |
+
* const req = http.request(options, (res) => {
|
1642 |
+
* console.log(`STATUS: ${res.statusCode}`);
|
1643 |
+
* console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
|
1644 |
+
* res.setEncoding('utf8');
|
1645 |
+
* res.on('data', (chunk) => {
|
1646 |
+
* console.log(`BODY: ${chunk}`);
|
1647 |
+
* });
|
1648 |
+
* res.on('end', () => {
|
1649 |
+
* console.log('No more data in response.');
|
1650 |
+
* });
|
1651 |
+
* });
|
1652 |
+
*
|
1653 |
+
* req.on('error', (e) => {
|
1654 |
+
* console.error(`problem with request: ${e.message}`);
|
1655 |
+
* });
|
1656 |
+
*
|
1657 |
+
* // Write data to request body
|
1658 |
+
* req.write(postData);
|
1659 |
+
* req.end();
|
1660 |
+
* ```
|
1661 |
+
*
|
1662 |
+
* In the example `req.end()` was called. With `http.request()` one
|
1663 |
+
* must always call `req.end()` to signify the end of the request -
|
1664 |
+
* even if there is no data being written to the request body.
|
1665 |
+
*
|
1666 |
+
* If any error is encountered during the request (be that with DNS resolution,
|
1667 |
+
* TCP level errors, or actual HTTP parse errors) an `'error'` event is emitted
|
1668 |
+
* on the returned request object. As with all `'error'` events, if no listeners
|
1669 |
+
* are registered the error will be thrown.
|
1670 |
+
*
|
1671 |
+
* There are a few special headers that should be noted.
|
1672 |
+
*
|
1673 |
+
* * Sending a 'Connection: keep-alive' will notify Node.js that the connection to
|
1674 |
+
* the server should be persisted until the next request.
|
1675 |
+
* * Sending a 'Content-Length' header will disable the default chunked encoding.
|
1676 |
+
* * Sending an 'Expect' header will immediately send the request headers.
|
1677 |
+
* Usually, when sending 'Expect: 100-continue', both a timeout and a listener
|
1678 |
+
* for the `'continue'` event should be set. See RFC 2616 Section 8.2.3 for more
|
1679 |
+
* information.
|
1680 |
+
* * Sending an Authorization header will override using the `auth` option
|
1681 |
+
* to compute basic authentication.
|
1682 |
+
*
|
1683 |
+
* Example using a `URL` as `options`:
|
1684 |
+
*
|
1685 |
+
* ```js
|
1686 |
+
* const options = new URL('http://abc:[email protected]');
|
1687 |
+
*
|
1688 |
+
* const req = http.request(options, (res) => {
|
1689 |
+
* // ...
|
1690 |
+
* });
|
1691 |
+
* ```
|
1692 |
+
*
|
1693 |
+
* In a successful request, the following events will be emitted in the following
|
1694 |
+
* order:
|
1695 |
+
*
|
1696 |
+
* * `'socket'`
|
1697 |
+
* * `'response'`
|
1698 |
+
* * `'data'` any number of times, on the `res` object
|
1699 |
+
* (`'data'` will not be emitted at all if the response body is empty, for
|
1700 |
+
* instance, in most redirects)
|
1701 |
+
* * `'end'` on the `res` object
|
1702 |
+
* * `'close'`
|
1703 |
+
*
|
1704 |
+
* In the case of a connection error, the following events will be emitted:
|
1705 |
+
*
|
1706 |
+
* * `'socket'`
|
1707 |
+
* * `'error'`
|
1708 |
+
* * `'close'`
|
1709 |
+
*
|
1710 |
+
* In the case of a premature connection close before the response is received,
|
1711 |
+
* the following events will be emitted in the following order:
|
1712 |
+
*
|
1713 |
+
* * `'socket'`
|
1714 |
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`
|
1715 |
+
* * `'close'`
|
1716 |
+
*
|
1717 |
+
* In the case of a premature connection close after the response is received,
|
1718 |
+
* the following events will be emitted in the following order:
|
1719 |
+
*
|
1720 |
+
* * `'socket'`
|
1721 |
+
* * `'response'`
|
1722 |
+
* * `'data'` any number of times, on the `res` object
|
1723 |
+
* * (connection closed here)
|
1724 |
+
* * `'aborted'` on the `res` object
|
1725 |
+
* * `'close'`
|
1726 |
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`
|
1727 |
+
* * `'close'` on the `res` object
|
1728 |
+
*
|
1729 |
+
* If `req.destroy()` is called before a socket is assigned, the following
|
1730 |
+
* events will be emitted in the following order:
|
1731 |
+
*
|
1732 |
+
* * (`req.destroy()` called here)
|
1733 |
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
1734 |
+
* * `'close'`
|
1735 |
+
*
|
1736 |
+
* If `req.destroy()` is called before the connection succeeds, the following
|
1737 |
+
* events will be emitted in the following order:
|
1738 |
+
*
|
1739 |
+
* * `'socket'`
|
1740 |
+
* * (`req.destroy()` called here)
|
1741 |
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
1742 |
+
* * `'close'`
|
1743 |
+
*
|
1744 |
+
* If `req.destroy()` is called after the response is received, the following
|
1745 |
+
* events will be emitted in the following order:
|
1746 |
+
*
|
1747 |
+
* * `'socket'`
|
1748 |
+
* * `'response'`
|
1749 |
+
* * `'data'` any number of times, on the `res` object
|
1750 |
+
* * (`req.destroy()` called here)
|
1751 |
+
* * `'aborted'` on the `res` object
|
1752 |
+
* * `'close'`
|
1753 |
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
1754 |
+
* * `'close'` on the `res` object
|
1755 |
+
*
|
1756 |
+
* If `req.abort()` is called before a socket is assigned, the following
|
1757 |
+
* events will be emitted in the following order:
|
1758 |
+
*
|
1759 |
+
* * (`req.abort()` called here)
|
1760 |
+
* * `'abort'`
|
1761 |
+
* * `'close'`
|
1762 |
+
*
|
1763 |
+
* If `req.abort()` is called before the connection succeeds, the following
|
1764 |
+
* events will be emitted in the following order:
|
1765 |
+
*
|
1766 |
+
* * `'socket'`
|
1767 |
+
* * (`req.abort()` called here)
|
1768 |
+
* * `'abort'`
|
1769 |
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`
|
1770 |
+
* * `'close'`
|
1771 |
+
*
|
1772 |
+
* If `req.abort()` is called after the response is received, the following
|
1773 |
+
* events will be emitted in the following order:
|
1774 |
+
*
|
1775 |
+
* * `'socket'`
|
1776 |
+
* * `'response'`
|
1777 |
+
* * `'data'` any number of times, on the `res` object
|
1778 |
+
* * (`req.abort()` called here)
|
1779 |
+
* * `'abort'`
|
1780 |
+
* * `'aborted'` on the `res` object
|
1781 |
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`.
|
1782 |
+
* * `'close'`
|
1783 |
+
* * `'close'` on the `res` object
|
1784 |
+
*
|
1785 |
+
* Setting the `timeout` option or using the `setTimeout()` function will
|
1786 |
+
* not abort the request or do anything besides add a `'timeout'` event.
|
1787 |
+
*
|
1788 |
+
* Passing an `AbortSignal` and then calling `abort()` on the corresponding `AbortController` will behave the same way as calling `.destroy()` on the
|
1789 |
+
* request. Specifically, the `'error'` event will be emitted with an error with
|
1790 |
+
* the message `'AbortError: The operation was aborted'`, the code `'ABORT_ERR'` and the `cause`, if one was provided.
|
1791 |
+
* @since v0.3.6
|
1792 |
+
*/
|
1793 |
+
function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
1794 |
+
function request(
|
1795 |
+
url: string | URL,
|
1796 |
+
options: RequestOptions,
|
1797 |
+
callback?: (res: IncomingMessage) => void,
|
1798 |
+
): ClientRequest;
|
1799 |
+
/**
|
1800 |
+
* Since most requests are GET requests without bodies, Node.js provides this
|
1801 |
+
* convenience method. The only difference between this method and {@link request} is that it sets the method to GET by default and calls `req.end()` automatically. The callback must take care to
|
1802 |
+
* consume the response
|
1803 |
+
* data for reasons stated in {@link ClientRequest} section.
|
1804 |
+
*
|
1805 |
+
* The `callback` is invoked with a single argument that is an instance of {@link IncomingMessage}.
|
1806 |
+
*
|
1807 |
+
* JSON fetching example:
|
1808 |
+
*
|
1809 |
+
* ```js
|
1810 |
+
* http.get('http://localhost:8000/', (res) => {
|
1811 |
+
* const { statusCode } = res;
|
1812 |
+
* const contentType = res.headers['content-type'];
|
1813 |
+
*
|
1814 |
+
* let error;
|
1815 |
+
* // Any 2xx status code signals a successful response but
|
1816 |
+
* // here we're only checking for 200.
|
1817 |
+
* if (statusCode !== 200) {
|
1818 |
+
* error = new Error('Request Failed.\n' +
|
1819 |
+
* `Status Code: ${statusCode}`);
|
1820 |
+
* } else if (!/^application\/json/.test(contentType)) {
|
1821 |
+
* error = new Error('Invalid content-type.\n' +
|
1822 |
+
* `Expected application/json but received ${contentType}`);
|
1823 |
+
* }
|
1824 |
+
* if (error) {
|
1825 |
+
* console.error(error.message);
|
1826 |
+
* // Consume response data to free up memory
|
1827 |
+
* res.resume();
|
1828 |
+
* return;
|
1829 |
+
* }
|
1830 |
+
*
|
1831 |
+
* res.setEncoding('utf8');
|
1832 |
+
* let rawData = '';
|
1833 |
+
* res.on('data', (chunk) => { rawData += chunk; });
|
1834 |
+
* res.on('end', () => {
|
1835 |
+
* try {
|
1836 |
+
* const parsedData = JSON.parse(rawData);
|
1837 |
+
* console.log(parsedData);
|
1838 |
+
* } catch (e) {
|
1839 |
+
* console.error(e.message);
|
1840 |
+
* }
|
1841 |
+
* });
|
1842 |
+
* }).on('error', (e) => {
|
1843 |
+
* console.error(`Got error: ${e.message}`);
|
1844 |
+
* });
|
1845 |
+
*
|
1846 |
+
* // Create a local server to receive data from
|
1847 |
+
* const server = http.createServer((req, res) => {
|
1848 |
+
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
1849 |
+
* res.end(JSON.stringify({
|
1850 |
+
* data: 'Hello World!',
|
1851 |
+
* }));
|
1852 |
+
* });
|
1853 |
+
*
|
1854 |
+
* server.listen(8000);
|
1855 |
+
* ```
|
1856 |
+
* @since v0.3.6
|
1857 |
+
* @param options Accepts the same `options` as {@link request}, with the method set to GET by default.
|
1858 |
+
*/
|
1859 |
+
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
1860 |
+
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
1861 |
+
/**
|
1862 |
+
* Performs the low-level validations on the provided `name` that are done when `res.setHeader(name, value)` is called.
|
1863 |
+
*
|
1864 |
+
* Passing illegal value as `name` will result in a `TypeError` being thrown,
|
1865 |
+
* identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
|
1866 |
+
*
|
1867 |
+
* It is not necessary to use this method before passing headers to an HTTP request
|
1868 |
+
* or response. The HTTP module will automatically validate such headers.
|
1869 |
+
*
|
1870 |
+
* Example:
|
1871 |
+
*
|
1872 |
+
* ```js
|
1873 |
+
* import { validateHeaderName } from 'node:http';
|
1874 |
+
*
|
1875 |
+
* try {
|
1876 |
+
* validateHeaderName('');
|
1877 |
+
* } catch (err) {
|
1878 |
+
* console.error(err instanceof TypeError); // --> true
|
1879 |
+
* console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'
|
1880 |
+
* console.error(err.message); // --> 'Header name must be a valid HTTP token [""]'
|
1881 |
+
* }
|
1882 |
+
* ```
|
1883 |
+
* @since v14.3.0
|
1884 |
+
* @param [label='Header name'] Label for error message.
|
1885 |
+
*/
|
1886 |
+
function validateHeaderName(name: string): void;
|
1887 |
+
/**
|
1888 |
+
* Performs the low-level validations on the provided `value` that are done when `res.setHeader(name, value)` is called.
|
1889 |
+
*
|
1890 |
+
* Passing illegal value as `value` will result in a `TypeError` being thrown.
|
1891 |
+
*
|
1892 |
+
* * Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
|
1893 |
+
* * Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
|
1894 |
+
*
|
1895 |
+
* It is not necessary to use this method before passing headers to an HTTP request
|
1896 |
+
* or response. The HTTP module will automatically validate such headers.
|
1897 |
+
*
|
1898 |
+
* Examples:
|
1899 |
+
*
|
1900 |
+
* ```js
|
1901 |
+
* import { validateHeaderValue } from 'node:http';
|
1902 |
+
*
|
1903 |
+
* try {
|
1904 |
+
* validateHeaderValue('x-my-header', undefined);
|
1905 |
+
* } catch (err) {
|
1906 |
+
* console.error(err instanceof TypeError); // --> true
|
1907 |
+
* console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true
|
1908 |
+
* console.error(err.message); // --> 'Invalid value "undefined" for header "x-my-header"'
|
1909 |
+
* }
|
1910 |
+
*
|
1911 |
+
* try {
|
1912 |
+
* validateHeaderValue('x-my-header', 'oʊmɪɡə');
|
1913 |
+
* } catch (err) {
|
1914 |
+
* console.error(err instanceof TypeError); // --> true
|
1915 |
+
* console.error(err.code === 'ERR_INVALID_CHAR'); // --> true
|
1916 |
+
* console.error(err.message); // --> 'Invalid character in header content ["x-my-header"]'
|
1917 |
+
* }
|
1918 |
+
* ```
|
1919 |
+
* @since v14.3.0
|
1920 |
+
* @param name Header name
|
1921 |
+
* @param value Header value
|
1922 |
+
*/
|
1923 |
+
function validateHeaderValue(name: string, value: string): void;
|
1924 |
+
/**
|
1925 |
+
* Set the maximum number of idle HTTP parsers.
|
1926 |
+
* @since v18.8.0, v16.18.0
|
1927 |
+
* @param [max=1000]
|
1928 |
+
*/
|
1929 |
+
function setMaxIdleHTTPParsers(max: number): void;
|
1930 |
+
/**
|
1931 |
+
* Global instance of `Agent` which is used as the default for all HTTP client
|
1932 |
+
* requests. Diverges from a default `Agent` configuration by having `keepAlive`
|
1933 |
+
* enabled and a `timeout` of 5 seconds.
|
1934 |
+
* @since v0.5.9
|
1935 |
+
*/
|
1936 |
+
let globalAgent: Agent;
|
1937 |
+
/**
|
1938 |
+
* Read-only property specifying the maximum allowed size of HTTP headers in bytes.
|
1939 |
+
* Defaults to 16KB. Configurable using the `--max-http-header-size` CLI option.
|
1940 |
+
*/
|
1941 |
+
const maxHeaderSize: number;
|
1942 |
+
/**
|
1943 |
+
* A browser-compatible implementation of [WebSocket](https://nodejs.org/docs/latest/api/http.html#websocket).
|
1944 |
+
* @since v22.5.0
|
1945 |
+
*/
|
1946 |
+
const WebSocket: import("undici-types").WebSocket;
|
1947 |
+
/**
|
1948 |
+
* @since v22.5.0
|
1949 |
+
*/
|
1950 |
+
const CloseEvent: import("undici-types").CloseEvent;
|
1951 |
+
/**
|
1952 |
+
* @since v22.5.0
|
1953 |
+
*/
|
1954 |
+
const MessageEvent: import("undici-types").MessageEvent;
|
1955 |
+
}
|
1956 |
+
declare module "node:http" {
|
1957 |
+
export * from "http";
|
1958 |
+
}
|
clone/node_modules/@types/node/http2.d.ts
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a
|
3 |
+
* separate module.
|
4 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/https.js)
|
5 |
+
*/
|
6 |
+
declare module "https" {
|
7 |
+
import { Duplex } from "node:stream";
|
8 |
+
import * as tls from "node:tls";
|
9 |
+
import * as http from "node:http";
|
10 |
+
import { URL } from "node:url";
|
11 |
+
type ServerOptions<
|
12 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
13 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
14 |
+
> = tls.SecureContextOptions & tls.TlsOptions & http.ServerOptions<Request, Response>;
|
15 |
+
type RequestOptions =
|
16 |
+
& http.RequestOptions
|
17 |
+
& tls.SecureContextOptions
|
18 |
+
& {
|
19 |
+
checkServerIdentity?: typeof tls.checkServerIdentity | undefined;
|
20 |
+
rejectUnauthorized?: boolean | undefined; // Defaults to true
|
21 |
+
servername?: string | undefined; // SNI TLS Extension
|
22 |
+
};
|
23 |
+
interface AgentOptions extends http.AgentOptions, tls.ConnectionOptions {
|
24 |
+
maxCachedSessions?: number | undefined;
|
25 |
+
}
|
26 |
+
/**
|
27 |
+
* An `Agent` object for HTTPS similar to `http.Agent`. See {@link request} for more information.
|
28 |
+
* @since v0.4.5
|
29 |
+
*/
|
30 |
+
class Agent extends http.Agent {
|
31 |
+
constructor(options?: AgentOptions);
|
32 |
+
options: AgentOptions;
|
33 |
+
}
|
34 |
+
interface Server<
|
35 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
36 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
37 |
+
> extends http.Server<Request, Response> {}
|
38 |
+
/**
|
39 |
+
* See `http.Server` for more information.
|
40 |
+
* @since v0.3.4
|
41 |
+
*/
|
42 |
+
class Server<
|
43 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
44 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
45 |
+
> extends tls.Server {
|
46 |
+
constructor(requestListener?: http.RequestListener<Request, Response>);
|
47 |
+
constructor(
|
48 |
+
options: ServerOptions<Request, Response>,
|
49 |
+
requestListener?: http.RequestListener<Request, Response>,
|
50 |
+
);
|
51 |
+
/**
|
52 |
+
* Closes all connections connected to this server.
|
53 |
+
* @since v18.2.0
|
54 |
+
*/
|
55 |
+
closeAllConnections(): void;
|
56 |
+
/**
|
57 |
+
* Closes all connections connected to this server which are not sending a request or waiting for a response.
|
58 |
+
* @since v18.2.0
|
59 |
+
*/
|
60 |
+
closeIdleConnections(): void;
|
61 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
62 |
+
addListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this;
|
63 |
+
addListener(
|
64 |
+
event: "newSession",
|
65 |
+
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void,
|
66 |
+
): this;
|
67 |
+
addListener(
|
68 |
+
event: "OCSPRequest",
|
69 |
+
listener: (
|
70 |
+
certificate: Buffer,
|
71 |
+
issuer: Buffer,
|
72 |
+
callback: (err: Error | null, resp: Buffer) => void,
|
73 |
+
) => void,
|
74 |
+
): this;
|
75 |
+
addListener(
|
76 |
+
event: "resumeSession",
|
77 |
+
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void,
|
78 |
+
): this;
|
79 |
+
addListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this;
|
80 |
+
addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this;
|
81 |
+
addListener(event: "close", listener: () => void): this;
|
82 |
+
addListener(event: "connection", listener: (socket: Duplex) => void): this;
|
83 |
+
addListener(event: "error", listener: (err: Error) => void): this;
|
84 |
+
addListener(event: "listening", listener: () => void): this;
|
85 |
+
addListener(event: "checkContinue", listener: http.RequestListener<Request, Response>): this;
|
86 |
+
addListener(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this;
|
87 |
+
addListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this;
|
88 |
+
addListener(
|
89 |
+
event: "connect",
|
90 |
+
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void,
|
91 |
+
): this;
|
92 |
+
addListener(event: "request", listener: http.RequestListener<Request, Response>): this;
|
93 |
+
addListener(
|
94 |
+
event: "upgrade",
|
95 |
+
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void,
|
96 |
+
): this;
|
97 |
+
emit(event: string, ...args: any[]): boolean;
|
98 |
+
emit(event: "keylog", line: Buffer, tlsSocket: tls.TLSSocket): boolean;
|
99 |
+
emit(
|
100 |
+
event: "newSession",
|
101 |
+
sessionId: Buffer,
|
102 |
+
sessionData: Buffer,
|
103 |
+
callback: (err: Error, resp: Buffer) => void,
|
104 |
+
): boolean;
|
105 |
+
emit(
|
106 |
+
event: "OCSPRequest",
|
107 |
+
certificate: Buffer,
|
108 |
+
issuer: Buffer,
|
109 |
+
callback: (err: Error | null, resp: Buffer) => void,
|
110 |
+
): boolean;
|
111 |
+
emit(event: "resumeSession", sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void): boolean;
|
112 |
+
emit(event: "secureConnection", tlsSocket: tls.TLSSocket): boolean;
|
113 |
+
emit(event: "tlsClientError", err: Error, tlsSocket: tls.TLSSocket): boolean;
|
114 |
+
emit(event: "close"): boolean;
|
115 |
+
emit(event: "connection", socket: Duplex): boolean;
|
116 |
+
emit(event: "error", err: Error): boolean;
|
117 |
+
emit(event: "listening"): boolean;
|
118 |
+
emit(
|
119 |
+
event: "checkContinue",
|
120 |
+
req: InstanceType<Request>,
|
121 |
+
res: InstanceType<Response>,
|
122 |
+
): boolean;
|
123 |
+
emit(
|
124 |
+
event: "checkExpectation",
|
125 |
+
req: InstanceType<Request>,
|
126 |
+
res: InstanceType<Response>,
|
127 |
+
): boolean;
|
128 |
+
emit(event: "clientError", err: Error, socket: Duplex): boolean;
|
129 |
+
emit(event: "connect", req: InstanceType<Request>, socket: Duplex, head: Buffer): boolean;
|
130 |
+
emit(
|
131 |
+
event: "request",
|
132 |
+
req: InstanceType<Request>,
|
133 |
+
res: InstanceType<Response>,
|
134 |
+
): boolean;
|
135 |
+
emit(event: "upgrade", req: InstanceType<Request>, socket: Duplex, head: Buffer): boolean;
|
136 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
137 |
+
on(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this;
|
138 |
+
on(
|
139 |
+
event: "newSession",
|
140 |
+
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void,
|
141 |
+
): this;
|
142 |
+
on(
|
143 |
+
event: "OCSPRequest",
|
144 |
+
listener: (
|
145 |
+
certificate: Buffer,
|
146 |
+
issuer: Buffer,
|
147 |
+
callback: (err: Error | null, resp: Buffer) => void,
|
148 |
+
) => void,
|
149 |
+
): this;
|
150 |
+
on(
|
151 |
+
event: "resumeSession",
|
152 |
+
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void,
|
153 |
+
): this;
|
154 |
+
on(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this;
|
155 |
+
on(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this;
|
156 |
+
on(event: "close", listener: () => void): this;
|
157 |
+
on(event: "connection", listener: (socket: Duplex) => void): this;
|
158 |
+
on(event: "error", listener: (err: Error) => void): this;
|
159 |
+
on(event: "listening", listener: () => void): this;
|
160 |
+
on(event: "checkContinue", listener: http.RequestListener<Request, Response>): this;
|
161 |
+
on(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this;
|
162 |
+
on(event: "clientError", listener: (err: Error, socket: Duplex) => void): this;
|
163 |
+
on(event: "connect", listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void): this;
|
164 |
+
on(event: "request", listener: http.RequestListener<Request, Response>): this;
|
165 |
+
on(event: "upgrade", listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void): this;
|
166 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
167 |
+
once(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this;
|
168 |
+
once(
|
169 |
+
event: "newSession",
|
170 |
+
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void,
|
171 |
+
): this;
|
172 |
+
once(
|
173 |
+
event: "OCSPRequest",
|
174 |
+
listener: (
|
175 |
+
certificate: Buffer,
|
176 |
+
issuer: Buffer,
|
177 |
+
callback: (err: Error | null, resp: Buffer) => void,
|
178 |
+
) => void,
|
179 |
+
): this;
|
180 |
+
once(
|
181 |
+
event: "resumeSession",
|
182 |
+
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void,
|
183 |
+
): this;
|
184 |
+
once(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this;
|
185 |
+
once(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this;
|
186 |
+
once(event: "close", listener: () => void): this;
|
187 |
+
once(event: "connection", listener: (socket: Duplex) => void): this;
|
188 |
+
once(event: "error", listener: (err: Error) => void): this;
|
189 |
+
once(event: "listening", listener: () => void): this;
|
190 |
+
once(event: "checkContinue", listener: http.RequestListener<Request, Response>): this;
|
191 |
+
once(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this;
|
192 |
+
once(event: "clientError", listener: (err: Error, socket: Duplex) => void): this;
|
193 |
+
once(event: "connect", listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void): this;
|
194 |
+
once(event: "request", listener: http.RequestListener<Request, Response>): this;
|
195 |
+
once(event: "upgrade", listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void): this;
|
196 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
197 |
+
prependListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this;
|
198 |
+
prependListener(
|
199 |
+
event: "newSession",
|
200 |
+
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void,
|
201 |
+
): this;
|
202 |
+
prependListener(
|
203 |
+
event: "OCSPRequest",
|
204 |
+
listener: (
|
205 |
+
certificate: Buffer,
|
206 |
+
issuer: Buffer,
|
207 |
+
callback: (err: Error | null, resp: Buffer) => void,
|
208 |
+
) => void,
|
209 |
+
): this;
|
210 |
+
prependListener(
|
211 |
+
event: "resumeSession",
|
212 |
+
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void,
|
213 |
+
): this;
|
214 |
+
prependListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this;
|
215 |
+
prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this;
|
216 |
+
prependListener(event: "close", listener: () => void): this;
|
217 |
+
prependListener(event: "connection", listener: (socket: Duplex) => void): this;
|
218 |
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
219 |
+
prependListener(event: "listening", listener: () => void): this;
|
220 |
+
prependListener(event: "checkContinue", listener: http.RequestListener<Request, Response>): this;
|
221 |
+
prependListener(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this;
|
222 |
+
prependListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this;
|
223 |
+
prependListener(
|
224 |
+
event: "connect",
|
225 |
+
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void,
|
226 |
+
): this;
|
227 |
+
prependListener(event: "request", listener: http.RequestListener<Request, Response>): this;
|
228 |
+
prependListener(
|
229 |
+
event: "upgrade",
|
230 |
+
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void,
|
231 |
+
): this;
|
232 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
233 |
+
prependOnceListener(event: "keylog", listener: (line: Buffer, tlsSocket: tls.TLSSocket) => void): this;
|
234 |
+
prependOnceListener(
|
235 |
+
event: "newSession",
|
236 |
+
listener: (sessionId: Buffer, sessionData: Buffer, callback: (err: Error, resp: Buffer) => void) => void,
|
237 |
+
): this;
|
238 |
+
prependOnceListener(
|
239 |
+
event: "OCSPRequest",
|
240 |
+
listener: (
|
241 |
+
certificate: Buffer,
|
242 |
+
issuer: Buffer,
|
243 |
+
callback: (err: Error | null, resp: Buffer) => void,
|
244 |
+
) => void,
|
245 |
+
): this;
|
246 |
+
prependOnceListener(
|
247 |
+
event: "resumeSession",
|
248 |
+
listener: (sessionId: Buffer, callback: (err: Error, sessionData: Buffer) => void) => void,
|
249 |
+
): this;
|
250 |
+
prependOnceListener(event: "secureConnection", listener: (tlsSocket: tls.TLSSocket) => void): this;
|
251 |
+
prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: tls.TLSSocket) => void): this;
|
252 |
+
prependOnceListener(event: "close", listener: () => void): this;
|
253 |
+
prependOnceListener(event: "connection", listener: (socket: Duplex) => void): this;
|
254 |
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
255 |
+
prependOnceListener(event: "listening", listener: () => void): this;
|
256 |
+
prependOnceListener(event: "checkContinue", listener: http.RequestListener<Request, Response>): this;
|
257 |
+
prependOnceListener(event: "checkExpectation", listener: http.RequestListener<Request, Response>): this;
|
258 |
+
prependOnceListener(event: "clientError", listener: (err: Error, socket: Duplex) => void): this;
|
259 |
+
prependOnceListener(
|
260 |
+
event: "connect",
|
261 |
+
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void,
|
262 |
+
): this;
|
263 |
+
prependOnceListener(event: "request", listener: http.RequestListener<Request, Response>): this;
|
264 |
+
prependOnceListener(
|
265 |
+
event: "upgrade",
|
266 |
+
listener: (req: InstanceType<Request>, socket: Duplex, head: Buffer) => void,
|
267 |
+
): this;
|
268 |
+
}
|
269 |
+
/**
|
270 |
+
* ```js
|
271 |
+
* // curl -k https://localhost:8000/
|
272 |
+
* import https from 'node:https';
|
273 |
+
* import fs from 'node:fs';
|
274 |
+
*
|
275 |
+
* const options = {
|
276 |
+
* key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
|
277 |
+
* cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
|
278 |
+
* };
|
279 |
+
*
|
280 |
+
* https.createServer(options, (req, res) => {
|
281 |
+
* res.writeHead(200);
|
282 |
+
* res.end('hello world\n');
|
283 |
+
* }).listen(8000);
|
284 |
+
* ```
|
285 |
+
*
|
286 |
+
* Or
|
287 |
+
*
|
288 |
+
* ```js
|
289 |
+
* import https from 'node:https';
|
290 |
+
* import fs from 'node:fs';
|
291 |
+
*
|
292 |
+
* const options = {
|
293 |
+
* pfx: fs.readFileSync('test/fixtures/test_cert.pfx'),
|
294 |
+
* passphrase: 'sample',
|
295 |
+
* };
|
296 |
+
*
|
297 |
+
* https.createServer(options, (req, res) => {
|
298 |
+
* res.writeHead(200);
|
299 |
+
* res.end('hello world\n');
|
300 |
+
* }).listen(8000);
|
301 |
+
* ```
|
302 |
+
* @since v0.3.4
|
303 |
+
* @param options Accepts `options` from `createServer`, `createSecureContext` and `createServer`.
|
304 |
+
* @param requestListener A listener to be added to the `'request'` event.
|
305 |
+
*/
|
306 |
+
function createServer<
|
307 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
308 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
309 |
+
>(requestListener?: http.RequestListener<Request, Response>): Server<Request, Response>;
|
310 |
+
function createServer<
|
311 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
312 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
313 |
+
>(
|
314 |
+
options: ServerOptions<Request, Response>,
|
315 |
+
requestListener?: http.RequestListener<Request, Response>,
|
316 |
+
): Server<Request, Response>;
|
317 |
+
/**
|
318 |
+
* Makes a request to a secure web server.
|
319 |
+
*
|
320 |
+
* The following additional `options` from `tls.connect()` are also accepted: `ca`, `cert`, `ciphers`, `clientCertEngine`, `crl`, `dhparam`, `ecdhCurve`, `honorCipherOrder`, `key`, `passphrase`,
|
321 |
+
* `pfx`, `rejectUnauthorized`, `secureOptions`, `secureProtocol`, `servername`, `sessionIdContext`, `highWaterMark`.
|
322 |
+
*
|
323 |
+
* `options` can be an object, a string, or a `URL` object. If `options` is a
|
324 |
+
* string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
|
325 |
+
*
|
326 |
+
* `https.request()` returns an instance of the `http.ClientRequest` class. The `ClientRequest` instance is a writable stream. If one needs to
|
327 |
+
* upload a file with a POST request, then write to the `ClientRequest` object.
|
328 |
+
*
|
329 |
+
* ```js
|
330 |
+
* import https from 'node:https';
|
331 |
+
*
|
332 |
+
* const options = {
|
333 |
+
* hostname: 'encrypted.google.com',
|
334 |
+
* port: 443,
|
335 |
+
* path: '/',
|
336 |
+
* method: 'GET',
|
337 |
+
* };
|
338 |
+
*
|
339 |
+
* const req = https.request(options, (res) => {
|
340 |
+
* console.log('statusCode:', res.statusCode);
|
341 |
+
* console.log('headers:', res.headers);
|
342 |
+
*
|
343 |
+
* res.on('data', (d) => {
|
344 |
+
* process.stdout.write(d);
|
345 |
+
* });
|
346 |
+
* });
|
347 |
+
*
|
348 |
+
* req.on('error', (e) => {
|
349 |
+
* console.error(e);
|
350 |
+
* });
|
351 |
+
* req.end();
|
352 |
+
* ```
|
353 |
+
*
|
354 |
+
* Example using options from `tls.connect()`:
|
355 |
+
*
|
356 |
+
* ```js
|
357 |
+
* const options = {
|
358 |
+
* hostname: 'encrypted.google.com',
|
359 |
+
* port: 443,
|
360 |
+
* path: '/',
|
361 |
+
* method: 'GET',
|
362 |
+
* key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
|
363 |
+
* cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
|
364 |
+
* };
|
365 |
+
* options.agent = new https.Agent(options);
|
366 |
+
*
|
367 |
+
* const req = https.request(options, (res) => {
|
368 |
+
* // ...
|
369 |
+
* });
|
370 |
+
* ```
|
371 |
+
*
|
372 |
+
* Alternatively, opt out of connection pooling by not using an `Agent`.
|
373 |
+
*
|
374 |
+
* ```js
|
375 |
+
* const options = {
|
376 |
+
* hostname: 'encrypted.google.com',
|
377 |
+
* port: 443,
|
378 |
+
* path: '/',
|
379 |
+
* method: 'GET',
|
380 |
+
* key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
|
381 |
+
* cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
|
382 |
+
* agent: false,
|
383 |
+
* };
|
384 |
+
*
|
385 |
+
* const req = https.request(options, (res) => {
|
386 |
+
* // ...
|
387 |
+
* });
|
388 |
+
* ```
|
389 |
+
*
|
390 |
+
* Example using a `URL` as `options`:
|
391 |
+
*
|
392 |
+
* ```js
|
393 |
+
* const options = new URL('https://abc:[email protected]');
|
394 |
+
*
|
395 |
+
* const req = https.request(options, (res) => {
|
396 |
+
* // ...
|
397 |
+
* });
|
398 |
+
* ```
|
399 |
+
*
|
400 |
+
* Example pinning on certificate fingerprint, or the public key (similar to`pin-sha256`):
|
401 |
+
*
|
402 |
+
* ```js
|
403 |
+
* import tls from 'node:tls';
|
404 |
+
* import https from 'node:https';
|
405 |
+
* import crypto from 'node:crypto';
|
406 |
+
*
|
407 |
+
* function sha256(s) {
|
408 |
+
* return crypto.createHash('sha256').update(s).digest('base64');
|
409 |
+
* }
|
410 |
+
* const options = {
|
411 |
+
* hostname: 'github.com',
|
412 |
+
* port: 443,
|
413 |
+
* path: '/',
|
414 |
+
* method: 'GET',
|
415 |
+
* checkServerIdentity: function(host, cert) {
|
416 |
+
* // Make sure the certificate is issued to the host we are connected to
|
417 |
+
* const err = tls.checkServerIdentity(host, cert);
|
418 |
+
* if (err) {
|
419 |
+
* return err;
|
420 |
+
* }
|
421 |
+
*
|
422 |
+
* // Pin the public key, similar to HPKP pin-sha256 pinning
|
423 |
+
* const pubkey256 = 'pL1+qb9HTMRZJmuC/bB/ZI9d302BYrrqiVuRyW+DGrU=';
|
424 |
+
* if (sha256(cert.pubkey) !== pubkey256) {
|
425 |
+
* const msg = 'Certificate verification error: ' +
|
426 |
+
* `The public key of '${cert.subject.CN}' ` +
|
427 |
+
* 'does not match our pinned fingerprint';
|
428 |
+
* return new Error(msg);
|
429 |
+
* }
|
430 |
+
*
|
431 |
+
* // Pin the exact certificate, rather than the pub key
|
432 |
+
* const cert256 = '25:FE:39:32:D9:63:8C:8A:FC:A1:9A:29:87:' +
|
433 |
+
* 'D8:3E:4C:1D:98:DB:71:E4:1A:48:03:98:EA:22:6A:BD:8B:93:16';
|
434 |
+
* if (cert.fingerprint256 !== cert256) {
|
435 |
+
* const msg = 'Certificate verification error: ' +
|
436 |
+
* `The certificate of '${cert.subject.CN}' ` +
|
437 |
+
* 'does not match our pinned fingerprint';
|
438 |
+
* return new Error(msg);
|
439 |
+
* }
|
440 |
+
*
|
441 |
+
* // This loop is informational only.
|
442 |
+
* // Print the certificate and public key fingerprints of all certs in the
|
443 |
+
* // chain. Its common to pin the public key of the issuer on the public
|
444 |
+
* // internet, while pinning the public key of the service in sensitive
|
445 |
+
* // environments.
|
446 |
+
* do {
|
447 |
+
* console.log('Subject Common Name:', cert.subject.CN);
|
448 |
+
* console.log(' Certificate SHA256 fingerprint:', cert.fingerprint256);
|
449 |
+
*
|
450 |
+
* hash = crypto.createHash('sha256');
|
451 |
+
* console.log(' Public key ping-sha256:', sha256(cert.pubkey));
|
452 |
+
*
|
453 |
+
* lastprint256 = cert.fingerprint256;
|
454 |
+
* cert = cert.issuerCertificate;
|
455 |
+
* } while (cert.fingerprint256 !== lastprint256);
|
456 |
+
*
|
457 |
+
* },
|
458 |
+
* };
|
459 |
+
*
|
460 |
+
* options.agent = new https.Agent(options);
|
461 |
+
* const req = https.request(options, (res) => {
|
462 |
+
* console.log('All OK. Server matched our pinned cert or public key');
|
463 |
+
* console.log('statusCode:', res.statusCode);
|
464 |
+
* // Print the HPKP values
|
465 |
+
* console.log('headers:', res.headers['public-key-pins']);
|
466 |
+
*
|
467 |
+
* res.on('data', (d) => {});
|
468 |
+
* });
|
469 |
+
*
|
470 |
+
* req.on('error', (e) => {
|
471 |
+
* console.error(e.message);
|
472 |
+
* });
|
473 |
+
* req.end();
|
474 |
+
* ```
|
475 |
+
*
|
476 |
+
* Outputs for example:
|
477 |
+
*
|
478 |
+
* ```text
|
479 |
+
* Subject Common Name: github.com
|
480 |
+
* Certificate SHA256 fingerprint: 25:FE:39:32:D9:63:8C:8A:FC:A1:9A:29:87:D8:3E:4C:1D:98:DB:71:E4:1A:48:03:98:EA:22:6A:BD:8B:93:16
|
481 |
+
* Public key ping-sha256: pL1+qb9HTMRZJmuC/bB/ZI9d302BYrrqiVuRyW+DGrU=
|
482 |
+
* Subject Common Name: DigiCert SHA2 Extended Validation Server CA
|
483 |
+
* Certificate SHA256 fingerprint: 40:3E:06:2A:26:53:05:91:13:28:5B:AF:80:A0:D4:AE:42:2C:84:8C:9F:78:FA:D0:1F:C9:4B:C5:B8:7F:EF:1A
|
484 |
+
* Public key ping-sha256: RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=
|
485 |
+
* Subject Common Name: DigiCert High Assurance EV Root CA
|
486 |
+
* Certificate SHA256 fingerprint: 74:31:E5:F4:C3:C1:CE:46:90:77:4F:0B:61:E0:54:40:88:3B:A9:A0:1E:D0:0B:A6:AB:D7:80:6E:D3:B1:18:CF
|
487 |
+
* Public key ping-sha256: WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=
|
488 |
+
* All OK. Server matched our pinned cert or public key
|
489 |
+
* statusCode: 200
|
490 |
+
* headers: max-age=0; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";
|
491 |
+
* pin-sha256="k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws="; pin-sha256="K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q="; pin-sha256="IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4=";
|
492 |
+
* pin-sha256="iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0="; pin-sha256="LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A="; includeSubDomains
|
493 |
+
* ```
|
494 |
+
* @since v0.3.6
|
495 |
+
* @param options Accepts all `options` from `request`, with some differences in default values:
|
496 |
+
*/
|
497 |
+
function request(
|
498 |
+
options: RequestOptions | string | URL,
|
499 |
+
callback?: (res: http.IncomingMessage) => void,
|
500 |
+
): http.ClientRequest;
|
501 |
+
function request(
|
502 |
+
url: string | URL,
|
503 |
+
options: RequestOptions,
|
504 |
+
callback?: (res: http.IncomingMessage) => void,
|
505 |
+
): http.ClientRequest;
|
506 |
+
/**
|
507 |
+
* Like `http.get()` but for HTTPS.
|
508 |
+
*
|
509 |
+
* `options` can be an object, a string, or a `URL` object. If `options` is a
|
510 |
+
* string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
|
511 |
+
*
|
512 |
+
* ```js
|
513 |
+
* import https from 'node:https';
|
514 |
+
*
|
515 |
+
* https.get('https://encrypted.google.com/', (res) => {
|
516 |
+
* console.log('statusCode:', res.statusCode);
|
517 |
+
* console.log('headers:', res.headers);
|
518 |
+
*
|
519 |
+
* res.on('data', (d) => {
|
520 |
+
* process.stdout.write(d);
|
521 |
+
* });
|
522 |
+
*
|
523 |
+
* }).on('error', (e) => {
|
524 |
+
* console.error(e);
|
525 |
+
* });
|
526 |
+
* ```
|
527 |
+
* @since v0.3.6
|
528 |
+
* @param options Accepts the same `options` as {@link request}, with the `method` always set to `GET`.
|
529 |
+
*/
|
530 |
+
function get(
|
531 |
+
options: RequestOptions | string | URL,
|
532 |
+
callback?: (res: http.IncomingMessage) => void,
|
533 |
+
): http.ClientRequest;
|
534 |
+
function get(
|
535 |
+
url: string | URL,
|
536 |
+
options: RequestOptions,
|
537 |
+
callback?: (res: http.IncomingMessage) => void,
|
538 |
+
): http.ClientRequest;
|
539 |
+
let globalAgent: Agent;
|
540 |
+
}
|
541 |
+
declare module "node:https" {
|
542 |
+
export * from "https";
|
543 |
+
}
|
clone/node_modules/@types/node/index.d.ts
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* License for programmatically and manually incorporated
|
3 |
+
* documentation aka. `JSDoc` from https://github.com/nodejs/node/tree/master/doc
|
4 |
+
*
|
5 |
+
* Copyright Node.js contributors. All rights reserved.
|
6 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 |
+
* of this software and associated documentation files (the "Software"), to
|
8 |
+
* deal in the Software without restriction, including without limitation the
|
9 |
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10 |
+
* sell copies of the Software, and to permit persons to whom the Software is
|
11 |
+
* furnished to do so, subject to the following conditions:
|
12 |
+
*
|
13 |
+
* The above copyright notice and this permission notice shall be included in
|
14 |
+
* all copies or substantial portions of the Software.
|
15 |
+
*
|
16 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21 |
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
22 |
+
* IN THE SOFTWARE.
|
23 |
+
*/
|
24 |
+
|
25 |
+
// NOTE: These definitions support Node.js and TypeScript 5.7+.
|
26 |
+
|
27 |
+
// Reference required TypeScript libs:
|
28 |
+
/// <reference lib="es2020" />
|
29 |
+
|
30 |
+
// TypeScript backwards-compatibility definitions:
|
31 |
+
/// <reference path="compatibility/index.d.ts" />
|
32 |
+
|
33 |
+
// Definitions specific to TypeScript 5.7+:
|
34 |
+
/// <reference path="globals.typedarray.d.ts" />
|
35 |
+
/// <reference path="buffer.buffer.d.ts" />
|
36 |
+
|
37 |
+
// Definitions for Node.js modules that are not specific to any version of TypeScript:
|
38 |
+
/// <reference path="globals.d.ts" />
|
39 |
+
/// <reference path="assert.d.ts" />
|
40 |
+
/// <reference path="assert/strict.d.ts" />
|
41 |
+
/// <reference path="async_hooks.d.ts" />
|
42 |
+
/// <reference path="buffer.d.ts" />
|
43 |
+
/// <reference path="child_process.d.ts" />
|
44 |
+
/// <reference path="cluster.d.ts" />
|
45 |
+
/// <reference path="console.d.ts" />
|
46 |
+
/// <reference path="constants.d.ts" />
|
47 |
+
/// <reference path="crypto.d.ts" />
|
48 |
+
/// <reference path="dgram.d.ts" />
|
49 |
+
/// <reference path="diagnostics_channel.d.ts" />
|
50 |
+
/// <reference path="dns.d.ts" />
|
51 |
+
/// <reference path="dns/promises.d.ts" />
|
52 |
+
/// <reference path="dns/promises.d.ts" />
|
53 |
+
/// <reference path="domain.d.ts" />
|
54 |
+
/// <reference path="dom-events.d.ts" />
|
55 |
+
/// <reference path="events.d.ts" />
|
56 |
+
/// <reference path="fs.d.ts" />
|
57 |
+
/// <reference path="fs/promises.d.ts" />
|
58 |
+
/// <reference path="http.d.ts" />
|
59 |
+
/// <reference path="http2.d.ts" />
|
60 |
+
/// <reference path="https.d.ts" />
|
61 |
+
/// <reference path="inspector.d.ts" />
|
62 |
+
/// <reference path="module.d.ts" />
|
63 |
+
/// <reference path="net.d.ts" />
|
64 |
+
/// <reference path="os.d.ts" />
|
65 |
+
/// <reference path="path.d.ts" />
|
66 |
+
/// <reference path="perf_hooks.d.ts" />
|
67 |
+
/// <reference path="process.d.ts" />
|
68 |
+
/// <reference path="punycode.d.ts" />
|
69 |
+
/// <reference path="querystring.d.ts" />
|
70 |
+
/// <reference path="readline.d.ts" />
|
71 |
+
/// <reference path="readline/promises.d.ts" />
|
72 |
+
/// <reference path="repl.d.ts" />
|
73 |
+
/// <reference path="sea.d.ts" />
|
74 |
+
/// <reference path="sqlite.d.ts" />
|
75 |
+
/// <reference path="stream.d.ts" />
|
76 |
+
/// <reference path="stream/promises.d.ts" />
|
77 |
+
/// <reference path="stream/consumers.d.ts" />
|
78 |
+
/// <reference path="stream/web.d.ts" />
|
79 |
+
/// <reference path="string_decoder.d.ts" />
|
80 |
+
/// <reference path="test.d.ts" />
|
81 |
+
/// <reference path="timers.d.ts" />
|
82 |
+
/// <reference path="timers/promises.d.ts" />
|
83 |
+
/// <reference path="tls.d.ts" />
|
84 |
+
/// <reference path="trace_events.d.ts" />
|
85 |
+
/// <reference path="tty.d.ts" />
|
86 |
+
/// <reference path="url.d.ts" />
|
87 |
+
/// <reference path="util.d.ts" />
|
88 |
+
/// <reference path="v8.d.ts" />
|
89 |
+
/// <reference path="vm.d.ts" />
|
90 |
+
/// <reference path="wasi.d.ts" />
|
91 |
+
/// <reference path="worker_threads.d.ts" />
|
92 |
+
/// <reference path="zlib.d.ts" />
|
clone/node_modules/@types/node/inspector.d.ts
ADDED
The diff for this file is too large to render.
See raw diff
|
|
clone/node_modules/@types/node/module.d.ts
ADDED
@@ -0,0 +1,621 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* @since v0.3.7
|
3 |
+
*/
|
4 |
+
declare module "module" {
|
5 |
+
import { URL } from "node:url";
|
6 |
+
class Module {
|
7 |
+
constructor(id: string, parent?: Module);
|
8 |
+
}
|
9 |
+
interface Module extends NodeJS.Module {}
|
10 |
+
namespace Module {
|
11 |
+
export { Module };
|
12 |
+
}
|
13 |
+
namespace Module {
|
14 |
+
/**
|
15 |
+
* A list of the names of all modules provided by Node.js. Can be used to verify
|
16 |
+
* if a module is maintained by a third party or not.
|
17 |
+
*
|
18 |
+
* Note: the list doesn't contain prefix-only modules like `node:test`.
|
19 |
+
* @since v9.3.0, v8.10.0, v6.13.0
|
20 |
+
*/
|
21 |
+
const builtinModules: readonly string[];
|
22 |
+
/**
|
23 |
+
* @since v12.2.0
|
24 |
+
* @param path Filename to be used to construct the require
|
25 |
+
* function. Must be a file URL object, file URL string, or absolute path
|
26 |
+
* string.
|
27 |
+
*/
|
28 |
+
function createRequire(path: string | URL): NodeJS.Require;
|
29 |
+
namespace constants {
|
30 |
+
/**
|
31 |
+
* The following constants are returned as the `status` field in the object returned by
|
32 |
+
* {@link enableCompileCache} to indicate the result of the attempt to enable the
|
33 |
+
* [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache).
|
34 |
+
* @since v22.8.0
|
35 |
+
*/
|
36 |
+
namespace compileCacheStatus {
|
37 |
+
/**
|
38 |
+
* Node.js has enabled the compile cache successfully. The directory used to store the
|
39 |
+
* compile cache will be returned in the `directory` field in the
|
40 |
+
* returned object.
|
41 |
+
*/
|
42 |
+
const ENABLED: number;
|
43 |
+
/**
|
44 |
+
* The compile cache has already been enabled before, either by a previous call to
|
45 |
+
* {@link enableCompileCache}, or by the `NODE_COMPILE_CACHE=dir`
|
46 |
+
* environment variable. The directory used to store the
|
47 |
+
* compile cache will be returned in the `directory` field in the
|
48 |
+
* returned object.
|
49 |
+
*/
|
50 |
+
const ALREADY_ENABLED: number;
|
51 |
+
/**
|
52 |
+
* Node.js fails to enable the compile cache. This can be caused by the lack of
|
53 |
+
* permission to use the specified directory, or various kinds of file system errors.
|
54 |
+
* The detail of the failure will be returned in the `message` field in the
|
55 |
+
* returned object.
|
56 |
+
*/
|
57 |
+
const FAILED: number;
|
58 |
+
/**
|
59 |
+
* Node.js cannot enable the compile cache because the environment variable
|
60 |
+
* `NODE_DISABLE_COMPILE_CACHE=1` has been set.
|
61 |
+
*/
|
62 |
+
const DISABLED: number;
|
63 |
+
}
|
64 |
+
}
|
65 |
+
interface EnableCompileCacheResult {
|
66 |
+
/**
|
67 |
+
* One of the {@link constants.compileCacheStatus}
|
68 |
+
*/
|
69 |
+
status: number;
|
70 |
+
/**
|
71 |
+
* If Node.js cannot enable the compile cache, this contains
|
72 |
+
* the error message. Only set if `status` is `module.constants.compileCacheStatus.FAILED`.
|
73 |
+
*/
|
74 |
+
message?: string;
|
75 |
+
/**
|
76 |
+
* If the compile cache is enabled, this contains the directory
|
77 |
+
* where the compile cache is stored. Only set if `status` is
|
78 |
+
* `module.constants.compileCacheStatus.ENABLED` or
|
79 |
+
* `module.constants.compileCacheStatus.ALREADY_ENABLED`.
|
80 |
+
*/
|
81 |
+
directory?: string;
|
82 |
+
}
|
83 |
+
/**
|
84 |
+
* Enable [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
|
85 |
+
* in the current Node.js instance.
|
86 |
+
*
|
87 |
+
* If `cacheDir` is not specified, Node.js will either use the directory specified by the
|
88 |
+
* `NODE_COMPILE_CACHE=dir` environment variable if it's set, or use
|
89 |
+
* `path.join(os.tmpdir(), 'node-compile-cache')` otherwise. For general use cases, it's
|
90 |
+
* recommended to call `module.enableCompileCache()` without specifying the `cacheDir`,
|
91 |
+
* so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment
|
92 |
+
* variable when necessary.
|
93 |
+
*
|
94 |
+
* Since compile cache is supposed to be a quiet optimization that is not required for the
|
95 |
+
* application to be functional, this method is designed to not throw any exception when the
|
96 |
+
* compile cache cannot be enabled. Instead, it will return an object containing an error
|
97 |
+
* message in the `message` field to aid debugging.
|
98 |
+
* If compile cache is enabled successfully, the `directory` field in the returned object
|
99 |
+
* contains the path to the directory where the compile cache is stored. The `status`
|
100 |
+
* field in the returned object would be one of the `module.constants.compileCacheStatus`
|
101 |
+
* values to indicate the result of the attempt to enable the
|
102 |
+
* [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache).
|
103 |
+
*
|
104 |
+
* This method only affects the current Node.js instance. To enable it in child worker threads,
|
105 |
+
* either call this method in child worker threads too, or set the
|
106 |
+
* `process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can
|
107 |
+
* be inherited into the child workers. The directory can be obtained either from the
|
108 |
+
* `directory` field returned by this method, or with {@link getCompileCacheDir}.
|
109 |
+
* @since v22.8.0
|
110 |
+
* @param cacheDir Optional path to specify the directory where the compile cache
|
111 |
+
* will be stored/retrieved.
|
112 |
+
*/
|
113 |
+
function enableCompileCache(cacheDir?: string): EnableCompileCacheResult;
|
114 |
+
/**
|
115 |
+
* Flush the [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
|
116 |
+
* accumulated from modules already loaded
|
117 |
+
* in the current Node.js instance to disk. This returns after all the flushing
|
118 |
+
* file system operations come to an end, no matter they succeed or not. If there
|
119 |
+
* are any errors, this will fail silently, since compile cache misses should not
|
120 |
+
* interfere with the actual operation of the application.
|
121 |
+
* @since v22.10.0
|
122 |
+
*/
|
123 |
+
function flushCompileCache(): void;
|
124 |
+
/**
|
125 |
+
* @since v22.8.0
|
126 |
+
* @return Path to the [module compile cache](https://nodejs.org/docs/latest-v22.x/api/module.html#module-compile-cache)
|
127 |
+
* directory if it is enabled, or `undefined` otherwise.
|
128 |
+
*/
|
129 |
+
function getCompileCacheDir(): string | undefined;
|
130 |
+
/**
|
131 |
+
* @since v18.6.0, v16.17.0
|
132 |
+
*/
|
133 |
+
function isBuiltin(moduleName: string): boolean;
|
134 |
+
interface RegisterOptions<Data> {
|
135 |
+
/**
|
136 |
+
* If you want to resolve `specifier` relative to a
|
137 |
+
* base URL, such as `import.meta.url`, you can pass that URL here. This
|
138 |
+
* property is ignored if the `parentURL` is supplied as the second argument.
|
139 |
+
* @default 'data:'
|
140 |
+
*/
|
141 |
+
parentURL?: string | URL | undefined;
|
142 |
+
/**
|
143 |
+
* Any arbitrary, cloneable JavaScript value to pass into the
|
144 |
+
* {@link initialize} hook.
|
145 |
+
*/
|
146 |
+
data?: Data | undefined;
|
147 |
+
/**
|
148 |
+
* [Transferable objects](https://nodejs.org/docs/latest-v22.x/api/worker_threads.html#portpostmessagevalue-transferlist)
|
149 |
+
* to be passed into the `initialize` hook.
|
150 |
+
*/
|
151 |
+
transferList?: any[] | undefined;
|
152 |
+
}
|
153 |
+
/* eslint-disable @definitelytyped/no-unnecessary-generics */
|
154 |
+
/**
|
155 |
+
* Register a module that exports hooks that customize Node.js module
|
156 |
+
* resolution and loading behavior. See
|
157 |
+
* [Customization hooks](https://nodejs.org/docs/latest-v22.x/api/module.html#customization-hooks).
|
158 |
+
* @since v20.6.0, v18.19.0
|
159 |
+
* @param specifier Customization hooks to be registered; this should be
|
160 |
+
* the same string that would be passed to `import()`, except that if it is
|
161 |
+
* relative, it is resolved relative to `parentURL`.
|
162 |
+
* @param parentURL f you want to resolve `specifier` relative to a base
|
163 |
+
* URL, such as `import.meta.url`, you can pass that URL here.
|
164 |
+
*/
|
165 |
+
function register<Data = any>(
|
166 |
+
specifier: string | URL,
|
167 |
+
parentURL?: string | URL,
|
168 |
+
options?: RegisterOptions<Data>,
|
169 |
+
): void;
|
170 |
+
function register<Data = any>(specifier: string | URL, options?: RegisterOptions<Data>): void;
|
171 |
+
/* eslint-enable @definitelytyped/no-unnecessary-generics */
|
172 |
+
/**
|
173 |
+
* The `module.syncBuiltinESMExports()` method updates all the live bindings for
|
174 |
+
* builtin `ES Modules` to match the properties of the `CommonJS` exports. It
|
175 |
+
* does not add or remove exported names from the `ES Modules`.
|
176 |
+
*
|
177 |
+
* ```js
|
178 |
+
* import fs from 'node:fs';
|
179 |
+
* import assert from 'node:assert';
|
180 |
+
* import { syncBuiltinESMExports } from 'node:module';
|
181 |
+
*
|
182 |
+
* fs.readFile = newAPI;
|
183 |
+
*
|
184 |
+
* delete fs.readFileSync;
|
185 |
+
*
|
186 |
+
* function newAPI() {
|
187 |
+
* // ...
|
188 |
+
* }
|
189 |
+
*
|
190 |
+
* fs.newAPI = newAPI;
|
191 |
+
*
|
192 |
+
* syncBuiltinESMExports();
|
193 |
+
*
|
194 |
+
* import('node:fs').then((esmFS) => {
|
195 |
+
* // It syncs the existing readFile property with the new value
|
196 |
+
* assert.strictEqual(esmFS.readFile, newAPI);
|
197 |
+
* // readFileSync has been deleted from the required fs
|
198 |
+
* assert.strictEqual('readFileSync' in fs, false);
|
199 |
+
* // syncBuiltinESMExports() does not remove readFileSync from esmFS
|
200 |
+
* assert.strictEqual('readFileSync' in esmFS, true);
|
201 |
+
* // syncBuiltinESMExports() does not add names
|
202 |
+
* assert.strictEqual(esmFS.newAPI, undefined);
|
203 |
+
* });
|
204 |
+
* ```
|
205 |
+
* @since v12.12.0
|
206 |
+
*/
|
207 |
+
function syncBuiltinESMExports(): void;
|
208 |
+
interface ImportAttributes extends NodeJS.Dict<string> {
|
209 |
+
type?: string | undefined;
|
210 |
+
}
|
211 |
+
type ModuleFormat =
|
212 |
+
| "builtin"
|
213 |
+
| "commonjs"
|
214 |
+
| "commonjs-typescript"
|
215 |
+
| "json"
|
216 |
+
| "module"
|
217 |
+
| "module-typescript"
|
218 |
+
| "wasm";
|
219 |
+
type ModuleSource = string | ArrayBuffer | NodeJS.TypedArray;
|
220 |
+
/**
|
221 |
+
* The `initialize` hook provides a way to define a custom function that runs in
|
222 |
+
* the hooks thread when the hooks module is initialized. Initialization happens
|
223 |
+
* when the hooks module is registered via {@link register}.
|
224 |
+
*
|
225 |
+
* This hook can receive data from a {@link register} invocation, including
|
226 |
+
* ports and other transferable objects. The return value of `initialize` can be a
|
227 |
+
* `Promise`, in which case it will be awaited before the main application thread
|
228 |
+
* execution resumes.
|
229 |
+
*/
|
230 |
+
type InitializeHook<Data = any> = (data: Data) => void | Promise<void>;
|
231 |
+
interface ResolveHookContext {
|
232 |
+
/**
|
233 |
+
* Export conditions of the relevant `package.json`
|
234 |
+
*/
|
235 |
+
conditions: string[];
|
236 |
+
/**
|
237 |
+
* An object whose key-value pairs represent the assertions for the module to import
|
238 |
+
*/
|
239 |
+
importAttributes: ImportAttributes;
|
240 |
+
/**
|
241 |
+
* The module importing this one, or undefined if this is the Node.js entry point
|
242 |
+
*/
|
243 |
+
parentURL: string | undefined;
|
244 |
+
}
|
245 |
+
interface ResolveFnOutput {
|
246 |
+
/**
|
247 |
+
* A hint to the load hook (it might be ignored)
|
248 |
+
*/
|
249 |
+
format?: ModuleFormat | null | undefined;
|
250 |
+
/**
|
251 |
+
* The import attributes to use when caching the module (optional; if excluded the input will be used)
|
252 |
+
*/
|
253 |
+
importAttributes?: ImportAttributes | undefined;
|
254 |
+
/**
|
255 |
+
* A signal that this hook intends to terminate the chain of `resolve` hooks.
|
256 |
+
* @default false
|
257 |
+
*/
|
258 |
+
shortCircuit?: boolean | undefined;
|
259 |
+
/**
|
260 |
+
* The absolute URL to which this input resolves
|
261 |
+
*/
|
262 |
+
url: string;
|
263 |
+
}
|
264 |
+
/**
|
265 |
+
* The `resolve` hook chain is responsible for telling Node.js where to find and
|
266 |
+
* how to cache a given `import` statement or expression, or `require` call. It can
|
267 |
+
* optionally return a format (such as `'module'`) as a hint to the `load` hook. If
|
268 |
+
* a format is specified, the `load` hook is ultimately responsible for providing
|
269 |
+
* the final `format` value (and it is free to ignore the hint provided by
|
270 |
+
* `resolve`); if `resolve` provides a `format`, a custom `load` hook is required
|
271 |
+
* even if only to pass the value to the Node.js default `load` hook.
|
272 |
+
*/
|
273 |
+
type ResolveHook = (
|
274 |
+
specifier: string,
|
275 |
+
context: ResolveHookContext,
|
276 |
+
nextResolve: (
|
277 |
+
specifier: string,
|
278 |
+
context?: Partial<ResolveHookContext>,
|
279 |
+
) => ResolveFnOutput | Promise<ResolveFnOutput>,
|
280 |
+
) => ResolveFnOutput | Promise<ResolveFnOutput>;
|
281 |
+
interface LoadHookContext {
|
282 |
+
/**
|
283 |
+
* Export conditions of the relevant `package.json`
|
284 |
+
*/
|
285 |
+
conditions: string[];
|
286 |
+
/**
|
287 |
+
* The format optionally supplied by the `resolve` hook chain
|
288 |
+
*/
|
289 |
+
format: ModuleFormat | null | undefined;
|
290 |
+
/**
|
291 |
+
* An object whose key-value pairs represent the assertions for the module to import
|
292 |
+
*/
|
293 |
+
importAttributes: ImportAttributes;
|
294 |
+
}
|
295 |
+
interface LoadFnOutput {
|
296 |
+
format: ModuleFormat;
|
297 |
+
/**
|
298 |
+
* A signal that this hook intends to terminate the chain of `resolve` hooks.
|
299 |
+
* @default false
|
300 |
+
*/
|
301 |
+
shortCircuit?: boolean | undefined;
|
302 |
+
/**
|
303 |
+
* The source for Node.js to evaluate
|
304 |
+
*/
|
305 |
+
source?: ModuleSource | undefined;
|
306 |
+
}
|
307 |
+
/**
|
308 |
+
* The `load` hook provides a way to define a custom method of determining how a
|
309 |
+
* URL should be interpreted, retrieved, and parsed. It is also in charge of
|
310 |
+
* validating the import attributes.
|
311 |
+
*/
|
312 |
+
type LoadHook = (
|
313 |
+
url: string,
|
314 |
+
context: LoadHookContext,
|
315 |
+
nextLoad: (
|
316 |
+
url: string,
|
317 |
+
context?: Partial<LoadHookContext>,
|
318 |
+
) => LoadFnOutput | Promise<LoadFnOutput>,
|
319 |
+
) => LoadFnOutput | Promise<LoadFnOutput>;
|
320 |
+
/**
|
321 |
+
* `path` is the resolved path for the file for which a corresponding source map
|
322 |
+
* should be fetched.
|
323 |
+
* @since v13.7.0, v12.17.0
|
324 |
+
* @return Returns `module.SourceMap` if a source map is found, `undefined` otherwise.
|
325 |
+
*/
|
326 |
+
function findSourceMap(path: string): SourceMap | undefined;
|
327 |
+
interface SourceMapConstructorOptions {
|
328 |
+
/**
|
329 |
+
* @since v21.0.0, v20.5.0
|
330 |
+
*/
|
331 |
+
lineLengths?: readonly number[] | undefined;
|
332 |
+
}
|
333 |
+
interface SourceMapPayload {
|
334 |
+
file: string;
|
335 |
+
version: number;
|
336 |
+
sources: string[];
|
337 |
+
sourcesContent: string[];
|
338 |
+
names: string[];
|
339 |
+
mappings: string;
|
340 |
+
sourceRoot: string;
|
341 |
+
}
|
342 |
+
interface SourceMapping {
|
343 |
+
generatedLine: number;
|
344 |
+
generatedColumn: number;
|
345 |
+
originalSource: string;
|
346 |
+
originalLine: number;
|
347 |
+
originalColumn: number;
|
348 |
+
}
|
349 |
+
interface SourceOrigin {
|
350 |
+
/**
|
351 |
+
* The name of the range in the source map, if one was provided
|
352 |
+
*/
|
353 |
+
name: string | undefined;
|
354 |
+
/**
|
355 |
+
* The file name of the original source, as reported in the SourceMap
|
356 |
+
*/
|
357 |
+
fileName: string;
|
358 |
+
/**
|
359 |
+
* The 1-indexed lineNumber of the corresponding call site in the original source
|
360 |
+
*/
|
361 |
+
lineNumber: number;
|
362 |
+
/**
|
363 |
+
* The 1-indexed columnNumber of the corresponding call site in the original source
|
364 |
+
*/
|
365 |
+
columnNumber: number;
|
366 |
+
}
|
367 |
+
/**
|
368 |
+
* @since v13.7.0, v12.17.0
|
369 |
+
*/
|
370 |
+
class SourceMap {
|
371 |
+
constructor(payload: SourceMapPayload, options?: SourceMapConstructorOptions);
|
372 |
+
/**
|
373 |
+
* Getter for the payload used to construct the `SourceMap` instance.
|
374 |
+
*/
|
375 |
+
readonly payload: SourceMapPayload;
|
376 |
+
/**
|
377 |
+
* Given a line offset and column offset in the generated source
|
378 |
+
* file, returns an object representing the SourceMap range in the
|
379 |
+
* original file if found, or an empty object if not.
|
380 |
+
*
|
381 |
+
* The object returned contains the following keys:
|
382 |
+
*
|
383 |
+
* The returned value represents the raw range as it appears in the
|
384 |
+
* SourceMap, based on zero-indexed offsets, _not_ 1-indexed line and
|
385 |
+
* column numbers as they appear in Error messages and CallSite
|
386 |
+
* objects.
|
387 |
+
*
|
388 |
+
* To get the corresponding 1-indexed line and column numbers from a
|
389 |
+
* lineNumber and columnNumber as they are reported by Error stacks
|
390 |
+
* and CallSite objects, use `sourceMap.findOrigin(lineNumber, columnNumber)`
|
391 |
+
* @param lineOffset The zero-indexed line number offset in the generated source
|
392 |
+
* @param columnOffset The zero-indexed column number offset in the generated source
|
393 |
+
*/
|
394 |
+
findEntry(lineOffset: number, columnOffset: number): SourceMapping | {};
|
395 |
+
/**
|
396 |
+
* Given a 1-indexed `lineNumber` and `columnNumber` from a call site in the generated source,
|
397 |
+
* find the corresponding call site location in the original source.
|
398 |
+
*
|
399 |
+
* If the `lineNumber` and `columnNumber` provided are not found in any source map,
|
400 |
+
* then an empty object is returned.
|
401 |
+
* @param lineNumber The 1-indexed line number of the call site in the generated source
|
402 |
+
* @param columnNumber The 1-indexed column number of the call site in the generated source
|
403 |
+
*/
|
404 |
+
findOrigin(lineNumber: number, columnNumber: number): SourceOrigin | {};
|
405 |
+
}
|
406 |
+
function runMain(main?: string): void;
|
407 |
+
function wrap(script: string): string;
|
408 |
+
}
|
409 |
+
global {
|
410 |
+
interface ImportMeta {
|
411 |
+
/**
|
412 |
+
* The directory name of the current module. This is the same as the `path.dirname()` of the `import.meta.filename`.
|
413 |
+
* **Caveat:** only present on `file:` modules.
|
414 |
+
*/
|
415 |
+
dirname: string;
|
416 |
+
/**
|
417 |
+
* The full absolute path and filename of the current module, with symlinks resolved.
|
418 |
+
* This is the same as the `url.fileURLToPath()` of the `import.meta.url`.
|
419 |
+
* **Caveat:** only local modules support this property. Modules not using the `file:` protocol will not provide it.
|
420 |
+
*/
|
421 |
+
filename: string;
|
422 |
+
/**
|
423 |
+
* The absolute `file:` URL of the module.
|
424 |
+
*/
|
425 |
+
url: string;
|
426 |
+
/**
|
427 |
+
* Provides a module-relative resolution function scoped to each module, returning
|
428 |
+
* the URL string.
|
429 |
+
*
|
430 |
+
* Second `parent` parameter is only used when the `--experimental-import-meta-resolve`
|
431 |
+
* command flag enabled.
|
432 |
+
*
|
433 |
+
* @since v20.6.0
|
434 |
+
*
|
435 |
+
* @param specifier The module specifier to resolve relative to `parent`.
|
436 |
+
* @param parent The absolute parent module URL to resolve from.
|
437 |
+
* @returns The absolute (`file:`) URL string for the resolved module.
|
438 |
+
*/
|
439 |
+
resolve(specifier: string, parent?: string | URL | undefined): string;
|
440 |
+
}
|
441 |
+
namespace NodeJS {
|
442 |
+
interface Module {
|
443 |
+
/**
|
444 |
+
* The module objects required for the first time by this one.
|
445 |
+
* @since v0.1.16
|
446 |
+
*/
|
447 |
+
children: Module[];
|
448 |
+
/**
|
449 |
+
* The `module.exports` object is created by the `Module` system. Sometimes this is
|
450 |
+
* not acceptable; many want their module to be an instance of some class. To do
|
451 |
+
* this, assign the desired export object to `module.exports`.
|
452 |
+
* @since v0.1.16
|
453 |
+
*/
|
454 |
+
exports: any;
|
455 |
+
/**
|
456 |
+
* The fully resolved filename of the module.
|
457 |
+
* @since v0.1.16
|
458 |
+
*/
|
459 |
+
filename: string;
|
460 |
+
/**
|
461 |
+
* The identifier for the module. Typically this is the fully resolved
|
462 |
+
* filename.
|
463 |
+
* @since v0.1.16
|
464 |
+
*/
|
465 |
+
id: string;
|
466 |
+
/**
|
467 |
+
* `true` if the module is running during the Node.js preload
|
468 |
+
* phase.
|
469 |
+
* @since v15.4.0, v14.17.0
|
470 |
+
*/
|
471 |
+
isPreloading: boolean;
|
472 |
+
/**
|
473 |
+
* Whether or not the module is done loading, or is in the process of
|
474 |
+
* loading.
|
475 |
+
* @since v0.1.16
|
476 |
+
*/
|
477 |
+
loaded: boolean;
|
478 |
+
/**
|
479 |
+
* The module that first required this one, or `null` if the current module is the
|
480 |
+
* entry point of the current process, or `undefined` if the module was loaded by
|
481 |
+
* something that is not a CommonJS module (e.g. REPL or `import`).
|
482 |
+
* @since v0.1.16
|
483 |
+
* @deprecated Please use `require.main` and `module.children` instead.
|
484 |
+
*/
|
485 |
+
parent: Module | null | undefined;
|
486 |
+
/**
|
487 |
+
* The directory name of the module. This is usually the same as the
|
488 |
+
* `path.dirname()` of the `module.id`.
|
489 |
+
* @since v11.14.0
|
490 |
+
*/
|
491 |
+
path: string;
|
492 |
+
/**
|
493 |
+
* The search paths for the module.
|
494 |
+
* @since v0.4.0
|
495 |
+
*/
|
496 |
+
paths: string[];
|
497 |
+
/**
|
498 |
+
* The `module.require()` method provides a way to load a module as if
|
499 |
+
* `require()` was called from the original module.
|
500 |
+
* @since v0.5.1
|
501 |
+
*/
|
502 |
+
require(id: string): any;
|
503 |
+
}
|
504 |
+
interface Require {
|
505 |
+
/**
|
506 |
+
* Used to import modules, `JSON`, and local files.
|
507 |
+
* @since v0.1.13
|
508 |
+
*/
|
509 |
+
(id: string): any;
|
510 |
+
/**
|
511 |
+
* Modules are cached in this object when they are required. By deleting a key
|
512 |
+
* value from this object, the next `require` will reload the module.
|
513 |
+
* This does not apply to
|
514 |
+
* [native addons](https://nodejs.org/docs/latest-v22.x/api/addons.html),
|
515 |
+
* for which reloading will result in an error.
|
516 |
+
* @since v0.3.0
|
517 |
+
*/
|
518 |
+
cache: Dict<Module>;
|
519 |
+
/**
|
520 |
+
* Instruct `require` on how to handle certain file extensions.
|
521 |
+
* @since v0.3.0
|
522 |
+
* @deprecated
|
523 |
+
*/
|
524 |
+
extensions: RequireExtensions;
|
525 |
+
/**
|
526 |
+
* The `Module` object representing the entry script loaded when the Node.js
|
527 |
+
* process launched, or `undefined` if the entry point of the program is not a
|
528 |
+
* CommonJS module.
|
529 |
+
* @since v0.1.17
|
530 |
+
*/
|
531 |
+
main: Module | undefined;
|
532 |
+
/**
|
533 |
+
* @since v0.3.0
|
534 |
+
*/
|
535 |
+
resolve: RequireResolve;
|
536 |
+
}
|
537 |
+
/** @deprecated */
|
538 |
+
interface RequireExtensions extends Dict<(module: Module, filename: string) => any> {
|
539 |
+
".js": (module: Module, filename: string) => any;
|
540 |
+
".json": (module: Module, filename: string) => any;
|
541 |
+
".node": (module: Module, filename: string) => any;
|
542 |
+
}
|
543 |
+
interface RequireResolveOptions {
|
544 |
+
/**
|
545 |
+
* Paths to resolve module location from. If present, these
|
546 |
+
* paths are used instead of the default resolution paths, with the exception
|
547 |
+
* of
|
548 |
+
* [GLOBAL\_FOLDERS](https://nodejs.org/docs/latest-v22.x/api/modules.html#loading-from-the-global-folders)
|
549 |
+
* like `$HOME/.node_modules`, which are
|
550 |
+
* always included. Each of these paths is used as a starting point for
|
551 |
+
* the module resolution algorithm, meaning that the `node_modules` hierarchy
|
552 |
+
* is checked from this location.
|
553 |
+
* @since v8.9.0
|
554 |
+
*/
|
555 |
+
paths?: string[] | undefined;
|
556 |
+
}
|
557 |
+
interface RequireResolve {
|
558 |
+
/**
|
559 |
+
* Use the internal `require()` machinery to look up the location of a module,
|
560 |
+
* but rather than loading the module, just return the resolved filename.
|
561 |
+
*
|
562 |
+
* If the module can not be found, a `MODULE_NOT_FOUND` error is thrown.
|
563 |
+
* @since v0.3.0
|
564 |
+
* @param request The module path to resolve.
|
565 |
+
*/
|
566 |
+
(request: string, options?: RequireResolveOptions): string;
|
567 |
+
/**
|
568 |
+
* Returns an array containing the paths searched during resolution of `request` or
|
569 |
+
* `null` if the `request` string references a core module, for example `http` or
|
570 |
+
* `fs`.
|
571 |
+
* @since v8.9.0
|
572 |
+
* @param request The module path whose lookup paths are being retrieved.
|
573 |
+
*/
|
574 |
+
paths(request: string): string[] | null;
|
575 |
+
}
|
576 |
+
}
|
577 |
+
/**
|
578 |
+
* The directory name of the current module. This is the same as the
|
579 |
+
* `path.dirname()` of the `__filename`.
|
580 |
+
* @since v0.1.27
|
581 |
+
*/
|
582 |
+
var __dirname: string;
|
583 |
+
/**
|
584 |
+
* The file name of the current module. This is the current module file's absolute
|
585 |
+
* path with symlinks resolved.
|
586 |
+
*
|
587 |
+
* For a main program this is not necessarily the same as the file name used in the
|
588 |
+
* command line.
|
589 |
+
* @since v0.0.1
|
590 |
+
*/
|
591 |
+
var __filename: string;
|
592 |
+
/**
|
593 |
+
* The `exports` variable is available within a module's file-level scope, and is
|
594 |
+
* assigned the value of `module.exports` before the module is evaluated.
|
595 |
+
* @since v0.1.16
|
596 |
+
*/
|
597 |
+
var exports: NodeJS.Module["exports"];
|
598 |
+
/**
|
599 |
+
* A reference to the current module.
|
600 |
+
* @since v0.1.16
|
601 |
+
*/
|
602 |
+
var module: NodeJS.Module;
|
603 |
+
/**
|
604 |
+
* @since v0.1.13
|
605 |
+
*/
|
606 |
+
var require: NodeJS.Require;
|
607 |
+
// Global-scope aliases for backwards compatibility with @types/node <13.0.x
|
608 |
+
// TODO: consider removing in a future major version update
|
609 |
+
/** @deprecated Use `NodeJS.Module` instead. */
|
610 |
+
interface NodeModule extends NodeJS.Module {}
|
611 |
+
/** @deprecated Use `NodeJS.Require` instead. */
|
612 |
+
interface NodeRequire extends NodeJS.Require {}
|
613 |
+
/** @deprecated Use `NodeJS.RequireResolve` instead. */
|
614 |
+
interface RequireResolve extends NodeJS.RequireResolve {}
|
615 |
+
}
|
616 |
+
export = Module;
|
617 |
+
}
|
618 |
+
declare module "node:module" {
|
619 |
+
import module = require("module");
|
620 |
+
export = module;
|
621 |
+
}
|
clone/node_modules/@types/node/net.d.ts
ADDED
@@ -0,0 +1,1004 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* > Stability: 2 - Stable
|
3 |
+
*
|
4 |
+
* The `node:net` module provides an asynchronous network API for creating stream-based
|
5 |
+
* TCP or `IPC` servers ({@link createServer}) and clients
|
6 |
+
* ({@link createConnection}).
|
7 |
+
*
|
8 |
+
* It can be accessed using:
|
9 |
+
*
|
10 |
+
* ```js
|
11 |
+
* import net from 'node:net';
|
12 |
+
* ```
|
13 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/net.js)
|
14 |
+
*/
|
15 |
+
declare module "net" {
|
16 |
+
import * as stream from "node:stream";
|
17 |
+
import { Abortable, EventEmitter } from "node:events";
|
18 |
+
import * as dns from "node:dns";
|
19 |
+
type LookupFunction = (
|
20 |
+
hostname: string,
|
21 |
+
options: dns.LookupOptions,
|
22 |
+
callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,
|
23 |
+
) => void;
|
24 |
+
interface AddressInfo {
|
25 |
+
address: string;
|
26 |
+
family: string;
|
27 |
+
port: number;
|
28 |
+
}
|
29 |
+
interface SocketConstructorOpts {
|
30 |
+
fd?: number | undefined;
|
31 |
+
allowHalfOpen?: boolean | undefined;
|
32 |
+
onread?: OnReadOpts | undefined;
|
33 |
+
readable?: boolean | undefined;
|
34 |
+
writable?: boolean | undefined;
|
35 |
+
signal?: AbortSignal;
|
36 |
+
}
|
37 |
+
interface OnReadOpts {
|
38 |
+
buffer: Uint8Array | (() => Uint8Array);
|
39 |
+
/**
|
40 |
+
* This function is called for every chunk of incoming data.
|
41 |
+
* Two arguments are passed to it: the number of bytes written to `buffer` and a reference to `buffer`.
|
42 |
+
* Return `false` from this function to implicitly `pause()` the socket.
|
43 |
+
*/
|
44 |
+
callback(bytesWritten: number, buffer: Uint8Array): boolean;
|
45 |
+
}
|
46 |
+
// TODO: remove empty ConnectOpts placeholder at next major @types/node version.
|
47 |
+
/** @deprecated */
|
48 |
+
interface ConnectOpts {}
|
49 |
+
interface TcpSocketConnectOpts {
|
50 |
+
port: number;
|
51 |
+
host?: string | undefined;
|
52 |
+
localAddress?: string | undefined;
|
53 |
+
localPort?: number | undefined;
|
54 |
+
hints?: number | undefined;
|
55 |
+
family?: number | undefined;
|
56 |
+
lookup?: LookupFunction | undefined;
|
57 |
+
noDelay?: boolean | undefined;
|
58 |
+
keepAlive?: boolean | undefined;
|
59 |
+
keepAliveInitialDelay?: number | undefined;
|
60 |
+
/**
|
61 |
+
* @since v18.13.0
|
62 |
+
*/
|
63 |
+
autoSelectFamily?: boolean | undefined;
|
64 |
+
/**
|
65 |
+
* @since v18.13.0
|
66 |
+
*/
|
67 |
+
autoSelectFamilyAttemptTimeout?: number | undefined;
|
68 |
+
}
|
69 |
+
interface IpcSocketConnectOpts {
|
70 |
+
path: string;
|
71 |
+
}
|
72 |
+
type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;
|
73 |
+
type SocketReadyState = "opening" | "open" | "readOnly" | "writeOnly" | "closed";
|
74 |
+
/**
|
75 |
+
* This class is an abstraction of a TCP socket or a streaming `IPC` endpoint
|
76 |
+
* (uses named pipes on Windows, and Unix domain sockets otherwise). It is also
|
77 |
+
* an `EventEmitter`.
|
78 |
+
*
|
79 |
+
* A `net.Socket` can be created by the user and used directly to interact with
|
80 |
+
* a server. For example, it is returned by {@link createConnection},
|
81 |
+
* so the user can use it to talk to the server.
|
82 |
+
*
|
83 |
+
* It can also be created by Node.js and passed to the user when a connection
|
84 |
+
* is received. For example, it is passed to the listeners of a `'connection'` event emitted on a {@link Server}, so the user can use
|
85 |
+
* it to interact with the client.
|
86 |
+
* @since v0.3.4
|
87 |
+
*/
|
88 |
+
class Socket extends stream.Duplex {
|
89 |
+
constructor(options?: SocketConstructorOpts);
|
90 |
+
/**
|
91 |
+
* Destroys the socket after all data is written. If the `finish` event was already emitted the socket is destroyed immediately.
|
92 |
+
* If the socket is still writable it implicitly calls `socket.end()`.
|
93 |
+
* @since v0.3.4
|
94 |
+
*/
|
95 |
+
destroySoon(): void;
|
96 |
+
/**
|
97 |
+
* Sends data on the socket. The second parameter specifies the encoding in the
|
98 |
+
* case of a string. It defaults to UTF8 encoding.
|
99 |
+
*
|
100 |
+
* Returns `true` if the entire data was flushed successfully to the kernel
|
101 |
+
* buffer. Returns `false` if all or part of the data was queued in user memory.`'drain'` will be emitted when the buffer is again free.
|
102 |
+
*
|
103 |
+
* The optional `callback` parameter will be executed when the data is finally
|
104 |
+
* written out, which may not be immediately.
|
105 |
+
*
|
106 |
+
* See `Writable` stream `write()` method for more
|
107 |
+
* information.
|
108 |
+
* @since v0.1.90
|
109 |
+
* @param [encoding='utf8'] Only used when data is `string`.
|
110 |
+
*/
|
111 |
+
write(buffer: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
112 |
+
write(str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error) => void): boolean;
|
113 |
+
/**
|
114 |
+
* Initiate a connection on a given socket.
|
115 |
+
*
|
116 |
+
* Possible signatures:
|
117 |
+
*
|
118 |
+
* * `socket.connect(options[, connectListener])`
|
119 |
+
* * `socket.connect(path[, connectListener])` for `IPC` connections.
|
120 |
+
* * `socket.connect(port[, host][, connectListener])` for TCP connections.
|
121 |
+
* * Returns: `net.Socket` The socket itself.
|
122 |
+
*
|
123 |
+
* This function is asynchronous. When the connection is established, the `'connect'` event will be emitted. If there is a problem connecting,
|
124 |
+
* instead of a `'connect'` event, an `'error'` event will be emitted with
|
125 |
+
* the error passed to the `'error'` listener.
|
126 |
+
* The last parameter `connectListener`, if supplied, will be added as a listener
|
127 |
+
* for the `'connect'` event **once**.
|
128 |
+
*
|
129 |
+
* This function should only be used for reconnecting a socket after`'close'` has been emitted or otherwise it may lead to undefined
|
130 |
+
* behavior.
|
131 |
+
*/
|
132 |
+
connect(options: SocketConnectOpts, connectionListener?: () => void): this;
|
133 |
+
connect(port: number, host: string, connectionListener?: () => void): this;
|
134 |
+
connect(port: number, connectionListener?: () => void): this;
|
135 |
+
connect(path: string, connectionListener?: () => void): this;
|
136 |
+
/**
|
137 |
+
* Set the encoding for the socket as a `Readable Stream`. See `readable.setEncoding()` for more information.
|
138 |
+
* @since v0.1.90
|
139 |
+
* @return The socket itself.
|
140 |
+
*/
|
141 |
+
setEncoding(encoding?: BufferEncoding): this;
|
142 |
+
/**
|
143 |
+
* Pauses the reading of data. That is, `'data'` events will not be emitted.
|
144 |
+
* Useful to throttle back an upload.
|
145 |
+
* @return The socket itself.
|
146 |
+
*/
|
147 |
+
pause(): this;
|
148 |
+
/**
|
149 |
+
* Close the TCP connection by sending an RST packet and destroy the stream.
|
150 |
+
* If this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected.
|
151 |
+
* Otherwise, it will call `socket.destroy` with an `ERR_SOCKET_CLOSED` Error.
|
152 |
+
* If this is not a TCP socket (for example, a pipe), calling this method will immediately throw an `ERR_INVALID_HANDLE_TYPE` Error.
|
153 |
+
* @since v18.3.0, v16.17.0
|
154 |
+
*/
|
155 |
+
resetAndDestroy(): this;
|
156 |
+
/**
|
157 |
+
* Resumes reading after a call to `socket.pause()`.
|
158 |
+
* @return The socket itself.
|
159 |
+
*/
|
160 |
+
resume(): this;
|
161 |
+
/**
|
162 |
+
* Sets the socket to timeout after `timeout` milliseconds of inactivity on
|
163 |
+
* the socket. By default `net.Socket` do not have a timeout.
|
164 |
+
*
|
165 |
+
* When an idle timeout is triggered the socket will receive a `'timeout'` event but the connection will not be severed. The user must manually call `socket.end()` or `socket.destroy()` to
|
166 |
+
* end the connection.
|
167 |
+
*
|
168 |
+
* ```js
|
169 |
+
* socket.setTimeout(3000);
|
170 |
+
* socket.on('timeout', () => {
|
171 |
+
* console.log('socket timeout');
|
172 |
+
* socket.end();
|
173 |
+
* });
|
174 |
+
* ```
|
175 |
+
*
|
176 |
+
* If `timeout` is 0, then the existing idle timeout is disabled.
|
177 |
+
*
|
178 |
+
* The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.
|
179 |
+
* @since v0.1.90
|
180 |
+
* @return The socket itself.
|
181 |
+
*/
|
182 |
+
setTimeout(timeout: number, callback?: () => void): this;
|
183 |
+
/**
|
184 |
+
* Enable/disable the use of Nagle's algorithm.
|
185 |
+
*
|
186 |
+
* When a TCP connection is created, it will have Nagle's algorithm enabled.
|
187 |
+
*
|
188 |
+
* Nagle's algorithm delays data before it is sent via the network. It attempts
|
189 |
+
* to optimize throughput at the expense of latency.
|
190 |
+
*
|
191 |
+
* Passing `true` for `noDelay` or not passing an argument will disable Nagle's
|
192 |
+
* algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's
|
193 |
+
* algorithm.
|
194 |
+
* @since v0.1.90
|
195 |
+
* @param [noDelay=true]
|
196 |
+
* @return The socket itself.
|
197 |
+
*/
|
198 |
+
setNoDelay(noDelay?: boolean): this;
|
199 |
+
/**
|
200 |
+
* Enable/disable keep-alive functionality, and optionally set the initial
|
201 |
+
* delay before the first keepalive probe is sent on an idle socket.
|
202 |
+
*
|
203 |
+
* Set `initialDelay` (in milliseconds) to set the delay between the last
|
204 |
+
* data packet received and the first keepalive probe. Setting `0` for`initialDelay` will leave the value unchanged from the default
|
205 |
+
* (or previous) setting.
|
206 |
+
*
|
207 |
+
* Enabling the keep-alive functionality will set the following socket options:
|
208 |
+
*
|
209 |
+
* * `SO_KEEPALIVE=1`
|
210 |
+
* * `TCP_KEEPIDLE=initialDelay`
|
211 |
+
* * `TCP_KEEPCNT=10`
|
212 |
+
* * `TCP_KEEPINTVL=1`
|
213 |
+
* @since v0.1.92
|
214 |
+
* @param [enable=false]
|
215 |
+
* @param [initialDelay=0]
|
216 |
+
* @return The socket itself.
|
217 |
+
*/
|
218 |
+
setKeepAlive(enable?: boolean, initialDelay?: number): this;
|
219 |
+
/**
|
220 |
+
* Returns the bound `address`, the address `family` name and `port` of the
|
221 |
+
* socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
|
222 |
+
* @since v0.1.90
|
223 |
+
*/
|
224 |
+
address(): AddressInfo | {};
|
225 |
+
/**
|
226 |
+
* Calling `unref()` on a socket will allow the program to exit if this is the only
|
227 |
+
* active socket in the event system. If the socket is already `unref`ed calling`unref()` again will have no effect.
|
228 |
+
* @since v0.9.1
|
229 |
+
* @return The socket itself.
|
230 |
+
*/
|
231 |
+
unref(): this;
|
232 |
+
/**
|
233 |
+
* Opposite of `unref()`, calling `ref()` on a previously `unref`ed socket will _not_ let the program exit if it's the only socket left (the default behavior).
|
234 |
+
* If the socket is `ref`ed calling `ref` again will have no effect.
|
235 |
+
* @since v0.9.1
|
236 |
+
* @return The socket itself.
|
237 |
+
*/
|
238 |
+
ref(): this;
|
239 |
+
/**
|
240 |
+
* This property is only present if the family autoselection algorithm is enabled in `socket.connect(options)`
|
241 |
+
* and it is an array of the addresses that have been attempted.
|
242 |
+
*
|
243 |
+
* Each address is a string in the form of `$IP:$PORT`.
|
244 |
+
* If the connection was successful, then the last address is the one that the socket is currently connected to.
|
245 |
+
* @since v19.4.0
|
246 |
+
*/
|
247 |
+
readonly autoSelectFamilyAttemptedAddresses: string[];
|
248 |
+
/**
|
249 |
+
* This property shows the number of characters buffered for writing. The buffer
|
250 |
+
* may contain strings whose length after encoding is not yet known. So this number
|
251 |
+
* is only an approximation of the number of bytes in the buffer.
|
252 |
+
*
|
253 |
+
* `net.Socket` has the property that `socket.write()` always works. This is to
|
254 |
+
* help users get up and running quickly. The computer cannot always keep up
|
255 |
+
* with the amount of data that is written to a socket. The network connection
|
256 |
+
* simply might be too slow. Node.js will internally queue up the data written to a
|
257 |
+
* socket and send it out over the wire when it is possible.
|
258 |
+
*
|
259 |
+
* The consequence of this internal buffering is that memory may grow.
|
260 |
+
* Users who experience large or growing `bufferSize` should attempt to
|
261 |
+
* "throttle" the data flows in their program with `socket.pause()` and `socket.resume()`.
|
262 |
+
* @since v0.3.8
|
263 |
+
* @deprecated Since v14.6.0 - Use `writableLength` instead.
|
264 |
+
*/
|
265 |
+
readonly bufferSize: number;
|
266 |
+
/**
|
267 |
+
* The amount of received bytes.
|
268 |
+
* @since v0.5.3
|
269 |
+
*/
|
270 |
+
readonly bytesRead: number;
|
271 |
+
/**
|
272 |
+
* The amount of bytes sent.
|
273 |
+
* @since v0.5.3
|
274 |
+
*/
|
275 |
+
readonly bytesWritten: number;
|
276 |
+
/**
|
277 |
+
* If `true`, `socket.connect(options[, connectListener])` was
|
278 |
+
* called and has not yet finished. It will stay `true` until the socket becomes
|
279 |
+
* connected, then it is set to `false` and the `'connect'` event is emitted. Note
|
280 |
+
* that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.
|
281 |
+
* @since v6.1.0
|
282 |
+
*/
|
283 |
+
readonly connecting: boolean;
|
284 |
+
/**
|
285 |
+
* This is `true` if the socket is not connected yet, either because `.connect()`has not yet been called or because it is still in the process of connecting
|
286 |
+
* (see `socket.connecting`).
|
287 |
+
* @since v11.2.0, v10.16.0
|
288 |
+
*/
|
289 |
+
readonly pending: boolean;
|
290 |
+
/**
|
291 |
+
* See `writable.destroyed` for further details.
|
292 |
+
*/
|
293 |
+
readonly destroyed: boolean;
|
294 |
+
/**
|
295 |
+
* The string representation of the local IP address the remote client is
|
296 |
+
* connecting on. For example, in a server listening on `'0.0.0.0'`, if a client
|
297 |
+
* connects on `'192.168.1.1'`, the value of `socket.localAddress` would be`'192.168.1.1'`.
|
298 |
+
* @since v0.9.6
|
299 |
+
*/
|
300 |
+
readonly localAddress?: string;
|
301 |
+
/**
|
302 |
+
* The numeric representation of the local port. For example, `80` or `21`.
|
303 |
+
* @since v0.9.6
|
304 |
+
*/
|
305 |
+
readonly localPort?: number;
|
306 |
+
/**
|
307 |
+
* The string representation of the local IP family. `'IPv4'` or `'IPv6'`.
|
308 |
+
* @since v18.8.0, v16.18.0
|
309 |
+
*/
|
310 |
+
readonly localFamily?: string;
|
311 |
+
/**
|
312 |
+
* This property represents the state of the connection as a string.
|
313 |
+
*
|
314 |
+
* * If the stream is connecting `socket.readyState` is `opening`.
|
315 |
+
* * If the stream is readable and writable, it is `open`.
|
316 |
+
* * If the stream is readable and not writable, it is `readOnly`.
|
317 |
+
* * If the stream is not readable and writable, it is `writeOnly`.
|
318 |
+
* @since v0.5.0
|
319 |
+
*/
|
320 |
+
readonly readyState: SocketReadyState;
|
321 |
+
/**
|
322 |
+
* The string representation of the remote IP address. For example,`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if
|
323 |
+
* the socket is destroyed (for example, if the client disconnected).
|
324 |
+
* @since v0.5.10
|
325 |
+
*/
|
326 |
+
readonly remoteAddress?: string | undefined;
|
327 |
+
/**
|
328 |
+
* The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. Value may be `undefined` if
|
329 |
+
* the socket is destroyed (for example, if the client disconnected).
|
330 |
+
* @since v0.11.14
|
331 |
+
*/
|
332 |
+
readonly remoteFamily?: string | undefined;
|
333 |
+
/**
|
334 |
+
* The numeric representation of the remote port. For example, `80` or `21`. Value may be `undefined` if
|
335 |
+
* the socket is destroyed (for example, if the client disconnected).
|
336 |
+
* @since v0.5.10
|
337 |
+
*/
|
338 |
+
readonly remotePort?: number | undefined;
|
339 |
+
/**
|
340 |
+
* The socket timeout in milliseconds as set by `socket.setTimeout()`.
|
341 |
+
* It is `undefined` if a timeout has not been set.
|
342 |
+
* @since v10.7.0
|
343 |
+
*/
|
344 |
+
readonly timeout?: number | undefined;
|
345 |
+
/**
|
346 |
+
* Half-closes the socket. i.e., it sends a FIN packet. It is possible the
|
347 |
+
* server will still send some data.
|
348 |
+
*
|
349 |
+
* See `writable.end()` for further details.
|
350 |
+
* @since v0.1.90
|
351 |
+
* @param [encoding='utf8'] Only used when data is `string`.
|
352 |
+
* @param callback Optional callback for when the socket is finished.
|
353 |
+
* @return The socket itself.
|
354 |
+
*/
|
355 |
+
end(callback?: () => void): this;
|
356 |
+
end(buffer: Uint8Array | string, callback?: () => void): this;
|
357 |
+
end(str: Uint8Array | string, encoding?: BufferEncoding, callback?: () => void): this;
|
358 |
+
/**
|
359 |
+
* events.EventEmitter
|
360 |
+
* 1. close
|
361 |
+
* 2. connect
|
362 |
+
* 3. connectionAttempt
|
363 |
+
* 4. connectionAttemptFailed
|
364 |
+
* 5. connectionAttemptTimeout
|
365 |
+
* 6. data
|
366 |
+
* 7. drain
|
367 |
+
* 8. end
|
368 |
+
* 9. error
|
369 |
+
* 10. lookup
|
370 |
+
* 11. ready
|
371 |
+
* 12. timeout
|
372 |
+
*/
|
373 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
374 |
+
addListener(event: "close", listener: (hadError: boolean) => void): this;
|
375 |
+
addListener(event: "connect", listener: () => void): this;
|
376 |
+
addListener(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;
|
377 |
+
addListener(
|
378 |
+
event: "connectionAttemptFailed",
|
379 |
+
listener: (ip: string, port: number, family: number) => void,
|
380 |
+
): this;
|
381 |
+
addListener(
|
382 |
+
event: "connectionAttemptTimeout",
|
383 |
+
listener: (ip: string, port: number, family: number) => void,
|
384 |
+
): this;
|
385 |
+
addListener(event: "data", listener: (data: Buffer) => void): this;
|
386 |
+
addListener(event: "drain", listener: () => void): this;
|
387 |
+
addListener(event: "end", listener: () => void): this;
|
388 |
+
addListener(event: "error", listener: (err: Error) => void): this;
|
389 |
+
addListener(
|
390 |
+
event: "lookup",
|
391 |
+
listener: (err: Error, address: string, family: string | number, host: string) => void,
|
392 |
+
): this;
|
393 |
+
addListener(event: "ready", listener: () => void): this;
|
394 |
+
addListener(event: "timeout", listener: () => void): this;
|
395 |
+
emit(event: string | symbol, ...args: any[]): boolean;
|
396 |
+
emit(event: "close", hadError: boolean): boolean;
|
397 |
+
emit(event: "connect"): boolean;
|
398 |
+
emit(event: "connectionAttempt", ip: string, port: number, family: number): boolean;
|
399 |
+
emit(event: "connectionAttemptFailed", ip: string, port: number, family: number): boolean;
|
400 |
+
emit(event: "connectionAttemptTimeout", ip: string, port: number, family: number): boolean;
|
401 |
+
emit(event: "data", data: Buffer): boolean;
|
402 |
+
emit(event: "drain"): boolean;
|
403 |
+
emit(event: "end"): boolean;
|
404 |
+
emit(event: "error", err: Error): boolean;
|
405 |
+
emit(event: "lookup", err: Error, address: string, family: string | number, host: string): boolean;
|
406 |
+
emit(event: "ready"): boolean;
|
407 |
+
emit(event: "timeout"): boolean;
|
408 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
409 |
+
on(event: "close", listener: (hadError: boolean) => void): this;
|
410 |
+
on(event: "connect", listener: () => void): this;
|
411 |
+
on(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;
|
412 |
+
on(event: "connectionAttemptFailed", listener: (ip: string, port: number, family: number) => void): this;
|
413 |
+
on(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this;
|
414 |
+
on(event: "data", listener: (data: Buffer) => void): this;
|
415 |
+
on(event: "drain", listener: () => void): this;
|
416 |
+
on(event: "end", listener: () => void): this;
|
417 |
+
on(event: "error", listener: (err: Error) => void): this;
|
418 |
+
on(
|
419 |
+
event: "lookup",
|
420 |
+
listener: (err: Error, address: string, family: string | number, host: string) => void,
|
421 |
+
): this;
|
422 |
+
on(event: "ready", listener: () => void): this;
|
423 |
+
on(event: "timeout", listener: () => void): this;
|
424 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
425 |
+
once(event: "close", listener: (hadError: boolean) => void): this;
|
426 |
+
once(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;
|
427 |
+
once(event: "connectionAttemptFailed", listener: (ip: string, port: number, family: number) => void): this;
|
428 |
+
once(event: "connectionAttemptTimeout", listener: (ip: string, port: number, family: number) => void): this;
|
429 |
+
once(event: "connect", listener: () => void): this;
|
430 |
+
once(event: "data", listener: (data: Buffer) => void): this;
|
431 |
+
once(event: "drain", listener: () => void): this;
|
432 |
+
once(event: "end", listener: () => void): this;
|
433 |
+
once(event: "error", listener: (err: Error) => void): this;
|
434 |
+
once(
|
435 |
+
event: "lookup",
|
436 |
+
listener: (err: Error, address: string, family: string | number, host: string) => void,
|
437 |
+
): this;
|
438 |
+
once(event: "ready", listener: () => void): this;
|
439 |
+
once(event: "timeout", listener: () => void): this;
|
440 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
441 |
+
prependListener(event: "close", listener: (hadError: boolean) => void): this;
|
442 |
+
prependListener(event: "connect", listener: () => void): this;
|
443 |
+
prependListener(event: "connectionAttempt", listener: (ip: string, port: number, family: number) => void): this;
|
444 |
+
prependListener(
|
445 |
+
event: "connectionAttemptFailed",
|
446 |
+
listener: (ip: string, port: number, family: number) => void,
|
447 |
+
): this;
|
448 |
+
prependListener(
|
449 |
+
event: "connectionAttemptTimeout",
|
450 |
+
listener: (ip: string, port: number, family: number) => void,
|
451 |
+
): this;
|
452 |
+
prependListener(event: "data", listener: (data: Buffer) => void): this;
|
453 |
+
prependListener(event: "drain", listener: () => void): this;
|
454 |
+
prependListener(event: "end", listener: () => void): this;
|
455 |
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
456 |
+
prependListener(
|
457 |
+
event: "lookup",
|
458 |
+
listener: (err: Error, address: string, family: string | number, host: string) => void,
|
459 |
+
): this;
|
460 |
+
prependListener(event: "ready", listener: () => void): this;
|
461 |
+
prependListener(event: "timeout", listener: () => void): this;
|
462 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
463 |
+
prependOnceListener(event: "close", listener: (hadError: boolean) => void): this;
|
464 |
+
prependOnceListener(event: "connect", listener: () => void): this;
|
465 |
+
prependOnceListener(
|
466 |
+
event: "connectionAttempt",
|
467 |
+
listener: (ip: string, port: number, family: number) => void,
|
468 |
+
): this;
|
469 |
+
prependOnceListener(
|
470 |
+
event: "connectionAttemptFailed",
|
471 |
+
listener: (ip: string, port: number, family: number) => void,
|
472 |
+
): this;
|
473 |
+
prependOnceListener(
|
474 |
+
event: "connectionAttemptTimeout",
|
475 |
+
listener: (ip: string, port: number, family: number) => void,
|
476 |
+
): this;
|
477 |
+
prependOnceListener(event: "data", listener: (data: Buffer) => void): this;
|
478 |
+
prependOnceListener(event: "drain", listener: () => void): this;
|
479 |
+
prependOnceListener(event: "end", listener: () => void): this;
|
480 |
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
481 |
+
prependOnceListener(
|
482 |
+
event: "lookup",
|
483 |
+
listener: (err: Error, address: string, family: string | number, host: string) => void,
|
484 |
+
): this;
|
485 |
+
prependOnceListener(event: "ready", listener: () => void): this;
|
486 |
+
prependOnceListener(event: "timeout", listener: () => void): this;
|
487 |
+
}
|
488 |
+
interface ListenOptions extends Abortable {
|
489 |
+
port?: number | undefined;
|
490 |
+
host?: string | undefined;
|
491 |
+
backlog?: number | undefined;
|
492 |
+
path?: string | undefined;
|
493 |
+
exclusive?: boolean | undefined;
|
494 |
+
readableAll?: boolean | undefined;
|
495 |
+
writableAll?: boolean | undefined;
|
496 |
+
/**
|
497 |
+
* @default false
|
498 |
+
*/
|
499 |
+
ipv6Only?: boolean | undefined;
|
500 |
+
}
|
501 |
+
interface ServerOpts {
|
502 |
+
/**
|
503 |
+
* Indicates whether half-opened TCP connections are allowed.
|
504 |
+
* @default false
|
505 |
+
*/
|
506 |
+
allowHalfOpen?: boolean | undefined;
|
507 |
+
/**
|
508 |
+
* Indicates whether the socket should be paused on incoming connections.
|
509 |
+
* @default false
|
510 |
+
*/
|
511 |
+
pauseOnConnect?: boolean | undefined;
|
512 |
+
/**
|
513 |
+
* If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
|
514 |
+
* @default false
|
515 |
+
* @since v16.5.0
|
516 |
+
*/
|
517 |
+
noDelay?: boolean | undefined;
|
518 |
+
/**
|
519 |
+
* If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
|
520 |
+
* similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
|
521 |
+
* @default false
|
522 |
+
* @since v16.5.0
|
523 |
+
*/
|
524 |
+
keepAlive?: boolean | undefined;
|
525 |
+
/**
|
526 |
+
* If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
|
527 |
+
* @default 0
|
528 |
+
* @since v16.5.0
|
529 |
+
*/
|
530 |
+
keepAliveInitialDelay?: number | undefined;
|
531 |
+
/**
|
532 |
+
* Optionally overrides all `net.Socket`s' `readableHighWaterMark` and `writableHighWaterMark`.
|
533 |
+
* @default See [stream.getDefaultHighWaterMark()](https://nodejs.org/docs/latest-v22.x/api/stream.html#streamgetdefaulthighwatermarkobjectmode).
|
534 |
+
* @since v18.17.0, v20.1.0
|
535 |
+
*/
|
536 |
+
highWaterMark?: number | undefined;
|
537 |
+
}
|
538 |
+
interface DropArgument {
|
539 |
+
localAddress?: string;
|
540 |
+
localPort?: number;
|
541 |
+
localFamily?: string;
|
542 |
+
remoteAddress?: string;
|
543 |
+
remotePort?: number;
|
544 |
+
remoteFamily?: string;
|
545 |
+
}
|
546 |
+
/**
|
547 |
+
* This class is used to create a TCP or `IPC` server.
|
548 |
+
* @since v0.1.90
|
549 |
+
*/
|
550 |
+
class Server extends EventEmitter {
|
551 |
+
constructor(connectionListener?: (socket: Socket) => void);
|
552 |
+
constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);
|
553 |
+
/**
|
554 |
+
* Start a server listening for connections. A `net.Server` can be a TCP or
|
555 |
+
* an `IPC` server depending on what it listens to.
|
556 |
+
*
|
557 |
+
* Possible signatures:
|
558 |
+
*
|
559 |
+
* * `server.listen(handle[, backlog][, callback])`
|
560 |
+
* * `server.listen(options[, callback])`
|
561 |
+
* * `server.listen(path[, backlog][, callback])` for `IPC` servers
|
562 |
+
* * `server.listen([port[, host[, backlog]]][, callback])` for TCP servers
|
563 |
+
*
|
564 |
+
* This function is asynchronous. When the server starts listening, the `'listening'` event will be emitted. The last parameter `callback`will be added as a listener for the `'listening'`
|
565 |
+
* event.
|
566 |
+
*
|
567 |
+
* All `listen()` methods can take a `backlog` parameter to specify the maximum
|
568 |
+
* length of the queue of pending connections. The actual length will be determined
|
569 |
+
* by the OS through sysctl settings such as `tcp_max_syn_backlog` and `somaxconn` on Linux. The default value of this parameter is 511 (not 512).
|
570 |
+
*
|
571 |
+
* All {@link Socket} are set to `SO_REUSEADDR` (see [`socket(7)`](https://man7.org/linux/man-pages/man7/socket.7.html) for
|
572 |
+
* details).
|
573 |
+
*
|
574 |
+
* The `server.listen()` method can be called again if and only if there was an
|
575 |
+
* error during the first `server.listen()` call or `server.close()` has been
|
576 |
+
* called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.
|
577 |
+
*
|
578 |
+
* One of the most common errors raised when listening is `EADDRINUSE`.
|
579 |
+
* This happens when another server is already listening on the requested`port`/`path`/`handle`. One way to handle this would be to retry
|
580 |
+
* after a certain amount of time:
|
581 |
+
*
|
582 |
+
* ```js
|
583 |
+
* server.on('error', (e) => {
|
584 |
+
* if (e.code === 'EADDRINUSE') {
|
585 |
+
* console.error('Address in use, retrying...');
|
586 |
+
* setTimeout(() => {
|
587 |
+
* server.close();
|
588 |
+
* server.listen(PORT, HOST);
|
589 |
+
* }, 1000);
|
590 |
+
* }
|
591 |
+
* });
|
592 |
+
* ```
|
593 |
+
*/
|
594 |
+
listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;
|
595 |
+
listen(port?: number, hostname?: string, listeningListener?: () => void): this;
|
596 |
+
listen(port?: number, backlog?: number, listeningListener?: () => void): this;
|
597 |
+
listen(port?: number, listeningListener?: () => void): this;
|
598 |
+
listen(path: string, backlog?: number, listeningListener?: () => void): this;
|
599 |
+
listen(path: string, listeningListener?: () => void): this;
|
600 |
+
listen(options: ListenOptions, listeningListener?: () => void): this;
|
601 |
+
listen(handle: any, backlog?: number, listeningListener?: () => void): this;
|
602 |
+
listen(handle: any, listeningListener?: () => void): this;
|
603 |
+
/**
|
604 |
+
* Stops the server from accepting new connections and keeps existing
|
605 |
+
* connections. This function is asynchronous, the server is finally closed
|
606 |
+
* when all connections are ended and the server emits a `'close'` event.
|
607 |
+
* The optional `callback` will be called once the `'close'` event occurs. Unlike
|
608 |
+
* that event, it will be called with an `Error` as its only argument if the server
|
609 |
+
* was not open when it was closed.
|
610 |
+
* @since v0.1.90
|
611 |
+
* @param callback Called when the server is closed.
|
612 |
+
*/
|
613 |
+
close(callback?: (err?: Error) => void): this;
|
614 |
+
/**
|
615 |
+
* Returns the bound `address`, the address `family` name, and `port` of the server
|
616 |
+
* as reported by the operating system if listening on an IP socket
|
617 |
+
* (useful to find which port was assigned when getting an OS-assigned address):`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
|
618 |
+
*
|
619 |
+
* For a server listening on a pipe or Unix domain socket, the name is returned
|
620 |
+
* as a string.
|
621 |
+
*
|
622 |
+
* ```js
|
623 |
+
* const server = net.createServer((socket) => {
|
624 |
+
* socket.end('goodbye\n');
|
625 |
+
* }).on('error', (err) => {
|
626 |
+
* // Handle errors here.
|
627 |
+
* throw err;
|
628 |
+
* });
|
629 |
+
*
|
630 |
+
* // Grab an arbitrary unused port.
|
631 |
+
* server.listen(() => {
|
632 |
+
* console.log('opened server on', server.address());
|
633 |
+
* });
|
634 |
+
* ```
|
635 |
+
*
|
636 |
+
* `server.address()` returns `null` before the `'listening'` event has been
|
637 |
+
* emitted or after calling `server.close()`.
|
638 |
+
* @since v0.1.90
|
639 |
+
*/
|
640 |
+
address(): AddressInfo | string | null;
|
641 |
+
/**
|
642 |
+
* Asynchronously get the number of concurrent connections on the server. Works
|
643 |
+
* when sockets were sent to forks.
|
644 |
+
*
|
645 |
+
* Callback should take two arguments `err` and `count`.
|
646 |
+
* @since v0.9.7
|
647 |
+
*/
|
648 |
+
getConnections(cb: (error: Error | null, count: number) => void): void;
|
649 |
+
/**
|
650 |
+
* Opposite of `unref()`, calling `ref()` on a previously `unref`ed server will _not_ let the program exit if it's the only server left (the default behavior).
|
651 |
+
* If the server is `ref`ed calling `ref()` again will have no effect.
|
652 |
+
* @since v0.9.1
|
653 |
+
*/
|
654 |
+
ref(): this;
|
655 |
+
/**
|
656 |
+
* Calling `unref()` on a server will allow the program to exit if this is the only
|
657 |
+
* active server in the event system. If the server is already `unref`ed calling`unref()` again will have no effect.
|
658 |
+
* @since v0.9.1
|
659 |
+
*/
|
660 |
+
unref(): this;
|
661 |
+
/**
|
662 |
+
* Set this property to reject connections when the server's connection count gets
|
663 |
+
* high.
|
664 |
+
*
|
665 |
+
* It is not recommended to use this option once a socket has been sent to a child
|
666 |
+
* with `child_process.fork()`.
|
667 |
+
* @since v0.2.0
|
668 |
+
*/
|
669 |
+
maxConnections: number;
|
670 |
+
connections: number;
|
671 |
+
/**
|
672 |
+
* Indicates whether or not the server is listening for connections.
|
673 |
+
* @since v5.7.0
|
674 |
+
*/
|
675 |
+
readonly listening: boolean;
|
676 |
+
/**
|
677 |
+
* events.EventEmitter
|
678 |
+
* 1. close
|
679 |
+
* 2. connection
|
680 |
+
* 3. error
|
681 |
+
* 4. listening
|
682 |
+
* 5. drop
|
683 |
+
*/
|
684 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
685 |
+
addListener(event: "close", listener: () => void): this;
|
686 |
+
addListener(event: "connection", listener: (socket: Socket) => void): this;
|
687 |
+
addListener(event: "error", listener: (err: Error) => void): this;
|
688 |
+
addListener(event: "listening", listener: () => void): this;
|
689 |
+
addListener(event: "drop", listener: (data?: DropArgument) => void): this;
|
690 |
+
emit(event: string | symbol, ...args: any[]): boolean;
|
691 |
+
emit(event: "close"): boolean;
|
692 |
+
emit(event: "connection", socket: Socket): boolean;
|
693 |
+
emit(event: "error", err: Error): boolean;
|
694 |
+
emit(event: "listening"): boolean;
|
695 |
+
emit(event: "drop", data?: DropArgument): boolean;
|
696 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
697 |
+
on(event: "close", listener: () => void): this;
|
698 |
+
on(event: "connection", listener: (socket: Socket) => void): this;
|
699 |
+
on(event: "error", listener: (err: Error) => void): this;
|
700 |
+
on(event: "listening", listener: () => void): this;
|
701 |
+
on(event: "drop", listener: (data?: DropArgument) => void): this;
|
702 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
703 |
+
once(event: "close", listener: () => void): this;
|
704 |
+
once(event: "connection", listener: (socket: Socket) => void): this;
|
705 |
+
once(event: "error", listener: (err: Error) => void): this;
|
706 |
+
once(event: "listening", listener: () => void): this;
|
707 |
+
once(event: "drop", listener: (data?: DropArgument) => void): this;
|
708 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
709 |
+
prependListener(event: "close", listener: () => void): this;
|
710 |
+
prependListener(event: "connection", listener: (socket: Socket) => void): this;
|
711 |
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
712 |
+
prependListener(event: "listening", listener: () => void): this;
|
713 |
+
prependListener(event: "drop", listener: (data?: DropArgument) => void): this;
|
714 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
715 |
+
prependOnceListener(event: "close", listener: () => void): this;
|
716 |
+
prependOnceListener(event: "connection", listener: (socket: Socket) => void): this;
|
717 |
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
718 |
+
prependOnceListener(event: "listening", listener: () => void): this;
|
719 |
+
prependOnceListener(event: "drop", listener: (data?: DropArgument) => void): this;
|
720 |
+
/**
|
721 |
+
* Calls {@link Server.close()} and returns a promise that fulfills when the server has closed.
|
722 |
+
* @since v20.5.0
|
723 |
+
*/
|
724 |
+
[Symbol.asyncDispose](): Promise<void>;
|
725 |
+
}
|
726 |
+
type IPVersion = "ipv4" | "ipv6";
|
727 |
+
/**
|
728 |
+
* The `BlockList` object can be used with some network APIs to specify rules for
|
729 |
+
* disabling inbound or outbound access to specific IP addresses, IP ranges, or
|
730 |
+
* IP subnets.
|
731 |
+
* @since v15.0.0, v14.18.0
|
732 |
+
*/
|
733 |
+
class BlockList {
|
734 |
+
/**
|
735 |
+
* Adds a rule to block the given IP address.
|
736 |
+
* @since v15.0.0, v14.18.0
|
737 |
+
* @param address An IPv4 or IPv6 address.
|
738 |
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
739 |
+
*/
|
740 |
+
addAddress(address: string, type?: IPVersion): void;
|
741 |
+
addAddress(address: SocketAddress): void;
|
742 |
+
/**
|
743 |
+
* Adds a rule to block a range of IP addresses from `start` (inclusive) to`end` (inclusive).
|
744 |
+
* @since v15.0.0, v14.18.0
|
745 |
+
* @param start The starting IPv4 or IPv6 address in the range.
|
746 |
+
* @param end The ending IPv4 or IPv6 address in the range.
|
747 |
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
748 |
+
*/
|
749 |
+
addRange(start: string, end: string, type?: IPVersion): void;
|
750 |
+
addRange(start: SocketAddress, end: SocketAddress): void;
|
751 |
+
/**
|
752 |
+
* Adds a rule to block a range of IP addresses specified as a subnet mask.
|
753 |
+
* @since v15.0.0, v14.18.0
|
754 |
+
* @param net The network IPv4 or IPv6 address.
|
755 |
+
* @param prefix The number of CIDR prefix bits. For IPv4, this must be a value between `0` and `32`. For IPv6, this must be between `0` and `128`.
|
756 |
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
757 |
+
*/
|
758 |
+
addSubnet(net: SocketAddress, prefix: number): void;
|
759 |
+
addSubnet(net: string, prefix: number, type?: IPVersion): void;
|
760 |
+
/**
|
761 |
+
* Returns `true` if the given IP address matches any of the rules added to the`BlockList`.
|
762 |
+
*
|
763 |
+
* ```js
|
764 |
+
* const blockList = new net.BlockList();
|
765 |
+
* blockList.addAddress('123.123.123.123');
|
766 |
+
* blockList.addRange('10.0.0.1', '10.0.0.10');
|
767 |
+
* blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
|
768 |
+
*
|
769 |
+
* console.log(blockList.check('123.123.123.123')); // Prints: true
|
770 |
+
* console.log(blockList.check('10.0.0.3')); // Prints: true
|
771 |
+
* console.log(blockList.check('222.111.111.222')); // Prints: false
|
772 |
+
*
|
773 |
+
* // IPv6 notation for IPv4 addresses works:
|
774 |
+
* console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true
|
775 |
+
* console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true
|
776 |
+
* ```
|
777 |
+
* @since v15.0.0, v14.18.0
|
778 |
+
* @param address The IP address to check
|
779 |
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
780 |
+
*/
|
781 |
+
check(address: SocketAddress): boolean;
|
782 |
+
check(address: string, type?: IPVersion): boolean;
|
783 |
+
/**
|
784 |
+
* The list of rules added to the blocklist.
|
785 |
+
* @since v15.0.0, v14.18.0
|
786 |
+
*/
|
787 |
+
rules: readonly string[];
|
788 |
+
}
|
789 |
+
interface TcpNetConnectOpts extends TcpSocketConnectOpts, SocketConstructorOpts {
|
790 |
+
timeout?: number | undefined;
|
791 |
+
}
|
792 |
+
interface IpcNetConnectOpts extends IpcSocketConnectOpts, SocketConstructorOpts {
|
793 |
+
timeout?: number | undefined;
|
794 |
+
}
|
795 |
+
type NetConnectOpts = TcpNetConnectOpts | IpcNetConnectOpts;
|
796 |
+
/**
|
797 |
+
* Creates a new TCP or `IPC` server.
|
798 |
+
*
|
799 |
+
* If `allowHalfOpen` is set to `true`, when the other end of the socket
|
800 |
+
* signals the end of transmission, the server will only send back the end of
|
801 |
+
* transmission when `socket.end()` is explicitly called. For example, in the
|
802 |
+
* context of TCP, when a FIN packed is received, a FIN packed is sent
|
803 |
+
* back only when `socket.end()` is explicitly called. Until then the
|
804 |
+
* connection is half-closed (non-readable but still writable). See `'end'` event and [RFC 1122](https://tools.ietf.org/html/rfc1122) (section 4.2.2.13) for more information.
|
805 |
+
*
|
806 |
+
* If `pauseOnConnect` is set to `true`, then the socket associated with each
|
807 |
+
* incoming connection will be paused, and no data will be read from its handle.
|
808 |
+
* This allows connections to be passed between processes without any data being
|
809 |
+
* read by the original process. To begin reading data from a paused socket, call `socket.resume()`.
|
810 |
+
*
|
811 |
+
* The server can be a TCP server or an `IPC` server, depending on what it `listen()` to.
|
812 |
+
*
|
813 |
+
* Here is an example of a TCP echo server which listens for connections
|
814 |
+
* on port 8124:
|
815 |
+
*
|
816 |
+
* ```js
|
817 |
+
* import net from 'node:net';
|
818 |
+
* const server = net.createServer((c) => {
|
819 |
+
* // 'connection' listener.
|
820 |
+
* console.log('client connected');
|
821 |
+
* c.on('end', () => {
|
822 |
+
* console.log('client disconnected');
|
823 |
+
* });
|
824 |
+
* c.write('hello\r\n');
|
825 |
+
* c.pipe(c);
|
826 |
+
* });
|
827 |
+
* server.on('error', (err) => {
|
828 |
+
* throw err;
|
829 |
+
* });
|
830 |
+
* server.listen(8124, () => {
|
831 |
+
* console.log('server bound');
|
832 |
+
* });
|
833 |
+
* ```
|
834 |
+
*
|
835 |
+
* Test this by using `telnet`:
|
836 |
+
*
|
837 |
+
* ```bash
|
838 |
+
* telnet localhost 8124
|
839 |
+
* ```
|
840 |
+
*
|
841 |
+
* To listen on the socket `/tmp/echo.sock`:
|
842 |
+
*
|
843 |
+
* ```js
|
844 |
+
* server.listen('/tmp/echo.sock', () => {
|
845 |
+
* console.log('server bound');
|
846 |
+
* });
|
847 |
+
* ```
|
848 |
+
*
|
849 |
+
* Use `nc` to connect to a Unix domain socket server:
|
850 |
+
*
|
851 |
+
* ```bash
|
852 |
+
* nc -U /tmp/echo.sock
|
853 |
+
* ```
|
854 |
+
* @since v0.5.0
|
855 |
+
* @param connectionListener Automatically set as a listener for the {@link 'connection'} event.
|
856 |
+
*/
|
857 |
+
function createServer(connectionListener?: (socket: Socket) => void): Server;
|
858 |
+
function createServer(options?: ServerOpts, connectionListener?: (socket: Socket) => void): Server;
|
859 |
+
/**
|
860 |
+
* Aliases to {@link createConnection}.
|
861 |
+
*
|
862 |
+
* Possible signatures:
|
863 |
+
*
|
864 |
+
* * {@link connect}
|
865 |
+
* * {@link connect} for `IPC` connections.
|
866 |
+
* * {@link connect} for TCP connections.
|
867 |
+
*/
|
868 |
+
function connect(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
869 |
+
function connect(port: number, host?: string, connectionListener?: () => void): Socket;
|
870 |
+
function connect(path: string, connectionListener?: () => void): Socket;
|
871 |
+
/**
|
872 |
+
* A factory function, which creates a new {@link Socket},
|
873 |
+
* immediately initiates connection with `socket.connect()`,
|
874 |
+
* then returns the `net.Socket` that starts the connection.
|
875 |
+
*
|
876 |
+
* When the connection is established, a `'connect'` event will be emitted
|
877 |
+
* on the returned socket. The last parameter `connectListener`, if supplied,
|
878 |
+
* will be added as a listener for the `'connect'` event **once**.
|
879 |
+
*
|
880 |
+
* Possible signatures:
|
881 |
+
*
|
882 |
+
* * {@link createConnection}
|
883 |
+
* * {@link createConnection} for `IPC` connections.
|
884 |
+
* * {@link createConnection} for TCP connections.
|
885 |
+
*
|
886 |
+
* The {@link connect} function is an alias to this function.
|
887 |
+
*/
|
888 |
+
function createConnection(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
889 |
+
function createConnection(port: number, host?: string, connectionListener?: () => void): Socket;
|
890 |
+
function createConnection(path: string, connectionListener?: () => void): Socket;
|
891 |
+
/**
|
892 |
+
* Gets the current default value of the `autoSelectFamily` option of `socket.connect(options)`.
|
893 |
+
* The initial default value is `true`, unless the command line option`--no-network-family-autoselection` is provided.
|
894 |
+
* @since v19.4.0
|
895 |
+
*/
|
896 |
+
function getDefaultAutoSelectFamily(): boolean;
|
897 |
+
/**
|
898 |
+
* Sets the default value of the `autoSelectFamily` option of `socket.connect(options)`.
|
899 |
+
* @param value The new default value.
|
900 |
+
* The initial default value is `true`, unless the command line option
|
901 |
+
* `--no-network-family-autoselection` is provided.
|
902 |
+
* @since v19.4.0
|
903 |
+
*/
|
904 |
+
function setDefaultAutoSelectFamily(value: boolean): void;
|
905 |
+
/**
|
906 |
+
* Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`.
|
907 |
+
* The initial default value is `250` or the value specified via the command line option `--network-family-autoselection-attempt-timeout`.
|
908 |
+
* @returns The current default value of the `autoSelectFamilyAttemptTimeout` option.
|
909 |
+
* @since v19.8.0, v18.8.0
|
910 |
+
*/
|
911 |
+
function getDefaultAutoSelectFamilyAttemptTimeout(): number;
|
912 |
+
/**
|
913 |
+
* Sets the default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`.
|
914 |
+
* @param value The new default value, which must be a positive number. If the number is less than `10`, the value `10` is used instead. The initial default value is `250` or the value specified via the command line
|
915 |
+
* option `--network-family-autoselection-attempt-timeout`.
|
916 |
+
* @since v19.8.0, v18.8.0
|
917 |
+
*/
|
918 |
+
function setDefaultAutoSelectFamilyAttemptTimeout(value: number): void;
|
919 |
+
/**
|
920 |
+
* Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4
|
921 |
+
* address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no leading zeroes. Otherwise, returns`0`.
|
922 |
+
*
|
923 |
+
* ```js
|
924 |
+
* net.isIP('::1'); // returns 6
|
925 |
+
* net.isIP('127.0.0.1'); // returns 4
|
926 |
+
* net.isIP('127.000.000.001'); // returns 0
|
927 |
+
* net.isIP('127.0.0.1/24'); // returns 0
|
928 |
+
* net.isIP('fhqwhgads'); // returns 0
|
929 |
+
* ```
|
930 |
+
* @since v0.3.0
|
931 |
+
*/
|
932 |
+
function isIP(input: string): number;
|
933 |
+
/**
|
934 |
+
* Returns `true` if `input` is an IPv4 address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no
|
935 |
+
* leading zeroes. Otherwise, returns `false`.
|
936 |
+
*
|
937 |
+
* ```js
|
938 |
+
* net.isIPv4('127.0.0.1'); // returns true
|
939 |
+
* net.isIPv4('127.000.000.001'); // returns false
|
940 |
+
* net.isIPv4('127.0.0.1/24'); // returns false
|
941 |
+
* net.isIPv4('fhqwhgads'); // returns false
|
942 |
+
* ```
|
943 |
+
* @since v0.3.0
|
944 |
+
*/
|
945 |
+
function isIPv4(input: string): boolean;
|
946 |
+
/**
|
947 |
+
* Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`.
|
948 |
+
*
|
949 |
+
* ```js
|
950 |
+
* net.isIPv6('::1'); // returns true
|
951 |
+
* net.isIPv6('fhqwhgads'); // returns false
|
952 |
+
* ```
|
953 |
+
* @since v0.3.0
|
954 |
+
*/
|
955 |
+
function isIPv6(input: string): boolean;
|
956 |
+
interface SocketAddressInitOptions {
|
957 |
+
/**
|
958 |
+
* The network address as either an IPv4 or IPv6 string.
|
959 |
+
* @default 127.0.0.1
|
960 |
+
*/
|
961 |
+
address?: string | undefined;
|
962 |
+
/**
|
963 |
+
* @default `'ipv4'`
|
964 |
+
*/
|
965 |
+
family?: IPVersion | undefined;
|
966 |
+
/**
|
967 |
+
* An IPv6 flow-label used only if `family` is `'ipv6'`.
|
968 |
+
* @default 0
|
969 |
+
*/
|
970 |
+
flowlabel?: number | undefined;
|
971 |
+
/**
|
972 |
+
* An IP port.
|
973 |
+
* @default 0
|
974 |
+
*/
|
975 |
+
port?: number | undefined;
|
976 |
+
}
|
977 |
+
/**
|
978 |
+
* @since v15.14.0, v14.18.0
|
979 |
+
*/
|
980 |
+
class SocketAddress {
|
981 |
+
constructor(options: SocketAddressInitOptions);
|
982 |
+
/**
|
983 |
+
* Either \`'ipv4'\` or \`'ipv6'\`.
|
984 |
+
* @since v15.14.0, v14.18.0
|
985 |
+
*/
|
986 |
+
readonly address: string;
|
987 |
+
/**
|
988 |
+
* Either \`'ipv4'\` or \`'ipv6'\`.
|
989 |
+
* @since v15.14.0, v14.18.0
|
990 |
+
*/
|
991 |
+
readonly family: IPVersion;
|
992 |
+
/**
|
993 |
+
* @since v15.14.0, v14.18.0
|
994 |
+
*/
|
995 |
+
readonly port: number;
|
996 |
+
/**
|
997 |
+
* @since v15.14.0, v14.18.0
|
998 |
+
*/
|
999 |
+
readonly flowlabel: number;
|
1000 |
+
}
|
1001 |
+
}
|
1002 |
+
declare module "node:net" {
|
1003 |
+
export * from "net";
|
1004 |
+
}
|
clone/node_modules/@types/node/os.d.ts
ADDED
@@ -0,0 +1,495 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* The `node:os` module provides operating system-related utility methods and
|
3 |
+
* properties. It can be accessed using:
|
4 |
+
*
|
5 |
+
* ```js
|
6 |
+
* import os from 'node:os';
|
7 |
+
* ```
|
8 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/os.js)
|
9 |
+
*/
|
10 |
+
declare module "os" {
|
11 |
+
interface CpuInfo {
|
12 |
+
model: string;
|
13 |
+
speed: number;
|
14 |
+
times: {
|
15 |
+
/** The number of milliseconds the CPU has spent in user mode. */
|
16 |
+
user: number;
|
17 |
+
/** The number of milliseconds the CPU has spent in nice mode. */
|
18 |
+
nice: number;
|
19 |
+
/** The number of milliseconds the CPU has spent in sys mode. */
|
20 |
+
sys: number;
|
21 |
+
/** The number of milliseconds the CPU has spent in idle mode. */
|
22 |
+
idle: number;
|
23 |
+
/** The number of milliseconds the CPU has spent in irq mode. */
|
24 |
+
irq: number;
|
25 |
+
};
|
26 |
+
}
|
27 |
+
interface NetworkInterfaceBase {
|
28 |
+
address: string;
|
29 |
+
netmask: string;
|
30 |
+
mac: string;
|
31 |
+
internal: boolean;
|
32 |
+
cidr: string | null;
|
33 |
+
}
|
34 |
+
interface NetworkInterfaceInfoIPv4 extends NetworkInterfaceBase {
|
35 |
+
family: "IPv4";
|
36 |
+
scopeid?: undefined;
|
37 |
+
}
|
38 |
+
interface NetworkInterfaceInfoIPv6 extends NetworkInterfaceBase {
|
39 |
+
family: "IPv6";
|
40 |
+
scopeid: number;
|
41 |
+
}
|
42 |
+
interface UserInfo<T> {
|
43 |
+
username: T;
|
44 |
+
uid: number;
|
45 |
+
gid: number;
|
46 |
+
shell: T | null;
|
47 |
+
homedir: T;
|
48 |
+
}
|
49 |
+
type NetworkInterfaceInfo = NetworkInterfaceInfoIPv4 | NetworkInterfaceInfoIPv6;
|
50 |
+
/**
|
51 |
+
* Returns the host name of the operating system as a string.
|
52 |
+
* @since v0.3.3
|
53 |
+
*/
|
54 |
+
function hostname(): string;
|
55 |
+
/**
|
56 |
+
* Returns an array containing the 1, 5, and 15 minute load averages.
|
57 |
+
*
|
58 |
+
* The load average is a measure of system activity calculated by the operating
|
59 |
+
* system and expressed as a fractional number.
|
60 |
+
*
|
61 |
+
* The load average is a Unix-specific concept. On Windows, the return value is
|
62 |
+
* always `[0, 0, 0]`.
|
63 |
+
* @since v0.3.3
|
64 |
+
*/
|
65 |
+
function loadavg(): number[];
|
66 |
+
/**
|
67 |
+
* Returns the system uptime in number of seconds.
|
68 |
+
* @since v0.3.3
|
69 |
+
*/
|
70 |
+
function uptime(): number;
|
71 |
+
/**
|
72 |
+
* Returns the amount of free system memory in bytes as an integer.
|
73 |
+
* @since v0.3.3
|
74 |
+
*/
|
75 |
+
function freemem(): number;
|
76 |
+
/**
|
77 |
+
* Returns the total amount of system memory in bytes as an integer.
|
78 |
+
* @since v0.3.3
|
79 |
+
*/
|
80 |
+
function totalmem(): number;
|
81 |
+
/**
|
82 |
+
* Returns an array of objects containing information about each logical CPU core.
|
83 |
+
* The array will be empty if no CPU information is available, such as if the `/proc` file system is unavailable.
|
84 |
+
*
|
85 |
+
* The properties included on each object include:
|
86 |
+
*
|
87 |
+
* ```js
|
88 |
+
* [
|
89 |
+
* {
|
90 |
+
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
91 |
+
* speed: 2926,
|
92 |
+
* times: {
|
93 |
+
* user: 252020,
|
94 |
+
* nice: 0,
|
95 |
+
* sys: 30340,
|
96 |
+
* idle: 1070356870,
|
97 |
+
* irq: 0,
|
98 |
+
* },
|
99 |
+
* },
|
100 |
+
* {
|
101 |
+
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
102 |
+
* speed: 2926,
|
103 |
+
* times: {
|
104 |
+
* user: 306960,
|
105 |
+
* nice: 0,
|
106 |
+
* sys: 26980,
|
107 |
+
* idle: 1071569080,
|
108 |
+
* irq: 0,
|
109 |
+
* },
|
110 |
+
* },
|
111 |
+
* {
|
112 |
+
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
113 |
+
* speed: 2926,
|
114 |
+
* times: {
|
115 |
+
* user: 248450,
|
116 |
+
* nice: 0,
|
117 |
+
* sys: 21750,
|
118 |
+
* idle: 1070919370,
|
119 |
+
* irq: 0,
|
120 |
+
* },
|
121 |
+
* },
|
122 |
+
* {
|
123 |
+
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
124 |
+
* speed: 2926,
|
125 |
+
* times: {
|
126 |
+
* user: 256880,
|
127 |
+
* nice: 0,
|
128 |
+
* sys: 19430,
|
129 |
+
* idle: 1070905480,
|
130 |
+
* irq: 20,
|
131 |
+
* },
|
132 |
+
* },
|
133 |
+
* ]
|
134 |
+
* ```
|
135 |
+
*
|
136 |
+
* `nice` values are POSIX-only. On Windows, the `nice` values of all processors
|
137 |
+
* are always 0.
|
138 |
+
*
|
139 |
+
* `os.cpus().length` should not be used to calculate the amount of parallelism
|
140 |
+
* available to an application. Use {@link availableParallelism} for this purpose.
|
141 |
+
* @since v0.3.3
|
142 |
+
*/
|
143 |
+
function cpus(): CpuInfo[];
|
144 |
+
/**
|
145 |
+
* Returns an estimate of the default amount of parallelism a program should use.
|
146 |
+
* Always returns a value greater than zero.
|
147 |
+
*
|
148 |
+
* This function is a small wrapper about libuv's [`uv_available_parallelism()`](https://docs.libuv.org/en/v1.x/misc.html#c.uv_available_parallelism).
|
149 |
+
* @since v19.4.0, v18.14.0
|
150 |
+
*/
|
151 |
+
function availableParallelism(): number;
|
152 |
+
/**
|
153 |
+
* Returns the operating system name as returned by [`uname(3)`](https://linux.die.net/man/3/uname). For example, it
|
154 |
+
* returns `'Linux'` on Linux, `'Darwin'` on macOS, and `'Windows_NT'` on Windows.
|
155 |
+
*
|
156 |
+
* See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for additional information
|
157 |
+
* about the output of running [`uname(3)`](https://linux.die.net/man/3/uname) on various operating systems.
|
158 |
+
* @since v0.3.3
|
159 |
+
*/
|
160 |
+
function type(): string;
|
161 |
+
/**
|
162 |
+
* Returns the operating system as a string.
|
163 |
+
*
|
164 |
+
* On POSIX systems, the operating system release is determined by calling [`uname(3)`](https://linux.die.net/man/3/uname). On Windows, `GetVersionExW()` is used. See
|
165 |
+
* [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
166 |
+
* @since v0.3.3
|
167 |
+
*/
|
168 |
+
function release(): string;
|
169 |
+
/**
|
170 |
+
* Returns an object containing network interfaces that have been assigned a
|
171 |
+
* network address.
|
172 |
+
*
|
173 |
+
* Each key on the returned object identifies a network interface. The associated
|
174 |
+
* value is an array of objects that each describe an assigned network address.
|
175 |
+
*
|
176 |
+
* The properties available on the assigned network address object include:
|
177 |
+
*
|
178 |
+
* ```js
|
179 |
+
* {
|
180 |
+
* lo: [
|
181 |
+
* {
|
182 |
+
* address: '127.0.0.1',
|
183 |
+
* netmask: '255.0.0.0',
|
184 |
+
* family: 'IPv4',
|
185 |
+
* mac: '00:00:00:00:00:00',
|
186 |
+
* internal: true,
|
187 |
+
* cidr: '127.0.0.1/8'
|
188 |
+
* },
|
189 |
+
* {
|
190 |
+
* address: '::1',
|
191 |
+
* netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
|
192 |
+
* family: 'IPv6',
|
193 |
+
* mac: '00:00:00:00:00:00',
|
194 |
+
* scopeid: 0,
|
195 |
+
* internal: true,
|
196 |
+
* cidr: '::1/128'
|
197 |
+
* }
|
198 |
+
* ],
|
199 |
+
* eth0: [
|
200 |
+
* {
|
201 |
+
* address: '192.168.1.108',
|
202 |
+
* netmask: '255.255.255.0',
|
203 |
+
* family: 'IPv4',
|
204 |
+
* mac: '01:02:03:0a:0b:0c',
|
205 |
+
* internal: false,
|
206 |
+
* cidr: '192.168.1.108/24'
|
207 |
+
* },
|
208 |
+
* {
|
209 |
+
* address: 'fe80::a00:27ff:fe4e:66a1',
|
210 |
+
* netmask: 'ffff:ffff:ffff:ffff::',
|
211 |
+
* family: 'IPv6',
|
212 |
+
* mac: '01:02:03:0a:0b:0c',
|
213 |
+
* scopeid: 1,
|
214 |
+
* internal: false,
|
215 |
+
* cidr: 'fe80::a00:27ff:fe4e:66a1/64'
|
216 |
+
* }
|
217 |
+
* ]
|
218 |
+
* }
|
219 |
+
* ```
|
220 |
+
* @since v0.6.0
|
221 |
+
*/
|
222 |
+
function networkInterfaces(): NodeJS.Dict<NetworkInterfaceInfo[]>;
|
223 |
+
/**
|
224 |
+
* Returns the string path of the current user's home directory.
|
225 |
+
*
|
226 |
+
* On POSIX, it uses the `$HOME` environment variable if defined. Otherwise it
|
227 |
+
* uses the [effective UID](https://en.wikipedia.org/wiki/User_identifier#Effective_user_ID) to look up the user's home directory.
|
228 |
+
*
|
229 |
+
* On Windows, it uses the `USERPROFILE` environment variable if defined.
|
230 |
+
* Otherwise it uses the path to the profile directory of the current user.
|
231 |
+
* @since v2.3.0
|
232 |
+
*/
|
233 |
+
function homedir(): string;
|
234 |
+
/**
|
235 |
+
* Returns information about the currently effective user. On POSIX platforms,
|
236 |
+
* this is typically a subset of the password file. The returned object includes
|
237 |
+
* the `username`, `uid`, `gid`, `shell`, and `homedir`. On Windows, the `uid` and `gid` fields are `-1`, and `shell` is `null`.
|
238 |
+
*
|
239 |
+
* The value of `homedir` returned by `os.userInfo()` is provided by the operating
|
240 |
+
* system. This differs from the result of `os.homedir()`, which queries
|
241 |
+
* environment variables for the home directory before falling back to the
|
242 |
+
* operating system response.
|
243 |
+
*
|
244 |
+
* Throws a [`SystemError`](https://nodejs.org/docs/latest-v22.x/api/errors.html#class-systemerror) if a user has no `username` or `homedir`.
|
245 |
+
* @since v6.0.0
|
246 |
+
*/
|
247 |
+
function userInfo(options: { encoding: "buffer" }): UserInfo<Buffer>;
|
248 |
+
function userInfo(options?: { encoding: BufferEncoding }): UserInfo<string>;
|
249 |
+
type SignalConstants = {
|
250 |
+
[key in NodeJS.Signals]: number;
|
251 |
+
};
|
252 |
+
namespace constants {
|
253 |
+
const UV_UDP_REUSEADDR: number;
|
254 |
+
namespace signals {}
|
255 |
+
const signals: SignalConstants;
|
256 |
+
namespace errno {
|
257 |
+
const E2BIG: number;
|
258 |
+
const EACCES: number;
|
259 |
+
const EADDRINUSE: number;
|
260 |
+
const EADDRNOTAVAIL: number;
|
261 |
+
const EAFNOSUPPORT: number;
|
262 |
+
const EAGAIN: number;
|
263 |
+
const EALREADY: number;
|
264 |
+
const EBADF: number;
|
265 |
+
const EBADMSG: number;
|
266 |
+
const EBUSY: number;
|
267 |
+
const ECANCELED: number;
|
268 |
+
const ECHILD: number;
|
269 |
+
const ECONNABORTED: number;
|
270 |
+
const ECONNREFUSED: number;
|
271 |
+
const ECONNRESET: number;
|
272 |
+
const EDEADLK: number;
|
273 |
+
const EDESTADDRREQ: number;
|
274 |
+
const EDOM: number;
|
275 |
+
const EDQUOT: number;
|
276 |
+
const EEXIST: number;
|
277 |
+
const EFAULT: number;
|
278 |
+
const EFBIG: number;
|
279 |
+
const EHOSTUNREACH: number;
|
280 |
+
const EIDRM: number;
|
281 |
+
const EILSEQ: number;
|
282 |
+
const EINPROGRESS: number;
|
283 |
+
const EINTR: number;
|
284 |
+
const EINVAL: number;
|
285 |
+
const EIO: number;
|
286 |
+
const EISCONN: number;
|
287 |
+
const EISDIR: number;
|
288 |
+
const ELOOP: number;
|
289 |
+
const EMFILE: number;
|
290 |
+
const EMLINK: number;
|
291 |
+
const EMSGSIZE: number;
|
292 |
+
const EMULTIHOP: number;
|
293 |
+
const ENAMETOOLONG: number;
|
294 |
+
const ENETDOWN: number;
|
295 |
+
const ENETRESET: number;
|
296 |
+
const ENETUNREACH: number;
|
297 |
+
const ENFILE: number;
|
298 |
+
const ENOBUFS: number;
|
299 |
+
const ENODATA: number;
|
300 |
+
const ENODEV: number;
|
301 |
+
const ENOENT: number;
|
302 |
+
const ENOEXEC: number;
|
303 |
+
const ENOLCK: number;
|
304 |
+
const ENOLINK: number;
|
305 |
+
const ENOMEM: number;
|
306 |
+
const ENOMSG: number;
|
307 |
+
const ENOPROTOOPT: number;
|
308 |
+
const ENOSPC: number;
|
309 |
+
const ENOSR: number;
|
310 |
+
const ENOSTR: number;
|
311 |
+
const ENOSYS: number;
|
312 |
+
const ENOTCONN: number;
|
313 |
+
const ENOTDIR: number;
|
314 |
+
const ENOTEMPTY: number;
|
315 |
+
const ENOTSOCK: number;
|
316 |
+
const ENOTSUP: number;
|
317 |
+
const ENOTTY: number;
|
318 |
+
const ENXIO: number;
|
319 |
+
const EOPNOTSUPP: number;
|
320 |
+
const EOVERFLOW: number;
|
321 |
+
const EPERM: number;
|
322 |
+
const EPIPE: number;
|
323 |
+
const EPROTO: number;
|
324 |
+
const EPROTONOSUPPORT: number;
|
325 |
+
const EPROTOTYPE: number;
|
326 |
+
const ERANGE: number;
|
327 |
+
const EROFS: number;
|
328 |
+
const ESPIPE: number;
|
329 |
+
const ESRCH: number;
|
330 |
+
const ESTALE: number;
|
331 |
+
const ETIME: number;
|
332 |
+
const ETIMEDOUT: number;
|
333 |
+
const ETXTBSY: number;
|
334 |
+
const EWOULDBLOCK: number;
|
335 |
+
const EXDEV: number;
|
336 |
+
const WSAEINTR: number;
|
337 |
+
const WSAEBADF: number;
|
338 |
+
const WSAEACCES: number;
|
339 |
+
const WSAEFAULT: number;
|
340 |
+
const WSAEINVAL: number;
|
341 |
+
const WSAEMFILE: number;
|
342 |
+
const WSAEWOULDBLOCK: number;
|
343 |
+
const WSAEINPROGRESS: number;
|
344 |
+
const WSAEALREADY: number;
|
345 |
+
const WSAENOTSOCK: number;
|
346 |
+
const WSAEDESTADDRREQ: number;
|
347 |
+
const WSAEMSGSIZE: number;
|
348 |
+
const WSAEPROTOTYPE: number;
|
349 |
+
const WSAENOPROTOOPT: number;
|
350 |
+
const WSAEPROTONOSUPPORT: number;
|
351 |
+
const WSAESOCKTNOSUPPORT: number;
|
352 |
+
const WSAEOPNOTSUPP: number;
|
353 |
+
const WSAEPFNOSUPPORT: number;
|
354 |
+
const WSAEAFNOSUPPORT: number;
|
355 |
+
const WSAEADDRINUSE: number;
|
356 |
+
const WSAEADDRNOTAVAIL: number;
|
357 |
+
const WSAENETDOWN: number;
|
358 |
+
const WSAENETUNREACH: number;
|
359 |
+
const WSAENETRESET: number;
|
360 |
+
const WSAECONNABORTED: number;
|
361 |
+
const WSAECONNRESET: number;
|
362 |
+
const WSAENOBUFS: number;
|
363 |
+
const WSAEISCONN: number;
|
364 |
+
const WSAENOTCONN: number;
|
365 |
+
const WSAESHUTDOWN: number;
|
366 |
+
const WSAETOOMANYREFS: number;
|
367 |
+
const WSAETIMEDOUT: number;
|
368 |
+
const WSAECONNREFUSED: number;
|
369 |
+
const WSAELOOP: number;
|
370 |
+
const WSAENAMETOOLONG: number;
|
371 |
+
const WSAEHOSTDOWN: number;
|
372 |
+
const WSAEHOSTUNREACH: number;
|
373 |
+
const WSAENOTEMPTY: number;
|
374 |
+
const WSAEPROCLIM: number;
|
375 |
+
const WSAEUSERS: number;
|
376 |
+
const WSAEDQUOT: number;
|
377 |
+
const WSAESTALE: number;
|
378 |
+
const WSAEREMOTE: number;
|
379 |
+
const WSASYSNOTREADY: number;
|
380 |
+
const WSAVERNOTSUPPORTED: number;
|
381 |
+
const WSANOTINITIALISED: number;
|
382 |
+
const WSAEDISCON: number;
|
383 |
+
const WSAENOMORE: number;
|
384 |
+
const WSAECANCELLED: number;
|
385 |
+
const WSAEINVALIDPROCTABLE: number;
|
386 |
+
const WSAEINVALIDPROVIDER: number;
|
387 |
+
const WSAEPROVIDERFAILEDINIT: number;
|
388 |
+
const WSASYSCALLFAILURE: number;
|
389 |
+
const WSASERVICE_NOT_FOUND: number;
|
390 |
+
const WSATYPE_NOT_FOUND: number;
|
391 |
+
const WSA_E_NO_MORE: number;
|
392 |
+
const WSA_E_CANCELLED: number;
|
393 |
+
const WSAEREFUSED: number;
|
394 |
+
}
|
395 |
+
namespace dlopen {
|
396 |
+
const RTLD_LAZY: number;
|
397 |
+
const RTLD_NOW: number;
|
398 |
+
const RTLD_GLOBAL: number;
|
399 |
+
const RTLD_LOCAL: number;
|
400 |
+
const RTLD_DEEPBIND: number;
|
401 |
+
}
|
402 |
+
namespace priority {
|
403 |
+
const PRIORITY_LOW: number;
|
404 |
+
const PRIORITY_BELOW_NORMAL: number;
|
405 |
+
const PRIORITY_NORMAL: number;
|
406 |
+
const PRIORITY_ABOVE_NORMAL: number;
|
407 |
+
const PRIORITY_HIGH: number;
|
408 |
+
const PRIORITY_HIGHEST: number;
|
409 |
+
}
|
410 |
+
}
|
411 |
+
const devNull: string;
|
412 |
+
/**
|
413 |
+
* The operating system-specific end-of-line marker.
|
414 |
+
* * `\n` on POSIX
|
415 |
+
* * `\r\n` on Windows
|
416 |
+
*/
|
417 |
+
const EOL: string;
|
418 |
+
/**
|
419 |
+
* Returns the operating system CPU architecture for which the Node.js binary was
|
420 |
+
* compiled. Possible values are `'arm'`, `'arm64'`, `'ia32'`, `'loong64'`, `'mips'`, `'mipsel'`, `'ppc'`, `'ppc64'`, `'riscv64'`, `'s390'`, `'s390x'`,
|
421 |
+
* and `'x64'`.
|
422 |
+
*
|
423 |
+
* The return value is equivalent to [process.arch](https://nodejs.org/docs/latest-v22.x/api/process.html#processarch).
|
424 |
+
* @since v0.5.0
|
425 |
+
*/
|
426 |
+
function arch(): string;
|
427 |
+
/**
|
428 |
+
* Returns a string identifying the kernel version.
|
429 |
+
*
|
430 |
+
* On POSIX systems, the operating system release is determined by calling [`uname(3)`](https://linux.die.net/man/3/uname). On Windows, `RtlGetVersion()` is used, and if it is not
|
431 |
+
* available, `GetVersionExW()` will be used. See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
432 |
+
* @since v13.11.0, v12.17.0
|
433 |
+
*/
|
434 |
+
function version(): string;
|
435 |
+
/**
|
436 |
+
* Returns a string identifying the operating system platform for which
|
437 |
+
* the Node.js binary was compiled. The value is set at compile time.
|
438 |
+
* Possible values are `'aix'`, `'darwin'`, `'freebsd'`, `'linux'`, `'openbsd'`, `'sunos'`, and `'win32'`.
|
439 |
+
*
|
440 |
+
* The return value is equivalent to `process.platform`.
|
441 |
+
*
|
442 |
+
* The value `'android'` may also be returned if Node.js is built on the Android
|
443 |
+
* operating system. [Android support is experimental](https://github.com/nodejs/node/blob/HEAD/BUILDING.md#androidandroid-based-devices-eg-firefox-os).
|
444 |
+
* @since v0.5.0
|
445 |
+
*/
|
446 |
+
function platform(): NodeJS.Platform;
|
447 |
+
/**
|
448 |
+
* Returns the machine type as a string, such as `arm`, `arm64`, `aarch64`, `mips`, `mips64`, `ppc64`, `ppc64le`, `s390`, `s390x`, `i386`, `i686`, `x86_64`.
|
449 |
+
*
|
450 |
+
* On POSIX systems, the machine type is determined by calling [`uname(3)`](https://linux.die.net/man/3/uname). On Windows, `RtlGetVersion()` is used, and if it is not
|
451 |
+
* available, `GetVersionExW()` will be used. See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
452 |
+
* @since v18.9.0, v16.18.0
|
453 |
+
*/
|
454 |
+
function machine(): string;
|
455 |
+
/**
|
456 |
+
* Returns the operating system's default directory for temporary files as a
|
457 |
+
* string.
|
458 |
+
* @since v0.9.9
|
459 |
+
*/
|
460 |
+
function tmpdir(): string;
|
461 |
+
/**
|
462 |
+
* Returns a string identifying the endianness of the CPU for which the Node.js
|
463 |
+
* binary was compiled.
|
464 |
+
*
|
465 |
+
* Possible values are `'BE'` for big endian and `'LE'` for little endian.
|
466 |
+
* @since v0.9.4
|
467 |
+
*/
|
468 |
+
function endianness(): "BE" | "LE";
|
469 |
+
/**
|
470 |
+
* Returns the scheduling priority for the process specified by `pid`. If `pid` is
|
471 |
+
* not provided or is `0`, the priority of the current process is returned.
|
472 |
+
* @since v10.10.0
|
473 |
+
* @param [pid=0] The process ID to retrieve scheduling priority for.
|
474 |
+
*/
|
475 |
+
function getPriority(pid?: number): number;
|
476 |
+
/**
|
477 |
+
* Attempts to set the scheduling priority for the process specified by `pid`. If `pid` is not provided or is `0`, the process ID of the current process is used.
|
478 |
+
*
|
479 |
+
* The `priority` input must be an integer between `-20` (high priority) and `19` (low priority). Due to differences between Unix priority levels and Windows
|
480 |
+
* priority classes, `priority` is mapped to one of six priority constants in `os.constants.priority`. When retrieving a process priority level, this range
|
481 |
+
* mapping may cause the return value to be slightly different on Windows. To avoid
|
482 |
+
* confusion, set `priority` to one of the priority constants.
|
483 |
+
*
|
484 |
+
* On Windows, setting priority to `PRIORITY_HIGHEST` requires elevated user
|
485 |
+
* privileges. Otherwise the set priority will be silently reduced to `PRIORITY_HIGH`.
|
486 |
+
* @since v10.10.0
|
487 |
+
* @param [pid=0] The process ID to set scheduling priority for.
|
488 |
+
* @param priority The scheduling priority to assign to the process.
|
489 |
+
*/
|
490 |
+
function setPriority(priority: number): void;
|
491 |
+
function setPriority(pid: number, priority: number): void;
|
492 |
+
}
|
493 |
+
declare module "node:os" {
|
494 |
+
export * from "os";
|
495 |
+
}
|
clone/node_modules/@types/node/package.json
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@types/node",
|
3 |
+
"version": "22.10.10",
|
4 |
+
"description": "TypeScript definitions for node",
|
5 |
+
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node",
|
6 |
+
"license": "MIT",
|
7 |
+
"contributors": [
|
8 |
+
{
|
9 |
+
"name": "Microsoft TypeScript",
|
10 |
+
"githubUsername": "Microsoft",
|
11 |
+
"url": "https://github.com/Microsoft"
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"name": "Alberto Schiabel",
|
15 |
+
"githubUsername": "jkomyno",
|
16 |
+
"url": "https://github.com/jkomyno"
|
17 |
+
},
|
18 |
+
{
|
19 |
+
"name": "Alvis HT Tang",
|
20 |
+
"githubUsername": "alvis",
|
21 |
+
"url": "https://github.com/alvis"
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"name": "Andrew Makarov",
|
25 |
+
"githubUsername": "r3nya",
|
26 |
+
"url": "https://github.com/r3nya"
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"name": "Benjamin Toueg",
|
30 |
+
"githubUsername": "btoueg",
|
31 |
+
"url": "https://github.com/btoueg"
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"name": "Chigozirim C.",
|
35 |
+
"githubUsername": "smac89",
|
36 |
+
"url": "https://github.com/smac89"
|
37 |
+
},
|
38 |
+
{
|
39 |
+
"name": "David Junger",
|
40 |
+
"githubUsername": "touffy",
|
41 |
+
"url": "https://github.com/touffy"
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"name": "Deividas Bakanas",
|
45 |
+
"githubUsername": "DeividasBakanas",
|
46 |
+
"url": "https://github.com/DeividasBakanas"
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"name": "Eugene Y. Q. Shen",
|
50 |
+
"githubUsername": "eyqs",
|
51 |
+
"url": "https://github.com/eyqs"
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"name": "Hannes Magnusson",
|
55 |
+
"githubUsername": "Hannes-Magnusson-CK",
|
56 |
+
"url": "https://github.com/Hannes-Magnusson-CK"
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"name": "Huw",
|
60 |
+
"githubUsername": "hoo29",
|
61 |
+
"url": "https://github.com/hoo29"
|
62 |
+
},
|
63 |
+
{
|
64 |
+
"name": "Kelvin Jin",
|
65 |
+
"githubUsername": "kjin",
|
66 |
+
"url": "https://github.com/kjin"
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"name": "Klaus Meinhardt",
|
70 |
+
"githubUsername": "ajafff",
|
71 |
+
"url": "https://github.com/ajafff"
|
72 |
+
},
|
73 |
+
{
|
74 |
+
"name": "Lishude",
|
75 |
+
"githubUsername": "islishude",
|
76 |
+
"url": "https://github.com/islishude"
|
77 |
+
},
|
78 |
+
{
|
79 |
+
"name": "Mariusz Wiktorczyk",
|
80 |
+
"githubUsername": "mwiktorczyk",
|
81 |
+
"url": "https://github.com/mwiktorczyk"
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"name": "Mohsen Azimi",
|
85 |
+
"githubUsername": "mohsen1",
|
86 |
+
"url": "https://github.com/mohsen1"
|
87 |
+
},
|
88 |
+
{
|
89 |
+
"name": "Nikita Galkin",
|
90 |
+
"githubUsername": "galkin",
|
91 |
+
"url": "https://github.com/galkin"
|
92 |
+
},
|
93 |
+
{
|
94 |
+
"name": "Parambir Singh",
|
95 |
+
"githubUsername": "parambirs",
|
96 |
+
"url": "https://github.com/parambirs"
|
97 |
+
},
|
98 |
+
{
|
99 |
+
"name": "Sebastian Silbermann",
|
100 |
+
"githubUsername": "eps1lon",
|
101 |
+
"url": "https://github.com/eps1lon"
|
102 |
+
},
|
103 |
+
{
|
104 |
+
"name": "Thomas den Hollander",
|
105 |
+
"githubUsername": "ThomasdenH",
|
106 |
+
"url": "https://github.com/ThomasdenH"
|
107 |
+
},
|
108 |
+
{
|
109 |
+
"name": "Wilco Bakker",
|
110 |
+
"githubUsername": "WilcoBakker",
|
111 |
+
"url": "https://github.com/WilcoBakker"
|
112 |
+
},
|
113 |
+
{
|
114 |
+
"name": "wwwy3y3",
|
115 |
+
"githubUsername": "wwwy3y3",
|
116 |
+
"url": "https://github.com/wwwy3y3"
|
117 |
+
},
|
118 |
+
{
|
119 |
+
"name": "Samuel Ainsworth",
|
120 |
+
"githubUsername": "samuela",
|
121 |
+
"url": "https://github.com/samuela"
|
122 |
+
},
|
123 |
+
{
|
124 |
+
"name": "Kyle Uehlein",
|
125 |
+
"githubUsername": "kuehlein",
|
126 |
+
"url": "https://github.com/kuehlein"
|
127 |
+
},
|
128 |
+
{
|
129 |
+
"name": "Thanik Bhongbhibhat",
|
130 |
+
"githubUsername": "bhongy",
|
131 |
+
"url": "https://github.com/bhongy"
|
132 |
+
},
|
133 |
+
{
|
134 |
+
"name": "Marcin Kopacz",
|
135 |
+
"githubUsername": "chyzwar",
|
136 |
+
"url": "https://github.com/chyzwar"
|
137 |
+
},
|
138 |
+
{
|
139 |
+
"name": "Trivikram Kamat",
|
140 |
+
"githubUsername": "trivikr",
|
141 |
+
"url": "https://github.com/trivikr"
|
142 |
+
},
|
143 |
+
{
|
144 |
+
"name": "Junxiao Shi",
|
145 |
+
"githubUsername": "yoursunny",
|
146 |
+
"url": "https://github.com/yoursunny"
|
147 |
+
},
|
148 |
+
{
|
149 |
+
"name": "Ilia Baryshnikov",
|
150 |
+
"githubUsername": "qwelias",
|
151 |
+
"url": "https://github.com/qwelias"
|
152 |
+
},
|
153 |
+
{
|
154 |
+
"name": "ExE Boss",
|
155 |
+
"githubUsername": "ExE-Boss",
|
156 |
+
"url": "https://github.com/ExE-Boss"
|
157 |
+
},
|
158 |
+
{
|
159 |
+
"name": "Piotr Błażejewicz",
|
160 |
+
"githubUsername": "peterblazejewicz",
|
161 |
+
"url": "https://github.com/peterblazejewicz"
|
162 |
+
},
|
163 |
+
{
|
164 |
+
"name": "Anna Henningsen",
|
165 |
+
"githubUsername": "addaleax",
|
166 |
+
"url": "https://github.com/addaleax"
|
167 |
+
},
|
168 |
+
{
|
169 |
+
"name": "Victor Perin",
|
170 |
+
"githubUsername": "victorperin",
|
171 |
+
"url": "https://github.com/victorperin"
|
172 |
+
},
|
173 |
+
{
|
174 |
+
"name": "NodeJS Contributors",
|
175 |
+
"githubUsername": "NodeJS",
|
176 |
+
"url": "https://github.com/NodeJS"
|
177 |
+
},
|
178 |
+
{
|
179 |
+
"name": "Linus Unnebäck",
|
180 |
+
"githubUsername": "LinusU",
|
181 |
+
"url": "https://github.com/LinusU"
|
182 |
+
},
|
183 |
+
{
|
184 |
+
"name": "wafuwafu13",
|
185 |
+
"githubUsername": "wafuwafu13",
|
186 |
+
"url": "https://github.com/wafuwafu13"
|
187 |
+
},
|
188 |
+
{
|
189 |
+
"name": "Matteo Collina",
|
190 |
+
"githubUsername": "mcollina",
|
191 |
+
"url": "https://github.com/mcollina"
|
192 |
+
},
|
193 |
+
{
|
194 |
+
"name": "Dmitry Semigradsky",
|
195 |
+
"githubUsername": "Semigradsky",
|
196 |
+
"url": "https://github.com/Semigradsky"
|
197 |
+
}
|
198 |
+
],
|
199 |
+
"main": "",
|
200 |
+
"types": "index.d.ts",
|
201 |
+
"typesVersions": {
|
202 |
+
"<=5.6": {
|
203 |
+
"*": [
|
204 |
+
"ts5.6/*"
|
205 |
+
]
|
206 |
+
}
|
207 |
+
},
|
208 |
+
"repository": {
|
209 |
+
"type": "git",
|
210 |
+
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
211 |
+
"directory": "types/node"
|
212 |
+
},
|
213 |
+
"scripts": {},
|
214 |
+
"dependencies": {
|
215 |
+
"undici-types": "~6.20.0"
|
216 |
+
},
|
217 |
+
"peerDependencies": {},
|
218 |
+
"typesPublisherContentHash": "473650c3cc1206a93e36487b99568f65b48fd9822931e9690fa0c31e93106b22",
|
219 |
+
"typeScriptVersion": "5.0"
|
220 |
+
}
|
clone/node_modules/@types/node/path.d.ts
ADDED
@@ -0,0 +1,200 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
declare module "path/posix" {
|
2 |
+
import path = require("path");
|
3 |
+
export = path;
|
4 |
+
}
|
5 |
+
declare module "path/win32" {
|
6 |
+
import path = require("path");
|
7 |
+
export = path;
|
8 |
+
}
|
9 |
+
/**
|
10 |
+
* The `node:path` module provides utilities for working with file and directory
|
11 |
+
* paths. It can be accessed using:
|
12 |
+
*
|
13 |
+
* ```js
|
14 |
+
* import path from 'node:path';
|
15 |
+
* ```
|
16 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/path.js)
|
17 |
+
*/
|
18 |
+
declare module "path" {
|
19 |
+
namespace path {
|
20 |
+
/**
|
21 |
+
* A parsed path object generated by path.parse() or consumed by path.format().
|
22 |
+
*/
|
23 |
+
interface ParsedPath {
|
24 |
+
/**
|
25 |
+
* The root of the path such as '/' or 'c:\'
|
26 |
+
*/
|
27 |
+
root: string;
|
28 |
+
/**
|
29 |
+
* The full directory path such as '/home/user/dir' or 'c:\path\dir'
|
30 |
+
*/
|
31 |
+
dir: string;
|
32 |
+
/**
|
33 |
+
* The file name including extension (if any) such as 'index.html'
|
34 |
+
*/
|
35 |
+
base: string;
|
36 |
+
/**
|
37 |
+
* The file extension (if any) such as '.html'
|
38 |
+
*/
|
39 |
+
ext: string;
|
40 |
+
/**
|
41 |
+
* The file name without extension (if any) such as 'index'
|
42 |
+
*/
|
43 |
+
name: string;
|
44 |
+
}
|
45 |
+
interface FormatInputPathObject {
|
46 |
+
/**
|
47 |
+
* The root of the path such as '/' or 'c:\'
|
48 |
+
*/
|
49 |
+
root?: string | undefined;
|
50 |
+
/**
|
51 |
+
* The full directory path such as '/home/user/dir' or 'c:\path\dir'
|
52 |
+
*/
|
53 |
+
dir?: string | undefined;
|
54 |
+
/**
|
55 |
+
* The file name including extension (if any) such as 'index.html'
|
56 |
+
*/
|
57 |
+
base?: string | undefined;
|
58 |
+
/**
|
59 |
+
* The file extension (if any) such as '.html'
|
60 |
+
*/
|
61 |
+
ext?: string | undefined;
|
62 |
+
/**
|
63 |
+
* The file name without extension (if any) such as 'index'
|
64 |
+
*/
|
65 |
+
name?: string | undefined;
|
66 |
+
}
|
67 |
+
interface PlatformPath {
|
68 |
+
/**
|
69 |
+
* Normalize a string path, reducing '..' and '.' parts.
|
70 |
+
* When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.
|
71 |
+
*
|
72 |
+
* @param path string path to normalize.
|
73 |
+
* @throws {TypeError} if `path` is not a string.
|
74 |
+
*/
|
75 |
+
normalize(path: string): string;
|
76 |
+
/**
|
77 |
+
* Join all arguments together and normalize the resulting path.
|
78 |
+
*
|
79 |
+
* @param paths paths to join.
|
80 |
+
* @throws {TypeError} if any of the path segments is not a string.
|
81 |
+
*/
|
82 |
+
join(...paths: string[]): string;
|
83 |
+
/**
|
84 |
+
* The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
|
85 |
+
*
|
86 |
+
* Starting from leftmost {from} parameter, resolves {to} to an absolute path.
|
87 |
+
*
|
88 |
+
* If {to} isn't already absolute, {from} arguments are prepended in right to left order,
|
89 |
+
* until an absolute path is found. If after using all {from} paths still no absolute path is found,
|
90 |
+
* the current working directory is used as well. The resulting path is normalized,
|
91 |
+
* and trailing slashes are removed unless the path gets resolved to the root directory.
|
92 |
+
*
|
93 |
+
* @param paths A sequence of paths or path segments.
|
94 |
+
* @throws {TypeError} if any of the arguments is not a string.
|
95 |
+
*/
|
96 |
+
resolve(...paths: string[]): string;
|
97 |
+
/**
|
98 |
+
* The `path.matchesGlob()` method determines if `path` matches the `pattern`.
|
99 |
+
* @param path The path to glob-match against.
|
100 |
+
* @param pattern The glob to check the path against.
|
101 |
+
* @returns Whether or not the `path` matched the `pattern`.
|
102 |
+
* @throws {TypeError} if `path` or `pattern` are not strings.
|
103 |
+
* @since v22.5.0
|
104 |
+
*/
|
105 |
+
matchesGlob(path: string, pattern: string): boolean;
|
106 |
+
/**
|
107 |
+
* Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
|
108 |
+
*
|
109 |
+
* If the given {path} is a zero-length string, `false` will be returned.
|
110 |
+
*
|
111 |
+
* @param path path to test.
|
112 |
+
* @throws {TypeError} if `path` is not a string.
|
113 |
+
*/
|
114 |
+
isAbsolute(path: string): boolean;
|
115 |
+
/**
|
116 |
+
* Solve the relative path from {from} to {to} based on the current working directory.
|
117 |
+
* At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.
|
118 |
+
*
|
119 |
+
* @throws {TypeError} if either `from` or `to` is not a string.
|
120 |
+
*/
|
121 |
+
relative(from: string, to: string): string;
|
122 |
+
/**
|
123 |
+
* Return the directory name of a path. Similar to the Unix dirname command.
|
124 |
+
*
|
125 |
+
* @param path the path to evaluate.
|
126 |
+
* @throws {TypeError} if `path` is not a string.
|
127 |
+
*/
|
128 |
+
dirname(path: string): string;
|
129 |
+
/**
|
130 |
+
* Return the last portion of a path. Similar to the Unix basename command.
|
131 |
+
* Often used to extract the file name from a fully qualified path.
|
132 |
+
*
|
133 |
+
* @param path the path to evaluate.
|
134 |
+
* @param suffix optionally, an extension to remove from the result.
|
135 |
+
* @throws {TypeError} if `path` is not a string or if `ext` is given and is not a string.
|
136 |
+
*/
|
137 |
+
basename(path: string, suffix?: string): string;
|
138 |
+
/**
|
139 |
+
* Return the extension of the path, from the last '.' to end of string in the last portion of the path.
|
140 |
+
* If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string.
|
141 |
+
*
|
142 |
+
* @param path the path to evaluate.
|
143 |
+
* @throws {TypeError} if `path` is not a string.
|
144 |
+
*/
|
145 |
+
extname(path: string): string;
|
146 |
+
/**
|
147 |
+
* The platform-specific file separator. '\\' or '/'.
|
148 |
+
*/
|
149 |
+
readonly sep: "\\" | "/";
|
150 |
+
/**
|
151 |
+
* The platform-specific file delimiter. ';' or ':'.
|
152 |
+
*/
|
153 |
+
readonly delimiter: ";" | ":";
|
154 |
+
/**
|
155 |
+
* Returns an object from a path string - the opposite of format().
|
156 |
+
*
|
157 |
+
* @param path path to evaluate.
|
158 |
+
* @throws {TypeError} if `path` is not a string.
|
159 |
+
*/
|
160 |
+
parse(path: string): ParsedPath;
|
161 |
+
/**
|
162 |
+
* Returns a path string from an object - the opposite of parse().
|
163 |
+
*
|
164 |
+
* @param pathObject path to evaluate.
|
165 |
+
*/
|
166 |
+
format(pathObject: FormatInputPathObject): string;
|
167 |
+
/**
|
168 |
+
* On Windows systems only, returns an equivalent namespace-prefixed path for the given path.
|
169 |
+
* If path is not a string, path will be returned without modifications.
|
170 |
+
* This method is meaningful only on Windows system.
|
171 |
+
* On POSIX systems, the method is non-operational and always returns path without modifications.
|
172 |
+
*/
|
173 |
+
toNamespacedPath(path: string): string;
|
174 |
+
/**
|
175 |
+
* Posix specific pathing.
|
176 |
+
* Same as parent object on posix.
|
177 |
+
*/
|
178 |
+
readonly posix: PlatformPath;
|
179 |
+
/**
|
180 |
+
* Windows specific pathing.
|
181 |
+
* Same as parent object on windows
|
182 |
+
*/
|
183 |
+
readonly win32: PlatformPath;
|
184 |
+
}
|
185 |
+
}
|
186 |
+
const path: path.PlatformPath;
|
187 |
+
export = path;
|
188 |
+
}
|
189 |
+
declare module "node:path" {
|
190 |
+
import path = require("path");
|
191 |
+
export = path;
|
192 |
+
}
|
193 |
+
declare module "node:path/posix" {
|
194 |
+
import path = require("path/posix");
|
195 |
+
export = path;
|
196 |
+
}
|
197 |
+
declare module "node:path/win32" {
|
198 |
+
import path = require("path/win32");
|
199 |
+
export = path;
|
200 |
+
}
|
clone/node_modules/@types/node/perf_hooks.d.ts
ADDED
@@ -0,0 +1,965 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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Is for
|
3 |
+
* Node.js-specific performance measurements.
|
4 |
+
*
|
5 |
+
* Node.js supports the following [Web Performance APIs](https://w3c.github.io/perf-timing-primer/):
|
6 |
+
*
|
7 |
+
* * [High Resolution Time](https://www.w3.org/TR/hr-time-2)
|
8 |
+
* * [Performance Timeline](https://w3c.github.io/performance-timeline/)
|
9 |
+
* * [User Timing](https://www.w3.org/TR/user-timing/)
|
10 |
+
* * [Resource Timing](https://www.w3.org/TR/resource-timing-2/)
|
11 |
+
*
|
12 |
+
* ```js
|
13 |
+
* import { PerformanceObserver, performance } from 'node:perf_hooks';
|
14 |
+
*
|
15 |
+
* const obs = new PerformanceObserver((items) => {
|
16 |
+
* console.log(items.getEntries()[0].duration);
|
17 |
+
* performance.clearMarks();
|
18 |
+
* });
|
19 |
+
* obs.observe({ type: 'measure' });
|
20 |
+
* performance.measure('Start to Now');
|
21 |
+
*
|
22 |
+
* performance.mark('A');
|
23 |
+
* doSomeLongRunningProcess(() => {
|
24 |
+
* performance.measure('A to Now', 'A');
|
25 |
+
*
|
26 |
+
* performance.mark('B');
|
27 |
+
* performance.measure('A to B', 'A', 'B');
|
28 |
+
* });
|
29 |
+
* ```
|
30 |
+
* @see [source](https://github.com/nodejs/node/blob/v22.x/lib/perf_hooks.js)
|
31 |
+
*/
|
32 |
+
declare module "perf_hooks" {
|
33 |
+
import { AsyncResource } from "node:async_hooks";
|
34 |
+
type EntryType =
|
35 |
+
| "dns" // Node.js only
|
36 |
+
| "function" // Node.js only
|
37 |
+
| "gc" // Node.js only
|
38 |
+
| "http2" // Node.js only
|
39 |
+
| "http" // Node.js only
|
40 |
+
| "mark" // available on the Web
|
41 |
+
| "measure" // available on the Web
|
42 |
+
| "net" // Node.js only
|
43 |
+
| "node" // Node.js only
|
44 |
+
| "resource"; // available on the Web
|
45 |
+
interface NodeGCPerformanceDetail {
|
46 |
+
/**
|
47 |
+
* When `performanceEntry.entryType` is equal to 'gc', the `performance.kind` property identifies
|
48 |
+
* the type of garbage collection operation that occurred.
|
49 |
+
* See perf_hooks.constants for valid values.
|
50 |
+
*/
|
51 |
+
readonly kind?: number | undefined;
|
52 |
+
/**
|
53 |
+
* When `performanceEntry.entryType` is equal to 'gc', the `performance.flags`
|
54 |
+
* property contains additional information about garbage collection operation.
|
55 |
+
* See perf_hooks.constants for valid values.
|
56 |
+
*/
|
57 |
+
readonly flags?: number | undefined;
|
58 |
+
}
|
59 |
+
/**
|
60 |
+
* The constructor of this class is not exposed to users directly.
|
61 |
+
* @since v8.5.0
|
62 |
+
*/
|
63 |
+
class PerformanceEntry {
|
64 |
+
protected constructor();
|
65 |
+
/**
|
66 |
+
* The total number of milliseconds elapsed for this entry. This value will not
|
67 |
+
* be meaningful for all Performance Entry types.
|
68 |
+
* @since v8.5.0
|
69 |
+
*/
|
70 |
+
readonly duration: number;
|
71 |
+
/**
|
72 |
+
* The name of the performance entry.
|
73 |
+
* @since v8.5.0
|
74 |
+
*/
|
75 |
+
readonly name: string;
|
76 |
+
/**
|
77 |
+
* The high resolution millisecond timestamp marking the starting time of the
|
78 |
+
* Performance Entry.
|
79 |
+
* @since v8.5.0
|
80 |
+
*/
|
81 |
+
readonly startTime: number;
|
82 |
+
/**
|
83 |
+
* The type of the performance entry. It may be one of:
|
84 |
+
*
|
85 |
+
* * `'node'` (Node.js only)
|
86 |
+
* * `'mark'` (available on the Web)
|
87 |
+
* * `'measure'` (available on the Web)
|
88 |
+
* * `'gc'` (Node.js only)
|
89 |
+
* * `'function'` (Node.js only)
|
90 |
+
* * `'http2'` (Node.js only)
|
91 |
+
* * `'http'` (Node.js only)
|
92 |
+
* @since v8.5.0
|
93 |
+
*/
|
94 |
+
readonly entryType: EntryType;
|
95 |
+
/**
|
96 |
+
* Additional detail specific to the `entryType`.
|
97 |
+
* @since v16.0.0
|
98 |
+
*/
|
99 |
+
readonly detail?: NodeGCPerformanceDetail | unknown | undefined; // TODO: Narrow this based on entry type.
|
100 |
+
toJSON(): any;
|
101 |
+
}
|
102 |
+
/**
|
103 |
+
* Exposes marks created via the `Performance.mark()` method.
|
104 |
+
* @since v18.2.0, v16.17.0
|
105 |
+
*/
|
106 |
+
class PerformanceMark extends PerformanceEntry {
|
107 |
+
readonly duration: 0;
|
108 |
+
readonly entryType: "mark";
|
109 |
+
}
|
110 |
+
/**
|
111 |
+
* Exposes measures created via the `Performance.measure()` method.
|
112 |
+
*
|
113 |
+
* The constructor of this class is not exposed to users directly.
|
114 |
+
* @since v18.2.0, v16.17.0
|
115 |
+
*/
|
116 |
+
class PerformanceMeasure extends PerformanceEntry {
|
117 |
+
readonly entryType: "measure";
|
118 |
+
}
|
119 |
+
interface UVMetrics {
|
120 |
+
/**
|
121 |
+
* Number of event loop iterations.
|
122 |
+
*/
|
123 |
+
readonly loopCount: number;
|
124 |
+
/**
|
125 |
+
* Number of events that have been processed by the event handler.
|
126 |
+
*/
|
127 |
+
readonly events: number;
|
128 |
+
/**
|
129 |
+
* Number of events that were waiting to be processed when the event provider was called.
|
130 |
+
*/
|
131 |
+
readonly eventsWaiting: number;
|
132 |
+
}
|
133 |
+
/**
|
134 |
+
* _This property is an extension by Node.js. It is not available in Web browsers._
|
135 |
+
*
|
136 |
+
* Provides timing details for Node.js itself. The constructor of this class
|
137 |
+
* is not exposed to users.
|
138 |
+
* @since v8.5.0
|
139 |
+
*/
|
140 |
+
class PerformanceNodeTiming extends PerformanceEntry {
|
141 |
+
readonly entryType: "node";
|
142 |
+
/**
|
143 |
+
* The high resolution millisecond timestamp at which the Node.js process
|
144 |
+
* completed bootstrapping. If bootstrapping has not yet finished, the property
|
145 |
+
* has the value of -1.
|
146 |
+
* @since v8.5.0
|
147 |
+
*/
|
148 |
+
readonly bootstrapComplete: number;
|
149 |
+
/**
|
150 |
+
* The high resolution millisecond timestamp at which the Node.js environment was
|
151 |
+
* initialized.
|
152 |
+
* @since v8.5.0
|
153 |
+
*/
|
154 |
+
readonly environment: number;
|
155 |
+
/**
|
156 |
+
* The high resolution millisecond timestamp of the amount of time the event loop
|
157 |
+
* has been idle within the event loop's event provider (e.g. `epoll_wait`). This
|
158 |
+
* does not take CPU usage into consideration. If the event loop has not yet
|
159 |
+
* started (e.g., in the first tick of the main script), the property has the
|
160 |
+
* value of 0.
|
161 |
+
* @since v14.10.0, v12.19.0
|
162 |
+
*/
|
163 |
+
readonly idleTime: number;
|
164 |
+
/**
|
165 |
+
* The high resolution millisecond timestamp at which the Node.js event loop
|
166 |
+
* exited. If the event loop has not yet exited, the property has the value of -1\.
|
167 |
+
* It can only have a value of not -1 in a handler of the `'exit'` event.
|
168 |
+
* @since v8.5.0
|
169 |
+
*/
|
170 |
+
readonly loopExit: number;
|
171 |
+
/**
|
172 |
+
* The high resolution millisecond timestamp at which the Node.js event loop
|
173 |
+
* started. If the event loop has not yet started (e.g., in the first tick of the
|
174 |
+
* main script), the property has the value of -1.
|
175 |
+
* @since v8.5.0
|
176 |
+
*/
|
177 |
+
readonly loopStart: number;
|
178 |
+
/**
|
179 |
+
* The high resolution millisecond timestamp at which the Node.js process was initialized.
|
180 |
+
* @since v8.5.0
|
181 |
+
*/
|
182 |
+
readonly nodeStart: number;
|
183 |
+
/**
|
184 |
+
* This is a wrapper to the `uv_metrics_info` function.
|
185 |
+
* It returns the current set of event loop metrics.
|
186 |
+
*
|
187 |
+
* It is recommended to use this property inside a function whose execution was
|
188 |
+
* scheduled using `setImmediate` to avoid collecting metrics before finishing all
|
189 |
+
* operations scheduled during the current loop iteration.
|
190 |
+
* @since v22.8.0, v20.18.0
|
191 |
+
*/
|
192 |
+
readonly uvMetricsInfo: UVMetrics;
|
193 |
+
/**
|
194 |
+
* The high resolution millisecond timestamp at which the V8 platform was
|
195 |
+
* initialized.
|
196 |
+
* @since v8.5.0
|
197 |
+
*/
|
198 |
+
readonly v8Start: number;
|
199 |
+
}
|
200 |
+
interface EventLoopUtilization {
|
201 |
+
idle: number;
|
202 |
+
active: number;
|
203 |
+
utilization: number;
|
204 |
+
}
|
205 |
+
/**
|
206 |
+
* @param utilization1 The result of a previous call to `eventLoopUtilization()`.
|
207 |
+
* @param utilization2 The result of a previous call to `eventLoopUtilization()` prior to `utilization1`.
|
208 |
+
*/
|
209 |
+
type EventLoopUtilityFunction = (
|
210 |
+
utilization1?: EventLoopUtilization,
|
211 |
+
utilization2?: EventLoopUtilization,
|
212 |
+
) => EventLoopUtilization;
|
213 |
+
interface MarkOptions {
|
214 |
+
/**
|
215 |
+
* Additional optional detail to include with the mark.
|
216 |
+
*/
|
217 |
+
detail?: unknown | undefined;
|
218 |
+
/**
|
219 |
+
* An optional timestamp to be used as the mark time.
|
220 |
+
* @default `performance.now()`
|
221 |
+
*/
|
222 |
+
startTime?: number | undefined;
|
223 |
+
}
|
224 |
+
interface MeasureOptions {
|
225 |
+
/**
|
226 |
+
* Additional optional detail to include with the mark.
|
227 |
+
*/
|
228 |
+
detail?: unknown | undefined;
|
229 |
+
/**
|
230 |
+
* Duration between start and end times.
|
231 |
+
*/
|
232 |
+
duration?: number | undefined;
|
233 |
+
/**
|
234 |
+
* Timestamp to be used as the end time, or a string identifying a previously recorded mark.
|
235 |
+
*/
|
236 |
+
end?: number | string | undefined;
|
237 |
+
/**
|
238 |
+
* Timestamp to be used as the start time, or a string identifying a previously recorded mark.
|
239 |
+
*/
|
240 |
+
start?: number | string | undefined;
|
241 |
+
}
|
242 |
+
interface TimerifyOptions {
|
243 |
+
/**
|
244 |
+
* A histogram object created using `perf_hooks.createHistogram()` that will record runtime
|
245 |
+
* durations in nanoseconds.
|
246 |
+
*/
|
247 |
+
histogram?: RecordableHistogram | undefined;
|
248 |
+
}
|
249 |
+
interface Performance {
|
250 |
+
/**
|
251 |
+
* If `name` is not provided, removes all `PerformanceMark` objects from the Performance Timeline.
|
252 |
+
* If `name` is provided, removes only the named mark.
|
253 |
+
* @since v8.5.0
|
254 |
+
*/
|
255 |
+
clearMarks(name?: string): void;
|
256 |
+
/**
|
257 |
+
* If `name` is not provided, removes all `PerformanceMeasure` objects from the Performance Timeline.
|
258 |
+
* If `name` is provided, removes only the named measure.
|
259 |
+
* @since v16.7.0
|
260 |
+
*/
|
261 |
+
clearMeasures(name?: string): void;
|
262 |
+
/**
|
263 |
+
* If `name` is not provided, removes all `PerformanceResourceTiming` objects from the Resource Timeline.
|
264 |
+
* If `name` is provided, removes only the named resource.
|
265 |
+
* @since v18.2.0, v16.17.0
|
266 |
+
*/
|
267 |
+
clearResourceTimings(name?: string): void;
|
268 |
+
/**
|
269 |
+
* eventLoopUtilization is similar to CPU utilization except that it is calculated using high precision wall-clock time.
|
270 |
+
* It represents the percentage of time the event loop has spent outside the event loop's event provider (e.g. epoll_wait).
|
271 |
+
* No other CPU idle time is taken into consideration.
|
272 |
+
*/
|
273 |
+
eventLoopUtilization: EventLoopUtilityFunction;
|
274 |
+
/**
|
275 |
+
* Returns a list of `PerformanceEntry` objects in chronological order with respect to `performanceEntry.startTime`.
|
276 |
+
* If you are only interested in performance entries of certain types or that have certain names, see
|
277 |
+
* `performance.getEntriesByType()` and `performance.getEntriesByName()`.
|
278 |
+
* @since v16.7.0
|
279 |
+
*/
|
280 |
+
getEntries(): PerformanceEntry[];
|
281 |
+
/**
|
282 |
+
* Returns a list of `PerformanceEntry` objects in chronological order with respect to `performanceEntry.startTime`
|
283 |
+
* whose `performanceEntry.name` is equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to `type`.
|
284 |
+
* @param name
|
285 |
+
* @param type
|
286 |
+
* @since v16.7.0
|
287 |
+
*/
|
288 |
+
getEntriesByName(name: string, type?: EntryType): PerformanceEntry[];
|
289 |
+
/**
|
290 |
+
* Returns a list of `PerformanceEntry` objects in chronological order with respect to `performanceEntry.startTime`
|
291 |
+
* whose `performanceEntry.entryType` is equal to `type`.
|
292 |
+
* @param type
|
293 |
+
* @since v16.7.0
|
294 |
+
*/
|
295 |
+
getEntriesByType(type: EntryType): PerformanceEntry[];
|
296 |
+
/**
|
297 |
+
* Creates a new `PerformanceMark` entry in the Performance Timeline.
|
298 |
+
* A `PerformanceMark` is a subclass of `PerformanceEntry` whose `performanceEntry.entryType` is always `'mark'`,
|
299 |
+
* and whose `performanceEntry.duration` is always `0`.
|
300 |
+
* Performance marks are used to mark specific significant moments in the Performance Timeline.
|
301 |
+
*
|
302 |
+
* The created `PerformanceMark` entry is put in the global Performance Timeline and can be queried with
|
303 |
+
* `performance.getEntries`, `performance.getEntriesByName`, and `performance.getEntriesByType`. When the observation is
|
304 |
+
* performed, the entries should be cleared from the global Performance Timeline manually with `performance.clearMarks`.
|
305 |
+
* @param name
|
306 |
+
*/
|
307 |
+
mark(name: string, options?: MarkOptions): PerformanceMark;
|
308 |
+
/**
|
309 |
+
* Creates a new `PerformanceResourceTiming` entry in the Resource Timeline.
|
310 |
+
* A `PerformanceResourceTiming` is a subclass of `PerformanceEntry` whose `performanceEntry.entryType` is always `'resource'`.
|
311 |
+
* Performance resources are used to mark moments in the Resource Timeline.
|
312 |
+
* @param timingInfo [Fetch Timing Info](https://fetch.spec.whatwg.org/#fetch-timing-info)
|
313 |
+
* @param requestedUrl The resource url
|
314 |
+
* @param initiatorType The initiator name, e.g: 'fetch'
|
315 |
+
* @param global
|
316 |
+
* @param cacheMode The cache mode must be an empty string ('') or 'local'
|
317 |
+
* @param bodyInfo [Fetch Response Body Info](https://fetch.spec.whatwg.org/#response-body-info)
|
318 |
+
* @param responseStatus The response's status code
|
319 |
+
* @param deliveryType The delivery type. Default: ''.
|
320 |
+
* @since v18.2.0, v16.17.0
|
321 |
+
*/
|
322 |
+
markResourceTiming(
|
323 |
+
timingInfo: object,
|
324 |
+
requestedUrl: string,
|
325 |
+
initiatorType: string,
|
326 |
+
global: object,
|
327 |
+
cacheMode: "" | "local",
|
328 |
+
bodyInfo: object,
|
329 |
+
responseStatus: number,
|
330 |
+
deliveryType?: string,
|
331 |
+
): PerformanceResourceTiming;
|
332 |
+
/**
|
333 |
+
* Creates a new PerformanceMeasure entry in the Performance Timeline.
|
334 |
+
* A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure',
|
335 |
+
* and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark.
|
336 |
+
*
|
337 |
+
* The startMark argument may identify any existing PerformanceMark in the the Performance Timeline, or may identify
|
338 |
+
* any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist,
|
339 |
+
* then startMark is set to timeOrigin by default.
|
340 |
+
*
|
341 |
+
* The endMark argument must identify any existing PerformanceMark in the the Performance Timeline or any of the timestamp
|
342 |
+
* properties provided by the PerformanceNodeTiming class. If the named endMark does not exist, an error will be thrown.
|
343 |
+
* @param name
|
344 |
+
* @param startMark
|
345 |
+
* @param endMark
|
346 |
+
* @return The PerformanceMeasure entry that was created
|
347 |
+
*/
|
348 |
+
measure(name: string, startMark?: string, endMark?: string): PerformanceMeasure;
|
349 |
+
measure(name: string, options: MeasureOptions): PerformanceMeasure;
|
350 |
+
/**
|
351 |
+
* _This property is an extension by Node.js. It is not available in Web browsers._
|
352 |
+
*
|
353 |
+
* An instance of the `PerformanceNodeTiming` class that provides performance metrics for specific Node.js operational milestones.
|
354 |
+
* @since v8.5.0
|
355 |
+
*/
|
356 |
+
readonly nodeTiming: PerformanceNodeTiming;
|
357 |
+
/**
|
358 |
+
* Returns the current high resolution millisecond timestamp, where 0 represents the start of the current `node` process.
|
359 |
+
* @since v8.5.0
|
360 |
+
*/
|
361 |
+
now(): number;
|
362 |
+
/**
|
363 |
+
* Sets the global performance resource timing buffer size to the specified number of "resource" type performance entry objects.
|
364 |
+
*
|
365 |
+
* By default the max buffer size is set to 250.
|
366 |
+
* @since v18.8.0
|
367 |
+
*/
|
368 |
+
setResourceTimingBufferSize(maxSize: number): void;
|
369 |
+
/**
|
370 |
+
* The [`timeOrigin`](https://w3c.github.io/hr-time/#dom-performance-timeorigin) specifies the high resolution millisecond timestamp
|
371 |
+
* at which the current `node` process began, measured in Unix time.
|
372 |
+
* @since v8.5.0
|
373 |
+
*/
|
374 |
+
readonly timeOrigin: number;
|
375 |
+
/**
|
376 |
+
* _This property is an extension by Node.js. It is not available in Web browsers._
|
377 |
+
*
|
378 |
+
* Wraps a function within a new function that measures the running time of the wrapped function.
|
379 |
+
* A `PerformanceObserver` must be subscribed to the `'function'` event type in order for the timing details to be accessed.
|
380 |
+
*
|
381 |
+
* ```js
|
382 |
+
* import {
|
383 |
+
* performance,
|
384 |
+
* PerformanceObserver,
|
385 |
+
* } from 'node:perf_hooks';
|
386 |
+
*
|
387 |
+
* function someFunction() {
|
388 |
+
* console.log('hello world');
|
389 |
+
* }
|
390 |
+
*
|
391 |
+
* const wrapped = performance.timerify(someFunction);
|
392 |
+
*
|
393 |
+
* const obs = new PerformanceObserver((list) => {
|
394 |
+
* console.log(list.getEntries()[0].duration);
|
395 |
+
*
|
396 |
+
* performance.clearMarks();
|
397 |
+
* performance.clearMeasures();
|
398 |
+
* obs.disconnect();
|
399 |
+
* });
|
400 |
+
* obs.observe({ entryTypes: ['function'] });
|
401 |
+
*
|
402 |
+
* // A performance timeline entry will be created
|
403 |
+
* wrapped();
|
404 |
+
* ```
|
405 |
+
*
|
406 |
+
* If the wrapped function returns a promise, a finally handler will be attached to the promise and the duration will be reported
|
407 |
+
* once the finally handler is invoked.
|
408 |
+
* @param fn
|
409 |
+
*/
|
410 |
+
timerify<T extends (...params: any[]) => any>(fn: T, options?: TimerifyOptions): T;
|
411 |
+
/**
|
412 |
+
* An object which is JSON representation of the performance object. It is similar to
|
413 |
+
* [`window.performance.toJSON`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/toJSON) in browsers.
|
414 |
+
* @since v16.1.0
|
415 |
+
*/
|
416 |
+
toJSON(): any;
|
417 |
+
}
|
418 |
+
class PerformanceObserverEntryList {
|
419 |
+
/**
|
420 |
+
* Returns a list of `PerformanceEntry` objects in chronological order
|
421 |
+
* with respect to `performanceEntry.startTime`.
|
422 |
+
*
|
423 |
+
* ```js
|
424 |
+
* import {
|
425 |
+
* performance,
|
426 |
+
* PerformanceObserver,
|
427 |
+
* } from 'node:perf_hooks';
|
428 |
+
*
|
429 |
+
* const obs = new PerformanceObserver((perfObserverList, observer) => {
|
430 |
+
* console.log(perfObserverList.getEntries());
|
431 |
+
*
|
432 |
+
* * [
|
433 |
+
* * PerformanceEntry {
|
434 |
+
* * name: 'test',
|
435 |
+
* * entryType: 'mark',
|
436 |
+
* * startTime: 81.465639,
|
437 |
+
* * duration: 0,
|
438 |
+
* * detail: null
|
439 |
+
* * },
|
440 |
+
* * PerformanceEntry {
|
441 |
+
* * name: 'meow',
|
442 |
+
* * entryType: 'mark',
|
443 |
+
* * startTime: 81.860064,
|
444 |
+
* * duration: 0,
|
445 |
+
* * detail: null
|
446 |
+
* * }
|
447 |
+
* * ]
|
448 |
+
*
|
449 |
+
* performance.clearMarks();
|
450 |
+
* performance.clearMeasures();
|
451 |
+
* observer.disconnect();
|
452 |
+
* });
|
453 |
+
* obs.observe({ type: 'mark' });
|
454 |
+
*
|
455 |
+
* performance.mark('test');
|
456 |
+
* performance.mark('meow');
|
457 |
+
* ```
|
458 |
+
* @since v8.5.0
|
459 |
+
*/
|
460 |
+
getEntries(): PerformanceEntry[];
|
461 |
+
/**
|
462 |
+
* Returns a list of `PerformanceEntry` objects in chronological order
|
463 |
+
* with respect to `performanceEntry.startTime` whose `performanceEntry.name` is
|
464 |
+
* equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to`type`.
|
465 |
+
*
|
466 |
+
* ```js
|
467 |
+
* import {
|
468 |
+
* performance,
|
469 |
+
* PerformanceObserver,
|
470 |
+
* } from 'node:perf_hooks';
|
471 |
+
*
|
472 |
+
* const obs = new PerformanceObserver((perfObserverList, observer) => {
|
473 |
+
* console.log(perfObserverList.getEntriesByName('meow'));
|
474 |
+
*
|
475 |
+
* * [
|
476 |
+
* * PerformanceEntry {
|
477 |
+
* * name: 'meow',
|
478 |
+
* * entryType: 'mark',
|
479 |
+
* * startTime: 98.545991,
|
480 |
+
* * duration: 0,
|
481 |
+
* * detail: null
|
482 |
+
* * }
|
483 |
+
* * ]
|
484 |
+
*
|
485 |
+
* console.log(perfObserverList.getEntriesByName('nope')); // []
|
486 |
+
*
|
487 |
+
* console.log(perfObserverList.getEntriesByName('test', 'mark'));
|
488 |
+
*
|
489 |
+
* * [
|
490 |
+
* * PerformanceEntry {
|
491 |
+
* * name: 'test',
|
492 |
+
* * entryType: 'mark',
|
493 |
+
* * startTime: 63.518931,
|
494 |
+
* * duration: 0,
|
495 |
+
* * detail: null
|
496 |
+
* * }
|
497 |
+
* * ]
|
498 |
+
*
|
499 |
+
* console.log(perfObserverList.getEntriesByName('test', 'measure')); // []
|
500 |
+
*
|
501 |
+
* performance.clearMarks();
|
502 |
+
* performance.clearMeasures();
|
503 |
+
* observer.disconnect();
|
504 |
+
* });
|
505 |
+
* obs.observe({ entryTypes: ['mark', 'measure'] });
|
506 |
+
*
|
507 |
+
* performance.mark('test');
|
508 |
+
* performance.mark('meow');
|
509 |
+
* ```
|
510 |
+
* @since v8.5.0
|
511 |
+
*/
|
512 |
+
getEntriesByName(name: string, type?: EntryType): PerformanceEntry[];
|
513 |
+
/**
|
514 |
+
* Returns a list of `PerformanceEntry` objects in chronological order
|
515 |
+
* with respect to `performanceEntry.startTime` whose `performanceEntry.entryType` is equal to `type`.
|
516 |
+
*
|
517 |
+
* ```js
|
518 |
+
* import {
|
519 |
+
* performance,
|
520 |
+
* PerformanceObserver,
|
521 |
+
* } from 'node:perf_hooks';
|
522 |
+
*
|
523 |
+
* const obs = new PerformanceObserver((perfObserverList, observer) => {
|
524 |
+
* console.log(perfObserverList.getEntriesByType('mark'));
|
525 |
+
*
|
526 |
+
* * [
|
527 |
+
* * PerformanceEntry {
|
528 |
+
* * name: 'test',
|
529 |
+
* * entryType: 'mark',
|
530 |
+
* * startTime: 55.897834,
|
531 |
+
* * duration: 0,
|
532 |
+
* * detail: null
|
533 |
+
* * },
|
534 |
+
* * PerformanceEntry {
|
535 |
+
* * name: 'meow',
|
536 |
+
* * entryType: 'mark',
|
537 |
+
* * startTime: 56.350146,
|
538 |
+
* * duration: 0,
|
539 |
+
* * detail: null
|
540 |
+
* * }
|
541 |
+
* * ]
|
542 |
+
*
|
543 |
+
* performance.clearMarks();
|
544 |
+
* performance.clearMeasures();
|
545 |
+
* observer.disconnect();
|
546 |
+
* });
|
547 |
+
* obs.observe({ type: 'mark' });
|
548 |
+
*
|
549 |
+
* performance.mark('test');
|
550 |
+
* performance.mark('meow');
|
551 |
+
* ```
|
552 |
+
* @since v8.5.0
|
553 |
+
*/
|
554 |
+
getEntriesByType(type: EntryType): PerformanceEntry[];
|
555 |
+
}
|
556 |
+
type PerformanceObserverCallback = (list: PerformanceObserverEntryList, observer: PerformanceObserver) => void;
|
557 |
+
/**
|
558 |
+
* @since v8.5.0
|
559 |
+
*/
|
560 |
+
class PerformanceObserver extends AsyncResource {
|
561 |
+
constructor(callback: PerformanceObserverCallback);
|
562 |
+
/**
|
563 |
+
* Disconnects the `PerformanceObserver` instance from all notifications.
|
564 |
+
* @since v8.5.0
|
565 |
+
*/
|
566 |
+
disconnect(): void;
|
567 |
+
/**
|
568 |
+
* Subscribes the `PerformanceObserver` instance to notifications of new `PerformanceEntry` instances identified either by `options.entryTypes` or `options.type`:
|
569 |
+
*
|
570 |
+
* ```js
|
571 |
+
* import {
|
572 |
+
* performance,
|
573 |
+
* PerformanceObserver,
|
574 |
+
* } from 'node:perf_hooks';
|
575 |
+
*
|
576 |
+
* const obs = new PerformanceObserver((list, observer) => {
|
577 |
+
* // Called once asynchronously. `list` contains three items.
|
578 |
+
* });
|
579 |
+
* obs.observe({ type: 'mark' });
|
580 |
+
*
|
581 |
+
* for (let n = 0; n < 3; n++)
|
582 |
+
* performance.mark(`test${n}`);
|
583 |
+
* ```
|
584 |
+
* @since v8.5.0
|
585 |
+
*/
|
586 |
+
observe(
|
587 |
+
options:
|
588 |
+
| {
|
589 |
+
entryTypes: readonly EntryType[];
|
590 |
+
buffered?: boolean | undefined;
|
591 |
+
}
|
592 |
+
| {
|
593 |
+
type: EntryType;
|
594 |
+
buffered?: boolean | undefined;
|
595 |
+
},
|
596 |
+
): void;
|
597 |
+
}
|
598 |
+
/**
|
599 |
+
* Provides detailed network timing data regarding the loading of an application's resources.
|
600 |
+
*
|
601 |
+
* The constructor of this class is not exposed to users directly.
|
602 |
+
* @since v18.2.0, v16.17.0
|
603 |
+
*/
|
604 |
+
class PerformanceResourceTiming extends PerformanceEntry {
|
605 |
+
readonly entryType: "resource";
|
606 |
+
protected constructor();
|
607 |
+
/**
|
608 |
+
* The high resolution millisecond timestamp at immediately before dispatching the `fetch`
|
609 |
+
* request. If the resource is not intercepted by a worker the property will always return 0.
|
610 |
+
* @since v18.2.0, v16.17.0
|
611 |
+
*/
|
612 |
+
readonly workerStart: number;
|
613 |
+
/**
|
614 |
+
* The high resolution millisecond timestamp that represents the start time of the fetch which
|
615 |
+
* initiates the redirect.
|
616 |
+
* @since v18.2.0, v16.17.0
|
617 |
+
*/
|
618 |
+
readonly redirectStart: number;
|
619 |
+
/**
|
620 |
+
* The high resolution millisecond timestamp that will be created immediately after receiving
|
621 |
+
* the last byte of the response of the last redirect.
|
622 |
+
* @since v18.2.0, v16.17.0
|
623 |
+
*/
|
624 |
+
readonly redirectEnd: number;
|
625 |
+
/**
|
626 |
+
* The high resolution millisecond timestamp immediately before the Node.js starts to fetch the resource.
|
627 |
+
* @since v18.2.0, v16.17.0
|
628 |
+
*/
|
629 |
+
readonly fetchStart: number;
|
630 |
+
/**
|
631 |
+
* The high resolution millisecond timestamp immediately before the Node.js starts the domain name lookup
|
632 |
+
* for the resource.
|
633 |
+
* @since v18.2.0, v16.17.0
|
634 |
+
*/
|
635 |
+
readonly domainLookupStart: number;
|
636 |
+
/**
|
637 |
+
* The high resolution millisecond timestamp representing the time immediately after the Node.js finished
|
638 |
+
* the domain name lookup for the resource.
|
639 |
+
* @since v18.2.0, v16.17.0
|
640 |
+
*/
|
641 |
+
readonly domainLookupEnd: number;
|
642 |
+
/**
|
643 |
+
* The high resolution millisecond timestamp representing the time immediately before Node.js starts to
|
644 |
+
* establish the connection to the server to retrieve the resource.
|
645 |
+
* @since v18.2.0, v16.17.0
|
646 |
+
*/
|
647 |
+
readonly connectStart: number;
|
648 |
+
/**
|
649 |
+
* The high resolution millisecond timestamp representing the time immediately after Node.js finishes
|
650 |
+
* establishing the connection to the server to retrieve the resource.
|
651 |
+
* @since v18.2.0, v16.17.0
|
652 |
+
*/
|
653 |
+
readonly connectEnd: number;
|
654 |
+
/**
|
655 |
+
* The high resolution millisecond timestamp representing the time immediately before Node.js starts the
|
656 |
+
* handshake process to secure the current connection.
|
657 |
+
* @since v18.2.0, v16.17.0
|
658 |
+
*/
|
659 |
+
readonly secureConnectionStart: number;
|
660 |
+
/**
|
661 |
+
* The high resolution millisecond timestamp representing the time immediately before Node.js receives the
|
662 |
+
* first byte of the response from the server.
|
663 |
+
* @since v18.2.0, v16.17.0
|
664 |
+
*/
|
665 |
+
readonly requestStart: number;
|
666 |
+
/**
|
667 |
+
* The high resolution millisecond timestamp representing the time immediately after Node.js receives the
|
668 |
+
* last byte of the resource or immediately before the transport connection is closed, whichever comes first.
|
669 |
+
* @since v18.2.0, v16.17.0
|
670 |
+
*/
|
671 |
+
readonly responseEnd: number;
|
672 |
+
/**
|
673 |
+
* A number representing the size (in octets) of the fetched resource. The size includes the response header
|
674 |
+
* fields plus the response payload body.
|
675 |
+
* @since v18.2.0, v16.17.0
|
676 |
+
*/
|
677 |
+
readonly transferSize: number;
|
678 |
+
/**
|
679 |
+
* A number representing the size (in octets) received from the fetch (HTTP or cache), of the payload body, before
|
680 |
+
* removing any applied content-codings.
|
681 |
+
* @since v18.2.0, v16.17.0
|
682 |
+
*/
|
683 |
+
readonly encodedBodySize: number;
|
684 |
+
/**
|
685 |
+
* A number representing the size (in octets) received from the fetch (HTTP or cache), of the message body, after
|
686 |
+
* removing any applied content-codings.
|
687 |
+
* @since v18.2.0, v16.17.0
|
688 |
+
*/
|
689 |
+
readonly decodedBodySize: number;
|
690 |
+
/**
|
691 |
+
* Returns a `object` that is the JSON representation of the `PerformanceResourceTiming` object
|
692 |
+
* @since v18.2.0, v16.17.0
|
693 |
+
*/
|
694 |
+
toJSON(): any;
|
695 |
+
}
|
696 |
+
namespace constants {
|
697 |
+
const NODE_PERFORMANCE_GC_MAJOR: number;
|
698 |
+
const NODE_PERFORMANCE_GC_MINOR: number;
|
699 |
+
const NODE_PERFORMANCE_GC_INCREMENTAL: number;
|
700 |
+
const NODE_PERFORMANCE_GC_WEAKCB: number;
|
701 |
+
const NODE_PERFORMANCE_GC_FLAGS_NO: number;
|
702 |
+
const NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED: number;
|
703 |
+
const NODE_PERFORMANCE_GC_FLAGS_FORCED: number;
|
704 |
+
const NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING: number;
|
705 |
+
const NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE: number;
|
706 |
+
const NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY: number;
|
707 |
+
const NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE: number;
|
708 |
+
}
|
709 |
+
const performance: Performance;
|
710 |
+
interface EventLoopMonitorOptions {
|
711 |
+
/**
|
712 |
+
* The sampling rate in milliseconds.
|
713 |
+
* Must be greater than zero.
|
714 |
+
* @default 10
|
715 |
+
*/
|
716 |
+
resolution?: number | undefined;
|
717 |
+
}
|
718 |
+
interface Histogram {
|
719 |
+
/**
|
720 |
+
* The number of samples recorded by the histogram.
|
721 |
+
* @since v17.4.0, v16.14.0
|
722 |
+
*/
|
723 |
+
readonly count: number;
|
724 |
+
/**
|
725 |
+
* The number of samples recorded by the histogram.
|
726 |
+
* v17.4.0, v16.14.0
|
727 |
+
*/
|
728 |
+
readonly countBigInt: bigint;
|
729 |
+
/**
|
730 |
+
* The number of times the event loop delay exceeded the maximum 1 hour event
|
731 |
+
* loop delay threshold.
|
732 |
+
* @since v11.10.0
|
733 |
+
*/
|
734 |
+
readonly exceeds: number;
|
735 |
+
/**
|
736 |
+
* The number of times the event loop delay exceeded the maximum 1 hour event loop delay threshold.
|
737 |
+
* @since v17.4.0, v16.14.0
|
738 |
+
*/
|
739 |
+
readonly exceedsBigInt: bigint;
|
740 |
+
/**
|
741 |
+
* The maximum recorded event loop delay.
|
742 |
+
* @since v11.10.0
|
743 |
+
*/
|
744 |
+
readonly max: number;
|
745 |
+
/**
|
746 |
+
* The maximum recorded event loop delay.
|
747 |
+
* v17.4.0, v16.14.0
|
748 |
+
*/
|
749 |
+
readonly maxBigInt: number;
|
750 |
+
/**
|
751 |
+
* The mean of the recorded event loop delays.
|
752 |
+
* @since v11.10.0
|
753 |
+
*/
|
754 |
+
readonly mean: number;
|
755 |
+
/**
|
756 |
+
* The minimum recorded event loop delay.
|
757 |
+
* @since v11.10.0
|
758 |
+
*/
|
759 |
+
readonly min: number;
|
760 |
+
/**
|
761 |
+
* The minimum recorded event loop delay.
|
762 |
+
* v17.4.0, v16.14.0
|
763 |
+
*/
|
764 |
+
readonly minBigInt: bigint;
|
765 |
+
/**
|
766 |
+
* Returns the value at the given percentile.
|
767 |
+
* @since v11.10.0
|
768 |
+
* @param percentile A percentile value in the range (0, 100].
|
769 |
+
*/
|
770 |
+
percentile(percentile: number): number;
|
771 |
+
/**
|
772 |
+
* Returns the value at the given percentile.
|
773 |
+
* @since v17.4.0, v16.14.0
|
774 |
+
* @param percentile A percentile value in the range (0, 100].
|
775 |
+
*/
|
776 |
+
percentileBigInt(percentile: number): bigint;
|
777 |
+
/**
|
778 |
+
* Returns a `Map` object detailing the accumulated percentile distribution.
|
779 |
+
* @since v11.10.0
|
780 |
+
*/
|
781 |
+
readonly percentiles: Map<number, number>;
|
782 |
+
/**
|
783 |
+
* Returns a `Map` object detailing the accumulated percentile distribution.
|
784 |
+
* @since v17.4.0, v16.14.0
|
785 |
+
*/
|
786 |
+
readonly percentilesBigInt: Map<bigint, bigint>;
|
787 |
+
/**
|
788 |
+
* Resets the collected histogram data.
|
789 |
+
* @since v11.10.0
|
790 |
+
*/
|
791 |
+
reset(): void;
|
792 |
+
/**
|
793 |
+
* The standard deviation of the recorded event loop delays.
|
794 |
+
* @since v11.10.0
|
795 |
+
*/
|
796 |
+
readonly stddev: number;
|
797 |
+
}
|
798 |
+
interface IntervalHistogram extends Histogram {
|
799 |
+
/**
|
800 |
+
* Enables the update interval timer. Returns `true` if the timer was
|
801 |
+
* started, `false` if it was already started.
|
802 |
+
* @since v11.10.0
|
803 |
+
*/
|
804 |
+
enable(): boolean;
|
805 |
+
/**
|
806 |
+
* Disables the update interval timer. Returns `true` if the timer was
|
807 |
+
* stopped, `false` if it was already stopped.
|
808 |
+
* @since v11.10.0
|
809 |
+
*/
|
810 |
+
disable(): boolean;
|
811 |
+
}
|
812 |
+
interface RecordableHistogram extends Histogram {
|
813 |
+
/**
|
814 |
+
* @since v15.9.0, v14.18.0
|
815 |
+
* @param val The amount to record in the histogram.
|
816 |
+
*/
|
817 |
+
record(val: number | bigint): void;
|
818 |
+
/**
|
819 |
+
* Calculates the amount of time (in nanoseconds) that has passed since the
|
820 |
+
* previous call to `recordDelta()` and records that amount in the histogram.
|
821 |
+
* @since v15.9.0, v14.18.0
|
822 |
+
*/
|
823 |
+
recordDelta(): void;
|
824 |
+
/**
|
825 |
+
* Adds the values from `other` to this histogram.
|
826 |
+
* @since v17.4.0, v16.14.0
|
827 |
+
*/
|
828 |
+
add(other: RecordableHistogram): void;
|
829 |
+
}
|
830 |
+
/**
|
831 |
+
* _This property is an extension by Node.js. It is not available in Web browsers._
|
832 |
+
*
|
833 |
+
* Creates an `IntervalHistogram` object that samples and reports the event loop
|
834 |
+
* delay over time. The delays will be reported in nanoseconds.
|
835 |
+
*
|
836 |
+
* Using a timer to detect approximate event loop delay works because the
|
837 |
+
* execution of timers is tied specifically to the lifecycle of the libuv
|
838 |
+
* event loop. That is, a delay in the loop will cause a delay in the execution
|
839 |
+
* of the timer, and those delays are specifically what this API is intended to
|
840 |
+
* detect.
|
841 |
+
*
|
842 |
+
* ```js
|
843 |
+
* import { monitorEventLoopDelay } from 'node:perf_hooks';
|
844 |
+
* const h = monitorEventLoopDelay({ resolution: 20 });
|
845 |
+
* h.enable();
|
846 |
+
* // Do something.
|
847 |
+
* h.disable();
|
848 |
+
* console.log(h.min);
|
849 |
+
* console.log(h.max);
|
850 |
+
* console.log(h.mean);
|
851 |
+
* console.log(h.stddev);
|
852 |
+
* console.log(h.percentiles);
|
853 |
+
* console.log(h.percentile(50));
|
854 |
+
* console.log(h.percentile(99));
|
855 |
+
* ```
|
856 |
+
* @since v11.10.0
|
857 |
+
*/
|
858 |
+
function monitorEventLoopDelay(options?: EventLoopMonitorOptions): IntervalHistogram;
|
859 |
+
interface CreateHistogramOptions {
|
860 |
+
/**
|
861 |
+
* The minimum recordable value. Must be an integer value greater than 0.
|
862 |
+
* @default 1
|
863 |
+
*/
|
864 |
+
min?: number | bigint | undefined;
|
865 |
+
/**
|
866 |
+
* The maximum recordable value. Must be an integer value greater than min.
|
867 |
+
* @default Number.MAX_SAFE_INTEGER
|
868 |
+
*/
|
869 |
+
max?: number | bigint | undefined;
|
870 |
+
/**
|
871 |
+
* The number of accuracy digits. Must be a number between 1 and 5.
|
872 |
+
* @default 3
|
873 |
+
*/
|
874 |
+
figures?: number | undefined;
|
875 |
+
}
|
876 |
+
/**
|
877 |
+
* Returns a `RecordableHistogram`.
|
878 |
+
* @since v15.9.0, v14.18.0
|
879 |
+
*/
|
880 |
+
function createHistogram(options?: CreateHistogramOptions): RecordableHistogram;
|
881 |
+
import {
|
882 |
+
performance as _performance,
|
883 |
+
PerformanceEntry as _PerformanceEntry,
|
884 |
+
PerformanceMark as _PerformanceMark,
|
885 |
+
PerformanceMeasure as _PerformanceMeasure,
|
886 |
+
PerformanceObserver as _PerformanceObserver,
|
887 |
+
PerformanceObserverEntryList as _PerformanceObserverEntryList,
|
888 |
+
PerformanceResourceTiming as _PerformanceResourceTiming,
|
889 |
+
} from "perf_hooks";
|
890 |
+
global {
|
891 |
+
/**
|
892 |
+
* `PerformanceEntry` is a global reference for `import { PerformanceEntry } from 'node:perf_hooks'`
|
893 |
+
* @see https://nodejs.org/docs/latest-v22.x/api/globals.html#performanceentry
|
894 |
+
* @since v19.0.0
|
895 |
+
*/
|
896 |
+
var PerformanceEntry: typeof globalThis extends {
|
897 |
+
onmessage: any;
|
898 |
+
PerformanceEntry: infer T;
|
899 |
+
} ? T
|
900 |
+
: typeof _PerformanceEntry;
|
901 |
+
/**
|
902 |
+
* `PerformanceMark` is a global reference for `import { PerformanceMark } from 'node:perf_hooks'`
|
903 |
+
* @see https://nodejs.org/docs/latest-v22.x/api/globals.html#performancemark
|
904 |
+
* @since v19.0.0
|
905 |
+
*/
|
906 |
+
var PerformanceMark: typeof globalThis extends {
|
907 |
+
onmessage: any;
|
908 |
+
PerformanceMark: infer T;
|
909 |
+
} ? T
|
910 |
+
: typeof _PerformanceMark;
|
911 |
+
/**
|
912 |
+
* `PerformanceMeasure` is a global reference for `import { PerformanceMeasure } from 'node:perf_hooks'`
|
913 |
+
* @see https://nodejs.org/docs/latest-v22.x/api/globals.html#performancemeasure
|
914 |
+
* @since v19.0.0
|
915 |
+
*/
|
916 |
+
var PerformanceMeasure: typeof globalThis extends {
|
917 |
+
onmessage: any;
|
918 |
+
PerformanceMeasure: infer T;
|
919 |
+
} ? T
|
920 |
+
: typeof _PerformanceMeasure;
|
921 |
+
/**
|
922 |
+
* `PerformanceObserver` is a global reference for `import { PerformanceObserver } from 'node:perf_hooks'`
|
923 |
+
* @see https://nodejs.org/docs/latest-v22.x/api/globals.html#performanceobserver
|
924 |
+
* @since v19.0.0
|
925 |
+
*/
|
926 |
+
var PerformanceObserver: typeof globalThis extends {
|
927 |
+
onmessage: any;
|
928 |
+
PerformanceObserver: infer T;
|
929 |
+
} ? T
|
930 |
+
: typeof _PerformanceObserver;
|
931 |
+
/**
|
932 |
+
* `PerformanceObserverEntryList` is a global reference for `import { PerformanceObserverEntryList } from 'node:perf_hooks'`
|
933 |
+
* @see https://nodejs.org/docs/latest-v22.x/api/globals.html#performanceobserverentrylist
|
934 |
+
* @since v19.0.0
|
935 |
+
*/
|
936 |
+
var PerformanceObserverEntryList: typeof globalThis extends {
|
937 |
+
onmessage: any;
|
938 |
+
PerformanceObserverEntryList: infer T;
|
939 |
+
} ? T
|
940 |
+
: typeof _PerformanceObserverEntryList;
|
941 |
+
/**
|
942 |
+
* `PerformanceResourceTiming` is a global reference for `import { PerformanceResourceTiming } from 'node:perf_hooks'`
|
943 |
+
* @see https://nodejs.org/docs/latest-v22.x/api/globals.html#performanceresourcetiming
|
944 |
+
* @since v19.0.0
|
945 |
+
*/
|
946 |
+
var PerformanceResourceTiming: typeof globalThis extends {
|
947 |
+
onmessage: any;
|
948 |
+
PerformanceResourceTiming: infer T;
|
949 |
+
} ? T
|
950 |
+
: typeof _PerformanceResourceTiming;
|
951 |
+
/**
|
952 |
+
* `performance` is a global reference for `import { performance } from 'node:perf_hooks'`
|
953 |
+
* @see https://nodejs.org/docs/latest-v22.x/api/globals.html#performance
|
954 |
+
* @since v16.0.0
|
955 |
+
*/
|
956 |
+
var performance: typeof globalThis extends {
|
957 |
+
onmessage: any;
|
958 |
+
performance: infer T;
|
959 |
+
} ? T
|
960 |
+
: typeof _performance;
|
961 |
+
}
|
962 |
+
}
|
963 |
+
declare module "node:perf_hooks" {
|
964 |
+
export * from "perf_hooks";
|
965 |
+
}
|