@mikro-orm/core 7.0.2-dev.9 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/EntityManager.d.ts +883 -579
  2. package/EntityManager.js +1897 -1865
  3. package/MikroORM.d.ts +103 -72
  4. package/MikroORM.js +178 -177
  5. package/README.md +128 -294
  6. package/cache/CacheAdapter.d.ts +38 -36
  7. package/cache/FileCacheAdapter.d.ts +30 -24
  8. package/cache/FileCacheAdapter.js +80 -78
  9. package/cache/GeneratedCacheAdapter.d.ts +19 -20
  10. package/cache/GeneratedCacheAdapter.js +31 -30
  11. package/cache/MemoryCacheAdapter.d.ts +19 -20
  12. package/cache/MemoryCacheAdapter.js +36 -36
  13. package/cache/NullCacheAdapter.d.ts +17 -16
  14. package/cache/NullCacheAdapter.js +25 -24
  15. package/connections/Connection.d.ts +99 -75
  16. package/connections/Connection.js +166 -160
  17. package/drivers/DatabaseDriver.d.ts +187 -69
  18. package/drivers/DatabaseDriver.js +451 -432
  19. package/drivers/IDatabaseDriver.d.ts +464 -281
  20. package/drivers/IDatabaseDriver.js +1 -0
  21. package/entity/BaseEntity.d.ts +121 -73
  22. package/entity/BaseEntity.js +44 -33
  23. package/entity/Collection.d.ts +216 -157
  24. package/entity/Collection.js +728 -707
  25. package/entity/EntityAssigner.d.ts +90 -76
  26. package/entity/EntityAssigner.js +232 -229
  27. package/entity/EntityFactory.d.ts +68 -40
  28. package/entity/EntityFactory.js +427 -366
  29. package/entity/EntityHelper.d.ts +34 -22
  30. package/entity/EntityHelper.js +280 -267
  31. package/entity/EntityIdentifier.d.ts +4 -4
  32. package/entity/EntityIdentifier.js +10 -10
  33. package/entity/EntityLoader.d.ts +105 -56
  34. package/entity/EntityLoader.js +754 -722
  35. package/entity/EntityRepository.d.ts +317 -200
  36. package/entity/EntityRepository.js +214 -212
  37. package/entity/PolymorphicRef.d.ts +5 -5
  38. package/entity/PolymorphicRef.js +10 -10
  39. package/entity/Reference.d.ts +130 -66
  40. package/entity/Reference.js +280 -260
  41. package/entity/WrappedEntity.d.ts +116 -53
  42. package/entity/WrappedEntity.js +169 -147
  43. package/entity/defineEntity.d.ts +1290 -614
  44. package/entity/defineEntity.js +521 -511
  45. package/entity/utils.d.ts +13 -3
  46. package/entity/utils.js +71 -73
  47. package/entity/validators.js +43 -43
  48. package/entity/wrap.js +8 -8
  49. package/enums.d.ts +275 -138
  50. package/enums.js +268 -137
  51. package/errors.d.ts +120 -72
  52. package/errors.js +356 -253
  53. package/events/EventManager.d.ts +27 -10
  54. package/events/EventManager.js +80 -73
  55. package/events/EventSubscriber.d.ts +33 -29
  56. package/events/TransactionEventBroadcaster.d.ts +16 -7
  57. package/events/TransactionEventBroadcaster.js +15 -13
  58. package/exceptions.d.ts +23 -40
  59. package/exceptions.js +35 -52
  60. package/hydration/Hydrator.d.ts +43 -16
  61. package/hydration/Hydrator.js +44 -42
  62. package/hydration/ObjectHydrator.d.ts +51 -17
  63. package/hydration/ObjectHydrator.js +480 -416
  64. package/index.d.ts +116 -2
  65. package/index.js +10 -1
  66. package/logging/DefaultLogger.d.ts +35 -30
  67. package/logging/DefaultLogger.js +87 -84
  68. package/logging/Logger.d.ts +45 -40
  69. package/logging/SimpleLogger.d.ts +13 -11
  70. package/logging/SimpleLogger.js +22 -22
  71. package/logging/colors.d.ts +6 -6
  72. package/logging/colors.js +11 -10
  73. package/logging/inspect.js +7 -7
  74. package/metadata/EntitySchema.d.ts +214 -108
  75. package/metadata/EntitySchema.js +398 -379
  76. package/metadata/MetadataDiscovery.d.ts +115 -111
  77. package/metadata/MetadataDiscovery.js +1948 -1857
  78. package/metadata/MetadataProvider.d.ts +25 -14
  79. package/metadata/MetadataProvider.js +83 -77
  80. package/metadata/MetadataStorage.d.ts +39 -19
  81. package/metadata/MetadataStorage.js +119 -106
  82. package/metadata/MetadataValidator.d.ts +39 -39
  83. package/metadata/MetadataValidator.js +381 -338
  84. package/metadata/discover-entities.d.ts +5 -2
  85. package/metadata/discover-entities.js +27 -27
  86. package/metadata/types.d.ts +615 -531
  87. package/naming-strategy/AbstractNamingStrategy.d.ts +55 -39
  88. package/naming-strategy/AbstractNamingStrategy.js +91 -85
  89. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  90. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  91. package/naming-strategy/MongoNamingStrategy.d.ts +7 -6
  92. package/naming-strategy/MongoNamingStrategy.js +19 -18
  93. package/naming-strategy/NamingStrategy.d.ts +109 -99
  94. package/naming-strategy/UnderscoreNamingStrategy.d.ts +8 -7
  95. package/naming-strategy/UnderscoreNamingStrategy.js +22 -21
  96. package/not-supported.js +7 -4
  97. package/package.json +1 -1
  98. package/platforms/ExceptionConverter.d.ts +2 -1
  99. package/platforms/ExceptionConverter.js +5 -4
  100. package/platforms/Platform.d.ts +310 -236
  101. package/platforms/Platform.js +661 -573
  102. package/serialization/EntitySerializer.d.ts +49 -25
  103. package/serialization/EntitySerializer.js +224 -216
  104. package/serialization/EntityTransformer.d.ts +11 -5
  105. package/serialization/EntityTransformer.js +220 -216
  106. package/serialization/SerializationContext.d.ts +27 -18
  107. package/serialization/SerializationContext.js +105 -100
  108. package/types/ArrayType.d.ts +9 -8
  109. package/types/ArrayType.js +34 -33
  110. package/types/BigIntType.d.ts +17 -10
  111. package/types/BigIntType.js +37 -37
  112. package/types/BlobType.d.ts +4 -3
  113. package/types/BlobType.js +14 -13
  114. package/types/BooleanType.d.ts +5 -4
  115. package/types/BooleanType.js +13 -12
  116. package/types/CharacterType.d.ts +3 -2
  117. package/types/CharacterType.js +7 -6
  118. package/types/DateTimeType.d.ts +6 -5
  119. package/types/DateTimeType.js +16 -15
  120. package/types/DateType.d.ts +6 -5
  121. package/types/DateType.js +16 -15
  122. package/types/DecimalType.d.ts +7 -7
  123. package/types/DecimalType.js +26 -26
  124. package/types/DoubleType.d.ts +3 -3
  125. package/types/DoubleType.js +12 -12
  126. package/types/EnumArrayType.d.ts +6 -5
  127. package/types/EnumArrayType.js +25 -24
  128. package/types/EnumType.d.ts +4 -3
  129. package/types/EnumType.js +12 -11
  130. package/types/FloatType.d.ts +4 -3
  131. package/types/FloatType.js +10 -9
  132. package/types/IntegerType.d.ts +4 -3
  133. package/types/IntegerType.js +10 -9
  134. package/types/IntervalType.d.ts +5 -4
  135. package/types/IntervalType.js +13 -12
  136. package/types/JsonType.d.ts +9 -8
  137. package/types/JsonType.js +33 -32
  138. package/types/MediumIntType.d.ts +2 -1
  139. package/types/MediumIntType.js +4 -3
  140. package/types/SmallIntType.d.ts +4 -3
  141. package/types/SmallIntType.js +10 -9
  142. package/types/StringType.d.ts +5 -4
  143. package/types/StringType.js +13 -12
  144. package/types/TextType.d.ts +4 -3
  145. package/types/TextType.js +10 -9
  146. package/types/TimeType.d.ts +6 -5
  147. package/types/TimeType.js +18 -17
  148. package/types/TinyIntType.d.ts +4 -3
  149. package/types/TinyIntType.js +11 -10
  150. package/types/Type.d.ts +88 -73
  151. package/types/Type.js +85 -74
  152. package/types/Uint8ArrayType.d.ts +5 -4
  153. package/types/Uint8ArrayType.js +22 -21
  154. package/types/UnknownType.d.ts +5 -4
  155. package/types/UnknownType.js +13 -12
  156. package/types/UuidType.d.ts +6 -5
  157. package/types/UuidType.js +20 -19
  158. package/types/index.d.ts +77 -49
  159. package/types/index.js +64 -26
  160. package/typings.d.ts +1388 -729
  161. package/typings.js +255 -231
  162. package/unit-of-work/ChangeSet.d.ts +28 -24
  163. package/unit-of-work/ChangeSet.js +58 -54
  164. package/unit-of-work/ChangeSetComputer.d.ts +13 -11
  165. package/unit-of-work/ChangeSetComputer.js +180 -159
  166. package/unit-of-work/ChangeSetPersister.d.ts +64 -41
  167. package/unit-of-work/ChangeSetPersister.js +443 -418
  168. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  169. package/unit-of-work/CommitOrderCalculator.js +89 -88
  170. package/unit-of-work/IdentityMap.d.ts +32 -25
  171. package/unit-of-work/IdentityMap.js +106 -99
  172. package/unit-of-work/UnitOfWork.d.ts +182 -127
  173. package/unit-of-work/UnitOfWork.js +1201 -1169
  174. package/utils/AbstractMigrator.d.ts +111 -91
  175. package/utils/AbstractMigrator.js +275 -275
  176. package/utils/AbstractSchemaGenerator.d.ts +43 -34
  177. package/utils/AbstractSchemaGenerator.js +121 -122
  178. package/utils/AsyncContext.d.ts +3 -3
  179. package/utils/AsyncContext.js +34 -35
  180. package/utils/Configuration.d.ts +853 -801
  181. package/utils/Configuration.js +360 -337
  182. package/utils/Cursor.d.ts +40 -22
  183. package/utils/Cursor.js +135 -127
  184. package/utils/DataloaderUtils.d.ts +58 -43
  185. package/utils/DataloaderUtils.js +203 -198
  186. package/utils/EntityComparator.d.ts +99 -80
  187. package/utils/EntityComparator.js +825 -727
  188. package/utils/NullHighlighter.d.ts +2 -1
  189. package/utils/NullHighlighter.js +4 -3
  190. package/utils/QueryHelper.d.ts +79 -51
  191. package/utils/QueryHelper.js +372 -361
  192. package/utils/RawQueryFragment.d.ts +54 -28
  193. package/utils/RawQueryFragment.js +110 -99
  194. package/utils/RequestContext.d.ts +33 -32
  195. package/utils/RequestContext.js +52 -53
  196. package/utils/TransactionContext.d.ts +17 -16
  197. package/utils/TransactionContext.js +28 -27
  198. package/utils/TransactionManager.d.ts +58 -58
  199. package/utils/TransactionManager.js +199 -197
  200. package/utils/Utils.d.ts +210 -145
  201. package/utils/Utils.js +820 -813
  202. package/utils/clone.js +104 -113
  203. package/utils/env-vars.js +90 -88
  204. package/utils/fs-utils.d.ts +15 -15
  205. package/utils/fs-utils.js +180 -181
  206. package/utils/upsert-utils.d.ts +20 -5
  207. package/utils/upsert-utils.js +114 -116
