@hotmeshio/hotmesh 0.12.1 → 0.14.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 (202) hide show
  1. package/README.md +18 -22
  2. package/build/modules/enums.d.ts +60 -5
  3. package/build/modules/enums.js +62 -7
  4. package/build/modules/errors.d.ts +15 -2
  5. package/build/modules/errors.js +17 -1
  6. package/build/modules/storage.d.ts +1 -0
  7. package/build/modules/storage.js +2 -1
  8. package/build/package.json +8 -2
  9. package/build/services/activities/activity/context.d.ts +22 -0
  10. package/build/services/activities/activity/context.js +76 -0
  11. package/build/services/activities/activity/index.d.ts +116 -0
  12. package/build/services/activities/activity/index.js +299 -0
  13. package/build/services/activities/activity/mapping.d.ts +12 -0
  14. package/build/services/activities/activity/mapping.js +63 -0
  15. package/build/services/activities/activity/process.d.ts +28 -0
  16. package/build/services/activities/activity/process.js +100 -0
  17. package/build/services/activities/activity/protocol.d.ts +39 -0
  18. package/build/services/activities/activity/protocol.js +151 -0
  19. package/build/services/activities/activity/state.d.ts +40 -0
  20. package/build/services/activities/activity/state.js +143 -0
  21. package/build/services/activities/activity/transition.d.ts +23 -0
  22. package/build/services/activities/activity/transition.js +71 -0
  23. package/build/services/activities/activity/verify.d.ts +22 -0
  24. package/build/services/activities/activity/verify.js +85 -0
  25. package/build/services/activities/await.d.ts +1 -4
  26. package/build/services/activities/await.js +2 -36
  27. package/build/services/activities/cycle.d.ts +1 -11
  28. package/build/services/activities/cycle.js +3 -46
  29. package/build/services/activities/hook.d.ts +2 -11
  30. package/build/services/activities/hook.js +30 -50
  31. package/build/services/activities/interrupt.d.ts +2 -4
  32. package/build/services/activities/interrupt.js +4 -38
  33. package/build/services/activities/signal.d.ts +1 -11
  34. package/build/services/activities/signal.js +3 -48
  35. package/build/services/activities/trigger.d.ts +1 -3
  36. package/build/services/activities/trigger.js +0 -3
  37. package/build/services/activities/worker.d.ts +3 -6
  38. package/build/services/activities/worker.js +4 -40
  39. package/build/services/connector/factory.d.ts +6 -0
  40. package/build/services/connector/factory.js +24 -0
  41. package/build/services/dba/index.d.ts +14 -4
  42. package/build/services/dba/index.js +57 -18
  43. package/build/services/durable/activity.d.ts +30 -0
  44. package/build/services/durable/activity.js +46 -0
  45. package/build/services/durable/client.d.ts +26 -31
  46. package/build/services/durable/client.js +26 -31
  47. package/build/services/durable/connection.d.ts +13 -7
  48. package/build/services/durable/connection.js +13 -7
  49. package/build/services/durable/exporter.d.ts +2 -2
  50. package/build/services/durable/exporter.js +27 -12
  51. package/build/services/durable/handle.d.ts +59 -41
  52. package/build/services/durable/handle.js +61 -41
  53. package/build/services/durable/index.d.ts +152 -283
  54. package/build/services/durable/index.js +161 -289
  55. package/build/services/durable/interceptor.d.ts +43 -33
  56. package/build/services/durable/interceptor.js +59 -39
  57. package/build/services/durable/schemas/factory.d.ts +2 -3
  58. package/build/services/durable/schemas/factory.js +180 -30
  59. package/build/services/durable/telemetry.d.ts +80 -0
  60. package/build/services/durable/telemetry.js +137 -0
  61. package/build/services/durable/worker.d.ts +100 -21
  62. package/build/services/durable/worker.js +314 -60
  63. package/build/services/durable/workflow/all.d.ts +1 -1
  64. package/build/services/durable/workflow/all.js +1 -1
  65. package/build/services/durable/workflow/cancellationScope.d.ts +104 -0
  66. package/build/services/durable/workflow/cancellationScope.js +139 -0
  67. package/build/services/durable/workflow/common.d.ts +5 -4
  68. package/build/services/durable/workflow/common.js +6 -1
  69. package/build/services/durable/workflow/{waitFor.d.ts → condition.d.ts} +9 -8
  70. package/build/services/durable/workflow/{waitFor.js → condition.js} +44 -11
  71. package/build/services/durable/workflow/continueAsNew.d.ts +65 -0
  72. package/build/services/durable/workflow/continueAsNew.js +92 -0
  73. package/build/services/durable/workflow/didRun.d.ts +2 -2
  74. package/build/services/durable/workflow/didRun.js +4 -4
  75. package/build/services/durable/workflow/enrich.d.ts +5 -0
  76. package/build/services/durable/workflow/enrich.js +5 -0
  77. package/build/services/durable/workflow/entityMethods.d.ts +7 -0
  78. package/build/services/durable/workflow/entityMethods.js +7 -0
  79. package/build/services/durable/workflow/execHook.js +3 -3
  80. package/build/services/durable/workflow/execHookBatch.js +2 -2
  81. package/build/services/durable/workflow/{execChild.d.ts → executeChild.d.ts} +4 -40
  82. package/build/services/durable/workflow/{execChild.js → executeChild.js} +36 -45
  83. package/build/services/durable/workflow/hook.d.ts +1 -1
  84. package/build/services/durable/workflow/hook.js +4 -3
  85. package/build/services/durable/workflow/index.d.ts +45 -50
  86. package/build/services/durable/workflow/index.js +46 -51
  87. package/build/services/durable/workflow/interruption.d.ts +7 -6
  88. package/build/services/durable/workflow/interruption.js +11 -7
  89. package/build/services/durable/workflow/patched.d.ts +72 -0
  90. package/build/services/durable/workflow/patched.js +110 -0
  91. package/build/services/durable/workflow/proxyActivities.d.ts +7 -7
  92. package/build/services/durable/workflow/proxyActivities.js +51 -15
  93. package/build/services/durable/workflow/searchMethods.d.ts +7 -0
  94. package/build/services/durable/workflow/searchMethods.js +7 -0
  95. package/build/services/durable/workflow/signal.d.ts +4 -4
  96. package/build/services/durable/workflow/signal.js +4 -4
  97. package/build/services/durable/workflow/{sleepFor.d.ts → sleep.d.ts} +7 -7
  98. package/build/services/durable/workflow/{sleepFor.js → sleep.js} +39 -10
  99. package/build/services/durable/workflow/terminate.d.ts +55 -0
  100. package/build/services/durable/workflow/{interrupt.js → terminate.js} +21 -21
  101. package/build/services/durable/workflow/trace.js +2 -2
  102. package/build/services/durable/workflow/uuid4.d.ts +14 -0
  103. package/build/services/durable/workflow/uuid4.js +39 -0
  104. package/build/services/durable/workflow/{context.d.ts → workflowInfo.d.ts} +5 -5
  105. package/build/services/durable/workflow/{context.js → workflowInfo.js} +7 -7
  106. package/build/services/engine/compiler.d.ts +19 -0
  107. package/build/services/engine/compiler.js +20 -0
  108. package/build/services/engine/completion.d.ts +46 -0
  109. package/build/services/engine/completion.js +145 -0
  110. package/build/services/engine/dispatch.d.ts +24 -0
  111. package/build/services/engine/dispatch.js +98 -0
  112. package/build/services/engine/index.d.ts +49 -81
  113. package/build/services/engine/index.js +175 -573
  114. package/build/services/engine/init.d.ts +42 -0
  115. package/build/services/engine/init.js +74 -0
  116. package/build/services/engine/pubsub.d.ts +50 -0
  117. package/build/services/engine/pubsub.js +118 -0
  118. package/build/services/engine/reporting.d.ts +20 -0
  119. package/build/services/engine/reporting.js +38 -0
  120. package/build/services/engine/schema.d.ts +23 -0
  121. package/build/services/engine/schema.js +62 -0
  122. package/build/services/engine/signal.d.ts +57 -0
  123. package/build/services/engine/signal.js +117 -0
  124. package/build/services/engine/state.d.ts +35 -0
  125. package/build/services/engine/state.js +61 -0
  126. package/build/services/engine/version.d.ts +31 -0
  127. package/build/services/engine/version.js +73 -0
  128. package/build/services/hotmesh/deployment.d.ts +21 -0
  129. package/build/services/hotmesh/deployment.js +25 -0
  130. package/build/services/hotmesh/index.d.ts +142 -533
  131. package/build/services/hotmesh/index.js +223 -674
  132. package/build/services/hotmesh/init.d.ts +42 -0
  133. package/build/services/hotmesh/init.js +93 -0
  134. package/build/services/hotmesh/jobs.d.ts +67 -0
  135. package/build/services/hotmesh/jobs.js +99 -0
  136. package/build/services/hotmesh/pubsub.d.ts +38 -0
  137. package/build/services/hotmesh/pubsub.js +54 -0
  138. package/build/services/hotmesh/quorum.d.ts +30 -0
  139. package/build/services/hotmesh/quorum.js +62 -0
  140. package/build/services/hotmesh/validation.d.ts +6 -0
  141. package/build/services/hotmesh/validation.js +28 -0
  142. package/build/services/quorum/index.js +1 -0
  143. package/build/services/router/consumption/index.d.ts +11 -5
  144. package/build/services/router/consumption/index.js +24 -17
  145. package/build/services/router/error-handling/index.d.ts +2 -2
  146. package/build/services/router/error-handling/index.js +14 -14
  147. package/build/services/router/index.d.ts +1 -1
  148. package/build/services/router/index.js +2 -2
  149. package/build/services/serializer/index.d.ts +22 -0
  150. package/build/services/serializer/index.js +39 -1
  151. package/build/services/store/index.d.ts +1 -0
  152. package/build/services/store/providers/postgres/exporter-sql.d.ts +2 -2
  153. package/build/services/store/providers/postgres/exporter-sql.js +4 -4
  154. package/build/services/store/providers/postgres/kvtables.js +7 -6
  155. package/build/services/store/providers/postgres/kvtypes/hash/basic.js +67 -52
  156. package/build/services/store/providers/postgres/kvtypes/hash/jsonb.js +87 -72
  157. package/build/services/store/providers/postgres/kvtypes/hash/udata.js +106 -79
  158. package/build/services/store/providers/postgres/kvtypes/hash/utils.d.ts +16 -0
  159. package/build/services/store/providers/postgres/kvtypes/hash/utils.js +29 -16
  160. package/build/services/store/providers/postgres/postgres.d.ts +1 -0
  161. package/build/services/store/providers/postgres/postgres.js +14 -4
  162. package/build/services/stream/factory.d.ts +3 -1
  163. package/build/services/stream/factory.js +2 -2
  164. package/build/services/stream/index.d.ts +1 -0
  165. package/build/services/stream/providers/nats/nats.d.ts +1 -0
  166. package/build/services/stream/providers/nats/nats.js +1 -0
  167. package/build/services/stream/providers/postgres/credentials.d.ts +56 -0
  168. package/build/services/stream/providers/postgres/credentials.js +129 -0
  169. package/build/services/stream/providers/postgres/kvtables.js +18 -0
  170. package/build/services/stream/providers/postgres/messages.js +7 -7
  171. package/build/services/stream/providers/postgres/notifications.js +16 -2
  172. package/build/services/stream/providers/postgres/postgres.d.ts +7 -0
  173. package/build/services/stream/providers/postgres/postgres.js +35 -4
  174. package/build/services/stream/providers/postgres/procedures.d.ts +21 -0
  175. package/build/services/stream/providers/postgres/procedures.js +213 -0
  176. package/build/services/stream/providers/postgres/secured.d.ts +34 -0
  177. package/build/services/stream/providers/postgres/secured.js +146 -0
  178. package/build/services/stream/providers/postgres/stats.d.ts +1 -0
  179. package/build/services/stream/providers/postgres/stats.js +1 -0
  180. package/build/services/stream/registry.d.ts +1 -1
  181. package/build/services/stream/registry.js +5 -2
  182. package/build/services/telemetry/index.d.ts +10 -1
  183. package/build/services/telemetry/index.js +40 -7
  184. package/build/services/worker/credentials.d.ts +51 -0
  185. package/build/services/worker/credentials.js +87 -0
  186. package/build/services/worker/index.d.ts +2 -2
  187. package/build/services/worker/index.js +7 -6
  188. package/build/types/codec.d.ts +84 -0
  189. package/build/types/codec.js +2 -0
  190. package/build/types/dba.d.ts +39 -3
  191. package/build/types/durable.d.ts +123 -25
  192. package/build/types/error.d.ts +10 -0
  193. package/build/types/exporter.d.ts +1 -1
  194. package/build/types/hotmesh.d.ts +67 -4
  195. package/build/types/index.d.ts +2 -1
  196. package/build/types/provider.d.ts +2 -2
  197. package/build/types/quorum.d.ts +35 -1
  198. package/build/types/stream.d.ts +12 -6
  199. package/package.json +8 -2
  200. package/build/services/activities/activity.d.ts +0 -192
  201. package/build/services/activities/activity.js +0 -786
  202. package/build/services/durable/workflow/interrupt.d.ts +0 -55
