s-private API Documentation - v3.8.1
    Preparing search index...
    bookEntity: { create: (args: CreateBookArgs) => BookWithEvent } = ...

    Factory object for Book domain entity operations.

    This is the Aggregate Root for the Books bounded context.

    Type Declaration

    • create: (args: CreateBookArgs) => BookWithEvent

      Creates a new unexported book entity with its domain event.

      When validation of any field fails

      For unexpected errors during creation

    As the aggregate root, Book is the only entry point for creating and managing book entities. All book-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 book with its domain event
    const [book, event] = bookEntity.create({
    userId: makeUserId("user-123"),
    isbn: makeISBN("978-4-06-521234-5"),
    title: makeBookTitle("The Pragmatic Programmer"),
    caller: "addBook",
    });

    // Persist and dispatch event
    await repository.create(book);
    await eventDispatcher.dispatch(event);
    • CreateBookArgs for creation parameters
    • BookWithEvent for return type
    • BooksDomainService for invariant validation (duplicate ISBN check)