import _ from "lodash"; import Adapter from "./adapters/Adapter"; import { JabResult } from "./JabResult"; export default class JabTable { private _name; private adapter; readonly name: string; constructor(name: string, adapter: Adapter); private getEntries; private getTable; /** * Returns the amount of entries in the table * * @returns {Promise} the amount of entries in the table as a promise */ count(): Promise; /** * Returns the object with the specified id. * @param id The id of the entry to get * @param {boolean} returnUndefined if `true`, returns `undefined` instead of throwing exception if no entry is found * (`true` by default) * @returns The object as a promise * @throws Throws a {@link JabTableError} if entry does not exist in table */ get(id: string, returnUndefined?: boolean): JabResult; /** * Returns all objects matching the predicate * @param predicate search predicate * @returns All objects matching the predicate as an array. Empty array if none was found */ find(predicate: (v: T) => boolean): JabResult; private isEntries; /** * Create a new entry in the table * * @param {*} entry The object to insert * @param {string} [id] the id of the object, a unique id is automatically created by default * @returns {string} Returns the id of the entry */ create(entry: any, id?: string): Promise; /** * Returns a new ID based on the `count` field on the table, * and increase `count` by 1 */ private static getNewId; /** * Put an entry into the table. * If any entry with the same id already exists, it its overridden. * * @param {string} id the id of the entry * @param {*} entry the object to put in the table * @returns {Promise} */ put(id: string, entry: any): Promise; /** * Patch an entry in the table, this updates the fields specified. * @param {...any} changes A list of changes to be made to the entry * * This method uses assignIn from lodash * @see https://lodash.com/docs/#assignIn */ patch(id: string, ...changes: any): Promise; /** * Patch an entry in the table, this updates the fields specified. * Uses the customizer if not null. * @param {lodash.AssignCustomizer} customizer A customizer invoked to produce assigned values * if customizer is null, the function acts the same as `patch` @see JabTable.patch * @param {...any} changes A list of changes to be made to the entry * * This method uses assignInWith from lodash * @see https://lodash.com/docs/#assignInWith */ patchWith(id: string, customizer: _.AssignCustomizer, ...changes: any): Promise; /** * Delete an entry from the table by its id * * @param {string} id The id of the entry to remove */ delete(id: string): Promise; }