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AAI,+BAA+B,CAAC,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC,CAAC;YAEzE,sEAAsE;YACtE,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC;SACzE;QAED,0BAA0B;QAC1B,IAAM,UAAU,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,OAAO,UAAU,CAAC;IACtB,CAAC;IAEL,wBAAC;AAAD,CA3DA,AA2DC,IAAA","file":"ConnectionManager.js","sourcesContent":["import {Connection} from \"./Connection\";\nimport {ConnectionNotFoundError} from \"../error/ConnectionNotFoundError\";\nimport {ConnectionOptions} from \"./ConnectionOptions\";\nimport {AlreadyHasActiveConnectionError} from \"../error/AlreadyHasActiveConnectionError\";\n\n/**\n * ConnectionManager is used to store and manage multiple orm connections.\n * It also provides useful factory methods to simplify connection creation.\n */\nexport class ConnectionManager {\n\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * List of connections registered in this connection manager.\n */\n public readonly connections: Connection[] = [];\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if connection with the given name exist in the manager.\n */\n has(name: string): boolean {\n return !!this.connections.find(connection => connection.name === name);\n }\n\n /**\n * Gets registered connection with the given name.\n * If connection name is not given then it will get a default connection.\n * Throws error if connection with the given name was not found.\n */\n get(name: string = \"default\"): Connection {\n const connection = this.connections.find(connection => connection.name === name);\n if (!connection)\n throw new ConnectionNotFoundError(name);\n\n return connection;\n }\n\n /**\n * Creates a new connection based on the given connection options and registers it in the manager.\n * Connection won't be established, you'll need to manually call connect method to establish connection.\n */\n create(options: ConnectionOptions): Connection {\n\n // check if such connection is already registered\n const existConnection = this.connections.find(connection => connection.name === (options.name || \"default\"));\n if (existConnection) {\n\n // if connection is registered and its not closed then throw an error\n if (existConnection.isConnected)\n throw new AlreadyHasActiveConnectionError(options.name || \"default\");\n\n // if its registered but closed then simply remove it from the manager\n this.connections.splice(this.connections.indexOf(existConnection), 1);\n }\n\n // create a new connection\n const connection = new Connection(options);\n this.connections.push(connection);\n return connection;\n }\n\n}\n"],"sourceRoot":".."}
|