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

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 (281) hide show
  1. package/EntityManager.d.ts +96 -58
  2. package/EntityManager.js +465 -395
  3. package/MikroORM.d.ts +45 -35
  4. package/MikroORM.js +109 -160
  5. package/README.md +3 -2
  6. package/cache/CacheAdapter.js +1 -2
  7. package/cache/FileCacheAdapter.d.ts +2 -2
  8. package/cache/FileCacheAdapter.js +20 -27
  9. package/cache/GeneratedCacheAdapter.d.ts +2 -3
  10. package/cache/GeneratedCacheAdapter.js +1 -7
  11. package/cache/MemoryCacheAdapter.d.ts +1 -1
  12. package/cache/MemoryCacheAdapter.js +1 -5
  13. package/cache/NullCacheAdapter.d.ts +1 -1
  14. package/cache/NullCacheAdapter.js +1 -5
  15. package/cache/index.d.ts +4 -5
  16. package/cache/index.js +4 -21
  17. package/connections/Connection.d.ts +22 -14
  18. package/connections/Connection.js +27 -23
  19. package/connections/index.d.ts +1 -1
  20. package/connections/index.js +1 -17
  21. package/drivers/DatabaseDriver.d.ts +25 -15
  22. package/drivers/DatabaseDriver.js +77 -64
  23. package/drivers/IDatabaseDriver.d.ts +40 -16
  24. package/drivers/IDatabaseDriver.js +1 -4
  25. package/drivers/index.d.ts +2 -2
  26. package/drivers/index.js +2 -18
  27. package/entity/BaseEntity.d.ts +6 -7
  28. package/entity/BaseEntity.js +16 -23
  29. package/entity/Collection.d.ts +98 -34
  30. package/entity/Collection.js +466 -131
  31. package/entity/EntityAssigner.d.ts +3 -3
  32. package/entity/EntityAssigner.js +67 -64
  33. package/entity/EntityFactory.d.ts +10 -3
  34. package/entity/EntityFactory.js +112 -91
  35. package/entity/EntityHelper.d.ts +2 -2
  36. package/entity/EntityHelper.js +66 -53
  37. package/entity/EntityIdentifier.d.ts +1 -1
  38. package/entity/EntityIdentifier.js +1 -5
  39. package/entity/EntityLoader.d.ts +8 -7
  40. package/entity/EntityLoader.js +161 -128
  41. package/entity/EntityRepository.d.ts +8 -8
  42. package/entity/EntityRepository.js +7 -11
  43. package/entity/Reference.d.ts +10 -13
  44. package/entity/Reference.js +64 -46
  45. package/entity/WrappedEntity.d.ts +12 -17
  46. package/entity/WrappedEntity.js +22 -31
  47. package/entity/defineEntity.d.ts +568 -0
  48. package/entity/defineEntity.js +529 -0
  49. package/entity/index.d.ts +14 -13
  50. package/entity/index.js +14 -29
  51. package/entity/utils.d.ts +8 -1
  52. package/entity/utils.js +22 -13
  53. package/entity/validators.d.ts +11 -0
  54. package/entity/validators.js +65 -0
  55. package/entity/wrap.d.ts +1 -1
  56. package/entity/wrap.js +2 -6
  57. package/enums.d.ts +24 -9
  58. package/enums.js +50 -41
  59. package/errors.d.ts +11 -3
  60. package/errors.js +42 -32
  61. package/events/EventManager.d.ts +5 -4
  62. package/events/EventManager.js +26 -22
  63. package/events/EventSubscriber.d.ts +8 -5
  64. package/events/EventSubscriber.js +1 -2
  65. package/events/TransactionEventBroadcaster.d.ts +3 -3
  66. package/events/TransactionEventBroadcaster.js +1 -5
  67. package/events/index.d.ts +3 -3
  68. package/events/index.js +3 -19
  69. package/exceptions.js +18 -39
  70. package/hydration/Hydrator.d.ts +5 -5
  71. package/hydration/Hydrator.js +2 -6
  72. package/hydration/ObjectHydrator.d.ts +7 -7
  73. package/hydration/ObjectHydrator.js +58 -50
  74. package/hydration/index.d.ts +2 -2
  75. package/hydration/index.js +2 -18
  76. package/index.d.ts +21 -21
  77. package/index.js +20 -46
  78. package/logging/DefaultLogger.d.ts +2 -2
  79. package/logging/DefaultLogger.js +10 -13
  80. package/logging/Logger.d.ts +1 -1
  81. package/logging/Logger.js +1 -2
  82. package/logging/SimpleLogger.d.ts +3 -3
  83. package/logging/SimpleLogger.js +2 -6
  84. package/logging/colors.js +1 -5
  85. package/logging/index.d.ts +5 -4
  86. package/logging/index.js +5 -20
  87. package/logging/inspect.d.ts +2 -0
  88. package/logging/inspect.js +16 -0
  89. package/metadata/EntitySchema.d.ts +14 -10
  90. package/metadata/EntitySchema.js +78 -64
  91. package/metadata/MetadataDiscovery.d.ts +11 -14
  92. package/metadata/MetadataDiscovery.js +278 -317
  93. package/metadata/MetadataProvider.d.ts +13 -4
  94. package/metadata/MetadataProvider.js +47 -8
  95. package/metadata/MetadataStorage.d.ts +2 -7
  96. package/metadata/MetadataStorage.js +19 -35
  97. package/metadata/MetadataValidator.d.ts +3 -10
  98. package/metadata/MetadataValidator.js +51 -64
  99. package/metadata/discover-entities.d.ts +5 -0
  100. package/metadata/discover-entities.js +40 -0
  101. package/metadata/index.d.ts +6 -6
  102. package/metadata/index.js +6 -22
  103. package/metadata/types.d.ts +480 -0
  104. package/metadata/types.js +1 -0
  105. package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
  106. package/naming-strategy/AbstractNamingStrategy.js +11 -9
  107. package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
  108. package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
  109. package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
  110. package/naming-strategy/MongoNamingStrategy.js +2 -6
  111. package/naming-strategy/NamingStrategy.d.ts +12 -2
  112. package/naming-strategy/NamingStrategy.js +1 -2
  113. package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
  114. package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
  115. package/naming-strategy/index.d.ts +5 -5
  116. package/naming-strategy/index.js +5 -21
  117. package/not-supported.d.ts +2 -0
  118. package/not-supported.js +4 -0
  119. package/package.json +19 -20
  120. package/platforms/ExceptionConverter.d.ts +2 -2
  121. package/platforms/ExceptionConverter.js +4 -8
  122. package/platforms/Platform.d.ts +15 -22
  123. package/platforms/Platform.js +58 -88
  124. package/platforms/index.d.ts +2 -2
  125. package/platforms/index.js +2 -18
  126. package/serialization/EntitySerializer.d.ts +4 -2
  127. package/serialization/EntitySerializer.js +64 -51
  128. package/serialization/EntityTransformer.d.ts +1 -1
  129. package/serialization/EntityTransformer.js +48 -42
  130. package/serialization/SerializationContext.d.ts +2 -2
  131. package/serialization/SerializationContext.js +24 -25
  132. package/serialization/index.d.ts +3 -3
  133. package/serialization/index.js +3 -19
  134. package/types/ArrayType.d.ts +3 -3
  135. package/types/ArrayType.js +6 -11
  136. package/types/BigIntType.d.ts +12 -9
  137. package/types/BigIntType.js +6 -6
  138. package/types/BlobType.d.ts +3 -4
  139. package/types/BlobType.js +2 -11
  140. package/types/BooleanType.d.ts +5 -4
  141. package/types/BooleanType.js +5 -6
  142. package/types/CharacterType.d.ts +3 -3
  143. package/types/CharacterType.js +2 -6
  144. package/types/DateTimeType.d.ts +3 -3
  145. package/types/DateTimeType.js +2 -6
  146. package/types/DateType.d.ts +3 -3
  147. package/types/DateType.js +2 -6
  148. package/types/DecimalType.d.ts +9 -7
  149. package/types/DecimalType.js +5 -8
  150. package/types/DoubleType.d.ts +3 -3
  151. package/types/DoubleType.js +4 -7
  152. package/types/EnumArrayType.d.ts +4 -4
  153. package/types/EnumArrayType.js +4 -10
  154. package/types/EnumType.d.ts +3 -3
  155. package/types/EnumType.js +2 -6
  156. package/types/FloatType.d.ts +3 -3
  157. package/types/FloatType.js +2 -6
  158. package/types/IntegerType.d.ts +3 -3
  159. package/types/IntegerType.js +2 -6
  160. package/types/IntervalType.d.ts +3 -3
  161. package/types/IntervalType.js +2 -6
  162. package/types/JsonType.d.ts +4 -4
  163. package/types/JsonType.js +9 -8
  164. package/types/MediumIntType.d.ts +3 -3
  165. package/types/MediumIntType.js +2 -6
  166. package/types/SmallIntType.d.ts +3 -3
  167. package/types/SmallIntType.js +2 -6
  168. package/types/StringType.d.ts +3 -3
  169. package/types/StringType.js +2 -6
  170. package/types/TextType.d.ts +3 -3
  171. package/types/TextType.js +2 -6
  172. package/types/TimeType.d.ts +3 -3
  173. package/types/TimeType.js +4 -8
  174. package/types/TinyIntType.d.ts +3 -3
  175. package/types/TinyIntType.js +3 -6
  176. package/types/Type.d.ts +4 -6
  177. package/types/Type.js +6 -10
  178. package/types/Uint8ArrayType.d.ts +3 -4
  179. package/types/Uint8ArrayType.js +3 -12
  180. package/types/UnknownType.d.ts +3 -3
  181. package/types/UnknownType.js +2 -6
  182. package/types/UuidType.d.ts +3 -3
  183. package/types/UuidType.js +2 -6
  184. package/types/index.d.ts +25 -25
  185. package/types/index.js +52 -79
  186. package/typings.d.ts +134 -93
  187. package/typings.js +67 -65
  188. package/unit-of-work/ChangeSet.d.ts +1 -4
  189. package/unit-of-work/ChangeSet.js +13 -17
  190. package/unit-of-work/ChangeSetComputer.d.ts +8 -9
  191. package/unit-of-work/ChangeSetComputer.js +36 -38
  192. package/unit-of-work/ChangeSetPersister.d.ts +11 -9
  193. package/unit-of-work/ChangeSetPersister.js +100 -65
  194. package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
  195. package/unit-of-work/CommitOrderCalculator.js +6 -10
  196. package/unit-of-work/IdentityMap.d.ts +1 -1
  197. package/unit-of-work/IdentityMap.js +1 -5
  198. package/unit-of-work/UnitOfWork.d.ts +16 -8
  199. package/unit-of-work/UnitOfWork.js +266 -209
  200. package/unit-of-work/index.d.ts +6 -6
  201. package/unit-of-work/index.js +6 -22
  202. package/utils/AbstractSchemaGenerator.d.ts +11 -11
  203. package/utils/AbstractSchemaGenerator.js +21 -20
  204. package/utils/Configuration.d.ts +774 -224
  205. package/utils/Configuration.js +166 -216
  206. package/utils/ConfigurationLoader.d.ts +1 -53
  207. package/utils/ConfigurationLoader.js +1 -367
  208. package/utils/Cursor.d.ts +6 -9
  209. package/utils/Cursor.js +25 -25
  210. package/utils/DataloaderUtils.d.ts +18 -8
  211. package/utils/DataloaderUtils.js +63 -21
  212. package/utils/EntityComparator.d.ts +9 -5
  213. package/utils/EntityComparator.js +155 -108
  214. package/utils/NullHighlighter.d.ts +1 -1
  215. package/utils/NullHighlighter.js +1 -5
  216. package/utils/QueryHelper.d.ts +12 -4
  217. package/utils/QueryHelper.js +110 -53
  218. package/utils/RawQueryFragment.d.ts +37 -14
  219. package/utils/RawQueryFragment.js +50 -33
  220. package/utils/RequestContext.d.ts +2 -2
  221. package/utils/RequestContext.js +3 -7
  222. package/utils/TransactionContext.d.ts +1 -1
  223. package/utils/TransactionContext.js +4 -8
  224. package/utils/TransactionManager.d.ts +65 -0
  225. package/utils/TransactionManager.js +223 -0
  226. package/utils/Utils.d.ts +16 -100
  227. package/utils/Utils.js +114 -332
  228. package/utils/clone.js +7 -11
  229. package/utils/env-vars.d.ts +3 -0
  230. package/utils/env-vars.js +87 -0
  231. package/utils/fs-utils.d.ts +12 -0
  232. package/utils/fs-utils.js +97 -0
  233. package/utils/index.d.ts +14 -13
  234. package/utils/index.js +14 -29
  235. package/utils/upsert-utils.d.ts +8 -3
  236. package/utils/upsert-utils.js +57 -10
  237. package/decorators/Check.d.ts +0 -3
  238. package/decorators/Check.js +0 -16
  239. package/decorators/CreateRequestContext.d.ts +0 -3
  240. package/decorators/CreateRequestContext.js +0 -33
  241. package/decorators/Embeddable.d.ts +0 -8
  242. package/decorators/Embeddable.js +0 -14
  243. package/decorators/Embedded.d.ts +0 -18
  244. package/decorators/Embedded.js +0 -20
  245. package/decorators/Entity.d.ts +0 -18
  246. package/decorators/Entity.js +0 -16
  247. package/decorators/Enum.d.ts +0 -9
  248. package/decorators/Enum.js +0 -19
  249. package/decorators/Filter.d.ts +0 -2
  250. package/decorators/Filter.js +0 -11
  251. package/decorators/Formula.d.ts +0 -5
  252. package/decorators/Formula.js +0 -18
  253. package/decorators/Indexed.d.ts +0 -17
  254. package/decorators/Indexed.js +0 -24
  255. package/decorators/ManyToMany.d.ts +0 -40
  256. package/decorators/ManyToMany.js +0 -16
  257. package/decorators/ManyToOne.d.ts +0 -30
  258. package/decorators/ManyToOne.js +0 -16
  259. package/decorators/OneToMany.d.ts +0 -28
  260. package/decorators/OneToMany.js +0 -20
  261. package/decorators/OneToOne.d.ts +0 -24
  262. package/decorators/OneToOne.js +0 -10
  263. package/decorators/PrimaryKey.d.ts +0 -9
  264. package/decorators/PrimaryKey.js +0 -23
  265. package/decorators/Property.d.ts +0 -250
  266. package/decorators/Property.js +0 -34
  267. package/decorators/Transactional.d.ts +0 -13
  268. package/decorators/Transactional.js +0 -31
  269. package/decorators/hooks.d.ts +0 -16
  270. package/decorators/hooks.js +0 -59
  271. package/decorators/index.d.ts +0 -17
  272. package/decorators/index.js +0 -36
  273. package/entity/ArrayCollection.d.ts +0 -116
  274. package/entity/ArrayCollection.js +0 -399
  275. package/entity/EntityValidator.d.ts +0 -19
  276. package/entity/EntityValidator.js +0 -154
  277. package/index.mjs +0 -199
  278. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  279. package/metadata/ReflectMetadataProvider.js +0 -48
  280. package/utils/resolveContextProvider.d.ts +0 -10
  281. package/utils/resolveContextProvider.js +0 -31
