@mikro-orm/core 7.0.0-dev.84 → 7.0.0-dev.86

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/MikroORM.js CHANGED
@@ -18,17 +18,17 @@ export async function lookupExtensions(options) {
18
18
  const extensions = options.extensions ?? [];
19
19
  const exists = (name) => extensions.some(ext => ext.name === name);
20
20
  if (!exists('SeedManager')) {
21
- await registerExtension('SeedManager', import('@mikro-orm/seeder' + ''), extensions);
21
+ await registerExtension('SeedManager', import((() => '@mikro-orm/seeder')()), extensions);
22
22
  }
23
23
  if (!exists('Migrator')) {
24
- await registerExtension('Migrator', import('@mikro-orm/migrations' + ''), extensions);
24
+ await registerExtension('Migrator', import((() => '@mikro-orm/migrations')()), extensions);
25
25
  }
26
26
  /* v8 ignore if */
27
27
  if (!exists('Migrator')) {
28
- await registerExtension('Migrator', import('@mikro-orm/migrations-mongodb' + ''), extensions);
28
+ await registerExtension('Migrator', import((() => '@mikro-orm/migrations-mongodb')()), extensions);
29
29
  }
30
30
  if (!exists('EntityGenerator')) {
31
- await registerExtension('EntityGenerator', import('@mikro-orm/entity-generator' + ''), extensions);
31
+ await registerExtension('EntityGenerator', import((() => '@mikro-orm/entity-generator')()), extensions);
32
32
  }
33
33
  options.extensions = extensions;
34
34
  const metadataCacheEnabled = options.metadataCache?.enabled || options.metadataProvider?.useCache?.();
@@ -6,8 +6,9 @@ export declare class EventManager {
6
6
  private readonly entities;
7
7
  private readonly cache;
8
8
  private readonly subscribers;
9
- constructor(subscribers: EventSubscriber[]);
9
+ constructor(subscribers: Iterable<EventSubscriber>);
10
10
  registerSubscriber(subscriber: EventSubscriber): void;
11
+ getSubscribers(): Set<EventSubscriber>;
11
12
  dispatchEvent<T extends object>(event: TransactionEventType, args: TransactionEventArgs, meta?: EntityMetadata<T>): unknown;
12
13
  dispatchEvent<T extends object>(event: EventType.onInit, args: Partial<EventArgs<T>>, meta?: EntityMetadata<T>): unknown;
13
14
  dispatchEvent<T extends object>(event: EventType, args: Partial<EventArgs<T> | FlushEventArgs>, meta?: EntityMetadata<T>): Promise<unknown>;
@@ -4,21 +4,29 @@ export class EventManager {
4
4
  listeners = {};
5
5
  entities = new Map();
6
6
  cache = new Map();
7
- subscribers = [];
7
+ subscribers = new Set();
8
8
  constructor(subscribers) {
9
- subscribers.forEach(subscriber => this.registerSubscriber(subscriber));
9
+ for (const subscriber of subscribers) {
10
+ this.registerSubscriber(subscriber);
11
+ }
10
12
  }
11
13
  registerSubscriber(subscriber) {
12
- this.subscribers.push(subscriber);
14
+ if (this.subscribers.has(subscriber)) {
15
+ return;
16
+ }
17
+ this.subscribers.add(subscriber);
13
18
  this.entities.set(subscriber, this.getSubscribedEntities(subscriber));
14
19
  this.cache.clear();
15
20
  Utils.keys(EventType)
16
21
  .filter(event => event in subscriber)
17
22
  .forEach(event => {
18
- this.listeners[event] ??= [];
19
- this.listeners[event].push(subscriber);
23
+ this.listeners[event] ??= new Set();
24
+ this.listeners[event].add(subscriber);
20
25
  });
21
26
  }
27
+ getSubscribers() {
28
+ return this.subscribers;
29
+ }
22
30
  dispatchEvent(event, args, meta) {
23
31
  const listeners = [];
24
32
  const entity = args.entity;
@@ -30,9 +38,9 @@ export class EventManager {
30
38
  const handler = typeof hook === 'function' ? hook : entity[hook] ?? prototypeHook;
31
39
  return handler.bind(entity);
32
40
  }));
33
- for (const listener of this.listeners[event] || []) {
41
+ for (const listener of this.listeners[event] ?? new Set()) {
34
42
  const entities = this.entities.get(listener);
35
- if (entities.length === 0 || !entity || entities.includes(entity.constructor.name)) {
43
+ if (entities.size === 0 || !entity || entities.has(entity.constructor.name)) {
36
44
  listeners.push(listener[event].bind(listener));
37
45
  }
38
46
  }
@@ -51,9 +59,9 @@ export class EventManager {
51
59
  this.cache.set(cacheKey, true);
52
60
  return true;
53
61
  }
54
- for (const listener of this.listeners[event] ?? []) {
62
+ for (const listener of this.listeners[event] ?? new Set()) {
55
63
  const entities = this.entities.get(listener);
56
- if (entities.length === 0 || entities.includes(meta.className)) {
64
+ if (entities.size === 0 || entities.has(meta.className)) {
57
65
  this.cache.set(cacheKey, true);
58
66
  return true;
59
67
  }
@@ -66,8 +74,8 @@ export class EventManager {
66
74
  }
67
75
  getSubscribedEntities(listener) {
68
76
  if (!listener.getSubscribedEntities) {
69
- return [];
77
+ return new Set();
70
78
  }
71
- return listener.getSubscribedEntities().map(name => Utils.className(name));
79
+ return new Set(listener.getSubscribedEntities().map(name => Utils.className(name)));
72
80
  }
73
81
  }
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.84",
4
+ "version": "7.0.0-dev.86",
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",
@@ -480,7 +480,7 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
480
480
  * Event subscribers to register.
481
481
  * Can be class references or instances.
482
482
  */
483
- subscribers?: (EventSubscriber | Constructor<EventSubscriber>)[];
483
+ subscribers?: Iterable<EventSubscriber | Constructor<EventSubscriber>>;
484
484
  /**
485
485
  * Global entity filters to apply.
486
486
  * Filters are applied by default unless explicitly disabled.
@@ -319,7 +319,7 @@ export class Configuration {
319
319
  if (!this.options.filtersOnRelations) {
320
320
  this.options.autoJoinRefsForFilters ??= false;
321
321
  }
322
- this.options.subscribers = Utils.unique(this.options.subscribers).map(subscriber => {
322
+ this.options.subscribers = [...this.options.subscribers].map(subscriber => {
323
323
  return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
324
324
  });
325
325
  this.sync();
@@ -216,7 +216,7 @@ export class DataloaderUtils {
216
216
  return this.DataLoader;
217
217
  }
218
218
  try {
219
- const mod = await import('dataloader' + '');
219
+ const mod = await import('dataloader');
220
220
  const DataLoader = mod.default;
221
221
  return (this.DataLoader ??= DataLoader);
222
222
  }
@@ -285,10 +285,14 @@ export class EntityComparator {
285
285
  lines.push(`${padding} if (${value} == null || ${value} instanceof Date) {`);
286
286
  lines.push(`${padding} ${key} = ${value};`);
287
287
  if (!tz || tz === 'local') {
288
+ lines.push(`${padding} } else if (typeof ${value} === 'bigint') {`);
289
+ lines.push(`${padding} ${key} = parseDate(Number(${value}));`);
288
290
  lines.push(`${padding} } else {`);
289
291
  lines.push(`${padding} ${key} = parseDate(${value});`);
290
292
  }
291
293
  else {
294
+ lines.push(`${padding} } else if (typeof ${value} === 'bigint') {`);
295
+ lines.push(`${padding} ${key} = parseDate(Number(${value}));`);
292
296
  lines.push(`${padding} } else if (typeof ${value} === 'number' || ${value}.includes('+') || ${value}.lastIndexOf('-') > 10 || ${value}.endsWith('Z')) {`);
293
297
  lines.push(`${padding} ${key} = parseDate(${value});`);
294
298
  lines.push(`${padding} } else {`);
package/utils/Utils.js CHANGED
@@ -728,7 +728,7 @@ export class Utils {
728
728
  return this.dynamicImportProvider(specifier);
729
729
  }
730
730
  static getORMVersion() {
731
- return '6.6.1';
731
+ return '6.6.2';
732
732
  }
733
733
  static createFunction(context, code) {
734
734
  try {
@@ -4,9 +4,9 @@ export declare const fs: {
4
4
  ensureDir(path: string): void;
5
5
  readJSONSync<T = Dictionary>(path: string): T;
6
6
  glob(input: string | string[], cwd?: string): string[];
7
- getPackageConfig<T extends Dictionary>(basePath?: string): Promise<T>;
8
- getORMPackages(): Promise<Set<string>>;
7
+ getPackageConfig<T extends Dictionary>(basePath?: string): T;
8
+ getORMPackages(): Set<string>;
9
9
  getORMPackageVersion(name: string): string | undefined;
10
- checkPackageVersion(): Promise<void>;
10
+ checkPackageVersion(): void;
11
11
  };
12
12
  export * from '../cache/FileCacheAdapter.js';
package/utils/fs-utils.js CHANGED
@@ -39,10 +39,11 @@ export const fs = {
39
39
  const files = globSync(input, { cwd, withFileTypes: true });
40
40
  return files.filter(f => f.isFile()).map(f => join(f.parentPath, f.name));
41
41
  },
42
- async getPackageConfig(basePath = process.cwd()) {
42
+ getPackageConfig(basePath = process.cwd()) {
43
43
  if (this.pathExists(`${basePath}/package.json`)) {
44
44
  try {
45
- return await Utils.dynamicImport(`${basePath}/package.json`);
45
+ const path = import.meta.resolve(`${basePath}/package.json`);
46
+ return this.readJSONSync(fileURLToPath(path));
46
47
  }
47
48
  catch (e) {
48
49
  /* v8 ignore next */
@@ -56,8 +57,8 @@ export const fs = {
56
57
  }
57
58
  return this.getPackageConfig(parentFolder);
58
59
  },
59
- async getORMPackages() {
60
- const pkg = await this.getPackageConfig();
60
+ getORMPackages() {
61
+ const pkg = this.getPackageConfig();
61
62
  return new Set([
62
63
  ...Object.keys(pkg.dependencies ?? {}),
63
64
  ...Object.keys(pkg.devDependencies ?? {}),
@@ -74,12 +75,12 @@ export const fs = {
74
75
  }
75
76
  },
76
77
  // inspired by https://github.com/facebook/docusaurus/pull/3386
77
- async checkPackageVersion() {
78
+ checkPackageVersion() {
78
79
  const coreVersion = Utils.getORMVersion();
79
80
  if (process.env.MIKRO_ORM_ALLOW_VERSION_MISMATCH || coreVersion === '[[MIKRO_ORM_VERSION]]') {
80
81
  return;
81
82
  }
82
- const deps = await this.getORMPackages();
83
+ const deps = this.getORMPackages();
83
84
  const exceptions = new Set(['nestjs', 'sql-highlighter', 'mongo-highlighter']);
84
85
  const ormPackages = [...deps].filter(d => d.startsWith('@mikro-orm/') && d !== '@mikro-orm/core' && !exceptions.has(d.substring('@mikro-orm/'.length)));
85
86
  for (const ormPackage of ormPackages) {