@@ -1,15 +1,32 @@
1
1
  import type { EntityMetadata } from '../typings.js';
2
2
  import type { EventArgs, EventSubscriber, FlushEventArgs, TransactionEventArgs } from './EventSubscriber.js';
3
3
  import { EventType, type TransactionEventType } from '../enums.js';
4
+ /** Manages event subscribers and dispatches entity/flush/transaction lifecycle events. */
4
5
  export declare class EventManager {
5
- #private;
6
- constructor(subscribers: Iterable<EventSubscriber>);
7
- registerSubscriber(subscriber: EventSubscriber): void;
8
- getSubscribers(): Set<EventSubscriber>;
9
- dispatchEvent<T extends object>(event: TransactionEventType, args: TransactionEventArgs, meta?: EntityMetadata<T>): unknown;
10
- dispatchEvent<T extends object>(event: EventType.onInit, args: Partial<EventArgs<T>>, meta?: EntityMetadata<T>): unknown;
11
- dispatchEvent<T extends object>(event: EventType, args: Partial<EventArgs<T> | FlushEventArgs>, meta?: EntityMetadata<T>): Promise<unknown>;
12
- hasListeners<T>(event: EventType, meta: EntityMetadata<T>): boolean;
13
- clone(): EventManager;
14
- private getSubscribedEntities;
6
+ #private;
7
+ constructor(subscribers: Iterable<EventSubscriber>);
8
+ /** Registers an event subscriber and indexes its subscribed entities and event types. */
9
+ registerSubscriber(subscriber: EventSubscriber): void;
10
+ /** Returns the set of all registered event subscribers. */
11
+ getSubscribers(): Set<EventSubscriber>;
12
+ dispatchEvent<T extends object>(
13
+ event: TransactionEventType,
14
+ args: TransactionEventArgs,
15
+ meta?: EntityMetadata<T>,
16
+ ): unknown;
17
+ dispatchEvent<T extends object>(
18
+ event: EventType.onInit,
19
+ args: Partial<EventArgs<T>>,
20
+ meta?: EntityMetadata<T>,
21
+ ): unknown;
22
+ dispatchEvent<T extends object>(
23
+ event: EventType,
24
+ args: Partial<EventArgs<T> | FlushEventArgs>,
25
+ meta?: EntityMetadata<T>,
26
+ ): Promise<unknown>;
27
+ /** Checks whether there are any listeners (hooks or subscribers) for the given event type and entity. */
28
+ hasListeners<T>(event: EventType, meta: EntityMetadata<T>): boolean;
29
+ /** Creates a new EventManager with the same set of subscribers. */
30
+ clone(): EventManager;
31
+ private getSubscribedEntities;
15
32
  }
