@tsed/mikro-orm 6.99.0 → 6.100.0

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.
Files changed (49) hide show
  1. package/jest.config.js +4 -4
  2. package/lib/cjs/MikroOrmModule.js +2 -2
  3. package/lib/cjs/MikroOrmModule.js.map +1 -1
  4. package/lib/cjs/decorators/entityManager.d.ts +6 -6
  5. package/lib/cjs/decorators/entityManager.js +5 -5
  6. package/lib/cjs/decorators/entityManager.js.map +1 -1
  7. package/lib/cjs/decorators/orm.d.ts +7 -1
  8. package/lib/cjs/decorators/orm.js +9 -4
  9. package/lib/cjs/decorators/orm.js.map +1 -1
  10. package/lib/cjs/decorators/transactional.d.ts +5 -1
  11. package/lib/cjs/decorators/transactional.js +5 -1
  12. package/lib/cjs/decorators/transactional.js.map +1 -1
  13. package/lib/cjs/interceptors/TransactionalInterceptor.d.ts +5 -1
  14. package/lib/cjs/interceptors/TransactionalInterceptor.js +28 -13
  15. package/lib/cjs/interceptors/TransactionalInterceptor.js.map +1 -1
  16. package/lib/cjs/services/DBContext.d.ts +4 -0
  17. package/lib/cjs/services/DBContext.js +9 -3
  18. package/lib/cjs/services/DBContext.js.map +1 -1
  19. package/lib/cjs/services/MikroOrmFactory.d.ts +1 -1
  20. package/lib/cjs/services/MikroOrmFactory.js +2 -2
  21. package/lib/cjs/services/MikroOrmFactory.js.map +1 -1
  22. package/lib/cjs/services/MikroOrmRegistry.d.ts +12 -4
  23. package/lib/cjs/services/MikroOrmRegistry.js +38 -27
  24. package/lib/cjs/services/MikroOrmRegistry.js.map +1 -1
  25. package/lib/esm/MikroOrmModule.js +2 -2
  26. package/lib/esm/MikroOrmModule.js.map +1 -1
  27. package/lib/esm/decorators/entityManager.js +5 -5
  28. package/lib/esm/decorators/entityManager.js.map +1 -1
  29. package/lib/esm/decorators/orm.js +8 -2
  30. package/lib/esm/decorators/orm.js.map +1 -1
  31. package/lib/esm/decorators/transactional.js +5 -1
  32. package/lib/esm/decorators/transactional.js.map +1 -1
  33. package/lib/esm/interceptors/TransactionalInterceptor.js +28 -13
  34. package/lib/esm/interceptors/TransactionalInterceptor.js.map +1 -1
  35. package/lib/esm/services/DBContext.js +9 -3
  36. package/lib/esm/services/DBContext.js.map +1 -1
  37. package/lib/esm/services/MikroOrmFactory.js +2 -2
  38. package/lib/esm/services/MikroOrmFactory.js.map +1 -1
  39. package/lib/esm/services/MikroOrmRegistry.js +38 -27
  40. package/lib/esm/services/MikroOrmRegistry.js.map +1 -1
  41. package/lib/types/decorators/entityManager.d.ts +6 -6
  42. package/lib/types/decorators/orm.d.ts +7 -1
  43. package/lib/types/decorators/transactional.d.ts +5 -1
  44. package/lib/types/interceptors/TransactionalInterceptor.d.ts +5 -1
  45. package/lib/types/services/DBContext.d.ts +4 -0
  46. package/lib/types/services/MikroOrmFactory.d.ts +1 -1
  47. package/lib/types/services/MikroOrmRegistry.d.ts +12 -4
  48. package/package.json +10 -10
  49. package/readme.md +4 -4
package/jest.config.js CHANGED
@@ -5,10 +5,10 @@ module.exports = {
5
5
  ...require("@tsed/jest-config")(__dirname, "mikro-orm"),
6
6
  coverageThreshold: {
7
7
  global: {
8
- branches: 90.91,
9
- functions: 96.97,
10
- lines: 99.06,
11
- statements: 98.54
8
+ branches: 90.38,
9
+ functions: 91.43,
10
+ lines: 96.52,
11
+ statements: 97.1
12
12
  }
13
13
  }
14
14
  };
@@ -6,11 +6,11 @@ const services_1 = require("./services");
6
6
  const di_1 = require("@tsed/di");
7
7
  let MikroOrmModule = class MikroOrmModule {
8
8
  async $onInit() {
9
- const promises = this.settings.map((opts) => this.mikroOrmRegistry.createConnection(opts));
9
+ const promises = this.settings.map((opts) => this.mikroOrmRegistry.register(opts));
10
10
  await Promise.all(promises);
11
11
  }
12
12
  $onDestroy() {
13
- return this.mikroOrmRegistry.closeConnections();
13
+ return this.mikroOrmRegistry.clear();
14
14
  }
15
15
  };
