@mikro-orm/core 6.2.10-dev.9 → 6.2.10-dev.91

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 (84) hide show
  1. package/EntityManager.d.ts +1 -2
  2. package/EntityManager.js +26 -24
  3. package/decorators/Check.js +1 -2
  4. package/decorators/CreateRequestContext.js +2 -3
  5. package/decorators/Embeddable.js +1 -2
  6. package/decorators/Embedded.js +1 -2
  7. package/decorators/Entity.js +1 -2
  8. package/decorators/Enum.js +1 -2
  9. package/decorators/Filter.js +1 -2
  10. package/decorators/Formula.js +1 -2
  11. package/decorators/Indexed.d.ts +3 -3
  12. package/decorators/Indexed.js +2 -3
  13. package/decorators/ManyToMany.js +1 -2
  14. package/decorators/ManyToOne.js +1 -2
  15. package/decorators/OneToMany.js +2 -3
  16. package/decorators/OneToOne.d.ts +1 -1
  17. package/decorators/OneToOne.js +1 -2
  18. package/decorators/PrimaryKey.d.ts +3 -2
  19. package/decorators/PrimaryKey.js +2 -3
  20. package/decorators/Property.d.ts +1 -1
  21. package/decorators/Property.js +1 -2
  22. package/decorators/hooks.js +10 -11
  23. package/drivers/DatabaseDriver.js +1 -1
  24. package/drivers/IDatabaseDriver.d.ts +2 -1
  25. package/entity/ArrayCollection.d.ts +0 -1
  26. package/entity/EntityIdentifier.d.ts +1 -1
  27. package/entity/EntityLoader.js +3 -0
  28. package/entity/Reference.d.ts +0 -1
  29. package/entity/Reference.js +10 -7
  30. package/entity/WrappedEntity.d.ts +0 -1
  31. package/entity/wrap.js +2 -3
  32. package/events/TransactionEventBroadcaster.d.ts +2 -2
  33. package/index.d.ts +1 -1
  34. package/index.mjs +1 -0
  35. package/metadata/MetadataDiscovery.js +6 -4
  36. package/naming-strategy/AbstractNamingStrategy.d.ts +13 -0
  37. package/naming-strategy/AbstractNamingStrategy.js +25 -0
  38. package/naming-strategy/NamingStrategy.d.ts +27 -1
  39. package/package.json +2 -2
  40. package/platforms/Platform.d.ts +6 -2
  41. package/platforms/Platform.js +17 -5
  42. package/serialization/EntitySerializer.js +2 -2
  43. package/serialization/SerializationContext.d.ts +2 -2
  44. package/types/BigIntType.d.ts +2 -2
  45. package/types/BigIntType.js +1 -1
  46. package/types/BlobType.d.ts +0 -1
  47. package/types/CharacterType.d.ts +7 -0
  48. package/types/CharacterType.js +13 -0
  49. package/types/DateTimeType.d.ts +1 -0
  50. package/types/DateTimeType.js +3 -0
  51. package/types/DateType.d.ts +1 -0
  52. package/types/DateType.js +3 -0
  53. package/types/DecimalType.d.ts +2 -2
  54. package/types/IntervalType.d.ts +1 -0
  55. package/types/IntervalType.js +3 -0
  56. package/types/JsonType.js +1 -1
  57. package/types/StringType.d.ts +1 -0
  58. package/types/StringType.js +3 -0
  59. package/types/TimeType.d.ts +1 -0
  60. package/types/TimeType.js +3 -0
  61. package/types/Type.d.ts +16 -2
  62. package/types/Uint8ArrayType.d.ts +0 -1
  63. package/types/index.d.ts +19 -16
  64. package/types/index.js +34 -31
  65. package/typings.d.ts +24 -19
  66. package/unit-of-work/ChangeSet.d.ts +0 -1
  67. package/unit-of-work/ChangeSetPersister.d.ts +1 -1
  68. package/unit-of-work/ChangeSetPersister.js +5 -3
  69. package/unit-of-work/UnitOfWork.d.ts +1 -1
  70. package/unit-of-work/UnitOfWork.js +32 -18
  71. package/utils/Configuration.js +2 -2
  72. package/utils/ConfigurationLoader.js +1 -0
  73. package/utils/Cursor.d.ts +0 -1
  74. package/utils/DataloaderUtils.d.ts +3 -3
  75. package/utils/DataloaderUtils.js +4 -4
  76. package/utils/EntityComparator.d.ts +13 -0
  77. package/utils/EntityComparator.js +62 -34
  78. package/utils/RawQueryFragment.d.ts +1 -2
  79. package/utils/RawQueryFragment.js +4 -4
  80. package/utils/Utils.d.ts +4 -6
  81. package/utils/Utils.js +13 -10
  82. package/utils/clone.js +1 -2
  83. package/utils/upsert-utils.d.ts +3 -2
  84. package/utils/upsert-utils.js +4 -5
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { inspect } from 'util';
3
2
  import DataLoader from 'dataloader';
