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

@juneil/entityts

v2.0.0

Published

EntityTS - Typescript library for entities, create entities for validation

Readme

EntityTS

Introduction

The idea is to use the power of Typescript/Decorators to have an easy and practical entity library. Based on a transformer system, this library use Joi to transform the entities to Validation Schemas.

How to install

npm install --save @juneil/entityts

Usage


import { Entity, Type, Required } from '@juneil/entityts';

class User extends Entity {

    @Type(Entity.Type.Hex)
    @Length(10)
    @Required()
    id: string;

    @Type(String)
    name: string;

}

const user1 = new User({ id: '1DB6A7FF08' });
user1.isValid() // true

const user2 = new User();
user2.isValid() // false

Static methods

  • schema(ModeEnum | EntityOptions): Joi.Schema
    • Build and return the schema for a mode

Instance methods

  • schema(ModeEnum | EntityOptions): Joi.Schema
    • Build and return the schema for a mode
  • isValid(ModeEnum): boolean
    • Based on the schema, valid the instance

EntityOptions

strict?: boolean - Default: true - Used in the constructor of the entity to throw an error if validation failed mode?: ModeEnum - Default: ModeEnum.READ - Schema mode array?: boolean - Default: false - Build the schema as a list of the Entity unknown?: boolean - Default: true - Allow unknown keys in the payload

Decorators

Type

@Type(String | Number | Date | Object | Boolean | Buffer | TypeEnum | *Entity)

Specify the type of the property's value and will be the base of the Schema

*Entity: Allow you to have a property with the type of an Entity. Example:

class Entity2 extends Entity {
    @Required()
    @Type(String)
    id: string

}
class Entity1 extends Entity {
    @Type(String)
    id: string

    @Type(Entity2)
    sub: Entity2
}
new Entity1().isValid()                         // true
new Entity1({ sub: {} }).isValid()              // false
new Entity1({ sub: { id: 'abc' } }).isValid()   // true

Array

@Array(String | Number | Date | Object | Boolean | Buffer | TypeEnum | *Entity)

Same as @Type() but with array.

ObjectPattern

@ObjectPattern(RegExp, String | Number | Date | Object | Boolean | Buffer | TypeEnum | *Entity)

Allow to define the key's pattern and the value's type of an object

Required

@Required(...ModeEnum) // By default: Entity.Mode.READ

Set the property as required, can be setted for several modes

Strip

@Strip(...ModeEnum) // By default: Entity.Mode.READ

The property will be removed depending of the modes provided

Valid

@Valid(...any)

Set the valid values for the property

Invalid

@Invalid(...any)

Set the invalid values for the property

Allow

@Allow(...any)

Set the allowed values for the property

Min

@Min(number)

Add Min validation for the property's value. Works with types: String | Number | Array | Buffer | TypeEnum

Max

@Max(number)

Add Max validation for the property's value. Works with types: String | Number | Array | Buffer | TypeEnum

Length

@Length(number)

Add Length validation for the property's value. Works with types: String | Array | Buffer | TypeEnum

Description

@Description(string)

Regex

@Regex(pattern)

Add regex validation for a string Works with type: String

TypeEnum

  • Entity.Type.Any: any
  • Entity.Type.ObjectId: String ObjectId from mongodb
  • Entity.Type.Hex: String in hexadecimal format
  • Entity.Type.Base64: String in base64 format
  • Entity.Type.IsoDate: String in iso date format
  • Entity.Type.URI: String URI format
  • Entity.Type.Email: String Email format
  • Entity.Type.Timestamp: Date timestamp format

ModeEnum

  • Entity.Mode.READ: Default mode
  • Entity.Mode.CREATE: Mode to use while creating in a datasource
  • Entity.Mode.UPDATE: Mode to use while updating in a datasource

More

You can extend the schema with `more()' static methods

class Entity1 extends Entity {
    @Type(String)
    id: string

    // Make id required
    static more() {
        return Joi.object({
            id: Joi.any.required()
        });
    }
}

Extends an other entity

You can directly extend an entity

class Entity1 extends Entity {
    @Type(String)
    id: string
}

class Entity2 extends EntityExtends(Entity1) {
    @Type(Number)
    id: number

    @Type(Boolean)
    flag: boolean
}