# @entity-factory/core

> Create entities on the fly for mocking and testing

Latest version **0.2.2** (published 2021-10-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @entity-factory/core
pnpm add @entity-factory/core
yarn add @entity-factory/core
bun add @entity-factory/core
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2021-10-21 |
| First published | 2019-03-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 49 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Jeremy Cloutier |
| Maintainers | jcloutz |
| Keywords | test, testing, typeorm, fixtures, orm, typescript, faker, typeorm-fixtures |

## Links

- npm: https://www.npmjs.com/package/@entity-factory/core
- Repository: https://github.com/entity-factory/entity-factory
- Homepage: https://github.com/entity-factory/entity-factory#readme
- Issues: https://github.com/entity-factory/entity-factory/issues
- npm.io page: https://npm.io/package/@entity-factory/core

## Dependencies (2)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [faker](https://npm.io/package/faker.md) ^5.5.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2021-10-21
- 0.2.1 — 2019-06-20
- 0.2.0 — 2019-06-20
- 0.1.2 — 2019-03-15
- 0.1.1-alpha.1 — 2019-03-05
- 0.1.1-alpha.0 — 2019-03-01

## README

# Entity Factory

Entity Factory is a library used for quickly creating fixture data from plain
objects or classes using faker. Inspired by laravel's factories for generating
test data. Currently the library supports plain JS objects and Typeorm entities.

[Documentation](https://entity-factory.gitbook.io/entity-factory/)

## Table of Contents

-   [Features](#features)
-   [Installation](#installation)
-   [Quick Guide](#quick-guide)

## Features

-   Generate plain javascript objects on demand
-   Generate objects with nested relations
-   [Typeorm Support](https://github.com/entity-factory/entity-factory/tree/master/packages/typeorm) - Generate and Persist Entities and nested relations

## Installation

```
npm install --save @entity-factory/core
```

## Quick Guide

Try it on [Runkit](https://runkit.com/jcloutz/entity-factory-quick-example)

```javascript
const { EntityFactory, ObjectBlueprint } = require('@entity-factory/core');

class UserBlueprint extends ObjectBlueprint {
    constructor() {
        super();

        this.type('user');

        this.define(async ({ faker, factory }) => ({
            username: faker.internet.userName(),
            email: faker.internet.email(),
            active: faker.random.boolean(),
        }));

        // define a state transform to return a user with embedded posts
        this.state('with-posts', async ({ faker, factory }) => ({
            posts: await factory.for('post').create(2),
        }));
    }
}

class PostBlueprint extends ObjectBlueprint {
    constructor() {
        super();

        this.type('post');

        this.define(async ({ faker, factory }) => ({
            title: faker.company.bsBuzz(),
            body: faker.lorem.sentences(2),
        }));
    }
}

export const entityFactory = new EntityFactory({
    blueprints: [UserBlueprint, PostBlueprint],
});

// Generate entities
entityFactory
    .for('user') // get builder instance for 'user'
    .state('with-posts') // get users with posts
    .create(3) // generate 3 users with incrementing id's
    .then(users => console.log(users));
```

It is also possible to generate random data using the `gen` method available on
EntityFactory

```javascript
await entityFactory.gen(3, async ({ faker, factory }) => {
    return {
        name: faker.company.bsBuzz(),
        active: faker.random.boolean(),
    };
});
```

[Additional Samples](https://github.com/jcloutz/entity-factory/tree/master/samples)

## TODO

-   [ ] Add Mongoose adapter
-   [ ] Add Sequelize adapter
-   [x] improve docs
-   [x] resolve nested objects
-   [x] resolve nested array
-   [x] allow guid id's for object adapter
-   [x] add method to generate random objects on the fly without a blueprint
        definition

---
_Source: https://npm.io/package/@entity-factory/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
