@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
package/MikroORM.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { EntityManagerType, IDatabaseDriver } from './drivers';
|
|
2
|
-
import { type EntitySchema
|
|
3
|
-
import {
|
|
4
|
-
import type
|
|
5
|
-
import type {
|
|
1
|
+
import type { EntityManagerType, IDatabaseDriver } from './drivers/IDatabaseDriver.js';
|
|
2
|
+
import { type EntitySchema } from './metadata/EntitySchema.js';
|
|
3
|
+
import { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
4
|
+
import { Configuration, type Options } from './utils/Configuration.js';
|
|
5
|
+
import type { EntityManager } from './EntityManager.js';
|
|
6
|
+
import type { Constructor, EntityMetadata, EntityName, IEntityGenerator, IMigrator, ISeedManager } from './typings.js';
|
|
6
7
|
/**
|
|
7
8
|
* Helper class for bootstrapping the MikroORM.
|
|
8
9
|
*/
|
|
@@ -27,7 +28,7 @@ export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver,
|
|
|
27
28
|
* - no check for mismatched package versions
|
|
28
29
|
*/
|
|
29
30
|
static initSync<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options: Options<D, EM>): MikroORM<D, EM>;
|
|
30
|
-
constructor(options: Options<Driver, EM>
|
|
31
|
+
constructor(options: Options<Driver, EM>);
|
|
31
32
|
/**
|
|
32
33
|
* Connects to the database.
|
|
33
34
|
*/
|
package/MikroORM.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { MetadataDiscovery } from './metadata/MetadataDiscovery.js';
|
|
2
|
+
import { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
3
|
+
import { MetadataValidator } from './metadata/MetadataValidator.js';
|
|
4
|
+
import { ReflectMetadataProvider } from './metadata/ReflectMetadataProvider.js';
|
|
5
|
+
import { Configuration } from './utils/Configuration.js';
|
|
6
|
+
import { ConfigurationLoader } from './utils/ConfigurationLoader.js';
|
|
7
|
+
import { Utils } from './utils/Utils.js';
|
|
8
|
+
import { colors } from './logging/colors.js';
|
|
9
|
+
import { NullCacheAdapter } from './cache/NullCacheAdapter.js';
|
|
8
10
|
/**
|
|
9
11
|
* Helper class for bootstrapping the MikroORM.
|
|
10
12
|
*/
|
|
11
|
-
class MikroORM {
|
|
13
|
+
export class MikroORM {
|
|
12
14
|
/** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
|
|
13
15
|
em;
|
|
14
16
|
driver;
|
|
@@ -21,28 +23,24 @@ class MikroORM {
|
|
|
21
23
|
* If you omit the `options` parameter, your CLI config will be used.
|
|
22
24
|
*/
|
|
23
25
|
static async init(options) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
utils_1.ConfigurationLoader.registerDotenv(options);
|
|
29
|
-
const coreVersion = await utils_1.ConfigurationLoader.checkPackageVersion();
|
|
30
|
-
const env = utils_1.ConfigurationLoader.loadEnvironmentVars();
|
|
26
|
+
ConfigurationLoader.registerDotenv(options);
|
|
27
|
+
const coreVersion = await ConfigurationLoader.checkPackageVersion();
|
|
28
|
+
const env = await ConfigurationLoader.loadEnvironmentVars();
|
|
31
29
|
if (!options) {
|
|
32
|
-
const configPathFromArg =
|
|
33
|
-
const config = (await
|
|
30
|
+
const configPathFromArg = ConfigurationLoader.configPathsFromArg();
|
|
31
|
+
const config = (await ConfigurationLoader.getConfiguration(process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default', configPathFromArg ?? ConfigurationLoader.getConfigPaths()));
|
|
34
32
|
options = config.getAll();
|
|
35
33
|
if (configPathFromArg) {
|
|
36
34
|
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' });
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
|
-
options =
|
|
40
|
-
await
|
|
37
|
+
options = Utils.mergeConfig(options, env);
|
|
38
|
+
await ConfigurationLoader.commonJSCompat(options);
|
|
41
39
|
if ('DRIVER' in this && !options.driver) {
|
|
42
40
|
options.driver = this.DRIVER;
|
|
43
41
|
}
|
|
44
42
|
const orm = new MikroORM(options);
|
|
45
|
-
orm.logger.log('info', `MikroORM version: ${
|
|
43
|
+
orm.logger.log('info', `MikroORM version: ${colors.green(coreVersion)}`);
|
|
46
44
|
// we need to allow global context here as we are not in a scope of requests yet
|
|
47
45
|
const allowGlobalContext = orm.config.get('allowGlobalContext');
|
|
48
46
|
orm.config.set('allowGlobalContext', true);
|
|
@@ -68,13 +66,9 @@ class MikroORM {
|
|
|
68
66
|
* - no check for mismatched package versions
|
|
69
67
|
*/
|
|
70
68
|
static initSync(options) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
utils_1.ConfigurationLoader.registerDotenv(options);
|
|
76
|
-
const env = utils_1.ConfigurationLoader.loadEnvironmentVars();
|
|
77
|
-
options = utils_1.Utils.merge(options, env);
|
|
69
|
+
ConfigurationLoader.registerDotenv(options);
|
|
70
|
+
const env = ConfigurationLoader.loadEnvironmentVarsSync();
|
|
71
|
+
options = Utils.merge(options, env);
|
|
78
72
|
if ('DRIVER' in this && !options.driver) {
|
|
79
73
|
options.driver = this.DRIVER;
|
|
80
74
|
}
|
|
@@ -91,21 +85,16 @@ class MikroORM {
|
|
|
91
85
|
return orm;
|
|
92
86
|
}
|
|
93
87
|
constructor(options) {
|
|
94
|
-
|
|
95
|
-
this.config = options;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
this.config = new utils_1.Configuration(options);
|
|
99
|
-
}
|
|
88
|
+
this.config = new Configuration(options);
|
|
100
89
|
const discovery = this.config.get('discovery');
|
|
101
90
|
if (discovery.disableDynamicFileAccess) {
|
|
102
|
-
this.config.set('metadataProvider',
|
|
103
|
-
this.config.set('metadataCache', { adapter:
|
|
91
|
+
this.config.set('metadataProvider', ReflectMetadataProvider);
|
|
92
|
+
this.config.set('metadataCache', { adapter: NullCacheAdapter });
|
|
104
93
|
discovery.requireEntitiesArray = true;
|
|
105
94
|
}
|
|
106
95
|
this.driver = this.config.getDriver();
|
|
107
96
|
this.logger = this.config.getLogger();
|
|
108
|
-
this.discovery = new
|
|
97
|
+
this.discovery = new MetadataDiscovery(new MetadataStorage(), this.driver.getPlatform(), this.config);
|
|
109
98
|
}
|
|
110
99
|
/**
|
|
111
100
|
* Connects to the database.
|
|
@@ -120,7 +109,7 @@ class MikroORM {
|
|
|
120
109
|
await this.schema.ensureDatabase(typeof options === 'boolean' ? {} : { ...options, forceCheck: true });
|
|
121
110
|
}
|
|
122
111
|
if (await this.isConnected()) {
|
|
123
|
-
this.logger.log('info', `MikroORM successfully connected to database ${
|
|
112
|
+
this.logger.log('info', `MikroORM successfully connected to database ${colors.green(db)}`);
|
|
124
113
|
}
|
|
125
114
|
else {
|
|
126
115
|
this.logger.error('info', `MikroORM failed to connect to database ${db}`);
|
|
@@ -131,8 +120,8 @@ class MikroORM {
|
|
|
131
120
|
* Reconnects, possibly to a different database.
|
|
132
121
|
*/
|
|
133
122
|
async reconnect(options = {}) {
|
|
134
|
-
/*
|
|
135
|
-
for (const key of
|
|
123
|
+
/* v8 ignore next 3 */
|
|
124
|
+
for (const key of Utils.keys(options)) {
|
|
136
125
|
this.config.set(key, options[key]);
|
|
137
126
|
}
|
|
138
127
|
await this.driver.reconnect();
|
|
@@ -168,7 +157,7 @@ class MikroORM {
|
|
|
168
157
|
*/
|
|
169
158
|
getMetadata(entityName) {
|
|
170
159
|
if (entityName) {
|
|
171
|
-
entityName =
|
|
160
|
+
entityName = Utils.className(entityName);
|
|
172
161
|
return this.metadata.get(entityName);
|
|
173
162
|
}
|
|
174
163
|
return this.metadata;
|
|
@@ -192,14 +181,14 @@ class MikroORM {
|
|
|
192
181
|
* Allows dynamically discovering new entity by reference, handy for testing schema diffing.
|
|
193
182
|
*/
|
|
194
183
|
discoverEntity(entities, reset) {
|
|
195
|
-
entities =
|
|
196
|
-
for (const className of
|
|
184
|
+
entities = Utils.asArray(entities);
|
|
185
|
+
for (const className of Utils.asArray(reset)) {
|
|
197
186
|
this.metadata.reset(className);
|
|
198
187
|
this.discovery.reset(className);
|
|
199
188
|
}
|
|
200
189
|
const tmp = this.discovery.discoverReferences(entities);
|
|
201
190
|
const options = this.config.get('discovery');
|
|
202
|
-
new
|
|
191
|
+
new MetadataValidator().validateDiscovered([...Object.values(this.metadata.getAll()), ...tmp], options);
|
|
203
192
|
const metadata = this.discovery.processDiscoveredEntities(tmp);
|
|
204
193
|
metadata.forEach(meta => {
|
|
205
194
|
this.metadata.set(meta.className, meta);
|
|
@@ -215,7 +204,7 @@ class MikroORM {
|
|
|
215
204
|
if (extension) {
|
|
216
205
|
return extension;
|
|
217
206
|
}
|
|
218
|
-
/*
|
|
207
|
+
/* v8 ignore next 2 */
|
|
219
208
|
throw new Error(`SchemaGenerator extension not registered.`);
|
|
220
209
|
}
|
|
221
210
|
/**
|
|
@@ -261,4 +250,3 @@ class MikroORM {
|
|
|
261
250
|
return this.getEntityGenerator();
|
|
262
251
|
}
|
|
263
252
|
}
|
|
264
|
-
exports.MikroORM = MikroORM;
|
package/cache/CacheAdapter.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FileCacheAdapter = void 0;
|
|
7
|
-
const globby_1 = __importDefault(require("globby"));
|
|
8
|
-
const fs_extra_1 = require("fs-extra");
|
|
9
|
-
const Utils_1 = require("../utils/Utils");
|
|
10
|
-
class FileCacheAdapter {
|
|
1
|
+
import globby from 'globby';
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
|
|
3
|
+
import { Utils } from '../utils/Utils.js';
|
|
4
|
+
export class FileCacheAdapter {
|
|
11
5
|
options;
|
|
12
6
|
baseDir;
|
|
13
7
|
pretty;
|
|
14
|
-
VERSION =
|
|
8
|
+
VERSION = Utils.getORMVersion();
|
|
15
9
|
cache = {};
|
|
16
10
|
constructor(options, baseDir, pretty = false) {
|
|
17
11
|
this.options = options;
|
|
@@ -23,10 +17,10 @@ class FileCacheAdapter {
|
|
|
23
17
|
*/
|
|
24
18
|
get(name) {
|
|
25
19
|
const path = this.path(name);
|
|
26
|
-
if (!(
|
|
20
|
+
if (!existsSync(path)) {
|
|
27
21
|
return null;
|
|
28
22
|
}
|
|
29
|
-
const payload =
|
|
23
|
+
const payload = Utils.readJSONSync(path);
|
|
30
24
|
const hash = this.getHash(payload.origin);
|
|
31
25
|
if (!hash || payload.hash !== hash) {
|
|
32
26
|
return null;
|
|
@@ -43,23 +37,22 @@ class FileCacheAdapter {
|
|
|
43
37
|
}
|
|
44
38
|
const path = this.path(name);
|
|
45
39
|
const hash = this.getHash(origin);
|
|
46
|
-
|
|
47
|
-
(0, fs_extra_1.writeJSONSync)(path, { data, origin, hash, version: this.VERSION }, opts);
|
|
40
|
+
writeFileSync(path, JSON.stringify({ data, origin, hash, version: this.VERSION }, null, this.pretty ? 2 : undefined));
|
|
48
41
|
}
|
|
49
42
|
/**
|
|
50
43
|
* @inheritDoc
|
|
51
44
|
*/
|
|
52
45
|
remove(name) {
|
|
53
46
|
const path = this.path(name);
|
|
54
|
-
|
|
47
|
+
unlinkSync(path);
|
|
55
48
|
}
|
|
56
49
|
/**
|
|
57
50
|
* @inheritDoc
|
|
58
51
|
*/
|
|
59
52
|
clear() {
|
|
60
53
|
const path = this.path('*');
|
|
61
|
-
const files =
|
|
62
|
-
files.forEach(file =>
|
|
54
|
+
const files = globby.sync(path);
|
|
55
|
+
files.forEach(file => unlinkSync(file));
|
|
63
56
|
this.cache = {};
|
|
64
57
|
}
|
|
65
58
|
combine() {
|
|
@@ -69,22 +62,21 @@ class FileCacheAdapter {
|
|
|
69
62
|
let path = typeof this.options.combined === 'string'
|
|
70
63
|
? this.options.combined
|
|
71
64
|
: './metadata.json';
|
|
72
|
-
path =
|
|
65
|
+
path = Utils.normalizePath(this.options.cacheDir, path);
|
|
73
66
|
this.options.combined = path; // override in the options, so we can log it from the CLI in `cache:generate` command
|
|
74
|
-
(
|
|
67
|
+
writeFileSync(path, JSON.stringify(this.cache, null, this.pretty ? 2 : undefined));
|
|
75
68
|
return path;
|
|
76
69
|
}
|
|
77
70
|
path(name) {
|
|
78
|
-
|
|
71
|
+
Utils.ensureDir(this.options.cacheDir);
|
|
79
72
|
return `${this.options.cacheDir}/${name}.json`;
|
|
80
73
|
}
|
|
81
74
|
getHash(origin) {
|
|
82
|
-
origin =
|
|
83
|
-
if (!(
|
|
75
|
+
origin = Utils.absolutePath(origin, this.baseDir);
|
|
76
|
+
if (!existsSync(origin)) {
|
|
84
77
|
return null;
|
|
85
78
|
}
|
|
86
|
-
const contents =
|
|
87
|
-
return
|
|
79
|
+
const contents = readFileSync(origin);
|
|
80
|
+
return Utils.hash(contents.toString() + this.VERSION);
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
|
-
exports.FileCacheAdapter = FileCacheAdapter;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CacheAdapter } from './CacheAdapter';
|
|
2
|
-
import type { Dictionary } from '../typings';
|
|
1
|
+
import type { CacheAdapter } from './CacheAdapter.js';
|
|
2
|
+
import type { Dictionary } from '../typings.js';
|
|
3
3
|
export declare class GeneratedCacheAdapter implements CacheAdapter {
|
|
4
4
|
private readonly options;
|
|
5
5
|
private readonly data;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GeneratedCacheAdapter = void 0;
|
|
4
|
-
class GeneratedCacheAdapter {
|
|
1
|
+
export class GeneratedCacheAdapter {
|
|
5
2
|
options;
|
|
6
3
|
data = new Map();
|
|
7
4
|
constructor(options) {
|
|
@@ -35,4 +32,3 @@ class GeneratedCacheAdapter {
|
|
|
35
32
|
this.data.clear();
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
exports.GeneratedCacheAdapter = GeneratedCacheAdapter;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MemoryCacheAdapter = void 0;
|
|
4
|
-
class MemoryCacheAdapter {
|
|
1
|
+
export class MemoryCacheAdapter {
|
|
5
2
|
options;
|
|
6
3
|
data = new Map();
|
|
7
4
|
constructor(options) {
|
|
@@ -41,4 +38,3 @@ class MemoryCacheAdapter {
|
|
|
41
38
|
this.data.clear();
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
|
-
exports.MemoryCacheAdapter = MemoryCacheAdapter;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NullCacheAdapter = void 0;
|
|
4
|
-
class NullCacheAdapter {
|
|
1
|
+
export class NullCacheAdapter {
|
|
5
2
|
/**
|
|
6
3
|
* @inheritDoc
|
|
7
4
|
*/
|
|
@@ -27,4 +24,3 @@ class NullCacheAdapter {
|
|
|
27
24
|
// ignore
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
exports.NullCacheAdapter = NullCacheAdapter;
|
package/cache/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './CacheAdapter';
|
|
2
|
-
export * from './NullCacheAdapter';
|
|
3
|
-
export * from './FileCacheAdapter';
|
|
4
|
-
export * from './MemoryCacheAdapter';
|
|
5
|
-
export * from './GeneratedCacheAdapter';
|
|
1
|
+
export * from './CacheAdapter.js';
|
|
2
|
+
export * from './NullCacheAdapter.js';
|
|
3
|
+
export * from './FileCacheAdapter.js';
|
|
4
|
+
export * from './MemoryCacheAdapter.js';
|
|
5
|
+
export * from './GeneratedCacheAdapter.js';
|
package/cache/index.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./CacheAdapter"), exports);
|
|
18
|
-
__exportStar(require("./NullCacheAdapter"), exports);
|
|
19
|
-
__exportStar(require("./FileCacheAdapter"), exports);
|
|
20
|
-
__exportStar(require("./MemoryCacheAdapter"), exports);
|
|
21
|
-
__exportStar(require("./GeneratedCacheAdapter"), exports);
|
|
1
|
+
export * from './CacheAdapter.js';
|
|
2
|
+
export * from './NullCacheAdapter.js';
|
|
3
|
+
export * from './FileCacheAdapter.js';
|
|
4
|
+
export * from './MemoryCacheAdapter.js';
|
|
5
|
+
export * from './GeneratedCacheAdapter.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type Configuration, type ConnectionOptions } from '../utils';
|
|
2
|
-
import type { LogContext, Logger } from '../logging';
|
|
3
|
-
import type { MetadataStorage } from '../metadata';
|
|
4
|
-
import type { ConnectionType, Dictionary, MaybePromise, Primary } from '../typings';
|
|
5
|
-
import type { Platform } from '../platforms/Platform';
|
|
6
|
-
import type { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster';
|
|
7
|
-
import type { IsolationLevel } from '../enums';
|
|
1
|
+
import { type Configuration, type ConnectionOptions } from '../utils/Configuration.js';
|
|
2
|
+
import type { LogContext, Logger } from '../logging/Logger.js';
|
|
3
|
+
import type { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
4
|
+
import type { ConnectionType, Dictionary, MaybePromise, Primary } from '../typings.js';
|
|
5
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
6
|
+
import type { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster.js';
|
|
7
|
+
import type { IsolationLevel } from '../enums.js';
|
|
8
8
|
export declare abstract class Connection {
|
|
9
9
|
protected readonly config: Configuration;
|
|
10
10
|
protected readonly type: ConnectionType;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const node_url_1 = require("node:url");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
class Connection {
|
|
1
|
+
import { URL } from 'node:url';
|
|
2
|
+
import { Utils } from '../utils/Utils.js';
|
|
3
|
+
export class Connection {
|
|
7
4
|
config;
|
|
8
5
|
type;
|
|
9
6
|
metadata;
|
|
@@ -17,7 +14,7 @@ class Connection {
|
|
|
17
14
|
this.logger = this.config.getLogger();
|
|
18
15
|
this.platform = this.config.getPlatform();
|
|
19
16
|
if (options) {
|
|
20
|
-
this.options =
|
|
17
|
+
this.options = Utils.copy(options);
|
|
21
18
|
}
|
|
22
19
|
else {
|
|
23
20
|
const props = ['dbName', 'clientUrl', 'host', 'port', 'user', 'password', 'multipleStatements', 'pool', 'schema', 'driverOptions'];
|
|
@@ -58,7 +55,7 @@ class Connection {
|
|
|
58
55
|
getConnectionOptions() {
|
|
59
56
|
const ret = {};
|
|
60
57
|
if (this.options.clientUrl) {
|
|
61
|
-
const url = new
|
|
58
|
+
const url = new URL(this.options.clientUrl);
|
|
62
59
|
this.options.host = ret.host = this.options.host ?? decodeURIComponent(url.hostname);
|
|
63
60
|
this.options.port = ret.port = this.options.port ?? +url.port;
|
|
64
61
|
this.options.user = ret.user = this.options.user ?? decodeURIComponent(url.username);
|
|
@@ -70,7 +67,7 @@ class Connection {
|
|
|
70
67
|
}
|
|
71
68
|
}
|
|
72
69
|
else {
|
|
73
|
-
const url = new
|
|
70
|
+
const url = new URL(this.config.getClientUrl());
|
|
74
71
|
this.options.host = ret.host = this.options.host ?? this.config.get('host', decodeURIComponent(url.hostname));
|
|
75
72
|
this.options.port = ret.port = this.options.port ?? this.config.get('port', +url.port);
|
|
76
73
|
this.options.user = ret.user = this.options.user ?? this.config.get('user', decodeURIComponent(url.username));
|
|
@@ -81,7 +78,7 @@ class Connection {
|
|
|
81
78
|
}
|
|
82
79
|
getClientUrl() {
|
|
83
80
|
const options = this.getConnectionOptions();
|
|
84
|
-
const url = new
|
|
81
|
+
const url = new URL(this.config.getClientUrl(true));
|
|
85
82
|
const password = options.password ? ':*****' : '';
|
|
86
83
|
const schema = options.schema && options.schema !== this.platform.getDefaultSchemaName()
|
|
87
84
|
? `?schema=${options.schema}`
|
|
@@ -105,7 +102,7 @@ class Connection {
|
|
|
105
102
|
...context,
|
|
106
103
|
took: Date.now() - now,
|
|
107
104
|
results: Array.isArray(res) ? res.length : undefined,
|
|
108
|
-
affected:
|
|
105
|
+
affected: Utils.isPlainObject(res) ? res.affectedRows : undefined,
|
|
109
106
|
});
|
|
110
107
|
return res;
|
|
111
108
|
}
|
|
@@ -126,4 +123,3 @@ class Connection {
|
|
|
126
123
|
});
|
|
127
124
|
}
|
|
128
125
|
}
|
|
129
|
-
exports.Connection = Connection;
|
package/connections/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './Connection';
|
|
1
|
+
export * from './Connection.js';
|
package/connections/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Connection"), exports);
|
|
1
|
+
export * from './Connection.js';
|
package/decorators/Check.d.ts
CHANGED
package/decorators/Check.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const metadata_1 = require("../metadata");
|
|
5
|
-
const Utils_1 = require("../utils/Utils");
|
|
6
|
-
function Check(options) {
|
|
1
|
+
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
+
import { Utils } from '../utils/Utils.js';
|
|
3
|
+
export function Check(options) {
|
|
7
4
|
return function (target, propertyName) {
|
|
8
|
-
const meta =
|
|
5
|
+
const meta = MetadataStorage.getMetadataFromDecorator((propertyName ? target.constructor : target));
|
|
9
6
|
options.property ??= propertyName;
|
|
10
7
|
meta.checks.push(options);
|
|
11
8
|
if (!propertyName) {
|
|
12
9
|
return target;
|
|
13
10
|
}
|
|
14
|
-
return
|
|
11
|
+
return Utils.propertyDecoratorReturnValue();
|
|
15
12
|
};
|
|
16
13
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ContextProvider } from '../typings';
|
|
1
|
+
import type { ContextProvider } from '../typings.js';
|
|
2
2
|
export declare function CreateRequestContext<T extends object>(context?: ContextProvider<T>, respectExistingContext?: boolean): MethodDecorator;
|
|
3
3
|
export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): MethodDecorator;
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const RequestContext_1 = require("../utils/RequestContext");
|
|
6
|
-
const resolveContextProvider_1 = require("../utils/resolveContextProvider");
|
|
7
|
-
const TransactionContext_1 = require("../utils/TransactionContext");
|
|
8
|
-
function CreateRequestContext(context, respectExistingContext = false) {
|
|
1
|
+
import { RequestContext } from '../utils/RequestContext.js';
|
|
2
|
+
import { resolveContextProvider } from '../utils/resolveContextProvider.js';
|
|
3
|
+
import { TransactionContext } from '../utils/TransactionContext.js';
|
|
4
|
+
export function CreateRequestContext(context, respectExistingContext = false) {
|
|
9
5
|
return function (target, propertyKey, descriptor) {
|
|
10
6
|
const originalMethod = descriptor.value;
|
|
11
7
|
descriptor.value = async function (...args) {
|
|
12
|
-
const em = await
|
|
8
|
+
const em = await resolveContextProvider(this, context);
|
|
13
9
|
if (!em) {
|
|
14
10
|
const name = respectExistingContext ? 'EnsureRequestContext' : 'CreateRequestContext';
|
|
15
11
|
throw new Error(`@${name}() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@${name}(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
|
|
16
12
|
}
|
|
17
13
|
// reuse existing context if available for given respect `contextName`
|
|
18
|
-
if (respectExistingContext &&
|
|
14
|
+
if (respectExistingContext && RequestContext.getEntityManager(em.name)) {
|
|
19
15
|
return originalMethod.apply(this, args);
|
|
20
16
|
}
|
|
21
17
|
// Otherwise, the outer tx context would be preferred.
|
|
22
|
-
const txContext =
|
|
23
|
-
const provider = txContext ?
|
|
18
|
+
const txContext = TransactionContext.currentTransactionContext();
|
|
19
|
+
const provider = txContext ? TransactionContext : RequestContext;
|
|
24
20
|
return txContext
|
|
25
21
|
? provider.create(em.fork({ useContext: true }), () => originalMethod.apply(this, args))
|
|
26
22
|
: provider.create(em, () => originalMethod.apply(this, args));
|
|
@@ -28,6 +24,6 @@ function CreateRequestContext(context, respectExistingContext = false) {
|
|
|
28
24
|
return descriptor;
|
|
29
25
|
};
|
|
30
26
|
}
|
|
31
|
-
function EnsureRequestContext(context) {
|
|
27
|
+
export function EnsureRequestContext(context) {
|
|
32
28
|
return CreateRequestContext(context, true);
|
|
33
29
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Dictionary } from '../typings';
|
|
1
|
+
import type { Dictionary } from '../typings.js';
|
|
2
2
|
export declare function Embeddable(options?: EmbeddableOptions): <T>(target: T & Dictionary) => T & Dictionary;
|
|
3
3
|
export type EmbeddableOptions = {
|
|
4
4
|
discriminatorColumn?: string;
|
package/decorators/Embeddable.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Embeddable = Embeddable;
|
|
4
|
-
const metadata_1 = require("../metadata");
|
|
5
|
-
function Embeddable(options = {}) {
|
|
1
|
+
import { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
2
|
+
export function Embeddable(options = {}) {
|
|
6
3
|
return function (target) {
|
|
7
|
-
const meta =
|
|
4
|
+
const meta = MetadataStorage.getMetadataFromDecorator(target);
|
|
8
5
|
meta.class = target;
|
|
9
6
|
meta.name = target.name;
|
|
10
7
|
meta.embeddable = true;
|
package/decorators/Embedded.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyEntity } from '../typings';
|
|
1
|
+
import type { AnyEntity } from '../typings.js';
|
|
2
2
|
export declare function Embedded<T extends object>(type?: EmbeddedOptions | (() => AnyEntity), options?: EmbeddedOptions): (target: AnyEntity, propertyName: string) => any;
|
|
3
3
|
/** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
|
|
4
4
|
export type EmbeddedPrefixMode = 'absolute' | 'relative';
|