@@ -1,18 +1,19 @@
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
+ import { MikroORM } from '../MikroORM.js';
13
+ export class DatabaseDriver {
13
14
  config;
14
15
  dependencies;
15
- [IDatabaseDriver_1.EntityManagerType];
16
+ [EntityManagerType];
16
17
  connection;
17
18
  replicas = [];
18
19
  platform;
@@ -28,14 +29,14 @@ class DatabaseDriver {
28
29
  throw new Error(`Batch updates are not supported by ${this.constructor.name} driver`);
29
30
  }
30
31
  createEntityManager(useContext) {
31
- const EntityManagerClass = this.config.get('entityManager', EntityManager_1.EntityManager);
32
+ const EntityManagerClass = this.config.get('entityManager', EntityManager);
32
33
  return new EntityManagerClass(this.config, this, this.metadata, useContext);
33
34
  }
34
- /* istanbul ignore next */
35
+ /* v8 ignore next */
35
36
  async findVirtual(entityName, where, options) {
36
37
  throw new Error(`Virtual entities are not supported by ${this.constructor.name} driver.`);
37
38
  }
38
- /* istanbul ignore next */
39
+ /* v8 ignore next */
39
40
  async countVirtual(entityName, where, options) {
40
41
  throw new Error(`Counting virtual entities is not supported by ${this.constructor.name} driver.`);
41
42
  }
@@ -47,17 +48,18 @@ class DatabaseDriver {
47
48
  }
48
49
  async syncCollections(collections, options) {
49
50
  for (const coll of collections) {
51
+ /* v8 ignore else */
50
52
  if (!coll.property.owner) {
51
53
  if (coll.getSnapshot() === undefined) {
52
- throw errors_1.ValidationError.cannotModifyInverseCollection(coll.owner, coll.property);
54
+ throw ValidationError.cannotModifyInverseCollection(coll.owner, coll.property);
53
55
  }
54
56
  continue;
55
57
  }
56
- /* istanbul ignore next */
58
+ /* v8 ignore next */
57
59
  {
58
60
  const pk = coll.property.targetMeta.primaryKeys[0];
59
61
  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);
62
+ await this.nativeUpdate(coll.owner.constructor.name, helper(coll.owner).getPrimaryKey(), data, options);
61
63
  }
62
64
  }
63
65
  }
