@mikro-orm/core 6.4.17-dev.65 → 6.4.17-dev.66

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.
package/EntityManager.js CHANGED
@@ -12,6 +12,7 @@ const unit_of_work_1 = require("./unit-of-work");
12
12
  const enums_1 = require("./enums");
13
13
  const events_1 = require("./events");
14
14
  const errors_1 = require("./errors");
15
+ const utils_2 = require("./entity/utils");
15
16
  /**
16
17
  * The EntityManager is the central access point to ORM functionality. It is a facade to all different ORM subsystems
17
18
  * such as UnitOfWork, Query Language, and Repository API.
@@ -131,7 +132,6 @@ class EntityManager {
131
132
  await em.entityLoader.populate(entityName, cached.data, populate, {
132
133
  ...options,
133
134
  ...em.getPopulateWhere(where, options),
134
- convertCustomTypes: false,
135
135
  ignoreLazyScalarProperties: true,
136
136
  lookup: false,
137
137
  });
@@ -162,7 +162,6 @@ class EntityManager {
162
162
  await em.entityLoader.populate(entityName, unique, populate, {
163
163
  ...options,
164
164
  ...em.getPopulateWhere(where, options),
165
- convertCustomTypes: false,
166
165
  ignoreLazyScalarProperties: true,
167
166
  lookup: false,
168
167
  });
@@ -283,7 +282,8 @@ class EntityManager {
283
282
  for (const hint of options.populate) {
284
283
  const field = hint.field.split(':')[0];
285
284
  const prop = meta.properties[field];
286
- const joined = (prop.strategy || options.strategy || hint.strategy || this.config.get('loadStrategy')) === enums_1.LoadStrategy.JOINED && prop.kind !== enums_1.ReferenceKind.SCALAR;
285
+ const strategy = (0, utils_2.getLoadingStrategy)(prop.strategy || options.strategy || hint.strategy || this.config.get('loadStrategy'), prop.kind);
286
+ const joined = strategy === enums_1.LoadStrategy.JOINED && prop.kind !== enums_1.ReferenceKind.SCALAR;
287
287
  if (!joined && !hint.filter) {
288
288
  continue;
289
289
  }
@@ -493,7 +493,7 @@ class EntityManager {
493
493
  for (const e of fork.unitOfWork.getIdentityMap()) {
494
494
  const ref = em.getReference(e.constructor.name, (0, entity_1.helper)(e).getPrimaryKey());
495
495
  const data = this.comparator.prepareEntity(e);
496
- em.config.getHydrator(this.metadata).hydrate(ref, (0, entity_1.helper)(ref).__meta, (0, entity_1.helper)(e).toPOJO(), em.entityFactory, 'full', false, true);
496
+ em.config.getHydrator(this.metadata).hydrate(ref, (0, entity_1.helper)(ref).__meta, (0, entity_1.helper)(e).serialize({ ignoreSerializers: true }), em.entityFactory, 'full', false, true);
497
497
  (0, entity_1.helper)(ref).__originalEntityData = data;
498
498
  }
499
499
  }
@@ -541,7 +541,6 @@ class EntityManager {
541
541
  await em.entityLoader.populate(entityName, [cached.data], options.populate, {
542
542
  ...options,
543
543
  ...em.getPopulateWhere(where, options),
544
- convertCustomTypes: false,
545
544
  ignoreLazyScalarProperties: true,
546
545
  lookup: false,
547
546
  });
@@ -1555,7 +1554,6 @@ class EntityManager {
1555
1554
  ...options,
1556
1555
  ...this.getPopulateWhere(where, options),
1557
1556
  orderBy: options.populateOrderBy ?? options.orderBy,
1558
- convertCustomTypes: false,
1559
1557
  ignoreLazyScalarProperties: true,
1560
1558
  lookup: false,
1561
1559
  });
@@ -143,12 +143,16 @@ class EntityLoader {
143
143
  const innerOrderBy = Utils_1.Utils.asArray(options.orderBy)
144
144
  .filter(orderBy => (Array.isArray(orderBy[prop.name]) && orderBy[prop.name].length > 0) || Utils_1.Utils.isObject(orderBy[prop.name]))
145
145
  .flatMap(orderBy => orderBy[prop.name]);
146
+ const where = await this.extractChildCondition(options, prop);
146
147
  if (prop.kind === enums_1.ReferenceKind.MANY_TO_MANY && this.driver.getPlatform().usesPivotTable()) {
147
148
  const res = await this.findChildrenFromPivotTable(filtered, prop, options, innerOrderBy, populate, !!ref);
148
149
  return Utils_1.Utils.flatten(res);
149
150
  }
150
- const where = await this.extractChildCondition(options, prop);
151
- const { items, partial } = await this.findChildren(entities, prop, populate, { ...options, where, orderBy: innerOrderBy }, !!(ref || prop.mapToPk));
151
+ const { items, partial } = await this.findChildren(options.filtered ?? entities, prop, populate, {
152
+ ...options,
153
+ where,
154
+ orderBy: innerOrderBy,
155
+ }, !!(ref || prop.mapToPk));
152
156
  this.initializeCollections(filtered, prop, field, items, innerOrderBy.length > 0, partial);
153
157
  return items;
154
158
  }
@@ -213,7 +217,7 @@ class EntityLoader {
213
217
  const meta = prop.targetMeta;
214
218
  let fk = Utils_1.Utils.getPrimaryKeyHash(meta.primaryKeys);
215
219
  let schema = options.schema;
216
- let partial = !Utils_1.Utils.isEmpty(prop.where);
220
+ const partial = !Utils_1.Utils.isEmpty(prop.where) || !Utils_1.Utils.isEmpty(options.where);
217
221
  if (prop.kind === enums_1.ReferenceKind.ONE_TO_MANY || (prop.kind === enums_1.ReferenceKind.MANY_TO_MANY && !prop.owner)) {
218
222
  fk = meta.properties[prop.mappedBy].name;
219
223
  }
@@ -254,7 +258,6 @@ class EntityLoader {
254
258
  }
255
259
  }
256
260
  }
257
- partial = !Utils_1.Utils.isEmpty(where);
258
261
  const items = await this.em.find(prop.type, where, {
259
262
  filters, convertCustomTypes, lockMode, populateWhere, logging,
260
263
  orderBy: [...Utils_1.Utils.asArray(options.orderBy), ...propOrderBy],
@@ -322,11 +325,12 @@ class EntityLoader {
322
325
  for (const entity of entities) {
323
326
  visited.delete(entity);
324
327
  }
325
- const filtered = Utils_1.Utils.unique(children.filter(e => !visited.has(e)));
328
+ const unique = Utils_1.Utils.unique(children);
329
+ const filtered = unique.filter(e => !visited.has(e));
326
330
  for (const entity of entities) {
327
331
  visited.add(entity);
328
332
  }
329
- await this.populate(prop.type, filtered, populate.children ?? populate.all, {
333
+ await this.populate(prop.type, unique, populate.children ?? populate.all, {
330
334
  where: await this.extractChildCondition(options, prop, false),
331
335
  orderBy: innerOrderBy,
332
336
  fields,
@@ -343,6 +347,8 @@ class EntityLoader {
343
347
  refresh: refresh && !filtered.every(item => options.visited.has(item)),
344
348
  // @ts-ignore not a public option, will be propagated to the populate call
345
349
  visited: options.visited,
350
+ // @ts-ignore not a public option
351
+ filtered,
346
352
  });
347
353
  }
348
354
  /** @internal */
