@mikro-orm/seeder 6.4.6-dev.7 → 6.4.6-dev.8

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.
package/Factory.d.ts CHANGED
@@ -9,7 +9,7 @@ export declare abstract class Factory<T extends object> {
9
9
  * Make a single entity instance, without persisting it.
10
10
  * @param overrideParameters Object specifying what default attributes of the entity factory should be overridden
11
11
  */
12
- makeEntity(overrideParameters?: EntityData<T>): T;
12
+ makeEntity(overrideParameters?: EntityData<T>, index?: number): T;
13
13
  /**
14
14
  * Make a single entity and persist (not flush)
15
15
  * @param overrideParameters Object specifying what default attributes of the entity factory should be overridden
@@ -37,5 +37,5 @@ export declare abstract class Factory<T extends object> {
37
37
  * In case of `createOne` or `create` it is applied before the entity is persisted
38
38
  * @param eachFunction The function that is applied on every entity
39
39
  */
40
- each(eachFunction: (entity: T) => void): this;
40
+ each(eachFunction: (entity: T, index: number) => void): this;
41
41
  }
package/Factory.js CHANGED
@@ -11,14 +11,12 @@ class Factory {
11
11
  * Make a single entity instance, without persisting it.
12
12
  * @param overrideParameters Object specifying what default attributes of the entity factory should be overridden
13
13
  */
14
- makeEntity(overrideParameters) {
14
+ makeEntity(overrideParameters, index = 0) {
15
15
  const entity = this.em.create(this.model, {
16
16
  ...this.definition(),
17
17
  ...overrideParameters,
18
18
  }, { persist: false });
19
- if (this.eachFunction) {
20
- this.eachFunction(entity);
21
- }
19
+ this.eachFunction?.(entity, index);
22
20
  return entity;
23
21
  }
24
22
  /**
@@ -36,8 +34,8 @@ class Factory {
36
34
  * @param overrideParameters Object specifying what default attributes of the entity factory should be overridden
37
35
  */
38
36
  make(amount, overrideParameters) {
39
- const entities = [...Array(amount)].map(() => {
40
- return this.makeEntity(overrideParameters);
37
+ const entities = [...Array(amount)].map((_, index) => {
38
+ return this.makeEntity(overrideParameters, index);
41
39
  });
42
40
  this.em.persist(entities);
43
41
  return entities;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/seeder",
3
- "version": "6.4.6-dev.7",
3
+ "version": "6.4.6-dev.8",
4
4
  "description": "Seeder package for MikroORM.",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -55,6 +55,6 @@
55
55
  "@mikro-orm/core": "^6.4.5"
56
56
  },
57
57
  "peerDependencies": {
58
- "@mikro-orm/core": "6.4.6-dev.7"
58
+ "@mikro-orm/core": "6.4.6-dev.8"
59
59
  }
60
60
  }