UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

41 lines (40 loc) 1.61 kB
import { isObject } from '../../../utils/validation/isObject.js'; export const isTimestampEnabled = (timestampOptions, timestampKey) => { if (timestampOptions === true) { return true; } if (isObject(timestampOptions)) { const timestampOptionsValue = timestampOptions[timestampKey]; if (timestampOptionsValue === true || typeof timestampOptionsValue === 'object') { return true; } } return false; }; const TIMESTAMPS_DEFAULTS_OPTIONS = { created: { name: 'created', savedAs: '_ct', hidden: false }, modified: { name: 'modified', savedAs: '_md', hidden: false } }; export const getTimestampOptionValue = (timestampsOptions, timestampKey, optionKey) => { var _a; const defaultOptions = TIMESTAMPS_DEFAULTS_OPTIONS[timestampKey][optionKey]; if (isObject(timestampsOptions)) { const timestampOptions = timestampsOptions[timestampKey]; return isObject(timestampOptions) ? (_a = timestampOptions[optionKey]) !== null && _a !== void 0 ? _a : defaultOptions : defaultOptions; } return defaultOptions; }; export const isEntityAttrEnabled = (entityAttrOptions) => Boolean(entityAttrOptions); const ENTITY_ATTR_DEFAULTS_OPTIONS = { name: 'entity', hidden: true }; export const getEntityAttrOptionValue = (entityAttrOptions, optionKey) => { var _a; const defaultOptions = ENTITY_ATTR_DEFAULTS_OPTIONS[optionKey]; return isObject(entityAttrOptions) ? (_a = entityAttrOptions[optionKey]) !== null && _a !== void 0 ? _a : defaultOptions : defaultOptions; };