@tsed/mikro-orm 7.0.0-beta.2 → 7.0.0-beta.20
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/jest.config.js +4 -4
- package/lib/cjs/MikroOrmModule.d.ts +7 -3
- package/lib/cjs/MikroOrmModule.js +30 -12
- package/lib/cjs/MikroOrmModule.js.map +1 -1
- package/lib/cjs/decorators/entityManager.d.ts +6 -6
- package/lib/cjs/decorators/entityManager.js +6 -6
- package/lib/cjs/decorators/entityManager.js.map +1 -1
- package/lib/cjs/decorators/orm.d.ts +5 -0
- package/lib/cjs/decorators/orm.js +12 -0
- package/lib/cjs/decorators/orm.js.map +1 -0
- package/lib/cjs/decorators/transactional.d.ts +6 -2
- package/lib/cjs/decorators/transactional.js +6 -2
- package/lib/cjs/decorators/transactional.js.map +1 -1
- package/lib/cjs/filters/OptimisticLockErrorFilter.js +1 -1
- package/lib/cjs/index.d.ts +12 -4
- package/lib/cjs/index.js +13 -5
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interceptors/TransactionalInterceptor.d.ts +10 -4
- package/lib/cjs/interceptors/TransactionalInterceptor.js +56 -40
- package/lib/cjs/interceptors/TransactionalInterceptor.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/MikroOrmContext.d.ts +9 -0
- package/lib/cjs/services/MikroOrmContext.js +26 -0
- package/lib/cjs/services/MikroOrmContext.js.map +1 -0
- package/lib/cjs/services/MikroOrmFactory.d.ts +4 -2
- package/lib/cjs/services/MikroOrmFactory.js +12 -10
- package/lib/cjs/services/MikroOrmFactory.js.map +1 -1
- package/lib/cjs/services/MikroOrmRegistry.d.ts +7 -5
- package/lib/cjs/services/MikroOrmRegistry.js +32 -27
- package/lib/cjs/services/MikroOrmRegistry.js.map +1 -1
- package/lib/esm/MikroOrmModule.js +25 -7
- package/lib/esm/MikroOrmModule.js.map +1 -1
- package/lib/esm/decorators/entityManager.js +6 -6
- package/lib/esm/decorators/entityManager.js.map +1 -1
- package/lib/esm/decorators/orm.js +8 -0
- package/lib/esm/decorators/orm.js.map +1 -0
- package/lib/esm/decorators/transactional.js +6 -2
- package/lib/esm/decorators/transactional.js.map +1 -1
- package/lib/esm/index.js +13 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interceptors/TransactionalInterceptor.js +49 -33
- package/lib/esm/interceptors/TransactionalInterceptor.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/MikroOrmContext.js +23 -0
- package/lib/esm/services/MikroOrmContext.js.map +1 -0
- package/lib/esm/services/MikroOrmFactory.js +12 -10
- package/lib/esm/services/MikroOrmFactory.js.map +1 -1
- package/lib/esm/services/MikroOrmRegistry.js +29 -24
- package/lib/esm/services/MikroOrmRegistry.js.map +1 -1
- package/lib/types/MikroOrmModule.d.ts +7 -3
- package/lib/types/decorators/entityManager.d.ts +6 -6
- package/lib/types/decorators/orm.d.ts +5 -0
- package/lib/types/decorators/transactional.d.ts +6 -2
- package/lib/types/index.d.ts +12 -4
- package/lib/types/interceptors/TransactionalInterceptor.d.ts +10 -4
- package/lib/types/services/MikroOrmContext.d.ts +9 -0
- package/lib/types/services/MikroOrmFactory.d.ts +4 -2
- package/lib/types/services/MikroOrmRegistry.d.ts +7 -5
- package/package.json +23 -18
- package/readme.md +75 -46
- package/tsconfig.compile.esm.json +1 -12
- package/lib/cjs/decorators/connection.d.ts +0 -1
- package/lib/cjs/decorators/connection.js +0 -8
- package/lib/cjs/decorators/connection.js.map +0 -1
- 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/DBContext.d.ts +0 -9
- package/lib/cjs/services/DBContext.js +0 -37
- package/lib/cjs/services/DBContext.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/connection.js +0 -4
- package/lib/esm/decorators/connection.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/DBContext.js +0 -34
- package/lib/esm/services/DBContext.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/connection.d.ts +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/DBContext.d.ts +0 -9
- package/lib/types/services/index.d.ts +0 -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:
|
|
9
|
-
functions:
|
|
10
|
-
lines:
|
|
11
|
-
statements:
|
|
8
|
+
branches: 95.83,
|
|
9
|
+
functions: 94.73,
|
|
10
|
+
lines: 97.43,
|
|
11
|
+
statements: 97.88
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./services/MikroOrmFactory";
|
|
2
|
+
import { AlterRunInContext, OnDestroy, OnInit } from "@tsed/di";
|
|
2
3
|
import { Options } from "@mikro-orm/core";
|
|
3
4
|
declare global {
|
|
4
5
|
namespace TsED {
|
|
@@ -11,9 +12,12 @@ declare global {
|
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
|
-
export declare class MikroOrmModule implements OnDestroy, OnInit {
|
|
15
|
+
export declare class MikroOrmModule implements OnDestroy, OnInit, AlterRunInContext {
|
|
15
16
|
private readonly settings;
|
|
16
|
-
private readonly
|
|
17
|
+
private readonly registry;
|
|
18
|
+
private readonly context;
|
|
17
19
|
$onInit(): Promise<void>;
|
|
18
20
|
$onDestroy(): Promise<void>;
|
|
21
|
+
$alterRunInContext(next: (...args: unknown[]) => unknown): () => unknown | Promise<() => unknown>;
|
|
22
|
+
private createContext;
|
|
19
23
|
}
|
|
@@ -2,32 +2,50 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MikroOrmModule = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
|
|
5
|
+
require("./services/MikroOrmFactory");
|
|
6
6
|
const di_1 = require("@tsed/di");
|
|
7
|
+
const MikroOrmRegistry_1 = require("./services/MikroOrmRegistry");
|
|
8
|
+
const RetryStrategy_1 = require("./services/RetryStrategy");
|
|
9
|
+
const OptimisticLockErrorFilter_1 = require("./filters/OptimisticLockErrorFilter");
|
|
10
|
+
const MikroOrmContext_1 = require("./services/MikroOrmContext");
|
|
7
11
|
let MikroOrmModule = class MikroOrmModule {
|
|
12
|
+
settings;
|
|
13
|
+
registry;
|
|
14
|
+
context;
|
|
8
15
|
async $onInit() {
|
|
9
|
-
const promises = this.settings.map((opts) => this.
|
|
16
|
+
const promises = this.settings.map((opts) => this.registry.register(opts));
|
|
10
17
|
await Promise.all(promises);
|
|
11
18
|
}
|
|
12
19
|
$onDestroy() {
|
|
13
|
-
return this.
|
|
20
|
+
return this.registry.clear();
|
|
21
|
+
}
|
|
22
|
+
$alterRunInContext(next) {
|
|
23
|
+
return () => this.createContext(next);
|
|
24
|
+
}
|
|
25
|
+
createContext(next) {
|
|
26
|
+
const instances = [...this.registry.values()];
|
|
27
|
+
const managers = instances.map((orm) => orm.em);
|
|
28
|
+
return this.context.run(managers, next);
|
|
14
29
|
}
|
|
15
30
|
};
|
|
16
|
-
|
|
31
|
+
tslib_1.__decorate([
|
|
17
32
|
(0, di_1.Constant)("mikroOrm", []),
|
|
18
|
-
|
|
33
|
+
tslib_1.__metadata("design:type", Array)
|
|
19
34
|
], MikroOrmModule.prototype, "settings", void 0);
|
|
20
|
-
|
|
35
|
+
tslib_1.__decorate([
|
|
36
|
+
(0, di_1.Inject)(),
|
|
37
|
+
tslib_1.__metadata("design:type", MikroOrmRegistry_1.MikroOrmRegistry)
|
|
38
|
+
], MikroOrmModule.prototype, "registry", void 0);
|
|
39
|
+
tslib_1.__decorate([
|
|
21
40
|
(0, di_1.Inject)(),
|
|
22
|
-
|
|
23
|
-
], MikroOrmModule.prototype, "
|
|
24
|
-
MikroOrmModule =
|
|
41
|
+
tslib_1.__metadata("design:type", MikroOrmContext_1.MikroOrmContext)
|
|
42
|
+
], MikroOrmModule.prototype, "context", void 0);
|
|
43
|
+
MikroOrmModule = tslib_1.__decorate([
|
|
25
44
|
(0, di_1.Module)({
|
|
26
|
-
|
|
27
|
-
deps: [di_1.Configuration, services_1.MikroOrmRegistry]
|
|
45
|
+
responseFilters: [OptimisticLockErrorFilter_1.OptimisticLockErrorFilter]
|
|
28
46
|
})
|
|
29
47
|
], MikroOrmModule);
|
|
30
48
|
exports.MikroOrmModule = MikroOrmModule;
|
|
31
49
|
// TODO: the IoC container should provide null or undefined by default until tsedio/tsed#1694 is closed
|
|
32
|
-
(0, di_1.registerProvider)({ provide:
|
|
50
|
+
(0, di_1.registerProvider)({ provide: RetryStrategy_1.RetryStrategy, useValue: null });
|
|
33
51
|
//# 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,sCAAoC;AACpC,iCAAqH;AAErH,kEAA6D;AAC7D,4DAAuD;AACvD,mFAA8E;AAC9E,gEAA2D;AAkB3D,IAAa,cAAc,GAA3B,MAAa,cAAc;IAER,QAAQ,CAAa;IAGrB,QAAQ,CAAoB;IAG5B,OAAO,CAAmB;IAEpC,KAAK,CAAC,OAAO;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAE3E,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;IAEM,kBAAkB,CAAC,IAAqC;QAC7D,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAEO,aAAa,CAAC,IAAqC;QACzD,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAEhD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF,CAAA;AA5BC;IADC,IAAA,aAAQ,EAAC,UAAU,EAAE,EAAE,CAAC;;gDACa;AAGtC;IADC,IAAA,WAAM,GAAE;sCACmB,mCAAgB;gDAAC;AAG7C;IADC,IAAA,WAAM,GAAE;sCACkB,iCAAe;+CAAC;AARhC,cAAc;IAH1B,IAAA,WAAM,EAAC;QACN,eAAe,EAAE,CAAC,qDAAyB,CAAC;KAC7C,CAAC;GACW,cAAc,CA8B1B;AA9BY,wCAAc;AAgC3B,uGAAuG;AACvG,IAAA,qBAAgB,EAAC,EAAC,OAAO,EAAE,6BAAa,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAC","sourcesContent":["import \"./services/MikroOrmFactory\";\nimport {AlterRunInContext, Constant, DIContext, Inject, Module, OnDestroy, OnInit, registerProvider} from \"@tsed/di\";\nimport {Options} from \"@mikro-orm/core\";\nimport {MikroOrmRegistry} from \"./services/MikroOrmRegistry\";\nimport {RetryStrategy} from \"./services/RetryStrategy\";\nimport {OptimisticLockErrorFilter} from \"./filters/OptimisticLockErrorFilter\";\nimport {MikroOrmContext} from \"./services/MikroOrmContext\";\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 responseFilters: [OptimisticLockErrorFilter]\n})\nexport class MikroOrmModule implements OnDestroy, OnInit, AlterRunInContext {\n @Constant(\"mikroOrm\", [])\n private readonly settings!: Options[];\n\n @Inject()\n private readonly registry!: MikroOrmRegistry;\n\n @Inject()\n private readonly context!: MikroOrmContext;\n\n public async $onInit(): Promise<void> {\n const promises = this.settings.map((opts) => this.registry.register(opts));\n\n await Promise.all(promises);\n }\n\n public $onDestroy(): Promise<void> {\n return this.registry.clear();\n }\n\n public $alterRunInContext(next: (...args: unknown[]) => unknown): () => unknown | Promise<() => unknown> {\n return () => this.createContext(next);\n }\n\n private createContext(next: (...args: unknown[]) => unknown): unknown {\n const instances = [...this.registry.values()];\n const managers = instances.map((orm) => orm.em);\n\n return this.context.run(managers, next);\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
|
|
3
|
-
* @param
|
|
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: (
|
|
7
|
+
export declare const EntityManager: (contextName?: string) => PropertyDecorator;
|
|
8
8
|
/**
|
|
9
|
-
* Get the entity manager for the given
|
|
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: (
|
|
14
|
+
export declare const Em: (contextName?: string) => PropertyDecorator;
|
|
@@ -2,18 +2,18 @@
|
|
|
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
|
-
* Get the entity manager for the given
|
|
8
|
-
* @param
|
|
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 = (
|
|
12
|
+
const EntityManager = (contextName) => (0, di_1.Inject)(MikroOrmRegistry_1.MikroOrmRegistry, (registry) => registry.get(contextName)?.em);
|
|
13
13
|
exports.EntityManager = EntityManager;
|
|
14
14
|
/**
|
|
15
|
-
* Get the entity manager for the given
|
|
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,
|
|
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,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,EAAE,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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Orm = void 0;
|
|
4
|
+
const MikroOrmRegistry_1 = require("../services/MikroOrmRegistry");
|
|
5
|
+
const di_1 = require("@tsed/di");
|
|
6
|
+
/**
|
|
7
|
+
* Get the ORM for the given context name.
|
|
8
|
+
* @param {String} contextName
|
|
9
|
+
*/
|
|
10
|
+
const Orm = (contextName) => (0, di_1.Inject)(MikroOrmRegistry_1.MikroOrmRegistry, (registry) => registry.get(contextName));
|
|
11
|
+
exports.Orm = Orm;
|
|
12
|
+
//# sourceMappingURL=orm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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","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"]}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import { TransactionOptions } from "../interceptors";
|
|
2
|
-
|
|
1
|
+
import { TransactionOptions } from "../interceptors/TransactionalInterceptor";
|
|
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) => MethodDecorator;
|
|
@@ -1,8 +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");
|
|
6
|
-
const
|
|
5
|
+
const TransactionalInterceptor_1 = require("../interceptors/TransactionalInterceptor");
|
|
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)(TransactionalInterceptor_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,
|
|
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"]}
|
|
@@ -13,7 +13,7 @@ let OptimisticLockErrorFilter = class OptimisticLockErrorFilter {
|
|
|
13
13
|
response.status(409).body(`Update refused. The resource has changed on the server. Please try again later`);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
OptimisticLockErrorFilter =
|
|
16
|
+
OptimisticLockErrorFilter = tslib_1.__decorate([
|
|
17
17
|
(0, common_1.Catch)(core_1.OptimisticLockError)
|
|
18
18
|
], OptimisticLockErrorFilter);
|
|
19
19
|
exports.OptimisticLockErrorFilter = OptimisticLockErrorFilter;
|
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/MikroOrmContext";
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
tslib_1.__exportStar(require("./MikroOrmModule"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./decorators/entityManager"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./decorators/orm"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./decorators/transactional"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./filters/OptimisticLockErrorFilter"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./interceptors/TransactionalInterceptor"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./services/MikroOrmContext"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./services/MikroOrmFactory"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./services/MikroOrmRegistry"), exports);
|
|
16
|
+
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,2DAAiC;AACjC,qEAA2C;AAC3C,2DAAiC;AACjC,qEAA2C;AAC3C,8EAAoD;AACpD,kFAAwD;AACxD,qEAA2C;AAC3C,qEAA2C;AAC3C,sEAA4C;AAC5C,mEAAyC","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/MikroOrmContext\";\nexport * from \"./services/MikroOrmFactory\";\nexport * from \"./services/MikroOrmRegistry\";\nexport * from \"./services/RetryStrategy\";\n"]}
|
|
@@ -1,19 +1,25 @@
|
|
|
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 { RetryStrategy } from "../services/RetryStrategy";
|
|
4
|
+
import { MikroOrmContext } from "../services/MikroOrmContext";
|
|
5
|
+
import { MikroOrmRegistry } from "../services/MikroOrmRegistry";
|
|
6
|
+
import { FlushMode, IsolationLevel } from "@mikro-orm/core";
|
|
4
7
|
export interface TransactionOptions {
|
|
5
|
-
connectionName?: string;
|
|
6
8
|
retry?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
isolationLevel?: IsolationLevel;
|
|
11
|
+
flushMode?: FlushMode;
|
|
12
|
+
contextName?: string;
|
|
7
13
|
}
|
|
8
14
|
export declare class TransactionalInterceptor implements InterceptorMethods {
|
|
9
15
|
private readonly registry;
|
|
10
16
|
private readonly context;
|
|
11
17
|
private readonly logger;
|
|
12
18
|
private readonly retryStrategy?;
|
|
13
|
-
constructor(registry: MikroOrmRegistry, context:
|
|
19
|
+
constructor(registry: MikroOrmRegistry, context: MikroOrmContext, logger: Logger, retryStrategy?: RetryStrategy | undefined);
|
|
14
20
|
intercept(context: InterceptorContext<unknown>, next: InterceptorNext): Promise<unknown>;
|
|
21
|
+
private runWithinCtx;
|
|
15
22
|
private runWithinNewCtx;
|
|
16
|
-
private runUnderCtx;
|
|
17
23
|
private extractContextName;
|
|
18
24
|
private executeInTransaction;
|
|
19
25
|
}
|
|
@@ -2,10 +2,17 @@
|
|
|
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 RetryStrategy_1 = require("../services/RetryStrategy");
|
|
8
|
+
const MikroOrmContext_1 = require("../services/MikroOrmContext");
|
|
9
|
+
const MikroOrmRegistry_1 = require("../services/MikroOrmRegistry");
|
|
10
|
+
const core_1 = require("@mikro-orm/core");
|
|
8
11
|
let TransactionalInterceptor = class TransactionalInterceptor {
|
|
12
|
+
registry;
|
|
13
|
+
context;
|
|
14
|
+
logger;
|
|
15
|
+
retryStrategy;
|
|
9
16
|
constructor(registry, context, logger, retryStrategy) {
|
|
10
17
|
this.registry = registry;
|
|
11
18
|
this.context = context;
|
|
@@ -15,62 +22,71 @@ let TransactionalInterceptor = class TransactionalInterceptor {
|
|
|
15
22
|
async intercept(context, next) {
|
|
16
23
|
const options = this.extractContextName(context);
|
|
17
24
|
if (options.retry && !this.retryStrategy) {
|
|
18
|
-
this.logger.warn(`To retry a transaction you have to implement a "${
|
|
25
|
+
this.logger.warn(`To retry a transaction you have to implement a "${RetryStrategy_1.RetryStrategy.description}" interface`);
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return this.runWithinNewCtx(next, options);
|
|
27
|
+
if (this.context.has(options.contextName)) {
|
|
28
|
+
return this.runWithinCtx(next, options);
|
|
23
29
|
}
|
|
24
|
-
|
|
25
|
-
return next();
|
|
26
|
-
}
|
|
27
|
-
return this.runUnderCtx(next, ctx, options);
|
|
30
|
+
return this.runWithinNewCtx(next, options);
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
return this.
|
|
32
|
+
runWithinCtx(next, options) {
|
|
33
|
+
const callback = () => this.executeInTransaction(next, options);
|
|
34
|
+
return options.retry && this.retryStrategy ? this.retryStrategy.acquire(callback) : callback();
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
const orm = this.registry.get(options.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return this.context.run(
|
|
36
|
+
runWithinNewCtx(next, options) {
|
|
37
|
+
const orm = this.registry.get(options.contextName);
|
|
38
|
+
if (!orm) {
|
|
39
|
+
throw new Error(`No such context: ${options.contextName}. Please register a corresponding MikroOrm instance using '@Configuration()' decorator.`);
|
|
40
|
+
}
|
|
41
|
+
return this.context.run([orm.em], () => this.runWithinCtx(next, options));
|
|
39
42
|
}
|
|
40
43
|
extractContextName(context) {
|
|
41
|
-
const options = context.options || {};
|
|
42
|
-
let
|
|
44
|
+
const options = (context.options || {});
|
|
45
|
+
let isolationLevel;
|
|
46
|
+
let disabled;
|
|
47
|
+
let contextName;
|
|
48
|
+
let flushMode;
|
|
43
49
|
let retry;
|
|
44
50
|
if (typeof options === "string") {
|
|
45
|
-
|
|
51
|
+
contextName = options;
|
|
46
52
|
}
|
|
47
53
|
else if (options) {
|
|
48
|
-
|
|
54
|
+
contextName = options.contextName;
|
|
55
|
+
isolationLevel = options.isolationLevel;
|
|
49
56
|
retry = options.retry;
|
|
57
|
+
disabled = options.disabled;
|
|
58
|
+
flushMode = options.flushMode;
|
|
50
59
|
}
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
return {
|
|
61
|
+
flushMode,
|
|
62
|
+
retry: retry ?? false,
|
|
63
|
+
disabled: disabled ?? false,
|
|
64
|
+
contextName: contextName ?? "default",
|
|
65
|
+
isolationLevel: isolationLevel ?? core_1.IsolationLevel.READ_COMMITTED
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async executeInTransaction(next, options) {
|
|
69
|
+
const manager = this.context.get(options.contextName);
|
|
70
|
+
if (!manager) {
|
|
71
|
+
throw new Error(`No such context: ${options.contextName}. Please check if the async context is lost in one of the asynchronous operations.`);
|
|
53
72
|
}
|
|
54
|
-
if (
|
|
55
|
-
|
|
73
|
+
if (options.disabled) {
|
|
74
|
+
return next();
|
|
56
75
|
}
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const result = await next();
|
|
62
|
-
await (em === null || em === void 0 ? void 0 : em.flush());
|
|
63
|
-
return result;
|
|
76
|
+
return manager.transactional(() => next(), {
|
|
77
|
+
flushMode: options.flushMode,
|
|
78
|
+
isolationLevel: options.isolationLevel
|
|
79
|
+
});
|
|
64
80
|
}
|
|
65
81
|
};
|
|
66
|
-
TransactionalInterceptor =
|
|
82
|
+
TransactionalInterceptor = tslib_1.__decorate([
|
|
67
83
|
(0, di_1.Interceptor)(),
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
84
|
+
tslib_1.__param(0, (0, di_1.Inject)()),
|
|
85
|
+
tslib_1.__param(1, (0, di_1.Inject)()),
|
|
86
|
+
tslib_1.__param(2, (0, di_1.Inject)()),
|
|
87
|
+
tslib_1.__param(3, (0, di_1.Inject)(RetryStrategy_1.RetryStrategy)),
|
|
88
|
+
tslib_1.__metadata("design:paramtypes", [MikroOrmRegistry_1.MikroOrmRegistry,
|
|
89
|
+
MikroOrmContext_1.MikroOrmContext,
|
|
74
90
|
logger_1.Logger, Object])
|
|
75
91
|
], TransactionalInterceptor);
|
|
76
92
|
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":"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","sourcesContent":["import {Inject, Interceptor, InterceptorContext, InterceptorMethods, InterceptorNext} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {RetryStrategy} from \"../services/RetryStrategy\";\nimport {MikroOrmContext} from \"../services/MikroOrmContext\";\nimport {MikroOrmRegistry} from \"../services/MikroOrmRegistry\";\nimport {FlushMode, IsolationLevel} from \"@mikro-orm/core\";\n\nexport interface TransactionOptions {\n retry?: boolean;\n disabled?: boolean;\n isolationLevel?: IsolationLevel;\n flushMode?: FlushMode;\n contextName?: string;\n}\n\ntype TransactionSettings = Required<Omit<TransactionOptions, \"connectionName\" | \"flushMode\">> & {flushMode?: FlushMode};\n\n@Interceptor()\nexport class TransactionalInterceptor implements InterceptorMethods {\n constructor(\n @Inject() private readonly registry: MikroOrmRegistry,\n @Inject() private readonly context: MikroOrmContext,\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 if (this.context.has(options.contextName)) {\n return this.runWithinCtx(next, options);\n }\n\n return this.runWithinNewCtx(next, options);\n }\n\n private runWithinCtx(next: InterceptorNext, options: TransactionSettings): Promise<unknown> | unknown {\n const callback = () => this.executeInTransaction(next, options);\n\n return options.retry && this.retryStrategy ? this.retryStrategy.acquire(callback) : callback();\n }\n\n private runWithinNewCtx(next: InterceptorNext, options: TransactionSettings): 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 return this.context.run([orm.em], () => this.runWithinCtx(next, options));\n }\n\n private extractContextName(context: InterceptorContext<unknown>): TransactionSettings {\n const options = (context.options || {}) as TransactionOptions | string;\n\n let isolationLevel: IsolationLevel | undefined;\n let disabled: boolean | undefined;\n let contextName: string | undefined;\n let flushMode: FlushMode | undefined;\n let retry: boolean | undefined;\n\n if (typeof options === \"string\") {\n contextName = options;\n } else if (options) {\n contextName = options.contextName;\n isolationLevel = options.isolationLevel;\n retry = options.retry;\n disabled = options.disabled;\n flushMode = options.flushMode;\n }\n\n return {\n flushMode,\n retry: retry ?? false,\n disabled: disabled ?? false,\n contextName: contextName ?? \"default\",\n isolationLevel: isolationLevel ?? IsolationLevel.READ_COMMITTED\n };\n }\n\n private async executeInTransaction(next: InterceptorNext, options: TransactionSettings): Promise<unknown> {\n const manager = this.context.get(options.contextName);\n\n if (!manager) {\n throw new Error(\n `No such context: ${options.contextName}. Please check if the async context is lost in one of the asynchronous operations.`\n );\n }\n\n if (options.disabled) {\n return next();\n }\n\n return manager.transactional(() => next(), {\n flushMode: options.flushMode,\n isolationLevel: options.isolationLevel\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EntityManager } from "@mikro-orm/core";
|
|
2
|
+
/**
|
|
3
|
+
* @internal Since 2022-06-20.
|
|
4
|
+
*/
|
|
5
|
+
export declare class MikroOrmContext {
|
|
6
|
+
run(managers: EntityManager[], task: (...args: unknown[]) => unknown): Promise<unknown>;
|
|
7
|
+
get(contextName?: string): EntityManager | undefined;
|
|
8
|
+
has(contextName?: string): boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MikroOrmContext = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const di_1 = require("@tsed/di");
|
|
6
|
+
const core_1 = require("@mikro-orm/core");
|
|
7
|
+
/**
|
|
8
|
+
* @internal Since 2022-06-20.
|
|
9
|
+
*/
|
|
10
|
+
let MikroOrmContext = class MikroOrmContext {
|
|
11
|
+
run(managers, task) {
|
|
12
|
+
return core_1.RequestContext.createAsync(managers, task);
|
|
13
|
+
}
|
|
14
|
+
get(contextName) {
|
|
15
|
+
return core_1.RequestContext.getEntityManager(contextName);
|
|
16
|
+
}
|
|
17
|
+
has(contextName) {
|
|
18
|
+
const manager = this.get(contextName);
|
|
19
|
+
return !!manager;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
MikroOrmContext = tslib_1.__decorate([
|
|
23
|
+
(0, di_1.Injectable)()
|
|
24
|
+
], MikroOrmContext);
|
|
25
|
+
exports.MikroOrmContext = MikroOrmContext;
|
|
26
|
+
//# sourceMappingURL=MikroOrmContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MikroOrmContext.js","sourceRoot":"","sources":["../../../src/services/MikroOrmContext.ts"],"names":[],"mappings":";;;;AAAA,iCAAoC;AACpC,0CAA8D;AAE9D;;GAEG;AAEH,IAAa,eAAe,GAA5B,MAAa,eAAe;IACnB,GAAG,CAAC,QAAyB,EAAE,IAAqC;QACzE,OAAO,qBAAc,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAW,CAAC,CAAC;IAC3D,CAAC;IAEM,GAAG,CAAC,WAAoB;QAC7B,OAAO,qBAAc,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACtD,CAAC;IAEM,GAAG,CAAC,WAAoB;QAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAEtC,OAAO,CAAC,CAAC,OAAO,CAAC;IACnB,CAAC;CACF,CAAA;AAdY,eAAe;IAD3B,IAAA,eAAU,GAAE;GACA,eAAe,CAc3B;AAdY,0CAAe","sourcesContent":["import {Injectable} from \"@tsed/di\";\nimport {EntityManager, RequestContext} from \"@mikro-orm/core\";\n\n/**\n * @internal Since 2022-06-20.\n */\n@Injectable()\nexport class MikroOrmContext {\n public run(managers: EntityManager[], task: (...args: unknown[]) => unknown): Promise<unknown> {\n return RequestContext.createAsync(managers, task as any);\n }\n\n public get(contextName?: string): EntityManager | undefined {\n return RequestContext.getEntityManager(contextName);\n }\n\n public has(contextName?: string): boolean {\n const manager = this.get(contextName);\n\n return !!manager;\n }\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { MikroORM, Options } from "@mikro-orm/core";
|
|
2
|
+
import { MikroOrmContext } from "./MikroOrmContext";
|
|
2
3
|
export declare class MikroOrmFactory {
|
|
3
|
-
private readonly
|
|
4
|
-
|
|
4
|
+
private readonly context;
|
|
5
|
+
constructor(context: MikroOrmContext);
|
|
6
|
+
create(options: Options): Promise<MikroORM>;
|
|
5
7
|
}
|
|
@@ -2,23 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MikroOrmFactory = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const DBContext_1 = require("./DBContext");
|
|
6
5
|
const core_1 = require("@mikro-orm/core");
|
|
7
6
|
const di_1 = require("@tsed/di");
|
|
7
|
+
const MikroOrmContext_1 = require("./MikroOrmContext");
|
|
8
8
|
let MikroOrmFactory = class MikroOrmFactory {
|
|
9
|
-
|
|
9
|
+
context;
|
|
10
|
+
constructor(context) {
|
|
11
|
+
this.context = context;
|
|
12
|
+
}
|
|
13
|
+
create(options) {
|
|
10
14
|
return core_1.MikroORM.init({
|
|
11
|
-
...
|
|
12
|
-
context: (name) => this.
|
|
15
|
+
...options,
|
|
16
|
+
context: (name) => this.context.get(name)
|
|
13
17
|
});
|
|
14
18
|
}
|
|
15
19
|
};
|
|
16
|
-
|
|
17
|
-
(0, di_1.
|
|
18
|
-
(0,
|
|
19
|
-
|
|
20
|
-
MikroOrmFactory = (0, tslib_1.__decorate)([
|
|
21
|
-
(0, di_1.Injectable)()
|
|
20
|
+
MikroOrmFactory = tslib_1.__decorate([
|
|
21
|
+
(0, di_1.Injectable)(),
|
|
22
|
+
tslib_1.__param(0, (0, di_1.Inject)()),
|
|
23
|
+
tslib_1.__metadata("design:paramtypes", [MikroOrmContext_1.MikroOrmContext])
|
|
22
24
|
], MikroOrmFactory);
|
|
23
25
|
exports.MikroOrmFactory = MikroOrmFactory;
|
|
24
26
|
//# sourceMappingURL=MikroOrmFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MikroOrmFactory.js","sourceRoot":"","sources":["../../../src/services/MikroOrmFactory.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"MikroOrmFactory.js","sourceRoot":"","sources":["../../../src/services/MikroOrmFactory.ts"],"names":[],"mappings":";;;;AAAA,0CAAkD;AAClD,iCAA4C;AAC5C,uDAAkD;AAGlD,IAAa,eAAe,GAA5B,MAAa,eAAe;IACa;IAAvC,YAAuC,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAAG,CAAC;IAE5D,MAAM,CAAC,OAAgB;QAC5B,OAAO,eAAQ,CAAC,IAAI,CAAC;YACnB,GAAG,OAAO;YACV,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;SAClD,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AATY,eAAe;IAD3B,IAAA,eAAU,GAAE;IAEE,mBAAA,IAAA,WAAM,GAAE,CAAA;6CAA2B,iCAAe;GADpD,eAAe,CAS3B;AATY,0CAAe","sourcesContent":["import {MikroORM, Options} from \"@mikro-orm/core\";\nimport {Inject, Injectable} from \"@tsed/di\";\nimport {MikroOrmContext} from \"./MikroOrmContext\";\n\n@Injectable()\nexport class MikroOrmFactory {\n constructor(@Inject() private readonly context: MikroOrmContext) {}\n\n public create(options: Options): Promise<MikroORM> {\n return MikroORM.init({\n ...options,\n context: (name: string) => this.context.get(name)\n });\n }\n}\n"]}
|