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

immutable-entity-manager

v1.0.0

Published

This initiative enables developers to leverage entities in Node.js projects, whether on the client side or in any other Node.js environment.

Downloads

3

Readme

Alt npm version

Immutable entites manager

This initiative enables developers to leverage entities in Node.js projects, whether on the client side or in any other Node.js environment.

🔨 Installation

npm install immutable-entity-manager
yarn add immutable-entity-manager

🗒️ Usage/Examples

This package is built on the foundation of the manager and builder patterns. Each immutable entity has its own dedicated manager, designed to assist in data parsing. The manager, in turn, yields a builder class responsible for handling various tasks such as processing decorators, applying properties, and more.

This package uses Typescript under-the-hood which means that it generates return type, properties name, etc.

@ImmutableEntity()
class Person {
  readonly firstName!: string
  readonly lastName!: string
  @ImmutableEntityTyped(Date) readonly birthDate!: Date
}

const person = ImmutableEntityManager
    .getUniqueManager(Person)
    .parseFromJson({
        first_name: 'hello',
        last_name: 'world',
        birth_date: '2023-12-15T11:01:22.041Z'
    })
    .build()

expect(person.firstName).toBe('hello')
expect(person.lastName).toBe('world')
expect(person.birthDate).toBeInstanceOf(Date)

📑 API Reference

Decorators

  • @ImmutableEntity – mark a class as immutable entity;
  • @ImmutableEntityTransient – mark a class property as transient. It means that property won't be handled by manager and builder, also value won't be set;
  • @ImmutableEntityDefaultValue(0) – sets the default value for property if JSON data don't have value;
  • @ImmutableEntityTyped(Date) – mark a property as typed. Argument could be any class or other one immutable entity. In this case, it will apply immutable entity rules for this property otherwise it will create a new class with value as argument;

Manager

Manager represents the parser of entity.

ImmutableEntityManager
    .getUniqueManager(Person)
    .parseFromJson({
        ...
    })

Builder

Builder represents the standard entity builder pattern. Builder is exported and could be created directly but the best way is using of the manager parsing result object.

const builder = ImmutableEntityManager
    .getUniqueManager(Person)
    .parseFromJson({
        ...
    })

Property setting

Builder allows to set the values for properties. It will override data given by manager in a parsing stage.

  • Arguments: propertyName: string, value: any, applyDecorators: boolean. Apply decorators allow to set: should the builder apply this package decorators before setting the value.
builder
    .withProperty('someProperty', someValue)
    .withProperty('someAnotherProperty', someAnotherValue)

Options setting

Builder allow to choose conversion of properties: camel to snake or viceversa. snakeToCamelCase is default.

builder.withOptions({ camelToSnakeCase: true })

🙌 Roadmap

  • Add transformation of property before parsing or in withProperty;

  • Allow to developers set custom constructor for entity which couldn't be initialized with @ImmutableEntityTyped decorator;

  • Add entity cloning;

  • Add React helper hooks for managing entities reactively;

  • Add different parser sources like Buffer, string etc.;

  • Add global singleton managers for each entity;

  • Allow to build entities w/o case conversion or with custom conversion function;

License

MIT

Alt