@jorgebodega/typeorm-seeding 4.0.0-next.3 → 5.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/.commitlintrc +5 -0
- package/CHANGELOG.md +48 -0
- package/README.md +2 -0
- package/dist/cli.js +2 -4
- package/dist/cli.js.map +1 -1
- package/dist/commands/seed.command.d.ts +8 -11
- package/dist/commands/seed.command.js +102 -61
- package/dist/commands/seed.command.js.map +1 -1
- package/dist/datasource/DataSourceManager.d.ts +8 -0
- package/dist/datasource/DataSourceManager.js +23 -0
- package/dist/datasource/DataSourceManager.js.map +1 -0
- package/dist/datasource/configureDataSource.d.ts +2 -0
- package/dist/datasource/configureDataSource.js +9 -0
- package/dist/datasource/configureDataSource.js.map +1 -0
- package/dist/datasource/fetchDataSource.d.ts +1 -0
- package/dist/datasource/fetchDataSource.js +9 -0
- package/dist/datasource/fetchDataSource.js.map +1 -0
- package/dist/datasource/index.d.ts +2 -0
- package/dist/datasource/index.js +6 -0
- package/dist/datasource/index.js.map +1 -0
- package/dist/errors/DataSourceNotProvidedError.d.ts +3 -0
- package/dist/errors/DataSourceNotProvidedError.js +10 -0
- package/dist/errors/DataSourceNotProvidedError.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +6 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/factory.d.ts +4 -1
- package/dist/factory.js +7 -4
- package/dist/factory.js.map +1 -1
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.js +6 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/useDataSource.d.ts +5 -0
- package/dist/helpers/useDataSource.js +19 -0
- package/dist/helpers/useDataSource.js.map +1 -0
- package/dist/helpers/useSeeders.d.ts +3 -0
- package/dist/helpers/useSeeders.js +13 -0
- package/dist/helpers/useSeeders.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/seeder.d.ts +2 -4
- package/dist/seeder.js +0 -5
- package/dist/seeder.js.map +1 -1
- package/dist/types.d.ts +0 -10
- package/dist/utils/fileHandling.d.ts +1 -1
- package/dist/utils/fileHandling.js +4 -4
- package/dist/utils/fileHandling.js.map +1 -1
- package/package.json +21 -26
- package/dist/commands/config.command.d.ts +0 -25
- package/dist/commands/config.command.js +0 -55
- package/dist/commands/config.command.js.map +0 -1
- package/dist/connection/ConnectionConfigurationManager.d.ts +0 -9
- package/dist/connection/ConnectionConfigurationManager.js +0 -24
- package/dist/connection/ConnectionConfigurationManager.js.map +0 -1
- package/dist/connection/configureConnection.d.ts +0 -2
- package/dist/connection/configureConnection.js +0 -9
- package/dist/connection/configureConnection.js.map +0 -1
- package/dist/connection/fetchConnection.d.ts +0 -2
- package/dist/connection/fetchConnection.js +0 -22
- package/dist/connection/fetchConnection.js.map +0 -1
- package/dist/connection/getConnectionOptions.d.ts +0 -2
- package/dist/connection/getConnectionOptions.js +0 -27
- package/dist/connection/getConnectionOptions.js.map +0 -1
- package/dist/connection/index.d.ts +0 -3
- package/dist/connection/index.js +0 -7
- package/dist/connection/index.js.map +0 -1
- package/dist/errors/DefaultSeederNotDefinedError.d.ts +0 -3
- package/dist/errors/DefaultSeederNotDefinedError.js +0 -10
- package/dist/errors/DefaultSeederNotDefinedError.js.map +0 -1
- package/dist/useSeeders.d.ts +0 -4
- package/dist/useSeeders.js +0 -15
- package/dist/useSeeders.js.map +0 -1
package/.commitlintrc
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
+
# [5.0.0-next.2](https://github.com/jorgebodega/typeorm-seeding/compare/v5.0.0-next.1...v5.0.0-next.2) (2022-08-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add factory deprecation notice ([8d75e05](https://github.com/jorgebodega/typeorm-seeding/commit/8d75e05e43b35e770f7c14437a1e6b04c8fffd01))
|
|
7
|
+
|
|
8
|
+
# [5.0.0-next.1](https://github.com/jorgebodega/typeorm-seeding/compare/v4.0.0...v5.0.0-next.1) (2022-07-13)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update dependency glob to v8 ([2d3c996](https://github.com/jorgebodega/typeorm-seeding/commit/2d3c99635fcfdd667b38a4bed60d663145dd619b))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* removed unused command and add some more tests ([ea6649e](https://github.com/jorgebodega/typeorm-seeding/commit/ea6649e98261d62907118448b047987cbebcd2c7))
|
|
19
|
+
* use typeorm 0.3 ([aa0153b](https://github.com/jorgebodega/typeorm-seeding/commit/aa0153bd050c60ab94f9979eff4e5ab9bec81645))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### BREAKING CHANGES
|
|
23
|
+
|
|
24
|
+
* Removed config command
|
|
25
|
+
* Connection API is deprecated and removed.
|
|
26
|
+
|
|
27
|
+
# [4.0.0](https://github.com/jorgebodega/typeorm-seeding/compare/v3.2.0...v4.0.0) (2022-03-23)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Bug Fixes
|
|
31
|
+
|
|
32
|
+
* add type check on subfactories creation ([2b2883b](https://github.com/jorgebodega/typeorm-seeding/commit/2b2883b48ea08173a032b219266b1fece937e753))
|
|
33
|
+
* attrs failing with lazy instances ([c8ddda8](https://github.com/jorgebodega/typeorm-seeding/commit/c8ddda841f9e65d7081e419d2d2e662c6d6a78df))
|
|
34
|
+
* update dependency yargs to v17.4.0 ([b64c224](https://github.com/jorgebodega/typeorm-seeding/commit/b64c2245ebb086d891c503972f74cdcca0e2ddab))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
* add factorized attrs ([4a2ce08](https://github.com/jorgebodega/typeorm-seeding/commit/4a2ce08e1be1d79df8f1c0450ba4b315ebca8c46))
|
|
40
|
+
* add lazyattribute and subfactory as options in attribs ([48a3630](https://github.com/jorgebodega/typeorm-seeding/commit/48a3630b8c606ff5189c05dc51908dc09f142184))
|
|
41
|
+
* add subfactory as valid factorized attr ([0f4b37e](https://github.com/jorgebodega/typeorm-seeding/commit/0f4b37e0f8c3e93aedbd109ddb8f33ac0127a2dc))
|
|
42
|
+
* separate different types of lazy attributes ([3efe94e](https://github.com/jorgebodega/typeorm-seeding/commit/3efe94ea140643ccb12dbf8858968a5866fd7577))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### BREAKING CHANGES
|
|
46
|
+
|
|
47
|
+
* definition function has been substituted with attrs
|
|
48
|
+
|
|
1
49
|
# [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)
|
|
2
50
|
|
|
3
51
|
# [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)
|
package/README.md
CHANGED
|
@@ -448,6 +448,8 @@ This command execute a seeder, that could be specified as a parameter.
|
|
|
448
448
|
typeorm-seeding seed
|
|
449
449
|
```
|
|
450
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
|
+
|
|
451
453
|
##### Options
|
|
452
454
|
|
|
453
455
|
| Option | Default | Description |
|
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
|
|
7
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
8
8
|
const seed_command_1 = require("./commands/seed.command");
|
|
9
|
-
|
|
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,
|
|
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
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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 {};
|
|
@@ -2,100 +2,141 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SeedCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const ora_1 = tslib_1.__importDefault(require("ora"));
|
|
7
|
+
const typeorm_1 = require("typeorm");
|
|
5
8
|
const yargs_1 = require("yargs");
|
|
6
|
-
const
|
|
7
|
-
const chalk_1 = require("chalk");
|
|
8
|
-
const connection_1 = require("../connection");
|
|
9
|
-
const useSeeders_1 = require("../useSeeders");
|
|
9
|
+
const useSeeders_1 = require("../helpers/useSeeders");
|
|
10
10
|
const fileHandling_1 = require("../utils/fileHandling");
|
|
11
|
-
const SeederImportationError_1 = require("../errors/SeederImportationError");
|
|
12
11
|
class SeedCommand {
|
|
13
12
|
constructor() {
|
|
14
|
-
this.command = 'seed';
|
|
15
|
-
this.describe = 'Runs the
|
|
13
|
+
this.command = 'seed <path>';
|
|
14
|
+
this.describe = 'Runs the seeders';
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
17
|
* @inheritdoc
|
|
19
18
|
*/
|
|
20
19
|
builder(args) {
|
|
21
20
|
return args
|
|
22
|
-
.option('
|
|
23
|
-
alias: '
|
|
21
|
+
.option('d', {
|
|
22
|
+
alias: 'dataSource',
|
|
24
23
|
type: 'string',
|
|
25
|
-
describe: '
|
|
24
|
+
describe: 'Path to the file where your DataSource instance is defined.',
|
|
25
|
+
required: true,
|
|
26
26
|
})
|
|
27
|
-
.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
alias: 'root',
|
|
35
|
-
type: 'string',
|
|
36
|
-
describe: 'Path to your typeorm config file',
|
|
37
|
-
})
|
|
38
|
-
.option('s', {
|
|
39
|
-
alias: 'seed',
|
|
40
|
-
type: 'string',
|
|
41
|
-
describe: 'Specific seed class to run.',
|
|
27
|
+
.fail((message, error) => {
|
|
28
|
+
if (error)
|
|
29
|
+
throw error; // preserve stack
|
|
30
|
+
else {
|
|
31
|
+
console.error(message);
|
|
32
|
+
(0, yargs_1.showHelp)();
|
|
33
|
+
}
|
|
42
34
|
});
|
|
43
35
|
}
|
|
44
36
|
/**
|
|
45
37
|
* @inheritdoc
|
|
46
38
|
*/
|
|
47
39
|
async handler(args) {
|
|
48
|
-
const spinner = (0, ora_1.default)({
|
|
49
|
-
|
|
50
|
-
let
|
|
40
|
+
const spinner = (0, ora_1.default)({ isSilent: process.env.NODE_ENV === 'test' }).start();
|
|
41
|
+
spinner.start('Loading datasource');
|
|
42
|
+
let dataSource;
|
|
51
43
|
try {
|
|
52
|
-
(0,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
connection: args.connection,
|
|
56
|
-
});
|
|
57
|
-
options = await (0, connection_1.getConnectionOptions)();
|
|
58
|
-
spinner.succeed('ORM Config loaded');
|
|
44
|
+
const dataSourcePath = (0, node_path_1.resolve)(process.cwd(), args.dataSource);
|
|
45
|
+
dataSource = await SeedCommand.loadDataSource(dataSourcePath);
|
|
46
|
+
spinner.succeed('Datasource loaded');
|
|
59
47
|
}
|
|
60
48
|
catch (error) {
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
spinner.fail('Could not load the data source!');
|
|
50
|
+
throw error;
|
|
63
51
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
let seeder;
|
|
52
|
+
spinner.start('Importing seeders');
|
|
53
|
+
let seeders;
|
|
67
54
|
try {
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const seederWanted = args.seed || options.defaultSeeder;
|
|
72
|
-
seeder = allSeeders[seederWanted];
|
|
73
|
-
if (!seeder) {
|
|
74
|
-
throw new SeederImportationError_1.SeederImportationError(`Seeder ${seederWanted} does not exist`);
|
|
75
|
-
}
|
|
55
|
+
const absolutePath = (0, node_path_1.resolve)(process.cwd(), args.path);
|
|
56
|
+
const seederFiles = (0, fileHandling_1.calculateFilePath)(absolutePath);
|
|
57
|
+
seeders = await SeedCommand.loadSeeders(seederFiles);
|
|
76
58
|
spinner.succeed('Seeder imported');
|
|
77
59
|
}
|
|
78
60
|
catch (error) {
|
|
79
|
-
|
|
80
|
-
|
|
61
|
+
spinner.fail('Could not load seeders!');
|
|
62
|
+
await dataSource.destroy();
|
|
63
|
+
throw error;
|
|
81
64
|
}
|
|
82
65
|
// Run seeder
|
|
83
|
-
spinner.start(`Executing
|
|
66
|
+
spinner.start(`Executing seeders`);
|
|
84
67
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
68
|
+
for (const seeder of seeders) {
|
|
69
|
+
await (0, useSeeders_1.useSeeders)(seeder);
|
|
70
|
+
spinner.succeed(`Seeder ${seeder.name} executed`);
|
|
71
|
+
}
|
|
87
72
|
}
|
|
88
73
|
catch (error) {
|
|
89
|
-
|
|
90
|
-
|
|
74
|
+
spinner.fail('Could not execute seeder!');
|
|
75
|
+
await dataSource.destroy();
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
spinner.succeed('Finished seeding');
|
|
79
|
+
await dataSource.destroy();
|
|
80
|
+
}
|
|
81
|
+
static async loadDataSource(dataSourceFilePath) {
|
|
82
|
+
let dataSourceFileExports;
|
|
83
|
+
try {
|
|
84
|
+
dataSourceFileExports = await Promise.resolve().then(() => tslib_1.__importStar(require(dataSourceFilePath)));
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
throw new Error(`Unable to open file: "${dataSourceFilePath}"`);
|
|
88
|
+
}
|
|
89
|
+
if (!dataSourceFileExports || typeof dataSourceFileExports !== 'object') {
|
|
90
|
+
throw new Error(`Given data source file must contain export of a DataSource instance`);
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
const dataSourceExports = [];
|
|
93
|
+
for (const fileExport in dataSourceFileExports) {
|
|
94
|
+
const dataSourceExport = dataSourceFileExports[fileExport];
|
|
95
|
+
if (dataSourceExport instanceof typeorm_1.DataSource) {
|
|
96
|
+
dataSourceExports.push(dataSourceExport);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (dataSourceExports.length === 0) {
|
|
100
|
+
throw new Error(`Given data source file must contain export of a DataSource instance`);
|
|
101
|
+
}
|
|
102
|
+
if (dataSourceExports.length > 1) {
|
|
103
|
+
throw new Error(`Given data source file must contain only one export of DataSource instance`);
|
|
104
|
+
}
|
|
105
|
+
const dataSource = dataSourceExports[0];
|
|
106
|
+
dataSource.setOptions({
|
|
107
|
+
synchronize: false,
|
|
108
|
+
migrationsRun: false,
|
|
109
|
+
dropSchema: false,
|
|
110
|
+
logging: false,
|
|
111
|
+
});
|
|
112
|
+
await dataSource.initialize();
|
|
113
|
+
return dataSource;
|
|
114
|
+
}
|
|
115
|
+
static async loadSeeders(seederPaths) {
|
|
116
|
+
let seederFileExports;
|
|
117
|
+
try {
|
|
118
|
+
seederFileExports = await Promise.all(seederPaths.map((seederFile) => Promise.resolve().then(() => tslib_1.__importStar(require(seederFile))))).then((seederExports) => {
|
|
119
|
+
return seederExports
|
|
120
|
+
.map((seederExport) => seederExport.default)
|
|
121
|
+
.filter((seederExport) => Boolean(seederExport));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
throw new Error(`Unable to open files ${err.message}`);
|
|
126
|
+
}
|
|
127
|
+
if (seederFileExports.length === 0) {
|
|
128
|
+
throw new Error(`No default seeders found`);
|
|
129
|
+
}
|
|
130
|
+
const seeders = [];
|
|
131
|
+
for (const fileExport in seederFileExports) {
|
|
132
|
+
const seederExport = seederFileExports[fileExport];
|
|
133
|
+
const instance = new seederExport();
|
|
134
|
+
if (instance instanceof typeorm_1.DataSource) {
|
|
135
|
+
seeders.push(seederExport);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return seeders;
|
|
93
139
|
}
|
|
94
140
|
}
|
|
95
141
|
exports.SeedCommand = SeedCommand;
|
|
96
|
-
function panic(spinner, error, message) {
|
|
97
|
-
spinner.fail(message);
|
|
98
|
-
console.error(error.message);
|
|
99
|
-
(0, yargs_1.exit)(1, error);
|
|
100
|
-
}
|
|
101
142
|
//# sourceMappingURL=seed.command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.command.js","sourceRoot":"","sources":["../../src/commands/seed.command.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"seed.command.js","sourceRoot":"","sources":["../../src/commands/seed.command.ts"],"names":[],"mappings":";;;;AAAA,yCAAmC;AACnC,sDAAqB;AACrB,qCAAoC;AACpC,iCAAgE;AAEhE,sDAAkD;AAClD,wDAAyD;AAQzD,MAAa,WAAW;IAAxB;QACE,YAAO,GAAG,aAAa,CAAA;QACvB,aAAQ,GAAG,kBAAkB,CAAA;IA6I/B,CAAC;IA3IC;;OAEG;IACH,OAAO,CAAC,IAAU;QAChB,OAAO,IAAI;aACR,MAAM,CAAC,GAAG,EAAE;YACX,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,6DAA6D;YACvE,QAAQ,EAAE,IAAI;SACf,CAAC;aACD,IAAI,CAAC,CAAC,OAAO,EAAE,KAAY,EAAE,EAAE;YAC9B,IAAI,KAAK;gBAAE,MAAM,KAAK,CAAA,CAAC,iBAAiB;iBACnC;gBACH,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;gBACt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BAAU,EAAE;gBAClC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;aAC3B;SACF;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AA/ID,kCA+IC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSourceManager = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
class DataSourceManager {
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!DataSourceManager._instance) {
|
|
8
|
+
DataSourceManager._instance = new DataSourceManager();
|
|
9
|
+
}
|
|
10
|
+
return DataSourceManager._instance;
|
|
11
|
+
}
|
|
12
|
+
get dataSource() {
|
|
13
|
+
if (this._dataSource === undefined) {
|
|
14
|
+
throw new errors_1.DataSourceNotProvidedError();
|
|
15
|
+
}
|
|
16
|
+
return this._dataSource;
|
|
17
|
+
}
|
|
18
|
+
set dataSource(dataSource) {
|
|
19
|
+
this._dataSource = dataSource;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.DataSourceManager = DataSourceManager;
|
|
23
|
+
//# sourceMappingURL=DataSourceManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataSourceManager.js","sourceRoot":"","sources":["../../src/datasource/DataSourceManager.ts"],"names":[],"mappings":";;;AACA,sCAAsD;AAEtD,MAAa,iBAAiB;IAI5B,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE;YAChC,iBAAiB,CAAC,SAAS,GAAG,IAAI,iBAAiB,EAAE,CAAA;SACtD;QAED,OAAO,iBAAiB,CAAC,SAAS,CAAA;IACpC,CAAC;IAED,IAAI,UAAU;QACZ,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,EAAE;YAClC,MAAM,IAAI,mCAA0B,EAAE,CAAA;SACvC;QAED,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;IAED,IAAI,UAAU,CAAC,UAAsB;QACnC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAA;IAC/B,CAAC;CACF;AAvBD,8CAuBC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configureDataSource = void 0;
|
|
4
|
+
const DataSourceManager_1 = require("./DataSourceManager");
|
|
5
|
+
function configureDataSource(dataSource) {
|
|
6
|
+
DataSourceManager_1.DataSourceManager.getInstance().dataSource = dataSource;
|
|
7
|
+
}
|
|
8
|
+
exports.configureDataSource = configureDataSource;
|
|
9
|
+
//# sourceMappingURL=configureDataSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configureDataSource.js","sourceRoot":"","sources":["../../src/datasource/configureDataSource.ts"],"names":[],"mappings":";;;AACA,2DAAuD;AAEvD,SAAgB,mBAAmB,CAAC,UAAsB;IACxD,qCAAiB,CAAC,WAAW,EAAE,CAAC,UAAU,GAAG,UAAU,CAAA;AACzD,CAAC;AAFD,kDAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fetchDataSource(): import("typeorm").DataSource;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchDataSource = void 0;
|
|
4
|
+
const DataSourceManager_1 = require("./DataSourceManager");
|
|
5
|
+
function fetchDataSource() {
|
|
6
|
+
return DataSourceManager_1.DataSourceManager.getInstance().dataSource;
|
|
7
|
+
}
|
|
8
|
+
exports.fetchDataSource = fetchDataSource;
|
|
9
|
+
//# sourceMappingURL=fetchDataSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchDataSource.js","sourceRoot":"","sources":["../../src/datasource/fetchDataSource.ts"],"names":[],"mappings":";;;AAAA,2DAAuD;AAEvD,SAAgB,eAAe;IAC7B,OAAO,qCAAiB,CAAC,WAAW,EAAE,CAAC,UAAU,CAAA;AACnD,CAAC;AAFD,0CAEC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./configureDataSource"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./fetchDataSource"), exports);
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/datasource/index.ts"],"names":[],"mappings":";;;AAAA,gEAAqC;AACrC,4DAAiC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSourceNotProvidedError = void 0;
|
|
4
|
+
class DataSourceNotProvidedError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(`Data source is not provided.`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.DataSourceNotProvidedError = DataSourceNotProvidedError;
|
|
10
|
+
//# sourceMappingURL=DataSourceNotProvidedError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataSourceNotProvidedError.js","sourceRoot":"","sources":["../../src/errors/DataSourceNotProvidedError.ts"],"names":[],"mappings":";;;AAAA,MAAa,0BAA2B,SAAQ,KAAK;IACnD;QACE,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACvC,CAAC;CACF;AAJD,gEAIC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./DataSourceNotProvidedError"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./SeederImportationError"), exports);
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;AAAA,uEAA4C;AAC5C,mEAAwC"}
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { SaveOptions } from 'typeorm';
|
|
2
2
|
import type { Constructable, FactorizedAttrs } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Starting from v6, this class is moved to [typeorm-factory](https://github.com/jorgebodega/typeorm-factory)
|
|
5
|
+
*/
|
|
3
6
|
export declare abstract class Factory<T> {
|
|
4
7
|
protected abstract entity: Constructable<T>;
|
|
5
|
-
protected abstract attrs: FactorizedAttrs<T>;
|
|
8
|
+
protected abstract attrs(): FactorizedAttrs<T>;
|
|
6
9
|
/**
|
|
7
10
|
* Make a new entity without persisting it
|
|
8
11
|
*/
|
package/dist/factory.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Factory = void 0;
|
|
4
|
-
const
|
|
4
|
+
const datasource_1 = require("./datasource");
|
|
5
5
|
const instanceAttribute_1 = require("./instanceAttribute");
|
|
6
6
|
const lazyInstanceAttribute_1 = require("./lazyInstanceAttribute");
|
|
7
7
|
const subfactory_1 = require("./subfactory");
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Starting from v6, this class is moved to [typeorm-factory](https://github.com/jorgebodega/typeorm-factory)
|
|
10
|
+
*/
|
|
8
11
|
class Factory {
|
|
9
12
|
/**
|
|
10
13
|
* Make a new entity without persisting it
|
|
11
14
|
*/
|
|
12
15
|
async make(overrideParams = {}) {
|
|
13
|
-
const attrs = { ...this.attrs, ...overrideParams };
|
|
16
|
+
const attrs = { ...this.attrs(), ...overrideParams };
|
|
14
17
|
const entity = await this.makeEntity(attrs, false);
|
|
15
18
|
await this.applyLazyAttributes(entity, attrs, false);
|
|
16
19
|
return entity;
|
|
@@ -29,10 +32,10 @@ class Factory {
|
|
|
29
32
|
* Create a new entity and persist it
|
|
30
33
|
*/
|
|
31
34
|
async create(overrideParams = {}, saveOptions) {
|
|
32
|
-
const attrs = { ...this.attrs, ...overrideParams };
|
|
35
|
+
const attrs = { ...this.attrs(), ...overrideParams };
|
|
33
36
|
const preloadedAttrs = Object.entries(attrs).filter(([, value]) => !(value instanceof lazyInstanceAttribute_1.LazyInstanceAttribute));
|
|
34
37
|
const entity = await this.makeEntity(Object.fromEntries(preloadedAttrs), true);
|
|
35
|
-
const em = (
|
|
38
|
+
const em = (0, datasource_1.fetchDataSource)().createEntityManager();
|
|
36
39
|
const savedEntity = await em.save(entity, saveOptions);
|
|
37
40
|
await this.applyLazyAttributes(savedEntity, attrs, true);
|
|
38
41
|
return em.save(savedEntity, saveOptions);
|
package/dist/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,2DAAuD;AACvD,mEAA+D;AAC/D,6CAAyC;AAGzC,MAAsB,OAAO;IAI3B;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,iBAA8C,EAAE;QACzD,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,cAAc,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":";;;AACA,6CAA8C;AAC9C,2DAAuD;AACvD,mEAA+D;AAC/D,6CAAyC;AAGzC;;GAEG;AACH,MAAsB,OAAO;IAI3B;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,iBAA8C,EAAE;QACzD,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,cAAc,EAAE,CAAA;QAEp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,CACH,CAAA;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAAC,MAAS,EAAE,KAAyB,EAAE,aAAsB;QAC5F,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC/C,IAAI,KAAK,YAAY,6CAAqB,EAAE;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;AAAA,0DAA+B;AAC/B,uDAA4B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DataSource, DataSourceOptions } from 'typeorm';
|
|
2
|
+
export declare function useDataSource(dataSource: DataSource): Promise<void>;
|
|
3
|
+
export declare function useDataSource(dataSource: DataSource, overrideOptions: Partial<DataSourceOptions>): Promise<void>;
|
|
4
|
+
export declare function useDataSource(dataSource: DataSource, forceInitialization: boolean): Promise<void>;
|
|
5
|
+
export declare function useDataSource(dataSource: DataSource, overrideOptions: Partial<DataSourceOptions>, forceInitialization: boolean): Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDataSource = void 0;
|
|
4
|
+
const datasource_1 = require("../datasource");
|
|
5
|
+
async function useDataSource(dataSource, overrideOptionsOrForceInitialization, forceInitialization) {
|
|
6
|
+
const overrideOptions = typeof overrideOptionsOrForceInitialization === 'object' ? overrideOptionsOrForceInitialization : undefined;
|
|
7
|
+
const shouldInitilialize = typeof overrideOptionsOrForceInitialization === 'boolean'
|
|
8
|
+
? overrideOptionsOrForceInitialization
|
|
9
|
+
: forceInitialization;
|
|
10
|
+
if (overrideOptions) {
|
|
11
|
+
dataSource.setOptions(overrideOptions);
|
|
12
|
+
}
|
|
13
|
+
if (shouldInitilialize) {
|
|
14
|
+
await dataSource.initialize();
|
|
15
|
+
}
|
|
16
|
+
(0, datasource_1.configureDataSource)(dataSource);
|
|
17
|
+
}
|
|
18
|
+
exports.useDataSource = useDataSource;
|
|
19
|
+
//# sourceMappingURL=useDataSource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDataSource.js","sourceRoot":"","sources":["../../src/helpers/useDataSource.ts"],"names":[],"mappings":";;;AACA,8CAAmD;AAW5C,KAAK,UAAU,aAAa,CACjC,UAAsB,EACtB,oCAA2E,EAC3E,mBAA6B;IAE7B,MAAM,eAAe,GACnB,OAAO,oCAAoC,KAAK,QAAQ,CAAC,CAAC,CAAC,oCAAoC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC7G,MAAM,kBAAkB,GACtB,OAAO,oCAAoC,KAAK,SAAS;QACvD,CAAC,CAAC,oCAAoC;QACtC,CAAC,CAAC,mBAAmB,CAAA;IAEzB,IAAI,eAAe,EAAE;QACnB,UAAU,CAAC,UAAU,CAAC,eAAe,CAAC,CAAA;KACvC;IAED,IAAI,kBAAkB,EAAE;QACtB,MAAM,UAAU,CAAC,UAAU,EAAE,CAAA;KAC9B;IAED,IAAA,gCAAmB,EAAC,UAAU,CAAC,CAAA;AACjC,CAAC;AArBD,sCAqBC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSeeders = void 0;
|
|
4
|
+
const datasource_1 = require("../datasource");
|
|
5
|
+
async function useSeeders(entrySeeders) {
|
|
6
|
+
const dataSource = (0, datasource_1.fetchDataSource)();
|
|
7
|
+
const seeders = Array.isArray(entrySeeders) ? entrySeeders : [entrySeeders];
|
|
8
|
+
for (const seeder of seeders) {
|
|
9
|
+
await new seeder().run(dataSource);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.useSeeders = useSeeders;
|
|
13
|
+
//# sourceMappingURL=useSeeders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSeeders.js","sourceRoot":"","sources":["../../src/helpers/useSeeders.ts"],"names":[],"mappings":";;;AAAA,8CAA+C;AAIxC,KAAK,UAAU,UAAU,CAAC,YAA6D;IAC5F,MAAM,UAAU,GAAG,IAAA,4BAAe,GAAE,CAAA;IAEpC,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;AAPD,gCAOC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './errors';
|
|
2
2
|
export * from './factory';
|
|
3
|
+
export * from './helpers';
|
|
3
4
|
export * from './instanceAttribute';
|
|
4
5
|
export * from './lazyInstanceAttribute';
|
|
5
6
|
export * from './seeder';
|
|
6
7
|
export * from './subfactory';
|
|
7
8
|
export * from './types';
|
|
8
|
-
export * from './useSeeders';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
tslib_1.__exportStar(require("./errors"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./factory"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./helpers"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./instanceAttribute"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lazyInstanceAttribute"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./seeder"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./subfactory"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
12
12
|
//# 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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwB;AACxB,oDAAyB;AACzB,oDAAyB;AACzB,8DAAmC;AACnC,kEAAuC;AACvC,mDAAwB;AACxB,uDAA4B;AAC5B,kDAAuB"}
|
package/dist/seeder.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Constructable } from './types';
|
|
1
|
+
import type { DataSource } from 'typeorm';
|
|
3
2
|
export declare abstract class Seeder {
|
|
4
|
-
abstract run(
|
|
5
|
-
protected call(connection: Connection, seeders: Constructable<Seeder>[]): Promise<void>;
|
|
3
|
+
abstract run(dataSource: DataSource): Promise<void>;
|
|
6
4
|
}
|
package/dist/seeder.js
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Seeder = void 0;
|
|
4
4
|
class Seeder {
|
|
5
|
-
async call(connection, seeders) {
|
|
6
|
-
for (const seeder of seeders) {
|
|
7
|
-
await new seeder().run(connection);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
5
|
}
|
|
11
6
|
exports.Seeder = Seeder;
|
|
12
7
|
//# sourceMappingURL=seeder.js.map
|
package/dist/seeder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seeder.js","sourceRoot":"","sources":["../src/seeder.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"seeder.js","sourceRoot":"","sources":["../src/seeder.ts"],"names":[],"mappings":";;;AAEA,MAAsB,MAAM;CAE3B;AAFD,wBAEC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import type { ConnectionOptions as TypeORMConnectionOptions } from 'typeorm';
|
|
2
1
|
import type { LazyAttribute } from './lazyAttribute';
|
|
3
2
|
import type { Subfactory } from './subfactory';
|
|
4
|
-
export declare type ConnectionOptions = TypeORMConnectionOptions & {
|
|
5
|
-
seeders: string[];
|
|
6
|
-
defaultSeeder: string;
|
|
7
|
-
};
|
|
8
|
-
export declare type ConnectionConfiguration = {
|
|
9
|
-
root?: string;
|
|
10
|
-
configName?: string;
|
|
11
|
-
connection: string;
|
|
12
|
-
};
|
|
13
3
|
export declare type Constructable<T> = new () => T;
|
|
14
4
|
export declare type FactorizedAttr<V> = V | (() => V | Promise<V>) | Subfactory<V extends Array<infer U> ? U : V>;
|
|
15
5
|
export declare type FactorizedAttrs<T> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const calculateFilePath: (filePattern: string) => string[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.calculateFilePath = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const glob_1 = require("glob");
|
|
6
|
-
const
|
|
7
|
-
return
|
|
6
|
+
const calculateFilePath = (filePattern) => {
|
|
7
|
+
return (0, glob_1.sync)((0, path_1.resolve)(process.cwd(), filePattern), { ignore: '**/node_modules/**' });
|
|
8
8
|
};
|
|
9
|
-
exports.
|
|
9
|
+
exports.calculateFilePath = calculateFilePath;
|
|
10
10
|
//# sourceMappingURL=fileHandling.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileHandling.js","sourceRoot":"","sources":["../../src/utils/fileHandling.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAC9B,+BAA2B;AAEpB,MAAM,
|
|
1
|
+
{"version":3,"file":"fileHandling.js","sourceRoot":"","sources":["../../src/utils/fileHandling.ts"],"names":[],"mappings":";;;AAAA,+BAA8B;AAC9B,+BAA2B;AAEpB,MAAM,iBAAiB,GAAG,CAAC,WAAmB,EAAY,EAAE;IACjE,OAAO,IAAA,WAAI,EAAC,IAAA,cAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAA;AACpF,CAAC,CAAA;AAFY,QAAA,iBAAiB,qBAE7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jorgebodega/typeorm-seeding",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.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,44 +36,39 @@
|
|
|
36
36
|
"typecheck": "tsc --noEmit"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@faker-js/faker": "
|
|
39
|
+
"@faker-js/faker": "7.3.0",
|
|
40
40
|
"@semantic-release/changelog": "6.0.1",
|
|
41
41
|
"@semantic-release/git": "10.0.1",
|
|
42
|
-
"@tsconfig/node16": "1.0.
|
|
42
|
+
"@tsconfig/node16": "1.0.3",
|
|
43
43
|
"@types/bcryptjs": "2.4.2",
|
|
44
|
-
"@types/chalk": "2.2.0",
|
|
45
44
|
"@types/glob": "7.2.0",
|
|
46
|
-
"@types/jest": "
|
|
47
|
-
"@types/
|
|
48
|
-
"@
|
|
49
|
-
"@typescript-eslint/
|
|
50
|
-
"@typescript-eslint/parser": "5.13.0",
|
|
45
|
+
"@types/jest": "28.1.6",
|
|
46
|
+
"@types/yargs": "17.0.10",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "5.31.0",
|
|
48
|
+
"@typescript-eslint/parser": "5.31.0",
|
|
51
49
|
"bcryptjs": "2.4.3",
|
|
52
|
-
"eslint": "8.
|
|
53
|
-
"eslint-config-prettier": "8.
|
|
54
|
-
"eslint-plugin-import": "2.
|
|
55
|
-
"jest": "
|
|
56
|
-
"prettier": "2.
|
|
50
|
+
"eslint": "8.21.0",
|
|
51
|
+
"eslint-config-prettier": "8.5.0",
|
|
52
|
+
"eslint-plugin-import": "2.26.0",
|
|
53
|
+
"jest": "28.1.3",
|
|
54
|
+
"prettier": "2.7.1",
|
|
57
55
|
"rimraf": "3.0.2",
|
|
58
|
-
"semantic-release": "19.0.
|
|
59
|
-
"sqlite3": "5.0.
|
|
60
|
-
"ts-jest": "
|
|
61
|
-
"ts-node": "10.
|
|
62
|
-
"typeorm": "0.
|
|
63
|
-
"typescript": "4.
|
|
56
|
+
"semantic-release": "19.0.3",
|
|
57
|
+
"sqlite3": "5.0.11",
|
|
58
|
+
"ts-jest": "28.0.7",
|
|
59
|
+
"ts-node": "10.9.1",
|
|
60
|
+
"typeorm": "0.3.7",
|
|
61
|
+
"typescript": "4.7.4"
|
|
64
62
|
},
|
|
65
63
|
"dependencies": {
|
|
66
64
|
"chalk": "4.1.2",
|
|
67
|
-
"glob": "
|
|
65
|
+
"glob": "8.0.3",
|
|
68
66
|
"ora": "5.4.1",
|
|
69
67
|
"reflect-metadata": "0.1.13",
|
|
70
|
-
"yargs": "17.
|
|
68
|
+
"yargs": "17.5.1"
|
|
71
69
|
},
|
|
72
70
|
"peerDependencies": {
|
|
73
|
-
"typeorm": "^0.
|
|
74
|
-
},
|
|
75
|
-
"resolutions": {
|
|
76
|
-
"mem": ">=4.0.0"
|
|
71
|
+
"typeorm": "^0.3.0"
|
|
77
72
|
},
|
|
78
73
|
"engines": {
|
|
79
74
|
"node": ">=14"
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Argv, Arguments, CommandModule } from 'yargs';
|
|
2
|
-
interface ConfigCommandArguments extends Arguments {
|
|
3
|
-
root?: string;
|
|
4
|
-
configName?: string;
|
|
5
|
-
connection?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare class ConfigCommand implements CommandModule {
|
|
8
|
-
command: string;
|
|
9
|
-
describe: string;
|
|
10
|
-
/**
|
|
11
|
-
* @inheritdoc
|
|
12
|
-
*/
|
|
13
|
-
builder(args: Argv): Argv<{
|
|
14
|
-
n: string | undefined;
|
|
15
|
-
} & {
|
|
16
|
-
c: string;
|
|
17
|
-
} & {
|
|
18
|
-
r: string | undefined;
|
|
19
|
-
}>;
|
|
20
|
-
/**
|
|
21
|
-
* @inheritdoc
|
|
22
|
-
*/
|
|
23
|
-
handler(args: ConfigCommandArguments): Promise<void>;
|
|
24
|
-
}
|
|
25
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConfigCommand = void 0;
|
|
4
|
-
const yargs_1 = require("yargs");
|
|
5
|
-
const chalk_1 = require("chalk");
|
|
6
|
-
const connection_1 = require("../connection");
|
|
7
|
-
class ConfigCommand {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.command = 'config';
|
|
10
|
-
this.describe = 'Show the TypeORM config with seeding values';
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @inheritdoc
|
|
14
|
-
*/
|
|
15
|
-
builder(args) {
|
|
16
|
-
return args
|
|
17
|
-
.option('n', {
|
|
18
|
-
alias: 'configName',
|
|
19
|
-
type: 'string',
|
|
20
|
-
describe: 'Name of the typeorm config file (json or js).',
|
|
21
|
-
})
|
|
22
|
-
.option('c', {
|
|
23
|
-
alias: 'connection',
|
|
24
|
-
type: 'string',
|
|
25
|
-
default: 'default',
|
|
26
|
-
describe: 'Name of the typeorm connection',
|
|
27
|
-
})
|
|
28
|
-
.option('r', {
|
|
29
|
-
alias: 'root',
|
|
30
|
-
type: 'string',
|
|
31
|
-
describe: 'Path to your typeorm config file',
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* @inheritdoc
|
|
36
|
-
*/
|
|
37
|
-
async handler(args) {
|
|
38
|
-
try {
|
|
39
|
-
(0, connection_1.configureConnection)({
|
|
40
|
-
root: args.root,
|
|
41
|
-
configName: args.configName,
|
|
42
|
-
connection: args.connection,
|
|
43
|
-
});
|
|
44
|
-
const options = await (0, connection_1.getConnectionOptions)();
|
|
45
|
-
console.log(options);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.log('\n❌ ', (0, chalk_1.red)('Could not find the orm config file'));
|
|
49
|
-
console.error(error);
|
|
50
|
-
(0, yargs_1.exit)(1, error);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.ConfigCommand = ConfigCommand;
|
|
55
|
-
//# sourceMappingURL=config.command.js.map
|
|
@@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A;SACxB;IACH,CAAC;CACF;AA7CD,sCA6CC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ConnectionConfiguration } from '../types';
|
|
2
|
-
export declare class ConnectionConfigurationManager {
|
|
3
|
-
private static _instance;
|
|
4
|
-
private _configuration;
|
|
5
|
-
private constructor();
|
|
6
|
-
static getInstance(): ConnectionConfigurationManager;
|
|
7
|
-
get configuration(): ConnectionConfiguration;
|
|
8
|
-
overrideConfiguration(configuration: Partial<ConnectionConfiguration>): void;
|
|
9
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConnectionConfigurationManager = void 0;
|
|
4
|
-
class ConnectionConfigurationManager {
|
|
5
|
-
constructor() {
|
|
6
|
-
this._configuration = {
|
|
7
|
-
connection: 'default',
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
static getInstance() {
|
|
11
|
-
if (!ConnectionConfigurationManager._instance) {
|
|
12
|
-
ConnectionConfigurationManager._instance = new ConnectionConfigurationManager();
|
|
13
|
-
}
|
|
14
|
-
return ConnectionConfigurationManager._instance;
|
|
15
|
-
}
|
|
16
|
-
get configuration() {
|
|
17
|
-
return this._configuration;
|
|
18
|
-
}
|
|
19
|
-
overrideConfiguration(configuration) {
|
|
20
|
-
this._configuration = { ...this._configuration, ...configuration };
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.ConnectionConfigurationManager = ConnectionConfigurationManager;
|
|
24
|
-
//# sourceMappingURL=ConnectionConfigurationManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionConfigurationManager.js","sourceRoot":"","sources":["../../src/connection/ConnectionConfigurationManager.ts"],"names":[],"mappings":";;;AAEA,MAAa,8BAA8B;IAIzC;QACE,IAAI,CAAC,cAAc,GAAG;YACpB,UAAU,EAAE,SAAS;SACtB,CAAA;IACH,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,8BAA8B,CAAC,SAAS,EAAE;YAC7C,8BAA8B,CAAC,SAAS,GAAG,IAAI,8BAA8B,EAAE,CAAA;SAChF;QAED,OAAO,8BAA8B,CAAC,SAAS,CAAA;IACjD,CAAC;IAED,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,cAAc,CAAA;IAC5B,CAAC;IAED,qBAAqB,CAAC,aAA+C;QACnE,IAAI,CAAC,cAAc,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,GAAG,aAAa,EAAE,CAAA;IACpE,CAAC;CACF;AAzBD,wEAyBC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configureConnection = void 0;
|
|
4
|
-
const ConnectionConfigurationManager_1 = require("./ConnectionConfigurationManager");
|
|
5
|
-
function configureConnection(options = {}) {
|
|
6
|
-
ConnectionConfigurationManager_1.ConnectionConfigurationManager.getInstance().overrideConfiguration(options);
|
|
7
|
-
}
|
|
8
|
-
exports.configureConnection = configureConnection;
|
|
9
|
-
//# sourceMappingURL=configureConnection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configureConnection.js","sourceRoot":"","sources":["../../src/connection/configureConnection.ts"],"names":[],"mappings":";;;AACA,qFAAiF;AAEjF,SAAgB,mBAAmB,CAAC,UAA4C,EAAE;IAChF,+DAA8B,CAAC,WAAW,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAA;AAC7E,CAAC;AAFD,kDAEC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchConnection = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
const ConnectionConfigurationManager_1 = require("./ConnectionConfigurationManager");
|
|
6
|
-
const getConnectionOptions_1 = require("./getConnectionOptions");
|
|
7
|
-
const fetchConnection = async () => {
|
|
8
|
-
const { connection: connectionName } = ConnectionConfigurationManager_1.ConnectionConfigurationManager.getInstance().configuration;
|
|
9
|
-
const getNewConnection = async () => (0, typeorm_1.createConnection)(await (0, getConnectionOptions_1.getConnectionOptions)());
|
|
10
|
-
let connection;
|
|
11
|
-
try {
|
|
12
|
-
connection = (0, typeorm_1.getConnection)(connectionName);
|
|
13
|
-
if (connection.isConnected)
|
|
14
|
-
return connection;
|
|
15
|
-
return getNewConnection();
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return getNewConnection();
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
exports.fetchConnection = fetchConnection;
|
|
22
|
-
//# sourceMappingURL=fetchConnection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchConnection.js","sourceRoot":"","sources":["../../src/connection/fetchConnection.ts"],"names":[],"mappings":";;;AACA,qCAAyD;AACzD,qFAAiF;AACjF,iEAA6D;AAEtD,MAAM,eAAe,GAAG,KAAK,IAAyB,EAAE;IAC7D,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,+DAA8B,CAAC,WAAW,EAAE,CAAC,aAAa,CAAA;IAEjG,MAAM,gBAAgB,GAAG,KAAK,IAAyB,EAAE,CAAC,IAAA,0BAAgB,EAAC,MAAM,IAAA,2CAAoB,GAAE,CAAC,CAAA;IAExG,IAAI,UAAsB,CAAA;IAC1B,IAAI;QACF,UAAU,GAAG,IAAA,uBAAa,EAAC,cAAc,CAAC,CAAA;QAC1C,IAAI,UAAU,CAAC,WAAW;YAAE,OAAO,UAAU,CAAA;QAE7C,OAAO,gBAAgB,EAAE,CAAA;KAC1B;IAAC,MAAM;QACN,OAAO,gBAAgB,EAAE,CAAA;KAC1B;AACH,CAAC,CAAA;AAdY,QAAA,eAAe,mBAc3B"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConnectionOptions = void 0;
|
|
4
|
-
const typeorm_1 = require("typeorm");
|
|
5
|
-
const DefaultSeederNotDefinedError_1 = require("../errors/DefaultSeederNotDefinedError");
|
|
6
|
-
const ConnectionConfigurationManager_1 = require("./ConnectionConfigurationManager");
|
|
7
|
-
async function getConnectionOptions() {
|
|
8
|
-
const { root, configName, connection } = ConnectionConfigurationManager_1.ConnectionConfigurationManager.getInstance().configuration;
|
|
9
|
-
const connectionReader = new typeorm_1.ConnectionOptionsReader({
|
|
10
|
-
root,
|
|
11
|
-
configName,
|
|
12
|
-
});
|
|
13
|
-
const options = (await connectionReader.get(connection));
|
|
14
|
-
const seedersFromEnv = process.env.TYPEORM_SEEDING_SEEDERS;
|
|
15
|
-
const defaultSeederFromEnv = process.env.TYPEORM_SEEDING_DEFAULT_SEEDER;
|
|
16
|
-
const defaultSeeder = defaultSeederFromEnv || options.defaultSeeder;
|
|
17
|
-
if (!defaultSeeder) {
|
|
18
|
-
throw new DefaultSeederNotDefinedError_1.DefaultSeederNotDefinedError();
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
...options,
|
|
22
|
-
seeders: seedersFromEnv ? [seedersFromEnv] : options.seeders || [],
|
|
23
|
-
defaultSeeder,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
exports.getConnectionOptions = getConnectionOptions;
|
|
27
|
-
//# sourceMappingURL=getConnectionOptions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getConnectionOptions.js","sourceRoot":"","sources":["../../src/connection/getConnectionOptions.ts"],"names":[],"mappings":";;;AAAA,qCAAiD;AACjD,yFAAqF;AAErF,qFAAiF;AAE1E,KAAK,UAAU,oBAAoB;IACxC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,+DAA8B,CAAC,WAAW,EAAE,CAAC,aAAa,CAAA;IACnG,MAAM,gBAAgB,GAAG,IAAI,iCAAuB,CAAC;QACnD,IAAI;QACJ,UAAU;KACX,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,CAAC,MAAM,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAsB,CAAA;IAE7E,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAA;IAC1D,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAA;IACvE,MAAM,aAAa,GAAG,oBAAoB,IAAI,OAAO,CAAC,aAAa,CAAA;IAEnE,IAAI,CAAC,aAAa,EAAE;QAClB,MAAM,IAAI,2DAA4B,EAAE,CAAA;KACzC;IAED,OAAO;QACL,GAAG,OAAO;QACV,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE;QAClE,aAAa;KACd,CAAA;AACH,CAAC;AAtBD,oDAsBC"}
|
package/dist/connection/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
(0, tslib_1.__exportStar)(require("./configureConnection"), exports);
|
|
5
|
-
(0, tslib_1.__exportStar)(require("./fetchConnection"), exports);
|
|
6
|
-
(0, tslib_1.__exportStar)(require("./getConnectionOptions"), exports);
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":";;;AAAA,qEAAqC;AACrC,iEAAiC;AACjC,sEAAsC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultSeederNotDefinedError = void 0;
|
|
4
|
-
class DefaultSeederNotDefinedError extends Error {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(`Default seeder is not defined.`);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
exports.DefaultSeederNotDefinedError = DefaultSeederNotDefinedError;
|
|
10
|
-
//# sourceMappingURL=DefaultSeederNotDefinedError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultSeederNotDefinedError.js","sourceRoot":"","sources":["../../src/errors/DefaultSeederNotDefinedError.ts"],"names":[],"mappings":";;;AAAA,MAAa,4BAA6B,SAAQ,KAAK;IACrD;QACE,KAAK,CAAC,gCAAgC,CAAC,CAAA;IACzC,CAAC;CACF;AAJD,oEAIC"}
|
package/dist/useSeeders.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Seeder } from './seeder';
|
|
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>;
|
package/dist/useSeeders.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSeeders = void 0;
|
|
4
|
-
const connection_1 = require("./connection");
|
|
5
|
-
async function useSeeders(entrySeeders, customOptions) {
|
|
6
|
-
if (customOptions)
|
|
7
|
-
(0, connection_1.configureConnection)(customOptions);
|
|
8
|
-
const connection = await (0, connection_1.fetchConnection)();
|
|
9
|
-
const seeders = Array.isArray(entrySeeders) ? entrySeeders : [entrySeeders];
|
|
10
|
-
for (const seeder of seeders) {
|
|
11
|
-
await new seeder().run(connection);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.useSeeders = useSeeders;
|
|
15
|
-
//# sourceMappingURL=useSeeders.js.map
|
package/dist/useSeeders.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|