Skip to content

Commit

Permalink
chore: jsdoc and typings fixes & improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowplay1 committed Jan 5, 2024
1 parent 5f84600 commit c845f97
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 56 deletions.
96 changes: 44 additions & 52 deletions src/Leveling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ILevelingEvents<TDatabaseType>>}
* @template TDatabaseType The database type that will be used in the module.
* @extends {Emitter<ILevelingEvents<TDatabaseType, TDatabaseKey, TDatabaseValue>>}
*
* @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<ILevelingEvents<TDatabaseType>> {
> extends Emitter<ILevelingEvents<TDatabaseType, TDatabaseKey, TDatabaseValue>> {

/**
* Discord Client.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -394,10 +381,6 @@ export class Leveling<
* @typedef {object} ILevelingConfiguration<TDatabaseType>
* @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.
Expand All @@ -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.
Expand Down Expand Up @@ -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<DatabaseType, TDatabaseKey, TDatabaseValue>} 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.
*/

/**
Expand Down Expand Up @@ -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<N, S>
*/
* 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<N, S>
*/

/**
* 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<ID>
*/
* 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<ID>
*/

/**
* Extracts the type that was passed into `Promise<...>` type.
Expand All @@ -734,7 +726,7 @@ export class Leveling<
/**
* Emits when the {@link Leveling} module is ready.
* @event Leveling#ready
* @param {Leveling<DatabaseType>} leveling Initialized {@link Leveling} instance.
* @param {Leveling<DatabaseType, TDatabaseKey, TDatabaseValue>} leveling Initialized {@link Leveling} instance.
*/

// [FILL IN]
1 change: 0 additions & 1 deletion src/lib/managers/DatabaseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
24 changes: 22 additions & 2 deletions src/types/levelingEvents.interface.ts
Original file line number Diff line number Diff line change
@@ -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<DatabaseType, TDatabaseKey, TDatabaseValue>} 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<TDatabaseType, TDatabaseKey, TDatabaseValue>
databaseConnect: void
// [FILL IN]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"removeComments": false,
"preserveConstEnums": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"resolveJsonModule": true,
"resolveJsonModule": true
},
"include": [
"src/**/*"
Expand Down

0 comments on commit c845f97

Please sign in to comment.