@mikro-orm/core 7.0.0-dev.321 → 7.0.0-dev.322
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 +2 -15
- package/EntityManager.js +155 -152
- package/MikroORM.d.ts +1 -3
- package/MikroORM.js +20 -20
- package/cache/FileCacheAdapter.d.ts +1 -5
- package/cache/FileCacheAdapter.js +22 -22
- 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/entity/Collection.d.ts +2 -10
- package/entity/Collection.js +95 -105
- package/entity/EntityFactory.d.ts +1 -8
- package/entity/EntityFactory.js +48 -48
- package/entity/EntityLoader.d.ts +1 -3
- package/entity/EntityLoader.js +33 -34
- package/entity/Reference.d.ts +1 -2
- package/entity/Reference.js +11 -11
- package/events/EventManager.d.ts +1 -4
- package/events/EventManager.js +21 -21
- package/hydration/ObjectHydrator.d.ts +1 -2
- package/hydration/ObjectHydrator.js +11 -11
- package/metadata/MetadataDiscovery.d.ts +1 -9
- package/metadata/MetadataDiscovery.js +147 -144
- package/metadata/MetadataStorage.d.ts +1 -5
- package/metadata/MetadataStorage.js +36 -36
- package/package.json +1 -1
- package/serialization/SerializationContext.d.ts +2 -6
- package/serialization/SerializationContext.js +14 -14
- package/unit-of-work/ChangeSetComputer.d.ts +1 -6
- package/unit-of-work/ChangeSetComputer.js +21 -21
- package/unit-of-work/ChangeSetPersister.d.ts +1 -9
- package/unit-of-work/ChangeSetPersister.js +51 -51
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
- package/unit-of-work/CommitOrderCalculator.js +13 -13
- package/unit-of-work/IdentityMap.d.ts +2 -5
- package/unit-of-work/IdentityMap.js +18 -18
- package/unit-of-work/UnitOfWork.d.ts +5 -19
- package/unit-of-work/UnitOfWork.js +181 -173
- package/utils/AbstractMigrator.d.ts +1 -1
- package/utils/AbstractMigrator.js +6 -6
- package/utils/Configuration.d.ts +1 -6
- package/utils/Configuration.js +78 -78
- package/utils/Cursor.d.ts +1 -1
- package/utils/Cursor.js +3 -3
- package/utils/EntityComparator.d.ts +2 -11
- package/utils/EntityComparator.js +44 -44
- package/utils/TransactionManager.js +1 -2
- package/utils/Utils.js +1 -1
- package/utils/clone.js +1 -1
package/events/EventManager.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { Utils } from '../utils/Utils.js';
|
|
2
2
|
import { EventType, EventTypeMap } from '../enums.js';
|
|
3
3
|
export class EventManager {
|
|
4
|
-
listeners = {};
|
|
5
|
-
entities = new Map();
|
|
6
|
-
cache = new Map();
|
|
7
|
-
subscribers = new Set();
|
|
4
|
+
#listeners = {};
|
|
5
|
+
#entities = new Map();
|
|
6
|
+
#cache = new Map();
|
|
7
|
+
#subscribers = new Set();
|
|
8
8
|
constructor(subscribers) {
|
|
9
9
|
for (const subscriber of subscribers) {
|
|
10
10
|
this.registerSubscriber(subscriber);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
registerSubscriber(subscriber) {
|
|
14
|
-
if (this
|
|
14
|
+
if (this.#subscribers.has(subscriber)) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
this
|
|
18
|
-
this
|
|
19
|
-
this
|
|
17
|
+
this.#subscribers.add(subscriber);
|
|
18
|
+
this.#entities.set(subscriber, this.getSubscribedEntities(subscriber));
|
|
19
|
+
this.#cache.clear();
|
|
20
20
|
Utils.keys(EventType)
|
|
21
21
|
.filter(event => event in subscriber)
|
|
22
22
|
.forEach(event => {
|
|
23
|
-
this
|
|
24
|
-
this
|
|
23
|
+
this.#listeners[event] ??= new Set();
|
|
24
|
+
this.#listeners[event].add(subscriber);
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
getSubscribers() {
|
|
28
|
-
return this
|
|
28
|
+
return this.#subscribers;
|
|
29
29
|
}
|
|
30
30
|
dispatchEvent(event, args, meta) {
|
|
31
31
|
const listeners = [];
|
|
@@ -38,8 +38,8 @@ export class EventManager {
|
|
|
38
38
|
const handler = typeof hook === 'function' ? hook : (entity[hook] ?? prototypeHook);
|
|
39
39
|
return handler.bind(entity);
|
|
40
40
|
}));
|
|
41
|
-
for (const listener of this
|
|
42
|
-
const entities = this
|
|
41
|
+
for (const listener of this.#listeners[event] ?? new Set()) {
|
|
42
|
+
const entities = this.#entities.get(listener);
|
|
43
43
|
if (entities.size === 0 || !entity || entities.has(entity.constructor.name)) {
|
|
44
44
|
listeners.push(listener[event].bind(listener));
|
|
45
45
|
}
|
|
@@ -54,26 +54,26 @@ export class EventManager {
|
|
|
54
54
|
}
|
|
55
55
|
hasListeners(event, meta) {
|
|
56
56
|
const cacheKey = meta._id + EventTypeMap[event];
|
|
57
|
-
if (this
|
|
58
|
-
return this
|
|
57
|
+
if (this.#cache.has(cacheKey)) {
|
|
58
|
+
return this.#cache.get(cacheKey);
|
|
59
59
|
}
|
|
60
60
|
const hasHooks = meta.hooks[event]?.length;
|
|
61
61
|
if (hasHooks) {
|
|
62
|
-
this
|
|
62
|
+
this.#cache.set(cacheKey, true);
|
|
63
63
|
return true;
|
|
64
64
|
}
|
|
65
|
-
for (const listener of this
|
|
66
|
-
const entities = this
|
|
65
|
+
for (const listener of this.#listeners[event] ?? new Set()) {
|
|
66
|
+
const entities = this.#entities.get(listener);
|
|
67
67
|
if (entities.size === 0 || entities.has(meta.className)) {
|
|
68
|
-
this
|
|
68
|
+
this.#cache.set(cacheKey, true);
|
|
69
69
|
return true;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
this
|
|
72
|
+
this.#cache.set(cacheKey, false);
|
|
73
73
|
return false;
|
|
74
74
|
}
|
|
75
75
|
clone() {
|
|
76
|
-
return new EventManager(this
|
|
76
|
+
return new EventManager(this.#subscribers);
|
|
77
77
|
}
|
|
78
78
|
getSubscribedEntities(listener) {
|
|
79
79
|
if (!listener.getSubscribedEntities) {
|
|
@@ -3,8 +3,7 @@ import { Hydrator } from './Hydrator.js';
|
|
|
3
3
|
import type { EntityFactory } from '../entity/EntityFactory.js';
|
|
4
4
|
type EntityHydrator<T extends object> = (entity: T, data: EntityData<T>, factory: EntityFactory, newEntity: boolean, convertCustomTypes: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean) => void;
|
|
5
5
|
export declare class ObjectHydrator extends Hydrator {
|
|
6
|
-
private
|
|
7
|
-
private tmpIndex;
|
|
6
|
+
#private;
|
|
8
7
|
/**
|
|
9
8
|
* @inheritDoc
|
|
10
9
|
*/
|
|
@@ -7,13 +7,13 @@ import { ReferenceKind } from '../enums.js';
|
|
|
7
7
|
import { Raw } from '../utils/RawQueryFragment.js';
|
|
8
8
|
import { ValidationError } from '../errors.js';
|
|
9
9
|
export class ObjectHydrator extends Hydrator {
|
|
10
|
-
hydrators = {
|
|
10
|
+
#hydrators = {
|
|
11
11
|
'full~true': new Map(),
|
|
12
12
|
'full~false': new Map(),
|
|
13
13
|
'reference~true': new Map(),
|
|
14
14
|
'reference~false': new Map(),
|
|
15
15
|
};
|
|
16
|
-
tmpIndex = 0;
|
|
16
|
+
#tmpIndex = 0;
|
|
17
17
|
/**
|
|
18
18
|
* @inheritDoc
|
|
19
19
|
*/
|
|
@@ -41,7 +41,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
41
41
|
*/
|
|
42
42
|
getEntityHydrator(meta, type, normalizeAccessors = false) {
|
|
43
43
|
const key = `${type}~${normalizeAccessors}`;
|
|
44
|
-
const exists = this
|
|
44
|
+
const exists = this.#hydrators[key].get(meta.class);
|
|
45
45
|
if (exists) {
|
|
46
46
|
return exists;
|
|
47
47
|
}
|
|
@@ -71,7 +71,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
71
71
|
.map(k => this.safeKey(k))
|
|
72
72
|
.join('_');
|
|
73
73
|
const ret = [];
|
|
74
|
-
const idx = this
|
|
74
|
+
const idx = this.#tmpIndex++;
|
|
75
75
|
const nullVal = this.config.get('forceUndefined') ? 'undefined' : 'null';
|
|
76
76
|
if (prop.getter && !prop.setter && prop.persist === false) {
|
|
77
77
|
return [];
|
|
@@ -150,7 +150,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
150
150
|
const keyOption = prop.targetKey ? `, key: '${prop.targetKey}'` : '';
|
|
151
151
|
if (prop.polymorphic) {
|
|
152
152
|
// For polymorphic: target class from discriminator map, PK from data.id
|
|
153
|
-
const discriminatorMapKey = this.safeKey(`discriminatorMap_${prop.name}_${this
|
|
153
|
+
const discriminatorMapKey = this.safeKey(`discriminatorMap_${prop.name}_${this.#tmpIndex++}`);
|
|
154
154
|
context.set(discriminatorMapKey, prop.discriminatorMap);
|
|
155
155
|
ret.push(` const targetClass = ${discriminatorMapKey}[data${dataKey}.discriminator];`);
|
|
156
156
|
ret.push(` if (!targetClass) throw new ValidationError(\`Unknown discriminator value '\${data${dataKey}.discriminator}' for polymorphic relation '${prop.name}'. Valid values: \${Object.keys(${discriminatorMapKey}).join(', ')}\`);`);
|
|
@@ -163,7 +163,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
163
163
|
}
|
|
164
164
|
else {
|
|
165
165
|
// For regular: fixed target class, PK is the data itself
|
|
166
|
-
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this
|
|
166
|
+
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
|
|
167
167
|
context.set(targetKey, prop.targetMeta.class);
|
|
168
168
|
if (prop.ref) {
|
|
169
169
|
ret.push(` entity${entityKey} = Reference.create(factory.createReference(${targetKey}, data${dataKey}, { merge: true, convertCustomTypes, normalizeAccessors, schema${keyOption} }));`);
|
|
@@ -179,7 +179,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
179
179
|
hydrateTargetExpr = `data${dataKey}.constructor`;
|
|
180
180
|
}
|
|
181
181
|
else {
|
|
182
|
-
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this
|
|
182
|
+
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
|
|
183
183
|
context.set(targetKey, prop.targetMeta.class);
|
|
184
184
|
hydrateTargetExpr = targetKey;
|
|
185
185
|
}
|
|
@@ -323,7 +323,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
323
323
|
});
|
|
324
324
|
}
|
|
325
325
|
else {
|
|
326
|
-
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this
|
|
326
|
+
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
|
|
327
327
|
context.set(targetKey, prop.targetMeta.class);
|
|
328
328
|
ret.push(` if (entity${entityKey} == null) {`);
|
|
329
329
|
ret.push(` entity${entityKey} = factory.createEmbeddable(${targetKey}, embeddedData, { newEntity, convertCustomTypes, normalizeAccessors });`);
|
|
@@ -352,7 +352,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
352
352
|
const hydrateEmbeddedArray = (prop, path, dataKey) => {
|
|
353
353
|
const entityKey = path.map(k => this.wrap(k)).join('');
|
|
354
354
|
const ret = [];
|
|
355
|
-
const idx = this
|
|
355
|
+
const idx = this.#tmpIndex++;
|
|
356
356
|
registerEmbeddedPrototype(prop, path);
|
|
357
357
|
parseObjectEmbeddable(prop, dataKey, ret);
|
|
358
358
|
ret.push(` if (Array.isArray(data${dataKey})) {`);
|
|
@@ -402,7 +402,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
402
402
|
`${lines.join('\n')}\n}`;
|
|
403
403
|
const fnKey = `hydrator-${meta.uniqueName}-${type}-${normalizeAccessors}`;
|
|
404
404
|
const hydrator = Utils.createFunction(context, code, this.config.get('compiledFunctions'), fnKey);
|
|
405
|
-
this
|
|
405
|
+
this.#hydrators[key].set(meta.class, hydrator);
|
|
406
406
|
return hydrator;
|
|
407
407
|
}
|
|
408
408
|
createCollectionItemMapper(prop, context) {
|
|
@@ -415,7 +415,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
415
415
|
lines.push(` value = { ...value, ['${prop2.name}']: Reference.wrapReference(entity, { ref: ${prop2.ref} }) };`);
|
|
416
416
|
lines.push(` }`);
|
|
417
417
|
}
|
|
418
|
-
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this
|
|
418
|
+
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
|
|
419
419
|
context.set(targetKey, prop.targetMeta.class);
|
|
420
420
|
lines.push(` if (isPrimaryKey(value, ${meta.compositePK})) return factory.createReference(${targetKey}, value, { convertCustomTypes, schema, normalizeAccessors, merge: true });`);
|
|
421
421
|
lines.push(` if (value && value.__entity) return value;`);
|
|
@@ -4,15 +4,7 @@ import { MetadataStorage } from './MetadataStorage.js';
|
|
|
4
4
|
import { EntitySchema } from './EntitySchema.js';
|
|
5
5
|
import type { Platform } from '../platforms/Platform.js';
|
|
6
6
|
export declare class MetadataDiscovery {
|
|
7
|
-
private
|
|
8
|
-
private readonly platform;
|
|
9
|
-
private readonly config;
|
|
10
|
-
private readonly namingStrategy;
|
|
11
|
-
private readonly metadataProvider;
|
|
12
|
-
private readonly logger;
|
|
13
|
-
private readonly schemaHelper;
|
|
14
|
-
private readonly validator;
|
|
15
|
-
private readonly discovered;
|
|
7
|
+
#private;
|
|
16
8
|
constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
|
|
17
9
|
discover(preferTs?: boolean): Promise<MetadataStorage>;
|
|
18
10
|
discoverSync(): MetadataStorage;
|