From 65c57b52ea1520b0bbd8648fc3ed01220b995c97 Mon Sep 17 00:00:00 2001 From: Praveen Yadav Date: Sun, 1 Dec 2024 02:03:12 +0530 Subject: [PATCH] fix some eslint issues --- src/ResultSet.ts | 4 +- src/error.ts | 2 +- src/types.ts | 141 +++++++++++++++++++++++------------------------ 3 files changed, 73 insertions(+), 74 deletions(-) diff --git a/src/ResultSet.ts b/src/ResultSet.ts index 55dc865..cb9bb50 100644 --- a/src/ResultSet.ts +++ b/src/ResultSet.ts @@ -418,7 +418,7 @@ export class ResultSet, Fields extends Readonly) { valArr(opt) this.#sortOptions = opt.map>(o => { - let s: OrderBy = isArray(o) ? o : [o, 'asc'] + const s: OrderBy = isArray(o) ? o : [o, 'asc'] if (s.length !== 2 || typeof s[0] !== 'string' || !['asc', 'desc'].includes(s[1])) throw new PDBError('Value', 'Incorrect values for orderBy') return s @@ -434,7 +434,7 @@ export class ResultSet, Fields extends Readonly extends Error { } } -type PDBErrorType = "Property" | "Value" | "Type" | "Event" | "Action" | "Filter" +type PDBErrorType = 'Property' | 'Value' | 'Type' | 'Event' | 'Action' | 'Filter' diff --git a/src/types.ts b/src/types.ts index c4a1956..3fa635e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,14 +1,14 @@ -import type { BinaryIndex } from "./BinaryIndex"; +import type { BinaryIndex } from './BinaryIndex' -export type FilterOption = "eq" | "neq" | "gt" | "gte" | "lt" | "lte" +export type FilterOption = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' export type FQ = [op: FilterOption, K: K, V: T[K]] - | [op: "in" | "nin", K: K, V: Set] - | [op: "btw", K: K, V1: T[K], V2: T[K]] - | [op: "nbtw", K: K, V1: T[K], V2: T[K]] + | [op: 'in' | 'nin', K: K, V: Set] + | [op: 'btw', K: K, V1: T[K], V2: T[K]] + | [op: 'nbtw', K: K, V1: T[K], V2: T[K]] -export type OrderBy = [key: keyof T, order: "asc" | "desc"] +export type OrderBy = [key: keyof T, order: 'asc' | 'desc'] export type SortOptions = ((keyof T) | OrderBy)[] export type Index = { [K in keyof T]: BinaryIndex | T[Key]> } @@ -16,42 +16,44 @@ export type Index = { [K in keyof T]: BinaryIndex = { /** - * "L" alias of load. fires when data loaded - */ - type: "L" + * 'L' alias of load. fires when data loaded + */ + type: 'L' } | { /** - * "C" alias of change. fires on any changes happened like (insert/update/delete) after some time (debounced) - */ - type: "C" + * 'C' alias of change. fires on any changes happened like (insert/update/delete) after some time (debounced) + */ + type: 'C' } | { /** - * "I" fires on row/record insert - */ - type: "I", payload: [T] + * 'I' fires on row/record insert + */ + type: 'I' + payload: [T] } | { /** - * "U" fires on row/record update - */ - type: "U", payload: [doc: T, oldDoc: T] + * 'U' fires on row/record update + */ + type: 'U' + payload: [doc: T, oldDoc: T] } | { /** - * "D" fires on row/record delete - */ - type: "D", payload: [T] + * 'D' fires on row/record delete + */ + type: 'D' + payload: [T] } | { /** - * "Q" alias of Quit. fires on database clone + * 'Q' alias of Quit. fires on database clone */ - type: "Q" + type: 'Q' } - export type Pretify = { [K in keyof T]: T[K] } & unknown @@ -60,148 +62,145 @@ export type Maybe = T | undefined | null export type MaybePartial = T | Partial - -export type BaseQueryBuilder, SecondaryBuilder> = { +export interface BaseQueryBuilder, SecondaryBuilder> { /** * return rows where field value is eqaul to given value * @example - * pd.select().eq("name", "Apple").data() - */ + * pd.select().eq('name', 'Apple').data() + */ eq: (field: K, value: T[K]) => SecondaryBuilder & BaseQueryBuilder /** * return rows where field value is in array of values * @throws if values are not in array * @example - * pd.select().nin("category", ["Fruit", "Vegetable"]).data() - */ + * pd.select().nin('category', ['Fruit', 'Vegetable']).data() + */ in: (field: K, values: T[K][]) => SecondaryBuilder & BaseQueryBuilder /** * return rows where field value is not in array of values * @throws if values are not in array * @example - * pd.select().nin("name", ["Apple", "Banana"]).data() - */ + * pd.select().nin('name', ['Apple', 'Banana']).data() + */ nin: (field: K, values: T[K][]) => SecondaryBuilder & BaseQueryBuilder /** * field value is between of 2 value, within a given range * @throws if values are not in array and the array is not length of 2 * @example - * pd.select().between("price", [140, 200]).data() - */ + * pd.select().between('price', [140, 200]).data() + */ between: (field: K, values: [T[K], T[K]]) => SecondaryBuilder & BaseQueryBuilder /** * field value is not between of 2 value, not within a given range * @throws if values are not in array and the array is not length of 2 * @example - * pd.select().nbetween("price", [120, 400]).data() - */ + * pd.select().nbetween('price', [120, 400]).data() + */ nbetween: (field: K, values: [T[K], T[K]]) => SecondaryBuilder & BaseQueryBuilder /** * return rows where field value is not eqaul to given value * @example - * pd.select().neq("name", "Apple").data() - */ + * pd.select().neq('name', 'Apple').data() + */ neq: (field: K, value: T[K]) => SecondaryBuilder & BaseQueryBuilder /** * return rows where field value is greater than to given value * @example - * pd.select().gt("price", 150).data() - */ + * pd.select().gt('price', 150).data() + */ gt: (field: K, value: T[K]) => SecondaryBuilder & BaseQueryBuilder /** * return rows where field value is greater than and eqaul to given value. * rows are order by the given field in ascending order * @example - * pd.select().gte("price", 100).data() - */ + * pd.select().gte('price', 100).data() + */ gte: (field: K, value: T[K]) => SecondaryBuilder & BaseQueryBuilder /** * return rows where field value is lower than to given value * @example - * pd.select().lt("price", 120).data() - */ + * pd.select().lt('price', 120).data() + */ lt: (field: K, value: T[K]) => SecondaryBuilder & BaseQueryBuilder /** * return rows where field value is lower than and eqaul to given value. * rows are order by the given field in ascending order * @example - * pd.select().lte("price", 120).data() - */ + * pd.select().lte('price', 120).data() + */ lte: (field: K, value: T[K]) => SecondaryBuilder & BaseQueryBuilder } -export type QueryBuilder, SecondaryBuilder> = { +export interface QueryBuilder, SecondaryBuilder> { /** * used to tell the starting point and length to return rows from a result set * @example * pd.select().range(2, 10).data() - */ - range: (offset: number, count?: number) => SecondaryBuilder & Omit, "range"> + */ + range: (offset: number, count?: number) => SecondaryBuilder & Omit, 'range'> /** * used to sort data with single or multiple keys - * + * * @example - * pd.select().orderBy("name", "price").data() - * pd.select().orderBy("name", ["price", "desc"]).data() - */ - orderBy: (opt: SortOptions) => SecondaryBuilder & Omit, "orderBy"> + * pd.select().orderBy('name', 'price').data() + * pd.select().orderBy('name', ['price', 'desc']).data() + */ + orderBy: (opt: SortOptions) => SecondaryBuilder & Omit, 'orderBy'> } -type SelectBaseQueryBuilder, Fields extends readonly (keyof T)[] | []> = { +interface SelectBaseQueryBuilder, Fields extends readonly (keyof T)[] | []> { /** * returns the first filtered row * @example - * pd.select().eq("id", 2).single() - * pd.select("name", "price").in("id", [2, 3, 8]).single() - */ + * pd.select().eq('id', 2).single() + * pd.select('name', 'price').in('id', [2, 3, 8]).single() + */ single: () => Pretify>> /** * returns all the filtered rows * @example - * pd.select("name", "price").in("id", [2, 3, 8]).data() - */ + * pd.select('name', 'price').in('id', [2, 3, 8]).data() + */ data: () => Pretify[]>> /** * count of the filtered rows/docs/records * @example - * pd.select().between("price", [8, 12]).count() - */ + * pd.select().between('price', [8, 12]).count() + */ count: () => number } -export type SelectQueryBuilder, Fields extends readonly (keyof T)[] | []> = SelectBaseQueryBuilder & BaseQueryBuilder & QueryBuilder>> & QueryBuilder> & { -} +export type SelectQueryBuilder, Fields extends readonly (keyof T)[] | []> = Pretify & BaseQueryBuilder & QueryBuilder>> & QueryBuilder>> -type WhereBaseQueryBuilder> = { +interface WhereBaseQueryBuilder> { /** * update all the docs with the given doc keys * @returns all updated docs if passed true as the param * @example - * pd.where().in("id", [2, 3, 8]).update({ price: 113 }) - */ + * pd.where().in('id', [2, 3, 8]).update({ price: 113 }) + */ update: (data: MaybePartial) => T[] /** * delete all the filtered docs/rows * @returns all removed docs - * @example - * pd.where().between("id", [8, 10]).delete() + * @example + * pd.where().between('id', [8, 10]).delete() */ delete: () => T[] } -export type WhereQueryBuilder> = WhereBaseQueryBuilder & BaseQueryBuilder> & { -} +export type WhereQueryBuilder> = Pretify & BaseQueryBuilder>>