@yandjin-mikro-orm/core 6.1.4-rc-sti-changes-1
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 +553 -0
- package/EntityManager.js +1736 -0
- package/LICENSE +21 -0
- package/MikroORM.d.ts +102 -0
- package/MikroORM.js +258 -0
- package/README.md +383 -0
- package/cache/CacheAdapter.d.ts +40 -0
- package/cache/CacheAdapter.js +2 -0
- package/cache/FileCacheAdapter.d.ts +31 -0
- package/cache/FileCacheAdapter.js +90 -0
- package/cache/GeneratedCacheAdapter.d.ts +25 -0
- package/cache/GeneratedCacheAdapter.js +38 -0
- package/cache/MemoryCacheAdapter.d.ts +24 -0
- package/cache/MemoryCacheAdapter.js +44 -0
- package/cache/NullCacheAdapter.d.ts +19 -0
- package/cache/NullCacheAdapter.js +30 -0
- package/cache/index.d.ts +5 -0
- package/cache/index.js +21 -0
- package/connections/Connection.d.ts +85 -0
- package/connections/Connection.js +128 -0
- package/connections/index.d.ts +1 -0
- package/connections/index.js +17 -0
- package/decorators/Check.d.ts +3 -0
- package/decorators/Check.js +17 -0
- package/decorators/CreateRequestContext.d.ts +2 -0
- package/decorators/CreateRequestContext.js +31 -0
- package/decorators/Embeddable.d.ts +8 -0
- package/decorators/Embeddable.js +15 -0
- package/decorators/Embedded.d.ts +13 -0
- package/decorators/Embedded.js +21 -0
- package/decorators/EnsureRequestContext.d.ts +2 -0
- package/decorators/EnsureRequestContext.js +26 -0
- package/decorators/Entity.d.ts +18 -0
- package/decorators/Entity.js +17 -0
- package/decorators/Enum.d.ts +9 -0
- package/decorators/Enum.js +20 -0
- package/decorators/Filter.d.ts +2 -0
- package/decorators/Filter.js +12 -0
- package/decorators/Formula.d.ts +5 -0
- package/decorators/Formula.js +19 -0
- package/decorators/Indexed.d.ts +12 -0
- package/decorators/Indexed.js +25 -0
- package/decorators/ManyToMany.d.ts +21 -0
- package/decorators/ManyToMany.js +17 -0
- package/decorators/ManyToOne.d.ts +15 -0
- package/decorators/ManyToOne.js +17 -0
- package/decorators/OneToMany.d.ts +18 -0
- package/decorators/OneToMany.js +21 -0
- package/decorators/OneToOne.d.ts +12 -0
- package/decorators/OneToOne.js +11 -0
- package/decorators/PrimaryKey.d.ts +8 -0
- package/decorators/PrimaryKey.js +24 -0
- package/decorators/Property.d.ts +218 -0
- package/decorators/Property.js +35 -0
- package/decorators/Subscriber.d.ts +1 -0
- package/decorators/Subscriber.js +2 -0
- package/decorators/hooks.d.ts +16 -0
- package/decorators/hooks.js +60 -0
- package/decorators/index.d.ts +17 -0
- package/decorators/index.js +36 -0
- package/drivers/DatabaseDriver.d.ts +72 -0
- package/drivers/DatabaseDriver.js +358 -0
- package/drivers/IDatabaseDriver.d.ts +193 -0
- package/drivers/IDatabaseDriver.js +4 -0
- package/drivers/index.d.ts +2 -0
- package/drivers/index.js +18 -0
- package/entity/ArrayCollection.d.ts +113 -0
- package/entity/ArrayCollection.js +386 -0
- package/entity/BaseEntity.d.ts +22 -0
- package/entity/BaseEntity.js +47 -0
- package/entity/Collection.d.ts +104 -0
- package/entity/Collection.js +373 -0
- package/entity/EntityAssigner.d.ts +28 -0
- package/entity/EntityAssigner.js +226 -0
- package/entity/EntityFactory.d.ts +41 -0
- package/entity/EntityFactory.js +302 -0
- package/entity/EntityHelper.d.ts +29 -0
- package/entity/EntityHelper.js +250 -0
- package/entity/EntityIdentifier.d.ts +10 -0
- package/entity/EntityIdentifier.js +19 -0
- package/entity/EntityLoader.d.ts +65 -0
- package/entity/EntityLoader.js +579 -0
- package/entity/EntityRepository.d.ts +161 -0
- package/entity/EntityRepository.js +207 -0
- package/entity/EntityValidator.d.ts +19 -0
- package/entity/EntityValidator.js +152 -0
- package/entity/Reference.d.ts +89 -0
- package/entity/Reference.js +242 -0
- package/entity/WrappedEntity.d.ts +67 -0
- package/entity/WrappedEntity.js +146 -0
- package/entity/index.d.ts +13 -0
- package/entity/index.js +29 -0
- package/entity/wrap.d.ts +15 -0
- package/entity/wrap.js +26 -0
- package/enums.d.ts +160 -0
- package/enums.js +169 -0
- package/errors.d.ts +65 -0
- package/errors.js +222 -0
- package/events/EventManager.d.ts +17 -0
- package/events/EventManager.js +77 -0
- package/events/EventSubscriber.d.ts +39 -0
- package/events/EventSubscriber.js +2 -0
- package/events/TransactionEventBroadcaster.d.ts +11 -0
- package/events/TransactionEventBroadcaster.js +17 -0
- package/events/index.d.ts +3 -0
- package/events/index.js +19 -0
- package/exceptions.d.ts +104 -0
- package/exceptions.js +130 -0
- package/hydration/Hydrator.d.ts +23 -0
- package/hydration/Hydrator.js +51 -0
- package/hydration/ObjectHydrator.d.ts +24 -0
- package/hydration/ObjectHydrator.js +332 -0
- package/hydration/index.d.ts +2 -0
- package/hydration/index.js +18 -0
- package/index.d.ts +25 -0
- package/index.js +50 -0
- package/index.mjs +192 -0
- package/logging/DefaultLogger.d.ts +32 -0
- package/logging/DefaultLogger.js +90 -0
- package/logging/Logger.d.ts +56 -0
- package/logging/Logger.js +2 -0
- package/logging/SimpleLogger.d.ts +17 -0
- package/logging/SimpleLogger.js +31 -0
- package/logging/colors.d.ts +9 -0
- package/logging/colors.js +20 -0
- package/logging/index.d.ts +4 -0
- package/logging/index.js +20 -0
- package/metadata/EntitySchema.d.ts +74 -0
- package/metadata/EntitySchema.js +293 -0
- package/metadata/MetadataDiscovery.d.ts +71 -0
- package/metadata/MetadataDiscovery.js +1244 -0
- package/metadata/MetadataProvider.d.ts +11 -0
- package/metadata/MetadataProvider.js +23 -0
- package/metadata/MetadataStorage.d.ts +22 -0
- package/metadata/MetadataStorage.js +87 -0
- package/metadata/MetadataValidator.d.ts +24 -0
- package/metadata/MetadataValidator.js +213 -0
- package/metadata/ReflectMetadataProvider.d.ts +8 -0
- package/metadata/ReflectMetadataProvider.js +48 -0
- package/metadata/index.d.ts +6 -0
- package/metadata/index.js +22 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +18 -0
- package/naming-strategy/AbstractNamingStrategy.js +48 -0
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +12 -0
- package/naming-strategy/EntityCaseNamingStrategy.js +32 -0
- package/naming-strategy/MongoNamingStrategy.d.ts +9 -0
- package/naming-strategy/MongoNamingStrategy.js +25 -0
- package/naming-strategy/NamingStrategy.d.ts +52 -0
- package/naming-strategy/NamingStrategy.js +2 -0
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +10 -0
- package/naming-strategy/UnderscoreNamingStrategy.js +28 -0
- package/naming-strategy/index.d.ts +5 -0
- package/naming-strategy/index.js +21 -0
- package/package.json +70 -0
- package/platforms/ExceptionConverter.d.ts +5 -0
- package/platforms/ExceptionConverter.js +11 -0
- package/platforms/Platform.d.ts +201 -0
- package/platforms/Platform.js +452 -0
- package/platforms/index.d.ts +2 -0
- package/platforms/index.js +18 -0
- package/serialization/EntitySerializer.d.ts +34 -0
- package/serialization/EntitySerializer.js +206 -0
- package/serialization/EntityTransformer.d.ts +8 -0
- package/serialization/EntityTransformer.js +192 -0
- package/serialization/SerializationContext.d.ts +30 -0
- package/serialization/SerializationContext.js +111 -0
- package/serialization/index.d.ts +3 -0
- package/serialization/index.js +19 -0
- package/types/ArrayType.d.ts +13 -0
- package/types/ArrayType.js +47 -0
- package/types/BigIntType.d.ts +16 -0
- package/types/BigIntType.js +45 -0
- package/types/BlobType.d.ts +10 -0
- package/types/BlobType.js +27 -0
- package/types/BooleanType.d.ts +8 -0
- package/types/BooleanType.js +16 -0
- package/types/DateTimeType.d.ts +8 -0
- package/types/DateTimeType.js +16 -0
- package/types/DateType.d.ts +8 -0
- package/types/DateType.js +16 -0
- package/types/DecimalType.d.ts +11 -0
- package/types/DecimalType.js +22 -0
- package/types/DoubleType.d.ts +11 -0
- package/types/DoubleType.js +22 -0
- package/types/EnumArrayType.d.ts +9 -0
- package/types/EnumArrayType.js +32 -0
- package/types/EnumType.d.ts +8 -0
- package/types/EnumType.js +16 -0
- package/types/FloatType.d.ts +8 -0
- package/types/FloatType.js +16 -0
- package/types/IntegerType.d.ts +8 -0
- package/types/IntegerType.js +16 -0
- package/types/IntervalType.d.ts +8 -0
- package/types/IntervalType.js +16 -0
- package/types/JsonType.d.ts +13 -0
- package/types/JsonType.js +34 -0
- package/types/MediumIntType.d.ts +6 -0
- package/types/MediumIntType.js +10 -0
- package/types/SmallIntType.d.ts +8 -0
- package/types/SmallIntType.js +16 -0
- package/types/StringType.d.ts +8 -0
- package/types/StringType.js +16 -0
- package/types/TextType.d.ts +8 -0
- package/types/TextType.js +16 -0
- package/types/TimeType.d.ts +9 -0
- package/types/TimeType.js +23 -0
- package/types/TinyIntType.d.ts +8 -0
- package/types/TinyIntType.js +16 -0
- package/types/Type.d.ts +64 -0
- package/types/Type.js +84 -0
- package/types/Uint8ArrayType.d.ts +11 -0
- package/types/Uint8ArrayType.js +37 -0
- package/types/UnknownType.d.ts +7 -0
- package/types/UnknownType.js +13 -0
- package/types/UuidType.d.ts +7 -0
- package/types/UuidType.js +13 -0
- package/types/index.d.ts +75 -0
- package/types/index.js +77 -0
- package/typings.d.ts +767 -0
- package/typings.js +198 -0
- package/unit-of-work/ChangeSet.d.ts +34 -0
- package/unit-of-work/ChangeSet.js +62 -0
- package/unit-of-work/ChangeSetComputer.d.ts +26 -0
- package/unit-of-work/ChangeSetComputer.js +153 -0
- package/unit-of-work/ChangeSetPersister.d.ts +50 -0
- package/unit-of-work/ChangeSetPersister.js +361 -0
- package/unit-of-work/CommitOrderCalculator.d.ts +62 -0
- package/unit-of-work/CommitOrderCalculator.js +113 -0
- package/unit-of-work/IdentityMap.d.ts +17 -0
- package/unit-of-work/IdentityMap.js +84 -0
- package/unit-of-work/UnitOfWork.d.ts +124 -0
- package/unit-of-work/UnitOfWork.js +1013 -0
- package/unit-of-work/index.d.ts +6 -0
- package/unit-of-work/index.js +22 -0
- package/utils/AbstractSchemaGenerator.d.ts +38 -0
- package/utils/AbstractSchemaGenerator.js +101 -0
- package/utils/Configuration.d.ts +390 -0
- package/utils/Configuration.js +357 -0
- package/utils/ConfigurationLoader.d.ts +29 -0
- package/utils/ConfigurationLoader.js +282 -0
- package/utils/Cursor.d.ts +77 -0
- package/utils/Cursor.js +169 -0
- package/utils/DataloaderUtils.d.ts +43 -0
- package/utils/DataloaderUtils.js +194 -0
- package/utils/EntityComparator.d.ts +73 -0
- package/utils/EntityComparator.js +568 -0
- package/utils/NullHighlighter.d.ts +4 -0
- package/utils/NullHighlighter.js +9 -0
- package/utils/QueryHelper.d.ts +28 -0
- package/utils/QueryHelper.js +228 -0
- package/utils/RawQueryFragment.d.ts +96 -0
- package/utils/RawQueryFragment.js +188 -0
- package/utils/RequestContext.d.ts +34 -0
- package/utils/RequestContext.js +54 -0
- package/utils/TransactionContext.d.ts +19 -0
- package/utils/TransactionContext.js +34 -0
- package/utils/Utils.d.ts +274 -0
- package/utils/Utils.js +1073 -0
- package/utils/clone.d.ts +6 -0
- package/utils/clone.js +127 -0
- package/utils/index.d.ts +13 -0
- package/utils/index.js +29 -0
- package/utils/upsert-utils.d.ts +6 -0
- package/utils/upsert-utils.js +33 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventManager = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const enums_1 = require("../enums");
|
|
6
|
+
class EventManager {
|
|
7
|
+
listeners = {};
|
|
8
|
+
entities = new Map();
|
|
9
|
+
cache = new Map();
|
|
10
|
+
subscribers = [];
|
|
11
|
+
constructor(subscribers) {
|
|
12
|
+
subscribers.forEach(subscriber => this.registerSubscriber(subscriber));
|
|
13
|
+
}
|
|
14
|
+
registerSubscriber(subscriber) {
|
|
15
|
+
this.subscribers.push(subscriber);
|
|
16
|
+
this.entities.set(subscriber, this.getSubscribedEntities(subscriber));
|
|
17
|
+
this.cache.clear();
|
|
18
|
+
utils_1.Utils.keys(enums_1.EventType)
|
|
19
|
+
.filter(event => event in subscriber)
|
|
20
|
+
.forEach(event => {
|
|
21
|
+
this.listeners[event] ??= [];
|
|
22
|
+
this.listeners[event].push(subscriber);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
dispatchEvent(event, args, meta) {
|
|
26
|
+
const listeners = [];
|
|
27
|
+
const entity = args.entity;
|
|
28
|
+
// execute lifecycle hooks first
|
|
29
|
+
meta ??= entity?.__meta;
|
|
30
|
+
const hooks = (meta?.hooks[event] || []);
|
|
31
|
+
listeners.push(...hooks.map(hook => {
|
|
32
|
+
const prototypeHook = meta?.prototype[hook];
|
|
33
|
+
const handler = typeof hook === 'function' ? hook : entity[hook] ?? prototypeHook;
|
|
34
|
+
return handler.bind(entity);
|
|
35
|
+
}));
|
|
36
|
+
for (const listener of this.listeners[event] || []) {
|
|
37
|
+
const entities = this.entities.get(listener);
|
|
38
|
+
if (entities.length === 0 || !entity || entities.includes(entity.constructor.name)) {
|
|
39
|
+
listeners.push(listener[event].bind(listener));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (event === enums_1.EventType.onInit) {
|
|
43
|
+
return listeners.forEach(listener => listener(args));
|
|
44
|
+
}
|
|
45
|
+
return utils_1.Utils.runSerial(listeners, listener => listener(args));
|
|
46
|
+
}
|
|
47
|
+
hasListeners(event, meta) {
|
|
48
|
+
const cacheKey = meta._id + enums_1.EventTypeMap[event];
|
|
49
|
+
if (this.cache.has(cacheKey)) {
|
|
50
|
+
return this.cache.get(cacheKey);
|
|
51
|
+
}
|
|
52
|
+
const hasHooks = meta.hooks[event]?.length;
|
|
53
|
+
if (hasHooks) {
|
|
54
|
+
this.cache.set(cacheKey, true);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
for (const listener of this.listeners[event] ?? []) {
|
|
58
|
+
const entities = this.entities.get(listener);
|
|
59
|
+
if (entities.length === 0 || entities.includes(meta.className)) {
|
|
60
|
+
this.cache.set(cacheKey, true);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
this.cache.set(cacheKey, false);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
clone() {
|
|
68
|
+
return new EventManager(this.subscribers);
|
|
69
|
+
}
|
|
70
|
+
getSubscribedEntities(listener) {
|
|
71
|
+
if (!listener.getSubscribedEntities) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
return listener.getSubscribedEntities().map(name => utils_1.Utils.className(name));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.EventManager = EventManager;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { EntityName, EntityMetadata } from '../typings';
|
|
2
|
+
import type { EntityManager } from '../EntityManager';
|
|
3
|
+
import type { ChangeSet, UnitOfWork } from '../unit-of-work';
|
|
4
|
+
import type { Transaction } from '../connections';
|
|
5
|
+
export interface EventArgs<T> {
|
|
6
|
+
entity: T;
|
|
7
|
+
em: EntityManager;
|
|
8
|
+
meta: EntityMetadata<T>;
|
|
9
|
+
changeSet?: ChangeSet<T & {}>;
|
|
10
|
+
}
|
|
11
|
+
export interface FlushEventArgs extends Omit<EventArgs<any>, 'entity' | 'changeSet' | 'meta'> {
|
|
12
|
+
uow: UnitOfWork;
|
|
13
|
+
}
|
|
14
|
+
export interface TransactionEventArgs extends Omit<EventArgs<any>, 'entity' | 'meta' | 'changeSet'> {
|
|
15
|
+
transaction?: Transaction;
|
|
16
|
+
uow?: UnitOfWork;
|
|
17
|
+
}
|
|
18
|
+
export interface EventSubscriber<T = any> {
|
|
19
|
+
getSubscribedEntities?(): EntityName<T>[];
|
|
20
|
+
onInit?(args: EventArgs<T>): void;
|
|
21
|
+
onLoad?(args: EventArgs<T>): void | Promise<void>;
|
|
22
|
+
beforeCreate?(args: EventArgs<T>): void | Promise<void>;
|
|
23
|
+
afterCreate?(args: EventArgs<T>): void | Promise<void>;
|
|
24
|
+
beforeUpdate?(args: EventArgs<T>): void | Promise<void>;
|
|
25
|
+
afterUpdate?(args: EventArgs<T>): void | Promise<void>;
|
|
26
|
+
beforeUpsert?(args: EventArgs<T>): void | Promise<void>;
|
|
27
|
+
afterUpsert?(args: EventArgs<T>): void | Promise<void>;
|
|
28
|
+
beforeDelete?(args: EventArgs<T>): void | Promise<void>;
|
|
29
|
+
afterDelete?(args: EventArgs<T>): void | Promise<void>;
|
|
30
|
+
beforeFlush?(args: FlushEventArgs): void | Promise<void>;
|
|
31
|
+
onFlush?(args: FlushEventArgs): void | Promise<void>;
|
|
32
|
+
afterFlush?(args: FlushEventArgs): void | Promise<void>;
|
|
33
|
+
beforeTransactionStart?(args: TransactionEventArgs): void | Promise<void>;
|
|
34
|
+
afterTransactionStart?(args: TransactionEventArgs): void | Promise<void>;
|
|
35
|
+
beforeTransactionCommit?(args: TransactionEventArgs): void | Promise<void>;
|
|
36
|
+
afterTransactionCommit?(args: TransactionEventArgs): void | Promise<void>;
|
|
37
|
+
beforeTransactionRollback?(args: TransactionEventArgs): void | Promise<void>;
|
|
38
|
+
afterTransactionRollback?(args: TransactionEventArgs): void | Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Transaction } from '../connections';
|
|
2
|
+
import type { EntityManager } from '../EntityManager';
|
|
3
|
+
import type { TransactionEventType } from '../enums';
|
|
4
|
+
import type { UnitOfWork } from '../unit-of-work';
|
|
5
|
+
export declare class TransactionEventBroadcaster {
|
|
6
|
+
private readonly em;
|
|
7
|
+
private readonly uow?;
|
|
8
|
+
private readonly eventManager;
|
|
9
|
+
constructor(em: EntityManager, uow?: UnitOfWork | undefined);
|
|
10
|
+
dispatchEvent(event: TransactionEventType, transaction?: Transaction): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionEventBroadcaster = void 0;
|
|
4
|
+
class TransactionEventBroadcaster {
|
|
5
|
+
em;
|
|
6
|
+
uow;
|
|
7
|
+
eventManager;
|
|
8
|
+
constructor(em, uow) {
|
|
9
|
+
this.em = em;
|
|
10
|
+
this.uow = uow;
|
|
11
|
+
this.eventManager = this.em.getEventManager();
|
|
12
|
+
}
|
|
13
|
+
async dispatchEvent(event, transaction) {
|
|
14
|
+
await this.eventManager.dispatchEvent(event, { em: this.em, transaction, uow: this.uow });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.TransactionEventBroadcaster = TransactionEventBroadcaster;
|
package/events/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
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("./EventSubscriber"), exports);
|
|
18
|
+
__exportStar(require("./EventManager"), exports);
|
|
19
|
+
__exportStar(require("./TransactionEventBroadcaster"), exports);
|
package/exceptions.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for all errors detected in the driver.
|
|
3
|
+
*/
|
|
4
|
+
export declare class DriverException extends Error {
|
|
5
|
+
code?: string;
|
|
6
|
+
errno?: number;
|
|
7
|
+
sqlState?: string;
|
|
8
|
+
sqlMessage?: string;
|
|
9
|
+
errmsg?: string;
|
|
10
|
+
constructor(previous: Error);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Base class for all connection related errors detected in the driver.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ConnectionException extends DriverException {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Base class for all server related errors detected in the driver.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ServerException extends DriverException {
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Base class for all constraint violation related errors detected in the driver.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ConstraintViolationException extends ServerException {
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Base class for all already existing database object related errors detected in the driver.
|
|
29
|
+
*
|
|
30
|
+
* A database object is considered any asset that can be created in a database
|
|
31
|
+
* such as schemas, tables, views, sequences, triggers, constraints, indexes,
|
|
32
|
+
* functions, stored procedures etc.
|
|
33
|
+
*/
|
|
34
|
+
export declare class DatabaseObjectExistsException extends ServerException {
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Base class for all unknown database object related errors detected in the driver.
|
|
38
|
+
*
|
|
39
|
+
* A database object is considered any asset that can be created in a database
|
|
40
|
+
* such as schemas, tables, views, sequences, triggers, constraints, indexes,
|
|
41
|
+
* functions, stored procedures etc.
|
|
42
|
+
*/
|
|
43
|
+
export declare class DatabaseObjectNotFoundException extends ServerException {
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Exception for a deadlock error of a transaction detected in the driver.
|
|
47
|
+
*/
|
|
48
|
+
export declare class DeadlockException extends ServerException {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Exception for a foreign key constraint violation detected in the driver.
|
|
52
|
+
*/
|
|
53
|
+
export declare class ForeignKeyConstraintViolationException extends ConstraintViolationException {
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Exception for a check constraint violation detected in the driver.
|
|
57
|
+
*/
|
|
58
|
+
export declare class CheckConstraintViolationException extends ConstraintViolationException {
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Exception for an invalid specified field name in a statement detected in the driver.
|
|
62
|
+
*/
|
|
63
|
+
export declare class InvalidFieldNameException extends ServerException {
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Exception for a lock wait timeout error of a transaction detected in the driver.
|
|
67
|
+
*/
|
|
68
|
+
export declare class LockWaitTimeoutException extends ServerException {
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Exception for a non-unique/ambiguous specified field name in a statement detected in the driver.
|
|
72
|
+
*/
|
|
73
|
+
export declare class NonUniqueFieldNameException extends ServerException {
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Exception for a NOT NULL constraint violation detected in the driver.
|
|
77
|
+
*/
|
|
78
|
+
export declare class NotNullConstraintViolationException extends ConstraintViolationException {
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Exception for a write operation attempt on a read-only database element detected in the driver.
|
|
82
|
+
*/
|
|
83
|
+
export declare class ReadOnlyException extends ServerException {
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Exception for a syntax error in a statement detected in the driver.
|
|
87
|
+
*/
|
|
88
|
+
export declare class SyntaxErrorException extends ServerException {
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Exception for an already existing table referenced in a statement detected in the driver.
|
|
92
|
+
*/
|
|
93
|
+
export declare class TableExistsException extends DatabaseObjectExistsException {
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Exception for an unknown table referenced in a statement detected in the driver.
|
|
97
|
+
*/
|
|
98
|
+
export declare class TableNotFoundException extends DatabaseObjectNotFoundException {
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Exception for a unique constraint violation detected in the driver.
|
|
102
|
+
*/
|
|
103
|
+
export declare class UniqueConstraintViolationException extends ConstraintViolationException {
|
|
104
|
+
}
|
package/exceptions.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* Base class for all errors detected in the driver.
|
|
6
|
+
*/
|
|
7
|
+
class DriverException extends Error {
|
|
8
|
+
code;
|
|
9
|
+
errno;
|
|
10
|
+
sqlState;
|
|
11
|
+
sqlMessage;
|
|
12
|
+
errmsg;
|
|
13
|
+
constructor(previous) {
|
|
14
|
+
super(previous.message);
|
|
15
|
+
Object.assign(this, previous);
|
|
16
|
+
this.name = this.constructor.name;
|
|
17
|
+
this.stack += '\n\n' + 'previous ' + previous.stack;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.DriverException = DriverException;
|
|
21
|
+
/**
|
|
22
|
+
* Base class for all connection related errors detected in the driver.
|
|
23
|
+
*/
|
|
24
|
+
class ConnectionException extends DriverException {
|
|
25
|
+
}
|
|
26
|
+
exports.ConnectionException = ConnectionException;
|
|
27
|
+
/**
|
|
28
|
+
* Base class for all server related errors detected in the driver.
|
|
29
|
+
*/
|
|
30
|
+
class ServerException extends DriverException {
|
|
31
|
+
}
|
|
32
|
+
exports.ServerException = ServerException;
|
|
33
|
+
/**
|
|
34
|
+
* Base class for all constraint violation related errors detected in the driver.
|
|
35
|
+
*/
|
|
36
|
+
class ConstraintViolationException extends ServerException {
|
|
37
|
+
}
|
|
38
|
+
exports.ConstraintViolationException = ConstraintViolationException;
|
|
39
|
+
/**
|
|
40
|
+
* Base class for all already existing database object related errors detected in the driver.
|
|
41
|
+
*
|
|
42
|
+
* A database object is considered any asset that can be created in a database
|
|
43
|
+
* such as schemas, tables, views, sequences, triggers, constraints, indexes,
|
|
44
|
+
* functions, stored procedures etc.
|
|
45
|
+
*/
|
|
46
|
+
class DatabaseObjectExistsException extends ServerException {
|
|
47
|
+
}
|
|
48
|
+
exports.DatabaseObjectExistsException = DatabaseObjectExistsException;
|
|
49
|
+
/**
|
|
50
|
+
* Base class for all unknown database object related errors detected in the driver.
|
|
51
|
+
*
|
|
52
|
+
* A database object is considered any asset that can be created in a database
|
|
53
|
+
* such as schemas, tables, views, sequences, triggers, constraints, indexes,
|
|
54
|
+
* functions, stored procedures etc.
|
|
55
|
+
*/
|
|
56
|
+
class DatabaseObjectNotFoundException extends ServerException {
|
|
57
|
+
}
|
|
58
|
+
exports.DatabaseObjectNotFoundException = DatabaseObjectNotFoundException;
|
|
59
|
+
/**
|
|
60
|
+
* Exception for a deadlock error of a transaction detected in the driver.
|
|
61
|
+
*/
|
|
62
|
+
class DeadlockException extends ServerException {
|
|
63
|
+
}
|
|
64
|
+
exports.DeadlockException = DeadlockException;
|
|
65
|
+
/**
|
|
66
|
+
* Exception for a foreign key constraint violation detected in the driver.
|
|
67
|
+
*/
|
|
68
|
+
class ForeignKeyConstraintViolationException extends ConstraintViolationException {
|
|
69
|
+
}
|
|
70
|
+
exports.ForeignKeyConstraintViolationException = ForeignKeyConstraintViolationException;
|
|
71
|
+
/**
|
|
72
|
+
* Exception for a check constraint violation detected in the driver.
|
|
73
|
+
*/
|
|
74
|
+
class CheckConstraintViolationException extends ConstraintViolationException {
|
|
75
|
+
}
|
|
76
|
+
exports.CheckConstraintViolationException = CheckConstraintViolationException;
|
|
77
|
+
/**
|
|
78
|
+
* Exception for an invalid specified field name in a statement detected in the driver.
|
|
79
|
+
*/
|
|
80
|
+
class InvalidFieldNameException extends ServerException {
|
|
81
|
+
}
|
|
82
|
+
exports.InvalidFieldNameException = InvalidFieldNameException;
|
|
83
|
+
/**
|
|
84
|
+
* Exception for a lock wait timeout error of a transaction detected in the driver.
|
|
85
|
+
*/
|
|
86
|
+
class LockWaitTimeoutException extends ServerException {
|
|
87
|
+
}
|
|
88
|
+
exports.LockWaitTimeoutException = LockWaitTimeoutException;
|
|
89
|
+
/**
|
|
90
|
+
* Exception for a non-unique/ambiguous specified field name in a statement detected in the driver.
|
|
91
|
+
*/
|
|
92
|
+
class NonUniqueFieldNameException extends ServerException {
|
|
93
|
+
}
|
|
94
|
+
exports.NonUniqueFieldNameException = NonUniqueFieldNameException;
|
|
95
|
+
/**
|
|
96
|
+
* Exception for a NOT NULL constraint violation detected in the driver.
|
|
97
|
+
*/
|
|
98
|
+
class NotNullConstraintViolationException extends ConstraintViolationException {
|
|
99
|
+
}
|
|
100
|
+
exports.NotNullConstraintViolationException = NotNullConstraintViolationException;
|
|
101
|
+
/**
|
|
102
|
+
* Exception for a write operation attempt on a read-only database element detected in the driver.
|
|
103
|
+
*/
|
|
104
|
+
class ReadOnlyException extends ServerException {
|
|
105
|
+
}
|
|
106
|
+
exports.ReadOnlyException = ReadOnlyException;
|
|
107
|
+
/**
|
|
108
|
+
* Exception for a syntax error in a statement detected in the driver.
|
|
109
|
+
*/
|
|
110
|
+
class SyntaxErrorException extends ServerException {
|
|
111
|
+
}
|
|
112
|
+
exports.SyntaxErrorException = SyntaxErrorException;
|
|
113
|
+
/**
|
|
114
|
+
* Exception for an already existing table referenced in a statement detected in the driver.
|
|
115
|
+
*/
|
|
116
|
+
class TableExistsException extends DatabaseObjectExistsException {
|
|
117
|
+
}
|
|
118
|
+
exports.TableExistsException = TableExistsException;
|
|
119
|
+
/**
|
|
120
|
+
* Exception for an unknown table referenced in a statement detected in the driver.
|
|
121
|
+
*/
|
|
122
|
+
class TableNotFoundException extends DatabaseObjectNotFoundException {
|
|
123
|
+
}
|
|
124
|
+
exports.TableNotFoundException = TableNotFoundException;
|
|
125
|
+
/**
|
|
126
|
+
* Exception for a unique constraint violation detected in the driver.
|
|
127
|
+
*/
|
|
128
|
+
class UniqueConstraintViolationException extends ConstraintViolationException {
|
|
129
|
+
}
|
|
130
|
+
exports.UniqueConstraintViolationException = UniqueConstraintViolationException;
|
|
@@ -0,0 +1,23 @@
|
|
|
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';
|
|
6
|
+
export declare abstract class Hydrator implements IHydrator {
|
|
7
|
+
protected readonly metadata: MetadataStorage;
|
|
8
|
+
protected readonly platform: Platform;
|
|
9
|
+
protected readonly config: Configuration;
|
|
10
|
+
protected running: boolean;
|
|
11
|
+
constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
|
|
12
|
+
/**
|
|
13
|
+
* @inheritDoc
|
|
14
|
+
*/
|
|
15
|
+
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string): void;
|
|
20
|
+
isRunning(): boolean;
|
|
21
|
+
protected getProperties<T extends object>(meta: EntityMetadata<T>, type: 'full' | 'reference'): EntityProperty<T>[];
|
|
22
|
+
protected hydrateProperty<T extends object>(entity: T, prop: EntityProperty<T>, data: EntityData<T>, factory: EntityFactory, newEntity?: boolean, convertCustomTypes?: boolean): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Hydrator = void 0;
|
|
4
|
+
/* istanbul ignore next */
|
|
5
|
+
class Hydrator {
|
|
6
|
+
metadata;
|
|
7
|
+
platform;
|
|
8
|
+
config;
|
|
9
|
+
running = false;
|
|
10
|
+
constructor(metadata, platform, config) {
|
|
11
|
+
this.metadata = metadata;
|
|
12
|
+
this.platform = platform;
|
|
13
|
+
this.config = config;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
hydrate(entity, meta, data, factory, type, newEntity = false, convertCustomTypes = false, schema) {
|
|
19
|
+
// the running state is used to consider propagation as hydration, saving the values directly to the entity data,
|
|
20
|
+
// but we don't want that for new entities, their propagation should result in entity updates when flushing
|
|
21
|
+
this.running = !newEntity;
|
|
22
|
+
const props = this.getProperties(meta, type);
|
|
23
|
+
for (const prop of props) {
|
|
24
|
+
this.hydrateProperty(entity, prop, data, factory, newEntity, convertCustomTypes);
|
|
25
|
+
}
|
|
26
|
+
this.running = false;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
hydrateReference(entity, meta, data, factory, convertCustomTypes, schema) {
|
|
32
|
+
this.running = true;
|
|
33
|
+
meta.primaryKeys.forEach(pk => {
|
|
34
|
+
this.hydrateProperty(entity, meta.properties[pk], data, factory, false, convertCustomTypes);
|
|
35
|
+
});
|
|
36
|
+
this.running = false;
|
|
37
|
+
}
|
|
38
|
+
isRunning() {
|
|
39
|
+
return this.running;
|
|
40
|
+
}
|
|
41
|
+
getProperties(meta, type) {
|
|
42
|
+
if (type === 'reference') {
|
|
43
|
+
return meta.primaryKeys.map(pk => meta.properties[pk]);
|
|
44
|
+
}
|
|
45
|
+
return meta.hydrateProps;
|
|
46
|
+
}
|
|
47
|
+
hydrateProperty(entity, prop, data, factory, newEntity, convertCustomTypes) {
|
|
48
|
+
entity[prop.name] = data[prop.name];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Hydrator = Hydrator;
|
|
@@ -0,0 +1,24 @@
|
|
|
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) => void;
|
|
5
|
+
export declare class ObjectHydrator extends Hydrator {
|
|
6
|
+
private readonly hydrators;
|
|
7
|
+
private tmpIndex;
|
|
8
|
+
/**
|
|
9
|
+
* @inheritDoc
|
|
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): void;
|
|
12
|
+
/**
|
|
13
|
+
* @inheritDoc
|
|
14
|
+
*/
|
|
15
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* @internal Highly performance-sensitive method.
|
|
18
|
+
*/
|
|
19
|
+
getEntityHydrator<T extends object>(meta: EntityMetadata<T>, type: 'full' | 'reference'): EntityHydrator<T>;
|
|
20
|
+
private createCollectionItemMapper;
|
|
21
|
+
private wrap;
|
|
22
|
+
private safeKey;
|
|
23
|
+
}
|
|
24
|
+
export {};
|