* @internal
(...classNames: string[])
| 89 | * @internal |
| 90 | */ |
| 91 | async seedString(...classNames: string[]): Promise<void> { |
| 92 | if (this.#options.seedersList) { |
| 93 | const classMap = new Map<string, Constructor<Seeder>>(); |
| 94 | |
| 95 | for (const entry of this.#options.seedersList) { |
| 96 | if (typeof entry === 'function') { |
| 97 | classMap.set(entry.name, entry as Constructor<Seeder>); |
| 98 | } else { |
| 99 | classMap.set(entry.name, entry.class as Constructor<Seeder>); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | for (const className of classNames) { |
| 104 | const seederClass = classMap.get(className); |
| 105 | |
| 106 | if (!seederClass) { |
| 107 | throw new Error(`Seeder class ${className} not found in seedersList`); |
| 108 | } |
| 109 | |
| 110 | await this.seed(seederClass); |
| 111 | } |
| 112 | |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | await this.init(); |
| 117 | const { fs } = await import('@mikro-orm/core/fs-utils'); |
| 118 | const path = fs.normalizePath(this.#absolutePath, this.#options.glob!); |
| 119 | const files = fs.glob(path).sort(); |
| 120 | const classMap = new Map<string, Constructor<Seeder>>(); |
| 121 | |
| 122 | for (const filePath of files) { |
| 123 | const exports = await fs.dynamicImport(filePath); |
| 124 | |
| 125 | for (const name of Object.keys(exports)) { |
| 126 | classMap.set(name, exports[name]); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | for (const className of classNames) { |
| 131 | const seederClass = classMap.get(className); |
| 132 | |
| 133 | if (!seederClass) { |
| 134 | throw new Error(`Seeder class ${className} not found in ${fs.relativePath(path, process.cwd())}`); |
| 135 | } |
| 136 | |
| 137 | await this.seed(seederClass); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | async create(className: string): Promise<string> { |
| 142 | await this.init(); |
nothing calls this directly
no test coverage detected