dynamodb-toolbox
Version:
Lightweight and type-safe query builder for DynamoDB and TypeScript.
48 lines (47 loc) • 2.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEntityAttrOptionValue = exports.isEntityAttrEnabled = exports.getTimestampOptionValue = exports.isTimestampEnabled = void 0;
const isObject_js_1 = require("../../../utils/validation/isObject.js");
const isTimestampEnabled = (timestampOptions, timestampKey) => {
if (timestampOptions === true) {
return true;
}
if ((0, isObject_js_1.isObject)(timestampOptions)) {
const timestampOptionsValue = timestampOptions[timestampKey];
if (timestampOptionsValue === true || typeof timestampOptionsValue === 'object') {
return true;
}
}
return false;
};
exports.isTimestampEnabled = isTimestampEnabled;
const TIMESTAMPS_DEFAULTS_OPTIONS = {
created: { name: 'created', savedAs: '_ct', hidden: false },
modified: { name: 'modified', savedAs: '_md', hidden: false }
};
const getTimestampOptionValue = (timestampsOptions, timestampKey, optionKey) => {
var _a;
const defaultOptions = TIMESTAMPS_DEFAULTS_OPTIONS[timestampKey][optionKey];
if ((0, isObject_js_1.isObject)(timestampsOptions)) {
const timestampOptions = timestampsOptions[timestampKey];
return (0, isObject_js_1.isObject)(timestampOptions)
? (_a = timestampOptions[optionKey]) !== null && _a !== void 0 ? _a : defaultOptions
: defaultOptions;
}
return defaultOptions;
};
exports.getTimestampOptionValue = getTimestampOptionValue;
const isEntityAttrEnabled = (entityAttrOptions) => Boolean(entityAttrOptions);
exports.isEntityAttrEnabled = isEntityAttrEnabled;
const ENTITY_ATTR_DEFAULTS_OPTIONS = {
name: 'entity',
hidden: true
};
const getEntityAttrOptionValue = (entityAttrOptions, optionKey) => {
var _a;
const defaultOptions = ENTITY_ATTR_DEFAULTS_OPTIONS[optionKey];
return (0, isObject_js_1.isObject)(entityAttrOptions)
? (_a = entityAttrOptions[optionKey]) !== null && _a !== void 0 ? _a : defaultOptions
: defaultOptions;
};
exports.getEntityAttrOptionValue = getEntityAttrOptionValue;