@@ -51,6 +51,13 @@ const common_1 = require("./common");
51
51
  * }
52
52
  * ```
53
53
  *
54
+ * **Not available with `workerCredentials`.** This method writes directly
55
+ * to the `jobs` and `jobs_attributes` tables, bypassing the SECURITY
56
+ * DEFINER stored procedures that scoped worker roles are restricted to.
57
+ * Workers connecting with `workerCredentials` will receive a permission
58
+ * error. Use `search()` only in workflows running with full database
59
+ * credentials.
60
+ *
54
61
  * @returns {Promise<Search>} A search session scoped to the current workflow job.
55
62
  */
56
63
  async function search() {
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Sends a signal payload to a paused workflow thread that is awaiting this
3
- * `signalId` via `waitFor()`. Signals are the primary mechanism for
3
+ * `signalId` via `condition()`. Signals are the primary mechanism for
4
4
  * inter-workflow communication and for delivering results from hook
5
5
  * functions back to the orchestrating workflow.
6
6
  *
7
7
  * `signal` is the **send** side of the coordination pair. The **receive**
8
- * side is `waitFor()`. A signal can be sent from:
8
+ * side is `condition()`. A signal can be sent from:
9
9
  * - Another workflow function
10
10
  * - A hook function (most common pattern with `execHook`)
11
11
  * - An external client via `Durable.Client.workflow.signal()`
@@ -40,7 +40,7 @@
40
40
  * const { prepareData } = Durable.workflow.proxyActivities<typeof activities>();
41
41
  * const data = await prepareData();
42
42
  *
43
- * // Signal another workflow that is paused on waitFor('data-ready')
43
+ * // Signal another workflow that is paused on condition('data-ready')
44
44
  * await Durable.workflow.signal('data-ready', { payload: data });
45
45
  * }
46
46
  * ```
