@mikro-orm/core 7.0.0-dev.0 → 7.0.0-dev.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/EntityManager.d.ts +18 -13
- package/EntityManager.js +202 -202
- package/MikroORM.d.ts +7 -6
- package/MikroORM.js +33 -45
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +18 -26
- package/cache/GeneratedCacheAdapter.d.ts +2 -2
- package/cache/GeneratedCacheAdapter.js +1 -5
- package/cache/MemoryCacheAdapter.d.ts +1 -1
- package/cache/MemoryCacheAdapter.js +1 -5
- package/cache/NullCacheAdapter.d.ts +1 -1
- package/cache/NullCacheAdapter.js +1 -5
- package/cache/index.d.ts +5 -5
- package/cache/index.js +5 -21
- package/connections/Connection.d.ts +7 -7
- package/connections/Connection.js +8 -12
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/decorators/Check.d.ts +1 -1
- package/decorators/Check.js +5 -8
- package/decorators/CreateRequestContext.d.ts +1 -1
- package/decorators/CreateRequestContext.js +9 -13
- package/decorators/Embeddable.d.ts +1 -1
- package/decorators/Embeddable.js +3 -6
- package/decorators/Embedded.d.ts +1 -1
- package/decorators/Embedded.js +10 -12
- package/decorators/Entity.d.ts +2 -2
- package/decorators/Entity.js +5 -8
- package/decorators/Enum.d.ts +2 -2
- package/decorators/Enum.js +7 -10
- package/decorators/Filter.d.ts +1 -1
- package/decorators/Filter.js +3 -6
- package/decorators/Formula.d.ts +2 -2
- package/decorators/Formula.js +7 -10
- package/decorators/Indexed.d.ts +2 -2
- package/decorators/Indexed.js +6 -10
- package/decorators/ManyToMany.d.ts +3 -3
- package/decorators/ManyToMany.js +10 -12
- package/decorators/ManyToOne.d.ts +3 -3
- package/decorators/ManyToOne.js +10 -12
- package/decorators/OneToMany.d.ts +3 -3
- package/decorators/OneToMany.js +11 -14
- package/decorators/OneToOne.d.ts +4 -4
- package/decorators/OneToOne.js +4 -7
- package/decorators/PrimaryKey.d.ts +2 -2
- package/decorators/PrimaryKey.js +10 -13
- package/decorators/Property.d.ts +5 -5
- package/decorators/Property.js +10 -12
- package/decorators/Transactional.d.ts +2 -2
- package/decorators/Transactional.js +7 -10
- package/decorators/hooks.js +23 -35
- package/decorators/index.d.ts +17 -17
- package/decorators/index.js +17 -36
- package/drivers/DatabaseDriver.d.ts +13 -12
- package/drivers/DatabaseDriver.js +60 -64
- package/drivers/IDatabaseDriver.d.ts +12 -12
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/ArrayCollection.d.ts +2 -2
- package/entity/ArrayCollection.js +29 -33
- package/entity/BaseEntity.d.ts +6 -6
- package/entity/BaseEntity.js +17 -21
- package/entity/Collection.d.ts +6 -6
- package/entity/Collection.js +40 -44
- package/entity/EntityAssigner.d.ts +2 -2
- package/entity/EntityAssigner.js +58 -63
- package/entity/EntityFactory.d.ts +3 -3
- package/entity/EntityFactory.js +58 -62
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +41 -45
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +5 -5
- package/entity/EntityLoader.js +92 -96
- package/entity/EntityRepository.d.ts +7 -7
- package/entity/EntityRepository.js +7 -11
- package/entity/EntityValidator.d.ts +1 -1
- package/entity/EntityValidator.js +25 -29
- package/entity/Reference.d.ts +2 -2
- package/entity/Reference.js +35 -42
- package/entity/WrappedEntity.d.ts +12 -12
- package/entity/WrappedEntity.js +23 -27
- package/entity/index.d.ts +13 -13
- package/entity/index.js +13 -29
- package/entity/utils.d.ts +1 -1
- package/entity/utils.js +9 -12
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +3 -3
- package/enums.js +37 -41
- package/errors.d.ts +1 -1
- package/errors.js +15 -24
- package/events/EventManager.d.ts +3 -3
- package/events/EventManager.js +8 -12
- package/events/EventSubscriber.d.ts +5 -4
- package/events/EventSubscriber.js +1 -2
- package/events/TransactionEventBroadcaster.d.ts +3 -3
- package/events/TransactionEventBroadcaster.js +1 -5
- package/events/index.d.ts +3 -3
- package/events/index.js +3 -19
- package/exceptions.js +18 -39
- package/hydration/Hydrator.d.ts +5 -5
- package/hydration/Hydrator.js +3 -6
- package/hydration/ObjectHydrator.d.ts +3 -3
- package/hydration/ObjectHydrator.js +25 -28
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +21 -46
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +9 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +2 -2
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +4 -4
- package/logging/index.js +4 -20
- package/metadata/EntitySchema.d.ts +12 -4
- package/metadata/EntitySchema.js +41 -45
- package/metadata/MetadataDiscovery.d.ts +7 -7
- package/metadata/MetadataDiscovery.js +174 -177
- package/metadata/MetadataProvider.d.ts +2 -2
- package/metadata/MetadataProvider.js +4 -7
- package/metadata/MetadataStorage.d.ts +2 -2
- package/metadata/MetadataStorage.js +15 -19
- package/metadata/MetadataValidator.d.ts +4 -4
- package/metadata/MetadataValidator.js +49 -53
- package/metadata/ReflectMetadataProvider.d.ts +2 -2
- package/metadata/ReflectMetadataProvider.js +8 -12
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/naming-strategy/AbstractNamingStrategy.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +4 -8
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
- package/naming-strategy/MongoNamingStrategy.js +2 -6
- package/naming-strategy/NamingStrategy.d.ts +1 -1
- package/naming-strategy/NamingStrategy.js +1 -2
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
- package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
- package/naming-strategy/index.d.ts +5 -5
- package/naming-strategy/index.js +5 -21
- package/package.json +5 -14
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +10 -10
- package/platforms/Platform.js +57 -61
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +2 -2
- package/serialization/EntitySerializer.js +36 -41
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +27 -31
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +10 -14
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +7 -11
- package/types/BigIntType.d.ts +3 -3
- package/types/BigIntType.js +3 -6
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +2 -8
- package/types/BooleanType.d.ts +3 -3
- package/types/BooleanType.js +2 -6
- package/types/CharacterType.d.ts +3 -3
- package/types/CharacterType.js +2 -6
- package/types/DateTimeType.d.ts +3 -3
- package/types/DateTimeType.js +2 -6
- package/types/DateType.d.ts +3 -3
- package/types/DateType.js +2 -6
- package/types/DecimalType.d.ts +3 -3
- package/types/DecimalType.js +4 -7
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +3 -6
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +5 -10
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +2 -6
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +2 -6
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +2 -6
- package/types/IntervalType.d.ts +3 -3
- package/types/IntervalType.js +2 -6
- package/types/JsonType.d.ts +3 -3
- package/types/JsonType.js +2 -6
- package/types/MediumIntType.d.ts +3 -3
- package/types/MediumIntType.js +2 -6
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +2 -6
- package/types/StringType.d.ts +3 -3
- package/types/StringType.js +2 -6
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +2 -6
- package/types/TimeType.d.ts +3 -3
- package/types/TimeType.js +4 -8
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +3 -6
- package/types/Type.d.ts +2 -2
- package/types/Type.js +5 -9
- package/types/Uint8ArrayType.d.ts +3 -3
- package/types/Uint8ArrayType.js +3 -9
- package/types/UnknownType.d.ts +3 -3
- package/types/UnknownType.js +2 -6
- package/types/UuidType.d.ts +3 -3
- package/types/UuidType.js +2 -6
- package/types/index.d.ts +25 -25
- package/types/index.js +52 -79
- package/typings.d.ts +22 -20
- package/typings.js +34 -38
- package/unit-of-work/ChangeSet.d.ts +1 -1
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -7
- package/unit-of-work/ChangeSetComputer.js +26 -30
- package/unit-of-work/ChangeSetPersister.d.ts +7 -6
- package/unit-of-work/ChangeSetPersister.js +44 -47
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
- package/unit-of-work/CommitOrderCalculator.js +6 -10
- package/unit-of-work/IdentityMap.d.ts +1 -1
- package/unit-of-work/IdentityMap.js +1 -5
- package/unit-of-work/UnitOfWork.d.ts +8 -7
- package/unit-of-work/UnitOfWork.js +171 -172
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +6 -6
- package/utils/AbstractSchemaGenerator.js +7 -11
- package/utils/Configuration.d.ts +26 -27
- package/utils/Configuration.js +50 -55
- package/utils/ConfigurationLoader.d.ts +9 -8
- package/utils/ConfigurationLoader.js +71 -86
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +22 -25
- package/utils/DataloaderUtils.d.ts +4 -4
- package/utils/DataloaderUtils.js +12 -16
- package/utils/EntityComparator.d.ts +2 -2
- package/utils/EntityComparator.js +48 -52
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +3 -3
- package/utils/QueryHelper.js +47 -51
- package/utils/RawQueryFragment.d.ts +1 -1
- package/utils/RawQueryFragment.js +16 -24
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +3 -7
- package/utils/TransactionContext.d.ts +1 -1
- package/utils/TransactionContext.js +4 -8
- package/utils/Utils.d.ts +16 -12
- package/utils/Utils.js +89 -93
- package/utils/clone.js +8 -11
- package/utils/index.d.ts +13 -13
- package/utils/index.js +13 -29
- package/utils/resolveContextProvider.d.ts +3 -3
- package/utils/resolveContextProvider.js +9 -12
- package/utils/upsert-utils.d.ts +3 -3
- package/utils/upsert-utils.js +5 -9
- package/index.mjs +0 -199
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const fs_extra_1 = require("fs-extra");
|
|
9
|
-
const node_os_1 = require("node:os");
|
|
10
|
-
const node_path_1 = require("node:path");
|
|
11
|
-
const node_url_1 = require("node:url");
|
|
12
|
-
const colors_1 = require("../logging/colors");
|
|
13
|
-
const Configuration_1 = require("./Configuration");
|
|
14
|
-
const Utils_1 = require("./Utils");
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import { platform } from 'node:os';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { colors } from '../logging/colors.js';
|
|
6
|
+
import { Configuration } from './Configuration.js';
|
|
7
|
+
import { Utils } from './Utils.js';
|
|
15
8
|
/**
|
|
16
9
|
* @internal
|
|
17
10
|
*/
|
|
18
|
-
class ConfigurationLoader {
|
|
11
|
+
export class ConfigurationLoader {
|
|
19
12
|
static async getConfiguration(contextName = 'default', paths = ConfigurationLoader.getConfigPaths(), options = {}) {
|
|
20
13
|
// Backwards compatibility layer
|
|
21
14
|
if (typeof contextName === 'boolean' || !Array.isArray(paths)) {
|
|
@@ -26,22 +19,22 @@ class ConfigurationLoader {
|
|
|
26
19
|
const config = contextName
|
|
27
20
|
? (await ConfigurationLoader.getConfiguration(process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default', configPaths, Array.isArray(paths) ? {} : paths))
|
|
28
21
|
: await (async () => {
|
|
29
|
-
const env = this.loadEnvironmentVars();
|
|
22
|
+
const env = await this.loadEnvironmentVars();
|
|
30
23
|
const [path, tmp] = await this.getConfigFile(configPaths);
|
|
31
24
|
if (!path) {
|
|
32
|
-
if (
|
|
33
|
-
return new
|
|
25
|
+
if (Utils.hasObjectKeys(env)) {
|
|
26
|
+
return new Configuration(Utils.mergeConfig({}, options, env), false);
|
|
34
27
|
}
|
|
35
28
|
throw new Error(`MikroORM config file not found in ['${configPaths.join(`', '`)}']`);
|
|
36
29
|
}
|
|
37
|
-
return new
|
|
30
|
+
return new Configuration(Utils.mergeConfig(tmp, options, env), false);
|
|
38
31
|
})();
|
|
39
32
|
if (configPathFromArg) {
|
|
40
33
|
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' });
|
|
41
34
|
}
|
|
42
35
|
return config;
|
|
43
36
|
}
|
|
44
|
-
const env = this.loadEnvironmentVars();
|
|
37
|
+
const env = await this.loadEnvironmentVars();
|
|
45
38
|
const configFinder = (cfg) => {
|
|
46
39
|
return typeof cfg === 'object' && cfg !== null && ('contextName' in cfg ? cfg.contextName === contextName : (contextName === 'default'));
|
|
47
40
|
};
|
|
@@ -50,8 +43,8 @@ class ConfigurationLoader {
|
|
|
50
43
|
};
|
|
51
44
|
const result = await this.getConfigFile(paths);
|
|
52
45
|
if (!result[0]) {
|
|
53
|
-
if (
|
|
54
|
-
return new
|
|
46
|
+
if (Utils.hasObjectKeys(env)) {
|
|
47
|
+
return new Configuration(Utils.mergeConfig({ contextName }, options, env));
|
|
55
48
|
}
|
|
56
49
|
throw new Error(`MikroORM config file not found in ['${paths.join(`', '`)}']`);
|
|
57
50
|
}
|
|
@@ -100,31 +93,31 @@ class ConfigurationLoader {
|
|
|
100
93
|
}
|
|
101
94
|
}
|
|
102
95
|
const esmConfigOptions = this.isESM() ? { entityGenerator: { esmImport: true } } : {};
|
|
103
|
-
return new
|
|
96
|
+
return new Configuration(Utils.mergeConfig({}, esmConfigOptions, tmp, options, env));
|
|
104
97
|
}
|
|
105
98
|
static async getConfigFile(paths) {
|
|
106
99
|
for (let path of paths) {
|
|
107
|
-
path =
|
|
108
|
-
path =
|
|
109
|
-
if (
|
|
110
|
-
const config = await
|
|
111
|
-
/*
|
|
100
|
+
path = Utils.absolutePath(path);
|
|
101
|
+
path = Utils.normalizePath(path);
|
|
102
|
+
if (Utils.pathExistsSync(path)) {
|
|
103
|
+
const config = await Utils.dynamicImport(path);
|
|
104
|
+
/* v8 ignore next */
|
|
112
105
|
return [path, await (config.default ?? config)];
|
|
113
106
|
}
|
|
114
107
|
}
|
|
115
108
|
return [];
|
|
116
109
|
}
|
|
117
110
|
static getPackageConfig(basePath = process.cwd()) {
|
|
118
|
-
if (
|
|
119
|
-
/*
|
|
111
|
+
if (Utils.pathExistsSync(`${basePath}/package.json`)) {
|
|
112
|
+
/* v8 ignore next 5 */
|
|
120
113
|
try {
|
|
121
|
-
return
|
|
114
|
+
return Utils.readJSONSync(`${basePath}/package.json`);
|
|
122
115
|
}
|
|
123
116
|
catch {
|
|
124
117
|
return {};
|
|
125
118
|
}
|
|
126
119
|
}
|
|
127
|
-
const parentFolder =
|
|
120
|
+
const parentFolder = realpathSync(`${basePath}/..`);
|
|
128
121
|
// we reached the root folder
|
|
129
122
|
if (basePath === parentFolder) {
|
|
130
123
|
return {};
|
|
@@ -135,17 +128,17 @@ class ConfigurationLoader {
|
|
|
135
128
|
const config = ConfigurationLoader.getPackageConfig();
|
|
136
129
|
const settings = { ...config['mikro-orm'] };
|
|
137
130
|
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
138
|
-
settings.
|
|
131
|
+
settings.preferTs = process.env.MIKRO_ORM_CLI_PREFER_TS != null ? bool(process.env.MIKRO_ORM_CLI_PREFER_TS) : settings.preferTs;
|
|
139
132
|
settings.tsConfigPath = process.env.MIKRO_ORM_CLI_TS_CONFIG_PATH ?? settings.tsConfigPath;
|
|
140
133
|
settings.alwaysAllowTs = process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS != null ? bool(process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS) : settings.alwaysAllowTs;
|
|
141
134
|
settings.verbose = process.env.MIKRO_ORM_CLI_VERBOSE != null ? bool(process.env.MIKRO_ORM_CLI_VERBOSE) : settings.verbose;
|
|
142
135
|
if (process.env.MIKRO_ORM_CLI_CONFIG?.endsWith('.ts')) {
|
|
143
|
-
settings.
|
|
136
|
+
settings.preferTs = true;
|
|
144
137
|
}
|
|
145
138
|
return settings;
|
|
146
139
|
}
|
|
147
140
|
static configPathsFromArg() {
|
|
148
|
-
const options =
|
|
141
|
+
const options = Utils.parseArgs();
|
|
149
142
|
const configArgName = process.env.MIKRO_ORM_CONFIG_ARG_NAME ?? 'config';
|
|
150
143
|
if (options[configArgName]) {
|
|
151
144
|
return [options[configArgName]];
|
|
@@ -160,60 +153,46 @@ class ConfigurationLoader {
|
|
|
160
153
|
}
|
|
161
154
|
paths.push(...(settings.configPaths || []));
|
|
162
155
|
const alwaysAllowTs = settings.alwaysAllowTs ?? process.versions.bun;
|
|
163
|
-
if (settings.
|
|
156
|
+
if (settings.preferTs !== false || alwaysAllowTs) {
|
|
164
157
|
paths.push('./src/mikro-orm.config.ts');
|
|
165
158
|
paths.push('./mikro-orm.config.ts');
|
|
166
159
|
}
|
|
167
|
-
const distDir =
|
|
168
|
-
const buildDir =
|
|
169
|
-
/*
|
|
160
|
+
const distDir = Utils.pathExistsSync(process.cwd() + '/dist');
|
|
161
|
+
const buildDir = Utils.pathExistsSync(process.cwd() + '/build');
|
|
162
|
+
/* v8 ignore next */
|
|
170
163
|
const path = distDir ? 'dist' : (buildDir ? 'build' : 'src');
|
|
171
164
|
paths.push(`./${path}/mikro-orm.config.js`);
|
|
172
165
|
paths.push('./mikro-orm.config.js');
|
|
173
|
-
const
|
|
174
|
-
|
|
166
|
+
const typeScriptSupport = Utils.detectTypeScriptSupport();
|
|
167
|
+
/* v8 ignore next */
|
|
168
|
+
return Utils.unique(paths).filter(p => p.endsWith('.js') || typeScriptSupport || alwaysAllowTs);
|
|
175
169
|
}
|
|
176
170
|
static isESM() {
|
|
177
171
|
const config = ConfigurationLoader.getPackageConfig();
|
|
178
172
|
const type = config?.type ?? '';
|
|
179
173
|
return type === 'module';
|
|
180
174
|
}
|
|
181
|
-
static
|
|
182
|
-
/*
|
|
175
|
+
static async registerTypeScriptSupport(configPath = 'tsconfig.json') {
|
|
176
|
+
/* v8 ignore next 3 */
|
|
183
177
|
if (process.versions.bun) {
|
|
184
178
|
return true;
|
|
185
179
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
180
|
+
process.env.SWC_NODE_PROJECT ??= configPath;
|
|
181
|
+
process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS ??= '1';
|
|
182
|
+
const esm = this.isESM();
|
|
183
|
+
/* v8 ignore next 2 */
|
|
184
|
+
const importMethod = esm ? 'tryImport' : 'tryRequire';
|
|
185
|
+
const module = esm ? '@swc-node/register/esm-register' : '@swc-node/register';
|
|
186
|
+
const supported = await Utils[importMethod]({
|
|
187
|
+
module,
|
|
188
|
+
warning: '@swc-node/register and @swc/core are not installed, support for working with TypeScript files might not work',
|
|
191
189
|
});
|
|
192
|
-
|
|
193
|
-
if (!tsNode) {
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
const { options } = tsNode.register({
|
|
197
|
-
project: tsConfigPath,
|
|
198
|
-
transpileOnly: true,
|
|
199
|
-
compilerOptions: {
|
|
200
|
-
module: 'nodenext',
|
|
201
|
-
moduleResolution: 'nodenext',
|
|
202
|
-
},
|
|
203
|
-
}).config;
|
|
204
|
-
if (Object.entries(options?.paths ?? {}).length > 0) {
|
|
205
|
-
Utils_1.Utils.requireFrom('tsconfig-paths', tsConfigPath).register({
|
|
206
|
-
baseUrl: options.baseUrl ?? '.',
|
|
207
|
-
paths: options.paths,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
190
|
+
return !!supported;
|
|
211
191
|
}
|
|
212
192
|
static registerDotenv(options) {
|
|
213
|
-
const
|
|
214
|
-
const path = process.env.MIKRO_ORM_ENV ?? ((baseDir ?? process.cwd()) + '/.env');
|
|
193
|
+
const path = process.env.MIKRO_ORM_ENV ?? ((options?.baseDir ?? process.cwd()) + '/.env');
|
|
215
194
|
const env = {};
|
|
216
|
-
|
|
195
|
+
dotenv.config({ path, processEnv: env });
|
|
217
196
|
// only propagate known env vars
|
|
218
197
|
for (const key of Object.keys(env)) {
|
|
219
198
|
if (key.startsWith('MIKRO_ORM_')) {
|
|
@@ -221,8 +200,8 @@ class ConfigurationLoader {
|
|
|
221
200
|
}
|
|
222
201
|
}
|
|
223
202
|
}
|
|
224
|
-
static loadEnvironmentVars() {
|
|
225
|
-
const ret =
|
|
203
|
+
static async loadEnvironmentVars() {
|
|
204
|
+
const ret = this.loadEnvironmentVarsSync();
|
|
226
205
|
// only to keep some sort of back compatibility with those using env vars only, to support `MIKRO_ORM_TYPE`
|
|
227
206
|
const PLATFORMS = {
|
|
228
207
|
mongo: { className: 'MongoDriver', module: '@mikro-orm/mongodb' },
|
|
@@ -233,10 +212,18 @@ class ConfigurationLoader {
|
|
|
233
212
|
sqlite: { className: 'SqliteDriver', module: '@mikro-orm/sqlite' },
|
|
234
213
|
libsql: { className: 'LibSqlDriver', module: '@mikro-orm/libsql' },
|
|
235
214
|
};
|
|
215
|
+
if (process.env.MIKRO_ORM_TYPE) {
|
|
216
|
+
const val = process.env.MIKRO_ORM_TYPE;
|
|
217
|
+
const driver = await import(PLATFORMS[val].module);
|
|
218
|
+
ret.driver = driver[PLATFORMS[val].className];
|
|
219
|
+
}
|
|
220
|
+
return ret;
|
|
221
|
+
}
|
|
222
|
+
static loadEnvironmentVarsSync() {
|
|
223
|
+
const ret = {};
|
|
236
224
|
const array = (v) => v.split(',').map(vv => vv.trim());
|
|
237
225
|
const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
|
|
238
226
|
const num = (v) => +v;
|
|
239
|
-
const driver = (v) => Utils_1.Utils.requireFrom(PLATFORMS[v].module)[PLATFORMS[v].className];
|
|
240
227
|
const read = (o, envKey, key, mapper = v => v) => {
|
|
241
228
|
if (!(envKey in process.env)) {
|
|
242
229
|
return;
|
|
@@ -244,9 +231,8 @@ class ConfigurationLoader {
|
|
|
244
231
|
const val = process.env[envKey];
|
|
245
232
|
o[key] = mapper(val);
|
|
246
233
|
};
|
|
247
|
-
const cleanup = (o, k) =>
|
|
234
|
+
const cleanup = (o, k) => Utils.hasObjectKeys(o[k]) ? {} : delete o[k];
|
|
248
235
|
read(ret, 'MIKRO_ORM_BASE_DIR', 'baseDir');
|
|
249
|
-
read(ret, 'MIKRO_ORM_TYPE', 'driver', driver);
|
|
250
236
|
read(ret, 'MIKRO_ORM_ENTITIES', 'entities', array);
|
|
251
237
|
read(ret, 'MIKRO_ORM_ENTITIES_TS', 'entitiesTs', array);
|
|
252
238
|
read(ret, 'MIKRO_ORM_CLIENT_URL', 'clientUrl');
|
|
@@ -319,24 +305,24 @@ class ConfigurationLoader {
|
|
|
319
305
|
if (this.isESM()) {
|
|
320
306
|
return;
|
|
321
307
|
}
|
|
322
|
-
/*
|
|
308
|
+
/* v8 ignore next 11 */
|
|
323
309
|
options.dynamicImportProvider ??= id => {
|
|
324
|
-
if (
|
|
310
|
+
if (platform() === 'win32') {
|
|
325
311
|
try {
|
|
326
|
-
id =
|
|
312
|
+
id = fileURLToPath(id);
|
|
327
313
|
}
|
|
328
314
|
catch {
|
|
329
315
|
// ignore
|
|
330
316
|
}
|
|
331
317
|
}
|
|
332
|
-
return
|
|
318
|
+
return Utils.requireFrom(id);
|
|
333
319
|
};
|
|
334
|
-
|
|
320
|
+
Utils.setDynamicImportProvider(options.dynamicImportProvider);
|
|
335
321
|
}
|
|
336
322
|
static getORMPackageVersion(name) {
|
|
337
|
-
/* istanbul ignore next */
|
|
338
323
|
try {
|
|
339
|
-
const pkg =
|
|
324
|
+
const pkg = Utils.requireFrom(`${name}/package.json`);
|
|
325
|
+
/* v8 ignore next */
|
|
340
326
|
return pkg?.version;
|
|
341
327
|
}
|
|
342
328
|
catch (e) {
|
|
@@ -345,7 +331,7 @@ class ConfigurationLoader {
|
|
|
345
331
|
}
|
|
346
332
|
// inspired by https://github.com/facebook/docusaurus/pull/3386
|
|
347
333
|
static checkPackageVersion() {
|
|
348
|
-
const coreVersion =
|
|
334
|
+
const coreVersion = Utils.getORMVersion();
|
|
349
335
|
if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH) {
|
|
350
336
|
return coreVersion;
|
|
351
337
|
}
|
|
@@ -355,8 +341,8 @@ class ConfigurationLoader {
|
|
|
355
341
|
for (const ormPackage of ormPackages) {
|
|
356
342
|
const version = this.getORMPackageVersion(ormPackage);
|
|
357
343
|
if (version != null && version !== coreVersion) {
|
|
358
|
-
throw new Error(`Bad ${
|
|
359
|
-
`All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${
|
|
344
|
+
throw new Error(`Bad ${colors.cyan(ormPackage)} version ${colors.yellow('' + version)}.\n` +
|
|
345
|
+
`All official @mikro-orm/* packages need to have the exact same version as @mikro-orm/core (${colors.green(coreVersion)}).\n` +
|
|
360
346
|
`Only exceptions are packages that don't live in the 'mikro-orm' repository: ${[...exceptions].join(', ')}.\n` +
|
|
361
347
|
`Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`);
|
|
362
348
|
}
|
|
@@ -364,4 +350,3 @@ class ConfigurationLoader {
|
|
|
364
350
|
return coreVersion;
|
|
365
351
|
}
|
|
366
352
|
}
|
|
367
|
-
exports.ConfigurationLoader = ConfigurationLoader;
|
package/utils/Cursor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
|
-
import type { EntityMetadata, FilterObject, Loaded } from '../typings';
|
|
3
|
-
import type { FindByCursorOptions, OrderDefinition } from '../drivers/IDatabaseDriver';
|
|
4
|
-
import { type QueryOrder } from '../enums';
|
|
2
|
+
import type { EntityMetadata, FilterObject, Loaded } from '../typings.js';
|
|
3
|
+
import type { FindByCursorOptions, OrderDefinition } from '../drivers/IDatabaseDriver.js';
|
|
4
|
+
import { type QueryOrder } from '../enums.js';
|
|
5
5
|
/**
|
|
6
6
|
* As an alternative to the offset-based pagination with `limit` and `offset`, we can paginate based on a cursor.
|
|
7
7
|
* A cursor is an opaque string that defines a specific place in ordered entity graph. You can use `em.findByCursor()`
|
package/utils/Cursor.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const wrap_1 = require("../entity/wrap");
|
|
9
|
-
const RawQueryFragment_1 = require("../utils/RawQueryFragment");
|
|
10
|
-
const errors_1 = require("../errors");
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import { Utils } from './Utils.js';
|
|
3
|
+
import { ReferenceKind } from '../enums.js';
|
|
4
|
+
import { Reference } from '../entity/Reference.js';
|
|
5
|
+
import { helper } from '../entity/wrap.js';
|
|
6
|
+
import { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
7
|
+
import { CursorError } from '../errors.js';
|
|
11
8
|
/**
|
|
12
9
|
* As an alternative to the offset-based pagination with `limit` and `offset`, we can paginate based on a cursor.
|
|
13
10
|
* A cursor is an opaque string that defines a specific place in ordered entity graph. You can use `em.findByCursor()`
|
|
@@ -55,7 +52,7 @@ const errors_1 = require("../errors");
|
|
|
55
52
|
* }
|
|
56
53
|
* ```
|
|
57
54
|
*/
|
|
58
|
-
class Cursor {
|
|
55
|
+
export class Cursor {
|
|
59
56
|
items;
|
|
60
57
|
totalCount;
|
|
61
58
|
hasPrevPage;
|
|
@@ -97,18 +94,18 @@ class Cursor {
|
|
|
97
94
|
*/
|
|
98
95
|
from(entity) {
|
|
99
96
|
const processEntity = (entity, prop, direction, object = false) => {
|
|
100
|
-
if (
|
|
101
|
-
return
|
|
102
|
-
Object.assign(o, processEntity(
|
|
97
|
+
if (Utils.isPlainObject(direction)) {
|
|
98
|
+
return Utils.keys(direction).reduce((o, key) => {
|
|
99
|
+
Object.assign(o, processEntity(Reference.unwrapReference(entity[prop]), key, direction[key], true));
|
|
103
100
|
return o;
|
|
104
101
|
}, {});
|
|
105
102
|
}
|
|
106
103
|
if (entity[prop] == null) {
|
|
107
|
-
throw
|
|
104
|
+
throw CursorError.entityNotPopulated(entity, prop);
|
|
108
105
|
}
|
|
109
106
|
let value = entity[prop];
|
|
110
|
-
if (
|
|
111
|
-
value =
|
|
107
|
+
if (Utils.isEntity(value, true)) {
|
|
108
|
+
value = helper(value).getPrimaryKey();
|
|
112
109
|
}
|
|
113
110
|
if (object) {
|
|
114
111
|
return ({ [prop]: value });
|
|
@@ -145,15 +142,16 @@ class Cursor {
|
|
|
145
142
|
});
|
|
146
143
|
}
|
|
147
144
|
static getDefinition(meta, orderBy) {
|
|
148
|
-
return
|
|
145
|
+
return Utils.asArray(orderBy).flatMap(order => {
|
|
149
146
|
const ret = [];
|
|
150
|
-
for (const key of
|
|
151
|
-
if (
|
|
147
|
+
for (const key of Utils.keys(order)) {
|
|
148
|
+
if (RawQueryFragment.isKnownFragment(key)) {
|
|
152
149
|
ret.push([key, order[key]]);
|
|
153
150
|
continue;
|
|
154
151
|
}
|
|
155
152
|
const prop = meta.properties[key];
|
|
156
|
-
|
|
153
|
+
/* v8 ignore next */
|
|
154
|
+
if (!prop || !([ReferenceKind.SCALAR, ReferenceKind.EMBEDDED, ReferenceKind.MANY_TO_ONE].includes(prop.kind) || (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner))) {
|
|
157
155
|
continue;
|
|
158
156
|
}
|
|
159
157
|
ret.push([prop.name, order[prop.name]]);
|
|
@@ -161,13 +159,12 @@ class Cursor {
|
|
|
161
159
|
return ret;
|
|
162
160
|
});
|
|
163
161
|
}
|
|
164
|
-
/*
|
|
162
|
+
/* v8 ignore start */
|
|
165
163
|
/** @ignore */
|
|
166
|
-
[
|
|
164
|
+
[inspect.custom]() {
|
|
167
165
|
const type = this.items[0]?.constructor.name;
|
|
168
166
|
const { items, startCursor, endCursor, hasPrevPage, hasNextPage, totalCount, length } = this;
|
|
169
|
-
const options =
|
|
167
|
+
const options = inspect({ startCursor, endCursor, totalCount, hasPrevPage, hasNextPage, items, length }, { depth: 0 });
|
|
170
168
|
return `Cursor${type ? `<${type}>` : ''} ${options.replace('items: [Array]', 'items: [...]')}`;
|
|
171
169
|
}
|
|
172
170
|
}
|
|
173
|
-
exports.Cursor = Cursor;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Primary, Ref } from '../typings';
|
|
2
|
-
import { Collection, type InitCollectionOptions } from '../entity/Collection';
|
|
3
|
-
import { type EntityManager } from '../EntityManager';
|
|
1
|
+
import type { Primary, Ref } from '../typings.js';
|
|
2
|
+
import { Collection, type InitCollectionOptions } from '../entity/Collection.js';
|
|
3
|
+
import { type EntityManager } from '../EntityManager.js';
|
|
4
4
|
import type DataLoader from 'dataloader';
|
|
5
|
-
import { type LoadReferenceOptions } from '../entity/Reference';
|
|
5
|
+
import { type LoadReferenceOptions } from '../entity/Reference.js';
|
|
6
6
|
export declare class DataloaderUtils {
|
|
7
7
|
/**
|
|
8
8
|
* Groups identified references by entity and returns a Map with the
|
package/utils/DataloaderUtils.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const enums_1 = require("../enums");
|
|
7
|
-
const Reference_1 = require("../entity/Reference");
|
|
8
|
-
class DataloaderUtils {
|
|
1
|
+
import { Collection } from '../entity/Collection.js';
|
|
2
|
+
import { helper } from '../entity/wrap.js';
|
|
3
|
+
import { ReferenceKind } from '../enums.js';
|
|
4
|
+
import { Reference } from '../entity/Reference.js';
|
|
5
|
+
export class DataloaderUtils {
|
|
9
6
|
/**
|
|
10
7
|
* Groups identified references by entity and returns a Map with the
|
|
11
8
|
* class name as the index and the corresponding primary keys as the value.
|
|
@@ -26,13 +23,13 @@ class DataloaderUtils {
|
|
|
26
23
|
Thus such approach should probably be configurable, if not opt-in.
|
|
27
24
|
NOTE: meta + opts multi maps (https://github.com/martian17/ds-js) might be a more elegant way
|
|
28
25
|
to implement this but not necessarily faster. */
|
|
29
|
-
const key = `${
|
|
26
|
+
const key = `${helper(ref).__meta.className}|${JSON.stringify(opts ?? {})}`;
|
|
30
27
|
let primaryKeysSet = map.get(key);
|
|
31
28
|
if (primaryKeysSet == null) {
|
|
32
29
|
primaryKeysSet = new Set();
|
|
33
30
|
map.set(key, primaryKeysSet);
|
|
34
31
|
}
|
|
35
|
-
primaryKeysSet.add(
|
|
32
|
+
primaryKeysSet.add(helper(ref).getPrimaryKey());
|
|
36
33
|
}
|
|
37
34
|
return map;
|
|
38
35
|
}
|
|
@@ -87,7 +84,7 @@ class DataloaderUtils {
|
|
|
87
84
|
filterMap.set(inversedProp, primaryKeys);
|
|
88
85
|
}
|
|
89
86
|
// This is the PK that in conjunction with the filter Map key (the prop) will lead to this specific Collection
|
|
90
|
-
primaryKeys.add(
|
|
87
|
+
primaryKeys.add(helper(col.owner).getPrimaryKey());
|
|
91
88
|
}
|
|
92
89
|
return entitiesMap;
|
|
93
90
|
}
|
|
@@ -141,8 +138,8 @@ class DataloaderUtils {
|
|
|
141
138
|
// This is the inverse side of the relationship where the filtering will be done in order to match the target collection
|
|
142
139
|
// Either inversedBy or mappedBy exist because we already checked in groupInversedOrMappedKeysByEntity
|
|
143
140
|
const inverseProp = collection.property.inversedBy ?? collection.property.mappedBy;
|
|
144
|
-
const target =
|
|
145
|
-
if (target instanceof
|
|
141
|
+
const target = Reference.unwrapReference(result[inverseProp]);
|
|
142
|
+
if (target instanceof Collection) {
|
|
146
143
|
for (const item of target) {
|
|
147
144
|
if (item === collection.owner) {
|
|
148
145
|
return true;
|
|
@@ -153,7 +150,7 @@ class DataloaderUtils {
|
|
|
153
150
|
return target === collection.owner;
|
|
154
151
|
}
|
|
155
152
|
// FIXME https://github.com/mikro-orm/mikro-orm/issues/6031
|
|
156
|
-
if (!target && collection.property.kind ===
|
|
153
|
+
if (!target && collection.property.kind === ReferenceKind.MANY_TO_MANY) {
|
|
157
154
|
throw new Error(`Inverse side is required for M:N relations with dataloader: ${collection.owner.constructor.name}.${collection.property.name}`);
|
|
158
155
|
}
|
|
159
156
|
return false;
|
|
@@ -175,7 +172,7 @@ class DataloaderUtils {
|
|
|
175
172
|
const entities = resultsMap.get(key);
|
|
176
173
|
if (entities == null) {
|
|
177
174
|
// Should never happen
|
|
178
|
-
/*
|
|
175
|
+
/* v8 ignore next 3 */
|
|
179
176
|
throw new Error('Cannot match results');
|
|
180
177
|
}
|
|
181
178
|
return entities.filter(DataloaderUtils.getColFilter(col));
|
|
@@ -183,4 +180,3 @@ class DataloaderUtils {
|
|
|
183
180
|
};
|
|
184
181
|
}
|
|
185
182
|
}
|
|
186
|
-
exports.DataloaderUtils = DataloaderUtils;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EntityData, EntityDictionary, EntityMetadata, EntityProperty, IMetadataStorage } from '../typings';
|
|
2
|
-
import type { Platform } from '../platforms';
|
|
1
|
+
import type { EntityData, EntityDictionary, EntityMetadata, EntityProperty, IMetadataStorage } from '../typings.js';
|
|
2
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
3
3
|
type Comparator<T> = (a: T, b: T) => EntityData<T>;
|
|
4
4
|
type ResultMapper<T> = (result: EntityData<T>) => EntityData<T> | null;
|
|
5
5
|
type SnapshotGenerator<T> = (entity: T) => EntityData<T>;
|