@nestjs-transactional/typeorm 1.0.0 → 2.0.0
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/README.md +16 -2
- package/dist/adapter/typeorm.adapter.d.ts +1 -1
- package/dist/adapter/typeorm.adapter.js +6 -10
- package/dist/adapter/typeorm.adapter.js.map +1 -1
- package/dist/helpers/get-entity-manager.js +6 -10
- package/dist/helpers/get-entity-manager.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -20
- package/dist/index.js.map +1 -1
- package/dist/module/typeorm-transactional.module.js +24 -27
- package/dist/module/typeorm-transactional.module.js.map +1 -1
- package/dist/patching/data-source-patches.js +10 -13
- package/dist/patching/data-source-patches.js.map +1 -1
- package/dist/patching/entity-manager-patches.js +9 -13
- package/dist/patching/entity-manager-patches.js.map +1 -1
- package/dist/patching/get-em-data-source.js +1 -4
- package/dist/patching/get-em-data-source.js.map +1 -1
- package/dist/patching/index.d.ts +5 -5
- package/dist/patching/index.js +13 -31
- package/dist/patching/index.js.map +1 -1
- package/dist/patching/managed-registry.js +10 -17
- package/dist/patching/managed-registry.js.map +1 -1
- package/dist/patching/repository-patches.js +17 -21
- package/dist/patching/repository-patches.js.map +1 -1
- package/dist/patching/symbols.js +3 -6
- package/dist/patching/symbols.js.map +1 -1
- package/dist/types/typeorm-transaction-handle.js +1 -2
- package/package.json +23 -20
package/README.md
CHANGED
|
@@ -35,6 +35,20 @@ through service layers, no separate "transactional" repository type.
|
|
|
35
35
|
pnpm add @nestjs-transactional/typeorm @nestjs-transactional/core typeorm @nestjs/typeorm reflect-metadata
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
## Module format
|
|
39
|
+
|
|
40
|
+
This package ships **ESM only**, matching NestJS 12, which is ESM-only
|
|
41
|
+
across its own packages. There is no CommonJS build.
|
|
42
|
+
|
|
43
|
+
A CommonJS application still works: Node loads ESM from `require()`
|
|
44
|
+
since 22.12.0, which is why `engines.node` is `>=22.13.0`. What does not
|
|
45
|
+
follow Node here is tooling with its own module loader — Jest above all,
|
|
46
|
+
which needs `NODE_OPTIONS=--experimental-vm-modules` and a few config
|
|
47
|
+
settings. The 19 example applications in the repository all run their
|
|
48
|
+
suites that way and can be copied from.
|
|
49
|
+
|
|
50
|
+
Reasoning and measurements: [ADR-022](https://github.com/igorgolovanov/nestjs-transactional/blob/main/docs/adr/022-esm-only-packaging.md).
|
|
51
|
+
|
|
38
52
|
## Quick start
|
|
39
53
|
|
|
40
54
|
```ts
|
|
@@ -164,8 +178,8 @@ if you inject adapters by token.
|
|
|
164
178
|
| --- | --- |
|
|
165
179
|
| Node.js | `>=22.13.0` |
|
|
166
180
|
| `typeorm` | `^0.3.0 \|\| ^1.0.0` |
|
|
167
|
-
| `@nestjs/typeorm` | `^10.0.0 \|\| ^11.0.0` |
|
|
168
|
-
| `@nestjs/common` / `@nestjs/core` | `^10.0.0 \|\| ^11.0.0` |
|
|
181
|
+
| `@nestjs/typeorm` | `^10.0.0 \|\| ^11.0.0 \|\| ^12.0.0` |
|
|
182
|
+
| `@nestjs/common` / `@nestjs/core` | `^10.0.0 \|\| ^11.0.0 \|\| ^12.0.0` |
|
|
169
183
|
| `reflect-metadata` | `^0.1.13 \|\| ^0.2.0` |
|
|
170
184
|
| `rxjs` | `^7.0.0` |
|
|
171
185
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type TransactionAdapter, type TransactionOptions } from '@nestjs-transactional/core';
|
|
2
2
|
import type { DataSource } from 'typeorm';
|
|
3
|
-
import type { TypeOrmTransactionHandle } from '../types/typeorm-transaction-handle';
|
|
3
|
+
import type { TypeOrmTransactionHandle } from '../types/typeorm-transaction-handle.js';
|
|
4
4
|
/**
|
|
5
5
|
* TypeORM implementation of {@link TransactionAdapter}. Delegates begin /
|
|
6
6
|
* commit / rollback to `DataSource.transaction` and emits raw `SAVEPOINT`
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.TypeOrmTransactionAdapter = void 0;
|
|
4
|
-
const node_crypto_1 = require("node:crypto");
|
|
5
|
-
const core_1 = require("@nestjs-transactional/core");
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { IllegalTransactionStateError, } from '@nestjs-transactional/core';
|
|
6
3
|
/**
|
|
7
4
|
* TypeORM implementation of {@link TransactionAdapter}. Delegates begin /
|
|
8
5
|
* commit / rollback to `DataSource.transaction` and emits raw `SAVEPOINT`
|
|
@@ -19,7 +16,7 @@ const core_1 = require("@nestjs-transactional/core");
|
|
|
19
16
|
* Server, SAP HANA, MongoDB, Spanner, Cordova) instead of emitting SQL
|
|
20
17
|
* they will refuse.
|
|
21
18
|
*/
|
|
22
|
-
class TypeOrmTransactionAdapter {
|
|
19
|
+
export class TypeOrmTransactionAdapter {
|
|
23
20
|
dataSource;
|
|
24
21
|
instanceName;
|
|
25
22
|
name = 'typeorm';
|
|
@@ -48,7 +45,7 @@ class TypeOrmTransactionAdapter {
|
|
|
48
45
|
await applyReadOnly(entityManager, this.dataSource.options.type);
|
|
49
46
|
}
|
|
50
47
|
const handle = {
|
|
51
|
-
id:
|
|
48
|
+
id: randomUUID(),
|
|
52
49
|
adapterName: this.name,
|
|
53
50
|
entityManager,
|
|
54
51
|
};
|
|
@@ -61,7 +58,7 @@ class TypeOrmTransactionAdapter {
|
|
|
61
58
|
}
|
|
62
59
|
async runInSavepoint(parent, fn) {
|
|
63
60
|
this.assertSavepointsSupported();
|
|
64
|
-
const savepointName = `sp_${
|
|
61
|
+
const savepointName = `sp_${randomUUID().replace(/-/g, '_').substring(0, 30)}`;
|
|
65
62
|
await parent.entityManager.query(`SAVEPOINT ${savepointName}`);
|
|
66
63
|
try {
|
|
67
64
|
const result = await fn(parent);
|
|
@@ -94,14 +91,13 @@ class TypeOrmTransactionAdapter {
|
|
|
94
91
|
const support = this.dataSource.driver
|
|
95
92
|
?.transactionSupport;
|
|
96
93
|
if (support !== undefined && support !== 'nested') {
|
|
97
|
-
throw new
|
|
94
|
+
throw new IllegalTransactionStateError(`PropagationMode.NESTED needs savepoints, which the '${this.dataSource.options.type}' ` +
|
|
98
95
|
`driver does not support (TypeORM reports transactionSupport: '${support}'). ` +
|
|
99
96
|
"Use PropagationMode.REQUIRED to join the caller's transaction, or " +
|
|
100
97
|
'REQUIRES_NEW for an independent one.');
|
|
101
98
|
}
|
|
102
99
|
}
|
|
103
100
|
}
|
|
104
|
-
exports.TypeOrmTransactionAdapter = TypeOrmTransactionAdapter;
|
|
105
101
|
/**
|
|
106
102
|
* Dialects where `SET TRANSACTION READ ONLY` is valid after `BEGIN`,
|
|
107
103
|
* provided it precedes the transaction's first query.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeorm.adapter.js","sourceRoot":"","sources":["../../src/adapter/typeorm.adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typeorm.adapter.js","sourceRoot":"","sources":["../../src/adapter/typeorm.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,4BAA4B,GAI7B,MAAM,4BAA4B,CAAC;AAapC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,yBAAyB;IAIjB;IAMR;IATF,IAAI,GAAG,SAAS,CAAC;IAE1B,YACmB,UAAsB;IACvC;;;;OAIG;IACM,YAAoB;QANZ,eAAU,GAAV,UAAU,CAAY;QAM9B,iBAAY,GAAZ,YAAY,CAAQ;IAC5B,CAAC;IAEJ;;;;OAIG;IACH,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,OAA2B,EAC3B,EAAoD;QAEpD,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,KAAK,EAAE,aAA4B,EAAc,EAAE;YAChE,IAAI,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BAAyB;QAC/B,MAAM,OAAO,GAAI,IAAI,CAAC,UAAU,CAAC,MAAsD;YACrF,EAAE,kBAAkB,CAAC;QAEvB,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;YAClD,MAAM,IAAI,4BAA4B,CACpC,uDAAuD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,IAAI;gBACrF,iEAAiE,OAAO,MAAM;gBAC9E,oEAAoE;gBACpE,sCAAsC,CACzC,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC;IACtD,UAAU;IACV,aAAa;IACb,iBAAiB;CAClB,CAAC,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,aAAa,CAAC,aAA4B,EAAE,OAAe;IACxE,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QACrC,OAAO;IACT,CAAC;IACD,MAAM,aAAa,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAAiC;IACrD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAA0B,CAAC;AAC3D,CAAC"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrentEntityManager = getCurrentEntityManager;
|
|
4
|
-
exports.isInTransaction = isInTransaction;
|
|
5
|
-
const core_1 = require("@nestjs-transactional/core");
|
|
1
|
+
import { IllegalTransactionStateError, TransactionContext } from '@nestjs-transactional/core';
|
|
6
2
|
/**
|
|
7
3
|
* Compose the `TransactionContext` lookup key for the TypeORM adapter.
|
|
8
4
|
* Must match the `${adapterName}:${instanceName}` format that
|
|
@@ -30,15 +26,15 @@ function typeOrmContextKey(adapterInstance) {
|
|
|
30
26
|
* @param adapterInstance - Adapter instance name. Defaults to `'default'`.
|
|
31
27
|
* @param fallback - DataSource used when no transaction is active.
|
|
32
28
|
*/
|
|
33
|
-
function getCurrentEntityManager(adapterInstance = 'default', fallback) {
|
|
34
|
-
const active =
|
|
29
|
+
export function getCurrentEntityManager(adapterInstance = 'default', fallback) {
|
|
30
|
+
const active = TransactionContext.getActiveTransaction(typeOrmContextKey(adapterInstance));
|
|
35
31
|
if (active !== undefined) {
|
|
36
32
|
return active.handle.entityManager;
|
|
37
33
|
}
|
|
38
34
|
if (fallback !== undefined) {
|
|
39
35
|
return fallback.manager;
|
|
40
36
|
}
|
|
41
|
-
throw new
|
|
37
|
+
throw new IllegalTransactionStateError(`No active transaction for 'typeorm:${adapterInstance}' and no fallback DataSource ` +
|
|
42
38
|
`provided. Either wrap the call with @Transactional() or pass a DataSource as fallback.`);
|
|
43
39
|
}
|
|
44
40
|
/**
|
|
@@ -46,7 +42,7 @@ function getCurrentEntityManager(adapterInstance = 'default', fallback) {
|
|
|
46
42
|
* instance? Useful to guard side effects that must only fire inside a
|
|
47
43
|
* transaction.
|
|
48
44
|
*/
|
|
49
|
-
function isInTransaction(adapterInstance = 'default') {
|
|
50
|
-
return
|
|
45
|
+
export function isInTransaction(adapterInstance = 'default') {
|
|
46
|
+
return TransactionContext.getActiveTransaction(typeOrmContextKey(adapterInstance)) !== undefined;
|
|
51
47
|
}
|
|
52
48
|
//# sourceMappingURL=get-entity-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-entity-manager.js","sourceRoot":"","sources":["../../src/helpers/get-entity-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-entity-manager.js","sourceRoot":"","sources":["../../src/helpers/get-entity-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAK9F;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,eAAuB;IAChD,OAAO,WAAW,eAAe,EAAE,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,uBAAuB,CACrC,eAAe,GAAG,SAAS,EAC3B,QAAqB;IAErB,MAAM,MAAM,GAAG,kBAAkB,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAAC;IAE3F,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAQ,MAAM,CAAC,MAAmC,CAAC,aAAa,CAAC;IACnE,CAAC;IAED,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC1B,CAAC;IAED,MAAM,IAAI,4BAA4B,CACpC,sCAAsC,eAAe,+BAA+B;QAClF,wFAAwF,CAC3F,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,eAAe,GAAG,SAAS;IACzD,OAAO,kBAAkB,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,KAAK,SAAS,CAAC;AACnG,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './types/typeorm-transaction-handle';
|
|
2
|
-
export * from './adapter/typeorm.adapter';
|
|
3
|
-
export * from './helpers/get-entity-manager';
|
|
4
|
-
export * from './module/typeorm-transactional.module';
|
|
1
|
+
export * from './types/typeorm-transaction-handle.js';
|
|
2
|
+
export * from './adapter/typeorm.adapter.js';
|
|
3
|
+
export * from './helpers/get-entity-manager.js';
|
|
4
|
+
export * from './module/typeorm-transactional.module.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types/typeorm-transaction-handle"), exports);
|
|
18
|
-
__exportStar(require("./adapter/typeorm.adapter"), exports);
|
|
19
|
-
__exportStar(require("./helpers/get-entity-manager"), exports);
|
|
20
|
-
__exportStar(require("./module/typeorm-transactional.module"), exports);
|
|
1
|
+
export * from './types/typeorm-transaction-handle.js';
|
|
2
|
+
export * from './adapter/typeorm.adapter.js';
|
|
3
|
+
export * from './helpers/get-entity-manager.js';
|
|
4
|
+
export * from './module/typeorm-transactional.module.js';
|
|
21
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,0CAA0C,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -12,14 +11,12 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
12
|
};
|
|
14
13
|
var TypeOrmTransactionalModule_1;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const typeorm_adapter_1 = require("../adapter/typeorm.adapter");
|
|
22
|
-
const patching_1 = require("../patching");
|
|
14
|
+
import { Inject, Injectable, Module, } from '@nestjs/common';
|
|
15
|
+
import { ModuleRef } from '@nestjs/core';
|
|
16
|
+
import { getDataSourceToken } from '@nestjs/typeorm';
|
|
17
|
+
import { ADAPTER_REGISTRY, AdapterRegistry, getTransactionalAdapterToken, } from '@nestjs-transactional/core';
|
|
18
|
+
import { TypeOrmTransactionAdapter } from '../adapter/typeorm.adapter.js';
|
|
19
|
+
import { applyAllPatches, markAsManaged, patchDataSourceInstance, resetPatchingForTesting, } from '../patching/index.js';
|
|
23
20
|
// ---------------------------------------------------------------
|
|
24
21
|
// Apply Repository / EntityManager prototype patches at MODULE-LOAD
|
|
25
22
|
// time, NOT at `forRoot` factory time.
|
|
@@ -41,7 +38,7 @@ const patching_1 = require("../patching");
|
|
|
41
38
|
// import (e.g. a stale duplicate copy on disk under pnpm hoist
|
|
42
39
|
// glitches) is a no-op via the install-once flag inside each patch.
|
|
43
40
|
// ---------------------------------------------------------------
|
|
44
|
-
|
|
41
|
+
applyAllPatches();
|
|
45
42
|
const ASYNC_OPTIONS_TOKEN = (id) => Symbol(`TYPEORM_TRANSACTIONAL_ASYNC_OPTIONS[${id}]`);
|
|
46
43
|
/**
|
|
47
44
|
* NestJS module that binds a TypeORM {@link DataSource} to the core
|
|
@@ -114,7 +111,7 @@ let TypeOrmTransactionalModule = class TypeOrmTransactionalModule {
|
|
|
114
111
|
* @internal
|
|
115
112
|
*/
|
|
116
113
|
static resetForTesting() {
|
|
117
|
-
|
|
114
|
+
resetPatchingForTesting();
|
|
118
115
|
this.asyncCounter = 0;
|
|
119
116
|
}
|
|
120
117
|
/**
|
|
@@ -134,8 +131,8 @@ let TypeOrmTransactionalModule = class TypeOrmTransactionalModule {
|
|
|
134
131
|
*/
|
|
135
132
|
static forRoot(options = {}) {
|
|
136
133
|
const dataSourceName = options.dataSource ?? 'default';
|
|
137
|
-
const dataSourceToken =
|
|
138
|
-
const adapterToken =
|
|
134
|
+
const dataSourceToken = getDataSourceToken(dataSourceName);
|
|
135
|
+
const adapterToken = getTransactionalAdapterToken(dataSourceName);
|
|
139
136
|
const adapterProvider = {
|
|
140
137
|
provide: adapterToken,
|
|
141
138
|
useFactory: (ds, registry) => registerManagedDataSource({
|
|
@@ -144,7 +141,7 @@ let TypeOrmTransactionalModule = class TypeOrmTransactionalModule {
|
|
|
144
141
|
isDefault: options.isDefault ?? false,
|
|
145
142
|
registry,
|
|
146
143
|
}),
|
|
147
|
-
inject: [dataSourceToken,
|
|
144
|
+
inject: [dataSourceToken, ADAPTER_REGISTRY],
|
|
148
145
|
};
|
|
149
146
|
return {
|
|
150
147
|
module: TypeOrmTransactionalModule_1,
|
|
@@ -211,10 +208,10 @@ let TypeOrmTransactionalModule = class TypeOrmTransactionalModule {
|
|
|
211
208
|
};
|
|
212
209
|
}
|
|
213
210
|
};
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
(0, common_1.Module)({})
|
|
211
|
+
TypeOrmTransactionalModule = TypeOrmTransactionalModule_1 = __decorate([
|
|
212
|
+
Module({})
|
|
217
213
|
], TypeOrmTransactionalModule);
|
|
214
|
+
export { TypeOrmTransactionalModule };
|
|
218
215
|
/**
|
|
219
216
|
* Generate a unique `OnModuleInit` registration class per
|
|
220
217
|
* `forRootAsync` call. The class injects the async-resolved
|
|
@@ -242,7 +239,7 @@ function createAsyncRegistrationClass(id, asyncToken) {
|
|
|
242
239
|
}
|
|
243
240
|
onModuleInit() {
|
|
244
241
|
const dataSourceName = this.resolved.dataSource ?? 'default';
|
|
245
|
-
const dataSourceToken =
|
|
242
|
+
const dataSourceToken = getDataSourceToken(dataSourceName);
|
|
246
243
|
const ds = this.moduleRef.get(dataSourceToken, {
|
|
247
244
|
strict: false,
|
|
248
245
|
});
|
|
@@ -255,11 +252,11 @@ function createAsyncRegistrationClass(id, asyncToken) {
|
|
|
255
252
|
}
|
|
256
253
|
};
|
|
257
254
|
TypeOrmTransactionalAsyncRegistration = __decorate([
|
|
258
|
-
|
|
259
|
-
__param(0,
|
|
260
|
-
__param(1,
|
|
261
|
-
__metadata("design:paramtypes", [Object,
|
|
262
|
-
|
|
255
|
+
Injectable(),
|
|
256
|
+
__param(0, Inject(asyncToken)),
|
|
257
|
+
__param(1, Inject(ADAPTER_REGISTRY)),
|
|
258
|
+
__metadata("design:paramtypes", [Object, AdapterRegistry,
|
|
259
|
+
ModuleRef])
|
|
263
260
|
], TypeOrmTransactionalAsyncRegistration);
|
|
264
261
|
// Distinguish each generated class so a TypeScript reflection /
|
|
265
262
|
// logging consumer can tell them apart. Class identity itself is
|
|
@@ -279,10 +276,10 @@ function createAsyncRegistrationClass(id, asyncToken) {
|
|
|
279
276
|
*/
|
|
280
277
|
function registerManagedDataSource(args) {
|
|
281
278
|
const { dataSource, dataSourceName, isDefault, registry } = args;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const adapter = new
|
|
279
|
+
applyAllPatches();
|
|
280
|
+
markAsManaged(dataSource, dataSourceName);
|
|
281
|
+
patchDataSourceInstance(dataSource);
|
|
282
|
+
const adapter = new TypeOrmTransactionAdapter(dataSource, dataSourceName);
|
|
286
283
|
registry.register({ adapterName: 'typeorm', instanceName: dataSourceName, adapter }, isDefault);
|
|
287
284
|
return adapter;
|
|
288
285
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeorm-transactional.module.js","sourceRoot":"","sources":["../../src/module/typeorm-transactional.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typeorm-transactional.module.js","sourceRoot":"","sources":["../../src/module/typeorm-transactional.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAGL,MAAM,EACN,UAAU,EAEV,MAAM,GAKP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,4BAA4B,GAC7B,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,eAAe,EACf,aAAa,EACb,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAE9B,kEAAkE;AAClE,oEAAoE;AACpE,uCAAuC;AACvC,EAAE;AACF,iEAAiE;AACjE,yDAAyD;AACzD,iEAAiE;AACjE,uEAAuE;AACvE,iEAAiE;AACjE,wDAAwD;AACxD,gEAAgE;AAChE,6DAA6D;AAC7D,+DAA+D;AAC/D,iBAAiB;AACjB,EAAE;AACF,iEAAiE;AACjE,+DAA+D;AAC/D,oEAAoE;AACpE,+DAA+D;AAC/D,oEAAoE;AACpE,kEAAkE;AAClE,eAAe,EAAE,CAAC;AAuDlB,MAAM,mBAAmB,GAAG,CAAC,EAAU,EAAU,EAAE,CACjD,MAAM,CAAC,uCAAuC,EAAE,GAAG,CAAC,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEI,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;;IACrC;;;;;;OAMG;IACK,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC;IAEhC;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,eAAe;QACpB,uBAAuB,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AAQ,CAAC,SAAS,IAAI,KAAK;gBAC3C,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB,CAAC,CAAC;QACL,CAAC;KACF,CAAA;IAtBK,qCAAqC;QAD1C,UAAU,EAAE;QAGR,WAAA,MAAM,CAAC,UAAU,CAAC,CAAA;QAElB,WAAA,MAAM,CAAC,gBAAgB,CAAC,CAAA;iDACE,eAAe;YACd,SAAS;OANnC,qCAAqC,CAsB1C;IACD,gEAAgE;IAChE,iEAAiE;IACjE,kEAAkE;IAClE,iEAAiE;IACjE,MAAM,CAAC,cAAc,CAAC,qCAAqC,EAAE,MAAM,EAAE;QACnE,KAAK,EAAE,yCAAyC,EAAE,EAAE;KACrD,CAAC,CAAC;IACH,OAAO,qCAAqC,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,SAAS,yBAAyB,CAAC,IAKlC;IACC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACjE,eAAe,EAAE,CAAC;IAClB,aAAa,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAC1C,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAEpC,MAAM,OAAO,GAAG,IAAI,yBAAyB,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;IAChG,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment */
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument */
|
|
3
2
|
// The patching machinery overrides instance-level methods on
|
|
4
3
|
// TypeORM `DataSource` objects (`manager` getter/setter,
|
|
5
4
|
// `query`, `createQueryBuilder`) via runtime property descriptors.
|
|
@@ -7,10 +6,8 @@
|
|
|
7
6
|
// TypeORM's generic signatures don't survive the wrap; the runtime
|
|
8
7
|
// contract is documented in JSDoc above each patch. File-level
|
|
9
8
|
// disable keeps the patch code readable.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const managed_registry_1 = require("./managed-registry");
|
|
13
|
-
const symbols_1 = require("./symbols");
|
|
9
|
+
import { getActiveEntityManager, getManagedDataSourceName } from './managed-registry.js';
|
|
10
|
+
import { TYPEORM_DATA_SOURCE_PATCHED } from './symbols.js';
|
|
14
11
|
/**
|
|
15
12
|
* Apply per-instance patches to a single `DataSource` at the time
|
|
16
13
|
* it's registered as managed. Three patches go on the instance
|
|
@@ -56,9 +53,9 @@ const symbols_1 = require("./symbols");
|
|
|
56
53
|
* destroy the DataSource and create a fresh one (the standard
|
|
57
54
|
* pattern; integration tests already do this in `afterAll`).
|
|
58
55
|
*/
|
|
59
|
-
function patchDataSourceInstance(dataSource) {
|
|
56
|
+
export function patchDataSourceInstance(dataSource) {
|
|
60
57
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
-
if (dataSource[
|
|
58
|
+
if (dataSource[TYPEORM_DATA_SOURCE_PATCHED] === true) {
|
|
62
59
|
return;
|
|
63
60
|
}
|
|
64
61
|
// (1) `manager` — getter/setter on the instance.
|
|
@@ -66,11 +63,11 @@ function patchDataSourceInstance(dataSource) {
|
|
|
66
63
|
Object.defineProperty(dataSource, 'manager', {
|
|
67
64
|
configurable: true,
|
|
68
65
|
get() {
|
|
69
|
-
const dsName =
|
|
66
|
+
const dsName = getManagedDataSourceName(dataSource);
|
|
70
67
|
if (dsName === undefined) {
|
|
71
68
|
return originalManager;
|
|
72
69
|
}
|
|
73
|
-
const active =
|
|
70
|
+
const active = getActiveEntityManager(dsName);
|
|
74
71
|
return active ?? originalManager;
|
|
75
72
|
},
|
|
76
73
|
set(manager) {
|
|
@@ -120,7 +117,7 @@ function patchDataSourceInstance(dataSource) {
|
|
|
120
117
|
};
|
|
121
118
|
// Stamp marker so re-entry is a no-op.
|
|
122
119
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
|
-
dataSource[
|
|
120
|
+
dataSource[TYPEORM_DATA_SOURCE_PATCHED] = true;
|
|
124
121
|
}
|
|
125
122
|
/**
|
|
126
123
|
* Helper — look up the active transactional EntityManager for this
|
|
@@ -129,11 +126,11 @@ function patchDataSourceInstance(dataSource) {
|
|
|
129
126
|
* `createQueryBuilder` patches share one resolution rule.
|
|
130
127
|
*/
|
|
131
128
|
function pickActiveQueryRunner(ds) {
|
|
132
|
-
const dsName =
|
|
129
|
+
const dsName = getManagedDataSourceName(ds);
|
|
133
130
|
if (dsName === undefined) {
|
|
134
131
|
return undefined;
|
|
135
132
|
}
|
|
136
|
-
const active =
|
|
133
|
+
const active = getActiveEntityManager(dsName);
|
|
137
134
|
return active?.queryRunner;
|
|
138
135
|
}
|
|
139
136
|
//# sourceMappingURL=data-source-patches.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-source-patches.js","sourceRoot":"","sources":["../../src/patching/data-source-patches.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"data-source-patches.js","sourceRoot":"","sources":["../../src/patching/data-source-patches.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,6DAA6D;AAC7D,yDAAyD;AACzD,mEAAmE;AACnE,kEAAkE;AAClE,mEAAmE;AACnE,+DAA+D;AAC/D,yCAAyC;AAIzC,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACzF,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,UAAU,uBAAuB,CAAC,UAAsB;IAC5D,8DAA8D;IAC9D,IAAK,UAAk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-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/unbound-method */
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/unbound-method */
|
|
3
2
|
// The patching machinery wraps `EntityManager.prototype.getRepository`
|
|
4
3
|
// and stamps hidden symbol-keyed properties on returned
|
|
5
4
|
// `Repository` instances. These properties live outside TypeORM's
|
|
@@ -7,11 +6,8 @@
|
|
|
7
6
|
// lint rules fire on every access. File-level disable keeps the
|
|
8
7
|
// patch code readable; the runtime contract is documented in the
|
|
9
8
|
// JSDoc above each patch.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.areEntityManagerPatchesApplied = areEntityManagerPatchesApplied;
|
|
13
|
-
const typeorm_1 = require("typeorm");
|
|
14
|
-
const symbols_1 = require("./symbols");
|
|
9
|
+
import { EntityManager } from 'typeorm';
|
|
10
|
+
import { TYPEORM_ENTITY_MANAGER_NAME } from './symbols.js';
|
|
15
11
|
/**
|
|
16
12
|
* Tracks whether `EntityManager.prototype.getRepository` has been
|
|
17
13
|
* wrapped. Idempotent install pattern matching
|
|
@@ -52,16 +48,16 @@ let originalGetRepository;
|
|
|
52
48
|
*. Use `getCurrentEntityManager()` as the escape
|
|
53
49
|
* hatch.
|
|
54
50
|
*/
|
|
55
|
-
function applyEntityManagerPatches() {
|
|
51
|
+
export function applyEntityManagerPatches() {
|
|
56
52
|
if (installed) {
|
|
57
53
|
return;
|
|
58
54
|
}
|
|
59
|
-
originalGetRepository =
|
|
55
|
+
originalGetRepository = EntityManager.prototype.getRepository;
|
|
60
56
|
// The generic shape of `getRepository<Entity>` resists clean
|
|
61
57
|
// typing on a wrapper; cast through `any` to keep the wrap a
|
|
62
58
|
// single statement. Runtime contract is unchanged.
|
|
63
59
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
-
|
|
60
|
+
EntityManager.prototype.getRepository = function patchedGetRepository(
|
|
65
61
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
62
|
target) {
|
|
67
63
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -71,16 +67,16 @@ function applyEntityManagerPatches() {
|
|
|
71
67
|
// calls — re-stamping with the same value is a no-op, but the
|
|
72
68
|
// guard makes the intent explicit.
|
|
73
69
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
|
-
if (repo[
|
|
70
|
+
if (repo[TYPEORM_ENTITY_MANAGER_NAME] === undefined) {
|
|
75
71
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
76
|
-
repo[
|
|
72
|
+
repo[TYPEORM_ENTITY_MANAGER_NAME] = this;
|
|
77
73
|
}
|
|
78
74
|
return repo;
|
|
79
75
|
};
|
|
80
76
|
installed = true;
|
|
81
77
|
}
|
|
82
78
|
/** Predicate exported for unit tests. @internal */
|
|
83
|
-
function areEntityManagerPatchesApplied() {
|
|
79
|
+
export function areEntityManagerPatchesApplied() {
|
|
84
80
|
return installed;
|
|
85
81
|
}
|
|
86
82
|
//# sourceMappingURL=entity-manager-patches.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-manager-patches.js","sourceRoot":"","sources":["../../src/patching/entity-manager-patches.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity-manager-patches.js","sourceRoot":"","sources":["../../src/patching/entity-manager-patches.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,uEAAuE;AACvE,wDAAwD;AACxD,kEAAkE;AAClE,8DAA8D;AAC9D,gEAAgE;AAChE,iEAAiE;AACjE,0BAA0B;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D;;;;;;GAMG;AACH,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB;;;GAGG;AACH,IAAI,qBAA+E,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,yBAAyB;IACvC,IAAI,SAAS,EAAE,CAAC;QACd,OAAO;IACT,CAAC;IAED,qBAAqB,GAAG,aAAa,CAAC,SAAS,CAAC,aAAa,CAAC;IAE9D,6DAA6D;IAC7D,6DAA6D;IAC7D,mDAAmD;IACnD,8DAA8D;IAC7D,aAAa,CAAC,SAAiB,CAAC,aAAa,GAAG,SAAS,oBAAoB;IAE5E,8DAA8D;IAC9D,MAAW;QAEX,oEAAoE;QACpE,MAAM,IAAI,GAAG,qBAAsB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACvD,8DAA8D;QAC9D,6DAA6D;QAC7D,8DAA8D;QAC9D,mCAAmC;QACnC,8DAA8D;QAC9D,IAAK,IAAY,CAAC,2BAA2B,CAAC,KAAK,SAAS,EAAE,CAAC;YAC7D,8DAA8D;YAC7D,IAAY,CAAC,2BAA2B,CAAC,GAAG,IAAI,CAAC;QACpD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEF,SAAS,GAAG,IAAI,CAAC;AACnB,CAAC;AAED,mDAAmD;AACnD,MAAM,UAAU,8BAA8B;IAC5C,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEmDataSource = getEmDataSource;
|
|
4
1
|
/**
|
|
5
2
|
* Read the owning {@link DataSource} from an {@link EntityManager}
|
|
6
3
|
* across TypeORM versions.
|
|
@@ -12,7 +9,7 @@ exports.getEmDataSource = getEmDataSource;
|
|
|
12
9
|
* patching layer compatible with both peer ranges without a runtime
|
|
13
10
|
* version check.
|
|
14
11
|
*/
|
|
15
|
-
function getEmDataSource(em) {
|
|
12
|
+
export function getEmDataSource(em) {
|
|
16
13
|
const shape = em;
|
|
17
14
|
const ds = shape.dataSource ?? shape.connection;
|
|
18
15
|
if (ds === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-em-data-source.js","sourceRoot":"","sources":["../../src/patching/get-em-data-source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-em-data-source.js","sourceRoot":"","sources":["../../src/patching/get-em-data-source.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,EAAiB;IAC/C,MAAM,KAAK,GAAG,EAGb,CAAC;IACF,MAAM,EAAE,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC;IAChD,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,+DAA+D;YAC7D,8BAA8B,CACjC,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/patching/index.d.ts
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
export { applyRepositoryPatches, areRepositoryPatchesApplied } from './repository-patches';
|
|
11
|
-
export { applyEntityManagerPatches, areEntityManagerPatchesApplied, } from './entity-manager-patches';
|
|
12
|
-
export { patchDataSourceInstance } from './data-source-patches';
|
|
13
|
-
export { getActiveEntityManager, getManagedDataSourceName, isManaged, markAsManaged, resetManagedRegistry, } from './managed-registry';
|
|
14
|
-
export { TYPEORM_DATA_SOURCE_NAME, TYPEORM_DATA_SOURCE_PATCHED, TYPEORM_ENTITY_MANAGER_NAME, } from './symbols';
|
|
10
|
+
export { applyRepositoryPatches, areRepositoryPatchesApplied } from './repository-patches.js';
|
|
11
|
+
export { applyEntityManagerPatches, areEntityManagerPatchesApplied, } from './entity-manager-patches.js';
|
|
12
|
+
export { patchDataSourceInstance } from './data-source-patches.js';
|
|
13
|
+
export { getActiveEntityManager, getManagedDataSourceName, isManaged, markAsManaged, resetManagedRegistry, } from './managed-registry.js';
|
|
14
|
+
export { TYPEORM_DATA_SOURCE_NAME, TYPEORM_DATA_SOURCE_PATCHED, TYPEORM_ENTITY_MANAGER_NAME, } from './symbols.js';
|
|
15
15
|
/**
|
|
16
16
|
* Apply both prototype-level patch families in one call. Used by
|
|
17
17
|
* `TypeOrmTransactionalModule.forRoot`'s registration factory.
|
package/dist/patching/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Transparent transactional repositories — patching
|
|
4
3
|
* machinery. Exported so the module layer can drive `applyAllPatches`
|
|
@@ -8,31 +7,14 @@
|
|
|
8
7
|
*
|
|
9
8
|
* @internal
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(exports, "applyRepositoryPatches", { enumerable: true, get: function () { return repository_patches_2.applyRepositoryPatches; } });
|
|
20
|
-
Object.defineProperty(exports, "areRepositoryPatchesApplied", { enumerable: true, get: function () { return repository_patches_2.areRepositoryPatchesApplied; } });
|
|
21
|
-
var entity_manager_patches_2 = require("./entity-manager-patches");
|
|
22
|
-
Object.defineProperty(exports, "applyEntityManagerPatches", { enumerable: true, get: function () { return entity_manager_patches_2.applyEntityManagerPatches; } });
|
|
23
|
-
Object.defineProperty(exports, "areEntityManagerPatchesApplied", { enumerable: true, get: function () { return entity_manager_patches_2.areEntityManagerPatchesApplied; } });
|
|
24
|
-
var data_source_patches_1 = require("./data-source-patches");
|
|
25
|
-
Object.defineProperty(exports, "patchDataSourceInstance", { enumerable: true, get: function () { return data_source_patches_1.patchDataSourceInstance; } });
|
|
26
|
-
var managed_registry_2 = require("./managed-registry");
|
|
27
|
-
Object.defineProperty(exports, "getActiveEntityManager", { enumerable: true, get: function () { return managed_registry_2.getActiveEntityManager; } });
|
|
28
|
-
Object.defineProperty(exports, "getManagedDataSourceName", { enumerable: true, get: function () { return managed_registry_2.getManagedDataSourceName; } });
|
|
29
|
-
Object.defineProperty(exports, "isManaged", { enumerable: true, get: function () { return managed_registry_2.isManaged; } });
|
|
30
|
-
Object.defineProperty(exports, "markAsManaged", { enumerable: true, get: function () { return managed_registry_2.markAsManaged; } });
|
|
31
|
-
Object.defineProperty(exports, "resetManagedRegistry", { enumerable: true, get: function () { return managed_registry_2.resetManagedRegistry; } });
|
|
32
|
-
var symbols_1 = require("./symbols");
|
|
33
|
-
Object.defineProperty(exports, "TYPEORM_DATA_SOURCE_NAME", { enumerable: true, get: function () { return symbols_1.TYPEORM_DATA_SOURCE_NAME; } });
|
|
34
|
-
Object.defineProperty(exports, "TYPEORM_DATA_SOURCE_PATCHED", { enumerable: true, get: function () { return symbols_1.TYPEORM_DATA_SOURCE_PATCHED; } });
|
|
35
|
-
Object.defineProperty(exports, "TYPEORM_ENTITY_MANAGER_NAME", { enumerable: true, get: function () { return symbols_1.TYPEORM_ENTITY_MANAGER_NAME; } });
|
|
10
|
+
import { applyEntityManagerPatches } from './entity-manager-patches.js';
|
|
11
|
+
import { resetManagedRegistry } from './managed-registry.js';
|
|
12
|
+
import { applyRepositoryPatches } from './repository-patches.js';
|
|
13
|
+
export { applyRepositoryPatches, areRepositoryPatchesApplied } from './repository-patches.js';
|
|
14
|
+
export { applyEntityManagerPatches, areEntityManagerPatchesApplied, } from './entity-manager-patches.js';
|
|
15
|
+
export { patchDataSourceInstance } from './data-source-patches.js';
|
|
16
|
+
export { getActiveEntityManager, getManagedDataSourceName, isManaged, markAsManaged, resetManagedRegistry, } from './managed-registry.js';
|
|
17
|
+
export { TYPEORM_DATA_SOURCE_NAME, TYPEORM_DATA_SOURCE_PATCHED, TYPEORM_ENTITY_MANAGER_NAME, } from './symbols.js';
|
|
36
18
|
/**
|
|
37
19
|
* Apply both prototype-level patch families in one call. Used by
|
|
38
20
|
* `TypeOrmTransactionalModule.forRoot`'s registration factory.
|
|
@@ -43,9 +25,9 @@ Object.defineProperty(exports, "TYPEORM_ENTITY_MANAGER_NAME", { enumerable: true
|
|
|
43
25
|
* are NOT included here because they apply to a specific instance
|
|
44
26
|
* and are driven separately at registration time, also idempotent.
|
|
45
27
|
*/
|
|
46
|
-
function applyAllPatches() {
|
|
47
|
-
|
|
48
|
-
|
|
28
|
+
export function applyAllPatches() {
|
|
29
|
+
applyRepositoryPatches();
|
|
30
|
+
applyEntityManagerPatches();
|
|
49
31
|
}
|
|
50
32
|
/**
|
|
51
33
|
* Test-only — drop the managed-DataSources WeakSet so cached
|
|
@@ -69,7 +51,7 @@ function applyAllPatches() {
|
|
|
69
51
|
*
|
|
70
52
|
* @internal
|
|
71
53
|
*/
|
|
72
|
-
function resetPatchingForTesting() {
|
|
73
|
-
|
|
54
|
+
export function resetPatchingForTesting() {
|
|
55
|
+
resetManagedRegistry();
|
|
74
56
|
}
|
|
75
57
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/patching/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/patching/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC9F,OAAO,EACL,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,SAAS,EACT,aAAa,EACb,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe;IAC7B,sBAAsB,EAAE,CAAC;IACzB,yBAAyB,EAAE,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,uBAAuB;IACrC,oBAAoB,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */
|
|
3
2
|
// The patching machinery stamps and reads hidden symbol-keyed
|
|
4
3
|
// properties on TypeORM internals (`DataSource`, `EntityManager`,
|
|
@@ -6,14 +5,8 @@
|
|
|
6
5
|
// types by design, so unsafe-access lint rules fire on every
|
|
7
6
|
// access. File-level disable keeps the patch code readable; the
|
|
8
7
|
// runtime contract is documented in JSDoc above each patch.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
exports.isManaged = isManaged;
|
|
12
|
-
exports.getManagedDataSourceName = getManagedDataSourceName;
|
|
13
|
-
exports.getActiveEntityManager = getActiveEntityManager;
|
|
14
|
-
exports.resetManagedRegistry = resetManagedRegistry;
|
|
15
|
-
const core_1 = require("@nestjs-transactional/core");
|
|
16
|
-
const symbols_1 = require("./symbols");
|
|
8
|
+
import { TransactionContext } from '@nestjs-transactional/core';
|
|
9
|
+
import { TYPEORM_DATA_SOURCE_NAME } from './symbols.js';
|
|
17
10
|
/**
|
|
18
11
|
* Process-wide set of `DataSource` instances we have registered as
|
|
19
12
|
* "managed" via {@link markAsManaged}. The patched
|
|
@@ -51,16 +44,16 @@ let managedDataSources = new WeakSet();
|
|
|
51
44
|
* own static-Map mechanism, so this collision should never occur in
|
|
52
45
|
* production.
|
|
53
46
|
*/
|
|
54
|
-
function markAsManaged(dataSource, name) {
|
|
47
|
+
export function markAsManaged(dataSource, name) {
|
|
55
48
|
managedDataSources.add(dataSource);
|
|
56
49
|
// Stamp the name as a hidden property. Cast to any to avoid a
|
|
57
50
|
// TypeORM type-shape change: we intentionally augment the runtime
|
|
58
51
|
// object without touching its public surface.
|
|
59
52
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
dataSource[
|
|
53
|
+
dataSource[TYPEORM_DATA_SOURCE_NAME] = name;
|
|
61
54
|
}
|
|
62
55
|
/** Predicate: is `dataSource` registered as managed? */
|
|
63
|
-
function isManaged(dataSource) {
|
|
56
|
+
export function isManaged(dataSource) {
|
|
64
57
|
return managedDataSources.has(dataSource);
|
|
65
58
|
}
|
|
66
59
|
/**
|
|
@@ -68,9 +61,9 @@ function isManaged(dataSource) {
|
|
|
68
61
|
* {@link markAsManaged}. Returns `undefined` if the DataSource has
|
|
69
62
|
* not been registered as managed.
|
|
70
63
|
*/
|
|
71
|
-
function getManagedDataSourceName(dataSource) {
|
|
64
|
+
export function getManagedDataSourceName(dataSource) {
|
|
72
65
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
return dataSource[
|
|
66
|
+
return dataSource[TYPEORM_DATA_SOURCE_NAME];
|
|
74
67
|
}
|
|
75
68
|
/**
|
|
76
69
|
* Resolve the active transactional `EntityManager` for the given
|
|
@@ -83,8 +76,8 @@ function getManagedDataSourceName(dataSource) {
|
|
|
83
76
|
* resolution rule — one place to evolve when the underlying lookup
|
|
84
77
|
* changes.
|
|
85
78
|
*/
|
|
86
|
-
function getActiveEntityManager(dataSourceName) {
|
|
87
|
-
const activeTx =
|
|
79
|
+
export function getActiveEntityManager(dataSourceName) {
|
|
80
|
+
const activeTx = TransactionContext.getActiveTransactionByDataSource(dataSourceName);
|
|
88
81
|
if (activeTx === undefined) {
|
|
89
82
|
return undefined;
|
|
90
83
|
}
|
|
@@ -106,7 +99,7 @@ function getActiveEntityManager(dataSourceName) {
|
|
|
106
99
|
*
|
|
107
100
|
* @internal
|
|
108
101
|
*/
|
|
109
|
-
function resetManagedRegistry() {
|
|
102
|
+
export function resetManagedRegistry() {
|
|
110
103
|
managedDataSources = new WeakSet();
|
|
111
104
|
}
|
|
112
105
|
//# sourceMappingURL=managed-registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"managed-registry.js","sourceRoot":"","sources":["../../src/patching/managed-registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"managed-registry.js","sourceRoot":"","sources":["../../src/patching/managed-registry.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,8DAA8D;AAC9D,kEAAkE;AAClE,gEAAgE;AAChE,6DAA6D;AAC7D,gEAAgE;AAChE,4DAA4D;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAKhE,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAExD;;;;;;;;;;;;;;;;GAgBG;AACH,IAAI,kBAAkB,GAAG,IAAI,OAAO,EAAc,CAAC;AAEnD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,aAAa,CAAC,UAAsB,EAAE,IAAY;IAChE,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACnC,8DAA8D;IAC9D,kEAAkE;IAClE,8CAA8C;IAC9C,8DAA8D;IAC7D,UAAkB,CAAC,wBAAwB,CAAC,GAAG,IAAI,CAAC;AACvD,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,SAAS,CAAC,UAAsB;IAC9C,OAAO,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AAC5C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,UAAsB;IAC7D,8DAA8D;IAC9D,OAAQ,UAAkB,CAAC,wBAAwB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CAAC,cAAsB;IAC3D,MAAM,QAAQ,GAAG,kBAAkB,CAAC,gCAAgC,CAAC,cAAc,CAAC,CAAC;IACrF,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAQ,QAAQ,CAAC,MAAmC,CAAC,aAAa,CAAC;AACrE,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,oBAAoB;IAClC,kBAAkB,GAAG,IAAI,OAAO,EAAc,CAAC;AACjD,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/unbound-method */
|
|
3
2
|
// The patching machinery stamps and reads hidden symbol-keyed
|
|
4
3
|
// properties on TypeORM `Repository` instances. These properties
|
|
@@ -6,13 +5,10 @@
|
|
|
6
5
|
// and unbound-method lint rules fire on every access. File-level
|
|
7
6
|
// disable keeps the patch code readable; the runtime contract is
|
|
8
7
|
// documented in the JSDoc above each patch.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const get_em_data_source_1 = require("./get-em-data-source");
|
|
14
|
-
const managed_registry_1 = require("./managed-registry");
|
|
15
|
-
const symbols_1 = require("./symbols");
|
|
8
|
+
import { Repository } from 'typeorm';
|
|
9
|
+
import { getEmDataSource } from './get-em-data-source.js';
|
|
10
|
+
import { getActiveEntityManager, getManagedDataSourceName, isManaged } from './managed-registry.js';
|
|
11
|
+
import { TYPEORM_ENTITY_MANAGER_NAME } from './symbols.js';
|
|
16
12
|
/**
|
|
17
13
|
* Tracks whether the prototype patch has been installed on
|
|
18
14
|
* `Repository.prototype`. Once installed, the patch lives for the
|
|
@@ -76,12 +72,12 @@ let originalExtend;
|
|
|
76
72
|
* patched getter to their captured original manager (autocommit) —
|
|
77
73
|
* never a broken `undefined`.
|
|
78
74
|
*/
|
|
79
|
-
function applyRepositoryPatches() {
|
|
75
|
+
export function applyRepositoryPatches() {
|
|
80
76
|
if (installed) {
|
|
81
77
|
return;
|
|
82
78
|
}
|
|
83
79
|
// (1) Repository.prototype.manager — getter/setter pair.
|
|
84
|
-
Object.defineProperty(
|
|
80
|
+
Object.defineProperty(Repository.prototype, 'manager', {
|
|
85
81
|
configurable: true,
|
|
86
82
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
83
|
get() {
|
|
@@ -91,7 +87,7 @@ function applyRepositoryPatches() {
|
|
|
91
87
|
// or (b) the `EntityManager.prototype.getRepository` wrapper
|
|
92
88
|
// when it stamps newly-resolved repositories.
|
|
93
89
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
-
const original = this[
|
|
90
|
+
const original = this[TYPEORM_ENTITY_MANAGER_NAME];
|
|
95
91
|
// Defensive: a Repository ending up here without ever having
|
|
96
92
|
// had its setter called (shouldn't happen in practice) yields
|
|
97
93
|
// `undefined`, mirroring the pre-patch behaviour for an
|
|
@@ -99,15 +95,15 @@ function applyRepositoryPatches() {
|
|
|
99
95
|
if (original === undefined) {
|
|
100
96
|
return undefined;
|
|
101
97
|
}
|
|
102
|
-
const ds =
|
|
103
|
-
if (!
|
|
98
|
+
const ds = getEmDataSource(original);
|
|
99
|
+
if (!isManaged(ds)) {
|
|
104
100
|
return original;
|
|
105
101
|
}
|
|
106
|
-
const dsName =
|
|
102
|
+
const dsName = getManagedDataSourceName(ds);
|
|
107
103
|
if (dsName === undefined) {
|
|
108
104
|
return original;
|
|
109
105
|
}
|
|
110
|
-
const active =
|
|
106
|
+
const active = getActiveEntityManager(dsName);
|
|
111
107
|
return active ?? original;
|
|
112
108
|
},
|
|
113
109
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -115,7 +111,7 @@ function applyRepositoryPatches() {
|
|
|
115
111
|
// Constructor's `this.manager = manager` reaches us here.
|
|
116
112
|
// Stash under the hidden symbol so the getter has a fallback.
|
|
117
113
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
-
this[
|
|
114
|
+
this[TYPEORM_ENTITY_MANAGER_NAME] = manager;
|
|
119
115
|
},
|
|
120
116
|
});
|
|
121
117
|
// (2) Repository.prototype.extend — wrap to preserve the stash on
|
|
@@ -123,9 +119,9 @@ function applyRepositoryPatches() {
|
|
|
123
119
|
// `extend` resists clean typing on the wrapper; cast through
|
|
124
120
|
// `any` to keep the wrap a single statement (the runtime
|
|
125
121
|
// contract is unchanged).
|
|
126
|
-
originalExtend =
|
|
122
|
+
originalExtend = Repository.prototype.extend;
|
|
127
123
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
-
|
|
124
|
+
Repository.prototype.extend = function patchedExtend(
|
|
129
125
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
126
|
customs) {
|
|
131
127
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -134,9 +130,9 @@ function applyRepositoryPatches() {
|
|
|
134
130
|
// patched setter, so the stash is already in place. Defensive
|
|
135
131
|
// copy in case TypeORM's internal extension shape changes.
|
|
136
132
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
-
if (result[
|
|
133
|
+
if (result[TYPEORM_ENTITY_MANAGER_NAME] === undefined) {
|
|
138
134
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
-
result[
|
|
135
|
+
result[TYPEORM_ENTITY_MANAGER_NAME] = this[TYPEORM_ENTITY_MANAGER_NAME];
|
|
140
136
|
}
|
|
141
137
|
return result;
|
|
142
138
|
};
|
|
@@ -145,7 +141,7 @@ function applyRepositoryPatches() {
|
|
|
145
141
|
/**
|
|
146
142
|
* Predicate exported for unit tests. @internal
|
|
147
143
|
*/
|
|
148
|
-
function areRepositoryPatchesApplied() {
|
|
144
|
+
export function areRepositoryPatchesApplied() {
|
|
149
145
|
return installed;
|
|
150
146
|
}
|
|
151
147
|
//# sourceMappingURL=repository-patches.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-patches.js","sourceRoot":"","sources":["../../src/patching/repository-patches.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"repository-patches.js","sourceRoot":"","sources":["../../src/patching/repository-patches.ts"],"names":[],"mappings":"AAAA,2IAA2I;AAC3I,8DAA8D;AAC9D,iEAAiE;AACjE,kEAAkE;AAClE,iEAAiE;AACjE,iEAAiE;AACjE,4CAA4C;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAE3D;;;;;;GAMG;AACH,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB;;;GAGG;AACH,IAAI,cAA8D,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,UAAU,sBAAsB;IACpC,IAAI,SAAS,EAAE,CAAC;QACd,OAAO;IACT,CAAC;IAED,yDAAyD;IACzD,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS,EAAE;QACrD,YAAY,EAAE,IAAI;QAClB,8DAA8D;QAC9D,GAAG;YACD,yDAAyD;YACzD,sDAAsD;YACtD,kEAAkE;YAClE,6DAA6D;YAC7D,8CAA8C;YAC9C,8DAA8D;YAC9D,MAAM,QAAQ,GAA+B,IAAY,CAAC,2BAA2B,CAAC,CAAC;YAEvF,6DAA6D;YAC7D,8DAA8D;YAC9D,wDAAwD;YACxD,iCAAiC;YACjC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC3B,OAAO,SAAqC,CAAC;YAC/C,CAAC;YAED,MAAM,EAAE,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;YACrC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;gBACnB,OAAO,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|
|
3
2
|
* Hidden property keys used by the transparent transactional patching
|
|
4
3
|
* machinery.
|
|
@@ -14,8 +13,6 @@
|
|
|
14
13
|
* Namespaced strings prevent collision with arbitrary user code that
|
|
15
14
|
* might assign symbols on TypeORM internals.
|
|
16
15
|
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.TYPEORM_DATA_SOURCE_PATCHED = exports.TYPEORM_ENTITY_MANAGER_NAME = exports.TYPEORM_DATA_SOURCE_NAME = void 0;
|
|
19
16
|
/**
|
|
20
17
|
* Hidden property on each managed `DataSource` instance carrying the
|
|
21
18
|
* dataSource name under which it was registered (`'default'`,
|
|
@@ -29,7 +26,7 @@ exports.TYPEORM_DATA_SOURCE_PATCHED = exports.TYPEORM_ENTITY_MANAGER_NAME = expo
|
|
|
29
26
|
* string key, but kept as a `Symbol.for(...)` to avoid colliding with
|
|
30
27
|
* arbitrary properties user code might set on a `DataSource`.
|
|
31
28
|
*/
|
|
32
|
-
|
|
29
|
+
export const TYPEORM_DATA_SOURCE_NAME = Symbol.for('@nestjs-transactional/typeorm/data-source-name');
|
|
33
30
|
/**
|
|
34
31
|
* Hidden property on each `Repository` instance carrying the original
|
|
35
32
|
* (non-active) `EntityManager` reference. Populated when a repository
|
|
@@ -44,7 +41,7 @@ exports.TYPEORM_DATA_SOURCE_NAME = Symbol.for('@nestjs-transactional/typeorm/dat
|
|
|
44
41
|
* the original manager carries `connection`, which carries the
|
|
45
42
|
* stamped {@link TYPEORM_DATA_SOURCE_NAME}.
|
|
46
43
|
*/
|
|
47
|
-
|
|
44
|
+
export const TYPEORM_ENTITY_MANAGER_NAME = Symbol.for('@nestjs-transactional/typeorm/entity-manager');
|
|
48
45
|
/**
|
|
49
46
|
* Hidden marker on each `DataSource` instance whose per-instance
|
|
50
47
|
* patches ({@link patchDataSourceInstance} in `data-source-patches.ts`)
|
|
@@ -52,5 +49,5 @@ exports.TYPEORM_ENTITY_MANAGER_NAME = Symbol.for('@nestjs-transactional/typeorm/
|
|
|
52
49
|
* a DataSource registered through `forRoot` more than once (e.g. on
|
|
53
50
|
* test resets) does not accumulate getter/setter pairs.
|
|
54
51
|
*/
|
|
55
|
-
|
|
52
|
+
export const TYPEORM_DATA_SOURCE_PATCHED = Symbol.for('@nestjs-transactional/typeorm/data-source-patched');
|
|
56
53
|
//# sourceMappingURL=symbols.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/patching/symbols.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../src/patching/symbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,GAAG,CAChD,gDAAgD,CACjD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,GAAG,CACnD,8CAA8C,CAC/C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAC,GAAG,CACnD,mDAAmD,CACpD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs-transactional/typeorm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "TypeORM adapter for @nestjs-transactional/core — EntityManager propagation, savepoints, multi-datasource",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"type": "
|
|
6
|
+
"type": "module",
|
|
7
7
|
"sideEffects": [
|
|
8
8
|
"./dist/module/typeorm-transactional.module.js"
|
|
9
9
|
],
|
|
@@ -48,39 +48,42 @@
|
|
|
48
48
|
"provenance": true
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
52
|
-
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
53
|
-
"@nestjs/typeorm": "^10.0.0 || ^11.0.0",
|
|
51
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
52
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
53
|
+
"@nestjs/typeorm": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
54
54
|
"reflect-metadata": "^0.1.13 || ^0.2.0",
|
|
55
55
|
"rxjs": "^7.0.0",
|
|
56
56
|
"typeorm": "^0.3.0 || ^1.0.0",
|
|
57
|
-
"@nestjs-transactional/core": "^
|
|
57
|
+
"@nestjs-transactional/core": "^2.0.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@
|
|
61
|
-
"@nestjs/
|
|
62
|
-
"@nestjs/
|
|
63
|
-
"@nestjs/
|
|
64
|
-
"@
|
|
60
|
+
"@jest/globals": "^30.4.2",
|
|
61
|
+
"@nestjs/common": "^11.2.3",
|
|
62
|
+
"@nestjs/core": "^11.2.3",
|
|
63
|
+
"@nestjs/testing": "^11.2.3",
|
|
64
|
+
"@nestjs/typeorm": "^11.0.3",
|
|
65
|
+
"@testcontainers/postgresql": "^12.1.0",
|
|
66
|
+
"@types/jest": "^30.0.0",
|
|
67
|
+
"@types/node": "^22.20.1",
|
|
65
68
|
"@types/sql.js": "^1.4.9",
|
|
66
69
|
"reflect-metadata": "^0.2.2",
|
|
67
70
|
"rxjs": "^7.8.1",
|
|
68
|
-
"sql.js": "^1.
|
|
69
|
-
"testcontainers": "^
|
|
71
|
+
"sql.js": "^1.14.2",
|
|
72
|
+
"testcontainers": "^12.1.0",
|
|
70
73
|
"typeorm": "^1.1.0",
|
|
71
|
-
"@nestjs-transactional/core": "
|
|
74
|
+
"@nestjs-transactional/core": "2.0.0"
|
|
72
75
|
},
|
|
73
76
|
"scripts": {
|
|
74
77
|
"build": "tsc -p tsconfig.build.json",
|
|
75
78
|
"clean": "rimraf dist *.tsbuildinfo coverage",
|
|
76
|
-
"test": "jest",
|
|
77
|
-
"test:watch": "jest --watch",
|
|
78
|
-
"test:cov": "jest --coverage",
|
|
79
|
-
"test:integration": "jest --config jest.integration.config.
|
|
79
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
80
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
|
81
|
+
"test:cov": "NODE_OPTIONS=--experimental-vm-modules jest --config jest.coverage.config.cjs --coverage",
|
|
82
|
+
"test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --config jest.integration.config.cjs",
|
|
80
83
|
"type-check": "tsc --noEmit",
|
|
81
|
-
"lint": "eslint
|
|
84
|
+
"lint": "eslint .",
|
|
82
85
|
"api:check": "api-extractor run",
|
|
83
86
|
"api:update": "api-extractor run --local",
|
|
84
|
-
"publish:check": "publint && attw --pack ."
|
|
87
|
+
"publish:check": "publint && attw --pack . --profile esm-only"
|
|
85
88
|
}
|
|
86
89
|
}
|