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

75 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PersistenceContext = void 0; /** * Centralized configuration holder for persistence-layer components. * * This singleton class is used to aggregate all necessary configurations * for a TypeORM-based persistence context, including repositories, migrations, * subscribers, naming strategy, query caching, and database options. * * It is designed for use in frameworks like NodeBoot or other structured apps * that need to configure and bootstrap the data layer in a centralized way. * * Usage: * ```ts * const context = PersistenceContext.get(); * //context.repositories * //context.migrations * //context.eventSubscribers * //... * ``` * * @author Manuel Santos <https://github.com/manusant> */ class PersistenceContext { static context; /** * Metadata for all custom repositories managed in this context. */ repositories = []; /** * Array of migration classes to be run by TypeORM. */ migrations = []; /** * Array of event subscriber classes for lifecycle hooks. */ eventSubscribers = []; /** * Optional custom naming strategy for database table and column naming. */ namingStrategy; /** * Optional custom query result cache provider. */ queryCache; /** * Optional configuration to override the default database connection. */ databaseConnectionOverrides; /** * Whether to synchronize the database schema with entities. * (Typically used in dev only) */ synchronizeDatabase; /** * Whether TypeORM should automatically run pending migrations. */ migrationsRun; /** * Retrieves the singleton instance of the `PersistenceContext`. * * Ensures a single source of truth for persistence configuration throughout the app. * * @returns Singleton instance of `PersistenceContext`. */ static get() { if (!PersistenceContext.context) { PersistenceContext.context = new PersistenceContext(); } return PersistenceContext.context; } } exports.PersistenceContext = PersistenceContext; //# sourceMappingURL=PersistenceContext.js.map