@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
package/utils/Utils.js CHANGED
@@ -1,27 +1,8 @@
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 { isAbsolute, normalize, relative } from 'node:path';
2
+ import { fileURLToPath, pathToFileURL } from 'node:url';
3
+ import { clone } from './clone.js';
4
+ import { GroupOperator, PlainObject, QueryOperator, ReferenceKind } from '../enums.js';
5
+ import { helper } from '../entity/wrap.js';
25
6
  function compareConstructors(a, b) {
26
7
  if (a.constructor === b.constructor) {
27
8
  return true;
@@ -34,10 +15,7 @@ function compareConstructors(a, b) {
34
15
  }
35
16
  return false;
36
17
  }
37
- function isRawSql(value) {
38
- return typeof value === 'object' && !!value && '__raw' in value;
39
- }
40
- function compareObjects(a, b) {
18
+ export function compareObjects(a, b) {
41
19
  if (a === b || (a == null && b == null)) {
42
20
  return true;
43
21
  }
@@ -56,6 +34,7 @@ function compareObjects(a, b) {
56
34
  }
57
35
  return timeA === timeB;
58
36
  }
37
+ /* v8 ignore next */
59
38
  if ((typeof a === 'function' && typeof b === 'function') ||
60
39
  (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
40
  (a instanceof RegExp && b instanceof RegExp) ||
@@ -82,7 +61,7 @@ function compareObjects(a, b) {
82
61
  }
83
62
  return true;
84
63
  }
85
- function compareArrays(a, b) {
64
+ export function compareArrays(a, b) {
86
65
  const length = a.length;
87
66
  if (length !== b.length) {
88
67
  return false;
@@ -95,12 +74,12 @@ function compareArrays(a, b) {
95
74
  }
96
75
  return true;
97
76
  }
98
- function compareBooleans(a, b) {
77
+ export function compareBooleans(a, b) {
99
78
  a = typeof a === 'number' ? Boolean(a) : a;
100
79
  b = typeof b === 'number' ? Boolean(b) : b;
101
80
  return a === b;
102
81
  }
103
- function compareBuffers(a, b) {
82
+ export function compareBuffers(a, b) {
104
83
  const length = a.length;
105
84
  if (length !== b.length) {
106
85
  return false;
@@ -115,7 +94,7 @@ function compareBuffers(a, b) {
115
94
  /**
116
95
  * Checks if arguments are deeply (but not strictly) equal.
117
96
  */
118
- function equals(a, b) {
97
+ export function equals(a, b) {
119
98
  if (a === b) {
120
99
  return true;
121
100
  }
@@ -131,8 +110,9 @@ function equals(a, b) {
131
110
  return Number.isNaN(a) && Number.isNaN(b);
132
111
  }
133
112
  const equalsFn = equals;
134
- function parseJsonSafe(value) {
113
+ export function parseJsonSafe(value) {
135
114
  if (typeof value === 'string') {
115
+ /* v8 ignore next */
136
116
  try {
137
117
  return JSON.parse(value);
138
118
  }
@@ -143,54 +123,17 @@ function parseJsonSafe(value) {
143
123
  }
144
124
  return value;
145
125
  }
146
- class Utils {
126
+ export class Utils {
147
127
  static PK_SEPARATOR = '~~~';
148
- /* istanbul ignore next */
128
+ static #ORM_VERSION = '7.0.0-dev.100';
129
+ /* v8 ignore next */
149
130
  static dynamicImportProvider = (id) => import(id);
150
- /**
151
- * Checks if the argument is not undefined
152
- */
153
- static isDefined(data) {
154
- return typeof data !== 'undefined';
155
- }
156
131
  /**
157
132
  * Checks if the argument is instance of `Object`. Returns false for arrays.
158
133
  */
159
134
  static isObject(o) {
160
135
  return !!o && typeof o === 'object' && !Array.isArray(o);
161
136
  }
162
- /**
163
- * Relation decorators allow using two signatures
164
- * - using first parameter as options object
165
- * - using all parameters
166
- *
167
- * This function validates those two ways are not mixed and returns the final options object.
168
- * If the second way is used, we always consider the last parameter as options object.
169
- * @internal
170
- */
171
- static processDecoratorParameters(params) {
172
- const keys = Object.keys(params);
173
- const values = Object.values(params);
174
- if (!Utils.isPlainObject(values[0])) {
175
- const lastKey = keys[keys.length - 1];
176
- const last = params[lastKey];
177
- delete params[lastKey];
178
- return { ...last, ...params };
179
- }
180
- // validate only first parameter is used if its an option object
181
- const empty = (v) => v == null || (Utils.isPlainObject(v) && !Utils.hasObjectKeys(v));
182
- if (values.slice(1).some(v => !empty(v))) {
183
- throw new Error('Mixing first decorator parameter as options object with other parameters is forbidden. ' +
184
- 'If you want to use the options parameter at first position, provide all options inside it.');
185
- }
186
- return values[0];
187
- }
188
- /**
189
- * Checks if the argument is instance of `Object`, but not one of the blacklisted types. Returns false for arrays.
190
- */
191
- static isNotObject(o, not) {
192
- return this.isObject(o) && !not.some(cls => o instanceof cls);
193
- }
194
137
  /**
195
138
  * Removes `undefined` properties (recursively) so they are not saved as nulls
196
139
  */
@@ -220,7 +163,6 @@ class Utils {
220
163
  static getObjectKeysSize(object) {
221
164
  let size = 0;
222
165
  for (const key in object) {
223
- /* istanbul ignore else */
224
166
  if (Object.hasOwn(object, key)) {
225
167
  size++;
226
168
  }
@@ -233,25 +175,12 @@ class Utils {
233
175
  */
234
176
  static hasObjectKeys(object) {
235
177
  for (const key in object) {
236
- /* istanbul ignore else */
237
178
  if (Object.hasOwn(object, key)) {
238
179
  return true;
239
180
  }
240
181
  }
241
182
  return false;
242
183
  }
243
- /**
244
- * Checks if the argument is string
245
- */
246
- static isString(s) {
247
- return typeof s === 'string';
248
- }
249
- /**
250
- * Checks if the argument is number
251
- */
252
- static isNumber(s) {
253
- return typeof s === 'number';
254
- }
255
184
  /**
256
185
  * Checks if arguments are deeply (but not strictly) equal.
257
186
  */
@@ -297,7 +226,7 @@ class Utils {
297
226
  target[key] = Utils.copy(value);
298
227
  continue;
299
228
  }
300
- /* istanbul ignore next */
229
+ /* v8 ignore next */
301
230
  if (!(key in target)) {
302
231
  Object.assign(target, { [key]: {} });
303
232
  }
@@ -310,35 +239,11 @@ class Utils {
310
239
  }
311
240
  return Utils._merge(target, sources, ignoreUndefined);
312
241
  }
313
- static getRootEntity(metadata, meta) {
314
- const base = meta.extends && metadata.find(Utils.className(meta.extends));
315
- if (!base || base === meta) { // make sure we do not fall into infinite loop
316
- return meta;
317
- }
318
- const root = Utils.getRootEntity(metadata, base);
319
- if (root.discriminatorColumn) {
320
- return root;
321
- }
322
- return meta;
323
- }
324
- /**
325
- * Computes difference between two objects, ignoring items missing in `b`.
326
- */
327
- static diff(a, b) {
328
- const ret = {};
329
- for (const k of Object.keys(b)) {
330
- if (Utils.equals(a[k], b[k])) {
331
- continue;
332
- }
333
- ret[k] = b[k];
334
- }
335
- return ret;
336
- }
337
242
  /**
338
243
  * Creates deep copy of given object.
339
244
  */
340
245
  static copy(entity, respectCustomCloneMethod = true) {
341
- return (0, clone_1.clone)(entity, respectCustomCloneMethod);
246
+ return clone(entity, respectCustomCloneMethod);
342
247
  }
343
248
  /**
344
249
  * Normalize the argument to always be an array.
@@ -374,53 +279,37 @@ class Utils {
374
279
  }
375
280
  }
376
281
  /**
377
- * Returns array of functions argument names. Uses `esprima` for source code analysis.
282
+ * Returns array of functions argument names. Uses basic regex for source code analysis, might not work with advanced syntax.
378
283
  */
379
- static tokenize(func) {
380
- if (Array.isArray(func)) {
381
- return func;
382
- }
383
- try {
384
- return (0, esprima_1.tokenize)(func.toString(), { tolerant: true });
284
+ static getConstructorParams(func) {
285
+ const source = func.toString();
286
+ const i = source.indexOf('constructor');
287
+ if (i === -1) {
288
+ return undefined;
385
289
  }
386
- catch {
387
- /* istanbul ignore next */
388
- return [];
290
+ const start = source.indexOf('(', i);
291
+ if (start === -1) {
292
+ return undefined;
389
293
  }
390
- }
391
- /**
392
- * Returns array of functions argument names. Uses `esprima` for source code analysis.
393
- */
394
- static getParamNames(func, methodName) {
395
- const ret = [];
396
- const tokens = this.tokenize(func);
397
- let inside = 0;
398
- let currentBlockStart = 0;
399
- for (let i = 0; i < tokens.length; i++) {
400
- const token = tokens[i];
401
- if (token.type === 'Identifier' && token.value === methodName) {
402
- inside = 1;
403
- currentBlockStart = i;
404
- continue;
294
+ let depth = 0;
295
+ let end = start;
296
+ for (; end < source.length; end++) {
297
+ if (source[end] === '(') {
298
+ depth++;
405
299
  }
406
- if (inside === 1 && token.type === 'Punctuator' && token.value === '(') {
407
- inside = 2;
408
- currentBlockStart = i;
409
- continue;
300
+ if (source[end] === ')') {
301
+ depth--;
410
302
  }
411
- if (inside === 2 && token.type === 'Punctuator' && token.value === ')') {
303
+ if (depth === 0) {
412
304
  break;
413
305
  }
414
- if (inside === 2 && token.type === 'Punctuator' && token.value === '{' && i === currentBlockStart + 1) {
415
- ret.push(exports.ObjectBindingPattern);
416
- i = tokens.findIndex((t, idx) => idx > i + 2 && t.type === 'Punctuator' && t.value === '}');
417
- continue;
418
- }
419
- if (inside === 2 && token.type === 'Identifier') {
420
- ret.push(token.value);
421
- }
422
306
  }
423
- return ret;
307
+ const raw = source.slice(start + 1, end);
308
+ return raw
309
+ .split(',')
310
+ .map(s => s.trim().replace(/=.*$/, '').trim())
311
+ .filter(Boolean)
312
+ .map(raw => raw.startsWith('{') && raw.endsWith('}') ? '' : raw);
424
313
  }
425
314
  /**
426
315
  * Checks whether the argument looks like primary key (string, number or ObjectId).
@@ -433,7 +322,7 @@ class Utils {
433
322
  return true;
434
323
  }
435
324
  if (Utils.isObject(key)) {
436
- if (key.constructor && key.constructor.name.toLowerCase() === 'objectid') {
325
+ if (key.constructor?.name === 'ObjectId') {
437
326
  return true;
438
327
  }
439
328
  if (!Utils.isPlainObject(key) && !Utils.isEntity(key, true)) {
@@ -450,7 +339,11 @@ class Utils {
450
339
  return data;
451
340
  }
452
341
  if (Utils.isEntity(data, true)) {
453
- return (0, wrap_1.helper)(data).getPrimaryKey();
342
+ const wrapped = helper(data);
343
+ if (wrapped.__meta.compositePK) {
344
+ return wrapped.getPrimaryKeys();
345
+ }
346
+ return wrapped.getPrimaryKey();
454
347
  }
455
348
  if (strict && meta && Utils.getObjectKeysSize(data) !== meta.primaryKeys.length) {
456
349
  return null;
@@ -459,7 +352,7 @@ class Utils {
459
352
  if (meta.compositePK) {
460
353
  return this.getCompositeKeyValue(data, meta);
461
354
  }
462
- return data[meta.primaryKeys[0]] || data[meta.serializedPrimaryKey] || null;
355
+ return data[meta.primaryKeys[0]] ?? data[meta.serializedPrimaryKey] ?? null;
463
356
  }
464
357
  return null;
465
358
  }
@@ -498,8 +391,8 @@ class Utils {
498
391
  static splitPrimaryKeys(key) {
499
392
  return key.split(this.PK_SEPARATOR);
500
393
  }
501
- static getPrimaryKeyValues(entity, primaryKeys, allowScalar = false, convertCustomTypes = false) {
502
- /* istanbul ignore next */
394
+ static getPrimaryKeyValues(entity, meta, allowScalar = false, convertCustomTypes = false) {
395
+ /* v8 ignore next */
503
396
  if (entity == null) {
504
397
  return entity;
505
398
  }
@@ -509,15 +402,28 @@ class Utils {
509
402
  }
510
403
  return val;
511
404
  }
512
- const pk = Utils.isEntity(entity, true)
513
- ? (0, wrap_1.helper)(entity).getPrimaryKey(convertCustomTypes)
514
- : primaryKeys.reduce((o, pk) => { o[pk] = entity[pk]; return o; }, {});
515
- if (primaryKeys.length > 1) {
405
+ let pk;
406
+ if (Utils.isEntity(entity, true)) {
407
+ pk = helper(entity).getPrimaryKey(convertCustomTypes);
408
+ }
409
+ else {
410
+ pk = meta.primaryKeys.reduce((o, pk) => {
411
+ const targetMeta = meta.properties[pk].targetMeta;
412
+ if (targetMeta && Utils.isPlainObject(entity[pk])) {
413
+ o[pk] = Utils.getPrimaryKeyValues(entity[pk], targetMeta, allowScalar, convertCustomTypes);
414
+ }
415
+ else {
416
+ o[pk] = entity[pk];
417
+ }
418
+ return o;
419
+ }, {});
420
+ }
421
+ if (meta.primaryKeys.length > 1) {
516
422
  return toArray(pk);
517
423
  }
518
424
  if (allowScalar) {
519
425
  if (Utils.isPlainObject(pk)) {
520
- return pk[primaryKeys[0]];
426
+ return pk[(meta.primaryKeys)[0]];
521
427
  }
522
428
  return pk;
523
429
  }
@@ -561,7 +467,7 @@ class Utils {
561
467
  return o;
562
468
  }, {});
563
469
  }
564
- static getOrderedPrimaryKeys(id, meta, platform, convertCustomTypes = false) {
470
+ static getOrderedPrimaryKeys(id, meta, platform, convertCustomTypes = false, allowScalar = false) {
565
471
  const data = (Utils.isPrimaryKey(id) ? { [meta.primaryKeys[0]]: id } : id);
566
472
  const pks = meta.primaryKeys.map((pk, idx) => {
567
473
  const prop = meta.properties[pk];
@@ -570,12 +476,15 @@ class Utils {
570
476
  if (convertCustomTypes && platform && prop.customType && !prop.targetMeta) {
571
477
  value = prop.customType.convertToJSValue(value, platform);
572
478
  }
573
- if (prop.kind !== enums_1.ReferenceKind.SCALAR && prop.targetMeta) {
574
- const value2 = this.getOrderedPrimaryKeys(value, prop.targetMeta, platform, convertCustomTypes);
479
+ if (prop.kind !== ReferenceKind.SCALAR && prop.targetMeta) {
480
+ const value2 = this.getOrderedPrimaryKeys(value, prop.targetMeta, platform, convertCustomTypes, allowScalar);
575
481
  value = value2.length > 1 ? value2 : value2[0];
576
482
  }
577
483
  return value;
578
484
  });
485
+ if (allowScalar && pks.length === 1) {
486
+ return pks[0];
487
+ }
579
488
  // we need to flatten the PKs as composite PKs can be build from another composite PKs
580
489
  // and this method is used to get the PK hash in identity map, that expects flat array
581
490
  return Utils.flatten(pks);
@@ -598,12 +507,6 @@ class Utils {
598
507
  static isScalarReference(data, allowReference = false) {
599
508
  return typeof data === 'object' && data?.__scalarReference;
600
509
  }
601
- /**
602
- * Checks whether the argument is ObjectId instance
603
- */
604
- static isObjectID(key) {
605
- return Utils.isObject(key) && key.constructor && key.constructor.name.toLowerCase() === 'objectid';
606
- }
607
510
  /**
608
511
  * Checks whether the argument is empty (array without items, object without keys or falsy value).
609
512
  */
@@ -631,55 +534,21 @@ class Utils {
631
534
  .map(field => field === allSymbol ? allSymbol : field.substring(prefix.length + 1));
632
535
  }
633
536
  /**
634
- * Tries to detect `ts-node` runtime.
537
+ * Tries to detect TypeScript support.
635
538
  */
636
- static detectTsNode() {
637
- /* istanbul ignore next */
539
+ static detectTypeScriptSupport() {
540
+ /* v8 ignore next */
638
541
  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
542
+ || !!process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS // forced explicitly or enabled via `registerTypeScriptSupport()`
641
543
  || !!process.env.TS_JEST // check if ts-jest is used (works only with v27.0.4+)
642
544
  || !!process.env.VITEST // check if vitest is used
643
545
  || !!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
647
- }
648
- /**
649
- * Uses some dark magic to get source path to caller where decorator is used.
650
- * Analyses stack trace of error created inside the function call.
651
- */
652
- static lookupPathFromDecorator(name, stack) {
653
- // use some dark magic to get source path to caller
654
- stack = stack || new Error().stack.split('\n');
655
- // In some situations (e.g. swc 1.3.4+), the presence of a source map can obscure the call to
656
- // __decorate(), replacing it with the constructor name. To support these cases we look for
657
- // Reflect.decorate() as well. Also when babel is used, we need to check
658
- // the `_applyDecoratedDescriptor` method instead.
659
- let line = stack.findIndex(line => line.match(/__decorate|Reflect\.decorate|_applyDecoratedDescriptor/));
660
- // bun does not have those lines at all, only the DecorateProperty/DecorateConstructor,
661
- // but those are also present in node, so we need to check this only if they weren't found.
662
- if (line === -1) {
663
- // 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'));
665
- if (reflectLine === -1 || reflectLine + 2 >= stack.length || !stack[reflectLine + 1].includes('bun:wrap')) {
666
- return name;
667
- }
668
- line = reflectLine + 2;
669
- }
670
- if (stack[line].includes('Reflect.decorate')) {
671
- line++;
672
- }
673
- if (Utils.normalizePath(stack[line]).includes('node_modules/tslib/tslib')) {
674
- line++;
675
- }
676
- try {
677
- const re = stack[line].match(/\(.+\)/i) ? /\((.*):\d+:\d+\)/ : /at\s*(.*):\d+:\d+$/;
678
- return Utils.normalizePath(stack[line].match(re)[1]);
679
- }
680
- catch {
681
- return name;
682
- }
546
+ || process.argv.slice(1).some(arg => arg.match(/\.([mc]?ts|tsx)$/)) // executing `.ts` file
547
+ || process.execArgv.some(arg => {
548
+ return arg.includes('ts-node') // check for ts-node loader
549
+ || arg.includes('@swc-node/register') // check for swc-node/register loader
550
+ || arg.includes('node_modules/tsx/'); // check for tsx loader
551
+ });
683
552
  }
684
553
  /**
685
554
  * Gets the type of the argument.
@@ -690,11 +559,11 @@ class Utils {
690
559
  return simple;
691
560
  }
692
561
  const objectType = Object.prototype.toString.call(value);
693
- const type = objectType.match(/\[object (\w+)]/)[1];
562
+ const type = objectType.match(/^\[object (.+)]$/)[1];
694
563
  if (type === 'Uint8Array') {
695
564
  return 'Buffer';
696
565
  }
697
- return ['Date', 'Buffer', 'RegExp'].includes(type) ? type : type.toLowerCase();
566
+ return type;
698
567
  }
699
568
  /**
700
569
  * Checks whether the value is POJO (e.g. `{ foo: 'bar' }`, and not instance of `Foo`)
@@ -705,7 +574,7 @@ class Utils {
705
574
  && typeof value.constructor === 'function'
706
575
  && (Object.hasOwn(value.constructor.prototype, 'isPrototypeOf') || Object.getPrototypeOf(value.constructor.prototype) === null))
707
576
  || (value && Object.getPrototypeOf(value) === null)
708
- || value instanceof enums_1.PlainObject;
577
+ || value instanceof PlainObject;
709
578
  }
710
579
  /**
711
580
  * Executes the `cb` promise serially on every element of the `items` array and returns array of resolved values.
@@ -722,7 +591,7 @@ class Utils {
722
591
  }
723
592
  static fileURLToPath(url) {
724
593
  // expose `fileURLToPath` on Utils so that it can be properly mocked in tests
725
- return (0, node_url_1.fileURLToPath)(url);
594
+ return fileURLToPath(url);
726
595
  }
727
596
  /**
728
597
  * Resolves and normalizes a series of path parts relative to each preceding part.
@@ -735,7 +604,7 @@ class Utils {
735
604
  let start = 0;
736
605
  for (let i = 0; i < parts.length; i++) {
737
606
  const part = parts[i];
738
- if ((0, node_path_1.isAbsolute)(part)) {
607
+ if (isAbsolute(part)) {
739
608
  start = i;
740
609
  }
741
610
  else if (part.startsWith('file:')) {
@@ -747,7 +616,7 @@ class Utils {
747
616
  parts = parts.slice(start);
748
617
  }
749
618
  let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
750
- path = (0, node_path_1.normalize)(path).replace(/\\/g, '/');
619
+ path = normalize(path).replace(/\\/g, '/');
751
620
  return (path.match(/^[/.]|[a-zA-Z]:/) || path.startsWith('!')) ? path : './' + path;
752
621
  }
753
622
  /**
@@ -762,7 +631,7 @@ class Utils {
762
631
  if (path.startsWith('.')) {
763
632
  return path;
764
633
  }
765
- path = (0, node_path_1.relative)(Utils.normalizePath(relativeTo), path);
634
+ path = relative(Utils.normalizePath(relativeTo), path);
766
635
  return Utils.normalizePath(path);
767
636
  }
768
637
  /**
@@ -773,13 +642,19 @@ class Utils {
773
642
  if (!path) {
774
643
  return Utils.normalizePath(baseDir);
775
644
  }
776
- if (!(0, node_path_1.isAbsolute)(path) && !path.startsWith('file://')) {
645
+ if (!isAbsolute(path) && !path.startsWith('file://')) {
777
646
  path = baseDir + '/' + path;
778
647
  }
779
648
  return Utils.normalizePath(path);
780
649
  }
650
+ // FNV-1a 64-bit
781
651
  static hash(data, length) {
782
- const hash = (0, node_crypto_1.createHash)('md5').update(data).digest('hex');
652
+ let h1 = 0xcbf29ce484222325n;
653
+ for (let i = 0; i < data.length; i++) {
654
+ h1 ^= BigInt(data.charCodeAt(i));
655
+ h1 = (h1 * 0x100000001b3n) & 0xffffffffffffffffn;
656
+ }
657
+ const hash = h1.toString(16).padStart(16, '0');
783
658
  if (length) {
784
659
  return hash.substring(0, length);
785
660
  }
@@ -811,13 +686,6 @@ class Utils {
811
686
  static randomInt(min, max) {
812
687
  return Math.round(Math.random() * (max - min)) + min;
813
688
  }
814
- static async pathExists(path, options = {}) {
815
- if (globby_1.default.hasMagic(path)) {
816
- const found = await (0, globby_1.default)(path, options);
817
- return found.length > 0;
818
- }
819
- return (0, fs_extra_1.pathExistsSync)(path);
820
- }
821
689
  /**
822
690
  * Extracts all possible values of a TS enum. Works with both string and numeric enums.
823
691
  */
@@ -839,18 +707,9 @@ class Utils {
839
707
  }
840
708
  static isOperator(key, includeGroupOperators = true) {
841
709
  if (!includeGroupOperators) {
842
- return key in enums_1.QueryOperator;
710
+ return key in QueryOperator;
843
711
  }
844
- return key in enums_1.GroupOperator || key in enums_1.QueryOperator;
845
- }
846
- static isGroupOperator(key) {
847
- return key in enums_1.GroupOperator;
848
- }
849
- static isArrayOperator(key) {
850
- return enums_1.ARRAY_OPERATORS.includes(key);
851
- }
852
- static isJsonKeyOperator(key) {
853
- return enums_1.JSON_KEY_OPERATORS.includes(key);
712
+ return key in GroupOperator || key in QueryOperator;
854
713
  }
855
714
  static hasNestedKey(object, key) {
856
715
  if (!object) {
@@ -864,60 +723,18 @@ class Utils {
864
723
  }
865
724
  return false;
866
725
  }
867
- static getGlobalStorage(namespace) {
868
- const key = `mikro-orm-${namespace}`;
869
- globalThis[key] = globalThis[key] || {};
870
- return globalThis[key];
871
- }
872
- /**
873
- * Require a module from a specific location
874
- * @param id The module to require
875
- * @param [from] Location to start the node resolution
876
- */
877
- static requireFrom(id, from = process.cwd()) {
878
- if (!(0, node_path_1.extname)(from)) {
879
- from = (0, node_path_1.join)(from, '__fake.js');
880
- }
881
- return (0, node_module_1.createRequire)((0, node_path_1.resolve)(from))(id);
882
- }
883
726
  static async dynamicImport(id) {
884
- /* istanbul ignore next */
885
- if ((0, node_os_1.platform)() === 'win32') {
886
- try {
887
- id = (0, node_url_1.pathToFileURL)(id).toString();
888
- }
889
- catch {
890
- // ignore
891
- }
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
- }
897
- /* istanbul ignore next */
898
- return this.dynamicImportProvider(id);
899
- }
900
- /* istanbul ignore next */
901
- static setDynamicImportProvider(provider) {
902
- this.dynamicImportProvider = provider;
727
+ /* v8 ignore next */
728
+ const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;
729
+ return this.dynamicImportProvider(specifier);
903
730
  }
904
731
  static getORMVersion() {
905
- /* istanbul ignore next */
906
- 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;
910
- }
911
- 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;
915
- }
732
+ return this.#ORM_VERSION;
916
733
  }
917
- /* istanbul ignore next */
918
734
  static createFunction(context, code) {
919
735
  try {
920
736
  return new Function(...context.keys(), `'use strict';\n` + code)(...context.values());
737
+ /* v8 ignore next */
921
738
  }
922
739
  catch (e) {
923
740
  // eslint-disable-next-line no-console
@@ -925,12 +742,12 @@ class Utils {
925
742
  throw e;
926
743
  }
927
744
  }
928
- /* istanbul ignore next */
929
745
  static callCompiledFunction(fn, ...args) {
930
746
  try {
931
747
  return fn(...args);
932
748
  }
933
749
  catch (e) {
750
+ /* v8 ignore next */
934
751
  if ([SyntaxError, TypeError, EvalError, ReferenceError].some(t => e instanceof t)) {
935
752
  const position = e.stack.match(/<anonymous>:(\d+):(\d+)/);
936
753
  let code = fn.toString();
@@ -950,14 +767,6 @@ class Utils {
950
767
  throw e;
951
768
  }
952
769
  }
953
- /**
954
- * @see https://github.com/mikro-orm/mikro-orm/issues/840
955
- */
956
- static propertyDecoratorReturnValue() {
957
- if (process.env.BABEL_DECORATORS_COMPAT) {
958
- return {};
959
- }
960
- }
961
770
  static unwrapProperty(entity, meta, prop, payload = false) {
962
771
  let p = prop;
963
772
  const path = [];
@@ -1037,44 +846,21 @@ class Utils {
1037
846
  }
1038
847
  }
1039
848
  }
1040
- static tryRequire({ module, from, allowError, warning }) {
1041
- allowError ??= `Cannot find module '${module}'`;
1042
- from ??= process.cwd();
849
+ static async tryImport({ module, warning }) {
1043
850
  try {
1044
- return Utils.requireFrom(module, from);
851
+ return await import(module);
1045
852
  }
1046
853
  catch (err) {
1047
- if (err.message.includes(allowError)) {
1048
- // eslint-disable-next-line no-console
1049
- console.warn(warning);
854
+ if (err.code === 'ERR_MODULE_NOT_FOUND') {
855
+ if (warning) {
856
+ // eslint-disable-next-line no-console
857
+ console.warn(warning);
858
+ }
1050
859
  return undefined;
1051
860
  }
1052
861
  throw err;
1053
862
  }
1054
863
  }
1055
- static stripRelativePath(str) {
1056
- return str.replace(/^(?:\.\.\/|\.\/)+/, '/');
1057
- }
1058
- /**
1059
- * simple process.argv parser, supports only properties with long names, prefixed with `--`
1060
- */
1061
- static parseArgs() {
1062
- let lastKey;
1063
- return process.argv.slice(2).reduce((args, arg) => {
1064
- if (arg.includes('=')) {
1065
- const [key, value] = arg.split('=');
1066
- args[key.substring(2)] = value;
1067
- }
1068
- else if (lastKey) {
1069
- args[lastKey] = arg;
1070
- lastKey = undefined;
1071
- }
1072
- else if (arg.startsWith('--')) {
1073
- lastKey = arg.substring(2);
1074
- }
1075
- return args;
1076
- }, {});
1077
- }
1078
864
  static xor(a, b) {
1079
865
  return (a || b) && !(a && b);
1080
866
  }
@@ -1087,9 +873,6 @@ class Utils {
1087
873
  static entries(obj) {
1088
874
  return Object.entries(obj);
1089
875
  }
1090
- static isRawSql(value) {
1091
- return isRawSql(value);
1092
- }
1093
876
  static primaryKeyToObject(meta, primaryKey, visible) {
1094
877
  const pks = meta.compositePK && Utils.isPlainObject(primaryKey) ? Object.values(primaryKey) : Utils.asArray(primaryKey);
1095
878
  const pkProps = meta.getPrimaryProps();
@@ -1107,4 +890,3 @@ class Utils {
1107
890
  }, {});
1108
891
  }
1109
892
  }
1110
- exports.Utils = Utils;