@hotmeshio/hotmesh 0.3.32 → 0.4.0

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 (254) hide show
  1. package/README.md +128 -823
  2. package/build/index.d.ts +9 -9
  3. package/build/index.js +10 -10
  4. package/build/package.json +22 -21
  5. package/build/types/error.d.ts +5 -5
  6. package/build/types/exporter.d.ts +1 -1
  7. package/build/types/index.d.ts +3 -3
  8. package/build/types/manifest.d.ts +2 -2
  9. package/build/types/{meshflow.d.ts → memflow.d.ts} +15 -15
  10. package/build/types/meshdata.d.ts +3 -3
  11. package/build/types/postgres.d.ts +7 -0
  12. package/build/types/stream.d.ts +3 -0
  13. package/index.ts +11 -11
  14. package/package.json +22 -21
  15. package/typedoc.json +8 -7
  16. package/types/error.ts +5 -5
  17. package/types/exporter.ts +1 -1
  18. package/types/index.ts +7 -7
  19. package/types/manifest.ts +2 -2
  20. package/types/{meshflow.ts → memflow.ts} +15 -15
  21. package/types/meshdata.ts +3 -3
  22. package/types/postgres.ts +9 -0
  23. package/types/stream.ts +4 -0
  24. package/build/modules/enums.d.ts +0 -110
  25. package/build/modules/enums.js +0 -134
  26. package/build/modules/errors.d.ts +0 -124
  27. package/build/modules/errors.js +0 -191
  28. package/build/modules/key.d.ts +0 -66
  29. package/build/modules/key.js +0 -1
  30. package/build/modules/storage.d.ts +0 -3
  31. package/build/modules/storage.js +0 -5
  32. package/build/modules/utils.d.ts +0 -119
  33. package/build/modules/utils.js +0 -1
  34. package/build/services/activities/activity.d.ts +0 -104
  35. package/build/services/activities/activity.js +0 -1
  36. package/build/services/activities/await.d.ts +0 -12
  37. package/build/services/activities/await.js +0 -1
  38. package/build/services/activities/cycle.d.ts +0 -19
  39. package/build/services/activities/cycle.js +0 -1
  40. package/build/services/activities/hook.d.ts +0 -27
  41. package/build/services/activities/hook.js +0 -1
  42. package/build/services/activities/index.d.ts +0 -19
  43. package/build/services/activities/index.js +0 -1
  44. package/build/services/activities/interrupt.d.ts +0 -16
  45. package/build/services/activities/interrupt.js +0 -1
  46. package/build/services/activities/signal.d.ts +0 -20
  47. package/build/services/activities/signal.js +0 -1
  48. package/build/services/activities/trigger.d.ts +0 -37
  49. package/build/services/activities/trigger.js +0 -1
  50. package/build/services/activities/worker.d.ts +0 -12
  51. package/build/services/activities/worker.js +0 -1
  52. package/build/services/collator/index.d.ts +0 -111
  53. package/build/services/collator/index.js +0 -1
  54. package/build/services/compiler/deployer.d.ts +0 -40
  55. package/build/services/compiler/deployer.js +0 -1
  56. package/build/services/compiler/index.d.ts +0 -32
  57. package/build/services/compiler/index.js +0 -1
  58. package/build/services/compiler/validator.d.ts +0 -34
  59. package/build/services/compiler/validator.js +0 -1
  60. package/build/services/connector/factory.d.ts +0 -22
  61. package/build/services/connector/factory.js +0 -99
  62. package/build/services/connector/index.d.ts +0 -30
  63. package/build/services/connector/index.js +0 -54
  64. package/build/services/connector/providers/ioredis.d.ts +0 -9
  65. package/build/services/connector/providers/ioredis.js +0 -26
  66. package/build/services/connector/providers/nats.d.ts +0 -9
  67. package/build/services/connector/providers/nats.js +0 -34
  68. package/build/services/connector/providers/postgres.d.ts +0 -20
  69. package/build/services/connector/providers/postgres.js +0 -102
  70. package/build/services/connector/providers/redis.d.ts +0 -9
  71. package/build/services/connector/providers/redis.js +0 -38
  72. package/build/services/engine/index.d.ts +0 -264
  73. package/build/services/engine/index.js +0 -1
  74. package/build/services/exporter/index.d.ts +0 -44
  75. package/build/services/exporter/index.js +0 -1
  76. package/build/services/hotmesh/index.d.ts +0 -340
  77. package/build/services/hotmesh/index.js +0 -479
  78. package/build/services/logger/index.d.ts +0 -16
  79. package/build/services/logger/index.js +0 -54
  80. package/build/services/mapper/index.d.ts +0 -28
  81. package/build/services/mapper/index.js +0 -1
  82. package/build/services/meshcall/index.d.ts +0 -194
  83. package/build/services/meshcall/index.js +0 -452
  84. package/build/services/meshcall/schemas/factory.d.ts +0 -9
  85. package/build/services/meshcall/schemas/factory.js +0 -189
  86. package/build/services/meshdata/index.d.ts +0 -795
  87. package/build/services/meshdata/index.js +0 -1235
  88. package/build/services/meshflow/client.d.ts +0 -108
  89. package/build/services/meshflow/client.js +0 -371
  90. package/build/services/meshflow/connection.d.ts +0 -23
  91. package/build/services/meshflow/connection.js +0 -33
  92. package/build/services/meshflow/exporter.d.ts +0 -51
  93. package/build/services/meshflow/exporter.js +0 -1
  94. package/build/services/meshflow/handle.d.ts +0 -90
  95. package/build/services/meshflow/handle.js +0 -176
  96. package/build/services/meshflow/index.d.ts +0 -111
  97. package/build/services/meshflow/index.js +0 -117
  98. package/build/services/meshflow/schemas/factory.d.ts +0 -29
  99. package/build/services/meshflow/schemas/factory.js +0 -2492
  100. package/build/services/meshflow/search.d.ts +0 -142
  101. package/build/services/meshflow/search.js +0 -320
  102. package/build/services/meshflow/worker.d.ts +0 -124
  103. package/build/services/meshflow/worker.js +0 -514
  104. package/build/services/meshflow/workflow/all.d.ts +0 -7
  105. package/build/services/meshflow/workflow/all.js +0 -15
  106. package/build/services/meshflow/workflow/common.d.ts +0 -18
  107. package/build/services/meshflow/workflow/common.js +0 -45
  108. package/build/services/meshflow/workflow/context.d.ts +0 -6
  109. package/build/services/meshflow/workflow/context.js +0 -45
  110. package/build/services/meshflow/workflow/didRun.d.ts +0 -7
  111. package/build/services/meshflow/workflow/didRun.js +0 -22
  112. package/build/services/meshflow/workflow/emit.d.ts +0 -11
  113. package/build/services/meshflow/workflow/emit.js +0 -29
  114. package/build/services/meshflow/workflow/enrich.d.ts +0 -9
  115. package/build/services/meshflow/workflow/enrich.js +0 -17
  116. package/build/services/meshflow/workflow/execChild.d.ts +0 -18
  117. package/build/services/meshflow/workflow/execChild.js +0 -102
  118. package/build/services/meshflow/workflow/hook.d.ts +0 -9
  119. package/build/services/meshflow/workflow/hook.js +0 -40
  120. package/build/services/meshflow/workflow/index.d.ts +0 -70
  121. package/build/services/meshflow/workflow/index.js +0 -83
  122. package/build/services/meshflow/workflow/interrupt.d.ts +0 -9
  123. package/build/services/meshflow/workflow/interrupt.js +0 -24
  124. package/build/services/meshflow/workflow/isSideEffectAllowed.d.ts +0 -10
  125. package/build/services/meshflow/workflow/isSideEffectAllowed.js +0 -33
  126. package/build/services/meshflow/workflow/proxyActivities.d.ts +0 -20
  127. package/build/services/meshflow/workflow/proxyActivities.js +0 -97
  128. package/build/services/meshflow/workflow/random.d.ts +0 -6
  129. package/build/services/meshflow/workflow/random.js +0 -16
  130. package/build/services/meshflow/workflow/searchMethods.d.ts +0 -6
  131. package/build/services/meshflow/workflow/searchMethods.js +0 -25
  132. package/build/services/meshflow/workflow/signal.d.ts +0 -7
  133. package/build/services/meshflow/workflow/signal.js +0 -28
  134. package/build/services/meshflow/workflow/sleepFor.d.ts +0 -8
  135. package/build/services/meshflow/workflow/sleepFor.js +0 -35
  136. package/build/services/meshflow/workflow/trace.d.ts +0 -14
  137. package/build/services/meshflow/workflow/trace.js +0 -33
  138. package/build/services/meshflow/workflow/waitFor.d.ts +0 -8
  139. package/build/services/meshflow/workflow/waitFor.js +0 -35
  140. package/build/services/meshos/index.d.ts +0 -293
  141. package/build/services/meshos/index.js +0 -547
  142. package/build/services/pipe/functions/array.d.ts +0 -17
  143. package/build/services/pipe/functions/array.js +0 -1
  144. package/build/services/pipe/functions/bitwise.d.ts +0 -9
  145. package/build/services/pipe/functions/bitwise.js +0 -1
  146. package/build/services/pipe/functions/conditional.d.ts +0 -13
  147. package/build/services/pipe/functions/conditional.js +0 -1
  148. package/build/services/pipe/functions/cron.d.ts +0 -12
  149. package/build/services/pipe/functions/cron.js +0 -1
  150. package/build/services/pipe/functions/date.d.ts +0 -58
  151. package/build/services/pipe/functions/date.js +0 -1
  152. package/build/services/pipe/functions/index.d.ts +0 -29
  153. package/build/services/pipe/functions/index.js +0 -1
  154. package/build/services/pipe/functions/json.d.ts +0 -5
  155. package/build/services/pipe/functions/json.js +0 -1
  156. package/build/services/pipe/functions/logical.d.ts +0 -5
  157. package/build/services/pipe/functions/logical.js +0 -1
  158. package/build/services/pipe/functions/math.d.ts +0 -42
  159. package/build/services/pipe/functions/math.js +0 -1
  160. package/build/services/pipe/functions/number.d.ts +0 -21
  161. package/build/services/pipe/functions/number.js +0 -1
  162. package/build/services/pipe/functions/object.d.ts +0 -25
  163. package/build/services/pipe/functions/object.js +0 -1
  164. package/build/services/pipe/functions/string.d.ts +0 -23
  165. package/build/services/pipe/functions/string.js +0 -1
  166. package/build/services/pipe/functions/symbol.d.ts +0 -12
  167. package/build/services/pipe/functions/symbol.js +0 -1
  168. package/build/services/pipe/functions/unary.d.ts +0 -7
  169. package/build/services/pipe/functions/unary.js +0 -1
  170. package/build/services/pipe/index.d.ts +0 -48
  171. package/build/services/pipe/index.js +0 -1
  172. package/build/services/quorum/index.d.ts +0 -90
  173. package/build/services/quorum/index.js +0 -1
  174. package/build/services/reporter/index.d.ts +0 -50
  175. package/build/services/reporter/index.js +0 -1
  176. package/build/services/router/index.d.ts +0 -60
  177. package/build/services/router/index.js +0 -1
  178. package/build/services/search/factory.d.ts +0 -7
  179. package/build/services/search/factory.js +0 -24
  180. package/build/services/search/index.d.ts +0 -22
  181. package/build/services/search/index.js +0 -10
  182. package/build/services/search/providers/postgres/postgres.d.ts +0 -24
  183. package/build/services/search/providers/postgres/postgres.js +0 -1
  184. package/build/services/search/providers/redis/ioredis.d.ts +0 -18
  185. package/build/services/search/providers/redis/ioredis.js +0 -1
  186. package/build/services/search/providers/redis/redis.d.ts +0 -18
  187. package/build/services/search/providers/redis/redis.js +0 -1
  188. package/build/services/serializer/index.d.ts +0 -42
  189. package/build/services/serializer/index.js +0 -1
  190. package/build/services/store/cache.d.ts +0 -67
  191. package/build/services/store/cache.js +0 -128
  192. package/build/services/store/factory.d.ts +0 -8
  193. package/build/services/store/factory.js +0 -24
  194. package/build/services/store/index.d.ts +0 -89
  195. package/build/services/store/index.js +0 -9
  196. package/build/services/store/providers/postgres/kvsql.d.ts +0 -168
  197. package/build/services/store/providers/postgres/kvsql.js +0 -1
  198. package/build/services/store/providers/postgres/kvtables.d.ts +0 -20
  199. package/build/services/store/providers/postgres/kvtables.js +0 -1
  200. package/build/services/store/providers/postgres/kvtransaction.d.ts +0 -36
  201. package/build/services/store/providers/postgres/kvtransaction.js +0 -1
  202. package/build/services/store/providers/postgres/kvtypes/hash.d.ts +0 -60
  203. package/build/services/store/providers/postgres/kvtypes/hash.js +0 -1
  204. package/build/services/store/providers/postgres/kvtypes/list.d.ts +0 -33
  205. package/build/services/store/providers/postgres/kvtypes/list.js +0 -1
  206. package/build/services/store/providers/postgres/kvtypes/string.d.ts +0 -20
  207. package/build/services/store/providers/postgres/kvtypes/string.js +0 -1
  208. package/build/services/store/providers/postgres/kvtypes/zset.d.ts +0 -41
  209. package/build/services/store/providers/postgres/kvtypes/zset.js +0 -1
  210. package/build/services/store/providers/postgres/postgres.d.ts +0 -145
  211. package/build/services/store/providers/postgres/postgres.js +0 -1
  212. package/build/services/store/providers/redis/_base.d.ts +0 -137
  213. package/build/services/store/providers/redis/_base.js +0 -1
  214. package/build/services/store/providers/redis/ioredis.d.ts +0 -20
  215. package/build/services/store/providers/redis/ioredis.js +0 -1
  216. package/build/services/store/providers/redis/redis.d.ts +0 -18
  217. package/build/services/store/providers/redis/redis.js +0 -1
  218. package/build/services/store/providers/store-initializable.d.ts +0 -5
  219. package/build/services/store/providers/store-initializable.js +0 -1
  220. package/build/services/stream/factory.d.ts +0 -8
  221. package/build/services/stream/factory.js +0 -37
  222. package/build/services/stream/index.d.ts +0 -64
  223. package/build/services/stream/index.js +0 -11
  224. package/build/services/stream/providers/nats/nats.d.ts +0 -59
  225. package/build/services/stream/providers/nats/nats.js +0 -1
  226. package/build/services/stream/providers/postgres/kvtables.d.ts +0 -2
  227. package/build/services/stream/providers/postgres/kvtables.js +0 -1
  228. package/build/services/stream/providers/postgres/postgres.d.ts +0 -88
  229. package/build/services/stream/providers/postgres/postgres.js +0 -1
  230. package/build/services/stream/providers/redis/ioredis.d.ts +0 -60
  231. package/build/services/stream/providers/redis/ioredis.js +0 -1
  232. package/build/services/stream/providers/redis/redis.d.ts +0 -60
  233. package/build/services/stream/providers/redis/redis.js +0 -1
  234. package/build/services/stream/providers/stream-initializable.d.ts +0 -4
  235. package/build/services/stream/providers/stream-initializable.js +0 -1
  236. package/build/services/sub/factory.d.ts +0 -7
  237. package/build/services/sub/factory.js +0 -29
  238. package/build/services/sub/index.d.ts +0 -22
  239. package/build/services/sub/index.js +0 -10
  240. package/build/services/sub/providers/nats/nats.d.ts +0 -19
  241. package/build/services/sub/providers/nats/nats.js +0 -1
  242. package/build/services/sub/providers/postgres/postgres.d.ts +0 -19
  243. package/build/services/sub/providers/postgres/postgres.js +0 -1
  244. package/build/services/sub/providers/redis/ioredis.d.ts +0 -17
  245. package/build/services/sub/providers/redis/ioredis.js +0 -1
  246. package/build/services/sub/providers/redis/redis.d.ts +0 -17
  247. package/build/services/sub/providers/redis/redis.js +0 -1
  248. package/build/services/task/index.d.ts +0 -36
  249. package/build/services/task/index.js +0 -1
  250. package/build/services/telemetry/index.d.ts +0 -52
  251. package/build/services/telemetry/index.js +0 -1
  252. package/build/services/worker/index.d.ts +0 -77
  253. package/build/services/worker/index.js +0 -1
  254. /package/build/types/{meshflow.js → memflow.js} +0 -0
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.didRun = void 0;
4
- const common_1 = require("./common");
5
- const context_1 = require("./context");
6
- /**
7
- * Determines if a replayed execution result already exists for the given prefix.
8
- * @private
9
- * @param {string} prefix - Identifier prefix (e.g., 'proxy', 'child', 'start', 'wait', etc.)
10
- * @returns {Promise<[boolean, number, any]>} A tuple: [alreadyRan, executionIndex, restoredData]
11
- */
12
- async function didRun(prefix) {
13
- const { COUNTER, replay, workflowDimension } = (0, context_1.getContext)();
14
- const execIndex = COUNTER.counter = COUNTER.counter + 1;
15
- const sessionId = `-${prefix}${workflowDimension}-${execIndex}-`;
16
- if (sessionId in replay) {
17
- const restored = common_1.SerializerService.fromString(replay[sessionId]);
18
- return [true, execIndex, restored];
19
- }
20
- return [false, execIndex, null];
21
- }
22
- exports.didRun = didRun;
@@ -1,11 +0,0 @@
1
- import { StringAnyType } from './common';
2
- /**
3
- * Emits events to the event bus provider. Topics are prefixed with the quorum namespace.
4
- *
5
- * @param {StringAnyType} events - A mapping of topic => message to publish.
6
- * @param {{ once: boolean }} [config={ once: true }] - If `once` is true, events are emitted only once.
7
- * @returns {Promise<boolean>} True after emission completes.
8
- */
9
- export declare function emit(events: StringAnyType, config?: {
10
- once: boolean;
11
- }): Promise<boolean>;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.emit = void 0;
4
- const common_1 = require("./common");
5
- const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
6
- /**
7
- * Emits events to the event bus provider. Topics are prefixed with the quorum namespace.
8
- *
9
- * @param {StringAnyType} events - A mapping of topic => message to publish.
10
- * @param {{ once: boolean }} [config={ once: true }] - If `once` is true, events are emitted only once.
11
- * @returns {Promise<boolean>} True after emission completes.
12
- */
13
- async function emit(events, config = { once: true }) {
14
- const store = common_1.asyncLocalStorage.getStore();
15
- const workflowTopic = store.get('workflowTopic');
16
- const connection = store.get('connection');
17
- const namespace = store.get('namespace');
18
- const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
19
- connection,
20
- namespace,
21
- });
22
- if (!config.once || await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'emit')) {
23
- for (const [topic, message] of Object.entries(events)) {
24
- await hotMeshClient.quorum.pub({ topic, message });
25
- }
26
- }
27
- return true;
28
- }
29
- exports.emit = emit;
@@ -1,9 +0,0 @@
1
- import { StringStringType } from './common';
2
- /**
3
- * Adds custom user data to the backend workflow record (writes to HASH).
4
- * Runs exactly once during workflow execution.
5
- *
6
- * @param {StringStringType} fields - Key-value fields to enrich the workflow record.
7
- * @returns {Promise<boolean>} True when enrichment is completed.
8
- */
9
- export declare function enrich(fields: StringStringType): Promise<boolean>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.enrich = void 0;
4
- const searchMethods_1 = require("./searchMethods");
5
- /**
6
- * Adds custom user data to the backend workflow record (writes to HASH).
7
- * Runs exactly once during workflow execution.
8
- *
9
- * @param {StringStringType} fields - Key-value fields to enrich the workflow record.
10
- * @returns {Promise<boolean>} True when enrichment is completed.
11
- */
12
- async function enrich(fields) {
13
- const searchSession = await (0, searchMethods_1.search)();
14
- await searchSession.set(fields);
15
- return true;
16
- }
17
- exports.enrich = enrich;
@@ -1,18 +0,0 @@
1
- import { WorkflowOptions } from './common';
2
- /**
3
- * Spawns a child workflow and awaits the result, or if `await` is false, returns immediately.
4
- * @template T
5
- * @param {WorkflowOptions} options - Workflow options.
6
- * @returns {Promise<T>} Result of the child workflow.
7
- */
8
- export declare function execChild<T>(options: WorkflowOptions): Promise<T>;
9
- /**
10
- * Alias for execChild.
11
- */
12
- export declare const executeChild: typeof execChild;
13
- /**
14
- * Spawns a child workflow and returns the child Job ID without awaiting its completion.
15
- * @param {WorkflowOptions} options - Workflow options.
16
- * @returns {Promise<string>} The child job ID.
17
- */
18
- export declare function startChild(options: WorkflowOptions): Promise<string>;
@@ -1,102 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startChild = exports.executeChild = exports.execChild = void 0;
4
- const common_1 = require("./common");
5
- const context_1 = require("./context");
6
- const didRun_1 = require("./didRun");
7
- /**
8
- * Constructs the payload necessary to spawn a child workflow.
9
- * @private
10
- */
11
- function getChildInterruptPayload(context, options, execIndex) {
12
- const { workflowId, originJobId, workflowDimension, expire } = context;
13
- let childJobId;
14
- if (options.workflowId) {
15
- childJobId = options.workflowId;
16
- }
17
- else if (options.entity) {
18
- childJobId = `${options.entity}-${(0, common_1.guid)()}-${workflowDimension}-${execIndex}`;
19
- }
20
- else {
21
- childJobId = `-${options.workflowName}-${(0, common_1.guid)()}-${workflowDimension}-${execIndex}`;
22
- }
23
- const parentWorkflowId = workflowId;
24
- const taskQueueName = options.taskQueue ?? options.entity;
25
- const workflowName = options.entity ?? options.workflowName;
26
- const workflowTopic = `${taskQueueName}-${workflowName}`;
27
- return {
28
- arguments: [...(options.args || [])],
29
- await: options?.await ?? true,
30
- backoffCoefficient: options?.config?.backoffCoefficient ?? common_1.HMSH_MESHFLOW_EXP_BACKOFF,
31
- index: execIndex,
32
- maximumAttempts: options?.config?.maximumAttempts ?? common_1.HMSH_MESHFLOW_MAX_ATTEMPTS,
33
- maximumInterval: (0, common_1.s)(options?.config?.maximumInterval ?? common_1.HMSH_MESHFLOW_MAX_INTERVAL),
34
- originJobId: originJobId ?? workflowId,
35
- expire: options.expire ?? expire,
36
- persistent: options.persistent,
37
- signalIn: options.signalIn,
38
- parentWorkflowId,
39
- workflowDimension: workflowDimension,
40
- workflowId: childJobId,
41
- workflowTopic,
42
- };
43
- }
44
- /**
45
- * Spawns a child workflow and awaits the result, or if `await` is false, returns immediately.
46
- * @template T
47
- * @param {WorkflowOptions} options - Workflow options.
48
- * @returns {Promise<T>} Result of the child workflow.
49
- */
50
- async function execChild(options) {
51
- const isStartChild = options.await === false;
52
- const prefix = isStartChild ? 'start' : 'child';
53
- const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)(prefix);
54
- const context = (0, context_1.getContext)();
55
- const { canRetry, interruptionRegistry } = context;
56
- if (didRunAlready) {
57
- if (result?.$error && (!result.$error.is_stream_error || !canRetry)) {
58
- if (options?.config?.throwOnError !== false) {
59
- const code = result.$error.code;
60
- const message = result.$error.message;
61
- const stack = result.$error.stack;
62
- if (code === common_1.HMSH_CODE_MESHFLOW_FATAL) {
63
- throw new common_1.MeshFlowFatalError(message, stack);
64
- }
65
- else if (code === common_1.HMSH_CODE_MESHFLOW_MAXED) {
66
- throw new common_1.MeshFlowMaxedError(message, stack);
67
- }
68
- else if (code === common_1.HMSH_CODE_MESHFLOW_TIMEOUT) {
69
- throw new common_1.MeshFlowTimeoutError(message, stack);
70
- }
71
- else {
72
- throw new common_1.MeshFlowRetryError(message, stack);
73
- }
74
- }
75
- return result.$error;
76
- }
77
- else if (!result?.$error) {
78
- return result.data;
79
- }
80
- }
81
- const interruptionMessage = getChildInterruptPayload(context, options, execIndex);
82
- interruptionRegistry.push({
83
- code: common_1.HMSH_CODE_MESHFLOW_CHILD,
84
- ...interruptionMessage,
85
- });
86
- await (0, common_1.sleepImmediate)();
87
- throw new common_1.MeshFlowChildError(interruptionMessage);
88
- }
89
- exports.execChild = execChild;
90
- /**
91
- * Alias for execChild.
92
- */
93
- exports.executeChild = execChild;
94
- /**
95
- * Spawns a child workflow and returns the child Job ID without awaiting its completion.
96
- * @param {WorkflowOptions} options - Workflow options.
97
- * @returns {Promise<string>} The child job ID.
98
- */
99
- async function startChild(options) {
100
- return execChild({ ...options, await: false });
101
- }
102
- exports.startChild = startChild;
@@ -1,9 +0,0 @@
1
- import { HookOptions } from './common';
2
- /**
3
- * Spawns a hook from the main thread or a hook thread.
4
- * If entity/workflowName are not provided, defaults to the current workflow.
5
- *
6
- * @param {HookOptions} options - Hook configuration options.
7
- * @returns {Promise<string>} The resulting hook/stream ID.
8
- */
9
- export declare function hook(options: HookOptions): Promise<string>;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hook = void 0;
4
- const common_1 = require("./common");
5
- const context_1 = require("./context");
6
- const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
7
- /**
8
- * Spawns a hook from the main thread or a hook thread.
9
- * If entity/workflowName are not provided, defaults to the current workflow.
10
- *
11
- * @param {HookOptions} options - Hook configuration options.
12
- * @returns {Promise<string>} The resulting hook/stream ID.
13
- */
14
- async function hook(options) {
15
- const { workflowId, connection, namespace, workflowTopic } = (0, context_1.getContext)();
16
- const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
17
- connection,
18
- namespace,
19
- });
20
- if (await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'hook')) {
21
- const targetWorkflowId = options.workflowId ?? workflowId;
22
- let targetTopic;
23
- if (options.entity || (options.taskQueue && options.workflowName)) {
24
- targetTopic = `${options.taskQueue ?? options.entity}-${options.entity ?? options.workflowName}`;
25
- }
26
- else {
27
- targetTopic = workflowTopic;
28
- }
29
- const payload = {
30
- arguments: [...options.args],
31
- id: targetWorkflowId,
32
- workflowTopic: targetTopic,
33
- backoffCoefficient: options.config?.backoffCoefficient || common_1.HMSH_MESHFLOW_EXP_BACKOFF,
34
- maximumAttempts: options.config?.maximumAttempts || common_1.HMSH_MESHFLOW_MAX_ATTEMPTS,
35
- maximumInterval: (0, common_1.s)(options?.config?.maximumInterval ?? common_1.HMSH_MESHFLOW_MAX_INTERVAL),
36
- };
37
- return await hotMeshClient.hook(`${namespace}.flow.signal`, payload, common_1.StreamStatus.PENDING, 202);
38
- }
39
- }
40
- exports.hook = hook;
@@ -1,70 +0,0 @@
1
- import { getContext } from './context';
2
- import { didRun } from './didRun';
3
- import { isSideEffectAllowed } from './isSideEffectAllowed';
4
- import { trace } from './trace';
5
- import { enrich } from './enrich';
6
- import { emit } from './emit';
7
- import { execChild, startChild } from './execChild';
8
- import { proxyActivities } from './proxyActivities';
9
- import { search } from './searchMethods';
10
- import { random } from './random';
11
- import { signal } from './signal';
12
- import { hook } from './hook';
13
- import { interrupt } from './interrupt';
14
- import { all } from './all';
15
- import { sleepFor } from './sleepFor';
16
- import { waitFor } from './waitFor';
17
- import { HotMesh } from './common';
18
- /**
19
- * The WorkflowService class provides a set of static methods to be used within a workflow function.
20
- * These methods ensure deterministic replay, persistence of state, and error handling across
21
- * re-entrant workflow executions.
22
- *
23
- * By refactoring the original single-file implementation into submodules,
24
- * we maintain clear separation of concerns and improved maintainability,
25
- * while preserving type information and full functionality.
26
- *
27
- * @example
28
- * ```typescript
29
- * import { MeshFlow } from '@hotmeshio/hotmesh';
30
- *
31
- * export async function waitForExample(): Promise<[boolean, number]> {
32
- * const [s1, s2] = await Promise.all([
33
- * MeshFlow.workflow.waitFor<boolean>('my-sig-nal-1'),
34
- * MeshFlow.workflow.waitFor<number>('my-sig-nal-2')
35
- * ]);
36
- * return [s1, s2];
37
- * }
38
- * ```
39
- */
40
- export declare class WorkflowService {
41
- /**
42
- * @private
43
- * The constructor is private to prevent instantiation;
44
- * all methods are static.
45
- */
46
- private constructor();
47
- static getContext: typeof getContext;
48
- static didRun: typeof didRun;
49
- static isSideEffectAllowed: typeof isSideEffectAllowed;
50
- static trace: typeof trace;
51
- static enrich: typeof enrich;
52
- static emit: typeof emit;
53
- static execChild: typeof execChild;
54
- static executeChild: typeof execChild;
55
- static startChild: typeof startChild;
56
- static proxyActivities: typeof proxyActivities;
57
- static search: typeof search;
58
- static random: typeof random;
59
- static signal: typeof signal;
60
- static hook: typeof hook;
61
- static interrupt: typeof interrupt;
62
- static all: typeof all;
63
- static sleepFor: typeof sleepFor;
64
- static waitFor: typeof waitFor;
65
- /**
66
- * Return a handle to the HotMesh client hosting the workflow execution.
67
- * @returns {Promise<HotMesh>} The HotMesh client instance.
68
- */
69
- static getHotMesh(): Promise<HotMesh>;
70
- }
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WorkflowService = void 0;
4
- const context_1 = require("./context");
5
- const didRun_1 = require("./didRun");
6
- const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
7
- const trace_1 = require("./trace");
8
- const enrich_1 = require("./enrich");
9
- const emit_1 = require("./emit");
10
- const execChild_1 = require("./execChild");
11
- const proxyActivities_1 = require("./proxyActivities");
12
- const searchMethods_1 = require("./searchMethods");
13
- const random_1 = require("./random");
14
- const signal_1 = require("./signal");
15
- const hook_1 = require("./hook");
16
- const interrupt_1 = require("./interrupt");
17
- const all_1 = require("./all");
18
- const sleepFor_1 = require("./sleepFor");
19
- const waitFor_1 = require("./waitFor");
20
- const common_1 = require("./common");
21
- /**
22
- * The WorkflowService class provides a set of static methods to be used within a workflow function.
23
- * These methods ensure deterministic replay, persistence of state, and error handling across
24
- * re-entrant workflow executions.
25
- *
26
- * By refactoring the original single-file implementation into submodules,
27
- * we maintain clear separation of concerns and improved maintainability,
28
- * while preserving type information and full functionality.
29
- *
30
- * @example
31
- * ```typescript
32
- * import { MeshFlow } from '@hotmeshio/hotmesh';
33
- *
34
- * export async function waitForExample(): Promise<[boolean, number]> {
35
- * const [s1, s2] = await Promise.all([
36
- * MeshFlow.workflow.waitFor<boolean>('my-sig-nal-1'),
37
- * MeshFlow.workflow.waitFor<number>('my-sig-nal-2')
38
- * ]);
39
- * return [s1, s2];
40
- * }
41
- * ```
42
- */
43
- class WorkflowService {
44
- /**
45
- * @private
46
- * The constructor is private to prevent instantiation;
47
- * all methods are static.
48
- */
49
- constructor() { }
50
- /**
51
- * Return a handle to the HotMesh client hosting the workflow execution.
52
- * @returns {Promise<HotMesh>} The HotMesh client instance.
53
- */
54
- static async getHotMesh() {
55
- const store = common_1.asyncLocalStorage.getStore();
56
- const workflowTopic = store.get('workflowTopic');
57
- const connection = store.get('connection');
58
- const namespace = store.get('namespace');
59
- return await common_1.WorkerService.getHotMesh(workflowTopic, {
60
- connection,
61
- namespace,
62
- });
63
- }
64
- }
65
- WorkflowService.getContext = context_1.getContext;
66
- WorkflowService.didRun = didRun_1.didRun;
67
- WorkflowService.isSideEffectAllowed = isSideEffectAllowed_1.isSideEffectAllowed;
68
- WorkflowService.trace = trace_1.trace;
69
- WorkflowService.enrich = enrich_1.enrich;
70
- WorkflowService.emit = emit_1.emit;
71
- WorkflowService.execChild = execChild_1.execChild;
72
- WorkflowService.executeChild = execChild_1.executeChild;
73
- WorkflowService.startChild = execChild_1.startChild;
74
- WorkflowService.proxyActivities = proxyActivities_1.proxyActivities;
75
- WorkflowService.search = searchMethods_1.search;
76
- WorkflowService.random = random_1.random;
77
- WorkflowService.signal = signal_1.signal;
78
- WorkflowService.hook = hook_1.hook;
79
- WorkflowService.interrupt = interrupt_1.interrupt;
80
- WorkflowService.all = all_1.all;
81
- WorkflowService.sleepFor = sleepFor_1.sleepFor;
82
- WorkflowService.waitFor = waitFor_1.waitFor;
83
- exports.WorkflowService = WorkflowService;
@@ -1,9 +0,0 @@
1
- import { JobInterruptOptions } from './common';
2
- /**
3
- * Interrupts a running job by sending an interruption request.
4
- *
5
- * @param {string} jobId - The ID of the job to interrupt.
6
- * @param {JobInterruptOptions} options - Additional interruption options.
7
- * @returns {Promise<string|void>} Result of the interruption, if any.
8
- */
9
- export declare function interrupt(jobId: string, options?: JobInterruptOptions): Promise<string | void>;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.interrupt = void 0;
4
- const common_1 = require("./common");
5
- const context_1 = require("./context");
6
- const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
7
- /**
8
- * Interrupts a running job by sending an interruption request.
9
- *
10
- * @param {string} jobId - The ID of the job to interrupt.
11
- * @param {JobInterruptOptions} options - Additional interruption options.
12
- * @returns {Promise<string|void>} Result of the interruption, if any.
13
- */
14
- async function interrupt(jobId, options = {}) {
15
- const { workflowTopic, connection, namespace } = (0, context_1.getContext)();
16
- const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
17
- connection,
18
- namespace,
19
- });
20
- if (await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'interrupt')) {
21
- return await hotMeshClient.interrupt(`${hotMeshClient.appId}.execute`, jobId, options);
22
- }
23
- }
24
- exports.interrupt = interrupt;
@@ -1,10 +0,0 @@
1
- import { HotMesh } from './common';
2
- /**
3
- * Checks if a side-effect is allowed to run. This ensures certain actions
4
- * are executed exactly once.
5
- * @private
6
- * @param {HotMesh} hotMeshClient - The HotMesh client.
7
- * @param {string} prefix - A unique prefix representing the action (e.g., 'trace', 'emit', etc.)
8
- * @returns {Promise<boolean>} True if the side effect can run, false otherwise.
9
- */
10
- export declare function isSideEffectAllowed(hotMeshClient: HotMesh, prefix: string): Promise<boolean>;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSideEffectAllowed = void 0;
4
- const common_1 = require("./common");
5
- /**
6
- * Checks if a side-effect is allowed to run. This ensures certain actions
7
- * are executed exactly once.
8
- * @private
9
- * @param {HotMesh} hotMeshClient - The HotMesh client.
10
- * @param {string} prefix - A unique prefix representing the action (e.g., 'trace', 'emit', etc.)
11
- * @returns {Promise<boolean>} True if the side effect can run, false otherwise.
12
- */
13
- async function isSideEffectAllowed(hotMeshClient, prefix) {
14
- const store = common_1.asyncLocalStorage.getStore();
15
- const workflowId = store.get('workflowId');
16
- const workflowDimension = store.get('workflowDimension') ?? '';
17
- const COUNTER = store.get('counter');
18
- const execIndex = COUNTER.counter = COUNTER.counter + 1;
19
- const sessionId = `-${prefix}${workflowDimension}-${execIndex}-`;
20
- const replay = store.get('replay');
21
- if (sessionId in replay) {
22
- return false;
23
- }
24
- const keyParams = {
25
- appId: hotMeshClient.appId,
26
- jobId: workflowId,
27
- };
28
- const workflowGuid = common_1.KeyService.mintKey(hotMeshClient.namespace, common_1.KeyType.JOB_STATE, keyParams);
29
- const searchClient = hotMeshClient.engine.search;
30
- const guidValue = await searchClient.incrementFieldByFloat(workflowGuid, sessionId, 1);
31
- return guidValue === 1;
32
- }
33
- exports.isSideEffectAllowed = isSideEffectAllowed;
@@ -1,20 +0,0 @@
1
- import { ActivityConfig, ProxyType, MeshFlowProxyErrorType } from './common';
2
- import { getContext } from './context';
3
- /**
4
- * Constructs payload for spawning a proxyActivity job.
5
- * @private
6
- */
7
- declare function getProxyInterruptPayload(context: ReturnType<typeof getContext>, activityName: string, execIndex: number, args: any[], options?: ActivityConfig): MeshFlowProxyErrorType;
8
- /**
9
- * Wraps a single activity in a proxy, orchestrating its execution and replay.
10
- * @private
11
- */
12
- declare function wrapActivity<T>(activityName: string, options?: ActivityConfig): T;
13
- /**
14
- * Provides a proxy for defined activities, ensuring deterministic replay and retry.
15
- * @template ACT
16
- * @param {ActivityConfig} [options] - Optional activity config (includes retryPolicy).
17
- * @returns {ProxyType<ACT>} A proxy to call activities as if local, but durably managed by the workflow.
18
- */
19
- export declare function proxyActivities<ACT>(options?: ActivityConfig): ProxyType<ACT>;
20
- export { wrapActivity, getProxyInterruptPayload };
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProxyInterruptPayload = exports.wrapActivity = exports.proxyActivities = void 0;
4
- const common_1 = require("./common");
5
- const context_1 = require("./context");
6
- const didRun_1 = require("./didRun");
7
- /**
8
- * Constructs payload for spawning a proxyActivity job.
9
- * @private
10
- */
11
- function getProxyInterruptPayload(context, activityName, execIndex, args, options) {
12
- const { workflowDimension, workflowId, originJobId, workflowTopic, expire } = context;
13
- const activityTopic = `${workflowTopic}-activity`;
14
- const activityJobId = `-${workflowId}-$${activityName}${workflowDimension}-${execIndex}`;
15
- let maximumInterval;
16
- if (options?.retryPolicy?.maximumInterval) {
17
- maximumInterval = (0, common_1.s)(options.retryPolicy.maximumInterval);
18
- }
19
- return {
20
- arguments: args,
21
- workflowDimension,
22
- index: execIndex,
23
- originJobId: originJobId || workflowId,
24
- parentWorkflowId: workflowId,
25
- workflowId: activityJobId,
26
- workflowTopic: activityTopic,
27
- activityName,
28
- expire: options?.expire ?? expire,
29
- backoffCoefficient: options?.retryPolicy?.backoffCoefficient ?? undefined,
30
- maximumAttempts: options?.retryPolicy?.maximumAttempts ?? undefined,
31
- maximumInterval: maximumInterval ?? undefined,
32
- };
33
- }
34
- exports.getProxyInterruptPayload = getProxyInterruptPayload;
35
- /**
36
- * Wraps a single activity in a proxy, orchestrating its execution and replay.
37
- * @private
38
- */
39
- function wrapActivity(activityName, options) {
40
- return async function (...args) {
41
- const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)('proxy');
42
- if (didRunAlready) {
43
- if (result?.$error) {
44
- if (options?.retryPolicy?.throwOnError !== false) {
45
- const code = result.$error.code;
46
- const message = result.$error.message;
47
- const stack = result.$error.stack;
48
- if (code === common_1.HMSH_CODE_MESHFLOW_FATAL) {
49
- throw new common_1.MeshFlowFatalError(message, stack);
50
- }
51
- else if (code === common_1.HMSH_CODE_MESHFLOW_MAXED) {
52
- throw new common_1.MeshFlowMaxedError(message, stack);
53
- }
54
- else if (code === common_1.HMSH_CODE_MESHFLOW_TIMEOUT) {
55
- throw new common_1.MeshFlowTimeoutError(message, stack);
56
- }
57
- else {
58
- // Non-fatal error
59
- }
60
- }
61
- return result.$error;
62
- }
63
- return result.data;
64
- }
65
- const context = (0, context_1.getContext)();
66
- const { interruptionRegistry } = context;
67
- const interruptionMessage = getProxyInterruptPayload(context, activityName, execIndex, args, options);
68
- interruptionRegistry.push({
69
- code: common_1.HMSH_CODE_MESHFLOW_PROXY,
70
- ...interruptionMessage,
71
- });
72
- await (0, common_1.sleepImmediate)();
73
- throw new common_1.MeshFlowProxyError(interruptionMessage);
74
- };
75
- }
76
- exports.wrapActivity = wrapActivity;
77
- /**
78
- * Provides a proxy for defined activities, ensuring deterministic replay and retry.
79
- * @template ACT
80
- * @param {ActivityConfig} [options] - Optional activity config (includes retryPolicy).
81
- * @returns {ProxyType<ACT>} A proxy to call activities as if local, but durably managed by the workflow.
82
- */
83
- function proxyActivities(options) {
84
- if (options?.activities) {
85
- common_1.WorkerService.registerActivities(options.activities);
86
- }
87
- const proxy = {};
88
- const keys = Object.keys(common_1.WorkerService.activityRegistry);
89
- if (keys.length) {
90
- keys.forEach((key) => {
91
- const activityFunction = common_1.WorkerService.activityRegistry[key];
92
- proxy[key] = wrapActivity(key, options);
93
- });
94
- }
95
- return proxy;
96
- }
97
- exports.proxyActivities = proxyActivities;
@@ -1,6 +0,0 @@
1
- /**
2
- * Returns a deterministic random number between 0 and 1. The number is derived from the
3
- * current execution index, ensuring deterministic replay.
4
- * @returns {number} A deterministic pseudo-random number between 0 and 1.
5
- */
6
- export declare function random(): number;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.random = void 0;
4
- const common_1 = require("./common");
5
- /**
6
- * Returns a deterministic random number between 0 and 1. The number is derived from the
7
- * current execution index, ensuring deterministic replay.
8
- * @returns {number} A deterministic pseudo-random number between 0 and 1.
9
- */
10
- function random() {
11
- const store = common_1.asyncLocalStorage.getStore();
12
- const COUNTER = store.get('counter');
13
- const seed = COUNTER.counter = COUNTER.counter + 1;
14
- return (0, common_1.deterministicRandom)(seed);
15
- }
16
- exports.random = random;
@@ -1,6 +0,0 @@
1
- import { Search } from './common';
2
- /**
3
- * Returns a search session handle for interacting with the workflow's HASH storage.
4
- * @returns {Promise<Search>} A search session for workflow data.
5
- */
6
- export declare function search(): Promise<Search>;