@mikro-orm/core 7.0.0-dev.105 → 7.0.0-dev.107
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/connections/Connection.d.ts +3 -2
- package/connections/Connection.js +4 -3
- package/package.json +1 -1
- package/unit-of-work/UnitOfWork.js +2 -2
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/RawQueryFragment.js +2 -2
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/Utils.js +1 -1
|
@@ -43,9 +43,10 @@ export declare abstract class Connection {
|
|
|
43
43
|
*/
|
|
44
44
|
ensureConnection(): Promise<void>;
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Execute raw SQL queries, handy from running schema dump loaded from a file.
|
|
47
|
+
* This method doesn't support transactions, as opposed to `orm.schema.execute()`, which is used internally.
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
+
executeDump(dump: string): Promise<void>;
|
|
49
50
|
protected onConnect(): Promise<void>;
|
|
50
51
|
transactional<T>(cb: (trx: Transaction) => Promise<T>, options?: {
|
|
51
52
|
isolationLevel?: IsolationLevel | `${IsolationLevel}`;
|
|
@@ -40,10 +40,11 @@ export class Connection {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Execute raw SQL queries, handy from running schema dump loaded from a file.
|
|
44
|
+
* This method doesn't support transactions, as opposed to `orm.schema.execute()`, which is used internally.
|
|
44
45
|
*/
|
|
45
|
-
async
|
|
46
|
-
throw new Error(`
|
|
46
|
+
async executeDump(dump) {
|
|
47
|
+
throw new Error(`Executing SQL dumps is not supported by current driver`);
|
|
47
48
|
}
|
|
48
49
|
async onConnect() {
|
|
49
50
|
const schemaGenerator = this.config.getExtension('@mikro-orm/schema-generator');
|
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.107",
|
|
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",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
1
|
import { Collection } from '../entity/Collection.js';
|
|
3
2
|
import { EntityHelper } from '../entity/EntityHelper.js';
|
|
4
3
|
import { helper } from '../entity/wrap.js';
|
|
@@ -13,8 +12,9 @@ import { Cascade, DeferMode, EventType, LockMode, ReferenceKind } from '../enums
|
|
|
13
12
|
import { OptimisticLockError, ValidationError } from '../errors.js';
|
|
14
13
|
import { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster.js';
|
|
15
14
|
import { IdentityMap } from './IdentityMap.js';
|
|
15
|
+
import { createAsyncContext } from '../utils/AsyncContext.js';
|
|
16
16
|
// to deal with validation for flush inside flush hooks and `Promise.all`
|
|
17
|
-
const insideFlush =
|
|
17
|
+
const insideFlush = createAsyncContext();
|
|
18
18
|
export class UnitOfWork {
|
|
19
19
|
em;
|
|
20
20
|
/** map of references to managed entities */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function getNodeAsyncContext() {
|
|
2
|
+
const mod = globalThis.process?.getBuiltinModule?.('node:async_hooks');
|
|
3
|
+
/* v8 ignore next */
|
|
4
|
+
if (!mod?.AsyncLocalStorage) {
|
|
5
|
+
throw new Error('AsyncLocalStorage not available');
|
|
6
|
+
}
|
|
7
|
+
return new mod.AsyncLocalStorage();
|
|
8
|
+
}
|
|
9
|
+
/* v8 ignore next */
|
|
10
|
+
function createFallbackAsyncContext() {
|
|
11
|
+
let store;
|
|
12
|
+
// eslint-disable-next-line no-console
|
|
13
|
+
console.warn('AsyncLocalStorage not available');
|
|
14
|
+
return {
|
|
15
|
+
getStore: () => store,
|
|
16
|
+
enterWith: value => store = value,
|
|
17
|
+
run: (value, cb) => {
|
|
18
|
+
const prev = store;
|
|
19
|
+
store = value;
|
|
20
|
+
try {
|
|
21
|
+
return cb();
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
store = prev;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function createAsyncContext() {
|
|
30
|
+
/* v8 ignore next */
|
|
31
|
+
const ALS = globalThis.AsyncLocalStorage;
|
|
32
|
+
/* v8 ignore next */
|
|
33
|
+
if (typeof ALS === 'function' && ALS.prototype?.run) {
|
|
34
|
+
return new ALS();
|
|
35
|
+
}
|
|
36
|
+
/* v8 ignore else */
|
|
37
|
+
if (globalThis.process?.versions?.node) {
|
|
38
|
+
return getNodeAsyncContext();
|
|
39
|
+
}
|
|
40
|
+
/* v8 ignore next */
|
|
41
|
+
return createFallbackAsyncContext();
|
|
42
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
1
|
import { Utils } from './Utils.js';
|
|
2
|
+
import { createAsyncContext } from './AsyncContext.js';
|
|
3
3
|
export class RawQueryFragment {
|
|
4
4
|
sql;
|
|
5
5
|
params;
|
|
6
6
|
static #rawQueryCache = new Map();
|
|
7
|
-
static #storage =
|
|
7
|
+
static #storage = createAsyncContext();
|
|
8
8
|
static #index = 0n;
|
|
9
9
|
static cloneRegistry;
|
|
10
10
|
#used = 0;
|
package/utils/RequestContext.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAsyncContext } from './AsyncContext.js';
|
|
2
2
|
/**
|
|
3
3
|
* Uses `AsyncLocalStorage` to create async context that holds the current EM fork.
|
|
4
4
|
*/
|
|
5
5
|
export class RequestContext {
|
|
6
6
|
map;
|
|
7
|
-
static storage =
|
|
7
|
+
static storage = createAsyncContext();
|
|
8
8
|
static counter = 1;
|
|
9
9
|
id = RequestContext.counter++;
|
|
10
10
|
constructor(map) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAsyncContext } from './AsyncContext.js';
|
|
2
2
|
export class TransactionContext {
|
|
3
3
|
em;
|
|
4
|
-
static storage =
|
|
4
|
+
static storage = createAsyncContext();
|
|
5
5
|
id;
|
|
6
6
|
constructor(em) {
|
|
7
7
|
this.em = em;
|
package/utils/Utils.js
CHANGED
|
@@ -125,7 +125,7 @@ export function parseJsonSafe(value) {
|
|
|
125
125
|
}
|
|
126
126
|
export class Utils {
|
|
127
127
|
static PK_SEPARATOR = '~~~';
|
|
128
|
-
static #ORM_VERSION = '7.0.0-dev.
|
|
128
|
+
static #ORM_VERSION = '7.0.0-dev.107';
|
|
129
129
|
/* v8 ignore next */
|
|
130
130
|
static dynamicImportProvider = (id) => import(id);
|
|
131
131
|
/**
|