Skip to content

Commit

Permalink
fix: deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Jan 21, 2024
1 parent 670333d commit ad9d856
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 55 deletions.
31 changes: 14 additions & 17 deletions src/mysql.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import {
_mapValues,
_Memo,
_omit,
AnyPartialObjectWithId,
CommonLogger,
commonLoggerPrefix,
JsonSchemaObject,
JsonSchemaRootObject,
PartialObjectWithId,
Saved,
ObjectWithId,
} from '@naturalcycles/js-lib'
import { ReadableTyped, white } from '@naturalcycles/nodejs-lib'
import {
Expand All @@ -48,8 +46,7 @@ import {
} from './schema/mysql.schema.util'

export interface MysqlDBOptions extends CommonDBOptions {}
export interface MysqlDBSaveOptions<ROW extends PartialObjectWithId = AnyPartialObjectWithId>
extends CommonDBSaveOptions<ROW> {}
export interface MysqlDBSaveOptions<ROW extends ObjectWithId> extends CommonDBSaveOptions<ROW> {}

/**
* @default false / undefined
Expand Down Expand Up @@ -196,22 +193,22 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
}

// GET
override async getByIds<ROW extends PartialObjectWithId>(
override async getByIds<ROW extends ObjectWithId>(
table: string,
ids: string[],
opt: MysqlDBOptions = {},
): Promise<Saved<ROW>[]> {
): Promise<ROW[]> {
if (!ids.length) return []
const q = new DBQuery<ROW>(table).filterEq('id', ids)
const { rows } = await this.runQuery(q, opt)
return rows.map(r => _mapKeys(r, k => mapNameFromMySQL(k as string)) as any)
}

// QUERY
override async runQuery<ROW extends PartialObjectWithId>(
override async runQuery<ROW extends ObjectWithId>(
q: DBQuery<ROW>,
_opt: MysqlDBOptions = {},
): Promise<RunQueryResult<Saved<ROW>>> {
): Promise<RunQueryResult<ROW>> {
const sql = dbQueryToSQLSelect(q)
if (!sql) {
return {
Expand Down Expand Up @@ -261,18 +258,18 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
}
}

override async runQueryCount<ROW extends PartialObjectWithId>(
override async runQueryCount<ROW extends ObjectWithId>(
q: DBQuery<ROW>,
_opt?: CommonDBOptions,
): Promise<number> {
const { rows } = await this.runQuery(q.select(['count(*) as _count' as any]))
return (rows[0] as any)._count
}

override streamQuery<ROW extends PartialObjectWithId>(
override streamQuery<ROW extends ObjectWithId>(
q: DBQuery<ROW>,
_opt: MysqlDBOptions = {},
): ReadableTyped<Saved<ROW>> {
): ReadableTyped<ROW> {
const sql = dbQueryToSQLSelect(q)
if (!sql) {
return Readable.from([])
Expand All @@ -295,7 +292,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
}

// SAVE
override async saveBatch<ROW extends PartialObjectWithId>(
override async saveBatch<ROW extends ObjectWithId>(
table: string,
rowsInput: ROW[],
opt: MysqlDBSaveOptions<ROW> = {},
Expand Down Expand Up @@ -373,7 +370,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
return affectedRows
}

override async deleteByQuery<ROW extends PartialObjectWithId>(
override async deleteByQuery<ROW extends ObjectWithId>(
q: DBQuery<ROW>,
_opt?: CommonDBOptions,
): Promise<number> {
Expand All @@ -393,7 +390,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
/**
* dropIfExists=true needed as a safety check
*/
override async createTable<ROW extends PartialObjectWithId>(
override async createTable<ROW extends ObjectWithId>(
table: string,
schema: JsonSchemaObject<ROW>,
opt: CommonDBCreateOptions = {},
Expand All @@ -410,7 +407,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
.filter(Boolean)
}

override async getTableSchema<ROW extends PartialObjectWithId>(
override async getTableSchema<ROW extends ObjectWithId>(
table: string,
): Promise<JsonSchemaRootObject<ROW>> {
const stats = await this.runSQL<MySQLTableStats[]>({
Expand All @@ -420,7 +417,7 @@ export class MysqlDB extends BaseCommonDB implements CommonDB {
return mysqlTableStatsToJsonSchemaField<ROW>(table, stats, this.cfg.logger)
}

override async updateByQuery<ROW extends PartialObjectWithId>(
override async updateByQuery<ROW extends ObjectWithId>(
q: DBQuery<ROW>,
patch: DBPatch<ROW>,
): Promise<number> {
Expand Down
12 changes: 6 additions & 6 deletions src/query.util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('dbQueryToSQLSelect', () => {
expect(sql).toMatchSnapshot()

sql = dbQueryToSQLSelect(
new DBQuery('TBL1')
new DBQuery<any>('TBL1')
.filterEq('a', 'b')
.filter('c', '>', '2019')
.order('aaa')
Expand All @@ -21,19 +21,19 @@ test('dbQueryToSQLSelect', () => {
// console.log(sql)
expect(sql).toMatchSnapshot()

sql = dbQueryToSQLSelect(new DBQuery('TBL1').filter('num', '>', 15))
sql = dbQueryToSQLSelect(new DBQuery<any>('TBL1').filter('num', '>', 15))
// console.log(sql)
expect(sql).toMatchSnapshot()

// NULL cases
sql = dbQueryToSQLSelect(
new DBQuery('TBL1').filterEq('a', undefined).filterEq('a2', null).filter('a3', '>', null),
new DBQuery<any>('TBL1').filterEq('a', undefined).filterEq('a2', null).filter('a3', '>', null),
)
// console.log(sql)
expect(sql).toMatchSnapshot()

// ARRAY CASES
sql = dbQueryToSQLSelect(new DBQuery('TBL1').filterEq('a', ['a1', 'a2', 'a3']))
sql = dbQueryToSQLSelect(new DBQuery<any>('TBL1').filterEq('a', ['a1', 'a2', 'a3']))
// console.log(sql)
expect(sql).toMatchSnapshot()
})
Expand All @@ -42,7 +42,7 @@ test('dbQueryToSQLDelete', () => {
let sql = dbQueryToSQLDelete(new DBQuery('TBL1'))
expect(sql).toMatchSnapshot()

sql = dbQueryToSQLDelete(new DBQuery('TBL1').filter('a', '>', null))
sql = dbQueryToSQLDelete(new DBQuery<any>('TBL1').filter('a', '>', null))
expect(sql).toMatchSnapshot()
})

Expand All @@ -60,7 +60,7 @@ test('dbQueryToSQLUpdate', () => {
// console.log(sql)
expect(sql).toMatchSnapshot()

sql = dbQueryToSQLUpdate(new DBQuery(TEST_TABLE).filter('a', '>', 5), item)
sql = dbQueryToSQLUpdate(new DBQuery<any>(TEST_TABLE).filter('a', '>', 5), item)
// console.log(sql)
expect(sql).toMatchSnapshot()
})
Expand Down
8 changes: 4 additions & 4 deletions src/query.util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DBQuery, DBQueryFilterOperator } from '@naturalcycles/db-lib'
import { _hb, CommonLogger } from '@naturalcycles/js-lib'
import { _hb, AnyObjectWithId, CommonLogger } from '@naturalcycles/js-lib'
import { white, yellow } from '@naturalcycles/nodejs-lib'
import { QueryOptions } from 'mysql'
import * as mysql from 'mysql'
Expand Down Expand Up @@ -160,7 +160,7 @@ export function dbQueryToSQLUpdate(q: DBQuery<any>, record: Record<any, any>): s
return mysql.format(tokens.join(' '), Object.values(record))
}

function selectTokens(q: DBQuery): string[] {
function selectTokens(q: DBQuery<any>): string[] {
let fields = ['*']

if (q._selectedFieldNames) {
Expand Down Expand Up @@ -192,7 +192,7 @@ function offsetLimitTokens(q: DBQuery<any>): string[] {
return tokens
}

function groupOrderTokens(q: DBQuery): string[] {
function groupOrderTokens(q: DBQuery<AnyObjectWithId>): string[] {
const t: string[] = []

if (q._groupByFieldNames?.length) {
Expand All @@ -216,7 +216,7 @@ const OP_MAP: Partial<Record<DBQueryFilterOperator, string>> = {
/**
* Returns `null` for "guaranteed 0 rows" cases.
*/
function getWhereTokens(q: DBQuery): string[] | null {
function getWhereTokens(q: DBQuery<any>): string[] | null {
if (!q._filters.length) return []

let returnNull = false
Expand Down
2 changes: 1 addition & 1 deletion src/test/mysql.manual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test('buffer', async () => {

await db.createTable(table, schema, { dropIfExists: true })
await db.saveBatch(table, items)
const { rows } = await db.runQuery(new DBQuery(table))
const { rows } = await db.runQuery<any>(new DBQuery(table))
// console.log(items2)
console.log(await inflateToString(rows[0]!['extra']))
expect(rows).toEqual(items)
Expand Down
54 changes: 27 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,9 @@
"@jridgewell/sourcemap-codec" "^1.4.10"

"@jridgewell/trace-mapping@^0.3.12", "@jridgewell/trace-mapping@^0.3.17", "@jridgewell/trace-mapping@^0.3.18", "@jridgewell/trace-mapping@^0.3.9":
version "0.3.21"
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.21.tgz#5dc1df7b3dc4a6209e503a924e1ca56097a2bb15"
integrity sha512-SRfKmRe1KvYnxjEMtxEr+J4HIeMX5YBg/qhRHpxEIGjhX1rshcHlnFUE9K0GazhVKWM7B+nARSkV8LuvJdJ5/g==
version "0.3.22"
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.22.tgz#72a621e5de59f5f1ef792d0793a82ee20f645e4c"
integrity sha512-Wf963MzWtA2sjrNt+g18IAln9lKnlRp+K2eH4jjIoF1wYeq3aMREpG09xhlhdzS0EjwU7qmUJYangWa+151vZw==
dependencies:
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"
Expand All @@ -799,9 +799,9 @@
typescript "^5.0.2"

"@naturalcycles/db-lib@^9.1.0":
version "9.3.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-9.3.0.tgz#d6727ff62b4150f26e83e3b68e5ca975229f154d"
integrity sha512-wcPFWmQ+jXtdXrSqPuXHnkzw4UjwvJUhtIIWFxLdsaoEFnA8peSsdpH+E5QIU7EDjXfQmYQ6nhcacmWQ6NvM+Q==
version "9.4.1"
resolved "https://registry.yarnpkg.com/@naturalcycles/db-lib/-/db-lib-9.4.1.tgz#e4ff4eaa571e3e78cf7a5b6d1cb0f08866a12b92"
integrity sha512-sb5p/T+da8/6BLPr5NRCX405JkZtKluCNkC+WY72L6MyPK0fEgOkXCyzpzs03b621SRIlH4lSqzLj+PwWsQJyw==
dependencies:
"@naturalcycles/js-lib" "^14.116.0"
"@naturalcycles/nodejs-lib" "^13.1.1"
Expand Down Expand Up @@ -842,17 +842,17 @@
yargs "^17.0.0"

"@naturalcycles/js-lib@^14.0.0", "@naturalcycles/js-lib@^14.116.0", "@naturalcycles/js-lib@^14.47.0":
version "14.204.1"
resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.204.1.tgz#d81838e4a8cd889b734637c2b26a750d5758ef10"
integrity sha512-+2E30+MKFdlxnkbsBHBcbi8aTTPl3AZRe+NUzgimJoJw+7wJS0k6v2DVbrmQ1MCcEyQ4gV5jhOQT8iHEtDDSDw==
version "14.206.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.206.0.tgz#529be8c590f31cd7dd432032387cca239b860c8f"
integrity sha512-PAoaYwrViznvASPixkaXCvonbaLEHs3yb4maQm5b1SXkiQq6viR8NLzaI+8/Rt3iWveP4BScluYYqfbuPJCtgg==
dependencies:
tslib "^2.0.0"
zod "^3.20.2"

"@naturalcycles/nodejs-lib@^13.0.1", "@naturalcycles/nodejs-lib@^13.1.0", "@naturalcycles/nodejs-lib@^13.1.1":
version "13.7.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/nodejs-lib/-/nodejs-lib-13.7.0.tgz#8d49d85d9c3165f20a9bbc08024bc213f5318cae"
integrity sha512-mPGMLS5pBP8U9ToVwM91+7ydir+fCUqYE3NVDotvfQW6jYf+LExKqnyMDGCEnwkGZhkafvGHbHBh5eqluyXsWA==
version "13.7.1"
resolved "https://registry.yarnpkg.com/@naturalcycles/nodejs-lib/-/nodejs-lib-13.7.1.tgz#2369c0a1b28de70bdf87fff067a2e6b2a651c2df"
integrity sha512-y0hVINujeLSVtggnfJEfavZMqLu32/ERIG+EcSgPHK4+MpnKMmpOkh3b59LjaVPs8JDvnCDWRTIPCOOllm1oLw==
dependencies:
"@naturalcycles/js-lib" "^14.0.0"
"@types/js-yaml" "^4.0.9"
Expand Down Expand Up @@ -918,9 +918,9 @@
integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==

"@sinonjs/commons@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.0.tgz#beb434fe875d965265e04722ccfc21df7f755d72"
integrity sha512-jXBtWAF4vmdNmZgD5FoKsVLv3rPgDnLgPbU84LIJ3otV44vJlDRokVng5v8NFJdCf/da9legHcKaRuZs4L7faA==
version "3.0.1"
resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-3.0.1.tgz#1029357e44ca901a615585f6d27738dbc89084cd"
integrity sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==
dependencies:
type-detect "4.0.8"

Expand Down Expand Up @@ -1811,9 +1811,9 @@ convert-source-map@^2.0.0:
integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==

core-js-compat@^3.34.0:
version "3.35.0"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.35.0.tgz#c149a3d1ab51e743bc1da61e39cb51f461a41873"
integrity sha512-5blwFAddknKeNgsjBzilkdQ0+YK8L1PfqPYq40NOYMYFSS38qj+hpTcLLWwpIwA2A5bje/x5jmVn2tzUMg9IVw==
version "3.35.1"
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.35.1.tgz#215247d7edb9e830efa4218ff719beb2803555e2"
integrity sha512-sftHa5qUJY3rs9Zht1WEnmkvXputCyDBczPnr7QDgL8n3qrF3CMXY4VPSYtOLLiOUJcah2WNXREd48iOl6mQIw==
dependencies:
browserslist "^4.22.2"

Expand Down Expand Up @@ -1980,9 +1980,9 @@ dot-prop@^5.1.0:
is-obj "^2.0.0"

dotenv@^16.0.0:
version "16.3.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==
version "16.3.2"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.2.tgz#3cb611ce5a63002dbabf7c281bc331f69d28f03f"
integrity sha512-HTlk5nmhkm8F6JcdXvHIzaorzCoziNQT9mGxLPVXW8wJF1TiGSL60ZGB4gHWabHOaMmWmhvk2/lPHfnBiT78AQ==

[email protected]:
version "1.0.11"
Expand All @@ -1992,9 +1992,9 @@ [email protected]:
safe-buffer "^5.0.1"

electron-to-chromium@^1.4.601:
version "1.4.639"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.639.tgz#c6f9cc685f9efb2980d2cfc95a27f8142c9adf28"
integrity sha512-CkKf3ZUVZchr+zDpAlNLEEy2NJJ9T64ULWaDgy3THXXlPVPkLu3VOs9Bac44nebVtdwl2geSj6AxTtGDOxoXhg==
version "1.4.640"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.640.tgz#76290a36fa4b5f1f4cadaf1fc582478ebb3ac246"
integrity sha512-z/6oZ/Muqk4BaE7P69bXhUhpJbUM9ZJeka43ZwxsDshKtePns4mhBlh8bU5+yrnOnz3fhG82XLzGUXazOmsWnA==

emittery@^0.13.1:
version "0.13.1"
Expand Down Expand Up @@ -4346,9 +4346,9 @@ reusify@^1.0.4:
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==

rfdc@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.3.0.tgz#d0b7c441ab2720d05dc4cf26e01c89631d9da08b"
integrity sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==
version "1.3.1"
resolved "https://registry.yarnpkg.com/rfdc/-/rfdc-1.3.1.tgz#2b6d4df52dffe8bb346992a10ea9451f24373a8f"
integrity sha512-r5a3l5HzYlIC68TpmYKlxWjmOP6wiPJ1vWv2HeLhNsRZMrCkxeqxiHlQ21oXmQ4F3SiryXBHhAD7JZqvOJjFmg==

rimraf@^3.0.2:
version "3.0.2"
Expand Down

0 comments on commit ad9d856

Please sign in to comment.