@tsed/mikro-orm 6.100.0 → 6.101.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.
Files changed (2) hide show
  1. package/package.json +10 -10
  2. package/readme.md +15 -22
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/mikro-orm",
3
- "version": "6.100.0",
3
+ "version": "6.101.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.100.0",
28
- "@tsed/core": "6.100.0",
29
- "@tsed/di": "6.100.0",
30
- "@tsed/json-mapper": "6.100.0",
27
+ "@tsed/common": "6.101.0",
28
+ "@tsed/core": "6.101.0",
29
+ "@tsed/di": "6.101.0",
30
+ "@tsed/json-mapper": "6.101.0",
31
31
  "@tsed/logger": "^6.0.0",
32
- "@tsed/schema": "6.100.0",
33
- "@tsed/testing-mongoose": "6.100.0",
32
+ "@tsed/schema": "6.101.0",
33
+ "@tsed/testing-mongoose": "6.101.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.100.0",
39
- "@tsed/core": "^6.100.0",
40
- "@tsed/di": "^6.100.0",
38
+ "@tsed/common": "^6.101.0",
39
+ "@tsed/core": "^6.101.0",
40
+ "@tsed/di": "^6.101.0",
41
41
  "@tsed/logger": "^6.0.0"
42
42
  },
43
43
  "repository": "https://github.com/tsedio/tsed",
package/readme.md CHANGED
@@ -33,13 +33,13 @@ A package of Ts.ED framework. See website: https://tsed.io/tutorials/mikro-orm
33
33
 
34
34
  Currently, `@tsed/mikro-orm` allows you:
35
35
 
36
- - Configure one or more MikroOrm instances via the `@Configuration` decorator. All databases will be initialized
36
+ - Configure one or more MikroORM instances via the `@Configuration` decorator. All databases will be initialized
37
37
  when the server starts during the server's `OnInit` phase.
38
- - Use the Entity MikroOrm as Model for Controllers, AJV Validation and Swagger.
38
+ - Use the Entity MikroORM as Model for Controllers, AJV Validation and Swagger.
39
39
 
40
40
  ## Installation
41
41
 
42
- To begin, install the MikroOrm module for TS.ED:
42
+ To begin, install the MikroORM module for TS.ED:
43
43
 
44
44
  <Tabs class="-code">
45
45
  <Tab label="NPM">
@@ -98,7 +98,7 @@ The `mikroOrm` options accepts the same configuration object as `init()` from th
98
98
 
99
99
  ## Obtain ORM instance
100
100
 
101
- `@Orm` decorator lets you retrieve an instance of MikroOrm.
101
+ `@Orm` decorator lets you retrieve an instance of MikroORM.
102
102
 
103
103
  ```typescript
104
104
  import {Injectable, AfterRoutesInit} from "@tsed/common";
@@ -148,7 +148,7 @@ export class MyService {
148
148
  ```typescript
149
149
  import {Injectable, AfterRoutesInit} from "@tsed/common";
150
150
  import {Em} from "@tsed/mikro-orm";
151
- import {EntityManager} from '@mikro-orm/mysql'; // Import EntityManager from your driver package or `@mikro-orm/knex`
151
+ import {EntityManager} from "@mikro-orm/mysql"; // Import EntityManager from your driver package or `@mikro-orm/knex`
152
152
 
153
153
  @Injectable()
