@mikro-orm/core 7.0.0-dev.321 → 7.0.0-dev.323

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 (53) hide show
  1. package/EntityManager.d.ts +2 -15
  2. package/EntityManager.js +155 -152
  3. package/MikroORM.d.ts +1 -3
  4. package/MikroORM.js +20 -20
  5. package/cache/FileCacheAdapter.d.ts +1 -5
  6. package/cache/FileCacheAdapter.js +22 -22
  7. package/cache/GeneratedCacheAdapter.d.ts +1 -1
  8. package/cache/GeneratedCacheAdapter.js +6 -6
  9. package/cache/MemoryCacheAdapter.d.ts +1 -2
  10. package/cache/MemoryCacheAdapter.js +8 -8
  11. package/entity/Collection.d.ts +2 -10
  12. package/entity/Collection.js +95 -105
  13. package/entity/EntityFactory.d.ts +1 -8
  14. package/entity/EntityFactory.js +48 -48
  15. package/entity/EntityLoader.d.ts +1 -3
  16. package/entity/EntityLoader.js +33 -34
  17. package/entity/Reference.d.ts +1 -2
  18. package/entity/Reference.js +11 -11
  19. package/events/EventManager.d.ts +1 -4
  20. package/events/EventManager.js +21 -21
  21. package/hydration/ObjectHydrator.d.ts +1 -2
  22. package/hydration/ObjectHydrator.js +11 -11
  23. package/metadata/MetadataDiscovery.d.ts +1 -9
  24. package/metadata/MetadataDiscovery.js +147 -144
  25. package/metadata/MetadataStorage.d.ts +1 -5
  26. package/metadata/MetadataStorage.js +36 -36
  27. package/naming-strategy/EntityCaseNamingStrategy.js +1 -1
  28. package/package.json +1 -1
  29. package/serialization/EntitySerializer.js +1 -1
  30. package/serialization/EntityTransformer.js +4 -1
  31. package/serialization/SerializationContext.d.ts +3 -7
  32. package/serialization/SerializationContext.js +20 -15
  33. package/unit-of-work/ChangeSetComputer.d.ts +1 -6
  34. package/unit-of-work/ChangeSetComputer.js +21 -21
  35. package/unit-of-work/ChangeSetPersister.d.ts +1 -9
  36. package/unit-of-work/ChangeSetPersister.js +51 -51
  37. package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
  38. package/unit-of-work/CommitOrderCalculator.js +13 -13
  39. package/unit-of-work/IdentityMap.d.ts +2 -5
  40. package/unit-of-work/IdentityMap.js +18 -18
  41. package/unit-of-work/UnitOfWork.d.ts +5 -19
  42. package/unit-of-work/UnitOfWork.js +181 -173
  43. package/utils/AbstractMigrator.d.ts +1 -1
  44. package/utils/AbstractMigrator.js +6 -6
  45. package/utils/Configuration.d.ts +1 -6
  46. package/utils/Configuration.js +78 -78
  47. package/utils/Cursor.d.ts +1 -1
  48. package/utils/Cursor.js +3 -3
  49. package/utils/EntityComparator.d.ts +2 -11
  50. package/utils/EntityComparator.js +44 -44
  51. package/utils/TransactionManager.js +1 -2
  52. package/utils/Utils.js +1 -1
  53. package/utils/clone.js +1 -1
