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

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.71",
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",
@@ -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)
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[];
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
  }