From 82fe46a4ef24b2794030f21473e56831a83ef51c Mon Sep 17 00:00:00 2001 From: uhKevinMC Date: Sun, 2 May 2021 16:57:58 -0500 Subject: [PATCH 1/3] feat(ShardingManager): add options typings --- src/sharding/ShardingManager.js | 30 +++++++++++++++---------- typings/index.d.ts | 39 ++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/sharding/ShardingManager.js b/src/sharding/ShardingManager.js index 85e18f114a8b..bf8ce7f3675b 100644 --- a/src/sharding/ShardingManager.js +++ b/src/sharding/ShardingManager.js @@ -19,24 +19,30 @@ const Util = require('../util/Util'); */ class ShardingManager extends EventEmitter { /** - * The mode to spawn shards with for a {@link ShardingManager}: either "process" to use child processes, or + * The mode to spawn shards with for a {@link ShardingManager}. Either "process" to use child processes, or * "worker" to use [Worker threads](https://nodejs.org/api/worker_threads.html). - * @typedef {Object} ShardingManagerMode + * @typedef {string} ShardingManagerMode + */ + + /** + * The options to spawn shards with for a {@link ShardingManager}, + * @typedef {Object} ShardingManagerOptions + * @property {string|number} [totalShards='auto'] Number of total shards of all shard managers or "auto" + * @property {string|number[]} [shardList='auto'] List of shards to spawn or "auto" + * @property {ShardingManagerMode} [mode='process'] Which mode to use for shards + * @property {boolean} [respawn=true] Whether shards should automatically respawn upon exiting + * @property {string[]} [shardArgs=[]] Arguments to pass to the shard script when spawning + * (only available when mode is set to 'process') + * @property {string} [execArgv=[]] Arguments to pass to the shard script executable when spawning + * (only available when mode is set to 'process') + * @property {string} [token] Token to use for automatical shard count and passing to shards */ /** * @param {string} file Path to your shard script file - * @param {Object} [options] Options for the sharding manager - * @param {string|number} [options.totalShards='auto'] Number of total shards of all shard managers or "auto" - * @param {string|number[]} [options.shardList='auto'] List of shards to spawn or "auto" - * @param {ShardingManagerMode} [options.mode='process'] Which mode to use for shards - * @param {boolean} [options.respawn=true] Whether shards should automatically respawn upon exiting - * @param {string[]} [options.shardArgs=[]] Arguments to pass to the shard script when spawning - * (only available when using the `process` mode) - * @param {string[]} [options.execArgv=[]] Arguments to pass to the shard script executable when spawning - * (only available when using the `process` mode) - * @param {string} [options.token] Token to use for automatic shard count and passing to shards + * @param {ShardingManagerOptions} [options] Options for the sharding manager */ + constructor(file, options = {}) { super(); options = Util.mergeDefault( diff --git a/typings/index.d.ts b/typings/index.d.ts index c217855c8f26..8094bc1b669a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1378,7 +1378,7 @@ declare module 'discord.js' { public eval(fn: (client: Client) => T): Promise; public fetchClientValue(prop: string): Promise; public kill(): void; - public respawn(options?: { delay?: number, timeout?: number }): Promise; + public respawn(options?: { delay?: number; timeout?: number }): Promise; public send(message: any): Promise; public spawn(timeout?: number): Promise; @@ -1411,7 +1411,7 @@ declare module 'discord.js' { public broadcastEval(fn: (client: Client) => T, shard: number): Promise; public fetchClientValues(prop: string): Promise; public fetchClientValues(prop: string, shard: number): Promise; - public respawnAll(options?: { shardDelay?: number, respawnDelay?: number, timeout?: number }): Promise; + public respawnAll(options?: { shardDelay?: number; respawnDelay?: number; timeout?: number }): Promise; public send(message: any): Promise; public static singleton(client: Client, mode: ShardingManagerMode): ShardClientUtil; @@ -1419,18 +1419,7 @@ declare module 'discord.js' { } export class ShardingManager extends EventEmitter { - constructor( - file: string, - options?: { - totalShards?: number | 'auto'; - shardList?: number[] | 'auto'; - mode?: ShardingManagerMode; - respawn?: boolean; - shardArgs?: string[]; - token?: string; - execArgv?: string[]; - }, - ); + constructor(file: string, options?: ShardingManagerOptions); private _performOnShards(method: string, args: any[]): Promise; private _performOnShards(method: string, args: any[], shard: number): Promise; @@ -1448,11 +1437,15 @@ declare module 'discord.js' { public fetchClientValues(prop: string): Promise; public fetchClientValues(prop: string, shard: number): Promise; public respawnAll(options?: { - shardDelay?: number, - respawnDelay?: number, - timeout?: number, + shardDelay?: number; + respawnDelay?: number; + timeout?: number; + }): Promise>; + public spawn(options?: { + amount?: number | 'auto'; + delay?: number; + timeout?: number; }): Promise>; - public spawn(options?: { amount?: number | 'auto', delay?: number, timeout?: number }): Promise>; public on(event: 'shardCreate', listener: (shard: Shard) => void): this; @@ -3261,6 +3254,16 @@ declare module 'discord.js' { type ShardingManagerMode = 'process' | 'worker'; + interface ShardingManagerOptions { + totalShards?: number | 'auto'; + shardList?: number[] | 'auto'; + mode?: ShardingManagerMode; + respawn?: boolean; + shardArgs?: string[]; + token?: string; + execArgv?: string[]; + } + type Snowflake = string; interface SplitOptions { From cfcbc150ef739e0212016e2ef688bdb70b1f4817 Mon Sep 17 00:00:00 2001 From: uhKevinMC Date: Mon, 10 May 2021 03:58:08 -0500 Subject: [PATCH 2/3] fix(ShardingManager): correct spelling Co-authored-by: Vlad Frangu --- src/sharding/ShardingManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sharding/ShardingManager.js b/src/sharding/ShardingManager.js index bf8ce7f3675b..3d6b8cf1274d 100644 --- a/src/sharding/ShardingManager.js +++ b/src/sharding/ShardingManager.js @@ -35,7 +35,7 @@ class ShardingManager extends EventEmitter { * (only available when mode is set to 'process') * @property {string} [execArgv=[]] Arguments to pass to the shard script executable when spawning * (only available when mode is set to 'process') - * @property {string} [token] Token to use for automatical shard count and passing to shards + * @property {string} [token] Token to use for automatic shard count and passing to shards */ /** From deb17163a7f4c156e191e7b1812b4edbae52b4d0 Mon Sep 17 00:00:00 2001 From: uhKevinMC Date: Mon, 10 May 2021 04:07:46 -0500 Subject: [PATCH 3/3] fix(ShardingManager): fix whitespaces Co-authored-by: SpaceEEC --- src/sharding/ShardingManager.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sharding/ShardingManager.js b/src/sharding/ShardingManager.js index 3d6b8cf1274d..bd8452c1e2c0 100644 --- a/src/sharding/ShardingManager.js +++ b/src/sharding/ShardingManager.js @@ -42,7 +42,6 @@ class ShardingManager extends EventEmitter { * @param {string} file Path to your shard script file * @param {ShardingManagerOptions} [options] Options for the sharding manager */ - constructor(file, options = {}) { super(); options = Util.mergeDefault(