@mikro-orm/core 7.0.0-dev.70 → 7.0.0-dev.72

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.
@@ -3,13 +3,12 @@ export declare class FileCacheAdapter implements SyncCacheAdapter {
3
3
  private readonly options;
4
4
  private readonly baseDir;
5
5
  private readonly pretty;
6
- private readonly hashAlgorithm;
7
6
  private readonly VERSION;
8
7
  private cache;
9
8
  constructor(options: {
10
9
  cacheDir: string;
11
10
  combined?: boolean | string;
12
- }, baseDir: string, pretty?: boolean, hashAlgorithm?: 'md5' | 'sha256');
11
+ }, baseDir: string, pretty?: boolean);
13
12
  /**
14
13
  * @inheritDoc
15
14
  */
@@ -4,14 +4,12 @@ export class FileCacheAdapter {
4
4
  options;
5
5
  baseDir;
6
6
  pretty;
7
- hashAlgorithm;
8
7
  VERSION = Utils.getORMVersion();
9
8
  cache = {};
10
- constructor(options, baseDir, pretty = false, hashAlgorithm = 'md5') {
9
+ constructor(options, baseDir, pretty = false) {
11
10
  this.options = options;
12
11
  this.baseDir = baseDir;
13
12
  this.pretty = pretty;
14
- this.hashAlgorithm = hashAlgorithm;
15
13
  }
16
14
  /**
17
15
  * @inheritDoc
@@ -78,6 +76,6 @@ export class FileCacheAdapter {
78
76
  return null;
79
77
  }
80
78
  const contents = readFileSync(origin);
81
- return Utils.hash(contents.toString() + this.VERSION, undefined, this.hashAlgorithm);
79
+ return Utils.hash(contents.toString() + this.VERSION);
82
80
  }
83
81
  }
@@ -1,4 +1,3 @@
1
- import { URL } from 'node:url';
2
1
  import { Utils } from '../utils/Utils.js';
3
2
  export class Connection {
4
3
  config;
@@ -15,7 +15,7 @@ export class MetadataStorage {
15
15
  this.metadata = Utils.copy(metadata, false);
16
16
  }
17
17
  static getMetadata(entity, path) {
18
- const key = entity && path ? entity + '-' + Utils.hash(path, undefined, 'sha256') : null;
18
+ const key = entity && path ? entity + '-' + Utils.hash(path) : null;
19
19
  if (key && !MetadataStorage.metadata[key]) {
20
20
  MetadataStorage.metadata[key] = new EntityMetadata({ className: entity, path });
21
21
  }
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.70",
4
+ "version": "7.0.0-dev.72",
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",
@@ -327,7 +327,8 @@ export class UnitOfWork {
327
327
  this.filterCollectionUpdates();
328
328
  // nothing to do, do not start transaction
329
329
  if (this.changeSets.size === 0 && this.collectionUpdates.size === 0 && this.extraUpdates.size === 0) {
330
- return void (await this.eventManager.dispatchEvent(EventType.afterFlush, { em: this.em, uow: this }));
330
+ await this.eventManager.dispatchEvent(EventType.afterFlush, { em: this.em, uow: this });
331
+ return;
331
332
  }
332
333
  const groups = this.getChangeSetGroups();
333
334
  const platform = this.em.getPlatform();
@@ -76,7 +76,6 @@ declare const DEFAULTS: {
76
76
  readonly ensureDatabase: true;
77
77
  readonly ensureIndexes: false;
78
78
  readonly batchSize: 300;
79
- readonly hashAlgorithm: "md5";
80
79
  readonly debug: false;
81
80
  readonly ignoreDeprecations: false;
82
81
  readonly verbose: false;
@@ -407,7 +406,6 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
407
406
  seeder?: SeederOptions;
408
407
  preferReadReplicas?: boolean;
409
408
  dynamicImportProvider?: (id: string) => Promise<unknown>;
410
- hashAlgorithm?: 'md5' | 'sha256';
411
409
  }
412
410
  type MarkRequired<T, D> = {
413
411
  [K in keyof T as Extract<K, keyof D>]-?: T[K];
@@ -68,7 +68,6 @@ const DEFAULTS = {
68
68
  ensureDatabase: true,
69
69
  ensureIndexes: false,
70
70
  batchSize: 300,
71
- hashAlgorithm: 'md5',
72
71
  debug: false,
73
72
  ignoreDeprecations: false,
74
73
  verbose: false,
@@ -262,7 +261,7 @@ export class Configuration {
262
261
  * Gets instance of metadata CacheAdapter. (cached)
263
262
  */
264
263
  getMetadataCacheAdapter() {
265
- return this.getCachedService(this.options.metadataCache.adapter, this.options.metadataCache.options, this.options.baseDir, this.options.metadataCache.pretty, this.options.hashAlgorithm);
264
+ return this.getCachedService(this.options.metadataCache.adapter, this.options.metadataCache.options, this.options.baseDir, this.options.metadataCache.pretty);
266
265
  }
267
266
  /**
268
267
  * Gets instance of CacheAdapter for result cache. (cached)
@@ -7,78 +7,88 @@ import { colors } from '../logging/colors.js';
7
7
  export class ConfigurationLoader {
8
8
  static loadEnvironmentVars() {
9
9
  const ret = {};
10
+ const getEnvKey = (key, envPrefix = 'MIKRO_ORM_') => {
11
+ return envPrefix + key
12
+ .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
13
+ .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2')
14
+ .toUpperCase();
15
+ };
10
16
  const array = (v) => v.split(',').map(vv => vv.trim());
11
17
  const bool = (v) => ['true', 't', '1'].includes(v.toLowerCase());
12
18
  const num = (v) => +v;
13
- const read = (o, envKey, key, mapper = v => v) => {
14
- if (!(envKey in process.env)) {
15
- return;
19
+ const read = (o, envPrefix, key, mapper = v => v) => {
20
+ const envKey = getEnvKey(key, envPrefix);
21
+ if (envKey in process.env) {
22
+ o[key] = mapper(process.env[envKey]);
16
23
  }
17
- const val = process.env[envKey];
18
- o[key] = mapper(val);
19
24
  };
20
25
  const cleanup = (o, k) => Utils.hasObjectKeys(o[k]) ? {} : delete o[k];
21
- read(ret, 'MIKRO_ORM_BASE_DIR', 'baseDir');
22
- read(ret, 'MIKRO_ORM_ENTITIES', 'entities', array);
23
- read(ret, 'MIKRO_ORM_ENTITIES_TS', 'entitiesTs', array);
24
- read(ret, 'MIKRO_ORM_CLIENT_URL', 'clientUrl');
25
- read(ret, 'MIKRO_ORM_HOST', 'host');
26
- read(ret, 'MIKRO_ORM_PORT', 'port', num);
27
- read(ret, 'MIKRO_ORM_USER', 'user');
28
- read(ret, 'MIKRO_ORM_PASSWORD', 'password');
29
- read(ret, 'MIKRO_ORM_DB_NAME', 'dbName');
30
- read(ret, 'MIKRO_ORM_SCHEMA', 'schema');
31
- read(ret, 'MIKRO_ORM_LOAD_STRATEGY', 'loadStrategy');
32
- read(ret, 'MIKRO_ORM_BATCH_SIZE', 'batchSize', num);
33
- read(ret, 'MIKRO_ORM_USE_BATCH_INSERTS', 'useBatchInserts', bool);
34
- read(ret, 'MIKRO_ORM_USE_BATCH_UPDATES', 'useBatchUpdates', bool);
35
- read(ret, 'MIKRO_ORM_STRICT', 'strict', bool);
36
- read(ret, 'MIKRO_ORM_VALIDATE', 'validate', bool);
37
- read(ret, 'MIKRO_ORM_ALLOW_GLOBAL_CONTEXT', 'allowGlobalContext', bool);
38
- read(ret, 'MIKRO_ORM_AUTO_JOIN_ONE_TO_ONE_OWNER', 'autoJoinOneToOneOwner', bool);
39
- read(ret, 'MIKRO_ORM_POPULATE_AFTER_FLUSH', 'populateAfterFlush', bool);
40
- read(ret, 'MIKRO_ORM_FORCE_ENTITY_CONSTRUCTOR', 'forceEntityConstructor', bool);
41
- read(ret, 'MIKRO_ORM_FORCE_UNDEFINED', 'forceUndefined', bool);
42
- read(ret, 'MIKRO_ORM_FORCE_UTC_TIMEZONE', 'forceUtcTimezone', bool);
43
- read(ret, 'MIKRO_ORM_TIMEZONE', 'timezone');
44
- read(ret, 'MIKRO_ORM_ENSURE_INDEXES', 'ensureIndexes', bool);
45
- read(ret, 'MIKRO_ORM_IMPLICIT_TRANSACTIONS', 'implicitTransactions', bool);
46
- read(ret, 'MIKRO_ORM_DEBUG', 'debug', bool);
47
- read(ret, 'MIKRO_ORM_COLORS', 'colors', bool);
26
+ const read0 = read.bind(null, ret, 'MIKRO_ORM_');
27
+ read0('baseDir');
28
+ read0('entities', array);
29
+ read0('entitiesTs', array);
30
+ read0('clientUrl');
31
+ read0('host');
32
+ read0('port', num);
33
+ read0('user');
34
+ read0('password');
35
+ read0('dbName');
36
+ read0('schema');
37
+ read0('loadStrategy');
38
+ read0('batchSize', num);
39
+ read0('useBatchInserts', bool);
40
+ read0('useBatchUpdates', bool);
41
+ read0('strict', bool);
42
+ read0('validate', bool);
43
+ read0('allowGlobalContext', bool);
44
+ read0('autoJoinOneToOneOwner', bool);
45
+ read0('populateAfterFlush', bool);
46
+ read0('forceEntityConstructor', bool);
47
+ read0('forceUndefined', bool);
48
+ read0('forceUtcTimezone', bool);
49
+ read0('timezone');
50
+ read0('ensureIndexes', bool);
51
+ read0('implicitTransactions', bool);
52
+ read0('debug', bool);
53
+ read0('colors', bool);
48
54
  ret.discovery = {};
49
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_WARN_WHEN_NO_ENTITIES', 'warnWhenNoEntities', bool);
50
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_CHECK_DUPLICATE_TABLE_NAMES', 'checkDuplicateTableNames', bool);
51
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_CHECK_DUPLICATE_FIELD_NAMES', 'checkDuplicateFieldNames', bool);
52
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_CHECK_DUPLICATE_ENTITIES', 'checkDuplicateEntities', bool);
53
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_CHECK_NON_PERSISTENT_COMPOSITE_PROPS', 'checkNonPersistentCompositeProps', bool);
54
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_INFER_DEFAULT_VALUES', 'inferDefaultValues', bool);
55
- read(ret.discovery, 'MIKRO_ORM_DISCOVERY_TS_CONFIG_PATH', 'tsConfigPath');
55
+ const read1 = read.bind(null, ret.discovery, 'MIKRO_ORM_DISCOVERY_');
56
+ read1('warnWhenNoEntities', bool);
57
+ read1('checkDuplicateTableNames', bool);
58
+ read1('checkDuplicateFieldNames', bool);
59
+ read1('checkDuplicateEntities', bool);
60
+ read1('checkNonPersistentCompositeProps', bool);
61
+ read1('inferDefaultValues', bool);
62
+ read1('tsConfigPath');
56
63
  cleanup(ret, 'discovery');
57
64
  ret.migrations = {};
58
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_TABLE_NAME', 'tableName');
59
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_PATH', 'path');
60
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_PATH_TS', 'pathTs');
61
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_GLOB', 'glob');
62
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_TRANSACTIONAL', 'transactional', bool);
63
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_DISABLE_FOREIGN_KEYS', 'disableForeignKeys', bool);
64
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_ALL_OR_NOTHING', 'allOrNothing', bool);
65
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_DROP_TABLES', 'dropTables', bool);
66
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_SAFE', 'safe', bool);
67
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_SILENT', 'silent', bool);
68
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_EMIT', 'emit');
69
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_SNAPSHOT', 'snapshot', bool);
70
- read(ret.migrations, 'MIKRO_ORM_MIGRATIONS_SNAPSHOT_NAME', 'snapshotName');
65
+ const read2 = read.bind(null, ret.migrations, 'MIKRO_ORM_MIGRATIONS_');
66
+ read2('tableName');
67
+ read2('path');
68
+ read2('pathTs');
69
+ read2('glob');
70
+ read2('transactional', bool);
71
+ read2('disableForeignKeys', bool);
72
+ read2('allOrNothing', bool);
73
+ read2('dropTables', bool);
74
+ read2('safe', bool);
75
+ read2('silent', bool);
76
+ read2('emit');
77
+ read2('snapshot', bool);
78
+ read2('snapshotName');
71
79
  cleanup(ret, 'migrations');
72
80
  ret.schemaGenerator = {};
73
- read(ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_DISABLE_FOREIGN_KEYS', 'disableForeignKeys', bool);
74
- read(ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_CREATE_FOREIGN_KEY_CONSTRAINTS', 'createForeignKeyConstraints', bool);
81
+ const read3 = read.bind(null, ret.schemaGenerator, 'MIKRO_ORM_SCHEMA_GENERATOR_');
82
+ read3('disableForeignKeys', bool);
83
+ read3('createForeignKeyConstraints', bool);
75
84
  cleanup(ret, 'schemaGenerator');
76
85
  ret.seeder = {};
77
- read(ret.seeder, 'MIKRO_ORM_SEEDER_PATH', 'path');
78
- read(ret.seeder, 'MIKRO_ORM_SEEDER_PATH_TS', 'pathTs');
79
- read(ret.seeder, 'MIKRO_ORM_SEEDER_GLOB', 'glob');
80
- read(ret.seeder, 'MIKRO_ORM_SEEDER_EMIT', 'emit');
81
- read(ret.seeder, 'MIKRO_ORM_SEEDER_DEFAULT_SEEDER', 'defaultSeeder');
86
+ const read4 = read.bind(null, ret.seeder, 'MIKRO_ORM_SEEDER_');
87
+ read4('path');
88
+ read4('pathTs');
89
+ read4('glob');
90
+ read4('emit');
91
+ read4('defaultSeeder');
82
92
  cleanup(ret, 'seeder');
83
93
  return ret;
84
94
  }
package/utils/Utils.d.ts CHANGED
@@ -147,7 +147,7 @@ export declare class Utils {
147
147
  * If either `path` or `baseDir` are `file:` URLs, they are converted to local paths.
148
148
  */
149
149
  static absolutePath(path: string, baseDir?: string): string;
150
- static hash(data: string, length?: number, algorithm?: 'md5' | 'sha256'): string;
150
+ static hash(data: string, length?: number): string;
151
151
  static runIfNotEmpty(clause: () => any, data: any): void;
152
152
  static defaultValue<T extends Dictionary>(prop: T, option: keyof T, defaultValue: any): void;
153
153
  static findDuplicates<T>(items: T[]): T[];
@@ -168,12 +168,6 @@ export declare class Utils {
168
168
  * @param [from] Location to start the node resolution
169
169
  */
170
170
  static requireFrom<T extends Dictionary>(id: string, from?: string): T;
171
- /**
172
- * Resolve path to a module.
173
- * @param id The module to require
174
- * @param [from] Location to start the node resolution
175
- */
176
- static resolveModulePath(id: string, from?: string): string;
177
171
  static dynamicImport<T = any>(id: string): Promise<T>;
178
172
  static ensureDir(path: string): void;
179
173
  static readJSONSync(path: string): Dictionary;
package/utils/Utils.js CHANGED
@@ -2,7 +2,6 @@ import { createRequire } from 'node:module';
2
2
  import { extname, isAbsolute, join, normalize, relative, resolve } from 'node:path';
3
3
  import { fileURLToPath, pathToFileURL } from 'node:url';
4
4
  import { existsSync, globSync, statSync, mkdirSync, readFileSync } from 'node:fs';
5
- import { createHash } from 'node:crypto';
6
5
  import { clone } from './clone.js';
7
6
  import { GroupOperator, PlainObject, QueryOperator, ReferenceKind } from '../enums.js';
8
7
  import { helper } from '../entity/wrap.js';
@@ -649,9 +648,14 @@ export class Utils {
649
648
  }
650
649
  return Utils.normalizePath(path);
651
650
  }
652
- static hash(data, length, algorithm) {
653
- const hashAlgorithm = algorithm || 'sha256';
654
- const hash = createHash(hashAlgorithm).update(data).digest('hex');
651
+ // FNV-1a 64-bit
652
+ static hash(data, length) {
653
+ let h1 = 0xcbf29ce484222325n;
654
+ for (let i = 0; i < data.length; i++) {
655
+ h1 ^= BigInt(data.charCodeAt(i));
656
+ h1 = (h1 * 0x100000001b3n) & 0xffffffffffffffffn;
657
+ }
658
+ const hash = h1.toString(16).padStart(16, '0');
655
659
  if (length) {
656
660
  return hash.substring(0, length);
657
661
  }
@@ -758,21 +762,6 @@ export class Utils {
758
762
  }
759
763
  return createRequire(resolve(from))(id);
760
764
  }
761
- /**
762
- * Resolve path to a module.
763
- * @param id The module to require
764
- * @param [from] Location to start the node resolution
765
- */
766
- static resolveModulePath(id, from = process.cwd()) {
767
- if (!extname(from)) {
768
- from = join(from, '__fake.js');
769
- }
770
- const path = Utils.normalizePath(createRequire(resolve(from)).resolve(id));
771
- const parts = path.split('/');
772
- const idx = parts.lastIndexOf(id) + 1;
773
- parts.splice(idx, parts.length - idx);
774
- return parts.join('/');
775
- }
776
765
  static async dynamicImport(id) {
777
766
  /* v8 ignore next */
778
767
  const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;