package/MikroORM.d.ts CHANGED
@@ -35,15 +35,13 @@ export declare function loadOptionalDependencies(options: Options): Promise<void
35
35
  * ```
36
36
  */
37
37
  export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver, EM extends Driver[typeof EntityManagerType] & EntityManager<Driver> = Driver[typeof EntityManagerType] & EntityManager<Driver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> {
38
+ #private;
38
39
  /** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
39
40
  em: EM & {
40
41
  '~entities'?: Entities;
41
42
  };
42
43
  readonly driver: Driver;
43
44
  readonly config: Configuration<Driver>;
44
- private metadata;
45
- private readonly logger;
46
- private readonly discovery;
47
45
  /**
48
46
  * Initialize the ORM, load entity metadata, create EntityManager and connect to the database.
49
47
  * If you omit the `options` parameter, your CLI config will be used.
package/MikroORM.js CHANGED
@@ -74,9 +74,9 @@ export class MikroORM {
74
74
  em;
75
75
  driver;
76
76
  config;
77
- metadata;
78
- logger;
79
- discovery;
77
+ #metadata;
78
+ #logger;
79
+ #discovery;
80
80
  /**
81
81
  * Initialize the ORM, load entity metadata, create EntityManager and connect to the database.
82
82
  * If you omit the `options` parameter, your CLI config will be used.
@@ -92,7 +92,7 @@ export class MikroORM {
92
92
  await loadOptionalDependencies(options);
93
93
  const orm = new this(options);
94
94
  const preferTs = orm.config.get('preferTs', Utils.detectTypeScriptSupport());
95
- orm.metadata = await orm.discovery.discover(preferTs);
95
+ orm.#metadata = await orm.#discovery.discover(preferTs);
96
96
  orm.createEntityManager();
97
97
  return orm;
98
98
  }
@@ -108,15 +108,15 @@ export class MikroORM {
108
108
  this.config = new Configuration(options);
109
109
  const discovery = this.config.get('discovery');
110
110
  this.driver = this.config.getDriver();
111
- this.logger = this.config.getLogger();
112
- this.logger.log('info', `MikroORM version: ${colors.green(Utils.getORMVersion())}`);
113
- this.discovery = new MetadataDiscovery(new MetadataStorage(), this.driver.getPlatform(), this.config);
111
+ this.#logger = this.config.getLogger();
112
+ this.#logger.log('info', `MikroORM version: ${colors.green(Utils.getORMVersion())}`);
113
+ this.#discovery = new MetadataDiscovery(new MetadataStorage(), this.driver.getPlatform(), this.config);
114
114
  this.driver.getPlatform().init(this);
115
115
  for (const extension of this.config.get('extensions')) {
116
116
  extension.register(this);
117
117
  }
118
118
  if (!discovery.skipSyncDiscovery) {
119
- this.metadata = this.discovery.discoverSync();
119
+ this.#metadata = this.#discovery.discoverSync();
120
120
  this.createEntityManager();
121
121
  }
122
122
  }
@@ -162,32 +162,32 @@ export class MikroORM {
162
162
  */
163
163
  getMetadata(entityName) {
164
164
  if (entityName) {
165
- return this.metadata.get(entityName);
165
+ return this.#metadata.get(entityName);
166
166
  }
167
- return this.metadata;
167
+ return this.#metadata;
168
168
  }
169
169
  createEntityManager() {
170
- this.driver.setMetadata(this.metadata);
170
+ this.driver.setMetadata(this.#metadata);
171
171
  this.em = this.driver.createEntityManager();
172
172
  this.em.global = true;
173
- this.metadata.decorate(this.em);
174
- this.driver.setMetadata(this.metadata);
173
+ this.#metadata.decorate(this.em);
174
+ this.driver.setMetadata(this.#metadata);
175
175
  }
176
176
  /**
177
177
  * Allows dynamically discovering new entity by reference, handy for testing schema diffing.
178
178
  */
179
179
  discoverEntity(entities, reset) {
180
180
  for (const className of Utils.asArray(reset)) {
181
- this.metadata.reset(className);
182
- this.discovery.reset(className);
181
+ this.#metadata.reset(className);
182
+ this.#discovery.reset(className);
183
183
  }
184
- const tmp = this.discovery.discoverReferences(Utils.asArray(entities));
185
- const metadata = this.discovery.processDiscoveredEntities(tmp);
184
+ const tmp = this.#discovery.discoverReferences(Utils.asArray(entities));
185
+ const metadata = this.#discovery.processDiscoveredEntities(tmp);
186
186
  for (const meta of metadata) {
187
- this.metadata.set(meta.class, meta);
188
- meta.root = this.metadata.get(meta.root.class);
187
+ this.#metadata.set(meta.class, meta);
188
+ meta.root = this.#metadata.get(meta.root.class);
189
189
  }
190
- this.metadata.decorate(this.em);
190
+ this.#metadata.decorate(this.em);
191
191
  }
192
192
  /**
193
193
  * Gets the SchemaGenerator.
@@ -1,10 +1,6 @@
1
1
  import type { SyncCacheAdapter } from './CacheAdapter.js';
2
2
  export declare class FileCacheAdapter implements SyncCacheAdapter {
3
- private readonly options;
4
- private readonly baseDir;
5
- private readonly pretty;
6
- private readonly VERSION;
7
- private cache;
3
+ #private;
8
4
  constructor(options: {
9
5
  cacheDir: string;
10
6
  combined?: boolean | string;
@@ -2,16 +2,16 @@ import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
2
2
  import { fs } from '../utils/fs-utils.js';
3
3
  import { Utils } from '../utils/Utils.js';
4
4
  export class FileCacheAdapter {
5
- options;
6
- baseDir;
7
- pretty;
8
- VERSION = Utils.getORMVersion();
9
- cache = {};
5
+ #VERSION = Utils.getORMVersion();
6
+ #cache = {};
7
+ #options;
8
+ #baseDir;
9
+ #pretty;
10
10
  constructor(options = {}, baseDir, pretty = false) {
11
- this.options = options;
12
- this.baseDir = baseDir;
13
- this.pretty = pretty;
14
- this.options.cacheDir ??= process.cwd() + '/temp';
11
+ this.#options = options;
12
+ this.#baseDir = baseDir;
13
+ this.#pretty = pretty;
14
+ this.#options.cacheDir ??= process.cwd() + '/temp';
15
15
  }
16
16
  /**
17
17
  * @inheritDoc
@@ -32,13 +32,13 @@ export class FileCacheAdapter {
32
32
  * @inheritDoc
33
33
  */
34
34
  set(name, data, origin) {
35
- if (this.options.combined) {
36
- this.cache[name.replace(/\.[jt]s$/, '')] = data;
35
+ if (this.#options.combined) {
36
+ this.#cache[name.replace(/\.[jt]s$/, '')] = data;
37
37
  return;
38
38
  }
39
39
  const path = this.path(name);
40
40
  const hash = this.getHash(origin);
41
- writeFileSync(path, JSON.stringify({ data, origin, hash, version: this.VERSION }, null, this.pretty ? 2 : undefined));
41
+ writeFileSync(path, JSON.stringify({ data, origin, hash, version: this.#VERSION }, null, this.#pretty ? 2 : undefined));
42
42
  }
43
43
  /**
44
44
  * @inheritDoc
@@ -62,28 +62,28 @@ export class FileCacheAdapter {
62
62
  // ignore if file is already gone
63
63
  }
64
64
  }
65
- this.cache = {};
65
+ this.#cache = {};
66
66
  }
67
67
  combine() {
68
- if (!this.options.combined) {
68
+ if (!this.#options.combined) {
69
69
  return;
70
70
  }
71
- let path = typeof this.options.combined === 'string' ? this.options.combined : './metadata.json';
72
- path = fs.normalizePath(this.options.cacheDir, path);
73
- this.options.combined = path; // override in the options, so we can log it from the CLI in `cache:generate` command
74
- writeFileSync(path, JSON.stringify(this.cache, null, this.pretty ? 2 : undefined));
71
+ let path = typeof this.#options.combined === 'string' ? this.#options.combined : './metadata.json';
72
+ path = fs.normalizePath(this.#options.cacheDir, path);
73
+ this.#options.combined = path; // override in the options, so we can log it from the CLI in `cache:generate` command
74
+ writeFileSync(path, JSON.stringify(this.#cache, null, this.#pretty ? 2 : undefined));
75
75
  return path;
76
76
  }
77
77
  path(name) {
78
- fs.ensureDir(this.options.cacheDir);
79
- return `${this.options.cacheDir}/${name}.json`;
78
+ fs.ensureDir(this.#options.cacheDir);
79
+ return `${this.#options.cacheDir}/${name}.json`;
80
80
  }
