@mikro-orm/core 7.0.2 → 7.0.3-dev.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.
Files changed (205) hide show
  1. package/EntityManager.d.ts +583 -883
  2. package/EntityManager.js +1869 -1897
  3. package/MikroORM.d.ts +74 -103
  4. package/MikroORM.js +179 -178
  5. package/cache/CacheAdapter.d.ts +36 -36
  6. package/cache/FileCacheAdapter.d.ts +24 -30
  7. package/cache/FileCacheAdapter.js +78 -80
  8. package/cache/GeneratedCacheAdapter.d.ts +20 -18
  9. package/cache/GeneratedCacheAdapter.js +30 -30
  10. package/cache/MemoryCacheAdapter.d.ts +20 -18
  11. package/cache/MemoryCacheAdapter.js +36 -35
  12. package/cache/NullCacheAdapter.d.ts +16 -16
  13. package/cache/NullCacheAdapter.js +24 -24
  14. package/connections/Connection.d.ts +84 -95
  15. package/connections/Connection.js +168 -165
  16. package/drivers/DatabaseDriver.d.ts +80 -186
  17. package/drivers/DatabaseDriver.js +443 -450
  18. package/drivers/IDatabaseDriver.d.ts +301 -440
  19. package/entity/BaseEntity.d.ts +83 -120
  20. package/entity/BaseEntity.js +43 -43
  21. package/entity/Collection.d.ts +179 -212
  22. package/entity/Collection.js +721 -727
  23. package/entity/EntityAssigner.d.ts +77 -88
  24. package/entity/EntityAssigner.js +230 -231
  25. package/entity/EntityFactory.d.ts +54 -66
  26. package/entity/EntityFactory.js +383 -425
  27. package/entity/EntityHelper.d.ts +22 -34
  28. package/entity/EntityHelper.js +267 -280
  29. package/entity/EntityIdentifier.d.ts +4 -4
  30. package/entity/EntityIdentifier.js +10 -10
  31. package/entity/EntityLoader.d.ts +73 -103
  32. package/entity/EntityLoader.js +723 -753
  33. package/entity/EntityRepository.d.ts +201 -316
  34. package/entity/EntityRepository.js +213 -213
  35. package/entity/PolymorphicRef.d.ts +5 -5
  36. package/entity/PolymorphicRef.js +10 -10
  37. package/entity/Reference.d.ts +82 -126
  38. package/entity/Reference.js +274 -278
  39. package/entity/WrappedEntity.d.ts +72 -115
  40. package/entity/WrappedEntity.js +166 -168
  41. package/entity/defineEntity.d.ts +614 -1280
  42. package/entity/defineEntity.js +511 -520
  43. package/entity/utils.d.ts +3 -13
  44. package/entity/utils.js +73 -71
  45. package/entity/validators.js +43 -43
  46. package/entity/wrap.js +8 -8
  47. package/enums.d.ts +253 -258
  48. package/enums.js +252 -251
  49. package/errors.d.ts +72 -114
  50. package/errors.js +253 -350
  51. package/events/EventManager.d.ts +14 -26
  52. package/events/EventManager.js +77 -79
  53. package/events/EventSubscriber.d.ts +29 -29
  54. package/events/TransactionEventBroadcaster.d.ts +8 -15
  55. package/events/TransactionEventBroadcaster.js +14 -14
  56. package/exceptions.d.ts +40 -23
  57. package/exceptions.js +52 -35
  58. package/hydration/Hydrator.d.ts +17 -42
  59. package/hydration/Hydrator.js +43 -43
  60. package/hydration/ObjectHydrator.d.ts +17 -50
  61. package/hydration/ObjectHydrator.js +416 -479
  62. package/index.d.ts +2 -116
  63. package/index.js +1 -10
  64. package/logging/DefaultLogger.d.ts +32 -34
  65. package/logging/DefaultLogger.js +86 -86
  66. package/logging/Logger.d.ts +41 -41
  67. package/logging/SimpleLogger.d.ts +11 -13
  68. package/logging/SimpleLogger.js +22 -22
  69. package/logging/colors.d.ts +6 -6
  70. package/logging/colors.js +10 -11
  71. package/logging/inspect.js +7 -7
  72. package/metadata/EntitySchema.d.ts +127 -211
  73. package/metadata/EntitySchema.js +398 -397
  74. package/metadata/MetadataDiscovery.d.ts +114 -114
  75. package/metadata/MetadataDiscovery.js +1863 -1947
  76. package/metadata/MetadataProvider.d.ts +21 -24
  77. package/metadata/MetadataProvider.js +84 -82
  78. package/metadata/MetadataStorage.d.ts +32 -38
  79. package/metadata/MetadataStorage.js +118 -118
  80. package/metadata/MetadataValidator.d.ts +39 -39
  81. package/metadata/MetadataValidator.js +338 -381
  82. package/metadata/discover-entities.d.ts +2 -5
  83. package/metadata/discover-entities.js +27 -27
  84. package/metadata/types.d.ts +531 -615
  85. package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
  86. package/naming-strategy/AbstractNamingStrategy.js +85 -90
  87. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  88. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  89. package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
  90. package/naming-strategy/MongoNamingStrategy.js +18 -18
  91. package/naming-strategy/NamingStrategy.d.ts +99 -109
  92. package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
  93. package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
  94. package/not-supported.js +4 -7
  95. package/package.json +1 -1
  96. package/platforms/ExceptionConverter.d.ts +1 -1
  97. package/platforms/ExceptionConverter.js +4 -4
  98. package/platforms/Platform.d.ts +299 -308
  99. package/platforms/Platform.js +636 -659
  100. package/serialization/EntitySerializer.d.ts +26 -48
  101. package/serialization/EntitySerializer.js +218 -224
  102. package/serialization/EntityTransformer.d.ts +6 -10
  103. package/serialization/EntityTransformer.js +217 -219
  104. package/serialization/SerializationContext.d.ts +23 -27
  105. package/serialization/SerializationContext.js +105 -105
  106. package/types/ArrayType.d.ts +8 -8
  107. package/types/ArrayType.js +33 -33
  108. package/types/BigIntType.d.ts +10 -17
  109. package/types/BigIntType.js +37 -37
  110. package/types/BlobType.d.ts +3 -3
  111. package/types/BlobType.js +13 -13
  112. package/types/BooleanType.d.ts +4 -4
  113. package/types/BooleanType.js +12 -12
  114. package/types/CharacterType.d.ts +2 -2
  115. package/types/CharacterType.js +6 -6
  116. package/types/DateTimeType.d.ts +5 -5
  117. package/types/DateTimeType.js +15 -15
  118. package/types/DateType.d.ts +5 -5
  119. package/types/DateType.js +15 -15
  120. package/types/DecimalType.d.ts +7 -7
  121. package/types/DecimalType.js +26 -26
  122. package/types/DoubleType.d.ts +3 -3
  123. package/types/DoubleType.js +12 -12
  124. package/types/EnumArrayType.d.ts +5 -5
  125. package/types/EnumArrayType.js +24 -24
  126. package/types/EnumType.d.ts +3 -3
  127. package/types/EnumType.js +11 -11
  128. package/types/FloatType.d.ts +3 -3
  129. package/types/FloatType.js +9 -9
  130. package/types/IntegerType.d.ts +3 -3
  131. package/types/IntegerType.js +9 -9
  132. package/types/IntervalType.d.ts +4 -4
  133. package/types/IntervalType.js +12 -12
  134. package/types/JsonType.d.ts +8 -8
  135. package/types/JsonType.js +32 -32
  136. package/types/MediumIntType.d.ts +1 -1
  137. package/types/MediumIntType.js +3 -3
  138. package/types/SmallIntType.d.ts +3 -3
  139. package/types/SmallIntType.js +9 -9
  140. package/types/StringType.d.ts +4 -4
  141. package/types/StringType.js +12 -12
  142. package/types/TextType.d.ts +3 -3
  143. package/types/TextType.js +9 -9
  144. package/types/TimeType.d.ts +5 -5
  145. package/types/TimeType.js +17 -17
  146. package/types/TinyIntType.d.ts +3 -3
  147. package/types/TinyIntType.js +10 -10
  148. package/types/Type.d.ts +79 -83
  149. package/types/Type.js +82 -82
  150. package/types/Uint8ArrayType.d.ts +4 -4
  151. package/types/Uint8ArrayType.js +21 -21
  152. package/types/UnknownType.d.ts +4 -4
  153. package/types/UnknownType.js +12 -12
  154. package/types/UuidType.d.ts +5 -5
  155. package/types/UuidType.js +19 -19
  156. package/types/index.d.ts +49 -75
  157. package/types/index.js +26 -52
  158. package/typings.d.ts +729 -1211
  159. package/typings.js +231 -244
  160. package/unit-of-work/ChangeSet.d.ts +26 -26
  161. package/unit-of-work/ChangeSet.js +56 -56
  162. package/unit-of-work/ChangeSetComputer.d.ts +12 -12
  163. package/unit-of-work/ChangeSetComputer.js +170 -178
  164. package/unit-of-work/ChangeSetPersister.d.ts +44 -63
  165. package/unit-of-work/ChangeSetPersister.js +421 -442
  166. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  167. package/unit-of-work/CommitOrderCalculator.js +88 -89
  168. package/unit-of-work/IdentityMap.d.ts +31 -31
  169. package/unit-of-work/IdentityMap.js +105 -105
  170. package/unit-of-work/UnitOfWork.d.ts +141 -181
  171. package/unit-of-work/UnitOfWork.js +1183 -1200
  172. package/utils/AbstractMigrator.d.ts +91 -111
  173. package/utils/AbstractMigrator.js +275 -275
  174. package/utils/AbstractSchemaGenerator.d.ts +34 -43
  175. package/utils/AbstractSchemaGenerator.js +122 -121
  176. package/utils/AsyncContext.d.ts +3 -3
  177. package/utils/AsyncContext.js +35 -34
  178. package/utils/Configuration.d.ts +808 -852
  179. package/utils/Configuration.js +344 -359
  180. package/utils/Cursor.d.ts +22 -40
  181. package/utils/Cursor.js +127 -135
  182. package/utils/DataloaderUtils.d.ts +43 -58
  183. package/utils/DataloaderUtils.js +198 -203
  184. package/utils/EntityComparator.d.ts +81 -98
  185. package/utils/EntityComparator.js +728 -824
  186. package/utils/NullHighlighter.d.ts +1 -1
  187. package/utils/NullHighlighter.js +3 -3
  188. package/utils/QueryHelper.d.ts +51 -79
  189. package/utils/QueryHelper.js +361 -372
  190. package/utils/RawQueryFragment.d.ts +34 -50
  191. package/utils/RawQueryFragment.js +105 -107
  192. package/utils/RequestContext.d.ts +32 -32
  193. package/utils/RequestContext.js +53 -52
  194. package/utils/TransactionContext.d.ts +16 -16
  195. package/utils/TransactionContext.js +27 -27
  196. package/utils/TransactionManager.d.ts +58 -58
  197. package/utils/TransactionManager.js +197 -199
  198. package/utils/Utils.d.ts +145 -204
  199. package/utils/Utils.js +813 -814
  200. package/utils/clone.js +113 -104
  201. package/utils/env-vars.js +88 -90
  202. package/utils/fs-utils.d.ts +15 -15
  203. package/utils/fs-utils.js +181 -180
  204. package/utils/upsert-utils.d.ts +5 -20
  205. package/utils/upsert-utils.js +116 -114
