/// import { Collection } from "./Collection"; import { EventEmitter } from "events"; import { ElementInData } from "./ElementInData"; import { Action } from "./Action"; interface DatabaseOptions { debug?: boolean; cPath?: boolean; autoDecrypt?: boolean; encryption?: { password: string; digest?: string; }; style?: { writing_format: (input: any) => any; reading_format: (input: any) => any; }; parse?: (input: Map) => string; stringify?: (input: Map) => string; } declare class Database extends EventEmitter { cPath: boolean; options: DatabaseOptions; readonly autoDecrypt: boolean; readonly fileExtension: string; readonly isYML: boolean; readonly path: string; readonly readyInDate: Date; inputPath: string; readonly encryption?: boolean; private encryptionPassword?; style: { writing_format: (input: any) => any; reading_format: (input: any) => any; }; readonly file_exists: boolean; crypto: any; stringify: (x: any) => any; parse: (x: any) => any; constructor(path: string, options?: DatabaseOptions); /** * @description Reads the file and returns the data * @example .cache * @returns {Collection} */ get cache(): Collection; /** * @description Sees the raw data * @example .raw * @returns {Object} */ get raw(): any; /** * @description Writes the data to the file * @example .writeFileSync() * @param {*} data * @returns {Promise} */ writeFileSync(collection: Collection): Promise; /** * @description Sets element in database * @example .set({version: "1.0.0"}) * @param {*} key Types a key for the element * @param {*} value Types a value for the element * @returns {Promise} */ set(key: any, value?: any): Promise; /** * @description Deletes an element from database * @example .delete({key:`version`}) * @param {*} key Types a key for the element * @returns {Promise} */ remove(key: any): Promise; /** * @description Deletes an element from database * @example .delete({key:`version`}) * @param {*} key Types a key for the element * @returns Promise */ delete(key: any): Promise; /** * @description Returns all elements in the Database * @example .all() * @param {*} limit default = 0 * @returns {ElementInData[]} */ all(limit?: number): ElementInData[]; /** * @description Returns all elements in the Database * @example .fetchAll() * @param {*} limit default = 0 * @returns {ElementInData[]} */ fetchAll(limit?: number): ElementInData[]; /** * @description Get all the elements in the database of value * @param {*} value * @example .getByValue({value:`v6`}) */ getByValue(value: any): { ID: any; typeof: { ID: string; data: string; }; data: any; }[] | false; /** * @description Get the value of a key * @example .get({key:`version`}) * @param {*} key Type a key for the element * @returns Boolean */ get(key: any, value?: any): any; /** * @description To fetch the value of a specific key element * @example .fetch({key:`version`}) * @param {*} key Type a key for the element * @returns {"boolean"} */ fetch(key: any): any; /** * @description Returns the number of items in the database */ get length(): () => number; /** * @description To get the file size * @example .fileSize * @returns {"object"} */ get fileSize(): { byte: number; megaBytes: number; kiloBytes: number; }; /** * @description Removes the first element of the array * @example .shift({key:`hello`}) * @param key * @returns {Promise} */ shift(key: any): Promise; /** * @description * @example .pop({key:`hello`}) * @param key * @returns {"any"} */ pop(key: any): any; /** * @description To pull an element from an array into data * @example .pull({key:`version`,value:"v6"}) * @param {*} key Type a key for the element * @returns {Promise} */ pull(key: any, value?: any): Promise; /** * @description To push an element to an array into data * @example .push({key:`version`,value:"v6"}) * @param {*} key Type a key for the element * @returns {Promise} */ push(key: any, value?: any): Promise; /** * @description To unshift an element to an array into data * @example .unshift({key:`version`,value:["v6"]}) * @param {*} key Type a key for the element * @returns {"boolean"} */ unshift(key: any, value?: any): Promise; /** * @description To get the value type of a given key element * @example .type({key:`xBase`}) * @param {*} key Type a key for the element * @returns {"symbol" | "array" | "undefined" | "string" | "number" | "bigint" | "boolean" | "object"} */ type(key: any): "symbol" | "array" | "undefined" | "string" | "number" | "bigint" | "boolean" | "object" | "function"; /** * @description Checking an item from the database if it exists or not * @example .has({key:`version`}) * @param {*} key Type a key for the element * @returns {"boolean"} */ has(key: any): boolean; /** * @param {*} value * @returns {"string"} */ encryptString(value: any): string; /** * @description Returns database connection uptime! * @return {"number"} * @example console.log(`Database is up for ${db.uptime} ms.`); */ get uptime(): number; /** * @example .valuesAll() * @returns {"any[]"} */ valuesAll(): any[]; /** * @example .keysAll() * @returns {"any[]"} */ keysAll(): any[]; /** * @param {*} value * @returns {"number","string"} */ decryptString(value: any): string | number; /** * @param {*} value * @returns {"boolean"} */ isEncryptString(value: any): boolean; /** * @description Reload the database * @example .reload(200) * @param {*} timeout Data relord working period * @returns {Promise} */ reload(timeout?: number): Promise; /** * @description Clean all data * @example .clear() * @returns {Promise} */ clear(): Promise; /** * @description Delete all data * @example .deleteAll() * @returns {Promise} */ deleteAll(): Promise; /** * @description Destroy the database * @example .destroy() * @returns {Promise} */ destroy(): void; /** * @description Check if the key starts with the key in the database * @example .startsWith({key:`xBase`}) * @param {*} key * @returns {Promise<{ ID: any, typeof: { ID: string, data: string }, data: any }[]>} */ startsWith(key: any): { ID: any; typeof: { ID: string; data: string; }; data: any; }[]; /** * @description Check if the key ends with the key in the database * @example .endsWith({key:`xBase`}) * @param {*} key * @returns {Promise<{ ID: any, typeof: { ID: string, data: string }, data: any }[]>} */ endsWith(key: any): { ID: any; typeof: { ID: string; data: string; }; data: any; }[]; /** * @description Filter the database by the key * @example .filter(t => t == "test") * @param {*} argument * @param {*} callback * @returns {Promise<{ ID: any, typeof: { ID: string, data: string }, data: any }[]>} */ filter(callback: any, argument?: any): { ID: any; typeof: { ID: string; data: string; }; data: any; }[]; /** * @description Check if the key includes with the key in the database * @example .includes({key:`xBase`}) * @param {*} key * @returns {Promise} */ includes(key: any): { ID: any; typeof: { ID: string; data: string; }; data: any; }[]; /** * @description Does a math calculation and stores the value in the database! * @param {string} key Data key * @param {string} operator One of +, -, %, * or / * @param {number} value The value, must be a number * @param {boolen} goToNegative Move to negative * @example db.math({key:"points",operator:"+",value:150}) * @return {Promise} */ math(key: { key: any; value: any; goToNegative?: boolean; operator: "-" | "+" | "*" | "/"; } | any, operator?: "-" | "+" | "*" | "/", new_value?: string | number, goToNegative?: boolean): Promise; /** * @example .add({key:`data`,value:2) * @param {string} key Data key * @param {number} value The value, must be a number * @returns {Promise} */ add(key: { key: any; value: any; } | any, value?: any): Promise; /** * @example .multiply({key:"coins", value:2}) * @param {string} key Data key * @param {number} value The value, must be a number * @returns {Promise} */ multiply(key: { key: any; value: any; } | any, value?: any): Promise; /** * @description Action is a class that is a dummy database where you can implement your methods without affecting the main database itself and save it for later whenever you want! * @example .action() */ action(): Action; /** * @example .double({key:"coins"}) * @param {string} key Data key * @param {number} value The value, must be a number * @returns {Promise} */ double(key: { key: any; value: any; } | any, value?: any): Promise; /** * @example .subtract({key:"coins", value:50}) * @param {string} key Data key * @param {number} value The value, must be a number * @returns {Promise} */ subtract(key: { key: any; value: any; } | any, value?: any): Promise; /** * @description Check if the value is numeric * @param {*} val * @returns {"boolean"} */ static isNumeric(val: string | number): boolean; static Style: { Array: { writing_format: { (arrayLike: ArrayLike): T[]; (arrayLike: ArrayLike, mapfn: (v: T_1, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T_2[]; (iterable: Iterable | ArrayLike, mapfn: (v: T_3, k: number) => U_1, thisArg?: any): U_1[]; }; reading_format: (a: any) => any; }; Object: { writing_format: { (entries: Iterable): { [k: string]: T_4; }; (entries: Iterable): any; }; reading_format: { (o: { [s: string]: T_5; } | ArrayLike): [string, T_5][]; (o: {}): [string, any][]; }; }; }; } /** * @event Database#ready * @example db.on("ready", () => { * console.log("Successfully connected to the database!"); * }); */ /** * @event Database#elementEdit * @param {ElementInData} elementInData elementInData * @example db.on("elementEdit", console.log); */ /** * Emitted for general warnings. * @event Database#elementAdd * @param {ElementInData} elementInData elementInData */ export { Collection, Database, ElementInData, Action };