@nestjs/typeorm
Version:
Nest - modern, fast, powerful node.js web framework (@typeorm)
37 lines (36 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataSourceNameRegistry = void 0;
const common_1 = require("@nestjs/common");
/**
* Tracks active data source names at runtime in order to prevent multiple
* data sources from being registered under the same name. Registering two
* data sources with the same name is unsupported by TypeORM — the second
* registration silently overrides the first — which is a common source
* of hard-to-debug configuration issues.
*/
class DataSourceNameRegistry {
static logger = new common_1.Logger(DataSourceNameRegistry.name);
static registeredNames = new Set();
static register(dataSourceName) {
if (this.registeredNames.has(dataSourceName)) {
// Commented out to avoid throwing an exception as it caused regressions in test suites.
// throw new DuplicateDataSourceException(dataSourceName);
this.logger.warn(`A data source with the ${dataSourceName} name is already registered. ` +
`Multiple data sources must be registered with unique names; otherwise, ` +
`they will override each other. Please assign a unique "name" property ` +
`to each TypeOrmModule.forRoot()/forRootAsync() registration.`);
}
this.registeredNames.add(dataSourceName);
}
static unregister(dataSourceName) {
this.registeredNames.delete(dataSourceName);
}
static has(dataSourceName) {
return this.registeredNames.has(dataSourceName);
}
static clear() {
this.registeredNames.clear();
}
}
exports.DataSourceNameRegistry = DataSourceNameRegistry;