@mikro-orm/core 7.0.0-dev.32 → 7.0.0-dev.321

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 (216) hide show
  1. package/EntityManager.d.ts +71 -63
  2. package/EntityManager.js +365 -283
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +109 -142
  5. package/README.md +7 -4
  6. package/cache/FileCacheAdapter.d.ts +1 -2
  7. package/cache/FileCacheAdapter.js +19 -14
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +1 -2
  11. package/cache/index.js +0 -2
  12. package/connections/Connection.d.ts +12 -5
  13. package/connections/Connection.js +37 -15
  14. package/drivers/DatabaseDriver.d.ts +25 -18
  15. package/drivers/DatabaseDriver.js +144 -45
  16. package/drivers/IDatabaseDriver.d.ts +118 -23
  17. package/entity/BaseEntity.d.ts +63 -4
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +101 -29
  20. package/entity/Collection.js +473 -115
  21. package/entity/EntityAssigner.js +37 -25
  22. package/entity/EntityFactory.d.ts +7 -1
  23. package/entity/EntityFactory.js +116 -64
  24. package/entity/EntityHelper.d.ts +2 -2
  25. package/entity/EntityHelper.js +69 -27
  26. package/entity/EntityLoader.d.ts +11 -10
  27. package/entity/EntityLoader.js +264 -102
  28. package/entity/EntityRepository.d.ts +28 -8
  29. package/entity/EntityRepository.js +8 -2
  30. package/entity/PolymorphicRef.d.ts +12 -0
  31. package/entity/PolymorphicRef.js +18 -0
  32. package/entity/Reference.d.ts +2 -6
  33. package/entity/Reference.js +52 -19
  34. package/entity/WrappedEntity.d.ts +3 -8
  35. package/entity/WrappedEntity.js +6 -7
  36. package/entity/defineEntity.d.ts +525 -311
  37. package/entity/defineEntity.js +134 -290
  38. package/entity/index.d.ts +2 -2
  39. package/entity/index.js +2 -2
  40. package/entity/utils.d.ts +6 -1
  41. package/entity/utils.js +46 -11
  42. package/entity/validators.d.ts +11 -0
  43. package/entity/validators.js +66 -0
  44. package/enums.d.ts +8 -6
  45. package/enums.js +13 -17
  46. package/errors.d.ts +20 -10
  47. package/errors.js +63 -31
  48. package/events/EventManager.d.ts +2 -1
  49. package/events/EventManager.js +24 -13
  50. package/events/index.d.ts +1 -1
  51. package/events/index.js +0 -1
  52. package/exceptions.js +9 -2
  53. package/hydration/Hydrator.js +1 -2
  54. package/hydration/ObjectHydrator.d.ts +4 -4
  55. package/hydration/ObjectHydrator.js +105 -46
  56. package/index.d.ts +2 -2
  57. package/index.js +1 -2
  58. package/logging/DefaultLogger.d.ts +1 -1
  59. package/logging/DefaultLogger.js +3 -4
  60. package/logging/SimpleLogger.d.ts +1 -1
  61. package/logging/colors.d.ts +1 -1
  62. package/logging/colors.js +5 -7
  63. package/logging/index.d.ts +2 -1
  64. package/logging/index.js +1 -1
  65. package/logging/inspect.d.ts +2 -0
  66. package/logging/inspect.js +11 -0
  67. package/metadata/EntitySchema.d.ts +47 -23
  68. package/metadata/EntitySchema.js +103 -34
  69. package/metadata/MetadataDiscovery.d.ts +64 -9
  70. package/metadata/MetadataDiscovery.js +867 -354
  71. package/metadata/MetadataProvider.d.ts +11 -2
  72. package/metadata/MetadataProvider.js +71 -2
  73. package/metadata/MetadataStorage.d.ts +13 -11
  74. package/metadata/MetadataStorage.js +72 -41
  75. package/metadata/MetadataValidator.d.ts +32 -9
  76. package/metadata/MetadataValidator.js +214 -44
  77. package/metadata/discover-entities.d.ts +5 -0
  78. package/metadata/discover-entities.js +40 -0
  79. package/metadata/index.d.ts +1 -1
  80. package/metadata/index.js +0 -1
  81. package/metadata/types.d.ts +577 -0
  82. package/metadata/types.js +1 -0
  83. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  84. package/naming-strategy/AbstractNamingStrategy.js +26 -5
  85. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  86. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  87. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/MongoNamingStrategy.js +6 -6
  89. package/naming-strategy/NamingStrategy.d.ts +28 -4
  90. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  91. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  92. package/naming-strategy/index.d.ts +1 -1
  93. package/naming-strategy/index.js +0 -1
  94. package/not-supported.d.ts +2 -0
  95. package/not-supported.js +8 -0
  96. package/package.json +47 -36
  97. package/platforms/ExceptionConverter.js +1 -1
  98. package/platforms/Platform.d.ts +33 -15
  99. package/platforms/Platform.js +125 -69
  100. package/serialization/EntitySerializer.d.ts +6 -3
  101. package/serialization/EntitySerializer.js +53 -29
  102. package/serialization/EntityTransformer.js +33 -21
  103. package/serialization/SerializationContext.d.ts +6 -6
  104. package/serialization/SerializationContext.js +4 -4
  105. package/types/ArrayType.d.ts +1 -1
  106. package/types/ArrayType.js +2 -3
  107. package/types/BigIntType.js +1 -1
  108. package/types/BlobType.d.ts +0 -1
  109. package/types/BlobType.js +0 -3
  110. package/types/BooleanType.d.ts +1 -0
  111. package/types/BooleanType.js +3 -0
  112. package/types/DecimalType.js +2 -2
  113. package/types/DoubleType.js +1 -1
  114. package/types/EnumArrayType.js +1 -2
  115. package/types/JsonType.d.ts +1 -1
  116. package/types/JsonType.js +7 -2
  117. package/types/TinyIntType.js +1 -1
  118. package/types/Type.d.ts +2 -4
  119. package/types/Type.js +3 -3
  120. package/types/Uint8ArrayType.d.ts +0 -1
  121. package/types/Uint8ArrayType.js +1 -4
  122. package/types/UuidType.d.ts +2 -0
  123. package/types/UuidType.js +14 -2
  124. package/types/index.d.ts +3 -2
  125. package/typings.d.ts +427 -170
  126. package/typings.js +100 -45
  127. package/unit-of-work/ChangeSet.d.ts +4 -6
  128. package/unit-of-work/ChangeSet.js +8 -9
  129. package/unit-of-work/ChangeSetComputer.d.ts +3 -8
  130. package/unit-of-work/ChangeSetComputer.js +49 -26
  131. package/unit-of-work/ChangeSetPersister.d.ts +13 -12
  132. package/unit-of-work/ChangeSetPersister.js +107 -44
  133. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  134. package/unit-of-work/CommitOrderCalculator.js +17 -15
  135. package/unit-of-work/IdentityMap.d.ts +12 -0
  136. package/unit-of-work/IdentityMap.js +39 -1
  137. package/unit-of-work/UnitOfWork.d.ts +34 -4
  138. package/unit-of-work/UnitOfWork.js +294 -107
  139. package/utils/AbstractMigrator.d.ts +101 -0
  140. package/utils/AbstractMigrator.js +303 -0
  141. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  142. package/utils/AbstractSchemaGenerator.js +30 -18
  143. package/utils/AsyncContext.d.ts +6 -0
  144. package/utils/AsyncContext.js +42 -0
  145. package/utils/Configuration.d.ts +796 -211
  146. package/utils/Configuration.js +160 -197
  147. package/utils/ConfigurationLoader.d.ts +1 -52
  148. package/utils/ConfigurationLoader.js +1 -330
  149. package/utils/Cursor.d.ts +0 -3
  150. package/utils/Cursor.js +29 -14
  151. package/utils/DataloaderUtils.d.ts +10 -5
  152. package/utils/DataloaderUtils.js +42 -22
  153. package/utils/EntityComparator.d.ts +16 -9
  154. package/utils/EntityComparator.js +202 -96
  155. package/utils/QueryHelper.d.ts +34 -7
  156. package/utils/QueryHelper.js +183 -72
  157. package/utils/RawQueryFragment.d.ts +28 -34
  158. package/utils/RawQueryFragment.js +37 -72
  159. package/utils/RequestContext.js +2 -2
  160. package/utils/TransactionContext.js +2 -2
  161. package/utils/TransactionManager.js +11 -7
  162. package/utils/Utils.d.ts +16 -127
  163. package/utils/Utils.js +106 -401
  164. package/utils/clone.js +13 -23
  165. package/utils/env-vars.d.ts +7 -0
  166. package/utils/env-vars.js +98 -0
  167. package/utils/fs-utils.d.ts +34 -0
  168. package/utils/fs-utils.js +193 -0
  169. package/utils/index.d.ts +1 -3
  170. package/utils/index.js +1 -3
  171. package/utils/upsert-utils.d.ts +9 -4
  172. package/utils/upsert-utils.js +51 -5
  173. package/decorators/Check.d.ts +0 -3
  174. package/decorators/Check.js +0 -13
  175. package/decorators/CreateRequestContext.d.ts +0 -3
  176. package/decorators/CreateRequestContext.js +0 -32
  177. package/decorators/Embeddable.d.ts +0 -8
  178. package/decorators/Embeddable.js +0 -11
  179. package/decorators/Embedded.d.ts +0 -12
  180. package/decorators/Embedded.js +0 -18
  181. package/decorators/Entity.d.ts +0 -33
  182. package/decorators/Entity.js +0 -12
  183. package/decorators/Enum.d.ts +0 -9
  184. package/decorators/Enum.js +0 -16
  185. package/decorators/Filter.d.ts +0 -2
  186. package/decorators/Filter.js +0 -8
  187. package/decorators/Formula.d.ts +0 -4
  188. package/decorators/Formula.js +0 -15
  189. package/decorators/Indexed.d.ts +0 -19
  190. package/decorators/Indexed.js +0 -20
  191. package/decorators/ManyToMany.d.ts +0 -42
  192. package/decorators/ManyToMany.js +0 -14
  193. package/decorators/ManyToOne.d.ts +0 -34
  194. package/decorators/ManyToOne.js +0 -14
  195. package/decorators/OneToMany.d.ts +0 -28
  196. package/decorators/OneToMany.js +0 -17
  197. package/decorators/OneToOne.d.ts +0 -28
  198. package/decorators/OneToOne.js +0 -7
  199. package/decorators/PrimaryKey.d.ts +0 -8
  200. package/decorators/PrimaryKey.js +0 -20
  201. package/decorators/Property.d.ts +0 -250
  202. package/decorators/Property.js +0 -32
  203. package/decorators/Transactional.d.ts +0 -14
  204. package/decorators/Transactional.js +0 -28
  205. package/decorators/hooks.d.ts +0 -16
  206. package/decorators/hooks.js +0 -47
  207. package/decorators/index.d.ts +0 -17
  208. package/decorators/index.js +0 -17
  209. package/entity/ArrayCollection.d.ts +0 -118
  210. package/entity/ArrayCollection.js +0 -407
  211. package/entity/EntityValidator.d.ts +0 -19
  212. package/entity/EntityValidator.js +0 -150
  213. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  214. package/metadata/ReflectMetadataProvider.js +0 -44
  215. package/utils/resolveContextProvider.d.ts +0 -10
  216. package/utils/resolveContextProvider.js +0 -28
