@tsed/mikro-orm 6.98.2 → 6.99.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.
package/jest.config.js CHANGED
@@ -6,9 +6,9 @@ module.exports = {
6
6
  coverageThreshold: {
7
7
  global: {
8
8
  branches: 90.91,
9
- functions: 100,
9
+ functions: 96.97,
10
10
  lines: 99.06,
11
- statements: 99.21
11
+ statements: 98.54
12
12
  }
13
13
  }
14
14
  };
@@ -1,3 +1,3 @@
1
1
  export * from "./transactional";
2
- export * from "./connection";
2
+ export * from "./orm";
3
3
  export * from "./entityManager";
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  (0, tslib_1.__exportStar)(require("./transactional"), exports);
5
- (0, tslib_1.__exportStar)(require("./connection"), exports);
5
+ (0, tslib_1.__exportStar)(require("./orm"), exports);
6
6
  (0, tslib_1.__exportStar)(require("./entityManager"), exports);
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,+DAAgC;AAChC,4DAA6B;AAC7B,+DAAgC","sourcesContent":["export * from \"./transactional\";\nexport * from \"./connection\";\nexport * from \"./entityManager\";\n"]}
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"]}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @deprecated Since 2022-02-01. Use {@link Orm} instead
3
+ */
4
+ export declare const Connection: (contextName?: string | undefined) => PropertyDecorator;
5
+ export declare const Orm: (contextName?: string | undefined) => PropertyDecorator;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Orm = exports.Connection = void 0;
4
+ const services_1 = require("../services");
5
+ const di_1 = require("@tsed/di");
6
+ /**
7
+ * @deprecated Since 2022-02-01. Use {@link Orm} instead
8
+ */
9
+ const Connection = (contextName) => (0, exports.Orm)(contextName);
10
+ exports.Connection = Connection;
11
+ const Orm = (contextName) => (0, di_1.Inject)(services_1.MikroOrmRegistry, (registry) => registry.get(contextName));
12
+ exports.Orm = Orm;
13
+ //# sourceMappingURL=orm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":";;;AAAA,0CAA6C;AAC7C,iCAAgC;AAEhC;;GAEG;AACI,MAAM,UAAU,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAAC,IAAA,WAAG,EAAC,WAAW,CAAC,CAAC;AAA3E,QAAA,UAAU,cAAiE;AAEjF,MAAM,GAAG,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAC7D,IAAA,WAAM,EAAC,2BAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAsB,CAAC;AAD9F,QAAA,GAAG,OAC2F","sourcesContent":["import {MikroOrmRegistry} from \"../services\";\nimport {Inject} from \"@tsed/di\";\n\n/**\n * @deprecated Since 2022-02-01. Use {@link Orm} instead\n */\nexport const Connection = (contextName?: string): PropertyDecorator => Orm(contextName);\n\nexport const Orm = (contextName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(contextName)) as PropertyDecorator;\n"]}
@@ -1,4 +1,4 @@
1
1
  export * from "./transactional";
2
- export * from "./connection";
2
+ export * from "./orm";
3
3
  export * from "./entityManager";
4
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC","sourcesContent":["export * from \"./transactional\";\nexport * from \"./connection\";\nexport * from \"./entityManager\";\n"]}
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"]}
@@ -0,0 +1,8 @@
1
+ import { MikroOrmRegistry } from "../services";
2
+ import { Inject } from "@tsed/di";
3
+ /**
4
+ * @deprecated Since 2022-02-01. Use {@link Orm} instead
5
+ */
6
+ export const Connection = (contextName) => Orm(contextName);
7
+ export const Orm = (contextName) => Inject(MikroOrmRegistry, (registry) => registry.get(contextName));
8
+ //# sourceMappingURL=orm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orm.js","sourceRoot":"","sources":["../../../src/decorators/orm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAExF,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,WAAoB,EAAqB,EAAE,CAC7D,MAAM,CAAC,gBAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAsB,CAAC","sourcesContent":["import {MikroOrmRegistry} from \"../services\";\nimport {Inject} from \"@tsed/di\";\n\n/**\n * @deprecated Since 2022-02-01. Use {@link Orm} instead\n */\nexport const Connection = (contextName?: string): PropertyDecorator => Orm(contextName);\n\nexport const Orm = (contextName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(contextName)) as PropertyDecorator;\n"]}
@@ -1,3 +1,3 @@
1
1
  export * from "./transactional";
