@mikro-orm/core 7.0.0-dev.30 → 7.0.0-dev.300

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 (209) hide show
  1. package/EntityManager.d.ts +68 -60
  2. package/EntityManager.js +290 -259
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +109 -142
  5. package/README.md +2 -0
  6. package/cache/FileCacheAdapter.d.ts +1 -2
  7. package/cache/FileCacheAdapter.js +18 -11
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +0 -1
  11. package/cache/index.js +0 -1
  12. package/connections/Connection.d.ts +12 -5
  13. package/connections/Connection.js +21 -12
  14. package/drivers/DatabaseDriver.d.ts +25 -16
  15. package/drivers/DatabaseDriver.js +119 -36
  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 +436 -104
  21. package/entity/EntityAssigner.js +17 -17
  22. package/entity/EntityFactory.d.ts +7 -1
  23. package/entity/EntityFactory.js +87 -55
  24. package/entity/EntityHelper.d.ts +2 -2
  25. package/entity/EntityHelper.js +57 -19
  26. package/entity/EntityLoader.d.ts +11 -10
  27. package/entity/EntityLoader.js +213 -82
  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 +1 -5
  33. package/entity/Reference.js +15 -11
  34. package/entity/WrappedEntity.d.ts +3 -8
  35. package/entity/WrappedEntity.js +2 -7
  36. package/entity/defineEntity.d.ts +526 -310
  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 +34 -1
  42. package/entity/validators.d.ts +11 -0
  43. package/entity/validators.js +65 -0
  44. package/enums.d.ts +8 -6
  45. package/enums.js +2 -1
  46. package/errors.d.ts +20 -10
  47. package/errors.js +55 -23
  48. package/events/EventManager.d.ts +2 -1
  49. package/events/EventManager.js +19 -11
  50. package/hydration/Hydrator.js +1 -2
  51. package/hydration/ObjectHydrator.d.ts +4 -4
  52. package/hydration/ObjectHydrator.js +79 -34
  53. package/index.d.ts +2 -2
  54. package/index.js +1 -2
  55. package/logging/DefaultLogger.d.ts +1 -1
  56. package/logging/DefaultLogger.js +1 -0
  57. package/logging/SimpleLogger.d.ts +1 -1
  58. package/logging/colors.d.ts +1 -1
  59. package/logging/colors.js +7 -6
  60. package/logging/index.d.ts +1 -0
  61. package/logging/index.js +1 -0
  62. package/logging/inspect.d.ts +2 -0
  63. package/logging/inspect.js +11 -0
  64. package/metadata/EntitySchema.d.ts +47 -23
  65. package/metadata/EntitySchema.js +92 -33
  66. package/metadata/MetadataDiscovery.d.ts +64 -9
  67. package/metadata/MetadataDiscovery.js +782 -325
  68. package/metadata/MetadataProvider.d.ts +11 -2
  69. package/metadata/MetadataProvider.js +66 -2
  70. package/metadata/MetadataStorage.d.ts +13 -11
  71. package/metadata/MetadataStorage.js +72 -39
  72. package/metadata/MetadataValidator.d.ts +32 -9
  73. package/metadata/MetadataValidator.js +196 -41
  74. package/metadata/discover-entities.d.ts +5 -0
  75. package/metadata/discover-entities.js +40 -0
  76. package/metadata/index.d.ts +1 -1
  77. package/metadata/index.js +1 -1
  78. package/metadata/types.d.ts +577 -0
  79. package/metadata/types.js +1 -0
  80. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  81. package/naming-strategy/AbstractNamingStrategy.js +20 -2
  82. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  83. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  84. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  85. package/naming-strategy/MongoNamingStrategy.js +6 -6
  86. package/naming-strategy/NamingStrategy.d.ts +28 -4
  87. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  89. package/not-supported.d.ts +2 -0
  90. package/not-supported.js +4 -0
  91. package/package.json +22 -11
  92. package/platforms/ExceptionConverter.js +1 -1
  93. package/platforms/Platform.d.ts +11 -15
  94. package/platforms/Platform.js +24 -44
  95. package/serialization/EntitySerializer.d.ts +6 -3
  96. package/serialization/EntitySerializer.js +46 -26
  97. package/serialization/EntityTransformer.js +33 -21
  98. package/serialization/SerializationContext.d.ts +6 -6
  99. package/serialization/SerializationContext.js +3 -3
  100. package/types/ArrayType.d.ts +1 -1
  101. package/types/ArrayType.js +2 -3
  102. package/types/BigIntType.js +1 -1
  103. package/types/BlobType.d.ts +0 -1
  104. package/types/BlobType.js +0 -3
  105. package/types/BooleanType.d.ts +1 -0
  106. package/types/BooleanType.js +3 -0
  107. package/types/DecimalType.js +2 -2
  108. package/types/DoubleType.js +1 -1
  109. package/types/EnumArrayType.js +1 -2
  110. package/types/JsonType.d.ts +1 -1
  111. package/types/JsonType.js +7 -2
  112. package/types/TinyIntType.js +1 -1
  113. package/types/Type.d.ts +2 -4
  114. package/types/Type.js +3 -3
  115. package/types/Uint8ArrayType.d.ts +0 -1
  116. package/types/Uint8ArrayType.js +1 -4
  117. package/types/index.d.ts +1 -1
  118. package/typings.d.ts +412 -155
  119. package/typings.js +99 -44
  120. package/unit-of-work/ChangeSet.d.ts +4 -6
  121. package/unit-of-work/ChangeSet.js +4 -5
  122. package/unit-of-work/ChangeSetComputer.d.ts +3 -8
  123. package/unit-of-work/ChangeSetComputer.js +41 -20
  124. package/unit-of-work/ChangeSetPersister.d.ts +13 -12
  125. package/unit-of-work/ChangeSetPersister.js +94 -36
  126. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  127. package/unit-of-work/CommitOrderCalculator.js +13 -13
  128. package/unit-of-work/IdentityMap.d.ts +12 -0
  129. package/unit-of-work/IdentityMap.js +39 -1
  130. package/unit-of-work/UnitOfWork.d.ts +27 -3
  131. package/unit-of-work/UnitOfWork.js +248 -90
  132. package/utils/AbstractMigrator.d.ts +101 -0
  133. package/utils/AbstractMigrator.js +305 -0
  134. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  135. package/utils/AbstractSchemaGenerator.js +28 -17
  136. package/utils/AsyncContext.d.ts +6 -0
  137. package/utils/AsyncContext.js +42 -0
  138. package/utils/Configuration.d.ts +795 -211
  139. package/utils/Configuration.js +153 -194
  140. package/utils/ConfigurationLoader.d.ts +1 -52
  141. package/utils/ConfigurationLoader.js +1 -330
  142. package/utils/Cursor.d.ts +0 -3
  143. package/utils/Cursor.js +24 -11
  144. package/utils/DataloaderUtils.d.ts +10 -5
  145. package/utils/DataloaderUtils.js +29 -12
  146. package/utils/EntityComparator.d.ts +16 -9
  147. package/utils/EntityComparator.js +154 -56
  148. package/utils/QueryHelper.d.ts +18 -6
  149. package/utils/QueryHelper.js +76 -23
  150. package/utils/RawQueryFragment.d.ts +28 -34
  151. package/utils/RawQueryFragment.js +35 -71
  152. package/utils/RequestContext.js +2 -2
  153. package/utils/TransactionContext.js +2 -2
  154. package/utils/TransactionManager.js +9 -6
  155. package/utils/Utils.d.ts +15 -126
  156. package/utils/Utils.js +80 -382
  157. package/utils/clone.js +8 -23
  158. package/utils/env-vars.d.ts +7 -0
  159. package/utils/env-vars.js +97 -0
  160. package/utils/fs-utils.d.ts +34 -0
  161. package/utils/fs-utils.js +196 -0
  162. package/utils/index.d.ts +1 -3
  163. package/utils/index.js +1 -3
  164. package/utils/upsert-utils.d.ts +9 -4
  165. package/utils/upsert-utils.js +46 -3
  166. package/decorators/Check.d.ts +0 -3
  167. package/decorators/Check.js +0 -13
  168. package/decorators/CreateRequestContext.d.ts +0 -3
  169. package/decorators/CreateRequestContext.js +0 -32
  170. package/decorators/Embeddable.d.ts +0 -8
  171. package/decorators/Embeddable.js +0 -11
  172. package/decorators/Embedded.d.ts +0 -12
  173. package/decorators/Embedded.js +0 -18
  174. package/decorators/Entity.d.ts +0 -33
  175. package/decorators/Entity.js +0 -12
  176. package/decorators/Enum.d.ts +0 -9
  177. package/decorators/Enum.js +0 -16
  178. package/decorators/Filter.d.ts +0 -2
  179. package/decorators/Filter.js +0 -8
  180. package/decorators/Formula.d.ts +0 -4
  181. package/decorators/Formula.js +0 -15
  182. package/decorators/Indexed.d.ts +0 -19
  183. package/decorators/Indexed.js +0 -20
  184. package/decorators/ManyToMany.d.ts +0 -42
  185. package/decorators/ManyToMany.js +0 -14
  186. package/decorators/ManyToOne.d.ts +0 -34
  187. package/decorators/ManyToOne.js +0 -14
  188. package/decorators/OneToMany.d.ts +0 -28
  189. package/decorators/OneToMany.js +0 -17
  190. package/decorators/OneToOne.d.ts +0 -28
  191. package/decorators/OneToOne.js +0 -7
  192. package/decorators/PrimaryKey.d.ts +0 -8
  193. package/decorators/PrimaryKey.js +0 -20
  194. package/decorators/Property.d.ts +0 -250
  195. package/decorators/Property.js +0 -32
  196. package/decorators/Transactional.d.ts +0 -14
  197. package/decorators/Transactional.js +0 -28
  198. package/decorators/hooks.d.ts +0 -16
  199. package/decorators/hooks.js +0 -47
  200. package/decorators/index.d.ts +0 -17
  201. package/decorators/index.js +0 -17
  202. package/entity/ArrayCollection.d.ts +0 -118
  203. package/entity/ArrayCollection.js +0 -407
  204. package/entity/EntityValidator.d.ts +0 -19
  205. package/entity/EntityValidator.js +0 -150
  206. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  207. package/metadata/ReflectMetadataProvider.js +0 -44
  208. package/utils/resolveContextProvider.d.ts +0 -10
  209. package/utils/resolveContextProvider.js +0 -28
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?: undefined | 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
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
  }