@mikro-orm/core 6.3.14-dev.66 → 6.3.14-dev.67
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/MikroORM.js
CHANGED
|
@@ -30,7 +30,7 @@ class MikroORM {
|
|
|
30
30
|
const env = utils_1.ConfigurationLoader.loadEnvironmentVars();
|
|
31
31
|
if (!options) {
|
|
32
32
|
const configPathFromArg = utils_1.ConfigurationLoader.configPathsFromArg();
|
|
33
|
-
const config = (await utils_1.ConfigurationLoader.getConfiguration(configPathFromArg ?? utils_1.ConfigurationLoader.getConfigPaths()));
|
|
33
|
+
const config = (await utils_1.ConfigurationLoader.getConfiguration(process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default', configPathFromArg ?? utils_1.ConfigurationLoader.getConfigPaths()));
|
|
34
34
|
options = config.getAll();
|
|
35
35
|
if (configPathFromArg) {
|
|
36
36
|
config.getLogger().warn('deprecated', 'Path for config file was inferred from the command line arguments. Instead, you should set the MIKRO_ORM_CLI_CONFIG environment variable to specify the path, or if you really must use the command line arguments, import the config manually based on them, and pass it to init.', { label: 'D0001' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.3.14-dev.
|
|
3
|
+
"version": "6.3.14-dev.67",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.2.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.3.14-dev.
|
|
67
|
+
"mikro-orm": "6.3.14-dev.67",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -6,7 +6,7 @@ import { Configuration, type Options } from './Configuration';
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
export declare class ConfigurationLoader {
|
|
9
|
-
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(paths: string[], options?: Partial<Options
|
|
9
|
+
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(contextName: string | undefined, paths: string[], options?: Partial<Options>): Promise<Configuration<D, EM>>;
|
|
10
10
|
static getPackageConfig(basePath?: string): Dictionary;
|
|
11
11
|
static getSettings(): Settings;
|
|
12
12
|
static configPathsFromArg(): string[] | undefined;
|
|
@@ -16,27 +16,69 @@ const Utils_1 = require("./Utils");
|
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
18
|
class ConfigurationLoader {
|
|
19
|
-
static async getConfiguration(paths, options = {}
|
|
19
|
+
static async getConfiguration(contextName = 'default', paths, options = {}) {
|
|
20
20
|
const env = this.loadEnvironmentVars();
|
|
21
|
+
const configFinder = (cfg) => {
|
|
22
|
+
return typeof cfg === 'object' && cfg !== null && ('contextName' in cfg ? cfg.contextName === contextName : (contextName === 'default'));
|
|
23
|
+
};
|
|
24
|
+
const isValidConfigFactoryResult = (cfg) => {
|
|
25
|
+
return typeof cfg === 'object' && cfg !== null && (!('contextName' in cfg) || cfg.contextName === contextName);
|
|
26
|
+
};
|
|
21
27
|
for (let path of paths) {
|
|
22
28
|
path = Utils_1.Utils.absolutePath(path);
|
|
23
29
|
path = Utils_1.Utils.normalizePath(path);
|
|
24
30
|
if ((0, fs_extra_1.pathExistsSync)(path)) {
|
|
25
31
|
const config = await Utils_1.Utils.dynamicImport(path);
|
|
26
32
|
/* istanbul ignore next */
|
|
27
|
-
let tmp = config.default ?? config;
|
|
28
|
-
if (tmp
|
|
29
|
-
|
|
33
|
+
let tmp = await (config.default ?? config);
|
|
34
|
+
if (Array.isArray(tmp)) {
|
|
35
|
+
const tmpFirstIndex = tmp.findIndex(configFinder);
|
|
36
|
+
if (tmpFirstIndex === -1) {
|
|
37
|
+
// Static config not found. Try factory functions
|
|
38
|
+
let configCandidate;
|
|
39
|
+
for (let i = 0, l = tmp.length; i < l; ++i) {
|
|
40
|
+
const f = tmp[i];
|
|
41
|
+
if (typeof f !== 'function') {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
configCandidate = await f(contextName);
|
|
45
|
+
if (!isValidConfigFactoryResult(configCandidate)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
tmp = configCandidate;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(tmp)) {
|
|
52
|
+
throw new Error(`MikroORM config '${contextName}' was not found within the config file '${path}'. Either add a config with this name to the array, or add a function that when given this name will return a configuration object without a name, or with name set to this name.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const tmpLastIndex = tmp.findLastIndex(configFinder);
|
|
57
|
+
if (tmpLastIndex !== tmpFirstIndex) {
|
|
58
|
+
throw new Error(`MikroORM config '${contextName}' is not unique within the array exported by '${path}' (first occurrence index: ${tmpFirstIndex}; last occurrence index: ${tmpLastIndex})`);
|
|
59
|
+
}
|
|
60
|
+
tmp = tmp[tmpFirstIndex];
|
|
61
|
+
}
|
|
30
62
|
}
|
|
31
|
-
|
|
32
|
-
tmp
|
|
63
|
+
else {
|
|
64
|
+
if (tmp instanceof Function) {
|
|
65
|
+
tmp = await tmp(contextName);
|
|
66
|
+
if (!isValidConfigFactoryResult(tmp)) {
|
|
67
|
+
throw new Error(`MikroORM config '${contextName}' was not what the function exported from '${path}' provided. Ensure it returns a config object with no name, or name matching the requested one.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if (!configFinder(tmp)) {
|
|
72
|
+
throw new Error(`MikroORM config '${contextName}' was not what the default export from '${path}' provided.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
33
75
|
}
|
|
34
76
|
const esmConfigOptions = this.isESM() ? { entityGenerator: { esmImport: true } } : {};
|
|
35
|
-
return new Configuration_1.Configuration(Utils_1.Utils.mergeConfig({}, esmConfigOptions, tmp, options, env)
|
|
77
|
+
return new Configuration_1.Configuration(Utils_1.Utils.mergeConfig({}, esmConfigOptions, tmp, options, env));
|
|
36
78
|
}
|
|
37
79
|
}
|
|
38
80
|
if (Utils_1.Utils.hasObjectKeys(env)) {
|
|
39
|
-
return new Configuration_1.Configuration(Utils_1.Utils.mergeConfig({}, options, env)
|
|
81
|
+
return new Configuration_1.Configuration(Utils_1.Utils.mergeConfig({ contextName }, options, env));
|
|
40
82
|
}
|
|
41
83
|
throw new Error(`MikroORM config file not found in ['${paths.join(`', '`)}']`);
|
|
42
84
|
}
|