Skip to content

Commit

Permalink
fix(deps): update deps, adapt to db-lib
Browse files Browse the repository at this point in the history
incrementBatch is to be implemented
  • Loading branch information
kirillgroshkov committed Oct 12, 2024
1 parent 6522566 commit 54add95
Show file tree
Hide file tree
Showing 13 changed files with 1,048 additions and 1,389 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- { uses: actions/setup-node@v4, with: { node-version: 'lts/*', cache: 'yarn' } }
- run: yarn --frozen-lockfile
- name: build
run: yarn build
run: yarn dev-lib tsc
- name: test
run: yarn test

Expand All @@ -34,7 +34,7 @@ jobs:
key: npm-v1-${{ runner.os }}

- run: yarn --frozen-lockfile
- run: yarn build-prod
- run: yarn build

- name: release
env:
Expand Down
5 changes: 1 addition & 4 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/bin/sh
[ -n "$CI" ] && exit 0
. "$(dirname "$0")/_/husky.sh"

node_modules/.bin/commitlint-def $1
# exit 1 # uncomment to debug
dev-lib commitlint $1
4 changes: 1 addition & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/sh
[ -n "$CI" ] && exit 0
. "$(dirname "$0")/_/husky.sh"

node_modules/.bin/lint-staged-def
dev-lib lint-staged
4 changes: 4 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"extends": ["node_modules/@naturalcycles/dev-lib/cfg/biome.jsonc"]
}
4 changes: 4 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// prettier-ignore
module.exports = [
...require('@naturalcycles/dev-lib/cfg/eslint.config'),
]
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "@naturalcycles/redis-lib",
"scripts": {
"prepare": "husky"
"prepare": "husky",
"build": "dev-lib build",
"test": "dev-lib test",
"lint": "dev-lib lint",
"bt": "dev-lib bt",
"lbt": "dev-lib lbt"
},
"dependencies": {
"@naturalcycles/db-lib": "^9.9.2",
Expand All @@ -10,8 +15,8 @@
"ioredis": "^5.3.2"
},
"devDependencies": {
"@naturalcycles/dev-lib": "^13.49.2",
"@types/node": "^20.12.2",
"@naturalcycles/dev-lib": "^15.22.0",
"@types/node": "^22.7.5",
"jest": "^29.7.0"
},
"files": [
Expand All @@ -33,7 +38,7 @@
"url": "https://github.com/NaturalCycles/redis-lib"
},
"engines": {
"node": ">=18.12"
"node": ">=20.13"
},
"version": "2.0.0",
"description": "Redis implementation of CommonKeyValueDB interface",
Expand Down
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@naturalcycles/dev-lib/cfg/prettier.config')
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './redisClient'
export * from './redisKeyValueDB'
export * from './redisHashKeyValueDB'
export * from './redisKeyValueDB'
9 changes: 5 additions & 4 deletions src/redisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
UnixTimestampNumber,
} from '@naturalcycles/js-lib'
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
// eslint-disable-next-line import/no-duplicates
// eslint-disable-next-line import-x/no-duplicates
import type { Redis, RedisOptions } from 'ioredis'
// eslint-disable-next-line import/no-duplicates
// eslint-disable-next-line import-x/no-duplicates
import type * as RedisLib from 'ioredis'
import type { ScanStreamOptions } from 'ioredis/built/types'
import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander'
Expand Down Expand Up @@ -153,7 +153,7 @@ export class RedisClient implements CommonClient {
return await this.redis().hmgetBuffer(key, ...fields)
}

