diff --git a/packages/ddd-kit/package.json b/packages/ddd-kit/package.json index 56683b7..a188aa6 100644 --- a/packages/ddd-kit/package.json +++ b/packages/ddd-kit/package.json @@ -2,8 +2,8 @@ "name": "@packages/ddd-kit", "version": "0.0.0", "private": true, - "main": "index.ts", - "types": "index.ts", + "main": "src/index.ts", + "types": "src/index.ts", "scripts": { "build": "tsc" }, diff --git a/packages/ddd-kit/src/core/Entity.ts b/packages/ddd-kit/src/core/Entity.ts index 9478e1f..a904142 100644 --- a/packages/ddd-kit/src/core/Entity.ts +++ b/packages/ddd-kit/src/core/Entity.ts @@ -5,17 +5,21 @@ import { UUID } from "./UUID"; * Interface for domain entities. * Entities are objects defined by their identity rather than their attributes. */ -export interface IEntity { +export interface IEntity { /** * Unique identifier of the entity. */ readonly _id: UUID; + /** + * Properties of the entity. + */ + readonly _props: T; /** * Checks if another object is equal to this entity. * @param object The object to compare. * @returns True if the objects are equal, false otherwise. */ - equals(object?: IEntity): boolean; + equals(object?: IEntity): boolean; /** * Returns the properties of the entity. */ @@ -31,7 +35,7 @@ export interface IEntity { * @param v The value to check. * @returns True if the value is an entity, false otherwise. */ -function isEntity(v: unknown): v is IEntity { +function isEntity(v: unknown): v is IEntity { return v instanceof Entity; } @@ -40,8 +44,8 @@ function isEntity(v: unknown): v is IEntity { * Entities are defined by their unique identity and encapsulate domain logic. * @template T The type of the entity's properties. */ -export abstract class Entity implements IEntity { - protected readonly _props: T; +export abstract class Entity implements IEntity { + public readonly _props: T; public readonly _id: UUID; /** @@ -59,7 +63,7 @@ export abstract class Entity implements IEntity { * @param object The object to compare. * @returns True if the objects are equal, false otherwise. */ - public equals(object?: IEntity): boolean { + public equals(object?: IEntity): boolean { if (!object || this === object || !isEntity(object)) return false; return this._id.equals(object._id); diff --git a/packages/ddd-kit/src/core/ValueObject.ts b/packages/ddd-kit/src/core/ValueObject.ts index 23dbec6..af8b971 100644 --- a/packages/ddd-kit/src/core/ValueObject.ts +++ b/packages/ddd-kit/src/core/ValueObject.ts @@ -12,7 +12,7 @@ export abstract class ValueObject { * Creates a new ValueObject instance. * @param value The value to encapsulate. */ - protected constructor(value: T) { + public constructor(value: T) { this._value = Object.freeze(value); } diff --git a/packages/ddd-kit/src/types/BaseRepository.ts b/packages/ddd-kit/src/types/BaseRepository.ts index 6a7b17b..defca2d 100644 --- a/packages/ddd-kit/src/types/BaseRepository.ts +++ b/packages/ddd-kit/src/types/BaseRepository.ts @@ -1,3 +1,4 @@ +import type { IEntity } from "@/core/Entity"; import type { Option } from "@/core/Option"; import type { Result } from "@/core/Result"; @@ -6,7 +7,7 @@ import type { Result } from "@/core/Result"; * Repositories abstract the persistence layer for aggregates/entities. * @template T The type of entity managed by the repository. */ -export interface BaseRepository { +export interface BaseRepository> { /** * Persists a new entity. * @param entity The entity to create. @@ -24,7 +25,7 @@ export interface BaseRepository { * @param entity The entity to delete. * @returns A Result indicating success or failure. */ - delete(entity: T): Promise>; + delete(entity: T["_id"]): Promise>; /** * Finds an entity by its unique identifier. * @param id The unique identifier. @@ -41,7 +42,7 @@ export interface BaseRepository { * @param props Partial properties to match. * @returns An Option containing the entity or None. */ - findBy(props: Partial): Promise>; + findBy(props: Partial): Promise>; /** * Checks if an entity exists by its unique identifier. * @param id The unique identifier.