Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@entity-factory/typeorm
Advanced tools
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.
npm install --save @entity-factory/core
Entity blueprints can also be defined within classes to enable better code separation.
import { EntityFactory, ObjectBlueprint } from '@entity-factory/core';
class UserBlueprint extends ObjectBlueprint {
constructor() {
super();
// Set the key used for identifying an object in the factory.
// The key can be a string or a class.
this.type('user');
this.define(async faker => {
return {
username: faker.internet.userName(),
email: faker.internet.email(),
active: false,
};
});
this.state('active', async faker => {
return {
active: true,
};
});
// called after make()
this.afterMaking(async (user, { faker, factory, adapter }) => {
// perform operation on entity
});
// called after make() on entity with a specific state transform
this.afterMakingState(
'active',
async (user, { faker, factory, adapter }) => {
// perform operation on entity
},
);
// called after create()
this.afterCreating(async (user, { faker, factory, adapter }) => {
// perform operation on entity
});
// called after create() on entity with a specific state transform
this.afterCreatingState(
'active',
async (user, { faker, factory, adapter }) => {
// perform operation on entity
},
);
}
}
export const entityFactory = new EntityFactory({
// blueprints can be an array of glob patterns, blueprint classes and/or blueprint instances
blueprints: [UserBlueprint],
});
// Generate entities
entityFactory
.for('user') // get builder instance for 'user'
.state('active')
.create(3) // generate 3 users with incrementing id's
.then(users => console.log(users));
// output:
// [
// { id: 1, username: 'Shawna_Muller77', email: 'Nelda55@hotmail.com', active: true },
// { id: 2, username: 'Abraham_Emard', email: 'Skye_Champlin@hotmail.com', active: true },
// { id: 3, username: 'Ena14', email: 'Suzanne.Hansen@yahoo.com', active: false }
// ]
import { EntityFactory, ObjectBlueprint } from 'entity-factory';
interface User {
id: number;
username: string;
email: string;
active: boolean;
}
export const entityFactory = new EntityFactory();
entityFactory.register((profile: ObjectBlueprint<User>) => {
// Set the key used for identifying an object in the factory.
// The key can be a string or a class.
profile.type('user');
profile.define(async faker => {
return {
username: faker.internet.userName(),
email: faker.internet.email(),
active: faker.random.boolean(),
};
});
});
// Generate entities
entityFactory
.for<User>('user') // get builder instance for 'user'
.create(3) // generate 3 users with incrementing id's
.then(users => console.log(users));
// output:
// [
// { id: 1, username: 'Mathias.Fay', email: 'Lisandro_Walker@yahoo.com', active: true },
// { id: 2, username: 'Ashlynn77', email: 'Edd_Jenkins@hotmail.com', active: false },
// { id: 3, username: 'Josefina99', email: 'Yesenia23@hotmail.com', active: true }
// ]
FAQs
TypeORM Adapter for entity-factory
The npm package @entity-factory/typeorm receives a total of 5 weekly downloads. As such, @entity-factory/typeorm popularity was classified as not popular.
We found that @entity-factory/typeorm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.