@nathapp/nestjs-typeorm 4.3.1 → 4.3.2
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
CHANGED
|
@@ -24,6 +24,37 @@ repositories, `BaseSpRepository.callQuery`, `@Transactional`, and
|
|
|
24
24
|
DataSource. Each connection has an independent context, including during nested
|
|
25
25
|
and concurrent work.
|
|
26
26
|
|
|
27
|
+
### Independent transactions (`requiresNew`)
|
|
28
|
+
|
|
29
|
+
By default `run` joins an active transaction. `await tx.run(fn, { propagation: 'requiresNew' })`
|
|
30
|
+
instead always starts a new transaction on its own QueryRunner. That runner is the
|
|
31
|
+
active one only inside `fn`; the outer transaction resumes afterwards, and a plain
|
|
32
|
+
`run` nested in `fn` joins the new one. Use it for writes that must persist even if
|
|
33
|
+
the caller later rolls back (security revocations, audit records, lockout counters):
|
|
34
|
+
|
|
35
|
+
- The inner commit survives an outer rollback.
|
|
36
|
+
- An error thrown inside it rolls back only the inner transaction; the outer
|
|
37
|
+
transaction can still commit, and the error still reaches the caller of `run`.
|
|
38
|
+
- `isolationLevel` applies to the new transaction. `getClient()` and
|
|
39
|
+
`isInTransaction()` report the inner runner inside `fn` and the outer one after.
|
|
40
|
+
|
|
41
|
+
Caveats:
|
|
42
|
+
|
|
43
|
+
- It needs a second pooled connection while the outer transaction still holds one.
|
|
44
|
+
On single-connection setups (a pool of size one, SQLite drivers that serialize
|
|
45
|
+
transactions) it deadlocks and is unsupported. The TypeORM manager does not try to
|
|
46
|
+
detect this, so size the pool for at least two connections.
|
|
47
|
+
- Each concurrent outer transaction using `requiresNew` holds two connections. Size
|
|
48
|
+
the pool for at least 2x the peak number of concurrent outer transactions.
|
|
49
|
+
TypeORM's default pools can wait forever, so set a pool acquire timeout in the
|
|
50
|
+
driver options (for example `connectionTimeoutMillis` in `extra` for Postgres)
|
|
51
|
+
so starvation fails instead of hanging.
|
|
52
|
+
- An unknown `propagation` value (for example `'requires_new'`) throws instead of
|
|
53
|
+
silently joining.
|
|
54
|
+
- If the outer transaction holds row locks on rows the inner one writes, the inner
|
|
55
|
+
transaction waits on its own caller until the lock timeout. Use it only for rows
|
|
56
|
+
the outer transaction has not locked.
|
|
57
|
+
|
|
27
58
|
## Stored procedure results
|
|
28
59
|
|
|
29
60
|
`BaseSpRepository.callQuery` preserves the driver result shape: PostgreSQL's
|
|
@@ -26,7 +26,11 @@ let TypeOrmTransactionManager = class TypeOrmTransactionManager {
|
|
|
26
26
|
this.als = (0, typeorm_transaction_context_1.registerTypeOrmTransactionContext)(dataSource, als !== null && als !== void 0 ? als : new async_hooks_1.AsyncLocalStorage());
|
|
27
27
|
}
|
|
28
28
|
async run(fn, options) {
|
|
29
|
-
|
|
29
|
+
const propagation = options === null || options === void 0 ? void 0 : options.propagation;
|
|
30
|
+
if (propagation !== undefined && propagation !== 'required' && propagation !== 'requiresNew') {
|
|
31
|
+
throw new Error(`Unknown transaction propagation ${JSON.stringify(propagation)}: expected 'required' or 'requiresNew'`);
|
|
32
|
+
}
|
|
33
|
+
if (this.als.getStore() && (options === null || options === void 0 ? void 0 : options.propagation) !== 'requiresNew') {
|
|
30
34
|
return fn();
|
|
31
35
|
}
|
|
32
36
|
const isolationLevel = (options === null || options === void 0 ? void 0 : options.isolationLevel)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeorm-transaction-manager.js","sourceRoot":"","sources":["../../lib/transaction/typeorm-transaction-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAAkD;AAClD,6CAAgD;AAEhD,+EAGuC;AAiBvC,MAAM,wBAAwB,GAG1B;IACF,eAAe,EAAE,kBAAkB;IACnC,aAAa,EAAE,gBAAgB;IAC/B,cAAc,EAAE,iBAAiB;IACjC,YAAY,EAAE,cAAc;CAC7B,CAAC;AA+CK,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAGpC,YACmB,UAAsB,EACvC,GAAoC;QADnB,eAAU,GA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gB,GAAG,YAAY,CAAC;YAClC,CAAC;QACH,CAAC;QAED,IAAI,iBAAiB,EAAE,CAAC;YACtB,MAAM,gBAAgB,CAAC;QACzB,CAAC;QACD,OAAO,MAAO,CAAC;IACjB,CAAC;IAMD,SAAS;;QACP,OAAO,CAAC,MAAA,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,mCAAI,IAAI,CAAC,UAAU,CAAM,CAAC;IACvD,CAAC;IAKD,eAAe;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,SAAS,CAAC;IAC3C,CAAC;CACF,CAAA;AAvGY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;qCAKoB,oBAAU;QACjC,+BAAiB;GALd,yBAAyB,CAuGrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-typeorm",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.2",
|
|
4
4
|
"description": "@nathapp/nestjs-typeorm",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist/ .turbo/",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@nathapp/common": "^0.1.14",
|
|
29
|
-
"@nathapp/nestjs-common": "^4.3.
|
|
30
|
-
"@nathapp/nestjs-data": "^4.3.
|
|
29
|
+
"@nathapp/nestjs-common": "^4.3.2",
|
|
30
|
+
"@nathapp/nestjs-data": "^4.3.2",
|
|
31
31
|
"@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
|
|
32
32
|
"class-transformer": "*",
|
|
33
33
|
"dayjs": "^1.11.13"
|