@mikro-orm/core 7.0.2 → 7.0.3-dev.1

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 (205) hide show
  1. package/EntityManager.d.ts +583 -883
  2. package/EntityManager.js +1869 -1897
  3. package/MikroORM.d.ts +74 -103
  4. package/MikroORM.js +179 -178
  5. package/cache/CacheAdapter.d.ts +36 -36
  6. package/cache/FileCacheAdapter.d.ts +24 -30
  7. package/cache/FileCacheAdapter.js +78 -80
  8. package/cache/GeneratedCacheAdapter.d.ts +20 -18
  9. package/cache/GeneratedCacheAdapter.js +30 -30
  10. package/cache/MemoryCacheAdapter.d.ts +20 -18
  11. package/cache/MemoryCacheAdapter.js +36 -35
  12. package/cache/NullCacheAdapter.d.ts +16 -16
  13. package/cache/NullCacheAdapter.js +24 -24
  14. package/connections/Connection.d.ts +84 -95
  15. package/connections/Connection.js +168 -165
  16. package/drivers/DatabaseDriver.d.ts +80 -186
  17. package/drivers/DatabaseDriver.js +443 -450
  18. package/drivers/IDatabaseDriver.d.ts +301 -440
  19. package/entity/BaseEntity.d.ts +83 -120
  20. package/entity/BaseEntity.js +43 -43
  21. package/entity/Collection.d.ts +179 -212
  22. package/entity/Collection.js +721 -727
  23. package/entity/EntityAssigner.d.ts +77 -88
  24. package/entity/EntityAssigner.js +230 -231
  25. package/entity/EntityFactory.d.ts +54 -66
  26. package/entity/EntityFactory.js +383 -425
  27. package/entity/EntityHelper.d.ts +22 -34
  28. package/entity/EntityHelper.js +267 -280
  29. package/entity/EntityIdentifier.d.ts +4 -4
  30. package/entity/EntityIdentifier.js +10 -10
  31. package/entity/EntityLoader.d.ts +73 -103
  32. package/entity/EntityLoader.js +723 -753
  33. package/entity/EntityRepository.d.ts +201 -316
  34. package/entity/EntityRepository.js +213 -213
  35. package/entity/PolymorphicRef.d.ts +5 -5
  36. package/entity/PolymorphicRef.js +10 -10
  37. package/entity/Reference.d.ts +82 -126
  38. package/entity/Reference.js +274 -278
  39. package/entity/WrappedEntity.d.ts +72 -115
  40. package/entity/WrappedEntity.js +166 -168
  41. package/entity/defineEntity.d.ts +614 -1280
  42. package/entity/defineEntity.js +511 -520
  43. package/entity/utils.d.ts +3 -13
  44. package/entity/utils.js +73 -71
  45. package/entity/validators.js +43 -43
  46. package/entity/wrap.js +8 -8
  47. package/enums.d.ts +253 -258
  48. package/enums.js +252 -251
  49. package/errors.d.ts +72 -114
  50. package/errors.js +253 -350
  51. package/events/EventManager.d.ts +14 -26
  52. package/events/EventManager.js +77 -79
  53. package/events/EventSubscriber.d.ts +29 -29
  54. package/events/TransactionEventBroadcaster.d.ts +8 -15
  55. package/events/TransactionEventBroadcaster.js +14 -14
  56. package/exceptions.d.ts +40 -23
  57. package/exceptions.js +52 -35
  58. package/hydration/Hydrator.d.ts +17 -42
  59. package/hydration/Hydrator.js +43 -43
  60. package/hydration/ObjectHydrator.d.ts +17 -50
  61. package/hydration/ObjectHydrator.js +416 -479
  62. package/index.d.ts +2 -116
  63. package/index.js +1 -10
  64. package/logging/DefaultLogger.d.ts +32 -34
  65. package/logging/DefaultLogger.js +86 -86
  66. package/logging/Logger.d.ts +41 -41
  67. package/logging/SimpleLogger.d.ts +11 -13
  68. package/logging/SimpleLogger.js +22 -22
  69. package/logging/colors.d.ts +6 -6
  70. package/logging/colors.js +10 -11
  71. package/logging/inspect.js +7 -7
  72. package/metadata/EntitySchema.d.ts +127 -211
  73. package/metadata/EntitySchema.js +398 -397
  74. package/metadata/MetadataDiscovery.d.ts +114 -114
  75. package/metadata/MetadataDiscovery.js +1863 -1947
  76. package/metadata/MetadataProvider.d.ts +21 -24
  77. package/metadata/MetadataProvider.js +84 -82
  78. package/metadata/MetadataStorage.d.ts +32 -38
  79. package/metadata/MetadataStorage.js +118 -118
  80. package/metadata/MetadataValidator.d.ts +39 -39
  81. package/metadata/MetadataValidator.js +338 -381
  82. package/metadata/discover-entities.d.ts +2 -5
  83. package/metadata/discover-entities.js +27 -27
  84. package/metadata/types.d.ts +531 -615
  85. package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
  86. package/naming-strategy/AbstractNamingStrategy.js +85 -90
  87. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  88. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  89. package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
  90. package/naming-strategy/MongoNamingStrategy.js +18 -18
  91. package/naming-strategy/NamingStrategy.d.ts +99 -109
  92. package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
  93. package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
  94. package/not-supported.js +4 -7
  95. package/package.json +1 -1
  96. package/platforms/ExceptionConverter.d.ts +1 -1
  97. package/platforms/ExceptionConverter.js +4 -4
  98. package/platforms/Platform.d.ts +299 -308
  99. package/platforms/Platform.js +636 -659
  100. package/serialization/EntitySerializer.d.ts +26 -48
  101. package/serialization/EntitySerializer.js +218 -224
  102. package/serialization/EntityTransformer.d.ts +6 -10
  103. package/serialization/EntityTransformer.js +217 -219
  104. package/serialization/SerializationContext.d.ts +23 -27
  105. package/serialization/SerializationContext.js +105 -105
  106. package/types/ArrayType.d.ts +8 -8
  107. package/types/ArrayType.js +33 -33
  108. package/types/BigIntType.d.ts +10 -17
  109. package/types/BigIntType.js +37 -37
  110. package/types/BlobType.d.ts +3 -3
  111. package/types/BlobType.js +13 -13
  112. package/types/BooleanType.d.ts +4 -4
  113. package/types/BooleanType.js +12 -12
  114. package/types/CharacterType.d.ts +2 -2
  115. package/types/CharacterType.js +6 -6
  116. package/types/DateTimeType.d.ts +5 -5
  117. package/types/DateTimeType.js +15 -15
  118. package/types/DateType.d.ts +5 -5
  119. package/types/DateType.js +15 -15
  120. package/types/DecimalType.d.ts +7 -7
  121. package/types/DecimalType.js +26 -26
  122. package/types/DoubleType.d.ts +3 -3
  123. package/types/DoubleType.js +12 -12
  124. package/types/EnumArrayType.d.ts +5 -5
  125. package/types/EnumArrayType.js +24 -24
  126. package/types/EnumType.d.ts +3 -3
  127. package/types/EnumType.js +11 -11
  128. package/types/FloatType.d.ts +3 -3
  129. package/types/FloatType.js +9 -9
  130. package/types/IntegerType.d.ts +3 -3
  131. package/types/IntegerType.js +9 -9
  132. package/types/IntervalType.d.ts +4 -4
  133. package/types/IntervalType.js +12 -12
  134. package/types/JsonType.d.ts +8 -8
  135. package/types/JsonType.js +32 -32
  136. package/types/MediumIntType.d.ts +1 -1
  137. package/types/MediumIntType.js +3 -3
  138. package/types/SmallIntType.d.ts +3 -3
  139. package/types/SmallIntType.js +9 -9
  140. package/types/StringType.d.ts +4 -4
  141. package/types/StringType.js +12 -12
  142. package/types/TextType.d.ts +3 -3
  143. package/types/TextType.js +9 -9
  144. package/types/TimeType.d.ts +5 -5
  145. package/types/TimeType.js +17 -17
  146. package/types/TinyIntType.d.ts +3 -3
  147. package/types/TinyIntType.js +10 -10
  148. package/types/Type.d.ts +79 -83
  149. package/types/Type.js +82 -82
  150. package/types/Uint8ArrayType.d.ts +4 -4
  151. package/types/Uint8ArrayType.js +21 -21
  152. package/types/UnknownType.d.ts +4 -4
  153. package/types/UnknownType.js +12 -12
  154. package/types/UuidType.d.ts +5 -5
  155. package/types/UuidType.js +19 -19
  156. package/types/index.d.ts +49 -75
  157. package/types/index.js +26 -52
  158. package/typings.d.ts +729 -1211
  159. package/typings.js +231 -244
  160. package/unit-of-work/ChangeSet.d.ts +26 -26
  161. package/unit-of-work/ChangeSet.js +56 -56
  162. package/unit-of-work/ChangeSetComputer.d.ts +12 -12
  163. package/unit-of-work/ChangeSetComputer.js +170 -178
  164. package/unit-of-work/ChangeSetPersister.d.ts +44 -63
  165. package/unit-of-work/ChangeSetPersister.js +421 -442
  166. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  167. package/unit-of-work/CommitOrderCalculator.js +88 -89
  168. package/unit-of-work/IdentityMap.d.ts +31 -31
  169. package/unit-of-work/IdentityMap.js +105 -105
  170. package/unit-of-work/UnitOfWork.d.ts +141 -181
  171. package/unit-of-work/UnitOfWork.js +1183 -1200
  172. package/utils/AbstractMigrator.d.ts +91 -111
  173. package/utils/AbstractMigrator.js +275 -275
  174. package/utils/AbstractSchemaGenerator.d.ts +34 -43
  175. package/utils/AbstractSchemaGenerator.js +122 -121
  176. package/utils/AsyncContext.d.ts +3 -3
  177. package/utils/AsyncContext.js +35 -34
  178. package/utils/Configuration.d.ts +808 -852
  179. package/utils/Configuration.js +344 -359
  180. package/utils/Cursor.d.ts +22 -40
  181. package/utils/Cursor.js +127 -135
  182. package/utils/DataloaderUtils.d.ts +43 -58
  183. package/utils/DataloaderUtils.js +198 -203
  184. package/utils/EntityComparator.d.ts +81 -98
  185. package/utils/EntityComparator.js +728 -824
  186. package/utils/NullHighlighter.d.ts +1 -1
  187. package/utils/NullHighlighter.js +3 -3
  188. package/utils/QueryHelper.d.ts +51 -79
  189. package/utils/QueryHelper.js +361 -372
  190. package/utils/RawQueryFragment.d.ts +34 -50
  191. package/utils/RawQueryFragment.js +105 -107
  192. package/utils/RequestContext.d.ts +32 -32
  193. package/utils/RequestContext.js +53 -52
  194. package/utils/TransactionContext.d.ts +16 -16
  195. package/utils/TransactionContext.js +27 -27
  196. package/utils/TransactionManager.d.ts +58 -58
  197. package/utils/TransactionManager.js +197 -199
  198. package/utils/Utils.d.ts +145 -204
  199. package/utils/Utils.js +813 -814
  200. package/utils/clone.js +113 -104
  201. package/utils/env-vars.js +88 -90
  202. package/utils/fs-utils.d.ts +15 -15
  203. package/utils/fs-utils.js +181 -180
  204. package/utils/upsert-utils.d.ts +5 -20
  205. package/utils/upsert-utils.js +116 -114
