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