@hotmeshio/hotmesh 0.4.0 → 0.4.2

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 (284) hide show
  1. package/README.md +39 -14
  2. package/build/modules/enums.d.ts +110 -0
  3. package/build/modules/enums.js +134 -0
  4. package/build/modules/errors.d.ts +124 -0
  5. package/build/modules/errors.js +191 -0
  6. package/build/modules/key.d.ts +66 -0
  7. package/build/modules/key.js +190 -0
  8. package/build/modules/storage.d.ts +3 -0
  9. package/build/modules/storage.js +5 -0
  10. package/build/modules/utils.d.ts +119 -0
  11. package/build/modules/utils.js +374 -0
  12. package/build/package.json +1 -1
  13. package/build/services/activities/activity.d.ts +104 -0
  14. package/build/services/activities/activity.js +549 -0
  15. package/build/services/activities/await.d.ts +12 -0
  16. package/build/services/activities/await.js +114 -0
  17. package/build/services/activities/cycle.d.ts +19 -0
  18. package/build/services/activities/cycle.js +112 -0
  19. package/build/services/activities/hook.d.ts +27 -0
  20. package/build/services/activities/hook.js +168 -0
  21. package/build/services/activities/index.d.ts +19 -0
  22. package/build/services/activities/index.js +20 -0
  23. package/build/services/activities/interrupt.d.ts +16 -0
  24. package/build/services/activities/interrupt.js +158 -0
  25. package/build/services/activities/signal.d.ts +20 -0
  26. package/build/services/activities/signal.js +134 -0
  27. package/build/services/activities/trigger.d.ts +37 -0
  28. package/build/services/activities/trigger.js +246 -0
  29. package/build/services/activities/worker.d.ts +12 -0
  30. package/build/services/activities/worker.js +106 -0
  31. package/build/services/collator/index.d.ts +111 -0
  32. package/build/services/collator/index.js +293 -0
  33. package/build/services/compiler/deployer.d.ts +40 -0
  34. package/build/services/compiler/deployer.js +488 -0
  35. package/build/services/compiler/index.d.ts +32 -0
  36. package/build/services/compiler/index.js +112 -0
  37. package/build/services/compiler/validator.d.ts +34 -0
  38. package/build/services/compiler/validator.js +147 -0
  39. package/build/services/connector/factory.d.ts +22 -0
  40. package/build/services/connector/factory.js +99 -0
  41. package/build/services/connector/index.d.ts +30 -0
  42. package/build/services/connector/index.js +54 -0
  43. package/build/services/connector/providers/ioredis.d.ts +9 -0
  44. package/build/services/connector/providers/ioredis.js +26 -0
  45. package/build/services/connector/providers/nats.d.ts +9 -0
  46. package/build/services/connector/providers/nats.js +34 -0
  47. package/build/services/connector/providers/postgres.d.ts +20 -0
  48. package/build/services/connector/providers/postgres.js +102 -0
  49. package/build/services/connector/providers/redis.d.ts +9 -0
  50. package/build/services/connector/providers/redis.js +38 -0
  51. package/build/services/engine/index.d.ts +264 -0
  52. package/build/services/engine/index.js +761 -0
  53. package/build/services/exporter/index.d.ts +44 -0
  54. package/build/services/exporter/index.js +126 -0
  55. package/build/services/hotmesh/index.d.ts +483 -0
  56. package/build/services/hotmesh/index.js +622 -0
  57. package/build/services/logger/index.d.ts +16 -0
  58. package/build/services/logger/index.js +54 -0
  59. package/build/services/mapper/index.d.ts +28 -0
  60. package/build/services/mapper/index.js +81 -0
  61. package/build/services/memflow/client.d.ts +108 -0
  62. package/build/services/memflow/client.js +372 -0
  63. package/build/services/memflow/connection.d.ts +23 -0
  64. package/build/services/memflow/connection.js +33 -0
  65. package/build/services/memflow/context.d.ts +143 -0
  66. package/build/services/memflow/context.js +299 -0
  67. package/build/services/memflow/exporter.d.ts +51 -0
  68. package/build/services/memflow/exporter.js +215 -0
  69. package/build/services/memflow/handle.d.ts +90 -0
  70. package/build/services/memflow/handle.js +176 -0
  71. package/build/services/memflow/index.d.ts +116 -0
  72. package/build/services/memflow/index.js +122 -0
  73. package/build/services/memflow/schemas/factory.d.ts +29 -0
  74. package/build/services/memflow/schemas/factory.js +2492 -0
  75. package/build/services/memflow/search.d.ts +142 -0
  76. package/build/services/memflow/search.js +320 -0
  77. package/build/services/memflow/worker.d.ts +124 -0
  78. package/build/services/memflow/worker.js +514 -0
  79. package/build/services/memflow/workflow/all.d.ts +7 -0
  80. package/build/services/memflow/workflow/all.js +15 -0
  81. package/build/services/memflow/workflow/common.d.ts +20 -0
  82. package/build/services/memflow/workflow/common.js +47 -0
  83. package/build/services/memflow/workflow/context.d.ts +6 -0
  84. package/build/services/memflow/workflow/context.js +45 -0
  85. package/build/services/memflow/workflow/contextMethods.d.ts +14 -0
  86. package/build/services/memflow/workflow/contextMethods.js +33 -0
  87. package/build/services/memflow/workflow/didRun.d.ts +7 -0
  88. package/build/services/memflow/workflow/didRun.js +22 -0
  89. package/build/services/memflow/workflow/emit.d.ts +11 -0
  90. package/build/services/memflow/workflow/emit.js +29 -0
  91. package/build/services/memflow/workflow/enrich.d.ts +9 -0
  92. package/build/services/memflow/workflow/enrich.js +17 -0
  93. package/build/services/memflow/workflow/execChild.d.ts +18 -0
  94. package/build/services/memflow/workflow/execChild.js +102 -0
  95. package/build/services/memflow/workflow/execHook.d.ts +65 -0
  96. package/build/services/memflow/workflow/execHook.js +73 -0
  97. package/build/services/memflow/workflow/hook.d.ts +9 -0
  98. package/build/services/memflow/workflow/hook.js +56 -0
  99. package/build/services/memflow/workflow/index.d.ts +74 -0
  100. package/build/services/memflow/workflow/index.js +87 -0
  101. package/build/services/memflow/workflow/interrupt.d.ts +9 -0
  102. package/build/services/memflow/workflow/interrupt.js +24 -0
  103. package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +10 -0
  104. package/build/services/memflow/workflow/isSideEffectAllowed.js +33 -0
  105. package/build/services/memflow/workflow/proxyActivities.d.ts +20 -0
  106. package/build/services/memflow/workflow/proxyActivities.js +97 -0
  107. package/build/services/memflow/workflow/random.d.ts +6 -0
  108. package/build/services/memflow/workflow/random.js +16 -0
  109. package/build/services/memflow/workflow/searchMethods.d.ts +6 -0
  110. package/build/services/memflow/workflow/searchMethods.js +25 -0
  111. package/build/services/memflow/workflow/signal.d.ts +29 -0
  112. package/build/services/memflow/workflow/signal.js +50 -0
  113. package/build/services/memflow/workflow/sleepFor.d.ts +24 -0
  114. package/build/services/memflow/workflow/sleepFor.js +51 -0
  115. package/build/services/memflow/workflow/trace.d.ts +14 -0
  116. package/build/services/memflow/workflow/trace.js +33 -0
  117. package/build/services/memflow/workflow/waitFor.d.ts +29 -0
  118. package/build/services/memflow/workflow/waitFor.js +56 -0
  119. package/build/services/meshcall/index.d.ts +194 -0
  120. package/build/services/meshcall/index.js +452 -0
  121. package/build/services/meshcall/schemas/factory.d.ts +9 -0
  122. package/build/services/meshcall/schemas/factory.js +189 -0
  123. package/build/services/meshdata/index.d.ts +795 -0
  124. package/build/services/meshdata/index.js +1235 -0
  125. package/build/services/meshos/index.d.ts +293 -0
  126. package/build/services/meshos/index.js +547 -0
  127. package/build/services/pipe/functions/array.d.ts +17 -0
  128. package/build/services/pipe/functions/array.js +74 -0
  129. package/build/services/pipe/functions/bitwise.d.ts +9 -0
  130. package/build/services/pipe/functions/bitwise.js +24 -0
  131. package/build/services/pipe/functions/conditional.d.ts +13 -0
  132. package/build/services/pipe/functions/conditional.js +36 -0
  133. package/build/services/pipe/functions/cron.d.ts +12 -0
  134. package/build/services/pipe/functions/cron.js +40 -0
  135. package/build/services/pipe/functions/date.d.ts +58 -0
  136. package/build/services/pipe/functions/date.js +171 -0
  137. package/build/services/pipe/functions/index.d.ts +29 -0
  138. package/build/services/pipe/functions/index.js +30 -0
  139. package/build/services/pipe/functions/json.d.ts +5 -0
  140. package/build/services/pipe/functions/json.js +12 -0
  141. package/build/services/pipe/functions/logical.d.ts +5 -0
  142. package/build/services/pipe/functions/logical.js +12 -0
  143. package/build/services/pipe/functions/math.d.ts +42 -0
  144. package/build/services/pipe/functions/math.js +184 -0
  145. package/build/services/pipe/functions/number.d.ts +21 -0
  146. package/build/services/pipe/functions/number.js +60 -0
  147. package/build/services/pipe/functions/object.d.ts +25 -0
  148. package/build/services/pipe/functions/object.js +81 -0
  149. package/build/services/pipe/functions/string.d.ts +23 -0
  150. package/build/services/pipe/functions/string.js +69 -0
  151. package/build/services/pipe/functions/symbol.d.ts +12 -0
  152. package/build/services/pipe/functions/symbol.js +33 -0
  153. package/build/services/pipe/functions/unary.d.ts +7 -0
  154. package/build/services/pipe/functions/unary.js +18 -0
  155. package/build/services/pipe/index.d.ts +48 -0
  156. package/build/services/pipe/index.js +242 -0
  157. package/build/services/quorum/index.d.ts +90 -0
  158. package/build/services/quorum/index.js +263 -0
  159. package/build/services/reporter/index.d.ts +50 -0
  160. package/build/services/reporter/index.js +348 -0
  161. package/build/services/router/config/index.d.ts +11 -0
  162. package/build/services/router/config/index.js +36 -0
  163. package/build/services/router/consumption/index.d.ts +34 -0
  164. package/build/services/router/consumption/index.js +395 -0
  165. package/build/services/router/error-handling/index.d.ts +8 -0
  166. package/build/services/router/error-handling/index.js +98 -0
  167. package/build/services/router/index.d.ts +57 -0
  168. package/build/services/router/index.js +121 -0
  169. package/build/services/router/lifecycle/index.d.ts +27 -0
  170. package/build/services/router/lifecycle/index.js +80 -0
  171. package/build/services/router/telemetry/index.d.ts +11 -0
  172. package/build/services/router/telemetry/index.js +32 -0
  173. package/build/services/router/throttling/index.d.ts +23 -0
  174. package/build/services/router/throttling/index.js +76 -0
  175. package/build/services/search/factory.d.ts +7 -0
  176. package/build/services/search/factory.js +24 -0
  177. package/build/services/search/index.d.ts +23 -0
  178. package/build/services/search/index.js +10 -0
  179. package/build/services/search/providers/postgres/postgres.d.ts +25 -0
  180. package/build/services/search/providers/postgres/postgres.js +149 -0
  181. package/build/services/search/providers/redis/ioredis.d.ts +19 -0
  182. package/build/services/search/providers/redis/ioredis.js +121 -0
  183. package/build/services/search/providers/redis/redis.d.ts +19 -0
  184. package/build/services/search/providers/redis/redis.js +134 -0
  185. package/build/services/serializer/index.d.ts +42 -0
  186. package/build/services/serializer/index.js +282 -0
  187. package/build/services/store/cache.d.ts +67 -0
  188. package/build/services/store/cache.js +128 -0
  189. package/build/services/store/factory.d.ts +8 -0
  190. package/build/services/store/factory.js +24 -0
  191. package/build/services/store/index.d.ts +89 -0
  192. package/build/services/store/index.js +9 -0
  193. package/build/services/store/providers/postgres/kvsql.d.ts +168 -0
  194. package/build/services/store/providers/postgres/kvsql.js +198 -0
  195. package/build/services/store/providers/postgres/kvtables.d.ts +20 -0
  196. package/build/services/store/providers/postgres/kvtables.js +441 -0
  197. package/build/services/store/providers/postgres/kvtransaction.d.ts +36 -0
  198. package/build/services/store/providers/postgres/kvtransaction.js +248 -0
  199. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +60 -0
  200. package/build/services/store/providers/postgres/kvtypes/hash.js +1287 -0
  201. package/build/services/store/providers/postgres/kvtypes/list.d.ts +33 -0
  202. package/build/services/store/providers/postgres/kvtypes/list.js +194 -0
  203. package/build/services/store/providers/postgres/kvtypes/string.d.ts +20 -0
  204. package/build/services/store/providers/postgres/kvtypes/string.js +115 -0
  205. package/build/services/store/providers/postgres/kvtypes/zset.d.ts +41 -0
  206. package/build/services/store/providers/postgres/kvtypes/zset.js +214 -0
  207. package/build/services/store/providers/postgres/postgres.d.ts +178 -0
  208. package/build/services/store/providers/postgres/postgres.js +1244 -0
  209. package/build/services/store/providers/redis/_base.d.ts +137 -0
  210. package/build/services/store/providers/redis/_base.js +980 -0
  211. package/build/services/store/providers/redis/ioredis.d.ts +20 -0
  212. package/build/services/store/providers/redis/ioredis.js +180 -0
  213. package/build/services/store/providers/redis/redis.d.ts +18 -0
  214. package/build/services/store/providers/redis/redis.js +199 -0
  215. package/build/services/store/providers/store-initializable.d.ts +5 -0
  216. package/build/services/store/providers/store-initializable.js +2 -0
  217. package/build/services/stream/factory.d.ts +8 -0
  218. package/build/services/stream/factory.js +37 -0
  219. package/build/services/stream/index.d.ts +69 -0
  220. package/build/services/stream/index.js +11 -0
  221. package/build/services/stream/providers/nats/nats.d.ts +60 -0
  222. package/build/services/stream/providers/nats/nats.js +225 -0
  223. package/build/services/stream/providers/postgres/kvtables.d.ts +3 -0
  224. package/build/services/stream/providers/postgres/kvtables.js +146 -0
  225. package/build/services/stream/providers/postgres/postgres.d.ts +107 -0
  226. package/build/services/stream/providers/postgres/postgres.js +519 -0
  227. package/build/services/stream/providers/redis/ioredis.d.ts +61 -0
  228. package/build/services/stream/providers/redis/ioredis.js +272 -0
  229. package/build/services/stream/providers/redis/redis.d.ts +61 -0
  230. package/build/services/stream/providers/redis/redis.js +305 -0
  231. package/build/services/stream/providers/stream-initializable.d.ts +4 -0
  232. package/build/services/stream/providers/stream-initializable.js +2 -0
  233. package/build/services/sub/factory.d.ts +7 -0
  234. package/build/services/sub/factory.js +29 -0
  235. package/build/services/sub/index.d.ts +22 -0
  236. package/build/services/sub/index.js +10 -0
  237. package/build/services/sub/providers/nats/nats.d.ts +19 -0
  238. package/build/services/sub/providers/nats/nats.js +105 -0
  239. package/build/services/sub/providers/postgres/postgres.d.ts +19 -0
  240. package/build/services/sub/providers/postgres/postgres.js +92 -0
  241. package/build/services/sub/providers/redis/ioredis.d.ts +17 -0
  242. package/build/services/sub/providers/redis/ioredis.js +81 -0
  243. package/build/services/sub/providers/redis/redis.d.ts +17 -0
  244. package/build/services/sub/providers/redis/redis.js +72 -0
  245. package/build/services/task/index.d.ts +48 -0
  246. package/build/services/task/index.js +253 -0
  247. package/build/services/telemetry/index.d.ts +52 -0
  248. package/build/services/telemetry/index.js +306 -0
  249. package/build/services/worker/index.d.ts +77 -0
  250. package/build/services/worker/index.js +197 -0
  251. package/package.json +1 -1
  252. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  253. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  254. package/typedoc.json +0 -47
  255. package/types/activity.ts +0 -268
  256. package/types/app.ts +0 -20
  257. package/types/async.ts +0 -6
  258. package/types/cache.ts +0 -1
  259. package/types/collator.ts +0 -9
  260. package/types/error.ts +0 -56
  261. package/types/exporter.ts +0 -102
  262. package/types/hook.ts +0 -44
  263. package/types/hotmesh.ts +0 -314
  264. package/types/index.ts +0 -306
  265. package/types/job.ts +0 -233
  266. package/types/logger.ts +0 -8
  267. package/types/manifest.ts +0 -70
  268. package/types/map.ts +0 -5
  269. package/types/memflow.ts +0 -645
  270. package/types/meshcall.ts +0 -235
  271. package/types/meshdata.ts +0 -278
  272. package/types/ms.d.ts +0 -7
  273. package/types/nats.ts +0 -270
  274. package/types/pipe.ts +0 -90
  275. package/types/postgres.ts +0 -114
  276. package/types/provider.ts +0 -161
  277. package/types/quorum.ts +0 -167
  278. package/types/redis.ts +0 -404
  279. package/types/serializer.ts +0 -40
  280. package/types/stats.ts +0 -117
  281. package/types/stream.ts +0 -231
  282. package/types/task.ts +0 -7
  283. package/types/telemetry.ts +0 -16
  284. package/types/transition.ts +0 -20
