MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / getConfiguration

Method getConfiguration

packages/cli/src/CLIHelper.ts:31–70  ·  view source on GitHub ↗

* Gets a named configuration * * @param contextName Load a config with the given `contextName` value. Used when config file exports array or factory function. Setting it to "default" matches also config objects without `contextName` set. * @param paths Array of possible paths for a configur

(contextName?: string, paths?: string[], options: Partial<Options<D>> = {})

Source from the content-addressed store, hash-verified

29 * @param options Additional options to augment the final configuration with.
30 */
31 static async getConfiguration<
32 D extends IDatabaseDriver = IDatabaseDriver,
33 EM extends D[typeof EntityManagerType] & EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>,
34 >(contextName?: string, paths?: string[], options: Partial<Options<D>> = {}): Promise<Configuration<D, EM>> {
35 this.commonJSCompat(options);
36 paths ??= await this.getConfigPaths();
37 const deps = fs.getORMPackages();
38
39 if (!deps.has('@mikro-orm/cli') && !process.env.MIKRO_ORM_ALLOW_GLOBAL_CLI && !process.versions.deno) {
40 throw new Error('@mikro-orm/cli needs to be installed as a local dependency!');
41 }
42
43 contextName ??= process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default';
44 const env = await this.loadEnvironmentVars();
45
46 const result = await this.getConfigFile(paths);
47 if (!result[0]) {
48 if (Utils.hasObjectKeys(env)) {
49 const merged = Utils.mergeConfig(
50 { contextName },
51 options.preferEnvVars ? options : env,
52 options.preferEnvVars ? env : options,
53 );
54 await loadOptionalDependencies(merged);
55 return new Configuration(merged);
56 }
57 throw new Error(`MikroORM config file not found in ['${paths.join(`', '`)}']`);
58 }
59
60 const [path, configExports] = result;
61 const tmp = await searchConfiguration(configExports, contextName, path);
62
63 const esmConfigOptions = this.isESM() ? { entityGenerator: { esmImport: true } } : {};
64 await loadOptionalDependencies(tmp);
65
66 const preferEnvVars = options.preferEnvVars ?? tmp.preferEnvVars;
67 return new Configuration(
68 Utils.mergeConfig({}, esmConfigOptions, tmp, preferEnvVars ? options : env, preferEnvVars ? env : options),
69 );
70 }
71
72 static commonJSCompat(options: Partial<Options>): void {
73 if (this.isESM()) {

Callers 5

handlerMethod · 0.45
handlerMethod · 0.45
handlerMethod · 0.45
handlerMethod · 0.45

Calls 12

commonJSCompatMethod · 0.95
getConfigPathsMethod · 0.95
loadEnvironmentVarsMethod · 0.95
getConfigFileMethod · 0.95
isESMMethod · 0.95
loadOptionalDependenciesFunction · 0.90
searchConfigurationFunction · 0.85
getORMPackagesMethod · 0.80
hasObjectKeysMethod · 0.80
mergeConfigMethod · 0.80
hasMethod · 0.65
joinMethod · 0.65

Tested by

no test coverage detected