@tsed/mikro-orm 7.31.0 → 7.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  import "./services/MikroOrmFactory";
2
2
  import { AlterRunInContext, OnDestroy, OnInit } from "@tsed/di";
3
- import { Options } from "@mikro-orm/core";
3
+ import { EventSubscriber, Options } from "@mikro-orm/core";
4
4
  declare global {
5
5
  namespace TsED {
6
6
  interface Configuration {
7
7
  /**
8
- * The the ORM configuration, entity metadata.
8
+ * The ORM configuration, entity metadata.
9
9
  * If you omit the `options` parameter, your CLI config will be used.
10
10
  */
11
11
  mikroOrm?: Options[];
@@ -13,11 +13,17 @@ declare global {
13
13
  }
14
14
  }
15
15
  export declare class MikroOrmModule implements OnDestroy, OnInit, AlterRunInContext {
16
+ private subscribers;
16
17
  private readonly settings;
17
18
  private readonly registry;
18
19
  private readonly context;
20
+ private readonly injector;
21
+ constructor(subscribers: EventSubscriber[]);
19
22
  $onInit(): Promise<void>;
20
23
  $onDestroy(): Promise<void>;
21
24
  $alterRunInContext(next: (...args: unknown[]) => unknown): () => unknown | Promise<() => unknown>;
25
+ private getSubscribers;
26
+ private getUnmanagedSubscribers;
27
+ private getManagedSubscribers;
22
28
  private createContext;
23
29
  }
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_CONTEXT_NAME = "default";
2
+ export declare const SUBSCRIBER_INJECTION_TYPE: unique symbol;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Register a new subscriber for the given context name.
3
+ * @decorator
4
+ * @mikroOrm
5
+ */
6
+ export declare const Subscriber: (options?: {
7
+ contextName: string;
8
+ }) => any;
@@ -2,8 +2,10 @@
2
2
  * @file Automatically generated by barrelsby.
3
3
  */
4
4
  export * from "./MikroOrmModule";
5
+ export * from "./constants";
5
6
  export * from "./decorators/entityManager";
6
7
  export * from "./decorators/orm";
8
+ export * from "./decorators/subscriber";
7
9
  export * from "./decorators/transactional";
8
10
  export * from "./filters/OptimisticLockErrorFilter";
9
11
  export * from "./interceptors/TransactionalInterceptor";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/mikro-orm",
3
- "version": "7.31.0",
3
+ "version": "7.33.0",
4
4
  "description": "MikroORM package for Ts.ED framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -27,23 +27,23 @@
27
27
  "devDependencies": {
28
28
  "@mikro-orm/core": "^5.2.2",
29
29
  "@mikro-orm/mongodb": "^5.2.2",
30
- "@tsed/common": "7.31.0",
31
- "@tsed/core": "7.31.0",
32
- "@tsed/di": "7.31.0",
33
- "@tsed/eslint": "7.31.0",
34
- "@tsed/json-mapper": "7.31.0",
30
+ "@tsed/common": "7.33.0",
31
+ "@tsed/core": "7.33.0",
32
+ "@tsed/di": "7.33.0",
33
+ "@tsed/eslint": "7.33.0",
34
+ "@tsed/json-mapper": "7.33.0",
35
35
  "@tsed/logger": ">=6.1.1",
36
- "@tsed/schema": "7.31.0",
37
- "@tsed/testing-mongoose": "7.31.0",
38
- "@tsed/typescript": "7.31.0",
36
+ "@tsed/schema": "7.33.0",
37
+ "@tsed/testing-mongoose": "7.33.0",
38
+ "@tsed/typescript": "7.33.0",
39
39
  "eslint": "^8.12.0",
40
40
  "ts-mockito": "^2.6.1"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@mikro-orm/core": ">=4.5.9",
44
- "@tsed/common": "^7.31.0",
45
- "@tsed/core": "^7.31.0",
46
- "@tsed/di": "^7.31.0",
44
+ "@tsed/common": "^7.33.0",
45
+ "@tsed/core": "^7.33.0",
46
+ "@tsed/di": "^7.33.0",
47
47
  "@tsed/logger": ">=6.2.2"
48
48
  },
49
49
  "repository": "https://github.com/tsedio/tsed",
package/readme.md CHANGED
@@ -389,6 +389,34 @@ export class UsersCtrl {
389
389
  }
390
390
  ```
391
391
 
392
+ ## Managing Lifecycle of Subscribers
393
+
394
+ With Ts.ED, managing the lifecycle of subscribers registered with Mikro-ORM using the IoC container is simple. To automatically resolve a subscriber's dependencies, you can use the `@Subscriber` decorator as follows:
395
+
396
+ ```typescript
397
+ import {EventSubscriber} from "@mikro-orm/core";
398
+ import {Subscriber} from "@tsed/mikro-orm";
399
+
400
+ @Subscriber()
401
+ export class SomeSubscriber implements EventSubscriber {
402
+ // ...
403
+ }
404
+ ```
405
+
406
+ In this example, we register the `SomeSubscriber` subscriber, which is automatically instantiated by the module using the IoC container, allowing you to easily manage the dependencies of your subscribers.
407
+
408
+ You can also specify the context name for a subscriber to tie it to a particular instance of the ORM:
409
+
410
+ ```typescript
411
+ import {EventSubscriber} from "@mikro-orm/core";
412
+ import {Subscriber} from "@tsed/mikro-orm";
413
+
414
+ @Subscriber({contextName: "mongodb"})
415
+ export class SomeSubscriber implements EventSubscriber {
416
+ // ...
417
+ }
418
+ ```
419
+
392
420
  ## Contributors
393
421
 
394
422
  Please read [contributing guidelines here](https://tsed.io/contributing.html)