@@ -1,84 +1,91 @@
1
1
  import { Utils } from '../utils/Utils.js';
2
2
  import { EventType, EventTypeMap } from '../enums.js';
3
+ /** Manages event subscribers and dispatches entity/flush/transaction lifecycle events. */
3
4
  export class EventManager {
4
- #listeners = {};
5
- #entities = new Map();
6
- #cache = new Map();
7
- #subscribers = new Set();
8
- constructor(subscribers) {
9
- for (const subscriber of subscribers) {
10
- this.registerSubscriber(subscriber);
11
- }
5
+ #listeners = {};
6
+ #entities = new Map();
7
+ #cache = new Map();
8
+ #subscribers = new Set();
9
+ constructor(subscribers) {
10
+ for (const subscriber of subscribers) {
11
+ this.registerSubscriber(subscriber);
12
12
  }
13
- registerSubscriber(subscriber) {
14
- if (this.#subscribers.has(subscriber)) {
15
- return;
16
- }
17
- this.#subscribers.add(subscriber);
18
- this.#entities.set(subscriber, this.getSubscribedEntities(subscriber));
19
- this.#cache.clear();
20
- Utils.keys(EventType)
21
- .filter(event => event in subscriber)
22
- .forEach(event => {
23
- this.#listeners[event] ??= new Set();
24
- this.#listeners[event].add(subscriber);
25
- });
13
+ }
14
+ /** Registers an event subscriber and indexes its subscribed entities and event types. */
15
+ registerSubscriber(subscriber) {
16
+ if (this.#subscribers.has(subscriber)) {
17
+ return;
26
18
  }
27
- getSubscribers() {
28
- return this.#subscribers;
19
+ this.#subscribers.add(subscriber);
20
+ this.#entities.set(subscriber, this.getSubscribedEntities(subscriber));
21
+ this.#cache.clear();
22
+ Utils.keys(EventType)
23
+ .filter(event => event in subscriber)
24
+ .forEach(event => {
25
+ this.#listeners[event] ??= new Set();
26
+ this.#listeners[event].add(subscriber);
27
+ });
28
+ }
29
+ /** Returns the set of all registered event subscribers. */
30
+ getSubscribers() {
31
+ return this.#subscribers;
32
+ }
33
+ dispatchEvent(event, args, meta) {
34
+ const listeners = [];
35
+ const entity = args.entity;
36
+ // execute lifecycle hooks first
37
+ meta ??= entity?.__meta;
38
+ const hooks = meta?.hooks[event] || [];
39
+ listeners.push(
40
+ ...hooks.map(hook => {
41
+ const prototypeHook = meta?.prototype[hook];
42
+ const handler = typeof hook === 'function' ? hook : (entity[hook] ?? prototypeHook);
43
+ return handler.bind(entity);
44
+ }),
45
+ );
46
+ for (const listener of this.#listeners[event] ?? new Set()) {
47
+ const entities = this.#entities.get(listener);
48
+ if (entities.size === 0 || !entity || entities.has(entity.constructor.name)) {
49
+ listeners.push(listener[event].bind(listener));
50
+ }
29
51
  }
30
- dispatchEvent(event, args, meta) {
31
- const listeners = [];
32
- const entity = args.entity;
33
- // execute lifecycle hooks first
34
- meta ??= entity?.__meta;
35
- const hooks = (meta?.hooks[event] || []);
36
- listeners.push(...hooks.map(hook => {
37
- const prototypeHook = meta?.prototype[hook];
38
- const handler = typeof hook === 'function' ? hook : (entity[hook] ?? prototypeHook);
39
- return handler.bind(entity);
40
- }));
41
- for (const listener of this.#listeners[event] ?? new Set()) {
42
- const entities = this.#entities.get(listener);
43
- if (entities.size === 0 || !entity || entities.has(entity.constructor.name)) {
44
- listeners.push(listener[event].bind(listener));
45
- }
46
- }
47
- if (event === EventType.onInit) {
48
- for (const listener of listeners) {
49
- void listener(args);
50
- }
51
- return;
52
- }
53
- return Utils.runSerial(listeners, listener => listener(args));
52
+ if (event === EventType.onInit) {
53
+ for (const listener of listeners) {
54
+ void listener(args);
55
+ }
56
+ return;
54
57
  }
55
- hasListeners(event, meta) {
56
- const cacheKey = meta._id + EventTypeMap[event];
57
- if (this.#cache.has(cacheKey)) {
58
- return this.#cache.get(cacheKey);
59
- }
60
- const hasHooks = meta.hooks[event]?.length;
61
- if (hasHooks) {
62
- this.#cache.set(cacheKey, true);
63
- return true;
64
- }
65
- for (const listener of this.#listeners[event] ?? new Set()) {
66
- const entities = this.#entities.get(listener);
67
- if (entities.size === 0 || entities.has(meta.className)) {
68
- this.#cache.set(cacheKey, true);
69
- return true;
70
- }
71
- }
72
- this.#cache.set(cacheKey, false);
73
- return false;
58
+ return Utils.runSerial(listeners, listener => listener(args));
59
+ }
60
+ /** Checks whether there are any listeners (hooks or subscribers) for the given event type and entity. */
61
+ hasListeners(event, meta) {
62
+ const cacheKey = meta._id + EventTypeMap[event];
63
+ if (this.#cache.has(cacheKey)) {
64
+ return this.#cache.get(cacheKey);
74
65
  }
75
- clone() {
76
- return new EventManager(this.#subscribers);
66
+ const hasHooks = meta.hooks[event]?.length;
67
+ if (hasHooks) {
68
+ this.#cache.set(cacheKey, true);
69
+ return true;
77
70
  }
78
- getSubscribedEntities(listener) {
79
- if (!listener.getSubscribedEntities) {
80
- return new Set();
81
- }
82
- return new Set(listener.getSubscribedEntities().map(name => Utils.className(name)));
71
+ for (const listener of this.#listeners[event] ?? new Set()) {
72
+ const entities = this.#entities.get(listener);
73
+ if (entities.size === 0 || entities.has(meta.className)) {
74
+ this.#cache.set(cacheKey, true);
75
+ return true;
76
+ }
83
77
  }
78
+ this.#cache.set(cacheKey, false);
79
+ return false;
80
+ }
81
+ /** Creates a new EventManager with the same set of subscribers. */
82
+ clone() {
83
+ return new EventManager(this.#subscribers);
84
+ }
85
+ getSubscribedEntities(listener) {
86
+ if (!listener.getSubscribedEntities) {
87
+ return new Set();
88
+ }
89
+ return new Set(listener.getSubscribedEntities().map(name => Utils.className(name)));
90
+ }
84
91
  }
@@ -3,40 +3,44 @@ import type { EntityManager } from '../EntityManager.js';
3
3
  import type { UnitOfWork } from '../unit-of-work/UnitOfWork.js';
4
4
  import type { ChangeSet } from '../unit-of-work/ChangeSet.js';
5
5
  import type { Transaction } from '../connections/Connection.js';
6
+ /** Arguments passed to entity lifecycle event hooks. */
6
7
  export interface EventArgs<T> {
7
- entity: T;
8
- em: EntityManager;
9
- meta: EntityMetadata<T>;
10
- changeSet?: ChangeSet<T & {}>;
8
+ entity: T;
9
+ em: EntityManager;
10
+ meta: EntityMetadata<T>;
11
+ changeSet?: ChangeSet<T & {}>;
11
12
  }
13
+ /** Arguments passed to flush lifecycle event hooks (beforeFlush, onFlush, afterFlush). */
12
14
  export interface FlushEventArgs extends Omit<EventArgs<any>, 'entity' | 'changeSet' | 'meta'> {
13
- uow: UnitOfWork;
15
+ uow: UnitOfWork;
14
16
  }
17
+ /** Arguments passed to transaction lifecycle event hooks (start, commit, rollback). */
15
18
  export interface TransactionEventArgs extends Omit<EventArgs<any>, 'entity' | 'meta' | 'changeSet'> {
16
- transaction?: Transaction & {
17
- savepointName?: string;
18
- };
19
- uow?: UnitOfWork;
19
+ transaction?: Transaction & {
20
+ savepointName?: string;
21
+ };
22
+ uow?: UnitOfWork;
20
23
  }
24
+ /** Interface for subscribing to entity and transaction lifecycle events. */
21
25
  export interface EventSubscriber<T = any> {
22
- getSubscribedEntities?(): EntityName<T>[];
23
- onInit?(args: EventArgs<T>): void;
24
- onLoad?(args: EventArgs<T>): void | Promise<void>;
25
- beforeCreate?(args: EventArgs<T>): void | Promise<void>;
26
- afterCreate?(args: EventArgs<T>): void | Promise<void>;
27
- beforeUpdate?(args: EventArgs<T>): void | Promise<void>;
28
- afterUpdate?(args: EventArgs<T>): void | Promise<void>;
29
- beforeUpsert?(args: EventArgs<T>): void | Promise<void>;
30
- afterUpsert?(args: EventArgs<T>): void | Promise<void>;
31
- beforeDelete?(args: EventArgs<T>): void | Promise<void>;
32
- afterDelete?(args: EventArgs<T>): void | Promise<void>;
33
- beforeFlush?(args: FlushEventArgs): void | Promise<void>;
34
- onFlush?(args: FlushEventArgs): void | Promise<void>;
35
- afterFlush?(args: FlushEventArgs): void | Promise<void>;
36
- beforeTransactionStart?(args: TransactionEventArgs): void | Promise<void>;
37
- afterTransactionStart?(args: TransactionEventArgs): void | Promise<void>;
38
- beforeTransactionCommit?(args: TransactionEventArgs): void | Promise<void>;
39
- afterTransactionCommit?(args: TransactionEventArgs): void | Promise<void>;
40
- beforeTransactionRollback?(args: TransactionEventArgs): void | Promise<void>;
41
- afterTransactionRollback?(args: TransactionEventArgs): void | Promise<void>;
26
+ getSubscribedEntities?(): EntityName<T>[];
27
+ onInit?(args: EventArgs<T>): void;
28
+ onLoad?(args: EventArgs<T>): void | Promise<void>;
29
+ beforeCreate?(args: EventArgs<T>): void | Promise<void>;
30
+ afterCreate?(args: EventArgs<T>): void | Promise<void>;
31
+ beforeUpdate?(args: EventArgs<T>): void | Promise<void>;
32
+ afterUpdate?(args: EventArgs<T>): void | Promise<void>;
33
+ beforeUpsert?(args: EventArgs<T>): void | Promise<void>;
34
+ afterUpsert?(args: EventArgs<T>): void | Promise<void>;
35
+ beforeDelete?(args: EventArgs<T>): void | Promise<void>;
36
+ afterDelete?(args: EventArgs<T>): void | Promise<void>;
37
+ beforeFlush?(args: FlushEventArgs): void | Promise<void>;
38
+ onFlush?(args: FlushEventArgs): void | Promise<void>;
39
+ afterFlush?(args: FlushEventArgs): void | Promise<void>;
40
+ beforeTransactionStart?(args: TransactionEventArgs): void | Promise<void>;
41
+ afterTransactionStart?(args: TransactionEventArgs): void | Promise<void>;
42
+ beforeTransactionCommit?(args: TransactionEventArgs): void | Promise<void>;
43
+ afterTransactionCommit?(args: TransactionEventArgs): void | Promise<void>;
44
+ beforeTransactionRollback?(args: TransactionEventArgs): void | Promise<void>;
45
+ afterTransactionRollback?(args: TransactionEventArgs): void | Promise<void>;
42
46
  }
@@ -1,13 +1,22 @@
1
1
  import type { Transaction } from '../connections/Connection.js';
2
2
  import type { EntityManager } from '../EntityManager.js';
3
3
  import type { TransactionEventType } from '../enums.js';
4
+ /** Broadcasts transaction lifecycle events (start, commit, rollback) through the EventManager. */
4
5
  export declare class TransactionEventBroadcaster {
5
- private readonly em;
6
- readonly context?: {
6
+ private readonly em;
7
+ readonly context?:
8
+ | {
7
9
  topLevelTransaction?: boolean;
8
- } | undefined;
9
- constructor(em: EntityManager, context?: {
10
- topLevelTransaction?: boolean;
11
- } | undefined);
12
- dispatchEvent(event: TransactionEventType, transaction?: Transaction): Promise<void>;
10
+ }
11
+ | undefined;
12
+ constructor(
13
+ em: EntityManager,
14
+ context?:
15
+ | {
16
+ topLevelTransaction?: boolean;
17
+ }
18
+ | undefined,
19
+ );
20
+ /** Dispatches a transaction lifecycle event to the EventManager. */
21
+ dispatchEvent(event: TransactionEventType, transaction?: Transaction): Promise<void>;
13
22
  }
@@ -1,15 +1,17 @@
1
+ /** Broadcasts transaction lifecycle events (start, commit, rollback) through the EventManager. */
1
2
  export class TransactionEventBroadcaster {
2
- em;
3
- context;
4
- constructor(em, context) {
5
- this.em = em;
6
- this.context = context;
7
- }
8
- async dispatchEvent(event, transaction) {
9
- await this.em.getEventManager().dispatchEvent(event, {
10
- em: this.em,
11
- uow: this.em.getUnitOfWork(false),
12
- transaction,
13
- });
14
- }
3
+ em;
4
+ context;
5
+ constructor(em, context) {
6
+ this.em = em;
7
+ this.context = context;
8
+ }
9
+ /** Dispatches a transaction lifecycle event to the EventManager. */
10
+ async dispatchEvent(event, transaction) {
11
+ await this.em.getEventManager().dispatchEvent(event, {
12
+ em: this.em,
13
+ uow: this.em.getUnitOfWork(false),
14
+ transaction,
15
+ });
16
+ }
15
17
  }
package/exceptions.d.ts CHANGED
@@ -2,28 +2,25 @@
2
2
  * Base class for all errors detected in the driver.
3
3
  */
4
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);
5
+ code?: string;
6
+ errno?: number;
7
+ sqlState?: string;
8
+ sqlMessage?: string;
9
+ errmsg?: string;
10
+ constructor(previous: Error);
11
11
  }
12
12
  /**
13
13
  * Base class for all connection related errors detected in the driver.
14
14
  */
15
- export declare class ConnectionException extends DriverException {
16
- }
15
+ export declare class ConnectionException extends DriverException {}
17
16
  /**
18
17
  * Base class for all server related errors detected in the driver.
19
18
  */
20
- export declare class ServerException extends DriverException {
21
- }
19
+ export declare class ServerException extends DriverException {}
22
20
  /**
23
21
  * Base class for all constraint violation related errors detected in the driver.
24
22
  */
25
- export declare class ConstraintViolationException extends ServerException {
26
- }
23
+ export declare class ConstraintViolationException extends ServerException {}
27
24
  /**
28
25
  * Base class for all already existing database object related errors detected in the driver.
29
26
  *
@@ -31,8 +28,7 @@ export declare class ConstraintViolationException extends ServerException {
31
28
  * such as schemas, tables, views, sequences, triggers, constraints, indexes,
32
29
  * functions, stored procedures etc.
33
30
  */
34
- export declare class DatabaseObjectExistsException extends ServerException {
35
- }
31
+ export declare class DatabaseObjectExistsException extends ServerException {}
36
32
  /**
37
33
  * Base class for all unknown database object related errors detected in the driver.
38
34
  *
@@ -40,65 +36,52 @@ export declare class DatabaseObjectExistsException extends ServerException {
40
36
  * such as schemas, tables, views, sequences, triggers, constraints, indexes,
41
37
  * functions, stored procedures etc.
42
38
  */
43
- export declare class DatabaseObjectNotFoundException extends ServerException {
44
- }
39
+ export declare class DatabaseObjectNotFoundException extends ServerException {}
45
40
  /**
46
41
  * Exception for a deadlock error of a transaction detected in the driver.
47
42
  */
48
- export declare class DeadlockException extends ServerException {
49
- }
43
+ export declare class DeadlockException extends ServerException {}
50
44
  /**
51
45
  * Exception for a foreign key constraint violation detected in the driver.
52
46
  */
53
- export declare class ForeignKeyConstraintViolationException extends ConstraintViolationException {
54
- }
47
+ export declare class ForeignKeyConstraintViolationException extends ConstraintViolationException {}
55
48
  /**
56
49
  * Exception for a check constraint violation detected in the driver.
57
50
  */
58
- export declare class CheckConstraintViolationException extends ConstraintViolationException {
59
- }
51
+ export declare class CheckConstraintViolationException extends ConstraintViolationException {}
60
52
  /**
61
53
  * Exception for an invalid specified field name in a statement detected in the driver.
62
54
  */
63
- export declare class InvalidFieldNameException extends ServerException {
64
- }
55
+ export declare class InvalidFieldNameException extends ServerException {}
65
56
  /**
66
57
  * Exception for a lock wait timeout error of a transaction detected in the driver.
67
58
  */
68
- export declare class LockWaitTimeoutException extends ServerException {
69
- }
59
+ export declare class LockWaitTimeoutException extends ServerException {}
70
60
  /**
71
61
  * Exception for a non-unique/ambiguous specified field name in a statement detected in the driver.
72
62
  */
73
- export declare class NonUniqueFieldNameException extends ServerException {
74
- }
63
+ export declare class NonUniqueFieldNameException extends ServerException {}
75
64
  /**
76
65
  * Exception for a NOT NULL constraint violation detected in the driver.
77
66
  */
78
- export declare class NotNullConstraintViolationException extends ConstraintViolationException {
79
- }
67
+ export declare class NotNullConstraintViolationException extends ConstraintViolationException {}
80
68
  /**
81
69
  * Exception for a write operation attempt on a read-only database element detected in the driver.
82
70
  */
83
- export declare class ReadOnlyException extends ServerException {
84
- }
71
+ export declare class ReadOnlyException extends ServerException {}
85
72
  /**
86
73
  * Exception for a syntax error in a statement detected in the driver.
87
74
  */
88
- export declare class SyntaxErrorException extends ServerException {
89
- }
75
+ export declare class SyntaxErrorException extends ServerException {}
90
76
  /**
91
77
  * Exception for an already existing table referenced in a statement detected in the driver.
92
78
  */
93
- export declare class TableExistsException extends DatabaseObjectExistsException {
94
- }
79
+ export declare class TableExistsException extends DatabaseObjectExistsException {}
95
80
  /**
96
81
  * Exception for an unknown table referenced in a statement detected in the driver.
97
82
  */
98
- export declare class TableNotFoundException extends DatabaseObjectNotFoundException {
99
- }
83
+ export declare class TableNotFoundException extends DatabaseObjectNotFoundException {}
100
84
  /**
101
85
  * Exception for a unique constraint violation detected in the driver.
102
86
  */
103
- export declare class UniqueConstraintViolationException extends ConstraintViolationException {
104
- }
87
+ export declare class UniqueConstraintViolationException extends ConstraintViolationException {}
package/exceptions.js CHANGED
@@ -2,41 +2,38 @@
2
2
  * Base class for all errors detected in the driver.
3
3
  */
4
4
  export class DriverException extends Error {
5
- code;
6
- errno;
7
- sqlState;
8
- sqlMessage;
9
- errmsg;
10
- constructor(previous) {
11
- super(previous.message);
12
- Object.getOwnPropertyNames(previous).forEach(k => (this[k] = previous[k]));
13
- this.name = this.constructor.name;
14
- Error.captureStackTrace(this, this.constructor);
15
- if (previous.stack) {
16
- this.stack +=
17
- '\n\n' +
18
- previous.stack
19
- .split('\n')
20
- .filter(l => l.trim().startsWith('at '))
21
- .join('\n');
22
- }
5
+ code;
6
+ errno;
7
+ sqlState;
8
+ sqlMessage;
9
+ errmsg;
10
+ constructor(previous) {
11
+ super(previous.message);
12
+ Object.getOwnPropertyNames(previous).forEach(k => (this[k] = previous[k]));
13
+ this.name = this.constructor.name;
14
+ Error.captureStackTrace(this, this.constructor);
15
+ if (previous.stack) {
16
+ this.stack +=
17
+ '\n\n' +
18
+ previous.stack
19
+ .split('\n')
20
+ .filter(l => l.trim().startsWith('at '))
21
+ .join('\n');
23
22
  }
23
+ }
24
24
  }
25
25
  /**
26
26
  * Base class for all connection related errors detected in the driver.
27
27
  */
28
- export class ConnectionException extends DriverException {
29
- }
28
+ export class ConnectionException extends DriverException {}
30
29
  /**
31
30
  * Base class for all server related errors detected in the driver.
32
31
  */
33
- export class ServerException extends DriverException {
34
- }
32
+ export class ServerException extends DriverException {}
35
33
  /**
36
34
  * Base class for all constraint violation related errors detected in the driver.
37
35
  */
38
- export class ConstraintViolationException extends ServerException {
39
- }
36
+ export class ConstraintViolationException extends ServerException {}
40
37
  /**
41
38
  * Base class for all already existing database object related errors detected in the driver.
42
39
  *
@@ -44,8 +41,7 @@ export class ConstraintViolationException extends ServerException {
44
41
  * such as schemas, tables, views, sequences, triggers, constraints, indexes,
45
42
  * functions, stored procedures etc.
46
43
  */
47
- export class DatabaseObjectExistsException extends ServerException {
48
- }
44
+ export class DatabaseObjectExistsException extends ServerException {}
49
45
  /**
50
46
  * Base class for all unknown database object related errors detected in the driver.
51
47
  *
@@ -53,65 +49,52 @@ export class DatabaseObjectExistsException extends ServerException {
53
49
  * such as schemas, tables, views, sequences, triggers, constraints, indexes,
54
50
  * functions, stored procedures etc.
55
51
  */
56
- export class DatabaseObjectNotFoundException extends ServerException {
57
- }
52
+ export class DatabaseObjectNotFoundException extends ServerException {}
58
53
  /**
59
54
  * Exception for a deadlock error of a transaction detected in the driver.
60
55
  */
61
- export class DeadlockException extends ServerException {
62
- }
56
+ export class DeadlockException extends ServerException {}
63
57
  /**
64
58
  * Exception for a foreign key constraint violation detected in the driver.
65
59
  */
66
- export class ForeignKeyConstraintViolationException extends ConstraintViolationException {
67
- }
60
+ export class ForeignKeyConstraintViolationException extends ConstraintViolationException {}
68
61
  /**
69
62
  * Exception for a check constraint violation detected in the driver.
70
63
  */
71
- export class CheckConstraintViolationException extends ConstraintViolationException {
72
- }
64
+ export class CheckConstraintViolationException extends ConstraintViolationException {}
73
65
  /**
74
66
  * Exception for an invalid specified field name in a statement detected in the driver.
75
67
  */
76
- export class InvalidFieldNameException extends ServerException {
77
- }
68
+ export class InvalidFieldNameException extends ServerException {}
78
69
  /**
79
70
  * Exception for a lock wait timeout error of a transaction detected in the driver.
80
71
  */
81
- export class LockWaitTimeoutException extends ServerException {
82
- }
72
+ export class LockWaitTimeoutException extends ServerException {}
83
73
  /**
84
74
  * Exception for a non-unique/ambiguous specified field name in a statement detected in the driver.
85
75
  */
86
- export class NonUniqueFieldNameException extends ServerException {
87
- }
76
+ export class NonUniqueFieldNameException extends ServerException {}
88
77
  /**
89
78
  * Exception for a NOT NULL constraint violation detected in the driver.
90
79
  */
91
- export class NotNullConstraintViolationException extends ConstraintViolationException {
92
- }
80
+ export class NotNullConstraintViolationException extends ConstraintViolationException {}
93
81
  /**
94
82
  * Exception for a write operation attempt on a read-only database element detected in the driver.
95
83
  */
96
- export class ReadOnlyException extends ServerException {
97
- }
84
+ export class ReadOnlyException extends ServerException {}
98
85
  /**
99
86
  * Exception for a syntax error in a statement detected in the driver.
100
87
  */
101
- export class SyntaxErrorException extends ServerException {
102
- }
88
+ export class SyntaxErrorException extends ServerException {}
103
89
  /**
104
90
  * Exception for an already existing table referenced in a statement detected in the driver.
105
91
  */
106
- export class TableExistsException extends DatabaseObjectExistsException {
107
- }
92
+ export class TableExistsException extends DatabaseObjectExistsException {}
108
93
  /**
109
94
  * Exception for an unknown table referenced in a statement detected in the driver.
110
95
  */
111
- export class TableNotFoundException extends DatabaseObjectNotFoundException {
112
- }
96
+ export class TableNotFoundException extends DatabaseObjectNotFoundException {}
113
97
  /**
114
98
  * Exception for a unique constraint violation detected in the driver.
115
99
  */
116
- export class UniqueConstraintViolationException extends ConstraintViolationException {
117
- }
100
+ export class UniqueConstraintViolationException extends ConstraintViolationException {}