81
81
  getHash(origin) {
82
- origin = fs.absolutePath(origin, this.baseDir);
82
+ origin = fs.absolutePath(origin, this.#baseDir);
83
83
  if (!existsSync(origin)) {
84
84
  return null;
85
85
  }
86
86
  const contents = readFileSync(origin);
87
- return Utils.hash(contents.toString() + this.VERSION);
87
+ return Utils.hash(contents.toString() + this.#VERSION);
88
88
  }
89
89
  }
@@ -1,7 +1,7 @@
1
1
  import type { CacheAdapter } from './CacheAdapter.js';
2
2
  import type { Dictionary } from '../typings.js';
3
3
  export declare class GeneratedCacheAdapter implements CacheAdapter {
4
- private readonly data;
4
+ #private;
5
5
  constructor(options: {
6
6
  data: Dictionary;
7
7
  });
@@ -1,32 +1,32 @@
1
1
  export class GeneratedCacheAdapter {
2
- data = new Map();
2
+ #data;
3
3
  constructor(options) {
4
- this.data = new Map(Object.entries(options.data));
4
+ this.#data = new Map(Object.entries(options.data));
5
5
  }
6
6
  /**
7
7
  * @inheritDoc
8
8
  */
9
9
  get(name) {
10
10
  const key = name.replace(/\.[jt]s$/, '');
11
- const data = this.data.get(key);
11
+ const data = this.#data.get(key);
12
12
  return data;
13
13
  }
14
14
  /**
15
15
  * @inheritDoc
16
16
  */
17
17
  set(name, data, origin) {
18
- this.data.set(name, { data });
18
+ this.#data.set(name, { data });
19
19
  }
20
20
  /**
21
21
  * @inheritDoc
22
22
  */
23
23
  remove(name) {
24
- this.data.delete(name);
24
+ this.#data.delete(name);
25
25
  }
26
26
  /**
27
27
  * @inheritDoc
28
28
  */
29
29
  clear() {
30
- this.data.clear();
30
+ this.#data.clear();
31
31
  }
32
32
  }
@@ -1,7 +1,6 @@
1
1
  import type { CacheAdapter } from './CacheAdapter.js';
2
2
  export declare class MemoryCacheAdapter implements CacheAdapter {
3
- private readonly options;
4
- private readonly data;
3
+ #private;
5
4
  constructor(options: {
6
5
  expiration: number;
7
6
  });
@@ -1,17 +1,17 @@
1
1
  export class MemoryCacheAdapter {
2
- options;
3
- data = new Map();
2
+ #data = new Map();
3
+ #options;
4
4
  constructor(options) {
5
- this.options = options;
5
+ this.#options = options;
6
6
  }
7
7
  /**
8
8
  * @inheritDoc
9
9
  */
10
10
  get(name) {
11
- const data = this.data.get(name);
11
+ const data = this.#data.get(name);
12
12
  if (data) {
13
13
  if (data.expiration < Date.now()) {
14
- this.data.delete(name);
14
+ this.#data.delete(name);
15
15
  }
16
16
  else {
17
17
  return data.data;
@@ -23,18 +23,18 @@ export class MemoryCacheAdapter {
23
23
  * @inheritDoc
24
24
  */
25
25
  set(name, data, origin, expiration) {
26
- this.data.set(name, { data, expiration: Date.now() + (expiration ?? this.options.expiration) });
26
+ this.#data.set(name, { data, expiration: Date.now() + (expiration ?? this.#options.expiration) });
27
27
  }
28
28
  /**
29
29
  * @inheritDoc
30
30
  */
31
31
  remove(name) {
32
- this.data.delete(name);
32
+ this.#data.delete(name);
33
33
  }
34
34
  /**
35
35
  * @inheritDoc
36
36
  */
37
37
  clear() {
38
- this.data.clear();
38
+ this.#data.clear();
39
39
  }
40
40
  }
@@ -9,17 +9,9 @@ export interface MatchingOptions<T extends object, P extends string = never> ext
9
9
  ctx?: Transaction;
10
10
  }
11
11
  export declare class Collection<T extends object, O extends object = object> {
12
+ #private;
12
13
  readonly owner: O;
13
14
  [k: number]: T;
14
- private readonly items;
15
- private initialized;
16
- private dirty;
17
- private partial;
18
- private snapshot;
19
- private readonly?;
20
- private _count?;
21
- private _property?;
22
- private _populated?;
23
15
  constructor(owner: O, items?: T[], initialized?: boolean);
24
16
  /**
25
17
  * Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
@@ -163,7 +155,7 @@ export declare class Collection<T extends object, O extends object = object> {
163
155
  protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
164
156
  protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
165
157
  protected shouldPropagateToCollection(collection: Collection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
166
- private incrementCount;
158
+ protected incrementCount(value: number): void;
167
159
  }
168
160
  export interface InitCollectionOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends EntityLoaderOptions<T, F, E> {
169
161
  dataloader?: boolean;