anote-server-libs 0.2.10 → 0.2.13

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.
@@ -1,7 +1,7 @@
1
+ import * as crypto from 'crypto';
1
2
  import * as fs from 'fs';
2
3
  import * as Memcached from 'memcached';
3
4
  import {ConnectionPool, Transaction} from 'mssql';
4
- import {md} from 'node-forge';
5
5
  import {ClientBase, Pool} from 'pg';
6
6
  import {Logger} from 'winston';
7
7
  import { ApiCallRepository } from '../ApiCall';
@@ -53,7 +53,7 @@ export class BaseModelRepository {
53
53
  return {
54
54
  id: file,
55
55
  content: content,
56
- hash: md.sha256.create().update(content).digest().toHex()
56
+ hash: crypto.createHash('sha256').update(content).digest('hex')
57
57
  };
58
58
  });
59
59
  if(migrationsAvailable.length === 0
@@ -119,7 +119,7 @@ class ModelDao extends Dao {
119
119
  else {
120
120
  const request = (client || this.poolMssql).request();
121
121
  request.input('1', id);
122
- return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (ROWLOCK)' : '') + ' WHERE id=@1').then(q => this.buildObject(q.recordsets[0][0]));
122
+ return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id=@1').then(q => this.buildObject(q.recordsets[0][0]));
123
123
  }
124
124
  }
125
125
  count(where, inputs = [], client) {
@@ -140,7 +140,7 @@ class ModelDao extends Dao {
140
140
  }
141
141
  else {
142
142
  const request = (client || this.poolMssql).request();
143
- return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (ROWLOCK)' : '') + ' WHERE id IN ('
143
+ return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id IN ('
144
144
  + (ids.length > 0 ? (typeof ids[0] === 'string' ? '\'' + ids.join('\',\'') + '\'' : ids.join(',')) : '') + ')')
145
145
  .then(q => q.recordsets[0].map(r => this.buildObject(r)));
146
146
  }
@@ -155,7 +155,7 @@ class ModelDao extends Dao {
155
155
  const request = (client || this.poolMssql).request();
156
156
  if (where)
157
157
  where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
158
- return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
158
+ return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
159
159
  + (order ? (' ORDER BY ' + order) : '') + (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : ''))
160
160
  .then(q => q.recordsets[0].map(r => this.buildObject(r)));
161
161
  }
@@ -174,7 +174,7 @@ class ModelDao extends Dao {
174
174
  if (where)
175
175
  where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
176
176
  return Promise.allConcurrent(1)([
177
- () => request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
177
+ () => request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
178
178
  + (order ? (' ORDER BY ' + order) : '') + (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : '')),
179
179
  () => request.query('SELECT COUNT(DISTINCT id) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : ''))
180
180
  ]).then(([q1, q2]) => ({
@@ -198,7 +198,7 @@ class ModelDao extends Dao {
198
198
  where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
199
199
  return Promise.allConcurrent(1)([
200
200
  () => request.query('SELECT ' + rows.map(r => '"' + r + '"').join(',') + ' FROM ' + this.table
201
- + ((client && lock) ? ' WITH (ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '') + (order ? (' ORDER BY ' + order) : '')
201
+ + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '') + (order ? (' ORDER BY ' + order) : '')
202
202
  + (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : '')),
203
203
  () => request.query('SELECT COUNT(DISTINCT id) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : ''))
204
204
  ]).then(([q1, q2]) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anote-server-libs",
3
- "version": "0.2.10",
3
+ "version": "0.2.13",
4
4
  "description": "Helpers for express-TS servers",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -17,22 +17,20 @@
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
19
  "@types/memcached": "2.2.7",
20
- "@types/mssql": "7.1.4",
21
- "@types/pg": "8.6.4",
20
+ "@types/mssql": "7.1.5",
21
+ "@types/pg": "8.6.5",
22
22
  "memcached": "2.2.2",
23
- "mssql": "8.0.2",
23
+ "mssql": "8.1.0",
24
24
  "pg": "8.7.3"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "express": "^4.17.3",
28
28
  "jsonschema": "^1.4.0",
29
- "node-forge": "^1.2.1",
30
- "winston": "3.6.0"
29
+ "winston": "^3.7.2"
31
30
  },
32
31
  "devDependencies": {
33
32
  "@types/express": "4.17.13",
34
33
  "@types/node": "14.18.2",
35
- "@types/node-forge": "1.0.0",
36
- "typescript": "4.5.5"
34
+ "typescript": "4.6.3"
37
35
  }
38
36
  }
@@ -12,7 +12,7 @@ function withTransaction(repo, logger, previousMethod, lock) {
12
12
  const connectTimeoutHandler = setTimeout(() => {
13
13
  logger.error('Error timed out getting a client, exiting...');
14
14
  process.exit(22);
15
- }, 3000);
15
+ }, 15000);
16
16
  Promise.all([
17
17
  repo.db ? repo.db.connect() : Promise.resolve(undefined),
18
18
  repo.dbMssql ? Promise.resolve(repo.dbMssql.transaction()) : Promise.resolve(undefined)
@@ -117,12 +117,6 @@ function withTransaction(repo, logger, previousMethod, lock) {
117
117
  else {
118
118
  finish();
119
119
  }
120
- }).catch((err) => {
121
- if (repo.db)
122
- dbClient.release();
123
- else
124
- dbClient.rollback();
125
- throw err;
126
120
  });
127
121
  }).catch(err => {
128
122
  res.status(500).json({
@@ -19,7 +19,7 @@ export function withTransaction(repo: BaseModelRepository, logger: Logger, previ
19
19
  // Timed out getting a client, restart worker or process...
20
20
  logger.error('Error timed out getting a client, exiting...');
21
21
  process.exit(22);
22
- }, 3000);
22
+ }, 15000);
23
23
  Promise.all([
24
24
  repo.db ? repo.db.connect() : Promise.resolve(undefined),
25
25
  repo.dbMssql ? Promise.resolve(repo.dbMssql.transaction()) : Promise.resolve(undefined)