package/entity/index.d.ts CHANGED
@@ -12,3 +12,4 @@ export * from './BaseEntity';
12
12
  export * from './WrappedEntity';
13
13
  export * from './wrap';
14
14
  export * from './defineEntity';
15
+ export * from './utils';
package/entity/index.js CHANGED
@@ -28,3 +28,4 @@ __exportStar(require("./BaseEntity"), exports);
28
28
  __exportStar(require("./WrappedEntity"), exports);
29
29
  __exportStar(require("./wrap"), exports);
30
30
  __exportStar(require("./defineEntity"), exports);
31
+ __exportStar(require("./utils"), exports);
package/entity/utils.d.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import type { EntityMetadata, PopulateOptions } from '../typings';
2
+ import { LoadStrategy, ReferenceKind } from '../enums';
2
3
  /**
3
4
  * @internal
4
5
  */
5
6
  export declare function expandDotPaths<Entity>(meta: EntityMetadata<Entity>, populate?: readonly (string | PopulateOptions<Entity>)[], normalized?: boolean): PopulateOptions<Entity>[];
7
+ /**
8
+ * Returns the loading strategy based on the provided hint.
9
+ * If `BALANCED` strategy is used, it will return JOINED if the property is a to-one relation.
10
+ * @internal
11
+ */
12
+ export declare function getLoadingStrategy(strategy: LoadStrategy | `${LoadStrategy}`, kind: ReferenceKind): LoadStrategy.SELECT_IN | LoadStrategy.JOINED;
package/entity/utils.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.expandDotPaths = expandDotPaths;
4
+ exports.getLoadingStrategy = getLoadingStrategy;
4
5
  const enums_1 = require("../enums");
5
- const core_1 = require("@mikro-orm/core");
6
+ const Utils_1 = require("../utils/Utils");
6
7
  /**
7
8
  * Expands `books.perex` like populate to use `children` array instead of the dot syntax
8
9
  */