@@ -3,30 +3,18 @@ import type { EventArgs, EventSubscriber, FlushEventArgs, TransactionEventArgs }
3
3
  import { EventType, type TransactionEventType } from '../enums.js';
4
4
  /** Manages event subscribers and dispatches entity/flush/transaction lifecycle events. */
5
5
  export declare class EventManager {
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;
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>(event: TransactionEventType, args: TransactionEventArgs, meta?: EntityMetadata<T>): unknown;
13
+ dispatchEvent<T extends object>(event: EventType.onInit, args: Partial<EventArgs<T>>, meta?: EntityMetadata<T>): unknown;
14
+ dispatchEvent<T extends object>(event: EventType, args: Partial<EventArgs<T> | FlushEventArgs>, meta?: EntityMetadata<T>): Promise<unknown>;
15
+ /** Checks whether there are any listeners (hooks or subscribers) for the given event type and entity. */
16
+ hasListeners<T>(event: EventType, meta: EntityMetadata<T>): boolean;
17
+ /** Creates a new EventManager with the same set of subscribers. */
18
+ clone(): EventManager;
19
+ private getSubscribedEntities;
32
20
  }
@@ -2,90 +2,88 @@ import { Utils } from '../utils/Utils.js';
2
2
  import { EventType, EventTypeMap } from '../enums.js';