@@ -51,7 +51,7 @@
51
51
  * await client.workflow.signal('approval-signal', { approved: true });
52
52
  * ```
53
53
  *
54
- * @param {string} signalId - Unique signal identifier that matches a `waitFor()` call.
54
+ * @param {string} signalId - Unique signal identifier that matches a `condition()` call.
55
55
  * @param {Record<any, any>} data - The payload to deliver to the waiting workflow.
56
56
  * @returns {Promise<string>} The resulting hook/stream ID.
57
57
  */
@@ -5,12 +5,12 @@ const common_1 = require("./common");
5
5
  const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
6
6
  /**
7
7
  * Sends a signal payload to a paused workflow thread that is awaiting this
8
- * `signalId` via `waitFor()`. Signals are the primary mechanism for
8
+ * `signalId` via `condition()`. Signals are the primary mechanism for
9
9
  * inter-workflow communication and for delivering results from hook
10
10
  * functions back to the orchestrating workflow.
11
11
  *
12
12
  * `signal` is the **send** side of the coordination pair. The **receive**
13
- * side is `waitFor()`. A signal can be sent from:
13
+ * side is `condition()`. A signal can be sent from:
14
14
  * - Another workflow function
15
15
  * - A hook function (most common pattern with `execHook`)
16
16
  * - An external client via `Durable.Client.workflow.signal()`
@@ -45,7 +45,7 @@ const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
45
45
  * const { prepareData } = Durable.workflow.proxyActivities<typeof activities>();
46
46
  * const data = await prepareData();
47
47
  *
48
- * // Signal another workflow that is paused on waitFor('data-ready')
48
+ * // Signal another workflow that is paused on condition('data-ready')
49
49
  * await Durable.workflow.signal('data-ready', { payload: data });
50
50
  * }
51
51
  * ```
