@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.11

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 (261) hide show
  1. package/EntityManager.d.ts +25 -16
  2. package/EntityManager.js +219 -209
  3. package/MikroORM.d.ts +7 -6
  4. package/MikroORM.js +33 -45
  5. package/cache/CacheAdapter.js +1 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +18 -26
  8. package/cache/GeneratedCacheAdapter.d.ts +2 -2
  9. package/cache/GeneratedCacheAdapter.js +1 -5
  10. package/cache/MemoryCacheAdapter.d.ts +1 -1
  11. package/cache/MemoryCacheAdapter.js +1 -5
  12. package/cache/NullCacheAdapter.d.ts +1 -1
  13. package/cache/NullCacheAdapter.js +1 -5
  14. package/cache/index.d.ts +5 -5
  15. package/cache/index.js +5 -21
  16. package/connections/Connection.d.ts +7 -7
  17. package/connections/Connection.js +8 -12
  18. package/connections/index.d.ts +1 -1
  19. package/connections/index.js +1 -17
  20. package/decorators/Check.d.ts +2 -2
  21. package/decorators/Check.js +5 -8
  22. package/decorators/CreateRequestContext.d.ts +1 -1
  23. package/decorators/CreateRequestContext.js +13 -14
  24. package/decorators/Embeddable.d.ts +5 -5
  25. package/decorators/Embeddable.js +4 -7
  26. package/decorators/Embedded.d.ts +3 -3
  27. package/decorators/Embedded.js +10 -12
  28. package/decorators/Entity.d.ts +6 -6
  29. package/decorators/Entity.js +5 -9
  30. package/decorators/Enum.d.ts +3 -3
  31. package/decorators/Enum.js +7 -10
  32. package/decorators/Filter.d.ts +1 -1
  33. package/decorators/Filter.js +3 -6
  34. package/decorators/Formula.d.ts +2 -3
  35. package/decorators/Formula.js +7 -10
  36. package/decorators/Indexed.d.ts +10 -8
  37. package/decorators/Indexed.js +7 -11
  38. package/decorators/ManyToMany.d.ts +4 -4
  39. package/decorators/ManyToMany.js +10 -12
  40. package/decorators/ManyToOne.d.ts +4 -4
  41. package/decorators/ManyToOne.js +10 -12
  42. package/decorators/OneToMany.d.ts +6 -6
  43. package/decorators/OneToMany.js +11 -14
  44. package/decorators/OneToOne.d.ts +4 -4
  45. package/decorators/OneToOne.js +4 -7
  46. package/decorators/PrimaryKey.d.ts +3 -4
  47. package/decorators/PrimaryKey.js +10 -13
  48. package/decorators/Property.d.ts +6 -6
  49. package/decorators/Property.js +10 -12
  50. package/decorators/Transactional.d.ts +2 -2
  51. package/decorators/Transactional.js +7 -10
  52. package/decorators/hooks.js +23 -35
  53. package/decorators/index.d.ts +17 -17
  54. package/decorators/index.js +17 -36
  55. package/drivers/DatabaseDriver.d.ts +13 -12
  56. package/drivers/DatabaseDriver.js +60 -64
  57. package/drivers/IDatabaseDriver.d.ts +16 -13
  58. package/drivers/IDatabaseDriver.js +1 -4
  59. package/drivers/index.d.ts +2 -2
  60. package/drivers/index.js +2 -18
  61. package/entity/ArrayCollection.d.ts +3 -3
  62. package/entity/ArrayCollection.js +38 -35
  63. package/entity/BaseEntity.d.ts +6 -6
  64. package/entity/BaseEntity.js +17 -21
  65. package/entity/Collection.d.ts +6 -7
  66. package/entity/Collection.js +47 -51
  67. package/entity/EntityAssigner.d.ts +2 -2
  68. package/entity/EntityAssigner.js +58 -63
  69. package/entity/EntityFactory.d.ts +3 -3
  70. package/entity/EntityFactory.js +62 -63
  71. package/entity/EntityHelper.d.ts +2 -2
  72. package/entity/EntityHelper.js +44 -45
  73. package/entity/EntityIdentifier.d.ts +1 -1
  74. package/entity/EntityIdentifier.js +1 -5
  75. package/entity/EntityLoader.d.ts +5 -5
  76. package/entity/EntityLoader.js +106 -98
  77. package/entity/EntityRepository.d.ts +7 -7
  78. package/entity/EntityRepository.js +7 -11
  79. package/entity/EntityValidator.d.ts +1 -1
  80. package/entity/EntityValidator.js +25 -29
  81. package/entity/Reference.d.ts +4 -8
  82. package/entity/Reference.js +35 -42
  83. package/entity/WrappedEntity.d.ts +12 -12
  84. package/entity/WrappedEntity.js +23 -27
  85. package/entity/index.d.ts +13 -13
  86. package/entity/index.js +13 -29
  87. package/entity/utils.d.ts +1 -1
  88. package/entity/utils.js +9 -12
  89. package/entity/wrap.d.ts +1 -1
  90. package/entity/wrap.js +2 -6
  91. package/enums.d.ts +3 -3
  92. package/enums.js +37 -41
  93. package/errors.d.ts +1 -1
  94. package/errors.js +15 -24
  95. package/events/EventManager.d.ts +3 -3
  96. package/events/EventManager.js +8 -12
  97. package/events/EventSubscriber.d.ts +8 -5
  98. package/events/EventSubscriber.js +1 -2
  99. package/events/TransactionEventBroadcaster.d.ts +3 -3
  100. package/events/TransactionEventBroadcaster.js +1 -5
  101. package/events/index.d.ts +3 -3
  102. package/events/index.js +3 -19
  103. package/exceptions.js +18 -39
  104. package/hydration/Hydrator.d.ts +5 -5
  105. package/hydration/Hydrator.js +3 -6
  106. package/hydration/ObjectHydrator.d.ts +3 -3
  107. package/hydration/ObjectHydrator.js +26 -28
  108. package/hydration/index.d.ts +2 -2
  109. package/hydration/index.js +2 -18
  110. package/index.d.ts +21 -21
  111. package/index.js +21 -46
  112. package/logging/DefaultLogger.d.ts +1 -1
  113. package/logging/DefaultLogger.js +9 -13
  114. package/logging/Logger.d.ts +1 -1
  115. package/logging/Logger.js +1 -2
  116. package/logging/SimpleLogger.d.ts +2 -2
  117. package/logging/SimpleLogger.js +2 -6
  118. package/logging/colors.js +1 -5
  119. package/logging/index.d.ts +4 -4
  120. package/logging/index.js +4 -20
  121. package/metadata/EntitySchema.d.ts +14 -6
  122. package/metadata/EntitySchema.js +41 -45
  123. package/metadata/MetadataDiscovery.d.ts +7 -7
  124. package/metadata/MetadataDiscovery.js +181 -180
  125. package/metadata/MetadataProvider.d.ts +2 -2
  126. package/metadata/MetadataProvider.js +4 -7
  127. package/metadata/MetadataStorage.d.ts +2 -2
  128. package/metadata/MetadataStorage.js +15 -19
  129. package/metadata/MetadataValidator.d.ts +4 -4
  130. package/metadata/MetadataValidator.js +52 -55
  131. package/metadata/ReflectMetadataProvider.d.ts +2 -2
  132. package/metadata/ReflectMetadataProvider.js +8 -12
  133. package/metadata/index.d.ts +6 -6
  134. package/metadata/index.js +6 -22
  135. package/naming-strategy/AbstractNamingStrategy.d.ts +2 -2
  136. package/naming-strategy/AbstractNamingStrategy.js +4 -8
  137. package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
  138. package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
  139. package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
  140. package/naming-strategy/MongoNamingStrategy.js +2 -6
  141. package/naming-strategy/NamingStrategy.d.ts +1 -1
  142. package/naming-strategy/NamingStrategy.js +1 -2
  143. package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
  144. package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
  145. package/naming-strategy/index.d.ts +5 -5
  146. package/naming-strategy/index.js +5 -21
  147. package/package.json +6 -15
  148. package/platforms/ExceptionConverter.d.ts +2 -2
  149. package/platforms/ExceptionConverter.js +4 -8
  150. package/platforms/Platform.d.ts +10 -10
  151. package/platforms/Platform.js +57 -61
  152. package/platforms/index.d.ts +2 -2
  153. package/platforms/index.js +2 -18
  154. package/serialization/EntitySerializer.d.ts +2 -2
  155. package/serialization/EntitySerializer.js +36 -41
  156. package/serialization/EntityTransformer.d.ts +1 -1
  157. package/serialization/EntityTransformer.js +27 -31
  158. package/serialization/SerializationContext.d.ts +2 -2
  159. package/serialization/SerializationContext.js +10 -14
  160. package/serialization/index.d.ts +3 -3
  161. package/serialization/index.js +3 -19
  162. package/types/ArrayType.d.ts +3 -3
  163. package/types/ArrayType.js +7 -11
  164. package/types/BigIntType.d.ts +4 -3
  165. package/types/BigIntType.js +6 -6
  166. package/types/BlobType.d.ts +3 -3
  167. package/types/BlobType.js +2 -8
  168. package/types/BooleanType.d.ts +3 -3
  169. package/types/BooleanType.js +2 -6
  170. package/types/CharacterType.d.ts +3 -3
  171. package/types/CharacterType.js +2 -6
  172. package/types/DateTimeType.d.ts +3 -3
  173. package/types/DateTimeType.js +2 -6
  174. package/types/DateType.d.ts +3 -3
  175. package/types/DateType.js +2 -6
  176. package/types/DecimalType.d.ts +3 -3
  177. package/types/DecimalType.js +4 -7
  178. package/types/DoubleType.d.ts +3 -3
  179. package/types/DoubleType.js +3 -6
  180. package/types/EnumArrayType.d.ts +4 -4
  181. package/types/EnumArrayType.js +5 -10
  182. package/types/EnumType.d.ts +3 -3
  183. package/types/EnumType.js +2 -6
  184. package/types/FloatType.d.ts +3 -3
  185. package/types/FloatType.js +2 -6
  186. package/types/IntegerType.d.ts +3 -3
  187. package/types/IntegerType.js +2 -6
  188. package/types/IntervalType.d.ts +3 -3
  189. package/types/IntervalType.js +2 -6
  190. package/types/JsonType.d.ts +3 -3
  191. package/types/JsonType.js +2 -6
  192. package/types/MediumIntType.d.ts +3 -3
  193. package/types/MediumIntType.js +2 -6
  194. package/types/SmallIntType.d.ts +3 -3
  195. package/types/SmallIntType.js +2 -6
  196. package/types/StringType.d.ts +3 -3
  197. package/types/StringType.js +2 -6
  198. package/types/TextType.d.ts +3 -3
  199. package/types/TextType.js +2 -6
  200. package/types/TimeType.d.ts +3 -3
  201. package/types/TimeType.js +4 -8
  202. package/types/TinyIntType.d.ts +3 -3
  203. package/types/TinyIntType.js +3 -6
  204. package/types/Type.d.ts +2 -2
  205. package/types/Type.js +5 -9
  206. package/types/Uint8ArrayType.d.ts +3 -3
  207. package/types/Uint8ArrayType.js +3 -9
  208. package/types/UnknownType.d.ts +3 -3
  209. package/types/UnknownType.js +2 -6
  210. package/types/UuidType.d.ts +3 -3
  211. package/types/UuidType.js +2 -6
  212. package/types/index.d.ts +25 -25
  213. package/types/index.js +52 -79
  214. package/typings.d.ts +33 -28
  215. package/typings.js +37 -38
  216. package/unit-of-work/ChangeSet.d.ts +1 -1
  217. package/unit-of-work/ChangeSet.js +13 -17
  218. package/unit-of-work/ChangeSetComputer.d.ts +8 -7
  219. package/unit-of-work/ChangeSetComputer.js +26 -30
  220. package/unit-of-work/ChangeSetPersister.d.ts +7 -6
  221. package/unit-of-work/ChangeSetPersister.js +51 -48
  222. package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
  223. package/unit-of-work/CommitOrderCalculator.js +6 -10
  224. package/unit-of-work/IdentityMap.d.ts +1 -1
  225. package/unit-of-work/IdentityMap.js +1 -5
  226. package/unit-of-work/UnitOfWork.d.ts +8 -7
  227. package/unit-of-work/UnitOfWork.js +193 -178
  228. package/unit-of-work/index.d.ts +6 -6
  229. package/unit-of-work/index.js +6 -22
  230. package/utils/AbstractSchemaGenerator.d.ts +6 -6
  231. package/utils/AbstractSchemaGenerator.js +12 -13
  232. package/utils/Configuration.d.ts +26 -27
  233. package/utils/Configuration.js +50 -55
  234. package/utils/ConfigurationLoader.d.ts +9 -8
  235. package/utils/ConfigurationLoader.js +71 -86
  236. package/utils/Cursor.d.ts +6 -6
  237. package/utils/Cursor.js +22 -25
  238. package/utils/DataloaderUtils.d.ts +4 -4
  239. package/utils/DataloaderUtils.js +12 -16
  240. package/utils/EntityComparator.d.ts +2 -2
  241. package/utils/EntityComparator.js +109 -97
  242. package/utils/NullHighlighter.d.ts +1 -1
  243. package/utils/NullHighlighter.js +1 -5
  244. package/utils/QueryHelper.d.ts +3 -3
  245. package/utils/QueryHelper.js +47 -51
  246. package/utils/RawQueryFragment.d.ts +1 -1
  247. package/utils/RawQueryFragment.js +22 -25
  248. package/utils/RequestContext.d.ts +2 -2
  249. package/utils/RequestContext.js +3 -7
  250. package/utils/TransactionContext.d.ts +1 -1
  251. package/utils/TransactionContext.js +4 -8
  252. package/utils/Utils.d.ts +16 -12
  253. package/utils/Utils.js +96 -95
  254. package/utils/clone.js +8 -11
  255. package/utils/index.d.ts +13 -13
  256. package/utils/index.js +13 -29
  257. package/utils/resolveContextProvider.d.ts +3 -3
  258. package/utils/resolveContextProvider.js +9 -12
  259. package/utils/upsert-utils.d.ts +3 -3
  260. package/utils/upsert-utils.js +5 -9
  261. package/index.mjs +0 -199