3
3
  /** Manages event subscribers and dispatches entity/flush/transaction lifecycle events. */
4
4
  export class EventManager {
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);
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
  }
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;
14
+ /** Registers an event subscriber and indexes its subscribed entities and event types. */
15
+ registerSubscriber(subscriber) {
16
+ if (this.#subscribers.has(subscriber)) {
17
+ return;
18
+ }
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
+ });
18
28
  }
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
+ /** Returns the set of all registered event subscribers. */
30
+ getSubscribers() {
31
+ return this.#subscribers;
51
32
  }
52
- if (event === EventType.onInit) {
53
- for (const listener of listeners) {
54
- void listener(args);
55
- }
56
- return;
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(...hooks.map(hook => {
40
+ const prototypeHook = meta?.prototype[hook];
41
+ const handler = typeof hook === 'function' ? hook : (entity[hook] ?? prototypeHook);
42
+ return handler.bind(entity);
43
+ }));
44
+ for (const listener of this.#listeners[event] ?? new Set()) {
45
+ const entities = this.#entities.get(listener);
46
+ if (entities.size === 0 || !entity || entities.has(entity.constructor.name)) {
47
+ listeners.push(listener[event].bind(listener));
48
+ }
49
+ }
50
+ if (event === EventType.onInit) {
51
+ for (const listener of listeners) {
52
+ void listener(args);
53
+ }
54
+ return;
55
+ }
56
+ return Utils.runSerial(listeners, listener => listener(args));
57
57
  }
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);
58
+ /** Checks whether there are any listeners (hooks or subscribers) for the given event type and entity. */
59
+ hasListeners(event, meta) {
60
+ const cacheKey = meta._id + EventTypeMap[event];
61
+ if (this.#cache.has(cacheKey)) {
62
+ return this.#cache.get(cacheKey);
63
+ }
64
+ const hasHooks = meta.hooks[event]?.length;
65
+ if (hasHooks) {
66
+ this.#cache.set(cacheKey, true);
67
+ return true;
68
+ }
69
+ for (const listener of this.#listeners[event] ?? new Set()) {
70
+ const entities = this.#entities.get(listener);
71
+ if (entities.size === 0 || entities.has(meta.className)) {
72
+ this.#cache.set(cacheKey, true);
73
+ return true;
74
+ }
75
+ }
76
+ this.#cache.set(cacheKey, false);
77
+ return false;
65
78
  }
