@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
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,21 @@ 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
- || 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
628
+ || process.argv.slice(1).some(arg => arg.match(/\.([mc]?ts|tsx)$/)) // executing `.ts` file
629
+ || process.execArgv.some(arg => {
630
+ return arg.includes('ts-node') // check for ts-node loader
631
+ || arg.includes('@swc-node/register') // check for swc-node/register loader
632
+ || arg.includes('node_modules/tsx/'); // check for tsx loader
633
+ });
647
634
  }
648
635
  /**
649
636
  * Uses some dark magic to get source path to caller where decorator is used.
@@ -661,7 +648,8 @@ class Utils {
661
648
  // but those are also present in node, so we need to check this only if they weren't found.
662
649
  if (line === -1) {
663
650
  // here we handle bun which stack is different from nodejs so we search for reflect-metadata
664
- const reflectLine = stack.findIndex(line => Utils.normalizePath(line).includes('node_modules/reflect-metadata/Reflect.js'));
651
+ // Different bun versions might have different stack traces. The "last index" works for both 1.2.6 and 1.2.7.
652
+ const reflectLine = stack.findLastIndex(line => Utils.normalizePath(line).includes('node_modules/reflect-metadata/Reflect.js'));
665
653
  if (reflectLine === -1 || reflectLine + 2 >= stack.length || !stack[reflectLine + 1].includes('bun:wrap')) {
666
654
  return name;
667
655
  }
@@ -705,7 +693,7 @@ class Utils {
705
693
  && typeof value.constructor === 'function'
706
694
  && (Object.hasOwn(value.constructor.prototype, 'isPrototypeOf') || Object.getPrototypeOf(value.constructor.prototype) === null))
707
695
  || (value && Object.getPrototypeOf(value) === null)
708
- || value instanceof enums_1.PlainObject;
696
+ || value instanceof PlainObject;
709
697
  }
710
698
  /**
711
699
  * Executes the `cb` promise serially on every element of the `items` array and returns array of resolved values.
@@ -722,7 +710,7 @@ class Utils {
722
710
  }
723
711
  static fileURLToPath(url) {
724
712
  // expose `fileURLToPath` on Utils so that it can be properly mocked in tests
725
- return (0, node_url_1.fileURLToPath)(url);
713
+ return fileURLToPath(url);
726
714
  }
727
715
  /**
728
716
  * Resolves and normalizes a series of path parts relative to each preceding part.
@@ -735,7 +723,7 @@ class Utils {
735
723
  let start = 0;
736
724
  for (let i = 0; i < parts.length; i++) {
737
725
  const part = parts[i];
738
- if ((0, node_path_1.isAbsolute)(part)) {
726
+ if (isAbsolute(part)) {
739
727
  start = i;
740
728
  }
741
729
  else if (part.startsWith('file:')) {
@@ -747,7 +735,7 @@ class Utils {
747
735
  parts = parts.slice(start);
748
736
  }
749
737
  let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
750
- path = (0, node_path_1.normalize)(path).replace(/\\/g, '/');
738
+ path = normalize(path).replace(/\\/g, '/');
751
739
  return (path.match(/^[/.]|[a-zA-Z]:/) || path.startsWith('!')) ? path : './' + path;
752
740
  }
753
741
  /**
@@ -762,7 +750,7 @@ class Utils {
762
750
  if (path.startsWith('.')) {
763
751
  return path;
764
752
  }
765
- path = (0, node_path_1.relative)(Utils.normalizePath(relativeTo), path);
753
+ path = relative(Utils.normalizePath(relativeTo), path);
766
754
  return Utils.normalizePath(path);
767
755
  }
768
756
  /**
@@ -773,13 +761,13 @@ class Utils {
773
761
  if (!path) {
774
762
  return Utils.normalizePath(baseDir);
775
763
  }
776
- if (!(0, node_path_1.isAbsolute)(path) && !path.startsWith('file://')) {
764
+ if (!isAbsolute(path) && !path.startsWith('file://')) {
777
765
  path = baseDir + '/' + path;
778
766
  }
779
767
  return Utils.normalizePath(path);
780
768
  }
781
769
  static hash(data, length) {
782
- const hash = (0, node_crypto_1.createHash)('md5').update(data).digest('hex');
770
+ const hash = createHash('md5').update(data).digest('hex');
783
771
  if (length) {
784
772
  return hash.substring(0, length);
785
773
  }
@@ -812,11 +800,11 @@ class Utils {
812
800
  return Math.round(Math.random() * (max - min)) + min;
813
801
  }
814
802
  static async pathExists(path, options = {}) {
815
- if (globby_1.default.hasMagic(path)) {
816
- const found = await (0, globby_1.default)(path, options);
803
+ if (globby.hasMagic(path)) {
804
+ const found = await globby(path, options);
817
805
  return found.length > 0;
818
806
  }
819
- return (0, fs_extra_1.pathExistsSync)(path);
807
+ return this.pathExistsSync(path);
820
808
  }
821
809
  /**
822
810
  * Extracts all possible values of a TS enum. Works with both string and numeric enums.
@@ -839,18 +827,18 @@ class Utils {
839
827
  }
840
828
  static isOperator(key, includeGroupOperators = true) {
841
829
  if (!includeGroupOperators) {
842
- return key in enums_1.QueryOperator;
830
+ return key in QueryOperator;
843
831
  }
844
- return key in enums_1.GroupOperator || key in enums_1.QueryOperator;
832
+ return key in GroupOperator || key in QueryOperator;
845
833
  }
846
834
  static isGroupOperator(key) {
847
- return key in enums_1.GroupOperator;
835
+ return key in GroupOperator;
848
836
  }
849
837
  static isArrayOperator(key) {
850
- return enums_1.ARRAY_OPERATORS.includes(key);
838
+ return ARRAY_OPERATORS.includes(key);
851
839
  }
852
840
  static isJsonKeyOperator(key) {
853
- return enums_1.JSON_KEY_OPERATORS.includes(key);
841
+ return JSON_KEY_OPERATORS.includes(key);
854
842
  }
855
843
  static hasNestedKey(object, key) {
856
844
  if (!object) {
@@ -875,49 +863,55 @@ class Utils {
875
863
  * @param [from] Location to start the node resolution
876
864
  */
