UNPKG

@nodeboot/starter-persistence

Version:

Nodeboot starter package for persistence. Supports data access layer auto-configuration providing features like database initialization, consistency check, entity mapping, repository pattern, transactions, paging, migrations, persistence listeners, persis

62 lines 3.17 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransactionConfiguration = void 0; const core_1 = require("@nodeboot/core"); const typeorm_1 = require("typeorm"); const typeorm_transactional_1 = require("typeorm-transactional"); const types_1 = require("../types"); /** * TransactionConfiguration class responsible for setting up transactional support * for the persistence layer using typeorm-transactional library. * * It initializes the transactional context and binds the DataSource * to the transactional data source manager. * * @author Manuel Santos <https://github.com/manusant> */ let TransactionConfiguration = class TransactionConfiguration { /** * Configures transactional support for the persistence layer. * * Reads transactional options from the persistence properties and * initializes the transactional context accordingly. * * Binds the TypeORM DataSource as the transactional data source. * * Logs configuration details. * * @param {BeansContext} context - Contains the IoC container, logger, and configuration instances. * @returns {void} * * @author Manuel Santos <https://github.com/manusant> */ transactionConfig({ iocContainer, logger, config }) { logger.info("Configuring transactions"); const dataSource = iocContainer.get(typeorm_1.DataSource); const persistenceProperties = config.get(types_1.PERSISTENCE_CONFIG_PATH); // Enable transactions (0, typeorm_transactional_1.initializeTransactionalContext)(persistenceProperties.transactions ?? { storageDriver: typeorm_transactional_1.StorageDriver.AUTO }); (0, typeorm_transactional_1.addTransactionalDataSource)(dataSource); logger.info("Transactions successfully configured with storage driver in AUTO mode (AsyncLocalStorage when node >= 16 and cls-hooked otherwise)"); } }; exports.TransactionConfiguration = TransactionConfiguration; __decorate([ (0, core_1.Bean)(), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], TransactionConfiguration.prototype, "transactionConfig", null); exports.TransactionConfiguration = TransactionConfiguration = __decorate([ (0, core_1.Configuration)() ], TransactionConfiguration); //# sourceMappingURL=TransactionConfiguration.js.map