npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vytches/ddd-contracts

v0.28.0

Published

Enterprise-grade contracts & fundamental types for Domain-Driven Design

Readme

@vytches/ddd-contracts

Foundation interfaces, types, and the Result<T,E> primitive for the entire VytchesDDD ecosystem.

npm version TypeScript License: MIT

Installation

pnpm add @vytches/ddd-contracts

What's included

  • Result<T,E> — explicit success/failure container used across all packages
  • EntityId — base identity implementation for domain entities
  • Event contractsIDomainEvent, IEventStore, IEventBus, and related interfaces
  • Capability systemCapability, CapabilityRegistry, and opt-in capability interfaces
  • Validation contractsISpecification, IValidator, IValidationError
  • Repository contractsIRepository, IUnitOfWork, and variants
  • Testing contractsITestHarness, ITestClock, ITestDataBuilder
  • Factory contractsIDomainFactory, IAsyncDomainFactory

Usage

import { Result, EntityId } from '@vytches/ddd-contracts';

// Result pattern for explicit error handling
function divide(a: number, b: number): Result<number> {
  if (b === 0) return Result.fail(new Error('Division by zero'));
  return Result.ok(a / b);
}

const result = divide(10, 2);
if (result.isSuccess) {
  console.log(result.value); // 5
}

// Entity identity
const id = EntityId.create<string>();
import type { IDomainEvent, IEventStore } from '@vytches/ddd-contracts';
import { createDomainEvent } from '@vytches/ddd-contracts';

// Create a domain event
const event = createDomainEvent({
  eventType: 'OrderCreated',
  aggregateId: 'order-123',
  aggregateVersion: 1,
  eventData: { customerId: 'c1' },
});

// Implement your own event store adapter
class MyEventStore implements IEventStore {
  async appendToStream(
    streamId: string,
    events: IDomainEvent[]
  ): Promise<void> {
    // your storage logic
  }
}

API Reference

Result

| Member | Description | | -------------------- | ------------------------------------- | | Result.ok(value) | Create a successful result | | Result.fail(error) | Create a failure result | | Result.empty() | Create a successful void result | | Result.try(fn) | Wrap a throwing function in a Result | | .isSuccess | true if success | | .isFailure | true if failure | | .value | The success value (throws if failure) | | .error | The error value (throws if success) |

Domain Identity

| Export | Kind | Description | | ---------------------------- | --------- | ------------------------------- | ------ | --------- | --------- | | EntityId | class | Base identity implementation | | IEntityId | interface | Entity identity contract | | IEntityIdFactory | interface | Factory for creating entity ids | | IEntityIdConstructorParams | interface | Constructor parameter shape | | IdType | type | 'text' | 'uuid' | 'integer' | 'bigint' |

Domain Events

| Export | Kind | Description | | ---------------------------------------- | -------------- | ------------------------------------------ | | IDomainEvent | interface | Base domain event contract | | IEventMetadata | interface | Metadata carried on every event | | IEventStore | interface | Append-only event storage port | | IEventStoreAdapter | interface | Lower-level storage adapter | | IEventStoreConfig | interface | Event store configuration | | IEventBus | interface | Publish/subscribe bus contract | | IEventDispatcher | interface | Synchronous event dispatch | | IEnhancedEventDispatcher | interface | Extended dispatcher with persistence | | IEventPersistenceHandler | interface | Handles persisting events | | IEventHandler | interface | Handles a specific event type | | IStoredEvent / IStoredDomainEvent | interface | Persisted event shapes | | IEventStream / IGlobalEventStream | interface | Stream read/write contracts | | IEventSerializer | interface | Event serialization port | | IEventUpcaster | interface | Schema migration for stored events | | IAdvancedEventStore | interface | Full event store with streams and metadata | | IEventProcessor | interface | Event processing contract | | IReadStreamOptions / IReadAllOptions | interface | Read operation options | | IStreamMetadata / IAppendResult | interface | Stream metadata and append result | | createDomainEvent | function | Factory for IDomainEvent instances | | isEventHandler | function | Type guard for event handler objects | | IEventBus (class) | abstract class | Re-exported for DI tokens | | IEventDispatcher (class) | abstract class | Re-exported for DI tokens | | IEnhancedEventDispatcher (class) | abstract class | Re-exported for DI tokens | | IEventPersistenceHandler (class) | abstract class | Re-exported for DI tokens |

