-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypings.d.ts
287 lines (258 loc) · 11.3 KB
/
typings.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
declare module 'discord-hybrid-sharding' {
import { EventEmitter } from 'events';
import { ChildProcess } from 'child_process';
import { Client as DJsClient, Collection } from 'discord.js';
export class Cluster extends EventEmitter {
constructor(manager: Manager, id: number);
private _evals: Map<string, Promise<any>>;
private _exitListener: (...args: any[]) => void;
private _fetches: Map<string, Promise<any>>;
private _handleExit(respawn?: boolean): void;
private _handleMessage(message: any): void;
public args: string[];
public execArgv: string[];
public env: object;
public id: number;
public manager: Manager;
public process: ChildProcess | null;
public ready: boolean;
public worker: any | null;
public heartbeat: object;
private _restarts: object;
public eval(script: string): Promise<unknown>;
public eval<T>(fn: (client: Client) => T): Promise<T>;
public eval<T, P>(fn: (client: Client, context: Serialized<P>) => T, context: P): Promise<T>;
public fetchClientValue(prop: string, cluster: number): Promise<any>;
public kill(): void;
public respawn(options?: { delay?: number; timeout?: number }): Promise<ChildProcess>;
public send(message: any): Promise<Cluster>;
public request(message: object): Promise<BaseMessage>;
public spawn(timeout?: number): Promise<ChildProcess>;
public triggerMaintenance(reason: string): any;
public on(event: 'spawn' | 'death', listener: (child: ChildProcess) => void): this;
public on(event: 'disconnect' | 'ready' | 'reconnecting', listener: () => void): this;
public on(event: 'error', listener: (error: Error) => void): this;
public on(event: 'message', listener: (message: any) => void): this;
public on(event: string, listener: (...args: any[]) => void): this;
public once(event: 'spawn' | 'death', listener: (child: ChildProcess) => void): this;
public once(event: 'disconnect' | 'ready' | 'reconnecting', listener: () => void): this;
public once(event: 'error', listener: (error: Error) => void): this;
public once(event: 'message', listener: (message: any) => void): this;
public once(event: string, listener: (...args: any[]) => void): this;
}
export class Client extends EventEmitter {
constructor(client: client | any);
private _handleMessage(message: any): void;
private _respond(type: string, message: any): void;
public client: client;
public readonly count: number;
public readonly id: number;
public readonly ids: Collection<number, any>;
public mode: ClusterManagerMode;
public maintenance: string;
public ready: boolean;
public static getInfo(): data;
get getInfo(): data;
public parentPort: any | null;
public evalOnManager(script: string): Promise<any[]>;
public evalOnManager(script: string, options?: evalOptions): Promise<any>;
public evalOnManager<T>(fn: (manager: Manager) => T, options?: evalOptions): Promise<T>;
public evalOnManager<T>(fn: (manager: Manager) => T, options?: evalOptions): Promise<any[]>;
public evalOnCluster(script: string, options?: evalOptions): Promise<any[]>;
public evalOnCluster<T>(fn: (client: DJsClient) => T, options?: evalOptions): Promise<T>;
public evalOnCluster<T>(fn: (client: DJsClient) => T, options?: evalOptions): Promise<any[]>;
public broadcastEval(script: string): Promise<any[]>;
public broadcastEval(script: string, options?: evalOptions): Promise<any>;
public broadcastEval<T>(fn: (client: DJsClient) => Awaitable<T>): Promise<Serialized<T>[]>;
public broadcastEval<T>(
fn: (client: DJsClient) => Awaitable<T>,
options?: { cluster?: number; timeout?: number },
): Promise<Serialized<T>>;
public broadcastEval<T, P>(
fn: (client: DJsClient, context: Serialized<P>) => Awaitable<T>,
options?: evalOptions<P>,
): Promise<Serialized<T>[]>;
public broadcastEval<T, P>(
fn: (client: DJsClient, context: Serialized<P>) => Awaitable<T>,
options?: evalOptions<P>,
): Promise<Serialized<T>>;
public fetchClientValues(prop: string): Promise<any[]>;
public fetchClientValues(prop: string, cluster: number): Promise<any>;
public send(message: any): Promise<void>;
public request(message: object): Promise<BaseMessage>;
public respawnAll(options?: ClusterRespawnOptions): Promise<void>;
public triggerReady(): Promise<void>;
public triggerMaintenance(reason: string, all?: Boolean): any;
public spawnNextCluster(): Promise<void>;
}
export interface ManagerOptions {
totalShards?: number | 'auto';
totalClusters?: number | 'auto';
shardsPerClusters?: number;
shardList?: number[][] | 'auto';
mode?: ClusterManagerMode;
respawn?: boolean;
shardArgs?: string[];
token?: string;
execArgv?: string[];
keepAlive?: keepAliveOptions;
queue?: {
auto?: boolean;
};
restarts?: {
max?: number;
interval?: number;
current?: number;
};
clusterData?: object;
clusterOptions?: object;
spawnOptions?: {
delay?: number;
timeout?: number;
};
}
export class Manager extends EventEmitter {
constructor(file: string, options?: ManagerOptions);
private _performOnShards(method: string, args: any[]): Promise<any[]>;
private _performOnShards(method: string, args: any[], cluster: number): Promise<any>;
private _nonce: Map<string, Promise<any>>;
public file: string;
public respawn: boolean;
public clusterData: object;
public clusterOptions: object;
public shardArgs: string[];
public clusters: Map<number, Cluster>;
public token: string | null;
public totalClusters: number | 'auto';
public shardsPerClusters: number | 'auto';
public totalShards: number | 'auto';
public shardList: number[][] | 'auto';
public clusterList: number[];
public keepAlive: keepAliveOptions;
public queue: Queue;
public spawnOptions: ClusterSpawnOptions;
public recluster?: ReClusterManager;
public heartbeat?: HeartbeatManager;
public broadcast(message: any): Promise<Cluster[]>;
public broadcastEval(script: string): Promise<any[]>;
public broadcastEval(script: string, options?: evalOptions): Promise<any>;
public broadcastEval<T>(fn: (client: DJsClient) => Awaitable<T>): Promise<Serialized<T>[]>;
public broadcastEval<T>(
fn: (client: DJsClient) => Awaitable<T>,
options?: { cluster?: number; timeout?: number },
): Promise<Serialized<T>>;
public broadcastEval<T, P>(
fn: (client: DJsClient, context: Serialized<P>) => Awaitable<T>,
options?: evalOptions<P>,
): Promise<Serialized<T>[]>;
public broadcastEval<T, P>(
fn: (client: DJsClient, context: Serialized<P>) => Awaitable<T>,
options?: evalOptions<P>,
): Promise<Serialized<T>>;
public createCluster(id: number, clustersToSpawn: number[], totalShards: number): Cluster;
public fetchClientValues(prop: string): Promise<any[]>;
public fetchClientValues(prop: string, cluster: number): Promise<any>;
public evalOnManager(script: string): Promise<any[]>;
private evalOnCluster(script: string, options: object): Promise<any[]>;
public respawnAll(options?: ClusterRespawnOptions): Promise<Map<number, Cluster>>;
public spawn(options?: ClusterSpawnOptions): Promise<Map<number, Cluster>>;
public triggerMaintenance(reason: string): any;
public extend(...plugins: object[]): void;
public on(event: 'clusterCreate', listener: (cluster: Cluster) => void): this;
public on(event: 'debug', listener: (message: string) => void): this;
public once(event: 'clusterCreate', listener: (cluster: Cluster) => void): this;
public once(event: 'debug', listener: (message: string) => void): this;
}
export class BaseMessage {
public _sCustom: true;
public nonce: String;
private destructMessage(message: object): Promise<object>;
public toJSON(): Promise<object>;
}
export class IPCMessage {
public instance: Cluster | Client;
public raw: BaseMessage;
public send(message: object): Promise<Cluster | Client>;
public request(message: object): Promise<object>;
public reply(message: object): Promise<object>;
}
export type data = {
SHARD_LIST: number[];
TOTAL_SHARDS: number;
LAST_SHARD_ID: number;
FIRST_SHARD_ID: number;
CLUSTER_COUNT: number;
CLUSTER: number;
CLUSTER_MANAGER_MODE: ClusterManagerMode;
};
type ClusterManagerMode = 'process' | 'worker';
type client = DJsClient;
export type keepAliveOptions = {
/** Default interval is 20000 */
interval?: number;
/** Default maxMissedHeartbeats is 5 */
maxMissedHeartbeats?: number;
};
export interface ClusterSpawnOptions {
amount?: number | 'auto';
delay?: number;
timeout?: number;
}
export interface ClusterRespawnOptions {
clusterDelay?: number;
respawnDelay?: number;
timeout?: number;
}
export interface ReClusterOptions {
delay?: number;
timeout?: number;
totalShards?: number | 'auto';
totalClusters?: number;
shardsPerClusters?: number;
shardList?: number[];
shardClusterList?: number[][];
restartMode?: 'gracefulSwitch' | 'rolling';
}
export interface evalOptions<T = object> {
cluster?: number | number[];
shard?: number;
guildId?: string;
context?: T;
timeout?: number;
}
export class Queue {
options: {
auto?: boolean;
timeout?: number;
};
queue: object[];
public start(): Promise<void>;
public stop(): Queue;
public resume(): Queue;
public add(item: any): Queue;
public next(): Promise<void>;
}
export class HeartbeatManager {
constructor(options?: keepAliveOptions);
public start(): Promise<void>;
public build(): Promise<typeof this.start>;
}
export class ReClusterManager {
constructor(options?: object);
private _start(): Promise<{ success: boolean }>;
public start(options: ReClusterOptions): ReturnType<typeof this._start>;
public build(manager: Manager): Manager;
}
export type Awaitable<T> = T | PromiseLike<T>;
export type Serialized<T> = T extends symbol | bigint | (() => any)
? never
: T extends number | string | boolean | undefined
? T
: T extends { toJSON(): infer R }
? R
: T extends ReadonlyArray<infer V>
? Serialized<V>[]
: T extends ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
? {}
: { [K in keyof T]: Serialized<T[K]> };
}