async hincr(key: string, field: string, increment: number = 1): Promise<number> {
async hincr(key: string, field: string, increment = 1): Promise<number> {
return await this.redis().hincrby(key, field, increment)
}

Expand Down Expand Up @@ -183,7 +183,7 @@ export class RedisClient implements CommonClient {
await this.redis().mset(obj)
}

async incr(key: string, by: number = 1): Promise<number> {
async incr(key: string, by = 1): Promise<number> {
return await this.redis().incrby(key, by)
}

Expand Down Expand Up @@ -234,6 +234,7 @@ export class RedisClient implements CommonClient {
* Like scanStream, but flattens the stream of keys.
*/
scanStreamFlat(opt: ScanStreamOptions): ReadableTyped<string> {
// biome-ignore lint/correctness/noFlatMapIdentity: ok
return (this.redis().scanStream(opt) as ReadableTyped<string[]>).flatMap(keys => keys)
}

Expand Down
18 changes: 15 additions & 3 deletions src/redisHashKeyValueDB.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
CommonKeyValueDBSaveBatchOptions,
CommonDBCreateOptions,
CommonKeyValueDB,
commonKeyValueDBFullSupport,
CommonKeyValueDBSaveBatchOptions,
KeyValueDBTuple,
} from '@naturalcycles/db-lib'
import { _chunk, StringMap } from '@naturalcycles/js-lib'
Expand All @@ -22,6 +23,10 @@ export class RedisHashKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
this.keyOfHashField = cfg.hashKey
}

support = {
...commonKeyValueDBFullSupport,
}

async ping(): Promise<void> {
await this.client.ping()
}
Expand Down Expand Up @@ -96,7 +101,7 @@ export class RedisHashKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
.take(limit || Infinity)
}

streamEntries(table: string, limit?: number | undefined): ReadableTyped<KeyValueDBTuple> {
streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
return this.client
.hscanStream(this.keyOfHashField, {
match: `${table}:*`,
Expand All @@ -116,10 +121,17 @@ export class RedisHashKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
})
}

async increment(table: string, id: string, by: number = 1): Promise<number> {
async increment(table: string, id: string, by = 1): Promise<number> {
return await this.client.hincr(this.keyOfHashField, this.idToKey(table, id), by)
}

async incrementBatch(
_table: string,
_incrementMap: StringMap<number>,
): Promise<StringMap<number>> {
throw new Error('Not implemented')
}

async createTable(table: string, opt?: CommonDBCreateOptions): Promise<void> {
if (!opt?.dropIfExists) return

Expand Down
20 changes: 16 additions & 4 deletions src/redisKeyValueDB.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
CommonKeyValueDBSaveBatchOptions,
CommonDBCreateOptions,
CommonKeyValueDB,
commonKeyValueDBFullSupport,
CommonKeyValueDBSaveBatchOptions,
KeyValueDBTuple,
} from '@naturalcycles/db-lib'
import { _isTruthy, _zip } from '@naturalcycles/js-lib'
import { _isTruthy, _zip, StringMap } from '@naturalcycles/js-lib'
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
import { RedisClient } from './redisClient'

Expand All @@ -19,6 +20,10 @@ export class RedisKeyValueDB implements CommonKeyValueDB, AsyncDisposable {

client: RedisClient

support = {
...commonKeyValueDBFullSupport,
}

async ping(): Promise<void> {
await this.client.ping()
}
Expand Down Expand Up @@ -93,7 +98,7 @@ export class RedisKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
.take(limit || Infinity)
}

streamEntries(table: string, limit?: number | undefined): ReadableTyped<KeyValueDBTuple> {
streamEntries(table: string, limit?: number): ReadableTyped<KeyValueDBTuple> {
return this.client
.scanStream({
match: `${table}:*`,
Expand All @@ -118,10 +123,17 @@ export class RedisKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
})
}

async increment(table: string, id: string, by: number = 1): Promise<number> {
async increment(table: string, id: string, by = 1): Promise<number> {
return await this.client.incr(this.idToKey(table, id), by)
}

async incrementBatch(
_table: string,
_incrementMap: StringMap<number>,
): Promise<StringMap<number>> {
throw new Error('Not implemented')
}

async createTable(table: string, opt?: CommonDBCreateOptions): Promise<void> {
if (!opt?.dropIfExists) return

Expand Down
2 changes: 1 addition & 1 deletion src/test/redis.hash.manual.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommonKeyValueDao } from '@naturalcycles/db-lib'
import {
runCommonKeyValueDBTest,
runCommonKeyValueDaoTest,
runCommonKeyValueDBTest,
TEST_TABLE,
} from '@naturalcycles/db-lib/dist/testing'
import { KeyValueDBTuple } from '@naturalcycles/db-lib/src/kv/commonKeyValueDB'
Expand Down
Loading

0 comments on commit 54add95

Please sign in to comment.