@@ -56,7 +56,7 @@ const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
56
56
  * await client.workflow.signal('approval-signal', { approved: true });
57
57
  * ```
58
58
  *
59
- * @param {string} signalId - Unique signal identifier that matches a `waitFor()` call.
59
+ * @param {string} signalId - Unique signal identifier that matches a `condition()` call.
60
60
  * @param {Record<any, any>} data - The payload to deliver to the waiting workflow.
61
61
  * @returns {Promise<string>} The resulting hook/stream ID.
62
62
  */
@@ -3,7 +3,7 @@
3
3
  * `setTimeout`, this sleep survives process restarts — the engine persists
4
4
  * the wake-up time and resumes the workflow when the timer expires.
5
5
  *
6
- * On replay, `sleepFor` returns immediately with the stored duration
6
+ * On replay, `sleep` returns immediately with the stored duration
7
7
  * (no actual waiting occurs). This makes it safe for deterministic
8
8
  * re-execution.
9
9
  *
@@ -23,11 +23,11 @@
23
23
  * const { sendReminder } = Durable.workflow.proxyActivities<typeof activities>();
24
24
  *
25
25
  * // Wait 24 hours (survives server restarts)
26
- * await Durable.workflow.sleepFor('24 hours');
26
+ * await Durable.workflow.sleep('24 hours');
27
27
  * await sendReminder(userId, 'Your trial expires tomorrow');
28
28
  *
29
29
  * // Wait another 6 days
30
- * await Durable.workflow.sleepFor('6 days');
30
+ * await Durable.workflow.sleep('6 days');
31
31
  * await sendReminder(userId, 'Your trial has expired');
32
32
  * }
33
33
  * ```
@@ -43,7 +43,7 @@
43
43
  *
44
44
  * // Exponential backoff: 1s, 2s, 4s, 8s, ...
45
45
  * const delay = Math.pow(2, attempt);
46
- * await Durable.workflow.sleepFor(`${delay} seconds`);
46
+ * await Durable.workflow.sleep(`${delay} seconds`);
47
47
  * }
48
48
  * return 'timeout';
49
49
  * }
@@ -53,11 +53,11 @@
53
53
  * // Race a sleep against an activity
54
54
  * const [result, _] = await Promise.all([
55
55
  * activities.fetchData(id),
56
- * Durable.workflow.sleepFor('30 seconds'),
56
+ * Durable.workflow.sleep('30 seconds'),
57
57
  * ]);
58
58
  * ```
59
59
  *
60
- * @param {string} duration - A human-readable duration string.
60
+ * @param {string | number} duration - A human-readable duration string (e.g., `'30s'`, `'5 minutes'`) or milliseconds as a number.
61
61
  * @returns {Promise<number>} The resolved duration in seconds.
62
62
  */
63
- export declare function sleepFor(duration: string): Promise<number>;
63
+ export declare function sleep(duration: string | number): Promise<number>;
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sleepFor = void 0;
3
+ exports.sleep = void 0;
4
4
  const common_1 = require("./common");
5
+ const cancellationScope_1 = require("./cancellationScope");
5
6
  const didRun_1 = require("./didRun");
6
7
  /**
7
8
  * Suspends workflow execution for a durable, crash-safe duration. Unlike
8
9
  * `setTimeout`, this sleep survives process restarts — the engine persists
9
10
  * the wake-up time and resumes the workflow when the timer expires.
10
11
  *
11
- * On replay, `sleepFor` returns immediately with the stored duration
12
+ * On replay, `sleep` returns immediately with the stored duration
12
13
  * (no actual waiting occurs). This makes it safe for deterministic
13
14
  * re-execution.
14
15
  *
@@ -28,11 +29,11 @@ const didRun_1 = require("./didRun");
28
29
  * const { sendReminder } = Durable.workflow.proxyActivities<typeof activities>();
29
30
  *
30
31
  * // Wait 24 hours (survives server restarts)
31
- * await Durable.workflow.sleepFor('24 hours');
32
+ * await Durable.workflow.sleep('24 hours');
32
33
  * await sendReminder(userId, 'Your trial expires tomorrow');
33
34
  *
34
35
  * // Wait another 6 days
35
- * await Durable.workflow.sleepFor('6 days');
36
+ * await Durable.workflow.sleep('6 days');
36
37
  * await sendReminder(userId, 'Your trial has expired');
37
38
  * }
38
39
  * ```
@@ -48,7 +49,7 @@ const didRun_1 = require("./didRun");
48
49
  *
49
50
  * // Exponential backoff: 1s, 2s, 4s, 8s, ...
50
51
  * const delay = Math.pow(2, attempt);
51
- * await Durable.workflow.sleepFor(`${delay} seconds`);
52
+ * await Durable.workflow.sleep(`${delay} seconds`);
52
53
  * }
53
54
  * return 'timeout';
54
55
  * }
@@ -58,25 +59,53 @@ const didRun_1 = require("./didRun");
58
59
  * // Race a sleep against an activity
59
60
  * const [result, _] = await Promise.all([
60
61
  * activities.fetchData(id),
61
- * Durable.workflow.sleepFor('30 seconds'),
62
+ * Durable.workflow.sleep('30 seconds'),
62
63
  * ]);
