@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.
Files changed (264) hide show
  1. package/EntityManager.d.ts +553 -0
  2. package/EntityManager.js +1736 -0
  3. package/LICENSE +21 -0
  4. package/MikroORM.d.ts +102 -0
  5. package/MikroORM.js +258 -0
  6. package/README.md +383 -0
  7. package/cache/CacheAdapter.d.ts +40 -0
  8. package/cache/CacheAdapter.js +2 -0
  9. package/cache/FileCacheAdapter.d.ts +31 -0
  10. package/cache/FileCacheAdapter.js +90 -0
  11. package/cache/GeneratedCacheAdapter.d.ts +25 -0
  12. package/cache/GeneratedCacheAdapter.js +38 -0
  13. package/cache/MemoryCacheAdapter.d.ts +24 -0
  14. package/cache/MemoryCacheAdapter.js +44 -0
  15. package/cache/NullCacheAdapter.d.ts +19 -0
  16. package/cache/NullCacheAdapter.js +30 -0
  17. package/cache/index.d.ts +5 -0
  18. package/cache/index.js +21 -0
  19. package/connections/Connection.d.ts +85 -0
  20. package/connections/Connection.js +128 -0
  21. package/connections/index.d.ts +1 -0
  22. package/connections/index.js +17 -0
  23. package/decorators/Check.d.ts +3 -0
  24. package/decorators/Check.js +17 -0
  25. package/decorators/CreateRequestContext.d.ts +2 -0
  26. package/decorators/CreateRequestContext.js +31 -0
  27. package/decorators/Embeddable.d.ts +8 -0
  28. package/decorators/Embeddable.js +15 -0
  29. package/decorators/Embedded.d.ts +13 -0
  30. package/decorators/Embedded.js +21 -0
  31. package/decorators/EnsureRequestContext.d.ts +2 -0
  32. package/decorators/EnsureRequestContext.js +26 -0
  33. package/decorators/Entity.d.ts +18 -0
  34. package/decorators/Entity.js +17 -0
  35. package/decorators/Enum.d.ts +9 -0
  36. package/decorators/Enum.js +20 -0
  37. package/decorators/Filter.d.ts +2 -0
  38. package/decorators/Filter.js +12 -0
  39. package/decorators/Formula.d.ts +5 -0
  40. package/decorators/Formula.js +19 -0
  41. package/decorators/Indexed.d.ts +12 -0
  42. package/decorators/Indexed.js +25 -0
  43. package/decorators/ManyToMany.d.ts +21 -0
  44. package/decorators/ManyToMany.js +17 -0
  45. package/decorators/ManyToOne.d.ts +15 -0
  46. package/decorators/ManyToOne.js +17 -0
  47. package/decorators/OneToMany.d.ts +18 -0
  48. package/decorators/OneToMany.js +21 -0
  49. package/decorators/OneToOne.d.ts +12 -0
  50. package/decorators/OneToOne.js +11 -0
  51. package/decorators/PrimaryKey.d.ts +8 -0
  52. package/decorators/PrimaryKey.js +24 -0
  53. package/decorators/Property.d.ts +218 -0
  54. package/decorators/Property.js +35 -0
  55. package/decorators/Subscriber.d.ts +1 -0
  56. package/decorators/Subscriber.js +2 -0
  57. package/decorators/hooks.d.ts +16 -0
  58. package/decorators/hooks.js +60 -0
  59. package/decorators/index.d.ts +17 -0
  60. package/decorators/index.js +36 -0
  61. package/drivers/DatabaseDriver.d.ts +72 -0
  62. package/drivers/DatabaseDriver.js +358 -0
  63. package/drivers/IDatabaseDriver.d.ts +193 -0
  64. package/drivers/IDatabaseDriver.js +4 -0
  65. package/drivers/index.d.ts +2 -0
  66. package/drivers/index.js +18 -0
  67. package/entity/ArrayCollection.d.ts +113 -0
  68. package/entity/ArrayCollection.js +386 -0
  69. package/entity/BaseEntity.d.ts +22 -0
  70. package/entity/BaseEntity.js +47 -0
  71. package/entity/Collection.d.ts +104 -0
  72. package/entity/Collection.js +373 -0
  73. package/entity/EntityAssigner.d.ts +28 -0
  74. package/entity/EntityAssigner.js +226 -0
  75. package/entity/EntityFactory.d.ts +41 -0
  76. package/entity/EntityFactory.js +302 -0
  77. package/entity/EntityHelper.d.ts +29 -0
  78. package/entity/EntityHelper.js +250 -0
  79. package/entity/EntityIdentifier.d.ts +10 -0
  80. package/entity/EntityIdentifier.js +19 -0
  81. package/entity/EntityLoader.d.ts +65 -0
  82. package/entity/EntityLoader.js +579 -0
  83. package/entity/EntityRepository.d.ts +161 -0
  84. package/entity/EntityRepository.js +207 -0
  85. package/entity/EntityValidator.d.ts +19 -0
  86. package/entity/EntityValidator.js +152 -0
  87. package/entity/Reference.d.ts +89 -0
  88. package/entity/Reference.js +242 -0
  89. package/entity/WrappedEntity.d.ts +67 -0
  90. package/entity/WrappedEntity.js +146 -0
  91. package/entity/index.d.ts +13 -0
  92. package/entity/index.js +29 -0
  93. package/entity/wrap.d.ts +15 -0
  94. package/entity/wrap.js +26 -0
  95. package/enums.d.ts +160 -0
  96. package/enums.js +169 -0
  97. package/errors.d.ts +65 -0
  98. package/errors.js +222 -0
  99. package/events/EventManager.d.ts +17 -0
  100. package/events/EventManager.js +77 -0
  101. package/events/EventSubscriber.d.ts +39 -0
  102. package/events/EventSubscriber.js +2 -0
  103. package/events/TransactionEventBroadcaster.d.ts +11 -0
  104. package/events/TransactionEventBroadcaster.js +17 -0
  105. package/events/index.d.ts +3 -0
  106. package/events/index.js +19 -0
  107. package/exceptions.d.ts +104 -0
  108. package/exceptions.js +130 -0
  109. package/hydration/Hydrator.d.ts +23 -0
  110. package/hydration/Hydrator.js +51 -0
  111. package/hydration/ObjectHydrator.d.ts +24 -0
  112. package/hydration/ObjectHydrator.js +332 -0
  113. package/hydration/index.d.ts +2 -0
  114. package/hydration/index.js +18 -0
  115. package/index.d.ts +25 -0
  116. package/index.js +50 -0
  117. package/index.mjs +192 -0
  118. package/logging/DefaultLogger.d.ts +32 -0
  119. package/logging/DefaultLogger.js +90 -0
  120. package/logging/Logger.d.ts +56 -0
  121. package/logging/Logger.js +2 -0
  122. package/logging/SimpleLogger.d.ts +17 -0
  123. package/logging/SimpleLogger.js +31 -0
  124. package/logging/colors.d.ts +9 -0
  125. package/logging/colors.js +20 -0
  126. package/logging/index.d.ts +4 -0
  127. package/logging/index.js +20 -0
  128. package/metadata/EntitySchema.d.ts +74 -0
  129. package/metadata/EntitySchema.js +293 -0
  130. package/metadata/MetadataDiscovery.d.ts +71 -0
  131. package/metadata/MetadataDiscovery.js +1244 -0
  132. package/metadata/MetadataProvider.d.ts +11 -0
  133. package/metadata/MetadataProvider.js +23 -0
  134. package/metadata/MetadataStorage.d.ts +22 -0
  135. package/metadata/MetadataStorage.js +87 -0
  136. package/metadata/MetadataValidator.d.ts +24 -0
  137. package/metadata/MetadataValidator.js +213 -0
  138. package/metadata/ReflectMetadataProvider.d.ts +8 -0
  139. package/metadata/ReflectMetadataProvider.js +48 -0
  140. package/metadata/index.d.ts +6 -0
  141. package/metadata/index.js +22 -0
  142. package/naming-strategy/AbstractNamingStrategy.d.ts +18 -0
  143. package/naming-strategy/AbstractNamingStrategy.js +48 -0
  144. package/naming-strategy/EntityCaseNamingStrategy.d.ts +12 -0
  145. package/naming-strategy/EntityCaseNamingStrategy.js +32 -0
  146. package/naming-strategy/MongoNamingStrategy.d.ts +9 -0
  147. package/naming-strategy/MongoNamingStrategy.js +25 -0
  148. package/naming-strategy/NamingStrategy.d.ts +52 -0
  149. package/naming-strategy/NamingStrategy.js +2 -0
  150. package/naming-strategy/UnderscoreNamingStrategy.d.ts +10 -0
  151. package/naming-strategy/UnderscoreNamingStrategy.js +28 -0
  152. package/naming-strategy/index.d.ts +5 -0
  153. package/naming-strategy/index.js +21 -0
  154. package/package.json +70 -0
  155. package/platforms/ExceptionConverter.d.ts +5 -0
  156. package/platforms/ExceptionConverter.js +11 -0
  157. package/platforms/Platform.d.ts +201 -0
  158. package/platforms/Platform.js +452 -0
  159. package/platforms/index.d.ts +2 -0
  160. package/platforms/index.js +18 -0
  161. package/serialization/EntitySerializer.d.ts +34 -0
  162. package/serialization/EntitySerializer.js +206 -0
  163. package/serialization/EntityTransformer.d.ts +8 -0
  164. package/serialization/EntityTransformer.js +192 -0
  165. package/serialization/SerializationContext.d.ts +30 -0
  166. package/serialization/SerializationContext.js +111 -0
  167. package/serialization/index.d.ts +3 -0
  168. package/serialization/index.js +19 -0
  169. package/types/ArrayType.d.ts +13 -0
  170. package/types/ArrayType.js +47 -0
  171. package/types/BigIntType.d.ts +16 -0
  172. package/types/BigIntType.js +45 -0
  173. package/types/BlobType.d.ts +10 -0
  174. package/types/BlobType.js +27 -0
  175. package/types/BooleanType.d.ts +8 -0
  176. package/types/BooleanType.js +16 -0
  177. package/types/DateTimeType.d.ts +8 -0
  178. package/types/DateTimeType.js +16 -0
  179. package/types/DateType.d.ts +8 -0
  180. package/types/DateType.js +16 -0
  181. package/types/DecimalType.d.ts +11 -0
  182. package/types/DecimalType.js +22 -0
  183. package/types/DoubleType.d.ts +11 -0
  184. package/types/DoubleType.js +22 -0
  185. package/types/EnumArrayType.d.ts +9 -0
  186. package/types/EnumArrayType.js +32 -0
  187. package/types/EnumType.d.ts +8 -0
  188. package/types/EnumType.js +16 -0
  189. package/types/FloatType.d.ts +8 -0
  190. package/types/FloatType.js +16 -0
  191. package/types/IntegerType.d.ts +8 -0
  192. package/types/IntegerType.js +16 -0
  193. package/types/IntervalType.d.ts +8 -0
  194. package/types/IntervalType.js +16 -0
  195. package/types/JsonType.d.ts +13 -0
  196. package/types/JsonType.js +34 -0
  197. package/types/MediumIntType.d.ts +6 -0
  198. package/types/MediumIntType.js +10 -0
  199. package/types/SmallIntType.d.ts +8 -0
  200. package/types/SmallIntType.js +16 -0
  201. package/types/StringType.d.ts +8 -0
  202. package/types/StringType.js +16 -0
  203. package/types/TextType.d.ts +8 -0
  204. package/types/TextType.js +16 -0
  205. package/types/TimeType.d.ts +9 -0
  206. package/types/TimeType.js +23 -0
  207. package/types/TinyIntType.d.ts +8 -0
  208. package/types/TinyIntType.js +16 -0
  209. package/types/Type.d.ts +64 -0
  210. package/types/Type.js +84 -0
  211. package/types/Uint8ArrayType.d.ts +11 -0
  212. package/types/Uint8ArrayType.js +37 -0
  213. package/types/UnknownType.d.ts +7 -0
  214. package/types/UnknownType.js +13 -0
  215. package/types/UuidType.d.ts +7 -0
  216. package/types/UuidType.js +13 -0
  217. package/types/index.d.ts +75 -0
  218. package/types/index.js +77 -0
  219. package/typings.d.ts +767 -0
  220. package/typings.js +198 -0
  221. package/unit-of-work/ChangeSet.d.ts +34 -0
  222. package/unit-of-work/ChangeSet.js +62 -0
  223. package/unit-of-work/ChangeSetComputer.d.ts +26 -0
  224. package/unit-of-work/ChangeSetComputer.js +153 -0
  225. package/unit-of-work/ChangeSetPersister.d.ts +50 -0
  226. package/unit-of-work/ChangeSetPersister.js +361 -0
  227. package/unit-of-work/CommitOrderCalculator.d.ts +62 -0
  228. package/unit-of-work/CommitOrderCalculator.js +113 -0
  229. package/unit-of-work/IdentityMap.d.ts +17 -0
  230. package/unit-of-work/IdentityMap.js +84 -0
  231. package/unit-of-work/UnitOfWork.d.ts +124 -0
  232. package/unit-of-work/UnitOfWork.js +1013 -0
  233. package/unit-of-work/index.d.ts +6 -0
  234. package/unit-of-work/index.js +22 -0
  235. package/utils/AbstractSchemaGenerator.d.ts +38 -0
  236. package/utils/AbstractSchemaGenerator.js +101 -0
  237. package/utils/Configuration.d.ts +390 -0
  238. package/utils/Configuration.js +357 -0
  239. package/utils/ConfigurationLoader.d.ts +29 -0
  240. package/utils/ConfigurationLoader.js +282 -0
  241. package/utils/Cursor.d.ts +77 -0
  242. package/utils/Cursor.js +169 -0
  243. package/utils/DataloaderUtils.d.ts +43 -0
  244. package/utils/DataloaderUtils.js +194 -0
  245. package/utils/EntityComparator.d.ts +73 -0
  246. package/utils/EntityComparator.js +568 -0
  247. package/utils/NullHighlighter.d.ts +4 -0
  248. package/utils/NullHighlighter.js +9 -0
  249. package/utils/QueryHelper.d.ts +28 -0
  250. package/utils/QueryHelper.js +228 -0
  251. package/utils/RawQueryFragment.d.ts +96 -0
  252. package/utils/RawQueryFragment.js +188 -0
  253. package/utils/RequestContext.d.ts +34 -0
  254. package/utils/RequestContext.js +54 -0
  255. package/utils/TransactionContext.d.ts +19 -0
  256. package/utils/TransactionContext.js +34 -0
  257. package/utils/Utils.d.ts +274 -0
  258. package/utils/Utils.js +1073 -0
  259. package/utils/clone.d.ts +6 -0
  260. package/utils/clone.js +127 -0
  261. package/utils/index.d.ts +13 -0
  262. package/utils/index.js +29 -0
  263. package/utils/upsert-utils.d.ts +6 -0
  264. 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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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;
@@ -0,0 +1,3 @@
1
+ export * from './EventSubscriber';
2
+ export * from './EventManager';
3
+ export * from './TransactionEventBroadcaster';
@@ -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);
@@ -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 {};