@hotmeshio/hotmesh 0.0.55 → 0.0.56

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 (181) hide show
  1. package/build/modules/enums.js +1 -10
  2. package/build/modules/key.d.ts +0 -38
  3. package/build/modules/key.js +4 -46
  4. package/build/modules/utils.d.ts +0 -8
  5. package/build/modules/utils.js +0 -14
  6. package/build/package.json +11 -4
  7. package/build/services/activities/activity.d.ts +0 -28
  8. package/build/services/activities/activity.js +1 -46
  9. package/build/services/activities/await.js +0 -4
  10. package/build/services/activities/cycle.d.ts +0 -7
  11. package/build/services/activities/cycle.js +1 -16
  12. package/build/services/activities/hook.d.ts +0 -6
  13. package/build/services/activities/hook.js +2 -12
  14. package/build/services/activities/interrupt.js +0 -8
  15. package/build/services/activities/signal.d.ts +0 -6
  16. package/build/services/activities/signal.js +0 -15
  17. package/build/services/activities/trigger.d.ts +0 -4
  18. package/build/services/activities/trigger.js +1 -7
  19. package/build/services/activities/worker.js +0 -4
  20. package/build/services/collator/index.d.ts +0 -70
  21. package/build/services/collator/index.js +1 -91
  22. package/build/services/compiler/deployer.js +6 -38
  23. package/build/services/compiler/index.d.ts +0 -15
  24. package/build/services/compiler/index.js +0 -20
  25. package/build/services/compiler/validator.d.ts +0 -3
  26. package/build/services/compiler/validator.js +0 -25
  27. package/build/services/connector/clients/ioredis.d.ts +2 -2
  28. package/build/services/connector/clients/ioredis.js +0 -2
  29. package/build/services/connector/clients/redis.d.ts +4 -4
  30. package/build/services/connector/clients/redis.js +1 -3
  31. package/build/services/connector/index.d.ts +1 -1
  32. package/build/services/connector/index.js +0 -2
  33. package/build/services/durable/client.d.ts +1 -26
  34. package/build/services/durable/client.js +0 -56
  35. package/build/services/durable/exporter.d.ts +0 -22
  36. package/build/services/durable/exporter.js +1 -30
  37. package/build/services/durable/handle.d.ts +0 -36
  38. package/build/services/durable/handle.js +0 -46
  39. package/build/services/durable/index.d.ts +0 -4
  40. package/build/services/durable/index.js +0 -4
  41. package/build/services/durable/schemas/factory.d.ts +0 -29
  42. package/build/services/durable/schemas/factory.js +0 -29
  43. package/build/services/durable/search.d.ts +1 -36
  44. package/build/services/durable/search.js +57 -56
  45. package/build/services/durable/worker.js +2 -22
  46. package/build/services/durable/workflow.d.ts +0 -114
  47. package/build/services/durable/workflow.js +1 -141
  48. package/build/services/engine/index.d.ts +1 -6
  49. package/build/services/engine/index.js +1 -43
  50. package/build/services/exporter/index.d.ts +0 -27
  51. package/build/services/exporter/index.js +0 -33
  52. package/build/services/hotmesh/index.d.ts +2 -2
  53. package/build/services/hotmesh/index.js +1 -9
  54. package/build/services/logger/index.js +0 -2
  55. package/build/services/mapper/index.d.ts +0 -14
  56. package/build/services/mapper/index.js +0 -14
  57. package/build/services/pipe/functions/date.d.ts +0 -7
  58. package/build/services/pipe/functions/date.js +0 -7
  59. package/build/services/pipe/functions/math.js +0 -2
  60. package/build/services/pipe/index.d.ts +0 -15
  61. package/build/services/pipe/index.js +2 -23
  62. package/build/services/quorum/index.d.ts +0 -7
  63. package/build/services/quorum/index.js +0 -21
  64. package/build/services/reporter/index.d.ts +0 -5
  65. package/build/services/reporter/index.js +0 -9
  66. package/build/services/router/index.d.ts +0 -9
  67. package/build/services/router/index.js +2 -38
  68. package/build/services/serializer/index.js +7 -26
  69. package/build/services/store/cache.d.ts +0 -18
  70. package/build/services/store/cache.js +0 -18
  71. package/build/services/store/clients/ioredis.d.ts +1 -1
  72. package/build/services/store/clients/ioredis.js +0 -1
  73. package/build/services/store/clients/redis.d.ts +1 -1
  74. package/build/services/store/index.d.ts +0 -55
  75. package/build/services/store/index.js +5 -81
  76. package/build/services/stream/clients/ioredis.d.ts +1 -1
  77. package/build/services/stream/clients/ioredis.js +1 -4
  78. package/build/services/stream/clients/redis.d.ts +1 -1
  79. package/build/services/sub/clients/ioredis.d.ts +1 -1
  80. package/build/services/sub/clients/redis.d.ts +1 -1
  81. package/build/services/task/index.d.ts +0 -9
  82. package/build/services/task/index.js +0 -31
  83. package/build/services/telemetry/index.d.ts +0 -7
  84. package/build/services/telemetry/index.js +1 -13
  85. package/build/services/worker/index.d.ts +0 -4
  86. package/build/services/worker/index.js +2 -6
  87. package/build/types/activity.d.ts +0 -81
  88. package/build/types/durable.d.ts +25 -177
  89. package/build/types/exporter.d.ts +0 -13
  90. package/build/types/hotmesh.d.ts +4 -16
  91. package/build/types/hotmesh.js +0 -3
  92. package/build/types/index.d.ts +4 -6
  93. package/build/types/index.js +4 -3
  94. package/build/types/job.d.ts +1 -86
  95. package/build/types/pipe.d.ts +0 -65
  96. package/build/types/quorum.d.ts +15 -10
  97. package/build/types/redis.d.ts +225 -7
  98. package/build/types/redis.js +9 -0
  99. package/build/types/stream.d.ts +0 -58
  100. package/build/types/stream.js +0 -4
  101. package/package.json +11 -4
  102. package/types/durable.ts +121 -3
  103. package/types/hotmesh.ts +3 -6
  104. package/types/index.ts +23 -10
  105. package/types/job.ts +1 -1
  106. package/types/quorum.ts +22 -0
  107. package/types/redis.ts +267 -18
  108. package/build/types/ioredisclient.d.ts +0 -5
  109. package/build/types/ioredisclient.js +0 -5
  110. package/build/types/redisclient.d.ts +0 -26
  111. package/build/types/redisclient.js +0 -2
  112. package/modules/enums.ts +0 -62
  113. package/modules/errors.ts +0 -280
  114. package/modules/key.ts +0 -101
  115. package/modules/storage.ts +0 -3
  116. package/modules/utils.ts +0 -242
  117. package/services/activities/activity.ts +0 -589
  118. package/services/activities/await.ts +0 -113
  119. package/services/activities/cycle.ts +0 -115
  120. package/services/activities/hook.ts +0 -197
  121. package/services/activities/index.ts +0 -19
  122. package/services/activities/interrupt.ts +0 -172
  123. package/services/activities/signal.ts +0 -148
  124. package/services/activities/trigger.ts +0 -295
  125. package/services/activities/worker.ts +0 -107
  126. package/services/collator/README.md +0 -102
  127. package/services/collator/index.ts +0 -291
  128. package/services/compiler/deployer.ts +0 -504
  129. package/services/compiler/index.ts +0 -98
  130. package/services/compiler/validator.ts +0 -158
  131. package/services/connector/clients/ioredis.ts +0 -57
  132. package/services/connector/clients/redis.ts +0 -72
  133. package/services/connector/index.ts +0 -42
  134. package/services/durable/client.ts +0 -266
  135. package/services/durable/connection.ts +0 -10
  136. package/services/durable/exporter.ts +0 -232
  137. package/services/durable/handle.ts +0 -160
  138. package/services/durable/index.ts +0 -27
  139. package/services/durable/schemas/factory.ts +0 -2358
  140. package/services/durable/search.ts +0 -196
  141. package/services/durable/worker.ts +0 -401
  142. package/services/durable/workflow.ts +0 -557
  143. package/services/engine/index.ts +0 -761
  144. package/services/exporter/index.ts +0 -146
  145. package/services/hotmesh/index.ts +0 -237
  146. package/services/logger/index.ts +0 -79
  147. package/services/mapper/index.ts +0 -89
  148. package/services/pipe/functions/array.ts +0 -78
  149. package/services/pipe/functions/bitwise.ts +0 -27
  150. package/services/pipe/functions/conditional.ts +0 -35
  151. package/services/pipe/functions/date.ts +0 -220
  152. package/services/pipe/functions/index.ts +0 -27
  153. package/services/pipe/functions/json.ts +0 -11
  154. package/services/pipe/functions/logical.ts +0 -11
  155. package/services/pipe/functions/math.ts +0 -217
  156. package/services/pipe/functions/number.ts +0 -75
  157. package/services/pipe/functions/object.ts +0 -98
  158. package/services/pipe/functions/string.ts +0 -86
  159. package/services/pipe/functions/symbol.ts +0 -39
  160. package/services/pipe/functions/unary.ts +0 -19
  161. package/services/pipe/index.ts +0 -216
  162. package/services/quorum/index.ts +0 -319
  163. package/services/reporter/index.ts +0 -387
  164. package/services/router/index.ts +0 -426
  165. package/services/serializer/README.md +0 -10
  166. package/services/serializer/index.ts +0 -285
  167. package/services/store/cache.ts +0 -172
  168. package/services/store/clients/ioredis.ts +0 -145
  169. package/services/store/clients/redis.ts +0 -191
  170. package/services/store/index.ts +0 -1091
  171. package/services/stream/clients/ioredis.ts +0 -157
  172. package/services/stream/clients/redis.ts +0 -158
  173. package/services/stream/index.ts +0 -58
  174. package/services/sub/clients/ioredis.ts +0 -83
  175. package/services/sub/clients/redis.ts +0 -74
  176. package/services/sub/index.ts +0 -25
  177. package/services/task/index.ts +0 -250
  178. package/services/telemetry/index.ts +0 -273
  179. package/services/worker/index.ts +0 -248
  180. package/types/ioredisclient.ts +0 -10
  181. package/types/redisclient.ts +0 -30
