From c845f97fb484ff47d38e8c1741da83f11b11ae3b Mon Sep 17 00:00:00 2001 From: shadowplay1 Date: Fri, 5 Jan 2024 03:54:33 +0300 Subject: [PATCH] chore: jsdoc and typings fixes & improvements --- src/Leveling.ts | 96 ++++++++++++--------------- src/lib/managers/DatabaseManager.ts | 1 - src/types/levelingEvents.interface.ts | 24 ++++++- tsconfig.json | 3 +- 4 files changed, 68 insertions(+), 56 deletions(-) diff --git a/src/Leveling.ts b/src/Leveling.ts index 4760ae0..e4acca4 100644 --- a/src/Leveling.ts +++ b/src/Leveling.ts @@ -39,16 +39,21 @@ import { IDatabaseStructure } from './types/databaseStructure.interface' * * Type parameters: * - * - `TDatabaseType` ({@link DatabaseType}) - The database type that will be used in the module. + * - `TDatabaseType` ({@link DatabaseType}) - The database type that is used. + * - `TDatabaseKey` ({@link string}, optional: defaults to `${string}.giveaways`) - The type of database key that will be used in database operations. + * - `TDatabaseValue` ({@link any}, optional: defaults to {@link IDatabaseStructure}) - The type of database content that will be used in database operations. * - * @extends {Emitter>} - * @template TDatabaseType The database type that will be used in the module. + * @extends {Emitter>} + * + * @template TDatabaseType The database type that is used. + * @template TDatabaseKey The type of database key that will be used in database operations. + * @template TDatabaseValue The type of database content that will be used in database operations. */ export class Leveling< TDatabaseType extends DatabaseType, TDatabaseKey extends string = `${string}.leveling`, TDatabaseValue = IDatabaseStructure -> extends Emitter> { +> extends Emitter> { /** * Discord Client. @@ -93,12 +98,6 @@ export class Leveling< */ private readonly _logger: Logger - /** - * Leveling ending state checking interval. - * @type {NodeJS.Timeout} - */ - public levelingCheckingInterval: NodeJS.Timeout - /** * Main {@link Leveling} constructor. * @param {Client} client Discord client. @@ -156,12 +155,6 @@ export class Leveling< */ this.database = null as any // specifying 'null' to just initialize the property; for docs purposes - /** - * {@link Leveling} ending state checking interval. - * @type {NodeJS.Timeout} - */ - this.levelingCheckingInterval = null as any // specifying 'null' to just initialize the property; for docs purposes - this._init() } @@ -321,12 +314,6 @@ export class Leveling< if (this.client.isReady()) { clearInterval(clientReadyInterval) - const giveawatCheckingInterval = setInterval(() => { - this._checkLeveling() - }, this.options.levelingCheckingInterval) - - this.levelingCheckingInterval = giveawatCheckingInterval - this.ready = true this.emit('ready', this) @@ -394,10 +381,6 @@ export class Leveling< * @typedef {object} ILevelingConfiguration * @prop {DatabaseType} database Database type to use. * @prop {DatabaseConnectionOptions} connection Database type to use. - * - * @prop {?number} [levelingCheckingInterval=1000] - * Determines how often the leveling ending state will be checked (in ms). Default: 1000. - * * @prop {?boolean} [debug=false] Determines if debug mode is enabled. Default: false. * @prop {Partial} [updatesChecker] Updates checker configuration. * @prop {Partial} [configurationChecker] Leveling config checker configuration. @@ -409,10 +392,6 @@ export class Leveling< /** * Optional configuration for the {@link Leveling} class. * @typedef {object} ILevelingOptionalConfiguration - * - * @prop {?number} [levelingCheckingInterval=1000] - * Determines how often the leveling ending state will be checked (in ms). Default: 1000. - * * @prop {?boolean} [debug=false] Determines if debug mode is enabled. Default: false. * @prop {Partial} [updatesChecker] Updates checker configuration. * @prop {Partial} [configurationChecker] Leveling config checker configuration. @@ -512,7 +491,20 @@ export class Leveling< /** * A type containing all the {@link Leveling} events and their return types. + * + * Type parameters: + * + * - `TDatabaseType` ({@link DatabaseType}) - The database type that is used. + * - `TDatabaseKey` ({@link string}, optional: defaults to `${string}.leveling`) - The type of database key that will be used in database operations. + * - `TDatabaseValue` ({@link any}, optional: defaults to {@link IDatabaseStructure}) - The type of database content that will be used in database operations. + * + * @typedef {object} ILevelingEvents + * @prop {Leveling} ready Emits when the {@link Leveling} module is ready. * [FILL IN] + * + * @template TDatabaseType The database type that is used. + * @template TDatabaseKey The type of database key that will be used in database operations. + * @template TDatabaseValue The type of database content that will be used in database operations. */ /** @@ -693,29 +685,29 @@ export class Leveling< */ /** -* Conditional type that will return the specified string if it matches the specified length. -* -* Type parameters: -* -* - `N` ({@link number}) - The string length to match to. -* - `S` ({@link string}) - The string to check the length of. -* -* @template N The string length to match to. -* @template S The string to check the length of. -* -* @typedef {number} ExactLengthString -*/ + * Conditional type that will return the specified string if it matches the specified length. + * + * Type parameters: + * + * - `N` ({@link number}) - The string length to match to. + * - `S` ({@link string}) - The string to check the length of. + * + * @template N The string length to match to. + * @template S The string to check the length of. + * + * @typedef {number} ExactLengthString + */ /** -* Conditional type that will return the specified string if it matches any of the possible Discord ID string lengths. -* -* Type parameters: -* -* - `S` ({@link string}) - The string to check the length of. -* -* @template S The string to check the length of. -* @typedef {number} DiscordID -*/ + * Conditional type that will return the specified string if it matches any of the possible Discord ID string lengths. + * + * Type parameters: + * + * - `S` ({@link string}) - The string to check the length of. + * + * @template S The string to check the length of. + * @typedef {number} DiscordID + */ /** * Extracts the type that was passed into `Promise<...>` type. @@ -734,7 +726,7 @@ export class Leveling< /** * Emits when the {@link Leveling} module is ready. * @event Leveling#ready - * @param {Leveling} leveling Initialized {@link Leveling} instance. + * @param {Leveling} leveling Initialized {@link Leveling} instance. */ // [FILL IN] diff --git a/src/lib/managers/DatabaseManager.ts b/src/lib/managers/DatabaseManager.ts index 3054670..70701ae 100644 --- a/src/lib/managers/DatabaseManager.ts +++ b/src/lib/managers/DatabaseManager.ts @@ -20,7 +20,6 @@ import { CacheManager } from './CacheManager' * * - `TDatabaseType` ({@link DatabaseType}) - The database type that will determine * which connection configuration should be used. - * * - `TKey` ({@link string}) - The type of database key that will be used. * - `TValue` ({@link any}) - The type of database values that will be used. * diff --git a/src/types/levelingEvents.interface.ts b/src/types/levelingEvents.interface.ts index 3b9ee2f..c807bcd 100644 --- a/src/types/levelingEvents.interface.ts +++ b/src/types/levelingEvents.interface.ts @@ -1,11 +1,31 @@ import { Leveling } from '../Leveling' +import { IDatabaseStructure } from './databaseStructure.interface' +import { DatabaseType } from './databaseType.enum' + /** * A type containing all the {@link Leveling} events and their return types. + * + * Type parameters: * + * - `TDatabaseType` ({@link DatabaseType}) - The database type that is used. + * - `TDatabaseKey` ({@link string}, optional: defaults to `${string}.leveling`) - The type of database key that will be used in database operations. + * - `TDatabaseValue` ({@link any}, optional: defaults to {@link IDatabaseStructure}) - The type of database content that will be used in database operations. + * * @typedef {object} ILevelingEvents + * @prop {Leveling} ready Emits when the {@link Leveling} module is ready. + * @prop {void} databaseConnect Emits when the connection to the database is established. + * + * @template TDatabaseType The database type that is used. + * @template TDatabaseKey The type of database key that will be used in database operations. + * @template TDatabaseValue The type of database content that will be used in database operations. */ -export type ILevelingEvents = { - ready: void +export type ILevelingEvents< + TDatabaseType extends DatabaseType, + TDatabaseKey extends string = `${string}.leveling`, + TDatabaseValue = IDatabaseStructure +> = { + ready: Leveling + databaseConnect: void // [FILL IN] } diff --git a/tsconfig.json b/tsconfig.json index dc11794..b2081a4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,8 +22,9 @@ "removeComments": false, "preserveConstEnums": true, "allowSyntheticDefaultImports": true, + "skipLibCheck": true, "skipDefaultLibCheck": true, - "resolveJsonModule": true, + "resolveJsonModule": true }, "include": [ "src/**/*"