ConstCreates a new unexported image entity with its domain event.
As the aggregate root, Image is the only entry point for creating and managing image entities. All image-related operations must go through this factory to ensure domain invariants are maintained.
Provides immutable entity creation following DDD patterns. All returned entities are frozen using Object.freeze(). Returns a tuple of [entity, event] for domain event dispatching.
// Create a new unexported image with its domain event
const [image, event] = imageEntity.create({
userId: makeUserId("user-123"),
path: makePath("image.jpg", true),
contentType: makeContentType("image/jpeg"),
fileSize: makeFileSize(1024),
caller: "addImage",
});
// Persist and dispatch event
await repository.create(image);
await eventDispatcher.dispatch(event);
ImagesDomainService for invariant validation (duplicate path check)
Factory object for Image domain entity operations.
This is the Aggregate Root for the Images bounded context.