Create a new entity builder.
Entities validate props, attach domain methods, and return frozen immutable
instances. with(...) revalidates the merged props. .Type is type-only and
should be used with typeof Entity.Type.
const Todo = defineEntity("Todo")
.props(z.object({
id: z.string(),
title: z.string(),
assigneeIds: z.array(z.string()).default([]),
}))
.methods((self) => ({
addAssignee(id: string) {
if (self.assigneeIds.includes(id)) return self;
return self.with({ assigneeIds: [...self.assigneeIds, id] });
},
}))
.build();
type Todo = typeof Todo.Type;
@beignet/core/domain
Domain modeling helpers for Beignet - value objects, entities, and domain events.
This package provides small, framework-agnostic helpers for domain modeling: