deepbase-redis 3.6.5 → 3.6.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepbase-redis",
3
- "version": "3.6.5",
3
+ "version": "3.6.6",
4
4
  "description": "⚡ DeepBase Redis (vanilla) - driver",
5
5
  "type": "module",
6
6
  "main": "src/index.cjs",
@@ -17,7 +17,7 @@
17
17
  "redis": "^4.7.0"
18
18
  },
19
19
  "peerDependencies": {
20
- "deepbase": "^3.6.5"
20
+ "deepbase": "^3.6.6"
21
21
  },
22
22
  "scripts": {
23
23
  "test": "mocha test/test.js"
@@ -195,6 +195,37 @@ export class RedisDriver extends DeepBaseDriver {
195
195
  const func = args.pop();
196
196
  return this.set(...args, func(await this.get(...args)));
197
197
  }
198
+
199
+ async first(...args) {
200
+ const value = await this.get(...args);
201
+ if (value === null || typeof value !== 'object') {
202
+ return undefined;
203
+ }
204
+
205
+ for (const key in value) {
206
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
207
+ return key;
208
+ }
209
+ }
210
+
211
+ return undefined;
212
+ }
213
+
214
+ async last(...args) {
215
+ const value = await this.get(...args);
216
+ if (value === null || typeof value !== 'object') {
217
+ return undefined;
218
+ }
219
+
220
+ let last;
221
+ for (const key in value) {
222
+ if (Object.prototype.hasOwnProperty.call(value, key)) {
223
+ last = key;
224
+ }
225
+ }
226
+
227
+ return last;
228
+ }
198
229
 
199
230
  async _zeroKeys() {
200
231
  const scan = {
package/test/test.js CHANGED
@@ -5,11 +5,34 @@ import { RedisDriver } from '../src/RedisDriver.js';
5
5
  describe('RedisDriver', function() {
6
6
  let db;
7
7
  let testCounter = 0;
8
+ let redisAvailable = true;
9
+ let redisSkipReason = '';
8
10
 
9
11
  // Increase timeout for Redis operations
10
12
  this.timeout(10000);
11
13
 
14
+ before(async function() {
15
+ const probeDb = new DeepBase(new RedisDriver({
16
+ url: 'redis://localhost:6379',
17
+ prefix: '__availability_probe__'
18
+ }));
19
+
20
+ try {
21
+ await probeDb.connect();
22
+ await probeDb.disconnect();
23
+ } catch (error) {
24
+ redisAvailable = false;
25
+ redisSkipReason = error?.message || 'Unknown Redis connection error';
26
+ console.warn(`[deepbase-redis:test] Redis is unavailable, skipping tests: ${redisSkipReason}`);
27
+ }
28
+ });
29
+
12
30
  beforeEach(async function() {
31
+ if (!redisAvailable) {
32
+ this.skip();
33
+ return;
34
+ }
35
+
13
36
  testCounter++;
14
37
  db = new DeepBase(new RedisDriver({
15
38
  url: 'redis://localhost:6379',
@@ -19,7 +42,7 @@ describe('RedisDriver', function() {
19
42
  try {
20
43
  await db.connect();
21
44
  } catch (error) {
22
- this.skip(); // Skip tests if Redis is not available
45
+ this.skip();
23
46
  }
24
47
  });
25
48
 
@@ -306,6 +329,19 @@ describe('RedisDriver', function() {
306
329
  assert.ok(entries.some(([k, v]) => k === 'alice' && v.age === 30));
307
330
  assert.ok(entries.some(([k, v]) => k === 'bob' && v.age === 25));
308
331
  });
332
+
333
+ it('first/last should match keys() boundaries', async function() {
334
+ const keys = await db.keys('users');
335
+ const driver = db.getDriver(0);
336
+ assert.strictEqual(await driver.first('users'), keys[0]);
337
+ assert.strictEqual(await driver.last('users'), keys[keys.length - 1]);
338
+ });
339
+
340
+ it('first/last should return undefined for missing path', async function() {
341
+ const driver = db.getDriver(0);
342
+ assert.strictEqual(await driver.first('missing'), undefined);
343
+ assert.strictEqual(await driver.last('missing'), undefined);
344
+ });
309
345
  });
310
346
 
311
347
  describe('Complex Nested Operations', function() {