import { Dict } from '../common'; /** * Function to be used to construct an update object. If value is null or undefined - property will not be updated. Example: * * ```ts await update('table_name', { title: element.title, ...optional(element.description, val => ({ description: val })), }, { id: elementId }, ).run(ctx); * ``` * * @param val value to be used to update a property * @param map mapping function that will return an update object for the property */ export const optional = ( val: T, map: (val: T) => Dict, ): false | Dict => { return val !== undefined && val !== null && map(val); }; /** * Function to be used to construct an update object. If value is undefined - property will not be updated. If value is null - it will be set. Useful for Date properties. Example: * * ```ts await update('table_name', { title: element.title, ...nullable(element.released, val => ({ released: val })), }, { id: elementId }, ).run(ctx); * ``` * * @param val value to be used to update a property * @param map mapping function that will return an update object for the property */ export const nullable = ( val: T, map: (val: T) => Dict, ): false | Dict => { return val !== undefined && map(val); };