2
- export * from "./connection";
2
+ export * from "./orm";
3
3
  export * from "./entityManager";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @deprecated Since 2022-02-01. Use {@link Orm} instead
3
+ */
4
+ export declare const Connection: (contextName?: string | undefined) => PropertyDecorator;
5
+ export declare const Orm: (contextName?: string | undefined) => PropertyDecorator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/mikro-orm",
3
- "version": "6.98.2",
3
+ "version": "6.99.0",
4
4
  "description": "MikroORM package for Ts.ED framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -24,20 +24,20 @@
24
24
  "devDependencies": {
25
25
  "@mikro-orm/core": "^4.5.9",
26
26
  "@mikro-orm/mongodb": "^4.5.9",
27
- "@tsed/common": "6.98.2",
28
- "@tsed/core": "6.98.2",
29
- "@tsed/di": "6.98.2",
30
- "@tsed/json-mapper": "6.98.2",
27
+ "@tsed/common": "6.99.0",
28
+ "@tsed/core": "6.99.0",
29
+ "@tsed/di": "6.99.0",
30
+ "@tsed/json-mapper": "6.99.0",
31
31
  "@tsed/logger": "^6.0.0",
32
- "@tsed/schema": "6.98.2",
33
- "@tsed/testing-mongoose": "6.98.2",
32
+ "@tsed/schema": "6.99.0",
33
+ "@tsed/testing-mongoose": "6.99.0",
34
34
  "ts-mockito": "^2.6.1"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@mikro-orm/core": ">=4.5.9",
38
- "@tsed/common": "^6.98.2",
39
- "@tsed/core": "^6.98.2",
40
- "@tsed/di": "^6.98.2",
38
+ "@tsed/common": "^6.99.0",
39
+ "@tsed/core": "^6.99.0",
40
+ "@tsed/di": "^6.99.0",
41
41
  "@tsed/logger": "^6.0.0"
42
42
  },
43
43
  "repository": "https://github.com/tsedio/tsed",
package/readme.md CHANGED
@@ -96,32 +96,32 @@ export class Server {}
96
96
 
