From fac0e057e14d8b399927c13463d3a2cb7105fa6a Mon Sep 17 00:00:00 2001 From: Baruch Odem Date: Thu, 13 Mar 2025 09:45:44 +0200 Subject: [PATCH] feat: add WithTimestamp type for document timestamps Added a new WithTimestamp type that adds createdAt and updatedAt fields of type Date to any object shaped type. This follows the same pattern as the existing WithId type and allows for easy addition of timestamp fields to MongoDB document types. --- src/mongo_types.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mongo_types.ts b/src/mongo_types.ts index fda9909429b..d27771e5cd8 100644 --- a/src/mongo_types.ts +++ b/src/mongo_types.ts @@ -45,6 +45,9 @@ export type InferIdType = TSchema extends { _id: infer IdType } /** Add an _id field to an object shaped type @public */ export type WithId = EnhancedOmit & { _id: InferIdType }; +/** Add timestamp fields (createdAt and updatedAt) to an object shaped type @public */ +export type WithTimestamp = TSchema & { createdAt: Date; updatedAt: Date }; + /** * Add an optional _id field to an object shaped type * @public