@mikro-orm/core 7.0.0-dev.71 → 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.
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.71",
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();
@@ -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
@@ -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
@@ -762,21 +762,6 @@ export class Utils {
762
762
  }
763
763
  return createRequire(resolve(from))(id);
764
764
  }
765
- /**
766
- * Resolve path to a module.
767
- * @param id The module to require
768
- * @param [from] Location to start the node resolution
769
- */
770
- static resolveModulePath(id, from = process.cwd()) {
771
- if (!extname(from)) {
772
- from = join(from, '__fake.js');
773
- }
774
- const path = Utils.normalizePath(createRequire(resolve(from)).resolve(id));
775
- const parts = path.split('/');
776
- const idx = parts.lastIndexOf(id) + 1;
777
- parts.splice(idx, parts.length - idx);
778
- return parts.join('/');
779
- }
780
765
  static async dynamicImport(id) {
781
766
  /* v8 ignore next */
782
767
  const specifier = id.startsWith('file://') ? id : pathToFileURL(id).href;