@naturalcycles/mysql-lib 3.12.3 → 3.12.4

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.
package/dist/mysql.db.js CHANGED
@@ -74,7 +74,6 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
74
74
  }
75
75
  async close() {
76
76
  const pool = this.pool();
77
- // eslint-disable-next-line @typescript-eslint/await-thenable
78
77
  await (0, node_util_1.promisify)(pool.end.bind(pool))();
79
78
  this.cfg.logger.log('closed');
80
79
  }
@@ -184,7 +183,12 @@ class MysqlDB extends db_lib_1.BaseCommonDB {
184
183
  return;
185
184
  // Stringify object values
186
185
  const rows = rowsInput.map(row => (0, js_lib_1._mapValues)(row, (_k, v) => {
187
- return v && typeof v === 'object' && !Buffer.isBuffer(v) ? JSON.stringify(v) : v;
186
+ if (v && typeof v === 'object' && !Buffer.isBuffer(v)) {
187
+ // This is to avoid implicit Date stringification and mismatch: it gets saved as Date, but loaded as String
188
+ (0, js_lib_1._assert)(!(v instanceof Date), 'mysql-lib does not support Date values, please stringify them before passing');
189
+ return JSON.stringify(v);
190
+ }
191
+ return v;
188
192
  }));
189
193
  const verb = opt.saveMethod === 'insert' ? 'INSERT' : 'REPLACE';
190
194
  if (opt.assignGeneratedIds) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MySQLKeyValueDB = void 0;
4
- const stream_1 = require("stream");
4
+ const node_stream_1 = require("node:stream");
5
5
  const js_lib_1 = require("@naturalcycles/js-lib");
6
6
  const mysql_db_1 = require("./mysql.db");
7
7
  class MySQLKeyValueDB {
@@ -67,7 +67,7 @@ class MySQLKeyValueDB {
67
67
  .pool()
68
68
  .query(sql)
69
69
  .stream()
70
- .pipe(new stream_1.Transform({
70
+ .pipe(new node_stream_1.Transform({
71
71
  objectMode: true,
72
72
  transform(row, _, cb) {
73
73
  cb(null, row.id);
@@ -84,7 +84,7 @@ class MySQLKeyValueDB {
84
84
  .pool()
85
85
  .query(sql)
86
86
  .stream()
87
- .pipe(new stream_1.Transform({
87
+ .pipe(new node_stream_1.Transform({
88
88
  objectMode: true,
89
89
  transform(row, _, cb) {
90
90
  cb(null, row.v);
@@ -101,7 +101,7 @@ class MySQLKeyValueDB {
101
101
  .pool()
102
102
  .query(sql)
103
103
  .stream()
104
- .pipe(new stream_1.Transform({
104
+ .pipe(new node_stream_1.Transform({
105
105
  objectMode: true,
106
106
  transform(row, _, cb) {
107
107
  cb(null, [row.id, row.v]);
package/package.json CHANGED
@@ -34,9 +34,9 @@
34
34
  "url": "https://github.com/NaturalCycles/mysql-lib"
35
35
  },
36
36
  "engines": {
37
- "node": ">=14.15.0"
37
+ "node": ">=16.15.0"
38
38
  },
39
- "version": "3.12.3",
39
+ "version": "3.12.4",
40
40
  "description": "MySQL client implementing CommonDB interface",
41
41
  "keywords": [
42
42
  "mysql",
package/src/mysql.db.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  RunQueryResult,
11
11
  } from '@naturalcycles/db-lib'
12
12
  import {
13
+ _assert,
13
14
  _filterUndefinedValues,
14
15
  _mapKeys,
15
16
  _mapValues,
@@ -143,7 +144,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
143
144
 
144
145
  async close(): Promise<void> {
145
146
  const pool = this.pool()
146
- // eslint-disable-next-line @typescript-eslint/await-thenable
147
+
147
148
  await promisify(pool.end.bind(pool))()
148
149
  this.cfg.logger.log('closed')
149
150
  }
@@ -291,7 +292,15 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
291
292
  // Stringify object values
292
293
  const rows = rowsInput.map(row =>
293
294
  _mapValues(row, (_k, v) => {
294
- return v && typeof v === 'object' && !Buffer.isBuffer(v) ? JSON.stringify(v) : v
295
+ if (v && typeof v === 'object' && !Buffer.isBuffer(v)) {
296
+ // This is to avoid implicit Date stringification and mismatch: it gets saved as Date, but loaded as String
297
+ _assert(
298
+ !(v instanceof Date),
299
+ 'mysql-lib does not support Date values, please stringify them before passing',
300
+ )
301
+ return JSON.stringify(v)
302
+ }
303
+ return v
295
304
  }),
296
305
  )
297
306
 
@@ -1,4 +1,4 @@
1
- import { Transform } from 'stream'
1
+ import { Transform } from 'node:stream'
2
2
  import { CommonDBCreateOptions, CommonKeyValueDB, KeyValueDBTuple } from '@naturalcycles/db-lib'
3
3
  import { pMap } from '@naturalcycles/js-lib'
4
4
  import { ReadableTyped } from '@naturalcycles/nodejs-lib'