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/dto

v1.0.1

Published

> `@ddd-framework/dto` is a package within the comprehensive `@ddd-framework` framework. It provides a type alias for Data Transfer Objects (DTOs) to facilitate data-centric operations and object/class initializers.

Downloads

7

Readme

@ddd-framework/dto

@ddd-framework/dto is a package within the comprehensive @ddd-framework framework. It provides a type alias for Data Transfer Objects (DTOs) to facilitate data-centric operations and object/class initializers.

Description

The @ddd-framework/dto package extends the functionality of the @ddd-framework by offering a type alias, DataTransferObject<T>, that allows developers to deeply convert a generic type into an anemic type. This is particularly useful for working with Data Transfer Objects (DTOs) in a DDD context within Node.js applications.

Documentation

For more detailed information on @ddd-framework/dto, including usage examples and API reference, please refer to the official documentation.

Installation

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

  • Node.js stable version
  • pnpm

Once the prerequisites are installed, run the following command:

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

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

Type Alias

DataTransferObject<T>

The DataTransferObject<T> type alias allows for the deep conversion of a generic type into an anemic type. It excludes any methods and focuses on data-centric operations or object/class initializers. This type alias is particularly useful for working with Data Transfer Objects (DTOs).

type DataTransferObject<T> = T extends FunctionType
  ? never
  : Extract<T, undefined> extends never
  ? Serialize<T>
  : Serialize<T> | undefined;

By utilizing the DataTransferObject<T> type alias from the @ddd-framework/dto package, developers can effectively work with DTOs in a data-centric manner, simplifying object/class initialization and data operations.

Usage

To use @ddd-framework/dto, import the DataTransferObject type alias from the package. For example:

import { DataTransferObject } from '@ddd-framework/dto';

interface User {
  id: string;
  name: string;
  email: string;
}

// Usage example
const user: DataTransferObject<User> = {
  id: '123',
  name: 'John Doe',
  email: '[email protected]',
};

console.log(user); // Output: { id: '123', name: 'John Doe', email: '[email protected]' }
import { DataTransferObject } from '@ddd-framework/dto';

const money = new Money(10, new CurrencyDetails('USD', '$', 2, true));
const dto = serialize(money);
expect(dto.amount as number).toBeTruthy();
expect(dto.currency.currencyCode as string).toBeTruthy();
import { DataTransferObject } from '@ddd-framework/dto';

const order = new Order({
  id: new OrderId(faker.string.uuid()),
  status: 'PROCESSING',
  createdAt: DateValue.now(),
  updatedAt: DateValue.null
});

const dto = serialize(order);

order.id as DomainPrimitive<string>;
expect(dto.id as string).toBeTruthy();

order.status as string;
expect(dto.status as string).toBeTruthy();

order.createdAt as DateValue;
expect(dto.createdAt as string).toBeTruthy();

order.updatedAt as DateValue | undefined;
expect(dto.updatedAt as string | undefined).toBeTruthy();

By utilizing the DataTransferObject type alias from the @ddd-framework/dto package, developers can deeply convert a generic type into an anemic type, facilitating the use of DTOs in their Node.js applications.

License

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