95 lines
3.3 KiB
TypeScript
95 lines
3.3 KiB
TypeScript
import { Config } from "./lib/JsonDBConfig";
|
|
export declare type FindCallback = (entry: any, index: number | string) => boolean;
|
|
export declare class JsonDB {
|
|
private loaded;
|
|
private data;
|
|
private readonly config;
|
|
/**
|
|
* JSONDB Constructor
|
|
* @param filename where to save the "DB". Can also be used to give the whole configuration
|
|
* @param saveOnPush save the database at each push command into the json file
|
|
* @param humanReadable the JSON file will be readable easily by a human
|
|
* @param separator what to use as separator
|
|
*/
|
|
constructor(filename: string | Config, saveOnPush?: boolean, humanReadable?: boolean, separator?: string);
|
|
/**
|
|
* Process datapath into different parts
|
|
* @param dataPath
|
|
*/
|
|
private processDataPath;
|
|
private retrieveData;
|
|
private getParentData;
|
|
/**
|
|
* Get the wanted data
|
|
* @param dataPath path of the data to retrieve
|
|
*/
|
|
getData(dataPath: string): any;
|
|
/**
|
|
* Same as getData only here it's directly typed to your object
|
|
* @param dataPath path of the data to retrieve
|
|
*/
|
|
getObject<T>(dataPath: string): T;
|
|
/**
|
|
* Check for existing datapath
|
|
* @param dataPath
|
|
*/
|
|
exists(dataPath: string): boolean;
|
|
/**
|
|
* Returns the number of element which constitutes the array
|
|
* @param dataPath
|
|
*/
|
|
count(dataPath: string): number;
|
|
/**
|
|
* Returns the index of the object that meets the criteria submitted.
|
|
* @param dataPath base dataPath from where to start searching
|
|
* @param searchValue value to look for in the dataPath
|
|
* @param propertyName name of the property to look for searchValue
|
|
*/
|
|
getIndex(dataPath: string, searchValue: (string | number), propertyName?: string): number;
|
|
/**
|
|
* Find all specific entry in an array/object
|
|
* @param rootPath base dataPath from where to start searching
|
|
* @param callback method to filter the result and find the wanted entry. Receive the entry and it's index.
|
|
*/
|
|
filter<T>(rootPath: string, callback: FindCallback): T[] | undefined;
|
|
/**
|
|
* Find a specific entry in an array/object
|
|
* @param rootPath base dataPath from where to start searching
|
|
* @param callback method to filter the result and find the wanted entry. Receive the entry and it's index.
|
|
*/
|
|
find<T>(rootPath: string, callback: FindCallback): T | undefined;
|
|
/**
|
|
* Pushing data into the database
|
|
* @param dataPath path leading to the data
|
|
* @param data data to push
|
|
* @param override overriding or not the data, if not, it will merge them
|
|
*/
|
|
push(dataPath: string, data: any, override?: boolean): void;
|
|
/**
|
|
* Delete the data
|
|
* @param dataPath path leading to the data
|
|
*/
|
|
delete(dataPath: string): void;
|
|
/**
|
|
* Only use this if you know what you're doing.
|
|
* It reset the full data of the database.
|
|
* @param data
|
|
*/
|
|
resetData(data: any): void;
|
|
/**
|
|
* Reload the database from the file
|
|
*/
|
|
reload(): void;
|
|
/**
|
|
* Manually load the database
|
|
* It is automatically called when the first getData is done
|
|
*/
|
|
load(): void;
|
|
/**
|
|
* Manually save the database
|
|
* By default you can't save the database if it's not loaded
|
|
* @param force force the save of the database
|
|
*/
|
|
save(force?: boolean): void;
|
|
}
|