@elsikora/nestjs-crud-automator 3.0.1 → 3.0.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 +3 -3
- package/dist/cjs/class/api/function/transaction/scope.class.d.ts +1 -1
- package/dist/cjs/class/api/function/transaction/scope.class.js +1 -1
- package/dist/cjs/class/api/function/transaction/scope.class.js.map +1 -1
- package/dist/esm/class/api/function/transaction/scope.class.d.ts +1 -1
- package/dist/esm/class/api/function/transaction/scope.class.js +1 -1
- package/dist/esm/class/api/function/transaction/scope.class.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -638,13 +638,13 @@ Use a named scope when application code, rather than a decorated function, must
|
|
|
638
638
|
```typescript
|
|
639
639
|
import { ApiFunctionTransactionScope } from "@elsikora/nestjs-crud-automator";
|
|
640
640
|
|
|
641
|
-
await ApiFunctionTransactionScope.runWithDataSource(dataSource, { name: "register-user" }, async () => {
|
|
641
|
+
await ApiFunctionTransactionScope.runWithDataSource(dataSource, { name: "register-user" }, async (entityManager) => {
|
|
642
642
|
await userService.create(body);
|
|
643
|
-
await
|
|
643
|
+
await entityManager.getRepository(AuditEntity).save(entry);
|
|
644
644
|
});
|
|
645
645
|
```
|
|
646
646
|
|
|
647
|
-
The scope name is trimmed and must be non-empty. `runWithEntityManager()` is join-only: it accepts only the manager already bound to an active Automator transaction and never opens a second transaction.
|
|
647
|
+
The callback receives the exact manager owned by the named scope. Decorated operations join it automatically; use the argument for transaction-bound raw repository or migration work. The scope name is trimmed and must be non-empty. `runWithEntityManager()` is join-only: it accepts only the manager already bound to an active Automator transaction and never opens a second transaction.
|
|
648
648
|
|
|
649
649
|
Function subscribers can react once after the outer commit or rollback. The observed service must use `@ApiServiceObservable()`, and the subscriber must be registered as a Nest provider:
|
|
650
650
|
|
|
@@ -2,7 +2,7 @@ import { DataSource, EntityManager } from 'typeorm';
|
|
|
2
2
|
export declare class ApiFunctionTransactionScope {
|
|
3
3
|
static runWithDataSource<R>(dataSource: DataSource, properties: {
|
|
4
4
|
name: string;
|
|
5
|
-
}, callback: () => Promise<R>): Promise<R>;
|
|
5
|
+
}, callback: (entityManager: EntityManager) => Promise<R>): Promise<R>;
|
|
6
6
|
static runWithEntityManager<R>(entityManager: EntityManager, callback: () => Promise<R>): Promise<R>;
|
|
7
7
|
private static createMissingServiceContextError;
|
|
8
8
|
}
|
|
@@ -38,7 +38,7 @@ class ApiFunctionTransactionScope {
|
|
|
38
38
|
throw exception_utility.ErrorException("ApiFunctionTransactionScope name must be a non-empty string");
|
|
39
39
|
}
|
|
40
40
|
return await runtime_class.ApiFunctionTransactionRuntime.execute({
|
|
41
|
-
callback: async (entityManager) => await ApiFunctionTransactionScope.runWithEntityManager(entityManager, callback),
|
|
41
|
+
callback: async (entityManager) => await ApiFunctionTransactionScope.runWithEntityManager(entityManager, async () => await callback(entityManager)),
|
|
42
42
|
dataSource,
|
|
43
43
|
owner: {
|
|
44
44
|
kind: ownerKind_enum.EApiFunctionTransactionOwnerKind.SCOPE,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.class.js","sources":["../../../../../../../src/class/api/function/transaction/scope.class.ts"],"sourcesContent":[null],"names":["ErrorException","ApiFunctionTransactionRuntime","EApiFunctionTransactionOwnerKind","ApiFunctionContextStorage"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAUa,2BAA2B,CAAA;IAChC,aAAa,iBAAiB,CAAI,UAAsB,EAAE,UAA4B,EAAE,
|
|
1
|
+
{"version":3,"file":"scope.class.js","sources":["../../../../../../../src/class/api/function/transaction/scope.class.ts"],"sourcesContent":[null],"names":["ErrorException","ApiFunctionTransactionRuntime","EApiFunctionTransactionOwnerKind","ApiFunctionContextStorage"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAUa,2BAA2B,CAAA;IAChC,aAAa,iBAAiB,CAAI,UAAsB,EAAE,UAA4B,EAAE,QAAsD,EAA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CAAC;AAC3G,gBAAA,GAAG,EAAE,MAA+B,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAAC,gCAAgC,EAAE,CAAC;AAClH,gBAAA,OAAO,EAAE,MAAsB,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAAC,gCAAgC,EAAE,CAAC;AAC7G,gBAAA,OAAO,EAAE,MAAsC,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAAC,gCAAgC,EAAE,CAAC;gBAC7H,aAAa,EAAE,CAA2B,gBAA6B,KAAoB,aAAa,CAAC,aAAa,CAAC,gBAAgB,CAAC;AACxI,gBAAA,MAAM,EAAE,MAA+B,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAAC,gCAAgC,EAAE,CAAC;AACrH,aAAA;AACD,YAAA,UAAU,EAAE,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC;SAC/C;QAED,OAAO,MAAMG,8CAAyB,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC9D;AAEQ,IAAA,OAAO,gCAAgC,GAAA;AAC9C,QAAA,OAAOH,gCAAc,CAAC,4EAA4E,CAAC;IACpG;AACA;;;;"}
|
|
@@ -2,7 +2,7 @@ import { DataSource, EntityManager } from 'typeorm';
|
|
|
2
2
|
export declare class ApiFunctionTransactionScope {
|
|
3
3
|
static runWithDataSource<R>(dataSource: DataSource, properties: {
|
|
4
4
|
name: string;
|
|
5
|
-
}, callback: () => Promise<R>): Promise<R>;
|
|
5
|
+
}, callback: (entityManager: EntityManager) => Promise<R>): Promise<R>;
|
|
6
6
|
static runWithEntityManager<R>(entityManager: EntityManager, callback: () => Promise<R>): Promise<R>;
|
|
7
7
|
private static createMissingServiceContextError;
|
|
8
8
|
}
|
|
@@ -36,7 +36,7 @@ class ApiFunctionTransactionScope {
|
|
|
36
36
|
throw ErrorException("ApiFunctionTransactionScope name must be a non-empty string");
|
|
37
37
|
}
|
|
38
38
|
return await ApiFunctionTransactionRuntime.execute({
|
|
39
|
-
callback: async (entityManager) => await ApiFunctionTransactionScope.runWithEntityManager(entityManager, callback),
|
|
39
|
+
callback: async (entityManager) => await ApiFunctionTransactionScope.runWithEntityManager(entityManager, async () => await callback(entityManager)),
|
|
40
40
|
dataSource,
|
|
41
41
|
owner: {
|
|
42
42
|
kind: EApiFunctionTransactionOwnerKind.SCOPE,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.class.js","sources":["../../../../../../../src/class/api/function/transaction/scope.class.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAUa,2BAA2B,CAAA;IAChC,aAAa,iBAAiB,CAAI,UAAsB,EAAE,UAA4B,EAAE,
|
|
1
|
+
{"version":3,"file":"scope.class.js","sources":["../../../../../../../src/class/api/function/transaction/scope.class.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAUa,2BAA2B,CAAA;IAChC,aAAa,iBAAiB,CAAI,UAAsB,EAAE,UAA4B,EAAE,QAAsD,EAAA;QACpJ,MAAM,IAAI,GAAW,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE;AAE3C,QAAA,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;AACtB,YAAA,MAAM,cAAc,CAAC,6DAA6D,CAAC;QACpF;AAEA,QAAA,OAAO,MAAM,6BAA6B,CAAC,OAAO,CAAC;YAClD,QAAQ,EAAE,OAAO,aAA4B,KAAiB,MAAM,2BAA2B,CAAC,oBAAoB,CAAC,aAAa,EAAE,YAAwB,MAAM,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC1L,UAAU;AACV,YAAA,KAAK,EAAE;gBACN,IAAI,EAAE,gCAAgC,CAAC,KAAK;gBAC5C,IAAI;AACJ,aAAA;AACD,SAAA,CAAC;IACH;AAEO,IAAA,aAAa,oBAAoB,CAAI,aAA4B,EAAE,QAA0B,EAAA;QACnG,MAAM,QAAQ,GAA+C,yBAAyB,CAAC,sCAAsC,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