66
- const hasHooks = meta.hooks[event]?.length;
67
- if (hasHooks) {
68
- this.#cache.set(cacheKey, true);
69
- return true;
79
+ /** Creates a new EventManager with the same set of subscribers. */
80
+ clone() {
81
+ return new EventManager(this.#subscribers);
70
82
  }
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
+ getSubscribedEntities(listener) {
84
+ if (!listener.getSubscribedEntities) {
85
+ return new Set();
86
+ }
87
+ return new Set(listener.getSubscribedEntities().map(name => Utils.className(name)));
77
88
  }
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
- }
91
89
  }
@@ -5,42 +5,42 @@ import type { ChangeSet } from '../unit-of-work/ChangeSet.js';
5
5
  import type { Transaction } from '../connections/Connection.js';
6
6
  /** Arguments passed to entity lifecycle event hooks. */
7
7
  export interface EventArgs<T> {
8
- entity: T;
9
- em: EntityManager;
10
- meta: EntityMetadata<T>;
11
- changeSet?: ChangeSet<T & {}>;
8
+ entity: T;
9
+ em: EntityManager;
10
+ meta: EntityMetadata<T>;
11
+ changeSet?: ChangeSet<T & {}>;
12
12
  }
13
13
  /** Arguments passed to flush lifecycle event hooks (beforeFlush, onFlush, afterFlush). */
