Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit dc9b77e

Browse files
feat: modernize, convert to ESM
BREAKING CHANGE: ^^^
1 parent 0cf2ff0 commit dc9b77e

19 files changed

+1414
-2283
lines changed

eslint.config.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
// prettier-ignore
2-
module.exports = [
3-
...require('@naturalcycles/dev-lib/cfg/eslint.config'),
1+
import sharedConfig from '@naturalcycles/dev-lib/cfg/eslint.config.js'
2+
3+
export default [
4+
...sharedConfig,
5+
{
6+
rules: {
7+
'@typescript-eslint/consistent-type-imports': 2,
8+
},
9+
},
410
]

jest.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "@naturalcycles/mysql-lib",
3+
"type": "module",
34
"scripts": {
45
"prepare": "husky",
56
"build": "dev-lib build",
@@ -9,17 +10,19 @@
910
"lbt": "dev-lib lbt"
1011
},
1112
"dependencies": {
12-
"@naturalcycles/db-lib": "^9",
13+
"@naturalcycles/db-lib": "^10",
1314
"@naturalcycles/js-lib": "^14",
1415
"@naturalcycles/nodejs-lib": "^13",
1516
"@types/mysql": "^2",
1617
"mysql": "^2"
1718
},
1819
"devDependencies": {
19-
"@naturalcycles/dev-lib": "^15",
20+
"@naturalcycles/dev-lib": "^17",
2021
"@types/node": "^22",
22+
"@vitest/coverage-v8": "^3",
2123
"dotenv": "^16",
22-
"jest": "^29"
24+
"tsx": "^4",
25+
"vitest": "^3"
2326
},
2427
"files": [
2528
"dist",

prettier.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = require('@naturalcycles/dev-lib/cfg/prettier.config')
1+
import sharedConfig from '@naturalcycles/dev-lib/cfg/prettier.config.js'
2+
3+
export default sharedConfig

src/__snapshots__/query.util.test.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`dbQueryToSQLDelete 1`] = `"DELETE FROM \`TBL1\`"`;
44

@@ -14,13 +14,13 @@ exports[`dbQueryToSQLSelect 4`] = `"SELECT * FROM \`TBL1\` WHERE \`a\` IS NULL A
1414

1515
exports[`dbQueryToSQLSelect 5`] = `"SELECT * FROM \`TBL1\` WHERE \`a\` IN ('a1', 'a2', 'a3')"`;
1616

17-
exports[`dbQueryToSQLUpdate 1`] = `"UPDATE \`TEST_TABLE\` SET \`id\` = 'id1', \`k1\` = 'v1', \`k2\` = 'v2', \`k3\` = 1, \`even\` = false, \`created\` = 1529539200, \`updated\` = 1529539200"`;
17+
exports[`dbQueryToSQLUpdate 1`] = `"UPDATE \`TEST_TABLE\` SET \`id\` = 'id1', \`k1\` = 'v1', \`k2\` = 'v2', \`k3\` = 1, \`even\` = false, \`nested\` = \`foo\` = 1, \`created\` = 1529539200, \`updated\` = 1529539200"`;
1818

19-
exports[`dbQueryToSQLUpdate 2`] = `"UPDATE \`TEST_TABLE\` SET \`id\` = 'id1', \`k1\` = 'v1', \`k2\` = 'v2', \`k3\` = 1, \`even\` = false, \`created\` = 1529539200, \`updated\` = 1529539200 WHERE \`a\` > 5"`;
19+
exports[`dbQueryToSQLUpdate 2`] = `"UPDATE \`TEST_TABLE\` SET \`id\` = 'id1', \`k1\` = 'v1', \`k2\` = 'v2', \`k3\` = 1, \`even\` = false, \`nested\` = \`foo\` = 1, \`created\` = 1529539200, \`updated\` = 1529539200 WHERE \`a\` > 5"`;
2020

2121
exports[`insertSQL 1`] = `
22-
"INSERT INTO \`TEST_TABLE\` (\`id\`,\`k1\`,\`k2\`,\`k3\`,\`even\`,\`created\`,\`updated\`) VALUES
23-
('id1','v1','v2',1,false,1529539200,1529539200),
24-
('id2','v2','v4',2,true,1529539200,1529539200),
25-
('id3','v3','v6',3,false,1529539200,1529539200)"
22+
"INSERT INTO \`TEST_TABLE\` (\`id\`,\`k1\`,\`k2\`,\`k3\`,\`even\`,\`nested\`,\`created\`,\`updated\`) VALUES
23+
('id1','v1','v2',1,false,\`foo\` = 1,1529539200,1529539200),
24+
('id2','v2','v4',2,true,\`foo\` = 2,1529539200,1529539200),
25+
('id3','v3','v6',3,false,\`foo\` = 3,1529539200,1529539200)"
2626
`;

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * from './mysql.db'
2-
export * from './mysqlKeyValueDB'
3-
export { jsonSchemaToMySQLDDL } from './schema/mysql.schema.util'
1+
export * from './mysql.db.js'
2+
export * from './mysqlKeyValueDB.js'
3+
export { jsonSchemaToMySQLDDL } from './schema/mysql.schema.util.js'

src/mysql.db.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
import { Readable, Transform } from 'node:stream'
22
import { promisify } from 'node:util'
3-
import {
4-
BaseCommonDB,
3+
import type {
54
CommonDB,
65
CommonDBCreateOptions,
7-
commonDBFullSupport,
86
CommonDBOptions,
97
CommonDBSaveOptions,
108
CommonDBSupport,
11-
CommonDBType,
12-
DBQuery,
139
RunQueryResult,
1410
} from '@naturalcycles/db-lib'
11+
import { BaseCommonDB, commonDBFullSupport, CommonDBType, DBQuery } from '@naturalcycles/db-lib'
12+
import type {
13+
CommonLogger,
14+
JsonSchemaObject,
15+
JsonSchemaRootObject,
16+
ObjectWithId,
17+
} from '@naturalcycles/js-lib'
1518
import {
1619
_assert,
1720
_filterUndefinedValues,
1821
_mapKeys,
1922
_mapValues,
2023
_Memo,
2124
_omit,
22-
CommonLogger,
2325
commonLoggerPrefix,
24-
JsonSchemaObject,
25-
JsonSchemaRootObject,
26-
ObjectWithId,
2726
} from '@naturalcycles/js-lib'
28-
import { ReadableTyped, white } from '@naturalcycles/nodejs-lib'
29-
import {
27+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
28+
import { white } from '@naturalcycles/nodejs-lib'
29+
import type {
3030
Connection,
3131
OkPacket,
3232
Pool,
@@ -36,13 +36,18 @@ import {
3636
TypeCast,
3737
} from 'mysql'
3838
import * as mysql from 'mysql'
39-
import { dbQueryToSQLDelete, dbQueryToSQLSelect, dbQueryToSQLUpdate, insertSQL } from './query.util'
39+
import {
40+
dbQueryToSQLDelete,
41+
dbQueryToSQLSelect,
42+
dbQueryToSQLUpdate,
43+
insertSQL,
44+
} from './query.util.js'
45+
import type { MySQLTableStats } from './schema/mysql.schema.util.js'
4046
import {
4147
jsonSchemaToMySQLDDL,
4248
mapNameFromMySQL,
43-
MySQLTableStats,
4449
mysqlTableStatsToJsonSchemaField,
45-
} from './schema/mysql.schema.util'
50+
} from './schema/mysql.schema.util.js'
4651

4752
export interface MysqlDBOptions extends CommonDBOptions {}
4853
export interface MysqlDBSaveOptions<ROW extends ObjectWithId> extends CommonDBSaveOptions<ROW> {}

src/mysqlKeyValueDB.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { Transform } from 'node:stream'
2-
import {
2+
import type {
33
CommonDBCreateOptions,
44
CommonKeyValueDB,
5-
commonKeyValueDBFullSupport,
65
KeyValueDBTuple,
76
} from '@naturalcycles/db-lib'
8-
import { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB'
9-
import { AppError, ObjectWithId, pMap } from '@naturalcycles/js-lib'
10-
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
11-
import { QueryOptions } from 'mysql'
12-
import { MysqlDB, MysqlDBCfg } from './mysql.db'
7+
import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib'
8+
import type { IncrementTuple } from '@naturalcycles/db-lib/dist/kv/commonKeyValueDB.js'
9+
import type { ObjectWithId } from '@naturalcycles/js-lib'
10+
import { AppError, pMap } from '@naturalcycles/js-lib'
11+
import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
12+
import type { QueryOptions } from 'mysql'
13+
import type { MysqlDBCfg } from './mysql.db.js'
14+
import { MysqlDB } from './mysql.db.js'
1315

1416
interface KeyValueObject {
1517
id: string

src/query.util.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ import {
33
createTestItemDBM,
44
createTestItemsDBM,
55
TEST_TABLE,
6-
} from '@naturalcycles/db-lib/dist/testing'
7-
import { dbQueryToSQLDelete, dbQueryToSQLSelect, dbQueryToSQLUpdate, insertSQL } from './query.util'
6+
} from '@naturalcycles/db-lib/dist/testing/index.js'
7+
import { expect, test } from 'vitest'
8+
import {
9+
dbQueryToSQLDelete,
10+
dbQueryToSQLSelect,
11+
dbQueryToSQLUpdate,
12+
insertSQL,
13+
} from './query.util.js'
814

915
test('dbQueryToSQLSelect', () => {
1016
let sql = dbQueryToSQLSelect(new DBQuery('TBL1'))

src/query.util.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
2-
import { _hb, AnyObjectWithId, CommonLogger } from '@naturalcycles/js-lib'
1+
import type { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
2+
import type { AnyObjectWithId, CommonLogger } from '@naturalcycles/js-lib'
3+
import { _hb } from '@naturalcycles/js-lib'
34
import { white, yellow } from '@naturalcycles/nodejs-lib'
4-
import { QueryOptions } from 'mysql'
5+
import type { QueryOptions } from 'mysql'
56
import * as mysql from 'mysql'
6-
import { mapNameToMySQL } from './schema/mysql.schema.util'
7+
import { mapNameToMySQL } from './schema/mysql.schema.util.js'
78

89
const MAX_PACKET_SIZE = 1024 * 1024 // 1Mb
910
const MAX_ROW_SIZE = 800 * 1024 // 1Mb - margin

0 commit comments

Comments
 (0)