@hotmeshio/hotmesh 0.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 (263) hide show
  1. package/LICENSE +214 -0
  2. package/README.md +241 -0
  3. package/build/index.d.ts +4 -0
  4. package/build/index.js +7 -0
  5. package/build/modules/errors.d.ts +28 -0
  6. package/build/modules/errors.js +50 -0
  7. package/build/modules/key.d.ts +75 -0
  8. package/build/modules/key.js +116 -0
  9. package/build/modules/utils.d.ts +34 -0
  10. package/build/modules/utils.js +173 -0
  11. package/build/package.json +73 -0
  12. package/build/services/activities/activity.d.ts +59 -0
  13. package/build/services/activities/activity.js +396 -0
  14. package/build/services/activities/await.d.ts +16 -0
  15. package/build/services/activities/await.js +143 -0
  16. package/build/services/activities/emit.d.ts +9 -0
  17. package/build/services/activities/emit.js +13 -0
  18. package/build/services/activities/index.d.ts +15 -0
  19. package/build/services/activities/index.js +16 -0
  20. package/build/services/activities/iterate.d.ts +9 -0
  21. package/build/services/activities/iterate.js +13 -0
  22. package/build/services/activities/trigger.d.ts +22 -0
  23. package/build/services/activities/trigger.js +161 -0
  24. package/build/services/activities/worker.d.ts +17 -0
  25. package/build/services/activities/worker.js +164 -0
  26. package/build/services/collator/index.d.ts +54 -0
  27. package/build/services/collator/index.js +171 -0
  28. package/build/services/compiler/deployer.d.ts +35 -0
  29. package/build/services/compiler/deployer.js +412 -0
  30. package/build/services/compiler/index.d.ts +30 -0
  31. package/build/services/compiler/index.js +111 -0
  32. package/build/services/compiler/validator.d.ts +32 -0
  33. package/build/services/compiler/validator.js +134 -0
  34. package/build/services/connector/clients/ioredis.d.ts +13 -0
  35. package/build/services/connector/clients/ioredis.js +50 -0
  36. package/build/services/connector/clients/redis.d.ts +13 -0
  37. package/build/services/connector/clients/redis.js +62 -0
  38. package/build/services/connector/index.d.ts +5 -0
  39. package/build/services/connector/index.js +31 -0
  40. package/build/services/dimension/index.d.ts +29 -0
  41. package/build/services/dimension/index.js +35 -0
  42. package/build/services/durable/asyncLocalStorage.d.ts +3 -0
  43. package/build/services/durable/asyncLocalStorage.js +5 -0
  44. package/build/services/durable/client.d.ts +15 -0
  45. package/build/services/durable/client.js +108 -0
  46. package/build/services/durable/connection.d.ts +4 -0
  47. package/build/services/durable/connection.js +51 -0
  48. package/build/services/durable/factory.d.ts +3 -0
  49. package/build/services/durable/factory.js +123 -0
  50. package/build/services/durable/handle.d.ts +8 -0
  51. package/build/services/durable/handle.js +38 -0
  52. package/build/services/durable/index.d.ts +57 -0
  53. package/build/services/durable/index.js +58 -0
  54. package/build/services/durable/native.d.ts +4 -0
  55. package/build/services/durable/native.js +47 -0
  56. package/build/services/durable/worker.d.ts +36 -0
  57. package/build/services/durable/worker.js +266 -0
  58. package/build/services/durable/workflow.d.ts +6 -0
  59. package/build/services/durable/workflow.js +135 -0
  60. package/build/services/engine/index.d.ts +82 -0
  61. package/build/services/engine/index.js +511 -0
  62. package/build/services/hotmesh/index.d.ts +45 -0
  63. package/build/services/hotmesh/index.js +134 -0
  64. package/build/services/logger/index.d.ts +17 -0
  65. package/build/services/logger/index.js +73 -0
  66. package/build/services/mapper/index.d.ts +24 -0
  67. package/build/services/mapper/index.js +72 -0
  68. package/build/services/pipe/functions/array.d.ts +24 -0
  69. package/build/services/pipe/functions/array.js +69 -0
  70. package/build/services/pipe/functions/bitwise.d.ts +9 -0
  71. package/build/services/pipe/functions/bitwise.js +24 -0
  72. package/build/services/pipe/functions/conditional.d.ts +10 -0
  73. package/build/services/pipe/functions/conditional.js +27 -0
  74. package/build/services/pipe/functions/date.d.ts +57 -0
  75. package/build/services/pipe/functions/date.js +167 -0
  76. package/build/services/pipe/functions/index.d.ts +25 -0
  77. package/build/services/pipe/functions/index.js +26 -0
  78. package/build/services/pipe/functions/json.d.ts +5 -0
  79. package/build/services/pipe/functions/json.js +12 -0
  80. package/build/services/pipe/functions/math.d.ts +38 -0
  81. package/build/services/pipe/functions/math.js +111 -0
  82. package/build/services/pipe/functions/number.d.ts +25 -0
  83. package/build/services/pipe/functions/number.js +133 -0
  84. package/build/services/pipe/functions/object.d.ts +22 -0
  85. package/build/services/pipe/functions/object.js +63 -0
  86. package/build/services/pipe/functions/string.d.ts +23 -0
  87. package/build/services/pipe/functions/string.js +69 -0
  88. package/build/services/pipe/functions/symbol.d.ts +12 -0
  89. package/build/services/pipe/functions/symbol.js +33 -0
  90. package/build/services/pipe/functions/unary.d.ts +7 -0
  91. package/build/services/pipe/functions/unary.js +18 -0
  92. package/build/services/pipe/index.d.ts +30 -0
  93. package/build/services/pipe/index.js +128 -0
  94. package/build/services/quorum/index.d.ts +34 -0
  95. package/build/services/quorum/index.js +147 -0
  96. package/build/services/reporter/index.d.ts +47 -0
  97. package/build/services/reporter/index.js +330 -0
  98. package/build/services/serializer/index.d.ts +36 -0
  99. package/build/services/serializer/index.js +222 -0
  100. package/build/services/signaler/store.d.ts +15 -0
  101. package/build/services/signaler/store.js +53 -0
  102. package/build/services/signaler/stream.d.ts +43 -0
  103. package/build/services/signaler/stream.js +317 -0
  104. package/build/services/store/cache.d.ts +66 -0
  105. package/build/services/store/cache.js +127 -0
  106. package/build/services/store/clients/ioredis.d.ts +27 -0
  107. package/build/services/store/clients/ioredis.js +96 -0
  108. package/build/services/store/clients/redis.d.ts +29 -0
  109. package/build/services/store/clients/redis.js +143 -0
  110. package/build/services/store/index.d.ts +88 -0
  111. package/build/services/store/index.js +657 -0
  112. package/build/services/stream/clients/ioredis.d.ts +23 -0
  113. package/build/services/stream/clients/ioredis.js +115 -0
  114. package/build/services/stream/clients/redis.d.ts +23 -0
  115. package/build/services/stream/clients/redis.js +119 -0
  116. package/build/services/stream/index.d.ts +21 -0
  117. package/build/services/stream/index.js +9 -0
  118. package/build/services/sub/clients/ioredis.d.ts +20 -0
  119. package/build/services/sub/clients/ioredis.js +72 -0
  120. package/build/services/sub/clients/redis.d.ts +20 -0
  121. package/build/services/sub/clients/redis.js +63 -0
  122. package/build/services/sub/index.d.ts +18 -0
  123. package/build/services/sub/index.js +9 -0
  124. package/build/services/task/index.d.ts +18 -0
  125. package/build/services/task/index.js +73 -0
  126. package/build/services/telemetry/index.d.ts +49 -0
  127. package/build/services/telemetry/index.js +223 -0
  128. package/build/services/worker/index.d.ts +30 -0
  129. package/build/services/worker/index.js +105 -0
  130. package/build/types/activity.d.ts +86 -0
  131. package/build/types/activity.js +2 -0
  132. package/build/types/app.d.ts +16 -0
  133. package/build/types/app.js +2 -0
  134. package/build/types/async.d.ts +5 -0
  135. package/build/types/async.js +2 -0
  136. package/build/types/cache.d.ts +1 -0
  137. package/build/types/cache.js +2 -0
  138. package/build/types/collator.d.ts +8 -0
  139. package/build/types/collator.js +11 -0
  140. package/build/types/durable.d.ts +59 -0
  141. package/build/types/durable.js +2 -0
  142. package/build/types/hook.d.ts +31 -0
  143. package/build/types/hook.js +9 -0
  144. package/build/types/hotmesh.d.ts +82 -0
  145. package/build/types/hotmesh.js +2 -0
  146. package/build/types/index.d.ts +20 -0
  147. package/build/types/index.js +21 -0
  148. package/build/types/ioredisclient.d.ts +5 -0
  149. package/build/types/ioredisclient.js +5 -0
  150. package/build/types/job.d.ts +50 -0
  151. package/build/types/job.js +2 -0
  152. package/build/types/logger.d.ts +6 -0
  153. package/build/types/logger.js +2 -0
  154. package/build/types/map.d.ts +4 -0
  155. package/build/types/map.js +2 -0
  156. package/build/types/pipe.d.ts +4 -0
  157. package/build/types/pipe.js +2 -0
  158. package/build/types/quorum.d.ts +46 -0
  159. package/build/types/quorum.js +2 -0
  160. package/build/types/redis.d.ts +8 -0
  161. package/build/types/redis.js +2 -0
  162. package/build/types/redisclient.d.ts +25 -0
  163. package/build/types/redisclient.js +2 -0
  164. package/build/types/serializer.d.ts +33 -0
  165. package/build/types/serializer.js +2 -0
  166. package/build/types/stats.d.ts +83 -0
  167. package/build/types/stats.js +2 -0
  168. package/build/types/stream.d.ts +67 -0
  169. package/build/types/stream.js +25 -0
  170. package/build/types/telemetry.d.ts +1 -0
  171. package/build/types/telemetry.js +11 -0
  172. package/build/types/transition.d.ts +17 -0
  173. package/build/types/transition.js +2 -0
  174. package/index.ts +5 -0
  175. package/modules/errors.ts +55 -0
  176. package/modules/key.ts +129 -0
  177. package/modules/utils.ts +170 -0
  178. package/package.json +73 -0
  179. package/services/activities/activity.ts +473 -0
  180. package/services/activities/await.ts +172 -0
  181. package/services/activities/emit.ts +25 -0
  182. package/services/activities/index.ts +15 -0
  183. package/services/activities/iterate.ts +26 -0
  184. package/services/activities/trigger.ts +196 -0
  185. package/services/activities/worker.ts +190 -0
  186. package/services/collator/README.md +102 -0
  187. package/services/collator/index.ts +182 -0
  188. package/services/compiler/deployer.ts +432 -0
  189. package/services/compiler/index.ts +98 -0
  190. package/services/compiler/validator.ts +154 -0
  191. package/services/connector/clients/ioredis.ts +57 -0
  192. package/services/connector/clients/redis.ts +72 -0
  193. package/services/connector/index.ts +44 -0
  194. package/services/dimension/README.md +73 -0
  195. package/services/dimension/index.ts +39 -0
  196. package/services/durable/asyncLocalStorage.ts +3 -0
  197. package/services/durable/client.ts +116 -0
  198. package/services/durable/connection.ts +50 -0
  199. package/services/durable/factory.ts +124 -0
  200. package/services/durable/handle.ts +43 -0
  201. package/services/durable/index.ts +60 -0
  202. package/services/durable/native.ts +46 -0
  203. package/services/durable/worker.ts +254 -0
  204. package/services/durable/workflow.ts +136 -0
  205. package/services/engine/index.ts +615 -0
  206. package/services/hotmesh/index.ts +182 -0
  207. package/services/logger/index.ts +79 -0
  208. package/services/mapper/index.ts +84 -0
  209. package/services/pipe/functions/array.ts +87 -0
  210. package/services/pipe/functions/bitwise.ts +27 -0
  211. package/services/pipe/functions/conditional.ts +31 -0
  212. package/services/pipe/functions/date.ts +214 -0
  213. package/services/pipe/functions/index.ts +25 -0
  214. package/services/pipe/functions/json.ts +11 -0
  215. package/services/pipe/functions/math.ts +143 -0
  216. package/services/pipe/functions/number.ts +150 -0
  217. package/services/pipe/functions/object.ts +79 -0
  218. package/services/pipe/functions/string.ts +86 -0
  219. package/services/pipe/functions/symbol.ts +39 -0
  220. package/services/pipe/functions/unary.ts +19 -0
  221. package/services/pipe/index.ts +138 -0
  222. package/services/quorum/index.ts +200 -0
  223. package/services/reporter/index.ts +379 -0
  224. package/services/serializer/README.md +10 -0
  225. package/services/serializer/index.ts +243 -0
  226. package/services/signaler/store.ts +61 -0
  227. package/services/signaler/stream.ts +354 -0
  228. package/services/store/cache.ts +172 -0
  229. package/services/store/clients/ioredis.ts +123 -0
  230. package/services/store/clients/redis.ts +169 -0
  231. package/services/store/index.ts +757 -0
  232. package/services/stream/clients/ioredis.ts +148 -0
  233. package/services/stream/clients/redis.ts +144 -0
  234. package/services/stream/index.ts +57 -0
  235. package/services/sub/clients/ioredis.ts +83 -0
  236. package/services/sub/clients/redis.ts +74 -0
  237. package/services/sub/index.ts +25 -0
  238. package/services/task/index.ts +86 -0
  239. package/services/telemetry/index.ts +267 -0
  240. package/services/worker/index.ts +165 -0
  241. package/types/activity.ts +115 -0
  242. package/types/app.ts +20 -0
  243. package/types/async.ts +7 -0
  244. package/types/cache.ts +1 -0
  245. package/types/collator.ts +9 -0
  246. package/types/durable.ts +81 -0
  247. package/types/hook.ts +32 -0
  248. package/types/hotmesh.ts +102 -0
  249. package/types/index.ts +138 -0
  250. package/types/ioredisclient.ts +10 -0
  251. package/types/job.ts +59 -0
  252. package/types/logger.ts +6 -0
  253. package/types/map.ts +5 -0
  254. package/types/ms.d.ts +7 -0
  255. package/types/pipe.ts +7 -0
  256. package/types/quorum.ts +59 -0
  257. package/types/redis.ts +27 -0
  258. package/types/redisclient.ts +29 -0
  259. package/types/serializer.ts +38 -0
  260. package/types/stats.ts +100 -0
  261. package/types/stream.ts +75 -0
  262. package/types/telemetry.ts +15 -0
  263. package/types/transition.ts +20 -0
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The Cache is a key/value store and used to store commonly accessed Redis metadata
3
+ * (mainly the execution rules for the app) to save time accessing them as they
4
+ * are immutable per verison. The only time the rules are ejected are when
5
+ * a new version is deployed to the quorum and the cache is invalidated/cleared.
6
+ */
7
+ import { ActivityType } from "../../types/activity";
8
+ import { HookRule } from "../../types/hook";
9
+ import { HotMeshApp, HotMeshSettings } from "../../types/hotmesh";
10
+ import { Symbols } from "../../types/serializer";
11
+ import { Transitions } from "../../types/transition";
12
+ declare class Cache {
13
+ settings: HotMeshSettings;
14
+ appId: string;
15
+ apps: Record<string, HotMeshApp>;
16
+ schemas: Record<string, ActivityType>;
17
+ subscriptions: Record<string, Record<string, string>>;
18
+ symbols: Record<string, Symbols>;
19
+ symvals: Record<string, Symbols>;
20
+ transitions: Record<string, Record<string, unknown>>;
21
+ hookRules: Record<string, Record<string, HookRule[]>>;
22
+ workItems: Record<string, string>;
23
+ /**
24
+ * The cache is ALWAYS initialized with HotMeshSettings. The other parameters are optional.
25
+ * @param settings
26
+ * @param apps
27
+ * @param schemas
28
+ * @param subscriptions
29
+ * @param transitions
30
+ * @param hookRules
31
+ */
32
+ constructor(appId: string, settings: HotMeshSettings, apps?: Record<string, HotMeshApp>, schemas?: Record<string, ActivityType>, subscriptions?: Record<string, Record<string, string>>, symbols?: Record<string, Symbols>, symvals?: Record<string, Symbols>, transitions?: Record<string, Record<string, unknown>>, hookRules?: Record<string, Record<string, HookRule[]>>, workItems?: Record<string, string>);
33
+ /**
34
+ * invalidate the cache; settings are not invalidated!
35
+ */
36
+ invalidate(): void;
37
+ getSettings(): HotMeshSettings;
38
+ setSettings(settings: HotMeshSettings): void;
39
+ getApps(): Record<string, HotMeshApp>;
40
+ getApp(appId: string): HotMeshApp;
41
+ setApps(apps: Record<string, HotMeshApp>): void;
42
+ setApp(appId: string, app: HotMeshApp): void;
43
+ getSchemas(appId: string, version: string): Record<string, ActivityType>;
44
+ getSchema(appId: string, version: string, activityId: string): ActivityType;
45
+ setSchemas(appId: string, version: string, schemas: Record<string, ActivityType>): void;
46
+ setSchema(appId: string, version: string, activityId: string, schema: ActivityType): void;
47
+ getSubscriptions(appId: string, version: string): Record<string, string>;
48
+ getSubscription(appId: string, version: string, topic: string): unknown;
49
+ setSubscriptions(appId: string, version: string, subscriptions: Record<string, string>): void;
50
+ getSymbols(appId: string, targetEntityId: string): Symbols;
51
+ setSymbols(appId: string, targetEntityId: string, symbols: Symbols): void;
52
+ deleteSymbols(appId: string, targetEntityId: string): void;
53
+ getSymbolValues(appId: string): Symbols;
54
+ setSymbolValues(appId: string, symvals: Symbols): void;
55
+ deleteSymbolValues(appId: string): void;
56
+ getTransitions(appId: string, version: string): Transitions;
57
+ setTransitions(appId: string, version: string, transitions: Transitions): void;
58
+ getHookRules(appId: string): Record<string, HookRule[]>;
59
+ setHookRules(appId: string, hookRules: Record<string, HookRule[]>): void;
60
+ getSignals(appId: string, version: string): Record<string, unknown>;
61
+ setSignals(appId: string, version: string): Record<string, unknown>;
62
+ getActiveTaskQueue(appId: string): string;
63
+ setWorkItem(appId: string, workItem: string): void;
64
+ removeWorkItem(appId: string): void;
65
+ }
66
+ export { Cache };
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ /**
3
+ * The Cache is a key/value store and used to store commonly accessed Redis metadata
4
+ * (mainly the execution rules for the app) to save time accessing them as they
5
+ * are immutable per verison. The only time the rules are ejected are when
6
+ * a new version is deployed to the quorum and the cache is invalidated/cleared.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Cache = void 0;
10
+ class Cache {
11
+ /**
12
+ * The cache is ALWAYS initialized with HotMeshSettings. The other parameters are optional.
13
+ * @param settings
14
+ * @param apps
15
+ * @param schemas
16
+ * @param subscriptions
17
+ * @param transitions
18
+ * @param hookRules
19
+ */
20
+ constructor(appId, settings, apps = {}, schemas = {}, subscriptions = {}, symbols = {}, symvals = {}, transitions = {}, hookRules = {}, workItems = {}) {
21
+ this.appId = appId;
22
+ this.settings = settings;
23
+ this.apps = apps;
24
+ this.schemas = schemas;
25
+ this.subscriptions = subscriptions;
26
+ this.symbols = symbols;
27
+ this.symvals = symvals;
28
+ this.transitions = transitions;
29
+ this.hookRules = hookRules;
30
+ this.workItems = workItems;
31
+ }
32
+ /**
33
+ * invalidate the cache; settings are not invalidated!
34
+ */
35
+ invalidate() {
36
+ this.apps = {};
37
+ this.schemas = {};
38
+ this.subscriptions = {};
39
+ this.transitions = {};
40
+ this.hookRules = {};
41
+ }
42
+ getSettings() {
43
+ return this.settings;
44
+ }
45
+ setSettings(settings) {
46
+ this.settings = settings;
47
+ }
48
+ getApps() {
49
+ return this.apps;
50
+ }
51
+ getApp(appId) {
52
+ return this.apps[appId];
53
+ }
54
+ setApps(apps) {
55
+ this.apps = apps;
56
+ }
57
+ setApp(appId, app) {
58
+ this.apps[appId] = app;
59
+ }
60
+ getSchemas(appId, version) {
61
+ return this.schemas[`${appId}/${version}`];
62
+ }
63
+ getSchema(appId, version, activityId) {
64
+ return this.schemas?.[`${appId}/${version}`]?.[activityId];
65
+ }
66
+ setSchemas(appId, version, schemas) {
67
+ this.schemas[`${appId}/${version}`] = schemas;
68
+ }
69
+ setSchema(appId, version, activityId, schema) {
70
+ this.schemas[`${appId}/${version}`][activityId] = schema;
71
+ }
72
+ getSubscriptions(appId, version) {
73
+ return this.subscriptions[`${appId}/${version}`];
74
+ }
75
+ getSubscription(appId, version, topic) {
76
+ return this.subscriptions?.[`${appId}/${version}`]?.[topic];
77
+ }
78
+ setSubscriptions(appId, version, subscriptions) {
79
+ this.subscriptions[`${appId}/${version}`] = subscriptions;
80
+ }
81
+ getSymbols(appId, targetEntityId) {
82
+ return this.symbols[`${appId}/${targetEntityId}`];
83
+ }
84
+ setSymbols(appId, targetEntityId, symbols) {
85
+ this.symbols[`${appId}/${targetEntityId}`] = symbols;
86
+ }
87
+ deleteSymbols(appId, targetEntityId) {
88
+ delete this.symbols[`${appId}/${targetEntityId}`];
89
+ }
90
+ getSymbolValues(appId) {
91
+ return this.symvals[`${appId}`];
92
+ }
93
+ setSymbolValues(appId, symvals) {
94
+ this.symvals[`${appId}`] = symvals;
95
+ }
96
+ deleteSymbolValues(appId) {
97
+ delete this.symvals[`${appId}`];
98
+ }
99
+ getTransitions(appId, version) {
100
+ return this.transitions[`${appId}/${version}`];
101
+ }
102
+ setTransitions(appId, version, transitions) {
103
+ this.transitions[`${appId}/${version}`] = transitions;
104
+ }
105
+ getHookRules(appId) {
106
+ return this.hookRules[`${appId}`];
107
+ }
108
+ setHookRules(appId, hookRules) {
109
+ this.hookRules[`${appId}`] = hookRules;
110
+ }
111
+ getSignals(appId, version) {
112
+ throw new Error("SIGNAL (getHooks) is not supported");
113
+ }
114
+ setSignals(appId, version) {
115
+ throw new Error("SIGNAL (setHook) is not supported");
116
+ }
117
+ getActiveTaskQueue(appId) {
118
+ return this.workItems[appId];
119
+ }
120
+ setWorkItem(appId, workItem) {
121
+ this.workItems[appId] = workItem;
122
+ }
123
+ removeWorkItem(appId) {
124
+ delete this.workItems[appId];
125
+ }
126
+ }
127
+ exports.Cache = Cache;
@@ -0,0 +1,27 @@
1
+ import { KeyType } from '../../../modules/key';
2
+ import { ILogger } from '../../logger';
3
+ import { SerializerService as Serializer } from '../../serializer';
4
+ import { Cache } from '../cache';
5
+ import { StoreService } from '../index';
6
+ import { RedisClientType, RedisMultiType } from '../../../types/ioredisclient';
7
+ import { ReclaimedMessageType } from '../../../types/stream';
8
+ declare class IORedisStoreService extends StoreService<RedisClientType, RedisMultiType> {
9
+ redisClient: RedisClientType;
10
+ cache: Cache;
11
+ namespace: string;
12
+ appId: string;
13
+ logger: ILogger;
14
+ serializer: Serializer;
15
+ constructor(redisClient: RedisClientType);
16
+ getMulti(): RedisMultiType;
17
+ hGetAllResult(result: any): any;
18
+ addTaskQueues(keys: string[]): Promise<void>;
19
+ publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
20
+ xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
21
+ xadd(key: string, id: string, messageId: string, messageValue: string, multi?: RedisMultiType): Promise<string | RedisMultiType>;
22
+ xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]>;
23
+ xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
24
+ xack(key: string, group: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
25
+ xdel(key: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
26
+ }
27
+ export { IORedisStoreService };
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IORedisStoreService = void 0;
4
+ const key_1 = require("../../../modules/key");
5
+ const index_1 = require("../index");
6
+ class IORedisStoreService extends index_1.StoreService {
7
+ constructor(redisClient) {
8
+ super(redisClient);
9
+ }
10
+ getMulti() {
11
+ return this.redisClient.multi();
12
+ }
13
+ hGetAllResult(result) {
14
+ //ioredis response signature is [null, {}] or [null, null]
15
+ return result[1];
16
+ }
17
+ async addTaskQueues(keys) {
18
+ const multi = this.redisClient.multi();
19
+ const zsetKey = this.mintKey(key_1.KeyType.WORK_ITEMS, { appId: this.appId });
20
+ for (const key of keys) {
21
+ multi.zadd(zsetKey, 'NX', Date.now(), key);
22
+ }
23
+ await multi.exec();
24
+ }
25
+ async publish(keyType, message, appId, engineId) {
26
+ const topic = this.mintKey(keyType, { appId, engineId });
27
+ const status = await this.redisClient.publish(topic, JSON.stringify(message));
28
+ return status === 1;
29
+ }
30
+ async xgroup(command, key, groupName, id, mkStream) {
31
+ if (mkStream === 'MKSTREAM') {
32
+ try {
33
+ return (await this.redisClient.xgroup(command, key, groupName, id, mkStream)) === 'OK';
34
+ }
35
+ catch (err) {
36
+ this.logger.info(`Consumer group not created with MKSTREAM for key: ${key} and group: ${groupName}`);
37
+ throw err;
38
+ }
39
+ }
40
+ else {
41
+ try {
42
+ return (await this.redisClient.xgroup(command, key, groupName, id)) === 'OK';
43
+ }
44
+ catch (err) {
45
+ this.logger.info(`Consumer group not created for key: ${key} and group: ${groupName}`);
46
+ throw err;
47
+ }
48
+ }
49
+ }
50
+ async xadd(key, id, messageId, messageValue, multi) {
51
+ try {
52
+ return await (multi || this.redisClient).xadd(key, id, messageId, messageValue);
53
+ }
54
+ catch (err) {
55
+ this.logger.error(`Error publishing 'xadd'; key: ${key}`, err);
56
+ throw err;
57
+ }
58
+ }
59
+ async xpending(key, group, start, end, count, consumer) {
60
+ try {
61
+ return await this.redisClient.xpending(key, group, start, end, count, consumer);
62
+ }
63
+ catch (err) {
64
+ this.logger.error(`Error in retrieving pending messages for [stream ${key}], [group ${group}]`, err);
65
+ throw err;
66
+ }
67
+ }
68
+ async xclaim(key, group, consumer, minIdleTime, id, ...args) {
69
+ try {
70
+ return await this.redisClient.xclaim(key, group, consumer, minIdleTime, id, ...args);
71
+ }
72
+ catch (err) {
73
+ this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, err);
74
+ throw err;
75
+ }
76
+ }
77
+ async xack(key, group, id, multi) {
78
+ try {
79
+ return await (multi || this.redisClient).xack(key, group, id);
80
+ }
81
+ catch (err) {
82
+ this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, err);
83
+ throw err;
84
+ }
85
+ }
86
+ async xdel(key, id, multi) {
87
+ try {
88
+ return await (multi || this.redisClient).xdel(key, id);
89
+ }
90
+ catch (err) {
91
+ this.logger.error(`Error in deleting messages with id: ${id} for key: ${key}`, err);
92
+ throw err;
93
+ }
94
+ }
95
+ }
96
+ exports.IORedisStoreService = IORedisStoreService;
@@ -0,0 +1,29 @@
1
+ import { KeyType } from '../../../modules/key';
2
+ import { ILogger } from '../../logger';
3
+ import { SerializerService as Serializer } from '../../serializer';
4
+ import { Cache } from '../cache';
5
+ import { StoreService } from '../index';
6
+ import { RedisClientType, RedisMultiType } from '../../../types/redisclient';
7
+ import { ReclaimedMessageType } from '../../../types/stream';
8
+ declare class RedisStoreService extends StoreService<RedisClientType, RedisMultiType> {
9
+ redisClient: RedisClientType;
10
+ cache: Cache;
11
+ namespace: string;
12
+ appId: string;
13
+ logger: ILogger;
14
+ serializer: Serializer;
15
+ commands: Record<string, string>;
16
+ constructor(redisClient: RedisClientType);
17
+ getMulti(): RedisMultiType;
18
+ publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
19
+ zAdd(key: string, score: number | string, value: string | number, redisMulti?: RedisMultiType): Promise<any>;
20
+ zRangeByScoreWithScores(key: string, score: number | string, value: string | number): Promise<string | null>;
21
+ zRangeByScore(key: string, score: number | string, value: string | number): Promise<string | null>;
22
+ xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
23
+ xadd(key: string, id: string, ...args: any[]): Promise<string | RedisMultiType>;
24
+ xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number]>;
25
+ xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
26
+ xack(key: string, group: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
27
+ xdel(key: string, id: string, multi?: RedisMultiType): Promise<number | RedisMultiType>;
28
+ }
29
+ export { RedisStoreService };
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisStoreService = void 0;
4
+ const index_1 = require("../index");
5
+ class RedisStoreService extends index_1.StoreService {
6
+ constructor(redisClient) {
7
+ super(redisClient);
8
+ this.commands = {
9
+ setnx: 'SETNX',
10
+ del: 'DEL',
11
+ expire: 'EXPIRE',
12
+ hset: 'HSET',
13
+ hsetnx: 'HSETNX',
14
+ hincrby: 'HINCRBY',
15
+ hdel: 'HDEL',
16
+ hget: 'HGET',
17
+ hmget: 'HMGET',
18
+ hgetall: 'HGETALL',
19
+ hincrbyfloat: 'HINCRBYFLOAT',
20
+ zrange: 'ZRANGE',
21
+ zrangebyscore_withscores: 'ZRANGEBYSCORE_WITHSCORES',
22
+ zrangebyscore: 'ZRANGEBYSCORE',
23
+ zrem: 'ZREM',
24
+ zadd: 'ZADD',
25
+ lmove: 'LMOVE',
26
+ lrange: 'LRANGE',
27
+ llen: 'LLEN',
28
+ lpop: 'LPOP',
29
+ rename: 'RENAME',
30
+ rpush: 'RPUSH',
31
+ xack: 'XACK',
32
+ xdel: 'XDEL',
33
+ };
34
+ }
35
+ getMulti() {
36
+ const multi = this.redisClient.MULTI();
37
+ return multi;
38
+ }
39
+ async publish(keyType, message, appId, engineId) {
40
+ const topic = this.mintKey(keyType, { appId, engineId });
41
+ const status = await this.redisClient.publish(topic, JSON.stringify(message));
42
+ return this.isSuccessful(status);
43
+ }
44
+ async zAdd(key, score, value, redisMulti) {
45
+ return await (redisMulti || this.redisClient)[this.commands.zadd](key, { score: score, value: value.toString() });
46
+ }
47
+ async zRangeByScoreWithScores(key, score, value) {
48
+ const result = await this.redisClient[this.commands.zrangebyscore_withscores](key, score, value);
49
+ if (result?.length > 0) {
50
+ return result[0];
51
+ }
52
+ return null;
53
+ }
54
+ async zRangeByScore(key, score, value) {
55
+ const result = await this.redisClient[this.commands.zrangebyscore](key, score, value);
56
+ if (result?.length > 0) {
57
+ return result[0];
58
+ }
59
+ return null;
60
+ }
61
+ async xgroup(command, key, groupName, id, mkStream) {
62
+ const args = mkStream === 'MKSTREAM' ? ['MKSTREAM'] : [];
63
+ try {
64
+ return (await this.redisClient.sendCommand(['XGROUP', 'CREATE', key, groupName, id, ...args])) === 1;
65
+ }
66
+ catch (err) {
67
+ const streamType = mkStream === 'MKSTREAM' ? 'with MKSTREAM' : 'without MKSTREAM';
68
+ this.logger.warn(`x-group-error ${streamType} for key: ${key} and group: ${groupName}`, err);
69
+ throw err;
70
+ }
71
+ }
72
+ async xadd(key, id, ...args) {
73
+ let multi;
74
+ if (typeof args[args.length - 1] !== 'string') {
75
+ multi = args.pop();
76
+ }
77
+ try {
78
+ return await (multi || this.redisClient).XADD(key, id, { [args[0]]: args[1] });
79
+ }
80
+ catch (err) {
81
+ this.logger.error(`Error publishing 'xadd'; key: ${key}`, err);
82
+ throw err;
83
+ }
84
+ }
85
+ async xpending(key, group, start, end, count, consumer) {
86
+ try {
87
+ const args = [key, group];
88
+ if (start)
89
+ args.push(start);
90
+ if (end)
91
+ args.push(end);
92
+ if (count !== undefined)
93
+ args.push(count.toString());
94
+ if (consumer)
95
+ args.push(consumer);
96
+ return await this.redisClient.sendCommand(['XPENDING', ...args]);
97
+ }
98
+ catch (err) {
99
+ this.logger.error(`Error in retrieving pending messages for group: ${group} in key: ${key}`, err);
100
+ throw err;
101
+ }
102
+ }
103
+ async xclaim(key, group, consumer, minIdleTime, id, ...args) {
104
+ try {
105
+ return await this.redisClient.sendCommand(['XCLAIM', key, group, consumer, minIdleTime.toString(), id, ...args]);
106
+ }
107
+ catch (err) {
108
+ this.logger.error(`Error in claiming message with id: ${id} in group: ${group} for key: ${key}`, err);
109
+ throw err;
110
+ }
111
+ }
112
+ async xack(key, group, id, multi) {
113
+ try {
114
+ if (multi) {
115
+ multi[this.commands.xack](key, group, id);
116
+ return multi;
117
+ }
118
+ else {
119
+ return await this.redisClient[this.commands.xack](key, group, id);
120
+ }
121
+ }
122
+ catch (err) {
123
+ this.logger.error(`Error in acknowledging messages in group: ${group} for key: ${key}`, err);
124
+ throw err;
125
+ }
126
+ }
127
+ async xdel(key, id, multi) {
128
+ try {
129
+ if (multi) {
130
+ multi[this.commands.xdel](key, id);
131
+ return multi;
132
+ }
133
+ else {
134
+ return await this.redisClient[this.commands.xdel](key, id);
135
+ }
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
+ exports.RedisStoreService = RedisStoreService;
@@ -0,0 +1,88 @@
1
+ import { KeyStoreParams, KeyType } from '../../modules/key';
2
+ import { ILogger } from '../logger';
3
+ import { SerializerService as Serializer } from '../serializer';
4
+ import { Cache } from './cache';
5
+ import { ActivityType, Consumes } from '../../types/activity';
6
+ import { AppVID } from '../../types/app';
7
+ import { HookRule, HookSignal } from '../../types/hook';
8
+ import { HotMeshApp, HotMeshApps, HotMeshSettings } from '../../types/hotmesh';
9
+ import { SymbolSets, StringStringType, StringAnyType, Symbols } from '../../types/serializer';
10
+ import { IdsData, JobStatsRange, StatsType } from '../../types/stats';
11
+ import { Transitions } from '../../types/transition';
12
+ import { ReclaimedMessageType } from '../../types/stream';
13
+ interface AbstractRedisClient {
14
+ exec(): any;
15
+ }
16
+ declare abstract class StoreService<T, U extends AbstractRedisClient> {
17
+ redisClient: T;
18
+ cache: Cache;
19
+ serializer: Serializer;
20
+ namespace: string;
21
+ appId: string;
22
+ logger: ILogger;
23
+ commands: Record<string, string>;
24
+ abstract getMulti(): U;
25
+ abstract publish(keyType: KeyType.QUORUM, message: Record<string, any>, appId: string, engineId?: string): Promise<boolean>;
26
+ abstract xgroup(command: 'CREATE', key: string, groupName: string, id: string, mkStream?: 'MKSTREAM'): Promise<boolean>;
27
+ abstract xadd(key: string, id: string, messageId: string, messageValue: string, multi?: U): Promise<string | U>;
28
+ abstract xpending(key: string, group: string, start?: string, end?: string, count?: number, consumer?: string): Promise<[string, string, number, [string, number][]][] | [string, string, number, number] | unknown[]>;
29
+ abstract xclaim(key: string, group: string, consumer: string, minIdleTime: number, id: string, ...args: string[]): Promise<ReclaimedMessageType>;
30
+ abstract xack(key: string, group: string, id: string, multi?: U): Promise<number | U>;
31
+ abstract xdel(key: string, id: string, multi?: U): Promise<number | U>;
32
+ constructor(redisClient: T);
33
+ init(namespace: string, appId: string, logger: ILogger): Promise<HotMeshApps>;
34
+ isSuccessful(result: any): boolean;
35
+ zAdd(key: string, score: number | string, value: string | number, redisMulti?: U): Promise<any>;
36
+ zRangeByScoreWithScores(key: string, score: number | string, value: string | number): Promise<string | null>;
37
+ zRangeByScore(key: string, score: number | string, value: string | number): Promise<string | null>;
38
+ mintKey(type: KeyType, params: KeyStoreParams): string;
39
+ invalidateCache(): void;
40
+ reserveEngineId(engineId: string): Promise<boolean>;
41
+ getSettings(bCreate?: boolean): Promise<HotMeshSettings>;
42
+ setSettings(manifest: HotMeshSettings): Promise<any>;
43
+ reserveSymbolRange(target: string, size: number, type: 'JOB' | 'ACTIVITY'): Promise<[number, number, Symbols]>;
44
+ getSymbols(activityId: string): Promise<Symbols>;
45
+ addSymbols(activityId: string, symbols: Symbols): Promise<boolean>;
46
+ seedSymbols(target: string, type: 'JOB' | 'ACTIVITY', startIndex: number): StringStringType;
47
+ seedJobSymbols(startIndex: number): StringStringType;
48
+ seedActivitySymbols(startIndex: number, activityId: string): StringStringType;
49
+ getSymbolValues(): Promise<Symbols>;
50
+ addSymbolValues(symvals: Symbols): Promise<boolean>;
51
+ getSymbolKeys(symbolNames: string[]): Promise<SymbolSets>;
52
+ getApp(id: string, refresh?: boolean): Promise<HotMeshApp>;
53
+ setApp(id: string, version: string): Promise<HotMeshApp>;
54
+ activateAppVersion(id: string, version: string): Promise<boolean>;
55
+ registerAppVersion(appId: string, version: string): Promise<any>;
56
+ setStats(jobKey: string, jobId: string, dateTime: string, stats: StatsType, appVersion: AppVID, multi?: U): Promise<any>;
57
+ hGetAllResult(result: any): any;
58
+ getJobStats(jobKeys: string[]): Promise<JobStatsRange>;
59
+ getJobIds(indexKeys: string[], idRange: [number, number]): Promise<IdsData>;
60
+ setStatus(collationKeyStatus: number, jobId: string, appId: string, multi?: U): Promise<any>;
61
+ getStatus(jobId: string, appId: string): Promise<number>;
62
+ setState({ ...state }: StringAnyType, status: number | null, jobId: string, appId: string, symbolNames: string[], multi?: U): Promise<string>;
63
+ getState(jobId: string, consumes: Consumes): Promise<[StringAnyType, number] | undefined>;
64
+ collate(jobId: string, activityId: string, amount: number, multi?: U): Promise<number>;
65
+ setStateNX(jobId: string, appId: string): Promise<boolean>;
66
+ getSchema(activityId: string, appVersion: AppVID): Promise<ActivityType>;
67
+ getSchemas(appVersion: AppVID): Promise<Record<string, ActivityType>>;
68
+ setSchemas(schemas: Record<string, ActivityType>, appVersion: AppVID): Promise<any>;
69
+ setSubscriptions(subscriptions: Record<string, any>, appVersion: AppVID): Promise<boolean>;
70
+ getSubscriptions(appVersion: AppVID): Promise<Record<string, string>>;
71
+ getSubscription(topic: string, appVersion: AppVID): Promise<string | undefined>;
72
+ setTransitions(transitions: Record<string, any>, appVersion: AppVID): Promise<any>;
73
+ getTransitions(appVersion: AppVID): Promise<Transitions>;
74
+ setHookRules(hookRules: Record<string, HookRule[]>): Promise<any>;
75
+ getHookRules(): Promise<Record<string, HookRule[]>>;
76
+ setHookSignal(hook: HookSignal, multi?: U): Promise<any>;
77
+ getHookSignal(topic: string, resolved: string): Promise<string | undefined>;
78
+ deleteHookSignal(topic: string, resolved: string): Promise<number | undefined>;
79
+ addTaskQueues(keys: string[]): Promise<void>;
80
+ getActiveTaskQueue(): Promise<string | null>;
81
+ deleteProcessedTaskQueue(workItemKey: string, key: string, processedKey: string): Promise<void>;
82
+ processTaskQueue(sourceKey: string, destinationKey: string): Promise<any>;
83
+ expireJob(jobId: string, inSeconds: number): Promise<void>;
84
+ registerTimeHook(jobId: string, activityId: string, type: 'sleep' | 'expire' | 'cron', deletionTime: number, multi?: U): Promise<void>;
85
+ getNextTimeJob(listKey?: string): Promise<[listKey: string, jobId: string, activityId: string] | void>;
86
+ scrub(jobId: string): Promise<void>;
87
+ }
88
+ export { StoreService };