14
14
  export interface FlushEventArgs extends Omit<EventArgs<any>, 'entity' | 'changeSet' | 'meta'> {
15
- uow: UnitOfWork;
15
+ uow: UnitOfWork;
16
16
  }
17
17
  /** Arguments passed to transaction lifecycle event hooks (start, commit, rollback). */
18
18
  export interface TransactionEventArgs extends Omit<EventArgs<any>, 'entity' | 'meta' | 'changeSet'> {
19
- transaction?: Transaction & {
20
- savepointName?: string;
21
- };
22
- uow?: UnitOfWork;
19
+ transaction?: Transaction & {
20
+ savepointName?: string;
21
+ };
22
+ uow?: UnitOfWork;
23
23
  }
24
24
  /** Interface for subscribing to entity and transaction lifecycle events. */
25
25
  export interface EventSubscriber<T = any> {
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>;
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>;
46
46
  }
@@ -3,20 +3,13 @@ import type { EntityManager } from '../EntityManager.js';
3
3
  import type { TransactionEventType } from '../enums.js';
4
4
  /** Broadcasts transaction lifecycle events (start, commit, rollback) through the EventManager. */
5
5
  export declare class TransactionEventBroadcaster {
6
- private readonly em;
7
- readonly context?:
8
- | {
6
+ private readonly em;
7
+ readonly context?: {
9
8
  topLevelTransaction?: boolean;
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>;
9
+ } | undefined;
10
+ constructor(em: EntityManager, context?: {
11
+ topLevelTransaction?: boolean;
12
+ } | undefined);
13
+ /** Dispatches a transaction lifecycle event to the EventManager. */
14
+ dispatchEvent(event: TransactionEventType, transaction?: Transaction): Promise<void>;
22
15
  }
@@ -1,17 +1,17 @@
1
1
  /** Broadcasts transaction lifecycle events (start, commit, rollback) through the EventManager. */
2
2
  export class TransactionEventBroadcaster {
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
- }
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
+ }
17
17
  }
package/exceptions.d.ts CHANGED
@@ -2,25 +2,28 @@
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 {}
15
+ export declare class ConnectionException extends DriverException {
16
+ }
16
17
  /**
17
18
  * Base class for all server related errors detected in the driver.
18
19
  */
19
- export declare class ServerException extends DriverException {}
20
+ export declare class ServerException extends DriverException {
21
+ }
20
22
  /**
21
23
  * Base class for all constraint violation related errors detected in the driver.
22
24
  */
23
- export declare class ConstraintViolationException extends ServerException {}
25
+ export declare class ConstraintViolationException extends ServerException {
26
+ }
24
27
  /**
25
28
  * Base class for all already existing database object related errors detected in the driver.
26
29
  *
@@ -28,7 +31,8 @@ export declare class ConstraintViolationException extends ServerException {}
28
31
  * such as schemas, tables, views, sequences, triggers, constraints, indexes,
29
32
  * functions, stored procedures etc.
30
33
  */
31
- export declare class DatabaseObjectExistsException extends ServerException {}
34
+ export declare class DatabaseObjectExistsException extends ServerException {
35
+ }
32
36
  /**
33
37
  * Base class for all unknown database object related errors detected in the driver.
34
38
  *
@@ -36,52 +40,65 @@ export declare class DatabaseObjectExistsException extends ServerException {}
36
40
  * such as schemas, tables, views, sequences, triggers, constraints, indexes,
37
41
  * functions, stored procedures etc.
38
42
  */
