@onivoro/server-typeorm-mysql 22.0.0 → 22.0.2

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.
@@ -10,7 +10,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
10
10
  getManyAndCount(options: FindManyOptions<TEntity>): Promise<[TEntity[], number]>;
11
11
  getOne(options: FindOneOptions<TEntity>): Promise<TEntity>;
12
12
  postOne(body: Partial<TEntity>): Promise<TEntity>;
13
- postMany(body: Partial<TEntity>[]): Promise<TEntity[]>;
13
+ postMany(body: Partial<TEntity | undefined>[]): Promise<TEntity[]>;
14
14
  delete(options: FindOptionsWhere<TEntity>): Promise<void>;
15
15
  softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
16
16
  put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
@@ -1,5 +1,6 @@
1
- import { DynamicModule } from '@nestjs/common';
1
+ import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
2
2
  import { IDataSourceOptions } from './types/data-source-options.interface';
3
- export declare class ServerTypeormMysqlModule {
3
+ export declare class ServerTypeormMysqlModule implements OnApplicationShutdown {
4
+ onApplicationShutdown(): Promise<void>;
4
5
  static configure(injectables: any[], entities: any[], options: IDataSourceOptions, name?: string): DynamicModule;
5
6
  }
@@ -13,6 +13,19 @@ const typeorm_1 = require("typeorm");
13
13
  const data_source_factory_function_1 = require("./functions/data-source-factory.function");
14
14
  const dataSourceMap = new Map();
15
15
  let ServerTypeormMysqlModule = ServerTypeormMysqlModule_1 = class ServerTypeormMysqlModule {
16
+ async onApplicationShutdown() {
17
+ for (let dataSourceKey in dataSourceMap.keys()) {
18
+ try {
19
+ const dataSource = dataSourceMap.get(dataSourceKey);
20
+ if (dataSource && dataSource.isInitialized) {
21
+ await dataSource.destroy();
22
+ }
23
+ }
24
+ catch (e) {
25
+ console.error(e?.message);
26
+ }
27
+ }
28
+ }
16
29
  static configure(injectables, entities, options, name = 'default') {
17
30
  const providers = [
18
31
  {
@@ -30,7 +43,7 @@ let ServerTypeormMysqlModule = ServerTypeormMysqlModule_1 = class ServerTypeormM
30
43
  {
31
44
  provide: typeorm_1.EntityManager,
32
45
  useFactory: (dataSource) => {
33
- return dataSource.manager;
46
+ return dataSource?.manager;
34
47
  },
35
48
  inject: [typeorm_1.DataSource]
36
49
  },
@@ -10,7 +10,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
10
10
  getManyAndCount(options: FindManyOptions<TEntity>): Promise<[TEntity[], number]>;
11
11
  getOne(options: FindOneOptions<TEntity>): Promise<TEntity>;
12
12
  postOne(body: Partial<TEntity>): Promise<TEntity>;
13
- postMany(body: Partial<TEntity>[]): Promise<TEntity[]>;
13
+ postMany(body: Partial<TEntity | undefined>[]): Promise<TEntity[]>;
14
14
  delete(options: FindOptionsWhere<TEntity>): Promise<void>;
15
15
  softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
16
16
  put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
@@ -1,5 +1,6 @@
1
- import { DynamicModule } from '@nestjs/common';
1
+ import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
2
2
  import { IDataSourceOptions } from './types/data-source-options.interface';
3
- export declare class ServerTypeormMysqlModule {
3
+ export declare class ServerTypeormMysqlModule implements OnApplicationShutdown {
4
+ onApplicationShutdown(): Promise<void>;
4
5
  static configure(injectables: any[], entities: any[], options: IDataSourceOptions, name?: string): DynamicModule;
5
6
  }
@@ -13,6 +13,19 @@ const typeorm_1 = require("typeorm");
13
13
  const data_source_factory_function_1 = require("./functions/data-source-factory.function");
14
14
  const dataSourceMap = new Map();
15
15
  let ServerTypeormMysqlModule = ServerTypeormMysqlModule_1 = class ServerTypeormMysqlModule {
16
+ async onApplicationShutdown() {
17
+ for (let dataSourceKey in dataSourceMap.keys()) {
18
+ try {
19
+ const dataSource = dataSourceMap.get(dataSourceKey);
20
+ if (dataSource && dataSource.isInitialized) {
21
+ await dataSource.destroy();
22
+ }
23
+ }
24
+ catch (e) {
25
+ console.error(e?.message);
26
+ }
27
+ }
28
+ }
16
29
  static configure(injectables, entities, options, name = 'default') {
17
30
  const providers = [
18
31
  {
@@ -30,7 +43,7 @@ let ServerTypeormMysqlModule = ServerTypeormMysqlModule_1 = class ServerTypeormM
30
43
  {
31
44
  provide: typeorm_1.EntityManager,
32
45
  useFactory: (dataSource) => {
33
- return dataSource.manager;
46
+ return dataSource?.manager;
34
47
  },
35
48
  inject: [typeorm_1.DataSource]
36
49
  },
@@ -10,7 +10,7 @@ export declare class TypeOrmRepository<TEntity> implements IEntityProvider<TEnti
10
10
  getManyAndCount(options: FindManyOptions<TEntity>): Promise<[TEntity[], number]>;
11
11
  getOne(options: FindOneOptions<TEntity>): Promise<TEntity>;
12
12
  postOne(body: Partial<TEntity>): Promise<TEntity>;
13
- postMany(body: Partial<TEntity>[]): Promise<TEntity[]>;
13
+ postMany(body: Partial<TEntity | undefined>[]): Promise<TEntity[]>;
14
14
  delete(options: FindOptionsWhere<TEntity>): Promise<void>;
15
15
  softDelete(options: FindOptionsWhere<TEntity>): Promise<void>;
16
16
  put(options: FindOptionsWhere<TEntity>, body: QueryDeepPartialEntity<TEntity>): Promise<void>;
@@ -1,5 +1,6 @@
1
- import { DynamicModule } from '@nestjs/common';
1
+ import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
2
2
  import { IDataSourceOptions } from './types/data-source-options.interface';
3
- export declare class ServerTypeormMysqlModule {
3
+ export declare class ServerTypeormMysqlModule implements OnApplicationShutdown {
4
+ onApplicationShutdown(): Promise<void>;
4
5
  static configure(injectables: any[], entities: any[], options: IDataSourceOptions, name?: string): DynamicModule;
5
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-typeorm-mysql",
3
- "version": "22.0.0",
3
+ "version": "22.0.2",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/onivoro/server-typeorm-mysql.git"
6
6
  },