@@ -67,21 +69,21 @@ class DatabaseDriver {
67
69
  }
68
70
  return this.comparator.mapResult(meta.className, result);
69
71
  }
70
- async connect() {
71
- await this.connection.connect();
72
+ async connect(options) {
73
+ await this.connection.connect(options);
72
74
  await Promise.all(this.replicas.map(replica => replica.connect()));
73
75
  return this.connection;
74
76
  }
75
- async reconnect() {
77
+ async reconnect(options) {
76
78
  await this.close(true);
77
- await this.connect();
79
+ await this.connect(options);
78
80
  return this.connection;
79
81
  }
80
82
  getConnection(type = 'write') {
81
83
  if (type === 'write' || this.replicas.length === 0) {
82
84
  return this.connection;
83
85
  }
84
- const rand = utils_1.Utils.randomInt(0, this.replicas.length - 1);
86
+ const rand = Utils.randomInt(0, this.replicas.length - 1);
85
87
  return this.replicas[rand];
86
88
  }
87
89
  async close(force) {
@@ -93,7 +95,7 @@ class DatabaseDriver {
93
95
  }
94
96
  setMetadata(metadata) {
95
97
  this.metadata = metadata;
96
- this.comparator = new utils_1.EntityComparator(this.metadata, this.platform);
98
+ this.comparator = new EntityComparator(this.metadata, this.platform);
97
99
  this.connection.setMetadata(metadata);
98
100
  this.connection.setPlatform(this.platform);
99
101
  this.replicas.forEach(replica => {
@@ -107,11 +109,20 @@ class DatabaseDriver {
107
109
  getDependencies() {
108
110
  return this.dependencies;
109
111
  }
112
+ isPopulated(meta, prop, hint, name) {
113
+ if (hint.field === prop.name || hint.field === name || hint.all) {
114
+ return true;
115
+ }
116
+ if (prop.embedded && hint.children && meta.properties[prop.embedded[0]].name === hint.field) {
117
+ return hint.children.some(c => this.isPopulated(meta, prop, c, prop.embedded[1]));
118
+ }
119
+ return false;
120
+ }
110
121
  processCursorOptions(meta, options, orderBy) {
111
122
  const { first, last, before, after, overfetch } = options;
112
123
  const limit = first ?? last;
113
124
  const isLast = !first && !!last;
114
- const definition = utils_1.Cursor.getDefinition(meta, orderBy);
125
+ const definition = Cursor.getDefinition(meta, orderBy);
115
126
  const $and = [];
116
127
  // allow POJO as well, we care only about the correct key being present
117
128
  const isCursor = (val, key) => {
@@ -119,15 +130,15 @@ class DatabaseDriver {
119
130
  };
120
131
  const createCursor = (val, key, inverse = false) => {
121
132
  let def = isCursor(val, key) ? val[key] : val;
122
- if (utils_1.Utils.isPlainObject(def)) {
123
- def = utils_1.Cursor.for(meta, def, orderBy);
133
+ if (Utils.isPlainObject(def)) {
134
+ def = Cursor.for(meta, def, orderBy);
124
135
  }
125
- /* istanbul ignore next */
126
- const offsets = def ? utils_1.Cursor.decode(def) : [];
136
+ /* v8 ignore next */
137
+ const offsets = def ? Cursor.decode(def) : [];
127
138
  if (definition.length === offsets.length) {
128
139
  return this.createCursorCondition(definition, offsets, inverse, meta);
129
140
  }
130
- /* istanbul ignore next */
141
+ /* v8 ignore next */
131
142
  return {};
132
143
  };
133
144
  if (after) {
@@ -140,15 +151,15 @@ class DatabaseDriver {
140
151
  options.limit = limit + (overfetch ? 1 : 0);
141
152
  }
142
153
  const createOrderBy = (prop, direction) => {
143
- if (utils_1.Utils.isPlainObject(direction)) {
144
- const value = utils_1.Utils.keys(direction).reduce((o, key) => {
154
+ if (Utils.isPlainObject(direction)) {
155
+ const value = Utils.keys(direction).reduce((o, key) => {
145
156
  Object.assign(o, createOrderBy(key, direction[key]));
146
157
  return o;
147
158
  }, {});
148
159
  return ({ [prop]: value });
149
160
  }
150
- const desc = direction === enums_1.QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
151
- const dir = utils_1.Utils.xor(desc, isLast) ? 'desc' : 'asc';
161
+ const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
162
+ const dir = Utils.xor(desc, isLast) ? 'desc' : 'asc';
152
163
  return ({ [prop]: dir });
153
164
  };
154
165
  return {
@@ -156,24 +167,23 @@ class DatabaseDriver {
156
167
  where: ($and.length > 1 ? { $and } : { ...$and[0] }),
157
168
  };
158
169
  }
159
- /* istanbul ignore next */
160
170
  createCursorCondition(definition, offsets, inverse, meta) {
161
171
  const createCondition = (prop, direction, offset, eq = false) => {
162
172
  if (offset === null) {
163
- throw errors_1.CursorError.missingValue(meta.className, prop);
173
+ throw CursorError.missingValue(meta.className, prop);
164
174
  }
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}`);
175
+ if (Utils.isPlainObject(direction)) {
176
+ const value = Utils.keys(direction).reduce((o, key) => {
177
+ if (Utils.isEmpty(offset[key])) {
178
+ throw CursorError.missingValue(meta.className, `${prop}.${key}`);
169
179
  }
170
180
  Object.assign(o, createCondition(key, direction[key], offset[key], eq));
171
181
  return o;
172
182
  }, {});
173
183
  return ({ [prop]: value });
174
184
  }
175
- const desc = direction === enums_1.QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
176
- const operator = utils_1.Utils.xor(desc, inverse) ? '$lt' : '$gt';
185
+ const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
186
+ const operator = Utils.xor(desc, inverse) ? '$lt' : '$gt';
177
187
  return { [prop]: { [operator + (eq ? 'e' : '')]: offset } };
178
188
  };
179
189
  const [order, ...otherOrders] = definition;
@@ -222,7 +232,7 @@ class DatabaseDriver {
222
232
  return;
223
233
  }
224
234
  if (prop.joinColumns && Array.isArray(data[k])) {
225
- const copy = utils_1.Utils.flatten(data[k]);
235
+ const copy = Utils.flatten(data[k]);
226
236
  delete data[k];
227
237
  prop.joinColumns.forEach((joinColumn, idx) => data[joinColumn] = copy[idx]);
228
238
  return;
@@ -232,49 +242,49 @@ class DatabaseDriver {
232
242
  prop.ownColumns.forEach(joinColumn => data[joinColumn] = null);
233
243
  return;
234
244
  }
235
- if (prop.customType && convertCustomTypes && !(prop.customType instanceof JsonType_1.JsonType && object) && !(0, utils_1.isRaw)(data[k])) {
245
+ if (prop.customType && convertCustomTypes && !(prop.customType instanceof JsonType && object) && !isRaw(data[k])) {
236
246
  data[k] = prop.customType.convertToDatabaseValue(data[k], this.platform, { fromQuery: true, key: k, mode: 'query-data' });
237
247
  }
238
- if (prop.hasConvertToDatabaseValueSQL && !prop.object && !(0, utils_1.isRaw)(data[k])) {
248
+ if (prop.hasConvertToDatabaseValueSQL && !prop.object && !isRaw(data[k])) {
239
249
  const quoted = this.platform.quoteValue(data[k]);
240
250
  const sql = prop.customType.convertToDatabaseValueSQL(quoted, this.platform);
241
- data[k] = (0, utils_1.raw)(sql.replace(/\?/g, '\\?'));
251
+ data[k] = raw(sql.replace(/\?/g, '\\?'));
242
252
  }
243
253
  if (prop.fieldNames) {
244
- utils_1.Utils.renameKey(data, k, prop.fieldNames[0]);
254
+ Utils.renameKey(data, k, prop.fieldNames[0]);
245
255
  }
246
256
  });
247
257
  return data;
248
258
  }
249
259
  inlineEmbeddables(meta, data, where) {
250
- /* istanbul ignore next */
260
+ /* v8 ignore next */
251
261
  if (data == null) {
252
262
  return;
253
263
  }
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));
264
+ Utils.keys(data).forEach(k => {
265
+ if (Utils.isOperator(k)) {
266
+ Utils.asArray(data[k]).forEach(payload => this.inlineEmbeddables(meta, payload, where));
257
267
  }
258
268
  });
259
269
  meta.props.forEach(prop => {
260
- if (prop.kind === enums_1.ReferenceKind.EMBEDDED && prop.object && !where && utils_1.Utils.isObject(data[prop.name])) {
270
+ if (prop.kind === ReferenceKind.EMBEDDED && prop.object && !where && Utils.isObject(data[prop.name])) {
261
271
  return;
262
272
  }
263
- if (prop.kind === enums_1.ReferenceKind.EMBEDDED && utils_1.Utils.isObject(data[prop.name])) {
273
+ if (prop.kind === ReferenceKind.EMBEDDED && Utils.isObject(data[prop.name])) {
264
274
  const props = prop.embeddedProps;
265
275
  let unknownProp = false;
266
276
  Object.keys(data[prop.name]).forEach(kk => {
267
277
  // 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));
278
+ const operator = Object.keys(data[prop.name]).some(f => Utils.isOperator(f) && !['$exists', '$ne', '$eq'].includes(f));
269
279
  if (operator) {
270
- throw errors_1.ValidationError.cannotUseOperatorsInsideEmbeddables(meta.className, prop.name, data);
280
+ throw ValidationError.cannotUseOperatorsInsideEmbeddables(meta.className, prop.name, data);
271
281
  }
272
282
  if (prop.object && where) {
273
283
  const inline = (payload, sub, path) => {
274
- if (sub.kind === enums_1.ReferenceKind.EMBEDDED && utils_1.Utils.isObject(payload[sub.embedded[1]])) {
284
+ if (sub.kind === ReferenceKind.EMBEDDED && Utils.isObject(payload[sub.embedded[1]])) {
275
285
  return Object.keys(payload[sub.embedded[1]]).forEach(kkk => {
276
286
  if (!sub.embeddedProps[kkk]) {
277
- throw errors_1.ValidationError.invalidEmbeddableQuery(meta.className, kkk, sub.type);
287
+ throw ValidationError.invalidEmbeddableQuery(meta.className, kkk, sub.type);
278
288
  }
279
289
  inline(payload[sub.embedded[1]], sub.embeddedProps[kkk], [...path, sub.embedded[1]]);
280
290
  });
@@ -284,7 +294,7 @@ class DatabaseDriver {
284
294
  const parentPropName = kk.substring(0, kk.indexOf('.'));
285
295
  // we might be using some native JSON operator, e.g. with mongodb's `$geoWithin` or `$exists`
286
296
  if (props[kk]) {
287
- /* istanbul ignore next */
297
+ /* v8 ignore next */
288
298
  inline(data[prop.name], props[kk] || props[parentPropName], [prop.name]);
289
299
  }
290
300
  else if (props[parentPropName]) {
@@ -298,7 +308,7 @@ class DatabaseDriver {
298
308
  data[props[kk].name] = data[prop.name][props[kk].embedded[1]];
299
309
  }
300
310
  else {
301
- throw errors_1.ValidationError.invalidEmbeddableQuery(meta.className, kk, prop.type);
311
+ throw ValidationError.invalidEmbeddableQuery(meta.className, kk, prop.type);
302
312
  }
303
313
  });
304
314
  if (!unknownProp) {
@@ -309,14 +319,14 @@ class DatabaseDriver {
309
319
  }
310
320
  getPrimaryKeyFields(entityName) {
311
321
  const meta = this.metadata.find(entityName);
312
- return meta ? utils_1.Utils.flatten(meta.getPrimaryProps().map(pk => pk.fieldNames)) : [this.config.getNamingStrategy().referenceColumnName()];
322
+ return meta ? Utils.flatten(meta.getPrimaryProps().map(pk => pk.fieldNames)) : [this.config.getNamingStrategy().referenceColumnName()];
313
323
  }
314
324
  createReplicas(cb) {
315
325
  const replicas = this.config.get('replicas', []);
316
326
  const ret = [];
317
327
  const props = ['dbName', 'clientUrl', 'host', 'port', 'user', 'password', 'multipleStatements', 'pool', 'name', 'driverOptions'];
318
328
  for (const conf of replicas) {
319
- const replicaConfig = utils_1.Utils.copy(conf);
329
+ const replicaConfig = Utils.copy(conf);
320
330
  for (const prop of props) {
321
331
  if (conf[prop]) {
322
332
  continue;
@@ -341,7 +351,7 @@ class DatabaseDriver {
341
351
  * @inheritDoc
342
352
  */
343
353
  convertException(exception) {
344
- if (exception instanceof exceptions_1.DriverException) {
354
+ if (exception instanceof DriverException) {
345
355
  return exception;
346
356
  }
347
357
  return this.platform.getExceptionConverter().convertException(exception);
@@ -375,5 +385,8 @@ class DatabaseDriver {
375
385
  const schemaName = meta?.schema === '*' ? this.config.getSchema() : meta?.schema;
376
386
  return options?.schema ?? options?.parentSchema ?? schemaName ?? this.config.getSchema();
377
387
  }
388
+ /** @internal */
389
+ getORMClass() {
390
+ return MikroORM;
391
+ }
378
392
  }
379
- exports.DatabaseDriver = DatabaseDriver;
@@ -1,22 +1,26 @@
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, EntityName } 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];
17
- connect(): Promise<C>;
16
+ createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
17
+ connect(options?: {
18
+ skipOnConnect?: boolean;
19
+ }): Promise<C>;
18
20
  close(force?: boolean): Promise<void>;
19
- reconnect(): Promise<C>;
21
+ reconnect(options?: {
22
+ skipOnConnect?: boolean;
23
+ }): Promise<C>;
20
24
  getConnection(type?: ConnectionType): C;
21
25
  /**
22
26
  * Finds selection of entities
@@ -27,6 +31,7 @@ export interface IDatabaseDriver<C extends Connection = Connection> {
27
31
  */
28
32
  findOne<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
29
33
  findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
34
+ stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T>): AsyncIterableIterator<T>;
30
35
  nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
31
36
  nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>;
32
37
  nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
@@ -68,6 +73,18 @@ export type OrderDefinition<T> = (QueryOrderMap<T> & {
68
73
  export interface FindAllOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends FindOptions<T, P, F, E> {
69
74
  where?: FilterQuery<T>;
70
75
  }
76
+ export interface StreamOptions<Entity, Populate extends string = never, Fields extends string = '*', Exclude extends string = never> extends Omit<FindAllOptions<Entity, Populate, Fields, Exclude>, 'cache' | 'before' | 'after' | 'first' | 'last' | 'overfetch' | 'strategy'> {
77
+ /**
78
+ * When populating to-many relations, the ORM streams fully merged entities instead of yielding every row.
79
+ * You can opt out of this behavior by specifying `mergeResults: false`. This will yield every row from
80
+ * the SQL result, but still mapped to entities, meaning that to-many collections will contain at most
81
+ * a single item, and you will get duplicate root entities when they have multiple items in the populated
82
+ * collection.
83
+ *
84
+ * @default true
85
+ */
86
+ mergeResults?: boolean;
87
+ }
71
88
  export type FilterOptions = Dictionary<boolean | Dictionary> | string[] | boolean;
72
89
  export interface LoadHint<Entity, Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never> {
73
90
  populate?: Populate<Entity, Hint>;
@@ -146,10 +163,13 @@ export interface FindOptions<Entity, Hint extends string = never, Fields extends
146
163
  hintComments?: string | string[];
147
164
  loggerContext?: LogContext;
148
165
  logging?: LoggingOptions;
166
+ /** @internal used to apply filters to the auto-joined relations */
167
+ em?: EntityManager;
149
168
  }
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'> {
169
+ 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'> {
170
+ includeCount?: I;
151
171
  }
152
- 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'> {
172
+ export interface FindOneOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'lockMode'> {
153
173
  lockMode?: LockMode;
154
174
  lockVersion?: number | Date;
155
175
  }
@@ -163,6 +183,7 @@ export interface NativeInsertUpdateOptions<T> {
163
183
  schema?: string;
164
184
  /** `nativeUpdate()` only option */
165
185
  upsert?: boolean;
186
+ loggerContext?: LogContext;
166
187
  }
167
188
  export interface NativeInsertUpdateManyOptions<T> extends NativeInsertUpdateOptions<T> {
168
189
  processCollections?: boolean;
@@ -197,6 +218,8 @@ export interface CountOptions<T extends object, P extends string = never> {
197
218
  hintComments?: string | string[];
198
219
  loggerContext?: LogContext;
199
220
  logging?: LoggingOptions;
221
+ /** @internal used to apply filters to the auto-joined relations */
222
+ em?: EntityManager;
200
223
  }
201
224
  export interface UpdateOptions<T> {
202
225
  filters?: FilterOptions;
@@ -218,6 +241,7 @@ export interface LockOptions extends DriverMethodOptions {
218
241
  export interface DriverMethodOptions {
219
242
  ctx?: Transaction;
220
243
  schema?: string;
244
+ loggerContext?: LogContext;
221
245
  }
222
246
  export interface GetReferenceOptions {
223
247
  wrapped?: boolean;
@@ -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,12 +1,11 @@
1
- import { type Ref } from './Reference';
2
- import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected } from '../typings';
3
- import { type AssignOptions } from './EntityAssigner';
4
- import type { EntityLoaderOptions } from './EntityLoader';
5
- import { type SerializeOptions } from '../serialization/EntitySerializer';
6
- import type { FindOneOptions } from '../drivers/IDatabaseDriver';
1
+ import { type Ref } from './Reference.js';
2
+ import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
3
+ import { type AssignOptions } from './EntityAssigner.js';
4
+ import type { EntityLoaderOptions } from './EntityLoader.js';
5
+ import { type SerializeOptions } from '../serialization/EntitySerializer.js';
6
+ import type { FindOneOptions } from '../drivers/IDatabaseDriver.js';
7
7
  export declare abstract class BaseEntity {
8
8
  isInitialized(): boolean;
9
- isTouched(): boolean;
10
9
  populated(populated?: boolean): void;
11
10
  populate<Entity extends this = this, Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
12
11
  toReference<Entity extends this = this>(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
@@ -1,47 +1,40 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseEntity = void 0;
4
- const Reference_1 = require("./Reference");
5
- const EntityAssigner_1 = require("./EntityAssigner");
6
- const EntitySerializer_1 = require("../serialization/EntitySerializer");
7
- const wrap_1 = require("./wrap");
8
- class BaseEntity {
1
+ import { Reference } from './Reference.js';
2
+ import { EntityAssigner } from './EntityAssigner.js';
3
+ import { EntitySerializer } from '../serialization/EntitySerializer.js';
4
+ import { helper } from './wrap.js';
5
+ export class BaseEntity {
9
6
  isInitialized() {
10
- return (0, wrap_1.helper)(this).__initialized;
11
- }
12
- isTouched() {
13
- return (0, wrap_1.helper)(this).__touched;
7
+ return helper(this).__initialized;
14
8
  }
15
9
  populated(populated = true) {
16
- (0, wrap_1.helper)(this).populated(populated);
10
+ helper(this).populated(populated);
17
11
  }
18
12
  async populate(populate, options = {}) {
19
- return (0, wrap_1.helper)(this).populate(populate, options);
13
+ return helper(this).populate(populate, options);
20
14
  }
21
15
  toReference() {
22
- return Reference_1.Reference.create(this);
16
+ return Reference.create(this);
23
17
  }
24
18
  toObject(ignoreFields) {
25
- return (0, wrap_1.helper)(this).toObject(ignoreFields);
19
+ return helper(this).toObject(ignoreFields);
26
20
  }
27
21
  toPOJO() {
28
- return (0, wrap_1.helper)(this).toPOJO();
22
+ return helper(this).toPOJO();
29
23
  }
30
24
  serialize(options) {
31
- return EntitySerializer_1.EntitySerializer.serialize(this, options);
25
+ return EntitySerializer.serialize(this, options);
32
26
  }
33
27
  assign(data, options = {}) {
34
- return EntityAssigner_1.EntityAssigner.assign(this, data, options);
28
+ return EntityAssigner.assign(this, data, options);
35
29
  }
36
30
  init(options) {
37
- return (0, wrap_1.helper)(this).init(options);
31
+ return helper(this).init(options);
38
32
  }
39
33
  getSchema() {
40
- return (0, wrap_1.helper)(this).getSchema();
34
+ return helper(this).getSchema();
41
35
  }
42
36
  setSchema(schema) {
43
- (0, wrap_1.helper)(this).setSchema(schema);
37
+ helper(this).setSchema(schema);
44
38
  }
45
39
  }
46
- exports.BaseEntity = BaseEntity;
47
40
  Object.defineProperty(BaseEntity.prototype, '__baseEntity', { value: true, writable: false, enumerable: false });