@sqb/connect 4.5.0 → 4.5.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.
@@ -52,7 +52,10 @@ class SqbClient extends (0, strict_typed_events_1.TypedEventEmitterClass)(strict
52
52
  const poolFactory = {
53
53
  create: () => adapter.connect(cfg),
54
54
  destroy: instance => instance.close(),
55
- reset: instance => instance.reset(),
55
+ reset: async (instance) => {
56
+ await this.emitAsyncSerial('connection-return').catch();
57
+ return instance.reset();
58
+ },
56
59
  validate: instance => instance.test()
57
60
  };
58
61
  this._pool = (0, lightning_pool_1.createPool)(poolFactory, poolOptions);
@@ -12,6 +12,7 @@ interface SqbClientEvents {
12
12
  close: () => void;
13
13
  acquire: (connection: SqbConnection) => Promise<void>;
14
14
  terminate: () => void;
15
+ 'connection-return': () => Promise<void>;
15
16
  }
16
17
  declare const SqbClient_base: Type<import("strict-typed-events").TypedEventEmitter<any, SqbClientEvents, SqbClientEvents>>;
17
18
  export declare class SqbClient extends SqbClient_base {
@@ -48,7 +48,10 @@ export class SqbClient extends TypedEventEmitterClass(AsyncEventEmitter) {
48
48
  const poolFactory = {
49
49
  create: () => adapter.connect(cfg),
50
50
  destroy: instance => instance.close(),
51
- reset: instance => instance.reset(),
51
+ reset: async (instance) => {
52
+ await this.emitAsyncSerial('connection-return').catch();
53
+ return instance.reset();
54
+ },
52
55
  validate: instance => instance.test()
53
56
  };
54
57
  this._pool = createPool(poolFactory, poolOptions);
@@ -1,9 +1,9 @@
1
- import { DeepPartial, Type } from 'ts-gems';
1
+ import { Type } from 'ts-gems';
2
2
  import { FieldInfoMap } from '../client/field-info-map.js';
3
3
  import { SqbClient } from '../client/sqb-client.js';
4
4
  import { SqbConnection } from '../client/sqb-connection.js';
5
5
  import { QueryRequest, TransactionFunction } from '../client/types.js';
6
- import { EntityData } from '../types.js';
6
+ import { EntityInput, EntityOutput } from '../types.js';
7
7
  import { EntityMetadata } from './model/entity-metadata.js';
8
8
  export declare namespace Repository {
9
9
  type TransformRowFunction = (fields: FieldInfoMap, row: object, obj: object) => void;
@@ -75,23 +75,23 @@ export declare class Repository<T> extends Repository_base {
75
75
  constructor(entityDef: EntityMetadata, executor: SqbClient | SqbConnection, schema?: string);
76
76
  get entity(): EntityMetadata;
77
77
  get type(): Type<T>;
78
- create(values: EntityData<T>, options?: Repository.CreateOptions): Promise<DeepPartial<T>>;
79
- createOnly(values: EntityData<T>, options?: Repository.CreateOptions): Promise<void>;
78
+ create(values: EntityInput<T>, options?: Repository.CreateOptions): Promise<EntityOutput<T>>;
79
+ createOnly(values: EntityInput<T>, options?: Repository.CreateOptions): Promise<void>;
80
80
  exists(keyValue: any | Record<string, any>, options?: Repository.ExistsOptions): Promise<boolean>;
81
81
  count(options?: Repository.CountOptions): Promise<number>;
82
- findAll(options?: Repository.FindAllOptions): Promise<DeepPartial<T>[]>;
83
- findOne(options?: Repository.FindOneOptions): Promise<DeepPartial<T> | undefined>;
84
- findByPk(keyValue: any | Record<string, any>, options?: Repository.GetOptions): Promise<DeepPartial<T> | undefined>;
82
+ findAll(options?: Repository.FindAllOptions): Promise<EntityOutput<T>[]>;
83
+ findOne(options?: Repository.FindOneOptions): Promise<EntityOutput<T> | undefined>;
84
+ findByPk(keyValue: any | Record<string, any>, options?: Repository.GetOptions): Promise<EntityOutput<T> | undefined>;
85
85
  destroy(keyValue: any | Record<string, any>, options?: Repository.DestroyOptions): Promise<boolean>;
86
86
  destroyAll(options?: Repository.DestroyOptions): Promise<number>;
87
- update(keyValue: any | Record<string, any>, values: EntityData<T>, options?: Repository.UpdateOptions): Promise<DeepPartial<T> | undefined>;
88
- updateOnly(keyValue: any | Record<string, any>, values: EntityData<T>, options?: Repository.UpdateOptions): Promise<DeepPartial<T>>;
89
- updateAll(values: EntityData<T>, options?: Repository.UpdateAllOptions): Promise<number>;
87
+ update(keyValue: any | Record<string, any>, values: EntityInput<T>, options?: Repository.UpdateOptions): Promise<EntityOutput<T> | undefined>;
88
+ updateOnly(keyValue: any | Record<string, any>, values: EntityInput<T>, options?: Repository.UpdateOptions): Promise<EntityOutput<T>>;
89
+ updateAll(values: EntityInput<T>, options?: Repository.UpdateAllOptions): Promise<number>;
90
90
  protected _execute(fn: TransactionFunction, opts?: Repository.CommandOptions): Promise<any>;
91
- protected _create(values: EntityData<T>, options: Repository.CreateOptions & {
91
+ protected _create(values: EntityInput<T>, options: Repository.CreateOptions & {
92
92
  connection: SqbConnection;
93
- }): Promise<DeepPartial<T>>;
94
- protected _createOnly(values: EntityData<T>, options: Repository.CreateOptions & {
93
+ }): Promise<EntityOutput<T>>;
94
+ protected _createOnly(values: EntityInput<T>, options: Repository.CreateOptions & {
95
95
  connection: SqbConnection;
96
96
  }): Promise<void>;
97
97
  protected _exists(keyValue: any | Record<string, any>, options: Repository.ExistsOptions & {
@@ -102,23 +102,23 @@ export declare class Repository<T> extends Repository_base {
102
102
  }): Promise<number>;
103
103
  protected _findAll(options: Repository.FindAllOptions & {
104
104
  connection: SqbConnection;
105
- }): Promise<DeepPartial<T>[]>;
105
+ }): Promise<EntityOutput<T>[]>;
106
106
  protected _findOne(options: Repository.FindOneOptions & {
107
107
  connection: SqbConnection;
108
- }): Promise<DeepPartial<T> | undefined>;
108
+ }): Promise<EntityOutput<T> | undefined>;
109
109
  protected _findByPk(keyValue: any | Record<string, any>, options: Repository.GetOptions & {
110
110
  connection: SqbConnection;
111
- }): Promise<DeepPartial<T> | undefined>;
111
+ }): Promise<EntityOutput<T> | undefined>;
112
112
  protected _destroy(keyValue: any | Record<string, any>, options: Repository.DestroyOptions & {
113
113
  connection: SqbConnection;
114
114
  }): Promise<boolean>;
115
115
  protected _destroyAll(options: Repository.DestroyOptions & {
116
116
  connection: SqbConnection;
117
117
  }): Promise<number>;
118
- protected _update(keyValue: any | Record<string, any>, values: EntityData<T>, options: Repository.UpdateOptions & {
118
+ protected _update(keyValue: any | Record<string, any>, values: EntityInput<T>, options: Repository.UpdateOptions & {
119
119
  connection: SqbConnection;
120
120
  }): Promise<Record<string, any> | undefined>;
121
- protected _updateAll(values: EntityData<T>, options: Repository.UpdateAllOptions & {
121
+ protected _updateAll(values: EntityInput<T>, options: Repository.UpdateAllOptions & {
122
122
  connection: SqbConnection;
123
123
  }): Promise<number>;
124
124
  protected _emit(event: string, ...args: any[]): Promise<void>;
package/esm/types.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Builtin, DeepPickWritable } from 'ts-gems';
2
- export declare type EntityData<T> = DeepNullableIfPartial<DeepPickWritable<T>>;
2
+ export declare type EntityInput<T> = DeepNullableIfPartial<DeepPickWritable<T>>;
3
+ export declare type EntityOutput<T> = DeepNullableIfPartial<T>;
3
4
  export declare type DeepNullableIfPartial<T> = _DeepNullableIfPartial<T>;
4
5
  declare type _DeepNullableIfPartial<T> = T extends Builtin ? T : T extends Promise<infer U> ? Promise<DeepNullableIfPartial<U>> : T extends (infer U)[] ? DeepNullableIfPartial<U>[] : {
5
- [P in keyof T]?: DeepNullableIfPartial<Exclude<T[P], undefined> | null>;
6
+ [P in keyof T]?: DeepNullableIfPartial<Exclude<T[P], undefined>> | null;
6
7
  };
7
8
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/connect",
3
3
  "description": "Multi-dialect database connection framework written with TypeScript",
4
- "version": "4.5.0",
4
+ "version": "4.5.2",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "debug": "^4.3.4",
33
- "lightning-pool": "^3.1.4",
33
+ "lightning-pool": "^4.0.0",
34
34
  "lodash": "^4.17.21",
35
35
  "putil-isplainobject": "^1.1.4",
36
36
  "putil-merge": "^3.8.0",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/debug": "^4.1.7",
46
- "@types/lodash": "^4.14.184"
46
+ "@types/lodash": "^4.14.185"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "@sqb/builder": "^4.5.0"