Event Replay

| Export | Kind | Description | | --------------------------------------------------------------------- | --------- | ----------------------------- | | IEventReplay / IAdvancedEventReplay | interface | Replay session contracts | | IEventReplayFactory | interface | Creates replay sessions | | IReplayConfig / IReplayFilter | interface | Replay configuration | | IReplayProgress / IReplayResult | interface | Progress tracking and results | | IReplaySession | interface | Active replay session | | ReplayEventHandler / ReplayErrorHandler / ReplayProgressHandler | type | Replay callback types |

Capabilities

| Export | Kind | Description | | ------------------------------------------------------------ | --------- | ---------------------------------------- | | Capability | class | Base capability marker | | CapabilityRegistry | class | Manages capabilities on an aggregate | | createCapabilityRegistry | function | Factory for CapabilityRegistry | | IAggregateCapability | interface | Base capability contract | | IAuditCapability | interface | Audit trail capability | | ISnapshotCapability | interface | State snapshot capability | | IVersioningCapability | interface | Optimistic locking capability | | IEventSourcingCapability | interface | Event sourcing reconstruction capability | | IProjectionCapability | interface | Projection management capability | | ICircuitBreakerCapability | interface | Circuit breaker capability | | ICheckpointCapability | interface | Processing checkpoint capability | | IDeadLetterCapability | interface | Dead-letter queue capability | | CapabilityConstructor / CapabilityMap / CapabilityType | type | Capability type helpers |

Validation

| Export | Kind | Description | | ------------------------ | --------- | ----------------------------------- | | ISpecification<T> | interface | Synchronous specification contract | | IAsyncSpecification<T> | interface | Asynchronous specification contract | | IValidator<T> | interface | Validator contract | | IValidationError | interface | Single validation error | | IValidationErrors | interface | Collection of validation errors | | IValidationRule | interface | A single validation rule |

Repositories

| Export | Kind | Description | | ------------------------ | --------- | ---------------------------------------- | | IRepository<T> | interface | Core CRUD repository | | IWriteRepository<T> | interface | Write-only repository | | IQueryRepository<T> | interface | Read-only repository | | IExtendedRepository<T> | interface | Repository with pagination and filtering | | IBatchRepository<T> | interface | Batch operations | | ICQRSRepository<T> | interface | Separate read/write sides | | IRepositoryProvider | interface | Repository factory | | IUnitOfWork | interface | Transactional boundary | | IRepositoryEntity | interface | Entity shape required by repositories |

Aggregates

| Export | Kind | Description | | ------------------------ | --------- | ----------------------------------- | | IAggregateWithEvents | interface | Aggregate that tracks domain events | | IAggregateSnapshot | interface | Snapshot contract | | IDomainFactory<T> | interface | Synchronous aggregate factory | | IAsyncDomainFactory<T> | interface | Asynchronous aggregate factory |

Testing Contracts

| Export | Kind | Description | | ----------------------------------------------------------------- | --------- | -------------------------------- | | ITestHarness | interface | Test environment setup/teardown | | ITestClock | interface | Controllable time in tests | | ITestDataBuilder<T> | interface | Fluent test data construction | | ITestFixture | interface | Shared test state | | ITestScenario | interface | Named test scenario | | ISafeRunResult<T> | interface | Result shape from safe execution | | TestClockOptions / TestHarnessOptions / TestScenarioOptions | interface | Configuration types |

Event Bus Middleware

| Export | Kind | Description | | ---------------------- | --------- | ------------------------------------------ | | EventBusMiddleware | type | Middleware function for event buses | | EventMiddleware | type | Alias for event bus middleware | | BaseEventBusOptions | interface | Base options for event bus implementations | | EventHandlerFn | type | Event handler function signature | | EventHandlerMetadata | interface | Metadata attached to event handlers |

Package boundaries

@vytches/ddd-contracts has zero runtime dependencies. It is the leaf node of the dependency graph — every other package in the VytchesDDD ecosystem depends on it, directly or transitively. Do not import other @vytches/ddd-* packages from consumer code in this package.

License

MIT