@mikro-orm/core 7.0.0-rc.2 → 7.0.0
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 +4 -16
- package/EntityManager.js +248 -181
- package/MikroORM.d.ts +4 -6
- package/MikroORM.js +24 -24
- package/README.md +5 -4
- package/cache/FileCacheAdapter.d.ts +1 -5
- package/cache/FileCacheAdapter.js +22 -24
- package/cache/GeneratedCacheAdapter.d.ts +1 -1
- package/cache/GeneratedCacheAdapter.js +6 -6
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -1
- package/cache/index.js +0 -1
- package/connections/Connection.d.ts +1 -0
- package/connections/Connection.js +43 -14
- package/drivers/DatabaseDriver.d.ts +0 -2
- package/drivers/DatabaseDriver.js +28 -12
- package/drivers/IDatabaseDriver.d.ts +43 -0
- package/entity/Collection.d.ts +1 -9
- package/entity/Collection.js +124 -108
- package/entity/EntityAssigner.js +23 -11
- package/entity/EntityFactory.d.ts +1 -8
- package/entity/EntityFactory.js +79 -59
- package/entity/EntityHelper.js +25 -16
- package/entity/EntityLoader.d.ts +1 -3
- package/entity/EntityLoader.js +90 -60
- package/entity/Reference.d.ts +2 -3
- package/entity/Reference.js +48 -19
- package/entity/WrappedEntity.d.ts +4 -2
- package/entity/WrappedEntity.js +5 -1
- package/entity/defineEntity.d.ts +42 -85
- package/entity/utils.js +28 -26
- package/entity/validators.js +2 -1
- package/enums.d.ts +2 -1
- package/enums.js +13 -17
- package/errors.d.ts +11 -11
- package/errors.js +8 -8
- package/events/EventManager.d.ts +1 -4
- package/events/EventManager.js +26 -23
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/ObjectHydrator.d.ts +1 -2
- package/hydration/ObjectHydrator.js +41 -27
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/logging/DefaultLogger.js +6 -7
- package/logging/Logger.d.ts +2 -1
- package/logging/colors.js +2 -5
- package/logging/index.d.ts +1 -1
- package/logging/index.js +0 -1
- package/metadata/EntitySchema.d.ts +3 -3
- package/metadata/EntitySchema.js +12 -2
- package/metadata/MetadataDiscovery.d.ts +1 -9
- package/metadata/MetadataDiscovery.js +251 -179
- package/metadata/MetadataProvider.js +26 -1
- package/metadata/MetadataStorage.d.ts +1 -5
- package/metadata/MetadataStorage.js +37 -39
- package/metadata/MetadataValidator.js +20 -5
- package/metadata/discover-entities.js +1 -1
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +6 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +1 -1
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.js +5 -1
- package/package.json +38 -38
- package/platforms/Platform.d.ts +24 -1
- package/platforms/Platform.js +106 -27
- package/serialization/EntitySerializer.js +8 -4
- package/serialization/EntityTransformer.js +4 -1
- package/serialization/SerializationContext.d.ts +4 -8
- package/serialization/SerializationContext.js +21 -16
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +2 -1
- package/typings.d.ts +35 -24
- package/typings.js +9 -9
- package/unit-of-work/ChangeSet.js +4 -4
- package/unit-of-work/ChangeSetComputer.d.ts +1 -6
- package/unit-of-work/ChangeSetComputer.js +29 -27
- package/unit-of-work/ChangeSetPersister.d.ts +1 -9
- package/unit-of-work/ChangeSetPersister.js +63 -58
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
- package/unit-of-work/CommitOrderCalculator.js +17 -15
- package/unit-of-work/IdentityMap.d.ts +2 -5
- package/unit-of-work/IdentityMap.js +18 -18
- package/unit-of-work/UnitOfWork.d.ts +12 -20
- package/unit-of-work/UnitOfWork.js +228 -191
- package/utils/AbstractMigrator.d.ts +2 -2
- package/utils/AbstractMigrator.js +10 -12
- package/utils/AbstractSchemaGenerator.js +2 -1
- package/utils/AsyncContext.js +1 -1
- package/utils/Configuration.d.ts +90 -189
- package/utils/Configuration.js +97 -77
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +8 -6
- package/utils/DataloaderUtils.js +15 -12
- package/utils/EntityComparator.d.ts +8 -15
- package/utils/EntityComparator.js +100 -92
- package/utils/QueryHelper.d.ts +16 -1
- package/utils/QueryHelper.js +108 -50
- package/utils/RawQueryFragment.d.ts +4 -4
- package/utils/RawQueryFragment.js +3 -2
- package/utils/TransactionManager.js +3 -3
- package/utils/Utils.d.ts +2 -2
- package/utils/Utils.js +39 -32
- package/utils/clone.js +5 -0
- package/utils/env-vars.js +6 -5
- package/utils/fs-utils.d.ts +3 -17
- package/utils/fs-utils.js +2 -5
- package/utils/upsert-utils.js +7 -4
|
@@ -15,6 +15,7 @@ type MigrateOptions = {
|
|
|
15
15
|
transaction?: Transaction;
|
|
16
16
|
};
|
|
17
17
|
export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implements IMigrator {
|
|
18
|
+
#private;
|
|
18
19
|
protected readonly em: D[typeof EntityManagerType];
|
|
19
20
|
protected runner: IMigrationRunner;
|
|
20
21
|
protected storage: IMigratorStorage;
|
|
@@ -24,7 +25,6 @@ export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implem
|
|
|
24
25
|
protected readonly options: MigrationsOptions;
|
|
25
26
|
protected absolutePath: string;
|
|
26
27
|
protected initialized: boolean;
|
|
27
|
-
private readonly listeners;
|
|
28
28
|
constructor(em: D[typeof EntityManagerType]);
|
|
29
29
|
protected abstract createRunner(): IMigrationRunner;
|
|
30
30
|
protected abstract createStorage(): IMigratorStorage;
|
|
@@ -95,7 +95,7 @@ export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implem
|
|
|
95
95
|
private filterDown;
|
|
96
96
|
private getMigrationFilename;
|
|
97
97
|
private prefix;
|
|
98
|
-
|
|
98
|
+
protected runMigrations(method: 'up' | 'down', options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>;
|
|
99
99
|
private runInTransaction;
|
|
100
100
|
}
|
|
101
101
|
export {};
|
|
@@ -9,7 +9,7 @@ export class AbstractMigrator {
|
|
|
9
9
|
options;
|
|
10
10
|
absolutePath;
|
|
11
11
|
initialized = false;
|
|
12
|
-
listeners = new Map();
|
|
12
|
+
#listeners = new Map();
|
|
13
13
|
constructor(em) {
|
|
14
14
|
this.em = em;
|
|
15
15
|
this.driver = this.em.getDriver();
|
|
@@ -22,17 +22,17 @@ export class AbstractMigrator {
|
|
|
22
22
|
* @inheritDoc
|
|
23
23
|
*/
|
|
24
24
|
on(eventName, listener) {
|
|
25
|
-
if (!this
|
|
26
|
-
this
|
|
25
|
+
if (!this.#listeners.has(eventName)) {
|
|
26
|
+
this.#listeners.set(eventName, new Set());
|
|
27
27
|
}
|
|
28
|
-
this
|
|
28
|
+
this.#listeners.get(eventName).add(listener);
|
|
29
29
|
return this;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* @inheritDoc
|
|
33
33
|
*/
|
|
34
34
|
off(eventName, listener) {
|
|
35
|
-
this
|
|
35
|
+
this.#listeners.get(eventName)?.delete(listener);
|
|
36
36
|
return this;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
@@ -49,9 +49,7 @@ export class AbstractMigrator {
|
|
|
49
49
|
await this.init();
|
|
50
50
|
const all = await this.discoverMigrations();
|
|
51
51
|
const executed = new Set(await this.storage.executed());
|
|
52
|
-
return all
|
|
53
|
-
.filter(m => !executed.has(m.name))
|
|
54
|
-
.map(m => ({ name: m.name, path: m.path }));
|
|
52
|
+
return all.filter(m => !executed.has(m.name)).map(m => ({ name: m.name, path: m.path }));
|
|
55
53
|
}
|
|
56
54
|
/**
|
|
57
55
|
* @inheritDoc
|
|
@@ -74,7 +72,7 @@ export class AbstractMigrator {
|
|
|
74
72
|
const { fs } = await import('@mikro-orm/core/fs-utils');
|
|
75
73
|
this.detectSourceFolder(fs);
|
|
76
74
|
/* v8 ignore next */
|
|
77
|
-
const key =
|
|
75
|
+
const key = this.config.get('preferTs', Utils.detectTypeScriptSupport()) && this.options.pathTs ? 'pathTs' : 'path';
|
|
78
76
|
this.absolutePath = fs.absolutePath(this.options[key], this.config.get('baseDir'));
|
|
79
77
|
fs.ensureDir(this.absolutePath);
|
|
80
78
|
}
|
|
@@ -132,7 +130,7 @@ export class AbstractMigrator {
|
|
|
132
130
|
const buildDir = fs.pathExists(baseDir + '/build');
|
|
133
131
|
// if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder
|
|
134
132
|
/* v8 ignore next */
|
|
135
|
-
const path = distDir ? './dist' :
|
|
133
|
+
const path = distDir ? './dist' : buildDir ? './build' : './src';
|
|
136
134
|
// only if the user did not provide any values and if the default path does not exist
|
|
137
135
|
if (!this.options.path && !this.options.pathTs && !exists) {
|
|
138
136
|
this.options.path = `${path}/migrations`;
|
|
@@ -150,7 +148,7 @@ export class AbstractMigrator {
|
|
|
150
148
|
}
|
|
151
149
|
}
|
|
152
150
|
async emit(event, data) {
|
|
153
|
-
for (const listener of this
|
|
151
|
+
for (const listener of this.#listeners.get(event) ?? []) {
|
|
154
152
|
await listener(data);
|
|
155
153
|
}
|
|
156
154
|
}
|
|
@@ -257,7 +255,7 @@ export class AbstractMigrator {
|
|
|
257
255
|
}
|
|
258
256
|
getMigrationFilename(name) {
|
|
259
257
|
name = name.replace(/\.[jt]s$/, '');
|
|
260
|
-
return
|
|
258
|
+
return /^\d{14}$/.exec(name) ? this.options.fileName(name) : name;
|
|
261
259
|
}
|
|
262
260
|
prefix(options) {
|
|
263
261
|
if (typeof options === 'string' || Array.isArray(options)) {
|
|
@@ -112,7 +112,8 @@ export class AbstractSchemaGenerator {
|
|
|
112
112
|
}
|
|
113
113
|
meta = metadata.pop();
|
|
114
114
|
}
|
|
115
|
-
return calc
|
|
115
|
+
return calc
|
|
116
|
+
.sort()
|
|
116
117
|
.map(cls => this.metadata.getById(cls))
|
|
117
118
|
.filter(meta => {
|
|
118
119
|
const targetSchema = meta.schema ?? this.config.get('schema', this.platform.getDefaultSchemaName());
|
package/utils/AsyncContext.js
CHANGED
|
@@ -13,7 +13,7 @@ function createFallbackAsyncContext() {
|
|
|
13
13
|
console.warn('AsyncLocalStorage not available');
|
|
14
14
|
return {
|
|
15
15
|
getStore: () => store,
|
|
16
|
-
enterWith: value => store = value,
|
|
16
|
+
enterWith: value => (store = value),
|
|
17
17
|
run: (value, cb) => {
|
|
18
18
|
const prev = store;
|
|
19
19
|
store = value;
|