@hotmeshio/hotmesh 0.13.0 → 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 (194) 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 -3
  5. package/build/modules/errors.js +17 -2
  6. package/build/package.json +6 -1
  7. package/build/services/activities/activity/context.d.ts +22 -0
  8. package/build/services/activities/activity/context.js +76 -0
  9. package/build/services/activities/activity/index.d.ts +116 -0
  10. package/build/services/activities/activity/index.js +299 -0
  11. package/build/services/activities/activity/mapping.d.ts +12 -0
  12. package/build/services/activities/activity/mapping.js +63 -0
  13. package/build/services/activities/activity/process.d.ts +28 -0
  14. package/build/services/activities/activity/process.js +100 -0
  15. package/build/services/activities/activity/protocol.d.ts +39 -0
  16. package/build/services/activities/activity/protocol.js +151 -0
  17. package/build/services/activities/activity/state.d.ts +40 -0
  18. package/build/services/activities/activity/state.js +143 -0
  19. package/build/services/activities/activity/transition.d.ts +23 -0
  20. package/build/services/activities/activity/transition.js +71 -0
  21. package/build/services/activities/activity/verify.d.ts +22 -0
  22. package/build/services/activities/activity/verify.js +85 -0
  23. package/build/services/activities/await.d.ts +1 -4
  24. package/build/services/activities/await.js +2 -36
  25. package/build/services/activities/cycle.d.ts +1 -11
  26. package/build/services/activities/cycle.js +3 -46
  27. package/build/services/activities/hook.d.ts +2 -11
  28. package/build/services/activities/hook.js +30 -50
  29. package/build/services/activities/interrupt.d.ts +2 -4
  30. package/build/services/activities/interrupt.js +4 -38
  31. package/build/services/activities/signal.d.ts +1 -11
  32. package/build/services/activities/signal.js +3 -48
  33. package/build/services/activities/trigger.d.ts +1 -3
  34. package/build/services/activities/trigger.js +0 -3
  35. package/build/services/activities/worker.d.ts +3 -6
  36. package/build/services/activities/worker.js +4 -40
  37. package/build/services/connector/factory.d.ts +6 -0
  38. package/build/services/connector/factory.js +24 -0
  39. package/build/services/durable/activity.d.ts +1 -1
  40. package/build/services/durable/activity.js +2 -2
  41. package/build/services/durable/client.d.ts +24 -29
  42. package/build/services/durable/client.js +24 -29
  43. package/build/services/durable/connection.d.ts +13 -7
  44. package/build/services/durable/connection.js +13 -7
  45. package/build/services/durable/handle.d.ts +58 -40
  46. package/build/services/durable/handle.js +60 -40
  47. package/build/services/durable/index.d.ts +148 -286
  48. package/build/services/durable/index.js +157 -292
  49. package/build/services/durable/interceptor.d.ts +43 -33
  50. package/build/services/durable/interceptor.js +59 -39
  51. package/build/services/durable/schemas/factory.d.ts +1 -1
  52. package/build/services/durable/schemas/factory.js +168 -38
  53. package/build/services/durable/telemetry.d.ts +80 -0
  54. package/build/services/durable/telemetry.js +137 -0
  55. package/build/services/durable/worker.d.ts +100 -21
  56. package/build/services/durable/worker.js +304 -63
  57. package/build/services/durable/workflow/all.d.ts +1 -1
  58. package/build/services/durable/workflow/all.js +1 -1
  59. package/build/services/durable/workflow/cancellationScope.d.ts +104 -0
  60. package/build/services/durable/workflow/cancellationScope.js +139 -0
  61. package/build/services/durable/workflow/common.d.ts +5 -4
  62. package/build/services/durable/workflow/common.js +6 -1
  63. package/build/services/durable/workflow/{waitFor.d.ts → condition.d.ts} +9 -8
  64. package/build/services/durable/workflow/{waitFor.js → condition.js} +44 -11
  65. package/build/services/durable/workflow/continueAsNew.d.ts +65 -0
  66. package/build/services/durable/workflow/continueAsNew.js +92 -0
  67. package/build/services/durable/workflow/didRun.d.ts +1 -1
  68. package/build/services/durable/workflow/didRun.js +3 -3
  69. package/build/services/durable/workflow/enrich.d.ts +5 -0
  70. package/build/services/durable/workflow/enrich.js +5 -0
  71. package/build/services/durable/workflow/entityMethods.d.ts +7 -0
  72. package/build/services/durable/workflow/entityMethods.js +7 -0
  73. package/build/services/durable/workflow/execHook.js +3 -3
  74. package/build/services/durable/workflow/execHookBatch.js +2 -2
  75. package/build/services/durable/workflow/{execChild.d.ts → executeChild.d.ts} +4 -40
  76. package/build/services/durable/workflow/{execChild.js → executeChild.js} +36 -45
  77. package/build/services/durable/workflow/hook.d.ts +1 -1
  78. package/build/services/durable/workflow/hook.js +4 -3
  79. package/build/services/durable/workflow/index.d.ts +45 -50
  80. package/build/services/durable/workflow/index.js +46 -51
  81. package/build/services/durable/workflow/interruption.d.ts +7 -6
  82. package/build/services/durable/workflow/interruption.js +11 -7
  83. package/build/services/durable/workflow/patched.d.ts +72 -0
  84. package/build/services/durable/workflow/patched.js +110 -0
  85. package/build/services/durable/workflow/proxyActivities.d.ts +7 -7
  86. package/build/services/durable/workflow/proxyActivities.js +50 -15
  87. package/build/services/durable/workflow/searchMethods.d.ts +7 -0
  88. package/build/services/durable/workflow/searchMethods.js +7 -0
  89. package/build/services/durable/workflow/signal.d.ts +4 -4
  90. package/build/services/durable/workflow/signal.js +4 -4
  91. package/build/services/durable/workflow/{sleepFor.d.ts → sleep.d.ts} +7 -7
  92. package/build/services/durable/workflow/{sleepFor.js → sleep.js} +39 -10
  93. package/build/services/durable/workflow/terminate.d.ts +55 -0
  94. package/build/services/durable/workflow/{interrupt.js → terminate.js} +21 -21
  95. package/build/services/durable/workflow/trace.js +2 -2
  96. package/build/services/durable/workflow/uuid4.d.ts +14 -0
  97. package/build/services/durable/workflow/uuid4.js +39 -0
  98. package/build/services/durable/workflow/{context.d.ts → workflowInfo.d.ts} +5 -5
  99. package/build/services/durable/workflow/{context.js → workflowInfo.js} +7 -7
  100. package/build/services/engine/compiler.d.ts +19 -0
  101. package/build/services/engine/compiler.js +20 -0
  102. package/build/services/engine/completion.d.ts +46 -0
  103. package/build/services/engine/completion.js +145 -0
  104. package/build/services/engine/dispatch.d.ts +24 -0
  105. package/build/services/engine/dispatch.js +98 -0
  106. package/build/services/engine/index.d.ts +49 -81
  107. package/build/services/engine/index.js +175 -573
  108. package/build/services/engine/init.d.ts +42 -0
  109. package/build/services/engine/init.js +74 -0
  110. package/build/services/engine/pubsub.d.ts +50 -0
  111. package/build/services/engine/pubsub.js +118 -0
  112. package/build/services/engine/reporting.d.ts +20 -0
  113. package/build/services/engine/reporting.js +38 -0
  114. package/build/services/engine/schema.d.ts +23 -0
  115. package/build/services/engine/schema.js +62 -0
  116. package/build/services/engine/signal.d.ts +57 -0
  117. package/build/services/engine/signal.js +117 -0
  118. package/build/services/engine/state.d.ts +35 -0
  119. package/build/services/engine/state.js +61 -0
  120. package/build/services/engine/version.d.ts +31 -0
  121. package/build/services/engine/version.js +73 -0
  122. package/build/services/hotmesh/deployment.d.ts +21 -0
  123. package/build/services/hotmesh/deployment.js +25 -0
  124. package/build/services/hotmesh/index.d.ts +141 -532
  125. package/build/services/hotmesh/index.js +222 -673
  126. package/build/services/hotmesh/init.d.ts +42 -0
  127. package/build/services/hotmesh/init.js +93 -0
  128. package/build/services/hotmesh/jobs.d.ts +67 -0
  129. package/build/services/hotmesh/jobs.js +99 -0
  130. package/build/services/hotmesh/pubsub.d.ts +38 -0
  131. package/build/services/hotmesh/pubsub.js +54 -0
  132. package/build/services/hotmesh/quorum.d.ts +30 -0
  133. package/build/services/hotmesh/quorum.js +62 -0
  134. package/build/services/hotmesh/validation.d.ts +6 -0
  135. package/build/services/hotmesh/validation.js +28 -0
  136. package/build/services/quorum/index.js +1 -0
  137. package/build/services/router/consumption/index.d.ts +11 -5
  138. package/build/services/router/consumption/index.js +24 -17
  139. package/build/services/router/error-handling/index.d.ts +2 -2
  140. package/build/services/router/error-handling/index.js +14 -14
  141. package/build/services/router/index.d.ts +1 -1
  142. package/build/services/router/index.js +2 -2
  143. package/build/services/serializer/index.d.ts +22 -0
  144. package/build/services/serializer/index.js +39 -1
  145. package/build/services/store/index.d.ts +1 -0
  146. package/build/services/store/providers/postgres/exporter-sql.d.ts +2 -2
  147. package/build/services/store/providers/postgres/exporter-sql.js +4 -4
  148. package/build/services/store/providers/postgres/kvtables.js +7 -6
  149. package/build/services/store/providers/postgres/kvtypes/hash/basic.js +67 -52
  150. package/build/services/store/providers/postgres/kvtypes/hash/jsonb.js +87 -72
  151. package/build/services/store/providers/postgres/kvtypes/hash/udata.js +106 -79
  152. package/build/services/store/providers/postgres/kvtypes/hash/utils.d.ts +16 -0
  153. package/build/services/store/providers/postgres/kvtypes/hash/utils.js +29 -16
  154. package/build/services/store/providers/postgres/postgres.d.ts +1 -0
  155. package/build/services/store/providers/postgres/postgres.js +14 -4
  156. package/build/services/stream/factory.d.ts +3 -1
  157. package/build/services/stream/factory.js +2 -2
  158. package/build/services/stream/index.d.ts +1 -0
  159. package/build/services/stream/providers/nats/nats.d.ts +1 -0
  160. package/build/services/stream/providers/nats/nats.js +1 -0
  161. package/build/services/stream/providers/postgres/credentials.d.ts +56 -0
  162. package/build/services/stream/providers/postgres/credentials.js +129 -0
  163. package/build/services/stream/providers/postgres/kvtables.js +18 -0
  164. package/build/services/stream/providers/postgres/messages.js +7 -7
  165. package/build/services/stream/providers/postgres/notifications.js +16 -2
  166. package/build/services/stream/providers/postgres/postgres.d.ts +7 -0
  167. package/build/services/stream/providers/postgres/postgres.js +35 -4
  168. package/build/services/stream/providers/postgres/procedures.d.ts +21 -0
  169. package/build/services/stream/providers/postgres/procedures.js +213 -0
  170. package/build/services/stream/providers/postgres/secured.d.ts +34 -0
  171. package/build/services/stream/providers/postgres/secured.js +146 -0
  172. package/build/services/stream/providers/postgres/stats.d.ts +1 -0
  173. package/build/services/stream/providers/postgres/stats.js +1 -0
  174. package/build/services/stream/registry.d.ts +1 -1
  175. package/build/services/stream/registry.js +5 -2
  176. package/build/services/telemetry/index.d.ts +10 -1
  177. package/build/services/telemetry/index.js +40 -7
  178. package/build/services/worker/credentials.d.ts +51 -0
  179. package/build/services/worker/credentials.js +87 -0
  180. package/build/services/worker/index.d.ts +2 -2
  181. package/build/services/worker/index.js +7 -6
  182. package/build/types/codec.d.ts +84 -0
  183. package/build/types/codec.js +2 -0
  184. package/build/types/durable.d.ts +104 -28
  185. package/build/types/error.d.ts +10 -1
  186. package/build/types/hotmesh.d.ts +67 -4
  187. package/build/types/index.d.ts +2 -1
  188. package/build/types/provider.d.ts +2 -2
  189. package/build/types/quorum.d.ts +35 -1
  190. package/build/types/stream.d.ts +12 -6
  191. package/package.json +6 -1
  192. package/build/services/activities/activity.d.ts +0 -192
  193. package/build/services/activities/activity.js +0 -786
  194. package/build/services/durable/workflow/interrupt.d.ts +0 -55
@@ -3,28 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WorkflowHandleService = void 0;
4
4
  const exporter_1 = require("./exporter");
5
5
  /**
6
- * The WorkflowHandleService provides methods to interact with a running
7
- * workflow. This includes exporting the workflow, sending signals, and
8
- * querying the state of the workflow. It is instanced/accessed via the
9
- * Durable.Client class.
6
+ * Handle to a running or completed workflow execution. Returned by
7
+ * `client.workflow.start()` and `client.workflow.getHandle()`.
10
8
  *
11
9
  * @example
12
10
  * ```typescript
13
- * import { Client } from '@hotmeshio/hotmesh';
14
- * import { Client as Postgres } from 'pg';
15
- *
16
- * const client = new Client({ connection: {
17
- * class: Postgres,
18
- * options: { connectionString: 'postgres://user:pass@localhost:5432/db' }
19
- * }});
20
- *
21
11
  * const handle = await client.workflow.start({
22
- * args: ['HotMesh'],
23
- * taskQueue: 'hello-world',
12
+ * args: ['order-123'],
13
+ * taskQueue: 'orders',
14
+ * workflowName: 'orderWorkflow',
15
+ * workflowId: Durable.guid(),
24
16
  * });
25
17
  *
26
- * //perform actions like send a signal
27
- * await handle.signal('my-signal', { data: 'Hello' });
18
+ * // Await the final result
19
+ * const result = await handle.result();
20
+ *
21
+ * // Or interact while running
22
+ * await handle.signal('approval', { approved: true });
23
+ * await handle.cancel();
28
24
  * ```
29
25
  */