@@ -1,99 +1,65 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
2
- import { inspect } from 'node:util';
3
1
  import { Utils } from './Utils.js';
4
2
  export class RawQueryFragment {
5
3
  sql;
6
4
  params;
7
- static #rawQueryCache = new Map();
8
- static #storage = new AsyncLocalStorage();
9
- static #index = 0n;
10
- static cloneRegistry;
11
- #assigned = false;
12
- #used = 0;
5
+ static #rawQueryReferences = new WeakMap();
13
6
  #key;
14
7
  constructor(sql, params = []) {
15
8
  this.sql = sql;
16
9
  this.params = params;
17
- this.#key = `[raw]: ${this.sql} (#${RawQueryFragment.#index++})`;
18
10
  }
19
- as(alias) {
20
- // TODO: to be removed in v7
21
- /* v8 ignore next 3 */
22
- if (alias.startsWith('`') || alias.startsWith('"')) {
23
- return new RawQueryFragment(`${this.sql} as ${alias}`, this.params);
11
+ get key() {
12
+ if (!this.#key) {
13
+ this.#key = Symbol(this.toJSON());
14
+ RawQueryFragment.#rawQueryReferences.set(this.#key, this);
24
15
  }
16
+ return this.#key;
17
+ }
18
+ as(alias) {
25
19
  return new RawQueryFragment(`${this.sql} as ??`, [...this.params, alias]);
26
20
  }
27
- valueOf() {
21
+ [Symbol.toPrimitive](hint) {
22
+ // if a fragment is converted to string (used as an object key), return a unique symbol
23
+ // and save a weak reference to map so we can retrieve it when compiling the query
24
+ if (hint === 'string') {
25
+ return this.key;
26
+ }
28
27
  throw new Error(`Trying to modify raw SQL fragment: '${this.sql}'`);
29
28
  }
29
+ get [Symbol.toStringTag]() {
30
+ return this.toJSON();
31
+ }
30
32
  toJSON() {
31
- return this.#key;
33
+ return `raw('${this.sql}')`;
32
34
  }
33
- toString() {
34
- RawQueryFragment.#rawQueryCache.set(this.#key, this);
35
- this.#used++;
36
- return this.#key;
35
+ clone() {
36
+ return this;
37
37
  }
38
- /** @internal */
39
- assign() {
40
- if (this.#assigned) {
41
- throw new Error(`Cannot reassign already used RawQueryFragment: '${this.sql}'`);
42
- }
43
- this.#assigned = true;
38
+ static isKnownFragmentSymbol(key) {
39
+ return typeof key === 'symbol' && this.#rawQueryReferences.has(key);
44
40
  }
45
- clone() {
46
- RawQueryFragment.cloneRegistry?.add(this.#key);
47
- return new RawQueryFragment(this.sql, this.params);
48
- }
49
- static async run(cb) {
50
- const removeStack = new Set();
51
- const res = await this.#storage.run(removeStack, cb);
52
- removeStack.forEach(key => RawQueryFragment.remove(key));
53
- removeStack.clear();
54
- return res;
55
- }
56
- /**
57
- * @internal allows testing we don't leak memory, as the raw fragments cache needs to be cleared automatically
58
- */
59
- static checkCacheSize() {
60
- return this.#rawQueryCache.size;
41
+ static hasObjectFragments(object) {
42
+ return (Utils.isPlainObject(object) &&
43
+ Object.getOwnPropertySymbols(object).some(symbol => this.isKnownFragmentSymbol(symbol)));
61
44
  }
62
45
  static isKnownFragment(key) {
63
46
  if (key instanceof RawQueryFragment) {
64
47
  return true;
65
48
  }
66
- return this.#rawQueryCache.has(key);
49
+ return this.isKnownFragmentSymbol(key);
67
50
  }
68
- static getKnownFragment(key, cleanup = true) {
51
+ static getKnownFragment(key) {
69
52
  if (key instanceof RawQueryFragment) {
70
53
  return key;
71
54
  }
72
- const raw = this.#rawQueryCache.get(key);
73
- if (raw && cleanup) {
74
- this.remove(key);
75
- }
76
- return raw;
77
- }
78
- static remove(key) {
79
- const raw = this.#rawQueryCache.get(key);
80
- if (!raw) {
55
+ if (typeof key !== 'symbol') {
81
56
  return;
82
57
  }
83
- raw.#used--;
84
- if (raw.#used <= 0) {
85
- const removeStack = this.#storage.getStore();
86
- if (removeStack) {
87
- removeStack.add(key);
88
- }
89
- else {
90
- this.#rawQueryCache.delete(key);
91
- }
92
- }
58
+ return this.#rawQueryReferences.get(key);
93
59
  }
94
- /* v8 ignore next 8 */
95
60
  /** @ignore */
96
- [inspect.custom]() {
61
+ /* v8 ignore next */
62
+ [Symbol.for('nodejs.util.inspect.custom')]() {
97
63
  if (this.params) {
98
64
  return { sql: this.sql, params: this.params };
99
65
  }
@@ -204,20 +170,19 @@ export function raw(sql, params) {
204
170
  *
205
171
  * // value can be empty array
206
172
  * await em.find(User, { [sql`(select 1 = 1)`]: [] });
173
+ *
174
+ * // with type parameter for assignment without casting
175
+ * entity.date = sql<Date>`now()`;
207
176
  * ```
208
177
  */
209
178
  export function sql(sql, ...values) {
210
- return raw(sql.reduce((query, queryPart, i) => {
211
- const valueExists = i < values.length;
212
- const text = query + queryPart;
213
- return valueExists ? text + '?' : text;
214
- }, ''), values);
179
+ return raw(sql.join('?'), values);
215
180
  }
216
181
  export function createSqlFunction(func, key) {
217
182
  if (typeof key === 'string') {
218
183
  return raw(`${func}(${key})`);
219
184
  }
220
- return raw(a => `${func}(${(key(a))})`);
185
+ return raw(a => `${func}(${key(a)})`);
221
186
  }
222
187
  sql.ref = (...keys) => raw('??', [keys.join('.')]);
223
188
  sql.now = (length) => raw('current_timestamp' + (length == null ? '' : `(${length})`));
@@ -231,7 +196,7 @@ sql.upper = (key) => createSqlFunction('upper', key);
231
196
  * ```ts
232
197
  * // On postgres, will produce: create index "index custom_idx_on_name" on "library.author" ("name")
233
198
  * // On mysql, will produce: create index `index custom_idx_on_name` on `library.author` (`name`)
234
- * @Index({ name: 'custom_idx_on_name', expression: (table, columns) => quote`create index ${'custom_idx_on_name'} on ${table} (${columns.name})` })
199
+ * @Index({ name: 'custom_idx_on_name', expression: (table, columns, indexName) => quote`create index ${indexName} on ${table} (${columns.name})` })
235
200
  * @Entity({ schema: 'library' })
236
201
  * export class Author { ... }
237
202
  * ```
@@ -1,10 +1,10 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
1
+ import { createAsyncContext } from './AsyncContext.js';
2
2
  /**
3
3
  * Uses `AsyncLocalStorage` to create async context that holds the current EM fork.
4
4
  */
5
5
  export class RequestContext {
6
6
  map;
7
- static storage = new AsyncLocalStorage();
7
+ static storage = createAsyncContext();
8
8
  static counter = 1;
9
9
  id = RequestContext.counter++;
10
10
  constructor(map) {
@@ -1,7 +1,7 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks';
1
+ import { createAsyncContext } from './AsyncContext.js';
2
2
  export class TransactionContext {
3
3
  em;
4
- static storage = new AsyncLocalStorage();
4
+ static storage = createAsyncContext();
5
5
  id;
6
6
  constructor(em) {
7
7
  this.em = em;
@@ -1,4 +1,4 @@
1
- import { TransactionPropagation } from '../enums.js';
1
+ import { ReferenceKind, TransactionPropagation } from '../enums.js';
2
2
  import { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster.js';
3
3
  import { TransactionContext } from '../utils/TransactionContext.js';
4
4
  import { ChangeSetType } from '../unit-of-work/ChangeSet.js';
@@ -17,9 +17,7 @@ export class TransactionManager {
17
17
  */
18
18
  async handle(cb, options = {}) {
19
19
  const em = this.em.getContext(false);
20
- // Set NESTED as the default propagation type
21
20
  options.propagation ??= TransactionPropagation.NESTED;
22
- // Set the context to the current transaction context if not already set
23
21
  options.ctx ??= em.getTransactionContext();
24
22
  const hasExistingTransaction = !!em.getTransactionContext();
25
23
  return this.executeWithPropagation(options.propagation, em, cb, options, hasExistingTransaction);
@@ -163,11 +161,16 @@ export class TransactionManager {
163
161
  const wrapped = helper(entity);
164
162
  const meta = wrapped.__meta;
165
163
  // eslint-disable-next-line dot-notation
166
- const parentEntity = parentUoW.getById(meta.className, wrapped.getPrimaryKey(), parent['_schema'], true);
164
+ const parentEntity = parentUoW.getById(meta.class, wrapped.getPrimaryKey(), parent['_schema'], true);
167
165
  if (parentEntity && parentEntity !== entity) {
168
166
  const parentWrapped = helper(parentEntity);
169
- parentWrapped.__data = helper(entity).__data;
170
- parentWrapped.__originalEntityData = helper(entity).__originalEntityData;
167
+ parentWrapped.__data = wrapped.__data;
168
+ parentWrapped.__originalEntityData = wrapped.__originalEntityData;
169
+ for (const prop of meta.hydrateProps) {
170
+ if (prop.kind === ReferenceKind.SCALAR) {
171
+ parentEntity[prop.name] = entity[prop.name];
172
+ }
173
+ }
171
174
  }
172
175
  else {
173
176
  parentUoW.merge(entity, new Set([entity]));
@@ -180,7 +183,8 @@ export class TransactionManager {
180
183
  registerDeletionHandler(fork, parent) {
181
184
  fork.getEventManager().registerSubscriber({
182
185
  afterFlush: (args) => {
183
- const deletionChangeSets = args.uow.getChangeSets()
186
+ const deletionChangeSets = args.uow
187
+ .getChangeSets()
184
188
  .filter(cs => cs.type === ChangeSetType.DELETE || cs.type === ChangeSetType.DELETE_EARLY);
185
189
  for (const cs of deletionChangeSets) {
186
190
  parent.getUnitOfWork(false).unsetIdentity(cs.entity);
package/utils/Utils.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { type GlobOptions } from 'tinyglobby';
2
- import type { Dictionary, EntityData, EntityDictionary, EntityKey, EntityMetadata, EntityName, EntityProperty, IMetadataStorage, Primary } from '../typings.js';
1
+ import type { CompiledFunctions, Dictionary, EntityData, EntityDictionary, EntityKey, EntityMetadata, EntityName, EntityProperty, Primary } from '../typings.js';
3
2
  import type { Collection } from '../entity/Collection.js';
4
3
  import type { Platform } from '../platforms/Platform.js';
5
- import type { ScalarReference } from '../entity/Reference.js';
6
- export declare const ObjectBindingPattern: unique symbol;
4
+ import { type ScalarReference } from '../entity/Reference.js';
5
+ import { type RawQueryFragmentSymbol } from './RawQueryFragment.js';
7
6
  export declare function compareObjects(a: any, b: any): boolean;
8
7
  export declare function compareArrays(a: any[] | string, b: any[] | string): boolean;
9
8
  export declare function compareBooleans(a: unknown, b: unknown): boolean;
@@ -14,33 +13,16 @@ export declare function compareBuffers(a: Uint8Array, b: Uint8Array): boolean;
14
13
  export declare function equals(a: any, b: any): boolean;
15
14
  export declare function parseJsonSafe<T = unknown>(value: unknown): T;
16
15
  export declare class Utils {
16
+ #private;
17
17
  static readonly PK_SEPARATOR = "~~~";
18
- /**
19
- * Checks if the argument is not undefined
20
- */
21
- static isDefined<T = Record<string, unknown>>(data: any): data is T;
22
18
  /**
23
19
  * Checks if the argument is instance of `Object`. Returns false for arrays.
24
20
  */
25
21
  static isObject<T = Dictionary>(o: any): o is T;
26
- /**
27
- * Relation decorators allow using two signatures
28
- * - using first parameter as options object
29
- * - using all parameters
30
- *
31
- * This function validates those two ways are not mixed and returns the final options object.
32
- * If the second way is used, we always consider the last parameter as options object.
33
- * @internal
34
- */
35
- static processDecoratorParameters<T>(params: Dictionary): T;
36
- /**
37
- * Checks if the argument is instance of `Object`, but not one of the blacklisted types. Returns false for arrays.
38
- */
39
- static isNotObject<T = Dictionary>(o: any, not: any[]): o is T;
40
22
  /**
41
23
  * Removes `undefined` properties (recursively) so they are not saved as nulls
42
24
  */
43
- static dropUndefinedProperties<T = Dictionary | unknown[]>(o: any, value?: undefined | null, visited?: Set<unknown>): void;
25
+ static dropUndefinedProperties(o: any, value?: null, visited?: Set<unknown>): void;
44
26
  /**
45
27
  * Returns the number of properties on `obj`. This is 20x faster than Object.keys(obj).length.
46
28
  * @see https://github.com/deepkit/deepkit-framework/blob/master/packages/core/src/core.ts
@@ -51,14 +33,6 @@ export declare class Utils {
51
33
  * @see https://github.com/deepkit/deepkit-framework/blob/master/packages/core/src/core.ts
52
34
  */
53
35
  static hasObjectKeys(object: Dictionary): boolean;
54
- /**
55
- * Checks if the argument is string
56
- */
57
- static isString(s: any): s is string;
58
- /**
59
- * Checks if the argument is number
60
- */
61
- static isNumber<T = number>(s: any): s is T;
62
36
  /**
63
37
  * Checks if arguments are deeply (but not strictly) equal.
64
38
  */
@@ -79,11 +53,6 @@ export declare class Utils {
79
53
  * Merges all sources into the target recursively.
80
54
  */
81
55
  private static _merge;
82
- static getRootEntity(metadata: IMetadataStorage, meta: EntityMetadata): EntityMetadata;
83
- /**
84
- * Computes difference between two objects, ignoring items missing in `b`.
85
- */
86
- static diff(a: Dictionary, b: Dictionary): Record<keyof (typeof a & typeof b), any>;
87
56
  /**
88
57
  * Creates deep copy of given object.
89
58
  */
@@ -101,26 +70,11 @@ export declare class Utils {
101
70
  */
102
71
  static renameKey<T>(payload: T, from: string | keyof T, to: string): void;
103
72
  /**
104
- * Returns array of functions argument names. Uses `esprima` for source code analysis.
105
- */
106
- static tokenize(func: {
107
- toString(): string;
108
- } | string | {
109
- type: string;
110
- value: string;
111
- }[]): {
112
- type: string;
113
- value: string;
114
- }[];
115
- /**
116
- * Returns array of functions argument names. Uses `esprima` for source code analysis.
73
+ * Returns array of functions argument names. Uses basic regex for source code analysis, might not work with advanced syntax.
117
74
  */
118
- static getParamNames(func: {
75
+ static getConstructorParams(func: {
119
76
  toString(): string;
120
- } | string | {
121
- type: string;
122
- value: string;
123
- }[], methodName?: string): string[];
77
+ }): string[] | undefined;
124
78
  /**
125
79
  * Checks whether the argument looks like primary key (string, number or ObjectId).
126
80
  */
@@ -133,7 +87,7 @@ export declare class Utils {
133
87
  static getCompositeKeyHash<T>(data: EntityData<T>, meta: EntityMetadata<T>, convertCustomTypes?: boolean, platform?: Platform, flat?: boolean): string;
134
88
  static getPrimaryKeyHash(pks: (string | Buffer | Date)[]): string;
135
89
  static splitPrimaryKeys<T extends object>(key: string): EntityKey<T>[];
136
- static getPrimaryKeyValues<T>(entity: T, primaryKeys: string[] | EntityMetadata<T>, allowScalar?: boolean, convertCustomTypes?: boolean): any;
90
+ static getPrimaryKeyValues<T>(entity: T, meta: EntityMetadata<T>, allowScalar?: boolean, convertCustomTypes?: boolean): any;
137
91
  static getPrimaryKeyCond<T>(entity: T, primaryKeys: EntityKey<T>[]): Record<string, Primary<T>> | null;
138
92
  /**
139
93
  * Maps nested FKs from `[1, 2, 3]` to `[1, [2, 3]]`.
@@ -149,12 +103,6 @@ export declare class Utils {
149
103
  * Checks whether given object is a scalar reference.
150
104
  */
151
105
  static isScalarReference<T = unknown>(data: any, allowReference?: boolean): data is ScalarReference<any> & {};
152
- /**
153
- * Checks whether the argument is ObjectId instance
154
- */
155
- static isObjectID(key: any): key is {
156
- toHexString: () => string;
157
- };
158
106
  /**
159
107
  * Checks whether the argument is empty (array without items, object without keys or falsy value).
160
108
  */
@@ -162,17 +110,12 @@ export declare class Utils {
162
110
  /**
163
111
  * Gets string name of given class.
164
112
  */
165
- static className<T>(classOrName: EntityName<T>): string;
113
+ static className<T>(classOrName: string | EntityName<T>): string;
166
114
  static extractChildElements(items: string[], prefix: string, allSymbol?: string): string[];
167
115
  /**
168
116
  * Tries to detect TypeScript support.
169
117
  */
170
118
  static detectTypeScriptSupport(): boolean;
171
- /**
172
- * Uses some dark magic to get source path to caller where decorator is used.
173
- * Analyses stack trace of error created inside the function call.
174
- */
175
- static lookupPathFromDecorator(name: string, stack?: string[]): string;
176
119
  /**
177
120
  * Gets the type of the argument.
178
121
  */
@@ -186,86 +129,32 @@ export declare class Utils {
186
129
  */
187
130
  static runSerial<T = any, U = any>(items: Iterable<U>, cb: (item: U) => Promise<T>): Promise<T[]>;
188
131
  static isCollection<T extends object, O extends object = object>(item: any): item is Collection<T, O>;
189
- static fileURLToPath(url: string | URL): string;
190
- /**
191
- * Resolves and normalizes a series of path parts relative to each preceding part.
192
- * If any part is a `file:` URL, it is converted to a local path. If any part is an
193
- * absolute path, it replaces preceding paths (similar to `path.resolve` in NodeJS).
194
- * Trailing directory separators are removed, and all directory separators are converted
195
- * to POSIX-style separators (`/`).
196
- */
197
- static normalizePath(...parts: string[]): string;
198
- /**
199
- * Determines the relative path between two paths. If either path is a `file:` URL,
200
- * it is converted to a local path.
201
- */
202
- static relativePath(path: string, relativeTo: string): string;
203
- /**
204
- * Computes the absolute path to for the given path relative to the provided base directory.
205
- * If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
206
- */
207
- static absolutePath(path: string, baseDir?: string): string;
208
- static hash(data: string, length?: number, algorithm?: 'md5' | 'sha256'): string;
132
+ static hash(data: string, length?: number): string;
209
133
  static runIfNotEmpty(clause: () => any, data: any): void;
210
134
  static defaultValue<T extends Dictionary>(prop: T, option: keyof T, defaultValue: any): void;
211
135
  static findDuplicates<T>(items: T[]): T[];
212
136
  static removeDuplicates<T>(items: T[]): T[];
213
137
  static randomInt(min: number, max: number): number;
214
- static pathExists(path: string, options?: GlobOptions): Promise<boolean>;
215
138
  /**
216
139
  * Extracts all possible values of a TS enum. Works with both string and numeric enums.
217
140
  */
218
141
  static extractEnumValues(target: Dictionary): (string | number)[];
219
- static flatten<T>(arrays: T[][]): T[];
142
+ static flatten<T>(arrays: T[][], deep?: boolean): T[];
220
143
  static isOperator(key: PropertyKey, includeGroupOperators?: boolean): boolean;
221
- static isGroupOperator(key: PropertyKey): boolean;
222
- static isArrayOperator(key: PropertyKey): boolean;
223
- static isJsonKeyOperator(key: PropertyKey): boolean;
224
144
  static hasNestedKey(object: unknown, key: string): boolean;
225
- static getGlobalStorage(namespace: string): Dictionary;
226
- /**
227
- * Require a module from a specific location
228
- * @param id The module to require
229
- * @param [from] Location to start the node resolution
230
- */
231
- static requireFrom<T extends Dictionary>(id: string, from?: string): T;
232
- /**
233
- * Resolve path to a module.
234
- * @param id The module to require
235
- * @param [from] Location to start the node resolution
236
- */
237
- static resolveModulePath(id: string, from?: string): string;
238
- static dynamicImport<T = any>(id: string): Promise<T>;
239
- static ensureDir(path: string): void;
240
- static pathExistsSync(path: string): boolean;
241
- static readJSONSync(path: string): Dictionary;
242
145
  static getORMVersion(): string;
243
- static createFunction(context: Map<string, any>, code: string): any;
146
+ static createFunction(context: Map<string, any>, code: string, compiledFunctions?: CompiledFunctions, key?: string): any;
244
147
  static callCompiledFunction<T extends unknown[], R>(fn: (...args: T) => R, ...args: T): R;
245
- /**
246
- * @see https://github.com/mikro-orm/mikro-orm/issues/840
247
- */
248
- static propertyDecoratorReturnValue(): any;
249
148
  static unwrapProperty<T>(entity: T, meta: EntityMetadata<T>, prop: EntityProperty<T>, payload?: boolean): [unknown, number[]][];
250
149
  static setPayloadProperty<T>(entity: EntityDictionary<T>, meta: EntityMetadata<T>, prop: EntityProperty<T>, value: unknown, idx: number[]): void;
251
- static tryRequire<T extends Dictionary = any>({ module, from, allowError, warning }: {
252
- module: string;
253
- warning: string;
254
- from?: string;
255
- allowError?: string;
256
- }): T | undefined;
257
- static tryImport<T extends Dictionary = any>({ module, warning }: {
150
+ static tryImport<T extends Dictionary = any>({ module, warning, }: {
258
151
  module: string;
259
- warning: string;
152
+ warning?: string;
260
153
  }): Promise<T | undefined>;
261
- static stripRelativePath(str: string): string;
262
- /**
263
- * simple process.argv parser, supports only properties with long names, prefixed with `--`
264
- */
265
- static parseArgs<T extends Dictionary = Dictionary>(): T;
266
154
  static xor(a: boolean, b: boolean): boolean;
267
155
  static keys<T extends object>(obj: T): (keyof T)[];
268
156
  static values<T extends object>(obj: T): T[keyof T][];
269
157
  static entries<T extends object>(obj: T): [keyof T, T[keyof T]][];
270
158
  static primaryKeyToObject<T>(meta: EntityMetadata<T>, primaryKey: Primary<T> | T, visible?: (keyof T)[]): T;
159
+ static getObjectQueryKeys<T extends Dictionary, K extends string = Extract<keyof T, string>>(obj: T): (K | RawQueryFragmentSymbol)[];
271
160
  }