39
- export declare class DatabaseObjectNotFoundException extends ServerException {}
43
+ export declare class DatabaseObjectNotFoundException extends ServerException {
44
+ }
40
45
  /**
41
46
  * Exception for a deadlock error of a transaction detected in the driver.
42
47
  */
43
- export declare class DeadlockException extends ServerException {}
48
+ export declare class DeadlockException extends ServerException {
49
+ }
44
50
  /**
45
51
  * Exception for a foreign key constraint violation detected in the driver.
46
52
  */
47
- export declare class ForeignKeyConstraintViolationException extends ConstraintViolationException {}
53
+ export declare class ForeignKeyConstraintViolationException extends ConstraintViolationException {
54
+ }
48
55
  /**
49
56
  * Exception for a check constraint violation detected in the driver.
50
57
  */
51
- export declare class CheckConstraintViolationException extends ConstraintViolationException {}
58
+ export declare class CheckConstraintViolationException extends ConstraintViolationException {
59
+ }
52
60
  /**
53
61
  * Exception for an invalid specified field name in a statement detected in the driver.
54
62
  */
55
- export declare class InvalidFieldNameException extends ServerException {}
63
+ export declare class InvalidFieldNameException extends ServerException {
64
+ }
56
65
  /**
57
66
  * Exception for a lock wait timeout error of a transaction detected in the driver.
58
67
  */
59
- export declare class LockWaitTimeoutException extends ServerException {}
68
+ export declare class LockWaitTimeoutException extends ServerException {
69
+ }
60
70
  /**
61
71
  * Exception for a non-unique/ambiguous specified field name in a statement detected in the driver.
62
72
  */
63
- export declare class NonUniqueFieldNameException extends ServerException {}
73
+ export declare class NonUniqueFieldNameException extends ServerException {
74
+ }
64
75
  /**
65
76
  * Exception for a NOT NULL constraint violation detected in the driver.
66
77
  */
67
- export declare class NotNullConstraintViolationException extends ConstraintViolationException {}
78
+ export declare class NotNullConstraintViolationException extends ConstraintViolationException {
79
+ }
68
80
  /**
69
81
  * Exception for a write operation attempt on a read-only database element detected in the driver.
70
82
  */
71
- export declare class ReadOnlyException extends ServerException {}
83
+ export declare class ReadOnlyException extends ServerException {
84
+ }
72
85
  /**
73
86
  * Exception for a syntax error in a statement detected in the driver.
74
87
  */
75
- export declare class SyntaxErrorException extends ServerException {}
88
+ export declare class SyntaxErrorException extends ServerException {
89
+ }
76
90
  /**
77
91
  * Exception for an already existing table referenced in a statement detected in the driver.
78
92
  */
79
- export declare class TableExistsException extends DatabaseObjectExistsException {}
93
+ export declare class TableExistsException extends DatabaseObjectExistsException {
94
+ }
80
95
  /**
81
96
  * Exception for an unknown table referenced in a statement detected in the driver.
82
97
  */
83
- export declare class TableNotFoundException extends DatabaseObjectNotFoundException {}
98
+ export declare class TableNotFoundException extends DatabaseObjectNotFoundException {
99
+ }
84
100
  /**
85
101
  * Exception for a unique constraint violation detected in the driver.
86
102
  */
87
- export declare class UniqueConstraintViolationException extends ConstraintViolationException {}
103
+ export declare class UniqueConstraintViolationException extends ConstraintViolationException {
104
+ }
package/exceptions.js CHANGED
@@ -2,38 +2,41 @@
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');
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
+ }
22
23
  }
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 {}
28
+ export class ConnectionException extends DriverException {
29
+ }
29
30
  /**
30
31
  * Base class for all server related errors detected in the driver.
31
32
  */
32
- export class ServerException extends DriverException {}
33
+ export class ServerException extends DriverException {
34
+ }
33
35
  /**
34
36
  * Base class for all constraint violation related errors detected in the driver.
35
37
  */
