anote-server-libs 0.6.1 → 0.6.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
+ }
@@ -2,7 +2,7 @@ import * as Memcached from 'memcached';
2
2
 
3
3
  export class MemoryCache<T> {
4
4
 
5
- private localCache = {};
5
+ private localCache: {[id: string]: any} = {};
6
6
 
7
7
  constructor(private localKey: string, private cache?: Memcached) {
8
8
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModelDao = exports.Dao = exports.promiseAllStepN = void 0;
3
+ exports.ModelDao = exports.Dao = void 0;
4
+ exports.promiseAllStepN = promiseAllStepN;
4
5
  function promiseAllStepN(n, list) {
5
6
  if (!list || !list.length)
6
7
  return Promise.resolve([]);
@@ -41,7 +42,6 @@ function promiseAllStepN(n, list) {
41
42
  }
42
43
  });
43
44
  }
44
- exports.promiseAllStepN = promiseAllStepN;
45
45
  Promise.allConcurrent = (n) => (list) => promiseAllStepN(n, list);
46
46
  class Dao {
47
47
  constructor(pool, poolMssql, logger, table, nFields, updateDefinition) {
@@ -100,7 +100,7 @@ class Dao {
100
100
  const request = (client || this.poolMssql).request();
101
101
  this.serialize(instance, request);
102
102
  return request.query('INSERT INTO ' + this.table + '(' + this.updateDefinition.replace(/=@\d+/g, '').replace(/=[^)]+\)/g, '') + ')'
103
- + ' VALUES(' + new Array(this.nFields).fill(undefined).map((_, i) => '@' + (i + 1)).join(',') + '); SELECT SCOPE_IDENTITY() AS id').then(q => {
103
+ + ' VALUES(' + new Array(this.nFields).fill(undefined).map((_, i) => '@' + (i + 1)).join(',') + '); SELECT SCOPE_IDENTITY() AS id').then((q) => {
104
104
  return q.recordsets[0][0].id || instance.id;
105
105
  });
106
106
  }
@@ -129,7 +129,7 @@ class ModelDao extends Dao {
129
129
  else {
130
130
  const request = (client || this.poolMssql).request();
131
131
  request.input('1', id);
132
- return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id=@1').then(q => this.buildObject(q.recordsets[0][0]));
132
+ return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id=@1').then((q) => this.buildObject(q.recordsets[0][0]));
133
133
  }
134
134
  }
135
135
  count(where, inputs = [], client) {
@@ -140,7 +140,7 @@ class ModelDao extends Dao {
140
140
  const request = (client || this.poolMssql).request();
141
141
  if (where)
142
142
  where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
143
- return request.query('SELECT count(*) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : '')).then(q => q.recordsets[0][0].cnt);
143
+ return request.query('SELECT count(*) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : '')).then((q) => q.recordsets[0][0].cnt);
144
144
  }
145
145
  }
146
146
  getList(ids, client, lock = true) {
@@ -152,7 +152,7 @@ class ModelDao extends Dao {
152
152
  const request = (client || this.poolMssql).request();
153
153
  return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id IN ('
154
154
  + (ids.length > 0 ? (typeof ids[0] === 'string' ? '\'' + ids.join('\',\'') + '\'' : ids.join(',')) : '') + ')')
155
- .then(q => q.recordsets[0].map((r) => this.buildObject(r)));
155
+ .then((q) => q.recordsets[0].map((r) => this.buildObject(r)));
156
156
  }
157
157
  }
158
158
  getAllBy(order, offset, limit, where, inputs = [], client, lock = true) {
@@ -167,7 +167,7 @@ class ModelDao extends Dao {
167
167
  where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
168
168
  return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
169
169
  + (order ? (' ORDER BY ' + order) : '') + (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : ''))
170
- .then(q => q.recordsets[0].map((r) => this.buildObject(r)));
170
+ .then((q) => q.recordsets[0].map((r) => this.buildObject(r)));
171
171
  }
172
172
  }
173
173
  getViewCountBy(order, offset, limit, where, inputs = [], client, lock = true) {
@@ -73,7 +73,7 @@ export abstract class Dao<R, T extends Model<R>> implements ModelRepr {
73
73
  }
74
74
 
75
75
  groupResultSet(q: any[], key: string): any[][] {
76
- const storage = {};
76
+ const storage: any = {};
77
77
  for(let i = 0; i < q.length; i++) {
78
78
  storage[q[i][key]] = storage[q[i][key]] || [];
79
79
  storage[q[i][key]].push(q[i]);
@@ -82,7 +82,7 @@ export abstract class Dao<R, T extends Model<R>> implements ModelRepr {
82
82
  }
83
83
 
84
84
  groupResultSetBy(q: any[], key: (qs: any) => string): any[][] {
85
- const storage = {};
85
+ const storage: any = {};
86
86
  for(let i = 0; i < q.length; i++) {
87
87
  storage[key(q[i])] = storage[key(q[i])] || [];
88
88
  storage[key(q[i])].push(q[i]);
@@ -120,7 +120,7 @@ export abstract class Dao<R, T extends Model<R>> implements ModelRepr {
120
120
  const request = (<Transaction | ConnectionPool>(client || this.poolMssql)).request();
121
121
  this.serialize(instance, request);
122
122
  return request.query('INSERT INTO ' + this.table + '(' + this.updateDefinition.replace(/=@\d+/g, '').replace(/=[^)]+\)/g, '') + ')'
123
- + ' VALUES(' + new Array(this.nFields).fill(undefined).map((_, i: number) => '@' + (i + 1)).join(',') + '); SELECT SCOPE_IDENTITY() AS id').then(q => {
123
+ + ' VALUES(' + new Array(this.nFields).fill(undefined).map((_, i: number) => '@' + (i + 1)).join(',') + '); SELECT SCOPE_IDENTITY() AS id').then((q: any) => {
124
124
  return q.recordsets[0][0].id || instance.id;
125
125
  });
126
126
  }
@@ -153,7 +153,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
153
153
  } else {
154
154
  const request = (<Transaction | ConnectionPool>(client || this.poolMssql)).request();
155
155
  request.input('1', id);
156
- return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id=@1').then(q => this.buildObject(q.recordsets[0][0]));
156
+ return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id=@1').then((q: any) => this.buildObject(q.recordsets[0][0]));
157
157
  }
158
158
  }
159
159
 
@@ -163,7 +163,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
163
163
  } else {
164
164
  const request = (<Transaction | ConnectionPool>(client || this.poolMssql)).request();
165
165
  if(where) where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
166
- return request.query('SELECT count(*) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : '')).then(q => q.recordsets[0][0].cnt);
166
+ return request.query('SELECT count(*) AS cnt FROM ' + this.table + (where ? (' WHERE ' + where) : '')).then((q: any) => q.recordsets[0][0].cnt);
167
167
  }
168
168
  }
169
169
 
@@ -175,7 +175,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
175
175
  const request = (<Transaction | ConnectionPool>(client || this.poolMssql)).request();
176
176
  return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + ' WHERE id IN ('
177
177
  + (ids.length > 0 ? (typeof ids[0] === 'string' ? '\'' + ids.join('\',\'') + '\'' : ids.join(',')) : '') + ')')
178
- .then(q => q.recordsets[0].map((r: any) => this.buildObject(r)));
178
+ .then((q: any) => q.recordsets[0].map((r: any) => this.buildObject(r)));
179
179
  }
180
180
  }
