@tsed/mikro-orm 6.114.17 → 6.114.18
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 +2 -0
- package/lib/cjs/MikroOrmModule.js.map +1 -1
- package/lib/cjs/decorators/entityManager.d.ts +2 -2
- package/lib/cjs/decorators/entityManager.js +1 -1
- package/lib/cjs/decorators/entityManager.js.map +1 -1
- package/lib/cjs/decorators/orm.d.ts +2 -2
- package/lib/cjs/decorators/transactional.d.ts +1 -1
- package/lib/cjs/interceptors/TransactionalInterceptor.js +7 -4
- package/lib/cjs/interceptors/TransactionalInterceptor.js.map +1 -1
- package/lib/cjs/services/DBContext.js +3 -3
- package/lib/cjs/services/DBContext.js.map +1 -1
- package/lib/cjs/services/MikroOrmFactory.js +1 -0
- package/lib/cjs/services/MikroOrmFactory.js.map +1 -1
- package/lib/cjs/services/MikroOrmRegistry.js +3 -1
- package/lib/cjs/services/MikroOrmRegistry.js.map +1 -1
- package/lib/esm/MikroOrmModule.js +2 -0
- 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/interceptors/TransactionalInterceptor.js +7 -4
- package/lib/esm/interceptors/TransactionalInterceptor.js.map +1 -1
- package/lib/esm/services/DBContext.js +3 -3
- package/lib/esm/services/DBContext.js.map +1 -1
- package/lib/esm/services/MikroOrmFactory.js +1 -0
- package/lib/esm/services/MikroOrmFactory.js.map +1 -1
- package/lib/esm/services/MikroOrmRegistry.js +3 -1
- package/lib/esm/services/MikroOrmRegistry.js.map +1 -1
- package/lib/types/decorators/entityManager.d.ts +2 -2
- package/lib/types/decorators/orm.d.ts +2 -2
- package/lib/types/decorators/transactional.d.ts +1 -1
- package/package.json +10 -10
|
@@ -7,6 +7,8 @@ const MikroOrmRegistry_1 = require("./services/MikroOrmRegistry");
|
|
|
7
7
|
const DBContext_1 = require("./services/DBContext");
|
|
8
8
|
const RetryStrategy_1 = require("./services/RetryStrategy");
|
|
9
9
|
let MikroOrmModule = class MikroOrmModule {
|
|
10
|
+
settings;
|
|
11
|
+
mikroOrmRegistry;
|
|
10
12
|
async $onInit() {
|
|
11
13
|
const promises = this.settings.map((opts) => this.mikroOrmRegistry.register(opts));
|
|
12
14
|
await Promise.all(promises);
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;IAER,QAAQ,CAAa;IAGrB,gBAAgB,CAAoB;IAE9C,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;sCAC2B,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"]}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @decorator
|
|
5
5
|
* @mikroOrm
|
|
6
6
|
*/
|
|
7
|
-
export declare const EntityManager: (contextName?: string
|
|
7
|
+
export declare const EntityManager: (contextName?: string) => PropertyDecorator;
|
|
8
8
|
/**
|
|
9
9
|
* Get the entity manager for the given context name.
|
|
10
10
|
* @param {String} connectionName
|
|
11
11
|
* @decorator
|
|
12
12
|
* @mikroOrm
|
|
13
13
|
*/
|
|
14
|
-
export declare const Em: (contextName?: string
|
|
14
|
+
export declare const Em: (contextName?: string) => PropertyDecorator;
|
|
@@ -9,7 +9,7 @@ const MikroOrmRegistry_1 = require("../services/MikroOrmRegistry");
|
|
|
9
9
|
* @decorator
|
|
10
10
|
* @mikroOrm
|
|
11
11
|
*/
|
|
12
|
-
const EntityManager = (contextName) => (0, di_1.Inject)(MikroOrmRegistry_1.MikroOrmRegistry, (registry) =>
|
|
12
|
+
const EntityManager = (contextName) => (0, di_1.Inject)(MikroOrmRegistry_1.MikroOrmRegistry, (registry) => registry.get(contextName)?.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,mEAA8D;AAE9D;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAAqB,EAAE,CACvE,IAAA,WAAM,EAAC,mCAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,
|
|
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"]}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Get the ORM for the given context name.
|
|
3
3
|
* @param {String} contextName
|
|
4
4
|
*/
|
|
5
|
-
export declare const Orm: (contextName?: string
|
|
5
|
+
export declare const Orm: (contextName?: string) => PropertyDecorator;
|
|
6
6
|
/**
|
|
7
7
|
* Get the ORM for the given context name.
|
|
8
8
|
* @param {String} contextName
|
|
9
9
|
* @deprecated Since 2022-02-01. Use {@link Orm} instead
|
|
10
10
|
*/
|
|
11
|
-
export declare const Connection: (contextName?: string
|
|
11
|
+
export declare const Connection: (contextName?: string) => PropertyDecorator;
|
|
@@ -3,4 +3,4 @@ import { TransactionOptions } from "../interceptors/TransactionalInterceptor";
|
|
|
3
3
|
* Register a new request context for your method and execute it inside the context.
|
|
4
4
|
* @param {String | TransactionOptions} contextNameOrOptions
|
|
5
5
|
*/
|
|
6
|
-
export declare const Transactional: (contextNameOrOptions?: string | TransactionOptions
|
|
6
|
+
export declare const Transactional: (contextNameOrOptions?: string | TransactionOptions) => MethodDecorator;
|
|
@@ -8,6 +8,10 @@ const MikroOrmRegistry_1 = require("../services/MikroOrmRegistry");
|
|
|
8
8
|
const DBContext_1 = require("../services/DBContext");
|
|
9
9
|
const RetryStrategy_1 = require("../services/RetryStrategy");
|
|
10
10
|
let TransactionalInterceptor = class TransactionalInterceptor {
|
|
11
|
+
registry;
|
|
12
|
+
context;
|
|
13
|
+
logger;
|
|
14
|
+
retryStrategy;
|
|
11
15
|
constructor(registry, context, logger, retryStrategy) {
|
|
12
16
|
this.registry = registry;
|
|
13
17
|
this.context = context;
|
|
@@ -51,10 +55,9 @@ let TransactionalInterceptor = class TransactionalInterceptor {
|
|
|
51
55
|
const em = orm.em.fork({ clear: true, useContext: true }, true);
|
|
52
56
|
ctx.set(em.name, em);
|
|
53
57
|
const runInTransaction = () => this.executeInTransaction(options.contextName, next);
|
|
54
|
-
return this.context.run(ctx, () =>
|
|
58
|
+
return this.context.run(ctx, () => (options.retry ? this.retryStrategy?.acquire(runInTransaction) : runInTransaction()));
|
|
55
59
|
}
|
|
56
60
|
extractContextName(context) {
|
|
57
|
-
var _a;
|
|
58
61
|
const options = context.options || {};
|
|
59
62
|
let contextName;
|
|
60
63
|
let retry;
|
|
@@ -62,7 +65,7 @@ let TransactionalInterceptor = class TransactionalInterceptor {
|
|
|
62
65
|
contextName = options;
|
|
63
66
|
}
|
|
64
67
|
else if (options) {
|
|
65
|
-
contextName =
|
|
68
|
+
contextName = options.contextName ?? options.connectionName;
|
|
66
69
|
retry = options.retry;
|
|
67
70
|
}
|
|
68
71
|
if (!contextName) {
|
|
@@ -76,7 +79,7 @@ let TransactionalInterceptor = class TransactionalInterceptor {
|
|
|
76
79
|
async executeInTransaction(contextName, next) {
|
|
77
80
|
const em = this.context.get(contextName);
|
|
78
81
|
const result = await next();
|
|
79
|
-
await
|
|
82
|
+
await em?.flush();
|
|
80
83
|
return result;
|
|
81
84
|
}
|
|
82
85
|
};
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"file":"TransactionalInterceptor.js","sourceRoot":"","sources":["../../../src/interceptors/TransactionalInterceptor.ts"],"names":[],"mappings":";;;;AAAA,iCAAsG;AAEtG,yCAAoC;AACpC,mEAA8D;AAC9D,qDAAgD;AAChD,6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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,EAAE,EAAE,KAAK,EAAE,CAAC;QAElB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAnGY,wBAAwB;IADpC,IAAA,gBAAW,GAAE;IAGT,mBAAA,IAAA,WAAM,GAAE,CAAA;IACR,mBAAA,IAAA,WAAM,GAAE,CAAA;IACR,mBAAA,IAAA,WAAM,GAAE,CAAA;IACR,mBAAA,IAAA,WAAM,EAAC,6BAAa,CAAC,CAAA;6CAHe,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"]}
|
|
@@ -5,8 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const di_1 = require("@tsed/di");
|
|
6
6
|
const async_hooks_1 = require("async_hooks");
|
|
7
7
|
let DBContext = class DBContext {
|
|
8
|
+
storage = new async_hooks_1.AsyncLocalStorage();
|
|
8
9
|
constructor() {
|
|
9
|
-
this.storage = new async_hooks_1.AsyncLocalStorage();
|
|
10
10
|
if (async_hooks_1.AsyncLocalStorage) {
|
|
11
11
|
this.storage = new async_hooks_1.AsyncLocalStorage();
|
|
12
12
|
}
|
|
@@ -28,11 +28,11 @@ let DBContext = class DBContext {
|
|
|
28
28
|
}
|
|
29
29
|
get(contextName) {
|
|
30
30
|
const context = this.entries();
|
|
31
|
-
return context
|
|
31
|
+
return context?.get(contextName);
|
|
32
32
|
}
|
|
33
33
|
has(contextName) {
|
|
34
34
|
const context = this.entries();
|
|
35
|
-
return !!
|
|
35
|
+
return !!context?.has(contextName);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
DBContext = tslib_1.__decorate([
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"DBContext.js","sourceRoot":"","sources":["../../../src/services/DBContext.ts"],"names":[],"mappings":";;;;AAAA,iCAAoC;AAEpC,6CAA8C;AAG9C,IAAa,SAAS,GAAtB,MAAa,SAAS;IACH,OAAO,GAAG,IAAI,+BAAiB,EAA8B,CAAC;IAE/E;QACE,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,EAAE,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,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,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 +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;
|
|
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;IAET,SAAS,CAAa;IAEhC,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;sCACoB,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"]}
|
|
@@ -7,10 +7,12 @@ const di_1 = require("@tsed/di");
|
|
|
7
7
|
const core_1 = require("@tsed/core");
|
|
8
8
|
const logger_1 = require("@tsed/logger");
|
|
9
9
|
let MikroOrmRegistry = class MikroOrmRegistry {
|
|
10
|
+
logger;
|
|
11
|
+
mikroOrmFactory;
|
|
12
|
+
instances = new Map();
|
|
10
13
|
constructor(logger, mikroOrmFactory) {
|
|
11
14
|
this.logger = logger;
|
|
12
15
|
this.mikroOrmFactory = mikroOrmFactory;
|
|
13
|
-
this.instances = new Map();
|
|
14
16
|
}
|
|
15
17
|
async register(options) {
|
|
16
18
|
const contextName = (0, core_1.getValue)(options, "contextName", "default");
|
|
@@ -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;
|
|
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;IAGY;IAA2C;IAFjE,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEzD,YAAuC,MAAc,EAA6B,eAAgC;QAA3E,WAAM,GAAN,MAAM,CAAQ;QAA6B,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAE/G,KAAK,CAAC,QAAQ,CAA2B,OAAmB;QACjE,MAAM,WAAW,GAAG,IAAA,eAAQ,EAAS,OAAO,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QAExE,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAE,CAAC;SAC/B;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iDAAiD,EAAE,WAAW,CAAC,CAAC;QACjF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAE1C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAA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AE,CAAA;IAAmC,mBAAA,IAAA,WAAM,GAAE,CAAA;6CAAjB,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"]}
|
|
@@ -4,6 +4,8 @@ import { MikroOrmRegistry } from "./services/MikroOrmRegistry.js";
|
|
|
4
4
|
import { DBContext } from "./services/DBContext.js";
|
|
5
5
|
import { RetryStrategy } from "./services/RetryStrategy.js";
|
|
6
6
|
let MikroOrmModule = class MikroOrmModule {
|
|
7
|
+
settings;
|
|
8
|
+
mikroOrmRegistry;
|
|
7
9
|
async $onInit() {
|
|
8
10
|
const promises = this.settings.map((opts) => this.mikroOrmRegistry.register(opts));
|
|
9
11
|
await Promise.all(promises);
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;IAER,QAAQ,CAAa;IAGrB,gBAAgB,CAAoB;IAE9C,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"]}
|
|
@@ -6,7 +6,7 @@ import { MikroOrmRegistry } from "../services/MikroOrmRegistry.js";
|
|
|
6
6
|
* @decorator
|
|
7
7
|
* @mikroOrm
|
|
8
8
|
*/
|
|
9
|
-
export const EntityManager = (contextName) => Inject(MikroOrmRegistry, (registry) =>
|
|
9
|
+
export const EntityManager = (contextName) => Inject(MikroOrmRegistry, (registry) => registry.get(contextName)?.em);
|
|
10
10
|
/**
|
|
11
11
|
* Get the entity manager for the given context name.
|
|
12
12
|
* @param {String} connectionName
|
|
@@ -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,8BAA8B,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,WAAoB,EAAqB,EAAE,CACvE,MAAM,CAAC,gBAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,
|
|
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,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,EAAE,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"]}
|
|
@@ -5,6 +5,10 @@ import { MikroOrmRegistry } from "../services/MikroOrmRegistry.js";
|
|
|
5
5
|
import { DBContext } from "../services/DBContext.js";
|
|
6
6
|
import { RetryStrategy } from "../services/RetryStrategy.js";
|
|
7
7
|
let TransactionalInterceptor = class TransactionalInterceptor {
|
|
8
|
+
registry;
|
|
9
|
+
context;
|
|
10
|
+
logger;
|
|
11
|
+
retryStrategy;
|
|
8
12
|
constructor(registry, context, logger, retryStrategy) {
|
|
9
13
|
this.registry = registry;
|
|
10
14
|
this.context = context;
|
|
@@ -48,10 +52,9 @@ let TransactionalInterceptor = class TransactionalInterceptor {
|
|
|
48
52
|
const em = orm.em.fork({ clear: true, useContext: true }, true);
|
|
49
53
|
ctx.set(em.name, em);
|
|
50
54
|
const runInTransaction = () => this.executeInTransaction(options.contextName, next);
|
|
51
|
-
return this.context.run(ctx, () =>
|
|
55
|
+
return this.context.run(ctx, () => (options.retry ? this.retryStrategy?.acquire(runInTransaction) : runInTransaction()));
|
|
52
56
|
}
|
|
53
57
|
extractContextName(context) {
|
|
54
|
-
var _a;
|
|
55
58
|
const options = context.options || {};
|
|
56
59
|
let contextName;
|
|
57
60
|
let retry;
|
|
@@ -59,7 +62,7 @@ let TransactionalInterceptor = class TransactionalInterceptor {
|
|
|
59
62
|
contextName = options;
|
|
60
63
|
}
|
|
61
64
|
else if (options) {
|
|
62
|
-
contextName =
|
|
65
|
+
contextName = options.contextName ?? options.connectionName;
|
|
63
66
|
retry = options.retry;
|
|
64
67
|
}
|
|
65
68
|
if (!contextName) {
|
|
@@ -73,7 +76,7 @@ let TransactionalInterceptor = class TransactionalInterceptor {
|
|
|
73
76
|
async executeInTransaction(contextName, next) {
|
|
74
77
|
const em = this.context.get(contextName);
|
|
75
78
|
const result = await next();
|
|
76
|
-
await
|
|
79
|
+
await em?.flush();
|
|
77
80
|
return result;
|
|
78
81
|
}
|
|
79
82
|
};
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;IAEN;IACA;IACA;IAEV;IALnB,YAC6B,QAA0B,EAC1B,OAAkB,EAClB,MAAc,EAExB,aAA6B;QAJnB,a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AAC;QAEzC,MAAM,MAAM,GAAG,MAAM,IAAI,EAAE,CAAC;QAE5B,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC;QAElB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAnGY,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,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"]}
|
|
@@ -2,8 +2,8 @@ import { __decorate, __metadata } from "tslib";
|
|
|
2
2
|
import { Injectable } from "@tsed/di";
|
|
3
3
|
import { AsyncLocalStorage } from "async_hooks";
|
|
4
4
|
let DBContext = class DBContext {
|
|
5
|
+
storage = new AsyncLocalStorage();
|
|
5
6
|
constructor() {
|
|
6
|
-
this.storage = new AsyncLocalStorage();
|
|
7
7
|
if (AsyncLocalStorage) {
|
|
8
8
|
this.storage = new AsyncLocalStorage();
|
|
9
9
|
}
|
|
@@ -25,11 +25,11 @@ let DBContext = class DBContext {
|
|
|
25
25
|
}
|
|
26
26
|
get(contextName) {
|
|
27
27
|
const context = this.entries();
|
|
28
|
-
return context
|
|
28
|
+
return context?.get(contextName);
|
|
29
29
|
}
|
|
30
30
|
has(contextName) {
|
|
31
31
|
const context = this.entries();
|
|
32
|
-
return !!
|
|
32
|
+
return !!context?.has(contextName);
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
DBContext = __decorate([
|
|
@@ -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;
|
|
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;IACH,OAAO,GAAG,IAAI,iBAAiB,EAA8B,CAAC;IAE/E;QACE,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,EAAE,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,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,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"]}
|
|
@@ -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;
|
|
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;IAET,SAAS,CAAa;IAEhC,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"]}
|
|
@@ -4,10 +4,12 @@ import { Inject, Injectable } from "@tsed/di";
|
|
|
4
4
|
import { catchAsyncError, getValue } from "@tsed/core";
|
|
5
5
|
import { Logger } from "@tsed/logger";
|
|
6
6
|
let MikroOrmRegistry = class MikroOrmRegistry {
|
|
7
|
+
logger;
|
|
8
|
+
mikroOrmFactory;
|
|
9
|
+
instances = new Map();
|
|
7
10
|
constructor(logger, mikroOrmFactory) {
|
|
8
11
|
this.logger = logger;
|
|
9
12
|
this.mikroOrmFactory = mikroOrmFactory;
|
|
10
|
-
this.instances = new Map();
|
|
11
13
|
}
|
|
12
14
|
async register(options) {
|
|
13
15
|
const contextName = getValue(options, "contextName", "default");
|
|
@@ -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;
|
|
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;IAGY;IAA2C;IAFjE,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEzD,YAAuC,MAAc,EAA6B,eAAgC;QAA3E,WAAM,GAAN,MAAM,CAAQ;QAA6B,oBAAe,GAAf,eAAe,CAAiB;IAA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C,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,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"]}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @decorator
|
|
5
5
|
* @mikroOrm
|
|
6
6
|
*/
|
|
7
|
-
export declare const EntityManager: (contextName?: string
|
|
7
|
+
export declare const EntityManager: (contextName?: string) => PropertyDecorator;
|
|
8
8
|
/**
|
|
9
9
|
* Get the entity manager for the given context name.
|
|
10
10
|
* @param {String} connectionName
|
|
11
11
|
* @decorator
|
|
12
12
|
* @mikroOrm
|
|
13
13
|
*/
|
|
14
|
-
export declare const Em: (contextName?: string
|
|
14
|
+
export declare const Em: (contextName?: string) => PropertyDecorator;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Get the ORM for the given context name.
|
|
3
3
|
* @param {String} contextName
|
|
4
4
|
*/
|
|
5
|
-
export declare const Orm: (contextName?: string
|
|
5
|
+
export declare const Orm: (contextName?: string) => PropertyDecorator;
|
|
6
6
|
/**
|
|
7
7
|
* Get the ORM for the given context name.
|
|
8
8
|
* @param {String} contextName
|
|
9
9
|
* @deprecated Since 2022-02-01. Use {@link Orm} instead
|
|
10
10
|
*/
|
|
11
|
-
export declare const Connection: (contextName?: string
|
|
11
|
+
export declare const Connection: (contextName?: string) => PropertyDecorator;
|
|
@@ -3,4 +3,4 @@ import { TransactionOptions } from "../interceptors/TransactionalInterceptor";
|
|
|
3
3
|
* Register a new request context for your method and execute it inside the context.
|
|
4
4
|
* @param {String | TransactionOptions} contextNameOrOptions
|
|
5
5
|
*/
|
|
6
|
-
export declare const Transactional: (contextNameOrOptions?: string | TransactionOptions
|
|
6
|
+
export declare const Transactional: (contextNameOrOptions?: string | TransactionOptions) => MethodDecorator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/mikro-orm",
|
|
3
|
-
"version": "6.114.
|
|
3
|
+
"version": "6.114.18",
|
|
4
4
|
"description": "MikroORM package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -26,20 +26,20 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@mikro-orm/core": "^4.5.9",
|
|
28
28
|
"@mikro-orm/mongodb": "^4.5.9",
|
|
29
|
-
"@tsed/common": "6.114.
|
|
30
|
-
"@tsed/core": "6.114.
|
|
31
|
-
"@tsed/di": "6.114.
|
|
32
|
-
"@tsed/json-mapper": "6.114.
|
|
29
|
+
"@tsed/common": "6.114.18",
|
|
30
|
+
"@tsed/core": "6.114.18",
|
|
31
|
+
"@tsed/di": "6.114.18",
|
|
32
|
+
"@tsed/json-mapper": "6.114.18",
|
|
33
33
|
"@tsed/logger": ">=6.1.4",
|
|
34
|
-
"@tsed/schema": "6.114.
|
|
35
|
-
"@tsed/testing-mongoose": "6.114.
|
|
34
|
+
"@tsed/schema": "6.114.18",
|
|
35
|
+
"@tsed/testing-mongoose": "6.114.18",
|
|
36
36
|
"ts-mockito": "^2.6.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@mikro-orm/core": ">=4.5.9",
|
|
40
|
-
"@tsed/common": "^6.114.
|
|
41
|
-
"@tsed/core": "^6.114.
|
|
42
|
-
"@tsed/di": "^6.114.
|
|
40
|
+
"@tsed/common": "^6.114.18",
|
|
41
|
+
"@tsed/core": "^6.114.18",
|
|
42
|
+
"@tsed/di": "^6.114.18",
|
|
43
43
|
"@tsed/logger": ">=6.1.4"
|
|
44
44
|
},
|
|
45
45
|
"repository": "https://github.com/tsedio/tsed",
|