@@ -1,157 +0,0 @@
1
- import { KeyService, KeyStoreParams, KeyType, HMNS } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { StreamService } from '../index';
4
- import { RedisClientType, RedisMultiType } from '../../../types/ioredisclient';
5
- import { ReclaimedMessageType } from '../../../types/stream';
6
-
7
- class IORedisStreamService extends StreamService<RedisClientType, RedisMultiType> {
8
- redisClient: RedisClientType;
9
- namespace: string;
10
- logger: ILogger;
11
- appId: string;
12
-
13
- constructor(redisClient: RedisClientType) {
14
- super(redisClient);
15
- }
16
-
17
- async init(namespace = HMNS, appId: string, logger: ILogger): Promise<void> {
18
- this.namespace = namespace;
19
- this.logger = logger;
20
- this.appId = appId;
21
- }
22
-
23
- getMulti(): RedisMultiType {
24
- return this.redisClient.multi();
25
- }
26
-
27
- mintKey(type: KeyType, params: KeyStoreParams): string {
28
- if (!this.namespace) throw new Error('namespace not set');
29
- return KeyService.mintKey(this.namespace, type, params);
30
- }
31
-
32
- async xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean> {
33
- if (mkStream === 'MKSTREAM') {
34
- try {
35
- return (await this.redisClient.xgroup(command, key, groupName, id, mkStream)) === 'OK';
36
- } catch (error) {
37
- this.logger.info(`Consumer group not created with MKSTREAM for key: ${key} and group: ${groupName}`);
38
- throw error;
39
- }
40
- } else {
41
- try {
42
- return (await this.redisClient.xgroup(command, key, groupName, id)) === 'OK';
43
- } catch (error) {
44
- this.logger.info(`Consumer group not created for key: ${key} and group: ${groupName}`);
45
- throw error;
46
- }
47
- }
48
- }
49
-
50
- async xadd(key: string, id: string, messageId: string, messageValue: string, multi?: RedisMultiType): Promise<string | RedisMultiType> {
51
- try {
52
- return await (multi || this.redisClient).xadd(key, id, messageId, messageValue);
53
- } catch (error) {
54
- this.logger.error(`Error publishing 'xadd'; key: ${key}`, { ...error });
55
- throw error;
56
- }
57
- }
58
-
59
- async xreadgroup(
60
- command: 'GROUP',
61
- groupName: string,
62
- consumerName: string,
63
- blockOption: 'BLOCK'|'COUNT',
64
- blockTime: number|string,
65
- streamsOption: 'STREAMS',
66
- streamName: string,
67
- id: string
68
- ): Promise<string[][][] | null | unknown[]> {
69
- try {
70
- //@ts-ignore
71
- return await this.redisClient.xreadgroup(
72
- command,
73
- groupName,
74
- consumerName,
75
- // @ts-ignore
76
- blockOption,
77
- blockTime,
78
- streamsOption,
79
- streamName,
80
- id
81
- );
82
- } catch (error) {
83
- this.logger.error(`Error reading stream data [Stream ${streamName}] [Group ${groupName}]`, { ...error });
84
- throw error;
85
- }
86
- }
87
-
88
- async xpending(
89
- key: string,
90
- group: string,
91
- start?: string,
92
- end?: string,
93
- count?: number,
94
- consumer?: string
95
- ): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]> {
96
- try {
97
- const args = [key, group];
98
- if (start) args.push(start);
99
- if (end) args.push(end);
100
- if (count !== undefined) args.push(count.toString());
101
- if (consumer) args.push(consumer);
102
- try {
103
- return await this.redisClient.call('XPENDING', ...args) as [string, string, number, number][];
104
- } catch (error) {
105
- this.logger.error('err, args', { ...error }, args);
106
- }
107
- } catch (error) {
108
- this.logger.error(`Error in retrieving pending messages for [stream ${key}], [group ${group}]`, { ...error });
109
- throw error;
110
- }
111
- }
112
-
113
- async xclaim(
114
- key: string,
115
- group: string,
116
- consumer: string,
117
- minIdleTime: number,
118
- id: string,
119
- ...args: string[]
120
- ): Promise<ReclaimedMessageType> {
121
- try {
122
- return await this.redisClient.xclaim(key, group, consumer, minIdleTime, id, ...args) as unknown as ReclaimedMessageType;
123
- } catch (error) {
124
- this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, { ...error });
125
- throw error;
126
- }
127
- }
128
-
129
- async xack(key: string, group: string, id: string, multi? : RedisMultiType): Promise<number|RedisMultiType> {
130
- try {
131
- return await (multi || this.redisClient).xack(key, group, id);
132
- } catch (error) {
133
- this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, { ...error });
134
- throw error;
135
- }
136
- }
137
-
138
- async xdel(key: string, id: string, multi? : RedisMultiType): Promise<number|RedisMultiType> {
139
- try {
140
- return await (multi || this.redisClient).xdel(key, id);
141
- } catch (error) {
142
- this.logger.error(`Error in deleting messages with id: ${id} for key: ${key}`, { ...error });
143
- throw error;
144
- }
145
- }
146
-
147
- async xlen(key: string, multi? : RedisMultiType): Promise<number|RedisMultiType> {
148
- try {
149
- return await (multi || this.redisClient).xlen(key);
150
- } catch (error) {
151
- this.logger.error(`Error getting stream depth: ${key}`, { ...error });
152
- throw error;
153
- }
154
- }
155
- }
156
-
157
- export { IORedisStreamService };
@@ -1,158 +0,0 @@
1
- import { KeyService, KeyStoreParams, KeyType, HMNS } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { StreamService } from '../index';
4
- import { RedisClientType, RedisMultiType } from '../../../types/redisclient';
5
- import { ReclaimedMessageType } from '../../../types/stream';
6
-
7
- class RedisStreamService extends StreamService<RedisClientType, RedisMultiType> {
8
- redisClient: RedisClientType;
9
- namespace: string;
10
- logger: ILogger;
11
- appId: string;
12
-
13
- constructor(redisClient: RedisClientType) {
14
- super(redisClient);
15
- }
16
-
17
- async init(namespace = HMNS, appId: string, logger: ILogger): Promise<void> {
18
- this.namespace = namespace;
19
- this.logger = logger;
20
- this.appId = appId;
21
- }
22
-
23
- getMulti(): RedisMultiType {
24
- return this.redisClient.multi() as unknown as RedisMultiType;
25
- }
26
-
27
- mintKey(type: KeyType, params: KeyStoreParams): string {
28
- if (!this.namespace) throw new Error('namespace not set');
29
- return KeyService.mintKey(this.namespace, type, params);
30
- }
31
-
32
- async xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean> {
33
- const args = mkStream === 'MKSTREAM' ? ['MKSTREAM'] : [];
34
- try {
35
- return (await this.redisClient.sendCommand(['XGROUP', 'CREATE', key, groupName, id, ...args])) === 1;
36
- } catch (err) {
37
- const streamType = mkStream === 'MKSTREAM' ? 'with MKSTREAM' : 'without MKSTREAM';
38
- this.logger.error(`x-group-error ${streamType} for key: ${key} and group: ${groupName}`, err);
39
- throw err;
40
- }
41
- }
42
-
43
- async xadd(key: string, id: string, ...args: any[]): Promise<string | RedisMultiType> {
44
- let multi: RedisMultiType;
45
- if (typeof args[args.length - 1] !== 'string') {
46
- multi = args.pop() as RedisMultiType;
47
- }
48
- try {
49
- return await (multi || this.redisClient).XADD(key, id, { [args[0]]: args[1] });
50
- } catch (err) {
51
- this.logger.error(`Error publishing 'xadd'; key: ${key}`, err);
52
- throw err;
53
- }
54
- }
55
-
56
- async xreadgroup(
57
- command: 'GROUP',
58
- groupName: string,
59
- consumerName: string,
60
- blockOption: 'BLOCK'|'COUNT',
61
- blockTime: number|string,
62
- streamsOption: 'STREAMS',
63
- streamName: string,
64
- id: string
65
- ): Promise<string[][][] | null> {
66
- try {
67
- return await this.redisClient.sendCommand(['XREADGROUP', command, groupName, consumerName, blockOption, blockTime.toString(), streamsOption, streamName, id]);
68
- } catch (err) {
69
- this.logger.error(`Error in reading data from group: ${groupName} in stream: ${streamName}`, err);
70
- throw err;
71
- }
72
- }
73
-
74
- async xpending(
75
- key: string,
76
- group: string,
77
- start?: string,
78
- end?: string,
79
- count?: number,
80
- consumer?: string
81
- ): Promise<[string, string, number, [string, number][]][] | [string, string, number, number]> {
82
- try {
83
- const args = [key, group];
84
- if (start) args.push(start);
85
- if (end) args.push(end);
86
- if (count !== undefined) args.push(count.toString());
87
- if (consumer) args.push(consumer);
88
- try {
89
- return await this.redisClient.sendCommand(['XPENDING', ...args]);
90
- } catch (err) {
91
- this.logger.error('err, args', err, args);
92
- }
93
- } catch (err) {
94
- this.logger.error(`Error in retrieving pending messages for group: ${group} in key: ${key}`, err);
95
- throw err;
96
- }
97
- }
98
-
99
- async xclaim(
100
- key: string,
101
- group: string,
102
- consumer: string,
103
- minIdleTime: number,
104
- id: string,
105
- ...args: string[]
106
- ): Promise<ReclaimedMessageType> {
107
- try {
108
- return await this.redisClient.sendCommand(['XCLAIM', key, group, consumer, minIdleTime.toString(), id, ...args]) as unknown as ReclaimedMessageType;
109
- } catch (err) {
110
- this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, err);
111
- throw err;
112
- }
113
- }
114
-
115
- async xack(key: string, group: string, id: string, multi? : RedisMultiType): Promise<number|RedisMultiType> {
116
- try {
117
- if (multi) {
118
- multi.XACK(key, group, id);
119
- return multi;
120
- } else {
121
- return await this.redisClient.XACK(key, group, id);
122
- }
123
- } catch (err) {
124
- this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, err);
125
- throw err;
126
- }
127
- }
128
-
129
- async xdel(key: string, id: string, multi? : RedisMultiType): Promise<number|RedisMultiType> {
130
- try {
131
- if (multi) {
132
- multi.XDEL(key, id);
133
- return multi;
134
- } else {
135
- return await this.redisClient.XDEL(key, id);
136
- }
137
- } catch (err) {
138
- this.logger.error(`Error in deleting messages with ids: ${id} for key: ${key}`, err);
139
- throw err;
140
- }
141
- }
142
-
143
- async xlen(key: string, multi? : RedisMultiType): Promise<number|RedisMultiType> {
144
- try {
145
- if (multi) {
146
- multi.XLEN(key);
147
- return multi;
148
- } else {
149
- return await this.redisClient.XLEN(key);
150
- }
151
- } catch (error) {
152
- this.logger.error(`Error getting stream depth: ${key}`, { ...error });
153
- throw error;
154
- }
155
- }
156
- }
157
-
158
- export { RedisStreamService };
@@ -1,58 +0,0 @@
1
- import { KeyStoreParams, KeyType } from '../../modules/key';
2
- import { ReclaimedMessageType } from '../../types/stream';
3
- import { ILogger } from '../logger';
4
-
5
- abstract class StreamService<T, U> {
6
- redisClient: T;
7
- namespace: string;
8
- logger: ILogger;
9
- appId: string;
10
-
11
- constructor(redisClient: T) {
12
- this.redisClient = redisClient;
13
- }
14
-
15
- abstract init(namespace: string, appId: string, logger: ILogger): Promise<void>;
16
- abstract getMulti(): U;
17
- abstract mintKey(type: KeyType, params: KeyStoreParams): string;
18
- abstract xgroup(
19
- command: 'CREATE',
20
- key: string,
21
- groupName: string,
22
- id: string,
23
- mkStream?: 'MKSTREAM'): Promise<boolean>;
24
- abstract xadd(
25
- key: string,
26
- id: string,
27
- messageId: string,
28
- messageValue: string,
29
- multi?: U): Promise<string | U>;
30
- abstract xreadgroup(
31
- command: 'GROUP',
32
- groupName: string,
33
- consumerName: string,
34
- blockOption: 'BLOCK'|'COUNT',
35
- blockTime: number|string,
36
- streamsOption: 'STREAMS',
37
- streamName: string,
38
- id: string): Promise<string[][][] | null | unknown[]>;
39
- abstract xpending(
40
- key: string,
41
- group: string,
42
- start?: string,
43
- end?: string,
44
- count?: number,
45
- consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]>;
46
- abstract xclaim(
47
- key: string,
48
- group: string,
49
- consumer: string,
50
- minIdleTime: number,
51
- id: string,
52
- ...args: string[]): Promise<ReclaimedMessageType>;
53
- abstract xack(key: string, group: string, id: string, multi?: U): Promise<number|U>;
54
- abstract xdel(key: string, id: string, multi?: U): Promise<number|U>;
55
- abstract xlen(key: string, multi?: U): Promise<number|U>;
56
- }
57
-
58
- export { StreamService };
@@ -1,83 +0,0 @@
1
- import { KeyService, KeyStoreParams, KeyType, HMNS } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { SubService } from '../index';
4
- import { RedisClientType, RedisMultiType } from '../../../types/ioredisclient';
5
- import { SubscriptionCallback } from '../../../types/quorum';
6
-
7
- class IORedisSubService extends SubService<RedisClientType, RedisMultiType> {
8
- redisClient: RedisClientType;
9
- namespace: string;
10
- logger: ILogger;
11
- appId: string
12
-
13
- constructor(redisClient: RedisClientType) {
14
- super(redisClient);
15
- }
16
-
17
- async init(namespace = HMNS, appId: string, engineId: string, logger: ILogger): Promise<void> {
18
- this.namespace = namespace;
19
- this.logger = logger;
20
- this.appId = appId;
21
- }
22
-
23
- getMulti(): RedisMultiType {
24
- return this.redisClient.multi();
25
- }
26
-
27
- mintKey(type: KeyType, params: KeyStoreParams): string {
28
- if (!this.namespace) throw new Error('namespace not set');
29
- return KeyService.mintKey(this.namespace, type, params);
30
- }
31
-
32
- async subscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void> {
33
- const self = this;
34
- const topic = this.mintKey(keyType, { appId, engineId });
35
- await this.redisClient.subscribe(topic, (err) => {
36
- if (err) {
37
- self.logger.error(`Error subscribing to: ${topic}`, err);
38
- }
39
- });
40
- this.redisClient.on('message', (channel, message) => {
41
- if (channel === topic) {
42
- try {
43
- const payload = JSON.parse(message);
44
- callback(topic, payload);
45
- } catch (e) {
46
- self.logger.error(`Error parsing message: ${message}`, e);
47
- }
48
- }
49
- });
50
- }
51
-
52
- async unsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void> {
53
- const topic = this.mintKey(keyType, { appId, engineId });
54
- await this.redisClient.unsubscribe(topic);
55
- }
56
-
57
- async psubscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void> {
58
- const self = this;
59
- const topic = this.mintKey(keyType, { appId, engineId });
60
- await this.redisClient.psubscribe(topic, (err) => {
61
- if (err) {
62
- self.logger.error(`Error subscribing to: ${topic}`, err);
63
- }
64
- });
65
- this.redisClient.on('pmessage', (pattern, channel, message) => {
66
- if (pattern === topic) {
67
- try {
68
- const payload = JSON.parse(message);
69
- callback(channel, payload);
70
- } catch (e) {
71
- self.logger.error(`Error parsing message: ${message}`, e);
72
- }
73
- }
74
- });
75
- }
76
-
77
- async punsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void> {
78
- const topic = this.mintKey(keyType, { appId, engineId });
79
- await this.redisClient.punsubscribe(topic);
80
- }
81
- }
82
-
83
- export { IORedisSubService };
@@ -1,74 +0,0 @@
1
- import { KeyService, KeyStoreParams, KeyType, HMNS } from '../../../modules/key';
2
- import { ILogger } from '../../logger';
3
- import { SubService } from '../index';
4
- import { RedisClientType, RedisMultiType } from '../../../types/redisclient';
5
- import { SubscriptionCallback } from '../../../types/quorum';
6
-
7
- class RedisSubService extends SubService<RedisClientType, RedisMultiType> {
8
- redisClient: RedisClientType;
9
- namespace: string;
10
- logger: ILogger;
11
- appId: string;
12
-
13
- constructor(redisClient: RedisClientType) {
14
- super(redisClient);
15
- }
16
-
17
- async init(namespace = HMNS, appId: string, engineId: string, logger: ILogger): Promise<void> {
18
- this.namespace = namespace;
19
- this.logger = logger;
20
- this.appId = appId;
21
- }
22
-
23
- getMulti(): RedisMultiType {
24
- const multi = this.redisClient.multi();
25
- return multi as unknown as RedisMultiType;
26
- }
27
-
28
- mintKey(type: KeyType, params: KeyStoreParams): string {
29
- if (!this.namespace) throw new Error('namespace not set');
30
- return KeyService.mintKey(this.namespace, type, params);
31
- }
32
-
33
- async subscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void> {
34
- if (this.redisClient) {
35
- const self = this;
36
- const topic = this.mintKey(keyType, { appId, engineId });
37
- await this.redisClient.subscribe(topic, (message) => {
38
- try {
39
- const payload = JSON.parse(message);
40
- callback(topic, payload);
41
- } catch (e) {
42
- self.logger.error(`Error parsing message: ${message}`, e);
43
- }
44
- });
45
- }
46
- }
47
-
48
- async unsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void> {
49
- const topic = this.mintKey(keyType, { appId, engineId });
50
- await this.redisClient.unsubscribe(topic);
51
- }
52
-
53
- async psubscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void> {
54
- if (this.redisClient) {
55
- const self = this;
56
- const topic = this.mintKey(keyType, { appId, engineId });
57
- await this.redisClient.pSubscribe(topic, (message, channel) => {
58
- try {
59
- const payload = JSON.parse(message);
60
- callback(channel, payload);
61
- } catch (e) {
62
- self.logger.error(`Error parsing message: ${message}`, e);
63
- }
64
- });
65
- }
66
- }
67
-
68
- async punsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void> {
69
- const topic = this.mintKey(keyType, { appId, engineId });
70
- await this.redisClient.pUnsubscribe(topic);
71
- }
72
- }
73
-
74
- export { RedisSubService };
@@ -1,25 +0,0 @@
1
- import { KeyStoreParams, KeyType } from '../../modules/key';
2
- import { ILogger } from '../logger';
3
- import { SubscriptionCallback } from '../../types/quorum';
4
-
5
- abstract class SubService<T, U> {
6
- redisClient: T;
7
- namespace: string;
8
- logger: ILogger;
9
- appId: string;
10
-
11
- constructor(redisClient: T) {
12
- this.redisClient = redisClient;
13
- }
14
-
15
- abstract init(namespace: string, appId: string, engineId: string, logger: ILogger): Promise<void>;
16
- abstract getMulti(): U;
17
- abstract mintKey(type: KeyType, params: KeyStoreParams): string;
18
- abstract subscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
19
- abstract unsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
20
- abstract psubscribe(keyType: KeyType.QUORUM, callback: SubscriptionCallback, appId: string, engineId?: string): Promise<void>;
21
- abstract punsubscribe(keyType: KeyType.QUORUM, appId: string, engineId?: string): Promise<void>;
22
- //NOTE: `publish` happens in the 'StoreService' as Redis subscription clients must be read-only
23
- }
24
-
25
- export { SubService };