63
64
  * ```
64
65
  *
65
- * @param {string} duration - A human-readable duration string.
66
+ * @param {string | number} duration - A human-readable duration string (e.g., `'30s'`, `'5 minutes'`) or milliseconds as a number.
66
67
  * @returns {Promise<number>} The resolved duration in seconds.
67
68
  */
68
- async function sleepFor(duration) {
69
+ async function sleep(duration) {
70
+ // Normalize: number input is treated as milliseconds (Temporal compat)
71
+ const durationStr = typeof duration === 'number' ? `${duration} milliseconds` : duration;
69
72
  const [didRunAlready, execIndex, result] = await (0, didRun_1.didRun)('sleep');
73
+ (0, cancellationScope_1.checkCancellation)();
70
74
  if (didRunAlready) {
75
+ // Emit RETURN span in debug mode
76
+ if (common_1.DurableTelemetryService.isVerbose() && result) {
77
+ const store = common_1.asyncLocalStorage.getStore();
78
+ const workflowTrace = store.get('workflowTrace');
79
+ const workflowSpan = store.get('workflowSpan');
80
+ if (workflowTrace && workflowSpan && result.ac && result.au) {
81
+ common_1.DurableTelemetryService.emitDurationSpan(workflowTrace, workflowSpan, `RETURN/sleep/${durationStr}/${execIndex}`, common_1.DurableTelemetryService.parseTimestamp(result.ac), common_1.DurableTelemetryService.parseTimestamp(result.au), {
82
+ 'durable.operation.type': 'sleep',
83
+ 'durable.sleep.duration': durationStr,
84
+ 'durable.exec.index': execIndex,
85
+ });
86
+ }
87
+ }
71
88
  return result.duration;
72
89
  }
73
90
  const store = common_1.asyncLocalStorage.getStore();
91
+ // Emit DISPATCH span in debug mode
92
+ if (common_1.DurableTelemetryService.isVerbose()) {
93
+ const workflowTrace = store.get('workflowTrace');
94
+ const workflowSpan = store.get('workflowSpan');
95
+ if (workflowTrace && workflowSpan) {
96
+ common_1.DurableTelemetryService.emitPointSpan(workflowTrace, workflowSpan, `DISPATCH/sleep/${durationStr}/${execIndex}`, {
97
+ 'durable.operation.type': 'sleep',
98
+ 'durable.sleep.duration': durationStr,
99
+ 'durable.exec.index': execIndex,
100
+ });
101
+ }
102
+ }
74
103
  const interruptionRegistry = store.get('interruptionRegistry');
75
104
  const workflowId = store.get('workflowId');
76
105
  const workflowDimension = store.get('workflowDimension') ?? '';
77
106
  const interruptionMessage = {
78
107
  workflowId,
79
- duration: (0, common_1.s)(duration),
108
+ duration: (0, common_1.s)(durationStr),
80
109
  index: execIndex,
81
110
  workflowDimension,
82
111
  };
@@ -88,4 +117,4 @@ async function sleepFor(duration) {
88
117
  await (0, common_1.sleepImmediate)();
89
118
  throw new common_1.DurableSleepError(interruptionMessage);
90
119
  }
91
- exports.sleepFor = sleepFor;
120
+ exports.sleep = sleep;
@@ -0,0 +1,55 @@
1
+ import { JobInterruptOptions } from './common';
2
+ /**
3
+ * Terminates a running workflow job by its ID. The target job's status
4
+ * is set to an error code indicating abnormal termination, and any
5
+ * pending activities or timers are cancelled.
6
+ *
7
+ * This is the workflow-internal terminate — it can only be called from
8
+ * within a workflow function. For external termination, use
9
+ * `handle.terminate()` directly.
10
+ *
11
+ * The terminate fires exactly once per workflow execution — the
12
+ * `isSideEffectAllowed` guard prevents re-terminating on replay.
13
+ *
14
+ * ## Examples
15
+ *
16
+ * ```typescript
17
+ * import { Durable } from '@hotmeshio/hotmesh';
18
+ *
19
+ * // Terminate a child workflow from the parent
20
+ * export async function supervisorWorkflow(): Promise<void> {
21
+ * const childId = await Durable.workflow.startChild({
22
+ * taskQueue: 'workers',
23
+ * workflowName: 'longTask',
24
+ * args: [],
25
+ * });
26
+ *
27
+ * // Wait for a timeout, then terminate the child
28
+ * await Durable.workflow.sleep('5 minutes');
29
+ * await Durable.workflow.terminate(childId, {
30
+ * reason: 'Timed out waiting for child',
31
+ * descend: true, // also terminate any grandchild workflows
32
+ * });
33
+ * }
34
+ * ```
35
+ *
36
+ * ```typescript
37
+ * // Self-terminate on validation failure
38
+ * export async function validatedWorkflow(input: string): Promise<void> {
39
+ * const { workflowId } = Durable.workflow.workflowInfo();
40
+ * const { validate } = Durable.workflow.proxyActivities<typeof activities>();
41
+ *
42
+ * const isValid = await validate(input);
43
+ * if (!isValid) {
44
+ * await Durable.workflow.terminate(workflowId, {
45
+ * reason: 'Invalid input',
46
+ * });
47
+ * }
48
+ * }
49
+ * ```
50
+ *
51
+ * @param {string} jobId - The ID of the workflow job to terminate.
52
+ * @param {JobInterruptOptions} [options={}] - Termination options (`reason`, `descend`, etc.).
53
+ * @returns {Promise<string | void>} The result of the termination, if any.
54
+ */
55
+ export declare function terminate(jobId: string, options?: JobInterruptOptions): Promise<string | void>;
@@ -1,27 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.interrupt = void 0;
3
+ exports.terminate = void 0;
4
4
  const common_1 = require("./common");
5
- const context_1 = require("./context");
5
+ const workflowInfo_1 = require("./workflowInfo");
6
6
  const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
7
7
  /**
8
8
  * Terminates a running workflow job by its ID. The target job's status
9
9
  * is set to an error code indicating abnormal termination, and any
10
10
  * pending activities or timers are cancelled.
11
11
  *
12
- * This is the workflow-internal interrupt — it can only be called from
13
- * within a workflow function. For external interruption, use
14
- * `hotMesh.interrupt()` directly.
12
+ * This is the workflow-internal terminate — it can only be called from
13
+ * within a workflow function. For external termination, use
14
+ * `handle.terminate()` directly.
15
15
  *
16
- * The interrupt fires exactly once per workflow execution — the
17
- * `isSideEffectAllowed` guard prevents re-interrupting on replay.
16
+ * The terminate fires exactly once per workflow execution — the
17
+ * `isSideEffectAllowed` guard prevents re-terminating on replay.
18
18
  *
19
19
  * ## Examples
20
20
  *
21
21
  * ```typescript
