inibase
Version:
A file-based & memory-efficient, serverless, ACID compliant, relational database management system
221 lines (220 loc) • 9.95 kB
TypeScript
import type { ComparisonOperator, Field, FieldType, Schema } from "./index.js";
/**
* Type guard function to check if the input is an array of objects.
*
* @param input - The value to be checked.
* @returns boolean - True if the input is an array of objects, false otherwise.
*
* Note: Considers empty arrays and arrays where every element is an object.
*/
export declare const isArrayOfObjects: (input: unknown) => input is Record<any, any>[];
/**
* Type guard function to check if the input is an array of arrays.
*
* @param input - The value to be checked.
* @returns boolean - True if the input is an array of arrays, false otherwise.
*
* Note: Considers empty arrays and arrays where every element is also an array.
*/
export declare const isArrayOfArrays: (input: unknown) => input is any[][];
/**
* Type guard function to check if the input is an array of nulls or an array of arrays of nulls.
*
* @param input - The value to be checked.
* @returns boolean - True if the input is an array consisting entirely of nulls or arrays of nulls, false otherwise.
*
* Note: Recursively checks each element, allowing for nested arrays of nulls.
*/
export declare const isArrayOfNulls: (input: unknown) => input is null[] | null[][];
/**
* Type guard function to check if the input is an object.
*
* @param obj - The value to be checked.
* @returns boolean - True if the input is an object (excluding arrays), false otherwise.
*
* Note: Checks if the input is non-null and either has 'Object' as its constructor name or is of type 'object' without being an array.
*/
export declare const isObject: (object: unknown) => object is Record<any, any>;
/**
* Type guard function to check if the input is a number.
*
* @param input - The value to be checked.
* @returns boolean - True if the input is a number, false otherwise.
*
* Note: Validates that the input can be parsed as a float and that subtracting zero results in a number, ensuring it's a numeric value.
*/
export declare const isNumber: (input: unknown) => input is number;
/**
* Checks if the input is a valid email format.
*
* @param input - The value to be checked.
* @returns boolean - True if the input matches the email format, false otherwise.
*
* Note: Uses a regular expression to validate the email format, ensuring it has parts separated by '@' and contains a domain with a period.
*/
export declare const isEmail: (input: unknown) => boolean;
/**
* Checks if the input is a valid URL format.
*
* @param input - The value to be checked.
* @returns boolean - True if the input matches the URL format, false otherwise.
*
* Note: Validates URLs including protocols (http/https), domain names, IP addresses, ports, paths, query strings, and fragments.
* Also recognizes 'tel:' and 'mailto:' as valid URL formats, as well as strings starting with '#' without spaces.
*/
export declare const isURL: (input: unknown) => boolean;
/**
* Checks if the input contains HTML tags or entities.
*
* @param input - The value to be checked.
* @returns boolean - True if the input contains HTML tags or entities, false otherwise.
*
* Note: Uses a regular expression to detect HTML tags (like <tag>) and entities (like &entity;).
* Recognizes both opening and closing tags, as well as self-closing tags.
*/
export declare const isHTML: (input: unknown) => boolean;
/**
* Type guard function to check if the input is a string, excluding strings that match specific formats (number, boolean, email, URL, IP).
*
* @param input - The value to be checked.
* @returns boolean - True if the input is a string that doesn't match the specific formats, false otherwise.
*
* Note: Validates the input against being a number, boolean, email, URL, or IP address to ensure it's a general string.
*/
export declare const isString: (input: unknown) => input is string;
/**
* Checks if the input is a valid IP address format.
*
* @param input - The value to be checked.
* @returns boolean - True if the input matches the IP address format, false otherwise.
*
* Note: Uses a regular expression to validate IP addresses, ensuring they consist of four octets, each ranging from 0 to 255.
*/
export declare const isIP: (input: unknown) => input is string;
/**
* Type guard function to check if the input is a boolean or a string representation of a boolean.
*
* @param input - The value to be checked.
* @returns boolean - True if the input is a boolean value or 'true'/'false' strings, false otherwise.
*
* Note: Recognizes both boolean literals (true, false) and their string representations ("true", "false").
*/
export declare const isBoolean: (input: unknown) => input is boolean;
/**
* Type guard function to check if the input is a password based on a specific length criterion.
*
* @param input - The value to be checked.
* @returns boolean - True if the input is a string with a length of 161 characters, false otherwise.
*
* Note: Specifically checks for string length to determine if it matches the defined password length criterion.
*/
export declare const isPassword: (input: unknown) => input is string;
/**
* Checks if the input can be converted to a valid date.
*
* @param input - The input to be checked, can be of any type.
* @returns A boolean indicating whether the input is a valid date.
*/
export declare const isDate: (input: unknown) => input is Date | number;
/**
* Checks if the input is a valid ID.
*
* @param input - The input to be checked, can be of any type.
* @returns A boolean indicating whether the input is a string representing a valid ID of length 32.
*/
export declare const isValidID: (input: unknown) => input is string;
/**
* Checks if a given string is a valid JSON.
*
* @param {string} input - The string to be checked.
* @returns {boolean} Returns true if the string is valid JSON, otherwise false.
*/
export declare const isStringified: (input: unknown) => boolean;
/**
* Recursively merges properties from a source object into a target object. If a property exists in both, the source's value overwrites the target's.
*
* @param target - The target object to merge properties into.
* @param source - The source object from which properties are merged.
* @returns any - The modified target object with merged properties.
*
* Note: Performs a deep merge for nested objects. Non-object properties are directly overwritten.
*/
export declare const deepMerge: (target: any, source: any) => any;
/**
* Identifies and returns properties that have changed between two objects.
*
* @param obj1 - The first object for comparison, with string keys and values.
* @param obj2 - The second object for comparison, with string keys and values.
* @returns A record of changed properties with original values from obj1 and new values from obj2, or null if no changes are found.
*/
export declare const findChangedProperties: (obj1: Record<string, string>, obj2: Record<string, string>) => Record<string, string> | null;
/**
* Detects the field type of an input based on available types.
*
* @param input - The input whose field type is to be detected.
* @param availableTypes - An array of potential field types to consider.
* @returns The detected field type as a string, or undefined if no matching type is found.
*/
export declare const detectFieldType: (input: any, availableTypes: FieldType[]) => FieldType | undefined;
export declare const isFieldType: (field: Field, compareAtType: string | string[]) => boolean;
export declare const flattenSchema: (schema: Schema, keepParents?: boolean) => Schema;
export declare const filterSchema: (schema: Schema, callback: (arg0: Field) => boolean) => Field[];
/**
* Validates if the given value matches the specified field type(s).
*
* @param value - The value to be validated.
* @param field - Field object config.
* @returns A boolean indicating whether the value matches the specified field type(s).
*/
export declare const validateFieldType: (value: any, field: Field) => boolean;
export declare const FormatObjectCriteriaValue: (value: string) => [ComparisonOperator, string | number | boolean | null | (string | number | null)[]];
/**
* Get field from schema
*
* @export
* @param {string} keyPath Support dot notation path
* @param {Schema} schema
*/
export declare const getField: (keyPath: string, schema: Schema) => Field;
/**
* Override a schema field, key, type or other properties
*
* @export
* @param {string} keyPath Support dot notation path
* @param {Schema} schema
* @param {(Omit<Field, "key" | "type"> & {
* key?: string;
* type?: FieldType | FieldType[];
* })} field
*/
export declare const setField: (keyPath: string, schema: Schema, field: Omit<Field, "key" | "type"> & {
key?: string;
type?: FieldType | FieldType[];
}) => Field;
/**
* Remove field from schema
*
* @export
* @param {string} keyPath Support dot notation path
* @param {Schema} schema
*/
export declare const unsetField: (keyPath: string, schema: Schema) => Field;
export declare function toDotNotation(obj: Record<string, any>, skipKeys?: string[], currentPath?: string): Record<string, any>;
export declare const extractIdsFromSchema: (schema: Schema) => number[];
/**
* Finds the last ID number in a schema, potentially decoding it if encrypted.
*
* @param schema - The schema to search, defined as an array of schema objects.
* @returns The last ID number in the schema, decoded if necessary.
*/
export declare const findLastIdNumber: (schema: Schema) => number;
/**
* Adds or updates IDs in a schema, encoding them using a provided secret key or salt.
*
* @param schema - The schema to update, defined as an array of schema objects.
* @param startWithID - An object containing the starting ID for generating new IDs.
* @returns The updated schema with encoded IDs.
*/
export declare function addIdToSchema(schema: Schema, startWithID: {
value: number;
}): Field[];