181
181
 
@@ -189,7 +189,7 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
189
189
  if(where) where.match(/(@\d+)/g).forEach((match, i) => request.input(match.substr(1), inputs[i]));
190
190
  return request.query('SELECT * FROM ' + this.table + ((client && lock) ? ' WITH (UPDLOCK, ROWLOCK)' : '') + (where ? (' WHERE ' + where) : '')
191
191
  + (order ? (' ORDER BY ' + order) : '') + (offset !== undefined ? (' OFFSET ' + offset + ' ROWS') : '') + (limit !== undefined ? (' FETCH NEXT ' + limit + ' ROWS ONLY') : ''))
192
- .then(q => q.recordsets[0].map((r: any) => this.buildObject(r)));
192
+ .then((q: any) => q.recordsets[0].map((r: any) => this.buildObject(r)));
193
193
  }
194
194
  }
195
195
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anote-server-libs",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Helpers for express-TS servers",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -19,10 +19,10 @@
19
19
  "@types/memcached": "2.2.10",
20
20
  "@types/mssql": "9.1.5",
21
21
  "@types/pg": "8.11.6",
22
- "ajv": "8.13.0",
22
+ "ajv": "8.16.0",
23
23
  "memcached": "2.2.2",
24
- "mssql": "10.0.2",
25
- "pg": "8.11.5"
24
+ "mssql": "11.0.0",
25
+ "pg": "8.12.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "express": "4.19.2",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/express": "4.17.21",
33
- "@types/node": "18.15.0",
34
- "typescript": "5.4.5"
33
+ "@types/node": "20.12.2",
34
+ "typescript": "5.5.2"
35
35
  }
