Skip to content

feat(ddd): add Entity.toJSON primitive serializer#53

Merged
pourdaavar merged 3 commits into
mainfrom
feat/entity-tojson-primitives
Apr 28, 2026
Merged

feat(ddd): add Entity.toJSON primitive serializer#53
pourdaavar merged 3 commits into
mainfrom
feat/entity-tojson-primitives

Conversation

@pourdaavar
Copy link
Copy Markdown
Contributor

Summary

  • add a base Entity.toJSON() method that returns a single object with id, createdAt, and all entity props
  • normalize nested values recursively so JSON output is primitive-safe (dates, arrays, nested objects, and values exposing toJSON())
  • add unit coverage for Entity.toJSON() in the entity test suite

Context

This provides a consistent serialization contract at the entity base class level, reducing duplicate mapping logic in subclasses and making entity snapshots easier to use in transport/logging scenarios.

Breaking changes

  • None

Test plan

  • Unit test added for Entity.toJSON() output shape and primitive values
  • Unit tests pass in this environment
  • Manual testing completed

Notes

pnpm vitest packages/ddd/src/domain/entities/__tests__/entity.spec.ts currently fails in this environment due to an existing module resolution issue (Cannot find package '@/shared'), unrelated to this change.

Add Entity.toJSON() to emit id, createdAt, and props in one normalized primitive object so entity snapshots are consistent for transport and logging.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

🦋 Changeset detected

Latest commit: e7ea76f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@rineex/ddd Minor
@rineex/auth-core Patch
@rineex/authentication-method-otp Patch
@rineex/authentication-method-passwordless Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Introduce Entity.toJSON() method to return a JSON object containing id, createdAt, and entity properties, ensuring consistent serialization for transport and logging.
…n test

Adjust the entity serialization test to ensure the id property is included in the expected JSON output, maintaining consistency with the Entity.toJSON() implementation.
@pourdaavar pourdaavar merged commit e3b46a6 into main Apr 28, 2026
5 checks passed
@pourdaavar pourdaavar mentioned this pull request Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant