UNPKG

inibase

Version:

A file-based & memory-efficient, serverless, ACID compliant, relational database management system

118 lines (117 loc) 7.08 kB
import { type ComparisonOperator, type Field } from "./index.js"; export declare const lock: (folderPath: string, prefix?: string) => Promise<void>; export declare const unlock: (folderPath: string, prefix?: string) => Promise<void>; export declare const write: (filePath: string, data: any) => Promise<void>; export declare const read: (filePath: string) => Promise<string>; export declare function escapeShellPath(filePath: string): string; /** * Checks if a file or directory exists at the specified path. * * @param path - The path to the file or directory. * @returns A Promise that resolves to true if the file/directory exists, false otherwise. */ export declare const isExists: (path: string) => Promise<boolean>; /** * Encodes the input using 'secureString' and 'Inison.stringify' functions. * If the input is an array, it is first secured and then joined into a string. * If the input is a single value, it is directly secured. * * @param input - A value or array of values (string, number, boolean, null). * @returns The secured and/or joined string. */ export declare const encode: (input: string | number | boolean | null | (string | number | boolean | null)[]) => string | number | boolean | null; /** * Decodes the input based on the specified field type(s) and an optional secret key. * Handles different formats of input, including strings, numbers, and their array representations. * * @param input - The input to be decoded, can be a string, number, or null. * @param field - Field object config. * @returns Decoded value as a string, number, boolean, or array of these, or null if no fieldType or input is null/empty. */ export declare const decode: (input: string | null | number, field: Field & { databasePath?: string; }) => string | number | boolean | null | (string | number | null | boolean)[]; /** * Asynchronously reads and decodes data from a file at specified line numbers. * Decodes each line based on specified field types and an optional secret key. * * @param filePath - Path of the file to be read. * @param lineNumbers - Optional line number(s) to read from the file. If -1, reads the last line. * @param field - Field object config. * @param readWholeFile - Optional Flag to indicate whether to continue reading the file after reaching the limit. * @returns Promise resolving to a tuple: * 1. Record of line numbers and their decoded content or null if no lines are read. * 2. Total count of lines processed. */ export declare function get(filePath: string, lineNumbers?: number | number[], field?: Field & { databasePath?: string; }, readWholeFile?: false): Promise<Record<number, string | number | boolean | null | (string | number | boolean | (string | number | boolean)[] | null)[]> | null>; export declare function get(filePath: string, lineNumbers: undefined | number | number[], field: undefined | (Field & { databasePath?: string; }), readWholeFile: true): Promise<[ Record<number, string | number | boolean | null | (string | number | boolean | (string | number | boolean)[] | null)[]> | null, number ]>; /** * Asynchronously replaces specific lines in a file based on the provided replacements map or string. * * @param filePath - Path of the file to modify. * @param replacements - Map of line numbers to replacement values, or a single replacement value for all lines. * Can be a string, number, boolean, null, array of these types, or a Record/Map of line numbers to these types. * @returns Promise<string[]> * * Note: If the file doesn't exist and replacements is an object, it creates a new file with the specified replacements. */ export declare const replace: (filePath: string, replacements: string | number | boolean | null | (string | number | boolean | null)[] | Record<number, string | boolean | number | null | (string | boolean | number | null)[]>, totalItems?: number) => Promise<string[]>; /** * Asynchronously appends data to the end of a file. * * @param filePath - Path of the file to append to. * @param data - Data to append. Can be a string, number, or an array of strings/numbers. * @returns Promise<string[]>. Modifies the file by appending data. * */ export declare const append: (filePath: string, data: string | number | (string | number)[]) => Promise<string[]>; /** * Asynchronously prepends data to the beginning of a file. * * @param filePath - Path of the file to append to. * @param data - Data to append. Can be a string, number, or an array of strings/numbers. * @returns Promise<string[]>. Modifies the file by appending data. * */ export declare const prepend: (filePath: string, data: string | number | (string | number)[]) => Promise<string[]>; /** * Asynchronously removes specified lines from a file. * * @param filePath - Path of the file from which lines are to be removed. * @param linesToDelete - A single line number or an array of line numbers to be deleted. * @returns Promise<string[]>. Modifies the file by removing specified lines. * * Note: Creates a temporary file during the process and replaces the original file with it after removing lines. */ export declare const remove: (filePath: string, linesToDelete: number | number[]) => Promise<string[]>; /** * Asynchronously searches a file for lines matching specified criteria, using comparison and logical operators. * * @param filePath - Path of the file to search. * @param operator - Comparison operator(s) for evaluation (e.g., '=', '!=', '>', '<'). * @param comparedAtValue - Value(s) to compare each line against. * @param logicalOperator - Optional logical operator ('and' or 'or') for combining multiple comparisons. * @param field - Field object config. * @param limit - Optional limit on the number of results to return. * @param offset - Optional offset to start returning results from. * @param readWholeFile - Flag to indicate whether to continue reading the file after reaching the limit. * @returns Promise resolving to a tuple: * 1. Record of line numbers and their content that match the criteria or null if none. * 2. The count of found items or processed items based on the 'readWholeFile' flag. * * Note: Decodes each line for comparison and can handle complex queries with multiple conditions. */ export declare const search: (filePath: string, operator: ComparisonOperator | ComparisonOperator[], comparedAtValue: string | number | boolean | null | (string | number | boolean | null)[], logicalOperator?: "and" | "or", searchIn?: Set<number>, field?: Field & { databasePath?: string; }, limit?: number, offset?: number, readWholeFile?: boolean) => Promise<[Record<number, string | number | boolean | null | (string | number | boolean | null)[]> | null, number, Set<number> | null]>; export declare const sum: (fp: string, ln?: number | number[]) => Promise<number>; export declare const min: (fp: string, ln?: number | number[]) => Promise<number>; export declare const max: (fp: string, ln?: number | number[]) => Promise<number>; export declare const getFileDate: (path: string) => Promise<Date>;