wispjs 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/{wisp.ts → dist/wisp.d.ts} +11 -28
- package/dist/wisp.js +34 -0
- package/dist/wisp_api/apis/allocations.d.ts +55 -0
- package/dist/wisp_api/apis/allocations.js +32 -0
- package/dist/wisp_api/apis/audit_log.d.ts +68 -0
- package/dist/wisp_api/apis/audit_log.js +21 -0
- package/{wisp_api/apis/backups.ts → dist/wisp_api/apis/backups.d.ts} +13 -51
- package/dist/wisp_api/apis/backups.js +93 -0
- package/dist/wisp_api/apis/databases.d.ts +61 -0
- package/dist/wisp_api/apis/databases.js +43 -0
- package/dist/wisp_api/apis/fastdl.d.ts +19 -0
- package/dist/wisp_api/apis/fastdl.js +21 -0
- package/dist/wisp_api/apis/filesystem.d.ts +200 -0
- package/dist/wisp_api/apis/filesystem.js +182 -0
- package/dist/wisp_api/apis/index.d.ts +52 -0
- package/dist/wisp_api/apis/index.js +100 -0
- package/dist/wisp_api/apis/mods.d.ts +40 -0
- package/dist/wisp_api/apis/mods.js +30 -0
- package/dist/wisp_api/apis/schedules.d.ts +179 -0
- package/dist/wisp_api/apis/schedules.js +167 -0
- package/dist/wisp_api/apis/servers.d.ts +120 -0
- package/dist/wisp_api/apis/servers.js +76 -0
- package/dist/wisp_api/apis/startup.d.ts +52 -0
- package/dist/wisp_api/apis/startup.js +35 -0
- package/dist/wisp_api/apis/subusers.d.ts +106 -0
- package/dist/wisp_api/apis/subusers.js +87 -0
- package/dist/wisp_api/index.d.ts +39 -0
- package/dist/wisp_api/index.js +41 -0
- package/dist/wisp_socket/index.d.ts +161 -0
- package/{wisp_socket/index.ts → dist/wisp_socket/index.js} +130 -236
- package/dist/wisp_socket/pool.d.ts +183 -0
- package/dist/wisp_socket/pool.js +171 -0
- package/package.json +1 -1
- package/.github/workflows/release.yml +0 -72
- package/tsconfig.json +0 -19
- package/wisp_api/apis/allocations.ts +0 -71
- package/wisp_api/apis/audit_log.ts +0 -81
- package/wisp_api/apis/databases.ts +0 -80
- package/wisp_api/apis/fastdl.ts +0 -22
- package/wisp_api/apis/filesystem.ts +0 -291
- package/wisp_api/apis/index.ts +0 -135
- package/wisp_api/apis/mods.ts +0 -53
- package/wisp_api/apis/schedules.ts +0 -270
- package/wisp_api/apis/servers.ts +0 -155
- package/wisp_api/apis/startup.ts +0 -65
- package/wisp_api/apis/subusers.ts +0 -159
- package/wisp_api/index.ts +0 -57
- package/wisp_socket/pool.ts +0 -387
package/wisp_socket/pool.ts
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import { io, Socket, Manager } from "socket.io-client";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The struct used to define the events that can be sent from the server to the client
|
|
5
|
-
*
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export interface ServerToClientEvents {
|
|
9
|
-
"error": (message: string) => void;
|
|
10
|
-
"auth_success": (message: string) => void;
|
|
11
|
-
"filesearch-results": (data: FilesearchResults) => void;
|
|
12
|
-
"git-error": (data: string) => void;
|
|
13
|
-
"git-success": (message?: string) => void;
|
|
14
|
-
"git-clone": (data: GitCloneData) => void;
|
|
15
|
-
"git-pull": (data: GitPullData) => void;
|
|
16
|
-
"console": (message: ConsoleMessage) => void;
|
|
17
|
-
"initial status": (message: any) => void;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The struct used to define the events that can be sent from the client to the server
|
|
23
|
-
*
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export interface ClientToServerEvents {
|
|
27
|
-
"auth": (token: string) => void;
|
|
28
|
-
"filesearch-start": (query: string) => void;
|
|
29
|
-
"git-clone": (data: GitCloneData) => void;
|
|
30
|
-
"git-pull": (data: GitPullData) => void;
|
|
31
|
-
"send command": (command: string) => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The struct sent from the server containing console messages
|
|
37
|
-
*
|
|
38
|
-
* @param type The type of message. Currently unknown what varients exist
|
|
39
|
-
* @param line The actual content of the console messages
|
|
40
|
-
*
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
export interface ConsoleMessage {
|
|
44
|
-
type: string;
|
|
45
|
-
line: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Struct used to initiate a Git Clone action
|
|
51
|
-
*
|
|
52
|
-
* @param dir The directory to clone into
|
|
53
|
-
* @param url The HTTPS URL to clone
|
|
54
|
-
* @param branch The repository branch
|
|
55
|
-
* @param authkey The authentication key to use when pulling
|
|
56
|
-
*
|
|
57
|
-
* @internal
|
|
58
|
-
*/
|
|
59
|
-
export interface GitCloneData {
|
|
60
|
-
dir: string;
|
|
61
|
-
url: string;
|
|
62
|
-
branch: string;
|
|
63
|
-
authkey?: string | undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Return struct after finishing a Git Clone action
|
|
69
|
-
*
|
|
70
|
-
* @param isPrivate Whether or not the repository is private
|
|
71
|
-
*
|
|
72
|
-
* @internal
|
|
73
|
-
*/
|
|
74
|
-
export interface GitCloneResult {
|
|
75
|
-
isPrivate: boolean;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Struct used to initiate a Git Pull action
|
|
81
|
-
*
|
|
82
|
-
* @param dir The directory to pull
|
|
83
|
-
* @param authkey The authentication key to use when pulling
|
|
84
|
-
*
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
export interface GitPullData {
|
|
88
|
-
dir: string;
|
|
89
|
-
authkey?: string;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Struct returned after a Git Pull action finishes
|
|
95
|
-
*
|
|
96
|
-
* @param output The actual output
|
|
97
|
-
* @param isPrivate Whether or not the repository is private
|
|
98
|
-
*
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
export interface GitPullResult {
|
|
102
|
-
output: string;
|
|
103
|
-
isPrivate: boolean;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* An individual filesearch result
|
|
109
|
-
*
|
|
110
|
-
* @param results How many results are present in the file
|
|
111
|
-
* @param lines A map of line numbers to their contents. These lines include nearby context of matched lines
|
|
112
|
-
*
|
|
113
|
-
* @internal
|
|
114
|
-
*/
|
|
115
|
-
export interface FilesearchFile {
|
|
116
|
-
results: number;
|
|
117
|
-
lines: {[key: string]: string};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* The results of a file search
|
|
123
|
-
*
|
|
124
|
-
* @param files A map of file names to matched+context lines within each file
|
|
125
|
-
* @param tooMany Whether or not there were too many results to display
|
|
126
|
-
*
|
|
127
|
-
* @internal
|
|
128
|
-
*/
|
|
129
|
-
export interface FilesearchResults {
|
|
130
|
-
files: {[key: string]: FilesearchFile};
|
|
131
|
-
tooMany: boolean;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* The events that can be sent from the server to the client
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
139
|
-
export type WispWebsocket = Socket<ServerToClientEvents, ClientToServerEvents>;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* The events that can be sent from the client to the server
|
|
144
|
-
* @internal
|
|
145
|
-
*/
|
|
146
|
-
export type WispWebsocketManager = Manager<ServerToClientEvents, ClientToServerEvents>;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* A single worker in the Websocket Pool
|
|
151
|
-
*
|
|
152
|
-
* @internal
|
|
153
|
-
*/
|
|
154
|
-
interface PoolWorker {
|
|
155
|
-
pool: WebsocketPool;
|
|
156
|
-
socket: WispWebsocket;
|
|
157
|
-
idx: number;
|
|
158
|
-
token: string;
|
|
159
|
-
ready: boolean;
|
|
160
|
-
logger: {
|
|
161
|
-
log(...args: any[]): void;
|
|
162
|
-
error(...args: any[]): void;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* A single Worker within a {@link WebsocketPool}
|
|
169
|
-
*
|
|
170
|
-
* @param pool The pool this worker is a part of
|
|
171
|
-
*
|
|
172
|
-
* @internal
|
|
173
|
-
*/
|
|
174
|
-
class PoolWorker {
|
|
175
|
-
constructor(pool: WebsocketPool) {
|
|
176
|
-
this.pool = pool;
|
|
177
|
-
this.ready = false;
|
|
178
|
-
|
|
179
|
-
this.idx = pool.workers.length;
|
|
180
|
-
this.token = pool.token;
|
|
181
|
-
this.socket = io(pool.url, {
|
|
182
|
-
forceNew: true,
|
|
183
|
-
transports: ["websocket"],
|
|
184
|
-
addTrailingSlash: true,
|
|
185
|
-
autoConnect: false
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
const logPrefix = `[Worker #${this.idx}]`
|
|
189
|
-
this.logger = {
|
|
190
|
-
log: (...args: any[]) => console.log(logPrefix, args),
|
|
191
|
-
error: (...args: any[]) => console.error(logPrefix, args),
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
available() {
|
|
197
|
-
return this.ready && this.socket.connected;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
connect() {
|
|
201
|
-
const socket = this.socket
|
|
202
|
-
const logger = this.logger
|
|
203
|
-
|
|
204
|
-
socket.onAnyOutgoing(this.logger.log)
|
|
205
|
-
|
|
206
|
-
logger.log("Connecting to websocket...")
|
|
207
|
-
|
|
208
|
-
return new Promise<void>((resolve, reject) => {
|
|
209
|
-
let connectedOnce = false
|
|
210
|
-
|
|
211
|
-
socket.on("connect", () => {
|
|
212
|
-
logger.log("Connected to WebSocket")
|
|
213
|
-
logger.log("Emitting:", "auth", this.token)
|
|
214
|
-
socket.emit("auth", this.token)
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
socket.on("error", (reason: string) => {
|
|
218
|
-
logger.error(`WebSocket error: ${reason}`)
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
socket.on("connect_error", (error: Error) => {
|
|
222
|
-
logger.error(`WebSocket Connect error: ${error.toString()}`)
|
|
223
|
-
|
|
224
|
-
if (!connectedOnce) {
|
|
225
|
-
connectedOnce = true
|
|
226
|
-
reject(`Connection error: ${error.toString()}`)
|
|
227
|
-
}
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
socket.on("disconnect", (reason: string) => {
|
|
231
|
-
logger.log(`Disconnected from WebSocket: ${reason}`)
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
socket.on("auth_success", () => {
|
|
235
|
-
logger.log("Auth success")
|
|
236
|
-
|
|
237
|
-
if (!connectedOnce) {
|
|
238
|
-
connectedOnce = true
|
|
239
|
-
this.ready = true
|
|
240
|
-
resolve()
|
|
241
|
-
}
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
setTimeout(() => {
|
|
245
|
-
if (!connectedOnce) {
|
|
246
|
-
logger.error("Socket didn't connect in time")
|
|
247
|
-
reject("Connection Timeout")
|
|
248
|
-
}
|
|
249
|
-
}, 10000)
|
|
250
|
-
|
|
251
|
-
socket.connect()
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
disconnect() {
|
|
256
|
-
this.ready = false;
|
|
257
|
-
|
|
258
|
-
return new Promise<void>((resolve, reject) => {
|
|
259
|
-
let done = false;
|
|
260
|
-
|
|
261
|
-
this.socket.once("disconnect", () => {
|
|
262
|
-
if (!done) {
|
|
263
|
-
done = true;
|
|
264
|
-
resolve();
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
this.socket.disconnect();
|
|
269
|
-
|
|
270
|
-
setTimeout(() => {
|
|
271
|
-
if (!done) {
|
|
272
|
-
this.logger.error("Socket didn't disconnect in time");
|
|
273
|
-
done = true;
|
|
274
|
-
reject();
|
|
275
|
-
}
|
|
276
|
-
}, 5000);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async run(work: (worker: PoolWorker) => Promise<any>) {
|
|
281
|
-
this.ready = false;
|
|
282
|
-
|
|
283
|
-
// TODO: Verify that a finally is what we want here
|
|
284
|
-
try {
|
|
285
|
-
return await work(this);
|
|
286
|
-
} catch (e) {
|
|
287
|
-
this.logger.error(e);
|
|
288
|
-
throw e;
|
|
289
|
-
} finally {
|
|
290
|
-
this.ready = true;
|
|
291
|
-
this.pool.processQueue();
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Struct used to manage a pool of WebSocket workers
|
|
299
|
-
*/
|
|
300
|
-
export interface WebsocketPool {
|
|
301
|
-
manager: WispWebsocketManager;
|
|
302
|
-
workers: PoolWorker[];
|
|
303
|
-
token: string;
|
|
304
|
-
url: string;
|
|
305
|
-
maxWorkers: number;
|
|
306
|
-
queue: ((worker: PoolWorker) => Promise<any>)[];
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* A pool of {@link PoolWorker}s
|
|
311
|
-
*
|
|
312
|
-
* This is used to manage a pool of WebSocket workers that can be used to run tasks in parallel
|
|
313
|
-
* This alleviates the need to wait for every WebSocket instruction to fully complete before starting another
|
|
314
|
-
*
|
|
315
|
-
* @param url The WebSocket URL to connect to
|
|
316
|
-
* @param token The token to use for WebSocket authentication
|
|
317
|
-
*
|
|
318
|
-
* @internal
|
|
319
|
-
*/
|
|
320
|
-
export class WebsocketPool {
|
|
321
|
-
constructor(url: string, token: string) {
|
|
322
|
-
this.maxWorkers = 5
|
|
323
|
-
this.token = token
|
|
324
|
-
this.url = url
|
|
325
|
-
|
|
326
|
-
this.manager = new Manager(url, {
|
|
327
|
-
forceNew: true,
|
|
328
|
-
transports: ["websocket"],
|
|
329
|
-
addTrailingSlash: true,
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
this.workers = []
|
|
333
|
-
this.queue = []
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
async createWorker() {
|
|
337
|
-
console.log("Creating a new Pool worker")
|
|
338
|
-
const worker = new PoolWorker(this)
|
|
339
|
-
this.workers.push(worker)
|
|
340
|
-
await worker.connect()
|
|
341
|
-
|
|
342
|
-
return worker
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
async disconnect() {
|
|
346
|
-
await Promise.all(this.workers.map((worker: PoolWorker) => worker.disconnect()))
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
async processQueue() {
|
|
350
|
-
if (this.queue.length == 0) { return }
|
|
351
|
-
|
|
352
|
-
const work = this.queue.shift()
|
|
353
|
-
if (!work) { return }
|
|
354
|
-
|
|
355
|
-
let worker: PoolWorker | undefined
|
|
356
|
-
if (this.workers.length == 0) {
|
|
357
|
-
worker = await this.createWorker()
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
worker = worker || this.workers.find((worker) => worker.available())
|
|
361
|
-
if (!worker) {
|
|
362
|
-
if (this.workers.length < this.maxWorkers) {
|
|
363
|
-
worker = await this.createWorker()
|
|
364
|
-
} else {
|
|
365
|
-
return
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return await worker.run(work)
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
async run(work: (worker: PoolWorker) => Promise<any>): Promise<any> {
|
|
373
|
-
return new Promise(async (resolve, reject) => {
|
|
374
|
-
this.queue.push(async (worker) => {
|
|
375
|
-
try {
|
|
376
|
-
const result = await work(worker)
|
|
377
|
-
resolve(result)
|
|
378
|
-
} catch (e) {
|
|
379
|
-
worker.logger.error("Failed to run a job!")
|
|
380
|
-
reject(e)
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
|
|
384
|
-
return this.processQueue()
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
}
|