@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.
- package/entity/EntityHelper.js +2 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +7 -6
- package/logging/inspect.js +1 -6
- package/package.json +1 -1
- package/utils/Configuration.js +3 -2
- package/utils/Utils.js +9 -7
- package/utils/env-vars.d.ts +4 -0
- package/utils/env-vars.js +13 -2
package/entity/EntityHelper.js
CHANGED
|
@@ -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(
|
|
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}]`;
|
package/logging/colors.d.ts
CHANGED
package/logging/colors.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
&&
|
|
6
|
-
&& boolIfDefined(
|
|
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 = {
|
package/logging/inspect.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
let nodeInspect;
|
|
2
2
|
/** @internal */
|
|
3
3
|
export function inspect(value, options) {
|
|
4
|
-
|
|
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.
|
|
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",
|
package/utils/Configuration.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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.
|
|
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
|
|
539
|
-
|| !!process.env
|
|
540
|
-
|| !!process.env
|
|
541
|
-
|| !!process.versions
|
|
542
|
-
|| process.argv
|
|
543
|
-
|| process.execArgv
|
|
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
|
package/utils/env-vars.d.ts
CHANGED
|
@@ -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
|
-
|
|
17
|
-
|
|
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];
|