@mikro-orm/core 7.0.0-rc.2 → 7.0.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.
Files changed (114) hide show
  1. package/EntityManager.d.ts +4 -16
  2. package/EntityManager.js +248 -181
  3. package/MikroORM.d.ts +4 -6
  4. package/MikroORM.js +24 -24
  5. package/README.md +5 -4
  6. package/cache/FileCacheAdapter.d.ts +1 -5
  7. package/cache/FileCacheAdapter.js +22 -24
  8. package/cache/GeneratedCacheAdapter.d.ts +1 -1
  9. package/cache/GeneratedCacheAdapter.js +6 -6
  10. package/cache/MemoryCacheAdapter.d.ts +1 -2
  11. package/cache/MemoryCacheAdapter.js +8 -8
  12. package/cache/index.d.ts +1 -1
  13. package/cache/index.js +0 -1
  14. package/connections/Connection.d.ts +1 -0
  15. package/connections/Connection.js +43 -14
  16. package/drivers/DatabaseDriver.d.ts +0 -2
  17. package/drivers/DatabaseDriver.js +28 -12
  18. package/drivers/IDatabaseDriver.d.ts +43 -0
  19. package/entity/Collection.d.ts +1 -9
  20. package/entity/Collection.js +124 -108
  21. package/entity/EntityAssigner.js +23 -11
  22. package/entity/EntityFactory.d.ts +1 -8
  23. package/entity/EntityFactory.js +79 -59
  24. package/entity/EntityHelper.js +25 -16
  25. package/entity/EntityLoader.d.ts +1 -3
  26. package/entity/EntityLoader.js +90 -60
  27. package/entity/Reference.d.ts +2 -3
  28. package/entity/Reference.js +48 -19
  29. package/entity/WrappedEntity.d.ts +4 -2
  30. package/entity/WrappedEntity.js +5 -1
  31. package/entity/defineEntity.d.ts +42 -85
  32. package/entity/utils.js +28 -26
  33. package/entity/validators.js +2 -1
  34. package/enums.d.ts +2 -1
  35. package/enums.js +13 -17
  36. package/errors.d.ts +11 -11
  37. package/errors.js +8 -8
  38. package/events/EventManager.d.ts +1 -4
  39. package/events/EventManager.js +26 -23
  40. package/events/index.d.ts +1 -1
  41. package/events/index.js +0 -1
  42. package/exceptions.js +9 -2
  43. package/hydration/ObjectHydrator.d.ts +1 -2
  44. package/hydration/ObjectHydrator.js +41 -27
  45. package/index.d.ts +1 -1
  46. package/index.js +1 -1
  47. package/logging/DefaultLogger.js +6 -7
  48. package/logging/Logger.d.ts +2 -1
  49. package/logging/colors.js +2 -5
  50. package/logging/index.d.ts +1 -1
  51. package/logging/index.js +0 -1
  52. package/metadata/EntitySchema.d.ts +3 -3
  53. package/metadata/EntitySchema.js +12 -2
  54. package/metadata/MetadataDiscovery.d.ts +1 -9
  55. package/metadata/MetadataDiscovery.js +251 -179
  56. package/metadata/MetadataProvider.js +26 -1
  57. package/metadata/MetadataStorage.d.ts +1 -5
  58. package/metadata/MetadataStorage.js +37 -39
  59. package/metadata/MetadataValidator.js +20 -5
  60. package/metadata/discover-entities.js +1 -1
  61. package/metadata/index.d.ts +1 -1
  62. package/metadata/index.js +0 -1
  63. package/metadata/types.d.ts +2 -2
  64. package/naming-strategy/AbstractNamingStrategy.js +6 -3
  65. package/naming-strategy/EntityCaseNamingStrategy.js +1 -1
  66. package/naming-strategy/index.d.ts +1 -1
  67. package/naming-strategy/index.js +0 -1
  68. package/not-supported.js +5 -1
  69. package/package.json +38 -38
  70. package/platforms/Platform.d.ts +24 -1
  71. package/platforms/Platform.js +106 -27
  72. package/serialization/EntitySerializer.js +8 -4
  73. package/serialization/EntityTransformer.js +4 -1
  74. package/serialization/SerializationContext.d.ts +4 -8
  75. package/serialization/SerializationContext.js +21 -16
  76. package/types/UuidType.d.ts +2 -0
  77. package/types/UuidType.js +14 -2
  78. package/types/index.d.ts +2 -1
  79. package/typings.d.ts +35 -24
  80. package/typings.js +9 -9
  81. package/unit-of-work/ChangeSet.js +4 -4
  82. package/unit-of-work/ChangeSetComputer.d.ts +1 -6
  83. package/unit-of-work/ChangeSetComputer.js +29 -27
  84. package/unit-of-work/ChangeSetPersister.d.ts +1 -9
  85. package/unit-of-work/ChangeSetPersister.js +63 -58
  86. package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
  87. package/unit-of-work/CommitOrderCalculator.js +17 -15
  88. package/unit-of-work/IdentityMap.d.ts +2 -5
  89. package/unit-of-work/IdentityMap.js +18 -18
  90. package/unit-of-work/UnitOfWork.d.ts +12 -20
  91. package/unit-of-work/UnitOfWork.js +228 -191
  92. package/utils/AbstractMigrator.d.ts +2 -2
  93. package/utils/AbstractMigrator.js +10 -12
  94. package/utils/AbstractSchemaGenerator.js +2 -1
  95. package/utils/AsyncContext.js +1 -1
  96. package/utils/Configuration.d.ts +90 -189
  97. package/utils/Configuration.js +97 -77
  98. package/utils/Cursor.d.ts +3 -3
  99. package/utils/Cursor.js +8 -6
  100. package/utils/DataloaderUtils.js +15 -12
  101. package/utils/EntityComparator.d.ts +8 -15
  102. package/utils/EntityComparator.js +100 -92
  103. package/utils/QueryHelper.d.ts +16 -1
  104. package/utils/QueryHelper.js +108 -50
  105. package/utils/RawQueryFragment.d.ts +4 -4
  106. package/utils/RawQueryFragment.js +3 -2
  107. package/utils/TransactionManager.js +3 -3
  108. package/utils/Utils.d.ts +2 -2
  109. package/utils/Utils.js +39 -32
  110. package/utils/clone.js +5 -0
  111. package/utils/env-vars.js +6 -5
  112. package/utils/fs-utils.d.ts +3 -17
  113. package/utils/fs-utils.js +2 -5
  114. package/utils/upsert-utils.js +7 -4
