@jorgebodega/typeorm-seeding 4.0.0-next.2 → 5.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/.commitlintrc +5 -0
  2. package/CHANGELOG.md +43 -0
  3. package/README.md +184 -88
  4. package/dist/cli.js +2 -4
  5. package/dist/cli.js.map +1 -1
  6. package/dist/commands/seed.command.d.ts +8 -11
  7. package/dist/commands/seed.command.js +102 -61
  8. package/dist/commands/seed.command.js.map +1 -1
  9. package/dist/datasource/DataSourceManager.d.ts +8 -0
  10. package/dist/datasource/DataSourceManager.js +23 -0
  11. package/dist/datasource/DataSourceManager.js.map +1 -0
  12. package/dist/datasource/configureDataSource.d.ts +2 -0
  13. package/dist/datasource/configureDataSource.js +9 -0
  14. package/dist/datasource/configureDataSource.js.map +1 -0
  15. package/dist/datasource/fetchDataSource.d.ts +1 -0
  16. package/dist/datasource/fetchDataSource.js +9 -0
  17. package/dist/datasource/fetchDataSource.js.map +1 -0
  18. package/dist/datasource/index.d.ts +2 -0
  19. package/dist/datasource/index.js +6 -0
  20. package/dist/datasource/index.js.map +1 -0
  21. package/dist/errors/DataSourceNotProvidedError.d.ts +3 -0
  22. package/dist/errors/DataSourceNotProvidedError.js +10 -0
  23. package/dist/errors/DataSourceNotProvidedError.js.map +1 -0
  24. package/dist/errors/index.d.ts +2 -0
  25. package/dist/errors/index.js +6 -0
  26. package/dist/errors/index.js.map +1 -0
  27. package/dist/factory.d.ts +1 -1
  28. package/dist/factory.js +4 -4
  29. package/dist/factory.js.map +1 -1
  30. package/dist/helpers/index.d.ts +2 -0
  31. package/dist/helpers/index.js +6 -0
  32. package/dist/helpers/index.js.map +1 -0
  33. package/dist/helpers/useDataSource.d.ts +5 -0
  34. package/dist/helpers/useDataSource.js +19 -0
  35. package/dist/helpers/useDataSource.js.map +1 -0
  36. package/dist/helpers/useSeeders.d.ts +3 -0
  37. package/dist/helpers/useSeeders.js +13 -0
  38. package/dist/helpers/useSeeders.js.map +1 -0
  39. package/dist/index.d.ts +2 -3
  40. package/dist/index.js +8 -9
  41. package/dist/index.js.map +1 -1
  42. package/dist/seeder.d.ts +2 -4
  43. package/dist/seeder.js +0 -5
  44. package/dist/seeder.js.map +1 -1
  45. package/dist/types.d.ts +0 -10
  46. package/dist/utils/fileHandling.d.ts +1 -1
  47. package/dist/utils/fileHandling.js +4 -4
  48. package/dist/utils/fileHandling.js.map +1 -1
  49. package/package.json +21 -26
  50. package/dist/commands/config.command.d.ts +0 -25
  51. package/dist/commands/config.command.js +0 -55
  52. package/dist/commands/config.command.js.map +0 -1
  53. package/dist/connection/ConnectionConfigurationManager.d.ts +0 -9
  54. package/dist/connection/ConnectionConfigurationManager.js +0 -24
  55. package/dist/connection/ConnectionConfigurationManager.js.map +0 -1
  56. package/dist/connection/configureConnection.d.ts +0 -2
  57. package/dist/connection/configureConnection.js +0 -9
  58. package/dist/connection/configureConnection.js.map +0 -1
  59. package/dist/connection/fetchConnection.d.ts +0 -2
  60. package/dist/connection/fetchConnection.js +0 -22
  61. package/dist/connection/fetchConnection.js.map +0 -1
  62. package/dist/connection/getConnectionOptions.d.ts +0 -2
  63. package/dist/connection/getConnectionOptions.js +0 -27
  64. package/dist/connection/getConnectionOptions.js.map +0 -1
  65. package/dist/connection/index.d.ts +0 -3
  66. package/dist/connection/index.js +0 -7
  67. package/dist/connection/index.js.map +0 -1
  68. package/dist/errors/DefaultSeederNotDefinedError.d.ts +0 -3
  69. package/dist/errors/DefaultSeederNotDefinedError.js +0 -10
  70. package/dist/errors/DefaultSeederNotDefinedError.js.map +0 -1
  71. package/dist/useSeeders.d.ts +0 -4
  72. package/dist/useSeeders.js +0 -15
  73. package/dist/useSeeders.js.map +0 -1
