@nestplatform/transactional 1.0.0 → 1.0.1
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/package.json +7 -5
- package/src/decorators/index.ts +0 -1
- package/src/decorators/transactional.decorator.ts +0 -54
- package/src/index.ts +0 -6
- package/src/interfaces/index.ts +0 -1
- package/src/interfaces/transaction-adapter.interface.ts +0 -41
- package/src/providers/index.ts +0 -2
- package/src/providers/transaction-adapter-async.provider.ts +0 -17
- package/src/providers/transaction-adapter.provider.ts +0 -16
- package/src/transaction-context.ts +0 -47
- package/src/transactional-feature.decoration.ts +0 -64
- package/src/transactional-metadata.accessor.ts +0 -30
- package/src/transactional-metadata.explorer.ts +0 -62
- package/src/transactional.constant.ts +0 -8
- package/src/transactional.module.ts +0 -35
- package/src/types/index.ts +0 -2
- package/src/types/transactional-module.type.ts +0 -10
- package/src/types/transactional.type.ts +0 -33
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestplatform/transactional",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -9,15 +9,17 @@
|
|
|
9
9
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@nestplatform/common": "^1.0.
|
|
12
|
+
"@nestplatform/common": "^1.0.1"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
16
16
|
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
17
17
|
"reflect-metadata": "^0.1.13 || ^0.2.0"
|
|
18
18
|
},
|
|
19
|
-
"keywords": [
|
|
20
|
-
|
|
19
|
+
"keywords": [
|
|
20
|
+
"transactional"
|
|
21
|
+
],
|
|
22
|
+
"author": "Đường Trung Nguyên",
|
|
21
23
|
"license": "ISC",
|
|
22
24
|
"type": "commonjs"
|
|
23
|
-
}
|
|
25
|
+
}
|
package/src/decorators/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./transactional.decorator";
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { applyDecorators, SetMetadata } from "@nestjs/common";
|
|
2
|
-
|
|
3
|
-
import { NO_TRANSACTIONAL_METADATA, TRANSACTIONAL_METADATA } from "../transactional.constant";
|
|
4
|
-
import { TransactionalOptions, TransactionPropagation } from "../types";
|
|
5
|
-
|
|
6
|
-
const TRANSACTIONAL_DEFAULTS: Required<Omit<TransactionalOptions, "adapter" | "isolation">> = {
|
|
7
|
-
propagation: TransactionPropagation.REQUIRED,
|
|
8
|
-
logging: false,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Marks a class or method as transactional.
|
|
13
|
-
*
|
|
14
|
-
* - **Method-level**: Wraps the decorated method in a database transaction.
|
|
15
|
-
* - **Class-level**: Wraps all methods of the class in transactions.
|
|
16
|
-
* Use `@NoTransactional()` on specific methods to opt-out.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* // Method-level
|
|
20
|
-
* @Transactional()
|
|
21
|
-
* async createOrder(dto: CreateOrderDto) { ... }
|
|
22
|
-
*
|
|
23
|
-
* // Method-level with options
|
|
24
|
-
* @Transactional({ propagation: TransactionPropagation.REQUIRES_NEW })
|
|
25
|
-
* async logAuditEvent(event: AuditEvent) { ... }
|
|
26
|
-
*
|
|
27
|
-
* // Class-level
|
|
28
|
-
* @Transactional()
|
|
29
|
-
* @Injectable()
|
|
30
|
-
* export class PaymentService { ... }
|
|
31
|
-
*/
|
|
32
|
-
export const Transactional = (options?: TransactionalOptions): ClassDecorator & MethodDecorator => {
|
|
33
|
-
const mergedOptions: TransactionalOptions = {
|
|
34
|
-
...TRANSACTIONAL_DEFAULTS,
|
|
35
|
-
...options,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return applyDecorators(SetMetadata(TRANSACTIONAL_METADATA, mergedOptions));
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Excludes a method from class-level `@Transactional()` wrapping.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* @Transactional()
|
|
46
|
-
* @Injectable()
|
|
47
|
-
* export class PaymentService {
|
|
48
|
-
* @NoTransactional()
|
|
49
|
-
* async getPaymentStatus(id: string) { ... } // Not wrapped in transaction
|
|
50
|
-
* }
|
|
51
|
-
*/
|
|
52
|
-
export const NoTransactional = (): MethodDecorator => {
|
|
53
|
-
return applyDecorators(SetMetadata(NO_TRANSACTIONAL_METADATA, true));
|
|
54
|
-
};
|
package/src/index.ts
DELETED
package/src/interfaces/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./transaction-adapter.interface";
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { TransactionExecuteOptions } from "../types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Plugin interface for ORM transaction adapters.
|
|
5
|
-
*
|
|
6
|
-
* Each adapter is responsible for managing the lifecycle of transactions
|
|
7
|
-
* for its specific ORM (TypeORM, Mongoose, MikroORM, etc.).
|
|
8
|
-
*
|
|
9
|
-
* The adapter handles:
|
|
10
|
-
* 1. Creating/reusing transactions based on propagation behavior
|
|
11
|
-
* 2. Committing on success, rolling back on error
|
|
12
|
-
* 3. Managing savepoints for NESTED propagation
|
|
13
|
-
* 4. Context propagation (storing/retrieving the active transaction)
|
|
14
|
-
*/
|
|
15
|
-
export interface ITransactionAdapter {
|
|
16
|
-
/**
|
|
17
|
-
* Proxy an instance to inject transaction management logic.
|
|
18
|
-
*
|
|
19
|
-
* @param instance - The instance to proxy
|
|
20
|
-
* @returns The proxied instance
|
|
21
|
-
*/
|
|
22
|
-
proxyInstance?<T extends object>(instance: T): T;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Execute callback within a transaction.
|
|
26
|
-
*
|
|
27
|
-
* @param callback - The function to execute within the transaction scope
|
|
28
|
-
* @param options - Transaction execution options (propagation, isolation)
|
|
29
|
-
* @returns The result of the callback
|
|
30
|
-
*/
|
|
31
|
-
execute<T>(callback: () => Promise<T>, options: TransactionExecuteOptions): Promise<T>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Get the active transaction handle from the current context.
|
|
35
|
-
* Returns `undefined` if no transaction is active.
|
|
36
|
-
*
|
|
37
|
-
* This is useful for repositories or services that need to access
|
|
38
|
-
* the current transaction directly (e.g., TypeORM QueryRunner, Mongoose Session).
|
|
39
|
-
*/
|
|
40
|
-
getActiveTransaction(): any | undefined;
|
|
41
|
-
}
|
package/src/providers/index.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { FactoryProvider } from "@nestjs/common";
|
|
2
|
-
|
|
3
|
-
import { DEFAULT_TRANSACTION_ADAPTER, TRANSACTION_ADAPTERS } from "../transactional.constant";
|
|
4
|
-
import { TransactionalModuleConfigAsync } from "../types";
|
|
5
|
-
|
|
6
|
-
export const TransactionAdapterAsyncProvider = (config: TransactionalModuleConfigAsync): FactoryProvider => {
|
|
7
|
-
return {
|
|
8
|
-
provide: TRANSACTION_ADAPTERS,
|
|
9
|
-
inject: config.inject,
|
|
10
|
-
useFactory: async (...args) => {
|
|
11
|
-
const { adapters } = await config.useFactory(...args);
|
|
12
|
-
|
|
13
|
-
// If single adapter (has `execute` method), wrap in default key
|
|
14
|
-
return !!adapters["execute"] ? { [DEFAULT_TRANSACTION_ADAPTER]: adapters } : adapters;
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FactoryProvider } from "@nestjs/common";
|
|
2
|
-
|
|
3
|
-
import { DEFAULT_TRANSACTION_ADAPTER, TRANSACTION_ADAPTERS } from "../transactional.constant";
|
|
4
|
-
import { TransactionalModuleConfigSync } from "../types";
|
|
5
|
-
|
|
6
|
-
export const TransactionAdapterProvider = (config: TransactionalModuleConfigSync): FactoryProvider => {
|
|
7
|
-
return {
|
|
8
|
-
provide: TRANSACTION_ADAPTERS,
|
|
9
|
-
useFactory: async () => {
|
|
10
|
-
const adapters = config.adapters;
|
|
11
|
-
|
|
12
|
-
// If single adapter (has `execute` method), wrap in default key
|
|
13
|
-
return !!adapters["execute"] ? { [DEFAULT_TRANSACTION_ADAPTER]: adapters } : adapters;
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Transaction store containing the active transaction handle and its adapter.
|
|
5
|
-
* Propagated through the async call stack via AsyncLocalStorage (Node.js CLS).
|
|
6
|
-
*/
|
|
7
|
-
export type TransactionStore = {
|
|
8
|
-
/** The active transaction handle (e.g., TypeORM QueryRunner, Mongoose Session, MikroORM EntityManager) */
|
|
9
|
-
transaction: any;
|
|
10
|
-
|
|
11
|
-
/** The adapter key that owns this transaction */
|
|
12
|
-
adapterKey: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* AsyncLocalStorage-based transaction context propagation.
|
|
17
|
-
*
|
|
18
|
-
* Mirrors how Spring uses ThreadLocal to propagate transaction context.
|
|
19
|
-
* In Node.js, AsyncLocalStorage achieves the same effect across the async call stack.
|
|
20
|
-
*/
|
|
21
|
-
export class TransactionContext {
|
|
22
|
-
private static readonly storage = new AsyncLocalStorage<TransactionStore>();
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Run a callback within a transaction context.
|
|
26
|
-
* The store will be available to all async operations within the callback scope.
|
|
27
|
-
*/
|
|
28
|
-
static run<T>(store: TransactionStore, fn: () => Promise<T>): Promise<T> {
|
|
29
|
-
return this.storage.run(store, fn);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Get the current transaction store from the async context.
|
|
34
|
-
* Returns `undefined` if no transaction is active in the current scope.
|
|
35
|
-
*/
|
|
36
|
-
static getStore(): TransactionStore | undefined {
|
|
37
|
-
return this.storage.getStore();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Get the current transaction from the async context.
|
|
42
|
-
* Returns `undefined` if no transaction is active in the current scope.
|
|
43
|
-
*/
|
|
44
|
-
static getTransaction<T = any>(): T | undefined {
|
|
45
|
-
return this.storage.getStore()?.transaction;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Inject, Injectable, Logger } from "@nestjs/common";
|
|
2
|
-
|
|
3
|
-
import { FeatureDecoration, stringifyMethod } from "@nestplatform/common";
|
|
4
|
-
|
|
5
|
-
import { DEFAULT_TRANSACTION_ADAPTER, TRANSACTION_ADAPTERS } from "./transactional.constant";
|
|
6
|
-
import { ITransactionAdapter } from "./interfaces";
|
|
7
|
-
import { TransactionalOptions, TransactionAdapters, TransactionPropagation } from "./types";
|
|
8
|
-
|
|
9
|
-
const LOGGING_CONTEXT = "TransactionalModule";
|
|
10
|
-
|
|
11
|
-
@Injectable()
|
|
12
|
-
export class TransactionalFeatureDecoration extends FeatureDecoration {
|
|
13
|
-
constructor(@Inject(TRANSACTION_ADAPTERS) private readonly adapters: TransactionAdapters) {
|
|
14
|
-
super();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Wrap a method with transaction management logic.
|
|
19
|
-
* Resolves the correct adapter and delegates execution.
|
|
20
|
-
*/
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22
|
-
public wrapMethodWithTransaction(instance: any, methodName: string, originalMethod: Function, options: TransactionalOptions): void {
|
|
23
|
-
const adapterKey: string = options.adapter || DEFAULT_TRANSACTION_ADAPTER;
|
|
24
|
-
const fallbackAdapter: ITransactionAdapter | undefined = Object.values(this.adapters)[0];
|
|
25
|
-
|
|
26
|
-
const adapter: ITransactionAdapter | undefined = this.adapters[adapterKey] || fallbackAdapter;
|
|
27
|
-
|
|
28
|
-
if (!adapter) {
|
|
29
|
-
if (options.logging) {
|
|
30
|
-
Logger.warn(`Transaction adapter "${adapterKey}" not found. Skip wrapping for method ${methodName}.`, LOGGING_CONTEXT);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
instance[methodName] = async (...args: any[]): Promise<any> => {
|
|
37
|
-
const methodString: string = stringifyMethod(methodName, ...args);
|
|
38
|
-
|
|
39
|
-
if (options.logging) {
|
|
40
|
-
Logger.log(`Starting transaction for \`${methodString}\` [${options.propagation || TransactionPropagation.REQUIRED}]`, LOGGING_CONTEXT);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const proxiedInstance = adapter.proxyInstance?.(instance);
|
|
45
|
-
const result = await adapter.execute(() => originalMethod.apply(proxiedInstance || instance, args), {
|
|
46
|
-
propagation: options.propagation || TransactionPropagation.REQUIRED,
|
|
47
|
-
isolation: options.isolation,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
if (options.logging) {
|
|
51
|
-
Logger.log(`Transaction committed for \`${methodString}\``, LOGGING_CONTEXT);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return result;
|
|
55
|
-
} catch (error) {
|
|
56
|
-
if (options.logging) {
|
|
57
|
-
Logger.error(`Transaction rolled back for \`${methodString}\`: ${error}`, LOGGING_CONTEXT);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Injectable } from "@nestjs/common";
|
|
2
|
-
import { Reflector } from "@nestjs/core";
|
|
3
|
-
|
|
4
|
-
import { MetadataAccessor } from "@nestplatform/common";
|
|
5
|
-
|
|
6
|
-
import { NO_TRANSACTIONAL_METADATA, TRANSACTIONAL_METADATA } from "./transactional.constant";
|
|
7
|
-
import { TransactionalOptions } from "./types";
|
|
8
|
-
|
|
9
|
-
@Injectable()
|
|
10
|
-
export class TransactionalMetadataAccessor extends MetadataAccessor {
|
|
11
|
-
constructor(protected readonly reflector: Reflector) {
|
|
12
|
-
super();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get @Transactional() metadata from a class or method.
|
|
17
|
-
*/
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
19
|
-
public getTransactionalMetadata(target: Function): TransactionalOptions | undefined {
|
|
20
|
-
return this.getMetadata<TransactionalOptions>(TRANSACTIONAL_METADATA, target);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get @NoTransactional() metadata from a method.
|
|
25
|
-
*/
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
27
|
-
public getNoTransactionalMetadata(target: Function): boolean | undefined {
|
|
28
|
-
return this.getMetadata<boolean>(NO_TRANSACTIONAL_METADATA, target);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Injectable } from "@nestjs/common";
|
|
2
|
-
|
|
3
|
-
import { IFeatureExplorer, FeatureExplorer, MethodContext, ProviderContext } from "@nestplatform/common";
|
|
4
|
-
|
|
5
|
-
import { TransactionalFeatureDecoration } from "./transactional-feature.decoration";
|
|
6
|
-
import { TransactionalMetadataAccessor } from "./transactional-metadata.accessor";
|
|
7
|
-
import { TransactionalOptions } from "./types";
|
|
8
|
-
|
|
9
|
-
@Injectable()
|
|
10
|
-
@FeatureExplorer()
|
|
11
|
-
export class TransactionalMetadataExplorer implements IFeatureExplorer {
|
|
12
|
-
/**
|
|
13
|
-
* Stores class-level @Transactional() options, keyed by class constructor.
|
|
14
|
-
* Used to apply class-level defaults to all methods of the class.
|
|
15
|
-
*/
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
17
|
-
private readonly classLevelOptions = new Map<Function, TransactionalOptions>();
|
|
18
|
-
|
|
19
|
-
constructor(
|
|
20
|
-
private readonly metadataAccessor: TransactionalMetadataAccessor,
|
|
21
|
-
private readonly featureDecoration: TransactionalFeatureDecoration,
|
|
22
|
-
) {}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Scan each provider for class-level @Transactional() metadata.
|
|
26
|
-
*/
|
|
27
|
-
onProvider(ctx: ProviderContext): void {
|
|
28
|
-
const { metatype } = ctx;
|
|
29
|
-
|
|
30
|
-
const classOptions: TransactionalOptions | undefined = this.metadataAccessor.getTransactionalMetadata(metatype);
|
|
31
|
-
|
|
32
|
-
if (classOptions) {
|
|
33
|
-
this.classLevelOptions.set(metatype, classOptions);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Scan each method for @Transactional()/@NoTransactional() metadata.
|
|
39
|
-
* Class-level options serve as defaults; method-level options override them.
|
|
40
|
-
*/
|
|
41
|
-
onMethod(ctx: MethodContext): void {
|
|
42
|
-
const { instance, methodName, methodRef, metatype } = ctx;
|
|
43
|
-
|
|
44
|
-
// Check if method is explicitly excluded
|
|
45
|
-
const isExcluded: boolean | undefined = this.metadataAccessor.getNoTransactionalMetadata(methodRef);
|
|
46
|
-
|
|
47
|
-
if (isExcluded) return;
|
|
48
|
-
|
|
49
|
-
// Method-level options take highest priority
|
|
50
|
-
const methodOptions: TransactionalOptions | undefined = this.metadataAccessor.getTransactionalMetadata(methodRef);
|
|
51
|
-
|
|
52
|
-
// Class-level options as fallback
|
|
53
|
-
const classOptions: TransactionalOptions | undefined = this.classLevelOptions.get(metatype);
|
|
54
|
-
|
|
55
|
-
// Merge: method-level overrides class-level
|
|
56
|
-
const resolvedOptions: TransactionalOptions | undefined = methodOptions ? { ...classOptions, ...methodOptions } : classOptions;
|
|
57
|
-
|
|
58
|
-
if (!resolvedOptions) return;
|
|
59
|
-
|
|
60
|
-
this.featureDecoration.wrapMethodWithTransaction(instance, methodName, methodRef, resolvedOptions);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const TRANSACTIONAL_METADATA = Symbol.for("metadata:transactional");
|
|
2
|
-
export const NO_TRANSACTIONAL_METADATA = Symbol.for("metadata:no_transactional");
|
|
3
|
-
|
|
4
|
-
export const TRANSACTION_ADAPTERS = Symbol.for("token:TRANSACTION_ADAPTERS");
|
|
5
|
-
|
|
6
|
-
/* constants */
|
|
7
|
-
|
|
8
|
-
export const DEFAULT_TRANSACTION_ADAPTER = "default";
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { DynamicModule, Module } from "@nestjs/common";
|
|
2
|
-
|
|
3
|
-
import { FeatureExplorerModule, ConfigurableModule } from "@nestplatform/common";
|
|
4
|
-
|
|
5
|
-
import { TransactionAdapterAsyncProvider, TransactionAdapterProvider } from "./providers";
|
|
6
|
-
import { TransactionalModuleConfigAsync, TransactionalModuleConfigSync } from "./types";
|
|
7
|
-
import { TransactionalMetadataExplorer } from "./transactional-metadata.explorer";
|
|
8
|
-
import { TransactionalFeatureDecoration } from "./transactional-feature.decoration";
|
|
9
|
-
import { TransactionalMetadataAccessor } from "./transactional-metadata.accessor";
|
|
10
|
-
|
|
11
|
-
@Module({})
|
|
12
|
-
export class TransactionalModule extends ConfigurableModule {
|
|
13
|
-
static register(config: TransactionalModuleConfigSync): DynamicModule {
|
|
14
|
-
return super.config(config, {
|
|
15
|
-
global: true,
|
|
16
|
-
module: TransactionalModule,
|
|
17
|
-
imports: [FeatureExplorerModule],
|
|
18
|
-
providers: [TransactionAdapterProvider(config), TransactionalMetadataExplorer, TransactionalMetadataAccessor, TransactionalFeatureDecoration],
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static registerAsync(config: TransactionalModuleConfigAsync): DynamicModule {
|
|
23
|
-
return super.config(config, {
|
|
24
|
-
global: true,
|
|
25
|
-
module: TransactionalModule,
|
|
26
|
-
imports: [FeatureExplorerModule],
|
|
27
|
-
providers: [
|
|
28
|
-
TransactionAdapterAsyncProvider(config),
|
|
29
|
-
TransactionalMetadataExplorer,
|
|
30
|
-
TransactionalMetadataAccessor,
|
|
31
|
-
TransactionalFeatureDecoration,
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ModuleConfigAsync, ModuleConfigBase } from "@nestplatform/common";
|
|
2
|
-
import { ITransactionAdapter } from "../interfaces";
|
|
3
|
-
|
|
4
|
-
export type TransactionalModuleConfig = {
|
|
5
|
-
adapters: ITransactionAdapter | Record<string, ITransactionAdapter>;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type TransactionalModuleConfigSync = Omit<ModuleConfigBase, "global"> & TransactionalModuleConfig;
|
|
9
|
-
|
|
10
|
-
export type TransactionalModuleConfigAsync = Omit<ModuleConfigBase, "global"> & ModuleConfigAsync<TransactionalModuleConfig>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ITransactionAdapter } from "../interfaces";
|
|
2
|
-
|
|
3
|
-
export enum TransactionPropagation {
|
|
4
|
-
/** Join existing transaction or create a new one (default) */
|
|
5
|
-
REQUIRED = "REQUIRED",
|
|
6
|
-
|
|
7
|
-
/** Always create a new transaction, suspending the current one */
|
|
8
|
-
REQUIRES_NEW = "REQUIRES_NEW",
|
|
9
|
-
|
|
10
|
-
/** Create a savepoint within the existing transaction */
|
|
11
|
-
NESTED = "NESTED",
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export enum TransactionIsolation {
|
|
15
|
-
READ_UNCOMMITTED = "READ UNCOMMITTED",
|
|
16
|
-
READ_COMMITTED = "READ COMMITTED",
|
|
17
|
-
REPEATABLE_READ = "REPEATABLE READ",
|
|
18
|
-
SERIALIZABLE = "SERIALIZABLE",
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type TransactionalOptions = {
|
|
22
|
-
propagation?: TransactionPropagation;
|
|
23
|
-
isolation?: TransactionIsolation;
|
|
24
|
-
adapter?: string;
|
|
25
|
-
logging?: boolean;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export type TransactionExecuteOptions = {
|
|
29
|
-
propagation: TransactionPropagation;
|
|
30
|
-
isolation?: TransactionIsolation;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type TransactionAdapters = Record<string, ITransactionAdapter>;
|