4lessandrodev / rich-domain

A lib to help you create a robust project based on domain driven-design (ddd) principles with typescript and zero dependencies.
https://www.npmjs.com/package/rich-domain
MIT License
122 stars 5 forks source link

fix(utils): fix circular ref json.stringify #170

Closed GaetanCottrez closed 3 months ago

GaetanCottrez commented 3 months ago

Fix

Converting circular structure to JSON can occur during validation in the Validator class in the isObject method during this check: if (JSON.stringify(props) === JSON.stringify({})) return true;. The problem occurs when an Entity has props that contains another Entity or an array of Entities because the entities contain _domainEvents, which is a circular ref.

A new utils function named stringify allows handling circular ref similar to JSON.stringify.

issue

https://github.com/4lessandrodev/type-ddd/issues/414