30
26
  class WorkflowHandleService {
@@ -38,7 +34,8 @@ class WorkflowHandleService {
38
34
  this.exporter = new exporter_1.ExporterService(this.hotMesh.appId, this.hotMesh.engine.store, this.hotMesh.engine.logger);
39
35
  }
40
36
  /**
41
- * Exports the workflow state to a JSON object.
37
+ * Exports the full workflow state (job hash, metadata, activity
38
+ * results) as a JSON object.
42
39
  */
43
40
  async export(options) {
44
41
  return this.exporter.export(this.workflowId, options);
@@ -57,10 +54,12 @@ class WorkflowHandleService {
57
54
  return this.exporter.exportExecution(this.workflowId, this.workflowTopic, options);
58
55
  }
59
56
  /**
60
- * Sends a signal to the workflow. This is a way to send
61
- * a message to a workflow that is paused due to having
62
- * executed `Durable.workflow.waitFor`. The workflow
63
- * will awaken if no other signals are pending.
57
+ * Delivers a named signal to the workflow. If the workflow is paused
58
+ * on `Durable.workflow.condition(signalId)`, it resumes with the
59
+ * provided data.
60
+ *
61
+ * @param signalId - Matches the `signalId` passed to `condition()`.
62
+ * @param data - Payload delivered to the waiting workflow.
64
63
  */
65
64
  async signal(signalId, data) {
66
65
  await this.hotMesh.signal(`${this.hotMesh.appId}.wfs.signal`, {
@@ -69,10 +68,12 @@ class WorkflowHandleService {
69
68
  });
70
69
  }
71
70
  /**
72
- * Returns the job state of the workflow. If the workflow has completed
73
- * this is also the job output. If the workflow is still running, this
74
- * is the current state of the job, but it may change depending upon
75
- * the activities that remain.
71
+ * Returns the current workflow state. For a completed workflow this
72
+ * is the final output; for a running workflow it reflects the latest
73
+ * persisted state (may change as activities complete).
74
+ *
75
+ * @param metadata - If `true`, returns the full job envelope including
76
+ * internal metadata alongside the data.
76
77
  */
77
78
  async state(metadata = false) {
78
79
  const state = await this.hotMesh.getState(`${this.hotMesh.appId}.execute`, this.workflowId);
@@ -82,35 +83,54 @@ class WorkflowHandleService {
82
83
  return metadata ? state : state.data;
83
84
  }
84
85
  /**
85
- * Returns the current search state of the workflow. This is
86
- * different than the job state or individual activity state.
87
- * Search state represents name/value pairs that were added
88
- * to the workflow.
86
+ * Returns key-value pairs previously written via
87
+ * `Durable.workflow.search()` or `Durable.workflow.enrich()`.
88
+ *
89
+ * @param fields - The field names to retrieve.
89
90
  */
90
91
  async queryState(fields) {
91
92
  return await this.hotMesh.getQueryState(this.workflowId, fields);
92
93
  }
93
94
  /**
94
- * Returns the current status of the workflow. This is a semaphore
95
- * value that represents the current state of the workflow, where
96
- * 0 is complete and a negative value represents that the flow was
97
- * interrupted.
95
+ * Returns the workflow's numeric status code: `0` = completed,
96
+ * positive = still running, negative = interrupted/errored.
98
97
  */
99
98
  async status() {
100
99
  return await this.hotMesh.getStatus(this.workflowId);
101
100
  }
102
101
  /**
103
- * Interrupts a running workflow. Standard Job Completion tasks will
104
- * run. Subscribers will be notified and the job hash will be expired.
102
+ * Immediately terminates the workflow. The job is marked as interrupted,
103
+ * subscribers are notified, and the job hash is expired. Unlike
104
+ * {@link cancel}, this does **not** give the workflow a chance to
105
+ * run cleanup code.
105
106
  */
106
- async interrupt(options) {
107
+ async terminate(options) {
107
108
  return await this.hotMesh.interrupt(`${this.hotMesh.appId}.execute`, this.workflowId, options);
108
109
  }
109
110
  /**
110
- * Waits for the workflow to complete and returns the result. If
111
- * the workflow response includes an error, this method will rethrow
112
- * the error, including the stack trace if available.
113
- * Wrap calls in a try/catch as necessary to avoid unhandled exceptions.
111
+ * Requests cooperative cancellation of the workflow. Unlike
112
+ * `terminate()` (which terminates immediately), `cancel()` sets
113
+ * a durable flag that the workflow detects at its next durable
114
+ * operation (`sleep`, `proxyActivities`, `executeChild`, etc.).
115
+ * The workflow receives a `CancelledFailure` error that it can
116
+ * catch to perform cleanup before exiting.
117
+ *
118
+ * ```typescript
119
+ * const handle = await client.workflow.start({ ... });
120
+ * await handle.cancel();
121
+ * // Workflow will throw CancelledFailure at its next durable operation
122
+ * ```
123
+ */
124
+ async cancel() {
125
+ await this.hotMesh.cancel(this.workflowId);
126
+ }
127
+ /**
128
+ * Blocks until the workflow completes and returns the result. If the
129
+ * workflow failed, the error is rethrown (with stack trace) unless
130
+ * `throwOnError: false` is set, in which case the error object is
131
+ * returned directly.
132
+ *
133
+ * @template T - The workflow's return type.
114
134
  */
115
135
  async result(config) {
116
136
  const topic = `${this.hotMesh.appId}.executed.${this.workflowId}`;