@things-factory/shell 7.0.70 → 7.0.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { DataSource, EntityTarget, Repository } from 'typeorm';
1
+ import { DataSource, EntityManager, EntityTarget, Repository } from 'typeorm';
2
2
  /**
3
3
  * Returns the specified DataSource by name.
4
4
  * @param {string} name - The name of the DataSource.
@@ -26,7 +26,7 @@ export declare function getDataSourceNames(): string[];
26
26
  * @param {EntityTarget<X>} target - The target entity for which to get the repository.
27
27
  * @returns {Repository<X>} - The repository for the specified entity.
28
28
  */
29
- export declare function getRepository<X>(target: EntityTarget<X>): Repository<X>;
29
+ export declare function getRepository<X>(target: EntityTarget<X>, tx?: EntityManager): Repository<X>;
30
30
  /**
31
31
  * Initializes the database connections and data sources.
32
32
  */
@@ -52,8 +52,8 @@ function getDataSourceNames() {
52
52
  * @param {EntityTarget<X>} target - The target entity for which to get the repository.
53
53
  * @returns {Repository<X>} - The repository for the specified entity.
54
54
  */
55
- function getRepository(target) {
56
- return getDataSource('default').getRepository(target);
55
+ function getRepository(target, tx) {
56
+ return tx ? tx.getRepository(target) : getDataSource('default').getRepository(target);
57
57
  }
58
58
  /**
59
59
  * Initializes the database connections and data sources.
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../server/initializers/database.ts"],"names":[],"mappings":";;;AAoBA,sCAEC;AAOD,sCAEC;AAMD,4CAEC;AAMD,gDAEC;AAOD,sCAEC;AAxDD,qCAAgF;AAEhF,6CAAiE;AAEjE,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,SAAS,CAAA;AACb,IAAI,CAAC;IACH,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAW,EAAE,WAAW,CAAC,CAAC,CAAA;AAC7D,CAAC;AAAC,OAAO,CAAC,EAAE,CAAC;IACX,SAAS,GAAG,OA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C;QAED,IAAI,YAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAC;YAC/B,MAAM,aAAa,GAAG,IAAI,oBAAU,iCAC/B,SAAS,GACT,YAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAC7B,CAAA;YACF,MAAM,aAAa,CAAC,UAAU,EAAE,CAAA;YAChC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;YAElC,YAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAA;QACnD,CAAC;aAAM,CAAC;YACN,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QACjC,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,YAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC,CAAA;AAlCY,QAAA,mBAAmB,uBAkC/B","sourcesContent":["import { createConnection, DataSource, EntityTarget, Repository } from 'typeorm'\n\nimport { appRootPath, config, logger } from '@things-factory/env'\n\nconst path = require('path')\n\nvar ormconfig\ntry {\n ormconfig = require(path.resolve(appRootPath, 'ormconfig'))\n} catch (e) {\n ormconfig = require('@things-factory/shell/ormconfig')\n}\n\nconst dataSources: { [name: string]: DataSource } = {}\n\n/**\n * Returns the specified DataSource by name.\n * @param {string} name - The name of the DataSource.\n * @returns {DataSource} - The DataSource with the specified name.\n */\nexport function getDataSource(name?: string): DataSource {\n return dataSources[name || 'default']\n}\n\n/**\n * Adds a new DataSource with the specified name.\n * @param {string} name - The name of the DataSource to add.\n * @param {DataSource} dataSource - The DataSource to add.\n */\nexport function addDataSource(name: string, dataSource: DataSource) {\n dataSources[name] = dataSource\n}\n\n/**\n * Removes a DataSource with the specified name.\n * @param {string} name - The name of the DataSource to remove.\n */\nexport function removeDataSource(name: string) {\n delete dataSources[name]\n}\n\n/**\n * Returns an array of all registered DataSource names.\n * @returns {string[]} - An array of DataSource names.\n */\nexport function getDataSourceNames() {\n return Object.keys(dataSources)\n}\n\n/**\n * Returns a repository for the specified entity.\n * @param {EntityTarget<X>} target - The target entity for which to get the repository.\n * @returns {Repository<X>} - The repository for the specified entity.\n */\nexport function getRepository<X>(target: EntityTarget<X>): Repository<X> {\n return getDataSource('default').getRepository<X>(target)\n}\n\n/**\n * Initializes the database connections and data sources.\n */\nexport const databaseInitializer = async () => {\n try {\n const readConnectionConfig = config.get('ormconfig')\n\n const dataSource = await createConnection({\n ...ormconfig,\n ...readConnectionConfig\n })\n\n addDataSource('default', dataSource)\n\n logger.info('Default DataSource established')\n\n if (readConnectionConfig.type == 'sqlite' && readConnectionConfig.synchronize == false) {\n await dataSource.query('PRAGMA foreign_keys=OFF')\n await dataSource.synchronize()\n await dataSource.query('PRAGMA foreign_keys=ON')\n }\n\n if (config.get('ormconfig4Tx')) {\n const dataSource4Tx = new DataSource({\n ...ormconfig,\n ...config.get('ormconfig4Tx')\n })\n await dataSource4Tx.initialize()\n addDataSource('tx', dataSource4Tx)\n\n logger.info('Transaction DataSource established')\n } else {\n addDataSource('tx', dataSource)\n }\n } catch (e) {\n logger.error(e)\n }\n}\n"]}
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../server/initializers/database.ts"],"names":[],"mappings":";;;AAoBA,sCAEC;AAOD,sCAEC;AAMD,4CAEC;AAMD,gDAEC;AAOD,sCAEC;AAxDD,qCAA+F;AAE/F,6CAAiE;AAEjE,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,SAAS,CAAA;AACb,IAAI,CAAC;IACH,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,iBAAW,EAAE,WAAW,CAAC,CAAC,CAAA;AAC7D,CAAC;AAAC,OAAO,CAAC,EAAE,CAAC;IACX,SAAS,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAA;AACxD,CAAC;AAED,MAAM,WAAW,GAAmC,EAAE,CAAA;AAEtD;;;;GAIG;AACH,SAAgB,aAAa,CAAC,IAAa;IACzC,OAAO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CAAC,EAAE,CAAC;YAC/B,MAAM,aAAa,GAAG,IAAI,oBAAU,iCAC/B,SAAS,GACT,YAAM,CAAC,GAAG,CAAC,cAAc,CAAC,EAC7B,CAAA;YACF,MAAM,aAAa,CAAC,UAAU,EAAE,CAAA;YAChC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;YAElC,YAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAA;QACnD,CAAC;aAAM,CAAC;YACN,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QACjC,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,YAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC,CAAA;AAlCY,QAAA,mBAAmB,uBAkC/B","sourcesContent":["import { createConnection, DataSource, EntityManager, EntityTarget, Repository } from 'typeorm'\n\nimport { appRootPath, config, logger } from '@things-factory/env'\n\nconst path = require('path')\n\nvar ormconfig\ntry {\n ormconfig = require(path.resolve(appRootPath, 'ormconfig'))\n} catch (e) {\n ormconfig = require('@things-factory/shell/ormconfig')\n}\n\nconst dataSources: { [name: string]: DataSource } = {}\n\n/**\n * Returns the specified DataSource by name.\n * @param {string} name - The name of the DataSource.\n * @returns {DataSource} - The DataSource with the specified name.\n */\nexport function getDataSource(name?: string): DataSource {\n return dataSources[name || 'default']\n}\n\n/**\n * Adds a new DataSource with the specified name.\n * @param {string} name - The name of the DataSource to add.\n * @param {DataSource} dataSource - The DataSource to add.\n */\nexport function addDataSource(name: string, dataSource: DataSource) {\n dataSources[name] = dataSource\n}\n\n/**\n * Removes a DataSource with the specified name.\n * @param {string} name - The name of the DataSource to remove.\n */\nexport function removeDataSource(name: string) {\n delete dataSources[name]\n}\n\n/**\n * Returns an array of all registered DataSource names.\n * @returns {string[]} - An array of DataSource names.\n */\nexport function getDataSourceNames() {\n return Object.keys(dataSources)\n}\n\n/**\n * Returns a repository for the specified entity.\n * @param {EntityTarget<X>} target - The target entity for which to get the repository.\n * @returns {Repository<X>} - The repository for the specified entity.\n */\nexport function getRepository<X>(target: EntityTarget<X>, tx?: EntityManager): Repository<X> {\n return tx ? tx.getRepository<X>(target) : getDataSource('default').getRepository<X>(target)\n}\n\n/**\n * Initializes the database connections and data sources.\n */\nexport const databaseInitializer = async () => {\n try {\n const readConnectionConfig = config.get('ormconfig')\n\n const dataSource = await createConnection({\n ...ormconfig,\n ...readConnectionConfig\n })\n\n addDataSource('default', dataSource)\n\n logger.info('Default DataSource established')\n\n if (readConnectionConfig.type == 'sqlite' && readConnectionConfig.synchronize == false) {\n await dataSource.query('PRAGMA foreign_keys=OFF')\n await dataSource.synchronize()\n await dataSource.query('PRAGMA foreign_keys=ON')\n }\n\n if (config.get('ormconfig4Tx')) {\n const dataSource4Tx = new DataSource({\n ...ormconfig,\n ...config.get('ormconfig4Tx')\n })\n await dataSource4Tx.initialize()\n addDataSource('tx', dataSource4Tx)\n\n logger.info('Transaction DataSource established')\n } else {\n addDataSource('tx', dataSource)\n }\n } catch (e) {\n logger.error(e)\n }\n}\n"]}