UNPKG

easy-api.ts

Version:

A powerful library to create your own API with ease.

108 lines (107 loc) 3.61 kB
import { Database, DatabaseOptions } from "midb"; /** * This is the compatibility layer for any ea.ts * database instance. * @template T - The generic type to support the custom driver. * @template Args - The generic type that represents the type of the abstract `<delete | get | set | has>Value` method parameters. */ export declare abstract class BaseDatabase<T, Args> { /** * The custom database instance. */ abstract driver: T; /** * Deletes a value from the database. * @template Args - Generic type for method arguments. * @template Return - Generic type for method return. * @param args - The arguments for this method. */ abstract deleteValue<Return>(args: Args): Return | Promise<Return>; /** * Returns a value saven in the database. * @template Args - Generic type for method arguments. * @template Return - Generic type for method return. * @param args - The arguments for this method. */ abstract getValue<Return>(args: Args): Return | Promise<Return>; /** * Check whether the database has the given value. * @template Args - Generic type for method arguments. * @template Return - Generic type for method return. * @param args - The arguments for this method. */ abstract hasValue<Return>(args: Args): Return | Promise<Return>; /** * Set a value in the database. * @template Args - Generic type for method arguments. * @template Return - Generic type for method return. * @param args - The arguments for this method. */ abstract setValue<Return>(args: Args): Return | Promise<Return>; /** * Set the `start` method of the given database driver. * @param callback - Database method to call. * @returns {void | Promise<void>} */ abstract start<U extends () => any>(callback: U): void | Promise<void>; } /** * Method parameter interface for the native database. */ export interface NativeDatabaseMethodParameters { /** * The value identificator. */ key: string; /** * The variable value. */ value: string; /** * Table name to save the value into. */ table?: string; } /** * The default database driver provided in ea.ts */ export declare class NativeDatabase extends BaseDatabase<Database, NativeDatabaseMethodParameters> { /** * The driver of this database. */ driver: Database; /** * Starts an instance of this database. * @param options - Database options. */ constructor(options: DatabaseOptions); /** * Delete a value from the database. * @param args * @returns {Promise<void>} */ deleteValue<Return = void>({ key, table }: Omit<NativeDatabaseMethodParameters, "value">): Promise<Return>; /** * Delete a value from the database. * @param args * @returns {Promise<void>} */ hasValue<Return = boolean>({ key, table }: Omit<NativeDatabaseMethodParameters, "value">): Promise<Return>; /** * Delete a value from the database. * @param args * @returns {Promise<void>} */ getValue<Return>({ key, table }: NativeDatabaseMethodParameters): Promise<Return>; /** * Delete a value from the database. * @param args * @returns {Promise<void>} */ setValue<Return = void>({ key, value, table }: NativeDatabaseMethodParameters): Promise<Return>; /** * Starts the database driver. * @param callback - Callback to start the database driver with. */ start<U extends () => any>(callback: U): void; }