@mikro-orm/core 7.0.0-dev.0 → 7.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/EntityManager.d.ts +18 -13
  2. package/EntityManager.js +202 -202
  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 +1 -1
  21. package/decorators/Check.js +5 -8
  22. package/decorators/CreateRequestContext.d.ts +1 -1
  23. package/decorators/CreateRequestContext.js +9 -13
  24. package/decorators/Embeddable.d.ts +1 -1
  25. package/decorators/Embeddable.js +3 -6
  26. package/decorators/Embedded.d.ts +1 -1
  27. package/decorators/Embedded.js +10 -12
  28. package/decorators/Entity.d.ts +2 -2
  29. package/decorators/Entity.js +5 -8
  30. package/decorators/Enum.d.ts +2 -2
  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 -2
  35. package/decorators/Formula.js +7 -10
  36. package/decorators/Indexed.d.ts +2 -2
  37. package/decorators/Indexed.js +6 -10
  38. package/decorators/ManyToMany.d.ts +3 -3
  39. package/decorators/ManyToMany.js +10 -12
  40. package/decorators/ManyToOne.d.ts +3 -3
  41. package/decorators/ManyToOne.js +10 -12
  42. package/decorators/OneToMany.d.ts +3 -3
  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 +2 -2
  47. package/decorators/PrimaryKey.js +10 -13
  48. package/decorators/Property.d.ts +5 -5
  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 +12 -12
  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 +2 -2
  62. package/entity/ArrayCollection.js +29 -33
  63. package/entity/BaseEntity.d.ts +6 -6
  64. package/entity/BaseEntity.js +17 -21
  65. package/entity/Collection.d.ts +6 -6
  66. package/entity/Collection.js +40 -44
  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 +58 -62
  71. package/entity/EntityHelper.d.ts +2 -2
  72. package/entity/EntityHelper.js +41 -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 +92 -96
  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 +2 -2
  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 +5 -4
  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 +25 -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 +12 -4
  122. package/metadata/EntitySchema.js +41 -45
  123. package/metadata/MetadataDiscovery.d.ts +7 -7
  124. package/metadata/MetadataDiscovery.js +174 -177
  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 +49 -53
  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 +5 -14
  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 +3 -3
  165. package/types/BigIntType.js +3 -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 +22 -20
  215. package/typings.js +34 -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 +44 -47
  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 +171 -172
  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 +7 -11
  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 +3 -3
  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 +48 -52
  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 +16 -24
  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 +89 -93
  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
