-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathtypes.ts
41 lines (34 loc) · 1.14 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as Faker from 'faker'
import { Connection, ObjectType } from 'typeorm'
import { EntityFactory } from './entity-factory'
/**
* FactoryFunction is the fucntion, which generate a new filled entity
*/
export type FactoryFunction<Entity, Context> = (faker: typeof Faker, context?: Context) => Entity
/**
* EntityProperty defines an object whose keys and values must be properties of the given Entity.
*/
export type EntityProperty<Entity> = { [Property in keyof Entity]?: Entity[Property] }
/**
* Factory gets the EntityFactory to the given Entity and pass the context along
*/
export type Factory = <Entity, Context>(
entity: ObjectType<Entity>,
) => (context?: Context) => EntityFactory<Entity, Context>
/**
* Seed are the class to create some data. Those seed are run by the cli.
*/
export interface Seeder {
run(factory: Factory, connection: Connection): Promise<void>
}
/**
* Constructor of the seed class
*/
export type SeederConstructor = new () => Seeder
/**
* Value of our EntityFactory state
*/
export interface EntityFactoryDefinition<Entity, Context> {
entity: ObjectType<Entity>
factory: FactoryFunction<Entity, Context>
}