package/.commitlintrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": [
3
+ "@commitlint/config-conventional"
4
+ ]
5
+ }
package/CHANGELOG.md CHANGED
@@ -1,3 +1,46 @@
1
+ # [5.0.0-next.1](https://github.com/jorgebodega/typeorm-seeding/compare/v4.0.0...v5.0.0-next.1) (2022-07-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update dependency glob to v8 ([2d3c996](https://github.com/jorgebodega/typeorm-seeding/commit/2d3c99635fcfdd667b38a4bed60d663145dd619b))
7
+
8
+
9
+ ### Features
10
+
11
+ * removed unused command and add some more tests ([ea6649e](https://github.com/jorgebodega/typeorm-seeding/commit/ea6649e98261d62907118448b047987cbebcd2c7))
12
+ * use typeorm 0.3 ([aa0153b](https://github.com/jorgebodega/typeorm-seeding/commit/aa0153bd050c60ab94f9979eff4e5ab9bec81645))
13
+
14
+
15
+ ### BREAKING CHANGES
16
+
17
+ * Removed config command
18
+ * Connection API is deprecated and removed.
19
+
20
+ # [4.0.0](https://github.com/jorgebodega/typeorm-seeding/compare/v3.2.0...v4.0.0) (2022-03-23)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * add type check on subfactories creation ([2b2883b](https://github.com/jorgebodega/typeorm-seeding/commit/2b2883b48ea08173a032b219266b1fece937e753))
26
+ * attrs failing with lazy instances ([c8ddda8](https://github.com/jorgebodega/typeorm-seeding/commit/c8ddda841f9e65d7081e419d2d2e662c6d6a78df))
27
+ * update dependency yargs to v17.4.0 ([b64c224](https://github.com/jorgebodega/typeorm-seeding/commit/b64c2245ebb086d891c503972f74cdcca0e2ddab))
28
+
29
+
30
+ ### Features
31
+
32
+ * add factorized attrs ([4a2ce08](https://github.com/jorgebodega/typeorm-seeding/commit/4a2ce08e1be1d79df8f1c0450ba4b315ebca8c46))
33
+ * add lazyattribute and subfactory as options in attribs ([48a3630](https://github.com/jorgebodega/typeorm-seeding/commit/48a3630b8c606ff5189c05dc51908dc09f142184))
34
+ * add subfactory as valid factorized attr ([0f4b37e](https://github.com/jorgebodega/typeorm-seeding/commit/0f4b37e0f8c3e93aedbd109ddb8f33ac0127a2dc))
35
+ * separate different types of lazy attributes ([3efe94e](https://github.com/jorgebodega/typeorm-seeding/commit/3efe94ea140643ccb12dbf8858968a5866fd7577))
36
+
37
+
38
+ ### BREAKING CHANGES
39
+
40
+ * definition function has been substituted with attrs
41
+
42
+ # [4.0.0-next.3](https://github.com/jorgebodega/typeorm-seeding/compare/v4.0.0-next.2...v4.0.0-next.3) (2022-03-03)
43
+
1
44
  # [4.0.0-next.2](https://github.com/jorgebodega/typeorm-seeding/compare/v4.0.0-next.1...v4.0.0-next.2) (2022-02-12)
2
45
 
3
46
  # [4.0.0-next.1](https://github.com/jorgebodega/typeorm-seeding/compare/v3.2.0...v4.0.0-next.1) (2022-02-12)
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  </a>
14
14
  <a href="https://github.com/semantic-release/semantic-release">
15
15
  <img src="https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release&style=for-the-badge" alt="Semantic release" />
16
- </a>
16
+ </a>
17
17
  </p>
18
18
 
19
19
  <p align="center">
@@ -43,14 +43,27 @@
43
43
 
44
44
  <br />
45
45
 
46
- ## Additional contents
46
+ # Contents
47
47
 
48
48
  - [Factory](#factory-1)
49
+ - [attrs](#attrs)
50
+ - [Simple value](#simple-value)
51
+ - [Function](#function)
52
+ - [InstanceAttribute](#instanceattribute)
53
+ - [LazyInstanceAttribute](#lazyinstanceattribute)
54
+ - [Subfactory](#subfactory)
55
+ - [make & makeMany](#make--makemany)
56
+ - [create & createMany](#create--createmany)
57
+ - [faker](#faker)
49
58
  - [Seeder](#seeder-1)
59
+ - [run](#run)
60
+ - [call](#call)
50
61
  - [CLI](#cli-configuration)
62
+ - [config](#config)
63
+ - [seed](#seed)
51
64
  - [Testing features](#testing-features)
52
65
 
53
- ## Installation
66
+ # Installation
54
67
 
55
68
  Before using this TypeORM extension please read the [TypeORM Getting Started](https://typeorm.io/#/) documentation. This explains how to setup a TypeORM project.
56
69
 
@@ -61,9 +74,9 @@ npm i [-D] @jorgebodega/typeorm-seeding
61
74
  yarn add [-D] @jorgebodega/typeorm-seeding
62
75
  ```
63
76
 
64
- ### Configuration
77
+ ## Configuration
65
78
 
66
- To configure the path to your seeders change the TypeORM config file or use environment variables like TypeORM. If both are used the environment variables will be prioritized.
79
+ To configure the path to your seeders extends the TypeORM config file or use environment variables like TypeORM. If both are used the environment variables will be prioritized.
67
80
 
68
81
  **ormconfig.js**
69
82
 
@@ -83,7 +96,7 @@ TYPEORM_SEEDING_SEEDERS=src/seeds/**/*{.ts,.js}
83
96
  TYPEORM_SEEDING_DEFAULT_SEEDER=RootSeeder
84
97
  ```
85
98
 
86
- ## Introduction
99
+ # Introduction
87
100
 
88
101
  Isn't it exhausting to create some sample data for your database, well this time is over!
89
102
 
@@ -94,11 +107,24 @@ How does it work? Just create a entity factory and/or seed script.
94
107
  ```typescript
95
108
  @Entity()
96
109
  class User {
97
- @PrimaryGeneratedColumn('uuid') id: string
110
+ @PrimaryGeneratedColumn('increment')
111
+ id!: number
112
+
113
+ @Column()
114
+ name!: string
115
+
116
+ @Column()
117
+ lastName!: string
98
118
 
99
- @Column() name: string
119
+ @Column()
120
+ email!: string
100
121
 
101
- @Column() lastname: string
122
+ @OneToMany(() => Pet, (pet) => pet.owner)
123
+ pets?: Pet[]
124
+
125
+ @ManyToOne(() => Country, (country) => country.users, { nullable: false })
126
+ @JoinColumn()
127
+ country!: Country
102
128
  }
103
129
  ```
104
130
 
@@ -106,13 +132,14 @@ class User {
106
132
 
107
133
  ```typescript
108
134
  class UserFactory extends Factory<User> {
109
- protected definition(): User {
110
- const user = new User()
111
-
112
- user.name = 'John'
113
- user.lastname = 'Doe'
114
-
115
- return user
135
+ protected entity = User
136
+ protected attrs: FactorizedAttrs<User> = {
137
+ name: faker.name.firstName(),
138
+ lastName: async () => faker.name.lastName(),
139
+ email: new InstanceAttribute((instance) =>
140
+ [instance.name.toLowerCase(), instance.lastName.toLowerCase(), '@email.com'].join(''),
141
+ ),
142
+ country: new Subfactory(CountryFactory),
116
143
  }
117
144
  }
118
145
  ```
@@ -120,67 +147,164 @@ class UserFactory extends Factory<User> {
120
147
  ### Seeder
121
148
 
122
149
  ```typescript
123
- export class UserExampleSeeder extends Seeder {
124
- async run() {
125
- await new UserFactory().create({
126
- name: 'Jane',
127
- })
150
+ class UserSeeder extends Seeder {
151
+ async run(connection: Connection) {
152
+ await new UserFactory().createMany(10)
153
+
154
+ await this.call(connection, [PetSeeder])
128
155
  }
129
156
  }
130
157
  ```
131
158
 
132
- ## Factory
159
+ # Factory
133
160
 
134
161
  Factory is how we provide a way to simplify entities creation, implementing a [factory creational pattern](https://refactoring.guru/design-patterns/factory-method). It is defined as an abstract class with generic typing, so you have to extend over it.
135
162
 
136
163
  ```typescript
137
164
  class UserFactory extends Factory<User> {
138
- protected definition(): User {
165
+ protected entity = User
166
+ protected attrs: FactorizedAttrs<User> = {
139
167
  ...
140
168
  }
141
169
  }
142
170
  ```
143
171
 
144
- ### `definition`
172
+ ## `attrs`
173
+
174
+ Attributes objects are superset from the original entity attributes.
175
+
176
+ ```typescript
177
+ protected attrs: FactorizedAttrs<User> = {
178
+ name: faker.name.firstName(),
179
+ lastName: async () => faker.name.lastName(),
180
+ email: new InstanceAttribute((instance) =>
181
+ [instance.name.toLowerCase(), instance.lastName.toLowerCase(), '@email.com'].join(''),
182
+ ),
183
+ country: new Subfactory(CountryFactory),
184
+ }
185
+ ```
186
+
187
+ Those factorized attributes resolves to the value of the original attribute, and could be one of the following types:
188
+
189
+ - [Simple value](#simple-value)
190
+ - [Function](#function)
191
+ - [InstanceAttribute](#instanceattribute)
192
+ - [LazyInstanceAttribute](#lazyinstanceattribute)
193
+ - [Subfactory](#subfactory)
194
+
195
+ ### Simple value
196
+
197
+ Nothing special, just a value with same type.
198
+
199
+ ```typescript
200
+ protected attrs: FactorizedAttrs<User> = {
201
+ name: faker.name.firstName(),
202
+ }
203
+ ```
204
+
205
+ ### Function
206
+
207
+ Function that could be sync or async, and return a value of the same type. This function will be executed once per entity.
208
+
209
+ ```typescript
210
+ protected attrs: FactorizedAttrs<User> = {
211
+ lastName: async () => faker.name.lastName(),
212
+ }
213
+ ```
214
+
215
+ ### `InstanceAttribute`
216
+
217
+ ```typescript
218
+ class InstanceAttribute<T, V> {
219
+ constructor(private callback: (entity: T) => V) {}
220
+
221
+ ...
222
+ }
223
+ ```
224
+
225
+ Class with a function that receive the current instance and returns a value of the same type. It is ideal for attributes that could depend on some others to be computed.
145
226
 
146
- This function is the one that needs to be defined when extending the class. It is called to instantiate the entity and the result will be used on the rest of factory lifecycle.
227
+ Will be executed after the entity has been created and the rest of the attributes have been calculated, but before persistance (in case of `create` or `createMany`).
147
228
 
148
229
  ```typescript
149
- protected definition(): User {
150
- const user = new User()
230
+ protected attrs: FactorizedAttrs<User> = {
231
+ name: faker.name.firstName(),
232
+ lastName: async () => faker.name.lastName(),
233
+ email: new InstanceAttribute((instance) =>
234
+ [instance.name.toLowerCase(), instance.lastName.toLowerCase(), '@email.com'].join(''),
235
+ ),
236
+ }
237
+ ```
238
+
239
+ In this simple case, if `name` or `lastName` override the value in any way, the `email` attribute will be affected too.
240
+
241
+ ### `LazyInstanceAttribute`
151
242
 
152
- user.name = 'John'
153
- user.lastname = 'Doe'
243
+ ```typescript
244
+ class LazyInstanceAttribute<T, V> {
245
+ constructor(private callback: (entity: T) => V) {}
154
246
 
155
- return user
247
+ ...
156
248
  }
157
249
  ```
158
250
 
159
- It is possible to create more than one factory related to a single entity, with different definition functions.
251
+ Class with similar functionality than `InstanceAttribute`, but it will be executed only after persistance. This is useful for attributes that depends on the database id, like relations.
160
252
 
161
- ### `map`
253
+ Just remember that, if you use `make` or `makeMany`, the only difference between `InstanceAttribute` and `LazyInstanceAttribute` is that `LazyInstanceAttribute` will be processed the last.
162
254
 
163
- Use the `.map()` function to alter the generated value before they get processed.
255
+ ```typescript
256
+ protected attrs: FactorizedAttrs<User> = {
257
+ name: faker.name.firstName(),
258
+ email: new LazyInstanceAttribute((instance) =>
259
+ [instance.name.toLowerCase(), instance.id, '@email.com'].join(''),
260
+ ),
261
+ }
262
+ ```
263
+
264
+ ### `Subfactory`
164
265
 
165
266
  ```typescript
166
- map(mapFunction: (entity: Entity) => void): Factory
267
+ export class Subfactory<T> {
268
+ constructor(factory: Constructable<Factory<T>>)
269
+ constructor(factory: Constructable<Factory<T>>, values?: Partial<FactorizedAttrs<T>>)
270
+ constructor(factory: Constructable<Factory<T>>, count?: number)
271
+ constructor(factory: Constructable<Factory<T>>, values?: Partial<FactorizedAttrs<T>>, count?: number)
272
+
273
+ ...
274
+ }
167
275
  ```
168
276
 
277
+ Subfactories are just a wrapper of another factory, to avoid explicit operations that could lead to unexpected results over that factory, like
278
+
169
279
  ```typescript
170
- new UserFactory().map((user) => {
171
- user.name = 'Jane'
172
- })
280
+ protected attrs: FactorizedAttrs<User> = {
281
+ country: async () => new CountryFactory().create({
282
+ name: faker.address.country(),
283
+ }),
284
+ }
173
285
  ```
174
286
 
175
- ### `make` & `makeMany`
287
+ instead of
288
+
289
+ ```typescript
290
+ protected attrs: FactorizedAttrs<User> = {
291
+ country: new Subfactory(CountryFactory, {
292
+ name: faker.address.country(),
293
+ }),
294
+ }
295
+ ```
296
+
297
+ Subfactory just execute the same kind of operation (`make` or `create`) over the factory. If `count` param is provided, it will execute `makeMany`/`createMany` instead of `make`/`create`, and returns an array.
298
+
299
+ ## `make` & `makeMany`
176
300
 
177
301
  Make and makeMany executes the factory functions and return a new instance of the given entity. The instance is filled with the generated values from the factory function, but not saved in the database.
178
302
 
179
303
  - **overrideParams** - Override some of the attributes of the entity.
180
304
 
181
305
  ```typescript
182
- make(overrideParams: Partial<Entity> = {}): Promise<Entity>
183
- makeMany(amount: number, overrideParams: Partial<Entity> = {}): Promise<Entity>
306
+ make(overrideParams: Partial<FactorizedAttrs<T>> = {}): Promise<T>
307
+ makeMany(amount: number, overrideParams: Partial<FactorizedAttrs<T>> = {}): Promise<T[]>
184
308
  ```
185
309
 
186
310
  ```typescript
@@ -192,7 +316,7 @@ new UserFactory().make({ email: 'other@mail.com' })
192
316
  new UserFactory().makeMany(10, { email: 'other@mail.com' })
193
317
  ```
194
318
 
195
- ### `create` & `createMany`
319
+ ## `create` & `createMany`
196
320
 
197
321
  the create and createMany method is similar to the make and makeMany method, but at the end the created entity instance gets persisted in the database using TypeORM entity manager.
198
322
 
@@ -200,8 +324,8 @@ the create and createMany method is similar to the make and makeMany method, but
200
324
  - **saveOptions** - [Save options](https://github.com/typeorm/typeorm/blob/master/src/repository/SaveOptions.ts) from TypeORM
201
325
 
202
326
  ```typescript
203
- create(overrideParams: Partial<Entity> = {}, saveOptions?: SaveOptions): Promise<Entity>
204
- createMany(amount: number, overrideParams: Partial<Entity> = {}, saveOptions?: SaveOptions): Promise<Entity>
327
+ create(overrideParams: Partial<FactorizedAttrs<T>> = {}, saveOptions?: SaveOptions): Promise<T>
328
+ createMany(amount: number, overrideParams: Partial<FactorizedAttrs<T>> = {}, saveOptions?: SaveOptions): Promise<T[]>
205
329
  ```
206
330
 
207
331
  ```typescript
@@ -217,50 +341,24 @@ new UserFactory().create({ email: 'other@mail.com' }, { listeners: false })
217
341
  new UserFactory().createMany(10, { email: 'other@mail.com' }, { listeners: false })
218
342
  ```
219
343
 
220
- ### Execution order
221
-
222
- As the order of execution can be complex, you can check it here:
223
-
224
- 2. **Map function**: Map function alters the already existing entity.
225
- 3. **Override params**: Alters the already existing entity.
226
- 4. **Promises**: If some attribute is a promise, the promise will be resolved before the entity is created.
227
- 5. **Factories**: If some attribute is a factory, the factory will be executed with `make`/`create` like the previous one.
344
+ ## faker
228
345
 
229
- ### Faker
230
-
231
- [Faker](https://github.com/marak/Faker.js/) package was previously a dependency of the project, but now it is optional due to its size. If you want to use faker, you may need to install it and import it.
232
-
233
- Instead of the previous example:
234
-
235
- ```typescript
236
- define(User, (faker: typeof Faker) => {
237
- const firstName = faker.name.firstName()
238
- const lastName = faker.name.lastName()
346
+ [Faker](https://github.com/faker-js/faker) package has been removed from `dependencies`. If you want to use it, please install it manually and just import when needed.
239
347
 
240
- const user = new User()
241
- user.name = `${firstName} ${lastName}`
242
- return user
243
- })
348
+ ```bash
349
+ npm i [-D] @faker-js/faker
350
+ yarn add [-D] @faker-js/faker
244
351
  ```
245
352
 
246
- You can do:
247
-
248
353
  ```typescript
249
- import faker from '@faker-js/faker'
354
+ import { faker } from '@faker-js/faker'
250
355
 
251
356
  class UserFactory extends Factory<User> {
252
- protected definition(): User {
253
- const user = new User()
254
-
255
- user.name = faker.name.firstName()
256
- user.lastname = faker.name.lastName()
257
-
258
- return user
259
- }
357
+ ...
260
358
  }
261
359
  ```
262
360
 
263
- ## Seeder
361
+ # Seeder
264
362
 
265
363
  Seeder class is how we provide a way to insert data into databases, and could be executed by the command line or by helper method. Is an abstract class with one method to be implemented, and a helper function to run some more seeder sequentially.
266
364
 
@@ -272,7 +370,7 @@ class UserSeeder extends Seeder {
272
370
  }
273
371
  ```
274
372
 
275
- ### `run`
373
+ ## `run`
276
374
 
277
375
  This function is the one that needs to be defined when extending the class. Could use `call` to run some other seeders.
278
376
 
@@ -288,7 +386,7 @@ async run(connection: Connection) {
288
386
  }
289
387
  ```
290
388
 
291
- ### `call`
389
+ ## `call`
292
390
 
293
391
  This function allow to run some other seeders in a sequential way.
294
392
 
@@ -298,7 +396,7 @@ In order to use seeders from cli command, a default seeder class must be provide
298
396
  <img src="./seeders.png" alt="logo" />
299
397
  </p>
300
398
 
301
- ## CLI Configuration
399
+ # CLI Configuration
302
400
 
303
401
  There are two possible commands to execute, one to see the current configuration and one to run a seeder.
304
402
 
@@ -312,7 +410,7 @@ Add the following scripts to your `package.json` file to configure them.
312
410
  }
313
411
  ```
314
412
 
315
- ### `config`
413
+ ## `config`
316
414
 
317
415
  This command just print the connection configuration.
318
416
 
@@ -342,7 +440,7 @@ Example result
342
440
  | `--configName` or `-n` | TypeORM default value | Name to the TypeORM config file. |
343
441
  | `--root` or `-r` | TypeORM default value | Path to the TypeORM config file. |
344
442
 
345
- ### `seed`
443
+ ## `seed`
346
444
 
347
445
  This command execute a seeder, that could be specified as a parameter.
348
446
 
@@ -350,6 +448,8 @@ This command execute a seeder, that could be specified as a parameter.
350
448
  typeorm-seeding seed
351
449
  ```
352
450
 
451
+ The name of the seeder to execute (either set with the `--seed` option or with default in [configs](#configuration)) must be the seeder's class name, and thus, the seeder must be exported with a named export. Please avoid default export for seeders: it may imply unwanted behavior. (See [\#75](https://github.com/jorgebodega/typeorm-seeding/issues/75)).
452
+
353
453
  ##### Options
354
454
 
355
455
  | Option | Default | Description |
@@ -359,12 +459,12 @@ typeorm-seeding seed
359
459
  | `--configName` or `-n` | TypeORM default value | Name to the TypeORM config file. |
360
460
  | `--root` or `-r` | TypeORM default value | Path to the TypeORM config file. |
361
461
 
362
- ## Testing features
462
+ # Testing features
363
463
 
364
464
  We provide some testing features that we already use to test this package, like connection configuration.
365
465
  The entity factories can also be used in testing. To do so call the `useFactories` or `useSeeders` function.
366
466
 
367
- ### `useSeeders`
467
+ ## `useSeeders`
368
468
 
369
469
  Execute one or more seeders.
370
470
 
@@ -375,7 +475,3 @@ useSeeders(
375
475
  customOptions: Partial<ConnectionConfiguration>,
376
476
  ): Promise<void>
377
477
  ```
378
-
379
- ### Factories
380
-
381
- If factories are being used to create entities, just remember to clean up fake data after every execution.
package/dist/cli.js CHANGED
@@ -4,12 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
5
  /* istanbul ignore file */
6
6
  require("reflect-metadata");
7
- const yargs = (0, tslib_1.__importStar)(require("yargs"));
7
+ const yargs_1 = tslib_1.__importDefault(require("yargs"));
8
8
  const seed_command_1 = require("./commands/seed.command");
9
- const config_command_1 = require("./commands/config.command");
10
- yargs
9
+ yargs_1.default
11
10
  .usage('Usage: $0 <command> [options]')
12
- .command(new config_command_1.ConfigCommand())
13
11
  .command(new seed_command_1.SeedCommand())
14
12
  .recommendCommands()
15
13
  .demandCommand(1)
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;AACA,0BAA0B;AAC1B,4BAAyB;AACzB,0DAA8B;AAC9B,0DAAqD;AACrD,8DAAyD;AAEzD,KAAK;KACF,KAAK,CAAC,+BAA+B,CAAC;KACtC,OAAO,CAAC,IAAI,8BAAa,EAAE,CAAC;KAC5B,OAAO,CAAC,IAAI,0BAAW,EAAE,CAAC;KAC1B,iBAAiB,EAAE;KACnB,aAAa,CAAC,CAAC,CAAC;KAChB,MAAM,EAAE;KACR,IAAI,CAAC,GAAG,CAAC;KACT,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,IAAI,CAAA"}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;AACA,0BAA0B;AAC1B,4BAAyB;AACzB,0DAAyB;AACzB,0DAAqD;AAErD,eAAK;KACF,KAAK,CAAC,+BAA+B,CAAC;KACtC,OAAO,CAAC,IAAI,0BAAW,EAAE,CAAC;KAC1B,iBAAiB,EAAE;KACnB,aAAa,CAAC,CAAC,CAAC;KAChB,MAAM,EAAE;KACR,IAAI,CAAC,GAAG,CAAC;KACT,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,IAAI,CAAA"}
@@ -1,9 +1,10 @@
1
+ import { DataSource } from 'typeorm';
1
2
  import { Arguments, Argv, CommandModule } from 'yargs';
3
+ import { Seeder } from '../seeder';
4
+ import type { Constructable } from '../types';
2
5
  interface SeedCommandArguments extends Arguments {
3
- root?: string;
4
- configName?: string;
5
- connection?: string;
6
- seed?: string;
6
+ dataSource?: string;
7
+ path?: string;
7
8
  }
8
9
  export declare class SeedCommand implements CommandModule {
9
10
  command: string;
@@ -12,17 +13,13 @@ export declare class SeedCommand implements CommandModule {
12
13
  * @inheritdoc
13
14
  */
14
15
  builder(args: Argv): Argv<{
15
- n: string | undefined;
16
- } & {
17
- c: string;
18
- } & {
19
- r: string | undefined;
20
- } & {
21
- s: string | undefined;
16
+ d: string;
22
17
  }>;
23
18
  /**
24
19
  * @inheritdoc
25
20
  */
26
21
  handler(args: SeedCommandArguments): Promise<void>;
22
+ static loadDataSource(dataSourceFilePath: string): Promise<DataSource>;
23
+ static loadSeeders(seederPaths: string[]): Promise<Constructable<Seeder>[]>;
27
24
  }
28
25
  export {};