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

Commit 54add95

Browse files
fix(deps): update deps, adapt to db-lib
incrementBatch is to be implemented
1 parent 6522566 commit 54add95

File tree

13 files changed

+1048
-1389
lines changed

13 files changed

+1048
-1389
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- { uses: actions/setup-node@v4, with: { node-version: 'lts/*', cache: 'yarn' } }
1414
- run: yarn --frozen-lockfile
1515
- name: build
16-
run: yarn build
16+
run: yarn dev-lib tsc
1717
- name: test
1818
run: yarn test
1919

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

3636
- run: yarn --frozen-lockfile
37-
- run: yarn build-prod
37+
- run: yarn build
3838

3939
- name: release
4040
env:

.husky/commit-msg

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/bin/sh
21
[ -n "$CI" ] && exit 0
3-
. "$(dirname "$0")/_/husky.sh"
42

5-
node_modules/.bin/commitlint-def $1
6-
# exit 1 # uncomment to debug
3+
dev-lib commitlint $1

.husky/pre-commit

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/bin/sh
21
[ -n "$CI" ] && exit 0
3-
. "$(dirname "$0")/_/husky.sh"
42

5-
node_modules/.bin/lint-staged-def
3+
dev-lib lint-staged

biome.jsonc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
3+
"extends": ["node_modules/@naturalcycles/dev-lib/cfg/biome.jsonc"]
4+
}

eslint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// prettier-ignore
2+
module.exports = [
3+
...require('@naturalcycles/dev-lib/cfg/eslint.config'),
4+
]

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"name": "@naturalcycles/redis-lib",
33
"scripts": {
4-
"prepare": "husky"
4+
"prepare": "husky",
5+
"build": "dev-lib build",
6+
"test": "dev-lib test",
7+
"lint": "dev-lib lint",
8+
"bt": "dev-lib bt",
9+
"lbt": "dev-lib lbt"
510
},
611
"dependencies": {
712
"@naturalcycles/db-lib": "^9.9.2",
@@ -10,8 +15,8 @@
1015
"ioredis": "^5.3.2"
1116
},
1217
"devDependencies": {
13-
"@naturalcycles/dev-lib": "^13.49.2",
14-
"@types/node": "^20.12.2",
18+
"@naturalcycles/dev-lib": "^15.22.0",
19+
"@types/node": "^22.7.5",
1520
"jest": "^29.7.0"
1621
},
1722
"files": [
@@ -33,7 +38,7 @@
3338
"url": "https://github.com/NaturalCycles/redis-lib"
3439
},
3540
"engines": {
36-
"node": ">=18.12"
41+
"node": ">=20.13"
3742
},
3843
"version": "2.0.0",
3944
"description": "Redis implementation of CommonKeyValueDB interface",

prettier.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@naturalcycles/dev-lib/cfg/prettier.config')

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './redisClient'
2-
export * from './redisKeyValueDB'
32
export * from './redisHashKeyValueDB'
3+
export * from './redisKeyValueDB'

src/redisClient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
UnixTimestampNumber,
88
} from '@naturalcycles/js-lib'
99
import { ReadableTyped } from '@naturalcycles/nodejs-lib'
10-
// eslint-disable-next-line import/no-duplicates
10+
// eslint-disable-next-line import-x/no-duplicates
1111
import type { Redis, RedisOptions } from 'ioredis'
12-
// eslint-disable-next-line import/no-duplicates
12+
// eslint-disable-next-line import-x/no-duplicates
1313
import type * as RedisLib from 'ioredis'
1414
import type { ScanStreamOptions } from 'ioredis/built/types'
1515
import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander'
@@ -153,7 +153,7 @@ export class RedisClient implements CommonClient {
153153
return await this.redis().hmgetBuffer(key, ...fields)
154154
}
155155

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

@@ -183,7 +183,7 @@ export class RedisClient implements CommonClient {
183183
await this.redis().mset(obj)
184184
}
185185

186-
async incr(key: string, by: number = 1): Promise<number> {
186+
async incr(key: string, by = 1): Promise<number> {
187187
return await this.redis().incrby(key, by)
188188
}
189189

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

src/redisHashKeyValueDB.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
2-
CommonKeyValueDBSaveBatchOptions,
32
CommonDBCreateOptions,
43
CommonKeyValueDB,
4+
commonKeyValueDBFullSupport,
5+
CommonKeyValueDBSaveBatchOptions,
56
KeyValueDBTuple,
67
} from '@naturalcycles/db-lib'
78
import { _chunk, StringMap } from '@naturalcycles/js-lib'
@@ -22,6 +23,10 @@ export class RedisHashKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
2223
this.keyOfHashField = cfg.hashKey
2324
}
2425

26+
support = {
27+
...commonKeyValueDBFullSupport,
28+
}
29+
2530
async ping(): Promise<void> {
2631
await this.client.ping()
2732
}
@@ -96,7 +101,7 @@ export class RedisHashKeyValueDB implements CommonKeyValueDB, AsyncDisposable {
96101
.take(limit || Infinity)
97102
}
98103

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

119-
async increment(table: string, id: string, by: number = 1): Promise<number> {
124+
async increment(table: string, id: string, by = 1): Promise<number> {
120125
return await this.client.hincr(this.keyOfHashField, this.idToKey(table, id), by)
121126
}
122127

128+
async incrementBatch(
129+
_table: string,
130+
_incrementMap: StringMap<number>,
131+
): Promise<StringMap<number>> {
132+
throw new Error('Not implemented')
133+
}
134+
123135
async createTable(table: string, opt?: CommonDBCreateOptions): Promise<void> {
124136
if (!opt?.dropIfExists) return
125137

0 commit comments

Comments
 (0)