@naturalcycles/redis-lib 3.3.1 → 4.0.0

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/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './redisClient';
2
- export * from './redisHashKeyValueDB';
3
- export * from './redisKeyValueDB';
1
+ export * from './redisClient.js';
2
+ export * from './redisHashKeyValueDB.js';
3
+ export * from './redisKeyValueDB.js';
package/dist/index.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./redisClient"), exports);
5
- tslib_1.__exportStar(require("./redisHashKeyValueDB"), exports);
6
- tslib_1.__exportStar(require("./redisKeyValueDB"), exports);
1
+ export * from './redisClient.js';
2
+ export * from './redisHashKeyValueDB.js';
3
+ export * from './redisKeyValueDB.js';
@@ -1,8 +1,8 @@
1
- import { AnyObject, CommonLogger, NullableBuffer, NullableString, Promisable, UnixTimestampNumber } from '@naturalcycles/js-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
1
+ import type { AnyObject, CommonLogger, NullableBuffer, NullableString, Promisable, UnixTimestamp } from '@naturalcycles/js-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
3
  import type { Redis, RedisOptions } from 'ioredis';
4
- import type { ScanStreamOptions } from 'ioredis/built/types';
5
- import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander';
4
+ import type { ScanStreamOptions } from 'ioredis/built/types.js';
5
+ import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander.js';
6
6
  export interface CommonClient extends AsyncDisposable {
7
7
  connected: boolean;
8
8
  connect: () => Promise<void>;
@@ -48,8 +48,8 @@ export declare class RedisClient implements CommonClient {
48
48
  hmgetBuffer(key: string, fields: string[]): Promise<NullableBuffer[]>;
49
49
  hincr(key: string, field: string, increment?: number): Promise<number>;
50
50
  hincrBatch(key: string, incrementTuples: [string, number][]): Promise<[string, number][]>;
51
- setWithTTL(key: string, value: string | number | Buffer, expireAt: UnixTimestampNumber): Promise<void>;
52
- hsetWithTTL(_key: string, _value: AnyObject, _expireAt: UnixTimestampNumber): Promise<void>;
51
+ setWithTTL(key: string, value: string | number | Buffer, expireAt: UnixTimestamp): Promise<void>;
52
+ hsetWithTTL(_key: string, _value: AnyObject, _expireAt: UnixTimestamp): Promise<void>;
53
53
  mset(obj: Record<string, string | number>): Promise<void>;
54
54
  msetBuffer(obj: Record<string, Buffer>): Promise<void>;
55
55
  incr(key: string, by?: number): Promise<number>;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisClient = void 0;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
1
+ import { _stringMapEntries } from '@naturalcycles/js-lib';
5
2
  /**
6
3
  Wraps the redis sdk with unified interface.
7
4
  Features:
@@ -10,9 +7,8 @@ const js_lib_1 = require("@naturalcycles/js-lib");
10
7
  - Reasonable defaults
11
8
 
12
9
  */
13
- class RedisClient {
10
+ export class RedisClient {
14
11
  constructor(cfg = {}) {
15
- this.connected = false;
16
12
  this.cfg = {
17
13
  logger: console,
18
14
  ...cfg,
@@ -23,6 +19,9 @@ class RedisClient {
23
19
  },
24
20
  };
25
21
  }
22
+ cfg;
23
+ connected = false;
24
+ _redis;
26
25
  redis() {
27
26
  if (this._redis)
28
27
  return this._redis;
@@ -108,7 +107,7 @@ class RedisClient {
108
107
  });
109
108
  }
110
109
  });
111
- const validResults = (0, js_lib_1._stringMapEntries)(results).filter(([_, v]) => v !== undefined);
110
+ const validResults = _stringMapEntries(results).filter(([_, v]) => v !== undefined);
112
111
  return validResults;
113
112
  }
114
113
  async setWithTTL(key, value, expireAt) {
@@ -142,7 +141,7 @@ class RedisClient {
142
141
  });
143
142
  }
144
143
  });
145
- const validResults = (0, js_lib_1._stringMapEntries)(results).filter(([_, v]) => v !== undefined);
144
+ const validResults = _stringMapEntries(results).filter(([_, v]) => v !== undefined);
146
145
  return validResults;
147
146
  }
148
147
  async ttl(key) {
@@ -215,4 +214,3 @@ class RedisClient {
215
214
  this.cfg.logger.log(...args);
216
215
  }
217
216
  }
