@mikro-orm/core 7.0.0-dev.51 → 7.0.0-dev.52

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.51",
4
+ "version": "7.0.0-dev.52",
5
5
  "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.",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
@@ -54,7 +54,7 @@
54
54
  "dataloader": "2.2.3",
55
55
  "dotenv": "17.2.3",
56
56
  "esprima": "4.0.1",
57
- "mikro-orm": "7.0.0-dev.51",
57
+ "mikro-orm": "7.0.0-dev.52",
58
58
  "reflect-metadata": "0.2.2",
59
59
  "tinyglobby": "0.2.13"
60
60
  }
package/utils/Utils.d.ts CHANGED
@@ -134,7 +134,7 @@ export declare class Utils {
134
134
  static getCompositeKeyHash<T>(data: EntityData<T>, meta: EntityMetadata<T>, convertCustomTypes?: boolean, platform?: Platform, flat?: boolean): string;
135
135
  static getPrimaryKeyHash(pks: (string | Buffer | Date)[]): string;
136
136
  static splitPrimaryKeys<T extends object>(key: string): EntityKey<T>[];
137
- static getPrimaryKeyValues<T>(entity: T, primaryKeys: string[] | EntityMetadata<T>, allowScalar?: boolean, convertCustomTypes?: boolean): any;
137
+ static getPrimaryKeyValues<T>(entity: T, meta: EntityMetadata<T>, allowScalar?: boolean, convertCustomTypes?: boolean): any;
138
138
  static getPrimaryKeyCond<T>(entity: T, primaryKeys: EntityKey<T>[]): Record<string, Primary<T>> | null;
139
139
  /**
140
140
  * Maps nested FKs from `[1, 2, 3]` to `[1, [2, 3]]`.
package/utils/Utils.js CHANGED
@@ -6,7 +6,7 @@ import { existsSync, mkdirSync, readFileSync } from 'node:fs';
6
6
  import { createHash } from 'node:crypto';
7
7
  import { tokenize } from 'esprima';
8
8
  import { clone } from './clone.js';
9
- import { ARRAY_OPERATORS, JSON_KEY_OPERATORS, GroupOperator, PlainObject, QueryOperator, ReferenceKind } from '../enums.js';
9
+ import { ARRAY_OPERATORS, GroupOperator, JSON_KEY_OPERATORS, PlainObject, QueryOperator, ReferenceKind, } from '../enums.js';
10
10
  import { helper } from '../entity/wrap.js';
11
11
  export const ObjectBindingPattern = Symbol('ObjectBindingPattern');
12
12
  function compareConstructors(a, b) {
@@ -486,8 +486,7 @@ export class Utils {
486
486
  static splitPrimaryKeys(key) {
487
487
  return key.split(this.PK_SEPARATOR);
488
488
  }
489
- // TODO v7: remove support for `primaryKeys: string[]`
490
- static getPrimaryKeyValues(entity, primaryKeys, allowScalar = false, convertCustomTypes = false) {
489
+ static getPrimaryKeyValues(entity, meta, allowScalar = false, convertCustomTypes = false) {
491
490
  /* v8 ignore next 3 */
492
491
  if (entity == null) {
493
492
  return entity;
@@ -498,15 +497,13 @@ export class Utils {
498
497
  }
499
498
  return val;
500
499
  }
501
- const meta = Array.isArray(primaryKeys) ? undefined : primaryKeys;
502
- primaryKeys = Array.isArray(primaryKeys) ? primaryKeys : meta.primaryKeys;
503
500
  let pk;
504
501
  if (Utils.isEntity(entity, true)) {
505
502
  pk = helper(entity).getPrimaryKey(convertCustomTypes);
506
503
  }
507
504
  else {
508
- pk = primaryKeys.reduce((o, pk) => {
509
- const targetMeta = meta?.properties[pk].targetMeta;
505
+ pk = meta.primaryKeys.reduce((o, pk) => {
506
+ const targetMeta = meta.properties[pk].targetMeta;
510
507
  if (targetMeta && Utils.isPlainObject(entity[pk])) {
511
508
  o[pk] = Utils.getPrimaryKeyValues(entity[pk], targetMeta, allowScalar, convertCustomTypes);
512
509
  }
@@ -516,12 +513,12 @@ export class Utils {
516
513
  return o;
517
514
  }, {});
518
515
  }
519
- if (primaryKeys.length > 1) {
516
+ if (meta.primaryKeys.length > 1) {
520
517
  return toArray(pk);
521
518
  }
522
519
  if (allowScalar) {
523
520
  if (Utils.isPlainObject(pk)) {
524
- return pk[primaryKeys[0]];
521
+ return pk[(meta.primaryKeys)[0]];
525
522
  }
526
523
  return pk;
527
524
  }