@mikro-orm/core 6.4.13-dev.9 → 6.4.14-dev.0

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.
@@ -486,7 +486,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
486
486
  * @internal
487
487
  */
488
488
  tryCache<T extends object, R>(entityName: string, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
489
- data?: R;
489
+ data?: R | null;
490
490
  key: string;
491
491
  } | undefined>;
492
492
  /**
package/EntityManager.js CHANGED
@@ -529,14 +529,16 @@ class EntityManager {
529
529
  options.populate = await em.preparePopulate(entityName, options);
530
530
  const cacheKey = em.cacheKey(entityName, options, 'em.findOne', where);
531
531
  const cached = await em.tryCache(entityName, options.cache, cacheKey, options.refresh, true);
532
- if (cached?.data) {
533
- await em.entityLoader.populate(entityName, [cached.data], options.populate, {
534
- ...options,
535
- ...em.getPopulateWhere(where, options),
536
- convertCustomTypes: false,
537
- ignoreLazyScalarProperties: true,
538
- lookup: false,
539
- });
532
+ if (cached?.data !== undefined) {
533
+ if (cached.data) {
534
+ await em.entityLoader.populate(entityName, [cached.data], options.populate, {
535
+ ...options,
536
+ ...em.getPopulateWhere(where, options),
537
+ convertCustomTypes: false,
538
+ ignoreLazyScalarProperties: true,
539
+ lookup: false,
540
+ });
541
+ }
540
542
  return cached.data;
541
543
  }
542
544
  options = { ...options };
@@ -1683,6 +1685,9 @@ class EntityManager {
1683
1685
  const em = this.getContext();
1684
1686
  const cacheKey = Array.isArray(config) ? config[0] : JSON.stringify(key);
1685
1687
  const cached = await em.resultCache.get(cacheKey);
1688
+ if (cached === null) {
1689
+ return { key: cacheKey, data: null };
1690
+ }
1686
1691
  if (cached) {
1687
1692
  let data;
1688
1693
  if (Array.isArray(cached) && merge) {
@@ -525,7 +525,7 @@ class EntityLoader {
525
525
  if (refresh) {
526
526
  return entities;
527
527
  }
528
- return entities.filter(e => !e[field]?.__helper?.__initialized);
528
+ return entities.filter(e => e[field] !== null && !e[field]?.__helper?.__initialized);
529
529
  }
530
530
  lookupAllRelationships(entityName) {
531
531
  const ret = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.13-dev.9",
3
+ "version": "6.4.14-dev.0",
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.13-dev.9",
67
+ "mikro-orm": "6.4.14-dev.0",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
package/typings.d.ts CHANGED
@@ -274,7 +274,7 @@ type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, Extra
274
274
  } : Primary<U>;
275
275
  export type EntityDTOProp<E, T, C extends TypeConfig = never> = T extends Scalar ? T : T extends {
276
276
  __serialized?: infer U;
277
- } ? U : T extends LoadedReference<infer U> ? EntityDTO<U, C> : T extends Reference<infer U> ? PrimaryOrObject<E, U, C> : T extends ScalarReference<infer U> ? U : T extends LoadedCollection<infer U> ? EntityDTO<U, C>[] : T extends Collection<infer U> ? PrimaryOrObject<E, U, C>[] : T extends readonly (infer U)[] ? (T extends readonly any[] ? T : U[]) : T extends Relation<T> ? EntityDTO<T, C> : T;
277
+ } ? (IsUnknown<U> extends false ? U : T) : T extends LoadedReference<infer U> ? EntityDTO<U, C> : T extends Reference<infer U> ? PrimaryOrObject<E, U, C> : T extends ScalarReference<infer U> ? U : T extends LoadedCollection<infer U> ? EntityDTO<U, C>[] : T extends Collection<infer U> ? PrimaryOrObject<E, U, C>[] : T extends readonly (infer U)[] ? (T extends readonly any[] ? T : U[]) : T extends Relation<T> ? EntityDTO<T, C> : T;
278
278
  type DTOProbablyOptionalProps<T> = NonNullable<NullableKeys<T, undefined>>;
279
279
  type DTOIsOptional<T, K extends keyof T> = T[K] extends LoadedCollection<any> ? false : K extends PrimaryProperty<T> ? false : K extends DTOProbablyOptionalProps<T> ? true : false;
280
280
  type DTORequiredKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;