@tsed/mikro-orm 6.102.8-rc.1 → 6.102.8-rc.2
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.
- package/lib/cjs/MikroOrmModule.js +7 -5
- package/lib/cjs/MikroOrmModule.js.map +1 -1
- package/lib/cjs/decorators/entityManager.js +2 -2
- package/lib/cjs/decorators/entityManager.js.map +1 -1
- package/lib/cjs/decorators/orm.js +2 -2
- package/lib/cjs/decorators/orm.js.map +1 -1
- package/lib/cjs/decorators/transactional.d.ts +1 -1
- package/lib/cjs/decorators/transactional.js +2 -2
- package/lib/cjs/decorators/transactional.js.map +1 -1
- package/lib/cjs/index.d.ts +12 -4
- package/lib/cjs/index.js +12 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interceptors/TransactionalInterceptor.d.ts +3 -1
- package/lib/cjs/interceptors/TransactionalInterceptor.js +7 -5
- package/lib/cjs/interceptors/TransactionalInterceptor.js.map +1 -1
- package/lib/esm/MikroOrmModule.js +3 -1
- package/lib/esm/MikroOrmModule.js.map +1 -1
- package/lib/esm/decorators/entityManager.js +1 -1
- package/lib/esm/decorators/entityManager.js.map +1 -1
- package/lib/esm/decorators/orm.js +1 -1
- package/lib/esm/decorators/orm.js.map +1 -1
- package/lib/esm/decorators/transactional.js +1 -1
- package/lib/esm/decorators/transactional.js.map +1 -1
- package/lib/esm/index.js +12 -4
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interceptors/TransactionalInterceptor.js +3 -1
- package/lib/esm/interceptors/TransactionalInterceptor.js.map +1 -1
- package/lib/types/decorators/transactional.d.ts +1 -1
- package/lib/types/index.d.ts +12 -4
- package/lib/types/interceptors/TransactionalInterceptor.d.ts +3 -1
- package/package.json +16 -12
- package/lib/cjs/decorators/index.d.ts +0 -3
- package/lib/cjs/decorators/index.js +0 -7
- package/lib/cjs/decorators/index.js.map +0 -1
- package/lib/cjs/filters/index.d.ts +0 -1
- package/lib/cjs/filters/index.js +0 -5
- package/lib/cjs/filters/index.js.map +0 -1
- package/lib/cjs/interceptors/index.d.ts +0 -1
- package/lib/cjs/interceptors/index.js +0 -5
- package/lib/cjs/interceptors/index.js.map +0 -1
- package/lib/cjs/services/index.d.ts +0 -4
- package/lib/cjs/services/index.js +0 -8
- package/lib/cjs/services/index.js.map +0 -1
- package/lib/esm/decorators/index.js +0 -4
- package/lib/esm/decorators/index.js.map +0 -1
- package/lib/esm/filters/index.js +0 -2
- package/lib/esm/filters/index.js.map +0 -1
- package/lib/esm/interceptors/index.js +0 -2
- package/lib/esm/interceptors/index.js.map +0 -1
- package/lib/esm/services/index.js +0 -5
- package/lib/esm/services/index.js.map +0 -1
- package/lib/types/decorators/index.d.ts +0 -3
- package/lib/types/filters/index.d.ts +0 -1
- package/lib/types/interceptors/index.d.ts +0 -1
- package/lib/types/services/index.d.ts +0 -4
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MikroOrmModule = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const services_1 = require("./services");
|
|
6
5
|
const di_1 = require("@tsed/di");
|
|
6
|
+
const MikroOrmRegistry_1 = require("./services/MikroOrmRegistry");
|
|
7
|
+
const DBContext_1 = require("./services/DBContext");
|
|
8
|
+
const RetryStrategy_1 = require("./services/RetryStrategy");
|
|
7
9
|
let MikroOrmModule = class MikroOrmModule {
|
|
8
10
|
async $onInit() {
|
|
9
11
|
const promises = this.settings.map((opts) => this.mikroOrmRegistry.register(opts));
|
|
@@ -19,15 +21,15 @@ let MikroOrmModule = class MikroOrmModule {
|
|
|
19
21
|
], MikroOrmModule.prototype, "settings", void 0);
|
|
20
22
|
(0, tslib_1.__decorate)([
|
|
21
23
|
(0, di_1.Inject)(),
|
|
22
|
-
(0, tslib_1.__metadata)("design:type",
|
|
24
|
+
(0, tslib_1.__metadata)("design:type", MikroOrmRegistry_1.MikroOrmRegistry)
|
|
23
25
|
], MikroOrmModule.prototype, "mikroOrmRegistry", void 0);
|
|
24
26
|
MikroOrmModule = (0, tslib_1.__decorate)([
|
|
25
27
|
(0, di_1.Module)({
|
|
26
|
-
imports: [
|
|
27
|
-
deps: [di_1.Configuration,
|
|
28
|
+
imports: [DBContext_1.DBContext, MikroOrmRegistry_1.MikroOrmRegistry],
|
|
29
|
+
deps: [di_1.Configuration, MikroOrmRegistry_1.MikroOrmRegistry]
|
|
28
30
|
})
|
|
29
31
|
], MikroOrmModule);
|
|
30
32
|
exports.MikroOrmModule = MikroOrmModule;
|
|
31
33
|
// TODO: the IoC container should provide null or undefined by default until tsedio/tsed#1694 is closed
|
|
32
|
-
(0, di_1.registerProvider)({ provide:
|
|
34
|
+
(0, di_1.registerProvider)({ provide: RetryStrategy_1.RetryStrategy, useValue: null });
|
|
33
35
|
//# sourceMappingURL=MikroOrmModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MikroOrmModule.js","sourceRoot":"","sources":["../../src/MikroOrmModule.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"MikroOrmModule.js","sourceRoot":"","sources":["../../src/MikroOrmModule.ts"],"names":[],"mappings":";;;;AAAA,iCAAsG;AAEtG,kEAA6D;AAC7D,oDAA+C;AAC/C,4DAAuD;AAmBvD,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,mCAAgB;wDAAC;AAL1C,cAAc;IAJ1B,IAAA,WAAM,EAAC;QACN,OAAO,EAAE,CAAC,qBAAS,EAAE,mCAAgB,CAAC;QACtC,IAAI,EAAE,CAAC,kBAAa,EAAE,mCAAgB,CAAC;KACxC,CAAC;GACW,cAAc,CAgB1B;AAhBY,wCAAc;AAkB3B,uGAAuG;AACvG,IAAA,qBAAgB,EAAC,EAAC,OAAO,EAAE,6BAAa,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC","sourcesContent":["import {Configuration, Constant, Inject, Module, OnDestroy, OnInit, registerProvider} from \"@tsed/di\";\nimport {Options} from \"@mikro-orm/core\";\nimport {MikroOrmRegistry} from \"./services/MikroOrmRegistry\";\nimport {DBContext} from \"./services/DBContext\";\nimport {RetryStrategy} from \"./services/RetryStrategy\";\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"]}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Em = exports.EntityManager = void 0;
|
|
4
4
|
const di_1 = require("@tsed/di");
|
|
5
|
-
const
|
|
5
|
+
const MikroOrmRegistry_1 = require("../services/MikroOrmRegistry");
|
|
6
6
|
/**
|
|
7
7
|
* Get the entity manager for the given context name.
|
|
8
8
|
* @param {String} contextName
|
|
9
9
|
* @decorator
|
|
10
10
|
* @mikroOrm
|
|
11
11
|
*/
|
|
12
|
-
const EntityManager = (contextName) => (0, di_1.Inject)(
|
|
12
|
+
const EntityManager = (contextName) => (0, di_1.Inject)(MikroOrmRegistry_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
15
|
* Get the entity manager for the given context name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityManager.js","sourceRoot":"","sources":["../../../src/decorators/entityManager.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,
|
|
1
|
+
{"version":3,"file":"entityManager.js","sourceRoot":"","sources":["../../../src/decorators/entityManager.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAChC,mEAA8D;AAE9D;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAAqB,EAAE,CACvE,IAAA,WAAM,EAAC,mCAAgB,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/MikroOrmRegistry\";\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,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Connection = exports.Orm = void 0;
|
|
4
|
-
const
|
|
4
|
+
const MikroOrmRegistry_1 = require("../services/MikroOrmRegistry");
|
|
5
5
|
const di_1 = require("@tsed/di");
|
|
6
6
|
/**
|
|
7
7
|
* Get the ORM for the given context name.
|
|
8
8
|
* @param {String} contextName
|
|
9
9
|
*/
|
|
10
|
-
const Orm = (contextName) => (0, di_1.Inject)(
|
|
10
|
+
const Orm = (contextName) => (0, di_1.Inject)(MikroOrmRegistry_1.MikroOrmRegistry, (registry) => registry.get(contextName));
|
|
11
11
|
exports.Orm = Orm;
|
|
12
12
|
/**
|
|
13
13
|
* Get the ORM for the given context name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":";;;AAAA,mEAA8D;AAC9D,iCAAgC;AAEhC;;;GAGG;AACI,MAAM,GAAG,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAC7D,IAAA,WAAM,EAAC,mCAAgB,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/MikroOrmRegistry\";\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,4 @@
|
|
|
1
|
-
import { TransactionOptions } from "../interceptors";
|
|
1
|
+
import { TransactionOptions } from "../interceptors/TransactionalInterceptor";
|
|
2
2
|
/**
|
|
3
3
|
* Register a new request context for your method and execute it inside the context.
|
|
4
4
|
* @param {String | TransactionOptions} contextNameOrOptions
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Transactional = void 0;
|
|
4
|
-
const interceptors_1 = require("../interceptors");
|
|
5
4
|
const di_1 = require("@tsed/di");
|
|
5
|
+
const TransactionalInterceptor_1 = require("../interceptors/TransactionalInterceptor");
|
|
6
6
|
/**
|
|
7
7
|
* Register a new request context for your method and execute it inside the context.
|
|
8
8
|
* @param {String | TransactionOptions} contextNameOrOptions
|
|
9
9
|
*/
|
|
10
|
-
const Transactional = (contextNameOrOptions) => (0, di_1.Intercept)(
|
|
10
|
+
const Transactional = (contextNameOrOptions) => (0, di_1.Intercept)(TransactionalInterceptor_1.TransactionalInterceptor, contextNameOrOptions);
|
|
11
11
|
exports.Transactional = Transactional;
|
|
12
12
|
//# sourceMappingURL=transactional.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactional.js","sourceRoot":"","sources":["../../../src/decorators/transactional.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"transactional.js","sourceRoot":"","sources":["../../../src/decorators/transactional.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AACnC,uFAAsG;AAEtG;;;GAGG;AACI,MAAM,aAAa,GAAG,CAAC,oBAAkD,EAAmB,EAAE,CACnG,IAAA,cAAS,EAAC,mDAAwB,EAAE,oBAAoB,CAAC,CAAC;AAD/C,QAAA,aAAa,iBACkC","sourcesContent":["import {Intercept} from \"@tsed/di\";\nimport {TransactionalInterceptor, TransactionOptions} from \"../interceptors/TransactionalInterceptor\";\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"]}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./services";
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
5
4
|
export * from "./MikroOrmModule";
|
|
5
|
+
export * from "./decorators/entityManager";
|
|
6
|
+
export * from "./decorators/orm";
|
|
7
|
+
export * from "./decorators/transactional";
|
|
8
|
+
export * from "./filters/OptimisticLockErrorFilter";
|
|
9
|
+
export * from "./interceptors/TransactionalInterceptor";
|
|
10
|
+
export * from "./services/DBContext";
|
|
11
|
+
export * from "./services/MikroOrmFactory";
|
|
12
|
+
export * from "./services/MikroOrmRegistry";
|
|
13
|
+
export * from "./services/RetryStrategy";
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const tslib_1 = require("tslib");
|
|
4
|
-
(0, tslib_1.__exportStar)(require("./decorators"), exports);
|
|
5
|
-
(0, tslib_1.__exportStar)(require("./filters"), exports);
|
|
6
|
-
(0, tslib_1.__exportStar)(require("./interceptors"), exports);
|
|
7
|
-
(0, tslib_1.__exportStar)(require("./services"), exports);
|
|
8
7
|
(0, tslib_1.__exportStar)(require("./MikroOrmModule"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./decorators/entityManager"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./decorators/orm"), exports);
|
|
10
|
+
(0, tslib_1.__exportStar)(require("./decorators/transactional"), exports);
|
|
11
|
+
(0, tslib_1.__exportStar)(require("./filters/OptimisticLockErrorFilter"), exports);
|
|
12
|
+
(0, tslib_1.__exportStar)(require("./interceptors/TransactionalInterceptor"), exports);
|
|
13
|
+
(0, tslib_1.__exportStar)(require("./services/DBContext"), exports);
|
|
14
|
+
(0, tslib_1.__exportStar)(require("./services/MikroOrmFactory"), exports);
|
|
15
|
+
(0, tslib_1.__exportStar)(require("./services/MikroOrmRegistry"), exports);
|
|
16
|
+
(0, tslib_1.__exportStar)(require("./services/RetryStrategy"), exports);
|
|
9
17
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAiC;AACjC,0EAA2C;AAC3C,gEAAiC;AACjC,0EAA2C;AAC3C,mFAAoD;AACpD,uFAAwD;AACxD,oEAAqC;AACrC,0EAA2C;AAC3C,2EAA4C;AAC5C,wEAAyC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./MikroOrmModule\";\nexport * from \"./decorators/entityManager\";\nexport * from \"./decorators/orm\";\nexport * from \"./decorators/transactional\";\nexport * from \"./filters/OptimisticLockErrorFilter\";\nexport * from \"./interceptors/TransactionalInterceptor\";\nexport * from \"./services/DBContext\";\nexport * from \"./services/MikroOrmFactory\";\nexport * from \"./services/MikroOrmRegistry\";\nexport * from \"./services/RetryStrategy\";\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { DBContext, MikroOrmRegistry, RetryStrategy } from "../services";
|
|
2
1
|
import { InterceptorContext, InterceptorMethods, InterceptorNext } from "@tsed/di";
|
|
3
2
|
import { Logger } from "@tsed/logger";
|
|
3
|
+
import { MikroOrmRegistry } from "../services/MikroOrmRegistry";
|
|
4
|
+
import { DBContext } from "../services/DBContext";
|
|
5
|
+
import { RetryStrategy } from "../services/RetryStrategy";
|
|
4
6
|
export interface TransactionOptions {
|
|
5
7
|
retry?: boolean;
|
|
6
8
|
contextName?: string;
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionalInterceptor = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const services_1 = require("../services");
|
|
6
5
|
const di_1 = require("@tsed/di");
|
|
7
6
|
const logger_1 = require("@tsed/logger");
|
|
7
|
+
const MikroOrmRegistry_1 = require("../services/MikroOrmRegistry");
|
|
8
|
+
const DBContext_1 = require("../services/DBContext");
|
|
9
|
+
const RetryStrategy_1 = require("../services/RetryStrategy");
|
|
8
10
|
let TransactionalInterceptor = class TransactionalInterceptor {
|
|
9
11
|
constructor(registry, context, logger, retryStrategy) {
|
|
10
12
|
this.registry = registry;
|
|
@@ -15,7 +17,7 @@ let TransactionalInterceptor = class TransactionalInterceptor {
|
|
|
15
17
|
async intercept(context, next) {
|
|
16
18
|
const options = this.extractContextName(context);
|
|
17
19
|
if (options.retry && !this.retryStrategy) {
|
|
18
|
-
this.logger.warn(`To retry a transaction you have to implement a "${
|
|
20
|
+
this.logger.warn(`To retry a transaction you have to implement a "${RetryStrategy_1.RetryStrategy.description}" interface`);
|
|
19
21
|
}
|
|
20
22
|
const ctx = this.context.entries();
|
|
21
23
|
if (!ctx) {
|
|
@@ -83,9 +85,9 @@ TransactionalInterceptor = (0, tslib_1.__decorate)([
|
|
|
83
85
|
(0, tslib_1.__param)(0, (0, di_1.Inject)()),
|
|
84
86
|
(0, tslib_1.__param)(1, (0, di_1.Inject)()),
|
|
85
87
|
(0, tslib_1.__param)(2, (0, di_1.Inject)()),
|
|
86
|
-
(0, tslib_1.__param)(3, (0, di_1.Inject)(
|
|
87
|
-
(0, tslib_1.__metadata)("design:paramtypes", [
|
|
88
|
-
|
|
88
|
+
(0, tslib_1.__param)(3, (0, di_1.Inject)(RetryStrategy_1.RetryStrategy)),
|
|
89
|
+
(0, tslib_1.__metadata)("design:paramtypes", [MikroOrmRegistry_1.MikroOrmRegistry,
|
|
90
|
+
DBContext_1.DBContext,
|
|
89
91
|
logger_1.Logger, Object])
|
|
90
92
|
], TransactionalInterceptor);
|
|
91
93
|
exports.TransactionalInterceptor = TransactionalInterceptor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionalInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/TransactionalInterceptor.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"TransactionalInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/TransactionalInterceptor.ts"],"names":[],"mappings":";;;;AAAA,iCAAsG;AAEtG,yCAAoC;AACpC,mEAA8D;AAC9D,qDAAgD;AAChD,6DAAwD;AAYxD,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,6BAAa,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IAAA,WAAM,EAAC,6BAAa,CAAC,CAAA;kDAHe,mCAAgB;QACjB,qBAAS;QACV,eAAM;GAJhC,wBAAwB,CAmGpC;AAnGY,4DAAwB","sourcesContent":["import {Inject, Interceptor, InterceptorContext, InterceptorMethods, InterceptorNext} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {Logger} from \"@tsed/logger\";\nimport {MikroOrmRegistry} from \"../services/MikroOrmRegistry\";\nimport {DBContext} from \"../services/DBContext\";\nimport {RetryStrategy} from \"../services/RetryStrategy\";\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 = (\n orm.em.fork as (clearOrForkOptions?: boolean | {clear?: boolean; useContext?: boolean}, useContext?: boolean) => EntityManager\n )({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"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { DBContext, MikroOrmRegistry, RetryStrategy } from "./services.js";
|
|
3
2
|
import { Configuration, Constant, Inject, Module, registerProvider } from "@tsed/di";
|
|
3
|
+
import { MikroOrmRegistry } from "./services/MikroOrmRegistry.js";
|
|
4
|
+
import { DBContext } from "./services/DBContext.js";
|
|
5
|
+
import { RetryStrategy } from "./services/RetryStrategy.js";
|
|
4
6
|
let MikroOrmModule = class MikroOrmModule {
|
|
5
7
|
async $onInit() {
|
|
6
8
|
const promises = this.settings.map((opts) => this.mikroOrmRegistry.register(opts));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MikroOrmModule.js","sourceRoot":"","sources":["../../src/MikroOrmModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"MikroOrmModule.js","sourceRoot":"","sources":["../../src/MikroOrmModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAqB,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAEtG,OAAO,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAmBvD,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 {Configuration, Constant, Inject, Module, OnDestroy, OnInit, registerProvider} from \"@tsed/di\";\nimport {Options} from \"@mikro-orm/core\";\nimport {MikroOrmRegistry} from \"./services/MikroOrmRegistry\";\nimport {DBContext} from \"./services/DBContext\";\nimport {RetryStrategy} from \"./services/RetryStrategy\";\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 +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,
|
|
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,8BAA8B,CAAC;AAE9D;;;;;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/MikroOrmRegistry\";\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,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/MikroOrmRegistry\";\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,5 +1,5 @@
|
|
|
1
|
-
import { TransactionalInterceptor } from "../interceptors.js";
|
|
2
1
|
import { Intercept } from "@tsed/di";
|
|
2
|
+
import { TransactionalInterceptor } from "../interceptors/TransactionalInterceptor.js";
|
|
3
3
|
/**
|
|
4
4
|
* Register a new request context for your method and execute it inside the context.
|
|
5
5
|
* @param {String | TransactionOptions} contextNameOrOptions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactional.js","sourceRoot":"","sources":["../../../src/decorators/transactional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"transactional.js","sourceRoot":"","sources":["../../../src/decorators/transactional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AACnC,OAAO,EAAC,wBAAwB,EAAqB,MAAM,0CAA0C,CAAC;AAEtG;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,oBAAkD,EAAmB,EAAE,CACnG,SAAS,CAAC,wBAAwB,EAAE,oBAAoB,CAAC,CAAC","sourcesContent":["import {Intercept} from \"@tsed/di\";\nimport {TransactionalInterceptor, TransactionOptions} from \"../interceptors/TransactionalInterceptor\";\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"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./services.js";
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
5
4
|
export * from "./MikroOrmModule.js";
|
|
5
|
+
export * from "./decorators/entityManager.js";
|
|
6
|
+
export * from "./decorators/orm.js";
|
|
7
|
+
export * from "./decorators/transactional.js";
|
|
8
|
+
export * from "./filters/OptimisticLockErrorFilter.js";
|
|
9
|
+
export * from "./interceptors/TransactionalInterceptor.js";
|
|
10
|
+
export * from "./services/DBContext.js";
|
|
11
|
+
export * from "./services/MikroOrmFactory.js";
|
|
12
|
+
export * from "./services/MikroOrmRegistry.js";
|
|
13
|
+
export * from "./services/RetryStrategy.js";
|
|
6
14
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,yCAAyC,CAAC;AACxD,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./MikroOrmModule\";\nexport * from \"./decorators/entityManager\";\nexport * from \"./decorators/orm\";\nexport * from \"./decorators/transactional\";\nexport * from \"./filters/OptimisticLockErrorFilter\";\nexport * from \"./interceptors/TransactionalInterceptor\";\nexport * from \"./services/DBContext\";\nexport * from \"./services/MikroOrmFactory\";\nexport * from \"./services/MikroOrmRegistry\";\nexport * from \"./services/RetryStrategy\";\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
-
import { DBContext, MikroOrmRegistry, RetryStrategy } from "../services.js";
|
|
3
2
|
import { Inject, Interceptor } from "@tsed/di";
|
|
4
3
|
import { Logger } from "@tsed/logger";
|
|
4
|
+
import { MikroOrmRegistry } from "../services/MikroOrmRegistry.js";
|
|
5
|
+
import { DBContext } from "../services/DBContext.js";
|
|
6
|
+
import { RetryStrategy } from "../services/RetryStrategy.js";
|
|
5
7
|
let TransactionalInterceptor = class TransactionalInterceptor {
|
|
6
8
|
constructor(registry, context, logger, retryStrategy) {
|
|
7
9
|
this.registry = registry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionalInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/TransactionalInterceptor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"TransactionalInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/TransactionalInterceptor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAE,WAAW,EAA0D,MAAM,UAAU,CAAC;AAEtG,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AAYxD,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;Q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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,CAmGpC;SAnGY,wBAAwB","sourcesContent":["import {Inject, Interceptor, InterceptorContext, InterceptorMethods, InterceptorNext} from \"@tsed/di\";\nimport {EntityManager} from \"@mikro-orm/core\";\nimport {Logger} from \"@tsed/logger\";\nimport {MikroOrmRegistry} from \"../services/MikroOrmRegistry\";\nimport {DBContext} from \"../services/DBContext\";\nimport {RetryStrategy} from \"../services/RetryStrategy\";\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 = (\n orm.em.fork as (clearOrForkOptions?: boolean | {clear?: boolean; useContext?: boolean}, useContext?: boolean) => EntityManager\n )({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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TransactionOptions } from "../interceptors";
|
|
1
|
+
import { TransactionOptions } from "../interceptors/TransactionalInterceptor";
|
|
2
2
|
/**
|
|
3
3
|
* Register a new request context for your method and execute it inside the context.
|
|
4
4
|
* @param {String | TransactionOptions} contextNameOrOptions
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./services";
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
5
4
|
export * from "./MikroOrmModule";
|
|
5
|
+
export * from "./decorators/entityManager";
|
|
6
|
+
export * from "./decorators/orm";
|
|
7
|
+
export * from "./decorators/transactional";
|
|
8
|
+
export * from "./filters/OptimisticLockErrorFilter";
|
|
9
|
+
export * from "./interceptors/TransactionalInterceptor";
|
|
10
|
+
export * from "./services/DBContext";
|
|
11
|
+
export * from "./services/MikroOrmFactory";
|
|
12
|
+
export * from "./services/MikroOrmRegistry";
|
|
13
|
+
export * from "./services/RetryStrategy";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { DBContext, MikroOrmRegistry, RetryStrategy } from "../services";
|
|
2
1
|
import { InterceptorContext, InterceptorMethods, InterceptorNext } from "@tsed/di";
|
|
3
2
|
import { Logger } from "@tsed/logger";
|
|
3
|
+
import { MikroOrmRegistry } from "../services/MikroOrmRegistry";
|
|
4
|
+
import { DBContext } from "../services/DBContext";
|
|
5
|
+
import { RetryStrategy } from "../services/RetryStrategy";
|
|
4
6
|
export interface TransactionOptions {
|
|
5
7
|
retry?: boolean;
|
|
6
8
|
contextName?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/mikro-orm",
|
|
3
|
-
"version": "6.102.8-rc.
|
|
3
|
+
"version": "6.102.8-rc.2",
|
|
4
4
|
"description": "MikroORM package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
"default": "./lib/esm/index.js"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
18
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
19
19
|
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
20
21
|
"test": "cross-env NODE_ENV=test jest"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
@@ -25,20 +26,20 @@
|
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@mikro-orm/core": "^4.5.9",
|
|
27
28
|
"@mikro-orm/mongodb": "^4.5.9",
|
|
28
|
-
"@tsed/common": "6.102.8-rc.
|
|
29
|
-
"@tsed/core": "6.102.8-rc.
|
|
30
|
-
"@tsed/di": "6.102.8-rc.
|
|
31
|
-
"@tsed/json-mapper": "6.102.8-rc.
|
|
29
|
+
"@tsed/common": "6.102.8-rc.2",
|
|
30
|
+
"@tsed/core": "6.102.8-rc.2",
|
|
31
|
+
"@tsed/di": "6.102.8-rc.2",
|
|
32
|
+
"@tsed/json-mapper": "6.102.8-rc.2",
|
|
32
33
|
"@tsed/logger": ">=6.0.2",
|
|
33
|
-
"@tsed/schema": "6.102.8-rc.
|
|
34
|
-
"@tsed/testing-mongoose": "6.102.8-rc.
|
|
34
|
+
"@tsed/schema": "6.102.8-rc.2",
|
|
35
|
+
"@tsed/testing-mongoose": "6.102.8-rc.2",
|
|
35
36
|
"ts-mockito": "^2.6.1"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"@mikro-orm/core": ">=4.5.9",
|
|
39
|
-
"@tsed/common": "^6.102.8-rc.
|
|
40
|
-
"@tsed/core": "^6.102.8-rc.
|
|
41
|
-
"@tsed/di": "^6.102.8-rc.
|
|
40
|
+
"@tsed/common": "^6.102.8-rc.2",
|
|
41
|
+
"@tsed/core": "^6.102.8-rc.2",
|
|
42
|
+
"@tsed/di": "^6.102.8-rc.2",
|
|
42
43
|
"@tsed/logger": ">=6.0.2"
|
|
43
44
|
},
|
|
44
45
|
"repository": "https://github.com/tsedio/tsed",
|
|
@@ -47,5 +48,8 @@
|
|
|
47
48
|
},
|
|
48
49
|
"homepage": "https://github.com/tsedio/tsed/tree/rc/packages/orm/mikro-orm",
|
|
49
50
|
"author": "Romain Lenzotti",
|
|
50
|
-
"license": "MIT"
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"tag": "rc"
|
|
54
|
+
}
|
|
51
55
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
(0, tslib_1.__exportStar)(require("./transactional"), exports);
|
|
5
|
-
(0, tslib_1.__exportStar)(require("./orm"), exports);
|
|
6
|
-
(0, tslib_1.__exportStar)(require("./entityManager"), exports);
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,+DAAgC;AAChC,qDAAsB;AACtB,+DAAgC","sourcesContent":["export * from \"./transactional\";\nexport * from \"./orm\";\nexport * from \"./entityManager\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./OptimisticLockErrorFilter";
|
package/lib/cjs/filters/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/filters/index.ts"],"names":[],"mappings":";;;AAAA,2EAA4C","sourcesContent":["export * from \"./OptimisticLockErrorFilter\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./TransactionalInterceptor";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interceptors/index.ts"],"names":[],"mappings":";;;AAAA,0EAA2C","sourcesContent":["export * from \"./TransactionalInterceptor\";\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
(0, tslib_1.__exportStar)(require("./DBContext"), exports);
|
|
5
|
-
(0, tslib_1.__exportStar)(require("./MikroOrmFactory"), exports);
|
|
6
|
-
(0, tslib_1.__exportStar)(require("./MikroOrmRegistry"), exports);
|
|
7
|
-
(0, tslib_1.__exportStar)(require("./RetryStrategy"), exports);
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,2DAA4B;AAC5B,iEAAkC;AAClC,kEAAmC;AACnC,+DAAgC","sourcesContent":["export * from \"./DBContext\";\nexport * from \"./MikroOrmFactory\";\nexport * from \"./MikroOrmRegistry\";\nexport * from \"./RetryStrategy\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,OAAO,CAAC;AACtB,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./transactional\";\nexport * from \"./orm\";\nexport * from \"./entityManager\";\n"]}
|
package/lib/esm/filters/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/filters/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC","sourcesContent":["export * from \"./OptimisticLockErrorFilter\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interceptors/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC","sourcesContent":["export * from \"./TransactionalInterceptor\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./DBContext\";\nexport * from \"./MikroOrmFactory\";\nexport * from \"./MikroOrmRegistry\";\nexport * from \"./RetryStrategy\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./OptimisticLockErrorFilter";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./TransactionalInterceptor";
|