97
97
  The `mikroOrm` options accepts the same configuration object as `init()` from the MikroORM package. Check [this page](https://mikro-orm.io/docs/configuration) for the complete configuration documentation.
98
98
 
99
- ## Obtain a connection
99
+ ## Obtain ORM instance
100
100
 
101
- `@Connection` decorator lets you retrieve an instance of MikroOrm Connection.
101
+ `@Orm` decorator lets you retrieve an instance of MikroOrm.
102
102
 
103
103
  ```typescript
104
104
  import {Injectable, AfterRoutesInit} from "@tsed/common";
105
- import {Connection} from "@tsed/mikro-orm";
105
+ import {Orm} from "@tsed/mikro-orm";
106
106
  import {MikroORM} from "@mikro-orm/core";
107
107
 
108
108
  @Injectable()
109
109
  export class UsersService {
110
- @Connection()
111
- private readonly connection!: MikroORM;
110
+ @Orm()
111
+ private readonly orm!: MikroORM;
112
112
 
113
113
  async create(user: User): Promise<User> {
114
114
  // do something
115
115
  // ...
116
116
  // Then save
117
- await this.connection.em.persistAndFlush(user);
117
+ await this.orm.em.persistAndFlush(user);
118
118
  console.log("Saved a new user with id: " + user.id);
119
119
 
120
120
  return user;
121
121
  }
122
122
 
123
123
  async find(): Promise<User[]> {
124
- const users = await this.connection.em.find(User, {});
124
+ const users = await this.orm.em.find(User, {});
125
125
  console.log("Loaded users: ", users);
126
126
 
127
127
  return users;
@@ -129,15 +129,15 @@ export class UsersService {
129
129
  }
130
130
  ```
131
131
 
132
- It's also possible to inject a connection by his name:
132
+ It's also possible to inject an ORM by a connection name:
133
133
 
134
134
  ```ts
135
135
  import {Injectable} from "@tsed/di";
136
136
 
137
137
  @Injectable()
138
138
  export class MyService {
139
- @Connection("mongo")
140
- private readonly connection!: MikroORM;
139
+ @Orm("mongo")
140
+ private readonly orm!: MikroORM;
141
141
  }
142
142
  ```
143
143
 
@@ -195,25 +195,24 @@ import {Entity, Property, PrimaryKey, Property as Column} from "@mikro-orm/core"
195
195
 
196
196
  @Entity()
197
197
  export class User {
198
-
199
198
  @PrimaryKey()
200
199
  @Property()
201
- id: number;
200
+ id!: number;
202
201
 
203
202
  @Column()
204
203
  @MaxLength(100)
205
204
  @Required()
206
- firstName: string;
205
+ firstName!: string;
207
206
 
208
207
  @Column()
209
208
  @MaxLength(100)
210
209
  @Required()
211
- lastName: string;
210
+ lastName!: string;
212
211
 
213
212
  @Column()
214
213
  @Mininum(0)
215
214
  @Maximum(100)
216
- age: number;
215
+ age!: number;
217
216
  }
218
217
  ```
219
218
 
@@ -229,7 +228,7 @@ import {Controller, Post, BodyParams, Inject, Post, Get} from "@tsed/common";
229
228
  @Controller("/users")
230
229
  export class UsersCtrl {
231
230
  @Inject()
232
- private usersService: UsersService;
231
+ private readonly usersService!: UsersService;
233
232
 
234
233
  @Post("/")
235
234
  create(@BodyParams() user: User): Promise<User> {
@@ -258,7 +257,7 @@ import {Transactional} from "@tsed/mikro-orm";
258
257
  @Controller("/users")
259
258
  export class UsersCtrl {
260
259
  @Inject()
261
- private usersService: UsersService;
260
+ private readonly usersService!: UsersService;
262
261
 
263
262
  @Post("/")
264
263
  @Transactional()
@@ -345,7 +344,7 @@ import {Transactional} from "@tsed/mikro-orm";
345
344
  @Controller("/users")
346
345
  export class UsersCtrl {
347
346
  @Inject()
348
- private usersService: UsersService;
347
+ private readonly usersService!: UsersService;
349
348
 
350
349
  @Post("/")
351
350
  @Transactional({retry: true})
@@ -1 +0,0 @@
1
- export declare const Connection: (connectionName?: string | undefined) => PropertyDecorator;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Connection = void 0;
4
- const services_1 = require("../services");
5
- const di_1 = require("@tsed/di");
6
- const Connection = (connectionName) => (0, di_1.Inject)(services_1.MikroOrmRegistry, (registry) => registry.get(connectionName));
7
- exports.Connection = Connection;
8
- //# sourceMappingURL=connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/decorators/connection.ts"],"names":[],"mappings":";;;AAAA,0CAA6C;AAC7C,iCAAgC;AAEzB,MAAM,UAAU,GAAG,CAAC,cAAuB,EAAqB,EAAE,CACvE,IAAA,WAAM,EAAC,2BAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAsB,CAAC;AADjG,QAAA,UAAU,cACuF","sourcesContent":["import {MikroOrmRegistry} from \"../services\";\nimport {Inject} from \"@tsed/di\";\n\nexport const Connection = (connectionName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(connectionName)) as PropertyDecorator;\n"]}
@@ -1,4 +0,0 @@
1
- import { MikroOrmRegistry } from "../services";
2
- import { Inject } from "@tsed/di";
3
- export const Connection = (connectionName) => Inject(MikroOrmRegistry, (registry) => registry.get(connectionName));
4
- //# sourceMappingURL=connection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/decorators/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAEhC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,cAAuB,EAAqB,EAAE,CACvE,MAAM,CAAC,gBAAgB,EAAE,CAAC,QAA0B,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAsB,CAAC","sourcesContent":["import {MikroOrmRegistry} from \"../services\";\nimport {Inject} from \"@tsed/di\";\n\nexport const Connection = (connectionName?: string): PropertyDecorator =>\n Inject(MikroOrmRegistry, (registry: MikroOrmRegistry) => registry.get(connectionName)) as PropertyDecorator;\n"]}
@@ -1 +0,0 @@
1
- export declare const Connection: (connectionName?: string | undefined) => PropertyDecorator;