877
865
  static requireFrom(id, from = process.cwd()) {
878
- if (!(0, node_path_1.extname)(from)) {
879
- from = (0, node_path_1.join)(from, '__fake.js');
866
+ if (!extname(from)) {
867
+ from = join(from, '__fake.js');
880
868
  }
881
- return (0, node_module_1.createRequire)((0, node_path_1.resolve)(from))(id);
869
+ return createRequire(resolve(from))(id);
882
870
  }
883
871
  static async dynamicImport(id) {
884
- /* istanbul ignore next */
885
- if ((0, node_os_1.platform)() === 'win32') {
872
+ /* v8 ignore next 7 */
873
+ if (platform() === 'win32') {
886
874
  try {
887
- id = (0, node_url_1.pathToFileURL)(id).toString();
875
+ id = pathToFileURL(id).toString();
888
876
  }
889
877
  catch {
890
878
  // ignore
891
879
  }
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
880
  }
897
- /* istanbul ignore next */
881
+ /* v8 ignore next */
898
882
  return this.dynamicImportProvider(id);
899
883
  }
900
- /* istanbul ignore next */
884
+ /* v8 ignore next 3 */
901
885
  static setDynamicImportProvider(provider) {
902
886
  this.dynamicImportProvider = provider;
903
887
  }
888
+ static ensureDir(path) {
889
+ if (!existsSync(path)) {
890
+ mkdirSync(path, { recursive: true });
891
+ }
892
+ }
893
+ static pathExistsSync(path) {
894
+ return existsSync(path);
895
+ }
896
+ static readJSONSync(path) {
897
+ const file = readFileSync(path);
898
+ return JSON.parse(file.toString());
899
+ }
904
900
  static getORMVersion() {
905
- /* istanbul ignore next */
906
901
  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;
902
+ // this works during development where we have `src` folder
903
+ return this.requireFrom('../../package.json', import.meta.dirname).version;
904
+ /* v8 ignore next 5 */
910
905
  }
911
906
  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;
907
+ // this works in production build where we do not have the `src` folder
908
+ return this.requireFrom('../package.json', import.meta.dirname).version;
915
909
  }
916
910
  }
917
- /* istanbul ignore next */
918
911
  static createFunction(context, code) {
919
912
  try {
920
913
  return new Function(...context.keys(), `'use strict';\n` + code)(...context.values());
914
+ /* v8 ignore next 5 */
921
915
  }
922
916
  catch (e) {
923
917
  // eslint-disable-next-line no-console
@@ -925,12 +919,12 @@ class Utils {
925
919
  throw e;
926
920
  }
927
921
  }
928
- /* istanbul ignore next */
929
922
  static callCompiledFunction(fn, ...args) {
930
923
  try {
931
924
  return fn(...args);
932
925
  }
933
926
  catch (e) {
927
+ /* v8 ignore start */
934
928
  if ([SyntaxError, TypeError, EvalError, ReferenceError].some(t => e instanceof t)) {
935
929
  const position = e.stack.match(/<anonymous>:(\d+):(\d+)/);
936
930
  let code = fn.toString();
@@ -947,6 +941,7 @@ class Utils {
947
941
  // eslint-disable-next-line no-console
948
942
  console.error(`JIT runtime error: ${e.message}\n\n${code}`);
949
943
  }
944
+ /* v8 ignore stop */
950
945
  throw e;
951
946
  }
952
947
  }
@@ -1052,6 +1047,16 @@ class Utils {
1052
1047
  throw err;
1053
1048
  }
1054
1049
  }
1050
+ static async tryImport({ module, warning }) {
1051
+ try {
1052
+ return await this.dynamicImport(module);
1053
+ }
1054
+ catch (err) {
1055
+ // eslint-disable-next-line no-console
1056
+ console.warn(warning);
1057
+ return undefined;
1058
+ }
1059
+ }
1055
1060
  static stripRelativePath(str) {
1056
1061
  return str.replace(/^(?:\.\.\/|\.\/)+/, '/');
1057
1062
  }
@@ -1087,9 +1092,6 @@ class Utils {
1087
1092
  static entries(obj) {
1088
1093
  return Object.entries(obj);
1089
1094
  }
1090
- static isRawSql(value) {
1091
- return isRawSql(value);
1092
- }
1093
1095
  static primaryKeyToObject(meta, primaryKey, visible) {
1094
1096
  const pks = meta.compositePK && Utils.isPlainObject(primaryKey) ? Object.values(primaryKey) : Utils.asArray(primaryKey);
1095
1097
  const pkProps = meta.getPrimaryProps();
@@ -1107,4 +1109,3 @@ class Utils {
1107
1109
  }, {});
1108
1110
  }
1109
1111
  }
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
  }