36
36
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WithBody = exports.ajv = void 0;
3
+ exports.ajv = void 0;
4
+ exports.WithBody = WithBody;
4
5
  const ajv_1 = require("ajv");
5
6
  exports.ajv = new ajv_1.default();
6
7
  exports.ajv.addKeyword({
@@ -60,4 +61,3 @@ function WithBody(schema) {
60
61
  return undefined;
61
62
  };
62
63
  }
63
- exports.WithBody = WithBody;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withTransaction = exports.withTransactionConfig = void 0;
3
+ exports.withTransactionConfig = void 0;
4
+ exports.withTransaction = withTransaction;
4
5
  const utils_1 = require("./utils");
5
6
  exports.withTransactionConfig = {
6
7
  timeoutMillis: 15000
@@ -136,4 +137,3 @@ function withTransaction(repo, logger, previousMethod, lock) {
136
137
  });
137
138
  };
138
139
  }
139
- exports.withTransaction = withTransaction;
package/services/utils.js CHANGED
@@ -1,18 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.digitize = exports.fpEuros = exports.sendSelfPostableMessage = exports.idempotent = exports.jsonStringify = exports.lcm = exports.gcd = exports.utils = exports.clientErrorHandle = exports.btoa = exports.atob = void 0;
3
+ exports.utils = void 0;
4
+ exports.atob = atob;
5
+ exports.btoa = btoa;
6
+ exports.clientErrorHandle = clientErrorHandle;
7
+ exports.gcd = gcd;
8
+ exports.lcm = lcm;
9
+ exports.jsonStringify = jsonStringify;
10
+ exports.idempotent = idempotent;
11
+ exports.sendSelfPostableMessage = sendSelfPostableMessage;
12
+ exports.fpEuros = fpEuros;
13
+ exports.digitize = digitize;
4
14
  function atob(str) {
5
15
  return Buffer.from(str, 'base64').toString('binary');
6
16
  }
7
- exports.atob = atob;
8
17
  function btoa(str) {
9
18
  return Buffer.from(str).toString('base64');
10
19
  }
11
- exports.btoa = btoa;
12
20
  function clientErrorHandle(err) {
13
21
  this.error('Error on DB client: %j', err);
14
22
  }
15
- exports.clientErrorHandle = clientErrorHandle;
16
23
  exports.utils = {
17
24
  clientErrorHandler: undefined
18
25
  };
@@ -27,7 +34,6 @@ function gcd(values) {
27
34
  result = gcdTwo(values[i], result);
28
35
  return result;
29
36
  }
30
- exports.gcd = gcd;
31
37
  function lcm(values) {
32
38
  let l = 1, divisor = 2;
33
39
  while (true) {
@@ -59,7 +65,6 @@ function lcm(values) {
59
65
  }
60
66
  }
61
67
  }
62
- exports.lcm = lcm;
63
68
  function jsonStringify(obj) {
64
69
  const cache = {};
65
70
  return JSON.stringify(obj, function (_, value) {
@@ -77,7 +82,6 @@ function jsonStringify(obj) {
77
82
  return value;
78
83
  });
79
84
  }
80
- exports.jsonStringify = jsonStringify;
81
85
  function idempotent(repo, debug, logger) {
82
86
  return function (req, res, next) {
83
87
  let idempotenceKey = req.header('x-idempotent-key');
@@ -138,7 +142,6 @@ function idempotent(repo, debug, logger) {
138
142
  next();
139
143
  };
140
144
  }
141
- exports.idempotent = idempotent;
142
145
  function sendSelfPostableMessage(res, code, messageType, err) {
143
146
  res.type('text/html').status(code).write(`
144
147
  <!DOCTYPE HTML>
@@ -159,11 +162,9 @@ function sendSelfPostableMessage(res, code, messageType, err) {
159
162
  `);
160
163
  res.end();
161
164
  }
162
- exports.sendSelfPostableMessage = sendSelfPostableMessage;
163
165
  function fpEuros(n) {
164
166
  return Math.round(n * 100) / 100;
165
167
  }
166
- exports.fpEuros = fpEuros;
167
168
  function digitize(value, opts) {
168
169
  if (value === undefined || value === null)
169
170
  return 'undefined';
@@ -194,4 +195,3 @@ function digitize(value, opts) {
194
195
  }
195
196
  return (opts && opts.currency) ? (parts[0] + '.00') : parts[0];
196
197
  }
197
- exports.digitize = digitize;