@@ -1,4 +1,4 @@
1
- import { EntityManagerType } from './IDatabaseDriver.js';
1
+ import { EntityManagerType, } from './IDatabaseDriver.js';
2
2
  import { Utils } from '../utils/Utils.js';
3
3
  import { Cursor } from '../utils/Cursor.js';
4
4
  import { EntityComparator } from '../utils/EntityComparator.js';
@@ -13,481 +13,474 @@ import { JsonType } from '../types/JsonType.js';
13
13
  import { MikroORM } from '../MikroORM.js';
14
14
  /** Abstract base class for all database drivers, implementing common driver logic. */
15
15
  export class DatabaseDriver {
16
- config;
17
- dependencies;
18
- [EntityManagerType];
19
- connection;
20
- replicas = [];
21
- platform;
22
- comparator;
23
- metadata;
24
- constructor(config, dependencies) {
25
- this.config = config;
26
- this.dependencies = dependencies;
27
- }
28
- async nativeUpdateMany(entityName, where, data, options) {
29
- throw new Error(`Batch updates are not supported by ${this.constructor.name} driver`);
30
- }
31
- /** Creates a new EntityManager instance bound to this driver. */
32
- createEntityManager(useContext) {
33
- const EntityManagerClass = this.config.get('entityManager', EntityManager);
34
- return new EntityManagerClass(this.config, this, this.metadata, useContext);
35
- }
36
- /* v8 ignore next */
37
- async findVirtual(entityName, where, options) {
38
- throw new Error(`Virtual entities are not supported by ${this.constructor.name} driver.`);
39
- }
40
- /* v8 ignore next */
41
- async countVirtual(entityName, where, options) {
42
- throw new Error(`Counting virtual entities is not supported by ${this.constructor.name} driver.`);
43
- }
44
- async aggregate(entityName, pipeline) {
45
- throw new Error(`Aggregations are not supported by ${this.constructor.name} driver`);
46
- }
47
- async loadFromPivotTable(prop, owners, where, orderBy, ctx, options, pivotJoin) {
48
- throw new Error(`${this.constructor.name} does not use pivot tables`);
49
- }
50
- async syncCollections(collections, options) {
51
- for (const coll of collections) {
52
- /* v8 ignore else */
53
- if (!coll.property.owner) {
54
- if (coll.getSnapshot() === undefined) {
55
- throw ValidationError.cannotModifyInverseCollection(coll.owner, coll.property);
56
- }
57
- continue;
58
- }
59
- /* v8 ignore next */
60
- {
61
- const pk = coll.property.targetMeta.primaryKeys[0];
62
- const data = { [coll.property.name]: coll.getIdentifiers(pk) };
63
- await this.nativeUpdate(coll.owner.constructor, helper(coll.owner).getPrimaryKey(), data, options);
64
- }
65
- }
66
- }
67
- /** Maps raw database result to entity data, converting column names to property names. */
68
- mapResult(result, meta, populate = []) {
69
- if (!result || !meta) {
70
- return result ?? null;
16
+ config;
17
+ dependencies;
18
+ [EntityManagerType];
19
+ connection;
20
+ replicas = [];
21
+ platform;
22
+ comparator;
23
+ metadata;
24
+ constructor(config, dependencies) {
25
+ this.config = config;
26
+ this.dependencies = dependencies;
71
27
  }
72
- return this.comparator.mapResult(meta, result);
73
- }
74
- /** Opens the primary connection and all read replicas. */
75
- async connect(options) {
76
- await this.connection.connect(options);
77
- await Promise.all(this.replicas.map(replica => replica.connect()));
78
- return this.connection;
79
- }
80
- /** Closes all connections and re-establishes them. */
81
- async reconnect(options) {
82
- await this.close(true);
83
- await this.connect(options);
84
- return this.connection;
85
- }
86
- /** Returns the write connection or a random read replica. */
87
- getConnection(type = 'write') {
88
- if (type === 'write' || this.replicas.length === 0) {
89
- return this.connection;
28
+ async nativeUpdateMany(entityName, where, data, options) {
29
+ throw new Error(`Batch updates are not supported by ${this.constructor.name} driver`);
90
30
  }
91
- const rand = Utils.randomInt(0, this.replicas.length - 1);
92
- return this.replicas[rand];
93
- }
94
- /** Closes the primary connection and all read replicas. */
95
- async close(force) {
96
- await Promise.all(this.replicas.map(replica => replica.close(force)));
97
- await this.connection.close(force);
98
- }
99
- /** Returns the database platform abstraction for this driver. */
100
- getPlatform() {
101
- return this.platform;
102
- }
103
- /** Sets the metadata storage and initializes the comparator for all connections. */
104
- setMetadata(metadata) {
105
- this.metadata = metadata;
106
- this.comparator = new EntityComparator(this.metadata, this.platform);
107
- this.connection.setMetadata(metadata);
108
- this.connection.setPlatform(this.platform);
109
- this.replicas.forEach(replica => {
110
- replica.setMetadata(metadata);
111
- replica.setPlatform(this.platform);
112
- });
113
- }
114
- /** Returns the metadata storage used by this driver. */
115
- getMetadata() {
116
- return this.metadata;
117
- }
118
- /** Returns the names of native database dependencies required by this driver. */
119
- getDependencies() {
120
- return this.dependencies;
121
- }
122
- isPopulated(meta, prop, hint, name) {
123
- if (hint.field === prop.name || hint.field === name || hint.all) {
124
- return true;
31
+ /** Creates a new EntityManager instance bound to this driver. */
32
+ createEntityManager(useContext) {
33
+ const EntityManagerClass = this.config.get('entityManager', EntityManager);
34
+ return new EntityManagerClass(this.config, this, this.metadata, useContext);
125
35
  }
126
- if (prop.embedded && hint.children && meta.properties[prop.embedded[0]].name === hint.field) {
127
- return hint.children.some(c => this.isPopulated(meta, prop, c, prop.embedded[1]));
36
+ /* v8 ignore next */
37
+ async findVirtual(entityName, where, options) {
38
+ throw new Error(`Virtual entities are not supported by ${this.constructor.name} driver.`);
128
39
  }
129
- return false;
130
- }
131
- processCursorOptions(meta, options, orderBy) {
132
- const { first, last, before, after, overfetch } = options;
133
- const limit = first ?? last;
134
- const isLast = !first && !!last;
135
- const definition = Cursor.getDefinition(meta, orderBy);
136
- const $and = [];
137
- // allow POJO as well, we care only about the correct key being present
138
- const isCursor = (val, key) => {
139
- return !!val && typeof val === 'object' && key in val;
140
- };
141
- const createCursor = (val, key, inverse = false) => {
142
- let def = isCursor(val, key) ? val[key] : val;
143
- if (Utils.isPlainObject(def)) {
144
- def = Cursor.for(meta, def, orderBy);
145
- }
146
- /* v8 ignore next */
147
- const offsets = def ? Cursor.decode(def) : [];
148
- if (definition.length === offsets.length) {
149
- return this.createCursorCondition(definition, offsets, inverse, meta);
150
- }
151
- /* v8 ignore next */
152
- return {};
153
- };
154
- if (after) {
155
- $and.push(createCursor(after, 'endCursor'));
40
+ /* v8 ignore next */
41
+ async countVirtual(entityName, where, options) {
42
+ throw new Error(`Counting virtual entities is not supported by ${this.constructor.name} driver.`);
156
43
  }
157
- if (before) {
158
- $and.push(createCursor(before, 'startCursor', true));
44
+ async aggregate(entityName, pipeline) {
45
+ throw new Error(`Aggregations are not supported by ${this.constructor.name} driver`);
159
46
  }
160
- if (limit != null) {
161
- options.limit = limit + (overfetch ? 1 : 0);
47
+ async loadFromPivotTable(prop, owners, where, orderBy, ctx, options, pivotJoin) {
48
+ throw new Error(`${this.constructor.name} does not use pivot tables`);
162
49
  }
163
- const createOrderBy = (prop, direction) => {
164
- if (Utils.isPlainObject(direction)) {
165
- const value = Utils.getObjectQueryKeys(direction).reduce((o, key) => {
166
- Object.assign(o, createOrderBy(key, direction[key]));
167
- return o;
168
- }, {});
169
- return { [prop]: value };
170
- }
171
- const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
172
- const dir = Utils.xor(desc, isLast) ? 'desc' : 'asc';
173
- return { [prop]: dir };
174
- };
175
- return {
176
- orderBy: definition.map(([prop, direction]) => createOrderBy(prop, direction)),
177
- where: $and.length > 1 ? { $and } : { ...$and[0] },
178
- };
179
- }
180
- createCursorCondition(definition, offsets, inverse, meta) {
181
- const createCondition = (prop, direction, offset, eq = false, path = prop) => {
182
- if (Utils.isPlainObject(direction)) {
183
- if (offset === undefined) {
184
- throw CursorError.missingValue(meta.className, path);
50
+ async syncCollections(collections, options) {
51
+ for (const coll of collections) {
52
+ /* v8 ignore else */
53
+ if (!coll.property.owner) {
54
+ if (coll.getSnapshot() === undefined) {
55
+ throw ValidationError.cannotModifyInverseCollection(coll.owner, coll.property);
56
+ }
57
+ continue;
58
+ }
59
+ /* v8 ignore next */
60
+ {
61
+ const pk = coll.property.targetMeta.primaryKeys[0];
62
+ const data = { [coll.property.name]: coll.getIdentifiers(pk) };
63
+ await this.nativeUpdate(coll.owner.constructor, helper(coll.owner).getPrimaryKey(), data, options);
64
+ }
185
65
  }
186
- const value = Utils.keys(direction).reduce((o, key) => {
187
- Object.assign(o, createCondition(key, direction[key], offset?.[key], eq, `${path}.${key}`));
188
- return o;
189
- }, {});
190
- return { [prop]: value };
191
- }
192
- const isDesc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
193
- const dirStr = direction.toString().toLowerCase();
194
- let nullsFirst;
195
- if (dirStr.includes('nulls first')) {
196
- nullsFirst = true;
197
- } else if (dirStr.includes('nulls last')) {
198
- nullsFirst = false;
199
- } else {
200
- // Default: NULLS LAST for ASC, NULLS FIRST for DESC (matches most databases)
201
- nullsFirst = isDesc;
202
- }
203
- const operator = Utils.xor(isDesc, inverse) ? '$lt' : '$gt';
204
- // For leaf-level properties, undefined means missing value
205
- if (offset === undefined) {
206
- throw CursorError.missingValue(meta.className, path);
207
- }
208
- // Handle null offset (intentional null cursor value)
209
- if (offset === null) {
210
- if (eq) {
211
- // Equal to null
212
- return { [prop]: null };
66
+ }
67
+ /** Maps raw database result to entity data, converting column names to property names. */
68
+ mapResult(result, meta, populate = []) {
69
+ if (!result || !meta) {
70
+ return result ?? null;
213
71
  }
214
- // Strict comparison with null cursor value
215
- // hasItemsAfterNull: forward + nullsFirst, or backward + nullsLast
216
- const hasItemsAfterNull = Utils.xor(nullsFirst, inverse);
217
- if (hasItemsAfterNull) {
218
- return { [prop]: { $ne: null } };
72
+ return this.comparator.mapResult(meta, result);
73
+ }
74
+ /** Opens the primary connection and all read replicas. */
75
+ async connect(options) {
76
+ await this.connection.connect(options);
77
+ await Promise.all(this.replicas.map(replica => replica.connect()));
78
+ return this.connection;
79
+ }
80
+ /** Closes all connections and re-establishes them. */
81
+ async reconnect(options) {
82
+ await this.close(true);
83
+ await this.connect(options);
84
+ return this.connection;
85
+ }
86
+ /** Returns the write connection or a random read replica. */
87
+ getConnection(type = 'write') {
88
+ if (type === 'write' || this.replicas.length === 0) {
89
+ return this.connection;
219
90
  }
220
- // No items after null in this direction, return impossible condition
221
- return { [prop]: [] };
222
- }
223
- // Non-null offset
224
- return { [prop]: { [operator + (eq ? 'e' : '')]: offset } };
225
- };
226
- const [order, ...otherOrders] = definition;
227
- const [offset, ...otherOffsets] = offsets;
228
- const [prop, direction] = order;
229
- if (!otherOrders.length) {
230
- return createCondition(prop, direction, offset);
91
+ const rand = Utils.randomInt(0, this.replicas.length - 1);
92
+ return this.replicas[rand];
93
+ }
94
+ /** Closes the primary connection and all read replicas. */
95
+ async close(force) {
96
+ await Promise.all(this.replicas.map(replica => replica.close(force)));
97
+ await this.connection.close(force);
98
+ }
99
+ /** Returns the database platform abstraction for this driver. */
100
+ getPlatform() {
101
+ return this.platform;
102
+ }
103
+ /** Sets the metadata storage and initializes the comparator for all connections. */
104
+ setMetadata(metadata) {
105
+ this.metadata = metadata;
106
+ this.comparator = new EntityComparator(this.metadata, this.platform);
107
+ this.connection.setMetadata(metadata);
108
+ this.connection.setPlatform(this.platform);
109
+ this.replicas.forEach(replica => {
110
+ replica.setMetadata(metadata);
111
+ replica.setPlatform(this.platform);
112
+ });
231
113
  }
232
- return {
233
- ...createCondition(prop, direction, offset, true),
234
- $or: [
235
- createCondition(prop, direction, offset),
236
- this.createCursorCondition(otherOrders, otherOffsets, inverse, meta),
237
- ],
238
- };
239
- }
240
- /** @internal */
241
- mapDataToFieldNames(data, stringifyJsonArrays, properties, convertCustomTypes, object) {
242
- if (!properties || data == null) {
243
- return data;
114
+ /** Returns the metadata storage used by this driver. */
115
+ getMetadata() {
116
+ return this.metadata;
244
117
  }
245
- data = Object.assign({}, data); // copy first
246
- Object.keys(data).forEach(k => {
247
- const prop = properties[k];
248
- if (!prop) {
249
- return;
250
- }
251
- if (prop.embeddedProps && !prop.object && !object) {
252
- const copy = data[k];
253
- delete data[k];
254
- Object.assign(
255
- data,
256
- this.mapDataToFieldNames(copy, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes),
257
- );
258
- return;
259
- }
260
- if (prop.embeddedProps && (object || prop.object)) {
261
- const copy = data[k];
262
- delete data[k];
263
- if (prop.array) {
264
- data[prop.fieldNames[0]] = copy?.map(item =>
265
- this.mapDataToFieldNames(item, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes, true),
266
- );
267
- } else {
268
- data[prop.fieldNames[0]] = this.mapDataToFieldNames(
269
- copy,
270
- stringifyJsonArrays,
271
- prop.embeddedProps,
272
- convertCustomTypes,
273
- true,
274
- );
118
+ /** Returns the names of native database dependencies required by this driver. */
119
+ getDependencies() {
120
+ return this.dependencies;
121
+ }
122
+ isPopulated(meta, prop, hint, name) {
123
+ if (hint.field === prop.name || hint.field === name || hint.all) {
124
+ return true;
275
125
  }
276
- if (stringifyJsonArrays && prop.array && !object) {
277
- data[prop.fieldNames[0]] = this.platform.convertJsonToDatabaseValue(data[prop.fieldNames[0]]);
126
+ if (prop.embedded && hint.children && meta.properties[prop.embedded[0]].name === hint.field) {
127
+ return hint.children.some(c => this.isPopulated(meta, prop, c, prop.embedded[1]));
278
128
  }
279
- return;
280
- }
281
- // Handle polymorphic relations - convert tuple or PolymorphicRef to separate columns
282
- // Tuple format: ['discriminator', id] or ['discriminator', id1, id2] for composite keys
283
- // Must be checked BEFORE joinColumns array handling since polymorphic uses fieldNames (includes discriminator)
284
- if (prop.polymorphic && prop.fieldNames && prop.fieldNames.length >= 2) {
285
- let discriminator;
286
- let ids;
287
- if (Array.isArray(data[k]) && typeof data[k][0] === 'string' && prop.discriminatorMap?.[data[k][0]]) {
288
- // Tuple format: ['discriminator', ...ids]
289
- const [disc, ...rest] = data[k];
290
- discriminator = disc;
291
- ids = rest;
292
- } else if (data[k] instanceof PolymorphicRef) {
293
- // PolymorphicRef wrapper (internal use)
294
- discriminator = data[k].discriminator;
295
- const polyId = data[k].id;
296
- // Handle object-style composite key IDs like { tenantId: 1, orgId: 100 }
297
- if (polyId && typeof polyId === 'object' && !Array.isArray(polyId)) {
298
- const targetEntity = prop.discriminatorMap?.[discriminator];
299
- const targetMeta = this.metadata.get(targetEntity);
300
- ids = targetMeta.primaryKeys.map(pk => polyId[pk]);
301
- } else {
302
- ids = Utils.asArray(polyId);
303
- }
129
+ return false;
130
+ }
131
+ processCursorOptions(meta, options, orderBy) {
132
+ const { first, last, before, after, overfetch } = options;
133
+ const limit = first ?? last;
134
+ const isLast = !first && !!last;
135
+ const definition = Cursor.getDefinition(meta, orderBy);
136
+ const $and = [];
137
+ // allow POJO as well, we care only about the correct key being present
138
+ const isCursor = (val, key) => {
139
+ return !!val && typeof val === 'object' && key in val;
140
+ };
141
+ const createCursor = (val, key, inverse = false) => {
142
+ let def = isCursor(val, key) ? val[key] : val;
143
+ if (Utils.isPlainObject(def)) {
144
+ def = Cursor.for(meta, def, orderBy);
145
+ }
146
+ /* v8 ignore next */
147
+ const offsets = def ? Cursor.decode(def) : [];
148
+ if (definition.length === offsets.length) {
149
+ return this.createCursorCondition(definition, offsets, inverse, meta);
150
+ }
151
+ /* v8 ignore next */
152
+ return {};
153
+ };
154
+ if (after) {
155
+ $and.push(createCursor(after, 'endCursor'));
304
156
  }
305
- if (discriminator) {
306
- const discriminatorColumn = prop.fieldNames[0];
307
- const idColumns = prop.fieldNames.slice(1);
308
- delete data[k];
309
- data[discriminatorColumn] = discriminator;
310
- idColumns.forEach((col, idx) => {
311
- data[col] = ids[idx];
312
- });
313
- return;
157
+ if (before) {
158
+ $and.push(createCursor(before, 'startCursor', true));
314
159
  }
315
- }
316
- if (prop.joinColumns && Array.isArray(data[k])) {
317
- const copy = Utils.flatten(data[k]);
318
- delete data[k];
319
- prop.joinColumns.forEach((joinColumn, idx) => (data[joinColumn] = copy[idx]));
320
- return;
321
- }
322
- if (prop.joinColumns?.length > 1 && data[k] == null) {
323
- delete data[k];
324
- prop.ownColumns.forEach(joinColumn => (data[joinColumn] = null));
325
- return;
326
- }
327
- if (
328
- prop.customType &&
329
- convertCustomTypes &&
330
- !(prop.customType instanceof JsonType && object) &&
331
- !isRaw(data[k])
332
- ) {
333
- data[k] = prop.customType.convertToDatabaseValue(data[k], this.platform, {
334
- fromQuery: true,
335
- key: k,
336
- mode: 'query-data',
337
- });
338
- }
339
- if (prop.hasConvertToDatabaseValueSQL && !prop.object && !isRaw(data[k])) {
340
- const quoted = this.platform.quoteValue(data[k]);
341
- const sql = prop.customType.convertToDatabaseValueSQL(quoted, this.platform);
342
- data[k] = raw(sql.replace(/\?/g, '\\?'));
343
- }
344
- if (prop.fieldNames) {
345
- Utils.renameKey(data, k, prop.fieldNames[0]);
346
- }
347
- });
348
- return data;
349
- }
350
- inlineEmbeddables(meta, data, where) {
351
- /* v8 ignore next */
352
- if (data == null) {
353
- return;
160
+ if (limit != null) {
161
+ options.limit = limit + (overfetch ? 1 : 0);
162
+ }
163
+ const createOrderBy = (prop, direction) => {
164
+ if (Utils.isPlainObject(direction)) {
165
+ const value = Utils.getObjectQueryKeys(direction).reduce((o, key) => {
166
+ Object.assign(o, createOrderBy(key, direction[key]));
167
+ return o;
168
+ }, {});
169
+ return { [prop]: value };
170
+ }
171
+ const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
172
+ const dir = Utils.xor(desc, isLast) ? 'desc' : 'asc';
173
+ return { [prop]: dir };
174
+ };
175
+ return {
176
+ orderBy: definition.map(([prop, direction]) => createOrderBy(prop, direction)),
177
+ where: ($and.length > 1 ? { $and } : { ...$and[0] }),
178
+ };
179
+ }
180
+ createCursorCondition(definition, offsets, inverse, meta) {
181
+ const createCondition = (prop, direction, offset, eq = false, path = prop) => {
182
+ if (Utils.isPlainObject(direction)) {
183
+ if (offset === undefined) {
184
+ throw CursorError.missingValue(meta.className, path);
185
+ }
186
+ const value = Utils.keys(direction).reduce((o, key) => {
187
+ Object.assign(o, createCondition(key, direction[key], offset?.[key], eq, `${path}.${key}`));
188
+ return o;
189
+ }, {});
190
+ return { [prop]: value };
191
+ }
192
+ const isDesc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
193
+ const dirStr = direction.toString().toLowerCase();
194
+ let nullsFirst;
195
+ if (dirStr.includes('nulls first')) {
196
+ nullsFirst = true;
197
+ }
198
+ else if (dirStr.includes('nulls last')) {
199
+ nullsFirst = false;
200
+ }
201
+ else {
202
+ // Default: NULLS LAST for ASC, NULLS FIRST for DESC (matches most databases)
203
+ nullsFirst = isDesc;
204
+ }
205
+ const operator = Utils.xor(isDesc, inverse) ? '$lt' : '$gt';
206
+ // For leaf-level properties, undefined means missing value
207
+ if (offset === undefined) {
208
+ throw CursorError.missingValue(meta.className, path);
209
+ }
210
+ // Handle null offset (intentional null cursor value)
211
+ if (offset === null) {
212
+ if (eq) {
213
+ // Equal to null
214
+ return { [prop]: null };
215
+ }
216
+ // Strict comparison with null cursor value
217
+ // hasItemsAfterNull: forward + nullsFirst, or backward + nullsLast
218
+ const hasItemsAfterNull = Utils.xor(nullsFirst, inverse);
219
+ if (hasItemsAfterNull) {
220
+ return { [prop]: { $ne: null } };
221
+ }
222
+ // No items after null in this direction, return impossible condition
223
+ return { [prop]: [] };
224
+ }
225
+ // Non-null offset
226
+ return { [prop]: { [operator + (eq ? 'e' : '')]: offset } };
227
+ };
228
+ const [order, ...otherOrders] = definition;
229
+ const [offset, ...otherOffsets] = offsets;
230
+ const [prop, direction] = order;
231
+ if (!otherOrders.length) {
232
+ return createCondition(prop, direction, offset);
233
+ }
234
+ return {
235
+ ...createCondition(prop, direction, offset, true),
236
+ $or: [
237
+ createCondition(prop, direction, offset),
238
+ this.createCursorCondition(otherOrders, otherOffsets, inverse, meta),
239
+ ],
240
+ };
354
241
  }
355
- Utils.keys(data).forEach(k => {
356
- if (Utils.isOperator(k)) {
357
- Utils.asArray(data[k]).forEach(payload => this.inlineEmbeddables(meta, payload, where));
358
- }
359
- });
360
- meta.props.forEach(prop => {
361
- if (prop.kind === ReferenceKind.EMBEDDED && prop.object && !where && Utils.isObject(data[prop.name])) {
362
- return;
363
- }
364
- if (prop.kind === ReferenceKind.EMBEDDED && Utils.isObject(data[prop.name])) {
365
- const props = prop.embeddedProps;
366
- let unknownProp = false;
367
- Object.keys(data[prop.name]).forEach(kk => {
368
- // explicitly allow `$exists`, `$eq`, `$ne` and `$elemMatch` operators here as they can't be misused this way
369
- const operator = Object.keys(data[prop.name]).some(
370
- f => Utils.isOperator(f) && !['$exists', '$ne', '$eq', '$elemMatch'].includes(f),
371
- );
372
- if (operator) {
373
- throw ValidationError.cannotUseOperatorsInsideEmbeddables(meta.class, prop.name, data);
374
- }
375
- if (prop.object && where) {
376
- const inline = (payload, sub, path) => {
377
- if (sub.kind === ReferenceKind.EMBEDDED && Utils.isObject(payload[sub.embedded[1]])) {
378
- return Object.keys(payload[sub.embedded[1]]).forEach(kkk => {
379
- if (!sub.embeddedProps[kkk]) {
380
- throw ValidationError.invalidEmbeddableQuery(meta.class, kkk, sub.type);
381
- }
382
- inline(payload[sub.embedded[1]], sub.embeddedProps[kkk], [...path, sub.fieldNames[0]]);
242
+ /** @internal */
243
+ mapDataToFieldNames(data, stringifyJsonArrays, properties, convertCustomTypes, object) {
244
+ if (!properties || data == null) {
245
+ return data;
246
+ }
247
+ data = Object.assign({}, data); // copy first
248
+ Object.keys(data).forEach(k => {
249
+ const prop = properties[k];
250
+ if (!prop) {
251
+ return;
252
+ }
253
+ if (prop.embeddedProps && !prop.object && !object) {
254
+ const copy = data[k];
255
+ delete data[k];
256
+ Object.assign(data, this.mapDataToFieldNames(copy, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes));
257
+ return;
258
+ }
259
+ if (prop.embeddedProps && (object || prop.object)) {
260
+ const copy = data[k];
261
+ delete data[k];
262
+ if (prop.array) {
263
+ data[prop.fieldNames[0]] = copy?.map((item) => this.mapDataToFieldNames(item, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes, true));
264
+ }
265
+ else {
266
+ data[prop.fieldNames[0]] = this.mapDataToFieldNames(copy, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes, true);
267
+ }
268
+ if (stringifyJsonArrays && prop.array && !object) {
269
+ data[prop.fieldNames[0]] = this.platform.convertJsonToDatabaseValue(data[prop.fieldNames[0]]);
270
+ }
271
+ return;
272
+ }
273
+ // Handle polymorphic relations - convert tuple or PolymorphicRef to separate columns
274
+ // Tuple format: ['discriminator', id] or ['discriminator', id1, id2] for composite keys
275
+ // Must be checked BEFORE joinColumns array handling since polymorphic uses fieldNames (includes discriminator)
276
+ if (prop.polymorphic && prop.fieldNames && prop.fieldNames.length >= 2) {
277
+ let discriminator;
278
+ let ids;
279
+ if (Array.isArray(data[k]) && typeof data[k][0] === 'string' && prop.discriminatorMap?.[data[k][0]]) {
280
+ // Tuple format: ['discriminator', ...ids]
281
+ const [disc, ...rest] = data[k];
282
+ discriminator = disc;
283
+ ids = rest;
284
+ }
285
+ else if (data[k] instanceof PolymorphicRef) {
286
+ // PolymorphicRef wrapper (internal use)
287
+ discriminator = data[k].discriminator;
288
+ const polyId = data[k].id;
289
+ // Handle object-style composite key IDs like { tenantId: 1, orgId: 100 }
290
+ if (polyId && typeof polyId === 'object' && !Array.isArray(polyId)) {
291
+ const targetEntity = prop.discriminatorMap?.[discriminator];
292
+ const targetMeta = this.metadata.get(targetEntity);
293
+ ids = targetMeta.primaryKeys.map(pk => polyId[pk]);
294
+ }
295
+ else {
296
+ ids = Utils.asArray(polyId);
297
+ }
298
+ }
299
+ if (discriminator) {
300
+ const discriminatorColumn = prop.fieldNames[0];
301
+ const idColumns = prop.fieldNames.slice(1);
302
+ delete data[k];
303
+ data[discriminatorColumn] = discriminator;
304
+ idColumns.forEach((col, idx) => {
305
+ data[col] = ids[idx];
306
+ });
307
+ return;
308
+ }
309
+ }
310
+ if (prop.joinColumns && Array.isArray(data[k])) {
311
+ const copy = Utils.flatten(data[k]);
312
+ delete data[k];
313
+ prop.joinColumns.forEach((joinColumn, idx) => (data[joinColumn] = copy[idx]));
314
+ return;
315
+ }
316
+ if (prop.joinColumns?.length > 1 && data[k] == null) {
317
+ delete data[k];
318
+ prop.ownColumns.forEach(joinColumn => (data[joinColumn] = null));
319
+ return;
320
+ }
321
+ if (prop.customType &&
322
+ convertCustomTypes &&
323
+ !(prop.customType instanceof JsonType && object) &&
324
+ !isRaw(data[k])) {
325
+ data[k] = prop.customType.convertToDatabaseValue(data[k], this.platform, {
326
+ fromQuery: true,
327
+ key: k,
328
+ mode: 'query-data',
383
329
  });
384
- }
385
- data[`${path.join('.')}.${sub.fieldNames[0]}`] = payload[sub.embedded[1]];
386
- };
387
- const parentPropName = kk.substring(0, kk.indexOf('.'));
388
- // we might be using some native JSON operator, e.g. with mongodb's `$geoWithin` or `$exists`
389
- if (props[kk]) {
390
- /* v8 ignore next */
391
- inline(data[prop.name], props[kk] || props[parentPropName], [prop.fieldNames[0]]);
392
- } else if (props[parentPropName]) {
393
- data[`${prop.fieldNames[0]}.${kk}`] = data[prop.name][kk];
394
- } else {
395
- unknownProp = true;
396
330
  }
397
- } else if (props[kk]) {
398
- data[props[kk].fieldNames[0]] = data[prop.name][props[kk].embedded[1]];
399
- } else {
400
- throw ValidationError.invalidEmbeddableQuery(meta.class, kk, prop.type);
401
- }
331
+ if (prop.hasConvertToDatabaseValueSQL && !prop.object && !isRaw(data[k])) {
332
+ const quoted = this.platform.quoteValue(data[k]);
333
+ const sql = prop.customType.convertToDatabaseValueSQL(quoted, this.platform);
334
+ data[k] = raw(sql.replace(/\?/g, '\\?'));
335
+ }
336
+ if (prop.fieldNames) {
337
+ Utils.renameKey(data, k, prop.fieldNames[0]);
338
+ }
402
339
  });
403
- if (!unknownProp) {
404
- delete data[prop.name];
405
- }
406
- }
407
- });
408
- }
409
- getPrimaryKeyFields(meta) {
410
- return meta.getPrimaryProps().flatMap(pk => pk.fieldNames);
411
- }
412
- createReplicas(cb) {
413
- const replicas = this.config.get('replicas', []);
414
- const ret = [];
415
- const props = [
416
- 'dbName',
417
- 'clientUrl',
418
- 'host',
419
- 'port',
420
- 'user',
421
- 'password',
422
- 'multipleStatements',
423
- 'pool',
424
- 'name',
425
- 'driverOptions',
426
- ];
427
- for (const conf of replicas) {
428
- const replicaConfig = Utils.copy(conf);
429
- for (const prop of props) {
430
- if (conf[prop]) {
431
- continue;
340
+ return data;
341
+ }
342
+ inlineEmbeddables(meta, data, where) {
343
+ /* v8 ignore next */
344
+ if (data == null) {
345
+ return;
432
346
  }
433
- // do not copy options that can be inferred from explicitly provided `clientUrl`
434
- if (conf.clientUrl && ['clientUrl', 'host', 'port', 'user', 'password'].includes(prop)) {
435
- continue;
347
+ Utils.keys(data).forEach(k => {
348
+ if (Utils.isOperator(k)) {
349
+ Utils.asArray(data[k]).forEach(payload => this.inlineEmbeddables(meta, payload, where));
350
+ }
351
+ });
352
+ meta.props.forEach(prop => {
353
+ if (prop.kind === ReferenceKind.EMBEDDED && prop.object && !where && Utils.isObject(data[prop.name])) {
354
+ return;
355
+ }
356
+ if (prop.kind === ReferenceKind.EMBEDDED && Utils.isObject(data[prop.name])) {
357
+ const props = prop.embeddedProps;
358
+ let unknownProp = false;
359
+ Object.keys(data[prop.name]).forEach(kk => {
360
+ // explicitly allow `$exists`, `$eq`, `$ne` and `$elemMatch` operators here as they can't be misused this way
361
+ const operator = Object.keys(data[prop.name]).some(f => Utils.isOperator(f) && !['$exists', '$ne', '$eq', '$elemMatch'].includes(f));
362
+ if (operator) {
363
+ throw ValidationError.cannotUseOperatorsInsideEmbeddables(meta.class, prop.name, data);
364
+ }
365
+ if (prop.object && where) {
366
+ const inline = (payload, sub, path) => {
367
+ if (sub.kind === ReferenceKind.EMBEDDED && Utils.isObject(payload[sub.embedded[1]])) {
368
+ return Object.keys(payload[sub.embedded[1]]).forEach(kkk => {
369
+ if (!sub.embeddedProps[kkk]) {
370
+ throw ValidationError.invalidEmbeddableQuery(meta.class, kkk, sub.type);
371
+ }
372
+ inline(payload[sub.embedded[1]], sub.embeddedProps[kkk], [...path, sub.fieldNames[0]]);
373
+ });
374
+ }
375
+ data[`${path.join('.')}.${sub.fieldNames[0]}`] = payload[sub.embedded[1]];
376
+ };
377
+ const parentPropName = kk.substring(0, kk.indexOf('.'));
378
+ // we might be using some native JSON operator, e.g. with mongodb's `$geoWithin` or `$exists`
379
+ if (props[kk]) {
380
+ /* v8 ignore next */
381
+ inline(data[prop.name], props[kk] || props[parentPropName], [prop.fieldNames[0]]);
382
+ }
383
+ else if (props[parentPropName]) {
384
+ data[`${prop.fieldNames[0]}.${kk}`] = data[prop.name][kk];
385
+ }
386
+ else {
387
+ unknownProp = true;
388
+ }
389
+ }
390
+ else if (props[kk]) {
391
+ data[props[kk].fieldNames[0]] = data[prop.name][props[kk].embedded[1]];
392
+ }
393
+ else {
394
+ throw ValidationError.invalidEmbeddableQuery(meta.class, kk, prop.type);
395
+ }
396
+ });
397
+ if (!unknownProp) {
398
+ delete data[prop.name];
399
+ }
400
+ }
401
+ });
402
+ }
403
+ getPrimaryKeyFields(meta) {
404
+ return meta.getPrimaryProps().flatMap(pk => pk.fieldNames);
405
+ }
406
+ createReplicas(cb) {
407
+ const replicas = this.config.get('replicas', []);
408
+ const ret = [];
409
+ const props = [
410
+ 'dbName',
411
+ 'clientUrl',
412
+ 'host',
413
+ 'port',
414
+ 'user',
415
+ 'password',
416
+ 'multipleStatements',
417
+ 'pool',
418
+ 'name',
419
+ 'driverOptions',
420
+ ];
421
+ for (const conf of replicas) {
422
+ const replicaConfig = Utils.copy(conf);
423
+ for (const prop of props) {
424
+ if (conf[prop]) {
425
+ continue;
426
+ }
427
+ // do not copy options that can be inferred from explicitly provided `clientUrl`
428
+ if (conf.clientUrl && ['clientUrl', 'host', 'port', 'user', 'password'].includes(prop)) {
429
+ continue;
430
+ }
431
+ if (conf.clientUrl && prop === 'dbName' && new URL(conf.clientUrl).pathname) {
432
+ continue;
433
+ }
434
+ replicaConfig[prop] = this.config.get(prop);
435
+ }
436
+ ret.push(cb(replicaConfig));
436
437
  }
437
- if (conf.clientUrl && prop === 'dbName' && new URL(conf.clientUrl).pathname) {
438
- continue;
438
+ return ret;
439
+ }
440
+ /** Acquires a pessimistic lock on the given entity. */
441
+ async lockPessimistic(entity, options) {
442
+ throw new Error(`Pessimistic locks are not supported by ${this.constructor.name} driver`);
443
+ }
444
+ /**
445
+ * @inheritDoc
446
+ */
447
+ convertException(exception) {
448
+ if (exception instanceof DriverException) {
449
+ return exception;
439
450
  }
440
- replicaConfig[prop] = this.config.get(prop);
441
- }
442
- ret.push(cb(replicaConfig));
451
+ return this.platform.getExceptionConverter().convertException(exception);
443
452
  }
444
- return ret;
445
- }
446
- /** Acquires a pessimistic lock on the given entity. */
447
- async lockPessimistic(entity, options) {
448
- throw new Error(`Pessimistic locks are not supported by ${this.constructor.name} driver`);
449
- }
450
- /**
451
- * @inheritDoc
452
- */
453
- convertException(exception) {
454
- if (exception instanceof DriverException) {
455
- return exception;
453
+ rethrow(promise) {
454
+ return promise.catch(e => {
455
+ throw this.convertException(e);
456
+ });
456
457
  }
457
- return this.platform.getExceptionConverter().convertException(exception);
458
- }
459
- rethrow(promise) {
460
- return promise.catch(e => {
461
- throw this.convertException(e);
462
- });
463
- }
464
- /**
465
- * @internal
466
- */
467
- getTableName(meta, options, quote = true) {
468
- const schema = this.getSchemaName(meta, options);
469
- const tableName =
470
- schema && schema !== this.platform.getDefaultSchemaName() ? `${schema}.${meta.tableName}` : meta.tableName;
471
- if (quote) {
472
- return this.platform.quoteIdentifier(tableName);
458
+ /**
459
+ * @internal
460
+ */
461
+ getTableName(meta, options, quote = true) {
462
+ const schema = this.getSchemaName(meta, options);
463
+ const tableName = schema && schema !== this.platform.getDefaultSchemaName() ? `${schema}.${meta.tableName}` : meta.tableName;
464
+ if (quote) {
465
+ return this.platform.quoteIdentifier(tableName);
466
+ }
467
+ return tableName;
473
468
  }
474
- return tableName;
475
- }
476
- /**
477
- * @internal
478
- */
479
- getSchemaName(meta, options) {
480
- if (meta?.schema && meta.schema !== '*') {
481
- return meta.schema;
469
+ /**
470
+ * @internal
471
+ */
472
+ getSchemaName(meta, options) {
473
+ if (meta?.schema && meta.schema !== '*') {
474
+ return meta.schema;
475
+ }
476
+ if (options?.schema === '*') {
477
+ return this.config.get('schema');
478
+ }
479
+ const schemaName = meta?.schema === '*' ? this.config.getSchema() : meta?.schema;
480
+ return options?.schema ?? options?.parentSchema ?? schemaName ?? this.config.getSchema();
482
481
  }
483
- if (options?.schema === '*') {
484
- return this.config.get('schema');
482
+ /** @internal */
483
+ getORMClass() {
484
+ return MikroORM;
485
485
  }
486
- const schemaName = meta?.schema === '*' ? this.config.getSchema() : meta?.schema;
487
- return options?.schema ?? options?.parentSchema ?? schemaName ?? this.config.getSchema();
488
- }
489
- /** @internal */
490
- getORMClass() {
491
- return MikroORM;
492
- }
493
486
  }