diff --git a/packages/prisma-factory/src/utils/getAttrs.ts b/packages/prisma-factory/src/utils/getAttrs.ts index a800e37..7c52f07 100644 --- a/packages/prisma-factory/src/utils/getAttrs.ts +++ b/packages/prisma-factory/src/utils/getAttrs.ts @@ -1,9 +1,16 @@ import type { ObjectWithMaybeCallbacks } from '../lib/types'; +const isNestedObject = (value: unknown): boolean => { + if (value instanceof Date) { + return false; + } + return typeof value === 'object'; +}; + export const getAttrs = (attrs: ObjectWithMaybeCallbacks): T => { return Object.fromEntries( Object.entries(attrs).map(([key, value]) => { - if (typeof value === 'object') { + if (isNestedObject(value)) { // recursively evaluate nested objects return [key, getAttrs(value as ObjectWithMaybeCallbacks)]; } @@ -11,7 +18,7 @@ export const getAttrs = (attrs: ObjectWithMaybeCallbacks): T => { if (typeof value === 'function') { const result = value(); - if (typeof result === 'object') { + if (isNestedObject(result)) { // recursively evaluate nested objects return [key, getAttrs(result as ObjectWithMaybeCallbacks)]; }