@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.100
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 +96 -58
- package/EntityManager.js +465 -395
- package/MikroORM.d.ts +45 -35
- package/MikroORM.js +109 -160
- package/README.md +3 -2
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +2 -2
- package/cache/FileCacheAdapter.js +20 -27
- package/cache/GeneratedCacheAdapter.d.ts +2 -3
- package/cache/GeneratedCacheAdapter.js +1 -7
- 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 +4 -5
- package/cache/index.js +4 -21
- package/connections/Connection.d.ts +22 -14
- package/connections/Connection.js +27 -23
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/drivers/DatabaseDriver.d.ts +25 -15
- package/drivers/DatabaseDriver.js +77 -64
- package/drivers/IDatabaseDriver.d.ts +40 -16
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/BaseEntity.d.ts +6 -7
- package/entity/BaseEntity.js +16 -23
- package/entity/Collection.d.ts +98 -34
- package/entity/Collection.js +466 -131
- package/entity/EntityAssigner.d.ts +3 -3
- package/entity/EntityAssigner.js +67 -64
- package/entity/EntityFactory.d.ts +10 -3
- package/entity/EntityFactory.js +112 -91
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +66 -53
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +8 -7
- package/entity/EntityLoader.js +161 -128
- package/entity/EntityRepository.d.ts +8 -8
- package/entity/EntityRepository.js +7 -11
- package/entity/Reference.d.ts +10 -13
- package/entity/Reference.js +64 -46
- package/entity/WrappedEntity.d.ts +12 -17
- package/entity/WrappedEntity.js +22 -31
- package/entity/defineEntity.d.ts +568 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +14 -13
- package/entity/index.js +14 -29
- package/entity/utils.d.ts +8 -1
- package/entity/utils.js +22 -13
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +24 -9
- package/enums.js +50 -41
- package/errors.d.ts +11 -3
- package/errors.js +42 -32
- package/events/EventManager.d.ts +5 -4
- package/events/EventManager.js +26 -22
- package/events/EventSubscriber.d.ts +8 -5
- 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 +2 -6
- package/hydration/ObjectHydrator.d.ts +7 -7
- package/hydration/ObjectHydrator.js +58 -50
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +20 -46
- package/logging/DefaultLogger.d.ts +2 -2
- package/logging/DefaultLogger.js +10 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +3 -3
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +5 -4
- package/logging/index.js +5 -20
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +16 -0
- package/metadata/EntitySchema.d.ts +14 -10
- package/metadata/EntitySchema.js +78 -64
- package/metadata/MetadataDiscovery.d.ts +11 -14
- package/metadata/MetadataDiscovery.js +278 -317
- package/metadata/MetadataProvider.d.ts +13 -4
- package/metadata/MetadataProvider.js +47 -8
- package/metadata/MetadataStorage.d.ts +2 -7
- package/metadata/MetadataStorage.js +19 -35
- package/metadata/MetadataValidator.d.ts +3 -10
- package/metadata/MetadataValidator.js +51 -64
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
- package/naming-strategy/AbstractNamingStrategy.js +11 -9
- 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 +12 -2
- 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/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +19 -20
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +15 -22
- package/platforms/Platform.js +58 -88
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +4 -2
- package/serialization/EntitySerializer.js +64 -51
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +48 -42
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +24 -25
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +6 -11
- package/types/BigIntType.d.ts +12 -9
- package/types/BigIntType.js +6 -6
- package/types/BlobType.d.ts +3 -4
- package/types/BlobType.js +2 -11
- package/types/BooleanType.d.ts +5 -4
- package/types/BooleanType.js +5 -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 +9 -7
- package/types/DecimalType.js +5 -8
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +4 -7
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +4 -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 +4 -4
- package/types/JsonType.js +9 -8
- 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 +4 -6
- package/types/Type.js +6 -10
- package/types/Uint8ArrayType.d.ts +3 -4
- package/types/Uint8ArrayType.js +3 -12
- 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 +134 -93
- package/typings.js +67 -65
- package/unit-of-work/ChangeSet.d.ts +1 -4
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -9
- package/unit-of-work/ChangeSetComputer.js +36 -38
- package/unit-of-work/ChangeSetPersister.d.ts +11 -9
- package/unit-of-work/ChangeSetPersister.js +100 -65
- 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 +16 -8
- package/unit-of-work/UnitOfWork.js +266 -209
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +11 -11
- package/utils/AbstractSchemaGenerator.js +21 -20
- package/utils/Configuration.d.ts +774 -224
- package/utils/Configuration.js +166 -216
- package/utils/ConfigurationLoader.d.ts +1 -53
- package/utils/ConfigurationLoader.js +1 -367
- package/utils/Cursor.d.ts +6 -9
- package/utils/Cursor.js +25 -25
- package/utils/DataloaderUtils.d.ts +18 -8
- package/utils/DataloaderUtils.js +63 -21
- package/utils/EntityComparator.d.ts +9 -5
- package/utils/EntityComparator.js +155 -108
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +12 -4
- package/utils/QueryHelper.js +110 -53
- package/utils/RawQueryFragment.d.ts +37 -14
- package/utils/RawQueryFragment.js +50 -33
- 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/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +16 -100
- package/utils/Utils.js +114 -332
- package/utils/clone.js +7 -11
- package/utils/env-vars.d.ts +3 -0
- package/utils/env-vars.js +87 -0
- package/utils/fs-utils.d.ts +12 -0
- package/utils/fs-utils.js +97 -0
- package/utils/index.d.ts +14 -13
- package/utils/index.js +14 -29
- package/utils/upsert-utils.d.ts +8 -3
- package/utils/upsert-utils.js +57 -10
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -16
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -33
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -14
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -20
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -16
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -19
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -11
- package/decorators/Formula.d.ts +0 -5
- package/decorators/Formula.js +0 -18
- package/decorators/Indexed.d.ts +0 -17
- package/decorators/Indexed.js +0 -24
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -16
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -16
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -20
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -10
- package/decorators/PrimaryKey.d.ts +0 -9
- package/decorators/PrimaryKey.js +0 -23
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -34
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -31
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -59
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -36
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -399
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -154
- package/index.mjs +0 -199
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -48
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -31
package/events/EventManager.js
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const Utils_1 = require("../utils/Utils");
|
|
5
|
-
const enums_1 = require("../enums");
|
|
6
|
-
class EventManager {
|
|
1
|
+
import { Utils } from '../utils/Utils.js';
|
|
2
|
+
import { EventType, EventTypeMap } from '../enums.js';
|
|
3
|
+
export class EventManager {
|
|
7
4
|
listeners = {};
|
|
8
5
|
entities = new Map();
|
|
9
6
|
cache = new Map();
|
|
10
|
-
subscribers =
|
|
7
|
+
subscribers = new Set();
|
|
11
8
|
constructor(subscribers) {
|
|
12
|
-
|
|
9
|
+
for (const subscriber of subscribers) {
|
|
10
|
+
this.registerSubscriber(subscriber);
|
|
11
|
+
}
|
|
13
12
|
}
|
|
14
13
|
registerSubscriber(subscriber) {
|
|
15
|
-
this.subscribers.
|
|
14
|
+
if (this.subscribers.has(subscriber)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.subscribers.add(subscriber);
|
|
16
18
|
this.entities.set(subscriber, this.getSubscribedEntities(subscriber));
|
|
17
19
|
this.cache.clear();
|
|
18
|
-
|
|
20
|
+
Utils.keys(EventType)
|
|
19
21
|
.filter(event => event in subscriber)
|
|
20
22
|
.forEach(event => {
|
|
21
|
-
this.listeners[event] ??=
|
|
22
|
-
this.listeners[event].
|
|
23
|
+
this.listeners[event] ??= new Set();
|
|
24
|
+
this.listeners[event].add(subscriber);
|
|
23
25
|
});
|
|
24
26
|
}
|
|
27
|
+
getSubscribers() {
|
|
28
|
+
return this.subscribers;
|
|
29
|
+
}
|
|
25
30
|
dispatchEvent(event, args, meta) {
|
|
26
31
|
const listeners = [];
|
|
27
32
|
const entity = args.entity;
|
|
@@ -33,19 +38,19 @@ class EventManager {
|
|
|
33
38
|
const handler = typeof hook === 'function' ? hook : entity[hook] ?? prototypeHook;
|
|
34
39
|
return handler.bind(entity);
|
|
35
40
|
}));
|
|
36
|
-
for (const listener of this.listeners[event]
|
|
41
|
+
for (const listener of this.listeners[event] ?? new Set()) {
|
|
37
42
|
const entities = this.entities.get(listener);
|
|
38
|
-
if (entities.
|
|
43
|
+
if (entities.size === 0 || !entity || entities.has(entity.constructor.name)) {
|
|
39
44
|
listeners.push(listener[event].bind(listener));
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
|
-
if (event ===
|
|
47
|
+
if (event === EventType.onInit) {
|
|
43
48
|
return listeners.forEach(listener => listener(args));
|
|
44
49
|
}
|
|
45
|
-
return
|
|
50
|
+
return Utils.runSerial(listeners, listener => listener(args));
|
|
46
51
|
}
|
|
47
52
|
hasListeners(event, meta) {
|
|
48
|
-
const cacheKey = meta._id +
|
|
53
|
+
const cacheKey = meta._id + EventTypeMap[event];
|
|
49
54
|
if (this.cache.has(cacheKey)) {
|
|
50
55
|
return this.cache.get(cacheKey);
|
|
51
56
|
}
|
|
@@ -54,9 +59,9 @@ class EventManager {
|
|
|
54
59
|
this.cache.set(cacheKey, true);
|
|
55
60
|
return true;
|
|
56
61
|
}
|
|
57
|
-
for (const listener of this.listeners[event] ??
|
|
62
|
+
for (const listener of this.listeners[event] ?? new Set()) {
|
|
58
63
|
const entities = this.entities.get(listener);
|
|
59
|
-
if (entities.
|
|
64
|
+
if (entities.size === 0 || entities.has(meta.className)) {
|
|
60
65
|
this.cache.set(cacheKey, true);
|
|
61
66
|
return true;
|
|
62
67
|
}
|
|
@@ -69,9 +74,8 @@ class EventManager {
|
|
|
69
74
|
}
|
|
70
75
|
getSubscribedEntities(listener) {
|
|
71
76
|
if (!listener.getSubscribedEntities) {
|
|
72
|
-
return
|
|
77
|
+
return new Set();
|
|
73
78
|
}
|
|
74
|
-
return listener.getSubscribedEntities().map(name =>
|
|
79
|
+
return new Set(listener.getSubscribedEntities().map(name => Utils.className(name)));
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
|
-
exports.EventManager = EventManager;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { EntityName, EntityMetadata } from '../typings';
|
|
2
|
-
import type { EntityManager } from '../EntityManager';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import type { EntityName, EntityMetadata } from '../typings.js';
|
|
2
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
3
|
+
import type { UnitOfWork } from '../unit-of-work/UnitOfWork.js';
|
|
4
|
+
import type { ChangeSet } from '../unit-of-work/ChangeSet.js';
|
|
5
|
+
import type { Transaction } from '../connections/Connection.js';
|
|
5
6
|
export interface EventArgs<T> {
|
|
6
7
|
entity: T;
|
|
7
8
|
em: EntityManager;
|
|
@@ -12,7 +13,9 @@ export interface FlushEventArgs extends Omit<EventArgs<any>, 'entity' | 'changeS
|
|
|
12
13
|
uow: UnitOfWork;
|
|
13
14
|
}
|
|
14
15
|
export interface TransactionEventArgs extends Omit<EventArgs<any>, 'entity' | 'meta' | 'changeSet'> {
|
|
15
|
-
transaction?: Transaction
|
|
16
|
+
transaction?: Transaction & {
|
|
17
|
+
savepointName?: string;
|
|
18
|
+
};
|
|
16
19
|
uow?: UnitOfWork;
|
|
17
20
|
}
|
|
18
21
|
export interface EventSubscriber<T = any> {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Transaction } from '../connections';
|
|
2
|
-
import type { EntityManager } from '../EntityManager';
|
|
3
|
-
import type { TransactionEventType } from '../enums';
|
|
1
|
+
import type { Transaction } from '../connections/Connection.js';
|
|
2
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
3
|
+
import type { TransactionEventType } from '../enums.js';
|
|
4
4
|
export declare class TransactionEventBroadcaster {
|
|
5
5
|
private readonly em;
|
|
6
6
|
readonly context?: {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransactionEventBroadcaster = void 0;
|
|
4
|
-
class TransactionEventBroadcaster {
|
|
1
|
+
export class TransactionEventBroadcaster {
|
|
5
2
|
em;
|
|
6
3
|
context;
|
|
7
4
|
constructor(em, context) {
|
|
@@ -16,4 +13,3 @@ class TransactionEventBroadcaster {
|
|
|
16
13
|
});
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.TransactionEventBroadcaster = TransactionEventBroadcaster;
|
package/events/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './EventSubscriber';
|
|
2
|
-
export * from './EventManager';
|
|
3
|
-
export * from './TransactionEventBroadcaster';
|
|
1
|
+
export * from './EventSubscriber.js';
|
|
2
|
+
export * from './EventManager.js';
|
|
3
|
+
export * from './TransactionEventBroadcaster.js';
|
package/events/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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("./EventSubscriber"), exports);
|
|
18
|
-
__exportStar(require("./EventManager"), exports);
|
|
19
|
-
__exportStar(require("./TransactionEventBroadcaster"), exports);
|
|
1
|
+
export * from './EventSubscriber.js';
|
|
2
|
+
export * from './EventManager.js';
|
|
3
|
+
export * from './TransactionEventBroadcaster.js';
|
package/exceptions.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UniqueConstraintViolationException = exports.TableNotFoundException = exports.TableExistsException = exports.SyntaxErrorException = exports.ReadOnlyException = exports.NotNullConstraintViolationException = exports.NonUniqueFieldNameException = exports.LockWaitTimeoutException = exports.InvalidFieldNameException = exports.CheckConstraintViolationException = exports.ForeignKeyConstraintViolationException = exports.DeadlockException = exports.DatabaseObjectNotFoundException = exports.DatabaseObjectExistsException = exports.ConstraintViolationException = exports.ServerException = exports.ConnectionException = exports.DriverException = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Base class for all errors detected in the driver.
|
|
6
3
|
*/
|
|
7
|
-
class DriverException extends Error {
|
|
4
|
+
export class DriverException extends Error {
|
|
8
5
|
code;
|
|
9
6
|
errno;
|
|
10
7
|
sqlState;
|
|
@@ -18,25 +15,21 @@ class DriverException extends Error {
|
|
|
18
15
|
this.stack += '\n\n' + previous.stack.split('\n').filter(l => l.trim().startsWith('at ')).join('\n');
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
exports.DriverException = DriverException;
|
|
22
18
|
/**
|
|
23
19
|
* Base class for all connection related errors detected in the driver.
|
|
24
20
|
*/
|
|
25
|
-
class ConnectionException extends DriverException {
|
|
21
|
+
export class ConnectionException extends DriverException {
|
|
26
22
|
}
|
|
27
|
-
exports.ConnectionException = ConnectionException;
|
|
28
23
|
/**
|
|
29
24
|
* Base class for all server related errors detected in the driver.
|
|
30
25
|
*/
|
|
31
|
-
class ServerException extends DriverException {
|
|
26
|
+
export class ServerException extends DriverException {
|
|
32
27
|
}
|
|
33
|
-
exports.ServerException = ServerException;
|
|
34
28
|
/**
|
|
35
29
|
* Base class for all constraint violation related errors detected in the driver.
|
|
36
30
|
*/
|
|
37
|
-
class ConstraintViolationException extends ServerException {
|
|
31
|
+
export class ConstraintViolationException extends ServerException {
|
|
38
32
|
}
|
|
39
|
-
exports.ConstraintViolationException = ConstraintViolationException;
|
|
40
33
|
/**
|
|
41
34
|
* Base class for all already existing database object related errors detected in the driver.
|
|
42
35
|
*
|
|
@@ -44,9 +37,8 @@ exports.ConstraintViolationException = ConstraintViolationException;
|
|
|
44
37
|
* such as schemas, tables, views, sequences, triggers, constraints, indexes,
|
|
45
38
|
* functions, stored procedures etc.
|
|
46
39
|
*/
|
|
47
|
-
class DatabaseObjectExistsException extends ServerException {
|
|
40
|
+
export class DatabaseObjectExistsException extends ServerException {
|
|
48
41
|
}
|
|
49
|
-
exports.DatabaseObjectExistsException = DatabaseObjectExistsException;
|
|
50
42
|
/**
|
|
51
43
|
* Base class for all unknown database object related errors detected in the driver.
|
|
52
44
|
*
|
|
@@ -54,78 +46,65 @@ exports.DatabaseObjectExistsException = DatabaseObjectExistsException;
|
|
|
54
46
|
* such as schemas, tables, views, sequences, triggers, constraints, indexes,
|
|
55
47
|
* functions, stored procedures etc.
|
|
56
48
|
*/
|
|
57
|
-
class DatabaseObjectNotFoundException extends ServerException {
|
|
49
|
+
export class DatabaseObjectNotFoundException extends ServerException {
|
|
58
50
|
}
|
|
59
|
-
exports.DatabaseObjectNotFoundException = DatabaseObjectNotFoundException;
|
|
60
51
|
/**
|
|
61
52
|
* Exception for a deadlock error of a transaction detected in the driver.
|
|
62
53
|
*/
|
|
63
|
-
class DeadlockException extends ServerException {
|
|
54
|
+
export class DeadlockException extends ServerException {
|
|
64
55
|
}
|
|
65
|
-
exports.DeadlockException = DeadlockException;
|
|
66
56
|
/**
|
|
67
57
|
* Exception for a foreign key constraint violation detected in the driver.
|
|
68
58
|
*/
|
|
69
|
-
class ForeignKeyConstraintViolationException extends ConstraintViolationException {
|
|
59
|
+
export class ForeignKeyConstraintViolationException extends ConstraintViolationException {
|
|
70
60
|
}
|
|
71
|
-
exports.ForeignKeyConstraintViolationException = ForeignKeyConstraintViolationException;
|
|
72
61
|
/**
|
|
73
62
|
* Exception for a check constraint violation detected in the driver.
|
|
74
63
|
*/
|
|
75
|
-
class CheckConstraintViolationException extends ConstraintViolationException {
|
|
64
|
+
export class CheckConstraintViolationException extends ConstraintViolationException {
|
|
76
65
|
}
|
|
77
|
-
exports.CheckConstraintViolationException = CheckConstraintViolationException;
|
|
78
66
|
/**
|
|
79
67
|
* Exception for an invalid specified field name in a statement detected in the driver.
|
|
80
68
|
*/
|
|
81
|
-
class InvalidFieldNameException extends ServerException {
|
|
69
|
+
export class InvalidFieldNameException extends ServerException {
|
|
82
70
|
}
|
|
83
|
-
exports.InvalidFieldNameException = InvalidFieldNameException;
|
|
84
71
|
/**
|
|
85
72
|
* Exception for a lock wait timeout error of a transaction detected in the driver.
|
|
86
73
|
*/
|
|
87
|
-
class LockWaitTimeoutException extends ServerException {
|
|
74
|
+
export class LockWaitTimeoutException extends ServerException {
|
|
88
75
|
}
|
|
89
|
-
exports.LockWaitTimeoutException = LockWaitTimeoutException;
|
|
90
76
|
/**
|
|
91
77
|
* Exception for a non-unique/ambiguous specified field name in a statement detected in the driver.
|
|
92
78
|
*/
|
|
93
|
-
class NonUniqueFieldNameException extends ServerException {
|
|
79
|
+
export class NonUniqueFieldNameException extends ServerException {
|
|
94
80
|
}
|
|
95
|
-
exports.NonUniqueFieldNameException = NonUniqueFieldNameException;
|
|
96
81
|
/**
|
|
97
82
|
* Exception for a NOT NULL constraint violation detected in the driver.
|
|
98
83
|
*/
|
|
99
|
-
class NotNullConstraintViolationException extends ConstraintViolationException {
|
|
84
|
+
export class NotNullConstraintViolationException extends ConstraintViolationException {
|
|
100
85
|
}
|
|
101
|
-
exports.NotNullConstraintViolationException = NotNullConstraintViolationException;
|
|
102
86
|
/**
|
|
103
87
|
* Exception for a write operation attempt on a read-only database element detected in the driver.
|
|
104
88
|
*/
|
|
105
|
-
class ReadOnlyException extends ServerException {
|
|
89
|
+
export class ReadOnlyException extends ServerException {
|
|
106
90
|
}
|
|
107
|
-
exports.ReadOnlyException = ReadOnlyException;
|
|
108
91
|
/**
|
|
109
92
|
* Exception for a syntax error in a statement detected in the driver.
|
|
110
93
|
*/
|
|
111
|
-
class SyntaxErrorException extends ServerException {
|
|
94
|
+
export class SyntaxErrorException extends ServerException {
|
|
112
95
|
}
|
|
113
|
-
exports.SyntaxErrorException = SyntaxErrorException;
|
|
114
96
|
/**
|
|
115
97
|
* Exception for an already existing table referenced in a statement detected in the driver.
|
|
116
98
|
*/
|
|
117
|
-
class TableExistsException extends DatabaseObjectExistsException {
|
|
99
|
+
export class TableExistsException extends DatabaseObjectExistsException {
|
|
118
100
|
}
|
|
119
|
-
exports.TableExistsException = TableExistsException;
|
|
120
101
|
/**
|
|
121
102
|
* Exception for an unknown table referenced in a statement detected in the driver.
|
|
122
103
|
*/
|
|
123
|
-
class TableNotFoundException extends DatabaseObjectNotFoundException {
|
|
104
|
+
export class TableNotFoundException extends DatabaseObjectNotFoundException {
|
|
124
105
|
}
|
|
125
|
-
exports.TableNotFoundException = TableNotFoundException;
|
|
126
106
|
/**
|
|
127
107
|
* Exception for a unique constraint violation detected in the driver.
|
|
128
108
|
*/
|
|
129
|
-
class UniqueConstraintViolationException extends ConstraintViolationException {
|
|
109
|
+
export class UniqueConstraintViolationException extends ConstraintViolationException {
|
|
130
110
|
}
|
|
131
|
-
exports.UniqueConstraintViolationException = UniqueConstraintViolationException;
|
package/hydration/Hydrator.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { EntityData, EntityMetadata, EntityProperty, IHydrator } from '../typings';
|
|
2
|
-
import type { EntityFactory } from '../entity/EntityFactory';
|
|
3
|
-
import type { Platform } from '../platforms/Platform';
|
|
4
|
-
import type { MetadataStorage } from '../metadata/MetadataStorage';
|
|
5
|
-
import type { Configuration } from '../utils/Configuration';
|
|
1
|
+
import type { EntityData, EntityMetadata, EntityProperty, IHydrator } from '../typings.js';
|
|
2
|
+
import type { EntityFactory } from '../entity/EntityFactory.js';
|
|
3
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
4
|
+
import type { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
5
|
+
import type { Configuration } from '../utils/Configuration.js';
|
|
6
6
|
export declare abstract class Hydrator implements IHydrator {
|
|
7
7
|
protected readonly metadata: MetadataStorage;
|
|
8
8
|
protected readonly platform: Platform;
|
package/hydration/Hydrator.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Hydrator = void 0;
|
|
4
|
-
/* istanbul ignore next */
|
|
5
|
-
class Hydrator {
|
|
1
|
+
/* v8 ignore next */
|
|
2
|
+
export class Hydrator {
|
|
6
3
|
metadata;
|
|
7
4
|
platform;
|
|
8
5
|
config;
|
|
@@ -48,4 +45,3 @@ class Hydrator {
|
|
|
48
45
|
entity[prop.name] = data[prop.name];
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
|
-
exports.Hydrator = Hydrator;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import type { EntityData, EntityMetadata } from '../typings';
|
|
2
|
-
import { Hydrator } from './Hydrator';
|
|
3
|
-
import type { EntityFactory } from '../entity/EntityFactory';
|
|
4
|
-
type EntityHydrator<T extends object> = (entity: T, data: EntityData<T>, factory: EntityFactory, newEntity: boolean, convertCustomTypes: boolean, schema?: string, parentSchema?: string) => void;
|
|
1
|
+
import type { EntityData, EntityMetadata } from '../typings.js';
|
|
2
|
+
import { Hydrator } from './Hydrator.js';
|
|
3
|
+
import type { EntityFactory } from '../entity/EntityFactory.js';
|
|
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
6
|
private readonly hydrators;
|
|
7
7
|
private tmpIndex;
|
|
8
8
|
/**
|
|
9
9
|
* @inheritDoc
|
|
10
10
|
*/
|
|
11
|
-
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
11
|
+
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
|
|
12
12
|
/**
|
|
13
13
|
* @inheritDoc
|
|
14
14
|
*/
|
|
15
|
-
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
15
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
|
|
16
16
|
/**
|
|
17
17
|
* @internal Highly performance-sensitive method.
|
|
18
18
|
*/
|
|
19
|
-
getEntityHydrator<T extends object>(meta: EntityMetadata<T>, type: 'full' | 'reference'): EntityHydrator<T>;
|
|
19
|
+
getEntityHydrator<T extends object>(meta: EntityMetadata<T>, type: 'full' | 'reference', normalizeAccessors?: boolean): EntityHydrator<T>;
|
|
20
20
|
private createCollectionItemMapper;
|
|
21
21
|
private wrap;
|
|
22
22
|
private safeKey;
|
|
@@ -1,57 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const enums_1 = require("../enums");
|
|
9
|
-
const RawQueryFragment_1 = require("../utils/RawQueryFragment");
|
|
10
|
-
class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
1
|
+
import { Hydrator } from './Hydrator.js';
|
|
2
|
+
import { Collection } from '../entity/Collection.js';
|
|
3
|
+
import { Reference, ScalarReference } from '../entity/Reference.js';
|
|
4
|
+
import { parseJsonSafe, Utils } from '../utils/Utils.js';
|
|
5
|
+
import { ReferenceKind } from '../enums.js';
|
|
6
|
+
import { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
7
|
+
export class ObjectHydrator extends Hydrator {
|
|
11
8
|
hydrators = {
|
|
12
|
-
full: new Map(),
|
|
13
|
-
|
|
9
|
+
'full~true': new Map(),
|
|
10
|
+
'full~false': new Map(),
|
|
11
|
+
'reference~true': new Map(),
|
|
12
|
+
'reference~false': new Map(),
|
|
14
13
|
};
|
|
15
14
|
tmpIndex = 0;
|
|
16
15
|
/**
|
|
17
16
|
* @inheritDoc
|
|
18
17
|
*/
|
|
19
|
-
hydrate(entity, meta, data, factory, type, newEntity = false, convertCustomTypes = false, schema, parentSchema) {
|
|
20
|
-
const hydrate = this.getEntityHydrator(meta, type);
|
|
18
|
+
hydrate(entity, meta, data, factory, type, newEntity = false, convertCustomTypes = false, schema, parentSchema, normalizeAccessors) {
|
|
19
|
+
const hydrate = this.getEntityHydrator(meta, type, normalizeAccessors);
|
|
21
20
|
const running = this.running;
|
|
22
21
|
// the running state is used to consider propagation as hydration, saving the values directly to the entity data,
|
|
23
22
|
// but we don't want that for new entities, their propagation should result in entity updates when flushing
|
|
24
23
|
this.running = !newEntity;
|
|
25
|
-
|
|
24
|
+
Utils.callCompiledFunction(hydrate, entity, data, factory, newEntity, convertCustomTypes, schema, parentSchema, normalizeAccessors);
|
|
26
25
|
this.running = running;
|
|
27
26
|
}
|
|
28
27
|
/**
|
|
29
28
|
* @inheritDoc
|
|
30
29
|
*/
|
|
31
|
-
hydrateReference(entity, meta, data, factory, convertCustomTypes = false, schema, parentSchema) {
|
|
32
|
-
const hydrate = this.getEntityHydrator(meta, 'reference');
|
|
30
|
+
hydrateReference(entity, meta, data, factory, convertCustomTypes = false, schema, parentSchema, normalizeAccessors) {
|
|
31
|
+
const hydrate = this.getEntityHydrator(meta, 'reference', normalizeAccessors);
|
|
33
32
|
const running = this.running;
|
|
34
33
|
this.running = true;
|
|
35
|
-
|
|
34
|
+
Utils.callCompiledFunction(hydrate, entity, data, factory, false, convertCustomTypes, schema, parentSchema, normalizeAccessors);
|
|
36
35
|
this.running = running;
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* @internal Highly performance-sensitive method.
|
|
40
39
|
*/
|
|
41
|
-
getEntityHydrator(meta, type) {
|
|
42
|
-
const
|
|
40
|
+
getEntityHydrator(meta, type, normalizeAccessors = false) {
|
|
41
|
+
const key = `${type}~${normalizeAccessors}`;
|
|
42
|
+
const exists = this.hydrators[key].get(meta.className);
|
|
43
43
|
if (exists) {
|
|
44
44
|
return exists;
|
|
45
45
|
}
|
|
46
46
|
const lines = [];
|
|
47
47
|
const context = new Map();
|
|
48
48
|
const props = this.getProperties(meta, type);
|
|
49
|
-
context.set('isPrimaryKey',
|
|
50
|
-
context.set('Collection',
|
|
51
|
-
context.set('Reference',
|
|
49
|
+
context.set('isPrimaryKey', Utils.isPrimaryKey);
|
|
50
|
+
context.set('Collection', Collection);
|
|
51
|
+
context.set('Reference', Reference);
|
|
52
52
|
const registerCustomType = (prop, convertorKey, method, context) => {
|
|
53
53
|
context.set(`${method}_${convertorKey}`, (val) => {
|
|
54
|
-
|
|
54
|
+
/* v8 ignore next */
|
|
55
|
+
if (RawQueryFragment.isKnownFragment(val)) {
|
|
55
56
|
return val;
|
|
56
57
|
}
|
|
57
58
|
return prop.customType[method](val, this.platform, { mode: 'serialization' });
|
|
@@ -65,15 +66,22 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
65
66
|
const ret = [];
|
|
66
67
|
const idx = this.tmpIndex++;
|
|
67
68
|
const nullVal = this.config.get('forceUndefined') ? 'undefined' : 'null';
|
|
68
|
-
if (prop.getter && !prop.setter) {
|
|
69
|
+
if (prop.getter && !prop.setter && prop.persist === false) {
|
|
69
70
|
return [];
|
|
70
71
|
}
|
|
71
72
|
if (prop.ref) {
|
|
72
|
-
context.set('ScalarReference',
|
|
73
|
+
context.set('ScalarReference', ScalarReference);
|
|
73
74
|
ret.push(` const oldValue_${idx} = entity${entityKey};`);
|
|
74
75
|
}
|
|
75
76
|
ret.push(` if (data${dataKey} === null) {`);
|
|
76
|
-
|
|
77
|
+
if (prop.ref) {
|
|
78
|
+
ret.push(` entity${entityKey} = new ScalarReference();`);
|
|
79
|
+
ret.push(` entity${entityKey}.bind(entity, '${prop.name}');`);
|
|
80
|
+
ret.push(` entity${entityKey}.set(${nullVal});`);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
ret.push(` entity${entityKey} = ${nullVal};`);
|
|
84
|
+
}
|
|
77
85
|
ret.push(` } else if (typeof data${dataKey} !== 'undefined') {`);
|
|
78
86
|
if (prop.customType) {
|
|
79
87
|
registerCustomType(prop, convertorKey, 'convertToJSValue', context);
|
|
@@ -128,21 +136,21 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
128
136
|
ret.push(` } else if (typeof data${dataKey} !== 'undefined') {`);
|
|
129
137
|
ret.push(` if (isPrimaryKey(data${dataKey}, true)) {`);
|
|
130
138
|
if (prop.ref) {
|
|
131
|
-
ret.push(` entity${entityKey} = Reference.create(factory.createReference('${prop.type}', data${dataKey}, { merge: true, convertCustomTypes, schema }));`);
|
|
139
|
+
ret.push(` entity${entityKey} = Reference.create(factory.createReference('${prop.type}', data${dataKey}, { merge: true, convertCustomTypes, normalizeAccessors, schema }));`);
|
|
132
140
|
}
|
|
133
141
|
else {
|
|
134
|
-
ret.push(` entity${entityKey} = factory.createReference('${prop.type}', data${dataKey}, { merge: true, convertCustomTypes, schema });`);
|
|
142
|
+
ret.push(` entity${entityKey} = factory.createReference('${prop.type}', data${dataKey}, { merge: true, convertCustomTypes, normalizeAccessors, schema });`);
|
|
135
143
|
}
|
|
136
144
|
ret.push(` } else if (data${dataKey} && typeof data${dataKey} === 'object') {`);
|
|
137
145
|
if (prop.ref) {
|
|
138
|
-
ret.push(` entity${entityKey} = Reference.create(factory.${method}('${prop.type}', data${dataKey}, { initialized: true, merge: true, newEntity, convertCustomTypes, schema }));`);
|
|
146
|
+
ret.push(` entity${entityKey} = Reference.create(factory.${method}('${prop.type}', data${dataKey}, { initialized: true, merge: true, newEntity, convertCustomTypes, normalizeAccessors, schema }));`);
|
|
139
147
|
}
|
|
140
148
|
else {
|
|
141
|
-
ret.push(` entity${entityKey} = factory.${method}('${prop.type}', data${dataKey}, { initialized: true, merge: true, newEntity, convertCustomTypes, schema });`);
|
|
149
|
+
ret.push(` entity${entityKey} = factory.${method}('${prop.type}', data${dataKey}, { initialized: true, merge: true, newEntity, convertCustomTypes, normalizeAccessors, schema });`);
|
|
142
150
|
}
|
|
143
151
|
ret.push(` }`);
|
|
144
152
|
ret.push(` }`);
|
|
145
|
-
if (prop.kind ===
|
|
153
|
+
if (prop.kind === ReferenceKind.ONE_TO_ONE) {
|
|
146
154
|
const meta2 = this.metadata.get(prop.type);
|
|
147
155
|
const prop2 = meta2.properties[prop.inversedBy || prop.mappedBy];
|
|
148
156
|
if (prop2 && !prop2.mapToPk) {
|
|
@@ -175,7 +183,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
175
183
|
ret.push(` }`);
|
|
176
184
|
ret.push(` } else if (!entity${entityKey} && data${dataKey} instanceof Collection) {`);
|
|
177
185
|
ret.push(` entity${entityKey} = data${dataKey};`);
|
|
178
|
-
if (!this.platform.usesPivotTable() && prop.owner && prop.kind ===
|
|
186
|
+
if (!this.platform.usesPivotTable() && prop.owner && prop.kind === ReferenceKind.MANY_TO_MANY) {
|
|
179
187
|
ret.push(` } else if (!entity${entityKey} && Array.isArray(data${dataKey})) {`);
|
|
180
188
|
const items = this.platform.usesPivotTable() || !prop.owner ? 'undefined' : '[]';
|
|
181
189
|
ret.push(` const coll = Collection.create(entity, '${prop.name}', ${items}, !!data${dataKey} || newEntity);`);
|
|
@@ -200,7 +208,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
200
208
|
};
|
|
201
209
|
const parseObjectEmbeddable = (prop, dataKey, ret) => {
|
|
202
210
|
if (!this.platform.convertsJsonAutomatically() && (prop.object || prop.array)) {
|
|
203
|
-
context.set('parseJsonSafe',
|
|
211
|
+
context.set('parseJsonSafe', parseJsonSafe);
|
|
204
212
|
ret.push(` if (typeof data${dataKey} === 'string') {`, ` data${dataKey} = parseJsonSafe(data${dataKey});`, ` }`);
|
|
205
213
|
}
|
|
206
214
|
};
|
|
@@ -214,7 +222,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
214
222
|
meta.props
|
|
215
223
|
.filter(p => p.embedded?.[0] === prop.name)
|
|
216
224
|
.forEach(p => {
|
|
217
|
-
if (p.kind ===
|
|
225
|
+
if (p.kind === ReferenceKind.EMBEDDED && !p.object && !p.array) {
|
|
218
226
|
conds.push(...createCond(p, dataKey + this.wrap(p.embedded[1]), cond));
|
|
219
227
|
return;
|
|
220
228
|
}
|
|
@@ -247,7 +255,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
247
255
|
// weak comparison as we can have numbers that might have been converted to strings due to being object keys
|
|
248
256
|
ret.push(` if (data${childDataKey} == '${childMeta.discriminatorValue}') {`);
|
|
249
257
|
ret.push(` if (entity${entityKey} == null) {`);
|
|
250
|
-
ret.push(` entity${entityKey} = factory.createEmbeddable('${childMeta.className}', embeddedData, { newEntity, convertCustomTypes });`);
|
|
258
|
+
ret.push(` entity${entityKey} = factory.createEmbeddable('${childMeta.className}', embeddedData, { newEntity, convertCustomTypes, normalizeAccessors });`);
|
|
251
259
|
ret.push(` }`);
|
|
252
260
|
meta.props
|
|
253
261
|
.filter(p => p.embedded?.[0] === prop.name)
|
|
@@ -258,6 +266,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
258
266
|
...prop2,
|
|
259
267
|
name: childProp.name,
|
|
260
268
|
embedded: childProp.embedded,
|
|
269
|
+
embeddedProps: childProp.embeddedProps,
|
|
261
270
|
};
|
|
262
271
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
263
272
|
ret.push(...hydrateProperty(prop3, childProp.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
|
|
@@ -267,7 +276,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
267
276
|
}
|
|
268
277
|
else {
|
|
269
278
|
ret.push(` if (entity${entityKey} == null) {`);
|
|
270
|
-
ret.push(` entity${entityKey} = factory.createEmbeddable('${prop.targetMeta.className}', embeddedData, { newEntity, convertCustomTypes });`);
|
|
279
|
+
ret.push(` entity${entityKey} = factory.createEmbeddable('${prop.targetMeta.className}', embeddedData, { newEntity, convertCustomTypes, normalizeAccessors });`);
|
|
271
280
|
ret.push(` }`);
|
|
272
281
|
meta.props
|
|
273
282
|
.filter(p => p.embedded?.[0] === prop.name)
|
|
@@ -277,7 +286,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
277
286
|
ret.push(...hydrateProperty(childProp, prop.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
|
|
278
287
|
});
|
|
279
288
|
}
|
|
280
|
-
/*
|
|
289
|
+
/* v8 ignore next */
|
|
281
290
|
const nullVal = this.config.get('forceUndefined') ? 'undefined' : 'null';
|
|
282
291
|
if (prop.object) {
|
|
283
292
|
ret.push(` } else if (data${dataKey} === null) {`);
|
|
@@ -305,15 +314,15 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
305
314
|
};
|
|
306
315
|
const hydrateProperty = (prop, object = prop.object, path = [prop.name], dataKey) => {
|
|
307
316
|
const entityKey = path.map(k => this.wrap(k)).join('');
|
|
308
|
-
dataKey = dataKey ?? (object ? entityKey : this.wrap(prop.name));
|
|
317
|
+
dataKey = dataKey ?? (object ? entityKey : this.wrap(normalizeAccessors ? (prop.accessor ?? prop.name) : prop.name));
|
|
309
318
|
const ret = [];
|
|
310
|
-
if ([
|
|
319
|
+
if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && !prop.mapToPk) {
|
|
311
320
|
ret.push(...hydrateToOne(prop, dataKey, entityKey));
|
|
312
321
|
}
|
|
313
|
-
else if (prop.kind ===
|
|
322
|
+
else if (prop.kind === ReferenceKind.ONE_TO_MANY || prop.kind === ReferenceKind.MANY_TO_MANY) {
|
|
314
323
|
ret.push(...hydrateToMany(prop, dataKey, entityKey));
|
|
315
324
|
}
|
|
316
|
-
else if (prop.kind ===
|
|
325
|
+
else if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
317
326
|
if (prop.array) {
|
|
318
327
|
ret.push(...hydrateEmbeddedArray(prop, path, dataKey));
|
|
319
328
|
}
|
|
@@ -335,11 +344,11 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
335
344
|
for (const prop of props) {
|
|
336
345
|
lines.push(...hydrateProperty(prop));
|
|
337
346
|
}
|
|
338
|
-
const code = `// compiled hydrator for entity ${meta.className} (${type})\n`
|
|
339
|
-
+ `return function(entity, data, factory, newEntity, convertCustomTypes, schema) {\n`
|
|
347
|
+
const code = `// compiled hydrator for entity ${meta.className} (${type + normalizeAccessors ? ' normalized' : ''})\n`
|
|
348
|
+
+ `return function(entity, data, factory, newEntity, convertCustomTypes, schema, parentSchema, normalizeAccessors) {\n`
|
|
340
349
|
+ `${lines.join('\n')}\n}`;
|
|
341
|
-
const hydrator =
|
|
342
|
-
this.hydrators[
|
|
350
|
+
const hydrator = Utils.createFunction(context, code);
|
|
351
|
+
this.hydrators[key].set(meta.className, hydrator);
|
|
343
352
|
return hydrator;
|
|
344
353
|
}
|
|
345
354
|
createCollectionItemMapper(prop) {
|
|
@@ -347,14 +356,14 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
347
356
|
const lines = [];
|
|
348
357
|
lines.push(` const createCollectionItem_${this.safeKey(prop.name)} = (value, entity) => {`);
|
|
349
358
|
const prop2 = prop.targetMeta.properties[prop.mappedBy];
|
|
350
|
-
if (prop.kind ===
|
|
359
|
+
if (prop.kind === ReferenceKind.ONE_TO_MANY && prop2.primary) {
|
|
351
360
|
lines.push(` if (typeof value === 'object' && value?.['${prop2.name}'] == null) {`);
|
|
352
361
|
lines.push(` value = { ...value, ['${prop2.name}']: Reference.wrapReference(entity, { ref: ${prop2.ref} }) };`);
|
|
353
362
|
lines.push(` }`);
|
|
354
363
|
}
|
|
355
|
-
lines.push(` if (isPrimaryKey(value, ${meta.compositePK})) return factory.createReference('${prop.type}', value, { convertCustomTypes, schema, merge: true });`);
|
|
364
|
+
lines.push(` if (isPrimaryKey(value, ${meta.compositePK})) return factory.createReference('${prop.type}', value, { convertCustomTypes, schema, normalizeAccessors, merge: true });`);
|
|
356
365
|
lines.push(` if (value && value.__entity) return value;`);
|
|
357
|
-
lines.push(` return factory.create('${prop.type}', value, { newEntity, convertCustomTypes, schema, merge: true });`);
|
|
366
|
+
lines.push(` return factory.create('${prop.type}', value, { newEntity, convertCustomTypes, schema, normalizeAccessors, merge: true });`);
|
|
358
367
|
lines.push(` }`);
|
|
359
368
|
return lines;
|
|
360
369
|
}
|
|
@@ -368,4 +377,3 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
368
377
|
return key.replace(/\W/g, '_');
|
|
369
378
|
}
|
|
370
379
|
}
|
|
371
|
-
exports.ObjectHydrator = ObjectHydrator;
|