Skip to content

Commit

Permalink
docs: 📚️ add extensive jsdocs to interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
iwpnd committed Jun 23, 2024
1 parent 755f4b1 commit 5386a7b
Show file tree
Hide file tree
Showing 2 changed files with 1,457 additions and 1 deletion.
73 changes: 73 additions & 0 deletions src/commands/Whereable.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,94 @@
import { Executable } from './Executable';
import { CommandArgs, SubCommand } from '../Client';

/**
* Represents the different types of WHERE clauses
* @typedef {Array} WhereType
* @property {Array} 0 - SubCommand.WHERE with field name and range values
* @property {Array} 1 - SubCommand.WHERE with field name only
*/
type WhereType = (
| [SubCommand.WHERE, string, number, number]
| [SubCommand.WHERE, string]
)[];

/**
* Represents the values for WHERE IN clause
* @typedef {(number | string)[]} WhereInValues
*/
export type WhereInValues = (number | string)[];

/**
* Represents the WHERE IN clause
* @typedef {Array} WhereInType
* @property {Array} 0 - SubCommand.WHEREIN with field name and values
*/
type WhereInType = [SubCommand.WHEREIN, string, ...Array<string | number>][];

export interface Where {
/**
* Filter by values of a specific field
* @param {string} field - The field name
* @param {number} min - The minimum value
* @param {number} max - The maximum value
* @returns {this}
*/
where(field: string, min: number, max: number): this;

/**
* Filter by values of a specific field using expressions
* @param {string} expr - The where expression
* @returns {this}
*/
whereExpr(expr: string): this;

/**
* Filter by values of a specific field
* @param {string} field - The field name
* @param {WhereInValues} values - The values to set
* @returns {this}
*/
wherein(field: string, values: WhereInValues): this;
}

/**
* Whereable class provides methods for setting WHERE clauses
* @extends {Executable}
* @implements {Where}
*/
export class Whereable extends Executable implements Where {
private _where: WhereType = [];

private _wherein: WhereInType = [];

/**
* Compile WHERE clauses into command arguments
* @returns {CommandArgs}
*/
compileWhere(): CommandArgs {
return this._where.length ? [...this._where.flat()] : [];
}

/**
* Compile WHERE IN clauses into command arguments
* @returns {CommandArgs}
*/
compileWherein(): CommandArgs {
return this._wherein.length ? [...this._wherein.flat()] : [];
}

/**
* Reset WHERE and WHERE IN clauses
*/
resetWhere(): void {
this._where = [];
this._wherein = [];
}

/**
* Set a WHERE clause
* @param {Array} query - The WHERE query
*/
setWhere(
query:
| [SubCommand.WHERE, string, number, number]
Expand All @@ -42,16 +97,34 @@ export class Whereable extends Executable implements Where {
this._where.push(query);
}

/**
* Filter by values of a specific field
* @param {string} field - The field name
* @param {number} min - The minimum value
* @param {number} max - The maximum value
* @returns {this}
*/
where(field: string, min: number, max: number): this {
this.setWhere([SubCommand.WHERE, field, min, max]);
return this;
}

/**
* Filter by values of a specific field using expressions
* @param {string} expr - The where expression
* @returns {this}
*/
whereExpr(expr: string): this {
this.setWhere([SubCommand.WHERE, expr]);
return this;
}

/**
* Filter by values of a specific field
* @param {string} field - The field name
* @param {WhereInValues} values - The values to set
* @returns {this}
*/
wherein(field: string, values: WhereInValues): this {
this._wherein.push([
SubCommand.WHEREIN,
Expand Down
Loading

0 comments on commit 5386a7b

Please sign in to comment.