@@ -20,7 +21,7 @@ function expandNestedPopulate(parentProp, parts, strategy, all) {
20
21
  * @internal
21
22
  */
22
23
  function expandDotPaths(meta, populate, normalized = false) {
23
- const ret = normalized ? populate : core_1.Utils.asArray(populate).map(field => {
24
+ const ret = normalized ? populate : Utils_1.Utils.asArray(populate).map(field => {
24
25
  if (typeof field === 'string') {
25
26
  return { field };
26
27
  }
@@ -58,3 +59,16 @@ function expandDotPaths(meta, populate, normalized = false) {
58
59
  }
59
60
  return ret;
60
61
  }
62
+ /**
63
+ * Returns the loading strategy based on the provided hint.
64
+ * If `BALANCED` strategy is used, it will return JOINED if the property is a to-one relation.
65
+ * @internal
66
+ */
67
+ function getLoadingStrategy(strategy, kind) {
68
+ if (strategy === enums_1.LoadStrategy.BALANCED) {
69
+ return [enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(kind)
70
+ ? enums_1.LoadStrategy.JOINED
71
+ : enums_1.LoadStrategy.SELECT_IN;
72
+ }
73
+ return strategy;
74
+ }
package/enums.d.ts CHANGED
@@ -108,7 +108,9 @@ export declare enum Cascade {
108
108
  }
109
109
  export declare enum LoadStrategy {
110
110
  SELECT_IN = "select-in",
111
- JOINED = "joined"
111
+ JOINED = "joined",
112
+ INNER_JOINED = "inner-joined",
113
+ BALANCED = "balanced"
112
114
  }
113
115
  export declare enum DataloaderType {
114
116
  NONE = 0,
package/enums.js CHANGED
@@ -125,6 +125,8 @@ var LoadStrategy;
125
125
  (function (LoadStrategy) {
126
126
  LoadStrategy["SELECT_IN"] = "select-in";
127
127
  LoadStrategy["JOINED"] = "joined";
128
+ LoadStrategy["INNER_JOINED"] = "inner-joined";
129
+ LoadStrategy["BALANCED"] = "balanced";
128
130
  })(LoadStrategy || (exports.LoadStrategy = LoadStrategy = {}));
129
131
  var DataloaderType;
130
132
  (function (DataloaderType) {
package/index.mjs CHANGED
@@ -184,6 +184,8 @@ export const createSqlFunction = mod.createSqlFunction;
184
184
  export const defineConfig = mod.defineConfig;
185
185
  export const defineEntity = mod.defineEntity;
186
186
  export const equals = mod.equals;
187
+ export const expandDotPaths = mod.expandDotPaths;
188
+ export const getLoadingStrategy = mod.getLoadingStrategy;
187
189
  export const getOnConflictFields = mod.getOnConflictFields;
188
190
  export const getOnConflictReturningFields = mod.getOnConflictReturningFields;
189
191
  export const helper = mod.helper;
@@ -622,7 +622,7 @@ class MetadataDiscovery {
622
622
  }
623
623
  data.properties[meta.name + '_owner'] = this.definePivotProperty(prop, meta.name + '_owner', meta.className, targetType + '_inverse', true, meta.className === targetType);
624
624
  data.properties[targetType + '_inverse'] = this.definePivotProperty(prop, targetType + '_inverse', targetType, meta.name + '_owner', false, meta.className === targetType);
625
- return this.metadata.set(data.className, data);
625
+ return this.metadata.set(data.className, EntitySchema_1.EntitySchema.fromMetadata(data).init().meta);
626
626
  }
627
627
  defineFixedOrderProperty(prop, targetType) {
628
628
  const pk = prop.fixedOrderColumn || this.namingStrategy.referenceColumnName();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.17-dev.65",
3
+ "version": "6.4.17-dev.66",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.3.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.4.17-dev.65",
67
+ "mikro-orm": "6.4.17-dev.66",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
package/typings.d.ts CHANGED
@@ -698,6 +698,7 @@ export type PopulateOptions<T> = {
698
698
  strategy?: LoadStrategy;
699
699
  all?: boolean;
700
700
  filter?: boolean;
701
+ joinType?: 'inner join' | 'left join';
701
702
  children?: PopulateOptions<T[keyof T]>[];
702
703
  };
703
704
  type Loadable<T extends object> = Collection<T, any> | Reference<T> | Ref<T> | readonly T[];
@@ -359,7 +359,7 @@ export interface MikroORMOptions<D extends IDatabaseDriver = IDatabaseDriver, EM
359
359
  useBatchUpdates?: boolean;
360
360
  batchSize: number;
361
361
  hydrator: HydratorConstructor;
362
- loadStrategy: LoadStrategy | 'select-in' | 'joined';
362
+ loadStrategy: LoadStrategy | `${LoadStrategy}`;
363
363
  dataloader: DataloaderType | boolean;
364
364
  populateWhere?: PopulateHint | `${PopulateHint}`;
365
365
  flushMode: FlushMode | 'commit' | 'auto' | 'always';