conduithub 0.1.0 → 1.0.1

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.
Files changed (83) hide show
  1. package/dist/core/conduit-hub/index.cjs +188 -0
  2. package/dist/core/conduit-hub/index.d.cts +44 -0
  3. package/dist/core/conduit-hub/index.d.mts +44 -0
  4. package/dist/core/conduit-hub/index.d.ts +44 -0
  5. package/dist/core/conduit-hub/index.mjs +186 -0
  6. package/dist/core/config-manager/index.cjs +216 -0
  7. package/dist/core/config-manager/index.d.cts +7 -0
  8. package/dist/core/config-manager/index.d.mts +7 -0
  9. package/dist/core/config-manager/index.d.ts +7 -0
  10. package/dist/core/config-manager/index.mjs +214 -0
  11. package/dist/core/event-bus/index.cjs +154 -53
  12. package/dist/core/event-bus/index.d.cts +2 -42
  13. package/dist/core/event-bus/index.d.mts +2 -42
  14. package/dist/core/event-bus/index.d.ts +2 -42
  15. package/dist/core/event-bus/index.mjs +153 -52
  16. package/dist/core/hook/index.cjs +185 -148
  17. package/dist/core/hook/index.d.cts +28 -16
  18. package/dist/core/hook/index.d.mts +28 -16
  19. package/dist/core/hook/index.d.ts +28 -16
  20. package/dist/core/hook/index.mjs +183 -146
  21. package/dist/core/index.cjs +17 -1
  22. package/dist/core/index.d.cts +184 -3
  23. package/dist/core/index.d.mts +184 -3
  24. package/dist/core/index.d.ts +184 -3
  25. package/dist/core/index.mjs +12 -1
  26. package/dist/core/plugin/index.cjs +271 -0
  27. package/dist/core/plugin/index.d.cts +7 -0
  28. package/dist/core/plugin/index.d.mts +7 -0
  29. package/dist/core/plugin/index.d.ts +7 -0
  30. package/dist/core/plugin/index.mjs +268 -0
  31. package/dist/core/service-container/index.cjs +306 -0
  32. package/dist/core/service-container/index.d.cts +51 -0
  33. package/dist/core/service-container/index.d.mts +51 -0
  34. package/dist/core/service-container/index.d.ts +51 -0
  35. package/dist/core/service-container/index.mjs +304 -0
  36. package/dist/core/state-manager/index.cjs +195 -0
  37. package/dist/core/state-manager/index.d.cts +39 -0
  38. package/dist/core/state-manager/index.d.mts +39 -0
  39. package/dist/core/state-manager/index.d.ts +39 -0
  40. package/dist/core/state-manager/index.mjs +193 -0
  41. package/dist/error/index.cjs +71 -0
  42. package/dist/error/index.d.cts +47 -0
  43. package/dist/error/index.d.mts +47 -0
  44. package/dist/error/index.d.ts +47 -0
  45. package/dist/error/index.mjs +65 -0
  46. package/dist/index.cjs +38 -5
  47. package/dist/index.d.cts +8 -2
  48. package/dist/index.d.mts +8 -2
  49. package/dist/index.d.ts +8 -2
  50. package/dist/index.mjs +16 -1
  51. package/dist/plugins/index.cjs +12 -0
  52. package/dist/plugins/index.d.cts +8 -0
  53. package/dist/plugins/index.d.mts +8 -0
  54. package/dist/plugins/index.d.ts +8 -0
  55. package/dist/plugins/index.mjs +6 -0
  56. package/dist/plugins/redis/index.cjs +12 -0
  57. package/dist/plugins/redis/index.d.cts +109 -0
  58. package/dist/plugins/redis/index.d.mts +109 -0
  59. package/dist/plugins/redis/index.d.ts +109 -0
  60. package/dist/plugins/redis/index.mjs +6 -0
  61. package/dist/shared/conduithub.-bZD30_I.mjs +769 -0
  62. package/dist/shared/{conduithub.CvMLTa-R.cjs → conduithub.BNQsddJO.cjs} +2 -9
  63. package/dist/shared/{conduithub.74V0wiLi.mjs → conduithub.BNefRQsK.mjs} +3 -9
  64. package/dist/shared/conduithub.BZQmkQy7.d.cts +52 -0
  65. package/dist/shared/conduithub.Bq_7Xj0J.cjs +18 -0
  66. package/dist/shared/conduithub.BzLwccre.d.mts +52 -0
  67. package/dist/shared/conduithub.CkOQG3cD.mjs +14 -0
  68. package/dist/shared/conduithub.CmZo_Vuc.cjs +38 -0
  69. package/dist/shared/conduithub.DQO1dRnn.cjs +33 -0
  70. package/dist/shared/conduithub.DQOWQ-Bx.d.ts +52 -0
  71. package/dist/shared/conduithub.Dlvl2xGE.cjs +76 -0
  72. package/dist/shared/conduithub.DsOOeNwU.cjs +269 -0
  73. package/dist/shared/conduithub.DyQQrHW9.mjs +267 -0
  74. package/dist/shared/conduithub.G7ICpZIy.mjs +36 -0
  75. package/dist/shared/conduithub.Up0QYVao.mjs +59 -0
  76. package/dist/shared/conduithub.alPiaJax.mjs +29 -0
  77. package/dist/shared/conduithub.cvEjE62V.cjs +775 -0
  78. package/dist/utils/index.cjs +19 -5
  79. package/dist/utils/index.d.cts +33 -2
  80. package/dist/utils/index.d.mts +33 -2
  81. package/dist/utils/index.d.ts +33 -2
  82. package/dist/utils/index.mjs +8 -1
  83. package/package.json +55 -7
