@mikro-orm/core 7.0.0-dev.108 → 7.0.0-dev.109

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.
@@ -6,6 +6,7 @@ import { WrappedEntity } from './WrappedEntity.js';
6
6
  import { ReferenceKind } from '../enums.js';
7
7
  import { helper } from './wrap.js';
8
8
  import { inspect } from '../logging/inspect.js';
9
+ import { getEnv } from '../utils/env-vars.js';
9
10
  /**
10
11
  * @internal
11
12
  */
@@ -130,7 +131,7 @@ export class EntityHelper {
130
131
  .forEach(prop => delete object[prop.name]);
131
132
  const ret = inspect(object, { depth });
132
133
  let name = this.constructor.name;
133
- const showEM = ['true', 't', '1'].includes(process.env.MIKRO_ORM_LOG_EM_ID?.toString().toLowerCase() ?? '');
134
+ const showEM = ['true', 't', '1'].includes(getEnv('MIKRO_ORM_LOG_EM_ID')?.toLowerCase() ?? '');
134
135
  if (showEM) {
135
136
  if (helper(this).__em) {
136
137
  name += ` [managed by ${helper(this).__em.id}]`;
@@ -5,5 +5,5 @@ export declare const colors: {
5
5
  yellow: (text: string) => string;
6
6
  grey: (text: string) => string;
7
7
  cyan: (text: string) => string;
8
- enabled: () => boolean | "" | undefined;
8
+ enabled: () => boolean;
9
9
  };
package/logging/colors.js CHANGED
@@ -1,9 +1,10 @@
1
- const bool = (v) => v && ['true', 't', '1'].includes(v.toLowerCase());
2
- const boolIfDefined = (v) => v != null ? bool(v) : true;
3
- const enabled = () => !bool(process.env.NO_COLOR)
4
- && !bool(process.env.MIKRO_ORM_NO_COLOR)
5
- && boolIfDefined(process.env.FORCE_COLOR)
6
- && boolIfDefined(process.env.MIKRO_ORM_COLORS);
1
+ import { getEnv } from '../utils/env-vars.js';
2
+ const bool = (k) => ['true', 't', '1'].includes(getEnv(k)?.toLowerCase() ?? '');
3
+ const boolIfDefined = (k) => getEnv(k) != null ? bool(k) : true;
4
+ const enabled = () => !bool('NO_COLOR')
5
+ && !bool('MIKRO_ORM_NO_COLOR')
6
+ && boolIfDefined('FORCE_COLOR')
7
+ && boolIfDefined('MIKRO_ORM_COLORS');
7
8
  const wrap = (fn) => (text) => enabled() ? fn(text) : text;
8
9
  /** @internal */
9
10
  export const colors = {
@@ -1,12 +1,7 @@
1
1
  let nodeInspect;
2
2
  /** @internal */
3
3
  export function inspect(value, options) {
4
- if (nodeInspect === undefined) {
5
- /* v8 ignore else */
6
- if (globalThis.process?.getBuiltinModule) {
7
- nodeInspect = globalThis.process.getBuiltinModule('node:util').inspect;
8
- }
9
- }
4
+ nodeInspect ??= globalThis.process?.getBuiltinModule?.('node:util').inspect;
10
5
  /* v8 ignore else */
11
6
  if (nodeInspect) {
12
7
  return nodeInspect(value, options);
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.108",
4
+ "version": "7.0.0-dev.109",
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",
@@ -10,6 +10,7 @@ import { RequestContext } from './RequestContext.js';
10
10
  import { DataloaderType, FlushMode, LoadStrategy, PopulateHint } from '../enums.js';
11
11
  import { MemoryCacheAdapter } from '../cache/MemoryCacheAdapter.js';
12
12
  import { EntityComparator } from './EntityComparator.js';
13
+ import { setEnv } from './env-vars.js';
13
14
  const DEFAULTS = {
14
15
  pool: {},
15
16
  entities: [],
@@ -34,7 +35,7 @@ const DEFAULTS = {
34
35
  colors: true,
35
36
  findOneOrFailHandler: (entityName, where) => NotFoundError.findOneFailed(entityName, where),
36
37
  findExactlyOneOrFailHandler: (entityName, where) => NotFoundError.findExactlyOneFailed(entityName, where),
37
- baseDir: process.cwd(),
38
+ baseDir: globalThis.process?.cwd?.(),
38
39
  hydrator: ObjectHydrator,
39
40
  flushMode: FlushMode.AUTO,
40
41
  loadStrategy: LoadStrategy.BALANCED,
@@ -327,7 +328,7 @@ export class Configuration {
327
328
  }
328
329
  }
329
330
  sync() {
330
- process.env.MIKRO_ORM_COLORS = '' + this.options.colors;
331
+ setEnv('MIKRO_ORM_COLORS', this.options.colors);
331
332
  this.logger.setDebugMode(this.options.debug);
332
333
  }
333
334
  validateOptions() {
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.108';
126
+ static #ORM_VERSION = '7.0.0-dev.109';
127
127
  /**
128
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
129
129
  */
@@ -533,14 +533,16 @@ export class Utils {
533
533
  * Tries to detect TypeScript support.
534
534
  */
535
535
  static detectTypeScriptSupport() {
536
+ /* v8 ignore next */
537
+ const process = globalThis.process ?? {};
536
538
  /* v8 ignore next */
537
539
  return process.argv[0].endsWith('ts-node') // running via ts-node directly
538
- || !!process.env.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS // forced explicitly or enabled via `registerTypeScriptSupport()`
539
- || !!process.env.TS_JEST // check if ts-jest is used (works only with v27.0.4+)
540
- || !!process.env.VITEST // check if vitest is used
541
- || !!process.versions.bun // check if bun is used
542
- || process.argv.slice(1).some(arg => arg.match(/\.([mc]?ts|tsx)$/)) // executing `.ts` file
543
- || process.execArgv.some(arg => {
540
+ || !!process.env?.MIKRO_ORM_CLI_ALWAYS_ALLOW_TS // forced explicitly or enabled via `registerTypeScriptSupport()`
541
+ || !!process.env?.TS_JEST // check if ts-jest is used
542
+ || !!process.env?.VITEST // check if vitest is used
543
+ || !!process.versions?.bun // check if bun is used
544
+ || process.argv?.slice(1).some(arg => arg.match(/\.([mc]?ts|tsx)$/)) // executing `.ts` file
545
+ || process.execArgv?.some(arg => {
544
546
  return arg.includes('ts-node') // check for ts-node loader
545
547
  || arg.includes('@swc-node/register') // check for swc-node/register loader
546
548
  || arg.includes('node_modules/tsx/'); // check for tsx loader
@@ -1,3 +1,7 @@
1
1
  import { type Options } from './Configuration.js';
2
2
  /** @internal */
3
+ export declare function setEnv(key: string, value: unknown): void;
4
+ /** @internal */
5
+ export declare function getEnv(key: string): string | undefined;
6
+ /** @internal */
3
7
  export declare function loadEnvironmentVars(): Partial<Options>;
package/utils/env-vars.js CHANGED
@@ -1,5 +1,15 @@
1
1
  import { Utils } from './Utils.js';
2
2
  /** @internal */
3
+ export function setEnv(key, value) {
4
+ if (globalThis.process?.env) {
5
+ globalThis.process.env[key] = String(value);
6
+ }
7
+ }
8
+ /** @internal */
9
+ export function getEnv(key) {
10
+ return globalThis.process?.env?.[key];
11
+ }
12
+ /** @internal */
3
13
  export function loadEnvironmentVars() {
4
14
  const ret = {};
5
15
  const getEnvKey = (key, envPrefix = 'MIKRO_ORM_') => {
@@ -13,8 +23,9 @@ export function loadEnvironmentVars() {
13
23
  const num = (v) => +v;
14
24
  const read = (o, envPrefix, key, mapper = v => v) => {
15
25
  const envKey = getEnvKey(key, envPrefix);
16
- if (envKey in process.env) {
17
- o[key] = mapper(process.env[envKey]);
26
+ /* v8 ignore next */
27
+ if (envKey in (globalThis.process?.env ?? {})) {
28
+ o[key] = mapper(getEnv(envKey));
18
29
  }
19
30
  };
20
31
  const cleanup = (o, k) => Utils.hasObjectKeys(o[k]) ? {} : delete o[k];