@hotmeshio/hotmesh 0.6.0 → 0.6.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 (41) hide show
  1. package/build/index.d.ts +3 -1
  2. package/build/index.js +5 -1
  3. package/build/modules/enums.d.ts +11 -0
  4. package/build/modules/enums.js +12 -1
  5. package/build/modules/utils.js +27 -0
  6. package/build/package.json +15 -3
  7. package/build/services/connector/factory.d.ts +1 -1
  8. package/build/services/connector/factory.js +15 -1
  9. package/build/services/connector/providers/ioredis.d.ts +9 -0
  10. package/build/services/connector/providers/ioredis.js +26 -0
  11. package/build/services/connector/providers/redis.d.ts +9 -0
  12. package/build/services/connector/providers/redis.js +38 -0
  13. package/build/services/search/factory.js +8 -0
  14. package/build/services/search/providers/redis/ioredis.d.ts +23 -0
  15. package/build/services/search/providers/redis/ioredis.js +189 -0
  16. package/build/services/search/providers/redis/redis.d.ts +23 -0
  17. package/build/services/search/providers/redis/redis.js +202 -0
  18. package/build/services/store/factory.js +9 -1
  19. package/build/services/store/providers/redis/_base.d.ts +137 -0
  20. package/build/services/store/providers/redis/_base.js +980 -0
  21. package/build/services/store/providers/redis/ioredis.d.ts +20 -0
  22. package/build/services/store/providers/redis/ioredis.js +180 -0
  23. package/build/services/store/providers/redis/redis.d.ts +18 -0
  24. package/build/services/store/providers/redis/redis.js +199 -0
  25. package/build/services/stream/factory.js +17 -1
  26. package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
  27. package/build/services/stream/providers/redis/ioredis.js +272 -0
  28. package/build/services/stream/providers/redis/redis.d.ts +61 -0
  29. package/build/services/stream/providers/redis/redis.js +305 -0
  30. package/build/services/sub/factory.js +8 -0
  31. package/build/services/sub/providers/redis/ioredis.d.ts +20 -0
  32. package/build/services/sub/providers/redis/ioredis.js +150 -0
  33. package/build/services/sub/providers/redis/redis.d.ts +18 -0
  34. package/build/services/sub/providers/redis/redis.js +137 -0
  35. package/build/types/index.d.ts +1 -0
  36. package/build/types/index.js +4 -1
  37. package/build/types/provider.d.ts +1 -1
  38. package/build/types/redis.d.ts +258 -0
  39. package/build/types/redis.js +11 -0
  40. package/index.ts +4 -0
  41. package/package.json +15 -3
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IORedisSubService = void 0;
4
+ const key_1 = require("../../../../modules/key");
5
+ const index_1 = require("../../index");
6
+ class IORedisSubService extends index_1.SubService {
7
+ constructor(eventClient, storeClient) {
8
+ super(eventClient, storeClient);
9
+ this.subscriptions = new Map();
10
+ this.messageHandlerSet = false;
11
+ this.pmessageHandlerSet = false;
12
+ }
13
+ async init(namespace = key_1.HMNS, appId, engineId, logger) {
14
+ this.namespace = namespace;
15
+ this.logger = logger;
16
+ this.appId = appId;
17
+ this.engineId = engineId;
18
+ }
19
+ transact() {
20
+ return this.eventClient.multi();
21
+ }
22
+ mintKey(type, params) {
23
+ if (!this.namespace)
24
+ throw new Error('namespace not set');
25
+ return key_1.KeyService.mintKey(this.namespace, type, params);
26
+ }
27
+ async subscribe(keyType, callback, appId, engineId) {
28
+ const topic = this.mintKey(keyType, { appId, engineId });
29
+ // Add callback to set (supports multiple subscribers per topic)
30
+ let callbacks = this.subscriptions.get(topic);
31
+ const isFirstSubscription = !callbacks;
32
+ if (!callbacks) {
33
+ callbacks = new Set();
34
+ this.subscriptions.set(topic, callbacks);
35
+ }
36
+ callbacks.add(callback);
37
+ this.logger.debug('ioredis-subscribe', {
38
+ topic,
39
+ isFirstSubscription,
40
+ totalCallbacks: callbacks.size,
41
+ messageHandlerSet: this.messageHandlerSet,
42
+ });
43
+ // Set up message handler only once
44
+ if (!this.messageHandlerSet) {
45
+ this.eventClient.on('message', (channel, message) => {
46
+ try {
47
+ const payload = JSON.parse(message);
48
+ const cbs = this.subscriptions.get(channel);
49
+ this.logger.debug('ioredis-message-received', {
50
+ channel,
51
+ callbackCount: cbs?.size || 0,
52
+ payload,
53
+ });
54
+ if (cbs) {
55
+ // Call all callbacks for this channel
56
+ cbs.forEach(cb => {
57
+ try {
58
+ cb(channel, payload);
59
+ }
60
+ catch (err) {
61
+ this.logger.error(`Error in callback for ${channel}`, err);
62
+ }
63
+ });
64
+ }
65
+ }
66
+ catch (e) {
67
+ this.logger.error(`Error parsing message: ${message}`, e);
68
+ }
69
+ });
70
+ this.messageHandlerSet = true;
71
+ }
72
+ await this.eventClient.subscribe(topic, (err) => {
73
+ if (err) {
74
+ this.logger.error(`Error subscribing to: ${topic}`, err);
75
+ }
76
+ });
77
+ }
78
+ async unsubscribe(keyType, appId, engineId) {
79
+ const topic = this.mintKey(keyType, { appId, engineId });
80
+ const callbacks = this.subscriptions.get(topic);
81
+ this.logger.debug('ioredis-unsubscribe', {
82
+ topic,
83
+ hadCallbacks: !!callbacks,
84
+ callbackCount: callbacks?.size || 0,
85
+ });
86
+ // Only unsubscribe from Redis if no more callbacks exist
87
+ if (callbacks && callbacks.size > 0) {
88
+ this.subscriptions.delete(topic);
89
+ await this.eventClient.unsubscribe(topic);
90
+ }
91
+ }
92
+ async psubscribe(keyType, callback, appId, engineId) {
93
+ const topic = this.mintKey(keyType, { appId, engineId });
94
+ // Add callback to set (supports multiple subscribers per topic)
95
+ let callbacks = this.subscriptions.get(topic);
96
+ if (!callbacks) {
97
+ callbacks = new Set();
98
+ this.subscriptions.set(topic, callbacks);
99
+ }
100
+ callbacks.add(callback);
101
+ // Set up pmessage handler only once
102
+ if (!this.pmessageHandlerSet) {
103
+ this.eventClient.on('pmessage', (pattern, channel, message) => {
104
+ try {
105
+ const payload = JSON.parse(message);
106
+ const cbs = this.subscriptions.get(pattern);
107
+ if (cbs) {
108
+ // Call all callbacks for this pattern
109
+ cbs.forEach(cb => {
110
+ try {
111
+ cb(channel, payload);
112
+ }
113
+ catch (err) {
114
+ this.logger.error(`Error in callback for ${pattern}`, err);
115
+ }
116
+ });
117
+ }
118
+ }
119
+ catch (e) {
120
+ this.logger.error(`Error parsing message: ${message}`, e);
121
+ }
122
+ });
123
+ this.pmessageHandlerSet = true;
124
+ }
125
+ await this.eventClient.psubscribe(topic, (err) => {
126
+ if (err) {
127
+ this.logger.error(`Error subscribing to: ${topic}`, err);
128
+ }
129
+ });
130
+ }
131
+ async punsubscribe(keyType, appId, engineId) {
132
+ const topic = this.mintKey(keyType, { appId, engineId });
133
+ const callbacks = this.subscriptions.get(topic);
134
+ // Only unsubscribe from Redis if no more callbacks exist
135
+ if (callbacks && callbacks.size > 0) {
136
+ this.subscriptions.delete(topic);
137
+ await this.eventClient.punsubscribe(topic);
138
+ }
139
+ }
140
+ async publish(keyType, message, appId, engineId) {
141
+ const topic = this.mintKey(keyType, { appId, engineId });
142
+ //NOTE: `storeClient.publish` is used,
143
+ // because a Redis connection with subscriptions
144
+ // may not publish (is read only).
145
+ this.logger.debug('ioredis-publish', { topic, message });
146
+ const status = await this.storeClient.publish(topic, JSON.stringify(message));
147
+ return status === 1;
148
+ }
149
+ }
150
+ exports.IORedisSubService = IORedisSubService;
@@ -0,0 +1,18 @@
1
+ import { KeyStoreParams, KeyType } from '../../../../modules/key';
2
+ import { ILogger } from '../../../logger';
3
+ import { SubService } from '../../index';
4
+ import { RedisRedisClientType as ClientProvider, RedisRedisMultiType as TransactionProvider } from '../../../../types/redis';
5
+ import { SubscriptionCallback } from '../../../../types/quorum';
6
+ declare class RedisSubService extends SubService<ClientProvider> {
7
+ private subscriptions;
8
+ constructor(eventClient: ClientProvider, storeClient: ClientProvider);
9
+ init(namespace: string, appId: string, engineId: string, logger: ILogger): Promise<void>;
10
+ transact(): TransactionProvider;
11
+ mintKey(type: KeyType, params: KeyStoreParams): string;
12
+ subscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
13
+ unsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
14
+ psubscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
15
+ punsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
16
+ publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
17
+ }
18
+ export { RedisSubService };
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisSubService = void 0;
4
+ const key_1 = require("../../../../modules/key");
5
+ const index_1 = require("../../index");
6
+ class RedisSubService extends index_1.SubService {
7
+ constructor(eventClient, storeClient) {
8
+ super(eventClient, storeClient);
9
+ this.subscriptions = new Map();
10
+ }
11
+ async init(namespace = key_1.HMNS, appId, engineId, logger) {
12
+ this.namespace = namespace;
13
+ this.logger = logger;
14
+ this.appId = appId;
15
+ this.engineId = engineId;
16
+ }
17
+ transact() {
18
+ const multi = this.eventClient.multi();
19
+ return multi;
20
+ }
21
+ mintKey(type, params) {
22
+ if (!this.namespace)
23
+ throw new Error('namespace not set');
24
+ return key_1.KeyService.mintKey(this.namespace, type, params);
25
+ }
26
+ async subscribe(keyType, callback, appId, engineId) {
27
+ if (this.eventClient) {
28
+ const topic = this.mintKey(keyType, { appId, engineId });
29
+ // Add callback to set (supports multiple subscribers per topic)
30
+ let callbacks = this.subscriptions.get(topic);
31
+ const isFirstSubscription = !callbacks;
32
+ if (!callbacks) {
33
+ callbacks = new Set();
34
+ this.subscriptions.set(topic, callbacks);
35
+ }
36
+ callbacks.add(callback);
37
+ this.logger.debug('redis-subscribe', {
38
+ topic,
39
+ isFirstSubscription,
40
+ totalCallbacks: callbacks.size,
41
+ });
42
+ // Only subscribe to Redis once per topic
43
+ if (isFirstSubscription) {
44
+ await this.eventClient.subscribe(topic, (message) => {
45
+ try {
46
+ const payload = JSON.parse(message);
47
+ const cbs = this.subscriptions.get(topic);
48
+ this.logger.debug('redis-message-received', {
49
+ topic,
50
+ callbackCount: cbs?.size || 0,
51
+ payload,
52
+ });
53
+ if (cbs) {
54
+ // Call all callbacks for this topic
55
+ cbs.forEach(cb => {
56
+ try {
57
+ cb(topic, payload);
58
+ }
59
+ catch (err) {
60
+ this.logger.error(`Error in callback for ${topic}`, err);
61
+ }
62
+ });
63
+ }
64
+ }
65
+ catch (e) {
66
+ this.logger.error(`Error parsing message: ${message}`, e);
67
+ }
68
+ });
69
+ }
70
+ }
71
+ }
72
+ async unsubscribe(keyType, appId, engineId) {
73
+ const topic = this.mintKey(keyType, { appId, engineId });
74
+ const callbacks = this.subscriptions.get(topic);
75
+ this.logger.debug('redis-unsubscribe', {
76
+ topic,
77
+ hadCallbacks: !!callbacks,
78
+ callbackCount: callbacks?.size || 0,
79
+ });
80
+ // Only unsubscribe from Redis if no more callbacks exist
81
+ if (callbacks && callbacks.size > 0) {
82
+ this.subscriptions.delete(topic);
83
+ await this.eventClient.unsubscribe(topic);
84
+ }
85
+ }
86
+ async psubscribe(keyType, callback, appId, engineId) {
87
+ if (this.eventClient) {
88
+ const topic = this.mintKey(keyType, { appId, engineId });
89
+ // Add callback to set (supports multiple subscribers per topic)
90
+ let callbacks = this.subscriptions.get(topic);
91
+ if (!callbacks) {
92
+ callbacks = new Set();
93
+ this.subscriptions.set(topic, callbacks);
94
+ }
95
+ callbacks.add(callback);
96
+ await this.eventClient.pSubscribe(topic, (message, channel) => {
97
+ try {
98
+ const payload = JSON.parse(message);
99
+ const cbs = this.subscriptions.get(topic);
100
+ if (cbs) {
101
+ // Call all callbacks for this topic
102
+ cbs.forEach(cb => {
103
+ try {
104
+ cb(channel, payload);
105
+ }
106
+ catch (err) {
107
+ this.logger.error(`Error in callback for ${topic}`, err);
108
+ }
109
+ });
110
+ }
111
+ }
112
+ catch (e) {
113
+ this.logger.error(`Error parsing message: ${message}`, e);
114
+ }
115
+ });
116
+ }
117
+ }
118
+ async punsubscribe(keyType, appId, engineId) {
119
+ const topic = this.mintKey(keyType, { appId, engineId });
120
+ const callbacks = this.subscriptions.get(topic);
121
+ // Only unsubscribe from Redis if no more callbacks exist
122
+ if (callbacks && callbacks.size > 0) {
123
+ this.subscriptions.delete(topic);
124
+ await this.eventClient.pUnsubscribe(topic);
125
+ }
126
+ }
127
+ async publish(keyType, message, appId, engineId) {
128
+ const topic = this.mintKey(keyType, { appId, engineId });
129
+ //NOTE: `storeClient.publish` is used,
130
+ // because a Redis connection with subscriptions
131
+ // may not publish (is read only).
132
+ this.logger.debug('redis-publish', { topic, message });
133
+ const status = await this.storeClient.publish(topic, JSON.stringify(message));
134
+ return status > 0;
135
+ }
136
+ }
137
+ exports.RedisSubService = RedisSubService;
@@ -17,6 +17,7 @@ export { MeshCallConnectParams, MeshCallExecParams, MeshCallCronParams, MeshCall
17
17
  export { PostgresClassType, PostgresClientOptions, PostgresClientType, PostgresConsumerGroup, PostgresPendingMessage, PostgresPoolClientType, PostgresQueryConfigType, PostgresQueryResultType, PostgresStreamMessage, PostgresStreamOptions, PostgresTransaction, } from './postgres';
18
18
  export { ActivateMessage, CronMessage, JobMessage, JobMessageCallback, PingMessage, PongMessage, QuorumMessage, QuorumMessageCallback, QuorumProfile, RollCallMessage, RollCallOptions, SubscriptionCallback, SubscriptionOptions, SystemHealth, ThrottleMessage, ThrottleOptions, WorkMessage, } from './quorum';
19
19
  export { NatsAckPolicy, NatsAckPolicyExplicitType, NatsClassType, NatsClientType, NatsClientOptions, NatsConsumerConfigType, NatsJetStreamManager, NatsConnection, NatsJetStreamType, NatsConnectionOptions, NatsConsumerConfig, NatsConsumerInfo, NatsConsumerManager, NatsDeliveryInfo, NatsJetStreamOptions, NatsError, NatsErrorType, NatsJetStreamClient, NatsJsMsg, NatsMessageType, NatsMsgExpect, NatsPubAck, NatsPubAckType, NatsPublishOptions, NatsRetentionPolicy, NatsRetentionPolicyWorkqueueType, NatsSequenceInfo, NatsStorageMemoryType, NatsStorageType, NatsStreamConfig, NatsStreamInfo, NatsStreamManager, NatsStreamConfigType, NatsStreamInfoType, NatsStreamOptions, NatsStreamState, NatsTransaction, } from './nats';
20
+ export { RedisClass, RedisRedisClientType, RedisRedisClientOptions, RedisRedisClassType, IORedisClientType, RedisClient, RedisMulti, RedisRedisMultiType, IORedisClientOptions, IORedisClassType, IORedisMultiType, RedisOptions, isRedisClient, isIORedisClient, } from './redis';
20
21
  export { JSONSchema, StringAnyType, StringScalarType, StringStringType, SymbolMap, SymbolMaps, SymbolRanges, Symbols, SymbolSets, } from './serializer';
21
22
  export { AggregatedData, CountByFacet, GetStatsOptions, IdsData, Measure, MeasureIds, MetricTypes, StatType, StatsType, IdsResponse, JobStats, JobStatsInput, JobStatsRange, StatsResponse, Segment, TimeSegment, } from './stats';
22
23
  export { ReclaimedMessageType, RouterConfig, StreamCode, StreamConfig, StreamData, StreamDataType, StreamError, StreamDataResponse, StreamMessage, StreamMessageMetadata, StreamProviderType, StreamRetryPolicy, StreamRole, StreamStats, StreamStatus, } from './stream';
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValueType = exports.trace = exports.SpanKind = exports.SpanStatusCode = exports.propagation = exports.metrics = exports.context = exports.StreamStatus = exports.StreamRole = exports.StreamDataType = exports.KeyType = exports.HookGate = exports.CollationFaultType = void 0;
3
+ exports.ValueType = exports.trace = exports.SpanKind = exports.SpanStatusCode = exports.propagation = exports.metrics = exports.context = exports.StreamStatus = exports.StreamRole = exports.StreamDataType = exports.isIORedisClient = exports.isRedisClient = exports.KeyType = exports.HookGate = exports.CollationFaultType = void 0;
4
4
  var collator_1 = require("./collator");
5
5
  Object.defineProperty(exports, "CollationFaultType", { enumerable: true, get: function () { return collator_1.CollationFaultType; } });
6
6
  var hook_1 = require("./hook");
7
7
  Object.defineProperty(exports, "HookGate", { enumerable: true, get: function () { return hook_1.HookGate; } });
8
8
  var hotmesh_1 = require("./hotmesh");
9
9
  Object.defineProperty(exports, "KeyType", { enumerable: true, get: function () { return hotmesh_1.KeyType; } });
10
+ var redis_1 = require("./redis");
11
+ Object.defineProperty(exports, "isRedisClient", { enumerable: true, get: function () { return redis_1.isRedisClient; } });
12
+ Object.defineProperty(exports, "isIORedisClient", { enumerable: true, get: function () { return redis_1.isIORedisClient; } });
10
13
  var stream_1 = require("./stream");
11
14
  Object.defineProperty(exports, "StreamDataType", { enumerable: true, get: function () { return stream_1.StreamDataType; } });
12
15
  Object.defineProperty(exports, "StreamRole", { enumerable: true, get: function () { return stream_1.StreamRole; } });
@@ -12,7 +12,7 @@ export interface ProviderClass {
12
12
  export interface ProviderOptions {
13
13
  [key: string]: any;
14
14
  }
15
- export type Providers = 'nats' | 'postgres';
15
+ export type Providers = 'nats' | 'postgres' | 'redis' | 'ioredis';
16
16
  /**
17
17
  * A provider transaction is a set of operations that are executed
18
18
  * atomically by the provider. The transaction is created by calling
@@ -0,0 +1,258 @@
1
+ /// <reference types="node" />
2
+ import { ProviderClient, ProviderConfig, ProviderTransaction } from './provider';
3
+ import { StringStringType } from './serializer';
4
+ import { ReclaimedMessageType } from './stream';
5
+ /**
6
+ * Redis types
7
+ */
8
+ interface ConnectionOptions {
9
+ host?: string;
10
+ port?: number;
11
+ path?: string;
12
+ socket?: any;
13
+ NPNProtocols?: string[] | Buffer[];
14
+ ALPNProtocols?: string[] | Buffer[];
15
+ servername?: string;
16
+ checkServerIdentity?: (servername: string, cert: Buffer) => Error | undefined;
17
+ session?: Buffer;
18
+ minDHSize?: number;
19
+ secureContext?: any;
20
+ secureProtocol?: string;
21
+ ciphers?: string;
22
+ honorCipherOrder?: boolean;
23
+ requestCert?: boolean;
24
+ rejectUnauthorized?: boolean;
25
+ maxVersion?: 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1';
26
+ minVersion?: 'TLSv1.3' | 'TLSv1.2' | 'TLSv1.1' | 'TLSv1';
27
+ }
28
+ interface RedisRedisClientOptions {
29
+ url?: string;
30
+ socket?: {
31
+ host?: string;
32
+ port?: number;
33
+ tls?: boolean;
34
+ servername?: string;
35
+ };
36
+ username?: string;
37
+ password?: string;
38
+ database?: number;
39
+ name?: string;
40
+ readonly?: boolean;
41
+ legacyMode?: boolean;
42
+ commandsQueueMaxLength?: number;
43
+ disableOfflineQueue?: boolean;
44
+ connectTimeout?: number;
45
+ autoResubscribe?: boolean;
46
+ autoResendUnfulfilledCommands?: boolean;
47
+ lazyConnect?: boolean;
48
+ tls?: boolean | ConnectionOptions;
49
+ enableReadyCheck?: boolean;
50
+ keepAlive?: number;
51
+ family?: 'IPv4' | 'IPv6';
52
+ keyPrefix?: string;
53
+ retry?: {
54
+ maxReconnectionAttempts?: number;
55
+ initialReconnectionDelay?: number;
56
+ reconnectionBackoffFactor?: number;
57
+ totalReconnectionTimeout?: number;
58
+ maxRetryCount?: number;
59
+ };
60
+ stringNumbers?: boolean;
61
+ }
62
+ interface RedisRedisMultiType extends ProviderTransaction {
63
+ sendCommand(command: string, ...args: string[]): Promise<any>;
64
+ exec: () => Promise<unknown[]>;
65
+ DEL(key: string): this;
66
+ EXISTS(key: string): this;
67
+ EXPIRE(key: string, seconds: number): this;
68
+ HDEL(key: string, fields: string[] | string): this;
69
+ HGET(key: string, itemId: string): this;
70
+ HGETALL(key: string): this;
71
+ HINCRBYFLOAT(key: string, itemId: string, value: number): this;
72
+ HMPUSH(key: string, values: Record<string, string>): this;
73
+ RPUSH(key: string, items: string[]): this;
74
+ HMGET(key: string, itemIds: string[]): this;
75
+ HSET(key: string, values: Record<string, string>): this;
76
+ LPUSH(key: string, items: string[]): this;
77
+ LRANGE(key: string, start: number, end: number): this;
78
+ RPUSH(key: string, items: string[]): this;
79
+ SET(key: string, value: string): this;
80
+ XADD(key: string, id: string, fields: any): this;
81
+ XACK(key: string, group: string, id: string): this;
82
+ XACK(key: string, group: string, ...ids: string[]): this;
83
+ XDEL(key: string, id: string): this;
84
+ XDEL(key: string, ...ids: string[]): this;
85
+ XCLAIM(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): this;
86
+ XLEN(key: string): this;
87
+ XGROUP(command: 'CREATE' | string, key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): this;
88
+ XPENDING(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): this;
89
+ ZADD(key: string, values: {
90
+ score: string;
91
+ value: string;
92
+ }, opts?: {
93
+ NX: boolean;
94
+ }): this;
95
+ ZRANGE_WITHSCORES(key: string, start: number, end: number): this;
96
+ ZRANK(key: string, member: string): this;
97
+ ZSCORE(key: string, value: string): this;
98
+ }
99
+ interface RedisRedisClientType extends ProviderClient {
100
+ multi(): Partial<RedisRedisMultiType>;
101
+ connect(): Promise<void>;
102
+ sendCommand(args: any[]): Promise<any>;
103
+ exec(): Promise<unknown[]>;
104
+ flushDb(): Promise<string>;
105
+ quit(): Promise<string>;
106
+ disconnect(): void;
107
+ duplicate(): RedisRedisClientType;
108
+ on(event: string, callback: (...args: any[]) => void): void;
109
+ publish(channel: string, message: string): Promise<number>;
110
+ pSubscribe(pattern: string, callback: (channel: string, message: string) => void): Promise<void>;
111
+ pUnsubscribe(pattern: string): Promise<void>;
112
+ subscribe(channel: string, callback: (channel: string, message: string) => void): Promise<void>;
113
+ unsubscribe(channel: string): Promise<void>;
114
+ punsubscribe(channel: string): void;
115
+ get(key: string): Promise<string | null>;
116
+ set(key: string, value: string): Promise<string>;
117
+ DEL(key: string): Promise<number>;
118
+ EXISTS(key: string): Promise<number>;
119
+ HDEL(key: string, fields: string[] | string): Promise<number>;
120
+ HGET(key: string, itemId: string): Promise<string | null>;
121
+ HGETALL(key: string): Promise<StringStringType>;
122
+ HINCRBYFLOAT(key: string, itemId: string, value: number): Promise<number>;
123
+ HMGET(key: string, itemIds: string[]): Promise<string[]>;
124
+ HSET(key: string, values: Record<string, string>): Promise<number>;
125
+ LPUSH(key: string, items: string[]): Promise<number>;
126
+ LRANGE(key: string, start: number, end: number): Promise<string[]>;
127
+ RPUSH(key: string, items: string[]): Promise<number>;
128
+ SET(key: string, value: string): Promise<string>;
129
+ XADD(key: string, id: string, fields: any): Promise<string>;
130
+ XACK(key: string, group: string, ...ids: string[]): Promise<number>;
131
+ XACK(key: string, group: string, id: string): Promise<number>;
132
+ XCLAIM(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
133
+ XDEL(key: string, id: string): Promise<number>;
134
+ XDEL(key: string, ...ids: string[]): Promise<number>;
135
+ xGroupDestroy(key: string, groupName: string): Promise<boolean>;
136
+ XINFO(command: 'GROUPS' | string, key: string): Promise<unknown>;
137
+ XINFO_GROUPS(key: string): Promise<unknown>;
138
+ XLEN(key: string): Promise<number>;
139
+ XPENDING(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): this;
140
+ ZADD(key: string, values: {
141
+ score: string;
142
+ value: string;
143
+ }, opts?: {
144
+ NX: boolean;
145
+ }): Promise<number>;
146
+ ZRANGE_WITHSCORES(key: string, start: number, end: number): Promise<{
147
+ score: number;
148
+ value: string;
149
+ }>;
150
+ ZRANK(key: string, member: string): Promise<number>;
151
+ ZSCORE(key: string, value: string): Promise<number>;
152
+ }
153
+ interface RedisRedisClassType {
154
+ createClient(options: RedisRedisClientOptions): Partial<RedisRedisClientType>;
155
+ }
156
+ /**
157
+ * IORedis types
158
+ */
159
+ interface IORedisClientOptions {
160
+ port?: number;
161
+ host?: string;
162
+ family?: 'IPv4' | 'IPv6';
163
+ path?: string;
164
+ keepAlive?: number;
165
+ noDelay?: boolean;
166
+ connectionName?: string;
167
+ db?: number;
168
+ password?: string;
169
+ username?: string;
170
+ sentinels?: Array<{
171
+ host: string;
172
+ port: number;
173
+ }>;
174
+ name?: string;
175
+ readOnly?: boolean;
176
+ keyPrefix?: string;
177
+ reconnectOnError?: (err: Error) => boolean;
178
+ }
179
+ interface IORedisClient extends ProviderClient {
180
+ multi(): IORedisMultiType;
181
+ exec(): Promise<unknown[]>;
182
+ sendCommand(args: any[]): Promise<any>;
183
+ call(command: string, ...args: any[]): Promise<any>;
184
+ quit(): Promise<string>;
185
+ flushdb(): Promise<string>;
186
+ publish(channel: string, message: string): Promise<number>;
187
+ psubscribe(pattern: string, callback: (channel: string, message: string) => void): Promise<void>;
188
+ punsubscribe(pattern: string): Promise<number>;
189
+ subscribe(channel: string, callback: (channel: string, message: string) => void): Promise<void>;
190
+ unsubscribe(channel: string): Promise<number>;
191
+ punsubscribe(channel: string): Promise<number>;
192
+ xadd(key: string, id: string, fields: any, message?: string): Promise<string>;
193
+ xack(key: string, group: string, id: string): Promise<number>;
194
+ xack(key: string, group: string, ...ids: string[]): Promise<number>;
195
+ xdel(key: string, id: string): Promise<number>;
196
+ xdel(key: string, ...ids: string[]): Promise<number>;
197
+ xlen(key: string): Promise<number>;
198
+ xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]>;
199
+ xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
200
+ xinfo(command: 'GROUPS' | string, key: string): Promise<unknown>;
201
+ xrange(key: string, start: string, end: string): Promise<string[][]>;
202
+ xreadgroup(command: 'GROUP', groupName: string, consumerName: string, blockOption: string, blockTime: number, streamsOption: string, streamName: string, key: string): Promise<string[][]>;
203
+ del(key: string): Promise<number>;
204
+ exists(key: string): Promise<number>;
205
+ get(key: string): Promise<string | null>;
206
+ hdel(key: string, ...fields: string[]): Promise<number>;
207
+ hget(key: string, itemId: string): Promise<string | null>;
208
+ hgetall(key: string): Promise<StringStringType>;
209
+ hincrbyfloat(key: string, itemId: string, value: number): Promise<number>;
210
+ hmget(key: string, itemIds: string[]): Promise<string[]>;
211
+ hset(key: string, values: Record<string, string>): Promise<number>;
212
+ lpush(key: string, ...args: string[]): Promise<number>;
213
+ lrange(key: string, start: number, end: number): Promise<string[]>;
214
+ on(event: string, callback: (...args: any[]) => void): void;
215
+ rpush(key: string, ...args: string[]): Promise<number>;
216
+ set(key: string, value: string): Promise<string>;
217
+ zadd(...args: Array<string | number>): Promise<number>;
218
+ zrange(key: string, start: number, end: number, withScores?: 'WITHSCORES'): Promise<string[]>;
219
+ zrank(key: string, member: string): Promise<number>;
220
+ zscore(key: string, value: string): Promise<number>;
221
+ xgroup(command: 'CREATE' | 'DESTROY' | string, key: string, groupName: string, id?: string, mkStream?: 'MKSTREAM'): Promise<string | number>;
222
+ }
223
+ type IORedisClassType = new (options: IORedisClientOptions, ...args: any[]) => IORedisClient;
224
+ interface IORedisMultiType extends ProviderTransaction {
225
+ xadd(key: string, id: string, fields: any, message?: string): this;
226
+ xack(key: string, group: string, id: string): this;
227
+ xack(key: string, group: string, ...ids: string[]): this;
228
+ xdel(key: string, id: string): this;
229
+ xdel(key: string, ...ids: string[]): this;
230
+ xlen(key: string): this;
231
+ xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): this;
232
+ xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): this;
233
+ del(key: string): this;
234
+ expire(key: string, seconds: number): this;
235
+ hdel(key: string, itemId: string): this;
236
+ hget(key: string, itemId: string): this;
237
+ hgetall(key: string): this;
238
+ hincrbyfloat(key: string, itemId: string, value: number): this;
239
+ hmget(key: string, itemIds: string[]): this;
240
+ hset(key: string, values: Record<string, string>): this;
241
+ lrange(key: string, start: number, end: number): this;
242
+ rpush(key: string, value: string): this;
243
+ zadd(...args: Array<string | number>): this;
244
+ xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): this;
245
+ sendCommand(command: string[]): Promise<any>;
246
+ exec: () => Promise<unknown[]>;
247
+ }
248
+ type RedisClass = RedisRedisClassType | IORedisClassType;
249
+ type RedisClient = RedisRedisClientType | IORedisClient;
250
+ type RedisOptions = RedisRedisClientOptions | IORedisClientOptions;
251
+ type RedisMulti = RedisRedisMultiType | IORedisMultiType;
252
+ declare function isRedisClient(client: RedisClient): client is RedisRedisClientType;
253
+ declare function isIORedisClient(client: RedisClient): client is IORedisClient;
254
+ interface RedisConfig extends ProviderConfig {
255
+ class: Partial<RedisClass>;
256
+ options: Partial<RedisOptions>;
257
+ }
258
+ export { RedisClass, RedisConfig, RedisRedisClientType, RedisRedisClientOptions, RedisRedisClassType, IORedisClient as IORedisClientType, RedisClient, RedisMulti, RedisRedisMultiType, IORedisClientOptions, IORedisClassType, IORedisMultiType, RedisOptions, isRedisClient, isIORedisClient, };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isIORedisClient = exports.isRedisClient = void 0;
4
+ function isRedisClient(client) {
5
+ return 'sendCommand' in client;
6
+ }
7
+ exports.isRedisClient = isRedisClient;
8
+ function isIORedisClient(client) {
9
+ return 'pipeline' in client;
10
+ }
11
+ exports.isIORedisClient = isIORedisClient;
package/index.ts CHANGED
@@ -16,13 +16,17 @@ import * as Enums from './modules/enums';
16
16
  import * as KeyStore from './modules/key';
17
17
  import { ConnectorService as Connector } from './services/connector/factory';
18
18
  import { PostgresConnection as ConnectorPostgres } from './services/connector/providers/postgres';
19
+ import { RedisConnection as ConnectorIORedis } from './services/connector/providers/ioredis';
20
+ import { RedisConnection as ConnectorRedis } from './services/connector/providers/redis';
19
21
  import { NatsConnection as ConnectorNATS } from './services/connector/providers/nats';
20
22
 
21
23
  export {
22
24
  //Provider Connectors
23
25
  Connector, //factory
26
+ ConnectorIORedis,
24
27
  ConnectorNATS,
25
28
  ConnectorPostgres,
29
+ ConnectorRedis,
26
30
 
27
31
  //Top-level Modules
28
32
  HotMesh,