anote-server-libs 0.9.0 → 0.9.3

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "typescript.tsdk": "node_modules\\typescript\\lib"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anote-server-libs",
3
- "version": "0.9.0",
3
+ "version": "0.9.3",
4
4
  "description": "Helpers for express-TS servers",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -32,8 +32,15 @@ function withTransaction(repo, logger, previousMethod, lock, commitIfLost = true
32
32
  const dbClient = c1 || c2;
33
33
  clearTimeout(connectTimeoutHandler);
34
34
  utils_1.utils.logger = logger;
35
- dbClient.removeListener('error', utils_1.utils.clientErrorHandler);
36
- dbClient.on('error', utils_1.utils.clientErrorHandler);
35
+ if (logger.level === 'debug') {
36
+ const originalQuery = dbClient.query.bind(dbClient);
37
+ dbClient.query = (...args) => {
38
+ logger.debug('SQL [Client %d] QUERY: %s', dbClient.processID, args[0]);
39
+ return originalQuery(...args);
40
+ };
41
+ }
42
+ dbClient.removeAllListeners('error');
43
+ dbClient.on('error', (err) => utils_1.utils.clientErrorHandler(err, dbClient));
37
44
  res.locals.dbClient = dbClient;
38
45
  res.locals.dbClientCommited = false;
39
46
  res.locals.dbClientCommit = (cb) => {
@@ -38,8 +38,15 @@ export function withTransaction(repo: BaseModelRepository, logger: Logger, previ
38
38
  clearTimeout(connectTimeoutHandler);
39
39
  // On error, will rollback...
40
40
  utils.logger = logger;
41
- dbClient.removeListener('error', utils.clientErrorHandler);
42
- dbClient.on('error', utils.clientErrorHandler);
41
+ if(logger.level === 'debug') {
42
+ const originalQuery = dbClient.query.bind(dbClient);
43
+ dbClient.query = (...args: any[]) => {
44
+ logger.debug('SQL [Client %d] QUERY: %s', dbClient.processID, args[0]);
45
+ return originalQuery(...args);
46
+ };
47
+ }
48
+ dbClient.removeAllListeners('error');
49
+ dbClient.on('error', (err: any) => utils.clientErrorHandler(err, dbClient));
43
50
 
44
51
  res.locals.dbClient = dbClient;
45
52
  res.locals.dbClientCommited = false;
package/services/utils.js CHANGED
@@ -17,8 +17,8 @@ function atob(str) {
17
17
  function btoa(str) {
18
18
  return Buffer.from(str).toString('base64');
19
19
  }
20
- function clientErrorHandle(err) {
21
- this.error('Error on DB client: %j', err);
20
+ function clientErrorHandle(err, dbClient) {
21
+ this.error('SQL [Client %d] ERROR: %j', dbClient.processID, err);
22
22
  }
23
23
  exports.utils = {
24
24
  clientErrorHandler: undefined
package/services/utils.ts CHANGED
@@ -10,8 +10,8 @@ export function btoa(str: string): string {
10
10
  return Buffer.from(str).toString('base64');
11
11
  }
12
12
 
13
- export function clientErrorHandle(this: Logger, err: any) {
14
- this.error('Error on DB client: %j', err);
13
+ export function clientErrorHandle(this: Logger, err: any, dbClient: any) {
14
+ this.error('SQL [Client %d] ERROR: %j', dbClient.processID, err);
15
15
  }
16
16
  export const utils: {[id: string]: any} = {
17
17
  clientErrorHandler: undefined