Spaces:
Running
Running
Upload 953 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- Dockerfile +6 -0
- index.js +69 -0
- node_modules/.package-lock.json +964 -0
- node_modules/@gradio/client/CHANGELOG.md +239 -0
- node_modules/@gradio/client/LICENSE +201 -0
- node_modules/@gradio/client/README.md +339 -0
- node_modules/@gradio/client/dist/client.d.ts +76 -0
- node_modules/@gradio/client/dist/client.d.ts.map +1 -0
- node_modules/@gradio/client/dist/index.d.ts +4 -0
- node_modules/@gradio/client/dist/index.d.ts.map +1 -0
- node_modules/@gradio/client/dist/index.js +1596 -0
- node_modules/@gradio/client/dist/types.d.ts +105 -0
- node_modules/@gradio/client/dist/types.d.ts.map +1 -0
- node_modules/@gradio/client/dist/upload.d.ts +29 -0
- node_modules/@gradio/client/dist/upload.d.ts.map +1 -0
- node_modules/@gradio/client/dist/utils.d.ts +32 -0
- node_modules/@gradio/client/dist/utils.d.ts.map +1 -0
- node_modules/@gradio/client/dist/wrapper-6f348d45.js +0 -0
- node_modules/@gradio/client/package.json +33 -0
- node_modules/@gradio/client/src/client.node-test.ts +172 -0
- node_modules/@gradio/client/src/client.ts +1727 -0
- node_modules/@gradio/client/src/globals.d.ts +29 -0
- node_modules/@gradio/client/src/index.ts +15 -0
- node_modules/@gradio/client/src/types.ts +119 -0
- node_modules/@gradio/client/src/upload.ts +174 -0
- node_modules/@gradio/client/src/utils.ts +241 -0
- node_modules/@gradio/client/tsconfig.json +14 -0
- node_modules/@gradio/client/vite.config.js +38 -0
- node_modules/@socket.io/component-emitter/LICENSE +24 -0
- node_modules/@socket.io/component-emitter/Readme.md +74 -0
- node_modules/@socket.io/component-emitter/index.d.ts +179 -0
- node_modules/@socket.io/component-emitter/index.js +176 -0
- node_modules/@socket.io/component-emitter/index.mjs +169 -0
- node_modules/@socket.io/component-emitter/package.json +31 -0
- node_modules/@types/cookie/LICENSE +21 -0
- node_modules/@types/cookie/README.md +16 -0
- node_modules/@types/cookie/index.d.ts +135 -0
- node_modules/@types/cookie/package.json +30 -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 +32 -0
- node_modules/@types/node/LICENSE +21 -0
- node_modules/@types/node/README.md +15 -0
- node_modules/@types/node/assert.d.ts +996 -0
- node_modules/@types/node/assert/strict.d.ts +8 -0
- node_modules/@types/node/async_hooks.d.ts +539 -0
- node_modules/@types/node/buffer.d.ts +0 -0
- node_modules/@types/node/child_process.d.ts +1540 -0
- node_modules/@types/node/cluster.d.ts +432 -0
Dockerfile
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM node:latest
|
2 |
+
|
3 |
+
COPY . .
|
4 |
+
|
5 |
+
RUN npm install
|
6 |
+
CMD node index.mjs
|
index.js
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import express from "express";
|
2 |
+
import 'dotenv/config.js'
|
3 |
+
import { createServer } from "http";
|
4 |
+
import { Server } from "socket.io";
|
5 |
+
import { client } from "@gradio/client";
|
6 |
+
import { createRequire } from 'node:module'
|
7 |
+
const require = createRequire(import.meta.url);
|
8 |
+
global.EventSource = require('eventsource');
|
9 |
+
|
10 |
+
const app = express();
|
11 |
+
const httpServer = createServer(app);
|
12 |
+
app.use(express.static('public'));
|
13 |
+
const io = new Server(httpServer, { /* options */ });
|
14 |
+
|
15 |
+
io.on("connection", (socket) => {
|
16 |
+
|
17 |
+
console.log("new socket connection");
|
18 |
+
|
19 |
+
socket.on("ask_api", (client_data) => {
|
20 |
+
console.log(client_data)
|
21 |
+
console.log("trying to reach api");
|
22 |
+
asyncAPICall(client_data, socket)
|
23 |
+
});
|
24 |
+
|
25 |
+
});
|
26 |
+
|
27 |
+
async function test_servers(){
|
28 |
+
try{
|
29 |
+
const grapi_test = await client("https://gradio-hello-world.hf.space");
|
30 |
+
const apitest_result = await grapi_test.predict("/predict", [
|
31 |
+
"John",
|
32 |
+
]);
|
33 |
+
console.log(apitest_result);
|
34 |
+
}
|
35 |
+
catch(e){
|
36 |
+
console.log(e)
|
37 |
+
}
|
38 |
+
|
39 |
+
}
|
40 |
+
|
41 |
+
//test_servers()
|
42 |
+
|
43 |
+
async function asyncAPICall(data, socket) {
|
44 |
+
|
45 |
+
const grapi = await client("fffiloni/mndrm-call");
|
46 |
+
try{
|
47 |
+
const api_result = await grapi.predict("/infer", [
|
48 |
+
data[0], // blob in 'image' Image component
|
49 |
+
data[1], // string in 'Question' Textbox component
|
50 |
+
]);
|
51 |
+
console.log(api_result)
|
52 |
+
socket.emit("api_response", (api_result.data))
|
53 |
+
}
|
54 |
+
catch(e){
|
55 |
+
console.log(e)
|
56 |
+
socket.emit("api_error", ("ERROR ON API SIDE, SORRY..."))
|
57 |
+
}
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
httpServer.listen(1234);
|
64 |
+
console.log("App running on localhost:1234")
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
|
node_modules/.package-lock.json
ADDED
@@ -0,0 +1,964 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "live-vision",
|
3 |
+
"version": "1.0.0",
|
4 |
+
"lockfileVersion": 3,
|
5 |
+
"requires": true,
|
6 |
+
"packages": {
|
7 |
+
"node_modules/@gradio/client": {
|
8 |
+
"version": "0.10.1",
|
9 |
+
"resolved": "https://registry.npmjs.org/@gradio/client/-/client-0.10.1.tgz",
|
10 |
+
"integrity": "sha512-C3uWIWEqlpTuG3sfPw3K3+26Fkr+jXPL8U2lC1u7DlBm25rHdGMVX17o8ApW7XcFtznfaLceVtpnDPkDpQTJlw==",
|
11 |
+
"dependencies": {
|
12 |
+
"bufferutil": "^4.0.7",
|
13 |
+
"semiver": "^1.1.0",
|
14 |
+
"ws": "^8.13.0"
|
15 |
+
},
|
16 |
+
"engines": {
|
17 |
+
"node": ">=18.0.0"
|
18 |
+
}
|
19 |
+
},
|
20 |
+
"node_modules/@socket.io/component-emitter": {
|
21 |
+
"version": "3.1.0",
|
22 |
+
"resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz",
|
23 |
+
"integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg=="
|
24 |
+
},
|
25 |
+
"node_modules/@types/cookie": {
|
26 |
+
"version": "0.4.1",
|
27 |
+
"resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz",
|
28 |
+
"integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q=="
|
29 |
+
},
|
30 |
+
"node_modules/@types/cors": {
|
31 |
+
"version": "2.8.17",
|
32 |
+
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz",
|
33 |
+
"integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==",
|
34 |
+
"dependencies": {
|
35 |
+
"@types/node": "*"
|
36 |
+
}
|
37 |
+
},
|
38 |
+
"node_modules/@types/node": {
|
39 |
+
"version": "20.11.6",
|
40 |
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.6.tgz",
|
41 |
+
"integrity": "sha512-+EOokTnksGVgip2PbYbr3xnR7kZigh4LbybAfBAw5BpnQ+FqBYUsvCEjYd70IXKlbohQ64mzEYmMtlWUY8q//Q==",
|
42 |
+
"dependencies": {
|
43 |
+
"undici-types": "~5.26.4"
|
44 |
+
}
|
45 |
+
},
|
46 |
+
"node_modules/accepts": {
|
47 |
+
"version": "1.3.8",
|
48 |
+
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
|
49 |
+
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
|
50 |
+
"dependencies": {
|
51 |
+
"mime-types": "~2.1.34",
|
52 |
+
"negotiator": "0.6.3"
|
53 |
+
},
|
54 |
+
"engines": {
|
55 |
+
"node": ">= 0.6"
|
56 |
+
}
|
57 |
+
},
|
58 |
+
"node_modules/array-flatten": {
|
59 |
+
"version": "1.1.1",
|
60 |
+
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
61 |
+
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
|
62 |
+
},
|
63 |
+
"node_modules/base64id": {
|
64 |
+
"version": "2.0.0",
|
65 |
+
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
66 |
+
"integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==",
|
67 |
+
"engines": {
|
68 |
+
"node": "^4.5.0 || >= 5.9"
|
69 |
+
}
|
70 |
+
},
|
71 |
+
"node_modules/body-parser": {
|
72 |
+
"version": "1.20.1",
|
73 |
+
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
|
74 |
+
"integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
|
75 |
+
"dependencies": {
|
76 |
+
"bytes": "3.1.2",
|
77 |
+
"content-type": "~1.0.4",
|
78 |
+
"debug": "2.6.9",
|
79 |
+
"depd": "2.0.0",
|
80 |
+
"destroy": "1.2.0",
|
81 |
+
"http-errors": "2.0.0",
|
82 |
+
"iconv-lite": "0.4.24",
|
83 |
+
"on-finished": "2.4.1",
|
84 |
+
"qs": "6.11.0",
|
85 |
+
"raw-body": "2.5.1",
|
86 |
+
"type-is": "~1.6.18",
|
87 |
+
"unpipe": "1.0.0"
|
88 |
+
},
|
89 |
+
"engines": {
|
90 |
+
"node": ">= 0.8",
|
91 |
+
"npm": "1.2.8000 || >= 1.4.16"
|
92 |
+
}
|
93 |
+
},
|
94 |
+
"node_modules/bufferutil": {
|
95 |
+
"version": "4.0.8",
|
96 |
+
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz",
|
97 |
+
"integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==",
|
98 |
+
"hasInstallScript": true,
|
99 |
+
"dependencies": {
|
100 |
+
"node-gyp-build": "^4.3.0"
|
101 |
+
},
|
102 |
+
"engines": {
|
103 |
+
"node": ">=6.14.2"
|
104 |
+
}
|
105 |
+
},
|
106 |
+
"node_modules/bytes": {
|
107 |
+
"version": "3.1.2",
|
108 |
+
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
109 |
+
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
|
110 |
+
"engines": {
|
111 |
+
"node": ">= 0.8"
|
112 |
+
}
|
113 |
+
},
|
114 |
+
"node_modules/call-bind": {
|
115 |
+
"version": "1.0.5",
|
116 |
+
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz",
|
117 |
+
"integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==",
|
118 |
+
"dependencies": {
|
119 |
+
"function-bind": "^1.1.2",
|
120 |
+
"get-intrinsic": "^1.2.1",
|
121 |
+
"set-function-length": "^1.1.1"
|
122 |
+
},
|
123 |
+
"funding": {
|
124 |
+
"url": "https://github.com/sponsors/ljharb"
|
125 |
+
}
|
126 |
+
},
|
127 |
+
"node_modules/content-disposition": {
|
128 |
+
"version": "0.5.4",
|
129 |
+
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
130 |
+
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
|
131 |
+
"dependencies": {
|
132 |
+
"safe-buffer": "5.2.1"
|
133 |
+
},
|
134 |
+
"engines": {
|
135 |
+
"node": ">= 0.6"
|
136 |
+
}
|
137 |
+
},
|
138 |
+
"node_modules/content-type": {
|
139 |
+
"version": "1.0.5",
|
140 |
+
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
|
141 |
+
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
|
142 |
+
"engines": {
|
143 |
+
"node": ">= 0.6"
|
144 |
+
}
|
145 |
+
},
|
146 |
+
"node_modules/cookie": {
|
147 |
+
"version": "0.5.0",
|
148 |
+
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz",
|
149 |
+
"integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==",
|
150 |
+
"engines": {
|
151 |
+
"node": ">= 0.6"
|
152 |
+
}
|
153 |
+
},
|
154 |
+
"node_modules/cookie-signature": {
|
155 |
+
"version": "1.0.6",
|
156 |
+
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
157 |
+
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
|
158 |
+
},
|
159 |
+
"node_modules/cors": {
|
160 |
+
"version": "2.8.5",
|
161 |
+
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
162 |
+
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
|
163 |
+
"dependencies": {
|
164 |
+
"object-assign": "^4",
|
165 |
+
"vary": "^1"
|
166 |
+
},
|
167 |
+
"engines": {
|
168 |
+
"node": ">= 0.10"
|
169 |
+
}
|
170 |
+
},
|
171 |
+
"node_modules/debug": {
|
172 |
+
"version": "2.6.9",
|
173 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
174 |
+
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
175 |
+
"dependencies": {
|
176 |
+
"ms": "2.0.0"
|
177 |
+
}
|
178 |
+
},
|
179 |
+
"node_modules/define-data-property": {
|
180 |
+
"version": "1.1.1",
|
181 |
+
"resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz",
|
182 |
+
"integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==",
|
183 |
+
"dependencies": {
|
184 |
+
"get-intrinsic": "^1.2.1",
|
185 |
+
"gopd": "^1.0.1",
|
186 |
+
"has-property-descriptors": "^1.0.0"
|
187 |
+
},
|
188 |
+
"engines": {
|
189 |
+
"node": ">= 0.4"
|
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 |
+
"engines": {
|
197 |
+
"node": ">= 0.8"
|
198 |
+
}
|
199 |
+
},
|
200 |
+
"node_modules/destroy": {
|
201 |
+
"version": "1.2.0",
|
202 |
+
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
|
203 |
+
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
|
204 |
+
"engines": {
|
205 |
+
"node": ">= 0.8",
|
206 |
+
"npm": "1.2.8000 || >= 1.4.16"
|
207 |
+
}
|
208 |
+
},
|
209 |
+
"node_modules/dotenv": {
|
210 |
+
"version": "4.0.0",
|
211 |
+
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-4.0.0.tgz",
|
212 |
+
"integrity": "sha512-XcaMACOr3JMVcEv0Y/iUM2XaOsATRZ3U1In41/1jjK6vJZ2PZbQ1bzCG8uvaByfaBpl9gqc9QWJovpUGBXLLYQ==",
|
213 |
+
"engines": {
|
214 |
+
"node": ">=4.6.0"
|
215 |
+
}
|
216 |
+
},
|
217 |
+
"node_modules/ee-first": {
|
218 |
+
"version": "1.1.1",
|
219 |
+
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
|
220 |
+
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="
|
221 |
+
},
|
222 |
+
"node_modules/encodeurl": {
|
223 |
+
"version": "1.0.2",
|
224 |
+
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
|
225 |
+
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
|
226 |
+
"engines": {
|
227 |
+
"node": ">= 0.8"
|
228 |
+
}
|
229 |
+
},
|
230 |
+
"node_modules/engine.io": {
|
231 |
+
"version": "6.5.4",
|
232 |
+
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.4.tgz",
|
233 |
+
"integrity": "sha512-KdVSDKhVKyOi+r5uEabrDLZw2qXStVvCsEB/LN3mw4WFi6Gx50jTyuxYVCwAAC0U46FdnzP/ScKRBTXb/NiEOg==",
|
234 |
+
"dependencies": {
|
235 |
+
"@types/cookie": "^0.4.1",
|
236 |
+
"@types/cors": "^2.8.12",
|
237 |
+
"@types/node": ">=10.0.0",
|
238 |
+
"accepts": "~1.3.4",
|
239 |
+
"base64id": "2.0.0",
|
240 |
+
"cookie": "~0.4.1",
|
241 |
+
"cors": "~2.8.5",
|
242 |
+
"debug": "~4.3.1",
|
243 |
+
"engine.io-parser": "~5.2.1",
|
244 |
+
"ws": "~8.11.0"
|
245 |
+
},
|
246 |
+
"engines": {
|
247 |
+
"node": ">=10.2.0"
|
248 |
+
}
|
249 |
+
},
|
250 |
+
"node_modules/engine.io-parser": {
|
251 |
+
"version": "5.2.1",
|
252 |
+
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.1.tgz",
|
253 |
+
"integrity": "sha512-9JktcM3u18nU9N2Lz3bWeBgxVgOKpw7yhRaoxQA3FUDZzzw+9WlA6p4G4u0RixNkg14fH7EfEc/RhpurtiROTQ==",
|
254 |
+
"engines": {
|
255 |
+
"node": ">=10.0.0"
|
256 |
+
}
|
257 |
+
},
|
258 |
+
"node_modules/engine.io/node_modules/cookie": {
|
259 |
+
"version": "0.4.2",
|
260 |
+
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
261 |
+
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
|
262 |
+
"engines": {
|
263 |
+
"node": ">= 0.6"
|
264 |
+
}
|
265 |
+
},
|
266 |
+
"node_modules/engine.io/node_modules/debug": {
|
267 |
+
"version": "4.3.4",
|
268 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
269 |
+
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
270 |
+
"dependencies": {
|
271 |
+
"ms": "2.1.2"
|
272 |
+
},
|
273 |
+
"engines": {
|
274 |
+
"node": ">=6.0"
|
275 |
+
},
|
276 |
+
"peerDependenciesMeta": {
|
277 |
+
"supports-color": {
|
278 |
+
"optional": true
|
279 |
+
}
|
280 |
+
}
|
281 |
+
},
|
282 |
+
"node_modules/engine.io/node_modules/ms": {
|
283 |
+
"version": "2.1.2",
|
284 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
285 |
+
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
286 |
+
},
|
287 |
+
"node_modules/engine.io/node_modules/ws": {
|
288 |
+
"version": "8.11.0",
|
289 |
+
"resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz",
|
290 |
+
"integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==",
|
291 |
+
"engines": {
|
292 |
+
"node": ">=10.0.0"
|
293 |
+
},
|
294 |
+
"peerDependencies": {
|
295 |
+
"bufferutil": "^4.0.1",
|
296 |
+
"utf-8-validate": "^5.0.2"
|
297 |
+
},
|
298 |
+
"peerDependenciesMeta": {
|
299 |
+
"bufferutil": {
|
300 |
+
"optional": true
|
301 |
+
},
|
302 |
+
"utf-8-validate": {
|
303 |
+
"optional": true
|
304 |
+
}
|
305 |
+
}
|
306 |
+
},
|
307 |
+
"node_modules/escape-html": {
|
308 |
+
"version": "1.0.3",
|
309 |
+
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
|
310 |
+
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="
|
311 |
+
},
|
312 |
+
"node_modules/etag": {
|
313 |
+
"version": "1.8.1",
|
314 |
+
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
315 |
+
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
|
316 |
+
"engines": {
|
317 |
+
"node": ">= 0.6"
|
318 |
+
}
|
319 |
+
},
|
320 |
+
"node_modules/eventsource": {
|
321 |
+
"version": "2.0.2",
|
322 |
+
"resolved": "https://registry.npmjs.org/eventsource/-/eventsource-2.0.2.tgz",
|
323 |
+
"integrity": "sha512-IzUmBGPR3+oUG9dUeXynyNmf91/3zUSJg1lCktzKw47OXuhco54U3r9B7O4XX+Rb1Itm9OZ2b0RkTs10bICOxA==",
|
324 |
+
"engines": {
|
325 |
+
"node": ">=12.0.0"
|
326 |
+
}
|
327 |
+
},
|
328 |
+
"node_modules/express": {
|
329 |
+
"version": "4.18.2",
|
330 |
+
"resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz",
|
331 |
+
"integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==",
|
332 |
+
"dependencies": {
|
333 |
+
"accepts": "~1.3.8",
|
334 |
+
"array-flatten": "1.1.1",
|
335 |
+
"body-parser": "1.20.1",
|
336 |
+
"content-disposition": "0.5.4",
|
337 |
+
"content-type": "~1.0.4",
|
338 |
+
"cookie": "0.5.0",
|
339 |
+
"cookie-signature": "1.0.6",
|
340 |
+
"debug": "2.6.9",
|
341 |
+
"depd": "2.0.0",
|
342 |
+
"encodeurl": "~1.0.2",
|
343 |
+
"escape-html": "~1.0.3",
|
344 |
+
"etag": "~1.8.1",
|
345 |
+
"finalhandler": "1.2.0",
|
346 |
+
"fresh": "0.5.2",
|
347 |
+
"http-errors": "2.0.0",
|
348 |
+
"merge-descriptors": "1.0.1",
|
349 |
+
"methods": "~1.1.2",
|
350 |
+
"on-finished": "2.4.1",
|
351 |
+
"parseurl": "~1.3.3",
|
352 |
+
"path-to-regexp": "0.1.7",
|
353 |
+
"proxy-addr": "~2.0.7",
|
354 |
+
"qs": "6.11.0",
|
355 |
+
"range-parser": "~1.2.1",
|
356 |
+
"safe-buffer": "5.2.1",
|
357 |
+
"send": "0.18.0",
|
358 |
+
"serve-static": "1.15.0",
|
359 |
+
"setprototypeof": "1.2.0",
|
360 |
+
"statuses": "2.0.1",
|
361 |
+
"type-is": "~1.6.18",
|
362 |
+
"utils-merge": "1.0.1",
|
363 |
+
"vary": "~1.1.2"
|
364 |
+
},
|
365 |
+
"engines": {
|
366 |
+
"node": ">= 0.10.0"
|
367 |
+
}
|
368 |
+
},
|
369 |
+
"node_modules/finalhandler": {
|
370 |
+
"version": "1.2.0",
|
371 |
+
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz",
|
372 |
+
"integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==",
|
373 |
+
"dependencies": {
|
374 |
+
"debug": "2.6.9",
|
375 |
+
"encodeurl": "~1.0.2",
|
376 |
+
"escape-html": "~1.0.3",
|
377 |
+
"on-finished": "2.4.1",
|
378 |
+
"parseurl": "~1.3.3",
|
379 |
+
"statuses": "2.0.1",
|
380 |
+
"unpipe": "~1.0.0"
|
381 |
+
},
|
382 |
+
"engines": {
|
383 |
+
"node": ">= 0.8"
|
384 |
+
}
|
385 |
+
},
|
386 |
+
"node_modules/forwarded": {
|
387 |
+
"version": "0.2.0",
|
388 |
+
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
|
389 |
+
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
|
390 |
+
"engines": {
|
391 |
+
"node": ">= 0.6"
|
392 |
+
}
|
393 |
+
},
|
394 |
+
"node_modules/fresh": {
|
395 |
+
"version": "0.5.2",
|
396 |
+
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
397 |
+
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
|
398 |
+
"engines": {
|
399 |
+
"node": ">= 0.6"
|
400 |
+
}
|
401 |
+
},
|
402 |
+
"node_modules/function-bind": {
|
403 |
+
"version": "1.1.2",
|
404 |
+
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
405 |
+
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
406 |
+
"funding": {
|
407 |
+
"url": "https://github.com/sponsors/ljharb"
|
408 |
+
}
|
409 |
+
},
|
410 |
+
"node_modules/get-intrinsic": {
|
411 |
+
"version": "1.2.2",
|
412 |
+
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz",
|
413 |
+
"integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==",
|
414 |
+
"dependencies": {
|
415 |
+
"function-bind": "^1.1.2",
|
416 |
+
"has-proto": "^1.0.1",
|
417 |
+
"has-symbols": "^1.0.3",
|
418 |
+
"hasown": "^2.0.0"
|
419 |
+
},
|
420 |
+
"funding": {
|
421 |
+
"url": "https://github.com/sponsors/ljharb"
|
422 |
+
}
|
423 |
+
},
|
424 |
+
"node_modules/gopd": {
|
425 |
+
"version": "1.0.1",
|
426 |
+
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
|
427 |
+
"integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==",
|
428 |
+
"dependencies": {
|
429 |
+
"get-intrinsic": "^1.1.3"
|
430 |
+
},
|
431 |
+
"funding": {
|
432 |
+
"url": "https://github.com/sponsors/ljharb"
|
433 |
+
}
|
434 |
+
},
|
435 |
+
"node_modules/has-property-descriptors": {
|
436 |
+
"version": "1.0.1",
|
437 |
+
"resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz",
|
438 |
+
"integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==",
|
439 |
+
"dependencies": {
|
440 |
+
"get-intrinsic": "^1.2.2"
|
441 |
+
},
|
442 |
+
"funding": {
|
443 |
+
"url": "https://github.com/sponsors/ljharb"
|
444 |
+
}
|
445 |
+
},
|
446 |
+
"node_modules/has-proto": {
|
447 |
+
"version": "1.0.1",
|
448 |
+
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz",
|
449 |
+
"integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==",
|
450 |
+
"engines": {
|
451 |
+
"node": ">= 0.4"
|
452 |
+
},
|
453 |
+
"funding": {
|
454 |
+
"url": "https://github.com/sponsors/ljharb"
|
455 |
+
}
|
456 |
+
},
|
457 |
+
"node_modules/has-symbols": {
|
458 |
+
"version": "1.0.3",
|
459 |
+
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
|
460 |
+
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
|
461 |
+
"engines": {
|
462 |
+
"node": ">= 0.4"
|
463 |
+
},
|
464 |
+
"funding": {
|
465 |
+
"url": "https://github.com/sponsors/ljharb"
|
466 |
+
}
|
467 |
+
},
|
468 |
+
"node_modules/hasown": {
|
469 |
+
"version": "2.0.0",
|
470 |
+
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz",
|
471 |
+
"integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==",
|
472 |
+
"dependencies": {
|
473 |
+
"function-bind": "^1.1.2"
|
474 |
+
},
|
475 |
+
"engines": {
|
476 |
+
"node": ">= 0.4"
|
477 |
+
}
|
478 |
+
},
|
479 |
+
"node_modules/http-errors": {
|
480 |
+
"version": "2.0.0",
|
481 |
+
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
|
482 |
+
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
|
483 |
+
"dependencies": {
|
484 |
+
"depd": "2.0.0",
|
485 |
+
"inherits": "2.0.4",
|
486 |
+
"setprototypeof": "1.2.0",
|
487 |
+
"statuses": "2.0.1",
|
488 |
+
"toidentifier": "1.0.1"
|
489 |
+
},
|
490 |
+
"engines": {
|
491 |
+
"node": ">= 0.8"
|
492 |
+
}
|
493 |
+
},
|
494 |
+
"node_modules/iconv-lite": {
|
495 |
+
"version": "0.4.24",
|
496 |
+
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
497 |
+
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
|
498 |
+
"dependencies": {
|
499 |
+
"safer-buffer": ">= 2.1.2 < 3"
|
500 |
+
},
|
501 |
+
"engines": {
|
502 |
+
"node": ">=0.10.0"
|
503 |
+
}
|
504 |
+
},
|
505 |
+
"node_modules/inherits": {
|
506 |
+
"version": "2.0.4",
|
507 |
+
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
508 |
+
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
509 |
+
},
|
510 |
+
"node_modules/ipaddr.js": {
|
511 |
+
"version": "1.9.1",
|
512 |
+
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
513 |
+
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
|
514 |
+
"engines": {
|
515 |
+
"node": ">= 0.10"
|
516 |
+
}
|
517 |
+
},
|
518 |
+
"node_modules/media-typer": {
|
519 |
+
"version": "0.3.0",
|
520 |
+
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
521 |
+
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
|
522 |
+
"engines": {
|
523 |
+
"node": ">= 0.6"
|
524 |
+
}
|
525 |
+
},
|
526 |
+
"node_modules/merge-descriptors": {
|
527 |
+
"version": "1.0.1",
|
528 |
+
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
|
529 |
+
"integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w=="
|
530 |
+
},
|
531 |
+
"node_modules/methods": {
|
532 |
+
"version": "1.1.2",
|
533 |
+
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
|
534 |
+
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
|
535 |
+
"engines": {
|
536 |
+
"node": ">= 0.6"
|
537 |
+
}
|
538 |
+
},
|
539 |
+
"node_modules/mime": {
|
540 |
+
"version": "1.6.0",
|
541 |
+
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
|
542 |
+
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
|
543 |
+
"bin": {
|
544 |
+
"mime": "cli.js"
|
545 |
+
},
|
546 |
+
"engines": {
|
547 |
+
"node": ">=4"
|
548 |
+
}
|
549 |
+
},
|
550 |
+
"node_modules/mime-db": {
|
551 |
+
"version": "1.52.0",
|
552 |
+
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
553 |
+
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
554 |
+
"engines": {
|
555 |
+
"node": ">= 0.6"
|
556 |
+
}
|
557 |
+
},
|
558 |
+
"node_modules/mime-types": {
|
559 |
+
"version": "2.1.35",
|
560 |
+
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
561 |
+
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
562 |
+
"dependencies": {
|
563 |
+
"mime-db": "1.52.0"
|
564 |
+
},
|
565 |
+
"engines": {
|
566 |
+
"node": ">= 0.6"
|
567 |
+
}
|
568 |
+
},
|
569 |
+
"node_modules/ms": {
|
570 |
+
"version": "2.0.0",
|
571 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
572 |
+
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
573 |
+
},
|
574 |
+
"node_modules/negotiator": {
|
575 |
+
"version": "0.6.3",
|
576 |
+
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
|
577 |
+
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
|
578 |
+
"engines": {
|
579 |
+
"node": ">= 0.6"
|
580 |
+
}
|
581 |
+
},
|
582 |
+
"node_modules/node-gyp-build": {
|
583 |
+
"version": "4.8.0",
|
584 |
+
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz",
|
585 |
+
"integrity": "sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og==",
|
586 |
+
"bin": {
|
587 |
+
"node-gyp-build": "bin.js",
|
588 |
+
"node-gyp-build-optional": "optional.js",
|
589 |
+
"node-gyp-build-test": "build-test.js"
|
590 |
+
}
|
591 |
+
},
|
592 |
+
"node_modules/object-assign": {
|
593 |
+
"version": "4.1.1",
|
594 |
+
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
595 |
+
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
596 |
+
"engines": {
|
597 |
+
"node": ">=0.10.0"
|
598 |
+
}
|
599 |
+
},
|
600 |
+
"node_modules/object-inspect": {
|
601 |
+
"version": "1.13.1",
|
602 |
+
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz",
|
603 |
+
"integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==",
|
604 |
+
"funding": {
|
605 |
+
"url": "https://github.com/sponsors/ljharb"
|
606 |
+
}
|
607 |
+
},
|
608 |
+
"node_modules/on-finished": {
|
609 |
+
"version": "2.4.1",
|
610 |
+
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
|
611 |
+
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
|
612 |
+
"dependencies": {
|
613 |
+
"ee-first": "1.1.1"
|
614 |
+
},
|
615 |
+
"engines": {
|
616 |
+
"node": ">= 0.8"
|
617 |
+
}
|
618 |
+
},
|
619 |
+
"node_modules/parseurl": {
|
620 |
+
"version": "1.3.3",
|
621 |
+
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
622 |
+
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
|
623 |
+
"engines": {
|
624 |
+
"node": ">= 0.8"
|
625 |
+
}
|
626 |
+
},
|
627 |
+
"node_modules/path-to-regexp": {
|
628 |
+
"version": "0.1.7",
|
629 |
+
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
630 |
+
"integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ=="
|
631 |
+
},
|
632 |
+
"node_modules/proxy-addr": {
|
633 |
+
"version": "2.0.7",
|
634 |
+
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
635 |
+
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
|
636 |
+
"dependencies": {
|
637 |
+
"forwarded": "0.2.0",
|
638 |
+
"ipaddr.js": "1.9.1"
|
639 |
+
},
|
640 |
+
"engines": {
|
641 |
+
"node": ">= 0.10"
|
642 |
+
}
|
643 |
+
},
|
644 |
+
"node_modules/qs": {
|
645 |
+
"version": "6.11.0",
|
646 |
+
"resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz",
|
647 |
+
"integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==",
|
648 |
+
"dependencies": {
|
649 |
+
"side-channel": "^1.0.4"
|
650 |
+
},
|
651 |
+
"engines": {
|
652 |
+
"node": ">=0.6"
|
653 |
+
},
|
654 |
+
"funding": {
|
655 |
+
"url": "https://github.com/sponsors/ljharb"
|
656 |
+
}
|
657 |
+
},
|
658 |
+
"node_modules/range-parser": {
|
659 |
+
"version": "1.2.1",
|
660 |
+
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
661 |
+
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
|
662 |
+
"engines": {
|
663 |
+
"node": ">= 0.6"
|
664 |
+
}
|
665 |
+
},
|
666 |
+
"node_modules/raw-body": {
|
667 |
+
"version": "2.5.1",
|
668 |
+
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
|
669 |
+
"integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
|
670 |
+
"dependencies": {
|
671 |
+
"bytes": "3.1.2",
|
672 |
+
"http-errors": "2.0.0",
|
673 |
+
"iconv-lite": "0.4.24",
|
674 |
+
"unpipe": "1.0.0"
|
675 |
+
},
|
676 |
+
"engines": {
|
677 |
+
"node": ">= 0.8"
|
678 |
+
}
|
679 |
+
},
|
680 |
+
"node_modules/safe-buffer": {
|
681 |
+
"version": "5.2.1",
|
682 |
+
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
683 |
+
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
684 |
+
"funding": [
|
685 |
+
{
|
686 |
+
"type": "github",
|
687 |
+
"url": "https://github.com/sponsors/feross"
|
688 |
+
},
|
689 |
+
{
|
690 |
+
"type": "patreon",
|
691 |
+
"url": "https://www.patreon.com/feross"
|
692 |
+
},
|
693 |
+
{
|
694 |
+
"type": "consulting",
|
695 |
+
"url": "https://feross.org/support"
|
696 |
+
}
|
697 |
+
]
|
698 |
+
},
|
699 |
+
"node_modules/safer-buffer": {
|
700 |
+
"version": "2.1.2",
|
701 |
+
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
702 |
+
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
703 |
+
},
|
704 |
+
"node_modules/semiver": {
|
705 |
+
"version": "1.1.0",
|
706 |
+
"resolved": "https://registry.npmjs.org/semiver/-/semiver-1.1.0.tgz",
|
707 |
+
"integrity": "sha512-QNI2ChmuioGC1/xjyYwyZYADILWyW6AmS1UH6gDj/SFUUUS4MBAWs/7mxnkRPc/F4iHezDP+O8t0dO8WHiEOdg==",
|
708 |
+
"engines": {
|
709 |
+
"node": ">=6"
|
710 |
+
}
|
711 |
+
},
|
712 |
+
"node_modules/send": {
|
713 |
+
"version": "0.18.0",
|
714 |
+
"resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz",
|
715 |
+
"integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==",
|
716 |
+
"dependencies": {
|
717 |
+
"debug": "2.6.9",
|
718 |
+
"depd": "2.0.0",
|
719 |
+
"destroy": "1.2.0",
|
720 |
+
"encodeurl": "~1.0.2",
|
721 |
+
"escape-html": "~1.0.3",
|
722 |
+
"etag": "~1.8.1",
|
723 |
+
"fresh": "0.5.2",
|
724 |
+
"http-errors": "2.0.0",
|
725 |
+
"mime": "1.6.0",
|
726 |
+
"ms": "2.1.3",
|
727 |
+
"on-finished": "2.4.1",
|
728 |
+
"range-parser": "~1.2.1",
|
729 |
+
"statuses": "2.0.1"
|
730 |
+
},
|
731 |
+
"engines": {
|
732 |
+
"node": ">= 0.8.0"
|
733 |
+
}
|
734 |
+
},
|
735 |
+
"node_modules/send/node_modules/ms": {
|
736 |
+
"version": "2.1.3",
|
737 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
738 |
+
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
|
739 |
+
},
|
740 |
+
"node_modules/serve-static": {
|
741 |
+
"version": "1.15.0",
|
742 |
+
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz",
|
743 |
+
"integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==",
|
744 |
+
"dependencies": {
|
745 |
+
"encodeurl": "~1.0.2",
|
746 |
+
"escape-html": "~1.0.3",
|
747 |
+
"parseurl": "~1.3.3",
|
748 |
+
"send": "0.18.0"
|
749 |
+
},
|
750 |
+
"engines": {
|
751 |
+
"node": ">= 0.8.0"
|
752 |
+
}
|
753 |
+
},
|
754 |
+
"node_modules/set-function-length": {
|
755 |
+
"version": "1.2.0",
|
756 |
+
"resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.0.tgz",
|
757 |
+
"integrity": "sha512-4DBHDoyHlM1IRPGYcoxexgh67y4ueR53FKV1yyxwFMY7aCqcN/38M1+SwZ/qJQ8iLv7+ck385ot4CcisOAPT9w==",
|
758 |
+
"dependencies": {
|
759 |
+
"define-data-property": "^1.1.1",
|
760 |
+
"function-bind": "^1.1.2",
|
761 |
+
"get-intrinsic": "^1.2.2",
|
762 |
+
"gopd": "^1.0.1",
|
763 |
+
"has-property-descriptors": "^1.0.1"
|
764 |
+
},
|
765 |
+
"engines": {
|
766 |
+
"node": ">= 0.4"
|
767 |
+
}
|
768 |
+
},
|
769 |
+
"node_modules/setprototypeof": {
|
770 |
+
"version": "1.2.0",
|
771 |
+
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
772 |
+
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
|
773 |
+
},
|
774 |
+
"node_modules/side-channel": {
|
775 |
+
"version": "1.0.4",
|
776 |
+
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
|
777 |
+
"integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
|
778 |
+
"dependencies": {
|
779 |
+
"call-bind": "^1.0.0",
|
780 |
+
"get-intrinsic": "^1.0.2",
|
781 |
+
"object-inspect": "^1.9.0"
|
782 |
+
},
|
783 |
+
"funding": {
|
784 |
+
"url": "https://github.com/sponsors/ljharb"
|
785 |
+
}
|
786 |
+
},
|
787 |
+
"node_modules/socket.io": {
|
788 |
+
"version": "4.7.4",
|
789 |
+
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.4.tgz",
|
790 |
+
"integrity": "sha512-DcotgfP1Zg9iP/dH9zvAQcWrE0TtbMVwXmlV4T4mqsvY+gw+LqUGPfx2AoVyRk0FLME+GQhufDMyacFmw7ksqw==",
|
791 |
+
"dependencies": {
|
792 |
+
"accepts": "~1.3.4",
|
793 |
+
"base64id": "~2.0.0",
|
794 |
+
"cors": "~2.8.5",
|
795 |
+
"debug": "~4.3.2",
|
796 |
+
"engine.io": "~6.5.2",
|
797 |
+
"socket.io-adapter": "~2.5.2",
|
798 |
+
"socket.io-parser": "~4.2.4"
|
799 |
+
},
|
800 |
+
"engines": {
|
801 |
+
"node": ">=10.2.0"
|
802 |
+
}
|
803 |
+
},
|
804 |
+
"node_modules/socket.io-adapter": {
|
805 |
+
"version": "2.5.2",
|
806 |
+
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.2.tgz",
|
807 |
+
"integrity": "sha512-87C3LO/NOMc+eMcpcxUBebGjkpMDkNBS9tf7KJqcDsmL936EChtVva71Dw2q4tQcuVC+hAUy4an2NO/sYXmwRA==",
|
808 |
+
"dependencies": {
|
809 |
+
"ws": "~8.11.0"
|
810 |
+
}
|
811 |
+
},
|
812 |
+
"node_modules/socket.io-adapter/node_modules/ws": {
|
813 |
+
"version": "8.11.0",
|
814 |
+
"resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz",
|
815 |
+
"integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==",
|
816 |
+
"engines": {
|
817 |
+
"node": ">=10.0.0"
|
818 |
+
},
|
819 |
+
"peerDependencies": {
|
820 |
+
"bufferutil": "^4.0.1",
|
821 |
+
"utf-8-validate": "^5.0.2"
|
822 |
+
},
|
823 |
+
"peerDependenciesMeta": {
|
824 |
+
"bufferutil": {
|
825 |
+
"optional": true
|
826 |
+
},
|
827 |
+
"utf-8-validate": {
|
828 |
+
"optional": true
|
829 |
+
}
|
830 |
+
}
|
831 |
+
},
|
832 |
+
"node_modules/socket.io-parser": {
|
833 |
+
"version": "4.2.4",
|
834 |
+
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz",
|
835 |
+
"integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==",
|
836 |
+
"dependencies": {
|
837 |
+
"@socket.io/component-emitter": "~3.1.0",
|
838 |
+
"debug": "~4.3.1"
|
839 |
+
},
|
840 |
+
"engines": {
|
841 |
+
"node": ">=10.0.0"
|
842 |
+
}
|
843 |
+
},
|
844 |
+
"node_modules/socket.io-parser/node_modules/debug": {
|
845 |
+
"version": "4.3.4",
|
846 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
847 |
+
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
848 |
+
"dependencies": {
|
849 |
+
"ms": "2.1.2"
|
850 |
+
},
|
851 |
+
"engines": {
|
852 |
+
"node": ">=6.0"
|
853 |
+
},
|
854 |
+
"peerDependenciesMeta": {
|
855 |
+
"supports-color": {
|
856 |
+
"optional": true
|
857 |
+
}
|
858 |
+
}
|
859 |
+
},
|
860 |
+
"node_modules/socket.io-parser/node_modules/ms": {
|
861 |
+
"version": "2.1.2",
|
862 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
863 |
+
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
864 |
+
},
|
865 |
+
"node_modules/socket.io/node_modules/debug": {
|
866 |
+
"version": "4.3.4",
|
867 |
+
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
868 |
+
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
|
869 |
+
"dependencies": {
|
870 |
+
"ms": "2.1.2"
|
871 |
+
},
|
872 |
+
"engines": {
|
873 |
+
"node": ">=6.0"
|
874 |
+
},
|
875 |
+
"peerDependenciesMeta": {
|
876 |
+
"supports-color": {
|
877 |
+
"optional": true
|
878 |
+
}
|
879 |
+
}
|
880 |
+
},
|
881 |
+
"node_modules/socket.io/node_modules/ms": {
|
882 |
+
"version": "2.1.2",
|
883 |
+
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
884 |
+
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
885 |
+
},
|
886 |
+
"node_modules/statuses": {
|
887 |
+
"version": "2.0.1",
|
888 |
+
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
|
889 |
+
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
|
890 |
+
"engines": {
|
891 |
+
"node": ">= 0.8"
|
892 |
+
}
|
893 |
+
},
|
894 |
+
"node_modules/toidentifier": {
|
895 |
+
"version": "1.0.1",
|
896 |
+
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
|
897 |
+
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
|
898 |
+
"engines": {
|
899 |
+
"node": ">=0.6"
|
900 |
+
}
|
901 |
+
},
|
902 |
+
"node_modules/type-is": {
|
903 |
+
"version": "1.6.18",
|
904 |
+
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
905 |
+
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
|
906 |
+
"dependencies": {
|
907 |
+
"media-typer": "0.3.0",
|
908 |
+
"mime-types": "~2.1.24"
|
909 |
+
},
|
910 |
+
"engines": {
|
911 |
+
"node": ">= 0.6"
|
912 |
+
}
|
913 |
+
},
|
914 |
+
"node_modules/undici-types": {
|
915 |
+
"version": "5.26.5",
|
916 |
+
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
917 |
+
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
|
918 |
+
},
|
919 |
+
"node_modules/unpipe": {
|
920 |
+
"version": "1.0.0",
|
921 |
+
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
922 |
+
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
|
923 |
+
"engines": {
|
924 |
+
"node": ">= 0.8"
|
925 |
+
}
|
926 |
+
},
|
927 |
+
"node_modules/utils-merge": {
|
928 |
+
"version": "1.0.1",
|
929 |
+
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
930 |
+
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
|
931 |
+
"engines": {
|
932 |
+
"node": ">= 0.4.0"
|
933 |
+
}
|
934 |
+
},
|
935 |
+
"node_modules/vary": {
|
936 |
+
"version": "1.1.2",
|
937 |
+
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
938 |
+
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
|
939 |
+
"engines": {
|
940 |
+
"node": ">= 0.8"
|
941 |
+
}
|
942 |
+
},
|
943 |
+
"node_modules/ws": {
|
944 |
+
"version": "8.16.0",
|
945 |
+
"resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz",
|
946 |
+
"integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==",
|
947 |
+
"engines": {
|
948 |
+
"node": ">=10.0.0"
|
949 |
+
},
|
950 |
+
"peerDependencies": {
|
951 |
+
"bufferutil": "^4.0.1",
|
952 |
+
"utf-8-validate": ">=5.0.2"
|
953 |
+
},
|
954 |
+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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# @gradio/client
|
2 |
+
|
3 |
+
## 0.10.1
|
4 |
+
|
5 |
+
### Fixes
|
6 |
+
|
7 |
+
- [#7055](https://github.com/gradio-app/gradio/pull/7055) [`3c3cf86`](https://github.com/gradio-app/gradio/commit/3c3cf8618a8cad1ef66a7f96664923d2c9f5e0e2) - Fix UI freeze on rapid generators. Thanks [@aliabid94](https://github.com/aliabid94)!
|
8 |
+
|
9 |
+
## 0.10.0
|
10 |
+
|
11 |
+
### Features
|
12 |
+
|
13 |
+
- [#6931](https://github.com/gradio-app/gradio/pull/6931) [`6c863af`](https://github.com/gradio-app/gradio/commit/6c863af92fa9ceb5c638857eb22cc5ddb718d549) - Fix functional tests. Thanks [@aliabid94](https://github.com/aliabid94)!
|
14 |
+
- [#6820](https://github.com/gradio-app/gradio/pull/6820) [`649cd4d`](https://github.com/gradio-app/gradio/commit/649cd4d68041d11fcbe31f8efa455345ac49fc74) - Use `EventSource_factory` in `open_stream()` for Wasm. Thanks [@whitphx](https://github.com/whitphx)!
|
15 |
+
|
16 |
+
## 0.9.4
|
17 |
+
|
18 |
+
### Fixes
|
19 |
+
|
20 |
+
- [#6863](https://github.com/gradio-app/gradio/pull/6863) [`d406855`](https://github.com/gradio-app/gradio/commit/d4068557953746662235d595ec435c42ceb24414) - Fix JS Client when app is running behind a proxy. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
|
21 |
+
|
22 |
+
## 0.9.3
|
23 |
+
|
24 |
+
### Features
|
25 |
+
|
26 |
+
- [#6814](https://github.com/gradio-app/gradio/pull/6814) [`828fb9e`](https://github.com/gradio-app/gradio/commit/828fb9e6ce15b6ea08318675a2361117596a1b5d) - Refactor queue so that there are separate queues for each concurrency id. Thanks [@aliabid94](https://github.com/aliabid94)!
|
27 |
+
|
28 |
+
## 0.9.2
|
29 |
+
|
30 |
+
### Features
|
31 |
+
|
32 |
+
- [#6798](https://github.com/gradio-app/gradio/pull/6798) [`245d58e`](https://github.com/gradio-app/gradio/commit/245d58eff788e8d44a59d37a2d9b26d0f08a62b4) - Improve how server/js client handle unexpected errors. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
|
33 |
+
|
34 |
+
## 0.9.1
|
35 |
+
|
36 |
+
### Fixes
|
37 |
+
|
38 |
+
- [#6693](https://github.com/gradio-app/gradio/pull/6693) [`34f9431`](https://github.com/gradio-app/gradio/commit/34f943101bf7dd6b8a8974a6131c1ed7c4a0dac0) - Python client properly handles hearbeat and log messages. Also handles responses longer than 65k. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
|
39 |
+
|
40 |
+
## 0.9.0
|
41 |
+
|
42 |
+
### Features
|
43 |
+
|
44 |
+
- [#6398](https://github.com/gradio-app/gradio/pull/6398) [`67ddd40`](https://github.com/gradio-app/gradio/commit/67ddd40b4b70d3a37cb1637c33620f8d197dbee0) - Lite v4. Thanks [@whitphx](https://github.com/whitphx)!
|
45 |
+
|
46 |
+
### Fixes
|
47 |
+
|
48 |
+
- [#6556](https://github.com/gradio-app/gradio/pull/6556) [`d76bcaa`](https://github.com/gradio-app/gradio/commit/d76bcaaaf0734aaf49a680f94ea9d4d22a602e70) - Fix api event drops. Thanks [@aliabid94](https://github.com/aliabid94)!
|
49 |
+
|
50 |
+
## 0.8.2
|
51 |
+
|
52 |
+
### Features
|
53 |
+
|
54 |
+
- [#6511](https://github.com/gradio-app/gradio/pull/6511) [`71f1a1f99`](https://github.com/gradio-app/gradio/commit/71f1a1f9931489d465c2c1302a5c8d768a3cd23a) - Mark `FileData.orig_name` optional on the frontend aligning the type definition on the Python side. Thanks [@whitphx](https://github.com/whitphx)!
|
55 |
+
|
56 |
+
## 0.8.1
|
57 |
+
|
58 |
+
### Fixes
|
59 |
+
|
60 |
+
- [#6383](https://github.com/gradio-app/gradio/pull/6383) [`324867f63`](https://github.com/gradio-app/gradio/commit/324867f63c920113d89a565892aa596cf8b1e486) - Fix event target. Thanks [@aliabid94](https://github.com/aliabid94)!
|
61 |
+
|
62 |
+
## 0.8.0
|
63 |
+
|
64 |
+
### Features
|
65 |
+
|
66 |
+
- [#6307](https://github.com/gradio-app/gradio/pull/6307) [`f1409f95e`](https://github.com/gradio-app/gradio/commit/f1409f95ed39c5565bed6a601e41f94e30196a57) - Provide status updates on file uploads. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
|
67 |
+
|
68 |
+
## 0.7.2
|
69 |
+
|
70 |
+
### Fixes
|
71 |
+
|
72 |
+
- [#6327](https://github.com/gradio-app/gradio/pull/6327) [`bca6c2c80`](https://github.com/gradio-app/gradio/commit/bca6c2c80f7e5062427019de45c282238388af95) - Restore query parameters in request. Thanks [@aliabid94](https://github.com/aliabid94)!
|
73 |
+
|
74 |
+
## 0.7.1
|
75 |
+
|
76 |
+
### Features
|
77 |
+
|
78 |
+
- [#6137](https://github.com/gradio-app/gradio/pull/6137) [`2ba14b284`](https://github.com/gradio-app/gradio/commit/2ba14b284f908aa13859f4337167a157075a68eb) - JS Param. Thanks [@dawoodkhan82](https://github.com/dawoodkhan82)!
|
79 |
+
|
80 |
+
## 0.7.0
|
81 |
+
|
82 |
+
### Features
|
83 |
+
|
84 |
+
- [#5498](https://github.com/gradio-app/gradio/pull/5498) [`287fe6782`](https://github.com/gradio-app/gradio/commit/287fe6782825479513e79a5cf0ba0fbfe51443d7) - fix circular dependency with client + upload. Thanks [@pngwn](https://github.com/pngwn)!
|
85 |
+
- [#5498](https://github.com/gradio-app/gradio/pull/5498) [`287fe6782`](https://github.com/gradio-app/gradio/commit/287fe6782825479513e79a5cf0ba0fbfe51443d7) - Image v4. Thanks [@pngwn](https://github.com/pngwn)!
|
86 |
+
- [#5498](https://github.com/gradio-app/gradio/pull/5498) [`287fe6782`](https://github.com/gradio-app/gradio/commit/287fe6782825479513e79a5cf0ba0fbfe51443d7) - Swap websockets for SSE. Thanks [@pngwn](https://github.com/pngwn)!
|
87 |
+
|
88 |
+
## 0.7.0-beta.1
|
89 |
+
|
90 |
+
### Features
|
91 |
+
|
92 |
+
- [#6143](https://github.com/gradio-app/gradio/pull/6143) [`e4f7b4b40`](https://github.com/gradio-app/gradio/commit/e4f7b4b409323b01aa01b39e15ce6139e29aa073) - fix circular dependency with client + upload. Thanks [@pngwn](https://github.com/pngwn)!
|
93 |
+
- [#6094](https://github.com/gradio-app/gradio/pull/6094) [`c476bd5a5`](https://github.com/gradio-app/gradio/commit/c476bd5a5b70836163b9c69bf4bfe068b17fbe13) - Image v4. Thanks [@pngwn](https://github.com/pngwn)!
|
94 |
+
- [#6069](https://github.com/gradio-app/gradio/pull/6069) [`bf127e124`](https://github.com/gradio-app/gradio/commit/bf127e1241a41401e144874ea468dff8474eb505) - Swap websockets for SSE. Thanks [@aliabid94](https://github.com/aliabid94)!
|
95 |
+
|
96 |
+
## 0.7.0-beta.0
|
97 |
+
|
98 |
+
### Features
|
99 |
+
|
100 |
+
- [#6016](https://github.com/gradio-app/gradio/pull/6016) [`83e947676`](https://github.com/gradio-app/gradio/commit/83e947676d327ca2ab6ae2a2d710c78961c771a0) - Format js in v4 branch. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
|
101 |
+
|
102 |
+
### Fixes
|
103 |
+
|
104 |
+
- [#6046](https://github.com/gradio-app/gradio/pull/6046) [`dbb7de5e0`](https://github.com/gradio-app/gradio/commit/dbb7de5e02c53fee05889d696d764d212cb96c74) - fix tests. Thanks [@pngwn](https://github.com/pngwn)!
|
105 |
+
|
106 |
+
## 0.6.0
|
107 |
+
|
108 |
+
### Features
|
109 |
+
|
110 |
+
- [#5972](https://github.com/gradio-app/gradio/pull/5972) [`11a300791`](https://github.com/gradio-app/gradio/commit/11a3007916071f0791844b0a37f0fb4cec69cea3) - Lite: Support opening the entrypoint HTML page directly in browser via the `file:` protocol. Thanks [@whitphx](https://github.com/whitphx)!
|
111 |
+
|
112 |
+
## 0.5.2
|
113 |
+
|
114 |
+
### Fixes
|
115 |
+
|
116 |
+
- [#5840](https://github.com/gradio-app/gradio/pull/5840) [`4e62b8493`](https://github.com/gradio-app/gradio/commit/4e62b8493dfce50bafafe49f1a5deb929d822103) - Ensure websocket polyfill doesn't load if there is already a `global.Webocket` property set. Thanks [@Jay2theWhy](https://github.com/Jay2theWhy)!
|
117 |
+
|
118 |
+
## 0.5.1
|
119 |
+
|
120 |
+
### Fixes
|
121 |
+
|
122 |
+
- [#5816](https://github.com/gradio-app/gradio/pull/5816) [`796145e2c`](https://github.com/gradio-app/gradio/commit/796145e2c48c4087bec17f8ec0be4ceee47170cb) - Fix calls to the component server so that `gr.FileExplorer` works on Spaces. Thanks [@abidlabs](https://github.com/abidlabs)!
|
123 |
+
|
124 |
+
## 0.5.0
|
125 |
+
|
126 |
+
### Highlights
|
127 |
+
|
128 |
+
#### new `FileExplorer` component ([#5672](https://github.com/gradio-app/gradio/pull/5672) [`e4a307ed6`](https://github.com/gradio-app/gradio/commit/e4a307ed6cde3bbdf4ff2f17655739addeec941e))
|
129 |
+
|
130 |
+
Thanks to a new capability that allows components to communicate directly with the server _without_ passing data via the value, we have created a new `FileExplorer` component.
|
131 |
+
|
132 |
+
This component allows you to populate the explorer by passing a glob, but only provides the selected file(s) in your prediction function.
|
133 |
+
|
134 |
+
Users can then navigate the virtual filesystem and select files which will be accessible in your predict function. This component will allow developers to build more complex spaces, with more flexible input options.
|
135 |
+
|
136 |
+
![output](https://github.com/pngwn/MDsveX/assets/12937446/ef108f0b-0e84-4292-9984-9dc66b3e144d)
|
137 |
+
|
138 |
+
For more information check the [`FileExplorer` documentation](https://gradio.app/docs/fileexplorer).
|
139 |
+
|
140 |
+
Thanks [@aliabid94](https://github.com/aliabid94)!
|
141 |
+
|
142 |
+
### Features
|
143 |
+
|
144 |
+
- [#5787](https://github.com/gradio-app/gradio/pull/5787) [`caeee8bf7`](https://github.com/gradio-app/gradio/commit/caeee8bf7821fd5fe2f936ed82483bed00f613ec) - ensure the client does not depend on `window` when running in a node environment. Thanks [@gibiee](https://github.com/gibiee)!
|
145 |
+
|
146 |
+
### Fixes
|
147 |
+
|
148 |
+
- [#5776](https://github.com/gradio-app/gradio/pull/5776) [`c0fef4454`](https://github.com/gradio-app/gradio/commit/c0fef44541bfa61568bdcfcdfc7d7d79869ab1df) - Revert replica proxy logic and instead implement using the `root` variable. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
|
149 |
+
|
150 |
+
## 0.4.2
|
151 |
+
|
152 |
+
### Features
|
153 |
+
|
154 |
+
- [#5124](https://github.com/gradio-app/gradio/pull/5124) [`6e56a0d9b`](https://github.com/gradio-app/gradio/commit/6e56a0d9b0c863e76c69e1183d9d40196922b4cd) - Lite: Websocket queueing. Thanks [@whitphx](https://github.com/whitphx)!
|
155 |
+
|
156 |
+
## 0.4.1
|
157 |
+
|
158 |
+
### Fixes
|
159 |
+
|
160 |
+
- [#5705](https://github.com/gradio-app/gradio/pull/5705) [`78e7cf516`](https://github.com/gradio-app/gradio/commit/78e7cf5163e8d205e8999428fce4c02dbdece25f) - ensure internal data has updated before dispatching `success` or `then` events. Thanks [@pngwn](https://github.com/pngwn)!
|
161 |
+
|
162 |
+
## 0.4.0
|
163 |
+
|
164 |
+
### Features
|
165 |
+
|
166 |
+
- [#5682](https://github.com/gradio-app/gradio/pull/5682) [`c57f1b75e`](https://github.com/gradio-app/gradio/commit/c57f1b75e272c76b0af4d6bd0c7f44743ff34f26) - Fix functional tests. Thanks [@abidlabs](https://github.com/abidlabs)!
|
167 |
+
- [#5681](https://github.com/gradio-app/gradio/pull/5681) [`40de3d217`](https://github.com/gradio-app/gradio/commit/40de3d2178b61ebe424b6f6228f94c0c6f679bea) - add query parameters to the `gr.Request` object through the `query_params` attribute. Thanks [@DarhkVoyd](https://github.com/DarhkVoyd)!
|
168 |
+
- [#5653](https://github.com/gradio-app/gradio/pull/5653) [`ea0e00b20`](https://github.com/gradio-app/gradio/commit/ea0e00b207b4b90a10e9d054c4202d4e705a29ba) - Prevent Clients from accessing API endpoints that set `api_name=False`. Thanks [@abidlabs](https://github.com/abidlabs)!
|
169 |
+
|
170 |
+
## 0.3.1
|
171 |
+
|
172 |
+
### Fixes
|
173 |
+
|
174 |
+
- [#5412](https://github.com/gradio-app/gradio/pull/5412) [`26fef8c7`](https://github.com/gradio-app/gradio/commit/26fef8c7f85a006c7e25cdbed1792df19c512d02) - Skip view_api request in js client when auth enabled. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
|
175 |
+
|
176 |
+
## 0.3.0
|
177 |
+
|
178 |
+
### Features
|
179 |
+
|
180 |
+
- [#5267](https://github.com/gradio-app/gradio/pull/5267) [`119c8343`](https://github.com/gradio-app/gradio/commit/119c834331bfae60d4742c8f20e9cdecdd67e8c2) - Faster reload mode. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
|
181 |
+
|
182 |
+
## 0.2.1
|
183 |
+
|
184 |
+
### Features
|
185 |
+
|
186 |
+
- [#5173](https://github.com/gradio-app/gradio/pull/5173) [`730f0c1d`](https://github.com/gradio-app/gradio/commit/730f0c1d54792eb11359e40c9f2326e8a6e39203) - Ensure gradio client works as expected for functions that return nothing. Thanks [@raymondtri](https://github.com/raymondtri)!
|
187 |
+
|
188 |
+
## 0.2.0
|
189 |
+
|
190 |
+
### Features
|
191 |
+
|
192 |
+
- [#5133](https://github.com/gradio-app/gradio/pull/5133) [`61129052`](https://github.com/gradio-app/gradio/commit/61129052ed1391a75c825c891d57fa0ad6c09fc8) - Update dependency esbuild to ^0.19.0. Thanks [@renovate](https://github.com/apps/renovate)!
|
193 |
+
- [#5035](https://github.com/gradio-app/gradio/pull/5035) [`8b4eb8ca`](https://github.com/gradio-app/gradio/commit/8b4eb8cac9ea07bde31b44e2006ca2b7b5f4de36) - JS Client: Fixes cannot read properties of null (reading 'is_file'). Thanks [@raymondtri](https://github.com/raymondtri)!
|
194 |
+
|
195 |
+
### Fixes
|
196 |
+
|
197 |
+
- [#5075](https://github.com/gradio-app/gradio/pull/5075) [`67265a58`](https://github.com/gradio-app/gradio/commit/67265a58027ef1f9e4c0eb849a532f72eaebde48) - Allow supporting >1000 files in `gr.File()` and `gr.UploadButton()`. Thanks [@abidlabs](https://github.com/abidlabs)!
|
198 |
+
|
199 |
+
## 0.1.4
|
200 |
+
|
201 |
+
### Patch Changes
|
202 |
+
|
203 |
+
- [#4717](https://github.com/gradio-app/gradio/pull/4717) [`ab5d1ea0`](https://github.com/gradio-app/gradio/commit/ab5d1ea0de87ed888779b66fd2a705583bd29e02) Thanks [@whitphx](https://github.com/whitphx)! - Fix the package description
|
204 |
+
|
205 |
+
## 0.1.3
|
206 |
+
|
207 |
+
### Patch Changes
|
208 |
+
|
209 |
+
- [#4357](https://github.com/gradio-app/gradio/pull/4357) [`0dbd8f7f`](https://github.com/gradio-app/gradio/commit/0dbd8f7fee4b4877f783fa7bc493f98bbfc3d01d) Thanks [@pngwn](https://github.com/pngwn)! - Various internal refactors and cleanups.
|
210 |
+
|
211 |
+
## 0.1.2
|
212 |
+
|
213 |
+
### Patch Changes
|
214 |
+
|
215 |
+
- [#4273](https://github.com/gradio-app/gradio/pull/4273) [`1d0f0a9d`](https://github.com/gradio-app/gradio/commit/1d0f0a9db096552e67eb2197c932342587e9e61e) Thanks [@pngwn](https://github.com/pngwn)! - Ensure websocket error messages are correctly handled.
|
216 |
+
|
217 |
+
- [#4315](https://github.com/gradio-app/gradio/pull/4315) [`b525b122`](https://github.com/gradio-app/gradio/commit/b525b122dd8569bbaf7e06db5b90d622d2e9073d) Thanks [@whitphx](https://github.com/whitphx)! - Refacor types.
|
218 |
+
|
219 |
+
- [#4271](https://github.com/gradio-app/gradio/pull/4271) [`1151c525`](https://github.com/gradio-app/gradio/commit/1151c5253554cb87ebd4a44a8a470ac215ff782b) Thanks [@pngwn](https://github.com/pngwn)! - Ensure the full root path is always respected when making requests to a gradio app server.
|
220 |
+
|
221 |
+
## 0.1.1
|
222 |
+
|
223 |
+
### Patch Changes
|
224 |
+
|
225 |
+
- [#4201](https://github.com/gradio-app/gradio/pull/4201) [`da5b4ee1`](https://github.com/gradio-app/gradio/commit/da5b4ee11721175858ded96e5710225369097f74) Thanks [@pngwn](https://github.com/pngwn)! - Ensure semiver is bundled so CDN links work correctly.
|
226 |
+
|
227 |
+
- [#4202](https://github.com/gradio-app/gradio/pull/4202) [`a26e9afd`](https://github.com/gradio-app/gradio/commit/a26e9afde319382993e6ddc77cc4e56337a31248) Thanks [@pngwn](https://github.com/pngwn)! - Ensure all URLs returned by the client are complete URLs with the correct host instead of an absolute path relative to a server.
|
228 |
+
|
229 |
+
## 0.1.0
|
230 |
+
|
231 |
+
### Minor Changes
|
232 |
+
|
233 |
+
- [#4185](https://github.com/gradio-app/gradio/pull/4185) [`67239ca9`](https://github.com/gradio-app/gradio/commit/67239ca9b2fe3796853fbf7bf865c9e4b383200d) Thanks [@pngwn](https://github.com/pngwn)! - Update client for initial release
|
234 |
+
|
235 |
+
### Patch Changes
|
236 |
+
|
237 |
+
- [#3692](https://github.com/gradio-app/gradio/pull/3692) [`48e8b113`](https://github.com/gradio-app/gradio/commit/48e8b113f4b55e461d9da4f153bf72aeb4adf0f1) Thanks [@pngwn](https://github.com/pngwn)! - Ensure client works in node, create ESM bundle and generate typescript declaration files.
|
238 |
+
|
239 |
+
- [#3605](https://github.com/gradio-app/gradio/pull/3605) [`ae4277a9`](https://github.com/gradio-app/gradio/commit/ae4277a9a83d49bdadfe523b0739ba988128e73b) Thanks [@pngwn](https://github.com/pngwn)! - Update readme.
|
node_modules/@gradio/client/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
177 |
+
|
178 |
+
APPENDIX: How to apply the Apache License to your work.
|
179 |
+
|
180 |
+
To apply the Apache License to your work, attach the following
|
181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182 |
+
replaced with your own identifying information. (Don't include
|
183 |
+
the brackets!) The text should be enclosed in the appropriate
|
184 |
+
comment syntax for the file format. We also recommend that a
|
185 |
+
file or class name and description of purpose be included on the
|
186 |
+
same "printed page" as the copyright notice for easier
|
187 |
+
identification within third-party archives.
|
188 |
+
|
189 |
+
Copyright [yyyy] [name of copyright owner]
|
190 |
+
|
191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192 |
+
you may not use this file except in compliance with the License.
|
193 |
+
You may obtain a copy of the License at
|
194 |
+
|
195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
196 |
+
|
197 |
+
Unless required by applicable law or agreed to in writing, software
|
198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200 |
+
See the License for the specific language governing permissions and
|
201 |
+
limitations under the License.
|
node_modules/@gradio/client/README.md
ADDED
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## JavaScript Client Library
|
2 |
+
|
3 |
+
A javascript (and typescript) client to call Gradio APIs.
|
4 |
+
|
5 |
+
## Installation
|
6 |
+
|
7 |
+
The Gradio JavaScript client is available on npm as `@gradio/client`. You can install it as below:
|
8 |
+
|
9 |
+
```sh
|
10 |
+
npm i @gradio/client
|
11 |
+
```
|
12 |
+
|
13 |
+
## Usage
|
14 |
+
|
15 |
+
The JavaScript Gradio Client exposes two named imports, `client` and `duplicate`.
|
16 |
+
|
17 |
+
### `client`
|
18 |
+
|
19 |
+
The client function connects to the API of a hosted Gradio space and returns an object that allows you to make calls to that API.
|
20 |
+
|
21 |
+
The simplest example looks like this:
|
22 |
+
|
23 |
+
```ts
|
24 |
+
import { client } from "@gradio/client";
|
25 |
+
|
26 |
+
const app = await client("user/space-name");
|
27 |
+
const result = await app.predict("/predict");
|
28 |
+
```
|
29 |
+
|
30 |
+
This function accepts two arguments: `source` and `options`:
|
31 |
+
|
32 |
+
#### `source`
|
33 |
+
|
34 |
+
This is the url or name of the gradio app whose API you wish to connect to. This parameter is required and should always be a string. For example:
|
35 |
+
|
36 |
+
```ts
|
37 |
+
client("user/space-name");
|
38 |
+
```
|
39 |
+
|
40 |
+
#### `options`
|
41 |
+
|
42 |
+
The options object can optionally be passed a second parameter. This object has two properties, `hf_token` and `status_callback`.
|
43 |
+
|
44 |
+
##### `hf_token`
|
45 |
+
|
46 |
+
This should be a Hugging Face personal access token and is required if you wish to make calls to a private gradio api. This option is optional and should be a string starting with `"hf_"`.
|
47 |
+
|
48 |
+
Example:
|
49 |
+
|
50 |
+
```ts
|
51 |
+
import { client } from "@gradio/client";
|
52 |
+
|
53 |
+
const app = await client("user/space-name", { hf_token: "hf_..." });
|
54 |
+
```
|
55 |
+
|
56 |
+
##### `status_callback`
|
57 |
+
|
58 |
+
This should be a function which will notify your of the status of a space if it is not running. If the gradio API you are connecting to is awake and running or is not hosted on Hugging Face space then this function will do nothing.
|
59 |
+
|
60 |
+
**Additional context**
|
61 |
+
|
62 |
+
Applications hosted on Hugging Face spaces can be in a number of different states. As spaces are a GitOps tool and will rebuild when new changes are pushed to the repository, they have various building, running and error states. If a space is not 'running' then the function passed as the `status_callback` will notify you of the current state of the space and the status of the space as it changes. Spaces that are building or sleeping can take longer than usual to respond, so you can use this information to give users feedback about the progress of their action.
|
63 |
+
|
64 |
+
```ts
|
65 |
+
import { client, type SpaceStatus } from "@gradio/client";
|
66 |
+
|
67 |
+
const app = await client("user/space-name", {
|
68 |
+
// The space_status parameter does not need to be manually annotated, this is just for illustration.
|
69 |
+
space_status: (space_status: SpaceStatus) => console.log(space_status)
|
70 |
+
});
|
71 |
+
```
|
72 |
+
|
73 |
+
```ts
|
74 |
+
interface SpaceStatusNormal {
|
75 |
+
status: "sleeping" | "running" | "building" | "error" | "stopped";
|
76 |
+
detail:
|
77 |
+
| "SLEEPING"
|
78 |
+
| "RUNNING"
|
79 |
+
| "RUNNING_BUILDING"
|
80 |
+
| "BUILDING"
|
81 |
+
| "NOT_FOUND";
|
82 |
+
load_status: "pending" | "error" | "complete" | "generating";
|
83 |
+
message: string;
|
84 |
+
}
|
85 |
+
|
86 |
+
interface SpaceStatusError {
|
87 |
+
status: "space_error";
|
88 |
+
detail: "NO_APP_FILE" | "CONFIG_ERROR" | "BUILD_ERROR" | "RUNTIME_ERROR";
|
89 |
+
load_status: "error";
|
90 |
+
message: string;
|
91 |
+
discussions_enabled: boolean;
|
92 |
+
|
93 |
+
type SpaceStatus = SpaceStatusNormal | SpaceStatusError;
|
94 |
+
```
|
95 |
+
|
96 |
+
The gradio client returns an object with a number of methods and properties:
|
97 |
+
|
98 |
+
#### `predict`
|
99 |
+
|
100 |
+
The `predict` method allows you to call an api endpoint and get a prediction result:
|
101 |
+
|
102 |
+
```ts
|
103 |
+
import { client } from "@gradio/client";
|
104 |
+
|
105 |
+
const app = await client("user/space-name");
|
106 |
+
const result = await app.predict("/predict");
|
107 |
+
```
|
108 |
+
|
109 |
+
`predict` accepts two parameters, `endpoint` and `payload`. It returns a promise that resolves to the prediction result.
|
110 |
+
|
111 |
+
##### `endpoint`
|
112 |
+
|
113 |
+
This is the endpoint for an api request and is required. The default endpoint for a `gradio.Interface` is `"/predict"`. Explicitly named endpoints have a custom name. The endpoint names can be found on the "View API" page of a space.
|
114 |
+
|
115 |
+
```ts
|
116 |
+
import { client } from "@gradio/client";
|
117 |
+
|
118 |
+
const app = await client("user/space-name");
|
119 |
+
const result = await app.predict("/predict");
|
120 |
+
```
|
121 |
+
|
122 |
+
##### `payload`
|
123 |
+
|
124 |
+
The `payload` argument is generally optional but this depends on the API itself. If the API endpoint depends on values being passed in then it is required for the API request to succeed. The data that should be passed in is detailed on the "View API" page of a space, or accessible via the `view_api()` method of the client.
|
125 |
+
|
126 |
+
```ts
|
127 |
+
import { client } from "@gradio/client";
|
128 |
+
|
129 |
+
const app = await client("user/space-name");
|
130 |
+
const result = await app.predict("/predict", [1, "Hello", "friends"]);
|
131 |
+
```
|
132 |
+
|
133 |
+
#### `submit`
|
134 |
+
|
135 |
+
The `submit` method provides a more flexible way to call an API endpoint, providing you with status updates about the current progress of the prediction as well as supporting more complex endpoint types.
|
136 |
+
|
137 |
+
```ts
|
138 |
+
import { client } from "@gradio/client";
|
139 |
+
|
140 |
+
const app = await client("user/space-name");
|
141 |
+
const submission = app.submit("/predict", payload);
|
142 |
+
```
|
143 |
+
|
144 |
+
The `submit` method accepts the same [`endpoint`](#endpoint) and [`payload`](#payload) arguments as `predict`.
|
145 |
+
|
146 |
+
The `submit` method does not return a promise and should not be awaited, instead it returns an object with a `on`, `off`, and `cancel` methods.
|
147 |
+
|
148 |
+
##### `on`
|
149 |
+
|
150 |
+
The `on` method allows you to subscribe to events related to the submitted API request. There are two types of event that can be subscribed to: `"data"` updates and `"status"` updates.
|
151 |
+
|
152 |
+
`"data"` updates are issued when the API computes a value, the callback provided as the second argument will be called when such a value is sent to the client. The shape of the data depends on the way the API itself is constructed. This event may fire more than once if that endpoint supports emmitting new values over time.
|
153 |
+
|
154 |
+
`"status` updates are issued when the status of a request changes. This information allows you to offer feedback to users when the queue position of the request changes, or when the request changes from queued to processing.
|
155 |
+
|
156 |
+
The status payload look like this:
|
157 |
+
|
158 |
+
```ts
|
159 |
+
interface Status {
|
160 |
+
queue: boolean;
|
161 |
+
code?: string;
|
162 |
+
success?: boolean;
|
163 |
+
stage: "pending" | "error" | "complete" | "generating";
|
164 |
+
size?: number;
|
165 |
+
position?: number;
|
166 |
+
eta?: number;
|
167 |
+
message?: string;
|
168 |
+
progress_data?: Array<{
|
169 |
+
progress: number | null;
|
170 |
+
index: number | null;
|
171 |
+
length: number | null;
|
172 |
+
unit: string | null;
|
173 |
+
desc: string | null;
|
174 |
+
}>;
|
175 |
+
time?: Date;
|
176 |
+
}
|
177 |
+
```
|
178 |
+
|
179 |
+
Usage of these subscribe callback looks like this:
|
180 |
+
|
181 |
+
```ts
|
182 |
+
import { client } from "@gradio/client";
|
183 |
+
|
184 |
+
const app = await client("user/space-name");
|
185 |
+
const submission = app
|
186 |
+
.submit("/predict", payload)
|
187 |
+
.on("data", (data) => console.log(data))
|
188 |
+
.on("status", (status: Status) => console.log(status));
|
189 |
+
```
|
190 |
+
|
191 |
+
##### `off`
|
192 |
+
|
193 |
+
The `off` method unsubscribes from a specific event of the submitted job and works similarly to `document.removeEventListener`; both the event name and the original callback must be passed in to successfully unsubscribe:
|
194 |
+
|
195 |
+
```ts
|
196 |
+
import { client } from "@gradio/client";
|
197 |
+
|
198 |
+
const app = await client("user/space-name");
|
199 |
+
const handle_data = (data) => console.log(data);
|
200 |
+
|
201 |
+
const submission = app.submit("/predict", payload).on("data", handle_data);
|
202 |
+
|
203 |
+
// later
|
204 |
+
submission.off("/predict", handle_data);
|
205 |
+
```
|
206 |
+
|
207 |
+
##### `destroy`
|
208 |
+
|
209 |
+
The `destroy` method will remove all subscriptions to a job, regardless of whether or not they are `"data"` or `"status"` events. This is a convenience method for when you do not want to unsubscribe use the `off` method.
|
210 |
+
|
211 |
+
```js
|
212 |
+
import { client } from "@gradio/client";
|
213 |
+
|
214 |
+
const app = await client("user/space-name");
|
215 |
+
const handle_data = (data) => console.log(data);
|
216 |
+
|
217 |
+
const submission = app.submit("/predict", payload).on("data", handle_data);
|
218 |
+
|
219 |
+
// later
|
220 |
+
submission.destroy();
|
221 |
+
```
|
222 |
+
|
223 |
+
##### `cancel`
|
224 |
+
|
225 |
+
Certain types of gradio function can run repeatedly and in some cases indefinitely. the `cancel` method will stop such an endpoints and prevent the API from issuing additional updates.
|
226 |
+
|
227 |
+
```ts
|
228 |
+
import { client } from "@gradio/client";
|
229 |
+
|
230 |
+
const app = await client("user/space-name");
|
231 |
+
const submission = app
|
232 |
+
.submit("/predict", payload)
|
233 |
+
.on("data", (data) => console.log(data));
|
234 |
+
|
235 |
+
// later
|
236 |
+
|
237 |
+
submission.cancel();
|
238 |
+
```
|
239 |
+
|
240 |
+
#### `view_api`
|
241 |
+
|
242 |
+
The `view_api` method provides details about the API you are connected to. It returns a JavaScript object of all named endpoints, unnamed endpoints and what values they accept and return. This method does not accept arguments.
|
243 |
+
|
244 |
+
```ts
|
245 |
+
import { client } from "@gradio/client";
|
246 |
+
|
247 |
+
const app = await client("user/space-name");
|
248 |
+
const api_info = await app.view_api();
|
249 |
+
|
250 |
+
console.log(api_info);
|
251 |
+
```
|
252 |
+
|
253 |
+
#### `config`
|
254 |
+
|
255 |
+
The `config` property contains the configuration for the gradio application you are connected to. This object may contain useful meta information about the application.
|
256 |
+
|
257 |
+
```ts
|
258 |
+
import { client } from "@gradio/client";
|
259 |
+
|
260 |
+
const app = await client("user/space-name");
|
261 |
+
console.log(app.config);
|
262 |
+
```
|
263 |
+
|
264 |
+
### `duplicate`
|
265 |
+
|
266 |
+
The duplicate function will attempt to duplicate the space that is referenced and return an instance of `client` connected to that space. If the space has already been duplicated then it will not create a new duplicate and will instead connect to the existing duplicated space. The huggingface token that is passed in will dictate the user under which the space is created.
|
267 |
+
|
268 |
+
`duplicate` accepts the same arguments as `client` with the addition of a `private` options property dictating whether the duplicated space should be private or public. A huggingface token is required for duplication to work.
|
269 |
+
|
270 |
+
```ts
|
271 |
+
import { duplicate } from "@gradio/client";
|
272 |
+
|
273 |
+
const app = await duplicate("user/space-name", {
|
274 |
+
hf_token: "hf_..."
|
275 |
+
});
|
276 |
+
```
|
277 |
+
|
278 |
+
This function accepts two arguments: `source` and `options`:
|
279 |
+
|
280 |
+
#### `source`
|
281 |
+
|
282 |
+
The space to duplicate and connect to. [See `client`'s `source` parameter](#source).
|
283 |
+
|
284 |
+
#### `options`
|
285 |
+
|
286 |
+
Accepts all options that `client` accepts, except `hf_token` is required. [See `client`'s `options` parameter](#source).
|
287 |
+
|
288 |
+
`duplicate` also accepts one additional `options` property.
|
289 |
+
|
290 |
+
##### `private`
|
291 |
+
|
292 |
+
This is an optional property specific to `duplicate`'s options object and will determine whether the space should be public or private. Spaces duplicated via the `duplicate` method are public by default.
|
293 |
+
|
294 |
+
```ts
|
295 |
+
import { duplicate } from "@gradio/client";
|
296 |
+
|
297 |
+
const app = await duplicate("user/space-name", {
|
298 |
+
hf_token: "hf_...",
|
299 |
+
private: true
|
300 |
+
});
|
301 |
+
```
|
302 |
+
|
303 |
+
##### `timeout`
|
304 |
+
|
305 |
+
This is an optional property specific to `duplicate`'s options object and will set the timeout in minutes before the duplicated space will go to sleep.
|
306 |
+
|
307 |
+
```ts
|
308 |
+
import { duplicate } from "@gradio/client";
|
309 |
+
|
310 |
+
const app = await duplicate("user/space-name", {
|
311 |
+
hf_token: "hf_...",
|
312 |
+
private: true,
|
313 |
+
timeout: 5
|
314 |
+
});
|
315 |
+
```
|
316 |
+
|
317 |
+
##### `hardware`
|
318 |
+
|
319 |
+
This is an optional property specific to `duplicate`'s options object and will set the hardware for the duplicated space. By default the hardware used will match that of the original space. If this cannot be obtained it will default to `"cpu-basic"`. For hardware upgrades (beyond the basic CPU tier), you may be required to provide [billing information on Hugging Face](https://huggingface.co/settings/billing).
|
320 |
+
|
321 |
+
Possible hardware options are:
|
322 |
+
|
323 |
+
- `"cpu-basic"`
|
324 |
+
- `"cpu-upgrade"`
|
325 |
+
- `"t4-small"`
|
326 |
+
- `"t4-medium"`
|
327 |
+
- `"a10g-small"`
|
328 |
+
- `"a10g-large"`
|
329 |
+
- `"a100-large"`
|
330 |
+
|
331 |
+
```ts
|
332 |
+
import { duplicate } from "@gradio/client";
|
333 |
+
|
334 |
+
const app = await duplicate("user/space-name", {
|
335 |
+
hf_token: "hf_...",
|
336 |
+
private: true,
|
337 |
+
hardware: "a10g-small"
|
338 |
+
});
|
339 |
+
```
|
node_modules/@gradio/client/dist/client.d.ts
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { hardware_types } from "./utils.js";
|
2 |
+
import type { EventType, EventListener, PostResponse, UploadResponse, SpaceStatusCallback } from "./types.js";
|
3 |
+
import type { Config } from "./types.js";
|
4 |
+
type event = <K extends EventType>(eventType: K, listener: EventListener<K>) => SubmitReturn;
|
5 |
+
type predict = (endpoint: string | number, data?: unknown[], event_data?: unknown) => Promise<unknown>;
|
6 |
+
type client_return = {
|
7 |
+
predict: predict;
|
8 |
+
config: Config;
|
9 |
+
submit: (endpoint: string | number, data?: unknown[], event_data?: unknown, trigger_id?: number | null) => SubmitReturn;
|
10 |
+
component_server: (component_id: number, fn_name: string, data: unknown[]) => any;
|
11 |
+
view_api: (c?: Config) => Promise<ApiInfo<JsApiData>>;
|
12 |
+
};
|
13 |
+
type SubmitReturn = {
|
14 |
+
on: event;
|
15 |
+
off: event;
|
16 |
+
cancel: () => Promise<void>;
|
17 |
+
destroy: () => void;
|
18 |
+
};
|
19 |
+
export declare let NodeBlob: any;
|
20 |
+
export declare function duplicate(app_reference: string, options: {
|
21 |
+
hf_token: `hf_${string}`;
|
22 |
+
private?: boolean;
|
23 |
+
status_callback: SpaceStatusCallback;
|
24 |
+
hardware?: (typeof hardware_types)[number];
|
25 |
+
timeout?: number;
|
26 |
+
}): Promise<client_return>;
|
27 |
+
interface Client {
|
28 |
+
post_data: (url: string, body: unknown, token?: `hf_${string}`) => Promise<[PostResponse, number]>;
|
29 |
+
upload_files: (root: string, files: File[], token?: `hf_${string}`, upload_id?: string) => Promise<UploadResponse>;
|
30 |
+
client: (app_reference: string, options: {
|
31 |
+
hf_token?: `hf_${string}`;
|
32 |
+
status_callback?: SpaceStatusCallback;
|
33 |
+
normalise_files?: boolean;
|
34 |
+
}) => Promise<client_return>;
|
35 |
+
handle_blob: (endpoint: string, data: unknown[], api_info: ApiInfo<JsApiData>, token?: `hf_${string}`) => Promise<unknown[]>;
|
36 |
+
}
|
37 |
+
export declare function api_factory(fetch_implementation: typeof fetch, EventSource_factory: (url: URL) => EventSource): Client;
|
38 |
+
export declare const post_data: (url: string, body: unknown, token?: `hf_${string}`) => Promise<[PostResponse, number]>, upload_files: (root: string, files: File[], token?: `hf_${string}`, upload_id?: string) => Promise<UploadResponse>, client: (app_reference: string, options: {
|
39 |
+
hf_token?: `hf_${string}`;
|
40 |
+
status_callback?: SpaceStatusCallback;
|
41 |
+
normalise_files?: boolean;
|
42 |
+
}) => Promise<client_return>, handle_blob: (endpoint: string, data: unknown[], api_info: ApiInfo<JsApiData>, token?: `hf_${string}`) => Promise<unknown[]>;
|
43 |
+
interface ApiData {
|
44 |
+
label: string;
|
45 |
+
type: {
|
46 |
+
type: any;
|
47 |
+
description: string;
|
48 |
+
};
|
49 |
+
component: string;
|
50 |
+
example_input?: any;
|
51 |
+
}
|
52 |
+
interface JsApiData {
|
53 |
+
label: string;
|
54 |
+
type: string;
|
55 |
+
component: string;
|
56 |
+
example_input: any;
|
57 |
+
}
|
58 |
+
interface EndpointInfo<T extends ApiData | JsApiData> {
|
59 |
+
parameters: T[];
|
60 |
+
returns: T[];
|
61 |
+
}
|
62 |
+
interface ApiInfo<T extends ApiData | JsApiData> {
|
63 |
+
named_endpoints: {
|
64 |
+
[key: string]: EndpointInfo<T>;
|
65 |
+
};
|
66 |
+
unnamed_endpoints: {
|
67 |
+
[key: string]: EndpointInfo<T>;
|
68 |
+
};
|
69 |
+
}
|
70 |
+
export declare function walk_and_store_blobs(param: any, type?: any, path?: any[], root?: boolean, api_info?: any): Promise<{
|
71 |
+
path: string[];
|
72 |
+
type: string;
|
73 |
+
blob: Blob | false;
|
74 |
+
}[]>;
|
75 |
+
export {};
|
76 |
+
//# sourceMappingURL=client.d.ts.map
|
node_modules/@gradio/client/dist/client.d.ts.map
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAIA,OAAO,EAQN,cAAc,EAEd,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EAIb,YAAY,EACZ,cAAc,EAGd,mBAAmB,EACnB,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,KAAK,KAAK,GAAG,CAAC,CAAC,SAAS,SAAS,EAChC,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,KACtB,YAAY,CAAC;AAClB,KAAK,OAAO,GAAG,CACd,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,IAAI,CAAC,EAAE,OAAO,EAAE,EAChB,UAAU,CAAC,EAAE,OAAO,KAChB,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,KAAK,aAAa,GAAG;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,CACP,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,IAAI,CAAC,EAAE,OAAO,EAAE,EAChB,UAAU,CAAC,EAAE,OAAO,EACpB,UAAU,CAAC,EAAE,MAAM,GAAG,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AAE,GAAG,CAAC;CACpB;AAED,UAAU,SAAS;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,GAAG,CAAC;CACnB;AAED,UAAU,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,SAAS;IACnD,UAAU,EAAE,CAAC,EAAE,CAAC;IAChB,OAAO,EAAE,CAAC,EAAE,CAAC;CACb;AACD,UAAU,OAAO,CAAC,CAAC,SAAS,OAAO,GAAG,SAAS;IAC9C,eAAe,EAAE;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;KAC/B,CAAC;IACF,iBAAiB,EAAE;QAClB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;KAC/B,CAAC;CACF;AAiID,wBAAsB,oBAAoB,CACzC,KAAK,KAAA,EACL,IAAI,MAAY,EAChB,IAAI,QAAK,EACT,IAAI,UAAQ,EACZ,QAAQ,MAAY,GAClB,OAAO,CACT;IACC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,GAAG,KAAK,CAAC;CACnB,EAAE,CACH,CAmDA"}
|
node_modules/@gradio/client/dist/index.d.ts
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export { client, post_data, upload_files, duplicate, api_factory } from "./client.js";
|
2 |
+
export type { SpaceStatus } from "./types.js";
|
3 |
+
export { normalise_file, FileData, upload, get_fetchable_url_or_file, prepare_files } from "./upload.js";
|
4 |
+
//# sourceMappingURL=index.d.ts.map
|
node_modules/@gradio/client/dist/index.d.ts.map
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,MAAM,EACN,SAAS,EAC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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var fn = new Intl.Collator(0, { numeric: 1 }).compare;
|
2 |
+
function semiver(a, b, bool) {
|
3 |
+
a = a.split(".");
|
4 |
+
b = b.split(".");
|
5 |
+
return fn(a[0], b[0]) || fn(a[1], b[1]) || (b[2] = b.slice(2).join("."), bool = /[.-]/.test(a[2] = a.slice(2).join(".")), bool == /[.-]/.test(b[2]) ? fn(a[2], b[2]) : bool ? -1 : 1);
|
6 |
+
}
|
7 |
+
function resolve_root(base_url, root_path, prioritize_base) {
|
8 |
+
if (root_path.startsWith("http://") || root_path.startsWith("https://")) {
|
9 |
+
return prioritize_base ? base_url : root_path;
|
10 |
+
}
|
11 |
+
return base_url + root_path;
|
12 |
+
}
|
13 |
+
function determine_protocol(endpoint) {
|
14 |
+
if (endpoint.startsWith("http")) {
|
15 |
+
const { protocol, host } = new URL(endpoint);
|
16 |
+
if (host.endsWith("hf.space")) {
|
17 |
+
return {
|
18 |
+
ws_protocol: "wss",
|
19 |
+
host,
|
20 |
+
http_protocol: protocol
|
21 |
+
};
|
22 |
+
}
|
23 |
+
return {
|
24 |
+
ws_protocol: protocol === "https:" ? "wss" : "ws",
|
25 |
+
http_protocol: protocol,
|
26 |
+
host
|
27 |
+
};
|
28 |
+
} else if (endpoint.startsWith("file:")) {
|
29 |
+
return {
|
30 |
+
ws_protocol: "ws",
|
31 |
+
http_protocol: "http:",
|
32 |
+
host: "lite.local"
|
33 |
+
// Special fake hostname only used for this case. This matches the hostname allowed in `is_self_host()` in `js/wasm/network/host.ts`.
|
34 |
+
};
|
35 |
+
}
|
36 |
+
return {
|
37 |
+
ws_protocol: "wss",
|
38 |
+
http_protocol: "https:",
|
39 |
+
host: endpoint
|
40 |
+
};
|
41 |
+
}
|
42 |
+
const RE_SPACE_NAME = /^[^\/]*\/[^\/]*$/;
|
43 |
+
const RE_SPACE_DOMAIN = /.*hf\.space\/{0,1}$/;
|
44 |
+
async function process_endpoint(app_reference, token) {
|
45 |
+
const headers = {};
|
46 |
+
if (token) {
|
47 |
+
headers.Authorization = `Bearer ${token}`;
|
48 |
+
}
|
49 |
+
const _app_reference = app_reference.trim();
|
50 |
+
if (RE_SPACE_NAME.test(_app_reference)) {
|
51 |
+
try {
|
52 |
+
const res = await fetch(
|
53 |
+
`https://huggingface.co/api/spaces/${_app_reference}/host`,
|
54 |
+
{ headers }
|
55 |
+
);
|
56 |
+
if (res.status !== 200)
|
57 |
+
throw new Error("Space metadata could not be loaded.");
|
58 |
+
const _host = (await res.json()).host;
|
59 |
+
return {
|
60 |
+
space_id: app_reference,
|
61 |
+
...determine_protocol(_host)
|
62 |
+
};
|
63 |
+
} catch (e) {
|
64 |
+
throw new Error("Space metadata could not be loaded." + e.message);
|
65 |
+
}
|
66 |
+
}
|
67 |
+
if (RE_SPACE_DOMAIN.test(_app_reference)) {
|
68 |
+
const { ws_protocol, http_protocol, host } = determine_protocol(_app_reference);
|
69 |
+
return {
|
70 |
+
space_id: host.replace(".hf.space", ""),
|
71 |
+
ws_protocol,
|
72 |
+
http_protocol,
|
73 |
+
host
|
74 |
+
};
|
75 |
+
}
|
76 |
+
return {
|
77 |
+
space_id: false,
|
78 |
+
...determine_protocol(_app_reference)
|
79 |
+
};
|
80 |
+
}
|
81 |
+
function map_names_to_ids(fns) {
|
82 |
+
let apis = {};
|
83 |
+
fns.forEach(({ api_name }, i) => {
|
84 |
+
if (api_name)
|
85 |
+
apis[api_name] = i;
|
86 |
+
});
|
87 |
+
return apis;
|
88 |
+
}
|
89 |
+
const RE_DISABLED_DISCUSSION = /^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
|
90 |
+
async function discussions_enabled(space_id) {
|
91 |
+
try {
|
92 |
+
const r = await fetch(
|
93 |
+
`https://huggingface.co/api/spaces/${space_id}/discussions`,
|
94 |
+
{
|
95 |
+
method: "HEAD"
|
96 |
+
}
|
97 |
+
);
|
98 |
+
const error = r.headers.get("x-error-message");
|
99 |
+
if (error && RE_DISABLED_DISCUSSION.test(error))
|
100 |
+
return false;
|
101 |
+
return true;
|
102 |
+
} catch (e) {
|
103 |
+
return false;
|
104 |
+
}
|
105 |
+
}
|
106 |
+
async function get_space_hardware(space_id, token) {
|
107 |
+
const headers = {};
|
108 |
+
if (token) {
|
109 |
+
headers.Authorization = `Bearer ${token}`;
|
110 |
+
}
|
111 |
+
try {
|
112 |
+
const res = await fetch(
|
113 |
+
`https://huggingface.co/api/spaces/${space_id}/runtime`,
|
114 |
+
{ headers }
|
115 |
+
);
|
116 |
+
if (res.status !== 200)
|
117 |
+
throw new Error("Space hardware could not be obtained.");
|
118 |
+
const { hardware } = await res.json();
|
119 |
+
return hardware;
|
120 |
+
} catch (e) {
|
121 |
+
throw new Error(e.message);
|
122 |
+
}
|
123 |
+
}
|
124 |
+
async function set_space_hardware(space_id, new_hardware, token) {
|
125 |
+
const headers = {};
|
126 |
+
if (token) {
|
127 |
+
headers.Authorization = `Bearer ${token}`;
|
128 |
+
}
|
129 |
+
try {
|
130 |
+
const res = await fetch(
|
131 |
+
`https://huggingface.co/api/spaces/${space_id}/hardware`,
|
132 |
+
{ headers, body: JSON.stringify(new_hardware) }
|
133 |
+
);
|
134 |
+
if (res.status !== 200)
|
135 |
+
throw new Error(
|
136 |
+
"Space hardware could not be set. Please ensure the space hardware provided is valid and that a Hugging Face token is passed in."
|
137 |
+
);
|
138 |
+
const { hardware } = await res.json();
|
139 |
+
return hardware;
|
140 |
+
} catch (e) {
|
141 |
+
throw new Error(e.message);
|
142 |
+
}
|
143 |
+
}
|
144 |
+
async function set_space_timeout(space_id, timeout, token) {
|
145 |
+
const headers = {};
|
146 |
+
if (token) {
|
147 |
+
headers.Authorization = `Bearer ${token}`;
|
148 |
+
}
|
149 |
+
try {
|
150 |
+
const res = await fetch(
|
151 |
+
`https://huggingface.co/api/spaces/${space_id}/hardware`,
|
152 |
+
{ headers, body: JSON.stringify({ seconds: timeout }) }
|
153 |
+
);
|
154 |
+
if (res.status !== 200)
|
155 |
+
throw new Error(
|
156 |
+
"Space hardware could not be set. Please ensure the space hardware provided is valid and that a Hugging Face token is passed in."
|
157 |
+
);
|
158 |
+
const { hardware } = await res.json();
|
159 |
+
return hardware;
|
160 |
+
} catch (e) {
|
161 |
+
throw new Error(e.message);
|
162 |
+
}
|
163 |
+
}
|
164 |
+
const hardware_types = [
|
165 |
+
"cpu-basic",
|
166 |
+
"cpu-upgrade",
|
167 |
+
"t4-small",
|
168 |
+
"t4-medium",
|
169 |
+
"a10g-small",
|
170 |
+
"a10g-large",
|
171 |
+
"a100-large"
|
172 |
+
];
|
173 |
+
function normalise_file(file, server_url, proxy_url) {
|
174 |
+
if (file == null) {
|
175 |
+
return null;
|
176 |
+
}
|
177 |
+
if (Array.isArray(file)) {
|
178 |
+
const normalized_file = [];
|
179 |
+
for (const x of file) {
|
180 |
+
if (x == null) {
|
181 |
+
normalized_file.push(null);
|
182 |
+
} else {
|
183 |
+
normalized_file.push(normalise_file(x, server_url, proxy_url));
|
184 |
+
}
|
185 |
+
}
|
186 |
+
return normalized_file;
|
187 |
+
}
|
188 |
+
if (file.is_stream) {
|
189 |
+
if (proxy_url == null) {
|
190 |
+
return new FileData({
|
191 |
+
...file,
|
192 |
+
url: server_url + "/stream/" + file.path
|
193 |
+
});
|
194 |
+
}
|
195 |
+
return new FileData({
|
196 |
+
...file,
|
197 |
+
url: "/proxy=" + proxy_url + "stream/" + file.path
|
198 |
+
});
|
199 |
+
}
|
200 |
+
return new FileData({
|
201 |
+
...file,
|
202 |
+
url: get_fetchable_url_or_file(file.path, server_url, proxy_url)
|
203 |
+
});
|
204 |
+
}
|
205 |
+
function is_url(str) {
|
206 |
+
try {
|
207 |
+
const url = new URL(str);
|
208 |
+
return url.protocol === "http:" || url.protocol === "https:";
|
209 |
+
} catch {
|
210 |
+
return false;
|
211 |
+
}
|
212 |
+
}
|
213 |
+
function get_fetchable_url_or_file(path, server_url, proxy_url) {
|
214 |
+
if (path == null) {
|
215 |
+
return proxy_url ? `/proxy=${proxy_url}file=` : `${server_url}/file=`;
|
216 |
+
}
|
217 |
+
if (is_url(path)) {
|
218 |
+
return path;
|
219 |
+
}
|
220 |
+
return proxy_url ? `/proxy=${proxy_url}file=${path}` : `${server_url}/file=${path}`;
|
221 |
+
}
|
222 |
+
async function upload(file_data, root, upload_id, upload_fn = upload_files) {
|
223 |
+
let files = (Array.isArray(file_data) ? file_data : [file_data]).map(
|
224 |
+
(file_data2) => file_data2.blob
|
225 |
+
);
|
226 |
+
return await Promise.all(
|
227 |
+
await upload_fn(root, files, void 0, upload_id).then(
|
228 |
+
async (response) => {
|
229 |
+
if (response.error) {
|
230 |
+
throw new Error(response.error);
|
231 |
+
} else {
|
232 |
+
if (response.files) {
|
233 |
+
return response.files.map((f, i) => {
|
234 |
+
const file = new FileData({ ...file_data[i], path: f });
|
235 |
+
return normalise_file(file, root, null);
|
236 |
+
});
|
237 |
+
}
|
238 |
+
return [];
|
239 |
+
}
|
240 |
+
}
|
241 |
+
)
|
242 |
+
);
|
243 |
+
}
|
244 |
+
async function prepare_files(files, is_stream) {
|
245 |
+
return files.map(
|
246 |
+
(f, i) => new FileData({
|
247 |
+
path: f.name,
|
248 |
+
orig_name: f.name,
|
249 |
+
blob: f,
|
250 |
+
size: f.size,
|
251 |
+
mime_type: f.type,
|
252 |
+
is_stream
|
253 |
+
})
|
254 |
+
);
|
255 |
+
}
|
256 |
+
class FileData {
|
257 |
+
constructor({
|
258 |
+
path,
|
259 |
+
url,
|
260 |
+
orig_name,
|
261 |
+
size,
|
262 |
+
blob,
|
263 |
+
is_stream,
|
264 |
+
mime_type,
|
265 |
+
alt_text
|
266 |
+
}) {
|
267 |
+
this.path = path;
|
268 |
+
this.url = url;
|
269 |
+
this.orig_name = orig_name;
|
270 |
+
this.size = size;
|
271 |
+
this.blob = url ? void 0 : blob;
|
272 |
+
this.is_stream = is_stream;
|
273 |
+
this.mime_type = mime_type;
|
274 |
+
this.alt_text = alt_text;
|
275 |
+
}
|
276 |
+
}
|
277 |
+
const QUEUE_FULL_MSG = "This application is too busy. Keep trying!";
|
278 |
+
const BROKEN_CONNECTION_MSG = "Connection errored out.";
|
279 |
+
let NodeBlob;
|
280 |
+
async function duplicate(app_reference, options) {
|
281 |
+
const { hf_token, private: _private, hardware, timeout } = options;
|
282 |
+
if (hardware && !hardware_types.includes(hardware)) {
|
283 |
+
throw new Error(
|
284 |
+
`Invalid hardware type provided. Valid types are: ${hardware_types.map((v) => `"${v}"`).join(",")}.`
|
285 |
+
);
|
286 |
+
}
|
287 |
+
const headers = {
|
288 |
+
Authorization: `Bearer ${hf_token}`
|
289 |
+
};
|
290 |
+
const user = (await (await fetch(`https://huggingface.co/api/whoami-v2`, {
|
291 |
+
headers
|
292 |
+
})).json()).name;
|
293 |
+
const space_name = app_reference.split("/")[1];
|
294 |
+
const body = {
|
295 |
+
repository: `${user}/${space_name}`
|
296 |
+
};
|
297 |
+
if (_private) {
|
298 |
+
body.private = true;
|
299 |
+
}
|
300 |
+
try {
|
301 |
+
const response = await fetch(
|
302 |
+
`https://huggingface.co/api/spaces/${app_reference}/duplicate`,
|
303 |
+
{
|
304 |
+
method: "POST",
|
305 |
+
headers: { "Content-Type": "application/json", ...headers },
|
306 |
+
body: JSON.stringify(body)
|
307 |
+
}
|
308 |
+
);
|
309 |
+
if (response.status === 409) {
|
310 |
+
return client(`${user}/${space_name}`, options);
|
311 |
+
}
|
312 |
+
const duplicated_space = await response.json();
|
313 |
+
let original_hardware;
|
314 |
+
if (!hardware) {
|
315 |
+
original_hardware = await get_space_hardware(app_reference, hf_token);
|
316 |
+
}
|
317 |
+
const requested_hardware = hardware || original_hardware || "cpu-basic";
|
318 |
+
await set_space_hardware(
|
319 |
+
`${user}/${space_name}`,
|
320 |
+
requested_hardware,
|
321 |
+
hf_token
|
322 |
+
);
|
323 |
+
await set_space_timeout(`${user}/${space_name}`, timeout || 300, hf_token);
|
324 |
+
return client(duplicated_space.url, options);
|
325 |
+
} catch (e) {
|
326 |
+
throw new Error(e);
|
327 |
+
}
|
328 |
+
}
|
329 |
+
function api_factory(fetch_implementation, EventSource_factory) {
|
330 |
+
return { post_data: post_data2, upload_files: upload_files2, client: client2, handle_blob: handle_blob2 };
|
331 |
+
async function post_data2(url, body, token) {
|
332 |
+
const headers = { "Content-Type": "application/json" };
|
333 |
+
if (token) {
|
334 |
+
headers.Authorization = `Bearer ${token}`;
|
335 |
+
}
|
336 |
+
try {
|
337 |
+
var response = await fetch_implementation(url, {
|
338 |
+
method: "POST",
|
339 |
+
body: JSON.stringify(body),
|
340 |
+
headers
|
341 |
+
});
|
342 |
+
} catch (e) {
|
343 |
+
return [{ error: BROKEN_CONNECTION_MSG }, 500];
|
344 |
+
}
|
345 |
+
let output;
|
346 |
+
let status;
|
347 |
+
try {
|
348 |
+
output = await response.json();
|
349 |
+
status = response.status;
|
350 |
+
} catch (e) {
|
351 |
+
output = { error: `Could not parse server response: ${e}` };
|
352 |
+
status = 500;
|
353 |
+
}
|
354 |
+
return [output, status];
|
355 |
+
}
|
356 |
+
async function upload_files2(root, files, token, upload_id) {
|
357 |
+
const headers = {};
|
358 |
+
if (token) {
|
359 |
+
headers.Authorization = `Bearer ${token}`;
|
360 |
+
}
|
361 |
+
const chunkSize = 1e3;
|
362 |
+
const uploadResponses = [];
|
363 |
+
for (let i = 0; i < files.length; i += chunkSize) {
|
364 |
+
const chunk = files.slice(i, i + chunkSize);
|
365 |
+
const formData = new FormData();
|
366 |
+
chunk.forEach((file) => {
|
367 |
+
formData.append("files", file);
|
368 |
+
});
|
369 |
+
try {
|
370 |
+
const upload_url = upload_id ? `${root}/upload?upload_id=${upload_id}` : `${root}/upload`;
|
371 |
+
var response = await fetch_implementation(upload_url, {
|
372 |
+
method: "POST",
|
373 |
+
body: formData,
|
374 |
+
headers
|
375 |
+
});
|
376 |
+
} catch (e) {
|
377 |
+
return { error: BROKEN_CONNECTION_MSG };
|
378 |
+
}
|
379 |
+
const output = await response.json();
|
380 |
+
uploadResponses.push(...output);
|
381 |
+
}
|
382 |
+
return { files: uploadResponses };
|
383 |
+
}
|
384 |
+
async function client2(app_reference, options = { normalise_files: true }) {
|
385 |
+
return new Promise(async (res) => {
|
386 |
+
const { status_callback, hf_token, normalise_files } = options;
|
387 |
+
const return_obj = {
|
388 |
+
predict,
|
389 |
+
submit,
|
390 |
+
view_api,
|
391 |
+
component_server
|
392 |
+
};
|
393 |
+
const transform_files = normalise_files ?? true;
|
394 |
+
if ((typeof window === "undefined" || !("WebSocket" in window)) && !global.Websocket) {
|
395 |
+
const ws = await import("./wrapper-6f348d45.js");
|
396 |
+
NodeBlob = (await import("node:buffer")).Blob;
|
397 |
+
global.WebSocket = ws.WebSocket;
|
398 |
+
}
|
399 |
+
const { ws_protocol, http_protocol, host, space_id } = await process_endpoint(app_reference, hf_token);
|
400 |
+
const session_hash = Math.random().toString(36).substring(2);
|
401 |
+
const last_status = {};
|
402 |
+
let stream_open = false;
|
403 |
+
let pending_stream_messages = {};
|
404 |
+
let event_stream = null;
|
405 |
+
const event_callbacks = {};
|
406 |
+
const unclosed_events = /* @__PURE__ */ new Set();
|
407 |
+
let config;
|
408 |
+
let api_map = {};
|
409 |
+
let jwt = false;
|
410 |
+
if (hf_token && space_id) {
|
411 |
+
jwt = await get_jwt(space_id, hf_token);
|
412 |
+
}
|
413 |
+
async function config_success(_config) {
|
414 |
+
config = _config;
|
415 |
+
api_map = map_names_to_ids((_config == null ? void 0 : _config.dependencies) || []);
|
416 |
+
if (config.auth_required) {
|
417 |
+
return {
|
418 |
+
config,
|
419 |
+
...return_obj
|
420 |
+
};
|
421 |
+
}
|
422 |
+
try {
|
423 |
+
api = await view_api(config);
|
424 |
+
} catch (e) {
|
425 |
+
console.error(`Could not get api details: ${e.message}`);
|
426 |
+
}
|
427 |
+
return {
|
428 |
+
config,
|
429 |
+
...return_obj
|
430 |
+
};
|
431 |
+
}
|
432 |
+
let api;
|
433 |
+
async function handle_space_sucess(status) {
|
434 |
+
if (status_callback)
|
435 |
+
status_callback(status);
|
436 |
+
if (status.status === "running")
|
437 |
+
try {
|
438 |
+
config = await resolve_config(
|
439 |
+
fetch_implementation,
|
440 |
+
`${http_protocol}//${host}`,
|
441 |
+
hf_token
|
442 |
+
);
|
443 |
+
const _config = await config_success(config);
|
444 |
+
res(_config);
|
445 |
+
} catch (e) {
|
446 |
+
console.error(e);
|
447 |
+
if (status_callback) {
|
448 |
+
status_callback({
|
449 |
+
status: "error",
|
450 |
+
message: "Could not load this space.",
|
451 |
+
load_status: "error",
|
452 |
+
detail: "NOT_FOUND"
|
453 |
+
});
|
454 |
+
}
|
455 |
+
}
|
456 |
+
}
|
457 |
+
try {
|
458 |
+
config = await resolve_config(
|
459 |
+
fetch_implementation,
|
460 |
+
`${http_protocol}//${host}`,
|
461 |
+
hf_token
|
462 |
+
);
|
463 |
+
const _config = await config_success(config);
|
464 |
+
res(_config);
|
465 |
+
} catch (e) {
|
466 |
+
console.error(e);
|
467 |
+
if (space_id) {
|
468 |
+
check_space_status(
|
469 |
+
space_id,
|
470 |
+
RE_SPACE_NAME.test(space_id) ? "space_name" : "subdomain",
|
471 |
+
handle_space_sucess
|
472 |
+
);
|
473 |
+
} else {
|
474 |
+
if (status_callback)
|
475 |
+
status_callback({
|
476 |
+
status: "error",
|
477 |
+
message: "Could not load this space.",
|
478 |
+
load_status: "error",
|
479 |
+
detail: "NOT_FOUND"
|
480 |
+
});
|
481 |
+
}
|
482 |
+
}
|
483 |
+
function predict(endpoint, data, event_data) {
|
484 |
+
let data_returned = false;
|
485 |
+
let status_complete = false;
|
486 |
+
let dependency;
|
487 |
+
if (typeof endpoint === "number") {
|
488 |
+
dependency = config.dependencies[endpoint];
|
489 |
+
} else {
|
490 |
+
const trimmed_endpoint = endpoint.replace(/^\//, "");
|
491 |
+
dependency = config.dependencies[api_map[trimmed_endpoint]];
|
492 |
+
}
|
493 |
+
if (dependency.types.continuous) {
|
494 |
+
throw new Error(
|
495 |
+
"Cannot call predict on this function as it may run forever. Use submit instead"
|
496 |
+
);
|
497 |
+
}
|
498 |
+
return new Promise((res2, rej) => {
|
499 |
+
const app = submit(endpoint, data, event_data);
|
500 |
+
let result;
|
501 |
+
app.on("data", (d) => {
|
502 |
+
if (status_complete) {
|
503 |
+
app.destroy();
|
504 |
+
res2(d);
|
505 |
+
}
|
506 |
+
data_returned = true;
|
507 |
+
result = d;
|
508 |
+
}).on("status", (status) => {
|
509 |
+
if (status.stage === "error")
|
510 |
+
rej(status);
|
511 |
+
if (status.stage === "complete") {
|
512 |
+
status_complete = true;
|
513 |
+
if (data_returned) {
|
514 |
+
app.destroy();
|
515 |
+
res2(result);
|
516 |
+
}
|
517 |
+
}
|
518 |
+
});
|
519 |
+
});
|
520 |
+
}
|
521 |
+
function submit(endpoint, data, event_data, trigger_id = null) {
|
522 |
+
let fn_index;
|
523 |
+
let api_info;
|
524 |
+
if (typeof endpoint === "number") {
|
525 |
+
fn_index = endpoint;
|
526 |
+
api_info = api.unnamed_endpoints[fn_index];
|
527 |
+
} else {
|
528 |
+
const trimmed_endpoint = endpoint.replace(/^\//, "");
|
529 |
+
fn_index = api_map[trimmed_endpoint];
|
530 |
+
api_info = api.named_endpoints[endpoint.trim()];
|
531 |
+
}
|
532 |
+
if (typeof fn_index !== "number") {
|
533 |
+
throw new Error(
|
534 |
+
"There is no endpoint matching that name of fn_index matching that number."
|
535 |
+
);
|
536 |
+
}
|
537 |
+
let websocket;
|
538 |
+
let eventSource;
|
539 |
+
let protocol = config.protocol ?? "ws";
|
540 |
+
const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint;
|
541 |
+
let payload;
|
542 |
+
let event_id = null;
|
543 |
+
let complete = false;
|
544 |
+
const listener_map = {};
|
545 |
+
let url_params = "";
|
546 |
+
if (typeof window !== "undefined") {
|
547 |
+
url_params = new URLSearchParams(window.location.search).toString();
|
548 |
+
}
|
549 |
+
handle_blob2(`${config.root}`, data, api_info, hf_token).then(
|
550 |
+
(_payload) => {
|
551 |
+
payload = {
|
552 |
+
data: _payload || [],
|
553 |
+
event_data,
|
554 |
+
fn_index,
|
555 |
+
trigger_id
|
556 |
+
};
|
557 |
+
if (skip_queue(fn_index, config)) {
|
558 |
+
fire_event({
|
559 |
+
type: "status",
|
560 |
+
endpoint: _endpoint,
|
561 |
+
stage: "pending",
|
562 |
+
queue: false,
|
563 |
+
fn_index,
|
564 |
+
time: /* @__PURE__ */ new Date()
|
565 |
+
});
|
566 |
+
post_data2(
|
567 |
+
`${config.root}/run${_endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`}${url_params ? "?" + url_params : ""}`,
|
568 |
+
{
|
569 |
+
...payload,
|
570 |
+
session_hash
|
571 |
+
},
|
572 |
+
hf_token
|
573 |
+
).then(([output, status_code]) => {
|
574 |
+
const data2 = transform_files ? transform_output(
|
575 |
+
output.data,
|
576 |
+
api_info,
|
577 |
+
config.root,
|
578 |
+
config.root_url
|
579 |
+
) : output.data;
|
580 |
+
if (status_code == 200) {
|
581 |
+
fire_event({
|
582 |
+
type: "data",
|
583 |
+
endpoint: _endpoint,
|
584 |
+
fn_index,
|
585 |
+
data: data2,
|
586 |
+
time: /* @__PURE__ */ new Date()
|
587 |
+
});
|
588 |
+
fire_event({
|
589 |
+
type: "status",
|
590 |
+
endpoint: _endpoint,
|
591 |
+
fn_index,
|
592 |
+
stage: "complete",
|
593 |
+
eta: output.average_duration,
|
594 |
+
queue: false,
|
595 |
+
time: /* @__PURE__ */ new Date()
|
596 |
+
});
|
597 |
+
} else {
|
598 |
+
fire_event({
|
599 |
+
type: "status",
|
600 |
+
stage: "error",
|
601 |
+
endpoint: _endpoint,
|
602 |
+
fn_index,
|
603 |
+
message: output.error,
|
604 |
+
queue: false,
|
605 |
+
time: /* @__PURE__ */ new Date()
|
606 |
+
});
|
607 |
+
}
|
608 |
+
}).catch((e) => {
|
609 |
+
fire_event({
|
610 |
+
type: "status",
|
611 |
+
stage: "error",
|
612 |
+
message: e.message,
|
613 |
+
endpoint: _endpoint,
|
614 |
+
fn_index,
|
615 |
+
queue: false,
|
616 |
+
time: /* @__PURE__ */ new Date()
|
617 |
+
});
|
618 |
+
});
|
619 |
+
} else if (protocol == "ws") {
|
620 |
+
fire_event({
|
621 |
+
type: "status",
|
622 |
+
stage: "pending",
|
623 |
+
queue: true,
|
624 |
+
endpoint: _endpoint,
|
625 |
+
fn_index,
|
626 |
+
time: /* @__PURE__ */ new Date()
|
627 |
+
});
|
628 |
+
let url = new URL(`${ws_protocol}://${resolve_root(
|
629 |
+
host,
|
630 |
+
config.path,
|
631 |
+
true
|
632 |
+
)}
|
633 |
+
/queue/join${url_params ? "?" + url_params : ""}`);
|
634 |
+
if (jwt) {
|
635 |
+
url.searchParams.set("__sign", jwt);
|
636 |
+
}
|
637 |
+
websocket = new WebSocket(url);
|
638 |
+
websocket.onclose = (evt) => {
|
639 |
+
if (!evt.wasClean) {
|
640 |
+
fire_event({
|
641 |
+
type: "status",
|
642 |
+
stage: "error",
|
643 |
+
broken: true,
|
644 |
+
message: BROKEN_CONNECTION_MSG,
|
645 |
+
queue: true,
|
646 |
+
endpoint: _endpoint,
|
647 |
+
fn_index,
|
648 |
+
time: /* @__PURE__ */ new Date()
|
649 |
+
});
|
650 |
+
}
|
651 |
+
};
|
652 |
+
websocket.onmessage = function(event) {
|
653 |
+
const _data = JSON.parse(event.data);
|
654 |
+
const { type, status, data: data2 } = handle_message(
|
655 |
+
_data,
|
656 |
+
last_status[fn_index]
|
657 |
+
);
|
658 |
+
if (type === "update" && status && !complete) {
|
659 |
+
fire_event({
|
660 |
+
type: "status",
|
661 |
+
endpoint: _endpoint,
|
662 |
+
fn_index,
|
663 |
+
time: /* @__PURE__ */ new Date(),
|
664 |
+
...status
|
665 |
+
});
|
666 |
+
if (status.stage === "error") {
|
667 |
+
websocket.close();
|
668 |
+
}
|
669 |
+
} else if (type === "hash") {
|
670 |
+
websocket.send(JSON.stringify({ fn_index, session_hash }));
|
671 |
+
return;
|
672 |
+
} else if (type === "data") {
|
673 |
+
websocket.send(JSON.stringify({ ...payload, session_hash }));
|
674 |
+
} else if (type === "complete") {
|
675 |
+
complete = status;
|
676 |
+
} else if (type === "log") {
|
677 |
+
fire_event({
|
678 |
+
type: "log",
|
679 |
+
log: data2.log,
|
680 |
+
level: data2.level,
|
681 |
+
endpoint: _endpoint,
|
682 |
+
fn_index
|
683 |
+
});
|
684 |
+
} else if (type === "generating") {
|
685 |
+
fire_event({
|
686 |
+
type: "status",
|
687 |
+
time: /* @__PURE__ */ new Date(),
|
688 |
+
...status,
|
689 |
+
stage: status == null ? void 0 : status.stage,
|
690 |
+
queue: true,
|
691 |
+
endpoint: _endpoint,
|
692 |
+
fn_index
|
693 |
+
});
|
694 |
+
}
|
695 |
+
if (data2) {
|
696 |
+
fire_event({
|
697 |
+
type: "data",
|
698 |
+
time: /* @__PURE__ */ new Date(),
|
699 |
+
data: transform_files ? transform_output(
|
700 |
+
data2.data,
|
701 |
+
api_info,
|
702 |
+
config.root,
|
703 |
+
config.root_url
|
704 |
+
) : data2.data,
|
705 |
+
endpoint: _endpoint,
|
706 |
+
fn_index
|
707 |
+
});
|
708 |
+
if (complete) {
|
709 |
+
fire_event({
|
710 |
+
type: "status",
|
711 |
+
time: /* @__PURE__ */ new Date(),
|
712 |
+
...complete,
|
713 |
+
stage: status == null ? void 0 : status.stage,
|
714 |
+
queue: true,
|
715 |
+
endpoint: _endpoint,
|
716 |
+
fn_index
|
717 |
+
});
|
718 |
+
websocket.close();
|
719 |
+
}
|
720 |
+
}
|
721 |
+
};
|
722 |
+
if (semiver(config.version || "2.0.0", "3.6") < 0) {
|
723 |
+
addEventListener(
|
724 |
+
"open",
|
725 |
+
() => websocket.send(JSON.stringify({ hash: session_hash }))
|
726 |
+
);
|
727 |
+
}
|
728 |
+
} else if (protocol == "sse") {
|
729 |
+
fire_event({
|
730 |
+
type: "status",
|
731 |
+
stage: "pending",
|
732 |
+
queue: true,
|
733 |
+
endpoint: _endpoint,
|
734 |
+
fn_index,
|
735 |
+
time: /* @__PURE__ */ new Date()
|
736 |
+
});
|
737 |
+
var params = new URLSearchParams({
|
738 |
+
fn_index: fn_index.toString(),
|
739 |
+
session_hash
|
740 |
+
}).toString();
|
741 |
+
let url = new URL(
|
742 |
+
`${config.root}/queue/join?${url_params ? url_params + "&" : ""}${params}`
|
743 |
+
);
|
744 |
+
eventSource = EventSource_factory(url.toString());
|
745 |
+
eventSource.onmessage = async function(event) {
|
746 |
+
const _data = JSON.parse(event.data);
|
747 |
+
const { type, status, data: data2 } = handle_message(
|
748 |
+
_data,
|
749 |
+
last_status[fn_index]
|
750 |
+
);
|
751 |
+
if (type === "update" && status && !complete) {
|
752 |
+
fire_event({
|
753 |
+
type: "status",
|
754 |
+
endpoint: _endpoint,
|
755 |
+
fn_index,
|
756 |
+
time: /* @__PURE__ */ new Date(),
|
757 |
+
...status
|
758 |
+
});
|
759 |
+
if (status.stage === "error") {
|
760 |
+
eventSource.close();
|
761 |
+
}
|
762 |
+
} else if (type === "data") {
|
763 |
+
event_id = _data.event_id;
|
764 |
+
let [_, status2] = await post_data2(
|
765 |
+
`${config.root}/queue/data`,
|
766 |
+
{
|
767 |
+
...payload,
|
768 |
+
session_hash,
|
769 |
+
event_id
|
770 |
+
},
|
771 |
+
hf_token
|
772 |
+
);
|
773 |
+
if (status2 !== 200) {
|
774 |
+
fire_event({
|
775 |
+
type: "status",
|
776 |
+
stage: "error",
|
777 |
+
message: BROKEN_CONNECTION_MSG,
|
778 |
+
queue: true,
|
779 |
+
endpoint: _endpoint,
|
780 |
+
fn_index,
|
781 |
+
time: /* @__PURE__ */ new Date()
|
782 |
+
});
|
783 |
+
eventSource.close();
|
784 |
+
}
|
785 |
+
} else if (type === "complete") {
|
786 |
+
complete = status;
|
787 |
+
} else if (type === "log") {
|
788 |
+
fire_event({
|
789 |
+
type: "log",
|
790 |
+
log: data2.log,
|
791 |
+
level: data2.level,
|
792 |
+
endpoint: _endpoint,
|
793 |
+
fn_index
|
794 |
+
});
|
795 |
+
} else if (type === "generating") {
|
796 |
+
fire_event({
|
797 |
+
type: "status",
|
798 |
+
time: /* @__PURE__ */ new Date(),
|
799 |
+
...status,
|
800 |
+
stage: status == null ? void 0 : status.stage,
|
801 |
+
queue: true,
|
802 |
+
endpoint: _endpoint,
|
803 |
+
fn_index
|
804 |
+
});
|
805 |
+
}
|
806 |
+
if (data2) {
|
807 |
+
fire_event({
|
808 |
+
type: "data",
|
809 |
+
time: /* @__PURE__ */ new Date(),
|
810 |
+
data: transform_files ? transform_output(
|
811 |
+
data2.data,
|
812 |
+
api_info,
|
813 |
+
config.root,
|
814 |
+
config.root_url
|
815 |
+
) : data2.data,
|
816 |
+
endpoint: _endpoint,
|
817 |
+
fn_index
|
818 |
+
});
|
819 |
+
if (complete) {
|
820 |
+
fire_event({
|
821 |
+
type: "status",
|
822 |
+
time: /* @__PURE__ */ new Date(),
|
823 |
+
...complete,
|
824 |
+
stage: status == null ? void 0 : status.stage,
|
825 |
+
queue: true,
|
826 |
+
endpoint: _endpoint,
|
827 |
+
fn_index
|
828 |
+
});
|
829 |
+
eventSource.close();
|
830 |
+
}
|
831 |
+
}
|
832 |
+
};
|
833 |
+
} else if (protocol == "sse_v1") {
|
834 |
+
fire_event({
|
835 |
+
type: "status",
|
836 |
+
stage: "pending",
|
837 |
+
queue: true,
|
838 |
+
endpoint: _endpoint,
|
839 |
+
fn_index,
|
840 |
+
time: /* @__PURE__ */ new Date()
|
841 |
+
});
|
842 |
+
post_data2(
|
843 |
+
`${config.root}/queue/join?${url_params}`,
|
844 |
+
{
|
845 |
+
...payload,
|
846 |
+
session_hash
|
847 |
+
},
|
848 |
+
hf_token
|
849 |
+
).then(([response, status]) => {
|
850 |
+
if (status === 503) {
|
851 |
+
fire_event({
|
852 |
+
type: "status",
|
853 |
+
stage: "error",
|
854 |
+
message: QUEUE_FULL_MSG,
|
855 |
+
queue: true,
|
856 |
+
endpoint: _endpoint,
|
857 |
+
fn_index,
|
858 |
+
time: /* @__PURE__ */ new Date()
|
859 |
+
});
|
860 |
+
} else if (status !== 200) {
|
861 |
+
fire_event({
|
862 |
+
type: "status",
|
863 |
+
stage: "error",
|
864 |
+
message: BROKEN_CONNECTION_MSG,
|
865 |
+
queue: true,
|
866 |
+
endpoint: _endpoint,
|
867 |
+
fn_index,
|
868 |
+
time: /* @__PURE__ */ new Date()
|
869 |
+
});
|
870 |
+
} else {
|
871 |
+
event_id = response.event_id;
|
872 |
+
let callback = async function(_data) {
|
873 |
+
try {
|
874 |
+
const { type, status: status2, data: data2 } = handle_message(
|
875 |
+
_data,
|
876 |
+
last_status[fn_index]
|
877 |
+
);
|
878 |
+
if (type == "heartbeat") {
|
879 |
+
return;
|
880 |
+
}
|
881 |
+
if (type === "update" && status2 && !complete) {
|
882 |
+
fire_event({
|
883 |
+
type: "status",
|
884 |
+
endpoint: _endpoint,
|
885 |
+
fn_index,
|
886 |
+
time: /* @__PURE__ */ new Date(),
|
887 |
+
...status2
|
888 |
+
});
|
889 |
+
} else if (type === "complete") {
|
890 |
+
complete = status2;
|
891 |
+
} else if (type == "unexpected_error") {
|
892 |
+
console.error("Unexpected error", status2 == null ? void 0 : status2.message);
|
893 |
+
fire_event({
|
894 |
+
type: "status",
|
895 |
+
stage: "error",
|
896 |
+
message: (status2 == null ? void 0 : status2.message) || "An Unexpected Error Occurred!",
|
897 |
+
queue: true,
|
898 |
+
endpoint: _endpoint,
|
899 |
+
fn_index,
|
900 |
+
time: /* @__PURE__ */ new Date()
|
901 |
+
});
|
902 |
+
} else if (type === "log") {
|
903 |
+
fire_event({
|
904 |
+
type: "log",
|
905 |
+
log: data2.log,
|
906 |
+
level: data2.level,
|
907 |
+
endpoint: _endpoint,
|
908 |
+
fn_index
|
909 |
+
});
|
910 |
+
return;
|
911 |
+
} else if (type === "generating") {
|
912 |
+
fire_event({
|
913 |
+
type: "status",
|
914 |
+
time: /* @__PURE__ */ new Date(),
|
915 |
+
...status2,
|
916 |
+
stage: status2 == null ? void 0 : status2.stage,
|
917 |
+
queue: true,
|
918 |
+
endpoint: _endpoint,
|
919 |
+
fn_index
|
920 |
+
});
|
921 |
+
}
|
922 |
+
if (data2) {
|
923 |
+
fire_event({
|
924 |
+
type: "data",
|
925 |
+
time: /* @__PURE__ */ new Date(),
|
926 |
+
data: transform_files ? transform_output(
|
927 |
+
data2.data,
|
928 |
+
api_info,
|
929 |
+
config.root,
|
930 |
+
config.root_url
|
931 |
+
) : data2.data,
|
932 |
+
endpoint: _endpoint,
|
933 |
+
fn_index
|
934 |
+
});
|
935 |
+
if (complete) {
|
936 |
+
fire_event({
|
937 |
+
type: "status",
|
938 |
+
time: /* @__PURE__ */ new Date(),
|
939 |
+
...complete,
|
940 |
+
stage: status2 == null ? void 0 : status2.stage,
|
941 |
+
queue: true,
|
942 |
+
endpoint: _endpoint,
|
943 |
+
fn_index
|
944 |
+
});
|
945 |
+
}
|
946 |
+
}
|
947 |
+
if ((status2 == null ? void 0 : status2.stage) === "complete" || (status2 == null ? void 0 : status2.stage) === "error") {
|
948 |
+
if (event_callbacks[event_id]) {
|
949 |
+
delete event_callbacks[event_id];
|
950 |
+
}
|
951 |
+
}
|
952 |
+
} catch (e) {
|
953 |
+
console.error("Unexpected client exception", e);
|
954 |
+
fire_event({
|
955 |
+
type: "status",
|
956 |
+
stage: "error",
|
957 |
+
message: "An Unexpected Error Occurred!",
|
958 |
+
queue: true,
|
959 |
+
endpoint: _endpoint,
|
960 |
+
fn_index,
|
961 |
+
time: /* @__PURE__ */ new Date()
|
962 |
+
});
|
963 |
+
close_stream();
|
964 |
+
}
|
965 |
+
};
|
966 |
+
if (event_id in pending_stream_messages) {
|
967 |
+
pending_stream_messages[event_id].forEach(
|
968 |
+
(msg) => callback(msg)
|
969 |
+
);
|
970 |
+
delete pending_stream_messages[event_id];
|
971 |
+
}
|
972 |
+
event_callbacks[event_id] = callback;
|
973 |
+
unclosed_events.add(event_id);
|
974 |
+
if (!stream_open) {
|
975 |
+
open_stream();
|
976 |
+
}
|
977 |
+
}
|
978 |
+
});
|
979 |
+
}
|
980 |
+
}
|
981 |
+
);
|
982 |
+
function fire_event(event) {
|
983 |
+
const narrowed_listener_map = listener_map;
|
984 |
+
const listeners = narrowed_listener_map[event.type] || [];
|
985 |
+
listeners == null ? void 0 : listeners.forEach((l) => l(event));
|
986 |
+
}
|
987 |
+
function on(eventType, listener) {
|
988 |
+
const narrowed_listener_map = listener_map;
|
989 |
+
const listeners = narrowed_listener_map[eventType] || [];
|
990 |
+
narrowed_listener_map[eventType] = listeners;
|
991 |
+
listeners == null ? void 0 : listeners.push(listener);
|
992 |
+
return { on, off, cancel, destroy };
|
993 |
+
}
|
994 |
+
function off(eventType, listener) {
|
995 |
+
const narrowed_listener_map = listener_map;
|
996 |
+
let listeners = narrowed_listener_map[eventType] || [];
|
997 |
+
listeners = listeners == null ? void 0 : listeners.filter((l) => l !== listener);
|
998 |
+
narrowed_listener_map[eventType] = listeners;
|
999 |
+
return { on, off, cancel, destroy };
|
1000 |
+
}
|
1001 |
+
async function cancel() {
|
1002 |
+
const _status = {
|
1003 |
+
stage: "complete",
|
1004 |
+
queue: false,
|
1005 |
+
time: /* @__PURE__ */ new Date()
|
1006 |
+
};
|
1007 |
+
complete = _status;
|
1008 |
+
fire_event({
|
1009 |
+
..._status,
|
1010 |
+
type: "status",
|
1011 |
+
endpoint: _endpoint,
|
1012 |
+
fn_index
|
1013 |
+
});
|
1014 |
+
let cancel_request = {};
|
1015 |
+
if (protocol === "ws") {
|
1016 |
+
if (websocket && websocket.readyState === 0) {
|
1017 |
+
websocket.addEventListener("open", () => {
|
1018 |
+
websocket.close();
|
1019 |
+
});
|
1020 |
+
} else {
|
1021 |
+
websocket.close();
|
1022 |
+
}
|
1023 |
+
cancel_request = { fn_index, session_hash };
|
1024 |
+
} else {
|
1025 |
+
eventSource.close();
|
1026 |
+
cancel_request = { event_id };
|
1027 |
+
}
|
1028 |
+
try {
|
1029 |
+
await fetch_implementation(`${config.root}/reset`, {
|
1030 |
+
headers: { "Content-Type": "application/json" },
|
1031 |
+
method: "POST",
|
1032 |
+
body: JSON.stringify(cancel_request)
|
1033 |
+
});
|
1034 |
+
} catch (e) {
|
1035 |
+
console.warn(
|
1036 |
+
"The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable."
|
1037 |
+
);
|
1038 |
+
}
|
1039 |
+
}
|
1040 |
+
function destroy() {
|
1041 |
+
for (const event_type in listener_map) {
|
1042 |
+
listener_map[event_type].forEach((fn2) => {
|
1043 |
+
off(event_type, fn2);
|
1044 |
+
});
|
1045 |
+
}
|
1046 |
+
}
|
1047 |
+
return {
|
1048 |
+
on,
|
1049 |
+
off,
|
1050 |
+
cancel,
|
1051 |
+
destroy
|
1052 |
+
};
|
1053 |
+
}
|
1054 |
+
function open_stream() {
|
1055 |
+
stream_open = true;
|
1056 |
+
let params = new URLSearchParams({
|
1057 |
+
session_hash
|
1058 |
+
}).toString();
|
1059 |
+
let url = new URL(`${config.root}/queue/data?${params}`);
|
1060 |
+
event_stream = EventSource_factory(url.toString());
|
1061 |
+
event_stream.onmessage = async function(event) {
|
1062 |
+
let _data = JSON.parse(event.data);
|
1063 |
+
const event_id = _data.event_id;
|
1064 |
+
if (!event_id) {
|
1065 |
+
await Promise.all(
|
1066 |
+
Object.keys(event_callbacks).map(
|
1067 |
+
(event_id2) => event_callbacks[event_id2](_data)
|
1068 |
+
)
|
1069 |
+
);
|
1070 |
+
} else if (event_callbacks[event_id]) {
|
1071 |
+
if (_data.msg === "process_completed") {
|
1072 |
+
unclosed_events.delete(event_id);
|
1073 |
+
if (unclosed_events.size === 0) {
|
1074 |
+
close_stream();
|
1075 |
+
}
|
1076 |
+
}
|
1077 |
+
let fn2 = event_callbacks[event_id];
|
1078 |
+
if (typeof window !== "undefined") {
|
1079 |
+
window.setTimeout(fn2, 0, _data);
|
1080 |
+
} else {
|
1081 |
+
setTimeout(fn2, 0, _data);
|
1082 |
+
}
|
1083 |
+
} else {
|
1084 |
+
if (!pending_stream_messages[event_id]) {
|
1085 |
+
pending_stream_messages[event_id] = [];
|
1086 |
+
}
|
1087 |
+
pending_stream_messages[event_id].push(_data);
|
1088 |
+
}
|
1089 |
+
};
|
1090 |
+
event_stream.onerror = async function(event) {
|
1091 |
+
await Promise.all(
|
1092 |
+
Object.keys(event_callbacks).map(
|
1093 |
+
(event_id) => event_callbacks[event_id]({
|
1094 |
+
msg: "unexpected_error",
|
1095 |
+
message: BROKEN_CONNECTION_MSG
|
1096 |
+
})
|
1097 |
+
)
|
1098 |
+
);
|
1099 |
+
close_stream();
|
1100 |
+
};
|
1101 |
+
}
|
1102 |
+
function close_stream() {
|
1103 |
+
stream_open = false;
|
1104 |
+
event_stream == null ? void 0 : event_stream.close();
|
1105 |
+
}
|
1106 |
+
async function component_server(component_id, fn_name, data) {
|
1107 |
+
var _a;
|
1108 |
+
const headers = { "Content-Type": "application/json" };
|
1109 |
+
if (hf_token) {
|
1110 |
+
headers.Authorization = `Bearer ${hf_token}`;
|
1111 |
+
}
|
1112 |
+
let root_url;
|
1113 |
+
let component = config.components.find(
|
1114 |
+
(comp) => comp.id === component_id
|
1115 |
+
);
|
1116 |
+
if ((_a = component == null ? void 0 : component.props) == null ? void 0 : _a.root_url) {
|
1117 |
+
root_url = component.props.root_url;
|
1118 |
+
} else {
|
1119 |
+
root_url = config.root;
|
1120 |
+
}
|
1121 |
+
const response = await fetch_implementation(
|
1122 |
+
`${root_url}/component_server/`,
|
1123 |
+
{
|
1124 |
+
method: "POST",
|
1125 |
+
body: JSON.stringify({
|
1126 |
+
data,
|
1127 |
+
component_id,
|
1128 |
+
fn_name,
|
1129 |
+
session_hash
|
1130 |
+
}),
|
1131 |
+
headers
|
1132 |
+
}
|
1133 |
+
);
|
1134 |
+
if (!response.ok) {
|
1135 |
+
throw new Error(
|
1136 |
+
"Could not connect to component server: " + response.statusText
|
1137 |
+
);
|
1138 |
+
}
|
1139 |
+
const output = await response.json();
|
1140 |
+
return output;
|
1141 |
+
}
|
1142 |
+
async function view_api(config2) {
|
1143 |
+
if (api)
|
1144 |
+
return api;
|
1145 |
+
const headers = { "Content-Type": "application/json" };
|
1146 |
+
if (hf_token) {
|
1147 |
+
headers.Authorization = `Bearer ${hf_token}`;
|
1148 |
+
}
|
1149 |
+
let response;
|
1150 |
+
if (semiver(config2.version || "2.0.0", "3.30") < 0) {
|
1151 |
+
response = await fetch_implementation(
|
1152 |
+
"https://gradio-space-api-fetcher-v2.hf.space/api",
|
1153 |
+
{
|
1154 |
+
method: "POST",
|
1155 |
+
body: JSON.stringify({
|
1156 |
+
serialize: false,
|
1157 |
+
config: JSON.stringify(config2)
|
1158 |
+
}),
|
1159 |
+
headers
|
1160 |
+
}
|
1161 |
+
);
|
1162 |
+
} else {
|
1163 |
+
response = await fetch_implementation(`${config2.root}/info`, {
|
1164 |
+
headers
|
1165 |
+
});
|
1166 |
+
}
|
1167 |
+
if (!response.ok) {
|
1168 |
+
throw new Error(BROKEN_CONNECTION_MSG);
|
1169 |
+
}
|
1170 |
+
let api_info = await response.json();
|
1171 |
+
if ("api" in api_info) {
|
1172 |
+
api_info = api_info.api;
|
1173 |
+
}
|
1174 |
+
if (api_info.named_endpoints["/predict"] && !api_info.unnamed_endpoints["0"]) {
|
1175 |
+
api_info.unnamed_endpoints[0] = api_info.named_endpoints["/predict"];
|
1176 |
+
}
|
1177 |
+
const x = transform_api_info(api_info, config2, api_map);
|
1178 |
+
return x;
|
1179 |
+
}
|
1180 |
+
});
|
1181 |
+
}
|
1182 |
+
async function handle_blob2(endpoint, data, api_info, token) {
|
1183 |
+
const blob_refs = await walk_and_store_blobs(
|
1184 |
+
data,
|
1185 |
+
void 0,
|
1186 |
+
[],
|
1187 |
+
true,
|
1188 |
+
api_info
|
1189 |
+
);
|
1190 |
+
return Promise.all(
|
1191 |
+
blob_refs.map(async ({ path, blob, type }) => {
|
1192 |
+
if (blob) {
|
1193 |
+
const file_url = (await upload_files2(endpoint, [blob], token)).files[0];
|
1194 |
+
return { path, file_url, type, name: blob == null ? void 0 : blob.name };
|
1195 |
+
}
|
1196 |
+
return { path, type };
|
1197 |
+
})
|
1198 |
+
).then((r) => {
|
1199 |
+
r.forEach(({ path, file_url, type, name }) => {
|
1200 |
+
if (type === "Gallery") {
|
1201 |
+
update_object(data, file_url, path);
|
1202 |
+
} else if (file_url) {
|
1203 |
+
const file = new FileData({ path: file_url, orig_name: name });
|
1204 |
+
update_object(data, file, path);
|
1205 |
+
}
|
1206 |
+
});
|
1207 |
+
return data;
|
1208 |
+
});
|
1209 |
+
}
|
1210 |
+
}
|
1211 |
+
const { post_data, upload_files, client, handle_blob } = api_factory(
|
1212 |
+
fetch,
|
1213 |
+
(...args) => new EventSource(...args)
|
1214 |
+
);
|
1215 |
+
function transform_output(data, api_info, root_url, remote_url) {
|
1216 |
+
return data.map((d, i) => {
|
1217 |
+
var _a, _b, _c, _d;
|
1218 |
+
if (((_b = (_a = api_info == null ? void 0 : api_info.returns) == null ? void 0 : _a[i]) == null ? void 0 : _b.component) === "File") {
|
1219 |
+
return normalise_file(d, root_url, remote_url);
|
1220 |
+
} else if (((_d = (_c = api_info == null ? void 0 : api_info.returns) == null ? void 0 : _c[i]) == null ? void 0 : _d.component) === "Gallery") {
|
1221 |
+
return d.map((img) => {
|
1222 |
+
return Array.isArray(img) ? [normalise_file(img[0], root_url, remote_url), img[1]] : [normalise_file(img, root_url, remote_url), null];
|
1223 |
+
});
|
1224 |
+
} else if (typeof d === "object" && d.path) {
|
1225 |
+
return normalise_file(d, root_url, remote_url);
|
1226 |
+
}
|
1227 |
+
return d;
|
1228 |
+
});
|
1229 |
+
}
|
1230 |
+
function get_type(type, component, serializer, signature_type) {
|
1231 |
+
switch (type.type) {
|
1232 |
+
case "string":
|
1233 |
+
return "string";
|
1234 |
+
case "boolean":
|
1235 |
+
return "boolean";
|
1236 |
+
case "number":
|
1237 |
+
return "number";
|
1238 |
+
}
|
1239 |
+
if (serializer === "JSONSerializable" || serializer === "StringSerializable") {
|
1240 |
+
return "any";
|
1241 |
+
} else if (serializer === "ListStringSerializable") {
|
1242 |
+
return "string[]";
|
1243 |
+
} else if (component === "Image") {
|
1244 |
+
return signature_type === "parameter" ? "Blob | File | Buffer" : "string";
|
1245 |
+
} else if (serializer === "FileSerializable") {
|
1246 |
+
if ((type == null ? void 0 : type.type) === "array") {
|
1247 |
+
return signature_type === "parameter" ? "(Blob | File | Buffer)[]" : `{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]`;
|
1248 |
+
}
|
1249 |
+
return signature_type === "parameter" ? "Blob | File | Buffer" : `{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}`;
|
1250 |
+
} else if (serializer === "GallerySerializable") {
|
1251 |
+
return signature_type === "parameter" ? "[(Blob | File | Buffer), (string | null)][]" : `[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]`;
|
1252 |
+
}
|
1253 |
+
}
|
1254 |
+
function get_description(type, serializer) {
|
1255 |
+
if (serializer === "GallerySerializable") {
|
1256 |
+
return "array of [file, label] tuples";
|
1257 |
+
} else if (serializer === "ListStringSerializable") {
|
1258 |
+
return "array of strings";
|
1259 |
+
} else if (serializer === "FileSerializable") {
|
1260 |
+
return "array of files or single file";
|
1261 |
+
}
|
1262 |
+
return type.description;
|
1263 |
+
}
|
1264 |
+
function transform_api_info(api_info, config, api_map) {
|
1265 |
+
const new_data = {
|
1266 |
+
named_endpoints: {},
|
1267 |
+
unnamed_endpoints: {}
|
1268 |
+
};
|
1269 |
+
for (const key in api_info) {
|
1270 |
+
const cat = api_info[key];
|
1271 |
+
for (const endpoint in cat) {
|
1272 |
+
const dep_index = config.dependencies[endpoint] ? endpoint : api_map[endpoint.replace("/", "")];
|
1273 |
+
const info = cat[endpoint];
|
1274 |
+
new_data[key][endpoint] = {};
|
1275 |
+
new_data[key][endpoint].parameters = {};
|
1276 |
+
new_data[key][endpoint].returns = {};
|
1277 |
+
new_data[key][endpoint].type = config.dependencies[dep_index].types;
|
1278 |
+
new_data[key][endpoint].parameters = info.parameters.map(
|
1279 |
+
({ label, component, type, serializer }) => ({
|
1280 |
+
label,
|
1281 |
+
component,
|
1282 |
+
type: get_type(type, component, serializer, "parameter"),
|
1283 |
+
description: get_description(type, serializer)
|
1284 |
+
})
|
1285 |
+
);
|
1286 |
+
new_data[key][endpoint].returns = info.returns.map(
|
1287 |
+
({ label, component, type, serializer }) => ({
|
1288 |
+
label,
|
1289 |
+
component,
|
1290 |
+
type: get_type(type, component, serializer, "return"),
|
1291 |
+
description: get_description(type, serializer)
|
1292 |
+
})
|
1293 |
+
);
|
1294 |
+
}
|
1295 |
+
}
|
1296 |
+
return new_data;
|
1297 |
+
}
|
1298 |
+
async function get_jwt(space, token) {
|
1299 |
+
try {
|
1300 |
+
const r = await fetch(`https://huggingface.co/api/spaces/${space}/jwt`, {
|
1301 |
+
headers: {
|
1302 |
+
Authorization: `Bearer ${token}`
|
1303 |
+
}
|
1304 |
+
});
|
1305 |
+
const jwt = (await r.json()).token;
|
1306 |
+
return jwt || false;
|
1307 |
+
} catch (e) {
|
1308 |
+
console.error(e);
|
1309 |
+
return false;
|
1310 |
+
}
|
1311 |
+
}
|
1312 |
+
function update_object(object, newValue, stack) {
|
1313 |
+
while (stack.length > 1) {
|
1314 |
+
object = object[stack.shift()];
|
1315 |
+
}
|
1316 |
+
object[stack.shift()] = newValue;
|
1317 |
+
}
|
1318 |
+
async function walk_and_store_blobs(param, type = void 0, path = [], root = false, api_info = void 0) {
|
1319 |
+
if (Array.isArray(param)) {
|
1320 |
+
let blob_refs = [];
|
1321 |
+
await Promise.all(
|
1322 |
+
param.map(async (v, i) => {
|
1323 |
+
var _a;
|
1324 |
+
let new_path = path.slice();
|
1325 |
+
new_path.push(i);
|
1326 |
+
const array_refs = await walk_and_store_blobs(
|
1327 |
+
param[i],
|
1328 |
+
root ? ((_a = api_info == null ? void 0 : api_info.parameters[i]) == null ? void 0 : _a.component) || void 0 : type,
|
1329 |
+
new_path,
|
1330 |
+
false,
|
1331 |
+
api_info
|
1332 |
+
);
|
1333 |
+
blob_refs = blob_refs.concat(array_refs);
|
1334 |
+
})
|
1335 |
+
);
|
1336 |
+
return blob_refs;
|
1337 |
+
} else if (globalThis.Buffer && param instanceof globalThis.Buffer) {
|
1338 |
+
const is_image = type === "Image";
|
1339 |
+
return [
|
1340 |
+
{
|
1341 |
+
path,
|
1342 |
+
blob: is_image ? false : new NodeBlob([param]),
|
1343 |
+
type
|
1344 |
+
}
|
1345 |
+
];
|
1346 |
+
} else if (typeof param === "object") {
|
1347 |
+
let blob_refs = [];
|
1348 |
+
for (let key in param) {
|
1349 |
+
if (param.hasOwnProperty(key)) {
|
1350 |
+
let new_path = path.slice();
|
1351 |
+
new_path.push(key);
|
1352 |
+
blob_refs = blob_refs.concat(
|
1353 |
+
await walk_and_store_blobs(
|
1354 |
+
param[key],
|
1355 |
+
void 0,
|
1356 |
+
new_path,
|
1357 |
+
false,
|
1358 |
+
api_info
|
1359 |
+
)
|
1360 |
+
);
|
1361 |
+
}
|
1362 |
+
}
|
1363 |
+
return blob_refs;
|
1364 |
+
}
|
1365 |
+
return [];
|
1366 |
+
}
|
1367 |
+
function skip_queue(id, config) {
|
1368 |
+
var _a, _b, _c, _d;
|
1369 |
+
return !(((_b = (_a = config == null ? void 0 : config.dependencies) == null ? void 0 : _a[id]) == null ? void 0 : _b.queue) === null ? config.enable_queue : (_d = (_c = config == null ? void 0 : config.dependencies) == null ? void 0 : _c[id]) == null ? void 0 : _d.queue) || false;
|
1370 |
+
}
|
1371 |
+
async function resolve_config(fetch_implementation, endpoint, token) {
|
1372 |
+
const headers = {};
|
1373 |
+
if (token) {
|
1374 |
+
headers.Authorization = `Bearer ${token}`;
|
1375 |
+
}
|
1376 |
+
if (typeof window !== "undefined" && window.gradio_config && location.origin !== "http://localhost:9876" && !window.gradio_config.dev_mode) {
|
1377 |
+
const path = window.gradio_config.root;
|
1378 |
+
const config = window.gradio_config;
|
1379 |
+
config.root = resolve_root(endpoint, config.root, false);
|
1380 |
+
return { ...config, path };
|
1381 |
+
} else if (endpoint) {
|
1382 |
+
let response = await fetch_implementation(`${endpoint}/config`, {
|
1383 |
+
headers
|
1384 |
+
});
|
1385 |
+
if (response.status === 200) {
|
1386 |
+
const config = await response.json();
|
1387 |
+
config.path = config.path ?? "";
|
1388 |
+
config.root = endpoint;
|
1389 |
+
return config;
|
1390 |
+
}
|
1391 |
+
throw new Error("Could not get config.");
|
1392 |
+
}
|
1393 |
+
throw new Error("No config or app endpoint found");
|
1394 |
+
}
|
1395 |
+
async function check_space_status(id, type, status_callback) {
|
1396 |
+
let endpoint = type === "subdomain" ? `https://huggingface.co/api/spaces/by-subdomain/${id}` : `https://huggingface.co/api/spaces/${id}`;
|
1397 |
+
let response;
|
1398 |
+
let _status;
|
1399 |
+
try {
|
1400 |
+
response = await fetch(endpoint);
|
1401 |
+
_status = response.status;
|
1402 |
+
if (_status !== 200) {
|
1403 |
+
throw new Error();
|
1404 |
+
}
|
1405 |
+
response = await response.json();
|
1406 |
+
} catch (e) {
|
1407 |
+
status_callback({
|
1408 |
+
status: "error",
|
1409 |
+
load_status: "error",
|
1410 |
+
message: "Could not get space status",
|
1411 |
+
detail: "NOT_FOUND"
|
1412 |
+
});
|
1413 |
+
return;
|
1414 |
+
}
|
1415 |
+
if (!response || _status !== 200)
|
1416 |
+
return;
|
1417 |
+
const {
|
1418 |
+
runtime: { stage },
|
1419 |
+
id: space_name
|
1420 |
+
} = response;
|
1421 |
+
switch (stage) {
|
1422 |
+
case "STOPPED":
|
1423 |
+
case "SLEEPING":
|
1424 |
+
status_callback({
|
1425 |
+
status: "sleeping",
|
1426 |
+
load_status: "pending",
|
1427 |
+
message: "Space is asleep. Waking it up...",
|
1428 |
+
detail: stage
|
1429 |
+
});
|
1430 |
+
setTimeout(() => {
|
1431 |
+
check_space_status(id, type, status_callback);
|
1432 |
+
}, 1e3);
|
1433 |
+
break;
|
1434 |
+
case "PAUSED":
|
1435 |
+
status_callback({
|
1436 |
+
status: "paused",
|
1437 |
+
load_status: "error",
|
1438 |
+
message: "This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
1439 |
+
detail: stage,
|
1440 |
+
discussions_enabled: await discussions_enabled(space_name)
|
1441 |
+
});
|
1442 |
+
break;
|
1443 |
+
case "RUNNING":
|
1444 |
+
case "RUNNING_BUILDING":
|
1445 |
+
status_callback({
|
1446 |
+
status: "running",
|
1447 |
+
load_status: "complete",
|
1448 |
+
message: "",
|
1449 |
+
detail: stage
|
1450 |
+
});
|
1451 |
+
break;
|
1452 |
+
case "BUILDING":
|
1453 |
+
status_callback({
|
1454 |
+
status: "building",
|
1455 |
+
load_status: "pending",
|
1456 |
+
message: "Space is building...",
|
1457 |
+
detail: stage
|
1458 |
+
});
|
1459 |
+
setTimeout(() => {
|
1460 |
+
check_space_status(id, type, status_callback);
|
1461 |
+
}, 1e3);
|
1462 |
+
break;
|
1463 |
+
default:
|
1464 |
+
status_callback({
|
1465 |
+
status: "space_error",
|
1466 |
+
load_status: "error",
|
1467 |
+
message: "This space is experiencing an issue.",
|
1468 |
+
detail: stage,
|
1469 |
+
discussions_enabled: await discussions_enabled(space_name)
|
1470 |
+
});
|
1471 |
+
break;
|
1472 |
+
}
|
1473 |
+
}
|
1474 |
+
function handle_message(data, last_status) {
|
1475 |
+
const queue = true;
|
1476 |
+
switch (data.msg) {
|
1477 |
+
case "send_data":
|
1478 |
+
return { type: "data" };
|
1479 |
+
case "send_hash":
|
1480 |
+
return { type: "hash" };
|
1481 |
+
case "queue_full":
|
1482 |
+
return {
|
1483 |
+
type: "update",
|
1484 |
+
status: {
|
1485 |
+
queue,
|
1486 |
+
message: QUEUE_FULL_MSG,
|
1487 |
+
stage: "error",
|
1488 |
+
code: data.code,
|
1489 |
+
success: data.success
|
1490 |
+
}
|
1491 |
+
};
|
1492 |
+
case "heartbeat":
|
1493 |
+
return {
|
1494 |
+
type: "heartbeat"
|
1495 |
+
};
|
1496 |
+
case "unexpected_error":
|
1497 |
+
return {
|
1498 |
+
type: "unexpected_error",
|
1499 |
+
status: {
|
1500 |
+
queue,
|
1501 |
+
message: data.message,
|
1502 |
+
stage: "error",
|
1503 |
+
success: false
|
1504 |
+
}
|
1505 |
+
};
|
1506 |
+
case "estimation":
|
1507 |
+
return {
|
1508 |
+
type: "update",
|
1509 |
+
status: {
|
1510 |
+
queue,
|
1511 |
+
stage: last_status || "pending",
|
1512 |
+
code: data.code,
|
1513 |
+
size: data.queue_size,
|
1514 |
+
position: data.rank,
|
1515 |
+
eta: data.rank_eta,
|
1516 |
+
success: data.success
|
1517 |
+
}
|
1518 |
+
};
|
1519 |
+
case "progress":
|
1520 |
+
return {
|
1521 |
+
type: "update",
|
1522 |
+
status: {
|
1523 |
+
queue,
|
1524 |
+
stage: "pending",
|
1525 |
+
code: data.code,
|
1526 |
+
progress_data: data.progress_data,
|
1527 |
+
success: data.success
|
1528 |
+
}
|
1529 |
+
};
|
1530 |
+
case "log":
|
1531 |
+
return { type: "log", data };
|
1532 |
+
case "process_generating":
|
1533 |
+
return {
|
1534 |
+
type: "generating",
|
1535 |
+
status: {
|
1536 |
+
queue,
|
1537 |
+
message: !data.success ? data.output.error : null,
|
1538 |
+
stage: data.success ? "generating" : "error",
|
1539 |
+
code: data.code,
|
1540 |
+
progress_data: data.progress_data,
|
1541 |
+
eta: data.average_duration
|
1542 |
+
},
|
1543 |
+
data: data.success ? data.output : null
|
1544 |
+
};
|
1545 |
+
case "process_completed":
|
1546 |
+
if ("error" in data.output) {
|
1547 |
+
return {
|
1548 |
+
type: "update",
|
1549 |
+
status: {
|
1550 |
+
queue,
|
1551 |
+
message: data.output.error,
|
1552 |
+
stage: "error",
|
1553 |
+
code: data.code,
|
1554 |
+
success: data.success
|
1555 |
+
}
|
1556 |
+
};
|
1557 |
+
}
|
1558 |
+
return {
|
1559 |
+
type: "complete",
|
1560 |
+
status: {
|
1561 |
+
queue,
|
1562 |
+
message: !data.success ? data.output.error : void 0,
|
1563 |
+
stage: data.success ? "complete" : "error",
|
1564 |
+
code: data.code,
|
1565 |
+
progress_data: data.progress_data
|
1566 |
+
},
|
1567 |
+
data: data.success ? data.output : null
|
1568 |
+
};
|
1569 |
+
case "process_starts":
|
1570 |
+
return {
|
1571 |
+
type: "update",
|
1572 |
+
status: {
|
1573 |
+
queue,
|
1574 |
+
stage: "pending",
|
1575 |
+
code: data.code,
|
1576 |
+
size: data.rank,
|
1577 |
+
position: 0,
|
1578 |
+
success: data.success,
|
1579 |
+
eta: data.eta
|
1580 |
+
}
|
1581 |
+
};
|
1582 |
+
}
|
1583 |
+
return { type: "none", status: { stage: "error", queue } };
|
1584 |
+
}
|
1585 |
+
export {
|
1586 |
+
FileData,
|
1587 |
+
api_factory,
|
1588 |
+
client,
|
1589 |
+
duplicate,
|
1590 |
+
get_fetchable_url_or_file,
|
1591 |
+
normalise_file,
|
1592 |
+
post_data,
|
1593 |
+
prepare_files,
|
1594 |
+
upload,
|
1595 |
+
upload_files
|
1596 |
+
};
|
node_modules/@gradio/client/dist/types.d.ts
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export interface Config {
|
2 |
+
auth_required: boolean | undefined;
|
3 |
+
auth_message: string;
|
4 |
+
components: any[];
|
5 |
+
css: string | null;
|
6 |
+
js: string | null;
|
7 |
+
head: string | null;
|
8 |
+
dependencies: any[];
|
9 |
+
dev_mode: boolean;
|
10 |
+
enable_queue: boolean;
|
11 |
+
layout: any;
|
12 |
+
mode: "blocks" | "interface";
|
13 |
+
root: string;
|
14 |
+
root_url?: string;
|
15 |
+
theme: string;
|
16 |
+
title: string;
|
17 |
+
version: string;
|
18 |
+
space_id: string | null;
|
19 |
+
is_colab: boolean;
|
20 |
+
show_api: boolean;
|
21 |
+
stylesheets: string[];
|
22 |
+
path: string;
|
23 |
+
protocol?: "sse_v1" | "sse" | "ws";
|
24 |
+
}
|
25 |
+
export interface Payload {
|
26 |
+
data: unknown[];
|
27 |
+
fn_index?: number;
|
28 |
+
event_data?: unknown;
|
29 |
+
time?: Date;
|
30 |
+
}
|
31 |
+
export interface PostResponse {
|
32 |
+
error?: string;
|
33 |
+
[x: string]: any;
|
34 |
+
}
|
35 |
+
export interface UploadResponse {
|
36 |
+
error?: string;
|
37 |
+
files?: string[];
|
38 |
+
}
|
39 |
+
export interface Status {
|
40 |
+
queue: boolean;
|
41 |
+
code?: string;
|
42 |
+
success?: boolean;
|
43 |
+
stage: "pending" | "error" | "complete" | "generating";
|
44 |
+
broken?: boolean;
|
45 |
+
size?: number;
|
46 |
+
position?: number;
|
47 |
+
eta?: number;
|
48 |
+
message?: string;
|
49 |
+
progress_data?: {
|
50 |
+
progress: number | null;
|
51 |
+
index: number | null;
|
52 |
+
length: number | null;
|
53 |
+
unit: string | null;
|
54 |
+
desc: string | null;
|
55 |
+
}[];
|
56 |
+
time?: Date;
|
57 |
+
}
|
58 |
+
export interface LogMessage {
|
59 |
+
log: string;
|
60 |
+
level: "warning" | "info";
|
61 |
+
}
|
62 |
+
export interface SpaceStatusNormal {
|
63 |
+
status: "sleeping" | "running" | "building" | "error" | "stopped";
|
64 |
+
detail: "SLEEPING" | "RUNNING" | "RUNNING_BUILDING" | "BUILDING" | "NOT_FOUND";
|
65 |
+
load_status: "pending" | "error" | "complete" | "generating";
|
66 |
+
message: string;
|
67 |
+
}
|
68 |
+
export interface SpaceStatusError {
|
69 |
+
status: "space_error" | "paused";
|
70 |
+
detail: "NO_APP_FILE" | "CONFIG_ERROR" | "BUILD_ERROR" | "RUNTIME_ERROR" | "PAUSED";
|
71 |
+
load_status: "error";
|
72 |
+
message: string;
|
73 |
+
discussions_enabled: boolean;
|
74 |
+
}
|
75 |
+
export type SpaceStatus = SpaceStatusNormal | SpaceStatusError;
|
76 |
+
export type status_callback_function = (a: Status) => void;
|
77 |
+
export type SpaceStatusCallback = (a: SpaceStatus) => void;
|
78 |
+
export type EventType = "data" | "status" | "log";
|
79 |
+
export interface EventMap {
|
80 |
+
data: Payload;
|
81 |
+
status: Status;
|
82 |
+
log: LogMessage;
|
83 |
+
}
|
84 |
+
export type Event<K extends EventType> = {
|
85 |
+
[P in K]: EventMap[P] & {
|
86 |
+
type: P;
|
87 |
+
endpoint: string;
|
88 |
+
fn_index: number;
|
89 |
+
};
|
90 |
+
}[K];
|
91 |
+
export type EventListener<K extends EventType> = (event: Event<K>) => void;
|
92 |
+
export type ListenerMap<K extends EventType> = {
|
93 |
+
[P in K]?: EventListener<K>[];
|
94 |
+
};
|
95 |
+
export interface FileData {
|
96 |
+
name: string;
|
97 |
+
orig_name?: string;
|
98 |
+
size?: number;
|
99 |
+
data: string;
|
100 |
+
blob?: File;
|
101 |
+
is_file?: boolean;
|
102 |
+
mime_type?: string;
|
103 |
+
alt_text?: string;
|
104 |
+
}
|
105 |
+
//# sourceMappingURL=types.d.ts.map
|
node_modules/@gradio/client/dist/types.d.ts.map
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACtB,aAAa,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,YAAY,EAAE,GAAG,EAAE,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,GAAG,CAAC;IACZ,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,OAAO;IACvB,IAAI,EAAE,OAAO,EAAE,CAAC;I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CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE;CAC7B,CAAC;AACF,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
node_modules/@gradio/client/dist/upload.d.ts
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { upload_files } from "./client";
|
2 |
+
export declare function normalise_file(file: FileData | null, server_url: string, proxy_url: string | null): FileData | null;
|
3 |
+
export declare function normalise_file(file: FileData[] | null, server_url: string, proxy_url: string | null): FileData[] | null;
|
4 |
+
export declare function normalise_file(file: FileData[] | FileData | null, server_url: string, // root: string,
|
5 |
+
proxy_url: string | null): FileData[] | FileData | null;
|
6 |
+
export declare function get_fetchable_url_or_file(path: string | null, server_url: string, proxy_url: string | null): string;
|
7 |
+
export declare function upload(file_data: FileData[], root: string, upload_id?: string, upload_fn?: typeof upload_files): Promise<(FileData | null)[] | null>;
|
8 |
+
export declare function prepare_files(files: File[], is_stream?: boolean): Promise<FileData[]>;
|
9 |
+
export declare class FileData {
|
10 |
+
path: string;
|
11 |
+
url?: string;
|
12 |
+
orig_name?: string;
|
13 |
+
size?: number;
|
14 |
+
blob?: File;
|
15 |
+
is_stream?: boolean;
|
16 |
+
mime_type?: string;
|
17 |
+
alt_text?: string;
|
18 |
+
constructor({ path, url, orig_name, size, blob, is_stream, mime_type, alt_text }: {
|
19 |
+
path: string;
|
20 |
+
url?: string;
|
21 |
+
orig_name?: string;
|
22 |
+
size?: number;
|
23 |
+
blob?: File;
|
24 |
+
is_stream?: boolean;
|
25 |
+
mime_type?: string;
|
26 |
+
alt_text?: string;
|
27 |
+
});
|
28 |
+
}
|
29 |
+
//# sourceMappingURL=upload.d.ts.map
|
node_modules/@gradio/client/dist/upload.d.ts.map
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,wBAAgB,cAAc,CAC7B,IAAI,EAAE,QAAQ,GAAG,IAAI,EACrB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAAG,IAAI,GACtB,QAAQ,GAAG,IAAI,CAAC;AAEnB,wBAAgB,cAAc,CAC7B,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,EACvB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAAG,IAAI,GACtB,QAAQ,EAAE,GAAG,IAAI,CAAC;AAErB,wBAAgB,cAAc,CAC7B,IAAI,EAAE,QAAQ,EAAE,GAAG,QAAQ,GAAG,IAAI,EAClC,UAAU,EAAE,MAAM,EAAE,gBAAgB;AACpC,SAAS,EAAE,MAAM,GAAG,IAAI,GACtB,QAAQ,EAAE,GAAG,QAAQ,GAAG,IAAI,CAAC;AAqDhC,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAUR;AAED,wBAAsB,MAAM,CAC3B,SAAS,EAAE,QAAQ,EAAE,EACrB,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,EAClB,SAAS,GAAE,OAAO,YAA2B,GAC3C,OAAO,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,CAwBrC;AAED,wBAAsB,aAAa,CAClC,KAAK,EAAE,IAAI,EAAE,EACb,SAAS,CAAC,EAAE,OAAO,GACjB,OAAO,CAAC,QAAQ,EAAE,CAAC,CAYrB;AAED,qBAAa,QAAQ;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAEN,EACX,IAAI,EACJ,GAAG,EACH,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,QAAQ,EACR,EAAE;QACF,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB;CAUD"}
|
node_modules/@gradio/client/dist/utils.d.ts
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { Config } from "./types.js";
|
2 |
+
/**
|
3 |
+
* This function is used to resolve the URL for making requests when the app has a root path.
|
4 |
+
* The root path could be a path suffix like "/app" which is appended to the end of the base URL. Or
|
5 |
+
* it could be a full URL like "https://abidlabs-test-client-replica--gqf2x.hf.space" which is used when hosting
|
6 |
+
* Gradio apps on Hugging Face Spaces.
|
7 |
+
* @param {string} base_url The base URL at which the Gradio server is hosted
|
8 |
+
* @param {string} root_path The root path, which could be a path suffix (e.g. mounted in FastAPI app) or a full URL (e.g. hosted on Hugging Face Spaces)
|
9 |
+
* @param {boolean} prioritize_base Whether to prioritize the base URL over the root path. This is used when both the base path and root paths are full URLs. For example, for fetching files the root path should be prioritized, but for making requests, the base URL should be prioritized.
|
10 |
+
* @returns {string} the resolved URL
|
11 |
+
*/
|
12 |
+
export declare function resolve_root(base_url: string, root_path: string, prioritize_base: boolean): string;
|
13 |
+
export declare function determine_protocol(endpoint: string): {
|
14 |
+
ws_protocol: "ws" | "wss";
|
15 |
+
http_protocol: "http:" | "https:";
|
16 |
+
host: string;
|
17 |
+
};
|
18 |
+
export declare const RE_SPACE_NAME: RegExp;
|
19 |
+
export declare const RE_SPACE_DOMAIN: RegExp;
|
20 |
+
export declare function process_endpoint(app_reference: string, token?: `hf_${string}`): Promise<{
|
21 |
+
space_id: string | false;
|
22 |
+
host: string;
|
23 |
+
ws_protocol: "ws" | "wss";
|
24 |
+
http_protocol: "http:" | "https:";
|
25 |
+
}>;
|
26 |
+
export declare function map_names_to_ids(fns: Config["dependencies"]): Record<string, number>;
|
27 |
+
export declare function discussions_enabled(space_id: string): Promise<boolean>;
|
28 |
+
export declare function get_space_hardware(space_id: string, token: `hf_${string}`): Promise<(typeof hardware_types)[number]>;
|
29 |
+
export declare function set_space_hardware(space_id: string, new_hardware: (typeof hardware_types)[number], token: `hf_${string}`): Promise<(typeof hardware_types)[number]>;
|
30 |
+
export declare function set_space_timeout(space_id: string, timeout: number, token: `hf_${string}`): Promise<number>;
|
31 |
+
export declare const hardware_types: readonly ["cpu-basic", "cpu-upgrade", "t4-small", "t4-medium", "a10g-small", "a10g-large", "a100-large"];
|
32 |
+
//# sourceMappingURL=utils.d.ts.map
|
node_modules/@gradio/client/dist/utils.d.ts.map
ADDED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ChB,YAAY,EAAE,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,EAC7C,KAAK,EAAE,MAAM,MAAM,EAAE,GACnB,OAAO,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAuB1C;AAED,wBAAsB,iBAAiB,CACtC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,MAAM,EAAE,GACnB,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAED,eAAO,MAAM,cAAc,0GAQjB,CAAC"}
|
node_modules/@gradio/client/dist/wrapper-6f348d45.js
ADDED
The diff for this file is too large to render.
See raw diff
|
|
node_modules/@gradio/client/package.json
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@gradio/client",
|
3 |
+
"version": "0.10.1",
|
4 |
+
"description": "Gradio API client",
|
5 |
+
"type": "module",
|
6 |
+
"main": "dist/index.js",
|
7 |
+
"author": "",
|
8 |
+
"license": "ISC",
|
9 |
+
"exports": {
|
10 |
+
".": {
|
11 |
+
"import": "./dist/index.js"
|
12 |
+
},
|
13 |
+
"./package.json": "./package.json"
|
14 |
+
},
|
15 |
+
"dependencies": {
|
16 |
+
"bufferutil": "^4.0.7",
|
17 |
+
"semiver": "^1.1.0",
|
18 |
+
"ws": "^8.13.0"
|
19 |
+
},
|
20 |
+
"devDependencies": {
|
21 |
+
"@types/ws": "^8.5.4",
|
22 |
+
"esbuild": "^0.19.0"
|
23 |
+
},
|
24 |
+
"engines": {
|
25 |
+
"node": ">=18.0.0"
|
26 |
+
},
|
27 |
+
"main_changeset": true,
|
28 |
+
"scripts": {
|
29 |
+
"bundle": "vite build --ssr",
|
30 |
+
"generate_types": "tsc",
|
31 |
+
"build": "pnpm bundle && pnpm generate_types"
|
32 |
+
}
|
33 |
+
}
|
node_modules/@gradio/client/src/client.node-test.ts
ADDED
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { test, describe, assert } from "vitest";
|
2 |
+
import { readFileSync } from "fs";
|
3 |
+
import { join, dirname } from "path";
|
4 |
+
import { fileURLToPath } from "url";
|
5 |
+
import { Blob } from "node:buffer";
|
6 |
+
|
7 |
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
8 |
+
const image_path = join(
|
9 |
+
__dirname,
|
10 |
+
"..",
|
11 |
+
"..",
|
12 |
+
"..",
|
13 |
+
"demo",
|
14 |
+
"kitchen_sink",
|
15 |
+
"files",
|
16 |
+
"lion.jpg"
|
17 |
+
);
|
18 |
+
|
19 |
+
import { walk_and_store_blobs, client, handle_blob } from "./client";
|
20 |
+
|
21 |
+
describe.skip("extract blob parts", () => {
|
22 |
+
test("convert Buffer to Blob", async () => {
|
23 |
+
const image = readFileSync(image_path);
|
24 |
+
await client("gradio/hello_world_main");
|
25 |
+
const parts = walk_and_store_blobs({
|
26 |
+
data: {
|
27 |
+
image
|
28 |
+
}
|
29 |
+
});
|
30 |
+
|
31 |
+
assert.isTrue(parts[0].blob instanceof Blob);
|
32 |
+
});
|
33 |
+
|
34 |
+
test("leave node Blob as Blob", async () => {
|
35 |
+
const image = new Blob([readFileSync(image_path)]);
|
36 |
+
|
37 |
+
await client("gradio/hello_world_main");
|
38 |
+
const parts = walk_and_store_blobs({
|
39 |
+
data: {
|
40 |
+
image
|
41 |
+
}
|
42 |
+
});
|
43 |
+
|
44 |
+
assert.isTrue(parts[0].blob instanceof Blob);
|
45 |
+
});
|
46 |
+
|
47 |
+
test("handle deep structures", async () => {
|
48 |
+
const image = new Blob([readFileSync(image_path)]);
|
49 |
+
|
50 |
+
await client("gradio/hello_world_main");
|
51 |
+
const parts = walk_and_store_blobs({
|
52 |
+
a: {
|
53 |
+
b: {
|
54 |
+
data: {
|
55 |
+
image
|
56 |
+
}
|
57 |
+
}
|
58 |
+
}
|
59 |
+
});
|
60 |
+
|
61 |
+
assert.isTrue(parts[0].blob instanceof Blob);
|
62 |
+
});
|
63 |
+
|
64 |
+
test("handle deep structures with arrays", async () => {
|
65 |
+
const image = new Blob([readFileSync(image_path)]);
|
66 |
+
|
67 |
+
await client("gradio/hello_world_main");
|
68 |
+
const parts = walk_and_store_blobs({
|
69 |
+
a: [
|
70 |
+
{
|
71 |
+
b: [
|
72 |
+
{
|
73 |
+
data: [
|
74 |
+
{
|
75 |
+
image
|
76 |
+
}
|
77 |
+
]
|
78 |
+
}
|
79 |
+
]
|
80 |
+
}
|
81 |
+
]
|
82 |
+
});
|
83 |
+
|
84 |
+
assert.isTrue(parts[0].blob instanceof Blob);
|
85 |
+
});
|
86 |
+
|
87 |
+
test("handle deep structures with arrays 2", async () => {
|
88 |
+
const image = new Blob([readFileSync(image_path)]);
|
89 |
+
|
90 |
+
await client("gradio/hello_world_main");
|
91 |
+
const obj = {
|
92 |
+
a: [
|
93 |
+
{
|
94 |
+
b: [
|
95 |
+
{
|
96 |
+
data: [[image], image, [image, [image]]]
|
97 |
+
}
|
98 |
+
]
|
99 |
+
}
|
100 |
+
]
|
101 |
+
};
|
102 |
+
const parts = walk_and_store_blobs(obj);
|
103 |
+
|
104 |
+
function map_path(
|
105 |
+
obj: Record<string, any>,
|
106 |
+
parts: { path: string[]; blob: any }[]
|
107 |
+
) {
|
108 |
+
const { path, blob } = parts[parts.length - 1];
|
109 |
+
let ref = obj;
|
110 |
+
path.forEach((p) => (ref = ref[p]));
|
111 |
+
|
112 |
+
return ref === blob;
|
113 |
+
}
|
114 |
+
|
115 |
+
assert.isTrue(parts[0].blob instanceof Blob);
|
116 |
+
// assert.isTrue(map_path(obj, parts));
|
117 |
+
});
|
118 |
+
});
|
119 |
+
|
120 |
+
describe("handle_blob", () => {
|
121 |
+
test("handle blobs", async () => {
|
122 |
+
const image = new Blob([readFileSync(image_path)]);
|
123 |
+
|
124 |
+
const app = await client("gradio/hello_world_main");
|
125 |
+
const obj = [
|
126 |
+
{
|
127 |
+
a: [
|
128 |
+
{
|
129 |
+
b: [
|
130 |
+
{
|
131 |
+
data: [[image], image, [image, [image]]]
|
132 |
+
}
|
133 |
+
]
|
134 |
+
}
|
135 |
+
]
|
136 |
+
}
|
137 |
+
];
|
138 |
+
|
139 |
+
const parts = await handle_blob(app.config.root, obj, undefined);
|
140 |
+
//@ts-ignore
|
141 |
+
// assert.isString(parts.data[0].a[0].b[0].data[0][0]);
|
142 |
+
});
|
143 |
+
});
|
144 |
+
|
145 |
+
describe.skip("private space", () => {
|
146 |
+
test("can access a private space", async () => {
|
147 |
+
const image = new Blob([readFileSync(image_path)]);
|
148 |
+
|
149 |
+
const app = await client("pngwn/hello_world", {
|
150 |
+
hf_token: "hf_"
|
151 |
+
});
|
152 |
+
|
153 |
+
console.log(app);
|
154 |
+
const obj = [
|
155 |
+
{
|
156 |
+
a: [
|
157 |
+
{
|
158 |
+
b: [
|
159 |
+
{
|
160 |
+
data: [[image], image, [image, [image]]]
|
161 |
+
}
|
162 |
+
]
|
163 |
+
}
|
164 |
+
]
|
165 |
+
}
|
166 |
+
];
|
167 |
+
|
168 |
+
const parts = await handle_blob(app.config.root, obj, "hf_");
|
169 |
+
//@ts-ignore
|
170 |
+
assert.isString(parts.data[0].a[0].b[0].data[0][0]);
|
171 |
+
});
|
172 |
+
});
|
node_modules/@gradio/client/src/client.ts
ADDED
@@ -0,0 +1,1727 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
//@ts-nocheck
|
2 |
+
|
3 |
+
import semiver from "semiver";
|
4 |
+
|
5 |
+
import {
|
6 |
+
process_endpoint,
|
7 |
+
RE_SPACE_NAME,
|
8 |
+
map_names_to_ids,
|
9 |
+
discussions_enabled,
|
10 |
+
get_space_hardware,
|
11 |
+
set_space_hardware,
|
12 |
+
set_space_timeout,
|
13 |
+
hardware_types,
|
14 |
+
resolve_root
|
15 |
+
} from "./utils.js";
|
16 |
+
|
17 |
+
import type {
|
18 |
+
EventType,
|
19 |
+
EventListener,
|
20 |
+
ListenerMap,
|
21 |
+
Event,
|
22 |
+
Payload,
|
23 |
+
PostResponse,
|
24 |
+
UploadResponse,
|
25 |
+
Status,
|
26 |
+
SpaceStatus,
|
27 |
+
SpaceStatusCallback
|
28 |
+
} from "./types.js";
|
29 |
+
|
30 |
+
import { FileData, normalise_file } from "./upload";
|
31 |
+
|
32 |
+
import type { Config } from "./types.js";
|
33 |
+
|
34 |
+
type event = <K extends EventType>(
|
35 |
+
eventType: K,
|
36 |
+
listener: EventListener<K>
|
37 |
+
) => SubmitReturn;
|
38 |
+
type predict = (
|
39 |
+
endpoint: string | number,
|
40 |
+
data?: unknown[],
|
41 |
+
event_data?: unknown
|
42 |
+
) => Promise<unknown>;
|
43 |
+
|
44 |
+
type client_return = {
|
45 |
+
predict: predict;
|
46 |
+
config: Config;
|
47 |
+
submit: (
|
48 |
+
endpoint: string | number,
|
49 |
+
data?: unknown[],
|
50 |
+
event_data?: unknown,
|
51 |
+
trigger_id?: number | null
|
52 |
+
) => SubmitReturn;
|
53 |
+
component_server: (
|
54 |
+
component_id: number,
|
55 |
+
fn_name: string,
|
56 |
+
data: unknown[]
|
57 |
+
) => any;
|
58 |
+
view_api: (c?: Config) => Promise<ApiInfo<JsApiData>>;
|
59 |
+
};
|
60 |
+
|
61 |
+
type SubmitReturn = {
|
62 |
+
on: event;
|
63 |
+
off: event;
|
64 |
+
cancel: () => Promise<void>;
|
65 |
+
destroy: () => void;
|
66 |
+
};
|
67 |
+
|
68 |
+
const QUEUE_FULL_MSG = "This application is too busy. Keep trying!";
|
69 |
+
const BROKEN_CONNECTION_MSG = "Connection errored out.";
|
70 |
+
|
71 |
+
export let NodeBlob;
|
72 |
+
|
73 |
+
export async function duplicate(
|
74 |
+
app_reference: string,
|
75 |
+
options: {
|
76 |
+
hf_token: `hf_${string}`;
|
77 |
+
private?: boolean;
|
78 |
+
status_callback: SpaceStatusCallback;
|
79 |
+
hardware?: (typeof hardware_types)[number];
|
80 |
+
timeout?: number;
|
81 |
+
}
|
82 |
+
): Promise<client_return> {
|
83 |
+
const { hf_token, private: _private, hardware, timeout } = options;
|
84 |
+
|
85 |
+
if (hardware && !hardware_types.includes(hardware)) {
|
86 |
+
throw new Error(
|
87 |
+
`Invalid hardware type provided. Valid types are: ${hardware_types
|
88 |
+
.map((v) => `"${v}"`)
|
89 |
+
.join(",")}.`
|
90 |
+
);
|
91 |
+
}
|
92 |
+
const headers = {
|
93 |
+
Authorization: `Bearer ${hf_token}`
|
94 |
+
};
|
95 |
+
|
96 |
+
const user = (
|
97 |
+
await (
|
98 |
+
await fetch(`https://huggingface.co/api/whoami-v2`, {
|
99 |
+
headers
|
100 |
+
})
|
101 |
+
).json()
|
102 |
+
).name;
|
103 |
+
|
104 |
+
const space_name = app_reference.split("/")[1];
|
105 |
+
const body: {
|
106 |
+
repository: string;
|
107 |
+
private?: boolean;
|
108 |
+
} = {
|
109 |
+
repository: `${user}/${space_name}`
|
110 |
+
};
|
111 |
+
|
112 |
+
if (_private) {
|
113 |
+
body.private = true;
|
114 |
+
}
|
115 |
+
|
116 |
+
try {
|
117 |
+
const response = await fetch(
|
118 |
+
`https://huggingface.co/api/spaces/${app_reference}/duplicate`,
|
119 |
+
{
|
120 |
+
method: "POST",
|
121 |
+
headers: { "Content-Type": "application/json", ...headers },
|
122 |
+
body: JSON.stringify(body)
|
123 |
+
}
|
124 |
+
);
|
125 |
+
|
126 |
+
if (response.status === 409) {
|
127 |
+
return client(`${user}/${space_name}`, options);
|
128 |
+
}
|
129 |
+
const duplicated_space = await response.json();
|
130 |
+
|
131 |
+
let original_hardware;
|
132 |
+
|
133 |
+
if (!hardware) {
|
134 |
+
original_hardware = await get_space_hardware(app_reference, hf_token);
|
135 |
+
}
|
136 |
+
|
137 |
+
const requested_hardware = hardware || original_hardware || "cpu-basic";
|
138 |
+
await set_space_hardware(
|
139 |
+
`${user}/${space_name}`,
|
140 |
+
requested_hardware,
|
141 |
+
hf_token
|
142 |
+
);
|
143 |
+
|
144 |
+
await set_space_timeout(`${user}/${space_name}`, timeout || 300, hf_token);
|
145 |
+
return client(duplicated_space.url, options);
|
146 |
+
} catch (e: any) {
|
147 |
+
throw new Error(e);
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
interface Client {
|
152 |
+
post_data: (
|
153 |
+
url: string,
|
154 |
+
body: unknown,
|
155 |
+
token?: `hf_${string}`
|
156 |
+
) => Promise<[PostResponse, number]>;
|
157 |
+
upload_files: (
|
158 |
+
root: string,
|
159 |
+
files: File[],
|
160 |
+
token?: `hf_${string}`,
|
161 |
+
upload_id?: string
|
162 |
+
) => Promise<UploadResponse>;
|
163 |
+
client: (
|
164 |
+
app_reference: string,
|
165 |
+
options: {
|
166 |
+
hf_token?: `hf_${string}`;
|
167 |
+
status_callback?: SpaceStatusCallback;
|
168 |
+
normalise_files?: boolean;
|
169 |
+
}
|
170 |
+
) => Promise<client_return>;
|
171 |
+
handle_blob: (
|
172 |
+
endpoint: string,
|
173 |
+
data: unknown[],
|
174 |
+
api_info: ApiInfo<JsApiData>,
|
175 |
+
token?: `hf_${string}`
|
176 |
+
) => Promise<unknown[]>;
|
177 |
+
}
|
178 |
+
|
179 |
+
export function api_factory(
|
180 |
+
fetch_implementation: typeof fetch,
|
181 |
+
EventSource_factory: (url: URL) => EventSource
|
182 |
+
): Client {
|
183 |
+
return { post_data, upload_files, client, handle_blob };
|
184 |
+
|
185 |
+
async function post_data(
|
186 |
+
url: string,
|
187 |
+
body: unknown,
|
188 |
+
token?: `hf_${string}`
|
189 |
+
): Promise<[PostResponse, number]> {
|
190 |
+
const headers: {
|
191 |
+
Authorization?: string;
|
192 |
+
"Content-Type": "application/json";
|
193 |
+
} = { "Content-Type": "application/json" };
|
194 |
+
if (token) {
|
195 |
+
headers.Authorization = `Bearer ${token}`;
|
196 |
+
}
|
197 |
+
try {
|
198 |
+
var response = await fetch_implementation(url, {
|
199 |
+
method: "POST",
|
200 |
+
body: JSON.stringify(body),
|
201 |
+
headers
|
202 |
+
});
|
203 |
+
} catch (e) {
|
204 |
+
return [{ error: BROKEN_CONNECTION_MSG }, 500];
|
205 |
+
}
|
206 |
+
let output: PostResponse;
|
207 |
+
let status: int;
|
208 |
+
try {
|
209 |
+
output = await response.json();
|
210 |
+
status = response.status;
|
211 |
+
} catch (e) {
|
212 |
+
output = { error: `Could not parse server response: ${e}` };
|
213 |
+
status = 500;
|
214 |
+
}
|
215 |
+
return [output, status];
|
216 |
+
}
|
217 |
+
|
218 |
+
async function upload_files(
|
219 |
+
root: string,
|
220 |
+
files: (Blob | File)[],
|
221 |
+
token?: `hf_${string}`,
|
222 |
+
upload_id?: string
|
223 |
+
): Promise<UploadResponse> {
|
224 |
+
const headers: {
|
225 |
+
Authorization?: string;
|
226 |
+
} = {};
|
227 |
+
if (token) {
|
228 |
+
headers.Authorization = `Bearer ${token}`;
|
229 |
+
}
|
230 |
+
const chunkSize = 1000;
|
231 |
+
const uploadResponses = [];
|
232 |
+
for (let i = 0; i < files.length; i += chunkSize) {
|
233 |
+
const chunk = files.slice(i, i + chunkSize);
|
234 |
+
const formData = new FormData();
|
235 |
+
chunk.forEach((file) => {
|
236 |
+
formData.append("files", file);
|
237 |
+
});
|
238 |
+
try {
|
239 |
+
const upload_url = upload_id
|
240 |
+
? `${root}/upload?upload_id=${upload_id}`
|
241 |
+
: `${root}/upload`;
|
242 |
+
var response = await fetch_implementation(upload_url, {
|
243 |
+
method: "POST",
|
244 |
+
body: formData,
|
245 |
+
headers
|
246 |
+
});
|
247 |
+
} catch (e) {
|
248 |
+
return { error: BROKEN_CONNECTION_MSG };
|
249 |
+
}
|
250 |
+
const output: UploadResponse["files"] = await response.json();
|
251 |
+
uploadResponses.push(...output);
|
252 |
+
}
|
253 |
+
return { files: uploadResponses };
|
254 |
+
}
|
255 |
+
|
256 |
+
async function client(
|
257 |
+
app_reference: string,
|
258 |
+
options: {
|
259 |
+
hf_token?: `hf_${string}`;
|
260 |
+
status_callback?: SpaceStatusCallback;
|
261 |
+
normalise_files?: boolean;
|
262 |
+
} = { normalise_files: true }
|
263 |
+
): Promise<client_return> {
|
264 |
+
return new Promise(async (res) => {
|
265 |
+
const { status_callback, hf_token, normalise_files } = options;
|
266 |
+
const return_obj = {
|
267 |
+
predict,
|
268 |
+
submit,
|
269 |
+
view_api,
|
270 |
+
component_server
|
271 |
+
};
|
272 |
+
|
273 |
+
const transform_files = normalise_files ?? true;
|
274 |
+
if (
|
275 |
+
(typeof window === "undefined" || !("WebSocket" in window)) &&
|
276 |
+
!global.Websocket
|
277 |
+
) {
|
278 |
+
const ws = await import("ws");
|
279 |
+
NodeBlob = (await import("node:buffer")).Blob;
|
280 |
+
//@ts-ignore
|
281 |
+
global.WebSocket = ws.WebSocket;
|
282 |
+
}
|
283 |
+
|
284 |
+
const { ws_protocol, http_protocol, host, space_id } =
|
285 |
+
await process_endpoint(app_reference, hf_token);
|
286 |
+
|
287 |
+
const session_hash = Math.random().toString(36).substring(2);
|
288 |
+
const last_status: Record<string, Status["stage"]> = {};
|
289 |
+
let stream_open = false;
|
290 |
+
let pending_stream_messages: Record<string, any[]> = {}; // Event messages may be received by the SSE stream before the initial data POST request is complete. To resolve this race condition, we store the messages in a dictionary and process them when the POST request is complete.
|
291 |
+
let event_stream: EventSource | null = null;
|
292 |
+
const event_callbacks: Record<string, () => Promise<void>> = {};
|
293 |
+
const unclosed_events: Set<string> = new Set();
|
294 |
+
let config: Config;
|
295 |
+
let api_map: Record<string, number> = {};
|
296 |
+
|
297 |
+
let jwt: false | string = false;
|
298 |
+
|
299 |
+
if (hf_token && space_id) {
|
300 |
+
jwt = await get_jwt(space_id, hf_token);
|
301 |
+
}
|
302 |
+
|
303 |
+
async function config_success(_config: Config): Promise<client_return> {
|
304 |
+
config = _config;
|
305 |
+
api_map = map_names_to_ids(_config?.dependencies || []);
|
306 |
+
if (config.auth_required) {
|
307 |
+
return {
|
308 |
+
config,
|
309 |
+
...return_obj
|
310 |
+
};
|
311 |
+
}
|
312 |
+
try {
|
313 |
+
api = await view_api(config);
|
314 |
+
} catch (e) {
|
315 |
+
console.error(`Could not get api details: ${e.message}`);
|
316 |
+
}
|
317 |
+
|
318 |
+
return {
|
319 |
+
config,
|
320 |
+
...return_obj
|
321 |
+
};
|
322 |
+
}
|
323 |
+
let api: ApiInfo<JsApiData>;
|
324 |
+
async function handle_space_sucess(status: SpaceStatus): Promise<void> {
|
325 |
+
if (status_callback) status_callback(status);
|
326 |
+
if (status.status === "running")
|
327 |
+
try {
|
328 |
+
config = await resolve_config(
|
329 |
+
fetch_implementation,
|
330 |
+
`${http_protocol}//${host}`,
|
331 |
+
hf_token
|
332 |
+
);
|
333 |
+
|
334 |
+
const _config = await config_success(config);
|
335 |
+
res(_config);
|
336 |
+
} catch (e) {
|
337 |
+
console.error(e);
|
338 |
+
if (status_callback) {
|
339 |
+
status_callback({
|
340 |
+
status: "error",
|
341 |
+
message: "Could not load this space.",
|
342 |
+
load_status: "error",
|
343 |
+
detail: "NOT_FOUND"
|
344 |
+
});
|
345 |
+
}
|
346 |
+
}
|
347 |
+
}
|
348 |
+
|
349 |
+
try {
|
350 |
+
config = await resolve_config(
|
351 |
+
fetch_implementation,
|
352 |
+
`${http_protocol}//${host}`,
|
353 |
+
hf_token
|
354 |
+
);
|
355 |
+
|
356 |
+
const _config = await config_success(config);
|
357 |
+
res(_config);
|
358 |
+
} catch (e) {
|
359 |
+
console.error(e);
|
360 |
+
if (space_id) {
|
361 |
+
check_space_status(
|
362 |
+
space_id,
|
363 |
+
RE_SPACE_NAME.test(space_id) ? "space_name" : "subdomain",
|
364 |
+
handle_space_sucess
|
365 |
+
);
|
366 |
+
} else {
|
367 |
+
if (status_callback)
|
368 |
+
status_callback({
|
369 |
+
status: "error",
|
370 |
+
message: "Could not load this space.",
|
371 |
+
load_status: "error",
|
372 |
+
detail: "NOT_FOUND"
|
373 |
+
});
|
374 |
+
}
|
375 |
+
}
|
376 |
+
|
377 |
+
function predict(
|
378 |
+
endpoint: string,
|
379 |
+
data: unknown[],
|
380 |
+
event_data?: unknown
|
381 |
+
): Promise<unknown> {
|
382 |
+
let data_returned = false;
|
383 |
+
let status_complete = false;
|
384 |
+
let dependency;
|
385 |
+
if (typeof endpoint === "number") {
|
386 |
+
dependency = config.dependencies[endpoint];
|
387 |
+
} else {
|
388 |
+
const trimmed_endpoint = endpoint.replace(/^\//, "");
|
389 |
+
dependency = config.dependencies[api_map[trimmed_endpoint]];
|
390 |
+
}
|
391 |
+
|
392 |
+
if (dependency.types.continuous) {
|
393 |
+
throw new Error(
|
394 |
+
"Cannot call predict on this function as it may run forever. Use submit instead"
|
395 |
+
);
|
396 |
+
}
|
397 |
+
|
398 |
+
return new Promise((res, rej) => {
|
399 |
+
const app = submit(endpoint, data, event_data);
|
400 |
+
let result;
|
401 |
+
|
402 |
+
app
|
403 |
+
.on("data", (d) => {
|
404 |
+
// if complete message comes before data, resolve here
|
405 |
+
if (status_complete) {
|
406 |
+
app.destroy();
|
407 |
+
res(d);
|
408 |
+
}
|
409 |
+
data_returned = true;
|
410 |
+
result = d;
|
411 |
+
})
|
412 |
+
.on("status", (status) => {
|
413 |
+
if (status.stage === "error") rej(status);
|
414 |
+
if (status.stage === "complete") {
|
415 |
+
status_complete = true;
|
416 |
+
// if complete message comes after data, resolve here
|
417 |
+
if (data_returned) {
|
418 |
+
app.destroy();
|
419 |
+
res(result);
|
420 |
+
}
|
421 |
+
}
|
422 |
+
});
|
423 |
+
});
|
424 |
+
}
|
425 |
+
|
426 |
+
function submit(
|
427 |
+
endpoint: string | number,
|
428 |
+
data: unknown[],
|
429 |
+
event_data?: unknown,
|
430 |
+
trigger_id: number | null = null
|
431 |
+
): SubmitReturn {
|
432 |
+
let fn_index: number;
|
433 |
+
let api_info;
|
434 |
+
|
435 |
+
if (typeof endpoint === "number") {
|
436 |
+
fn_index = endpoint;
|
437 |
+
api_info = api.unnamed_endpoints[fn_index];
|
438 |
+
} else {
|
439 |
+
const trimmed_endpoint = endpoint.replace(/^\//, "");
|
440 |
+
|
441 |
+
fn_index = api_map[trimmed_endpoint];
|
442 |
+
api_info = api.named_endpoints[endpoint.trim()];
|
443 |
+
}
|
444 |
+
|
445 |
+
if (typeof fn_index !== "number") {
|
446 |
+
throw new Error(
|
447 |
+
"There is no endpoint matching that name of fn_index matching that number."
|
448 |
+
);
|
449 |
+
}
|
450 |
+
|
451 |
+
let websocket: WebSocket;
|
452 |
+
let eventSource: EventSource;
|
453 |
+
let protocol = config.protocol ?? "ws";
|
454 |
+
|
455 |
+
const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint;
|
456 |
+
let payload: Payload;
|
457 |
+
let event_id: string | null = null;
|
458 |
+
let complete: false | Record<string, any> = false;
|
459 |
+
const listener_map: ListenerMap<EventType> = {};
|
460 |
+
let url_params = "";
|
461 |
+
if (typeof window !== "undefined") {
|
462 |
+
url_params = new URLSearchParams(window.location.search).toString();
|
463 |
+
}
|
464 |
+
|
465 |
+
handle_blob(`${config.root}`, data, api_info, hf_token).then(
|
466 |
+
(_payload) => {
|
467 |
+
payload = {
|
468 |
+
data: _payload || [],
|
469 |
+
event_data,
|
470 |
+
fn_index,
|
471 |
+
trigger_id
|
472 |
+
};
|
473 |
+
if (skip_queue(fn_index, config)) {
|
474 |
+
fire_event({
|
475 |
+
type: "status",
|
476 |
+
endpoint: _endpoint,
|
477 |
+
stage: "pending",
|
478 |
+
queue: false,
|
479 |
+
fn_index,
|
480 |
+
time: new Date()
|
481 |
+
});
|
482 |
+
|
483 |
+
post_data(
|
484 |
+
`${config.root}/run${
|
485 |
+
_endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`
|
486 |
+
}${url_params ? "?" + url_params : ""}`,
|
487 |
+
{
|
488 |
+
...payload,
|
489 |
+
session_hash
|
490 |
+
},
|
491 |
+
hf_token
|
492 |
+
)
|
493 |
+
.then(([output, status_code]) => {
|
494 |
+
const data = transform_files
|
495 |
+
? transform_output(
|
496 |
+
output.data,
|
497 |
+
api_info,
|
498 |
+
config.root,
|
499 |
+
config.root_url
|
500 |
+
)
|
501 |
+
: output.data;
|
502 |
+
if (status_code == 200) {
|
503 |
+
fire_event({
|
504 |
+
type: "data",
|
505 |
+
endpoint: _endpoint,
|
506 |
+
fn_index,
|
507 |
+
data: data,
|
508 |
+
time: new Date()
|
509 |
+
});
|
510 |
+
|
511 |
+
fire_event({
|
512 |
+
type: "status",
|
513 |
+
endpoint: _endpoint,
|
514 |
+
fn_index,
|
515 |
+
stage: "complete",
|
516 |
+
eta: output.average_duration,
|
517 |
+
queue: false,
|
518 |
+
time: new Date()
|
519 |
+
});
|
520 |
+
} else {
|
521 |
+
fire_event({
|
522 |
+
type: "status",
|
523 |
+
stage: "error",
|
524 |
+
endpoint: _endpoint,
|
525 |
+
fn_index,
|
526 |
+
message: output.error,
|
527 |
+
queue: false,
|
528 |
+
time: new Date()
|
529 |
+
});
|
530 |
+
}
|
531 |
+
})
|
532 |
+
.catch((e) => {
|
533 |
+
fire_event({
|
534 |
+
type: "status",
|
535 |
+
stage: "error",
|
536 |
+
message: e.message,
|
537 |
+
endpoint: _endpoint,
|
538 |
+
fn_index,
|
539 |
+
queue: false,
|
540 |
+
time: new Date()
|
541 |
+
});
|
542 |
+
});
|
543 |
+
} else if (protocol == "ws") {
|
544 |
+
fire_event({
|
545 |
+
type: "status",
|
546 |
+
stage: "pending",
|
547 |
+
queue: true,
|
548 |
+
endpoint: _endpoint,
|
549 |
+
fn_index,
|
550 |
+
time: new Date()
|
551 |
+
});
|
552 |
+
let url = new URL(`${ws_protocol}://${resolve_root(
|
553 |
+
host,
|
554 |
+
config.path,
|
555 |
+
true
|
556 |
+
)}
|
557 |
+
/queue/join${url_params ? "?" + url_params : ""}`);
|
558 |
+
|
559 |
+
if (jwt) {
|
560 |
+
url.searchParams.set("__sign", jwt);
|
561 |
+
}
|
562 |
+
|
563 |
+
websocket = new WebSocket(url);
|
564 |
+
|
565 |
+
websocket.onclose = (evt) => {
|
566 |
+
if (!evt.wasClean) {
|
567 |
+
fire_event({
|
568 |
+
type: "status",
|
569 |
+
stage: "error",
|
570 |
+
broken: true,
|
571 |
+
message: BROKEN_CONNECTION_MSG,
|
572 |
+
queue: true,
|
573 |
+
endpoint: _endpoint,
|
574 |
+
fn_index,
|
575 |
+
time: new Date()
|
576 |
+
});
|
577 |
+
}
|
578 |
+
};
|
579 |
+
|
580 |
+
websocket.onmessage = function (event) {
|
581 |
+
const _data = JSON.parse(event.data);
|
582 |
+
const { type, status, data } = handle_message(
|
583 |
+
_data,
|
584 |
+
last_status[fn_index]
|
585 |
+
);
|
586 |
+
|
587 |
+
if (type === "update" && status && !complete) {
|
588 |
+
// call 'status' listeners
|
589 |
+
fire_event({
|
590 |
+
type: "status",
|
591 |
+
endpoint: _endpoint,
|
592 |
+
fn_index,
|
593 |
+
time: new Date(),
|
594 |
+
...status
|
595 |
+
});
|
596 |
+
if (status.stage === "error") {
|
597 |
+
websocket.close();
|
598 |
+
}
|
599 |
+
} else if (type === "hash") {
|
600 |
+
websocket.send(JSON.stringify({ fn_index, session_hash }));
|
601 |
+
return;
|
602 |
+
} else if (type === "data") {
|
603 |
+
websocket.send(JSON.stringify({ ...payload, session_hash }));
|
604 |
+
} else if (type === "complete") {
|
605 |
+
complete = status;
|
606 |
+
} else if (type === "log") {
|
607 |
+
fire_event({
|
608 |
+
type: "log",
|
609 |
+
log: data.log,
|
610 |
+
level: data.level,
|
611 |
+
endpoint: _endpoint,
|
612 |
+
fn_index
|
613 |
+
});
|
614 |
+
} else if (type === "generating") {
|
615 |
+
fire_event({
|
616 |
+
type: "status",
|
617 |
+
time: new Date(),
|
618 |
+
...status,
|
619 |
+
stage: status?.stage!,
|
620 |
+
queue: true,
|
621 |
+
endpoint: _endpoint,
|
622 |
+
fn_index
|
623 |
+
});
|
624 |
+
}
|
625 |
+
if (data) {
|
626 |
+
fire_event({
|
627 |
+
type: "data",
|
628 |
+
time: new Date(),
|
629 |
+
data: transform_files
|
630 |
+
? transform_output(
|
631 |
+
data.data,
|
632 |
+
api_info,
|
633 |
+
config.root,
|
634 |
+
config.root_url
|
635 |
+
)
|
636 |
+
: data.data,
|
637 |
+
endpoint: _endpoint,
|
638 |
+
fn_index
|
639 |
+
});
|
640 |
+
|
641 |
+
if (complete) {
|
642 |
+
fire_event({
|
643 |
+
type: "status",
|
644 |
+
time: new Date(),
|
645 |
+
...complete,
|
646 |
+
stage: status?.stage!,
|
647 |
+
queue: true,
|
648 |
+
endpoint: _endpoint,
|
649 |
+
fn_index
|
650 |
+
});
|
651 |
+
websocket.close();
|
652 |
+
}
|
653 |
+
}
|
654 |
+
};
|
655 |
+
|
656 |
+
// different ws contract for gradio versions older than 3.6.0
|
657 |
+
//@ts-ignore
|
658 |
+
if (semiver(config.version || "2.0.0", "3.6") < 0) {
|
659 |
+
addEventListener("open", () =>
|
660 |
+
websocket.send(JSON.stringify({ hash: session_hash }))
|
661 |
+
);
|
662 |
+
}
|
663 |
+
} else if (protocol == "sse") {
|
664 |
+
fire_event({
|
665 |
+
type: "status",
|
666 |
+
stage: "pending",
|
667 |
+
queue: true,
|
668 |
+
endpoint: _endpoint,
|
669 |
+
fn_index,
|
670 |
+
time: new Date()
|
671 |
+
});
|
672 |
+
var params = new URLSearchParams({
|
673 |
+
fn_index: fn_index.toString(),
|
674 |
+
session_hash: session_hash
|
675 |
+
}).toString();
|
676 |
+
let url = new URL(
|
677 |
+
`${config.root}/queue/join?${
|
678 |
+
url_params ? url_params + "&" : ""
|
679 |
+
}${params}`
|
680 |
+
);
|
681 |
+
|
682 |
+
eventSource = EventSource_factory(url);
|
683 |
+
|
684 |
+
eventSource.onmessage = async function (event) {
|
685 |
+
const _data = JSON.parse(event.data);
|
686 |
+
const { type, status, data } = handle_message(
|
687 |
+
_data,
|
688 |
+
last_status[fn_index]
|
689 |
+
);
|
690 |
+
|
691 |
+
if (type === "update" && status && !complete) {
|
692 |
+
// call 'status' listeners
|
693 |
+
fire_event({
|
694 |
+
type: "status",
|
695 |
+
endpoint: _endpoint,
|
696 |
+
fn_index,
|
697 |
+
time: new Date(),
|
698 |
+
...status
|
699 |
+
});
|
700 |
+
if (status.stage === "error") {
|
701 |
+
eventSource.close();
|
702 |
+
}
|
703 |
+
} else if (type === "data") {
|
704 |
+
event_id = _data.event_id as string;
|
705 |
+
let [_, status] = await post_data(
|
706 |
+
`${config.root}/queue/data`,
|
707 |
+
{
|
708 |
+
...payload,
|
709 |
+
session_hash,
|
710 |
+
event_id
|
711 |
+
},
|
712 |
+
hf_token
|
713 |
+
);
|
714 |
+
if (status !== 200) {
|
715 |
+
fire_event({
|
716 |
+
type: "status",
|
717 |
+
stage: "error",
|
718 |
+
message: BROKEN_CONNECTION_MSG,
|
719 |
+
queue: true,
|
720 |
+
endpoint: _endpoint,
|
721 |
+
fn_index,
|
722 |
+
time: new Date()
|
723 |
+
});
|
724 |
+
eventSource.close();
|
725 |
+
}
|
726 |
+
} else if (type === "complete") {
|
727 |
+
complete = status;
|
728 |
+
} else if (type === "log") {
|
729 |
+
fire_event({
|
730 |
+
type: "log",
|
731 |
+
log: data.log,
|
732 |
+
level: data.level,
|
733 |
+
endpoint: _endpoint,
|
734 |
+
fn_index
|
735 |
+
});
|
736 |
+
} else if (type === "generating") {
|
737 |
+
fire_event({
|
738 |
+
type: "status",
|
739 |
+
time: new Date(),
|
740 |
+
...status,
|
741 |
+
stage: status?.stage!,
|
742 |
+
queue: true,
|
743 |
+
endpoint: _endpoint,
|
744 |
+
fn_index
|
745 |
+
});
|
746 |
+
}
|
747 |
+
if (data) {
|
748 |
+
fire_event({
|
749 |
+
type: "data",
|
750 |
+
time: new Date(),
|
751 |
+
data: transform_files
|
752 |
+
? transform_output(
|
753 |
+
data.data,
|
754 |
+
api_info,
|
755 |
+
config.root,
|
756 |
+
config.root_url
|
757 |
+
)
|
758 |
+
: data.data,
|
759 |
+
endpoint: _endpoint,
|
760 |
+
fn_index
|
761 |
+
});
|
762 |
+
|
763 |
+
if (complete) {
|
764 |
+
fire_event({
|
765 |
+
type: "status",
|
766 |
+
time: new Date(),
|
767 |
+
...complete,
|
768 |
+
stage: status?.stage!,
|
769 |
+
queue: true,
|
770 |
+
endpoint: _endpoint,
|
771 |
+
fn_index
|
772 |
+
});
|
773 |
+
eventSource.close();
|
774 |
+
}
|
775 |
+
}
|
776 |
+
};
|
777 |
+
} else if (protocol == "sse_v1") {
|
778 |
+
fire_event({
|
779 |
+
type: "status",
|
780 |
+
stage: "pending",
|
781 |
+
queue: true,
|
782 |
+
endpoint: _endpoint,
|
783 |
+
fn_index,
|
784 |
+
time: new Date()
|
785 |
+
});
|
786 |
+
|
787 |
+
post_data(
|
788 |
+
`${config.root}/queue/join?${url_params}`,
|
789 |
+
{
|
790 |
+
...payload,
|
791 |
+
session_hash
|
792 |
+
},
|
793 |
+
hf_token
|
794 |
+
).then(([response, status]) => {
|
795 |
+
if (status === 503) {
|
796 |
+
fire_event({
|
797 |
+
type: "status",
|
798 |
+
stage: "error",
|
799 |
+
message: QUEUE_FULL_MSG,
|
800 |
+
queue: true,
|
801 |
+
endpoint: _endpoint,
|
802 |
+
fn_index,
|
803 |
+
time: new Date()
|
804 |
+
});
|
805 |
+
} else if (status !== 200) {
|
806 |
+
fire_event({
|
807 |
+
type: "status",
|
808 |
+
stage: "error",
|
809 |
+
message: BROKEN_CONNECTION_MSG,
|
810 |
+
queue: true,
|
811 |
+
endpoint: _endpoint,
|
812 |
+
fn_index,
|
813 |
+
time: new Date()
|
814 |
+
});
|
815 |
+
} else {
|
816 |
+
event_id = response.event_id as string;
|
817 |
+
let callback = async function (_data: object): void {
|
818 |
+
try {
|
819 |
+
const { type, status, data } = handle_message(
|
820 |
+
_data,
|
821 |
+
last_status[fn_index]
|
822 |
+
);
|
823 |
+
|
824 |
+
if (type == "heartbeat") {
|
825 |
+
return;
|
826 |
+
}
|
827 |
+
|
828 |
+
if (type === "update" && status && !complete) {
|
829 |
+
// call 'status' listeners
|
830 |
+
fire_event({
|
831 |
+
type: "status",
|
832 |
+
endpoint: _endpoint,
|
833 |
+
fn_index,
|
834 |
+
time: new Date(),
|
835 |
+
...status
|
836 |
+
});
|
837 |
+
} else if (type === "complete") {
|
838 |
+
complete = status;
|
839 |
+
} else if (type == "unexpected_error") {
|
840 |
+
console.error("Unexpected error", status?.message);
|
841 |
+
fire_event({
|
842 |
+
type: "status",
|
843 |
+
stage: "error",
|
844 |
+
message:
|
845 |
+
status?.message || "An Unexpected Error Occurred!",
|
846 |
+
queue: true,
|
847 |
+
endpoint: _endpoint,
|
848 |
+
fn_index,
|
849 |
+
time: new Date()
|
850 |
+
});
|
851 |
+
} else if (type === "log") {
|
852 |
+
fire_event({
|
853 |
+
type: "log",
|
854 |
+
log: data.log,
|
855 |
+
level: data.level,
|
856 |
+
endpoint: _endpoint,
|
857 |
+
fn_index
|
858 |
+
});
|
859 |
+
return;
|
860 |
+
} else if (type === "generating") {
|
861 |
+
fire_event({
|
862 |
+
type: "status",
|
863 |
+
time: new Date(),
|
864 |
+
...status,
|
865 |
+
stage: status?.stage!,
|
866 |
+
queue: true,
|
867 |
+
endpoint: _endpoint,
|
868 |
+
fn_index
|
869 |
+
});
|
870 |
+
}
|
871 |
+
if (data) {
|
872 |
+
fire_event({
|
873 |
+
type: "data",
|
874 |
+
time: new Date(),
|
875 |
+
data: transform_files
|
876 |
+
? transform_output(
|
877 |
+
data.data,
|
878 |
+
api_info,
|
879 |
+
config.root,
|
880 |
+
config.root_url
|
881 |
+
)
|
882 |
+
: data.data,
|
883 |
+
endpoint: _endpoint,
|
884 |
+
fn_index
|
885 |
+
});
|
886 |
+
|
887 |
+
if (complete) {
|
888 |
+
fire_event({
|
889 |
+
type: "status",
|
890 |
+
time: new Date(),
|
891 |
+
...complete,
|
892 |
+
stage: status?.stage!,
|
893 |
+
queue: true,
|
894 |
+
endpoint: _endpoint,
|
895 |
+
fn_index
|
896 |
+
});
|
897 |
+
}
|
898 |
+
}
|
899 |
+
|
900 |
+
if (
|
901 |
+
status?.stage === "complete" ||
|
902 |
+
status?.stage === "error"
|
903 |
+
) {
|
904 |
+
if (event_callbacks[event_id]) {
|
905 |
+
delete event_callbacks[event_id];
|
906 |
+
}
|
907 |
+
}
|
908 |
+
} catch (e) {
|
909 |
+
console.error("Unexpected client exception", e);
|
910 |
+
fire_event({
|
911 |
+
type: "status",
|
912 |
+
stage: "error",
|
913 |
+
message: "An Unexpected Error Occurred!",
|
914 |
+
queue: true,
|
915 |
+
endpoint: _endpoint,
|
916 |
+
fn_index,
|
917 |
+
time: new Date()
|
918 |
+
});
|
919 |
+
close_stream();
|
920 |
+
}
|
921 |
+
};
|
922 |
+
if (event_id in pending_stream_messages) {
|
923 |
+
pending_stream_messages[event_id].forEach((msg) =>
|
924 |
+
callback(msg)
|
925 |
+
);
|
926 |
+
delete pending_stream_messages[event_id];
|
927 |
+
}
|
928 |
+
event_callbacks[event_id] = callback;
|
929 |
+
unclosed_events.add(event_id);
|
930 |
+
if (!stream_open) {
|
931 |
+
open_stream();
|
932 |
+
}
|
933 |
+
}
|
934 |
+
});
|
935 |
+
}
|
936 |
+
}
|
937 |
+
);
|
938 |
+
|
939 |
+
function fire_event<K extends EventType>(event: Event<K>): void {
|
940 |
+
const narrowed_listener_map: ListenerMap<K> = listener_map;
|
941 |
+
const listeners = narrowed_listener_map[event.type] || [];
|
942 |
+
listeners?.forEach((l) => l(event));
|
943 |
+
}
|
944 |
+
|
945 |
+
function on<K extends EventType>(
|
946 |
+
eventType: K,
|
947 |
+
listener: EventListener<K>
|
948 |
+
): SubmitReturn {
|
949 |
+
const narrowed_listener_map: ListenerMap<K> = listener_map;
|
950 |
+
const listeners = narrowed_listener_map[eventType] || [];
|
951 |
+
narrowed_listener_map[eventType] = listeners;
|
952 |
+
listeners?.push(listener);
|
953 |
+
|
954 |
+
return { on, off, cancel, destroy };
|
955 |
+
}
|
956 |
+
|
957 |
+
function off<K extends EventType>(
|
958 |
+
eventType: K,
|
959 |
+
listener: EventListener<K>
|
960 |
+
): SubmitReturn {
|
961 |
+
const narrowed_listener_map: ListenerMap<K> = listener_map;
|
962 |
+
let listeners = narrowed_listener_map[eventType] || [];
|
963 |
+
listeners = listeners?.filter((l) => l !== listener);
|
964 |
+
narrowed_listener_map[eventType] = listeners;
|
965 |
+
|
966 |
+
return { on, off, cancel, destroy };
|
967 |
+
}
|
968 |
+
|
969 |
+
async function cancel(): Promise<void> {
|
970 |
+
const _status: Status = {
|
971 |
+
stage: "complete",
|
972 |
+
queue: false,
|
973 |
+
time: new Date()
|
974 |
+
};
|
975 |
+
complete = _status;
|
976 |
+
fire_event({
|
977 |
+
..._status,
|
978 |
+
type: "status",
|
979 |
+
endpoint: _endpoint,
|
980 |
+
fn_index: fn_index
|
981 |
+
});
|
982 |
+
|
983 |
+
let cancel_request = {};
|
984 |
+
if (protocol === "ws") {
|
985 |
+
if (websocket && websocket.readyState === 0) {
|
986 |
+
websocket.addEventListener("open", () => {
|
987 |
+
websocket.close();
|
988 |
+
});
|
989 |
+
} else {
|
990 |
+
websocket.close();
|
991 |
+
}
|
992 |
+
cancel_request = { fn_index, session_hash };
|
993 |
+
} else {
|
994 |
+
eventSource.close();
|
995 |
+
cancel_request = { event_id };
|
996 |
+
}
|
997 |
+
|
998 |
+
try {
|
999 |
+
await fetch_implementation(`${config.root}/reset`, {
|
1000 |
+
headers: { "Content-Type": "application/json" },
|
1001 |
+
method: "POST",
|
1002 |
+
body: JSON.stringify(cancel_request)
|
1003 |
+
});
|
1004 |
+
} catch (e) {
|
1005 |
+
console.warn(
|
1006 |
+
"The `/reset` endpoint could not be called. Subsequent endpoint results may be unreliable."
|
1007 |
+
);
|
1008 |
+
}
|
1009 |
+
}
|
1010 |
+
|
1011 |
+
function destroy(): void {
|
1012 |
+
for (const event_type in listener_map) {
|
1013 |
+
listener_map[event_type as "data" | "status"].forEach((fn) => {
|
1014 |
+
off(event_type as "data" | "status", fn);
|
1015 |
+
});
|
1016 |
+
}
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
return {
|
1020 |
+
on,
|
1021 |
+
off,
|
1022 |
+
cancel,
|
1023 |
+
destroy
|
1024 |
+
};
|
1025 |
+
}
|
1026 |
+
|
1027 |
+
function open_stream(): void {
|
1028 |
+
stream_open = true;
|
1029 |
+
let params = new URLSearchParams({
|
1030 |
+
session_hash: session_hash
|
1031 |
+
}).toString();
|
1032 |
+
let url = new URL(`${config.root}/queue/data?${params}`);
|
1033 |
+
event_stream = EventSource_factory(url);
|
1034 |
+
event_stream.onmessage = async function (event) {
|
1035 |
+
let _data = JSON.parse(event.data);
|
1036 |
+
const event_id = _data.event_id;
|
1037 |
+
if (!event_id) {
|
1038 |
+
await Promise.all(
|
1039 |
+
Object.keys(event_callbacks).map((event_id) =>
|
1040 |
+
event_callbacks[event_id](_data)
|
1041 |
+
)
|
1042 |
+
);
|
1043 |
+
} else if (event_callbacks[event_id]) {
|
1044 |
+
if (_data.msg === "process_completed") {
|
1045 |
+
unclosed_events.delete(event_id);
|
1046 |
+
if (unclosed_events.size === 0) {
|
1047 |
+
close_stream();
|
1048 |
+
}
|
1049 |
+
}
|
1050 |
+
let fn = event_callbacks[event_id];
|
1051 |
+
window.setTimeout(fn, 0, _data); // need to do this to put the event on the end of the event loop, so the browser can refresh between callbacks and not freeze in case of quick generations. See https://github.com/gradio-app/gradio/pull/7055
|
1052 |
+
} else {
|
1053 |
+
if (!pending_stream_messages[event_id]) {
|
1054 |
+
pending_stream_messages[event_id] = [];
|
1055 |
+
}
|
1056 |
+
pending_stream_messages[event_id].push(_data);
|
1057 |
+
}
|
1058 |
+
};
|
1059 |
+
event_stream.onerror = async function (event) {
|
1060 |
+
await Promise.all(
|
1061 |
+
Object.keys(event_callbacks).map((event_id) =>
|
1062 |
+
event_callbacks[event_id]({
|
1063 |
+
msg: "unexpected_error",
|
1064 |
+
message: BROKEN_CONNECTION_MSG
|
1065 |
+
})
|
1066 |
+
)
|
1067 |
+
);
|
1068 |
+
close_stream();
|
1069 |
+
};
|
1070 |
+
}
|
1071 |
+
|
1072 |
+
function close_stream(): void {
|
1073 |
+
stream_open = false;
|
1074 |
+
event_stream?.close();
|
1075 |
+
}
|
1076 |
+
|
1077 |
+
async function component_server(
|
1078 |
+
component_id: number,
|
1079 |
+
fn_name: string,
|
1080 |
+
data: unknown[]
|
1081 |
+
): Promise<any> {
|
1082 |
+
const headers: {
|
1083 |
+
Authorization?: string;
|
1084 |
+
"Content-Type": "application/json";
|
1085 |
+
} = { "Content-Type": "application/json" };
|
1086 |
+
if (hf_token) {
|
1087 |
+
headers.Authorization = `Bearer ${hf_token}`;
|
1088 |
+
}
|
1089 |
+
let root_url: string;
|
1090 |
+
let component = config.components.find(
|
1091 |
+
(comp) => comp.id === component_id
|
1092 |
+
);
|
1093 |
+
if (component?.props?.root_url) {
|
1094 |
+
root_url = component.props.root_url;
|
1095 |
+
} else {
|
1096 |
+
root_url = config.root;
|
1097 |
+
}
|
1098 |
+
const response = await fetch_implementation(
|
1099 |
+
`${root_url}/component_server/`,
|
1100 |
+
{
|
1101 |
+
method: "POST",
|
1102 |
+
body: JSON.stringify({
|
1103 |
+
data: data,
|
1104 |
+
component_id: component_id,
|
1105 |
+
fn_name: fn_name,
|
1106 |
+
session_hash: session_hash
|
1107 |
+
}),
|
1108 |
+
headers
|
1109 |
+
}
|
1110 |
+
);
|
1111 |
+
|
1112 |
+
if (!response.ok) {
|
1113 |
+
throw new Error(
|
1114 |
+
"Could not connect to component server: " + response.statusText
|
1115 |
+
);
|
1116 |
+
}
|
1117 |
+
|
1118 |
+
const output = await response.json();
|
1119 |
+
return output;
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
async function view_api(config?: Config): Promise<ApiInfo<JsApiData>> {
|
1123 |
+
if (api) return api;
|
1124 |
+
|
1125 |
+
const headers: {
|
1126 |
+
Authorization?: string;
|
1127 |
+
"Content-Type": "application/json";
|
1128 |
+
} = { "Content-Type": "application/json" };
|
1129 |
+
if (hf_token) {
|
1130 |
+
headers.Authorization = `Bearer ${hf_token}`;
|
1131 |
+
}
|
1132 |
+
let response: Response;
|
1133 |
+
// @ts-ignore
|
1134 |
+
if (semiver(config.version || "2.0.0", "3.30") < 0) {
|
1135 |
+
response = await fetch_implementation(
|
1136 |
+
"https://gradio-space-api-fetcher-v2.hf.space/api",
|
1137 |
+
{
|
1138 |
+
method: "POST",
|
1139 |
+
body: JSON.stringify({
|
1140 |
+
serialize: false,
|
1141 |
+
config: JSON.stringify(config)
|
1142 |
+
}),
|
1143 |
+
headers
|
1144 |
+
}
|
1145 |
+
);
|
1146 |
+
} else {
|
1147 |
+
response = await fetch_implementation(`${config.root}/info`, {
|
1148 |
+
headers
|
1149 |
+
});
|
1150 |
+
}
|
1151 |
+
|
1152 |
+
if (!response.ok) {
|
1153 |
+
throw new Error(BROKEN_CONNECTION_MSG);
|
1154 |
+
}
|
1155 |
+
|
1156 |
+
let api_info = (await response.json()) as
|
1157 |
+
| ApiInfo<ApiData>
|
1158 |
+
| { api: ApiInfo<ApiData> };
|
1159 |
+
if ("api" in api_info) {
|
1160 |
+
api_info = api_info.api;
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
if (
|
1164 |
+
api_info.named_endpoints["/predict"] &&
|
1165 |
+
!api_info.unnamed_endpoints["0"]
|
1166 |
+
) {
|
1167 |
+
api_info.unnamed_endpoints[0] = api_info.named_endpoints["/predict"];
|
1168 |
+
}
|
1169 |
+
|
1170 |
+
const x = transform_api_info(api_info, config, api_map);
|
1171 |
+
return x;
|
1172 |
+
}
|
1173 |
+
});
|
1174 |
+
}
|
1175 |
+
|
1176 |
+
async function handle_blob(
|
1177 |
+
endpoint: string,
|
1178 |
+
data: unknown[],
|
1179 |
+
api_info: ApiInfo<JsApiData>,
|
1180 |
+
token?: `hf_${string}`
|
1181 |
+
): Promise<unknown[]> {
|
1182 |
+
const blob_refs = await walk_and_store_blobs(
|
1183 |
+
data,
|
1184 |
+
undefined,
|
1185 |
+
[],
|
1186 |
+
true,
|
1187 |
+
api_info
|
1188 |
+
);
|
1189 |
+
|
1190 |
+
return Promise.all(
|
1191 |
+
blob_refs.map(async ({ path, blob, type }) => {
|
1192 |
+
if (blob) {
|
1193 |
+
const file_url = (await upload_files(endpoint, [blob], token))
|
1194 |
+
.files[0];
|
1195 |
+
return { path, file_url, type, name: blob?.name };
|
1196 |
+
}
|
1197 |
+
return { path, type };
|
1198 |
+
})
|
1199 |
+
).then((r) => {
|
1200 |
+
r.forEach(({ path, file_url, type, name }) => {
|
1201 |
+
if (type === "Gallery") {
|
1202 |
+
update_object(data, file_url, path);
|
1203 |
+
} else if (file_url) {
|
1204 |
+
const file = new FileData({ path: file_url, orig_name: name });
|
1205 |
+
update_object(data, file, path);
|
1206 |
+
}
|
1207 |
+
});
|
1208 |
+
|
1209 |
+
return data;
|
1210 |
+
});
|
1211 |
+
}
|
1212 |
+
}
|
1213 |
+
|
1214 |
+
export const { post_data, upload_files, client, handle_blob } = api_factory(
|
1215 |
+
fetch,
|
1216 |
+
(...args) => new EventSource(...args)
|
1217 |
+
);
|
1218 |
+
|
1219 |
+
function transform_output(
|
1220 |
+
data: any[],
|
1221 |
+
api_info: any,
|
1222 |
+
root_url: string,
|
1223 |
+
remote_url?: string
|
1224 |
+
): unknown[] {
|
1225 |
+
return data.map((d, i) => {
|
1226 |
+
if (api_info?.returns?.[i]?.component === "File") {
|
1227 |
+
return normalise_file(d, root_url, remote_url);
|
1228 |
+
} else if (api_info?.returns?.[i]?.component === "Gallery") {
|
1229 |
+
return d.map((img) => {
|
1230 |
+
return Array.isArray(img)
|
1231 |
+
? [normalise_file(img[0], root_url, remote_url), img[1]]
|
1232 |
+
: [normalise_file(img, root_url, remote_url), null];
|
1233 |
+
});
|
1234 |
+
} else if (typeof d === "object" && d.path) {
|
1235 |
+
return normalise_file(d, root_url, remote_url);
|
1236 |
+
}
|
1237 |
+
return d;
|
1238 |
+
});
|
1239 |
+
}
|
1240 |
+
|
1241 |
+
interface ApiData {
|
1242 |
+
label: string;
|
1243 |
+
type: {
|
1244 |
+
type: any;
|
1245 |
+
description: string;
|
1246 |
+
};
|
1247 |
+
component: string;
|
1248 |
+
example_input?: any;
|
1249 |
+
}
|
1250 |
+
|
1251 |
+
interface JsApiData {
|
1252 |
+
label: string;
|
1253 |
+
type: string;
|
1254 |
+
component: string;
|
1255 |
+
example_input: any;
|
1256 |
+
}
|
1257 |
+
|
1258 |
+
interface EndpointInfo<T extends ApiData | JsApiData> {
|
1259 |
+
parameters: T[];
|
1260 |
+
returns: T[];
|
1261 |
+
}
|
1262 |
+
interface ApiInfo<T extends ApiData | JsApiData> {
|
1263 |
+
named_endpoints: {
|
1264 |
+
[key: string]: EndpointInfo<T>;
|
1265 |
+
};
|
1266 |
+
unnamed_endpoints: {
|
1267 |
+
[key: string]: EndpointInfo<T>;
|
1268 |
+
};
|
1269 |
+
}
|
1270 |
+
|
1271 |
+
function get_type(
|
1272 |
+
type: { [key: string]: any },
|
1273 |
+
component: string,
|
1274 |
+
serializer: string,
|
1275 |
+
signature_type: "return" | "parameter"
|
1276 |
+
): string {
|
1277 |
+
switch (type.type) {
|
1278 |
+
case "string":
|
1279 |
+
return "string";
|
1280 |
+
case "boolean":
|
1281 |
+
return "boolean";
|
1282 |
+
case "number":
|
1283 |
+
return "number";
|
1284 |
+
}
|
1285 |
+
|
1286 |
+
if (
|
1287 |
+
serializer === "JSONSerializable" ||
|
1288 |
+
serializer === "StringSerializable"
|
1289 |
+
) {
|
1290 |
+
return "any";
|
1291 |
+
} else if (serializer === "ListStringSerializable") {
|
1292 |
+
return "string[]";
|
1293 |
+
} else if (component === "Image") {
|
1294 |
+
return signature_type === "parameter" ? "Blob | File | Buffer" : "string";
|
1295 |
+
} else if (serializer === "FileSerializable") {
|
1296 |
+
if (type?.type === "array") {
|
1297 |
+
return signature_type === "parameter"
|
1298 |
+
? "(Blob | File | Buffer)[]"
|
1299 |
+
: `{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}[]`;
|
1300 |
+
}
|
1301 |
+
return signature_type === "parameter"
|
1302 |
+
? "Blob | File | Buffer"
|
1303 |
+
: `{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}`;
|
1304 |
+
} else if (serializer === "GallerySerializable") {
|
1305 |
+
return signature_type === "parameter"
|
1306 |
+
? "[(Blob | File | Buffer), (string | null)][]"
|
1307 |
+
: `[{ name: string; data: string; size?: number; is_file?: boolean; orig_name?: string}, (string | null))][]`;
|
1308 |
+
}
|
1309 |
+
}
|
1310 |
+
|
1311 |
+
function get_description(
|
1312 |
+
type: { type: any; description: string },
|
1313 |
+
serializer: string
|
1314 |
+
): string {
|
1315 |
+
if (serializer === "GallerySerializable") {
|
1316 |
+
return "array of [file, label] tuples";
|
1317 |
+
} else if (serializer === "ListStringSerializable") {
|
1318 |
+
return "array of strings";
|
1319 |
+
} else if (serializer === "FileSerializable") {
|
1320 |
+
return "array of files or single file";
|
1321 |
+
}
|
1322 |
+
return type.description;
|
1323 |
+
}
|
1324 |
+
|
1325 |
+
function transform_api_info(
|
1326 |
+
api_info: ApiInfo<ApiData>,
|
1327 |
+
config: Config,
|
1328 |
+
api_map: Record<string, number>
|
1329 |
+
): ApiInfo<JsApiData> {
|
1330 |
+
const new_data = {
|
1331 |
+
named_endpoints: {},
|
1332 |
+
unnamed_endpoints: {}
|
1333 |
+
};
|
1334 |
+
for (const key in api_info) {
|
1335 |
+
const cat = api_info[key];
|
1336 |
+
|
1337 |
+
for (const endpoint in cat) {
|
1338 |
+
const dep_index = config.dependencies[endpoint]
|
1339 |
+
? endpoint
|
1340 |
+
: api_map[endpoint.replace("/", "")];
|
1341 |
+
|
1342 |
+
const info = cat[endpoint];
|
1343 |
+
new_data[key][endpoint] = {};
|
1344 |
+
new_data[key][endpoint].parameters = {};
|
1345 |
+
new_data[key][endpoint].returns = {};
|
1346 |
+
new_data[key][endpoint].type = config.dependencies[dep_index].types;
|
1347 |
+
new_data[key][endpoint].parameters = info.parameters.map(
|
1348 |
+
({ label, component, type, serializer }) => ({
|
1349 |
+
label,
|
1350 |
+
component,
|
1351 |
+
type: get_type(type, component, serializer, "parameter"),
|
1352 |
+
description: get_description(type, serializer)
|
1353 |
+
})
|
1354 |
+
);
|
1355 |
+
|
1356 |
+
new_data[key][endpoint].returns = info.returns.map(
|
1357 |
+
({ label, component, type, serializer }) => ({
|
1358 |
+
label,
|
1359 |
+
component,
|
1360 |
+
type: get_type(type, component, serializer, "return"),
|
1361 |
+
description: get_description(type, serializer)
|
1362 |
+
})
|
1363 |
+
);
|
1364 |
+
}
|
1365 |
+
}
|
1366 |
+
|
1367 |
+
return new_data;
|
1368 |
+
}
|
1369 |
+
|
1370 |
+
async function get_jwt(
|
1371 |
+
space: string,
|
1372 |
+
token: `hf_${string}`
|
1373 |
+
): Promise<string | false> {
|
1374 |
+
try {
|
1375 |
+
const r = await fetch(`https://huggingface.co/api/spaces/${space}/jwt`, {
|
1376 |
+
headers: {
|
1377 |
+
Authorization: `Bearer ${token}`
|
1378 |
+
}
|
1379 |
+
});
|
1380 |
+
|
1381 |
+
const jwt = (await r.json()).token;
|
1382 |
+
|
1383 |
+
return jwt || false;
|
1384 |
+
} catch (e) {
|
1385 |
+
console.error(e);
|
1386 |
+
return false;
|
1387 |
+
}
|
1388 |
+
}
|
1389 |
+
|
1390 |
+
function update_object(object, newValue, stack): void {
|
1391 |
+
while (stack.length > 1) {
|
1392 |
+
object = object[stack.shift()];
|
1393 |
+
}
|
1394 |
+
|
1395 |
+
object[stack.shift()] = newValue;
|
1396 |
+
}
|
1397 |
+
|
1398 |
+
export async function walk_and_store_blobs(
|
1399 |
+
param,
|
1400 |
+
type = undefined,
|
1401 |
+
path = [],
|
1402 |
+
root = false,
|
1403 |
+
api_info = undefined
|
1404 |
+
): Promise<
|
1405 |
+
{
|
1406 |
+
path: string[];
|
1407 |
+
type: string;
|
1408 |
+
blob: Blob | false;
|
1409 |
+
}[]
|
1410 |
+
> {
|
1411 |
+
if (Array.isArray(param)) {
|
1412 |
+
let blob_refs = [];
|
1413 |
+
|
1414 |
+
await Promise.all(
|
1415 |
+
param.map(async (v, i) => {
|
1416 |
+
let new_path = path.slice();
|
1417 |
+
new_path.push(i);
|
1418 |
+
|
1419 |
+
const array_refs = await walk_and_store_blobs(
|
1420 |
+
param[i],
|
1421 |
+
root ? api_info?.parameters[i]?.component || undefined : type,
|
1422 |
+
new_path,
|
1423 |
+
false,
|
1424 |
+
api_info
|
1425 |
+
);
|
1426 |
+
|
1427 |
+
blob_refs = blob_refs.concat(array_refs);
|
1428 |
+
})
|
1429 |
+
);
|
1430 |
+
|
1431 |
+
return blob_refs;
|
1432 |
+
} else if (globalThis.Buffer && param instanceof globalThis.Buffer) {
|
1433 |
+
const is_image = type === "Image";
|
1434 |
+
return [
|
1435 |
+
{
|
1436 |
+
path: path,
|
1437 |
+
blob: is_image ? false : new NodeBlob([param]),
|
1438 |
+
type
|
1439 |
+
}
|
1440 |
+
];
|
1441 |
+
} else if (typeof param === "object") {
|
1442 |
+
let blob_refs = [];
|
1443 |
+
for (let key in param) {
|
1444 |
+
if (param.hasOwnProperty(key)) {
|
1445 |
+
let new_path = path.slice();
|
1446 |
+
new_path.push(key);
|
1447 |
+
blob_refs = blob_refs.concat(
|
1448 |
+
await walk_and_store_blobs(
|
1449 |
+
param[key],
|
1450 |
+
undefined,
|
1451 |
+
new_path,
|
1452 |
+
false,
|
1453 |
+
api_info
|
1454 |
+
)
|
1455 |
+
);
|
1456 |
+
}
|
1457 |
+
}
|
1458 |
+
return blob_refs;
|
1459 |
+
}
|
1460 |
+
return [];
|
1461 |
+
}
|
1462 |
+
|
1463 |
+
function image_to_data_uri(blob: Blob): Promise<string | ArrayBuffer> {
|
1464 |
+
return new Promise((resolve, _) => {
|
1465 |
+
const reader = new FileReader();
|
1466 |
+
reader.onloadend = () => resolve(reader.result);
|
1467 |
+
reader.readAsDataURL(blob);
|
1468 |
+
});
|
1469 |
+
}
|
1470 |
+
|
1471 |
+
function skip_queue(id: number, config: Config): boolean {
|
1472 |
+
return (
|
1473 |
+
!(config?.dependencies?.[id]?.queue === null
|
1474 |
+
? config.enable_queue
|
1475 |
+
: config?.dependencies?.[id]?.queue) || false
|
1476 |
+
);
|
1477 |
+
}
|
1478 |
+
|
1479 |
+
async function resolve_config(
|
1480 |
+
fetch_implementation: typeof fetch,
|
1481 |
+
endpoint?: string,
|
1482 |
+
token?: `hf_${string}`
|
1483 |
+
): Promise<Config> {
|
1484 |
+
const headers: { Authorization?: string } = {};
|
1485 |
+
if (token) {
|
1486 |
+
headers.Authorization = `Bearer ${token}`;
|
1487 |
+
}
|
1488 |
+
if (
|
1489 |
+
typeof window !== "undefined" &&
|
1490 |
+
window.gradio_config &&
|
1491 |
+
location.origin !== "http://localhost:9876" &&
|
1492 |
+
!window.gradio_config.dev_mode
|
1493 |
+
) {
|
1494 |
+
const path = window.gradio_config.root;
|
1495 |
+
const config = window.gradio_config;
|
1496 |
+
config.root = resolve_root(endpoint, config.root, false);
|
1497 |
+
return { ...config, path: path };
|
1498 |
+
} else if (endpoint) {
|
1499 |
+
let response = await fetch_implementation(`${endpoint}/config`, {
|
1500 |
+
headers
|
1501 |
+
});
|
1502 |
+
|
1503 |
+
if (response.status === 200) {
|
1504 |
+
const config = await response.json();
|
1505 |
+
config.path = config.path ?? "";
|
1506 |
+
config.root = endpoint;
|
1507 |
+
return config;
|
1508 |
+
}
|
1509 |
+
throw new Error("Could not get config.");
|
1510 |
+
}
|
1511 |
+
|
1512 |
+
throw new Error("No config or app endpoint found");
|
1513 |
+
}
|
1514 |
+
|
1515 |
+
async function check_space_status(
|
1516 |
+
id: string,
|
1517 |
+
type: "subdomain" | "space_name",
|
1518 |
+
status_callback: SpaceStatusCallback
|
1519 |
+
): Promise<void> {
|
1520 |
+
let endpoint =
|
1521 |
+
type === "subdomain"
|
1522 |
+
? `https://huggingface.co/api/spaces/by-subdomain/${id}`
|
1523 |
+
: `https://huggingface.co/api/spaces/${id}`;
|
1524 |
+
let response;
|
1525 |
+
let _status;
|
1526 |
+
try {
|
1527 |
+
response = await fetch(endpoint);
|
1528 |
+
_status = response.status;
|
1529 |
+
if (_status !== 200) {
|
1530 |
+
throw new Error();
|
1531 |
+
}
|
1532 |
+
response = await response.json();
|
1533 |
+
} catch (e) {
|
1534 |
+
status_callback({
|
1535 |
+
status: "error",
|
1536 |
+
load_status: "error",
|
1537 |
+
message: "Could not get space status",
|
1538 |
+
detail: "NOT_FOUND"
|
1539 |
+
});
|
1540 |
+
return;
|
1541 |
+
}
|
1542 |
+
|
1543 |
+
if (!response || _status !== 200) return;
|
1544 |
+
const {
|
1545 |
+
runtime: { stage },
|
1546 |
+
id: space_name
|
1547 |
+
} = response;
|
1548 |
+
|
1549 |
+
switch (stage) {
|
1550 |
+
case "STOPPED":
|
1551 |
+
case "SLEEPING":
|
1552 |
+
status_callback({
|
1553 |
+
status: "sleeping",
|
1554 |
+
load_status: "pending",
|
1555 |
+
message: "Space is asleep. Waking it up...",
|
1556 |
+
detail: stage
|
1557 |
+
});
|
1558 |
+
|
1559 |
+
setTimeout(() => {
|
1560 |
+
check_space_status(id, type, status_callback);
|
1561 |
+
}, 1000); // poll for status
|
1562 |
+
break;
|
1563 |
+
case "PAUSED":
|
1564 |
+
status_callback({
|
1565 |
+
status: "paused",
|
1566 |
+
load_status: "error",
|
1567 |
+
message:
|
1568 |
+
"This space has been paused by the author. If you would like to try this demo, consider duplicating the space.",
|
1569 |
+
detail: stage,
|
1570 |
+
discussions_enabled: await discussions_enabled(space_name)
|
1571 |
+
});
|
1572 |
+
break;
|
1573 |
+
case "RUNNING":
|
1574 |
+
case "RUNNING_BUILDING":
|
1575 |
+
status_callback({
|
1576 |
+
status: "running",
|
1577 |
+
load_status: "complete",
|
1578 |
+
message: "",
|
1579 |
+
detail: stage
|
1580 |
+
});
|
1581 |
+
// load_config(source);
|
1582 |
+
// launch
|
1583 |
+
break;
|
1584 |
+
case "BUILDING":
|
1585 |
+
status_callback({
|
1586 |
+
status: "building",
|
1587 |
+
load_status: "pending",
|
1588 |
+
message: "Space is building...",
|
1589 |
+
detail: stage
|
1590 |
+
});
|
1591 |
+
|
1592 |
+
setTimeout(() => {
|
1593 |
+
check_space_status(id, type, status_callback);
|
1594 |
+
}, 1000);
|
1595 |
+
break;
|
1596 |
+
default:
|
1597 |
+
status_callback({
|
1598 |
+
status: "space_error",
|
1599 |
+
load_status: "error",
|
1600 |
+
message: "This space is experiencing an issue.",
|
1601 |
+
detail: stage,
|
1602 |
+
discussions_enabled: await discussions_enabled(space_name)
|
1603 |
+
});
|
1604 |
+
break;
|
1605 |
+
}
|
1606 |
+
}
|
1607 |
+
|
1608 |
+
function handle_message(
|
1609 |
+
data: any,
|
1610 |
+
last_status: Status["stage"]
|
1611 |
+
): {
|
1612 |
+
type: "hash" | "data" | "update" | "complete" | "generating" | "log" | "none";
|
1613 |
+
data?: any;
|
1614 |
+
status?: Status;
|
1615 |
+
} {
|
1616 |
+
const queue = true;
|
1617 |
+
switch (data.msg) {
|
1618 |
+
case "send_data":
|
1619 |
+
return { type: "data" };
|
1620 |
+
case "send_hash":
|
1621 |
+
return { type: "hash" };
|
1622 |
+
case "queue_full":
|
1623 |
+
return {
|
1624 |
+
type: "update",
|
1625 |
+
status: {
|
1626 |
+
queue,
|
1627 |
+
message: QUEUE_FULL_MSG,
|
1628 |
+
stage: "error",
|
1629 |
+
code: data.code,
|
1630 |
+
success: data.success
|
1631 |
+
}
|
1632 |
+
};
|
1633 |
+
case "heartbeat":
|
1634 |
+
return {
|
1635 |
+
type: "heartbeat"
|
1636 |
+
};
|
1637 |
+
case "unexpected_error":
|
1638 |
+
return {
|
1639 |
+
type: "unexpected_error",
|
1640 |
+
status: {
|
1641 |
+
queue,
|
1642 |
+
message: data.message,
|
1643 |
+
stage: "error",
|
1644 |
+
success: false
|
1645 |
+
}
|
1646 |
+
};
|
1647 |
+
case "estimation":
|
1648 |
+
return {
|
1649 |
+
type: "update",
|
1650 |
+
status: {
|
1651 |
+
queue,
|
1652 |
+
stage: last_status || "pending",
|
1653 |
+
code: data.code,
|
1654 |
+
size: data.queue_size,
|
1655 |
+
position: data.rank,
|
1656 |
+
eta: data.rank_eta,
|
1657 |
+
success: data.success
|
1658 |
+
}
|
1659 |
+
};
|
1660 |
+
case "progress":
|
1661 |
+
return {
|
1662 |
+
type: "update",
|
1663 |
+
status: {
|
1664 |
+
queue,
|
1665 |
+
stage: "pending",
|
1666 |
+
code: data.code,
|
1667 |
+
progress_data: data.progress_data,
|
1668 |
+
success: data.success
|
1669 |
+
}
|
1670 |
+
};
|
1671 |
+
case "log":
|
1672 |
+
return { type: "log", data: data };
|
1673 |
+
case "process_generating":
|
1674 |
+
return {
|
1675 |
+
type: "generating",
|
1676 |
+
status: {
|
1677 |
+
queue,
|
1678 |
+
message: !data.success ? data.output.error : null,
|
1679 |
+
stage: data.success ? "generating" : "error",
|
1680 |
+
code: data.code,
|
1681 |
+
progress_data: data.progress_data,
|
1682 |
+
eta: data.average_duration
|
1683 |
+
},
|
1684 |
+
data: data.success ? data.output : null
|
1685 |
+
};
|
1686 |
+
case "process_completed":
|
1687 |
+
if ("error" in data.output) {
|
1688 |
+
return {
|
1689 |
+
type: "update",
|
1690 |
+
status: {
|
1691 |
+
queue,
|
1692 |
+
message: data.output.error as string,
|
1693 |
+
stage: "error",
|
1694 |
+
code: data.code,
|
1695 |
+
success: data.success
|
1696 |
+
}
|
1697 |
+
};
|
1698 |
+
}
|
1699 |
+
return {
|
1700 |
+
type: "complete",
|
1701 |
+
status: {
|
1702 |
+
queue,
|
1703 |
+
message: !data.success ? data.output.error : undefined,
|
1704 |
+
stage: data.success ? "complete" : "error",
|
1705 |
+
code: data.code,
|
1706 |
+
progress_data: data.progress_data
|
1707 |
+
},
|
1708 |
+
data: data.success ? data.output : null
|
1709 |
+
};
|
1710 |
+
|
1711 |
+
case "process_starts":
|
1712 |
+
return {
|
1713 |
+
type: "update",
|
1714 |
+
status: {
|
1715 |
+
queue,
|
1716 |
+
stage: "pending",
|
1717 |
+
code: data.code,
|
1718 |
+
size: data.rank,
|
1719 |
+
position: 0,
|
1720 |
+
success: data.success,
|
1721 |
+
eta: data.eta
|
1722 |
+
}
|
1723 |
+
};
|
1724 |
+
}
|
1725 |
+
|
1726 |
+
return { type: "none", status: { stage: "error", queue } };
|
1727 |
+
}
|
node_modules/@gradio/client/src/globals.d.ts
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
declare global {
|
2 |
+
interface Window {
|
3 |
+
__gradio_mode__: "app" | "website";
|
4 |
+
gradio_config: Config;
|
5 |
+
__is_colab__: boolean;
|
6 |
+
__gradio_space__: string | null;
|
7 |
+
}
|
8 |
+
}
|
9 |
+
|
10 |
+
export interface Config {
|
11 |
+
auth_required: boolean | undefined;
|
12 |
+
auth_message: string;
|
13 |
+
components: any[];
|
14 |
+
css: string | null;
|
15 |
+
dependencies: any[];
|
16 |
+
dev_mode: boolean;
|
17 |
+
enable_queue: boolean;
|
18 |
+
layout: any;
|
19 |
+
mode: "blocks" | "interface";
|
20 |
+
root: string;
|
21 |
+
theme: string;
|
22 |
+
title: string;
|
23 |
+
version: string;
|
24 |
+
space_id: string | null;
|
25 |
+
is_colab: boolean;
|
26 |
+
show_api: boolean;
|
27 |
+
stylesheets: string[];
|
28 |
+
path: string;
|
29 |
+
}
|
node_modules/@gradio/client/src/index.ts
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export {
|
2 |
+
client,
|
3 |
+
post_data,
|
4 |
+
upload_files,
|
5 |
+
duplicate,
|
6 |
+
api_factory
|
7 |
+
} from "./client.js";
|
8 |
+
export type { SpaceStatus } from "./types.js";
|
9 |
+
export {
|
10 |
+
normalise_file,
|
11 |
+
FileData,
|
12 |
+
upload,
|
13 |
+
get_fetchable_url_or_file,
|
14 |
+
prepare_files
|
15 |
+
} from "./upload.js";
|
node_modules/@gradio/client/src/types.ts
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export interface Config {
|
2 |
+
auth_required: boolean | undefined;
|
3 |
+
auth_message: string;
|
4 |
+
components: any[];
|
5 |
+
css: string | null;
|
6 |
+
js: string | null;
|
7 |
+
head: string | null;
|
8 |
+
dependencies: any[];
|
9 |
+
dev_mode: boolean;
|
10 |
+
enable_queue: boolean;
|
11 |
+
layout: any;
|
12 |
+
mode: "blocks" | "interface";
|
13 |
+
root: string;
|
14 |
+
root_url?: string;
|
15 |
+
theme: string;
|
16 |
+
title: string;
|
17 |
+
version: string;
|
18 |
+
space_id: string | null;
|
19 |
+
is_colab: boolean;
|
20 |
+
show_api: boolean;
|
21 |
+
stylesheets: string[];
|
22 |
+
path: string;
|
23 |
+
protocol?: "sse_v1" | "sse" | "ws";
|
24 |
+
}
|
25 |
+
|
26 |
+
export interface Payload {
|
27 |
+
data: unknown[];
|
28 |
+
fn_index?: number;
|
29 |
+
event_data?: unknown;
|
30 |
+
time?: Date;
|
31 |
+
}
|
32 |
+
|
33 |
+
export interface PostResponse {
|
34 |
+
error?: string;
|
35 |
+
[x: string]: any;
|
36 |
+
}
|
37 |
+
export interface UploadResponse {
|
38 |
+
error?: string;
|
39 |
+
files?: string[];
|
40 |
+
}
|
41 |
+
|
42 |
+
export interface Status {
|
43 |
+
queue: boolean;
|
44 |
+
code?: string;
|
45 |
+
success?: boolean;
|
46 |
+
stage: "pending" | "error" | "complete" | "generating";
|
47 |
+
broken?: boolean;
|
48 |
+
size?: number;
|
49 |
+
position?: number;
|
50 |
+
eta?: number;
|
51 |
+
message?: string;
|
52 |
+
progress_data?: {
|
53 |
+
progress: number | null;
|
54 |
+
index: number | null;
|
55 |
+
length: number | null;
|
56 |
+
unit: string | null;
|
57 |
+
desc: string | null;
|
58 |
+
}[];
|
59 |
+
time?: Date;
|
60 |
+
}
|
61 |
+
|
62 |
+
export interface LogMessage {
|
63 |
+
log: string;
|
64 |
+
level: "warning" | "info";
|
65 |
+
}
|
66 |
+
|
67 |
+
export interface SpaceStatusNormal {
|
68 |
+
status: "sleeping" | "running" | "building" | "error" | "stopped";
|
69 |
+
detail:
|
70 |
+
| "SLEEPING"
|
71 |
+
| "RUNNING"
|
72 |
+
| "RUNNING_BUILDING"
|
73 |
+
| "BUILDING"
|
74 |
+
| "NOT_FOUND";
|
75 |
+
load_status: "pending" | "error" | "complete" | "generating";
|
76 |
+
message: string;
|
77 |
+
}
|
78 |
+
export interface SpaceStatusError {
|
79 |
+
status: "space_error" | "paused";
|
80 |
+
detail:
|
81 |
+
| "NO_APP_FILE"
|
82 |
+
| "CONFIG_ERROR"
|
83 |
+
| "BUILD_ERROR"
|
84 |
+
| "RUNTIME_ERROR"
|
85 |
+
| "PAUSED";
|
86 |
+
load_status: "error";
|
87 |
+
message: string;
|
88 |
+
discussions_enabled: boolean;
|
89 |
+
}
|
90 |
+
export type SpaceStatus = SpaceStatusNormal | SpaceStatusError;
|
91 |
+
|
92 |
+
export type status_callback_function = (a: Status) => void;
|
93 |
+
export type SpaceStatusCallback = (a: SpaceStatus) => void;
|
94 |
+
|
95 |
+
export type EventType = "data" | "status" | "log";
|
96 |
+
|
97 |
+
export interface EventMap {
|
98 |
+
data: Payload;
|
99 |
+
status: Status;
|
100 |
+
log: LogMessage;
|
101 |
+
}
|
102 |
+
|
103 |
+
export type Event<K extends EventType> = {
|
104 |
+
[P in K]: EventMap[P] & { type: P; endpoint: string; fn_index: number };
|
105 |
+
}[K];
|
106 |
+
export type EventListener<K extends EventType> = (event: Event<K>) => void;
|
107 |
+
export type ListenerMap<K extends EventType> = {
|
108 |
+
[P in K]?: EventListener<K>[];
|
109 |
+
};
|
110 |
+
export interface FileData {
|
111 |
+
name: string;
|
112 |
+
orig_name?: string;
|
113 |
+
size?: number;
|
114 |
+
data: string;
|
115 |
+
blob?: File;
|
116 |
+
is_file?: boolean;
|
117 |
+
mime_type?: string;
|
118 |
+
alt_text?: string;
|
119 |
+
}
|
node_modules/@gradio/client/src/upload.ts
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { upload_files } from "./client";
|
2 |
+
|
3 |
+
export function normalise_file(
|
4 |
+
file: FileData | null,
|
5 |
+
server_url: string,
|
6 |
+
proxy_url: string | null
|
7 |
+
): FileData | null;
|
8 |
+
|
9 |
+
export function normalise_file(
|
10 |
+
file: FileData[] | null,
|
11 |
+
server_url: string,
|
12 |
+
proxy_url: string | null
|
13 |
+
): FileData[] | null;
|
14 |
+
|
15 |
+
export function normalise_file(
|
16 |
+
file: FileData[] | FileData | null,
|
17 |
+
server_url: string, // root: string,
|
18 |
+
proxy_url: string | null // root_url: string | null
|
19 |
+
): FileData[] | FileData | null;
|
20 |
+
|
21 |
+
export function normalise_file(
|
22 |
+
file: FileData[] | FileData | null,
|
23 |
+
server_url: string, // root: string,
|
24 |
+
proxy_url: string | null // root_url: string | null
|
25 |
+
): FileData[] | FileData | null {
|
26 |
+
if (file == null) {
|
27 |
+
return null;
|
28 |
+
}
|
29 |
+
|
30 |
+
if (Array.isArray(file)) {
|
31 |
+
const normalized_file: (FileData | null)[] = [];
|
32 |
+
|
33 |
+
for (const x of file) {
|
34 |
+
if (x == null) {
|
35 |
+
normalized_file.push(null);
|
36 |
+
} else {
|
37 |
+
normalized_file.push(normalise_file(x, server_url, proxy_url));
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
return normalized_file as FileData[];
|
42 |
+
}
|
43 |
+
|
44 |
+
if (file.is_stream) {
|
45 |
+
if (proxy_url == null) {
|
46 |
+
return new FileData({
|
47 |
+
...file,
|
48 |
+
url: server_url + "/stream/" + file.path
|
49 |
+
});
|
50 |
+
}
|
51 |
+
return new FileData({
|
52 |
+
...file,
|
53 |
+
url: "/proxy=" + proxy_url + "stream/" + file.path
|
54 |
+
});
|
55 |
+
}
|
56 |
+
|
57 |
+
return new FileData({
|
58 |
+
...file,
|
59 |
+
url: get_fetchable_url_or_file(file.path, server_url, proxy_url)
|
60 |
+
});
|
61 |
+
}
|
62 |
+
|
63 |
+
function is_url(str: string): boolean {
|
64 |
+
try {
|
65 |
+
const url = new URL(str);
|
66 |
+
return url.protocol === "http:" || url.protocol === "https:";
|
67 |
+
} catch {
|
68 |
+
return false;
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
export function get_fetchable_url_or_file(
|
73 |
+
path: string | null,
|
74 |
+
server_url: string,
|
75 |
+
proxy_url: string | null
|
76 |
+
): string {
|
77 |
+
if (path == null) {
|
78 |
+
return proxy_url ? `/proxy=${proxy_url}file=` : `${server_url}/file=`;
|
79 |
+
}
|
80 |
+
if (is_url(path)) {
|
81 |
+
return path;
|
82 |
+
}
|
83 |
+
return proxy_url
|
84 |
+
? `/proxy=${proxy_url}file=${path}`
|
85 |
+
: `${server_url}/file=${path}`;
|
86 |
+
}
|
87 |
+
|
88 |
+
export async function upload(
|
89 |
+
file_data: FileData[],
|
90 |
+
root: string,
|
91 |
+
upload_id?: string,
|
92 |
+
upload_fn: typeof upload_files = upload_files
|
93 |
+
): Promise<(FileData | null)[] | null> {
|
94 |
+
let files = (Array.isArray(file_data) ? file_data : [file_data]).map(
|
95 |
+
(file_data) => file_data.blob!
|
96 |
+
);
|
97 |
+
|
98 |
+
return await Promise.all(
|
99 |
+
await upload_fn(root, files, undefined, upload_id).then(
|
100 |
+
async (response: { files?: string[]; error?: string }) => {
|
101 |
+
if (response.error) {
|
102 |
+
throw new Error(response.error);
|
103 |
+
} else {
|
104 |
+
if (response.files) {
|
105 |
+
return response.files.map((f, i) => {
|
106 |
+
const file = new FileData({ ...file_data[i], path: f });
|
107 |
+
|
108 |
+
return normalise_file(file, root, null);
|
109 |
+
});
|
110 |
+
}
|
111 |
+
|
112 |
+
return [];
|
113 |
+
}
|
114 |
+
}
|
115 |
+
)
|
116 |
+
);
|
117 |
+
}
|
118 |
+
|
119 |
+
export async function prepare_files(
|
120 |
+
files: File[],
|
121 |
+
is_stream?: boolean
|
122 |
+
): Promise<FileData[]> {
|
123 |
+
return files.map(
|
124 |
+
(f, i) =>
|
125 |
+
new FileData({
|
126 |
+
path: f.name,
|
127 |
+
orig_name: f.name,
|
128 |
+
blob: f,
|
129 |
+
size: f.size,
|
130 |
+
mime_type: f.type,
|
131 |
+
is_stream
|
132 |
+
})
|
133 |
+
);
|
134 |
+
}
|
135 |
+
|
136 |
+
export class FileData {
|
137 |
+
path: string;
|
138 |
+
url?: string;
|
139 |
+
orig_name?: string;
|
140 |
+
size?: number;
|
141 |
+
blob?: File;
|
142 |
+
is_stream?: boolean;
|
143 |
+
mime_type?: string;
|
144 |
+
alt_text?: string;
|
145 |
+
|
146 |
+
constructor({
|
147 |
+
path,
|
148 |
+
url,
|
149 |
+
orig_name,
|
150 |
+
size,
|
151 |
+
blob,
|
152 |
+
is_stream,
|
153 |
+
mime_type,
|
154 |
+
alt_text
|
155 |
+
}: {
|
156 |
+
path: string;
|
157 |
+
url?: string;
|
158 |
+
orig_name?: string;
|
159 |
+
size?: number;
|
160 |
+
blob?: File;
|
161 |
+
is_stream?: boolean;
|
162 |
+
mime_type?: string;
|
163 |
+
alt_text?: string;
|
164 |
+
}) {
|
165 |
+
this.path = path;
|
166 |
+
this.url = url;
|
167 |
+
this.orig_name = orig_name;
|
168 |
+
this.size = size;
|
169 |
+
this.blob = url ? undefined : blob;
|
170 |
+
this.is_stream = is_stream;
|
171 |
+
this.mime_type = mime_type;
|
172 |
+
this.alt_text = alt_text;
|
173 |
+
}
|
174 |
+
}
|
node_modules/@gradio/client/src/utils.ts
ADDED
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { Config } from "./types.js";
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This function is used to resolve the URL for making requests when the app has a root path.
|
5 |
+
* The root path could be a path suffix like "/app" which is appended to the end of the base URL. Or
|
6 |
+
* it could be a full URL like "https://abidlabs-test-client-replica--gqf2x.hf.space" which is used when hosting
|
7 |
+
* Gradio apps on Hugging Face Spaces.
|
8 |
+
* @param {string} base_url The base URL at which the Gradio server is hosted
|
9 |
+
* @param {string} root_path The root path, which could be a path suffix (e.g. mounted in FastAPI app) or a full URL (e.g. hosted on Hugging Face Spaces)
|
10 |
+
* @param {boolean} prioritize_base Whether to prioritize the base URL over the root path. This is used when both the base path and root paths are full URLs. For example, for fetching files the root path should be prioritized, but for making requests, the base URL should be prioritized.
|
11 |
+
* @returns {string} the resolved URL
|
12 |
+
*/
|
13 |
+
export function resolve_root(
|
14 |
+
base_url: string,
|
15 |
+
root_path: string,
|
16 |
+
prioritize_base: boolean
|
17 |
+
): string {
|
18 |
+
if (root_path.startsWith("http://") || root_path.startsWith("https://")) {
|
19 |
+
return prioritize_base ? base_url : root_path;
|
20 |
+
}
|
21 |
+
return base_url + root_path;
|
22 |
+
}
|
23 |
+
|
24 |
+
export function determine_protocol(endpoint: string): {
|
25 |
+
ws_protocol: "ws" | "wss";
|
26 |
+
http_protocol: "http:" | "https:";
|
27 |
+
host: string;
|
28 |
+
} {
|
29 |
+
if (endpoint.startsWith("http")) {
|
30 |
+
const { protocol, host } = new URL(endpoint);
|
31 |
+
|
32 |
+
if (host.endsWith("hf.space")) {
|
33 |
+
return {
|
34 |
+
ws_protocol: "wss",
|
35 |
+
host: host,
|
36 |
+
http_protocol: protocol as "http:" | "https:"
|
37 |
+
};
|
38 |
+
}
|
39 |
+
return {
|
40 |
+
ws_protocol: protocol === "https:" ? "wss" : "ws",
|
41 |
+
http_protocol: protocol as "http:" | "https:",
|
42 |
+
host
|
43 |
+
};
|
44 |
+
} else if (endpoint.startsWith("file:")) {
|
45 |
+
// This case is only expected to be used for the Wasm mode (Gradio-lite),
|
46 |
+
// where users can create a local HTML file using it and open the page in a browser directly via the `file:` protocol.
|
47 |
+
return {
|
48 |
+
ws_protocol: "ws",
|
49 |
+
http_protocol: "http:",
|
50 |
+
host: "lite.local" // Special fake hostname only used for this case. This matches the hostname allowed in `is_self_host()` in `js/wasm/network/host.ts`.
|
51 |
+
};
|
52 |
+
}
|
53 |
+
|
54 |
+
// default to secure if no protocol is provided
|
55 |
+
return {
|
56 |
+
ws_protocol: "wss",
|
57 |
+
http_protocol: "https:",
|
58 |
+
host: endpoint
|
59 |
+
};
|
60 |
+
}
|
61 |
+
|
62 |
+
export const RE_SPACE_NAME = /^[^\/]*\/[^\/]*$/;
|
63 |
+
export const RE_SPACE_DOMAIN = /.*hf\.space\/{0,1}$/;
|
64 |
+
export async function process_endpoint(
|
65 |
+
app_reference: string,
|
66 |
+
token?: `hf_${string}`
|
67 |
+
): Promise<{
|
68 |
+
space_id: string | false;
|
69 |
+
host: string;
|
70 |
+
ws_protocol: "ws" | "wss";
|
71 |
+
http_protocol: "http:" | "https:";
|
72 |
+
}> {
|
73 |
+
const headers: { Authorization?: string } = {};
|
74 |
+
if (token) {
|
75 |
+
headers.Authorization = `Bearer ${token}`;
|
76 |
+
}
|
77 |
+
|
78 |
+
const _app_reference = app_reference.trim();
|
79 |
+
|
80 |
+
if (RE_SPACE_NAME.test(_app_reference)) {
|
81 |
+
try {
|
82 |
+
const res = await fetch(
|
83 |
+
`https://huggingface.co/api/spaces/${_app_reference}/host`,
|
84 |
+
{ headers }
|
85 |
+
);
|
86 |
+
|
87 |
+
if (res.status !== 200)
|
88 |
+
throw new Error("Space metadata could not be loaded.");
|
89 |
+
const _host = (await res.json()).host;
|
90 |
+
|
91 |
+
return {
|
92 |
+
space_id: app_reference,
|
93 |
+
...determine_protocol(_host)
|
94 |
+
};
|
95 |
+
} catch (e: any) {
|
96 |
+
throw new Error("Space metadata could not be loaded." + e.message);
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
if (RE_SPACE_DOMAIN.test(_app_reference)) {
|
101 |
+
const { ws_protocol, http_protocol, host } =
|
102 |
+
determine_protocol(_app_reference);
|
103 |
+
|
104 |
+
return {
|
105 |
+
space_id: host.replace(".hf.space", ""),
|
106 |
+
ws_protocol,
|
107 |
+
http_protocol,
|
108 |
+
host
|
109 |
+
};
|
110 |
+
}
|
111 |
+
|
112 |
+
return {
|
113 |
+
space_id: false,
|
114 |
+
...determine_protocol(_app_reference)
|
115 |
+
};
|
116 |
+
}
|
117 |
+
|
118 |
+
export function map_names_to_ids(
|
119 |
+
fns: Config["dependencies"]
|
120 |
+
): Record<string, number> {
|
121 |
+
let apis: Record<string, number> = {};
|
122 |
+
|
123 |
+
fns.forEach(({ api_name }, i) => {
|
124 |
+
if (api_name) apis[api_name] = i;
|
125 |
+
});
|
126 |
+
|
127 |
+
return apis;
|
128 |
+
}
|
129 |
+
|
130 |
+
const RE_DISABLED_DISCUSSION =
|
131 |
+
/^(?=[^]*\b[dD]iscussions{0,1}\b)(?=[^]*\b[dD]isabled\b)[^]*$/;
|
132 |
+
export async function discussions_enabled(space_id: string): Promise<boolean> {
|
133 |
+
try {
|
134 |
+
const r = await fetch(
|
135 |
+
`https://huggingface.co/api/spaces/${space_id}/discussions`,
|
136 |
+
{
|
137 |
+
method: "HEAD"
|
138 |
+
}
|
139 |
+
);
|
140 |
+
const error = r.headers.get("x-error-message");
|
141 |
+
|
142 |
+
if (error && RE_DISABLED_DISCUSSION.test(error)) return false;
|
143 |
+
return true;
|
144 |
+
} catch (e) {
|
145 |
+
return false;
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
export async function get_space_hardware(
|
150 |
+
space_id: string,
|
151 |
+
token: `hf_${string}`
|
152 |
+
): Promise<(typeof hardware_types)[number]> {
|
153 |
+
const headers: { Authorization?: string } = {};
|
154 |
+
if (token) {
|
155 |
+
headers.Authorization = `Bearer ${token}`;
|
156 |
+
}
|
157 |
+
|
158 |
+
try {
|
159 |
+
const res = await fetch(
|
160 |
+
`https://huggingface.co/api/spaces/${space_id}/runtime`,
|
161 |
+
{ headers }
|
162 |
+
);
|
163 |
+
|
164 |
+
if (res.status !== 200)
|
165 |
+
throw new Error("Space hardware could not be obtained.");
|
166 |
+
|
167 |
+
const { hardware } = await res.json();
|
168 |
+
|
169 |
+
return hardware;
|
170 |
+
} catch (e: any) {
|
171 |
+
throw new Error(e.message);
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
export async function set_space_hardware(
|
176 |
+
space_id: string,
|
177 |
+
new_hardware: (typeof hardware_types)[number],
|
178 |
+
token: `hf_${string}`
|
179 |
+
): Promise<(typeof hardware_types)[number]> {
|
180 |
+
const headers: { Authorization?: string } = {};
|
181 |
+
if (token) {
|
182 |
+
headers.Authorization = `Bearer ${token}`;
|
183 |
+
}
|
184 |
+
|
185 |
+
try {
|
186 |
+
const res = await fetch(
|
187 |
+
`https://huggingface.co/api/spaces/${space_id}/hardware`,
|
188 |
+
{ headers, body: JSON.stringify(new_hardware) }
|
189 |
+
);
|
190 |
+
|
191 |
+
if (res.status !== 200)
|
192 |
+
throw new Error(
|
193 |
+
"Space hardware could not be set. Please ensure the space hardware provided is valid and that a Hugging Face token is passed in."
|
194 |
+
);
|
195 |
+
|
196 |
+
const { hardware } = await res.json();
|
197 |
+
|
198 |
+
return hardware;
|
199 |
+
} catch (e: any) {
|
200 |
+
throw new Error(e.message);
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
export async function set_space_timeout(
|
205 |
+
space_id: string,
|
206 |
+
timeout: number,
|
207 |
+
token: `hf_${string}`
|
208 |
+
): Promise<number> {
|
209 |
+
const headers: { Authorization?: string } = {};
|
210 |
+
if (token) {
|
211 |
+
headers.Authorization = `Bearer ${token}`;
|
212 |
+
}
|
213 |
+
|
214 |
+
try {
|
215 |
+
const res = await fetch(
|
216 |
+
`https://huggingface.co/api/spaces/${space_id}/hardware`,
|
217 |
+
{ headers, body: JSON.stringify({ seconds: timeout }) }
|
218 |
+
);
|
219 |
+
|
220 |
+
if (res.status !== 200)
|
221 |
+
throw new Error(
|
222 |
+
"Space hardware could not be set. Please ensure the space hardware provided is valid and that a Hugging Face token is passed in."
|
223 |
+
);
|
224 |
+
|
225 |
+
const { hardware } = await res.json();
|
226 |
+
|
227 |
+
return hardware;
|
228 |
+
} catch (e: any) {
|
229 |
+
throw new Error(e.message);
|
230 |
+
}
|
231 |
+
}
|
232 |
+
|
233 |
+
export const hardware_types = [
|
234 |
+
"cpu-basic",
|
235 |
+
"cpu-upgrade",
|
236 |
+
"t4-small",
|
237 |
+
"t4-medium",
|
238 |
+
"a10g-small",
|
239 |
+
"a10g-large",
|
240 |
+
"a100-large"
|
241 |
+
] as const;
|
node_modules/@gradio/client/tsconfig.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"include": ["src/**/*"],
|
3 |
+
"exclude": ["src/**/*.test.ts", "src/**/*.node-test.ts"],
|
4 |
+
"compilerOptions": {
|
5 |
+
"allowJs": true,
|
6 |
+
"declaration": true,
|
7 |
+
"emitDeclarationOnly": true,
|
8 |
+
"outDir": "dist",
|
9 |
+
"declarationMap": true,
|
10 |
+
"module": "es2020",
|
11 |
+
"moduleResolution": "bundler",
|
12 |
+
"skipDefaultLibCheck": true
|
13 |
+
}
|
14 |
+
}
|
node_modules/@gradio/client/vite.config.js
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { defineConfig } from "vite";
|
2 |
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
3 |
+
import { fileURLToPath } from "url";
|
4 |
+
import path from "path";
|
5 |
+
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
6 |
+
|
7 |
+
export default defineConfig({
|
8 |
+
build: {
|
9 |
+
lib: {
|
10 |
+
entry: "src/index.ts",
|
11 |
+
formats: ["es"]
|
12 |
+
},
|
13 |
+
rollupOptions: {
|
14 |
+
input: "src/index.ts",
|
15 |
+
output: {
|
16 |
+
dir: "dist"
|
17 |
+
}
|
18 |
+
}
|
19 |
+
},
|
20 |
+
plugins: [
|
21 |
+
svelte()
|
22 |
+
// {
|
23 |
+
// name: "resolve-gradio-client",
|
24 |
+
// enforce: "pre",
|
25 |
+
// resolveId(id) {
|
26 |
+
// if (id === "@gradio/client") {
|
27 |
+
// return path.join(__dirname, "src", "index.ts");
|
28 |
+
// }
|
29 |
+
// }
|
30 |
+
// }
|
31 |
+
],
|
32 |
+
|
33 |
+
ssr: {
|
34 |
+
target: "node",
|
35 |
+
format: "esm",
|
36 |
+
noExternal: ["ws", "semiver", "@gradio/upload"]
|
37 |
+
}
|
38 |
+
});
|
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,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Emitter [![Build Status](https://travis-ci.org/component/emitter.png)](https://travis-ci.org/component/emitter)
|
2 |
+
|
3 |
+
Event emitter component.
|
4 |
+
|
5 |
+
## Installation
|
6 |
+
|
7 |
+
```
|
8 |
+
$ component install component/emitter
|
9 |
+
```
|
10 |
+
|
11 |
+
## API
|
12 |
+
|
13 |
+
### Emitter(obj)
|
14 |
+
|
15 |
+
The `Emitter` may also be used as a mixin. For example
|
16 |
+
a "plain" object may become an emitter, or you may
|
17 |
+
extend an existing prototype.
|
18 |
+
|
19 |
+
As an `Emitter` instance:
|
20 |
+
|
21 |
+
```js
|
22 |
+
var Emitter = require('emitter');
|
23 |
+
var emitter = new Emitter;
|
24 |
+
emitter.emit('something');
|
25 |
+
```
|
26 |
+
|
27 |
+
As a mixin:
|
28 |
+
|
29 |
+
```js
|
30 |
+
var Emitter = require('emitter');
|
31 |
+
var user = { name: 'tobi' };
|
32 |
+
Emitter(user);
|
33 |
+
|
34 |
+
user.emit('im a user');
|
35 |
+
```
|
36 |
+
|
37 |
+
As a prototype mixin:
|
38 |
+
|
39 |
+
```js
|
40 |
+
var Emitter = require('emitter');
|
41 |
+
Emitter(User.prototype);
|
42 |
+
```
|
43 |
+
|
44 |
+
### Emitter#on(event, fn)
|
45 |
+
|
46 |
+
Register an `event` handler `fn`.
|
47 |
+
|
48 |
+
### Emitter#once(event, fn)
|
49 |
+
|
50 |
+
Register a single-shot `event` handler `fn`,
|
51 |
+
removed immediately after it is invoked the
|
52 |
+
first time.
|
53 |
+
|
54 |
+
### Emitter#off(event, fn)
|
55 |
+
|
56 |
+
* Pass `event` and `fn` to remove a listener.
|
57 |
+
* Pass `event` to remove all listeners on that event.
|
58 |
+
* Pass nothing to remove all listeners on all events.
|
59 |
+
|
60 |
+
### Emitter#emit(event, ...)
|
61 |
+
|
62 |
+
Emit an `event` with variable option args.
|
63 |
+
|
64 |
+
### Emitter#listeners(event)
|
65 |
+
|
66 |
+
Return an array of callbacks, or an empty array.
|
67 |
+
|
68 |
+
### Emitter#hasListeners(event)
|
69 |
+
|
70 |
+
Check if this emitter has `event` handlers.
|
71 |
+
|
72 |
+
## License
|
73 |
+
|
74 |
+
MIT
|
node_modules/@socket.io/component-emitter/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/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/index.mjs
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/package.json
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@socket.io/component-emitter",
|
3 |
+
"description": "Event emitter",
|
4 |
+
"version": "3.1.0",
|
5 |
+
"license": "MIT",
|
6 |
+
"devDependencies": {
|
7 |
+
"mocha": "*",
|
8 |
+
"should": "*"
|
9 |
+
},
|
10 |
+
"component": {
|
11 |
+
"scripts": {
|
12 |
+
"emitter/index.js": "index.js"
|
13 |
+
}
|
14 |
+
},
|
15 |
+
"main": "index.js",
|
16 |
+
"module": "index.mjs",
|
17 |
+
"types": "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 |
+
"index.js",
|
27 |
+
"index.mjs",
|
28 |
+
"index.d.ts",
|
29 |
+
"LICENSE"
|
30 |
+
]
|
31 |
+
}
|
node_modules/@types/cookie/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/cookie/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Installation
|
2 |
+
> `npm install --save @types/cookie`
|
3 |
+
|
4 |
+
# Summary
|
5 |
+
This package contains type definitions for cookie (https://github.com/jshttp/cookie).
|
6 |
+
|
7 |
+
# Details
|
8 |
+
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cookie.
|
9 |
+
|
10 |
+
### Additional Details
|
11 |
+
* Last updated: Tue, 06 Jul 2021 20:32:30 GMT
|
12 |
+
* Dependencies: none
|
13 |
+
* Global values: none
|
14 |
+
|
15 |
+
# Credits
|
16 |
+
These definitions were written by [Pine Mizune](https://github.com/pine), and [Piotr Błażejewicz](https://github.com/peterblazejewicz).
|
node_modules/@types/cookie/index.d.ts
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Type definitions for cookie 0.4
|
2 |
+
// Project: https://github.com/jshttp/cookie
|
3 |
+
// Definitions by: Pine Mizune <https://github.com/pine>
|
4 |
+
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
5 |
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Basic HTTP cookie parser and serializer for HTTP servers.
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Additional serialization options
|
13 |
+
*/
|
14 |
+
export interface CookieSerializeOptions {
|
15 |
+
/**
|
16 |
+
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no
|
17 |
+
* domain is set, and most clients will consider the cookie to apply to only
|
18 |
+
* the current domain.
|
19 |
+
*/
|
20 |
+
domain?: string | undefined;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Specifies a function that will be used to encode a cookie's value. Since
|
24 |
+
* value of a cookie has a limited character set (and must be a simple
|
25 |
+
* string), this function can be used to encode a value into a string suited
|
26 |
+
* for a cookie's value.
|
27 |
+
*
|
28 |
+
* The default function is the global `encodeURIComponent`, which will
|
29 |
+
* encode a JavaScript string into UTF-8 byte sequences and then URL-encode
|
30 |
+
* any that fall outside of the cookie range.
|
31 |
+
*/
|
32 |
+
encode?(value: string): string;
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default,
|
36 |
+
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete
|
37 |
+
* it on a condition like exiting a web browser application.
|
38 |
+
*
|
39 |
+
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
|
40 |
+
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
41 |
+
* possible not all clients by obey this, so if both are set, they should
|
42 |
+
* point to the same date and time.
|
43 |
+
*/
|
44 |
+
expires?: Date | undefined;
|
45 |
+
/**
|
46 |
+
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}.
|
47 |
+
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By
|
48 |
+
* default, the `HttpOnly` attribute is not set.
|
49 |
+
*
|
50 |
+
* *Note* be careful when setting this to true, as compliant clients will
|
51 |
+
* not allow client-side JavaScript to see the cookie in `document.cookie`.
|
52 |
+
*/
|
53 |
+
httpOnly?: boolean | undefined;
|
54 |
+
/**
|
55 |
+
* Specifies the number (in seconds) to be the value for the `Max-Age`
|
56 |
+
* `Set-Cookie` attribute. The given number will be converted to an integer
|
57 |
+
* by rounding down. By default, no maximum age is set.
|
58 |
+
*
|
59 |
+
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
|
60 |
+
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
61 |
+
* possible not all clients by obey this, so if both are set, they should
|
62 |
+
* point to the same date and time.
|
63 |
+
*/
|
64 |
+
maxAge?: number | undefined;
|
65 |
+
/**
|
66 |
+
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}.
|
67 |
+
* By default, the path is considered the "default path".
|
68 |
+
*/
|
69 |
+
path?: string | undefined;
|
70 |
+
/**
|
71 |
+
* Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}.
|
72 |
+
*
|
73 |
+
* - `true` will set the `SameSite` attribute to `Strict` for strict same
|
74 |
+
* site enforcement.
|
75 |
+
* - `false` will not set the `SameSite` attribute.
|
76 |
+
* - `'lax'` will set the `SameSite` attribute to Lax for lax same site
|
77 |
+
* enforcement.
|
78 |
+
* - `'strict'` will set the `SameSite` attribute to Strict for strict same
|
79 |
+
* site enforcement.
|
80 |
+
* - `'none'` will set the SameSite attribute to None for an explicit
|
81 |
+
* cross-site cookie.
|
82 |
+
*
|
83 |
+
* More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}.
|
84 |
+
*
|
85 |
+
* *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
|
86 |
+
*/
|
87 |
+
sameSite?: true | false | 'lax' | 'strict' | 'none' | undefined;
|
88 |
+
/**
|
89 |
+
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the
|
90 |
+
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
|
91 |
+
*
|
92 |
+
* *Note* be careful when setting this to `true`, as compliant clients will
|
93 |
+
* not send the cookie back to the server in the future if the browser does
|
94 |
+
* not have an HTTPS connection.
|
95 |
+
*/
|
96 |
+
secure?: boolean | undefined;
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Additional parsing options
|
101 |
+
*/
|
102 |
+
export interface CookieParseOptions {
|
103 |
+
/**
|
104 |
+
* Specifies a function that will be used to decode a cookie's value. Since
|
105 |
+
* the value of a cookie has a limited character set (and must be a simple
|
106 |
+
* string), this function can be used to decode a previously-encoded cookie
|
107 |
+
* value into a JavaScript string or other object.
|
108 |
+
*
|
109 |
+
* The default function is the global `decodeURIComponent`, which will decode
|
110 |
+
* any URL-encoded sequences into their byte representations.
|
111 |
+
*
|
112 |
+
* *Note* if an error is thrown from this function, the original, non-decoded
|
113 |
+
* cookie value will be returned as the cookie's value.
|
114 |
+
*/
|
115 |
+
decode?(value: string): string;
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Parse an HTTP Cookie header string and returning an object of all cookie
|
120 |
+
* name-value pairs.
|
121 |
+
*
|
122 |
+
* @param str the string representing a `Cookie` header value
|
123 |
+
* @param [options] object containing parsing options
|
124 |
+
*/
|
125 |
+
export function parse(str: string, options?: CookieParseOptions): { [key: string]: string };
|
126 |
+
|
127 |
+
/**
|
128 |
+
* Serialize a cookie name-value pair into a `Set-Cookie` header string.
|
129 |
+
*
|
130 |
+
* @param name the name for the cookie
|
131 |
+
* @param value value to set the cookie to
|
132 |
+
* @param [options] object containing serialization options
|
133 |
+
* @throws {TypeError} when `maxAge` options is invalid
|
134 |
+
*/
|
135 |
+
export function serialize(name: string, value: string, options?: CookieSerializeOptions): string;
|
node_modules/@types/cookie/package.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@types/cookie",
|
3 |
+
"version": "0.4.1",
|
4 |
+
"description": "TypeScript definitions for cookie",
|
5 |
+
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cookie",
|
6 |
+
"license": "MIT",
|
7 |
+
"contributors": [
|
8 |
+
{
|
9 |
+
"name": "Pine Mizune",
|
10 |
+
"url": "https://github.com/pine",
|
11 |
+
"githubUsername": "pine"
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"name": "Piotr Błażejewicz",
|
15 |
+
"url": "https://github.com/peterblazejewicz",
|
16 |
+
"githubUsername": "peterblazejewicz"
|
17 |
+
}
|
18 |
+
],
|
19 |
+
"main": "",
|
20 |
+
"types": "index.d.ts",
|
21 |
+
"repository": {
|
22 |
+
"type": "git",
|
23 |
+
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
24 |
+
"directory": "types/cookie"
|
25 |
+
},
|
26 |
+
"scripts": {},
|
27 |
+
"dependencies": {},
|
28 |
+
"typesPublisherContentHash": "7d4a6dd505c896319459ae131b5fa8fc0a2ed25552db53dac87946119bb21559",
|
29 |
+
"typeScriptVersion": "3.6"
|
30 |
+
}
|
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: Mon, 20 Nov 2023 23:36:24 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), and [Gaurav Sharma](https://github.com/gtpan77).
|
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,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "@types/cors",
|
3 |
+
"version": "2.8.17",
|
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 |
+
"main": "",
|
20 |
+
"types": "index.d.ts",
|
21 |
+
"repository": {
|
22 |
+
"type": "git",
|
23 |
+
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
24 |
+
"directory": "types/cors"
|
25 |
+
},
|
26 |
+
"scripts": {},
|
27 |
+
"dependencies": {
|
28 |
+
"@types/node": "*"
|
29 |
+
},
|
30 |
+
"typesPublisherContentHash": "04d506dbb23d9e7a142bfb227d59c61102abec00fb40694bb64a8d9fe1f1a3a1",
|
31 |
+
"typeScriptVersion": "4.5"
|
32 |
+
}
|
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, 24 Jan 2024 06:08:24 GMT
|
12 |
+
* Dependencies: [undici-types](https://npmjs.com/package/undici-types)
|
13 |
+
|
14 |
+
# Credits
|
15 |
+
These definitions were written by [Microsoft TypeScript](https://github.com/Microsoft), [Alberto Schiabel](https://github.com/jkomyno), [Alvis HT Tang](https://github.com/alvis), [Andrew Makarov](https://github.com/r3nya), [Benjamin Toueg](https://github.com/btoueg), [Chigozirim C.](https://github.com/smac89), [David Junger](https://github.com/touffy), [Deividas Bakanas](https://github.com/DeividasBakanas), [Eugene Y. Q. Shen](https://github.com/eyqs), [Hannes Magnusson](https://github.com/Hannes-Magnusson-CK), [Huw](https://github.com/hoo29), [Kelvin Jin](https://github.com/kjin), [Klaus Meinhardt](https://github.com/ajafff), [Lishude](https://github.com/islishude), [Mariusz Wiktorczyk](https://github.com/mwiktorczyk), [Mohsen Azimi](https://github.com/mohsen1), [Nicolas Even](https://github.com/n-e), [Nikita Galkin](https://github.com/galkin), [Parambir Singh](https://github.com/parambirs), [Sebastian Silbermann](https://github.com/eps1lon), [Thomas den Hollander](https://github.com/ThomasdenH), [Wilco Bakker](https://github.com/WilcoBakker), [wwwy3y3](https://github.com/wwwy3y3), [Samuel Ainsworth](https://github.com/samuela), [Kyle Uehlein](https://github.com/kuehlein), [Thanik Bhongbhibhat](https://github.com/bhongy), [Marcin Kopacz](https://github.com/chyzwar), [Trivikram Kamat](https://github.com/trivikr), [Junxiao Shi](https://github.com/yoursunny), [Ilia Baryshnikov](https://github.com/qwelias), [ExE Boss](https://github.com/ExE-Boss), [Piotr Błażejewicz](https://github.com/peterblazejewicz), [Anna Henningsen](https://github.com/addaleax), [Victor Perin](https://github.com/victorperin), [Yongsheng Zhang](https://github.com/ZYSzys), [NodeJS Contributors](https://github.com/NodeJS), [Linus Unnebäck](https://github.com/LinusU), [wafuwafu13](https://github.com/wafuwafu13), [Matteo Collina](https://github.com/mcollina), and [Dmitry Semigradsky](https://github.com/Semigradsky).
|
node_modules/@types/node/assert.d.ts
ADDED
@@ -0,0 +1,996 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* The `node:assert` module provides a set of assertion functions for verifying
|
3 |
+
* invariants.
|
4 |
+
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/assert.js)
|
5 |
+
*/
|
6 |
+
declare module "assert" {
|
7 |
+
/**
|
8 |
+
* An alias of {@link ok}.
|
9 |
+
* @since v0.5.9
|
10 |
+
* @param value The input that is checked for being truthy.
|
11 |
+
*/
|
12 |
+
function assert(value: unknown, message?: string | Error): asserts value;
|
13 |
+
namespace assert {
|
14 |
+
/**
|
15 |
+
* Indicates the failure of an assertion. All errors thrown by the `node:assert`module will be instances of the `AssertionError` class.
|
16 |
+
*/
|
17 |
+
class AssertionError extends Error {
|
18 |
+
/**
|
19 |
+
* Set to the `actual` argument for methods such as {@link assert.strictEqual()}.
|
20 |
+
*/
|
21 |
+
actual: unknown;
|
22 |
+
/**
|
23 |
+
* Set to the `expected` argument for methods such as {@link assert.strictEqual()}.
|
24 |
+
*/
|
25 |
+
expected: unknown;
|
26 |
+
/**
|
27 |
+
* Set to the passed in operator value.
|
28 |
+
*/
|
29 |
+
operator: string;
|
30 |
+
/**
|
31 |
+
* Indicates if the message was auto-generated (`true`) or not.
|
32 |
+
*/
|
33 |
+
generatedMessage: boolean;
|
34 |
+
/**
|
35 |
+
* Value is always `ERR_ASSERTION` to show that the error is an assertion error.
|
36 |
+
*/
|
37 |
+
code: "ERR_ASSERTION";
|
38 |
+
constructor(options?: {
|
39 |
+
/** If provided, the error message is set to this value. */
|
40 |
+
message?: string | undefined;
|
41 |
+
/** The `actual` property on the error instance. */
|
42 |
+
actual?: unknown | undefined;
|
43 |
+
/** The `expected` property on the error instance. */
|
44 |
+
expected?: unknown | undefined;
|
45 |
+
/** The `operator` property on the error instance. */
|
46 |
+
operator?: string | undefined;
|
47 |
+
/** If provided, the generated stack trace omits frames before this function. */
|
48 |
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
49 |
+
stackStartFn?: Function | undefined;
|
50 |
+
});
|
51 |
+
}
|
52 |
+
/**
|
53 |
+
* This feature is deprecated and will be removed in a future version.
|
54 |
+
* Please consider using alternatives such as the `mock` helper function.
|
55 |
+
* @since v14.2.0, v12.19.0
|
56 |
+
* @deprecated Deprecated
|
57 |
+
*/
|
58 |
+
class CallTracker {
|
59 |
+
/**
|
60 |
+
* The wrapper function is expected to be called exactly `exact` times. If the
|
61 |
+
* function has not been called exactly `exact` times when `tracker.verify()` is called, then `tracker.verify()` will throw an
|
62 |
+
* error.
|
63 |
+
*
|
64 |
+
* ```js
|
65 |
+
* import assert from 'node:assert';
|
66 |
+
*
|
67 |
+
* // Creates call tracker.
|
68 |
+
* const tracker = new assert.CallTracker();
|
69 |
+
*
|
70 |
+
* function func() {}
|
71 |
+
*
|
72 |
+
* // Returns a function that wraps func() that must be called exact times
|
73 |
+
* // before tracker.verify().
|
74 |
+
* const callsfunc = tracker.calls(func);
|
75 |
+
* ```
|
76 |
+
* @since v14.2.0, v12.19.0
|
77 |
+
* @param [fn='A no-op function']
|
78 |
+
* @param [exact=1]
|
79 |
+
* @return that wraps `fn`.
|
80 |
+
*/
|
81 |
+
calls(exact?: number): () => void;
|
82 |
+
calls<Func extends (...args: any[]) => any>(fn?: Func, exact?: number): Func;
|
83 |
+
/**
|
84 |
+
* Example:
|
85 |
+
*
|
86 |
+
* ```js
|
87 |
+
* import assert from 'node:assert';
|
88 |
+
*
|
89 |
+
* const tracker = new assert.CallTracker();
|
90 |
+
*
|
91 |
+
* function func() {}
|
92 |
+
* const callsfunc = tracker.calls(func);
|
93 |
+
* callsfunc(1, 2, 3);
|
94 |
+
*
|
95 |
+
* assert.deepStrictEqual(tracker.getCalls(callsfunc),
|
96 |
+
* [{ thisArg: undefined, arguments: [1, 2, 3] }]);
|
97 |
+
* ```
|
98 |
+
* @since v18.8.0, v16.18.0
|
99 |
+
* @param fn
|
100 |
+
* @return An Array with all the calls to a tracked function.
|
101 |
+
*/
|
102 |
+
getCalls(fn: Function): CallTrackerCall[];
|
103 |
+
/**
|
104 |
+
* The arrays contains information about the expected and actual number of calls of
|
105 |
+
* the functions that have not been called the expected number of times.
|
106 |
+
*
|
107 |
+
* ```js
|
108 |
+
* import assert from 'node:assert';
|
109 |
+
*
|
110 |
+
* // Creates call tracker.
|
111 |
+
* const tracker = new assert.CallTracker();
|
112 |
+
*
|
113 |
+
* function func() {}
|
114 |
+
*
|
115 |
+
* // Returns a function that wraps func() that must be called exact times
|
116 |
+
* // before tracker.verify().
|
117 |
+
* const callsfunc = tracker.calls(func, 2);
|
118 |
+
*
|
119 |
+
* // Returns an array containing information on callsfunc()
|
120 |
+
* console.log(tracker.report());
|
121 |
+
* // [
|
122 |
+
* // {
|
123 |
+
* // message: 'Expected the func function to be executed 2 time(s) but was
|
124 |
+
* // executed 0 time(s).',
|
125 |
+
* // actual: 0,
|
126 |
+
* // expected: 2,
|
127 |
+
* // operator: 'func',
|
128 |
+
* // stack: stack trace
|
129 |
+
* // }
|
130 |
+
* // ]
|
131 |
+
* ```
|
132 |
+
* @since v14.2.0, v12.19.0
|
133 |
+
* @return An Array of objects containing information about the wrapper functions returned by `calls`.
|
134 |
+
*/
|
135 |
+
report(): CallTrackerReportInformation[];
|
136 |
+
/**
|
137 |
+
* Reset calls of the call tracker.
|
138 |
+
* If a tracked function is passed as an argument, the calls will be reset for it.
|
139 |
+
* If no arguments are passed, all tracked functions will be reset.
|
140 |
+
*
|
141 |
+
* ```js
|
142 |
+
* import assert from 'node:assert';
|
143 |
+
*
|
144 |
+
* const tracker = new assert.CallTracker();
|
145 |
+
*
|
146 |
+
* function func() {}
|
147 |
+
* const callsfunc = tracker.calls(func);
|
148 |
+
*
|
149 |
+
* callsfunc();
|
150 |
+
* // Tracker was called once
|
151 |
+
* assert.strictEqual(tracker.getCalls(callsfunc).length, 1);
|
152 |
+
*
|
153 |
+
* tracker.reset(callsfunc);
|
154 |
+
* assert.strictEqual(tracker.getCalls(callsfunc).length, 0);
|
155 |
+
* ```
|
156 |
+
* @since v18.8.0, v16.18.0
|
157 |
+
* @param fn a tracked function to reset.
|
158 |
+
*/
|
159 |
+
reset(fn?: Function): void;
|
160 |
+
/**
|
161 |
+
* Iterates through the list of functions passed to `tracker.calls()` and will throw an error for functions that
|
162 |
+
* have not been called the expected number of times.
|
163 |
+
*
|
164 |
+
* ```js
|
165 |
+
* import assert from 'node:assert';
|
166 |
+
*
|
167 |
+
* // Creates call tracker.
|
168 |
+
* const tracker = new assert.CallTracker();
|
169 |
+
*
|
170 |
+
* function func() {}
|
171 |
+
*
|
172 |
+
* // Returns a function that wraps func() that must be called exact times
|
173 |
+
* // before tracker.verify().
|
174 |
+
* const callsfunc = tracker.calls(func, 2);
|
175 |
+
*
|
176 |
+
* callsfunc();
|
177 |
+
*
|
178 |
+
* // Will throw an error since callsfunc() was only called once.
|
179 |
+
* tracker.verify();
|
180 |
+
* ```
|
181 |
+
* @since v14.2.0, v12.19.0
|
182 |
+
*/
|
183 |
+
verify(): void;
|
184 |
+
}
|
185 |
+
interface CallTrackerCall {
|
186 |
+
thisArg: object;
|
187 |
+
arguments: unknown[];
|
188 |
+
}
|
189 |
+
interface CallTrackerReportInformation {
|
190 |
+
message: string;
|
191 |
+
/** The actual number of times the function was called. */
|
192 |
+
actual: number;
|
193 |
+
/** The number of times the function was expected to be called. */
|
194 |
+
expected: number;
|
195 |
+
/** The name of the function that is wrapped. */
|
196 |
+
operator: string;
|
197 |
+
/** A stack trace of the function. */
|
198 |
+
stack: object;
|
199 |
+
}
|
200 |
+
type AssertPredicate = RegExp | (new() => object) | ((thrown: unknown) => boolean) | object | Error;
|
201 |
+
/**
|
202 |
+
* Throws an `AssertionError` with the provided error message or a default
|
203 |
+
* error message. If the `message` parameter is an instance of an `Error` then
|
204 |
+
* it will be thrown instead of the `AssertionError`.
|
205 |
+
*
|
206 |
+
* ```js
|
207 |
+
* import assert from 'node:assert/strict';
|
208 |
+
*
|
209 |
+
* assert.fail();
|
210 |
+
* // AssertionError [ERR_ASSERTION]: Failed
|
211 |
+
*
|
212 |
+
* assert.fail('boom');
|
213 |
+
* // AssertionError [ERR_ASSERTION]: boom
|
214 |
+
*
|
215 |
+
* assert.fail(new TypeError('need array'));
|
216 |
+
* // TypeError: need array
|
217 |
+
* ```
|
218 |
+
*
|
219 |
+
* Using `assert.fail()` with more than two arguments is possible but deprecated.
|
220 |
+
* See below for further details.
|
221 |
+
* @since v0.1.21
|
222 |
+
* @param [message='Failed']
|
223 |
+
*/
|
224 |
+
function fail(message?: string | Error): never;
|
225 |
+
/** @deprecated since v10.0.0 - use fail([message]) or other assert functions instead. */
|
226 |
+
function fail(
|
227 |
+
actual: unknown,
|
228 |
+
expected: unknown,
|
229 |
+
message?: string | Error,
|
230 |
+
operator?: string,
|
231 |
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
232 |
+
stackStartFn?: Function,
|
233 |
+
): never;
|
234 |
+
/**
|
235 |
+
* Tests if `value` is truthy. It is equivalent to`assert.equal(!!value, true, message)`.
|
236 |
+
*
|
237 |
+
* 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
|
238 |
+
* error message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
|
239 |
+
* If no arguments are passed in at all `message` will be set to the string:`` 'No value argument passed to `assert.ok()`' ``.
|
240 |
+
*
|
241 |
+
* Be aware that in the `repl` the error message will be different to the one
|
242 |
+
* thrown in a file! See below for further details.
|
243 |
+
*
|
244 |
+
* ```js
|
245 |
+
* import assert from 'node:assert/strict';
|
246 |
+
*
|
247 |
+
* assert.ok(true);
|
248 |
+
* // OK
|
249 |
+
* assert.ok(1);
|
250 |
+
* // OK
|
251 |
+
*
|
252 |
+
* assert.ok();
|
253 |
+
* // AssertionError: No value argument passed to `assert.ok()`
|
254 |
+
*
|
255 |
+
* assert.ok(false, 'it\'s false');
|
256 |
+
* // AssertionError: it's false
|
257 |
+
*
|
258 |
+
* // In the repl:
|
259 |
+
* assert.ok(typeof 123 === 'string');
|
260 |
+
* // AssertionError: false == true
|
261 |
+
*
|
262 |
+
* // In a file (e.g. test.js):
|
263 |
+
* assert.ok(typeof 123 === 'string');
|
264 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
265 |
+
* //
|
266 |
+
* // assert.ok(typeof 123 === 'string')
|
267 |
+
*
|
268 |
+
* assert.ok(false);
|
269 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
270 |
+
* //
|
271 |
+
* // assert.ok(false)
|
272 |
+
*
|
273 |
+
* assert.ok(0);
|
274 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
275 |
+
* //
|
276 |
+
* // assert.ok(0)
|
277 |
+
* ```
|
278 |
+
*
|
279 |
+
* ```js
|
280 |
+
* import assert from 'node:assert/strict';
|
281 |
+
*
|
282 |
+
* // Using `assert()` works the same:
|
283 |
+
* assert(0);
|
284 |
+
* // AssertionError: The expression evaluated to a falsy value:
|
285 |
+
* //
|
286 |
+
* // assert(0)
|
287 |
+
* ```
|
288 |
+
* @since v0.1.21
|
289 |
+
*/
|
290 |
+
function ok(value: unknown, message?: string | Error): asserts value;
|
291 |
+
/**
|
292 |
+
* **Strict assertion mode**
|
293 |
+
*
|
294 |
+
* An alias of {@link strictEqual}.
|
295 |
+
*
|
296 |
+
* **Legacy assertion mode**
|
297 |
+
*
|
298 |
+
* > Stability: 3 - Legacy: Use {@link strictEqual} instead.
|
299 |
+
*
|
300 |
+
* Tests shallow, coercive equality between the `actual` and `expected` parameters
|
301 |
+
* using the [`==` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality). `NaN` is specially handled
|
302 |
+
* and treated as being identical if both sides are `NaN`.
|
303 |
+
*
|
304 |
+
* ```js
|
305 |
+
* import assert from 'node:assert';
|
306 |
+
*
|
307 |
+
* assert.equal(1, 1);
|
308 |
+
* // OK, 1 == 1
|
309 |
+
* assert.equal(1, '1');
|
310 |
+
* // OK, 1 == '1'
|
311 |
+
* assert.equal(NaN, NaN);
|
312 |
+
* // OK
|
313 |
+
*
|
314 |
+
* assert.equal(1, 2);
|
315 |
+
* // AssertionError: 1 == 2
|
316 |
+
* assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
|
317 |
+
* // AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
|
318 |
+
* ```
|
319 |
+
*
|
320 |
+
* 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
|
321 |
+
* error message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
|
322 |
+
* @since v0.1.21
|
323 |
+
*/
|
324 |
+
function equal(actual: unknown, expected: unknown, message?: string | Error): void;
|
325 |
+
/**
|
326 |
+
* **Strict assertion mode**
|
327 |
+
*
|
328 |
+
* An alias of {@link notStrictEqual}.
|
329 |
+
*
|
330 |
+
* **Legacy assertion mode**
|
331 |
+
*
|
332 |
+
* > Stability: 3 - Legacy: Use {@link notStrictEqual} instead.
|
333 |
+
*
|
334 |
+
* Tests shallow, coercive inequality with the [`!=` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality). `NaN` is
|
335 |
+
* specially handled and treated as being identical if both sides are `NaN`.
|
336 |
+
*
|
337 |
+
* ```js
|
338 |
+
* import assert from 'node:assert';
|
339 |
+
*
|
340 |
+
* assert.notEqual(1, 2);
|
341 |
+
* // OK
|
342 |
+
*
|
343 |
+
* assert.notEqual(1, 1);
|
344 |
+
* // AssertionError: 1 != 1
|
345 |
+
*
|
346 |
+
* assert.notEqual(1, '1');
|
347 |
+
* // AssertionError: 1 != '1'
|
348 |
+
* ```
|
349 |
+
*
|
350 |
+
* 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
|
351 |
+
* message is assigned. If the `message`parameter is an instance of an `Error` then it will be thrown instead of the`AssertionError`.
|
352 |
+
* @since v0.1.21
|
353 |
+
*/
|
354 |
+
function notEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
355 |
+
/**
|
356 |
+
* **Strict assertion mode**
|
357 |
+
*
|
358 |
+
* An alias of {@link deepStrictEqual}.
|
359 |
+
*
|
360 |
+
* **Legacy assertion mode**
|
361 |
+
*
|
362 |
+
* > Stability: 3 - Legacy: Use {@link deepStrictEqual} instead.
|
363 |
+
*
|
364 |
+
* Tests for deep equality between the `actual` and `expected` parameters. Consider
|
365 |
+
* using {@link deepStrictEqual} instead. {@link deepEqual} can have
|
366 |
+
* surprising results.
|
367 |
+
*
|
368 |
+
* _Deep equality_ means that the enumerable "own" properties of child objects
|
369 |
+
* are also recursively evaluated by the following rules.
|
370 |
+
* @since v0.1.21
|
371 |
+
*/
|
372 |
+
function deepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
373 |
+
/**
|
374 |
+
* **Strict assertion mode**
|
375 |
+
*
|
376 |
+
* An alias of {@link notDeepStrictEqual}.
|
377 |
+
*
|
378 |
+
* **Legacy assertion mode**
|
379 |
+
*
|
380 |
+
* > Stability: 3 - Legacy: Use {@link notDeepStrictEqual} instead.
|
381 |
+
*
|
382 |
+
* Tests for any deep inequality. Opposite of {@link deepEqual}.
|
383 |
+
*
|
384 |
+
* ```js
|
385 |
+
* import assert from 'node:assert';
|
386 |
+
*
|
387 |
+
* const obj1 = {
|
388 |
+
* a: {
|
389 |
+
* b: 1,
|
390 |
+
* },
|
391 |
+
* };
|
392 |
+
* const obj2 = {
|
393 |
+
* a: {
|
394 |
+
* b: 2,
|
395 |
+
* },
|
396 |
+
* };
|
397 |
+
* const obj3 = {
|
398 |
+
* a: {
|
399 |
+
* b: 1,
|
400 |
+
* },
|
401 |
+
* };
|
402 |
+
* const obj4 = { __proto__: obj1 };
|
403 |
+
*
|
404 |
+
* assert.notDeepEqual(obj1, obj1);
|
405 |
+
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
406 |
+
*
|
407 |
+
* assert.notDeepEqual(obj1, obj2);
|
408 |
+
* // OK
|
409 |
+
*
|
410 |
+
* assert.notDeepEqual(obj1, obj3);
|
411 |
+
* // AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
412 |
+
*
|
413 |
+
* assert.notDeepEqual(obj1, obj4);
|
414 |
+
* // OK
|
415 |
+
* ```
|
416 |
+
*
|
417 |
+
* 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
|
418 |
+
* error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
|
419 |
+
* instead of the `AssertionError`.
|
420 |
+
* @since v0.1.21
|
421 |
+
*/
|
422 |
+
function notDeepEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
423 |
+
/**
|
424 |
+
* Tests strict equality between the `actual` and `expected` parameters as
|
425 |
+
* determined by [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
426 |
+
*
|
427 |
+
* ```js
|
428 |
+
* import assert from 'node:assert/strict';
|
429 |
+
*
|
430 |
+
* assert.strictEqual(1, 2);
|
431 |
+
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
432 |
+
* //
|
433 |
+
* // 1 !== 2
|
434 |
+
*
|
435 |
+
* assert.strictEqual(1, 1);
|
436 |
+
* // OK
|
437 |
+
*
|
438 |
+
* assert.strictEqual('Hello foobar', 'Hello World!');
|
439 |
+
* // AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
|
440 |
+
* // + actual - expected
|
441 |
+
* //
|
442 |
+
* // + 'Hello foobar'
|
443 |
+
* // - 'Hello World!'
|
444 |
+
* // ^
|
445 |
+
*
|
446 |
+
* const apples = 1;
|
447 |
+
* const oranges = 2;
|
448 |
+
* assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`);
|
449 |
+
* // AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2
|
450 |
+
*
|
451 |
+
* assert.strictEqual(1, '1', new TypeError('Inputs are not identical'));
|
452 |
+
* // TypeError: Inputs are not identical
|
453 |
+
* ```
|
454 |
+
*
|
455 |
+
* 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
|
456 |
+
* default error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
|
457 |
+
* instead of the `AssertionError`.
|
458 |
+
* @since v0.1.21
|
459 |
+
*/
|
460 |
+
function strictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
461 |
+
/**
|
462 |
+
* Tests strict inequality between the `actual` and `expected` parameters as
|
463 |
+
* determined by [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
|
464 |
+
*
|
465 |
+
* ```js
|
466 |
+
* import assert from 'node:assert/strict';
|
467 |
+
*
|
468 |
+
* assert.notStrictEqual(1, 2);
|
469 |
+
* // OK
|
470 |
+
*
|
471 |
+
* assert.notStrictEqual(1, 1);
|
472 |
+
* // AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to:
|
473 |
+
* //
|
474 |
+
* // 1
|
475 |
+
*
|
476 |
+
* assert.notStrictEqual(1, '1');
|
477 |
+
* // OK
|
478 |
+
* ```
|
479 |
+
*
|
480 |
+
* 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
|
481 |
+
* default error message is assigned. If the`message` parameter is an instance of an `Error` then it will be thrown
|
482 |
+
* instead of the `AssertionError`.
|
483 |
+
* @since v0.1.21
|
484 |
+
*/
|
485 |
+
function notStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
486 |
+
/**
|
487 |
+
* Tests for deep equality between the `actual` and `expected` parameters.
|
488 |
+
* "Deep" equality means that the enumerable "own" properties of child objects
|
489 |
+
* are recursively evaluated also by the following rules.
|
490 |
+
* @since v1.2.0
|
491 |
+
*/
|
492 |
+
function deepStrictEqual<T>(actual: unknown, expected: T, message?: string | Error): asserts actual is T;
|
493 |
+
/**
|
494 |
+
* Tests for deep strict inequality. Opposite of {@link deepStrictEqual}.
|
495 |
+
*
|
496 |
+
* ```js
|
497 |
+
* import assert from 'node:assert/strict';
|
498 |
+
*
|
499 |
+
* assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
|
500 |
+
* // OK
|
501 |
+
* ```
|
502 |
+
*
|
503 |
+
* If the values are deeply and strictly equal, an `AssertionError` is thrown
|
504 |
+
* with a `message` property set equal to the value of the `message` parameter. If
|
505 |
+
* the `message` parameter is undefined, a default error message is assigned. If
|
506 |
+
* the `message` parameter is an instance of an `Error` then it will be thrown
|
507 |
+
* instead of the `AssertionError`.
|
508 |
+
* @since v1.2.0
|
509 |
+
*/
|
510 |
+
function notDeepStrictEqual(actual: unknown, expected: unknown, message?: string | Error): void;
|
511 |
+
/**
|
512 |
+
* Expects the function `fn` to throw an error.
|
513 |
+
*
|
514 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
515 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
|
516 |
+
* a validation object where each property will be tested for strict deep equality,
|
517 |
+
* or an instance of error where each property will be tested for strict deep
|
518 |
+
* equality including the non-enumerable `message` and `name` properties. When
|
519 |
+
* using an object, it is also possible to use a regular expression, when
|
520 |
+
* validating against a string property. See below for examples.
|
521 |
+
*
|
522 |
+
* 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
|
523 |
+
* fails.
|
524 |
+
*
|
525 |
+
* Custom validation object/error instance:
|
526 |
+
*
|
527 |
+
* ```js
|
528 |
+
* import assert from 'node:assert/strict';
|
529 |
+
*
|
530 |
+
* const err = new TypeError('Wrong value');
|
531 |
+
* err.code = 404;
|
532 |
+
* err.foo = 'bar';
|
533 |
+
* err.info = {
|
534 |
+
* nested: true,
|
535 |
+
* baz: 'text',
|
536 |
+
* };
|
537 |
+
* err.reg = /abc/i;
|
538 |
+
*
|
539 |
+
* assert.throws(
|
540 |
+
* () => {
|
541 |
+
* throw err;
|
542 |
+
* },
|
543 |
+
* {
|
544 |
+
* name: 'TypeError',
|
545 |
+
* message: 'Wrong value',
|
546 |
+
* info: {
|
547 |
+
* nested: true,
|
548 |
+
* baz: 'text',
|
549 |
+
* },
|
550 |
+
* // Only properties on the validation object will be tested for.
|
551 |
+
* // Using nested objects requires all properties to be present. Otherwise
|
552 |
+
* // the validation is going to fail.
|
553 |
+
* },
|
554 |
+
* );
|
555 |
+
*
|
556 |
+
* // Using regular expressions to validate error properties:
|
557 |
+
* assert.throws(
|
558 |
+
* () => {
|
559 |
+
* throw err;
|
560 |
+
* },
|
561 |
+
* {
|
562 |
+
* // The `name` and `message` properties are strings and using regular
|
563 |
+
* // expressions on those will match against the string. If they fail, an
|
564 |
+
* // error is thrown.
|
565 |
+
* name: /^TypeError$/,
|
566 |
+
* message: /Wrong/,
|
567 |
+
* foo: 'bar',
|
568 |
+
* info: {
|
569 |
+
* nested: true,
|
570 |
+
* // It is not possible to use regular expressions for nested properties!
|
571 |
+
* baz: 'text',
|
572 |
+
* },
|
573 |
+
* // The `reg` property contains a regular expression and only if the
|
574 |
+
* // validation object contains an identical regular expression, it is going
|
575 |
+
* // to pass.
|
576 |
+
* reg: /abc/i,
|
577 |
+
* },
|
578 |
+
* );
|
579 |
+
*
|
580 |
+
* // Fails due to the different `message` and `name` properties:
|
581 |
+
* assert.throws(
|
582 |
+
* () => {
|
583 |
+
* const otherErr = new Error('Not found');
|
584 |
+
* // Copy all enumerable properties from `err` to `otherErr`.
|
585 |
+
* for (const [key, value] of Object.entries(err)) {
|
586 |
+
* otherErr[key] = value;
|
587 |
+
* }
|
588 |
+
* throw otherErr;
|
589 |
+
* },
|
590 |
+
* // The error's `message` and `name` properties will also be checked when using
|
591 |
+
* // an error as validation object.
|
592 |
+
* err,
|
593 |
+
* );
|
594 |
+
* ```
|
595 |
+
*
|
596 |
+
* Validate instanceof using constructor:
|
597 |
+
*
|
598 |
+
* ```js
|
599 |
+
* import assert from 'node:assert/strict';
|
600 |
+
*
|
601 |
+
* assert.throws(
|
602 |
+
* () => {
|
603 |
+
* throw new Error('Wrong value');
|
604 |
+
* },
|
605 |
+
* Error,
|
606 |
+
* );
|
607 |
+
* ```
|
608 |
+
*
|
609 |
+
* Validate error message using [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions):
|
610 |
+
*
|
611 |
+
* Using a regular expression runs `.toString` on the error object, and will
|
612 |
+
* therefore also include the error name.
|
613 |
+
*
|
614 |
+
* ```js
|
615 |
+
* import assert from 'node:assert/strict';
|
616 |
+
*
|
617 |
+
* assert.throws(
|
618 |
+
* () => {
|
619 |
+
* throw new Error('Wrong value');
|
620 |
+
* },
|
621 |
+
* /^Error: Wrong value$/,
|
622 |
+
* );
|
623 |
+
* ```
|
624 |
+
*
|
625 |
+
* Custom error validation:
|
626 |
+
*
|
627 |
+
* The function must return `true` to indicate all internal validations passed.
|
628 |
+
* It will otherwise fail with an `AssertionError`.
|
629 |
+
*
|
630 |
+
* ```js
|
631 |
+
* import assert from 'node:assert/strict';
|
632 |
+
*
|
633 |
+
* assert.throws(
|
634 |
+
* () => {
|
635 |
+
* throw new Error('Wrong value');
|
636 |
+
* },
|
637 |
+
* (err) => {
|
638 |
+
* assert(err instanceof Error);
|
639 |
+
* assert(/value/.test(err));
|
640 |
+
* // Avoid returning anything from validation functions besides `true`.
|
641 |
+
* // Otherwise, it's not clear what part of the validation failed. Instead,
|
642 |
+
* // throw an error about the specific validation that failed (as done in this
|
643 |
+
* // example) and add as much helpful debugging information to that error as
|
644 |
+
* // possible.
|
645 |
+
* return true;
|
646 |
+
* },
|
647 |
+
* 'unexpected error',
|
648 |
+
* );
|
649 |
+
* ```
|
650 |
+
*
|
651 |
+
* `error` cannot be a string. If a string is provided as the second
|
652 |
+
* 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
|
653 |
+
* message as the thrown error message is going to result in an`ERR_AMBIGUOUS_ARGUMENT` error. Please read the example below carefully if using
|
654 |
+
* a string as the second argument gets considered:
|
655 |
+
*
|
656 |
+
* ```js
|
657 |
+
* import assert from 'node:assert/strict';
|
658 |
+
*
|
659 |
+
* function throwingFirst() {
|
660 |
+
* throw new Error('First');
|
661 |
+
* }
|
662 |
+
*
|
663 |
+
* function throwingSecond() {
|
664 |
+
* throw new Error('Second');
|
665 |
+
* }
|
666 |
+
*
|
667 |
+
* function notThrowing() {}
|
668 |
+
*
|
669 |
+
* // The second argument is a string and the input function threw an Error.
|
670 |
+
* // The first case will not throw as it does not match for the error message
|
671 |
+
* // thrown by the input function!
|
672 |
+
* assert.throws(throwingFirst, 'Second');
|
673 |
+
* // In the next example the message has no benefit over the message from the
|
674 |
+
* // error and since it is not clear if the user intended to actually match
|
675 |
+
* // against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.
|
676 |
+
* assert.throws(throwingSecond, 'Second');
|
677 |
+
* // TypeError [ERR_AMBIGUOUS_ARGUMENT]
|
678 |
+
*
|
679 |
+
* // The string is only used (as message) in case the function does not throw:
|
680 |
+
* assert.throws(notThrowing, 'Second');
|
681 |
+
* // AssertionError [ERR_ASSERTION]: Missing expected exception: Second
|
682 |
+
*
|
683 |
+
* // If it was intended to match for the error message do this instead:
|
684 |
+
* // It does not throw because the error messages match.
|
685 |
+
* assert.throws(throwingSecond, /Second$/);
|
686 |
+
*
|
687 |
+
* // If the error message does not match, an AssertionError is thrown.
|
688 |
+
* assert.throws(throwingFirst, /Second$/);
|
689 |
+
* // AssertionError [ERR_ASSERTION]
|
690 |
+
* ```
|
691 |
+
*
|
692 |
+
* Due to the confusing error-prone notation, avoid a string as the second
|
693 |
+
* argument.
|
694 |
+
* @since v0.1.21
|
695 |
+
*/
|
696 |
+
function throws(block: () => unknown, message?: string | Error): void;
|
697 |
+
function throws(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
|
698 |
+
/**
|
699 |
+
* Asserts that the function `fn` does not throw an error.
|
700 |
+
*
|
701 |
+
* Using `assert.doesNotThrow()` is actually not useful because there
|
702 |
+
* is no benefit in catching an error and then rethrowing it. Instead, consider
|
703 |
+
* adding a comment next to the specific code path that should not throw and keep
|
704 |
+
* error messages as expressive as possible.
|
705 |
+
*
|
706 |
+
* When `assert.doesNotThrow()` is called, it will immediately call the `fn`function.
|
707 |
+
*
|
708 |
+
* 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
|
709 |
+
* different type, or if the `error` parameter is undefined, the error is
|
710 |
+
* propagated back to the caller.
|
711 |
+
*
|
712 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
713 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), or a validation
|
714 |
+
* function. See {@link throws} for more details.
|
715 |
+
*
|
716 |
+
* The following, for instance, will throw the `TypeError` because there is no
|
717 |
+
* matching error type in the assertion:
|
718 |
+
*
|
719 |
+
* ```js
|
720 |
+
* import assert from 'node:assert/strict';
|
721 |
+
*
|
722 |
+
* assert.doesNotThrow(
|
723 |
+
* () => {
|
724 |
+
* throw new TypeError('Wrong value');
|
725 |
+
* },
|
726 |
+
* SyntaxError,
|
727 |
+
* );
|
728 |
+
* ```
|
729 |
+
*
|
730 |
+
* However, the following will result in an `AssertionError` with the message
|
731 |
+
* 'Got unwanted exception...':
|
732 |
+
*
|
733 |
+
* ```js
|
734 |
+
* import assert from 'node:assert/strict';
|
735 |
+
*
|
736 |
+
* assert.doesNotThrow(
|
737 |
+
* () => {
|
738 |
+
* throw new TypeError('Wrong value');
|
739 |
+
* },
|
740 |
+
* TypeError,
|
741 |
+
* );
|
742 |
+
* ```
|
743 |
+
*
|
744 |
+
* 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:
|
745 |
+
*
|
746 |
+
* ```js
|
747 |
+
* import assert from 'node:assert/strict';
|
748 |
+
*
|
749 |
+
* assert.doesNotThrow(
|
750 |
+
* () => {
|
751 |
+
* throw new TypeError('Wrong value');
|
752 |
+
* },
|
753 |
+
* /Wrong value/,
|
754 |
+
* 'Whoops',
|
755 |
+
* );
|
756 |
+
* // Throws: AssertionError: Got unwanted exception: Whoops
|
757 |
+
* ```
|
758 |
+
* @since v0.1.21
|
759 |
+
*/
|
760 |
+
function doesNotThrow(block: () => unknown, message?: string | Error): void;
|
761 |
+
function doesNotThrow(block: () => unknown, error: AssertPredicate, message?: string | Error): void;
|
762 |
+
/**
|
763 |
+
* Throws `value` if `value` is not `undefined` or `null`. This is useful when
|
764 |
+
* testing the `error` argument in callbacks. The stack trace contains all frames
|
765 |
+
* from the error passed to `ifError()` including the potential new frames for`ifError()` itself.
|
766 |
+
*
|
767 |
+
* ```js
|
768 |
+
* import assert from 'node:assert/strict';
|
769 |
+
*
|
770 |
+
* assert.ifError(null);
|
771 |
+
* // OK
|
772 |
+
* assert.ifError(0);
|
773 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0
|
774 |
+
* assert.ifError('error');
|
775 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'
|
776 |
+
* assert.ifError(new Error());
|
777 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error
|
778 |
+
*
|
779 |
+
* // Create some random error frames.
|
780 |
+
* let err;
|
781 |
+
* (function errorFrame() {
|
782 |
+
* err = new Error('test error');
|
783 |
+
* })();
|
784 |
+
*
|
785 |
+
* (function ifErrorFrame() {
|
786 |
+
* assert.ifError(err);
|
787 |
+
* })();
|
788 |
+
* // AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error
|
789 |
+
* // at ifErrorFrame
|
790 |
+
* // at errorFrame
|
791 |
+
* ```
|
792 |
+
* @since v0.1.97
|
793 |
+
*/
|
794 |
+
function ifError(value: unknown): asserts value is null | undefined;
|
795 |
+
/**
|
796 |
+
* Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
|
797 |
+
* calls the function and awaits the returned promise to complete. It will then
|
798 |
+
* check that the promise is rejected.
|
799 |
+
*
|
800 |
+
* If `asyncFn` is a function and it throws an error synchronously,`assert.rejects()` will return a rejected `Promise` with that error. If the
|
801 |
+
* function does not return a promise, `assert.rejects()` will return a rejected`Promise` with an `ERR_INVALID_RETURN_VALUE` error. In both cases the error
|
802 |
+
* handler is skipped.
|
803 |
+
*
|
804 |
+
* Besides the async nature to await the completion behaves identically to {@link throws}.
|
805 |
+
*
|
806 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
807 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), a validation function,
|
808 |
+
* an object where each property will be tested for, or an instance of error where
|
809 |
+
* each property will be tested for including the non-enumerable `message` and`name` properties.
|
810 |
+
*
|
811 |
+
* If specified, `message` will be the message provided by the `AssertionError` if the `asyncFn` fails to reject.
|
812 |
+
*
|
813 |
+
* ```js
|
814 |
+
* import assert from 'node:assert/strict';
|
815 |
+
*
|
816 |
+
* await assert.rejects(
|
817 |
+
* async () => {
|
818 |
+
* throw new TypeError('Wrong value');
|
819 |
+
* },
|
820 |
+
* {
|
821 |
+
* name: 'TypeError',
|
822 |
+
* message: 'Wrong value',
|
823 |
+
* },
|
824 |
+
* );
|
825 |
+
* ```
|
826 |
+
*
|
827 |
+
* ```js
|
828 |
+
* import assert from 'node:assert/strict';
|
829 |
+
*
|
830 |
+
* await assert.rejects(
|
831 |
+
* async () => {
|
832 |
+
* throw new TypeError('Wrong value');
|
833 |
+
* },
|
834 |
+
* (err) => {
|
835 |
+
* assert.strictEqual(err.name, 'TypeError');
|
836 |
+
* assert.strictEqual(err.message, 'Wrong value');
|
837 |
+
* return true;
|
838 |
+
* },
|
839 |
+
* );
|
840 |
+
* ```
|
841 |
+
*
|
842 |
+
* ```js
|
843 |
+
* import assert from 'node:assert/strict';
|
844 |
+
*
|
845 |
+
* assert.rejects(
|
846 |
+
* Promise.reject(new Error('Wrong value')),
|
847 |
+
* Error,
|
848 |
+
* ).then(() => {
|
849 |
+
* // ...
|
850 |
+
* });
|
851 |
+
* ```
|
852 |
+
*
|
853 |
+
* `error` cannot be a string. If a string is provided as the second
|
854 |
+
* 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. Please read the
|
855 |
+
* example in {@link throws} carefully if using a string as the second
|
856 |
+
* argument gets considered.
|
857 |
+
* @since v10.0.0
|
858 |
+
*/
|
859 |
+
function rejects(block: (() => Promise<unknown>) | Promise<unknown>, message?: string | Error): Promise<void>;
|
860 |
+
function rejects(
|
861 |
+
block: (() => Promise<unknown>) | Promise<unknown>,
|
862 |
+
error: AssertPredicate,
|
863 |
+
message?: string | Error,
|
864 |
+
): Promise<void>;
|
865 |
+
/**
|
866 |
+
* Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately
|
867 |
+
* calls the function and awaits the returned promise to complete. It will then
|
868 |
+
* check that the promise is not rejected.
|
869 |
+
*
|
870 |
+
* If `asyncFn` is a function and it throws an error synchronously,`assert.doesNotReject()` will return a rejected `Promise` with that error. If
|
871 |
+
* the function does not return a promise, `assert.doesNotReject()` will return a
|
872 |
+
* rejected `Promise` with an `ERR_INVALID_RETURN_VALUE` error. In both cases
|
873 |
+
* the error handler is skipped.
|
874 |
+
*
|
875 |
+
* Using `assert.doesNotReject()` is actually not useful because there is little
|
876 |
+
* benefit in catching a rejection and then rejecting it again. Instead, consider
|
877 |
+
* adding a comment next to the specific code path that should not reject and keep
|
878 |
+
* error messages as expressive as possible.
|
879 |
+
*
|
880 |
+
* If specified, `error` can be a [`Class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes),
|
881 |
+
* [`RegExp`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions), or a validation
|
882 |
+
* function. See {@link throws} for more details.
|
883 |
+
*
|
884 |
+
* Besides the async nature to await the completion behaves identically to {@link doesNotThrow}.
|
885 |
+
*
|
886 |
+
* ```js
|
887 |
+
* import assert from 'node:assert/strict';
|
888 |
+
*
|
889 |
+
* await assert.doesNotReject(
|
890 |
+
* async () => {
|
891 |
+
* throw new TypeError('Wrong value');
|
892 |
+
* },
|
893 |
+
* SyntaxError,
|
894 |
+
* );
|
895 |
+
* ```
|
896 |
+
*
|
897 |
+
* ```js
|
898 |
+
* import assert from 'node:assert/strict';
|
899 |
+
*
|
900 |
+
* assert.doesNotReject(Promise.reject(new TypeError('Wrong value')))
|
901 |
+
* .then(() => {
|
902 |
+
* // ...
|
903 |
+
* });
|
904 |
+
* ```
|
905 |
+
* @since v10.0.0
|
906 |
+
*/
|
907 |
+
function doesNotReject(
|
908 |
+
block: (() => Promise<unknown>) | Promise<unknown>,
|
909 |
+
message?: string | Error,
|
910 |
+
): Promise<void>;
|
911 |
+
function doesNotReject(
|
912 |
+
block: (() => Promise<unknown>) | Promise<unknown>,
|
913 |
+
error: AssertPredicate,
|
914 |
+
message?: string | Error,
|
915 |
+
): Promise<void>;
|
916 |
+
/**
|
917 |
+
* Expects the `string` input to match the regular expression.
|
918 |
+
*
|
919 |
+
* ```js
|
920 |
+
* import assert from 'node:assert/strict';
|
921 |
+
*
|
922 |
+
* assert.match('I will fail', /pass/);
|
923 |
+
* // AssertionError [ERR_ASSERTION]: The input did not match the regular ...
|
924 |
+
*
|
925 |
+
* assert.match(123, /pass/);
|
926 |
+
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
927 |
+
*
|
928 |
+
* assert.match('I will pass', /pass/);
|
929 |
+
* // OK
|
930 |
+
* ```
|
931 |
+
*
|
932 |
+
* If the values do not match, or if the `string` argument is of another type than`string`, an `AssertionError` is thrown with a `message` property set equal
|
933 |
+
* to the value of the `message` parameter. If the `message` parameter is
|
934 |
+
* undefined, a default error message is assigned. If the `message` parameter is an
|
935 |
+
* instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
936 |
+
* @since v13.6.0, v12.16.0
|
937 |
+
*/
|
938 |
+
function match(value: string, regExp: RegExp, message?: string | Error): void;
|
939 |
+
/**
|
940 |
+
* Expects the `string` input not to match the regular expression.
|
941 |
+
*
|
942 |
+
* ```js
|
943 |
+
* import assert from 'node:assert/strict';
|
944 |
+
*
|
945 |
+
* assert.doesNotMatch('I will fail', /fail/);
|
946 |
+
* // AssertionError [ERR_ASSERTION]: The input was expected to not match the ...
|
947 |
+
*
|
948 |
+
* assert.doesNotMatch(123, /pass/);
|
949 |
+
* // AssertionError [ERR_ASSERTION]: The "string" argument must be of type string.
|
950 |
+
*
|
951 |
+
* assert.doesNotMatch('I will pass', /different/);
|
952 |
+
* // OK
|
953 |
+
* ```
|
954 |
+
*
|
955 |
+
* If the values do match, or if the `string` argument is of another type than`string`, an `AssertionError` is thrown with a `message` property set equal
|
956 |
+
* to the value of the `message` parameter. If the `message` parameter is
|
957 |
+
* undefined, a default error message is assigned. If the `message` parameter is an
|
958 |
+
* instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
959 |
+
* @since v13.6.0, v12.16.0
|
960 |
+
*/
|
961 |
+
function doesNotMatch(value: string, regExp: RegExp, message?: string | Error): void;
|
962 |
+
const strict:
|
963 |
+
& Omit<
|
964 |
+
typeof assert,
|
965 |
+
| "equal"
|
966 |
+
| "notEqual"
|
967 |
+
| "deepEqual"
|
968 |
+
| "notDeepEqual"
|
969 |
+
| "ok"
|
970 |
+
| "strictEqual"
|
971 |
+
| "deepStrictEqual"
|
972 |
+
| "ifError"
|
973 |
+
| "strict"
|
974 |
+
>
|
975 |
+
& {
|
976 |
+
(value: unknown, message?: string | Error): asserts value;
|
977 |
+
equal: typeof strictEqual;
|
978 |
+
notEqual: typeof notStrictEqual;
|
979 |
+
deepEqual: typeof deepStrictEqual;
|
980 |
+
notDeepEqual: typeof notDeepStrictEqual;
|
981 |
+
// Mapped types and assertion functions are incompatible?
|
982 |
+
// TS2775: Assertions require every name in the call target
|
983 |
+
// to be declared with an explicit type annotation.
|
984 |
+
ok: typeof ok;
|
985 |
+
strictEqual: typeof strictEqual;
|
986 |
+
deepStrictEqual: typeof deepStrictEqual;
|
987 |
+
ifError: typeof ifError;
|
988 |
+
strict: typeof strict;
|
989 |
+
};
|
990 |
+
}
|
991 |
+
export = assert;
|
992 |
+
}
|
993 |
+
declare module "node:assert" {
|
994 |
+
import assert = require("assert");
|
995 |
+
export = assert;
|
996 |
+
}
|
node_modules/@types/node/assert/strict.d.ts
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
declare module "assert/strict" {
|
2 |
+
import { strict } from "node:assert";
|
3 |
+
export = strict;
|
4 |
+
}
|
5 |
+
declare module "node:assert/strict" {
|
6 |
+
import { strict } from "node:assert";
|
7 |
+
export = strict;
|
8 |
+
}
|
node_modules/@types/node/async_hooks.d.ts
ADDED
@@ -0,0 +1,539 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* We strongly discourage the use of the `async_hooks` API.
|
3 |
+
* Other APIs that can cover most of its use cases include:
|
4 |
+
*
|
5 |
+
* * `AsyncLocalStorage` tracks async context
|
6 |
+
* * `process.getActiveResourcesInfo()` tracks active resources
|
7 |
+
*
|
8 |
+
* The `node:async_hooks` module provides an API to track asynchronous resources.
|
9 |
+
* It can be accessed using:
|
10 |
+
*
|
11 |
+
* ```js
|
12 |
+
* import async_hooks from 'node:async_hooks';
|
13 |
+
* ```
|
14 |
+
* @experimental
|
15 |
+
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/async_hooks.js)
|
16 |
+
*/
|
17 |
+
declare module "async_hooks" {
|
18 |
+
/**
|
19 |
+
* ```js
|
20 |
+
* import { executionAsyncId } from 'node:async_hooks';
|
21 |
+
* import fs from 'node:fs';
|
22 |
+
*
|
23 |
+
* console.log(executionAsyncId()); // 1 - bootstrap
|
24 |
+
* const path = '.';
|
25 |
+
* fs.open(path, 'r', (err, fd) => {
|
26 |
+
* console.log(executionAsyncId()); // 6 - open()
|
27 |
+
* });
|
28 |
+
* ```
|
29 |
+
*
|
30 |
+
* The ID returned from `executionAsyncId()` is related to execution timing, not
|
31 |
+
* causality (which is covered by `triggerAsyncId()`):
|
32 |
+
*
|
33 |
+
* ```js
|
34 |
+
* const server = net.createServer((conn) => {
|
35 |
+
* // Returns the ID of the server, not of the new connection, because the
|
36 |
+
* // callback runs in the execution scope of the server's MakeCallback().
|
37 |
+
* async_hooks.executionAsyncId();
|
38 |
+
*
|
39 |
+
* }).listen(port, () => {
|
40 |
+
* // Returns the ID of a TickObject (process.nextTick()) because all
|
41 |
+
* // callbacks passed to .listen() are wrapped in a nextTick().
|
42 |
+
* async_hooks.executionAsyncId();
|
43 |
+
* });
|
44 |
+
* ```
|
45 |
+
*
|
46 |
+
* Promise contexts may not get precise `executionAsyncIds` by default.
|
47 |
+
* See the section on `promise execution tracking`.
|
48 |
+
* @since v8.1.0
|
49 |
+
* @return The `asyncId` of the current execution context. Useful to track when something calls.
|
50 |
+
*/
|
51 |
+
function executionAsyncId(): number;
|
52 |
+
/**
|
53 |
+
* Resource objects returned by `executionAsyncResource()` are most often internal
|
54 |
+
* Node.js handle objects with undocumented APIs. Using any functions or properties
|
55 |
+
* on the object is likely to crash your application and should be avoided.
|
56 |
+
*
|
57 |
+
* Using `executionAsyncResource()` in the top-level execution context will
|
58 |
+
* return an empty object as there is no handle or request object to use,
|
59 |
+
* but having an object representing the top-level can be helpful.
|
60 |
+
*
|
61 |
+
* ```js
|
62 |
+
* import { open } from 'node:fs';
|
63 |
+
* import { executionAsyncId, executionAsyncResource } from 'node:async_hooks';
|
64 |
+
*
|
65 |
+
* console.log(executionAsyncId(), executionAsyncResource()); // 1 {}
|
66 |
+
* open(new URL(import.meta.url), 'r', (err, fd) => {
|
67 |
+
* console.log(executionAsyncId(), executionAsyncResource()); // 7 FSReqWrap
|
68 |
+
* });
|
69 |
+
* ```
|
70 |
+
*
|
71 |
+
* This can be used to implement continuation local storage without the
|
72 |
+
* use of a tracking `Map` to store the metadata:
|
73 |
+
*
|
74 |
+
* ```js
|
75 |
+
* import { createServer } from 'node:http';
|
76 |
+
* import {
|
77 |
+
* executionAsyncId,
|
78 |
+
* executionAsyncResource,
|
79 |
+
* createHook,
|
80 |
+
* } from 'async_hooks';
|
81 |
+
* const sym = Symbol('state'); // Private symbol to avoid pollution
|
82 |
+
*
|
83 |
+
* createHook({
|
84 |
+
* init(asyncId, type, triggerAsyncId, resource) {
|
85 |
+
* const cr = executionAsyncResource();
|
86 |
+
* if (cr) {
|
87 |
+
* resource[sym] = cr[sym];
|
88 |
+
* }
|
89 |
+
* },
|
90 |
+
* }).enable();
|
91 |
+
*
|
92 |
+
* const server = createServer((req, res) => {
|
93 |
+
* executionAsyncResource()[sym] = { state: req.url };
|
94 |
+
* setTimeout(function() {
|
95 |
+
* res.end(JSON.stringify(executionAsyncResource()[sym]));
|
96 |
+
* }, 100);
|
97 |
+
* }).listen(3000);
|
98 |
+
* ```
|
99 |
+
* @since v13.9.0, v12.17.0
|
100 |
+
* @return The resource representing the current execution. Useful to store data within the resource.
|
101 |
+
*/
|
102 |
+
function executionAsyncResource(): object;
|
103 |
+
/**
|
104 |
+
* ```js
|
105 |
+
* const server = net.createServer((conn) => {
|
106 |
+
* // The resource that caused (or triggered) this callback to be called
|
107 |
+
* // was that of the new connection. Thus the return value of triggerAsyncId()
|
108 |
+
* // is the asyncId of "conn".
|
109 |
+
* async_hooks.triggerAsyncId();
|
110 |
+
*
|
111 |
+
* }).listen(port, () => {
|
112 |
+
* // Even though all callbacks passed to .listen() are wrapped in a nextTick()
|
113 |
+
* // the callback itself exists because the call to the server's .listen()
|
114 |
+
* // was made. So the return value would be the ID of the server.
|
115 |
+
* async_hooks.triggerAsyncId();
|
116 |
+
* });
|
117 |
+
* ```
|
118 |
+
*
|
119 |
+
* Promise contexts may not get valid `triggerAsyncId`s by default. See
|
120 |
+
* the section on `promise execution tracking`.
|
121 |
+
* @return The ID of the resource responsible for calling the callback that is currently being executed.
|
122 |
+
*/
|
123 |
+
function triggerAsyncId(): number;
|
124 |
+
interface HookCallbacks {
|
125 |
+
/**
|
126 |
+
* Called when a class is constructed that has the possibility to emit an asynchronous event.
|
127 |
+
* @param asyncId a unique ID for the async resource
|
128 |
+
* @param type the type of the async resource
|
129 |
+
* @param triggerAsyncId the unique ID of the async resource in whose execution context this async resource was created
|
130 |
+
* @param resource reference to the resource representing the async operation, needs to be released during destroy
|
131 |
+
*/
|
132 |
+
init?(asyncId: number, type: string, triggerAsyncId: number, resource: object): void;
|
133 |
+
/**
|
134 |
+
* When an asynchronous operation is initiated or completes a callback is called to notify the user.
|
135 |
+
* The before callback is called just before said callback is executed.
|
136 |
+
* @param asyncId the unique identifier assigned to the resource about to execute the callback.
|
137 |
+
*/
|
138 |
+
before?(asyncId: number): void;
|
139 |
+
/**
|
140 |
+
* Called immediately after the callback specified in before is completed.
|
141 |
+
* @param asyncId the unique identifier assigned to the resource which has executed the callback.
|
142 |
+
*/
|
143 |
+
after?(asyncId: number): void;
|
144 |
+
/**
|
145 |
+
* Called when a promise has resolve() called. This may not be in the same execution id
|
146 |
+
* as the promise itself.
|
147 |
+
* @param asyncId the unique id for the promise that was resolve()d.
|
148 |
+
*/
|
149 |
+
promiseResolve?(asyncId: number): void;
|
150 |
+
/**
|
151 |
+
* Called after the resource corresponding to asyncId is destroyed
|
152 |
+
* @param asyncId a unique ID for the async resource
|
153 |
+
*/
|
154 |
+
destroy?(asyncId: number): void;
|
155 |
+
}
|
156 |
+
interface AsyncHook {
|
157 |
+
/**
|
158 |
+
* Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
|
159 |
+
*/
|
160 |
+
enable(): this;
|
161 |
+
/**
|
162 |
+
* 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.
|
163 |
+
*/
|
164 |
+
disable(): this;
|
165 |
+
}
|
166 |
+
/**
|
167 |
+
* Registers functions to be called for different lifetime events of each async
|
168 |
+
* operation.
|
169 |
+
*
|
170 |
+
* The callbacks `init()`/`before()`/`after()`/`destroy()` are called for the
|
171 |
+
* respective asynchronous event during a resource's lifetime.
|
172 |
+
*
|
173 |
+
* All callbacks are optional. For example, if only resource cleanup needs to
|
174 |
+
* be tracked, then only the `destroy` callback needs to be passed. The
|
175 |
+
* specifics of all functions that can be passed to `callbacks` is in the `Hook Callbacks` section.
|
176 |
+
*
|
177 |
+
* ```js
|
178 |
+
* import { createHook } from 'node:async_hooks';
|
179 |
+
*
|
180 |
+
* const asyncHook = createHook({
|
181 |
+
* init(asyncId, type, triggerAsyncId, resource) { },
|
182 |
+
* destroy(asyncId) { },
|
183 |
+
* });
|
184 |
+
* ```
|
185 |
+
*
|
186 |
+
* The callbacks will be inherited via the prototype chain:
|
187 |
+
*
|
188 |
+
* ```js
|
189 |
+
* class MyAsyncCallbacks {
|
190 |
+
* init(asyncId, type, triggerAsyncId, resource) { }
|
191 |
+
* destroy(asyncId) {}
|
192 |
+
* }
|
193 |
+
*
|
194 |
+
* class MyAddedCallbacks extends MyAsyncCallbacks {
|
195 |
+
* before(asyncId) { }
|
196 |
+
* after(asyncId) { }
|
197 |
+
* }
|
198 |
+
*
|
199 |
+
* const asyncHook = async_hooks.createHook(new MyAddedCallbacks());
|
200 |
+
* ```
|
201 |
+
*
|
202 |
+
* Because promises are asynchronous resources whose lifecycle is tracked
|
203 |
+
* via the async hooks mechanism, the `init()`, `before()`, `after()`, and`destroy()` callbacks _must not_ be async functions that return promises.
|
204 |
+
* @since v8.1.0
|
205 |
+
* @param callbacks The `Hook Callbacks` to register
|
206 |
+
* @return Instance used for disabling and enabling hooks
|
207 |
+
*/
|
208 |
+
function createHook(callbacks: HookCallbacks): AsyncHook;
|
209 |
+
interface AsyncResourceOptions {
|
210 |
+
/**
|
211 |
+
* The ID of the execution context that created this async event.
|
212 |
+
* @default executionAsyncId()
|
213 |
+
*/
|
214 |
+
triggerAsyncId?: number | undefined;
|
215 |
+
/**
|
216 |
+
* Disables automatic `emitDestroy` when the object is garbage collected.
|
217 |
+
* This usually does not need to be set (even if `emitDestroy` is called
|
218 |
+
* manually), unless the resource's `asyncId` is retrieved and the
|
219 |
+
* sensitive API's `emitDestroy` is called with it.
|
220 |
+
* @default false
|
221 |
+
*/
|
222 |
+
requireManualDestroy?: boolean | undefined;
|
223 |
+
}
|
224 |
+
/**
|
225 |
+
* The class `AsyncResource` is designed to be extended by the embedder's async
|
226 |
+
* resources. Using this, users can easily trigger the lifetime events of their
|
227 |
+
* own resources.
|
228 |
+
*
|
229 |
+
* The `init` hook will trigger when an `AsyncResource` is instantiated.
|
230 |
+
*
|
231 |
+
* The following is an overview of the `AsyncResource` API.
|
232 |
+
*
|
233 |
+
* ```js
|
234 |
+
* import { AsyncResource, executionAsyncId } from 'node:async_hooks';
|
235 |
+
*
|
236 |
+
* // AsyncResource() is meant to be extended. Instantiating a
|
237 |
+
* // new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
238 |
+
* // async_hook.executionAsyncId() is used.
|
239 |
+
* const asyncResource = new AsyncResource(
|
240 |
+
* type, { triggerAsyncId: executionAsyncId(), requireManualDestroy: false },
|
241 |
+
* );
|
242 |
+
*
|
243 |
+
* // Run a function in the execution context of the resource. This will
|
244 |
+
* // * establish the context of the resource
|
245 |
+
* // * trigger the AsyncHooks before callbacks
|
246 |
+
* // * call the provided function `fn` with the supplied arguments
|
247 |
+
* // * trigger the AsyncHooks after callbacks
|
248 |
+
* // * restore the original execution context
|
249 |
+
* asyncResource.runInAsyncScope(fn, thisArg, ...args);
|
250 |
+
*
|
251 |
+
* // Call AsyncHooks destroy callbacks.
|
252 |
+
* asyncResource.emitDestroy();
|
253 |
+
*
|
254 |
+
* // Return the unique ID assigned to the AsyncResource instance.
|
255 |
+
* asyncResource.asyncId();
|
256 |
+
*
|
257 |
+
* // Return the trigger ID for the AsyncResource instance.
|
258 |
+
* asyncResource.triggerAsyncId();
|
259 |
+
* ```
|
260 |
+
*/
|
261 |
+
class AsyncResource {
|
262 |
+
/**
|
263 |
+
* AsyncResource() is meant to be extended. Instantiating a
|
264 |
+
* new AsyncResource() also triggers init. If triggerAsyncId is omitted then
|
265 |
+
* async_hook.executionAsyncId() is used.
|
266 |
+
* @param type The type of async event.
|
267 |
+
* @param triggerAsyncId The ID of the execution context that created
|
268 |
+
* this async event (default: `executionAsyncId()`), or an
|
269 |
+
* AsyncResourceOptions object (since v9.3.0)
|
270 |
+
*/
|
271 |
+
constructor(type: string, triggerAsyncId?: number | AsyncResourceOptions);
|
272 |
+
/**
|
273 |
+
* Binds the given function to the current execution context.
|
274 |
+
* @since v14.8.0, v12.19.0
|
275 |
+
* @param fn The function to bind to the current execution context.
|
276 |
+
* @param type An optional name to associate with the underlying `AsyncResource`.
|
277 |
+
*/
|
278 |
+
static bind<Func extends (this: ThisArg, ...args: any[]) => any, ThisArg>(
|
279 |
+
fn: Func,
|
280 |
+
type?: string,
|
281 |
+
thisArg?: ThisArg,
|
282 |
+
): Func;
|
283 |
+
/**
|
284 |
+
* Binds the given function to execute to this `AsyncResource`'s scope.
|
285 |
+
* @since v14.8.0, v12.19.0
|
286 |
+
* @param fn The function to bind to the current `AsyncResource`.
|
287 |
+
*/
|
288 |
+
bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
289 |
+
/**
|
290 |
+
* Call the provided function with the provided arguments in the execution context
|
291 |
+
* of the async resource. This will establish the context, trigger the AsyncHooks
|
292 |
+
* before callbacks, call the function, trigger the AsyncHooks after callbacks, and
|
293 |
+
* then restore the original execution context.
|
294 |
+
* @since v9.6.0
|
295 |
+
* @param fn The function to call in the execution context of this async resource.
|
296 |
+
* @param thisArg The receiver to be used for the function call.
|
297 |
+
* @param args Optional arguments to pass to the function.
|
298 |
+
*/
|
299 |
+
runInAsyncScope<This, Result>(
|
300 |
+
fn: (this: This, ...args: any[]) => Result,
|
301 |
+
thisArg?: This,
|
302 |
+
...args: any[]
|
303 |
+
): Result;
|
304 |
+
/**
|
305 |
+
* Call all `destroy` hooks. This should only ever be called once. An error will
|
306 |
+
* be thrown if it is called more than once. This **must** be manually called. If
|
307 |
+
* the resource is left to be collected by the GC then the `destroy` hooks will
|
308 |
+
* never be called.
|
309 |
+
* @return A reference to `asyncResource`.
|
310 |
+
*/
|
311 |
+
emitDestroy(): this;
|
312 |
+
/**
|
313 |
+
* @return The unique `asyncId` assigned to the resource.
|
314 |
+
*/
|
315 |
+
asyncId(): number;
|
316 |
+
/**
|
317 |
+
* @return The same `triggerAsyncId` that is passed to the `AsyncResource` constructor.
|
318 |
+
*/
|
319 |
+
triggerAsyncId(): number;
|
320 |
+
}
|
321 |
+
/**
|
322 |
+
* This class creates stores that stay coherent through asynchronous operations.
|
323 |
+
*
|
324 |
+
* 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
|
325 |
+
* safe implementation that involves significant optimizations that are non-obvious
|
326 |
+
* to implement.
|
327 |
+
*
|
328 |
+
* The following example uses `AsyncLocalStorage` to build a simple logger
|
329 |
+
* that assigns IDs to incoming HTTP requests and includes them in messages
|
330 |
+
* logged within each request.
|
331 |
+
*
|
332 |
+
* ```js
|
333 |
+
* import http from 'node:http';
|
334 |
+
* import { AsyncLocalStorage } from 'node:async_hooks';
|
335 |
+
*
|
336 |
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
337 |
+
*
|
338 |
+
* function logWithId(msg) {
|
339 |
+
* const id = asyncLocalStorage.getStore();
|
340 |
+
* console.log(`${id !== undefined ? id : '-'}:`, msg);
|
341 |
+
* }
|
342 |
+
*
|
343 |
+
* let idSeq = 0;
|
344 |
+
* http.createServer((req, res) => {
|
345 |
+
* asyncLocalStorage.run(idSeq++, () => {
|
346 |
+
* logWithId('start');
|
347 |
+
* // Imagine any chain of async operations here
|
348 |
+
* setImmediate(() => {
|
349 |
+
* logWithId('finish');
|
350 |
+
* res.end();
|
351 |
+
* });
|
352 |
+
* });
|
353 |
+
* }).listen(8080);
|
354 |
+
*
|
355 |
+
* http.get('http://localhost:8080');
|
356 |
+
* http.get('http://localhost:8080');
|
357 |
+
* // Prints:
|
358 |
+
* // 0: start
|
359 |
+
* // 1: start
|
360 |
+
* // 0: finish
|
361 |
+
* // 1: finish
|
362 |
+
* ```
|
363 |
+
*
|
364 |
+
* Each instance of `AsyncLocalStorage` maintains an independent storage context.
|
365 |
+
* Multiple instances can safely exist simultaneously without risk of interfering
|
366 |
+
* with each other's data.
|
367 |
+
* @since v13.10.0, v12.17.0
|
368 |
+
*/
|
369 |
+
class AsyncLocalStorage<T> {
|
370 |
+
/**
|
371 |
+
* Binds the given function to the current execution context.
|
372 |
+
* @since v19.8.0
|
373 |
+
* @experimental
|
374 |
+
* @param fn The function to bind to the current execution context.
|
375 |
+
* @return A new function that calls `fn` within the captured execution context.
|
376 |
+
*/
|
377 |
+
static bind<Func extends (...args: any[]) => any>(fn: Func): Func;
|
378 |
+
/**
|
379 |
+
* Captures the current execution context and returns a function that accepts a
|
380 |
+
* function as an argument. Whenever the returned function is called, it
|
381 |
+
* calls the function passed to it within the captured context.
|
382 |
+
*
|
383 |
+
* ```js
|
384 |
+
* const asyncLocalStorage = new AsyncLocalStorage();
|
385 |
+
* const runInAsyncScope = asyncLocalStorage.run(123, () => AsyncLocalStorage.snapshot());
|
386 |
+
* const result = asyncLocalStorage.run(321, () => runInAsyncScope(() => asyncLocalStorage.getStore()));
|
387 |
+
* console.log(result); // returns 123
|
388 |
+
* ```
|
389 |
+
*
|
390 |
+
* AsyncLocalStorage.snapshot() can replace the use of AsyncResource for simple
|
391 |
+
* async context tracking purposes, for example:
|
392 |
+
*
|
393 |
+
* ```js
|
394 |
+
* class Foo {
|
395 |
+
* #runInAsyncScope = AsyncLocalStorage.snapshot();
|
396 |
+
*
|
397 |
+
* get() { return this.#runInAsyncScope(() => asyncLocalStorage.getStore()); }
|
398 |
+
* }
|
399 |
+
*
|
400 |
+
* const foo = asyncLocalStorage.run(123, () => new Foo());
|
401 |
+
* console.log(asyncLocalStorage.run(321, () => foo.get())); // returns 123
|
402 |
+
* ```
|
403 |
+
* @since v19.8.0
|
404 |
+
* @experimental
|
405 |
+
* @return A new function with the signature `(fn: (...args) : R, ...args) : R`.
|
406 |
+
*/
|
407 |
+
static snapshot(): <R, TArgs extends any[]>(fn: (...args: TArgs) => R, ...args: TArgs) => R;
|
408 |
+
/**
|
409 |
+
* Disables the instance of `AsyncLocalStorage`. All subsequent calls
|
410 |
+
* to `asyncLocalStorage.getStore()` will return `undefined` until`asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()` is called again.
|
411 |
+
*
|
412 |
+
* When calling `asyncLocalStorage.disable()`, all current contexts linked to the
|
413 |
+
* instance will be exited.
|
414 |
+
*
|
415 |
+
* Calling `asyncLocalStorage.disable()` is required before the`asyncLocalStorage` can be garbage collected. This does not apply to stores
|
416 |
+
* provided by the `asyncLocalStorage`, as those objects are garbage collected
|
417 |
+
* along with the corresponding async resources.
|
418 |
+
*
|
419 |
+
* Use this method when the `asyncLocalStorage` is not in use anymore
|
420 |
+
* in the current process.
|
421 |
+
* @since v13.10.0, v12.17.0
|
422 |
+
* @experimental
|
423 |
+
*/
|
424 |
+
disable(): void;
|
425 |
+
/**
|
426 |
+
* Returns the current store.
|
427 |
+
* If called outside of an asynchronous context initialized by
|
428 |
+
* calling `asyncLocalStorage.run()` or `asyncLocalStorage.enterWith()`, it
|
429 |
+
* returns `undefined`.
|
430 |
+
* @since v13.10.0, v12.17.0
|
431 |
+
*/
|
432 |
+
getStore(): T | undefined;
|
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 |
+
* Transitions into the context for the remainder of the current
|
496 |
+
* synchronous execution and then persists the store through any following
|
497 |
+
* asynchronous calls.
|
498 |
+
*
|
499 |
+
* Example:
|
500 |
+
*
|
501 |
+
* ```js
|
502 |
+
* const store = { id: 1 };
|
503 |
+
* // Replaces previous store with the given store object
|
504 |
+
* asyncLocalStorage.enterWith(store);
|
505 |
+
* asyncLocalStorage.getStore(); // Returns the store object
|
506 |
+
* someAsyncOperation(() => {
|
507 |
+
* asyncLocalStorage.getStore(); // Returns the same object
|
508 |
+
* });
|
509 |
+
* ```
|
510 |
+
*
|
511 |
+
* This transition will continue for the _entire_ synchronous execution.
|
512 |
+
* This means that if, for example, the context is entered within an event
|
513 |
+
* handler subsequent event handlers will also run within that context unless
|
514 |
+
* specifically bound to another context with an `AsyncResource`. That is why`run()` should be preferred over `enterWith()` unless there are strong reasons
|
515 |
+
* to use the latter method.
|
516 |
+
*
|
517 |
+
* ```js
|
518 |
+
* const store = { id: 1 };
|
519 |
+
*
|
520 |
+
* emitter.on('my-event', () => {
|
521 |
+
* asyncLocalStorage.enterWith(store);
|
522 |
+
* });
|
523 |
+
* emitter.on('my-event', () => {
|
524 |
+
* asyncLocalStorage.getStore(); // Returns the same object
|
525 |
+
* });
|
526 |
+
*
|
527 |
+
* asyncLocalStorage.getStore(); // Returns undefined
|
528 |
+
* emitter.emit('my-event');
|
529 |
+
* asyncLocalStorage.getStore(); // Returns the same object
|
530 |
+
* ```
|
531 |
+
* @since v13.11.0, v12.17.0
|
532 |
+
* @experimental
|
533 |
+
*/
|
534 |
+
enterWith(store: T): void;
|
535 |
+
}
|
536 |
+
}
|
537 |
+
declare module "node:async_hooks" {
|
538 |
+
export * from "async_hooks";
|
539 |
+
}
|
node_modules/@types/node/buffer.d.ts
ADDED
The diff for this file is too large to render.
See raw diff
|
|
node_modules/@types/node/child_process.d.ts
ADDED
@@ -0,0 +1,1540 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* The `node:child_process` module provides the ability to spawn subprocesses in
|
3 |
+
* a manner that is similar, but not identical, to [`popen(3)`](http://man7.org/linux/man-pages/man3/popen.3.html). This capability
|
4 |
+
* is primarily provided by the {@link spawn} function:
|
5 |
+
*
|
6 |
+
* ```js
|
7 |
+
* const { spawn } = require('node:child_process');
|
8 |
+
* const ls = spawn('ls', ['-lh', '/usr']);
|
9 |
+
*
|
10 |
+
* ls.stdout.on('data', (data) => {
|
11 |
+
* console.log(`stdout: ${data}`);
|
12 |
+
* });
|
13 |
+
*
|
14 |
+
* ls.stderr.on('data', (data) => {
|
15 |
+
* console.error(`stderr: ${data}`);
|
16 |
+
* });
|
17 |
+
*
|
18 |
+
* ls.on('close', (code) => {
|
19 |
+
* console.log(`child process exited with code ${code}`);
|
20 |
+
* });
|
21 |
+
* ```
|
22 |
+
*
|
23 |
+
* By default, pipes for `stdin`, `stdout`, and `stderr` are established between
|
24 |
+
* the parent Node.js process and the spawned subprocess. These pipes have
|
25 |
+
* limited (and platform-specific) capacity. If the subprocess writes to
|
26 |
+
* stdout in excess of that limit without the output being captured, the
|
27 |
+
* subprocess blocks waiting for the pipe buffer to accept more data. This is
|
28 |
+
* identical to the behavior of pipes in the shell. Use the `{ stdio: 'ignore' }`option if the output will not be consumed.
|
29 |
+
*
|
30 |
+
* The command lookup is performed using the `options.env.PATH` environment
|
31 |
+
* variable if `env` is in the `options` object. Otherwise, `process.env.PATH` is
|
32 |
+
* used. If `options.env` is set without `PATH`, lookup on Unix is performed
|
33 |
+
* on a default search path search of `/usr/bin:/bin` (see your operating system's
|
34 |
+
* manual for execvpe/execvp), on Windows the current processes environment
|
35 |
+
* variable `PATH` is used.
|
36 |
+
*
|
37 |
+
* On Windows, environment variables are case-insensitive. Node.js
|
38 |
+
* lexicographically sorts the `env` keys and uses the first one that
|
39 |
+
* case-insensitively matches. Only first (in lexicographic order) entry will be
|
40 |
+
* passed to the subprocess. This might lead to issues on Windows when passing
|
41 |
+
* objects to the `env` option that have multiple variants of the same key, such as`PATH` and `Path`.
|
42 |
+
*
|
43 |
+
* The {@link spawn} method spawns the child process asynchronously,
|
44 |
+
* without blocking the Node.js event loop. The {@link spawnSync} function provides equivalent functionality in a synchronous manner that blocks
|
45 |
+
* the event loop until the spawned process either exits or is terminated.
|
46 |
+
*
|
47 |
+
* For convenience, the `node:child_process` module provides a handful of
|
48 |
+
* synchronous and asynchronous alternatives to {@link spawn} and {@link spawnSync}. Each of these alternatives are implemented on
|
49 |
+
* top of {@link spawn} or {@link spawnSync}.
|
50 |
+
*
|
51 |
+
* * {@link exec}: spawns a shell and runs a command within that
|
52 |
+
* shell, passing the `stdout` and `stderr` to a callback function when
|
53 |
+
* complete.
|
54 |
+
* * {@link execFile}: similar to {@link exec} except
|
55 |
+
* that it spawns the command directly without first spawning a shell by
|
56 |
+
* default.
|
57 |
+
* * {@link fork}: spawns a new Node.js process and invokes a
|
58 |
+
* specified module with an IPC communication channel established that allows
|
59 |
+
* sending messages between parent and child.
|
60 |
+
* * {@link execSync}: a synchronous version of {@link exec} that will block the Node.js event loop.
|
61 |
+
* * {@link execFileSync}: a synchronous version of {@link execFile} that will block the Node.js event loop.
|
62 |
+
*
|
63 |
+
* For certain use cases, such as automating shell scripts, the `synchronous counterparts` may be more convenient. In many cases, however,
|
64 |
+
* the synchronous methods can have significant impact on performance due to
|
65 |
+
* stalling the event loop while spawned processes complete.
|
66 |
+
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/child_process.js)
|
67 |
+
*/
|
68 |
+
declare module "child_process" {
|
69 |
+
import { ObjectEncodingOptions } from "node:fs";
|
70 |
+
import { Abortable, EventEmitter } from "node:events";
|
71 |
+
import * as net from "node:net";
|
72 |
+
import { Pipe, Readable, Stream, Writable } from "node:stream";
|
73 |
+
import { URL } from "node:url";
|
74 |
+
type Serializable = string | object | number | boolean | bigint;
|
75 |
+
type SendHandle = net.Socket | net.Server;
|
76 |
+
/**
|
77 |
+
* Instances of the `ChildProcess` represent spawned child processes.
|
78 |
+
*
|
79 |
+
* Instances of `ChildProcess` are not intended to be created directly. Rather,
|
80 |
+
* use the {@link spawn}, {@link exec},{@link execFile}, or {@link fork} methods to create
|
81 |
+
* instances of `ChildProcess`.
|
82 |
+
* @since v2.2.0
|
83 |
+
*/
|
84 |
+
class ChildProcess extends EventEmitter {
|
85 |
+
/**
|
86 |
+
* A `Writable Stream` that represents the child process's `stdin`.
|
87 |
+
*
|
88 |
+
* If a child process waits to read all of its input, the child will not continue
|
89 |
+
* until this stream has been closed via `end()`.
|
90 |
+
*
|
91 |
+
* If the child was spawned with `stdio[0]` set to anything other than `'pipe'`,
|
92 |
+
* then this will be `null`.
|
93 |
+
*
|
94 |
+
* `subprocess.stdin` is an alias for `subprocess.stdio[0]`. Both properties will
|
95 |
+
* refer to the same value.
|
96 |
+
*
|
97 |
+
* The `subprocess.stdin` property can be `null` or `undefined`if the child process could not be successfully spawned.
|
98 |
+
* @since v0.1.90
|
99 |
+
*/
|
100 |
+
stdin: Writable | null;
|
101 |
+
/**
|
102 |
+
* A `Readable Stream` that represents the child process's `stdout`.
|
103 |
+
*
|
104 |
+
* If the child was spawned with `stdio[1]` set to anything other than `'pipe'`,
|
105 |
+
* then this will be `null`.
|
106 |
+
*
|
107 |
+
* `subprocess.stdout` is an alias for `subprocess.stdio[1]`. Both properties will
|
108 |
+
* refer to the same value.
|
109 |
+
*
|
110 |
+
* ```js
|
111 |
+
* const { spawn } = require('node:child_process');
|
112 |
+
*
|
113 |
+
* const subprocess = spawn('ls');
|
114 |
+
*
|
115 |
+
* subprocess.stdout.on('data', (data) => {
|
116 |
+
* console.log(`Received chunk ${data}`);
|
117 |
+
* });
|
118 |
+
* ```
|
119 |
+
*
|
120 |
+
* The `subprocess.stdout` property can be `null` or `undefined`if the child process could not be successfully spawned.
|
121 |
+
* @since v0.1.90
|
122 |
+
*/
|
123 |
+
stdout: Readable | null;
|
124 |
+
/**
|
125 |
+
* A `Readable Stream` that represents the child process's `stderr`.
|
126 |
+
*
|
127 |
+
* If the child was spawned with `stdio[2]` set to anything other than `'pipe'`,
|
128 |
+
* then this will be `null`.
|
129 |
+
*
|
130 |
+
* `subprocess.stderr` is an alias for `subprocess.stdio[2]`. Both properties will
|
131 |
+
* refer to the same value.
|
132 |
+
*
|
133 |
+
* The `subprocess.stderr` property can be `null` or `undefined`if the child process could not be successfully spawned.
|
134 |
+
* @since v0.1.90
|
135 |
+
*/
|
136 |
+
stderr: Readable | null;
|
137 |
+
/**
|
138 |
+
* The `subprocess.channel` property is a reference to the child's IPC channel. If
|
139 |
+
* no IPC channel exists, this property is `undefined`.
|
140 |
+
* @since v7.1.0
|
141 |
+
*/
|
142 |
+
readonly channel?: Pipe | null | undefined;
|
143 |
+
/**
|
144 |
+
* A sparse array of pipes to the child process, corresponding with positions in
|
145 |
+
* the `stdio` option passed to {@link spawn} that have been set
|
146 |
+
* 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`,
|
147 |
+
* respectively.
|
148 |
+
*
|
149 |
+
* In the following example, only the child's fd `1` (stdout) is configured as a
|
150 |
+
* pipe, so only the parent's `subprocess.stdio[1]` is a stream, all other values
|
151 |
+
* in the array are `null`.
|
152 |
+
*
|
153 |
+
* ```js
|
154 |
+
* const assert = require('node:assert');
|
155 |
+
* const fs = require('node:fs');
|
156 |
+
* const child_process = require('node:child_process');
|
157 |
+
*
|
158 |
+
* const subprocess = child_process.spawn('ls', {
|
159 |
+
* stdio: [
|
160 |
+
* 0, // Use parent's stdin for child.
|
161 |
+
* 'pipe', // Pipe child's stdout to parent.
|
162 |
+
* fs.openSync('err.out', 'w'), // Direct child's stderr to a file.
|
163 |
+
* ],
|
164 |
+
* });
|
165 |
+
*
|
166 |
+
* assert.strictEqual(subprocess.stdio[0], null);
|
167 |
+
* assert.strictEqual(subprocess.stdio[0], subprocess.stdin);
|
168 |
+
*
|
169 |
+
* assert(subprocess.stdout);
|
170 |
+
* assert.strictEqual(subprocess.stdio[1], subprocess.stdout);
|
171 |
+
*
|
172 |
+
* assert.strictEqual(subprocess.stdio[2], null);
|
173 |
+
* assert.strictEqual(subprocess.stdio[2], subprocess.stderr);
|
174 |
+
* ```
|
175 |
+
*
|
176 |
+
* The `subprocess.stdio` property can be `undefined` if the child process could
|
177 |
+
* not be successfully spawned.
|
178 |
+
* @since v0.7.10
|
179 |
+
*/
|
180 |
+
readonly stdio: [
|
181 |
+
Writable | null,
|
182 |
+
// stdin
|
183 |
+
Readable | null,
|
184 |
+
// stdout
|
185 |
+
Readable | null,
|
186 |
+
// stderr
|
187 |
+
Readable | Writable | null | undefined,
|
188 |
+
// extra
|
189 |
+
Readable | Writable | null | undefined, // extra
|
190 |
+
];
|
191 |
+
/**
|
192 |
+
* The `subprocess.killed` property indicates whether the child process
|
193 |
+
* successfully received a signal from `subprocess.kill()`. The `killed` property
|
194 |
+
* does not indicate that the child process has been terminated.
|
195 |
+
* @since v0.5.10
|
196 |
+
*/
|
197 |
+
readonly killed: boolean;
|
198 |
+
/**
|
199 |
+
* Returns the process identifier (PID) of the child process. If the child process
|
200 |
+
* fails to spawn due to errors, then the value is `undefined` and `error` is
|
201 |
+
* emitted.
|
202 |
+
*
|
203 |
+
* ```js
|
204 |
+
* const { spawn } = require('node:child_process');
|
205 |
+
* const grep = spawn('grep', ['ssh']);
|
206 |
+
*
|
207 |
+
* console.log(`Spawned child pid: ${grep.pid}`);
|
208 |
+
* grep.stdin.end();
|
209 |
+
* ```
|
210 |
+
* @since v0.1.90
|
211 |
+
*/
|
212 |
+
readonly pid?: number | undefined;
|
213 |
+
/**
|
214 |
+
* The `subprocess.connected` property indicates whether it is still possible to
|
215 |
+
* send and receive messages from a child process. When `subprocess.connected` is`false`, it is no longer possible to send or receive messages.
|
216 |
+
* @since v0.7.2
|
217 |
+
*/
|
218 |
+
readonly connected: boolean;
|
219 |
+
/**
|
220 |
+
* The `subprocess.exitCode` property indicates the exit code of the child process.
|
221 |
+
* If the child process is still running, the field will be `null`.
|
222 |
+
*/
|
223 |
+
readonly exitCode: number | null;
|
224 |
+
/**
|
225 |
+
* The `subprocess.signalCode` property indicates the signal received by
|
226 |
+
* the child process if any, else `null`.
|
227 |
+
*/
|
228 |
+
readonly signalCode: NodeJS.Signals | null;
|
229 |
+
/**
|
230 |
+
* The `subprocess.spawnargs` property represents the full list of command-line
|
231 |
+
* arguments the child process was launched with.
|
232 |
+
*/
|
233 |
+
readonly spawnargs: string[];
|
234 |
+
/**
|
235 |
+
* The `subprocess.spawnfile` property indicates the executable file name of
|
236 |
+
* the child process that is launched.
|
237 |
+
*
|
238 |
+
* For {@link fork}, its value will be equal to `process.execPath`.
|
239 |
+
* For {@link spawn}, its value will be the name of
|
240 |
+
* the executable file.
|
241 |
+
* For {@link exec}, its value will be the name of the shell
|
242 |
+
* in which the child process is launched.
|
243 |
+
*/
|
244 |
+
readonly spawnfile: string;
|
245 |
+
/**
|
246 |
+
* The `subprocess.kill()` method sends a signal to the child process. If no
|
247 |
+
* 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
|
248 |
+
* returns `true` if [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) succeeds, and `false` otherwise.
|
249 |
+
*
|
250 |
+
* ```js
|
251 |
+
* const { spawn } = require('node:child_process');
|
252 |
+
* const grep = spawn('grep', ['ssh']);
|
253 |
+
*
|
254 |
+
* grep.on('close', (code, signal) => {
|
255 |
+
* console.log(
|
256 |
+
* `child process terminated due to receipt of signal ${signal}`);
|
257 |
+
* });
|
258 |
+
*
|
259 |
+
* // Send SIGHUP to process.
|
260 |
+
* grep.kill('SIGHUP');
|
261 |
+
* ```
|
262 |
+
*
|
263 |
+
* The `ChildProcess` object may emit an `'error'` event if the signal
|
264 |
+
* cannot be delivered. Sending a signal to a child process that has already exited
|
265 |
+
* is not an error but may have unforeseen consequences. Specifically, if the
|
266 |
+
* process identifier (PID) has been reassigned to another process, the signal will
|
267 |
+
* be delivered to that process instead which can have unexpected results.
|
268 |
+
*
|
269 |
+
* While the function is called `kill`, the signal delivered to the child process
|
270 |
+
* may not actually terminate the process.
|
271 |
+
*
|
272 |
+
* See [`kill(2)`](http://man7.org/linux/man-pages/man2/kill.2.html) for reference.
|
273 |
+
*
|
274 |
+
* On Windows, where POSIX signals do not exist, the `signal` argument will be
|
275 |
+
* ignored, and the process will be killed forcefully and abruptly (similar to`'SIGKILL'`).
|
276 |
+
* See `Signal Events` for more details.
|
277 |
+
*
|
278 |
+
* On Linux, child processes of child processes will not be terminated
|
279 |
+
* when attempting to kill their parent. This is likely to happen when running a
|
280 |
+
* new process in a shell or with the use of the `shell` option of `ChildProcess`:
|
281 |
+
*
|
282 |
+
* ```js
|
283 |
+
* 'use strict';
|
284 |
+
* const { spawn } = require('node:child_process');
|
285 |
+
*
|
286 |
+
* const subprocess = spawn(
|
287 |
+
* 'sh',
|
288 |
+
* [
|
289 |
+
* '-c',
|
290 |
+
* `node -e "setInterval(() => {
|
291 |
+
* console.log(process.pid, 'is alive')
|
292 |
+
* }, 500);"`,
|
293 |
+
* ], {
|
294 |
+
* stdio: ['inherit', 'inherit', 'inherit'],
|
295 |
+
* },
|
296 |
+
* );
|
297 |
+
*
|
298 |
+
* setTimeout(() => {
|
299 |
+
* subprocess.kill(); // Does not terminate the Node.js process in the shell.
|
300 |
+
* }, 2000);
|
301 |
+
* ```
|
302 |
+
* @since v0.1.90
|
303 |
+
*/
|
304 |
+
kill(signal?: NodeJS.Signals | number): boolean;
|
305 |
+
/**
|
306 |
+
* Calls {@link ChildProcess.kill} with `'SIGTERM'`.
|
307 |
+
* @since v20.5.0
|
308 |
+
*/
|
309 |
+
[Symbol.dispose](): void;
|
310 |
+
/**
|
311 |
+
* When an IPC channel has been established between the parent and child (
|
312 |
+
* i.e. when using {@link fork}), the `subprocess.send()` method can
|
313 |
+
* be used to send messages to the child process. When the child process is a
|
314 |
+
* Node.js instance, these messages can be received via the `'message'` event.
|
315 |
+
*
|
316 |
+
* The message goes through serialization and parsing. The resulting
|
317 |
+
* message might not be the same as what is originally sent.
|
318 |
+
*
|
319 |
+
* For example, in the parent script:
|
320 |
+
*
|
321 |
+
* ```js
|
322 |
+
* const cp = require('node:child_process');
|
323 |
+
* const n = cp.fork(`${__dirname}/sub.js`);
|
324 |
+
*
|
325 |
+
* n.on('message', (m) => {
|
326 |
+
* console.log('PARENT got message:', m);
|
327 |
+
* });
|
328 |
+
*
|
329 |
+
* // Causes the child to print: CHILD got message: { hello: 'world' }
|
330 |
+
* n.send({ hello: 'world' });
|
331 |
+
* ```
|
332 |
+
*
|
333 |
+
* And then the child script, `'sub.js'` might look like this:
|
334 |
+
*
|
335 |
+
* ```js
|
336 |
+
* process.on('message', (m) => {
|
337 |
+
* console.log('CHILD got message:', m);
|
338 |
+
* });
|
339 |
+
*
|
340 |
+
* // Causes the parent to print: PARENT got message: { foo: 'bar', baz: null }
|
341 |
+
* process.send({ foo: 'bar', baz: NaN });
|
342 |
+
* ```
|
343 |
+
*
|
344 |
+
* Child Node.js processes will have a `process.send()` method of their own
|
345 |
+
* that allows the child to send messages back to the parent.
|
346 |
+
*
|
347 |
+
* There is a special case when sending a `{cmd: 'NODE_foo'}` message. Messages
|
348 |
+
* containing a `NODE_` prefix in the `cmd` property are reserved for use within
|
349 |
+
* 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.
|
350 |
+
* Applications should avoid using such messages or listening for`'internalMessage'` events as it is subject to change without notice.
|
351 |
+
*
|
352 |
+
* The optional `sendHandle` argument that may be passed to `subprocess.send()` is
|
353 |
+
* for passing a TCP server or socket object to the child process. The child will
|
354 |
+
* receive the object as the second argument passed to the callback function
|
355 |
+
* registered on the `'message'` event. Any data that is received
|
356 |
+
* and buffered in the socket will not be sent to the child.
|
357 |
+
*
|
358 |
+
* The optional `callback` is a function that is invoked after the message is
|
359 |
+
* sent but before the child may have received it. The function is called with a
|
360 |
+
* single argument: `null` on success, or an `Error` object on failure.
|
361 |
+
*
|
362 |
+
* If no `callback` function is provided and the message cannot be sent, an`'error'` event will be emitted by the `ChildProcess` object. This can
|
363 |
+
* happen, for instance, when the child process has already exited.
|
364 |
+
*
|
365 |
+
* `subprocess.send()` will return `false` if the channel has closed or when the
|
366 |
+
* backlog of unsent messages exceeds a threshold that makes it unwise to send
|
367 |
+
* more. Otherwise, the method returns `true`. The `callback` function can be
|
368 |
+
* used to implement flow control.
|
369 |
+
*
|
370 |
+
* #### Example: sending a server object
|
371 |
+
*
|
372 |
+
* The `sendHandle` argument can be used, for instance, to pass the handle of
|
373 |
+
* a TCP server object to the child process as illustrated in the example below:
|
374 |
+
*
|
375 |
+
* ```js
|
376 |
+
* const subprocess = require('node:child_process').fork('subprocess.js');
|
377 |
+
*
|
378 |
+
* // Open up the server object and send the handle.
|
379 |
+
* const server = require('node:net').createServer();
|
380 |
+
* server.on('connection', (socket) => {
|
381 |
+
* socket.end('handled by parent');
|
382 |
+
* });
|
383 |
+
* server.listen(1337, () => {
|
384 |
+
* subprocess.send('server', server);
|
385 |
+
* });
|
386 |
+
* ```
|
387 |
+
*
|
388 |
+
* The child would then receive the server object as:
|
389 |
+
*
|
390 |
+
* ```js
|
391 |
+
* process.on('message', (m, server) => {
|
392 |
+
* if (m === 'server') {
|
393 |
+
* server.on('connection', (socket) => {
|
394 |
+
* socket.end('handled by child');
|
395 |
+
* });
|
396 |
+
* }
|
397 |
+
* });
|
398 |
+
* ```
|
399 |
+
*
|
400 |
+
* Once the server is now shared between the parent and child, some connections
|
401 |
+
* can be handled by the parent and some by the child.
|
402 |
+
*
|
403 |
+
* 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
|
404 |
+
* listening on a `'message'` event instead of `'connection'` and using`server.bind()` instead of `server.listen()`. This is, however, only
|
405 |
+
* supported on Unix platforms.
|
406 |
+
*
|
407 |
+
* #### Example: sending a socket object
|
408 |
+
*
|
409 |
+
* Similarly, the `sendHandler` argument can be used to pass the handle of a
|
410 |
+
* socket to the child process. The example below spawns two children that each
|
411 |
+
* handle connections with "normal" or "special" priority:
|
412 |
+
*
|
413 |
+
* ```js
|
414 |
+
* const { fork } = require('node:child_process');
|
415 |
+
* const normal = fork('subprocess.js', ['normal']);
|
416 |
+
* const special = fork('subprocess.js', ['special']);
|
417 |
+
*
|
418 |
+
* // Open up the server and send sockets to child. Use pauseOnConnect to prevent
|
419 |
+
* // the sockets from being read before they are sent to the child process.
|
420 |
+
* const server = require('node:net').createServer({ pauseOnConnect: true });
|
421 |
+
* server.on('connection', (socket) => {
|
422 |
+
*
|
423 |
+
* // If this is special priority...
|
424 |
+
* if (socket.remoteAddress === '74.125.127.100') {
|
425 |
+
* special.send('socket', socket);
|
426 |
+
* return;
|
427 |
+
* }
|
428 |
+
* // This is normal priority.
|
429 |
+
* normal.send('socket', socket);
|
430 |
+
* });
|
431 |
+
* server.listen(1337);
|
432 |
+
* ```
|
433 |
+
*
|
434 |
+
* The `subprocess.js` would receive the socket handle as the second argument
|
435 |
+
* passed to the event callback function:
|
436 |
+
*
|
437 |
+
* ```js
|
438 |
+
* process.on('message', (m, socket) => {
|
439 |
+
* if (m === 'socket') {
|
440 |
+
* if (socket) {
|
441 |
+
* // Check that the client socket exists.
|
442 |
+
* // It is possible for the socket to be closed between the time it is
|
443 |
+
* // sent and the time it is received in the child process.
|
444 |
+
* socket.end(`Request handled with ${process.argv[2]} priority`);
|
445 |
+
* }
|
446 |
+
* }
|
447 |
+
* });
|
448 |
+
* ```
|
449 |
+
*
|
450 |
+
* Do not use `.maxConnections` on a socket that has been passed to a subprocess.
|
451 |
+
* The parent cannot track when the socket is destroyed.
|
452 |
+
*
|
453 |
+
* Any `'message'` handlers in the subprocess should verify that `socket` exists,
|
454 |
+
* as the connection may have been closed during the time it takes to send the
|
455 |
+
* connection to the child.
|
456 |
+
* @since v0.5.9
|
457 |
+
* @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:
|
458 |
+
*/
|
459 |
+
send(message: Serializable, callback?: (error: Error | null) => void): boolean;
|
460 |
+
send(message: Serializable, sendHandle?: SendHandle, callback?: (error: Error | null) => void): boolean;
|
461 |
+
send(
|
462 |
+
message: Serializable,
|
463 |
+
sendHandle?: SendHandle,
|
464 |
+
options?: MessageOptions,
|
465 |
+
callback?: (error: Error | null) => void,
|
466 |
+
): boolean;
|
467 |
+
/**
|
468 |
+
* Closes the IPC channel between parent and child, allowing the child to exit
|
469 |
+
* gracefully once there are no other connections keeping it alive. After calling
|
470 |
+
* this method the `subprocess.connected` and `process.connected` properties in
|
471 |
+
* both the parent and child (respectively) will be set to `false`, and it will be
|
472 |
+
* no longer possible to pass messages between the processes.
|
473 |
+
*
|
474 |
+
* The `'disconnect'` event will be emitted when there are no messages in the
|
475 |
+
* process of being received. This will most often be triggered immediately after
|
476 |
+
* calling `subprocess.disconnect()`.
|
477 |
+
*
|
478 |
+
* When the child process is a Node.js instance (e.g. spawned using {@link fork}), the `process.disconnect()` method can be invoked
|
479 |
+
* within the child process to close the IPC channel as well.
|
480 |
+
* @since v0.7.2
|
481 |
+
*/
|
482 |
+
disconnect(): void;
|
483 |
+
/**
|
484 |
+
* By default, the parent will wait for the detached child to exit. To prevent the
|
485 |
+
* 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
|
486 |
+
* include the child in its reference count, allowing the parent to exit
|
487 |
+
* independently of the child, unless there is an established IPC channel between
|
488 |
+
* the child and the parent.
|
489 |
+
*
|
490 |
+
* ```js
|
491 |
+
* const { spawn } = require('node:child_process');
|
492 |
+
*
|
493 |
+
* const subprocess = spawn(process.argv[0], ['child_program.js'], {
|
494 |
+
* detached: true,
|
495 |
+
* stdio: 'ignore',
|
496 |
+
* });
|
497 |
+
*
|
498 |
+
* subprocess.unref();
|
499 |
+
* ```
|
500 |
+
* @since v0.7.10
|
501 |
+
*/
|
502 |
+
unref(): void;
|
503 |
+
/**
|
504 |
+
* Calling `subprocess.ref()` after making a call to `subprocess.unref()` will
|
505 |
+
* restore the removed reference count for the child process, forcing the parent
|
506 |
+
* to wait for the child to exit before exiting itself.
|
507 |
+
*
|
508 |
+
* ```js
|
509 |
+
* const { spawn } = require('node:child_process');
|
510 |
+
*
|
511 |
+
* const subprocess = spawn(process.argv[0], ['child_program.js'], {
|
512 |
+
* detached: true,
|
513 |
+
* stdio: 'ignore',
|
514 |
+
* });
|
515 |
+
*
|
516 |
+
* subprocess.unref();
|
517 |
+
* subprocess.ref();
|
518 |
+
* ```
|
519 |
+
* @since v0.7.10
|
520 |
+
*/
|
521 |
+
ref(): void;
|
522 |
+
/**
|
523 |
+
* events.EventEmitter
|
524 |
+
* 1. close
|
525 |
+
* 2. disconnect
|
526 |
+
* 3. error
|
527 |
+
* 4. exit
|
528 |
+
* 5. message
|
529 |
+
* 6. spawn
|
530 |
+
*/
|
531 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
532 |
+
addListener(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
533 |
+
addListener(event: "disconnect", listener: () => void): this;
|
534 |
+
addListener(event: "error", listener: (err: Error) => void): this;
|
535 |
+
addListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
536 |
+
addListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
537 |
+
addListener(event: "spawn", listener: () => void): this;
|
538 |
+
emit(event: string | symbol, ...args: any[]): boolean;
|
539 |
+
emit(event: "close", code: number | null, signal: NodeJS.Signals | null): boolean;
|
540 |
+
emit(event: "disconnect"): boolean;
|
541 |
+
emit(event: "error", err: Error): boolean;
|
542 |
+
emit(event: "exit", code: number | null, signal: NodeJS.Signals | null): boolean;
|
543 |
+
emit(event: "message", message: Serializable, sendHandle: SendHandle): boolean;
|
544 |
+
emit(event: "spawn", listener: () => void): boolean;
|
545 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
546 |
+
on(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
547 |
+
on(event: "disconnect", listener: () => void): this;
|
548 |
+
on(event: "error", listener: (err: Error) => void): this;
|
549 |
+
on(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
550 |
+
on(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
551 |
+
on(event: "spawn", listener: () => void): this;
|
552 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
553 |
+
once(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
554 |
+
once(event: "disconnect", listener: () => void): this;
|
555 |
+
once(event: "error", listener: (err: Error) => void): this;
|
556 |
+
once(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
557 |
+
once(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
558 |
+
once(event: "spawn", listener: () => void): this;
|
559 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
560 |
+
prependListener(event: "close", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
561 |
+
prependListener(event: "disconnect", listener: () => void): this;
|
562 |
+
prependListener(event: "error", listener: (err: Error) => void): this;
|
563 |
+
prependListener(event: "exit", listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
|
564 |
+
prependListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
565 |
+
prependListener(event: "spawn", listener: () => void): this;
|
566 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
567 |
+
prependOnceListener(
|
568 |
+
event: "close",
|
569 |
+
listener: (code: number | null, signal: NodeJS.Signals | null) => void,
|
570 |
+
): this;
|
571 |
+
prependOnceListener(event: "disconnect", listener: () => void): this;
|
572 |
+
prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
573 |
+
prependOnceListener(
|
574 |
+
event: "exit",
|
575 |
+
listener: (code: number | null, signal: NodeJS.Signals | null) => void,
|
576 |
+
): this;
|
577 |
+
prependOnceListener(event: "message", listener: (message: Serializable, sendHandle: SendHandle) => void): this;
|
578 |
+
prependOnceListener(event: "spawn", listener: () => void): this;
|
579 |
+
}
|
580 |
+
// return this object when stdio option is undefined or not specified
|
581 |
+
interface ChildProcessWithoutNullStreams extends ChildProcess {
|
582 |
+
stdin: Writable;
|
583 |
+
stdout: Readable;
|
584 |
+
stderr: Readable;
|
585 |
+
readonly stdio: [
|
586 |
+
Writable,
|
587 |
+
Readable,
|
588 |
+
Readable,
|
589 |
+
// stderr
|
590 |
+
Readable | Writable | null | undefined,
|
591 |
+
// extra, no modification
|
592 |
+
Readable | Writable | null | undefined, // extra, no modification
|
593 |
+
];
|
594 |
+
}
|
595 |
+
// return this object when stdio option is a tuple of 3
|
596 |
+
interface ChildProcessByStdio<I extends null | Writable, O extends null | Readable, E extends null | Readable>
|
597 |
+
extends ChildProcess
|
598 |
+
{
|
599 |
+
stdin: I;
|
600 |
+
stdout: O;
|
601 |
+
stderr: E;
|
602 |
+
readonly stdio: [
|
603 |
+
I,
|
604 |
+
O,
|
605 |
+
E,
|
606 |
+
Readable | Writable | null | undefined,
|
607 |
+
// extra, no modification
|
608 |
+
Readable | Writable | null | undefined, // extra, no modification
|
609 |
+
];
|
610 |
+
}
|
611 |
+
interface MessageOptions {
|
612 |
+
keepOpen?: boolean | undefined;
|
613 |
+
}
|
614 |
+
type IOType = "overlapped" | "pipe" | "ignore" | "inherit";
|
615 |
+
type StdioOptions = IOType | Array<IOType | "ipc" | Stream | number | null | undefined>;
|
616 |
+
type SerializationType = "json" | "advanced";
|
617 |
+
interface MessagingOptions extends Abortable {
|
618 |
+
/**
|
619 |
+
* Specify the kind of serialization used for sending messages between processes.
|
620 |
+
* @default 'json'
|
621 |
+
*/
|
622 |
+
serialization?: SerializationType | undefined;
|
623 |
+
/**
|
624 |
+
* The signal value to be used when the spawned process will be killed by the abort signal.
|
625 |
+
* @default 'SIGTERM'
|
626 |
+
*/
|
627 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
628 |
+
/**
|
629 |
+
* In milliseconds the maximum amount of time the process is allowed to run.
|
630 |
+
*/
|
631 |
+
timeout?: number | undefined;
|
632 |
+
}
|
633 |
+
interface ProcessEnvOptions {
|
634 |
+
uid?: number | undefined;
|
635 |
+
gid?: number | undefined;
|
636 |
+
cwd?: string | URL | undefined;
|
637 |
+
env?: NodeJS.ProcessEnv | undefined;
|
638 |
+
}
|
639 |
+
interface CommonOptions extends ProcessEnvOptions {
|
640 |
+
/**
|
641 |
+
* @default false
|
642 |
+
*/
|
643 |
+
windowsHide?: boolean | undefined;
|
644 |
+
/**
|
645 |
+
* @default 0
|
646 |
+
*/
|
647 |
+
timeout?: number | undefined;
|
648 |
+
}
|
649 |
+
interface CommonSpawnOptions extends CommonOptions, MessagingOptions, Abortable {
|
650 |
+
argv0?: string | undefined;
|
651 |
+
/**
|
652 |
+
* Can be set to 'pipe', 'inherit', 'overlapped', or 'ignore', or an array of these strings.
|
653 |
+
* If passed as an array, the first element is used for `stdin`, the second for
|
654 |
+
* `stdout`, and the third for `stderr`. A fourth element can be used to
|
655 |
+
* specify the `stdio` behavior beyond the standard streams. See
|
656 |
+
* {@link ChildProcess.stdio} for more information.
|
657 |
+
*
|
658 |
+
* @default 'pipe'
|
659 |
+
*/
|
660 |
+
stdio?: StdioOptions | undefined;
|
661 |
+
shell?: boolean | string | undefined;
|
662 |
+
windowsVerbatimArguments?: boolean | undefined;
|
663 |
+
}
|
664 |
+
interface SpawnOptions extends CommonSpawnOptions {
|
665 |
+
detached?: boolean | undefined;
|
666 |
+
}
|
667 |
+
interface SpawnOptionsWithoutStdio extends SpawnOptions {
|
668 |
+
stdio?: StdioPipeNamed | StdioPipe[] | undefined;
|
669 |
+
}
|
670 |
+
type StdioNull = "inherit" | "ignore" | Stream;
|
671 |
+
type StdioPipeNamed = "pipe" | "overlapped";
|
672 |
+
type StdioPipe = undefined | null | StdioPipeNamed;
|
673 |
+
interface SpawnOptionsWithStdioTuple<
|
674 |
+
Stdin extends StdioNull | StdioPipe,
|
675 |
+
Stdout extends StdioNull | StdioPipe,
|
676 |
+
Stderr extends StdioNull | StdioPipe,
|
677 |
+
> extends SpawnOptions {
|
678 |
+
stdio: [Stdin, Stdout, Stderr];
|
679 |
+
}
|
680 |
+
/**
|
681 |
+
* The `child_process.spawn()` method spawns a new process using the given`command`, with command-line arguments in `args`. If omitted, `args` defaults
|
682 |
+
* to an empty array.
|
683 |
+
*
|
684 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
685 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
686 |
+
* **arbitrary command execution.**
|
687 |
+
*
|
688 |
+
* A third argument may be used to specify additional options, with these defaults:
|
689 |
+
*
|
690 |
+
* ```js
|
691 |
+
* const defaults = {
|
692 |
+
* cwd: undefined,
|
693 |
+
* env: process.env,
|
694 |
+
* };
|
695 |
+
* ```
|
696 |
+
*
|
697 |
+
* Use `cwd` to specify the working directory from which the process is spawned.
|
698 |
+
* If not given, the default is to inherit the current working directory. If given,
|
699 |
+
* but the path does not exist, the child process emits an `ENOENT` error
|
700 |
+
* and exits immediately. `ENOENT` is also emitted when the command
|
701 |
+
* does not exist.
|
702 |
+
*
|
703 |
+
* Use `env` to specify environment variables that will be visible to the new
|
704 |
+
* process, the default is `process.env`.
|
705 |
+
*
|
706 |
+
* `undefined` values in `env` will be ignored.
|
707 |
+
*
|
708 |
+
* Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the
|
709 |
+
* exit code:
|
710 |
+
*
|
711 |
+
* ```js
|
712 |
+
* const { spawn } = require('node:child_process');
|
713 |
+
* const ls = spawn('ls', ['-lh', '/usr']);
|
714 |
+
*
|
715 |
+
* ls.stdout.on('data', (data) => {
|
716 |
+
* console.log(`stdout: ${data}`);
|
717 |
+
* });
|
718 |
+
*
|
719 |
+
* ls.stderr.on('data', (data) => {
|
720 |
+
* console.error(`stderr: ${data}`);
|
721 |
+
* });
|
722 |
+
*
|
723 |
+
* ls.on('close', (code) => {
|
724 |
+
* console.log(`child process exited with code ${code}`);
|
725 |
+
* });
|
726 |
+
* ```
|
727 |
+
*
|
728 |
+
* Example: A very elaborate way to run `ps ax | grep ssh`
|
729 |
+
*
|
730 |
+
* ```js
|
731 |
+
* const { spawn } = require('node:child_process');
|
732 |
+
* const ps = spawn('ps', ['ax']);
|
733 |
+
* const grep = spawn('grep', ['ssh']);
|
734 |
+
*
|
735 |
+
* ps.stdout.on('data', (data) => {
|
736 |
+
* grep.stdin.write(data);
|
737 |
+
* });
|
738 |
+
*
|
739 |
+
* ps.stderr.on('data', (data) => {
|
740 |
+
* console.error(`ps stderr: ${data}`);
|
741 |
+
* });
|
742 |
+
*
|
743 |
+
* ps.on('close', (code) => {
|
744 |
+
* if (code !== 0) {
|
745 |
+
* console.log(`ps process exited with code ${code}`);
|
746 |
+
* }
|
747 |
+
* grep.stdin.end();
|
748 |
+
* });
|
749 |
+
*
|
750 |
+
* grep.stdout.on('data', (data) => {
|
751 |
+
* console.log(data.toString());
|
752 |
+
* });
|
753 |
+
*
|
754 |
+
* grep.stderr.on('data', (data) => {
|
755 |
+
* console.error(`grep stderr: ${data}`);
|
756 |
+
* });
|
757 |
+
*
|
758 |
+
* grep.on('close', (code) => {
|
759 |
+
* if (code !== 0) {
|
760 |
+
* console.log(`grep process exited with code ${code}`);
|
761 |
+
* }
|
762 |
+
* });
|
763 |
+
* ```
|
764 |
+
*
|
765 |
+
* Example of checking for failed `spawn`:
|
766 |
+
*
|
767 |
+
* ```js
|
768 |
+
* const { spawn } = require('node:child_process');
|
769 |
+
* const subprocess = spawn('bad_command');
|
770 |
+
*
|
771 |
+
* subprocess.on('error', (err) => {
|
772 |
+
* console.error('Failed to start subprocess.');
|
773 |
+
* });
|
774 |
+
* ```
|
775 |
+
*
|
776 |
+
* Certain platforms (macOS, Linux) will use the value of `argv[0]` for the process
|
777 |
+
* title while others (Windows, SunOS) will use `command`.
|
778 |
+
*
|
779 |
+
* 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
|
780 |
+
* it with the`process.argv0` property instead.
|
781 |
+
*
|
782 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
|
783 |
+
* the error passed to the callback will be an `AbortError`:
|
784 |
+
*
|
785 |
+
* ```js
|
786 |
+
* const { spawn } = require('node:child_process');
|
787 |
+
* const controller = new AbortController();
|
788 |
+
* const { signal } = controller;
|
789 |
+
* const grep = spawn('grep', ['ssh'], { signal });
|
790 |
+
* grep.on('error', (err) => {
|
791 |
+
* // This will be called with err being an AbortError if the controller aborts
|
792 |
+
* });
|
793 |
+
* controller.abort(); // Stops the child process
|
794 |
+
* ```
|
795 |
+
* @since v0.1.90
|
796 |
+
* @param command The command to run.
|
797 |
+
* @param args List of string arguments.
|
798 |
+
*/
|
799 |
+
function spawn(command: string, options?: SpawnOptionsWithoutStdio): ChildProcessWithoutNullStreams;
|
800 |
+
function spawn(
|
801 |
+
command: string,
|
802 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
803 |
+
): ChildProcessByStdio<Writable, Readable, Readable>;
|
804 |
+
function spawn(
|
805 |
+
command: string,
|
806 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
807 |
+
): ChildProcessByStdio<Writable, Readable, null>;
|
808 |
+
function spawn(
|
809 |
+
command: string,
|
810 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
811 |
+
): ChildProcessByStdio<Writable, null, Readable>;
|
812 |
+
function spawn(
|
813 |
+
command: string,
|
814 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
815 |
+
): ChildProcessByStdio<null, Readable, Readable>;
|
816 |
+
function spawn(
|
817 |
+
command: string,
|
818 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
819 |
+
): ChildProcessByStdio<Writable, null, null>;
|
820 |
+
function spawn(
|
821 |
+
command: string,
|
822 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
823 |
+
): ChildProcessByStdio<null, Readable, null>;
|
824 |
+
function spawn(
|
825 |
+
command: string,
|
826 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
827 |
+
): ChildProcessByStdio<null, null, Readable>;
|
828 |
+
function spawn(
|
829 |
+
command: string,
|
830 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
831 |
+
): ChildProcessByStdio<null, null, null>;
|
832 |
+
function spawn(command: string, options: SpawnOptions): ChildProcess;
|
833 |
+
// overloads of spawn with 'args'
|
834 |
+
function spawn(
|
835 |
+
command: string,
|
836 |
+
args?: readonly string[],
|
837 |
+
options?: SpawnOptionsWithoutStdio,
|
838 |
+
): ChildProcessWithoutNullStreams;
|
839 |
+
function spawn(
|
840 |
+
command: string,
|
841 |
+
args: readonly string[],
|
842 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioPipe>,
|
843 |
+
): ChildProcessByStdio<Writable, Readable, Readable>;
|
844 |
+
function spawn(
|
845 |
+
command: string,
|
846 |
+
args: readonly string[],
|
847 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioPipe, StdioNull>,
|
848 |
+
): ChildProcessByStdio<Writable, Readable, null>;
|
849 |
+
function spawn(
|
850 |
+
command: string,
|
851 |
+
args: readonly string[],
|
852 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioPipe>,
|
853 |
+
): ChildProcessByStdio<Writable, null, Readable>;
|
854 |
+
function spawn(
|
855 |
+
command: string,
|
856 |
+
args: readonly string[],
|
857 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioPipe>,
|
858 |
+
): ChildProcessByStdio<null, Readable, Readable>;
|
859 |
+
function spawn(
|
860 |
+
command: string,
|
861 |
+
args: readonly string[],
|
862 |
+
options: SpawnOptionsWithStdioTuple<StdioPipe, StdioNull, StdioNull>,
|
863 |
+
): ChildProcessByStdio<Writable, null, null>;
|
864 |
+
function spawn(
|
865 |
+
command: string,
|
866 |
+
args: readonly string[],
|
867 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioPipe, StdioNull>,
|
868 |
+
): ChildProcessByStdio<null, Readable, null>;
|
869 |
+
function spawn(
|
870 |
+
command: string,
|
871 |
+
args: readonly string[],
|
872 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioPipe>,
|
873 |
+
): ChildProcessByStdio<null, null, Readable>;
|
874 |
+
function spawn(
|
875 |
+
command: string,
|
876 |
+
args: readonly string[],
|
877 |
+
options: SpawnOptionsWithStdioTuple<StdioNull, StdioNull, StdioNull>,
|
878 |
+
): ChildProcessByStdio<null, null, null>;
|
879 |
+
function spawn(command: string, args: readonly string[], options: SpawnOptions): ChildProcess;
|
880 |
+
interface ExecOptions extends CommonOptions {
|
881 |
+
shell?: string | undefined;
|
882 |
+
signal?: AbortSignal | undefined;
|
883 |
+
maxBuffer?: number | undefined;
|
884 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
885 |
+
}
|
886 |
+
interface ExecOptionsWithStringEncoding extends ExecOptions {
|
887 |
+
encoding: BufferEncoding;
|
888 |
+
}
|
889 |
+
interface ExecOptionsWithBufferEncoding extends ExecOptions {
|
890 |
+
encoding: BufferEncoding | null; // specify `null`.
|
891 |
+
}
|
892 |
+
interface ExecException extends Error {
|
893 |
+
cmd?: string | undefined;
|
894 |
+
killed?: boolean | undefined;
|
895 |
+
code?: number | undefined;
|
896 |
+
signal?: NodeJS.Signals | undefined;
|
897 |
+
}
|
898 |
+
/**
|
899 |
+
* Spawns a shell then executes the `command` within that shell, buffering any
|
900 |
+
* generated output. The `command` string passed to the exec function is processed
|
901 |
+
* directly by the shell and special characters (vary based on [shell](https://en.wikipedia.org/wiki/List_of_command-line_interpreters))
|
902 |
+
* need to be dealt with accordingly:
|
903 |
+
*
|
904 |
+
* ```js
|
905 |
+
* const { exec } = require('node:child_process');
|
906 |
+
*
|
907 |
+
* exec('"/path/to/test file/test.sh" arg1 arg2');
|
908 |
+
* // Double quotes are used so that the space in the path is not interpreted as
|
909 |
+
* // a delimiter of multiple arguments.
|
910 |
+
*
|
911 |
+
* exec('echo "The \\$HOME variable is $HOME"');
|
912 |
+
* // The $HOME variable is escaped in the first instance, but not in the second.
|
913 |
+
* ```
|
914 |
+
*
|
915 |
+
* **Never pass unsanitized user input to this function. Any input containing shell**
|
916 |
+
* **metacharacters may be used to trigger arbitrary command execution.**
|
917 |
+
*
|
918 |
+
* 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
|
919 |
+
* `error.code` property will be
|
920 |
+
* 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
|
921 |
+
* process.
|
922 |
+
*
|
923 |
+
* The `stdout` and `stderr` arguments passed to the callback will contain the
|
924 |
+
* stdout and stderr output of the child process. By default, Node.js will decode
|
925 |
+
* the output as UTF-8 and pass strings to the callback. The `encoding` option
|
926 |
+
* can be used to specify the character encoding used to decode the stdout and
|
927 |
+
* stderr output. If `encoding` is `'buffer'`, or an unrecognized character
|
928 |
+
* encoding, `Buffer` objects will be passed to the callback instead.
|
929 |
+
*
|
930 |
+
* ```js
|
931 |
+
* const { exec } = require('node:child_process');
|
932 |
+
* exec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {
|
933 |
+
* if (error) {
|
934 |
+
* console.error(`exec error: ${error}`);
|
935 |
+
* return;
|
936 |
+
* }
|
937 |
+
* console.log(`stdout: ${stdout}`);
|
938 |
+
* console.error(`stderr: ${stderr}`);
|
939 |
+
* });
|
940 |
+
* ```
|
941 |
+
*
|
942 |
+
* If `timeout` is greater than `0`, the parent will send the signal
|
943 |
+
* identified by the `killSignal` property (the default is `'SIGTERM'`) if the
|
944 |
+
* child runs longer than `timeout` milliseconds.
|
945 |
+
*
|
946 |
+
* Unlike the [`exec(3)`](http://man7.org/linux/man-pages/man3/exec.3.html) POSIX system call, `child_process.exec()` does not replace
|
947 |
+
* the existing process and uses a shell to execute the command.
|
948 |
+
*
|
949 |
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
950 |
+
* a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned`ChildProcess` instance is attached to the `Promise` as a `child` property. In
|
951 |
+
* case of an error (including any error resulting in an exit code other than 0), a
|
952 |
+
* rejected promise is returned, with the same `error` object given in the
|
953 |
+
* callback, but with two additional properties `stdout` and `stderr`.
|
954 |
+
*
|
955 |
+
* ```js
|
956 |
+
* const util = require('node:util');
|
957 |
+
* const exec = util.promisify(require('node:child_process').exec);
|
958 |
+
*
|
959 |
+
* async function lsExample() {
|
960 |
+
* const { stdout, stderr } = await exec('ls');
|
961 |
+
* console.log('stdout:', stdout);
|
962 |
+
* console.error('stderr:', stderr);
|
963 |
+
* }
|
964 |
+
* lsExample();
|
965 |
+
* ```
|
966 |
+
*
|
967 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
|
968 |
+
* the error passed to the callback will be an `AbortError`:
|
969 |
+
*
|
970 |
+
* ```js
|
971 |
+
* const { exec } = require('node:child_process');
|
972 |
+
* const controller = new AbortController();
|
973 |
+
* const { signal } = controller;
|
974 |
+
* const child = exec('grep ssh', { signal }, (error) => {
|
975 |
+
* console.error(error); // an AbortError
|
976 |
+
* });
|
977 |
+
* controller.abort();
|
978 |
+
* ```
|
979 |
+
* @since v0.1.90
|
980 |
+
* @param command The command to run, with space-separated arguments.
|
981 |
+
* @param callback called with the output when process terminates.
|
982 |
+
*/
|
983 |
+
function exec(
|
984 |
+
command: string,
|
985 |
+
callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
|
986 |
+
): ChildProcess;
|
987 |
+
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
988 |
+
function exec(
|
989 |
+
command: string,
|
990 |
+
options: {
|
991 |
+
encoding: "buffer" | null;
|
992 |
+
} & ExecOptions,
|
993 |
+
callback?: (error: ExecException | null, stdout: Buffer, stderr: Buffer) => void,
|
994 |
+
): ChildProcess;
|
995 |
+
// `options` with well known `encoding` means stdout/stderr are definitely `string`.
|
996 |
+
function exec(
|
997 |
+
command: string,
|
998 |
+
options: {
|
999 |
+
encoding: BufferEncoding;
|
1000 |
+
} & ExecOptions,
|
1001 |
+
callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
|
1002 |
+
): ChildProcess;
|
1003 |
+
// `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
|
1004 |
+
// There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
|
1005 |
+
function exec(
|
1006 |
+
command: string,
|
1007 |
+
options: {
|
1008 |
+
encoding: BufferEncoding;
|
1009 |
+
} & ExecOptions,
|
1010 |
+
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
1011 |
+
): ChildProcess;
|
1012 |
+
// `options` without an `encoding` means stdout/stderr are definitely `string`.
|
1013 |
+
function exec(
|
1014 |
+
command: string,
|
1015 |
+
options: ExecOptions,
|
1016 |
+
callback?: (error: ExecException | null, stdout: string, stderr: string) => void,
|
1017 |
+
): ChildProcess;
|
1018 |
+
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
1019 |
+
function exec(
|
1020 |
+
command: string,
|
1021 |
+
options: (ObjectEncodingOptions & ExecOptions) | undefined | null,
|
1022 |
+
callback?: (error: ExecException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
1023 |
+
): ChildProcess;
|
1024 |
+
interface PromiseWithChild<T> extends Promise<T> {
|
1025 |
+
child: ChildProcess;
|
1026 |
+
}
|
1027 |
+
namespace exec {
|
1028 |
+
function __promisify__(command: string): PromiseWithChild<{
|
1029 |
+
stdout: string;
|
1030 |
+
stderr: string;
|
1031 |
+
}>;
|
1032 |
+
function __promisify__(
|
1033 |
+
command: string,
|
1034 |
+
options: {
|
1035 |
+
encoding: "buffer" | null;
|
1036 |
+
} & ExecOptions,
|
1037 |
+
): PromiseWithChild<{
|
1038 |
+
stdout: Buffer;
|
1039 |
+
stderr: Buffer;
|
1040 |
+
}>;
|
1041 |
+
function __promisify__(
|
1042 |
+
command: string,
|
1043 |
+
options: {
|
1044 |
+
encoding: BufferEncoding;
|
1045 |
+
} & ExecOptions,
|
1046 |
+
): PromiseWithChild<{
|
1047 |
+
stdout: string;
|
1048 |
+
stderr: string;
|
1049 |
+
}>;
|
1050 |
+
function __promisify__(
|
1051 |
+
command: string,
|
1052 |
+
options: ExecOptions,
|
1053 |
+
): PromiseWithChild<{
|
1054 |
+
stdout: string;
|
1055 |
+
stderr: string;
|
1056 |
+
}>;
|
1057 |
+
function __promisify__(
|
1058 |
+
command: string,
|
1059 |
+
options?: (ObjectEncodingOptions & ExecOptions) | null,
|
1060 |
+
): PromiseWithChild<{
|
1061 |
+
stdout: string | Buffer;
|
1062 |
+
stderr: string | Buffer;
|
1063 |
+
}>;
|
1064 |
+
}
|
1065 |
+
interface ExecFileOptions extends CommonOptions, Abortable {
|
1066 |
+
maxBuffer?: number | undefined;
|
1067 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
1068 |
+
windowsVerbatimArguments?: boolean | undefined;
|
1069 |
+
shell?: boolean | string | undefined;
|
1070 |
+
signal?: AbortSignal | undefined;
|
1071 |
+
}
|
1072 |
+
interface ExecFileOptionsWithStringEncoding extends ExecFileOptions {
|
1073 |
+
encoding: BufferEncoding;
|
1074 |
+
}
|
1075 |
+
interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions {
|
1076 |
+
encoding: "buffer" | null;
|
1077 |
+
}
|
1078 |
+
interface ExecFileOptionsWithOtherEncoding extends ExecFileOptions {
|
1079 |
+
encoding: BufferEncoding;
|
1080 |
+
}
|
1081 |
+
type ExecFileException =
|
1082 |
+
& Omit<ExecException, "code">
|
1083 |
+
& Omit<NodeJS.ErrnoException, "code">
|
1084 |
+
& { code?: string | number | undefined | null };
|
1085 |
+
/**
|
1086 |
+
* The `child_process.execFile()` function is similar to {@link exec} except that it does not spawn a shell by default. Rather, the specified
|
1087 |
+
* executable `file` is spawned directly as a new process making it slightly more
|
1088 |
+
* efficient than {@link exec}.
|
1089 |
+
*
|
1090 |
+
* The same options as {@link exec} are supported. Since a shell is
|
1091 |
+
* not spawned, behaviors such as I/O redirection and file globbing are not
|
1092 |
+
* supported.
|
1093 |
+
*
|
1094 |
+
* ```js
|
1095 |
+
* const { execFile } = require('node:child_process');
|
1096 |
+
* const child = execFile('node', ['--version'], (error, stdout, stderr) => {
|
1097 |
+
* if (error) {
|
1098 |
+
* throw error;
|
1099 |
+
* }
|
1100 |
+
* console.log(stdout);
|
1101 |
+
* });
|
1102 |
+
* ```
|
1103 |
+
*
|
1104 |
+
* The `stdout` and `stderr` arguments passed to the callback will contain the
|
1105 |
+
* stdout and stderr output of the child process. By default, Node.js will decode
|
1106 |
+
* the output as UTF-8 and pass strings to the callback. The `encoding` option
|
1107 |
+
* can be used to specify the character encoding used to decode the stdout and
|
1108 |
+
* stderr output. If `encoding` is `'buffer'`, or an unrecognized character
|
1109 |
+
* encoding, `Buffer` objects will be passed to the callback instead.
|
1110 |
+
*
|
1111 |
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
1112 |
+
* a `Promise` for an `Object` with `stdout` and `stderr` properties. The returned`ChildProcess` instance is attached to the `Promise` as a `child` property. In
|
1113 |
+
* case of an error (including any error resulting in an exit code other than 0), a
|
1114 |
+
* rejected promise is returned, with the same `error` object given in the
|
1115 |
+
* callback, but with two additional properties `stdout` and `stderr`.
|
1116 |
+
*
|
1117 |
+
* ```js
|
1118 |
+
* const util = require('node:util');
|
1119 |
+
* const execFile = util.promisify(require('node:child_process').execFile);
|
1120 |
+
* async function getVersion() {
|
1121 |
+
* const { stdout } = await execFile('node', ['--version']);
|
1122 |
+
* console.log(stdout);
|
1123 |
+
* }
|
1124 |
+
* getVersion();
|
1125 |
+
* ```
|
1126 |
+
*
|
1127 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
1128 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
1129 |
+
* **arbitrary command execution.**
|
1130 |
+
*
|
1131 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
|
1132 |
+
* the error passed to the callback will be an `AbortError`:
|
1133 |
+
*
|
1134 |
+
* ```js
|
1135 |
+
* const { execFile } = require('node:child_process');
|
1136 |
+
* const controller = new AbortController();
|
1137 |
+
* const { signal } = controller;
|
1138 |
+
* const child = execFile('node', ['--version'], { signal }, (error) => {
|
1139 |
+
* console.error(error); // an AbortError
|
1140 |
+
* });
|
1141 |
+
* controller.abort();
|
1142 |
+
* ```
|
1143 |
+
* @since v0.1.91
|
1144 |
+
* @param file The name or path of the executable file to run.
|
1145 |
+
* @param args List of string arguments.
|
1146 |
+
* @param callback Called with the output when process terminates.
|
1147 |
+
*/
|
1148 |
+
function execFile(file: string): ChildProcess;
|
1149 |
+
function execFile(
|
1150 |
+
file: string,
|
1151 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1152 |
+
): ChildProcess;
|
1153 |
+
function execFile(file: string, args?: readonly string[] | null): ChildProcess;
|
1154 |
+
function execFile(
|
1155 |
+
file: string,
|
1156 |
+
args: readonly string[] | undefined | null,
|
1157 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1158 |
+
): ChildProcess;
|
1159 |
+
// no `options` definitely means stdout/stderr are `string`.
|
1160 |
+
function execFile(
|
1161 |
+
file: string,
|
1162 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1163 |
+
): ChildProcess;
|
1164 |
+
function execFile(
|
1165 |
+
file: string,
|
1166 |
+
args: readonly string[] | undefined | null,
|
1167 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1168 |
+
): ChildProcess;
|
1169 |
+
// `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
|
1170 |
+
function execFile(
|
1171 |
+
file: string,
|
1172 |
+
options: ExecFileOptionsWithBufferEncoding,
|
1173 |
+
callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void,
|
1174 |
+
): ChildProcess;
|
1175 |
+
function execFile(
|
1176 |
+
file: string,
|
1177 |
+
args: readonly string[] | undefined | null,
|
1178 |
+
options: ExecFileOptionsWithBufferEncoding,
|
1179 |
+
callback: (error: ExecFileException | null, stdout: Buffer, stderr: Buffer) => void,
|
1180 |
+
): ChildProcess;
|
1181 |
+
// `options` with well known `encoding` means stdout/stderr are definitely `string`.
|
1182 |
+
function execFile(
|
1183 |
+
file: string,
|
1184 |
+
options: ExecFileOptionsWithStringEncoding,
|
1185 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1186 |
+
): ChildProcess;
|
1187 |
+
function execFile(
|
1188 |
+
file: string,
|
1189 |
+
args: readonly string[] | undefined | null,
|
1190 |
+
options: ExecFileOptionsWithStringEncoding,
|
1191 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1192 |
+
): ChildProcess;
|
1193 |
+
// `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
|
1194 |
+
// There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
|
1195 |
+
function execFile(
|
1196 |
+
file: string,
|
1197 |
+
options: ExecFileOptionsWithOtherEncoding,
|
1198 |
+
callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
1199 |
+
): ChildProcess;
|
1200 |
+
function execFile(
|
1201 |
+
file: string,
|
1202 |
+
args: readonly string[] | undefined | null,
|
1203 |
+
options: ExecFileOptionsWithOtherEncoding,
|
1204 |
+
callback: (error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void,
|
1205 |
+
): ChildProcess;
|
1206 |
+
// `options` without an `encoding` means stdout/stderr are definitely `string`.
|
1207 |
+
function execFile(
|
1208 |
+
file: string,
|
1209 |
+
options: ExecFileOptions,
|
1210 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1211 |
+
): ChildProcess;
|
1212 |
+
function execFile(
|
1213 |
+
file: string,
|
1214 |
+
args: readonly string[] | undefined | null,
|
1215 |
+
options: ExecFileOptions,
|
1216 |
+
callback: (error: ExecFileException | null, stdout: string, stderr: string) => void,
|
1217 |
+
): ChildProcess;
|
1218 |
+
// fallback if nothing else matches. Worst case is always `string | Buffer`.
|
1219 |
+
function execFile(
|
1220 |
+
file: string,
|
1221 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1222 |
+
callback:
|
1223 |
+
| ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void)
|
1224 |
+
| undefined
|
1225 |
+
| null,
|
1226 |
+
): ChildProcess;
|
1227 |
+
function execFile(
|
1228 |
+
file: string,
|
1229 |
+
args: readonly string[] | undefined | null,
|
1230 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1231 |
+
callback:
|
1232 |
+
| ((error: ExecFileException | null, stdout: string | Buffer, stderr: string | Buffer) => void)
|
1233 |
+
| undefined
|
1234 |
+
| null,
|
1235 |
+
): ChildProcess;
|
1236 |
+
namespace execFile {
|
1237 |
+
function __promisify__(file: string): PromiseWithChild<{
|
1238 |
+
stdout: string;
|
1239 |
+
stderr: string;
|
1240 |
+
}>;
|
1241 |
+
function __promisify__(
|
1242 |
+
file: string,
|
1243 |
+
args: readonly string[] | undefined | null,
|
1244 |
+
): PromiseWithChild<{
|
1245 |
+
stdout: string;
|
1246 |
+
stderr: string;
|
1247 |
+
}>;
|
1248 |
+
function __promisify__(
|
1249 |
+
file: string,
|
1250 |
+
options: ExecFileOptionsWithBufferEncoding,
|
1251 |
+
): PromiseWithChild<{
|
1252 |
+
stdout: Buffer;
|
1253 |
+
stderr: Buffer;
|
1254 |
+
}>;
|
1255 |
+
function __promisify__(
|
1256 |
+
file: string,
|
1257 |
+
args: readonly string[] | undefined | null,
|
1258 |
+
options: ExecFileOptionsWithBufferEncoding,
|
1259 |
+
): PromiseWithChild<{
|
1260 |
+
stdout: Buffer;
|
1261 |
+
stderr: Buffer;
|
1262 |
+
}>;
|
1263 |
+
function __promisify__(
|
1264 |
+
file: string,
|
1265 |
+
options: ExecFileOptionsWithStringEncoding,
|
1266 |
+
): PromiseWithChild<{
|
1267 |
+
stdout: string;
|
1268 |
+
stderr: string;
|
1269 |
+
}>;
|
1270 |
+
function __promisify__(
|
1271 |
+
file: string,
|
1272 |
+
args: readonly string[] | undefined | null,
|
1273 |
+
options: ExecFileOptionsWithStringEncoding,
|
1274 |
+
): PromiseWithChild<{
|
1275 |
+
stdout: string;
|
1276 |
+
stderr: string;
|
1277 |
+
}>;
|
1278 |
+
function __promisify__(
|
1279 |
+
file: string,
|
1280 |
+
options: ExecFileOptionsWithOtherEncoding,
|
1281 |
+
): PromiseWithChild<{
|
1282 |
+
stdout: string | Buffer;
|
1283 |
+
stderr: string | Buffer;
|
1284 |
+
}>;
|
1285 |
+
function __promisify__(
|
1286 |
+
file: string,
|
1287 |
+
args: readonly string[] | undefined | null,
|
1288 |
+
options: ExecFileOptionsWithOtherEncoding,
|
1289 |
+
): PromiseWithChild<{
|
1290 |
+
stdout: string | Buffer;
|
1291 |
+
stderr: string | Buffer;
|
1292 |
+
}>;
|
1293 |
+
function __promisify__(
|
1294 |
+
file: string,
|
1295 |
+
options: ExecFileOptions,
|
1296 |
+
): PromiseWithChild<{
|
1297 |
+
stdout: string;
|
1298 |
+
stderr: string;
|
1299 |
+
}>;
|
1300 |
+
function __promisify__(
|
1301 |
+
file: string,
|
1302 |
+
args: readonly string[] | undefined | null,
|
1303 |
+
options: ExecFileOptions,
|
1304 |
+
): PromiseWithChild<{
|
1305 |
+
stdout: string;
|
1306 |
+
stderr: string;
|
1307 |
+
}>;
|
1308 |
+
function __promisify__(
|
1309 |
+
file: string,
|
1310 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1311 |
+
): PromiseWithChild<{
|
1312 |
+
stdout: string | Buffer;
|
1313 |
+
stderr: string | Buffer;
|
1314 |
+
}>;
|
1315 |
+
function __promisify__(
|
1316 |
+
file: string,
|
1317 |
+
args: readonly string[] | undefined | null,
|
1318 |
+
options: (ObjectEncodingOptions & ExecFileOptions) | undefined | null,
|
1319 |
+
): PromiseWithChild<{
|
1320 |
+
stdout: string | Buffer;
|
1321 |
+
stderr: string | Buffer;
|
1322 |
+
}>;
|
1323 |
+
}
|
1324 |
+
interface ForkOptions extends ProcessEnvOptions, MessagingOptions, Abortable {
|
1325 |
+
execPath?: string | undefined;
|
1326 |
+
execArgv?: string[] | undefined;
|
1327 |
+
silent?: boolean | undefined;
|
1328 |
+
/**
|
1329 |
+
* Can be set to 'pipe', 'inherit', 'overlapped', or 'ignore', or an array of these strings.
|
1330 |
+
* If passed as an array, the first element is used for `stdin`, the second for
|
1331 |
+
* `stdout`, and the third for `stderr`. A fourth element can be used to
|
1332 |
+
* specify the `stdio` behavior beyond the standard streams. See
|
1333 |
+
* {@link ChildProcess.stdio} for more information.
|
1334 |
+
*
|
1335 |
+
* @default 'pipe'
|
1336 |
+
*/
|
1337 |
+
stdio?: StdioOptions | undefined;
|
1338 |
+
detached?: boolean | undefined;
|
1339 |
+
windowsVerbatimArguments?: boolean | undefined;
|
1340 |
+
}
|
1341 |
+
/**
|
1342 |
+
* The `child_process.fork()` method is a special case of {@link spawn} used specifically to spawn new Node.js processes.
|
1343 |
+
* Like {@link spawn}, a `ChildProcess` object is returned. The
|
1344 |
+
* returned `ChildProcess` will have an additional communication channel
|
1345 |
+
* built-in that allows messages to be passed back and forth between the parent and
|
1346 |
+
* child. See `subprocess.send()` for details.
|
1347 |
+
*
|
1348 |
+
* Keep in mind that spawned Node.js child processes are
|
1349 |
+
* independent of the parent with exception of the IPC communication channel
|
1350 |
+
* that is established between the two. Each process has its own memory, with
|
1351 |
+
* their own V8 instances. Because of the additional resource allocations
|
1352 |
+
* required, spawning a large number of child Node.js processes is not
|
1353 |
+
* recommended.
|
1354 |
+
*
|
1355 |
+
* 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
|
1356 |
+
* execution path to be used.
|
1357 |
+
*
|
1358 |
+
* Node.js processes launched with a custom `execPath` will communicate with the
|
1359 |
+
* parent process using the file descriptor (fd) identified using the
|
1360 |
+
* environment variable `NODE_CHANNEL_FD` on the child process.
|
1361 |
+
*
|
1362 |
+
* Unlike the [`fork(2)`](http://man7.org/linux/man-pages/man2/fork.2.html) POSIX system call, `child_process.fork()` does not clone the
|
1363 |
+
* current process.
|
1364 |
+
*
|
1365 |
+
* The `shell` option available in {@link spawn} is not supported by`child_process.fork()` and will be ignored if set.
|
1366 |
+
*
|
1367 |
+
* If the `signal` option is enabled, calling `.abort()` on the corresponding`AbortController` is similar to calling `.kill()` on the child process except
|
1368 |
+
* the error passed to the callback will be an `AbortError`:
|
1369 |
+
*
|
1370 |
+
* ```js
|
1371 |
+
* if (process.argv[2] === 'child') {
|
1372 |
+
* setTimeout(() => {
|
1373 |
+
* console.log(`Hello from ${process.argv[2]}!`);
|
1374 |
+
* }, 1_000);
|
1375 |
+
* } else {
|
1376 |
+
* const { fork } = require('node:child_process');
|
1377 |
+
* const controller = new AbortController();
|
1378 |
+
* const { signal } = controller;
|
1379 |
+
* const child = fork(__filename, ['child'], { signal });
|
1380 |
+
* child.on('error', (err) => {
|
1381 |
+
* // This will be called with err being an AbortError if the controller aborts
|
1382 |
+
* });
|
1383 |
+
* controller.abort(); // Stops the child process
|
1384 |
+
* }
|
1385 |
+
* ```
|
1386 |
+
* @since v0.5.0
|
1387 |
+
* @param modulePath The module to run in the child.
|
1388 |
+
* @param args List of string arguments.
|
1389 |
+
*/
|
1390 |
+
function fork(modulePath: string, options?: ForkOptions): ChildProcess;
|
1391 |
+
function fork(modulePath: string, args?: readonly string[], options?: ForkOptions): ChildProcess;
|
1392 |
+
interface SpawnSyncOptions extends CommonSpawnOptions {
|
1393 |
+
input?: string | NodeJS.ArrayBufferView | undefined;
|
1394 |
+
maxBuffer?: number | undefined;
|
1395 |
+
encoding?: BufferEncoding | "buffer" | null | undefined;
|
1396 |
+
}
|
1397 |
+
interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions {
|
1398 |
+
encoding: BufferEncoding;
|
1399 |
+
}
|
1400 |
+
interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions {
|
1401 |
+
encoding?: "buffer" | null | undefined;
|
1402 |
+
}
|
1403 |
+
interface SpawnSyncReturns<T> {
|
1404 |
+
pid: number;
|
1405 |
+
output: Array<T | null>;
|
1406 |
+
stdout: T;
|
1407 |
+
stderr: T;
|
1408 |
+
status: number | null;
|
1409 |
+
signal: NodeJS.Signals | null;
|
1410 |
+
error?: Error | undefined;
|
1411 |
+
}
|
1412 |
+
/**
|
1413 |
+
* The `child_process.spawnSync()` method is generally identical to {@link spawn} with the exception that the function will not return
|
1414 |
+
* until the child process has fully closed. When a timeout has been encountered
|
1415 |
+
* and `killSignal` is sent, the method won't return until the process has
|
1416 |
+
* completely exited. If the process intercepts and handles the `SIGTERM` signal
|
1417 |
+
* and doesn't exit, the parent process will wait until the child process has
|
1418 |
+
* exited.
|
1419 |
+
*
|
1420 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
1421 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
1422 |
+
* **arbitrary command execution.**
|
1423 |
+
* @since v0.11.12
|
1424 |
+
* @param command The command to run.
|
1425 |
+
* @param args List of string arguments.
|
1426 |
+
*/
|
1427 |
+
function spawnSync(command: string): SpawnSyncReturns<Buffer>;
|
1428 |
+
function spawnSync(command: string, options: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns<string>;
|
1429 |
+
function spawnSync(command: string, options: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns<Buffer>;
|
1430 |
+
function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns<string | Buffer>;
|
1431 |
+
function spawnSync(command: string, args: readonly string[]): SpawnSyncReturns<Buffer>;
|
1432 |
+
function spawnSync(
|
1433 |
+
command: string,
|
1434 |
+
args: readonly string[],
|
1435 |
+
options: SpawnSyncOptionsWithStringEncoding,
|
1436 |
+
): SpawnSyncReturns<string>;
|
1437 |
+
function spawnSync(
|
1438 |
+
command: string,
|
1439 |
+
args: readonly string[],
|
1440 |
+
options: SpawnSyncOptionsWithBufferEncoding,
|
1441 |
+
): SpawnSyncReturns<Buffer>;
|
1442 |
+
function spawnSync(
|
1443 |
+
command: string,
|
1444 |
+
args?: readonly string[],
|
1445 |
+
options?: SpawnSyncOptions,
|
1446 |
+
): SpawnSyncReturns<string | Buffer>;
|
1447 |
+
interface CommonExecOptions extends CommonOptions {
|
1448 |
+
input?: string | NodeJS.ArrayBufferView | undefined;
|
1449 |
+
/**
|
1450 |
+
* Can be set to 'pipe', 'inherit, or 'ignore', or an array of these strings.
|
1451 |
+
* If passed as an array, the first element is used for `stdin`, the second for
|
1452 |
+
* `stdout`, and the third for `stderr`. A fourth element can be used to
|
1453 |
+
* specify the `stdio` behavior beyond the standard streams. See
|
1454 |
+
* {@link ChildProcess.stdio} for more information.
|
1455 |
+
*
|
1456 |
+
* @default 'pipe'
|
1457 |
+
*/
|
1458 |
+
stdio?: StdioOptions | undefined;
|
1459 |
+
killSignal?: NodeJS.Signals | number | undefined;
|
1460 |
+
maxBuffer?: number | undefined;
|
1461 |
+
encoding?: BufferEncoding | "buffer" | null | undefined;
|
1462 |
+
}
|
1463 |
+
interface ExecSyncOptions extends CommonExecOptions {
|
1464 |
+
shell?: string | undefined;
|
1465 |
+
}
|
1466 |
+
interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions {
|
1467 |
+
encoding: BufferEncoding;
|
1468 |
+
}
|
1469 |
+
interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions {
|
1470 |
+
encoding?: "buffer" | null | undefined;
|
1471 |
+
}
|
1472 |
+
/**
|
1473 |
+
* The `child_process.execSync()` method is generally identical to {@link exec} with the exception that the method will not return
|
1474 |
+
* until the child process has fully closed. When a timeout has been encountered
|
1475 |
+
* and `killSignal` is sent, the method won't return until the process has
|
1476 |
+
* 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
|
1477 |
+
* has exited.
|
1478 |
+
*
|
1479 |
+
* If the process times out or has a non-zero exit code, this method will throw.
|
1480 |
+
* The `Error` object will contain the entire result from {@link spawnSync}.
|
1481 |
+
*
|
1482 |
+
* **Never pass unsanitized user input to this function. Any input containing shell**
|
1483 |
+
* **metacharacters may be used to trigger arbitrary command execution.**
|
1484 |
+
* @since v0.11.12
|
1485 |
+
* @param command The command to run.
|
1486 |
+
* @return The stdout from the command.
|
1487 |
+
*/
|
1488 |
+
function execSync(command: string): Buffer;
|
1489 |
+
function execSync(command: string, options: ExecSyncOptionsWithStringEncoding): string;
|
1490 |
+
function execSync(command: string, options: ExecSyncOptionsWithBufferEncoding): Buffer;
|
1491 |
+
function execSync(command: string, options?: ExecSyncOptions): string | Buffer;
|
1492 |
+
interface ExecFileSyncOptions extends CommonExecOptions {
|
1493 |
+
shell?: boolean | string | undefined;
|
1494 |
+
}
|
1495 |
+
interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions {
|
1496 |
+
encoding: BufferEncoding;
|
1497 |
+
}
|
1498 |
+
interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions {
|
1499 |
+
encoding?: "buffer" | null; // specify `null`.
|
1500 |
+
}
|
1501 |
+
/**
|
1502 |
+
* The `child_process.execFileSync()` method is generally identical to {@link execFile} with the exception that the method will not
|
1503 |
+
* return until the child process has fully closed. When a timeout has been
|
1504 |
+
* encountered and `killSignal` is sent, the method won't return until the process
|
1505 |
+
* has completely exited.
|
1506 |
+
*
|
1507 |
+
* If the child process intercepts and handles the `SIGTERM` signal and
|
1508 |
+
* does not exit, the parent process will still wait until the child process has
|
1509 |
+
* exited.
|
1510 |
+
*
|
1511 |
+
* 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}.
|
1512 |
+
*
|
1513 |
+
* **If the `shell` option is enabled, do not pass unsanitized user input to this**
|
1514 |
+
* **function. Any input containing shell metacharacters may be used to trigger**
|
1515 |
+
* **arbitrary command execution.**
|
1516 |
+
* @since v0.11.12
|
1517 |
+
* @param file The name or path of the executable file to run.
|
1518 |
+
* @param args List of string arguments.
|
1519 |
+
* @return The stdout from the command.
|
1520 |
+
*/
|
1521 |
+
function execFileSync(file: string): Buffer;
|
1522 |
+
function execFileSync(file: string, options: ExecFileSyncOptionsWithStringEncoding): string;
|
1523 |
+
function execFileSync(file: string, options: ExecFileSyncOptionsWithBufferEncoding): Buffer;
|
1524 |
+
function execFileSync(file: string, options?: ExecFileSyncOptions): string | Buffer;
|
1525 |
+
function execFileSync(file: string, args: readonly string[]): Buffer;
|
1526 |
+
function execFileSync(
|
1527 |
+
file: string,
|
1528 |
+
args: readonly string[],
|
1529 |
+
options: ExecFileSyncOptionsWithStringEncoding,
|
1530 |
+
): string;
|
1531 |
+
function execFileSync(
|
1532 |
+
file: string,
|
1533 |
+
args: readonly string[],
|
1534 |
+
options: ExecFileSyncOptionsWithBufferEncoding,
|
1535 |
+
): Buffer;
|
1536 |
+
function execFileSync(file: string, args?: readonly string[], options?: ExecFileSyncOptions): string | Buffer;
|
1537 |
+
}
|
1538 |
+
declare module "node:child_process" {
|
1539 |
+
export * from "child_process";
|
1540 |
+
}
|
node_modules/@types/node/cluster.d.ts
ADDED
@@ -0,0 +1,432 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Clusters of Node.js processes can be used to run multiple instances of Node.js
|
3 |
+
* that can distribute workloads among their application threads. When process
|
4 |
+
* isolation is not needed, use the `worker_threads` module instead, which
|
5 |
+
* allows running multiple application threads within a single Node.js instance.
|
6 |
+
*
|
7 |
+
* The cluster module allows easy creation of child processes that all share
|
8 |
+
* server ports.
|
9 |
+
*
|
10 |
+
* ```js
|
11 |
+
* import cluster from 'node:cluster';
|
12 |
+
* import http from 'node:http';
|
13 |
+
* import { availableParallelism } from 'node:os';
|
14 |
+
* import process from 'node:process';
|
15 |
+
*
|
16 |
+
* const numCPUs = availableParallelism();
|
17 |
+
*
|
18 |
+
* if (cluster.isPrimary) {
|
19 |
+
* console.log(`Primary ${process.pid} is running`);
|
20 |
+
*
|
21 |
+
* // Fork workers.
|
22 |
+
* for (let i = 0; i < numCPUs; i++) {
|
23 |
+
* cluster.fork();
|
24 |
+
* }
|
25 |
+
*
|
26 |
+
* cluster.on('exit', (worker, code, signal) => {
|
27 |
+
* console.log(`worker ${worker.process.pid} died`);
|
28 |
+
* });
|
29 |
+
* } else {
|
30 |
+
* // Workers can share any TCP connection
|
31 |
+
* // In this case it is an HTTP server
|
32 |
+
* http.createServer((req, res) => {
|
33 |
+
* res.writeHead(200);
|
34 |
+
* res.end('hello world\n');
|
35 |
+
* }).listen(8000);
|
36 |
+
*
|
37 |
+
* console.log(`Worker ${process.pid} started`);
|
38 |
+
* }
|
39 |
+
* ```
|
40 |
+
*
|
41 |
+
* Running Node.js will now share port 8000 between the workers:
|
42 |
+
*
|
43 |
+
* ```console
|
44 |
+
* $ node server.js
|
45 |
+
* Primary 3596 is running
|
46 |
+
* Worker 4324 started
|
47 |
+
* Worker 4520 started
|
48 |
+
* Worker 6056 started
|
49 |
+
* Worker 5644 started
|
50 |
+
* ```
|
51 |
+
*
|
52 |
+
* On Windows, it is not yet possible to set up a named pipe server in a worker.
|
53 |
+
* @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/cluster.js)
|
54 |
+
*/
|
55 |
+
declare module "cluster" {
|
56 |
+
import * as child from "node:child_process";
|
57 |
+
import EventEmitter = require("node:events");
|
58 |
+
import * as net from "node:net";
|
59 |
+
type SerializationType = "json" | "advanced";
|
60 |
+
export interface ClusterSettings {
|
61 |
+
execArgv?: string[] | undefined; // default: process.execArgv
|
62 |
+
exec?: string | undefined;
|
63 |
+
args?: string[] | undefined;
|
64 |
+
silent?: boolean | undefined;
|
65 |
+
stdio?: any[] | undefined;
|
66 |
+
uid?: number | undefined;
|
67 |
+
gid?: number | undefined;
|
68 |
+
inspectPort?: number | (() => number) | undefined;
|
69 |
+
serialization?: SerializationType | undefined;
|
70 |
+
cwd?: string | undefined;
|
71 |
+
windowsHide?: boolean | undefined;
|
72 |
+
}
|
73 |
+
export interface Address {
|
74 |
+
address: string;
|
75 |
+
port: number;
|
76 |
+
addressType: number | "udp4" | "udp6"; // 4, 6, -1, "udp4", "udp6"
|
77 |
+
}
|
78 |
+
/**
|
79 |
+
* A `Worker` object contains all public information and method about a worker.
|
80 |
+
* In the primary it can be obtained using `cluster.workers`. In a worker
|
81 |
+
* it can be obtained using `cluster.worker`.
|
82 |
+
* @since v0.7.0
|
83 |
+
*/
|
84 |
+
export class Worker extends EventEmitter {
|
85 |
+
/**
|
86 |
+
* Each new worker is given its own unique id, this id is stored in the`id`.
|
87 |
+
*
|
88 |
+
* While a worker is alive, this is the key that indexes it in`cluster.workers`.
|
89 |
+
* @since v0.8.0
|
90 |
+
*/
|
91 |
+
id: number;
|
92 |
+
/**
|
93 |
+
* All workers are created using `child_process.fork()`, the returned object
|
94 |
+
* from this function is stored as `.process`. In a worker, the global `process`is stored.
|
95 |
+
*
|
96 |
+
* See: `Child Process module`.
|
97 |
+
*
|
98 |
+
* Workers will call `process.exit(0)` if the `'disconnect'` event occurs
|
99 |
+
* on `process` and `.exitedAfterDisconnect` is not `true`. This protects against
|
100 |
+
* accidental disconnection.
|
101 |
+
* @since v0.7.0
|
102 |
+
*/
|
103 |
+
process: child.ChildProcess;
|
104 |
+
/**
|
105 |
+
* Send a message to a worker or primary, optionally with a handle.
|
106 |
+
*
|
107 |
+
* In the primary, this sends a message to a specific worker. It is identical to `ChildProcess.send()`.
|
108 |
+
*
|
109 |
+
* In a worker, this sends a message to the primary. It is identical to`process.send()`.
|
110 |
+
*
|
111 |
+
* This example will echo back all messages from the primary:
|
112 |
+
*
|
113 |
+
* ```js
|
114 |
+
* if (cluster.isPrimary) {
|
115 |
+
* const worker = cluster.fork();
|
116 |
+
* worker.send('hi there');
|
117 |
+
*
|
118 |
+
* } else if (cluster.isWorker) {
|
119 |
+
* process.on('message', (msg) => {
|
120 |
+
* process.send(msg);
|
121 |
+
* });
|
122 |
+
* }
|
123 |
+
* ```
|
124 |
+
* @since v0.7.0
|
125 |
+
* @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:
|
126 |
+
*/
|
127 |
+
send(message: child.Serializable, callback?: (error: Error | null) => void): boolean;
|
128 |
+
send(
|
129 |
+
message: child.Serializable,
|
130 |
+
sendHandle: child.SendHandle,
|
131 |
+
callback?: (error: Error | null) => void,
|
132 |
+
): boolean;
|
133 |
+
send(
|
134 |
+
message: child.Serializable,
|
135 |
+
sendHandle: child.SendHandle,
|
136 |
+
options?: child.MessageOptions,
|
137 |
+
callback?: (error: Error | null) => void,
|
138 |
+
): boolean;
|
139 |
+
/**
|
140 |
+
* This function will kill the worker. In the primary worker, it does this by
|
141 |
+
* disconnecting the `worker.process`, and once disconnected, killing with`signal`. In the worker, it does it by killing the process with `signal`.
|
142 |
+
*
|
143 |
+
* The `kill()` function kills the worker process without waiting for a graceful
|
144 |
+
* disconnect, it has the same behavior as `worker.process.kill()`.
|
145 |
+
*
|
146 |
+
* This method is aliased as `worker.destroy()` for backwards compatibility.
|
147 |
+
*
|
148 |
+
* In a worker, `process.kill()` exists, but it is not this function;
|
149 |
+
* it is `kill()`.
|
150 |
+
* @since v0.9.12
|
151 |
+
* @param [signal='SIGTERM'] Name of the kill signal to send to the worker process.
|
152 |
+
*/
|
153 |
+
kill(signal?: string): void;
|
154 |
+
destroy(signal?: string): void;
|
155 |
+
/**
|
156 |
+
* In a worker, this function will close all servers, wait for the `'close'` event
|
157 |
+
* on those servers, and then disconnect the IPC channel.
|
158 |
+
*
|
159 |
+
* In the primary, an internal message is sent to the worker causing it to call`.disconnect()` on itself.
|
160 |
+
*
|
161 |
+
* Causes `.exitedAfterDisconnect` to be set.
|
162 |
+
*
|
163 |
+
* After a server is closed, it will no longer accept new connections,
|
164 |
+
* but connections may be accepted by any other listening worker. Existing
|
165 |
+
* connections will be allowed to close as usual. When no more connections exist,
|
166 |
+
* see `server.close()`, the IPC channel to the worker will close allowing it
|
167 |
+
* to die gracefully.
|
168 |
+
*
|
169 |
+
* The above applies _only_ to server connections, client connections are not
|
170 |
+
* automatically closed by workers, and disconnect does not wait for them to close
|
171 |
+
* before exiting.
|
172 |
+
*
|
173 |
+
* In a worker, `process.disconnect` exists, but it is not this function;
|
174 |
+
* it is `disconnect()`.
|
175 |
+
*
|
176 |
+
* Because long living server connections may block workers from disconnecting, it
|
177 |
+
* may be useful to send a message, so application specific actions may be taken to
|
178 |
+
* close them. It also may be useful to implement a timeout, killing a worker if
|
179 |
+
* the `'disconnect'` event has not been emitted after some time.
|
180 |
+
*
|
181 |
+
* ```js
|
182 |
+
* if (cluster.isPrimary) {
|
183 |
+
* const worker = cluster.fork();
|
184 |
+
* let timeout;
|
185 |
+
*
|
186 |
+
* worker.on('listening', (address) => {
|
187 |
+
* worker.send('shutdown');
|
188 |
+
* worker.disconnect();
|
189 |
+
* timeout = setTimeout(() => {
|
190 |
+
* worker.kill();
|
191 |
+
* }, 2000);
|
192 |
+
* });
|
193 |
+
*
|
194 |
+
* worker.on('disconnect', () => {
|
195 |
+
* clearTimeout(timeout);
|
196 |
+
* });
|
197 |
+
*
|
198 |
+
* } else if (cluster.isWorker) {
|
199 |
+
* const net = require('node:net');
|
200 |
+
* const server = net.createServer((socket) => {
|
201 |
+
* // Connections never end
|
202 |
+
* });
|
203 |
+
*
|
204 |
+
* server.listen(8000);
|
205 |
+
*
|
206 |
+
* process.on('message', (msg) => {
|
207 |
+
* if (msg === 'shutdown') {
|
208 |
+
* // Initiate graceful close of any connections to server
|
209 |
+
* }
|
210 |
+
* });
|
211 |
+
* }
|
212 |
+
* ```
|
213 |
+
* @since v0.7.7
|
214 |
+
* @return A reference to `worker`.
|
215 |
+
*/
|
216 |
+
disconnect(): void;
|
217 |
+
/**
|
218 |
+
* This function returns `true` if the worker is connected to its primary via its
|
219 |
+
* IPC channel, `false` otherwise. A worker is connected to its primary after it
|
220 |
+
* has been created. It is disconnected after the `'disconnect'` event is emitted.
|
221 |
+
* @since v0.11.14
|
222 |
+
*/
|
223 |
+
isConnected(): boolean;
|
224 |
+
/**
|
225 |
+
* This function returns `true` if the worker's process has terminated (either
|
226 |
+
* because of exiting or being signaled). Otherwise, it returns `false`.
|
227 |
+
*
|
228 |
+
* ```js
|
229 |
+
* import cluster from 'node:cluster';
|
230 |
+
* import http from 'node:http';
|
231 |
+
* import { availableParallelism } from 'node:os';
|
232 |
+
* import process from 'node:process';
|
233 |
+
*
|
234 |
+
* const numCPUs = availableParallelism();
|
235 |
+
*
|
236 |
+
* if (cluster.isPrimary) {
|
237 |
+
* console.log(`Primary ${process.pid} is running`);
|
238 |
+
*
|
239 |
+
* // Fork workers.
|
240 |
+
* for (let i = 0; i < numCPUs; i++) {
|
241 |
+
* cluster.fork();
|
242 |
+
* }
|
243 |
+
*
|
244 |
+
* cluster.on('fork', (worker) => {
|
245 |
+
* console.log('worker is dead:', worker.isDead());
|
246 |
+
* });
|
247 |
+
*
|
248 |
+
* cluster.on('exit', (worker, code, signal) => {
|
249 |
+
* console.log('worker is dead:', worker.isDead());
|
250 |
+
* });
|
251 |
+
* } else {
|
252 |
+
* // Workers can share any TCP connection. In this case, it is an HTTP server.
|
253 |
+
* http.createServer((req, res) => {
|
254 |
+
* res.writeHead(200);
|
255 |
+
* res.end(`Current process\n ${process.pid}`);
|
256 |
+
* process.kill(process.pid);
|
257 |
+
* }).listen(8000);
|
258 |
+
* }
|
259 |
+
* ```
|
260 |
+
* @since v0.11.14
|
261 |
+
*/
|
262 |
+
isDead(): boolean;
|
263 |
+
/**
|
264 |
+
* This property is `true` if the worker exited due to `.disconnect()`.
|
265 |
+
* If the worker exited any other way, it is `false`. If the
|
266 |
+
* worker has not exited, it is `undefined`.
|
267 |
+
*
|
268 |
+
* The boolean `worker.exitedAfterDisconnect` allows distinguishing between
|
269 |
+
* voluntary and accidental exit, the primary may choose not to respawn a worker
|
270 |
+
* based on this value.
|
271 |
+
*
|
272 |
+
* ```js
|
273 |
+
* cluster.on('exit', (worker, code, signal) => {
|
274 |
+
* if (worker.exitedAfterDisconnect === true) {
|
275 |
+
* console.log('Oh, it was just voluntary – no need to worry');
|
276 |
+
* }
|
277 |
+
* });
|
278 |
+
*
|
279 |
+
* // kill worker
|
280 |
+
* worker.kill();
|
281 |
+
* ```
|
282 |
+
* @since v6.0.0
|
283 |
+
*/
|
284 |
+
exitedAfterDisconnect: boolean;
|
285 |
+
/**
|
286 |
+
* events.EventEmitter
|
287 |
+
* 1. disconnect
|
288 |
+
* 2. error
|
289 |
+
* 3. exit
|
290 |
+
* 4. listening
|
291 |
+
* 5. message
|
292 |
+
* 6. online
|
293 |
+
*/
|
294 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
295 |
+
addListener(event: "disconnect", listener: () => void): this;
|
296 |
+
addListener(event: "error", listener: (error: Error) => void): this;
|
297 |
+
addListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
298 |
+
addListener(event: "listening", listener: (address: Address) => void): this;
|
299 |
+
addListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
300 |
+
addListener(event: "online", listener: () => void): this;
|
301 |
+
emit(event: string | symbol, ...args: any[]): boolean;
|
302 |
+
emit(event: "disconnect"): boolean;
|
303 |
+
emit(event: "error", error: Error): boolean;
|
304 |
+
emit(event: "exit", code: number, signal: string): boolean;
|
305 |
+
emit(event: "listening", address: Address): boolean;
|
306 |
+
emit(event: "message", message: any, handle: net.Socket | net.Server): boolean;
|
307 |
+
emit(event: "online"): boolean;
|
308 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
309 |
+
on(event: "disconnect", listener: () => void): this;
|
310 |
+
on(event: "error", listener: (error: Error) => void): this;
|
311 |
+
on(event: "exit", listener: (code: number, signal: string) => void): this;
|
312 |
+
on(event: "listening", listener: (address: Address) => void): this;
|
313 |
+
on(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
314 |
+
on(event: "online", listener: () => void): this;
|
315 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
316 |
+
once(event: "disconnect", listener: () => void): this;
|
317 |
+
once(event: "error", listener: (error: Error) => void): this;
|
318 |
+
once(event: "exit", listener: (code: number, signal: string) => void): this;
|
319 |
+
once(event: "listening", listener: (address: Address) => void): this;
|
320 |
+
once(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
321 |
+
once(event: "online", listener: () => void): this;
|
322 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
323 |
+
prependListener(event: "disconnect", listener: () => void): this;
|
324 |
+
prependListener(event: "error", listener: (error: Error) => void): this;
|
325 |
+
prependListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
326 |
+
prependListener(event: "listening", listener: (address: Address) => void): this;
|
327 |
+
prependListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
328 |
+
prependListener(event: "online", listener: () => void): this;
|
329 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
330 |
+
prependOnceListener(event: "disconnect", listener: () => void): this;
|
331 |
+
prependOnceListener(event: "error", listener: (error: Error) => void): this;
|
332 |
+
prependOnceListener(event: "exit", listener: (code: number, signal: string) => void): this;
|
333 |
+
prependOnceListener(event: "listening", listener: (address: Address) => void): this;
|
334 |
+
prependOnceListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
335 |
+
prependOnceListener(event: "online", listener: () => void): this;
|
336 |
+
}
|
337 |
+
export interface Cluster extends EventEmitter {
|
338 |
+
disconnect(callback?: () => void): void;
|
339 |
+
fork(env?: any): Worker;
|
340 |
+
/** @deprecated since v16.0.0 - use isPrimary. */
|
341 |
+
readonly isMaster: boolean;
|
342 |
+
readonly isPrimary: boolean;
|
343 |
+
readonly isWorker: boolean;
|
344 |
+
schedulingPolicy: number;
|
345 |
+
readonly settings: ClusterSettings;
|
346 |
+
/** @deprecated since v16.0.0 - use setupPrimary. */
|
347 |
+
setupMaster(settings?: ClusterSettings): void;
|
348 |
+
/**
|
349 |
+
* `setupPrimary` is used to change the default 'fork' behavior. Once called, the settings will be present in cluster.settings.
|
350 |
+
*/
|
351 |
+
setupPrimary(settings?: ClusterSettings): void;
|
352 |
+
readonly worker?: Worker | undefined;
|
353 |
+
readonly workers?: NodeJS.Dict<Worker> | undefined;
|
354 |
+
readonly SCHED_NONE: number;
|
355 |
+
readonly SCHED_RR: number;
|
356 |
+
/**
|
357 |
+
* events.EventEmitter
|
358 |
+
* 1. disconnect
|
359 |
+
* 2. exit
|
360 |
+
* 3. fork
|
361 |
+
* 4. listening
|
362 |
+
* 5. message
|
363 |
+
* 6. online
|
364 |
+
* 7. setup
|
365 |
+
*/
|
366 |
+
addListener(event: string, listener: (...args: any[]) => void): this;
|
367 |
+
addListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
368 |
+
addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
369 |
+
addListener(event: "fork", listener: (worker: Worker) => void): this;
|
370 |
+
addListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
371 |
+
addListener(
|
372 |
+
event: "message",
|
373 |
+
listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void,
|
374 |
+
): this; // the handle is a net.Socket or net.Server object, or undefined.
|
375 |
+
addListener(event: "online", listener: (worker: Worker) => void): this;
|
376 |
+
addListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
377 |
+
emit(event: string | symbol, ...args: any[]): boolean;
|
378 |
+
emit(event: "disconnect", worker: Worker): boolean;
|
379 |
+
emit(event: "exit", worker: Worker, code: number, signal: string): boolean;
|
380 |
+
emit(event: "fork", worker: Worker): boolean;
|
381 |
+
emit(event: "listening", worker: Worker, address: Address): boolean;
|
382 |
+
emit(event: "message", worker: Worker, message: any, handle: net.Socket | net.Server): boolean;
|
383 |
+
emit(event: "online", worker: Worker): boolean;
|
384 |
+
emit(event: "setup", settings: ClusterSettings): boolean;
|
385 |
+
on(event: string, listener: (...args: any[]) => void): this;
|
386 |
+
on(event: "disconnect", listener: (worker: Worker) => void): this;
|
387 |
+
on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
388 |
+
on(event: "fork", listener: (worker: Worker) => void): this;
|
389 |
+
on(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
390 |
+
on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
391 |
+
on(event: "online", listener: (worker: Worker) => void): this;
|
392 |
+
on(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
393 |
+
once(event: string, listener: (...args: any[]) => void): this;
|
394 |
+
once(event: "disconnect", listener: (worker: Worker) => void): this;
|
395 |
+
once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
396 |
+
once(event: "fork", listener: (worker: Worker) => void): this;
|
397 |
+
once(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
398 |
+
once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
|
399 |
+
once(event: "online", listener: (worker: Worker) => void): this;
|
400 |
+
once(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
401 |
+
prependListener(event: string, listener: (...args: any[]) => void): this;
|
402 |
+
prependListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
403 |
+
prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
404 |
+
prependListener(event: "fork", listener: (worker: Worker) => void): this;
|
405 |
+
prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
406 |
+
// the handle is a net.Socket or net.Server object, or undefined.
|
407 |
+
prependListener(
|
408 |
+
event: "message",
|
409 |
+
listener: (worker: Worker, message: any, handle?: net.Socket | net.Server) => void,
|
410 |
+
): this;
|
411 |
+
prependListener(event: "online", listener: (worker: Worker) => void): this;
|
412 |
+
prependListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
413 |
+
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
414 |
+
prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): this;
|
415 |
+
prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
|
416 |
+
prependOnceListener(event: "fork", listener: (worker: Worker) => void): this;
|
417 |
+
prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): this;
|
418 |
+
// the handle is a net.Socket or net.Server object, or undefined.
|
419 |
+
prependOnceListener(
|
420 |
+
event: "message",
|
421 |
+
listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void,
|
422 |
+
): this;
|
423 |
+
prependOnceListener(event: "online", listener: (worker: Worker) => void): this;
|
424 |
+
prependOnceListener(event: "setup", listener: (settings: ClusterSettings) => void): this;
|
425 |
+
}
|
426 |
+
const cluster: Cluster;
|
427 |
+
export default cluster;
|
428 |
+
}
|
429 |
+
declare module "node:cluster" {
|
430 |
+
export * from "cluster";
|
431 |
+
export { default as default } from "cluster";
|
432 |
+
}
|