@naturalcycles/db-lib
Version:
Lowest Common Denominator API to supported Databases
32 lines (31 loc) • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createdUpdatedFields = createdUpdatedFields;
exports.createdUpdatedIdFields = createdUpdatedIdFields;
exports.deserializeJsonField = deserializeJsonField;
exports.serializeJsonField = serializeJsonField;
const js_lib_1 = require("@naturalcycles/js-lib");
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
function createdUpdatedFields(existingObject) {
const now = js_lib_1.localTime.nowUnix();
return {
created: existingObject?.created || now,
updated: now,
};
}
function createdUpdatedIdFields(existingObject) {
const now = js_lib_1.localTime.nowUnix();
return {
created: existingObject?.created || now,
id: existingObject?.id || (0, nodejs_lib_1.stringId)(),
updated: now,
};
}
function deserializeJsonField(f) {
return JSON.parse(f || '{}');
}
function serializeJsonField(f) {
if (f === undefined)
return;
return JSON.stringify(f);
}