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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ddd-framework/core

v1.0.8

Published

> `@ddd-framework/core` is a package within the comprehensive `@ddd-framework` framework. It provides essential functionalities and classes for implementing Domain-Driven Design (DDD) specifically for Node.js.

Downloads

4

Readme

@ddd-framework/core

@ddd-framework/core is a package within the comprehensive @ddd-framework framework. It provides essential functionalities and classes for implementing Domain-Driven Design (DDD) specifically for Node.js.

Introduction

The @ddd-framework/core package is a fundamental component of the @ddd-framework. It offers a range of features and tools that are crucial for incorporating DDD principles into Node.js applications. This package plays a significant role in streamlining the development process, improving code organization, and creating robust and maintainable applications based on DDD principles.

Documentation

For more detailed TypeDoc-generated documentation on @ddd-framework/core, please refer to the official documentation.

Installation

To install @ddd-framework/core, ensure you have the following prerequisites:

  • Node.js stable version
  • pnpm

Once the prerequisites are installed, run the following command:

$ pnpm i @ddd-framework/core
...

This will install the @ddd-framework/core package and its dependencies.

Features

The @ddd-framework/core package offers a set of features that align with the principles of Domain-Driven Design (DDD) to facilitate the development of Node.js applications:

  • Aggregates and Entities: Provides decorators and classes such as AggregateRoot and Entity to model and manage domain aggregates and entities. These classes encapsulate behavior, enforce business rules, and enable consistency within the domain model.
  • Domain Events: Offers the DomainEvent decorator to represent and handle domain events. Domain events are used to capture meaningful occurrences within the domain and allow decoupled communication between different parts of the application.
  • Value Objects: Includes the ValueObject class to define immutable value objects. Value objects encapsulate small, cohesive pieces of data with their own rules and behaviors, contributing to the integrity and expressiveness of the domain model.
  • Domain Primitives: Provides domain primitive classes such as DateValue that encapsulate specific domain concepts and ensure type safety and consistency within the domain model.
  • Repositories: Provides the Repository class, which serves as an abstraction to access and persist aggregates and entities in a domain-agnostic manner. Repositories enable a consistent and standardized way to retrieve and store domain objects.
  • Unit of Work: Offers the UnitOfWork and UnitOfWorkManager classes to implement the Unit of Work pattern. These classes provide a way to manage the transactional consistency and coordination of changes across multiple aggregates or entities within a single operation.
  • Exception Handling: Provides a range of exception classes, including ArgumentException, InvalidOperationException, and more, to handle exceptional situations and errors that can occur during domain operations.

By leveraging these features from the @ddd-framework/core package, developers can effectively implement DDD concepts such as aggregates, entities, domain events, and repositories in their Node.js applications, leading to more maintainable, expressive, and domain-focused code.

Usage

To use @ddd-framework/core, import the desired classes, interfaces, or functions from the package. For example:

import {
  AggregateId,
  AggregateRoot,
  Entity,
  EntityId,
  IllegalStateException
} from '@ddd-framework/core';
import { faker } from '@faker-js/faker';

@AggregateRoot()
export class GiftCard extends Entity {
  @AggregateId()
  public id: string;

  public remainingValue: number;

  public transactions: GiftCardTransaction[] = [];

  constructor(id: string, initialBalance: number) {
    super();
    this.id = id;
    this.remainingValue = initialBalance;
  }

  @Entity.Invariant()
  public handle(cmd: TransactCommand | ReimburseCardCommand) {
    if (cmd instanceof TransactCommand) {
      const transaction = new GiftCardTransaction(
        faker.string.uuid(),
        cmd.transactionValue
      );

      this.remainingValue -= transaction.transactionValue;

      this.transactions.push(transaction);

      this.raise(
        new TransactionEvent(
          this.id,
          transaction.transactionId,
          transaction.transactionValue
        )
      );
    } else if (cmd instanceof ReimburseCardCommand) {
      const transaction = this.transactions.find(
        (i) => i.transactionId === cmd.transactionId
      );

      if (transaction) {
        this.remainingValue += transaction.transactionValue;
        transaction.handle(cmd);
      }
    }
  }

  protected validateInvariants(): void {
    if (this.remainingValue < 0)
      throw new IllegalStateException('Gift card cannot be overdrawn');
  }
}

License

@ddd-framework/core is released under the MIT License. Feel free to customize it further to fit your needs.