inibase
Version:
A file-based & memory-efficient, serverless, ACID compliant, relational database management system
70 lines (69 loc) • 4.21 kB
TypeScript
import "dotenv/config";
import { execFile as execFileSync, exec as execSync } from "node:child_process";
import { gunzip as gunzipSync, gzip as gzipSync } from "node:zlib";
import RE2 from "re2";
import type { ComparisonOperator, FieldType } from "./index.js";
export declare const exec: typeof execSync.__promisify__;
export declare const execFile: typeof execFileSync.__promisify__;
export declare const gzip: typeof gzipSync.__promisify__;
export declare const gunzip: typeof gunzipSync.__promisify__;
/**
* Generates a hashed password using SHA-256.
*
* @param password - The plain text password to hash.
* @returns A string containing the salt and the hashed password, separated by a colon.
*/
export declare const hashPassword: (password: string) => string;
/**
* Compares a hashed password with an input password to verify a match.
*
* @param hashedPassword - The hashed password, containing both the salt and the hash, separated by a colon.
* @param inputPassword - The plain text input password to compare against the hashed password.
* @returns A boolean indicating whether the input password matches the hashed password.
*/
export declare const comparePassword: (hash: string, password: string) => boolean;
export declare const encodeID: (id: number | string) => string;
export declare function decodeID(input: string, raw: true): string | null;
export declare function decodeID(input?: string, raw?: false): number | null;
export declare const hashString: (str: string) => string;
/**
* Evaluates a comparison between two values based on a specified operator and field types.
*
* @param operator - The comparison operator (e.g., '=', '!=', '>', '<', '>=', '<=', '[]', '![]', '*', '!*').
* @param originalValue - The value to compare, can be a single value or an array of values.
* @param comparedValue - The value or values to compare against.
* @param fieldType - Optional type of the field.
* @returns boolean - Result of the comparison operation.
*
* Note: Handles various data types and comparison logic, including special handling for passwords and regex patterns.
*/
export declare const compare: (operator: ComparisonOperator, originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[], fieldType?: FieldType | FieldType[]) => boolean;
export declare const isEqual: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[], fieldType?: FieldType) => boolean;
/**
* Helper function to check array equality.
*
* @param originalValue - The original value.
* @param comparedValue - The value to compare against.
* @returns boolean - Result of the array equality check.
*/
export declare const isArrayEqual: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[]) => boolean;
/**
* Helper function to check wildcard pattern matching using regex.
*
* @param originalValue - The original value.
* @param comparedValue - The value with wildcard pattern.
* @returns boolean - Result of the wildcard pattern matching.
*/
export declare const isWildcardMatch: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[]) => boolean;
/**
* Retrieves a cached compiled regex or compiles and caches a new one.
*
* This function checks if a given regex pattern is already compiled and cached.
* If it is, the cached instance is returned. If not, the function attempts to compile
* the regex using RE2, caches the compiled instance, and then returns it. If the pattern
* is invalid, it returns a fallback object with a `test` method that always returns `false`.
*
* @param {string} pattern - The regex pattern to compile or retrieve from the cache.
* @returns {RE2} - The compiled regex instance or a fallback object on error.
*/
export declare const getCachedRegex: (pattern: string) => RE2;