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

object-seeder

v1.2.2

Published

Tiny utils for hassle free automatic object seeding

Readme

Object Seeder

Typescript utils for hassle free automatic object seeding. No more static mapping to maintain!

npm Build DeepScan grade

Object Seeder is a set of two utils aiming to make model seeding efficient and easy again using the power of Typescript. Your models will be used to determine where the data coming from the data source should be stored, without maintaining static mappings.

With Object Seeder, your models look like this:

import { AbstractModel, Property } from 'object-seeder';

export class User extends AbstractModel<User> {
    @Property()
    public id: number;

    @Property()
    public firstName: string;

    @Property()
    public lastName: string;

    @Property()
    public age: number;

    @Property(() => Role)
    public role: Role;
}

And no longer like this:

export class User {
    public id: number;

    public firstName: string;

    public lastName: string;

    public age: number;

    constructor(data: any) {
        if (!data) {
            return;
        }

        this.id = data.id;
        this.firstName = data.firstName;
        this.lastName = data.lastName;
        this.age = data.age;
        this.role = new Role(data.role);
    }
}

Installation

  1. Install the npm package

npm install object-seeder

  1. Install reflect-metadata shim

npm install reflect-metadata

  1. TypeScript configuration

Make sure you have the following settings enabled in your tsconfig.json

{
    "compilerOptions": {
        "target": "es6",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true
    }
}

Quick Start

This package only provide two things: the AbstractModel, and the decorator Property. When implementing it in your models you only need to extends the AbstractModel and decorates your properties with @Property().

import { AbstractModel, Property } from 'object-seeder';

export class User extends AbstractModel<User> {
    @Property()
    public id: number;

    @Property()
    public firstName: string;

    @Property()
    public lastName: string;

    @Property()
    public age: number;

    @Property(() => Role)
    public role: Role;
}

const user = new User({
    id: 1,
    firstName: 'foo',
    lastName: 'bar',
    age: 35,
    role: {
        id: 1,
        name: 'superadmin',
    },
});

Handling Arrays and Relationships between classes

When dealing with arrays and relationships, the preferred way is to provides a function that returns the relation class. While not mandatory, it helps the AbstractModel to seeds our models without adding non expected properties, which would otherwise be impossible due to language specifics. If not provided, the fallback will be a generic object, and as such, any property can be seeded in the model.

import { AbstractModel, Property } from 'object-seeder';

export class User extends AbstractModel<User> {
    @Property()
    public id: number;

    @Property(() => Role)
    public roles: Role[]; // An array of roles
}
import { AbstractModel, Property } from 'object-seeder';

export class User extends AbstractModel<User> {
    @Property()
    public id: number;

    @Property(() => Role)
    public role: Role;
}

Retrieving Class Metadata

Exposed properties can be retrieved using the method getMetadata(). This method return an array of metadata about the exposed properties such as the reflected type and the type that have been directly provided to the decorator.

import { AbstractModel, Property } from 'object-seeder';

export class User extends AbstractModel<User> {
    @Property(() => Role, {
        expose: true,
    })
    public role: Role;
}

const user = new User();

console.log(user.getMetadata()); // [ id: { reflectedType: undefined, providedType: Role } ]

Decorator Options

Those options can be provided to the @Property decorator to fine tune its behavior.

name

The name option is to be used when the name of the property in the data source (e.g. database) differ from the one you want to use in your model. Provided with the name of the property in the data source, it will automatically associate the data with its property in the model.

import { AbstractModel, Property } from 'object-seeder';

export class User extends AbstractModel<User> {
    @Property({
        name: 'uuid',
    })
    public id: number;
}

const user = new User({
    uuid: 1,
});

console.log(user.id); // 1

ignoreCast

If true, the reflected / provided type will not be used, and the value will be returned as received.

This is particularly useful when the data type is any because the reflected type in this case will be Object which is not always what we want.

By default, received values will always be cast.

import { AbstractModel, Property } from 'object-seeder';

export class User extends AbstractModel<User> {
    @Property({
        ignoreCast: true,
    })
    public id: any;
}

const user = new User({
    id: 'very-unique-id',
});

console.log(user.id); // 'very-unique-id'

expose

If true, property metadata will be returned by getMetadata method. By default, no property metadata are exposed.

import { AbstractModel, Property } from 'object-seeder';

export class User extends AbstractModel<User> {
    @Property({
        expose: true,
    })
    public id: string;
}

const user = new User();

console.log(user.getMetadata()); // [ id: { reflectedType: String, providedType: undefined } ]

TODO

  • [ ] Replace AbstractModel by another decorator
  • [ ] Add custom example (select options based on model properties)
  • [ ] Contributor guidelines
    • [ ] Branch naming rules
    • [ ] Commit naming rules
    • [ ] Code of conduct

Contributing

Interested in contributing features and fixes? All contributions are welcome :smiley:

Make sure to follow these step, or your contribution might be rejected.

  1. Fork it (https://github.com/yourname/yourproject/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. If your changes impact the public API, make sure to add more tests and run the old ones
  4. Commit your changes (git commit -am 'Add some fooBar')
  5. Push to the branch (git push origin feature/fooBar)
  6. Open a new Pull Request against develop following our contributor guidelines

License

This project is under the MIT License. See the LICENSE file for the full license text.