UNPKG

@nestjs-cls/transactional

Version:

A nestjs-cls plugin for transactional decorators

37 lines (36 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NoOpTransactionalAdapter = void 0; const common_1 = require("@nestjs/common"); /** * A no-op transactional adapter that does not actually start a transaction. * * Useful for testing purposes or making sure that the TransactionHost is wired up correctly. */ class NoOpTransactionalAdapter { constructor(options) { this.logger = new common_1.Logger(NoOpTransactionalAdapter.name); this.optionsFactory = (connection) => { return { wrapWithTransaction: async (_options, fn, setTx) => { if (!this.disableWarning) { this.logger.warn('Transactions are disabled when using the no-op adapter. Make sure you only use it for testing purposes.'); } setTx(connection); return fn(); }, getFallbackInstance: () => connection, }; }; if (!options.tx && !options.txToken) { throw new Error('Either `tx` or `txToken` must be provided.'); } if (options.tx && options.txToken) { throw new Error('Only one of `tx` or `txToken` must be provided.'); } this.connection = options.tx; this.connectionToken = options.txToken; this.disableWarning = options.disableWarning ?? false; } } exports.NoOpTransactionalAdapter = NoOpTransactionalAdapter;