4
3
  import { type Configuration, Cursor } from './utils';
@@ -258,7 +257,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
258
257
  /**
259
258
  * Runs your callback wrapped inside a database transaction.
260
259
  */
261
- transactional<T>(cb: (em: this) => Promise<T>, options?: TransactionOptions): Promise<T>;
260
+ transactional<T>(cb: (em: this) => T | Promise<T>, options?: TransactionOptions): Promise<T>;
262
261
  /**
263
262
  * Starts new transaction bound to this EntityManager. Use `ctx` parameter to provide the parent when nesting transactions.
264
263
  */
package/EntityManager.js CHANGED
@@ -467,7 +467,7 @@ class EntityManager {
467
467
  * in database, the method returns `null`.
468
468
  */
469
469
  async refresh(entity, options = {}) {
470
- const fork = this.fork();
470
+ const fork = this.fork({ keepTransactionContext: true });
471
471
  const entityName = entity.constructor.name;
472
472
  const reloaded = await fork.findOne(entityName, entity, {
473
473
  schema: (0, entity_1.helper)(entity).__schema,
@@ -603,7 +603,7 @@ class EntityManager {
603
603
  em.prepareOptions(options);
604
604
  let entityName;
605
605
  let where;
606
- let entity;
606
+ let entity = null;
607
607
  if (data === undefined) {
608
608
  entityName = entityNameOrEntity.constructor.name;
609
609
  data = entityNameOrEntity;
@@ -633,9 +633,9 @@ class EntityManager {
633
633
  }
634
634
  }
635
635
  const unique = options.onConflictFields ?? meta.props.filter(p => p.unique).map(p => p.name);
636
- const propIndex = unique.findIndex(p => data[p] != null);
636
+ const propIndex = !utils_1.Utils.isRawSql(unique) && unique.findIndex(p => data[p] != null);
637
637
  if (options.onConflictFields || where == null) {
638
- if (propIndex >= 0) {
638
+ if (propIndex !== false && propIndex >= 0) {
639
639
  where = { [unique[propIndex]]: data[unique[propIndex]] };
640
640
  }
641
641
  else if (meta.uniques.length > 0) {
@@ -650,11 +650,6 @@ class EntityManager {
650
650
  }
651
651
  }
652
652
  }
653
- if (where == null) {
654
- const compositeUniqueProps = meta.uniques.map(u => utils_1.Utils.asArray(u.properties).join(' + '));
655
- const uniqueProps = meta.primaryKeys.concat(...unique).concat(compositeUniqueProps);
656
- throw new Error(`Unique property value required for upsert, provide one of: ${uniqueProps.join(', ')}`);
657
- }
658
653
  data = utils_1.QueryHelper.processObjectParams(data);
659
654
  em.validator.validateParams(data, 'insert data');
660
655
  if (em.eventManager.hasListeners(enums_1.EventType.beforeUpsert, meta)) {
@@ -666,18 +661,27 @@ class EntityManager {
666
661
  convertCustomTypes,
667
662
  ...options,
668
663
  });
664
+ em.unitOfWork.getChangeSetPersister().mapReturnedValues(entity, data, ret.row, meta, true);
669
665
  entity ??= em.entityFactory.create(entityName, data, {
670
666
  refresh: true,
671
667
  initialized: true,
672
668
  schema: options.schema,
673
669
  convertCustomTypes: true,
674
670
  });
675
- em.unitOfWork.getChangeSetPersister().mapReturnedValues(entity, data, ret.row, meta);
676
671
  const uniqueFields = options.onConflictFields ?? (utils_1.Utils.isPlainObject(where) ? Object.keys(where) : meta.primaryKeys);
677
672
  const returning = (0, utils_1.getOnConflictReturningFields)(meta, data, uniqueFields, options);
678
673
  if (options.onConflictAction === 'ignore' || !(0, entity_1.helper)(entity).hasPrimaryKey() || (returning.length > 0 && !(this.getPlatform().usesReturningStatement() && ret.row))) {
679
674
  const where = {};
680
- uniqueFields.forEach(prop => where[prop] = data[prop]);
675
+ if (Array.isArray(uniqueFields)) {
676
+ for (const prop of uniqueFields) {
677
+ if (data[prop] != null) {
678
+ where[prop] = data[prop];
679
+ }
680
+ else if (meta.primaryKeys.includes(prop) && ret.insertId != null) {
681
+ where[prop] = ret.insertId;
682
+ }
683
+ }
684
+ }
681
685
  const data2 = await this.driver.findOne(meta.className, where, {
682
686
  fields: returning,
683
687
  ctx: em.transactionContext,
@@ -791,11 +795,6 @@ class EntityManager {
791
795
  }
792
796
  }
793
797
  }
794
- if (where == null) {
795
- const compositeUniqueProps = meta.uniques.map(u => utils_1.Utils.asArray(u.properties).join(' + '));
796
- const uniqueProps = meta.primaryKeys.concat(...unique).concat(compositeUniqueProps);
797
- throw new Error(`Unique property value required for upsert, provide one of: ${uniqueProps.join(', ')}`);
798
- }
799
798
  row = utils_1.QueryHelper.processObjectParams(row);
800
799
  where = utils_1.QueryHelper.processWhere({
801
800
  where,
@@ -826,13 +825,13 @@ class EntityManager {
826
825
  entitiesByData.clear();
827
826
  const loadPK = new Map();
828
827
  allData.forEach((row, i) => {
828
+ em.unitOfWork.getChangeSetPersister().mapReturnedValues(utils_1.Utils.isEntity(data[i]) ? data[i] : null, utils_1.Utils.isEntity(data[i]) ? {} : data[i], res.rows?.[i], meta, true);
829
829
  const entity = utils_1.Utils.isEntity(data[i]) ? data[i] : em.entityFactory.create(entityName, row, {
830
830
  refresh: true,
831
831
  initialized: true,
832
832
  schema: options.schema,
833
833
  convertCustomTypes: true,
834
834
  });
835
- em.unitOfWork.getChangeSetPersister().mapReturnedValues(entity, utils_1.Utils.isEntity(data[i]) ? {} : data[i], res.rows?.[i], meta);
836
835
  if (!(0, entity_1.helper)(entity).hasPrimaryKey()) {
837
836
  loadPK.set(entity, allWhere[i]);
838
837
  }
@@ -850,14 +849,16 @@ class EntityManager {
850
849
  utils_1.Utils.keys(cond).forEach(key => add.add(key));
851
850
  }
852
851
  const where = { $or: [] };
853
- data.forEach((item, idx) => {
854
- where.$or[idx] = {};
855
- uniqueFields.forEach(prop => {
856
- where.$or[idx][prop] = item[prop];
852
+ if (Array.isArray(uniqueFields)) {
853
+ data.forEach((item, idx) => {
854
+ where.$or[idx] = {};
855
+ uniqueFields.forEach(prop => {
856
+ where.$or[idx][prop] = item[prop];
857
+ });
857
858
  });
858
- });
859
+ }
859
860
  const data2 = await this.driver.find(meta.className, where, {
860
- fields: returning.concat(...add).concat(...uniqueFields),
861
+ fields: returning.concat(...add).concat(...(Array.isArray(uniqueFields) ? uniqueFields : [])),
861
862
  ctx: em.transactionContext,
862
863
  convertCustomTypes: true,
863
864
  connectionType: 'write',
@@ -878,7 +879,7 @@ class EntityManager {
878
879
  }
879
880
  em.getHydrator().hydrate(entity, meta, row, em.entityFactory, 'full');
880
881
  }
881
- if (loadPK.size !== data2.length) {
882
+ if (loadPK.size !== data2.length && Array.isArray(uniqueFields)) {
882
883
  for (let i = 0; i < allData.length; i++) {
883
884
  const data = allData[i];
884
885
  const cond = uniqueFields.reduce((a, b) => {
@@ -1497,6 +1498,7 @@ class EntityManager {
1497
1498
  await this.entityLoader.populate(meta.className, [entity], preparedPopulate, {
1498
1499
  ...options,
1499
1500
  ...this.getPopulateWhere(where, options),
1501
+ orderBy: options.populateOrderBy ?? options.orderBy,
1500
1502
  convertCustomTypes: false,
1501
1503
  ignoreLazyScalarProperties: true,
1502
1504
  lookup: false,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Check = void 0;
3
+ exports.Check = Check;
4
4
  const metadata_1 = require("../metadata");
5
5
  const Utils_1 = require("../utils/Utils");
6
6
  function Check(options) {
@@ -14,4 +14,3 @@ function Check(options) {
14
14
  return Utils_1.Utils.propertyDecoratorReturnValue();
15
15
  };
16
16
  }
17
- exports.Check = Check;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EnsureRequestContext = exports.CreateRequestContext = void 0;
3
+ exports.CreateRequestContext = CreateRequestContext;
4
+ exports.EnsureRequestContext = EnsureRequestContext;
4
5
  const MikroORM_1 = require("../MikroORM");
5
6
  const RequestContext_1 = require("../utils/RequestContext");
6
7
  const EntityManager_1 = require("../EntityManager");
@@ -47,8 +48,6 @@ function CreateRequestContext(getContext, respectExistingContext = false) {
47
48
  return descriptor;
48
49
  };
49
50
  }
50
- exports.CreateRequestContext = CreateRequestContext;
51
51
  function EnsureRequestContext(getContext) {
52
52
  return CreateRequestContext(getContext, true);
53
53
  }
54
- exports.EnsureRequestContext = EnsureRequestContext;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Embeddable = void 0;
3
+ exports.Embeddable = Embeddable;
4
4
  const metadata_1 = require("../metadata");
5
5
  function Embeddable(options = {}) {
6
6
  return function (target) {
@@ -12,4 +12,3 @@ function Embeddable(options = {}) {
12
12
  return target;
13
13
  };
14
14
  }
15
- exports.Embeddable = Embeddable;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Embedded = void 0;
3
+ exports.Embedded = Embedded;
4
4
  const metadata_1 = require("../metadata");
5
5
  const utils_1 = require("../utils");
6
6
  const enums_1 = require("../enums");
@@ -18,4 +18,3 @@ function Embedded(type = {}, options = {}) {
18
18
  return utils_1.Utils.propertyDecoratorReturnValue();
19
19
  };
20
20
  }
21
- exports.Embedded = Embedded;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Entity = void 0;
3
+ exports.Entity = Entity;
4
4
  const metadata_1 = require("../metadata");
5
5
  const utils_1 = require("../utils");
6
6
  function Entity(options = {}) {
@@ -14,4 +14,3 @@ function Entity(options = {}) {
14
14
  return target;
15
15
  };
16
16
  }
17
- exports.Entity = Entity;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Enum = void 0;
3
+ exports.Enum = Enum;
4
4
  const metadata_1 = require("../metadata");
5
5
  const enums_1 = require("../enums");
6
6
  const Utils_1 = require("../utils/Utils");
@@ -17,4 +17,3 @@ function Enum(options = {}) {
17
17
  return Utils_1.Utils.propertyDecoratorReturnValue();
18
18
  };
19
19
  }
20
- exports.Enum = Enum;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Filter = void 0;
3
+ exports.Filter = Filter;
4
4
  const metadata_1 = require("../metadata");
5
5
  function Filter(options) {
6
6
  return function (target) {
@@ -9,4 +9,3 @@ function Filter(options) {
9
9
  return target;
10
10
  };
11
11
  }
12
- exports.Filter = Filter;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Formula = void 0;
3
+ exports.Formula = Formula;
4
4
  const metadata_1 = require("../metadata");
5
5
  const enums_1 = require("../enums");
6
6
  const Utils_1 = require("../utils/Utils");
@@ -16,4 +16,3 @@ function Formula(formula, options = {}) {
16
16
  return Utils_1.Utils.propertyDecoratorReturnValue();
17
17
  };
18
18
  }
19
- exports.Formula = Formula;
@@ -1,7 +1,7 @@
1
- import type { Dictionary } from '../typings';
1
+ import type { AnyEntity, Dictionary } from '../typings';
2
2
  import type { DeferMode } from '../enums';
3
- export declare function Index<T>(options?: IndexOptions<T>): (target: Partial<any>, propertyName?: string | undefined) => any;
4
- export declare function Unique<T>(options?: UniqueOptions<T>): (target: Partial<any>, propertyName?: string | undefined) => any;
3
+ export declare function Index<T>(options?: IndexOptions<T>): (target: AnyEntity, propertyName?: string) => any;
4
+ export declare function Unique<T>(options?: UniqueOptions<T>): (target: AnyEntity, propertyName?: string) => any;
5
5
  interface BaseOptions<T> {
6
6
  name?: string;
7
7
  properties?: keyof T | (keyof T)[];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Unique = exports.Index = void 0;
3
+ exports.Index = Index;
4
+ exports.Unique = Unique;
4
5
  const metadata_1 = require("../metadata");
5
6
  const Utils_1 = require("../utils/Utils");
6
7
  function createDecorator(options, unique) {
@@ -18,8 +19,6 @@ function createDecorator(options, unique) {
18
19
  function Index(options = {}) {
19
20
  return createDecorator(options, false);
20
21
  }
21
- exports.Index = Index;
22
22
  function Unique(options = {}) {
23
23
  return createDecorator(options, true);
24
24
  }
25
- exports.Unique = Unique;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ManyToMany = void 0;
3
+ exports.ManyToMany = ManyToMany;
4
4
  const metadata_1 = require("../metadata");
5
5
  const utils_1 = require("../utils");
6
6
  const enums_1 = require("../enums");
@@ -14,4 +14,3 @@ function ManyToMany(entity, mappedBy, options = {}) {
14
14
  return utils_1.Utils.propertyDecoratorReturnValue();
15
15
  };
16
16
  }
17
- exports.ManyToMany = ManyToMany;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ManyToOne = void 0;
3
+ exports.ManyToOne = ManyToOne;
4
4
  const metadata_1 = require("../metadata");
5
5
  const utils_1 = require("../utils");
6
6
  const enums_1 = require("../enums");
@@ -14,4 +14,3 @@ function ManyToOne(entity = {}, options = {}) {
14
14
  return utils_1.Utils.propertyDecoratorReturnValue();
15
15
  };
16
16
  }
17
- exports.ManyToOne = ManyToOne;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OneToMany = exports.createOneToDecorator = void 0;
3
+ exports.createOneToDecorator = createOneToDecorator;
4
+ exports.OneToMany = OneToMany;
4
5
  const metadata_1 = require("../metadata");
5
6
  const utils_1 = require("../utils");
6
7
  const enums_1 = require("../enums");
@@ -14,8 +15,6 @@ function createOneToDecorator(entity, mappedBy, options, kind) {
14
15
  return utils_1.Utils.propertyDecoratorReturnValue();
15
16
  };
16
17
  }
17
- exports.createOneToDecorator = createOneToDecorator;
18
18
  function OneToMany(entity, mappedBy, options = {}) {
19
19
  return createOneToDecorator(entity, mappedBy, options, enums_1.ReferenceKind.ONE_TO_MANY);
20
20
  }
21
- exports.OneToMany = OneToMany;
@@ -1,7 +1,7 @@
1
1
  import { type DeferMode } from '../enums';
2
2
  import { type OneToManyOptions } from './OneToMany';
3
3
  import type { AnyString, EntityName } from '../typings';
4
- export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target>), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (target: Partial<any>, propertyName: string) => any;
4
+ export declare function OneToOne<Target, Owner>(entity?: OneToOneOptions<Owner, Target> | string | ((e: Owner) => EntityName<Target>), mappedByOrOptions?: (string & keyof Target) | ((e: Target) => any) | Partial<OneToOneOptions<Owner, Target>>, options?: Partial<OneToOneOptions<Owner, Target>>): (target: import("../typings").AnyEntity, propertyName: string) => any;
5
5
  export interface OneToOneOptions<Owner, Target> extends Partial<Omit<OneToManyOptions<Owner, Target>, 'orderBy'>> {
6
6
  owner?: boolean;
7
7
  inversedBy?: (string & keyof Target) | ((e: Target) => any);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OneToOne = void 0;
3
+ exports.OneToOne = OneToOne;
4
4
  const enums_1 = require("../enums");
5
5
  const OneToMany_1 = require("./OneToMany");
6
6
  function OneToOne(entity, mappedByOrOptions, options = {}) {
@@ -8,4 +8,3 @@ function OneToOne(entity, mappedByOrOptions, options = {}) {
8
8
  options = typeof mappedByOrOptions === 'object' ? { ...mappedByOrOptions, ...options } : options;
9
9
  return (0, OneToMany_1.createOneToDecorator)(entity, mappedBy, options, enums_1.ReferenceKind.ONE_TO_ONE);
10
10
  }
11
- exports.OneToOne = OneToOne;
@@ -1,6 +1,7 @@
1
1
  import type { PropertyOptions } from './Property';
2
- export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (target: Partial<any>, propertyName: string) => any;
3
- export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (target: Partial<any>, propertyName: string) => any;
2
+ import type { AnyEntity } from '../typings';
3
+ export declare function PrimaryKey<T extends object>(options?: PrimaryKeyOptions<T>): (target: AnyEntity, propertyName: string) => any;
4
+ export declare function SerializedPrimaryKey<T extends object>(options?: SerializedPrimaryKeyOptions<T>): (target: AnyEntity, propertyName: string) => any;
4
5
  export interface PrimaryKeyOptions<T> extends PropertyOptions<T> {
5
6
  }
6
7
  export interface SerializedPrimaryKeyOptions<T> extends PropertyOptions<T> {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SerializedPrimaryKey = exports.PrimaryKey = void 0;
3
+ exports.PrimaryKey = PrimaryKey;
4
+ exports.SerializedPrimaryKey = SerializedPrimaryKey;
4
5
  const metadata_1 = require("../metadata");
5
6
  const enums_1 = require("../enums");
6
7
  const Utils_1 = require("../utils/Utils");
@@ -17,8 +18,6 @@ function createDecorator(options, serialized) {
17
18
  function PrimaryKey(options = {}) {
18
19
  return createDecorator(options, false);
19
20
  }
20
- exports.PrimaryKey = PrimaryKey;
21
21
  function SerializedPrimaryKey(options = {}) {
22
22
  return createDecorator(options, true);
23
23
  }
24
- exports.SerializedPrimaryKey = SerializedPrimaryKey;
@@ -213,7 +213,7 @@ export type PropertyOptions<Owner> = {
213
213
  *
214
214
  * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
215
215
  */
216
- ignoreSchemaChanges?: ('type' | 'extra')[];
216
+ ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
217
217
  };
218
218
  export interface ReferenceOptions<Owner, Target> extends PropertyOptions<Owner> {
219
219
  entity?: string | (() => EntityName<Target>);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Property = void 0;
3
+ exports.Property = Property;
4
4
  const metadata_1 = require("../metadata");
5
5
  const utils_1 = require("../utils");
6
6
  const enums_1 = require("../enums");
@@ -32,4 +32,3 @@ function Property(options = {}) {
32
32
  return utils_1.Utils.propertyDecoratorReturnValue();
33
33
  };
34
34
  }
35
- exports.Property = Property;
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AfterDelete = exports.BeforeDelete = exports.OnLoad = exports.OnInit = exports.AfterUpsert = exports.BeforeUpsert = exports.AfterUpdate = exports.BeforeUpdate = exports.AfterCreate = exports.BeforeCreate = void 0;
3
+ exports.BeforeCreate = BeforeCreate;
4
+ exports.AfterCreate = AfterCreate;
5
+ exports.BeforeUpdate = BeforeUpdate;
6
+ exports.AfterUpdate = AfterUpdate;
7
+ exports.BeforeUpsert = BeforeUpsert;
8
+ exports.AfterUpsert = AfterUpsert;
9
+ exports.OnInit = OnInit;
10
+ exports.OnLoad = OnLoad;
11
+ exports.BeforeDelete = BeforeDelete;
12
+ exports.AfterDelete = AfterDelete;
4
13
  const metadata_1 = require("../metadata");
5
14
  const enums_1 = require("../enums");
6
15
  function hook(type) {
@@ -15,46 +24,36 @@ function hook(type) {
15
24
  function BeforeCreate() {
16
25
  return hook(enums_1.EventType.beforeCreate);
17
26
  }
18
- exports.BeforeCreate = BeforeCreate;
19
27
  function AfterCreate() {
20
28
  return hook(enums_1.EventType.afterCreate);
21
29
  }
22
- exports.AfterCreate = AfterCreate;
23
30
  function BeforeUpdate() {
24
31
  return hook(enums_1.EventType.beforeUpdate);
25
32
  }
26
- exports.BeforeUpdate = BeforeUpdate;
27
33
  function AfterUpdate() {
28
34
  return hook(enums_1.EventType.afterUpdate);
29
35
  }
30
- exports.AfterUpdate = AfterUpdate;
31
36
  function BeforeUpsert() {
32
37
  return hook(enums_1.EventType.beforeUpsert);
33
38
  }
34
- exports.BeforeUpsert = BeforeUpsert;
35
39
  function AfterUpsert() {
36
40
  return hook(enums_1.EventType.afterUpsert);
37
41
  }
38
- exports.AfterUpsert = AfterUpsert;
39
42
  function OnInit() {
40
43
  return hook(enums_1.EventType.onInit);
41
44
  }
42
- exports.OnInit = OnInit;
43
45
  function OnLoad() {
44
46
  return hook(enums_1.EventType.onLoad);
45
47
  }
46
- exports.OnLoad = OnLoad;
47
48
  /**
48
49
  * Called before deleting entity, but only when providing initialized entity to EM#remove()
49
50
  */
50
51
  function BeforeDelete() {
51
52
  return hook(enums_1.EventType.beforeDelete);
52
53
  }
53
- exports.BeforeDelete = BeforeDelete;
54
54
  /**
55
55
  * Called after deleting entity, but only when providing initialized entity to EM#remove()
56
56
  */
57
57
  function AfterDelete() {
58
58
  return hook(enums_1.EventType.afterDelete);
59
59
  }
60
- exports.AfterDelete = AfterDelete;
@@ -204,7 +204,7 @@ class DatabaseDriver {
204
204
  const copy = data[k];
205
205
  delete data[k];
206
206
  if (prop.array) {
207
- data[prop.fieldNames[0]] = copy.map((item) => this.mapDataToFieldNames(item, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes, true));
207
+ data[prop.fieldNames[0]] = copy?.map((item) => this.mapDataToFieldNames(item, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes, true));
208
208
  }
209
209
  else {
210
210
  data[prop.fieldNames[0]] = this.mapDataToFieldNames(copy, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes, true);
@@ -8,6 +8,7 @@ import type { EntityManager } from '../EntityManager';
8
8
  import type { DriverException } from '../exceptions';
9
9
  import type { Configuration } from '../utils/Configuration';
10
10
  import type { LoggingOptions, LogContext } from '../logging';
11
+ import type { RawQueryFragment } from '../utils/RawQueryFragment';
11
12
  export declare const EntityManagerType: unique symbol;
12
13
  export interface IDatabaseDriver<C extends Connection = Connection> {
13
14
  [EntityManagerType]: EntityManager<this>;
@@ -139,7 +140,7 @@ export interface NativeInsertUpdateManyOptions<T> extends NativeInsertUpdateOpti
139
140
  processCollections?: boolean;
140
141
  }
141
142
  export interface UpsertOptions<Entity> extends Omit<NativeInsertUpdateOptions<Entity>, 'upsert'> {
142
- onConflictFields?: (keyof Entity)[];
143
+ onConflictFields?: (keyof Entity)[] | RawQueryFragment;
143
144
  onConflictAction?: 'ignore' | 'merge';
144
145
  onConflictMergeFields?: (keyof Entity)[];
145
146
  onConflictExcludeFields?: (keyof Entity)[];
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { inspect } from 'util';
3
2
  import type { EntityDTO, EntityProperty, IPrimaryKey, Primary } from '../typings';
4
3
  import { Reference } from './Reference';
@@ -4,7 +4,7 @@ import type { IPrimaryKey } from '../typings';
4
4
  */
5
5
  export declare class EntityIdentifier {
6
6
  private value?;
7
- constructor(value?: import("../typings").IPrimaryKeyValue | undefined);
7
+ constructor(value?: IPrimaryKey | undefined);
8
8
  setValue(value: IPrimaryKey): void;
9
9
  getValue<T extends IPrimaryKey = IPrimaryKey>(): T;
10
10
  }
@@ -51,6 +51,9 @@ class EntityLoader {
51
51
  for (const pop of populate) {
52
52
  await this.populateField(entityName, entities, pop, options);
53
53
  }
54
+ for (const entity of entities) {
55
+ visited.delete(entity);
56
+ }
54
57
  }
55
58
  normalizePopulate(entityName, populate, strategy, lookup = true) {
56
59
  const meta = this.metadata.find(entityName);
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { inspect } from 'util';
3
2
  import type { AddEager, Dictionary, EntityClass, EntityKey, EntityProperty, Loaded, LoadedReference, Primary, Ref } from '../typings';
4
3
  import type { FindOneOptions, FindOneOrFailOptions } from '../drivers/IDatabaseDriver';
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Ref = exports.rel = exports.ref = exports.ScalarReference = exports.Reference = void 0;
3
+ exports.Ref = exports.ScalarReference = exports.Reference = void 0;
4
+ exports.ref = ref;
5
+ exports.rel = rel;
4
6
  const util_1 = require("util");
5
7
  const enums_1 = require("../enums");
6
8
  const wrap_1 = require("./wrap");
@@ -77,11 +79,14 @@ class Reference {
77
79
  * the method returns `null`. Use `loadOrFail()` if you want an error to be thrown in such a case.
78
80
  */
79
81
  async load(options = {}) {
82
+ const wrapped = (0, wrap_1.helper)(this.entity);
83
+ if (!wrapped.__em) {
84
+ return this.entity;
85
+ }
86
+ if (this.isInitialized() && !options.refresh && options.populate) {
87
+ await wrapped.__em.populate(this.entity, options.populate, options);
88
+ }
80
89
  if (!this.isInitialized() || options.refresh) {
81
- const wrapped = (0, wrap_1.helper)(this.entity);
82
- if (!wrapped.__em) {
83
- return this.entity;
84
- }
85
90
  if (options.dataloader ?? [enums_1.DataloaderType.ALL, enums_1.DataloaderType.REFERENCE].includes(utils_1.DataloaderUtils.getDataloaderType(wrapped.__em.config.get('dataloader')))) {
86
91
  // eslint-disable-next-line dot-notation
87
92
  return wrapped.__em['refLoader'].load([this, options]);
@@ -229,7 +234,6 @@ function ref(entityOrType, pk) {
229
234
  }
230
235
  return Reference.createFromPK(entityOrType, pk);
231
236
  }
232
- exports.ref = ref;
233
237
  /**
234
238
  * shortcut for `Reference.createNakedFromPK(entityType, pk)`
235
239
  */
@@ -239,4 +243,3 @@ function rel(entityType, pk) {
239
243
  }
240
244
  return Reference.createNakedFromPK(entityType, pk);
241
245
  }
242
- exports.rel = rel;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { PopulatePath } from '../enums';
3
2
  import { inspect } from 'util';
4
3
  import type { EntityManager } from '../EntityManager';
package/entity/wrap.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.helper = exports.wrap = void 0;
3
+ exports.wrap = wrap;
4
+ exports.helper = helper;
4
5
  /**
5
6
  * wraps entity type with WrappedEntity internal properties and helpers like init/isInitialized/populated/toJSON
6
7
  * use `preferHelper = true` to have access to the internal `__` properties like `__meta` or `__em`
@@ -14,7 +15,6 @@ function wrap(entity, preferHelper = false) {
14
15
  }
15
16
  return entity.__helper ?? entity;
16
17
  }
17
- exports.wrap = wrap;
18
18
  /**
19
19
  * wraps entity type with WrappedEntity internal properties and helpers like init/isInitialized/populated/toJSON
20
20
  * use `preferHelper = true` to have access to the internal `__` properties like `__meta` or `__em`
@@ -23,4 +23,3 @@ exports.wrap = wrap;
23
23
  function helper(entity) {
24
24
  return entity.__helper;
25
25
  }
26
- exports.helper = helper;
@@ -6,11 +6,11 @@ export declare class TransactionEventBroadcaster {
6
6
  private readonly em;
7
7
  private readonly uow?;
8
8
  readonly context?: {
9
- topLevelTransaction?: boolean | undefined;
9
+ topLevelTransaction?: boolean;
10
10
  } | undefined;
11
11
  private readonly eventManager;
12
12
  constructor(em: EntityManager, uow?: UnitOfWork | undefined, context?: {
13
- topLevelTransaction?: boolean | undefined;
13
+ topLevelTransaction?: boolean;
14
14
  } | undefined);
15
15
  dispatchEvent(event: TransactionEventType, transaction?: Transaction): Promise<void>;
16
16
  isTopLevel(): boolean;
package/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @packageDocumentation
3
3
  * @module core
4
4
  */
5
- export { Constructor, ConnectionType, Dictionary, PrimaryKeyProp, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, AnyEntity, EntityClass, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, GetRepository, EntityRepositoryType, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, EntityClassGroup, OptionalProps, EagerProps, HiddenProps, RequiredEntityData, CheckCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, FilterKey, Opt, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, Hidden, FilterValue, MergeLoaded, MergeSelected, Config, DefineConfig, TypeConfig, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, } from './typings';
5
+ export { Constructor, ConnectionType, Dictionary, PrimaryKeyProp, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, AnyEntity, EntityClass, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, GetRepository, EntityRepositoryType, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, EntityClassGroup, OptionalProps, EagerProps, HiddenProps, RequiredEntityData, CheckCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, FilterKey, Opt, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, Hidden, FilterValue, MergeLoaded, MergeSelected, Config, DefineConfig, TypeConfig, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, } from './typings';
6
6
  export * from './enums';
7
7
  export * from './errors';
8
8
  export * from './exceptions';