@@ -0,0 +1,44 @@
1
+ import { ILogger } from '../logger';
2
+ import { StoreService } from '../store';
3
+ import { DependencyExport, ExportOptions, JobActionExport, JobExport } from '../../types/exporter';
4
+ import { ProviderClient, ProviderTransaction } from '../../types/provider';
5
+ import { StringStringType, Symbols } from '../../types/serializer';
6
+ /**
7
+ * Downloads job data from Redis (hscan, hmget, hgetall)
8
+ * Expands process data and includes dependency list
9
+ */
10
+ declare class ExporterService {
11
+ appId: string;
12
+ logger: ILogger;
13
+ store: StoreService<ProviderClient, ProviderTransaction>;
14
+ symbols: Promise<Symbols> | Symbols;
15
+ constructor(appId: string, store: StoreService<ProviderClient, ProviderTransaction>, logger: ILogger);
16
+ /**
17
+ * Convert the job hash into a JobExport object.
18
+ * This object contains various facets that describe the interaction
19
+ * in terms relevant to narrative storytelling.
20
+ */
21
+ export(jobId: string, options?: ExportOptions): Promise<JobExport>;
22
+ /**
23
+ * Inflates the key from Redis, 3-character symbol
24
+ * into a human-readable JSON path, reflecting the
25
+ * tree-like structure of the unidimensional Hash
26
+ */
27
+ inflateKey(key: string): string;
28
+ /**
29
+ * Inflates the job data from Redis into a JobExport object
30
+ * @param jobHash - the job data from Redis
31
+ * @param dependencyList - the list of dependencies for the job
32
+ * @returns - the inflated job data
33
+ */
34
+ inflate(jobHash: StringStringType, dependencyList: string[]): JobExport;
35
+ /**
36
+ * Inflates the dependency data from Redis into a JobExport object by
37
+ * organizing the dimensional isolate in sch a way asto interleave
38
+ * into a story
39
+ * @param data - the dependency data from Redis
40
+ * @returns - the organized dependency data
41
+ */
42
+ inflateDependencyData(data: string[], actions: JobActionExport): DependencyExport[];
43
+ }
44
+ export { ExporterService };
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExporterService = void 0;
4
+ const key_1 = require("../../modules/key");
5
+ const utils_1 = require("../../modules/utils");
6
+ const serializer_1 = require("../serializer");
7
+ /**
8
+ * Downloads job data from Redis (hscan, hmget, hgetall)
9
+ * Expands process data and includes dependency list
10
+ */
11
+ class ExporterService {
12
+ constructor(appId, store, logger) {
13
+ this.appId = appId;
14
+ this.logger = logger;
15
+ this.store = store;
16
+ }
17
+ /**
18
+ * Convert the job hash into a JobExport object.
19
+ * This object contains various facets that describe the interaction
20
+ * in terms relevant to narrative storytelling.
21
+ */
22
+ async export(jobId, options = {}) {
23
+ if (!this.symbols) {
24
+ this.symbols = this.store.getAllSymbols();
25
+ this.symbols = await this.symbols;
26
+ }
27
+ const depData = []; // await this.store.getDependencies(jobId);
28
+ const jobData = await this.store.getRaw(jobId);
29
+ const jobExport = this.inflate(jobData, depData);
30
+ return jobExport;
31
+ }
32
+ /**
33
+ * Inflates the key from Redis, 3-character symbol
34
+ * into a human-readable JSON path, reflecting the
35
+ * tree-like structure of the unidimensional Hash
36
+ */
37
+ inflateKey(key) {
38
+ return key in this.symbols ? this.symbols[key] : key;
39
+ }
40
+ /**
41
+ * Inflates the job data from Redis into a JobExport object
42
+ * @param jobHash - the job data from Redis
43
+ * @param dependencyList - the list of dependencies for the job
44
+ * @returns - the inflated job data
45
+ */
46
+ inflate(jobHash, dependencyList) {
47
+ //the list of actions taken in the workflow and hook functions
48
+ const actions = {
49
+ hooks: {},
50
+ main: {
51
+ cursor: -1,
52
+ items: [],
53
+ },
54
+ };
55
+ const process = {};
56
+ const dependencies = this.inflateDependencyData(dependencyList, actions);
57
+ const regex = /^([a-zA-Z]{3}),(\d+(?:,\d+)*)/;
58
+ Object.entries(jobHash).forEach(([key, value]) => {
59
+ const match = key.match(regex);
60
+ if (match) {
61
+ //activity process state
62
+ const [_, letters, numbers] = match;
63
+ const path = this.inflateKey(letters);
64
+ const dimensions = `${numbers.replace(/,/g, '/')}`;
65
+ const resolved = serializer_1.SerializerService.fromString(value);
66
+ process[`${dimensions}/${path}`] = resolved;
67
+ }
68
+ else if (key.length === 3) {
69
+ //job state
70
+ process[this.inflateKey(key)] = serializer_1.SerializerService.fromString(value);
71
+ }
72
+ });
73
+ return {
74
+ dependencies,
75
+ process: (0, utils_1.restoreHierarchy)(process),
76
+ status: jobHash[':'],
77
+ };
78
+ }
79
+ /**
80
+ * Inflates the dependency data from Redis into a JobExport object by
81
+ * organizing the dimensional isolate in sch a way asto interleave
82
+ * into a story
83
+ * @param data - the dependency data from Redis
84
+ * @returns - the organized dependency data
85
+ */
86
+ inflateDependencyData(data, actions) {
87
+ const hookReg = /([0-9,]+)-(\d+)$/;
88
+ const flowReg = /-(\d+)$/;
89
+ return data.map((dependency, index) => {
90
+ const [action, topic, gid, _pd, ...jid] = dependency.split(key_1.VALSEP);
91
+ const jobId = jid.join(key_1.VALSEP);
92
+ const match = jobId.match(hookReg);
93
+ let prefix;
94
+ let type;
95
+ let dimensionKey = '';
96
+ if (match) {
97
+ //hook-originating dependency
98
+ const [_, dimension, counter] = match;
99
+ dimensionKey = dimension.split(',').join('/');
100
+ prefix = `${dimensionKey}[${counter}]`;
101
+ type = 'hook';
102
+ }
103
+ else {
104
+ const match = jobId.match(flowReg);
105
+ if (match) {
106
+ //main workflow-originating dependency
107
+ const [_, counter] = match;
108
+ prefix = `[${counter}]`;
109
+ type = 'flow';
110
+ }
111
+ else {
112
+ //'other' types like signal cleanup
113
+ prefix = '/';
114
+ type = 'other';
115
+ }
116
+ }
117
+ return {
118
+ type: action,
119
+ topic,
120
+ gid,
121
+ jid: jobId,
122
+ };
123
+ });
124
+ }
125
+ }
126
+ exports.ExporterService = ExporterService;
@@ -0,0 +1,483 @@
1
+ import { EngineService } from '../engine';
2
+ import { ILogger } from '../logger';
3
+ import { QuorumService } from '../quorum';
4
+ import { WorkerService } from '../worker';
5
+ import { JobState, JobData, JobOutput, JobStatus, JobInterruptOptions, ExtensionType } from '../../types/job';
6
+ import { HotMeshConfig, HotMeshManifest } from '../../types/hotmesh';
7
+ import { JobExport } from '../../types/exporter';
8
+ import { JobMessageCallback, QuorumMessage, QuorumMessageCallback, QuorumProfile, ThrottleOptions } from '../../types/quorum';
9
+ import { StringAnyType, StringStringType } from '../../types/serializer';
10
+ import { JobStatsInput, GetStatsOptions, IdsResponse, StatsResponse } from '../../types/stats';
11
+ import { StreamCode, StreamData, StreamDataResponse, StreamStatus } from '../../types/stream';
12
+ /**
13
+ * HotMesh is a distributed, reentrant process orchestration engine that transforms
14
+ * Redis, Postgres, or NATS into a resilient service mesh capable of running
15
+ * fault-tolerant workflows across multiple services and systems.
16
+ *
17
+ * ## Core Concepts
18
+ *
19
+ * **Distributed Quorum Architecture**: HotMesh operates as a distributed quorum
20
+ * where multiple engine and worker instances coordinate using CQRS principles.
21
+ * Each member reads from assigned topic queues and writes results to other queues,
22
+ * creating emergent workflow orchestration without a central controller.
23
+ *
24
+ * **Reentrant Process Engine**: Unlike traditional workflow engines, HotMesh
25
+ * provides built-in retry logic, idempotency, and failure recovery. Your business
26
+ * logic doesn't need to handle timeouts or retries - the engine manages all of that.
27
+ *
28
+ * **Multi-Provider Support**: Supports Redis/ValKey, Postgres, and NATS as backend
29
+ * providers, allowing you to leverage existing infrastructure investments.
30
+ *
31
+ * ## Key Features
32
+ *
33
+ * - **Fault Tolerance**: Automatic retry, timeout, and failure recovery
34
+ * - **Distributed Execution**: No single point of failure
35
+ * - **Multi-Provider**: Redis, Postgres, NATS backend support
36
+ * - **YAML-Driven**: Model-driven development with declarative workflow definitions
37
+ * - **OpenTelemetry**: Built-in observability and tracing
38
+ * - **Durable State**: Workflow state persists across system restarts
39
+ * - **Pattern Matching**: Pub/sub with wildcard pattern support
40
+ * - **Throttling**: Dynamic flow control and backpressure management
41
+ *
42
+ * ## Architecture
43
+ *
44
+ * HotMesh consists of several specialized modules:
45
+ * - **HotMesh**: Core orchestration engine (this class)
46
+ * - **MemFlow**: Temporal.io-compatible workflow framework
47
+ * - **MeshCall**: Durable function execution (Temporal-like clone)
48
+ *
49
+ * ## Lifecycle Overview
50
+ *
51
+ * 1. **Initialize**: Create HotMesh instance with provider configuration
52
+ * 2. **Deploy**: Upload YAML workflow definitions to the backend
53
+ * 3. **Activate**: Coordinate quorum to enable the workflow version
54
+ * 4. **Execute**: Publish events to trigger workflow execution
55
+ * 5. **Monitor**: Track progress via OpenTelemetry and built-in observability
56
+ *
57
+ * ## Basic Usage
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * import { HotMesh } from '@hotmeshio/hotmesh';
62
+ * import Redis from 'ioredis';
63
+ *
64
+ * // Initialize with Redis backend
65
+ * const hotMesh = await HotMesh.init({
66
+ * appId: 'my-app',
67
+ * engine: {
68
+ * connection: {
69
+ * class: Redis,
70
+ * options: { host: 'localhost', port: 6379 }
71
+ * }
72
+ * }
73
+ * });
74
+ *
75
+ * // Deploy workflow definition
76
+ * await hotMesh.deploy(`
77
+ * app:
78
+ * id: my-app
79
+ * version: '1'
80
+ * graphs:
81
+ * - subscribes: order.process
82
+ * activities:
83
+ * validate:
84
+ * type: worker
85
+ * topic: order.validate
86
+ * approve:
87
+ * type: hook
88
+ * topic: order.approve
89
+ * fulfill:
90
+ * type: worker
91
+ * topic: order.fulfill
92
+ * transitions:
93
+ * validate:
94
+ * - to: approve
95
+ * approve:
96
+ * - to: fulfill
97
+ * `);
98
+ *
99
+ * // Activate the workflow version
100
+ * await hotMesh.activate('1');
101
+ *
102
+ * // Execute workflow (fire-and-forget)
103
+ * const jobId = await hotMesh.pub('order.process', {
104
+ * orderId: '12345',
105
+ * amount: 99.99
106
+ * });
107
+ *
108
+ * // Execute workflow and wait for result
109
+ * const result = await hotMesh.pubsub('order.process', {
110
+ * orderId: '12345',
111
+ * amount: 99.99
112
+ * });
113
+ * ```
114
+ *
115
+ * ## Postgres Backend Example
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * import { HotMesh } from '@hotmeshio/hotmesh';
120
+ * import { Client as Postgres } from 'pg';
121
+ *
122
+ * const hotMesh = await HotMesh.init({
123
+ * appId: 'my-app',
124
+ * engine: {
125
+ * connection: {
126
+ * class: Postgres,
127
+ * options: {
128
+ * connectionString: 'postgresql://user:pass@localhost:5432/db'
129
+ * }
130
+ * }
131
+ * }
132
+ * });
133
+ * ```
134
+ *
135
+ * ## Advanced Features
136
+ *
137
+ * **Pattern Subscriptions**: Listen to multiple workflow topics
138
+ * ```typescript
139
+ * await hotMesh.psub('order.*', (topic, message) => {
140
+ * console.log(`Received ${topic}:`, message);
141
+ * });
142
+ * ```
143
+ *
144
+ * **Throttling**: Control processing rates
145
+ * ```typescript
146
+ * // Pause all processing for 5 seconds
147
+ * await hotMesh.throttle({ throttle: 5000 });
148
+ *
149
+ * // Emergency stop (pause indefinitely)
150
+ * await hotMesh.throttle({ throttle: -1 });
151
+ * ```
152
+ *
153
+ * **Workflow Interruption**: Gracefully stop running workflows
154
+ * ```typescript
155
+ * await hotMesh.interrupt('order.process', jobId, {
156
+ * reason: 'User cancellation'
157
+ * });
158
+ * ```
159
+ *
160
+ * **State Inspection**: Query workflow state and progress
161
+ * ```typescript
162
+ * const state = await hotMesh.getState('order.process', jobId);
163
+ * const status = await hotMesh.getStatus(jobId);
164
+ * ```
165
+ *
166
+ * ## Distributed Coordination
167
+ *
168
+ * HotMesh automatically handles distributed coordination through its quorum system:
169
+ *
170
+ * ```typescript
171
+ * // Check quorum health
172
+ * const members = await hotMesh.rollCall();
173
+ *
174
+ * // Coordinate version activation across all instances
175
+ * await hotMesh.activate('2', 1000); // 1 second delay for consensus
176
+ * ```
177
+ *
178
+ * ## Integration with Higher-Level Modules
179
+ *
180
+ * For most use cases, consider using the higher-level modules:
181
+ * - **MemFlow**: For Temporal.io-style workflows with TypeScript functions
182
+ * - **MeshCall**: For durable function calls and RPC patterns
183
+ *
184
+ * ## Cleanup
185
+ *
186
+ * Always clean up resources when shutting down:
187
+ * ```typescript
188
+ * // Stop this instance
189
+ * hotMesh.stop();
190
+ *
191
+ * // Stop all instances (typically in signal handlers)
192
+ * await HotMesh.stop();
193
+ * ```
194
+ *
195
+ * @see {@link https://hotmesh.io/docs} - Complete documentation
196
+ * @see {@link https://github.com/hotmeshio/samples-typescript} - Examples and tutorials
197
+ * @see {@link https://zenodo.org/records/12168558} - Academic paper on the architecture
198
+ */
199
+ declare class HotMesh {
200
+ namespace: string;
201
+ appId: string;
202
+ guid: string;
203
+ /**
204
+ * @private
205
+ */
206
+ engine: EngineService | null;
207
+ /**
208
+ * @private
209
+ */
210
+ quorum: QuorumService | null;
211
+ /**
212
+ * @private
213
+ */
214
+ workers: WorkerService[];
215
+ logger: ILogger;
216
+ static disconnecting: boolean;
217
+ /**
218
+ * @private
219
+ */
220
+ verifyAndSetNamespace(namespace?: string): void;
221
+ /**
222
+ * @private
223
+ */
224
+ verifyAndSetAppId(appId: string): void;
225
+ /**
226
+ * Instance initializer. Workers are configured
227
+ * similarly to the engine, but as an array with
228
+ * multiple worker objects.
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * const config: HotMeshConfig = {
233
+ * appId: 'myapp',
234
+ * engine: {
235
+ * connection: {
236
+ * class: Postgres,
237
+ * options: {
238
+ * connectionString: 'postgresql://usr:pwd@localhost:5432/db',
239
+ * }
240
+ * }
241
+ * },
242
+ * workers [...]
243
+ * };
244
+ * const hotMesh = await HotMesh.init(config);
245
+ * ```
246
+ */
247
+ static init(config: HotMeshConfig): Promise<HotMesh>;
248
+ /**
249
+ * returns a guid using the same core guid
250
+ * generator used by the HotMesh (nanoid)
251
+ */
252
+ static guid(): string;
253
+ /**
254
+ * @private
255
+ */
256
+ initEngine(config: HotMeshConfig, logger: ILogger): Promise<void>;
257
+ /**
258
+ * @private
259
+ */
260
+ initQuorum(config: HotMeshConfig, engine: EngineService, logger: ILogger): Promise<void>;
261
+ /**
262
+ * @private
263
+ */
264
+ constructor();
265
+ /**
266
+ * @private
267
+ */
268
+ doWork(config: HotMeshConfig, logger: ILogger): Promise<void>;
269
+ /**
270
+ * Starts a workflow
271
+ * @example
272
+ * ```typescript
273
+ * await hotMesh.pub('a.b.c', { key: 'value' });
274
+ * ```
275
+ */
276
+ pub(topic: string, data?: JobData, context?: JobState, extended?: ExtensionType): Promise<string>;
277
+ /**
278
+ * Subscribe (listen) to all output and interim emissions of a single
279
+ * workflow topic. NOTE: Postgres does not support patterned
280
+ * unsubscription, so this method is not supported for Postgres.
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * await hotMesh.psub('a.b.c', (topic, message) => {
285
+ * console.log(message);
286
+ * });
287
+ * ```
288
+ */
289
+ sub(topic: string, callback: JobMessageCallback): Promise<void>;
290
+ /**
291
+ * Stop listening in on a single workflow topic
292
+ */
293
+ unsub(topic: string): Promise<void>;
294
+ /**
295
+ * Listen to all output and interim emissions of a workflow topic
296
+ * matching a wildcard pattern.
297
+ * @example
298
+ * ```typescript
299
+ * await hotMesh.psub('a.b.c*', (topic, message) => {
300
+ * console.log(message);
301
+ * });
302
+ * ```
303
+ */
304
+ psub(wild: string, callback: JobMessageCallback): Promise<void>;
305
+ /**
306
+ * Patterned unsubscribe. NOTE: Postgres does not support patterned
307
+ * unsubscription, so this method is not supported for Postgres.
308
+ */
309
+ punsub(wild: string): Promise<void>;
310
+ /**
311
+ * Starts a workflow and awaits the response
312
+ * @example
313
+ * ```typescript
314
+ * await hotMesh.pubsub('a.b.c', { key: 'value' });
315
+ * ```
316
+ */
317
+ pubsub(topic: string, data?: JobData, context?: JobState | null, timeout?: number): Promise<JobOutput>;
318
+ /**
319
+ * Add a transition message to the workstream, resuming leg 2 of a paused
320
+ * reentrant activity (e.g., await, worker, hook)
321
+ */
322
+ add(streamData: StreamData | StreamDataResponse): Promise<string>;
323
+ /**
324
+ * Request a roll call from the quorum (engine and workers)
325
+ */
326
+ rollCall(delay?: number): Promise<QuorumProfile[]>;
327
+ /**
328
+ * Sends a throttle message to the quorum (engine and/or workers)
329
+ * to limit the rate of processing. Pass `-1` to throttle indefinitely.
330
+ * The value must be a non-negative integer and not exceed `MAX_DELAY` ms.
331
+ *
332
+ * When throttling is set, the quorum will pause for the specified time
333
+ * before processing the next message. Target specific engines and
334
+ * workers by passing a `guid` and/or `topic`. Pass no arguments to
335
+ * throttle the entire quorum.
336
+ *
337
+ * In this example, all processing has been paused indefinitely for
338
+ * the entire quorum. This is equivalent to an emergency stop.
339
+ *
340
+ * HotMesh is a stateless sequence engine, so the throttle can be adjusted up
341
+ * and down with no loss of data.
342
+ *
343
+ *
344
+ * @example
345
+ * ```typescript
346
+ * await hotMesh.throttle({ throttle: -1 });
347
+ * ```
348
+ */
349
+ throttle(options: ThrottleOptions): Promise<boolean>;
350
+ /**
351
+ * Publish a message to the quorum (engine and/or workers)
352
+ */
353
+ pubQuorum(quorumMessage: QuorumMessage): Promise<boolean>;
354
+ /**
355
+ * Subscribe to quorum events (engine and workers)
356
+ */
357
+ subQuorum(callback: QuorumMessageCallback): Promise<void>;
358
+ /**
359
+ * Unsubscribe from quorum events (engine and workers)
360
+ */
361
+ unsubQuorum(callback: QuorumMessageCallback): Promise<void>;
362
+ /**
363
+ * Preview changes and provide an analysis of risk
364
+ * prior to deployment
365
+ * @private
366
+ */
367
+ plan(path: string): Promise<HotMeshManifest>;
368
+ /**
369
+ * When the app YAML descriptor file is ready, the `deploy` function can be called.
370
+ * This function is responsible for merging all referenced YAML source
371
+ * files and writing the JSON output to the file system and to the provider backend. It
372
+ * is also possible to embed the YAML in-line as a string.
373
+ *
374
+ * *The version will not be active until activation is explicitly called.*
375
+ */
376
+ deploy(pathOrYAML: string): Promise<HotMeshManifest>;
377
+ /**
378
+ * Once the app YAML file is deployed to the provider backend, the `activate` function can be
379
+ * called to enable it for the entire quorum at the same moment.
380
+ *
381
+ * The approach is to establish the coordinated health of the system through series
382
+ * of call/response exchanges. Once it is established that the quorum is healthy,
383
+ * the quorum is instructed to run their engine in `no-cache` mode, ensuring
384
+ * that the provider backend is consulted for the active app version each time a
385
+ * call is processed. This ensures that all engines are running the same version
386
+ * of the app, switching over at the same moment and then enabling `cache` mode
387
+ * to improve performance.
388
+ *
389
+ * *Add a delay for the quorum to reach consensus if traffic is busy, but
390
+ * also consider throttling traffic flow to an acceptable level.*
391
+ */
392
+ activate(version: string, delay?: number): Promise<boolean>;
393
+ /**
394
+ * Returns the job state as a JSON object, useful
395
+ * for understanding dependency chains
396
+ */
397
+ export(jobId: string): Promise<JobExport>;
398
+ /**
399
+ * Returns all data (HGETALL) for a job.
400
+ */
401
+ getRaw(jobId: string): Promise<StringStringType>;
402
+ /**
403
+ * Reporter-related method to get the status of a job
404
+ * @private
405
+ */
406
+ getStats(topic: string, query: JobStatsInput): Promise<StatsResponse>;
407
+ /**
408
+ * Returns the status of a job. This is a numeric
409
+ * semaphore value that indicates the job's state.
410
+ * Any non-positive value indicates a completed job.
411
+ * Jobs with a value of `-1` are pending and will
412
+ * automatically be scrubbed after a set period.
413
+ * Jobs a value around -1billion have been interrupted
414
+ * and will be scrubbed after a set period. Jobs with
415
+ * a value of 0 completed normally. Jobs with a
416
+ * positive value are still running.
417
+ */
418
+ getStatus(jobId: string): Promise<JobStatus>;
419
+ /**
420
+ * Returns the job state (data and metadata) for a job.
421
+ */
422
+ getState(topic: string, jobId: string): Promise<JobOutput>;
423
+ /**
424
+ * Returns searchable/queryable data for a job. In this
425
+ * example a literal field is also searched (the colon
426
+ * is used to track job status and is a reserved field;
427
+ * it can be read but not written).
428
+ *
429
+ * @example
430
+ * ```typescript
431
+ * const fields = ['fred', 'barney', '":"'];
432
+ * const queryState = await hotMesh.getQueryState('123', fields);
433
+ * //returns { fred: 'flintstone', barney: 'rubble', ':': '1' }
434
+ * ```
435
+ */
436
+ getQueryState(jobId: string, fields: string[]): Promise<StringAnyType>;
437
+ /**
438
+ * @private
439
+ */
440
+ getIds(topic: string, query: JobStatsInput, queryFacets?: any[]): Promise<IdsResponse>;
441
+ /**
442
+ * @private
443
+ */
444
+ resolveQuery(topic: string, query: JobStatsInput): Promise<GetStatsOptions>;
445
+ /**
446
+ * Interrupt an active job
447
+ */
448
+ interrupt(topic: string, jobId: string, options?: JobInterruptOptions): Promise<string>;
449
+ /**
450
+ * Immediately deletes (DEL) a completed job from the system.
451
+ *
452
+ * *Scrubbed jobs must be complete with a non-positive `status` value*
453
+ */
454
+ scrub(jobId: string): Promise<void>;
455
+ /**
456
+ * Re/entry point for an active job. This is used to resume a paused job
457
+ * and close the reentry point or leave it open for subsequent reentry.
458
+ * Because `hooks` are public entry points, they include a `topic`
459
+ * which is established in the app YAML file.
460
+ *
461
+ * When this method is called, a hook rule will be located to establish
462
+ * the exact activity and activity dimension for reentry.
463
+ */
464
+ hook(topic: string, data: JobData, status?: StreamStatus, code?: StreamCode): Promise<string>;
465
+ /**
466
+ * @private
467
+ */
468
+ hookAll(hookTopic: string, data: JobData, query: JobStatsInput, queryFacets?: string[]): Promise<string[]>;
469
+ /**
470
+ * Stop all points of presence, workers and engines
471
+ */
472
+ static stop(): Promise<void>;
473
+ /**
474
+ * Stop this point of presence, workers and engines
475
+ */
476
+ stop(): void;
477
+ /**
478
+ * @private
479
+ * @deprecated
480
+ */
481
+ compress(terms: string[]): Promise<boolean>;
482
+ }
483
+ export { HotMesh };