218
- exports.RedisClient = RedisClient;
@@ -1,6 +1,6 @@
1
- import { CommonDBCreateOptions, CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { RedisKeyValueDBCfg } from './redisKeyValueDB';
1
+ import type { CommonDBCreateOptions, CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
+ import type { RedisKeyValueDBCfg } from './redisKeyValueDB.js';
4
4
  /**
5
5
  * RedisHashKeyValueDB is a KeyValueDB implementation that uses hash fields to simulate tables.
6
6
  * The value in the `table` arguments points to a hash field in Redis.
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisHashKeyValueDB = void 0;
4
- const db_lib_1 = require("@naturalcycles/db-lib");
1
+ import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib';
5
2
  /**
6
3
  * RedisHashKeyValueDB is a KeyValueDB implementation that uses hash fields to simulate tables.
7
4
  * The value in the `table` arguments points to a hash field in Redis.
@@ -14,13 +11,14 @@ const db_lib_1 = require("@naturalcycles/db-lib");
14
11
  * Once the available Redis version reaches 7.4.0+,
15
12
  * this implementation can take over for RedisKeyValueDB.
16
13
  */
17
- class RedisHashKeyValueDB {
14
+ export class RedisHashKeyValueDB {
15
+ cfg;
18
16
  constructor(cfg) {
19
17
  this.cfg = cfg;
20
- this.support = {
21
- ...db_lib_1.commonKeyValueDBFullSupport,
22
- };
23
18
  }
19
+ support = {
20
+ ...commonKeyValueDBFullSupport,
21
+ };
24
22
  async ping() {
25
23
  await this.cfg.client.ping();
26
24
  }
@@ -102,4 +100,3 @@ class RedisHashKeyValueDB {
102
100
  await this.cfg.client.del([table]);
103
101
  }
104
102
  }
105
- exports.RedisHashKeyValueDB = RedisHashKeyValueDB;
@@ -1,6 +1,6 @@
1
- import { CommonDBCreateOptions, CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
- import { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
- import { RedisClient } from './redisClient';
1
+ import type { CommonDBCreateOptions, CommonKeyValueDB, CommonKeyValueDBSaveBatchOptions, IncrementTuple, KeyValueDBTuple } from '@naturalcycles/db-lib';
2
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib';
3
+ import type { RedisClient } from './redisClient.js';
4
4
  export interface RedisKeyValueDBCfg {
5
5
  client: RedisClient;
6
6
  }
@@ -1,15 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RedisKeyValueDB = void 0;
4
- const db_lib_1 = require("@naturalcycles/db-lib");
5
- const js_lib_1 = require("@naturalcycles/js-lib");
6
- class RedisKeyValueDB {
1
+ import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib';
2
+ import { _isTruthy, _zip } from '@naturalcycles/js-lib';
3
+ export class RedisKeyValueDB {
4
+ cfg;
7
5
  constructor(cfg) {
8
6
  this.cfg = cfg;
9
- this.support = {
10
- ...db_lib_1.commonKeyValueDBFullSupport,
11
- };
12
7
  }
8
+ support = {
9
+ ...commonKeyValueDBFullSupport,
10
+ };
13
11
  async ping() {
14
12
  await this.cfg.client.ping();
15
13
  }
@@ -63,7 +61,7 @@ class RedisKeyValueDB {
63
61
  match: `${table}:*`,
64
62
  })
65
63
  .flatMap(async (keys) => {
66
- return (await this.cfg.client.mgetBuffer(keys)).filter(js_lib_1._isTruthy);
64
+ return (await this.cfg.client.mgetBuffer(keys)).filter(_isTruthy);
67
65
  }, {
68
66
  concurrency: 16,
69
67
  })
@@ -77,7 +75,7 @@ class RedisKeyValueDB {
77
75
  .flatMap(async (keys) => {
78
76
  // casting as Buffer[], because values are expected to exist for given keys
79
77
  const bufs = (await this.cfg.client.mgetBuffer(keys));
80
- return (0, js_lib_1._zip)(this.keysToIds(table, keys), bufs);
78
+ return _zip(this.keysToIds(table, keys), bufs);
81
79
  }, {
82
80
  concurrency: 16,
83
81
  })
@@ -113,4 +111,3 @@ class RedisKeyValueDB {
113
111
  return key.slice(table.length + 1);
114
112
  }
115
113
  }
116
- exports.RedisKeyValueDB = RedisKeyValueDB;
package/package.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/redis-lib",
3
+ "type": "module",
3
4
  "scripts": {
4
5
  "prepare": "husky",
5
6
  "build": "dev-lib build",
@@ -9,15 +10,17 @@
9
10
  "lbt": "dev-lib lbt"
10
11
  },
11
12
  "dependencies": {
12
- "@naturalcycles/db-lib": "^9.9.2",
13
- "@naturalcycles/js-lib": "^14.217.0",
14
- "@naturalcycles/nodejs-lib": "^13.8.0",
15
- "ioredis": "^5.3.2"
13
+ "@naturalcycles/db-lib": "^10",
14
+ "@naturalcycles/js-lib": "^14",
15
+ "@naturalcycles/nodejs-lib": "^13",
16
+ "ioredis": "^5"
16
17
  },
17
18
  "devDependencies": {
18
- "@naturalcycles/dev-lib": "^15.22.0",
19
- "@types/node": "^22.7.5",
20
- "jest": "^29.7.0"
19
+ "@naturalcycles/dev-lib": "^17",
20
+ "@types/node": "^22",
21
+ "@vitest/coverage-v8": "^3",
22
+ "tsx": "^4",
23
+ "vitest": "^3"
21
24
  },
22
25
  "files": [
23
26
  "dist",
@@ -38,9 +41,9 @@
38
41
  "url": "https://github.com/NaturalCycles/redis-lib"
39
42
  },
40
43
  "engines": {
41
- "node": ">=20.13"
44
+ "node": ">=22.10"
42
45
  },
43
- "version": "3.3.1",
46
+ "version": "4.0.0",
44
47
  "description": "Redis implementation of CommonKeyValueDB interface",
45
48
  "author": "Natural Cycles Team",
46
49
  "license": "MIT"
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './redisClient'
2
- export * from './redisHashKeyValueDB'
3
- export * from './redisKeyValueDB'
1
+ export * from './redisClient.js'
2
+ export * from './redisHashKeyValueDB.js'
3
+ export * from './redisKeyValueDB.js'
@@ -1,20 +1,18 @@
1
- import {
2
- _stringMapEntries,
1
+ import type {
3
2
  AnyObject,
4
3
  CommonLogger,
5
4
  NullableBuffer,
6
5
  NullableString,
7
6
  Promisable,
8
7
  StringMap,
9
- UnixTimestampNumber,
8
+ UnixTimestamp,
10
9
  } from '@naturalcycles/js-lib'
11
- import { ReadableTyped } from '@naturalcycles/nodejs-lib'
12
- // eslint-disable-next-line import-x/no-duplicates
10
+ import { _stringMapEntries } from '@naturalcycles/js-lib'
11
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
13
12
  import type { Redis, RedisOptions } from 'ioredis'
14
- // eslint-disable-next-line import-x/no-duplicates
15
13
  import type * as RedisLib from 'ioredis'
16
- import type { ScanStreamOptions } from 'ioredis/built/types'
17
- import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander'
14
+ import type { ScanStreamOptions } from 'ioredis/built/types.js'
15
+ import type { ChainableCommander } from 'ioredis/built/utils/RedisCommander.js'
18
16
 
19
17
  export interface CommonClient extends AsyncDisposable {
20
18
  connected: boolean
@@ -181,16 +179,12 @@ export class RedisClient implements CommonClient {
181
179
  async setWithTTL(
182
180
  key: string,
183
181
  value: string | number | Buffer,
184
- expireAt: UnixTimestampNumber,
182
+ expireAt: UnixTimestamp,
185
183
  ): Promise<void> {
186
184
  await this.redis().set(key, value, 'EXAT', expireAt)
187
185
  }
188
186
 
189
- async hsetWithTTL(
190
- _key: string,
191
- _value: AnyObject,
192
- _expireAt: UnixTimestampNumber,
193
- ): Promise<void> {
187
+ async hsetWithTTL(_key: string, _value: AnyObject, _expireAt: UnixTimestamp): Promise<void> {
194
188
  throw new Error('Not supported until Redis 7.4.0')
195
189
  // const valueKeys = Object.keys(value)
196
190
  // const numberOfKeys = valueKeys.length
@@ -1,13 +1,13 @@
1
- import {
1
+ import type {
2
2
  CommonDBCreateOptions,
3
3
  CommonKeyValueDB,
4
- commonKeyValueDBFullSupport,
5
4
  CommonKeyValueDBSaveBatchOptions,
6
5
  IncrementTuple,
7
6
  KeyValueDBTuple,
8
7
  } from '@naturalcycles/db-lib'
9
- import { ReadableTyped } from '@naturalcycles/nodejs-lib'
10
- import { RedisKeyValueDBCfg } from './redisKeyValueDB'
8
+ import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib'
9
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
10
+ import type { RedisKeyValueDBCfg } from './redisKeyValueDB.js'
11
11
 
12
12
  /**
13
13
  * RedisHashKeyValueDB is a KeyValueDB implementation that uses hash fields to simulate tables.
@@ -1,14 +1,14 @@
1
- import {
1
+ import type {
2
2
  CommonDBCreateOptions,
3
3
  CommonKeyValueDB,
4
- commonKeyValueDBFullSupport,
5
4
  CommonKeyValueDBSaveBatchOptions,
6
5
  IncrementTuple,
7
6
  KeyValueDBTuple,
8
7
  } from '@naturalcycles/db-lib'
8
+ import { commonKeyValueDBFullSupport } from '@naturalcycles/db-lib'
9
9
  import { _isTruthy, _zip } from '@naturalcycles/js-lib'
10
- import { ReadableTyped } from '@naturalcycles/nodejs-lib'
11
- import { RedisClient } from './redisClient'
10
+ import type { ReadableTyped } from '@naturalcycles/nodejs-lib'
11
+ import type { RedisClient } from './redisClient.js'
12
12
 
13
13
  export interface RedisKeyValueDBCfg {
14
14
  client: RedisClient