@mikro-orm/core 7.0.0-dev.303 → 7.0.0-dev.305

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/cache/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './CacheAdapter.js';
1
+ export type * from './CacheAdapter.js';
2
2
  export * from './NullCacheAdapter.js';
3
3
  export * from './MemoryCacheAdapter.js';
4
4
  export * from './GeneratedCacheAdapter.js';
package/cache/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export * from './CacheAdapter.js';
2
1
  export * from './NullCacheAdapter.js';
3
2
  export * from './MemoryCacheAdapter.js';
4
3
  export * from './GeneratedCacheAdapter.js';
package/errors.js CHANGED
@@ -34,19 +34,12 @@ export class ValidationError extends Error {
34
34
  return new ValidationError(`Entity ${entity.constructor.name} is not managed. An entity is managed if its fetched from the database or registered as new through EntityManager.persist()`);
35
35
  }
36
36
  static notEntity(owner, prop, data) {
37
- const type = Object.prototype.toString
38
- .call(data)
39
- .match(/\[object (\w+)]/)[1]
40
- .toLowerCase();
37
+ const type = /\[object (\w+)]/.exec(Object.prototype.toString.call(data))[1].toLowerCase();
41
38
  return new ValidationError(`Entity of type ${prop.type} expected for property ${owner.constructor.name}.${prop.name}, ${inspect(data)} of type ${type} given. If you are using Object.assign(entity, data), use em.assign(entity, data) instead.`);
42
39
  }
