Creating a Factory
const entityFactory = new EntityFactory({
adapter: new OjectAdapter(),
blueprints: [
new UserBlueprint(), // blueprint instance
PostBlueprint, // blueprint reference
],
});Create a new entity factory instance. Opts is optional and can contain the following attributes.
opts.adapter (optional): default
new ObjectAdapter(). The adapter isused when making and creating objects. Available adapters
ObjectAdapter: Creates standard javascript objects with incrementing
id values.
TypeormAdapter: Makes and persists TypeORM entities.
opts.profiles (optional): default
[]. The profiles array accepts anarray of Profile instances or Profile classes.
Class Reference: Ex
UserProfile. If a class reference is passed Entity factory will create a new instance and register it.Profile Instance: Ex
new UserProfile(). If a profile instance isprovided EntityFactory will register it.
factory.register(profile | callback(profile))
Registers a profile with the factory
Arguments
profile: Must be a profile instance, or a callback method accepting a
profile instance.
Returns: void
factory.for(key)
Arguments
key (string|object reference): The is defined in the profile calling
type(key)in a blueprint and used to retrieve the profile from the factoryand supply it to the
ProfileBuilder.
Returns: BlueprintBuilder
factory.gen(count, callback)
Generates arbitrary objects on an as needed basis.
Last updated
Was this helpful?