@@ -15,6 +15,7 @@ type MigrateOptions = {
15
15
  transaction?: Transaction;
16
16
  };
17
17
  export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implements IMigrator {
18
+ #private;
18
19
  protected readonly em: D[typeof EntityManagerType];
19
20
  protected runner: IMigrationRunner;
20
21
  protected storage: IMigratorStorage;
@@ -24,7 +25,6 @@ export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implem
24
25
  protected readonly options: MigrationsOptions;
25
26
  protected absolutePath: string;
26
27
  protected initialized: boolean;
27
- private readonly listeners;
28
28
  constructor(em: D[typeof EntityManagerType]);
29
29
  protected abstract createRunner(): IMigrationRunner;
30
30
  protected abstract createStorage(): IMigratorStorage;
@@ -95,7 +95,7 @@ export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implem
95
95
  private filterDown;
96
96
  private getMigrationFilename;
97
97
  private prefix;
98
- private runMigrations;
98
+ protected runMigrations(method: 'up' | 'down', options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>;
99
99
  private runInTransaction;
100
100
  }
101
101
  export {};
@@ -9,7 +9,7 @@ export class AbstractMigrator {
9
9
  options;
10
10
  absolutePath;
11
11
  initialized = false;
12
- listeners = new Map();
12
+ #listeners = new Map();
13
13
  constructor(em) {
14
14
  this.em = em;
15
15
  this.driver = this.em.getDriver();
@@ -22,17 +22,17 @@ export class AbstractMigrator {
22
22
  * @inheritDoc
23
23
  */
24
24
  on(eventName, listener) {
25
- if (!this.listeners.has(eventName)) {
26
- this.listeners.set(eventName, new Set());
25
+ if (!this.#listeners.has(eventName)) {
26
+ this.#listeners.set(eventName, new Set());
27
27
  }
28
- this.listeners.get(eventName).add(listener);
28
+ this.#listeners.get(eventName).add(listener);
29
29
  return this;
30
30
  }
31
31
  /**
32
32
  * @inheritDoc
33
33
  */
34
34
  off(eventName, listener) {
35
- this.listeners.get(eventName)?.delete(listener);
35
+ this.#listeners.get(eventName)?.delete(listener);
36
36
  return this;
37
37
  }
38
38
  /**
@@ -49,9 +49,7 @@ export class AbstractMigrator {
49
49
  await this.init();
50
50
  const all = await this.discoverMigrations();
51
51
  const executed = new Set(await this.storage.executed());
52
- return all
53
- .filter(m => !executed.has(m.name))
54
- .map(m => ({ name: m.name, path: m.path }));
52
+ return all.filter(m => !executed.has(m.name)).map(m => ({ name: m.name, path: m.path }));
55
53
  }
56
54
  /**
57
55
  * @inheritDoc
@@ -74,7 +72,7 @@ export class AbstractMigrator {
74
72
  const { fs } = await import('@mikro-orm/core/fs-utils');
75
73
  this.detectSourceFolder(fs);
76
74
  /* v8 ignore next */
77
- const key = (this.config.get('preferTs', Utils.detectTypeScriptSupport()) && this.options.pathTs) ? 'pathTs' : 'path';
75
+ const key = this.config.get('preferTs', Utils.detectTypeScriptSupport()) && this.options.pathTs ? 'pathTs' : 'path';
78
76
  this.absolutePath = fs.absolutePath(this.options[key], this.config.get('baseDir'));
79
77
  fs.ensureDir(this.absolutePath);
80
78
  }
@@ -132,7 +130,7 @@ export class AbstractMigrator {
132
130
  const buildDir = fs.pathExists(baseDir + '/build');
133
131
  // if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder
134
132
  /* v8 ignore next */
135
- const path = distDir ? './dist' : (buildDir ? './build' : './src');
133
+ const path = distDir ? './dist' : buildDir ? './build' : './src';
136
134
  // only if the user did not provide any values and if the default path does not exist
137
135
  if (!this.options.path && !this.options.pathTs && !exists) {
138
136
  this.options.path = `${path}/migrations`;
@@ -150,7 +148,7 @@ export class AbstractMigrator {
150
148
  }
151
149
  }
152
150
  async emit(event, data) {
153
- for (const listener of this.listeners.get(event) ?? []) {
151
+ for (const listener of this.#listeners.get(event) ?? []) {
154
152
  await listener(data);
155
153
  }
156
154
  }
@@ -257,7 +255,7 @@ export class AbstractMigrator {
257
255
  }
258
256
  getMigrationFilename(name) {
259
257
  name = name.replace(/\.[jt]s$/, '');
260
- return name.match(/^\d{14}$/) ? this.options.fileName(name) : name;
258
+ return /^\d{14}$/.exec(name) ? this.options.fileName(name) : name;
261
259
  }
262
260
  prefix(options) {
263
261
  if (typeof options === 'string' || Array.isArray(options)) {
@@ -112,7 +112,8 @@ export class AbstractSchemaGenerator {
112
112
  }
113
113
  meta = metadata.pop();
114
114
  }
115
- return calc.sort()
115
+ return calc
116
+ .sort()
116
117
  .map(cls => this.metadata.getById(cls))
117
118
  .filter(meta => {
118
119
  const targetSchema = meta.schema ?? this.config.get('schema', this.platform.getDefaultSchemaName());
@@ -13,7 +13,7 @@ function createFallbackAsyncContext() {
13
13
  console.warn('AsyncLocalStorage not available');
14
14
  return {
15
15
  getStore: () => store,
16
- enterWith: value => store = value,
16
+ enterWith: value => (store = value),
17
17
  run: (value, cb) => {
18
18
  const prev = store;
19
19
  store = value;