22
22
  * import { Durable } from '@hotmeshio/hotmesh';
23
23
  *
24
- * // Cancel a child workflow from the parent
24
+ * // Terminate a child workflow from the parent
25
25
  * export async function supervisorWorkflow(): Promise<void> {
26
26
  * const childId = await Durable.workflow.startChild({
27
27
  * taskQueue: 'workers',
@@ -29,36 +29,36 @@ const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
29
29
  * args: [],
30
30
  * });
31
31
  *
32
- * // Wait for a timeout, then cancel the child
33
- * await Durable.workflow.sleepFor('5 minutes');
34
- * await Durable.workflow.interrupt(childId, {
32
+ * // Wait for a timeout, then terminate the child
33
+ * await Durable.workflow.sleep('5 minutes');
34
+ * await Durable.workflow.terminate(childId, {
35
35
  * reason: 'Timed out waiting for child',
36
- * descend: true, // also interrupt any grandchild workflows
36
+ * descend: true, // also terminate any grandchild workflows
37
37
  * });
38
38
  * }
39
39
  * ```
40
40
  *
41
41
  * ```typescript
42
- * // Self-interrupt on validation failure
42
+ * // Self-terminate on validation failure
43
43
  * export async function validatedWorkflow(input: string): Promise<void> {
44
- * const { workflowId } = Durable.workflow.getContext();
44
+ * const { workflowId } = Durable.workflow.workflowInfo();
45
45
  * const { validate } = Durable.workflow.proxyActivities<typeof activities>();
46
46
  *
47
47
  * const isValid = await validate(input);
48
48
  * if (!isValid) {
49
- * await Durable.workflow.interrupt(workflowId, {
49
+ * await Durable.workflow.terminate(workflowId, {
50
50
  * reason: 'Invalid input',
51
51
  * });
52
52
  * }
53
53
  * }
54
54
  * ```
55
55
  *
56
- * @param {string} jobId - The ID of the workflow job to interrupt.
57
- * @param {JobInterruptOptions} [options={}] - Interruption options (`reason`, `descend`, etc.).
58
- * @returns {Promise<string | void>} The result of the interruption, if any.
56
+ * @param {string} jobId - The ID of the workflow job to terminate.
57
+ * @param {JobInterruptOptions} [options={}] - Termination options (`reason`, `descend`, etc.).
58
+ * @returns {Promise<string | void>} The result of the termination, if any.
59
59
  */
60
- async function interrupt(jobId, options = {}) {
61
- const { workflowTopic, connection, namespace } = (0, context_1.getContext)();
60
+ async function terminate(jobId, options = {}) {
61
+ const { workflowTopic, connection, namespace } = (0, workflowInfo_1.workflowInfo)();
62
62
  const hotMeshClient = await common_1.WorkerService.getHotMesh(workflowTopic, {
63
63
  connection,
64
64
  namespace,
@@ -67,4 +67,4 @@ async function interrupt(jobId, options = {}) {
67
67
  return await hotMeshClient.interrupt(`${hotMeshClient.appId}.execute`, jobId, options);
68
68
  }
69
69
  }
70
- exports.interrupt = interrupt;
70
+ exports.terminate = terminate;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.trace = void 0;
4
4
  const common_1 = require("./common");
5
- const context_1 = require("./context");
5
+ const workflowInfo_1 = require("./workflowInfo");
6
6
  const isSideEffectAllowed_1 = require("./isSideEffectAllowed");
7
7
  /**
8
8
  * Emits a distributed trace span to the configured telemetry sink
@@ -56,7 +56,7 @@ async function trace(attributes, config = { once: true }) {
56
56
  connection,
57
57
  namespace,
58
58
  });
59
- const { raw, COUNTER } = (0, context_1.getContext)();
59
+ const { raw, COUNTER } = (0, workflowInfo_1.workflowInfo)();
60
60
  const { trc: traceId, spn: spanId, aid: activityId } = raw.metadata;
61
61
  if (!config.once || await (0, isSideEffectAllowed_1.isSideEffectAllowed)(hotMeshClient, 'trace')) {
62
62
  return await common_1.TelemetryService.traceActivity(namespace, attributes, activityId, traceId, spanId, COUNTER.counter);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns a deterministic UUID v4 string. The value is derived from the
3
+ * current execution counter, producing the **same UUID** on every replay.
4
+ *
5
+ * Use this instead of `crypto.randomUUID()` inside workflow functions.
6
+ *
7
+ * ```typescript
8
+ * const id = Durable.workflow.uuid4();
9
+ * // e.g. "a3b8f042-1e9c-4d5a-b6e7-3f2c8a9d0e1b"
10
+ * ```
11
+ *
12
+ * @returns {string} A deterministic UUID v4 string.
13
+ */
14
+ export declare function uuid4(): string;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uuid4 = void 0;
4
+ const common_1 = require("./common");
5
+ /**
6
+ * Returns a deterministic UUID v4 string. The value is derived from the
7
+ * current execution counter, producing the **same UUID** on every replay.
8
+ *
9
+ * Use this instead of `crypto.randomUUID()` inside workflow functions.
10
+ *
11
+ * ```typescript
12
+ * const id = Durable.workflow.uuid4();
13
+ * // e.g. "a3b8f042-1e9c-4d5a-b6e7-3f2c8a9d0e1b"
14
+ * ```
15
+ *
16
+ * @returns {string} A deterministic UUID v4 string.
17
+ */
18
+ function uuid4() {
19
+ const store = common_1.asyncLocalStorage.getStore();
20
+ const COUNTER = store.get('counter');
21
+ // Generate 16 deterministic pseudo-random bytes
22
+ const bytes = [];
23
+ for (let i = 0; i < 16; i++) {
24
+ const seed = COUNTER.counter = COUNTER.counter + 1;
25
+ bytes.push(Math.floor((0, common_1.deterministicRandom)(seed) * 256));
26
+ }
27
+ // Set version (4) and variant (RFC 4122)
28
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
29
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
30
+ const hex = bytes.map(b => b.toString(16).padStart(2, '0'));
31
+ return [
32
+ hex.slice(0, 4).join(''),
33
+ hex.slice(4, 6).join(''),
34
+ hex.slice(6, 8).join(''),
35
+ hex.slice(8, 10).join(''),
36
+ hex.slice(10, 16).join(''),
37
+ ].join('-');
38
+ }
39
+ exports.uuid4 = uuid4;
@@ -15,7 +15,7 @@ import { WorkflowContext } from './common';
15
15
  *
16
16
  * // Access the workflow ID and namespace
17
17
  * export async function contextAwareWorkflow(): Promise<string> {
18
- * const ctx = Durable.workflow.getContext();
18
+ * const ctx = Durable.workflow.workflowInfo();
19
19
  * console.log(`Running workflow ${ctx.workflowId} in ${ctx.namespace}`);
20
20
  * return ctx.workflowId;
21
21
  * }
@@ -24,7 +24,7 @@ import { WorkflowContext } from './common';
24
24
  * ```typescript
25
25
  * // Check if the current execution is a replay
26
26
  * export async function replayAwareWorkflow(): Promise<void> {
27
- * const { counter, workflowDimension } = Durable.workflow.getContext();
27
+ * const { counter, workflowDimension } = Durable.workflow.workflowInfo();
28
28
  *
29
29
  * // Use context for logging/debugging
30
30
  * console.log(`Execution counter: ${counter}, dimension: ${workflowDimension}`);
@@ -34,9 +34,9 @@ import { WorkflowContext } from './common';
34
34
  * ```typescript
35
35
  * // Pass context info to child workflows
36
36
  * export async function parentWorkflow(): Promise<void> {
37
- * const { workflowId } = Durable.workflow.getContext();
37
+ * const { workflowId } = Durable.workflow.workflowInfo();
38
38
  *
39
- * await Durable.workflow.execChild({
39
+ * await Durable.workflow.executeChild({
40
40
  * taskQueue: 'children',
41
41
  * workflowName: 'childWorkflow',
42
42
  * args: [workflowId], // pass parent ID to child
@@ -46,4 +46,4 @@ import { WorkflowContext } from './common';
46
46
  *
47
47
  * @returns {WorkflowContext} The current workflow context.
48
48
  */
49
- export declare function getContext(): WorkflowContext;
49
+ export declare function workflowInfo(): WorkflowContext;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getContext = void 0;
3
+ exports.workflowInfo = void 0;
4
4
  const common_1 = require("./common");
5
5
  /**
6
6
  * Returns the current workflow's execution context, providing access to
@@ -18,7 +18,7 @@ const common_1 = require("./common");
18
18
  *
19
19
  * // Access the workflow ID and namespace
20
20
  * export async function contextAwareWorkflow(): Promise<string> {
21
- * const ctx = Durable.workflow.getContext();
21
+ * const ctx = Durable.workflow.workflowInfo();
22
22
  * console.log(`Running workflow ${ctx.workflowId} in ${ctx.namespace}`);
23
23
  * return ctx.workflowId;
24
24
  * }
@@ -27,7 +27,7 @@ const common_1 = require("./common");
27
27
  * ```typescript
28
28
  * // Check if the current execution is a replay
29
29
  * export async function replayAwareWorkflow(): Promise<void> {
30
- * const { counter, workflowDimension } = Durable.workflow.getContext();
30
+ * const { counter, workflowDimension } = Durable.workflow.workflowInfo();
31
31
  *
32
32
  * // Use context for logging/debugging
33
33
  * console.log(`Execution counter: ${counter}, dimension: ${workflowDimension}`);
@@ -37,9 +37,9 @@ const common_1 = require("./common");
37
37
  * ```typescript
38
38
  * // Pass context info to child workflows
39
39
  * export async function parentWorkflow(): Promise<void> {
40
- * const { workflowId } = Durable.workflow.getContext();
40
+ * const { workflowId } = Durable.workflow.workflowInfo();
41
41
  *
42
- * await Durable.workflow.execChild({
42
+ * await Durable.workflow.executeChild({
43
43
  * taskQueue: 'children',
44
44
  * workflowName: 'childWorkflow',
45
45
  * args: [workflowId], // pass parent ID to child
@@ -49,7 +49,7 @@ const common_1 = require("./common");
49
49
  *
50
50
  * @returns {WorkflowContext} The current workflow context.
51
51
  */
52
- function getContext() {
52
+ function workflowInfo() {
53
53
  const store = common_1.asyncLocalStorage.getStore();
54
54
  const workflowId = store.get('workflowId');
55
55
  const replay = store.get('replay');
@@ -87,4 +87,4 @@ function getContext() {
87
87
  workflowSpan,
88
88
  };
89
89
  }
90
- exports.getContext = getContext;
90
+ exports.workflowInfo = workflowInfo;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * YAML app compilation and deployment.
3
+ *
4
+ * Thin delegation to CompilerService — kept as a separate module
5
+ * so the engine index reads as a clear list of capabilities.
6
+ */
7
+ import { StoreService } from '../store';
8
+ import { StreamService } from '../stream';
9
+ import { ILogger } from '../logger';
10
+ import { HotMeshManifest } from '../../types/hotmesh';
11
+ import { ProviderClient, ProviderTransaction } from '../../types/provider';
12
+ interface CompilerContext {
13
+ store: StoreService<ProviderClient, ProviderTransaction>;
14
+ stream: StreamService<ProviderClient, ProviderTransaction>;
15
+ logger: ILogger;
16
+ }
17
+ export declare function plan(instance: CompilerContext, pathOrYAML: string): Promise<HotMeshManifest>;
18
+ export declare function deploy(instance: CompilerContext, pathOrYAML: string): Promise<HotMeshManifest>;
19
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * YAML app compilation and deployment.
4
+ *
5
+ * Thin delegation to CompilerService — kept as a separate module
6
+ * so the engine index reads as a clear list of capabilities.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.deploy = exports.plan = void 0;
10
+ const compiler_1 = require("../compiler");
11
+ async function plan(instance, pathOrYAML) {
12
+ const compiler = new compiler_1.CompilerService(instance.store, instance.stream, instance.logger);
13
+ return await compiler.plan(pathOrYAML);
14
+ }
15
+ exports.plan = plan;
16
+ async function deploy(instance, pathOrYAML) {
17
+ const compiler = new compiler_1.CompilerService(instance.store, instance.stream, instance.logger);
18
+ return await compiler.deploy(pathOrYAML);
19
+ }
20
+ exports.deploy = deploy;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Job lifecycle completion — parent notification, cleanup, and expiry.
3
+ *
4
+ * When a job finishes (or is interrupted), this module:
5
+ * 1. Notifies the parent job (if this is a child via execChild)
6
+ * 2. Publishes to one-time and permanent subscribers
7
+ * 3. Registers the job for TTL-based cleanup
8
+ */
9
+ import { Router } from '../router';
10
+ import { StoreService } from '../store';
11
+ import { StreamService } from '../stream';
12
+ import { SubService } from '../sub';
13
+ import { TaskService } from '../task';
14
+ import { ILogger } from '../logger';
15
+ import { AppVID } from '../../types/app';
16
+ import { JobState, JobOutput, JobMetadata, JobCompletionOptions, JobInterruptOptions } from '../../types/job';
17
+ import { ProviderClient, ProviderTransaction } from '../../types/provider';
18
+ import { StreamError } from '../../types/stream';
19
+ interface CompletionContext {
20
+ appId: string;
21
+ store: StoreService<ProviderClient, ProviderTransaction>;
22
+ stream: StreamService<ProviderClient, ProviderTransaction>;
23
+ subscribe: SubService<ProviderClient>;
24
+ router: Router<typeof this.stream> | null;
25
+ taskService: TaskService;
26
+ logger: ILogger;
27
+ getVID(vid?: AppVID): Promise<AppVID>;
28
+ getState(topic: string, jobId: string): Promise<JobOutput>;
29
+ getPublishesTopic(context: JobState): Promise<string>;
30
+ }
31
+ /**
32
+ * Sends the child job result back to the waiting parent activity.
33
+ * Only applies to non-severed children (execChild, not startChild).
34
+ */
35
+ export declare function execAdjacentParent(instance: CompletionContext, context: JobState, jobOutput: JobOutput, emit?: boolean, transaction?: ProviderTransaction): Promise<string>;
36
+ export declare function hasParentJob(context: JobState, checkSevered?: boolean): boolean;
37
+ export declare function resolveError(metadata: JobMetadata): StreamError | undefined;
38
+ export declare function interrupt(instance: CompletionContext, topic: string, jobId: string, options?: JobInterruptOptions): Promise<string>;
39
+ export declare function scrub(instance: CompletionContext, jobId: string): Promise<void>;
40
+ /**
41
+ * Orchestrates all post-completion work for a finished job:
42
+ * notify parent, publish to subscribers, schedule cleanup.
43
+ */
44
+ export declare function runJobCompletionTasks(instance: CompletionContext, context: JobState, options?: JobCompletionOptions, transaction?: ProviderTransaction): Promise<string | void>;
45
+ export declare function resolveExpires(context: JobState, options: JobCompletionOptions): number;
46
+ export {};