package/utils/Utils.js CHANGED
@@ -1,27 +1,15 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Utils = exports.ObjectBindingPattern = void 0;
7
- exports.compareObjects = compareObjects;
8
- exports.compareArrays = compareArrays;
9
- exports.compareBooleans = compareBooleans;
10
- exports.compareBuffers = compareBuffers;
11
- exports.equals = equals;
12
- exports.parseJsonSafe = parseJsonSafe;
13
- const node_module_1 = require("node:module");
14
- const globby_1 = __importDefault(require("globby"));
15
- const node_path_1 = require("node:path");
16
- const node_os_1 = require("node:os");
17
- const node_url_1 = require("node:url");
18
- const fs_extra_1 = require("fs-extra");
19
- const node_crypto_1 = require("node:crypto");
20
- const esprima_1 = require("esprima");
21
- const clone_1 = require("./clone");
22
- const enums_1 = require("../enums");
23
- const wrap_1 = require("../entity/wrap");
24
- exports.ObjectBindingPattern = Symbol('ObjectBindingPattern');
1
+ import { createRequire } from 'node:module';
2
+ import globby from 'globby';
3
+ import { extname, isAbsolute, join, normalize, relative, resolve } from 'node:path';
4
+ import { platform } from 'node:os';
5
+ import { fileURLToPath, pathToFileURL } from 'node:url';
6
+ import { existsSync, mkdirSync, readFileSync } from 'node:fs';
7
+ import { createHash } from 'node:crypto';
8
+ import { tokenize } from 'esprima';
9
+ import { clone } from './clone.js';
10
+ import { ARRAY_OPERATORS, JSON_KEY_OPERATORS, GroupOperator, PlainObject, QueryOperator, ReferenceKind } from '../enums.js';
11
+ import { helper } from '../entity/wrap.js';
12
+ export const ObjectBindingPattern = Symbol('ObjectBindingPattern');
25
13
  function compareConstructors(a, b) {
26
14
  if (a.constructor === b.constructor) {
27
15
  return true;
@@ -34,10 +22,7 @@ function compareConstructors(a, b) {
34
22
  }
35
23
  return false;
36
24
  }
37
- function isRawSql(value) {
38
- return typeof value === 'object' && !!value && '__raw' in value;
39
- }
40
- function compareObjects(a, b) {
25
+ export function compareObjects(a, b) {
41
26
  if (a === b || (a == null && b == null)) {
42
27
  return true;
43
28
  }
@@ -56,6 +41,7 @@ function compareObjects(a, b) {
56
41
  }
57
42
  return timeA === timeB;
58
43
  }
44
+ /* v8 ignore next 9 */
59
45
  if ((typeof a === 'function' && typeof b === 'function') ||
60
46
  (typeof a === 'object' && a.client && ['Ref', 'Raw'].includes(a.constructor.name) && typeof b === 'object' && b.client && ['Ref', 'Raw'].includes(b.constructor.name)) || // knex qb
61
47
  (a instanceof RegExp && b instanceof RegExp) ||
@@ -82,7 +68,7 @@ function compareObjects(a, b) {
82
68
  }
83
69
  return true;
84
70
  }
85
- function compareArrays(a, b) {
71
+ export function compareArrays(a, b) {
86
72
  const length = a.length;
87
73
  if (length !== b.length) {
88
74
  return false;
@@ -95,12 +81,12 @@ function compareArrays(a, b) {
95
81
  }
96
82
  return true;
97
83
  }
98
- function compareBooleans(a, b) {
84
+ export function compareBooleans(a, b) {
99
85
  a = typeof a === 'number' ? Boolean(a) : a;
100
86
  b = typeof b === 'number' ? Boolean(b) : b;
101
87
  return a === b;
102
88
  }
103
- function compareBuffers(a, b) {
89
+ export function compareBuffers(a, b) {
104
90
  const length = a.length;
105
91
  if (length !== b.length) {
106
92
  return false;
@@ -115,7 +101,7 @@ function compareBuffers(a, b) {
115
101
  /**
116
102
  * Checks if arguments are deeply (but not strictly) equal.
117
103
  */
118
- function equals(a, b) {
104
+ export function equals(a, b) {
119
105
  if (a === b) {
120
106
  return true;
121
107
  }
@@ -131,8 +117,9 @@ function equals(a, b) {
131
117
  return Number.isNaN(a) && Number.isNaN(b);
132
118
  }
133
119
  const equalsFn = equals;
134
- function parseJsonSafe(value) {
120
+ export function parseJsonSafe(value) {
135
121
  if (typeof value === 'string') {
122
+ /* v8 ignore next 6 */
136
123
  try {
137
124
  return JSON.parse(value);
138
125
  }
@@ -143,9 +130,9 @@ function parseJsonSafe(value) {
143
130
  }
144
131
  return value;
145
132
  }
146
- class Utils {
133
+ export class Utils {
147
134
  static PK_SEPARATOR = '~~~';
148
- /* istanbul ignore next */
135
+ /* v8 ignore next */
149
136
  static dynamicImportProvider = (id) => import(id);
150
137
  /**
151
138
  * Checks if the argument is not undefined
@@ -220,7 +207,6 @@ class Utils {
220
207
  static getObjectKeysSize(object) {
221
208
  let size = 0;
222
209
  for (const key in object) {
223
- /* istanbul ignore else */
224
210
  if (Object.hasOwn(object, key)) {
225
211
  size++;
226
212
  }
@@ -233,7 +219,6 @@ class Utils {
233
219
  */
234
220
  static hasObjectKeys(object) {
235
221
  for (const key in object) {
236
- /* istanbul ignore else */
237
222
  if (Object.hasOwn(object, key)) {
238
223
  return true;
239
224
  }
@@ -297,7 +282,7 @@ class Utils {
297
282
  target[key] = Utils.copy(value);
298
283
  continue;
299
284
  }
300
- /* istanbul ignore next */
285
+ /* v8 ignore next 3 */
301
286
  if (!(key in target)) {
302
287
  Object.assign(target, { [key]: {} });
303
288
  }
@@ -338,7 +323,7 @@ class Utils {
338
323
  * Creates deep copy of given object.
339
324
  */
340
325
  static copy(entity, respectCustomCloneMethod = true) {
341
- return (0, clone_1.clone)(entity, respectCustomCloneMethod);
326
+ return clone(entity, respectCustomCloneMethod);
342
327
  }
343
328
  /**
344
329
  * Normalize the argument to always be an array.
@@ -380,11 +365,11 @@ class Utils {
380
365
  if (Array.isArray(func)) {
381
366
  return func;
382
367
  }
368
+ /* v8 ignore next 5 */
383
369
  try {
384
- return (0, esprima_1.tokenize)(func.toString(), { tolerant: true });
370
+ return tokenize(func.toString(), { tolerant: true });
385
371
  }
386
372
  catch {
387
- /* istanbul ignore next */
388
373
  return [];
389
374
  }
390
375
  }
@@ -412,7 +397,7 @@ class Utils {
412
397
  break;
413
398
  }
414
399
  if (inside === 2 && token.type === 'Punctuator' && token.value === '{' && i === currentBlockStart + 1) {
415
- ret.push(exports.ObjectBindingPattern);
400
+ ret.push(ObjectBindingPattern);
416
401
  i = tokens.findIndex((t, idx) => idx > i + 2 && t.type === 'Punctuator' && t.value === '}');
417
402
  continue;
418
403
  }
@@ -450,7 +435,7 @@ class Utils {
450
435
  return data;
451
436
  }
452
437
  if (Utils.isEntity(data, true)) {
453
- return (0, wrap_1.helper)(data).getPrimaryKey();
438
+ return helper(data).getPrimaryKey();
454
439
  }
455
440
  if (strict && meta && Utils.getObjectKeysSize(data) !== meta.primaryKeys.length) {
456
441
  return null;
@@ -499,7 +484,7 @@ class Utils {
499
484
  return key.split(this.PK_SEPARATOR);
500
485
  }
501
486
  static getPrimaryKeyValues(entity, primaryKeys, allowScalar = false, convertCustomTypes = false) {
502
- /* istanbul ignore next */
487
+ /* v8 ignore next 3 */
503
488
  if (entity == null) {
504
489
  return entity;
505
490
  }
@@ -510,7 +495,7 @@ class Utils {
510
495
  return val;
511
496
  }
512
497
  const pk = Utils.isEntity(entity, true)
513
- ? (0, wrap_1.helper)(entity).getPrimaryKey(convertCustomTypes)
498
+ ? helper(entity).getPrimaryKey(convertCustomTypes)
514
499
  : primaryKeys.reduce((o, pk) => { o[pk] = entity[pk]; return o; }, {});
515
500
  if (primaryKeys.length > 1) {
516
501
  return toArray(pk);
@@ -570,7 +555,7 @@ class Utils {
570
555
  if (convertCustomTypes && platform && prop.customType && !prop.targetMeta) {
571
556
  value = prop.customType.convertToJSValue(value, platform);
572
557
  }
573
- if (prop.kind !== enums_1.ReferenceKind.SCALAR && prop.targetMeta) {
558
+ if (prop.kind !== ReferenceKind.SCALAR && prop.targetMeta) {
574
559
  const value2 = this.getOrderedPrimaryKeys(value, prop.targetMeta, platform, convertCustomTypes);
575
560
  value = value2.length > 1 ? value2 : value2[0];
576
561
  }
@@ -631,19 +616,17 @@ class Utils {
631
616
  .map(field => field === allSymbol ? allSymbol : field.substring(prefix.length + 1));
632
617
  }
633
618
  /**
634
- * Tries to detect `ts-node` runtime.
619
+ * Tries to detect TypeScript support.
635
620
  */
636
- static detectTsNode() {
637
- /* istanbul ignore next */
621
+ static detectTypeScriptSupport() {
622
+ /* v8 ignore next 7 */
638
623
  return process.argv[0].endsWith('ts-node') // running via ts-node directly
639
- // @ts-ignore
640
- || !!process[Symbol.for('ts-node.register.instance')] // check if internal ts-node symbol exists
624
+ || !!process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS // forced explicitly or enabled via `registerTypeScriptSupport()`
641
625
  || !!process.env.TS_JEST // check if ts-jest is used (works only with v27.0.4+)
642
626
  || !!process.env.VITEST // check if vitest is used
643
627
  || !!process.versions.bun // check if bun is used
644
628
  || process.argv.slice(1).some(arg => arg.includes('ts-node')) // registering ts-node runner
645
- || process.execArgv.some(arg => arg === 'ts-node/esm') // check for ts-node/esm module loader
646
- || (require.extensions && !!require.extensions['.ts']); // check if the extension is registered
629
+ || process.execArgv.some(arg => arg === 'ts-node/esm'); // check for ts-node/esm module loader
647
630
  }
648
631
  /**
649
632
  * Uses some dark magic to get source path to caller where decorator is used.
@@ -705,7 +688,7 @@ class Utils {
705
688
  && typeof value.constructor === 'function'
706
689
  && (Object.hasOwn(value.constructor.prototype, 'isPrototypeOf') || Object.getPrototypeOf(value.constructor.prototype) === null))
707
690
  || (value && Object.getPrototypeOf(value) === null)
708
- || value instanceof enums_1.PlainObject;
691
+ || value instanceof PlainObject;
709
692
  }
710
693
  /**
711
694
  * Executes the `cb` promise serially on every element of the `items` array and returns array of resolved values.
@@ -722,7 +705,7 @@ class Utils {
722
705
  }
723
706
  static fileURLToPath(url) {
724
707
  // expose `fileURLToPath` on Utils so that it can be properly mocked in tests
725
- return (0, node_url_1.fileURLToPath)(url);
708
+ return fileURLToPath(url);
726
709
  }
727
710
  /**
728
711
  * Resolves and normalizes a series of path parts relative to each preceding part.
@@ -735,7 +718,7 @@ class Utils {
735
718
  let start = 0;
736
719
  for (let i = 0; i < parts.length; i++) {
737
720
  const part = parts[i];
738
- if ((0, node_path_1.isAbsolute)(part)) {
721
+ if (isAbsolute(part)) {
739
722
  start = i;
740
723
  }
741
724
  else if (part.startsWith('file:')) {
@@ -747,7 +730,7 @@ class Utils {
747
730
  parts = parts.slice(start);
748
731
  }
749
732
  let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
750
- path = (0, node_path_1.normalize)(path).replace(/\\/g, '/');
733
+ path = normalize(path).replace(/\\/g, '/');
751
734
  return (path.match(/^[/.]|[a-zA-Z]:/) || path.startsWith('!')) ? path : './' + path;
752
735
  }
753
736
  /**
@@ -762,7 +745,7 @@ class Utils {
762
745
  if (path.startsWith('.')) {
763
746
  return path;
764
747
  }
765
- path = (0, node_path_1.relative)(Utils.normalizePath(relativeTo), path);
748
+ path = relative(Utils.normalizePath(relativeTo), path);
766
749
  return Utils.normalizePath(path);
767
750
  }
768
751
  /**
@@ -773,13 +756,13 @@ class Utils {
773
756
  if (!path) {
774
757
  return Utils.normalizePath(baseDir);
775
758
  }
776
- if (!(0, node_path_1.isAbsolute)(path) && !path.startsWith('file://')) {
759
+ if (!isAbsolute(path) && !path.startsWith('file://')) {
777
760
  path = baseDir + '/' + path;
778
761
  }
779
762
  return Utils.normalizePath(path);
780
763
  }
781
764
  static hash(data, length) {
782
- const hash = (0, node_crypto_1.createHash)('md5').update(data).digest('hex');
765
+ const hash = createHash('md5').update(data).digest('hex');
783
766
  if (length) {
784
767
  return hash.substring(0, length);
785
768
  }
@@ -812,11 +795,11 @@ class Utils {
812
795
  return Math.round(Math.random() * (max - min)) + min;
813
796
  }
814
797
  static async pathExists(path, options = {}) {
815
- if (globby_1.default.hasMagic(path)) {
816
- const found = await (0, globby_1.default)(path, options);
798
+ if (globby.hasMagic(path)) {
799
+ const found = await globby(path, options);
817
800
  return found.length > 0;
818
801
  }
819
- return (0, fs_extra_1.pathExistsSync)(path);
802
+ return this.pathExistsSync(path);
820
803
  }
821
804
  /**
822
805
  * Extracts all possible values of a TS enum. Works with both string and numeric enums.
@@ -839,18 +822,18 @@ class Utils {
839
822
  }
840
823
  static isOperator(key, includeGroupOperators = true) {
841
824
  if (!includeGroupOperators) {
842
- return key in enums_1.QueryOperator;
825
+ return key in QueryOperator;
843
826
  }
844
- return key in enums_1.GroupOperator || key in enums_1.QueryOperator;
827
+ return key in GroupOperator || key in QueryOperator;
845
828
  }
846
829
  static isGroupOperator(key) {
847
- return key in enums_1.GroupOperator;
830
+ return key in GroupOperator;
848
831
  }
849
832
  static isArrayOperator(key) {
850
- return enums_1.ARRAY_OPERATORS.includes(key);
833
+ return ARRAY_OPERATORS.includes(key);
851
834
  }
852
835
  static isJsonKeyOperator(key) {
853
- return enums_1.JSON_KEY_OPERATORS.includes(key);
836
+ return JSON_KEY_OPERATORS.includes(key);
854
837
  }
855
838
  static hasNestedKey(object, key) {
856
839
  if (!object) {
@@ -875,49 +858,55 @@ class Utils {
875
858
  * @param [from] Location to start the node resolution
876
859
  */
877
860
  static requireFrom(id, from = process.cwd()) {
878
- if (!(0, node_path_1.extname)(from)) {
879
- from = (0, node_path_1.join)(from, '__fake.js');
861
+ if (!extname(from)) {
862
+ from = join(from, '__fake.js');
880
863
  }
881
- return (0, node_module_1.createRequire)((0, node_path_1.resolve)(from))(id);
864
+ return createRequire(resolve(from))(id);
882
865
  }
883
866
  static async dynamicImport(id) {
884
- /* istanbul ignore next */
885
- if ((0, node_os_1.platform)() === 'win32') {
867
+ /* v8 ignore next 7 */
868
+ if (platform() === 'win32') {
886
869
  try {
887
- id = (0, node_url_1.pathToFileURL)(id).toString();
870
+ id = pathToFileURL(id).toString();
888
871
  }
889
872
  catch {
890
873
  // ignore
891
874
  }
892
- // If the extension is not registered, we need to fall back to a file path.
893
- if (require.extensions && !require.extensions[(0, node_path_1.extname)(id)]) {
894
- id = (0, node_url_1.fileURLToPath)(id);
895
- }
896
875
  }
897
- /* istanbul ignore next */
876
+ /* v8 ignore next */
898
877
  return this.dynamicImportProvider(id);
899
878
  }
900
- /* istanbul ignore next */
879
+ /* v8 ignore next 3 */
901
880
  static setDynamicImportProvider(provider) {
902
881
  this.dynamicImportProvider = provider;
903
882
  }
883
+ static ensureDir(path) {
884
+ if (!existsSync(path)) {
885
+ mkdirSync(path, { recursive: true });
886
+ }
887
+ }
888
+ static pathExistsSync(path) {
889
+ return existsSync(path);
890
+ }
891
+ static readJSONSync(path) {
892
+ const file = readFileSync(path);
893
+ return JSON.parse(file.toString());
894
+ }
904
895
  static getORMVersion() {
905
- /* istanbul ignore next */
906
896
  try {
907
- // this works with ts-node during development (where we have `src` folder)
908
- // eslint-disable-next-line @typescript-eslint/no-var-requires
909
- return require('../../package.json').version;
897
+ // this works during development where we have `src` folder
898
+ return this.requireFrom('../../package.json', import.meta.dirname).version;
899
+ /* v8 ignore next 5 */
910
900
  }
911
901
  catch {
912
- // this works with node in production build (where we do not have the `src` folder)
913
- // eslint-disable-next-line @typescript-eslint/no-var-requires
914
- return require('../package.json').version;
902
+ // this works in production build where we do not have the `src` folder
903
+ return this.requireFrom('../package.json', import.meta.dirname).version;
915
904
  }
916
905
  }
917
- /* istanbul ignore next */
918
906
  static createFunction(context, code) {
919
907
  try {
920
908
  return new Function(...context.keys(), `'use strict';\n` + code)(...context.values());
909
+ /* v8 ignore next 5 */
921
910
  }
922
911
  catch (e) {
923
912
  // eslint-disable-next-line no-console
@@ -925,12 +914,12 @@ class Utils {
925
914
  throw e;
926
915
  }
927
916
  }
928
- /* istanbul ignore next */
929
917
  static callCompiledFunction(fn, ...args) {
930
918
  try {
931
919
  return fn(...args);
932
920
  }
933
921
  catch (e) {
922
+ /* v8 ignore start */
934
923
  if ([SyntaxError, TypeError, EvalError, ReferenceError].some(t => e instanceof t)) {
935
924
  const position = e.stack.match(/<anonymous>:(\d+):(\d+)/);
936
925
  let code = fn.toString();
@@ -947,6 +936,7 @@ class Utils {
947
936
  // eslint-disable-next-line no-console
948
937
  console.error(`JIT runtime error: ${e.message}\n\n${code}`);
949
938
  }
939
+ /* v8 ignore stop */
950
940
  throw e;
951
941
  }
952
942
  }
@@ -1052,6 +1042,16 @@ class Utils {
1052
1042
  throw err;
1053
1043
  }
1054
1044
  }
1045
+ static async tryImport({ module, warning }) {
1046
+ try {
1047
+ return await this.dynamicImport(module);
1048
+ }
1049
+ catch (err) {
1050
+ // eslint-disable-next-line no-console
1051
+ console.warn(warning);
1052
+ return undefined;
1053
+ }
1054
+ }
1055
1055
  static stripRelativePath(str) {
1056
1056
  return str.replace(/^(?:\.\.\/|\.\/)+/, '/');
1057
1057
  }
@@ -1087,9 +1087,6 @@ class Utils {
1087
1087
  static entries(obj) {
1088
1088
  return Object.entries(obj);
1089
1089
  }
1090
- static isRawSql(value) {
1091
- return isRawSql(value);
1092
- }
1093
1090
  static primaryKeyToObject(meta, primaryKey, visible) {
1094
1091
  const pks = meta.compositePK && Utils.isPlainObject(primaryKey) ? Object.values(primaryKey) : Utils.asArray(primaryKey);
1095
1092
  const pkProps = meta.getPrimaryProps();
@@ -1107,4 +1104,3 @@ class Utils {
1107
1104
  }, {});
1108
1105
  }
1109
1106
  }
1110
- exports.Utils = Utils;
package/utils/clone.js CHANGED
@@ -1,13 +1,10 @@
1
- "use strict";
2
1
  /**
3
2
  * Inspired by https://github.com/pvorb/clone but simplified and never tries to
4
3
  * clone `EventEmitter`s to get around https://github.com/mikro-orm/mikro-orm/issues/2748
5
4
  * @internal
6
5
  */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.clone = clone;
9
- const node_events_1 = require("node:events");
10
- const RawQueryFragment_1 = require("./RawQueryFragment");
6
+ import { EventEmitter } from 'node:events';
7
+ import { RawQueryFragment } from './RawQueryFragment.js';
11
8
  /**
12
9
  * Get the property descriptor of a property on an object or its prototype chain.
13
10
  *
@@ -25,7 +22,7 @@ function getPropertyDescriptor(obj, prop) {
25
22
  }
26
23
  return null;
27
24
  }
28
- function clone(parent, respectCustomCloneMethod = true) {
25
+ export function clone(parent, respectCustomCloneMethod = true) {
29
26
  const allParents = [];
30
27
  const allChildren = [];
31
28
  function _clone(parent) {
@@ -33,11 +30,11 @@ function clone(parent, respectCustomCloneMethod = true) {
33
30
  if (parent === null) {
34
31
  return null;
35
32
  }
36
- const raw = RawQueryFragment_1.RawQueryFragment.getKnownFragment(parent, false);
33
+ const raw = RawQueryFragment.getKnownFragment(parent, false);
37
34
  if (raw && respectCustomCloneMethod) {
38
35
  return raw.clone();
39
36
  }
40
- if (typeof parent !== 'object' || parent instanceof node_events_1.EventEmitter) {
37
+ if (typeof parent !== 'object' || parent instanceof EventEmitter) {
41
38
  return parent;
42
39
  }
43
40
  if (respectCustomCloneMethod && 'clone' in parent && typeof parent.clone === 'function') {
@@ -84,7 +81,7 @@ function clone(parent, respectCustomCloneMethod = true) {
84
81
  return child;
85
82
  }
86
83
  else if (parent instanceof Error) {
87
- child = Object.create(parent);
84
+ child = new parent.constructor(parent.message);
88
85
  }
89
86
  else {
90
87
  proto = Object.getPrototypeOf(parent);
@@ -117,7 +114,7 @@ function clone(parent, respectCustomCloneMethod = true) {
117
114
  if (attrs && typeof attrs.get === 'function' && attrs.set == null) {
118
115
  continue;
119
116
  }
120
- const raw = RawQueryFragment_1.RawQueryFragment.getKnownFragment(i, false);
117
+ const raw = RawQueryFragment.getKnownFragment(i, false);
121
118
  if (raw && respectCustomCloneMethod) {
122
119
  const i2 = raw.clone().toString();
123
120
  child[i2] = _clone(parent[i]);
@@ -130,7 +127,7 @@ function clone(parent, respectCustomCloneMethod = true) {
130
127
  for (let i = 0; i < symbols.length; i++) {
131
128
  const symbol = symbols[i];
132
129
  const descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
133
- /* istanbul ignore next */
130
+ /* v8 ignore next 3 */
134
131
  if (descriptor && !descriptor.enumerable) {
135
132
  continue;
136
133
  }
package/utils/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- export * from './Configuration';
2
- export * from './ConfigurationLoader';
3
- export * from './Cursor';
4
- export * from './DataloaderUtils';
5
- export * from './Utils';
6
- export * from './RequestContext';
7
- export * from './TransactionContext';
8
- export * from './QueryHelper';
9
- export * from './NullHighlighter';
10
- export * from './EntityComparator';
11
- export * from './AbstractSchemaGenerator';
12
- export * from './RawQueryFragment';
13
- export * from './upsert-utils';
1
+ export * from './Configuration.js';
2
+ export * from './ConfigurationLoader.js';
3
+ export * from './Cursor.js';
4
+ export * from './DataloaderUtils.js';
5
+ export * from './Utils.js';
6
+ export * from './RequestContext.js';
7
+ export * from './TransactionContext.js';
8
+ export * from './QueryHelper.js';
9
+ export * from './NullHighlighter.js';
10
+ export * from './EntityComparator.js';
11
+ export * from './AbstractSchemaGenerator.js';
12
+ export * from './RawQueryFragment.js';
13
+ export * from './upsert-utils.js';
package/utils/index.js CHANGED
@@ -1,29 +1,13 @@
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("./Configuration"), exports);
18
- __exportStar(require("./ConfigurationLoader"), exports);
19
- __exportStar(require("./Cursor"), exports);
20
- __exportStar(require("./DataloaderUtils"), exports);
21
- __exportStar(require("./Utils"), exports);
22
- __exportStar(require("./RequestContext"), exports);
23
- __exportStar(require("./TransactionContext"), exports);
24
- __exportStar(require("./QueryHelper"), exports);
25
- __exportStar(require("./NullHighlighter"), exports);
26
- __exportStar(require("./EntityComparator"), exports);
27
- __exportStar(require("./AbstractSchemaGenerator"), exports);
28
- __exportStar(require("./RawQueryFragment"), exports);
29
- __exportStar(require("./upsert-utils"), exports);
1
+ export * from './Configuration.js';
2
+ export * from './ConfigurationLoader.js';
3
+ export * from './Cursor.js';
4
+ export * from './DataloaderUtils.js';
5
+ export * from './Utils.js';
6
+ export * from './RequestContext.js';
7
+ export * from './TransactionContext.js';
8
+ export * from './QueryHelper.js';
9
+ export * from './NullHighlighter.js';
10
+ export * from './EntityComparator.js';
11
+ export * from './AbstractSchemaGenerator.js';
12
+ export * from './RawQueryFragment.js';
13
+ export * from './upsert-utils.js';
@@ -1,6 +1,6 @@
1
- import { EntityManager } from '../EntityManager';
2
- import { MikroORM } from '../MikroORM';
3
- import type { ContextProvider, MaybePromise } from '../typings';
1
+ import { EntityManager } from '../EntityManager.js';
2
+ import { MikroORM } from '../MikroORM.js';
3
+ import type { ContextProvider, MaybePromise } from '../typings.js';
4
4
  /**
5
5
  * Find `EntityManager` in provided context, or else in instance's `orm` or `em` properties.
6
6
  */
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveContextProvider = resolveContextProvider;
4
- const EntityRepository_1 = require("../entity/EntityRepository");
5
- const EntityManager_1 = require("../EntityManager");
6
- const MikroORM_1 = require("../MikroORM");
1
+ import { EntityRepository } from '../entity/EntityRepository.js';
2
+ import { EntityManager } from '../EntityManager.js';
3
+ import { MikroORM } from '../MikroORM.js';
7
4
  function getEntityManager(caller, context) {
8
- if (context instanceof EntityManager_1.EntityManager) {
5
+ if (context instanceof EntityManager) {
9
6
  return context;
10
7
  }
11
- if (context instanceof EntityRepository_1.EntityRepository) {
8
+ if (context instanceof EntityRepository) {
12
9
  return context.getEntityManager();
13
10
  }
14
- if (context instanceof MikroORM_1.MikroORM) {
11
+ if (context instanceof MikroORM) {
15
12
  return context.em;
16
13
  }
17
- if (caller.em instanceof EntityManager_1.EntityManager) {
14
+ if (caller.em instanceof EntityManager) {
18
15
  return caller.em;
19
16
  }
20
- if (caller.orm instanceof MikroORM_1.MikroORM) {
17
+ if (caller.orm instanceof MikroORM) {
21
18
  return caller.orm.em;
22
19
  }
23
20
  return undefined;
@@ -25,7 +22,7 @@ function getEntityManager(caller, context) {
25
22
  /**
26
23
  * Find `EntityManager` in provided context, or else in instance's `orm` or `em` properties.
27
24
  */
28
- async function resolveContextProvider(caller, provider) {
25
+ export async function resolveContextProvider(caller, provider) {
29
26
  const context = typeof provider === 'function' ? await provider(caller) : await provider;
30
27
  return getEntityManager({ orm: await caller.orm, em: await caller.em }, context);
31
28
  }
@@ -1,6 +1,6 @@
1
- import type { EntityData, EntityMetadata } from '../typings';
2
- import type { UpsertOptions } from '../drivers/IDatabaseDriver';
3
- import type { RawQueryFragment } from '../utils/RawQueryFragment';
1
+ import type { EntityData, EntityMetadata } from '../typings.js';
2
+ import type { UpsertOptions } from '../drivers/IDatabaseDriver.js';
3
+ import type { RawQueryFragment } from '../utils/RawQueryFragment.js';
4
4
  /** @internal */
5
5
  export declare function getOnConflictFields<T>(meta: EntityMetadata<T> | undefined, data: EntityData<T>, uniqueFields: (keyof T)[] | RawQueryFragment, options: UpsertOptions<T>): (keyof T)[];
6
6
  /** @internal */