@nerdware/ddb-single-table
Version:
A schema-based DynamoDB modeling tool, high-level API, and type-generator built to supercharge single-table designs!⚡
30 lines (29 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TIMESTAMP_ATTRIBUTES = exports.BASE_TIMESTAMP_ATTRIBUTE_CONFIG = void 0;
const ts_type_safety_utils_1 = require("@nerdware/ts-type-safety-utils");
const index_js_1 = require("../utils/index.js");
/**
* A base timestamp attribute config for a Model-schema's "createdAt" and/or "updatedAt" attributes.
*/
exports.BASE_TIMESTAMP_ATTRIBUTE_CONFIG = {
type: "Date",
required: true,
default: () => new Date(),
validate: (value) => (0, ts_type_safety_utils_1.isDate)(value) || (0, index_js_1.isValidIso8601DatetimeString)(value),
};
/**
* Timestamp attributes for a ModelSchema.
*/
exports.TIMESTAMP_ATTRIBUTES = {
createdAt: {
...exports.BASE_TIMESTAMP_ATTRIBUTE_CONFIG,
},
updatedAt: {
...exports.BASE_TIMESTAMP_ATTRIBUTE_CONFIG,
transformValue: {
/** This toDB ensures `updatedAt` is updated on every write operation. */
toDB: () => new Date(),
},
},
};