@ackplus/nest-seeder 1.1.2 → 1.1.6
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/package.json +1 -1
- package/src/cli.js +173 -0
- package/src/index.js +11 -0
- package/src/lib/decorators/factory.decorator.js +16 -0
- package/src/lib/factory/data.factory.js +67 -0
- package/src/lib/index.js +7 -0
- package/src/lib/interfaces/factory.interface.js +2 -0
- package/src/lib/interfaces/index.js +5 -0
- package/src/lib/interfaces/property-metadata.interface.js +2 -0
- package/src/lib/interfaces/seeder-module-async-options.interface.js +2 -0
- package/src/lib/interfaces/seeder-options-factory.interface.js +2 -0
- package/src/lib/seeder/seeder.interface.js +2 -0
- package/src/lib/seeder/seeder.js +37 -0
- package/src/lib/seeder/seeder.module.js +74 -0
- package/src/lib/seeder/seeder.service.js +62 -0
- package/src/lib/storages/factory.metadata.storage.js +18 -0
package/package.json
CHANGED
package/src/cli.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.seeder = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const seeder_module_1 = require("./lib/seeder/seeder.module");
|
|
7
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
8
|
+
const core_1 = require("@nestjs/core");
|
|
9
|
+
const seeder_service_1 = require("./lib/seeder/seeder.service");
|
|
10
|
+
const path = tslib_1.__importStar(require("path"));
|
|
11
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
12
|
+
async function parseArguments() {
|
|
13
|
+
const argv = await (0, yargs_1.default)(process.argv.slice(2))
|
|
14
|
+
.option('refresh', {
|
|
15
|
+
alias: 'r',
|
|
16
|
+
type: 'boolean',
|
|
17
|
+
description: 'Drop all data before seeding',
|
|
18
|
+
default: false
|
|
19
|
+
})
|
|
20
|
+
.option('name', {
|
|
21
|
+
alias: 'n',
|
|
22
|
+
type: 'array',
|
|
23
|
+
string: true,
|
|
24
|
+
description: 'Specific seeder names to run',
|
|
25
|
+
})
|
|
26
|
+
.option('dummyData', {
|
|
27
|
+
alias: 'd',
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
description: 'Include dummy data',
|
|
30
|
+
default: false
|
|
31
|
+
})
|
|
32
|
+
.option('config', {
|
|
33
|
+
alias: 'c',
|
|
34
|
+
type: 'string',
|
|
35
|
+
description: 'Path to seeder configuration file',
|
|
36
|
+
demandOption: true
|
|
37
|
+
})
|
|
38
|
+
.help()
|
|
39
|
+
.example('nest-seed -c ./seeder.config.ts', 'Run all seeders')
|
|
40
|
+
.example('nest-seed -c ./seeder.config.ts --refresh', 'Drop and reseed all data')
|
|
41
|
+
.example('nest-seed -c ./seeder.config.ts --name UserSeeder', 'Run specific seeder')
|
|
42
|
+
.parseAsync();
|
|
43
|
+
return {
|
|
44
|
+
refresh: argv.refresh,
|
|
45
|
+
name: argv.name,
|
|
46
|
+
dummyData: argv.dummyData,
|
|
47
|
+
config: argv.config,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function setupTsNode() {
|
|
51
|
+
try {
|
|
52
|
+
// Register ts-node for TypeScript support
|
|
53
|
+
require('ts-node').register({
|
|
54
|
+
transpileOnly: true,
|
|
55
|
+
compilerOptions: {
|
|
56
|
+
module: 'commonjs',
|
|
57
|
+
experimentalDecorators: true,
|
|
58
|
+
emitDecoratorMetadata: true,
|
|
59
|
+
esModuleInterop: true,
|
|
60
|
+
allowSyntheticDefaultImports: true,
|
|
61
|
+
skipLibCheck: true,
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error('Failed to setup TypeScript support. Make sure ts-node is installed:');
|
|
67
|
+
console.error('npm install -D ts-node typescript');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function loadSeederConfig(configPath) {
|
|
72
|
+
try {
|
|
73
|
+
// Resolve the config path relative to current working directory
|
|
74
|
+
const resolvedPath = path.resolve(process.cwd(), configPath);
|
|
75
|
+
// Check if file exists
|
|
76
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
77
|
+
throw new Error(`Configuration file not found: ${resolvedPath}`);
|
|
78
|
+
}
|
|
79
|
+
// Setup TypeScript support if needed
|
|
80
|
+
if (configPath.endsWith('.ts')) {
|
|
81
|
+
setupTsNode();
|
|
82
|
+
}
|
|
83
|
+
// Clear require cache to ensure fresh import
|
|
84
|
+
delete require.cache[resolvedPath];
|
|
85
|
+
// Import the configuration
|
|
86
|
+
const configModule = await Promise.resolve(`${resolvedPath}`).then(s => tslib_1.__importStar(require(s)));
|
|
87
|
+
const config = configModule.default || configModule;
|
|
88
|
+
if (!config) {
|
|
89
|
+
throw new Error('Configuration file must export a default configuration object');
|
|
90
|
+
}
|
|
91
|
+
return config;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error('Error loading seeder configuration:');
|
|
95
|
+
console.error(error.message);
|
|
96
|
+
console.error('\nMake sure your configuration file:');
|
|
97
|
+
console.error('1. Exists at the specified path');
|
|
98
|
+
console.error('2. Exports a default configuration object');
|
|
99
|
+
console.error('3. Has proper TypeScript setup if using .ts files');
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function runSeeder() {
|
|
104
|
+
try {
|
|
105
|
+
const args = await parseArguments();
|
|
106
|
+
console.log('🌱 Starting NestJS Seeder...');
|
|
107
|
+
console.log(`📁 Loading configuration from: ${args.config}`);
|
|
108
|
+
// Load the seeder configuration from specified path
|
|
109
|
+
const seederConfig = await loadSeederConfig(args.config);
|
|
110
|
+
const cliOptions = {
|
|
111
|
+
refresh: args.refresh,
|
|
112
|
+
name: args.name,
|
|
113
|
+
dummyData: args.dummyData,
|
|
114
|
+
};
|
|
115
|
+
if (args.refresh) {
|
|
116
|
+
console.log('🔄 Refresh mode: Will drop existing data before seeding');
|
|
117
|
+
}
|
|
118
|
+
if (args.name && args.name.length > 0) {
|
|
119
|
+
console.log(`🎯 Running specific seeders: ${args.name.join(', ')}`);
|
|
120
|
+
}
|
|
121
|
+
if (args.dummyData) {
|
|
122
|
+
console.log('🎲 Dummy data mode enabled');
|
|
123
|
+
}
|
|
124
|
+
const app = await core_1.NestFactory.createApplicationContext(seeder_module_1.SeederModule.register({
|
|
125
|
+
...seederConfig,
|
|
126
|
+
...cliOptions,
|
|
127
|
+
}));
|
|
128
|
+
const seedersService = app.get(seeder_service_1.SeederService);
|
|
129
|
+
await seedersService.run();
|
|
130
|
+
await app.close();
|
|
131
|
+
console.log('✅ Seeding completed successfully!');
|
|
132
|
+
process.exit(0);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
console.error('❌ Error running seeder:');
|
|
136
|
+
console.error(error.message);
|
|
137
|
+
if (error.stack && process.env.NODE_ENV === 'development') {
|
|
138
|
+
console.error('\nStack trace:');
|
|
139
|
+
console.error(error.stack);
|
|
140
|
+
}
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const seeder = (options) => {
|
|
145
|
+
return {
|
|
146
|
+
async run(extraOptions) {
|
|
147
|
+
const cliOptions = {};
|
|
148
|
+
const argv = (0, yargs_1.default)(process.argv).argv;
|
|
149
|
+
if (argv.r || argv.refresh) {
|
|
150
|
+
cliOptions.refresh = true;
|
|
151
|
+
}
|
|
152
|
+
if (argv.n || argv.name) {
|
|
153
|
+
cliOptions.name = argv.n || argv.name;
|
|
154
|
+
}
|
|
155
|
+
if (argv.d || argv.dummyData) {
|
|
156
|
+
cliOptions.dummyData = argv.d || argv.dummyData;
|
|
157
|
+
}
|
|
158
|
+
extraOptions = Object.assign(extraOptions, cliOptions);
|
|
159
|
+
const app = await core_1.NestFactory.createApplicationContext(seeder_module_1.SeederModule.register({
|
|
160
|
+
...options,
|
|
161
|
+
...extraOptions,
|
|
162
|
+
}));
|
|
163
|
+
const seedersService = app.get(seeder_service_1.SeederService);
|
|
164
|
+
await seedersService.run();
|
|
165
|
+
await app.close();
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
exports.seeder = seeder;
|
|
170
|
+
// Only run if this file is executed directly
|
|
171
|
+
if (require.main === module) {
|
|
172
|
+
runSeeder();
|
|
173
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/seeder/seeder"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/seeder/seeder.interface"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/seeder/seeder.module"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/seeder/seeder.service"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lib/factory/data.factory"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./lib/decorators/factory.decorator"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./lib/interfaces/seeder-options-factory.interface"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./lib/interfaces/seeder-module-async-options.interface"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Factory = Factory;
|
|
4
|
+
const factory_metadata_storage_1 = require("../storages/factory.metadata.storage");
|
|
5
|
+
function Factory(generator, dependsOn) {
|
|
6
|
+
return (target, propertyKey) => {
|
|
7
|
+
factory_metadata_storage_1.FactoryMetadataStorage.addPropertyMetadata({
|
|
8
|
+
target: target.constructor,
|
|
9
|
+
propertyKey: propertyKey,
|
|
10
|
+
arg: {
|
|
11
|
+
generator,
|
|
12
|
+
dependsOn,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataFactory = void 0;
|
|
4
|
+
const faker_1 = require("@faker-js/faker");
|
|
5
|
+
const factory_metadata_storage_1 = require("../storages/factory.metadata.storage");
|
|
6
|
+
class DataFactory {
|
|
7
|
+
static createForClass(target) {
|
|
8
|
+
if (!target) {
|
|
9
|
+
throw new Error(`Target class "${target}" passed in to the "TemplateFactory#createForClass()" method is "undefined".`);
|
|
10
|
+
}
|
|
11
|
+
const properties = factory_metadata_storage_1.FactoryMetadataStorage.getPropertyMetadatasByTarget(target);
|
|
12
|
+
return {
|
|
13
|
+
generate: (count, values = {}) => {
|
|
14
|
+
const ret = [];
|
|
15
|
+
for (let i = 0; i < count; i++) {
|
|
16
|
+
ret.push(this.generate(properties, values));
|
|
17
|
+
}
|
|
18
|
+
return ret;
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
static generate(properties, values) {
|
|
23
|
+
const ctx = { ...values };
|
|
24
|
+
return properties.reduce((result, property) => {
|
|
25
|
+
const propertyKey = property.propertyKey;
|
|
26
|
+
const { generator, dependsOn } = property.arg;
|
|
27
|
+
// Skip if the value is already generated in the context (ctx)
|
|
28
|
+
if (ctx[propertyKey] !== undefined) {
|
|
29
|
+
return {
|
|
30
|
+
[propertyKey]: ctx[propertyKey],
|
|
31
|
+
...result,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// If the property has dependencies, ensure they are generated first
|
|
35
|
+
if (Array.isArray(dependsOn)) {
|
|
36
|
+
dependsOn.forEach((dependency) => {
|
|
37
|
+
if (ctx[dependency] === undefined) {
|
|
38
|
+
// Find the dependent property and generate it if it hasn't been generated yet
|
|
39
|
+
const dependentProperty = properties.find((p) => p.propertyKey === dependency);
|
|
40
|
+
if (dependentProperty) {
|
|
41
|
+
ctx[dependency] = typeof dependentProperty.arg.generator ===
|
|
42
|
+
'function' ?
|
|
43
|
+
dependentProperty.arg.generator(faker_1.faker, ctx) :
|
|
44
|
+
dependentProperty.arg;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// Generate the current field
|
|
50
|
+
ctx[propertyKey] = typeof generator === 'function' ?
|
|
51
|
+
generator(faker_1.faker, ctx) :
|
|
52
|
+
generator;
|
|
53
|
+
return {
|
|
54
|
+
[propertyKey]: ctx[propertyKey],
|
|
55
|
+
...result,
|
|
56
|
+
};
|
|
57
|
+
}, {});
|
|
58
|
+
// return properties.reduce(
|
|
59
|
+
// (r, p) => ({
|
|
60
|
+
// [p.propertyKey]: ctx[p.propertyKey] = typeof p.arg === 'function' ? p.arg(faker, ctx) : p.arg,
|
|
61
|
+
// ...r,
|
|
62
|
+
// }),
|
|
63
|
+
// {},
|
|
64
|
+
// );
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.DataFactory = DataFactory;
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./seeder/seeder"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./seeder/seeder.interface"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./factory/data.factory"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./decorators/factory.decorator"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.seeder = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@nestjs/core");
|
|
6
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
7
|
+
const seeder_module_1 = require("./seeder.module");
|
|
8
|
+
const seeder_service_1 = require("./seeder.service");
|
|
9
|
+
async function bootstrap(options) {
|
|
10
|
+
const app = await core_1.NestFactory.createApplicationContext(seeder_module_1.SeederModule.register(options));
|
|
11
|
+
const seedersService = app.get(seeder_service_1.SeederService);
|
|
12
|
+
await seedersService.run();
|
|
13
|
+
await app.close();
|
|
14
|
+
}
|
|
15
|
+
const seeder = (options) => {
|
|
16
|
+
return {
|
|
17
|
+
run(extraOptions) {
|
|
18
|
+
const cliOptions = {};
|
|
19
|
+
const argv = (0, yargs_1.default)(process.argv).argv;
|
|
20
|
+
if (argv.r || argv.refresh) {
|
|
21
|
+
cliOptions.refresh = true;
|
|
22
|
+
}
|
|
23
|
+
if (argv.n || argv.name) {
|
|
24
|
+
cliOptions.name = argv.n || argv.name;
|
|
25
|
+
}
|
|
26
|
+
if (argv.d || argv.dummyData) {
|
|
27
|
+
cliOptions.dummyData = argv.d || argv.dummyData;
|
|
28
|
+
}
|
|
29
|
+
extraOptions = Object.assign(extraOptions, cliOptions);
|
|
30
|
+
return bootstrap({
|
|
31
|
+
...options,
|
|
32
|
+
...extraOptions,
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.seeder = seeder;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var SeederModule_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SeederModule = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const common_1 = require("@nestjs/common");
|
|
7
|
+
const seeder_service_1 = require("./seeder.service");
|
|
8
|
+
const SEEDER_MODULE_OPTIONS = 'SEEDER_MODULE_OPTIONS';
|
|
9
|
+
let SeederModule = SeederModule_1 = class SeederModule {
|
|
10
|
+
static register(options) {
|
|
11
|
+
return {
|
|
12
|
+
module: SeederModule_1,
|
|
13
|
+
imports: options.imports || [],
|
|
14
|
+
providers: [
|
|
15
|
+
...(options.providers || []),
|
|
16
|
+
...options.seeders || [],
|
|
17
|
+
{
|
|
18
|
+
provide: seeder_service_1.SeederService,
|
|
19
|
+
useFactory: (...seeders) => {
|
|
20
|
+
return new seeder_service_1.SeederService(seeders, options);
|
|
21
|
+
},
|
|
22
|
+
inject: (options.seeders || []),
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static forRootAsync(options) {
|
|
28
|
+
return {
|
|
29
|
+
module: SeederModule_1,
|
|
30
|
+
global: options.isGlobal,
|
|
31
|
+
imports: options.imports || [],
|
|
32
|
+
providers: [
|
|
33
|
+
...this.createAsyncProviders(options),
|
|
34
|
+
{
|
|
35
|
+
provide: seeder_service_1.SeederService,
|
|
36
|
+
useFactory: async (seederOptions, ...seeders) => {
|
|
37
|
+
return new seeder_service_1.SeederService(seeders, seederOptions);
|
|
38
|
+
},
|
|
39
|
+
inject: [SEEDER_MODULE_OPTIONS, ...(options.inject || [])],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
static createAsyncProviders(options) {
|
|
45
|
+
if (options.useExisting || options.useFactory) {
|
|
46
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
47
|
+
}
|
|
48
|
+
return [
|
|
49
|
+
this.createAsyncOptionsProvider(options),
|
|
50
|
+
{
|
|
51
|
+
provide: options.useClass,
|
|
52
|
+
useClass: options.useClass,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
static createAsyncOptionsProvider(options) {
|
|
57
|
+
if (options.useFactory) {
|
|
58
|
+
return {
|
|
59
|
+
provide: SEEDER_MODULE_OPTIONS,
|
|
60
|
+
useFactory: options.useFactory,
|
|
61
|
+
inject: options.inject || [],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
provide: SEEDER_MODULE_OPTIONS,
|
|
66
|
+
useFactory: async (optionsFactory) => await optionsFactory.createSeederOptions(),
|
|
67
|
+
inject: [options.useExisting || options.useClass],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.SeederModule = SeederModule;
|
|
72
|
+
exports.SeederModule = SeederModule = SeederModule_1 = tslib_1.__decorate([
|
|
73
|
+
(0, common_1.Module)({})
|
|
74
|
+
], SeederModule);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SeederService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
let SeederService = class SeederService {
|
|
7
|
+
constructor(seeders, options = {}) {
|
|
8
|
+
this.seeders = seeders;
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
async run() {
|
|
12
|
+
if (this.options.refresh) {
|
|
13
|
+
await this.drop();
|
|
14
|
+
await this.seed();
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
await this.seed();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async seed() {
|
|
21
|
+
// Don't use `Promise.all` during insertion.
|
|
22
|
+
// `Promise.all` will run all promises in parallel which is not what we want.
|
|
23
|
+
const seeders = this.getSeederToRun();
|
|
24
|
+
for (const seeder of seeders) {
|
|
25
|
+
console.info(`${seeder.constructor.name} start`);
|
|
26
|
+
await seeder.seed(this.options);
|
|
27
|
+
console.info(`${seeder.constructor.name} completed`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async drop() {
|
|
31
|
+
const seeders = this.getSeederToRun();
|
|
32
|
+
for (const seeder of seeders) {
|
|
33
|
+
console.info(`Truncate ${seeder.constructor.name} start`);
|
|
34
|
+
await seeder.drop(this.options);
|
|
35
|
+
console.info(`Truncate ${seeder.constructor.name} completed`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
getSeederToRun() {
|
|
39
|
+
if (this.options?.name && typeof this.options.name === 'string') {
|
|
40
|
+
this.options.name = [this.options.name];
|
|
41
|
+
}
|
|
42
|
+
if (this.options.name) {
|
|
43
|
+
const nameArray = Array.isArray(this.options.name) ? this.options.name : [this.options.name];
|
|
44
|
+
const seeders = this.seeders.filter((s) => nameArray.indexOf(s.constructor.name) >= 0);
|
|
45
|
+
if (seeders?.length === 0) {
|
|
46
|
+
const allNames = this.seeders.map((s) => s.constructor.name);
|
|
47
|
+
console.warn('\x1b[43m', 'Warning : No Seeder Found. Available Name are', '\x1b[0m', '\x1b[32m', '\n', `${allNames.join('\n')}`, '\x1b[0m');
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
return seeders;
|
|
51
|
+
}
|
|
52
|
+
if (this.seeders?.length === 0) {
|
|
53
|
+
console.info('\x1b[43m', 'Warning : No seeders to run. Make sure you have passed default seeder', '\x1b[0m');
|
|
54
|
+
}
|
|
55
|
+
return this.seeders;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.SeederService = SeederService;
|
|
59
|
+
exports.SeederService = SeederService = tslib_1.__decorate([
|
|
60
|
+
(0, common_1.Injectable)(),
|
|
61
|
+
tslib_1.__metadata("design:paramtypes", [Array, Object])
|
|
62
|
+
], SeederService);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FactoryMetadataStorage = exports.FactoryMetadataStorageHost = void 0;
|
|
4
|
+
class FactoryMetadataStorageHost {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.properties = [];
|
|
7
|
+
}
|
|
8
|
+
addPropertyMetadata(metadata) {
|
|
9
|
+
this.properties.push(metadata);
|
|
10
|
+
}
|
|
11
|
+
getPropertyMetadatasByTarget(target) {
|
|
12
|
+
return this.properties.filter((property) => property.target === target);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.FactoryMetadataStorageHost = FactoryMetadataStorageHost;
|
|
16
|
+
const globalRef = global;
|
|
17
|
+
exports.FactoryMetadataStorage = globalRef.FactoryMetadataStorage ||
|
|
18
|
+
(globalRef.FactoryMetadataStorage = new FactoryMetadataStorageHost());
|