UNPKG

helene

Version:
74 lines (73 loc) 3.07 kB
/** * Handle models (i.e. docs) * Serialization/deserialization * Copying * Querying, update */ /** * Check a key, throw an error if the key is non valid * @param {String} key key * @param {Model} value value, needed to treat the Date edge case * Non-treatable edge cases here: if part of the object if of the form { $$date: number } or { $$deleted: true } * Its serialized-then-deserialized version it will transformed into a Date object * But you really need to want it to trigger such behaviour, even when warned not to use '$' at the beginning of the field names... */ export declare function checkKey(key: number | string, value: any): void; /** * Check a DB object and throw an error if it's not valid * Works by applying the above checkKey function to all fields recursively */ export declare function checkObject(obj: Record<string, any>[] | Record<string, any>): void; /** * Deep copy a DB object * The optional strictKeys flag (defaulting to false) indicates whether to copy everything or only fields * where the keys are valid, i.e. don't begin with $ and don't contain a . */ export declare function deepCopy<T>(obj: T & { _id?: string; }, strictKeys?: boolean): T; /** * Tells if an object is a primitive type or a "real" object * Arrays are considered primitive */ export declare function isPrimitiveType(obj: any): boolean; /** * Compare { things U undefined } * Things are defined as any native types (string, number, boolean, null, date) and objects * We need to compare with undefined as it will be used in indexes * In the case of objects and arrays, we deep-compare * If two objects dont have the same type, the (arbitrary) type hierarchy is: undefined, null, number, strings, boolean, dates, arrays, objects * Return -1 if a < b, 1 if a > b and 0 if a = b (note that equality here is NOT the same as defined in areThingsEqual!) * * @param a * @param b * @param {Function} _compareStrings String comparing function, returning -1, 0 or 1, overriding default string comparison (useful for languages with accented letters) */ export declare function compareThings(a: any, b: any, _compareStrings?: (a: string, b: string) => number): any; /** * Modify a DB object according to an update query */ export declare function modify(obj: any, updateQuery: any): any; /** * Get a value from object with dot notation * @param {Object} obj * @param {String} field */ export declare function getDotValue(obj: any, field: any): any; /** * Check whether 'things' are equal * Things are defined as any native types (string, number, boolean, null, date) and objects * In the case of object, we check deep equality * Returns true if they are, false otherwise */ export declare function areThingsEqual(a: any, b: any): boolean; /** * Check that two values are comparable */ export declare function areComparable(a: any, b: any): boolean; /** * Tell if a given document matches a query * @param {Object} obj Document to check * @param {Object} query */ export declare function match(obj: any, query: any): boolean;