154
154
  export class UsersService {
@@ -169,7 +169,7 @@ It's also possible to inject Entity manager by his context name:
169
169
  ```typescript
170
170
  import {Injectable, AfterRoutesInit} from "@tsed/common";
171
171
  import {Em} from "@tsed/mikro-orm";
172
- import {EntityManager} from '@mikro-orm/mysql'; // Import EntityManager from your driver package or `@mikro-orm/knex`
172
+ import {EntityManager} from "@mikro-orm/mysql"; // Import EntityManager from your driver package or `@mikro-orm/knex`
173
173
 
174
174
  @Injectable()
175
175
  export class UsersService {
@@ -187,7 +187,7 @@ export class UsersService {
187
187
 
188
188
  ## Use Entity with Controller
189
189
 
190
- To begin, we need to define an Entity MikroOrm like this and use Ts.ED Decorator to define the JSON Schema.
190
+ To begin, we need to define an Entity MikroORM like this and use Ts.ED Decorator to define the JSON Schema.
191
191
 
192
192
  ```typescript
193
193
  import {Property, MaxLength, Required} from "@tsed/common";
@@ -218,7 +218,7 @@ export class User {
218
218
 
219
219
  Now, the model is correctly defined and can be used with a [Controller](https://tsed.io/docs/controllers.html)
220
220
  , [AJV validation](tutorials/ajv.md),
221
- [Swagger](tutorials/swagger.md) and [MikroOrm](https://mikro-orm.io/docs/defining-entities).
221
+ [Swagger](tutorials/swagger.md) and [MikroORM](https://mikro-orm.io/docs/defining-entities).
222
222
 
223
223
  We can use this model with a Controller like that:
224
224
 
@@ -277,8 +277,8 @@ By default, the automatic retry policy is disabled. You can implement your own t
277
277
  The `@Transactional()` decorator allows you to enable a retry policy for the particular resources. You just need to implement the `RetryStrategy` interface and use `registerProvider()` or `@OverrideProvider()` to register it in the IoC container. Below you can find an example to handle occurred optimistic locks based on [an exponential backoff retry strategy](https://en.wikipedia.org/wiki/Exponential_backoff).
278
278
 
279
279
  ```ts
280
- import { OptimisticLockError } from '@mikro-orm/core';
281
- import { RetryStrategy } from '@tsed/mikro-orm';
280
+ import {OptimisticLockError} from "@mikro-orm/core";
281
+ import {RetryStrategy} from "@tsed/mikro-orm";
282
282
 
283
283
  export interface ExponentialBackoffOptions {
284
284
  maxDepth: number;
@@ -289,16 +289,11 @@ export class ExponentialBackoff implements RetryStrategy {
289
289
 
290
290
  constructor(private readonly options: ExponentialBackoffOptions) {}
291
291
 
292
- public async acquire<T extends (...args: unknown[]) => unknown>(
293
- task: T
294
- ): Promise<ReturnType<T>> {
292
+ public async acquire<T extends (...args: unknown[]) => unknown>(task: T): Promise<ReturnType<T>> {
295
293
  try {
296
294
  return (await task()) as ReturnType<T>;
297
295
  } catch (e) {
298
- if (
299
- this.shouldRetry(e as Error) &&
300
- this.depth < this.options.maxDepth
301
- ) {
296
+ if (this.shouldRetry(e as Error) && this.depth < this.options.maxDepth) {
302
297
  return this.retry(task);
303
298
  }
304
299
 
@@ -310,9 +305,7 @@ export class ExponentialBackoff implements RetryStrategy {
310
305
  return error instanceof OptimisticLockError;
311
306
  }
312
307
 
313
- private async retry<T extends (...args: unknown[]) => unknown>(
314
- task: T
315
- ): Promise<ReturnType<T>> {
308
+ private async retry<T extends (...args: unknown[]) => unknown>(task: T): Promise<ReturnType<T>> {
316
309
  await this.sleep(2 ** this.depth * 50);
317
310
 
318
311
  this.depth += 1;
@@ -321,14 +314,14 @@ export class ExponentialBackoff implements RetryStrategy {
321
314
  }
322
315
 
323
316
  private sleep(milliseconds: number): Promise<void> {
324
- return new Promise(resolve => setTimeout(resolve, milliseconds));
317
+ return new Promise((resolve) => setTimeout(resolve, milliseconds));
325
318
  }
326
319
  }
327
320
 
328
321
  registerProvider({
329
322
  provide: RetryStrategy,
330
323
  useFactory(): ExponentialBackoff {
331
- return new ExponentialBackoff({maxDepth: 3})
324
+ return new ExponentialBackoff({maxDepth: 3});
332
325
  }
333
326
  });
334
327
  ```