@@ -1,59 +1,47 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BeforeCreate = BeforeCreate;
4
- exports.AfterCreate = AfterCreate;
5
- exports.BeforeUpdate = BeforeUpdate;
6
- exports.AfterUpdate = AfterUpdate;
7
- exports.BeforeUpsert = BeforeUpsert;
8
- exports.AfterUpsert = AfterUpsert;
9
- exports.OnInit = OnInit;
10
- exports.OnLoad = OnLoad;
11
- exports.BeforeDelete = BeforeDelete;
12
- exports.AfterDelete = AfterDelete;
13
- const metadata_1 = require("../metadata");
14
- const enums_1 = require("../enums");
1
+ import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
+ import { EventType } from '../enums.js';
15
3
  function hook(type) {
16
4
  return function (target, method) {
17
- const meta = metadata_1.MetadataStorage.getMetadataFromDecorator(target.constructor);
5
+ const meta = MetadataStorage.getMetadataFromDecorator(target.constructor);
18
6
  if (!meta.hooks[type]) {
19
7
  meta.hooks[type] = [];
20
8
  }
21
9
  meta.hooks[type].push(method);
22
10
  };
23
11
  }
24
- function BeforeCreate() {
25
- return hook(enums_1.EventType.beforeCreate);
12
+ export function BeforeCreate() {
13
+ return hook(EventType.beforeCreate);
26
14
  }
27
- function AfterCreate() {
28
- return hook(enums_1.EventType.afterCreate);
15
+ export function AfterCreate() {
16
+ return hook(EventType.afterCreate);
29
17
  }
30
- function BeforeUpdate() {
31
- return hook(enums_1.EventType.beforeUpdate);
18
+ export function BeforeUpdate() {
19
+ return hook(EventType.beforeUpdate);
32
20
  }
33
- function AfterUpdate() {
34
- return hook(enums_1.EventType.afterUpdate);
21
+ export function AfterUpdate() {
22
+ return hook(EventType.afterUpdate);
35
23
  }
36
- function BeforeUpsert() {
37
- return hook(enums_1.EventType.beforeUpsert);
24
+ export function BeforeUpsert() {
25
+ return hook(EventType.beforeUpsert);
38
26
  }
39
- function AfterUpsert() {
40
- return hook(enums_1.EventType.afterUpsert);
27
+ export function AfterUpsert() {
28
+ return hook(EventType.afterUpsert);
41
29
  }
42
- function OnInit() {
43
- return hook(enums_1.EventType.onInit);
30
+ export function OnInit() {
31
+ return hook(EventType.onInit);
44
32
  }
45
- function OnLoad() {
46
- return hook(enums_1.EventType.onLoad);
33
+ export function OnLoad() {
34
+ return hook(EventType.onLoad);
47
35
  }
48
36
  /**
49
37
  * Called before deleting entity, but only when providing initialized entity to EM#remove()
50
38
  */
51
- function BeforeDelete() {
52
- return hook(enums_1.EventType.beforeDelete);
39
+ export function BeforeDelete() {
40
+ return hook(EventType.beforeDelete);
53
41
  }
54
42
  /**
55
43
  * Called after deleting entity, but only when providing initialized entity to EM#remove()
56
44
  */
57
- function AfterDelete() {
58
- return hook(enums_1.EventType.afterDelete);
45
+ export function AfterDelete() {
46
+ return hook(EventType.afterDelete);
59
47
  }
@@ -1,17 +1,17 @@
1
- export * from './PrimaryKey';
2
- export * from './Entity';
3
- export * from './OneToOne';
4
- export * from './ManyToOne';
5
- export * from './ManyToMany';
6
- export { OneToMany, OneToManyOptions } from './OneToMany';
7
- export * from './Property';
8
- export * from './Check';
9
- export * from './Enum';
10
- export * from './Formula';
11
- export * from './Indexed';
12
- export * from './Embeddable';
13
- export * from './Embedded';
14
- export * from './Filter';
15
- export * from './CreateRequestContext';
16
- export * from './hooks';
17
- export * from './Transactional';
1
+ export * from './PrimaryKey.js';
2
+ export * from './Entity.js';
3
+ export * from './OneToOne.js';
4
+ export * from './ManyToOne.js';
5
+ export * from './ManyToMany.js';
6
+ export { OneToMany, OneToManyOptions } from './OneToMany.js';
7
+ export * from './Property.js';
8
+ export * from './Check.js';
9
+ export * from './Enum.js';
10
+ export * from './Formula.js';
11
+ export * from './Indexed.js';
12
+ export * from './Embeddable.js';
13
+ export * from './Embedded.js';
14
+ export * from './Filter.js';
15
+ export * from './CreateRequestContext.js';
16
+ export * from './hooks.js';
17
+ export * from './Transactional.js';
@@ -1,36 +1,17 @@
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
- exports.OneToMany = void 0;
18
- /* istanbul ignore file */
19
- __exportStar(require("./PrimaryKey"), exports);
20
- __exportStar(require("./Entity"), exports);
21
- __exportStar(require("./OneToOne"), exports);
22
- __exportStar(require("./ManyToOne"), exports);
23
- __exportStar(require("./ManyToMany"), exports);
24
- var OneToMany_1 = require("./OneToMany");
25
- Object.defineProperty(exports, "OneToMany", { enumerable: true, get: function () { return OneToMany_1.OneToMany; } });
26
- __exportStar(require("./Property"), exports);
27
- __exportStar(require("./Check"), exports);
28
- __exportStar(require("./Enum"), exports);
29
- __exportStar(require("./Formula"), exports);
30
- __exportStar(require("./Indexed"), exports);
31
- __exportStar(require("./Embeddable"), exports);
32
- __exportStar(require("./Embedded"), exports);
33
- __exportStar(require("./Filter"), exports);
34
- __exportStar(require("./CreateRequestContext"), exports);
35
- __exportStar(require("./hooks"), exports);
36
- __exportStar(require("./Transactional"), exports);
1
+ export * from './PrimaryKey.js';
2
+ export * from './Entity.js';
3
+ export * from './OneToOne.js';
4
+ export * from './ManyToOne.js';
5
+ export * from './ManyToMany.js';
6
+ export { OneToMany } from './OneToMany.js';
7
+ export * from './Property.js';
8
+ export * from './Check.js';
9
+ export * from './Enum.js';
10
+ export * from './Formula.js';
11
+ export * from './Indexed.js';
12
+ export * from './Embeddable.js';
13
+ export * from './Embedded.js';
14
+ export * from './Filter.js';
15
+ export * from './CreateRequestContext.js';
16
+ export * from './hooks.js';
17
+ export * from './Transactional.js';
@@ -1,14 +1,15 @@
1
- import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition } from './IDatabaseDriver';
2
- import type { ConnectionType, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings';
3
- import type { MetadataStorage } from '../metadata';
4
- import type { Connection, QueryResult, Transaction } from '../connections';
5
- import { type Configuration, type ConnectionOptions, EntityComparator } from '../utils';
6
- import { type QueryOrder } from '../enums';
7
- import type { Platform } from '../platforms';
8
- import type { Collection } from '../entity/Collection';
9
- import { EntityManager } from '../EntityManager';
10
- import { DriverException } from '../exceptions';
11
- import type { Logger } from '../logging/Logger';
1
+ import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition } from './IDatabaseDriver.js';
2
+ import type { ConnectionType, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings.js';
3
+ import type { MetadataStorage } from '../metadata/MetadataStorage.js';
4
+ import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
5
+ import { type Configuration, type ConnectionOptions } from '../utils/Configuration.js';
6
+ import { EntityComparator } from '../utils/EntityComparator.js';
7
+ import { type QueryOrder } from '../enums.js';
8
+ import type { Platform } from '../platforms/Platform.js';
9
+ import type { Collection } from '../entity/Collection.js';
10
+ import { EntityManager } from '../EntityManager.js';
11
+ import { DriverException } from '../exceptions.js';
12
+ import type { Logger } from '../logging/Logger.js';
12
13
  export declare abstract class DatabaseDriver<C extends Connection> implements IDatabaseDriver<C> {
13
14
  readonly config: Configuration;
14
15
  protected readonly dependencies: string[];
@@ -28,7 +29,7 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
28
29
  nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
29
30
  abstract nativeDelete<T extends object>(entityName: string, where: FilterQuery<T>, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
30
31
  abstract count<T extends object, P extends string = never>(entityName: string, where: FilterQuery<T>, options?: CountOptions<T, P>): Promise<number>;
31
- createEntityManager<D extends IDatabaseDriver = IDatabaseDriver>(useContext?: boolean): D[typeof EntityManagerType];
32
+ createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
32
33
  findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
33
34
  countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
34
35
  aggregate(entityName: string, pipeline: any[]): Promise<any[]>;
@@ -1,18 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DatabaseDriver = void 0;
4
- const IDatabaseDriver_1 = require("./IDatabaseDriver");
5
- const utils_1 = require("../utils");
6
- const enums_1 = require("../enums");
7
- const EntityManager_1 = require("../EntityManager");
8
- const errors_1 = require("../errors");
9
- const exceptions_1 = require("../exceptions");
10
- const wrap_1 = require("../entity/wrap");
11
- const JsonType_1 = require("../types/JsonType");
12
- class DatabaseDriver {
1
+ import { EntityManagerType, } from './IDatabaseDriver.js';
2
+ import { Utils } from '../utils/Utils.js';
3
+ import { Cursor } from '../utils/Cursor.js';
4
+ import { EntityComparator } from '../utils/EntityComparator.js';
5
+ import { isRaw, raw } from '../utils/RawQueryFragment.js';
6
+ import { QueryOrderNumeric, ReferenceKind } from '../enums.js';
7
+ import { EntityManager } from '../EntityManager.js';
8
+ import { CursorError, ValidationError } from '../errors.js';
9
+ import { DriverException } from '../exceptions.js';
10
+ import { helper } from '../entity/wrap.js';
11
+ import { JsonType } from '../types/JsonType.js';
12
+ export class DatabaseDriver {
13
13
  config;
14
14
  dependencies;
15
- [IDatabaseDriver_1.EntityManagerType];
15
+ [EntityManagerType];
16
16
  connection;
17
17
  replicas = [];
18
18
  platform;
@@ -28,14 +28,14 @@ class DatabaseDriver {
28
28
  throw new Error(`Batch updates are not supported by ${this.constructor.name} driver`);
29
29
  }
30
30
  createEntityManager(useContext) {
31
- const EntityManagerClass = this.config.get('entityManager', EntityManager_1.EntityManager);
31
+ const EntityManagerClass = this.config.get('entityManager', EntityManager);
32
32
  return new EntityManagerClass(this.config, this, this.metadata, useContext);
33
33
  }
34
- /* istanbul ignore next */
34
+ /* v8 ignore next 3 */
35
35
  async findVirtual(entityName, where, options) {
36
36
  throw new Error(`Virtual entities are not supported by ${this.constructor.name} driver.`);
37
37
  }
38
- /* istanbul ignore next */
38
+ /* v8 ignore next 3 */
39
39
  async countVirtual(entityName, where, options) {
40
40
  throw new Error(`Counting virtual entities is not supported by ${this.constructor.name} driver.`);
41
41
  }
@@ -49,16 +49,14 @@ class DatabaseDriver {
49
49
  for (const coll of collections) {
50
50
  if (!coll.property.owner) {
51
51
  if (coll.getSnapshot() === undefined) {
52
- throw errors_1.ValidationError.cannotModifyInverseCollection(coll.owner, coll.property);
52
+ throw ValidationError.cannotModifyInverseCollection(coll.owner, coll.property);
53
53
  }
54
54
  continue;
55
55
  }
56
- /* istanbul ignore next */
57
- {
58
- const pk = coll.property.targetMeta.primaryKeys[0];
59
- const data = { [coll.property.name]: coll.getIdentifiers(pk) };
60
- await this.nativeUpdate(coll.owner.constructor.name, (0, wrap_1.helper)(coll.owner).getPrimaryKey(), data, options);
61
- }
56
+ /* v8 ignore next 3 */
57
+ const pk = coll.property.targetMeta.primaryKeys[0];
58
+ const data = { [coll.property.name]: coll.getIdentifiers(pk) };
59
+ await this.nativeUpdate(coll.owner.constructor.name, helper(coll.owner).getPrimaryKey(), data, options);
62
60
  }
63
61
  }
64
62
  mapResult(result, meta, populate = []) {
@@ -81,7 +79,7 @@ class DatabaseDriver {
81
79
  if (type === 'write' || this.replicas.length === 0) {
82
80
  return this.connection;
83
81
  }
84
- const rand = utils_1.Utils.randomInt(0, this.replicas.length - 1);
82
+ const rand = Utils.randomInt(0, this.replicas.length - 1);
85
83
  return this.replicas[rand];
86
84
  }
87
85
  async close(force) {
@@ -93,7 +91,7 @@ class DatabaseDriver {
93
91
  }
94
92
  setMetadata(metadata) {
95
93
  this.metadata = metadata;
96
- this.comparator = new utils_1.EntityComparator(this.metadata, this.platform);
94
+ this.comparator = new EntityComparator(this.metadata, this.platform);
97
95
  this.connection.setMetadata(metadata);
98
96
  this.connection.setPlatform(this.platform);
99
97
  this.replicas.forEach(replica => {
@@ -111,7 +109,7 @@ class DatabaseDriver {
111
109
  const { first, last, before, after, overfetch } = options;
112
110
  const limit = first ?? last;
113
111
  const isLast = !first && !!last;
114
- const definition = utils_1.Cursor.getDefinition(meta, orderBy);
112
+ const definition = Cursor.getDefinition(meta, orderBy);
115
113
  const $and = [];
116
114
  // allow POJO as well, we care only about the correct key being present
117
115
  const isCursor = (val, key) => {
@@ -119,15 +117,15 @@ class DatabaseDriver {
119
117
  };
120
118
  const createCursor = (val, key, inverse = false) => {
121
119
  let def = isCursor(val, key) ? val[key] : val;
122
- if (utils_1.Utils.isPlainObject(def)) {
123
- def = utils_1.Cursor.for(meta, def, orderBy);
120
+ if (Utils.isPlainObject(def)) {
121
+ def = Cursor.for(meta, def, orderBy);
124
122
  }
125
- /* istanbul ignore next */
126
- const offsets = def ? utils_1.Cursor.decode(def) : [];
123
+ /* v8 ignore next */
124
+ const offsets = def ? Cursor.decode(def) : [];
127
125
  if (definition.length === offsets.length) {
128
126
  return this.createCursorCondition(definition, offsets, inverse, meta);
129
127
  }
130
- /* istanbul ignore next */
128
+ /* v8 ignore next */
131
129
  return {};
132
130
  };
133
131
  if (after) {
@@ -140,15 +138,15 @@ class DatabaseDriver {
140
138
  options.limit = limit + (overfetch ? 1 : 0);
141
139
  }
142
140
  const createOrderBy = (prop, direction) => {
143
- if (utils_1.Utils.isPlainObject(direction)) {
144
- const value = utils_1.Utils.keys(direction).reduce((o, key) => {
141
+ if (Utils.isPlainObject(direction)) {
142
+ const value = Utils.keys(direction).reduce((o, key) => {
145
143
  Object.assign(o, createOrderBy(key, direction[key]));
146
144
  return o;
147
145
  }, {});
148
146
  return ({ [prop]: value });
149
147
  }
150
- const desc = direction === enums_1.QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
151
- const dir = utils_1.Utils.xor(desc, isLast) ? 'desc' : 'asc';
148
+ const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
149
+ const dir = Utils.xor(desc, isLast) ? 'desc' : 'asc';
152
150
  return ({ [prop]: dir });
153
151
  };
154
152
  return {
@@ -156,24 +154,23 @@ class DatabaseDriver {
156
154
  where: ($and.length > 1 ? { $and } : { ...$and[0] }),
157
155
  };
158
156
  }
159
- /* istanbul ignore next */
160
157
  createCursorCondition(definition, offsets, inverse, meta) {
161
158
  const createCondition = (prop, direction, offset, eq = false) => {
162
159
  if (offset === null) {
163
- throw errors_1.CursorError.missingValue(meta.className, prop);
160
+ throw CursorError.missingValue(meta.className, prop);
164
161
  }
165
- if (utils_1.Utils.isPlainObject(direction)) {
166
- const value = utils_1.Utils.keys(direction).reduce((o, key) => {
167
- if (utils_1.Utils.isEmpty(offset[key])) {
168
- throw errors_1.CursorError.missingValue(meta.className, `${prop}.${key}`);
162
+ if (Utils.isPlainObject(direction)) {
163
+ const value = Utils.keys(direction).reduce((o, key) => {
164
+ if (Utils.isEmpty(offset[key])) {
165
+ throw CursorError.missingValue(meta.className, `${prop}.${key}`);
169
166
  }
170
167
  Object.assign(o, createCondition(key, direction[key], offset[key], eq));
171
168
  return o;
172
169
  }, {});
173
170
  return ({ [prop]: value });
174
171
  }
175
- const desc = direction === enums_1.QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
176
- const operator = utils_1.Utils.xor(desc, inverse) ? '$lt' : '$gt';
172
+ const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
173
+ const operator = Utils.xor(desc, inverse) ? '$lt' : '$gt';
177
174
  return { [prop]: { [operator + (eq ? 'e' : '')]: offset } };
178
175
  };
179
176
  const [order, ...otherOrders] = definition;
@@ -222,7 +219,7 @@ class DatabaseDriver {
222
219
  return;
223
220
  }
224
221
  if (prop.joinColumns && Array.isArray(data[k])) {
225
- const copy = utils_1.Utils.flatten(data[k]);
222
+ const copy = Utils.flatten(data[k]);
226
223
  delete data[k];
227
224
  prop.joinColumns.forEach((joinColumn, idx) => data[joinColumn] = copy[idx]);
228
225
  return;
@@ -232,49 +229,49 @@ class DatabaseDriver {
232
229
  prop.ownColumns.forEach(joinColumn => data[joinColumn] = null);
233
230
  return;
234
231
  }
235
- if (prop.customType && convertCustomTypes && !(prop.customType instanceof JsonType_1.JsonType && object) && !(0, utils_1.isRaw)(data[k])) {
232
+ if (prop.customType && convertCustomTypes && !(prop.customType instanceof JsonType && object) && !isRaw(data[k])) {
236
233
  data[k] = prop.customType.convertToDatabaseValue(data[k], this.platform, { fromQuery: true, key: k, mode: 'query-data' });
237
234
  }
238
- if (prop.hasConvertToDatabaseValueSQL && !prop.object && !(0, utils_1.isRaw)(data[k])) {
235
+ if (prop.hasConvertToDatabaseValueSQL && !prop.object && !isRaw(data[k])) {
239
236
  const quoted = this.platform.quoteValue(data[k]);
240
237
  const sql = prop.customType.convertToDatabaseValueSQL(quoted, this.platform);
241
- data[k] = (0, utils_1.raw)(sql.replace(/\?/g, '\\?'));
238
+ data[k] = raw(sql.replace(/\?/g, '\\?'));
242
239
  }
243
240
  if (prop.fieldNames) {
244
- utils_1.Utils.renameKey(data, k, prop.fieldNames[0]);
241
+ Utils.renameKey(data, k, prop.fieldNames[0]);
245
242
  }
246
243
  });
247
244
  return data;
248
245
  }
249
246
  inlineEmbeddables(meta, data, where) {
250
- /* istanbul ignore next */
247
+ /* v8 ignore next 3 */
251
248
  if (data == null) {
252
249
  return;
253
250
  }
254
- utils_1.Utils.keys(data).forEach(k => {
255
- if (utils_1.Utils.isOperator(k)) {
256
- utils_1.Utils.asArray(data[k]).forEach(payload => this.inlineEmbeddables(meta, payload, where));
251
+ Utils.keys(data).forEach(k => {
252
+ if (Utils.isOperator(k)) {
253
+ Utils.asArray(data[k]).forEach(payload => this.inlineEmbeddables(meta, payload, where));
257
254
  }
258
255
  });
259
256
  meta.props.forEach(prop => {
260
- if (prop.kind === enums_1.ReferenceKind.EMBEDDED && prop.object && !where && utils_1.Utils.isObject(data[prop.name])) {
257
+ if (prop.kind === ReferenceKind.EMBEDDED && prop.object && !where && Utils.isObject(data[prop.name])) {
261
258
  return;
262
259
  }
263
- if (prop.kind === enums_1.ReferenceKind.EMBEDDED && utils_1.Utils.isObject(data[prop.name])) {
260
+ if (prop.kind === ReferenceKind.EMBEDDED && Utils.isObject(data[prop.name])) {
264
261
  const props = prop.embeddedProps;
265
262
  let unknownProp = false;
266
263
  Object.keys(data[prop.name]).forEach(kk => {
267
264
  // explicitly allow `$exists`, `$eq` and `$ne` operators here as they can't be misused this way
268
- const operator = Object.keys(data[prop.name]).some(f => utils_1.Utils.isOperator(f) && !['$exists', '$ne', '$eq'].includes(f));
265
+ const operator = Object.keys(data[prop.name]).some(f => Utils.isOperator(f) && !['$exists', '$ne', '$eq'].includes(f));
269
266
  if (operator) {
270
- throw errors_1.ValidationError.cannotUseOperatorsInsideEmbeddables(meta.className, prop.name, data);
267
+ throw ValidationError.cannotUseOperatorsInsideEmbeddables(meta.className, prop.name, data);
271
268
  }
272
269
  if (prop.object && where) {
273
270
  const inline = (payload, sub, path) => {
274
- if (sub.kind === enums_1.ReferenceKind.EMBEDDED && utils_1.Utils.isObject(payload[sub.embedded[1]])) {
271
+ if (sub.kind === ReferenceKind.EMBEDDED && Utils.isObject(payload[sub.embedded[1]])) {
275
272
  return Object.keys(payload[sub.embedded[1]]).forEach(kkk => {
276
273
  if (!sub.embeddedProps[kkk]) {
277
- throw errors_1.ValidationError.invalidEmbeddableQuery(meta.className, kkk, sub.type);
274
+ throw ValidationError.invalidEmbeddableQuery(meta.className, kkk, sub.type);
278
275
  }
279
276
  inline(payload[sub.embedded[1]], sub.embeddedProps[kkk], [...path, sub.embedded[1]]);
280
277
  });
@@ -284,7 +281,7 @@ class DatabaseDriver {
284
281
  const parentPropName = kk.substring(0, kk.indexOf('.'));
285
282
  // we might be using some native JSON operator, e.g. with mongodb's `$geoWithin` or `$exists`
286
283
  if (props[kk]) {
287
- /* istanbul ignore next */
284
+ /* v8 ignore next */
288
285
  inline(data[prop.name], props[kk] || props[parentPropName], [prop.name]);
289
286
  }
290
287
  else if (props[parentPropName]) {
@@ -298,7 +295,7 @@ class DatabaseDriver {
298
295
  data[props[kk].name] = data[prop.name][props[kk].embedded[1]];
299
296
  }
300
297
  else {
301
- throw errors_1.ValidationError.invalidEmbeddableQuery(meta.className, kk, prop.type);
298
+ throw ValidationError.invalidEmbeddableQuery(meta.className, kk, prop.type);
302
299
  }
303
300
  });
304
301
  if (!unknownProp) {
@@ -309,14 +306,14 @@ class DatabaseDriver {
309
306
  }
310
307
  getPrimaryKeyFields(entityName) {
311
308
  const meta = this.metadata.find(entityName);
312
- return meta ? utils_1.Utils.flatten(meta.getPrimaryProps().map(pk => pk.fieldNames)) : [this.config.getNamingStrategy().referenceColumnName()];
309
+ return meta ? Utils.flatten(meta.getPrimaryProps().map(pk => pk.fieldNames)) : [this.config.getNamingStrategy().referenceColumnName()];
313
310
  }
314
311
  createReplicas(cb) {
315
312
  const replicas = this.config.get('replicas', []);
316
313
  const ret = [];
317
314
  const props = ['dbName', 'clientUrl', 'host', 'port', 'user', 'password', 'multipleStatements', 'pool', 'name', 'driverOptions'];
318
315
  for (const conf of replicas) {
319
- const replicaConfig = utils_1.Utils.copy(conf);
316
+ const replicaConfig = Utils.copy(conf);
320
317
  for (const prop of props) {
321
318
  if (conf[prop]) {
322
319
  continue;
@@ -341,7 +338,7 @@ class DatabaseDriver {
341
338
  * @inheritDoc
342
339
  */
343
340
  convertException(exception) {
344
- if (exception instanceof exceptions_1.DriverException) {
341
+ if (exception instanceof DriverException) {
345
342
  return exception;
346
343
  }
347
344
  return this.platform.getExceptionConverter().convertException(exception);
@@ -376,4 +373,3 @@ class DatabaseDriver {
376
373
  return options?.schema ?? options?.parentSchema ?? schemaName ?? this.config.getSchema();
377
374
  }
378
375
  }
379
- exports.DatabaseDriver = DatabaseDriver;
@@ -1,19 +1,19 @@
1
- import type { ConnectionType, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary, Dictionary, QBFilterQuery, IPrimaryKey, PopulateOptions, EntityDictionary, AutoPath, ObjectQuery, FilterObject, Populate } from '../typings';
2
- import type { Connection, QueryResult, Transaction } from '../connections';
3
- import type { FlushMode, LockMode, QueryOrderMap, QueryFlag, LoadStrategy, PopulateHint, PopulatePath } from '../enums';
4
- import type { Platform } from '../platforms';
5
- import type { MetadataStorage } from '../metadata';
6
- import type { Collection } from '../entity/Collection';
7
- import type { EntityManager } from '../EntityManager';
8
- import type { DriverException } from '../exceptions';
9
- import type { Configuration } from '../utils/Configuration';
10
- import type { LoggingOptions, LogContext } from '../logging';
11
- import type { RawQueryFragment } from '../utils/RawQueryFragment';
1
+ import type { ConnectionType, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary, Dictionary, QBFilterQuery, IPrimaryKey, PopulateOptions, EntityDictionary, AutoPath, ObjectQuery, FilterObject, Populate } from '../typings.js';
2
+ import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
3
+ import type { FlushMode, LockMode, QueryOrderMap, QueryFlag, LoadStrategy, PopulateHint, PopulatePath } from '../enums.js';
4
+ import type { Platform } from '../platforms/Platform.js';
5
+ import type { MetadataStorage } from '../metadata/MetadataStorage.js';
6
+ import type { Collection } from '../entity/Collection.js';
7
+ import type { EntityManager } from '../EntityManager.js';
8
+ import type { DriverException } from '../exceptions.js';
9
+ import type { Configuration } from '../utils/Configuration.js';
10
+ import type { LoggingOptions, LogContext } from '../logging/Logger.js';
11
+ import type { RawQueryFragment } from '../utils/RawQueryFragment.js';
12
12
  export declare const EntityManagerType: unique symbol;
13
13
  export interface IDatabaseDriver<C extends Connection = Connection> {
14
14
  [EntityManagerType]: EntityManager<this>;
15
15
  readonly config: Configuration;
16
- createEntityManager<D extends IDatabaseDriver = IDatabaseDriver>(useContext?: boolean): D[typeof EntityManagerType];
16
+ createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
17
17
  connect(): Promise<C>;
18
18
  close(force?: boolean): Promise<void>;
19
19
  reconnect(): Promise<C>;
@@ -146,8 +146,11 @@ export interface FindOptions<Entity, Hint extends string = never, Fields extends
146
146
  hintComments?: string | string[];
147
147
  loggerContext?: LogContext;
148
148
  logging?: LoggingOptions;
149
+ /** @internal used to apply filters to the auto-joined relations */
150
+ em?: EntityManager;
149
151
  }
150
- export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
152
+ export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never, I extends boolean = true> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
153
+ includeCount?: I;
151
154
  }
152
155
  export interface FindOneOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'lockMode'> {
153
156
  lockMode?: LockMode;
@@ -1,4 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EntityManagerType = void 0;
4
- exports.EntityManagerType = Symbol('EntityManagerType');
1
+ export const EntityManagerType = Symbol('EntityManagerType');
@@ -1,2 +1,2 @@
1
- export * from './IDatabaseDriver';
2
- export * from './DatabaseDriver';
1
+ export * from './IDatabaseDriver.js';
2
+ export * from './DatabaseDriver.js';
package/drivers/index.js CHANGED
@@ -1,18 +1,2 @@
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("./IDatabaseDriver"), exports);
18
- __exportStar(require("./DatabaseDriver"), exports);
1
+ export * from './IDatabaseDriver.js';
2
+ export * from './DatabaseDriver.js';
@@ -1,6 +1,6 @@
1
1
  import { inspect } from 'node:util';
2
- import type { EntityDTO, EntityProperty, IPrimaryKey, Primary } from '../typings';
3
- import { Reference } from './Reference';
2
+ import type { EntityDTO, EntityProperty, IPrimaryKey, Primary } from '../typings.js';
3
+ import { Reference } from './Reference.js';
4
4
  export declare class ArrayCollection<T extends object, O extends object> {
5
5
  readonly owner: O;
6
6
  protected readonly items: Set<T>;
@@ -14,7 +14,7 @@ export declare class ArrayCollection<T extends object, O extends object> {
14
14
  getItems(): T[];
15
15
  toArray<TT extends T>(): EntityDTO<TT>[];
16
16
  toJSON(): EntityDTO<T>[];
17
- getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string): U[];
17
+ getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
18
18
  add(entity: T | Reference<T> | Iterable<T | Reference<T>>, ...entities: (T | Reference<T>)[]): void;
19
19
  /**
20
20
  * @internal