43
40
  static notDiscoveredEntity(data, meta, action = 'persist') {
44
41
  /* v8 ignore next */
45
- const type = meta?.className ??
46
- Object.prototype.toString
47
- .call(data)
48
- .match(/\[object (\w+)]/)[1]
49
- .toLowerCase();
42
+ const type = meta?.className ?? /\[object (\w+)]/.exec(Object.prototype.toString.call(data))[1].toLowerCase();
50
43
  let err = `Trying to ${action} not discovered entity of type ${type}.`;
51
44
  if (meta) {
52
45
  err += ` Entity with this name was discovered, but not the prototype you are passing to the ORM. If using EntitySchema, be sure to point to the implementation via \`class\`.`;
@@ -63,10 +56,7 @@ export class ValidationError extends Error {
63
56
  return new ValidationError(`Invalid enum array items provided in ${entityName}: ${inspect(invalid)}`);
64
57
  }
65
58
  static invalidType(type, value, mode) {
66
- const valueType = Object.prototype.toString
67
- .call(value)
68
- .match(/\[object (\w+)]/)[1]
69
- .toLowerCase();
59
+ const valueType = /\[object (\w+)]/.exec(Object.prototype.toString.call(value))[1].toLowerCase();
70
60
  if (value instanceof Date) {
71
61
  value = value.toISOString();
72
62
  }
@@ -45,7 +45,10 @@ export class EventManager {
45
45
  }
46
46
  }
47
47
  if (event === EventType.onInit) {
48
- return listeners.forEach(listener => listener(args));
48
+ for (const listener of listeners) {
49
+ void listener(args);
50
+ }
51
+ return;
49
52
  }
50
53
  return Utils.runSerial(listeners, listener => listener(args));
51
54
  }
package/events/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './EventSubscriber.js';
1
+ export type * from './EventSubscriber.js';
2
2
  export * from './EventManager.js';
3
3
  export * from './TransactionEventBroadcaster.js';
package/events/index.js CHANGED
@@ -1,3 +1,2 @@
1
- export * from './EventSubscriber.js';
2
1
  export * from './EventManager.js';
3
2
  export * from './TransactionEventBroadcaster.js';
@@ -67,7 +67,7 @@ export class ObjectHydrator extends Hydrator {
67
67
  const entityKey = path.map(k => this.wrap(k)).join('');
68
68
  const tz = this.platform.getTimezone();
69
69
  const convertorKey = path
70
- .filter(k => !k.match(/\[idx_\d+]/))
70
+ .filter(k => !/\[idx_\d+]/.exec(k))
71
71
  .map(k => this.safeKey(k))
72
72
  .join('_');
73
73
  const ret = [];
@@ -238,7 +238,7 @@ export class ObjectHydrator extends Hydrator {
238
238
  };
239
239
  const registerEmbeddedPrototype = (prop, path) => {
240
240
  const convertorKey = path
241
- .filter(k => !k.match(/\[idx_\d+]/))
241
+ .filter(k => !/\[idx_\d+]/.exec(k))
242
242
  .map(k => this.safeKey(k))
243
243
  .join('_');
244
244
  if (prop.targetMeta?.polymorphs) {
@@ -287,7 +287,7 @@ export class ObjectHydrator extends Hydrator {
287
287
  else {
288
288
  ret.push(` const embeddedData = {`);
289
289
  for (const childProp of Object.values(prop.embeddedProps)) {
290
- const key = childProp.embedded[1].match(/^\w+$/) ? childProp.embedded[1] : `'${childProp.embedded[1]}'`;
290
+ const key = /^\w+$/.exec(childProp.embedded[1]) ? childProp.embedded[1] : `'${childProp.embedded[1]}'`;
291
291
  ret.push(` ${key}: data${this.wrap(childProp.name)},`);
292
292
  }
293
293
  ret.push(` };`);
@@ -424,10 +424,10 @@ export class ObjectHydrator extends Hydrator {
424
424
  return lines;
425
425
  }
426
426
  wrap(key) {
427
- if (key.match(/^\[.*]$/)) {
427
+ if (/^\[.*]$/.exec(key)) {
428
428
  return key;
429
429
  }
430
- return key.match(/^\w+$/) ? `.${key}` : `['${key}']`;
430
+ return /^\w+$/.exec(key) ? `.${key}` : `['${key}']`;
431
431
  }
432
432
  safeKey(key) {
433
433
  return key.replace(/\W/g, '_');
@@ -1,5 +1,5 @@
1
1
  export * from './colors.js';
2
- export * from './Logger.js';
2
+ export type * from './Logger.js';
3
3
  export * from './DefaultLogger.js';
4
4
  export * from './SimpleLogger.js';
5
5
  export * from './inspect.js';
package/logging/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './colors.js';
2
- export * from './Logger.js';
3
2
  export * from './DefaultLogger.js';
4
3
  export * from './SimpleLogger.js';
5
4
  export * from './inspect.js';
@@ -1481,13 +1481,13 @@ export class MetadataDiscovery {
1481
1481
  }
1482
1482
  initGeneratedColumn(meta, prop) {
1483
1483
  if (!prop.generated && prop.columnTypes) {
1484
- const match = prop.columnTypes[0]?.match(/(.*) generated always as (.*)/i);
1484
+ const match = /(.*) generated always as (.*)/i.exec(prop.columnTypes[0]);
1485
1485
  if (match) {
1486
1486
  prop.columnTypes[0] = match[1];
1487
1487
  prop.generated = match[2];
1488
1488
  return;
1489
1489
  }
1490
- const match2 = prop.columnTypes[0]?.trim().match(/^as (.*)/i);
1490
+ const match2 = /^as (.*)/i.exec(prop.columnTypes[0]?.trim());
1491
1491
  if (match2) {
1492
1492
  prop.generated = match2[1];
1493
1493
  }
@@ -1775,7 +1775,7 @@ export class MetadataDiscovery {
1775
1775
  // it could be a runtime type from reflect-metadata
1776
1776
  !SCALAR_TYPES.includes(prop.type) &&
1777
1777
  // or it might be inferred via ts-morph to some generic type alias
1778
- !prop.type.match(/[<>:"';{}]/)) {
1778
+ !/[<>:"';{}]/.exec(prop.type)) {
1779
1779
  const type = prop.length != null && !prop.type.endsWith(`(${prop.length})`) ? `${prop.type}(${prop.length})` : prop.type;
1780
1780
  prop.columnTypes = [type];
1781
1781
  }
@@ -31,7 +31,7 @@ export async function discoverEntities(paths, options) {
31
31
  const found = new Map();
32
32
  for (const filepath of files) {
33
33
  const filename = basename(filepath);
34
- if (!filename.match(/\.[cm]?[jt]s$/) || filename.match(/\.d\.[cm]?ts/)) {
34
+ if (!/\.[cm]?[jt]s$/.exec(filename) || /\.d\.[cm]?ts/.exec(filename)) {
35
35
  continue;
36
36
  }
37
37
  await getEntityClassOrSchema(filepath, found, baseDir);
@@ -1,4 +1,4 @@
1
- export * from './types.js';
1
+ export type * from './types.js';
2
2
  export * from './EntitySchema.js';
3
3
  export * from './MetadataDiscovery.js';
4
4
  export * from './MetadataStorage.js';
package/metadata/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export * from './types.js';
2
1
  export * from './EntitySchema.js';
3
2
  export * from './MetadataDiscovery.js';
4
3
  export * from './MetadataStorage.js';
@@ -34,7 +34,7 @@ export class AbstractNamingStrategy {
34
34
  * @inheritDoc
35
35
  */
36
36
  getEntityName(tableName, schemaName) {
37
- const name = tableName.match(/^[^$_\p{ID_Start}]/u) ? `E_${tableName}` : tableName;
37
+ const name = /^[^$_\p{ID_Start}]/u.exec(tableName) ? `E_${tableName}` : tableName;
38
38
  return this.getClassName(name.replaceAll(/[^\u200C\u200D\p{ID_Continue}]+/gu, r => r
39
39
  .split('')
40
40
  .map(c => `$${c.codePointAt(0)}`)
@@ -1,4 +1,4 @@
1
- export * from './NamingStrategy.js';
1
+ export type * from './NamingStrategy.js';
2
2
  export * from './AbstractNamingStrategy.js';
3
3
  export * from './MongoNamingStrategy.js';
4
4
  export * from './UnderscoreNamingStrategy.js';
@@ -1,4 +1,3 @@
1
- export * from './NamingStrategy.js';
2
1
  export * from './AbstractNamingStrategy.js';
3
2
  export * from './MongoNamingStrategy.js';
4
3
  export * from './UnderscoreNamingStrategy.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.0-dev.303",
3
+ "version": "7.0.0-dev.305",
4
4
  "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.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -180,7 +180,7 @@ export class Platform {
180
180
  return this.getVarcharTypeDeclarationSQL(column);
181
181
  }
182
182
  extractSimpleType(type) {
183
- return type.toLowerCase().match(/[^(), ]+/)[0];
183
+ return /[^(), ]+/.exec(type.toLowerCase())[0];
184
184
  }
185
185
  /**
186
186
  * This should be used only to compare types, it can strip some information like the length.
@@ -380,7 +380,7 @@ export class Platform {
380
380
  let j = 0;
381
381
  let pos = 0;
382
382
  let ret = '';
383
- if (sql[0] === '?') {
383
+ if (sql.startsWith('?')) {
384
384
  if (sql[1] === '?') {
385
385
  ret += this.quoteIdentifier(params[j++]);
386
386
  pos = 2;
package/types/index.d.ts CHANGED
@@ -23,7 +23,8 @@ import { type IType, type TransformContext, Type } from './Type.js';
23
23
  import { Uint8ArrayType } from './Uint8ArrayType.js';
24
24
  import { UnknownType } from './UnknownType.js';
25
25
  import { UuidType } from './UuidType.js';
26
- export { Type, DateType, TimeType, DateTimeType, BigIntType, BlobType, Uint8ArrayType, ArrayType, EnumArrayType, EnumType, JsonType, IntegerType, SmallIntType, TinyIntType, MediumIntType, FloatType, DoubleType, BooleanType, DecimalType, StringType, UuidType, TextType, UnknownType, TransformContext, IntervalType, IType, CharacterType, };
26
+ export type { TransformContext, IType };
27
+ export { Type, DateType, TimeType, DateTimeType, BigIntType, BlobType, Uint8ArrayType, ArrayType, EnumArrayType, EnumType, JsonType, IntegerType, SmallIntType, TinyIntType, MediumIntType, FloatType, DoubleType, BooleanType, DecimalType, StringType, UuidType, TextType, UnknownType, IntervalType, CharacterType, };
27
28
  export declare const types: {
28
29
  readonly date: typeof DateType;
29
30
  readonly time: typeof TimeType;
@@ -327,7 +327,7 @@ export class UnitOfWork {
327
327
  }
328
328
  continue;
329
329
  }
330
- const target = relation && relation[inverseProp];
330
+ const target = relation?.[inverseProp];
331
331
  if (relation && Utils.isCollection(target)) {
332
332
  target.removeWithoutPropagation(entity);
333
333
  }
@@ -255,7 +255,7 @@ export class AbstractMigrator {
255
255
  }
256
256
  getMigrationFilename(name) {
257
257
  name = name.replace(/\.[jt]s$/, '');
258
- return name.match(/^\d{14}$/) ? this.options.fileName(name) : name;
258
+ return /^\d{14}$/.exec(name) ? this.options.fileName(name) : name;
259
259
  }
260
260
  prefix(options) {
261
261
  if (typeof options === 'string' || Array.isArray(options)) {
@@ -310,7 +310,7 @@ export class Configuration {
310
310
  }
311
311
  }
312
312
  catch {
313
- const url = this.options.clientUrl.match(/:\/\/.*\/([^?]+)/);
313
+ const url = /:\/\/.*\/([^?]+)/.exec(this.options.clientUrl);
314
314
  if (url) {
315
315
  this.options.dbName = this.get('dbName', decodeURIComponent(url[1]));
316
316
  }
package/utils/Cursor.js CHANGED
@@ -151,7 +151,7 @@ export class Cursor {
151
151
  }
152
152
  static decode(value) {
153
153
  return JSON.parse(Buffer.from(value, 'base64url').toString('utf8')).map((value) => {
154
- if (typeof value === 'string' && value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/)) {
154
+ if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/.exec(value)) {
155
155
  return new Date(value);
156
156
  }
157
157
  return value;
@@ -271,7 +271,7 @@ export class EntityComparator {
271
271
  if (part.length === 1) {
272
272
  return this.formatCompositeKeyPart(part[0]);
273
273
  }
274
- const formatted = part.map(this.formatCompositeKeyPart).join(', ');
274
+ const formatted = part.map(p => this.formatCompositeKeyPart(p)).join(', ');
275
275
  return `[${formatted}]`;
276
276
  }
277
277
  /**
@@ -404,7 +404,7 @@ export class EntityComparator {
404
404
  let tail = '';
405
405
  return parts
406
406
  .map(k => {
407
- if (k.match(/^\[idx_\d+]$/)) {
407
+ if (/^\[idx_\d+]$/.exec(k)) {
408
408
  tail += k;
409
409
  return '';
410
410
  }
@@ -445,7 +445,7 @@ export class EntityComparator {
445
445
  getEmbeddedPropertySnapshot(meta, prop, context, level, path, dataKey, object = prop.object) {
446
446
  const padding = ' '.repeat(level * 2);
447
447
  const nullCond = `entity${path.map(k => this.wrap(k)).join('')} === null`;
448
- let ret = `${level === 1 ? '' : '\n'}`;
448
+ let ret = level === 1 ? '' : '\n';
449
449
  if (object) {
450
450
  ret += `${padding}if (${nullCond}) ret${dataKey} = null;\n`;
451
451
  }
@@ -708,10 +708,10 @@ export class EntityComparator {
708
708
  return this.getGenericComparator(this.wrap(prop.name), `!equals(last${this.wrap(prop.name)}, current${this.wrap(prop.name)})`);
709
709
  }
710
710
  wrap(key) {
711
- if (key.match(/^\[.*]$/)) {
711
+ if (/^\[.*]$/.exec(key)) {
712
712
  return key;
713
713
  }
714
- return key.match(/^\w+$/) ? `.${key}` : `['${key}']`;
714
+ return /^\w+$/.exec(key) ? `.${key}` : `['${key}']`;
715
715
  }
716
716
  safeKey(key) {
717
717
  return key.replace(/\W/g, '_');
package/utils/Utils.d.ts CHANGED
@@ -22,7 +22,7 @@ export declare class Utils {
22
22
  /**
23
23
  * Removes `undefined` properties (recursively) so they are not saved as nulls
24
24
  */
25
- static dropUndefinedProperties(o: any, value?: undefined | null, visited?: Set<unknown>): void;
25
+ static dropUndefinedProperties(o: any, value?: null, visited?: Set<unknown>): void;
26
26
  /**
27
27
  * Returns the number of properties on `obj`. This is 20x faster than Object.keys(obj).length.
28
28
  * @see https://github.com/deepkit/deepkit-framework/blob/master/packages/core/src/core.ts
package/utils/Utils.js CHANGED
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
123
123
  }
124
124
  export class Utils {
125
125
  static PK_SEPARATOR = '~~~';
126
- static #ORM_VERSION = '7.0.0-dev.303';
126
+ static #ORM_VERSION = '7.0.0-dev.305';
127
127
  /**
128
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
129
129
  */
@@ -543,7 +543,7 @@ export class Utils {
543
543
  !!process.env?.TS_JEST || // check if ts-jest is used
544
544
  !!process.env?.VITEST || // check if vitest is used
545
545
  !!process.versions?.bun || // check if bun is used
546
- process.argv?.slice(1).some(arg => arg.match(/\.([mc]?ts|tsx)$/)) || // executing `.ts` file
546
+ process.argv?.slice(1).some(arg => /\.([mc]?ts|tsx)$/.exec(arg)) || // executing `.ts` file
547
547
  process.execArgv?.some(arg => {
548
548
  return (arg.includes('ts-node') || // check for ts-node loader
549
549
  arg.includes('@swc-node/register') || // check for swc-node/register loader
@@ -559,7 +559,7 @@ export class Utils {
559
559
  return simple;
560
560
  }
561
561
  const objectType = Object.prototype.toString.call(value);
562
- const type = objectType.match(/^\[object (.+)]$/)[1];
562
+ const type = /^\[object (.+)]$/.exec(objectType)[1];
563
563
  if (type === 'Uint8Array') {
564
564
  return 'Buffer';
565
565
  }
@@ -613,7 +613,7 @@ export class Utils {
613
613
  }
614
614
  static findDuplicates(items) {
615
615
  return items.reduce((acc, v, i, arr) => {
616
- return arr.indexOf(v) !== i && acc.indexOf(v) === -1 ? acc.concat(v) : acc;
616
+ return arr.indexOf(v) !== i && !acc.includes(v) ? acc.concat(v) : acc;
617
617
  }, []);
618
618
  }
619
619
  static removeDuplicates(items) {
@@ -677,6 +677,7 @@ export class Utils {
677
677
  return compiledFunctions[key](...context.values());
678
678
  }
679
679
  try {
680
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
680
681
  return new Function(...context.keys(), `'use strict';\n` + code)(...context.values());
681
682
  /* v8 ignore next */
682
683
  }
package/utils/fs-utils.js CHANGED
@@ -150,7 +150,7 @@ export const fs = {
150
150
  }
151
151
  let path = parts.join('/').replace(/\\/g, '/').replace(/\/$/, '');
152
152
  path = normalize(path).replace(/\\/g, '/');
153
- return path.match(/^[/.]|[a-zA-Z]:/) || path.startsWith('!') ? path : './' + path;
153
+ return /^[/.]|[a-zA-Z]:/.exec(path) || path.startsWith('!') ? path : './' + path;
154
154
  },
155
155
  /**
156
156
  * Determines the relative path between two paths. If either path is a `file:` URL,
@@ -101,7 +101,7 @@ export function getOnConflictReturningFields(meta, data, uniqueFields, options)
101
101
  return keys.filter(key => !(key in data));
102
102
  }
103
103
  function getPropertyValue(obj, key) {
104
- if (key.indexOf('.') === -1) {
104
+ if (!key.includes('.')) {
105
105
  return obj[key];
106
106
  }
107
107
  const parts = key.split('.');