@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,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Validator = void 0;
4
+ const pipe_1 = require("../pipe");
5
+ class Validator {
6
+ constructor(manifest) {
7
+ this.manifest = null;
8
+ this.activityIds = [];
9
+ this.mappingStatements = {};
10
+ this.store = null;
11
+ this.manifest = manifest;
12
+ }
13
+ /**
14
+ * validate the manifest file
15
+ */
16
+ async validate(store) {
17
+ this.store = store;
18
+ this.getMappingStatements();
19
+ this.validateActivityIds();
20
+ this.validateReferencedActivityIds();
21
+ this.validateMappingStatements();
22
+ this.validateTransitions();
23
+ this.validateTransitionConditions();
24
+ this.validateStats();
25
+ this.validateSchemas();
26
+ this.validateUniqueHandledTopics();
27
+ this.validateGraphPublishSubscribe();
28
+ this.validateHooks();
29
+ this.validateConditionalStatements();
30
+ }
31
+ // 1.1) Validate the manifest file activity ids are unique (no duplicates)
32
+ validateActivityIds() {
33
+ const activityIdsSet = new Set();
34
+ this.manifest.app.graphs.forEach((graph) => {
35
+ const ids = Object.keys(graph.activities);
36
+ // Check for duplicates and add ids to the set
37
+ ids.forEach((id) => {
38
+ if (activityIdsSet.has(id)) {
39
+ throw new Error(`Duplicate activity id found: ${id}`);
40
+ }
41
+ else {
42
+ activityIdsSet.add(id);
43
+ }
44
+ });
45
+ });
46
+ this.activityIds = Array.from(activityIdsSet);
47
+ }
48
+ isMappingStatement(value) {
49
+ return typeof value === 'string' && value.startsWith('{') && value.endsWith('}');
50
+ }
51
+ extractMappingStatements(obj, result, currentActivityId) {
52
+ for (const key in obj) {
53
+ if (typeof obj[key] === 'object' && obj[key] !== null) {
54
+ this.extractMappingStatements(obj[key], result, currentActivityId);
55
+ }
56
+ else if (this.isMappingStatement(obj[key])) {
57
+ if (!result[currentActivityId]) {
58
+ result[currentActivityId] = [];
59
+ }
60
+ result[currentActivityId].push(obj[key]);
61
+ }
62
+ }
63
+ }
64
+ getMappingStatements() {
65
+ const mappingStatements = {};
66
+ this.manifest.app.graphs.forEach((graph) => {
67
+ const activities = graph.activities;
68
+ for (const activityId in activities) {
69
+ const activity = activities[activityId];
70
+ this.extractMappingStatements(activity, mappingStatements, activityId);
71
+ }
72
+ });
73
+ this.mappingStatements = mappingStatements;
74
+ }
75
+ // 1.2) Validate no activity ids are referenced that don't exist
76
+ validateReferencedActivityIds() {
77
+ // get list of all mapping statements and validate
78
+ const mappingStatements = this.mappingStatements;
79
+ const activityIds = this.activityIds;
80
+ for (const activity in mappingStatements) {
81
+ const statements = mappingStatements[activity];
82
+ statements.forEach((statement) => {
83
+ if (statement.startsWith('{') && statement.endsWith('}')) {
84
+ const statementParts = statement.slice(1, -1).split('.');
85
+ const referencedActivityId = statementParts[0];
86
+ if (!(Validator.SYS_VARS.includes(referencedActivityId) || activityIds.includes(referencedActivityId) || this.isFunction(statement))) {
87
+ throw new Error(`Mapping statement references non-existent activity: ${statement}`);
88
+ }
89
+ }
90
+ });
91
+ }
92
+ }
93
+ isFunction(value) {
94
+ return value.startsWith('{@') && pipe_1.Pipe.resolveFunction(value);
95
+ }
96
+ // 1.3) Validate the mapping/@pipe statements are valid
97
+ validateMappingStatements() {
98
+ // Implement the method content
99
+ }
100
+ // 1.4) Validate the transitions are valid
101
+ validateTransitions() {
102
+ // Implement the method content
103
+ }
104
+ // 1.5) Validate the transition conditions are valid
105
+ validateTransitionConditions() {
106
+ // Implement the method content
107
+ }
108
+ // 1.6) Validate the stats
109
+ validateStats() {
110
+ // Implement the method content
111
+ }
112
+ // 1.7) Validate the schemas
113
+ validateSchemas() {
114
+ // Implement the method content
115
+ }
116
+ // 1.8) Validate the topics are unique and handled
117
+ validateUniqueHandledTopics() {
118
+ // Implement the method content
119
+ }
120
+ // 1.9) Validate that every graph has publishes and subscribes
121
+ validateGraphPublishSubscribe() {
122
+ // Implement the method content
123
+ }
124
+ // 1.10) Validate hooks, including mapping statements
125
+ validateHooks() {
126
+ // Implement the method content
127
+ }
128
+ // 1.11) Validate conditional statements
129
+ validateConditionalStatements() {
130
+ // Implement the method content
131
+ }
132
+ }
133
+ exports.Validator = Validator;
134
+ Validator.SYS_VARS = ['$app', '$self', '$graph', '$job'];
@@ -0,0 +1,13 @@
1
+ import { RedisClientOptions, RedisClassType, RedisClientType } from '../../../types/ioredisclient';
2
+ declare class RedisConnection {
3
+ private connection;
4
+ private static instances;
5
+ private id;
6
+ private static clientOptions;
7
+ private createConnection;
8
+ getClient(): RedisClientType;
9
+ disconnect(): Promise<void>;
10
+ static connect(id: string, Redis: RedisClassType, options?: RedisClientOptions): Promise<RedisConnection>;
11
+ static disconnectAll(): Promise<void>;
12
+ }
13
+ export { RedisConnection };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisConnection = void 0;
4
+ class RedisConnection {
5
+ constructor() {
6
+ this.connection = null;
7
+ this.id = null;
8
+ }
9
+ async createConnection(Redis, options) {
10
+ return new Redis(options);
11
+ }
12
+ getClient() {
13
+ if (!this.connection) {
14
+ throw new Error('Redis client is not connected');
15
+ }
16
+ return this.connection;
17
+ }
18
+ async disconnect() {
19
+ if (this.connection) {
20
+ await this.connection.quit();
21
+ this.connection = null;
22
+ }
23
+ if (this.id) {
24
+ RedisConnection.instances.delete(this.id);
25
+ }
26
+ }
27
+ static async connect(id, Redis, options) {
28
+ if (this.instances.has(id)) {
29
+ return this.instances.get(id);
30
+ }
31
+ const instance = new RedisConnection();
32
+ const opts = options ? { ...options } : { ...this.clientOptions };
33
+ instance.connection = await instance.createConnection(Redis, opts);
34
+ instance.id = id;
35
+ this.instances.set(id, instance);
36
+ return instance;
37
+ }
38
+ static async disconnectAll() {
39
+ await Promise.all(Array.from(this.instances.values()).map((instance) => instance.disconnect()));
40
+ this.instances.clear();
41
+ }
42
+ }
43
+ exports.RedisConnection = RedisConnection;
44
+ RedisConnection.instances = new Map();
45
+ RedisConnection.clientOptions = {
46
+ host: 'localhost',
47
+ port: 6379,
48
+ //password: config.REDIS_PASSWORD,
49
+ //db: config.REDIS_DATABASE,
50
+ };
@@ -0,0 +1,13 @@
1
+ import { RedisClientType, RedisClientOptions, RedisClassType } from '../../../types/redisclient';
2
+ declare class RedisConnection {
3
+ private connection;
4
+ private static instances;
5
+ private id;
6
+ private static clientOptions;
7
+ private createConnection;
8
+ getClient(): RedisClientType;
9
+ disconnect(): Promise<void>;
10
+ static connect(id: string, Redis: RedisClassType, options?: RedisClientOptions): Promise<RedisConnection>;
11
+ static disconnectAll(): Promise<void>;
12
+ }
13
+ export { RedisConnection, RedisClientType };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RedisConnection = void 0;
4
+ class RedisConnection {
5
+ constructor() {
6
+ this.connection = null;
7
+ this.id = null;
8
+ }
9
+ async createConnection(Redis, options) {
10
+ return new Promise((resolve, reject) => {
11
+ const client = Redis.createClient(options);
12
+ client.on('error', (error) => {
13
+ reject(error);
14
+ });
15
+ client.on('ready', () => {
16
+ resolve(client);
17
+ });
18
+ client.connect();
19
+ });
20
+ }
21
+ getClient() {
22
+ if (!this.connection) {
23
+ throw new Error('Redis client is not connected');
24
+ }
25
+ return this.connection;
26
+ }
27
+ async disconnect() {
28
+ if (this.connection) {
29
+ await this.connection.quit();
30
+ this.connection = null;
31
+ }
32
+ if (this.id) {
33
+ RedisConnection.instances.delete(this.id);
34
+ }
35
+ }
36
+ static async connect(id, Redis, options) {
37
+ if (this.instances.has(id)) {
38
+ return this.instances.get(id);
39
+ }
40
+ const instance = new RedisConnection();
41
+ const opts = options ? { ...options } : { ...this.clientOptions };
42
+ instance.connection = await instance.createConnection(Redis, opts);
43
+ instance.id = id;
44
+ this.instances.set(id, instance);
45
+ return instance;
46
+ }
47
+ static async disconnectAll() {
48
+ await Promise.all(Array.from(this.instances.values()).map((instance) => instance.disconnect()));
49
+ this.instances.clear();
50
+ }
51
+ }
52
+ exports.RedisConnection = RedisConnection;
53
+ RedisConnection.instances = new Map();
54
+ RedisConnection.clientOptions = {
55
+ socket: {
56
+ host: 'localhost',
57
+ port: 6379,
58
+ tls: false,
59
+ },
60
+ //password: config.REDIS_PASSWORD,
61
+ //database: config.REDIS_DATABASE,
62
+ };
@@ -0,0 +1,5 @@
1
+ import { HotMeshEngine, HotMeshWorker } from '../../types/hotmesh';
2
+ import { RedisClass, RedisOptions } from '../../types/redis';
3
+ export declare class ConnectorService {
4
+ static initRedisClients(Redis: RedisClass, options: RedisOptions, target: HotMeshEngine | HotMeshWorker): Promise<void>;
5
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectorService = void 0;
4
+ const nanoid_1 = require("nanoid");
5
+ const utils_1 = require("../../modules/utils");
6
+ const ioredis_1 = require("../connector/clients/ioredis");
7
+ const redis_1 = require("../connector/clients/redis");
8
+ class ConnectorService {
9
+ //1) Initialize `store`, `stream`, and `subscription` Redis clients.
10
+ //2) Bind to the target if not already present
11
+ static async initRedisClients(Redis, options, target) {
12
+ if (!target.store || !target.stream || !target.sub) {
13
+ const instances = [];
14
+ if ((0, utils_1.identifyRedisTypeFromClass)(Redis) === 'redis') {
15
+ for (let i = 1; i <= 3; i++) {
16
+ instances.push(redis_1.RedisConnection.connect((0, nanoid_1.nanoid)(), Redis, options));
17
+ }
18
+ }
19
+ else {
20
+ for (let i = 1; i <= 3; i++) {
21
+ instances.push(ioredis_1.RedisConnection.connect((0, nanoid_1.nanoid)(), Redis, options));
22
+ }
23
+ }
24
+ const [store, stream, sub] = await Promise.all(instances);
25
+ target.store = target.store || store.getClient();
26
+ target.stream = target.stream || stream.getClient();
27
+ target.sub = target.sub || sub.getClient();
28
+ }
29
+ }
30
+ }
31
+ exports.ConnectorService = ConnectorService;
@@ -0,0 +1,29 @@
1
+ import { HotMeshGraph } from "../../types/hotmesh";
2
+ declare class DimensionService {
3
+ static targetLength: number;
4
+ /**
5
+ * entry point for compiler-type activities. This is called by the compiler
6
+ * to bind the sorted activity IDs to the trigger activity. These are then used
7
+ * at runtime by the activities to track job/activity status.
8
+ * @param graphs
9
+ */
10
+ static compile(graphs: HotMeshGraph[]): void;
11
+ /**
12
+ * All activities exist on a dimensional plane. Zero
13
+ * is the default and is implied if no dimension is
14
+ * present in the hash item key. EVERY value in the
15
+ * job ledger is dimensionalized even if the dimension
16
+ * is not present. The key, `AaA`, might not contain
17
+ * a dimensional index, but it is still implicitly
18
+ * dimensionalized as `AaA,0` (assuming a trigger).
19
+ * A value of `AxY,0,0,0,0,1,0,0` would reflect that
20
+ * an ancestor activity was dimensionalized beyond
21
+ * the default. The dimensional string must
22
+ * be included if not zero. There is likely a preceding
23
+ * sibling dimension, so it would not need to include
24
+ * the suffix, so these addresses are equivalent:
25
+ * `AxY,0,0,0,0,0,0,0` == `AxY` for said sibling.
26
+ */
27
+ static getSeed(index?: number): string;
28
+ }
29
+ export { DimensionService };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DimensionService = void 0;
4
+ class DimensionService {
5
+ /**
6
+ * entry point for compiler-type activities. This is called by the compiler
7
+ * to bind the sorted activity IDs to the trigger activity. These are then used
8
+ * at runtime by the activities to track job/activity status.
9
+ * @param graphs
10
+ */
11
+ static compile(graphs) {
12
+ }
13
+ /**
14
+ * All activities exist on a dimensional plane. Zero
15
+ * is the default and is implied if no dimension is
16
+ * present in the hash item key. EVERY value in the
17
+ * job ledger is dimensionalized even if the dimension
18
+ * is not present. The key, `AaA`, might not contain
19
+ * a dimensional index, but it is still implicitly
20
+ * dimensionalized as `AaA,0` (assuming a trigger).
21
+ * A value of `AxY,0,0,0,0,1,0,0` would reflect that
22
+ * an ancestor activity was dimensionalized beyond
23
+ * the default. The dimensional string must
24
+ * be included if not zero. There is likely a preceding
25
+ * sibling dimension, so it would not need to include
26
+ * the suffix, so these addresses are equivalent:
27
+ * `AxY,0,0,0,0,0,0,0` == `AxY` for said sibling.
28
+ */
29
+ static getSeed(index = 0) {
30
+ return `,${index}`;
31
+ }
32
+ }
33
+ exports.DimensionService = DimensionService;
34
+ //max int digit count that supports `hincrby`
35
+ DimensionService.targetLength = 15;
@@ -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,15 @@
1
+ import { WorkflowHandleService } from "./handle";
2
+ import { HotMeshService as HotMesh } from "../hotmesh";
3
+ import { ClientConfig, Connection, WorkflowOptions } from "../../types/durable";
4
+ export declare class ClientService {
5
+ connection: Connection;
6
+ options: WorkflowOptions;
7
+ static instances: Map<string, HotMesh | Promise<HotMesh>>;
8
+ constructor(config: ClientConfig);
9
+ getHotMesh: (worflowTopic: string) => Promise<HotMesh>;
10
+ workflow: {
11
+ start: (options: WorkflowOptions) => Promise<WorkflowHandleService>;
12
+ };
13
+ activateWorkflow(hotMesh: HotMesh, workflowTopic: string): Promise<void>;
14
+ static shutdown(): Promise<void>;
15
+ }
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientService = void 0;
4
+ const handle_1 = require("./handle");
5
+ const hotmesh_1 = require("../hotmesh");
6
+ const factory_1 = require("./factory");
7
+ /*
8
+ Here is an example of how the methods in this file are used:
9
+
10
+ ./client.ts
11
+
12
+ import { Durable } from '@hotmeshio/hotmesh';
13
+ import Redis from 'ioredis';
14
+ import { example } from './workflows';
15
+ import { nanoid } from 'nanoid';
16
+
17
+ async function run() {
18
+ const connection = await Durable.Connection.connect({
19
+ class: Redis,
20
+ options: {
21
+ host: 'localhost',
22
+ port: 6379,
23
+ },
24
+ });
25
+
26
+ const client = new Durable.Client({
27
+ connection,
28
+ });
29
+
30
+ const handle = await client.workflow.start({
31
+ args: ['HotMesh'],
32
+ taskQueue: 'hello-world',
33
+ workflowName: 'example',
34
+ workflowId: 'workflow-' + nanoid(),
35
+ });
36
+
37
+ console.log(`Started workflow ${handle.workflowId}`);
38
+ console.log(await handle.result());
39
+ }
40
+
41
+ run().catch((err) => {
42
+ console.error(err);
43
+ process.exit(1);
44
+ });
45
+
46
+ */
47
+ class ClientService {
48
+ constructor(config) {
49
+ this.getHotMesh = async (worflowTopic) => {
50
+ if (ClientService.instances.has(worflowTopic)) {
51
+ return await ClientService.instances.get(worflowTopic);
52
+ }
53
+ const hotMesh = hotmesh_1.HotMeshService.init({
54
+ appId: worflowTopic,
55
+ engine: {
56
+ redis: {
57
+ class: this.connection.class,
58
+ options: this.connection.options,
59
+ }
60
+ }
61
+ });
62
+ ClientService.instances.set(worflowTopic, hotMesh);
63
+ await this.activateWorkflow(await hotMesh, worflowTopic);
64
+ return hotMesh;
65
+ };
66
+ this.workflow = {
67
+ start: async (options) => {
68
+ const taskQueueName = options.taskQueue;
69
+ const workflowName = options.workflowName;
70
+ const trc = options.workflowTrace;
71
+ const spn = options.workflowSpan;
72
+ const workflowTopic = `${taskQueueName}-${workflowName}`;
73
+ const hotMesh = await this.getHotMesh(workflowTopic);
74
+ const payload = {
75
+ arguments: [...options.args],
76
+ workflowId: options.workflowId,
77
+ };
78
+ const context = { metadata: { trc, spn }, data: {} };
79
+ const jobId = await hotMesh.pub(workflowTopic, payload, context);
80
+ return new handle_1.WorkflowHandleService(hotMesh, workflowTopic, jobId);
81
+ },
82
+ };
83
+ this.connection = config.connection;
84
+ }
85
+ async activateWorkflow(hotMesh, workflowTopic) {
86
+ const version = '1';
87
+ const app = await hotMesh.engine.store.getApp(workflowTopic);
88
+ const appVersion = app?.version;
89
+ if (isNaN(appVersion)) {
90
+ try {
91
+ await hotMesh.deploy((0, factory_1.getWorkflowYAML)(workflowTopic, version));
92
+ await hotMesh.activate(version);
93
+ }
94
+ catch (err) {
95
+ hotMesh.engine.logger.error('durable-client-workflow-activation-err', err);
96
+ throw err;
97
+ }
98
+ }
99
+ }
100
+ static async shutdown() {
101
+ for (const [key, value] of ClientService.instances) {
102
+ const hotMesh = await value;
103
+ await hotMesh.stop();
104
+ }
105
+ }
106
+ }
107
+ ClientService.instances = new Map();
108
+ exports.ClientService = ClientService;
@@ -0,0 +1,4 @@
1
+ import { Connection, ConnectionConfig } from "../../types/durable";
2
+ export declare class ConnectionService {
3
+ static connect(config: ConnectionConfig): Promise<Connection>;
4
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionService = void 0;
4
+ /*
5
+ Here is an example of how the methods in this file are used:
6
+
7
+ ./client.ts
8
+
9
+ import { Durable } from '@hotmeshio/hotmesh';
10
+ import Redis from 'ioredis';
11
+ import { nanoid } from 'nanoid';
12
+
13
+ async function run() {
14
+ const connection = await Durable.Connection.connect({
15
+ class: Redis,
16
+ options: {
17
+ host: 'localhost',
18
+ port: 6379,
19
+ },
20
+ });
21
+
22
+ const client = new Durable.Client({
23
+ connection,
24
+ });
25
+
26
+ const handle = await client.workflow.start(example, {
27
+ taskQueue: 'hello-world',
28
+ args: ['HotMesh'],
29
+ workflowName: 'example',
30
+ workflowId: nanoid(),
31
+ });
32
+
33
+ console.log(`Started workflow ${handle.workflowId}`);
34
+ console.log(await handle.result());
35
+ }
36
+
37
+ run().catch((err) => {
38
+ console.error(err);
39
+ process.exit(1);
40
+ });
41
+
42
+ */
43
+ class ConnectionService {
44
+ static async connect(config) {
45
+ return {
46
+ class: config.class,
47
+ options: { ...config.options },
48
+ };
49
+ }
50
+ }
51
+ exports.ConnectionService = ConnectionService;
@@ -0,0 +1,3 @@
1
+ declare const getWorkflowYAML: (topic: string, version?: string) => string;
2
+ declare const getActivityYAML: (topic: string, version?: string) => string;
3
+ export { getActivityYAML, getWorkflowYAML };