36
- export class ConstraintViolationException extends ServerException {}
38
+ export class ConstraintViolationException extends ServerException {
39
+ }
37
40
  /**
38
41
  * Base class for all already existing database object related errors detected in the driver.
39
42
  *
@@ -41,7 +44,8 @@ export class ConstraintViolationException extends ServerException {}
41
44
  * such as schemas, tables, views, sequences, triggers, constraints, indexes,
42
45
  * functions, stored procedures etc.
43
46
  */
44
- export class DatabaseObjectExistsException extends ServerException {}
47
+ export class DatabaseObjectExistsException extends ServerException {
48
+ }
45
49
  /**
46
50
  * Base class for all unknown database object related errors detected in the driver.
47
51
  *
@@ -49,52 +53,65 @@ export class DatabaseObjectExistsException extends ServerException {}
49
53
  * such as schemas, tables, views, sequences, triggers, constraints, indexes,
50
54
  * functions, stored procedures etc.
51
55
  */
52
- export class DatabaseObjectNotFoundException extends ServerException {}
56
+ export class DatabaseObjectNotFoundException extends ServerException {
57
+ }
53
58
  /**
54
59
  * Exception for a deadlock error of a transaction detected in the driver.
55
60
  */
56
- export class DeadlockException extends ServerException {}
61
+ export class DeadlockException extends ServerException {
62
+ }
57
63
  /**
58
64
  * Exception for a foreign key constraint violation detected in the driver.
59
65
  */
60
- export class ForeignKeyConstraintViolationException extends ConstraintViolationException {}
66
+ export class ForeignKeyConstraintViolationException extends ConstraintViolationException {
67
+ }
61
68
  /**
62
69
  * Exception for a check constraint violation detected in the driver.
63
70
  */
64
- export class CheckConstraintViolationException extends ConstraintViolationException {}
71
+ export class CheckConstraintViolationException extends ConstraintViolationException {
72
+ }
65
73
  /**
66
74
  * Exception for an invalid specified field name in a statement detected in the driver.
67
75
  */
68
- export class InvalidFieldNameException extends ServerException {}
76
+ export class InvalidFieldNameException extends ServerException {
77
+ }
69
78
  /**
70
79
  * Exception for a lock wait timeout error of a transaction detected in the driver.
71
80
  */
72
- export class LockWaitTimeoutException extends ServerException {}
81
+ export class LockWaitTimeoutException extends ServerException {
82
+ }
73
83
  /**
74
84
  * Exception for a non-unique/ambiguous specified field name in a statement detected in the driver.
75
85
  */
76
- export class NonUniqueFieldNameException extends ServerException {}
86
+ export class NonUniqueFieldNameException extends ServerException {
87
+ }
77
88
  /**
78
89
  * Exception for a NOT NULL constraint violation detected in the driver.
79
90
  */
80
- export class NotNullConstraintViolationException extends ConstraintViolationException {}
91
+ export class NotNullConstraintViolationException extends ConstraintViolationException {
92
+ }
81
93
  /**
82
94
  * Exception for a write operation attempt on a read-only database element detected in the driver.
83
95
  */
84
- export class ReadOnlyException extends ServerException {}
96
+ export class ReadOnlyException extends ServerException {
97
+ }
85
98
  /**
86
99
  * Exception for a syntax error in a statement detected in the driver.
87
100
  */
88
- export class SyntaxErrorException extends ServerException {}
101
+ export class SyntaxErrorException extends ServerException {
102
+ }
89
103
  /**
90
104
  * Exception for an already existing table referenced in a statement detected in the driver.
91
105
  */
92
- export class TableExistsException extends DatabaseObjectExistsException {}
106
+ export class TableExistsException extends DatabaseObjectExistsException {
107
+ }
93
108
  /**
94
109
  * Exception for an unknown table referenced in a statement detected in the driver.
95
110
  */
96
- export class TableNotFoundException extends DatabaseObjectNotFoundException {}
111
+ export class TableNotFoundException extends DatabaseObjectNotFoundException {
112
+ }
97
113
  /**
98
114
  * Exception for a unique constraint violation detected in the driver.
99
115
  */
100
- export class UniqueConstraintViolationException extends ConstraintViolationException {}
116
+ export class UniqueConstraintViolationException extends ConstraintViolationException {
117
+ }