@hotmeshio/hotmesh 0.4.0 → 0.4.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 (283) hide show
  1. package/build/modules/enums.d.ts +110 -0
  2. package/build/modules/enums.js +134 -0
  3. package/build/modules/errors.d.ts +124 -0
  4. package/build/modules/errors.js +191 -0
  5. package/build/modules/key.d.ts +66 -0
  6. package/build/modules/key.js +190 -0
  7. package/build/modules/storage.d.ts +3 -0
  8. package/build/modules/storage.js +5 -0
  9. package/build/modules/utils.d.ts +119 -0
  10. package/build/modules/utils.js +374 -0
  11. package/build/package.json +1 -1
  12. package/build/services/activities/activity.d.ts +104 -0
  13. package/build/services/activities/activity.js +549 -0
  14. package/build/services/activities/await.d.ts +12 -0
  15. package/build/services/activities/await.js +114 -0
  16. package/build/services/activities/cycle.d.ts +19 -0
  17. package/build/services/activities/cycle.js +112 -0
  18. package/build/services/activities/hook.d.ts +27 -0
  19. package/build/services/activities/hook.js +168 -0
  20. package/build/services/activities/index.d.ts +19 -0
  21. package/build/services/activities/index.js +20 -0
  22. package/build/services/activities/interrupt.d.ts +16 -0
  23. package/build/services/activities/interrupt.js +158 -0
  24. package/build/services/activities/signal.d.ts +20 -0
  25. package/build/services/activities/signal.js +134 -0
  26. package/build/services/activities/trigger.d.ts +37 -0
  27. package/build/services/activities/trigger.js +246 -0
  28. package/build/services/activities/worker.d.ts +12 -0
  29. package/build/services/activities/worker.js +106 -0
  30. package/build/services/collator/index.d.ts +111 -0
  31. package/build/services/collator/index.js +293 -0
  32. package/build/services/compiler/deployer.d.ts +40 -0
  33. package/build/services/compiler/deployer.js +488 -0
  34. package/build/services/compiler/index.d.ts +32 -0
  35. package/build/services/compiler/index.js +112 -0
  36. package/build/services/compiler/validator.d.ts +34 -0
  37. package/build/services/compiler/validator.js +147 -0
  38. package/build/services/connector/factory.d.ts +22 -0
  39. package/build/services/connector/factory.js +99 -0
  40. package/build/services/connector/index.d.ts +30 -0
  41. package/build/services/connector/index.js +54 -0
  42. package/build/services/connector/providers/ioredis.d.ts +9 -0
  43. package/build/services/connector/providers/ioredis.js +26 -0
  44. package/build/services/connector/providers/nats.d.ts +9 -0
  45. package/build/services/connector/providers/nats.js +34 -0
  46. package/build/services/connector/providers/postgres.d.ts +20 -0
  47. package/build/services/connector/providers/postgres.js +102 -0
  48. package/build/services/connector/providers/redis.d.ts +9 -0
  49. package/build/services/connector/providers/redis.js +38 -0
  50. package/build/services/engine/index.d.ts +264 -0
  51. package/build/services/engine/index.js +761 -0
  52. package/build/services/exporter/index.d.ts +44 -0
  53. package/build/services/exporter/index.js +126 -0
  54. package/build/services/hotmesh/index.d.ts +483 -0
  55. package/build/services/hotmesh/index.js +622 -0
  56. package/build/services/logger/index.d.ts +16 -0
  57. package/build/services/logger/index.js +54 -0
  58. package/build/services/mapper/index.d.ts +28 -0
  59. package/build/services/mapper/index.js +81 -0
  60. package/build/services/memflow/client.d.ts +108 -0
  61. package/build/services/memflow/client.js +372 -0
  62. package/build/services/memflow/connection.d.ts +23 -0
  63. package/build/services/memflow/connection.js +33 -0
  64. package/build/services/memflow/context.d.ts +143 -0
  65. package/build/services/memflow/context.js +299 -0
  66. package/build/services/memflow/exporter.d.ts +51 -0
  67. package/build/services/memflow/exporter.js +215 -0
  68. package/build/services/memflow/handle.d.ts +90 -0
  69. package/build/services/memflow/handle.js +176 -0
  70. package/build/services/memflow/index.d.ts +116 -0
  71. package/build/services/memflow/index.js +122 -0
  72. package/build/services/memflow/schemas/factory.d.ts +29 -0
  73. package/build/services/memflow/schemas/factory.js +2492 -0
  74. package/build/services/memflow/search.d.ts +142 -0
  75. package/build/services/memflow/search.js +320 -0
  76. package/build/services/memflow/worker.d.ts +124 -0
  77. package/build/services/memflow/worker.js +514 -0
  78. package/build/services/memflow/workflow/all.d.ts +7 -0
  79. package/build/services/memflow/workflow/all.js +15 -0
  80. package/build/services/memflow/workflow/common.d.ts +20 -0
  81. package/build/services/memflow/workflow/common.js +47 -0
  82. package/build/services/memflow/workflow/context.d.ts +6 -0
  83. package/build/services/memflow/workflow/context.js +45 -0
  84. package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
  85. package/build/services/memflow/workflow/contextMethods.js +33 -0
  86. package/build/services/memflow/workflow/didRun.d.ts +7 -0
  87. package/build/services/memflow/workflow/didRun.js +22 -0
  88. package/build/services/memflow/workflow/emit.d.ts +11 -0
  89. package/build/services/memflow/workflow/emit.js +29 -0
  90. package/build/services/memflow/workflow/enrich.d.ts +9 -0
  91. package/build/services/memflow/workflow/enrich.js +17 -0
  92. package/build/services/memflow/workflow/execChild.d.ts +18 -0
  93. package/build/services/memflow/workflow/execChild.js +102 -0
  94. package/build/services/memflow/workflow/execHook.d.ts +65 -0
  95. package/build/services/memflow/workflow/execHook.js +73 -0
  96. package/build/services/memflow/workflow/hook.d.ts +9 -0
  97. package/build/services/memflow/workflow/hook.js +56 -0
  98. package/build/services/memflow/workflow/index.d.ts +74 -0
  99. package/build/services/memflow/workflow/index.js +87 -0
  100. package/build/services/memflow/workflow/interrupt.d.ts +9 -0
  101. package/build/services/memflow/workflow/interrupt.js +24 -0
  102. package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
  103. package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
  104. package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
  105. package/build/services/memflow/workflow/proxyActivities.js +97 -0
  106. package/build/services/memflow/workflow/random.d.ts +6 -0
  107. package/build/services/memflow/workflow/random.js +16 -0
  108. package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
  109. package/build/services/memflow/workflow/searchMethods.js +25 -0
  110. package/build/services/memflow/workflow/signal.d.ts +7 -0
  111. package/build/services/memflow/workflow/signal.js +28 -0
  112. package/build/services/memflow/workflow/sleepFor.d.ts +8 -0
  113. package/build/services/memflow/workflow/sleepFor.js +35 -0
  114. package/build/services/memflow/workflow/trace.d.ts +14 -0
  115. package/build/services/memflow/workflow/trace.js +33 -0
  116. package/build/services/memflow/workflow/waitFor.d.ts +8 -0
  117. package/build/services/memflow/workflow/waitFor.js +35 -0
  118. package/build/services/meshcall/index.d.ts +194 -0
  119. package/build/services/meshcall/index.js +452 -0
  120. package/build/services/meshcall/schemas/factory.d.ts +9 -0
  121. package/build/services/meshcall/schemas/factory.js +189 -0
  122. package/build/services/meshdata/index.d.ts +795 -0
  123. package/build/services/meshdata/index.js +1235 -0
  124. package/build/services/meshos/index.d.ts +293 -0
  125. package/build/services/meshos/index.js +547 -0
  126. package/build/services/pipe/functions/array.d.ts +17 -0
  127. package/build/services/pipe/functions/array.js +74 -0
  128. package/build/services/pipe/functions/bitwise.d.ts +9 -0
  129. package/build/services/pipe/functions/bitwise.js +24 -0
  130. package/build/services/pipe/functions/conditional.d.ts +13 -0
  131. package/build/services/pipe/functions/conditional.js +36 -0
  132. package/build/services/pipe/functions/cron.d.ts +12 -0
  133. package/build/services/pipe/functions/cron.js +40 -0
  134. package/build/services/pipe/functions/date.d.ts +58 -0
  135. package/build/services/pipe/functions/date.js +171 -0
  136. package/build/services/pipe/functions/index.d.ts +29 -0
  137. package/build/services/pipe/functions/index.js +30 -0
  138. package/build/services/pipe/functions/json.d.ts +5 -0
  139. package/build/services/pipe/functions/json.js +12 -0
  140. package/build/services/pipe/functions/logical.d.ts +5 -0
  141. package/build/services/pipe/functions/logical.js +12 -0
  142. package/build/services/pipe/functions/math.d.ts +42 -0
  143. package/build/services/pipe/functions/math.js +184 -0
  144. package/build/services/pipe/functions/number.d.ts +21 -0
  145. package/build/services/pipe/functions/number.js +60 -0
  146. package/build/services/pipe/functions/object.d.ts +25 -0
  147. package/build/services/pipe/functions/object.js +81 -0
  148. package/build/services/pipe/functions/string.d.ts +23 -0
  149. package/build/services/pipe/functions/string.js +69 -0
  150. package/build/services/pipe/functions/symbol.d.ts +12 -0
  151. package/build/services/pipe/functions/symbol.js +33 -0
  152. package/build/services/pipe/functions/unary.d.ts +7 -0
  153. package/build/services/pipe/functions/unary.js +18 -0
  154. package/build/services/pipe/index.d.ts +48 -0
  155. package/build/services/pipe/index.js +242 -0
  156. package/build/services/quorum/index.d.ts +90 -0
  157. package/build/services/quorum/index.js +263 -0
  158. package/build/services/reporter/index.d.ts +50 -0
  159. package/build/services/reporter/index.js +348 -0
  160. package/build/services/router/config/index.d.ts +11 -0
  161. package/build/services/router/config/index.js +36 -0
  162. package/build/services/router/consumption/index.d.ts +34 -0
  163. package/build/services/router/consumption/index.js +395 -0
  164. package/build/services/router/error-handling/index.d.ts +8 -0
  165. package/build/services/router/error-handling/index.js +98 -0
  166. package/build/services/router/index.d.ts +57 -0
  167. package/build/services/router/index.js +121 -0
  168. package/build/services/router/lifecycle/index.d.ts +27 -0
  169. package/build/services/router/lifecycle/index.js +80 -0
  170. package/build/services/router/telemetry/index.d.ts +11 -0
  171. package/build/services/router/telemetry/index.js +32 -0
  172. package/build/services/router/throttling/index.d.ts +23 -0
  173. package/build/services/router/throttling/index.js +76 -0
  174. package/build/services/search/factory.d.ts +7 -0
  175. package/build/services/search/factory.js +24 -0
  176. package/build/services/search/index.d.ts +23 -0
  177. package/build/services/search/index.js +10 -0
  178. package/build/services/search/providers/postgres/postgres.d.ts +25 -0
  179. package/build/services/search/providers/postgres/postgres.js +149 -0
  180. package/build/services/search/providers/redis/ioredis.d.ts +19 -0
  181. package/build/services/search/providers/redis/ioredis.js +121 -0
  182. package/build/services/search/providers/redis/redis.d.ts +19 -0
  183. package/build/services/search/providers/redis/redis.js +134 -0
  184. package/build/services/serializer/index.d.ts +42 -0
  185. package/build/services/serializer/index.js +282 -0
  186. package/build/services/store/cache.d.ts +67 -0
  187. package/build/services/store/cache.js +128 -0
  188. package/build/services/store/factory.d.ts +8 -0
  189. package/build/services/store/factory.js +24 -0
  190. package/build/services/store/index.d.ts +89 -0
  191. package/build/services/store/index.js +9 -0
  192. package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
  193. package/build/services/store/providers/postgres/kvsql.js +198 -0
  194. package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
  195. package/build/services/store/providers/postgres/kvtables.js +441 -0
  196. package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
  197. package/build/services/store/providers/postgres/kvtransaction.js +248 -0
  198. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
  199. package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
  200. package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
  201. package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
  202. package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
  203. package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
  204. package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
  205. package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
  206. package/build/services/store/providers/postgres/postgres.d.ts +145 -0
  207. package/build/services/store/providers/postgres/postgres.js +1036 -0
  208. package/build/services/store/providers/redis/_base.d.ts +137 -0
  209. package/build/services/store/providers/redis/_base.js +980 -0
  210. package/build/services/store/providers/redis/ioredis.d.ts +20 -0
  211. package/build/services/store/providers/redis/ioredis.js +180 -0
  212. package/build/services/store/providers/redis/redis.d.ts +18 -0
  213. package/build/services/store/providers/redis/redis.js +199 -0
  214. package/build/services/store/providers/store-initializable.d.ts +5 -0
  215. package/build/services/store/providers/store-initializable.js +2 -0
  216. package/build/services/stream/factory.d.ts +8 -0
  217. package/build/services/stream/factory.js +37 -0
  218. package/build/services/stream/index.d.ts +69 -0
  219. package/build/services/stream/index.js +11 -0
  220. package/build/services/stream/providers/nats/nats.d.ts +60 -0
  221. package/build/services/stream/providers/nats/nats.js +225 -0
  222. package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
  223. package/build/services/stream/providers/postgres/kvtables.js +146 -0
  224. package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
  225. package/build/services/stream/providers/postgres/postgres.js +519 -0
  226. package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
  227. package/build/services/stream/providers/redis/ioredis.js +272 -0
  228. package/build/services/stream/providers/redis/redis.d.ts +61 -0
  229. package/build/services/stream/providers/redis/redis.js +305 -0
  230. package/build/services/stream/providers/stream-initializable.d.ts +4 -0
  231. package/build/services/stream/providers/stream-initializable.js +2 -0
  232. package/build/services/sub/factory.d.ts +7 -0
  233. package/build/services/sub/factory.js +29 -0
  234. package/build/services/sub/index.d.ts +22 -0
  235. package/build/services/sub/index.js +10 -0
  236. package/build/services/sub/providers/nats/nats.d.ts +19 -0
  237. package/build/services/sub/providers/nats/nats.js +105 -0
  238. package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
  239. package/build/services/sub/providers/postgres/postgres.js +92 -0
  240. package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
  241. package/build/services/sub/providers/redis/ioredis.js +81 -0
  242. package/build/services/sub/providers/redis/redis.d.ts +17 -0
  243. package/build/services/sub/providers/redis/redis.js +72 -0
  244. package/build/services/task/index.d.ts +36 -0
  245. package/build/services/task/index.js +206 -0
  246. package/build/services/telemetry/index.d.ts +52 -0
  247. package/build/services/telemetry/index.js +306 -0
  248. package/build/services/worker/index.d.ts +77 -0
  249. package/build/services/worker/index.js +197 -0
  250. package/package.json +1 -1
  251. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  252. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  253. package/typedoc.json +0 -47
  254. package/types/activity.ts +0 -268
  255. package/types/app.ts +0 -20
  256. package/types/async.ts +0 -6
  257. package/types/cache.ts +0 -1
  258. package/types/collator.ts +0 -9
  259. package/types/error.ts +0 -56
  260. package/types/exporter.ts +0 -102
  261. package/types/hook.ts +0 -44
  262. package/types/hotmesh.ts +0 -314
  263. package/types/index.ts +0 -306
  264. package/types/job.ts +0 -233
  265. package/types/logger.ts +0 -8
  266. package/types/manifest.ts +0 -70
  267. package/types/map.ts +0 -5
  268. package/types/memflow.ts +0 -645
  269. package/types/meshcall.ts +0 -235
  270. package/types/meshdata.ts +0 -278
  271. package/types/ms.d.ts +0 -7
  272. package/types/nats.ts +0 -270
  273. package/types/pipe.ts +0 -90
  274. package/types/postgres.ts +0 -114
  275. package/types/provider.ts +0 -161
  276. package/types/quorum.ts +0 -167
  277. package/types/redis.ts +0 -404
  278. package/types/serializer.ts +0 -40
  279. package/types/stats.ts +0 -117
  280. package/types/stream.ts +0 -231
  281. package/types/task.ts +0 -7
  282. package/types/telemetry.ts +0 -16
  283. package/types/transition.ts +0 -20
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VALSEP = exports.WEBSEP = exports.TYPSEP = exports.KEYSEP = exports.HMNS = exports.KeyType = exports.KeyService = void 0;
4
+ const hotmesh_1 = require("../types/hotmesh");
5
+ Object.defineProperty(exports, "KeyType", { enumerable: true, get: function () { return hotmesh_1.KeyType; } });
6
+ /**
7
+ * Keys
8
+ *
9
+ * hmsh -> {hash} hotmesh config {version: "0.0.1", namespace: "hmsh"}
10
+ * hmsh:a:<appid> -> {hash} app profile { "id": "appid", "version": "2", "versions/1": "GMT", "versions/2": "GMT"}
11
+ * hmsh:<appid>:r: -> {hash} throttle rates {':': '23', 'topic.thing': '555'} => {':i': 'all', 'topic.thing': '555seconds'}
12
+ * hmsh:<appid>:w: -> {zset} work items/tasks an engine must do like garbage collect or hook a set of matching records (hookAll)
13
+ * hmsh:<appid>:t: -> {zset} an ordered set of list (work lists) ids
14
+ * hmsh:<appid>:t:<timeValue?> -> {list} a worklist of `jobId+activityId` items that should be awakened
15
+ * hmsh:<appid>:q: -> {hash} quorum-wide messages
16
+ * hmsh:<appid>:q:<ngnid> -> {hash} engine-targeted messages (targeted quorum-oriented message)
17
+ * hmsh:<appid>:j:<jobid> -> {hash} job data
18
+ * hmsh:<appid>:s:<jobkey>:<dateTime> -> {hash} job stats (general)
19
+ * hmsh:<appid>:s:<jobkey>:<dateTime>:mdn:<field/path>:<fieldvalue> -> {zset} job stats (median)
20
+ * hmsh:<appid>:s:<jobkey>:<dateTime>:index:<field/path>:<fieldvalue> -> {list} job stats (index of jobid[])
21
+ * hmsh:<appid>:v:<version>:activities -> {hash} schemas [cache]
22
+ * hmsh:<appid>:v:<version>:transitions -> {hash} transitions [cache]
23
+ * hmsh:<appid>:v:<version>:subscriptions -> {hash} subscriptions [cache]
24
+ * hmsh:<appid>:x: -> {xstream} when an engine is sent or reads a buffered task (engines read from their custom topic)
25
+ * hmsh:<appid>:x:<topic> -> {xstream} when a worker is sent or reads a buffered task (workers read from their custom topic)
26
+ * hmsh:<appid>:hooks -> {hash} hook patterns/rules; set at compile time
27
+ * hmsh:<appid>:signals -> {string} dynamic hook signals (hget/hdel); expirable
28
+ * hmsh:<appid>:sym:keys: -> {hash} list of symbol ranges and :cursor assigned at version deploy time for job keys
29
+ * hmsh:<appid>:sym:keys:<activityid|$subscribes> -> {hash} list of symbols based upon schema enums (initially) and adaptively optimized (later) during runtime; if '$subscribes' is used as the activityid, it is a top-level `job` symbol set (for job keys)
30
+ * hmsh:<appid>:sym:vals: -> {hash} list of symbols for job values across all app versions
31
+ */
32
+ const HMNS = 'hmsh';
33
+ exports.HMNS = HMNS;
34
+ const KEYSEP = ':'; // default delimiter for keys
35
+ exports.KEYSEP = KEYSEP;
36
+ const VALSEP = '::'; // default delimiter for vals
37
+ exports.VALSEP = VALSEP;
38
+ const WEBSEP = '::'; // default delimiter for webhook vals
39
+ exports.WEBSEP = WEBSEP;
40
+ const TYPSEP = '::'; // delimiter for ZSET task typing (how should a list be used?)
41
+ exports.TYPSEP = TYPSEP;
42
+ class KeyService {
43
+ /**
44
+ * Returns a key that can be used to access a value in the key/value store
45
+ * appropriate for the given key type; the keys have an implicit hierarchy
46
+ * and are used to organize data in the store in a tree-like structure
47
+ * via the use of colons as separators.
48
+ * @param namespace
49
+ * @param keyType
50
+ * @param params
51
+ * @returns {string}
52
+ */
53
+ static mintKey(namespace, keyType, params) {
54
+ switch (keyType) {
55
+ case hotmesh_1.KeyType.HOTMESH:
56
+ return namespace;
57
+ case hotmesh_1.KeyType.THROTTLE_RATE:
58
+ return `${namespace}:${params.appId}:r:`;
59
+ case hotmesh_1.KeyType.WORK_ITEMS:
60
+ return `${namespace}:${params.appId}:w:${params.scoutType || ''}`;
61
+ case hotmesh_1.KeyType.TIME_RANGE:
62
+ return `${namespace}:${params.appId}:t:${params.timeValue || ''}`;
63
+ case hotmesh_1.KeyType.APP:
64
+ return `${namespace}:a:${params.appId || ''}`;
65
+ case hotmesh_1.KeyType.QUORUM:
66
+ return `${namespace}:${params.appId}:q:${params.engineId || ''}`;
67
+ case hotmesh_1.KeyType.JOB_STATE:
68
+ return `${namespace}:${params.appId}:j:${params.jobId}`;
69
+ case hotmesh_1.KeyType.JOB_DEPENDENTS:
70
+ return `${namespace}:${params.appId}:d:${params.jobId}`;
71
+ case hotmesh_1.KeyType.JOB_STATS_GENERAL:
72
+ return `${namespace}:${params.appId}:s:${params.jobKey}:${params.dateTime}`;
73
+ case hotmesh_1.KeyType.JOB_STATS_MEDIAN:
74
+ return `${namespace}:${params.appId}:s:${params.jobKey}:${params.dateTime}:${params.facet}`;
75
+ case hotmesh_1.KeyType.JOB_STATS_INDEX:
76
+ return `${namespace}:${params.appId}:s:${params.jobKey}:${params.dateTime}:${params.facet}`;
77
+ case hotmesh_1.KeyType.SCHEMAS:
78
+ return `${namespace}:${params.appId}:v:${params.appVersion}:schemas`;
79
+ case hotmesh_1.KeyType.SUBSCRIPTIONS:
80
+ return `${namespace}:${params.appId}:v:${params.appVersion}:subscriptions`;
81
+ case hotmesh_1.KeyType.SUBSCRIPTION_PATTERNS:
82
+ return `${namespace}:${params.appId}:v:${params.appVersion}:transitions`;
83
+ case hotmesh_1.KeyType.HOOKS:
84
+ return `${namespace}:${params.appId}:hooks`;
85
+ case hotmesh_1.KeyType.SIGNALS:
86
+ return `${namespace}:${params.appId}:signals`;
87
+ case hotmesh_1.KeyType.SYMKEYS:
88
+ return `${namespace}:${params.appId}:sym:keys:${params.activityId || ''}`;
89
+ case hotmesh_1.KeyType.SYMVALS:
90
+ return `${namespace}:${params.appId}:sym:vals:`;
91
+ case hotmesh_1.KeyType.STREAMS:
92
+ return `${namespace}:${params.appId || ''}:x:${params.topic || ''}`;
93
+ default:
94
+ throw new Error('Invalid key type.');
95
+ }
96
+ }
97
+ /**
98
+ * Extracts the parts of a given key string, safely handling cases where
99
+ * the 'id' portion may contain additional colons.
100
+ * @param key - The key to parse.
101
+ * @returns An object with the parsed key parts.
102
+ */
103
+ static parseKey(key) {
104
+ const [namespace, appId, entity, ...rest] = key.split(KEYSEP);
105
+ const id = rest.join(KEYSEP) || ''; // Join remaining parts to reconstruct the id
106
+ return {
107
+ namespace,
108
+ app: entity === 'a' ? appId : undefined,
109
+ entity,
110
+ id,
111
+ };
112
+ }
113
+ /**
114
+ * Reconstructs a key string from its parts.
115
+ * @param parts - An object with the key parts.
116
+ * @returns The reconstructed key string.
117
+ */
118
+ static reconstituteKey(parts) {
119
+ const { namespace, app, entity, id } = parts;
120
+ return `${namespace}${KEYSEP}${app}${KEYSEP}${entity}${KEYSEP}${id || ''}`;
121
+ }
122
+ /**
123
+ * Resolves an entity type abbreviation to a table-friendly name.
124
+ * @param abbreviation - The abbreviated entity type.
125
+ * @returns The long-form entity name.
126
+ */
127
+ static resolveEntityType(abbreviation, id = '') {
128
+ switch (abbreviation) {
129
+ case 'a':
130
+ return 'applications';
131
+ case 'r':
132
+ return 'throttles';
133
+ case 'w':
134
+ return id === '' ? 'task_priorities' : 'roles';
135
+ case 't':
136
+ return id === '' ? 'task_schedules' : 'task_lists';
137
+ case 'q':
138
+ return 'events';
139
+ case 'j':
140
+ return 'jobs';
141
+ case 's':
142
+ return 'stats';
143
+ case 'v':
144
+ return 'versions';
145
+ case 'x':
146
+ return id === '' ? 'streams' : 'stream_topics';
147
+ case 'hooks':
148
+ return 'signal_patterns';
149
+ case 'signals':
150
+ return 'signal_registry';
151
+ case 'sym':
152
+ return 'symbols';
153
+ default:
154
+ return 'unknown_entity';
155
+ }
156
+ }
157
+ static resolveAbbreviation(entity) {
158
+ switch (entity) {
159
+ case 'applications':
160
+ return 'a';
161
+ case 'throttles':
162
+ return 'r';
163
+ case 'roles':
164
+ return 'w';
165
+ case 'task_schedules':
166
+ return 't';
167
+ case 'task_lists':
168
+ return 't';
169
+ case 'events':
170
+ return 'q';
171
+ case 'jobs':
172
+ return 'j';
173
+ case 'stats':
174
+ return 's';
175
+ case 'versions':
176
+ return 'v';
177
+ case 'streams':
178
+ return 'x';
179
+ case 'signal_patterns':
180
+ return 'hooks';
181
+ case 'signal_registry':
182
+ return 'signals';
183
+ case 'symbols':
184
+ return 'sym';
185
+ default:
186
+ return 'unknown_entity';
187
+ }
188
+ }
189
+ }
190
+ exports.KeyService = KeyService;
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ import { AsyncLocalStorage } from 'async_hooks';
3
+ export declare const asyncLocalStorage: AsyncLocalStorage<Map<string, any>>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asyncLocalStorage = void 0;
4
+ const async_hooks_1 = require("async_hooks");
5
+ exports.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
@@ -0,0 +1,119 @@
1
+ /// <reference types="node" />
2
+ import { StoreService } from '../services/store';
3
+ import { AppSubscriptions, AppTransitions, AppVID } from '../types/app';
4
+ import { ProviderClient, ProviderConfig, ProviderTransaction, Providers, ProvidersConfig } from '../types/provider';
5
+ import { StringAnyType } from '../types/serializer';
6
+ import { StreamCode, StreamData, StreamStatus } from '../types/stream';
7
+ import { SystemHealth } from '../types/quorum';
8
+ /**
9
+ * @private
10
+ */
11
+ export declare const hashOptions: (options: any) => string;
12
+ export declare function getSystemHealth(): Promise<SystemHealth>;
13
+ export declare function deepCopy<T>(obj: T): T;
14
+ export declare function deterministicRandom(seed: number): number;
15
+ export declare function guid(size?: number): string;
16
+ export declare function sleepFor(ms: number): Promise<void>;
17
+ export declare function sleepImmediate(): Promise<void>;
18
+ export declare function XSleepFor(ms: number): {
19
+ promise: Promise<unknown>;
20
+ timerId: NodeJS.Timeout;
21
+ };
22
+ /**
23
+ * Identies the provider type based on the provider object. Customers may
24
+ * explicitly set the provider type in the configuration. But this is a
25
+ * convenience method to automatically identify the provider type.
26
+ * @private
27
+ */
28
+ export declare function identifyProvider(provider: any): Providers | null;
29
+ /**
30
+ * @private
31
+ */
32
+ export declare const polyfill: {
33
+ /**
34
+ * `redis` is deprecated; `connection` is the generic replacement
35
+ */
36
+ providerConfig(obj: any): any;
37
+ /**
38
+ * NOTE: `redisClass and redisOptions` input parameters are deprecated; use `connection` for all configuration inputs
39
+ */
40
+ meshDataConfig(obj: {
41
+ connection?: Partial<ProviderConfig | ProvidersConfig>;
42
+ redisClass?: any;
43
+ redisOptions?: StringAnyType;
44
+ }): Partial<ProviderConfig> | Partial<ProvidersConfig>;
45
+ };
46
+ /**
47
+ * @private
48
+ */
49
+ export declare function matchesStatusCode(code: StreamCode, pattern: string | RegExp): boolean;
50
+ /**
51
+ * @private
52
+ */
53
+ export declare function matchesStatus(status: StreamStatus, targetStatus: StreamStatus): boolean;
54
+ /**
55
+ * @private
56
+ */
57
+ export declare function findTopKey(obj: AppTransitions, input: string): string | null;
58
+ /**
59
+ * @private
60
+ */
61
+ export declare function findSubscriptionForTrigger(obj: AppSubscriptions, value: string): string | null;
62
+ /**
63
+ * Get the subscription topic for the flow to which activityId belongs.
64
+ * @private
65
+ */
66
+ export declare function getSubscriptionTopic(activityId: string, store: StoreService<ProviderClient, ProviderTransaction>, appVID: AppVID): Promise<string | undefined>;
67
+ /**
68
+ * returns the 12-digit format of the iso timestamp (e.g, 202101010000); returns
69
+ * an empty string if overridden by the user to not segment by time (infinity).
70
+ * @private
71
+ */
72
+ export declare function getTimeSeries(granularity: string): string;
73
+ /**
74
+ * @private
75
+ */
76
+ export declare function formatISODate(input: Date | string): string;
77
+ /**
78
+ * @private
79
+ */
80
+ export declare function getSymKey(number: number): string;
81
+ /**
82
+ * @private
83
+ */
84
+ export declare function getSymVal(number: number): string;
85
+ /**
86
+ * @private
87
+ */
88
+ export declare function getIndexedHash<T>(hash: T, target: string): [number, T];
89
+ /**
90
+ * @private
91
+ */
92
+ export declare function getValueByPath(obj: {
93
+ [key: string]: any;
94
+ }, path: string): any;
95
+ /**
96
+ * @private
97
+ */
98
+ export declare function restoreHierarchy(obj: StringAnyType): StringAnyType;
99
+ /**
100
+ * @private
101
+ */
102
+ export declare function isValidCron(cronExpression: string): boolean;
103
+ /**
104
+ * Returns the number of seconds for a string using the milliseconds format
105
+ * used by the `ms` npm package as the input.
106
+ */
107
+ export declare const s: (input: string) => number;
108
+ /**
109
+ * @private
110
+ */
111
+ export declare const parseStreamMessage: (message: string) => StreamData;
112
+ /**
113
+ * @private
114
+ */
115
+ export declare const isStreamMessage: (result: any) => boolean;
116
+ /**
117
+ * Transforms an array of arrays to an array of objects.
118
+ */
119
+ export declare const arrayToHash: (response: [number, ...Array<string | string[]>]) => Record<string, string>[];
@@ -0,0 +1,374 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.arrayToHash = exports.isStreamMessage = exports.parseStreamMessage = exports.s = exports.isValidCron = exports.restoreHierarchy = exports.getValueByPath = exports.getIndexedHash = exports.getSymVal = exports.getSymKey = exports.formatISODate = exports.getTimeSeries = exports.getSubscriptionTopic = exports.findSubscriptionForTrigger = exports.findTopKey = exports.matchesStatus = exports.matchesStatusCode = exports.polyfill = exports.identifyProvider = exports.XSleepFor = exports.sleepImmediate = exports.sleepFor = exports.guid = exports.deterministicRandom = exports.deepCopy = exports.getSystemHealth = exports.hashOptions = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ const crypto_1 = require("crypto");
9
+ const nanoid_1 = require("nanoid");
10
+ const ms_1 = __importDefault(require("ms"));
11
+ const logger_1 = require("../services/logger");
12
+ const enums_1 = require("./enums");
13
+ const logger = new logger_1.LoggerService('hotmesh', 'utils');
14
+ /**
15
+ * @private
16
+ */
17
+ const hashOptions = (options) => {
18
+ const str = JSON.stringify(options);
19
+ return (0, crypto_1.createHash)('sha256').update(str).digest('hex');
20
+ };
21
+ exports.hashOptions = hashOptions;
22
+ async function getSystemHealth() {
23
+ const totalMemory = os_1.default.totalmem();
24
+ const freeMemory = os_1.default.freemem();
25
+ const usedMemory = totalMemory - freeMemory;
26
+ const systemHealth = {
27
+ TotalMemoryGB: `${(totalMemory / 1024 / 1024 / 1024).toFixed(2)} GB`,
28
+ FreeMemoryGB: `${(freeMemory / 1024 / 1024 / 1024).toFixed(2)} GB`,
29
+ UsedMemoryGB: `${(usedMemory / 1024 / 1024 / 1024).toFixed(2)} GB`,
30
+ CPULoad: [],
31
+ NetworkStats: [],
32
+ };
33
+ return systemHealth;
34
+ }
35
+ exports.getSystemHealth = getSystemHealth;
36
+ function deepCopy(obj) {
37
+ return JSON.parse(JSON.stringify(obj));
38
+ }
39
+ exports.deepCopy = deepCopy;
40
+ function deterministicRandom(seed) {
41
+ const x = Math.sin(seed) * 10000;
42
+ return x - Math.floor(x);
43
+ }
44
+ exports.deterministicRandom = deterministicRandom;
45
+ function guid(size = enums_1.HMSH_GUID_SIZE) {
46
+ return `H` + (0, nanoid_1.nanoid)(size);
47
+ }
48
+ exports.guid = guid;
49
+ async function sleepFor(ms) {
50
+ return new Promise((resolve) => setTimeout(resolve, ms));
51
+ }
52
+ exports.sleepFor = sleepFor;
53
+ function sleepImmediate() {
54
+ return new Promise((resolve) => setImmediate(resolve));
55
+ }
56
+ exports.sleepImmediate = sleepImmediate;
57
+ function XSleepFor(ms) {
58
+ //can be interrupted with `clearTimeout`
59
+ let timerId;
60
+ const promise = new Promise((resolve) => {
61
+ timerId = setTimeout(resolve, ms);
62
+ });
63
+ return { promise, timerId };
64
+ }
65
+ exports.XSleepFor = XSleepFor;
66
+ /**
67
+ * Identies the provider type based on the provider object. Customers may
68
+ * explicitly set the provider type in the configuration. But this is a
69
+ * convenience method to automatically identify the provider type.
70
+ * @private
71
+ */
72
+ function identifyProvider(provider) {
73
+ const prototype = Object.getPrototypeOf(provider);
74
+ if (provider.Query?.prototype ||
75
+ Object.keys(provider).includes('database') ||
76
+ prototype.name === 'Pool') {
77
+ return 'postgres';
78
+ }
79
+ else if (provider.toString().toLowerCase().includes('nats')) {
80
+ return 'nats';
81
+ }
82
+ else if ('defineCommand' in prototype ||
83
+ Object.keys(prototype).includes('multi')) {
84
+ return 'ioredis';
85
+ }
86
+ else if (Object.keys(prototype).includes('Multi')) {
87
+ return 'redis';
88
+ }
89
+ if (provider.constructor) {
90
+ if (provider.constructor.name === 'Redis' ||
91
+ provider.constructor.name === 'EventEmitter') {
92
+ if ('hset' in provider) {
93
+ return 'ioredis';
94
+ }
95
+ }
96
+ else if (provider.constructor.name === 'ProviderClient' ||
97
+ provider.constructor.name === 'Commander') {
98
+ if ('HSET' in provider) {
99
+ return 'redis';
100
+ }
101
+ }
102
+ }
103
+ let type = null;
104
+ if (Object.keys(provider).includes('connection') ||
105
+ !isNaN(provider.totalCount) && !isNaN(provider.idleCount)) {
106
+ type = 'postgres';
107
+ }
108
+ else if (Object.keys(provider).includes('Pipeline')) {
109
+ type = 'ioredis';
110
+ }
111
+ else if (Object.keys(provider).includes('createClient')) {
112
+ type = 'redis';
113
+ }
114
+ else if (prototype.constructor.toString().includes('NatsConnectionImpl')) {
115
+ type = 'nats';
116
+ }
117
+ return type;
118
+ }
119
+ exports.identifyProvider = identifyProvider;
120
+ /**
121
+ * @private
122
+ */
123
+ exports.polyfill = {
124
+ /**
125
+ * `redis` is deprecated; `connection` is the generic replacement
126
+ */
127
+ providerConfig(obj) {
128
+ return obj?.connection ?? obj?.redis ?? obj?.connections;
129
+ },
130
+ /**
131
+ * NOTE: `redisClass and redisOptions` input parameters are deprecated; use `connection` for all configuration inputs
132
+ */
133
+ meshDataConfig(obj) {
134
+ return { ...obj.connection };
135
+ },
136
+ };
137
+ /**
138
+ * @private
139
+ */
140
+ function matchesStatusCode(code, pattern) {
141
+ if (typeof pattern === 'string') {
142
+ // Convert '*' wildcard to its regex equivalent (\d)
143
+ const regexPattern = `^${pattern.replace(/\*/g, '\\d')}$`;
144
+ return new RegExp(regexPattern).test(code.toString());
145
+ }
146
+ return pattern.test(code.toString());
147
+ }
148
+ exports.matchesStatusCode = matchesStatusCode;
149
+ /**
150
+ * @private
151
+ */
152
+ function matchesStatus(status, targetStatus) {
153
+ return status === targetStatus;
154
+ }
155
+ exports.matchesStatus = matchesStatus;
156
+ /**
157
+ * @private
158
+ */
159
+ function findTopKey(obj, input) {
160
+ for (const [key, value] of Object.entries(obj)) {
161
+ if (value.hasOwnProperty(input)) {
162
+ const parentKey = findTopKey(obj, key.replace(/^\./, ''));
163
+ return (parentKey || key).replace(/^\./, '');
164
+ }
165
+ }
166
+ return null;
167
+ }
168
+ exports.findTopKey = findTopKey;
169
+ /**
170
+ * @private
171
+ */
172
+ function findSubscriptionForTrigger(obj, value) {
173
+ for (const [key, itemValue] of Object.entries(obj)) {
174
+ if (itemValue === value) {
175
+ return key;
176
+ }
177
+ }
178
+ return null;
179
+ }
180
+ exports.findSubscriptionForTrigger = findSubscriptionForTrigger;
181
+ /**
182
+ * Get the subscription topic for the flow to which activityId belongs.
183
+ * @private
184
+ */
185
+ async function getSubscriptionTopic(activityId, store, appVID) {
186
+ const appTransitions = await store.getTransitions(appVID);
187
+ const appSubscriptions = await store.getSubscriptions(appVID);
188
+ const triggerId = findTopKey(appTransitions, activityId);
189
+ const topic = findSubscriptionForTrigger(appSubscriptions, triggerId);
190
+ return topic;
191
+ }
192
+ exports.getSubscriptionTopic = getSubscriptionTopic;
193
+ /**
194
+ * returns the 12-digit format of the iso timestamp (e.g, 202101010000); returns
195
+ * an empty string if overridden by the user to not segment by time (infinity).
196
+ * @private
197
+ */
198
+ function getTimeSeries(granularity) {
199
+ if (granularity.toString() === 'infinity') {
200
+ return '0';
201
+ }
202
+ const now = new Date();
203
+ const granularityUnit = granularity.slice(-1);
204
+ const granularityValue = parseInt(granularity.slice(0, -1), 10);
205
+ if (granularityUnit === 'm') {
206
+ const minute = Math.floor(now.getMinutes() / granularityValue) * granularityValue;
207
+ now.setUTCMinutes(minute, 0, 0);
208
+ }
209
+ else if (granularityUnit === 'h') {
210
+ now.setUTCMinutes(0, 0, 0);
211
+ }
212
+ return now
213
+ .toISOString()
214
+ .replace(/:\d\d\..+|-|T/g, '')
215
+ .replace(':', '');
216
+ }
217
+ exports.getTimeSeries = getTimeSeries;
218
+ /**
219
+ * @private
220
+ */
221
+ function formatISODate(input) {
222
+ const date = input instanceof Date ? input : new Date(input);
223
+ return date.toISOString().replace(/[:TZ-]/g, '');
224
+ }
225
+ exports.formatISODate = formatISODate;
226
+ /**
227
+ * @private
228
+ */
229
+ function getSymKey(number) {
230
+ const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
231
+ const base = alphabet.length;
232
+ if (number < 0 || number >= Math.pow(base, 3)) {
233
+ throw new Error('Number out of range');
234
+ }
235
+ const [q1, r1] = divmod(number, base);
236
+ const [q2, r2] = divmod(q1, base);
237
+ return alphabet[q2] + alphabet[r1] + alphabet[r2];
238
+ }
239
+ exports.getSymKey = getSymKey;
240
+ /**
241
+ * @private
242
+ */
243
+ function getSymVal(number) {
244
+ const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
245
+ const base = alphabet.length;
246
+ if (number < 0 || number >= Math.pow(base, 2)) {
247
+ throw new Error('Number out of range');
248
+ }
249
+ const [q, r] = divmod(number, base);
250
+ return alphabet[q] + alphabet[r];
251
+ }
252
+ exports.getSymVal = getSymVal;
253
+ /**
254
+ * @private
255
+ */
256
+ function divmod(m, n) {
257
+ return [Math.floor(m / n), m % n];
258
+ }
259
+ /**
260
+ * @private
261
+ */
262
+ function getIndexedHash(hash, target) {
263
+ const index = hash[target] || 0;
264
+ const newHash = { ...hash };
265
+ delete newHash[target];
266
+ return [index, newHash];
267
+ }
268
+ exports.getIndexedHash = getIndexedHash;
269
+ /**
270
+ * @private
271
+ */
272
+ function getValueByPath(obj, path) {
273
+ const pathParts = path.split('/');
274
+ let currentValue = obj;
275
+ for (const part of pathParts) {
276
+ if (currentValue[part] !== undefined) {
277
+ currentValue = currentValue[part];
278
+ }
279
+ else {
280
+ return undefined;
281
+ }
282
+ }
283
+ return currentValue;
284
+ }
285
+ exports.getValueByPath = getValueByPath;
286
+ /**
287
+ * @private
288
+ */
289
+ function restoreHierarchy(obj) {
290
+ const result = {};
291
+ for (const key in obj) {
292
+ if (obj[key] === undefined)
293
+ continue;
294
+ const keys = key.split('/');
295
+ let current = result;
296
+ for (let i = 0; i < keys.length; i++) {
297
+ if (i === keys.length - 1) {
298
+ current[keys[i]] = obj[key];
299
+ }
300
+ else {
301
+ current[keys[i]] = current[keys[i]] || {};
302
+ current = current[keys[i]];
303
+ }
304
+ }
305
+ }
306
+ return result;
307
+ }
308
+ exports.restoreHierarchy = restoreHierarchy;
309
+ /**
310
+ * @private
311
+ */
312
+ function isValidCron(cronExpression) {
313
+ const cronRegex = /^(\*|([0-5]?\d)) (\*|([01]?\d|2[0-3])) (\*|([12]?\d|3[01])) (\*|([1-9]|1[0-2])) (\*|([0-6](?:-[0-6])?(?:,[0-6])?))$/;
314
+ return cronRegex.test(cronExpression);
315
+ }
316
+ exports.isValidCron = isValidCron;
317
+ /**
318
+ * Returns the number of seconds for a string using the milliseconds format
319
+ * used by the `ms` npm package as the input.
320
+ */
321
+ const s = (input) => {
322
+ return (0, ms_1.default)(input) / 1000;
323
+ };
324
+ exports.s = s;
325
+ /**
326
+ * @private
327
+ */
328
+ const parseStreamMessage = (message) => {
329
+ try {
330
+ return JSON.parse(message);
331
+ }
332
+ catch (error) {
333
+ logger.error('Error parsing Stream message', { error });
334
+ throw error;
335
+ }
336
+ };
337
+ exports.parseStreamMessage = parseStreamMessage;
338
+ /**
339
+ * @private
340
+ */
341
+ const isStreamMessage = (result) => {
342
+ return Array.isArray(result) && Array.isArray(result[0]);
343
+ };
344
+ exports.isStreamMessage = isStreamMessage;
345
+ /**
346
+ * Transforms an array of arrays to an array of objects.
347
+ */
348
+ const arrayToHash = (response) => {
349
+ const results = [];
350
+ let key;
351
+ for (let i = 1; i < response.length; i++) {
352
+ // ignore count
353
+ const row = response[i];
354
+ const result = {};
355
+ if (Array.isArray(row)) {
356
+ // Check if row is an array
357
+ for (let j = 0; j < row.length; j += 2) {
358
+ const key = row[j];
359
+ const value = row[j + 1];
360
+ result[key] = value;
361
+ }
362
+ if (key) {
363
+ result.$ = key;
364
+ }
365
+ results.push(result);
366
+ key = undefined;
367
+ }
368
+ else {
369
+ key = row;
370
+ }
371
+ }
372
+ return results;
373
+ };
374
+ exports.arrayToHash = arrayToHash;