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

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/CHANGELOG.md CHANGED
@@ -1,40 +1,53 @@
1
- # [4.0.0-next.1](https://github.com/jorgebodega/typeorm-seeding/compare/v3.0.0...v4.0.0-next.1) (2022-01-08)
1
+ # [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
+
3
+ # [4.0.0-next.1](https://github.com/jorgebodega/typeorm-seeding/compare/v3.2.0...v4.0.0-next.1) (2022-02-12)
2
4
 
3
5
 
4
6
  ### Bug Fixes
5
7
 
6
- * adapt seeder to new schema ([a1d4e27](https://github.com/jorgebodega/typeorm-seeding/commit/a1d4e272e89481d0163ef0d4594a32ae7942cb9d))
7
- * add rimraf as dev dependency ([6be6801](https://github.com/jorgebodega/typeorm-seeding/commit/6be6801a70c8b27a1176a416c5981024fe68e907))
8
- * remove factories option from config ([870a23d](https://github.com/jorgebodega/typeorm-seeding/commit/870a23d912a1d18964e52c5c172b38714a8aa042))
8
+ * add type check on subfactories creation ([2b2883b](https://github.com/jorgebodega/typeorm-seeding/commit/2b2883b48ea08173a032b219266b1fece937e753))
9
+ * attrs failing with lazy instances ([c8ddda8](https://github.com/jorgebodega/typeorm-seeding/commit/c8ddda841f9e65d7081e419d2d2e662c6d6a78df))
9
10
 
10
11
 
11
- ### chore
12
+ ### Features
12
13
 
13
- * remove all faker usages from source folder ([2e4b0fb](https://github.com/jorgebodega/typeorm-seeding/commit/2e4b0fb756050f5061d3c0ea38899d40ce30b5a0))
14
- * remove faker from dependencies ([f41cef4](https://github.com/jorgebodega/typeorm-seeding/commit/f41cef4c32720fb36756ac117d6b74d30d6d8998))
14
+ * add factorized attrs ([4a2ce08](https://github.com/jorgebodega/typeorm-seeding/commit/4a2ce08e1be1d79df8f1c0450ba4b315ebca8c46))
15
+ * add lazyattribute and subfactory as options in attribs ([48a3630](https://github.com/jorgebodega/typeorm-seeding/commit/48a3630b8c606ff5189c05dc51908dc09f142184))
16
+ * add subfactory as valid factorized attr ([0f4b37e](https://github.com/jorgebodega/typeorm-seeding/commit/0f4b37e0f8c3e93aedbd109ddb8f33ac0127a2dc))
17
+ * separate different types of lazy attributes ([3efe94e](https://github.com/jorgebodega/typeorm-seeding/commit/3efe94ea140643ccb12dbf8858968a5866fd7577))
18
+
19
+
20
+ ### BREAKING CHANGES
21
+
22
+ * definition function has been substituted with attrs
23
+
24
+ # [3.2.0](https://github.com/jorgebodega/typeorm-seeding/compare/v3.1.0...v3.2.0) (2022-02-06)
15
25
 
16
26
 
17
27
  ### Features
18
28
 
19
- * adapt use seeders to new structure ([7ea3607](https://github.com/jorgebodega/typeorm-seeding/commit/7ea360752e54b8694f148f9dad25bf4815c04224))
20
- * move factory definition to new abstract class ([41cf349](https://github.com/jorgebodega/typeorm-seeding/commit/41cf3494e8a97b185d113191c9598e49a4e73ced))
21
- * remove context from factories ([#23](https://github.com/jorgebodega/typeorm-seeding/issues/23)) ([c030e89](https://github.com/jorgebodega/typeorm-seeding/commit/c030e890add5d41099004f8542a8dd521873d91d))
22
- * remove deprecated elements ([09006e8](https://github.com/jorgebodega/typeorm-seeding/commit/09006e8655f288ebc318d32136b10f720687449f))
23
- * remove factory helper methods and test associateds ([#30](https://github.com/jorgebodega/typeorm-seeding/issues/30)) ([a335ca2](https://github.com/jorgebodega/typeorm-seeding/commit/a335ca232410e2d1d93011ceca33068e01a7f16e))
24
- * remove useFactories helper method ([#29](https://github.com/jorgebodega/typeorm-seeding/issues/29)) ([6fbeaba](https://github.com/jorgebodega/typeorm-seeding/commit/6fbeabaf2988b3d71fa19c2b44e443f58b805495))
25
- * seed command will execute now default seeder or seed param ([84025f9](https://github.com/jorgebodega/typeorm-seeding/commit/84025f9a948c2d0823c2f95e6fb0193f0e36716a))
29
+ * Allow async map function ([2d2c27b](https://github.com/jorgebodega/typeorm-seeding/commit/2d2c27bfb6d208a4507169a9e9fa41e8e3680072))
26
30
 
31
+ # [3.1.0](https://github.com/jorgebodega/typeorm-seeding/compare/v3.0.1...v3.1.0) (2022-01-13)
27
32
 
28
- ### BREAKING CHANGES
29
33
 
30
- * `useSeeders` change its definition and is now incompatible with previous version
31
- * Faker is not available anymore as function param
32
- * Faker is removed from dependencies and now users must install it by themselves
33
- * Some of these functions were used on previous versions
34
- * New abstract factory class is incompatible with previous version
35
- * Helper methods removed were a core part of previous versions
36
- * This method will no longer be available as is useless in new architecture
37
- * Context is being removed from factories. This could break some applications that were using it
34
+ ### Features
35
+
36
+ * add support to async definition on factory ([9432089](https://github.com/jorgebodega/typeorm-seeding/commit/9432089394b027552c12dc0a1dcb5f706cb6c107))
37
+
38
+ # [3.1.0-next.1](https://github.com/jorgebodega/typeorm-seeding/compare/v3.0.1...v3.1.0-next.1) (2022-01-09)
39
+
40
+
41
+ ### Features
42
+
43
+ * add support to async definition on factory ([5fcca0e](https://github.com/jorgebodega/typeorm-seeding/commit/5fcca0e8d2016c68fda18fe1b202739558b07466))
44
+
45
+ ## [3.0.1](https://github.com/jorgebodega/typeorm-seeding/compare/v3.0.0...v3.0.1) (2022-01-08)
46
+
47
+
48
+ ### Bug Fixes
49
+
50
+ * update dependencies and add rimraf to dev deps ([504cef2](https://github.com/jorgebodega/typeorm-seeding/commit/504cef2f94b1b8e2e47d6bfa6e0bb1e8325490e2))
38
51
 
39
52
  # [3.0.0](https://github.com/jorgebodega/typeorm-seeding/compare/v2.0.0...v3.0.0) (2022-01-06)
40
53
 
package/README.md CHANGED
@@ -246,7 +246,7 @@ define(User, (faker: typeof Faker) => {
246
246
  You can do:
247
247
 
248
248
  ```typescript
249
- import * as faker from 'faker'
249
+ import faker from '@faker-js/faker'
250
250
 
251
251
  class UserFactory extends Factory<User> {
252
252
  protected definition(): User {
@@ -1 +1 @@
1
- {"version":3,"file":"seed.command.js","sourceRoot":"","sources":["../../src/commands/seed.command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AE,EAAE,CAAC,CAAA;YAExF,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,aAAa,CAAA;YACvD,MAAM,GAAG,UAAU,CAAC,YAAY,CAAC,CAAA;YAEjC,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,+CAAsB,CAAC,UAAU,YAAY,iBAAiB,CAAC,CAAA;aAC1E;YACD,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;SACnC;QAAC,OAAO,KAAK,EAAE;YACd,KAAK,CAAC,OAAO,EAAE,KAAc,EAAE,2BAA2B,CAAC,CAAA;YAC3D,OAAM;SACP;QAED,aAAa;QACb,OAAO,CAAC,KAAK,CAAC,aAAa,MAAM,CAAC,IAAI,SAAS,CAAC,CAAA;QAChD,IAAI;YACF,MAAM,IAAA,uBAAU,EAAC,MAAM,CAAC,CAAA;YACxB,OAAO,CAAC,OAAO,CAAC,UAAU,MAAM,CAAC,IAAI,WAAW,CAAC,CAAA;SAClD;QAAC,OAAO,KAAK,EAAE;YACd,KAAK,CAAC,OAAO,EAAE,KAAc,EAAE,0BAA0B,MAAM,CAAC,IAAI,GAAG,CAAC,CAAA;YACxE,OAAM;SACP;QAED,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,YAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAA;IACxD,CAAC;CACF;AArFD,kCAqFC;AAED,SAAS,KAAK,CAAC,OAAY,EAAE,KAAY,EAAE,OAAe;IACxD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACrB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC5B,IAAA,YAAI,EAAC,CAAC,EAAE,KAAK,CAAC,CAAA;AAChB,CAAC"}
package/dist/factory.d.ts CHANGED
@@ -1,28 +1,25 @@
1
1
  import type { SaveOptions } from 'typeorm';
2
- export declare abstract class Factory<Entity> {
3
- private mapFunction?;
4
- protected abstract definition(): Entity;
5
- /**
6
- * This function is used to alter the generated values of entity, before it
7
- * is persist into the database
8
- */
9
- map(mapFunction: (entity: Entity) => void): this;
2
+ import type { Constructable, FactorizedAttrs } from './types';
3
+ export declare abstract class Factory<T> {
4
+ protected abstract entity: Constructable<T>;
5
+ protected abstract attrs: FactorizedAttrs<T>;
10
6
  /**
11
7
  * Make a new entity without persisting it
12
8
  */
13
- make(overrideParams?: Partial<Entity>): Promise<Entity>;
9
+ make(overrideParams?: Partial<FactorizedAttrs<T>>): Promise<T>;
14
10
  /**
15
11
  * Make many new entities without persisting it
16
12
  */
17
- makeMany(amount: number, overrideParams?: Partial<Entity>): Promise<Entity[]>;
13
+ makeMany(amount: number, overrideParams?: Partial<FactorizedAttrs<T>>): Promise<T[]>;
18
14
  /**
19
15
  * Create a new entity and persist it
20
16
  */
21
- create(overrideParams?: Partial<Entity>, saveOptions?: SaveOptions): Promise<Entity>;
17
+ create(overrideParams?: Partial<FactorizedAttrs<T>>, saveOptions?: SaveOptions): Promise<T>;
22
18
  /**
23
19
  * Create many new entities and persist them
24
20
  */
25
- createMany(amount: number, overrideParams?: Partial<Entity>, saveOptions?: SaveOptions): Promise<Entity[]>;
21
+ createMany(amount: number, overrideParams?: Partial<FactorizedAttrs<T>>, saveOptions?: SaveOptions): Promise<T[]>;
26
22
  private makeEntity;
27
- private resolveEntity;
23
+ private applyLazyAttributes;
24
+ private static resolveValue;
28
25
  }
package/dist/factory.js CHANGED
@@ -2,21 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Factory = void 0;
4
4
  const connection_1 = require("./connection");
5
- const isPromiseLike_1 = require("./utils/isPromiseLike");
5
+ const instanceAttribute_1 = require("./instanceAttribute");
6
+ const lazyInstanceAttribute_1 = require("./lazyInstanceAttribute");
7
+ const subfactory_1 = require("./subfactory");
6
8
  class Factory {
7
- /**
8
- * This function is used to alter the generated values of entity, before it
9
- * is persist into the database
10
- */
11
- map(mapFunction) {
12
- this.mapFunction = mapFunction;
13
- return this;
14
- }
15
9
  /**
16
10
  * Make a new entity without persisting it
17
11
  */
18
12
  async make(overrideParams = {}) {
19
- return this.makeEntity(overrideParams, false);
13
+ const attrs = { ...this.attrs, ...overrideParams };
14
+ const entity = await this.makeEntity(attrs, false);
15
+ await this.applyLazyAttributes(entity, attrs, false);
16
+ return entity;
20
17
  }
21
18
  /**
22
19
  * Make many new entities without persisting it
@@ -32,9 +29,13 @@ class Factory {
32
29
  * Create a new entity and persist it
33
30
  */
34
31
  async create(overrideParams = {}, saveOptions) {
35
- const entity = await this.makeEntity(overrideParams, true);
36
- const connection = await (0, connection_1.fetchConnection)();
37
- return connection.createEntityManager().save(entity, saveOptions);
32
+ const attrs = { ...this.attrs, ...overrideParams };
33
+ const preloadedAttrs = Object.entries(attrs).filter(([, value]) => !(value instanceof lazyInstanceAttribute_1.LazyInstanceAttribute));
34
+ const entity = await this.makeEntity(Object.fromEntries(preloadedAttrs), true);
35
+ const em = (await (0, connection_1.fetchConnection)()).createEntityManager();
36
+ const savedEntity = await em.save(entity, saveOptions);
37
+ await this.applyLazyAttributes(savedEntity, attrs, true);
38
+ return em.save(savedEntity, saveOptions);
38
39
  }
39
40
  /**
40
41
  * Create many new entities and persist them
@@ -46,32 +47,37 @@ class Factory {
46
47
  }
47
48
  return list;
48
49
  }
49
- async makeEntity(overrideParams, isSeeding) {
50
- const entity = this.definition();
51
- if (this.mapFunction)
52
- this.mapFunction(entity);
53
- for (const key in overrideParams) {
54
- const actualValue = entity[key];
55
- entity[key] = overrideParams[key];
56
- }
57
- return this.resolveEntity(entity, isSeeding);
58
- }
59
- async resolveEntity(entity, isSeeding) {
60
- for (const attribute in entity) {
61
- const attributeValue = entity[attribute];
62
- if ((0, isPromiseLike_1.isPromiseLike)(attributeValue)) {
63
- entity[attribute] = await attributeValue;
50
+ async makeEntity(attrs, shouldPersist) {
51
+ const entity = new this.entity();
52
+ await Promise.all(Object.entries(attrs).map(async ([key, value]) => {
53
+ Object.assign(entity, { [key]: await Factory.resolveValue(value, shouldPersist) });
54
+ }));
55
+ await Promise.all(Object.entries(attrs).map(async ([key, value]) => {
56
+ if (value instanceof instanceAttribute_1.InstanceAttribute) {
57
+ const newAttrib = value.resolve(entity);
58
+ Object.assign(entity, { [key]: await Factory.resolveValue(newAttrib, shouldPersist) });
64
59
  }
65
- if (attributeValue instanceof Factory) {
66
- if (isSeeding) {
67
- entity[attribute] = await attributeValue.create();
68
- }
69
- else {
70
- entity[attribute] = await attributeValue.make();
71
- }
60
+ }));
61
+ return entity;
62
+ }
63
+ async applyLazyAttributes(entity, attrs, shouldPersist) {
64
+ await Promise.all(Object.entries(attrs).map(async ([key, value]) => {
65
+ if (value instanceof lazyInstanceAttribute_1.LazyInstanceAttribute) {
66
+ const newAttrib = value.resolve(entity);
67
+ Object.assign(entity, { [key]: await Factory.resolveValue(newAttrib, shouldPersist) });
72
68
  }
69
+ }));
70
+ }
71
+ static resolveValue(value, shouldPersist) {
72
+ if (value instanceof subfactory_1.Subfactory) {
73
+ return shouldPersist ? value.create() : value.make();
74
+ }
75
+ else if (value instanceof Function) {
76
+ return value();
77
+ }
78
+ else {
79
+ return value;
73
80
  }
74
- return entity;
75
81
  }
76
82
  }
77
83
  exports.Factory = Factory;
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,yDAAqD;AAErD,MAAsB,OAAO;IAI3B;;;OAGG;IACH,GAAG,CAAC,WAAqC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,iBAAkC,EAAE;QAC7C,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;IAC/C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,iBAAkC,EAAE;QACjE,MAAM,I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AAE;gBAC1C,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;gBACvC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,CAAC,CAAA;aACvF;QACH,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IAEO,MAAM,CAAC,YAAY,CAAC,KAAc,EAAE,aAAsB;QAChE,IAAI,KAAK,YAAY,uBAAU,EAAE;YAC/B,OAAO,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;SACrD;aAAM,IAAI,KAAK,YAAY,QAAQ,EAAE;YACpC,OAAO,KAAK,EAAE,CAAA;SACf;aAAM;YACL,OAAO,KAAK,CAAA;SACb;IACH,CAAC;CACF;AAnGD,0BAmGC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
1
  export * from './connection';
2
2
  export * from './factory';
3
+ export * from './lazyAttribute';
4
+ export * from './instanceAttribute';
5
+ export * from './lazyInstanceAttribute';
3
6
  export * from './seeder';
7
+ export * from './subfactory';
4
8
  export * from './types';
5
9
  export * from './useSeeders';
package/dist/index.js CHANGED
@@ -3,7 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  (0, tslib_1.__exportStar)(require("./connection"), exports);
5
5
  (0, tslib_1.__exportStar)(require("./factory"), exports);
6
+ (0, tslib_1.__exportStar)(require("./lazyAttribute"), exports);
7
+ (0, tslib_1.__exportStar)(require("./instanceAttribute"), exports);
8
+ (0, tslib_1.__exportStar)(require("./lazyInstanceAttribute"), exports);
6
9
  (0, tslib_1.__exportStar)(require("./seeder"), exports);
10
+ (0, tslib_1.__exportStar)(require("./subfactory"), exports);
7
11
  (0, tslib_1.__exportStar)(require("./types"), exports);
8
12
  (0, tslib_1.__exportStar)(require("./useSeeders"), exports);
9
13
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4DAA4B;AAC5B,yDAAyB;AACzB,wDAAwB;AACxB,uDAAuB;AACvB,4DAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4DAA4B;AAC5B,yDAAyB;AACzB,+DAA+B;AAC/B,mEAAmC;AACnC,uEAAuC;AACvC,wDAAwB;AACxB,4DAA4B;AAC5B,uDAAuB;AACvB,4DAA4B"}
@@ -0,0 +1,3 @@
1
+ import { LazyAttribute } from './lazyAttribute';
2
+ export declare class InstanceAttribute<T, V> extends LazyAttribute<T, V> {
3
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InstanceAttribute = void 0;
4
+ const lazyAttribute_1 = require("./lazyAttribute");
5
+ class InstanceAttribute extends lazyAttribute_1.LazyAttribute {
6
+ }
7
+ exports.InstanceAttribute = InstanceAttribute;
8
+ //# sourceMappingURL=instanceAttribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instanceAttribute.js","sourceRoot":"","sources":["../src/instanceAttribute.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAE/C,MAAa,iBAAwB,SAAQ,6BAAmB;CAAG;AAAnE,8CAAmE"}
@@ -0,0 +1,6 @@
1
+ import type { FactorizedAttr, LazyAttributeCallback } from './types';
2
+ export declare abstract class LazyAttribute<T, V> {
3
+ private callback;
4
+ constructor(callback: LazyAttributeCallback<T, V>);
5
+ resolve(entity: T): FactorizedAttr<V>;
6
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LazyAttribute = void 0;
4
+ class LazyAttribute {
5
+ constructor(callback) {
6
+ this.callback = callback;
7
+ }
8
+ resolve(entity) {
9
+ return this.callback(entity);
10
+ }
11
+ }
12
+ exports.LazyAttribute = LazyAttribute;
13
+ //# sourceMappingURL=lazyAttribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazyAttribute.js","sourceRoot":"","sources":["../src/lazyAttribute.ts"],"names":[],"mappings":";;;AAEA,MAAsB,aAAa;IACjC,YAAoB,QAAqC;QAArC,aAAQ,GAAR,QAAQ,CAA6B;IAAG,CAAC;IAE7D,OAAO,CAAC,MAAS;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IAC9B,CAAC;CACF;AAND,sCAMC"}
@@ -0,0 +1,3 @@
1
+ import { LazyAttribute } from './lazyAttribute';
2
+ export declare class LazyInstanceAttribute<T, V> extends LazyAttribute<T, V> {
3
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LazyInstanceAttribute = void 0;
4
+ const lazyAttribute_1 = require("./lazyAttribute");
5
+ class LazyInstanceAttribute extends lazyAttribute_1.LazyAttribute {
6
+ }
7
+ exports.LazyInstanceAttribute = LazyInstanceAttribute;
8
+ //# sourceMappingURL=lazyInstanceAttribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazyInstanceAttribute.js","sourceRoot":"","sources":["../src/lazyInstanceAttribute.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAE/C,MAAa,qBAA4B,SAAQ,6BAAmB;CAAG;AAAvE,sDAAuE"}
package/dist/seeder.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Connection } from 'typeorm';
2
- import type { ClassConstructor } from './types';
2
+ import type { Constructable } from './types';
3
3
  export declare abstract class Seeder {
4
4
  abstract run(connection: Connection): Promise<void>;
5
- protected call(connection: Connection, seeders: ClassConstructor<Seeder>[]): Promise<void>;
5
+ protected call(connection: Connection, seeders: Constructable<Seeder>[]): Promise<void>;
6
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"seeder.js","sourceRoot":"","sources":["../src/seeder.ts"],"names":[],"mappings":";;;AAGA,MAAsB,MAAM;IAGhB,KAAK,CAAC,IAAI,CAAC,UAAsB,EAAE,OAAmC;QAC9E,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC5B,MAAM,IAAI,MAAM,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;SACnC;IACH,CAAC;CACF;AARD,wBAQC"}
1
+ {"version":3,"file":"seeder.js","sourceRoot":"","sources":["../src/seeder.ts"],"names":[],"mappings":";;;AAGA,MAAsB,MAAM;IAGhB,KAAK,CAAC,IAAI,CAAC,UAAsB,EAAE,OAAgC;QAC3E,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC5B,MAAM,IAAI,MAAM,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;SACnC;IACH,CAAC;CACF;AARD,wBAQC"}
@@ -0,0 +1,13 @@
1
+ import type { Factory } from './factory';
2
+ import type { Constructable, FactorizedAttrs } from './types';
3
+ export declare class Subfactory<T> {
4
+ private factoryInstance;
5
+ private values?;
6
+ private count?;
7
+ constructor(factory: Constructable<Factory<T>>);
8
+ constructor(factory: Constructable<Factory<T>>, values?: Partial<FactorizedAttrs<T>>);
9
+ constructor(factory: Constructable<Factory<T>>, count?: number);
10
+ constructor(factory: Constructable<Factory<T>>, values?: Partial<FactorizedAttrs<T>>, count?: number);
11
+ create(): Promise<T[]> | Promise<T>;
12
+ make(): Promise<T[]> | Promise<T>;
13
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Subfactory = void 0;
4
+ class Subfactory {
5
+ constructor(factory, countOrValues, count) {
6
+ this.factoryInstance = new factory();
7
+ this.values = typeof countOrValues === 'number' ? undefined : countOrValues;
8
+ this.count = typeof countOrValues === 'number' ? countOrValues : count;
9
+ }
10
+ create() {
11
+ if (this.count !== undefined) {
12
+ return this.factoryInstance.createMany(this.count, this.values);
13
+ }
14
+ return this.factoryInstance.create(this.values);
15
+ }
16
+ make() {
17
+ if (this.count !== undefined) {
18
+ return this.factoryInstance.makeMany(this.count, this.values);
19
+ }
20
+ return this.factoryInstance.make(this.values);
21
+ }
22
+ }
23
+ exports.Subfactory = Subfactory;
24
+ //# sourceMappingURL=subfactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subfactory.js","sourceRoot":"","sources":["../src/subfactory.ts"],"names":[],"mappings":";;;AAGA,MAAa,UAAU;IAUrB,YACE,OAAkC,EAClC,aAAoD,EACpD,KAAc;QAEd,IAAI,CAAC,eAAe,GAAG,IAAI,OAAO,EAAE,CAAA;QACpC,IAAI,CAAC,MAAM,GAAG,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,CAAA;QAC3E,IAAI,CAAC,KAAK,GAAG,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAA;IACxE,CAAC;IAED,MAAM;QACJ,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;SAChE;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACjD,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;YAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;SAC9D;QAED,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;CACF;AAnCD,gCAmCC"}
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ConnectionOptions as TypeORMConnectionOptions } from 'typeorm';
2
- export declare type ClassConstructor<T> = new () => T;
2
+ import type { LazyAttribute } from './lazyAttribute';
3
+ import type { Subfactory } from './subfactory';
3
4
  export declare type ConnectionOptions = TypeORMConnectionOptions & {
4
5
  seeders: string[];
5
6
  defaultSeeder: string;
@@ -9,3 +10,9 @@ export declare type ConnectionConfiguration = {
9
10
  configName?: string;
10
11
  connection: string;
11
12
  };
13
+ export declare type Constructable<T> = new () => T;
14
+ export declare type FactorizedAttr<V> = V | (() => V | Promise<V>) | Subfactory<V extends Array<infer U> ? U : V>;
15
+ export declare type FactorizedAttrs<T> = {
16
+ [K in keyof Partial<T>]: FactorizedAttr<T[K]> | LazyAttribute<T, FactorizedAttr<T[K]>>;
17
+ };
18
+ export declare type LazyAttributeCallback<T, V> = (entity: T) => V;
@@ -1,4 +1,4 @@
1
1
  import { Seeder } from './seeder';
2
- import type { ClassConstructor, ConnectionConfiguration } from './types';
3
- export declare function useSeeders(entrySeeders: ClassConstructor<Seeder> | ClassConstructor<Seeder>[]): Promise<void>;
4
- export declare function useSeeders(entrySeeders: ClassConstructor<Seeder> | ClassConstructor<Seeder>[], customOptions: Partial<ConnectionConfiguration>): Promise<void>;
2
+ import type { ConnectionConfiguration, Constructable } from './types';
3
+ export declare function useSeeders(entrySeeders: Constructable<Seeder> | Constructable<Seeder>[]): Promise<void>;
4
+ export declare function useSeeders(entrySeeders: Constructable<Seeder> | Constructable<Seeder>[], customOptions: Partial<ConnectionConfiguration>): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"useSeeders.js","sourceRoot":"","sources":["../src/useSeeders.ts"],"names":[],"mappings":";;;AAAA,6CAAmE;AAU5D,KAAK,UAAU,UAAU,CAC9B,YAAmE,EACnE,aAAgD;IAEhD,IAAI,aAAa;QAAE,IAAA,gCAAmB,EAAC,aAAa,CAAC,CAAA;IAErD,MAAM,UAAU,GAAG,MAAM,IAAA,4BAAe,GAAE,CAAA;IAE1C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;IAC3E,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,MAAM,IAAI,MAAM,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;KACnC;AACH,CAAC;AAZD,gCAYC"}
1
+ {"version":3,"file":"useSeeders.js","sourceRoot":"","sources":["../src/useSeeders.ts"],"names":[],"mappings":";;;AAAA,6CAAmE;AAU5D,KAAK,UAAU,UAAU,CAC9B,YAA6D,EAC7D,aAAgD;IAEhD,IAAI,aAAa;QAAE,IAAA,gCAAmB,EAAC,aAAa,CAAC,CAAA;IAErD,MAAM,UAAU,GAAG,MAAM,IAAA,4BAAe,GAAE,CAAA;IAE1C,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;IAC3E,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,MAAM,IAAI,MAAM,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;KACnC;AACH,CAAC;AAZD,gCAYC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jorgebodega/typeorm-seeding",
3
- "version": "4.0.0-next.1",
3
+ "version": "4.0.0-next.2",
4
4
  "description": "🌱 A delightful way to seed test data into your database.",
5
5
  "license": "MIT",
6
6
  "author": "Gery Hirschfeld <gery.hirschfeld@w3tec.ch> (https://github.com/hirsch88)",
@@ -36,39 +36,38 @@
36
36
  "typecheck": "tsc --noEmit"
37
37
  },
38
38
  "devDependencies": {
39
+ "@faker-js/faker": "6.0.0-alpha.6",
39
40
  "@semantic-release/changelog": "6.0.1",
40
41
  "@semantic-release/git": "10.0.1",
41
42
  "@tsconfig/node16": "1.0.2",
42
43
  "@types/bcryptjs": "2.4.2",
43
44
  "@types/chalk": "2.2.0",
44
- "@types/faker": "5.5.9",
45
45
  "@types/glob": "7.2.0",
46
46
  "@types/jest": "27.4.0",
47
- "@types/node": "16.11.19",
47
+ "@types/node": "17.0.17",
48
48
  "@types/yargs": "17.0.8",
49
- "@typescript-eslint/eslint-plugin": "5.9.0",
50
- "@typescript-eslint/parser": "5.9.0",
49
+ "@typescript-eslint/eslint-plugin": "5.11.0",
50
+ "@typescript-eslint/parser": "5.11.0",
51
51
  "bcryptjs": "2.4.3",
52
- "eslint": "8.6.0",
52
+ "eslint": "8.9.0",
53
53
  "eslint-config-prettier": "8.3.0",
54
54
  "eslint-plugin-import": "2.25.4",
55
- "faker": "5.5.3",
56
- "jest": "27.4.7",
55
+ "jest": "27.5.1",
57
56
  "prettier": "2.5.1",
58
- "rimraf": "^3.0.2",
57
+ "rimraf": "3.0.2",
59
58
  "semantic-release": "18.0.1",
60
59
  "sqlite3": "5.0.2",
61
- "ts-jest": "27.1.2",
62
- "ts-node": "10.4.0",
60
+ "ts-jest": "27.1.3",
61
+ "ts-node": "10.5.0",
63
62
  "typeorm": "0.2.41",
64
- "typescript": "4.5.4"
63
+ "typescript": "4.5.5"
65
64
  },
66
65
  "dependencies": {
67
- "chalk": "^4",
68
- "glob": "^7.2.0",
69
- "ora": "^5",
70
- "reflect-metadata": "^0.1.13",
71
- "yargs": "^17.3.0"
66
+ "chalk": "4.1.2",
67
+ "glob": "7.2.0",
68
+ "ora": "5.4.1",
69
+ "reflect-metadata": "0.1.13",
70
+ "yargs": "17.3.1"
72
71
  },
73
72
  "peerDependencies": {
74
73
  "typeorm": "^0.2.41"
@@ -1 +0,0 @@
1
- export declare const isPromiseLike: (o: any) => o is Promise<any>;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPromiseLike = void 0;
4
- const isPromiseLike = (o) => o && Object.prototype.toString.call(o) === '[object Promise]';
5
- exports.isPromiseLike = isPromiseLike;
6
- //# sourceMappingURL=isPromiseLike.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isPromiseLike.js","sourceRoot":"","sources":["../../src/utils/isPromiseLike.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAAC,CAAM,EAAqB,EAAE,CACzD,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,kBAAkB,CAAA;AADlD,QAAA,aAAa,iBACqC"}