16
16
  (0, tslib_1.__decorate)([
@@ -1 +1 @@
1
- {"version":3,"file":"MikroOrmModule.js","sourceRoot":"","sources":["../../src/MikroOrmModule.ts"],"names":[],"mappings":";;;;AAAA,yCAAsE;AACtE,iCAAsG;AAoBtG,IAAa,cAAc,GAA3B,MAAa,cAAc;IAOlB,KAAK,CAAC,OAAO;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3F,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,CAAC;IAClD,CAAC;CACF,CAAA;AAdC;IADC,IAAA,aAAQ,EAAC,UAAU,EAAE,EAAE,CAAC;;gDACa;AAGtC;IADC,IAAA,WAAM,GAAE;2CAC2B,2BAAgB;wDAAC;AAL1C,cAAc;IAJ1B,IAAA,WAAM,EAAC;QACN,OAAO,EAAE,CAAC,oBAAS,EAAE,2BAAgB,CAAC;QACtC,IAAI,EAAE,CAAC,kBAAa,EAAE,2BAAgB,CAAC;KACxC,CAAC;GACW,cAAc,CAgB1B;AAhBY,wCAAc;AAkB3B,uGAAuG;AACvG,IAAA,qBAAgB,EAAC,EAAC,OAAO,EAAE,wBAAa,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC","sourcesContent":["import {DBContext, MikroOrmRegistry, RetryStrategy} from \"./services\";\nimport {Configuration, Constant, Inject, Module, OnDestroy, OnInit, registerProvider} from \"@tsed/di\";\nimport {Options} from \"@mikro-orm/core\";\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace TsED {\n interface Configuration {\n /**\n * The the ORM configuration, entity metadata.\n * If you omit the `options` parameter, your CLI config will be used.\n */\n mikroOrm?: Options[];\n }\n }\n}\n\n@Module({\n imports: [DBContext, MikroOrmRegistry],\n deps: [Configuration, MikroOrmRegistry]\n})\nexport class MikroOrmModule implements OnDestroy, OnInit {\n @Constant(\"mikroOrm\", [])\n private readonly settings!: Options[];\n\n @Inject()\n private readonly mikroOrmRegistry!: MikroOrmRegistry;\n\n public async $onInit(): Promise<void> {\n const promises = this.settings.map((opts) => this.mikroOrmRegistry.createConnection(opts));\n\n await Promise.all(promises);\n }\n\n public $onDestroy(): Promise<void> {\n return this.mikroOrmRegistry.closeConnections();\n }\n}\n\n// TODO: the IoC container should provide null or undefined by default until tsedio/tsed#1694 is closed\nregisterProvider({provide: RetryStrategy, useValue: null});\n"]}
1
+ {"version":3,"file":"MikroOrmModule.js","sourceRoot":"","sources":["../../src/MikroOrmModule.ts"],"names":[],"mappings":";;;;AAAA,yCAAsE;AACtE,iCAAsG;AAoBtG,IAAa,cAAc,GAA3B,MAAa,cAAc;IAOlB,KAAK,CAAC,OAAO;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAEnF,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IACvC,CAAC;CACF,CAAA;AAdC;IADC,IAAA,aAAQ,EAAC,UAAU,EAAE,EAAE,CAAC;;gDACa;AAGtC;IADC,IAAA,WAAM,GAAE;2CAC2B,2BAAgB;wDAAC;AAL1C,cAAc;IAJ1B,IAAA,WAAM,EAAC;QACN,OAAO,EAAE,CAAC,oBAAS,EAAE,2BAAgB,CAAC;QACtC,IAAI,EAAE,CAAC,kBAAa,EAAE,2BAAgB,CAAC;KACxC,CAAC;GACW,cAAc,CAgB1B;AAhBY,wCAAc;AAkB3B,uGAAuG;AACvG,IAAA,qBAAgB,EAAC,EAAC,OAAO,EAAE,wBAAa,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC","sourcesContent":["import {DBContext, MikroOrmRegistry, RetryStrategy} from \"./services\";\nimport {Configuration, Constant, Inject, Module, OnDestroy, OnInit, registerProvider} from \"@tsed/di\";\nimport {Options} from \"@mikro-orm/core\";\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace TsED {\n interface Configuration {\n /**\n * The the ORM configuration, entity metadata.\n * If you omit the `options` parameter, your CLI config will be used.\n */\n mikroOrm?: Options[];\n }\n }\n}\n\n@Module({\n imports: [DBContext, MikroOrmRegistry],\n deps: [Configuration, MikroOrmRegistry]\n})\nexport class MikroOrmModule implements OnDestroy, OnInit {\n @Constant(\"mikroOrm\", [])\n private readonly settings!: Options[];\n\n @Inject()\n private readonly mikroOrmRegistry!: MikroOrmRegistry;\n\n public async $onInit(): Promise<void> {\n const promises = this.settings.map((opts) => this.mikroOrmRegistry.register(opts));\n\n await Promise.all(promises);\n }\n\n public $onDestroy(): Promise<void> {\n return this.mikroOrmRegistry.clear();\n }\n}\n\n// TODO: the IoC container should provide null or undefined by default until tsedio/tsed#1694 is closed\nregisterProvider({provide: RetryStrategy, useValue: null});\n"]}
@@ -1,14 +1,14 @@
1
1
  /**
2
- * Get the entity manager for the given connection name.
3
- * @param connectionName
2
+ * Get the entity manager for the given context name.
3
+ * @param {String} contextName
4
4
  * @decorator
5
5
  * @mikroOrm
6
6
  */
7
- export declare const EntityManager: (connectionName?: string | undefined) => PropertyDecorator;
7
+ export declare const EntityManager: (contextName?: string | undefined) => PropertyDecorator;
8
8
  /**
9
- * Get the entity manager for the given connection name.
10
- * @param connectionName
9
+ * Get the entity manager for the given context name.
10
+ * @param {String} connectionName
11
11
  * @decorator
12
12
  * @mikroOrm
13
13
  */
14
- export declare const Em: (connectionName?: string | undefined) => PropertyDecorator;
14
+ export declare const Em: (contextName?: string | undefined) => PropertyDecorator;
@@ -4,16 +4,16 @@ exports.Em = exports.EntityManager = void 0;
4
4
  const di_1 = require("@tsed/di");
5
5
  const services_1 = require("../services");
6
6
  /**
7
- * Get the entity manager for the given connection name.
8
- * @param connectionName
7
+ * Get the entity manager for the given context name.
8
+ * @param {String} contextName
9
9
  * @decorator
10
10
  * @mikroOrm
11
11
  */
12
- const EntityManager = (connectionName) => (0, di_1.Inject)(services_1.MikroOrmRegistry, (registry) => { var _a; return (_a = registry.get(connectionName)) === null || _a === void 0 ? void 0 : _a.em; });
12
+ const EntityManager = (contextName) => (0, di_1.Inject)(services_1.MikroOrmRegistry, (registry) => { var _a; return (_a = registry.get(contextName)) === null || _a === void 0 ? void 0 : _a.em; });
13
13
  exports.EntityManager = EntityManager;
14
14
  /**
15
- * Get the entity manager for the given connection name.
16
- * @param connectionName
15
+ * Get the entity manager for the given context name.
16
+ * @param {String} connectionName
17
17
  * @decorator
18
18
  * @mikroOrm
19
19
  */
@@ -1 +1 @@
1
- {"version":3,"file":"entityManager.js","sourceRoot":"","sources":["../../../src/decorators/entityManager.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,0CAA6C;AAE7C;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,cAAuB,EAAqB,EAAE,CAC1E,IAAA,WAAM,EAAC,2BAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,WAAC,OAAA,MAAA,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAsB,CAAC;AADrG,QAAA,aAAa,iBACwF;AAElH;;;;;GAKG;AACU,QAAA,EAAE,GAAG,qBAAa,CAAC","sourcesContent":["import {Inject} from \"@tsed/di\";\nimport {MikroOrmRegistry} from \"../services\";\n\n/**\n * Get the entity manager for the given connection name.\n * @param connectionName\n * @decorator\n * @mikroOrm\n */\nexport const EntityManager = (connectionName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(connectionName)?.em) as PropertyDecorator;\n\n/**\n * Get the entity manager for the given connection name.\n * @param connectionName\n * @decorator\n * @mikroOrm\n */\nexport const Em = EntityManager;\n"]}
1
+ {"version":3,"file":"entityManager.js","sourceRoot":"","sources":["../../../src/decorators/entityManager.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,0CAA6C;AAE7C;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAAqB,EAAE,CACvE,IAAA,WAAM,EAAC,2BAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,WAAC,OAAA,MAAA,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAsB,CAAC;AADlG,QAAA,aAAa,iBACqF;AAE/G;;;;;GAKG;AACU,QAAA,EAAE,GAAG,qBAAa,CAAC","sourcesContent":["import {Inject} from \"@tsed/di\";\nimport {MikroOrmRegistry} from \"../services\";\n\n/**\n * Get the entity manager for the given context name.\n * @param {String} contextName\n * @decorator\n * @mikroOrm\n */\nexport const EntityManager = (contextName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(contextName)?.em) as PropertyDecorator;\n\n/**\n * Get the entity manager for the given context name.\n * @param {String} connectionName\n * @decorator\n * @mikroOrm\n */\nexport const Em = EntityManager;\n"]}
@@ -1,5 +1,11 @@
1
1
  /**
2
+ * Get the ORM for the given context name.
3
+ * @param {String} contextName
4
+ */
5
+ export declare const Orm: (contextName?: string | undefined) => PropertyDecorator;
6
+ /**
7
+ * Get the ORM for the given context name.
8
+ * @param {String} contextName
2
9
  * @deprecated Since 2022-02-01. Use {@link Orm} instead
3
10
  */
4
11
  export declare const Connection: (contextName?: string | undefined) => PropertyDecorator;
5
- export declare const Orm: (contextName?: string | undefined) => PropertyDecorator;
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Orm = exports.Connection = void 0;
3
+ exports.Connection = exports.Orm = void 0;
4
4
  const services_1 = require("../services");
5
5
  const di_1 = require("@tsed/di");
6
6
  /**
7
- * @deprecated Since 2022-02-01. Use {@link Orm} instead
7
+ * Get the ORM for the given context name.
8
+ * @param {String} contextName
8
9
  */
9
- const Connection = (contextName) => (0, exports.Orm)(contextName);
10
- exports.Connection = Connection;
11
10
  const Orm = (contextName) => (0, di_1.Inject)(services_1.MikroOrmRegistry, (registry) => registry.get(contextName));
12
11
  exports.Orm = Orm;
12
+ /**
13
+ * Get the ORM for the given context name.
14
+ * @param {String} contextName
15
+ * @deprecated Since 2022-02-01. Use {@link Orm} instead
16
+ */
17
+ exports.Connection = exports.Orm;
13
18
  //# sourceMappingURL=orm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":";;;AAAA,0CAA6C;AAC7C,iCAAgC;AAEhC;;GAEG;AACI,MAAM,UAAU,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAAC,IAAA,WAAG,EAAC,WAAW,CAAC,CAAC;AAA3E,QAAA,UAAU,cAAiE;AAEjF,MAAM,GAAG,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAC7D,IAAA,WAAM,EAAC,2BAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAsB,CAAC;AAD9F,QAAA,GAAG,OAC2F","sourcesContent":["import {MikroOrmRegistry} from \"../services\";\nimport {Inject} from \"@tsed/di\";\n\n/**\n * @deprecated Since 2022-02-01. Use {@link Orm} instead\n */\nexport const Connection = (contextName?: string): PropertyDecorator => Orm(contextName);\n\nexport const Orm = (contextName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(contextName)) as PropertyDecorator;\n"]}
1
+ {"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":";;;AAAA,0CAA6C;AAC7C,iCAAgC;AAEhC;;;GAGG;AACI,MAAM,GAAG,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAC7D,IAAA,WAAM,EAAC,2BAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAsB,CAAC;AAD9F,QAAA,GAAG,OAC2F;AAE3G;;;;GAIG;AACU,QAAA,UAAU,GAAG,WAAG,CAAC","sourcesContent":["import {MikroOrmRegistry} from \"../services\";\nimport {Inject} from \"@tsed/di\";\n\n/**\n * Get the ORM for the given context name.\n * @param {String} contextName\n */\nexport const Orm = (contextName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(contextName)) as PropertyDecorator;\n\n/**\n * Get the ORM for the given context name.\n * @param {String} contextName\n * @deprecated Since 2022-02-01. Use {@link Orm} instead\n */\nexport const Connection = Orm;\n"]}
@@ -1,2 +1,6 @@
1
1
  import { TransactionOptions } from "../interceptors";
2
- export declare const Transactional: (connectionOrOptions?: string | TransactionOptions | undefined) => MethodDecorator;
2
+ /**
3
+ * Register a new request context for your method and execute it inside the context.
4
+ * @param {String | TransactionOptions} contextNameOrOptions
5
+ */
6
+ export declare const Transactional: (contextNameOrOptions?: string | TransactionOptions | undefined) => MethodDecorator;
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Transactional = void 0;
4
4
  const interceptors_1 = require("../interceptors");
5
5
  const di_1 = require("@tsed/di");
6
- const Transactional = (connectionOrOptions) => (0, di_1.Intercept)(interceptors_1.TransactionalInterceptor, connectionOrOptions);
6
+ /**
7
+ * Register a new request context for your method and execute it inside the context.
8
+ * @param {String | TransactionOptions} contextNameOrOptions
9
+ */
10
+ const Transactional = (contextNameOrOptions) => (0, di_1.Intercept)(interceptors_1.TransactionalInterceptor, contextNameOrOptions);
7
11
  exports.Transactional = Transactional;
8
12
  //# sourceMappingURL=transactional.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transactional.js","sourceRoot":"","sources":["../../../src/decorators/transactional.ts"],"names":[],"mappings":";;;AAAA,kDAA6E;AAC7E,iCAAmC;AAE5B,MAAM,aAAa,GAAG,CAAC,mBAAiD,EAAmB,EAAE,CAClG,IAAA,cAAS,EAAC,uCAAwB,EAAE,mBAAmB,CAAC,CAAC;AAD9C,QAAA,aAAa,iBACiC","sourcesContent":["import {TransactionalInterceptor, TransactionOptions} from \"../interceptors\";\nimport {Intercept} from \"@tsed/di\";\n\nexport const Transactional = (connectionOrOptions?: string | TransactionOptions): MethodDecorator =>\n Intercept(TransactionalInterceptor, connectionOrOptions);\n"]}
1
+ {"version":3,"file":"transactional.js","sourceRoot":"","sources":["../../../src/decorators/transactional.ts"],"names":[],"mappings":";;;AAAA,kDAA6E;AAC7E,iCAAmC;AAEnC;;;GAGG;AACI,MAAM,aAAa,GAAG,CAAC,oBAAkD,EAAmB,EAAE,CACnG,IAAA,cAAS,EAAC,uCAAwB,EAAE,oBAAoB,CAAC,CAAC;AAD/C,QAAA,aAAa,iBACkC","sourcesContent":["import {TransactionalInterceptor, TransactionOptions} from \"../interceptors\";\nimport {Intercept} from \"@tsed/di\";\n\n/**\n * Register a new request context for your method and execute it inside the context.\n * @param {String | TransactionOptions} contextNameOrOptions\n */\nexport const Transactional = (contextNameOrOptions?: string | TransactionOptions): MethodDecorator =>\n Intercept(TransactionalInterceptor, contextNameOrOptions);\n"]}
@@ -2,8 +2,12 @@ import { DBContext, MikroOrmRegistry, RetryStrategy } from "../services";
2
2
  import { InterceptorContext, InterceptorMethods, InterceptorNext } from "@tsed/di";
3
3
  import { Logger } from "@tsed/logger";
4
4
  export interface TransactionOptions {
5
- connectionName?: string;
6
5
  retry?: boolean;
6
+ contextName?: string;
7
+ /**
8
+ * @deprecated Since 2022-02-01. Use {@link contextName} instead
9
+ */
10
+ connectionName?: string;
7
11
  }
8
12
  export declare class TransactionalInterceptor implements InterceptorMethods {
9
13
  private readonly registry;
@@ -17,11 +17,11 @@ let TransactionalInterceptor = class TransactionalInterceptor {
17
17
  if (options.retry && !this.retryStrategy) {
18
18
  this.logger.warn(`To retry a transaction you have to implement a "${services_1.RetryStrategy.description}" interface`);
19
19
  }
20
- const ctx = this.context.getContext();
20
+ const ctx = this.context.entries();
21
21
  if (!ctx) {
22
22
  return this.runWithinNewCtx(next, options);
23
23
  }
24
- if (ctx.has(options.connectionName)) {
24
+ if (ctx.has(options.contextName)) {
25
25
  return next();
26
26
  }
27
27
  return this.runUnderCtx(next, ctx, options);
@@ -31,33 +31,48 @@ let TransactionalInterceptor = class TransactionalInterceptor {
31
31
  return this.runUnderCtx(next, ctx, options);
32
32
  }
33
33
  runUnderCtx(next, ctx, options) {
34
- const orm = this.registry.get(options.connectionName);
35
- const em = orm.em.fork(true, true);
34
+ const orm = this.registry.get(options.contextName);
35
+ if (!orm) {
36
+ throw new Error(`No such context: ${options.contextName}. Please register a corresponding MikroOrm instance using '@Configuration()' decorator.`);
37
+ }
38
+ /**
39
+ * The fork method signature has been changed since v5.x,
40
+ * which might lead to unexpected behavior while using the @Transactional() decorator.
41
+ *
42
+ * ```diff
43
+ * - fork(clear = true, useContext = false): D[typeof EntityManagerType]
44
+ * + fork(options: ForkOptions = {}): D[typeof EntityManagerType] {
45
+ * ```
46
+ *
47
+ * To ensure backward compatibility with v4.x and add support for v5.x, provided the following workaround:
48
+ */
49
+ const em = orm.em.fork({ clear: true, useContext: true }, true);
36
50
  ctx.set(em.name, em);
37
- const runInTransaction = () => this.executeInTransaction(options.connectionName, next);
51
+ const runInTransaction = () => this.executeInTransaction(options.contextName, next);
38
52
  return this.context.run(ctx, () => { var _a; return (options.retry ? (_a = this.retryStrategy) === null || _a === void 0 ? void 0 : _a.acquire(runInTransaction) : runInTransaction()); });
39
53
  }
40
54
  extractContextName(context) {
55
+ var _a;
41
56
  const options = context.options || {};
42
- let connectionName;
57
+ let contextName;
43
58
  let retry;
44
59
  if (typeof options === "string") {
45
- connectionName = options;
60
+ contextName = options;
46
61
  }
47
62
  else if (options) {
48
- connectionName = options.connectionName;
63
+ contextName = (_a = options.contextName) !== null && _a !== void 0 ? _a : options.connectionName;
49
64
  retry = options.retry;
50
65
  }
51
- if (!connectionName) {
52
- connectionName = "default";
66
+ if (!contextName) {
67
+ contextName = "default";
53
68
  }
54
69
  if (!retry) {
55
70
  retry = false;
56
71
  }
57
- return { connectionName, retry };
72
+ return { contextName, retry };
58
73
  }
59
- async executeInTransaction(connectionName, next) {
60
- const em = this.context.get(connectionName);
74
+ async executeInTransaction(contextName, next) {
75
+ const em = this.context.get(contextName);
61
76
  const result = await next();
62
77
  await (em === null || em === void 0 ? void 0 : em.flush());
63
78
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"TransactionalInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/TransactionalInterceptor.ts"],"names":[],"mappings":";;;;AAAA,0CAAuE;AACvE,iCAAsG;AAEtG,yCAAoC;AAQpC,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IACnC,YAC6B,QAA0B,EAC1B,OAAkB,EAClB,MAAc,EAExB,aAA6B;QAJnB,aAAQ,GAAR,QAAQ,CAAkB;QAC1B,YAAO,GAAP,OAAO,CAAW;QAClB,WAAM,GAAN,MAAM,CAAQ;QAExB,kBAAa,GAAb,aAAa,CAAgB;IAC7C,CAAC;IAEG,KAAK,CAAC,SAAS,CAAC,OAAoC,EAAE,IAAqB;QAChF,MAAM,OAAO,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEjD,IAAI,OAAO,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mDAAmD,wBAAa,CAAC,WAAW,aAAa,CAAC,CAAC;SAC7G;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QAEtC,IAAI,CAAC,GAAG,EAAE;YACR,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SAC5C;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AAE;YAC/B,cAAc,GAAG,OAAO,CAAC;SAC1B;aAAM,IAAI,OAAO,EAAE;YAClB,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;YACxC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;SACvB;QAED,IAAI,CAAC,cAAc,EAAE;YACnB,cAAc,GAAG,SAAS,CAAC;SAC5B;QAED,IAAI,CAAC,KAAK,EAAE;YACV,KAAK,GAAG,KAAK,CAAC;SACf;QAED,OAAO,EAAC,cAAc,EAAE,KAAK,EAAC,CAAC;IACjC,CAAC;IAEO,KAAK,CAAC,oBAAoB,CAAC,cAAsB,EAAE,IAAqB;QAC9E,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAE5C,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAE5B,MAAM,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,KAAK,EAAE,CAAA,CAAC;QAElB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AA/EY,wBAAwB;IADpC,IAAA,gBAAW,GAAE;IAGT,wBAAA,IAAA,WAAM,GAAE,CAAA;IACR,wBAAA,IAAA,WAAM,GAAE,CAAA;IACR,wBAAA,IAAA,WAAM,GAAE,CAAA;IACR,wBAAA,IAAA,WAAM,EAAC,wBAAa,CAAC,CAAA;kDAHe,2BAAgB;QACjB,oBAAS;QACV,eAAM;GAJhC,wBAAwB,CA+EpC;AA/EY,4DAAwB","sourcesContent":["import {DBContext, MikroOrmRegistry, RetryStrategy} from \"../services\";\nimport {Inject, Interceptor, InterceptorContext, InterceptorMethods, InterceptorNext} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {Logger} from \"@tsed/logger\";\n\nexport interface TransactionOptions {\n connectionName?: string;\n retry?: boolean;\n}\n\n@Interceptor()\nexport class TransactionalInterceptor implements InterceptorMethods {\n constructor(\n @Inject() private readonly registry: MikroOrmRegistry,\n @Inject() private readonly context: DBContext,\n @Inject() private readonly logger: Logger,\n @Inject(RetryStrategy)\n private readonly retryStrategy?: RetryStrategy\n ) {}\n\n public async intercept(context: InterceptorContext<unknown>, next: InterceptorNext): Promise<unknown> {\n const options = this.extractContextName(context);\n\n if (options.retry && !this.retryStrategy) {\n this.logger.warn(`To retry a transaction you have to implement a \"${RetryStrategy.description}\" interface`);\n }\n\n const ctx = this.context.getContext();\n\n if (!ctx) {\n return this.runWithinNewCtx(next, options);\n }\n\n if (ctx.has(options.connectionName!)) {\n return next();\n }\n\n return this.runUnderCtx(next, ctx, options);\n }\n\n private runWithinNewCtx(next: InterceptorNext, options: TransactionOptions): Promise<unknown> | unknown {\n const ctx = new Map<string, EntityManager>();\n\n return this.runUnderCtx(next, ctx, options);\n }\n\n private runUnderCtx(next: InterceptorNext, ctx: Map<string, EntityManager>, options: TransactionOptions): Promise<unknown> | unknown {\n const orm = this.registry.get(options.connectionName);\n const em = orm.em.fork(true, true);\n\n ctx.set(em.name, em);\n\n const runInTransaction = () => this.executeInTransaction(options.connectionName!, next);\n\n return this.context.run(ctx, () => (options.retry ? this.retryStrategy?.acquire(runInTransaction) : runInTransaction()));\n }\n\n private extractContextName(context: InterceptorContext<unknown>): TransactionOptions {\n const options = context.options || ({} as Partial<TransactionOptions> | string);\n\n let connectionName: string | undefined;\n let retry: boolean | undefined;\n\n if (typeof options === \"string\") {\n connectionName = options;\n } else if (options) {\n connectionName = options.connectionName;\n retry = options.retry;\n }\n\n if (!connectionName) {\n connectionName = \"default\";\n }\n\n if (!retry) {\n retry = false;\n }\n\n return {connectionName, retry};\n }\n\n private async executeInTransaction(connectionName: string, next: InterceptorNext): Promise<unknown> {\n const em = this.context.get(connectionName);\n\n const result = await next();\n\n await em?.flush();\n\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"TransactionalInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/TransactionalInterceptor.ts"],"names":[],"mappings":";;;;AAAA,0CAAuE;AACvE,iCA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AW,EAAE,KAAK,EAAC,CAAC;IAC9B,CAAC;IAEO,KAAK,CAAC,oBAAoB,CAAC,WAAmB,EAAE,IAAqB;QAC3E,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAEzC,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAE5B,MAAM,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,KAAK,EAAE,CAAA,CAAC;QAElB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AApGY,wBAAwB;IADpC,IAAA,gBAAW,GAAE;IAGT,wBAAA,IAAA,WAAM,GAAE,CAAA;IACR,wBAAA,IAAA,WAAM,GAAE,CAAA;IACR,wBAAA,IAAA,WAAM,GAAE,CAAA;IACR,wBAAA,IAAA,WAAM,EAAC,wBAAa,CAAC,CAAA;kDAHe,2BAAgB;QACjB,oBAAS;QACV,eAAM;GAJhC,wBAAwB,CAoGpC;AApGY,4DAAwB","sourcesContent":["import {DBContext, MikroOrmRegistry, RetryStrategy} from \"../services\";\nimport {Inject, Interceptor, InterceptorContext, InterceptorMethods, InterceptorNext} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {Logger} from \"@tsed/logger\";\n\nexport interface TransactionOptions {\n retry?: boolean;\n contextName?: string;\n /**\n * @deprecated Since 2022-02-01. Use {@link contextName} instead\n */\n connectionName?: string;\n}\n\n@Interceptor()\nexport class TransactionalInterceptor implements InterceptorMethods {\n constructor(\n @Inject() private readonly registry: MikroOrmRegistry,\n @Inject() private readonly context: DBContext,\n @Inject() private readonly logger: Logger,\n @Inject(RetryStrategy)\n private readonly retryStrategy?: RetryStrategy\n ) {}\n\n public async intercept(context: InterceptorContext<unknown>, next: InterceptorNext): Promise<unknown> {\n const options = this.extractContextName(context);\n\n if (options.retry && !this.retryStrategy) {\n this.logger.warn(`To retry a transaction you have to implement a \"${RetryStrategy.description}\" interface`);\n }\n\n const ctx = this.context.entries();\n\n if (!ctx) {\n return this.runWithinNewCtx(next, options);\n }\n\n if (ctx.has(options.contextName!)) {\n return next();\n }\n\n return this.runUnderCtx(next, ctx, options);\n }\n\n private runWithinNewCtx(next: InterceptorNext, options: TransactionOptions): Promise<unknown> | unknown {\n const ctx = new Map<string, EntityManager>();\n\n return this.runUnderCtx(next, ctx, options);\n }\n\n private runUnderCtx(next: InterceptorNext, ctx: Map<string, EntityManager>, options: TransactionOptions): Promise<unknown> | unknown {\n const orm = this.registry.get(options.contextName);\n\n if (!orm) {\n throw new Error(\n `No such context: ${options.contextName}. Please register a corresponding MikroOrm instance using '@Configuration()' decorator.`\n );\n }\n\n /**\n * The fork method signature has been changed since v5.x,\n * which might lead to unexpected behavior while using the @Transactional() decorator.\n *\n * ```diff\n * - fork(clear = true, useContext = false): D[typeof EntityManagerType]\n * + fork(options: ForkOptions = {}): D[typeof EntityManagerType] {\n * ```\n *\n * To ensure backward compatibility with v4.x and add support for v5.x, provided the following workaround:\n */\n const em = (orm.em.fork as (\n clearOrForkOptions?: boolean | {clear?: boolean; useContext?: boolean},\n useContext?: boolean\n ) => EntityManager)({clear: true, useContext: true}, true);\n\n ctx.set(em.name, em);\n\n const runInTransaction = () => this.executeInTransaction(options.contextName!, next);\n\n return this.context.run(ctx, () => (options.retry ? this.retryStrategy?.acquire(runInTransaction) : runInTransaction()));\n }\n\n private extractContextName(context: InterceptorContext<unknown>): TransactionOptions {\n const options = context.options || ({} as Partial<TransactionOptions> | string);\n\n let contextName: string | undefined;\n let retry: boolean | undefined;\n\n if (typeof options === \"string\") {\n contextName = options;\n } else if (options) {\n contextName = options.contextName ?? options.connectionName;\n retry = options.retry;\n }\n\n if (!contextName) {\n contextName = \"default\";\n }\n\n if (!retry) {\n retry = false;\n }\n\n return {contextName, retry};\n }\n\n private async executeInTransaction(contextName: string, next: InterceptorNext): Promise<unknown> {\n const em = this.context.get(contextName);\n\n const result = await next();\n\n await em?.flush();\n\n return result;\n }\n}\n"]}
@@ -3,6 +3,10 @@ export declare class DBContext {
3
3
  private readonly storage;
4
4
  constructor();
5
5
  run<R>(ctx: Map<string, EntityManager>, callback: (...args: any[]) => R): R;
6
+ entries(): Map<string, EntityManager> | undefined;
7
+ /**
8
+ * @deprecated Since 2022-02-01. Use {@link entries} instead
9
+ */
6
10
  getContext(): Map<string, EntityManager> | undefined;
7
11
  get(contextName: string): EntityManager | undefined;
8
12
  has(contextName: string): boolean;
@@ -17,15 +17,21 @@ let DBContext = class DBContext {
17
17
  run(ctx, callback) {
18
18
  return this.storage.run(ctx, callback);
19
19
  }
20
- getContext() {
20
+ entries() {
21
21
  return this.storage.getStore();
22
22
  }
23
+ /**
24
+ * @deprecated Since 2022-02-01. Use {@link entries} instead
25
+ */
26
+ getContext() {
27
+ return this.entries();
28
+ }
23
29
  get(contextName) {
24
- const context = this.getContext();
30
+ const context = this.entries();
25
31
  return context === null || context === void 0 ? void 0 : context.get(contextName);
26
32
  }
27
33
  has(contextName) {
28
- const context = this.getContext();
34
+ const context = this.entries();
29
35
  return !!(context === null || context === void 0 ? void 0 : context.has(contextName));
30
36
  }
31
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"DBContext.js","sourceRoot":"","sources":["../../../src/services/DBContext.ts"],"names":[],"mappings":";;;;AAAA,iCAAoC;AAEpC,6CAA8C;AAG9C,IAAa,SAAS,GAAtB,MAAa,SAAS;IAGpB;QAFiB,YAAO,GAAG,IAAI,+BAAiB,EAA8B,CAAC;QAG7E,IAAI,+BAAiB,EAAE;YACrB,IAAI,CAAC,OAAO,GAAG,IAAI,+BAAiB,EAAE,CAAC;SACxC;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,gEAAgE,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;SAC5G;IACH,CAAC;IAEM,GAAG,CAAI,GAA+B,EAAE,QAA+B;QAC5E,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAEM,GAAG,CAAC,WAAmB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAElC,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IAEM,GAAG,CAAC,WAAmB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAElC,OAAO,CAAC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,WAAW,CAAC,CAAA,CAAC;IACrC,CAAC;CACF,CAAA;AA9BY,SAAS;IADrB,IAAA,eAAU,GAAE;;GACA,SAAS,CA8BrB;AA9BY,8BAAS","sourcesContent":["import {Injectable} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {AsyncLocalStorage} from \"async_hooks\";\n\n@Injectable()\nexport class DBContext {\n private readonly storage = new AsyncLocalStorage<Map<string, EntityManager>>();\n\n constructor() {\n if (AsyncLocalStorage) {\n this.storage = new AsyncLocalStorage();\n } else {\n throw new Error(`AsyncLocalStorage is not available for your Node.js version (${process.versions.node}).`);\n }\n }\n\n public run<R>(ctx: Map<string, EntityManager>, callback: (...args: any[]) => R): R {\n return this.storage.run(ctx, callback);\n }\n\n public getContext(): Map<string, EntityManager> | undefined {\n return this.storage.getStore();\n }\n\n public get(contextName: string): EntityManager | undefined {\n const context = this.getContext();\n\n return context?.get(contextName);\n }\n\n public has(contextName: string): boolean {\n const context = this.getContext();\n\n return !!context?.has(contextName);\n }\n}\n"]}
1
+ {"version":3,"file":"DBContext.js","sourceRoot":"","sources":["../../../src/services/DBContext.ts"],"names":[],"mappings":";;;;AAAA,iCAAoC;AAEpC,6CAA8C;AAG9C,IAAa,SAAS,GAAtB,MAAa,SAAS;IAGpB;QAFiB,YAAO,GAAG,IAAI,+BAAiB,EAA8B,CAAC;QAG7E,IAAI,+BAAiB,EAAE;YACrB,IAAI,CAAC,OAAO,GAAG,IAAI,+BAAiB,EAAE,CAAC;SACxC;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,gEAAgE,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;SAC5G;IACH,CAAC;IAEM,GAAG,CAAI,GAA+B,EAAE,QAA+B;QAC5E,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAEM,GAAG,CAAC,WAAmB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAE/B,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IAEM,GAAG,CAAC,WAAmB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAE/B,OAAO,CAAC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,WAAW,CAAC,CAAA,CAAC;IACrC,CAAC;CACF,CAAA;AArCY,SAAS;IADrB,IAAA,eAAU,GAAE;;GACA,SAAS,CAqCrB;AArCY,8BAAS","sourcesContent":["import {Injectable} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {AsyncLocalStorage} from \"async_hooks\";\n\n@Injectable()\nexport class DBContext {\n private readonly storage = new AsyncLocalStorage<Map<string, EntityManager>>();\n\n constructor() {\n if (AsyncLocalStorage) {\n this.storage = new AsyncLocalStorage();\n } else {\n throw new Error(`AsyncLocalStorage is not available for your Node.js version (${process.versions.node}).`);\n }\n }\n\n public run<R>(ctx: Map<string, EntityManager>, callback: (...args: any[]) => R): R {\n return this.storage.run(ctx, callback);\n }\n\n public entries(): Map<string, EntityManager> | undefined {\n return this.storage.getStore();\n }\n\n /**\n * @deprecated Since 2022-02-01. Use {@link entries} instead\n */\n public getContext(): Map<string, EntityManager> | undefined {\n return this.entries();\n }\n\n public get(contextName: string): EntityManager | undefined {\n const context = this.entries();\n\n return context?.get(contextName);\n }\n\n public has(contextName: string): boolean {\n const context = this.entries();\n\n return !!context?.has(contextName);\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { MikroORM, Options } from "@mikro-orm/core";
2
2
  export declare class MikroOrmFactory {
3
3
  private readonly dbContext;
4
- create(connectionOptions: Options): Promise<MikroORM>;
4
+ create(options: Options): Promise<MikroORM>;
5
5
  }
@@ -6,9 +6,9 @@ const DBContext_1 = require("./DBContext");
6
6
  const core_1 = require("@mikro-orm/core");
7
7
  const di_1 = require("@tsed/di");
8
8
  let MikroOrmFactory = class MikroOrmFactory {
9
- create(connectionOptions) {
9
+ create(options) {
10
10
  return core_1.MikroORM.init({
11
- ...connectionOptions,
11
+ ...options,
12
12
  context: (name) => this.dbContext.get(name)
13
13
  });
14
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MikroOrmFactory.js","sourceRoot":"","sources":["../../../src/services/MikroOrmFactory.ts"],"names":[],"mappings":";;;;AAAA,2CAAsC;AACtC,0CAAkD;AAClD,iCAA4C;AAG5C,IAAa,eAAe,GAA5B,MAAa,eAAe;IAInB,MAAM,CAAC,iBAA0B;QACtC,OAAO,eAAQ,CAAC,IAAI,CAAC;YACnB,GAAG,iBAAiB;YACpB,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AARC;IADC,IAAA,WAAM,GAAE;2CACoB,qBAAS;kDAAC;AAF5B,eAAe;IAD3B,IAAA,eAAU,GAAE;GACA,eAAe,CAU3B;AAVY,0CAAe","sourcesContent":["import {DBContext} from \"./DBContext\";\nimport {MikroORM, Options} from \"@mikro-orm/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\n\n@Injectable()\nexport class MikroOrmFactory {\n @Inject()\n private readonly dbContext!: DBContext;\n\n public create(connectionOptions: Options): Promise<MikroORM> {\n return MikroORM.init({\n ...connectionOptions,\n context: (name: string) => this.dbContext.get(name)\n });\n }\n}\n"]}
1
+ {"version":3,"file":"MikroOrmFactory.js","sourceRoot":"","sources":["../../../src/services/MikroOrmFactory.ts"],"names":[],"mappings":";;;;AAAA,2CAAsC;AACtC,0CAAkD;AAClD,iCAA4C;AAG5C,IAAa,eAAe,GAA5B,MAAa,eAAe;IAInB,MAAM,CAAC,OAAgB;QAC5B,OAAO,eAAQ,CAAC,IAAI,CAAC;YACnB,GAAG,OAAO;YACV,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AARC;IADC,IAAA,WAAM,GAAE;2CACoB,qBAAS;kDAAC;AAF5B,eAAe;IAD3B,IAAA,eAAU,GAAE;GACA,eAAe,CAU3B;AAVY,0CAAe","sourcesContent":["import {DBContext} from \"./DBContext\";\nimport {MikroORM, Options} from \"@mikro-orm/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\n\n@Injectable()\nexport class MikroOrmFactory {\n @Inject()\n private readonly dbContext!: DBContext;\n\n public create(options: Options): Promise<MikroORM> {\n return MikroORM.init({\n ...options,\n context: (name: string) => this.dbContext.get(name)\n });\n }\n}\n"]}
@@ -4,11 +4,19 @@ import { Logger } from "@tsed/logger";
4
4
  export declare class MikroOrmRegistry {
5
5
  private readonly logger;
6
6
  private readonly mikroOrmFactory;
7
- private readonly connections;
7
+ private readonly instances;
8
8
  constructor(logger: Logger, mikroOrmFactory: MikroOrmFactory);
9
- createConnection<T extends DatabaseDriver>(connectionOptions: Options<T>): Promise<MikroORM>;
10
- get(id?: string): MikroORM;
11
- has(id?: string): boolean;
9
+ register<T extends DatabaseDriver>(options: Options<T>): Promise<MikroORM>;
10
+ /**
11
+ * @deprecated Since 2022-02-01. Use {@link register} instead
12
+ */
13
+ createConnection<T extends DatabaseDriver>(options: Options<T>): Promise<MikroORM>;
14
+ get(contextName?: string): MikroORM | undefined;
15
+ has(contextName?: string): boolean;
16
+ clear(): Promise<void>;
17
+ /**
18
+ * @deprecated Since 2022-02-01. Use {@link clear} instead
19
+ */
12
20
  closeConnections(): Promise<void>;
13
21
  private dispose;
14
22
  }
@@ -10,35 +10,46 @@ let MikroOrmRegistry = class MikroOrmRegistry {
10
10
  constructor(logger, mikroOrmFactory) {
11
11
  this.logger = logger;
12
12
  this.mikroOrmFactory = mikroOrmFactory;
13
- this.connections = new Map();
13
+ this.instances = new Map();
14
14
  }
15
- async createConnection(connectionOptions) {
16
- const connectionName = (0, core_1.getValue)(connectionOptions, "contextName", "default");
17
- if (this.has(connectionName)) {
18
- return this.get(connectionName);
15
+ async register(options) {
16
+ const contextName = (0, core_1.getValue)(options, "contextName", "default");
17
+ if (this.has(contextName)) {
18
+ return this.get(contextName);
19
19
  }
20
- this.logger.info(`Create connection with MikroOrm to database: %s`, connectionName);
21
- this.logger.debug(`options: %j`, connectionOptions);
22
- const connection = await this.mikroOrmFactory.create(connectionOptions);
23
- this.connections.set(connectionName, connection);
24
- this.logger.info(`Connected with MikroOrm to database: %s`, connectionName);
25
- return connection;
26
- }
27
- get(id = "default") {
28
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
29
- return this.connections.get(id);
30
- }
31
- has(id = "default") {
32
- return this.connections.has(id);
33
- }
34
- async closeConnections() {
35
- const connections = [...this.connections.values()];
36
- await Promise.all(connections.map((connection) => (0, core_1.catchAsyncError)(() => this.dispose(connection))));
37
- this.connections.clear();
38
- }
39
- async dispose(connection) {
40
- if (await connection.isConnected()) {
41
- await connection.close(false);
20
+ this.logger.info(`Create connection with MikroOrm to database: %s`, contextName);
21
+ this.logger.debug(`options: %j`, options);
22
+ const instance = await this.mikroOrmFactory.create(options);
23
+ this.instances.set(contextName, instance);
24
+ this.logger.info(`Connected with MikroOrm to database: %s`, contextName);
25
+ return instance;
26
+ }
27
+ /**
28
+ * @deprecated Since 2022-02-01. Use {@link register} instead
29
+ */
30
+ createConnection(options) {
31
+ return this.register(options);
32
+ }
33
+ get(contextName = "default") {
34
+ return this.instances.get(contextName);
35
+ }
36
+ has(contextName = "default") {
37
+ return this.instances.has(contextName);
38
+ }
39
+ async clear() {
40
+ const instances = [...this.instances.values()];
41
+ await Promise.all(instances.map((instance) => (0, core_1.catchAsyncError)(() => this.dispose(instance))));
42
+ this.instances.clear();
43
+ }
44
+ /**
45
+ * @deprecated Since 2022-02-01. Use {@link clear} instead
46
+ */
47
+ closeConnections() {
48
+ return this.clear();
49
+ }
50
+ async dispose(instance) {
51
+ if (await instance.isConnected()) {
52
+ await instance.close(false);
42
53
  }
43
54
  }
44
55
  };
@@ -1 +1 @@
1
- {"version":3,"file":"MikroOrmRegistry.js","sourceRoot":"","sources":["../../../src/services/MikroOrmRegistry.ts"],"names":[],"mappings":";;;;AAAA,uDAAkD;AAClD,iCAA4C;AAE5C,qCAAqD;AACrD,yCAAoC;AAGpC,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAG3B,YAAuC,MAAc,EAA6B,eAAgC;QAA3E,WAAM,GAAN,MAAM,CAAQ;QAA6B,oBAAe,GAAf,eAAe,CAAiB;QAFjG,gBAAW,GAAG,IAAI,GAAG,EAAoB,CAAC;IAE0D,CAAC;IAE/G,KAAK,CAAC,gBAAgB,CAA2B,iBAA6B;QACnF,MAAM,cAAc,GAAG,IAAA,eAAQ,EAAS,iBAAiB,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QAErF,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;YAC5B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CACF,CAAA;AA9CY,gBAAgB;IAD5B,IAAA,eAAU,GAAE;IAIE,wBAAA,IAAA,WAAM,GAAE,CAAA;IAAmC,wBAAA,IAAA,WAAM,GAAE,CAAA;kDAAjB,eAAM,EAA8C,iCAAe;GAHvG,gBAAgB,CA8C5B;AA9CY,4CAAgB","sourcesContent":["import {MikroOrmFactory} from \"./MikroOrmFactory\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {IDatabaseDriver as DatabaseDriver, MikroORM, Options} from \"@mikro-orm/core\";\nimport {catchAsyncError, getValue} from \"@tsed/core\";\nimport {Logger} from \"@tsed/logger\";\n\n@Injectable()\nexport class MikroOrmRegistry {\n private readonly connections = new Map<string, MikroORM>();\n\n constructor(@Inject() private readonly logger: Logger, @Inject() private readonly mikroOrmFactory: MikroOrmFactory) {}\n\n public async createConnection<T extends DatabaseDriver>(connectionOptions: Options<T>): Promise<MikroORM> {\n const connectionName = getValue<string>(connectionOptions, \"contextName\", \"default\");\n\n if (this.has(connectionName)) {\n return this.get(connectionName);\n }\n\n this.logger.info(`Create connection with MikroOrm to database: %s`, connectionName);\n this.logger.debug(`options: %j`, connectionOptions);\n\n const connection = await this.mikroOrmFactory.create(connectionOptions);\n\n this.connections.set(connectionName, connection);\n\n this.logger.info(`Connected with MikroOrm to database: %s`, connectionName);\n\n return connection;\n }\n\n public get(id: string = \"default\"): MikroORM {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.connections.get(id)!;\n }\n\n public has(id: string = \"default\"): boolean {\n return this.connections.has(id);\n }\n\n public async closeConnections(): Promise<void> {\n const connections = [...this.connections.values()];\n\n await Promise.all(connections.map((connection: MikroORM) => catchAsyncError(() => this.dispose(connection))));\n\n this.connections.clear();\n }\n\n private async dispose(connection: MikroORM): Promise<void> {\n if (await connection.isConnected()) {\n await connection.close(false);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"MikroOrmRegistry.js","sourceRoot":"","sources":["../../../src/services/MikroOrmRegistry.ts"],"names":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,WAAW,CAAC,CAAC;IACzC,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;QAE/C,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAkB,EAAE,EAAE,CAAC,IAAA,sBAAe,EAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAExG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,gBAAgB;QACrB,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,QAAkB;QACtC,IAAI,MAAM,QAAQ,CAAC,WAAW,EAAE,EAAE;YAChC,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SAC7B;IACH,CAAC;CACF,CAAA;AA3DY,gBAAgB;IAD5B,IAAA,eAAU,GAAE;IAIE,wBAAA,IAAA,WAAM,GAAE,CAAA;IAAmC,wBAAA,IAAA,WAAM,GAAE,CAAA;kDAAjB,eAAM,EAA8C,iCAAe;GAHvG,gBAAgB,CA2D5B;AA3DY,4CAAgB","sourcesContent":["import {MikroOrmFactory} from \"./MikroOrmFactory\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {IDatabaseDriver as DatabaseDriver, MikroORM, Options} from \"@mikro-orm/core\";\nimport {catchAsyncError, getValue} from \"@tsed/core\";\nimport {Logger} from \"@tsed/logger\";\n\n@Injectable()\nexport class MikroOrmRegistry {\n private readonly instances = new Map<string, MikroORM>();\n\n constructor(@Inject() private readonly logger: Logger, @Inject() private readonly mikroOrmFactory: MikroOrmFactory) {}\n\n public async register<T extends DatabaseDriver>(options: Options<T>): Promise<MikroORM> {\n const contextName = getValue<string>(options, \"contextName\", \"default\");\n\n if (this.has(contextName)) {\n return this.get(contextName)!;\n }\n\n this.logger.info(`Create connection with MikroOrm to database: %s`, contextName);\n this.logger.debug(`options: %j`, options);\n\n const instance = await this.mikroOrmFactory.create(options);\n\n this.instances.set(contextName, instance);\n\n this.logger.info(`Connected with MikroOrm to database: %s`, contextName);\n\n return instance;\n }\n\n /**\n * @deprecated Since 2022-02-01. Use {@link register} instead\n */\n public createConnection<T extends DatabaseDriver>(options: Options<T>): Promise<MikroORM> {\n return this.register(options);\n }\n\n public get(contextName: string = \"default\"): MikroORM | undefined {\n return this.instances.get(contextName);\n }\n\n public has(contextName: string = \"default\"): boolean {\n return this.instances.has(contextName);\n }\n\n public async clear(): Promise<void> {\n const instances = [...this.instances.values()];\n\n await Promise.all(instances.map((instance: MikroORM) => catchAsyncError(() => this.dispose(instance))));\n\n this.instances.clear();\n }\n\n /**\n * @deprecated Since 2022-02-01. Use {@link clear} instead\n */\n public closeConnections(): Promise<void> {\n return this.clear();\n }\n\n private async dispose(instance: MikroORM): Promise<void> {\n if (await instance.isConnected()) {\n await instance.close(false);\n }\n }\n}\n"]}
@@ -3,11 +3,11 @@ import { DBContext, MikroOrmRegistry, RetryStrategy } from "./services";
3
3
  import { Configuration, Constant, Inject, Module, registerProvider } from "@tsed/di";
4
4
  let MikroOrmModule = class MikroOrmModule {
5
5
  async $onInit() {
6
- const promises = this.settings.map((opts) => this.mikroOrmRegistry.createConnection(opts));
6
+ const promises = this.settings.map((opts) => this.mikroOrmRegistry.register(opts));
7
7
  await Promise.all(promises);
8
8
  }
9
9
  $onDestroy() {
10
- return this.mikroOrmRegistry.closeConnections();
10
+ return this.mikroOrmRegistry.clear();
11
11
  }
12
12
  };
13
13
  __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"MikroOrmModule.js","sourceRoot":"","sources":["../../src/MikroOrmModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACtE,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAqB,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAoBtG,IAAa,cAAc,GAA3B,MAAa,cAAc;IAOlB,KAAK,CAAC,OAAO;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3F,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,CAAC;IAClD,CAAC;CACF,CAAA;AAdC;IADC,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC;;gDACa;AAGtC;IADC,MAAM,EAAE;8BAC2B,gBAAgB;wDAAC;AAL1C,cAAc;IAJ1B,MAAM,CAAC;QACN,OAAO,EAAE,CAAC,SAAS,EAAE,gBAAgB,CAAC;QACtC,IAAI,EAAE,CAAC,aAAa,EAAE,gBAAgB,CAAC;KACxC,CAAC;GACW,cAAc,CAgB1B;SAhBY,cAAc;AAkB3B,uGAAuG;AACvG,gBAAgB,CAAC,EAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC","sourcesContent":["import {DBContext, MikroOrmRegistry, RetryStrategy} from \"./services\";\nimport {Configuration, Constant, Inject, Module, OnDestroy, OnInit, registerProvider} from \"@tsed/di\";\nimport {Options} from \"@mikro-orm/core\";\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace TsED {\n interface Configuration {\n /**\n * The the ORM configuration, entity metadata.\n * If you omit the `options` parameter, your CLI config will be used.\n */\n mikroOrm?: Options[];\n }\n }\n}\n\n@Module({\n imports: [DBContext, MikroOrmRegistry],\n deps: [Configuration, MikroOrmRegistry]\n})\nexport class MikroOrmModule implements OnDestroy, OnInit {\n @Constant(\"mikroOrm\", [])\n private readonly settings!: Options[];\n\n @Inject()\n private readonly mikroOrmRegistry!: MikroOrmRegistry;\n\n public async $onInit(): Promise<void> {\n const promises = this.settings.map((opts) => this.mikroOrmRegistry.createConnection(opts));\n\n await Promise.all(promises);\n }\n\n public $onDestroy(): Promise<void> {\n return this.mikroOrmRegistry.closeConnections();\n }\n}\n\n// TODO: the IoC container should provide null or undefined by default until tsedio/tsed#1694 is closed\nregisterProvider({provide: RetryStrategy, useValue: null});\n"]}
1
+ {"version":3,"file":"MikroOrmModule.js","sourceRoot":"","sources":["../../src/MikroOrmModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACtE,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAqB,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAoBtG,IAAa,cAAc,GAA3B,MAAa,cAAc;IAOlB,KAAK,CAAC,OAAO;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAEnF,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IACvC,CAAC;CACF,CAAA;AAdC;IADC,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC;;gDACa;AAGtC;IADC,MAAM,EAAE;8BAC2B,gBAAgB;wDAAC;AAL1C,cAAc;IAJ1B,MAAM,CAAC;QACN,OAAO,EAAE,CAAC,SAAS,EAAE,gBAAgB,CAAC;QACtC,IAAI,EAAE,CAAC,aAAa,EAAE,gBAAgB,CAAC;KACxC,CAAC;GACW,cAAc,CAgB1B;SAhBY,cAAc;AAkB3B,uGAAuG;AACvG,gBAAgB,CAAC,EAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC","sourcesContent":["import {DBContext, MikroOrmRegistry, RetryStrategy} from \"./services\";\nimport {Configuration, Constant, Inject, Module, OnDestroy, OnInit, registerProvider} from \"@tsed/di\";\nimport {Options} from \"@mikro-orm/core\";\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace TsED {\n interface Configuration {\n /**\n * The the ORM configuration, entity metadata.\n * If you omit the `options` parameter, your CLI config will be used.\n */\n mikroOrm?: Options[];\n }\n }\n}\n\n@Module({\n imports: [DBContext, MikroOrmRegistry],\n deps: [Configuration, MikroOrmRegistry]\n})\nexport class MikroOrmModule implements OnDestroy, OnInit {\n @Constant(\"mikroOrm\", [])\n private readonly settings!: Options[];\n\n @Inject()\n private readonly mikroOrmRegistry!: MikroOrmRegistry;\n\n public async $onInit(): Promise<void> {\n const promises = this.settings.map((opts) => this.mikroOrmRegistry.register(opts));\n\n await Promise.all(promises);\n }\n\n public $onDestroy(): Promise<void> {\n return this.mikroOrmRegistry.clear();\n }\n}\n\n// TODO: the IoC container should provide null or undefined by default until tsedio/tsed#1694 is closed\nregisterProvider({provide: RetryStrategy, useValue: null});\n"]}
@@ -1,15 +1,15 @@
1
1
  import { Inject } from "@tsed/di";
2
2
  import { MikroOrmRegistry } from "../services";
3
3
  /**
4
- * Get the entity manager for the given connection name.
5
- * @param connectionName
4
+ * Get the entity manager for the given context name.
5
+ * @param {String} contextName
6
6
  * @decorator
7
7
  * @mikroOrm
8
8
  */
9
- export const EntityManager = (connectionName) => Inject(MikroOrmRegistry, (registry) => { var _a; return (_a = registry.get(connectionName)) === null || _a === void 0 ? void 0 : _a.em; });
9
+ export const EntityManager = (contextName) => Inject(MikroOrmRegistry, (registry) => { var _a; return (_a = registry.get(contextName)) === null || _a === void 0 ? void 0 : _a.em; });
10
10
  /**
11
- * Get the entity manager for the given connection name.
12
- * @param connectionName
11
+ * Get the entity manager for the given context name.
12
+ * @param {String} connectionName
13
13
  * @decorator
14
14
  * @mikroOrm
15
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"entityManager.js","sourceRoot":"","sources":["../../../src/decorators/entityManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,cAAuB,EAAqB,EAAE,CAC1E,MAAM,CAAC,gBAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,WAAC,OAAA,MAAA,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAsB,CAAC;AAElH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC","sourcesContent":["import {Inject} from \"@tsed/di\";\nimport {MikroOrmRegistry} from \"../services\";\n\n/**\n * Get the entity manager for the given connection name.\n * @param connectionName\n * @decorator\n * @mikroOrm\n */\nexport const EntityManager = (connectionName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(connectionName)?.em) as PropertyDecorator;\n\n/**\n * Get the entity manager for the given connection name.\n * @param connectionName\n * @decorator\n * @mikroOrm\n */\nexport const Em = EntityManager;\n"]}
1
+ {"version":3,"file":"entityManager.js","sourceRoot":"","sources":["../../../src/decorators/entityManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,WAAoB,EAAqB,EAAE,CACvE,MAAM,CAAC,gBAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,WAAC,OAAA,MAAA,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,0CAAE,EAAE,CAAA,EAAA,CAAsB,CAAC;AAE/G;;;;;GAKG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC","sourcesContent":["import {Inject} from \"@tsed/di\";\nimport {MikroOrmRegistry} from \"../services\";\n\n/**\n * Get the entity manager for the given context name.\n * @param {String} contextName\n * @decorator\n * @mikroOrm\n */\nexport const EntityManager = (contextName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(contextName)?.em) as PropertyDecorator;\n\n/**\n * Get the entity manager for the given context name.\n * @param {String} connectionName\n * @decorator\n * @mikroOrm\n */\nexport const Em = EntityManager;\n"]}
@@ -1,8 +1,14 @@
1
1
  import { MikroOrmRegistry } from "../services";
2
2
  import { Inject } from "@tsed/di";
3
3
  /**
4
- * @deprecated Since 2022-02-01. Use {@link Orm} instead
4
+ * Get the ORM for the given context name.
5
+ * @param {String} contextName
5
6
  */
6
- export const Connection = (contextName) => Orm(contextName);
7
7
  export const Orm = (contextName) => Inject(MikroOrmRegistry, (registry) => registry.get(contextName));
8
+ /**
9
+ * Get the ORM for the given context name.
10
+ * @param {String} contextName
11
+ * @deprecated Since 2022-02-01. Use {@link Orm} instead
12
+ */
13
+ export const Connection = Orm;
8
14
  //# sourceMappingURL=orm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAExF,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAC7D,MAAM,CAAC,gBAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAsB,CAAC","sourcesContent":["import {MikroOrmRegistry} from \"../services\";\nimport {Inject} from \"@tsed/di\";\n\n/**\n * @deprecated Since 2022-02-01. Use {@link Orm} instead\n */\nexport const Connection = (contextName?: string): PropertyDecorator => Orm(contextName);\n\nexport const Orm = (contextName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(contextName)) as PropertyDecorator;\n"]}
1
+ {"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC;;;GAGG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAC7D,MAAM,CAAC,gBAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAsB,CAAC;AAE3G;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC","sourcesContent":["import {MikroOrmRegistry} from \"../services\";\nimport {Inject} from \"@tsed/di\";\n\n/**\n * Get the ORM for the given context name.\n * @param {String} contextName\n */\nexport const Orm = (contextName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(contextName)) as PropertyDecorator;\n\n/**\n * Get the ORM for the given context name.\n * @param {String} contextName\n * @deprecated Since 2022-02-01. Use {@link Orm} instead\n */\nexport const Connection = Orm;\n"]}
@@ -1,4 +1,8 @@
1
1
  import { TransactionalInterceptor } from "../interceptors";
2
2
  import { Intercept } from "@tsed/di";
3
- export const Transactional = (connectionOrOptions) => Intercept(TransactionalInterceptor, connectionOrOptions);
3
+ /**
4
+ * Register a new request context for your method and execute it inside the context.
5
+ * @param {String | TransactionOptions} contextNameOrOptions
6
+ */
7
+ export const Transactional = (contextNameOrOptions) => Intercept(TransactionalInterceptor, contextNameOrOptions);
4
8
  //# sourceMappingURL=transactional.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transactional.js","sourceRoot":"","sources":["../../../src/decorators/transactional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,wBAAwB,EAAqB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,mBAAiD,EAAmB,EAAE,CAClG,SAAS,CAAC,wBAAwB,EAAE,mBAAmB,CAAC,CAAC","sourcesContent":["import {TransactionalInterceptor, TransactionOptions} from \"../interceptors\";\nimport {Intercept} from \"@tsed/di\";\n\nexport const Transactional = (connectionOrOptions?: string | TransactionOptions): MethodDecorator =>\n Intercept(TransactionalInterceptor, connectionOrOptions);\n"]}
1
+ {"version":3,"file":"transactional.js","sourceRoot":"","sources":["../../../src/decorators/transactional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,wBAAwB,EAAqB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,oBAAkD,EAAmB,EAAE,CACnG,SAAS,CAAC,wBAAwB,EAAE,oBAAoB,CAAC,CAAC","sourcesContent":["import {TransactionalInterceptor, TransactionOptions} from \"../interceptors\";\nimport {Intercept} from \"@tsed/di\";\n\n/**\n * Register a new request context for your method and execute it inside the context.\n * @param {String | TransactionOptions} contextNameOrOptions\n */\nexport const Transactional = (contextNameOrOptions?: string | TransactionOptions): MethodDecorator =>\n Intercept(TransactionalInterceptor, contextNameOrOptions);\n"]}
@@ -14,11 +14,11 @@ let TransactionalInterceptor = class TransactionalInterceptor {
14
14
  if (options.retry && !this.retryStrategy) {
15
15
  this.logger.warn(`To retry a transaction you have to implement a "${RetryStrategy.description}" interface`);
16
16
  }
17
- const ctx = this.context.getContext();
17
+ const ctx = this.context.entries();
18
18
  if (!ctx) {
19
19
  return this.runWithinNewCtx(next, options);
20
20
  }
21
- if (ctx.has(options.connectionName)) {
21
+ if (ctx.has(options.contextName)) {
22
22
  return next();
23
23
  }
24
24
  return this.runUnderCtx(next, ctx, options);
@@ -28,33 +28,48 @@ let TransactionalInterceptor = class TransactionalInterceptor {
28
28
  return this.runUnderCtx(next, ctx, options);
29
29
  }
30
30
  runUnderCtx(next, ctx, options) {
31
- const orm = this.registry.get(options.connectionName);
32
- const em = orm.em.fork(true, true);
31
+ const orm = this.registry.get(options.contextName);
32
+ if (!orm) {
33
+ throw new Error(`No such context: ${options.contextName}. Please register a corresponding MikroOrm instance using '@Configuration()' decorator.`);
34
+ }
35
+ /**
36
+ * The fork method signature has been changed since v5.x,
37
+ * which might lead to unexpected behavior while using the @Transactional() decorator.
38
+ *
39
+ * ```diff
40
+ * - fork(clear = true, useContext = false): D[typeof EntityManagerType]
41
+ * + fork(options: ForkOptions = {}): D[typeof EntityManagerType] {
42
+ * ```
43
+ *
44
+ * To ensure backward compatibility with v4.x and add support for v5.x, provided the following workaround:
45
+ */
46
+ const em = orm.em.fork({ clear: true, useContext: true }, true);
33
47
  ctx.set(em.name, em);
34
- const runInTransaction = () => this.executeInTransaction(options.connectionName, next);
48
+ const runInTransaction = () => this.executeInTransaction(options.contextName, next);
35
49
  return this.context.run(ctx, () => { var _a; return (options.retry ? (_a = this.retryStrategy) === null || _a === void 0 ? void 0 : _a.acquire(runInTransaction) : runInTransaction()); });
36
50
  }
37
51
  extractContextName(context) {
52
+ var _a;
38
53
  const options = context.options || {};
39
- let connectionName;
54
+ let contextName;
40
55
  let retry;
41
56
  if (typeof options === "string") {
42
- connectionName = options;
57
+ contextName = options;
43
58
  }
44
59
  else if (options) {
45
- connectionName = options.connectionName;
60
+ contextName = (_a = options.contextName) !== null && _a !== void 0 ? _a : options.connectionName;
46
61
  retry = options.retry;
47
62
  }
48
- if (!connectionName) {
49
- connectionName = "default";
63
+ if (!contextName) {
64
+ contextName = "default";
50
65
  }
51
66
  if (!retry) {
52
67
  retry = false;
53
68
  }
54
- return { connectionName, retry };
69
+ return { contextName, retry };
55
70
  }
56
- async executeInTransaction(connectionName, next) {
57
- const em = this.context.get(connectionName);
71
+ async executeInTransaction(contextName, next) {
72
+ const em = this.context.get(contextName);
58
73
  const result = await next();
59
74
  await (em === null || em === void 0 ? void 0 : em.flush());
60
75
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"TransactionalInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/TransactionalInterceptor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,gBAAgB,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AACvE,OAAO,EAAC,MAAM,EAAE,WAAW,EAA0D,MAAM,UAAU,CAAC;AAEtG,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAQpC,IAAa,wBAAwB,GAArC,MAAa,wBAAwB;IACnC,YAC6B,QAA0B,EAC1B,OAAkB,EAClB,MAAc,EAExB,aAA6B;QAJnB,aAAQ,GAAR,QAAQ,CAAkB;QAC1B,YAAO,GAAP,OAAO,CAAW;QAClB,WAAM,GAAN,MAAM,CAAQ;QAExB,kBAAa,GAAb,aAAa,CAAgB;IAC7C,CAAC;IAEG,KAAK,CAAC,SAAS,CAAC,OAAoC,EAAE,IAAqB;QAChF,MAAM,OAAO,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEjD,IAAI,OAAO,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mDAAmD,aAAa,CAAC,WAAW,aAAa,CAAC,CAAC;SAC7G;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QAEtC,IAAI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QAEhF,IAAI,cAAkC,CAAC;QACvC,IAAI,KAA0B,CAAC;QAE/B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,cAAc,GAAG,OAAO,CAAC;SAC1B;aAAM,IAAI,OAAO,EAAE;YAClB,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;YACxC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;SACvB;QAED,IAAI,CAAC,cAAc,EAAE;YACnB,cAAc,GAAG,SAAS,CAAC;SAC5B;QAED,IAAI,CAAC,KAAK,EAAE;YACV,KAAK,GAAG,KAAK,CAAC;SACf;QAED,OAAO,EAAC,cAAc,EAAE,KAAK,EAAC,CAAC;IACjC,CAAC;IAEO,KAAK,CAAC,oBAAoB,CAAC,cAAsB,EAAE,IAAqB;QAC9E,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAE5C,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAE5B,MAAM,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,KAAK,EAAE,CAAA,CAAC;QAElB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AA/EY,wBAAwB;IADpC,WAAW,EAAE;IAGT,WAAA,MAAM,EAAE,CAAA;IACR,WAAA,MAAM,EAAE,CAAA;IACR,WAAA,MAAM,EAAE,CAAA;IACR,WAAA,MAAM,CAAC,aAAa,CAAC,CAAA;qCAHe,gBAAgB;QACjB,SAAS;QACV,MAAM;GAJhC,wBAAwB,CA+EpC;SA/EY,wBAAwB","sourcesContent":["import {DBContext, MikroOrmRegistry, RetryStrategy} from \"../services\";\nimport {Inject, Interceptor, InterceptorContext, InterceptorMethods, InterceptorNext} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {Logger} from \"@tsed/logger\";\n\nexport interface TransactionOptions {\n connectionName?: string;\n retry?: boolean;\n}\n\n@Interceptor()\nexport class TransactionalInterceptor implements InterceptorMethods {\n constructor(\n @Inject() private readonly registry: MikroOrmRegistry,\n @Inject() private readonly context: DBContext,\n @Inject() private readonly logger: Logger,\n @Inject(RetryStrategy)\n private readonly retryStrategy?: RetryStrategy\n ) {}\n\n public async intercept(context: InterceptorContext<unknown>, next: InterceptorNext): Promise<unknown> {\n const options = this.extractContextName(context);\n\n if (options.retry && !this.retryStrategy) {\n this.logger.warn(`To retry a transaction you have to implement a \"${RetryStrategy.description}\" interface`);\n }\n\n const ctx = this.context.getContext();\n\n if (!ctx) {\n return this.runWithinNewCtx(next, options);\n }\n\n if (ctx.has(options.connectionName!)) {\n return next();\n }\n\n return this.runUnderCtx(next, ctx, options);\n }\n\n private runWithinNewCtx(next: InterceptorNext, options: TransactionOptions): Promise<unknown> | unknown {\n const ctx = new Map<string, EntityManager>();\n\n return this.runUnderCtx(next, ctx, options);\n }\n\n private runUnderCtx(next: InterceptorNext, ctx: Map<string, EntityManager>, options: TransactionOptions): Promise<unknown> | unknown {\n const orm = this.registry.get(options.connectionName);\n const em = orm.em.fork(true, true);\n\n ctx.set(em.name, em);\n\n const runInTransaction = () => this.executeInTransaction(options.connectionName!, next);\n\n return this.context.run(ctx, () => (options.retry ? this.retryStrategy?.acquire(runInTransaction) : runInTransaction()));\n }\n\n private extractContextName(context: InterceptorContext<unknown>): TransactionOptions {\n const options = context.options || ({} as Partial<TransactionOptions> | string);\n\n let connectionName: string | undefined;\n let retry: boolean | undefined;\n\n if (typeof options === \"string\") {\n connectionName = options;\n } else if (options) {\n connectionName = options.connectionName;\n retry = options.retry;\n }\n\n if (!connectionName) {\n connectionName = \"default\";\n }\n\n if (!retry) {\n retry = false;\n }\n\n return {connectionName, retry};\n }\n\n private async executeInTransaction(connectionName: string, next: InterceptorNext): Promise<unknown> {\n const em = this.context.get(connectionName);\n\n const result = await next();\n\n await em?.flush();\n\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"TransactionalInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/Transactional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KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;SACvB;QAED,IAAI,CAAC,WAAW,EAAE;YAChB,WAAW,GAAG,SAAS,CAAC;SACzB;QAED,IAAI,CAAC,KAAK,EAAE;YACV,KAAK,GAAG,KAAK,CAAC;SACf;QAED,OAAO,EAAC,WAAW,EAAE,KAAK,EAAC,CAAC;IAC9B,CAAC;IAEO,KAAK,CAAC,oBAAoB,CAAC,WAAmB,EAAE,IAAqB;QAC3E,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAEzC,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAE5B,MAAM,CAAA,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,KAAK,EAAE,CAAA,CAAC;QAElB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AApGY,wBAAwB;IADpC,WAAW,EAAE;IAGT,WAAA,MAAM,EAAE,CAAA;IACR,WAAA,MAAM,EAAE,CAAA;IACR,WAAA,MAAM,EAAE,CAAA;IACR,WAAA,MAAM,CAAC,aAAa,CAAC,CAAA;qCAHe,gBAAgB;QACjB,SAAS;QACV,MAAM;GAJhC,wBAAwB,CAoGpC;SApGY,wBAAwB","sourcesContent":["import {DBContext, MikroOrmRegistry, RetryStrategy} from \"../services\";\nimport {Inject, Interceptor, InterceptorContext, InterceptorMethods, InterceptorNext} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {Logger} from \"@tsed/logger\";\n\nexport interface TransactionOptions {\n retry?: boolean;\n contextName?: string;\n /**\n * @deprecated Since 2022-02-01. Use {@link contextName} instead\n */\n connectionName?: string;\n}\n\n@Interceptor()\nexport class TransactionalInterceptor implements InterceptorMethods {\n constructor(\n @Inject() private readonly registry: MikroOrmRegistry,\n @Inject() private readonly context: DBContext,\n @Inject() private readonly logger: Logger,\n @Inject(RetryStrategy)\n private readonly retryStrategy?: RetryStrategy\n ) {}\n\n public async intercept(context: InterceptorContext<unknown>, next: InterceptorNext): Promise<unknown> {\n const options = this.extractContextName(context);\n\n if (options.retry && !this.retryStrategy) {\n this.logger.warn(`To retry a transaction you have to implement a \"${RetryStrategy.description}\" interface`);\n }\n\n const ctx = this.context.entries();\n\n if (!ctx) {\n return this.runWithinNewCtx(next, options);\n }\n\n if (ctx.has(options.contextName!)) {\n return next();\n }\n\n return this.runUnderCtx(next, ctx, options);\n }\n\n private runWithinNewCtx(next: InterceptorNext, options: TransactionOptions): Promise<unknown> | unknown {\n const ctx = new Map<string, EntityManager>();\n\n return this.runUnderCtx(next, ctx, options);\n }\n\n private runUnderCtx(next: InterceptorNext, ctx: Map<string, EntityManager>, options: TransactionOptions): Promise<unknown> | unknown {\n const orm = this.registry.get(options.contextName);\n\n if (!orm) {\n throw new Error(\n `No such context: ${options.contextName}. Please register a corresponding MikroOrm instance using '@Configuration()' decorator.`\n );\n }\n\n /**\n * The fork method signature has been changed since v5.x,\n * which might lead to unexpected behavior while using the @Transactional() decorator.\n *\n * ```diff\n * - fork(clear = true, useContext = false): D[typeof EntityManagerType]\n * + fork(options: ForkOptions = {}): D[typeof EntityManagerType] {\n * ```\n *\n * To ensure backward compatibility with v4.x and add support for v5.x, provided the following workaround:\n */\n const em = (orm.em.fork as (\n clearOrForkOptions?: boolean | {clear?: boolean; useContext?: boolean},\n useContext?: boolean\n ) => EntityManager)({clear: true, useContext: true}, true);\n\n ctx.set(em.name, em);\n\n const runInTransaction = () => this.executeInTransaction(options.contextName!, next);\n\n return this.context.run(ctx, () => (options.retry ? this.retryStrategy?.acquire(runInTransaction) : runInTransaction()));\n }\n\n private extractContextName(context: InterceptorContext<unknown>): TransactionOptions {\n const options = context.options || ({} as Partial<TransactionOptions> | string);\n\n let contextName: string | undefined;\n let retry: boolean | undefined;\n\n if (typeof options === \"string\") {\n contextName = options;\n } else if (options) {\n contextName = options.contextName ?? options.connectionName;\n retry = options.retry;\n }\n\n if (!contextName) {\n contextName = \"default\";\n }\n\n if (!retry) {\n retry = false;\n }\n\n return {contextName, retry};\n }\n\n private async executeInTransaction(contextName: string, next: InterceptorNext): Promise<unknown> {\n const em = this.context.get(contextName);\n\n const result = await next();\n\n await em?.flush();\n\n return result;\n }\n}\n"]}
@@ -14,15 +14,21 @@ let DBContext = class DBContext {
14
14
  run(ctx, callback) {
15
15
  return this.storage.run(ctx, callback);
16
16
  }
17
- getContext() {
17
+ entries() {
18
18
  return this.storage.getStore();
19
19
  }
20
+ /**
21
+ * @deprecated Since 2022-02-01. Use {@link entries} instead
22
+ */
23
+ getContext() {
24
+ return this.entries();
25
+ }
20
26
  get(contextName) {
21
- const context = this.getContext();
27
+ const context = this.entries();
22
28
  return context === null || context === void 0 ? void 0 : context.get(contextName);
23
29
  }
24
30
  has(contextName) {
25
- const context = this.getContext();
31
+ const context = this.entries();
26
32
  return !!(context === null || context === void 0 ? void 0 : context.has(contextName));
27
33
  }
28
34
  };
@@ -1 +1 @@
1
- {"version":3,"file":"DBContext.js","sourceRoot":"","sources":["../../../src/services/DBContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAG9C,IAAa,SAAS,GAAtB,MAAa,SAAS;IAGpB;QAFiB,YAAO,GAAG,IAAI,iBAAiB,EAA8B,CAAC;QAG7E,IAAI,iBAAiB,EAAE;YACrB,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC;SACxC;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,gEAAgE,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;SAC5G;IACH,CAAC;IAEM,GAAG,CAAI,GAA+B,EAAE,QAA+B;QAC5E,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAEM,GAAG,CAAC,WAAmB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAElC,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IAEM,GAAG,CAAC,WAAmB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAElC,OAAO,CAAC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,WAAW,CAAC,CAAA,CAAC;IACrC,CAAC;CACF,CAAA;AA9BY,SAAS;IADrB,UAAU,EAAE;;GACA,SAAS,CA8BrB;SA9BY,SAAS","sourcesContent":["import {Injectable} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {AsyncLocalStorage} from \"async_hooks\";\n\n@Injectable()\nexport class DBContext {\n private readonly storage = new AsyncLocalStorage<Map<string, EntityManager>>();\n\n constructor() {\n if (AsyncLocalStorage) {\n this.storage = new AsyncLocalStorage();\n } else {\n throw new Error(`AsyncLocalStorage is not available for your Node.js version (${process.versions.node}).`);\n }\n }\n\n public run<R>(ctx: Map<string, EntityManager>, callback: (...args: any[]) => R): R {\n return this.storage.run(ctx, callback);\n }\n\n public getContext(): Map<string, EntityManager> | undefined {\n return this.storage.getStore();\n }\n\n public get(contextName: string): EntityManager | undefined {\n const context = this.getContext();\n\n return context?.get(contextName);\n }\n\n public has(contextName: string): boolean {\n const context = this.getContext();\n\n return !!context?.has(contextName);\n }\n}\n"]}
1
+ {"version":3,"file":"DBContext.js","sourceRoot":"","sources":["../../../src/services/DBContext.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAG9C,IAAa,SAAS,GAAtB,MAAa,SAAS;IAGpB;QAFiB,YAAO,GAAG,IAAI,iBAAiB,EAA8B,CAAC;QAG7E,IAAI,iBAAiB,EAAE;YACrB,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAC;SACxC;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,gEAAgE,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;SAC5G;IACH,CAAC;IAEM,GAAG,CAAI,GAA+B,EAAE,QAA+B;QAC5E,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACzC,CAAC;IAEM,OAAO;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACI,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAEM,GAAG,CAAC,WAAmB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAE/B,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IAEM,GAAG,CAAC,WAAmB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAE/B,OAAO,CAAC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,WAAW,CAAC,CAAA,CAAC;IACrC,CAAC;CACF,CAAA;AArCY,SAAS;IADrB,UAAU,EAAE;;GACA,SAAS,CAqCrB;SArCY,SAAS","sourcesContent":["import {Injectable} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {AsyncLocalStorage} from \"async_hooks\";\n\n@Injectable()\nexport class DBContext {\n private readonly storage = new AsyncLocalStorage<Map<string, EntityManager>>();\n\n constructor() {\n if (AsyncLocalStorage) {\n this.storage = new AsyncLocalStorage();\n } else {\n throw new Error(`AsyncLocalStorage is not available for your Node.js version (${process.versions.node}).`);\n }\n }\n\n public run<R>(ctx: Map<string, EntityManager>, callback: (...args: any[]) => R): R {\n return this.storage.run(ctx, callback);\n }\n\n public entries(): Map<string, EntityManager> | undefined {\n return this.storage.getStore();\n }\n\n /**\n * @deprecated Since 2022-02-01. Use {@link entries} instead\n */\n public getContext(): Map<string, EntityManager> | undefined {\n return this.entries();\n }\n\n public get(contextName: string): EntityManager | undefined {\n const context = this.entries();\n\n return context?.get(contextName);\n }\n\n public has(contextName: string): boolean {\n const context = this.entries();\n\n return !!context?.has(contextName);\n }\n}\n"]}
@@ -3,9 +3,9 @@ import { DBContext } from "./DBContext";
3
3
  import { MikroORM } from "@mikro-orm/core";
4
4
  import { Inject, Injectable } from "@tsed/di";
5
5
  let MikroOrmFactory = class MikroOrmFactory {
6
- create(connectionOptions) {
6
+ create(options) {
7
7
  return MikroORM.init({
8
- ...connectionOptions,
8
+ ...options,
9
9
  context: (name) => this.dbContext.get(name)
10
10
  });
11
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MikroOrmFactory.js","sourceRoot":"","sources":["../../../src/services/MikroOrmFactory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,QAAQ,EAAU,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAG5C,IAAa,eAAe,GAA5B,MAAa,eAAe;IAInB,MAAM,CAAC,iBAA0B;QACtC,OAAO,QAAQ,CAAC,IAAI,CAAC;YACnB,GAAG,iBAAiB;YACpB,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AARC;IADC,MAAM,EAAE;8BACoB,SAAS;kDAAC;AAF5B,eAAe;IAD3B,UAAU,EAAE;GACA,eAAe,CAU3B;SAVY,eAAe","sourcesContent":["import {DBContext} from \"./DBContext\";\nimport {MikroORM, Options} from \"@mikro-orm/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\n\n@Injectable()\nexport class MikroOrmFactory {\n @Inject()\n private readonly dbContext!: DBContext;\n\n public create(connectionOptions: Options): Promise<MikroORM> {\n return MikroORM.init({\n ...connectionOptions,\n context: (name: string) => this.dbContext.get(name)\n });\n }\n}\n"]}
1
+ {"version":3,"file":"MikroOrmFactory.js","sourceRoot":"","sources":["../../../src/services/MikroOrmFactory.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,QAAQ,EAAU,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAG5C,IAAa,eAAe,GAA5B,MAAa,eAAe;IAInB,MAAM,CAAC,OAAgB;QAC5B,OAAO,QAAQ,CAAC,IAAI,CAAC;YACnB,GAAG,OAAO;YACV,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AARC;IADC,MAAM,EAAE;8BACoB,SAAS;kDAAC;AAF5B,eAAe;IAD3B,UAAU,EAAE;GACA,eAAe,CAU3B;SAVY,eAAe","sourcesContent":["import {DBContext} from \"./DBContext\";\nimport {MikroORM, Options} from \"@mikro-orm/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\n\n@Injectable()\nexport class MikroOrmFactory {\n @Inject()\n private readonly dbContext!: DBContext;\n\n public create(options: Options): Promise<MikroORM> {\n return MikroORM.init({\n ...options,\n context: (name: string) => this.dbContext.get(name)\n });\n }\n}\n"]}
@@ -7,35 +7,46 @@ let MikroOrmRegistry = class MikroOrmRegistry {
7
7
  constructor(logger, mikroOrmFactory) {
8
8
  this.logger = logger;
9
9
  this.mikroOrmFactory = mikroOrmFactory;
10
- this.connections = new Map();
10
+ this.instances = new Map();
11
11
  }
12
- async createConnection(connectionOptions) {
13
- const connectionName = getValue(connectionOptions, "contextName", "default");
14
- if (this.has(connectionName)) {
15
- return this.get(connectionName);
12
+ async register(options) {
13
+ const contextName = getValue(options, "contextName", "default");
14
+ if (this.has(contextName)) {
15
+ return this.get(contextName);
16
16
  }
17
- this.logger.info(`Create connection with MikroOrm to database: %s`, connectionName);
18
- this.logger.debug(`options: %j`, connectionOptions);
19
- const connection = await this.mikroOrmFactory.create(connectionOptions);
20
- this.connections.set(connectionName, connection);
21
- this.logger.info(`Connected with MikroOrm to database: %s`, connectionName);
22
- return connection;
23
- }
24
- get(id = "default") {
25
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
26
- return this.connections.get(id);
27
- }
28
- has(id = "default") {
29
- return this.connections.has(id);
30
- }
31
- async closeConnections() {
32
- const connections = [...this.connections.values()];
33
- await Promise.all(connections.map((connection) => catchAsyncError(() => this.dispose(connection))));
34
- this.connections.clear();
35
- }
36
- async dispose(connection) {
37
- if (await connection.isConnected()) {
38
- await connection.close(false);
17
+ this.logger.info(`Create connection with MikroOrm to database: %s`, contextName);
18
+ this.logger.debug(`options: %j`, options);
19
+ const instance = await this.mikroOrmFactory.create(options);
20
+ this.instances.set(contextName, instance);
21
+ this.logger.info(`Connected with MikroOrm to database: %s`, contextName);
22
+ return instance;
23
+ }
24
+ /**
25
+ * @deprecated Since 2022-02-01. Use {@link register} instead
26
+ */
27
+ createConnection(options) {
28
+ return this.register(options);
29
+ }
30
+ get(contextName = "default") {
31
+ return this.instances.get(contextName);
32
+ }
33
+ has(contextName = "default") {
34
+ return this.instances.has(contextName);
35
+ }
36
+ async clear() {
37
+ const instances = [...this.instances.values()];
38
+ await Promise.all(instances.map((instance) => catchAsyncError(() => this.dispose(instance))));
39
+ this.instances.clear();
40
+ }
41
+ /**
42
+ * @deprecated Since 2022-02-01. Use {@link clear} instead
43
+ */
44
+ closeConnections() {
45
+ return this.clear();
46
+ }
47
+ async dispose(instance) {
48
+ if (await instance.isConnected()) {
49
+ await instance.close(false);
39
50
  }
40
51
  }
41
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"MikroOrmRegistry.js","sourceRoot":"","sources":["../../../src/services/MikroOrmRegistry.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAC,eAAe,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAGpC,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAG3B,YAAuC,MAAc,EAA6B,eAAgC;QAA3E,WAAM,GAAN,MAAM,CAAQ;QAA6B,oBAAe,GAAf,eAAe,CAAiB;QAFjG,gBAAW,GAAG,IAAI,GAAG,EAAoB,CAAC;IAE0D,CAAC;IAE/G,KAAK,CAAC,gBAAgB,CAA2B,iBAA6B;QACnF,MAAM,cAAc,GAAG,QAAQ,CAAS,iBAAiB,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QAErF,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE;YAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;SACjC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iDAAiD,EAAE,cAAc,CAAC,CAAC;QACpF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC;QAEpD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QAExE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAEjD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,yCAAyC,EAAE,cAAc,CAAC,CAAC;QAE5E,OAAO,UAAU,CAAC;IACpB,CAAC;IAEM,GAAG,CAAC,KAAa,SAAS;QAC/B,oEAAoE;QACpE,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;IACnC,CAAC;IAEM,GAAG,CAAC,KAAa,SAAS;QAC/B,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;IAEM,KAAK,CAAC,gBAAgB;QAC3B,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;QAEnD,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAoB,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAE9G,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,UAAoB;QACxC,IAAI,MAAM,UAAU,CAAC,WAAW,EAAE,EAAE;YAClC,MAAM,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SAC/B;IACH,CAAC;CACF,CAAA;AA9CY,gBAAgB;IAD5B,UAAU,EAAE;IAIE,WAAA,MAAM,EAAE,CAAA;IAAmC,WAAA,MAAM,EAAE,CAAA;qCAAjB,MAAM,EAA8C,eAAe;GAHvG,gBAAgB,CA8C5B;SA9CY,gBAAgB","sourcesContent":["import {MikroOrmFactory} from \"./MikroOrmFactory\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {IDatabaseDriver as DatabaseDriver, MikroORM, Options} from \"@mikro-orm/core\";\nimport {catchAsyncError, getValue} from \"@tsed/core\";\nimport {Logger} from \"@tsed/logger\";\n\n@Injectable()\nexport class MikroOrmRegistry {\n private readonly connections = new Map<string, MikroORM>();\n\n constructor(@Inject() private readonly logger: Logger, @Inject() private readonly mikroOrmFactory: MikroOrmFactory) {}\n\n public async createConnection<T extends DatabaseDriver>(connectionOptions: Options<T>): Promise<MikroORM> {\n const connectionName = getValue<string>(connectionOptions, \"contextName\", \"default\");\n\n if (this.has(connectionName)) {\n return this.get(connectionName);\n }\n\n this.logger.info(`Create connection with MikroOrm to database: %s`, connectionName);\n this.logger.debug(`options: %j`, connectionOptions);\n\n const connection = await this.mikroOrmFactory.create(connectionOptions);\n\n this.connections.set(connectionName, connection);\n\n this.logger.info(`Connected with MikroOrm to database: %s`, connectionName);\n\n return connection;\n }\n\n public get(id: string = \"default\"): MikroORM {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.connections.get(id)!;\n }\n\n public has(id: string = \"default\"): boolean {\n return this.connections.has(id);\n }\n\n public async closeConnections(): Promise<void> {\n const connections = [...this.connections.values()];\n\n await Promise.all(connections.map((connection: MikroORM) => catchAsyncError(() => this.dispose(connection))));\n\n this.connections.clear();\n }\n\n private async dispose(connection: MikroORM): Promise<void> {\n if (await connection.isConnected()) {\n await connection.close(false);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"MikroOrmRegistry.js","sourceRoot":"","sources":["../../../src/services/MikroOrmRegistry.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAC,eAAe,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAGpC,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IAG3B,YAAuC,MAAc,EAA6B,eAAgC;QAA3E,WAAM,GAAN,MAAM,CAAQ;QAA6B,oBAAe,GAAf,eAAe,CAAiB;QAFjG,cAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAE4D,CAAC;IAE/G,KAAK,CAAC,QAAQ,CAA2B,OAAmB;QACj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AExG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,gBAAgB;QACrB,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,QAAkB;QACtC,IAAI,MAAM,QAAQ,CAAC,WAAW,EAAE,EAAE;YAChC,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SAC7B;IACH,CAAC;CACF,CAAA;AA3DY,gBAAgB;IAD5B,UAAU,EAAE;IAIE,WAAA,MAAM,EAAE,CAAA;IAAmC,WAAA,MAAM,EAAE,CAAA;qCAAjB,MAAM,EAA8C,eAAe;GAHvG,gBAAgB,CA2D5B;SA3DY,gBAAgB","sourcesContent":["import {MikroOrmFactory} from \"./MikroOrmFactory\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {IDatabaseDriver as DatabaseDriver, MikroORM, Options} from \"@mikro-orm/core\";\nimport {catchAsyncError, getValue} from \"@tsed/core\";\nimport {Logger} from \"@tsed/logger\";\n\n@Injectable()\nexport class MikroOrmRegistry {\n private readonly instances = new Map<string, MikroORM>();\n\n constructor(@Inject() private readonly logger: Logger, @Inject() private readonly mikroOrmFactory: MikroOrmFactory) {}\n\n public async register<T extends DatabaseDriver>(options: Options<T>): Promise<MikroORM> {\n const contextName = getValue<string>(options, \"contextName\", \"default\");\n\n if (this.has(contextName)) {\n return this.get(contextName)!;\n }\n\n this.logger.info(`Create connection with MikroOrm to database: %s`, contextName);\n this.logger.debug(`options: %j`, options);\n\n const instance = await this.mikroOrmFactory.create(options);\n\n this.instances.set(contextName, instance);\n\n this.logger.info(`Connected with MikroOrm to database: %s`, contextName);\n\n return instance;\n }\n\n /**\n * @deprecated Since 2022-02-01. Use {@link register} instead\n */\n public createConnection<T extends DatabaseDriver>(options: Options<T>): Promise<MikroORM> {\n return this.register(options);\n }\n\n public get(contextName: string = \"default\"): MikroORM | undefined {\n return this.instances.get(contextName);\n }\n\n public has(contextName: string = \"default\"): boolean {\n return this.instances.has(contextName);\n }\n\n public async clear(): Promise<void> {\n const instances = [...this.instances.values()];\n\n await Promise.all(instances.map((instance: MikroORM) => catchAsyncError(() => this.dispose(instance))));\n\n this.instances.clear();\n }\n\n /**\n * @deprecated Since 2022-02-01. Use {@link clear} instead\n */\n public closeConnections(): Promise<void> {\n return this.clear();\n }\n\n private async dispose(instance: MikroORM): Promise<void> {\n if (await instance.isConnected()) {\n await instance.close(false);\n }\n }\n}\n"]}
@@ -1,14 +1,14 @@
1
1
  /**
2
- * Get the entity manager for the given connection name.
3
- * @param connectionName
2
+ * Get the entity manager for the given context name.
3
+ * @param {String} contextName
4
4
  * @decorator
5
5
  * @mikroOrm
6
6
  */
7
- export declare const EntityManager: (connectionName?: string | undefined) => PropertyDecorator;
7
+ export declare const EntityManager: (contextName?: string | undefined) => PropertyDecorator;
8
8
  /**
9
- * Get the entity manager for the given connection name.
10
- * @param connectionName
9
+ * Get the entity manager for the given context name.
10
+ * @param {String} connectionName
11
11
  * @decorator
12
12
  * @mikroOrm
13
13
  */
14
- export declare const Em: (connectionName?: string | undefined) => PropertyDecorator;
14
+ export declare const Em: (contextName?: string | undefined) => PropertyDecorator;
@@ -1,5 +1,11 @@
1
1
  /**
2
+ * Get the ORM for the given context name.
3
+ * @param {String} contextName
4
+ */
5
+ export declare const Orm: (contextName?: string | undefined) => PropertyDecorator;
6
+ /**
7
+ * Get the ORM for the given context name.
8
+ * @param {String} contextName
2
9
  * @deprecated Since 2022-02-01. Use {@link Orm} instead
3
10
  */
4
11
  export declare const Connection: (contextName?: string | undefined) => PropertyDecorator;
5
- export declare const Orm: (contextName?: string | undefined) => PropertyDecorator;
@@ -1,2 +1,6 @@
1
1
  import { TransactionOptions } from "../interceptors";
2
- export declare const Transactional: (connectionOrOptions?: string | TransactionOptions | undefined) => MethodDecorator;
2
+ /**
3
+ * Register a new request context for your method and execute it inside the context.
4
+ * @param {String | TransactionOptions} contextNameOrOptions
5
+ */
6
+ export declare const Transactional: (contextNameOrOptions?: string | TransactionOptions | undefined) => MethodDecorator;
@@ -2,8 +2,12 @@ import { DBContext, MikroOrmRegistry, RetryStrategy } from "../services";
2
2
  import { InterceptorContext, InterceptorMethods, InterceptorNext } from "@tsed/di";
3
3
  import { Logger } from "@tsed/logger";
4
4
  export interface TransactionOptions {
5
- connectionName?: string;
6
5
  retry?: boolean;
6
+ contextName?: string;
7
+ /**
8
+ * @deprecated Since 2022-02-01. Use {@link contextName} instead
9
+ */
10
+ connectionName?: string;
7
11
  }
8
12
  export declare class TransactionalInterceptor implements InterceptorMethods {
9
13
  private readonly registry;
@@ -3,6 +3,10 @@ export declare class DBContext {
3
3
  private readonly storage;
4
4
  constructor();
5
5
  run<R>(ctx: Map<string, EntityManager>, callback: (...args: any[]) => R): R;
6
+ entries(): Map<string, EntityManager> | undefined;
7
+ /**
8
+ * @deprecated Since 2022-02-01. Use {@link entries} instead
9
+ */
6
10
  getContext(): Map<string, EntityManager> | undefined;
7
11
  get(contextName: string): EntityManager | undefined;
8
12
  has(contextName: string): boolean;
@@ -1,5 +1,5 @@
1
1
  import { MikroORM, Options } from "@mikro-orm/core";
2
2
  export declare class MikroOrmFactory {
3
3
  private readonly dbContext;
4
- create(connectionOptions: Options): Promise<MikroORM>;
4
+ create(options: Options): Promise<MikroORM>;
5
5
  }
@@ -4,11 +4,19 @@ import { Logger } from "@tsed/logger";
4
4
  export declare class MikroOrmRegistry {
5
5
  private readonly logger;
6
6
  private readonly mikroOrmFactory;
7
- private readonly connections;
7
+ private readonly instances;
8
8
  constructor(logger: Logger, mikroOrmFactory: MikroOrmFactory);
9
- createConnection<T extends DatabaseDriver>(connectionOptions: Options<T>): Promise<MikroORM>;
10
- get(id?: string): MikroORM;
11
- has(id?: string): boolean;
9
+ register<T extends DatabaseDriver>(options: Options<T>): Promise<MikroORM>;
10
+ /**
11
+ * @deprecated Since 2022-02-01. Use {@link register} instead
12
+ */
13
+ createConnection<T extends DatabaseDriver>(options: Options<T>): Promise<MikroORM>;
14
+ get(contextName?: string): MikroORM | undefined;
15
+ has(contextName?: string): boolean;
16
+ clear(): Promise<void>;
17
+ /**
18
+ * @deprecated Since 2022-02-01. Use {@link clear} instead
19
+ */
12
20
  closeConnections(): Promise<void>;
13
21
  private dispose;
14
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/mikro-orm",
3
- "version": "6.99.0",
3
+ "version": "6.100.0",
4
4
  "description": "MikroORM package for Ts.ED framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -24,20 +24,20 @@
24
24
  "devDependencies": {
25
25
  "@mikro-orm/core": "^4.5.9",
26
26
  "@mikro-orm/mongodb": "^4.5.9",
27
- "@tsed/common": "6.99.0",
28
- "@tsed/core": "6.99.0",
29
- "@tsed/di": "6.99.0",
30
- "@tsed/json-mapper": "6.99.0",
27
+ "@tsed/common": "6.100.0",
28
+ "@tsed/core": "6.100.0",
29
+ "@tsed/di": "6.100.0",
30
+ "@tsed/json-mapper": "6.100.0",
31
31
  "@tsed/logger": "^6.0.0",
32
- "@tsed/schema": "6.99.0",
33
- "@tsed/testing-mongoose": "6.99.0",
32
+ "@tsed/schema": "6.100.0",
33
+ "@tsed/testing-mongoose": "6.100.0",
34
34
  "ts-mockito": "^2.6.1"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@mikro-orm/core": ">=4.5.9",
38
- "@tsed/common": "^6.99.0",
39
- "@tsed/core": "^6.99.0",
40
- "@tsed/di": "^6.99.0",
38
+ "@tsed/common": "^6.100.0",
39
+ "@tsed/core": "^6.100.0",
40
+ "@tsed/di": "^6.100.0",
41
41
  "@tsed/logger": "^6.0.0"
42
42
  },
43
43
  "repository": "https://github.com/tsedio/tsed",
package/readme.md CHANGED
@@ -33,7 +33,7 @@ A package of Ts.ED framework. See website: https://tsed.io/tutorials/mikro-orm
33
33
 
34
34
  Currently, `@tsed/mikro-orm` allows you:
35
35
 
36
- - Configure one or more MikroOrm connections via the `@Configuration` decorator. All databases will be initialized
36
+ - Configure one or more MikroOrm instances via the `@Configuration` decorator. All databases will be initialized
37
37
  when the server starts during the server's `OnInit` phase.
38
38
  - Use the Entity MikroOrm as Model for Controllers, AJV Validation and Swagger.
39
39
 
@@ -129,7 +129,7 @@ export class UsersService {
129
129
  }
130
130
  ```
131
131
 
132
- It's also possible to inject an ORM by a connection name:
132
+ It's also possible to inject an ORM by its context name:
133
133
 
134
134
  ```ts
135
135
  import {Injectable} from "@tsed/di";
@@ -164,7 +164,7 @@ export class UsersService {
164
164
  }
165
165
  ```
166
166
 
167
- It's also possible to inject Entity manager by his connection name:
167
+ It's also possible to inject Entity manager by his context name:
168
168
 
169
169
  ```typescript
170
170
  import {Injectable, AfterRoutesInit} from "@tsed/common";
@@ -173,7 +173,7 @@ import {EntityManager} from '@mikro-orm/mysql'; // Import EntityManager from you
173
173
 
174
174
  @Injectable()
175
175
  export class UsersService {
176
- @Em("connectionName")
176
+ @Em("contextName")
177
177
  private readonly em!: EntityManager;
178
178
 
179
179
  async create(user: User): Promise<User> {