@@ -0,0 +1,775 @@
1
+ 'use strict';
2
+
3
+ const Redis = require('ioredis');
4
+ const core_plugin_index = require('../core/plugin/index.cjs');
5
+ const zod = require('zod');
6
+
7
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
8
+
9
+ const Redis__default = /*#__PURE__*/_interopDefaultCompat(Redis);
10
+
11
+ const redisConfigSchema = zod.z.object({
12
+ host: zod.z.string().default("localhost"),
13
+ port: zod.z.number().default(6379),
14
+ password: zod.z.string().optional(),
15
+ db: zod.z.number().default(0),
16
+ username: zod.z.string().optional(),
17
+ url: zod.z.string().url().optional(),
18
+ keyPrefix: zod.z.string().optional(),
19
+ tls: zod.z.object({
20
+ ca: zod.z.string().optional(),
21
+ cert: zod.z.string().optional(),
22
+ key: zod.z.string().optional(),
23
+ rejectUnauthorized: zod.z.boolean().default(true)
24
+ }).optional(),
25
+ connectionTimeout: zod.z.number().default(5e4),
26
+ commandTimeout: zod.z.number().default(5e4),
27
+ maxRetriesPerRequest: zod.z.number().default(3),
28
+ retryDelayOnFailover: zod.z.number().default(100),
29
+ enableReadyCheck: zod.z.boolean().default(true),
30
+ enableOfflineQueue: zod.z.boolean().default(true),
31
+ keepAlive: zod.z.boolean().default(true),
32
+ lazyConnect: zod.z.boolean().default(false),
33
+ family: zod.z.enum(["IPv4", "IPv6"]).default("IPv4")
34
+ });
35
+
36
+ function createNoopRedisClient() {
37
+ return {
38
+ set: async () => "OK",
39
+ get: async () => null,
40
+ del: async () => 0,
41
+ exists: async () => 0,
42
+ expire: async () => 1,
43
+ ttl: async () => -1,
44
+ hset: async () => 1,
45
+ hget: async () => null,
46
+ hgetall: async () => ({}),
47
+ hdel: async () => 0,
48
+ lpush: async () => 0,
49
+ rpush: async () => 0,
50
+ lpop: async () => null,
51
+ rpop: async () => null,
52
+ llen: async () => 0,
53
+ lrange: async () => [],
54
+ sadd: async () => 0,
55
+ srem: async () => 0,
56
+ smembers: async () => [],
57
+ sismember: async () => 0,
58
+ scard: async () => 0,
59
+ zadd: async () => 0,
60
+ zrange: async () => [],
61
+ ping: async () => "PONG",
62
+ flushdb: async () => "OK",
63
+ flushall: async () => "OK"
64
+ };
65
+ }
66
+ class RedisPlugin extends core_plugin_index.BasePlugin {
67
+ redis;
68
+ ioredisClient;
69
+ isConnected = false;
70
+ stats = {
71
+ totalCommands: 0,
72
+ successfulCommands: 0,
73
+ failedCommands: 0,
74
+ averageResponseTime: 0
75
+ };
76
+ async run(operation, payload, call) {
77
+ await this.executeHook("before-redis-operation", {
78
+ operation,
79
+ ...payload
80
+ });
81
+ const start = Date.now();
82
+ try {
83
+ const result = await call();
84
+ const duration = Date.now() - start;
85
+ this.stats.totalCommands++;
86
+ this.stats.successfulCommands++;
87
+ const n = this.stats.successfulCommands;
88
+ this.stats.averageResponseTime = this.stats.averageResponseTime + (duration - this.stats.averageResponseTime) / n;
89
+ this.stats.lastCommandTime = Date.now();
90
+ await this.executeHook("after-redis-operation", {
91
+ operation,
92
+ ...payload,
93
+ result
94
+ });
95
+ return result;
96
+ } catch (error) {
97
+ this.stats.totalCommands++;
98
+ this.stats.failedCommands++;
99
+ await this.executeHook("after-redis-operation", {
100
+ operation,
101
+ ...payload,
102
+ error
103
+ });
104
+ this.logger.log?.("error", `Redis ${operation} failed`, error);
105
+ throw error;
106
+ }
107
+ }
108
+ constructor(config) {
109
+ const normalized = redisConfigSchema.parse(config ?? {});
110
+ super({
111
+ name: "redis",
112
+ version: "1.0.0",
113
+ enabled: true,
114
+ dependencies: [],
115
+ config: normalized
116
+ });
117
+ }
118
+ createRedisWrapper(redisClient) {
119
+ return {
120
+ set: async (key, value, options) => {
121
+ if (!options || Object.keys(options).length === 0) {
122
+ return redisClient.set(key, String(value));
123
+ }
124
+ const setOptions = {};
125
+ if (options.EX) setOptions.EX = options.EX;
126
+ if (options.PX) setOptions.PX = options.PX;
127
+ if (options.NX) setOptions.GET = false;
128
+ if (options.XX) setOptions.GET = false;
129
+ return redisClient.set(key, String(value), setOptions);
130
+ },
131
+ get: (key) => redisClient.get(key),
132
+ del: (key) => Array.isArray(key) ? redisClient.del(...key) : redisClient.del(key),
133
+ exists: (key) => Array.isArray(key) ? redisClient.exists(...key) : redisClient.exists(key),
134
+ expire: (key, seconds) => redisClient.expire(key, seconds),
135
+ ttl: (key) => redisClient.ttl(key),
136
+ hset: (key, field, value) => redisClient.hset(key, field, value),
137
+ hget: (key, field) => redisClient.hget(key, field),
138
+ hgetall: (key) => redisClient.hgetall(key),
139
+ hdel: (key, field) => Array.isArray(field) ? redisClient.hdel(key, ...field) : redisClient.hdel(key, field),
140
+ lpush: (key, ...elements) => redisClient.lpush(key, ...elements),
141
+ rpush: (key, ...elements) => redisClient.rpush(key, ...elements),
142
+ lpop: (key) => redisClient.lpop(key),
143
+ rpop: (key) => redisClient.rpop(key),
144
+ llen: (key) => redisClient.llen(key),
145
+ lrange: (key, start, stop) => redisClient.lrange(key, start, stop),
146
+ sadd: (key, ...members) => redisClient.sadd(key, ...members),
147
+ srem: (key, ...members) => redisClient.srem(key, ...members),
148
+ smembers: (key) => redisClient.smembers(key),
149
+ sismember: (key, member) => redisClient.sismember(key, member),
150
+ scard: (key) => redisClient.scard(key),
151
+ zadd: (key, score, member) => redisClient.zadd(key, score, member),
152
+ zrange: (key, start, stop) => redisClient.zrange(key, start, stop),
153
+ ping: () => redisClient.ping(),
154
+ flushdb: () => redisClient.flushdb(),
155
+ flushall: () => redisClient.flushall()
156
+ };
157
+ }
158
+ getMetadata() {
159
+ return {
160
+ name: "redis",
161
+ version: "1.0.0",
162
+ description: "Redis plugin for ConduitHub - provides Redis client functionality",
163
+ author: "ConduitHub",
164
+ dependencies: [],
165
+ hooks: ["before-redis-operation", "after-redis-operation"],
166
+ events: ["redis-connected", "redis-disconnected", "redis-error"]
167
+ };
168
+ }
169
+ async onInitialize() {
170
+ this.logger.log?.("info", "Initializing Redis plugin...");
171
+ const config = this.getConfig().config;
172
+ try {
173
+ const redisOptions = {
174
+ host: config.host,
175
+ port: config.port,
176
+ db: config.db,
177
+ retryDelayOnFailover: config.retryDelayOnFailover,
178
+ maxRetriesPerRequest: config.maxRetriesPerRequest,
179
+ connectTimeout: config.connectionTimeout,
180
+ commandTimeout: config.commandTimeout
181
+ };
182
+ if (config.password) redisOptions.password = config.password;
183
+ if (config.username) redisOptions.username = config.username;
184
+ if (config.keyPrefix) redisOptions.keyPrefix = config.keyPrefix;
185
+ if (config.tls) redisOptions.tls = config.tls;
186
+ const redisClient = new Redis__default(redisOptions);
187
+ await redisClient.ping();
188
+ this.ioredisClient = redisClient;
189
+ this.redis = this.createRedisWrapper(redisClient);
190
+ this.logger.log?.("info", "Successfully connected to Redis server");
191
+ } catch (error) {
192
+ this.logger.log?.(
193
+ "error",
194
+ "Failed to connect to Redis server, using no-op client",
195
+ error
196
+ );
197
+ this.ioredisClient = void 0;
198
+ this.redis = createNoopRedisClient();
199
+ }
200
+ }
201
+ async onStart() {
202
+ this.isConnected = true;
203
+ const cfg = this.getConfig().config;
204
+ await this.emit("redis-connected", {
205
+ host: cfg.host,
206
+ port: cfg.port,
207
+ db: cfg.db,
208
+ connected: true,
209
+ timestamp: Date.now()
210
+ });
211
+ this.logger.log?.("info", "Redis plugin started");
212
+ }
213
+ async onStop() {
214
+ this.isConnected = false;
215
+ const cfg = this.getConfig().config;
216
+ await this.emit("redis-disconnected", {
217
+ host: cfg.host,
218
+ port: cfg.port,
219
+ db: cfg.db,
220
+ connected: false,
221
+ timestamp: Date.now()
222
+ });
223
+ this.logger.log?.("info", "Redis plugin stopped");
224
+ }
225
+ async onDestroy() {
226
+ try {
227
+ if (this.ioredisClient) {
228
+ await Promise.race([
229
+ this.ioredisClient.quit(),
230
+ new Promise(
231
+ (_, reject) => setTimeout(() => reject(new Error("Quit timeout")), 1e3)
232
+ )
233
+ ]);
234
+ this.logger.log?.("info", "Redis connection closed gracefully");
235
+ }
236
+ } catch (error) {
237
+ this.logger.log?.("error", "Error closing Redis connection", error);
238
+ try {
239
+ if (this.ioredisClient) {
240
+ await Promise.race([
241
+ this.ioredisClient.disconnect(),
242
+ new Promise(
243
+ (_, reject) => setTimeout(
244
+ () => reject(new Error("Force disconnect timeout")),
245
+ 500
246
+ )
247
+ )
248
+ ]);
249
+ this.logger.log?.("info", "Redis connection force disconnected");
250
+ }
251
+ } catch (disconnectError) {
252
+ this.logger.log?.(
253
+ "error",
254
+ "Error during force disconnect",
255
+ disconnectError
256
+ );
257
+ }
258
+ } finally {
259
+ this.ioredisClient = void 0;
260
+ this.redis = createNoopRedisClient();
261
+ this.logger.log?.("info", "Redis plugin destroyed");
262
+ }
263
+ }
264
+ async set(key, value, options) {
265
+ return this.run(
266
+ "set",
267
+ { key, value, options },
268
+ () => this.redis.set(key, value, options)
269
+ );
270
+ }
271
+ async get(key) {
272
+ return this.run("get", { key }, () => this.redis.get(key));
273
+ }
274
+ async del(key) {
275
+ return this.run("del", { key }, () => this.redis.del(key));
276
+ }
277
+ async exists(key) {
278
+ await this.executeHook("before-redis-operation", {
279
+ operation: "exists",
280
+ key
281
+ });
282
+ try {
283
+ const result = await this.redis.exists(key);
284
+ await this.executeHook("after-redis-operation", {
285
+ operation: "exists",
286
+ key,
287
+ result
288
+ });
289
+ return result;
290
+ } catch (error) {
291
+ this.logger.log?.(
292
+ "error",
293
+ `Redis EXISTS operation failed for key: ${key}`,
294
+ error
295
+ );
296
+ throw error;
297
+ }
298
+ }
299
+ async expire(key, seconds) {
300
+ await this.executeHook("before-redis-operation", {
301
+ operation: "expire",
302
+ key,
303
+ seconds
304
+ });
305
+ try {
306
+ const result = await this.redis.expire(key, seconds);
307
+ await this.executeHook("after-redis-operation", {
308
+ operation: "expire",
309
+ key,
310
+ seconds,
311
+ result
312
+ });
313
+ return result;
314
+ } catch (error) {
315
+ this.logger.log?.(
316
+ "error",
317
+ `Redis EXPIRE operation failed for key: ${key}`,
318
+ error
319
+ );
320
+ throw error;
321
+ }
322
+ }
323
+ async ttl(key) {
324
+ await this.executeHook("before-redis-operation", { operation: "ttl", key });
325
+ try {
326
+ const result = await this.redis.ttl(key);
327
+ await this.executeHook("after-redis-operation", {
328
+ operation: "ttl",
329
+ key,
330
+ result
331
+ });
332
+ return result;
333
+ } catch (error) {
334
+ this.logger.log?.(
335
+ "error",
336
+ `Redis TTL operation failed for key: ${key}`,
337
+ error
338
+ );
339
+ throw error;
340
+ }
341
+ }
342
+ // Hash operations
343
+ async hset(key, field, value) {
344
+ await this.executeHook("before-redis-operation", {
345
+ operation: "hset",
346
+ key,
347
+ field,
348
+ value
349
+ });
350
+ try {
351
+ const result = await this.redis.hset(key, field, value);
352
+ await this.executeHook("after-redis-operation", {
353
+ operation: "hset",
354
+ key,
355
+ field,
356
+ value,
357
+ result
358
+ });
359
+ return result;
360
+ } catch (error) {
361
+ this.logger.log?.(
362
+ "error",
363
+ `Redis HSET operation failed for key: ${key}`,
364
+ error
365
+ );
366
+ throw error;
367
+ }
368
+ }
369
+ async hget(key, field) {
370
+ await this.executeHook("before-redis-operation", {
371
+ operation: "hget",
372
+ key,
373
+ field
374
+ });
375
+ try {
376
+ const result = await this.redis.hget(key, field);
377
+ await this.executeHook("after-redis-operation", {
378
+ operation: "hget",
379
+ key,
380
+ field,
381
+ result
382
+ });
383
+ return result;
384
+ } catch (error) {
385
+ this.logger.log?.(
386
+ "error",
387
+ `Redis HGET operation failed for key: ${key}`,
388
+ error
389
+ );
390
+ throw error;
391
+ }
392
+ }
393
+ async hgetall(key) {
394
+ await this.executeHook("before-redis-operation", {
395
+ operation: "hgetall",
396
+ key
397
+ });
398
+ try {
399
+ const result = await this.redis.hgetall(key);
400
+ await this.executeHook("after-redis-operation", {
401
+ operation: "hgetall",
402
+ key,
403
+ result
404
+ });
405
+ return result;
406
+ } catch (error) {
407
+ this.logger.log?.(
408
+ "error",
409
+ `Redis HGETALL operation failed for key: ${key}`,
410
+ error
411
+ );
412
+ throw error;
413
+ }
414
+ }
415
+ async hdel(key, field) {
416
+ await this.executeHook("before-redis-operation", {
417
+ operation: "hdel",
418
+ key,
419
+ field
420
+ });
421
+ try {
422
+ const result = await this.redis.hdel(key, field);
423
+ await this.executeHook("after-redis-operation", {
424
+ operation: "hdel",
425
+ key,
426
+ field,
427
+ result
428
+ });
429
+ return result;
430
+ } catch (error) {
431
+ this.logger.log?.(
432
+ "error",
433
+ `Redis HDEL operation failed for key: ${key}`,
434
+ error
435
+ );
436
+ throw error;
437
+ }
438
+ }
439
+ // List operations
440
+ async lpush(key, ...elements) {
441
+ await this.executeHook("before-redis-operation", {
442
+ operation: "lpush",
443
+ key,
444
+ elements
445
+ });
446
+ try {
447
+ const result = await this.redis.lpush(key, ...elements);
448
+ await this.executeHook("after-redis-operation", {
449
+ operation: "lpush",
450
+ key,
451
+ elements,
452
+ result
453
+ });
454
+ return result;
455
+ } catch (error) {
456
+ this.logger.log?.(
457
+ "error",
458
+ `Redis LPUSH operation failed for key: ${key}`,
459
+ error
460
+ );
461
+ throw error;
462
+ }
463
+ }
464
+ async rpush(key, ...elements) {
465
+ await this.executeHook("before-redis-operation", {
466
+ operation: "rpush",
467
+ key,
468
+ elements
469
+ });
470
+ try {
471
+ const result = await this.redis.rpush(key, ...elements);
472
+ await this.executeHook("after-redis-operation", {
473
+ operation: "rpush",
474
+ key,
475
+ elements,
476
+ result
477
+ });
478
+ return result;
479
+ } catch (error) {
480
+ this.logger.log?.(
481
+ "error",
482
+ `Redis RPUSH operation failed for key: ${key}`,
483
+ error
484
+ );
485
+ throw error;
486
+ }
487
+ }
488
+ async lpop(key) {
489
+ await this.executeHook("before-redis-operation", {
490
+ operation: "lpop",
491
+ key
492
+ });
493
+ try {
494
+ const result = await this.redis.lpop(key);
495
+ await this.executeHook("after-redis-operation", {
496
+ operation: "lpop",
497
+ key,
498
+ result
499
+ });
500
+ return result;
501
+ } catch (error) {
502
+ this.logger.log?.(
503
+ "error",
504
+ `Redis LPOP operation failed for key: ${key}`,
505
+ error
506
+ );
507
+ throw error;
508
+ }
509
+ }
510
+ async rpop(key) {
511
+ await this.executeHook("before-redis-operation", {
512
+ operation: "rpop",
513
+ key
514
+ });
515
+ try {
516
+ const result = await this.redis.rpop(key);
517
+ await this.executeHook("after-redis-operation", {
518
+ operation: "rpop",
519
+ key,
520
+ result
521
+ });
522
+ return result;
523
+ } catch (error) {
524
+ this.logger.log?.(
525
+ "error",
526
+ `Redis RPOP operation failed for key: ${key}`,
527
+ error
528
+ );
529
+ throw error;
530
+ }
531
+ }
532
+ async llen(key) {
533
+ await this.executeHook("before-redis-operation", {
534
+ operation: "llen",
535
+ key
536
+ });
537
+ try {
538
+ const result = await this.redis.llen(key);
539
+ await this.executeHook("after-redis-operation", {
540
+ operation: "llen",
541
+ key,
542
+ result
543
+ });
544
+ return result;
545
+ } catch (error) {
546
+ this.logger.log?.(
547
+ "error",
548
+ `Redis LLEN operation failed for key: ${key}`,
549
+ error
550
+ );
551
+ throw error;
552
+ }
553
+ }
554
+ async lrange(key, start, stop) {
555
+ await this.executeHook("before-redis-operation", {
556
+ operation: "lrange",
557
+ key,
558
+ start,
559
+ stop
560
+ });
561
+ try {
562
+ const result = await this.redis.lrange(key, start, stop);
563
+ await this.executeHook("after-redis-operation", {
564
+ operation: "lrange",
565
+ key,
566
+ start,
567
+ stop,
568
+ result
569
+ });
570
+ return result;
571
+ } catch (error) {
572
+ this.logger.log?.(
573
+ "error",
574
+ `Redis LRANGE operation failed for key: ${key}`,
575
+ error
576
+ );
577
+ throw error;
578
+ }
579
+ }
580
+ // Set operations
581
+ async sadd(key, ...members) {
582
+ await this.executeHook("before-redis-operation", {
583
+ operation: "sadd",
584
+ key,
585
+ members
586
+ });
587
+ try {
588
+ const result = await this.redis.sadd(key, ...members);
589
+ await this.executeHook("after-redis-operation", {
590
+ operation: "sadd",
591
+ key,
592
+ members,
593
+ result
594
+ });
595
+ return result;
596
+ } catch (error) {
597
+ this.logger.log?.(
598
+ "error",
599
+ `Redis SADD operation failed for key: ${key}`,
600
+ error
601
+ );
602
+ throw error;
603
+ }
604
+ }
605
+ async srem(key, ...members) {
606
+ await this.executeHook("before-redis-operation", {
607
+ operation: "srem",
608
+ key,
609
+ members
610
+ });
611
+ try {
612
+ const result = await this.redis.srem(key, ...members);
613
+ await this.executeHook("after-redis-operation", {
614
+ operation: "srem",
615
+ key,
616
+ members,
617
+ result
618
+ });
619
+ return result;
620
+ } catch (error) {
621
+ this.logger.log?.(
622
+ "error",
623
+ `Redis SREM operation failed for key: ${key}`,
624
+ error
625
+ );
626
+ throw error;
627
+ }
628
+ }
629
+ async smembers(key) {
630
+ await this.executeHook("before-redis-operation", {
631
+ operation: "smembers",
632
+ key
633
+ });
634
+ try {
635
+ const result = await this.redis.smembers(key);
636
+ await this.executeHook("after-redis-operation", {
637
+ operation: "smembers",
638
+ key,
639
+ result
640
+ });
641
+ return result;
642
+ } catch (error) {
643
+ this.logger.log?.(
644
+ "error",
645
+ `Redis SMEMBERS operation failed for key: ${key}`,
646
+ error
647
+ );
648
+ throw error;
649
+ }
650
+ }
651
+ async sismember(key, member) {
652
+ await this.executeHook("before-redis-operation", {
653
+ operation: "sismember",
654
+ key,
655
+ member
656
+ });
657
+ try {
658
+ const result = await this.redis.sismember(key, member);
659
+ await this.executeHook("after-redis-operation", {
660
+ operation: "sismember",
661
+ key,
662
+ member,
663
+ result
664
+ });
665
+ return result;
666
+ } catch (error) {
667
+ this.logger.log?.(
668
+ "error",
669
+ `Redis SISMEMBER operation failed for key: ${key}`,
670
+ error
671
+ );
672
+ throw error;
673
+ }
674
+ }
675
+ async scard(key) {
676
+ await this.executeHook("before-redis-operation", {
677
+ operation: "scard",
678
+ key
679
+ });
680
+ try {
681
+ const result = await this.redis.scard(key);
682
+ await this.executeHook("after-redis-operation", {
683
+ operation: "scard",
684
+ key,
685
+ result
686
+ });
687
+ return result;
688
+ } catch (error) {
689
+ this.logger.log?.(
690
+ "error",
691
+ `Redis SCARD operation failed for key: ${key}`,
692
+ error
693
+ );
694
+ throw error;
695
+ }
696
+ }
697
+ // Sorted set operations
698
+ async zadd(key, score, member) {
699
+ await this.executeHook("before-redis-operation", {
700
+ operation: "zadd",
701
+ key,
702
+ score,
703
+ member
704
+ });
705
+ try {
706
+ const result = await this.redis.zadd(key, score, member);
707
+ await this.executeHook("after-redis-operation", {
708
+ operation: "zadd",
709
+ key,
710
+ score,
711
+ member,
712
+ result
713
+ });
714
+ return result;
715
+ } catch (error) {
716
+ this.logger.log?.(
717
+ "error",
718
+ `Redis ZADD operation failed for key: ${key}`,
719
+ error
720
+ );
721
+ throw error;
722
+ }
723
+ }
724
+ async zrange(key, start, stop) {
725
+ await this.executeHook("before-redis-operation", {
726
+ operation: "zrange",
727
+ key,
728
+ start,
729
+ stop
730
+ });
731
+ try {
732
+ const result = await this.redis.zrange(key, start, stop);
733
+ await this.executeHook("after-redis-operation", {
734
+ operation: "zrange",
735
+ key,
736
+ start,
737
+ stop,
738
+ result
739
+ });
740
+ return result;
741
+ } catch (error) {
742
+ this.logger.log?.(
743
+ "error",
744
+ `Redis ZRANGE operation failed for key: ${key}`,
745
+ error
746
+ );
747
+ throw error;
748
+ }
749
+ }
750
+ // Utility methods
751
+ getConnectionInfo() {
752
+ const cfg = this.getConfig().config;
753
+ return {
754
+ host: cfg.host,
755
+ port: cfg.port,
756
+ db: cfg.db,
757
+ connected: this.isConnected,
758
+ timestamp: Date.now()
759
+ };
760
+ }
761
+ getStats() {
762
+ return { ...this.stats };
763
+ }
764
+ async ping() {
765
+ return this.run("ping", {}, () => this.redis.ping());
766
+ }
767
+ async flushdb() {
768
+ return this.run("flushdb", {}, () => this.redis.flushdb());
769
+ }
770
+ async flushall() {
771
+ return this.run("flushall", {}, () => this.redis.flushall());
772
+ }
773
+ }
774
+
775
+ exports.RedisPlugin = RedisPlugin;