Spaces:
Paused
Paused
Upload 994 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Dockerfile +8 -0
- node_modules/.DS_Store +0 -0
- node_modules/.package-lock.json +1078 -0
- node_modules/@socket.io/component-emitter/LICENSE +24 -0
- node_modules/@socket.io/component-emitter/Readme.md +79 -0
- node_modules/@socket.io/component-emitter/lib/cjs/index.d.ts +179 -0
- node_modules/@socket.io/component-emitter/lib/cjs/index.js +176 -0
- node_modules/@socket.io/component-emitter/lib/cjs/package.json +4 -0
- node_modules/@socket.io/component-emitter/lib/esm/index.d.ts +179 -0
- node_modules/@socket.io/component-emitter/lib/esm/index.js +169 -0
- node_modules/@socket.io/component-emitter/lib/esm/package.json +4 -0
- node_modules/@socket.io/component-emitter/package.json +28 -0
- node_modules/@types/.DS_Store +0 -0
- node_modules/@types/cors/LICENSE +21 -0
- node_modules/@types/cors/README.md +75 -0
- node_modules/@types/cors/index.d.ts +56 -0
- node_modules/@types/cors/package.json +38 -0
- node_modules/@types/node/LICENSE +21 -0
- node_modules/@types/node/README.md +15 -0
- node_modules/@types/node/assert.d.ts +950 -0
- node_modules/@types/node/assert/strict.d.ts +59 -0
- node_modules/@types/node/async_hooks.d.ts +711 -0
- node_modules/@types/node/buffer.buffer.d.ts +466 -0
- node_modules/@types/node/buffer.d.ts +1765 -0
- node_modules/@types/node/child_process.d.ts +1366 -0
- node_modules/@types/node/cluster.d.ts +432 -0
- node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- node_modules/@types/node/console.d.ts +93 -0
- node_modules/@types/node/constants.d.ts +14 -0
- node_modules/@types/node/crypto.d.ts +0 -0
- node_modules/@types/node/dgram.d.ts +537 -0
- node_modules/@types/node/diagnostics_channel.d.ts +552 -0
- node_modules/@types/node/dns.d.ts +876 -0
- node_modules/@types/node/dns/promises.d.ts +497 -0
- node_modules/@types/node/domain.d.ts +150 -0
- node_modules/@types/node/events.d.ts +1008 -0
- node_modules/@types/node/fs.d.ts +0 -0
- node_modules/@types/node/fs/promises.d.ts +1468 -0
- node_modules/@types/node/globals.d.ts +150 -0
- node_modules/@types/node/globals.typedarray.d.ts +101 -0
- node_modules/@types/node/http.d.ts +2147 -0
- node_modules/@types/node/http2.d.ts +0 -0
- node_modules/@types/node/https.d.ts +400 -0
- node_modules/@types/node/index.d.ts +117 -0
- node_modules/@types/node/inspector.d.ts +264 -0
- node_modules/@types/node/inspector.generated.d.ts +0 -0
- node_modules/@types/node/inspector/promises.d.ts +35 -0
- node_modules/@types/node/module.d.ts +755 -0
- node_modules/@types/node/net.d.ts +970 -0
- node_modules/@types/node/os.d.ts +498 -0
Dockerfile
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:18-alpine
|
| 2 |
+
WORKDIR /app
|
| 3 |
+
COPY package*.json ./
|
| 4 |
+
RUN npm ci --omit=dev
|
| 5 |
+
COPY . .
|
| 6 |
+
EXPOSE 7860
|
| 7 |
+
ENV PORT=7860
|
| 8 |
+
CMD ["node", "server.js"]
|
node_modules/.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
node_modules/.package-lock.json
ADDED
|
@@ -0,0 +1,1078 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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0",
|
| 4 |
+
"lockfileVersion": 3,
|
| 5 |
+
"requires": true,
|
| 6 |
+
"packages": {
|
| 7 |
+
"node_modules/@socket.io/component-emitter": {
|
| 8 |
+
"version": "3.1.2",
|
| 9 |
+
"resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz",
|
| 10 |
+
"integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==",
|
| 11 |
+
"license": "MIT"
|
| 12 |
+
},
|
| 13 |
+
"node_modules/@types/cors": {
|
| 14 |
+
"version": "2.8.19",
|
| 15 |
+
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.19.tgz",
|
| 16 |
+
"integrity": "sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==",
|
| 17 |
+
"license": "MIT",
|
| 18 |
+
"dependencies": {
|
| 19 |
+
"@types/node": "*"
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
"node_modules/@types/node": {
|
| 23 |
+
"version": "25.9.3",
|
| 24 |
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.9.3.tgz",
|
| 25 |
+
"integrity": "sha512-603BddQMv3pUcr4U2dhujk83N2tTDVr/34wII2B6bJy6g+8WD6yUb11jszNs0gdi4PesVWl7ABt8nYMVpnLUcg==",
|
| 26 |
+
"license": "MIT",
|
| 27 |
+
"dependencies": {
|
| 28 |
+
"undici-types": ">=7.24.0 <7.24.7"
|
| 29 |
+
}
|
| 30 |
+
},
|
| 31 |
+
"node_modules/@types/ws": {
|
| 32 |
+
"version": "8.18.1",
|
| 33 |
+
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
|
| 34 |
+
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
|
| 35 |
+
"license": "MIT",
|
| 36 |
+
"dependencies": {
|
| 37 |
+
"@types/node": "*"
|
| 38 |
+
}
|
| 39 |
+
},
|
| 40 |
+
"node_modules/accepts": {
|
| 41 |
+
"version": "1.3.8",
|
| 42 |
+
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
|
| 43 |
+
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
|
| 44 |
+
"license": "MIT",
|
| 45 |
+
"dependencies": {
|
| 46 |
+
"mime-types": "~2.1.34",
|
| 47 |
+
"negotiator": "0.6.3"
|
| 48 |
+
},
|
| 49 |
+
"engines": {
|
| 50 |
+
"node": ">= 0.6"
|
| 51 |
+
}
|
| 52 |
+
},
|
| 53 |
+
"node_modules/array-flatten": {
|
| 54 |
+
"version": "1.1.1",
|
| 55 |
+
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
| 56 |
+
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
|
| 57 |
+
"license": "MIT"
|
| 58 |
+
},
|
| 59 |
+
"node_modules/base64id": {
|
| 60 |
+
"version": "2.0.0",
|
| 61 |
+
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
| 62 |
+
"integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==",
|
| 63 |
+
"license": "MIT",
|
| 64 |
+
"engines": {
|
| 65 |
+
"node": "^4.5.0 || >= 5.9"
|
| 66 |
+
}
|
| 67 |
+
},
|
| 68 |
+
"node_modules/body-parser": {
|
| 69 |
+
"version": "1.20.5",
|
| 70 |
+
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.5.tgz",
|
| 71 |
+
"integrity": "sha512-3grm+/2tUOvu2cjJkvsIxrv/wVpfXQW4PsQHYm7yk4vfpu7Ekl6nEsYBoJUL6qDwZUx8wUhQ8tR2qz+ad9c9OA==",
|
| 72 |
+
"license": "MIT",
|
| 73 |
+
"dependencies": {
|
| 74 |
+
"bytes": "~3.1.2",
|
| 75 |
+
"content-type": "~1.0.5",
|
| 76 |
+
"debug": "2.6.9",
|
| 77 |
+
"depd": "2.0.0",
|
| 78 |
+
"destroy": "~1.2.0",
|
| 79 |
+
"http-errors": "~2.0.1",
|
| 80 |
+
"iconv-lite": "~0.4.24",
|
| 81 |
+
"on-finished": "~2.4.1",
|
| 82 |
+
"qs": "~6.15.1",
|
| 83 |
+
"raw-body": "~2.5.3",
|
| 84 |
+
"type-is": "~1.6.18",
|
| 85 |
+
"unpipe": "~1.0.0"
|
| 86 |
+
},
|
| 87 |
+
"engines": {
|
| 88 |
+
"node": ">= 0.8",
|
| 89 |
+
"npm": "1.2.8000 || >= 1.4.16"
|
| 90 |
+
}
|
| 91 |
+
},
|
| 92 |
+
"node_modules/bytes": {
|
| 93 |
+
"version": "3.1.2",
|
| 94 |
+
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
| 95 |
+
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
|
| 96 |
+
"license": "MIT",
|
| 97 |
+
"engines": {
|
| 98 |
+
"node": ">= 0.8"
|
| 99 |
+
}
|
| 100 |
+
},
|
| 101 |
+
"node_modules/call-bind-apply-helpers": {
|
| 102 |
+
"version": "1.0.2",
|
| 103 |
+
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
| 104 |
+
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
| 105 |
+
"license": "MIT",
|
| 106 |
+
"dependencies": {
|
| 107 |
+
"es-errors": "^1.3.0",
|
| 108 |
+
"function-bind": "^1.1.2"
|
| 109 |
+
},
|
| 110 |
+
"engines": {
|
| 111 |
+
"node": ">= 0.4"
|
| 112 |
+
}
|
| 113 |
+
},
|
| 114 |
+
"node_modules/call-bound": {
|
| 115 |
+
"version": "1.0.4",
|
| 116 |
+
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
|
| 117 |
+
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
|
| 118 |
+
"license": "MIT",
|
| 119 |
+
"dependencies": {
|
| 120 |
+
"call-bind-apply-helpers": "^1.0.2",
|
| 121 |
+
"get-intrinsic": "^1.3.0"
|
| 122 |
+
},
|
| 123 |
+
"engines": {
|
| 124 |
+
"node": ">= 0.4"
|
| 125 |
+
},
|
| 126 |
+
"funding": {
|
| 127 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 128 |
+
}
|
| 129 |
+
},
|
| 130 |
+
"node_modules/content-disposition": {
|
| 131 |
+
"version": "0.5.4",
|
| 132 |
+
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
| 133 |
+
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
|
| 134 |
+
"license": "MIT",
|
| 135 |
+
"dependencies": {
|
| 136 |
+
"safe-buffer": "5.2.1"
|
| 137 |
+
},
|
| 138 |
+
"engines": {
|
| 139 |
+
"node": ">= 0.6"
|
| 140 |
+
}
|
| 141 |
+
},
|
| 142 |
+
"node_modules/content-type": {
|
| 143 |
+
"version": "1.0.5",
|
| 144 |
+
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
|
| 145 |
+
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
| 146 |
+
"license": "MIT",
|
| 147 |
+
"engines": {
|
| 148 |
+
"node": ">= 0.6"
|
| 149 |
+
}
|
| 150 |
+
},
|
| 151 |
+
"node_modules/cookie": {
|
| 152 |
+
"version": "0.7.2",
|
| 153 |
+
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
| 154 |
+
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
| 155 |
+
"license": "MIT",
|
| 156 |
+
"engines": {
|
| 157 |
+
"node": ">= 0.6"
|
| 158 |
+
}
|
| 159 |
+
},
|
| 160 |
+
"node_modules/cookie-signature": {
|
| 161 |
+
"version": "1.0.7",
|
| 162 |
+
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz",
|
| 163 |
+
"integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==",
|
| 164 |
+
"license": "MIT"
|
| 165 |
+
},
|
| 166 |
+
"node_modules/cors": {
|
| 167 |
+
"version": "2.8.6",
|
| 168 |
+
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz",
|
| 169 |
+
"integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==",
|
| 170 |
+
"license": "MIT",
|
| 171 |
+
"dependencies": {
|
| 172 |
+
"object-assign": "^4",
|
| 173 |
+
"vary": "^1"
|
| 174 |
+
},
|
| 175 |
+
"engines": {
|
| 176 |
+
"node": ">= 0.10"
|
| 177 |
+
},
|
| 178 |
+
"funding": {
|
| 179 |
+
"type": "opencollective",
|
| 180 |
+
"url": "https://opencollective.com/express"
|
| 181 |
+
}
|
| 182 |
+
},
|
| 183 |
+
"node_modules/debug": {
|
| 184 |
+
"version": "2.6.9",
|
| 185 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
| 186 |
+
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
| 187 |
+
"license": "MIT",
|
| 188 |
+
"dependencies": {
|
| 189 |
+
"ms": "2.0.0"
|
| 190 |
+
}
|
| 191 |
+
},
|
| 192 |
+
"node_modules/depd": {
|
| 193 |
+
"version": "2.0.0",
|
| 194 |
+
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
|
| 195 |
+
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
|
| 196 |
+
"license": "MIT",
|
| 197 |
+
"engines": {
|
| 198 |
+
"node": ">= 0.8"
|
| 199 |
+
}
|
| 200 |
+
},
|
| 201 |
+
"node_modules/destroy": {
|
| 202 |
+
"version": "1.2.0",
|
| 203 |
+
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
|
| 204 |
+
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
|
| 205 |
+
"license": "MIT",
|
| 206 |
+
"engines": {
|
| 207 |
+
"node": ">= 0.8",
|
| 208 |
+
"npm": "1.2.8000 || >= 1.4.16"
|
| 209 |
+
}
|
| 210 |
+
},
|
| 211 |
+
"node_modules/dunder-proto": {
|
| 212 |
+
"version": "1.0.1",
|
| 213 |
+
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
| 214 |
+
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
| 215 |
+
"license": "MIT",
|
| 216 |
+
"dependencies": {
|
| 217 |
+
"call-bind-apply-helpers": "^1.0.1",
|
| 218 |
+
"es-errors": "^1.3.0",
|
| 219 |
+
"gopd": "^1.2.0"
|
| 220 |
+
},
|
| 221 |
+
"engines": {
|
| 222 |
+
"node": ">= 0.4"
|
| 223 |
+
}
|
| 224 |
+
},
|
| 225 |
+
"node_modules/ee-first": {
|
| 226 |
+
"version": "1.1.1",
|
| 227 |
+
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
| 228 |
+
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
| 229 |
+
"license": "MIT"
|
| 230 |
+
},
|
| 231 |
+
"node_modules/encodeurl": {
|
| 232 |
+
"version": "2.0.0",
|
| 233 |
+
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
|
| 234 |
+
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
|
| 235 |
+
"license": "MIT",
|
| 236 |
+
"engines": {
|
| 237 |
+
"node": ">= 0.8"
|
| 238 |
+
}
|
| 239 |
+
},
|
| 240 |
+
"node_modules/engine.io": {
|
| 241 |
+
"version": "6.6.8",
|
| 242 |
+
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.8.tgz",
|
| 243 |
+
"integrity": "sha512-2agL3ueZhqxoVrfmntO8yuVj+uNSlIOnhykYHk3Cq0ShYPdUjjUiSJrQvXjq01I9jAuI0Zl2YO8Evv5Mqytm5g==",
|
| 244 |
+
"license": "MIT",
|
| 245 |
+
"dependencies": {
|
| 246 |
+
"@types/cors": "^2.8.12",
|
| 247 |
+
"@types/node": ">=10.0.0",
|
| 248 |
+
"@types/ws": "^8.5.12",
|
| 249 |
+
"accepts": "~1.3.4",
|
| 250 |
+
"base64id": "2.0.0",
|
| 251 |
+
"cookie": "~0.7.2",
|
| 252 |
+
"cors": "~2.8.5",
|
| 253 |
+
"debug": "~4.4.1",
|
| 254 |
+
"engine.io-parser": "~5.2.1",
|
| 255 |
+
"ws": "~8.20.1"
|
| 256 |
+
},
|
| 257 |
+
"engines": {
|
| 258 |
+
"node": ">=10.2.0"
|
| 259 |
+
}
|
| 260 |
+
},
|
| 261 |
+
"node_modules/engine.io-parser": {
|
| 262 |
+
"version": "5.2.3",
|
| 263 |
+
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz",
|
| 264 |
+
"integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==",
|
| 265 |
+
"license": "MIT",
|
| 266 |
+
"engines": {
|
| 267 |
+
"node": ">=10.0.0"
|
| 268 |
+
}
|
| 269 |
+
},
|
| 270 |
+
"node_modules/engine.io/node_modules/debug": {
|
| 271 |
+
"version": "4.4.3",
|
| 272 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
| 273 |
+
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
| 274 |
+
"license": "MIT",
|
| 275 |
+
"dependencies": {
|
| 276 |
+
"ms": "^2.1.3"
|
| 277 |
+
},
|
| 278 |
+
"engines": {
|
| 279 |
+
"node": ">=6.0"
|
| 280 |
+
},
|
| 281 |
+
"peerDependenciesMeta": {
|
| 282 |
+
"supports-color": {
|
| 283 |
+
"optional": true
|
| 284 |
+
}
|
| 285 |
+
}
|
| 286 |
+
},
|
| 287 |
+
"node_modules/engine.io/node_modules/ms": {
|
| 288 |
+
"version": "2.1.3",
|
| 289 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
| 290 |
+
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
| 291 |
+
"license": "MIT"
|
| 292 |
+
},
|
| 293 |
+
"node_modules/es-define-property": {
|
| 294 |
+
"version": "1.0.1",
|
| 295 |
+
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
| 296 |
+
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
| 297 |
+
"license": "MIT",
|
| 298 |
+
"engines": {
|
| 299 |
+
"node": ">= 0.4"
|
| 300 |
+
}
|
| 301 |
+
},
|
| 302 |
+
"node_modules/es-errors": {
|
| 303 |
+
"version": "1.3.0",
|
| 304 |
+
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
| 305 |
+
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
| 306 |
+
"license": "MIT",
|
| 307 |
+
"engines": {
|
| 308 |
+
"node": ">= 0.4"
|
| 309 |
+
}
|
| 310 |
+
},
|
| 311 |
+
"node_modules/es-object-atoms": {
|
| 312 |
+
"version": "1.1.2",
|
| 313 |
+
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz",
|
| 314 |
+
"integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==",
|
| 315 |
+
"license": "MIT",
|
| 316 |
+
"dependencies": {
|
| 317 |
+
"es-errors": "^1.3.0"
|
| 318 |
+
},
|
| 319 |
+
"engines": {
|
| 320 |
+
"node": ">= 0.4"
|
| 321 |
+
}
|
| 322 |
+
},
|
| 323 |
+
"node_modules/escape-html": {
|
| 324 |
+
"version": "1.0.3",
|
| 325 |
+
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
| 326 |
+
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
|
| 327 |
+
"license": "MIT"
|
| 328 |
+
},
|
| 329 |
+
"node_modules/etag": {
|
| 330 |
+
"version": "1.8.1",
|
| 331 |
+
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
| 332 |
+
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
|
| 333 |
+
"license": "MIT",
|
| 334 |
+
"engines": {
|
| 335 |
+
"node": ">= 0.6"
|
| 336 |
+
}
|
| 337 |
+
},
|
| 338 |
+
"node_modules/express": {
|
| 339 |
+
"version": "4.22.2",
|
| 340 |
+
"resolved": "https://registry.npmjs.org/express/-/express-4.22.2.tgz",
|
| 341 |
+
"integrity": "sha512-IuL+Elrou2ZvCFHs18/CIzy2Nzvo25nZ1/D2eIZlz7c+QUayAcYoiM2BthCjs+EBHVpjYjcuLDAiCWgeIX3X1Q==",
|
| 342 |
+
"license": "MIT",
|
| 343 |
+
"dependencies": {
|
| 344 |
+
"accepts": "~1.3.8",
|
| 345 |
+
"array-flatten": "1.1.1",
|
| 346 |
+
"body-parser": "~1.20.5",
|
| 347 |
+
"content-disposition": "~0.5.4",
|
| 348 |
+
"content-type": "~1.0.4",
|
| 349 |
+
"cookie": "~0.7.1",
|
| 350 |
+
"cookie-signature": "~1.0.6",
|
| 351 |
+
"debug": "2.6.9",
|
| 352 |
+
"depd": "2.0.0",
|
| 353 |
+
"encodeurl": "~2.0.0",
|
| 354 |
+
"escape-html": "~1.0.3",
|
| 355 |
+
"etag": "~1.8.1",
|
| 356 |
+
"finalhandler": "~1.3.1",
|
| 357 |
+
"fresh": "~0.5.2",
|
| 358 |
+
"http-errors": "~2.0.0",
|
| 359 |
+
"merge-descriptors": "1.0.3",
|
| 360 |
+
"methods": "~1.1.2",
|
| 361 |
+
"on-finished": "~2.4.1",
|
| 362 |
+
"parseurl": "~1.3.3",
|
| 363 |
+
"path-to-regexp": "~0.1.12",
|
| 364 |
+
"proxy-addr": "~2.0.7",
|
| 365 |
+
"qs": "~6.15.1",
|
| 366 |
+
"range-parser": "~1.2.1",
|
| 367 |
+
"safe-buffer": "5.2.1",
|
| 368 |
+
"send": "~0.19.0",
|
| 369 |
+
"serve-static": "~1.16.2",
|
| 370 |
+
"setprototypeof": "1.2.0",
|
| 371 |
+
"statuses": "~2.0.1",
|
| 372 |
+
"type-is": "~1.6.18",
|
| 373 |
+
"utils-merge": "1.0.1",
|
| 374 |
+
"vary": "~1.1.2"
|
| 375 |
+
},
|
| 376 |
+
"engines": {
|
| 377 |
+
"node": ">= 0.10.0"
|
| 378 |
+
},
|
| 379 |
+
"funding": {
|
| 380 |
+
"type": "opencollective",
|
| 381 |
+
"url": "https://opencollective.com/express"
|
| 382 |
+
}
|
| 383 |
+
},
|
| 384 |
+
"node_modules/finalhandler": {
|
| 385 |
+
"version": "1.3.2",
|
| 386 |
+
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz",
|
| 387 |
+
"integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==",
|
| 388 |
+
"license": "MIT",
|
| 389 |
+
"dependencies": {
|
| 390 |
+
"debug": "2.6.9",
|
| 391 |
+
"encodeurl": "~2.0.0",
|
| 392 |
+
"escape-html": "~1.0.3",
|
| 393 |
+
"on-finished": "~2.4.1",
|
| 394 |
+
"parseurl": "~1.3.3",
|
| 395 |
+
"statuses": "~2.0.2",
|
| 396 |
+
"unpipe": "~1.0.0"
|
| 397 |
+
},
|
| 398 |
+
"engines": {
|
| 399 |
+
"node": ">= 0.8"
|
| 400 |
+
}
|
| 401 |
+
},
|
| 402 |
+
"node_modules/forwarded": {
|
| 403 |
+
"version": "0.2.0",
|
| 404 |
+
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
| 405 |
+
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
| 406 |
+
"license": "MIT",
|
| 407 |
+
"engines": {
|
| 408 |
+
"node": ">= 0.6"
|
| 409 |
+
}
|
| 410 |
+
},
|
| 411 |
+
"node_modules/fresh": {
|
| 412 |
+
"version": "0.5.2",
|
| 413 |
+
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
| 414 |
+
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
|
| 415 |
+
"license": "MIT",
|
| 416 |
+
"engines": {
|
| 417 |
+
"node": ">= 0.6"
|
| 418 |
+
}
|
| 419 |
+
},
|
| 420 |
+
"node_modules/function-bind": {
|
| 421 |
+
"version": "1.1.2",
|
| 422 |
+
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
| 423 |
+
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
| 424 |
+
"license": "MIT",
|
| 425 |
+
"funding": {
|
| 426 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 427 |
+
}
|
| 428 |
+
},
|
| 429 |
+
"node_modules/get-intrinsic": {
|
| 430 |
+
"version": "1.3.0",
|
| 431 |
+
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
| 432 |
+
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
| 433 |
+
"license": "MIT",
|
| 434 |
+
"dependencies": {
|
| 435 |
+
"call-bind-apply-helpers": "^1.0.2",
|
| 436 |
+
"es-define-property": "^1.0.1",
|
| 437 |
+
"es-errors": "^1.3.0",
|
| 438 |
+
"es-object-atoms": "^1.1.1",
|
| 439 |
+
"function-bind": "^1.1.2",
|
| 440 |
+
"get-proto": "^1.0.1",
|
| 441 |
+
"gopd": "^1.2.0",
|
| 442 |
+
"has-symbols": "^1.1.0",
|
| 443 |
+
"hasown": "^2.0.2",
|
| 444 |
+
"math-intrinsics": "^1.1.0"
|
| 445 |
+
},
|
| 446 |
+
"engines": {
|
| 447 |
+
"node": ">= 0.4"
|
| 448 |
+
},
|
| 449 |
+
"funding": {
|
| 450 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 451 |
+
}
|
| 452 |
+
},
|
| 453 |
+
"node_modules/get-proto": {
|
| 454 |
+
"version": "1.0.1",
|
| 455 |
+
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
| 456 |
+
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
| 457 |
+
"license": "MIT",
|
| 458 |
+
"dependencies": {
|
| 459 |
+
"dunder-proto": "^1.0.1",
|
| 460 |
+
"es-object-atoms": "^1.0.0"
|
| 461 |
+
},
|
| 462 |
+
"engines": {
|
| 463 |
+
"node": ">= 0.4"
|
| 464 |
+
}
|
| 465 |
+
},
|
| 466 |
+
"node_modules/gopd": {
|
| 467 |
+
"version": "1.2.0",
|
| 468 |
+
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
| 469 |
+
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
| 470 |
+
"license": "MIT",
|
| 471 |
+
"engines": {
|
| 472 |
+
"node": ">= 0.4"
|
| 473 |
+
},
|
| 474 |
+
"funding": {
|
| 475 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 476 |
+
}
|
| 477 |
+
},
|
| 478 |
+
"node_modules/has-symbols": {
|
| 479 |
+
"version": "1.1.0",
|
| 480 |
+
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
| 481 |
+
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
| 482 |
+
"license": "MIT",
|
| 483 |
+
"engines": {
|
| 484 |
+
"node": ">= 0.4"
|
| 485 |
+
},
|
| 486 |
+
"funding": {
|
| 487 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 488 |
+
}
|
| 489 |
+
},
|
| 490 |
+
"node_modules/hasown": {
|
| 491 |
+
"version": "2.0.4",
|
| 492 |
+
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
|
| 493 |
+
"integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
|
| 494 |
+
"license": "MIT",
|
| 495 |
+
"dependencies": {
|
| 496 |
+
"function-bind": "^1.1.2"
|
| 497 |
+
},
|
| 498 |
+
"engines": {
|
| 499 |
+
"node": ">= 0.4"
|
| 500 |
+
}
|
| 501 |
+
},
|
| 502 |
+
"node_modules/http-errors": {
|
| 503 |
+
"version": "2.0.1",
|
| 504 |
+
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
|
| 505 |
+
"integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
|
| 506 |
+
"license": "MIT",
|
| 507 |
+
"dependencies": {
|
| 508 |
+
"depd": "~2.0.0",
|
| 509 |
+
"inherits": "~2.0.4",
|
| 510 |
+
"setprototypeof": "~1.2.0",
|
| 511 |
+
"statuses": "~2.0.2",
|
| 512 |
+
"toidentifier": "~1.0.1"
|
| 513 |
+
},
|
| 514 |
+
"engines": {
|
| 515 |
+
"node": ">= 0.8"
|
| 516 |
+
},
|
| 517 |
+
"funding": {
|
| 518 |
+
"type": "opencollective",
|
| 519 |
+
"url": "https://opencollective.com/express"
|
| 520 |
+
}
|
| 521 |
+
},
|
| 522 |
+
"node_modules/iconv-lite": {
|
| 523 |
+
"version": "0.4.24",
|
| 524 |
+
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
| 525 |
+
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
| 526 |
+
"license": "MIT",
|
| 527 |
+
"dependencies": {
|
| 528 |
+
"safer-buffer": ">= 2.1.2 < 3"
|
| 529 |
+
},
|
| 530 |
+
"engines": {
|
| 531 |
+
"node": ">=0.10.0"
|
| 532 |
+
}
|
| 533 |
+
},
|
| 534 |
+
"node_modules/inherits": {
|
| 535 |
+
"version": "2.0.4",
|
| 536 |
+
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
| 537 |
+
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
| 538 |
+
"license": "ISC"
|
| 539 |
+
},
|
| 540 |
+
"node_modules/ipaddr.js": {
|
| 541 |
+
"version": "1.9.1",
|
| 542 |
+
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
| 543 |
+
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
| 544 |
+
"license": "MIT",
|
| 545 |
+
"engines": {
|
| 546 |
+
"node": ">= 0.10"
|
| 547 |
+
}
|
| 548 |
+
},
|
| 549 |
+
"node_modules/math-intrinsics": {
|
| 550 |
+
"version": "1.1.0",
|
| 551 |
+
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
| 552 |
+
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
| 553 |
+
"license": "MIT",
|
| 554 |
+
"engines": {
|
| 555 |
+
"node": ">= 0.4"
|
| 556 |
+
}
|
| 557 |
+
},
|
| 558 |
+
"node_modules/media-typer": {
|
| 559 |
+
"version": "0.3.0",
|
| 560 |
+
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
| 561 |
+
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
|
| 562 |
+
"license": "MIT",
|
| 563 |
+
"engines": {
|
| 564 |
+
"node": ">= 0.6"
|
| 565 |
+
}
|
| 566 |
+
},
|
| 567 |
+
"node_modules/merge-descriptors": {
|
| 568 |
+
"version": "1.0.3",
|
| 569 |
+
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
|
| 570 |
+
"integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
|
| 571 |
+
"license": "MIT",
|
| 572 |
+
"funding": {
|
| 573 |
+
"url": "https://github.com/sponsors/sindresorhus"
|
| 574 |
+
}
|
| 575 |
+
},
|
| 576 |
+
"node_modules/methods": {
|
| 577 |
+
"version": "1.1.2",
|
| 578 |
+
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
|
| 579 |
+
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
|
| 580 |
+
"license": "MIT",
|
| 581 |
+
"engines": {
|
| 582 |
+
"node": ">= 0.6"
|
| 583 |
+
}
|
| 584 |
+
},
|
| 585 |
+
"node_modules/mime": {
|
| 586 |
+
"version": "1.6.0",
|
| 587 |
+
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
|
| 588 |
+
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
|
| 589 |
+
"license": "MIT",
|
| 590 |
+
"bin": {
|
| 591 |
+
"mime": "cli.js"
|
| 592 |
+
},
|
| 593 |
+
"engines": {
|
| 594 |
+
"node": ">=4"
|
| 595 |
+
}
|
| 596 |
+
},
|
| 597 |
+
"node_modules/mime-db": {
|
| 598 |
+
"version": "1.52.0",
|
| 599 |
+
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
| 600 |
+
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
| 601 |
+
"license": "MIT",
|
| 602 |
+
"engines": {
|
| 603 |
+
"node": ">= 0.6"
|
| 604 |
+
}
|
| 605 |
+
},
|
| 606 |
+
"node_modules/mime-types": {
|
| 607 |
+
"version": "2.1.35",
|
| 608 |
+
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
| 609 |
+
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
| 610 |
+
"license": "MIT",
|
| 611 |
+
"dependencies": {
|
| 612 |
+
"mime-db": "1.52.0"
|
| 613 |
+
},
|
| 614 |
+
"engines": {
|
| 615 |
+
"node": ">= 0.6"
|
| 616 |
+
}
|
| 617 |
+
},
|
| 618 |
+
"node_modules/ms": {
|
| 619 |
+
"version": "2.0.0",
|
| 620 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
| 621 |
+
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
| 622 |
+
"license": "MIT"
|
| 623 |
+
},
|
| 624 |
+
"node_modules/negotiator": {
|
| 625 |
+
"version": "0.6.3",
|
| 626 |
+
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
|
| 627 |
+
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
|
| 628 |
+
"license": "MIT",
|
| 629 |
+
"engines": {
|
| 630 |
+
"node": ">= 0.6"
|
| 631 |
+
}
|
| 632 |
+
},
|
| 633 |
+
"node_modules/object-assign": {
|
| 634 |
+
"version": "4.1.1",
|
| 635 |
+
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
| 636 |
+
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
| 637 |
+
"license": "MIT",
|
| 638 |
+
"engines": {
|
| 639 |
+
"node": ">=0.10.0"
|
| 640 |
+
}
|
| 641 |
+
},
|
| 642 |
+
"node_modules/object-inspect": {
|
| 643 |
+
"version": "1.13.4",
|
| 644 |
+
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
|
| 645 |
+
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
|
| 646 |
+
"license": "MIT",
|
| 647 |
+
"engines": {
|
| 648 |
+
"node": ">= 0.4"
|
| 649 |
+
},
|
| 650 |
+
"funding": {
|
| 651 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 652 |
+
}
|
| 653 |
+
},
|
| 654 |
+
"node_modules/on-finished": {
|
| 655 |
+
"version": "2.4.1",
|
| 656 |
+
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
|
| 657 |
+
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
|
| 658 |
+
"license": "MIT",
|
| 659 |
+
"dependencies": {
|
| 660 |
+
"ee-first": "1.1.1"
|
| 661 |
+
},
|
| 662 |
+
"engines": {
|
| 663 |
+
"node": ">= 0.8"
|
| 664 |
+
}
|
| 665 |
+
},
|
| 666 |
+
"node_modules/parseurl": {
|
| 667 |
+
"version": "1.3.3",
|
| 668 |
+
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
| 669 |
+
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
|
| 670 |
+
"license": "MIT",
|
| 671 |
+
"engines": {
|
| 672 |
+
"node": ">= 0.8"
|
| 673 |
+
}
|
| 674 |
+
},
|
| 675 |
+
"node_modules/path-to-regexp": {
|
| 676 |
+
"version": "0.1.13",
|
| 677 |
+
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.13.tgz",
|
| 678 |
+
"integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==",
|
| 679 |
+
"license": "MIT"
|
| 680 |
+
},
|
| 681 |
+
"node_modules/proxy-addr": {
|
| 682 |
+
"version": "2.0.7",
|
| 683 |
+
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
| 684 |
+
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
| 685 |
+
"license": "MIT",
|
| 686 |
+
"dependencies": {
|
| 687 |
+
"forwarded": "0.2.0",
|
| 688 |
+
"ipaddr.js": "1.9.1"
|
| 689 |
+
},
|
| 690 |
+
"engines": {
|
| 691 |
+
"node": ">= 0.10"
|
| 692 |
+
}
|
| 693 |
+
},
|
| 694 |
+
"node_modules/qs": {
|
| 695 |
+
"version": "6.15.2",
|
| 696 |
+
"resolved": "https://registry.npmjs.org/qs/-/qs-6.15.2.tgz",
|
| 697 |
+
"integrity": "sha512-Rzq0KEyX/w/tEybncDgdkZrJgVUsUMk3xjh3t5bv3S1HTAtg+uOYt72+ZfwiQwKdysThkTBdL/rTi6HDmX9Ddw==",
|
| 698 |
+
"license": "BSD-3-Clause",
|
| 699 |
+
"dependencies": {
|
| 700 |
+
"side-channel": "^1.1.0"
|
| 701 |
+
},
|
| 702 |
+
"engines": {
|
| 703 |
+
"node": ">=0.6"
|
| 704 |
+
},
|
| 705 |
+
"funding": {
|
| 706 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 707 |
+
}
|
| 708 |
+
},
|
| 709 |
+
"node_modules/range-parser": {
|
| 710 |
+
"version": "1.2.1",
|
| 711 |
+
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
| 712 |
+
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
|
| 713 |
+
"license": "MIT",
|
| 714 |
+
"engines": {
|
| 715 |
+
"node": ">= 0.6"
|
| 716 |
+
}
|
| 717 |
+
},
|
| 718 |
+
"node_modules/raw-body": {
|
| 719 |
+
"version": "2.5.3",
|
| 720 |
+
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz",
|
| 721 |
+
"integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==",
|
| 722 |
+
"license": "MIT",
|
| 723 |
+
"dependencies": {
|
| 724 |
+
"bytes": "~3.1.2",
|
| 725 |
+
"http-errors": "~2.0.1",
|
| 726 |
+
"iconv-lite": "~0.4.24",
|
| 727 |
+
"unpipe": "~1.0.0"
|
| 728 |
+
},
|
| 729 |
+
"engines": {
|
| 730 |
+
"node": ">= 0.8"
|
| 731 |
+
}
|
| 732 |
+
},
|
| 733 |
+
"node_modules/safe-buffer": {
|
| 734 |
+
"version": "5.2.1",
|
| 735 |
+
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
| 736 |
+
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
| 737 |
+
"funding": [
|
| 738 |
+
{
|
| 739 |
+
"type": "github",
|
| 740 |
+
"url": "https://github.com/sponsors/feross"
|
| 741 |
+
},
|
| 742 |
+
{
|
| 743 |
+
"type": "patreon",
|
| 744 |
+
"url": "https://www.patreon.com/feross"
|
| 745 |
+
},
|
| 746 |
+
{
|
| 747 |
+
"type": "consulting",
|
| 748 |
+
"url": "https://feross.org/support"
|
| 749 |
+
}
|
| 750 |
+
],
|
| 751 |
+
"license": "MIT"
|
| 752 |
+
},
|
| 753 |
+
"node_modules/safer-buffer": {
|
| 754 |
+
"version": "2.1.2",
|
| 755 |
+
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
| 756 |
+
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
| 757 |
+
"license": "MIT"
|
| 758 |
+
},
|
| 759 |
+
"node_modules/send": {
|
| 760 |
+
"version": "0.19.2",
|
| 761 |
+
"resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz",
|
| 762 |
+
"integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==",
|
| 763 |
+
"license": "MIT",
|
| 764 |
+
"dependencies": {
|
| 765 |
+
"debug": "2.6.9",
|
| 766 |
+
"depd": "2.0.0",
|
| 767 |
+
"destroy": "1.2.0",
|
| 768 |
+
"encodeurl": "~2.0.0",
|
| 769 |
+
"escape-html": "~1.0.3",
|
| 770 |
+
"etag": "~1.8.1",
|
| 771 |
+
"fresh": "~0.5.2",
|
| 772 |
+
"http-errors": "~2.0.1",
|
| 773 |
+
"mime": "1.6.0",
|
| 774 |
+
"ms": "2.1.3",
|
| 775 |
+
"on-finished": "~2.4.1",
|
| 776 |
+
"range-parser": "~1.2.1",
|
| 777 |
+
"statuses": "~2.0.2"
|
| 778 |
+
},
|
| 779 |
+
"engines": {
|
| 780 |
+
"node": ">= 0.8.0"
|
| 781 |
+
}
|
| 782 |
+
},
|
| 783 |
+
"node_modules/send/node_modules/ms": {
|
| 784 |
+
"version": "2.1.3",
|
| 785 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
| 786 |
+
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
| 787 |
+
"license": "MIT"
|
| 788 |
+
},
|
| 789 |
+
"node_modules/serve-static": {
|
| 790 |
+
"version": "1.16.3",
|
| 791 |
+
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz",
|
| 792 |
+
"integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==",
|
| 793 |
+
"license": "MIT",
|
| 794 |
+
"dependencies": {
|
| 795 |
+
"encodeurl": "~2.0.0",
|
| 796 |
+
"escape-html": "~1.0.3",
|
| 797 |
+
"parseurl": "~1.3.3",
|
| 798 |
+
"send": "~0.19.1"
|
| 799 |
+
},
|
| 800 |
+
"engines": {
|
| 801 |
+
"node": ">= 0.8.0"
|
| 802 |
+
}
|
| 803 |
+
},
|
| 804 |
+
"node_modules/setprototypeof": {
|
| 805 |
+
"version": "1.2.0",
|
| 806 |
+
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
| 807 |
+
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
|
| 808 |
+
"license": "ISC"
|
| 809 |
+
},
|
| 810 |
+
"node_modules/side-channel": {
|
| 811 |
+
"version": "1.1.1",
|
| 812 |
+
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz",
|
| 813 |
+
"integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==",
|
| 814 |
+
"license": "MIT",
|
| 815 |
+
"dependencies": {
|
| 816 |
+
"es-errors": "^1.3.0",
|
| 817 |
+
"object-inspect": "^1.13.4",
|
| 818 |
+
"side-channel-list": "^1.0.1",
|
| 819 |
+
"side-channel-map": "^1.0.1",
|
| 820 |
+
"side-channel-weakmap": "^1.0.2"
|
| 821 |
+
},
|
| 822 |
+
"engines": {
|
| 823 |
+
"node": ">= 0.4"
|
| 824 |
+
},
|
| 825 |
+
"funding": {
|
| 826 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 827 |
+
}
|
| 828 |
+
},
|
| 829 |
+
"node_modules/side-channel-list": {
|
| 830 |
+
"version": "1.0.1",
|
| 831 |
+
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz",
|
| 832 |
+
"integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==",
|
| 833 |
+
"license": "MIT",
|
| 834 |
+
"dependencies": {
|
| 835 |
+
"es-errors": "^1.3.0",
|
| 836 |
+
"object-inspect": "^1.13.4"
|
| 837 |
+
},
|
| 838 |
+
"engines": {
|
| 839 |
+
"node": ">= 0.4"
|
| 840 |
+
},
|
| 841 |
+
"funding": {
|
| 842 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 843 |
+
}
|
| 844 |
+
},
|
| 845 |
+
"node_modules/side-channel-map": {
|
| 846 |
+
"version": "1.0.1",
|
| 847 |
+
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
|
| 848 |
+
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
|
| 849 |
+
"license": "MIT",
|
| 850 |
+
"dependencies": {
|
| 851 |
+
"call-bound": "^1.0.2",
|
| 852 |
+
"es-errors": "^1.3.0",
|
| 853 |
+
"get-intrinsic": "^1.2.5",
|
| 854 |
+
"object-inspect": "^1.13.3"
|
| 855 |
+
},
|
| 856 |
+
"engines": {
|
| 857 |
+
"node": ">= 0.4"
|
| 858 |
+
},
|
| 859 |
+
"funding": {
|
| 860 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 861 |
+
}
|
| 862 |
+
},
|
| 863 |
+
"node_modules/side-channel-weakmap": {
|
| 864 |
+
"version": "1.0.2",
|
| 865 |
+
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
|
| 866 |
+
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
|
| 867 |
+
"license": "MIT",
|
| 868 |
+
"dependencies": {
|
| 869 |
+
"call-bound": "^1.0.2",
|
| 870 |
+
"es-errors": "^1.3.0",
|
| 871 |
+
"get-intrinsic": "^1.2.5",
|
| 872 |
+
"object-inspect": "^1.13.3",
|
| 873 |
+
"side-channel-map": "^1.0.1"
|
| 874 |
+
},
|
| 875 |
+
"engines": {
|
| 876 |
+
"node": ">= 0.4"
|
| 877 |
+
},
|
| 878 |
+
"funding": {
|
| 879 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 880 |
+
}
|
| 881 |
+
},
|
| 882 |
+
"node_modules/socket.io": {
|
| 883 |
+
"version": "4.8.3",
|
| 884 |
+
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.3.tgz",
|
| 885 |
+
"integrity": "sha512-2Dd78bqzzjE6KPkD5fHZmDAKRNe3J15q+YHDrIsy9WEkqttc7GY+kT9OBLSMaPbQaEd0x1BjcmtMtXkfpc+T5A==",
|
| 886 |
+
"license": "MIT",
|
| 887 |
+
"dependencies": {
|
| 888 |
+
"accepts": "~1.3.4",
|
| 889 |
+
"base64id": "~2.0.0",
|
| 890 |
+
"cors": "~2.8.5",
|
| 891 |
+
"debug": "~4.4.1",
|
| 892 |
+
"engine.io": "~6.6.0",
|
| 893 |
+
"socket.io-adapter": "~2.5.2",
|
| 894 |
+
"socket.io-parser": "~4.2.4"
|
| 895 |
+
},
|
| 896 |
+
"engines": {
|
| 897 |
+
"node": ">=10.2.0"
|
| 898 |
+
}
|
| 899 |
+
},
|
| 900 |
+
"node_modules/socket.io-adapter": {
|
| 901 |
+
"version": "2.5.7",
|
| 902 |
+
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.7.tgz",
|
| 903 |
+
"integrity": "sha512-e0LyK91f3cUxTmv95/KzoLg47+zF+s/sbxRGDNsyG4dmIP8ZSX8ax6byOxfJXeNNtS/8AZlfD+uP7gBeR7DLlg==",
|
| 904 |
+
"license": "MIT",
|
| 905 |
+
"dependencies": {
|
| 906 |
+
"debug": "~4.4.1",
|
| 907 |
+
"ws": "~8.20.1"
|
| 908 |
+
}
|
| 909 |
+
},
|
| 910 |
+
"node_modules/socket.io-adapter/node_modules/debug": {
|
| 911 |
+
"version": "4.4.3",
|
| 912 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
| 913 |
+
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
| 914 |
+
"license": "MIT",
|
| 915 |
+
"dependencies": {
|
| 916 |
+
"ms": "^2.1.3"
|
| 917 |
+
},
|
| 918 |
+
"engines": {
|
| 919 |
+
"node": ">=6.0"
|
| 920 |
+
},
|
| 921 |
+
"peerDependenciesMeta": {
|
| 922 |
+
"supports-color": {
|
| 923 |
+
"optional": true
|
| 924 |
+
}
|
| 925 |
+
}
|
| 926 |
+
},
|
| 927 |
+
"node_modules/socket.io-adapter/node_modules/ms": {
|
| 928 |
+
"version": "2.1.3",
|
| 929 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
| 930 |
+
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
| 931 |
+
"license": "MIT"
|
| 932 |
+
},
|
| 933 |
+
"node_modules/socket.io-parser": {
|
| 934 |
+
"version": "4.2.6",
|
| 935 |
+
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.6.tgz",
|
| 936 |
+
"integrity": "sha512-asJqbVBDsBCJx0pTqw3WfesSY0iRX+2xzWEWzrpcH7L6fLzrhyF8WPI8UaeM4YCuDfpwA/cgsdugMsmtz8EJeg==",
|
| 937 |
+
"license": "MIT",
|
| 938 |
+
"dependencies": {
|
| 939 |
+
"@socket.io/component-emitter": "~3.1.0",
|
| 940 |
+
"debug": "~4.4.1"
|
| 941 |
+
},
|
| 942 |
+
"engines": {
|
| 943 |
+
"node": ">=10.0.0"
|
| 944 |
+
}
|
| 945 |
+
},
|
| 946 |
+
"node_modules/socket.io-parser/node_modules/debug": {
|
| 947 |
+
"version": "4.4.3",
|
| 948 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
| 949 |
+
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
| 950 |
+
"license": "MIT",
|
| 951 |
+
"dependencies": {
|
| 952 |
+
"ms": "^2.1.3"
|
| 953 |
+
},
|
| 954 |
+
"engines": {
|
| 955 |
+
"node": ">=6.0"
|
| 956 |
+
},
|
| 957 |
+
"peerDependenciesMeta": {
|
| 958 |
+
"supports-color": {
|
| 959 |
+
"optional": true
|
| 960 |
+
}
|
| 961 |
+
}
|
| 962 |
+
},
|
| 963 |
+
"node_modules/socket.io-parser/node_modules/ms": {
|
| 964 |
+
"version": "2.1.3",
|
| 965 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
| 966 |
+
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
| 967 |
+
"license": "MIT"
|
| 968 |
+
},
|
| 969 |
+
"node_modules/socket.io/node_modules/debug": {
|
| 970 |
+
"version": "4.4.3",
|
| 971 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
| 972 |
+
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
|
| 973 |
+
"license": "MIT",
|
| 974 |
+
"dependencies": {
|
| 975 |
+
"ms": "^2.1.3"
|
| 976 |
+
},
|
| 977 |
+
"engines": {
|
| 978 |
+
"node": ">=6.0"
|
| 979 |
+
},
|
| 980 |
+
"peerDependenciesMeta": {
|
| 981 |
+
"supports-color": {
|
| 982 |
+
"optional": true
|
| 983 |
+
}
|
| 984 |
+
}
|
| 985 |
+
},
|
| 986 |
+
"node_modules/socket.io/node_modules/ms": {
|
| 987 |
+
"version": "2.1.3",
|
| 988 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
| 989 |
+
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
| 990 |
+
"license": "MIT"
|
| 991 |
+
},
|
| 992 |
+
"node_modules/statuses": {
|
| 993 |
+
"version": "2.0.2",
|
| 994 |
+
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
|
| 995 |
+
"integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
|
| 996 |
+
"license": "MIT",
|
| 997 |
+
"engines": {
|
| 998 |
+
"node": ">= 0.8"
|
| 999 |
+
}
|
| 1000 |
+
},
|
| 1001 |
+
"node_modules/toidentifier": {
|
| 1002 |
+
"version": "1.0.1",
|
| 1003 |
+
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
|
| 1004 |
+
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
|
| 1005 |
+
"license": "MIT",
|
| 1006 |
+
"engines": {
|
| 1007 |
+
"node": ">=0.6"
|
| 1008 |
+
}
|
| 1009 |
+
},
|
| 1010 |
+
"node_modules/type-is": {
|
| 1011 |
+
"version": "1.6.18",
|
| 1012 |
+
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
| 1013 |
+
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
| 1014 |
+
"license": "MIT",
|
| 1015 |
+
"dependencies": {
|
| 1016 |
+
"media-typer": "0.3.0",
|
| 1017 |
+
"mime-types": "~2.1.24"
|
| 1018 |
+
},
|
| 1019 |
+
"engines": {
|
| 1020 |
+
"node": ">= 0.6"
|
| 1021 |
+
}
|
| 1022 |
+
},
|
| 1023 |
+
"node_modules/undici-types": {
|
| 1024 |
+
"version": "7.24.6",
|
| 1025 |
+
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.6.tgz",
|
| 1026 |
+
"integrity": "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==",
|
| 1027 |
+
"license": "MIT"
|
| 1028 |
+
},
|
| 1029 |
+
"node_modules/unpipe": {
|
| 1030 |
+
"version": "1.0.0",
|
| 1031 |
+
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
| 1032 |
+
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
|
| 1033 |
+
"license": "MIT",
|
| 1034 |
+
"engines": {
|
| 1035 |
+
"node": ">= 0.8"
|
| 1036 |
+
}
|
| 1037 |
+
},
|
| 1038 |
+
"node_modules/utils-merge": {
|
| 1039 |
+
"version": "1.0.1",
|
| 1040 |
+
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
| 1041 |
+
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
|
| 1042 |
+
"license": "MIT",
|
| 1043 |
+
"engines": {
|
| 1044 |
+
"node": ">= 0.4.0"
|
| 1045 |
+
}
|
| 1046 |
+
},
|
| 1047 |
+
"node_modules/vary": {
|
| 1048 |
+
"version": "1.1.2",
|
| 1049 |
+
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
| 1050 |
+
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
|
| 1051 |
+
"license": "MIT",
|
| 1052 |
+
"engines": {
|
| 1053 |
+
"node": ">= 0.8"
|
| 1054 |
+
}
|
| 1055 |
+
},
|
| 1056 |
+
"node_modules/ws": {
|
| 1057 |
+
"version": "8.20.1",
|
| 1058 |
+
"resolved": "https://registry.npmjs.org/ws/-/ws-8.20.1.tgz",
|
| 1059 |
+
"integrity": "sha512-It4dO0K5v//JtTXuPkfEOaI3uUN87iYPnqo/ZzqCoG3g8uhA66QUMs/SrM0YK7/NAu+r4LMh/9dq2A7k+rHs+w==",
|
| 1060 |
+
"license": "MIT",
|
| 1061 |
+
"engines": {
|
| 1062 |
+
"node": ">=10.0.0"
|
| 1063 |
+
},
|
| 1064 |
+
"peerDependencies": {
|
| 1065 |
+
"bufferutil": "^4.0.1",
|
| 1066 |
+
"utf-8-validate": ">=5.0.2"
|
| 1067 |
+
},
|
| 1068 |
+
"peerDependenciesMeta": {
|
| 1069 |
+
"bufferutil": {
|
| 1070 |
+
"optional": true
|
| 1071 |
+
},
|
| 1072 |
+
"utf-8-validate": {
|
| 1073 |
+
"optional": true
|
| 1074 |
+
}
|
| 1075 |
+
}
|
| 1076 |
+
}
|
| 1077 |
+
}
|
| 1078 |
+
}
|
node_modules/@socket.io/component-emitter/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
(The MIT License)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2014 Component contributors <dev@component.io>
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person
|
| 6 |
+
obtaining a copy of this software and associated documentation
|
| 7 |
+
files (the "Software"), to deal in the Software without
|
| 8 |
+
restriction, including without limitation the rights to use,
|
| 9 |
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the
|
| 11 |
+
Software is furnished to do so, subject to the following
|
| 12 |
+
conditions:
|
| 13 |
+
|
| 14 |
+
The above copyright notice and this permission notice shall be
|
| 15 |
+
included in all copies or substantial portions of the Software.
|
| 16 |
+
|
| 17 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 18 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
| 19 |
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 20 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
| 21 |
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 22 |
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 23 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 24 |
+
OTHER DEALINGS IN THE SOFTWARE.
|
node_modules/@socket.io/component-emitter/Readme.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# `@socket.io/component-emitter`
|
| 2 |
+
|
| 3 |
+
Event emitter component.
|
| 4 |
+
|
| 5 |
+
This project is a fork of the [`component-emitter`](https://github.com/sindresorhus/component-emitter) project, with [Socket.IO](https://socket.io/)-specific TypeScript typings.
|
| 6 |
+
|
| 7 |
+
## Installation
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
$ npm i @socket.io/component-emitter
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
## API
|
| 14 |
+
|
| 15 |
+
### Emitter(obj)
|
| 16 |
+
|
| 17 |
+
The `Emitter` may also be used as a mixin. For example
|
| 18 |
+
a "plain" object may become an emitter, or you may
|
| 19 |
+
extend an existing prototype.
|
| 20 |
+
|
| 21 |
+
As an `Emitter` instance:
|
| 22 |
+
|
| 23 |
+
```js
|
| 24 |
+
import { Emitter } from '@socket.io/component-emitter';
|
| 25 |
+
|
| 26 |
+
var emitter = new Emitter;
|
| 27 |
+
emitter.emit('something');
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
As a mixin:
|
| 31 |
+
|
| 32 |
+
```js
|
| 33 |
+
import { Emitter } from '@socket.io/component-emitter';
|
| 34 |
+
|
| 35 |
+
var user = { name: 'tobi' };
|
| 36 |
+
Emitter(user);
|
| 37 |
+
|
| 38 |
+
user.emit('im a user');
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
As a prototype mixin:
|
| 42 |
+
|
| 43 |
+
```js
|
| 44 |
+
import { Emitter } from '@socket.io/component-emitter';
|
| 45 |
+
|
| 46 |
+
Emitter(User.prototype);
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### Emitter#on(event, fn)
|
| 50 |
+
|
| 51 |
+
Register an `event` handler `fn`.
|
| 52 |
+
|
| 53 |
+
### Emitter#once(event, fn)
|
| 54 |
+
|
| 55 |
+
Register a single-shot `event` handler `fn`,
|
| 56 |
+
removed immediately after it is invoked the
|
| 57 |
+
first time.
|
| 58 |
+
|
| 59 |
+
### Emitter#off(event, fn)
|
| 60 |
+
|
| 61 |
+
* Pass `event` and `fn` to remove a listener.
|
| 62 |
+
* Pass `event` to remove all listeners on that event.
|
| 63 |
+
* Pass nothing to remove all listeners on all events.
|
| 64 |
+
|
| 65 |
+
### Emitter#emit(event, ...)
|
| 66 |
+
|
| 67 |
+
Emit an `event` with variable option args.
|
| 68 |
+
|
| 69 |
+
### Emitter#listeners(event)
|
| 70 |
+
|
| 71 |
+
Return an array of callbacks, or an empty array.
|
| 72 |
+
|
| 73 |
+
### Emitter#hasListeners(event)
|
| 74 |
+
|
| 75 |
+
Check if this emitter has `event` handlers.
|
| 76 |
+
|
| 77 |
+
## License
|
| 78 |
+
|
| 79 |
+
MIT
|
node_modules/@socket.io/component-emitter/lib/cjs/index.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* An events map is an interface that maps event names to their value, which
|
| 3 |
+
* represents the type of the `on` listener.
|
| 4 |
+
*/
|
| 5 |
+
export interface EventsMap {
|
| 6 |
+
[event: string]: any;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* The default events map, used if no EventsMap is given. Using this EventsMap
|
| 11 |
+
* is equivalent to accepting all event names, and any data.
|
| 12 |
+
*/
|
| 13 |
+
export interface DefaultEventsMap {
|
| 14 |
+
[event: string]: (...args: any[]) => void;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Returns a union type containing all the keys of an event map.
|
| 19 |
+
*/
|
| 20 |
+
export type EventNames<Map extends EventsMap> = keyof Map & (string | symbol);
|
| 21 |
+
|
| 22 |
+
/** The tuple type representing the parameters of an event listener */
|
| 23 |
+
export type EventParams<
|
| 24 |
+
Map extends EventsMap,
|
| 25 |
+
Ev extends EventNames<Map>
|
| 26 |
+
> = Parameters<Map[Ev]>;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* The event names that are either in ReservedEvents or in UserEvents
|
| 30 |
+
*/
|
| 31 |
+
export type ReservedOrUserEventNames<
|
| 32 |
+
ReservedEventsMap extends EventsMap,
|
| 33 |
+
UserEvents extends EventsMap
|
| 34 |
+
> = EventNames<ReservedEventsMap> | EventNames<UserEvents>;
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Type of a listener of a user event or a reserved event. If `Ev` is in
|
| 38 |
+
* `ReservedEvents`, the reserved event listener is returned.
|
| 39 |
+
*/
|
| 40 |
+
export type ReservedOrUserListener<
|
| 41 |
+
ReservedEvents extends EventsMap,
|
| 42 |
+
UserEvents extends EventsMap,
|
| 43 |
+
Ev extends ReservedOrUserEventNames<ReservedEvents, UserEvents>
|
| 44 |
+
> = FallbackToUntypedListener<
|
| 45 |
+
Ev extends EventNames<ReservedEvents>
|
| 46 |
+
? ReservedEvents[Ev]
|
| 47 |
+
: Ev extends EventNames<UserEvents>
|
| 48 |
+
? UserEvents[Ev]
|
| 49 |
+
: never
|
| 50 |
+
>;
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Returns an untyped listener type if `T` is `never`; otherwise, returns `T`.
|
| 54 |
+
*
|
| 55 |
+
* This is a hack to mitigate https://github.com/socketio/socket.io/issues/3833.
|
| 56 |
+
* Needed because of https://github.com/microsoft/TypeScript/issues/41778
|
| 57 |
+
*/
|
| 58 |
+
type FallbackToUntypedListener<T> = [T] extends [never]
|
| 59 |
+
? (...args: any[]) => void | Promise<void>
|
| 60 |
+
: T;
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Strictly typed version of an `EventEmitter`. A `TypedEventEmitter` takes type
|
| 64 |
+
* parameters for mappings of event names to event data types, and strictly
|
| 65 |
+
* types method calls to the `EventEmitter` according to these event maps.
|
| 66 |
+
*
|
| 67 |
+
* @typeParam ListenEvents - `EventsMap` of user-defined events that can be
|
| 68 |
+
* listened to with `on` or `once`
|
| 69 |
+
* @typeParam EmitEvents - `EventsMap` of user-defined events that can be
|
| 70 |
+
* emitted with `emit`
|
| 71 |
+
* @typeParam ReservedEvents - `EventsMap` of reserved events, that can be
|
| 72 |
+
* emitted by socket.io with `emitReserved`, and can be listened to with
|
| 73 |
+
* `listen`.
|
| 74 |
+
*/
|
| 75 |
+
export class Emitter<
|
| 76 |
+
ListenEvents extends EventsMap,
|
| 77 |
+
EmitEvents extends EventsMap,
|
| 78 |
+
ReservedEvents extends EventsMap = {}
|
| 79 |
+
> {
|
| 80 |
+
/**
|
| 81 |
+
* Adds the `listener` function as an event listener for `ev`.
|
| 82 |
+
*
|
| 83 |
+
* @param ev Name of the event
|
| 84 |
+
* @param listener Callback function
|
| 85 |
+
*/
|
| 86 |
+
on<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
|
| 87 |
+
ev: Ev,
|
| 88 |
+
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
|
| 89 |
+
): this;
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* Adds a one-time `listener` function as an event listener for `ev`.
|
| 93 |
+
*
|
| 94 |
+
* @param ev Name of the event
|
| 95 |
+
* @param listener Callback function
|
| 96 |
+
*/
|
| 97 |
+
once<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
|
| 98 |
+
ev: Ev,
|
| 99 |
+
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
|
| 100 |
+
): this;
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Removes the `listener` function as an event listener for `ev`.
|
| 104 |
+
*
|
| 105 |
+
* @param ev Name of the event
|
| 106 |
+
* @param listener Callback function
|
| 107 |
+
*/
|
| 108 |
+
off<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
|
| 109 |
+
ev?: Ev,
|
| 110 |
+
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
|
| 111 |
+
): this;
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Emits an event.
|
| 115 |
+
*
|
| 116 |
+
* @param ev Name of the event
|
| 117 |
+
* @param args Values to send to listeners of this event
|
| 118 |
+
*/
|
| 119 |
+
emit<Ev extends EventNames<EmitEvents>>(
|
| 120 |
+
ev: Ev,
|
| 121 |
+
...args: EventParams<EmitEvents, Ev>
|
| 122 |
+
): this;
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Emits a reserved event.
|
| 126 |
+
*
|
| 127 |
+
* This method is `protected`, so that only a class extending
|
| 128 |
+
* `StrictEventEmitter` can emit its own reserved events.
|
| 129 |
+
*
|
| 130 |
+
* @param ev Reserved event name
|
| 131 |
+
* @param args Arguments to emit along with the event
|
| 132 |
+
*/
|
| 133 |
+
protected emitReserved<Ev extends EventNames<ReservedEvents>>(
|
| 134 |
+
ev: Ev,
|
| 135 |
+
...args: EventParams<ReservedEvents, Ev>
|
| 136 |
+
): this;
|
| 137 |
+
|
| 138 |
+
/**
|
| 139 |
+
* Returns the listeners listening to an event.
|
| 140 |
+
*
|
| 141 |
+
* @param event Event name
|
| 142 |
+
* @returns Array of listeners subscribed to `event`
|
| 143 |
+
*/
|
| 144 |
+
listeners<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
|
| 145 |
+
event: Ev
|
| 146 |
+
): ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>[];
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Returns true if there is a listener for this event.
|
| 150 |
+
*
|
| 151 |
+
* @param event Event name
|
| 152 |
+
* @returns boolean
|
| 153 |
+
*/
|
| 154 |
+
hasListeners<
|
| 155 |
+
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
|
| 156 |
+
>(event: Ev): boolean;
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* Removes the `listener` function as an event listener for `ev`.
|
| 160 |
+
*
|
| 161 |
+
* @param ev Name of the event
|
| 162 |
+
* @param listener Callback function
|
| 163 |
+
*/
|
| 164 |
+
removeListener<
|
| 165 |
+
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
|
| 166 |
+
>(
|
| 167 |
+
ev?: Ev,
|
| 168 |
+
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
|
| 169 |
+
): this;
|
| 170 |
+
|
| 171 |
+
/**
|
| 172 |
+
* Removes all `listener` function as an event listener for `ev`.
|
| 173 |
+
*
|
| 174 |
+
* @param ev Name of the event
|
| 175 |
+
*/
|
| 176 |
+
removeAllListeners<
|
| 177 |
+
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
|
| 178 |
+
>(ev?: Ev): this;
|
| 179 |
+
}
|
node_modules/@socket.io/component-emitter/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
/**
|
| 3 |
+
* Expose `Emitter`.
|
| 4 |
+
*/
|
| 5 |
+
|
| 6 |
+
exports.Emitter = Emitter;
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* Initialize a new `Emitter`.
|
| 10 |
+
*
|
| 11 |
+
* @api public
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
function Emitter(obj) {
|
| 15 |
+
if (obj) return mixin(obj);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
/**
|
| 19 |
+
* Mixin the emitter properties.
|
| 20 |
+
*
|
| 21 |
+
* @param {Object} obj
|
| 22 |
+
* @return {Object}
|
| 23 |
+
* @api private
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
function mixin(obj) {
|
| 27 |
+
for (var key in Emitter.prototype) {
|
| 28 |
+
obj[key] = Emitter.prototype[key];
|
| 29 |
+
}
|
| 30 |
+
return obj;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* Listen on the given `event` with `fn`.
|
| 35 |
+
*
|
| 36 |
+
* @param {String} event
|
| 37 |
+
* @param {Function} fn
|
| 38 |
+
* @return {Emitter}
|
| 39 |
+
* @api public
|
| 40 |
+
*/
|
| 41 |
+
|
| 42 |
+
Emitter.prototype.on =
|
| 43 |
+
Emitter.prototype.addEventListener = function(event, fn){
|
| 44 |
+
this._callbacks = this._callbacks || {};
|
| 45 |
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
| 46 |
+
.push(fn);
|
| 47 |
+
return this;
|
| 48 |
+
};
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Adds an `event` listener that will be invoked a single
|
| 52 |
+
* time then automatically removed.
|
| 53 |
+
*
|
| 54 |
+
* @param {String} event
|
| 55 |
+
* @param {Function} fn
|
| 56 |
+
* @return {Emitter}
|
| 57 |
+
* @api public
|
| 58 |
+
*/
|
| 59 |
+
|
| 60 |
+
Emitter.prototype.once = function(event, fn){
|
| 61 |
+
function on() {
|
| 62 |
+
this.off(event, on);
|
| 63 |
+
fn.apply(this, arguments);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
on.fn = fn;
|
| 67 |
+
this.on(event, on);
|
| 68 |
+
return this;
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
/**
|
| 72 |
+
* Remove the given callback for `event` or all
|
| 73 |
+
* registered callbacks.
|
| 74 |
+
*
|
| 75 |
+
* @param {String} event
|
| 76 |
+
* @param {Function} fn
|
| 77 |
+
* @return {Emitter}
|
| 78 |
+
* @api public
|
| 79 |
+
*/
|
| 80 |
+
|
| 81 |
+
Emitter.prototype.off =
|
| 82 |
+
Emitter.prototype.removeListener =
|
| 83 |
+
Emitter.prototype.removeAllListeners =
|
| 84 |
+
Emitter.prototype.removeEventListener = function(event, fn){
|
| 85 |
+
this._callbacks = this._callbacks || {};
|
| 86 |
+
|
| 87 |
+
// all
|
| 88 |
+
if (0 == arguments.length) {
|
| 89 |
+
this._callbacks = {};
|
| 90 |
+
return this;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// specific event
|
| 94 |
+
var callbacks = this._callbacks['$' + event];
|
| 95 |
+
if (!callbacks) return this;
|
| 96 |
+
|
| 97 |
+
// remove all handlers
|
| 98 |
+
if (1 == arguments.length) {
|
| 99 |
+
delete this._callbacks['$' + event];
|
| 100 |
+
return this;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// remove specific handler
|
| 104 |
+
var cb;
|
| 105 |
+
for (var i = 0; i < callbacks.length; i++) {
|
| 106 |
+
cb = callbacks[i];
|
| 107 |
+
if (cb === fn || cb.fn === fn) {
|
| 108 |
+
callbacks.splice(i, 1);
|
| 109 |
+
break;
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// Remove event specific arrays for event types that no
|
| 114 |
+
// one is subscribed for to avoid memory leak.
|
| 115 |
+
if (callbacks.length === 0) {
|
| 116 |
+
delete this._callbacks['$' + event];
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
return this;
|
| 120 |
+
};
|
| 121 |
+
|
| 122 |
+
/**
|
| 123 |
+
* Emit `event` with the given args.
|
| 124 |
+
*
|
| 125 |
+
* @param {String} event
|
| 126 |
+
* @param {Mixed} ...
|
| 127 |
+
* @return {Emitter}
|
| 128 |
+
*/
|
| 129 |
+
|
| 130 |
+
Emitter.prototype.emit = function(event){
|
| 131 |
+
this._callbacks = this._callbacks || {};
|
| 132 |
+
|
| 133 |
+
var args = new Array(arguments.length - 1)
|
| 134 |
+
, callbacks = this._callbacks['$' + event];
|
| 135 |
+
|
| 136 |
+
for (var i = 1; i < arguments.length; i++) {
|
| 137 |
+
args[i - 1] = arguments[i];
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
if (callbacks) {
|
| 141 |
+
callbacks = callbacks.slice(0);
|
| 142 |
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
| 143 |
+
callbacks[i].apply(this, args);
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
return this;
|
| 148 |
+
};
|
| 149 |
+
|
| 150 |
+
// alias used for reserved events (protected method)
|
| 151 |
+
Emitter.prototype.emitReserved = Emitter.prototype.emit;
|
| 152 |
+
|
| 153 |
+
/**
|
| 154 |
+
* Return array of callbacks for `event`.
|
| 155 |
+
*
|
| 156 |
+
* @param {String} event
|
| 157 |
+
* @return {Array}
|
| 158 |
+
* @api public
|
| 159 |
+
*/
|
| 160 |
+
|
| 161 |
+
Emitter.prototype.listeners = function(event){
|
| 162 |
+
this._callbacks = this._callbacks || {};
|
| 163 |
+
return this._callbacks['$' + event] || [];
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
/**
|
| 167 |
+
* Check if this emitter has `event` handlers.
|
| 168 |
+
*
|
| 169 |
+
* @param {String} event
|
| 170 |
+
* @return {Boolean}
|
| 171 |
+
* @api public
|
| 172 |
+
*/
|
| 173 |
+
|
| 174 |
+
Emitter.prototype.hasListeners = function(event){
|
| 175 |
+
return !! this.listeners(event).length;
|
| 176 |
+
};
|
node_modules/@socket.io/component-emitter/lib/cjs/package.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@socket.io/component-emitter",
|
| 3 |
+
"type": "commonjs"
|
| 4 |
+
}
|
node_modules/@socket.io/component-emitter/lib/esm/index.d.ts
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* An events map is an interface that maps event names to their value, which
|
| 3 |
+
* represents the type of the `on` listener.
|
| 4 |
+
*/
|
| 5 |
+
export interface EventsMap {
|
| 6 |
+
[event: string]: any;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* The default events map, used if no EventsMap is given. Using this EventsMap
|
| 11 |
+
* is equivalent to accepting all event names, and any data.
|
| 12 |
+
*/
|
| 13 |
+
export interface DefaultEventsMap {
|
| 14 |
+
[event: string]: (...args: any[]) => void;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Returns a union type containing all the keys of an event map.
|
| 19 |
+
*/
|
| 20 |
+
export type EventNames<Map extends EventsMap> = keyof Map & (string | symbol);
|
| 21 |
+
|
| 22 |
+
/** The tuple type representing the parameters of an event listener */
|
| 23 |
+
export type EventParams<
|
| 24 |
+
Map extends EventsMap,
|
| 25 |
+
Ev extends EventNames<Map>
|
| 26 |
+
> = Parameters<Map[Ev]>;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* The event names that are either in ReservedEvents or in UserEvents
|
| 30 |
+
*/
|
| 31 |
+
export type ReservedOrUserEventNames<
|
| 32 |
+
ReservedEventsMap extends EventsMap,
|
| 33 |
+
UserEvents extends EventsMap
|
| 34 |
+
> = EventNames<ReservedEventsMap> | EventNames<UserEvents>;
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Type of a listener of a user event or a reserved event. If `Ev` is in
|
| 38 |
+
* `ReservedEvents`, the reserved event listener is returned.
|
| 39 |
+
*/
|
| 40 |
+
export type ReservedOrUserListener<
|
| 41 |
+
ReservedEvents extends EventsMap,
|
| 42 |
+
UserEvents extends EventsMap,
|
| 43 |
+
Ev extends ReservedOrUserEventNames<ReservedEvents, UserEvents>
|
| 44 |
+
> = FallbackToUntypedListener<
|
| 45 |
+
Ev extends EventNames<ReservedEvents>
|
| 46 |
+
? ReservedEvents[Ev]
|
| 47 |
+
: Ev extends EventNames<UserEvents>
|
| 48 |
+
? UserEvents[Ev]
|
| 49 |
+
: never
|
| 50 |
+
>;
|
| 51 |
+
|
| 52 |
+
/**
|
| 53 |
+
* Returns an untyped listener type if `T` is `never`; otherwise, returns `T`.
|
| 54 |
+
*
|
| 55 |
+
* This is a hack to mitigate https://github.com/socketio/socket.io/issues/3833.
|
| 56 |
+
* Needed because of https://github.com/microsoft/TypeScript/issues/41778
|
| 57 |
+
*/
|
| 58 |
+
type FallbackToUntypedListener<T> = [T] extends [never]
|
| 59 |
+
? (...args: any[]) => void | Promise<void>
|
| 60 |
+
: T;
|
| 61 |
+
|
| 62 |
+
/**
|
| 63 |
+
* Strictly typed version of an `EventEmitter`. A `TypedEventEmitter` takes type
|
| 64 |
+
* parameters for mappings of event names to event data types, and strictly
|
| 65 |
+
* types method calls to the `EventEmitter` according to these event maps.
|
| 66 |
+
*
|
| 67 |
+
* @typeParam ListenEvents - `EventsMap` of user-defined events that can be
|
| 68 |
+
* listened to with `on` or `once`
|
| 69 |
+
* @typeParam EmitEvents - `EventsMap` of user-defined events that can be
|
| 70 |
+
* emitted with `emit`
|
| 71 |
+
* @typeParam ReservedEvents - `EventsMap` of reserved events, that can be
|
| 72 |
+
* emitted by socket.io with `emitReserved`, and can be listened to with
|
| 73 |
+
* `listen`.
|
| 74 |
+
*/
|
| 75 |
+
export class Emitter<
|
| 76 |
+
ListenEvents extends EventsMap,
|
| 77 |
+
EmitEvents extends EventsMap,
|
| 78 |
+
ReservedEvents extends EventsMap = {}
|
| 79 |
+
> {
|
| 80 |
+
/**
|
| 81 |
+
* Adds the `listener` function as an event listener for `ev`.
|
| 82 |
+
*
|
| 83 |
+
* @param ev Name of the event
|
| 84 |
+
* @param listener Callback function
|
| 85 |
+
*/
|
| 86 |
+
on<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
|
| 87 |
+
ev: Ev,
|
| 88 |
+
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
|
| 89 |
+
): this;
|
| 90 |
+
|
| 91 |
+
/**
|
| 92 |
+
* Adds a one-time `listener` function as an event listener for `ev`.
|
| 93 |
+
*
|
| 94 |
+
* @param ev Name of the event
|
| 95 |
+
* @param listener Callback function
|
| 96 |
+
*/
|
| 97 |
+
once<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
|
| 98 |
+
ev: Ev,
|
| 99 |
+
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
|
| 100 |
+
): this;
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* Removes the `listener` function as an event listener for `ev`.
|
| 104 |
+
*
|
| 105 |
+
* @param ev Name of the event
|
| 106 |
+
* @param listener Callback function
|
| 107 |
+
*/
|
| 108 |
+
off<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
|
| 109 |
+
ev?: Ev,
|
| 110 |
+
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
|
| 111 |
+
): this;
|
| 112 |
+
|
| 113 |
+
/**
|
| 114 |
+
* Emits an event.
|
| 115 |
+
*
|
| 116 |
+
* @param ev Name of the event
|
| 117 |
+
* @param args Values to send to listeners of this event
|
| 118 |
+
*/
|
| 119 |
+
emit<Ev extends EventNames<EmitEvents>>(
|
| 120 |
+
ev: Ev,
|
| 121 |
+
...args: EventParams<EmitEvents, Ev>
|
| 122 |
+
): this;
|
| 123 |
+
|
| 124 |
+
/**
|
| 125 |
+
* Emits a reserved event.
|
| 126 |
+
*
|
| 127 |
+
* This method is `protected`, so that only a class extending
|
| 128 |
+
* `StrictEventEmitter` can emit its own reserved events.
|
| 129 |
+
*
|
| 130 |
+
* @param ev Reserved event name
|
| 131 |
+
* @param args Arguments to emit along with the event
|
| 132 |
+
*/
|
| 133 |
+
protected emitReserved<Ev extends EventNames<ReservedEvents>>(
|
| 134 |
+
ev: Ev,
|
| 135 |
+
...args: EventParams<ReservedEvents, Ev>
|
| 136 |
+
): this;
|
| 137 |
+
|
| 138 |
+
/**
|
| 139 |
+
* Returns the listeners listening to an event.
|
| 140 |
+
*
|
| 141 |
+
* @param event Event name
|
| 142 |
+
* @returns Array of listeners subscribed to `event`
|
| 143 |
+
*/
|
| 144 |
+
listeners<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(
|
| 145 |
+
event: Ev
|
| 146 |
+
): ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>[];
|
| 147 |
+
|
| 148 |
+
/**
|
| 149 |
+
* Returns true if there is a listener for this event.
|
| 150 |
+
*
|
| 151 |
+
* @param event Event name
|
| 152 |
+
* @returns boolean
|
| 153 |
+
*/
|
| 154 |
+
hasListeners<
|
| 155 |
+
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
|
| 156 |
+
>(event: Ev): boolean;
|
| 157 |
+
|
| 158 |
+
/**
|
| 159 |
+
* Removes the `listener` function as an event listener for `ev`.
|
| 160 |
+
*
|
| 161 |
+
* @param ev Name of the event
|
| 162 |
+
* @param listener Callback function
|
| 163 |
+
*/
|
| 164 |
+
removeListener<
|
| 165 |
+
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
|
| 166 |
+
>(
|
| 167 |
+
ev?: Ev,
|
| 168 |
+
listener?: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>
|
| 169 |
+
): this;
|
| 170 |
+
|
| 171 |
+
/**
|
| 172 |
+
* Removes all `listener` function as an event listener for `ev`.
|
| 173 |
+
*
|
| 174 |
+
* @param ev Name of the event
|
| 175 |
+
*/
|
| 176 |
+
removeAllListeners<
|
| 177 |
+
Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>
|
| 178 |
+
>(ev?: Ev): this;
|
| 179 |
+
}
|
node_modules/@socket.io/component-emitter/lib/esm/index.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Initialize a new `Emitter`.
|
| 3 |
+
*
|
| 4 |
+
* @api public
|
| 5 |
+
*/
|
| 6 |
+
|
| 7 |
+
export function Emitter(obj) {
|
| 8 |
+
if (obj) return mixin(obj);
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* Mixin the emitter properties.
|
| 13 |
+
*
|
| 14 |
+
* @param {Object} obj
|
| 15 |
+
* @return {Object}
|
| 16 |
+
* @api private
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
function mixin(obj) {
|
| 20 |
+
for (var key in Emitter.prototype) {
|
| 21 |
+
obj[key] = Emitter.prototype[key];
|
| 22 |
+
}
|
| 23 |
+
return obj;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Listen on the given `event` with `fn`.
|
| 28 |
+
*
|
| 29 |
+
* @param {String} event
|
| 30 |
+
* @param {Function} fn
|
| 31 |
+
* @return {Emitter}
|
| 32 |
+
* @api public
|
| 33 |
+
*/
|
| 34 |
+
|
| 35 |
+
Emitter.prototype.on =
|
| 36 |
+
Emitter.prototype.addEventListener = function(event, fn){
|
| 37 |
+
this._callbacks = this._callbacks || {};
|
| 38 |
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || [])
|
| 39 |
+
.push(fn);
|
| 40 |
+
return this;
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Adds an `event` listener that will be invoked a single
|
| 45 |
+
* time then automatically removed.
|
| 46 |
+
*
|
| 47 |
+
* @param {String} event
|
| 48 |
+
* @param {Function} fn
|
| 49 |
+
* @return {Emitter}
|
| 50 |
+
* @api public
|
| 51 |
+
*/
|
| 52 |
+
|
| 53 |
+
Emitter.prototype.once = function(event, fn){
|
| 54 |
+
function on() {
|
| 55 |
+
this.off(event, on);
|
| 56 |
+
fn.apply(this, arguments);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
on.fn = fn;
|
| 60 |
+
this.on(event, on);
|
| 61 |
+
return this;
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Remove the given callback for `event` or all
|
| 66 |
+
* registered callbacks.
|
| 67 |
+
*
|
| 68 |
+
* @param {String} event
|
| 69 |
+
* @param {Function} fn
|
| 70 |
+
* @return {Emitter}
|
| 71 |
+
* @api public
|
| 72 |
+
*/
|
| 73 |
+
|
| 74 |
+
Emitter.prototype.off =
|
| 75 |
+
Emitter.prototype.removeListener =
|
| 76 |
+
Emitter.prototype.removeAllListeners =
|
| 77 |
+
Emitter.prototype.removeEventListener = function(event, fn){
|
| 78 |
+
this._callbacks = this._callbacks || {};
|
| 79 |
+
|
| 80 |
+
// all
|
| 81 |
+
if (0 == arguments.length) {
|
| 82 |
+
this._callbacks = {};
|
| 83 |
+
return this;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
// specific event
|
| 87 |
+
var callbacks = this._callbacks['$' + event];
|
| 88 |
+
if (!callbacks) return this;
|
| 89 |
+
|
| 90 |
+
// remove all handlers
|
| 91 |
+
if (1 == arguments.length) {
|
| 92 |
+
delete this._callbacks['$' + event];
|
| 93 |
+
return this;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// remove specific handler
|
| 97 |
+
var cb;
|
| 98 |
+
for (var i = 0; i < callbacks.length; i++) {
|
| 99 |
+
cb = callbacks[i];
|
| 100 |
+
if (cb === fn || cb.fn === fn) {
|
| 101 |
+
callbacks.splice(i, 1);
|
| 102 |
+
break;
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
// Remove event specific arrays for event types that no
|
| 107 |
+
// one is subscribed for to avoid memory leak.
|
| 108 |
+
if (callbacks.length === 0) {
|
| 109 |
+
delete this._callbacks['$' + event];
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
return this;
|
| 113 |
+
};
|
| 114 |
+
|
| 115 |
+
/**
|
| 116 |
+
* Emit `event` with the given args.
|
| 117 |
+
*
|
| 118 |
+
* @param {String} event
|
| 119 |
+
* @param {Mixed} ...
|
| 120 |
+
* @return {Emitter}
|
| 121 |
+
*/
|
| 122 |
+
|
| 123 |
+
Emitter.prototype.emit = function(event){
|
| 124 |
+
this._callbacks = this._callbacks || {};
|
| 125 |
+
|
| 126 |
+
var args = new Array(arguments.length - 1)
|
| 127 |
+
, callbacks = this._callbacks['$' + event];
|
| 128 |
+
|
| 129 |
+
for (var i = 1; i < arguments.length; i++) {
|
| 130 |
+
args[i - 1] = arguments[i];
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
if (callbacks) {
|
| 134 |
+
callbacks = callbacks.slice(0);
|
| 135 |
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
| 136 |
+
callbacks[i].apply(this, args);
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
return this;
|
| 141 |
+
};
|
| 142 |
+
|
| 143 |
+
// alias used for reserved events (protected method)
|
| 144 |
+
Emitter.prototype.emitReserved = Emitter.prototype.emit;
|
| 145 |
+
|
| 146 |
+
/**
|
| 147 |
+
* Return array of callbacks for `event`.
|
| 148 |
+
*
|
| 149 |
+
* @param {String} event
|
| 150 |
+
* @return {Array}
|
| 151 |
+
* @api public
|
| 152 |
+
*/
|
| 153 |
+
|
| 154 |
+
Emitter.prototype.listeners = function(event){
|
| 155 |
+
this._callbacks = this._callbacks || {};
|
| 156 |
+
return this._callbacks['$' + event] || [];
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
/**
|
| 160 |
+
* Check if this emitter has `event` handlers.
|
| 161 |
+
*
|
| 162 |
+
* @param {String} event
|
| 163 |
+
* @return {Boolean}
|
| 164 |
+
* @api public
|
| 165 |
+
*/
|
| 166 |
+
|
| 167 |
+
Emitter.prototype.hasListeners = function(event){
|
| 168 |
+
return !! this.listeners(event).length;
|
| 169 |
+
};
|
node_modules/@socket.io/component-emitter/lib/esm/package.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@socket.io/component-emitter",
|
| 3 |
+
"type": "module"
|
| 4 |
+
}
|
node_modules/@socket.io/component-emitter/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@socket.io/component-emitter",
|
| 3 |
+
"description": "Event emitter",
|
| 4 |
+
"version": "3.1.2",
|
| 5 |
+
"license": "MIT",
|
| 6 |
+
"devDependencies": {
|
| 7 |
+
"mocha": "*",
|
| 8 |
+
"should": "*"
|
| 9 |
+
},
|
| 10 |
+
"component": {
|
| 11 |
+
"scripts": {
|
| 12 |
+
"emitter/index.js": "index.js"
|
| 13 |
+
}
|
| 14 |
+
},
|
| 15 |
+
"main": "./lib/cjs/index.js",
|
| 16 |
+
"module": "./lib/esm/index.js",
|
| 17 |
+
"types": "./lib/cjs/index.d.ts",
|
| 18 |
+
"repository": {
|
| 19 |
+
"type": "git",
|
| 20 |
+
"url": "https://github.com/socketio/emitter.git"
|
| 21 |
+
},
|
| 22 |
+
"scripts": {
|
| 23 |
+
"test": "make test"
|
| 24 |
+
},
|
| 25 |
+
"files": [
|
| 26 |
+
"lib/"
|
| 27 |
+
]
|
| 28 |
+
}
|
node_modules/@types/.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
node_modules/@types/cors/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
|
node_modules/@types/cors/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Installation
|
| 2 |
+
> `npm install --save @types/cors`
|
| 3 |
+
|
| 4 |
+
# Summary
|
| 5 |
+
This package contains type definitions for cors (https://github.com/expressjs/cors/).
|
| 6 |
+
|
| 7 |
+
# Details
|
| 8 |
+
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cors.
|
| 9 |
+
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cors/index.d.ts)
|
| 10 |
+
````ts
|
| 11 |
+
/// <reference types="node" />
|
| 12 |
+
|
| 13 |
+
import { IncomingHttpHeaders } from "http";
|
| 14 |
+
|
| 15 |
+
type StaticOrigin = boolean | string | RegExp | Array<boolean | string | RegExp>;
|
| 16 |
+
|
| 17 |
+
type CustomOrigin = (
|
| 18 |
+
requestOrigin: string | undefined,
|
| 19 |
+
callback: (err: Error | null, origin?: StaticOrigin) => void,
|
| 20 |
+
) => void;
|
| 21 |
+
|
| 22 |
+
declare namespace e {
|
| 23 |
+
interface CorsRequest {
|
| 24 |
+
method?: string | undefined;
|
| 25 |
+
headers: IncomingHttpHeaders;
|
| 26 |
+
}
|
| 27 |
+
interface CorsOptions {
|
| 28 |
+
/**
|
| 29 |
+
* @default '*'
|
| 30 |
+
*/
|
| 31 |
+
origin?: StaticOrigin | CustomOrigin | undefined;
|
| 32 |
+
/**
|
| 33 |
+
* @default 'GET,HEAD,PUT,PATCH,POST,DELETE'
|
| 34 |
+
*/
|
| 35 |
+
methods?: string | string[] | undefined;
|
| 36 |
+
allowedHeaders?: string | string[] | undefined;
|
| 37 |
+
exposedHeaders?: string | string[] | undefined;
|
| 38 |
+
credentials?: boolean | undefined;
|
| 39 |
+
maxAge?: number | undefined;
|
| 40 |
+
/**
|
| 41 |
+
* @default false
|
| 42 |
+
*/
|
| 43 |
+
preflightContinue?: boolean | undefined;
|
| 44 |
+
/**
|
| 45 |
+
* @default 204
|
| 46 |
+
*/
|
| 47 |
+
optionsSuccessStatus?: number | undefined;
|
| 48 |
+
}
|
| 49 |
+
type CorsOptionsDelegate<T extends CorsRequest = CorsRequest> = (
|
| 50 |
+
req: T,
|
| 51 |
+
callback: (err: Error | null, options?: CorsOptions) => void,
|
| 52 |
+
) => void;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
declare function e<T extends e.CorsRequest = e.CorsRequest>(
|
| 56 |
+
options?: e.CorsOptions | e.CorsOptionsDelegate<T>,
|
| 57 |
+
): (
|
| 58 |
+
req: T,
|
| 59 |
+
res: {
|
| 60 |
+
statusCode?: number | undefined;
|
| 61 |
+
setHeader(key: string, value: string): any;
|
| 62 |
+
end(): any;
|
| 63 |
+
},
|
| 64 |
+
next: (err?: any) => any,
|
| 65 |
+
) => void;
|
| 66 |
+
export = e;
|
| 67 |
+
|
| 68 |
+
````
|
| 69 |
+
|
| 70 |
+
### Additional Details
|
| 71 |
+
* Last updated: Sat, 07 Jun 2025 02:15:25 GMT
|
| 72 |
+
* Dependencies: [@types/node](https://npmjs.com/package/@types/node)
|
| 73 |
+
|
| 74 |
+
# Credits
|
| 75 |
+
These definitions were written by [Alan Plum](https://github.com/pluma), [Gaurav Sharma](https://github.com/gtpan77), and [Sebastian Beltran](https://github.com/bjohansebas).
|
node_modules/@types/cors/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/// <reference types="node" />
|
| 2 |
+
|
| 3 |
+
import { IncomingHttpHeaders } from "http";
|
| 4 |
+
|
| 5 |
+
type StaticOrigin = boolean | string | RegExp | Array<boolean | string | RegExp>;
|
| 6 |
+
|
| 7 |
+
type CustomOrigin = (
|
| 8 |
+
requestOrigin: string | undefined,
|
| 9 |
+
callback: (err: Error | null, origin?: StaticOrigin) => void,
|
| 10 |
+
) => void;
|
| 11 |
+
|
| 12 |
+
declare namespace e {
|
| 13 |
+
interface CorsRequest {
|
| 14 |
+
method?: string | undefined;
|
| 15 |
+
headers: IncomingHttpHeaders;
|
| 16 |
+
}
|
| 17 |
+
interface CorsOptions {
|
| 18 |
+
/**
|
| 19 |
+
* @default '*'
|
| 20 |
+
*/
|
| 21 |
+
origin?: StaticOrigin | CustomOrigin | undefined;
|
| 22 |
+
/**
|
| 23 |
+
* @default 'GET,HEAD,PUT,PATCH,POST,DELETE'
|
| 24 |
+
*/
|
| 25 |
+
methods?: string | string[] | undefined;
|
| 26 |
+
allowedHeaders?: string | string[] | undefined;
|
| 27 |
+
exposedHeaders?: string | string[] | undefined;
|
| 28 |
+
credentials?: boolean | undefined;
|
| 29 |
+
maxAge?: number | undefined;
|
| 30 |
+
/**
|
| 31 |
+
* @default false
|
| 32 |
+
*/
|
| 33 |
+
preflightContinue?: boolean | undefined;
|
| 34 |
+
/**
|
| 35 |
+
* @default 204
|
| 36 |
+
*/
|
| 37 |
+
optionsSuccessStatus?: number | undefined;
|
| 38 |
+
}
|
| 39 |
+
type CorsOptionsDelegate<T extends CorsRequest = CorsRequest> = (
|
| 40 |
+
req: T,
|
| 41 |
+
callback: (err: Error | null, options?: CorsOptions) => void,
|
| 42 |
+
) => void;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
declare function e<T extends e.CorsRequest = e.CorsRequest>(
|
| 46 |
+
options?: e.CorsOptions | e.CorsOptionsDelegate<T>,
|
| 47 |
+
): (
|
| 48 |
+
req: T,
|
| 49 |
+
res: {
|
| 50 |
+
statusCode?: number | undefined;
|
| 51 |
+
setHeader(key: string, value: string): any;
|
| 52 |
+
end(): any;
|
| 53 |
+
},
|
| 54 |
+
next: (err?: any) => any,
|
| 55 |
+
) => void;
|
| 56 |
+
export = e;
|
node_modules/@types/cors/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@types/cors",
|
| 3 |
+
"version": "2.8.19",
|
| 4 |
+
"description": "TypeScript definitions for cors",
|
| 5 |
+
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cors",
|
| 6 |
+
"license": "MIT",
|
| 7 |
+
"contributors": [
|
| 8 |
+
{
|
| 9 |
+
"name": "Alan Plum",
|
| 10 |
+
"githubUsername": "pluma",
|
| 11 |
+
"url": "https://github.com/pluma"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"name": "Gaurav Sharma",
|
| 15 |
+
"githubUsername": "gtpan77",
|
| 16 |
+
"url": "https://github.com/gtpan77"
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"name": "Sebastian Beltran",
|
| 20 |
+
"githubUsername": "bjohansebas",
|
| 21 |
+
"url": "https://github.com/bjohansebas"
|
| 22 |
+
}
|
| 23 |
+
],
|
| 24 |
+
"main": "",
|
| 25 |
+
"types": "index.d.ts",
|
| 26 |
+
"repository": {
|
| 27 |
+
"type": "git",
|
| 28 |
+
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
| 29 |
+
"directory": "types/cors"
|
| 30 |
+
},
|
| 31 |
+
"scripts": {},
|
| 32 |
+
"dependencies": {
|
| 33 |
+
"@types/node": "*"
|
| 34 |
+
},
|
| 35 |
+
"peerDependencies": {},
|
| 36 |
+
"typesPublisherContentHash": "a090e558c5f443573318c2955deecddc840bd8dfaac7cdedf31c7f6ede8d0b47",
|
| 37 |
+
"typeScriptVersion": "5.1"
|
| 38 |
+
}
|
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
|
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: Wed, 10 Jun 2026 22:15:09 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), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [David Junger](https://github.com/touffy), [Mohsen Azimi](https://github.com/mohsen1), [Nikita Galkin](https://github.com/galkin), [Sebastian Silbermann](https://github.com/eps1lon), [Wilco Bakker](https://github.com/WilcoBakker), [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), [Dmitry Semigradsky](https://github.com/Semigradsky), [René](https://github.com/Renegade334), and [Yagiz Nizipli](https://github.com/anonrig).
|
node_modules/@types/node/assert.d.ts
ADDED
|
@@ -0,0 +1,950 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:assert" {
|
| 2 |
+
import strict = require("node:assert/strict");
|
| 3 |
+
/**
|
| 4 |
+
* An alias of {@link assert.ok}.
|
| 5 |
+
* @since v0.5.9
|
| 6 |
+
* @param value The input that is checked for being truthy.
|
| 7 |
+
*/
|
| 8 |
+
function assert(value: unknown, message?: string | Error): asserts value;
|
| 9 |
+
const kOptions: unique symbol;
|
| 10 |
+
namespace assert {
|
| 11 |
+
type AssertMethodNames =
|
| 12 |
+
| "deepEqual"
|
| 13 |
+
| "deepStrictEqual"
|
| 14 |
+
| "doesNotMatch"
|
| 15 |
+
| "doesNotReject"
|
| 16 |
+
| "doesNotThrow"
|
| 17 |
+
| "equal"
|
| 18 |
+
| "fail"
|
| 19 |
+
| "ifError"
|
| 20 |
+
| "match"
|
| 21 |
+
| "notDeepEqual"
|
| 22 |
+
| "notDeepStrictEqual"
|
| 23 |
+
| "notEqual"
|
| 24 |
+
| "notStrictEqual"
|
| 25 |
+
| "ok"
|
| 26 |
+
| "partialDeepStrictEqual"
|
| 27 |
+
| "rejects"
|
| 28 |
+
| "strictEqual"
|
| 29 |
+
| "throws";
|
| 30 |
+
interface AssertOptions {
|
| 31 |
+
/**
|
| 32 |
+
* If set to `'full'`, shows the full diff in assertion errors.
|
| 33 |
+
* @default 'simple'
|
| 34 |
+
*/
|
| 35 |
+
diff?: "simple" | "full" | undefined;
|
| 36 |
+
/**
|
| 37 |
+
* If set to `true`, non-strict methods behave like their
|
| 38 |
+
* corresponding strict methods.
|
| 39 |
+
* @default true
|
| 40 |
+
*/
|
| 41 |
+
strict?: boolean | undefined;
|
| 42 |
+
/**
|
| 43 |
+
* If set to `true`, skips prototype and constructor
|
| 44 |
+
* comparison in deep equality checks.
|
| 45 |
+
* @since v24.9.0
|
| 46 |
+
* @default false
|
| 47 |
+
*/
|
| 48 |
+
skipPrototype?: boolean | undefined;
|
| 49 |
+
}
|
| 50 |
+
interface Assert extends Pick<typeof assert, AssertMethodNames> {
|
| 51 |
+
readonly [kOptions]: AssertOptions & { strict: false };
|
| 52 |
+
}
|
| 53 |
+
interface AssertStrict extends Pick<typeof strict, AssertMethodNames> {
|
| 54 |
+
readonly [kOptions]: AssertOptions & { strict: true };
|
| 55 |
+
}
|
| 56 |
+
/**
|
| 57 |
+
* The `Assert` class allows creating independent assertion instances with custom options.
|
| 58 |
+
* @since v24.6.0
|
| 59 |
+
*/
|
| 60 |
+
var Assert: {
|
| 61 |
+
/**
|
| 62 |
+
* Creates a new assertion instance. The `diff` option controls the verbosity of diffs in assertion error messages.
|
| 63 |
+
*
|
| 64 |
+
* ```js
|
| 65 |
+
* const { Assert } = require('node:assert');
|
| 66 |
+
* const assertInstance = new Assert({ diff: 'full' });
|
| 67 |
+
* assertInstance.deepStrictEqual({ a: 1 }, { a: 2 });
|
| 68 |
+
* // Shows a full diff in the error message.
|
| 69 |
+
* ```
|
| 70 |
+
*
|
| 71 |
+
* **Important**: When destructuring assertion methods from an `Assert` instance,
|
| 72 |
+
* the methods lose their connection to the instance's configuration options (such
|
| 73 |
+
* as `diff`, `strict`, and `skipPrototype` settings).
|
| 74 |
+
* The destructured methods will fall back to default behavior instead.
|
| 75 |
+
*
|
| 76 |
+
* ```js
|
| 77 |
+
* const myAssert = new Assert({ diff: 'full' });
|
| 78 |
+
*
|
| 79 |
+
* // This works as expected - uses 'full' diff
|
| 80 |
+
* myAssert.strictEqual({ a: 1 }, { b: { c: 1 } });
|
| 81 |
+
*
|
| 82 |
+
* // This loses the 'full' diff setting - falls back to default 'simple' diff
|
| 83 |
+
* const { strictEqual } = myAssert;
|
| 84 |
+
* strictEqual({ a: 1 }, { b: { c: 1 } });
|
| 85 |
+
* ```
|
| 86 |
+
*
|
| 87 |
+
* The `skipPrototype` option affects all deep equality methods:
|
| 88 |
+
*
|
| 89 |
+
* ```js
|
| 90 |
+
* class Foo {
|
| 91 |
+
* constructor(a) {
|
| 92 |
+
* this.a = a;
|
| 93 |
+
* }
|
| 94 |
+
* }
|
| 95 |
+
*
|
| 96 |
+
* class Bar {
|
| 97 |
+
* constructor(a) {
|
| 98 |
+
* this.a = a;
|
| 99 |
+
* }
|
| 100 |
+
* }
|
| 101 |
+
*
|
| 102 |
+
* const foo = new Foo(1);
|
| 103 |
+
* const bar = new Bar(1);
|
| 104 |
+
*
|
| 105 |
+
* // Default behavior - fails due to different constructors
|
| 106 |
+
* const assert1 = new Assert();
|
| 107 |
+
* assert1.deepStrictEqual(foo, bar); // AssertionError
|
| 108 |
+
*
|
| 109 |
+
* // Skip prototype comparison - passes if properties are equal
|
| 110 |
+
* const assert2 = new Assert({ skipPrototype: true });
|
| 111 |
+
* assert2.deepStrictEqual(foo, bar); // OK
|
| 112 |
+
* ```
|
| 113 |
+
*
|
| 114 |
+
* When destructured, methods lose access to the instance's `this` context and revert to default assertion behavior
|
| 115 |
+
* (diff: 'simple', non-strict mode).
|
| 116 |
+
* To maintain custom options when using destructured methods, avoid
|
| 117 |
+
* destructuring and call methods directly on the instance.
|
| 118 |
+
* @since v24.6.0
|
| 119 |
+
*/
|
| 120 |
+
new(
|
| 121 |
+
options?: AssertOptions & { strict?: true | undefined },
|
| 122 |
+
): AssertStrict;
|
| 123 |
+
new(
|
| 124 |
+
options: AssertOptions,
|
| 125 |
+
): Assert;
|
| 126 |
+
};
|
| 127 |
+
interface AssertionErrorOptions {
|
| 128 |
+
/**
|
| 129 |
+
* If provided, the error message is set to this value.
|
| 130 |
+
*/
|
| 131 |
+
message?: string | undefined;
|
| 132 |
+
/**
|
| 133 |
+
* The `actual` property on the error instance.
|
| 134 |
+
*/
|
| 135 |
+
actual?: unknown;
|
| 136 |
+
/**
|
| 137 |
+
* The `expected` property on the error instance.
|
| 138 |
+
*/
|
| 139 |
+
expected?: unknown;
|
| 140 |
+
/**
|
| 141 |
+
* The `operator` property on the error instance.
|
| 142 |
+
*/
|
| 143 |
+
operator?: string | undefined;
|
| 144 |
+
/**
|
| 145 |
+
* If provided, the generated stack trace omits frames before this function.
|
| 146 |
+
*/
|
| 147 |
+
stackStartFn?: Function | undefined;
|
| 148 |
+
/**
|
| 149 |
+
* If set to `'full'`, shows the full diff in assertion errors.
|
| 150 |
+
* @default 'simple'
|
| 151 |
+
*/
|
| 152 |
+
diff?: "simple" | "full" | undefined;
|
| 153 |
+
}
|
| 154 |
+
/**
|
| 155 |
+
* Indicates the failure of an assertion. All errors thrown by the `node:assert` module will be instances of the `AssertionError` class.
|
| 156 |
+
*/
|
| 157 |
+
class AssertionError extends Error {
|
| 158 |
+
constructor(options: AssertionErrorOptions);
|
| 159 |
+
/**
|
| 160 |
+
* Set to the `actual` argument for methods such as {@link assert.strictEqual()}.
|
| 161 |
+
*/
|
| 162 |
+
actual: unknown;
|
| 163 |
+
/**
|
| 164 |
+
* Set to the `expected` argument for methods such as {@link assert.strictEqual()}.
|
| 165 |
+
*/
|
| 166 |
+
expected: unknown;
|
| 167 |
+
/**
|
| 168 |
+
* Indicates if the message was auto-generated (`true`) or not.
|
| 169 |
+
*/
|
| 170 |
+
generatedMessage: boolean;
|
| 171 |
+
/**
|
| 172 |
+
* Value is always `ERR_ASSERTION` to show that the error is an assertion error.
|
| 173 |
+
*/
|
| 174 |
+
code: "ERR_ASSERTION";
|
| 175 |
+
/**
|
| 176 |
+
* Set to the passed in operator value.
|
| 177 |
+
*/
|
| 178 |
+
operator: string;
|
| 179 |
+
}
|
| 180 |
+
type AssertPredicate = RegExp | (new() => object) | ((thrown: unknown) => boolean) | object | Error;
|
| 181 |
+
/**
|
| 182 |
+
* Throws an `AssertionError` with the provided error message or a default
|
| 183 |
+
* error message. If the `message` parameter is an instance of an `Error` then
|
| 184 |
+
* it will be thrown instead of the `AssertionError`.
|
| 185 |
+
*
|
| 186 |
+
* ```js
|
| 187 |
+
* import assert from 'node:assert/strict';
|
| 188 |
+
*
|
| 189 |
+
* assert.fail();
|
| 190 |
+
* // AssertionError [ERR_ASSERTION]: Failed
|
| 191 |
+
*
|
| 192 |
+
* assert.fail('boom');
|
| 193 |
+
* // AssertionError [ERR_ASSERTION]: boom
|
| 194 |
+
*
|
| 195 |
+
* assert.fail(new TypeError('need array'));
|
| 196 |
+
* // TypeError: need array
|
| 197 |
+
* ```
|
| 198 |
+
* @since v0.1.21
|
| 199 |
+
* @param [message='Failed']
|
| 200 |
+
*/
|
| 201 |
+
function fail(message?: string | Error): never;
|
| 202 |
+
/**
|
| 203 |
+
* Tests if `value` is truthy. It is equivalent to `assert.equal(!!value, true, message)`.
|
| 204 |
+
*
|
| 205 |
+
* 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
|
| 206 |
+
* error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
| 207 |
+
* If no arguments are passed in at all `message` will be set to the string:`` 'No value argument passed to `assert.ok()`' ``.
|
| 208 |
+
*
|
| 209 |
+
* Be aware that in the `repl` the error message will be different to the one
|
| 210 |
+
* thrown in a file! See below for further details.
|
| 211 |
+
*
|
| 212 |
+
* ```js
|
| 213 |
+
* import assert from 'node:assert/strict';
|
| 214 |
+
*
|
| 215 |
+
* assert.ok(true);
|
| 216 |
+
* // OK
|
| 217 |
+
* assert.ok(1);
|
| 218 |
+
* // OK
|
| 219 |
+
*
|
| 220 |
+
* assert.ok();
|
| 221 |
+
* // AssertionError: No value argument passed to `assert.ok()`
|
| 222 |
+
*
|
| 223 |
+
* assert.ok(false, 'it\'s false');
|
| 224 |
+
* // AssertionError: it's false
|
| 225 |
+
*
|
| 226 |
+
* // In the repl:
|
| 227 |
+
* assert.ok(typeof 123 === 'string');
|
| 228 |
+
* // AssertionError: false == true
|
| 229 |
+
*
|
| 230 |
+
* // In a file (e.g. test.js):
|
| 231 |
+
* assert.ok(typeof 123 === 'string');
|
| 232 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
| 233 |
+
* //
|
| 234 |
+
* // assert.ok(typeof 123 === 'string')
|
| 235 |
+
*
|
| 236 |
+
* assert.ok(false);
|
| 237 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
| 238 |
+
* //
|
| 239 |
+
* // assert.ok(false)
|
| 240 |
+
*
|
| 241 |
+
* assert.ok(0);
|
| 242 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
| 243 |
+
* //
|
| 244 |
+
* // assert.ok(0)
|
| 245 |
+
* ```
|
| 246 |
+
*
|
| 247 |
+
* ```js
|
| 248 |
+
* import assert from 'node:assert/strict';
|
| 249 |
+
*
|
| 250 |
+
* // Using `assert()` works the same:
|
| 251 |
+
* assert(2 + 2 > 5);;
|
| 252 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
| 253 |
+
* //
|
| 254 |
+
* // assert(2 + 2 > 5)
|
| 255 |
+
* ```
|
| 256 |
+
* @since v0.1.21
|
| 257 |
+
*/
|
| 258 |
+
function ok(value: unknown, message?: string | Error): asserts value;
|
| 259 |
+
/**
|
| 260 |
+
* **Strict assertion mode**
|
| 261 |
+
*
|
| 262 |
+
* An alias of {@link strictEqual}.
|
| 263 |
+
*
|
| 264 |
+
* **Legacy assertion mode**
|
| 265 |
+
*
|
| 266 |
+
* > Stability: 3 - Legacy: Use {@link strictEqual} instead.
|
| 267 |
+
*
|
| 268 |
+
* Tests shallow, coercive equality between the `actual` and `expected` parameters
|
| 269 |
+
* using the [`==` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality). `NaN` is specially handled
|
| 270 |
+
* and treated as being identical if both sides are `NaN`.
|
| 271 |
+
*
|
| 272 |
+
* ```js
|
| 273 |
+
* import assert from 'node:assert';
|
| 274 |
+
*
|
| 275 |
+
* assert.equal(1, 1);
|
| 276 |
+
* // OK, 1 == 1
|
| 277 |
+
* assert.equal(1, '1');
|
| 278 |
+
* // OK, 1 == '1'
|
| 279 |
+
* assert.equal(NaN, NaN);
|
| 280 |
+
* // OK
|
| 281 |
+
*
|
| 282 |
+
* assert.equal(1, 2);
|
| 283 |
+
* // AssertionError: 1 == 2
|
| 284 |
+
* assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
|
| 285 |
+
* // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
|
| 286 |
+
* ```
|
| 287 |
+
*
|
| 288 |
+
* 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
|
| 289 |
+
* error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
| 290 |
+
* @since v0.1.21
|
| 291 |
+
*/
|
| 292 |
+
function equal(actual: unknown, expected: unknown, message?: string | Error): void;
|
| 293 |
+
/**
|
| 294 |
+
* **Strict assertion mode**
|
| 295 |
+
*
|
| 296 |
+
* An alias of {@link notStrictEqual}.
|
| 297 |
+
*
|
| 298 |
+
* **Legacy assertion mode**
|
| 299 |
+
*
|
| 300 |
+
* > Stability: 3 - Legacy: Use {@link notStrictEqual} instead.
|
| 301 |
+
*
|
| 302 |
+
* Tests shallow, coercive inequality with the [`!=` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality). `NaN` is
|
| 303 |
+
* specially handled and treated as being identical if both sides are `NaN`.
|
| 304 |
+
*
|
| 305 |
+
* ```js
|
| 306 |
+
* import assert from 'node:assert';
|
| 307 |
+
*
|
| 308 |
+
* assert.notEqual(1, 2);
|
| 309 |
+
* // OK
|
| 310 |
+
*
|
| 311 |
+
* assert.notEqual(1, 1);
|
| 312 |
+
* // AssertionError: 1 != 1
|
| 313 |
+
*
|
| 314 |
+
* assert.notEqual(1, '1');
|
| 315 |
+
* // AssertionError: 1 != '1'
|
| 316 |
+
* ```
|
| 317 |
+
*
|
| 318 |
+
* 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
|
| 319 |
+
* 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 notEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
| 323 |
+
/**
|
| 324 |
+
* **Strict assertion mode**
|
| 325 |
+
*
|
| 326 |
+
* An alias of {@link deepStrictEqual}.
|
| 327 |
+
*
|
| 328 |
+
* **Legacy assertion mode**
|
| 329 |
+
*
|
| 330 |
+
* > Stability: 3 - Legacy: Use {@link deepStrictEqual} instead.
|
| 331 |
+
*
|
| 332 |
+
* Tests for deep equality between the `actual` and `expected` parameters. Consider
|
| 333 |
+
* using {@link deepStrictEqual} instead. {@link deepEqual} can have
|
| 334 |
+
* surprising results.
|
| 335 |
+
*
|
| 336 |
+
* _Deep equality_ means that the enumerable "own" properties of child objects
|
| 337 |
+
* are also recursively evaluated by the following rules.
|
| 338 |
+
* @since v0.1.21
|
| 339 |
+
*/
|
| 340 |
+
function deepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
| 341 |
+
/**
|
| 342 |
+
* **Strict assertion mode**
|
| 343 |
+
*
|
| 344 |
+
* An alias of {@link notDeepStrictEqual}.
|
| 345 |
+
*
|
| 346 |
+
* **Legacy assertion mode**
|
| 347 |
+
*
|
| 348 |
+
* > Stability: 3 - Legacy: Use {@link notDeepStrictEqual} instead.
|
| 349 |
+
*
|
| 350 |
+
* Tests for any deep inequality. Opposite of {@link deepEqual}.
|
| 351 |
+
*
|
| 352 |
+
* ```js
|
| 353 |
+
* import assert from 'node:assert';
|
| 354 |
+
*
|
| 355 |
+
* const obj1 = {
|
| 356 |
+
* a: {
|
| 357 |
+
* b: 1,
|
| 358 |
+
* },
|
| 359 |
+
* };
|
| 360 |
+
* const obj2 = {
|
| 361 |
+
* a: {
|
| 362 |
+
* b: 2,
|
| 363 |
+
* },
|
| 364 |
+
* };
|
| 365 |
+
* const obj3 = {
|
| 366 |
+
* a: {
|
| 367 |
+
* b: 1,
|
| 368 |
+
* },
|
| 369 |
+
* };
|
| 370 |
+
* const obj4 = { __proto__: obj1 };
|
| 371 |
+
*
|
| 372 |
+
* assert.notDeepEqual(obj1, obj1);
|
| 373 |
+
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
| 374 |
+
*
|
| 375 |
+
* assert.notDeepEqual(obj1, obj2);
|
| 376 |
+
* // OK
|
| 377 |
+
*
|
| 378 |
+
* assert.notDeepEqual(obj1, obj3);
|
| 379 |
+
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
| 380 |
+
*
|
| 381 |
+
* assert.notDeepEqual(obj1, obj4);
|
| 382 |
+
* // OK
|
| 383 |
+
* ```
|
| 384 |
+
*
|
| 385 |
+
* 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
|
| 386 |
+
* error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown
|
| 387 |
+
* instead of the `AssertionError`.
|
| 388 |
+
* @since v0.1.21
|
| 389 |
+
*/
|
| 390 |
+
function notDeepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
| 391 |
+
/**
|
| 392 |
+
* Tests strict equality between the `actual` and `expected` parameters as
|
| 393 |
+
* determined by [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
| 394 |
+
*
|
| 395 |
+
* ```js
|
| 396 |
+
* import assert from 'node:assert/strict';
|
| 397 |
+
*
|
| 398 |
+
* assert.strictEqual(1, 2);
|
| 399 |
+
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
| 400 |
+
* //
|
| 401 |
+
* // 1 !== 2
|
| 402 |
+
*
|
| 403 |
+
* assert.strictEqual(1, 1);
|
| 404 |
+
* // OK
|
| 405 |
+
*
|
| 406 |
+
* assert.strictEqual('Hello foobar', 'Hello World!');
|
| 407 |
+
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
| 408 |
+
* // + actual - expected
|
| 409 |
+
* //
|
| 410 |
+
* // + 'Hello foobar'
|
| 411 |
+
* // - 'Hello World!'
|
| 412 |
+
* // ^
|
| 413 |
+
*
|
| 414 |
+
* const apples = 1;
|
| 415 |
+
* const oranges = 2;
|
| 416 |
+
* assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`);
|
| 417 |
+
* // AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2
|
| 418 |
+
*
|
| 419 |
+
* assert.strictEqual(1, '1', new TypeError('Inputs are not identical'));
|
| 420 |
+
* // TypeError: Inputs are not identical
|
| 421 |
+
* ```
|
| 422 |
+
*
|
| 423 |
+
* 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
|
| 424 |
+
* default error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown
|
| 425 |
+
* instead of the `AssertionError`.
|
| 426 |
+
* @since v0.1.21
|
| 427 |
+
*/
|
| 428 |
+
function strictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
| 429 |
+
/**
|
| 430 |
+
* Tests strict inequality between the `actual` and `expected` parameters as
|
| 431 |
+
* determined by [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
| 432 |
+
*
|
| 433 |
+
* ```js
|
| 434 |
+
* import assert from 'node:assert/strict';
|
| 435 |
+
*
|
| 436 |
+
* assert.notStrictEqual(1, 2);
|
| 437 |
+
* // OK
|
| 438 |
+
*
|
| 439 |
+
* assert.notStrictEqual(1, 1);
|
| 440 |
+
* // AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to:
|
| 441 |
+
* //
|
| 442 |
+
* // 1
|
| 443 |
+
*
|
| 444 |
+
* assert.notStrictEqual(1, '1');
|
| 445 |
+
* // OK
|
| 446 |
+
* ```
|
| 447 |
+
*
|
| 448 |
+
* 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
|
| 449 |
+
* default error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown
|
| 450 |
+
* instead of the `AssertionError`.
|
| 451 |
+
* @since v0.1.21
|
| 452 |
+
*/
|
| 453 |
+
function notStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
| 454 |
+
/**
|
| 455 |
+
* Tests for deep equality between the `actual` and `expected` parameters.
|
| 456 |
+
* "Deep" equality means that the enumerable "own" properties of child objects
|
| 457 |
+
* are recursively evaluated also by the following rules.
|
| 458 |
+
* @since v1.2.0
|
| 459 |
+
*/
|
| 460 |
+
function deepStrictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
| 461 |
+
/**
|
| 462 |
+
* Tests for deep strict inequality. Opposite of {@link deepStrictEqual}.
|
| 463 |
+
*
|
| 464 |
+
* ```js
|
| 465 |
+
* import assert from 'node:assert/strict';
|
| 466 |
+
*
|
| 467 |
+
* assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
|
| 468 |
+
* // OK
|
| 469 |
+
* ```
|
| 470 |
+
*
|
| 471 |
+
* If the values are deeply and strictly equal, an `AssertionError` is thrown
|
| 472 |
+
* with a `message` property set equal to the value of the `message` parameter. If
|
| 473 |
+
* the `message` parameter is undefined, a default error message is assigned. If
|
| 474 |
+
* the `message` parameter is an instance of an `Error` then it will be thrown
|
| 475 |
+
* instead of the `AssertionError`.
|
| 476 |
+
* @since v1.2.0
|
| 477 |
+
*/
|
| 478 |
+
function notDeepStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
| 479 |
+
/**
|
| 480 |
+
* Expects the function `fn` to throw an error.
|
| 481 |
+
*
|
| 482 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
| 483 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
|
| 484 |
+
* a validation object where each property will be tested for strict deep equality,
|
| 485 |
+
* or an instance of error where each property will be tested for strict deep
|
| 486 |
+
* equality including the non-enumerable `message` and `name` properties. When
|
| 487 |
+
* using an object, it is also possible to use a regular expression, when
|
| 488 |
+
* validating against a string property. See below for examples.
|
| 489 |
+
*
|
| 490 |
+
* 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
|
| 491 |
+
* fails.
|
| 492 |
+
*
|
| 493 |
+
* Custom validation object/error instance:
|
| 494 |
+
*
|
| 495 |
+
* ```js
|
| 496 |
+
* import assert from 'node:assert/strict';
|
| 497 |
+
*
|
| 498 |
+
* const err = new TypeError('Wrong value');
|
| 499 |
+
* err.code = 404;
|
| 500 |
+
* err.foo = 'bar';
|
| 501 |
+
* err.info = {
|
| 502 |
+
* nested: true,
|
| 503 |
+
* baz: 'text',
|
| 504 |
+
* };
|
| 505 |
+
* err.reg = /abc/i;
|
| 506 |
+
*
|
| 507 |
+
* assert.throws(
|
| 508 |
+
* () => {
|
| 509 |
+
* throw err;
|
| 510 |
+
* },
|
| 511 |
+
* {
|
| 512 |
+
* name: 'TypeError',
|
| 513 |
+
* message: 'Wrong value',
|
| 514 |
+
* info: {
|
| 515 |
+
* nested: true,
|
| 516 |
+
* baz: 'text',
|
| 517 |
+
* },
|
| 518 |
+
* // Only properties on the validation object will be tested for.
|
| 519 |
+
* // Using nested objects requires all properties to be present. Otherwise
|
| 520 |
+
* // the validation is going to fail.
|
| 521 |
+
* },
|
| 522 |
+
* );
|
| 523 |
+
*
|
| 524 |
+
* // Using regular expressions to validate error properties:
|
| 525 |
+
* assert.throws(
|
| 526 |
+
* () => {
|
| 527 |
+
* throw err;
|
| 528 |
+
* },
|
| 529 |
+
* {
|
| 530 |
+
* // The `name` and `message` properties are strings and using regular
|
| 531 |
+
* // expressions on those will match against the string. If they fail, an
|
| 532 |
+
* // error is thrown.
|
| 533 |
+
* name: /^TypeError$/,
|
| 534 |
+
* message: /Wrong/,
|
| 535 |
+
* foo: 'bar',
|
| 536 |
+
* info: {
|
| 537 |
+
* nested: true,
|
| 538 |
+
* // It is not possible to use regular expressions for nested properties!
|
| 539 |
+
* baz: 'text',
|
| 540 |
+
* },
|
| 541 |
+
* // The `reg` property contains a regular expression and only if the
|
| 542 |
+
* // validation object contains an identical regular expression, it is going
|
| 543 |
+
* // to pass.
|
| 544 |
+
* reg: /abc/i,
|
| 545 |
+
* },
|
| 546 |
+
* );
|
| 547 |
+
*
|
| 548 |
+
* // Fails due to the different `message` and `name` properties:
|
| 549 |
+
* assert.throws(
|
| 550 |
+
* () => {
|
| 551 |
+
* const otherErr = new Error('Not found');
|
| 552 |
+
* // Copy all enumerable properties from `err` to `otherErr`.
|
| 553 |
+
* for (const [key, value] of Object.entries(err)) {
|
| 554 |
+
* otherErr[key] = value;
|
| 555 |
+
* }
|
| 556 |
+
* throw otherErr;
|
| 557 |
+
* },
|
| 558 |
+
* // The error's `message` and `name` properties will also be checked when using
|
| 559 |
+
* // an error as validation object.
|
| 560 |
+
* err,
|
| 561 |
+
* );
|
| 562 |
+
* ```
|
| 563 |
+
*
|
| 564 |
+
* Validate instanceof using constructor:
|
| 565 |
+
*
|
| 566 |
+
* ```js
|
| 567 |
+
* import assert from 'node:assert/strict';
|
| 568 |
+
*
|
| 569 |
+
* assert.throws(
|
| 570 |
+
* () => {
|
| 571 |
+
* throw new Error('Wrong value');
|
| 572 |
+
* },
|
| 573 |
+
* Error,
|
| 574 |
+
* );
|
| 575 |
+
* ```
|
| 576 |
+
*
|
| 577 |
+
* Validate error message using [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions):
|
| 578 |
+
*
|
| 579 |
+
* Using a regular expression runs `.toString` on the error object, and will
|
| 580 |
+
* therefore also include the error name.
|
| 581 |
+
*
|
| 582 |
+
* ```js
|
| 583 |
+
* import assert from 'node:assert/strict';
|
| 584 |
+
*
|
| 585 |
+
* assert.throws(
|
| 586 |
+
* () => {
|
| 587 |
+
* throw new Error('Wrong value');
|
| 588 |
+
* },
|
| 589 |
+
* /^Error: Wrong value$/,
|
| 590 |
+
* );
|
| 591 |
+
* ```
|
| 592 |
+
*
|
| 593 |
+
* Custom error validation:
|
| 594 |
+
*
|
| 595 |
+
* The function must return `true` to indicate all internal validations passed.
|
| 596 |
+
* It will otherwise fail with an `AssertionError`.
|
| 597 |
+
*
|
| 598 |
+
* ```js
|
| 599 |
+
* import assert from 'node:assert/strict';
|
| 600 |
+
*
|
| 601 |
+
* assert.throws(
|
| 602 |
+
* () => {
|
| 603 |
+
* throw new Error('Wrong value');
|
| 604 |
+
* },
|
| 605 |
+
* (err) => {
|
| 606 |
+
* assert(err instanceof Error);
|
| 607 |
+
* assert(/value/.test(err));
|
| 608 |
+
* // Avoid returning anything from validation functions besides `true`.
|
| 609 |
+
* // Otherwise, it's not clear what part of the validation failed. Instead,
|
| 610 |
+
* // throw an error about the specific validation that failed (as done in this
|
| 611 |
+
* // example) and add as much helpful debugging information to that error as
|
| 612 |
+
* // possible.
|
| 613 |
+
* return true;
|
| 614 |
+
* },
|
| 615 |
+
* 'unexpected error',
|
| 616 |
+
* );
|
| 617 |
+
* ```
|
| 618 |
+
*
|
| 619 |
+
* `error` cannot be a string. If a string is provided as the second
|
| 620 |
+
* 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
|
| 621 |
+
* message as the thrown error message is going to result in an `ERR_AMBIGUOUS_ARGUMENT` error. Please read the example below carefully if using
|
| 622 |
+
* a string as the second argument gets considered:
|
| 623 |
+
*
|
| 624 |
+
* ```js
|
| 625 |
+
* import assert from 'node:assert/strict';
|
| 626 |
+
*
|
| 627 |
+
* function throwingFirst() {
|
| 628 |
+
* throw new Error('First');
|
| 629 |
+
* }
|
| 630 |
+
*
|
| 631 |
+
* function throwingSecond() {
|
| 632 |
+
* throw new Error('Second');
|
| 633 |
+
* }
|
| 634 |
+
*
|
| 635 |
+
* function notThrowing() {}
|
| 636 |
+
*
|
| 637 |
+
* // The second argument is a string and the input function threw an Error.
|
| 638 |
+
* // The first case will not throw as it does not match for the error message
|
| 639 |
+
* // thrown by the input function!
|
| 640 |
+
* assert.throws(throwingFirst, 'Second');
|
| 641 |
+
* // In the next example the message has no benefit over the message from the
|
| 642 |
+
* // error and since it is not clear if the user intended to actually match
|
| 643 |
+
* // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.
|
| 644 |
+
* assert.throws(throwingSecond, 'Second');
|
| 645 |
+
* // TypeError [ERR_AMBIGUOUS_ARGUMENT]
|
| 646 |
+
*
|
| 647 |
+
* // The string is only used (as message) in case the function does not throw:
|
| 648 |
+
* assert.throws(notThrowing, 'Second');
|
| 649 |
+
* // AssertionError [ERR_ASSERTION]: Missing expected exception: Second
|
| 650 |
+
*
|
| 651 |
+
* // If it was intended to match for the error message do this instead:
|
| 652 |
+
* // It does not throw because the error messages match.
|
| 653 |
+
* assert.throws(throwingSecond, /Second$/);
|
| 654 |
+
*
|
| 655 |
+
* // If the error message does not match, an AssertionError is thrown.
|
| 656 |
+
* assert.throws(throwingFirst, /Second$/);
|
| 657 |
+
* // AssertionError [ERR_ASSERTION]
|
| 658 |
+
* ```
|
| 659 |
+
*
|
| 660 |
+
* Due to the confusing error-prone notation, avoid a string as the second
|
| 661 |
+
* argument.
|
| 662 |
+
* @since v0.1.21
|
| 663 |
+
*/
|
| 664 |
+
function throws(block: () => unknown, message?: string | Error): void;
|
| 665 |
+
function throws(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
|
| 666 |
+
/**
|
| 667 |
+
* Asserts that the function `fn` does not throw an error.
|
| 668 |
+
*
|
| 669 |
+
* Using `assert.doesNotThrow()` is actually not useful because there
|
| 670 |
+
* is no benefit in catching an error and then rethrowing it. Instead, consider
|
| 671 |
+
* adding a comment next to the specific code path that should not throw and keep
|
| 672 |
+
* error messages as expressive as possible.
|
| 673 |
+
*
|
| 674 |
+
* When `assert.doesNotThrow()` is called, it will immediately call the `fn` function.
|
| 675 |
+
*
|
| 676 |
+
* 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
|
| 677 |
+
* different type, or if the `error` parameter is undefined, the error is
|
| 678 |
+
* propagated back to the caller.
|
| 679 |
+
*
|
| 680 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
| 681 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), or a validation
|
| 682 |
+
* function. See {@link throws} for more details.
|
| 683 |
+
*
|
| 684 |
+
* The following, for instance, will throw the `TypeError` because there is no
|
| 685 |
+
* matching error type in the assertion:
|
| 686 |
+
*
|
| 687 |
+
* ```js
|
| 688 |
+
* import assert from 'node:assert/strict';
|
| 689 |
+
*
|
| 690 |
+
* assert.doesNotThrow(
|
| 691 |
+
* () => {
|
| 692 |
+
* throw new TypeError('Wrong value');
|
| 693 |
+
* },
|
| 694 |
+
* SyntaxError,
|
| 695 |
+
* );
|
| 696 |
+
* ```
|
| 697 |
+
*
|
| 698 |
+
* However, the following will result in an `AssertionError` with the message
|
| 699 |
+
* 'Got unwanted exception...':
|
| 700 |
+
*
|
| 701 |
+
* ```js
|
| 702 |
+
* import assert from 'node:assert/strict';
|
| 703 |
+
*
|
| 704 |
+
* assert.doesNotThrow(
|
| 705 |
+
* () => {
|
| 706 |
+
* throw new TypeError('Wrong value');
|
| 707 |
+
* },
|
| 708 |
+
* TypeError,
|
| 709 |
+
* );
|
| 710 |
+
* ```
|
| 711 |
+
*
|
| 712 |
+
* 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:
|
| 713 |
+
*
|
| 714 |
+
* ```js
|
| 715 |
+
* import assert from 'node:assert/strict';
|
| 716 |
+
*
|
| 717 |
+
* assert.doesNotThrow(
|
| 718 |
+
* () => {
|
| 719 |
+
* throw new TypeError('Wrong value');
|
| 720 |
+
* },
|
| 721 |
+
* /Wrong value/,
|
| 722 |
+
* 'Whoops',
|
| 723 |
+
* );
|
| 724 |
+
* // Throws: AssertionError: Got unwanted exception: Whoops
|
| 725 |
+
* ```
|
| 726 |
+
* @since v0.1.21
|
| 727 |
+
*/
|
| 728 |
+
function doesNotThrow(block: () => unknown, message?: string | Error): void;
|
| 729 |
+
function doesNotThrow(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
|
| 730 |
+
/**
|
| 731 |
+
* Throws `value` if `value` is not `undefined` or `null`. This is useful when
|
| 732 |
+
* testing the `error` argument in callbacks. The stack trace contains all frames
|
| 733 |
+
* from the error passed to `ifError()` including the potential new frames for `ifError()` itself.
|
| 734 |
+
*
|
| 735 |
+
* ```js
|
| 736 |
+
* import assert from 'node:assert/strict';
|
| 737 |
+
*
|
| 738 |
+
* assert.ifError(null);
|
| 739 |
+
* // OK
|
| 740 |
+
* assert.ifError(0);
|
| 741 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0
|
| 742 |
+
* assert.ifError('error');
|
| 743 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'
|
| 744 |
+
* assert.ifError(new Error());
|
| 745 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error
|
| 746 |
+
*
|
| 747 |
+
* // Create some random error frames.
|
| 748 |
+
* let err;
|
| 749 |
+
* (function errorFrame() {
|
| 750 |
+
* err = new Error('test error');
|
| 751 |
+
* })();
|
| 752 |
+
*
|
| 753 |
+
* (function ifErrorFrame() {
|
| 754 |
+
* assert.ifError(err);
|
| 755 |
+
* })();
|
| 756 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
|
| 757 |
+
* // at ifErrorFrame
|
| 758 |
+
* // at errorFrame
|
| 759 |
+
* ```
|
| 760 |
+
* @since v0.1.97
|
| 761 |
+
*/
|
| 762 |
+
function ifError(value: unknown): asserts value is null | undefined;
|
| 763 |
+
/**
|
| 764 |
+
* Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
|
| 765 |
+
* calls the function and awaits the returned promise to complete. It will then
|
| 766 |
+
* check that the promise is rejected.
|
| 767 |
+
*
|
| 768 |
+
* If `asyncFn` is a function and it throws an error synchronously, `assert.rejects()` will return a rejected `Promise` with that error. If the
|
| 769 |
+
* function does not return a promise, `assert.rejects()` will return a rejected `Promise` with an [ERR_INVALID_RETURN_VALUE](https://nodejs.org/docs/latest-v25.x/api/errors.html#err_invalid_return_value)
|
| 770 |
+
* error. In both cases the error handler is skipped.
|
| 771 |
+
*
|
| 772 |
+
* Besides the async nature to await the completion behaves identically to {@link throws}.
|
| 773 |
+
*
|
| 774 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
| 775 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
|
| 776 |
+
* an object where each property will be tested for, or an instance of error where
|
| 777 |
+
* each property will be tested for including the non-enumerable `message` and `name` properties.
|
| 778 |
+
*
|
| 779 |
+
* If specified, `message` will be the message provided by the `{@link AssertionError}` if the `asyncFn` fails to reject.
|
| 780 |
+
*
|
| 781 |
+
* ```js
|
| 782 |
+
* import assert from 'node:assert/strict';
|
| 783 |
+
*
|
| 784 |
+
* await assert.rejects(
|
| 785 |
+
* async () => {
|
| 786 |
+
* throw new TypeError('Wrong value');
|
| 787 |
+
* },
|
| 788 |
+
* {
|
| 789 |
+
* name: 'TypeError',
|
| 790 |
+
* message: 'Wrong value',
|
| 791 |
+
* },
|
| 792 |
+
* );
|
| 793 |
+
* ```
|
| 794 |
+
*
|
| 795 |
+
* ```js
|
| 796 |
+
* import assert from 'node:assert/strict';
|
| 797 |
+
*
|
| 798 |
+
* await assert.rejects(
|
| 799 |
+
* async () => {
|
| 800 |
+
* throw new TypeError('Wrong value');
|
| 801 |
+
* },
|
| 802 |
+
* (err) => {
|
| 803 |
+
* assert.strictEqual(err.name, 'TypeError');
|
| 804 |
+
* assert.strictEqual(err.message, 'Wrong value');
|
| 805 |
+
* return true;
|
| 806 |
+
* },
|
| 807 |
+
* );
|
| 808 |
+
* ```
|
| 809 |
+
*
|
| 810 |
+
* ```js
|
| 811 |
+
* import assert from 'node:assert/strict';
|
| 812 |
+
*
|
| 813 |
+
* assert.rejects(
|
| 814 |
+
* Promise.reject(new Error('Wrong value')),
|
| 815 |
+
* Error,
|
| 816 |
+
* ).then(() => {
|
| 817 |
+
* // ...
|
| 818 |
+
* });
|
| 819 |
+
* ```
|
| 820 |
+
*
|
| 821 |
+
* `error` cannot be a string. If a string is provided as the second argument, then `error` is assumed to
|
| 822 |
+
* be omitted and the string will be used for `message` instead. This can lead to easy-to-miss mistakes. Please read the
|
| 823 |
+
* example in {@link throws} carefully if using a string as the second argument gets considered.
|
| 824 |
+
* @since v10.0.0
|
| 825 |
+
*/
|
| 826 |
+
function rejects(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
|
| 827 |
+
function rejects(
|
| 828 |
+
block: (() => Promise<unknown>) | Promise<unknown>,
|
| 829 |
+
error: AssertPredicate,
|
| 830 |
+
message?: string | Error,
|
| 831 |
+
): Promise<void>;
|
| 832 |
+
/**
|
| 833 |
+
* Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
|
| 834 |
+
* calls the function and awaits the returned promise to complete. It will then
|
| 835 |
+
* check that the promise is not rejected.
|
| 836 |
+
*
|
| 837 |
+
* If `asyncFn` is a function and it throws an error synchronously, `assert.doesNotReject()` will return a rejected `Promise` with that error. If
|
| 838 |
+
* the function does not return a promise, `assert.doesNotReject()` will return a
|
| 839 |
+
* rejected `Promise` with an [ERR_INVALID_RETURN_VALUE](https://nodejs.org/docs/latest-v25.x/api/errors.html#err_invalid_return_value) error. In both cases
|
| 840 |
+
* the error handler is skipped.
|
| 841 |
+
*
|
| 842 |
+
* Using `assert.doesNotReject()` is actually not useful because there is little
|
| 843 |
+
* benefit in catching a rejection and then rejecting it again. Instead, consider
|
| 844 |
+
* adding a comment next to the specific code path that should not reject and keep
|
| 845 |
+
* error messages as expressive as possible.
|
| 846 |
+
*
|
| 847 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
| 848 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), or a validation
|
| 849 |
+
* function. See {@link throws} for more details.
|
| 850 |
+
*
|
| 851 |
+
* Besides the async nature to await the completion behaves identically to {@link doesNotThrow}.
|
| 852 |
+
*
|
| 853 |
+
* ```js
|
| 854 |
+
* import assert from 'node:assert/strict';
|
| 855 |
+
*
|
| 856 |
+
* await assert.doesNotReject(
|
| 857 |
+
* async () => {
|
| 858 |
+
* throw new TypeError('Wrong value');
|
| 859 |
+
* },
|
| 860 |
+
* SyntaxError,
|
| 861 |
+
* );
|
| 862 |
+
* ```
|
| 863 |
+
*
|
| 864 |
+
* ```js
|
| 865 |
+
* import assert from 'node:assert/strict';
|
| 866 |
+
*
|
| 867 |
+
* assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
|
| 868 |
+
* .then(() => {
|
| 869 |
+
* // ...
|
| 870 |
+
* });
|
| 871 |
+
* ```
|
| 872 |
+
* @since v10.0.0
|
| 873 |
+
*/
|
| 874 |
+
function doesNotReject(
|
| 875 |
+
block: (() => Promise<unknown>) | Promise<unknown>,
|
| 876 |
+
message?: string | Error,
|
| 877 |
+
): Promise<void>;
|
| 878 |
+
function doesNotReject(
|
| 879 |
+
block: (() => Promise<unknown>) | Promise<unknown>,
|
| 880 |
+
error: AssertPredicate,
|
| 881 |
+
message?: string | Error,
|
| 882 |
+
): Promise<void>;
|
| 883 |
+
/**
|
| 884 |
+
* Expects the `string` input to match the regular expression.
|
| 885 |
+
*
|
| 886 |
+
* ```js
|
| 887 |
+
* import assert from 'node:assert/strict';
|
| 888 |
+
*
|
| 889 |
+
* assert.match('I will fail', /pass/);
|
| 890 |
+
* // AssertionError [ERR_ASSERTION]: The input did not match the regular ...
|
| 891 |
+
*
|
| 892 |
+
* assert.match(123, /pass/);
|
| 893 |
+
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
| 894 |
+
*
|
| 895 |
+
* assert.match('I will pass', /pass/);
|
| 896 |
+
* // OK
|
| 897 |
+
* ```
|
| 898 |
+
*
|
| 899 |
+
* 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
|
| 900 |
+
* to the value of the `message` parameter. If the `message` parameter is
|
| 901 |
+
* undefined, a default error message is assigned. If the `message` parameter is an
|
| 902 |
+
* instance of an [Error](https://nodejs.org/docs/latest-v25.x/api/errors.html#class-error) then it will be thrown instead of the `{@link AssertionError}`.
|
| 903 |
+
* @since v13.6.0, v12.16.0
|
| 904 |
+
*/
|
| 905 |
+
function match(value: string, regExp: RegExp, message?: string | Error): void;
|
| 906 |
+
/**
|
| 907 |
+
* Expects the `string` input not to match the regular expression.
|
| 908 |
+
*
|
| 909 |
+
* ```js
|
| 910 |
+
* import assert from 'node:assert/strict';
|
| 911 |
+
*
|
| 912 |
+
* assert.doesNotMatch('I will fail', /fail/);
|
| 913 |
+
* // AssertionError [ERR_ASSERTION]: The input was expected to not match the ...
|
| 914 |
+
*
|
| 915 |
+
* assert.doesNotMatch(123, /pass/);
|
| 916 |
+
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
| 917 |
+
*
|
| 918 |
+
* assert.doesNotMatch('I will pass', /different/);
|
| 919 |
+
* // OK
|
| 920 |
+
* ```
|
| 921 |
+
*
|
| 922 |
+
* 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
|
| 923 |
+
* to the value of the `message` parameter. If the `message` parameter is
|
| 924 |
+
* undefined, a default error message is assigned. If the `message` parameter is an
|
| 925 |
+
* instance of an [Error](https://nodejs.org/docs/latest-v25.x/api/errors.html#class-error) then it will be thrown instead of the `{@link AssertionError}`.
|
| 926 |
+
* @since v13.6.0, v12.16.0
|
| 927 |
+
*/
|
| 928 |
+
function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
|
| 929 |
+
/**
|
| 930 |
+
* Tests for partial deep equality between the `actual` and `expected` parameters.
|
| 931 |
+
* "Deep" equality means that the enumerable "own" properties of child objects
|
| 932 |
+
* are recursively evaluated also by the following rules. "Partial" equality means
|
| 933 |
+
* that only properties that exist on the `expected` parameter are going to be
|
| 934 |
+
* compared.
|
| 935 |
+
*
|
| 936 |
+
* This method always passes the same test cases as `assert.deepStrictEqual()`,
|
| 937 |
+
* behaving as a super set of it.
|
| 938 |
+
* @since v22.13.0
|
| 939 |
+
*/
|
| 940 |
+
function partialDeepStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
| 941 |
+
}
|
| 942 |
+
namespace assert {
|
| 943 |
+
export { strict };
|
| 944 |
+
}
|
| 945 |
+
export = assert;
|
| 946 |
+
}
|
| 947 |
+
declare module "assert" {
|
| 948 |
+
import assert = require("node:assert");
|
| 949 |
+
export = assert;
|
| 950 |
+
}
|
node_modules/@types/node/assert/strict.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:assert/strict" {
|
| 2 |
+
import {
|
| 3 |
+
Assert,
|
| 4 |
+
AssertionError,
|
| 5 |
+
AssertionErrorOptions,
|
| 6 |
+
AssertOptions,
|
| 7 |
+
AssertPredicate,
|
| 8 |
+
AssertStrict,
|
| 9 |
+
deepStrictEqual,
|
| 10 |
+
doesNotMatch,
|
| 11 |
+
doesNotReject,
|
| 12 |
+
doesNotThrow,
|
| 13 |
+
fail,
|
| 14 |
+
ifError,
|
| 15 |
+
match,
|
| 16 |
+
notDeepStrictEqual,
|
| 17 |
+
notStrictEqual,
|
| 18 |
+
ok,
|
| 19 |
+
partialDeepStrictEqual,
|
| 20 |
+
rejects,
|
| 21 |
+
strictEqual,
|
| 22 |
+
throws,
|
| 23 |
+
} from "node:assert";
|
| 24 |
+
function strict(value: unknown, message?: string | Error): asserts value;
|
| 25 |
+
namespace strict {
|
| 26 |
+
export {
|
| 27 |
+
Assert,
|
| 28 |
+
AssertionError,
|
| 29 |
+
AssertionErrorOptions,
|
| 30 |
+
AssertOptions,
|
| 31 |
+
AssertPredicate,
|
| 32 |
+
AssertStrict,
|
| 33 |
+
deepStrictEqual,
|
| 34 |
+
deepStrictEqual as deepEqual,
|
| 35 |
+
doesNotMatch,
|
| 36 |
+
doesNotReject,
|
| 37 |
+
doesNotThrow,
|
| 38 |
+
fail,
|
| 39 |
+
ifError,
|
| 40 |
+
match,
|
| 41 |
+
notDeepStrictEqual,
|
| 42 |
+
notDeepStrictEqual as notDeepEqual,
|
| 43 |
+
notStrictEqual,
|
| 44 |
+
notStrictEqual as notEqual,
|
| 45 |
+
ok,
|
| 46 |
+
partialDeepStrictEqual,
|
| 47 |
+
rejects,
|
| 48 |
+
strict,
|
| 49 |
+
strictEqual,
|
| 50 |
+
strictEqual as equal,
|
| 51 |
+
throws,
|
| 52 |
+
};
|
| 53 |
+
}
|
| 54 |
+
export = strict;
|
| 55 |
+
}
|
| 56 |
+
declare module "assert/strict" {
|
| 57 |
+
import strict = require("node:assert/strict");
|
| 58 |
+
export = strict;
|
| 59 |
+
}
|
node_modules/@types/node/async_hooks.d.ts
ADDED
|
@@ -0,0 +1,711 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:async_hooks" {
|
| 2 |
+
/**
|
| 3 |
+
* ```js
|
| 4 |
+
* import { executionAsyncId } from 'node:async_hooks';
|
| 5 |
+
* import fs from 'node:fs';
|
| 6 |
+
*
|
| 7 |
+
* console.log(executionAsyncId()); // 1 - bootstrap
|
| 8 |
+
* const path = '.';
|
| 9 |
+
* fs.open(path, 'r', (err, fd) => {
|
| 10 |
+
* console.log(executionAsyncId()); // 6 - open()
|
| 11 |
+
* });
|
| 12 |
+
* ```
|
| 13 |
+
*
|
| 14 |
+
* The ID returned from `executionAsyncId()` is related to execution timing, not
|
| 15 |
+
* causality (which is covered by `triggerAsyncId()`):
|
| 16 |
+
*
|
| 17 |
+
* ```js
|
| 18 |
+
* const server = net.createServer((conn) => {
|
| 19 |
+
* // Returns the ID of the server, not of the new connection, because the
|
| 20 |
+
* // callback runs in the execution scope of the server's MakeCallback().
|
| 21 |
+
* async_hooks.executionAsyncId();
|
| 22 |
+
*
|
| 23 |
+
* }).listen(port, () => {
|
| 24 |
+
* // Returns the ID of a TickObject (process.nextTick()) because all
|
| 25 |
+
* // callbacks passed to .listen() are wrapped in a nextTick().
|
| 26 |
+
* async_hooks.executionAsyncId();
|
| 27 |
+
* });
|
| 28 |
+
* ```
|
| 29 |
+
*
|
| 30 |
+
* Promise contexts may not get precise `executionAsyncIds` by default.
|
| 31 |
+
* See the section on [promise execution tracking](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#promise-execution-tracking).
|
| 32 |
+
* @since v8.1.0
|
| 33 |
+
* @return The `asyncId` of the current execution context. Useful to track when something calls.
|
| 34 |
+
*/
|
| 35 |
+
function executionAsyncId(): number;
|
| 36 |
+
/**
|
| 37 |
+
* Resource objects returned by `executionAsyncResource()` are most often internal
|
| 38 |
+
* Node.js handle objects with undocumented APIs. Using any functions or properties
|
| 39 |
+
* on the object is likely to crash your application and should be avoided.
|
| 40 |
+
*
|
| 41 |
+
* Using `executionAsyncResource()` in the top-level execution context will
|
| 42 |
+
* return an empty object as there is no handle or request object to use,
|
| 43 |
+
* but having an object representing the top-level can be helpful.
|
| 44 |
+
*
|
| 45 |
+
* ```js
|
| 46 |
+
* import { open } from 'node:fs';
|
| 47 |
+
* import { executionAsyncId, executionAsyncResource } from 'node:async_hooks';
|
| 48 |
+
*
|
| 49 |
+
* console.log(executionAsyncId(), executionAsyncResource()); // 1 {}
|
| 50 |
+
* open(new URL(import.meta.url), 'r', (err, fd) => {
|
| 51 |
+
* console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap
|
| 52 |
+
* });
|
| 53 |
+
* ```
|
| 54 |
+
*
|
| 55 |
+
* This can be used to implement continuation local storage without the
|
| 56 |
+
* use of a tracking `Map` to store the metadata:
|
| 57 |
+
*
|
| 58 |
+
* ```js
|
| 59 |
+
* import { createServer } from 'node:http';
|
| 60 |
+
* import {
|
| 61 |
+
* executionAsyncId,
|
| 62 |
+
* executionAsyncResource,
|
| 63 |
+
* createHook,
|
| 64 |
+
* } from 'node:async_hooks';
|
| 65 |
+
* const sym = Symbol('state'); // Private symbol to avoid pollution
|
| 66 |
+
*
|
| 67 |
+
* createHook({
|
| 68 |
+
* init(asyncId, type, triggerAsyncId, resource) {
|
| 69 |
+
* const cr = executionAsyncResource();
|
| 70 |
+
* if (cr) {
|
| 71 |
+
* resource[sym] = cr[sym];
|
| 72 |
+
* }
|
| 73 |
+
* },
|
| 74 |
+
* }).enable();
|
| 75 |
+
*
|
| 76 |
+
* const server = createServer((req, res) => {
|
| 77 |
+
* executionAsyncResource()[sym] = { state: req.url };
|
| 78 |
+
* setTimeout(function() {
|
| 79 |
+
* res.end(JSON.stringify(executionAsyncResource()[sym]));
|
| 80 |
+
* }, 100);
|
| 81 |
+
* }).listen(3000);
|
| 82 |
+
* ```
|
| 83 |
+
* @since v13.9.0, v12.17.0
|
| 84 |
+
* @return The resource representing the current execution. Useful to store data within the resource.
|
| 85 |
+
*/
|
| 86 |
+
function executionAsyncResource(): object;
|
| 87 |
+
/**
|
| 88 |
+
* ```js
|
| 89 |
+
* const server = net.createServer((conn) => {
|
| 90 |
+
* // The resource that caused (or triggered) this callback to be called
|
| 91 |
+
* // was that of the new connection. Thus the return value of triggerAsyncId()
|
| 92 |
+
* // is the asyncId of "conn".
|
| 93 |
+
* async_hooks.triggerAsyncId();
|
| 94 |
+
*
|
| 95 |
+
* }).listen(port, () => {
|
| 96 |
+
* // Even though all callbacks passed to .listen() are wrapped in a nextTick()
|
| 97 |
+
* // the callback itself exists because the call to the server's .listen()
|
| 98 |
+
* // was made. So the return value would be the ID of the server.
|
| 99 |
+
* async_hooks.triggerAsyncId();
|
| 100 |
+
* });
|
| 101 |
+
* ```
|
| 102 |
+
*
|
| 103 |
+
* Promise contexts may not get valid `triggerAsyncId`s by default. See
|
| 104 |
+
* the section on [promise execution tracking](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#promise-execution-tracking).
|
| 105 |
+
* @return The ID of the resource responsible for calling the callback that is currently being executed.
|
| 106 |
+
*/
|
| 107 |
+
function triggerAsyncId(): number;
|
| 108 |
+
interface HookCallbacks {
|
| 109 |
+
/**
|
| 110 |
+
* The [`init` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#initasyncid-type-triggerasyncid-resource).
|
| 111 |
+
*/
|
| 112 |
+
init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
|
| 113 |
+
/**
|
| 114 |
+
* The [`before` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#beforeasyncid).
|
| 115 |
+
*/
|
| 116 |
+
before?(asyncId: number): void;
|
| 117 |
+
/**
|
| 118 |
+
* The [`after` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#afterasyncid).
|
| 119 |
+
*/
|
| 120 |
+
after?(asyncId: number): void;
|
| 121 |
+
/**
|
| 122 |
+
* The [`promiseResolve` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#promiseresolveasyncid).
|
| 123 |
+
*/
|
| 124 |
+
promiseResolve?(asyncId: number): void;
|
| 125 |
+
/**
|
| 126 |
+
* The [`destroy` callback](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#destroyasyncid).
|
| 127 |
+
*/
|
| 128 |
+
destroy?(asyncId: number): void;
|
| 129 |
+
/**
|
| 130 |
+
* Whether the hook should track `Promise`s. Cannot be `false` if
|
| 131 |
+
* `promiseResolve` is set.
|
| 132 |
+
* @default true
|
| 133 |
+
*/
|
| 134 |
+
trackPromises?: boolean | undefined;
|
| 135 |
+
}
|
| 136 |
+
interface AsyncHook {
|
| 137 |
+
/**
|
| 138 |
+
* Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
|
| 139 |
+
*/
|
| 140 |
+
enable(): this;
|
| 141 |
+
/**
|
| 142 |
+
* 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.
|
| 143 |
+
*/
|
| 144 |
+
disable(): this;
|
| 145 |
+
}
|
| 146 |
+
/**
|
| 147 |
+
* Registers functions to be called for different lifetime events of each async
|
| 148 |
+
* operation.
|
| 149 |
+
*
|
| 150 |
+
* The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the
|
| 151 |
+
* respective asynchronous event during a resource's lifetime.
|
| 152 |
+
*
|
| 153 |
+
* All callbacks are optional. For example, if only resource cleanup needs to
|
| 154 |
+
* be tracked, then only the `destroy` callback needs to be passed. The
|
| 155 |
+
* specifics of all functions that can be passed to `callbacks` is in the
|
| 156 |
+
* [Hook Callbacks](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#hook-callbacks) section.
|
| 157 |
+
*
|
| 158 |
+
* ```js
|
| 159 |
+
* import { createHook } from 'node:async_hooks';
|
| 160 |
+
*
|
| 161 |
+
* const asyncHook = createHook({
|
| 162 |
+
* init(asyncId, type, triggerAsyncId, resource) { },
|
| 163 |
+
* destroy(asyncId) { },
|
| 164 |
+
* });
|
| 165 |
+
* ```
|
| 166 |
+
*
|
| 167 |
+
* The callbacks will be inherited via the prototype chain:
|
| 168 |
+
*
|
| 169 |
+
* ```js
|
| 170 |
+
* class MyAsyncCallbacks {
|
| 171 |
+
* init(asyncId, type, triggerAsyncId, resource) { }
|
| 172 |
+
* destroy(asyncId) {}
|
| 173 |
+
* }
|
| 174 |
+
*
|
| 175 |
+
* class MyAddedCallbacks extends MyAsyncCallbacks {
|
| 176 |
+
* before(asyncId) { }
|
| 177 |
+
* after(asyncId) { }
|
| 178 |
+
* }
|
| 179 |
+
*
|
| 180 |
+
* const asyncHook = async_hooks.createHook(new MyAddedCallbacks());
|
| 181 |
+
* ```
|
| 182 |
+
*
|
| 183 |
+
* Because promises are asynchronous resources whose lifecycle is tracked
|
| 184 |
+
* via the async hooks mechanism, the `init()`, `before()`, `after()`, and
|
| 185 |
+
* `destroy()` callbacks _must not_ be async functions that return promises.
|
| 186 |
+
* @since v8.1.0
|
| 187 |
+
* @param options The [Hook Callbacks](https://nodejs.org/docs/latest-v25.x/api/async_hooks.html#hook-callbacks) to register
|
| 188 |
+
* @returns Instance used for disabling and enabling hooks
|
| 189 |
+
*/
|
| 190 |
+
function createHook(options: HookCallbacks): AsyncHook;
|
| 191 |
+
interface AsyncResourceOptions {
|
| 192 |
+
/**
|
| 193 |
+
* The ID of the execution context that created this async event.
|
| 194 |
+
* @default executionAsyncId()
|
| 195 |
+
*/
|
| 196 |
+
triggerAsyncId?: number | undefined;
|
| 197 |
+
/**
|
| 198 |
+
* Disables automatic `emitDestroy` when the object is garbage collected.
|
| 199 |
+
* This usually does not need to be set (even if `emitDestroy` is called
|
| 200 |
+
* manually), unless the resource's `asyncId` is retrieved and the
|
| 201 |
+
* sensitive API's `emitDestroy` is called with it.
|
| 202 |
+
* @default false
|
| 203 |
+
*/
|
| 204 |
+
requireManualDestroy?: boolean | undefined;
|
| 205 |
+
}
|
| 206 |
+
/**
|
| 207 |
+
* The class `AsyncResource` is designed to be extended by the embedder's async
|
| 208 |
+
* resources. Using this, users can easily trigger the lifetime events of their
|
| 209 |
+
* own resources.
|
| 210 |
+
*
|
| 211 |
+
* The `init` hook will trigger when an `AsyncResource` is instantiated.
|
| 212 |
+
*
|
| 213 |
+
* The following is an overview of the `AsyncResource` API.
|
| 214 |
+
*
|
| 215 |
+
* ```js
|
| 216 |
+
* import { AsyncResource, executionAsyncId } from 'node:async_hooks';
|
| 217 |
+
*
|
| 218 |
+
* // AsyncResource() is meant to be extended. Instantiating a
|
| 219 |
+
* // new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
| 220 |
+
* // async_hook.executionAsyncId() is used.
|
| 221 |
+
* const asyncResource = new AsyncResource(
|
| 222 |
+
* type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false },
|
| 223 |
+
* );
|
| 224 |
+
*
|
| 225 |
+
* // Run a function in the execution context of the resource. This will
|
| 226 |
+
* // * establish the context of the resource
|
| 227 |
+
* // * trigger the AsyncHooks before callbacks
|
| 228 |
+
* // * call the provided function `fn` with the supplied arguments
|
| 229 |
+
* // * trigger the AsyncHooks after callbacks
|
| 230 |
+
* // * restore the original execution context
|
| 231 |
+
* asyncResource.runInAsyncScope(fn, thisArg, ...args);
|
| 232 |
+
*
|
| 233 |
+
* // Call AsyncHooks destroy callbacks.
|
| 234 |
+
* asyncResource.emitDestroy();
|
| 235 |
+
*
|
| 236 |
+
* // Return the unique ID assigned to the AsyncResource instance.
|
| 237 |
+
* asyncResource.asyncId();
|
| 238 |
+
*
|
| 239 |
+
* // Return the trigger ID for the AsyncResource instance.
|
| 240 |
+
* asyncResource.triggerAsyncId();
|
| 241 |
+
* ```
|
| 242 |
+
*/
|
| 243 |
+
class AsyncResource {
|
| 244 |
+
/**
|
| 245 |
+
* AsyncResource() is meant to be extended. Instantiating a
|
| 246 |
+
* new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
| 247 |
+
* async_hook.executionAsyncId() is used.
|
| 248 |
+
* @param type The type of async event.
|
| 249 |
+
* @param triggerAsyncId The ID of the execution context that created
|
| 250 |
+
* this async event (default: `executionAsyncId()`), or an
|
| 251 |
+
* AsyncResourceOptions object (since v9.3.0)
|
| 252 |
+
*/
|
| 253 |
+
constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions);
|
| 254 |
+
/**
|
| 255 |
+
* Binds the given function to the current execution context.
|
| 256 |
+
* @since v14.8.0, v12.19.0
|
| 257 |
+
* @param fn The function to bind to the current execution context.
|
| 258 |
+
* @param type An optional name to associate with the underlying `AsyncResource`.
|
| 259 |
+
*/
|
| 260 |
+
static bind<Func extends (this: ThisArg, ...args: any[]) => any, ThisArg>(
|
| 261 |
+
fn: Func,
|
| 262 |
+
type?: string,
|
| 263 |
+
thisArg?: ThisArg,
|
| 264 |
+
): Func;
|
| 265 |
+
/**
|
| 266 |
+
* Binds the given function to execute to this `AsyncResource`'s scope.
|
| 267 |
+
* @since v14.8.0, v12.19.0
|
| 268 |
+
* @param fn The function to bind to the current `AsyncResource`.
|
| 269 |
+
*/
|
| 270 |
+
bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
| 271 |
+
/**
|
| 272 |
+
* Call the provided function with the provided arguments in the execution context
|
| 273 |
+
* of the async resource. This will establish the context, trigger the AsyncHooks
|
| 274 |
+
* before callbacks, call the function, trigger the AsyncHooks after callbacks, and
|
| 275 |
+
* then restore the original execution context.
|
| 276 |
+
* @since v9.6.0
|
| 277 |
+
* @param fn The function to call in the execution context of this async resource.
|
| 278 |
+
* @param thisArg The receiver to be used for the function call.
|
| 279 |
+
* @param args Optional arguments to pass to the function.
|
| 280 |
+
*/
|
| 281 |
+
runInAsyncScope<This, Result>(
|
| 282 |
+
fn: (this: This, ...args: any[]) => Result,
|
| 283 |
+
thisArg?: This,
|
| 284 |
+
...args: any[]
|
| 285 |
+
): Result;
|
| 286 |
+
/**
|
| 287 |
+
* Call all `destroy` hooks. This should only ever be called once. An error will
|
| 288 |
+
* be thrown if it is called more than once. This **must** be manually called. If
|
| 289 |
+
* the resource is left to be collected by the GC then the `destroy` hooks will
|
| 290 |
+
* never be called.
|
| 291 |
+
* @return A reference to `asyncResource`.
|
| 292 |
+
*/
|
| 293 |
+
emitDestroy(): this;
|
| 294 |
+
/**
|
| 295 |
+
* @return The unique `asyncId` assigned to the resource.
|
| 296 |
+
*/
|
| 297 |
+
asyncId(): number;
|
| 298 |
+
/**
|
| 299 |
+
* @return The same `triggerAsyncId` that is passed to the `AsyncResource` constructor.
|
| 300 |
+
*/
|
| 301 |
+
triggerAsyncId(): number;
|
| 302 |
+
}
|
| 303 |
+
interface AsyncLocalStorageOptions {
|
| 304 |
+
/**
|
| 305 |
+
* The default value to be used when no store is provided.
|
| 306 |
+
*/
|
| 307 |
+
defaultValue?: any;
|
| 308 |
+
/**
|
| 309 |
+
* A name for the `AsyncLocalStorage` value.
|
| 310 |
+
*/
|
| 311 |
+
name?: string | undefined;
|
| 312 |
+
}
|
| 313 |
+
/**
|
| 314 |
+
* This class creates stores that stay coherent through asynchronous operations.
|
| 315 |
+
*
|
| 316 |
+
* 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
|
| 317 |
+
* safe implementation that involves significant optimizations that are non-obvious
|
| 318 |
+
* to implement.
|
| 319 |
+
*
|
| 320 |
+
* The following example uses `AsyncLocalStorage` to build a simple logger
|
| 321 |
+
* that assigns IDs to incoming HTTP requests and includes them in messages
|
| 322 |
+
* logged within each request.
|
| 323 |
+
*
|
| 324 |
+
* ```js
|
| 325 |
+
* import http from 'node:http';
|
| 326 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
| 327 |
+
*
|
| 328 |
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
| 329 |
+
*
|
| 330 |
+
* function logWithId(msg) {
|
| 331 |
+
* const id = asyncLocalStorage.getStore();
|
| 332 |
+
* console.log(`${id !== undefined ? id : '-'}:`, msg);
|
| 333 |
+
* }
|
| 334 |
+
*
|
| 335 |
+
* let idSeq = 0;
|
| 336 |
+
* http.createServer((req, res) => {
|
| 337 |
+
* asyncLocalStorage.run(idSeq++, () => {
|
| 338 |
+
* logWithId('start');
|
| 339 |
+
* // Imagine any chain of async operations here
|
| 340 |
+
* setImmediate(() => {
|
| 341 |
+
* logWithId('finish');
|
| 342 |
+
* res.end();
|
| 343 |
+
* });
|
| 344 |
+
* });
|
| 345 |
+
* }).listen(8080);
|
| 346 |
+
*
|
| 347 |
+
* http.get('http://localhost:8080');
|
| 348 |
+
* http.get('http://localhost:8080');
|
| 349 |
+
* // Prints:
|
| 350 |
+
* // 0: start
|
| 351 |
+
* // 0: finish
|
| 352 |
+
* // 1: start
|
| 353 |
+
* // 1: finish
|
| 354 |
+
* ```
|
| 355 |
+
*
|
| 356 |
+
* Each instance of `AsyncLocalStorage` maintains an independent storage context.
|
| 357 |
+
* Multiple instances can safely exist simultaneously without risk of interfering
|
| 358 |
+
* with each other's data.
|
| 359 |
+
* @since v13.10.0, v12.17.0
|
| 360 |
+
*/
|
| 361 |
+
class AsyncLocalStorage<T> {
|
| 362 |
+
/**
|
| 363 |
+
* Creates a new instance of `AsyncLocalStorage`. Store is only provided within a
|
| 364 |
+
* `run()` call or after an `enterWith()` call.
|
| 365 |
+
*/
|
| 366 |
+
constructor(options?: AsyncLocalStorageOptions);
|
| 367 |
+
/**
|
| 368 |
+
* Binds the given function to the current execution context.
|
| 369 |
+
* @since v19.8.0
|
| 370 |
+
* @param fn The function to bind to the current execution context.
|
| 371 |
+
* @return A new function that calls `fn` within the captured execution context.
|
| 372 |
+
*/
|
| 373 |
+
static bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
| 374 |
+
/**
|
| 375 |
+
* Captures the current execution context and returns a function that accepts a
|
| 376 |
+
* function as an argument. Whenever the returned function is called, it
|
| 377 |
+
* calls the function passed to it within the captured context.
|
| 378 |
+
*
|
| 379 |
+
* ```js
|
| 380 |
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
| 381 |
+
* const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot());
|
| 382 |
+
* const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore()));
|
| 383 |
+
* console.log(result); // returns 123
|
| 384 |
+
* ```
|
| 385 |
+
*
|
| 386 |
+
* AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple
|
| 387 |
+
* async context tracking purposes, for example:
|
| 388 |
+
*
|
| 389 |
+
* ```js
|
| 390 |
+
* class Foo {
|
| 391 |
+
* #runInAsyncScope = AsyncLocalStorage.snapshot();
|
| 392 |
+
*
|
| 393 |
+
* get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); }
|
| 394 |
+
* }
|
| 395 |
+
*
|
| 396 |
+
* const foo = asyncLocalStorage.run(123, () => new Foo());
|
| 397 |
+
* console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123
|
| 398 |
+
* ```
|
| 399 |
+
* @since v19.8.0
|
| 400 |
+
* @return A new function with the signature `(fn: (...args) : R, ...args) : R`.
|
| 401 |
+
*/
|
| 402 |
+
static snapshot(): <R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R;
|
| 403 |
+
/**
|
| 404 |
+
* Disables the instance of `AsyncLocalStorage`. All subsequent calls
|
| 405 |
+
* to `asyncLocalStorage.getStore()` will return `undefined` until `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again.
|
| 406 |
+
*
|
| 407 |
+
* When calling `asyncLocalStorage.disable()`, all current contexts linked to the
|
| 408 |
+
* instance will be exited.
|
| 409 |
+
*
|
| 410 |
+
* Calling `asyncLocalStorage.disable()` is required before the `asyncLocalStorage` can be garbage collected. This does not apply to stores
|
| 411 |
+
* provided by the `asyncLocalStorage`, as those objects are garbage collected
|
| 412 |
+
* along with the corresponding async resources.
|
| 413 |
+
*
|
| 414 |
+
* Use this method when the `asyncLocalStorage` is not in use anymore
|
| 415 |
+
* in the current process.
|
| 416 |
+
* @since v13.10.0, v12.17.0
|
| 417 |
+
* @experimental
|
| 418 |
+
*/
|
| 419 |
+
disable(): void;
|
| 420 |
+
/**
|
| 421 |
+
* Returns the current store.
|
| 422 |
+
* If called outside of an asynchronous context initialized by
|
| 423 |
+
* calling `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()`, it
|
| 424 |
+
* returns `undefined`.
|
| 425 |
+
* @since v13.10.0, v12.17.0
|
| 426 |
+
*/
|
| 427 |
+
getStore(): T | undefined;
|
| 428 |
+
/**
|
| 429 |
+
* The name of the `AsyncLocalStorage` instance if provided.
|
| 430 |
+
* @since v24.0.0
|
| 431 |
+
*/
|
| 432 |
+
readonly name: string;
|
| 433 |
+
/**
|
| 434 |
+
* Runs a function synchronously within a context and returns its
|
| 435 |
+
* return value. The store is not accessible outside of the callback function.
|
| 436 |
+
* The store is accessible to any asynchronous operations created within the
|
| 437 |
+
* callback.
|
| 438 |
+
*
|
| 439 |
+
* The optional `args` are passed to the callback function.
|
| 440 |
+
*
|
| 441 |
+
* If the callback function throws an error, the error is thrown by `run()` too.
|
| 442 |
+
* The stacktrace is not impacted by this call and the context is exited.
|
| 443 |
+
*
|
| 444 |
+
* Example:
|
| 445 |
+
*
|
| 446 |
+
* ```js
|
| 447 |
+
* const store = { id: 2 };
|
| 448 |
+
* try {
|
| 449 |
+
* asyncLocalStorage.run(store, () => {
|
| 450 |
+
* asyncLocalStorage.getStore(); // Returns the store object
|
| 451 |
+
* setTimeout(() => {
|
| 452 |
+
* asyncLocalStorage.getStore(); // Returns the store object
|
| 453 |
+
* }, 200);
|
| 454 |
+
* throw new Error();
|
| 455 |
+
* });
|
| 456 |
+
* } catch (e) {
|
| 457 |
+
* asyncLocalStorage.getStore(); // Returns undefined
|
| 458 |
+
* // The error will be caught here
|
| 459 |
+
* }
|
| 460 |
+
* ```
|
| 461 |
+
* @since v13.10.0, v12.17.0
|
| 462 |
+
*/
|
| 463 |
+
run<R>(store: T, callback: () => R): R;
|
| 464 |
+
run<R, TArgs extends any[]>(store: T, callback: (...args: TArgs) => R, ...args: TArgs): R;
|
| 465 |
+
/**
|
| 466 |
+
* Runs a function synchronously outside of a context and returns its
|
| 467 |
+
* return value. The store is not accessible within the callback function or
|
| 468 |
+
* the asynchronous operations created within the callback. Any `getStore()` call done within the callback function will always return `undefined`.
|
| 469 |
+
*
|
| 470 |
+
* The optional `args` are passed to the callback function.
|
| 471 |
+
*
|
| 472 |
+
* If the callback function throws an error, the error is thrown by `exit()` too.
|
| 473 |
+
* The stacktrace is not impacted by this call and the context is re-entered.
|
| 474 |
+
*
|
| 475 |
+
* Example:
|
| 476 |
+
*
|
| 477 |
+
* ```js
|
| 478 |
+
* // Within a call to run
|
| 479 |
+
* try {
|
| 480 |
+
* asyncLocalStorage.getStore(); // Returns the store object or value
|
| 481 |
+
* asyncLocalStorage.exit(() => {
|
| 482 |
+
* asyncLocalStorage.getStore(); // Returns undefined
|
| 483 |
+
* throw new Error();
|
| 484 |
+
* });
|
| 485 |
+
* } catch (e) {
|
| 486 |
+
* asyncLocalStorage.getStore(); // Returns the same object or value
|
| 487 |
+
* // The error will be caught here
|
| 488 |
+
* }
|
| 489 |
+
* ```
|
| 490 |
+
* @since v13.10.0, v12.17.0
|
| 491 |
+
* @experimental
|
| 492 |
+
*/
|
| 493 |
+
exit<R, TArgs extends any[]>(callback: (...args: TArgs) => R, ...args: TArgs): R;
|
| 494 |
+
/**
|
| 495 |
+
* Creates a disposable scope that enters the given store and automatically
|
| 496 |
+
* restores the previous store value when the scope is disposed. This method is
|
| 497 |
+
* designed to work with JavaScript's explicit resource management (`using` syntax).
|
| 498 |
+
*
|
| 499 |
+
* Example:
|
| 500 |
+
*
|
| 501 |
+
* ```js
|
| 502 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
| 503 |
+
*
|
| 504 |
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
| 505 |
+
*
|
| 506 |
+
* {
|
| 507 |
+
* using _ = asyncLocalStorage.withScope('my-store');
|
| 508 |
+
* console.log(asyncLocalStorage.getStore()); // Prints: my-store
|
| 509 |
+
* }
|
| 510 |
+
*
|
| 511 |
+
* console.log(asyncLocalStorage.getStore()); // Prints: undefined
|
| 512 |
+
* ```
|
| 513 |
+
*
|
| 514 |
+
* The `withScope()` method is particularly useful for managing context in
|
| 515 |
+
* synchronous code where you want to ensure the previous store value is restored
|
| 516 |
+
* when exiting a block, even if an error is thrown.
|
| 517 |
+
*
|
| 518 |
+
* ```js
|
| 519 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
| 520 |
+
*
|
| 521 |
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
| 522 |
+
*
|
| 523 |
+
* try {
|
| 524 |
+
* using _ = asyncLocalStorage.withScope('my-store');
|
| 525 |
+
* console.log(asyncLocalStorage.getStore()); // Prints: my-store
|
| 526 |
+
* throw new Error('test');
|
| 527 |
+
* } catch (e) {
|
| 528 |
+
* // Store is automatically restored even after error
|
| 529 |
+
* console.log(asyncLocalStorage.getStore()); // Prints: undefined
|
| 530 |
+
* }
|
| 531 |
+
* ```
|
| 532 |
+
*
|
| 533 |
+
* **Important:** When using `withScope()` in async functions before the first
|
| 534 |
+
* `await`, be aware that the scope change will affect the caller's context. The
|
| 535 |
+
* synchronous portion of an async function (before the first `await`) runs
|
| 536 |
+
* immediately when called, and when it reaches the first `await`, it returns the
|
| 537 |
+
* promise to the caller. At that point, the scope change becomes visible in the
|
| 538 |
+
* caller's context and will persist in subsequent synchronous code until something
|
| 539 |
+
* else changes the scope value. For async operations, prefer using `run()` which
|
| 540 |
+
* properly isolates context across async boundaries.
|
| 541 |
+
*
|
| 542 |
+
* ```js
|
| 543 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
| 544 |
+
*
|
| 545 |
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
| 546 |
+
*
|
| 547 |
+
* async function example() {
|
| 548 |
+
* using _ = asyncLocalStorage.withScope('my-store');
|
| 549 |
+
* console.log(asyncLocalStorage.getStore()); // Prints: my-store
|
| 550 |
+
* await someAsyncOperation(); // Function pauses here and returns promise
|
| 551 |
+
* console.log(asyncLocalStorage.getStore()); // Prints: my-store
|
| 552 |
+
* }
|
| 553 |
+
*
|
| 554 |
+
* // Calling without await
|
| 555 |
+
* example(); // Synchronous portion runs, then pauses at first await
|
| 556 |
+
* // After the promise is returned, the scope 'my-store' is now active in caller!
|
| 557 |
+
* console.log(asyncLocalStorage.getStore()); // Prints: my-store (unexpected!)
|
| 558 |
+
* ```
|
| 559 |
+
* @since v25.9.0
|
| 560 |
+
* @experimental
|
| 561 |
+
*/
|
| 562 |
+
withScope(store: T): RunScope;
|
| 563 |
+
/**
|
| 564 |
+
* Transitions into the context for the remainder of the current
|
| 565 |
+
* synchronous execution and then persists the store through any following
|
| 566 |
+
* asynchronous calls.
|
| 567 |
+
*
|
| 568 |
+
* Example:
|
| 569 |
+
*
|
| 570 |
+
* ```js
|
| 571 |
+
* const store = { id: 1 };
|
| 572 |
+
* // Replaces previous store with the given store object
|
| 573 |
+
* asyncLocalStorage.enterWith(store);
|
| 574 |
+
* asyncLocalStorage.getStore(); // Returns the store object
|
| 575 |
+
* someAsyncOperation(() => {
|
| 576 |
+
* asyncLocalStorage.getStore(); // Returns the same object
|
| 577 |
+
* });
|
| 578 |
+
* ```
|
| 579 |
+
*
|
| 580 |
+
* This transition will continue for the _entire_ synchronous execution.
|
| 581 |
+
* This means that if, for example, the context is entered within an event
|
| 582 |
+
* handler subsequent event handlers will also run within that context unless
|
| 583 |
+
* specifically bound to another context with an `AsyncResource`. That is why `run()` should be preferred over `enterWith()` unless there are strong reasons
|
| 584 |
+
* to use the latter method.
|
| 585 |
+
*
|
| 586 |
+
* ```js
|
| 587 |
+
* const store = { id: 1 };
|
| 588 |
+
*
|
| 589 |
+
* emitter.on('my-event', () => {
|
| 590 |
+
* asyncLocalStorage.enterWith(store);
|
| 591 |
+
* });
|
| 592 |
+
* emitter.on('my-event', () => {
|
| 593 |
+
* asyncLocalStorage.getStore(); // Returns the same object
|
| 594 |
+
* });
|
| 595 |
+
*
|
| 596 |
+
* asyncLocalStorage.getStore(); // Returns undefined
|
| 597 |
+
* emitter.emit('my-event');
|
| 598 |
+
* asyncLocalStorage.getStore(); // Returns the same object
|
| 599 |
+
* ```
|
| 600 |
+
* @since v13.11.0, v12.17.0
|
| 601 |
+
* @experimental
|
| 602 |
+
*/
|
| 603 |
+
enterWith(store: T): void;
|
| 604 |
+
}
|
| 605 |
+
/**
|
| 606 |
+
* A disposable scope returned by `asyncLocalStorage.withScope()` that
|
| 607 |
+
* automatically restores the previous store value when disposed. This class
|
| 608 |
+
* implements the [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management) protocol and is designed to work
|
| 609 |
+
* with JavaScript's `using` syntax.
|
| 610 |
+
*
|
| 611 |
+
* The scope automatically restores the previous store value when the `using` block
|
| 612 |
+
* exits, whether through normal completion or by throwing an error.
|
| 613 |
+
* @since v25.9.0
|
| 614 |
+
* @experimental
|
| 615 |
+
*/
|
| 616 |
+
interface RunScope extends Disposable {
|
| 617 |
+
/**
|
| 618 |
+
* Explicitly ends the scope and restores the previous store value. This method
|
| 619 |
+
* is idempotent: calling it multiple times has the same effect as calling it once.
|
| 620 |
+
*
|
| 621 |
+
* The `[Symbol.dispose]()` method defers to `dispose()`.
|
| 622 |
+
*
|
| 623 |
+
* If `withScope()` is called without the `using` keyword, `dispose()` must be
|
| 624 |
+
* called manually to restore the previous store value. Forgetting to call
|
| 625 |
+
* `dispose()` will cause the store value to persist for the remainder of the
|
| 626 |
+
* current execution context:
|
| 627 |
+
*
|
| 628 |
+
* ```js
|
| 629 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
| 630 |
+
*
|
| 631 |
+
* const storage = new AsyncLocalStorage();
|
| 632 |
+
*
|
| 633 |
+
* // Without using, the scope must be disposed manually
|
| 634 |
+
* const scope = storage.withScope('my-store');
|
| 635 |
+
* // storage.getStore() === 'my-store' here
|
| 636 |
+
*
|
| 637 |
+
* scope.dispose(); // Restore previous value
|
| 638 |
+
* // storage.getStore() === undefined here
|
| 639 |
+
* ```
|
| 640 |
+
* @since v25.9.0
|
| 641 |
+
*/
|
| 642 |
+
dispose(): void;
|
| 643 |
+
}
|
| 644 |
+
/**
|
| 645 |
+
* @since v17.2.0, v16.14.0
|
| 646 |
+
* @return A map of provider types to the corresponding numeric id.
|
| 647 |
+
* This map contains all the event types that might be emitted by the `async_hooks.init()` event.
|
| 648 |
+
*/
|
| 649 |
+
namespace asyncWrapProviders {
|
| 650 |
+
const NONE: number;
|
| 651 |
+
const DIRHANDLE: number;
|
| 652 |
+
const DNSCHANNEL: number;
|
| 653 |
+
const ELDHISTOGRAM: number;
|
| 654 |
+
const FILEHANDLE: number;
|
| 655 |
+
const FILEHANDLECLOSEREQ: number;
|
| 656 |
+
const FIXEDSIZEBLOBCOPY: number;
|
| 657 |
+
const FSEVENTWRAP: number;
|
| 658 |
+
const FSREQCALLBACK: number;
|
| 659 |
+
const FSREQPROMISE: number;
|
| 660 |
+
const GETADDRINFOREQWRAP: number;
|
| 661 |
+
const GETNAMEINFOREQWRAP: number;
|
| 662 |
+
const HEAPSNAPSHOT: number;
|
| 663 |
+
const HTTP2SESSION: number;
|
| 664 |
+
const HTTP2STREAM: number;
|
| 665 |
+
const HTTP2PING: number;
|
| 666 |
+
const HTTP2SETTINGS: number;
|
| 667 |
+
const HTTPINCOMINGMESSAGE: number;
|
| 668 |
+
const HTTPCLIENTREQUEST: number;
|
| 669 |
+
const JSSTREAM: number;
|
| 670 |
+
const JSUDPWRAP: number;
|
| 671 |
+
const MESSAGEPORT: number;
|
| 672 |
+
const PIPECONNECTWRAP: number;
|
| 673 |
+
const PIPESERVERWRAP: number;
|
| 674 |
+
const PIPEWRAP: number;
|
| 675 |
+
const PROCESSWRAP: number;
|
| 676 |
+
const PROMISE: number;
|
| 677 |
+
const QUERYWRAP: number;
|
| 678 |
+
const SHUTDOWNWRAP: number;
|
| 679 |
+
const SIGNALWRAP: number;
|
| 680 |
+
const STATWATCHER: number;
|
| 681 |
+
const STREAMPIPE: number;
|
| 682 |
+
const TCPCONNECTWRAP: number;
|
| 683 |
+
const TCPSERVERWRAP: number;
|
| 684 |
+
const TCPWRAP: number;
|
| 685 |
+
const TTYWRAP: number;
|
| 686 |
+
const UDPSENDWRAP: number;
|
| 687 |
+
const UDPWRAP: number;
|
| 688 |
+
const SIGINTWATCHDOG: number;
|
| 689 |
+
const WORKER: number;
|
| 690 |
+
const WORKERHEAPSNAPSHOT: number;
|
| 691 |
+
const WRITEWRAP: number;
|
| 692 |
+
const ZLIB: number;
|
| 693 |
+
const CHECKPRIMEREQUEST: number;
|
| 694 |
+
const PBKDF2REQUEST: number;
|
| 695 |
+
const KEYPAIRGENREQUEST: number;
|
| 696 |
+
const KEYGENREQUEST: number;
|
| 697 |
+
const KEYEXPORTREQUEST: number;
|
| 698 |
+
const CIPHERREQUEST: number;
|
| 699 |
+
const DERIVEBITSREQUEST: number;
|
| 700 |
+
const HASHREQUEST: number;
|
| 701 |
+
const RANDOMBYTESREQUEST: number;
|
| 702 |
+
const RANDOMPRIMEREQUEST: number;
|
| 703 |
+
const SCRYPTREQUEST: number;
|
| 704 |
+
const SIGNREQUEST: number;
|
| 705 |
+
const TLSWRAP: number;
|
| 706 |
+
const VERIFYREQUEST: number;
|
| 707 |
+
}
|
| 708 |
+
}
|
| 709 |
+
declare module "async_hooks" {
|
| 710 |
+
export * from "node:async_hooks";
|
| 711 |
+
}
|
node_modules/@types/node/buffer.buffer.d.ts
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ends
|
| 3 |
+
{ valueOf(): infer V extends ArrayBufferLike } ? V : T;
|
| 4 |
+
global {
|
| 5 |
+
interface BufferConstructor {
|
| 6 |
+
// see buffer.d.ts for implementation shared with all TypeScript versions
|
| 7 |
+
|
| 8 |
+
/**
|
| 9 |
+
* Allocates a new buffer containing the given {str}.
|
| 10 |
+
*
|
| 11 |
+
* @param str String to store in buffer.
|
| 12 |
+
* @param encoding encoding to use, optional. Default is 'utf8'
|
| 13 |
+
* @deprecated since v10.0.0 - Use `Buffer.from(string[, encoding])` instead.
|
| 14 |
+
*/
|
| 15 |
+
new(str: string, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
|
| 16 |
+
/**
|
| 17 |
+
* Allocates a new buffer of {size} octets.
|
| 18 |
+
*
|
| 19 |
+
* @param size count of octets to allocate.
|
| 20 |
+
* @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`).
|
| 21 |
+
*/
|
| 22 |
+
new(size: number): Buffer<ArrayBuffer>;
|
| 23 |
+
/**
|
| 24 |
+
* Allocates a new buffer containing the given {array} of octets.
|
| 25 |
+
*
|
| 26 |
+
* @param array The octets to store.
|
| 27 |
+
* @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
|
| 28 |
+
*/
|
| 29 |
+
new(array: ArrayLike<number>): Buffer<ArrayBuffer>;
|
| 30 |
+
/**
|
| 31 |
+
* Produces a Buffer backed by the same allocated memory as
|
| 32 |
+
* the given {ArrayBuffer}/{SharedArrayBuffer}.
|
| 33 |
+
*
|
| 34 |
+
* @param arrayBuffer The ArrayBuffer with which to share memory.
|
| 35 |
+
* @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead.
|
| 36 |
+
*/
|
| 37 |
+
new<TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: TArrayBuffer): Buffer<TArrayBuffer>;
|
| 38 |
+
/**
|
| 39 |
+
* Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`.
|
| 40 |
+
* Array entries outside that range will be truncated to fit into it.
|
| 41 |
+
*
|
| 42 |
+
* ```js
|
| 43 |
+
* import { Buffer } from 'node:buffer';
|
| 44 |
+
*
|
| 45 |
+
* // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
|
| 46 |
+
* const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
|
| 47 |
+
* ```
|
| 48 |
+
*
|
| 49 |
+
* If `array` is an `Array`-like object (that is, one with a `length` property of
|
| 50 |
+
* type `number`), it is treated as if it is an array, unless it is a `Buffer` or
|
| 51 |
+
* a `Uint8Array`. This means all other `TypedArray` variants get treated as an
|
| 52 |
+
* `Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use
|
| 53 |
+
* `Buffer.copyBytesFrom()`.
|
| 54 |
+
*
|
| 55 |
+
* A `TypeError` will be thrown if `array` is not an `Array` or another type
|
| 56 |
+
* appropriate for `Buffer.from()` variants.
|
| 57 |
+
*
|
| 58 |
+
* `Buffer.from(array)` and `Buffer.from(string)` may also use the internal
|
| 59 |
+
* `Buffer` pool like `Buffer.allocUnsafe()` does.
|
| 60 |
+
* @since v5.10.0
|
| 61 |
+
*/
|
| 62 |
+
from(array: WithImplicitCoercion<ArrayLike<number>>): Buffer<ArrayBuffer>;
|
| 63 |
+
/**
|
| 64 |
+
* This creates a view of the `ArrayBuffer` without copying the underlying
|
| 65 |
+
* memory. For example, when passed a reference to the `.buffer` property of a
|
| 66 |
+
* `TypedArray` instance, the newly created `Buffer` will share the same
|
| 67 |
+
* allocated memory as the `TypedArray`'s underlying `ArrayBuffer`.
|
| 68 |
+
*
|
| 69 |
+
* ```js
|
| 70 |
+
* import { Buffer } from 'node:buffer';
|
| 71 |
+
*
|
| 72 |
+
* const arr = new Uint16Array(2);
|
| 73 |
+
*
|
| 74 |
+
* arr[0] = 5000;
|
| 75 |
+
* arr[1] = 4000;
|
| 76 |
+
*
|
| 77 |
+
* // Shares memory with `arr`.
|
| 78 |
+
* const buf = Buffer.from(arr.buffer);
|
| 79 |
+
*
|
| 80 |
+
* console.log(buf);
|
| 81 |
+
* // Prints: <Buffer 88 13 a0 0f>
|
| 82 |
+
*
|
| 83 |
+
* // Changing the original Uint16Array changes the Buffer also.
|
| 84 |
+
* arr[1] = 6000;
|
| 85 |
+
*
|
| 86 |
+
* console.log(buf);
|
| 87 |
+
* // Prints: <Buffer 88 13 70 17>
|
| 88 |
+
* ```
|
| 89 |
+
*
|
| 90 |
+
* The optional `byteOffset` and `length` arguments specify a memory range within
|
| 91 |
+
* the `arrayBuffer` that will be shared by the `Buffer`.
|
| 92 |
+
*
|
| 93 |
+
* ```js
|
| 94 |
+
* import { Buffer } from 'node:buffer';
|
| 95 |
+
*
|
| 96 |
+
* const ab = new ArrayBuffer(10);
|
| 97 |
+
* const buf = Buffer.from(ab, 0, 2);
|
| 98 |
+
*
|
| 99 |
+
* console.log(buf.length);
|
| 100 |
+
* // Prints: 2
|
| 101 |
+
* ```
|
| 102 |
+
*
|
| 103 |
+
* A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer` or a
|
| 104 |
+
* `SharedArrayBuffer` or another type appropriate for `Buffer.from()`
|
| 105 |
+
* variants.
|
| 106 |
+
*
|
| 107 |
+
* It is important to remember that a backing `ArrayBuffer` can cover a range
|
| 108 |
+
* of memory that extends beyond the bounds of a `TypedArray` view. A new
|
| 109 |
+
* `Buffer` created using the `buffer` property of a `TypedArray` may extend
|
| 110 |
+
* beyond the range of the `TypedArray`:
|
| 111 |
+
*
|
| 112 |
+
* ```js
|
| 113 |
+
* import { Buffer } from 'node:buffer';
|
| 114 |
+
*
|
| 115 |
+
* const arrA = Uint8Array.from([0x63, 0x64, 0x65, 0x66]); // 4 elements
|
| 116 |
+
* const arrB = new Uint8Array(arrA.buffer, 1, 2); // 2 elements
|
| 117 |
+
* console.log(arrA.buffer === arrB.buffer); // true
|
| 118 |
+
*
|
| 119 |
+
* const buf = Buffer.from(arrB.buffer);
|
| 120 |
+
* console.log(buf);
|
| 121 |
+
* // Prints: <Buffer 63 64 65 66>
|
| 122 |
+
* ```
|
| 123 |
+
* @since v5.10.0
|
| 124 |
+
* @param arrayBuffer An `ArrayBuffer`, `SharedArrayBuffer`, for example the
|
| 125 |
+
* `.buffer` property of a `TypedArray`.
|
| 126 |
+
* @param byteOffset Index of first byte to expose. **Default:** `0`.
|
| 127 |
+
* @param length Number of bytes to expose. **Default:**
|
| 128 |
+
* `arrayBuffer.byteLength - byteOffset`.
|
| 129 |
+
*/
|
| 130 |
+
from<TArrayBuffer extends WithImplicitCoercion<ArrayBufferLike>>(
|
| 131 |
+
arrayBuffer: TArrayBuffer,
|
| 132 |
+
byteOffset?: number,
|
| 133 |
+
length?: number,
|
| 134 |
+
): Buffer<ImplicitArrayBuffer<TArrayBuffer>>;
|
| 135 |
+
/**
|
| 136 |
+
* Creates a new `Buffer` containing `string`. The `encoding` parameter identifies
|
| 137 |
+
* the character encoding to be used when converting `string` into bytes.
|
| 138 |
+
*
|
| 139 |
+
* ```js
|
| 140 |
+
* import { Buffer } from 'node:buffer';
|
| 141 |
+
*
|
| 142 |
+
* const buf1 = Buffer.from('this is a tést');
|
| 143 |
+
* const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');
|
| 144 |
+
*
|
| 145 |
+
* console.log(buf1.toString());
|
| 146 |
+
* // Prints: this is a tést
|
| 147 |
+
* console.log(buf2.toString());
|
| 148 |
+
* // Prints: this is a tést
|
| 149 |
+
* console.log(buf1.toString('latin1'));
|
| 150 |
+
* // Prints: this is a tést
|
| 151 |
+
* ```
|
| 152 |
+
*
|
| 153 |
+
* A `TypeError` will be thrown if `string` is not a string or another type
|
| 154 |
+
* appropriate for `Buffer.from()` variants.
|
| 155 |
+
*
|
| 156 |
+
* `Buffer.from(string)` may also use the internal `Buffer` pool like
|
| 157 |
+
* `Buffer.allocUnsafe()` does.
|
| 158 |
+
* @since v5.10.0
|
| 159 |
+
* @param string A string to encode.
|
| 160 |
+
* @param encoding The encoding of `string`. **Default:** `'utf8'`.
|
| 161 |
+
*/
|
| 162 |
+
from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
|
| 163 |
+
from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer<ArrayBuffer>;
|
| 164 |
+
/**
|
| 165 |
+
* Creates a new Buffer using the passed {data}
|
| 166 |
+
* @param values to create a new Buffer
|
| 167 |
+
*/
|
| 168 |
+
of(...items: number[]): Buffer<ArrayBuffer>;
|
| 169 |
+
/**
|
| 170 |
+
* Returns a new `Buffer` which is the result of concatenating all the `Buffer` instances in the `list` together.
|
| 171 |
+
*
|
| 172 |
+
* If the list has no items, or if the `totalLength` is 0, then a new zero-length `Buffer` is returned.
|
| 173 |
+
*
|
| 174 |
+
* If `totalLength` is not provided, it is calculated from the `Buffer` instances
|
| 175 |
+
* in `list` by adding their lengths.
|
| 176 |
+
*
|
| 177 |
+
* If `totalLength` is provided, it must be an unsigned integer. If the
|
| 178 |
+
* combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is
|
| 179 |
+
* truncated to `totalLength`. If the combined length of the `Buffer`s in `list` is
|
| 180 |
+
* less than `totalLength`, the remaining space is filled with zeros.
|
| 181 |
+
*
|
| 182 |
+
* ```js
|
| 183 |
+
* import { Buffer } from 'node:buffer';
|
| 184 |
+
*
|
| 185 |
+
* // Create a single `Buffer` from a list of three `Buffer` instances.
|
| 186 |
+
*
|
| 187 |
+
* const buf1 = Buffer.alloc(10);
|
| 188 |
+
* const buf2 = Buffer.alloc(14);
|
| 189 |
+
* const buf3 = Buffer.alloc(18);
|
| 190 |
+
* const totalLength = buf1.length + buf2.length + buf3.length;
|
| 191 |
+
*
|
| 192 |
+
* console.log(totalLength);
|
| 193 |
+
* // Prints: 42
|
| 194 |
+
*
|
| 195 |
+
* const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
|
| 196 |
+
*
|
| 197 |
+
* console.log(bufA);
|
| 198 |
+
* // Prints: <Buffer 00 00 00 00 ...>
|
| 199 |
+
* console.log(bufA.length);
|
| 200 |
+
* // Prints: 42
|
| 201 |
+
* ```
|
| 202 |
+
*
|
| 203 |
+
* `Buffer.concat()` may also use the internal `Buffer` pool like `Buffer.allocUnsafe()` does.
|
| 204 |
+
* @since v0.7.11
|
| 205 |
+
* @param list List of `Buffer` or {@link Uint8Array} instances to concatenate.
|
| 206 |
+
* @param totalLength Total length of the `Buffer` instances in `list` when concatenated.
|
| 207 |
+
*/
|
| 208 |
+
concat(list: readonly Uint8Array[], totalLength?: number): Buffer<ArrayBuffer>;
|
| 209 |
+
/**
|
| 210 |
+
* Copies the underlying memory of `view` into a new `Buffer`.
|
| 211 |
+
*
|
| 212 |
+
* ```js
|
| 213 |
+
* const u16 = new Uint16Array([0, 0xffff]);
|
| 214 |
+
* const buf = Buffer.copyBytesFrom(u16, 1, 1);
|
| 215 |
+
* u16[1] = 0;
|
| 216 |
+
* console.log(buf.length); // 2
|
| 217 |
+
* console.log(buf[0]); // 255
|
| 218 |
+
* console.log(buf[1]); // 255
|
| 219 |
+
* ```
|
| 220 |
+
* @since v19.8.0
|
| 221 |
+
* @param view The {TypedArray} to copy.
|
| 222 |
+
* @param [offset=0] The starting offset within `view`.
|
| 223 |
+
* @param [length=view.length - offset] The number of elements from `view` to copy.
|
| 224 |
+
*/
|
| 225 |
+
copyBytesFrom(view: NodeJS.TypedArray, offset?: number, length?: number): Buffer<ArrayBuffer>;
|
| 226 |
+
/**
|
| 227 |
+
* Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the`Buffer` will be zero-filled.
|
| 228 |
+
*
|
| 229 |
+
* ```js
|
| 230 |
+
* import { Buffer } from 'node:buffer';
|
| 231 |
+
*
|
| 232 |
+
* const buf = Buffer.alloc(5);
|
| 233 |
+
*
|
| 234 |
+
* console.log(buf);
|
| 235 |
+
* // Prints: <Buffer 00 00 00 00 00>
|
| 236 |
+
* ```
|
| 237 |
+
*
|
| 238 |
+
* If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.
|
| 239 |
+
*
|
| 240 |
+
* If `fill` is specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill)`.
|
| 241 |
+
*
|
| 242 |
+
* ```js
|
| 243 |
+
* import { Buffer } from 'node:buffer';
|
| 244 |
+
*
|
| 245 |
+
* const buf = Buffer.alloc(5, 'a');
|
| 246 |
+
*
|
| 247 |
+
* console.log(buf);
|
| 248 |
+
* // Prints: <Buffer 61 61 61 61 61>
|
| 249 |
+
* ```
|
| 250 |
+
*
|
| 251 |
+
* If both `fill` and `encoding` are specified, the allocated `Buffer` will be
|
| 252 |
+
* initialized by calling `buf.fill(fill, encoding)`.
|
| 253 |
+
*
|
| 254 |
+
* ```js
|
| 255 |
+
* import { Buffer } from 'node:buffer';
|
| 256 |
+
*
|
| 257 |
+
* const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
|
| 258 |
+
*
|
| 259 |
+
* console.log(buf);
|
| 260 |
+
* // Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
|
| 261 |
+
* ```
|
| 262 |
+
*
|
| 263 |
+
* Calling `Buffer.alloc()` can be measurably slower than the alternative `Buffer.allocUnsafe()` but ensures that the newly created `Buffer` instance
|
| 264 |
+
* contents will never contain sensitive data from previous allocations, including
|
| 265 |
+
* data that might not have been allocated for `Buffer`s.
|
| 266 |
+
*
|
| 267 |
+
* A `TypeError` will be thrown if `size` is not a number.
|
| 268 |
+
* @since v5.10.0
|
| 269 |
+
* @param size The desired length of the new `Buffer`.
|
| 270 |
+
* @param [fill=0] A value to pre-fill the new `Buffer` with.
|
| 271 |
+
* @param [encoding='utf8'] If `fill` is a string, this is its encoding.
|
| 272 |
+
*/
|
| 273 |
+
alloc(size: number, fill?: string | Uint8Array | number, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
|
| 274 |
+
/**
|
| 275 |
+
* 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.
|
| 276 |
+
*
|
| 277 |
+
* The underlying memory for `Buffer` instances created in this way is _not_
|
| 278 |
+
* _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.
|
| 279 |
+
*
|
| 280 |
+
* ```js
|
| 281 |
+
* import { Buffer } from 'node:buffer';
|
| 282 |
+
*
|
| 283 |
+
* const buf = Buffer.allocUnsafe(10);
|
| 284 |
+
*
|
| 285 |
+
* console.log(buf);
|
| 286 |
+
* // Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
|
| 287 |
+
*
|
| 288 |
+
* buf.fill(0);
|
| 289 |
+
*
|
| 290 |
+
* console.log(buf);
|
| 291 |
+
* // Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>
|
| 292 |
+
* ```
|
| 293 |
+
*
|
| 294 |
+
* A `TypeError` will be thrown if `size` is not a number.
|
| 295 |
+
*
|
| 296 |
+
* The `Buffer` module pre-allocates an internal `Buffer` instance of
|
| 297 |
+
* size `Buffer.poolSize` that is used as a pool for the fast allocation of new `Buffer` instances created using `Buffer.allocUnsafe()`, `Buffer.from(array)`,
|
| 298 |
+
* and `Buffer.concat()` only when `size` is less than `Buffer.poolSize >>> 1` (floor of `Buffer.poolSize` divided by two).
|
| 299 |
+
*
|
| 300 |
+
* Use of this pre-allocated internal memory pool is a key difference between
|
| 301 |
+
* calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
|
| 302 |
+
* 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
|
| 303 |
+
* than or equal to half `Buffer.poolSize`. The
|
| 304 |
+
* difference is subtle but can be important when an application requires the
|
| 305 |
+
* additional performance that `Buffer.allocUnsafe()` provides.
|
| 306 |
+
* @since v5.10.0
|
| 307 |
+
* @param size The desired length of the new `Buffer`.
|
| 308 |
+
*/
|
| 309 |
+
allocUnsafe(size: number): Buffer<ArrayBuffer>;
|
| 310 |
+
/**
|
| 311 |
+
* 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
|
| 312 |
+
* `size` is 0.
|
| 313 |
+
*
|
| 314 |
+
* The underlying memory for `Buffer` instances created in this way is _not_
|
| 315 |
+
* _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `buf.fill(0)` to initialize
|
| 316 |
+
* such `Buffer` instances with zeroes.
|
| 317 |
+
*
|
| 318 |
+
* When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
|
| 319 |
+
* allocations under 4 KiB are sliced from a single pre-allocated `Buffer`. This
|
| 320 |
+
* allows applications to avoid the garbage collection overhead of creating many
|
| 321 |
+
* individually allocated `Buffer` instances. This approach improves both
|
| 322 |
+
* performance and memory usage by eliminating the need to track and clean up as
|
| 323 |
+
* many individual `ArrayBuffer` objects.
|
| 324 |
+
*
|
| 325 |
+
* However, in the case where a developer may need to retain a small chunk of
|
| 326 |
+
* memory from a pool for an indeterminate amount of time, it may be appropriate
|
| 327 |
+
* to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and
|
| 328 |
+
* then copying out the relevant bits.
|
| 329 |
+
*
|
| 330 |
+
* ```js
|
| 331 |
+
* import { Buffer } from 'node:buffer';
|
| 332 |
+
*
|
| 333 |
+
* // Need to keep around a few small chunks of memory.
|
| 334 |
+
* const store = [];
|
| 335 |
+
*
|
| 336 |
+
* socket.on('readable', () => {
|
| 337 |
+
* let data;
|
| 338 |
+
* while (null !== (data = readable.read())) {
|
| 339 |
+
* // Allocate for retained data.
|
| 340 |
+
* const sb = Buffer.allocUnsafeSlow(10);
|
| 341 |
+
*
|
| 342 |
+
* // Copy the data into the new allocation.
|
| 343 |
+
* data.copy(sb, 0, 0, 10);
|
| 344 |
+
*
|
| 345 |
+
* store.push(sb);
|
| 346 |
+
* }
|
| 347 |
+
* });
|
| 348 |
+
* ```
|
| 349 |
+
*
|
| 350 |
+
* A `TypeError` will be thrown if `size` is not a number.
|
| 351 |
+
* @since v5.12.0
|
| 352 |
+
* @param size The desired length of the new `Buffer`.
|
| 353 |
+
*/
|
| 354 |
+
allocUnsafeSlow(size: number): Buffer<ArrayBuffer>;
|
| 355 |
+
}
|
| 356 |
+
interface Buffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> extends Uint8Array<TArrayBuffer> {
|
| 357 |
+
// see buffer.d.ts for implementation shared with all TypeScript versions
|
| 358 |
+
|
| 359 |
+
/**
|
| 360 |
+
* Returns a new `Buffer` that references the same memory as the original, but
|
| 361 |
+
* offset and cropped by the `start` and `end` indices.
|
| 362 |
+
*
|
| 363 |
+
* This method is not compatible with the `Uint8Array.prototype.slice()`,
|
| 364 |
+
* which is a superclass of `Buffer`. To copy the slice, use`Uint8Array.prototype.slice()`.
|
| 365 |
+
*
|
| 366 |
+
* ```js
|
| 367 |
+
* import { Buffer } from 'node:buffer';
|
| 368 |
+
*
|
| 369 |
+
* const buf = Buffer.from('buffer');
|
| 370 |
+
*
|
| 371 |
+
* const copiedBuf = Uint8Array.prototype.slice.call(buf);
|
| 372 |
+
* copiedBuf[0]++;
|
| 373 |
+
* console.log(copiedBuf.toString());
|
| 374 |
+
* // Prints: cuffer
|
| 375 |
+
*
|
| 376 |
+
* console.log(buf.toString());
|
| 377 |
+
* // Prints: buffer
|
| 378 |
+
*
|
| 379 |
+
* // With buf.slice(), the original buffer is modified.
|
| 380 |
+
* const notReallyCopiedBuf = buf.slice();
|
| 381 |
+
* notReallyCopiedBuf[0]++;
|
| 382 |
+
* console.log(notReallyCopiedBuf.toString());
|
| 383 |
+
* // Prints: cuffer
|
| 384 |
+
* console.log(buf.toString());
|
| 385 |
+
* // Also prints: cuffer (!)
|
| 386 |
+
* ```
|
| 387 |
+
* @since v0.3.0
|
| 388 |
+
* @deprecated Use `subarray` instead.
|
| 389 |
+
* @param [start=0] Where the new `Buffer` will start.
|
| 390 |
+
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
| 391 |
+
*/
|
| 392 |
+
slice(start?: number, end?: number): Buffer<ArrayBuffer>;
|
| 393 |
+
/**
|
| 394 |
+
* Returns a new `Buffer` that references the same memory as the original, but
|
| 395 |
+
* offset and cropped by the `start` and `end` indices.
|
| 396 |
+
*
|
| 397 |
+
* Specifying `end` greater than `buf.length` will return the same result as
|
| 398 |
+
* that of `end` equal to `buf.length`.
|
| 399 |
+
*
|
| 400 |
+
* This method is inherited from [`TypedArray.prototype.subarray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray).
|
| 401 |
+
*
|
| 402 |
+
* Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap.
|
| 403 |
+
*
|
| 404 |
+
* ```js
|
| 405 |
+
* import { Buffer } from 'node:buffer';
|
| 406 |
+
*
|
| 407 |
+
* // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte
|
| 408 |
+
* // from the original `Buffer`.
|
| 409 |
+
*
|
| 410 |
+
* const buf1 = Buffer.allocUnsafe(26);
|
| 411 |
+
*
|
| 412 |
+
* for (let i = 0; i < 26; i++) {
|
| 413 |
+
* // 97 is the decimal ASCII value for 'a'.
|
| 414 |
+
* buf1[i] = i + 97;
|
| 415 |
+
* }
|
| 416 |
+
*
|
| 417 |
+
* const buf2 = buf1.subarray(0, 3);
|
| 418 |
+
*
|
| 419 |
+
* console.log(buf2.toString('ascii', 0, buf2.length));
|
| 420 |
+
* // Prints: abc
|
| 421 |
+
*
|
| 422 |
+
* buf1[0] = 33;
|
| 423 |
+
*
|
| 424 |
+
* console.log(buf2.toString('ascii', 0, buf2.length));
|
| 425 |
+
* // Prints: !bc
|
| 426 |
+
* ```
|
| 427 |
+
*
|
| 428 |
+
* Specifying negative indexes causes the slice to be generated relative to the
|
| 429 |
+
* end of `buf` rather than the beginning.
|
| 430 |
+
*
|
| 431 |
+
* ```js
|
| 432 |
+
* import { Buffer } from 'node:buffer';
|
| 433 |
+
*
|
| 434 |
+
* const buf = Buffer.from('buffer');
|
| 435 |
+
*
|
| 436 |
+
* console.log(buf.subarray(-6, -1).toString());
|
| 437 |
+
* // Prints: buffe
|
| 438 |
+
* // (Equivalent to buf.subarray(0, 5).)
|
| 439 |
+
*
|
| 440 |
+
* console.log(buf.subarray(-6, -2).toString());
|
| 441 |
+
* // Prints: buff
|
| 442 |
+
* // (Equivalent to buf.subarray(0, 4).)
|
| 443 |
+
*
|
| 444 |
+
* console.log(buf.subarray(-5, -2).toString());
|
| 445 |
+
* // Prints: uff
|
| 446 |
+
* // (Equivalent to buf.subarray(1, 4).)
|
| 447 |
+
* ```
|
| 448 |
+
* @since v3.0.0
|
| 449 |
+
* @param [start=0] Where the new `Buffer` will start.
|
| 450 |
+
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
| 451 |
+
*/
|
| 452 |
+
subarray(start?: number, end?: number): Buffer<TArrayBuffer>;
|
| 453 |
+
}
|
| 454 |
+
// TODO: remove globals in future version
|
| 455 |
+
/**
|
| 456 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 457 |
+
* TypeScript versions earlier than 5.7.
|
| 458 |
+
*/
|
| 459 |
+
type NonSharedBuffer = Buffer<ArrayBuffer>;
|
| 460 |
+
/**
|
| 461 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 462 |
+
* TypeScript versions earlier than 5.7.
|
| 463 |
+
*/
|
| 464 |
+
type AllowSharedBuffer = Buffer<ArrayBufferLike>;
|
| 465 |
+
}
|
| 466 |
+
}
|
node_modules/@types/node/buffer.d.ts
ADDED
|
@@ -0,0 +1,1765 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:buffer" {
|
| 2 |
+
import { ReadableStream } from "node:stream/web";
|
| 3 |
+
/**
|
| 4 |
+
* This function returns `true` if `input` contains only valid UTF-8-encoded data,
|
| 5 |
+
* including the case in which `input` is empty.
|
| 6 |
+
*
|
| 7 |
+
* Throws if the `input` is a detached array buffer.
|
| 8 |
+
* @since v19.4.0, v18.14.0
|
| 9 |
+
* @param input The input to validate.
|
| 10 |
+
*/
|
| 11 |
+
export function isUtf8(input: ArrayBuffer | NodeJS.TypedArray): boolean;
|
| 12 |
+
/**
|
| 13 |
+
* This function returns `true` if `input` contains only valid ASCII-encoded data,
|
| 14 |
+
* including the case in which `input` is empty.
|
| 15 |
+
*
|
| 16 |
+
* Throws if the `input` is a detached array buffer.
|
| 17 |
+
* @since v19.6.0, v18.15.0
|
| 18 |
+
* @param input The input to validate.
|
| 19 |
+
*/
|
| 20 |
+
export function isAscii(input: ArrayBuffer | NodeJS.TypedArray): boolean;
|
| 21 |
+
export let INSPECT_MAX_BYTES: number;
|
| 22 |
+
export const kMaxLength: number;
|
| 23 |
+
export const kStringMaxLength: number;
|
| 24 |
+
export const constants: {
|
| 25 |
+
MAX_LENGTH: number;
|
| 26 |
+
MAX_STRING_LENGTH: number;
|
| 27 |
+
};
|
| 28 |
+
export type TranscodeEncoding =
|
| 29 |
+
| "ascii"
|
| 30 |
+
| "utf8"
|
| 31 |
+
| "utf-8"
|
| 32 |
+
| "utf16le"
|
| 33 |
+
| "utf-16le"
|
| 34 |
+
| "ucs2"
|
| 35 |
+
| "ucs-2"
|
| 36 |
+
| "latin1"
|
| 37 |
+
| "binary";
|
| 38 |
+
/**
|
| 39 |
+
* Re-encodes the given `Buffer` or `Uint8Array` instance from one character
|
| 40 |
+
* encoding to another. Returns a new `Buffer` instance.
|
| 41 |
+
*
|
| 42 |
+
* Throws if the `fromEnc` or `toEnc` specify invalid character encodings or if
|
| 43 |
+
* conversion from `fromEnc` to `toEnc` is not permitted.
|
| 44 |
+
*
|
| 45 |
+
* Encodings supported by `buffer.transcode()` are: `'ascii'`, `'utf8'`, `'utf16le'`, `'ucs2'`, `'latin1'`, and `'binary'`.
|
| 46 |
+
*
|
| 47 |
+
* The transcoding process will use substitution characters if a given byte
|
| 48 |
+
* sequence cannot be adequately represented in the target encoding. For instance:
|
| 49 |
+
*
|
| 50 |
+
* ```js
|
| 51 |
+
* import { Buffer, transcode } from 'node:buffer';
|
| 52 |
+
*
|
| 53 |
+
* const newBuf = transcode(Buffer.from('€'), 'utf8', 'ascii');
|
| 54 |
+
* console.log(newBuf.toString('ascii'));
|
| 55 |
+
* // Prints: '?'
|
| 56 |
+
* ```
|
| 57 |
+
*
|
| 58 |
+
* Because the Euro (`€`) sign is not representable in US-ASCII, it is replaced
|
| 59 |
+
* with `?` in the transcoded `Buffer`.
|
| 60 |
+
* @since v7.1.0
|
| 61 |
+
* @param source A `Buffer` or `Uint8Array` instance.
|
| 62 |
+
* @param fromEnc The current encoding.
|
| 63 |
+
* @param toEnc To target encoding.
|
| 64 |
+
*/
|
| 65 |
+
export function transcode(
|
| 66 |
+
source: Uint8Array,
|
| 67 |
+
fromEnc: TranscodeEncoding,
|
| 68 |
+
toEnc: TranscodeEncoding,
|
| 69 |
+
): NonSharedBuffer;
|
| 70 |
+
/**
|
| 71 |
+
* Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using
|
| 72 |
+
* a prior call to `URL.createObjectURL()`.
|
| 73 |
+
* @since v16.7.0
|
| 74 |
+
* @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
|
| 75 |
+
*/
|
| 76 |
+
export function resolveObjectURL(id: string): Blob | undefined;
|
| 77 |
+
export { type AllowSharedBuffer, Buffer, type NonSharedBuffer };
|
| 78 |
+
/** @deprecated This alias will be removed in a future version. Use the canonical `BlobPropertyBag` instead. */
|
| 79 |
+
// TODO: remove in future major
|
| 80 |
+
export interface BlobOptions extends BlobPropertyBag {}
|
| 81 |
+
/** @deprecated This alias will be removed in a future version. Use the canonical `FilePropertyBag` instead. */
|
| 82 |
+
export interface FileOptions extends FilePropertyBag {}
|
| 83 |
+
export type WithImplicitCoercion<T> =
|
| 84 |
+
| T
|
| 85 |
+
| { valueOf(): T }
|
| 86 |
+
| (T extends string ? { [Symbol.toPrimitive](hint: "string"): T } : never);
|
| 87 |
+
global {
|
| 88 |
+
namespace NodeJS {
|
| 89 |
+
export { BufferEncoding };
|
| 90 |
+
}
|
| 91 |
+
// Buffer class
|
| 92 |
+
type BufferEncoding =
|
| 93 |
+
| "ascii"
|
| 94 |
+
| "utf8"
|
| 95 |
+
| "utf-8"
|
| 96 |
+
| "utf16le"
|
| 97 |
+
| "utf-16le"
|
| 98 |
+
| "ucs2"
|
| 99 |
+
| "ucs-2"
|
| 100 |
+
| "base64"
|
| 101 |
+
| "base64url"
|
| 102 |
+
| "latin1"
|
| 103 |
+
| "binary"
|
| 104 |
+
| "hex";
|
| 105 |
+
/**
|
| 106 |
+
* Raw data is stored in instances of the Buffer class.
|
| 107 |
+
* 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.
|
| 108 |
+
* Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'base64url'|'binary'(deprecated)|'hex'
|
| 109 |
+
*/
|
| 110 |
+
interface BufferConstructor {
|
| 111 |
+
// see buffer.buffer.d.ts for implementation specific to TypeScript 5.7 and later
|
| 112 |
+
// see ts5.6/buffer.buffer.d.ts for implementation specific to TypeScript 5.6 and earlier
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Returns `true` if `obj` is a `Buffer`, `false` otherwise.
|
| 116 |
+
*
|
| 117 |
+
* ```js
|
| 118 |
+
* import { Buffer } from 'node:buffer';
|
| 119 |
+
*
|
| 120 |
+
* Buffer.isBuffer(Buffer.alloc(10)); // true
|
| 121 |
+
* Buffer.isBuffer(Buffer.from('foo')); // true
|
| 122 |
+
* Buffer.isBuffer('a string'); // false
|
| 123 |
+
* Buffer.isBuffer([]); // false
|
| 124 |
+
* Buffer.isBuffer(new Uint8Array(1024)); // false
|
| 125 |
+
* ```
|
| 126 |
+
* @since v0.1.101
|
| 127 |
+
*/
|
| 128 |
+
isBuffer(obj: any): obj is Buffer;
|
| 129 |
+
/**
|
| 130 |
+
* Returns `true` if `encoding` is the name of a supported character encoding,
|
| 131 |
+
* or `false` otherwise.
|
| 132 |
+
*
|
| 133 |
+
* ```js
|
| 134 |
+
* import { Buffer } from 'node:buffer';
|
| 135 |
+
*
|
| 136 |
+
* console.log(Buffer.isEncoding('utf8'));
|
| 137 |
+
* // Prints: true
|
| 138 |
+
*
|
| 139 |
+
* console.log(Buffer.isEncoding('hex'));
|
| 140 |
+
* // Prints: true
|
| 141 |
+
*
|
| 142 |
+
* console.log(Buffer.isEncoding('utf/8'));
|
| 143 |
+
* // Prints: false
|
| 144 |
+
*
|
| 145 |
+
* console.log(Buffer.isEncoding(''));
|
| 146 |
+
* // Prints: false
|
| 147 |
+
* ```
|
| 148 |
+
* @since v0.9.1
|
| 149 |
+
* @param encoding A character encoding name to check.
|
| 150 |
+
*/
|
| 151 |
+
isEncoding(encoding: string): encoding is BufferEncoding;
|
| 152 |
+
/**
|
| 153 |
+
* Returns the byte length of a string when encoded using `encoding`.
|
| 154 |
+
* 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
|
| 155 |
+
* for the encoding that is used to convert the string into bytes.
|
| 156 |
+
*
|
| 157 |
+
* For `'base64'`, `'base64url'`, and `'hex'`, this function assumes valid input.
|
| 158 |
+
* For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
|
| 159 |
+
* return value might be greater than the length of a `Buffer` created from the
|
| 160 |
+
* string.
|
| 161 |
+
*
|
| 162 |
+
* ```js
|
| 163 |
+
* import { Buffer } from 'node:buffer';
|
| 164 |
+
*
|
| 165 |
+
* const str = '\u00bd + \u00bc = \u00be';
|
| 166 |
+
*
|
| 167 |
+
* console.log(`${str}: ${str.length} characters, ` +
|
| 168 |
+
* `${Buffer.byteLength(str, 'utf8')} bytes`);
|
| 169 |
+
* // Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
|
| 170 |
+
* ```
|
| 171 |
+
*
|
| 172 |
+
* When `string` is a
|
| 173 |
+
* `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/-
|
| 174 |
+
* Reference/Global_Objects/TypedArray)/[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)/[`SharedArrayBuffer`](https://develop-
|
| 175 |
+
* er.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer), the byte length as reported by `.byteLength`is returned.
|
| 176 |
+
* @since v0.1.90
|
| 177 |
+
* @param string A value to calculate the length of.
|
| 178 |
+
* @param [encoding='utf8'] If `string` is a string, this is its encoding.
|
| 179 |
+
* @return The number of bytes contained within `string`.
|
| 180 |
+
*/
|
| 181 |
+
byteLength(
|
| 182 |
+
string: string | NodeJS.ArrayBufferView | ArrayBufferLike,
|
| 183 |
+
encoding?: BufferEncoding,
|
| 184 |
+
): number;
|
| 185 |
+
/**
|
| 186 |
+
* Compares `buf1` to `buf2`, typically for the purpose of sorting arrays of `Buffer` instances. This is equivalent to calling `buf1.compare(buf2)`.
|
| 187 |
+
*
|
| 188 |
+
* ```js
|
| 189 |
+
* import { Buffer } from 'node:buffer';
|
| 190 |
+
*
|
| 191 |
+
* const buf1 = Buffer.from('1234');
|
| 192 |
+
* const buf2 = Buffer.from('0123');
|
| 193 |
+
* const arr = [buf1, buf2];
|
| 194 |
+
*
|
| 195 |
+
* console.log(arr.sort(Buffer.compare));
|
| 196 |
+
* // Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
|
| 197 |
+
* // (This result is equal to: [buf2, buf1].)
|
| 198 |
+
* ```
|
| 199 |
+
* @since v0.11.13
|
| 200 |
+
* @return Either `-1`, `0`, or `1`, depending on the result of the comparison. See `compare` for details.
|
| 201 |
+
*/
|
| 202 |
+
compare(buf1: Uint8Array, buf2: Uint8Array): -1 | 0 | 1;
|
| 203 |
+
/**
|
| 204 |
+
* This is the size (in bytes) of pre-allocated internal `Buffer` instances used
|
| 205 |
+
* for pooling. This value may be modified.
|
| 206 |
+
* @since v0.11.3
|
| 207 |
+
*/
|
| 208 |
+
poolSize: number;
|
| 209 |
+
}
|
| 210 |
+
interface Buffer {
|
| 211 |
+
// see buffer.buffer.d.ts for implementation specific to TypeScript 5.7 and later
|
| 212 |
+
// see ts5.6/buffer.buffer.d.ts for implementation specific to TypeScript 5.6 and earlier
|
| 213 |
+
|
| 214 |
+
/**
|
| 215 |
+
* 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
|
| 216 |
+
* not contain enough space to fit the entire string, only part of `string` will be
|
| 217 |
+
* written. However, partially encoded characters will not be written.
|
| 218 |
+
*
|
| 219 |
+
* ```js
|
| 220 |
+
* import { Buffer } from 'node:buffer';
|
| 221 |
+
*
|
| 222 |
+
* const buf = Buffer.alloc(256);
|
| 223 |
+
*
|
| 224 |
+
* const len = buf.write('\u00bd + \u00bc = \u00be', 0);
|
| 225 |
+
*
|
| 226 |
+
* console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
|
| 227 |
+
* // Prints: 12 bytes: ½ + ¼ = ¾
|
| 228 |
+
*
|
| 229 |
+
* const buffer = Buffer.alloc(10);
|
| 230 |
+
*
|
| 231 |
+
* const length = buffer.write('abcd', 8);
|
| 232 |
+
*
|
| 233 |
+
* console.log(`${length} bytes: ${buffer.toString('utf8', 8, 10)}`);
|
| 234 |
+
* // Prints: 2 bytes : ab
|
| 235 |
+
* ```
|
| 236 |
+
* @since v0.1.90
|
| 237 |
+
* @param string String to write to `buf`.
|
| 238 |
+
* @param [offset=0] Number of bytes to skip before starting to write `string`.
|
| 239 |
+
* @param [length=buf.length - offset] Maximum number of bytes to write (written bytes will not exceed `buf.length - offset`).
|
| 240 |
+
* @param [encoding='utf8'] The character encoding of `string`.
|
| 241 |
+
* @return Number of bytes written.
|
| 242 |
+
*/
|
| 243 |
+
write(string: string, encoding?: BufferEncoding): number;
|
| 244 |
+
write(string: string, offset: number, encoding?: BufferEncoding): number;
|
| 245 |
+
write(string: string, offset: number, length: number, encoding?: BufferEncoding): number;
|
| 246 |
+
/**
|
| 247 |
+
* 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`.
|
| 248 |
+
*
|
| 249 |
+
* If `encoding` is `'utf8'` and a byte sequence in the input is not valid UTF-8,
|
| 250 |
+
* then each invalid byte is replaced with the replacement character `U+FFFD`.
|
| 251 |
+
*
|
| 252 |
+
* The maximum length of a string instance (in UTF-16 code units) is available
|
| 253 |
+
* as {@link constants.MAX_STRING_LENGTH}.
|
| 254 |
+
*
|
| 255 |
+
* ```js
|
| 256 |
+
* import { Buffer } from 'node:buffer';
|
| 257 |
+
*
|
| 258 |
+
* const buf1 = Buffer.allocUnsafe(26);
|
| 259 |
+
*
|
| 260 |
+
* for (let i = 0; i < 26; i++) {
|
| 261 |
+
* // 97 is the decimal ASCII value for 'a'.
|
| 262 |
+
* buf1[i] = i + 97;
|
| 263 |
+
* }
|
| 264 |
+
*
|
| 265 |
+
* console.log(buf1.toString('utf8'));
|
| 266 |
+
* // Prints: abcdefghijklmnopqrstuvwxyz
|
| 267 |
+
* console.log(buf1.toString('utf8', 0, 5));
|
| 268 |
+
* // Prints: abcde
|
| 269 |
+
*
|
| 270 |
+
* const buf2 = Buffer.from('tést');
|
| 271 |
+
*
|
| 272 |
+
* console.log(buf2.toString('hex'));
|
| 273 |
+
* // Prints: 74c3a97374
|
| 274 |
+
* console.log(buf2.toString('utf8', 0, 3));
|
| 275 |
+
* // Prints: té
|
| 276 |
+
* console.log(buf2.toString(undefined, 0, 3));
|
| 277 |
+
* // Prints: té
|
| 278 |
+
* ```
|
| 279 |
+
* @since v0.1.90
|
| 280 |
+
* @param [encoding='utf8'] The character encoding to use.
|
| 281 |
+
* @param [start=0] The byte offset to start decoding at.
|
| 282 |
+
* @param [end=buf.length] The byte offset to stop decoding at (not inclusive).
|
| 283 |
+
*/
|
| 284 |
+
toString(encoding?: BufferEncoding, start?: number, end?: number): string;
|
| 285 |
+
/**
|
| 286 |
+
* Returns a JSON representation of `buf`. [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) implicitly calls
|
| 287 |
+
* this function when stringifying a `Buffer` instance.
|
| 288 |
+
*
|
| 289 |
+
* `Buffer.from()` accepts objects in the format returned from this method.
|
| 290 |
+
* In particular, `Buffer.from(buf.toJSON())` works like `Buffer.from(buf)`.
|
| 291 |
+
*
|
| 292 |
+
* ```js
|
| 293 |
+
* import { Buffer } from 'node:buffer';
|
| 294 |
+
*
|
| 295 |
+
* const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);
|
| 296 |
+
* const json = JSON.stringify(buf);
|
| 297 |
+
*
|
| 298 |
+
* console.log(json);
|
| 299 |
+
* // Prints: {"type":"Buffer","data":[1,2,3,4,5]}
|
| 300 |
+
*
|
| 301 |
+
* const copy = JSON.parse(json, (key, value) => {
|
| 302 |
+
* return value && value.type === 'Buffer' ?
|
| 303 |
+
* Buffer.from(value) :
|
| 304 |
+
* value;
|
| 305 |
+
* });
|
| 306 |
+
*
|
| 307 |
+
* console.log(copy);
|
| 308 |
+
* // Prints: <Buffer 01 02 03 04 05>
|
| 309 |
+
* ```
|
| 310 |
+
* @since v0.9.2
|
| 311 |
+
*/
|
| 312 |
+
toJSON(): {
|
| 313 |
+
type: "Buffer";
|
| 314 |
+
data: number[];
|
| 315 |
+
};
|
| 316 |
+
/**
|
| 317 |
+
* Returns `true` if both `buf` and `otherBuffer` have exactly the same bytes,`false` otherwise. Equivalent to `buf.compare(otherBuffer) === 0`.
|
| 318 |
+
*
|
| 319 |
+
* ```js
|
| 320 |
+
* import { Buffer } from 'node:buffer';
|
| 321 |
+
*
|
| 322 |
+
* const buf1 = Buffer.from('ABC');
|
| 323 |
+
* const buf2 = Buffer.from('414243', 'hex');
|
| 324 |
+
* const buf3 = Buffer.from('ABCD');
|
| 325 |
+
*
|
| 326 |
+
* console.log(buf1.equals(buf2));
|
| 327 |
+
* // Prints: true
|
| 328 |
+
* console.log(buf1.equals(buf3));
|
| 329 |
+
* // Prints: false
|
| 330 |
+
* ```
|
| 331 |
+
* @since v0.11.13
|
| 332 |
+
* @param otherBuffer A `Buffer` or {@link Uint8Array} with which to compare `buf`.
|
| 333 |
+
*/
|
| 334 |
+
equals(otherBuffer: Uint8Array): boolean;
|
| 335 |
+
/**
|
| 336 |
+
* Compares `buf` with `target` and returns a number indicating whether `buf`comes before, after, or is the same as `target` in sort order.
|
| 337 |
+
* Comparison is based on the actual sequence of bytes in each `Buffer`.
|
| 338 |
+
*
|
| 339 |
+
* * `0` is returned if `target` is the same as `buf`
|
| 340 |
+
* * `1` is returned if `target` should come _before_`buf` when sorted.
|
| 341 |
+
* * `-1` is returned if `target` should come _after_`buf` when sorted.
|
| 342 |
+
*
|
| 343 |
+
* ```js
|
| 344 |
+
* import { Buffer } from 'node:buffer';
|
| 345 |
+
*
|
| 346 |
+
* const buf1 = Buffer.from('ABC');
|
| 347 |
+
* const buf2 = Buffer.from('BCD');
|
| 348 |
+
* const buf3 = Buffer.from('ABCD');
|
| 349 |
+
*
|
| 350 |
+
* console.log(buf1.compare(buf1));
|
| 351 |
+
* // Prints: 0
|
| 352 |
+
* console.log(buf1.compare(buf2));
|
| 353 |
+
* // Prints: -1
|
| 354 |
+
* console.log(buf1.compare(buf3));
|
| 355 |
+
* // Prints: -1
|
| 356 |
+
* console.log(buf2.compare(buf1));
|
| 357 |
+
* // Prints: 1
|
| 358 |
+
* console.log(buf2.compare(buf3));
|
| 359 |
+
* // Prints: 1
|
| 360 |
+
* console.log([buf1, buf2, buf3].sort(Buffer.compare));
|
| 361 |
+
* // Prints: [ <Buffer 41 42 43>, <Buffer 41 42 43 44>, <Buffer 42 43 44> ]
|
| 362 |
+
* // (This result is equal to: [buf1, buf3, buf2].)
|
| 363 |
+
* ```
|
| 364 |
+
*
|
| 365 |
+
* The optional `targetStart`, `targetEnd`, `sourceStart`, and `sourceEnd` arguments can be used to limit the comparison to specific ranges within `target` and `buf` respectively.
|
| 366 |
+
*
|
| 367 |
+
* ```js
|
| 368 |
+
* import { Buffer } from 'node:buffer';
|
| 369 |
+
*
|
| 370 |
+
* const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
| 371 |
+
* const buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);
|
| 372 |
+
*
|
| 373 |
+
* console.log(buf1.compare(buf2, 5, 9, 0, 4));
|
| 374 |
+
* // Prints: 0
|
| 375 |
+
* console.log(buf1.compare(buf2, 0, 6, 4));
|
| 376 |
+
* // Prints: -1
|
| 377 |
+
* console.log(buf1.compare(buf2, 5, 6, 5));
|
| 378 |
+
* // Prints: 1
|
| 379 |
+
* ```
|
| 380 |
+
*
|
| 381 |
+
* `ERR_OUT_OF_RANGE` is thrown if `targetStart < 0`, `sourceStart < 0`, `targetEnd > target.byteLength`, or `sourceEnd > source.byteLength`.
|
| 382 |
+
* @since v0.11.13
|
| 383 |
+
* @param target A `Buffer` or {@link Uint8Array} with which to compare `buf`.
|
| 384 |
+
* @param [targetStart=0] The offset within `target` at which to begin comparison.
|
| 385 |
+
* @param [targetEnd=target.length] The offset within `target` at which to end comparison (not inclusive).
|
| 386 |
+
* @param [sourceStart=0] The offset within `buf` at which to begin comparison.
|
| 387 |
+
* @param [sourceEnd=buf.length] The offset within `buf` at which to end comparison (not inclusive).
|
| 388 |
+
*/
|
| 389 |
+
compare(
|
| 390 |
+
target: Uint8Array,
|
| 391 |
+
targetStart?: number,
|
| 392 |
+
targetEnd?: number,
|
| 393 |
+
sourceStart?: number,
|
| 394 |
+
sourceEnd?: number,
|
| 395 |
+
): -1 | 0 | 1;
|
| 396 |
+
/**
|
| 397 |
+
* Copies data from a region of `buf` to a region in `target`, even if the `target`memory region overlaps with `buf`.
|
| 398 |
+
*
|
| 399 |
+
* [`TypedArray.prototype.set()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set) performs the same operation, and is available
|
| 400 |
+
* for all TypedArrays, including Node.js `Buffer`s, although it takes
|
| 401 |
+
* different function arguments.
|
| 402 |
+
*
|
| 403 |
+
* ```js
|
| 404 |
+
* import { Buffer } from 'node:buffer';
|
| 405 |
+
*
|
| 406 |
+
* // Create two `Buffer` instances.
|
| 407 |
+
* const buf1 = Buffer.allocUnsafe(26);
|
| 408 |
+
* const buf2 = Buffer.allocUnsafe(26).fill('!');
|
| 409 |
+
*
|
| 410 |
+
* for (let i = 0; i < 26; i++) {
|
| 411 |
+
* // 97 is the decimal ASCII value for 'a'.
|
| 412 |
+
* buf1[i] = i + 97;
|
| 413 |
+
* }
|
| 414 |
+
*
|
| 415 |
+
* // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
|
| 416 |
+
* buf1.copy(buf2, 8, 16, 20);
|
| 417 |
+
* // This is equivalent to:
|
| 418 |
+
* // buf2.set(buf1.subarray(16, 20), 8);
|
| 419 |
+
*
|
| 420 |
+
* console.log(buf2.toString('ascii', 0, 25));
|
| 421 |
+
* // Prints: !!!!!!!!qrst!!!!!!!!!!!!!
|
| 422 |
+
* ```
|
| 423 |
+
*
|
| 424 |
+
* ```js
|
| 425 |
+
* import { Buffer } from 'node:buffer';
|
| 426 |
+
*
|
| 427 |
+
* // Create a `Buffer` and copy data from one region to an overlapping region
|
| 428 |
+
* // within the same `Buffer`.
|
| 429 |
+
*
|
| 430 |
+
* const buf = Buffer.allocUnsafe(26);
|
| 431 |
+
*
|
| 432 |
+
* for (let i = 0; i < 26; i++) {
|
| 433 |
+
* // 97 is the decimal ASCII value for 'a'.
|
| 434 |
+
* buf[i] = i + 97;
|
| 435 |
+
* }
|
| 436 |
+
*
|
| 437 |
+
* buf.copy(buf, 0, 4, 10);
|
| 438 |
+
*
|
| 439 |
+
* console.log(buf.toString());
|
| 440 |
+
* // Prints: efghijghijklmnopqrstuvwxyz
|
| 441 |
+
* ```
|
| 442 |
+
* @since v0.1.90
|
| 443 |
+
* @param target A `Buffer` or {@link Uint8Array} to copy into.
|
| 444 |
+
* @param [targetStart=0] The offset within `target` at which to begin writing.
|
| 445 |
+
* @param [sourceStart=0] The offset within `buf` from which to begin copying.
|
| 446 |
+
* @param [sourceEnd=buf.length] The offset within `buf` at which to stop copying (not inclusive).
|
| 447 |
+
* @return The number of bytes copied.
|
| 448 |
+
*/
|
| 449 |
+
copy(target: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
|
| 450 |
+
/**
|
| 451 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian.
|
| 452 |
+
*
|
| 453 |
+
* `value` is interpreted and written as a two's complement signed integer.
|
| 454 |
+
*
|
| 455 |
+
* ```js
|
| 456 |
+
* import { Buffer } from 'node:buffer';
|
| 457 |
+
*
|
| 458 |
+
* const buf = Buffer.allocUnsafe(8);
|
| 459 |
+
*
|
| 460 |
+
* buf.writeBigInt64BE(0x0102030405060708n, 0);
|
| 461 |
+
*
|
| 462 |
+
* console.log(buf);
|
| 463 |
+
* // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
| 464 |
+
* ```
|
| 465 |
+
* @since v12.0.0, v10.20.0
|
| 466 |
+
* @param value Number to be written to `buf`.
|
| 467 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
| 468 |
+
* @return `offset` plus the number of bytes written.
|
| 469 |
+
*/
|
| 470 |
+
writeBigInt64BE(value: bigint, offset?: number): number;
|
| 471 |
+
/**
|
| 472 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian.
|
| 473 |
+
*
|
| 474 |
+
* `value` is interpreted and written as a two's complement signed integer.
|
| 475 |
+
*
|
| 476 |
+
* ```js
|
| 477 |
+
* import { Buffer } from 'node:buffer';
|
| 478 |
+
*
|
| 479 |
+
* const buf = Buffer.allocUnsafe(8);
|
| 480 |
+
*
|
| 481 |
+
* buf.writeBigInt64LE(0x0102030405060708n, 0);
|
| 482 |
+
*
|
| 483 |
+
* console.log(buf);
|
| 484 |
+
* // Prints: <Buffer 08 07 06 05 04 03 02 01>
|
| 485 |
+
* ```
|
| 486 |
+
* @since v12.0.0, v10.20.0
|
| 487 |
+
* @param value Number to be written to `buf`.
|
| 488 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
| 489 |
+
* @return `offset` plus the number of bytes written.
|
| 490 |
+
*/
|
| 491 |
+
writeBigInt64LE(value: bigint, offset?: number): number;
|
| 492 |
+
/**
|
| 493 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian.
|
| 494 |
+
*
|
| 495 |
+
* This function is also available under the `writeBigUint64BE` alias.
|
| 496 |
+
*
|
| 497 |
+
* ```js
|
| 498 |
+
* import { Buffer } from 'node:buffer';
|
| 499 |
+
*
|
| 500 |
+
* const buf = Buffer.allocUnsafe(8);
|
| 501 |
+
*
|
| 502 |
+
* buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
|
| 503 |
+
*
|
| 504 |
+
* console.log(buf);
|
| 505 |
+
* // Prints: <Buffer de ca fa fe ca ce fa de>
|
| 506 |
+
* ```
|
| 507 |
+
* @since v12.0.0, v10.20.0
|
| 508 |
+
* @param value Number to be written to `buf`.
|
| 509 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
| 510 |
+
* @return `offset` plus the number of bytes written.
|
| 511 |
+
*/
|
| 512 |
+
writeBigUInt64BE(value: bigint, offset?: number): number;
|
| 513 |
+
/**
|
| 514 |
+
* @alias Buffer.writeBigUInt64BE
|
| 515 |
+
* @since v14.10.0, v12.19.0
|
| 516 |
+
*/
|
| 517 |
+
writeBigUint64BE(value: bigint, offset?: number): number;
|
| 518 |
+
/**
|
| 519 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian
|
| 520 |
+
*
|
| 521 |
+
* ```js
|
| 522 |
+
* import { Buffer } from 'node:buffer';
|
| 523 |
+
*
|
| 524 |
+
* const buf = Buffer.allocUnsafe(8);
|
| 525 |
+
*
|
| 526 |
+
* buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
|
| 527 |
+
*
|
| 528 |
+
* console.log(buf);
|
| 529 |
+
* // Prints: <Buffer de fa ce ca fe fa ca de>
|
| 530 |
+
* ```
|
| 531 |
+
*
|
| 532 |
+
* This function is also available under the `writeBigUint64LE` alias.
|
| 533 |
+
* @since v12.0.0, v10.20.0
|
| 534 |
+
* @param value Number to be written to `buf`.
|
| 535 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
|
| 536 |
+
* @return `offset` plus the number of bytes written.
|
| 537 |
+
*/
|
| 538 |
+
writeBigUInt64LE(value: bigint, offset?: number): number;
|
| 539 |
+
/**
|
| 540 |
+
* @alias Buffer.writeBigUInt64LE
|
| 541 |
+
* @since v14.10.0, v12.19.0
|
| 542 |
+
*/
|
| 543 |
+
writeBigUint64LE(value: bigint, offset?: number): number;
|
| 544 |
+
/**
|
| 545 |
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
|
| 546 |
+
* when `value` is anything other than an unsigned integer.
|
| 547 |
+
*
|
| 548 |
+
* This function is also available under the `writeUintLE` alias.
|
| 549 |
+
*
|
| 550 |
+
* ```js
|
| 551 |
+
* import { Buffer } from 'node:buffer';
|
| 552 |
+
*
|
| 553 |
+
* const buf = Buffer.allocUnsafe(6);
|
| 554 |
+
*
|
| 555 |
+
* buf.writeUIntLE(0x1234567890ab, 0, 6);
|
| 556 |
+
*
|
| 557 |
+
* console.log(buf);
|
| 558 |
+
* // Prints: <Buffer ab 90 78 56 34 12>
|
| 559 |
+
* ```
|
| 560 |
+
* @since v0.5.5
|
| 561 |
+
* @param value Number to be written to `buf`.
|
| 562 |
+
* @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
| 563 |
+
* @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
| 564 |
+
* @return `offset` plus the number of bytes written.
|
| 565 |
+
*/
|
| 566 |
+
writeUIntLE(value: number, offset: number, byteLength: number): number;
|
| 567 |
+
/**
|
| 568 |
+
* @alias Buffer.writeUIntLE
|
| 569 |
+
* @since v14.9.0, v12.19.0
|
| 570 |
+
*/
|
| 571 |
+
writeUintLE(value: number, offset: number, byteLength: number): number;
|
| 572 |
+
/**
|
| 573 |
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined
|
| 574 |
+
* when `value` is anything other than an unsigned integer.
|
| 575 |
+
*
|
| 576 |
+
* This function is also available under the `writeUintBE` alias.
|
| 577 |
+
*
|
| 578 |
+
* ```js
|
| 579 |
+
* import { Buffer } from 'node:buffer';
|
| 580 |
+
*
|
| 581 |
+
* const buf = Buffer.allocUnsafe(6);
|
| 582 |
+
*
|
| 583 |
+
* buf.writeUIntBE(0x1234567890ab, 0, 6);
|
| 584 |
+
*
|
| 585 |
+
* console.log(buf);
|
| 586 |
+
* // Prints: <Buffer 12 34 56 78 90 ab>
|
| 587 |
+
* ```
|
| 588 |
+
* @since v0.5.5
|
| 589 |
+
* @param value Number to be written to `buf`.
|
| 590 |
+
* @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
| 591 |
+
* @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
| 592 |
+
* @return `offset` plus the number of bytes written.
|
| 593 |
+
*/
|
| 594 |
+
writeUIntBE(value: number, offset: number, byteLength: number): number;
|
| 595 |
+
/**
|
| 596 |
+
* @alias Buffer.writeUIntBE
|
| 597 |
+
* @since v14.9.0, v12.19.0
|
| 598 |
+
*/
|
| 599 |
+
writeUintBE(value: number, offset: number, byteLength: number): number;
|
| 600 |
+
/**
|
| 601 |
+
* Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
|
| 602 |
+
* when `value` is anything other than a signed integer.
|
| 603 |
+
*
|
| 604 |
+
* ```js
|
| 605 |
+
* import { Buffer } from 'node:buffer';
|
| 606 |
+
*
|
| 607 |
+
* const buf = Buffer.allocUnsafe(6);
|
| 608 |
+
*
|
| 609 |
+
* buf.writeIntLE(0x1234567890ab, 0, 6);
|
| 610 |
+
*
|
| 611 |
+
* console.log(buf);
|
| 612 |
+
* // Prints: <Buffer ab 90 78 56 34 12>
|
| 613 |
+
* ```
|
| 614 |
+
* @since v0.11.15
|
| 615 |
+
* @param value Number to be written to `buf`.
|
| 616 |
+
* @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
| 617 |
+
* @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
| 618 |
+
* @return `offset` plus the number of bytes written.
|
| 619 |
+
*/
|
| 620 |
+
writeIntLE(value: number, offset: number, byteLength: number): number;
|
| 621 |
+
/**
|
| 622 |
+
* 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
|
| 623 |
+
* signed integer.
|
| 624 |
+
*
|
| 625 |
+
* ```js
|
| 626 |
+
* import { Buffer } from 'node:buffer';
|
| 627 |
+
*
|
| 628 |
+
* const buf = Buffer.allocUnsafe(6);
|
| 629 |
+
*
|
| 630 |
+
* buf.writeIntBE(0x1234567890ab, 0, 6);
|
| 631 |
+
*
|
| 632 |
+
* console.log(buf);
|
| 633 |
+
* // Prints: <Buffer 12 34 56 78 90 ab>
|
| 634 |
+
* ```
|
| 635 |
+
* @since v0.11.15
|
| 636 |
+
* @param value Number to be written to `buf`.
|
| 637 |
+
* @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
| 638 |
+
* @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
|
| 639 |
+
* @return `offset` plus the number of bytes written.
|
| 640 |
+
*/
|
| 641 |
+
writeIntBE(value: number, offset: number, byteLength: number): number;
|
| 642 |
+
/**
|
| 643 |
+
* Reads an unsigned, big-endian 64-bit integer from `buf` at the specified`offset`.
|
| 644 |
+
*
|
| 645 |
+
* This function is also available under the `readBigUint64BE` alias.
|
| 646 |
+
*
|
| 647 |
+
* ```js
|
| 648 |
+
* import { Buffer } from 'node:buffer';
|
| 649 |
+
*
|
| 650 |
+
* const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
|
| 651 |
+
*
|
| 652 |
+
* console.log(buf.readBigUInt64BE(0));
|
| 653 |
+
* // Prints: 4294967295n
|
| 654 |
+
* ```
|
| 655 |
+
* @since v12.0.0, v10.20.0
|
| 656 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
| 657 |
+
*/
|
| 658 |
+
readBigUInt64BE(offset?: number): bigint;
|
| 659 |
+
/**
|
| 660 |
+
* @alias Buffer.readBigUInt64BE
|
| 661 |
+
* @since v14.10.0, v12.19.0
|
| 662 |
+
*/
|
| 663 |
+
readBigUint64BE(offset?: number): bigint;
|
| 664 |
+
/**
|
| 665 |
+
* Reads an unsigned, little-endian 64-bit integer from `buf` at the specified`offset`.
|
| 666 |
+
*
|
| 667 |
+
* This function is also available under the `readBigUint64LE` alias.
|
| 668 |
+
*
|
| 669 |
+
* ```js
|
| 670 |
+
* import { Buffer } from 'node:buffer';
|
| 671 |
+
*
|
| 672 |
+
* const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
|
| 673 |
+
*
|
| 674 |
+
* console.log(buf.readBigUInt64LE(0));
|
| 675 |
+
* // Prints: 18446744069414584320n
|
| 676 |
+
* ```
|
| 677 |
+
* @since v12.0.0, v10.20.0
|
| 678 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
| 679 |
+
*/
|
| 680 |
+
readBigUInt64LE(offset?: number): bigint;
|
| 681 |
+
/**
|
| 682 |
+
* @alias Buffer.readBigUInt64LE
|
| 683 |
+
* @since v14.10.0, v12.19.0
|
| 684 |
+
*/
|
| 685 |
+
readBigUint64LE(offset?: number): bigint;
|
| 686 |
+
/**
|
| 687 |
+
* Reads a signed, big-endian 64-bit integer from `buf` at the specified `offset`.
|
| 688 |
+
*
|
| 689 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed
|
| 690 |
+
* values.
|
| 691 |
+
* @since v12.0.0, v10.20.0
|
| 692 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
| 693 |
+
*/
|
| 694 |
+
readBigInt64BE(offset?: number): bigint;
|
| 695 |
+
/**
|
| 696 |
+
* Reads a signed, little-endian 64-bit integer from `buf` at the specified`offset`.
|
| 697 |
+
*
|
| 698 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed
|
| 699 |
+
* values.
|
| 700 |
+
* @since v12.0.0, v10.20.0
|
| 701 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
|
| 702 |
+
*/
|
| 703 |
+
readBigInt64LE(offset?: number): bigint;
|
| 704 |
+
/**
|
| 705 |
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an unsigned, little-endian integer supporting
|
| 706 |
+
* up to 48 bits of accuracy.
|
| 707 |
+
*
|
| 708 |
+
* This function is also available under the `readUintLE` alias.
|
| 709 |
+
*
|
| 710 |
+
* ```js
|
| 711 |
+
* import { Buffer } from 'node:buffer';
|
| 712 |
+
*
|
| 713 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
| 714 |
+
*
|
| 715 |
+
* console.log(buf.readUIntLE(0, 6).toString(16));
|
| 716 |
+
* // Prints: ab9078563412
|
| 717 |
+
* ```
|
| 718 |
+
* @since v0.11.15
|
| 719 |
+
* @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
| 720 |
+
* @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
| 721 |
+
*/
|
| 722 |
+
readUIntLE(offset: number, byteLength: number): number;
|
| 723 |
+
/**
|
| 724 |
+
* @alias Buffer.readUIntLE
|
| 725 |
+
* @since v14.9.0, v12.19.0
|
| 726 |
+
*/
|
| 727 |
+
readUintLE(offset: number, byteLength: number): number;
|
| 728 |
+
/**
|
| 729 |
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an unsigned big-endian integer supporting
|
| 730 |
+
* up to 48 bits of accuracy.
|
| 731 |
+
*
|
| 732 |
+
* This function is also available under the `readUintBE` alias.
|
| 733 |
+
*
|
| 734 |
+
* ```js
|
| 735 |
+
* import { Buffer } from 'node:buffer';
|
| 736 |
+
*
|
| 737 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
| 738 |
+
*
|
| 739 |
+
* console.log(buf.readUIntBE(0, 6).toString(16));
|
| 740 |
+
* // Prints: 1234567890ab
|
| 741 |
+
* console.log(buf.readUIntBE(1, 6).toString(16));
|
| 742 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 743 |
+
* ```
|
| 744 |
+
* @since v0.11.15
|
| 745 |
+
* @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
| 746 |
+
* @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
| 747 |
+
*/
|
| 748 |
+
readUIntBE(offset: number, byteLength: number): number;
|
| 749 |
+
/**
|
| 750 |
+
* @alias Buffer.readUIntBE
|
| 751 |
+
* @since v14.9.0, v12.19.0
|
| 752 |
+
*/
|
| 753 |
+
readUintBE(offset: number, byteLength: number): number;
|
| 754 |
+
/**
|
| 755 |
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a little-endian, two's complement signed value
|
| 756 |
+
* supporting up to 48 bits of accuracy.
|
| 757 |
+
*
|
| 758 |
+
* ```js
|
| 759 |
+
* import { Buffer } from 'node:buffer';
|
| 760 |
+
*
|
| 761 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
| 762 |
+
*
|
| 763 |
+
* console.log(buf.readIntLE(0, 6).toString(16));
|
| 764 |
+
* // Prints: -546f87a9cbee
|
| 765 |
+
* ```
|
| 766 |
+
* @since v0.11.15
|
| 767 |
+
* @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
| 768 |
+
* @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
| 769 |
+
*/
|
| 770 |
+
readIntLE(offset: number, byteLength: number): number;
|
| 771 |
+
/**
|
| 772 |
+
* Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a big-endian, two's complement signed value
|
| 773 |
+
* supporting up to 48 bits of accuracy.
|
| 774 |
+
*
|
| 775 |
+
* ```js
|
| 776 |
+
* import { Buffer } from 'node:buffer';
|
| 777 |
+
*
|
| 778 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
|
| 779 |
+
*
|
| 780 |
+
* console.log(buf.readIntBE(0, 6).toString(16));
|
| 781 |
+
* // Prints: 1234567890ab
|
| 782 |
+
* console.log(buf.readIntBE(1, 6).toString(16));
|
| 783 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 784 |
+
* console.log(buf.readIntBE(1, 0).toString(16));
|
| 785 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 786 |
+
* ```
|
| 787 |
+
* @since v0.11.15
|
| 788 |
+
* @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
|
| 789 |
+
* @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
|
| 790 |
+
*/
|
| 791 |
+
readIntBE(offset: number, byteLength: number): number;
|
| 792 |
+
/**
|
| 793 |
+
* Reads an unsigned 8-bit integer from `buf` at the specified `offset`.
|
| 794 |
+
*
|
| 795 |
+
* This function is also available under the `readUint8` alias.
|
| 796 |
+
*
|
| 797 |
+
* ```js
|
| 798 |
+
* import { Buffer } from 'node:buffer';
|
| 799 |
+
*
|
| 800 |
+
* const buf = Buffer.from([1, -2]);
|
| 801 |
+
*
|
| 802 |
+
* console.log(buf.readUInt8(0));
|
| 803 |
+
* // Prints: 1
|
| 804 |
+
* console.log(buf.readUInt8(1));
|
| 805 |
+
* // Prints: 254
|
| 806 |
+
* console.log(buf.readUInt8(2));
|
| 807 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 808 |
+
* ```
|
| 809 |
+
* @since v0.5.0
|
| 810 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
|
| 811 |
+
*/
|
| 812 |
+
readUInt8(offset?: number): number;
|
| 813 |
+
/**
|
| 814 |
+
* @alias Buffer.readUInt8
|
| 815 |
+
* @since v14.9.0, v12.19.0
|
| 816 |
+
*/
|
| 817 |
+
readUint8(offset?: number): number;
|
| 818 |
+
/**
|
| 819 |
+
* Reads an unsigned, little-endian 16-bit integer from `buf` at the specified `offset`.
|
| 820 |
+
*
|
| 821 |
+
* This function is also available under the `readUint16LE` alias.
|
| 822 |
+
*
|
| 823 |
+
* ```js
|
| 824 |
+
* import { Buffer } from 'node:buffer';
|
| 825 |
+
*
|
| 826 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56]);
|
| 827 |
+
*
|
| 828 |
+
* console.log(buf.readUInt16LE(0).toString(16));
|
| 829 |
+
* // Prints: 3412
|
| 830 |
+
* console.log(buf.readUInt16LE(1).toString(16));
|
| 831 |
+
* // Prints: 5634
|
| 832 |
+
* console.log(buf.readUInt16LE(2).toString(16));
|
| 833 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 834 |
+
* ```
|
| 835 |
+
* @since v0.5.5
|
| 836 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
| 837 |
+
*/
|
| 838 |
+
readUInt16LE(offset?: number): number;
|
| 839 |
+
/**
|
| 840 |
+
* @alias Buffer.readUInt16LE
|
| 841 |
+
* @since v14.9.0, v12.19.0
|
| 842 |
+
*/
|
| 843 |
+
readUint16LE(offset?: number): number;
|
| 844 |
+
/**
|
| 845 |
+
* Reads an unsigned, big-endian 16-bit integer from `buf` at the specified`offset`.
|
| 846 |
+
*
|
| 847 |
+
* This function is also available under the `readUint16BE` alias.
|
| 848 |
+
*
|
| 849 |
+
* ```js
|
| 850 |
+
* import { Buffer } from 'node:buffer';
|
| 851 |
+
*
|
| 852 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56]);
|
| 853 |
+
*
|
| 854 |
+
* console.log(buf.readUInt16BE(0).toString(16));
|
| 855 |
+
* // Prints: 1234
|
| 856 |
+
* console.log(buf.readUInt16BE(1).toString(16));
|
| 857 |
+
* // Prints: 3456
|
| 858 |
+
* ```
|
| 859 |
+
* @since v0.5.5
|
| 860 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
| 861 |
+
*/
|
| 862 |
+
readUInt16BE(offset?: number): number;
|
| 863 |
+
/**
|
| 864 |
+
* @alias Buffer.readUInt16BE
|
| 865 |
+
* @since v14.9.0, v12.19.0
|
| 866 |
+
*/
|
| 867 |
+
readUint16BE(offset?: number): number;
|
| 868 |
+
/**
|
| 869 |
+
* Reads an unsigned, little-endian 32-bit integer from `buf` at the specified`offset`.
|
| 870 |
+
*
|
| 871 |
+
* This function is also available under the `readUint32LE` alias.
|
| 872 |
+
*
|
| 873 |
+
* ```js
|
| 874 |
+
* import { Buffer } from 'node:buffer';
|
| 875 |
+
*
|
| 876 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
|
| 877 |
+
*
|
| 878 |
+
* console.log(buf.readUInt32LE(0).toString(16));
|
| 879 |
+
* // Prints: 78563412
|
| 880 |
+
* console.log(buf.readUInt32LE(1).toString(16));
|
| 881 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 882 |
+
* ```
|
| 883 |
+
* @since v0.5.5
|
| 884 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 885 |
+
*/
|
| 886 |
+
readUInt32LE(offset?: number): number;
|
| 887 |
+
/**
|
| 888 |
+
* @alias Buffer.readUInt32LE
|
| 889 |
+
* @since v14.9.0, v12.19.0
|
| 890 |
+
*/
|
| 891 |
+
readUint32LE(offset?: number): number;
|
| 892 |
+
/**
|
| 893 |
+
* Reads an unsigned, big-endian 32-bit integer from `buf` at the specified`offset`.
|
| 894 |
+
*
|
| 895 |
+
* This function is also available under the `readUint32BE` alias.
|
| 896 |
+
*
|
| 897 |
+
* ```js
|
| 898 |
+
* import { Buffer } from 'node:buffer';
|
| 899 |
+
*
|
| 900 |
+
* const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
|
| 901 |
+
*
|
| 902 |
+
* console.log(buf.readUInt32BE(0).toString(16));
|
| 903 |
+
* // Prints: 12345678
|
| 904 |
+
* ```
|
| 905 |
+
* @since v0.5.5
|
| 906 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 907 |
+
*/
|
| 908 |
+
readUInt32BE(offset?: number): number;
|
| 909 |
+
/**
|
| 910 |
+
* @alias Buffer.readUInt32BE
|
| 911 |
+
* @since v14.9.0, v12.19.0
|
| 912 |
+
*/
|
| 913 |
+
readUint32BE(offset?: number): number;
|
| 914 |
+
/**
|
| 915 |
+
* Reads a signed 8-bit integer from `buf` at the specified `offset`.
|
| 916 |
+
*
|
| 917 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
| 918 |
+
*
|
| 919 |
+
* ```js
|
| 920 |
+
* import { Buffer } from 'node:buffer';
|
| 921 |
+
*
|
| 922 |
+
* const buf = Buffer.from([-1, 5]);
|
| 923 |
+
*
|
| 924 |
+
* console.log(buf.readInt8(0));
|
| 925 |
+
* // Prints: -1
|
| 926 |
+
* console.log(buf.readInt8(1));
|
| 927 |
+
* // Prints: 5
|
| 928 |
+
* console.log(buf.readInt8(2));
|
| 929 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 930 |
+
* ```
|
| 931 |
+
* @since v0.5.0
|
| 932 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
|
| 933 |
+
*/
|
| 934 |
+
readInt8(offset?: number): number;
|
| 935 |
+
/**
|
| 936 |
+
* Reads a signed, little-endian 16-bit integer from `buf` at the specified`offset`.
|
| 937 |
+
*
|
| 938 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
| 939 |
+
*
|
| 940 |
+
* ```js
|
| 941 |
+
* import { Buffer } from 'node:buffer';
|
| 942 |
+
*
|
| 943 |
+
* const buf = Buffer.from([0, 5]);
|
| 944 |
+
*
|
| 945 |
+
* console.log(buf.readInt16LE(0));
|
| 946 |
+
* // Prints: 1280
|
| 947 |
+
* console.log(buf.readInt16LE(1));
|
| 948 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 949 |
+
* ```
|
| 950 |
+
* @since v0.5.5
|
| 951 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
| 952 |
+
*/
|
| 953 |
+
readInt16LE(offset?: number): number;
|
| 954 |
+
/**
|
| 955 |
+
* Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`.
|
| 956 |
+
*
|
| 957 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
| 958 |
+
*
|
| 959 |
+
* ```js
|
| 960 |
+
* import { Buffer } from 'node:buffer';
|
| 961 |
+
*
|
| 962 |
+
* const buf = Buffer.from([0, 5]);
|
| 963 |
+
*
|
| 964 |
+
* console.log(buf.readInt16BE(0));
|
| 965 |
+
* // Prints: 5
|
| 966 |
+
* ```
|
| 967 |
+
* @since v0.5.5
|
| 968 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
|
| 969 |
+
*/
|
| 970 |
+
readInt16BE(offset?: number): number;
|
| 971 |
+
/**
|
| 972 |
+
* Reads a signed, little-endian 32-bit integer from `buf` at the specified`offset`.
|
| 973 |
+
*
|
| 974 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
| 975 |
+
*
|
| 976 |
+
* ```js
|
| 977 |
+
* import { Buffer } from 'node:buffer';
|
| 978 |
+
*
|
| 979 |
+
* const buf = Buffer.from([0, 0, 0, 5]);
|
| 980 |
+
*
|
| 981 |
+
* console.log(buf.readInt32LE(0));
|
| 982 |
+
* // Prints: 83886080
|
| 983 |
+
* console.log(buf.readInt32LE(1));
|
| 984 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 985 |
+
* ```
|
| 986 |
+
* @since v0.5.5
|
| 987 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 988 |
+
*/
|
| 989 |
+
readInt32LE(offset?: number): number;
|
| 990 |
+
/**
|
| 991 |
+
* Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`.
|
| 992 |
+
*
|
| 993 |
+
* Integers read from a `Buffer` are interpreted as two's complement signed values.
|
| 994 |
+
*
|
| 995 |
+
* ```js
|
| 996 |
+
* import { Buffer } from 'node:buffer';
|
| 997 |
+
*
|
| 998 |
+
* const buf = Buffer.from([0, 0, 0, 5]);
|
| 999 |
+
*
|
| 1000 |
+
* console.log(buf.readInt32BE(0));
|
| 1001 |
+
* // Prints: 5
|
| 1002 |
+
* ```
|
| 1003 |
+
* @since v0.5.5
|
| 1004 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 1005 |
+
*/
|
| 1006 |
+
readInt32BE(offset?: number): number;
|
| 1007 |
+
/**
|
| 1008 |
+
* Reads a 32-bit, little-endian float from `buf` at the specified `offset`.
|
| 1009 |
+
*
|
| 1010 |
+
* ```js
|
| 1011 |
+
* import { Buffer } from 'node:buffer';
|
| 1012 |
+
*
|
| 1013 |
+
* const buf = Buffer.from([1, 2, 3, 4]);
|
| 1014 |
+
*
|
| 1015 |
+
* console.log(buf.readFloatLE(0));
|
| 1016 |
+
* // Prints: 1.539989614439558e-36
|
| 1017 |
+
* console.log(buf.readFloatLE(1));
|
| 1018 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 1019 |
+
* ```
|
| 1020 |
+
* @since v0.11.15
|
| 1021 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 1022 |
+
*/
|
| 1023 |
+
readFloatLE(offset?: number): number;
|
| 1024 |
+
/**
|
| 1025 |
+
* Reads a 32-bit, big-endian float from `buf` at the specified `offset`.
|
| 1026 |
+
*
|
| 1027 |
+
* ```js
|
| 1028 |
+
* import { Buffer } from 'node:buffer';
|
| 1029 |
+
*
|
| 1030 |
+
* const buf = Buffer.from([1, 2, 3, 4]);
|
| 1031 |
+
*
|
| 1032 |
+
* console.log(buf.readFloatBE(0));
|
| 1033 |
+
* // Prints: 2.387939260590663e-38
|
| 1034 |
+
* ```
|
| 1035 |
+
* @since v0.11.15
|
| 1036 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 1037 |
+
*/
|
| 1038 |
+
readFloatBE(offset?: number): number;
|
| 1039 |
+
/**
|
| 1040 |
+
* Reads a 64-bit, little-endian double from `buf` at the specified `offset`.
|
| 1041 |
+
*
|
| 1042 |
+
* ```js
|
| 1043 |
+
* import { Buffer } from 'node:buffer';
|
| 1044 |
+
*
|
| 1045 |
+
* const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
| 1046 |
+
*
|
| 1047 |
+
* console.log(buf.readDoubleLE(0));
|
| 1048 |
+
* // Prints: 5.447603722011605e-270
|
| 1049 |
+
* console.log(buf.readDoubleLE(1));
|
| 1050 |
+
* // Throws ERR_OUT_OF_RANGE.
|
| 1051 |
+
* ```
|
| 1052 |
+
* @since v0.11.15
|
| 1053 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
|
| 1054 |
+
*/
|
| 1055 |
+
readDoubleLE(offset?: number): number;
|
| 1056 |
+
/**
|
| 1057 |
+
* Reads a 64-bit, big-endian double from `buf` at the specified `offset`.
|
| 1058 |
+
*
|
| 1059 |
+
* ```js
|
| 1060 |
+
* import { Buffer } from 'node:buffer';
|
| 1061 |
+
*
|
| 1062 |
+
* const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
|
| 1063 |
+
*
|
| 1064 |
+
* console.log(buf.readDoubleBE(0));
|
| 1065 |
+
* // Prints: 8.20788039913184e-304
|
| 1066 |
+
* ```
|
| 1067 |
+
* @since v0.11.15
|
| 1068 |
+
* @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
|
| 1069 |
+
*/
|
| 1070 |
+
readDoubleBE(offset?: number): number;
|
| 1071 |
+
reverse(): this;
|
| 1072 |
+
/**
|
| 1073 |
+
* Interprets `buf` as an array of unsigned 16-bit integers and swaps the
|
| 1074 |
+
* byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 2.
|
| 1075 |
+
*
|
| 1076 |
+
* ```js
|
| 1077 |
+
* import { Buffer } from 'node:buffer';
|
| 1078 |
+
*
|
| 1079 |
+
* const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
| 1080 |
+
*
|
| 1081 |
+
* console.log(buf1);
|
| 1082 |
+
* // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
| 1083 |
+
*
|
| 1084 |
+
* buf1.swap16();
|
| 1085 |
+
*
|
| 1086 |
+
* console.log(buf1);
|
| 1087 |
+
* // Prints: <Buffer 02 01 04 03 06 05 08 07>
|
| 1088 |
+
*
|
| 1089 |
+
* const buf2 = Buffer.from([0x1, 0x2, 0x3]);
|
| 1090 |
+
*
|
| 1091 |
+
* buf2.swap16();
|
| 1092 |
+
* // Throws ERR_INVALID_BUFFER_SIZE.
|
| 1093 |
+
* ```
|
| 1094 |
+
*
|
| 1095 |
+
* One convenient use of `buf.swap16()` is to perform a fast in-place conversion
|
| 1096 |
+
* between UTF-16 little-endian and UTF-16 big-endian:
|
| 1097 |
+
*
|
| 1098 |
+
* ```js
|
| 1099 |
+
* import { Buffer } from 'node:buffer';
|
| 1100 |
+
*
|
| 1101 |
+
* const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
|
| 1102 |
+
* buf.swap16(); // Convert to big-endian UTF-16 text.
|
| 1103 |
+
* ```
|
| 1104 |
+
* @since v5.10.0
|
| 1105 |
+
* @return A reference to `buf`.
|
| 1106 |
+
*/
|
| 1107 |
+
swap16(): this;
|
| 1108 |
+
/**
|
| 1109 |
+
* Interprets `buf` as an array of unsigned 32-bit integers and swaps the
|
| 1110 |
+
* byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 4.
|
| 1111 |
+
*
|
| 1112 |
+
* ```js
|
| 1113 |
+
* import { Buffer } from 'node:buffer';
|
| 1114 |
+
*
|
| 1115 |
+
* const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
| 1116 |
+
*
|
| 1117 |
+
* console.log(buf1);
|
| 1118 |
+
* // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
| 1119 |
+
*
|
| 1120 |
+
* buf1.swap32();
|
| 1121 |
+
*
|
| 1122 |
+
* console.log(buf1);
|
| 1123 |
+
* // Prints: <Buffer 04 03 02 01 08 07 06 05>
|
| 1124 |
+
*
|
| 1125 |
+
* const buf2 = Buffer.from([0x1, 0x2, 0x3]);
|
| 1126 |
+
*
|
| 1127 |
+
* buf2.swap32();
|
| 1128 |
+
* // Throws ERR_INVALID_BUFFER_SIZE.
|
| 1129 |
+
* ```
|
| 1130 |
+
* @since v5.10.0
|
| 1131 |
+
* @return A reference to `buf`.
|
| 1132 |
+
*/
|
| 1133 |
+
swap32(): this;
|
| 1134 |
+
/**
|
| 1135 |
+
* Interprets `buf` as an array of 64-bit numbers and swaps byte order _in-place_.
|
| 1136 |
+
* Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 8.
|
| 1137 |
+
*
|
| 1138 |
+
* ```js
|
| 1139 |
+
* import { Buffer } from 'node:buffer';
|
| 1140 |
+
*
|
| 1141 |
+
* const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
| 1142 |
+
*
|
| 1143 |
+
* console.log(buf1);
|
| 1144 |
+
* // Prints: <Buffer 01 02 03 04 05 06 07 08>
|
| 1145 |
+
*
|
| 1146 |
+
* buf1.swap64();
|
| 1147 |
+
*
|
| 1148 |
+
* console.log(buf1);
|
| 1149 |
+
* // Prints: <Buffer 08 07 06 05 04 03 02 01>
|
| 1150 |
+
*
|
| 1151 |
+
* const buf2 = Buffer.from([0x1, 0x2, 0x3]);
|
| 1152 |
+
*
|
| 1153 |
+
* buf2.swap64();
|
| 1154 |
+
* // Throws ERR_INVALID_BUFFER_SIZE.
|
| 1155 |
+
* ```
|
| 1156 |
+
* @since v6.3.0
|
| 1157 |
+
* @return A reference to `buf`.
|
| 1158 |
+
*/
|
| 1159 |
+
swap64(): this;
|
| 1160 |
+
/**
|
| 1161 |
+
* Writes `value` to `buf` at the specified `offset`. `value` must be a
|
| 1162 |
+
* valid unsigned 8-bit integer. Behavior is undefined when `value` is anything
|
| 1163 |
+
* other than an unsigned 8-bit integer.
|
| 1164 |
+
*
|
| 1165 |
+
* This function is also available under the `writeUint8` alias.
|
| 1166 |
+
*
|
| 1167 |
+
* ```js
|
| 1168 |
+
* import { Buffer } from 'node:buffer';
|
| 1169 |
+
*
|
| 1170 |
+
* const buf = Buffer.allocUnsafe(4);
|
| 1171 |
+
*
|
| 1172 |
+
* buf.writeUInt8(0x3, 0);
|
| 1173 |
+
* buf.writeUInt8(0x4, 1);
|
| 1174 |
+
* buf.writeUInt8(0x23, 2);
|
| 1175 |
+
* buf.writeUInt8(0x42, 3);
|
| 1176 |
+
*
|
| 1177 |
+
* console.log(buf);
|
| 1178 |
+
* // Prints: <Buffer 03 04 23 42>
|
| 1179 |
+
* ```
|
| 1180 |
+
* @since v0.5.0
|
| 1181 |
+
* @param value Number to be written to `buf`.
|
| 1182 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
|
| 1183 |
+
* @return `offset` plus the number of bytes written.
|
| 1184 |
+
*/
|
| 1185 |
+
writeUInt8(value: number, offset?: number): number;
|
| 1186 |
+
/**
|
| 1187 |
+
* @alias Buffer.writeUInt8
|
| 1188 |
+
* @since v14.9.0, v12.19.0
|
| 1189 |
+
*/
|
| 1190 |
+
writeUint8(value: number, offset?: number): number;
|
| 1191 |
+
/**
|
| 1192 |
+
* 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
|
| 1193 |
+
* anything other than an unsigned 16-bit integer.
|
| 1194 |
+
*
|
| 1195 |
+
* This function is also available under the `writeUint16LE` alias.
|
| 1196 |
+
*
|
| 1197 |
+
* ```js
|
| 1198 |
+
* import { Buffer } from 'node:buffer';
|
| 1199 |
+
*
|
| 1200 |
+
* const buf = Buffer.allocUnsafe(4);
|
| 1201 |
+
*
|
| 1202 |
+
* buf.writeUInt16LE(0xdead, 0);
|
| 1203 |
+
* buf.writeUInt16LE(0xbeef, 2);
|
| 1204 |
+
*
|
| 1205 |
+
* console.log(buf);
|
| 1206 |
+
* // Prints: <Buffer ad de ef be>
|
| 1207 |
+
* ```
|
| 1208 |
+
* @since v0.5.5
|
| 1209 |
+
* @param value Number to be written to `buf`.
|
| 1210 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
| 1211 |
+
* @return `offset` plus the number of bytes written.
|
| 1212 |
+
*/
|
| 1213 |
+
writeUInt16LE(value: number, offset?: number): number;
|
| 1214 |
+
/**
|
| 1215 |
+
* @alias Buffer.writeUInt16LE
|
| 1216 |
+
* @since v14.9.0, v12.19.0
|
| 1217 |
+
*/
|
| 1218 |
+
writeUint16LE(value: number, offset?: number): number;
|
| 1219 |
+
/**
|
| 1220 |
+
* 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
|
| 1221 |
+
* unsigned 16-bit integer.
|
| 1222 |
+
*
|
| 1223 |
+
* This function is also available under the `writeUint16BE` alias.
|
| 1224 |
+
*
|
| 1225 |
+
* ```js
|
| 1226 |
+
* import { Buffer } from 'node:buffer';
|
| 1227 |
+
*
|
| 1228 |
+
* const buf = Buffer.allocUnsafe(4);
|
| 1229 |
+
*
|
| 1230 |
+
* buf.writeUInt16BE(0xdead, 0);
|
| 1231 |
+
* buf.writeUInt16BE(0xbeef, 2);
|
| 1232 |
+
*
|
| 1233 |
+
* console.log(buf);
|
| 1234 |
+
* // Prints: <Buffer de ad be ef>
|
| 1235 |
+
* ```
|
| 1236 |
+
* @since v0.5.5
|
| 1237 |
+
* @param value Number to be written to `buf`.
|
| 1238 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
| 1239 |
+
* @return `offset` plus the number of bytes written.
|
| 1240 |
+
*/
|
| 1241 |
+
writeUInt16BE(value: number, offset?: number): number;
|
| 1242 |
+
/**
|
| 1243 |
+
* @alias Buffer.writeUInt16BE
|
| 1244 |
+
* @since v14.9.0, v12.19.0
|
| 1245 |
+
*/
|
| 1246 |
+
writeUint16BE(value: number, offset?: number): number;
|
| 1247 |
+
/**
|
| 1248 |
+
* 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
|
| 1249 |
+
* anything other than an unsigned 32-bit integer.
|
| 1250 |
+
*
|
| 1251 |
+
* This function is also available under the `writeUint32LE` alias.
|
| 1252 |
+
*
|
| 1253 |
+
* ```js
|
| 1254 |
+
* import { Buffer } from 'node:buffer';
|
| 1255 |
+
*
|
| 1256 |
+
* const buf = Buffer.allocUnsafe(4);
|
| 1257 |
+
*
|
| 1258 |
+
* buf.writeUInt32LE(0xfeedface, 0);
|
| 1259 |
+
*
|
| 1260 |
+
* console.log(buf);
|
| 1261 |
+
* // Prints: <Buffer ce fa ed fe>
|
| 1262 |
+
* ```
|
| 1263 |
+
* @since v0.5.5
|
| 1264 |
+
* @param value Number to be written to `buf`.
|
| 1265 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 1266 |
+
* @return `offset` plus the number of bytes written.
|
| 1267 |
+
*/
|
| 1268 |
+
writeUInt32LE(value: number, offset?: number): number;
|
| 1269 |
+
/**
|
| 1270 |
+
* @alias Buffer.writeUInt32LE
|
| 1271 |
+
* @since v14.9.0, v12.19.0
|
| 1272 |
+
*/
|
| 1273 |
+
writeUint32LE(value: number, offset?: number): number;
|
| 1274 |
+
/**
|
| 1275 |
+
* 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
|
| 1276 |
+
* unsigned 32-bit integer.
|
| 1277 |
+
*
|
| 1278 |
+
* This function is also available under the `writeUint32BE` alias.
|
| 1279 |
+
*
|
| 1280 |
+
* ```js
|
| 1281 |
+
* import { Buffer } from 'node:buffer';
|
| 1282 |
+
*
|
| 1283 |
+
* const buf = Buffer.allocUnsafe(4);
|
| 1284 |
+
*
|
| 1285 |
+
* buf.writeUInt32BE(0xfeedface, 0);
|
| 1286 |
+
*
|
| 1287 |
+
* console.log(buf);
|
| 1288 |
+
* // Prints: <Buffer fe ed fa ce>
|
| 1289 |
+
* ```
|
| 1290 |
+
* @since v0.5.5
|
| 1291 |
+
* @param value Number to be written to `buf`.
|
| 1292 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 1293 |
+
* @return `offset` plus the number of bytes written.
|
| 1294 |
+
*/
|
| 1295 |
+
writeUInt32BE(value: number, offset?: number): number;
|
| 1296 |
+
/**
|
| 1297 |
+
* @alias Buffer.writeUInt32BE
|
| 1298 |
+
* @since v14.9.0, v12.19.0
|
| 1299 |
+
*/
|
| 1300 |
+
writeUint32BE(value: number, offset?: number): number;
|
| 1301 |
+
/**
|
| 1302 |
+
* Writes `value` to `buf` at the specified `offset`. `value` must be a valid
|
| 1303 |
+
* signed 8-bit integer. Behavior is undefined when `value` is anything other than
|
| 1304 |
+
* a signed 8-bit integer.
|
| 1305 |
+
*
|
| 1306 |
+
* `value` is interpreted and written as a two's complement signed integer.
|
| 1307 |
+
*
|
| 1308 |
+
* ```js
|
| 1309 |
+
* import { Buffer } from 'node:buffer';
|
| 1310 |
+
*
|
| 1311 |
+
* const buf = Buffer.allocUnsafe(2);
|
| 1312 |
+
*
|
| 1313 |
+
* buf.writeInt8(2, 0);
|
| 1314 |
+
* buf.writeInt8(-2, 1);
|
| 1315 |
+
*
|
| 1316 |
+
* console.log(buf);
|
| 1317 |
+
* // Prints: <Buffer 02 fe>
|
| 1318 |
+
* ```
|
| 1319 |
+
* @since v0.5.0
|
| 1320 |
+
* @param value Number to be written to `buf`.
|
| 1321 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
|
| 1322 |
+
* @return `offset` plus the number of bytes written.
|
| 1323 |
+
*/
|
| 1324 |
+
writeInt8(value: number, offset?: number): number;
|
| 1325 |
+
/**
|
| 1326 |
+
* 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
|
| 1327 |
+
* anything other than a signed 16-bit integer.
|
| 1328 |
+
*
|
| 1329 |
+
* The `value` is interpreted and written as a two's complement signed integer.
|
| 1330 |
+
*
|
| 1331 |
+
* ```js
|
| 1332 |
+
* import { Buffer } from 'node:buffer';
|
| 1333 |
+
*
|
| 1334 |
+
* const buf = Buffer.allocUnsafe(2);
|
| 1335 |
+
*
|
| 1336 |
+
* buf.writeInt16LE(0x0304, 0);
|
| 1337 |
+
*
|
| 1338 |
+
* console.log(buf);
|
| 1339 |
+
* // Prints: <Buffer 04 03>
|
| 1340 |
+
* ```
|
| 1341 |
+
* @since v0.5.5
|
| 1342 |
+
* @param value Number to be written to `buf`.
|
| 1343 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
| 1344 |
+
* @return `offset` plus the number of bytes written.
|
| 1345 |
+
*/
|
| 1346 |
+
writeInt16LE(value: number, offset?: number): number;
|
| 1347 |
+
/**
|
| 1348 |
+
* 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
|
| 1349 |
+
* anything other than a signed 16-bit integer.
|
| 1350 |
+
*
|
| 1351 |
+
* The `value` is interpreted and written as a two's complement signed integer.
|
| 1352 |
+
*
|
| 1353 |
+
* ```js
|
| 1354 |
+
* import { Buffer } from 'node:buffer';
|
| 1355 |
+
*
|
| 1356 |
+
* const buf = Buffer.allocUnsafe(2);
|
| 1357 |
+
*
|
| 1358 |
+
* buf.writeInt16BE(0x0102, 0);
|
| 1359 |
+
*
|
| 1360 |
+
* console.log(buf);
|
| 1361 |
+
* // Prints: <Buffer 01 02>
|
| 1362 |
+
* ```
|
| 1363 |
+
* @since v0.5.5
|
| 1364 |
+
* @param value Number to be written to `buf`.
|
| 1365 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
| 1366 |
+
* @return `offset` plus the number of bytes written.
|
| 1367 |
+
*/
|
| 1368 |
+
writeInt16BE(value: number, offset?: number): number;
|
| 1369 |
+
/**
|
| 1370 |
+
* 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
|
| 1371 |
+
* anything other than a signed 32-bit integer.
|
| 1372 |
+
*
|
| 1373 |
+
* The `value` is interpreted and written as a two's complement signed integer.
|
| 1374 |
+
*
|
| 1375 |
+
* ```js
|
| 1376 |
+
* import { Buffer } from 'node:buffer';
|
| 1377 |
+
*
|
| 1378 |
+
* const buf = Buffer.allocUnsafe(4);
|
| 1379 |
+
*
|
| 1380 |
+
* buf.writeInt32LE(0x05060708, 0);
|
| 1381 |
+
*
|
| 1382 |
+
* console.log(buf);
|
| 1383 |
+
* // Prints: <Buffer 08 07 06 05>
|
| 1384 |
+
* ```
|
| 1385 |
+
* @since v0.5.5
|
| 1386 |
+
* @param value Number to be written to `buf`.
|
| 1387 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 1388 |
+
* @return `offset` plus the number of bytes written.
|
| 1389 |
+
*/
|
| 1390 |
+
writeInt32LE(value: number, offset?: number): number;
|
| 1391 |
+
/**
|
| 1392 |
+
* 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
|
| 1393 |
+
* anything other than a signed 32-bit integer.
|
| 1394 |
+
*
|
| 1395 |
+
* The `value` is interpreted and written as a two's complement signed integer.
|
| 1396 |
+
*
|
| 1397 |
+
* ```js
|
| 1398 |
+
* import { Buffer } from 'node:buffer';
|
| 1399 |
+
*
|
| 1400 |
+
* const buf = Buffer.allocUnsafe(4);
|
| 1401 |
+
*
|
| 1402 |
+
* buf.writeInt32BE(0x01020304, 0);
|
| 1403 |
+
*
|
| 1404 |
+
* console.log(buf);
|
| 1405 |
+
* // Prints: <Buffer 01 02 03 04>
|
| 1406 |
+
* ```
|
| 1407 |
+
* @since v0.5.5
|
| 1408 |
+
* @param value Number to be written to `buf`.
|
| 1409 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 1410 |
+
* @return `offset` plus the number of bytes written.
|
| 1411 |
+
*/
|
| 1412 |
+
writeInt32BE(value: number, offset?: number): number;
|
| 1413 |
+
/**
|
| 1414 |
+
* Writes `value` to `buf` at the specified `offset` as little-endian. Behavior is
|
| 1415 |
+
* undefined when `value` is anything other than a JavaScript number.
|
| 1416 |
+
*
|
| 1417 |
+
* ```js
|
| 1418 |
+
* import { Buffer } from 'node:buffer';
|
| 1419 |
+
*
|
| 1420 |
+
* const buf = Buffer.allocUnsafe(4);
|
| 1421 |
+
*
|
| 1422 |
+
* buf.writeFloatLE(0xcafebabe, 0);
|
| 1423 |
+
*
|
| 1424 |
+
* console.log(buf);
|
| 1425 |
+
* // Prints: <Buffer bb fe 4a 4f>
|
| 1426 |
+
* ```
|
| 1427 |
+
* @since v0.11.15
|
| 1428 |
+
* @param value Number to be written to `buf`.
|
| 1429 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 1430 |
+
* @return `offset` plus the number of bytes written.
|
| 1431 |
+
*/
|
| 1432 |
+
writeFloatLE(value: number, offset?: number): number;
|
| 1433 |
+
/**
|
| 1434 |
+
* Writes `value` to `buf` at the specified `offset` as big-endian. Behavior is
|
| 1435 |
+
* undefined when `value` is anything other than a JavaScript number.
|
| 1436 |
+
*
|
| 1437 |
+
* ```js
|
| 1438 |
+
* import { Buffer } from 'node:buffer';
|
| 1439 |
+
*
|
| 1440 |
+
* const buf = Buffer.allocUnsafe(4);
|
| 1441 |
+
*
|
| 1442 |
+
* buf.writeFloatBE(0xcafebabe, 0);
|
| 1443 |
+
*
|
| 1444 |
+
* console.log(buf);
|
| 1445 |
+
* // Prints: <Buffer 4f 4a fe bb>
|
| 1446 |
+
* ```
|
| 1447 |
+
* @since v0.11.15
|
| 1448 |
+
* @param value Number to be written to `buf`.
|
| 1449 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
| 1450 |
+
* @return `offset` plus the number of bytes written.
|
| 1451 |
+
*/
|
| 1452 |
+
writeFloatBE(value: number, offset?: number): number;
|
| 1453 |
+
/**
|
| 1454 |
+
* 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
|
| 1455 |
+
* other than a JavaScript number.
|
| 1456 |
+
*
|
| 1457 |
+
* ```js
|
| 1458 |
+
* import { Buffer } from 'node:buffer';
|
| 1459 |
+
*
|
| 1460 |
+
* const buf = Buffer.allocUnsafe(8);
|
| 1461 |
+
*
|
| 1462 |
+
* buf.writeDoubleLE(123.456, 0);
|
| 1463 |
+
*
|
| 1464 |
+
* console.log(buf);
|
| 1465 |
+
* // Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>
|
| 1466 |
+
* ```
|
| 1467 |
+
* @since v0.11.15
|
| 1468 |
+
* @param value Number to be written to `buf`.
|
| 1469 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
|
| 1470 |
+
* @return `offset` plus the number of bytes written.
|
| 1471 |
+
*/
|
| 1472 |
+
writeDoubleLE(value: number, offset?: number): number;
|
| 1473 |
+
/**
|
| 1474 |
+
* 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
|
| 1475 |
+
* other than a JavaScript number.
|
| 1476 |
+
*
|
| 1477 |
+
* ```js
|
| 1478 |
+
* import { Buffer } from 'node:buffer';
|
| 1479 |
+
*
|
| 1480 |
+
* const buf = Buffer.allocUnsafe(8);
|
| 1481 |
+
*
|
| 1482 |
+
* buf.writeDoubleBE(123.456, 0);
|
| 1483 |
+
*
|
| 1484 |
+
* console.log(buf);
|
| 1485 |
+
* // Prints: <Buffer 40 5e dd 2f 1a 9f be 77>
|
| 1486 |
+
* ```
|
| 1487 |
+
* @since v0.11.15
|
| 1488 |
+
* @param value Number to be written to `buf`.
|
| 1489 |
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
|
| 1490 |
+
* @return `offset` plus the number of bytes written.
|
| 1491 |
+
*/
|
| 1492 |
+
writeDoubleBE(value: number, offset?: number): number;
|
| 1493 |
+
/**
|
| 1494 |
+
* Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
|
| 1495 |
+
* the entire `buf` will be filled:
|
| 1496 |
+
*
|
| 1497 |
+
* ```js
|
| 1498 |
+
* import { Buffer } from 'node:buffer';
|
| 1499 |
+
*
|
| 1500 |
+
* // Fill a `Buffer` with the ASCII character 'h'.
|
| 1501 |
+
*
|
| 1502 |
+
* const b = Buffer.allocUnsafe(50).fill('h');
|
| 1503 |
+
*
|
| 1504 |
+
* console.log(b.toString());
|
| 1505 |
+
* // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
|
| 1506 |
+
*
|
| 1507 |
+
* // Fill a buffer with empty string
|
| 1508 |
+
* const c = Buffer.allocUnsafe(5).fill('');
|
| 1509 |
+
*
|
| 1510 |
+
* console.log(c.fill(''));
|
| 1511 |
+
* // Prints: <Buffer 00 00 00 00 00>
|
| 1512 |
+
* ```
|
| 1513 |
+
*
|
| 1514 |
+
* `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or
|
| 1515 |
+
* integer. If the resulting integer is greater than `255` (decimal), `buf` will be
|
| 1516 |
+
* filled with `value & 255`.
|
| 1517 |
+
*
|
| 1518 |
+
* If the final write of a `fill()` operation falls on a multi-byte character,
|
| 1519 |
+
* then only the bytes of that character that fit into `buf` are written:
|
| 1520 |
+
*
|
| 1521 |
+
* ```js
|
| 1522 |
+
* import { Buffer } from 'node:buffer';
|
| 1523 |
+
*
|
| 1524 |
+
* // Fill a `Buffer` with character that takes up two bytes in UTF-8.
|
| 1525 |
+
*
|
| 1526 |
+
* console.log(Buffer.allocUnsafe(5).fill('\u0222'));
|
| 1527 |
+
* // Prints: <Buffer c8 a2 c8 a2 c8>
|
| 1528 |
+
* ```
|
| 1529 |
+
*
|
| 1530 |
+
* If `value` contains invalid characters, it is truncated; if no valid
|
| 1531 |
+
* fill data remains, an exception is thrown:
|
| 1532 |
+
*
|
| 1533 |
+
* ```js
|
| 1534 |
+
* import { Buffer } from 'node:buffer';
|
| 1535 |
+
*
|
| 1536 |
+
* const buf = Buffer.allocUnsafe(5);
|
| 1537 |
+
*
|
| 1538 |
+
* console.log(buf.fill('a'));
|
| 1539 |
+
* // Prints: <Buffer 61 61 61 61 61>
|
| 1540 |
+
* console.log(buf.fill('aazz', 'hex'));
|
| 1541 |
+
* // Prints: <Buffer aa aa aa aa aa>
|
| 1542 |
+
* console.log(buf.fill('zz', 'hex'));
|
| 1543 |
+
* // Throws an exception.
|
| 1544 |
+
* ```
|
| 1545 |
+
* @since v0.5.0
|
| 1546 |
+
* @param value The value with which to fill `buf`. Empty value (string, Uint8Array, Buffer) is coerced to `0`.
|
| 1547 |
+
* @param [offset=0] Number of bytes to skip before starting to fill `buf`.
|
| 1548 |
+
* @param [end=buf.length] Where to stop filling `buf` (not inclusive).
|
| 1549 |
+
* @param [encoding='utf8'] The encoding for `value` if `value` is a string.
|
| 1550 |
+
* @return A reference to `buf`.
|
| 1551 |
+
*/
|
| 1552 |
+
fill(value: string | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): this;
|
| 1553 |
+
fill(value: string | Uint8Array | number, offset: number, encoding: BufferEncoding): this;
|
| 1554 |
+
fill(value: string | Uint8Array | number, encoding: BufferEncoding): this;
|
| 1555 |
+
/**
|
| 1556 |
+
* If `value` is:
|
| 1557 |
+
*
|
| 1558 |
+
* * a string, `value` is interpreted according to the character encoding in `encoding`.
|
| 1559 |
+
* * a `Buffer` or [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), `value` will be used in its entirety.
|
| 1560 |
+
* To compare a partial `Buffer`, use `buf.subarray`.
|
| 1561 |
+
* * a number, `value` will be interpreted as an unsigned 8-bit integer
|
| 1562 |
+
* value between `0` and `255`.
|
| 1563 |
+
*
|
| 1564 |
+
* ```js
|
| 1565 |
+
* import { Buffer } from 'node:buffer';
|
| 1566 |
+
*
|
| 1567 |
+
* const buf = Buffer.from('this is a buffer');
|
| 1568 |
+
*
|
| 1569 |
+
* console.log(buf.indexOf('this'));
|
| 1570 |
+
* // Prints: 0
|
| 1571 |
+
* console.log(buf.indexOf('is'));
|
| 1572 |
+
* // Prints: 2
|
| 1573 |
+
* console.log(buf.indexOf(Buffer.from('a buffer')));
|
| 1574 |
+
* // Prints: 8
|
| 1575 |
+
* console.log(buf.indexOf(97));
|
| 1576 |
+
* // Prints: 8 (97 is the decimal ASCII value for 'a')
|
| 1577 |
+
* console.log(buf.indexOf(Buffer.from('a buffer example')));
|
| 1578 |
+
* // Prints: -1
|
| 1579 |
+
* console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));
|
| 1580 |
+
* // Prints: 8
|
| 1581 |
+
*
|
| 1582 |
+
* const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
|
| 1583 |
+
*
|
| 1584 |
+
* console.log(utf16Buffer.indexOf('\u03a3', 0, 'utf16le'));
|
| 1585 |
+
* // Prints: 4
|
| 1586 |
+
* console.log(utf16Buffer.indexOf('\u03a3', -4, 'utf16le'));
|
| 1587 |
+
* // Prints: 6
|
| 1588 |
+
* ```
|
| 1589 |
+
*
|
| 1590 |
+
* 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,
|
| 1591 |
+
* an integer between 0 and 255.
|
| 1592 |
+
*
|
| 1593 |
+
* If `byteOffset` is not a number, it will be coerced to a number. If the result
|
| 1594 |
+
* of coercion is `NaN` or `0`, then the entire buffer will be searched. This
|
| 1595 |
+
* behavior matches [`String.prototype.indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf).
|
| 1596 |
+
*
|
| 1597 |
+
* ```js
|
| 1598 |
+
* import { Buffer } from 'node:buffer';
|
| 1599 |
+
*
|
| 1600 |
+
* const b = Buffer.from('abcdef');
|
| 1601 |
+
*
|
| 1602 |
+
* // Passing a value that's a number, but not a valid byte.
|
| 1603 |
+
* // Prints: 2, equivalent to searching for 99 or 'c'.
|
| 1604 |
+
* console.log(b.indexOf(99.9));
|
| 1605 |
+
* console.log(b.indexOf(256 + 99));
|
| 1606 |
+
*
|
| 1607 |
+
* // Passing a byteOffset that coerces to NaN or 0.
|
| 1608 |
+
* // Prints: 1, searching the whole buffer.
|
| 1609 |
+
* console.log(b.indexOf('b', undefined));
|
| 1610 |
+
* console.log(b.indexOf('b', {}));
|
| 1611 |
+
* console.log(b.indexOf('b', null));
|
| 1612 |
+
* console.log(b.indexOf('b', []));
|
| 1613 |
+
* ```
|
| 1614 |
+
*
|
| 1615 |
+
* If `value` is an empty string or empty `Buffer` and `byteOffset` is less
|
| 1616 |
+
* than `buf.length`, `byteOffset` will be returned. If `value` is empty and`byteOffset` is at least `buf.length`, `buf.length` will be returned.
|
| 1617 |
+
* @since v1.5.0
|
| 1618 |
+
* @param value What to search for.
|
| 1619 |
+
* @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
|
| 1620 |
+
* @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`.
|
| 1621 |
+
* @return The index of the first occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
|
| 1622 |
+
*/
|
| 1623 |
+
indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
|
| 1624 |
+
indexOf(value: string | number | Uint8Array, encoding: BufferEncoding): number;
|
| 1625 |
+
/**
|
| 1626 |
+
* Identical to `buf.indexOf()`, except the last occurrence of `value` is found
|
| 1627 |
+
* rather than the first occurrence.
|
| 1628 |
+
*
|
| 1629 |
+
* ```js
|
| 1630 |
+
* import { Buffer } from 'node:buffer';
|
| 1631 |
+
*
|
| 1632 |
+
* const buf = Buffer.from('this buffer is a buffer');
|
| 1633 |
+
*
|
| 1634 |
+
* console.log(buf.lastIndexOf('this'));
|
| 1635 |
+
* // Prints: 0
|
| 1636 |
+
* console.log(buf.lastIndexOf('buffer'));
|
| 1637 |
+
* // Prints: 17
|
| 1638 |
+
* console.log(buf.lastIndexOf(Buffer.from('buffer')));
|
| 1639 |
+
* // Prints: 17
|
| 1640 |
+
* console.log(buf.lastIndexOf(97));
|
| 1641 |
+
* // Prints: 15 (97 is the decimal ASCII value for 'a')
|
| 1642 |
+
* console.log(buf.lastIndexOf(Buffer.from('yolo')));
|
| 1643 |
+
* // Prints: -1
|
| 1644 |
+
* console.log(buf.lastIndexOf('buffer', 5));
|
| 1645 |
+
* // Prints: 5
|
| 1646 |
+
* console.log(buf.lastIndexOf('buffer', 4));
|
| 1647 |
+
* // Prints: -1
|
| 1648 |
+
*
|
| 1649 |
+
* const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
|
| 1650 |
+
*
|
| 1651 |
+
* console.log(utf16Buffer.lastIndexOf('\u03a3', undefined, 'utf16le'));
|
| 1652 |
+
* // Prints: 6
|
| 1653 |
+
* console.log(utf16Buffer.lastIndexOf('\u03a3', -5, 'utf16le'));
|
| 1654 |
+
* // Prints: 4
|
| 1655 |
+
* ```
|
| 1656 |
+
*
|
| 1657 |
+
* 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,
|
| 1658 |
+
* an integer between 0 and 255.
|
| 1659 |
+
*
|
| 1660 |
+
* If `byteOffset` is not a number, it will be coerced to a number. Any arguments
|
| 1661 |
+
* that coerce to `NaN`, like `{}` or `undefined`, will search the whole buffer.
|
| 1662 |
+
* This behavior matches [`String.prototype.lastIndexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf).
|
| 1663 |
+
*
|
| 1664 |
+
* ```js
|
| 1665 |
+
* import { Buffer } from 'node:buffer';
|
| 1666 |
+
*
|
| 1667 |
+
* const b = Buffer.from('abcdef');
|
| 1668 |
+
*
|
| 1669 |
+
* // Passing a value that's a number, but not a valid byte.
|
| 1670 |
+
* // Prints: 2, equivalent to searching for 99 or 'c'.
|
| 1671 |
+
* console.log(b.lastIndexOf(99.9));
|
| 1672 |
+
* console.log(b.lastIndexOf(256 + 99));
|
| 1673 |
+
*
|
| 1674 |
+
* // Passing a byteOffset that coerces to NaN.
|
| 1675 |
+
* // Prints: 1, searching the whole buffer.
|
| 1676 |
+
* console.log(b.lastIndexOf('b', undefined));
|
| 1677 |
+
* console.log(b.lastIndexOf('b', {}));
|
| 1678 |
+
*
|
| 1679 |
+
* // Passing a byteOffset that coerces to 0.
|
| 1680 |
+
* // Prints: -1, equivalent to passing 0.
|
| 1681 |
+
* console.log(b.lastIndexOf('b', null));
|
| 1682 |
+
* console.log(b.lastIndexOf('b', []));
|
| 1683 |
+
* ```
|
| 1684 |
+
*
|
| 1685 |
+
* If `value` is an empty string or empty `Buffer`, `byteOffset` will be returned.
|
| 1686 |
+
* @since v6.0.0
|
| 1687 |
+
* @param value What to search for.
|
| 1688 |
+
* @param [byteOffset=buf.length - 1] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
|
| 1689 |
+
* @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`.
|
| 1690 |
+
* @return The index of the last occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
|
| 1691 |
+
*/
|
| 1692 |
+
lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
|
| 1693 |
+
lastIndexOf(value: string | number | Uint8Array, encoding: BufferEncoding): number;
|
| 1694 |
+
/**
|
| 1695 |
+
* Equivalent to `buf.indexOf() !== -1`.
|
| 1696 |
+
*
|
| 1697 |
+
* ```js
|
| 1698 |
+
* import { Buffer } from 'node:buffer';
|
| 1699 |
+
*
|
| 1700 |
+
* const buf = Buffer.from('this is a buffer');
|
| 1701 |
+
*
|
| 1702 |
+
* console.log(buf.includes('this'));
|
| 1703 |
+
* // Prints: true
|
| 1704 |
+
* console.log(buf.includes('is'));
|
| 1705 |
+
* // Prints: true
|
| 1706 |
+
* console.log(buf.includes(Buffer.from('a buffer')));
|
| 1707 |
+
* // Prints: true
|
| 1708 |
+
* console.log(buf.includes(97));
|
| 1709 |
+
* // Prints: true (97 is the decimal ASCII value for 'a')
|
| 1710 |
+
* console.log(buf.includes(Buffer.from('a buffer example')));
|
| 1711 |
+
* // Prints: false
|
| 1712 |
+
* console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
|
| 1713 |
+
* // Prints: true
|
| 1714 |
+
* console.log(buf.includes('this', 4));
|
| 1715 |
+
* // Prints: false
|
| 1716 |
+
* ```
|
| 1717 |
+
* @since v5.3.0
|
| 1718 |
+
* @param value What to search for.
|
| 1719 |
+
* @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
|
| 1720 |
+
* @param [encoding='utf8'] If `value` is a string, this is its encoding.
|
| 1721 |
+
* @return `true` if `value` was found in `buf`, `false` otherwise.
|
| 1722 |
+
*/
|
| 1723 |
+
includes(value: string | number | Buffer, byteOffset?: number, encoding?: BufferEncoding): boolean;
|
| 1724 |
+
includes(value: string | number | Buffer, encoding: BufferEncoding): boolean;
|
| 1725 |
+
}
|
| 1726 |
+
var Buffer: BufferConstructor;
|
| 1727 |
+
}
|
| 1728 |
+
// #region web types
|
| 1729 |
+
export type BlobPart = NodeJS.BufferSource | Blob | string;
|
| 1730 |
+
export interface BlobPropertyBag {
|
| 1731 |
+
endings?: "native" | "transparent";
|
| 1732 |
+
type?: string;
|
| 1733 |
+
}
|
| 1734 |
+
export interface FilePropertyBag extends BlobPropertyBag {
|
| 1735 |
+
lastModified?: number;
|
| 1736 |
+
}
|
| 1737 |
+
export interface Blob {
|
| 1738 |
+
readonly size: number;
|
| 1739 |
+
readonly type: string;
|
| 1740 |
+
arrayBuffer(): Promise<ArrayBuffer>;
|
| 1741 |
+
bytes(): Promise<NodeJS.NonSharedUint8Array>;
|
| 1742 |
+
slice(start?: number, end?: number, contentType?: string): Blob;
|
| 1743 |
+
stream(): ReadableStream<NodeJS.NonSharedUint8Array>;
|
| 1744 |
+
text(): Promise<string>;
|
| 1745 |
+
}
|
| 1746 |
+
export var Blob: {
|
| 1747 |
+
prototype: Blob;
|
| 1748 |
+
new(blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
| 1749 |
+
};
|
| 1750 |
+
export interface File extends Blob {
|
| 1751 |
+
readonly lastModified: number;
|
| 1752 |
+
readonly name: string;
|
| 1753 |
+
readonly webkitRelativePath: string;
|
| 1754 |
+
}
|
| 1755 |
+
export var File: {
|
| 1756 |
+
prototype: File;
|
| 1757 |
+
new(fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
|
| 1758 |
+
};
|
| 1759 |
+
export import atob = globalThis.atob;
|
| 1760 |
+
export import btoa = globalThis.btoa;
|
| 1761 |
+
// #endregion
|
| 1762 |
+
}
|
| 1763 |
+
declare module "buffer" {
|
| 1764 |
+
export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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:child_process" {
|
| 2 |
+
import { NonSharedBuffer } from "node:buffer";
|
| 3 |
+
import * as dgram from "node:dgram";
|
| 4 |
+
import { Abortable, EventEmitter, InternalEventEmitter } from "node:events";
|
| 5 |
+
import * as net from "node:net";
|
| 6 |
+
import { Readable, Stream, Writable } from "node:stream";
|
| 7 |
+
import { URL } from "node:url";
|
| 8 |
+
type Serializable = string | object | number | boolean | bigint;
|
| 9 |
+
type SendHandle = net.Socket | net.Server | dgram.Socket | undefined;
|
| 10 |
+
interface ChildProcessEventMap {
|
| 11 |
+
"close": [code: number | null, signal: NodeJS.Signals | null];
|
| 12 |
+
"disconnect": [];
|
| 13 |
+
"error": [err: Error];
|
| 14 |
+
"exit": [code: number | null, signal: NodeJS.Signals | null];
|
| 15 |
+
"message": [message: Serializable, sendHandle: SendHandle];
|
| 16 |
+
"spawn": [];
|
| 17 |
+
}
|
| 18 |
+
/**
|
| 19 |
+
* Instances of the `ChildProcess` represent spawned child processes.
|
| 20 |
+
*
|
| 21 |
+
* Instances of `ChildProcess` are not intended to be created directly. Rather,
|
| 22 |
+
* use the {@link spawn}, {@link exec},{@link execFile}, or {@link fork} methods to create
|
| 23 |
+
* instances of `ChildProcess`.
|
| 24 |
+
* @since v2.2.0
|
| 25 |
+
*/
|
| 26 |
+
class ChildProcess implements EventEmitter {
|
| 27 |
+
/**
|
| 28 |
+
* A `Writable Stream` that represents the child process's `stdin`.
|
| 29 |
+
*
|
| 30 |
+
* If a child process waits to read all of its input, the child will not continue
|
| 31 |
+
* until this stream has been closed via `end()`.
|
| 32 |
+
*
|
| 33 |
+
* If the child was spawned with `stdio[0]` set to anything other than `'pipe'`,
|
| 34 |
+
* then this will be `null`.
|
| 35 |
+
*
|
| 36 |
+
* `subprocess.stdin` is an alias for `subprocess.stdio[0]`. Both properties will
|
| 37 |
+
* refer to the same value.
|
| 38 |
+
*
|
| 39 |
+
* The `subprocess.stdin` property can be `null` or `undefined` if the child process could not be successfully spawned.
|
| 40 |
+
* @since v0.1.90
|
| 41 |
+
*/
|
| 42 |
+
stdin: Writable | null;
|
| 43 |
+
/**
|
| 44 |
+
* A `Readable Stream` that represents the child process's `stdout`.
|
| 45 |
+
*
|
| 46 |
+
* If the child was spawned with `stdio[1]` set to anything other than `'pipe'`,
|
| 47 |
+
* then this will be `null`.
|
| 48 |
+
*
|
| 49 |
+
* `subprocess.stdout` is an alias for `subprocess.stdio[1]`. Both properties will
|
| 50 |
+
* refer to the same value.
|
| 51 |
+
*
|
| 52 |
+
* ```js
|
| 53 |
+
* import { spawn } from 'node:child_process';
|
| 54 |
+
*
|
| 55 |
+
* const subprocess = spawn('ls');
|
| 56 |
+
*
|
| 57 |
+
* subprocess.stdout.on('data', (data) => {
|
| 58 |
+
* console.log(`Received chunk ${data}`);
|
| 59 |
+
* });
|
| 60 |
+
* ```
|
| 61 |
+
*
|
| 62 |
+
* The `subprocess.stdout` property can be `null` or `undefined` if the child process could not be successfully spawned.
|
| 63 |
+
* @since v0.1.90
|
| 64 |
+
*/
|
| 65 |
+
stdout: Readable | null;
|
| 66 |
+
/**
|
| 67 |
+
* A `Readable Stream` that represents the child process's `stderr`.
|
| 68 |
+
*
|
| 69 |
+
* If the child was spawned with `stdio[2]` set to anything other than `'pipe'`,
|
| 70 |
+
* then this will be `null`.
|
| 71 |
+
*
|
| 72 |
+
* `subprocess.stderr` is an alias for `subprocess.stdio[2]`. Both properties will
|
| 73 |
+
* refer to the same value.
|
| 74 |
+
*
|
| 75 |
+
* The `subprocess.stderr` property can be `null` or `undefined` if the child process could not be successfully spawned.
|
| 76 |
+
* @since v0.1.90
|
| 77 |
+
*/
|
| 78 |
+
stderr: Readable | null;
|
| 79 |
+
/**
|
| 80 |
+
* The `subprocess.channel` property is a reference to the child's IPC channel. If
|
| 81 |
+
* no IPC channel exists, this property is `undefined`.
|
| 82 |
+
* @since v7.1.0
|
| 83 |
+
*/
|
| 84 |
+
readonly channel?: Control | null;
|
| 85 |
+
/**
|
| 86 |
+
* A sparse array of pipes to the child process, corresponding with positions in
|
| 87 |
+
* the `stdio` option passed to {@link spawn} that have been set
|
| 88 |
+
* 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`,
|
| 89 |
+
* respectively.
|
| 90 |
+
*
|
| 91 |
+
* In the following example, only the child's fd `1` (stdout) is configured as a
|
| 92 |
+
* pipe, so only the parent's `subprocess.stdio[1]` is a stream, all other values
|
| 93 |
+
* in the array are `null`.
|
| 94 |
+
*
|
| 95 |
+
* ```js
|
| 96 |
+
* import assert from 'node:assert';
|
| 97 |
+
* import fs from 'node:fs';
|
| 98 |
+
* import child_process from 'node:child_process';
|
| 99 |
+
*
|
| 100 |
+
* const subprocess = child_process.spawn('ls', {
|
| 101 |
+
* stdio: [
|
| 102 |
+
* 0, // Use parent's stdin for child.
|
| 103 |
+
* 'pipe', // Pipe child's stdout to parent.
|
| 104 |
+
* fs.openSync('err.out', 'w'), // Direct child's stderr to a file.
|
| 105 |
+
* ],
|
| 106 |
+
* });
|
| 107 |
+
*
|
| 108 |
+
* assert.strictEqual(subprocess.stdio[0], null);
|
| 109 |
+
* assert.strictEqual(subprocess.stdio[0], subprocess.stdin);
|
| 110 |
+
*
|
| 111 |
+
* assert(subprocess.stdout);
|
| 112 |
+
* assert.strictEqual(subprocess.stdio[1], subprocess.stdout);
|
| 113 |
+
*
|
| 114 |
+
* assert.strictEqual(subprocess.stdio[2], null);
|
| 115 |
+
* assert.strictEqual(subprocess.stdio[2], subprocess.stderr);
|
| 116 |
+
* ```
|
| 117 |
+
*
|
| 118 |
+
* The `subprocess.stdio` property can be `undefined` if the child process could
|
| 119 |
+
* not be successfully spawned.
|
| 120 |
+
* @since v0.7.10
|
| 121 |
+
*/
|
| 122 |
+
readonly stdio: [
|
| 123 |
+
Writable | null,
|
| 124 |
+
// stdin
|
| 125 |
+
Readable | null,
|
| 126 |
+
// stdout
|
| 127 |
+
Readable | null,
|
| 128 |
+
// stderr
|
| 129 |
+
Readable | Writable | null | undefined,
|
| 130 |
+
// extra
|
| 131 |
+
Readable | Writable | null | undefined, // extra
|
| 132 |
+
];
|
| 133 |
+
/**
|
| 134 |
+
* The `subprocess.killed` property indicates whether the child process
|
| 135 |
+
* successfully received a signal from `subprocess.kill()`. The `killed` property
|
| 136 |
+
* does not indicate that the child process has been terminated.
|
| 137 |
+
* @since v0.5.10
|
| 138 |
+
*/
|
| 139 |
+
readonly killed: boolean;
|
| 140 |
+
/**
|
| 141 |
+
* Returns the process identifier (PID) of the child process. If the child process
|
| 142 |
+
* fails to spawn due to errors, then the value is `undefined` and `error` is
|
| 143 |
+
* emitted.
|
| 144 |
+
*
|
| 145 |
+
* ```js
|
| 146 |
+
* import { spawn } from 'node:child_process';
|
| 147 |
+
* const grep = spawn('grep', ['ssh']);
|
| 148 |
+
*
|
| 149 |
+
* console.log(`Spawned child pid: ${grep.pid}`);
|
| 150 |
+
* grep.stdin.end();
|
| 151 |
+
* ```
|
| 152 |
+
* @since v0.1.90
|
| 153 |
+
*/
|
| 154 |
+
readonly pid?: number | undefined;
|
| 155 |
+
/**
|
| 156 |
+
* The `subprocess.connected` property indicates whether it is still possible to
|
| 157 |
+
* send and receive messages from a child process. When `subprocess.connected` is `false`, it is no longer possible to send or receive messages.
|
| 158 |
+
* @since v0.7.2
|
| 159 |
+
*/
|
| 160 |
+
readonly connected: boolean;
|
| 161 |
+
/**
|
| 162 |
+
* The `subprocess.exitCode` property indicates the exit code of the child process.
|
| 163 |
+
* If the child process is still running, the field will be `null`.
|
| 164 |
+
*
|
| 165 |
+
* When the child process is terminated by a signal, `subprocess.exitCode` will be
|
| 166 |
+
* `null` and `subprocess.signalCode` will be set. To get the corresponding
|
| 167 |
+
* POSIX exit code, use
|
| 168 |
+
* `util.convertProcessSignalToExitCode(subprocess.signalCode)`.
|
| 169 |
+
*/
|
| 170 |
+
readonly exitCode: number | null;
|
| 171 |
+
/**
|
| 172 |
+
* The `subprocess.signalCode` property indicates the signal received by
|
| 173 |
+
* the child process if any, else `null`.
|
| 174 |
+
*/
|
| 175 |
+
readonly signalCode: NodeJS.Signals | null;
|
| 176 |
+
/**
|
| 177 |
+
* The `subprocess.spawnargs` property represents the full list of command-line
|
| 178 |
+
* arguments the child process was launched with.
|
| 179 |
+
*/
|
| 180 |
+
readonly spawnargs: string[];
|
| 181 |
+
/**
|
| 182 |
+
* The `subprocess.spawnfile` property indicates the executable file name of
|
| 183 |
+
* the child process that is launched.
|
| 184 |
+
*
|
| 185 |
+
* For {@link fork}, its value will be equal to `process.execPath`.
|
| 186 |
+
* For {@link spawn}, its value will be the name of
|
| 187 |
+
* the executable file.
|
| 188 |
+
* For {@link exec}, its value will be the name of the shell
|
| 189 |
+
* in which the child process is launched.
|
| 190 |
+
*/
|
| 191 |
+
readonly spawnfile: string;
|
| 192 |
+
/**
|
| 193 |
+
* The `subprocess.kill()` method sends a signal to the child process. If no
|
| 194 |
+
* 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
|
| 195 |
+
* returns `true` if [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) succeeds, and `false` otherwise.
|
| 196 |
+
*
|
| 197 |
+
* ```js
|
| 198 |
+
* import { spawn } from 'node:child_process';
|
| 199 |
+
* const grep = spawn('grep', ['ssh']);
|
| 200 |
+
*
|
| 201 |
+
* grep.on('close', (code, signal) => {
|
| 202 |
+
* console.log(
|
| 203 |
+
* `child process terminated due to receipt of signal ${signal}`);
|
| 204 |
+
* });
|
| 205 |
+
*
|
| 206 |
+
* // Send SIGHUP to process.
|
| 207 |
+
* grep.kill('SIGHUP');
|
| 208 |
+
* ```
|
| 209 |
+
*
|
| 210 |
+
* The `ChildProcess` object may emit an `'error'` event if the signal
|
| 211 |
+
* cannot be delivered. Sending a signal to a child process that has already exited
|
| 212 |
+
* is not an error but may have unforeseen consequences. Specifically, if the
|
| 213 |
+
* process identifier (PID) has been reassigned to another process, the signal will
|
| 214 |
+
* be delivered to that process instead which can have unexpected results.
|
| 215 |
+
*
|
| 216 |
+
* While the function is called `kill`, the signal delivered to the child process
|
| 217 |
+
* may not actually terminate the process.
|
| 218 |
+
*
|
| 219 |
+
* See [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) for reference.
|
| 220 |
+
*
|
| 221 |
+
* On Windows, where POSIX signals do not exist, the `signal` argument will be
|
| 222 |
+
* ignored, and the process will be killed forcefully and abruptly (similar to `'SIGKILL'`).
|
| 223 |
+
* See `Signal Events` for more details.
|
| 224 |
+
*
|
| 225 |
+
* On Linux, child processes of child processes will not be terminated
|
| 226 |
+
* when attempting to kill their parent. This is likely to happen when running a
|
| 227 |
+
* new process in a shell or with the use of the `shell` option of `ChildProcess`:
|
| 228 |
+
*
|
| 229 |
+
* ```js
|
| 230 |
+
* 'use strict';
|
| 231 |
+
* import { spawn } from 'node:child_process';
|
| 232 |
+
*
|
| 233 |
+
* const subprocess = spawn(
|
| 234 |
+
* 'sh',
|
| 235 |
+
* [
|
| 236 |
+
* '-c',
|
| 237 |
+
* `node -e "setInterval(() => {
|
| 238 |
+
* console.log(process.pid, 'is alive')
|
| 239 |
+
* }, 500);"`,
|
| 240 |
+
* ], {
|
| 241 |
+
* stdio: ['inherit', 'inherit', 'inherit'],
|
| 242 |
+
* },
|
| 243 |
+
* );
|
| 244 |
+
*
|
| 245 |
+
* setTimeout(() => {
|
| 246 |
+
* subprocess.kill(); // Does not terminate the Node.js process in the shell.
|
| 247 |
+
* }, 2000);
|
| 248 |
+
* ```
|
| 249 |
+
* @since v0.1.90
|
| 250 |
+
*/
|
| 251 |
+
kill(signal?: NodeJS.Signals | number): boolean;
|
| 252 |
+
/**
|
| 253 |
+
* Calls {@link ChildProcess.kill} with `'SIGTERM'`.
|
| 254 |
+
* @since v20.5.0
|
| 255 |
+
*/
|
| 256 |
+
[Symbol.dispose](): void;
|
| 257 |
+
/**
|
| 258 |
+
* When an IPC channel has been established between the parent and child (
|
| 259 |
+
* i.e. when using {@link fork}), the `subprocess.send()` method can
|
| 260 |
+
* be used to send messages to the child process. When the child process is a
|
| 261 |
+
* Node.js instance, these messages can be received via the `'message'` event.
|
| 262 |
+
*
|
| 263 |
+
* The message goes through serialization and parsing. The resulting
|
| 264 |
+
* message might not be the same as what is originally sent.
|
| 265 |
+
*
|
| 266 |
+
* For example, in the parent script:
|
| 267 |
+
*
|
| 268 |
+
* ```js
|
| 269 |
+
* import cp from 'node:child_process';
|
| 270 |
+
* const n = cp.fork(`${__dirname}/sub.js`);
|
| 271 |
+
*
|
| 272 |
+
* n.on('message', (m) => {
|
| 273 |
+
* console.log('PARENT got message:', m);
|
| 274 |
+
* });
|
| 275 |
+
*
|
| 276 |
+
* // Causes the child to print: CHILD got message: { hello: 'world' }
|
| 277 |
+
* n.send({ hello: 'world' });
|
| 278 |
+
* ```
|
| 279 |
+
*
|
| 280 |
+
* And then the child script, `'sub.js'` might look like this:
|
| 281 |
+
*
|
| 282 |
+
* ```js
|
| 283 |
+
* process.on('message', (m) => {
|
| 284 |
+
* console.log('CHILD got message:', m);
|
| 285 |
+
* });
|
| 286 |
+
*
|
| 287 |
+
* // Causes the parent to print: PARENT got message: { foo: 'bar', baz: null }
|
| 288 |
+
* process.send({ foo: 'bar', baz: NaN });
|
| 289 |
+
* ```
|
| 290 |
+
*
|
| 291 |
+
* Child Node.js processes will have a `process.send()` method of their own
|
| 292 |
+
* that allows the child to send messages back to the parent.
|
| 293 |
+
*
|
| 294 |
+
* There is a special case when sending a `{cmd: 'NODE_foo'}` message. Messages
|
| 295 |
+
* containing a `NODE_` prefix in the `cmd` property are reserved for use within
|
| 296 |
+
* 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.
|
| 297 |
+
* Applications should avoid using such messages or listening for `'internalMessage'` events as it is subject to change without notice.
|
| 298 |
+
*
|
| 299 |
+
* The optional `sendHandle` argument that may be passed to `subprocess.send()` is
|
| 300 |
+
* for passing a TCP server or socket object to the child process. The child will
|
| 301 |
+
* receive the object as the second argument passed to the callback function
|
| 302 |
+
* registered on the `'message'` event. Any data that is received and buffered in
|
| 303 |
+
* the socket will not be sent to the child. Sending IPC sockets is not supported on Windows.
|
| 304 |
+
*
|
| 305 |
+
* The optional `callback` is a function that is invoked after the message is
|
| 306 |
+
* sent but before the child may have received it. The function is called with a
|
| 307 |
+
* single argument: `null` on success, or an `Error` object on failure.
|
| 308 |
+
*
|
| 309 |
+
* If no `callback` function is provided and the message cannot be sent, an `'error'` event will be emitted by the `ChildProcess` object. This can
|
| 310 |
+
* happen, for instance, when the child process has already exited.
|
| 311 |
+
*
|
| 312 |
+
* `subprocess.send()` will return `false` if the channel has closed or when the
|
| 313 |
+
* backlog of unsent messages exceeds a threshold that makes it unwise to send
|
| 314 |
+
* more. Otherwise, the method returns `true`. The `callback` function can be
|
| 315 |
+
* used to implement flow control.
|
| 316 |
+
*
|
| 317 |
+
* #### Example: sending a server object
|
| 318 |
+
*
|
| 319 |
+
* The `sendHandle` argument can be used, for instance, to pass the handle of
|
| 320 |
+
* a TCP server object to the child process as illustrated in the example below:
|
| 321 |
+
*
|
| 322 |
+
* ```js
|
| 323 |
+
* import { createServer } from 'node:net';
|
| 324 |
+
* import { fork } from 'node:child_process';
|
| 325 |
+
* const subprocess = fork('subprocess.js');
|
| 326 |
+
*
|
| 327 |
+
* // Open up the server object and send the handle.
|
| 328 |
+
* const server = createServer();
|
| 329 |
+
* server.on('connection', (socket) => {
|
| 330 |
+
* socket.end('handled by parent');
|
| 331 |
+
* });
|
| 332 |
+
* server.listen(1337, () => {
|
| 333 |
+
* subprocess.send('server', server);
|
| 334 |
+
* });
|
| 335 |
+
* ```
|
| 336 |
+
*
|
| 337 |
+
* The child would then receive the server object as:
|
| 338 |
+
*
|
| 339 |
+
* ```js
|
| 340 |
+
* process.on('message', (m, server) => {
|
| 341 |
+
* if (m === 'server') {
|
| 342 |
+
* server.on('connection', (socket) => {
|
| 343 |
+
* socket.end('handled by child');
|
| 344 |
+
* });
|
| 345 |
+
* }
|
| 346 |
+
* });
|
| 347 |
+
* ```
|
| 348 |
+
*
|
| 349 |
+
* Once the server is now shared between the parent and child, some connections
|
| 350 |
+
* can be handled by the parent and some by the child.
|
| 351 |
+
*
|
| 352 |
+
* 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
|
| 353 |
+
* listening on a `'message'` event instead of `'connection'` and using `server.bind()` instead of `server.listen()`. This is, however, only
|
| 354 |
+
* supported on Unix platforms.
|
| 355 |
+
*
|
| 356 |
+
* #### Example: sending a socket object
|
| 357 |
+
*
|
| 358 |
+
* Similarly, the `sendHandler` argument can be used to pass the handle of a
|
| 359 |
+
* socket to the child process. The example below spawns two children that each
|
| 360 |
+
* handle connections with "normal" or "special" priority:
|
| 361 |
+
*
|
| 362 |
+
* ```js
|
| 363 |
+
* import { createServer } from 'node:net';
|
| 364 |
+
* import { fork } from 'node:child_process';
|
| 365 |
+
* const normal = fork('subprocess.js', ['normal']);
|
| 366 |
+
* const special = fork('subprocess.js', ['special']);
|
| 367 |
+
*
|
| 368 |
+
* // Open up the server and send sockets to child. Use pauseOnConnect to prevent
|
| 369 |
+
* // the sockets from being read before they are sent to the child process.
|
| 370 |
+
* const server = createServer({ pauseOnConnect: true });
|
| 371 |
+
* server.on('connection', (socket) => {
|
| 372 |
+
*
|
| 373 |
+
* // If this is special priority...
|
| 374 |
+
* if (socket.remoteAddress === '74.125.127.100') {
|
| 375 |
+
* special.send('socket', socket);
|
| 376 |
+
* return;
|
| 377 |
+
* }
|
| 378 |
+
* // This is normal priority.
|
| 379 |
+
* normal.send('socket', socket);
|
| 380 |
+
* });
|
| 381 |
+
* server.listen(1337);
|
| 382 |
+
* ```
|
| 383 |
+
*
|
| 384 |
+
* The `subprocess.js` would receive the socket handle as the second argument
|
| 385 |
+
* passed to the event callback function:
|
| 386 |
+
*
|
| 387 |
+
* ```js
|
| 388 |
+
* process.on('message', (m, socket) => {
|
| 389 |
+
* if (m === 'socket') {
|
| 390 |
+
* if (socket) {
|
| 391 |
+
* // Check that the client socket exists.
|
| 392 |
+
* // It is possible for the socket to be closed between the time it is
|
| 393 |
+
* // sent and the time it is received in the child process.
|
| 394 |
+
* socket.end(`Request handled with ${process.argv[2]} priority`);
|
| 395 |
+
* }
|
| 396 |
+
* }
|
| 397 |
+
* });
|
| 398 |
+
* ```
|
| 399 |
+
*
|
| 400 |
+
* Do not use `.maxConnections` on a socket that has been passed to a subprocess.
|
| 401 |
+
* The parent cannot track when the socket is destroyed.
|
| 402 |
+
*
|
| 403 |
+
* Any `'message'` handlers in the subprocess should verify that `socket` exists,
|
| 404 |
+
* as the connection may have been closed during the time it takes to send the
|
| 405 |
+
* connection to the child.
|
| 406 |
+
* @since v0.5.9
|
| 407 |
+
* @param sendHandle `undefined`, or a [`net.Socket`](https://nodejs.org/docs/latest-v25.x/api/net.html#class-netsocket), [`net.Server`](https://nodejs.org/docs/latest-v25.x/api/net.html#class-netserver), or [`dgram.Socket`](https://nodejs.org/docs/latest-v25.x/api/dgram.html#class-dgramsocket) object.
|
| 408 |
+
* @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:
|
| 409 |
+
*/
|
| 410 |
+
send(message: Serializable, callback?: (error: Error | null) => void): boolean;
|
| 411 |
+
send(message: Serializable, sendHandle?: SendHandle, callback?: (error: Error | null) => void): boolean;
|
| 412 |
+
send(
|
| 413 |
+
message: Serializable,
|
| 414 |
+
sendHandle?: SendHandle,
|
| 415 |
+
options?: MessageOptions,
|
| 416 |
+
callback?: (error: Error | null) => void,
|
| 417 |
+
): boolean;
|
| 418 |
+
/**
|
| 419 |
+
* Closes the IPC channel between parent and child, allowing the child to exit
|
| 420 |
+
* gracefully once there are no other connections keeping it alive. After calling
|
| 421 |
+
* this method the `subprocess.connected` and `process.connected` properties in
|
| 422 |
+
* both the parent and child (respectively) will be set to `false`, and it will be
|
| 423 |
+
* no longer possible to pass messages between the processes.
|
| 424 |
+
*
|
| 425 |
+
* The `'disconnect'` event will be emitted when there are no messages in the
|
| 426 |
+
* process of being received. This will most often be triggered immediately after
|
| 427 |
+
* calling `subprocess.disconnect()`.
|
| 428 |
+
*
|
| 429 |
+
* When the child process is a Node.js instance (e.g. spawned using {@link fork}), the `process.disconnect()` method can be invoked
|
| 430 |
+
* within the child process to close the IPC channel as well.
|
| 431 |
+
* @since v0.7.2
|
| 432 |
+
*/
|
| 433 |
+
disconnect(): void;
|
| 434 |
+
/**
|
| 435 |
+
* By default, the parent will wait for the detached child to exit. To prevent the
|
| 436 |
+
* 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
|
| 437 |
+
* include the child in its reference count, allowing the parent to exit
|
| 438 |
+
* independently of the child, unless there is an established IPC channel between
|
| 439 |
+
* the child and the parent.
|
| 440 |
+
*
|
| 441 |
+
* ```js
|
| 442 |
+
* import { spawn } from 'node:child_process';
|
| 443 |
+
*
|
| 444 |
+
* const subprocess = spawn(process.argv[0], ['child_program.js'], {
|
| 445 |
+
* detached: true,
|
| 446 |
+
* stdio: 'ignore',
|
| 447 |
+
* });
|
| 448 |
+
*
|
| 449 |
+
* subprocess.unref();
|
| 450 |
+
* ```
|
| 451 |
+
* @since v0.7.10
|
| 452 |
+
*/
|
| 453 |
+
unref(): void;
|
| 454 |
+
/**
|
| 455 |
+
* Calling `subprocess.ref()` after making a call to `subprocess.unref()` will
|
| 456 |
+
* restore the removed reference count for the child process, forcing the parent
|
| 457 |
+
* to wait for the child to exit before exiting itself.
|
| 458 |
+
*
|
| 459 |
+
* ```js
|
| 460 |
+
* import { spawn } from 'node:child_process';
|
| 461 |
+
*
|
| 462 |
+
* const subprocess = spawn(process.argv[0], ['child_program.js'], {
|
| 463 |
+
* detached: true,
|
| 464 |
+
* stdio: 'ignore',
|
| 465 |
+
* });
|
| 466 |
+
*
|
| 467 |
+
* subprocess.unref();
|
| 468 |
+
* subprocess.ref();
|
| 469 |
+
* ```
|
| 470 |
+
* @since v0.7.10
|
| 471 |
+
*/
|
| 472 |
+
ref(): void;
|
| 473 |
+
}
|
| 474 |
+
interface ChildProcess extends InternalEventEmitter<ChildProcessEventMap> {}
|
| 475 |
+
// return this object when stdio option is undefined or not specified
|
| 476 |
+
interface ChildProcessWithoutNullStreams extends ChildProcess {
|
| 477 |
+
stdin: Writable;
|
| 478 |
+
stdout: Readable;
|
| 479 |
+
stderr: Readable;
|
| 480 |
+
readonly stdio: [
|
| 481 |
+
Writable,
|
| 482 |
+
Readable,
|
| 483 |
+
Readable,
|
| 484 |
+
// stderr
|
| 485 |
+
Readable | Writable | null | undefined,
|
| 486 |
+
// extra, no modification
|
| 487 |
+
Readable | Writable | null | undefined, // extra, no modification
|
| 488 |
+
];
|
| 489 |
+
}
|
| 490 |
+
// return this object when stdio option is a tuple of 3
|
| 491 |
+
interface ChildProcessByStdio<I extends null | Writable, O extends null | Readable, E extends null | Readable>
|
| 492 |
+
extends ChildProcess
|
| 493 |
+
{
|
| 494 |
+
stdin: I;
|
| 495 |
+
stdout: O;
|
| 496 |
+
stderr: E;
|
| 497 |
+
readonly stdio: [
|
| 498 |
+
I,
|
| 499 |
+
O,
|
| 500 |
+
E,
|
| 501 |
+
Readable | Writable | null | undefined,
|
| 502 |
+
// extra, no modification
|
| 503 |
+
Readable | Writable | null | undefined, // extra, no modification
|
| 504 |
+
];
|
| 505 |
+
}
|
| 506 |
+
interface Control extends EventEmitter {
|
| 507 |
+
ref(): void;
|
| 508 |
+
unref(): void;
|
| 509 |
+
}
|
| 510 |
+
interface MessageOptions {
|
| 511 |
+
keepOpen?: boolean | undefined;
|
| 512 |
+
}
|
| 513 |
+
type IOType = "overlapped" | "pipe" | "ignore" | "inherit";
|
| 514 |
+
type StdioOptions = IOType | Array<IOType | "ipc" | Stream | number | null | undefined>;
|
| 515 |
+
type SerializationType = "json" | "advanced";
|
| 516 |
+
interface MessagingOptions extends Abortable {
|
| 517 |
+
/**
|
| 518 |
+
* Specify the kind of serialization used for sending messages between processes.
|
| 519 |
+
* @default 'json'
|
| 520 |
+
*/
|
| 521 |
+
serialization?: SerializationType | undefined;
|
| 522 |
+
/**
|
| 523 |
+
* The signal value to be used when the spawned process will be killed by the abort signal.
|
| 524 |
+
* @default 'SIGTERM'
|
| 525 |
+
*/
|
| 526 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
| 527 |
+
/**
|
| 528 |
+
* In milliseconds the maximum amount of time the process is allowed to run.
|
| 529 |
+
*/
|
| 530 |
+
timeout?: number | undefined;
|
| 531 |
+
}
|
| 532 |
+
interface ProcessEnvOptions {
|
| 533 |
+
uid?: number | undefined;
|
| 534 |
+
gid?: number | undefined;
|
| 535 |
+
cwd?: string | URL | undefined;
|
| 536 |
+
env?: NodeJS.ProcessEnv | undefined;
|
| 537 |
+
}
|
| 538 |
+
interface CommonOptions extends ProcessEnvOptions {
|
| 539 |
+
/**
|
| 540 |
+
* @default false
|
| 541 |
+
*/
|
| 542 |
+
windowsHide?: boolean | undefined;
|
| 543 |
+
/**
|
| 544 |
+
* @default 0
|
| 545 |
+
*/
|
| 546 |
+
timeout?: number | undefined;
|
| 547 |
+
}
|
| 548 |
+
interface CommonSpawnOptions extends CommonOptions, MessagingOptions, Abortable {
|
| 549 |
+
argv0?: string | undefined;
|
| 550 |
+
/**
|
| 551 |
+
* Can be set to 'pipe', 'inherit', 'overlapped', or 'ignore', or an array of these strings.
|
| 552 |
+
* If passed as an array, the first element is used for `stdin`, the second for
|
| 553 |
+
* `stdout`, and the third for `stderr`. A fourth element can be used to
|
| 554 |
+
* specify the `stdio` behavior beyond the standard streams. See
|
| 555 |
+
* {@link ChildProcess.stdio} for more information.
|
| 556 |
+
*
|
| 557 |
+
* @default 'pipe'
|
| 558 |
+
*/
|
| 559 |
+
stdio?: StdioOptions | undefined;
|
| 560 |
+
shell?: boolean | string | undefined;
|
| 561 |
+
windowsVerbatimArguments?: boolean | undefined;
|
| 562 |
+
}
|
| 563 |
+
interface SpawnOptions extends CommonSpawnOptions {
|
| 564 |
+
detached?: boolean | undefined;
|
| 565 |
+
}
|
| 566 |
+
interface SpawnOptionsWithoutStdio extends SpawnOptions {
|
| 567 |
+
stdio?: StdioPipeNamed | StdioPipe[] | undefined;
|
| 568 |
+
}
|
| 569 |
+
type StdioNull = "inherit" | "ignore" | Stream;
|
| 570 |
+
type StdioPipeNamed = "pipe" | "overlapped";
|
| 571 |
+
type StdioPipe = undefined | null | StdioPipeNamed;
|
| 572 |
+
interface SpawnOptionsWithStdioTuple<
|
| 573 |
+
Stdin extends StdioNull | StdioPipe,
|
| 574 |
+
Stdout extends StdioNull | StdioPipe,
|
| 575 |
+
Stderr extends StdioNull | StdioPipe,
|
| 576 |
+
> extends SpawnOptions {
|
| 577 |
+
stdio: [Stdin, Stdout, Stderr];
|
| 578 |
+
}
|
| 579 |
+
/**
|
| 580 |
+
* The `child_process.spawn()` method spawns a new process using the given `command`, with command-line arguments in `args`. If omitted, `args` defaults
|
| 581 |
+
* to an empty array.
|
| 582 |
+
*
|
| 583 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
| 584 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
| 585 |
+
* **arbitrary command execution.**
|
| 586 |
+
*
|
| 587 |
+
* A third argument may be used to specify additional options, with these defaults:
|
| 588 |
+
*
|
| 589 |
+
* ```js
|
| 590 |
+
* const defaults = {
|
| 591 |
+
* cwd: undefined,
|
| 592 |
+
* env: process.env,
|
| 593 |
+
* };
|
| 594 |
+
* ```
|
| 595 |
+
*
|
| 596 |
+
* Use `cwd` to specify the working directory from which the process is spawned.
|
| 597 |
+
* If not given, the default is to inherit the current working directory. If given,
|
| 598 |
+
* but the path does not exist, the child process emits an `ENOENT` error
|
| 599 |
+
* and exits immediately. `ENOENT` is also emitted when the command
|
| 600 |
+
* does not exist.
|
| 601 |
+
*
|
| 602 |
+
* Use `env` to specify environment variables that will be visible to the new
|
| 603 |
+
* process, the default is `process.env`.
|
| 604 |
+
*
|
| 605 |
+
* `undefined` values in `env` will be ignored.
|
| 606 |
+
*
|
| 607 |
+
* Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the
|
| 608 |
+
* exit code:
|
| 609 |
+
*
|
| 610 |
+
* ```js
|
| 611 |
+
* import { spawn } from 'node:child_process';
|
| 612 |
+
* import { once } from 'node:events';
|
| 613 |
+
* const ls = spawn('ls', ['-lh', '/usr']);
|
| 614 |
+
*
|
| 615 |
+
* ls.stdout.on('data', (data) => {
|
| 616 |
+
* console.log(`stdout: ${data}`);
|
| 617 |
+
* });
|
| 618 |
+
*
|
| 619 |
+
* ls.stderr.on('data', (data) => {
|
| 620 |
+
* console.error(`stderr: ${data}`);
|
| 621 |
+
* });
|
| 622 |
+
*
|
| 623 |
+
* const [code] = await once(ls, 'close');
|
| 624 |
+
* console.log(`child process exited with code ${code}`);
|
| 625 |
+
* ```
|
| 626 |
+
*
|
| 627 |
+
* Example: A very elaborate way to run `ps ax | grep ssh`
|
| 628 |
+
*
|
| 629 |
+
* ```js
|
| 630 |
+
* import { spawn } from 'node:child_process';
|
| 631 |
+
* const ps = spawn('ps', ['ax']);
|
| 632 |
+
* const grep = spawn('grep', ['ssh']);
|
| 633 |
+
*
|
| 634 |
+
* ps.stdout.on('data', (data) => {
|
| 635 |
+
* grep.stdin.write(data);
|
| 636 |
+
* });
|
| 637 |
+
*
|
| 638 |
+
* ps.stderr.on('data', (data) => {
|
| 639 |
+
* console.error(`ps stderr: ${data}`);
|
| 640 |
+
* });
|
| 641 |
+
*
|
| 642 |
+
* ps.on('close', (code) => {
|
| 643 |
+
* if (code !== 0) {
|
| 644 |
+
* console.log(`ps process exited with code ${code}`);
|
| 645 |
+
* }
|
| 646 |
+
* grep.stdin.end();
|
| 647 |
+
* });
|
| 648 |
+
*
|
| 649 |
+
* grep.stdout.on('data', (data) => {
|
| 650 |
+
* console.log(data.toString());
|
| 651 |
+
* });
|
| 652 |
+
*
|
| 653 |
+
* grep.stderr.on('data', (data) => {
|
| 654 |
+
* console.error(`grep stderr: ${data}`);
|
| 655 |
+
* });
|
| 656 |
+
*
|
| 657 |
+
* grep.on('close', (code) => {
|
| 658 |
+
* if (code !== 0) {
|
| 659 |
+
* console.log(`grep process exited with code ${code}`);
|
| 660 |
+
* }
|
| 661 |
+
* });
|
| 662 |
+
* ```
|
| 663 |
+
*
|
| 664 |
+
* Example of checking for failed `spawn`:
|
| 665 |
+
*
|
| 666 |
+
* ```js
|
| 667 |
+
* import { spawn } from 'node:child_process';
|
| 668 |
+
* const subprocess = spawn('bad_command');
|
| 669 |
+
*
|
| 670 |
+
* subprocess.on('error', (err) => {
|
| 671 |
+
* console.error('Failed to start subprocess.');
|
| 672 |
+
* });
|
| 673 |
+
* ```
|
| 674 |
+
*
|
| 675 |
+
* Certain platforms (macOS, Linux) will use the value of `argv[0]` for the process
|
| 676 |
+
* title while others (Windows, SunOS) will use `command`.
|
| 677 |
+
*
|
| 678 |
+
* 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
|
| 679 |
+
* it with the `process.argv0` property instead.
|
| 680 |
+
*
|
| 681 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except
|
| 682 |
+
* the error passed to the callback will be an `AbortError`:
|
| 683 |
+
*
|
| 684 |
+
* ```js
|
| 685 |
+
* import { spawn } from 'node:child_process';
|
| 686 |
+
* const controller = new AbortController();
|
| 687 |
+
* const { signal } = controller;
|
| 688 |
+
* const grep = spawn('grep', ['ssh'], { signal });
|
| 689 |
+
* grep.on('error', (err) => {
|
| 690 |
+
* // This will be called with err being an AbortError if the controller aborts
|
| 691 |
+
* });
|
| 692 |
+
* controller.abort(); // Stops the child process
|
| 693 |
+
* ```
|
| 694 |
+
* @since v0.1.90
|
| 695 |
+
* @param command The command to run.
|
| 696 |
+
* @param args List of string arguments.
|
| 697 |
+
*/
|
| 698 |
+
function spawn(command: string, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
| 699 |
+
function spawn(
|
| 700 |
+
command: string,
|
| 701 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
| 702 |
+
): ChildProcessByStdio<Writable, Readable, Readable>;
|
| 703 |
+
function spawn(
|
| 704 |
+
command: string,
|
| 705 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
| 706 |
+
): ChildProcessByStdio<Writable, Readable, null>;
|
| 707 |
+
function spawn(
|
| 708 |
+
command: string,
|
| 709 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
| 710 |
+
): ChildProcessByStdio<Writable, null, Readable>;
|
| 711 |
+
function spawn(
|
| 712 |
+
command: string,
|
| 713 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
| 714 |
+
): ChildProcessByStdio<null, Readable, Readable>;
|
| 715 |
+
function spawn(
|
| 716 |
+
command: string,
|
| 717 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
| 718 |
+
): ChildProcessByStdio<Writable, null, null>;
|
| 719 |
+
function spawn(
|
| 720 |
+
command: string,
|
| 721 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
| 722 |
+
): ChildProcessByStdio<null, Readable, null>;
|
| 723 |
+
function spawn(
|
| 724 |
+
command: string,
|
| 725 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
| 726 |
+
): ChildProcessByStdio<null, null, Readable>;
|
| 727 |
+
function spawn(
|
| 728 |
+
command: string,
|
| 729 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
| 730 |
+
): ChildProcessByStdio<null, null, null>;
|
| 731 |
+
function spawn(command: string, options: SpawnOptions): ChildProcess;
|
| 732 |
+
// overloads of spawn with 'args'
|
| 733 |
+
function spawn(
|
| 734 |
+
command: string,
|
| 735 |
+
args?: readonly string[],
|
| 736 |
+
options?: SpawnOptionsWithoutStdio,
|
| 737 |
+
): ChildProcessWithoutNullStreams;
|
| 738 |
+
function spawn(
|
| 739 |
+
command: string,
|
| 740 |
+
args: readonly string[],
|
| 741 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
| 742 |
+
): ChildProcessByStdio<Writable, Readable, Readable>;
|
| 743 |
+
function spawn(
|
| 744 |
+
command: string,
|
| 745 |
+
args: readonly string[],
|
| 746 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
| 747 |
+
): ChildProcessByStdio<Writable, Readable, null>;
|
| 748 |
+
function spawn(
|
| 749 |
+
command: string,
|
| 750 |
+
args: readonly string[],
|
| 751 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
| 752 |
+
): ChildProcessByStdio<Writable, null, Readable>;
|
| 753 |
+
function spawn(
|
| 754 |
+
command: string,
|
| 755 |
+
args: readonly string[],
|
| 756 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
| 757 |
+
): ChildProcessByStdio<null, Readable, Readable>;
|
| 758 |
+
function spawn(
|
| 759 |
+
command: string,
|
| 760 |
+
args: readonly string[],
|
| 761 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
| 762 |
+
): ChildProcessByStdio<Writable, null, null>;
|
| 763 |
+
function spawn(
|
| 764 |
+
command: string,
|
| 765 |
+
args: readonly string[],
|
| 766 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
| 767 |
+
): ChildProcessByStdio<null, Readable, null>;
|
| 768 |
+
function spawn(
|
| 769 |
+
command: string,
|
| 770 |
+
args: readonly string[],
|
| 771 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
| 772 |
+
): ChildProcessByStdio<null, null, Readable>;
|
| 773 |
+
function spawn(
|
| 774 |
+
command: string,
|
| 775 |
+
args: readonly string[],
|
| 776 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
| 777 |
+
): ChildProcessByStdio<null, null, null>;
|
| 778 |
+
function spawn(command: string, args: readonly string[], options: SpawnOptions): ChildProcess;
|
| 779 |
+
interface ExecOptions extends CommonOptions {
|
| 780 |
+
shell?: string | undefined;
|
| 781 |
+
signal?: AbortSignal | undefined;
|
| 782 |
+
maxBuffer?: number | undefined;
|
| 783 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
| 784 |
+
encoding?: string | null | undefined;
|
| 785 |
+
}
|
| 786 |
+
interface ExecOptionsWithStringEncoding extends ExecOptions {
|
| 787 |
+
encoding?: BufferEncoding | undefined;
|
| 788 |
+
}
|
| 789 |
+
interface ExecOptionsWithBufferEncoding extends ExecOptions {
|
| 790 |
+
encoding: "buffer" | null; // specify `null`.
|
| 791 |
+
}
|
| 792 |
+
// TODO: Just Plain Wrong™ (see also nodejs/node#57392)
|
| 793 |
+
interface ExecException extends Error {
|
| 794 |
+
cmd?: string;
|
| 795 |
+
killed?: boolean;
|
| 796 |
+
code?: number;
|
| 797 |
+
signal?: NodeJS.Signals;
|
| 798 |
+
stdout?: string;
|
| 799 |
+
stderr?: string;
|
| 800 |
+
}
|
| 801 |
+
/**
|
| 802 |
+
* Spawns a shell then executes the `command` within that shell, buffering any
|
| 803 |
+
* generated output. The `command` string passed to the exec function is processed
|
| 804 |
+
* directly by the shell and special characters (vary based on [shell](https://en.wikipedia.org/wiki/List_of_command-line_interpreters))
|
| 805 |
+
* need to be dealt with accordingly:
|
| 806 |
+
*
|
| 807 |
+
* ```js
|
| 808 |
+
* import { exec } from 'node:child_process';
|
| 809 |
+
*
|
| 810 |
+
* exec('"/path/to/test file/test.sh" arg1 arg2');
|
| 811 |
+
* // Double quotes are used so that the space in the path is not interpreted as
|
| 812 |
+
* // a delimiter of multiple arguments.
|
| 813 |
+
*
|
| 814 |
+
* exec('echo "The \\$HOME variable is $HOME"');
|
| 815 |
+
* // The $HOME variable is escaped in the first instance, but not in the second.
|
| 816 |
+
* ```
|
| 817 |
+
*
|
| 818 |
+
* **Never pass unsanitized user input to this function. Any input containing shell**
|
| 819 |
+
* **metacharacters may be used to trigger arbitrary command execution.**
|
| 820 |
+
*
|
| 821 |
+
* 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
|
| 822 |
+
* `error.code` property will be
|
| 823 |
+
* 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
|
| 824 |
+
* process.
|
| 825 |
+
*
|
| 826 |
+
* The `stdout` and `stderr` arguments passed to the callback will contain the
|
| 827 |
+
* stdout and stderr output of the child process. By default, Node.js will decode
|
| 828 |
+
* the output as UTF-8 and pass strings to the callback. The `encoding` option
|
| 829 |
+
* can be used to specify the character encoding used to decode the stdout and
|
| 830 |
+
* stderr output. If `encoding` is `'buffer'`, or an unrecognized character
|
| 831 |
+
* encoding, `Buffer` objects will be passed to the callback instead.
|
| 832 |
+
*
|
| 833 |
+
* ```js
|
| 834 |
+
* import { exec } from 'node:child_process';
|
| 835 |
+
* exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {
|
| 836 |
+
* if (error) {
|
| 837 |
+
* console.error(`exec error: ${error}`);
|
| 838 |
+
* return;
|
| 839 |
+
* }
|
| 840 |
+
* console.log(`stdout: ${stdout}`);
|
| 841 |
+
* console.error(`stderr: ${stderr}`);
|
| 842 |
+
* });
|
| 843 |
+
* ```
|
| 844 |
+
*
|
| 845 |
+
* If `timeout` is greater than `0`, the parent will send the signal
|
| 846 |
+
* identified by the `killSignal` property (the default is `'SIGTERM'`) if the
|
| 847 |
+
* child runs longer than `timeout` milliseconds.
|
| 848 |
+
*
|
| 849 |
+
* Unlike the [`exec(3)`](http://man7.org/linux/man-pages/man3/exec.3.html) POSIX system call, `child_process.exec()` does not replace
|
| 850 |
+
* the existing process and uses a shell to execute the command.
|
| 851 |
+
*
|
| 852 |
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
| 853 |
+
* a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned `ChildProcess` instance is attached to the `Promise` as a `child` property. In
|
| 854 |
+
* case of an error (including any error resulting in an exit code other than 0), a
|
| 855 |
+
* rejected promise is returned, with the same `error` object given in the
|
| 856 |
+
* callback, but with two additional properties `stdout` and `stderr`.
|
| 857 |
+
*
|
| 858 |
+
* ```js
|
| 859 |
+
* import util from 'node:util';
|
| 860 |
+
* import child_process from 'node:child_process';
|
| 861 |
+
* const exec = util.promisify(child_process.exec);
|
| 862 |
+
*
|
| 863 |
+
* async function lsExample() {
|
| 864 |
+
* const { stdout, stderr } = await exec('ls');
|
| 865 |
+
* console.log('stdout:', stdout);
|
| 866 |
+
* console.error('stderr:', stderr);
|
| 867 |
+
* }
|
| 868 |
+
* lsExample();
|
| 869 |
+
* ```
|
| 870 |
+
*
|
| 871 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except
|
| 872 |
+
* the error passed to the callback will be an `AbortError`:
|
| 873 |
+
*
|
| 874 |
+
* ```js
|
| 875 |
+
* import { exec } from 'node:child_process';
|
| 876 |
+
* const controller = new AbortController();
|
| 877 |
+
* const { signal } = controller;
|
| 878 |
+
* const child = exec('grep ssh', { signal }, (error) => {
|
| 879 |
+
* console.error(error); // an AbortError
|
| 880 |
+
* });
|
| 881 |
+
* controller.abort();
|
| 882 |
+
* ```
|
| 883 |
+
* @since v0.1.90
|
| 884 |
+
* @param command The command to run, with space-separated arguments.
|
| 885 |
+
* @param callback called with the output when process terminates.
|
| 886 |
+
*/
|
| 887 |
+
function exec(
|
| 888 |
+
command: string,
|
| 889 |
+
callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
|
| 890 |
+
): ChildProcess;
|
| 891 |
+
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
| 892 |
+
function exec(
|
| 893 |
+
command: string,
|
| 894 |
+
options: ExecOptionsWithBufferEncoding,
|
| 895 |
+
callback?: (error: ExecException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void,
|
| 896 |
+
): ChildProcess;
|
| 897 |
+
// `options` with well-known or absent `encoding` means stdout/stderr are definitely `string`.
|
| 898 |
+
function exec(
|
| 899 |
+
command: string,
|
| 900 |
+
options: ExecOptionsWithStringEncoding,
|
| 901 |
+
callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
|
| 902 |
+
): ChildProcess;
|
| 903 |
+
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
| 904 |
+
function exec(
|
| 905 |
+
command: string,
|
| 906 |
+
options: ExecOptions | undefined | null,
|
| 907 |
+
callback?: (
|
| 908 |
+
error: ExecException | null,
|
| 909 |
+
stdout: string | NonSharedBuffer,
|
| 910 |
+
stderr: string | NonSharedBuffer,
|
| 911 |
+
) => void,
|
| 912 |
+
): ChildProcess;
|
| 913 |
+
interface PromiseWithChild<T> extends Promise<T> {
|
| 914 |
+
child: ChildProcess;
|
| 915 |
+
}
|
| 916 |
+
namespace exec {
|
| 917 |
+
function __promisify__(command: string): PromiseWithChild<{
|
| 918 |
+
stdout: string;
|
| 919 |
+
stderr: string;
|
| 920 |
+
}>;
|
| 921 |
+
function __promisify__(
|
| 922 |
+
command: string,
|
| 923 |
+
options: ExecOptionsWithBufferEncoding,
|
| 924 |
+
): PromiseWithChild<{
|
| 925 |
+
stdout: NonSharedBuffer;
|
| 926 |
+
stderr: NonSharedBuffer;
|
| 927 |
+
}>;
|
| 928 |
+
function __promisify__(
|
| 929 |
+
command: string,
|
| 930 |
+
options: ExecOptionsWithStringEncoding,
|
| 931 |
+
): PromiseWithChild<{
|
| 932 |
+
stdout: string;
|
| 933 |
+
stderr: string;
|
| 934 |
+
}>;
|
| 935 |
+
function __promisify__(
|
| 936 |
+
command: string,
|
| 937 |
+
options: ExecOptions | undefined | null,
|
| 938 |
+
): PromiseWithChild<{
|
| 939 |
+
stdout: string | NonSharedBuffer;
|
| 940 |
+
stderr: string | NonSharedBuffer;
|
| 941 |
+
}>;
|
| 942 |
+
}
|
| 943 |
+
interface ExecFileOptions extends CommonOptions, Abortable {
|
| 944 |
+
maxBuffer?: number | undefined;
|
| 945 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
| 946 |
+
windowsVerbatimArguments?: boolean | undefined;
|
| 947 |
+
shell?: boolean | string | undefined;
|
| 948 |
+
signal?: AbortSignal | undefined;
|
| 949 |
+
encoding?: string | null | undefined;
|
| 950 |
+
}
|
| 951 |
+
interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
|
| 952 |
+
encoding?: BufferEncoding | undefined;
|
| 953 |
+
}
|
| 954 |
+
interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions {
|
| 955 |
+
encoding: "buffer" | null;
|
| 956 |
+
}
|
| 957 |
+
/** @deprecated Use `ExecFileOptions` instead. */
|
| 958 |
+
interface ExecFileOptionsWithOtherEncoding extends ExecFileOptions {}
|
| 959 |
+
// TODO: execFile exceptions can take many forms... this accurately describes none of them
|
| 960 |
+
type ExecFileException =
|
| 961 |
+
& Omit<ExecException, "code">
|
| 962 |
+
& Omit<NodeJS.ErrnoException, "code">
|
| 963 |
+
& { code?: string | number | null };
|
| 964 |
+
/**
|
| 965 |
+
* The `child_process.execFile()` function is similar to {@link exec} except that it does not spawn a shell by default. Rather, the specified
|
| 966 |
+
* executable `file` is spawned directly as a new process making it slightly more
|
| 967 |
+
* efficient than {@link exec}.
|
| 968 |
+
*
|
| 969 |
+
* The same options as {@link exec} are supported. Since a shell is
|
| 970 |
+
* not spawned, behaviors such as I/O redirection and file globbing are not
|
| 971 |
+
* supported.
|
| 972 |
+
*
|
| 973 |
+
* ```js
|
| 974 |
+
* import { execFile } from 'node:child_process';
|
| 975 |
+
* const child = execFile('node', ['--version'], (error, stdout, stderr) => {
|
| 976 |
+
* if (error) {
|
| 977 |
+
* throw error;
|
| 978 |
+
* }
|
| 979 |
+
* console.log(stdout);
|
| 980 |
+
* });
|
| 981 |
+
* ```
|
| 982 |
+
*
|
| 983 |
+
* The `stdout` and `stderr` arguments passed to the callback will contain the
|
| 984 |
+
* stdout and stderr output of the child process. By default, Node.js will decode
|
| 985 |
+
* the output as UTF-8 and pass strings to the callback. The `encoding` option
|
| 986 |
+
* can be used to specify the character encoding used to decode the stdout and
|
| 987 |
+
* stderr output. If `encoding` is `'buffer'`, or an unrecognized character
|
| 988 |
+
* encoding, `Buffer` objects will be passed to the callback instead.
|
| 989 |
+
*
|
| 990 |
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
| 991 |
+
* a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned `ChildProcess` instance is attached to the `Promise` as a `child` property. In
|
| 992 |
+
* case of an error (including any error resulting in an exit code other than 0), a
|
| 993 |
+
* rejected promise is returned, with the same `error` object given in the
|
| 994 |
+
* callback, but with two additional properties `stdout` and `stderr`.
|
| 995 |
+
*
|
| 996 |
+
* ```js
|
| 997 |
+
* import util from 'node:util';
|
| 998 |
+
* import child_process from 'node:child_process';
|
| 999 |
+
* const execFile = util.promisify(child_process.execFile);
|
| 1000 |
+
* async function getVersion() {
|
| 1001 |
+
* const { stdout } = await execFile('node', ['--version']);
|
| 1002 |
+
* console.log(stdout);
|
| 1003 |
+
* }
|
| 1004 |
+
* getVersion();
|
| 1005 |
+
* ```
|
| 1006 |
+
*
|
| 1007 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
| 1008 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
| 1009 |
+
* **arbitrary command execution.**
|
| 1010 |
+
*
|
| 1011 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except
|
| 1012 |
+
* the error passed to the callback will be an `AbortError`:
|
| 1013 |
+
*
|
| 1014 |
+
* ```js
|
| 1015 |
+
* import { execFile } from 'node:child_process';
|
| 1016 |
+
* const controller = new AbortController();
|
| 1017 |
+
* const { signal } = controller;
|
| 1018 |
+
* const child = execFile('node', ['--version'], { signal }, (error) => {
|
| 1019 |
+
* console.error(error); // an AbortError
|
| 1020 |
+
* });
|
| 1021 |
+
* controller.abort();
|
| 1022 |
+
* ```
|
| 1023 |
+
* @since v0.1.91
|
| 1024 |
+
* @param file The name or path of the executable file to run.
|
| 1025 |
+
* @param args List of string arguments.
|
| 1026 |
+
* @param callback Called with the output when process terminates.
|
| 1027 |
+
*/
|
| 1028 |
+
// no `options` definitely means stdout/stderr are `string`.
|
| 1029 |
+
function execFile(
|
| 1030 |
+
file: string,
|
| 1031 |
+
callback?: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
| 1032 |
+
): ChildProcess;
|
| 1033 |
+
function execFile(
|
| 1034 |
+
file: string,
|
| 1035 |
+
args: readonly string[] | undefined | null,
|
| 1036 |
+
callback?: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
| 1037 |
+
): ChildProcess;
|
| 1038 |
+
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
| 1039 |
+
function execFile(
|
| 1040 |
+
file: string,
|
| 1041 |
+
options: ExecFileOptionsWithBufferEncoding,
|
| 1042 |
+
callback?: (error: ExecFileException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void,
|
| 1043 |
+
): ChildProcess;
|
| 1044 |
+
function execFile(
|
| 1045 |
+
file: string,
|
| 1046 |
+
args: readonly string[] | undefined | null,
|
| 1047 |
+
options: ExecFileOptionsWithBufferEncoding,
|
| 1048 |
+
callback?: (error: ExecFileException | null, stdout: NonSharedBuffer, stderr: NonSharedBuffer) => void,
|
| 1049 |
+
): ChildProcess;
|
| 1050 |
+
// `options` with well-known or absent `encoding` means stdout/stderr are definitely `string`.
|
| 1051 |
+
function execFile(
|
| 1052 |
+
file: string,
|
| 1053 |
+
options: ExecFileOptionsWithStringEncoding,
|
| 1054 |
+
callback?: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
| 1055 |
+
): ChildProcess;
|
| 1056 |
+
function execFile(
|
| 1057 |
+
file: string,
|
| 1058 |
+
args: readonly string[] | undefined | null,
|
| 1059 |
+
options: ExecFileOptionsWithStringEncoding,
|
| 1060 |
+
callback?: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
| 1061 |
+
): ChildProcess;
|
| 1062 |
+
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
| 1063 |
+
function execFile(
|
| 1064 |
+
file: string,
|
| 1065 |
+
options: ExecFileOptions | undefined | null,
|
| 1066 |
+
callback:
|
| 1067 |
+
| ((
|
| 1068 |
+
error: ExecFileException | null,
|
| 1069 |
+
stdout: string | NonSharedBuffer,
|
| 1070 |
+
stderr: string | NonSharedBuffer,
|
| 1071 |
+
) => void)
|
| 1072 |
+
| undefined
|
| 1073 |
+
| null,
|
| 1074 |
+
): ChildProcess;
|
| 1075 |
+
function execFile(
|
| 1076 |
+
file: string,
|
| 1077 |
+
args: readonly string[] | undefined | null,
|
| 1078 |
+
options: ExecFileOptions | undefined | null,
|
| 1079 |
+
callback:
|
| 1080 |
+
| ((
|
| 1081 |
+
error: ExecFileException | null,
|
| 1082 |
+
stdout: string | NonSharedBuffer,
|
| 1083 |
+
stderr: string | NonSharedBuffer,
|
| 1084 |
+
) => void)
|
| 1085 |
+
| undefined
|
| 1086 |
+
| null,
|
| 1087 |
+
): ChildProcess;
|
| 1088 |
+
namespace execFile {
|
| 1089 |
+
function __promisify__(file: string): PromiseWithChild<{
|
| 1090 |
+
stdout: string;
|
| 1091 |
+
stderr: string;
|
| 1092 |
+
}>;
|
| 1093 |
+
function __promisify__(
|
| 1094 |
+
file: string,
|
| 1095 |
+
args: readonly string[] | undefined | null,
|
| 1096 |
+
): PromiseWithChild<{
|
| 1097 |
+
stdout: string;
|
| 1098 |
+
stderr: string;
|
| 1099 |
+
}>;
|
| 1100 |
+
function __promisify__(
|
| 1101 |
+
file: string,
|
| 1102 |
+
options: ExecFileOptionsWithBufferEncoding,
|
| 1103 |
+
): PromiseWithChild<{
|
| 1104 |
+
stdout: NonSharedBuffer;
|
| 1105 |
+
stderr: NonSharedBuffer;
|
| 1106 |
+
}>;
|
| 1107 |
+
function __promisify__(
|
| 1108 |
+
file: string,
|
| 1109 |
+
args: readonly string[] | undefined | null,
|
| 1110 |
+
options: ExecFileOptionsWithBufferEncoding,
|
| 1111 |
+
): PromiseWithChild<{
|
| 1112 |
+
stdout: NonSharedBuffer;
|
| 1113 |
+
stderr: NonSharedBuffer;
|
| 1114 |
+
}>;
|
| 1115 |
+
function __promisify__(
|
| 1116 |
+
file: string,
|
| 1117 |
+
options: ExecFileOptionsWithStringEncoding,
|
| 1118 |
+
): PromiseWithChild<{
|
| 1119 |
+
stdout: string;
|
| 1120 |
+
stderr: string;
|
| 1121 |
+
}>;
|
| 1122 |
+
function __promisify__(
|
| 1123 |
+
file: string,
|
| 1124 |
+
args: readonly string[] | undefined | null,
|
| 1125 |
+
options: ExecFileOptionsWithStringEncoding,
|
| 1126 |
+
): PromiseWithChild<{
|
| 1127 |
+
stdout: string;
|
| 1128 |
+
stderr: string;
|
| 1129 |
+
}>;
|
| 1130 |
+
function __promisify__(
|
| 1131 |
+
file: string,
|
| 1132 |
+
options: ExecFileOptions | undefined | null,
|
| 1133 |
+
): PromiseWithChild<{
|
| 1134 |
+
stdout: string | NonSharedBuffer;
|
| 1135 |
+
stderr: string | NonSharedBuffer;
|
| 1136 |
+
}>;
|
| 1137 |
+
function __promisify__(
|
| 1138 |
+
file: string,
|
| 1139 |
+
args: readonly string[] | undefined | null,
|
| 1140 |
+
options: ExecFileOptions | undefined | null,
|
| 1141 |
+
): PromiseWithChild<{
|
| 1142 |
+
stdout: string | NonSharedBuffer;
|
| 1143 |
+
stderr: string | NonSharedBuffer;
|
| 1144 |
+
}>;
|
| 1145 |
+
}
|
| 1146 |
+
interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable {
|
| 1147 |
+
execPath?: string | undefined;
|
| 1148 |
+
execArgv?: string[] | undefined;
|
| 1149 |
+
silent?: boolean | undefined;
|
| 1150 |
+
/**
|
| 1151 |
+
* Can be set to 'pipe', 'inherit', 'overlapped', or 'ignore', or an array of these strings.
|
| 1152 |
+
* If passed as an array, the first element is used for `stdin`, the second for
|
| 1153 |
+
* `stdout`, and the third for `stderr`. A fourth element can be used to
|
| 1154 |
+
* specify the `stdio` behavior beyond the standard streams. See
|
| 1155 |
+
* {@link ChildProcess.stdio} for more information.
|
| 1156 |
+
*
|
| 1157 |
+
* @default 'pipe'
|
| 1158 |
+
*/
|
| 1159 |
+
stdio?: StdioOptions | undefined;
|
| 1160 |
+
detached?: boolean | undefined;
|
| 1161 |
+
windowsVerbatimArguments?: boolean | undefined;
|
| 1162 |
+
}
|
| 1163 |
+
/**
|
| 1164 |
+
* The `child_process.fork()` method is a special case of {@link spawn} used specifically to spawn new Node.js processes.
|
| 1165 |
+
* Like {@link spawn}, a `ChildProcess` object is returned. The
|
| 1166 |
+
* returned `ChildProcess` will have an additional communication channel
|
| 1167 |
+
* built-in that allows messages to be passed back and forth between the parent and
|
| 1168 |
+
* child. See `subprocess.send()` for details.
|
| 1169 |
+
*
|
| 1170 |
+
* Keep in mind that spawned Node.js child processes are
|
| 1171 |
+
* independent of the parent with exception of the IPC communication channel
|
| 1172 |
+
* that is established between the two. Each process has its own memory, with
|
| 1173 |
+
* their own V8 instances. Because of the additional resource allocations
|
| 1174 |
+
* required, spawning a large number of child Node.js processes is not
|
| 1175 |
+
* recommended.
|
| 1176 |
+
*
|
| 1177 |
+
* 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
|
| 1178 |
+
* execution path to be used.
|
| 1179 |
+
*
|
| 1180 |
+
* Node.js processes launched with a custom `execPath` will communicate with the
|
| 1181 |
+
* parent process using the file descriptor (fd) identified using the
|
| 1182 |
+
* environment variable `NODE_CHANNEL_FD` on the child process.
|
| 1183 |
+
*
|
| 1184 |
+
* Unlike the [`fork(2)`](http://man7.org/linux/man-pages/man2/fork.2.html) POSIX system call, `child_process.fork()` does not clone the
|
| 1185 |
+
* current process.
|
| 1186 |
+
*
|
| 1187 |
+
* The `shell` option available in {@link spawn} is not supported by `child_process.fork()` and will be ignored if set.
|
| 1188 |
+
*
|
| 1189 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.kill()` on the child process except
|
| 1190 |
+
* the error passed to the callback will be an `AbortError`:
|
| 1191 |
+
*
|
| 1192 |
+
* ```js
|
| 1193 |
+
* if (process.argv[2] === 'child') {
|
| 1194 |
+
* setTimeout(() => {
|
| 1195 |
+
* console.log(`Hello from ${process.argv[2]}!`);
|
| 1196 |
+
* }, 1_000);
|
| 1197 |
+
* } else {
|
| 1198 |
+
* import { fork } from 'node:child_process';
|
| 1199 |
+
* const controller = new AbortController();
|
| 1200 |
+
* const { signal } = controller;
|
| 1201 |
+
* const child = fork(__filename, ['child'], { signal });
|
| 1202 |
+
* child.on('error', (err) => {
|
| 1203 |
+
* // This will be called with err being an AbortError if the controller aborts
|
| 1204 |
+
* });
|
| 1205 |
+
* controller.abort(); // Stops the child process
|
| 1206 |
+
* }
|
| 1207 |
+
* ```
|
| 1208 |
+
* @since v0.5.0
|
| 1209 |
+
* @param modulePath The module to run in the child.
|
| 1210 |
+
* @param args List of string arguments.
|
| 1211 |
+
*/
|
| 1212 |
+
function fork(modulePath: string | URL, options?: ForkOptions): ChildProcess;
|
| 1213 |
+
function fork(modulePath: string | URL, args?: readonly string[], options?: ForkOptions): ChildProcess;
|
| 1214 |
+
interface SpawnSyncOptions extends CommonSpawnOptions {
|
| 1215 |
+
input?: string | NodeJS.ArrayBufferView | undefined;
|
| 1216 |
+
maxBuffer?: number | undefined;
|
| 1217 |
+
encoding?: BufferEncoding | "buffer" | null | undefined;
|
| 1218 |
+
}
|
| 1219 |
+
interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions {
|
| 1220 |
+
encoding: BufferEncoding;
|
| 1221 |
+
}
|
| 1222 |
+
interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions {
|
| 1223 |
+
encoding?: "buffer" | null | undefined;
|
| 1224 |
+
}
|
| 1225 |
+
interface SpawnSyncReturns<T> {
|
| 1226 |
+
pid: number;
|
| 1227 |
+
output: Array<T | null>;
|
| 1228 |
+
stdout: T;
|
| 1229 |
+
stderr: T;
|
| 1230 |
+
status: number | null;
|
| 1231 |
+
signal: NodeJS.Signals | null;
|
| 1232 |
+
error?: Error;
|
| 1233 |
+
}
|
| 1234 |
+
/**
|
| 1235 |
+
* The `child_process.spawnSync()` method is generally identical to {@link spawn} with the exception that the function will not return
|
| 1236 |
+
* until the child process has fully closed. When a timeout has been encountered
|
| 1237 |
+
* and `killSignal` is sent, the method won't return until the process has
|
| 1238 |
+
* completely exited. If the process intercepts and handles the `SIGTERM` signal
|
| 1239 |
+
* and doesn't exit, the parent process will wait until the child process has
|
| 1240 |
+
* exited.
|
| 1241 |
+
*
|
| 1242 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
| 1243 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
| 1244 |
+
* **arbitrary command execution.**
|
| 1245 |
+
* @since v0.11.12
|
| 1246 |
+
* @param command The command to run.
|
| 1247 |
+
* @param args List of string arguments.
|
| 1248 |
+
*/
|
| 1249 |
+
function spawnSync(command: string): SpawnSyncReturns<NonSharedBuffer>;
|
| 1250 |
+
function spawnSync(command: string, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
|
| 1251 |
+
function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<NonSharedBuffer>;
|
| 1252 |
+
function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns<string | NonSharedBuffer>;
|
| 1253 |
+
function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns<NonSharedBuffer>;
|
| 1254 |
+
function spawnSync(
|
| 1255 |
+
command: string,
|
| 1256 |
+
args: readonly string[],
|
| 1257 |
+
options: SpawnSyncOptionsWithStringEncoding,
|
| 1258 |
+
): SpawnSyncReturns<string>;
|
| 1259 |
+
function spawnSync(
|
| 1260 |
+
command: string,
|
| 1261 |
+
args: readonly string[],
|
| 1262 |
+
options: SpawnSyncOptionsWithBufferEncoding,
|
| 1263 |
+
): SpawnSyncReturns<NonSharedBuffer>;
|
| 1264 |
+
function spawnSync(
|
| 1265 |
+
command: string,
|
| 1266 |
+
args?: readonly string[],
|
| 1267 |
+
options?: SpawnSyncOptions,
|
| 1268 |
+
): SpawnSyncReturns<string | NonSharedBuffer>;
|
| 1269 |
+
interface CommonExecOptions extends CommonOptions {
|
| 1270 |
+
input?: string | NodeJS.ArrayBufferView | undefined;
|
| 1271 |
+
/**
|
| 1272 |
+
* Can be set to 'pipe', 'inherit, or 'ignore', or an array of these strings.
|
| 1273 |
+
* If passed as an array, the first element is used for `stdin`, the second for
|
| 1274 |
+
* `stdout`, and the third for `stderr`. A fourth element can be used to
|
| 1275 |
+
* specify the `stdio` behavior beyond the standard streams. See
|
| 1276 |
+
* {@link ChildProcess.stdio} for more information.
|
| 1277 |
+
*
|
| 1278 |
+
* @default 'pipe'
|
| 1279 |
+
*/
|
| 1280 |
+
stdio?: StdioOptions | undefined;
|
| 1281 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
| 1282 |
+
maxBuffer?: number | undefined;
|
| 1283 |
+
encoding?: BufferEncoding | "buffer" | null | undefined;
|
| 1284 |
+
}
|
| 1285 |
+
interface ExecSyncOptions extends CommonExecOptions {
|
| 1286 |
+
shell?: string | undefined;
|
| 1287 |
+
}
|
| 1288 |
+
interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
|
| 1289 |
+
encoding: BufferEncoding;
|
| 1290 |
+
}
|
| 1291 |
+
interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
|
| 1292 |
+
encoding?: "buffer" | null | undefined;
|
| 1293 |
+
}
|
| 1294 |
+
/**
|
| 1295 |
+
* The `child_process.execSync()` method is generally identical to {@link exec} with the exception that the method will not return
|
| 1296 |
+
* until the child process has fully closed. When a timeout has been encountered
|
| 1297 |
+
* and `killSignal` is sent, the method won't return until the process has
|
| 1298 |
+
* 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
|
| 1299 |
+
* has exited.
|
| 1300 |
+
*
|
| 1301 |
+
* If the process times out or has a non-zero exit code, this method will throw.
|
| 1302 |
+
* The `Error` object will contain the entire result from {@link spawnSync}.
|
| 1303 |
+
*
|
| 1304 |
+
* **Never pass unsanitized user input to this function. Any input containing shell**
|
| 1305 |
+
* **metacharacters may be used to trigger arbitrary command execution.**
|
| 1306 |
+
* @since v0.11.12
|
| 1307 |
+
* @param command The command to run.
|
| 1308 |
+
* @return The stdout from the command.
|
| 1309 |
+
*/
|
| 1310 |
+
function execSync(command: string): NonSharedBuffer;
|
| 1311 |
+
function execSync(command: string, options: ExecSyncOptionsWithStringEncoding): string;
|
| 1312 |
+
function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): NonSharedBuffer;
|
| 1313 |
+
function execSync(command: string, options?: ExecSyncOptions): string | NonSharedBuffer;
|
| 1314 |
+
interface ExecFileSyncOptions extends CommonExecOptions {
|
| 1315 |
+
shell?: boolean | string | undefined;
|
| 1316 |
+
}
|
| 1317 |
+
interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
|
| 1318 |
+
encoding: BufferEncoding;
|
| 1319 |
+
}
|
| 1320 |
+
interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
|
| 1321 |
+
encoding?: "buffer" | null | undefined; // specify `null`.
|
| 1322 |
+
}
|
| 1323 |
+
/**
|
| 1324 |
+
* The `child_process.execFileSync()` method is generally identical to {@link execFile} with the exception that the method will not
|
| 1325 |
+
* return until the child process has fully closed. When a timeout has been
|
| 1326 |
+
* encountered and `killSignal` is sent, the method won't return until the process
|
| 1327 |
+
* has completely exited.
|
| 1328 |
+
*
|
| 1329 |
+
* If the child process intercepts and handles the `SIGTERM` signal and
|
| 1330 |
+
* does not exit, the parent process will still wait until the child process has
|
| 1331 |
+
* exited.
|
| 1332 |
+
*
|
| 1333 |
+
* 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}.
|
| 1334 |
+
*
|
| 1335 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
| 1336 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
| 1337 |
+
* **arbitrary command execution.**
|
| 1338 |
+
* @since v0.11.12
|
| 1339 |
+
* @param file The name or path of the executable file to run.
|
| 1340 |
+
* @param args List of string arguments.
|
| 1341 |
+
* @return The stdout from the command.
|
| 1342 |
+
*/
|
| 1343 |
+
function execFileSync(file: string): NonSharedBuffer;
|
| 1344 |
+
function execFileSync(file: string, options: ExecFileSyncOptionsWithStringEncoding): string;
|
| 1345 |
+
function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): NonSharedBuffer;
|
| 1346 |
+
function execFileSync(file: string, options?: ExecFileSyncOptions): string | NonSharedBuffer;
|
| 1347 |
+
function execFileSync(file: string, args: readonly string[]): NonSharedBuffer;
|
| 1348 |
+
function execFileSync(
|
| 1349 |
+
file: string,
|
| 1350 |
+
args: readonly string[],
|
| 1351 |
+
options: ExecFileSyncOptionsWithStringEncoding,
|
| 1352 |
+
): string;
|
| 1353 |
+
function execFileSync(
|
| 1354 |
+
file: string,
|
| 1355 |
+
args: readonly string[],
|
| 1356 |
+
options: ExecFileSyncOptionsWithBufferEncoding,
|
| 1357 |
+
): NonSharedBuffer;
|
| 1358 |
+
function execFileSync(
|
| 1359 |
+
file: string,
|
| 1360 |
+
args?: readonly string[],
|
| 1361 |
+
options?: ExecFileSyncOptions,
|
| 1362 |
+
): string | NonSharedBuffer;
|
| 1363 |
+
}
|
| 1364 |
+
declare module "child_process" {
|
| 1365 |
+
export * from "node:child_process";
|
| 1366 |
+
}
|
node_modules/@types/node/cluster.d.ts
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:cluster" {
|
| 2 |
+
import * as child_process from "node:child_process";
|
| 3 |
+
import { EventEmitter, InternalEventEmitter } from "node:events";
|
| 4 |
+
class Worker implements EventEmitter {
|
| 5 |
+
constructor(options?: cluster.WorkerOptions);
|
| 6 |
+
/**
|
| 7 |
+
* Each new worker is given its own unique id, this id is stored in the `id`.
|
| 8 |
+
*
|
| 9 |
+
* While a worker is alive, this is the key that indexes it in `cluster.workers`.
|
| 10 |
+
* @since v0.8.0
|
| 11 |
+
*/
|
| 12 |
+
id: number;
|
| 13 |
+
/**
|
| 14 |
+
* All workers are created using [`child_process.fork()`](https://nodejs.org/docs/latest-v25.x/api/child_process.html#child_processforkmodulepath-args-options), the returned object
|
| 15 |
+
* from this function is stored as `.process`. In a worker, the global `process` is stored.
|
| 16 |
+
*
|
| 17 |
+
* See: [Child Process module](https://nodejs.org/docs/latest-v25.x/api/child_process.html#child_processforkmodulepath-args-options).
|
| 18 |
+
*
|
| 19 |
+
* Workers will call `process.exit(0)` if the `'disconnect'` event occurs
|
| 20 |
+
* on `process` and `.exitedAfterDisconnect` is not `true`. This protects against
|
| 21 |
+
* accidental disconnection.
|
| 22 |
+
* @since v0.7.0
|
| 23 |
+
*/
|
| 24 |
+
process: child_process.ChildProcess;
|
| 25 |
+
/**
|
| 26 |
+
* Send a message to a worker or primary, optionally with a handle.
|
| 27 |
+
*
|
| 28 |
+
* In the primary, this sends a message to a specific worker. It is identical to [`ChildProcess.send()`](https://nodejs.org/docs/latest-v25.x/api/child_process.html#subprocesssendmessage-sendhandle-options-callback).
|
| 29 |
+
*
|
| 30 |
+
* In a worker, this sends a message to the primary. It is identical to `process.send()`.
|
| 31 |
+
*
|
| 32 |
+
* This example will echo back all messages from the primary:
|
| 33 |
+
*
|
| 34 |
+
* ```js
|
| 35 |
+
* if (cluster.isPrimary) {
|
| 36 |
+
* const worker = cluster.fork();
|
| 37 |
+
* worker.send('hi there');
|
| 38 |
+
*
|
| 39 |
+
* } else if (cluster.isWorker) {
|
| 40 |
+
* process.on('message', (msg) => {
|
| 41 |
+
* process.send(msg);
|
| 42 |
+
* });
|
| 43 |
+
* }
|
| 44 |
+
* ```
|
| 45 |
+
* @since v0.7.0
|
| 46 |
+
* @param options The `options` argument, if present, is an object used to parameterize the sending of certain types of handles.
|
| 47 |
+
*/
|
| 48 |
+
send(message: child_process.Serializable, callback?: (error: Error | null) => void): boolean;
|
| 49 |
+
send(
|
| 50 |
+
message: child_process.Serializable,
|
| 51 |
+
sendHandle: child_process.SendHandle,
|
| 52 |
+
callback?: (error: Error | null) => void,
|
| 53 |
+
): boolean;
|
| 54 |
+
send(
|
| 55 |
+
message: child_process.Serializable,
|
| 56 |
+
sendHandle: child_process.SendHandle,
|
| 57 |
+
options?: child_process.MessageOptions,
|
| 58 |
+
callback?: (error: Error | null) => void,
|
| 59 |
+
): boolean;
|
| 60 |
+
/**
|
| 61 |
+
* This function will kill the worker. In the primary worker, it does this by
|
| 62 |
+
* disconnecting the `worker.process`, and once disconnected, killing with `signal`. In the worker, it does it by killing the process with `signal`.
|
| 63 |
+
*
|
| 64 |
+
* The `kill()` function kills the worker process without waiting for a graceful
|
| 65 |
+
* disconnect, it has the same behavior as `worker.process.kill()`.
|
| 66 |
+
*
|
| 67 |
+
* This method is aliased as `worker.destroy()` for backwards compatibility.
|
| 68 |
+
*
|
| 69 |
+
* In a worker, `process.kill()` exists, but it is not this function;
|
| 70 |
+
* it is [`kill()`](https://nodejs.org/docs/latest-v25.x/api/process.html#processkillpid-signal).
|
| 71 |
+
* @since v0.9.12
|
| 72 |
+
* @param [signal='SIGTERM'] Name of the kill signal to send to the worker process.
|
| 73 |
+
*/
|
| 74 |
+
kill(signal?: string): void;
|
| 75 |
+
destroy(signal?: string): void;
|
| 76 |
+
/**
|
| 77 |
+
* In a worker, this function will close all servers, wait for the `'close'` event
|
| 78 |
+
* on those servers, and then disconnect the IPC channel.
|
| 79 |
+
*
|
| 80 |
+
* In the primary, an internal message is sent to the worker causing it to call `.disconnect()` on itself.
|
| 81 |
+
*
|
| 82 |
+
* Causes `.exitedAfterDisconnect` to be set.
|
| 83 |
+
*
|
| 84 |
+
* After a server is closed, it will no longer accept new connections,
|
| 85 |
+
* but connections may be accepted by any other listening worker. Existing
|
| 86 |
+
* connections will be allowed to close as usual. When no more connections exist,
|
| 87 |
+
* see `server.close()`, the IPC channel to the worker will close allowing it
|
| 88 |
+
* to die gracefully.
|
| 89 |
+
*
|
| 90 |
+
* The above applies _only_ to server connections, client connections are not
|
| 91 |
+
* automatically closed by workers, and disconnect does not wait for them to close
|
| 92 |
+
* before exiting.
|
| 93 |
+
*
|
| 94 |
+
* In a worker, `process.disconnect` exists, but it is not this function;
|
| 95 |
+
* it is `disconnect()`.
|
| 96 |
+
*
|
| 97 |
+
* Because long living server connections may block workers from disconnecting, it
|
| 98 |
+
* may be useful to send a message, so application specific actions may be taken to
|
| 99 |
+
* close them. It also may be useful to implement a timeout, killing a worker if
|
| 100 |
+
* the `'disconnect'` event has not been emitted after some time.
|
| 101 |
+
*
|
| 102 |
+
* ```js
|
| 103 |
+
* import net from 'node:net';
|
| 104 |
+
*
|
| 105 |
+
* if (cluster.isPrimary) {
|
| 106 |
+
* const worker = cluster.fork();
|
| 107 |
+
* let timeout;
|
| 108 |
+
*
|
| 109 |
+
* worker.on('listening', (address) => {
|
| 110 |
+
* worker.send('shutdown');
|
| 111 |
+
* worker.disconnect();
|
| 112 |
+
* timeout = setTimeout(() => {
|
| 113 |
+
* worker.kill();
|
| 114 |
+
* }, 2000);
|
| 115 |
+
* });
|
| 116 |
+
*
|
| 117 |
+
* worker.on('disconnect', () => {
|
| 118 |
+
* clearTimeout(timeout);
|
| 119 |
+
* });
|
| 120 |
+
*
|
| 121 |
+
* } else if (cluster.isWorker) {
|
| 122 |
+
* const server = net.createServer((socket) => {
|
| 123 |
+
* // Connections never end
|
| 124 |
+
* });
|
| 125 |
+
*
|
| 126 |
+
* server.listen(8000);
|
| 127 |
+
*
|
| 128 |
+
* process.on('message', (msg) => {
|
| 129 |
+
* if (msg === 'shutdown') {
|
| 130 |
+
* // Initiate graceful close of any connections to server
|
| 131 |
+
* }
|
| 132 |
+
* });
|
| 133 |
+
* }
|
| 134 |
+
* ```
|
| 135 |
+
* @since v0.7.7
|
| 136 |
+
* @return A reference to `worker`.
|
| 137 |
+
*/
|
| 138 |
+
disconnect(): this;
|
| 139 |
+
/**
|
| 140 |
+
* This function returns `true` if the worker is connected to its primary via its
|
| 141 |
+
* IPC channel, `false` otherwise. A worker is connected to its primary after it
|
| 142 |
+
* has been created. It is disconnected after the `'disconnect'` event is emitted.
|
| 143 |
+
* @since v0.11.14
|
| 144 |
+
*/
|
| 145 |
+
isConnected(): boolean;
|
| 146 |
+
/**
|
| 147 |
+
* This function returns `true` if the worker's process has terminated (either
|
| 148 |
+
* because of exiting or being signaled). Otherwise, it returns `false`.
|
| 149 |
+
*
|
| 150 |
+
* ```js
|
| 151 |
+
* import cluster from 'node:cluster';
|
| 152 |
+
* import http from 'node:http';
|
| 153 |
+
* import { availableParallelism } from 'node:os';
|
| 154 |
+
* import process from 'node:process';
|
| 155 |
+
*
|
| 156 |
+
* const numCPUs = availableParallelism();
|
| 157 |
+
*
|
| 158 |
+
* if (cluster.isPrimary) {
|
| 159 |
+
* console.log(`Primary ${process.pid} is running`);
|
| 160 |
+
*
|
| 161 |
+
* // Fork workers.
|
| 162 |
+
* for (let i = 0; i < numCPUs; i++) {
|
| 163 |
+
* cluster.fork();
|
| 164 |
+
* }
|
| 165 |
+
*
|
| 166 |
+
* cluster.on('fork', (worker) => {
|
| 167 |
+
* console.log('worker is dead:', worker.isDead());
|
| 168 |
+
* });
|
| 169 |
+
*
|
| 170 |
+
* cluster.on('exit', (worker, code, signal) => {
|
| 171 |
+
* console.log('worker is dead:', worker.isDead());
|
| 172 |
+
* });
|
| 173 |
+
* } else {
|
| 174 |
+
* // Workers can share any TCP connection. In this case, it is an HTTP server.
|
| 175 |
+
* http.createServer((req, res) => {
|
| 176 |
+
* res.writeHead(200);
|
| 177 |
+
* res.end(`Current process\n ${process.pid}`);
|
| 178 |
+
* process.kill(process.pid);
|
| 179 |
+
* }).listen(8000);
|
| 180 |
+
* }
|
| 181 |
+
* ```
|
| 182 |
+
* @since v0.11.14
|
| 183 |
+
*/
|
| 184 |
+
isDead(): boolean;
|
| 185 |
+
/**
|
| 186 |
+
* This property is `true` if the worker exited due to `.disconnect()`.
|
| 187 |
+
* If the worker exited any other way, it is `false`. If the
|
| 188 |
+
* worker has not exited, it is `undefined`.
|
| 189 |
+
*
|
| 190 |
+
* The boolean `worker.exitedAfterDisconnect` allows distinguishing between
|
| 191 |
+
* voluntary and accidental exit, the primary may choose not to respawn a worker
|
| 192 |
+
* based on this value.
|
| 193 |
+
*
|
| 194 |
+
* ```js
|
| 195 |
+
* cluster.on('exit', (worker, code, signal) => {
|
| 196 |
+
* if (worker.exitedAfterDisconnect === true) {
|
| 197 |
+
* console.log('Oh, it was just voluntary – no need to worry');
|
| 198 |
+
* }
|
| 199 |
+
* });
|
| 200 |
+
*
|
| 201 |
+
* // kill worker
|
| 202 |
+
* worker.kill();
|
| 203 |
+
* ```
|
| 204 |
+
* @since v6.0.0
|
| 205 |
+
*/
|
| 206 |
+
exitedAfterDisconnect: boolean;
|
| 207 |
+
}
|
| 208 |
+
interface Worker extends InternalEventEmitter<cluster.WorkerEventMap> {}
|
| 209 |
+
type _Worker = Worker;
|
| 210 |
+
namespace cluster {
|
| 211 |
+
interface Worker extends _Worker {}
|
| 212 |
+
interface WorkerOptions {
|
| 213 |
+
id?: number | undefined;
|
| 214 |
+
process?: child_process.ChildProcess | undefined;
|
| 215 |
+
state?: string | undefined;
|
| 216 |
+
}
|
| 217 |
+
interface WorkerEventMap {
|
| 218 |
+
"disconnect": [];
|
| 219 |
+
"error": [error: Error];
|
| 220 |
+
"exit": [code: number, signal: string];
|
| 221 |
+
"listening": [address: Address];
|
| 222 |
+
"message": [message: any, handle: child_process.SendHandle];
|
| 223 |
+
"online": [];
|
| 224 |
+
}
|
| 225 |
+
interface ClusterSettings {
|
| 226 |
+
/**
|
| 227 |
+
* List of string arguments passed to the Node.js executable.
|
| 228 |
+
* @default process.execArgv
|
| 229 |
+
*/
|
| 230 |
+
execArgv?: string[] | undefined;
|
| 231 |
+
/**
|
| 232 |
+
* File path to worker file.
|
| 233 |
+
* @default process.argv[1]
|
| 234 |
+
*/
|
| 235 |
+
exec?: string | undefined;
|
| 236 |
+
/**
|
| 237 |
+
* String arguments passed to worker.
|
| 238 |
+
* @default process.argv.slice(2)
|
| 239 |
+
*/
|
| 240 |
+
args?: readonly string[] | undefined;
|
| 241 |
+
/**
|
| 242 |
+
* Whether or not to send output to parent's stdio.
|
| 243 |
+
* @default false
|
| 244 |
+
*/
|
| 245 |
+
silent?: boolean | undefined;
|
| 246 |
+
/**
|
| 247 |
+
* Configures the stdio of forked processes. Because the cluster module relies on IPC to function, this configuration must
|
| 248 |
+
* contain an `'ipc'` entry. When this option is provided, it overrides `silent`. See [`child_prcess.spawn()`](https://nodejs.org/docs/latest-v25.x/api/child_process.html#child_processspawncommand-args-options)'s
|
| 249 |
+
* [`stdio`](https://nodejs.org/docs/latest-v25.x/api/child_process.html#optionsstdio).
|
| 250 |
+
*/
|
| 251 |
+
stdio?: any[] | undefined;
|
| 252 |
+
/**
|
| 253 |
+
* Sets the user identity of the process. (See [`setuid(2)`](https://man7.org/linux/man-pages/man2/setuid.2.html).)
|
| 254 |
+
*/
|
| 255 |
+
uid?: number | undefined;
|
| 256 |
+
/**
|
| 257 |
+
* Sets the group identity of the process. (See [`setgid(2)`](https://man7.org/linux/man-pages/man2/setgid.2.html).)
|
| 258 |
+
*/
|
| 259 |
+
gid?: number | undefined;
|
| 260 |
+
/**
|
| 261 |
+
* Sets inspector port of worker. This can be a number, or a function that takes no arguments and returns a number.
|
| 262 |
+
* By default each worker gets its own port, incremented from the primary's `process.debugPort`.
|
| 263 |
+
*/
|
| 264 |
+
inspectPort?: number | (() => number) | undefined;
|
| 265 |
+
/**
|
| 266 |
+
* Specify the kind of serialization used for sending messages between processes. Possible values are `'json'` and `'advanced'`.
|
| 267 |
+
* See [Advanced serialization for `child_process`](https://nodejs.org/docs/latest-v25.x/api/child_process.html#advanced-serialization) for more details.
|
| 268 |
+
* @default false
|
| 269 |
+
*/
|
| 270 |
+
serialization?: "json" | "advanced" | undefined;
|
| 271 |
+
/**
|
| 272 |
+
* Current working directory of the worker process.
|
| 273 |
+
* @default undefined (inherits from parent process)
|
| 274 |
+
*/
|
| 275 |
+
cwd?: string | undefined;
|
| 276 |
+
/**
|
| 277 |
+
* Hide the forked processes console window that would normally be created on Windows systems.
|
| 278 |
+
* @default false
|
| 279 |
+
*/
|
| 280 |
+
windowsHide?: boolean | undefined;
|
| 281 |
+
}
|
| 282 |
+
interface Address {
|
| 283 |
+
address: string;
|
| 284 |
+
port: number;
|
| 285 |
+
/**
|
| 286 |
+
* The `addressType` is one of:
|
| 287 |
+
*
|
| 288 |
+
* * `4` (TCPv4)
|
| 289 |
+
* * `6` (TCPv6)
|
| 290 |
+
* * `-1` (Unix domain socket)
|
| 291 |
+
* * `'udp4'` or `'udp6'` (UDPv4 or UDPv6)
|
| 292 |
+
*/
|
| 293 |
+
addressType: 4 | 6 | -1 | "udp4" | "udp6";
|
| 294 |
+
}
|
| 295 |
+
interface ClusterEventMap {
|
| 296 |
+
"disconnect": [worker: Worker];
|
| 297 |
+
"exit": [worker: Worker, code: number, signal: string];
|
| 298 |
+
"fork": [worker: Worker];
|
| 299 |
+
"listening": [worker: Worker, address: Address];
|
| 300 |
+
"message": [worker: Worker, message: any, handle: child_process.SendHandle];
|
| 301 |
+
"online": [worker: Worker];
|
| 302 |
+
"setup": [settings: ClusterSettings];
|
| 303 |
+
}
|
| 304 |
+
interface Cluster extends InternalEventEmitter<ClusterEventMap> {
|
| 305 |
+
/**
|
| 306 |
+
* A `Worker` object contains all public information and method about a worker.
|
| 307 |
+
* In the primary it can be obtained using `cluster.workers`. In a worker
|
| 308 |
+
* it can be obtained using `cluster.worker`.
|
| 309 |
+
* @since v0.7.0
|
| 310 |
+
*/
|
| 311 |
+
Worker: typeof Worker;
|
| 312 |
+
disconnect(callback?: () => void): void;
|
| 313 |
+
/**
|
| 314 |
+
* Spawn a new worker process.
|
| 315 |
+
*
|
| 316 |
+
* This can only be called from the primary process.
|
| 317 |
+
* @param env Key/value pairs to add to worker process environment.
|
| 318 |
+
* @since v0.6.0
|
| 319 |
+
*/
|
| 320 |
+
fork(env?: any): Worker;
|
| 321 |
+
/** @deprecated since v16.0.0 - use isPrimary. */
|
| 322 |
+
readonly isMaster: boolean;
|
| 323 |
+
/**
|
| 324 |
+
* True if the process is a primary. This is determined by the `process.env.NODE_UNIQUE_ID`. If `process.env.NODE_UNIQUE_ID`
|
| 325 |
+
* is undefined, then `isPrimary` is `true`.
|
| 326 |
+
* @since v16.0.0
|
| 327 |
+
*/
|
| 328 |
+
readonly isPrimary: boolean;
|
| 329 |
+
/**
|
| 330 |
+
* True if the process is not a primary (it is the negation of `cluster.isPrimary`).
|
| 331 |
+
* @since v0.6.0
|
| 332 |
+
*/
|
| 333 |
+
readonly isWorker: boolean;
|
| 334 |
+
/**
|
| 335 |
+
* The scheduling policy, either `cluster.SCHED_RR` for round-robin or `cluster.SCHED_NONE` to leave it to the operating system. This is a
|
| 336 |
+
* global setting and effectively frozen once either the first worker is spawned, or [`.setupPrimary()`](https://nodejs.org/docs/latest-v25.x/api/cluster.html#clustersetupprimarysettings)
|
| 337 |
+
* is called, whichever comes first.
|
| 338 |
+
*
|
| 339 |
+
* `SCHED_RR` is the default on all operating systems except Windows. Windows will change to `SCHED_RR` once libuv is able to effectively distribute
|
| 340 |
+
* IOCP handles without incurring a large performance hit.
|
| 341 |
+
*
|
| 342 |
+
* `cluster.schedulingPolicy` can also be set through the `NODE_CLUSTER_SCHED_POLICY` environment variable. Valid values are `'rr'` and `'none'`.
|
| 343 |
+
* @since v0.11.2
|
| 344 |
+
*/
|
| 345 |
+
schedulingPolicy: number;
|
| 346 |
+
/**
|
| 347 |
+
* After calling [`.setupPrimary()`](https://nodejs.org/docs/latest-v25.x/api/cluster.html#clustersetupprimarysettings)
|
| 348 |
+
* (or [`.fork()`](https://nodejs.org/docs/latest-v25.x/api/cluster.html#clusterforkenv)) this settings object will contain
|
| 349 |
+
* the settings, including the default values.
|
| 350 |
+
*
|
| 351 |
+
* This object is not intended to be changed or set manually.
|
| 352 |
+
* @since v0.7.1
|
| 353 |
+
*/
|
| 354 |
+
readonly settings: ClusterSettings;
|
| 355 |
+
/** @deprecated since v16.0.0 - use [`.setupPrimary()`](https://nodejs.org/docs/latest-v25.x/api/cluster.html#clustersetupprimarysettings) instead. */
|
| 356 |
+
setupMaster(settings?: ClusterSettings): void;
|
| 357 |
+
/**
|
| 358 |
+
* `setupPrimary` is used to change the default 'fork' behavior. Once called, the settings will be present in `cluster.settings`.
|
| 359 |
+
*
|
| 360 |
+
* Any settings changes only affect future calls to [`.fork()`](https://nodejs.org/docs/latest-v25.x/api/cluster.html#clusterforkenv)
|
| 361 |
+
* and have no effect on workers that are already running.
|
| 362 |
+
*
|
| 363 |
+
* The only attribute of a worker that cannot be set via `.setupPrimary()` is the `env` passed to
|
| 364 |
+
* [`.fork()`](https://nodejs.org/docs/latest-v25.x/api/cluster.html#clusterforkenv).
|
| 365 |
+
*
|
| 366 |
+
* The defaults above apply to the first call only; the defaults for later calls are the current values at the time of
|
| 367 |
+
* `cluster.setupPrimary()` is called.
|
| 368 |
+
*
|
| 369 |
+
* ```js
|
| 370 |
+
* import cluster from 'node:cluster';
|
| 371 |
+
*
|
| 372 |
+
* cluster.setupPrimary({
|
| 373 |
+
* exec: 'worker.js',
|
| 374 |
+
* args: ['--use', 'https'],
|
| 375 |
+
* silent: true,
|
| 376 |
+
* });
|
| 377 |
+
* cluster.fork(); // https worker
|
| 378 |
+
* cluster.setupPrimary({
|
| 379 |
+
* exec: 'worker.js',
|
| 380 |
+
* args: ['--use', 'http'],
|
| 381 |
+
* });
|
| 382 |
+
* cluster.fork(); // http worker
|
| 383 |
+
* ```
|
| 384 |
+
*
|
| 385 |
+
* This can only be called from the primary process.
|
| 386 |
+
* @since v16.0.0
|
| 387 |
+
*/
|
| 388 |
+
setupPrimary(settings?: ClusterSettings): void;
|
| 389 |
+
/**
|
| 390 |
+
* A reference to the current worker object. Not available in the primary process.
|
| 391 |
+
*
|
| 392 |
+
* ```js
|
| 393 |
+
* import cluster from 'node:cluster';
|
| 394 |
+
*
|
| 395 |
+
* if (cluster.isPrimary) {
|
| 396 |
+
* console.log('I am primary');
|
| 397 |
+
* cluster.fork();
|
| 398 |
+
* cluster.fork();
|
| 399 |
+
* } else if (cluster.isWorker) {
|
| 400 |
+
* console.log(`I am worker #${cluster.worker.id}`);
|
| 401 |
+
* }
|
| 402 |
+
* ```
|
| 403 |
+
* @since v0.7.0
|
| 404 |
+
*/
|
| 405 |
+
readonly worker?: Worker;
|
| 406 |
+
/**
|
| 407 |
+
* 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.
|
| 408 |
+
*
|
| 409 |
+
* 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
|
| 410 |
+
* is guaranteed that the removal from the `cluster.workers` list happens before the last `'disconnect'` or `'exit'` event is emitted.
|
| 411 |
+
*
|
| 412 |
+
* ```js
|
| 413 |
+
* import cluster from 'node:cluster';
|
| 414 |
+
*
|
| 415 |
+
* for (const worker of Object.values(cluster.workers)) {
|
| 416 |
+
* worker.send('big announcement to all workers');
|
| 417 |
+
* }
|
| 418 |
+
* ```
|
| 419 |
+
* @since v0.7.0
|
| 420 |
+
*/
|
| 421 |
+
readonly workers?: NodeJS.Dict<Worker>;
|
| 422 |
+
readonly SCHED_NONE: number;
|
| 423 |
+
readonly SCHED_RR: number;
|
| 424 |
+
}
|
| 425 |
+
}
|
| 426 |
+
var cluster: cluster.Cluster;
|
| 427 |
+
export = cluster;
|
| 428 |
+
}
|
| 429 |
+
declare module "cluster" {
|
| 430 |
+
import cluster = require("node:cluster");
|
| 431 |
+
export = cluster;
|
| 432 |
+
}
|
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 |
+
}
|
node_modules/@types/node/console.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:console" {
|
| 2 |
+
import { InspectOptions } from "node:util";
|
| 3 |
+
namespace console {
|
| 4 |
+
interface ConsoleOptions {
|
| 5 |
+
stdout: NodeJS.WritableStream;
|
| 6 |
+
stderr?: NodeJS.WritableStream | undefined;
|
| 7 |
+
/**
|
| 8 |
+
* Ignore errors when writing to the underlying streams.
|
| 9 |
+
* @default true
|
| 10 |
+
*/
|
| 11 |
+
ignoreErrors?: boolean | undefined;
|
| 12 |
+
/**
|
| 13 |
+
* Set color support for this `Console` instance. Setting to true enables coloring while inspecting
|
| 14 |
+
* values. Setting to `false` disables coloring while inspecting values. Setting to `'auto'` makes color
|
| 15 |
+
* support depend on the value of the `isTTY` property and the value returned by `getColorDepth()` on the
|
| 16 |
+
* respective stream. This option can not be used, if `inspectOptions.colors` is set as well.
|
| 17 |
+
* @default 'auto'
|
| 18 |
+
*/
|
| 19 |
+
colorMode?: boolean | "auto" | undefined;
|
| 20 |
+
/**
|
| 21 |
+
* Specifies options that are passed along to
|
| 22 |
+
* [`util.inspect()`](https://nodejs.org/docs/latest-v25.x/api/util.html#utilinspectobject-options).
|
| 23 |
+
*/
|
| 24 |
+
inspectOptions?: InspectOptions | ReadonlyMap<NodeJS.WritableStream, InspectOptions> | undefined;
|
| 25 |
+
/**
|
| 26 |
+
* Set group indentation.
|
| 27 |
+
* @default 2
|
| 28 |
+
*/
|
| 29 |
+
groupIndentation?: number | undefined;
|
| 30 |
+
}
|
| 31 |
+
interface Console {
|
| 32 |
+
readonly Console: {
|
| 33 |
+
prototype: Console;
|
| 34 |
+
new(stdout: NodeJS.WritableStream, stderr?: NodeJS.WritableStream, ignoreErrors?: boolean): Console;
|
| 35 |
+
new(options: ConsoleOptions): Console;
|
| 36 |
+
};
|
| 37 |
+
assert(condition?: unknown, ...data: any[]): void;
|
| 38 |
+
clear(): void;
|
| 39 |
+
count(label?: string): void;
|
| 40 |
+
countReset(label?: string): void;
|
| 41 |
+
debug(...data: any[]): void;
|
| 42 |
+
dir(item?: any, options?: InspectOptions): void;
|
| 43 |
+
dirxml(...data: any[]): void;
|
| 44 |
+
error(...data: any[]): void;
|
| 45 |
+
group(...data: any[]): void;
|
| 46 |
+
groupCollapsed(...data: any[]): void;
|
| 47 |
+
groupEnd(): void;
|
| 48 |
+
info(...data: any[]): void;
|
| 49 |
+
log(...data: any[]): void;
|
| 50 |
+
table(tabularData?: any, properties?: string[]): void;
|
| 51 |
+
time(label?: string): void;
|
| 52 |
+
timeEnd(label?: string): void;
|
| 53 |
+
timeLog(label?: string, ...data: any[]): void;
|
| 54 |
+
trace(...data: any[]): void;
|
| 55 |
+
warn(...data: any[]): void;
|
| 56 |
+
/**
|
| 57 |
+
* This method does not display anything unless used in the inspector. The `console.profile()`
|
| 58 |
+
* method starts a JavaScript CPU profile with an optional label until {@link profileEnd}
|
| 59 |
+
* is called. The profile is then added to the Profile panel of the inspector.
|
| 60 |
+
*
|
| 61 |
+
* ```js
|
| 62 |
+
* console.profile('MyLabel');
|
| 63 |
+
* // Some code
|
| 64 |
+
* console.profileEnd('MyLabel');
|
| 65 |
+
* // Adds the profile 'MyLabel' to the Profiles panel of the inspector.
|
| 66 |
+
* ```
|
| 67 |
+
* @since v8.0.0
|
| 68 |
+
*/
|
| 69 |
+
profile(label?: string): void;
|
| 70 |
+
/**
|
| 71 |
+
* This method does not display anything unless used in the inspector. Stops the current
|
| 72 |
+
* JavaScript CPU profiling session if one has been started and prints the report to the
|
| 73 |
+
* Profiles panel of the inspector. See {@link profile} for an example.
|
| 74 |
+
*
|
| 75 |
+
* If this method is called without a label, the most recently started profile is stopped.
|
| 76 |
+
* @since v8.0.0
|
| 77 |
+
*/
|
| 78 |
+
profileEnd(label?: string): void;
|
| 79 |
+
/**
|
| 80 |
+
* This method does not display anything unless used in the inspector. The `console.timeStamp()`
|
| 81 |
+
* method adds an event with the label `'label'` to the Timeline panel of the inspector.
|
| 82 |
+
* @since v8.0.0
|
| 83 |
+
*/
|
| 84 |
+
timeStamp(label?: string): void;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
var console: console.Console;
|
| 88 |
+
export = console;
|
| 89 |
+
}
|
| 90 |
+
declare module "console" {
|
| 91 |
+
import console = require("node:console");
|
| 92 |
+
export = console;
|
| 93 |
+
}
|
node_modules/@types/node/constants.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:constants" {
|
| 2 |
+
const constants:
|
| 3 |
+
& typeof import("node:os").constants.dlopen
|
| 4 |
+
& typeof import("node:os").constants.errno
|
| 5 |
+
& typeof import("node:os").constants.priority
|
| 6 |
+
& typeof import("node:os").constants.signals
|
| 7 |
+
& typeof import("node:fs").constants
|
| 8 |
+
& typeof import("node:crypto").constants;
|
| 9 |
+
export = constants;
|
| 10 |
+
}
|
| 11 |
+
declare module "constants" {
|
| 12 |
+
import constants = require("node:constants");
|
| 13 |
+
export = constants;
|
| 14 |
+
}
|
node_modules/@types/node/crypto.d.ts
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/@types/node/dgram.d.ts
ADDED
|
@@ -0,0 +1,537 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:dgram" {
|
| 2 |
+
import { NonSharedBuffer } from "node:buffer";
|
| 3 |
+
import * as dns from "node:dns";
|
| 4 |
+
import { Abortable, EventEmitter, InternalEventEmitter } from "node:events";
|
| 5 |
+
import { AddressInfo, BlockList } from "node:net";
|
| 6 |
+
interface RemoteInfo {
|
| 7 |
+
address: string;
|
| 8 |
+
family: "IPv4" | "IPv6";
|
| 9 |
+
port: number;
|
| 10 |
+
size: number;
|
| 11 |
+
}
|
| 12 |
+
interface BindOptions {
|
| 13 |
+
port?: number | undefined;
|
| 14 |
+
address?: string | undefined;
|
| 15 |
+
exclusive?: boolean | undefined;
|
| 16 |
+
fd?: number | undefined;
|
| 17 |
+
}
|
| 18 |
+
type SocketType = "udp4" | "udp6";
|
| 19 |
+
interface SocketOptions extends Abortable {
|
| 20 |
+
type: SocketType;
|
| 21 |
+
reuseAddr?: boolean | undefined;
|
| 22 |
+
reusePort?: boolean | undefined;
|
| 23 |
+
/**
|
| 24 |
+
* @default false
|
| 25 |
+
*/
|
| 26 |
+
ipv6Only?: boolean | undefined;
|
| 27 |
+
recvBufferSize?: number | undefined;
|
| 28 |
+
sendBufferSize?: number | undefined;
|
| 29 |
+
lookup?:
|
| 30 |
+
| ((
|
| 31 |
+
hostname: string,
|
| 32 |
+
options: dns.LookupOneOptions,
|
| 33 |
+
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
| 34 |
+
) => void)
|
| 35 |
+
| undefined;
|
| 36 |
+
receiveBlockList?: BlockList | undefined;
|
| 37 |
+
sendBlockList?: BlockList | undefined;
|
| 38 |
+
}
|
| 39 |
+
/**
|
| 40 |
+
* Creates a `dgram.Socket` object. Once the socket is created, calling `socket.bind()` will instruct the socket to begin listening for datagram
|
| 41 |
+
* messages. When `address` and `port` are not passed to `socket.bind()` the
|
| 42 |
+
* method will bind the socket to the "all interfaces" address on a random port
|
| 43 |
+
* (it does the right thing for both `udp4` and `udp6` sockets). The bound address
|
| 44 |
+
* and port can be retrieved using `socket.address().address` and `socket.address().port`.
|
| 45 |
+
*
|
| 46 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding `AbortController` is similar to calling `.close()` on the socket:
|
| 47 |
+
*
|
| 48 |
+
* ```js
|
| 49 |
+
* const controller = new AbortController();
|
| 50 |
+
* const { signal } = controller;
|
| 51 |
+
* const server = dgram.createSocket({ type: 'udp4', signal });
|
| 52 |
+
* server.on('message', (msg, rinfo) => {
|
| 53 |
+
* console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
|
| 54 |
+
* });
|
| 55 |
+
* // Later, when you want to close the server.
|
| 56 |
+
* controller.abort();
|
| 57 |
+
* ```
|
| 58 |
+
* @since v0.11.13
|
| 59 |
+
* @param options Available options are:
|
| 60 |
+
* @param callback Attached as a listener for `'message'` events. Optional.
|
| 61 |
+
*/
|
| 62 |
+
function createSocket(type: SocketType, callback?: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): Socket;
|
| 63 |
+
function createSocket(options: SocketOptions, callback?: (msg: NonSharedBuffer, rinfo: RemoteInfo) => void): Socket;
|
| 64 |
+
interface SocketEventMap {
|
| 65 |
+
"close": [];
|
| 66 |
+
"connect": [];
|
| 67 |
+
"error": [err: Error];
|
| 68 |
+
"listening": [];
|
| 69 |
+
"message": [msg: NonSharedBuffer, rinfo: RemoteInfo];
|
| 70 |
+
}
|
| 71 |
+
/**
|
| 72 |
+
* Encapsulates the datagram functionality.
|
| 73 |
+
*
|
| 74 |
+
* New instances of `dgram.Socket` are created using {@link createSocket}.
|
| 75 |
+
* The `new` keyword is not to be used to create `dgram.Socket` instances.
|
| 76 |
+
* @since v0.1.99
|
| 77 |
+
*/
|
| 78 |
+
class Socket implements EventEmitter {
|
| 79 |
+
/**
|
| 80 |
+
* 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
|
| 81 |
+
* specified, the operating system will choose
|
| 82 |
+
* one interface and will add membership to it. To add membership to every
|
| 83 |
+
* available interface, call `addMembership` multiple times, once per interface.
|
| 84 |
+
*
|
| 85 |
+
* When called on an unbound socket, this method will implicitly bind to a random
|
| 86 |
+
* port, listening on all interfaces.
|
| 87 |
+
*
|
| 88 |
+
* When sharing a UDP socket across multiple `cluster` workers, the`socket.addMembership()` function must be called only once or an`EADDRINUSE` error will occur:
|
| 89 |
+
*
|
| 90 |
+
* ```js
|
| 91 |
+
* import cluster from 'node:cluster';
|
| 92 |
+
* import dgram from 'node:dgram';
|
| 93 |
+
*
|
| 94 |
+
* if (cluster.isPrimary) {
|
| 95 |
+
* cluster.fork(); // Works ok.
|
| 96 |
+
* cluster.fork(); // Fails with EADDRINUSE.
|
| 97 |
+
* } else {
|
| 98 |
+
* const s = dgram.createSocket('udp4');
|
| 99 |
+
* s.bind(1234, () => {
|
| 100 |
+
* s.addMembership('224.0.0.114');
|
| 101 |
+
* });
|
| 102 |
+
* }
|
| 103 |
+
* ```
|
| 104 |
+
* @since v0.6.9
|
| 105 |
+
*/
|
| 106 |
+
addMembership(multicastAddress: string, multicastInterface?: string): void;
|
| 107 |
+
/**
|
| 108 |
+
* Returns an object containing the address information for a socket.
|
| 109 |
+
* For UDP sockets, this object will contain `address`, `family`, and `port` properties.
|
| 110 |
+
*
|
| 111 |
+
* This method throws `EBADF` if called on an unbound socket.
|
| 112 |
+
* @since v0.1.99
|
| 113 |
+
*/
|
| 114 |
+
address(): AddressInfo;
|
| 115 |
+
/**
|
| 116 |
+
* For UDP sockets, causes the `dgram.Socket` to listen for datagram
|
| 117 |
+
* messages on a named `port` and optional `address`. If `port` is not
|
| 118 |
+
* specified or is `0`, the operating system will attempt to bind to a
|
| 119 |
+
* random port. If `address` is not specified, the operating system will
|
| 120 |
+
* attempt to listen on all addresses. Once binding is complete, a `'listening'` event is emitted and the optional `callback` function is
|
| 121 |
+
* called.
|
| 122 |
+
*
|
| 123 |
+
* Specifying both a `'listening'` event listener and passing a `callback` to the `socket.bind()` method is not harmful but not very
|
| 124 |
+
* useful.
|
| 125 |
+
*
|
| 126 |
+
* A bound datagram socket keeps the Node.js process running to receive
|
| 127 |
+
* datagram messages.
|
| 128 |
+
*
|
| 129 |
+
* If binding fails, an `'error'` event is generated. In rare case (e.g.
|
| 130 |
+
* attempting to bind with a closed socket), an `Error` may be thrown.
|
| 131 |
+
*
|
| 132 |
+
* Example of a UDP server listening on port 41234:
|
| 133 |
+
*
|
| 134 |
+
* ```js
|
| 135 |
+
* import dgram from 'node:dgram';
|
| 136 |
+
*
|
| 137 |
+
* const server = dgram.createSocket('udp4');
|
| 138 |
+
*
|
| 139 |
+
* server.on('error', (err) => {
|
| 140 |
+
* console.error(`server error:\n${err.stack}`);
|
| 141 |
+
* server.close();
|
| 142 |
+
* });
|
| 143 |
+
*
|
| 144 |
+
* server.on('message', (msg, rinfo) => {
|
| 145 |
+
* console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
|
| 146 |
+
* });
|
| 147 |
+
*
|
| 148 |
+
* server.on('listening', () => {
|
| 149 |
+
* const address = server.address();
|
| 150 |
+
* console.log(`server listening ${address.address}:${address.port}`);
|
| 151 |
+
* });
|
| 152 |
+
*
|
| 153 |
+
* server.bind(41234);
|
| 154 |
+
* // Prints: server listening 0.0.0.0:41234
|
| 155 |
+
* ```
|
| 156 |
+
* @since v0.1.99
|
| 157 |
+
* @param callback with no parameters. Called when binding is complete.
|
| 158 |
+
*/
|
| 159 |
+
bind(port?: number, address?: string, callback?: () => void): this;
|
| 160 |
+
bind(port?: number, callback?: () => void): this;
|
| 161 |
+
bind(callback?: () => void): this;
|
| 162 |
+
bind(options: BindOptions, callback?: () => void): this;
|
| 163 |
+
/**
|
| 164 |
+
* Close the underlying socket and stop listening for data on it. If a callback is
|
| 165 |
+
* provided, it is added as a listener for the `'close'` event.
|
| 166 |
+
* @since v0.1.99
|
| 167 |
+
* @param callback Called when the socket has been closed.
|
| 168 |
+
*/
|
| 169 |
+
close(callback?: () => void): this;
|
| 170 |
+
/**
|
| 171 |
+
* Associates the `dgram.Socket` to a remote address and port. Every
|
| 172 |
+
* message sent by this handle is automatically sent to that destination. Also,
|
| 173 |
+
* the socket will only receive messages from that remote peer.
|
| 174 |
+
* Trying to call `connect()` on an already connected socket will result
|
| 175 |
+
* in an `ERR_SOCKET_DGRAM_IS_CONNECTED` exception. If `address` is not
|
| 176 |
+
* provided, `'127.0.0.1'` (for `udp4` sockets) or `'::1'` (for `udp6` sockets)
|
| 177 |
+
* will be used by default. Once the connection is complete, a `'connect'` event
|
| 178 |
+
* is emitted and the optional `callback` function is called. In case of failure,
|
| 179 |
+
* the `callback` is called or, failing this, an `'error'` event is emitted.
|
| 180 |
+
* @since v12.0.0
|
| 181 |
+
* @param callback Called when the connection is completed or on error.
|
| 182 |
+
*/
|
| 183 |
+
connect(port: number, address?: string, callback?: () => void): void;
|
| 184 |
+
connect(port: number, callback: () => void): void;
|
| 185 |
+
/**
|
| 186 |
+
* A synchronous function that disassociates a connected `dgram.Socket` from
|
| 187 |
+
* its remote address. Trying to call `disconnect()` on an unbound or already
|
| 188 |
+
* disconnected socket will result in an `ERR_SOCKET_DGRAM_NOT_CONNECTED` exception.
|
| 189 |
+
* @since v12.0.0
|
| 190 |
+
*/
|
| 191 |
+
disconnect(): void;
|
| 192 |
+
/**
|
| 193 |
+
* Instructs the kernel to leave a multicast group at `multicastAddress` using the `IP_DROP_MEMBERSHIP` socket option. This method is automatically called by the
|
| 194 |
+
* kernel when the socket is closed or the process terminates, so most apps will
|
| 195 |
+
* never have reason to call this.
|
| 196 |
+
*
|
| 197 |
+
* If `multicastInterface` is not specified, the operating system will attempt to
|
| 198 |
+
* drop membership on all valid interfaces.
|
| 199 |
+
* @since v0.6.9
|
| 200 |
+
*/
|
| 201 |
+
dropMembership(multicastAddress: string, multicastInterface?: string): void;
|
| 202 |
+
/**
|
| 203 |
+
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket.
|
| 204 |
+
* @since v8.7.0
|
| 205 |
+
* @return the `SO_RCVBUF` socket receive buffer size in bytes.
|
| 206 |
+
*/
|
| 207 |
+
getRecvBufferSize(): number;
|
| 208 |
+
/**
|
| 209 |
+
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket.
|
| 210 |
+
* @since v8.7.0
|
| 211 |
+
* @return the `SO_SNDBUF` socket send buffer size in bytes.
|
| 212 |
+
*/
|
| 213 |
+
getSendBufferSize(): number;
|
| 214 |
+
/**
|
| 215 |
+
* @since v18.8.0, v16.19.0
|
| 216 |
+
* @return Number of bytes queued for sending.
|
| 217 |
+
*/
|
| 218 |
+
getSendQueueSize(): number;
|
| 219 |
+
/**
|
| 220 |
+
* @since v18.8.0, v16.19.0
|
| 221 |
+
* @return Number of send requests currently in the queue awaiting to be processed.
|
| 222 |
+
*/
|
| 223 |
+
getSendQueueCount(): number;
|
| 224 |
+
/**
|
| 225 |
+
* By default, binding a socket will cause it to block the Node.js process from
|
| 226 |
+
* exiting as long as the socket is open. The `socket.unref()` method can be used
|
| 227 |
+
* to exclude the socket from the reference counting that keeps the Node.js
|
| 228 |
+
* process active. The `socket.ref()` method adds the socket back to the reference
|
| 229 |
+
* counting and restores the default behavior.
|
| 230 |
+
*
|
| 231 |
+
* Calling `socket.ref()` multiples times will have no additional effect.
|
| 232 |
+
*
|
| 233 |
+
* The `socket.ref()` method returns a reference to the socket so calls can be
|
| 234 |
+
* chained.
|
| 235 |
+
* @since v0.9.1
|
| 236 |
+
*/
|
| 237 |
+
ref(): this;
|
| 238 |
+
/**
|
| 239 |
+
* Returns an object containing the `address`, `family`, and `port` of the remote
|
| 240 |
+
* endpoint. This method throws an `ERR_SOCKET_DGRAM_NOT_CONNECTED` exception
|
| 241 |
+
* if the socket is not connected.
|
| 242 |
+
* @since v12.0.0
|
| 243 |
+
*/
|
| 244 |
+
remoteAddress(): AddressInfo;
|
| 245 |
+
/**
|
| 246 |
+
* Broadcasts a datagram on the socket.
|
| 247 |
+
* For connectionless sockets, the destination `port` and `address` must be
|
| 248 |
+
* specified. Connected sockets, on the other hand, will use their associated
|
| 249 |
+
* remote endpoint, so the `port` and `address` arguments must not be set.
|
| 250 |
+
*
|
| 251 |
+
* The `msg` argument contains the message to be sent.
|
| 252 |
+
* Depending on its type, different behavior can apply. If `msg` is a `Buffer`,
|
| 253 |
+
* any `TypedArray` or a `DataView`,
|
| 254 |
+
* the `offset` and `length` specify the offset within the `Buffer` where the
|
| 255 |
+
* message begins and the number of bytes in the message, respectively.
|
| 256 |
+
* If `msg` is a `String`, then it is automatically converted to a `Buffer` with `'utf8'` encoding. With messages that
|
| 257 |
+
* contain multi-byte characters, `offset` and `length` will be calculated with
|
| 258 |
+
* respect to `byte length` and not the character position.
|
| 259 |
+
* If `msg` is an array, `offset` and `length` must not be specified.
|
| 260 |
+
*
|
| 261 |
+
* The `address` argument is a string. If the value of `address` is a host name,
|
| 262 |
+
* DNS will be used to resolve the address of the host. If `address` is not
|
| 263 |
+
* provided or otherwise nullish, `'127.0.0.1'` (for `udp4` sockets) or `'::1'` (for `udp6` sockets) will be used by default.
|
| 264 |
+
*
|
| 265 |
+
* If the socket has not been previously bound with a call to `bind`, the socket
|
| 266 |
+
* is assigned a random port number and is bound to the "all interfaces" address
|
| 267 |
+
* (`'0.0.0.0'` for `udp4` sockets, `'::0'` for `udp6` sockets.)
|
| 268 |
+
*
|
| 269 |
+
* An optional `callback` function may be specified to as a way of reporting
|
| 270 |
+
* DNS errors or for determining when it is safe to reuse the `buf` object.
|
| 271 |
+
* DNS lookups delay the time to send for at least one tick of the
|
| 272 |
+
* Node.js event loop.
|
| 273 |
+
*
|
| 274 |
+
* 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
|
| 275 |
+
* passed as the first argument to the `callback`. If a `callback` is not given,
|
| 276 |
+
* the error is emitted as an `'error'` event on the `socket` object.
|
| 277 |
+
*
|
| 278 |
+
* Offset and length are optional but both _must_ be set if either are used.
|
| 279 |
+
* They are supported only when the first argument is a `Buffer`, a `TypedArray`,
|
| 280 |
+
* or a `DataView`.
|
| 281 |
+
*
|
| 282 |
+
* This method throws `ERR_SOCKET_BAD_PORT` if called on an unbound socket.
|
| 283 |
+
*
|
| 284 |
+
* Example of sending a UDP packet to a port on `localhost`;
|
| 285 |
+
*
|
| 286 |
+
* ```js
|
| 287 |
+
* import dgram from 'node:dgram';
|
| 288 |
+
* import { Buffer } from 'node:buffer';
|
| 289 |
+
*
|
| 290 |
+
* const message = Buffer.from('Some bytes');
|
| 291 |
+
* const client = dgram.createSocket('udp4');
|
| 292 |
+
* client.send(message, 41234, 'localhost', (err) => {
|
| 293 |
+
* client.close();
|
| 294 |
+
* });
|
| 295 |
+
* ```
|
| 296 |
+
*
|
| 297 |
+
* Example of sending a UDP packet composed of multiple buffers to a port on`127.0.0.1`;
|
| 298 |
+
*
|
| 299 |
+
* ```js
|
| 300 |
+
* import dgram from 'node:dgram';
|
| 301 |
+
* import { Buffer } from 'node:buffer';
|
| 302 |
+
*
|
| 303 |
+
* const buf1 = Buffer.from('Some ');
|
| 304 |
+
* const buf2 = Buffer.from('bytes');
|
| 305 |
+
* const client = dgram.createSocket('udp4');
|
| 306 |
+
* client.send([buf1, buf2], 41234, (err) => {
|
| 307 |
+
* client.close();
|
| 308 |
+
* });
|
| 309 |
+
* ```
|
| 310 |
+
*
|
| 311 |
+
* Sending multiple buffers might be faster or slower depending on the
|
| 312 |
+
* application and operating system. Run benchmarks to
|
| 313 |
+
* determine the optimal strategy on a case-by-case basis. Generally speaking,
|
| 314 |
+
* however, sending multiple buffers is faster.
|
| 315 |
+
*
|
| 316 |
+
* Example of sending a UDP packet using a socket connected to a port on `localhost`:
|
| 317 |
+
*
|
| 318 |
+
* ```js
|
| 319 |
+
* import dgram from 'node:dgram';
|
| 320 |
+
* import { Buffer } from 'node:buffer';
|
| 321 |
+
*
|
| 322 |
+
* const message = Buffer.from('Some bytes');
|
| 323 |
+
* const client = dgram.createSocket('udp4');
|
| 324 |
+
* client.connect(41234, 'localhost', (err) => {
|
| 325 |
+
* client.send(message, (err) => {
|
| 326 |
+
* client.close();
|
| 327 |
+
* });
|
| 328 |
+
* });
|
| 329 |
+
* ```
|
| 330 |
+
* @since v0.1.99
|
| 331 |
+
* @param msg Message to be sent.
|
| 332 |
+
* @param offset Offset in the buffer where the message starts.
|
| 333 |
+
* @param length Number of bytes in the message.
|
| 334 |
+
* @param port Destination port.
|
| 335 |
+
* @param address Destination host name or IP address.
|
| 336 |
+
* @param callback Called when the message has been sent.
|
| 337 |
+
*/
|
| 338 |
+
send(
|
| 339 |
+
msg: string | NodeJS.ArrayBufferView | readonly any[],
|
| 340 |
+
port?: number,
|
| 341 |
+
address?: string,
|
| 342 |
+
callback?: (error: Error | null, bytes: number) => void,
|
| 343 |
+
): void;
|
| 344 |
+
send(
|
| 345 |
+
msg: string | NodeJS.ArrayBufferView | readonly any[],
|
| 346 |
+
port?: number,
|
| 347 |
+
callback?: (error: Error | null, bytes: number) => void,
|
| 348 |
+
): void;
|
| 349 |
+
send(
|
| 350 |
+
msg: string | NodeJS.ArrayBufferView | readonly any[],
|
| 351 |
+
callback?: (error: Error | null, bytes: number) => void,
|
| 352 |
+
): void;
|
| 353 |
+
send(
|
| 354 |
+
msg: string | NodeJS.ArrayBufferView,
|
| 355 |
+
offset: number,
|
| 356 |
+
length: number,
|
| 357 |
+
port?: number,
|
| 358 |
+
address?: string,
|
| 359 |
+
callback?: (error: Error | null, bytes: number) => void,
|
| 360 |
+
): void;
|
| 361 |
+
send(
|
| 362 |
+
msg: string | NodeJS.ArrayBufferView,
|
| 363 |
+
offset: number,
|
| 364 |
+
length: number,
|
| 365 |
+
port?: number,
|
| 366 |
+
callback?: (error: Error | null, bytes: number) => void,
|
| 367 |
+
): void;
|
| 368 |
+
send(
|
| 369 |
+
msg: string | NodeJS.ArrayBufferView,
|
| 370 |
+
offset: number,
|
| 371 |
+
length: number,
|
| 372 |
+
callback?: (error: Error | null, bytes: number) => void,
|
| 373 |
+
): void;
|
| 374 |
+
/**
|
| 375 |
+
* Sets or clears the `SO_BROADCAST` socket option. When set to `true`, UDP
|
| 376 |
+
* packets may be sent to a local interface's broadcast address.
|
| 377 |
+
*
|
| 378 |
+
* This method throws `EBADF` if called on an unbound socket.
|
| 379 |
+
* @since v0.6.9
|
| 380 |
+
*/
|
| 381 |
+
setBroadcast(flag: boolean): void;
|
| 382 |
+
/**
|
| 383 |
+
* _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
|
| 384 |
+
* 4007](https://tools.ietf.org/html/rfc4007). In string form, an IP_
|
| 385 |
+
* _with a scope index is written as `'IP%scope'` where scope is an interface name_
|
| 386 |
+
* _or interface number._
|
| 387 |
+
*
|
| 388 |
+
* Sets the default outgoing multicast interface of the socket to a chosen
|
| 389 |
+
* interface or back to system interface selection. The `multicastInterface` must
|
| 390 |
+
* be a valid string representation of an IP from the socket's family.
|
| 391 |
+
*
|
| 392 |
+
* For IPv4 sockets, this should be the IP configured for the desired physical
|
| 393 |
+
* interface. All packets sent to multicast on the socket will be sent on the
|
| 394 |
+
* interface determined by the most recent successful use of this call.
|
| 395 |
+
*
|
| 396 |
+
* For IPv6 sockets, `multicastInterface` should include a scope to indicate the
|
| 397 |
+
* interface as in the examples that follow. In IPv6, individual `send` calls can
|
| 398 |
+
* also use explicit scope in addresses, so only packets sent to a multicast
|
| 399 |
+
* address without specifying an explicit scope are affected by the most recent
|
| 400 |
+
* successful use of this call.
|
| 401 |
+
*
|
| 402 |
+
* This method throws `EBADF` if called on an unbound socket.
|
| 403 |
+
*
|
| 404 |
+
* #### Example: IPv6 outgoing multicast interface
|
| 405 |
+
*
|
| 406 |
+
* On most systems, where scope format uses the interface name:
|
| 407 |
+
*
|
| 408 |
+
* ```js
|
| 409 |
+
* const socket = dgram.createSocket('udp6');
|
| 410 |
+
*
|
| 411 |
+
* socket.bind(1234, () => {
|
| 412 |
+
* socket.setMulticastInterface('::%eth1');
|
| 413 |
+
* });
|
| 414 |
+
* ```
|
| 415 |
+
*
|
| 416 |
+
* On Windows, where scope format uses an interface number:
|
| 417 |
+
*
|
| 418 |
+
* ```js
|
| 419 |
+
* const socket = dgram.createSocket('udp6');
|
| 420 |
+
*
|
| 421 |
+
* socket.bind(1234, () => {
|
| 422 |
+
* socket.setMulticastInterface('::%2');
|
| 423 |
+
* });
|
| 424 |
+
* ```
|
| 425 |
+
*
|
| 426 |
+
* #### Example: IPv4 outgoing multicast interface
|
| 427 |
+
*
|
| 428 |
+
* All systems use an IP of the host on the desired physical interface:
|
| 429 |
+
*
|
| 430 |
+
* ```js
|
| 431 |
+
* const socket = dgram.createSocket('udp4');
|
| 432 |
+
*
|
| 433 |
+
* socket.bind(1234, () => {
|
| 434 |
+
* socket.setMulticastInterface('10.0.0.2');
|
| 435 |
+
* });
|
| 436 |
+
* ```
|
| 437 |
+
* @since v8.6.0
|
| 438 |
+
*/
|
| 439 |
+
setMulticastInterface(multicastInterface: string): void;
|
| 440 |
+
/**
|
| 441 |
+
* Sets or clears the `IP_MULTICAST_LOOP` socket option. When set to `true`,
|
| 442 |
+
* multicast packets will also be received on the local interface.
|
| 443 |
+
*
|
| 444 |
+
* This method throws `EBADF` if called on an unbound socket.
|
| 445 |
+
* @since v0.3.8
|
| 446 |
+
*/
|
| 447 |
+
setMulticastLoopback(flag: boolean): boolean;
|
| 448 |
+
/**
|
| 449 |
+
* Sets the `IP_MULTICAST_TTL` socket option. While TTL generally stands for
|
| 450 |
+
* "Time to Live", in this context it specifies the number of IP hops that a
|
| 451 |
+
* packet is allowed to travel through, specifically for multicast traffic. Each
|
| 452 |
+
* router or gateway that forwards a packet decrements the TTL. If the TTL is
|
| 453 |
+
* decremented to 0 by a router, it will not be forwarded.
|
| 454 |
+
*
|
| 455 |
+
* The `ttl` argument may be between 0 and 255\. The default on most systems is `1`.
|
| 456 |
+
*
|
| 457 |
+
* This method throws `EBADF` if called on an unbound socket.
|
| 458 |
+
* @since v0.3.8
|
| 459 |
+
*/
|
| 460 |
+
setMulticastTTL(ttl: number): number;
|
| 461 |
+
/**
|
| 462 |
+
* Sets the `SO_RCVBUF` socket option. Sets the maximum socket receive buffer
|
| 463 |
+
* in bytes.
|
| 464 |
+
*
|
| 465 |
+
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket.
|
| 466 |
+
* @since v8.7.0
|
| 467 |
+
*/
|
| 468 |
+
setRecvBufferSize(size: number): void;
|
| 469 |
+
/**
|
| 470 |
+
* Sets the `SO_SNDBUF` socket option. Sets the maximum socket send buffer
|
| 471 |
+
* in bytes.
|
| 472 |
+
*
|
| 473 |
+
* This method throws `ERR_SOCKET_BUFFER_SIZE` if called on an unbound socket.
|
| 474 |
+
* @since v8.7.0
|
| 475 |
+
*/
|
| 476 |
+
setSendBufferSize(size: number): void;
|
| 477 |
+
/**
|
| 478 |
+
* Sets the `IP_TTL` socket option. While TTL generally stands for "Time to Live",
|
| 479 |
+
* in this context it specifies the number of IP hops that a packet is allowed to
|
| 480 |
+
* travel through. Each router or gateway that forwards a packet decrements the
|
| 481 |
+
* TTL. If the TTL is decremented to 0 by a router, it will not be forwarded.
|
| 482 |
+
* Changing TTL values is typically done for network probes or when multicasting.
|
| 483 |
+
*
|
| 484 |
+
* The `ttl` argument may be between 1 and 255\. The default on most systems
|
| 485 |
+
* is 64.
|
| 486 |
+
*
|
| 487 |
+
* This method throws `EBADF` if called on an unbound socket.
|
| 488 |
+
* @since v0.1.101
|
| 489 |
+
*/
|
| 490 |
+
setTTL(ttl: number): number;
|
| 491 |
+
/**
|
| 492 |
+
* By default, binding a socket will cause it to block the Node.js process from
|
| 493 |
+
* exiting as long as the socket is open. The `socket.unref()` method can be used
|
| 494 |
+
* to exclude the socket from the reference counting that keeps the Node.js
|
| 495 |
+
* process active, allowing the process to exit even if the socket is still
|
| 496 |
+
* listening.
|
| 497 |
+
*
|
| 498 |
+
* Calling `socket.unref()` multiple times will have no additional effect.
|
| 499 |
+
*
|
| 500 |
+
* The `socket.unref()` method returns a reference to the socket so calls can be
|
| 501 |
+
* chained.
|
| 502 |
+
* @since v0.9.1
|
| 503 |
+
*/
|
| 504 |
+
unref(): this;
|
| 505 |
+
/**
|
| 506 |
+
* 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
|
| 507 |
+
* option. If the `multicastInterface` argument
|
| 508 |
+
* is not specified, the operating system will choose one interface and will add
|
| 509 |
+
* membership to it. To add membership to every available interface, call `socket.addSourceSpecificMembership()` multiple times, once per interface.
|
| 510 |
+
*
|
| 511 |
+
* When called on an unbound socket, this method will implicitly bind to a random
|
| 512 |
+
* port, listening on all interfaces.
|
| 513 |
+
* @since v13.1.0, v12.16.0
|
| 514 |
+
*/
|
| 515 |
+
addSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string): void;
|
| 516 |
+
/**
|
| 517 |
+
* 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
|
| 518 |
+
* automatically called by the kernel when the
|
| 519 |
+
* socket is closed or the process terminates, so most apps will never have
|
| 520 |
+
* reason to call this.
|
| 521 |
+
*
|
| 522 |
+
* If `multicastInterface` is not specified, the operating system will attempt to
|
| 523 |
+
* drop membership on all valid interfaces.
|
| 524 |
+
* @since v13.1.0, v12.16.0
|
| 525 |
+
*/
|
| 526 |
+
dropSourceSpecificMembership(sourceAddress: string, groupAddress: string, multicastInterface?: string): void;
|
| 527 |
+
/**
|
| 528 |
+
* Calls `socket.close()` and returns a promise that fulfills when the socket has closed.
|
| 529 |
+
* @since v20.5.0
|
| 530 |
+
*/
|
| 531 |
+
[Symbol.asyncDispose](): Promise<void>;
|
| 532 |
+
}
|
| 533 |
+
interface Socket extends InternalEvent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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:diagnostics_channel" {
|
| 2 |
+
import { AsyncLocalStorage } from "node:async_hooks";
|
| 3 |
+
/**
|
| 4 |
+
* Check if there are active subscribers to the named channel. This is helpful if
|
| 5 |
+
* the message you want to send might be expensive to prepare.
|
| 6 |
+
*
|
| 7 |
+
* This API is optional but helpful when trying to publish messages from very
|
| 8 |
+
* performance-sensitive code.
|
| 9 |
+
*
|
| 10 |
+
* ```js
|
| 11 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 12 |
+
*
|
| 13 |
+
* if (diagnostics_channel.hasSubscribers('my-channel')) {
|
| 14 |
+
* // There are subscribers, prepare and publish message
|
| 15 |
+
* }
|
| 16 |
+
* ```
|
| 17 |
+
* @since v15.1.0, v14.17.0
|
| 18 |
+
* @param name The channel name
|
| 19 |
+
* @return If there are active subscribers
|
| 20 |
+
*/
|
| 21 |
+
function hasSubscribers(name: string | symbol): boolean;
|
| 22 |
+
/**
|
| 23 |
+
* This is the primary entry-point for anyone wanting to publish to a named
|
| 24 |
+
* channel. It produces a channel object which is optimized to reduce overhead at
|
| 25 |
+
* publish time as much as possible.
|
| 26 |
+
*
|
| 27 |
+
* ```js
|
| 28 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 29 |
+
*
|
| 30 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
| 31 |
+
* ```
|
| 32 |
+
* @since v15.1.0, v14.17.0
|
| 33 |
+
* @param name The channel name
|
| 34 |
+
* @return The named channel object
|
| 35 |
+
*/
|
| 36 |
+
function channel(name: string | symbol): Channel;
|
| 37 |
+
type ChannelListener = (message: unknown, name: string | symbol) => void;
|
| 38 |
+
/**
|
| 39 |
+
* Register a message handler to subscribe to this channel. This message handler
|
| 40 |
+
* will be run synchronously whenever a message is published to the channel. Any
|
| 41 |
+
* errors thrown in the message handler will trigger an `'uncaughtException'`.
|
| 42 |
+
*
|
| 43 |
+
* ```js
|
| 44 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 45 |
+
*
|
| 46 |
+
* diagnostics_channel.subscribe('my-channel', (message, name) => {
|
| 47 |
+
* // Received data
|
| 48 |
+
* });
|
| 49 |
+
* ```
|
| 50 |
+
* @since v18.7.0, v16.17.0
|
| 51 |
+
* @param name The channel name
|
| 52 |
+
* @param onMessage The handler to receive channel messages
|
| 53 |
+
*/
|
| 54 |
+
function subscribe(name: string | symbol, onMessage: ChannelListener): void;
|
| 55 |
+
/**
|
| 56 |
+
* Remove a message handler previously registered to this channel with {@link subscribe}.
|
| 57 |
+
*
|
| 58 |
+
* ```js
|
| 59 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 60 |
+
*
|
| 61 |
+
* function onMessage(message, name) {
|
| 62 |
+
* // Received data
|
| 63 |
+
* }
|
| 64 |
+
*
|
| 65 |
+
* diagnostics_channel.subscribe('my-channel', onMessage);
|
| 66 |
+
*
|
| 67 |
+
* diagnostics_channel.unsubscribe('my-channel', onMessage);
|
| 68 |
+
* ```
|
| 69 |
+
* @since v18.7.0, v16.17.0
|
| 70 |
+
* @param name The channel name
|
| 71 |
+
* @param onMessage The previous subscribed handler to remove
|
| 72 |
+
* @return `true` if the handler was found, `false` otherwise.
|
| 73 |
+
*/
|
| 74 |
+
function unsubscribe(name: string | symbol, onMessage: ChannelListener): boolean;
|
| 75 |
+
/**
|
| 76 |
+
* Creates a `TracingChannel` wrapper for the given `TracingChannel Channels`. If a name is given, the corresponding tracing
|
| 77 |
+
* channels will be created in the form of `tracing:${name}:${eventType}` where `eventType` corresponds to the types of `TracingChannel Channels`.
|
| 78 |
+
*
|
| 79 |
+
* ```js
|
| 80 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 81 |
+
*
|
| 82 |
+
* const channelsByName = diagnostics_channel.tracingChannel('my-channel');
|
| 83 |
+
*
|
| 84 |
+
* // or...
|
| 85 |
+
*
|
| 86 |
+
* const channelsByCollection = diagnostics_channel.tracingChannel({
|
| 87 |
+
* start: diagnostics_channel.channel('tracing:my-channel:start'),
|
| 88 |
+
* end: diagnostics_channel.channel('tracing:my-channel:end'),
|
| 89 |
+
* asyncStart: diagnostics_channel.channel('tracing:my-channel:asyncStart'),
|
| 90 |
+
* asyncEnd: diagnostics_channel.channel('tracing:my-channel:asyncEnd'),
|
| 91 |
+
* error: diagnostics_channel.channel('tracing:my-channel:error'),
|
| 92 |
+
* });
|
| 93 |
+
* ```
|
| 94 |
+
* @since v19.9.0
|
| 95 |
+
* @experimental
|
| 96 |
+
* @param nameOrChannels Channel name or object containing all the `TracingChannel Channels`
|
| 97 |
+
* @return Collection of channels to trace with
|
| 98 |
+
*/
|
| 99 |
+
function tracingChannel<
|
| 100 |
+
StoreType = unknown,
|
| 101 |
+
ContextType extends object = StoreType extends object ? StoreType : object,
|
| 102 |
+
>(
|
| 103 |
+
nameOrChannels: string | TracingChannelCollection<StoreType, ContextType>,
|
| 104 |
+
): TracingChannel<StoreType, ContextType>;
|
| 105 |
+
/**
|
| 106 |
+
* The class `Channel` represents an individual named channel within the data
|
| 107 |
+
* pipeline. It is used to track subscribers and to publish messages when there
|
| 108 |
+
* are subscribers present. It exists as a separate object to avoid channel
|
| 109 |
+
* lookups at publish time, enabling very fast publish speeds and allowing
|
| 110 |
+
* for heavy use while incurring very minimal cost. Channels are created with {@link channel}, constructing a channel directly
|
| 111 |
+
* with `new Channel(name)` is not supported.
|
| 112 |
+
* @since v15.1.0, v14.17.0
|
| 113 |
+
*/
|
| 114 |
+
class Channel<StoreType = unknown, ContextType = StoreType> {
|
| 115 |
+
readonly name: string | symbol;
|
| 116 |
+
/**
|
| 117 |
+
* Check if there are active subscribers to this channel. This is helpful if
|
| 118 |
+
* the message you want to send might be expensive to prepare.
|
| 119 |
+
*
|
| 120 |
+
* This API is optional but helpful when trying to publish messages from very
|
| 121 |
+
* performance-sensitive code.
|
| 122 |
+
*
|
| 123 |
+
* ```js
|
| 124 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 125 |
+
*
|
| 126 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
| 127 |
+
*
|
| 128 |
+
* if (channel.hasSubscribers) {
|
| 129 |
+
* // There are subscribers, prepare and publish message
|
| 130 |
+
* }
|
| 131 |
+
* ```
|
| 132 |
+
* @since v15.1.0, v14.17.0
|
| 133 |
+
*/
|
| 134 |
+
readonly hasSubscribers: boolean;
|
| 135 |
+
private constructor(name: string | symbol);
|
| 136 |
+
/**
|
| 137 |
+
* Publish a message to any subscribers to the channel. This will trigger
|
| 138 |
+
* message handlers synchronously so they will execute within the same context.
|
| 139 |
+
*
|
| 140 |
+
* ```js
|
| 141 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 142 |
+
*
|
| 143 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
| 144 |
+
*
|
| 145 |
+
* channel.publish({
|
| 146 |
+
* some: 'message',
|
| 147 |
+
* });
|
| 148 |
+
* ```
|
| 149 |
+
* @since v15.1.0, v14.17.0
|
| 150 |
+
* @param message The message to send to the channel subscribers
|
| 151 |
+
*/
|
| 152 |
+
publish(message: unknown): void;
|
| 153 |
+
/**
|
| 154 |
+
* Register a message handler to subscribe to this channel. This message handler
|
| 155 |
+
* will be run synchronously whenever a message is published to the channel. Any
|
| 156 |
+
* errors thrown in the message handler will trigger an `'uncaughtException'`.
|
| 157 |
+
*
|
| 158 |
+
* ```js
|
| 159 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 160 |
+
*
|
| 161 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
| 162 |
+
*
|
| 163 |
+
* channel.subscribe((message, name) => {
|
| 164 |
+
* // Received data
|
| 165 |
+
* });
|
| 166 |
+
* ```
|
| 167 |
+
* @since v15.1.0, v14.17.0
|
| 168 |
+
* @param onMessage The handler to receive channel messages
|
| 169 |
+
*/
|
| 170 |
+
subscribe(onMessage: ChannelListener): void;
|
| 171 |
+
/**
|
| 172 |
+
* Remove a message handler previously registered to this channel with `channel.subscribe(onMessage)`.
|
| 173 |
+
*
|
| 174 |
+
* ```js
|
| 175 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 176 |
+
*
|
| 177 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
| 178 |
+
*
|
| 179 |
+
* function onMessage(message, name) {
|
| 180 |
+
* // Received data
|
| 181 |
+
* }
|
| 182 |
+
*
|
| 183 |
+
* channel.subscribe(onMessage);
|
| 184 |
+
*
|
| 185 |
+
* channel.unsubscribe(onMessage);
|
| 186 |
+
* ```
|
| 187 |
+
* @since v15.1.0, v14.17.0
|
| 188 |
+
* @param onMessage The previous subscribed handler to remove
|
| 189 |
+
* @return `true` if the handler was found, `false` otherwise.
|
| 190 |
+
*/
|
| 191 |
+
unsubscribe(onMessage: ChannelListener): void;
|
| 192 |
+
/**
|
| 193 |
+
* When `channel.runStores(context, ...)` is called, the given context data
|
| 194 |
+
* will be applied to any store bound to the channel. If the store has already been
|
| 195 |
+
* bound the previous `transform` function will be replaced with the new one.
|
| 196 |
+
* The `transform` function may be omitted to set the given context data as the
|
| 197 |
+
* context directly.
|
| 198 |
+
*
|
| 199 |
+
* ```js
|
| 200 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 201 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
| 202 |
+
*
|
| 203 |
+
* const store = new AsyncLocalStorage();
|
| 204 |
+
*
|
| 205 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
| 206 |
+
*
|
| 207 |
+
* channel.bindStore(store, (data) => {
|
| 208 |
+
* return { data };
|
| 209 |
+
* });
|
| 210 |
+
* ```
|
| 211 |
+
* @since v19.9.0
|
| 212 |
+
* @experimental
|
| 213 |
+
* @param store The store to which to bind the context data
|
| 214 |
+
* @param transform Transform context data before setting the store context
|
| 215 |
+
*/
|
| 216 |
+
bindStore(store: AsyncLocalStorage<StoreType>, transform?: (context: ContextType) => StoreType): void;
|
| 217 |
+
/**
|
| 218 |
+
* Remove a message handler previously registered to this channel with `channel.bindStore(store)`.
|
| 219 |
+
*
|
| 220 |
+
* ```js
|
| 221 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 222 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
| 223 |
+
*
|
| 224 |
+
* const store = new AsyncLocalStorage();
|
| 225 |
+
*
|
| 226 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
| 227 |
+
*
|
| 228 |
+
* channel.bindStore(store);
|
| 229 |
+
* channel.unbindStore(store);
|
| 230 |
+
* ```
|
| 231 |
+
* @since v19.9.0
|
| 232 |
+
* @experimental
|
| 233 |
+
* @param store The store to unbind from the channel.
|
| 234 |
+
* @return `true` if the store was found, `false` otherwise.
|
| 235 |
+
*/
|
| 236 |
+
unbindStore(store: AsyncLocalStorage<StoreType>): boolean;
|
| 237 |
+
/**
|
| 238 |
+
* Applies the given data to any AsyncLocalStorage instances bound to the channel
|
| 239 |
+
* for the duration of the given function, then publishes to the channel within
|
| 240 |
+
* the scope of that data is applied to the stores.
|
| 241 |
+
*
|
| 242 |
+
* If a transform function was given to `channel.bindStore(store)` it will be
|
| 243 |
+
* applied to transform the message data before it becomes the context value for
|
| 244 |
+
* the store. The prior storage context is accessible from within the transform
|
| 245 |
+
* function in cases where context linking is required.
|
| 246 |
+
*
|
| 247 |
+
* The context applied to the store should be accessible in any async code which
|
| 248 |
+
* continues from execution which began during the given function, however
|
| 249 |
+
* there are some situations in which `context loss` may occur.
|
| 250 |
+
*
|
| 251 |
+
* ```js
|
| 252 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 253 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
| 254 |
+
*
|
| 255 |
+
* const store = new AsyncLocalStorage();
|
| 256 |
+
*
|
| 257 |
+
* const channel = diagnostics_channel.channel('my-channel');
|
| 258 |
+
*
|
| 259 |
+
* channel.bindStore(store, (message) => {
|
| 260 |
+
* const parent = store.getStore();
|
| 261 |
+
* return new Span(message, parent);
|
| 262 |
+
* });
|
| 263 |
+
* channel.runStores({ some: 'message' }, () => {
|
| 264 |
+
* store.getStore(); // Span({ some: 'message' })
|
| 265 |
+
* });
|
| 266 |
+
* ```
|
| 267 |
+
* @since v19.9.0
|
| 268 |
+
* @experimental
|
| 269 |
+
* @param context Message to send to subscribers and bind to stores
|
| 270 |
+
* @param fn Handler to run within the entered storage context
|
| 271 |
+
* @param thisArg The receiver to be used for the function call.
|
| 272 |
+
* @param args Optional arguments to pass to the function.
|
| 273 |
+
*/
|
| 274 |
+
runStores<ThisArg = any, Args extends any[] = any[], Result = any>(
|
| 275 |
+
context: ContextType,
|
| 276 |
+
fn: (this: ThisArg, ...args: Args) => Result,
|
| 277 |
+
thisArg?: ThisArg,
|
| 278 |
+
...args: Args
|
| 279 |
+
): Result;
|
| 280 |
+
}
|
| 281 |
+
interface TracingChannelSubscribers<ContextType extends object> {
|
| 282 |
+
start: (message: ContextType) => void;
|
| 283 |
+
end: (
|
| 284 |
+
message: ContextType & {
|
| 285 |
+
error?: unknown;
|
| 286 |
+
result?: unknown;
|
| 287 |
+
},
|
| 288 |
+
) => void;
|
| 289 |
+
asyncStart: (
|
| 290 |
+
message: ContextType & {
|
| 291 |
+
error?: unknown;
|
| 292 |
+
result?: unknown;
|
| 293 |
+
},
|
| 294 |
+
) => void;
|
| 295 |
+
asyncEnd: (
|
| 296 |
+
message: ContextType & {
|
| 297 |
+
error?: unknown;
|
| 298 |
+
result?: unknown;
|
| 299 |
+
},
|
| 300 |
+
) => void;
|
| 301 |
+
error: (
|
| 302 |
+
message: ContextType & {
|
| 303 |
+
error: unknown;
|
| 304 |
+
},
|
| 305 |
+
) => void;
|
| 306 |
+
}
|
| 307 |
+
interface TracingChannelCollection<StoreType = unknown, ContextType = StoreType> {
|
| 308 |
+
start: Channel<StoreType, ContextType>;
|
| 309 |
+
end: Channel<StoreType, ContextType>;
|
| 310 |
+
asyncStart: Channel<StoreType, ContextType>;
|
| 311 |
+
asyncEnd: Channel<StoreType, ContextType>;
|
| 312 |
+
error: Channel<StoreType, ContextType>;
|
| 313 |
+
}
|
| 314 |
+
/**
|
| 315 |
+
* The class `TracingChannel` is a collection of `TracingChannel Channels` which
|
| 316 |
+
* together express a single traceable action. It is used to formalize and
|
| 317 |
+
* 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
|
| 318 |
+
* single `TracingChannel` at the top-level of the file rather than creating them
|
| 319 |
+
* dynamically.
|
| 320 |
+
* @since v19.9.0
|
| 321 |
+
* @experimental
|
| 322 |
+
*/
|
| 323 |
+
class TracingChannel<StoreType = unknown, ContextType extends object = {}> implements TracingChannelCollection {
|
| 324 |
+
start: Channel<StoreType, ContextType>;
|
| 325 |
+
end: Channel<StoreType, ContextType>;
|
| 326 |
+
asyncStart: Channel<StoreType, ContextType>;
|
| 327 |
+
asyncEnd: Channel<StoreType, ContextType>;
|
| 328 |
+
error: Channel<StoreType, ContextType>;
|
| 329 |
+
/**
|
| 330 |
+
* Helper to subscribe a collection of functions to the corresponding channels.
|
| 331 |
+
* This is the same as calling `channel.subscribe(onMessage)` on each channel
|
| 332 |
+
* individually.
|
| 333 |
+
*
|
| 334 |
+
* ```js
|
| 335 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 336 |
+
*
|
| 337 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
| 338 |
+
*
|
| 339 |
+
* channels.subscribe({
|
| 340 |
+
* start(message) {
|
| 341 |
+
* // Handle start message
|
| 342 |
+
* },
|
| 343 |
+
* end(message) {
|
| 344 |
+
* // Handle end message
|
| 345 |
+
* },
|
| 346 |
+
* asyncStart(message) {
|
| 347 |
+
* // Handle asyncStart message
|
| 348 |
+
* },
|
| 349 |
+
* asyncEnd(message) {
|
| 350 |
+
* // Handle asyncEnd message
|
| 351 |
+
* },
|
| 352 |
+
* error(message) {
|
| 353 |
+
* // Handle error message
|
| 354 |
+
* },
|
| 355 |
+
* });
|
| 356 |
+
* ```
|
| 357 |
+
* @since v19.9.0
|
| 358 |
+
* @experimental
|
| 359 |
+
* @param subscribers Set of `TracingChannel Channels` subscribers
|
| 360 |
+
*/
|
| 361 |
+
subscribe(subscribers: TracingChannelSubscribers<ContextType>): void;
|
| 362 |
+
/**
|
| 363 |
+
* Helper to unsubscribe a collection of functions from the corresponding channels.
|
| 364 |
+
* This is the same as calling `channel.unsubscribe(onMessage)` on each channel
|
| 365 |
+
* individually.
|
| 366 |
+
*
|
| 367 |
+
* ```js
|
| 368 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 369 |
+
*
|
| 370 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
| 371 |
+
*
|
| 372 |
+
* channels.unsubscribe({
|
| 373 |
+
* start(message) {
|
| 374 |
+
* // Handle start message
|
| 375 |
+
* },
|
| 376 |
+
* end(message) {
|
| 377 |
+
* // Handle end message
|
| 378 |
+
* },
|
| 379 |
+
* asyncStart(message) {
|
| 380 |
+
* // Handle asyncStart message
|
| 381 |
+
* },
|
| 382 |
+
* asyncEnd(message) {
|
| 383 |
+
* // Handle asyncEnd message
|
| 384 |
+
* },
|
| 385 |
+
* error(message) {
|
| 386 |
+
* // Handle error message
|
| 387 |
+
* },
|
| 388 |
+
* });
|
| 389 |
+
* ```
|
| 390 |
+
* @since v19.9.0
|
| 391 |
+
* @experimental
|
| 392 |
+
* @param subscribers Set of `TracingChannel Channels` subscribers
|
| 393 |
+
* @return `true` if all handlers were successfully unsubscribed, and `false` otherwise.
|
| 394 |
+
*/
|
| 395 |
+
unsubscribe(subscribers: TracingChannelSubscribers<ContextType>): void;
|
| 396 |
+
/**
|
| 397 |
+
* 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.
|
| 398 |
+
* This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all
|
| 399 |
+
* events should have any bound stores set to match this trace context.
|
| 400 |
+
*
|
| 401 |
+
* To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions
|
| 402 |
+
* which are added after the trace begins will not receive future events from that trace, only future traces will be seen.
|
| 403 |
+
*
|
| 404 |
+
* ```js
|
| 405 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 406 |
+
*
|
| 407 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
| 408 |
+
*
|
| 409 |
+
* channels.traceSync(() => {
|
| 410 |
+
* // Do something
|
| 411 |
+
* }, {
|
| 412 |
+
* some: 'thing',
|
| 413 |
+
* });
|
| 414 |
+
* ```
|
| 415 |
+
* @since v19.9.0
|
| 416 |
+
* @experimental
|
| 417 |
+
* @param fn Function to wrap a trace around
|
| 418 |
+
* @param context Shared object to correlate events through
|
| 419 |
+
* @param thisArg The receiver to be used for the function call
|
| 420 |
+
* @param args Optional arguments to pass to the function
|
| 421 |
+
* @return The return value of the given function
|
| 422 |
+
*/
|
| 423 |
+
traceSync<ThisArg = any, Args extends any[] = any[], Result = any>(
|
| 424 |
+
fn: (this: ThisArg, ...args: Args) => Result,
|
| 425 |
+
context?: ContextType,
|
| 426 |
+
thisArg?: ThisArg,
|
| 427 |
+
...args: Args
|
| 428 |
+
): Result;
|
| 429 |
+
/**
|
| 430 |
+
* Trace a promise-returning function call. This will always produce a `start event` and `end event` around the synchronous portion of the
|
| 431 |
+
* function execution, and will produce an `asyncStart event` and `asyncEnd event` when a promise continuation is reached. It may also
|
| 432 |
+
* produce an `error event` if the given function throws an error or the
|
| 433 |
+
* returned promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all
|
| 434 |
+
* events should have any bound stores set to match this trace context.
|
| 435 |
+
*
|
| 436 |
+
* To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions
|
| 437 |
+
* which are added after the trace begins will not receive future events from that trace, only future traces will be seen.
|
| 438 |
+
*
|
| 439 |
+
* ```js
|
| 440 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 441 |
+
*
|
| 442 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
| 443 |
+
*
|
| 444 |
+
* channels.tracePromise(async () => {
|
| 445 |
+
* // Do something
|
| 446 |
+
* }, {
|
| 447 |
+
* some: 'thing',
|
| 448 |
+
* });
|
| 449 |
+
* ```
|
| 450 |
+
* @since v19.9.0
|
| 451 |
+
* @experimental
|
| 452 |
+
* @param fn Promise-returning function to wrap a trace around
|
| 453 |
+
* @param context Shared object to correlate trace events through
|
| 454 |
+
* @param thisArg The receiver to be used for the function call
|
| 455 |
+
* @param args Optional arguments to pass to the function
|
| 456 |
+
* @return Chained from promise returned by the given function
|
| 457 |
+
*/
|
| 458 |
+
tracePromise<ThisArg = any, Args extends any[] = any[], Result = any>(
|
| 459 |
+
fn: (this: ThisArg, ...args: Args) => Promise<Result>,
|
| 460 |
+
context?: ContextType,
|
| 461 |
+
thisArg?: ThisArg,
|
| 462 |
+
...args: Args
|
| 463 |
+
): Promise<Result>;
|
| 464 |
+
/**
|
| 465 |
+
* Trace a callback-receiving function call. This will always produce a `start event` and `end event` around the synchronous portion of the
|
| 466 |
+
* 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
|
| 467 |
+
* the returned
|
| 468 |
+
* promise rejects. This will run the given function using `channel.runStores(context, ...)` on the `start` channel which ensures all
|
| 469 |
+
* events should have any bound stores set to match this trace context.
|
| 470 |
+
*
|
| 471 |
+
* The `position` will be -1 by default to indicate the final argument should
|
| 472 |
+
* be used as the callback.
|
| 473 |
+
*
|
| 474 |
+
* ```js
|
| 475 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 476 |
+
*
|
| 477 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
| 478 |
+
*
|
| 479 |
+
* channels.traceCallback((arg1, callback) => {
|
| 480 |
+
* // Do something
|
| 481 |
+
* callback(null, 'result');
|
| 482 |
+
* }, 1, {
|
| 483 |
+
* some: 'thing',
|
| 484 |
+
* }, thisArg, arg1, callback);
|
| 485 |
+
* ```
|
| 486 |
+
*
|
| 487 |
+
* The callback will also be run with `channel.runStores(context, ...)` which
|
| 488 |
+
* enables context loss recovery in some cases.
|
| 489 |
+
*
|
| 490 |
+
* To ensure only correct trace graphs are formed, events will only be published if subscribers are present prior to starting the trace. Subscriptions
|
| 491 |
+
* which are added after the trace begins will not receive future events from that trace, only future traces will be seen.
|
| 492 |
+
*
|
| 493 |
+
* ```js
|
| 494 |
+
* import diagnostics_channel from 'node:diagnostics_channel';
|
| 495 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
| 496 |
+
*
|
| 497 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
| 498 |
+
* const myStore = new AsyncLocalStorage();
|
| 499 |
+
*
|
| 500 |
+
* // The start channel sets the initial store data to something
|
| 501 |
+
* // and stores that store data value on the trace context object
|
| 502 |
+
* channels.start.bindStore(myStore, (data) => {
|
| 503 |
+
* const span = new Span(data);
|
| 504 |
+
* data.span = span;
|
| 505 |
+
* return span;
|
| 506 |
+
* });
|
| 507 |
+
*
|
| 508 |
+
* // Then asyncStart can restore from that data it stored previously
|
| 509 |
+
* channels.asyncStart.bindStore(myStore, (data) => {
|
| 510 |
+
* return data.span;
|
| 511 |
+
* });
|
| 512 |
+
* ```
|
| 513 |
+
* @since v19.9.0
|
| 514 |
+
* @experimental
|
| 515 |
+
* @param fn callback using function to wrap a trace around
|
| 516 |
+
* @param position Zero-indexed argument position of expected callback
|
| 517 |
+
* @param context Shared object to correlate trace events through
|
| 518 |
+
* @param thisArg The receiver to be used for the function call
|
| 519 |
+
* @param args Optional arguments to pass to the function
|
| 520 |
+
* @return The return value of the given function
|
| 521 |
+
*/
|
| 522 |
+
traceCallback<ThisArg = any, Args extends any[] = any[], Result = any>(
|
| 523 |
+
fn: (this: ThisArg, ...args: Args) => Result,
|
| 524 |
+
position?: number,
|
| 525 |
+
context?: ContextType,
|
| 526 |
+
thisArg?: ThisArg,
|
| 527 |
+
...args: Args
|
| 528 |
+
): Result;
|
| 529 |
+
/**
|
| 530 |
+
* `true` if any of the individual channels has a subscriber, `false` if not.
|
| 531 |
+
*
|
| 532 |
+
* This is a helper method available on a {@link TracingChannel} instance to check
|
| 533 |
+
* if any of the [TracingChannel Channels](https://nodejs.org/api/diagnostics_channel.html#tracingchannel-channels) have subscribers.
|
| 534 |
+
* A `true` is returned if any of them have at least one subscriber, a `false` is returned otherwise.
|
| 535 |
+
*
|
| 536 |
+
* ```js
|
| 537 |
+
* const diagnostics_channel = require('node:diagnostics_channel');
|
| 538 |
+
*
|
| 539 |
+
* const channels = diagnostics_channel.tracingChannel('my-channel');
|
| 540 |
+
*
|
| 541 |
+
* if (channels.hasSubscribers) {
|
| 542 |
+
* // Do something
|
| 543 |
+
* }
|
| 544 |
+
* ```
|
| 545 |
+
* @since v22.0.0, v20.13.0
|
| 546 |
+
*/
|
| 547 |
+
readonly hasSubscribers: boolean;
|
| 548 |
+
}
|
| 549 |
+
}
|
| 550 |
+
declare module "diagnostics_channel" {
|
| 551 |
+
export * from "node:diagnostics_channel";
|
| 552 |
+
}
|
node_modules/@types/node/dns.d.ts
ADDED
|
@@ -0,0 +1,876 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:dns" {
|
| 2 |
+
// Supported getaddrinfo flags.
|
| 3 |
+
/**
|
| 4 |
+
* Limits returned address types to the types of non-loopback addresses configured on the system. For example, IPv4 addresses are
|
| 5 |
+
* only returned if the current system has at least one IPv4 address configured.
|
| 6 |
+
*/
|
| 7 |
+
const ADDRCONFIG: number;
|
| 8 |
+
/**
|
| 9 |
+
* If the IPv6 family was specified, but no IPv6 addresses were found, then return IPv4 mapped IPv6 addresses. It is not supported
|
| 10 |
+
* on some operating systems (e.g. FreeBSD 10.1).
|
| 11 |
+
*/
|
| 12 |
+
const V4MAPPED: number;
|
| 13 |
+
/**
|
| 14 |
+
* If `dns.V4MAPPED` is specified, return resolved IPv6 addresses as
|
| 15 |
+
* well as IPv4 mapped IPv6 addresses.
|
| 16 |
+
*/
|
| 17 |
+
const ALL: number;
|
| 18 |
+
interface LookupOptions {
|
| 19 |
+
/**
|
| 20 |
+
* The record family. Must be `4`, `6`, or `0`. For backward compatibility reasons, `'IPv4'` and `'IPv6'` are interpreted
|
| 21 |
+
* as `4` and `6` respectively. The value 0 indicates that either an IPv4 or IPv6 address is returned. If the value `0` is used
|
| 22 |
+
* with `{ all: true } (see below)`, both IPv4 and IPv6 addresses are returned.
|
| 23 |
+
* @default 0
|
| 24 |
+
*/
|
| 25 |
+
family?: number | "IPv4" | "IPv6" | undefined;
|
| 26 |
+
/**
|
| 27 |
+
* One or more [supported `getaddrinfo`](https://nodejs.org/docs/latest-v25.x/api/dns.html#supported-getaddrinfo-flags) flags. Multiple flags may be
|
| 28 |
+
* passed by bitwise `OR`ing their values.
|
| 29 |
+
*/
|
| 30 |
+
hints?: number | undefined;
|
| 31 |
+
/**
|
| 32 |
+
* When `true`, the callback returns all resolved addresses in an array. Otherwise, returns a single address.
|
| 33 |
+
* @default false
|
| 34 |
+
*/
|
| 35 |
+
all?: boolean | undefined;
|
| 36 |
+
/**
|
| 37 |
+
* When `verbatim`, the resolved addresses are return unsorted. When `ipv4first`, the resolved addresses are sorted
|
| 38 |
+
* by placing IPv4 addresses before IPv6 addresses. When `ipv6first`, the resolved addresses are sorted by placing IPv6
|
| 39 |
+
* addresses before IPv4 addresses. Default value is configurable using
|
| 40 |
+
* {@link setDefaultResultOrder} or [`--dns-result-order`](https://nodejs.org/docs/latest-v25.x/api/cli.html#--dns-result-orderorder).
|
| 41 |
+
* @default `verbatim` (addresses are not reordered)
|
| 42 |
+
* @since v22.1.0
|
| 43 |
+
*/
|
| 44 |
+
order?: "ipv4first" | "ipv6first" | "verbatim" | undefined;
|
| 45 |
+
/**
|
| 46 |
+
* When `true`, the callback receives IPv4 and IPv6 addresses in the order the DNS resolver returned them. When `false`, IPv4
|
| 47 |
+
* addresses are placed before IPv6 addresses. This option will be deprecated in favor of `order`. When both are specified,
|
| 48 |
+
* `order` has higher precedence. New code should only use `order`. Default value is configurable using {@link setDefaultResultOrder}
|
| 49 |
+
* @default true (addresses are not reordered)
|
| 50 |
+
* @deprecated Please use `order` option
|
| 51 |
+
*/
|
| 52 |
+
verbatim?: boolean | undefined;
|
| 53 |
+
}
|
| 54 |
+
interface LookupOneOptions extends LookupOptions {
|
| 55 |
+
all?: false | undefined;
|
| 56 |
+
}
|
| 57 |
+
interface LookupAllOptions extends LookupOptions {
|
| 58 |
+
all: true;
|
| 59 |
+
}
|
| 60 |
+
interface LookupAddress {
|
| 61 |
+
/**
|
| 62 |
+
* A string representation of an IPv4 or IPv6 address.
|
| 63 |
+
*/
|
| 64 |
+
address: string;
|
| 65 |
+
/**
|
| 66 |
+
* `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
|
| 67 |
+
* bug in the name resolution service used by the operating system.
|
| 68 |
+
*/
|
| 69 |
+
family: number;
|
| 70 |
+
}
|
| 71 |
+
/**
|
| 72 |
+
* Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
|
| 73 |
+
* AAAA (IPv6) record. All `option` properties are optional. If `options` is an
|
| 74 |
+
* integer, then it must be `4` or `6` – if `options` is `0` or not provided, then
|
| 75 |
+
* IPv4 and IPv6 addresses are both returned if found.
|
| 76 |
+
*
|
| 77 |
+
* With the `all` option set to `true`, the arguments for `callback` change to `(err, addresses)`, with `addresses` being an array of objects with the
|
| 78 |
+
* properties `address` and `family`.
|
| 79 |
+
*
|
| 80 |
+
* On error, `err` is an `Error` object, where `err.code` is the error code.
|
| 81 |
+
* Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
|
| 82 |
+
* the host name does not exist but also when the lookup fails in other ways
|
| 83 |
+
* such as no available file descriptors.
|
| 84 |
+
*
|
| 85 |
+
* `dns.lookup()` does not necessarily have anything to do with the DNS protocol.
|
| 86 |
+
* The implementation uses an operating system facility that can associate names
|
| 87 |
+
* with addresses and vice versa. This implementation can have subtle but
|
| 88 |
+
* important consequences on the behavior of any Node.js program. Please take some
|
| 89 |
+
* time to consult the [Implementation considerations section](https://nodejs.org/docs/latest-v25.x/api/dns.html#implementation-considerations)
|
| 90 |
+
* before using `dns.lookup()`.
|
| 91 |
+
*
|
| 92 |
+
* Example usage:
|
| 93 |
+
*
|
| 94 |
+
* ```js
|
| 95 |
+
* import dns from 'node:dns';
|
| 96 |
+
* const options = {
|
| 97 |
+
* family: 6,
|
| 98 |
+
* hints: dns.ADDRCONFIG | dns.V4MAPPED,
|
| 99 |
+
* };
|
| 100 |
+
* dns.lookup('example.com', options, (err, address, family) =>
|
| 101 |
+
* console.log('address: %j family: IPv%s', address, family));
|
| 102 |
+
* // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
|
| 103 |
+
*
|
| 104 |
+
* // When options.all is true, the result will be an Array.
|
| 105 |
+
* options.all = true;
|
| 106 |
+
* dns.lookup('example.com', options, (err, addresses) =>
|
| 107 |
+
* console.log('addresses: %j', addresses));
|
| 108 |
+
* // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
|
| 109 |
+
* ```
|
| 110 |
+
*
|
| 111 |
+
* If this method is invoked as its [util.promisify()](https://nodejs.org/docs/latest-v25.x/api/util.html#utilpromisifyoriginal) ed
|
| 112 |
+
* version, and `all` is not set to `true`, it returns a `Promise` for an `Object` with `address` and `family` properties.
|
| 113 |
+
* @since v0.1.90
|
| 114 |
+
*/
|
| 115 |
+
function lookup(
|
| 116 |
+
hostname: string,
|
| 117 |
+
family: number,
|
| 118 |
+
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
| 119 |
+
): void;
|
| 120 |
+
function lookup(
|
| 121 |
+
hostname: string,
|
| 122 |
+
options: LookupOneOptions,
|
| 123 |
+
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
| 124 |
+
): void;
|
| 125 |
+
function lookup(
|
| 126 |
+
hostname: string,
|
| 127 |
+
options: LookupAllOptions,
|
| 128 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: LookupAddress[]) => void,
|
| 129 |
+
): void;
|
| 130 |
+
function lookup(
|
| 131 |
+
hostname: string,
|
| 132 |
+
options: LookupOptions,
|
| 133 |
+
callback: (err: NodeJS.ErrnoException | null, address: string | LookupAddress[], family: number) => void,
|
| 134 |
+
): void;
|
| 135 |
+
function lookup(
|
| 136 |
+
hostname: string,
|
| 137 |
+
callback: (err: NodeJS.ErrnoException | null, address: string, family: number) => void,
|
| 138 |
+
): void;
|
| 139 |
+
namespace lookup {
|
| 140 |
+
function __promisify__(hostname: string, options: LookupAllOptions): Promise<LookupAddress[]>;
|
| 141 |
+
function __promisify__(hostname: string, options?: LookupOneOptions | number): Promise<LookupAddress>;
|
| 142 |
+
function __promisify__(hostname: string, options: LookupOptions): Promise<LookupAddress | LookupAddress[]>;
|
| 143 |
+
}
|
| 144 |
+
/**
|
| 145 |
+
* Resolves the given `address` and `port` into a host name and service using
|
| 146 |
+
* the operating system's underlying `getnameinfo` implementation.
|
| 147 |
+
*
|
| 148 |
+
* If `address` is not a valid IP address, a `TypeError` will be thrown.
|
| 149 |
+
* The `port` will be coerced to a number. If it is not a legal port, a `TypeError` will be thrown.
|
| 150 |
+
*
|
| 151 |
+
* On an error, `err` is an [`Error`](https://nodejs.org/docs/latest-v25.x/api/errors.html#class-error) object,
|
| 152 |
+
* where `err.code` is the error code.
|
| 153 |
+
*
|
| 154 |
+
* ```js
|
| 155 |
+
* import dns from 'node:dns';
|
| 156 |
+
* dns.lookupService('127.0.0.1', 22, (err, hostname, service) => {
|
| 157 |
+
* console.log(hostname, service);
|
| 158 |
+
* // Prints: localhost ssh
|
| 159 |
+
* });
|
| 160 |
+
* ```
|
| 161 |
+
*
|
| 162 |
+
* If this method is invoked as its [util.promisify()](https://nodejs.org/docs/latest-v25.x/api/util.html#utilpromisifyoriginal) ed
|
| 163 |
+
* version, it returns a `Promise` for an `Object` with `hostname` and `service` properties.
|
| 164 |
+
* @since v0.11.14
|
| 165 |
+
*/
|
| 166 |
+
function lookupService(
|
| 167 |
+
address: string,
|
| 168 |
+
port: number,
|
| 169 |
+
callback: (err: NodeJS.ErrnoException | null, hostname: string, service: string) => void,
|
| 170 |
+
): void;
|
| 171 |
+
namespace lookupService {
|
| 172 |
+
function __promisify__(
|
| 173 |
+
address: string,
|
| 174 |
+
port: number,
|
| 175 |
+
): Promise<{
|
| 176 |
+
hostname: string;
|
| 177 |
+
service: string;
|
| 178 |
+
}>;
|
| 179 |
+
}
|
| 180 |
+
interface ResolveOptions {
|
| 181 |
+
ttl: boolean;
|
| 182 |
+
}
|
| 183 |
+
interface ResolveWithTtlOptions extends ResolveOptions {
|
| 184 |
+
ttl: true;
|
| 185 |
+
}
|
| 186 |
+
interface RecordWithTtl {
|
| 187 |
+
address: string;
|
| 188 |
+
ttl: number;
|
| 189 |
+
}
|
| 190 |
+
interface AnyARecord extends RecordWithTtl {
|
| 191 |
+
type: "A";
|
| 192 |
+
}
|
| 193 |
+
interface AnyAaaaRecord extends RecordWithTtl {
|
| 194 |
+
type: "AAAA";
|
| 195 |
+
}
|
| 196 |
+
interface CaaRecord {
|
| 197 |
+
critical: number;
|
| 198 |
+
issue?: string | undefined;
|
| 199 |
+
issuewild?: string | undefined;
|
| 200 |
+
iodef?: string | undefined;
|
| 201 |
+
contactemail?: string | undefined;
|
| 202 |
+
contactphone?: string | undefined;
|
| 203 |
+
}
|
| 204 |
+
interface AnyCaaRecord extends CaaRecord {
|
| 205 |
+
type: "CAA";
|
| 206 |
+
}
|
| 207 |
+
interface MxRecord {
|
| 208 |
+
priority: number;
|
| 209 |
+
exchange: string;
|
| 210 |
+
}
|
| 211 |
+
interface AnyMxRecord extends MxRecord {
|
| 212 |
+
type: "MX";
|
| 213 |
+
}
|
| 214 |
+
interface NaptrRecord {
|
| 215 |
+
flags: string;
|
| 216 |
+
service: string;
|
| 217 |
+
regexp: string;
|
| 218 |
+
replacement: string;
|
| 219 |
+
order: number;
|
| 220 |
+
preference: number;
|
| 221 |
+
}
|
| 222 |
+
interface AnyNaptrRecord extends NaptrRecord {
|
| 223 |
+
type: "NAPTR";
|
| 224 |
+
}
|
| 225 |
+
interface SoaRecord {
|
| 226 |
+
nsname: string;
|
| 227 |
+
hostmaster: string;
|
| 228 |
+
serial: number;
|
| 229 |
+
refresh: number;
|
| 230 |
+
retry: number;
|
| 231 |
+
expire: number;
|
| 232 |
+
minttl: number;
|
| 233 |
+
}
|
| 234 |
+
interface AnySoaRecord extends SoaRecord {
|
| 235 |
+
type: "SOA";
|
| 236 |
+
}
|
| 237 |
+
interface SrvRecord {
|
| 238 |
+
priority: number;
|
| 239 |
+
weight: number;
|
| 240 |
+
port: number;
|
| 241 |
+
name: string;
|
| 242 |
+
}
|
| 243 |
+
interface AnySrvRecord extends SrvRecord {
|
| 244 |
+
type: "SRV";
|
| 245 |
+
}
|
| 246 |
+
interface TlsaRecord {
|
| 247 |
+
certUsage: number;
|
| 248 |
+
selector: number;
|
| 249 |
+
match: number;
|
| 250 |
+
data: ArrayBuffer;
|
| 251 |
+
}
|
| 252 |
+
interface AnyTlsaRecord extends TlsaRecord {
|
| 253 |
+
type: "TLSA";
|
| 254 |
+
}
|
| 255 |
+
interface AnyTxtRecord {
|
| 256 |
+
type: "TXT";
|
| 257 |
+
entries: string[];
|
| 258 |
+
}
|
| 259 |
+
interface AnyNsRecord {
|
| 260 |
+
type: "NS";
|
| 261 |
+
value: string;
|
| 262 |
+
}
|
| 263 |
+
interface AnyPtrRecord {
|
| 264 |
+
type: "PTR";
|
| 265 |
+
value: string;
|
| 266 |
+
}
|
| 267 |
+
interface AnyCnameRecord {
|
| 268 |
+
type: "CNAME";
|
| 269 |
+
value: string;
|
| 270 |
+
}
|
| 271 |
+
type AnyRecord =
|
| 272 |
+
| AnyARecord
|
| 273 |
+
| AnyAaaaRecord
|
| 274 |
+
| AnyCaaRecord
|
| 275 |
+
| AnyCnameRecord
|
| 276 |
+
| AnyMxRecord
|
| 277 |
+
| AnyNaptrRecord
|
| 278 |
+
| AnyNsRecord
|
| 279 |
+
| AnyPtrRecord
|
| 280 |
+
| AnySoaRecord
|
| 281 |
+
| AnySrvRecord
|
| 282 |
+
| AnyTlsaRecord
|
| 283 |
+
| AnyTxtRecord;
|
| 284 |
+
/**
|
| 285 |
+
* Uses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array
|
| 286 |
+
* of the resource records. The `callback` function has arguments `(err, records)`. When successful, `records` will be an array of resource
|
| 287 |
+
* records. The type and structure of individual results varies based on `rrtype`:
|
| 288 |
+
*
|
| 289 |
+
* <omitted>
|
| 290 |
+
*
|
| 291 |
+
* On error, `err` is an [`Error`](https://nodejs.org/docs/latest-v25.x/api/errors.html#class-error) object,
|
| 292 |
+
* where `err.code` is one of the `DNS error codes`.
|
| 293 |
+
* @since v0.1.27
|
| 294 |
+
* @param hostname Host name to resolve.
|
| 295 |
+
* @param [rrtype='A'] Resource record type.
|
| 296 |
+
*/
|
| 297 |
+
function resolve(
|
| 298 |
+
hostname: string,
|
| 299 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
| 300 |
+
): void;
|
| 301 |
+
function resolve(
|
| 302 |
+
hostname: string,
|
| 303 |
+
rrtype: "A" | "AAAA" | "CNAME" | "NS" | "PTR",
|
| 304 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
| 305 |
+
): void;
|
| 306 |
+
function resolve(
|
| 307 |
+
hostname: string,
|
| 308 |
+
rrtype: "ANY",
|
| 309 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: AnyRecord[]) => void,
|
| 310 |
+
): void;
|
| 311 |
+
function resolve(
|
| 312 |
+
hostname: string,
|
| 313 |
+
rrtype: "CAA",
|
| 314 |
+
callback: (err: NodeJS.ErrnoException | null, address: CaaRecord[]) => void,
|
| 315 |
+
): void;
|
| 316 |
+
function resolve(
|
| 317 |
+
hostname: string,
|
| 318 |
+
rrtype: "MX",
|
| 319 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: MxRecord[]) => void,
|
| 320 |
+
): void;
|
| 321 |
+
function resolve(
|
| 322 |
+
hostname: string,
|
| 323 |
+
rrtype: "NAPTR",
|
| 324 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: NaptrRecord[]) => void,
|
| 325 |
+
): void;
|
| 326 |
+
function resolve(
|
| 327 |
+
hostname: string,
|
| 328 |
+
rrtype: "SOA",
|
| 329 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: SoaRecord) => void,
|
| 330 |
+
): void;
|
| 331 |
+
function resolve(
|
| 332 |
+
hostname: string,
|
| 333 |
+
rrtype: "SRV",
|
| 334 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: SrvRecord[]) => void,
|
| 335 |
+
): void;
|
| 336 |
+
function resolve(
|
| 337 |
+
hostname: string,
|
| 338 |
+
rrtype: "TLSA",
|
| 339 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: TlsaRecord[]) => void,
|
| 340 |
+
): void;
|
| 341 |
+
function resolve(
|
| 342 |
+
hostname: string,
|
| 343 |
+
rrtype: "TXT",
|
| 344 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[][]) => void,
|
| 345 |
+
): void;
|
| 346 |
+
function resolve(
|
| 347 |
+
hostname: string,
|
| 348 |
+
rrtype: string,
|
| 349 |
+
callback: (
|
| 350 |
+
err: NodeJS.ErrnoException | null,
|
| 351 |
+
addresses:
|
| 352 |
+
| string[]
|
| 353 |
+
| CaaRecord[]
|
| 354 |
+
| MxRecord[]
|
| 355 |
+
| NaptrRecord[]
|
| 356 |
+
| SoaRecord
|
| 357 |
+
| SrvRecord[]
|
| 358 |
+
| TlsaRecord[]
|
| 359 |
+
| string[][]
|
| 360 |
+
| AnyRecord[],
|
| 361 |
+
) => void,
|
| 362 |
+
): void;
|
| 363 |
+
namespace resolve {
|
| 364 |
+
function __promisify__(hostname: string, rrtype?: "A" | "AAAA" | "CNAME" | "NS" | "PTR"): Promise<string[]>;
|
| 365 |
+
function __promisify__(hostname: string, rrtype: "ANY"): Promise<AnyRecord[]>;
|
| 366 |
+
function __promisify__(hostname: string, rrtype: "CAA"): Promise<CaaRecord[]>;
|
| 367 |
+
function __promisify__(hostname: string, rrtype: "MX"): Promise<MxRecord[]>;
|
| 368 |
+
function __promisify__(hostname: string, rrtype: "NAPTR"): Promise<NaptrRecord[]>;
|
| 369 |
+
function __promisify__(hostname: string, rrtype: "SOA"): Promise<SoaRecord>;
|
| 370 |
+
function __promisify__(hostname: string, rrtype: "SRV"): Promise<SrvRecord[]>;
|
| 371 |
+
function __promisify__(hostname: string, rrtype: "TLSA"): Promise<TlsaRecord[]>;
|
| 372 |
+
function __promisify__(hostname: string, rrtype: "TXT"): Promise<string[][]>;
|
| 373 |
+
function __promisify__(
|
| 374 |
+
hostname: string,
|
| 375 |
+
rrtype: string,
|
| 376 |
+
): Promise<
|
| 377 |
+
| string[]
|
| 378 |
+
| CaaRecord[]
|
| 379 |
+
| MxRecord[]
|
| 380 |
+
| NaptrRecord[]
|
| 381 |
+
| SoaRecord
|
| 382 |
+
| SrvRecord[]
|
| 383 |
+
| TlsaRecord[]
|
| 384 |
+
| string[][]
|
| 385 |
+
| AnyRecord[]
|
| 386 |
+
>;
|
| 387 |
+
}
|
| 388 |
+
/**
|
| 389 |
+
* Uses the DNS protocol to resolve a IPv4 addresses (`A` records) for the `hostname`. The `addresses` argument passed to the `callback` function
|
| 390 |
+
* will contain an array of IPv4 addresses (e.g.`['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
|
| 391 |
+
* @since v0.1.16
|
| 392 |
+
* @param hostname Host name to resolve.
|
| 393 |
+
*/
|
| 394 |
+
function resolve4(
|
| 395 |
+
hostname: string,
|
| 396 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
| 397 |
+
): void;
|
| 398 |
+
function resolve4(
|
| 399 |
+
hostname: string,
|
| 400 |
+
options: ResolveWithTtlOptions,
|
| 401 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: RecordWithTtl[]) => void,
|
| 402 |
+
): void;
|
| 403 |
+
function resolve4(
|
| 404 |
+
hostname: string,
|
| 405 |
+
options: ResolveOptions,
|
| 406 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[] | RecordWithTtl[]) => void,
|
| 407 |
+
): void;
|
| 408 |
+
namespace resolve4 {
|
| 409 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
| 410 |
+
function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
|
| 411 |
+
function __promisify__(hostname: string, options?: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
|
| 412 |
+
}
|
| 413 |
+
/**
|
| 414 |
+
* Uses the DNS protocol to resolve IPv6 addresses (`AAAA` records) for the `hostname`. The `addresses` argument passed to the `callback` function
|
| 415 |
+
* will contain an array of IPv6 addresses.
|
| 416 |
+
* @since v0.1.16
|
| 417 |
+
* @param hostname Host name to resolve.
|
| 418 |
+
*/
|
| 419 |
+
function resolve6(
|
| 420 |
+
hostname: string,
|
| 421 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
| 422 |
+
): void;
|
| 423 |
+
function resolve6(
|
| 424 |
+
hostname: string,
|
| 425 |
+
options: ResolveWithTtlOptions,
|
| 426 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: RecordWithTtl[]) => void,
|
| 427 |
+
): void;
|
| 428 |
+
function resolve6(
|
| 429 |
+
hostname: string,
|
| 430 |
+
options: ResolveOptions,
|
| 431 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[] | RecordWithTtl[]) => void,
|
| 432 |
+
): void;
|
| 433 |
+
namespace resolve6 {
|
| 434 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
| 435 |
+
function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
|
| 436 |
+
function __promisify__(hostname: string, options?: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
|
| 437 |
+
}
|
| 438 |
+
/**
|
| 439 |
+
* Uses the DNS protocol to resolve `CNAME` records for the `hostname`. The `addresses` argument passed to the `callback` function
|
| 440 |
+
* will contain an array of canonical name records available for the `hostname` (e.g. `['bar.example.com']`).
|
| 441 |
+
* @since v0.3.2
|
| 442 |
+
*/
|
| 443 |
+
function resolveCname(
|
| 444 |
+
hostname: string,
|
| 445 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
| 446 |
+
): void;
|
| 447 |
+
namespace resolveCname {
|
| 448 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
| 449 |
+
}
|
| 450 |
+
/**
|
| 451 |
+
* Uses the DNS protocol to resolve `CAA` records for the `hostname`. The `addresses` argument passed to the `callback` function
|
| 452 |
+
* will contain an array of certification authority authorization records
|
| 453 |
+
* available for the `hostname` (e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'}, {critical: 128, issue: 'pki.example.com'}]`).
|
| 454 |
+
* @since v15.0.0, v14.17.0
|
| 455 |
+
*/
|
| 456 |
+
function resolveCaa(
|
| 457 |
+
hostname: string,
|
| 458 |
+
callback: (err: NodeJS.ErrnoException | null, records: CaaRecord[]) => void,
|
| 459 |
+
): void;
|
| 460 |
+
namespace resolveCaa {
|
| 461 |
+
function __promisify__(hostname: string): Promise<CaaRecord[]>;
|
| 462 |
+
}
|
| 463 |
+
/**
|
| 464 |
+
* Uses the DNS protocol to resolve mail exchange records (`MX` records) for the `hostname`. The `addresses` argument passed to the `callback` function will
|
| 465 |
+
* contain an array of objects containing both a `priority` and `exchange` property (e.g. `[{priority: 10, exchange: 'mx.example.com'}, ...]`).
|
| 466 |
+
* @since v0.1.27
|
| 467 |
+
*/
|
| 468 |
+
function resolveMx(
|
| 469 |
+
hostname: string,
|
| 470 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: MxRecord[]) => void,
|
| 471 |
+
): void;
|
| 472 |
+
namespace resolveMx {
|
| 473 |
+
function __promisify__(hostname: string): Promise<MxRecord[]>;
|
| 474 |
+
}
|
| 475 |
+
/**
|
| 476 |
+
* 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
|
| 477 |
+
* objects with the following properties:
|
| 478 |
+
*
|
| 479 |
+
* * `flags`
|
| 480 |
+
* * `service`
|
| 481 |
+
* * `regexp`
|
| 482 |
+
* * `replacement`
|
| 483 |
+
* * `order`
|
| 484 |
+
* * `preference`
|
| 485 |
+
*
|
| 486 |
+
* ```js
|
| 487 |
+
* {
|
| 488 |
+
* flags: 's',
|
| 489 |
+
* service: 'SIP+D2U',
|
| 490 |
+
* regexp: '',
|
| 491 |
+
* replacement: '_sip._udp.example.com',
|
| 492 |
+
* order: 30,
|
| 493 |
+
* preference: 100
|
| 494 |
+
* }
|
| 495 |
+
* ```
|
| 496 |
+
* @since v0.9.12
|
| 497 |
+
*/
|
| 498 |
+
function resolveNaptr(
|
| 499 |
+
hostname: string,
|
| 500 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: NaptrRecord[]) => void,
|
| 501 |
+
): void;
|
| 502 |
+
namespace resolveNaptr {
|
| 503 |
+
function __promisify__(hostname: string): Promise<NaptrRecord[]>;
|
| 504 |
+
}
|
| 505 |
+
/**
|
| 506 |
+
* Uses the DNS protocol to resolve name server records (`NS` records) for the `hostname`. The `addresses` argument passed to the `callback` function will
|
| 507 |
+
* contain an array of name server records available for `hostname` (e.g. `['ns1.example.com', 'ns2.example.com']`).
|
| 508 |
+
* @since v0.1.90
|
| 509 |
+
*/
|
| 510 |
+
function resolveNs(
|
| 511 |
+
hostname: string,
|
| 512 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
| 513 |
+
): void;
|
| 514 |
+
namespace resolveNs {
|
| 515 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
| 516 |
+
}
|
| 517 |
+
/**
|
| 518 |
+
* Uses the DNS protocol to resolve pointer records (`PTR` records) for the `hostname`. The `addresses` argument passed to the `callback` function will
|
| 519 |
+
* be an array of strings containing the reply records.
|
| 520 |
+
* @since v6.0.0
|
| 521 |
+
*/
|
| 522 |
+
function resolvePtr(
|
| 523 |
+
hostname: string,
|
| 524 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[]) => void,
|
| 525 |
+
): void;
|
| 526 |
+
namespace resolvePtr {
|
| 527 |
+
function __promisify__(hostname: string): Promise<string[]>;
|
| 528 |
+
}
|
| 529 |
+
/**
|
| 530 |
+
* Uses the DNS protocol to resolve a start of authority record (`SOA` record) for
|
| 531 |
+
* the `hostname`. The `address` argument passed to the `callback` function will
|
| 532 |
+
* be an object with the following properties:
|
| 533 |
+
*
|
| 534 |
+
* * `nsname`
|
| 535 |
+
* * `hostmaster`
|
| 536 |
+
* * `serial`
|
| 537 |
+
* * `refresh`
|
| 538 |
+
* * `retry`
|
| 539 |
+
* * `expire`
|
| 540 |
+
* * `minttl`
|
| 541 |
+
*
|
| 542 |
+
* ```js
|
| 543 |
+
* {
|
| 544 |
+
* nsname: 'ns.example.com',
|
| 545 |
+
* hostmaster: 'root.example.com',
|
| 546 |
+
* serial: 2013101809,
|
| 547 |
+
* refresh: 10000,
|
| 548 |
+
* retry: 2400,
|
| 549 |
+
* expire: 604800,
|
| 550 |
+
* minttl: 3600
|
| 551 |
+
* }
|
| 552 |
+
* ```
|
| 553 |
+
* @since v0.11.10
|
| 554 |
+
*/
|
| 555 |
+
function resolveSoa(
|
| 556 |
+
hostname: string,
|
| 557 |
+
callback: (err: NodeJS.ErrnoException | null, address: SoaRecord) => void,
|
| 558 |
+
): void;
|
| 559 |
+
namespace resolveSoa {
|
| 560 |
+
function __promisify__(hostname: string): Promise<SoaRecord>;
|
| 561 |
+
}
|
| 562 |
+
/**
|
| 563 |
+
* Uses the DNS protocol to resolve service records (`SRV` records) for the `hostname`. The `addresses` argument passed to the `callback` function will
|
| 564 |
+
* be an array of objects with the following properties:
|
| 565 |
+
*
|
| 566 |
+
* * `priority`
|
| 567 |
+
* * `weight`
|
| 568 |
+
* * `port`
|
| 569 |
+
* * `name`
|
| 570 |
+
*
|
| 571 |
+
* ```js
|
| 572 |
+
* {
|
| 573 |
+
* priority: 10,
|
| 574 |
+
* weight: 5,
|
| 575 |
+
* port: 21223,
|
| 576 |
+
* name: 'service.example.com'
|
| 577 |
+
* }
|
| 578 |
+
* ```
|
| 579 |
+
* @since v0.1.27
|
| 580 |
+
*/
|
| 581 |
+
function resolveSrv(
|
| 582 |
+
hostname: string,
|
| 583 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: SrvRecord[]) => void,
|
| 584 |
+
): void;
|
| 585 |
+
namespace resolveSrv {
|
| 586 |
+
function __promisify__(hostname: string): Promise<SrvRecord[]>;
|
| 587 |
+
}
|
| 588 |
+
/**
|
| 589 |
+
* Uses the DNS protocol to resolve certificate associations (`TLSA` records) for
|
| 590 |
+
* the `hostname`. The `records` argument passed to the `callback` function is an
|
| 591 |
+
* array of objects with these properties:
|
| 592 |
+
*
|
| 593 |
+
* * `certUsage`
|
| 594 |
+
* * `selector`
|
| 595 |
+
* * `match`
|
| 596 |
+
* * `data`
|
| 597 |
+
*
|
| 598 |
+
* ```js
|
| 599 |
+
* {
|
| 600 |
+
* certUsage: 3,
|
| 601 |
+
* selector: 1,
|
| 602 |
+
* match: 1,
|
| 603 |
+
* data: [ArrayBuffer]
|
| 604 |
+
* }
|
| 605 |
+
* ```
|
| 606 |
+
* @since v23.9.0, v22.15.0
|
| 607 |
+
*/
|
| 608 |
+
function resolveTlsa(
|
| 609 |
+
hostname: string,
|
| 610 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: TlsaRecord[]) => void,
|
| 611 |
+
): void;
|
| 612 |
+
namespace resolveTlsa {
|
| 613 |
+
function __promisify__(hostname: string): Promise<TlsaRecord[]>;
|
| 614 |
+
}
|
| 615 |
+
/**
|
| 616 |
+
* Uses the DNS protocol to resolve text queries (`TXT` records) for the `hostname`. The `records` argument passed to the `callback` function is a
|
| 617 |
+
* 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
|
| 618 |
+
* one record. Depending on the use case, these could be either joined together or
|
| 619 |
+
* treated separately.
|
| 620 |
+
* @since v0.1.27
|
| 621 |
+
*/
|
| 622 |
+
function resolveTxt(
|
| 623 |
+
hostname: string,
|
| 624 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: string[][]) => void,
|
| 625 |
+
): void;
|
| 626 |
+
namespace resolveTxt {
|
| 627 |
+
function __promisify__(hostname: string): Promise<string[][]>;
|
| 628 |
+
}
|
| 629 |
+
/**
|
| 630 |
+
* Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
|
| 631 |
+
* The `ret` argument passed to the `callback` function will be an array containing
|
| 632 |
+
* various types of records. Each object has a property `type` that indicates the
|
| 633 |
+
* type of the current record. And depending on the `type`, additional properties
|
| 634 |
+
* will be present on the object:
|
| 635 |
+
*
|
| 636 |
+
* <omitted>
|
| 637 |
+
*
|
| 638 |
+
* Here is an example of the `ret` object passed to the callback:
|
| 639 |
+
*
|
| 640 |
+
* ```js
|
| 641 |
+
* [ { type: 'A', address: '127.0.0.1', ttl: 299 },
|
| 642 |
+
* { type: 'CNAME', value: 'example.com' },
|
| 643 |
+
* { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
|
| 644 |
+
* { type: 'NS', value: 'ns1.example.com' },
|
| 645 |
+
* { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
|
| 646 |
+
* { type: 'SOA',
|
| 647 |
+
* nsname: 'ns1.example.com',
|
| 648 |
+
* hostmaster: 'admin.example.com',
|
| 649 |
+
* serial: 156696742,
|
| 650 |
+
* refresh: 900,
|
| 651 |
+
* retry: 900,
|
| 652 |
+
* expire: 1800,
|
| 653 |
+
* minttl: 60 } ]
|
| 654 |
+
* ```
|
| 655 |
+
*
|
| 656 |
+
* 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
|
| 657 |
+
* [RFC 8482](https://tools.ietf.org/html/rfc8482).
|
| 658 |
+
*/
|
| 659 |
+
function resolveAny(
|
| 660 |
+
hostname: string,
|
| 661 |
+
callback: (err: NodeJS.ErrnoException | null, addresses: AnyRecord[]) => void,
|
| 662 |
+
): void;
|
| 663 |
+
namespace resolveAny {
|
| 664 |
+
function __promisify__(hostname: string): Promise<AnyRecord[]>;
|
| 665 |
+
}
|
| 666 |
+
/**
|
| 667 |
+
* Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
|
| 668 |
+
* array of host names.
|
| 669 |
+
*
|
| 670 |
+
* On error, `err` is an [`Error`](https://nodejs.org/docs/latest-v25.x/api/errors.html#class-error) object, where `err.code` is
|
| 671 |
+
* one of the [DNS error codes](https://nodejs.org/docs/latest-v25.x/api/dns.html#error-codes).
|
| 672 |
+
* @since v0.1.16
|
| 673 |
+
*/
|
| 674 |
+
function reverse(
|
| 675 |
+
ip: string,
|
| 676 |
+
callback: (err: NodeJS.ErrnoException | null, hostnames: string[]) => void,
|
| 677 |
+
): void;
|
| 678 |
+
/**
|
| 679 |
+
* Get the default value for `order` in {@link lookup} and [`dnsPromises.lookup()`](https://nodejs.org/docs/latest-v25.x/api/dns.html#dnspromiseslookuphostname-options).
|
| 680 |
+
* The value could be:
|
| 681 |
+
*
|
| 682 |
+
* * `ipv4first`: for `order` defaulting to `ipv4first`.
|
| 683 |
+
* * `ipv6first`: for `order` defaulting to `ipv6first`.
|
| 684 |
+
* * `verbatim`: for `order` defaulting to `verbatim`.
|
| 685 |
+
* @since v18.17.0
|
| 686 |
+
*/
|
| 687 |
+
function getDefaultResultOrder(): "ipv4first" | "ipv6first" | "verbatim";
|
| 688 |
+
/**
|
| 689 |
+
* Sets the IP address and port of servers to be used when performing DNS
|
| 690 |
+
* resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted
|
| 691 |
+
* addresses. If the port is the IANA default DNS port (53) it can be omitted.
|
| 692 |
+
*
|
| 693 |
+
* ```js
|
| 694 |
+
* dns.setServers([
|
| 695 |
+
* '4.4.4.4',
|
| 696 |
+
* '[2001:4860:4860::8888]',
|
| 697 |
+
* '4.4.4.4:1053',
|
| 698 |
+
* '[2001:4860:4860::8888]:1053',
|
| 699 |
+
* ]);
|
| 700 |
+
* ```
|
| 701 |
+
*
|
| 702 |
+
* An error will be thrown if an invalid address is provided.
|
| 703 |
+
*
|
| 704 |
+
* The `dns.setServers()` method must not be called while a DNS query is in
|
| 705 |
+
* progress.
|
| 706 |
+
*
|
| 707 |
+
* The {@link setServers} method affects only {@link resolve}, `dns.resolve*()` and {@link reverse} (and specifically _not_ {@link lookup}).
|
| 708 |
+
*
|
| 709 |
+
* This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
|
| 710 |
+
* 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
|
| 711 |
+
* subsequent servers provided. Fallback DNS servers will only be used if the
|
| 712 |
+
* earlier ones time out or result in some other error.
|
| 713 |
+
* @since v0.11.3
|
| 714 |
+
* @param servers array of [RFC 5952](https://datatracker.ietf.org/doc/html/rfc5952#section-6) formatted addresses
|
| 715 |
+
*/
|
| 716 |
+
function setServers(servers: readonly string[]): void;
|
| 717 |
+
/**
|
| 718 |
+
* Returns an array of IP address strings, formatted according to [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6),
|
| 719 |
+
* that are currently configured for DNS resolution. A string will include a port
|
| 720 |
+
* section if a custom port is used.
|
| 721 |
+
*
|
| 722 |
+
* ```js
|
| 723 |
+
* [
|
| 724 |
+
* '4.4.4.4',
|
| 725 |
+
* '2001:4860:4860::8888',
|
| 726 |
+
* '4.4.4.4:1053',
|
| 727 |
+
* '[2001:4860:4860::8888]:1053',
|
| 728 |
+
* ]
|
| 729 |
+
* ```
|
| 730 |
+
* @since v0.11.3
|
| 731 |
+
*/
|
| 732 |
+
function getServers(): string[];
|
| 733 |
+
/**
|
| 734 |
+
* Set the default value of `order` in {@link lookup} and [`dnsPromises.lookup()`](https://nodejs.org/docs/latest-v25.x/api/dns.html#dnspromiseslookuphostname-options).
|
| 735 |
+
* The value could be:
|
| 736 |
+
*
|
| 737 |
+
* * `ipv4first`: sets default `order` to `ipv4first`.
|
| 738 |
+
* * `ipv6first`: sets default `order` to `ipv6first`.
|
| 739 |
+
* * `verbatim`: sets default `order` to `verbatim`.
|
| 740 |
+
*
|
| 741 |
+
* The default is `verbatim` and {@link setDefaultResultOrder} have higher
|
| 742 |
+
* priority than [`--dns-result-order`](https://nodejs.org/docs/latest-v25.x/api/cli.html#--dns-result-orderorder). When using
|
| 743 |
+
* [worker threads](https://nodejs.org/docs/latest-v25.x/api/worker_threads.html), {@link setDefaultResultOrder} from the main
|
| 744 |
+
* thread won't affect the default dns orders in workers.
|
| 745 |
+
* @since v16.4.0, v14.18.0
|
| 746 |
+
* @param order must be `'ipv4first'`, `'ipv6first'` or `'verbatim'`.
|
| 747 |
+
*/
|
| 748 |
+
function setDefaultResultOrder(order: "ipv4first" | "ipv6first" | "verbatim"): void;
|
| 749 |
+
// Error codes
|
| 750 |
+
const NODATA: "ENODATA";
|
| 751 |
+
const FORMERR: "EFORMERR";
|
| 752 |
+
const SERVFAIL: "ESERVFAIL";
|
| 753 |
+
const NOTFOUND: "ENOTFOUND";
|
| 754 |
+
const NOTIMP: "ENOTIMP";
|
| 755 |
+
const REFUSED: "EREFUSED";
|
| 756 |
+
const BADQUERY: "EBADQUERY";
|
| 757 |
+
const BADNAME: "EBADNAME";
|
| 758 |
+
const BADFAMILY: "EBADFAMILY";
|
| 759 |
+
const BADRESP: "EBADRESP";
|
| 760 |
+
const CONNREFUSED: "ECONNREFUSED";
|
| 761 |
+
const TIMEOUT: "ETIMEOUT";
|
| 762 |
+
const EOF: "EOF";
|
| 763 |
+
const FILE: "EFILE";
|
| 764 |
+
const NOMEM: "ENOMEM";
|
| 765 |
+
const DESTRUCTION: "EDESTRUCTION";
|
| 766 |
+
const BADSTR: "EBADSTR";
|
| 767 |
+
const BADFLAGS: "EBADFLAGS";
|
| 768 |
+
const NONAME: "ENONAME";
|
| 769 |
+
const BADHINTS: "EBADHINTS";
|
| 770 |
+
const NOTINITIALIZED: "ENOTINITIALIZED";
|
| 771 |
+
const LOADIPHLPAPI: "ELOADIPHLPAPI";
|
| 772 |
+
const ADDRGETNETWORKPARAMS: "EADDRGETNETWORKPARAMS";
|
| 773 |
+
const CANCELLED: "ECANCELLED";
|
| 774 |
+
interface ResolverOptions {
|
| 775 |
+
/**
|
| 776 |
+
* Query timeout in milliseconds, or `-1` to use the default timeout.
|
| 777 |
+
*/
|
| 778 |
+
timeout?: number | undefined;
|
| 779 |
+
/**
|
| 780 |
+
* The number of tries the resolver will try contacting each name server before giving up.
|
| 781 |
+
* @default 4
|
| 782 |
+
*/
|
| 783 |
+
tries?: number | undefined;
|
| 784 |
+
/**
|
| 785 |
+
* The max retry timeout, in milliseconds.
|
| 786 |
+
* @default 0
|
| 787 |
+
*/
|
| 788 |
+
maxTimeout?: number | undefined;
|
| 789 |
+
}
|
| 790 |
+
/**
|
| 791 |
+
* An independent resolver for DNS requests.
|
| 792 |
+
*
|
| 793 |
+
* Creating a new resolver uses the default server settings. Setting
|
| 794 |
+
* the servers used for a resolver using [`resolver.setServers()`](https://nodejs.org/docs/latest-v25.x/api/dns.html#dnssetserversservers) does not affect
|
| 795 |
+
* other resolvers:
|
| 796 |
+
*
|
| 797 |
+
* ```js
|
| 798 |
+
* import { Resolver } from 'node:dns';
|
| 799 |
+
* const resolver = new Resolver();
|
| 800 |
+
* resolver.setServers(['4.4.4.4']);
|
| 801 |
+
*
|
| 802 |
+
* // This request will use the server at 4.4.4.4, independent of global settings.
|
| 803 |
+
* resolver.resolve4('example.org', (err, addresses) => {
|
| 804 |
+
* // ...
|
| 805 |
+
* });
|
| 806 |
+
* ```
|
| 807 |
+
*
|
| 808 |
+
* The following methods from the `node:dns` module are available:
|
| 809 |
+
*
|
| 810 |
+
* * `resolver.getServers()`
|
| 811 |
+
* * `resolver.resolve()`
|
| 812 |
+
* * `resolver.resolve4()`
|
| 813 |
+
* * `resolver.resolve6()`
|
| 814 |
+
* * `resolver.resolveAny()`
|
| 815 |
+
* * `resolver.resolveCaa()`
|
| 816 |
+
* * `resolver.resolveCname()`
|
| 817 |
+
* * `resolver.resolveMx()`
|
| 818 |
+
* * `resolver.resolveNaptr()`
|
| 819 |
+
* * `resolver.resolveNs()`
|
| 820 |
+
* * `resolver.resolvePtr()`
|
| 821 |
+
* * `resolver.resolveSoa()`
|
| 822 |
+
* * `resolver.resolveSrv()`
|
| 823 |
+
* * `resolver.resolveTxt()`
|
| 824 |
+
* * `resolver.reverse()`
|
| 825 |
+
* * `resolver.setServers()`
|
| 826 |
+
* @since v8.3.0
|
| 827 |
+
*/
|
| 828 |
+
class Resolver {
|
| 829 |
+
constructor(options?: ResolverOptions);
|
| 830 |
+
/**
|
| 831 |
+
* Cancel all outstanding DNS queries made by this resolver. The corresponding
|
| 832 |
+
* callbacks will be called with an error with code `ECANCELLED`.
|
| 833 |
+
* @since v8.3.0
|
| 834 |
+
*/
|
| 835 |
+
cancel(): void;
|
| 836 |
+
getServers: typeof getServers;
|
| 837 |
+
resolve: typeof resolve;
|
| 838 |
+
resolve4: typeof resolve4;
|
| 839 |
+
resolve6: typeof resolve6;
|
| 840 |
+
resolveAny: typeof resolveAny;
|
| 841 |
+
resolveCaa: typeof resolveCaa;
|
| 842 |
+
resolveCname: typeof resolveCname;
|
| 843 |
+
resolveMx: typeof resolveMx;
|
| 844 |
+
resolveNaptr: typeof resolveNaptr;
|
| 845 |
+
resolveNs: typeof resolveNs;
|
| 846 |
+
resolvePtr: typeof resolvePtr;
|
| 847 |
+
resolveSoa: typeof resolveSoa;
|
| 848 |
+
resolveSrv: typeof resolveSrv;
|
| 849 |
+
resolveTlsa: typeof resolveTlsa;
|
| 850 |
+
resolveTxt: typeof resolveTxt;
|
| 851 |
+
reverse: typeof reverse;
|
| 852 |
+
/**
|
| 853 |
+
* The resolver instance will send its requests from the specified IP address.
|
| 854 |
+
* This allows programs to specify outbound interfaces when used on multi-homed
|
| 855 |
+
* systems.
|
| 856 |
+
*
|
| 857 |
+
* If a v4 or v6 address is not specified, it is set to the default and the
|
| 858 |
+
* operating system will choose a local address automatically.
|
| 859 |
+
*
|
| 860 |
+
* The resolver will use the v4 local address when making requests to IPv4 DNS
|
| 861 |
+
* servers, and the v6 local address when making requests to IPv6 DNS servers.
|
| 862 |
+
* The `rrtype` of resolution requests has no impact on the local address used.
|
| 863 |
+
* @since v15.1.0, v14.17.0
|
| 864 |
+
* @param [ipv4='0.0.0.0'] A string representation of an IPv4 address.
|
| 865 |
+
* @param [ipv6='::0'] A string representation of an IPv6 address.
|
| 866 |
+
*/
|
| 867 |
+
setLocalAddress(ipv4?: string, ipv6?: string): void;
|
| 868 |
+
setServers: typeof setServers;
|
| 869 |
+
}
|
| 870 |
+
}
|
| 871 |
+
declare module "node:dns" {
|
| 872 |
+
export * as promises from "node:dns/promises";
|
| 873 |
+
}
|
| 874 |
+
declare module "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
| 1 |
+
declare module "node:dns/promises" {
|
| 2 |
+
import {
|
| 3 |
+
AnyRecord,
|
| 4 |
+
CaaRecord,
|
| 5 |
+
LookupAddress,
|
| 6 |
+
LookupAllOptions,
|
| 7 |
+
LookupOneOptions,
|
| 8 |
+
LookupOptions,
|
| 9 |
+
MxRecord,
|
| 10 |
+
NaptrRecord,
|
| 11 |
+
RecordWithTtl,
|
| 12 |
+
ResolveOptions,
|
| 13 |
+
ResolverOptions,
|
| 14 |
+
ResolveWithTtlOptions,
|
| 15 |
+
SoaRecord,
|
| 16 |
+
SrvRecord,
|
| 17 |
+
TlsaRecord,
|
| 18 |
+
} from "node:dns";
|
| 19 |
+
/**
|
| 20 |
+
* Returns an array of IP address strings, formatted according to [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6),
|
| 21 |
+
* that are currently configured for DNS resolution. A string will include a port
|
| 22 |
+
* section if a custom port is used.
|
| 23 |
+
*
|
| 24 |
+
* ```js
|
| 25 |
+
* [
|
| 26 |
+
* '4.4.4.4',
|
| 27 |
+
* '2001:4860:4860::8888',
|
| 28 |
+
* '4.4.4.4:1053',
|
| 29 |
+
* '[2001:4860:4860::8888]:1053',
|
| 30 |
+
* ]
|
| 31 |
+
* ```
|
| 32 |
+
* @since v10.6.0
|
| 33 |
+
*/
|
| 34 |
+
function getServers(): string[];
|
| 35 |
+
/**
|
| 36 |
+
* Resolves a host name (e.g. `'nodejs.org'`) into the first found A (IPv4) or
|
| 37 |
+
* AAAA (IPv6) record. All `option` properties are optional. If `options` is an
|
| 38 |
+
* integer, then it must be `4` or `6` – if `options` is not provided, then IPv4
|
| 39 |
+
* and IPv6 addresses are both returned if found.
|
| 40 |
+
*
|
| 41 |
+
* With the `all` option set to `true`, the `Promise` is resolved with `addresses` being an array of objects with the properties `address` and `family`.
|
| 42 |
+
*
|
| 43 |
+
* 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.
|
| 44 |
+
* Keep in mind that `err.code` will be set to `'ENOTFOUND'` not only when
|
| 45 |
+
* the host name does not exist but also when the lookup fails in other ways
|
| 46 |
+
* such as no available file descriptors.
|
| 47 |
+
*
|
| 48 |
+
* [`dnsPromises.lookup()`](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromiseslookuphostname-options) does not necessarily have anything to do with the DNS
|
| 49 |
+
* protocol. The implementation uses an operating system facility that can
|
| 50 |
+
* associate names with addresses and vice versa. This implementation can have
|
| 51 |
+
* subtle but important consequences on the behavior of any Node.js program. Please
|
| 52 |
+
* take some time to consult the [Implementation considerations section](https://nodejs.org/docs/latest-v20.x/api/dns.html#implementation-considerations) before
|
| 53 |
+
* using `dnsPromises.lookup()`.
|
| 54 |
+
*
|
| 55 |
+
* Example usage:
|
| 56 |
+
*
|
| 57 |
+
* ```js
|
| 58 |
+
* import dns from 'node:dns';
|
| 59 |
+
* const dnsPromises = dns.promises;
|
| 60 |
+
* const options = {
|
| 61 |
+
* family: 6,
|
| 62 |
+
* hints: dns.ADDRCONFIG | dns.V4MAPPED,
|
| 63 |
+
* };
|
| 64 |
+
*
|
| 65 |
+
* dnsPromises.lookup('example.com', options).then((result) => {
|
| 66 |
+
* console.log('address: %j family: IPv%s', result.address, result.family);
|
| 67 |
+
* // address: "2606:2800:220:1:248:1893:25c8:1946" family: IPv6
|
| 68 |
+
* });
|
| 69 |
+
*
|
| 70 |
+
* // When options.all is true, the result will be an Array.
|
| 71 |
+
* options.all = true;
|
| 72 |
+
* dnsPromises.lookup('example.com', options).then((result) => {
|
| 73 |
+
* console.log('addresses: %j', result);
|
| 74 |
+
* // addresses: [{"address":"2606:2800:220:1:248:1893:25c8:1946","family":6}]
|
| 75 |
+
* });
|
| 76 |
+
* ```
|
| 77 |
+
* @since v10.6.0
|
| 78 |
+
*/
|
| 79 |
+
function lookup(hostname: string, family: number): Promise<LookupAddress>;
|
| 80 |
+
function lookup(hostname: string, options: LookupOneOptions): Promise<LookupAddress>;
|
| 81 |
+
function lookup(hostname: string, options: LookupAllOptions): Promise<LookupAddress[]>;
|
| 82 |
+
function lookup(hostname: string, options: LookupOptions): Promise<LookupAddress | LookupAddress[]>;
|
| 83 |
+
function lookup(hostname: string): Promise<LookupAddress>;
|
| 84 |
+
/**
|
| 85 |
+
* Resolves the given `address` and `port` into a host name and service using
|
| 86 |
+
* the operating system's underlying `getnameinfo` implementation.
|
| 87 |
+
*
|
| 88 |
+
* If `address` is not a valid IP address, a `TypeError` will be thrown.
|
| 89 |
+
* The `port` will be coerced to a number. If it is not a legal port, a `TypeError` will be thrown.
|
| 90 |
+
*
|
| 91 |
+
* 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.
|
| 92 |
+
*
|
| 93 |
+
* ```js
|
| 94 |
+
* import dnsPromises from 'node:dns';
|
| 95 |
+
* dnsPromises.lookupService('127.0.0.1', 22).then((result) => {
|
| 96 |
+
* console.log(result.hostname, result.service);
|
| 97 |
+
* // Prints: localhost ssh
|
| 98 |
+
* });
|
| 99 |
+
* ```
|
| 100 |
+
* @since v10.6.0
|
| 101 |
+
*/
|
| 102 |
+
function lookupService(
|
| 103 |
+
address: string,
|
| 104 |
+
port: number,
|
| 105 |
+
): Promise<{
|
| 106 |
+
hostname: string;
|
| 107 |
+
service: string;
|
| 108 |
+
}>;
|
| 109 |
+
/**
|
| 110 |
+
* Uses the DNS protocol to resolve a host name (e.g. `'nodejs.org'`) into an array
|
| 111 |
+
* of the resource records. When successful, the `Promise` is resolved with an
|
| 112 |
+
* array of resource records. The type and structure of individual results vary
|
| 113 |
+
* based on `rrtype`:
|
| 114 |
+
*
|
| 115 |
+
* <omitted>
|
| 116 |
+
*
|
| 117 |
+
* 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`
|
| 118 |
+
* is one of the [DNS error codes](https://nodejs.org/docs/latest-v20.x/api/dns.html#error-codes).
|
| 119 |
+
* @since v10.6.0
|
| 120 |
+
* @param hostname Host name to resolve.
|
| 121 |
+
* @param [rrtype='A'] Resource record type.
|
| 122 |
+
*/
|
| 123 |
+
function resolve(hostname: string): Promise<string[]>;
|
| 124 |
+
function resolve(hostname: string, rrtype: "A" | "AAAA" | "CNAME" | "NS" | "PTR"): Promise<string[]>;
|
| 125 |
+
function resolve(hostname: string, rrtype: "ANY"): Promise<AnyRecord[]>;
|
| 126 |
+
function resolve(hostname: string, rrtype: "CAA"): Promise<CaaRecord[]>;
|
| 127 |
+
function resolve(hostname: string, rrtype: "MX"): Promise<MxRecord[]>;
|
| 128 |
+
function resolve(hostname: string, rrtype: "NAPTR"): Promise<NaptrRecord[]>;
|
| 129 |
+
function resolve(hostname: string, rrtype: "SOA"): Promise<SoaRecord>;
|
| 130 |
+
function resolve(hostname: string, rrtype: "SRV"): Promise<SrvRecord[]>;
|
| 131 |
+
function resolve(hostname: string, rrtype: "TLSA"): Promise<TlsaRecord[]>;
|
| 132 |
+
function resolve(hostname: string, rrtype: "TXT"): Promise<string[][]>;
|
| 133 |
+
function resolve(hostname: string, rrtype: string): Promise<
|
| 134 |
+
| string[]
|
| 135 |
+
| CaaRecord[]
|
| 136 |
+
| MxRecord[]
|
| 137 |
+
| NaptrRecord[]
|
| 138 |
+
| SoaRecord
|
| 139 |
+
| SrvRecord[]
|
| 140 |
+
| TlsaRecord[]
|
| 141 |
+
| string[][]
|
| 142 |
+
| AnyRecord[]
|
| 143 |
+
>;
|
| 144 |
+
/**
|
| 145 |
+
* Uses the DNS protocol to resolve IPv4 addresses (`A` records) for the `hostname`. On success, the `Promise` is resolved with an array of IPv4
|
| 146 |
+
* addresses (e.g. `['74.125.79.104', '74.125.79.105', '74.125.79.106']`).
|
| 147 |
+
* @since v10.6.0
|
| 148 |
+
* @param hostname Host name to resolve.
|
| 149 |
+
*/
|
| 150 |
+
function resolve4(hostname: string): Promise<string[]>;
|
| 151 |
+
function resolve4(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
|
| 152 |
+
function resolve4(hostname: string, options: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
|
| 153 |
+
/**
|
| 154 |
+
* Uses the DNS protocol to resolve IPv6 addresses (`AAAA` records) for the `hostname`. On success, the `Promise` is resolved with an array of IPv6
|
| 155 |
+
* addresses.
|
| 156 |
+
* @since v10.6.0
|
| 157 |
+
* @param hostname Host name to resolve.
|
| 158 |
+
*/
|
| 159 |
+
function resolve6(hostname: string): Promise<string[]>;
|
| 160 |
+
function resolve6(hostname: string, options: ResolveWithTtlOptions): Promise<RecordWithTtl[]>;
|
| 161 |
+
function resolve6(hostname: string, options: ResolveOptions): Promise<string[] | RecordWithTtl[]>;
|
| 162 |
+
/**
|
| 163 |
+
* Uses the DNS protocol to resolve all records (also known as `ANY` or `*` query).
|
| 164 |
+
* On success, the `Promise` is resolved with an array containing various types of
|
| 165 |
+
* records. Each object has a property `type` that indicates the type of the
|
| 166 |
+
* current record. And depending on the `type`, additional properties will be
|
| 167 |
+
* present on the object:
|
| 168 |
+
*
|
| 169 |
+
* <omitted>
|
| 170 |
+
*
|
| 171 |
+
* Here is an example of the result object:
|
| 172 |
+
*
|
| 173 |
+
* ```js
|
| 174 |
+
* [ { type: 'A', address: '127.0.0.1', ttl: 299 },
|
| 175 |
+
* { type: 'CNAME', value: 'example.com' },
|
| 176 |
+
* { type: 'MX', exchange: 'alt4.aspmx.l.example.com', priority: 50 },
|
| 177 |
+
* { type: 'NS', value: 'ns1.example.com' },
|
| 178 |
+
* { type: 'TXT', entries: [ 'v=spf1 include:_spf.example.com ~all' ] },
|
| 179 |
+
* { type: 'SOA',
|
| 180 |
+
* nsname: 'ns1.example.com',
|
| 181 |
+
* hostmaster: 'admin.example.com',
|
| 182 |
+
* serial: 156696742,
|
| 183 |
+
* refresh: 900,
|
| 184 |
+
* retry: 900,
|
| 185 |
+
* expire: 1800,
|
| 186 |
+
* minttl: 60 } ]
|
| 187 |
+
* ```
|
| 188 |
+
* @since v10.6.0
|
| 189 |
+
*/
|
| 190 |
+
function resolveAny(hostname: string): Promise<AnyRecord[]>;
|
| 191 |
+
/**
|
| 192 |
+
* Uses the DNS protocol to resolve `CAA` records for the `hostname`. On success,
|
| 193 |
+
* the `Promise` is resolved with an array of objects containing available
|
| 194 |
+
* certification authority authorization records available for the `hostname` (e.g. `[{critical: 0, iodef: 'mailto:pki@example.com'},{critical: 128, issue: 'pki.example.com'}]`).
|
| 195 |
+
* @since v15.0.0, v14.17.0
|
| 196 |
+
*/
|
| 197 |
+
function resolveCaa(hostname: string): Promise<CaaRecord[]>;
|
| 198 |
+
/**
|
| 199 |
+
* Uses the DNS protocol to resolve `CNAME` records for the `hostname`. On success,
|
| 200 |
+
* the `Promise` is resolved with an array of canonical name records available for
|
| 201 |
+
* the `hostname` (e.g. `['bar.example.com']`).
|
| 202 |
+
* @since v10.6.0
|
| 203 |
+
*/
|
| 204 |
+
function resolveCname(hostname: string): Promise<string[]>;
|
| 205 |
+
/**
|
| 206 |
+
* 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
|
| 207 |
+
* containing both a `priority` and `exchange` property (e.g.`[{priority: 10, exchange: 'mx.example.com'}, ...]`).
|
| 208 |
+
* @since v10.6.0
|
| 209 |
+
*/
|
| 210 |
+
function resolveMx(hostname: string): Promise<MxRecord[]>;
|
| 211 |
+
/**
|
| 212 |
+
* Uses the DNS protocol to resolve regular expression-based records (`NAPTR` records) for the `hostname`. On success, the `Promise` is resolved with an array
|
| 213 |
+
* of objects with the following properties:
|
| 214 |
+
*
|
| 215 |
+
* * `flags`
|
| 216 |
+
* * `service`
|
| 217 |
+
* * `regexp`
|
| 218 |
+
* * `replacement`
|
| 219 |
+
* * `order`
|
| 220 |
+
* * `preference`
|
| 221 |
+
*
|
| 222 |
+
* ```js
|
| 223 |
+
* {
|
| 224 |
+
* flags: 's',
|
| 225 |
+
* service: 'SIP+D2U',
|
| 226 |
+
* regexp: '',
|
| 227 |
+
* replacement: '_sip._udp.example.com',
|
| 228 |
+
* order: 30,
|
| 229 |
+
* preference: 100
|
| 230 |
+
* }
|
| 231 |
+
* ```
|
| 232 |
+
* @since v10.6.0
|
| 233 |
+
*/
|
| 234 |
+
function resolveNaptr(hostname: string): Promise<NaptrRecord[]>;
|
| 235 |
+
/**
|
| 236 |
+
* 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
|
| 237 |
+
* records available for `hostname` (e.g.`['ns1.example.com', 'ns2.example.com']`).
|
| 238 |
+
* @since v10.6.0
|
| 239 |
+
*/
|
| 240 |
+
function resolveNs(hostname: string): Promise<string[]>;
|
| 241 |
+
/**
|
| 242 |
+
* Uses the DNS protocol to resolve pointer records (`PTR` records) for the `hostname`. On success, the `Promise` is resolved with an array of strings
|
| 243 |
+
* containing the reply records.
|
| 244 |
+
* @since v10.6.0
|
| 245 |
+
*/
|
| 246 |
+
function resolvePtr(hostname: string): Promise<string[]>;
|
| 247 |
+
/**
|
| 248 |
+
* Uses the DNS protocol to resolve a start of authority record (`SOA` record) for
|
| 249 |
+
* the `hostname`. On success, the `Promise` is resolved with an object with the
|
| 250 |
+
* following properties:
|
| 251 |
+
*
|
| 252 |
+
* * `nsname`
|
| 253 |
+
* * `hostmaster`
|
| 254 |
+
* * `serial`
|
| 255 |
+
* * `refresh`
|
| 256 |
+
* * `retry`
|
| 257 |
+
* * `expire`
|
| 258 |
+
* * `minttl`
|
| 259 |
+
*
|
| 260 |
+
* ```js
|
| 261 |
+
* {
|
| 262 |
+
* nsname: 'ns.example.com',
|
| 263 |
+
* hostmaster: 'root.example.com',
|
| 264 |
+
* serial: 2013101809,
|
| 265 |
+
* refresh: 10000,
|
| 266 |
+
* retry: 2400,
|
| 267 |
+
* expire: 604800,
|
| 268 |
+
* minttl: 3600
|
| 269 |
+
* }
|
| 270 |
+
* ```
|
| 271 |
+
* @since v10.6.0
|
| 272 |
+
*/
|
| 273 |
+
function resolveSoa(hostname: string): Promise<SoaRecord>;
|
| 274 |
+
/**
|
| 275 |
+
* 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
|
| 276 |
+
* the following properties:
|
| 277 |
+
*
|
| 278 |
+
* * `priority`
|
| 279 |
+
* * `weight`
|
| 280 |
+
* * `port`
|
| 281 |
+
* * `name`
|
| 282 |
+
*
|
| 283 |
+
* ```js
|
| 284 |
+
* {
|
| 285 |
+
* priority: 10,
|
| 286 |
+
* weight: 5,
|
| 287 |
+
* port: 21223,
|
| 288 |
+
* name: 'service.example.com'
|
| 289 |
+
* }
|
| 290 |
+
* ```
|
| 291 |
+
* @since v10.6.0
|
| 292 |
+
*/
|
| 293 |
+
function resolveSrv(hostname: string): Promise<SrvRecord[]>;
|
| 294 |
+
/**
|
| 295 |
+
* Uses the DNS protocol to resolve certificate associations (`TLSA` records) for
|
| 296 |
+
* the `hostname`. On success, the `Promise` is resolved with an array of objectsAdd commentMore actions
|
| 297 |
+
* with these properties:
|
| 298 |
+
*
|
| 299 |
+
* * `certUsage`
|
| 300 |
+
* * `selector`
|
| 301 |
+
* * `match`
|
| 302 |
+
* * `data`
|
| 303 |
+
*
|
| 304 |
+
* ```js
|
| 305 |
+
* {
|
| 306 |
+
* certUsage: 3,
|
| 307 |
+
* selector: 1,
|
| 308 |
+
* match: 1,
|
| 309 |
+
* data: [ArrayBuffer]
|
| 310 |
+
* }
|
| 311 |
+
* ```
|
| 312 |
+
* @since v23.9.0, v22.15.0
|
| 313 |
+
*/
|
| 314 |
+
function resolveTlsa(hostname: string): Promise<TlsaRecord[]>;
|
| 315 |
+
/**
|
| 316 |
+
* Uses the DNS protocol to resolve text queries (`TXT` records) for the `hostname`. On success, the `Promise` is resolved with a two-dimensional array
|
| 317 |
+
* of the text records available for `hostname` (e.g.`[ ['v=spf1 ip4:0.0.0.0 ', '~all' ] ]`). Each sub-array contains TXT chunks of
|
| 318 |
+
* one record. Depending on the use case, these could be either joined together or
|
| 319 |
+
* treated separately.
|
| 320 |
+
* @since v10.6.0
|
| 321 |
+
*/
|
| 322 |
+
function resolveTxt(hostname: string): Promise<string[][]>;
|
| 323 |
+
/**
|
| 324 |
+
* Performs a reverse DNS query that resolves an IPv4 or IPv6 address to an
|
| 325 |
+
* array of host names.
|
| 326 |
+
*
|
| 327 |
+
* 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`
|
| 328 |
+
* is one of the [DNS error codes](https://nodejs.org/docs/latest-v20.x/api/dns.html#error-codes).
|
| 329 |
+
* @since v10.6.0
|
| 330 |
+
*/
|
| 331 |
+
function reverse(ip: string): Promise<string[]>;
|
| 332 |
+
/**
|
| 333 |
+
* Get the default value for `verbatim` in {@link lookup} and [dnsPromises.lookup()](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromiseslookuphostname-options).
|
| 334 |
+
* The value could be:
|
| 335 |
+
*
|
| 336 |
+
* * `ipv4first`: for `verbatim` defaulting to `false`.
|
| 337 |
+
* * `verbatim`: for `verbatim` defaulting to `true`.
|
| 338 |
+
* @since v20.1.0
|
| 339 |
+
*/
|
| 340 |
+
function getDefaultResultOrder(): "ipv4first" | "verbatim";
|
| 341 |
+
/**
|
| 342 |
+
* Sets the IP address and port of servers to be used when performing DNS
|
| 343 |
+
* resolution. The `servers` argument is an array of [RFC 5952](https://tools.ietf.org/html/rfc5952#section-6) formatted
|
| 344 |
+
* addresses. If the port is the IANA default DNS port (53) it can be omitted.
|
| 345 |
+
*
|
| 346 |
+
* ```js
|
| 347 |
+
* dnsPromises.setServers([
|
| 348 |
+
* '4.4.4.4',
|
| 349 |
+
* '[2001:4860:4860::8888]',
|
| 350 |
+
* '4.4.4.4:1053',
|
| 351 |
+
* '[2001:4860:4860::8888]:1053',
|
| 352 |
+
* ]);
|
| 353 |
+
* ```
|
| 354 |
+
*
|
| 355 |
+
* An error will be thrown if an invalid address is provided.
|
| 356 |
+
*
|
| 357 |
+
* The `dnsPromises.setServers()` method must not be called while a DNS query is in
|
| 358 |
+
* progress.
|
| 359 |
+
*
|
| 360 |
+
* This method works much like [resolve.conf](https://man7.org/linux/man-pages/man5/resolv.conf.5.html).
|
| 361 |
+
* 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
|
| 362 |
+
* subsequent servers provided. Fallback DNS servers will only be used if the
|
| 363 |
+
* earlier ones time out or result in some other error.
|
| 364 |
+
* @since v10.6.0
|
| 365 |
+
* @param servers array of `RFC 5952` formatted addresses
|
| 366 |
+
*/
|
| 367 |
+
function setServers(servers: readonly string[]): void;
|
| 368 |
+
/**
|
| 369 |
+
* Set the default value of `order` in `dns.lookup()` and `{@link lookup}`. The value could be:
|
| 370 |
+
*
|
| 371 |
+
* * `ipv4first`: sets default `order` to `ipv4first`.
|
| 372 |
+
* * `ipv6first`: sets default `order` to `ipv6first`.
|
| 373 |
+
* * `verbatim`: sets default `order` to `verbatim`.
|
| 374 |
+
*
|
| 375 |
+
* The default is `verbatim` and [dnsPromises.setDefaultResultOrder()](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromisessetdefaultresultorderorder)
|
| 376 |
+
* have higher priority than [`--dns-result-order`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--dns-result-orderorder).
|
| 377 |
+
* 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)
|
| 378 |
+
* from the main thread won't affect the default dns orders in workers.
|
| 379 |
+
* @since v16.4.0, v14.18.0
|
| 380 |
+
* @param order must be `'ipv4first'`, `'ipv6first'` or `'verbatim'`.
|
| 381 |
+
*/
|
| 382 |
+
function setDefaultResultOrder(order: "ipv4first" | "ipv6first" | "verbatim"): void;
|
| 383 |
+
// Error codes
|
| 384 |
+
const NODATA: "ENODATA";
|
| 385 |
+
const FORMERR: "EFORMERR";
|
| 386 |
+
const SERVFAIL: "ESERVFAIL";
|
| 387 |
+
const NOTFOUND: "ENOTFOUND";
|
| 388 |
+
const NOTIMP: "ENOTIMP";
|
| 389 |
+
const REFUSED: "EREFUSED";
|
| 390 |
+
const BADQUERY: "EBADQUERY";
|
| 391 |
+
const BADNAME: "EBADNAME";
|
| 392 |
+
const BADFAMILY: "EBADFAMILY";
|
| 393 |
+
const BADRESP: "EBADRESP";
|
| 394 |
+
const CONNREFUSED: "ECONNREFUSED";
|
| 395 |
+
const TIMEOUT: "ETIMEOUT";
|
| 396 |
+
const EOF: "EOF";
|
| 397 |
+
const FILE: "EFILE";
|
| 398 |
+
const NOMEM: "ENOMEM";
|
| 399 |
+
const DESTRUCTION: "EDESTRUCTION";
|
| 400 |
+
const BADSTR: "EBADSTR";
|
| 401 |
+
const BADFLAGS: "EBADFLAGS";
|
| 402 |
+
const NONAME: "ENONAME";
|
| 403 |
+
const BADHINTS: "EBADHINTS";
|
| 404 |
+
const NOTINITIALIZED: "ENOTINITIALIZED";
|
| 405 |
+
const LOADIPHLPAPI: "ELOADIPHLPAPI";
|
| 406 |
+
const ADDRGETNETWORKPARAMS: "EADDRGETNETWORKPARAMS";
|
| 407 |
+
const CANCELLED: "ECANCELLED";
|
| 408 |
+
|
| 409 |
+
/**
|
| 410 |
+
* An independent resolver for DNS requests.
|
| 411 |
+
*
|
| 412 |
+
* Creating a new resolver uses the default server settings. Setting
|
| 413 |
+
* the servers used for a resolver using [`resolver.setServers()`](https://nodejs.org/docs/latest-v20.x/api/dns.html#dnspromisessetserversservers) does not affect
|
| 414 |
+
* other resolvers:
|
| 415 |
+
*
|
| 416 |
+
* ```js
|
| 417 |
+
* import { promises } from 'node:dns';
|
| 418 |
+
* const resolver = new promises.Resolver();
|
| 419 |
+
* resolver.setServers(['4.4.4.4']);
|
| 420 |
+
*
|
| 421 |
+
* // This request will use the server at 4.4.4.4, independent of global settings.
|
| 422 |
+
* resolver.resolve4('example.org').then((addresses) => {
|
| 423 |
+
* // ...
|
| 424 |
+
* });
|
| 425 |
+
*
|
| 426 |
+
* // Alternatively, the same code can be written using async-await style.
|
| 427 |
+
* (async function() {
|
| 428 |
+
* const addresses = await resolver.resolve4('example.org');
|
| 429 |
+
* })();
|
| 430 |
+
* ```
|
| 431 |
+
*
|
| 432 |
+
* The following methods from the `dnsPromises` API are available:
|
| 433 |
+
*
|
| 434 |
+
* * `resolver.getServers()`
|
| 435 |
+
* * `resolver.resolve()`
|
| 436 |
+
* * `resolver.resolve4()`
|
| 437 |
+
* * `resolver.resolve6()`
|
| 438 |
+
* * `resolver.resolveAny()`
|
| 439 |
+
* * `resolver.resolveCaa()`
|
| 440 |
+
* * `resolver.resolveCname()`
|
| 441 |
+
* * `resolver.resolveMx()`
|
| 442 |
+
* * `resolver.resolveNaptr()`
|
| 443 |
+
* * `resolver.resolveNs()`
|
| 444 |
+
* * `resolver.resolvePtr()`
|
| 445 |
+
* * `resolver.resolveSoa()`
|
| 446 |
+
* * `resolver.resolveSrv()`
|
| 447 |
+
* * `resolver.resolveTxt()`
|
| 448 |
+
* * `resolver.reverse()`
|
| 449 |
+
* * `resolver.setServers()`
|
| 450 |
+
* @since v10.6.0
|
| 451 |
+
*/
|
| 452 |
+
class Resolver {
|
| 453 |
+
constructor(options?: ResolverOptions);
|
| 454 |
+
/**
|
| 455 |
+
* Cancel all outstanding DNS queries made by this resolver. The corresponding
|
| 456 |
+
* callbacks will be called with an error with code `ECANCELLED`.
|
| 457 |
+
* @since v8.3.0
|
| 458 |
+
*/
|
| 459 |
+
cancel(): void;
|
| 460 |
+
getServers: typeof getServers;
|
| 461 |
+
resolve: typeof resolve;
|
| 462 |
+
resolve4: typeof resolve4;
|
| 463 |
+
resolve6: typeof resolve6;
|
| 464 |
+
resolveAny: typeof resolveAny;
|
| 465 |
+
resolveCaa: typeof resolveCaa;
|
| 466 |
+
resolveCname: typeof resolveCname;
|
| 467 |
+
resolveMx: typeof resolveMx;
|
| 468 |
+
resolveNaptr: typeof resolveNaptr;
|
| 469 |
+
resolveNs: typeof resolveNs;
|
| 470 |
+
resolvePtr: typeof resolvePtr;
|
| 471 |
+
resolveSoa: typeof resolveSoa;
|
| 472 |
+
resolveSrv: typeof resolveSrv;
|
| 473 |
+
resolveTlsa: typeof resolveTlsa;
|
| 474 |
+
resolveTxt: typeof resolveTxt;
|
| 475 |
+
reverse: typeof reverse;
|
| 476 |
+
/**
|
| 477 |
+
* The resolver instance will send its requests from the specified IP address.
|
| 478 |
+
* This allows programs to specify outbound interfaces when used on multi-homed
|
| 479 |
+
* systems.
|
| 480 |
+
*
|
| 481 |
+
* If a v4 or v6 address is not specified, it is set to the default and the
|
| 482 |
+
* operating system will choose a local address automatically.
|
| 483 |
+
*
|
| 484 |
+
* The resolver will use the v4 local address when making requests to IPv4 DNS
|
| 485 |
+
* servers, and the v6 local address when making requests to IPv6 DNS servers.
|
| 486 |
+
* The `rrtype` of resolution requests has no impact on the local address used.
|
| 487 |
+
* @since v15.1.0, v14.17.0
|
| 488 |
+
* @param [ipv4='0.0.0.0'] A string representation of an IPv4 address.
|
| 489 |
+
* @param [ipv6='::0'] A string representation of an IPv6 address.
|
| 490 |
+
*/
|
| 491 |
+
setLocalAddress(ipv4?: string, ipv6?: string): void;
|
| 492 |
+
setServers: typeof setServers;
|
| 493 |
+
}
|
| 494 |
+
}
|
| 495 |
+
declare module "dns/promises" {
|
| 496 |
+
export * from "node:dns/promises";
|
| 497 |
+
}
|
node_modules/@types/node/domain.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:domain" {
|
| 2 |
+
import { EventEmitter } from "node:events";
|
| 3 |
+
/**
|
| 4 |
+
* The `Domain` class encapsulates the functionality of routing errors and
|
| 5 |
+
* uncaught exceptions to the active `Domain` object.
|
| 6 |
+
*
|
| 7 |
+
* To handle the errors that it catches, listen to its `'error'` event.
|
| 8 |
+
*/
|
| 9 |
+
class Domain extends EventEmitter {
|
| 10 |
+
/**
|
| 11 |
+
* An array of event emitters that have been explicitly added to the domain.
|
| 12 |
+
*/
|
| 13 |
+
members: EventEmitter[];
|
| 14 |
+
/**
|
| 15 |
+
* 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
|
| 16 |
+
* pushes the domain onto the domain
|
| 17 |
+
* stack managed by the domain module (see {@link exit} for details on the
|
| 18 |
+
* domain stack). The call to `enter()` delimits the beginning of a chain of
|
| 19 |
+
* asynchronous calls and I/O operations bound to a domain.
|
| 20 |
+
*
|
| 21 |
+
* Calling `enter()` changes only the active domain, and does not alter the domain
|
| 22 |
+
* itself. `enter()` and `exit()` can be called an arbitrary number of times on a
|
| 23 |
+
* single domain.
|
| 24 |
+
*/
|
| 25 |
+
enter(): void;
|
| 26 |
+
/**
|
| 27 |
+
* The `exit()` method exits the current domain, popping it off the domain stack.
|
| 28 |
+
* Any time execution is going to switch to the context of a different chain of
|
| 29 |
+
* asynchronous calls, it's important to ensure that the current domain is exited.
|
| 30 |
+
* The call to `exit()` delimits either the end of or an interruption to the chain
|
| 31 |
+
* of asynchronous calls and I/O operations bound to a domain.
|
| 32 |
+
*
|
| 33 |
+
* If there are multiple, nested domains bound to the current execution context, `exit()` will exit any domains nested within this domain.
|
| 34 |
+
*
|
| 35 |
+
* Calling `exit()` changes only the active domain, and does not alter the domain
|
| 36 |
+
* itself. `enter()` and `exit()` can be called an arbitrary number of times on a
|
| 37 |
+
* single domain.
|
| 38 |
+
*/
|
| 39 |
+
exit(): void;
|
| 40 |
+
/**
|
| 41 |
+
* Run the supplied function in the context of the domain, implicitly
|
| 42 |
+
* binding all event emitters, timers, and low-level requests that are
|
| 43 |
+
* created in that context. Optionally, arguments can be passed to
|
| 44 |
+
* the function.
|
| 45 |
+
*
|
| 46 |
+
* This is the most basic way to use a domain.
|
| 47 |
+
*
|
| 48 |
+
* ```js
|
| 49 |
+
* import domain from 'node:domain';
|
| 50 |
+
* import fs from 'node:fs';
|
| 51 |
+
* const d = domain.create();
|
| 52 |
+
* d.on('error', (er) => {
|
| 53 |
+
* console.error('Caught error!', er);
|
| 54 |
+
* });
|
| 55 |
+
* d.run(() => {
|
| 56 |
+
* process.nextTick(() => {
|
| 57 |
+
* setTimeout(() => { // Simulating some various async stuff
|
| 58 |
+
* fs.open('non-existent file', 'r', (er, fd) => {
|
| 59 |
+
* if (er) throw er;
|
| 60 |
+
* // proceed...
|
| 61 |
+
* });
|
| 62 |
+
* }, 100);
|
| 63 |
+
* });
|
| 64 |
+
* });
|
| 65 |
+
* ```
|
| 66 |
+
*
|
| 67 |
+
* In this example, the `d.on('error')` handler will be triggered, rather
|
| 68 |
+
* than crashing the program.
|
| 69 |
+
*/
|
| 70 |
+
run<T>(fn: (...args: any[]) => T, ...args: any[]): T;
|
| 71 |
+
/**
|
| 72 |
+
* Explicitly adds an emitter to the domain. If any event handlers called by
|
| 73 |
+
* the emitter throw an error, or if the emitter emits an `'error'` event, it
|
| 74 |
+
* will be routed to the domain's `'error'` event, just like with implicit
|
| 75 |
+
* binding.
|
| 76 |
+
*
|
| 77 |
+
* If the `EventEmitter` was already bound to a domain, it is removed from that
|
| 78 |
+
* one, and bound to this one instead.
|
| 79 |
+
* @param emitter emitter to be added to the domain
|
| 80 |
+
*/
|
| 81 |
+
add(emitter: EventEmitter): void;
|
| 82 |
+
/**
|
| 83 |
+
* The opposite of {@link add}. Removes domain handling from the
|
| 84 |
+
* specified emitter.
|
| 85 |
+
* @param emitter emitter to be removed from the domain
|
| 86 |
+
*/
|
| 87 |
+
remove(emitter: EventEmitter): void;
|
| 88 |
+
/**
|
| 89 |
+
* The returned function will be a wrapper around the supplied callback
|
| 90 |
+
* function. When the returned function is called, any errors that are
|
| 91 |
+
* thrown will be routed to the domain's `'error'` event.
|
| 92 |
+
*
|
| 93 |
+
* ```js
|
| 94 |
+
* const d = domain.create();
|
| 95 |
+
*
|
| 96 |
+
* function readSomeFile(filename, cb) {
|
| 97 |
+
* fs.readFile(filename, 'utf8', d.bind((er, data) => {
|
| 98 |
+
* // If this throws, it will also be passed to the domain.
|
| 99 |
+
* return cb(er, data ? JSON.parse(data) : null);
|
| 100 |
+
* }));
|
| 101 |
+
* }
|
| 102 |
+
*
|
| 103 |
+
* d.on('error', (er) => {
|
| 104 |
+
* // An error occurred somewhere. If we throw it now, it will crash the program
|
| 105 |
+
* // with the normal line number and stack message.
|
| 106 |
+
* });
|
| 107 |
+
* ```
|
| 108 |
+
* @param callback The callback function
|
| 109 |
+
* @return The bound function
|
| 110 |
+
*/
|
| 111 |
+
bind<T extends Function>(callback: T): T;
|
| 112 |
+
/**
|
| 113 |
+
* This method is almost identical to {@link bind}. However, in
|
| 114 |
+
* addition to catching thrown errors, it will also intercept `Error` objects sent as the first argument to the function.
|
| 115 |
+
*
|
| 116 |
+
* In this way, the common `if (err) return callback(err);` pattern can be replaced
|
| 117 |
+
* with a single error handler in a single place.
|
| 118 |
+
*
|
| 119 |
+
* ```js
|
| 120 |
+
* const d = domain.create();
|
| 121 |
+
*
|
| 122 |
+
* function readSomeFile(filename, cb) {
|
| 123 |
+
* fs.readFile(filename, 'utf8', d.intercept((data) => {
|
| 124 |
+
* // Note, the first argument is never passed to the
|
| 125 |
+
* // callback since it is assumed to be the 'Error' argument
|
| 126 |
+
* // and thus intercepted by the domain.
|
| 127 |
+
*
|
| 128 |
+
* // If this throws, it will also be passed to the domain
|
| 129 |
+
* // so the error-handling logic can be moved to the 'error'
|
| 130 |
+
* // event on the domain instead of being repeated throughout
|
| 131 |
+
* // the program.
|
| 132 |
+
* return cb(null, JSON.parse(data));
|
| 133 |
+
* }));
|
| 134 |
+
* }
|
| 135 |
+
*
|
| 136 |
+
* d.on('error', (er) => {
|
| 137 |
+
* // An error occurred somewhere. If we throw it now, it will crash the program
|
| 138 |
+
* // with the normal line number and stack message.
|
| 139 |
+
* });
|
| 140 |
+
* ```
|
| 141 |
+
* @param callback The callback function
|
| 142 |
+
* @return The intercepted function
|
| 143 |
+
*/
|
| 144 |
+
intercept<T extends Function>(callback: T): T;
|
| 145 |
+
}
|
| 146 |
+
function create(): Domain;
|
| 147 |
+
}
|
| 148 |
+
declare module "domain" {
|
| 149 |
+
export * from "node:domain";
|
| 150 |
+
}
|
node_modules/@types/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ooks";
|
| 3 |
+
// #region Event map helpers
|
| 4 |
+
type EventMap<T> = Record<keyof T, any[]>;
|
| 5 |
+
type IfEventMap<Events extends EventMap<Events>, True, False> = {} extends Events ? False : True;
|
| 6 |
+
type Args<Events extends EventMap<Events>, EventName extends string | symbol> = IfEventMap<
|
| 7 |
+
Events,
|
| 8 |
+
EventName extends keyof Events ? Events[EventName]
|
| 9 |
+
: EventName extends keyof EventEmitterEventMap ? EventEmitterEventMap[EventName]
|
| 10 |
+
: any[],
|
| 11 |
+
any[]
|
| 12 |
+
>;
|
| 13 |
+
type EventNames<Events extends EventMap<Events>, EventName extends string | symbol> = IfEventMap<
|
| 14 |
+
Events,
|
| 15 |
+
EventName | (keyof Events & (string | symbol)) | keyof EventEmitterEventMap,
|
| 16 |
+
string | symbol
|
| 17 |
+
>;
|
| 18 |
+
type Listener<Events extends EventMap<Events>, EventName extends string | symbol> = IfEventMap<
|
| 19 |
+
Events,
|
| 20 |
+
(
|
| 21 |
+
...args: EventName extends keyof Events ? Events[EventName]
|
| 22 |
+
: EventName extends keyof EventEmitterEventMap ? EventEmitterEventMap[EventName]
|
| 23 |
+
: any[]
|
| 24 |
+
) => void,
|
| 25 |
+
(...args: any[]) => void
|
| 26 |
+
>;
|
| 27 |
+
interface EventEmitterEventMap {
|
| 28 |
+
newListener: [eventName: string | symbol, listener: (...args: any[]) => void];
|
| 29 |
+
removeListener: [eventName: string | symbol, listener: (...args: any[]) => void];
|
| 30 |
+
}
|
| 31 |
+
// #endregion
|
| 32 |
+
interface EventEmitterOptions {
|
| 33 |
+
/**
|
| 34 |
+
* It enables
|
| 35 |
+
* [automatic capturing of promise rejection](https://nodejs.org/docs/latest-v25.x/api/events.html#capture-rejections-of-promises).
|
| 36 |
+
* @default false
|
| 37 |
+
*/
|
| 38 |
+
captureRejections?: boolean | undefined;
|
| 39 |
+
}
|
| 40 |
+
/**
|
| 41 |
+
* The `EventEmitter` class is defined and exposed by the `node:events` module:
|
| 42 |
+
*
|
| 43 |
+
* ```js
|
| 44 |
+
* import { EventEmitter } from 'node:events';
|
| 45 |
+
* ```
|
| 46 |
+
*
|
| 47 |
+
* All `EventEmitter`s emit the event `'newListener'` when new listeners are
|
| 48 |
+
* added and `'removeListener'` when existing listeners are removed.
|
| 49 |
+
*
|
| 50 |
+
* It supports the following option:
|
| 51 |
+
* @since v0.1.26
|
| 52 |
+
*/
|
| 53 |
+
class EventEmitter<T extends EventMap<T> = any> {
|
| 54 |
+
constructor(options?: EventEmitterOptions);
|
| 55 |
+
}
|
| 56 |
+
interface EventEmitter<T extends EventMap<T> = any> extends NodeJS.EventEmitter<T> {}
|
| 57 |
+
global {
|
| 58 |
+
namespace NodeJS {
|
| 59 |
+
interface EventEmitter<T extends EventMap<T> = any> {
|
| 60 |
+
/**
|
| 61 |
+
* The `Symbol.for('nodejs.rejection')` method is called in case a
|
| 62 |
+
* promise rejection happens when emitting an event and
|
| 63 |
+
* `captureRejections` is enabled on the emitter.
|
| 64 |
+
* It is possible to use `events.captureRejectionSymbol` in
|
| 65 |
+
* place of `Symbol.for('nodejs.rejection')`.
|
| 66 |
+
*
|
| 67 |
+
* ```js
|
| 68 |
+
* import { EventEmitter, captureRejectionSymbol } from 'node:events';
|
| 69 |
+
*
|
| 70 |
+
* class MyClass extends EventEmitter {
|
| 71 |
+
* constructor() {
|
| 72 |
+
* super({ captureRejections: true });
|
| 73 |
+
* }
|
| 74 |
+
*
|
| 75 |
+
* [captureRejectionSymbol](err, event, ...args) {
|
| 76 |
+
* console.log('rejection happened for', event, 'with', err, ...args);
|
| 77 |
+
* this.destroy(err);
|
| 78 |
+
* }
|
| 79 |
+
*
|
| 80 |
+
* destroy(err) {
|
| 81 |
+
* // Tear the resource down here.
|
| 82 |
+
* }
|
| 83 |
+
* }
|
| 84 |
+
* ```
|
| 85 |
+
* @since v13.4.0, v12.16.0
|
| 86 |
+
*/
|
| 87 |
+
[EventEmitter.captureRejectionSymbol]?(error: Error, event: string | symbol, ...args: any[]): void;
|
| 88 |
+
/**
|
| 89 |
+
* Alias for `emitter.on(eventName, listener)`.
|
| 90 |
+
* @since v0.1.26
|
| 91 |
+
*/
|
| 92 |
+
addListener<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
| 93 |
+
/**
|
| 94 |
+
* Synchronously calls each of the listeners registered for the event named
|
| 95 |
+
* `eventName`, in the order they were registered, passing the supplied arguments
|
| 96 |
+
* to each.
|
| 97 |
+
*
|
| 98 |
+
* Returns `true` if the event had listeners, `false` otherwise.
|
| 99 |
+
*
|
| 100 |
+
* ```js
|
| 101 |
+
* import { EventEmitter } from 'node:events';
|
| 102 |
+
* const myEmitter = new EventEmitter();
|
| 103 |
+
*
|
| 104 |
+
* // First listener
|
| 105 |
+
* myEmitter.on('event', function firstListener() {
|
| 106 |
+
* console.log('Helloooo! first listener');
|
| 107 |
+
* });
|
| 108 |
+
* // Second listener
|
| 109 |
+
* myEmitter.on('event', function secondListener(arg1, arg2) {
|
| 110 |
+
* console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
|
| 111 |
+
* });
|
| 112 |
+
* // Third listener
|
| 113 |
+
* myEmitter.on('event', function thirdListener(...args) {
|
| 114 |
+
* const parameters = args.join(', ');
|
| 115 |
+
* console.log(`event with parameters ${parameters} in third listener`);
|
| 116 |
+
* });
|
| 117 |
+
*
|
| 118 |
+
* console.log(myEmitter.listeners('event'));
|
| 119 |
+
*
|
| 120 |
+
* myEmitter.emit('event', 1, 2, 3, 4, 5);
|
| 121 |
+
*
|
| 122 |
+
* // Prints:
|
| 123 |
+
* // [
|
| 124 |
+
* // [Function: firstListener],
|
| 125 |
+
* // [Function: secondListener],
|
| 126 |
+
* // [Function: thirdListener]
|
| 127 |
+
* // ]
|
| 128 |
+
* // Helloooo! first listener
|
| 129 |
+
* // event with parameters 1, 2 in second listener
|
| 130 |
+
* // event with parameters 1, 2, 3, 4, 5 in third listener
|
| 131 |
+
* ```
|
| 132 |
+
* @since v0.1.26
|
| 133 |
+
*/
|
| 134 |
+
emit<E extends string | symbol>(eventName: EventNames<T, E>, ...args: Args<T, E>): boolean;
|
| 135 |
+
/**
|
| 136 |
+
* Returns an array listing the events for which the emitter has registered
|
| 137 |
+
* listeners.
|
| 138 |
+
*
|
| 139 |
+
* ```js
|
| 140 |
+
* import { EventEmitter } from 'node:events';
|
| 141 |
+
*
|
| 142 |
+
* const myEE = new EventEmitter();
|
| 143 |
+
* myEE.on('foo', () => {});
|
| 144 |
+
* myEE.on('bar', () => {});
|
| 145 |
+
*
|
| 146 |
+
* const sym = Symbol('symbol');
|
| 147 |
+
* myEE.on(sym, () => {});
|
| 148 |
+
*
|
| 149 |
+
* console.log(myEE.eventNames());
|
| 150 |
+
* // Prints: [ 'foo', 'bar', Symbol(symbol) ]
|
| 151 |
+
* ```
|
| 152 |
+
* @since v6.0.0
|
| 153 |
+
*/
|
| 154 |
+
eventNames(): (string | symbol)[];
|
| 155 |
+
/**
|
| 156 |
+
* Returns the current max listener value for the `EventEmitter` which is either
|
| 157 |
+
* set by `emitter.setMaxListeners(n)` or defaults to
|
| 158 |
+
* `events.defaultMaxListeners`.
|
| 159 |
+
* @since v1.0.0
|
| 160 |
+
*/
|
| 161 |
+
getMaxListeners(): number;
|
| 162 |
+
/**
|
| 163 |
+
* Returns the number of listeners listening for the event named `eventName`.
|
| 164 |
+
* If `listener` is provided, it will return how many times the listener is found
|
| 165 |
+
* in the list of the listeners of the event.
|
| 166 |
+
* @since v3.2.0
|
| 167 |
+
* @param eventName The name of the event being listened for
|
| 168 |
+
* @param listener The event handler function
|
| 169 |
+
*/
|
| 170 |
+
listenerCount<E extends string | symbol>(
|
| 171 |
+
eventName: EventNames<T, E>,
|
| 172 |
+
listener?: Listener<T, E>,
|
| 173 |
+
): number;
|
| 174 |
+
/**
|
| 175 |
+
* Returns a copy of the array of listeners for the event named `eventName`.
|
| 176 |
+
*
|
| 177 |
+
* ```js
|
| 178 |
+
* server.on('connection', (stream) => {
|
| 179 |
+
* console.log('someone connected!');
|
| 180 |
+
* });
|
| 181 |
+
* console.log(util.inspect(server.listeners('connection')));
|
| 182 |
+
* // Prints: [ [Function] ]
|
| 183 |
+
* ```
|
| 184 |
+
* @since v0.1.26
|
| 185 |
+
*/
|
| 186 |
+
listeners<E extends string | symbol>(eventName: EventNames<T, E>): Listener<T, E>[];
|
| 187 |
+
/**
|
| 188 |
+
* Alias for `emitter.removeListener()`.
|
| 189 |
+
* @since v10.0.0
|
| 190 |
+
*/
|
| 191 |
+
off<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
| 192 |
+
/**
|
| 193 |
+
* Adds the `listener` function to the end of the listeners array for the
|
| 194 |
+
* event named `eventName`. No checks are made to see if the `listener` has
|
| 195 |
+
* already been added. Multiple calls passing the same combination of `eventName`
|
| 196 |
+
* and `listener` will result in the `listener` being added, and called, multiple
|
| 197 |
+
* times.
|
| 198 |
+
*
|
| 199 |
+
* ```js
|
| 200 |
+
* server.on('connection', (stream) => {
|
| 201 |
+
* console.log('someone connected!');
|
| 202 |
+
* });
|
| 203 |
+
* ```
|
| 204 |
+
*
|
| 205 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
| 206 |
+
*
|
| 207 |
+
* By default, event listeners are invoked in the order they are added. The
|
| 208 |
+
* `emitter.prependListener()` method can be used as an alternative to add the
|
| 209 |
+
* event listener to the beginning of the listeners array.
|
| 210 |
+
*
|
| 211 |
+
* ```js
|
| 212 |
+
* import { EventEmitter } from 'node:events';
|
| 213 |
+
* const myEE = new EventEmitter();
|
| 214 |
+
* myEE.on('foo', () => console.log('a'));
|
| 215 |
+
* myEE.prependListener('foo', () => console.log('b'));
|
| 216 |
+
* myEE.emit('foo');
|
| 217 |
+
* // Prints:
|
| 218 |
+
* // b
|
| 219 |
+
* // a
|
| 220 |
+
* ```
|
| 221 |
+
* @since v0.1.101
|
| 222 |
+
* @param eventName The name of the event.
|
| 223 |
+
* @param listener The callback function
|
| 224 |
+
*/
|
| 225 |
+
on<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
| 226 |
+
/**
|
| 227 |
+
* Adds a **one-time** `listener` function for the event named `eventName`. The
|
| 228 |
+
* next time `eventName` is triggered, this listener is removed and then invoked.
|
| 229 |
+
*
|
| 230 |
+
* ```js
|
| 231 |
+
* server.once('connection', (stream) => {
|
| 232 |
+
* console.log('Ah, we have our first user!');
|
| 233 |
+
* });
|
| 234 |
+
* ```
|
| 235 |
+
*
|
| 236 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
| 237 |
+
*
|
| 238 |
+
* By default, event listeners are invoked in the order they are added. The
|
| 239 |
+
* `emitter.prependOnceListener()` method can be used as an alternative to add the
|
| 240 |
+
* event listener to the beginning of the listeners array.
|
| 241 |
+
*
|
| 242 |
+
* ```js
|
| 243 |
+
* import { EventEmitter } from 'node:events';
|
| 244 |
+
* const myEE = new EventEmitter();
|
| 245 |
+
* myEE.once('foo', () => console.log('a'));
|
| 246 |
+
* myEE.prependOnceListener('foo', () => console.log('b'));
|
| 247 |
+
* myEE.emit('foo');
|
| 248 |
+
* // Prints:
|
| 249 |
+
* // b
|
| 250 |
+
* // a
|
| 251 |
+
* ```
|
| 252 |
+
* @since v0.3.0
|
| 253 |
+
* @param eventName The name of the event.
|
| 254 |
+
* @param listener The callback function
|
| 255 |
+
*/
|
| 256 |
+
once<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
| 257 |
+
/**
|
| 258 |
+
* Adds the `listener` function to the _beginning_ of the listeners array for the
|
| 259 |
+
* event named `eventName`. No checks are made to see if the `listener` has
|
| 260 |
+
* already been added. Multiple calls passing the same combination of `eventName`
|
| 261 |
+
* and `listener` will result in the `listener` being added, and called, multiple
|
| 262 |
+
* times.
|
| 263 |
+
*
|
| 264 |
+
* ```js
|
| 265 |
+
* server.prependListener('connection', (stream) => {
|
| 266 |
+
* console.log('someone connected!');
|
| 267 |
+
* });
|
| 268 |
+
* ```
|
| 269 |
+
*
|
| 270 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
| 271 |
+
* @since v6.0.0
|
| 272 |
+
* @param eventName The name of the event.
|
| 273 |
+
* @param listener The callback function
|
| 274 |
+
*/
|
| 275 |
+
prependListener<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
| 276 |
+
/**
|
| 277 |
+
* Adds a **one-time** `listener` function for the event named `eventName` to the
|
| 278 |
+
* _beginning_ of the listeners array. The next time `eventName` is triggered, this
|
| 279 |
+
* listener is removed, and then invoked.
|
| 280 |
+
*
|
| 281 |
+
* ```js
|
| 282 |
+
* server.prependOnceListener('connection', (stream) => {
|
| 283 |
+
* console.log('Ah, we have our first user!');
|
| 284 |
+
* });
|
| 285 |
+
* ```
|
| 286 |
+
*
|
| 287 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
| 288 |
+
* @since v6.0.0
|
| 289 |
+
* @param eventName The name of the event.
|
| 290 |
+
* @param listener The callback function
|
| 291 |
+
*/
|
| 292 |
+
prependOnceListener<E extends string | symbol>(
|
| 293 |
+
eventName: EventNames<T, E>,
|
| 294 |
+
listener: Listener<T, E>,
|
| 295 |
+
): this;
|
| 296 |
+
/**
|
| 297 |
+
* Returns a copy of the array of listeners for the event named `eventName`,
|
| 298 |
+
* including any wrappers (such as those created by `.once()`).
|
| 299 |
+
*
|
| 300 |
+
* ```js
|
| 301 |
+
* import { EventEmitter } from 'node:events';
|
| 302 |
+
* const emitter = new EventEmitter();
|
| 303 |
+
* emitter.once('log', () => console.log('log once'));
|
| 304 |
+
*
|
| 305 |
+
* // Returns a new Array with a function `onceWrapper` which has a property
|
| 306 |
+
* // `listener` which contains the original listener bound above
|
| 307 |
+
* const listeners = emitter.rawListeners('log');
|
| 308 |
+
* const logFnWrapper = listeners[0];
|
| 309 |
+
*
|
| 310 |
+
* // Logs "log once" to the console and does not unbind the `once` event
|
| 311 |
+
* logFnWrapper.listener();
|
| 312 |
+
*
|
| 313 |
+
* // Logs "log once" to the console and removes the listener
|
| 314 |
+
* logFnWrapper();
|
| 315 |
+
*
|
| 316 |
+
* emitter.on('log', () => console.log('log persistently'));
|
| 317 |
+
* // Will return a new Array with a single function bound by `.on()` above
|
| 318 |
+
* const newListeners = emitter.rawListeners('log');
|
| 319 |
+
*
|
| 320 |
+
* // Logs "log persistently" twice
|
| 321 |
+
* newListeners[0]();
|
| 322 |
+
* emitter.emit('log');
|
| 323 |
+
* ```
|
| 324 |
+
* @since v9.4.0
|
| 325 |
+
*/
|
| 326 |
+
rawListeners<E extends string | symbol>(eventName: EventNames<T, E>): Listener<T, E>[];
|
| 327 |
+
/**
|
| 328 |
+
* Removes all listeners, or those of the specified `eventName`.
|
| 329 |
+
*
|
| 330 |
+
* It is bad practice to remove listeners added elsewhere in the code,
|
| 331 |
+
* particularly when the `EventEmitter` instance was created by some other
|
| 332 |
+
* component or module (e.g. sockets or file streams).
|
| 333 |
+
*
|
| 334 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
| 335 |
+
* @since v0.1.26
|
| 336 |
+
*/
|
| 337 |
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
| 338 |
+
removeAllListeners<E extends string | symbol>(eventName?: EventNames<T, E>): this;
|
| 339 |
+
/**
|
| 340 |
+
* Removes the specified `listener` from the listener array for the event named
|
| 341 |
+
* `eventName`.
|
| 342 |
+
*
|
| 343 |
+
* ```js
|
| 344 |
+
* const callback = (stream) => {
|
| 345 |
+
* console.log('someone connected!');
|
| 346 |
+
* };
|
| 347 |
+
* server.on('connection', callback);
|
| 348 |
+
* // ...
|
| 349 |
+
* server.removeListener('connection', callback);
|
| 350 |
+
* ```
|
| 351 |
+
*
|
| 352 |
+
* `removeListener()` will remove, at most, one instance of a listener from the
|
| 353 |
+
* listener array. If any single listener has been added multiple times to the
|
| 354 |
+
* listener array for the specified `eventName`, then `removeListener()` must be
|
| 355 |
+
* called multiple times to remove each instance.
|
| 356 |
+
*
|
| 357 |
+
* Once an event is emitted, all listeners attached to it at the
|
| 358 |
+
* time of emitting are called in order. This implies that any
|
| 359 |
+
* `removeListener()` or `removeAllListeners()` calls _after_ emitting and
|
| 360 |
+
* _before_ the last listener finishes execution will not remove them from
|
| 361 |
+
* `emit()` in progress. Subsequent events behave as expected.
|
| 362 |
+
*
|
| 363 |
+
* ```js
|
| 364 |
+
* import { EventEmitter } from 'node:events';
|
| 365 |
+
* class MyEmitter extends EventEmitter {}
|
| 366 |
+
* const myEmitter = new MyEmitter();
|
| 367 |
+
*
|
| 368 |
+
* const callbackA = () => {
|
| 369 |
+
* console.log('A');
|
| 370 |
+
* myEmitter.removeListener('event', callbackB);
|
| 371 |
+
* };
|
| 372 |
+
*
|
| 373 |
+
* const callbackB = () => {
|
| 374 |
+
* console.log('B');
|
| 375 |
+
* };
|
| 376 |
+
*
|
| 377 |
+
* myEmitter.on('event', callbackA);
|
| 378 |
+
*
|
| 379 |
+
* myEmitter.on('event', callbackB);
|
| 380 |
+
*
|
| 381 |
+
* // callbackA removes listener callbackB but it will still be called.
|
| 382 |
+
* // Internal listener array at time of emit [callbackA, callbackB]
|
| 383 |
+
* myEmitter.emit('event');
|
| 384 |
+
* // Prints:
|
| 385 |
+
* // A
|
| 386 |
+
* // B
|
| 387 |
+
*
|
| 388 |
+
* // callbackB is now removed.
|
| 389 |
+
* // Internal listener array [callbackA]
|
| 390 |
+
* myEmitter.emit('event');
|
| 391 |
+
* // Prints:
|
| 392 |
+
* // A
|
| 393 |
+
* ```
|
| 394 |
+
*
|
| 395 |
+
* Because listeners are managed using an internal array, calling this will
|
| 396 |
+
* change the position indexes of any listener registered _after_ the listener
|
| 397 |
+
* being removed. This will not impact the order in which listeners are called,
|
| 398 |
+
* but it means that any copies of the listener array as returned by
|
| 399 |
+
* the `emitter.listeners()` method will need to be recreated.
|
| 400 |
+
*
|
| 401 |
+
* When a single function has been added as a handler multiple times for a single
|
| 402 |
+
* event (as in the example below), `removeListener()` will remove the most
|
| 403 |
+
* recently added instance. In the example the `once('ping')`
|
| 404 |
+
* listener is removed:
|
| 405 |
+
*
|
| 406 |
+
* ```js
|
| 407 |
+
* import { EventEmitter } from 'node:events';
|
| 408 |
+
* const ee = new EventEmitter();
|
| 409 |
+
*
|
| 410 |
+
* function pong() {
|
| 411 |
+
* console.log('pong');
|
| 412 |
+
* }
|
| 413 |
+
*
|
| 414 |
+
* ee.on('ping', pong);
|
| 415 |
+
* ee.once('ping', pong);
|
| 416 |
+
* ee.removeListener('ping', pong);
|
| 417 |
+
*
|
| 418 |
+
* ee.emit('ping');
|
| 419 |
+
* ee.emit('ping');
|
| 420 |
+
* ```
|
| 421 |
+
*
|
| 422 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
| 423 |
+
* @since v0.1.26
|
| 424 |
+
*/
|
| 425 |
+
removeListener<E extends string | symbol>(eventName: EventNames<T, E>, listener: Listener<T, E>): this;
|
| 426 |
+
/**
|
| 427 |
+
* By default `EventEmitter`s will print a warning if more than `10` listeners are
|
| 428 |
+
* added for a particular event. This is a useful default that helps finding
|
| 429 |
+
* memory leaks. The `emitter.setMaxListeners()` method allows the limit to be
|
| 430 |
+
* modified for this specific `EventEmitter` instance. The value can be set to
|
| 431 |
+
* `Infinity` (or `0`) to indicate an unlimited number of listeners.
|
| 432 |
+
*
|
| 433 |
+
* Returns a reference to the `EventEmitter`, so that calls can be chained.
|
| 434 |
+
* @since v0.3.5
|
| 435 |
+
*/
|
| 436 |
+
setMaxListeners(n: number): this;
|
| 437 |
+
}
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
namespace EventEmitter {
|
| 441 |
+
export { EventEmitter, EventEmitterEventMap, EventEmitterOptions };
|
| 442 |
+
}
|
| 443 |
+
namespace EventEmitter {
|
| 444 |
+
interface Abortable {
|
| 445 |
+
signal?: AbortSignal | undefined;
|
| 446 |
+
}
|
| 447 |
+
/**
|
| 448 |
+
* See how to write a custom [rejection handler](https://nodejs.org/docs/latest-v25.x/api/events.html#emittersymbolfornodejsrejectionerr-eventname-args).
|
| 449 |
+
* @since v13.4.0, v12.16.0
|
| 450 |
+
*/
|
| 451 |
+
const captureRejectionSymbol: unique symbol;
|
| 452 |
+
/**
|
| 453 |
+
* Change the default `captureRejections` option on all new `EventEmitter` objects.
|
| 454 |
+
* @since v13.4.0, v12.16.0
|
| 455 |
+
*/
|
| 456 |
+
let captureRejections: boolean;
|
| 457 |
+
/**
|
| 458 |
+
* By default, a maximum of `10` listeners can be registered for any single
|
| 459 |
+
* event. This limit can be changed for individual `EventEmitter` instances
|
| 460 |
+
* using the `emitter.setMaxListeners(n)` method. To change the default
|
| 461 |
+
* for _all_ `EventEmitter` instances, the `events.defaultMaxListeners`
|
| 462 |
+
* property can be used. If this value is not a positive number, a `RangeError`
|
| 463 |
+
* is thrown.
|
| 464 |
+
*
|
| 465 |
+
* Take caution when setting the `events.defaultMaxListeners` because the
|
| 466 |
+
* change affects _all_ `EventEmitter` instances, including those created before
|
| 467 |
+
* the change is made. However, calling `emitter.setMaxListeners(n)` still has
|
| 468 |
+
* precedence over `events.defaultMaxListeners`.
|
| 469 |
+
*
|
| 470 |
+
* This is not a hard limit. The `EventEmitter` instance will allow
|
| 471 |
+
* more listeners to be added but will output a trace warning to stderr indicating
|
| 472 |
+
* that a "possible EventEmitter memory leak" has been detected. For any single
|
| 473 |
+
* `EventEmitter`, the `emitter.getMaxListeners()` and `emitter.setMaxListeners()`
|
| 474 |
+
* methods can be used to temporarily avoid this warning:
|
| 475 |
+
*
|
| 476 |
+
* `defaultMaxListeners` has no effect on `AbortSignal` instances. While it is
|
| 477 |
+
* still possible to use `emitter.setMaxListeners(n)` to set a warning limit
|
| 478 |
+
* for individual `AbortSignal` instances, per default `AbortSignal` instances will not warn.
|
| 479 |
+
*
|
| 480 |
+
* ```js
|
| 481 |
+
* import { EventEmitter } from 'node:events';
|
| 482 |
+
* const emitter = new EventEmitter();
|
| 483 |
+
* emitter.setMaxListeners(emitter.getMaxListeners() + 1);
|
| 484 |
+
* emitter.once('event', () => {
|
| 485 |
+
* // do stuff
|
| 486 |
+
* emitter.setMaxListeners(Math.max(emitter.getMaxListeners() - 1, 0));
|
| 487 |
+
* });
|
| 488 |
+
* ```
|
| 489 |
+
*
|
| 490 |
+
* The `--trace-warnings` command-line flag can be used to display the
|
| 491 |
+
* stack trace for such warnings.
|
| 492 |
+
*
|
| 493 |
+
* The emitted warning can be inspected with `process.on('warning')` and will
|
| 494 |
+
* have the additional `emitter`, `type`, and `count` properties, referring to
|
| 495 |
+
* the event emitter instance, the event's name and the number of attached
|
| 496 |
+
* listeners, respectively.
|
| 497 |
+
* Its `name` property is set to `'MaxListenersExceededWarning'`.
|
| 498 |
+
* @since v0.11.2
|
| 499 |
+
*/
|
| 500 |
+
let defaultMaxListeners: number;
|
| 501 |
+
/**
|
| 502 |
+
* This symbol shall be used to install a listener for only monitoring `'error'`
|
| 503 |
+
* events. Listeners installed using this symbol are called before the regular
|
| 504 |
+
* `'error'` listeners are called.
|
| 505 |
+
*
|
| 506 |
+
* Installing a listener using this symbol does not change the behavior once an
|
| 507 |
+
* `'error'` event is emitted. Therefore, the process will still crash if no
|
| 508 |
+
* regular `'error'` listener is installed.
|
| 509 |
+
* @since v13.6.0, v12.17.0
|
| 510 |
+
*/
|
| 511 |
+
const errorMonitor: unique symbol;
|
| 512 |
+
/**
|
| 513 |
+
* Listens once to the `abort` event on the provided `signal`.
|
| 514 |
+
*
|
| 515 |
+
* Listening to the `abort` event on abort signals is unsafe and may
|
| 516 |
+
* lead to resource leaks since another third party with the signal can
|
| 517 |
+
* call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change
|
| 518 |
+
* this since it would violate the web standard. Additionally, the original
|
| 519 |
+
* API makes it easy to forget to remove listeners.
|
| 520 |
+
*
|
| 521 |
+
* This API allows safely using `AbortSignal`s in Node.js APIs by solving these
|
| 522 |
+
* two issues by listening to the event such that `stopImmediatePropagation` does
|
| 523 |
+
* not prevent the listener from running.
|
| 524 |
+
*
|
| 525 |
+
* Returns a disposable so that it may be unsubscribed from more easily.
|
| 526 |
+
*
|
| 527 |
+
* ```js
|
| 528 |
+
* import { addAbortListener } from 'node:events';
|
| 529 |
+
*
|
| 530 |
+
* function example(signal) {
|
| 531 |
+
* signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
|
| 532 |
+
* // addAbortListener() returns a disposable, so the `using` keyword ensures
|
| 533 |
+
* // the abort listener is automatically removed when this scope exits.
|
| 534 |
+
* using _ = addAbortListener(signal, (e) => {
|
| 535 |
+
* // Do something when signal is aborted.
|
| 536 |
+
* });
|
| 537 |
+
* }
|
| 538 |
+
* ```
|
| 539 |
+
* @since v20.5.0
|
| 540 |
+
* @return Disposable that removes the `abort` listener.
|
| 541 |
+
*/
|
| 542 |
+
function addAbortListener(signal: AbortSignal, resource: (event: Event) => void): Disposable;
|
| 543 |
+
/**
|
| 544 |
+
* Returns a copy of the array of listeners for the event named `eventName`.
|
| 545 |
+
*
|
| 546 |
+
* For `EventEmitter`s this behaves exactly the same as calling `.listeners` on
|
| 547 |
+
* the emitter.
|
| 548 |
+
*
|
| 549 |
+
* For `EventTarget`s this is the only way to get the event listeners for the
|
| 550 |
+
* event target. This is useful for debugging and diagnostic purposes.
|
| 551 |
+
*
|
| 552 |
+
* ```js
|
| 553 |
+
* import { getEventListeners, EventEmitter } from 'node:events';
|
| 554 |
+
*
|
| 555 |
+
* {
|
| 556 |
+
* const ee = new EventEmitter();
|
| 557 |
+
* const listener = () => console.log('Events are fun');
|
| 558 |
+
* ee.on('foo', listener);
|
| 559 |
+
* console.log(getEventListeners(ee, 'foo')); // [ [Function: listener] ]
|
| 560 |
+
* }
|
| 561 |
+
* {
|
| 562 |
+
* const et = new EventTarget();
|
| 563 |
+
* const listener = () => console.log('Events are fun');
|
| 564 |
+
* et.addEventListener('foo', listener);
|
| 565 |
+
* console.log(getEventListeners(et, 'foo')); // [ [Function: listener] ]
|
| 566 |
+
* }
|
| 567 |
+
* ```
|
| 568 |
+
* @since v15.2.0, v14.17.0
|
| 569 |
+
*/
|
| 570 |
+
function getEventListeners(emitter: EventEmitter, name: string | symbol): ((...args: any[]) => void)[];
|
| 571 |
+
function getEventListeners(emitter: EventTarget, name: string): ((...args: any[]) => void)[];
|
| 572 |
+
/**
|
| 573 |
+
* Returns the currently set max amount of listeners.
|
| 574 |
+
*
|
| 575 |
+
* For `EventEmitter`s this behaves exactly the same as calling `.getMaxListeners` on
|
| 576 |
+
* the emitter.
|
| 577 |
+
*
|
| 578 |
+
* For `EventTarget`s this is the only way to get the max event listeners for the
|
| 579 |
+
* event target. If the number of event handlers on a single EventTarget exceeds
|
| 580 |
+
* the max set, the EventTarget will print a warning.
|
| 581 |
+
*
|
| 582 |
+
* ```js
|
| 583 |
+
* import { getMaxListeners, setMaxListeners, EventEmitter } from 'node:events';
|
| 584 |
+
*
|
| 585 |
+
* {
|
| 586 |
+
* const ee = new EventEmitter();
|
| 587 |
+
* console.log(getMaxListeners(ee)); // 10
|
| 588 |
+
* setMaxListeners(11, ee);
|
| 589 |
+
* console.log(getMaxListeners(ee)); // 11
|
| 590 |
+
* }
|
| 591 |
+
* {
|
| 592 |
+
* const et = new EventTarget();
|
| 593 |
+
* console.log(getMaxListeners(et)); // 10
|
| 594 |
+
* setMaxListeners(11, et);
|
| 595 |
+
* console.log(getMaxListeners(et)); // 11
|
| 596 |
+
* }
|
| 597 |
+
* ```
|
| 598 |
+
* @since v19.9.0
|
| 599 |
+
*/
|
| 600 |
+
function getMaxListeners(emitter: EventEmitter | EventTarget): number;
|
| 601 |
+
/**
|
| 602 |
+
* Returns the number of registered listeners for the event named `eventName`.
|
| 603 |
+
*
|
| 604 |
+
* For `EventEmitter`s this behaves exactly the same as calling `.listenerCount`
|
| 605 |
+
* on the emitter.
|
| 606 |
+
*
|
| 607 |
+
* For `EventTarget`s this is the only way to obtain the listener count. This can
|
| 608 |
+
* be useful for debugging and diagnostic purposes.
|
| 609 |
+
* @since v0.9.12
|
| 610 |
+
*/
|
| 611 |
+
function listenerCount(emitter: EventEmitter, eventName: string | symbol): number;
|
| 612 |
+
function listenerCount(emitter: EventTarget, eventName: string): number;
|
| 613 |
+
interface OnOptions extends Abortable {
|
| 614 |
+
/**
|
| 615 |
+
* Names of events that will end the iteration.
|
| 616 |
+
*/
|
| 617 |
+
close?: readonly string[] | undefined;
|
| 618 |
+
/**
|
| 619 |
+
* The high watermark. The emitter is paused every time the size of events
|
| 620 |
+
* being buffered is higher than it. Supported only on emitters implementing
|
| 621 |
+
* `pause()` and `resume()` methods.
|
| 622 |
+
* @default Number.MAX_SAFE_INTEGER
|
| 623 |
+
*/
|
| 624 |
+
highWaterMark?: number | undefined;
|
| 625 |
+
/**
|
| 626 |
+
* The low watermark. The emitter is resumed every time the size of events
|
| 627 |
+
* being buffered is lower than it. Supported only on emitters implementing
|
| 628 |
+
* `pause()` and `resume()` methods.
|
| 629 |
+
* @default 1
|
| 630 |
+
*/
|
| 631 |
+
lowWaterMark?: number | undefined;
|
| 632 |
+
}
|
| 633 |
+
/**
|
| 634 |
+
* ```js
|
| 635 |
+
* import { on, EventEmitter } from 'node:events';
|
| 636 |
+
* import process from 'node:process';
|
| 637 |
+
*
|
| 638 |
+
* const ee = new EventEmitter();
|
| 639 |
+
*
|
| 640 |
+
* // Emit later on
|
| 641 |
+
* process.nextTick(() => {
|
| 642 |
+
* ee.emit('foo', 'bar');
|
| 643 |
+
* ee.emit('foo', 42);
|
| 644 |
+
* });
|
| 645 |
+
*
|
| 646 |
+
* for await (const event of on(ee, 'foo')) {
|
| 647 |
+
* // The execution of this inner block is synchronous and it
|
| 648 |
+
* // processes one event at a time (even with await). Do not use
|
| 649 |
+
* // if concurrent execution is required.
|
| 650 |
+
* console.log(event); // prints ['bar'] [42]
|
| 651 |
+
* }
|
| 652 |
+
* // Unreachable here
|
| 653 |
+
* ```
|
| 654 |
+
*
|
| 655 |
+
* Returns an `AsyncIterator` that iterates `eventName` events. It will throw
|
| 656 |
+
* if the `EventEmitter` emits `'error'`. It removes all listeners when
|
| 657 |
+
* exiting the loop. The `value` returned by each iteration is an array
|
| 658 |
+
* composed of the emitted event arguments.
|
| 659 |
+
*
|
| 660 |
+
* An `AbortSignal` can be used to cancel waiting on events:
|
| 661 |
+
*
|
| 662 |
+
* ```js
|
| 663 |
+
* import { on, EventEmitter } from 'node:events';
|
| 664 |
+
* import process from 'node:process';
|
| 665 |
+
*
|
| 666 |
+
* const ac = new AbortController();
|
| 667 |
+
*
|
| 668 |
+
* (async () => {
|
| 669 |
+
* const ee = new EventEmitter();
|
| 670 |
+
*
|
| 671 |
+
* // Emit later on
|
| 672 |
+
* process.nextTick(() => {
|
| 673 |
+
* ee.emit('foo', 'bar');
|
| 674 |
+
* ee.emit('foo', 42);
|
| 675 |
+
* });
|
| 676 |
+
*
|
| 677 |
+
* for await (const event of on(ee, 'foo', { signal: ac.signal })) {
|
| 678 |
+
* // The execution of this inner block is synchronous and it
|
| 679 |
+
* // processes one event at a time (even with await). Do not use
|
| 680 |
+
* // if concurrent execution is required.
|
| 681 |
+
* console.log(event); // prints ['bar'] [42]
|
| 682 |
+
* }
|
| 683 |
+
* // Unreachable here
|
| 684 |
+
* })();
|
| 685 |
+
*
|
| 686 |
+
* process.nextTick(() => ac.abort());
|
| 687 |
+
* ```
|
| 688 |
+
* @since v13.6.0, v12.16.0
|
| 689 |
+
* @returns `AsyncIterator` that iterates `eventName` events emitted by the `emitter`
|
| 690 |
+
*/
|
| 691 |
+
function on(
|
| 692 |
+
emitter: EventEmitter,
|
| 693 |
+
eventName: string | symbol,
|
| 694 |
+
options?: OnOptions,
|
| 695 |
+
): NodeJS.AsyncIterator<any[]>;
|
| 696 |
+
function on(
|
| 697 |
+
emitter: EventTarget,
|
| 698 |
+
eventName: string,
|
| 699 |
+
options?: OnOptions,
|
| 700 |
+
): NodeJS.AsyncIterator<any[]>;
|
| 701 |
+
interface OnceOptions extends Abortable {}
|
| 702 |
+
/**
|
| 703 |
+
* Creates a `Promise` that is fulfilled when the `EventEmitter` emits the given
|
| 704 |
+
* event or that is rejected if the `EventEmitter` emits `'error'` while waiting.
|
| 705 |
+
* The `Promise` will resolve with an array of all the arguments emitted to the
|
| 706 |
+
* given event.
|
| 707 |
+
*
|
| 708 |
+
* This method is intentionally generic and works with the web platform
|
| 709 |
+
* [EventTarget][WHATWG-EventTarget] interface, which has no special
|
| 710 |
+
* `'error'` event semantics and does not listen to the `'error'` event.
|
| 711 |
+
*
|
| 712 |
+
* ```js
|
| 713 |
+
* import { once, EventEmitter } from 'node:events';
|
| 714 |
+
* import process from 'node:process';
|
| 715 |
+
*
|
| 716 |
+
* const ee = new EventEmitter();
|
| 717 |
+
*
|
| 718 |
+
* process.nextTick(() => {
|
| 719 |
+
* ee.emit('myevent', 42);
|
| 720 |
+
* });
|
| 721 |
+
*
|
| 722 |
+
* const [value] = await once(ee, 'myevent');
|
| 723 |
+
* console.log(value);
|
| 724 |
+
*
|
| 725 |
+
* const err = new Error('kaboom');
|
| 726 |
+
* process.nextTick(() => {
|
| 727 |
+
* ee.emit('error', err);
|
| 728 |
+
* });
|
| 729 |
+
*
|
| 730 |
+
* try {
|
| 731 |
+
* await once(ee, 'myevent');
|
| 732 |
+
* } catch (err) {
|
| 733 |
+
* console.error('error happened', err);
|
| 734 |
+
* }
|
| 735 |
+
* ```
|
| 736 |
+
*
|
| 737 |
+
* The special handling of the `'error'` event is only used when `events.once()`
|
| 738 |
+
* is used to wait for another event. If `events.once()` is used to wait for the
|
| 739 |
+
* '`error'` event itself, then it is treated as any other kind of event without
|
| 740 |
+
* special handling:
|
| 741 |
+
*
|
| 742 |
+
* ```js
|
| 743 |
+
* import { EventEmitter, once } from 'node:events';
|
| 744 |
+
*
|
| 745 |
+
* const ee = new EventEmitter();
|
| 746 |
+
*
|
| 747 |
+
* once(ee, 'error')
|
| 748 |
+
* .then(([err]) => console.log('ok', err.message))
|
| 749 |
+
* .catch((err) => console.error('error', err.message));
|
| 750 |
+
*
|
| 751 |
+
* ee.emit('error', new Error('boom'));
|
| 752 |
+
*
|
| 753 |
+
* // Prints: ok boom
|
| 754 |
+
* ```
|
| 755 |
+
*
|
| 756 |
+
* An `AbortSignal` can be used to cancel waiting for the event:
|
| 757 |
+
*
|
| 758 |
+
* ```js
|
| 759 |
+
* import { EventEmitter, once } from 'node:events';
|
| 760 |
+
*
|
| 761 |
+
* const ee = new EventEmitter();
|
| 762 |
+
* const ac = new AbortController();
|
| 763 |
+
*
|
| 764 |
+
* async function foo(emitter, event, signal) {
|
| 765 |
+
* try {
|
| 766 |
+
* await once(emitter, event, { signal });
|
| 767 |
+
* console.log('event emitted!');
|
| 768 |
+
* } catch (error) {
|
| 769 |
+
* if (error.name === 'AbortError') {
|
| 770 |
+
* console.error('Waiting for the event was canceled!');
|
| 771 |
+
* } else {
|
| 772 |
+
* console.error('There was an error', error.message);
|
| 773 |
+
* }
|
| 774 |
+
* }
|
| 775 |
+
* }
|
| 776 |
+
*
|
| 777 |
+
* foo(ee, 'foo', ac.signal);
|
| 778 |
+
* ac.abort(); // Prints: Waiting for the event was canceled!
|
| 779 |
+
* ```
|
| 780 |
+
* @since v11.13.0, v10.16.0
|
| 781 |
+
*/
|
| 782 |
+
function once(
|
| 783 |
+
emitter: EventEmitter,
|
| 784 |
+
eventName: string | symbol,
|
| 785 |
+
options?: OnceOptions,
|
| 786 |
+
): Promise<any[]>;
|
| 787 |
+
function once(emitter: EventTarget, eventName: string, options?: OnceOptions): Promise<any[]>;
|
| 788 |
+
/**
|
| 789 |
+
* ```js
|
| 790 |
+
* import { setMaxListeners, EventEmitter } from 'node:events';
|
| 791 |
+
*
|
| 792 |
+
* const target = new EventTarget();
|
| 793 |
+
* const emitter = new EventEmitter();
|
| 794 |
+
*
|
| 795 |
+
* setMaxListeners(5, target, emitter);
|
| 796 |
+
* ```
|
| 797 |
+
* @since v15.4.0
|
| 798 |
+
* @param n A non-negative number. The maximum number of listeners per `EventTarget` event.
|
| 799 |
+
* @param eventTargets Zero or more `EventTarget`
|
| 800 |
+
* or `EventEmitter` instances. If none are specified, `n` is set as the default
|
| 801 |
+
* max for all newly created `EventTarget` and `EventEmitter` objects.
|
| 802 |
+
* objects.
|
| 803 |
+
*/
|
| 804 |
+
function setMaxListeners(n: number, ...eventTargets: ReadonlyArray<EventEmitter | EventTarget>): void;
|
| 805 |
+
/**
|
| 806 |
+
* This is the interface from which event-emitting Node.js APIs inherit in the types package.
|
| 807 |
+
* **It is not intended for consumer use.**
|
| 808 |
+
*
|
| 809 |
+
* It provides event-mapped definitions similar to EventEmitter, except that its signatures
|
| 810 |
+
* are deliberately permissive: they provide type _hinting_, but not rigid type-checking,
|
| 811 |
+
* for compatibility reasons.
|
| 812 |
+
*
|
| 813 |
+
* Classes that inherit directly from EventEmitter in JavaScript can inherit directly from
|
| 814 |
+
* this interface in the type definitions. Classes that are more than one inheritance level
|
| 815 |
+
* away from EventEmitter (eg. `net.Socket` > `stream.Duplex` > `EventEmitter`) must instead
|
| 816 |
+
* copy these method definitions into the derived class. Search "#region InternalEventEmitter"
|
| 817 |
+
* for examples.
|
| 818 |
+
* @internal
|
| 819 |
+
*/
|
| 820 |
+
interface InternalEventEmitter<T extends EventMap<T>> extends EventEmitter {
|
| 821 |
+
addListener<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
|
| 822 |
+
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 823 |
+
emit<E extends keyof T>(eventName: E, ...args: T[E]): boolean;
|
| 824 |
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
| 825 |
+
listenerCount<E extends keyof T>(eventName: E, listener?: (...args: T[E]) => void): number;
|
| 826 |
+
listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
|
| 827 |
+
listeners<E extends keyof T>(eventName: E): ((...args: T[E]) => void)[];
|
| 828 |
+
listeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 829 |
+
off<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
|
| 830 |
+
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 831 |
+
on<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
|
| 832 |
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 833 |
+
once<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
|
| 834 |
+
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 835 |
+
prependListener<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
|
| 836 |
+
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 837 |
+
prependOnceListener<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
|
| 838 |
+
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 839 |
+
rawListeners<E extends keyof T>(eventName: E): ((...args: T[E]) => void)[];
|
| 840 |
+
rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 841 |
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
| 842 |
+
removeAllListeners<E extends keyof T>(eventName?: E): this;
|
| 843 |
+
removeAllListeners(eventName?: string | symbol): this;
|
| 844 |
+
removeListener<E extends keyof T>(eventName: E, listener: (...args: T[E]) => void): this;
|
| 845 |
+
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 846 |
+
}
|
| 847 |
+
interface EventEmitterReferencingAsyncResource extends AsyncResource {
|
| 848 |
+
readonly eventEmitter: EventEmitterAsyncResource;
|
| 849 |
+
}
|
| 850 |
+
interface EventEmitterAsyncResourceOptions extends AsyncResourceOptions, EventEmitterOptions {
|
| 851 |
+
/**
|
| 852 |
+
* The type of async event.
|
| 853 |
+
* @default new.target.name
|
| 854 |
+
*/
|
| 855 |
+
name?: string | undefined;
|
| 856 |
+
}
|
| 857 |
+
/**
|
| 858 |
+
* Integrates `EventEmitter` with `AsyncResource` for `EventEmitter`s that
|
| 859 |
+
* require manual async tracking. Specifically, all events emitted by instances
|
| 860 |
+
* of `events.EventEmitterAsyncResource` will run within its [async context](https://nodejs.org/docs/latest-v25.x/api/async_context.html).
|
| 861 |
+
*
|
| 862 |
+
* ```js
|
| 863 |
+
* import { EventEmitterAsyncResource, EventEmitter } from 'node:events';
|
| 864 |
+
* import { notStrictEqual, strictEqual } from 'node:assert';
|
| 865 |
+
* import { executionAsyncId, triggerAsyncId } from 'node:async_hooks';
|
| 866 |
+
*
|
| 867 |
+
* // Async tracking tooling will identify this as 'Q'.
|
| 868 |
+
* const ee1 = new EventEmitterAsyncResource({ name: 'Q' });
|
| 869 |
+
*
|
| 870 |
+
* // 'foo' listeners will run in the EventEmitters async context.
|
| 871 |
+
* ee1.on('foo', () => {
|
| 872 |
+
* strictEqual(executionAsyncId(), ee1.asyncId);
|
| 873 |
+
* strictEqual(triggerAsyncId(), ee1.triggerAsyncId);
|
| 874 |
+
* });
|
| 875 |
+
*
|
| 876 |
+
* const ee2 = new EventEmitter();
|
| 877 |
+
*
|
| 878 |
+
* // 'foo' listeners on ordinary EventEmitters that do not track async
|
| 879 |
+
* // context, however, run in the same async context as the emit().
|
| 880 |
+
* ee2.on('foo', () => {
|
| 881 |
+
* notStrictEqual(executionAsyncId(), ee2.asyncId);
|
| 882 |
+
* notStrictEqual(triggerAsyncId(), ee2.triggerAsyncId);
|
| 883 |
+
* });
|
| 884 |
+
*
|
| 885 |
+
* Promise.resolve().then(() => {
|
| 886 |
+
* ee1.emit('foo');
|
| 887 |
+
* ee2.emit('foo');
|
| 888 |
+
* });
|
| 889 |
+
* ```
|
| 890 |
+
*
|
| 891 |
+
* The `EventEmitterAsyncResource` class has the same methods and takes the
|
| 892 |
+
* same options as `EventEmitter` and `AsyncResource` themselves.
|
| 893 |
+
* @since v17.4.0, v16.14.0
|
| 894 |
+
*/
|
| 895 |
+
class EventEmitterAsyncResource extends EventEmitter {
|
| 896 |
+
constructor(options?: EventEmitterAsyncResourceOptions);
|
| 897 |
+
/**
|
| 898 |
+
* The unique `asyncId` assigned to the resource.
|
| 899 |
+
*/
|
| 900 |
+
readonly asyncId: number;
|
| 901 |
+
/**
|
| 902 |
+
* The returned `AsyncResource` object has an additional `eventEmitter` property
|
| 903 |
+
* that provides a reference to this `EventEmitterAsyncResource`.
|
| 904 |
+
*/
|
| 905 |
+
readonly asyncResource: EventEmitterReferencingAsyncResource;
|
| 906 |
+
/**
|
| 907 |
+
* Call all `destroy` hooks. This should only ever be called once. An error will
|
| 908 |
+
* be thrown if it is called more than once. This **must** be manually called. If
|
| 909 |
+
* the resource is left to be collected by the GC then the `destroy` hooks will
|
| 910 |
+
* never be called.
|
| 911 |
+
*/
|
| 912 |
+
emitDestroy(): void;
|
| 913 |
+
/**
|
| 914 |
+
* The same `triggerAsyncId` that is passed to the
|
| 915 |
+
* `AsyncResource` constructor.
|
| 916 |
+
*/
|
| 917 |
+
readonly triggerAsyncId: number;
|
| 918 |
+
}
|
| 919 |
+
/**
|
| 920 |
+
* The `NodeEventTarget` is a Node.js-specific extension to `EventTarget`
|
| 921 |
+
* that emulates a subset of the `EventEmitter` API.
|
| 922 |
+
* @since v14.5.0
|
| 923 |
+
*/
|
| 924 |
+
interface NodeEventTarget extends EventTarget {
|
| 925 |
+
/**
|
| 926 |
+
* Node.js-specific extension to the `EventTarget` class that emulates the
|
| 927 |
+
* equivalent `EventEmitter` API. The only difference between `addListener()` and
|
| 928 |
+
* `addEventListener()` is that `addListener()` will return a reference to the
|
| 929 |
+
* `EventTarget`.
|
| 930 |
+
* @since v14.5.0
|
| 931 |
+
*/
|
| 932 |
+
addListener(type: string, listener: (arg: any) => void): this;
|
| 933 |
+
/**
|
| 934 |
+
* Node.js-specific extension to the `EventTarget` class that dispatches the
|
| 935 |
+
* `arg` to the list of handlers for `type`.
|
| 936 |
+
* @since v15.2.0
|
| 937 |
+
* @returns `true` if event listeners registered for the `type` exist,
|
| 938 |
+
* otherwise `false`.
|
| 939 |
+
*/
|
| 940 |
+
emit(type: string, arg: any): boolean;
|
| 941 |
+
/**
|
| 942 |
+
* Node.js-specific extension to the `EventTarget` class that returns an array
|
| 943 |
+
* of event `type` names for which event listeners are registered.
|
| 944 |
+
* @since 14.5.0
|
| 945 |
+
*/
|
| 946 |
+
eventNames(): string[];
|
| 947 |
+
/**
|
| 948 |
+
* Node.js-specific extension to the `EventTarget` class that returns the number
|
| 949 |
+
* of event listeners registered for the `type`.
|
| 950 |
+
* @since v14.5.0
|
| 951 |
+
*/
|
| 952 |
+
listenerCount(type: string): number;
|
| 953 |
+
/**
|
| 954 |
+
* Node.js-specific extension to the `EventTarget` class that sets the number
|
| 955 |
+
* of max event listeners as `n`.
|
| 956 |
+
* @since v14.5.0
|
| 957 |
+
*/
|
| 958 |
+
setMaxListeners(n: number): void;
|
| 959 |
+
/**
|
| 960 |
+
* Node.js-specific extension to the `EventTarget` class that returns the number
|
| 961 |
+
* of max event listeners.
|
| 962 |
+
* @since v14.5.0
|
| 963 |
+
*/
|
| 964 |
+
getMaxListeners(): number;
|
| 965 |
+
/**
|
| 966 |
+
* Node.js-specific alias for `eventTarget.removeEventListener()`.
|
| 967 |
+
* @since v14.5.0
|
| 968 |
+
*/
|
| 969 |
+
off(type: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
| 970 |
+
/**
|
| 971 |
+
* Node.js-specific alias for `eventTarget.addEventListener()`.
|
| 972 |
+
* @since v14.5.0
|
| 973 |
+
*/
|
| 974 |
+
on(type: string, listener: (arg: any) => void): this;
|
| 975 |
+
/**
|
| 976 |
+
* Node.js-specific extension to the `EventTarget` class that adds a `once`
|
| 977 |
+
* listener for the given event `type`. This is equivalent to calling `on`
|
| 978 |
+
* with the `once` option set to `true`.
|
| 979 |
+
* @since v14.5.0
|
| 980 |
+
*/
|
| 981 |
+
once(type: string, listener: (arg: any) => void): this;
|
| 982 |
+
/**
|
| 983 |
+
* Node.js-specific extension to the `EventTarget` class. If `type` is specified,
|
| 984 |
+
* removes all registered listeners for `type`, otherwise removes all registered
|
| 985 |
+
* listeners.
|
| 986 |
+
* @since v14.5.0
|
| 987 |
+
*/
|
| 988 |
+
removeAllListeners(type?: string): this;
|
| 989 |
+
/**
|
| 990 |
+
* Node.js-specific extension to the `EventTarget` class that removes the
|
| 991 |
+
* `listener` for the given `type`. The only difference between `removeListener()`
|
| 992 |
+
* and `removeEventListener()` is that `removeListener()` will return a reference
|
| 993 |
+
* to the `EventTarget`.
|
| 994 |
+
* @since v14.5.0
|
| 995 |
+
*/
|
| 996 |
+
removeListener(type: string, listener: (arg: any) => void, options?: EventListenerOptions): this;
|
| 997 |
+
}
|
| 998 |
+
/** @internal */
|
| 999 |
+
type InternalEventTargetEventProperties<T> = {
|
| 1000 |
+
[K in keyof T & string as `on${K}`]: ((ev: T[K]) => void) | null;
|
| 1001 |
+
};
|
| 1002 |
+
}
|
| 1003 |
+
export = EventEmitter;
|
| 1004 |
+
}
|
| 1005 |
+
declare module "events" {
|
| 1006 |
+
import events = require("node:events");
|
| 1007 |
+
export = events;
|
| 1008 |
+
}
|
node_modules/@types/node/fs.d.ts
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/@types/node/fs/promises.d.ts
ADDED
|
@@ -0,0 +1,1468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:fs/promises" {
|
| 2 |
+
import { NonSharedBuffer } from "node:buffer";
|
| 3 |
+
import { Abortable } from "node:events";
|
| 4 |
+
import { Interface as ReadlineInterface } from "node:readline";
|
| 5 |
+
import {
|
| 6 |
+
BigIntStats,
|
| 7 |
+
BigIntStatsFs,
|
| 8 |
+
BufferEncodingOption,
|
| 9 |
+
constants as fsConstants,
|
| 10 |
+
CopyOptions,
|
| 11 |
+
Dir,
|
| 12 |
+
Dirent,
|
| 13 |
+
EncodingOption,
|
| 14 |
+
GlobOptions,
|
| 15 |
+
GlobOptionsWithFileTypes,
|
| 16 |
+
GlobOptionsWithoutFileTypes,
|
| 17 |
+
MakeDirectoryOptions,
|
| 18 |
+
Mode,
|
| 19 |
+
ObjectEncodingOptions,
|
| 20 |
+
OpenDirOptions,
|
| 21 |
+
OpenMode,
|
| 22 |
+
PathLike,
|
| 23 |
+
ReadOptions,
|
| 24 |
+
ReadOptionsWithBuffer,
|
| 25 |
+
ReadPosition,
|
| 26 |
+
ReadStream,
|
| 27 |
+
ReadVResult,
|
| 28 |
+
RmOptions,
|
| 29 |
+
StatFsOptions,
|
| 30 |
+
StatOptions,
|
| 31 |
+
Stats,
|
| 32 |
+
StatsFs,
|
| 33 |
+
TimeLike,
|
| 34 |
+
WatchEventType,
|
| 35 |
+
WatchOptions as _WatchOptions,
|
| 36 |
+
WriteStream,
|
| 37 |
+
WriteVResult,
|
| 38 |
+
} from "node:fs";
|
| 39 |
+
import { Stream } from "node:stream";
|
| 40 |
+
import { ByteReadableStream, Transform, Writer } from "node:stream/iter";
|
| 41 |
+
import { ReadableStream } from "node:stream/web";
|
| 42 |
+
interface FileChangeInfo<T extends string | Buffer> {
|
| 43 |
+
eventType: WatchEventType;
|
| 44 |
+
filename: T | null;
|
| 45 |
+
}
|
| 46 |
+
interface FlagAndOpenMode {
|
| 47 |
+
mode?: Mode | undefined;
|
| 48 |
+
flag?: OpenMode | undefined;
|
| 49 |
+
}
|
| 50 |
+
interface FileReadResult<T extends NodeJS.ArrayBufferView> {
|
| 51 |
+
bytesRead: number;
|
| 52 |
+
buffer: T;
|
| 53 |
+
}
|
| 54 |
+
/** @deprecated This interface will be removed in a future version. Use `import { ReadOptionsWithBuffer } from "node:fs"` instead. */
|
| 55 |
+
interface FileReadOptions<T extends NodeJS.ArrayBufferView = Buffer> {
|
| 56 |
+
/**
|
| 57 |
+
* @default `Buffer.alloc(0xffff)`
|
| 58 |
+
*/
|
| 59 |
+
buffer?: T;
|
| 60 |
+
/**
|
| 61 |
+
* @default 0
|
| 62 |
+
*/
|
| 63 |
+
offset?: number | null;
|
| 64 |
+
/**
|
| 65 |
+
* @default `buffer.byteLength`
|
| 66 |
+
*/
|
| 67 |
+
length?: number | null;
|
| 68 |
+
position?: ReadPosition | null;
|
| 69 |
+
}
|
| 70 |
+
interface CreateReadStreamOptions extends Abortable {
|
| 71 |
+
encoding?: BufferEncoding | null | undefined;
|
| 72 |
+
autoClose?: boolean | undefined;
|
| 73 |
+
emitClose?: boolean | undefined;
|
| 74 |
+
start?: number | undefined;
|
| 75 |
+
end?: number | undefined;
|
| 76 |
+
highWaterMark?: number | undefined;
|
| 77 |
+
}
|
| 78 |
+
interface CreateWriteStreamOptions {
|
| 79 |
+
encoding?: BufferEncoding | null | undefined;
|
| 80 |
+
autoClose?: boolean | undefined;
|
| 81 |
+
emitClose?: boolean | undefined;
|
| 82 |
+
start?: number | undefined;
|
| 83 |
+
highWaterMark?: number | undefined;
|
| 84 |
+
flush?: boolean | undefined;
|
| 85 |
+
}
|
| 86 |
+
interface ReadableWebStreamOptions {
|
| 87 |
+
autoClose?: boolean | undefined;
|
| 88 |
+
}
|
| 89 |
+
interface PullOptions extends Abortable {
|
| 90 |
+
/**
|
| 91 |
+
* Close the file handle when the stream ends.
|
| 92 |
+
* @default false
|
| 93 |
+
*/
|
| 94 |
+
autoClose?: boolean | undefined;
|
| 95 |
+
/**
|
| 96 |
+
* Byte offset to begin reading from. When specified,
|
| 97 |
+
* reads use explicit positioning (`pread` semantics).
|
| 98 |
+
*/
|
| 99 |
+
start?: number | undefined;
|
| 100 |
+
/**
|
| 101 |
+
* Maximum number of bytes to read before ending the
|
| 102 |
+
* iterator. Reads stop when `limit` bytes have been delivered or EOF is
|
| 103 |
+
* reached, whichever comes first.
|
| 104 |
+
*/
|
| 105 |
+
limit?: number | undefined;
|
| 106 |
+
/**
|
| 107 |
+
* Size in bytes of the buffer allocated for each
|
| 108 |
+
* read operation.
|
| 109 |
+
* @default 131072
|
| 110 |
+
*/
|
| 111 |
+
chunkSize?: number | undefined;
|
| 112 |
+
}
|
| 113 |
+
interface WriterOptions {
|
| 114 |
+
/**
|
| 115 |
+
* Close the file handle when the writer ends or fails.
|
| 116 |
+
* @default false
|
| 117 |
+
*/
|
| 118 |
+
autoClose?: boolean | undefined;
|
| 119 |
+
/**
|
| 120 |
+
* Byte offset to start writing at. When specified,
|
| 121 |
+
* writes use explicit positioning.
|
| 122 |
+
*/
|
| 123 |
+
start?: number | undefined;
|
| 124 |
+
/**
|
| 125 |
+
* Maximum number of bytes the writer will accept.
|
| 126 |
+
* Async writes (`write()`, `writev()`) that would exceed the limit reject
|
| 127 |
+
* with `ERR_OUT_OF_RANGE`. Sync writes (`writeSync()`, `writevSync()`)
|
| 128 |
+
* return `false`.
|
| 129 |
+
*/
|
| 130 |
+
limit?: number | undefined;
|
| 131 |
+
/**
|
| 132 |
+
* Maximum chunk size in bytes for synchronous write
|
| 133 |
+
* operations. Writes larger than this threshold fall back to async I/O.
|
| 134 |
+
* Set this to match the reader's `chunkSize` for optimal `pipeTo()`
|
| 135 |
+
* performance.
|
| 136 |
+
* @default 131072
|
| 137 |
+
*/
|
| 138 |
+
chunkSize?: number | undefined;
|
| 139 |
+
}
|
| 140 |
+
// TODO: Add `EventEmitter` close
|
| 141 |
+
interface FileHandle {
|
| 142 |
+
/**
|
| 143 |
+
* The numeric file descriptor managed by the {FileHandle} object.
|
| 144 |
+
* @since v10.0.0
|
| 145 |
+
*/
|
| 146 |
+
readonly fd: number;
|
| 147 |
+
/**
|
| 148 |
+
* Alias of `filehandle.writeFile()`.
|
| 149 |
+
*
|
| 150 |
+
* When operating on file handles, the mode cannot be changed from what it was set
|
| 151 |
+
* to with `fsPromises.open()`. Therefore, this is equivalent to `filehandle.writeFile()`.
|
| 152 |
+
* @since v10.0.0
|
| 153 |
+
* @return Fulfills with `undefined` upon success.
|
| 154 |
+
*/
|
| 155 |
+
appendFile(
|
| 156 |
+
data: string | Uint8Array,
|
| 157 |
+
options?:
|
| 158 |
+
| (ObjectEncodingOptions & Abortable)
|
| 159 |
+
| BufferEncoding
|
| 160 |
+
| null,
|
| 161 |
+
): Promise<void>;
|
| 162 |
+
/**
|
| 163 |
+
* Changes the ownership of the file. A wrapper for [`chown(2)`](http://man7.org/linux/man-pages/man2/chown.2.html).
|
| 164 |
+
* @since v10.0.0
|
| 165 |
+
* @param uid The file's new owner's user id.
|
| 166 |
+
* @param gid The file's new group's group id.
|
| 167 |
+
* @return Fulfills with `undefined` upon success.
|
| 168 |
+
*/
|
| 169 |
+
chown(uid: number, gid: number): Promise<void>;
|
| 170 |
+
/**
|
| 171 |
+
* Modifies the permissions on the file. See [`chmod(2)`](http://man7.org/linux/man-pages/man2/chmod.2.html).
|
| 172 |
+
* @since v10.0.0
|
| 173 |
+
* @param mode the file mode bit mask.
|
| 174 |
+
* @return Fulfills with `undefined` upon success.
|
| 175 |
+
*/
|
| 176 |
+
chmod(mode: Mode): Promise<void>;
|
| 177 |
+
/**
|
| 178 |
+
* Unlike the 16 KiB default `highWaterMark` for a `stream.Readable`, the stream
|
| 179 |
+
* returned by this method has a default `highWaterMark` of 64 KiB.
|
| 180 |
+
*
|
| 181 |
+
* `options` can include `start` and `end` values to read a range of bytes from
|
| 182 |
+
* the file instead of the entire file. Both `start` and `end` are inclusive and
|
| 183 |
+
* start counting at 0, allowed values are in the
|
| 184 |
+
* \[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
|
| 185 |
+
* omitted or `undefined`, `filehandle.createReadStream()` reads sequentially from
|
| 186 |
+
* the current file position. The `encoding` can be any one of those accepted by `Buffer`.
|
| 187 |
+
*
|
| 188 |
+
* If the `FileHandle` points to a character device that only supports blocking
|
| 189 |
+
* reads (such as keyboard or sound card), read operations do not finish until data
|
| 190 |
+
* is available. This can prevent the process from exiting and the stream from
|
| 191 |
+
* closing naturally.
|
| 192 |
+
*
|
| 193 |
+
* By default, the stream will emit a `'close'` event after it has been
|
| 194 |
+
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
| 195 |
+
*
|
| 196 |
+
* ```js
|
| 197 |
+
* import { open } from 'node:fs/promises';
|
| 198 |
+
*
|
| 199 |
+
* const fd = await open('/dev/input/event0');
|
| 200 |
+
* // Create a stream from some character device.
|
| 201 |
+
* const stream = fd.createReadStream();
|
| 202 |
+
* setTimeout(() => {
|
| 203 |
+
* stream.close(); // This may not close the stream.
|
| 204 |
+
* // Artificially marking end-of-stream, as if the underlying resource had
|
| 205 |
+
* // indicated end-of-file by itself, allows the stream to close.
|
| 206 |
+
* // This does not cancel pending read operations, and if there is such an
|
| 207 |
+
* // operation, the process may still not be able to exit successfully
|
| 208 |
+
* // until it finishes.
|
| 209 |
+
* stream.push(null);
|
| 210 |
+
* stream.read(0);
|
| 211 |
+
* }, 100);
|
| 212 |
+
* ```
|
| 213 |
+
*
|
| 214 |
+
* If `autoClose` is false, then the file descriptor won't be closed, even if
|
| 215 |
+
* there's an error. It is the application's responsibility to close it and make
|
| 216 |
+
* sure there's no file descriptor leak. If `autoClose` is set to true (default
|
| 217 |
+
* behavior), on `'error'` or `'end'` the file descriptor will be closed
|
| 218 |
+
* automatically.
|
| 219 |
+
*
|
| 220 |
+
* An example to read the last 10 bytes of a file which is 100 bytes long:
|
| 221 |
+
*
|
| 222 |
+
* ```js
|
| 223 |
+
* import { open } from 'node:fs/promises';
|
| 224 |
+
*
|
| 225 |
+
* const fd = await open('sample.txt');
|
| 226 |
+
* fd.createReadStream({ start: 90, end: 99 });
|
| 227 |
+
* ```
|
| 228 |
+
* @since v16.11.0
|
| 229 |
+
*/
|
| 230 |
+
createReadStream(options?: CreateReadStreamOptions): ReadStream;
|
| 231 |
+
/**
|
| 232 |
+
* `options` may also include a `start` option to allow writing data at some
|
| 233 |
+
* position past the beginning of the file, allowed values are in the
|
| 234 |
+
* \[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
|
| 235 |
+
* replacing it may require the `flags` `open` option to be set to `r+` rather than
|
| 236 |
+
* the default `r`. The `encoding` can be any one of those accepted by `Buffer`.
|
| 237 |
+
*
|
| 238 |
+
* If `autoClose` is set to true (default behavior) on `'error'` or `'finish'` the file descriptor will be closed automatically. If `autoClose` is false,
|
| 239 |
+
* then the file descriptor won't be closed, even if there's an error.
|
| 240 |
+
* It is the application's responsibility to close it and make sure there's no
|
| 241 |
+
* file descriptor leak.
|
| 242 |
+
*
|
| 243 |
+
* By default, the stream will emit a `'close'` event after it has been
|
| 244 |
+
* destroyed. Set the `emitClose` option to `false` to change this behavior.
|
| 245 |
+
* @since v16.11.0
|
| 246 |
+
*/
|
| 247 |
+
createWriteStream(options?: CreateWriteStreamOptions): WriteStream;
|
| 248 |
+
/**
|
| 249 |
+
* Forces all currently queued I/O operations associated with the file to the
|
| 250 |
+
* 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.
|
| 251 |
+
*
|
| 252 |
+
* Unlike `filehandle.sync` this method does not flush modified metadata.
|
| 253 |
+
* @since v10.0.0
|
| 254 |
+
* @return Fulfills with `undefined` upon success.
|
| 255 |
+
*/
|
| 256 |
+
datasync(): Promise<void>;
|
| 257 |
+
/**
|
| 258 |
+
* Return the file contents as an async iterable using the
|
| 259 |
+
* [`node:stream/iter`](https://nodejs.org/docs/latest-v25.x/api/stream_iter.html) pull model. Reads are performed in `chunkSize`-byte
|
| 260 |
+
* chunks (default 128 KB). If transforms are provided, they are applied
|
| 261 |
+
* via [`stream/iter pull()`](https://nodejs.org/docs/latest-v25.x/api/stream_iter.html#pullsource-transforms-options).
|
| 262 |
+
*
|
| 263 |
+
* The file handle is locked while the iterable is being consumed and unlocked
|
| 264 |
+
* when iteration completes, an error occurs, or the consumer breaks.
|
| 265 |
+
*
|
| 266 |
+
* This function is only available when the `--experimental-stream-iter` flag is
|
| 267 |
+
* enabled.
|
| 268 |
+
*
|
| 269 |
+
* ```js
|
| 270 |
+
* import { open } from 'node:fs/promises';
|
| 271 |
+
* import { text } from 'node:stream/iter';
|
| 272 |
+
* import { compressGzip } from 'node:zlib/iter';
|
| 273 |
+
*
|
| 274 |
+
* const fh = await open('input.txt', 'r');
|
| 275 |
+
*
|
| 276 |
+
* // Read as text
|
| 277 |
+
* console.log(await text(fh.pull({ autoClose: true })));
|
| 278 |
+
*
|
| 279 |
+
* // Read 1 KB starting at byte 100
|
| 280 |
+
* const fh2 = await open('input.txt', 'r');
|
| 281 |
+
* console.log(await text(fh2.pull({ start: 100, limit: 1024, autoClose: true })));
|
| 282 |
+
*
|
| 283 |
+
* // Read with compression
|
| 284 |
+
* const fh3 = await open('input.txt', 'r');
|
| 285 |
+
* const compressed = fh3.pull(compressGzip(), { autoClose: true });
|
| 286 |
+
* ```
|
| 287 |
+
* @since v25.9.0
|
| 288 |
+
* @experimental
|
| 289 |
+
*/
|
| 290 |
+
pull(...transforms: Transform[]): ByteReadableStream;
|
| 291 |
+
pull(...args: [...transforms: Transform[], options: PullOptions]): ByteReadableStream;
|
| 292 |
+
/**
|
| 293 |
+
* Request that all data for the open file descriptor is flushed to the storage
|
| 294 |
+
* device. The specific implementation is operating system and device specific.
|
| 295 |
+
* Refer to the POSIX [`fsync(2)`](http://man7.org/linux/man-pages/man2/fsync.2.html) documentation for more detail.
|
| 296 |
+
* @since v10.0.0
|
| 297 |
+
* @return Fulfills with `undefined` upon success.
|
| 298 |
+
*/
|
| 299 |
+
sync(): Promise<void>;
|
| 300 |
+
/**
|
| 301 |
+
* Reads data from the file and stores that in the given buffer.
|
| 302 |
+
*
|
| 303 |
+
* If the file is not modified concurrently, the end-of-file is reached when the
|
| 304 |
+
* number of bytes read is zero.
|
| 305 |
+
* @since v10.0.0
|
| 306 |
+
* @param buffer A buffer that will be filled with the file data read.
|
| 307 |
+
* @param offset The location in the buffer at which to start filling.
|
| 308 |
+
* @param length The number of bytes to read.
|
| 309 |
+
* @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
|
| 310 |
+
* integer, the current file position will remain unchanged.
|
| 311 |
+
* @return Fulfills upon success with an object with two properties:
|
| 312 |
+
*/
|
| 313 |
+
read<T extends NodeJS.ArrayBufferView>(
|
| 314 |
+
buffer: T,
|
| 315 |
+
offset?: number | null,
|
| 316 |
+
length?: number | null,
|
| 317 |
+
position?: ReadPosition | null,
|
| 318 |
+
): Promise<FileReadResult<T>>;
|
| 319 |
+
read<T extends NodeJS.ArrayBufferView>(
|
| 320 |
+
buffer: T,
|
| 321 |
+
options?: ReadOptions,
|
| 322 |
+
): Promise<FileReadResult<T>>;
|
| 323 |
+
read<T extends NodeJS.ArrayBufferView = NonSharedBuffer>(
|
| 324 |
+
options?: ReadOptionsWithBuffer<T>,
|
| 325 |
+
): Promise<FileReadResult<T>>;
|
| 326 |
+
/**
|
| 327 |
+
* Returns a byte-oriented `ReadableStream` that may be used to read the file's
|
| 328 |
+
* contents.
|
| 329 |
+
*
|
| 330 |
+
* An error will be thrown if this method is called more than once or is called
|
| 331 |
+
* after the `FileHandle` is closed or closing.
|
| 332 |
+
*
|
| 333 |
+
* ```js
|
| 334 |
+
* import {
|
| 335 |
+
* open,
|
| 336 |
+
* } from 'node:fs/promises';
|
| 337 |
+
*
|
| 338 |
+
* const file = await open('./some/file/to/read');
|
| 339 |
+
*
|
| 340 |
+
* for await (const chunk of file.readableWebStream())
|
| 341 |
+
* console.log(chunk);
|
| 342 |
+
*
|
| 343 |
+
* await file.close();
|
| 344 |
+
* ```
|
| 345 |
+
*
|
| 346 |
+
* While the `ReadableStream` will read the file to completion, it will not
|
| 347 |
+
* close the `FileHandle` automatically. User code must still call the`fileHandle.close()` method.
|
| 348 |
+
* @since v17.0.0
|
| 349 |
+
*/
|
| 350 |
+
readableWebStream(options?: ReadableWebStreamOptions): ReadableStream;
|
| 351 |
+
/**
|
| 352 |
+
* Asynchronously reads the entire contents of a file.
|
| 353 |
+
*
|
| 354 |
+
* If `options` is a string, then it specifies the `encoding`.
|
| 355 |
+
*
|
| 356 |
+
* The `FileHandle` has to support reading.
|
| 357 |
+
*
|
| 358 |
+
* 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
|
| 359 |
+
* position till the end of the file. It doesn't always read from the beginning
|
| 360 |
+
* of the file.
|
| 361 |
+
* @since v10.0.0
|
| 362 |
+
* @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
|
| 363 |
+
* data will be a string.
|
| 364 |
+
*/
|
| 365 |
+
readFile(
|
| 366 |
+
options?:
|
| 367 |
+
| ({ encoding?: null | undefined } & Abortable)
|
| 368 |
+
| null,
|
| 369 |
+
): Promise<NonSharedBuffer>;
|
| 370 |
+
/**
|
| 371 |
+
* Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
|
| 372 |
+
* The `FileHandle` must have been opened for reading.
|
| 373 |
+
*/
|
| 374 |
+
readFile(
|
| 375 |
+
options:
|
| 376 |
+
| ({ encoding: BufferEncoding } & Abortable)
|
| 377 |
+
| BufferEncoding,
|
| 378 |
+
): Promise<string>;
|
| 379 |
+
/**
|
| 380 |
+
* Asynchronously reads the entire contents of a file. The underlying file will _not_ be closed automatically.
|
| 381 |
+
* The `FileHandle` must have been opened for reading.
|
| 382 |
+
*/
|
| 383 |
+
readFile(
|
| 384 |
+
options?:
|
| 385 |
+
| (ObjectEncodingOptions & Abortable)
|
| 386 |
+
| BufferEncoding
|
| 387 |
+
| null,
|
| 388 |
+
): Promise<string | NonSharedBuffer>;
|
| 389 |
+
/**
|
| 390 |
+
* Convenience method to create a `readline` interface and stream over the file.
|
| 391 |
+
* See `filehandle.createReadStream()` for the options.
|
| 392 |
+
*
|
| 393 |
+
* ```js
|
| 394 |
+
* import { open } from 'node:fs/promises';
|
| 395 |
+
*
|
| 396 |
+
* const file = await open('./some/file/to/read');
|
| 397 |
+
*
|
| 398 |
+
* for await (const line of file.readLines()) {
|
| 399 |
+
* console.log(line);
|
| 400 |
+
* }
|
| 401 |
+
* ```
|
| 402 |
+
* @since v18.11.0
|
| 403 |
+
*/
|
| 404 |
+
readLines(options?: CreateReadStreamOptions): ReadlineInterface;
|
| 405 |
+
/**
|
| 406 |
+
* @since v10.0.0
|
| 407 |
+
* @return Fulfills with an {fs.Stats} for the file.
|
| 408 |
+
*/
|
| 409 |
+
stat(
|
| 410 |
+
opts?: StatOptions & {
|
| 411 |
+
bigint?: false | undefined;
|
| 412 |
+
},
|
| 413 |
+
): Promise<Stats>;
|
| 414 |
+
stat(
|
| 415 |
+
opts: StatOptions & {
|
| 416 |
+
bigint: true;
|
| 417 |
+
},
|
| 418 |
+
): Promise<BigIntStats>;
|
| 419 |
+
stat(opts?: StatOptions): Promise<Stats | BigIntStats>;
|
| 420 |
+
/**
|
| 421 |
+
* Truncates the file.
|
| 422 |
+
*
|
| 423 |
+
* If the file was larger than `len` bytes, only the first `len` bytes will be
|
| 424 |
+
* retained in the file.
|
| 425 |
+
*
|
| 426 |
+
* The following example retains only the first four bytes of the file:
|
| 427 |
+
*
|
| 428 |
+
* ```js
|
| 429 |
+
* import { open } from 'node:fs/promises';
|
| 430 |
+
*
|
| 431 |
+
* let filehandle = null;
|
| 432 |
+
* try {
|
| 433 |
+
* filehandle = await open('temp.txt', 'r+');
|
| 434 |
+
* await filehandle.truncate(4);
|
| 435 |
+
* } finally {
|
| 436 |
+
* await filehandle?.close();
|
| 437 |
+
* }
|
| 438 |
+
* ```
|
| 439 |
+
*
|
| 440 |
+
* If the file previously was shorter than `len` bytes, it is extended, and the
|
| 441 |
+
* extended part is filled with null bytes (`'\0'`):
|
| 442 |
+
*
|
| 443 |
+
* If `len` is negative then `0` will be used.
|
| 444 |
+
* @since v10.0.0
|
| 445 |
+
* @param [len=0]
|
| 446 |
+
* @return Fulfills with `undefined` upon success.
|
| 447 |
+
*/
|
| 448 |
+
truncate(len?: number): Promise<void>;
|
| 449 |
+
/**
|
| 450 |
+
* Change the file system timestamps of the object referenced by the `FileHandle` then fulfills the promise with no arguments upon success.
|
| 451 |
+
* @since v10.0.0
|
| 452 |
+
*/
|
| 453 |
+
utimes(atime: TimeLike, mtime: TimeLike): Promise<void>;
|
| 454 |
+
/**
|
| 455 |
+
* Asynchronously writes data to a file, replacing the file if it already exists. `data` can be a string, a buffer, an
|
| 456 |
+
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an
|
| 457 |
+
* [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
|
| 458 |
+
* The promise is fulfilled with no arguments upon success.
|
| 459 |
+
*
|
| 460 |
+
* If `options` is a string, then it specifies the `encoding`.
|
| 461 |
+
*
|
| 462 |
+
* The `FileHandle` has to support writing.
|
| 463 |
+
*
|
| 464 |
+
* It is unsafe to use `filehandle.writeFile()` multiple times on the same file
|
| 465 |
+
* without waiting for the promise to be fulfilled (or rejected).
|
| 466 |
+
*
|
| 467 |
+
* 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
|
| 468 |
+
* current position till the end of the file. It doesn't always write from the
|
| 469 |
+
* beginning of the file.
|
| 470 |
+
* @since v10.0.0
|
| 471 |
+
*/
|
| 472 |
+
writeFile(
|
| 473 |
+
data: string | Uint8Array,
|
| 474 |
+
options?:
|
| 475 |
+
| (ObjectEncodingOptions & Abortable)
|
| 476 |
+
| BufferEncoding
|
| 477 |
+
| null,
|
| 478 |
+
): Promise<void>;
|
| 479 |
+
/**
|
| 480 |
+
* Write `buffer` to the file.
|
| 481 |
+
*
|
| 482 |
+
* The promise is fulfilled with an object containing two properties:
|
| 483 |
+
*
|
| 484 |
+
* It is unsafe to use `filehandle.write()` multiple times on the same file
|
| 485 |
+
* without waiting for the promise to be fulfilled (or rejected). For this
|
| 486 |
+
* scenario, use `filehandle.createWriteStream()`.
|
| 487 |
+
*
|
| 488 |
+
* On Linux, positional writes do not work when the file is opened in append mode.
|
| 489 |
+
* The kernel ignores the position argument and always appends the data to
|
| 490 |
+
* the end of the file.
|
| 491 |
+
* @since v10.0.0
|
| 492 |
+
* @param offset The start position from within `buffer` where the data to write begins.
|
| 493 |
+
* @param [length=buffer.byteLength - offset] The number of bytes from `buffer` to write.
|
| 494 |
+
* @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
|
| 495 |
+
* position. See the POSIX pwrite(2) documentation for more detail.
|
| 496 |
+
*/
|
| 497 |
+
write<TBuffer extends NodeJS.ArrayBufferView>(
|
| 498 |
+
buffer: TBuffer,
|
| 499 |
+
offset?: number | null,
|
| 500 |
+
length?: number | null,
|
| 501 |
+
position?: number | null,
|
| 502 |
+
): Promise<{
|
| 503 |
+
bytesWritten: number;
|
| 504 |
+
buffer: TBuffer;
|
| 505 |
+
}>;
|
| 506 |
+
write<TBuffer extends Uint8Array>(
|
| 507 |
+
buffer: TBuffer,
|
| 508 |
+
options?: { offset?: number; length?: number; position?: number },
|
| 509 |
+
): Promise<{
|
| 510 |
+
bytesWritten: number;
|
| 511 |
+
buffer: TBuffer;
|
| 512 |
+
}>;
|
| 513 |
+
write(
|
| 514 |
+
data: string,
|
| 515 |
+
position?: number | null,
|
| 516 |
+
encoding?: BufferEncoding | null,
|
| 517 |
+
): Promise<{
|
| 518 |
+
bytesWritten: number;
|
| 519 |
+
buffer: string;
|
| 520 |
+
}>;
|
| 521 |
+
/**
|
| 522 |
+
* Write an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s to the file.
|
| 523 |
+
*
|
| 524 |
+
* The promise is fulfilled with an object containing a two properties:
|
| 525 |
+
*
|
| 526 |
+
* It is unsafe to call `writev()` multiple times on the same file without waiting
|
| 527 |
+
* for the promise to be fulfilled (or rejected).
|
| 528 |
+
*
|
| 529 |
+
* On Linux, positional writes don't work when the file is opened in append mode.
|
| 530 |
+
* The kernel ignores the position argument and always appends the data to
|
| 531 |
+
* the end of the file.
|
| 532 |
+
* @since v12.9.0
|
| 533 |
+
* @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
|
| 534 |
+
* position.
|
| 535 |
+
*/
|
| 536 |
+
writev<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
|
| 537 |
+
buffers: TBuffers,
|
| 538 |
+
position?: number,
|
| 539 |
+
): Promise<WriteVResult<TBuffers>>;
|
| 540 |
+
/**
|
| 541 |
+
* Return a [`node:stream/iter`](https://nodejs.org/docs/latest-v25.x/api/stream_iter.html) writer backed by this file handle.
|
| 542 |
+
*
|
| 543 |
+
* The writer supports both `Symbol.asyncDispose` and `Symbol.dispose`:
|
| 544 |
+
*
|
| 545 |
+
* * `await using w = fh.writer()` — if the writer is still open (no `end()`
|
| 546 |
+
* called), `asyncDispose` calls `fail()`. If `end()` is pending, it waits
|
| 547 |
+
* for it to complete.
|
| 548 |
+
* * `using w = fh.writer()` — calls `fail()` unconditionally.
|
| 549 |
+
*
|
| 550 |
+
* The `writeSync()` and `writevSync()` methods enable the try-sync fast path
|
| 551 |
+
* used by [`stream/iter pipeTo()`](https://nodejs.org/docs/latest-v25.x/api/stream_iter.html#pipetosource-transforms-writer). When the reader's chunk size matches the
|
| 552 |
+
* writer's `chunkSize`, all writes in a `pipeTo()` pipeline complete
|
| 553 |
+
* synchronously with zero promise overhead.
|
| 554 |
+
*
|
| 555 |
+
* This function is only available when the `--experimental-stream-iter` flag is
|
| 556 |
+
* enabled.
|
| 557 |
+
*
|
| 558 |
+
* ```js
|
| 559 |
+
* import { open } from 'node:fs/promises';
|
| 560 |
+
* import { from, pipeTo } from 'node:stream/iter';
|
| 561 |
+
* import { compressGzip } from 'node:zlib/iter';
|
| 562 |
+
*
|
| 563 |
+
* // Async pipeline
|
| 564 |
+
* const fh = await open('output.gz', 'w');
|
| 565 |
+
* await pipeTo(from('Hello!'), compressGzip(), fh.writer({ autoClose: true }));
|
| 566 |
+
*
|
| 567 |
+
* // Sync pipeline with limit
|
| 568 |
+
* const src = await open('input.txt', 'r');
|
| 569 |
+
* const dst = await open('output.txt', 'w');
|
| 570 |
+
* const w = dst.writer({ limit: 1024 * 1024 }); // Max 1 MB
|
| 571 |
+
* await pipeTo(src.pull({ autoClose: true }), w);
|
| 572 |
+
* await w.end();
|
| 573 |
+
* await dst.close();
|
| 574 |
+
* ```
|
| 575 |
+
* @since v25.9.0
|
| 576 |
+
* @experimental
|
| 577 |
+
*/
|
| 578 |
+
writer(options?: WriterOptions): Writer;
|
| 579 |
+
/**
|
| 580 |
+
* Read from a file and write to an array of [ArrayBufferView](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView) s
|
| 581 |
+
* @since v13.13.0, v12.17.0
|
| 582 |
+
* @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.
|
| 583 |
+
* @return Fulfills upon success an object containing two properties:
|
| 584 |
+
*/
|
| 585 |
+
readv<TBuffers extends readonly NodeJS.ArrayBufferView[]>(
|
| 586 |
+
buffers: TBuffers,
|
| 587 |
+
position?: number,
|
| 588 |
+
): Promise<ReadVResult<TBuffers>>;
|
| 589 |
+
/**
|
| 590 |
+
* Closes the file handle after waiting for any pending operation on the handle to
|
| 591 |
+
* complete.
|
| 592 |
+
*
|
| 593 |
+
* ```js
|
| 594 |
+
* import { open } from 'node:fs/promises';
|
| 595 |
+
*
|
| 596 |
+
* let filehandle;
|
| 597 |
+
* try {
|
| 598 |
+
* filehandle = await open('thefile.txt', 'r');
|
| 599 |
+
* } finally {
|
| 600 |
+
* await filehandle?.close();
|
| 601 |
+
* }
|
| 602 |
+
* ```
|
| 603 |
+
* @since v10.0.0
|
| 604 |
+
* @return Fulfills with `undefined` upon success.
|
| 605 |
+
*/
|
| 606 |
+
close(): Promise<void>;
|
| 607 |
+
/**
|
| 608 |
+
* Calls `filehandle.close()` and returns a promise that fulfills when the
|
| 609 |
+
* filehandle is closed.
|
| 610 |
+
* @since v20.4.0, v18.8.0
|
| 611 |
+
*/
|
| 612 |
+
[Symbol.asyncDispose](): Promise<void>;
|
| 613 |
+
}
|
| 614 |
+
const constants: typeof fsConstants;
|
| 615 |
+
/**
|
| 616 |
+
* Tests a user's permissions for the file or directory specified by `path`.
|
| 617 |
+
* The `mode` argument is an optional integer that specifies the accessibility
|
| 618 |
+
* 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`
|
| 619 |
+
* (e.g.`fs.constants.W_OK | fs.constants.R_OK`). Check `File access constants` for
|
| 620 |
+
* possible values of `mode`.
|
| 621 |
+
*
|
| 622 |
+
* If the accessibility check is successful, the promise is fulfilled with no
|
| 623 |
+
* value. If any of the accessibility checks fail, the promise is rejected
|
| 624 |
+
* 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
|
| 625 |
+
* written by the current process.
|
| 626 |
+
*
|
| 627 |
+
* ```js
|
| 628 |
+
* import { access, constants } from 'node:fs/promises';
|
| 629 |
+
*
|
| 630 |
+
* try {
|
| 631 |
+
* await access('/etc/passwd', constants.R_OK | constants.W_OK);
|
| 632 |
+
* console.log('can access');
|
| 633 |
+
* } catch {
|
| 634 |
+
* console.error('cannot access');
|
| 635 |
+
* }
|
| 636 |
+
* ```
|
| 637 |
+
*
|
| 638 |
+
* Using `fsPromises.access()` to check for the accessibility of a file before
|
| 639 |
+
* calling `fsPromises.open()` is not recommended. Doing so introduces a race
|
| 640 |
+
* condition, since other processes may change the file's state between the two
|
| 641 |
+
* calls. Instead, user code should open/read/write the file directly and handle
|
| 642 |
+
* the error raised if the file is not accessible.
|
| 643 |
+
* @since v10.0.0
|
| 644 |
+
* @param [mode=fs.constants.F_OK]
|
| 645 |
+
* @return Fulfills with `undefined` upon success.
|
| 646 |
+
*/
|
| 647 |
+
function access(path: PathLike, mode?: number): Promise<void>;
|
| 648 |
+
/**
|
| 649 |
+
* Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it
|
| 650 |
+
* already exists.
|
| 651 |
+
*
|
| 652 |
+
* No guarantees are made about the atomicity of the copy operation. If an
|
| 653 |
+
* error occurs after the destination file has been opened for writing, an attempt
|
| 654 |
+
* will be made to remove the destination.
|
| 655 |
+
*
|
| 656 |
+
* ```js
|
| 657 |
+
* import { copyFile, constants } from 'node:fs/promises';
|
| 658 |
+
*
|
| 659 |
+
* try {
|
| 660 |
+
* await copyFile('source.txt', 'destination.txt');
|
| 661 |
+
* console.log('source.txt was copied to destination.txt');
|
| 662 |
+
* } catch {
|
| 663 |
+
* console.error('The file could not be copied');
|
| 664 |
+
* }
|
| 665 |
+
*
|
| 666 |
+
* // By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
|
| 667 |
+
* try {
|
| 668 |
+
* await copyFile('source.txt', 'destination.txt', constants.COPYFILE_EXCL);
|
| 669 |
+
* console.log('source.txt was copied to destination.txt');
|
| 670 |
+
* } catch {
|
| 671 |
+
* console.error('The file could not be copied');
|
| 672 |
+
* }
|
| 673 |
+
* ```
|
| 674 |
+
* @since v10.0.0
|
| 675 |
+
* @param src source filename to copy
|
| 676 |
+
* @param dest destination filename of the copy operation
|
| 677 |
+
* @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.
|
| 678 |
+
* `fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE`)
|
| 679 |
+
* @return Fulfills with `undefined` upon success.
|
| 680 |
+
*/
|
| 681 |
+
function copyFile(src: PathLike, dest: PathLike, mode?: number): Promise<void>;
|
| 682 |
+
/**
|
| 683 |
+
* Opens a `FileHandle`.
|
| 684 |
+
*
|
| 685 |
+
* Refer to the POSIX [`open(2)`](http://man7.org/linux/man-pages/man2/open.2.html) documentation for more detail.
|
| 686 |
+
*
|
| 687 |
+
* Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented
|
| 688 |
+
* by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
|
| 689 |
+
* 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).
|
| 690 |
+
* @since v10.0.0
|
| 691 |
+
* @param [flags='r'] See `support of file system `flags``.
|
| 692 |
+
* @param [mode=0o666] Sets the file mode (permission and sticky bits) if the file is created.
|
| 693 |
+
* @return Fulfills with a {FileHandle} object.
|
| 694 |
+
*/
|
| 695 |
+
function open(path: PathLike, flags?: string | number, mode?: Mode): Promise<FileHandle>;
|
| 696 |
+
/**
|
| 697 |
+
* Renames `oldPath` to `newPath`.
|
| 698 |
+
* @since v10.0.0
|
| 699 |
+
* @return Fulfills with `undefined` upon success.
|
| 700 |
+
*/
|
| 701 |
+
function rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
| 702 |
+
/**
|
| 703 |
+
* Truncates (shortens or extends the length) of the content at `path` to `len` bytes.
|
| 704 |
+
* @since v10.0.0
|
| 705 |
+
* @param [len=0]
|
| 706 |
+
* @return Fulfills with `undefined` upon success.
|
| 707 |
+
*/
|
| 708 |
+
function truncate(path: PathLike, len?: number): Promise<void>;
|
| 709 |
+
/**
|
| 710 |
+
* Removes the directory identified by `path`.
|
| 711 |
+
*
|
| 712 |
+
* Using `fsPromises.rmdir()` on a file (not a directory) results in the
|
| 713 |
+
* promise being rejected with an `ENOENT` error on Windows and an `ENOTDIR` error on POSIX.
|
| 714 |
+
*
|
| 715 |
+
* To get a behavior similar to the `rm -rf` Unix command, use `fsPromises.rm()` with options `{ recursive: true, force: true }`.
|
| 716 |
+
* @since v10.0.0
|
| 717 |
+
* @return Fulfills with `undefined` upon success.
|
| 718 |
+
*/
|
| 719 |
+
function rmdir(path: PathLike): Promise<void>;
|
| 720 |
+
/**
|
| 721 |
+
* Removes files and directories (modeled on the standard POSIX `rm` utility).
|
| 722 |
+
* @since v14.14.0
|
| 723 |
+
* @return Fulfills with `undefined` upon success.
|
| 724 |
+
*/
|
| 725 |
+
function rm(path: PathLike, options?: RmOptions): Promise<void>;
|
| 726 |
+
/**
|
| 727 |
+
* Asynchronously creates a directory.
|
| 728 |
+
*
|
| 729 |
+
* The optional `options` argument can be an integer specifying `mode` (permission
|
| 730 |
+
* 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
|
| 731 |
+
* that exists results in a
|
| 732 |
+
* rejection only when `recursive` is false.
|
| 733 |
+
*
|
| 734 |
+
* ```js
|
| 735 |
+
* import { mkdir } from 'node:fs/promises';
|
| 736 |
+
*
|
| 737 |
+
* try {
|
| 738 |
+
* const projectFolder = new URL('./test/project/', import.meta.url);
|
| 739 |
+
* const createDir = await mkdir(projectFolder, { recursive: true });
|
| 740 |
+
*
|
| 741 |
+
* console.log(`created ${createDir}`);
|
| 742 |
+
* } catch (err) {
|
| 743 |
+
* console.error(err.message);
|
| 744 |
+
* }
|
| 745 |
+
* ```
|
| 746 |
+
* @since v10.0.0
|
| 747 |
+
* @return Upon success, fulfills with `undefined` if `recursive` is `false`, or the first directory path created if `recursive` is `true`.
|
| 748 |
+
*/
|
| 749 |
+
function mkdir(
|
| 750 |
+
path: PathLike,
|
| 751 |
+
options: MakeDirectoryOptions & {
|
| 752 |
+
recursive: true;
|
| 753 |
+
},
|
| 754 |
+
): Promise<string | undefined>;
|
| 755 |
+
/**
|
| 756 |
+
* Asynchronous mkdir(2) - create a directory.
|
| 757 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 758 |
+
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
| 759 |
+
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
| 760 |
+
*/
|
| 761 |
+
function mkdir(
|
| 762 |
+
path: PathLike,
|
| 763 |
+
options?:
|
| 764 |
+
| Mode
|
| 765 |
+
| (MakeDirectoryOptions & {
|
| 766 |
+
recursive?: false | undefined;
|
| 767 |
+
})
|
| 768 |
+
| null,
|
| 769 |
+
): Promise<void>;
|
| 770 |
+
/**
|
| 771 |
+
* Asynchronous mkdir(2) - create a directory.
|
| 772 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 773 |
+
* @param options Either the file mode, or an object optionally specifying the file mode and whether parent folders
|
| 774 |
+
* should be created. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
|
| 775 |
+
*/
|
| 776 |
+
function mkdir(path: PathLike, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
|
| 777 |
+
/**
|
| 778 |
+
* Reads the contents of a directory.
|
| 779 |
+
*
|
| 780 |
+
* The optional `options` argument can be a string specifying an encoding, or an
|
| 781 |
+
* object with an `encoding` property specifying the character encoding to use for
|
| 782 |
+
* the filenames. If the `encoding` is set to `'buffer'`, the filenames returned
|
| 783 |
+
* will be passed as `Buffer` objects.
|
| 784 |
+
*
|
| 785 |
+
* If `options.withFileTypes` is set to `true`, the returned array will contain `fs.Dirent` objects.
|
| 786 |
+
*
|
| 787 |
+
* ```js
|
| 788 |
+
* import { readdir } from 'node:fs/promises';
|
| 789 |
+
*
|
| 790 |
+
* try {
|
| 791 |
+
* const files = await readdir(path);
|
| 792 |
+
* for (const file of files)
|
| 793 |
+
* console.log(file);
|
| 794 |
+
* } catch (err) {
|
| 795 |
+
* console.error(err);
|
| 796 |
+
* }
|
| 797 |
+
* ```
|
| 798 |
+
* @since v10.0.0
|
| 799 |
+
* @return Fulfills with an array of the names of the files in the directory excluding `'.'` and `'..'`.
|
| 800 |
+
*/
|
| 801 |
+
function readdir(
|
| 802 |
+
path: PathLike,
|
| 803 |
+
options?:
|
| 804 |
+
| (ObjectEncodingOptions & {
|
| 805 |
+
withFileTypes?: false | undefined;
|
| 806 |
+
recursive?: boolean | undefined;
|
| 807 |
+
})
|
| 808 |
+
| BufferEncoding
|
| 809 |
+
| null,
|
| 810 |
+
): Promise<string[]>;
|
| 811 |
+
/**
|
| 812 |
+
* Asynchronous readdir(3) - read a directory.
|
| 813 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 814 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
| 815 |
+
*/
|
| 816 |
+
function readdir(
|
| 817 |
+
path: PathLike,
|
| 818 |
+
options:
|
| 819 |
+
| {
|
| 820 |
+
encoding: "buffer";
|
| 821 |
+
withFileTypes?: false | undefined;
|
| 822 |
+
recursive?: boolean | undefined;
|
| 823 |
+
}
|
| 824 |
+
| "buffer",
|
| 825 |
+
): Promise<NonSharedBuffer[]>;
|
| 826 |
+
/**
|
| 827 |
+
* Asynchronous readdir(3) - read a directory.
|
| 828 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 829 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
| 830 |
+
*/
|
| 831 |
+
function readdir(
|
| 832 |
+
path: PathLike,
|
| 833 |
+
options?:
|
| 834 |
+
| (ObjectEncodingOptions & {
|
| 835 |
+
withFileTypes?: false | undefined;
|
| 836 |
+
recursive?: boolean | undefined;
|
| 837 |
+
})
|
| 838 |
+
| BufferEncoding
|
| 839 |
+
| null,
|
| 840 |
+
): Promise<string[] | NonSharedBuffer[]>;
|
| 841 |
+
/**
|
| 842 |
+
* Asynchronous readdir(3) - read a directory.
|
| 843 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 844 |
+
* @param options If called with `withFileTypes: true` the result data will be an array of Dirent.
|
| 845 |
+
*/
|
| 846 |
+
function readdir(
|
| 847 |
+
path: PathLike,
|
| 848 |
+
options: ObjectEncodingOptions & {
|
| 849 |
+
withFileTypes: true;
|
| 850 |
+
recursive?: boolean | undefined;
|
| 851 |
+
},
|
| 852 |
+
): Promise<Dirent[]>;
|
| 853 |
+
/**
|
| 854 |
+
* Asynchronous readdir(3) - read a directory.
|
| 855 |
+
* @param path A path to a directory. If a URL is provided, it must use the `file:` protocol.
|
| 856 |
+
* @param options Must include `withFileTypes: true` and `encoding: 'buffer'`.
|
| 857 |
+
*/
|
| 858 |
+
function readdir(
|
| 859 |
+
path: PathLike,
|
| 860 |
+
options: {
|
| 861 |
+
encoding: "buffer";
|
| 862 |
+
withFileTypes: true;
|
| 863 |
+
recursive?: boolean | undefined;
|
| 864 |
+
},
|
| 865 |
+
): Promise<Dirent<NonSharedBuffer>[]>;
|
| 866 |
+
/**
|
| 867 |
+
* 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
|
| 868 |
+
* fulfilled with the`linkString` upon success.
|
| 869 |
+
*
|
| 870 |
+
* The optional `options` argument can be a string specifying an encoding, or an
|
| 871 |
+
* object with an `encoding` property specifying the character encoding to use for
|
| 872 |
+
* the link path returned. If the `encoding` is set to `'buffer'`, the link path
|
| 873 |
+
* returned will be passed as a `Buffer` object.
|
| 874 |
+
* @since v10.0.0
|
| 875 |
+
* @return Fulfills with the `linkString` upon success.
|
| 876 |
+
*/
|
| 877 |
+
function readlink(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
| 878 |
+
/**
|
| 879 |
+
* Asynchronous readlink(2) - read value of a symbolic link.
|
| 880 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 881 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
| 882 |
+
*/
|
| 883 |
+
function readlink(path: PathLike, options: BufferEncodingOption): Promise<NonSharedBuffer>;
|
| 884 |
+
/**
|
| 885 |
+
* Asynchronous readlink(2) - read value of a symbolic link.
|
| 886 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 887 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
| 888 |
+
*/
|
| 889 |
+
function readlink(
|
| 890 |
+
path: PathLike,
|
| 891 |
+
options?: ObjectEncodingOptions | string | null,
|
| 892 |
+
): Promise<string | NonSharedBuffer>;
|
| 893 |
+
/**
|
| 894 |
+
* Creates a symbolic link.
|
| 895 |
+
*
|
| 896 |
+
* 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
|
| 897 |
+
* autodetect `target` type and use `'file'` or `'dir'`. If the `target` does not
|
| 898 |
+
* exist, `'file'` will be used. Windows junction points require the destination
|
| 899 |
+
* path to be absolute. When using `'junction'`, the `target` argument will
|
| 900 |
+
* automatically be normalized to absolute path. Junction points on NTFS volumes
|
| 901 |
+
* can only point to directories.
|
| 902 |
+
* @since v10.0.0
|
| 903 |
+
* @param [type='null']
|
| 904 |
+
* @return Fulfills with `undefined` upon success.
|
| 905 |
+
*/
|
| 906 |
+
function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>;
|
| 907 |
+
/**
|
| 908 |
+
* Equivalent to `fsPromises.stat()` unless `path` refers to a symbolic link,
|
| 909 |
+
* in which case the link itself is stat-ed, not the file that it refers to.
|
| 910 |
+
* Refer to the POSIX [`lstat(2)`](http://man7.org/linux/man-pages/man2/lstat.2.html) document for more detail.
|
| 911 |
+
* @since v10.0.0
|
| 912 |
+
* @return Fulfills with the {fs.Stats} object for the given symbolic link `path`.
|
| 913 |
+
*/
|
| 914 |
+
function lstat(
|
| 915 |
+
path: PathLike,
|
| 916 |
+
opts?: StatOptions & {
|
| 917 |
+
bigint?: false | undefined;
|
| 918 |
+
},
|
| 919 |
+
): Promise<Stats>;
|
| 920 |
+
function lstat(
|
| 921 |
+
path: PathLike,
|
| 922 |
+
opts: StatOptions & {
|
| 923 |
+
bigint: true;
|
| 924 |
+
},
|
| 925 |
+
): Promise<BigIntStats>;
|
| 926 |
+
function lstat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats>;
|
| 927 |
+
/**
|
| 928 |
+
* @since v10.0.0
|
| 929 |
+
* @return Fulfills with the {fs.Stats} object for the given `path`.
|
| 930 |
+
*/
|
| 931 |
+
function stat(path: PathLike): Promise<Stats>;
|
| 932 |
+
function stat(
|
| 933 |
+
path: PathLike,
|
| 934 |
+
opts?: StatOptions & {
|
| 935 |
+
bigint?: false | undefined;
|
| 936 |
+
throwIfNoEntry?: true | undefined;
|
| 937 |
+
},
|
| 938 |
+
): Promise<Stats>;
|
| 939 |
+
function stat(
|
| 940 |
+
path: PathLike,
|
| 941 |
+
opts: StatOptions & {
|
| 942 |
+
bigint: true;
|
| 943 |
+
throwIfNoEntry?: true | undefined;
|
| 944 |
+
},
|
| 945 |
+
): Promise<BigIntStats>;
|
| 946 |
+
function stat(
|
| 947 |
+
path: PathLike,
|
| 948 |
+
opts: StatOptions & {
|
| 949 |
+
bigint?: false | undefined;
|
| 950 |
+
throwIfNoEntry: false;
|
| 951 |
+
},
|
| 952 |
+
): Promise<Stats | undefined>;
|
| 953 |
+
function stat(
|
| 954 |
+
path: PathLike,
|
| 955 |
+
opts: StatOptions & {
|
| 956 |
+
bigint: true;
|
| 957 |
+
throwIfNoEntry: false;
|
| 958 |
+
},
|
| 959 |
+
): Promise<BigIntStats | undefined>;
|
| 960 |
+
function stat(
|
| 961 |
+
path: PathLike,
|
| 962 |
+
opts: StatOptions & {
|
| 963 |
+
throwIfNoEntry?: true | undefined;
|
| 964 |
+
},
|
| 965 |
+
): Promise<Stats | BigIntStats>;
|
| 966 |
+
function stat(path: PathLike, opts?: StatOptions): Promise<Stats | BigIntStats | undefined>;
|
| 967 |
+
/**
|
| 968 |
+
* @since v19.6.0, v18.15.0
|
| 969 |
+
* @return Fulfills with the {fs.StatFs} object for the given `path`.
|
| 970 |
+
*/
|
| 971 |
+
function statfs(
|
| 972 |
+
path: PathLike,
|
| 973 |
+
opts?: StatFsOptions & {
|
| 974 |
+
bigint?: false | undefined;
|
| 975 |
+
},
|
| 976 |
+
): Promise<StatsFs>;
|
| 977 |
+
function statfs(
|
| 978 |
+
path: PathLike,
|
| 979 |
+
opts: StatFsOptions & {
|
| 980 |
+
bigint: true;
|
| 981 |
+
},
|
| 982 |
+
): Promise<BigIntStatsFs>;
|
| 983 |
+
function statfs(path: PathLike, opts?: StatFsOptions): Promise<StatsFs | BigIntStatsFs>;
|
| 984 |
+
/**
|
| 985 |
+
* 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.
|
| 986 |
+
* @since v10.0.0
|
| 987 |
+
* @return Fulfills with `undefined` upon success.
|
| 988 |
+
*/
|
| 989 |
+
function link(existingPath: PathLike, newPath: PathLike): Promise<void>;
|
| 990 |
+
/**
|
| 991 |
+
* If `path` refers to a symbolic link, then the link is removed without affecting
|
| 992 |
+
* the file or directory to which that link refers. If the `path` refers to a file
|
| 993 |
+
* 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.
|
| 994 |
+
* @since v10.0.0
|
| 995 |
+
* @return Fulfills with `undefined` upon success.
|
| 996 |
+
*/
|
| 997 |
+
function unlink(path: PathLike): Promise<void>;
|
| 998 |
+
/**
|
| 999 |
+
* Changes the permissions of a file.
|
| 1000 |
+
* @since v10.0.0
|
| 1001 |
+
* @return Fulfills with `undefined` upon success.
|
| 1002 |
+
*/
|
| 1003 |
+
function chmod(path: PathLike, mode: Mode): Promise<void>;
|
| 1004 |
+
/**
|
| 1005 |
+
* Changes the permissions on a symbolic link.
|
| 1006 |
+
*
|
| 1007 |
+
* This method is only implemented on macOS.
|
| 1008 |
+
* @deprecated Since v10.0.0
|
| 1009 |
+
* @return Fulfills with `undefined` upon success.
|
| 1010 |
+
*/
|
| 1011 |
+
function lchmod(path: PathLike, mode: Mode): Promise<void>;
|
| 1012 |
+
/**
|
| 1013 |
+
* Changes the ownership on a symbolic link.
|
| 1014 |
+
* @since v10.0.0
|
| 1015 |
+
* @return Fulfills with `undefined` upon success.
|
| 1016 |
+
*/
|
| 1017 |
+
function lchown(path: PathLike, uid: number, gid: number): Promise<void>;
|
| 1018 |
+
/**
|
| 1019 |
+
* 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
|
| 1020 |
+
* symbolic link, then the link is not dereferenced: instead, the timestamps of
|
| 1021 |
+
* the symbolic link itself are changed.
|
| 1022 |
+
* @since v14.5.0, v12.19.0
|
| 1023 |
+
* @return Fulfills with `undefined` upon success.
|
| 1024 |
+
*/
|
| 1025 |
+
function lutimes(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
| 1026 |
+
/**
|
| 1027 |
+
* Changes the ownership of a file.
|
| 1028 |
+
* @since v10.0.0
|
| 1029 |
+
* @return Fulfills with `undefined` upon success.
|
| 1030 |
+
*/
|
| 1031 |
+
function chown(path: PathLike, uid: number, gid: number): Promise<void>;
|
| 1032 |
+
/**
|
| 1033 |
+
* Change the file system timestamps of the object referenced by `path`.
|
| 1034 |
+
*
|
| 1035 |
+
* The `atime` and `mtime` arguments follow these rules:
|
| 1036 |
+
*
|
| 1037 |
+
* * Values can be either numbers representing Unix epoch time, `Date`s, or a
|
| 1038 |
+
* numeric string like `'123456789.0'`.
|
| 1039 |
+
* * If the value can not be converted to a number, or is `NaN`, `Infinity`, or `-Infinity`, an `Error` will be thrown.
|
| 1040 |
+
* @since v10.0.0
|
| 1041 |
+
* @return Fulfills with `undefined` upon success.
|
| 1042 |
+
*/
|
| 1043 |
+
function utimes(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
| 1044 |
+
/**
|
| 1045 |
+
* Determines the actual location of `path` using the same semantics as the `fs.realpath.native()` function.
|
| 1046 |
+
*
|
| 1047 |
+
* Only paths that can be converted to UTF8 strings are supported.
|
| 1048 |
+
*
|
| 1049 |
+
* The optional `options` argument can be a string specifying an encoding, or an
|
| 1050 |
+
* object with an `encoding` property specifying the character encoding to use for
|
| 1051 |
+
* the path. If the `encoding` is set to `'buffer'`, the path returned will be
|
| 1052 |
+
* passed as a `Buffer` object.
|
| 1053 |
+
*
|
| 1054 |
+
* On Linux, when Node.js is linked against musl libc, the procfs file system must
|
| 1055 |
+
* be mounted on `/proc` in order for this function to work. Glibc does not have
|
| 1056 |
+
* this restriction.
|
| 1057 |
+
* @since v10.0.0
|
| 1058 |
+
* @return Fulfills with the resolved path upon success.
|
| 1059 |
+
*/
|
| 1060 |
+
function realpath(path: PathLike, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
| 1061 |
+
/**
|
| 1062 |
+
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
| 1063 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 1064 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
| 1065 |
+
*/
|
| 1066 |
+
function realpath(path: PathLike, options: BufferEncodingOption): Promise<NonSharedBuffer>;
|
| 1067 |
+
/**
|
| 1068 |
+
* Asynchronous realpath(3) - return the canonicalized absolute pathname.
|
| 1069 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 1070 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
| 1071 |
+
*/
|
| 1072 |
+
function realpath(
|
| 1073 |
+
path: PathLike,
|
| 1074 |
+
options?: ObjectEncodingOptions | BufferEncoding | null,
|
| 1075 |
+
): Promise<string | NonSharedBuffer>;
|
| 1076 |
+
/**
|
| 1077 |
+
* Creates a unique temporary directory. A unique directory name is generated by
|
| 1078 |
+
* appending six random characters to the end of the provided `prefix`. Due to
|
| 1079 |
+
* platform inconsistencies, avoid trailing `X` characters in `prefix`. Some
|
| 1080 |
+
* platforms, notably the BSDs, can return more than six random characters, and
|
| 1081 |
+
* replace trailing `X` characters in `prefix` with random characters.
|
| 1082 |
+
*
|
| 1083 |
+
* The optional `options` argument can be a string specifying an encoding, or an
|
| 1084 |
+
* object with an `encoding` property specifying the character encoding to use.
|
| 1085 |
+
*
|
| 1086 |
+
* ```js
|
| 1087 |
+
* import { mkdtemp } from 'node:fs/promises';
|
| 1088 |
+
* import { join } from 'node:path';
|
| 1089 |
+
* import { tmpdir } from 'node:os';
|
| 1090 |
+
*
|
| 1091 |
+
* try {
|
| 1092 |
+
* await mkdtemp(join(tmpdir(), 'foo-'));
|
| 1093 |
+
* } catch (err) {
|
| 1094 |
+
* console.error(err);
|
| 1095 |
+
* }
|
| 1096 |
+
* ```
|
| 1097 |
+
*
|
| 1098 |
+
* The `fsPromises.mkdtemp()` method will append the six randomly selected
|
| 1099 |
+
* 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
|
| 1100 |
+
* platform-specific path separator
|
| 1101 |
+
* (`import { sep } from 'node:path'`).
|
| 1102 |
+
* @since v10.0.0
|
| 1103 |
+
* @return Fulfills with a string containing the file system path of the newly created temporary directory.
|
| 1104 |
+
*/
|
| 1105 |
+
function mkdtemp(prefix: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
|
| 1106 |
+
/**
|
| 1107 |
+
* Asynchronously creates a unique temporary directory.
|
| 1108 |
+
* Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
|
| 1109 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
| 1110 |
+
*/
|
| 1111 |
+
function mkdtemp(prefix: string, options: BufferEncodingOption): Promise<NonSharedBuffer>;
|
| 1112 |
+
/**
|
| 1113 |
+
* Asynchronously creates a unique temporary directory.
|
| 1114 |
+
* Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory.
|
| 1115 |
+
* @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
|
| 1116 |
+
*/
|
| 1117 |
+
function mkdtemp(
|
| 1118 |
+
prefix: string,
|
| 1119 |
+
options?: ObjectEncodingOptions | BufferEncoding | null,
|
| 1120 |
+
): Promise<string | NonSharedBuffer>;
|
| 1121 |
+
interface DisposableTempDir extends AsyncDisposable {
|
| 1122 |
+
/**
|
| 1123 |
+
* The path of the created directory.
|
| 1124 |
+
*/
|
| 1125 |
+
path: string;
|
| 1126 |
+
/**
|
| 1127 |
+
* A function which removes the created directory.
|
| 1128 |
+
*/
|
| 1129 |
+
remove(): Promise<void>;
|
| 1130 |
+
/**
|
| 1131 |
+
* The same as `remove`.
|
| 1132 |
+
*/
|
| 1133 |
+
[Symbol.asyncDispose](): Promise<void>;
|
| 1134 |
+
}
|
| 1135 |
+
/**
|
| 1136 |
+
* The resulting Promise holds an async-disposable object whose `path` property
|
| 1137 |
+
* holds the created directory path. When the object is disposed, the directory
|
| 1138 |
+
* and its contents will be removed asynchronously if it still exists. If the
|
| 1139 |
+
* directory cannot be deleted, disposal will throw an error. The object has an
|
| 1140 |
+
* async `remove()` method which will perform the same task.
|
| 1141 |
+
*
|
| 1142 |
+
* Both this function and the disposal function on the resulting object are
|
| 1143 |
+
* async, so it should be used with `await` + `await using` as in
|
| 1144 |
+
* `await using dir = await fsPromises.mkdtempDisposable('prefix')`.
|
| 1145 |
+
*
|
| 1146 |
+
* <!-- TODO: link MDN docs for disposables once https://github.com/mdn/content/pull/38027 lands -->
|
| 1147 |
+
*
|
| 1148 |
+
* For detailed information, see the documentation of `fsPromises.mkdtemp()`.
|
| 1149 |
+
*
|
| 1150 |
+
* The optional `options` argument can be a string specifying an encoding, or an
|
| 1151 |
+
* object with an `encoding` property specifying the character encoding to use.
|
| 1152 |
+
* @since v24.4.0
|
| 1153 |
+
*/
|
| 1154 |
+
function mkdtempDisposable(prefix: PathLike, options?: EncodingOption): Promise<DisposableTempDir>;
|
| 1155 |
+
/**
|
| 1156 |
+
* Asynchronously writes data to a file, replacing the file if it already exists. `data` can be a string, a buffer, an
|
| 1157 |
+
* [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an
|
| 1158 |
+
* [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object.
|
| 1159 |
+
*
|
| 1160 |
+
* The `encoding` option is ignored if `data` is a buffer.
|
| 1161 |
+
*
|
| 1162 |
+
* If `options` is a string, then it specifies the encoding.
|
| 1163 |
+
*
|
| 1164 |
+
* The `mode` option only affects the newly created file. See `fs.open()` for more details.
|
| 1165 |
+
*
|
| 1166 |
+
* Any specified `FileHandle` has to support writing.
|
| 1167 |
+
*
|
| 1168 |
+
* It is unsafe to use `fsPromises.writeFile()` multiple times on the same file
|
| 1169 |
+
* without waiting for the promise to be settled.
|
| 1170 |
+
*
|
| 1171 |
+
* Similarly to `fsPromises.readFile` \- `fsPromises.writeFile` is a convenience
|
| 1172 |
+
* method that performs multiple `write` calls internally to write the buffer
|
| 1173 |
+
* passed to it. For performance sensitive code consider using `fs.createWriteStream()` or `filehandle.createWriteStream()`.
|
| 1174 |
+
*
|
| 1175 |
+
* It is possible to use an `AbortSignal` to cancel an `fsPromises.writeFile()`.
|
| 1176 |
+
* Cancelation is "best effort", and some amount of data is likely still
|
| 1177 |
+
* to be written.
|
| 1178 |
+
*
|
| 1179 |
+
* ```js
|
| 1180 |
+
* import { writeFile } from 'node:fs/promises';
|
| 1181 |
+
* import { Buffer } from 'node:buffer';
|
| 1182 |
+
*
|
| 1183 |
+
* try {
|
| 1184 |
+
* const controller = new AbortController();
|
| 1185 |
+
* const { signal } = controller;
|
| 1186 |
+
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
| 1187 |
+
* const promise = writeFile('message.txt', data, { signal });
|
| 1188 |
+
*
|
| 1189 |
+
* // Abort the request before the promise settles.
|
| 1190 |
+
* controller.abort();
|
| 1191 |
+
*
|
| 1192 |
+
* await promise;
|
| 1193 |
+
* } catch (err) {
|
| 1194 |
+
* // When a request is aborted - err is an AbortError
|
| 1195 |
+
* console.error(err);
|
| 1196 |
+
* }
|
| 1197 |
+
* ```
|
| 1198 |
+
*
|
| 1199 |
+
* Aborting an ongoing request does not abort individual operating
|
| 1200 |
+
* system requests but rather the internal buffering `fs.writeFile` performs.
|
| 1201 |
+
* @since v10.0.0
|
| 1202 |
+
* @param file filename or `FileHandle`
|
| 1203 |
+
* @return Fulfills with `undefined` upon success.
|
| 1204 |
+
*/
|
| 1205 |
+
function writeFile(
|
| 1206 |
+
file: PathLike | FileHandle,
|
| 1207 |
+
data:
|
| 1208 |
+
| string
|
| 1209 |
+
| NodeJS.ArrayBufferView
|
| 1210 |
+
| Iterable<string | NodeJS.ArrayBufferView>
|
| 1211 |
+
| AsyncIterable<string | NodeJS.ArrayBufferView>
|
| 1212 |
+
| Stream,
|
| 1213 |
+
options?:
|
| 1214 |
+
| (ObjectEncodingOptions & {
|
| 1215 |
+
mode?: Mode | undefined;
|
| 1216 |
+
flag?: OpenMode | undefined;
|
| 1217 |
+
/**
|
| 1218 |
+
* If all data is successfully written to the file, and `flush`
|
| 1219 |
+
* is `true`, `filehandle.sync()` is used to flush the data.
|
| 1220 |
+
* @default false
|
| 1221 |
+
*/
|
| 1222 |
+
flush?: boolean | undefined;
|
| 1223 |
+
} & Abortable)
|
| 1224 |
+
| BufferEncoding
|
| 1225 |
+
| null,
|
| 1226 |
+
): Promise<void>;
|
| 1227 |
+
/**
|
| 1228 |
+
* Asynchronously append data to a file, creating the file if it does not yet
|
| 1229 |
+
* exist. `data` can be a string or a `Buffer`.
|
| 1230 |
+
*
|
| 1231 |
+
* If `options` is a string, then it specifies the `encoding`.
|
| 1232 |
+
*
|
| 1233 |
+
* The `mode` option only affects the newly created file. See `fs.open()` for more details.
|
| 1234 |
+
*
|
| 1235 |
+
* The `path` may be specified as a `FileHandle` that has been opened
|
| 1236 |
+
* for appending (using `fsPromises.open()`).
|
| 1237 |
+
* @since v10.0.0
|
| 1238 |
+
* @param path filename or {FileHandle}
|
| 1239 |
+
* @return Fulfills with `undefined` upon success.
|
| 1240 |
+
*/
|
| 1241 |
+
function appendFile(
|
| 1242 |
+
path: PathLike | FileHandle,
|
| 1243 |
+
data: string | Uint8Array,
|
| 1244 |
+
options?: (ObjectEncodingOptions & FlagAndOpenMode & { flush?: boolean | undefined }) | BufferEncoding | null,
|
| 1245 |
+
): Promise<void>;
|
| 1246 |
+
/**
|
| 1247 |
+
* Asynchronously reads the entire contents of a file.
|
| 1248 |
+
*
|
| 1249 |
+
* If no encoding is specified (using `options.encoding`), the data is returned
|
| 1250 |
+
* as a `Buffer` object. Otherwise, the data will be a string.
|
| 1251 |
+
*
|
| 1252 |
+
* If `options` is a string, then it specifies the encoding.
|
| 1253 |
+
*
|
| 1254 |
+
* When the `path` is a directory, the behavior of `fsPromises.readFile()` is
|
| 1255 |
+
* platform-specific. On macOS, Linux, and Windows, the promise will be rejected
|
| 1256 |
+
* with an error. On FreeBSD, a representation of the directory's contents will be
|
| 1257 |
+
* returned.
|
| 1258 |
+
*
|
| 1259 |
+
* An example of reading a `package.json` file located in the same directory of the
|
| 1260 |
+
* running code:
|
| 1261 |
+
*
|
| 1262 |
+
* ```js
|
| 1263 |
+
* import { readFile } from 'node:fs/promises';
|
| 1264 |
+
* try {
|
| 1265 |
+
* const filePath = new URL('./package.json', import.meta.url);
|
| 1266 |
+
* const contents = await readFile(filePath, { encoding: 'utf8' });
|
| 1267 |
+
* console.log(contents);
|
| 1268 |
+
* } catch (err) {
|
| 1269 |
+
* console.error(err.message);
|
| 1270 |
+
* }
|
| 1271 |
+
* ```
|
| 1272 |
+
*
|
| 1273 |
+
* It is possible to abort an ongoing `readFile` using an `AbortSignal`. If a
|
| 1274 |
+
* request is aborted the promise returned is rejected with an `AbortError`:
|
| 1275 |
+
*
|
| 1276 |
+
* ```js
|
| 1277 |
+
* import { readFile } from 'node:fs/promises';
|
| 1278 |
+
*
|
| 1279 |
+
* try {
|
| 1280 |
+
* const controller = new AbortController();
|
| 1281 |
+
* const { signal } = controller;
|
| 1282 |
+
* const promise = readFile(fileName, { signal });
|
| 1283 |
+
*
|
| 1284 |
+
* // Abort the request before the promise settles.
|
| 1285 |
+
* controller.abort();
|
| 1286 |
+
*
|
| 1287 |
+
* await promise;
|
| 1288 |
+
* } catch (err) {
|
| 1289 |
+
* // When a request is aborted - err is an AbortError
|
| 1290 |
+
* console.error(err);
|
| 1291 |
+
* }
|
| 1292 |
+
* ```
|
| 1293 |
+
*
|
| 1294 |
+
* Aborting an ongoing request does not abort individual operating
|
| 1295 |
+
* system requests but rather the internal buffering `fs.readFile` performs.
|
| 1296 |
+
*
|
| 1297 |
+
* Any specified `FileHandle` has to support reading.
|
| 1298 |
+
* @since v10.0.0
|
| 1299 |
+
* @param path filename or `FileHandle`
|
| 1300 |
+
* @return Fulfills with the contents of the file.
|
| 1301 |
+
*/
|
| 1302 |
+
function readFile(
|
| 1303 |
+
path: PathLike | FileHandle,
|
| 1304 |
+
options?:
|
| 1305 |
+
| ({
|
| 1306 |
+
encoding?: null | undefined;
|
| 1307 |
+
flag?: OpenMode | undefined;
|
| 1308 |
+
} & Abortable)
|
| 1309 |
+
| null,
|
| 1310 |
+
): Promise<NonSharedBuffer>;
|
| 1311 |
+
/**
|
| 1312 |
+
* Asynchronously reads the entire contents of a file.
|
| 1313 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 1314 |
+
* If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
|
| 1315 |
+
* @param options An object that may contain an optional flag.
|
| 1316 |
+
* If a flag is not provided, it defaults to `'r'`.
|
| 1317 |
+
*/
|
| 1318 |
+
function readFile(
|
| 1319 |
+
path: PathLike | FileHandle,
|
| 1320 |
+
options:
|
| 1321 |
+
| ({
|
| 1322 |
+
encoding: BufferEncoding;
|
| 1323 |
+
flag?: OpenMode | undefined;
|
| 1324 |
+
} & Abortable)
|
| 1325 |
+
| BufferEncoding,
|
| 1326 |
+
): Promise<string>;
|
| 1327 |
+
/**
|
| 1328 |
+
* Asynchronously reads the entire contents of a file.
|
| 1329 |
+
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
| 1330 |
+
* If a `FileHandle` is provided, the underlying file will _not_ be closed automatically.
|
| 1331 |
+
* @param options An object that may contain an optional flag.
|
| 1332 |
+
* If a flag is not provided, it defaults to `'r'`.
|
| 1333 |
+
*/
|
| 1334 |
+
function readFile(
|
| 1335 |
+
path: PathLike | FileHandle,
|
| 1336 |
+
options?:
|
| 1337 |
+
| (
|
| 1338 |
+
& ObjectEncodingOptions
|
| 1339 |
+
& Abortable
|
| 1340 |
+
& {
|
| 1341 |
+
flag?: OpenMode | undefined;
|
| 1342 |
+
}
|
| 1343 |
+
)
|
| 1344 |
+
| BufferEncoding
|
| 1345 |
+
| null,
|
| 1346 |
+
): Promise<string | NonSharedBuffer>;
|
| 1347 |
+
/**
|
| 1348 |
+
* 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.
|
| 1349 |
+
*
|
| 1350 |
+
* Creates an `fs.Dir`, which contains all further functions for reading from
|
| 1351 |
+
* and cleaning up the directory.
|
| 1352 |
+
*
|
| 1353 |
+
* The `encoding` option sets the encoding for the `path` while opening the
|
| 1354 |
+
* directory and subsequent read operations.
|
| 1355 |
+
*
|
| 1356 |
+
* Example using async iteration:
|
| 1357 |
+
*
|
| 1358 |
+
* ```js
|
| 1359 |
+
* import { opendir } from 'node:fs/promises';
|
| 1360 |
+
*
|
| 1361 |
+
* try {
|
| 1362 |
+
* const dir = await opendir('./');
|
| 1363 |
+
* for await (const dirent of dir)
|
| 1364 |
+
* console.log(dirent.name);
|
| 1365 |
+
* } catch (err) {
|
| 1366 |
+
* console.error(err);
|
| 1367 |
+
* }
|
| 1368 |
+
* ```
|
| 1369 |
+
*
|
| 1370 |
+
* When using the async iterator, the `fs.Dir` object will be automatically
|
| 1371 |
+
* closed after the iterator exits.
|
| 1372 |
+
* @since v12.12.0
|
| 1373 |
+
* @return Fulfills with an {fs.Dir}.
|
| 1374 |
+
*/
|
| 1375 |
+
function opendir(path: PathLike, options?: OpenDirOptions): Promise<Dir>;
|
| 1376 |
+
interface WatchOptions extends _WatchOptions {
|
| 1377 |
+
maxQueue?: number | undefined;
|
| 1378 |
+
overflow?: "ignore" | "throw" | undefined;
|
| 1379 |
+
}
|
| 1380 |
+
interface WatchOptionsWithBufferEncoding extends WatchOptions {
|
| 1381 |
+
encoding: "buffer";
|
| 1382 |
+
}
|
| 1383 |
+
interface WatchOptionsWithStringEncoding extends WatchOptions {
|
| 1384 |
+
encoding?: BufferEncoding | undefined;
|
| 1385 |
+
}
|
| 1386 |
+
/**
|
| 1387 |
+
* Returns an async iterator that watches for changes on `filename`, where `filename`is either a file or a directory.
|
| 1388 |
+
*
|
| 1389 |
+
* ```js
|
| 1390 |
+
* import { watch } from 'node:fs/promises';
|
| 1391 |
+
*
|
| 1392 |
+
* const ac = new AbortController();
|
| 1393 |
+
* const { signal } = ac;
|
| 1394 |
+
* setTimeout(() => ac.abort(), 10000);
|
| 1395 |
+
*
|
| 1396 |
+
* (async () => {
|
| 1397 |
+
* try {
|
| 1398 |
+
* const watcher = watch(__filename, { signal });
|
| 1399 |
+
* for await (const event of watcher)
|
| 1400 |
+
* console.log(event);
|
| 1401 |
+
* } catch (err) {
|
| 1402 |
+
* if (err.name === 'AbortError')
|
| 1403 |
+
* return;
|
| 1404 |
+
* throw err;
|
| 1405 |
+
* }
|
| 1406 |
+
* })();
|
| 1407 |
+
* ```
|
| 1408 |
+
*
|
| 1409 |
+
* On most platforms, `'rename'` is emitted whenever a filename appears or
|
| 1410 |
+
* disappears in the directory.
|
| 1411 |
+
*
|
| 1412 |
+
* All the `caveats` for `fs.watch()` also apply to `fsPromises.watch()`.
|
| 1413 |
+
* @since v15.9.0, v14.18.0
|
| 1414 |
+
* @return of objects with the properties:
|
| 1415 |
+
*/
|
| 1416 |
+
function watch(
|
| 1417 |
+
filename: PathLike,
|
| 1418 |
+
options?: WatchOptionsWithStringEncoding | BufferEncoding,
|
| 1419 |
+
): NodeJS.AsyncIterator<FileChangeInfo<string>>;
|
| 1420 |
+
function watch(
|
| 1421 |
+
filename: PathLike,
|
| 1422 |
+
options: WatchOptionsWithBufferEncoding | "buffer",
|
| 1423 |
+
): NodeJS.AsyncIterator<FileChangeInfo<NonSharedBuffer>>;
|
| 1424 |
+
function watch(
|
| 1425 |
+
filename: PathLike,
|
| 1426 |
+
options: WatchOptions | BufferEncoding | "buffer",
|
| 1427 |
+
): NodeJS.AsyncIterator<FileChangeInfo<string | NonSharedBuffer>>;
|
| 1428 |
+
/**
|
| 1429 |
+
* Asynchronously copies the entire directory structure from `src` to `dest`,
|
| 1430 |
+
* including subdirectories and files.
|
| 1431 |
+
*
|
| 1432 |
+
* When copying a directory to another directory, globs are not supported and
|
| 1433 |
+
* behavior is similar to `cp dir1/ dir2/`.
|
| 1434 |
+
* @since v16.7.0
|
| 1435 |
+
* @experimental
|
| 1436 |
+
* @param src source path to copy.
|
| 1437 |
+
* @param dest destination path to copy to.
|
| 1438 |
+
* @return Fulfills with `undefined` upon success.
|
| 1439 |
+
*/
|
| 1440 |
+
function cp(source: string | URL, destination: string | URL, opts?: CopyOptions): Promise<void>;
|
| 1441 |
+
/**
|
| 1442 |
+
* ```js
|
| 1443 |
+
* import { glob } from 'node:fs/promises';
|
| 1444 |
+
*
|
| 1445 |
+
* for await (const entry of glob('*.js'))
|
| 1446 |
+
* console.log(entry);
|
| 1447 |
+
* ```
|
| 1448 |
+
* @since v22.0.0
|
| 1449 |
+
* @returns An AsyncIterator that yields the paths of files
|
| 1450 |
+
* that match the pattern.
|
| 1451 |
+
*/
|
| 1452 |
+
function glob(pattern: string | readonly string[]): NodeJS.AsyncIterator<string>;
|
| 1453 |
+
function glob(
|
| 1454 |
+
pattern: string | readonly string[],
|
| 1455 |
+
options: GlobOptionsWithFileTypes,
|
| 1456 |
+
): NodeJS.AsyncIterator<Dirent>;
|
| 1457 |
+
function glob(
|
| 1458 |
+
pattern: string | readonly string[],
|
| 1459 |
+
options: GlobOptionsWithoutFileTypes,
|
| 1460 |
+
): NodeJS.AsyncIterator<string>;
|
| 1461 |
+
function glob(
|
| 1462 |
+
pattern: string | readonly string[],
|
| 1463 |
+
options: GlobOptions,
|
| 1464 |
+
): NodeJS.AsyncIterator<Dirent | string>;
|
| 1465 |
+
}
|
| 1466 |
+
declare module "fs/promises" {
|
| 1467 |
+
export * from "node:fs/promises";
|
| 1468 |
+
}
|
node_modules/@types/node/globals.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare var global: typeof globalThis;
|
| 2 |
+
|
| 3 |
+
declare var process: NodeJS.Process;
|
| 4 |
+
|
| 5 |
+
interface ErrorConstructor {
|
| 6 |
+
/**
|
| 7 |
+
* Creates a `.stack` property on `targetObject`, which when accessed returns
|
| 8 |
+
* a string representing the location in the code at which
|
| 9 |
+
* `Error.captureStackTrace()` was called.
|
| 10 |
+
*
|
| 11 |
+
* ```js
|
| 12 |
+
* const myObject = {};
|
| 13 |
+
* Error.captureStackTrace(myObject);
|
| 14 |
+
* myObject.stack; // Similar to `new Error().stack`
|
| 15 |
+
* ```
|
| 16 |
+
*
|
| 17 |
+
* The first line of the trace will be prefixed with
|
| 18 |
+
* `${myObject.name}: ${myObject.message}`.
|
| 19 |
+
*
|
| 20 |
+
* The optional `constructorOpt` argument accepts a function. If given, all frames
|
| 21 |
+
* above `constructorOpt`, including `constructorOpt`, will be omitted from the
|
| 22 |
+
* generated stack trace.
|
| 23 |
+
*
|
| 24 |
+
* The `constructorOpt` argument is useful for hiding implementation
|
| 25 |
+
* details of error generation from the user. For instance:
|
| 26 |
+
*
|
| 27 |
+
* ```js
|
| 28 |
+
* function a() {
|
| 29 |
+
* b();
|
| 30 |
+
* }
|
| 31 |
+
*
|
| 32 |
+
* function b() {
|
| 33 |
+
* c();
|
| 34 |
+
* }
|
| 35 |
+
*
|
| 36 |
+
* function c() {
|
| 37 |
+
* // Create an error without stack trace to avoid calculating the stack trace twice.
|
| 38 |
+
* const { stackTraceLimit } = Error;
|
| 39 |
+
* Error.stackTraceLimit = 0;
|
| 40 |
+
* const error = new Error();
|
| 41 |
+
* Error.stackTraceLimit = stackTraceLimit;
|
| 42 |
+
*
|
| 43 |
+
* // Capture the stack trace above function b
|
| 44 |
+
* Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
|
| 45 |
+
* throw error;
|
| 46 |
+
* }
|
| 47 |
+
*
|
| 48 |
+
* a();
|
| 49 |
+
* ```
|
| 50 |
+
*/
|
| 51 |
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
| 52 |
+
/**
|
| 53 |
+
* @see https://v8.dev/docs/stack-trace-api#customizing-stack-traces
|
| 54 |
+
*/
|
| 55 |
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
| 56 |
+
/**
|
| 57 |
+
* The `Error.stackTraceLimit` property specifies the number of stack frames
|
| 58 |
+
* collected by a stack trace (whether generated by `new Error().stack` or
|
| 59 |
+
* `Error.captureStackTrace(obj)`).
|
| 60 |
+
*
|
| 61 |
+
* The default value is `10` but may be set to any valid JavaScript number. Changes
|
| 62 |
+
* will affect any stack trace captured _after_ the value has been changed.
|
| 63 |
+
*
|
| 64 |
+
* If set to a non-number value, or set to a negative number, stack traces will
|
| 65 |
+
* not capture any frames.
|
| 66 |
+
*/
|
| 67 |
+
stackTraceLimit: number;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* Enable this API with the `--expose-gc` CLI flag.
|
| 72 |
+
*/
|
| 73 |
+
declare var gc: NodeJS.GCFunction | undefined;
|
| 74 |
+
|
| 75 |
+
declare namespace NodeJS {
|
| 76 |
+
interface CallSite {
|
| 77 |
+
getColumnNumber(): number | null;
|
| 78 |
+
getEnclosingColumnNumber(): number | null;
|
| 79 |
+
getEnclosingLineNumber(): number | null;
|
| 80 |
+
getEvalOrigin(): string | undefined;
|
| 81 |
+
getFileName(): string | null;
|
| 82 |
+
getFunction(): Function | undefined;
|
| 83 |
+
getFunctionName(): string | null;
|
| 84 |
+
getLineNumber(): number | null;
|
| 85 |
+
getMethodName(): string | null;
|
| 86 |
+
getPosition(): number;
|
| 87 |
+
getPromiseIndex(): number | null;
|
| 88 |
+
getScriptHash(): string;
|
| 89 |
+
getScriptNameOrSourceURL(): string | null;
|
| 90 |
+
getThis(): unknown;
|
| 91 |
+
getTypeName(): string | null;
|
| 92 |
+
isAsync(): boolean;
|
| 93 |
+
isConstructor(): boolean;
|
| 94 |
+
isEval(): boolean;
|
| 95 |
+
isNative(): boolean;
|
| 96 |
+
isPromiseAll(): boolean;
|
| 97 |
+
isToplevel(): boolean;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
interface ErrnoException extends Error {
|
| 101 |
+
errno?: number | undefined;
|
| 102 |
+
code?: string | undefined;
|
| 103 |
+
path?: string | undefined;
|
| 104 |
+
syscall?: string | undefined;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
interface RefCounted {
|
| 108 |
+
ref(): this;
|
| 109 |
+
unref(): this;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
interface Dict<T> {
|
| 113 |
+
[key: string]: T | undefined;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
interface ReadOnlyDict<T> {
|
| 117 |
+
readonly [key: string]: T | undefined;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
type PartialOptions<T> = { [K in keyof T]?: T[K] | undefined };
|
| 121 |
+
|
| 122 |
+
interface GCFunction {
|
| 123 |
+
(minor?: boolean): void;
|
| 124 |
+
(options: NodeJS.GCOptions & { execution: "async" }): Promise<void>;
|
| 125 |
+
(options: NodeJS.GCOptions): void;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
interface GCOptions {
|
| 129 |
+
execution?: "sync" | "async" | undefined;
|
| 130 |
+
flavor?: "regular" | "last-resort" | undefined;
|
| 131 |
+
type?: "major-snapshot" | "major" | "minor" | undefined;
|
| 132 |
+
filename?: string | undefined;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
/** An iterable iterator returned by the Node.js API. */
|
| 136 |
+
interface Iterator<T, TReturn = undefined, TNext = any> extends IteratorObject<T, TReturn, TNext> {
|
| 137 |
+
[Symbol.iterator](): NodeJS.Iterator<T, TReturn, TNext>;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
/** An async iterable iterator returned by the Node.js API. */
|
| 141 |
+
interface AsyncIterator<T, TReturn = undefined, TNext = any> extends AsyncIteratorObject<T, TReturn, TNext> {
|
| 142 |
+
[Symbol.asyncIterator](): NodeJS.AsyncIterator<T, TReturn, TNext>;
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/** The [`BufferSource`](https://webidl.spec.whatwg.org/#BufferSource) type from the Web IDL specification. */
|
| 146 |
+
type BufferSource = NonSharedArrayBufferView | ArrayBuffer;
|
| 147 |
+
|
| 148 |
+
/** The [`AllowSharedBufferSource`](https://webidl.spec.whatwg.org/#AllowSharedBufferSource) type from the Web IDL specification. */
|
| 149 |
+
type AllowSharedBufferSource = ArrayBufferView | ArrayBufferLike;
|
| 150 |
+
}
|
node_modules/@types/node/globals.typedarray.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
| Float16Array<TArrayBuffer>
|
| 16 |
+
| Float32Array<TArrayBuffer>
|
| 17 |
+
| Float64Array<TArrayBuffer>;
|
| 18 |
+
type ArrayBufferView<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> =
|
| 19 |
+
| TypedArray<TArrayBuffer>
|
| 20 |
+
| DataView<TArrayBuffer>;
|
| 21 |
+
|
| 22 |
+
// The following aliases are required to allow use of non-shared ArrayBufferViews in @types/node
|
| 23 |
+
// while maintaining compatibility with TS <=5.6.
|
| 24 |
+
// TODO: remove once @types/node no longer supports TS 5.6, and replace with native types.
|
| 25 |
+
/**
|
| 26 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 27 |
+
* TypeScript versions earlier than 5.7.
|
| 28 |
+
*/
|
| 29 |
+
type NonSharedUint8Array = Uint8Array<ArrayBuffer>;
|
| 30 |
+
/**
|
| 31 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 32 |
+
* TypeScript versions earlier than 5.7.
|
| 33 |
+
*/
|
| 34 |
+
type NonSharedUint8ClampedArray = Uint8ClampedArray<ArrayBuffer>;
|
| 35 |
+
/**
|
| 36 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 37 |
+
* TypeScript versions earlier than 5.7.
|
| 38 |
+
*/
|
| 39 |
+
type NonSharedUint16Array = Uint16Array<ArrayBuffer>;
|
| 40 |
+
/**
|
| 41 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 42 |
+
* TypeScript versions earlier than 5.7.
|
| 43 |
+
*/
|
| 44 |
+
type NonSharedUint32Array = Uint32Array<ArrayBuffer>;
|
| 45 |
+
/**
|
| 46 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 47 |
+
* TypeScript versions earlier than 5.7.
|
| 48 |
+
*/
|
| 49 |
+
type NonSharedInt8Array = Int8Array<ArrayBuffer>;
|
| 50 |
+
/**
|
| 51 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 52 |
+
* TypeScript versions earlier than 5.7.
|
| 53 |
+
*/
|
| 54 |
+
type NonSharedInt16Array = Int16Array<ArrayBuffer>;
|
| 55 |
+
/**
|
| 56 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 57 |
+
* TypeScript versions earlier than 5.7.
|
| 58 |
+
*/
|
| 59 |
+
type NonSharedInt32Array = Int32Array<ArrayBuffer>;
|
| 60 |
+
/**
|
| 61 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 62 |
+
* TypeScript versions earlier than 5.7.
|
| 63 |
+
*/
|
| 64 |
+
type NonSharedBigUint64Array = BigUint64Array<ArrayBuffer>;
|
| 65 |
+
/**
|
| 66 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 67 |
+
* TypeScript versions earlier than 5.7.
|
| 68 |
+
*/
|
| 69 |
+
type NonSharedBigInt64Array = BigInt64Array<ArrayBuffer>;
|
| 70 |
+
/**
|
| 71 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 72 |
+
* TypeScript versions earlier than 5.7.
|
| 73 |
+
*/
|
| 74 |
+
type NonSharedFloat16Array = Float16Array<ArrayBuffer>;
|
| 75 |
+
/**
|
| 76 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 77 |
+
* TypeScript versions earlier than 5.7.
|
| 78 |
+
*/
|
| 79 |
+
type NonSharedFloat32Array = Float32Array<ArrayBuffer>;
|
| 80 |
+
/**
|
| 81 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 82 |
+
* TypeScript versions earlier than 5.7.
|
| 83 |
+
*/
|
| 84 |
+
type NonSharedFloat64Array = Float64Array<ArrayBuffer>;
|
| 85 |
+
/**
|
| 86 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 87 |
+
* TypeScript versions earlier than 5.7.
|
| 88 |
+
*/
|
| 89 |
+
type NonSharedDataView = DataView<ArrayBuffer>;
|
| 90 |
+
/**
|
| 91 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 92 |
+
* TypeScript versions earlier than 5.7.
|
| 93 |
+
*/
|
| 94 |
+
type NonSharedTypedArray = TypedArray<ArrayBuffer>;
|
| 95 |
+
/**
|
| 96 |
+
* @deprecated This is intended for internal use, and will be removed once `@types/node` no longer supports
|
| 97 |
+
* TypeScript versions earlier than 5.7.
|
| 98 |
+
*/
|
| 99 |
+
type NonSharedArrayBufferView = ArrayBufferView<ArrayBuffer>;
|
| 100 |
+
}
|
| 101 |
+
}
|
node_modules/@types/node/http.d.ts
ADDED
|
@@ -0,0 +1,2147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:http" {
|
| 2 |
+
import { NonSharedBuffer } from "node:buffer";
|
| 3 |
+
import { LookupOptions } from "node:dns";
|
| 4 |
+
import { EventEmitter } from "node:events";
|
| 5 |
+
import * as net from "node:net";
|
| 6 |
+
import * as stream from "node:stream";
|
| 7 |
+
import { URL } from "node:url";
|
| 8 |
+
// incoming headers will never contain number
|
| 9 |
+
interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
|
| 10 |
+
accept?: string | undefined;
|
| 11 |
+
"accept-encoding"?: string | undefined;
|
| 12 |
+
"accept-language"?: string | undefined;
|
| 13 |
+
"accept-patch"?: string | undefined;
|
| 14 |
+
"accept-ranges"?: string | undefined;
|
| 15 |
+
"access-control-allow-credentials"?: string | undefined;
|
| 16 |
+
"access-control-allow-headers"?: string | undefined;
|
| 17 |
+
"access-control-allow-methods"?: string | undefined;
|
| 18 |
+
"access-control-allow-origin"?: string | undefined;
|
| 19 |
+
"access-control-expose-headers"?: string | undefined;
|
| 20 |
+
"access-control-max-age"?: string | undefined;
|
| 21 |
+
"access-control-request-headers"?: string | undefined;
|
| 22 |
+
"access-control-request-method"?: string | undefined;
|
| 23 |
+
age?: string | undefined;
|
| 24 |
+
allow?: string | undefined;
|
| 25 |
+
"alt-svc"?: string | undefined;
|
| 26 |
+
authorization?: string | undefined;
|
| 27 |
+
"cache-control"?: string | undefined;
|
| 28 |
+
connection?: string | undefined;
|
| 29 |
+
"content-disposition"?: string | undefined;
|
| 30 |
+
"content-encoding"?: string | undefined;
|
| 31 |
+
"content-language"?: string | undefined;
|
| 32 |
+
"content-length"?: string | undefined;
|
| 33 |
+
"content-location"?: string | undefined;
|
| 34 |
+
"content-range"?: string | undefined;
|
| 35 |
+
"content-type"?: string | undefined;
|
| 36 |
+
cookie?: string | undefined;
|
| 37 |
+
date?: string | undefined;
|
| 38 |
+
etag?: string | undefined;
|
| 39 |
+
expect?: string | undefined;
|
| 40 |
+
expires?: string | undefined;
|
| 41 |
+
forwarded?: string | undefined;
|
| 42 |
+
from?: string | undefined;
|
| 43 |
+
host?: string | undefined;
|
| 44 |
+
"if-match"?: string | undefined;
|
| 45 |
+
"if-modified-since"?: string | undefined;
|
| 46 |
+
"if-none-match"?: string | undefined;
|
| 47 |
+
"if-unmodified-since"?: string | undefined;
|
| 48 |
+
"last-modified"?: string | undefined;
|
| 49 |
+
location?: string | undefined;
|
| 50 |
+
origin?: string | undefined;
|
| 51 |
+
pragma?: string | undefined;
|
| 52 |
+
"proxy-authenticate"?: string | undefined;
|
| 53 |
+
"proxy-authorization"?: string | undefined;
|
| 54 |
+
"public-key-pins"?: string | undefined;
|
| 55 |
+
range?: string | undefined;
|
| 56 |
+
referer?: string | undefined;
|
| 57 |
+
"retry-after"?: string | undefined;
|
| 58 |
+
"sec-fetch-site"?: string | undefined;
|
| 59 |
+
"sec-fetch-mode"?: string | undefined;
|
| 60 |
+
"sec-fetch-user"?: string | undefined;
|
| 61 |
+
"sec-fetch-dest"?: string | undefined;
|
| 62 |
+
"sec-websocket-accept"?: string | undefined;
|
| 63 |
+
"sec-websocket-extensions"?: string | undefined;
|
| 64 |
+
"sec-websocket-key"?: string | undefined;
|
| 65 |
+
"sec-websocket-protocol"?: string | undefined;
|
| 66 |
+
"sec-websocket-version"?: string | undefined;
|
| 67 |
+
"set-cookie"?: string[] | undefined;
|
| 68 |
+
"strict-transport-security"?: string | undefined;
|
| 69 |
+
tk?: string | undefined;
|
| 70 |
+
trailer?: string | undefined;
|
| 71 |
+
"transfer-encoding"?: string | undefined;
|
| 72 |
+
upgrade?: string | undefined;
|
| 73 |
+
"user-agent"?: string | undefined;
|
| 74 |
+
vary?: string | undefined;
|
| 75 |
+
via?: string | undefined;
|
| 76 |
+
warning?: string | undefined;
|
| 77 |
+
"www-authenticate"?: string | undefined;
|
| 78 |
+
}
|
| 79 |
+
// outgoing headers allows numbers (as they are converted internally to strings)
|
| 80 |
+
type OutgoingHttpHeader = number | string | string[];
|
| 81 |
+
interface OutgoingHttpHeaders extends NodeJS.Dict<OutgoingHttpHeader> {
|
| 82 |
+
accept?: string | string[] | undefined;
|
| 83 |
+
"accept-charset"?: string | string[] | undefined;
|
| 84 |
+
"accept-encoding"?: string | string[] | undefined;
|
| 85 |
+
"accept-language"?: string | string[] | undefined;
|
| 86 |
+
"accept-ranges"?: string | undefined;
|
| 87 |
+
"access-control-allow-credentials"?: string | undefined;
|
| 88 |
+
"access-control-allow-headers"?: string | undefined;
|
| 89 |
+
"access-control-allow-methods"?: string | undefined;
|
| 90 |
+
"access-control-allow-origin"?: string | undefined;
|
| 91 |
+
"access-control-expose-headers"?: string | undefined;
|
| 92 |
+
"access-control-max-age"?: string | undefined;
|
| 93 |
+
"access-control-request-headers"?: string | undefined;
|
| 94 |
+
"access-control-request-method"?: string | undefined;
|
| 95 |
+
age?: string | undefined;
|
| 96 |
+
allow?: string | undefined;
|
| 97 |
+
authorization?: string | undefined;
|
| 98 |
+
"cache-control"?: string | undefined;
|
| 99 |
+
"cdn-cache-control"?: string | undefined;
|
| 100 |
+
connection?: string | string[] | undefined;
|
| 101 |
+
"content-disposition"?: string | undefined;
|
| 102 |
+
"content-encoding"?: string | undefined;
|
| 103 |
+
"content-language"?: string | undefined;
|
| 104 |
+
"content-length"?: string | number | undefined;
|
| 105 |
+
"content-location"?: string | undefined;
|
| 106 |
+
"content-range"?: string | undefined;
|
| 107 |
+
"content-security-policy"?: string | undefined;
|
| 108 |
+
"content-security-policy-report-only"?: string | undefined;
|
| 109 |
+
"content-type"?: string | undefined;
|
| 110 |
+
cookie?: string | string[] | undefined;
|
| 111 |
+
dav?: string | string[] | undefined;
|
| 112 |
+
dnt?: string | undefined;
|
| 113 |
+
date?: string | undefined;
|
| 114 |
+
etag?: string | undefined;
|
| 115 |
+
expect?: string | undefined;
|
| 116 |
+
expires?: string | undefined;
|
| 117 |
+
forwarded?: string | undefined;
|
| 118 |
+
from?: string | undefined;
|
| 119 |
+
host?: string | undefined;
|
| 120 |
+
"if-match"?: string | undefined;
|
| 121 |
+
"if-modified-since"?: string | undefined;
|
| 122 |
+
"if-none-match"?: string | undefined;
|
| 123 |
+
"if-range"?: string | undefined;
|
| 124 |
+
"if-unmodified-since"?: string | undefined;
|
| 125 |
+
"last-modified"?: string | undefined;
|
| 126 |
+
link?: string | string[] | undefined;
|
| 127 |
+
location?: string | undefined;
|
| 128 |
+
"max-forwards"?: string | undefined;
|
| 129 |
+
origin?: string | undefined;
|
| 130 |
+
pragma?: string | string[] | undefined;
|
| 131 |
+
"proxy-authenticate"?: string | string[] | undefined;
|
| 132 |
+
"proxy-authorization"?: string | undefined;
|
| 133 |
+
"public-key-pins"?: string | undefined;
|
| 134 |
+
"public-key-pins-report-only"?: string | undefined;
|
| 135 |
+
range?: string | undefined;
|
| 136 |
+
referer?: string | undefined;
|
| 137 |
+
"referrer-policy"?: string | undefined;
|
| 138 |
+
refresh?: string | undefined;
|
| 139 |
+
"retry-after"?: string | undefined;
|
| 140 |
+
"sec-websocket-accept"?: string | undefined;
|
| 141 |
+
"sec-websocket-extensions"?: string | string[] | undefined;
|
| 142 |
+
"sec-websocket-key"?: string | undefined;
|
| 143 |
+
"sec-websocket-protocol"?: string | string[] | undefined;
|
| 144 |
+
"sec-websocket-version"?: string | undefined;
|
| 145 |
+
server?: string | undefined;
|
| 146 |
+
"set-cookie"?: string | string[] | undefined;
|
| 147 |
+
"strict-transport-security"?: string | undefined;
|
| 148 |
+
te?: string | undefined;
|
| 149 |
+
trailer?: string | undefined;
|
| 150 |
+
"transfer-encoding"?: string | undefined;
|
| 151 |
+
"user-agent"?: string | undefined;
|
| 152 |
+
upgrade?: string | undefined;
|
| 153 |
+
"upgrade-insecure-requests"?: string | undefined;
|
| 154 |
+
vary?: string | undefined;
|
| 155 |
+
via?: string | string[] | undefined;
|
| 156 |
+
warning?: string | undefined;
|
| 157 |
+
"www-authenticate"?: string | string[] | undefined;
|
| 158 |
+
"x-content-type-options"?: string | undefined;
|
| 159 |
+
"x-dns-prefetch-control"?: string | undefined;
|
| 160 |
+
"x-frame-options"?: string | undefined;
|
| 161 |
+
"x-xss-protection"?: string | undefined;
|
| 162 |
+
}
|
| 163 |
+
interface ClientRequestArgs extends Pick<LookupOptions, "hints"> {
|
| 164 |
+
_defaultAgent?: Agent | undefined;
|
| 165 |
+
agent?: Agent | boolean | undefined;
|
| 166 |
+
auth?: string | null | undefined;
|
| 167 |
+
createConnection?:
|
| 168 |
+
| ((
|
| 169 |
+
options: ClientRequestArgs,
|
| 170 |
+
oncreate: (err: Error | null, socket: stream.Duplex) => void,
|
| 171 |
+
) => stream.Duplex | null | undefined)
|
| 172 |
+
| undefined;
|
| 173 |
+
defaultPort?: number | string | undefined;
|
| 174 |
+
family?: number | undefined;
|
| 175 |
+
headers?: OutgoingHttpHeaders | readonly string[] | undefined;
|
| 176 |
+
host?: string | null | undefined;
|
| 177 |
+
hostname?: string | null | undefined;
|
| 178 |
+
insecureHTTPParser?: boolean | undefined;
|
| 179 |
+
localAddress?: string | undefined;
|
| 180 |
+
localPort?: number | undefined;
|
| 181 |
+
lookup?: net.LookupFunction | undefined;
|
| 182 |
+
/**
|
| 183 |
+
* @default 16384
|
| 184 |
+
*/
|
| 185 |
+
maxHeaderSize?: number | undefined;
|
| 186 |
+
method?: string | undefined;
|
| 187 |
+
path?: string | null | undefined;
|
| 188 |
+
port?: number | string | null | undefined;
|
| 189 |
+
protocol?: string | null | undefined;
|
| 190 |
+
setDefaultHeaders?: boolean | undefined;
|
| 191 |
+
setHost?: boolean | undefined;
|
| 192 |
+
signal?: AbortSignal | undefined;
|
| 193 |
+
socketPath?: string | undefined;
|
| 194 |
+
timeout?: number | undefined;
|
| 195 |
+
uniqueHeaders?: Array<string | string[]> | undefined;
|
| 196 |
+
joinDuplicateHeaders?: boolean | undefined;
|
| 197 |
+
}
|
| 198 |
+
interface ServerOptions<
|
| 199 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
| 200 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
| 201 |
+
> {
|
| 202 |
+
/**
|
| 203 |
+
* Specifies the `IncomingMessage` class to be used. Useful for extending the original `IncomingMessage`.
|
| 204 |
+
*/
|
| 205 |
+
IncomingMessage?: Request | undefined;
|
| 206 |
+
/**
|
| 207 |
+
* Specifies the `ServerResponse` class to be used. Useful for extending the original `ServerResponse`.
|
| 208 |
+
*/
|
| 209 |
+
ServerResponse?: Response | undefined;
|
| 210 |
+
/**
|
| 211 |
+
* Sets the timeout value in milliseconds for receiving the entire request from the client.
|
| 212 |
+
* @see Server.requestTimeout for more information.
|
| 213 |
+
* @default 300000
|
| 214 |
+
* @since v18.0.0
|
| 215 |
+
*/
|
| 216 |
+
requestTimeout?: number | undefined;
|
| 217 |
+
/**
|
| 218 |
+
* It joins the field line values of multiple headers in a request with `, ` instead of discarding the duplicates.
|
| 219 |
+
* @default false
|
| 220 |
+
* @since v18.14.0
|
| 221 |
+
*/
|
| 222 |
+
joinDuplicateHeaders?: boolean | undefined;
|
| 223 |
+
/**
|
| 224 |
+
* The number of milliseconds of inactivity a server needs to wait for additional incoming data,
|
| 225 |
+
* after it has finished writing the last response, before a socket will be destroyed.
|
| 226 |
+
* @see Server.keepAliveTimeout for more information.
|
| 227 |
+
* @default 5000
|
| 228 |
+
* @since v18.0.0
|
| 229 |
+
*/
|
| 230 |
+
keepAliveTimeout?: number | undefined;
|
| 231 |
+
/**
|
| 232 |
+
* An additional buffer time added to the
|
| 233 |
+
* `server.keepAliveTimeout` to extend the internal socket timeout.
|
| 234 |
+
* @since 24.6.0
|
| 235 |
+
* @default 1000
|
| 236 |
+
*/
|
| 237 |
+
keepAliveTimeoutBuffer?: number | undefined;
|
| 238 |
+
/**
|
| 239 |
+
* Sets the interval value in milliseconds to check for request and headers timeout in incomplete requests.
|
| 240 |
+
* @default 30000
|
| 241 |
+
*/
|
| 242 |
+
connectionsCheckingInterval?: number | undefined;
|
| 243 |
+
/**
|
| 244 |
+
* Sets the timeout value in milliseconds for receiving the complete HTTP headers from the client.
|
| 245 |
+
* See {@link Server.headersTimeout} for more information.
|
| 246 |
+
* @default 60000
|
| 247 |
+
* @since 18.0.0
|
| 248 |
+
*/
|
| 249 |
+
headersTimeout?: number | undefined;
|
| 250 |
+
/**
|
| 251 |
+
* Optionally overrides all `socket`s' `readableHighWaterMark` and `writableHighWaterMark`.
|
| 252 |
+
* This affects `highWaterMark` property of both `IncomingMessage` and `ServerResponse`.
|
| 253 |
+
* Default: @see stream.getDefaultHighWaterMark().
|
| 254 |
+
* @since v20.1.0
|
| 255 |
+
*/
|
| 256 |
+
highWaterMark?: number | undefined;
|
| 257 |
+
/**
|
| 258 |
+
* Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
|
| 259 |
+
* Using the insecure parser should be avoided.
|
| 260 |
+
* See --insecure-http-parser for more information.
|
| 261 |
+
* @default false
|
| 262 |
+
*/
|
| 263 |
+
insecureHTTPParser?: boolean | undefined;
|
| 264 |
+
/**
|
| 265 |
+
* Optionally overrides the value of `--max-http-header-size` for requests received by
|
| 266 |
+
* this server, i.e. the maximum length of request headers in bytes.
|
| 267 |
+
* @default 16384
|
| 268 |
+
* @since v13.3.0
|
| 269 |
+
*/
|
| 270 |
+
maxHeaderSize?: number | undefined;
|
| 271 |
+
/**
|
| 272 |
+
* If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
|
| 273 |
+
* @default true
|
| 274 |
+
* @since v16.5.0
|
| 275 |
+
*/
|
| 276 |
+
noDelay?: boolean | undefined;
|
| 277 |
+
/**
|
| 278 |
+
* If set to `true`, it forces the server to respond with a 400 (Bad Request) status code
|
| 279 |
+
* to any HTTP/1.1 request message that lacks a Host header (as mandated by the specification).
|
| 280 |
+
* @default true
|
| 281 |
+
* @since 20.0.0
|
| 282 |
+
*/
|
| 283 |
+
requireHostHeader?: boolean | undefined;
|
| 284 |
+
/**
|
| 285 |
+
* If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
|
| 286 |
+
* similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
|
| 287 |
+
* @default false
|
| 288 |
+
* @since v16.5.0
|
| 289 |
+
*/
|
| 290 |
+
keepAlive?: boolean | undefined;
|
| 291 |
+
/**
|
| 292 |
+
* If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
|
| 293 |
+
* @default 0
|
| 294 |
+
* @since v16.5.0
|
| 295 |
+
*/
|
| 296 |
+
keepAliveInitialDelay?: number | undefined;
|
| 297 |
+
/**
|
| 298 |
+
* A list of response headers that should be sent only once.
|
| 299 |
+
* If the header's value is an array, the items will be joined using `; `.
|
| 300 |
+
*/
|
| 301 |
+
uniqueHeaders?: Array<string | string[]> | undefined;
|
| 302 |
+
/**
|
| 303 |
+
* A callback which receives an
|
| 304 |
+
* incoming request and returns a boolean, to control which upgrade attempts
|
| 305 |
+
* should be accepted. Accepted upgrades will fire an `'upgrade'` event (or
|
| 306 |
+
* their sockets will be destroyed, if no listener is registered) while
|
| 307 |
+
* rejected upgrades will fire a `'request'` event like any non-upgrade
|
| 308 |
+
* request.
|
| 309 |
+
* @since v24.9.0
|
| 310 |
+
* @default () => server.listenerCount('upgrade') > 0
|
| 311 |
+
*/
|
| 312 |
+
shouldUpgradeCallback?: ((request: InstanceType<Request>) => boolean) | undefined;
|
| 313 |
+
/**
|
| 314 |
+
* If set to `true`, an error is thrown when writing to an HTTP response which does not have a body.
|
| 315 |
+
* @default false
|
| 316 |
+
* @since v18.17.0, v20.2.0
|
| 317 |
+
*/
|
| 318 |
+
rejectNonStandardBodyWrites?: boolean | undefined;
|
| 319 |
+
/**
|
| 320 |
+
* If set to `true`, requests without `Content-Length`
|
| 321 |
+
* or `Transfer-Encoding` headers (indicating no body) will be initialized with an
|
| 322 |
+
* already-ended body stream, so they will never emit any stream events
|
| 323 |
+
* (like `'data'` or `'end'`). You can use `req.readableEnded` to detect this case.
|
| 324 |
+
* @since v25.1.0
|
| 325 |
+
* @default false
|
| 326 |
+
*/
|
| 327 |
+
optimizeEmptyRequests?: boolean | undefined;
|
| 328 |
+
}
|
| 329 |
+
type RequestListener<
|
| 330 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
| 331 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
| 332 |
+
> = (request: InstanceType<Request>, response: InstanceType<Response> & { req: InstanceType<Request> }) => void;
|
| 333 |
+
interface ServerEventMap<
|
| 334 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
| 335 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
| 336 |
+
> extends net.ServerEventMap {
|
| 337 |
+
"checkContinue": Parameters<RequestListener<Request, Response>>;
|
| 338 |
+
"checkExpectation": Parameters<RequestListener<Request, Response>>;
|
| 339 |
+
"clientError": [exception: Error, socket: stream.Duplex];
|
| 340 |
+
"connect": [request: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer];
|
| 341 |
+
"connection": [socket: net.Socket];
|
| 342 |
+
"dropRequest": [request: InstanceType<Request>, socket: stream.Duplex];
|
| 343 |
+
"request": Parameters<RequestListener<Request, Response>>;
|
| 344 |
+
"upgrade": [req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer];
|
| 345 |
+
}
|
| 346 |
+
/**
|
| 347 |
+
* @since v0.1.17
|
| 348 |
+
*/
|
| 349 |
+
class Server<
|
| 350 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
| 351 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
| 352 |
+
> extends net.Server {
|
| 353 |
+
constructor(requestListener?: RequestListener<Request, Response>);
|
| 354 |
+
constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
|
| 355 |
+
/**
|
| 356 |
+
* Sets the timeout value for sockets, and emits a `'timeout'` event on
|
| 357 |
+
* the Server object, passing the socket as an argument, if a timeout
|
| 358 |
+
* occurs.
|
| 359 |
+
*
|
| 360 |
+
* If there is a `'timeout'` event listener on the Server object, then it
|
| 361 |
+
* will be called with the timed-out socket as an argument.
|
| 362 |
+
*
|
| 363 |
+
* By default, the Server does not timeout sockets. However, if a callback
|
| 364 |
+
* is assigned to the Server's `'timeout'` event, timeouts must be handled
|
| 365 |
+
* explicitly.
|
| 366 |
+
* @since v0.9.12
|
| 367 |
+
* @param [msecs=0 (no timeout)]
|
| 368 |
+
*/
|
| 369 |
+
setTimeout(msecs?: number, callback?: (socket: net.Socket) => void): this;
|
| 370 |
+
setTimeout(callback: (socket: net.Socket) => void): this;
|
| 371 |
+
/**
|
| 372 |
+
* Limits maximum incoming headers count. If set to 0, no limit will be applied.
|
| 373 |
+
* @since v0.7.0
|
| 374 |
+
*/
|
| 375 |
+
maxHeadersCount: number | null;
|
| 376 |
+
/**
|
| 377 |
+
* The maximum number of requests socket can handle
|
| 378 |
+
* before closing keep alive connection.
|
| 379 |
+
*
|
| 380 |
+
* A value of `0` will disable the limit.
|
| 381 |
+
*
|
| 382 |
+
* When the limit is reached it will set the `Connection` header value to `close`,
|
| 383 |
+
* but will not actually close the connection, subsequent requests sent
|
| 384 |
+
* after the limit is reached will get `503 Service Unavailable` as a response.
|
| 385 |
+
* @since v16.10.0
|
| 386 |
+
*/
|
| 387 |
+
maxRequestsPerSocket: number | null;
|
| 388 |
+
/**
|
| 389 |
+
* The number of milliseconds of inactivity before a socket is presumed
|
| 390 |
+
* to have timed out.
|
| 391 |
+
*
|
| 392 |
+
* A value of `0` will disable the timeout behavior on incoming connections.
|
| 393 |
+
*
|
| 394 |
+
* The socket timeout logic is set up on connection, so changing this
|
| 395 |
+
* value only affects new connections to the server, not any existing connections.
|
| 396 |
+
* @since v0.9.12
|
| 397 |
+
*/
|
| 398 |
+
timeout: number;
|
| 399 |
+
/**
|
| 400 |
+
* Limit the amount of time the parser will wait to receive the complete HTTP
|
| 401 |
+
* headers.
|
| 402 |
+
*
|
| 403 |
+
* If the timeout expires, the server responds with status 408 without
|
| 404 |
+
* forwarding the request to the request listener and then closes the connection.
|
| 405 |
+
*
|
| 406 |
+
* It must be set to a non-zero value (e.g. 120 seconds) to protect against
|
| 407 |
+
* potential Denial-of-Service attacks in case the server is deployed without a
|
| 408 |
+
* reverse proxy in front.
|
| 409 |
+
* @since v11.3.0, v10.14.0
|
| 410 |
+
*/
|
| 411 |
+
headersTimeout: number;
|
| 412 |
+
/**
|
| 413 |
+
* The number of milliseconds of inactivity a server needs to wait for additional
|
| 414 |
+
* incoming data, after it has finished writing the last response, before a socket
|
| 415 |
+
* will be destroyed.
|
| 416 |
+
*
|
| 417 |
+
* This timeout value is combined with the
|
| 418 |
+
* `server.keepAliveTimeoutBuffer` option to determine the actual socket
|
| 419 |
+
* timeout, calculated as:
|
| 420 |
+
* socketTimeout = keepAliveTimeout + keepAliveTimeoutBuffer
|
| 421 |
+
* If the server receives new data before the keep-alive timeout has fired, it
|
| 422 |
+
* will reset the regular inactivity timeout, i.e., `server.timeout`.
|
| 423 |
+
*
|
| 424 |
+
* A value of `0` will disable the keep-alive timeout behavior on incoming
|
| 425 |
+
* connections.
|
| 426 |
+
* A value of `0` makes the HTTP server behave similarly to Node.js versions prior
|
| 427 |
+
* to 8.0.0, which did not have a keep-alive timeout.
|
| 428 |
+
*
|
| 429 |
+
* The socket timeout logic is set up on connection, so changing this value only
|
| 430 |
+
* affects new connections to the server, not any existing connections.
|
| 431 |
+
* @since v8.0.0
|
| 432 |
+
*/
|
| 433 |
+
keepAliveTimeout: number;
|
| 434 |
+
/**
|
| 435 |
+
* An additional buffer time added to the
|
| 436 |
+
* `server.keepAliveTimeout` to extend the internal socket timeout.
|
| 437 |
+
*
|
| 438 |
+
* This buffer helps reduce connection reset (`ECONNRESET`) errors by increasing
|
| 439 |
+
* the socket timeout slightly beyond the advertised keep-alive timeout.
|
| 440 |
+
*
|
| 441 |
+
* This option applies only to new incoming connections.
|
| 442 |
+
* @since v24.6.0
|
| 443 |
+
* @default 1000
|
| 444 |
+
*/
|
| 445 |
+
keepAliveTimeoutBuffer: number;
|
| 446 |
+
/**
|
| 447 |
+
* Sets the timeout value in milliseconds for receiving the entire request from
|
| 448 |
+
* the client.
|
| 449 |
+
*
|
| 450 |
+
* If the timeout expires, the server responds with status 408 without
|
| 451 |
+
* forwarding the request to the request listener and then closes the connection.
|
| 452 |
+
*
|
| 453 |
+
* It must be set to a non-zero value (e.g. 120 seconds) to protect against
|
| 454 |
+
* potential Denial-of-Service attacks in case the server is deployed without a
|
| 455 |
+
* reverse proxy in front.
|
| 456 |
+
* @since v14.11.0
|
| 457 |
+
*/
|
| 458 |
+
requestTimeout: number;
|
| 459 |
+
/**
|
| 460 |
+
* Closes all connections connected to this server.
|
| 461 |
+
* @since v18.2.0
|
| 462 |
+
*/
|
| 463 |
+
closeAllConnections(): void;
|
| 464 |
+
/**
|
| 465 |
+
* Closes all connections connected to this server which are not sending a request
|
| 466 |
+
* or waiting for a response.
|
| 467 |
+
* @since v18.2.0
|
| 468 |
+
*/
|
| 469 |
+
closeIdleConnections(): void;
|
| 470 |
+
// #region InternalEventEmitter
|
| 471 |
+
addListener<E extends keyof ServerEventMap>(
|
| 472 |
+
eventName: E,
|
| 473 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 474 |
+
): this;
|
| 475 |
+
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 476 |
+
emit<E extends keyof ServerEventMap>(eventName: E, ...args: ServerEventMap<Request, Response>[E]): boolean;
|
| 477 |
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
| 478 |
+
listenerCount<E extends keyof ServerEventMap>(
|
| 479 |
+
eventName: E,
|
| 480 |
+
listener?: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 481 |
+
): number;
|
| 482 |
+
listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
|
| 483 |
+
listeners<E extends keyof ServerEventMap>(
|
| 484 |
+
eventName: E,
|
| 485 |
+
): ((...args: ServerEventMap<Request, Response>[E]) => void)[];
|
| 486 |
+
listeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 487 |
+
off<E extends keyof ServerEventMap>(
|
| 488 |
+
eventName: E,
|
| 489 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 490 |
+
): this;
|
| 491 |
+
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 492 |
+
on<E extends keyof ServerEventMap>(
|
| 493 |
+
eventName: E,
|
| 494 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 495 |
+
): this;
|
| 496 |
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 497 |
+
once<E extends keyof ServerEventMap>(
|
| 498 |
+
eventName: E,
|
| 499 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 500 |
+
): this;
|
| 501 |
+
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 502 |
+
prependListener<E extends keyof ServerEventMap>(
|
| 503 |
+
eventName: E,
|
| 504 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 505 |
+
): this;
|
| 506 |
+
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 507 |
+
prependOnceListener<E extends keyof ServerEventMap>(
|
| 508 |
+
eventName: E,
|
| 509 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 510 |
+
): this;
|
| 511 |
+
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 512 |
+
rawListeners<E extends keyof ServerEventMap>(
|
| 513 |
+
eventName: E,
|
| 514 |
+
): ((...args: ServerEventMap<Request, Response>[E]) => void)[];
|
| 515 |
+
rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 516 |
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
| 517 |
+
removeAllListeners<E extends keyof ServerEventMap>(eventName?: E): this;
|
| 518 |
+
removeAllListeners(eventName?: string | symbol): this;
|
| 519 |
+
removeListener<E extends keyof ServerEventMap>(
|
| 520 |
+
eventName: E,
|
| 521 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 522 |
+
): this;
|
| 523 |
+
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 524 |
+
// #endregion
|
| 525 |
+
}
|
| 526 |
+
interface OutgoingMessageEventMap extends stream.WritableEventMap {
|
| 527 |
+
"prefinish": [];
|
| 528 |
+
}
|
| 529 |
+
/**
|
| 530 |
+
* This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract outgoing message from
|
| 531 |
+
* the perspective of the participants of an HTTP transaction.
|
| 532 |
+
* @since v0.1.17
|
| 533 |
+
*/
|
| 534 |
+
class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
|
| 535 |
+
constructor();
|
| 536 |
+
readonly req: Request;
|
| 537 |
+
chunkedEncoding: boolean;
|
| 538 |
+
shouldKeepAlive: boolean;
|
| 539 |
+
useChunkedEncodingByDefault: boolean;
|
| 540 |
+
sendDate: boolean;
|
| 541 |
+
/**
|
| 542 |
+
* @deprecated Use `writableEnded` instead.
|
| 543 |
+
*/
|
| 544 |
+
finished: boolean;
|
| 545 |
+
/**
|
| 546 |
+
* Read-only. `true` if the headers were sent, otherwise `false`.
|
| 547 |
+
* @since v0.9.3
|
| 548 |
+
*/
|
| 549 |
+
readonly headersSent: boolean;
|
| 550 |
+
/**
|
| 551 |
+
* Alias of `outgoingMessage.socket`.
|
| 552 |
+
* @since v0.3.0
|
| 553 |
+
* @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
|
| 554 |
+
*/
|
| 555 |
+
readonly connection: net.Socket | null;
|
| 556 |
+
/**
|
| 557 |
+
* Reference to the underlying socket. Usually, users will not want to access
|
| 558 |
+
* this property.
|
| 559 |
+
*
|
| 560 |
+
* After calling `outgoingMessage.end()`, this property will be nulled.
|
| 561 |
+
* @since v0.3.0
|
| 562 |
+
*/
|
| 563 |
+
readonly socket: net.Socket | null;
|
| 564 |
+
/**
|
| 565 |
+
* Once a socket is associated with the message and is connected, `socket.setTimeout()` will be called with `msecs` as the first parameter.
|
| 566 |
+
* @since v0.9.12
|
| 567 |
+
* @param callback Optional function to be called when a timeout occurs. Same as binding to the `timeout` event.
|
| 568 |
+
*/
|
| 569 |
+
setTimeout(msecs: number, callback?: () => void): this;
|
| 570 |
+
/**
|
| 571 |
+
* Sets a single header value. If the header already exists in the to-be-sent
|
| 572 |
+
* headers, its value will be replaced. Use an array of strings to send multiple
|
| 573 |
+
* headers with the same name.
|
| 574 |
+
* @since v0.4.0
|
| 575 |
+
* @param name Header name
|
| 576 |
+
* @param value Header value
|
| 577 |
+
*/
|
| 578 |
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
| 579 |
+
/**
|
| 580 |
+
* Sets multiple header values for implicit headers. headers must be an instance of
|
| 581 |
+
* `Headers` or `Map`, if a header already exists in the to-be-sent headers, its
|
| 582 |
+
* value will be replaced.
|
| 583 |
+
*
|
| 584 |
+
* ```js
|
| 585 |
+
* const headers = new Headers({ foo: 'bar' });
|
| 586 |
+
* outgoingMessage.setHeaders(headers);
|
| 587 |
+
* ```
|
| 588 |
+
*
|
| 589 |
+
* or
|
| 590 |
+
*
|
| 591 |
+
* ```js
|
| 592 |
+
* const headers = new Map([['foo', 'bar']]);
|
| 593 |
+
* outgoingMessage.setHeaders(headers);
|
| 594 |
+
* ```
|
| 595 |
+
*
|
| 596 |
+
* When headers have been set with `outgoingMessage.setHeaders()`, they will be
|
| 597 |
+
* merged with any headers passed to `response.writeHead()`, with the headers passed
|
| 598 |
+
* to `response.writeHead()` given precedence.
|
| 599 |
+
*
|
| 600 |
+
* ```js
|
| 601 |
+
* // Returns content-type = text/plain
|
| 602 |
+
* const server = http.createServer((req, res) => {
|
| 603 |
+
* const headers = new Headers({ 'Content-Type': 'text/html' });
|
| 604 |
+
* res.setHeaders(headers);
|
| 605 |
+
* res.writeHead(200, { 'Content-Type': 'text/plain' });
|
| 606 |
+
* res.end('ok');
|
| 607 |
+
* });
|
| 608 |
+
* ```
|
| 609 |
+
*
|
| 610 |
+
* @since v19.6.0, v18.15.0
|
| 611 |
+
* @param name Header name
|
| 612 |
+
* @param value Header value
|
| 613 |
+
*/
|
| 614 |
+
setHeaders(headers: Headers | Map<string, number | string | readonly string[]>): this;
|
| 615 |
+
/**
|
| 616 |
+
* Append a single header value to the header object.
|
| 617 |
+
*
|
| 618 |
+
* If the value is an array, this is equivalent to calling this method multiple
|
| 619 |
+
* times.
|
| 620 |
+
*
|
| 621 |
+
* If there were no previous values for the header, this is equivalent to calling `outgoingMessage.setHeader(name, value)`.
|
| 622 |
+
*
|
| 623 |
+
* Depending of the value of `options.uniqueHeaders` when the client request or the
|
| 624 |
+
* server were created, this will end up in the header being sent multiple times or
|
| 625 |
+
* a single time with values joined using `; `.
|
| 626 |
+
* @since v18.3.0, v16.17.0
|
| 627 |
+
* @param name Header name
|
| 628 |
+
* @param value Header value
|
| 629 |
+
*/
|
| 630 |
+
appendHeader(name: string, value: string | readonly string[]): this;
|
| 631 |
+
/**
|
| 632 |
+
* Gets the value of the HTTP header with the given name. If that header is not
|
| 633 |
+
* set, the returned value will be `undefined`.
|
| 634 |
+
* @since v0.4.0
|
| 635 |
+
* @param name Name of header
|
| 636 |
+
*/
|
| 637 |
+
getHeader(name: string): number | string | string[] | undefined;
|
| 638 |
+
/**
|
| 639 |
+
* Returns a shallow copy of the current outgoing headers. Since a shallow
|
| 640 |
+
* copy is used, array values may be mutated without additional calls to
|
| 641 |
+
* various header-related HTTP module methods. The keys of the returned
|
| 642 |
+
* object are the header names and the values are the respective header
|
| 643 |
+
* values. All header names are lowercase.
|
| 644 |
+
*
|
| 645 |
+
* The object returned by the `outgoingMessage.getHeaders()` method does
|
| 646 |
+
* not prototypically inherit from the JavaScript `Object`. This means that
|
| 647 |
+
* typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,
|
| 648 |
+
* and others are not defined and will not work.
|
| 649 |
+
*
|
| 650 |
+
* ```js
|
| 651 |
+
* outgoingMessage.setHeader('Foo', 'bar');
|
| 652 |
+
* outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
| 653 |
+
*
|
| 654 |
+
* const headers = outgoingMessage.getHeaders();
|
| 655 |
+
* // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
|
| 656 |
+
* ```
|
| 657 |
+
* @since v7.7.0
|
| 658 |
+
*/
|
| 659 |
+
getHeaders(): OutgoingHttpHeaders;
|
| 660 |
+
/**
|
| 661 |
+
* Returns an array containing the unique names of the current outgoing headers.
|
| 662 |
+
* All names are lowercase.
|
| 663 |
+
* @since v7.7.0
|
| 664 |
+
*/
|
| 665 |
+
getHeaderNames(): string[];
|
| 666 |
+
/**
|
| 667 |
+
* Returns `true` if the header identified by `name` is currently set in the
|
| 668 |
+
* outgoing headers. The header name is case-insensitive.
|
| 669 |
+
*
|
| 670 |
+
* ```js
|
| 671 |
+
* const hasContentType = outgoingMessage.hasHeader('content-type');
|
| 672 |
+
* ```
|
| 673 |
+
* @since v7.7.0
|
| 674 |
+
*/
|
| 675 |
+
hasHeader(name: string): boolean;
|
| 676 |
+
/**
|
| 677 |
+
* Removes a header that is queued for implicit sending.
|
| 678 |
+
*
|
| 679 |
+
* ```js
|
| 680 |
+
* outgoingMessage.removeHeader('Content-Encoding');
|
| 681 |
+
* ```
|
| 682 |
+
* @since v0.4.0
|
| 683 |
+
* @param name Header name
|
| 684 |
+
*/
|
| 685 |
+
removeHeader(name: string): void;
|
| 686 |
+
/**
|
| 687 |
+
* Adds HTTP trailers (headers but at the end of the message) to the message.
|
| 688 |
+
*
|
| 689 |
+
* Trailers will **only** be emitted if the message is chunked encoded. If not,
|
| 690 |
+
* the trailers will be silently discarded.
|
| 691 |
+
*
|
| 692 |
+
* HTTP requires the `Trailer` header to be sent to emit trailers,
|
| 693 |
+
* with a list of header field names in its value, e.g.
|
| 694 |
+
*
|
| 695 |
+
* ```js
|
| 696 |
+
* message.writeHead(200, { 'Content-Type': 'text/plain',
|
| 697 |
+
* 'Trailer': 'Content-MD5' });
|
| 698 |
+
* message.write(fileData);
|
| 699 |
+
* message.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });
|
| 700 |
+
* message.end();
|
| 701 |
+
* ```
|
| 702 |
+
*
|
| 703 |
+
* Attempting to set a header field name or value that contains invalid characters
|
| 704 |
+
* will result in a `TypeError` being thrown.
|
| 705 |
+
* @since v0.3.0
|
| 706 |
+
*/
|
| 707 |
+
addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
|
| 708 |
+
/**
|
| 709 |
+
* Flushes the message headers.
|
| 710 |
+
*
|
| 711 |
+
* For efficiency reason, Node.js normally buffers the message headers
|
| 712 |
+
* until `outgoingMessage.end()` is called or the first chunk of message data
|
| 713 |
+
* is written. It then tries to pack the headers and data into a single TCP
|
| 714 |
+
* packet.
|
| 715 |
+
*
|
| 716 |
+
* It is usually desired (it saves a TCP round-trip), but not when the first
|
| 717 |
+
* data is not sent until possibly much later. `outgoingMessage.flushHeaders()` bypasses the optimization and kickstarts the message.
|
| 718 |
+
* @since v1.6.0
|
| 719 |
+
*/
|
| 720 |
+
flushHeaders(): void;
|
| 721 |
+
// #region InternalEventEmitter
|
| 722 |
+
addListener<E extends keyof OutgoingMessageEventMap>(
|
| 723 |
+
eventName: E,
|
| 724 |
+
listener: (...args: OutgoingMessageEventMap[E]) => void,
|
| 725 |
+
): this;
|
| 726 |
+
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 727 |
+
emit<E extends keyof OutgoingMessageEventMap>(eventName: E, ...args: OutgoingMessageEventMap[E]): boolean;
|
| 728 |
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
| 729 |
+
listenerCount<E extends keyof OutgoingMessageEventMap>(
|
| 730 |
+
eventName: E,
|
| 731 |
+
listener?: (...args: OutgoingMessageEventMap[E]) => void,
|
| 732 |
+
): number;
|
| 733 |
+
listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
|
| 734 |
+
listeners<E extends keyof OutgoingMessageEventMap>(
|
| 735 |
+
eventName: E,
|
| 736 |
+
): ((...args: OutgoingMessageEventMap[E]) => void)[];
|
| 737 |
+
listeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 738 |
+
off<E extends keyof OutgoingMessageEventMap>(
|
| 739 |
+
eventName: E,
|
| 740 |
+
listener: (...args: OutgoingMessageEventMap[E]) => void,
|
| 741 |
+
): this;
|
| 742 |
+
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 743 |
+
on<E extends keyof OutgoingMessageEventMap>(
|
| 744 |
+
eventName: E,
|
| 745 |
+
listener: (...args: OutgoingMessageEventMap[E]) => void,
|
| 746 |
+
): this;
|
| 747 |
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 748 |
+
once<E extends keyof OutgoingMessageEventMap>(
|
| 749 |
+
eventName: E,
|
| 750 |
+
listener: (...args: OutgoingMessageEventMap[E]) => void,
|
| 751 |
+
): this;
|
| 752 |
+
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 753 |
+
prependListener<E extends keyof OutgoingMessageEventMap>(
|
| 754 |
+
eventName: E,
|
| 755 |
+
listener: (...args: OutgoingMessageEventMap[E]) => void,
|
| 756 |
+
): this;
|
| 757 |
+
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 758 |
+
prependOnceListener<E extends keyof OutgoingMessageEventMap>(
|
| 759 |
+
eventName: E,
|
| 760 |
+
listener: (...args: OutgoingMessageEventMap[E]) => void,
|
| 761 |
+
): this;
|
| 762 |
+
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 763 |
+
rawListeners<E extends keyof OutgoingMessageEventMap>(
|
| 764 |
+
eventName: E,
|
| 765 |
+
): ((...args: OutgoingMessageEventMap[E]) => void)[];
|
| 766 |
+
rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 767 |
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
| 768 |
+
removeAllListeners<E extends keyof OutgoingMessageEventMap>(eventName?: E): this;
|
| 769 |
+
removeAllListeners(eventName?: string | symbol): this;
|
| 770 |
+
removeListener<E extends keyof OutgoingMessageEventMap>(
|
| 771 |
+
eventName: E,
|
| 772 |
+
listener: (...args: OutgoingMessageEventMap[E]) => void,
|
| 773 |
+
): this;
|
| 774 |
+
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 775 |
+
// #endregion
|
| 776 |
+
}
|
| 777 |
+
/**
|
| 778 |
+
* This object is created internally by an HTTP server, not by the user. It is
|
| 779 |
+
* passed as the second parameter to the `'request'` event.
|
| 780 |
+
* @since v0.1.17
|
| 781 |
+
*/
|
| 782 |
+
class ServerResponse<Request extends IncomingMessage = IncomingMessage> extends OutgoingMessage<Request> {
|
| 783 |
+
/**
|
| 784 |
+
* When using implicit headers (not calling `response.writeHead()` explicitly),
|
| 785 |
+
* this property controls the status code that will be sent to the client when
|
| 786 |
+
* the headers get flushed.
|
| 787 |
+
*
|
| 788 |
+
* ```js
|
| 789 |
+
* response.statusCode = 404;
|
| 790 |
+
* ```
|
| 791 |
+
*
|
| 792 |
+
* After response header was sent to the client, this property indicates the
|
| 793 |
+
* status code which was sent out.
|
| 794 |
+
* @since v0.4.0
|
| 795 |
+
*/
|
| 796 |
+
statusCode: number;
|
| 797 |
+
/**
|
| 798 |
+
* When using implicit headers (not calling `response.writeHead()` explicitly),
|
| 799 |
+
* this property controls the status message that will be sent to the client when
|
| 800 |
+
* the headers get flushed. If this is left as `undefined` then the standard
|
| 801 |
+
* message for the status code will be used.
|
| 802 |
+
*
|
| 803 |
+
* ```js
|
| 804 |
+
* response.statusMessage = 'Not found';
|
| 805 |
+
* ```
|
| 806 |
+
*
|
| 807 |
+
* After response header was sent to the client, this property indicates the
|
| 808 |
+
* status message which was sent out.
|
| 809 |
+
* @since v0.11.8
|
| 810 |
+
*/
|
| 811 |
+
statusMessage: string;
|
| 812 |
+
/**
|
| 813 |
+
* If set to `true`, Node.js will check whether the `Content-Length` header value and the size of the body, in bytes, are equal.
|
| 814 |
+
* Mismatching the `Content-Length` header value will result
|
| 815 |
+
* in an `Error` being thrown, identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
|
| 816 |
+
* @since v18.10.0, v16.18.0
|
| 817 |
+
*/
|
| 818 |
+
strictContentLength: boolean;
|
| 819 |
+
constructor(req: Request);
|
| 820 |
+
assignSocket(socket: net.Socket): void;
|
| 821 |
+
detachSocket(socket: net.Socket): void;
|
| 822 |
+
/**
|
| 823 |
+
* Sends an HTTP/1.1 100 Continue message to the client, indicating that
|
| 824 |
+
* the request body should be sent. See the `'checkContinue'` event on `Server`.
|
| 825 |
+
* @since v0.3.0
|
| 826 |
+
*/
|
| 827 |
+
writeContinue(callback?: () => void): void;
|
| 828 |
+
/**
|
| 829 |
+
* Sends an HTTP/1.1 103 Early Hints message to the client with a Link header,
|
| 830 |
+
* indicating that the user agent can preload/preconnect the linked resources.
|
| 831 |
+
* The `hints` is an object containing the values of headers to be sent with
|
| 832 |
+
* early hints message. The optional `callback` argument will be called when
|
| 833 |
+
* the response message has been written.
|
| 834 |
+
*
|
| 835 |
+
* **Example**
|
| 836 |
+
*
|
| 837 |
+
* ```js
|
| 838 |
+
* const earlyHintsLink = '</styles.css>; rel=preload; as=style';
|
| 839 |
+
* response.writeEarlyHints({
|
| 840 |
+
* 'link': earlyHintsLink,
|
| 841 |
+
* });
|
| 842 |
+
*
|
| 843 |
+
* const earlyHintsLinks = [
|
| 844 |
+
* '</styles.css>; rel=preload; as=style',
|
| 845 |
+
* '</scripts.js>; rel=preload; as=script',
|
| 846 |
+
* ];
|
| 847 |
+
* response.writeEarlyHints({
|
| 848 |
+
* 'link': earlyHintsLinks,
|
| 849 |
+
* 'x-trace-id': 'id for diagnostics',
|
| 850 |
+
* });
|
| 851 |
+
*
|
| 852 |
+
* const earlyHintsCallback = () => console.log('early hints message sent');
|
| 853 |
+
* response.writeEarlyHints({
|
| 854 |
+
* 'link': earlyHintsLinks,
|
| 855 |
+
* }, earlyHintsCallback);
|
| 856 |
+
* ```
|
| 857 |
+
* @since v18.11.0
|
| 858 |
+
* @param hints An object containing the values of headers
|
| 859 |
+
* @param callback Will be called when the response message has been written
|
| 860 |
+
*/
|
| 861 |
+
writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;
|
| 862 |
+
/**
|
| 863 |
+
* Sends a response header to the request. The status code is a 3-digit HTTP
|
| 864 |
+
* status code, like `404`. The last argument, `headers`, are the response headers.
|
| 865 |
+
* Optionally one can give a human-readable `statusMessage` as the second
|
| 866 |
+
* argument.
|
| 867 |
+
*
|
| 868 |
+
* `headers` may be an `Array` where the keys and values are in the same list.
|
| 869 |
+
* It is _not_ a list of tuples. So, the even-numbered offsets are key values,
|
| 870 |
+
* and the odd-numbered offsets are the associated values. The array is in the same
|
| 871 |
+
* format as `request.rawHeaders`.
|
| 872 |
+
*
|
| 873 |
+
* Returns a reference to the `ServerResponse`, so that calls can be chained.
|
| 874 |
+
*
|
| 875 |
+
* ```js
|
| 876 |
+
* const body = 'hello world';
|
| 877 |
+
* response
|
| 878 |
+
* .writeHead(200, {
|
| 879 |
+
* 'Content-Length': Buffer.byteLength(body),
|
| 880 |
+
* 'Content-Type': 'text/plain',
|
| 881 |
+
* })
|
| 882 |
+
* .end(body);
|
| 883 |
+
* ```
|
| 884 |
+
*
|
| 885 |
+
* This method must only be called once on a message and it must
|
| 886 |
+
* be called before `response.end()` is called.
|
| 887 |
+
*
|
| 888 |
+
* If `response.write()` or `response.end()` are called before calling
|
| 889 |
+
* this, the implicit/mutable headers will be calculated and call this function.
|
| 890 |
+
*
|
| 891 |
+
* When headers have been set with `response.setHeader()`, they will be merged
|
| 892 |
+
* with any headers passed to `response.writeHead()`, with the headers passed
|
| 893 |
+
* to `response.writeHead()` given precedence.
|
| 894 |
+
*
|
| 895 |
+
* If this method is called and `response.setHeader()` has not been called,
|
| 896 |
+
* it will directly write the supplied header values onto the network channel
|
| 897 |
+
* without caching internally, and the `response.getHeader()` on the header
|
| 898 |
+
* will not yield the expected result. If progressive population of headers is
|
| 899 |
+
* desired with potential future retrieval and modification, use `response.setHeader()` instead.
|
| 900 |
+
*
|
| 901 |
+
* ```js
|
| 902 |
+
* // Returns content-type = text/plain
|
| 903 |
+
* const server = http.createServer((req, res) => {
|
| 904 |
+
* res.setHeader('Content-Type', 'text/html');
|
| 905 |
+
* res.setHeader('X-Foo', 'bar');
|
| 906 |
+
* res.writeHead(200, { 'Content-Type': 'text/plain' });
|
| 907 |
+
* res.end('ok');
|
| 908 |
+
* });
|
| 909 |
+
* ```
|
| 910 |
+
*
|
| 911 |
+
* `Content-Length` is read in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js
|
| 912 |
+
* will check whether `Content-Length` and the length of the body which has
|
| 913 |
+
* been transmitted are equal or not.
|
| 914 |
+
*
|
| 915 |
+
* Attempting to set a header field name or value that contains invalid characters
|
| 916 |
+
* will result in a `Error` being thrown.
|
| 917 |
+
* @since v0.1.30
|
| 918 |
+
*/
|
| 919 |
+
writeHead(
|
| 920 |
+
statusCode: number,
|
| 921 |
+
statusMessage?: string,
|
| 922 |
+
headers?: OutgoingHttpHeaders | OutgoingHttpHeader[],
|
| 923 |
+
): this;
|
| 924 |
+
writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
|
| 925 |
+
/**
|
| 926 |
+
* Sends a HTTP/1.1 102 Processing message to the client, indicating that
|
| 927 |
+
* the request body should be sent.
|
| 928 |
+
* @since v10.0.0
|
| 929 |
+
*/
|
| 930 |
+
writeProcessing(callback?: () => void): void;
|
| 931 |
+
}
|
| 932 |
+
interface InformationEvent {
|
| 933 |
+
httpVersion: string;
|
| 934 |
+
httpVersionMajor: number;
|
| 935 |
+
httpVersionMinor: number;
|
| 936 |
+
statusCode: number;
|
| 937 |
+
statusMessage: string;
|
| 938 |
+
headers: IncomingHttpHeaders;
|
| 939 |
+
rawHeaders: string[];
|
| 940 |
+
}
|
| 941 |
+
interface ClientRequestEventMap extends stream.WritableEventMap {
|
| 942 |
+
/** @deprecated Listen for the `'close'` event instead. */
|
| 943 |
+
"abort": [];
|
| 944 |
+
"connect": [response: IncomingMessage, socket: net.Socket, head: NonSharedBuffer];
|
| 945 |
+
"continue": [];
|
| 946 |
+
"information": [info: InformationEvent];
|
| 947 |
+
"response": [response: IncomingMessage];
|
| 948 |
+
"socket": [socket: net.Socket];
|
| 949 |
+
"timeout": [];
|
| 950 |
+
"upgrade": [response: IncomingMessage, socket: net.Socket, head: NonSharedBuffer];
|
| 951 |
+
}
|
| 952 |
+
/**
|
| 953 |
+
* This object is created internally and returned from {@link request}. It
|
| 954 |
+
* represents an _in-progress_ request whose header has already been queued. The
|
| 955 |
+
* header is still mutable using the `setHeader(name, value)`, `getHeader(name)`, `removeHeader(name)` API. The actual header will
|
| 956 |
+
* be sent along with the first data chunk or when calling `request.end()`.
|
| 957 |
+
*
|
| 958 |
+
* To get the response, add a listener for `'response'` to the request object. `'response'` will be emitted from the request object when the response
|
| 959 |
+
* headers have been received. The `'response'` event is executed with one
|
| 960 |
+
* argument which is an instance of {@link IncomingMessage}.
|
| 961 |
+
*
|
| 962 |
+
* During the `'response'` event, one can add listeners to the
|
| 963 |
+
* response object; particularly to listen for the `'data'` event.
|
| 964 |
+
*
|
| 965 |
+
* If no `'response'` handler is added, then the response will be
|
| 966 |
+
* entirely discarded. However, if a `'response'` event handler is added,
|
| 967 |
+
* then the data from the response object **must** be consumed, either by
|
| 968 |
+
* calling `response.read()` whenever there is a `'readable'` event, or
|
| 969 |
+
* by adding a `'data'` handler, or by calling the `.resume()` method.
|
| 970 |
+
* Until the data is consumed, the `'end'` event will not fire. Also, until
|
| 971 |
+
* the data is read it will consume memory that can eventually lead to a
|
| 972 |
+
* 'process out of memory' error.
|
| 973 |
+
*
|
| 974 |
+
* For backward compatibility, `res` will only emit `'error'` if there is an `'error'` listener registered.
|
| 975 |
+
*
|
| 976 |
+
* Set `Content-Length` header to limit the response body size.
|
| 977 |
+
* If `response.strictContentLength` is set to `true`, mismatching the `Content-Length` header value will result in an `Error` being thrown,
|
| 978 |
+
* identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
|
| 979 |
+
*
|
| 980 |
+
* `Content-Length` value should be in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes.
|
| 981 |
+
* @since v0.1.17
|
| 982 |
+
*/
|
| 983 |
+
class ClientRequest extends OutgoingMessage {
|
| 984 |
+
/**
|
| 985 |
+
* The `request.aborted` property will be `true` if the request has
|
| 986 |
+
* been aborted.
|
| 987 |
+
* @since v0.11.14
|
| 988 |
+
* @deprecated Since v17.0.0, v16.12.0 - Check `destroyed` instead.
|
| 989 |
+
*/
|
| 990 |
+
aborted: boolean;
|
| 991 |
+
/**
|
| 992 |
+
* The request host.
|
| 993 |
+
* @since v14.5.0, v12.19.0
|
| 994 |
+
*/
|
| 995 |
+
host: string;
|
| 996 |
+
/**
|
| 997 |
+
* The request protocol.
|
| 998 |
+
* @since v14.5.0, v12.19.0
|
| 999 |
+
*/
|
| 1000 |
+
protocol: string;
|
| 1001 |
+
/**
|
| 1002 |
+
* When sending request through a keep-alive enabled agent, the underlying socket
|
| 1003 |
+
* might be reused. But if server closes connection at unfortunate time, client
|
| 1004 |
+
* may run into a 'ECONNRESET' error.
|
| 1005 |
+
*
|
| 1006 |
+
* ```js
|
| 1007 |
+
* import http from 'node:http';
|
| 1008 |
+
* const agent = new http.Agent({ keepAlive: true });
|
| 1009 |
+
*
|
| 1010 |
+
* // Server has a 5 seconds keep-alive timeout by default
|
| 1011 |
+
* http
|
| 1012 |
+
* .createServer((req, res) => {
|
| 1013 |
+
* res.write('hello\n');
|
| 1014 |
+
* res.end();
|
| 1015 |
+
* })
|
| 1016 |
+
* .listen(3000);
|
| 1017 |
+
*
|
| 1018 |
+
* setInterval(() => {
|
| 1019 |
+
* // Adapting a keep-alive agent
|
| 1020 |
+
* http.get('http://localhost:3000', { agent }, (res) => {
|
| 1021 |
+
* res.on('data', (data) => {
|
| 1022 |
+
* // Do nothing
|
| 1023 |
+
* });
|
| 1024 |
+
* });
|
| 1025 |
+
* }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout
|
| 1026 |
+
* ```
|
| 1027 |
+
*
|
| 1028 |
+
* By marking a request whether it reused socket or not, we can do
|
| 1029 |
+
* automatic error retry base on it.
|
| 1030 |
+
*
|
| 1031 |
+
* ```js
|
| 1032 |
+
* import http from 'node:http';
|
| 1033 |
+
* const agent = new http.Agent({ keepAlive: true });
|
| 1034 |
+
*
|
| 1035 |
+
* function retriableRequest() {
|
| 1036 |
+
* const req = http
|
| 1037 |
+
* .get('http://localhost:3000', { agent }, (res) => {
|
| 1038 |
+
* // ...
|
| 1039 |
+
* })
|
| 1040 |
+
* .on('error', (err) => {
|
| 1041 |
+
* // Check if retry is needed
|
| 1042 |
+
* if (req.reusedSocket && err.code === 'ECONNRESET') {
|
| 1043 |
+
* retriableRequest();
|
| 1044 |
+
* }
|
| 1045 |
+
* });
|
| 1046 |
+
* }
|
| 1047 |
+
*
|
| 1048 |
+
* retriableRequest();
|
| 1049 |
+
* ```
|
| 1050 |
+
* @since v13.0.0, v12.16.0
|
| 1051 |
+
*/
|
| 1052 |
+
reusedSocket: boolean;
|
| 1053 |
+
/**
|
| 1054 |
+
* Limits maximum response headers count. If set to 0, no limit will be applied.
|
| 1055 |
+
*/
|
| 1056 |
+
maxHeadersCount: number;
|
| 1057 |
+
constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);
|
| 1058 |
+
/**
|
| 1059 |
+
* The request method.
|
| 1060 |
+
* @since v0.1.97
|
| 1061 |
+
*/
|
| 1062 |
+
method: string;
|
| 1063 |
+
/**
|
| 1064 |
+
* The request path.
|
| 1065 |
+
* @since v0.4.0
|
| 1066 |
+
*/
|
| 1067 |
+
path: string;
|
| 1068 |
+
/**
|
| 1069 |
+
* Marks the request as aborting. Calling this will cause remaining data
|
| 1070 |
+
* in the response to be dropped and the socket to be destroyed.
|
| 1071 |
+
* @since v0.3.8
|
| 1072 |
+
* @deprecated Since v14.1.0,v13.14.0 - Use `destroy` instead.
|
| 1073 |
+
*/
|
| 1074 |
+
abort(): void;
|
| 1075 |
+
onSocket(socket: net.Socket): void;
|
| 1076 |
+
/**
|
| 1077 |
+
* Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called.
|
| 1078 |
+
* @since v0.5.9
|
| 1079 |
+
* @param timeout Milliseconds before a request times out.
|
| 1080 |
+
* @param callback Optional function to be called when a timeout occurs. Same as binding to the `'timeout'` event.
|
| 1081 |
+
*/
|
| 1082 |
+
setTimeout(timeout: number, callback?: () => void): this;
|
| 1083 |
+
/**
|
| 1084 |
+
* Once a socket is assigned to this request and is connected `socket.setNoDelay()` will be called.
|
| 1085 |
+
* @since v0.5.9
|
| 1086 |
+
*/
|
| 1087 |
+
setNoDelay(noDelay?: boolean): void;
|
| 1088 |
+
/**
|
| 1089 |
+
* Once a socket is assigned to this request and is connected `socket.setKeepAlive()` will be called.
|
| 1090 |
+
* @since v0.5.9
|
| 1091 |
+
*/
|
| 1092 |
+
setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
|
| 1093 |
+
/**
|
| 1094 |
+
* Returns an array containing the unique names of the current outgoing raw
|
| 1095 |
+
* headers. Header names are returned with their exact casing being set.
|
| 1096 |
+
*
|
| 1097 |
+
* ```js
|
| 1098 |
+
* request.setHeader('Foo', 'bar');
|
| 1099 |
+
* request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
| 1100 |
+
*
|
| 1101 |
+
* const headerNames = request.getRawHeaderNames();
|
| 1102 |
+
* // headerNames === ['Foo', 'Set-Cookie']
|
| 1103 |
+
* ```
|
| 1104 |
+
* @since v15.13.0, v14.17.0
|
| 1105 |
+
*/
|
| 1106 |
+
getRawHeaderNames(): string[];
|
| 1107 |
+
// #region InternalEventEmitter
|
| 1108 |
+
addListener<E extends keyof ClientRequestEventMap>(
|
| 1109 |
+
eventName: E,
|
| 1110 |
+
listener: (...args: ClientRequestEventMap[E]) => void,
|
| 1111 |
+
): this;
|
| 1112 |
+
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1113 |
+
emit<E extends keyof ClientRequestEventMap>(eventName: E, ...args: ClientRequestEventMap[E]): boolean;
|
| 1114 |
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
| 1115 |
+
listenerCount<E extends keyof ClientRequestEventMap>(
|
| 1116 |
+
eventName: E,
|
| 1117 |
+
listener?: (...args: ClientRequestEventMap[E]) => void,
|
| 1118 |
+
): number;
|
| 1119 |
+
listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
|
| 1120 |
+
listeners<E extends keyof ClientRequestEventMap>(eventName: E): ((...args: ClientRequestEventMap[E]) => void)[];
|
| 1121 |
+
listeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 1122 |
+
off<E extends keyof ClientRequestEventMap>(
|
| 1123 |
+
eventName: E,
|
| 1124 |
+
listener: (...args: ClientRequestEventMap[E]) => void,
|
| 1125 |
+
): this;
|
| 1126 |
+
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1127 |
+
on<E extends keyof ClientRequestEventMap>(
|
| 1128 |
+
eventName: E,
|
| 1129 |
+
listener: (...args: ClientRequestEventMap[E]) => void,
|
| 1130 |
+
): this;
|
| 1131 |
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1132 |
+
once<E extends keyof ClientRequestEventMap>(
|
| 1133 |
+
eventName: E,
|
| 1134 |
+
listener: (...args: ClientRequestEventMap[E]) => void,
|
| 1135 |
+
): this;
|
| 1136 |
+
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1137 |
+
prependListener<E extends keyof ClientRequestEventMap>(
|
| 1138 |
+
eventName: E,
|
| 1139 |
+
listener: (...args: ClientRequestEventMap[E]) => void,
|
| 1140 |
+
): this;
|
| 1141 |
+
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1142 |
+
prependOnceListener<E extends keyof ClientRequestEventMap>(
|
| 1143 |
+
eventName: E,
|
| 1144 |
+
listener: (...args: ClientRequestEventMap[E]) => void,
|
| 1145 |
+
): this;
|
| 1146 |
+
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1147 |
+
rawListeners<E extends keyof ClientRequestEventMap>(
|
| 1148 |
+
eventName: E,
|
| 1149 |
+
): ((...args: ClientRequestEventMap[E]) => void)[];
|
| 1150 |
+
rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 1151 |
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
| 1152 |
+
removeAllListeners<E extends keyof ClientRequestEventMap>(eventName?: E): this;
|
| 1153 |
+
removeAllListeners(eventName?: string | symbol): this;
|
| 1154 |
+
removeListener<E extends keyof ClientRequestEventMap>(
|
| 1155 |
+
eventName: E,
|
| 1156 |
+
listener: (...args: ClientRequestEventMap[E]) => void,
|
| 1157 |
+
): this;
|
| 1158 |
+
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1159 |
+
// #endregion
|
| 1160 |
+
}
|
| 1161 |
+
interface IncomingMessageEventMap extends stream.ReadableEventMap {
|
| 1162 |
+
/** @deprecated Listen for `'close'` event instead. */
|
| 1163 |
+
"aborted": [];
|
| 1164 |
+
}
|
| 1165 |
+
/**
|
| 1166 |
+
* 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
|
| 1167 |
+
* access response
|
| 1168 |
+
* status, headers, and data.
|
| 1169 |
+
*
|
| 1170 |
+
* Different from its `socket` value which is a subclass of `stream.Duplex`, the `IncomingMessage` itself extends `stream.Readable` and is created separately to
|
| 1171 |
+
* parse and emit the incoming HTTP headers and payload, as the underlying socket
|
| 1172 |
+
* may be reused multiple times in case of keep-alive.
|
| 1173 |
+
* @since v0.1.17
|
| 1174 |
+
*/
|
| 1175 |
+
class IncomingMessage extends stream.Readable {
|
| 1176 |
+
constructor(socket: net.Socket);
|
| 1177 |
+
/**
|
| 1178 |
+
* The `message.aborted` property will be `true` if the request has
|
| 1179 |
+
* been aborted.
|
| 1180 |
+
* @since v10.1.0
|
| 1181 |
+
* @deprecated Since v17.0.0,v16.12.0 - Check `message.destroyed` from <a href="stream.html#class-streamreadable" class="type">stream.Readable</a>.
|
| 1182 |
+
*/
|
| 1183 |
+
aborted: boolean;
|
| 1184 |
+
/**
|
| 1185 |
+
* In case of server request, the HTTP version sent by the client. In the case of
|
| 1186 |
+
* client response, the HTTP version of the connected-to server.
|
| 1187 |
+
* Probably either `'1.1'` or `'1.0'`.
|
| 1188 |
+
*
|
| 1189 |
+
* Also `message.httpVersionMajor` is the first integer and `message.httpVersionMinor` is the second.
|
| 1190 |
+
* @since v0.1.1
|
| 1191 |
+
*/
|
| 1192 |
+
httpVersion: string;
|
| 1193 |
+
httpVersionMajor: number;
|
| 1194 |
+
httpVersionMinor: number;
|
| 1195 |
+
/**
|
| 1196 |
+
* The `message.complete` property will be `true` if a complete HTTP message has
|
| 1197 |
+
* been received and successfully parsed.
|
| 1198 |
+
*
|
| 1199 |
+
* This property is particularly useful as a means of determining if a client or
|
| 1200 |
+
* server fully transmitted a message before a connection was terminated:
|
| 1201 |
+
*
|
| 1202 |
+
* ```js
|
| 1203 |
+
* const req = http.request({
|
| 1204 |
+
* host: '127.0.0.1',
|
| 1205 |
+
* port: 8080,
|
| 1206 |
+
* method: 'POST',
|
| 1207 |
+
* }, (res) => {
|
| 1208 |
+
* res.resume();
|
| 1209 |
+
* res.on('end', () => {
|
| 1210 |
+
* if (!res.complete)
|
| 1211 |
+
* console.error(
|
| 1212 |
+
* 'The connection was terminated while the message was still being sent');
|
| 1213 |
+
* });
|
| 1214 |
+
* });
|
| 1215 |
+
* ```
|
| 1216 |
+
* @since v0.3.0
|
| 1217 |
+
*/
|
| 1218 |
+
complete: boolean;
|
| 1219 |
+
/**
|
| 1220 |
+
* Alias for `message.socket`.
|
| 1221 |
+
* @since v0.1.90
|
| 1222 |
+
* @deprecated Since v16.0.0 - Use `socket`.
|
| 1223 |
+
*/
|
| 1224 |
+
connection: net.Socket;
|
| 1225 |
+
/**
|
| 1226 |
+
* The `net.Socket` object associated with the connection.
|
| 1227 |
+
*
|
| 1228 |
+
* With HTTPS support, use `request.socket.getPeerCertificate()` to obtain the
|
| 1229 |
+
* client's authentication details.
|
| 1230 |
+
*
|
| 1231 |
+
* This property is guaranteed to be an instance of the `net.Socket` class,
|
| 1232 |
+
* a subclass of `stream.Duplex`, unless the user specified a socket
|
| 1233 |
+
* type other than `net.Socket` or internally nulled.
|
| 1234 |
+
* @since v0.3.0
|
| 1235 |
+
*/
|
| 1236 |
+
socket: net.Socket;
|
| 1237 |
+
/**
|
| 1238 |
+
* The request/response headers object.
|
| 1239 |
+
*
|
| 1240 |
+
* Key-value pairs of header names and values. Header names are lower-cased.
|
| 1241 |
+
*
|
| 1242 |
+
* ```js
|
| 1243 |
+
* // Prints something like:
|
| 1244 |
+
* //
|
| 1245 |
+
* // { 'user-agent': 'curl/7.22.0',
|
| 1246 |
+
* // host: '127.0.0.1:8000',
|
| 1247 |
+
* // accept: '*' }
|
| 1248 |
+
* console.log(request.headers);
|
| 1249 |
+
* ```
|
| 1250 |
+
*
|
| 1251 |
+
* Duplicates in raw headers are handled in the following ways, depending on the
|
| 1252 |
+
* header name:
|
| 1253 |
+
*
|
| 1254 |
+
* * Duplicates of `age`, `authorization`, `content-length`, `content-type`, `etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`, `last-modified`, `location`,
|
| 1255 |
+
* `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, `server`, or `user-agent` are discarded.
|
| 1256 |
+
* To allow duplicate values of the headers listed above to be joined,
|
| 1257 |
+
* use the option `joinDuplicateHeaders` in {@link request} and {@link createServer}. See RFC 9110 Section 5.3 for more
|
| 1258 |
+
* information.
|
| 1259 |
+
* * `set-cookie` is always an array. Duplicates are added to the array.
|
| 1260 |
+
* * For duplicate `cookie` headers, the values are joined together with `; `.
|
| 1261 |
+
* * For all other headers, the values are joined together with `, `.
|
| 1262 |
+
* @since v0.1.5
|
| 1263 |
+
*/
|
| 1264 |
+
headers: IncomingHttpHeaders;
|
| 1265 |
+
/**
|
| 1266 |
+
* Similar to `message.headers`, but there is no join logic and the values are
|
| 1267 |
+
* always arrays of strings, even for headers received just once.
|
| 1268 |
+
*
|
| 1269 |
+
* ```js
|
| 1270 |
+
* // Prints something like:
|
| 1271 |
+
* //
|
| 1272 |
+
* // { 'user-agent': ['curl/7.22.0'],
|
| 1273 |
+
* // host: ['127.0.0.1:8000'],
|
| 1274 |
+
* // accept: ['*'] }
|
| 1275 |
+
* console.log(request.headersDistinct);
|
| 1276 |
+
* ```
|
| 1277 |
+
* @since v18.3.0, v16.17.0
|
| 1278 |
+
*/
|
| 1279 |
+
headersDistinct: NodeJS.Dict<string[]>;
|
| 1280 |
+
/**
|
| 1281 |
+
* The raw request/response headers list exactly as they were received.
|
| 1282 |
+
*
|
| 1283 |
+
* The keys and values are in the same list. It is _not_ a
|
| 1284 |
+
* list of tuples. So, the even-numbered offsets are key values, and the
|
| 1285 |
+
* odd-numbered offsets are the associated values.
|
| 1286 |
+
*
|
| 1287 |
+
* Header names are not lowercased, and duplicates are not merged.
|
| 1288 |
+
*
|
| 1289 |
+
* ```js
|
| 1290 |
+
* // Prints something like:
|
| 1291 |
+
* //
|
| 1292 |
+
* // [ 'user-agent',
|
| 1293 |
+
* // 'this is invalid because there can be only one',
|
| 1294 |
+
* // 'User-Agent',
|
| 1295 |
+
* // 'curl/7.22.0',
|
| 1296 |
+
* // 'Host',
|
| 1297 |
+
* // '127.0.0.1:8000',
|
| 1298 |
+
* // 'ACCEPT',
|
| 1299 |
+
* // '*' ]
|
| 1300 |
+
* console.log(request.rawHeaders);
|
| 1301 |
+
* ```
|
| 1302 |
+
* @since v0.11.6
|
| 1303 |
+
*/
|
| 1304 |
+
rawHeaders: string[];
|
| 1305 |
+
/**
|
| 1306 |
+
* The request/response trailers object. Only populated at the `'end'` event.
|
| 1307 |
+
* @since v0.3.0
|
| 1308 |
+
*/
|
| 1309 |
+
trailers: NodeJS.Dict<string>;
|
| 1310 |
+
/**
|
| 1311 |
+
* Similar to `message.trailers`, but there is no join logic and the values are
|
| 1312 |
+
* always arrays of strings, even for headers received just once.
|
| 1313 |
+
* Only populated at the `'end'` event.
|
| 1314 |
+
* @since v18.3.0, v16.17.0
|
| 1315 |
+
*/
|
| 1316 |
+
trailersDistinct: NodeJS.Dict<string[]>;
|
| 1317 |
+
/**
|
| 1318 |
+
* The raw request/response trailer keys and values exactly as they were
|
| 1319 |
+
* received. Only populated at the `'end'` event.
|
| 1320 |
+
* @since v0.11.6
|
| 1321 |
+
*/
|
| 1322 |
+
rawTrailers: string[];
|
| 1323 |
+
/**
|
| 1324 |
+
* Calls `message.socket.setTimeout(msecs, callback)`.
|
| 1325 |
+
* @since v0.5.9
|
| 1326 |
+
*/
|
| 1327 |
+
setTimeout(msecs: number, callback?: () => void): this;
|
| 1328 |
+
/**
|
| 1329 |
+
* **Only valid for request obtained from {@link Server}.**
|
| 1330 |
+
*
|
| 1331 |
+
* The request method as a string. Read only. Examples: `'GET'`, `'DELETE'`.
|
| 1332 |
+
* @since v0.1.1
|
| 1333 |
+
*/
|
| 1334 |
+
method?: string | undefined;
|
| 1335 |
+
/**
|
| 1336 |
+
* **Only valid for request obtained from {@link Server}.**
|
| 1337 |
+
*
|
| 1338 |
+
* Request URL string. This contains only the URL that is present in the actual
|
| 1339 |
+
* HTTP request. Take the following request:
|
| 1340 |
+
*
|
| 1341 |
+
* ```http
|
| 1342 |
+
* GET /status?name=ryan HTTP/1.1
|
| 1343 |
+
* Accept: text/plain
|
| 1344 |
+
* ```
|
| 1345 |
+
*
|
| 1346 |
+
* To parse the URL into its parts:
|
| 1347 |
+
*
|
| 1348 |
+
* ```js
|
| 1349 |
+
* new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);
|
| 1350 |
+
* ```
|
| 1351 |
+
*
|
| 1352 |
+
* When `request.url` is `'/status?name=ryan'` and `process.env.HOST` is undefined:
|
| 1353 |
+
*
|
| 1354 |
+
* ```console
|
| 1355 |
+
* $ node
|
| 1356 |
+
* > new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);
|
| 1357 |
+
* URL {
|
| 1358 |
+
* href: 'http://localhost/status?name=ryan',
|
| 1359 |
+
* origin: 'http://localhost',
|
| 1360 |
+
* protocol: 'http:',
|
| 1361 |
+
* username: '',
|
| 1362 |
+
* password: '',
|
| 1363 |
+
* host: 'localhost',
|
| 1364 |
+
* hostname: 'localhost',
|
| 1365 |
+
* port: '',
|
| 1366 |
+
* pathname: '/status',
|
| 1367 |
+
* search: '?name=ryan',
|
| 1368 |
+
* searchParams: URLSearchParams { 'name' => 'ryan' },
|
| 1369 |
+
* hash: ''
|
| 1370 |
+
* }
|
| 1371 |
+
* ```
|
| 1372 |
+
*
|
| 1373 |
+
* 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
|
| 1374 |
+
* validation is used, as clients may specify a custom `Host` header.
|
| 1375 |
+
* @since v0.1.90
|
| 1376 |
+
*/
|
| 1377 |
+
url?: string | undefined;
|
| 1378 |
+
/**
|
| 1379 |
+
* **Only valid for response obtained from {@link ClientRequest}.**
|
| 1380 |
+
*
|
| 1381 |
+
* The 3-digit HTTP response status code. E.G. `404`.
|
| 1382 |
+
* @since v0.1.1
|
| 1383 |
+
*/
|
| 1384 |
+
statusCode?: number | undefined;
|
| 1385 |
+
/**
|
| 1386 |
+
* **Only valid for response obtained from {@link ClientRequest}.**
|
| 1387 |
+
*
|
| 1388 |
+
* The HTTP response status message (reason phrase). E.G. `OK` or `Internal Server Error`.
|
| 1389 |
+
* @since v0.11.10
|
| 1390 |
+
*/
|
| 1391 |
+
statusMessage?: string | undefined;
|
| 1392 |
+
/**
|
| 1393 |
+
* 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
|
| 1394 |
+
* as an argument to any listeners on the event.
|
| 1395 |
+
* @since v0.3.0
|
| 1396 |
+
*/
|
| 1397 |
+
destroy(error?: Error): this;
|
| 1398 |
+
// #region InternalEventEmitter
|
| 1399 |
+
addListener<E extends keyof IncomingMessageEventMap>(
|
| 1400 |
+
eventName: E,
|
| 1401 |
+
listener: (...args: IncomingMessageEventMap[E]) => void,
|
| 1402 |
+
): this;
|
| 1403 |
+
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1404 |
+
emit<E extends keyof IncomingMessageEventMap>(eventName: E, ...args: IncomingMessageEventMap[E]): boolean;
|
| 1405 |
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
| 1406 |
+
listenerCount<E extends keyof IncomingMessageEventMap>(
|
| 1407 |
+
eventName: E,
|
| 1408 |
+
listener?: (...args: IncomingMessageEventMap[E]) => void,
|
| 1409 |
+
): number;
|
| 1410 |
+
listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
|
| 1411 |
+
listeners<E extends keyof IncomingMessageEventMap>(
|
| 1412 |
+
eventName: E,
|
| 1413 |
+
): ((...args: IncomingMessageEventMap[E]) => void)[];
|
| 1414 |
+
listeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 1415 |
+
off<E extends keyof IncomingMessageEventMap>(
|
| 1416 |
+
eventName: E,
|
| 1417 |
+
listener: (...args: IncomingMessageEventMap[E]) => void,
|
| 1418 |
+
): this;
|
| 1419 |
+
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1420 |
+
on<E extends keyof IncomingMessageEventMap>(
|
| 1421 |
+
eventName: E,
|
| 1422 |
+
listener: (...args: IncomingMessageEventMap[E]) => void,
|
| 1423 |
+
): this;
|
| 1424 |
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1425 |
+
once<E extends keyof IncomingMessageEventMap>(
|
| 1426 |
+
eventName: E,
|
| 1427 |
+
listener: (...args: IncomingMessageEventMap[E]) => void,
|
| 1428 |
+
): this;
|
| 1429 |
+
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1430 |
+
prependListener<E extends keyof IncomingMessageEventMap>(
|
| 1431 |
+
eventName: E,
|
| 1432 |
+
listener: (...args: IncomingMessageEventMap[E]) => void,
|
| 1433 |
+
): this;
|
| 1434 |
+
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1435 |
+
prependOnceListener<E extends keyof IncomingMessageEventMap>(
|
| 1436 |
+
eventName: E,
|
| 1437 |
+
listener: (...args: IncomingMessageEventMap[E]) => void,
|
| 1438 |
+
): this;
|
| 1439 |
+
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1440 |
+
rawListeners<E extends keyof IncomingMessageEventMap>(
|
| 1441 |
+
eventName: E,
|
| 1442 |
+
): ((...args: IncomingMessageEventMap[E]) => void)[];
|
| 1443 |
+
rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 1444 |
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
| 1445 |
+
removeAllListeners<E extends keyof IncomingMessageEventMap>(eventName?: E): this;
|
| 1446 |
+
removeAllListeners(eventName?: string | symbol): this;
|
| 1447 |
+
removeListener<E extends keyof IncomingMessageEventMap>(
|
| 1448 |
+
eventName: E,
|
| 1449 |
+
listener: (...args: IncomingMessageEventMap[E]) => void,
|
| 1450 |
+
): this;
|
| 1451 |
+
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 1452 |
+
// #endregion
|
| 1453 |
+
}
|
| 1454 |
+
interface ProxyEnv extends NodeJS.ProcessEnv {
|
| 1455 |
+
HTTP_PROXY?: string | undefined;
|
| 1456 |
+
HTTPS_PROXY?: string | undefined;
|
| 1457 |
+
NO_PROXY?: string | undefined;
|
| 1458 |
+
http_proxy?: string | undefined;
|
| 1459 |
+
https_proxy?: string | undefined;
|
| 1460 |
+
no_proxy?: string | undefined;
|
| 1461 |
+
}
|
| 1462 |
+
interface AgentOptions extends NodeJS.PartialOptions<net.TcpSocketConnectOpts> {
|
| 1463 |
+
/**
|
| 1464 |
+
* Keep sockets around in a pool to be used by other requests in the future. Default = false
|
| 1465 |
+
*/
|
| 1466 |
+
keepAlive?: boolean | undefined;
|
| 1467 |
+
/**
|
| 1468 |
+
* When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
|
| 1469 |
+
* Only relevant if keepAlive is set to true.
|
| 1470 |
+
*/
|
| 1471 |
+
keepAliveMsecs?: number | undefined;
|
| 1472 |
+
/**
|
| 1473 |
+
* Milliseconds to subtract from
|
| 1474 |
+
* the server-provided `keep-alive: timeout=...` hint when determining socket
|
| 1475 |
+
* expiration time. This buffer helps ensure the agent closes the socket
|
| 1476 |
+
* slightly before the server does, reducing the chance of sending a request
|
| 1477 |
+
* on a socket that’s about to be closed by the server.
|
| 1478 |
+
* @since v24.7.0
|
| 1479 |
+
* @default 1000
|
| 1480 |
+
*/
|
| 1481 |
+
agentKeepAliveTimeoutBuffer?: number | undefined;
|
| 1482 |
+
/**
|
| 1483 |
+
* Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
|
| 1484 |
+
*/
|
| 1485 |
+
maxSockets?: number | undefined;
|
| 1486 |
+
/**
|
| 1487 |
+
* Maximum number of sockets allowed for all hosts in total. Each request will use a new socket until the maximum is reached. Default: Infinity.
|
| 1488 |
+
*/
|
| 1489 |
+
maxTotalSockets?: number | undefined;
|
| 1490 |
+
/**
|
| 1491 |
+
* Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
|
| 1492 |
+
*/
|
| 1493 |
+
maxFreeSockets?: number | undefined;
|
| 1494 |
+
/**
|
| 1495 |
+
* Socket timeout in milliseconds. This will set the timeout after the socket is connected.
|
| 1496 |
+
*/
|
| 1497 |
+
timeout?: number | undefined;
|
| 1498 |
+
/**
|
| 1499 |
+
* Scheduling strategy to apply when picking the next free socket to use.
|
| 1500 |
+
* @default `lifo`
|
| 1501 |
+
*/
|
| 1502 |
+
scheduling?: "fifo" | "lifo" | undefined;
|
| 1503 |
+
/**
|
| 1504 |
+
* Environment variables for proxy configuration. See
|
| 1505 |
+
* [Built-in Proxy Support](https://nodejs.org/docs/latest-v25.x/api/http.html#built-in-proxy-support) for details.
|
| 1506 |
+
* @since v24.5.0
|
| 1507 |
+
*/
|
| 1508 |
+
proxyEnv?: ProxyEnv | undefined;
|
| 1509 |
+
/**
|
| 1510 |
+
* Default port to use when the port is not specified in requests.
|
| 1511 |
+
* @since v24.5.0
|
| 1512 |
+
*/
|
| 1513 |
+
defaultPort?: number | undefined;
|
| 1514 |
+
/**
|
| 1515 |
+
* The protocol to use for the agent.
|
| 1516 |
+
* @since v24.5.0
|
| 1517 |
+
*/
|
| 1518 |
+
protocol?: string | undefined;
|
| 1519 |
+
}
|
| 1520 |
+
/**
|
| 1521 |
+
* An `Agent` is responsible for managing connection persistence
|
| 1522 |
+
* and reuse for HTTP clients. It maintains a queue of pending requests
|
| 1523 |
+
* for a given host and port, reusing a single socket connection for each
|
| 1524 |
+
* until the queue is empty, at which time the socket is either destroyed
|
| 1525 |
+
* or put into a pool where it is kept to be used again for requests to the
|
| 1526 |
+
* same host and port. Whether it is destroyed or pooled depends on the `keepAlive` `option`.
|
| 1527 |
+
*
|
| 1528 |
+
* Pooled connections have TCP Keep-Alive enabled for them, but servers may
|
| 1529 |
+
* still close idle connections, in which case they will be removed from the
|
| 1530 |
+
* pool and a new connection will be made when a new HTTP request is made for
|
| 1531 |
+
* that host and port. Servers may also refuse to allow multiple requests
|
| 1532 |
+
* over the same connection, in which case the connection will have to be
|
| 1533 |
+
* remade for every request and cannot be pooled. The `Agent` will still make
|
| 1534 |
+
* the requests to that server, but each one will occur over a new connection.
|
| 1535 |
+
*
|
| 1536 |
+
* When a connection is closed by the client or the server, it is removed
|
| 1537 |
+
* from the pool. Any unused sockets in the pool will be unrefed so as not
|
| 1538 |
+
* to keep the Node.js process running when there are no outstanding requests.
|
| 1539 |
+
* (see `socket.unref()`).
|
| 1540 |
+
*
|
| 1541 |
+
* It is good practice, to `destroy()` an `Agent` instance when it is no
|
| 1542 |
+
* longer in use, because unused sockets consume OS resources.
|
| 1543 |
+
*
|
| 1544 |
+
* Sockets are removed from an agent when the socket emits either
|
| 1545 |
+
* a `'close'` event or an `'agentRemove'` event. When intending to keep one
|
| 1546 |
+
* HTTP request open for a long time without keeping it in the agent, something
|
| 1547 |
+
* like the following may be done:
|
| 1548 |
+
*
|
| 1549 |
+
* ```js
|
| 1550 |
+
* http.get(options, (res) => {
|
| 1551 |
+
* // Do stuff
|
| 1552 |
+
* }).on('socket', (socket) => {
|
| 1553 |
+
* socket.emit('agentRemove');
|
| 1554 |
+
* });
|
| 1555 |
+
* ```
|
| 1556 |
+
*
|
| 1557 |
+
* 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
|
| 1558 |
+
* will be used
|
| 1559 |
+
* for the client connection.
|
| 1560 |
+
*
|
| 1561 |
+
* `agent:false`:
|
| 1562 |
+
*
|
| 1563 |
+
* ```js
|
| 1564 |
+
* http.get({
|
| 1565 |
+
* hostname: 'localhost',
|
| 1566 |
+
* port: 80,
|
| 1567 |
+
* path: '/',
|
| 1568 |
+
* agent: false, // Create a new agent just for this one request
|
| 1569 |
+
* }, (res) => {
|
| 1570 |
+
* // Do stuff with response
|
| 1571 |
+
* });
|
| 1572 |
+
* ```
|
| 1573 |
+
*
|
| 1574 |
+
* `options` in [`socket.connect()`](https://nodejs.org/docs/latest-v25.x/api/net.html#socketconnectoptions-connectlistener) are also supported.
|
| 1575 |
+
*
|
| 1576 |
+
* To configure any of them, a custom {@link Agent} instance must be created.
|
| 1577 |
+
*
|
| 1578 |
+
* ```js
|
| 1579 |
+
* import http from 'node:http';
|
| 1580 |
+
* const keepAliveAgent = new http.Agent({ keepAlive: true });
|
| 1581 |
+
* options.agent = keepAliveAgent;
|
| 1582 |
+
* http.request(options, onResponseCallback)
|
| 1583 |
+
* ```
|
| 1584 |
+
* @since v0.3.4
|
| 1585 |
+
*/
|
| 1586 |
+
class Agent extends EventEmitter {
|
| 1587 |
+
/**
|
| 1588 |
+
* By default set to 256. For agents with `keepAlive` enabled, this
|
| 1589 |
+
* sets the maximum number of sockets that will be left open in the free
|
| 1590 |
+
* state.
|
| 1591 |
+
* @since v0.11.7
|
| 1592 |
+
*/
|
| 1593 |
+
maxFreeSockets: number;
|
| 1594 |
+
/**
|
| 1595 |
+
* By default set to `Infinity`. Determines how many concurrent sockets the agent
|
| 1596 |
+
* can have open per origin. Origin is the returned value of `agent.getName()`.
|
| 1597 |
+
* @since v0.3.6
|
| 1598 |
+
*/
|
| 1599 |
+
maxSockets: number;
|
| 1600 |
+
/**
|
| 1601 |
+
* By default set to `Infinity`. Determines how many concurrent sockets the agent
|
| 1602 |
+
* can have open. Unlike `maxSockets`, this parameter applies across all origins.
|
| 1603 |
+
* @since v14.5.0, v12.19.0
|
| 1604 |
+
*/
|
| 1605 |
+
maxTotalSockets: number;
|
| 1606 |
+
/**
|
| 1607 |
+
* An object which contains arrays of sockets currently awaiting use by
|
| 1608 |
+
* the agent when `keepAlive` is enabled. Do not modify.
|
| 1609 |
+
*
|
| 1610 |
+
* Sockets in the `freeSockets` list will be automatically destroyed and
|
| 1611 |
+
* removed from the array on `'timeout'`.
|
| 1612 |
+
* @since v0.11.4
|
| 1613 |
+
*/
|
| 1614 |
+
readonly freeSockets: NodeJS.ReadOnlyDict<net.Socket[]>;
|
| 1615 |
+
/**
|
| 1616 |
+
* An object which contains arrays of sockets currently in use by the
|
| 1617 |
+
* agent. Do not modify.
|
| 1618 |
+
* @since v0.3.6
|
| 1619 |
+
*/
|
| 1620 |
+
readonly sockets: NodeJS.ReadOnlyDict<net.Socket[]>;
|
| 1621 |
+
/**
|
| 1622 |
+
* An object which contains queues of requests that have not yet been assigned to
|
| 1623 |
+
* sockets. Do not modify.
|
| 1624 |
+
* @since v0.5.9
|
| 1625 |
+
*/
|
| 1626 |
+
readonly requests: NodeJS.ReadOnlyDict<ClientRequest[]>;
|
| 1627 |
+
constructor(opts?: AgentOptions);
|
| 1628 |
+
/**
|
| 1629 |
+
* Destroy any sockets that are currently in use by the agent.
|
| 1630 |
+
*
|
| 1631 |
+
* It is usually not necessary to do this. However, if using an
|
| 1632 |
+
* agent with `keepAlive` enabled, then it is best to explicitly shut down
|
| 1633 |
+
* the agent when it is no longer needed. Otherwise,
|
| 1634 |
+
* sockets might stay open for quite a long time before the server
|
| 1635 |
+
* terminates them.
|
| 1636 |
+
* @since v0.11.4
|
| 1637 |
+
*/
|
| 1638 |
+
destroy(): void;
|
| 1639 |
+
/**
|
| 1640 |
+
* Produces a socket/stream to be used for HTTP requests.
|
| 1641 |
+
*
|
| 1642 |
+
* By default, this function behaves identically to `net.createConnection()`,
|
| 1643 |
+
* synchronously returning the created socket. The optional `callback` parameter in the
|
| 1644 |
+
* signature is **not** used by this default implementation.
|
| 1645 |
+
*
|
| 1646 |
+
* However, custom agents may override this method to provide greater flexibility,
|
| 1647 |
+
* for example, to create sockets asynchronously. When overriding `createConnection`:
|
| 1648 |
+
*
|
| 1649 |
+
* 1. **Synchronous socket creation**: The overriding method can return the
|
| 1650 |
+
* socket/stream directly.
|
| 1651 |
+
* 2. **Asynchronous socket creation**: The overriding method can accept the `callback`
|
| 1652 |
+
* and pass the created socket/stream to it (e.g., `callback(null, newSocket)`).
|
| 1653 |
+
* If an error occurs during socket creation, it should be passed as the first
|
| 1654 |
+
* argument to the `callback` (e.g., `callback(err)`).
|
| 1655 |
+
*
|
| 1656 |
+
* The agent will call the provided `createConnection` function with `options` and
|
| 1657 |
+
* this internal `callback`. The `callback` provided by the agent has a signature
|
| 1658 |
+
* of `(err, stream)`.
|
| 1659 |
+
* @since v0.11.4
|
| 1660 |
+
* @param options Options containing connection details. Check
|
| 1661 |
+
* `net.createConnection` for the format of the options. For custom agents,
|
| 1662 |
+
* this object is passed to the custom `createConnection` function.
|
| 1663 |
+
* @param callback (Optional, primarily for custom agents) A function to be
|
| 1664 |
+
* called by a custom `createConnection` implementation when the socket is
|
| 1665 |
+
* created, especially for asynchronous operations.
|
| 1666 |
+
* @returns The created socket. This is returned by the default
|
| 1667 |
+
* implementation or by a custom synchronous `createConnection` implementation.
|
| 1668 |
+
* If a custom `createConnection` uses the `callback` for asynchronous
|
| 1669 |
+
* operation, this return value might not be the primary way to obtain the socket.
|
| 1670 |
+
*/
|
| 1671 |
+
createConnection(
|
| 1672 |
+
options: ClientRequestArgs,
|
| 1673 |
+
callback?: (err: Error | null, stream: stream.Duplex) => void,
|
| 1674 |
+
): stream.Duplex | null | undefined;
|
| 1675 |
+
/**
|
| 1676 |
+
* Called when `socket` is detached from a request and could be persisted by the`Agent`. Default behavior is to:
|
| 1677 |
+
*
|
| 1678 |
+
* ```js
|
| 1679 |
+
* socket.setKeepAlive(true, this.keepAliveMsecs);
|
| 1680 |
+
* socket.unref();
|
| 1681 |
+
* return true;
|
| 1682 |
+
* ```
|
| 1683 |
+
*
|
| 1684 |
+
* This method can be overridden by a particular `Agent` subclass. If this
|
| 1685 |
+
* method returns a falsy value, the socket will be destroyed instead of persisting
|
| 1686 |
+
* it for use with the next request.
|
| 1687 |
+
*
|
| 1688 |
+
* The `socket` argument can be an instance of `net.Socket`, a subclass of `stream.Duplex`.
|
| 1689 |
+
* @since v8.1.0
|
| 1690 |
+
*/
|
| 1691 |
+
keepSocketAlive(socket: stream.Duplex): void;
|
| 1692 |
+
/**
|
| 1693 |
+
* Called when `socket` is attached to `request` after being persisted because of
|
| 1694 |
+
* the keep-alive options. Default behavior is to:
|
| 1695 |
+
*
|
| 1696 |
+
* ```js
|
| 1697 |
+
* socket.ref();
|
| 1698 |
+
* ```
|
| 1699 |
+
*
|
| 1700 |
+
* This method can be overridden by a particular `Agent` subclass.
|
| 1701 |
+
*
|
| 1702 |
+
* The `socket` argument can be an instance of `net.Socket`, a subclass of `stream.Duplex`.
|
| 1703 |
+
* @since v8.1.0
|
| 1704 |
+
*/
|
| 1705 |
+
reuseSocket(socket: stream.Duplex, request: ClientRequest): void;
|
| 1706 |
+
/**
|
| 1707 |
+
* Get a unique name for a set of request options, to determine whether a
|
| 1708 |
+
* connection can be reused. For an HTTP agent, this returns`host:port:localAddress` or `host:port:localAddress:family`. For an HTTPS agent,
|
| 1709 |
+
* the name includes the CA, cert, ciphers, and other HTTPS/TLS-specific options
|
| 1710 |
+
* that determine socket reusability.
|
| 1711 |
+
* @since v0.11.4
|
| 1712 |
+
* @param options A set of options providing information for name generation
|
| 1713 |
+
*/
|
| 1714 |
+
getName(options?: ClientRequestArgs): string;
|
| 1715 |
+
}
|
| 1716 |
+
const METHODS: string[];
|
| 1717 |
+
const STATUS_CODES: {
|
| 1718 |
+
[errorCode: number]: string | undefined;
|
| 1719 |
+
[errorCode: string]: string | undefined;
|
| 1720 |
+
};
|
| 1721 |
+
/**
|
| 1722 |
+
* Returns a new instance of {@link Server}.
|
| 1723 |
+
*
|
| 1724 |
+
* The `requestListener` is a function which is automatically
|
| 1725 |
+
* added to the `'request'` event.
|
| 1726 |
+
*
|
| 1727 |
+
* ```js
|
| 1728 |
+
* import http from 'node:http';
|
| 1729 |
+
*
|
| 1730 |
+
* // Create a local server to receive data from
|
| 1731 |
+
* const server = http.createServer((req, res) => {
|
| 1732 |
+
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 1733 |
+
* res.end(JSON.stringify({
|
| 1734 |
+
* data: 'Hello World!',
|
| 1735 |
+
* }));
|
| 1736 |
+
* });
|
| 1737 |
+
*
|
| 1738 |
+
* server.listen(8000);
|
| 1739 |
+
* ```
|
| 1740 |
+
*
|
| 1741 |
+
* ```js
|
| 1742 |
+
* import http from 'node:http';
|
| 1743 |
+
*
|
| 1744 |
+
* // Create a local server to receive data from
|
| 1745 |
+
* const server = http.createServer();
|
| 1746 |
+
*
|
| 1747 |
+
* // Listen to the request event
|
| 1748 |
+
* server.on('request', (request, res) => {
|
| 1749 |
+
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 1750 |
+
* res.end(JSON.stringify({
|
| 1751 |
+
* data: 'Hello World!',
|
| 1752 |
+
* }));
|
| 1753 |
+
* });
|
| 1754 |
+
*
|
| 1755 |
+
* server.listen(8000);
|
| 1756 |
+
* ```
|
| 1757 |
+
* @since v0.1.13
|
| 1758 |
+
*/
|
| 1759 |
+
function createServer<
|
| 1760 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
| 1761 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
| 1762 |
+
>(requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
|
| 1763 |
+
function createServer<
|
| 1764 |
+
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
| 1765 |
+
Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
|
| 1766 |
+
>(
|
| 1767 |
+
options: ServerOptions<Request, Response>,
|
| 1768 |
+
requestListener?: RequestListener<Request, Response>,
|
| 1769 |
+
): Server<Request, Response>;
|
| 1770 |
+
// although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
|
| 1771 |
+
// create interface RequestOptions would make the naming more clear to developers
|
| 1772 |
+
interface RequestOptions extends ClientRequestArgs {}
|
| 1773 |
+
/**
|
| 1774 |
+
* `options` in `socket.connect()` are also supported.
|
| 1775 |
+
*
|
| 1776 |
+
* Node.js maintains several connections per server to make HTTP requests.
|
| 1777 |
+
* This function allows one to transparently issue requests.
|
| 1778 |
+
*
|
| 1779 |
+
* `url` can be a string or a `URL` object. If `url` is a
|
| 1780 |
+
* string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
|
| 1781 |
+
*
|
| 1782 |
+
* If both `url` and `options` are specified, the objects are merged, with the `options` properties taking precedence.
|
| 1783 |
+
*
|
| 1784 |
+
* The optional `callback` parameter will be added as a one-time listener for
|
| 1785 |
+
* the `'response'` event.
|
| 1786 |
+
*
|
| 1787 |
+
* `http.request()` returns an instance of the {@link ClientRequest} class. The `ClientRequest` instance is a writable stream. If one needs to
|
| 1788 |
+
* upload a file with a POST request, then write to the `ClientRequest` object.
|
| 1789 |
+
*
|
| 1790 |
+
* ```js
|
| 1791 |
+
* import http from 'node:http';
|
| 1792 |
+
* import { Buffer } from 'node:buffer';
|
| 1793 |
+
*
|
| 1794 |
+
* const postData = JSON.stringify({
|
| 1795 |
+
* 'msg': 'Hello World!',
|
| 1796 |
+
* });
|
| 1797 |
+
*
|
| 1798 |
+
* const options = {
|
| 1799 |
+
* hostname: 'www.google.com',
|
| 1800 |
+
* port: 80,
|
| 1801 |
+
* path: '/upload',
|
| 1802 |
+
* method: 'POST',
|
| 1803 |
+
* headers: {
|
| 1804 |
+
* 'Content-Type': 'application/json',
|
| 1805 |
+
* 'Content-Length': Buffer.byteLength(postData),
|
| 1806 |
+
* },
|
| 1807 |
+
* };
|
| 1808 |
+
*
|
| 1809 |
+
* const req = http.request(options, (res) => {
|
| 1810 |
+
* console.log(`STATUS: ${res.statusCode}`);
|
| 1811 |
+
* console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
|
| 1812 |
+
* res.setEncoding('utf8');
|
| 1813 |
+
* res.on('data', (chunk) => {
|
| 1814 |
+
* console.log(`BODY: ${chunk}`);
|
| 1815 |
+
* });
|
| 1816 |
+
* res.on('end', () => {
|
| 1817 |
+
* console.log('No more data in response.');
|
| 1818 |
+
* });
|
| 1819 |
+
* });
|
| 1820 |
+
*
|
| 1821 |
+
* req.on('error', (e) => {
|
| 1822 |
+
* console.error(`problem with request: ${e.message}`);
|
| 1823 |
+
* });
|
| 1824 |
+
*
|
| 1825 |
+
* // Write data to request body
|
| 1826 |
+
* req.write(postData);
|
| 1827 |
+
* req.end();
|
| 1828 |
+
* ```
|
| 1829 |
+
*
|
| 1830 |
+
* In the example `req.end()` was called. With `http.request()` one
|
| 1831 |
+
* must always call `req.end()` to signify the end of the request -
|
| 1832 |
+
* even if there is no data being written to the request body.
|
| 1833 |
+
*
|
| 1834 |
+
* If any error is encountered during the request (be that with DNS resolution,
|
| 1835 |
+
* TCP level errors, or actual HTTP parse errors) an `'error'` event is emitted
|
| 1836 |
+
* on the returned request object. As with all `'error'` events, if no listeners
|
| 1837 |
+
* are registered the error will be thrown.
|
| 1838 |
+
*
|
| 1839 |
+
* There are a few special headers that should be noted.
|
| 1840 |
+
*
|
| 1841 |
+
* * Sending a 'Connection: keep-alive' will notify Node.js that the connection to
|
| 1842 |
+
* the server should be persisted until the next request.
|
| 1843 |
+
* * Sending a 'Content-Length' header will disable the default chunked encoding.
|
| 1844 |
+
* * Sending an 'Expect' header will immediately send the request headers.
|
| 1845 |
+
* Usually, when sending 'Expect: 100-continue', both a timeout and a listener
|
| 1846 |
+
* for the `'continue'` event should be set. See RFC 2616 Section 8.2.3 for more
|
| 1847 |
+
* information.
|
| 1848 |
+
* * Sending an Authorization header will override using the `auth` option
|
| 1849 |
+
* to compute basic authentication.
|
| 1850 |
+
*
|
| 1851 |
+
* Example using a `URL` as `options`:
|
| 1852 |
+
*
|
| 1853 |
+
* ```js
|
| 1854 |
+
* const options = new URL('http://abc:xyz@example.com');
|
| 1855 |
+
*
|
| 1856 |
+
* const req = http.request(options, (res) => {
|
| 1857 |
+
* // ...
|
| 1858 |
+
* });
|
| 1859 |
+
* ```
|
| 1860 |
+
*
|
| 1861 |
+
* In a successful request, the following events will be emitted in the following
|
| 1862 |
+
* order:
|
| 1863 |
+
*
|
| 1864 |
+
* * `'socket'`
|
| 1865 |
+
* * `'response'`
|
| 1866 |
+
* * `'data'` any number of times, on the `res` object
|
| 1867 |
+
* (`'data'` will not be emitted at all if the response body is empty, for
|
| 1868 |
+
* instance, in most redirects)
|
| 1869 |
+
* * `'end'` on the `res` object
|
| 1870 |
+
* * `'close'`
|
| 1871 |
+
*
|
| 1872 |
+
* In the case of a connection error, the following events will be emitted:
|
| 1873 |
+
*
|
| 1874 |
+
* * `'socket'`
|
| 1875 |
+
* * `'error'`
|
| 1876 |
+
* * `'close'`
|
| 1877 |
+
*
|
| 1878 |
+
* In the case of a premature connection close before the response is received,
|
| 1879 |
+
* the following events will be emitted in the following order:
|
| 1880 |
+
*
|
| 1881 |
+
* * `'socket'`
|
| 1882 |
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`
|
| 1883 |
+
* * `'close'`
|
| 1884 |
+
*
|
| 1885 |
+
* In the case of a premature connection close after the response is received,
|
| 1886 |
+
* the following events will be emitted in the following order:
|
| 1887 |
+
*
|
| 1888 |
+
* * `'socket'`
|
| 1889 |
+
* * `'response'`
|
| 1890 |
+
* * `'data'` any number of times, on the `res` object
|
| 1891 |
+
* * (connection closed here)
|
| 1892 |
+
* * `'aborted'` on the `res` object
|
| 1893 |
+
* * `'close'`
|
| 1894 |
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`
|
| 1895 |
+
* * `'close'` on the `res` object
|
| 1896 |
+
*
|
| 1897 |
+
* If `req.destroy()` is called before a socket is assigned, the following
|
| 1898 |
+
* events will be emitted in the following order:
|
| 1899 |
+
*
|
| 1900 |
+
* * (`req.destroy()` called here)
|
| 1901 |
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
| 1902 |
+
* * `'close'`
|
| 1903 |
+
*
|
| 1904 |
+
* If `req.destroy()` is called before the connection succeeds, the following
|
| 1905 |
+
* events will be emitted in the following order:
|
| 1906 |
+
*
|
| 1907 |
+
* * `'socket'`
|
| 1908 |
+
* * (`req.destroy()` called here)
|
| 1909 |
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
| 1910 |
+
* * `'close'`
|
| 1911 |
+
*
|
| 1912 |
+
* If `req.destroy()` is called after the response is received, the following
|
| 1913 |
+
* events will be emitted in the following order:
|
| 1914 |
+
*
|
| 1915 |
+
* * `'socket'`
|
| 1916 |
+
* * `'response'`
|
| 1917 |
+
* * `'data'` any number of times, on the `res` object
|
| 1918 |
+
* * (`req.destroy()` called here)
|
| 1919 |
+
* * `'aborted'` on the `res` object
|
| 1920 |
+
* * `'close'`
|
| 1921 |
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
| 1922 |
+
* * `'close'` on the `res` object
|
| 1923 |
+
*
|
| 1924 |
+
* If `req.abort()` is called before a socket is assigned, the following
|
| 1925 |
+
* events will be emitted in the following order:
|
| 1926 |
+
*
|
| 1927 |
+
* * (`req.abort()` called here)
|
| 1928 |
+
* * `'abort'`
|
| 1929 |
+
* * `'close'`
|
| 1930 |
+
*
|
| 1931 |
+
* If `req.abort()` is called before the connection succeeds, the following
|
| 1932 |
+
* events will be emitted in the following order:
|
| 1933 |
+
*
|
| 1934 |
+
* * `'socket'`
|
| 1935 |
+
* * (`req.abort()` called here)
|
| 1936 |
+
* * `'abort'`
|
| 1937 |
+
* * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`
|
| 1938 |
+
* * `'close'`
|
| 1939 |
+
*
|
| 1940 |
+
* If `req.abort()` is called after the response is received, the following
|
| 1941 |
+
* events will be emitted in the following order:
|
| 1942 |
+
*
|
| 1943 |
+
* * `'socket'`
|
| 1944 |
+
* * `'response'`
|
| 1945 |
+
* * `'data'` any number of times, on the `res` object
|
| 1946 |
+
* * (`req.abort()` called here)
|
| 1947 |
+
* * `'abort'`
|
| 1948 |
+
* * `'aborted'` on the `res` object
|
| 1949 |
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`.
|
| 1950 |
+
* * `'close'`
|
| 1951 |
+
* * `'close'` on the `res` object
|
| 1952 |
+
*
|
| 1953 |
+
* Setting the `timeout` option or using the `setTimeout()` function will
|
| 1954 |
+
* not abort the request or do anything besides add a `'timeout'` event.
|
| 1955 |
+
*
|
| 1956 |
+
* Passing an `AbortSignal` and then calling `abort()` on the corresponding `AbortController` will behave the same way as calling `.destroy()` on the
|
| 1957 |
+
* request. Specifically, the `'error'` event will be emitted with an error with
|
| 1958 |
+
* the message `'AbortError: The operation was aborted'`, the code `'ABORT_ERR'` and the `cause`, if one was provided.
|
| 1959 |
+
* @since v0.3.6
|
| 1960 |
+
*/
|
| 1961 |
+
function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
| 1962 |
+
function request(
|
| 1963 |
+
url: string | URL,
|
| 1964 |
+
options: RequestOptions,
|
| 1965 |
+
callback?: (res: IncomingMessage) => void,
|
| 1966 |
+
): ClientRequest;
|
| 1967 |
+
/**
|
| 1968 |
+
* Since most requests are GET requests without bodies, Node.js provides this
|
| 1969 |
+
* 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
|
| 1970 |
+
* consume the response
|
| 1971 |
+
* data for reasons stated in {@link ClientRequest} section.
|
| 1972 |
+
*
|
| 1973 |
+
* The `callback` is invoked with a single argument that is an instance of {@link IncomingMessage}.
|
| 1974 |
+
*
|
| 1975 |
+
* JSON fetching example:
|
| 1976 |
+
*
|
| 1977 |
+
* ```js
|
| 1978 |
+
* http.get('http://localhost:8000/', (res) => {
|
| 1979 |
+
* const { statusCode } = res;
|
| 1980 |
+
* const contentType = res.headers['content-type'];
|
| 1981 |
+
*
|
| 1982 |
+
* let error;
|
| 1983 |
+
* // Any 2xx status code signals a successful response but
|
| 1984 |
+
* // here we're only checking for 200.
|
| 1985 |
+
* if (statusCode !== 200) {
|
| 1986 |
+
* error = new Error('Request Failed.\n' +
|
| 1987 |
+
* `Status Code: ${statusCode}`);
|
| 1988 |
+
* } else if (!/^application\/json/.test(contentType)) {
|
| 1989 |
+
* error = new Error('Invalid content-type.\n' +
|
| 1990 |
+
* `Expected application/json but received ${contentType}`);
|
| 1991 |
+
* }
|
| 1992 |
+
* if (error) {
|
| 1993 |
+
* console.error(error.message);
|
| 1994 |
+
* // Consume response data to free up memory
|
| 1995 |
+
* res.resume();
|
| 1996 |
+
* return;
|
| 1997 |
+
* }
|
| 1998 |
+
*
|
| 1999 |
+
* res.setEncoding('utf8');
|
| 2000 |
+
* let rawData = '';
|
| 2001 |
+
* res.on('data', (chunk) => { rawData += chunk; });
|
| 2002 |
+
* res.on('end', () => {
|
| 2003 |
+
* try {
|
| 2004 |
+
* const parsedData = JSON.parse(rawData);
|
| 2005 |
+
* console.log(parsedData);
|
| 2006 |
+
* } catch (e) {
|
| 2007 |
+
* console.error(e.message);
|
| 2008 |
+
* }
|
| 2009 |
+
* });
|
| 2010 |
+
* }).on('error', (e) => {
|
| 2011 |
+
* console.error(`Got error: ${e.message}`);
|
| 2012 |
+
* });
|
| 2013 |
+
*
|
| 2014 |
+
* // Create a local server to receive data from
|
| 2015 |
+
* const server = http.createServer((req, res) => {
|
| 2016 |
+
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 2017 |
+
* res.end(JSON.stringify({
|
| 2018 |
+
* data: 'Hello World!',
|
| 2019 |
+
* }));
|
| 2020 |
+
* });
|
| 2021 |
+
*
|
| 2022 |
+
* server.listen(8000);
|
| 2023 |
+
* ```
|
| 2024 |
+
* @since v0.3.6
|
| 2025 |
+
* @param options Accepts the same `options` as {@link request}, with the method set to GET by default.
|
| 2026 |
+
*/
|
| 2027 |
+
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
| 2028 |
+
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
| 2029 |
+
/**
|
| 2030 |
+
* Performs the low-level validations on the provided `name` that are done when `res.setHeader(name, value)` is called.
|
| 2031 |
+
*
|
| 2032 |
+
* Passing illegal value as `name` will result in a `TypeError` being thrown,
|
| 2033 |
+
* identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
|
| 2034 |
+
*
|
| 2035 |
+
* It is not necessary to use this method before passing headers to an HTTP request
|
| 2036 |
+
* or response. The HTTP module will automatically validate such headers.
|
| 2037 |
+
*
|
| 2038 |
+
* Example:
|
| 2039 |
+
*
|
| 2040 |
+
* ```js
|
| 2041 |
+
* import { validateHeaderName } from 'node:http';
|
| 2042 |
+
*
|
| 2043 |
+
* try {
|
| 2044 |
+
* validateHeaderName('');
|
| 2045 |
+
* } catch (err) {
|
| 2046 |
+
* console.error(err instanceof TypeError); // --> true
|
| 2047 |
+
* console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'
|
| 2048 |
+
* console.error(err.message); // --> 'Header name must be a valid HTTP token [""]'
|
| 2049 |
+
* }
|
| 2050 |
+
* ```
|
| 2051 |
+
* @since v14.3.0
|
| 2052 |
+
* @param [label='Header name'] Label for error message.
|
| 2053 |
+
*/
|
| 2054 |
+
function validateHeaderName(name: string): void;
|
| 2055 |
+
/**
|
| 2056 |
+
* Performs the low-level validations on the provided `value` that are done when `res.setHeader(name, value)` is called.
|
| 2057 |
+
*
|
| 2058 |
+
* Passing illegal value as `value` will result in a `TypeError` being thrown.
|
| 2059 |
+
*
|
| 2060 |
+
* * Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
|
| 2061 |
+
* * Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
|
| 2062 |
+
*
|
| 2063 |
+
* It is not necessary to use this method before passing headers to an HTTP request
|
| 2064 |
+
* or response. The HTTP module will automatically validate such headers.
|
| 2065 |
+
*
|
| 2066 |
+
* Examples:
|
| 2067 |
+
*
|
| 2068 |
+
* ```js
|
| 2069 |
+
* import { validateHeaderValue } from 'node:http';
|
| 2070 |
+
*
|
| 2071 |
+
* try {
|
| 2072 |
+
* validateHeaderValue('x-my-header', undefined);
|
| 2073 |
+
* } catch (err) {
|
| 2074 |
+
* console.error(err instanceof TypeError); // --> true
|
| 2075 |
+
* console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true
|
| 2076 |
+
* console.error(err.message); // --> 'Invalid value "undefined" for header "x-my-header"'
|
| 2077 |
+
* }
|
| 2078 |
+
*
|
| 2079 |
+
* try {
|
| 2080 |
+
* validateHeaderValue('x-my-header', 'oʊmɪɡə');
|
| 2081 |
+
* } catch (err) {
|
| 2082 |
+
* console.error(err instanceof TypeError); // --> true
|
| 2083 |
+
* console.error(err.code === 'ERR_INVALID_CHAR'); // --> true
|
| 2084 |
+
* console.error(err.message); // --> 'Invalid character in header content ["x-my-header"]'
|
| 2085 |
+
* }
|
| 2086 |
+
* ```
|
| 2087 |
+
* @since v14.3.0
|
| 2088 |
+
* @param name Header name
|
| 2089 |
+
* @param value Header value
|
| 2090 |
+
*/
|
| 2091 |
+
function validateHeaderValue(name: string, value: string): void;
|
| 2092 |
+
/**
|
| 2093 |
+
* Set the maximum number of idle HTTP parsers.
|
| 2094 |
+
* @since v18.8.0, v16.18.0
|
| 2095 |
+
* @param [max=1000]
|
| 2096 |
+
*/
|
| 2097 |
+
function setMaxIdleHTTPParsers(max: number): void;
|
| 2098 |
+
/**
|
| 2099 |
+
* Dynamically resets the global configurations to enable built-in proxy support for
|
| 2100 |
+
* `fetch()` and `http.request()`/`https.request()` at runtime, as an alternative
|
| 2101 |
+
* to using the `--use-env-proxy` flag or `NODE_USE_ENV_PROXY` environment variable.
|
| 2102 |
+
* It can also be used to override settings configured from the environment variables.
|
| 2103 |
+
*
|
| 2104 |
+
* As this function resets the global configurations, any previously configured
|
| 2105 |
+
* `http.globalAgent`, `https.globalAgent` or undici global dispatcher would be
|
| 2106 |
+
* overridden after this function is invoked. It's recommended to invoke it before any
|
| 2107 |
+
* requests are made and avoid invoking it in the middle of any requests.
|
| 2108 |
+
*
|
| 2109 |
+
* See [Built-in Proxy Support](https://nodejs.org/docs/latest-v25.x/api/http.html#built-in-proxy-support) for details on proxy URL formats and `NO_PROXY`
|
| 2110 |
+
* syntax.
|
| 2111 |
+
* @since v25.4.0
|
| 2112 |
+
* @param proxyEnv An object containing proxy configuration. This accepts the
|
| 2113 |
+
* same options as the `proxyEnv` option accepted by {@link Agent}. **Default:**
|
| 2114 |
+
* `process.env`.
|
| 2115 |
+
* @returns A function that restores the original agent and dispatcher
|
| 2116 |
+
* settings to the state before this `http.setGlobalProxyFromEnv()` is invoked.
|
| 2117 |
+
*/
|
| 2118 |
+
function setGlobalProxyFromEnv(proxyEnv?: ProxyEnv): () => void;
|
| 2119 |
+
/**
|
| 2120 |
+
* Global instance of `Agent` which is used as the default for all HTTP client
|
| 2121 |
+
* requests. Diverges from a default `Agent` configuration by having `keepAlive`
|
| 2122 |
+
* enabled and a `timeout` of 5 seconds.
|
| 2123 |
+
* @since v0.5.9
|
| 2124 |
+
*/
|
| 2125 |
+
let globalAgent: Agent;
|
| 2126 |
+
/**
|
| 2127 |
+
* Read-only property specifying the maximum allowed size of HTTP headers in bytes.
|
| 2128 |
+
* Defaults to 16KB. Configurable using the `--max-http-header-size` CLI option.
|
| 2129 |
+
*/
|
| 2130 |
+
const maxHeaderSize: number;
|
| 2131 |
+
/**
|
| 2132 |
+
* A browser-compatible implementation of `WebSocket`.
|
| 2133 |
+
* @since v22.5.0
|
| 2134 |
+
*/
|
| 2135 |
+
const WebSocket: typeof import("undici-types").WebSocket;
|
| 2136 |
+
/**
|
| 2137 |
+
* @since v22.5.0
|
| 2138 |
+
*/
|
| 2139 |
+
const CloseEvent: typeof import("undici-types").CloseEvent;
|
| 2140 |
+
/**
|
| 2141 |
+
* @since v22.5.0
|
| 2142 |
+
*/
|
| 2143 |
+
const MessageEvent: typeof import("undici-types").MessageEvent;
|
| 2144 |
+
}
|
| 2145 |
+
declare module "http" {
|
| 2146 |
+
export * from "node:http";
|
| 2147 |
+
}
|
node_modules/@types/node/http2.d.ts
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/@types/node/https.d.ts
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:https" {
|
| 2 |
+
import * as http from "node:http";
|
| 3 |
+
import { Duplex } from "node:stream";
|
| 4 |
+
import * as tls from "node:tls";
|
| 5 |
+
import { URL } from "node:url";
|
| 6 |
+
interface ServerOptions<
|
| 7 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
| 8 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
| 9 |
+
> extends http.ServerOptions<Request, Response>, tls.TlsOptions {}
|
| 10 |
+
interface RequestOptions extends http.RequestOptions, tls.SecureContextOptions {
|
| 11 |
+
checkServerIdentity?:
|
| 12 |
+
| ((hostname: string, cert: tls.DetailedPeerCertificate) => Error | undefined)
|
| 13 |
+
| undefined;
|
| 14 |
+
rejectUnauthorized?: boolean | undefined; // Defaults to true
|
| 15 |
+
servername?: string | undefined; // SNI TLS Extension
|
| 16 |
+
}
|
| 17 |
+
interface AgentOptions extends http.AgentOptions, tls.ConnectionOptions {
|
| 18 |
+
maxCachedSessions?: number | undefined;
|
| 19 |
+
}
|
| 20 |
+
/**
|
| 21 |
+
* An `Agent` object for HTTPS similar to `http.Agent`. See {@link request} for more information.
|
| 22 |
+
*
|
| 23 |
+
* Like `http.Agent`, the `createConnection(options[, callback])` method can be overridden
|
| 24 |
+
* to customize how TLS connections are established.
|
| 25 |
+
*
|
| 26 |
+
* > See `agent.createConnection()` for details on overriding this method,
|
| 27 |
+
* > including asynchronous socket creation with a callback.
|
| 28 |
+
* @since v0.4.5
|
| 29 |
+
*/
|
| 30 |
+
class Agent extends http.Agent {
|
| 31 |
+
constructor(options?: AgentOptions);
|
| 32 |
+
options: AgentOptions;
|
| 33 |
+
createConnection(
|
| 34 |
+
options: RequestOptions,
|
| 35 |
+
callback?: (err: Error | null, stream: Duplex) => void,
|
| 36 |
+
): Duplex | null | undefined;
|
| 37 |
+
getName(options?: RequestOptions): string;
|
| 38 |
+
}
|
| 39 |
+
interface ServerEventMap<
|
| 40 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
| 41 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
| 42 |
+
> extends http.ServerEventMap<Request, Response>, tls.ServerEventMap {}
|
| 43 |
+
/**
|
| 44 |
+
* See `http.Server` for more information.
|
| 45 |
+
* @since v0.3.4
|
| 46 |
+
*/
|
| 47 |
+
class Server<
|
| 48 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
| 49 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
| 50 |
+
> extends tls.Server {
|
| 51 |
+
constructor(requestListener?: http.RequestListener<Request, Response>);
|
| 52 |
+
constructor(
|
| 53 |
+
options: ServerOptions<Request, Response>,
|
| 54 |
+
requestListener?: http.RequestListener<Request, Response>,
|
| 55 |
+
);
|
| 56 |
+
/**
|
| 57 |
+
* Closes all connections connected to this server.
|
| 58 |
+
* @since v18.2.0
|
| 59 |
+
*/
|
| 60 |
+
closeAllConnections(): void;
|
| 61 |
+
/**
|
| 62 |
+
* Closes all connections connected to this server which are not sending a request or waiting for a response.
|
| 63 |
+
* @since v18.2.0
|
| 64 |
+
*/
|
| 65 |
+
closeIdleConnections(): void;
|
| 66 |
+
// #region InternalEventEmitter
|
| 67 |
+
addListener<E extends keyof ServerEventMap>(
|
| 68 |
+
eventName: E,
|
| 69 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 70 |
+
): this;
|
| 71 |
+
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 72 |
+
emit<E extends keyof ServerEventMap>(eventName: E, ...args: ServerEventMap<Request, Response>[E]): boolean;
|
| 73 |
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
| 74 |
+
listenerCount<E extends keyof ServerEventMap>(
|
| 75 |
+
eventName: E,
|
| 76 |
+
listener?: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 77 |
+
): number;
|
| 78 |
+
listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
|
| 79 |
+
listeners<E extends keyof ServerEventMap>(
|
| 80 |
+
eventName: E,
|
| 81 |
+
): ((...args: ServerEventMap<Request, Response>[E]) => void)[];
|
| 82 |
+
listeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 83 |
+
off<E extends keyof ServerEventMap>(
|
| 84 |
+
eventName: E,
|
| 85 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 86 |
+
): this;
|
| 87 |
+
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 88 |
+
on<E extends keyof ServerEventMap>(
|
| 89 |
+
eventName: E,
|
| 90 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 91 |
+
): this;
|
| 92 |
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 93 |
+
once<E extends keyof ServerEventMap>(
|
| 94 |
+
eventName: E,
|
| 95 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 96 |
+
): this;
|
| 97 |
+
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 98 |
+
prependListener<E extends keyof ServerEventMap>(
|
| 99 |
+
eventName: E,
|
| 100 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 101 |
+
): this;
|
| 102 |
+
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 103 |
+
prependOnceListener<E extends keyof ServerEventMap>(
|
| 104 |
+
eventName: E,
|
| 105 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 106 |
+
): this;
|
| 107 |
+
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 108 |
+
rawListeners<E extends keyof ServerEventMap>(
|
| 109 |
+
eventName: E,
|
| 110 |
+
): ((...args: ServerEventMap<Request, Response>[E]) => void)[];
|
| 111 |
+
rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 112 |
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
| 113 |
+
removeAllListeners<E extends keyof ServerEventMap>(eventName?: E): this;
|
| 114 |
+
removeAllListeners(eventName?: string | symbol): this;
|
| 115 |
+
removeListener<E extends keyof ServerEventMap>(
|
| 116 |
+
eventName: E,
|
| 117 |
+
listener: (...args: ServerEventMap<Request, Response>[E]) => void,
|
| 118 |
+
): this;
|
| 119 |
+
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 120 |
+
// #endregion
|
| 121 |
+
}
|
| 122 |
+
interface Server<
|
| 123 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
| 124 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
| 125 |
+
> extends http.Server<Request, Response> {}
|
| 126 |
+
/**
|
| 127 |
+
* ```js
|
| 128 |
+
* // curl -k https://localhost:8000/
|
| 129 |
+
* import https from 'node:https';
|
| 130 |
+
* import fs from 'node:fs';
|
| 131 |
+
*
|
| 132 |
+
* const options = {
|
| 133 |
+
* key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
|
| 134 |
+
* cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
|
| 135 |
+
* };
|
| 136 |
+
*
|
| 137 |
+
* https.createServer(options, (req, res) => {
|
| 138 |
+
* res.writeHead(200);
|
| 139 |
+
* res.end('hello world\n');
|
| 140 |
+
* }).listen(8000);
|
| 141 |
+
* ```
|
| 142 |
+
*
|
| 143 |
+
* Or
|
| 144 |
+
*
|
| 145 |
+
* ```js
|
| 146 |
+
* import https from 'node:https';
|
| 147 |
+
* import fs from 'node:fs';
|
| 148 |
+
*
|
| 149 |
+
* const options = {
|
| 150 |
+
* pfx: fs.readFileSync('test/fixtures/test_cert.pfx'),
|
| 151 |
+
* passphrase: 'sample',
|
| 152 |
+
* };
|
| 153 |
+
*
|
| 154 |
+
* https.createServer(options, (req, res) => {
|
| 155 |
+
* res.writeHead(200);
|
| 156 |
+
* res.end('hello world\n');
|
| 157 |
+
* }).listen(8000);
|
| 158 |
+
* ```
|
| 159 |
+
* @since v0.3.4
|
| 160 |
+
* @param options Accepts `options` from `createServer`, `createSecureContext` and `createServer`.
|
| 161 |
+
* @param requestListener A listener to be added to the `'request'` event.
|
| 162 |
+
*/
|
| 163 |
+
function createServer<
|
| 164 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
| 165 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
| 166 |
+
>(requestListener?: http.RequestListener<Request, Response>): Server<Request, Response>;
|
| 167 |
+
function createServer<
|
| 168 |
+
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,
|
| 169 |
+
Response extends typeof http.ServerResponse<InstanceType<Request>> = typeof http.ServerResponse,
|
| 170 |
+
>(
|
| 171 |
+
options: ServerOptions<Request, Response>,
|
| 172 |
+
requestListener?: http.RequestListener<Request, Response>,
|
| 173 |
+
): Server<Request, Response>;
|
| 174 |
+
/**
|
| 175 |
+
* Makes a request to a secure web server.
|
| 176 |
+
*
|
| 177 |
+
* The following additional `options` from `tls.connect()` are also accepted: `ca`, `cert`, `ciphers`, `clientCertEngine`, `crl`, `dhparam`, `ecdhCurve`, `honorCipherOrder`, `key`, `passphrase`,
|
| 178 |
+
* `pfx`, `rejectUnauthorized`, `secureOptions`, `secureProtocol`, `servername`, `sessionIdContext`, `highWaterMark`.
|
| 179 |
+
*
|
| 180 |
+
* `options` can be an object, a string, or a `URL` object. If `options` is a
|
| 181 |
+
* string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
|
| 182 |
+
*
|
| 183 |
+
* `https.request()` returns an instance of the `http.ClientRequest` class. The `ClientRequest` instance is a writable stream. If one needs to
|
| 184 |
+
* upload a file with a POST request, then write to the `ClientRequest` object.
|
| 185 |
+
*
|
| 186 |
+
* ```js
|
| 187 |
+
* import https from 'node:https';
|
| 188 |
+
*
|
| 189 |
+
* const options = {
|
| 190 |
+
* hostname: 'encrypted.google.com',
|
| 191 |
+
* port: 443,
|
| 192 |
+
* path: '/',
|
| 193 |
+
* method: 'GET',
|
| 194 |
+
* };
|
| 195 |
+
*
|
| 196 |
+
* const req = https.request(options, (res) => {
|
| 197 |
+
* console.log('statusCode:', res.statusCode);
|
| 198 |
+
* console.log('headers:', res.headers);
|
| 199 |
+
*
|
| 200 |
+
* res.on('data', (d) => {
|
| 201 |
+
* process.stdout.write(d);
|
| 202 |
+
* });
|
| 203 |
+
* });
|
| 204 |
+
*
|
| 205 |
+
* req.on('error', (e) => {
|
| 206 |
+
* console.error(e);
|
| 207 |
+
* });
|
| 208 |
+
* req.end();
|
| 209 |
+
* ```
|
| 210 |
+
*
|
| 211 |
+
* Example using options from `tls.connect()`:
|
| 212 |
+
*
|
| 213 |
+
* ```js
|
| 214 |
+
* const options = {
|
| 215 |
+
* hostname: 'encrypted.google.com',
|
| 216 |
+
* port: 443,
|
| 217 |
+
* path: '/',
|
| 218 |
+
* method: 'GET',
|
| 219 |
+
* key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
|
| 220 |
+
* cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
|
| 221 |
+
* };
|
| 222 |
+
* options.agent = new https.Agent(options);
|
| 223 |
+
*
|
| 224 |
+
* const req = https.request(options, (res) => {
|
| 225 |
+
* // ...
|
| 226 |
+
* });
|
| 227 |
+
* ```
|
| 228 |
+
*
|
| 229 |
+
* Alternatively, opt out of connection pooling by not using an `Agent`.
|
| 230 |
+
*
|
| 231 |
+
* ```js
|
| 232 |
+
* const options = {
|
| 233 |
+
* hostname: 'encrypted.google.com',
|
| 234 |
+
* port: 443,
|
| 235 |
+
* path: '/',
|
| 236 |
+
* method: 'GET',
|
| 237 |
+
* key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
|
| 238 |
+
* cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
|
| 239 |
+
* agent: false,
|
| 240 |
+
* };
|
| 241 |
+
*
|
| 242 |
+
* const req = https.request(options, (res) => {
|
| 243 |
+
* // ...
|
| 244 |
+
* });
|
| 245 |
+
* ```
|
| 246 |
+
*
|
| 247 |
+
* Example using a `URL` as `options`:
|
| 248 |
+
*
|
| 249 |
+
* ```js
|
| 250 |
+
* const options = new URL('https://abc:xyz@example.com');
|
| 251 |
+
*
|
| 252 |
+
* const req = https.request(options, (res) => {
|
| 253 |
+
* // ...
|
| 254 |
+
* });
|
| 255 |
+
* ```
|
| 256 |
+
*
|
| 257 |
+
* Example pinning on certificate fingerprint, or the public key (similar to`pin-sha256`):
|
| 258 |
+
*
|
| 259 |
+
* ```js
|
| 260 |
+
* import tls from 'node:tls';
|
| 261 |
+
* import https from 'node:https';
|
| 262 |
+
* import crypto from 'node:crypto';
|
| 263 |
+
*
|
| 264 |
+
* function sha256(s) {
|
| 265 |
+
* return crypto.createHash('sha256').update(s).digest('base64');
|
| 266 |
+
* }
|
| 267 |
+
* const options = {
|
| 268 |
+
* hostname: 'github.com',
|
| 269 |
+
* port: 443,
|
| 270 |
+
* path: '/',
|
| 271 |
+
* method: 'GET',
|
| 272 |
+
* checkServerIdentity: function(host, cert) {
|
| 273 |
+
* // Make sure the certificate is issued to the host we are connected to
|
| 274 |
+
* const err = tls.checkServerIdentity(host, cert);
|
| 275 |
+
* if (err) {
|
| 276 |
+
* return err;
|
| 277 |
+
* }
|
| 278 |
+
*
|
| 279 |
+
* // Pin the public key, similar to HPKP pin-sha256 pinning
|
| 280 |
+
* const pubkey256 = 'pL1+qb9HTMRZJmuC/bB/ZI9d302BYrrqiVuRyW+DGrU=';
|
| 281 |
+
* if (sha256(cert.pubkey) !== pubkey256) {
|
| 282 |
+
* const msg = 'Certificate verification error: ' +
|
| 283 |
+
* `The public key of '${cert.subject.CN}' ` +
|
| 284 |
+
* 'does not match our pinned fingerprint';
|
| 285 |
+
* return new Error(msg);
|
| 286 |
+
* }
|
| 287 |
+
*
|
| 288 |
+
* // Pin the exact certificate, rather than the pub key
|
| 289 |
+
* const cert256 = '25:FE:39:32:D9:63:8C:8A:FC:A1:9A:29:87:' +
|
| 290 |
+
* 'D8:3E:4C:1D:98:DB:71:E4:1A:48:03:98:EA:22:6A:BD:8B:93:16';
|
| 291 |
+
* if (cert.fingerprint256 !== cert256) {
|
| 292 |
+
* const msg = 'Certificate verification error: ' +
|
| 293 |
+
* `The certificate of '${cert.subject.CN}' ` +
|
| 294 |
+
* 'does not match our pinned fingerprint';
|
| 295 |
+
* return new Error(msg);
|
| 296 |
+
* }
|
| 297 |
+
*
|
| 298 |
+
* // This loop is informational only.
|
| 299 |
+
* // Print the certificate and public key fingerprints of all certs in the
|
| 300 |
+
* // chain. Its common to pin the public key of the issuer on the public
|
| 301 |
+
* // internet, while pinning the public key of the service in sensitive
|
| 302 |
+
* // environments.
|
| 303 |
+
* do {
|
| 304 |
+
* console.log('Subject Common Name:', cert.subject.CN);
|
| 305 |
+
* console.log(' Certificate SHA256 fingerprint:', cert.fingerprint256);
|
| 306 |
+
*
|
| 307 |
+
* hash = crypto.createHash('sha256');
|
| 308 |
+
* console.log(' Public key ping-sha256:', sha256(cert.pubkey));
|
| 309 |
+
*
|
| 310 |
+
* lastprint256 = cert.fingerprint256;
|
| 311 |
+
* cert = cert.issuerCertificate;
|
| 312 |
+
* } while (cert.fingerprint256 !== lastprint256);
|
| 313 |
+
*
|
| 314 |
+
* },
|
| 315 |
+
* };
|
| 316 |
+
*
|
| 317 |
+
* options.agent = new https.Agent(options);
|
| 318 |
+
* const req = https.request(options, (res) => {
|
| 319 |
+
* console.log('All OK. Server matched our pinned cert or public key');
|
| 320 |
+
* console.log('statusCode:', res.statusCode);
|
| 321 |
+
* // Print the HPKP values
|
| 322 |
+
* console.log('headers:', res.headers['public-key-pins']);
|
| 323 |
+
*
|
| 324 |
+
* res.on('data', (d) => {});
|
| 325 |
+
* });
|
| 326 |
+
*
|
| 327 |
+
* req.on('error', (e) => {
|
| 328 |
+
* console.error(e.message);
|
| 329 |
+
* });
|
| 330 |
+
* req.end();
|
| 331 |
+
* ```
|
| 332 |
+
*
|
| 333 |
+
* Outputs for example:
|
| 334 |
+
*
|
| 335 |
+
* ```text
|
| 336 |
+
* Subject Common Name: github.com
|
| 337 |
+
* 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
|
| 338 |
+
* Public key ping-sha256: pL1+qb9HTMRZJmuC/bB/ZI9d302BYrrqiVuRyW+DGrU=
|
| 339 |
+
* Subject Common Name: DigiCert SHA2 Extended Validation Server CA
|
| 340 |
+
* 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
|
| 341 |
+
* Public key ping-sha256: RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=
|
| 342 |
+
* Subject Common Name: DigiCert High Assurance EV Root CA
|
| 343 |
+
* 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
|
| 344 |
+
* Public key ping-sha256: WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=
|
| 345 |
+
* All OK. Server matched our pinned cert or public key
|
| 346 |
+
* statusCode: 200
|
| 347 |
+
* headers: max-age=0; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";
|
| 348 |
+
* pin-sha256="k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws="; pin-sha256="K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q="; pin-sha256="IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4=";
|
| 349 |
+
* pin-sha256="iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0="; pin-sha256="LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A="; includeSubDomains
|
| 350 |
+
* ```
|
| 351 |
+
* @since v0.3.6
|
| 352 |
+
* @param options Accepts all `options` from `request`, with some differences in default values:
|
| 353 |
+
*/
|
| 354 |
+
function request(
|
| 355 |
+
options: RequestOptions | string | URL,
|
| 356 |
+
callback?: (res: http.IncomingMessage) => void,
|
| 357 |
+
): http.ClientRequest;
|
| 358 |
+
function request(
|
| 359 |
+
url: string | URL,
|
| 360 |
+
options: RequestOptions,
|
| 361 |
+
callback?: (res: http.IncomingMessage) => void,
|
| 362 |
+
): http.ClientRequest;
|
| 363 |
+
/**
|
| 364 |
+
* Like `http.get()` but for HTTPS.
|
| 365 |
+
*
|
| 366 |
+
* `options` can be an object, a string, or a `URL` object. If `options` is a
|
| 367 |
+
* string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
|
| 368 |
+
*
|
| 369 |
+
* ```js
|
| 370 |
+
* import https from 'node:https';
|
| 371 |
+
*
|
| 372 |
+
* https.get('https://encrypted.google.com/', (res) => {
|
| 373 |
+
* console.log('statusCode:', res.statusCode);
|
| 374 |
+
* console.log('headers:', res.headers);
|
| 375 |
+
*
|
| 376 |
+
* res.on('data', (d) => {
|
| 377 |
+
* process.stdout.write(d);
|
| 378 |
+
* });
|
| 379 |
+
*
|
| 380 |
+
* }).on('error', (e) => {
|
| 381 |
+
* console.error(e);
|
| 382 |
+
* });
|
| 383 |
+
* ```
|
| 384 |
+
* @since v0.3.6
|
| 385 |
+
* @param options Accepts the same `options` as {@link request}, with the `method` always set to `GET`.
|
| 386 |
+
*/
|
| 387 |
+
function get(
|
| 388 |
+
options: RequestOptions | string | URL,
|
| 389 |
+
callback?: (res: http.IncomingMessage) => void,
|
| 390 |
+
): http.ClientRequest;
|
| 391 |
+
function get(
|
| 392 |
+
url: string | URL,
|
| 393 |
+
options: RequestOptions,
|
| 394 |
+
callback?: (res: http.IncomingMessage) => void,
|
| 395 |
+
): http.ClientRequest;
|
| 396 |
+
let globalAgent: Agent;
|
| 397 |
+
}
|
| 398 |
+
declare module "https" {
|
| 399 |
+
export * from "node:https";
|
| 400 |
+
}
|
node_modules/@types/node/index.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.8+.
|
| 26 |
+
|
| 27 |
+
// Reference required TypeScript libraries:
|
| 28 |
+
/// <reference lib="es2020" />
|
| 29 |
+
/// <reference lib="esnext.disposable" />
|
| 30 |
+
/// <reference lib="esnext.float16" />
|
| 31 |
+
|
| 32 |
+
// Iterator definitions required for compatibility with TypeScript <5.6:
|
| 33 |
+
/// <reference path="compatibility/iterators.d.ts" />
|
| 34 |
+
|
| 35 |
+
// Definitions for Node.js modules specific to TypeScript 5.7+:
|
| 36 |
+
/// <reference path="globals.typedarray.d.ts" />
|
| 37 |
+
/// <reference path="buffer.buffer.d.ts" />
|
| 38 |
+
|
| 39 |
+
// Definitions for Node.js modules that are not specific to any version of TypeScript:
|
| 40 |
+
/// <reference path="globals.d.ts" />
|
| 41 |
+
/// <reference path="web-globals/abortcontroller.d.ts" />
|
| 42 |
+
/// <reference path="web-globals/blob.d.ts" />
|
| 43 |
+
/// <reference path="web-globals/console.d.ts" />
|
| 44 |
+
/// <reference path="web-globals/crypto.d.ts" />
|
| 45 |
+
/// <reference path="web-globals/domexception.d.ts" />
|
| 46 |
+
/// <reference path="web-globals/encoding.d.ts" />
|
| 47 |
+
/// <reference path="web-globals/events.d.ts" />
|
| 48 |
+
/// <reference path="web-globals/fetch.d.ts" />
|
| 49 |
+
/// <reference path="web-globals/importmeta.d.ts" />
|
| 50 |
+
/// <reference path="web-globals/messaging.d.ts" />
|
| 51 |
+
/// <reference path="web-globals/navigator.d.ts" />
|
| 52 |
+
/// <reference path="web-globals/performance.d.ts" />
|
| 53 |
+
/// <reference path="web-globals/storage.d.ts" />
|
| 54 |
+
/// <reference path="web-globals/streams.d.ts" />
|
| 55 |
+
/// <reference path="web-globals/timers.d.ts" />
|
| 56 |
+
/// <reference path="web-globals/url.d.ts" />
|
| 57 |
+
/// <reference path="assert.d.ts" />
|
| 58 |
+
/// <reference path="assert/strict.d.ts" />
|
| 59 |
+
/// <reference path="async_hooks.d.ts" />
|
| 60 |
+
/// <reference path="buffer.d.ts" />
|
| 61 |
+
/// <reference path="child_process.d.ts" />
|
| 62 |
+
/// <reference path="cluster.d.ts" />
|
| 63 |
+
/// <reference path="console.d.ts" />
|
| 64 |
+
/// <reference path="constants.d.ts" />
|
| 65 |
+
/// <reference path="crypto.d.ts" />
|
| 66 |
+
/// <reference path="dgram.d.ts" />
|
| 67 |
+
/// <reference path="diagnostics_channel.d.ts" />
|
| 68 |
+
/// <reference path="dns.d.ts" />
|
| 69 |
+
/// <reference path="dns/promises.d.ts" />
|
| 70 |
+
/// <reference path="domain.d.ts" />
|
| 71 |
+
/// <reference path="events.d.ts" />
|
| 72 |
+
/// <reference path="fs.d.ts" />
|
| 73 |
+
/// <reference path="fs/promises.d.ts" />
|
| 74 |
+
/// <reference path="http.d.ts" />
|
| 75 |
+
/// <reference path="http2.d.ts" />
|
| 76 |
+
/// <reference path="https.d.ts" />
|
| 77 |
+
/// <reference path="inspector.d.ts" />
|
| 78 |
+
/// <reference path="inspector.generated.d.ts" />
|
| 79 |
+
/// <reference path="inspector/promises.d.ts" />
|
| 80 |
+
/// <reference path="module.d.ts" />
|
| 81 |
+
/// <reference path="net.d.ts" />
|
| 82 |
+
/// <reference path="os.d.ts" />
|
| 83 |
+
/// <reference path="path.d.ts" />
|
| 84 |
+
/// <reference path="path/posix.d.ts" />
|
| 85 |
+
/// <reference path="path/win32.d.ts" />
|
| 86 |
+
/// <reference path="perf_hooks.d.ts" />
|
| 87 |
+
/// <reference path="process.d.ts" />
|
| 88 |
+
/// <reference path="punycode.d.ts" />
|
| 89 |
+
/// <reference path="querystring.d.ts" />
|
| 90 |
+
/// <reference path="quic.d.ts" />
|
| 91 |
+
/// <reference path="readline.d.ts" />
|
| 92 |
+
/// <reference path="readline/promises.d.ts" />
|
| 93 |
+
/// <reference path="repl.d.ts" />
|
| 94 |
+
/// <reference path="sea.d.ts" />
|
| 95 |
+
/// <reference path="sqlite.d.ts" />
|
| 96 |
+
/// <reference path="stream.d.ts" />
|
| 97 |
+
/// <reference path="stream/consumers.d.ts" />
|
| 98 |
+
/// <reference path="stream/iter.d.ts" />
|
| 99 |
+
/// <reference path="stream/promises.d.ts" />
|
| 100 |
+
/// <reference path="stream/web.d.ts" />
|
| 101 |
+
/// <reference path="string_decoder.d.ts" />
|
| 102 |
+
/// <reference path="test.d.ts" />
|
| 103 |
+
/// <reference path="test/reporters.d.ts" />
|
| 104 |
+
/// <reference path="timers.d.ts" />
|
| 105 |
+
/// <reference path="timers/promises.d.ts" />
|
| 106 |
+
/// <reference path="tls.d.ts" />
|
| 107 |
+
/// <reference path="trace_events.d.ts" />
|
| 108 |
+
/// <reference path="tty.d.ts" />
|
| 109 |
+
/// <reference path="url.d.ts" />
|
| 110 |
+
/// <reference path="util.d.ts" />
|
| 111 |
+
/// <reference path="util/types.d.ts" />
|
| 112 |
+
/// <reference path="v8.d.ts" />
|
| 113 |
+
/// <reference path="vm.d.ts" />
|
| 114 |
+
/// <reference path="wasi.d.ts" />
|
| 115 |
+
/// <reference path="worker_threads.d.ts" />
|
| 116 |
+
/// <reference path="zlib.d.ts" />
|
| 117 |
+
/// <reference path="zlib/iter.d.ts" />
|
node_modules/@types/node/inspector.d.ts
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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8 inspector
|
| 5 |
+
* back-end and receiving message responses and notifications.
|
| 6 |
+
*/
|
| 7 |
+
class Session extends EventEmitter {
|
| 8 |
+
/**
|
| 9 |
+
* Create a new instance of the inspector.Session class.
|
| 10 |
+
* The inspector session needs to be connected through `session.connect()` before the messages can be dispatched to the inspector backend.
|
| 11 |
+
*/
|
| 12 |
+
constructor();
|
| 13 |
+
/**
|
| 14 |
+
* Connects a session to the inspector back-end.
|
| 15 |
+
*/
|
| 16 |
+
connect(): void;
|
| 17 |
+
/**
|
| 18 |
+
* Connects a session to the inspector back-end.
|
| 19 |
+
* An exception will be thrown if this API was not called on a Worker thread.
|
| 20 |
+
* @since v12.11.0
|
| 21 |
+
*/
|
| 22 |
+
connectToMainThread(): void;
|
| 23 |
+
/**
|
| 24 |
+
* Immediately close the session. All pending message callbacks will be called with an error.
|
| 25 |
+
* `session.connect()` will need to be called to be able to send messages again.
|
| 26 |
+
* Reconnected session will lose all inspector state, such as enabled agents or configured breakpoints.
|
| 27 |
+
*/
|
| 28 |
+
disconnect(): void;
|
| 29 |
+
}
|
| 30 |
+
/**
|
| 31 |
+
* Activate inspector on host and port. Equivalent to `node --inspect=[[host:]port]`, but can be done programmatically after node has
|
| 32 |
+
* started.
|
| 33 |
+
*
|
| 34 |
+
* If wait is `true`, will block until a client has connected to the inspect port
|
| 35 |
+
* and flow control has been passed to the debugger client.
|
| 36 |
+
*
|
| 37 |
+
* See the [security warning](https://nodejs.org/docs/latest-v25.x/api/cli.html#warning-binding-inspector-to-a-public-ipport-combination-is-insecure)
|
| 38 |
+
* regarding the `host` parameter usage.
|
| 39 |
+
* @param port Port to listen on for inspector connections. Defaults to what was specified on the CLI.
|
| 40 |
+
* @param host Host to listen on for inspector connections. Defaults to what was specified on the CLI.
|
| 41 |
+
* @param wait Block until a client has connected. Defaults to what was specified on the CLI.
|
| 42 |
+
* @returns Disposable that calls `inspector.close()`.
|
| 43 |
+
*/
|
| 44 |
+
function open(port?: number, host?: string, wait?: boolean): Disposable;
|
| 45 |
+
/**
|
| 46 |
+
* Deactivate the inspector. Blocks until there are no active connections.
|
| 47 |
+
*/
|
| 48 |
+
function close(): void;
|
| 49 |
+
/**
|
| 50 |
+
* Return the URL of the active inspector, or `undefined` if there is none.
|
| 51 |
+
*
|
| 52 |
+
* ```console
|
| 53 |
+
* $ node --inspect -p 'inspector.url()'
|
| 54 |
+
* Debugger listening on ws://127.0.0.1:9229/166e272e-7a30-4d09-97ce-f1c012b43c34
|
| 55 |
+
* For help, see: https://nodejs.org/en/docs/inspector
|
| 56 |
+
* ws://127.0.0.1:9229/166e272e-7a30-4d09-97ce-f1c012b43c34
|
| 57 |
+
*
|
| 58 |
+
* $ node --inspect=localhost:3000 -p 'inspector.url()'
|
| 59 |
+
* Debugger listening on ws://localhost:3000/51cf8d0e-3c36-4c59-8efd-54519839e56a
|
| 60 |
+
* For help, see: https://nodejs.org/en/docs/inspector
|
| 61 |
+
* ws://localhost:3000/51cf8d0e-3c36-4c59-8efd-54519839e56a
|
| 62 |
+
*
|
| 63 |
+
* $ node -p 'inspector.url()'
|
| 64 |
+
* undefined
|
| 65 |
+
* ```
|
| 66 |
+
*/
|
| 67 |
+
function url(): string | undefined;
|
| 68 |
+
/**
|
| 69 |
+
* Blocks until a client (existing or connected later) has sent `Runtime.runIfWaitingForDebugger` command.
|
| 70 |
+
*
|
| 71 |
+
* An exception will be thrown if there is no active inspector.
|
| 72 |
+
* @since v12.7.0
|
| 73 |
+
*/
|
| 74 |
+
function waitForDebugger(): void;
|
| 75 |
+
// These methods are exposed by the V8 inspector console API (inspector/v8-console.h).
|
| 76 |
+
// The method signatures differ from those of the Node.js console, and are deliberately
|
| 77 |
+
// typed permissively.
|
| 78 |
+
interface InspectorConsole {
|
| 79 |
+
debug(...data: any[]): void;
|
| 80 |
+
error(...data: any[]): void;
|
| 81 |
+
info(...data: any[]): void;
|
| 82 |
+
log(...data: any[]): void;
|
| 83 |
+
warn(...data: any[]): void;
|
| 84 |
+
dir(...data: any[]): void;
|
| 85 |
+
dirxml(...data: any[]): void;
|
| 86 |
+
table(...data: any[]): void;
|
| 87 |
+
trace(...data: any[]): void;
|
| 88 |
+
group(...data: any[]): void;
|
| 89 |
+
groupCollapsed(...data: any[]): void;
|
| 90 |
+
groupEnd(...data: any[]): void;
|
| 91 |
+
clear(...data: any[]): void;
|
| 92 |
+
count(label?: any): void;
|
| 93 |
+
countReset(label?: any): void;
|
| 94 |
+
assert(value?: any, ...data: any[]): void;
|
| 95 |
+
profile(label?: any): void;
|
| 96 |
+
profileEnd(label?: any): void;
|
| 97 |
+
time(label?: any): void;
|
| 98 |
+
timeLog(label?: any): void;
|
| 99 |
+
timeStamp(label?: any): void;
|
| 100 |
+
}
|
| 101 |
+
/**
|
| 102 |
+
* An object to send messages to the remote inspector console.
|
| 103 |
+
* @since v11.0.0
|
| 104 |
+
*/
|
| 105 |
+
const console: InspectorConsole;
|
| 106 |
+
// DevTools protocol event broadcast methods
|
| 107 |
+
namespace Network {
|
| 108 |
+
/**
|
| 109 |
+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
|
| 110 |
+
*
|
| 111 |
+
* Broadcasts the `Network.requestWillBeSent` event to connected frontends. This event indicates that
|
| 112 |
+
* the application is about to send an HTTP request.
|
| 113 |
+
* @since v22.6.0
|
| 114 |
+
*/
|
| 115 |
+
function requestWillBeSent(params: RequestWillBeSentEventDataType): void;
|
| 116 |
+
/**
|
| 117 |
+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
|
| 118 |
+
*
|
| 119 |
+
* Broadcasts the `Network.dataReceived` event to connected frontends, or buffers the data if
|
| 120 |
+
* `Network.streamResourceContent` command was not invoked for the given request yet.
|
| 121 |
+
*
|
| 122 |
+
* Also enables `Network.getResponseBody` command to retrieve the response data.
|
| 123 |
+
* @since v24.2.0
|
| 124 |
+
*/
|
| 125 |
+
function dataReceived(params: DataReceivedEventDataType): void;
|
| 126 |
+
/**
|
| 127 |
+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
|
| 128 |
+
*
|
| 129 |
+
* Enables `Network.getRequestPostData` command to retrieve the request data.
|
| 130 |
+
* @since v24.3.0
|
| 131 |
+
*/
|
| 132 |
+
function dataSent(params: unknown): void;
|
| 133 |
+
/**
|
| 134 |
+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
|
| 135 |
+
*
|
| 136 |
+
* Broadcasts the `Network.responseReceived` event to connected frontends. This event indicates that
|
| 137 |
+
* HTTP response is available.
|
| 138 |
+
* @since v22.6.0
|
| 139 |
+
*/
|
| 140 |
+
function responseReceived(params: ResponseReceivedEventDataType): void;
|
| 141 |
+
/**
|
| 142 |
+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
|
| 143 |
+
*
|
| 144 |
+
* Broadcasts the `Network.loadingFinished` event to connected frontends. This event indicates that
|
| 145 |
+
* HTTP request has finished loading.
|
| 146 |
+
* @since v22.6.0
|
| 147 |
+
*/
|
| 148 |
+
function loadingFinished(params: LoadingFinishedEventDataType): void;
|
| 149 |
+
/**
|
| 150 |
+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
|
| 151 |
+
*
|
| 152 |
+
* Broadcasts the `Network.loadingFailed` event to connected frontends. This event indicates that
|
| 153 |
+
* HTTP request has failed to load.
|
| 154 |
+
* @since v22.7.0
|
| 155 |
+
*/
|
| 156 |
+
function loadingFailed(params: LoadingFailedEventDataType): void;
|
| 157 |
+
/**
|
| 158 |
+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
|
| 159 |
+
*
|
| 160 |
+
* Broadcasts the `Network.webSocketCreated` event to connected frontends. This event indicates that
|
| 161 |
+
* a WebSocket connection has been initiated.
|
| 162 |
+
* @since v24.7.0
|
| 163 |
+
*/
|
| 164 |
+
function webSocketCreated(params: WebSocketCreatedEventDataType): void;
|
| 165 |
+
/**
|
| 166 |
+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
|
| 167 |
+
*
|
| 168 |
+
* Broadcasts the `Network.webSocketHandshakeResponseReceived` event to connected frontends.
|
| 169 |
+
* This event indicates that the WebSocket handshake response has been received.
|
| 170 |
+
* @since v24.7.0
|
| 171 |
+
*/
|
| 172 |
+
function webSocketHandshakeResponseReceived(params: WebSocketHandshakeResponseReceivedEventDataType): void;
|
| 173 |
+
/**
|
| 174 |
+
* This feature is only available with the `--experimental-network-inspection` flag enabled.
|
| 175 |
+
*
|
| 176 |
+
* Broadcasts the `Network.webSocketClosed` event to connected frontends.
|
| 177 |
+
* This event indicates that a WebSocket connection has been closed.
|
| 178 |
+
* @since v24.7.0
|
| 179 |
+
*/
|
| 180 |
+
function webSocketClosed(params: WebSocketClosedEventDataType): void;
|
| 181 |
+
}
|
| 182 |
+
namespace NetworkResources {
|
| 183 |
+
/**
|
| 184 |
+
* This feature is only available with the `--experimental-inspector-network-resource` flag enabled.
|
| 185 |
+
*
|
| 186 |
+
* The inspector.NetworkResources.put method is used to provide a response for a loadNetworkResource
|
| 187 |
+
* request issued via the Chrome DevTools Protocol (CDP).
|
| 188 |
+
* This is typically triggered when a source map is specified by URL, and a DevTools frontend—such as
|
| 189 |
+
* Chrome—requests the resource to retrieve the source map.
|
| 190 |
+
*
|
| 191 |
+
* This method allows developers to predefine the resource content to be served in response to such CDP requests.
|
| 192 |
+
*
|
| 193 |
+
* ```js
|
| 194 |
+
* const inspector = require('node:inspector');
|
| 195 |
+
* // By preemptively calling put to register the resource, a source map can be resolved when
|
| 196 |
+
* // a loadNetworkResource request is made from the frontend.
|
| 197 |
+
* async function setNetworkResources() {
|
| 198 |
+
* const mapUrl = 'http://localhost:3000/dist/app.js.map';
|
| 199 |
+
* const tsUrl = 'http://localhost:3000/src/app.ts';
|
| 200 |
+
* const distAppJsMap = await fetch(mapUrl).then((res) => res.text());
|
| 201 |
+
* const srcAppTs = await fetch(tsUrl).then((res) => res.text());
|
| 202 |
+
* inspector.NetworkResources.put(mapUrl, distAppJsMap);
|
| 203 |
+
* inspector.NetworkResources.put(tsUrl, srcAppTs);
|
| 204 |
+
* };
|
| 205 |
+
* setNetworkResources().then(() => {
|
| 206 |
+
* require('./dist/app');
|
| 207 |
+
* });
|
| 208 |
+
* ```
|
| 209 |
+
*
|
| 210 |
+
* For more details, see the official CDP documentation: [Network.loadNetworkResource](https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-loadNetworkResource)
|
| 211 |
+
* @since v24.5.0
|
| 212 |
+
* @experimental
|
| 213 |
+
*/
|
| 214 |
+
function put(url: string, data: string): void;
|
| 215 |
+
}
|
| 216 |
+
namespace DOMStorage {
|
| 217 |
+
/**
|
| 218 |
+
* This feature is only available with the
|
| 219 |
+
* `--experimental-storage-inspection` flag enabled.
|
| 220 |
+
*
|
| 221 |
+
* Broadcasts the `DOMStorage.domStorageItemAdded` event to connected frontends.
|
| 222 |
+
* This event indicates that a new item has been added to the storage.
|
| 223 |
+
* @since v25.5.0
|
| 224 |
+
*/
|
| 225 |
+
function domStorageItemAdded(params: DomStorageItemAddedEventDataType): void;
|
| 226 |
+
/**
|
| 227 |
+
* This feature is only available with the
|
| 228 |
+
* `--experimental-storage-inspection` flag enabled.
|
| 229 |
+
*
|
| 230 |
+
* Broadcasts the `DOMStorage.domStorageItemRemoved` event to connected frontends.
|
| 231 |
+
* This event indicates that an item has been removed from the storage.
|
| 232 |
+
* @since v25.5.0
|
| 233 |
+
*/
|
| 234 |
+
function domStorageItemRemoved(params: DomStorageItemRemovedEventDataType): void;
|
| 235 |
+
/**
|
| 236 |
+
* This feature is only available with the
|
| 237 |
+
* `--experimental-storage-inspection` flag enabled.
|
| 238 |
+
|
| 239 |
+
* Broadcasts the `DOMStorage.domStorageItemUpdated` event to connected frontends.
|
| 240 |
+
* This event indicates that a storage item has been updated.
|
| 241 |
+
* @since v25.5.0
|
| 242 |
+
*/
|
| 243 |
+
function domStorageItemUpdated(params: DomStorageItemUpdatedEventDataType): void;
|
| 244 |
+
/**
|
| 245 |
+
* This feature is only available with the
|
| 246 |
+
* `--experimental-storage-inspection` flag enabled.
|
| 247 |
+
*
|
| 248 |
+
* Broadcasts the `DOMStorage.domStorageItemsCleared` event to connected
|
| 249 |
+
* frontends. This event indicates that all items have been cleared from the
|
| 250 |
+
* storage.
|
| 251 |
+
* @since v25.5.0
|
| 252 |
+
*/
|
| 253 |
+
function domStorageItemsCleared(params: DomStorageItemsClearedEventDataType): void;
|
| 254 |
+
/**
|
| 255 |
+
* This feature is only available with the
|
| 256 |
+
* `--experimental-storage-inspection` flag enabled.
|
| 257 |
+
* @since v25.5.0
|
| 258 |
+
*/
|
| 259 |
+
function registerStorage(params: unknown): void;
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
declare module "inspector" {
|
| 263 |
+
export * from "node:inspector";
|
| 264 |
+
}
|
node_modules/@types/node/inspector.generated.d.ts
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
node_modules/@types/node/inspector/promises.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:inspector/promises" {
|
| 2 |
+
import { EventEmitter } from "node:events";
|
| 3 |
+
export { close, console, NetworkResources, open, url, waitForDebugger } from "node:inspector";
|
| 4 |
+
/**
|
| 5 |
+
* The `inspector.Session` is used for dispatching messages to the V8 inspector
|
| 6 |
+
* back-end and receiving message responses and notifications.
|
| 7 |
+
* @since v19.0.0
|
| 8 |
+
*/
|
| 9 |
+
export class Session extends EventEmitter {
|
| 10 |
+
/**
|
| 11 |
+
* Create a new instance of the inspector.Session class.
|
| 12 |
+
* The inspector session needs to be connected through `session.connect()` before the messages can be dispatched to the inspector backend.
|
| 13 |
+
*/
|
| 14 |
+
constructor();
|
| 15 |
+
/**
|
| 16 |
+
* Connects a session to the inspector back-end.
|
| 17 |
+
*/
|
| 18 |
+
connect(): void;
|
| 19 |
+
/**
|
| 20 |
+
* Connects a session to the inspector back-end.
|
| 21 |
+
* An exception will be thrown if this API was not called on a Worker thread.
|
| 22 |
+
* @since v12.11.0
|
| 23 |
+
*/
|
| 24 |
+
connectToMainThread(): void;
|
| 25 |
+
/**
|
| 26 |
+
* Immediately close the session. All pending message callbacks will be called with an error.
|
| 27 |
+
* `session.connect()` will need to be called to be able to send messages again.
|
| 28 |
+
* Reconnected session will lose all inspector state, such as enabled agents or configured breakpoints.
|
| 29 |
+
*/
|
| 30 |
+
disconnect(): void;
|
| 31 |
+
}
|
| 32 |
+
}
|
| 33 |
+
declare module "inspector/promises" {
|
| 34 |
+
export * from "node:inspector/promises";
|
| 35 |
+
}
|
node_modules/@types/node/module.d.ts
ADDED
|
@@ -0,0 +1,755 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 7 |
+
namespace Module {
|
| 8 |
+
export { Module };
|
| 9 |
+
}
|
| 10 |
+
namespace Module {
|
| 11 |
+
/**
|
| 12 |
+
* A list of the names of all modules provided by Node.js. Can be used to verify
|
| 13 |
+
* if a module is maintained by a third party or not.
|
| 14 |
+
*
|
| 15 |
+
* Note: the list doesn't contain prefix-only modules like `node:test`.
|
| 16 |
+
* @since v9.3.0, v8.10.0, v6.13.0
|
| 17 |
+
*/
|
| 18 |
+
const builtinModules: readonly string[];
|
| 19 |
+
/**
|
| 20 |
+
* @since v12.2.0
|
| 21 |
+
* @param path Filename to be used to construct the require
|
| 22 |
+
* function. Must be a file URL object, file URL string, or absolute path
|
| 23 |
+
* string.
|
| 24 |
+
*/
|
| 25 |
+
function createRequire(path: string | URL): NodeJS.Require;
|
| 26 |
+
namespace constants {
|
| 27 |
+
/**
|
| 28 |
+
* The following constants are returned as the `status` field in the object returned by
|
| 29 |
+
* {@link enableCompileCache} to indicate the result of the attempt to enable the
|
| 30 |
+
* [module compile cache](https://nodejs.org/docs/latest-v25.x/api/module.html#module-compile-cache).
|
| 31 |
+
* @since v22.8.0
|
| 32 |
+
*/
|
| 33 |
+
namespace compileCacheStatus {
|
| 34 |
+
/**
|
| 35 |
+
* Node.js has enabled the compile cache successfully. The directory used to store the
|
| 36 |
+
* compile cache will be returned in the `directory` field in the
|
| 37 |
+
* returned object.
|
| 38 |
+
*/
|
| 39 |
+
const ENABLED: number;
|
| 40 |
+
/**
|
| 41 |
+
* The compile cache has already been enabled before, either by a previous call to
|
| 42 |
+
* {@link enableCompileCache}, or by the `NODE_COMPILE_CACHE=dir`
|
| 43 |
+
* environment variable. The directory used to store the
|
| 44 |
+
* compile cache will be returned in the `directory` field in the
|
| 45 |
+
* returned object.
|
| 46 |
+
*/
|
| 47 |
+
const ALREADY_ENABLED: number;
|
| 48 |
+
/**
|
| 49 |
+
* Node.js fails to enable the compile cache. This can be caused by the lack of
|
| 50 |
+
* permission to use the specified directory, or various kinds of file system errors.
|
| 51 |
+
* The detail of the failure will be returned in the `message` field in the
|
| 52 |
+
* returned object.
|
| 53 |
+
*/
|
| 54 |
+
const FAILED: number;
|
| 55 |
+
/**
|
| 56 |
+
* Node.js cannot enable the compile cache because the environment variable
|
| 57 |
+
* `NODE_DISABLE_COMPILE_CACHE=1` has been set.
|
| 58 |
+
*/
|
| 59 |
+
const DISABLED: number;
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
interface EnableCompileCacheOptions {
|
| 63 |
+
/**
|
| 64 |
+
* Optional. Directory to store the compile cache. If not specified,
|
| 65 |
+
* the directory specified by the `NODE_COMPILE_CACHE=dir` environment variable
|
| 66 |
+
* will be used if it's set, or `path.join(os.tmpdir(), 'node-compile-cache')`
|
| 67 |
+
* otherwise.
|
| 68 |
+
* @since v25.0.0
|
| 69 |
+
*/
|
| 70 |
+
directory?: string | undefined;
|
| 71 |
+
/**
|
| 72 |
+
* Optional. If `true`, enables portable compile cache so that
|
| 73 |
+
* the cache can be reused even if the project directory is moved. This is a best-effort
|
| 74 |
+
* feature. If not specified, it will depend on whether the environment variable
|
| 75 |
+
* `NODE_COMPILE_CACHE_PORTABLE=1` is set.
|
| 76 |
+
* @since v25.0.0
|
| 77 |
+
*/
|
| 78 |
+
portable?: boolean | undefined;
|
| 79 |
+
}
|
| 80 |
+
interface EnableCompileCacheResult {
|
| 81 |
+
/**
|
| 82 |
+
* One of the {@link constants.compileCacheStatus}
|
| 83 |
+
*/
|
| 84 |
+
status: number;
|
| 85 |
+
/**
|
| 86 |
+
* If Node.js cannot enable the compile cache, this contains
|
| 87 |
+
* the error message. Only set if `status` is `module.constants.compileCacheStatus.FAILED`.
|
| 88 |
+
*/
|
| 89 |
+
message?: string;
|
| 90 |
+
/**
|
| 91 |
+
* If the compile cache is enabled, this contains the directory
|
| 92 |
+
* where the compile cache is stored. Only set if `status` is
|
| 93 |
+
* `module.constants.compileCacheStatus.ENABLED` or
|
| 94 |
+
* `module.constants.compileCacheStatus.ALREADY_ENABLED`.
|
| 95 |
+
*/
|
| 96 |
+
directory?: string;
|
| 97 |
+
}
|
| 98 |
+
/**
|
| 99 |
+
* Enable [module compile cache](https://nodejs.org/docs/latest-v25.x/api/module.html#module-compile-cache)
|
| 100 |
+
* in the current Node.js instance.
|
| 101 |
+
*
|
| 102 |
+
* For general use cases, it's recommended to call `module.enableCompileCache()` without
|
| 103 |
+
* specifying the `options.directory`, so that the directory can be overridden by the
|
| 104 |
+
* `NODE_COMPILE_CACHE` environment variable when necessary.
|
| 105 |
+
*
|
| 106 |
+
* Since compile cache is supposed to be a optimization that is not mission critical, this
|
| 107 |
+
* method is designed to not throw any exception when the compile cache cannot be enabled.
|
| 108 |
+
* Instead, it will return an object containing an error message in the `message` field to
|
| 109 |
+
* aid debugging. If compile cache is enabled successfully, the `directory` field in the
|
| 110 |
+
* returned object contains the path to the directory where the compile cache is stored. The
|
| 111 |
+
* `status` field in the returned object would be one of the `module.constants.compileCacheStatus`
|
| 112 |
+
* values to indicate the result of the attempt to enable the
|
| 113 |
+
* [module compile cache](https://nodejs.org/docs/latest-v25.x/api/module.html#module-compile-cache).
|
| 114 |
+
*
|
| 115 |
+
* This method only affects the current Node.js instance. To enable it in child worker threads,
|
| 116 |
+
* either call this method in child worker threads too, or set the
|
| 117 |
+
* `process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can
|
| 118 |
+
* be inherited into the child workers. The directory can be obtained either from the
|
| 119 |
+
* `directory` field returned by this method, or with {@link getCompileCacheDir}.
|
| 120 |
+
* @since v22.8.0
|
| 121 |
+
* @param options Optional. If a string is passed, it is considered to be `options.directory`.
|
| 122 |
+
*/
|
| 123 |
+
function enableCompileCache(options?: string | EnableCompileCacheOptions): EnableCompileCacheResult;
|
| 124 |
+
/**
|
| 125 |
+
* Flush the [module compile cache](https://nodejs.org/docs/latest-v25.x/api/module.html#module-compile-cache)
|
| 126 |
+
* accumulated from modules already loaded
|
| 127 |
+
* in the current Node.js instance to disk. This returns after all the flushing
|
| 128 |
+
* file system operations come to an end, no matter they succeed or not. If there
|
| 129 |
+
* are any errors, this will fail silently, since compile cache misses should not
|
| 130 |
+
* interfere with the actual operation of the application.
|
| 131 |
+
* @since v22.10.0
|
| 132 |
+
*/
|
| 133 |
+
function flushCompileCache(): void;
|
| 134 |
+
/**
|
| 135 |
+
* @since v22.8.0
|
| 136 |
+
* @return Path to the [module compile cache](https://nodejs.org/docs/latest-v25.x/api/module.html#module-compile-cache)
|
| 137 |
+
* directory if it is enabled, or `undefined` otherwise.
|
| 138 |
+
*/
|
| 139 |
+
function getCompileCacheDir(): string | undefined;
|
| 140 |
+
/**
|
| 141 |
+
* ```text
|
| 142 |
+
* /path/to/project
|
| 143 |
+
* ├ packages/
|
| 144 |
+
* ├ bar/
|
| 145 |
+
* ├ bar.js
|
| 146 |
+
* └ package.json // name = '@foo/bar'
|
| 147 |
+
* └ qux/
|
| 148 |
+
* ├ node_modules/
|
| 149 |
+
* └ some-package/
|
| 150 |
+
* └ package.json // name = 'some-package'
|
| 151 |
+
* ├ qux.js
|
| 152 |
+
* └ package.json // name = '@foo/qux'
|
| 153 |
+
* ├ main.js
|
| 154 |
+
* └ package.json // name = '@foo'
|
| 155 |
+
* ```
|
| 156 |
+
* ```js
|
| 157 |
+
* // /path/to/project/packages/bar/bar.js
|
| 158 |
+
* import { findPackageJSON } from 'node:module';
|
| 159 |
+
*
|
| 160 |
+
* findPackageJSON('..', import.meta.url);
|
| 161 |
+
* // '/path/to/project/package.json'
|
| 162 |
+
* // Same result when passing an absolute specifier instead:
|
| 163 |
+
* findPackageJSON(new URL('../', import.meta.url));
|
| 164 |
+
* findPackageJSON(import.meta.resolve('../'));
|
| 165 |
+
*
|
| 166 |
+
* findPackageJSON('some-package', import.meta.url);
|
| 167 |
+
* // '/path/to/project/packages/bar/node_modules/some-package/package.json'
|
| 168 |
+
* // When passing an absolute specifier, you might get a different result if the
|
| 169 |
+
* // resolved module is inside a subfolder that has nested `package.json`.
|
| 170 |
+
* findPackageJSON(import.meta.resolve('some-package'));
|
| 171 |
+
* // '/path/to/project/packages/bar/node_modules/some-package/some-subfolder/package.json'
|
| 172 |
+
*
|
| 173 |
+
* findPackageJSON('@foo/qux', import.meta.url);
|
| 174 |
+
* // '/path/to/project/packages/qux/package.json'
|
| 175 |
+
* ```
|
| 176 |
+
* @since v22.14.0
|
| 177 |
+
* @param specifier The specifier for the module whose `package.json` to
|
| 178 |
+
* retrieve. When passing a _bare specifier_, the `package.json` at the root of
|
| 179 |
+
* the package is returned. When passing a _relative specifier_ or an _absolute specifier_,
|
| 180 |
+
* the closest parent `package.json` is returned.
|
| 181 |
+
* @param base The absolute location (`file:` URL string or FS path) of the
|
| 182 |
+
* containing module. For CJS, use `__filename` (not `__dirname`!); for ESM, use
|
| 183 |
+
* `import.meta.url`. You do not need to pass it if `specifier` is an _absolute specifier_.
|
| 184 |
+
* @returns A path if the `package.json` is found. When `startLocation`
|
| 185 |
+
* is a package, the package's root `package.json`; when a relative or unresolved, the closest
|
| 186 |
+
* `package.json` to the `startLocation`.
|
| 187 |
+
*/
|
| 188 |
+
function findPackageJSON(specifier: string | URL, base?: string | URL): string | undefined;
|
| 189 |
+
/**
|
| 190 |
+
* @since v18.6.0, v16.17.0
|
| 191 |
+
*/
|
| 192 |
+
function isBuiltin(moduleName: string): boolean;
|
| 193 |
+
interface RegisterOptions<Data> {
|
| 194 |
+
/**
|
| 195 |
+
* If you want to resolve `specifier` relative to a
|
| 196 |
+
* base URL, such as `import.meta.url`, you can pass that URL here. This
|
| 197 |
+
* property is ignored if the `parentURL` is supplied as the second argument.
|
| 198 |
+
* @default 'data:'
|
| 199 |
+
*/
|
| 200 |
+
parentURL?: string | URL | undefined;
|
| 201 |
+
/**
|
| 202 |
+
* Any arbitrary, cloneable JavaScript value to pass into the
|
| 203 |
+
* {@link initialize} hook.
|
| 204 |
+
*/
|
| 205 |
+
data?: Data | undefined;
|
| 206 |
+
/**
|
| 207 |
+
* [Transferable objects](https://nodejs.org/docs/latest-v25.x/api/worker_threads.html#portpostmessagevalue-transferlist)
|
| 208 |
+
* to be passed into the `initialize` hook.
|
| 209 |
+
*/
|
| 210 |
+
transferList?: any[] | undefined;
|
| 211 |
+
}
|
| 212 |
+
/* eslint-disable @definitelytyped/no-unnecessary-generics */
|
| 213 |
+
/**
|
| 214 |
+
* Register a module that exports hooks that customize Node.js module
|
| 215 |
+
* resolution and loading behavior. See
|
| 216 |
+
* [Customization hooks](https://nodejs.org/docs/latest-v25.x/api/module.html#customization-hooks).
|
| 217 |
+
*
|
| 218 |
+
* This feature requires `--allow-worker` if used with the
|
| 219 |
+
* [Permission Model](https://nodejs.org/docs/latest-v25.x/api/permissions.html#permission-model).
|
| 220 |
+
* @since v20.6.0, v18.19.0
|
| 221 |
+
* @deprecated Use `module.registerHooks()` instead.
|
| 222 |
+
* @param specifier Customization hooks to be registered; this should be
|
| 223 |
+
* the same string that would be passed to `import()`, except that if it is
|
| 224 |
+
* relative, it is resolved relative to `parentURL`.
|
| 225 |
+
* @param parentURL f you want to resolve `specifier` relative to a base
|
| 226 |
+
* URL, such as `import.meta.url`, you can pass that URL here.
|
| 227 |
+
*/
|
| 228 |
+
function register<Data = any>(
|
| 229 |
+
specifier: string | URL,
|
| 230 |
+
parentURL?: string | URL,
|
| 231 |
+
options?: RegisterOptions<Data>,
|
| 232 |
+
): void;
|
| 233 |
+
function register<Data = any>(specifier: string | URL, options?: RegisterOptions<Data>): void;
|
| 234 |
+
interface RegisterHooksOptions {
|
| 235 |
+
/**
|
| 236 |
+
* See [load hook](https://nodejs.org/docs/latest-v25.x/api/module.html#loadurl-context-nextload).
|
| 237 |
+
* @default undefined
|
| 238 |
+
*/
|
| 239 |
+
load?: LoadHookSync | undefined;
|
| 240 |
+
/**
|
| 241 |
+
* See [resolve hook](https://nodejs.org/docs/latest-v25.x/api/module.html#resolvespecifier-context-nextresolve).
|
| 242 |
+
* @default undefined
|
| 243 |
+
*/
|
| 244 |
+
resolve?: ResolveHookSync | undefined;
|
| 245 |
+
}
|
| 246 |
+
interface ModuleHooks {
|
| 247 |
+
/**
|
| 248 |
+
* Deregister the hook instance.
|
| 249 |
+
*/
|
| 250 |
+
deregister(): void;
|
| 251 |
+
}
|
| 252 |
+
/**
|
| 253 |
+
* Register [hooks](https://nodejs.org/docs/latest-v25.x/api/module.html#customization-hooks)
|
| 254 |
+
* that customize Node.js module resolution and loading behavior.
|
| 255 |
+
* @since v22.15.0
|
| 256 |
+
* @experimental
|
| 257 |
+
*/
|
| 258 |
+
function registerHooks(options: RegisterHooksOptions): ModuleHooks;
|
| 259 |
+
interface StripTypeScriptTypesOptions {
|
| 260 |
+
/**
|
| 261 |
+
* Possible values are:
|
| 262 |
+
* * `'strip'` Only strip type annotations without performing the transformation of TypeScript features.
|
| 263 |
+
* * `'transform'` Strip type annotations and transform TypeScript features to JavaScript.
|
| 264 |
+
* @default 'strip'
|
| 265 |
+
*/
|
| 266 |
+
mode?: "strip" | "transform" | undefined;
|
| 267 |
+
/**
|
| 268 |
+
* Only when `mode` is `'transform'`, if `true`, a source map
|
| 269 |
+
* will be generated for the transformed code.
|
| 270 |
+
* @default false
|
| 271 |
+
*/
|
| 272 |
+
sourceMap?: boolean | undefined;
|
| 273 |
+
/**
|
| 274 |
+
* Specifies the source url used in the source map.
|
| 275 |
+
*/
|
| 276 |
+
sourceUrl?: string | undefined;
|
| 277 |
+
}
|
| 278 |
+
/**
|
| 279 |
+
* `module.stripTypeScriptTypes()` removes type annotations from TypeScript code. It
|
| 280 |
+
* can be used to strip type annotations from TypeScript code before running it
|
| 281 |
+
* with `vm.runInContext()` or `vm.compileFunction()`.
|
| 282 |
+
* By default, it will throw an error if the code contains TypeScript features
|
| 283 |
+
* that require transformation such as `Enums`,
|
| 284 |
+
* see [type-stripping](https://nodejs.org/docs/latest-v25.x/api/typescript.md#type-stripping) for more information.
|
| 285 |
+
* When mode is `'transform'`, it also transforms TypeScript features to JavaScript,
|
| 286 |
+
* see [transform TypeScript features](https://nodejs.org/docs/latest-v25.x/api/typescript.md#typescript-features) for more information.
|
| 287 |
+
* When mode is `'strip'`, source maps are not generated, because locations are preserved.
|
| 288 |
+
* If `sourceMap` is provided, when mode is `'strip'`, an error will be thrown.
|
| 289 |
+
*
|
| 290 |
+
* _WARNING_: The output of this function should not be considered stable across Node.js versions,
|
| 291 |
+
* due to changes in the TypeScript parser.
|
| 292 |
+
*
|
| 293 |
+
* ```js
|
| 294 |
+
* import { stripTypeScriptTypes } from 'node:module';
|
| 295 |
+
* const code = 'const a: number = 1;';
|
| 296 |
+
* const strippedCode = stripTypeScriptTypes(code);
|
| 297 |
+
* console.log(strippedCode);
|
| 298 |
+
* // Prints: const a = 1;
|
| 299 |
+
* ```
|
| 300 |
+
*
|
| 301 |
+
* If `sourceUrl` is provided, it will be used appended as a comment at the end of the output:
|
| 302 |
+
*
|
| 303 |
+
* ```js
|
| 304 |
+
* import { stripTypeScriptTypes } from 'node:module';
|
| 305 |
+
* const code = 'const a: number = 1;';
|
| 306 |
+
* const strippedCode = stripTypeScriptTypes(code, { mode: 'strip', sourceUrl: 'source.ts' });
|
| 307 |
+
* console.log(strippedCode);
|
| 308 |
+
* // Prints: const a = 1\n\n//# sourceURL=source.ts;
|
| 309 |
+
* ```
|
| 310 |
+
*
|
| 311 |
+
* When `mode` is `'transform'`, the code is transformed to JavaScript:
|
| 312 |
+
*
|
| 313 |
+
* ```js
|
| 314 |
+
* import { stripTypeScriptTypes } from 'node:module';
|
| 315 |
+
* const code = `
|
| 316 |
+
* namespace MathUtil {
|
| 317 |
+
* export const add = (a: number, b: number) => a + b;
|
| 318 |
+
* }`;
|
| 319 |
+
* const strippedCode = stripTypeScriptTypes(code, { mode: 'transform', sourceMap: true });
|
| 320 |
+
* console.log(strippedCode);
|
| 321 |
+
* // Prints:
|
| 322 |
+
* // var MathUtil;
|
| 323 |
+
* // (function(MathUtil) {
|
| 324 |
+
* // MathUtil.add = (a, b)=>a + b;
|
| 325 |
+
* // })(MathUtil || (MathUtil = {}));
|
| 326 |
+
* // # sourceMappingURL=data:application/json;base64, ...
|
| 327 |
+
* ```
|
| 328 |
+
* @since v22.13.0
|
| 329 |
+
* @param code The code to strip type annotations from.
|
| 330 |
+
* @returns The code with type annotations stripped.
|
| 331 |
+
*/
|
| 332 |
+
function stripTypeScriptTypes(code: string, options?: StripTypeScriptTypesOptions): string;
|
| 333 |
+
/* eslint-enable @definitelytyped/no-unnecessary-generics */
|
| 334 |
+
/**
|
| 335 |
+
* The `module.syncBuiltinESMExports()` method updates all the live bindings for
|
| 336 |
+
* builtin `ES Modules` to match the properties of the `CommonJS` exports. It
|
| 337 |
+
* does not add or remove exported names from the `ES Modules`.
|
| 338 |
+
*
|
| 339 |
+
* ```js
|
| 340 |
+
* import fs from 'node:fs';
|
| 341 |
+
* import assert from 'node:assert';
|
| 342 |
+
* import { syncBuiltinESMExports } from 'node:module';
|
| 343 |
+
*
|
| 344 |
+
* fs.readFile = newAPI;
|
| 345 |
+
*
|
| 346 |
+
* delete fs.readFileSync;
|
| 347 |
+
*
|
| 348 |
+
* function newAPI() {
|
| 349 |
+
* // ...
|
| 350 |
+
* }
|
| 351 |
+
*
|
| 352 |
+
* fs.newAPI = newAPI;
|
| 353 |
+
*
|
| 354 |
+
* syncBuiltinESMExports();
|
| 355 |
+
*
|
| 356 |
+
* import('node:fs').then((esmFS) => {
|
| 357 |
+
* // It syncs the existing readFile property with the new value
|
| 358 |
+
* assert.strictEqual(esmFS.readFile, newAPI);
|
| 359 |
+
* // readFileSync has been deleted from the required fs
|
| 360 |
+
* assert.strictEqual('readFileSync' in fs, false);
|
| 361 |
+
* // syncBuiltinESMExports() does not remove readFileSync from esmFS
|
| 362 |
+
* assert.strictEqual('readFileSync' in esmFS, true);
|
| 363 |
+
* // syncBuiltinESMExports() does not add names
|
| 364 |
+
* assert.strictEqual(esmFS.newAPI, undefined);
|
| 365 |
+
* });
|
| 366 |
+
* ```
|
| 367 |
+
* @since v12.12.0
|
| 368 |
+
*/
|
| 369 |
+
function syncBuiltinESMExports(): void;
|
| 370 |
+
interface ImportAttributes extends NodeJS.Dict<string> {
|
| 371 |
+
type?: string | undefined;
|
| 372 |
+
}
|
| 373 |
+
type ImportPhase = "source" | "evaluation";
|
| 374 |
+
type ModuleFormat =
|
| 375 |
+
| "addon"
|
| 376 |
+
| "builtin"
|
| 377 |
+
| "commonjs"
|
| 378 |
+
| "commonjs-typescript"
|
| 379 |
+
| "json"
|
| 380 |
+
| "module"
|
| 381 |
+
| "module-typescript"
|
| 382 |
+
| "wasm";
|
| 383 |
+
type ModuleSource = string | ArrayBuffer | NodeJS.TypedArray;
|
| 384 |
+
type InitializeHook<Data = any> = (data: Data) => void | Promise<void>;
|
| 385 |
+
interface ResolveHookContext {
|
| 386 |
+
conditions: string[];
|
| 387 |
+
importAttributes: ImportAttributes;
|
| 388 |
+
parentURL: string | undefined;
|
| 389 |
+
}
|
| 390 |
+
interface ResolveFnOutput {
|
| 391 |
+
format?: string | null | undefined;
|
| 392 |
+
importAttributes?: ImportAttributes | undefined;
|
| 393 |
+
shortCircuit?: boolean | undefined;
|
| 394 |
+
url: string;
|
| 395 |
+
}
|
| 396 |
+
type ResolveHook = (
|
| 397 |
+
specifier: string,
|
| 398 |
+
context: ResolveHookContext,
|
| 399 |
+
nextResolve: (
|
| 400 |
+
specifier: string,
|
| 401 |
+
context?: Partial<ResolveHookContext>,
|
| 402 |
+
) => ResolveFnOutput | Promise<ResolveFnOutput>,
|
| 403 |
+
) => ResolveFnOutput | Promise<ResolveFnOutput>;
|
| 404 |
+
type ResolveHookSync = (
|
| 405 |
+
specifier: string,
|
| 406 |
+
context: ResolveHookContext,
|
| 407 |
+
nextResolve: (
|
| 408 |
+
specifier: string,
|
| 409 |
+
context?: Partial<ResolveHookContext>,
|
| 410 |
+
) => ResolveFnOutput,
|
| 411 |
+
) => ResolveFnOutput;
|
| 412 |
+
interface LoadHookContext {
|
| 413 |
+
conditions: string[];
|
| 414 |
+
format: string | null | undefined;
|
| 415 |
+
importAttributes: ImportAttributes;
|
| 416 |
+
}
|
| 417 |
+
interface LoadFnOutput {
|
| 418 |
+
format: string | null | undefined;
|
| 419 |
+
shortCircuit?: boolean | undefined;
|
| 420 |
+
source?: ModuleSource | undefined;
|
| 421 |
+
}
|
| 422 |
+
type LoadHook = (
|
| 423 |
+
url: string,
|
| 424 |
+
context: LoadHookContext,
|
| 425 |
+
nextLoad: (
|
| 426 |
+
url: string,
|
| 427 |
+
context?: Partial<LoadHookContext>,
|
| 428 |
+
) => LoadFnOutput | Promise<LoadFnOutput>,
|
| 429 |
+
) => LoadFnOutput | Promise<LoadFnOutput>;
|
| 430 |
+
type LoadHookSync = (
|
| 431 |
+
url: string,
|
| 432 |
+
context: LoadHookContext,
|
| 433 |
+
nextLoad: (
|
| 434 |
+
url: string,
|
| 435 |
+
context?: Partial<LoadHookContext>,
|
| 436 |
+
) => LoadFnOutput,
|
| 437 |
+
) => LoadFnOutput;
|
| 438 |
+
interface SourceMapsSupport {
|
| 439 |
+
/**
|
| 440 |
+
* If the source maps support is enabled
|
| 441 |
+
*/
|
| 442 |
+
enabled: boolean;
|
| 443 |
+
/**
|
| 444 |
+
* If the support is enabled for files in `node_modules`.
|
| 445 |
+
*/
|
| 446 |
+
nodeModules: boolean;
|
| 447 |
+
/**
|
| 448 |
+
* If the support is enabled for generated code from `eval` or `new Function`.
|
| 449 |
+
*/
|
| 450 |
+
generatedCode: boolean;
|
| 451 |
+
}
|
| 452 |
+
/**
|
| 453 |
+
* This method returns whether the [Source Map v3](https://tc39.es/ecma426/) support for stack
|
| 454 |
+
* traces is enabled.
|
| 455 |
+
* @since v23.7.0, v22.14.0
|
| 456 |
+
*/
|
| 457 |
+
function getSourceMapsSupport(): SourceMapsSupport;
|
| 458 |
+
/**
|
| 459 |
+
* `path` is the resolved path for the file for which a corresponding source map
|
| 460 |
+
* should be fetched.
|
| 461 |
+
* @since v13.7.0, v12.17.0
|
| 462 |
+
* @return Returns `module.SourceMap` if a source map is found, `undefined` otherwise.
|
| 463 |
+
*/
|
| 464 |
+
function findSourceMap(path: string): SourceMap | undefined;
|
| 465 |
+
interface SetSourceMapsSupportOptions {
|
| 466 |
+
/**
|
| 467 |
+
* If enabling the support for files in `node_modules`.
|
| 468 |
+
* @default false
|
| 469 |
+
*/
|
| 470 |
+
nodeModules?: boolean | undefined;
|
| 471 |
+
/**
|
| 472 |
+
* If enabling the support for generated code from `eval` or `new Function`.
|
| 473 |
+
* @default false
|
| 474 |
+
*/
|
| 475 |
+
generatedCode?: boolean | undefined;
|
| 476 |
+
}
|
| 477 |
+
/**
|
| 478 |
+
* This function enables or disables the [Source Map v3](https://tc39.es/ecma426/) support for
|
| 479 |
+
* stack traces.
|
| 480 |
+
*
|
| 481 |
+
* It provides same features as launching Node.js process with commandline options
|
| 482 |
+
* `--enable-source-maps`, with additional options to alter the support for files
|
| 483 |
+
* in `node_modules` or generated codes.
|
| 484 |
+
*
|
| 485 |
+
* Only source maps in JavaScript files that are loaded after source maps has been
|
| 486 |
+
* enabled will be parsed and loaded. Preferably, use the commandline options
|
| 487 |
+
* `--enable-source-maps` to avoid losing track of source maps of modules loaded
|
| 488 |
+
* before this API call.
|
| 489 |
+
* @since v23.7.0, v22.14.0
|
| 490 |
+
*/
|
| 491 |
+
function setSourceMapsSupport(enabled: boolean, options?: SetSourceMapsSupportOptions): void;
|
| 492 |
+
interface SourceMapConstructorOptions {
|
| 493 |
+
/**
|
| 494 |
+
* @since v21.0.0, v20.5.0
|
| 495 |
+
*/
|
| 496 |
+
lineLengths?: readonly number[] | undefined;
|
| 497 |
+
}
|
| 498 |
+
interface SourceMapPayload {
|
| 499 |
+
file: string;
|
| 500 |
+
version: number;
|
| 501 |
+
sources: string[];
|
| 502 |
+
sourcesContent: string[];
|
| 503 |
+
names: string[];
|
| 504 |
+
mappings: string;
|
| 505 |
+
sourceRoot: string;
|
| 506 |
+
}
|
| 507 |
+
interface SourceMapping {
|
| 508 |
+
generatedLine: number;
|
| 509 |
+
generatedColumn: number;
|
| 510 |
+
originalSource: string;
|
| 511 |
+
originalLine: number;
|
| 512 |
+
originalColumn: number;
|
| 513 |
+
}
|
| 514 |
+
interface SourceOrigin {
|
| 515 |
+
/**
|
| 516 |
+
* The name of the range in the source map, if one was provided
|
| 517 |
+
*/
|
| 518 |
+
name: string | undefined;
|
| 519 |
+
/**
|
| 520 |
+
* The file name of the original source, as reported in the SourceMap
|
| 521 |
+
*/
|
| 522 |
+
fileName: string;
|
| 523 |
+
/**
|
| 524 |
+
* The 1-indexed lineNumber of the corresponding call site in the original source
|
| 525 |
+
*/
|
| 526 |
+
lineNumber: number;
|
| 527 |
+
/**
|
| 528 |
+
* The 1-indexed columnNumber of the corresponding call site in the original source
|
| 529 |
+
*/
|
| 530 |
+
columnNumber: number;
|
| 531 |
+
}
|
| 532 |
+
/**
|
| 533 |
+
* @since v13.7.0, v12.17.0
|
| 534 |
+
*/
|
| 535 |
+
class SourceMap {
|
| 536 |
+
constructor(payload: SourceMapPayload, options?: SourceMapConstructorOptions);
|
| 537 |
+
/**
|
| 538 |
+
* Getter for the payload used to construct the `SourceMap` instance.
|
| 539 |
+
*/
|
| 540 |
+
readonly payload: SourceMapPayload;
|
| 541 |
+
/**
|
| 542 |
+
* Given a line offset and column offset in the generated source
|
| 543 |
+
* file, returns an object representing the SourceMap range in the
|
| 544 |
+
* original file if found, or an empty object if not.
|
| 545 |
+
*
|
| 546 |
+
* The object returned contains the following keys:
|
| 547 |
+
*
|
| 548 |
+
* The returned value represents the raw range as it appears in the
|
| 549 |
+
* SourceMap, based on zero-indexed offsets, _not_ 1-indexed line and
|
| 550 |
+
* column numbers as they appear in Error messages and CallSite
|
| 551 |
+
* objects.
|
| 552 |
+
*
|
| 553 |
+
* To get the corresponding 1-indexed line and column numbers from a
|
| 554 |
+
* lineNumber and columnNumber as they are reported by Error stacks
|
| 555 |
+
* and CallSite objects, use `sourceMap.findOrigin(lineNumber, columnNumber)`
|
| 556 |
+
* @param lineOffset The zero-indexed line number offset in the generated source
|
| 557 |
+
* @param columnOffset The zero-indexed column number offset in the generated source
|
| 558 |
+
*/
|
| 559 |
+
findEntry(lineOffset: number, columnOffset: number): SourceMapping | {};
|
| 560 |
+
/**
|
| 561 |
+
* Given a 1-indexed `lineNumber` and `columnNumber` from a call site in the generated source,
|
| 562 |
+
* find the corresponding call site location in the original source.
|
| 563 |
+
*
|
| 564 |
+
* If the `lineNumber` and `columnNumber` provided are not found in any source map,
|
| 565 |
+
* then an empty object is returned.
|
| 566 |
+
* @param lineNumber The 1-indexed line number of the call site in the generated source
|
| 567 |
+
* @param columnNumber The 1-indexed column number of the call site in the generated source
|
| 568 |
+
*/
|
| 569 |
+
findOrigin(lineNumber: number, columnNumber: number): SourceOrigin | {};
|
| 570 |
+
}
|
| 571 |
+
function runMain(main?: string): void;
|
| 572 |
+
function wrap(script: string): string;
|
| 573 |
+
}
|
| 574 |
+
global {
|
| 575 |
+
namespace NodeJS {
|
| 576 |
+
interface Module {
|
| 577 |
+
/**
|
| 578 |
+
* The module objects required for the first time by this one.
|
| 579 |
+
* @since v0.1.16
|
| 580 |
+
*/
|
| 581 |
+
children: Module[];
|
| 582 |
+
/**
|
| 583 |
+
* The `module.exports` object is created by the `Module` system. Sometimes this is
|
| 584 |
+
* not acceptable; many want their module to be an instance of some class. To do
|
| 585 |
+
* this, assign the desired export object to `module.exports`.
|
| 586 |
+
* @since v0.1.16
|
| 587 |
+
*/
|
| 588 |
+
exports: any;
|
| 589 |
+
/**
|
| 590 |
+
* The fully resolved filename of the module.
|
| 591 |
+
* @since v0.1.16
|
| 592 |
+
*/
|
| 593 |
+
filename: string;
|
| 594 |
+
/**
|
| 595 |
+
* The identifier for the module. Typically this is the fully resolved
|
| 596 |
+
* filename.
|
| 597 |
+
* @since v0.1.16
|
| 598 |
+
*/
|
| 599 |
+
id: string;
|
| 600 |
+
/**
|
| 601 |
+
* `true` if the module is running during the Node.js preload
|
| 602 |
+
* phase.
|
| 603 |
+
* @since v15.4.0, v14.17.0
|
| 604 |
+
*/
|
| 605 |
+
isPreloading: boolean;
|
| 606 |
+
/**
|
| 607 |
+
* Whether or not the module is done loading, or is in the process of
|
| 608 |
+
* loading.
|
| 609 |
+
* @since v0.1.16
|
| 610 |
+
*/
|
| 611 |
+
loaded: boolean;
|
| 612 |
+
/**
|
| 613 |
+
* The module that first required this one, or `null` if the current module is the
|
| 614 |
+
* entry point of the current process, or `undefined` if the module was loaded by
|
| 615 |
+
* something that is not a CommonJS module (e.g. REPL or `import`).
|
| 616 |
+
* @since v0.1.16
|
| 617 |
+
* @deprecated Please use `require.main` and `module.children` instead.
|
| 618 |
+
*/
|
| 619 |
+
parent: Module | null | undefined;
|
| 620 |
+
/**
|
| 621 |
+
* The directory name of the module. This is usually the same as the
|
| 622 |
+
* `path.dirname()` of the `module.id`.
|
| 623 |
+
* @since v11.14.0
|
| 624 |
+
*/
|
| 625 |
+
path: string;
|
| 626 |
+
/**
|
| 627 |
+
* The search paths for the module.
|
| 628 |
+
* @since v0.4.0
|
| 629 |
+
*/
|
| 630 |
+
paths: string[];
|
| 631 |
+
/**
|
| 632 |
+
* The `module.require()` method provides a way to load a module as if
|
| 633 |
+
* `require()` was called from the original module.
|
| 634 |
+
* @since v0.5.1
|
| 635 |
+
*/
|
| 636 |
+
require(id: string): any;
|
| 637 |
+
}
|
| 638 |
+
interface Require {
|
| 639 |
+
/**
|
| 640 |
+
* Used to import modules, `JSON`, and local files.
|
| 641 |
+
* @since v0.1.13
|
| 642 |
+
*/
|
| 643 |
+
(id: string): any;
|
| 644 |
+
/**
|
| 645 |
+
* Modules are cached in this object when they are required. By deleting a key
|
| 646 |
+
* value from this object, the next `require` will reload the module.
|
| 647 |
+
* This does not apply to
|
| 648 |
+
* [native addons](https://nodejs.org/docs/latest-v25.x/api/addons.html),
|
| 649 |
+
* for which reloading will result in an error.
|
| 650 |
+
* @since v0.3.0
|
| 651 |
+
*/
|
| 652 |
+
cache: Dict<Module>;
|
| 653 |
+
/**
|
| 654 |
+
* Instruct `require` on how to handle certain file extensions.
|
| 655 |
+
* @since v0.3.0
|
| 656 |
+
* @deprecated
|
| 657 |
+
*/
|
| 658 |
+
extensions: RequireExtensions;
|
| 659 |
+
/**
|
| 660 |
+
* The `Module` object representing the entry script loaded when the Node.js
|
| 661 |
+
* process launched, or `undefined` if the entry point of the program is not a
|
| 662 |
+
* CommonJS module.
|
| 663 |
+
* @since v0.1.17
|
| 664 |
+
*/
|
| 665 |
+
main: Module | undefined;
|
| 666 |
+
/**
|
| 667 |
+
* @since v0.3.0
|
| 668 |
+
*/
|
| 669 |
+
resolve: RequireResolve;
|
| 670 |
+
}
|
| 671 |
+
/** @deprecated */
|
| 672 |
+
interface RequireExtensions extends Dict<(module: Module, filename: string) => any> {
|
| 673 |
+
".js": (module: Module, filename: string) => any;
|
| 674 |
+
".json": (module: Module, filename: string) => any;
|
| 675 |
+
".node": (module: Module, filename: string) => any;
|
| 676 |
+
}
|
| 677 |
+
interface RequireResolveOptions {
|
| 678 |
+
/**
|
| 679 |
+
* Paths to resolve module location from. If present, these
|
| 680 |
+
* paths are used instead of the default resolution paths, with the exception
|
| 681 |
+
* of
|
| 682 |
+
* [GLOBAL\_FOLDERS](https://nodejs.org/docs/latest-v25.x/api/modules.html#loading-from-the-global-folders)
|
| 683 |
+
* like `$HOME/.node_modules`, which are
|
| 684 |
+
* always included. Each of these paths is used as a starting point for
|
| 685 |
+
* the module resolution algorithm, meaning that the `node_modules` hierarchy
|
| 686 |
+
* is checked from this location.
|
| 687 |
+
* @since v8.9.0
|
| 688 |
+
*/
|
| 689 |
+
paths?: string[] | undefined;
|
| 690 |
+
}
|
| 691 |
+
interface RequireResolve {
|
| 692 |
+
/**
|
| 693 |
+
* Use the internal `require()` machinery to look up the location of a module,
|
| 694 |
+
* but rather than loading the module, just return the resolved filename.
|
| 695 |
+
*
|
| 696 |
+
* If the module can not be found, a `MODULE_NOT_FOUND` error is thrown.
|
| 697 |
+
* @since v0.3.0
|
| 698 |
+
* @param request The module path to resolve.
|
| 699 |
+
*/
|
| 700 |
+
(request: string, options?: RequireResolveOptions): string;
|
| 701 |
+
/**
|
| 702 |
+
* Returns an array containing the paths searched during resolution of `request` or
|
| 703 |
+
* `null` if the `request` string references a core module, for example `http` or
|
| 704 |
+
* `fs`.
|
| 705 |
+
* @since v8.9.0
|
| 706 |
+
* @param request The module path whose lookup paths are being retrieved.
|
| 707 |
+
*/
|
| 708 |
+
paths(request: string): string[] | null;
|
| 709 |
+
}
|
| 710 |
+
}
|
| 711 |
+
/**
|
| 712 |
+
* The directory name of the current module. This is the same as the
|
| 713 |
+
* `path.dirname()` of the `__filename`.
|
| 714 |
+
* @since v0.1.27
|
| 715 |
+
*/
|
| 716 |
+
var __dirname: string;
|
| 717 |
+
/**
|
| 718 |
+
* The file name of the current module. This is the current module file's absolute
|
| 719 |
+
* path with symlinks resolved.
|
| 720 |
+
*
|
| 721 |
+
* For a main program this is not necessarily the same as the file name used in the
|
| 722 |
+
* command line.
|
| 723 |
+
* @since v0.0.1
|
| 724 |
+
*/
|
| 725 |
+
var __filename: string;
|
| 726 |
+
/**
|
| 727 |
+
* The `exports` variable is available within a module's file-level scope, and is
|
| 728 |
+
* assigned the value of `module.exports` before the module is evaluated.
|
| 729 |
+
* @since v0.1.16
|
| 730 |
+
*/
|
| 731 |
+
var exports: NodeJS.Module["exports"];
|
| 732 |
+
/**
|
| 733 |
+
* A reference to the current module.
|
| 734 |
+
* @since v0.1.16
|
| 735 |
+
*/
|
| 736 |
+
var module: NodeJS.Module;
|
| 737 |
+
/**
|
| 738 |
+
* @since v0.1.13
|
| 739 |
+
*/
|
| 740 |
+
var require: NodeJS.Require;
|
| 741 |
+
// Global-scope aliases for backwards compatibility with @types/node <13.0.x
|
| 742 |
+
// TODO: consider removing in a future major version update
|
| 743 |
+
/** @deprecated Use `NodeJS.Module` instead. */
|
| 744 |
+
interface NodeModule extends NodeJS.Module {}
|
| 745 |
+
/** @deprecated Use `NodeJS.Require` instead. */
|
| 746 |
+
interface NodeRequire extends NodeJS.Require {}
|
| 747 |
+
/** @deprecated Use `NodeJS.RequireResolve` instead. */
|
| 748 |
+
interface RequireResolve extends NodeJS.RequireResolve {}
|
| 749 |
+
}
|
| 750 |
+
export = Module;
|
| 751 |
+
}
|
| 752 |
+
declare module "module" {
|
| 753 |
+
import module = require("node:module");
|
| 754 |
+
export = module;
|
| 755 |
+
}
|
node_modules/@types/node/net.d.ts
ADDED
|
@@ -0,0 +1,970 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ventEmitter, InternalEventEmitter } from "node:events";
|
| 5 |
+
import * as stream from "node:stream";
|
| 6 |
+
type LookupFunction = (
|
| 7 |
+
hostname: string,
|
| 8 |
+
options: dns.LookupOptions,
|
| 9 |
+
callback: (err: NodeJS.ErrnoException | null, address: string | dns.LookupAddress[], family?: number) => void,
|
| 10 |
+
) => void;
|
| 11 |
+
interface AddressInfo {
|
| 12 |
+
address: string;
|
| 13 |
+
family: string;
|
| 14 |
+
port: number;
|
| 15 |
+
}
|
| 16 |
+
interface SocketConstructorOpts {
|
| 17 |
+
fd?: number | undefined;
|
| 18 |
+
allowHalfOpen?: boolean | undefined;
|
| 19 |
+
onread?: OnReadOpts | undefined;
|
| 20 |
+
readable?: boolean | undefined;
|
| 21 |
+
writable?: boolean | undefined;
|
| 22 |
+
signal?: AbortSignal | undefined;
|
| 23 |
+
noDelay?: boolean | undefined;
|
| 24 |
+
keepAlive?: boolean | undefined;
|
| 25 |
+
keepAliveInitialDelay?: number | undefined;
|
| 26 |
+
blockList?: BlockList | undefined;
|
| 27 |
+
typeOfService?: number | undefined;
|
| 28 |
+
}
|
| 29 |
+
interface OnReadOpts {
|
| 30 |
+
buffer: Uint8Array | (() => Uint8Array);
|
| 31 |
+
/**
|
| 32 |
+
* This function is called for every chunk of incoming data.
|
| 33 |
+
* Two arguments are passed to it: the number of bytes written to `buffer` and a reference to `buffer`.
|
| 34 |
+
* Return `false` from this function to implicitly `pause()` the socket.
|
| 35 |
+
*/
|
| 36 |
+
callback(bytesWritten: number, buffer: Uint8Array): boolean;
|
| 37 |
+
}
|
| 38 |
+
interface TcpSocketConnectOpts {
|
| 39 |
+
port: number;
|
| 40 |
+
host?: string | undefined;
|
| 41 |
+
localAddress?: string | undefined;
|
| 42 |
+
localPort?: number | undefined;
|
| 43 |
+
hints?: number | undefined;
|
| 44 |
+
family?: number | undefined;
|
| 45 |
+
lookup?: LookupFunction | undefined;
|
| 46 |
+
/**
|
| 47 |
+
* @since v18.13.0
|
| 48 |
+
*/
|
| 49 |
+
autoSelectFamily?: boolean | undefined;
|
| 50 |
+
/**
|
| 51 |
+
* @since v18.13.0
|
| 52 |
+
*/
|
| 53 |
+
autoSelectFamilyAttemptTimeout?: number | undefined;
|
| 54 |
+
}
|
| 55 |
+
interface IpcSocketConnectOpts {
|
| 56 |
+
path: string;
|
| 57 |
+
}
|
| 58 |
+
type SocketConnectOpts = TcpSocketConnectOpts | IpcSocketConnectOpts;
|
| 59 |
+
type SocketReadyState = "opening" | "open" | "readOnly" | "writeOnly" | "closed";
|
| 60 |
+
interface SocketEventMap extends Omit<stream.DuplexEventMap, "close"> {
|
| 61 |
+
"close": [hadError: boolean];
|
| 62 |
+
"connect": [];
|
| 63 |
+
"connectionAttempt": [ip: string, port: number, family: number];
|
| 64 |
+
"connectionAttemptFailed": [ip: string, port: number, family: number, error: Error];
|
| 65 |
+
"connectionAttemptTimeout": [ip: string, port: number, family: number];
|
| 66 |
+
"data": [data: string | NonSharedBuffer];
|
| 67 |
+
"lookup": [err: Error | null, address: string, family: number | null, host: string];
|
| 68 |
+
"ready": [];
|
| 69 |
+
"timeout": [];
|
| 70 |
+
}
|
| 71 |
+
/**
|
| 72 |
+
* This class is an abstraction of a TCP socket or a streaming `IPC` endpoint
|
| 73 |
+
* (uses named pipes on Windows, and Unix domain sockets otherwise). It is also
|
| 74 |
+
* an `EventEmitter`.
|
| 75 |
+
*
|
| 76 |
+
* A `net.Socket` can be created by the user and used directly to interact with
|
| 77 |
+
* a server. For example, it is returned by {@link createConnection},
|
| 78 |
+
* so the user can use it to talk to the server.
|
| 79 |
+
*
|
| 80 |
+
* It can also be created by Node.js and passed to the user when a connection
|
| 81 |
+
* is received. For example, it is passed to the listeners of a `'connection'` event emitted on a {@link Server}, so the user can use
|
| 82 |
+
* it to interact with the client.
|
| 83 |
+
* @since v0.3.4
|
| 84 |
+
*/
|
| 85 |
+
class Socket extends stream.Duplex {
|
| 86 |
+
constructor(options?: SocketConstructorOpts);
|
| 87 |
+
/**
|
| 88 |
+
* Destroys the socket after all data is written. If the `finish` event was already emitted the socket is destroyed immediately.
|
| 89 |
+
* If the socket is still writable it implicitly calls `socket.end()`.
|
| 90 |
+
* @since v0.3.4
|
| 91 |
+
*/
|
| 92 |
+
destroySoon(): void;
|
| 93 |
+
/**
|
| 94 |
+
* Sends data on the socket. The second parameter specifies the encoding in the
|
| 95 |
+
* case of a string. It defaults to UTF8 encoding.
|
| 96 |
+
*
|
| 97 |
+
* Returns `true` if the entire data was flushed successfully to the kernel
|
| 98 |
+
* 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.
|
| 99 |
+
*
|
| 100 |
+
* The optional `callback` parameter will be executed when the data is finally
|
| 101 |
+
* written out, which may not be immediately.
|
| 102 |
+
*
|
| 103 |
+
* See `Writable` stream `write()` method for more
|
| 104 |
+
* information.
|
| 105 |
+
* @since v0.1.90
|
| 106 |
+
*/
|
| 107 |
+
write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
|
| 108 |
+
/**
|
| 109 |
+
* Sends data on the socket, with an explicit encoding for string data.
|
| 110 |
+
* @see {@link Socket.write} for full details.
|
| 111 |
+
* @since v0.1.90
|
| 112 |
+
* @param [encoding='utf8'] Only used when data is `string`.
|
| 113 |
+
*/
|
| 114 |
+
write(str: Uint8Array | string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
|
| 115 |
+
/**
|
| 116 |
+
* Initiate a connection on a given socket.
|
| 117 |
+
*
|
| 118 |
+
* Possible signatures:
|
| 119 |
+
*
|
| 120 |
+
* * `socket.connect(options[, connectListener])`
|
| 121 |
+
* * `socket.connect(path[, connectListener])` for `IPC` connections.
|
| 122 |
+
* * `socket.connect(port[, host][, connectListener])` for TCP connections.
|
| 123 |
+
* * Returns: `net.Socket` The socket itself.
|
| 124 |
+
*
|
| 125 |
+
* This function is asynchronous. When the connection is established, the `'connect'` event will be emitted. If there is a problem connecting,
|
| 126 |
+
* instead of a `'connect'` event, an `'error'` event will be emitted with
|
| 127 |
+
* the error passed to the `'error'` listener.
|
| 128 |
+
* The last parameter `connectListener`, if supplied, will be added as a listener
|
| 129 |
+
* for the `'connect'` event **once**.
|
| 130 |
+
*
|
| 131 |
+
* This function should only be used for reconnecting a socket after`'close'` has been emitted or otherwise it may lead to undefined
|
| 132 |
+
* behavior.
|
| 133 |
+
*/
|
| 134 |
+
connect(options: SocketConnectOpts, connectionListener?: () => void): this;
|
| 135 |
+
connect(port: number, host: string, connectionListener?: () => void): this;
|
| 136 |
+
connect(port: number, connectionListener?: () => void): this;
|
| 137 |
+
connect(path: string, connectionListener?: () => void): this;
|
| 138 |
+
/**
|
| 139 |
+
* Set the encoding for the socket as a `Readable Stream`. See `readable.setEncoding()` for more information.
|
| 140 |
+
* @since v0.1.90
|
| 141 |
+
* @return The socket itself.
|
| 142 |
+
*/
|
| 143 |
+
setEncoding(encoding?: BufferEncoding): this;
|
| 144 |
+
/**
|
| 145 |
+
* Pauses the reading of data. That is, `'data'` events will not be emitted.
|
| 146 |
+
* Useful to throttle back an upload.
|
| 147 |
+
* @return The socket itself.
|
| 148 |
+
*/
|
| 149 |
+
pause(): this;
|
| 150 |
+
/**
|
| 151 |
+
* Close the TCP connection by sending an RST packet and destroy the stream.
|
| 152 |
+
* If this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected.
|
| 153 |
+
* Otherwise, it will call `socket.destroy` with an `ERR_SOCKET_CLOSED` Error.
|
| 154 |
+
* If this is not a TCP socket (for example, a pipe), calling this method will immediately throw an `ERR_INVALID_HANDLE_TYPE` Error.
|
| 155 |
+
* @since v18.3.0, v16.17.0
|
| 156 |
+
*/
|
| 157 |
+
resetAndDestroy(): this;
|
| 158 |
+
/**
|
| 159 |
+
* Resumes reading after a call to `socket.pause()`.
|
| 160 |
+
* @return The socket itself.
|
| 161 |
+
*/
|
| 162 |
+
resume(): this;
|
| 163 |
+
/**
|
| 164 |
+
* Sets the socket to timeout after `timeout` milliseconds of inactivity on
|
| 165 |
+
* the socket. By default `net.Socket` do not have a timeout.
|
| 166 |
+
*
|
| 167 |
+
* 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
|
| 168 |
+
* end the connection.
|
| 169 |
+
*
|
| 170 |
+
* ```js
|
| 171 |
+
* socket.setTimeout(3000);
|
| 172 |
+
* socket.on('timeout', () => {
|
| 173 |
+
* console.log('socket timeout');
|
| 174 |
+
* socket.end();
|
| 175 |
+
* });
|
| 176 |
+
* ```
|
| 177 |
+
*
|
| 178 |
+
* If `timeout` is 0, then the existing idle timeout is disabled.
|
| 179 |
+
*
|
| 180 |
+
* The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.
|
| 181 |
+
* @since v0.1.90
|
| 182 |
+
* @return The socket itself.
|
| 183 |
+
*/
|
| 184 |
+
setTimeout(timeout: number, callback?: () => void): this;
|
| 185 |
+
/**
|
| 186 |
+
* Enable/disable the use of Nagle's algorithm.
|
| 187 |
+
*
|
| 188 |
+
* When a TCP connection is created, it will have Nagle's algorithm enabled.
|
| 189 |
+
*
|
| 190 |
+
* Nagle's algorithm delays data before it is sent via the network. It attempts
|
| 191 |
+
* to optimize throughput at the expense of latency.
|
| 192 |
+
*
|
| 193 |
+
* Passing `true` for `noDelay` or not passing an argument will disable Nagle's
|
| 194 |
+
* algorithm for the socket. Passing `false` for `noDelay` will enable Nagle's
|
| 195 |
+
* algorithm.
|
| 196 |
+
* @since v0.1.90
|
| 197 |
+
* @param [noDelay=true]
|
| 198 |
+
* @return The socket itself.
|
| 199 |
+
*/
|
| 200 |
+
setNoDelay(noDelay?: boolean): this;
|
| 201 |
+
/**
|
| 202 |
+
* Enable/disable keep-alive functionality, and optionally set the initial
|
| 203 |
+
* delay before the first keepalive probe is sent on an idle socket.
|
| 204 |
+
*
|
| 205 |
+
* Set `initialDelay` (in milliseconds) to set the delay between the last
|
| 206 |
+
* data packet received and the first keepalive probe. Setting `0` for`initialDelay` will leave the value unchanged from the default
|
| 207 |
+
* (or previous) setting.
|
| 208 |
+
*
|
| 209 |
+
* Enabling the keep-alive functionality will set the following socket options:
|
| 210 |
+
*
|
| 211 |
+
* * `SO_KEEPALIVE=1`
|
| 212 |
+
* * `TCP_KEEPIDLE=initialDelay`
|
| 213 |
+
* * `TCP_KEEPCNT=10`
|
| 214 |
+
* * `TCP_KEEPINTVL=1`
|
| 215 |
+
* @since v0.1.92
|
| 216 |
+
* @param [enable=false]
|
| 217 |
+
* @param [initialDelay=0]
|
| 218 |
+
* @return The socket itself.
|
| 219 |
+
*/
|
| 220 |
+
setKeepAlive(enable?: boolean, initialDelay?: number): this;
|
| 221 |
+
/**
|
| 222 |
+
* Returns the current Type of Service (TOS) field for IPv4 packets or Traffic
|
| 223 |
+
* Class for IPv6 packets for this socket.
|
| 224 |
+
*
|
| 225 |
+
* `setTypeOfService()` may be called before the socket is connected; the value
|
| 226 |
+
* will be cached and applied when the socket establishes a connection.
|
| 227 |
+
* `getTypeOfService()` will return the currently set value even before connection.
|
| 228 |
+
*
|
| 229 |
+
* On some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored,
|
| 230 |
+
* and behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers
|
| 231 |
+
* should verify platform-specific semantics.
|
| 232 |
+
* @since v25.6.0
|
| 233 |
+
* @returns The current TOS value.
|
| 234 |
+
*/
|
| 235 |
+
getTypeOfService(): number;
|
| 236 |
+
/**
|
| 237 |
+
* Sets the Type of Service (TOS) field for IPv4 packets or Traffic Class for IPv6
|
| 238 |
+
* Packets sent from this socket. This can be used to prioritize network traffic.
|
| 239 |
+
*
|
| 240 |
+
* `setTypeOfService()` may be called before the socket is connected; the value
|
| 241 |
+
* will be cached and applied when the socket establishes a connection.
|
| 242 |
+
* `getTypeOfService()` will return the currently set value even before connection.
|
| 243 |
+
*
|
| 244 |
+
* On some platforms (e.g., Linux), certain TOS/ECN bits may be masked or ignored,
|
| 245 |
+
* and behavior can differ between IPv4 and IPv6 or dual-stack sockets. Callers
|
| 246 |
+
* should verify platform-specific semantics.
|
| 247 |
+
* @since v25.6.0
|
| 248 |
+
* @param tos The TOS value to set (0-255).
|
| 249 |
+
* @returns The socket itself.
|
| 250 |
+
*/
|
| 251 |
+
setTypeOfService(tos: number): this;
|
| 252 |
+
/**
|
| 253 |
+
* Returns the bound `address`, the address `family` name and `port` of the
|
| 254 |
+
* socket as reported by the operating system:`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`
|
| 255 |
+
* @since v0.1.90
|
| 256 |
+
*/
|
| 257 |
+
address(): AddressInfo | {};
|
| 258 |
+
/**
|
| 259 |
+
* Calling `unref()` on a socket will allow the program to exit if this is the only
|
| 260 |
+
* active socket in the event system. If the socket is already `unref`ed calling`unref()` again will have no effect.
|
| 261 |
+
* @since v0.9.1
|
| 262 |
+
* @return The socket itself.
|
| 263 |
+
*/
|
| 264 |
+
unref(): this;
|
| 265 |
+
/**
|
| 266 |
+
* 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).
|
| 267 |
+
* If the socket is `ref`ed calling `ref` again will have no effect.
|
| 268 |
+
* @since v0.9.1
|
| 269 |
+
* @return The socket itself.
|
| 270 |
+
*/
|
| 271 |
+
ref(): this;
|
| 272 |
+
/**
|
| 273 |
+
* This property is only present if the family autoselection algorithm is enabled in `socket.connect(options)`
|
| 274 |
+
* and it is an array of the addresses that have been attempted.
|
| 275 |
+
*
|
| 276 |
+
* Each address is a string in the form of `$IP:$PORT`.
|
| 277 |
+
* If the connection was successful, then the last address is the one that the socket is currently connected to.
|
| 278 |
+
* @since v19.4.0
|
| 279 |
+
*/
|
| 280 |
+
readonly autoSelectFamilyAttemptedAddresses: string[];
|
| 281 |
+
/**
|
| 282 |
+
* This property shows the number of characters buffered for writing. The buffer
|
| 283 |
+
* may contain strings whose length after encoding is not yet known. So this number
|
| 284 |
+
* is only an approximation of the number of bytes in the buffer.
|
| 285 |
+
*
|
| 286 |
+
* `net.Socket` has the property that `socket.write()` always works. This is to
|
| 287 |
+
* help users get up and running quickly. The computer cannot always keep up
|
| 288 |
+
* with the amount of data that is written to a socket. The network connection
|
| 289 |
+
* simply might be too slow. Node.js will internally queue up the data written to a
|
| 290 |
+
* socket and send it out over the wire when it is possible.
|
| 291 |
+
*
|
| 292 |
+
* The consequence of this internal buffering is that memory may grow.
|
| 293 |
+
* Users who experience large or growing `bufferSize` should attempt to
|
| 294 |
+
* "throttle" the data flows in their program with `socket.pause()` and `socket.resume()`.
|
| 295 |
+
* @since v0.3.8
|
| 296 |
+
* @deprecated Since v14.6.0 - Use `writableLength` instead.
|
| 297 |
+
*/
|
| 298 |
+
readonly bufferSize: number;
|
| 299 |
+
/**
|
| 300 |
+
* The amount of received bytes.
|
| 301 |
+
* @since v0.5.3
|
| 302 |
+
*/
|
| 303 |
+
readonly bytesRead: number;
|
| 304 |
+
/**
|
| 305 |
+
* The amount of bytes sent.
|
| 306 |
+
* @since v0.5.3
|
| 307 |
+
*/
|
| 308 |
+
readonly bytesWritten: number;
|
| 309 |
+
/**
|
| 310 |
+
* If `true`, `socket.connect(options[, connectListener])` was
|
| 311 |
+
* called and has not yet finished. It will stay `true` until the socket becomes
|
| 312 |
+
* connected, then it is set to `false` and the `'connect'` event is emitted. Note
|
| 313 |
+
* that the `socket.connect(options[, connectListener])` callback is a listener for the `'connect'` event.
|
| 314 |
+
* @since v6.1.0
|
| 315 |
+
*/
|
| 316 |
+
readonly connecting: boolean;
|
| 317 |
+
/**
|
| 318 |
+
* 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
|
| 319 |
+
* (see `socket.connecting`).
|
| 320 |
+
* @since v11.2.0, v10.16.0
|
| 321 |
+
*/
|
| 322 |
+
readonly pending: boolean;
|
| 323 |
+
/**
|
| 324 |
+
* See `writable.destroyed` for further details.
|
| 325 |
+
*/
|
| 326 |
+
readonly destroyed: boolean;
|
| 327 |
+
/**
|
| 328 |
+
* The string representation of the local IP address the remote client is
|
| 329 |
+
* connecting on. For example, in a server listening on `'0.0.0.0'`, if a client
|
| 330 |
+
* connects on `'192.168.1.1'`, the value of `socket.localAddress` would be`'192.168.1.1'`.
|
| 331 |
+
* @since v0.9.6
|
| 332 |
+
*/
|
| 333 |
+
readonly localAddress?: string;
|
| 334 |
+
/**
|
| 335 |
+
* The numeric representation of the local port. For example, `80` or `21`.
|
| 336 |
+
* @since v0.9.6
|
| 337 |
+
*/
|
| 338 |
+
readonly localPort?: number;
|
| 339 |
+
/**
|
| 340 |
+
* The string representation of the local IP family. `'IPv4'` or `'IPv6'`.
|
| 341 |
+
* @since v18.8.0, v16.18.0
|
| 342 |
+
*/
|
| 343 |
+
readonly localFamily?: string;
|
| 344 |
+
/**
|
| 345 |
+
* This property represents the state of the connection as a string.
|
| 346 |
+
*
|
| 347 |
+
* * If the stream is connecting `socket.readyState` is `opening`.
|
| 348 |
+
* * If the stream is readable and writable, it is `open`.
|
| 349 |
+
* * If the stream is readable and not writable, it is `readOnly`.
|
| 350 |
+
* * If the stream is not readable and writable, it is `writeOnly`.
|
| 351 |
+
* @since v0.5.0
|
| 352 |
+
*/
|
| 353 |
+
readonly readyState: SocketReadyState;
|
| 354 |
+
/**
|
| 355 |
+
* The string representation of the remote IP address. For example,`'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if
|
| 356 |
+
* the socket is destroyed (for example, if the client disconnected).
|
| 357 |
+
* @since v0.5.10
|
| 358 |
+
*/
|
| 359 |
+
readonly remoteAddress: string | undefined;
|
| 360 |
+
/**
|
| 361 |
+
* The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. Value may be `undefined` if
|
| 362 |
+
* the socket is destroyed (for example, if the client disconnected).
|
| 363 |
+
* @since v0.11.14
|
| 364 |
+
*/
|
| 365 |
+
readonly remoteFamily: string | undefined;
|
| 366 |
+
/**
|
| 367 |
+
* The numeric representation of the remote port. For example, `80` or `21`. Value may be `undefined` if
|
| 368 |
+
* the socket is destroyed (for example, if the client disconnected).
|
| 369 |
+
* @since v0.5.10
|
| 370 |
+
*/
|
| 371 |
+
readonly remotePort: number | undefined;
|
| 372 |
+
/**
|
| 373 |
+
* The socket timeout in milliseconds as set by `socket.setTimeout()`.
|
| 374 |
+
* It is `undefined` if a timeout has not been set.
|
| 375 |
+
* @since v10.7.0
|
| 376 |
+
*/
|
| 377 |
+
readonly timeout?: number;
|
| 378 |
+
/**
|
| 379 |
+
* Half-closes the socket. i.e., it sends a FIN packet. It is possible the
|
| 380 |
+
* server will still send some data.
|
| 381 |
+
*
|
| 382 |
+
* See `writable.end()` for further details.
|
| 383 |
+
* @since v0.1.90
|
| 384 |
+
* @param callback Optional callback for when the socket is finished.
|
| 385 |
+
* @return The socket itself.
|
| 386 |
+
*/
|
| 387 |
+
end(callback?: () => void): this;
|
| 388 |
+
/**
|
| 389 |
+
* Half-closes the socket, with one final chunk of data.
|
| 390 |
+
* @see {@link Socket.end} for full details.
|
| 391 |
+
* @since v0.1.90
|
| 392 |
+
* @param callback Optional callback for when the socket is finished.
|
| 393 |
+
* @return The socket itself.
|
| 394 |
+
*/
|
| 395 |
+
end(buffer: Uint8Array | string, callback?: () => void): this;
|
| 396 |
+
/**
|
| 397 |
+
* Half-closes the socket, with one final chunk of data.
|
| 398 |
+
* @see {@link Socket.end} for full details.
|
| 399 |
+
* @since v0.1.90
|
| 400 |
+
* @param [encoding='utf8'] Only used when data is `string`.
|
| 401 |
+
* @param callback Optional callback for when the socket is finished.
|
| 402 |
+
* @return The socket itself.
|
| 403 |
+
*/
|
| 404 |
+
end(str: Uint8Array | string, encoding?: BufferEncoding, callback?: () => void): this;
|
| 405 |
+
// #region InternalEventEmitter
|
| 406 |
+
addListener<E extends keyof SocketEventMap>(eventName: E, listener: (...args: SocketEventMap[E]) => void): this;
|
| 407 |
+
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 408 |
+
emit<E extends keyof SocketEventMap>(eventName: E, ...args: SocketEventMap[E]): boolean;
|
| 409 |
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
| 410 |
+
listenerCount<E extends keyof SocketEventMap>(
|
| 411 |
+
eventName: E,
|
| 412 |
+
listener?: (...args: SocketEventMap[E]) => void,
|
| 413 |
+
): number;
|
| 414 |
+
listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
|
| 415 |
+
listeners<E extends keyof SocketEventMap>(eventName: E): ((...args: SocketEventMap[E]) => void)[];
|
| 416 |
+
listeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 417 |
+
off<E extends keyof SocketEventMap>(eventName: E, listener: (...args: SocketEventMap[E]) => void): this;
|
| 418 |
+
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 419 |
+
on<E extends keyof SocketEventMap>(eventName: E, listener: (...args: SocketEventMap[E]) => void): this;
|
| 420 |
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 421 |
+
once<E extends keyof SocketEventMap>(eventName: E, listener: (...args: SocketEventMap[E]) => void): this;
|
| 422 |
+
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 423 |
+
prependListener<E extends keyof SocketEventMap>(
|
| 424 |
+
eventName: E,
|
| 425 |
+
listener: (...args: SocketEventMap[E]) => void,
|
| 426 |
+
): this;
|
| 427 |
+
prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 428 |
+
prependOnceListener<E extends keyof SocketEventMap>(
|
| 429 |
+
eventName: E,
|
| 430 |
+
listener: (...args: SocketEventMap[E]) => void,
|
| 431 |
+
): this;
|
| 432 |
+
prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 433 |
+
rawListeners<E extends keyof SocketEventMap>(eventName: E): ((...args: SocketEventMap[E]) => void)[];
|
| 434 |
+
rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
|
| 435 |
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
| 436 |
+
removeAllListeners<E extends keyof SocketEventMap>(eventName?: E): this;
|
| 437 |
+
removeAllListeners(eventName?: string | symbol): this;
|
| 438 |
+
removeListener<E extends keyof SocketEventMap>(
|
| 439 |
+
eventName: E,
|
| 440 |
+
listener: (...args: SocketEventMap[E]) => void,
|
| 441 |
+
): this;
|
| 442 |
+
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
| 443 |
+
// #endregion
|
| 444 |
+
}
|
| 445 |
+
interface ListenOptions extends Abortable {
|
| 446 |
+
backlog?: number | undefined;
|
| 447 |
+
exclusive?: boolean | undefined;
|
| 448 |
+
host?: string | undefined;
|
| 449 |
+
/**
|
| 450 |
+
* @default false
|
| 451 |
+
*/
|
| 452 |
+
ipv6Only?: boolean | undefined;
|
| 453 |
+
reusePort?: boolean | undefined;
|
| 454 |
+
path?: string | undefined;
|
| 455 |
+
port?: number | undefined;
|
| 456 |
+
readableAll?: boolean | undefined;
|
| 457 |
+
writableAll?: boolean | undefined;
|
| 458 |
+
}
|
| 459 |
+
interface ServerOpts {
|
| 460 |
+
/**
|
| 461 |
+
* Indicates whether half-opened TCP connections are allowed.
|
| 462 |
+
* @default false
|
| 463 |
+
*/
|
| 464 |
+
allowHalfOpen?: boolean | undefined;
|
| 465 |
+
/**
|
| 466 |
+
* Indicates whether the socket should be paused on incoming connections.
|
| 467 |
+
* @default false
|
| 468 |
+
*/
|
| 469 |
+
pauseOnConnect?: boolean | undefined;
|
| 470 |
+
/**
|
| 471 |
+
* If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
|
| 472 |
+
* @default false
|
| 473 |
+
* @since v16.5.0
|
| 474 |
+
*/
|
| 475 |
+
noDelay?: boolean | undefined;
|
| 476 |
+
/**
|
| 477 |
+
* If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
|
| 478 |
+
* similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
|
| 479 |
+
* @default false
|
| 480 |
+
* @since v16.5.0
|
| 481 |
+
*/
|
| 482 |
+
keepAlive?: boolean | undefined;
|
| 483 |
+
/**
|
| 484 |
+
* If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
|
| 485 |
+
* @default 0
|
| 486 |
+
* @since v16.5.0
|
| 487 |
+
*/
|
| 488 |
+
keepAliveInitialDelay?: number | undefined;
|
| 489 |
+
/**
|
| 490 |
+
* Optionally overrides all `net.Socket`s' `readableHighWaterMark` and `writableHighWaterMark`.
|
| 491 |
+
* @default See [stream.getDefaultHighWaterMark()](https://nodejs.org/docs/latest-v25.x/api/stream.html#streamgetdefaulthighwatermarkobjectmode).
|
| 492 |
+
* @since v18.17.0, v20.1.0
|
| 493 |
+
*/
|
| 494 |
+
highWaterMark?: number | undefined;
|
| 495 |
+
/**
|
| 496 |
+
* `blockList` can be used for disabling inbound
|
| 497 |
+
* access to specific IP addresses, IP ranges, or IP subnets. This does not
|
| 498 |
+
* work if the server is behind a reverse proxy, NAT, etc. because the address
|
| 499 |
+
* checked against the block list is the address of the proxy, or the one
|
| 500 |
+
* specified by the NAT.
|
| 501 |
+
* @since v22.13.0
|
| 502 |
+
*/
|
| 503 |
+
blockList?: BlockList | undefined;
|
| 504 |
+
}
|
| 505 |
+
interface DropArgument {
|
| 506 |
+
localAddress?: string;
|
| 507 |
+
localPort?: number;
|
| 508 |
+
localFamily?: string;
|
| 509 |
+
remoteAddress?: string;
|
| 510 |
+
remotePort?: number;
|
| 511 |
+
remoteFamily?: string;
|
| 512 |
+
}
|
| 513 |
+
interface ServerEventMap {
|
| 514 |
+
"close": [];
|
| 515 |
+
"connection": [socket: Socket];
|
| 516 |
+
"error": [err: Error];
|
| 517 |
+
"listening": [];
|
| 518 |
+
"drop": [data?: DropArgument];
|
| 519 |
+
}
|
| 520 |
+
/**
|
| 521 |
+
* This class is used to create a TCP or `IPC` server.
|
| 522 |
+
* @since v0.1.90
|
| 523 |
+
*/
|
| 524 |
+
class Server implements EventEmitter {
|
| 525 |
+
constructor(connectionListener?: (socket: Socket) => void);
|
| 526 |
+
constructor(options?: ServerOpts, connectionListener?: (socket: Socket) => void);
|
| 527 |
+
/**
|
| 528 |
+
* Start a server listening for connections. A `net.Server` can be a TCP or
|
| 529 |
+
* an `IPC` server depending on what it listens to.
|
| 530 |
+
*
|
| 531 |
+
* Possible signatures:
|
| 532 |
+
*
|
| 533 |
+
* * `server.listen(handle[, backlog][, callback])`
|
| 534 |
+
* * `server.listen(options[, callback])`
|
| 535 |
+
* * `server.listen(path[, backlog][, callback])` for `IPC` servers
|
| 536 |
+
* * `server.listen([port[, host[, backlog]]][, callback])` for TCP servers
|
| 537 |
+
*
|
| 538 |
+
* 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'`
|
| 539 |
+
* event.
|
| 540 |
+
*
|
| 541 |
+
* All `listen()` methods can take a `backlog` parameter to specify the maximum
|
| 542 |
+
* length of the queue of pending connections. The actual length will be determined
|
| 543 |
+
* 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).
|
| 544 |
+
*
|
| 545 |
+
* All {@link Socket} are set to `SO_REUSEADDR` (see [`socket(7)`](https://man7.org/linux/man-pages/man7/socket.7.html) for
|
| 546 |
+
* details).
|
| 547 |
+
*
|
| 548 |
+
* The `server.listen()` method can be called again if and only if there was an
|
| 549 |
+
* error during the first `server.listen()` call or `server.close()` has been
|
| 550 |
+
* called. Otherwise, an `ERR_SERVER_ALREADY_LISTEN` error will be thrown.
|
| 551 |
+
*
|
| 552 |
+
* One of the most common errors raised when listening is `EADDRINUSE`.
|
| 553 |
+
* This happens when another server is already listening on the requested`port`/`path`/`handle`. One way to handle this would be to retry
|
| 554 |
+
* after a certain amount of time:
|
| 555 |
+
*
|
| 556 |
+
* ```js
|
| 557 |
+
* server.on('error', (e) => {
|
| 558 |
+
* if (e.code === 'EADDRINUSE') {
|
| 559 |
+
* console.error('Address in use, retrying...');
|
| 560 |
+
* setTimeout(() => {
|
| 561 |
+
* server.close();
|
| 562 |
+
* server.listen(PORT, HOST);
|
| 563 |
+
* }, 1000);
|
| 564 |
+
* }
|
| 565 |
+
* });
|
| 566 |
+
* ```
|
| 567 |
+
*/
|
| 568 |
+
listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): this;
|
| 569 |
+
listen(port?: number, hostname?: string, listeningListener?: () => void): this;
|
| 570 |
+
listen(port?: number, backlog?: number, listeningListener?: () => void): this;
|
| 571 |
+
listen(port?: number, listeningListener?: () => void): this;
|
| 572 |
+
listen(path: string, backlog?: number, listeningListener?: () => void): this;
|
| 573 |
+
listen(path: string, listeningListener?: () => void): this;
|
| 574 |
+
listen(options: ListenOptions, listeningListener?: () => void): this;
|
| 575 |
+
listen(handle: any, backlog?: number, listeningListener?: () => void): this;
|
| 576 |
+
listen(handle: any, listeningListener?: () => void): this;
|
| 577 |
+
/**
|
| 578 |
+
* Stops the server from accepting new connections and keeps existing
|
| 579 |
+
* connections. This function is asynchronous, the server is finally closed
|
| 580 |
+
* when all connections are ended and the server emits a `'close'` event.
|
| 581 |
+
* The optional `callback` will be called once the `'close'` event occurs. Unlike
|
| 582 |
+
* that event, it will be called with an `Error` as its only argument if the server
|
| 583 |
+
* was not open when it was closed.
|
| 584 |
+
* @since v0.1.90
|
| 585 |
+
* @param callback Called when the server is closed.
|
| 586 |
+
*/
|
| 587 |
+
close(callback?: (err?: Error) => void): this;
|
| 588 |
+
/**
|
| 589 |
+
* Returns the bound `address`, the address `family` name, and `port` of the server
|
| 590 |
+
* as reported by the operating system if listening on an IP socket
|
| 591 |
+
* (useful to find which port was assigned when getting an OS-assigned address):`{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
|
| 592 |
+
*
|
| 593 |
+
* For a server listening on a pipe or Unix domain socket, the name is returned
|
| 594 |
+
* as a string.
|
| 595 |
+
*
|
| 596 |
+
* ```js
|
| 597 |
+
* const server = net.createServer((socket) => {
|
| 598 |
+
* socket.end('goodbye\n');
|
| 599 |
+
* }).on('error', (err) => {
|
| 600 |
+
* // Handle errors here.
|
| 601 |
+
* throw err;
|
| 602 |
+
* });
|
| 603 |
+
*
|
| 604 |
+
* // Grab an arbitrary unused port.
|
| 605 |
+
* server.listen(() => {
|
| 606 |
+
* console.log('opened server on', server.address());
|
| 607 |
+
* });
|
| 608 |
+
* ```
|
| 609 |
+
*
|
| 610 |
+
* `server.address()` returns `null` before the `'listening'` event has been
|
| 611 |
+
* emitted or after calling `server.close()`.
|
| 612 |
+
* @since v0.1.90
|
| 613 |
+
*/
|
| 614 |
+
address(): AddressInfo | string | null;
|
| 615 |
+
/**
|
| 616 |
+
* Asynchronously get the number of concurrent connections on the server. Works
|
| 617 |
+
* when sockets were sent to forks.
|
| 618 |
+
*
|
| 619 |
+
* Callback should take two arguments `err` and `count`.
|
| 620 |
+
* @since v0.9.7
|
| 621 |
+
*/
|
| 622 |
+
getConnections(cb: (error: Error | null, count: number) => void): this;
|
| 623 |
+
/**
|
| 624 |
+
* 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).
|
| 625 |
+
* If the server is `ref`ed calling `ref()` again will have no effect.
|
| 626 |
+
* @since v0.9.1
|
| 627 |
+
*/
|
| 628 |
+
ref(): this;
|
| 629 |
+
/**
|
| 630 |
+
* Calling `unref()` on a server will allow the program to exit if this is the only
|
| 631 |
+
* active server in the event system. If the server is already `unref`ed calling`unref()` again will have no effect.
|
| 632 |
+
* @since v0.9.1
|
| 633 |
+
*/
|
| 634 |
+
unref(): this;
|
| 635 |
+
/**
|
| 636 |
+
* Set this property to reject connections when the server's connection count gets
|
| 637 |
+
* high.
|
| 638 |
+
*
|
| 639 |
+
* It is not recommended to use this option once a socket has been sent to a child
|
| 640 |
+
* with `child_process.fork()`.
|
| 641 |
+
* @since v0.2.0
|
| 642 |
+
*/
|
| 643 |
+
maxConnections: number;
|
| 644 |
+
connections: number;
|
| 645 |
+
/**
|
| 646 |
+
* Indicates whether or not the server is listening for connections.
|
| 647 |
+
* @since v5.7.0
|
| 648 |
+
*/
|
| 649 |
+
readonly listening: boolean;
|
| 650 |
+
/**
|
| 651 |
+
* Calls {@link Server.close()} and returns a promise that fulfills when the server has closed.
|
| 652 |
+
* @since v20.5.0
|
| 653 |
+
*/
|
| 654 |
+
[Symbol.asyncDispose](): Promise<void>;
|
| 655 |
+
}
|
| 656 |
+
interface Server extends InternalEventEmitter<ServerEventMap> {}
|
| 657 |
+
type IPVersion = "ipv4" | "ipv6";
|
| 658 |
+
/**
|
| 659 |
+
* The `BlockList` object can be used with some network APIs to specify rules for
|
| 660 |
+
* disabling inbound or outbound access to specific IP addresses, IP ranges, or
|
| 661 |
+
* IP subnets.
|
| 662 |
+
* @since v15.0.0, v14.18.0
|
| 663 |
+
*/
|
| 664 |
+
class BlockList {
|
| 665 |
+
/**
|
| 666 |
+
* Adds a rule to block the given IP address.
|
| 667 |
+
* @since v15.0.0, v14.18.0
|
| 668 |
+
* @param address An IPv4 or IPv6 address.
|
| 669 |
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
| 670 |
+
*/
|
| 671 |
+
addAddress(address: string, type?: IPVersion): void;
|
| 672 |
+
addAddress(address: SocketAddress): void;
|
| 673 |
+
/**
|
| 674 |
+
* Adds a rule to block a range of IP addresses from `start` (inclusive) to`end` (inclusive).
|
| 675 |
+
* @since v15.0.0, v14.18.0
|
| 676 |
+
* @param start The starting IPv4 or IPv6 address in the range.
|
| 677 |
+
* @param end The ending IPv4 or IPv6 address in the range.
|
| 678 |
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
| 679 |
+
*/
|
| 680 |
+
addRange(start: string, end: string, type?: IPVersion): void;
|
| 681 |
+
addRange(start: SocketAddress, end: SocketAddress): void;
|
| 682 |
+
/**
|
| 683 |
+
* Adds a rule to block a range of IP addresses specified as a subnet mask.
|
| 684 |
+
* @since v15.0.0, v14.18.0
|
| 685 |
+
* @param net The network IPv4 or IPv6 address.
|
| 686 |
+
* @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`.
|
| 687 |
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
| 688 |
+
*/
|
| 689 |
+
addSubnet(net: SocketAddress, prefix: number): void;
|
| 690 |
+
addSubnet(net: string, prefix: number, type?: IPVersion): void;
|
| 691 |
+
/**
|
| 692 |
+
* Returns `true` if the given IP address matches any of the rules added to the`BlockList`.
|
| 693 |
+
*
|
| 694 |
+
* ```js
|
| 695 |
+
* const blockList = new net.BlockList();
|
| 696 |
+
* blockList.addAddress('123.123.123.123');
|
| 697 |
+
* blockList.addRange('10.0.0.1', '10.0.0.10');
|
| 698 |
+
* blockList.addSubnet('8592:757c:efae:4e45::', 64, 'ipv6');
|
| 699 |
+
*
|
| 700 |
+
* console.log(blockList.check('123.123.123.123')); // Prints: true
|
| 701 |
+
* console.log(blockList.check('10.0.0.3')); // Prints: true
|
| 702 |
+
* console.log(blockList.check('222.111.111.222')); // Prints: false
|
| 703 |
+
*
|
| 704 |
+
* // IPv6 notation for IPv4 addresses works:
|
| 705 |
+
* console.log(blockList.check('::ffff:7b7b:7b7b', 'ipv6')); // Prints: true
|
| 706 |
+
* console.log(blockList.check('::ffff:123.123.123.123', 'ipv6')); // Prints: true
|
| 707 |
+
* ```
|
| 708 |
+
* @since v15.0.0, v14.18.0
|
| 709 |
+
* @param address The IP address to check
|
| 710 |
+
* @param [type='ipv4'] Either `'ipv4'` or `'ipv6'`.
|
| 711 |
+
*/
|
| 712 |
+
check(address: SocketAddress): boolean;
|
| 713 |
+
check(address: string, type?: IPVersion): boolean;
|
| 714 |
+
/**
|
| 715 |
+
* The list of rules added to the blocklist.
|
| 716 |
+
* @since v15.0.0, v14.18.0
|
| 717 |
+
*/
|
| 718 |
+
rules: readonly string[];
|
| 719 |
+
/**
|
| 720 |
+
* Returns `true` if the `value` is a `net.BlockList`.
|
| 721 |
+
* @since v22.13.0
|
| 722 |
+
* @param value Any JS value
|
| 723 |
+
*/
|
| 724 |
+
static isBlockList(value: unknown): value is BlockList;
|
| 725 |
+
/**
|
| 726 |
+
* ```js
|
| 727 |
+
* const blockList = new net.BlockList();
|
| 728 |
+
* const data = [
|
| 729 |
+
* 'Subnet: IPv4 192.168.1.0/24',
|
| 730 |
+
* 'Address: IPv4 10.0.0.5',
|
| 731 |
+
* 'Range: IPv4 192.168.2.1-192.168.2.10',
|
| 732 |
+
* 'Range: IPv4 10.0.0.1-10.0.0.10',
|
| 733 |
+
* ];
|
| 734 |
+
* blockList.fromJSON(data);
|
| 735 |
+
* blockList.fromJSON(JSON.stringify(data));
|
| 736 |
+
* ```
|
| 737 |
+
* @since v24.5.0
|
| 738 |
+
* @experimental
|
| 739 |
+
*/
|
| 740 |
+
fromJSON(data: string | readonly string[]): void;
|
| 741 |
+
/**
|
| 742 |
+
* @since v24.5.0
|
| 743 |
+
* @experimental
|
| 744 |
+
*/
|
| 745 |
+
toJSON(): readonly string[];
|
| 746 |
+
}
|
| 747 |
+
interface TcpNetConnectOpts extends TcpSocketConnectOpts, SocketConstructorOpts {
|
| 748 |
+
timeout?: number | undefined;
|
| 749 |
+
}
|
| 750 |
+
interface IpcNetConnectOpts extends IpcSocketConnectOpts, SocketConstructorOpts {
|
| 751 |
+
timeout?: number | undefined;
|
| 752 |
+
}
|
| 753 |
+
type NetConnectOpts = TcpNetConnectOpts | IpcNetConnectOpts;
|
| 754 |
+
/**
|
| 755 |
+
* Creates a new TCP or `IPC` server.
|
| 756 |
+
*
|
| 757 |
+
* If `allowHalfOpen` is set to `true`, when the other end of the socket
|
| 758 |
+
* signals the end of transmission, the server will only send back the end of
|
| 759 |
+
* transmission when `socket.end()` is explicitly called. For example, in the
|
| 760 |
+
* context of TCP, when a FIN packed is received, a FIN packed is sent
|
| 761 |
+
* back only when `socket.end()` is explicitly called. Until then the
|
| 762 |
+
* 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.
|
| 763 |
+
*
|
| 764 |
+
* If `pauseOnConnect` is set to `true`, then the socket associated with each
|
| 765 |
+
* incoming connection will be paused, and no data will be read from its handle.
|
| 766 |
+
* This allows connections to be passed between processes without any data being
|
| 767 |
+
* read by the original process. To begin reading data from a paused socket, call `socket.resume()`.
|
| 768 |
+
*
|
| 769 |
+
* The server can be a TCP server or an `IPC` server, depending on what it `listen()` to.
|
| 770 |
+
*
|
| 771 |
+
* Here is an example of a TCP echo server which listens for connections
|
| 772 |
+
* on port 8124:
|
| 773 |
+
*
|
| 774 |
+
* ```js
|
| 775 |
+
* import net from 'node:net';
|
| 776 |
+
* const server = net.createServer((c) => {
|
| 777 |
+
* // 'connection' listener.
|
| 778 |
+
* console.log('client connected');
|
| 779 |
+
* c.on('end', () => {
|
| 780 |
+
* console.log('client disconnected');
|
| 781 |
+
* });
|
| 782 |
+
* c.write('hello\r\n');
|
| 783 |
+
* c.pipe(c);
|
| 784 |
+
* });
|
| 785 |
+
* server.on('error', (err) => {
|
| 786 |
+
* throw err;
|
| 787 |
+
* });
|
| 788 |
+
* server.listen(8124, () => {
|
| 789 |
+
* console.log('server bound');
|
| 790 |
+
* });
|
| 791 |
+
* ```
|
| 792 |
+
*
|
| 793 |
+
* Test this by using `telnet`:
|
| 794 |
+
*
|
| 795 |
+
* ```bash
|
| 796 |
+
* telnet localhost 8124
|
| 797 |
+
* ```
|
| 798 |
+
*
|
| 799 |
+
* To listen on the socket `/tmp/echo.sock`:
|
| 800 |
+
*
|
| 801 |
+
* ```js
|
| 802 |
+
* server.listen('/tmp/echo.sock', () => {
|
| 803 |
+
* console.log('server bound');
|
| 804 |
+
* });
|
| 805 |
+
* ```
|
| 806 |
+
*
|
| 807 |
+
* Use `nc` to connect to a Unix domain socket server:
|
| 808 |
+
*
|
| 809 |
+
* ```bash
|
| 810 |
+
* nc -U /tmp/echo.sock
|
| 811 |
+
* ```
|
| 812 |
+
* @since v0.5.0
|
| 813 |
+
* @param connectionListener Automatically set as a listener for the {@link 'connection'} event.
|
| 814 |
+
*/
|
| 815 |
+
function createServer(connectionListener?: (socket: Socket) => void): Server;
|
| 816 |
+
function createServer(options?: ServerOpts, connectionListener?: (socket: Socket) => void): Server;
|
| 817 |
+
/**
|
| 818 |
+
* Aliases to {@link createConnection}.
|
| 819 |
+
*
|
| 820 |
+
* Possible signatures:
|
| 821 |
+
*
|
| 822 |
+
* * {@link connect}
|
| 823 |
+
* * {@link connect} for `IPC` connections.
|
| 824 |
+
* * {@link connect} for TCP connections.
|
| 825 |
+
*/
|
| 826 |
+
function connect(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
| 827 |
+
function connect(port: number, host?: string, connectionListener?: () => void): Socket;
|
| 828 |
+
function connect(path: string, connectionListener?: () => void): Socket;
|
| 829 |
+
/**
|
| 830 |
+
* A factory function, which creates a new {@link Socket},
|
| 831 |
+
* immediately initiates connection with `socket.connect()`,
|
| 832 |
+
* then returns the `net.Socket` that starts the connection.
|
| 833 |
+
*
|
| 834 |
+
* When the connection is established, a `'connect'` event will be emitted
|
| 835 |
+
* on the returned socket. The last parameter `connectListener`, if supplied,
|
| 836 |
+
* will be added as a listener for the `'connect'` event **once**.
|
| 837 |
+
*
|
| 838 |
+
* Possible signatures:
|
| 839 |
+
*
|
| 840 |
+
* * {@link createConnection}
|
| 841 |
+
* * {@link createConnection} for `IPC` connections.
|
| 842 |
+
* * {@link createConnection} for TCP connections.
|
| 843 |
+
*
|
| 844 |
+
* The {@link connect} function is an alias to this function.
|
| 845 |
+
*/
|
| 846 |
+
function createConnection(options: NetConnectOpts, connectionListener?: () => void): Socket;
|
| 847 |
+
function createConnection(port: number, host?: string, connectionListener?: () => void): Socket;
|
| 848 |
+
function createConnection(path: string, connectionListener?: () => void): Socket;
|
| 849 |
+
/**
|
| 850 |
+
* Gets the current default value of the `autoSelectFamily` option of `socket.connect(options)`.
|
| 851 |
+
* The initial default value is `true`, unless the command line option`--no-network-family-autoselection` is provided.
|
| 852 |
+
* @since v19.4.0
|
| 853 |
+
*/
|
| 854 |
+
function getDefaultAutoSelectFamily(): boolean;
|
| 855 |
+
/**
|
| 856 |
+
* Sets the default value of the `autoSelectFamily` option of `socket.connect(options)`.
|
| 857 |
+
* @param value The new default value.
|
| 858 |
+
* The initial default value is `true`, unless the command line option
|
| 859 |
+
* `--no-network-family-autoselection` is provided.
|
| 860 |
+
* @since v19.4.0
|
| 861 |
+
*/
|
| 862 |
+
function setDefaultAutoSelectFamily(value: boolean): void;
|
| 863 |
+
/**
|
| 864 |
+
* Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`.
|
| 865 |
+
* The initial default value is `500` or the value specified via the command line option `--network-family-autoselection-attempt-timeout`.
|
| 866 |
+
* @returns The current default value of the `autoSelectFamilyAttemptTimeout` option.
|
| 867 |
+
* @since v19.8.0, v18.8.0
|
| 868 |
+
*/
|
| 869 |
+
function getDefaultAutoSelectFamilyAttemptTimeout(): number;
|
| 870 |
+
/**
|
| 871 |
+
* Sets the default value of the `autoSelectFamilyAttemptTimeout` option of `socket.connect(options)`.
|
| 872 |
+
* @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
|
| 873 |
+
* option `--network-family-autoselection-attempt-timeout`.
|
| 874 |
+
* @since v19.8.0, v18.8.0
|
| 875 |
+
*/
|
| 876 |
+
function setDefaultAutoSelectFamilyAttemptTimeout(value: number): void;
|
| 877 |
+
/**
|
| 878 |
+
* Returns `6` if `input` is an IPv6 address. Returns `4` if `input` is an IPv4
|
| 879 |
+
* address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no leading zeroes. Otherwise, returns`0`.
|
| 880 |
+
*
|
| 881 |
+
* ```js
|
| 882 |
+
* net.isIP('::1'); // returns 6
|
| 883 |
+
* net.isIP('127.0.0.1'); // returns 4
|
| 884 |
+
* net.isIP('127.000.000.001'); // returns 0
|
| 885 |
+
* net.isIP('127.0.0.1/24'); // returns 0
|
| 886 |
+
* net.isIP('fhqwhgads'); // returns 0
|
| 887 |
+
* ```
|
| 888 |
+
* @since v0.3.0
|
| 889 |
+
*/
|
| 890 |
+
function isIP(input: string): number;
|
| 891 |
+
/**
|
| 892 |
+
* Returns `true` if `input` is an IPv4 address in [dot-decimal notation](https://en.wikipedia.org/wiki/Dot-decimal_notation) with no
|
| 893 |
+
* leading zeroes. Otherwise, returns `false`.
|
| 894 |
+
*
|
| 895 |
+
* ```js
|
| 896 |
+
* net.isIPv4('127.0.0.1'); // returns true
|
| 897 |
+
* net.isIPv4('127.000.000.001'); // returns false
|
| 898 |
+
* net.isIPv4('127.0.0.1/24'); // returns false
|
| 899 |
+
* net.isIPv4('fhqwhgads'); // returns false
|
| 900 |
+
* ```
|
| 901 |
+
* @since v0.3.0
|
| 902 |
+
*/
|
| 903 |
+
function isIPv4(input: string): boolean;
|
| 904 |
+
/**
|
| 905 |
+
* Returns `true` if `input` is an IPv6 address. Otherwise, returns `false`.
|
| 906 |
+
*
|
| 907 |
+
* ```js
|
| 908 |
+
* net.isIPv6('::1'); // returns true
|
| 909 |
+
* net.isIPv6('fhqwhgads'); // returns false
|
| 910 |
+
* ```
|
| 911 |
+
* @since v0.3.0
|
| 912 |
+
*/
|
| 913 |
+
function isIPv6(input: string): boolean;
|
| 914 |
+
interface SocketAddressInitOptions {
|
| 915 |
+
/**
|
| 916 |
+
* The network address as either an IPv4 or IPv6 string.
|
| 917 |
+
* @default 127.0.0.1
|
| 918 |
+
*/
|
| 919 |
+
address?: string | undefined;
|
| 920 |
+
/**
|
| 921 |
+
* @default `'ipv4'`
|
| 922 |
+
*/
|
| 923 |
+
family?: IPVersion | undefined;
|
| 924 |
+
/**
|
| 925 |
+
* An IPv6 flow-label used only if `family` is `'ipv6'`.
|
| 926 |
+
* @default 0
|
| 927 |
+
*/
|
| 928 |
+
flowlabel?: number | undefined;
|
| 929 |
+
/**
|
| 930 |
+
* An IP port.
|
| 931 |
+
* @default 0
|
| 932 |
+
*/
|
| 933 |
+
port?: number | undefined;
|
| 934 |
+
}
|
| 935 |
+
/**
|
| 936 |
+
* @since v15.14.0, v14.18.0
|
| 937 |
+
*/
|
| 938 |
+
class SocketAddress {
|
| 939 |
+
constructor(options: SocketAddressInitOptions);
|
| 940 |
+
/**
|
| 941 |
+
* Either \`'ipv4'\` or \`'ipv6'\`.
|
| 942 |
+
* @since v15.14.0, v14.18.0
|
| 943 |
+
*/
|
| 944 |
+
readonly address: string;
|
| 945 |
+
/**
|
| 946 |
+
* Either \`'ipv4'\` or \`'ipv6'\`.
|
| 947 |
+
* @since v15.14.0, v14.18.0
|
| 948 |
+
*/
|
| 949 |
+
readonly family: IPVersion;
|
| 950 |
+
/**
|
| 951 |
+
* @since v15.14.0, v14.18.0
|
| 952 |
+
*/
|
| 953 |
+
readonly port: number;
|
| 954 |
+
/**
|
| 955 |
+
* @since v15.14.0, v14.18.0
|
| 956 |
+
*/
|
| 957 |
+
readonly flowlabel: number;
|
| 958 |
+
/**
|
| 959 |
+
* @since v22.13.0
|
| 960 |
+
* @param input An input string containing an IP address and optional port,
|
| 961 |
+
* e.g. `123.1.2.3:1234` or `[1::1]:1234`.
|
| 962 |
+
* @returns Returns a `SocketAddress` if parsing was successful.
|
| 963 |
+
* Otherwise returns `undefined`.
|
| 964 |
+
*/
|
| 965 |
+
static parse(input: string): SocketAddress | undefined;
|
| 966 |
+
}
|
| 967 |
+
}
|
| 968 |
+
declare module "net" {
|
| 969 |
+
export * from "node:net";
|
| 970 |
+
}
|
node_modules/@types/node/os.d.ts
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module "node:os" {
|
| 2 |
+
import { NonSharedBuffer } from "buffer";
|
| 3 |
+
interface CpuInfo {
|
| 4 |
+
model: string;
|
| 5 |
+
speed: number;
|
| 6 |
+
times: {
|
| 7 |
+
/** The number of milliseconds the CPU has spent in user mode. */
|
| 8 |
+
user: number;
|
| 9 |
+
/** The number of milliseconds the CPU has spent in nice mode. */
|
| 10 |
+
nice: number;
|
| 11 |
+
/** The number of milliseconds the CPU has spent in sys mode. */
|
| 12 |
+
sys: number;
|
| 13 |
+
/** The number of milliseconds the CPU has spent in idle mode. */
|
| 14 |
+
idle: number;
|
| 15 |
+
/** The number of milliseconds the CPU has spent in irq mode. */
|
| 16 |
+
irq: number;
|
| 17 |
+
};
|
| 18 |
+
}
|
| 19 |
+
interface NetworkInterfaceBase {
|
| 20 |
+
address: string;
|
| 21 |
+
netmask: string;
|
| 22 |
+
mac: string;
|
| 23 |
+
internal: boolean;
|
| 24 |
+
cidr: string | null;
|
| 25 |
+
scopeid?: number;
|
| 26 |
+
}
|
| 27 |
+
interface NetworkInterfaceInfoIPv4 extends NetworkInterfaceBase {
|
| 28 |
+
family: "IPv4";
|
| 29 |
+
}
|
| 30 |
+
interface NetworkInterfaceInfoIPv6 extends NetworkInterfaceBase {
|
| 31 |
+
family: "IPv6";
|
| 32 |
+
scopeid: number;
|
| 33 |
+
}
|
| 34 |
+
interface UserInfo<T> {
|
| 35 |
+
username: T;
|
| 36 |
+
uid: number;
|
| 37 |
+
gid: number;
|
| 38 |
+
shell: T | null;
|
| 39 |
+
homedir: T;
|
| 40 |
+
}
|
| 41 |
+
type NetworkInterfaceInfo = NetworkInterfaceInfoIPv4 | NetworkInterfaceInfoIPv6;
|
| 42 |
+
/**
|
| 43 |
+
* Returns the host name of the operating system as a string.
|
| 44 |
+
* @since v0.3.3
|
| 45 |
+
*/
|
| 46 |
+
function hostname(): string;
|
| 47 |
+
/**
|
| 48 |
+
* Returns an array containing the 1, 5, and 15 minute load averages.
|
| 49 |
+
*
|
| 50 |
+
* The load average is a measure of system activity calculated by the operating
|
| 51 |
+
* system and expressed as a fractional number.
|
| 52 |
+
*
|
| 53 |
+
* The load average is a Unix-specific concept. On Windows, the return value is
|
| 54 |
+
* always `[0, 0, 0]`.
|
| 55 |
+
* @since v0.3.3
|
| 56 |
+
*/
|
| 57 |
+
function loadavg(): number[];
|
| 58 |
+
/**
|
| 59 |
+
* Returns the system uptime in number of seconds.
|
| 60 |
+
* @since v0.3.3
|
| 61 |
+
*/
|
| 62 |
+
function uptime(): number;
|
| 63 |
+
/**
|
| 64 |
+
* Returns the amount of free system memory in bytes as an integer.
|
| 65 |
+
* @since v0.3.3
|
| 66 |
+
*/
|
| 67 |
+
function freemem(): number;
|
| 68 |
+
/**
|
| 69 |
+
* Returns the total amount of system memory in bytes as an integer.
|
| 70 |
+
* @since v0.3.3
|
| 71 |
+
*/
|
| 72 |
+
function totalmem(): number;
|
| 73 |
+
/**
|
| 74 |
+
* Returns an array of objects containing information about each logical CPU core.
|
| 75 |
+
* The array will be empty if no CPU information is available, such as if the `/proc` file system is unavailable.
|
| 76 |
+
*
|
| 77 |
+
* The properties included on each object include:
|
| 78 |
+
*
|
| 79 |
+
* ```js
|
| 80 |
+
* [
|
| 81 |
+
* {
|
| 82 |
+
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
| 83 |
+
* speed: 2926,
|
| 84 |
+
* times: {
|
| 85 |
+
* user: 252020,
|
| 86 |
+
* nice: 0,
|
| 87 |
+
* sys: 30340,
|
| 88 |
+
* idle: 1070356870,
|
| 89 |
+
* irq: 0,
|
| 90 |
+
* },
|
| 91 |
+
* },
|
| 92 |
+
* {
|
| 93 |
+
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
| 94 |
+
* speed: 2926,
|
| 95 |
+
* times: {
|
| 96 |
+
* user: 306960,
|
| 97 |
+
* nice: 0,
|
| 98 |
+
* sys: 26980,
|
| 99 |
+
* idle: 1071569080,
|
| 100 |
+
* irq: 0,
|
| 101 |
+
* },
|
| 102 |
+
* },
|
| 103 |
+
* {
|
| 104 |
+
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
| 105 |
+
* speed: 2926,
|
| 106 |
+
* times: {
|
| 107 |
+
* user: 248450,
|
| 108 |
+
* nice: 0,
|
| 109 |
+
* sys: 21750,
|
| 110 |
+
* idle: 1070919370,
|
| 111 |
+
* irq: 0,
|
| 112 |
+
* },
|
| 113 |
+
* },
|
| 114 |
+
* {
|
| 115 |
+
* model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
|
| 116 |
+
* speed: 2926,
|
| 117 |
+
* times: {
|
| 118 |
+
* user: 256880,
|
| 119 |
+
* nice: 0,
|
| 120 |
+
* sys: 19430,
|
| 121 |
+
* idle: 1070905480,
|
| 122 |
+
* irq: 20,
|
| 123 |
+
* },
|
| 124 |
+
* },
|
| 125 |
+
* ]
|
| 126 |
+
* ```
|
| 127 |
+
*
|
| 128 |
+
* `nice` values are POSIX-only. On Windows, the `nice` values of all processors
|
| 129 |
+
* are always 0.
|
| 130 |
+
*
|
| 131 |
+
* `os.cpus().length` should not be used to calculate the amount of parallelism
|
| 132 |
+
* available to an application. Use {@link availableParallelism} for this purpose.
|
| 133 |
+
* @since v0.3.3
|
| 134 |
+
*/
|
| 135 |
+
function cpus(): CpuInfo[];
|
| 136 |
+
/**
|
| 137 |
+
* Returns an estimate of the default amount of parallelism a program should use.
|
| 138 |
+
* Always returns a value greater than zero.
|
| 139 |
+
*
|
| 140 |
+
* 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).
|
| 141 |
+
* @since v19.4.0, v18.14.0
|
| 142 |
+
*/
|
| 143 |
+
function availableParallelism(): number;
|
| 144 |
+
/**
|
| 145 |
+
* Returns the operating system name as returned by [`uname(3)`](https://linux.die.net/man/3/uname). For example, it
|
| 146 |
+
* returns `'Linux'` on Linux, `'Darwin'` on macOS, and `'Windows_NT'` on Windows.
|
| 147 |
+
*
|
| 148 |
+
* See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for additional information
|
| 149 |
+
* about the output of running [`uname(3)`](https://linux.die.net/man/3/uname) on various operating systems.
|
| 150 |
+
* @since v0.3.3
|
| 151 |
+
*/
|
| 152 |
+
function type(): string;
|
| 153 |
+
/**
|
| 154 |
+
* Returns the operating system as a string.
|
| 155 |
+
*
|
| 156 |
+
* 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
|
| 157 |
+
* [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
| 158 |
+
* @since v0.3.3
|
| 159 |
+
*/
|
| 160 |
+
function release(): string;
|
| 161 |
+
/**
|
| 162 |
+
* Returns an object containing network interfaces that have been assigned a
|
| 163 |
+
* network address.
|
| 164 |
+
*
|
| 165 |
+
* Each key on the returned object identifies a network interface. The associated
|
| 166 |
+
* value is an array of objects that each describe an assigned network address.
|
| 167 |
+
*
|
| 168 |
+
* The properties available on the assigned network address object include:
|
| 169 |
+
*
|
| 170 |
+
* ```js
|
| 171 |
+
* {
|
| 172 |
+
* lo: [
|
| 173 |
+
* {
|
| 174 |
+
* address: '127.0.0.1',
|
| 175 |
+
* netmask: '255.0.0.0',
|
| 176 |
+
* family: 'IPv4',
|
| 177 |
+
* mac: '00:00:00:00:00:00',
|
| 178 |
+
* internal: true,
|
| 179 |
+
* cidr: '127.0.0.1/8'
|
| 180 |
+
* },
|
| 181 |
+
* {
|
| 182 |
+
* address: '::1',
|
| 183 |
+
* netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
|
| 184 |
+
* family: 'IPv6',
|
| 185 |
+
* mac: '00:00:00:00:00:00',
|
| 186 |
+
* scopeid: 0,
|
| 187 |
+
* internal: true,
|
| 188 |
+
* cidr: '::1/128'
|
| 189 |
+
* }
|
| 190 |
+
* ],
|
| 191 |
+
* eth0: [
|
| 192 |
+
* {
|
| 193 |
+
* address: '192.168.1.108',
|
| 194 |
+
* netmask: '255.255.255.0',
|
| 195 |
+
* family: 'IPv4',
|
| 196 |
+
* mac: '01:02:03:0a:0b:0c',
|
| 197 |
+
* internal: false,
|
| 198 |
+
* cidr: '192.168.1.108/24'
|
| 199 |
+
* },
|
| 200 |
+
* {
|
| 201 |
+
* address: 'fe80::a00:27ff:fe4e:66a1',
|
| 202 |
+
* netmask: 'ffff:ffff:ffff:ffff::',
|
| 203 |
+
* family: 'IPv6',
|
| 204 |
+
* mac: '01:02:03:0a:0b:0c',
|
| 205 |
+
* scopeid: 1,
|
| 206 |
+
* internal: false,
|
| 207 |
+
* cidr: 'fe80::a00:27ff:fe4e:66a1/64'
|
| 208 |
+
* }
|
| 209 |
+
* ]
|
| 210 |
+
* }
|
| 211 |
+
* ```
|
| 212 |
+
* @since v0.6.0
|
| 213 |
+
*/
|
| 214 |
+
function networkInterfaces(): NodeJS.Dict<NetworkInterfaceInfo[]>;
|
| 215 |
+
/**
|
| 216 |
+
* Returns the string path of the current user's home directory.
|
| 217 |
+
*
|
| 218 |
+
* On POSIX, it uses the `$HOME` environment variable if defined. Otherwise it
|
| 219 |
+
* uses the [effective UID](https://en.wikipedia.org/wiki/User_identifier#Effective_user_ID) to look up the user's home directory.
|
| 220 |
+
*
|
| 221 |
+
* On Windows, it uses the `USERPROFILE` environment variable if defined.
|
| 222 |
+
* Otherwise it uses the path to the profile directory of the current user.
|
| 223 |
+
* @since v2.3.0
|
| 224 |
+
*/
|
| 225 |
+
function homedir(): string;
|
| 226 |
+
interface UserInfoOptions {
|
| 227 |
+
encoding?: BufferEncoding | "buffer" | undefined;
|
| 228 |
+
}
|
| 229 |
+
interface UserInfoOptionsWithBufferEncoding extends UserInfoOptions {
|
| 230 |
+
encoding: "buffer";
|
| 231 |
+
}
|
| 232 |
+
interface UserInfoOptionsWithStringEncoding extends UserInfoOptions {
|
| 233 |
+
encoding?: BufferEncoding | undefined;
|
| 234 |
+
}
|
| 235 |
+
/**
|
| 236 |
+
* Returns information about the currently effective user. On POSIX platforms,
|
| 237 |
+
* this is typically a subset of the password file. The returned object includes
|
| 238 |
+
* the `username`, `uid`, `gid`, `shell`, and `homedir`. On Windows, the `uid` and `gid` fields are `-1`, and `shell` is `null`.
|
| 239 |
+
*
|
| 240 |
+
* The value of `homedir` returned by `os.userInfo()` is provided by the operating
|
| 241 |
+
* system. This differs from the result of `os.homedir()`, which queries
|
| 242 |
+
* environment variables for the home directory before falling back to the
|
| 243 |
+
* operating system response.
|
| 244 |
+
*
|
| 245 |
+
* Throws a [`SystemError`](https://nodejs.org/docs/latest-v25.x/api/errors.html#class-systemerror) if a user has no `username` or `homedir`.
|
| 246 |
+
* @since v6.0.0
|
| 247 |
+
*/
|
| 248 |
+
function userInfo(options?: UserInfoOptionsWithStringEncoding): UserInfo<string>;
|
| 249 |
+
function userInfo(options: UserInfoOptionsWithBufferEncoding): UserInfo<NonSharedBuffer>;
|
| 250 |
+
function userInfo(options: UserInfoOptions): UserInfo<string | NonSharedBuffer>;
|
| 251 |
+
type SignalConstants = {
|
| 252 |
+
[key in NodeJS.Signals]: number;
|
| 253 |
+
};
|
| 254 |
+
namespace constants {
|
| 255 |
+
const UV_UDP_REUSEADDR: number;
|
| 256 |
+
namespace signals {}
|
| 257 |
+
const signals: SignalConstants;
|
| 258 |
+
namespace errno {
|
| 259 |
+
const E2BIG: number;
|
| 260 |
+
const EACCES: number;
|
| 261 |
+
const EADDRINUSE: number;
|
| 262 |
+
const EADDRNOTAVAIL: number;
|
| 263 |
+
const EAFNOSUPPORT: number;
|
| 264 |
+
const EAGAIN: number;
|
| 265 |
+
const EALREADY: number;
|
| 266 |
+
const EBADF: number;
|
| 267 |
+
const EBADMSG: number;
|
| 268 |
+
const EBUSY: number;
|
| 269 |
+
const ECANCELED: number;
|
| 270 |
+
const ECHILD: number;
|
| 271 |
+
const ECONNABORTED: number;
|
| 272 |
+
const ECONNREFUSED: number;
|
| 273 |
+
const ECONNRESET: number;
|
| 274 |
+
const EDEADLK: number;
|
| 275 |
+
const EDESTADDRREQ: number;
|
| 276 |
+
const EDOM: number;
|
| 277 |
+
const EDQUOT: number;
|
| 278 |
+
const EEXIST: number;
|
| 279 |
+
const EFAULT: number;
|
| 280 |
+
const EFBIG: number;
|
| 281 |
+
const EHOSTUNREACH: number;
|
| 282 |
+
const EIDRM: number;
|
| 283 |
+
const EILSEQ: number;
|
| 284 |
+
const EINPROGRESS: number;
|
| 285 |
+
const EINTR: number;
|
| 286 |
+
const EINVAL: number;
|
| 287 |
+
const EIO: number;
|
| 288 |
+
const EISCONN: number;
|
| 289 |
+
const EISDIR: number;
|
| 290 |
+
const ELOOP: number;
|
| 291 |
+
const EMFILE: number;
|
| 292 |
+
const EMLINK: number;
|
| 293 |
+
const EMSGSIZE: number;
|
| 294 |
+
const EMULTIHOP: number;
|
| 295 |
+
const ENAMETOOLONG: number;
|
| 296 |
+
const ENETDOWN: number;
|
| 297 |
+
const ENETRESET: number;
|
| 298 |
+
const ENETUNREACH: number;
|
| 299 |
+
const ENFILE: number;
|
| 300 |
+
const ENOBUFS: number;
|
| 301 |
+
const ENODATA: number;
|
| 302 |
+
const ENODEV: number;
|
| 303 |
+
const ENOENT: number;
|
| 304 |
+
const ENOEXEC: number;
|
| 305 |
+
const ENOLCK: number;
|
| 306 |
+
const ENOLINK: number;
|
| 307 |
+
const ENOMEM: number;
|
| 308 |
+
const ENOMSG: number;
|
| 309 |
+
const ENOPROTOOPT: number;
|
| 310 |
+
const ENOSPC: number;
|
| 311 |
+
const ENOSR: number;
|
| 312 |
+
const ENOSTR: number;
|
| 313 |
+
const ENOSYS: number;
|
| 314 |
+
const ENOTCONN: number;
|
| 315 |
+
const ENOTDIR: number;
|
| 316 |
+
const ENOTEMPTY: number;
|
| 317 |
+
const ENOTSOCK: number;
|
| 318 |
+
const ENOTSUP: number;
|
| 319 |
+
const ENOTTY: number;
|
| 320 |
+
const ENXIO: number;
|
| 321 |
+
const EOPNOTSUPP: number;
|
| 322 |
+
const EOVERFLOW: number;
|
| 323 |
+
const EPERM: number;
|
| 324 |
+
const EPIPE: number;
|
| 325 |
+
const EPROTO: number;
|
| 326 |
+
const EPROTONOSUPPORT: number;
|
| 327 |
+
const EPROTOTYPE: number;
|
| 328 |
+
const ERANGE: number;
|
| 329 |
+
const EROFS: number;
|
| 330 |
+
const ESPIPE: number;
|
| 331 |
+
const ESRCH: number;
|
| 332 |
+
const ESTALE: number;
|
| 333 |
+
const ETIME: number;
|
| 334 |
+
const ETIMEDOUT: number;
|
| 335 |
+
const ETXTBSY: number;
|
| 336 |
+
const EWOULDBLOCK: number;
|
| 337 |
+
const EXDEV: number;
|
| 338 |
+
const WSAEINTR: number;
|
| 339 |
+
const WSAEBADF: number;
|
| 340 |
+
const WSAEACCES: number;
|
| 341 |
+
const WSAEFAULT: number;
|
| 342 |
+
const WSAEINVAL: number;
|
| 343 |
+
const WSAEMFILE: number;
|
| 344 |
+
const WSAEWOULDBLOCK: number;
|
| 345 |
+
const WSAEINPROGRESS: number;
|
| 346 |
+
const WSAEALREADY: number;
|
| 347 |
+
const WSAENOTSOCK: number;
|
| 348 |
+
const WSAEDESTADDRREQ: number;
|
| 349 |
+
const WSAEMSGSIZE: number;
|
| 350 |
+
const WSAEPROTOTYPE: number;
|
| 351 |
+
const WSAENOPROTOOPT: number;
|
| 352 |
+
const WSAEPROTONOSUPPORT: number;
|
| 353 |
+
const WSAESOCKTNOSUPPORT: number;
|
| 354 |
+
const WSAEOPNOTSUPP: number;
|
| 355 |
+
const WSAEPFNOSUPPORT: number;
|
| 356 |
+
const WSAEAFNOSUPPORT: number;
|
| 357 |
+
const WSAEADDRINUSE: number;
|
| 358 |
+
const WSAEADDRNOTAVAIL: number;
|
| 359 |
+
const WSAENETDOWN: number;
|
| 360 |
+
const WSAENETUNREACH: number;
|
| 361 |
+
const WSAENETRESET: number;
|
| 362 |
+
const WSAECONNABORTED: number;
|
| 363 |
+
const WSAECONNRESET: number;
|
| 364 |
+
const WSAENOBUFS: number;
|
| 365 |
+
const WSAEISCONN: number;
|
| 366 |
+
const WSAENOTCONN: number;
|
| 367 |
+
const WSAESHUTDOWN: number;
|
| 368 |
+
const WSAETOOMANYREFS: number;
|
| 369 |
+
const WSAETIMEDOUT: number;
|
| 370 |
+
const WSAECONNREFUSED: number;
|
| 371 |
+
const WSAELOOP: number;
|
| 372 |
+
const WSAENAMETOOLONG: number;
|
| 373 |
+
const WSAEHOSTDOWN: number;
|
| 374 |
+
const WSAEHOSTUNREACH: number;
|
| 375 |
+
const WSAENOTEMPTY: number;
|
| 376 |
+
const WSAEPROCLIM: number;
|
| 377 |
+
const WSAEUSERS: number;
|
| 378 |
+
const WSAEDQUOT: number;
|
| 379 |
+
const WSAESTALE: number;
|
| 380 |
+
const WSAEREMOTE: number;
|
| 381 |
+
const WSASYSNOTREADY: number;
|
| 382 |
+
const WSAVERNOTSUPPORTED: number;
|
| 383 |
+
const WSANOTINITIALISED: number;
|
| 384 |
+
const WSAEDISCON: number;
|
| 385 |
+
const WSAENOMORE: number;
|
| 386 |
+
const WSAECANCELLED: number;
|
| 387 |
+
const WSAEINVALIDPROCTABLE: number;
|
| 388 |
+
const WSAEINVALIDPROVIDER: number;
|
| 389 |
+
const WSAEPROVIDERFAILEDINIT: number;
|
| 390 |
+
const WSASYSCALLFAILURE: number;
|
| 391 |
+
const WSASERVICE_NOT_FOUND: number;
|
| 392 |
+
const WSATYPE_NOT_FOUND: number;
|
| 393 |
+
const WSA_E_NO_MORE: number;
|
| 394 |
+
const WSA_E_CANCELLED: number;
|
| 395 |
+
const WSAEREFUSED: number;
|
| 396 |
+
}
|
| 397 |
+
namespace dlopen {
|
| 398 |
+
const RTLD_LAZY: number;
|
| 399 |
+
const RTLD_NOW: number;
|
| 400 |
+
const RTLD_GLOBAL: number;
|
| 401 |
+
const RTLD_LOCAL: number;
|
| 402 |
+
const RTLD_DEEPBIND: number;
|
| 403 |
+
}
|
| 404 |
+
namespace priority {
|
| 405 |
+
const PRIORITY_LOW: number;
|
| 406 |
+
const PRIORITY_BELOW_NORMAL: number;
|
| 407 |
+
const PRIORITY_NORMAL: number;
|
| 408 |
+
const PRIORITY_ABOVE_NORMAL: number;
|
| 409 |
+
const PRIORITY_HIGH: number;
|
| 410 |
+
const PRIORITY_HIGHEST: number;
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
+
const devNull: string;
|
| 414 |
+
/**
|
| 415 |
+
* The operating system-specific end-of-line marker.
|
| 416 |
+
* * `\n` on POSIX
|
| 417 |
+
* * `\r\n` on Windows
|
| 418 |
+
*/
|
| 419 |
+
const EOL: string;
|
| 420 |
+
/**
|
| 421 |
+
* Returns the operating system CPU architecture for which the Node.js binary was
|
| 422 |
+
* compiled. Possible values are `'arm'`, `'arm64'`, `'ia32'`, `'loong64'`,
|
| 423 |
+
* `'mips'`, `'mipsel'`, `'ppc64'`, `'riscv64'`, `'s390x'`, and `'x64'`.
|
| 424 |
+
*
|
| 425 |
+
* The return value is equivalent to [process.arch](https://nodejs.org/docs/latest-v25.x/api/process.html#processarch).
|
| 426 |
+
* @since v0.5.0
|
| 427 |
+
*/
|
| 428 |
+
function arch(): NodeJS.Architecture;
|
| 429 |
+
/**
|
| 430 |
+
* Returns a string identifying the kernel version.
|
| 431 |
+
*
|
| 432 |
+
* 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
|
| 433 |
+
* available, `GetVersionExW()` will be used. See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
| 434 |
+
* @since v13.11.0, v12.17.0
|
| 435 |
+
*/
|
| 436 |
+
function version(): string;
|
| 437 |
+
/**
|
| 438 |
+
* Returns a string identifying the operating system platform for which
|
| 439 |
+
* the Node.js binary was compiled. The value is set at compile time.
|
| 440 |
+
* Possible values are `'aix'`, `'darwin'`, `'freebsd'`, `'linux'`, `'openbsd'`, `'sunos'`, and `'win32'`.
|
| 441 |
+
*
|
| 442 |
+
* The return value is equivalent to `process.platform`.
|
| 443 |
+
*
|
| 444 |
+
* The value `'android'` may also be returned if Node.js is built on the Android
|
| 445 |
+
* operating system. [Android support is experimental](https://github.com/nodejs/node/blob/HEAD/BUILDING.md#androidandroid-based-devices-eg-firefox-os).
|
| 446 |
+
* @since v0.5.0
|
| 447 |
+
*/
|
| 448 |
+
function platform(): NodeJS.Platform;
|
| 449 |
+
/**
|
| 450 |
+
* Returns the machine type as a string, such as `arm`, `arm64`, `aarch64`,
|
| 451 |
+
* `mips`, `mips64`, `ppc64`, `ppc64le`, `s390x`, `i386`, `i686`, `x86_64`.
|
| 452 |
+
*
|
| 453 |
+
* 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
|
| 454 |
+
* available, `GetVersionExW()` will be used. See [https://en.wikipedia.org/wiki/Uname#Examples](https://en.wikipedia.org/wiki/Uname#Examples) for more information.
|
| 455 |
+
* @since v18.9.0, v16.18.0
|
| 456 |
+
*/
|
| 457 |
+
function machine(): string;
|
| 458 |
+
/**
|
| 459 |
+
* Returns the operating system's default directory for temporary files as a
|
| 460 |
+
* string.
|
| 461 |
+
* @since v0.9.9
|
| 462 |
+
*/
|
| 463 |
+
function tmpdir(): string;
|
| 464 |
+
/**
|
| 465 |
+
* Returns a string identifying the endianness of the CPU for which the Node.js
|
| 466 |
+
* binary was compiled.
|
| 467 |
+
*
|
| 468 |
+
* Possible values are `'BE'` for big endian and `'LE'` for little endian.
|
| 469 |
+
* @since v0.9.4
|
| 470 |
+
*/
|
| 471 |
+
function endianness(): "BE" | "LE";
|
| 472 |
+
/**
|
| 473 |
+
* Returns the scheduling priority for the process specified by `pid`. If `pid` is
|
| 474 |
+
* not provided or is `0`, the priority of the current process is returned.
|
| 475 |
+
* @since v10.10.0
|
| 476 |
+
* @param [pid=0] The process ID to retrieve scheduling priority for.
|
| 477 |
+
*/
|
| 478 |
+
function getPriority(pid?: number): number;
|
| 479 |
+
/**
|
| 480 |
+
* 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.
|
| 481 |
+
*
|
| 482 |
+
* The `priority` input must be an integer between `-20` (high priority) and `19` (low priority). Due to differences between Unix priority levels and Windows
|
| 483 |
+
* priority classes, `priority` is mapped to one of six priority constants in `os.constants.priority`. When retrieving a process priority level, this range
|
| 484 |
+
* mapping may cause the return value to be slightly different on Windows. To avoid
|
| 485 |
+
* confusion, set `priority` to one of the priority constants.
|
| 486 |
+
*
|
| 487 |
+
* On Windows, setting priority to `PRIORITY_HIGHEST` requires elevated user
|
| 488 |
+
* privileges. Otherwise the set priority will be silently reduced to `PRIORITY_HIGH`.
|
| 489 |
+
* @since v10.10.0
|
| 490 |
+
* @param [pid=0] The process ID to set scheduling priority for.
|
| 491 |
+
* @param priority The scheduling priority to assign to the process.
|
| 492 |
+
*/
|
| 493 |
+
function setPriority(priority: number): void;
|
| 494 |
+
function setPriority(pid: number, priority: number): void;
|
| 495 |
+
}
|
| 496 |
+
declare module "os" {
|
| 497 |
+
export * from "node:os";
|
| 498 |
+
}
|