@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
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Worker = void 0;
4
- const errors_1 = require("../../modules/errors");
5
4
  const utils_1 = require("../../modules/utils");
6
5
  const collator_1 = require("../collator");
7
6
  const pipe_1 = require("../pipe");
@@ -74,7 +73,7 @@ const activity_1 = require("./activity");
74
73
  * ## Retry Policy
75
74
  *
76
75
  * Retry behavior is configured at the **worker level** (not in YAML) via
77
- * the `retryPolicy` option. Failed callbacks are retried with exponential
76
+ * the `retry` option. Failed callbacks are retried with exponential
78
77
  * backoff until `maximumAttempts` is exhausted. The `maximumInterval` caps
79
78
  * the delay between retries.
80
79
  *
@@ -85,7 +84,7 @@ const activity_1 = require("./activity");
85
84
  * workers: [{
86
85
  * topic: 'work.backoff',
87
86
  * connection,
88
- * retryPolicy: {
87
+ * retry: {
89
88
  * maximumAttempts: 5, // retry up to 5 times
90
89
  * backoffCoefficient: 2, // exponential: 2^0, 2^1, 2^2, ... seconds
91
90
  * maximumInterval: '30s', // cap delay at 30 seconds
@@ -115,10 +114,6 @@ const activity_1 = require("./activity");
115
114
  * @see {@link WorkerActivity} for the TypeScript interface
116
115
  */
117
116
  class Worker extends activity_1.Activity {
118
- constructor(config, data, metadata, hook, engine, context) {
119
- super(config, data, metadata, hook, engine, context);
120
- }
121
- //******** INITIAL ENTRY POINT (A) ********//
122
117
  async process() {
123
118
  this.logger.debug('worker-process', {
124
119
  jid: this.context.metadata.jid,
@@ -131,15 +126,12 @@ class Worker extends activity_1.Activity {
131
126
  telemetry = new telemetry_1.TelemetryService(this.engine.appId, this.config, this.metadata, this.context);
132
127
  telemetry.startActivitySpan(this.leg);
133
128
  this.mapInputData();
134
- //save state and mark Leg1 complete
135
129
  const transaction = this.store.transact();
136
- //todo: await this.registerTimeout();
137
130
  const messageId = await this.execActivity(transaction);
138
131
  await collator_1.CollatorService.notarizeLeg1Completion(this, transaction);
139
132
  await this.setState(transaction);
140
133
  await this.setStatus(0, transaction);
141
134
  const txResponse = (await transaction.exec());
142
- //telemetry
143
135
  telemetry.mapActivityAttributes();
144
136
  const jobStatus = this.resolveStatus(txResponse);
145
137
  telemetry.setActivityAttributes({
@@ -149,34 +141,8 @@ class Worker extends activity_1.Activity {
149
141
  return this.context.metadata.aid;
150
142
  }
151
143
  catch (error) {
152
- if (error instanceof errors_1.InactiveJobError) {
153
- this.logger.error('await-inactive-job-error', { error });
154
- return;
155
- }
156
- else if (error instanceof errors_1.GenerationalError) {
157
- this.logger.info('process-event-generational-job-error', { error });
158
- return;
159
- }
160
- else if (error instanceof errors_1.GetStateError) {
161
- this.logger.error('worker-get-state-error', { error });
162
- return;
163
- }
164
- else if (error instanceof errors_1.CollationError) {
165
- if (error.fault === 'duplicate') {
166
- this.logger.info('worker-collation-overage', {
167
- job_id: this.context.metadata.jid,
168
- guid: this.context.metadata.guid,
169
- });
170
- return;
171
- }
172
- //unknown collation error
173
- this.logger.error('worker-collation-error', { error });
174
- }
175
- else {
176
- this.logger.error('worker-process-error', { error });
177
- }
178
- telemetry?.setActivityError(error.message);
179
- throw error;
144
+ this.handleProcessError(error, telemetry, 'worker');
145
+ return;
180
146
  }
181
147
  finally {
182
148
  telemetry?.endActivitySpan();
@@ -189,11 +155,9 @@ class Worker extends activity_1.Activity {
189
155
  }
190
156
  async execActivity(transaction) {
191
157
  const topic = pipe_1.Pipe.resolve(this.config.subtype, this.context);
192
- // Extract workflow name from job data (set by durable client) or derive from subscribes
193
158
  const jobData = this.context.data;
194
159
  let wfn = jobData?.workflowName || '';
195
160
  if (!wfn && this.config.subscribes) {
196
- // Fallback: derive from subscribes by removing topic prefix
197
161
  wfn = this.config.subscribes.startsWith(`${topic}-`)
198
162
  ? this.config.subscribes.substring(topic.length + 1)
199
163
  : this.config.subscribes;
@@ -11,6 +11,12 @@ export declare class ConnectorService {
11
11
  static connectClient(ProviderConfig: ProviderConfig, taskQueue?: string): Promise<ProviderNativeClient>;
12
12
  /**
13
13
  * Initialize `store`, `stream`, and `subscription` clients for any provider.
14
+ *
15
+ * When the target has `workerCredentials`, the `user` and `password`
16
+ * in all connection options are overridden with the scoped Postgres
17
+ * role credentials, and `securedWorker` is set so downstream stream
18
+ * services use SECURITY DEFINER stored procedures.
19
+ *
14
20
  * @private
15
21
  */
16
22
  static initClients(target: HotMeshEngine | HotMeshWorker): Promise<void>;
@@ -22,6 +22,12 @@ class ConnectorService {
22
22
  }
23
23
  /**
24
24
  * Initialize `store`, `stream`, and `subscription` clients for any provider.
25
+ *
26
+ * When the target has `workerCredentials`, the `user` and `password`
27
+ * in all connection options are overridden with the scoped Postgres
28
+ * role credentials, and `securedWorker` is set so downstream stream
29
+ * services use SECURITY DEFINER stored procedures.
30
+ *
25
31
  * @private
26
32
  */
27
33
  static async initClients(target) {
@@ -34,6 +40,24 @@ class ConnectorService {
34
40
  sub: { ...connection },
35
41
  };
36
42
  }
43
+ // Apply scoped worker credentials to stream/sub only.
44
+ // The `store` connection retains full credentials because it is
45
+ // used by the engine for schema deployment, job-state reads, and
46
+ // other operations that require direct table access. Only the
47
+ // `stream` (dequeue/ack/respond) and `sub` (LISTEN/UNLISTEN)
48
+ // connections are scoped to the least-privilege worker role.
49
+ const workerCreds = target.workerCredentials;
50
+ if (workerCreds) {
51
+ for (const key of ['stream', 'sub']) {
52
+ if (connection[key]?.options) {
53
+ connection[key].options = {
54
+ ...connection[key].options,
55
+ user: workerCreds.user,
56
+ password: workerCreds.password,
57
+ };
58
+ }
59
+ }
60
+ }
37
61
  // Extract taskQueue from target for connection pooling
38
62
  const taskQueue = target.taskQueue;
39
63
  // Expanded form
@@ -13,7 +13,7 @@ import { DurableActivityContext } from '../../types/durable';
13
13
  * export async function processData(data: string): Promise<string> {
14
14
  * const ctx = Durable.activity.getContext();
15
15
  * console.log(`Activity ${ctx.activityName} for workflow ${ctx.workflowId}`);
16
- * console.log(`Metadata:`, ctx.argumentMetadata);
16
+ * console.log(`Metadata:`, ctx.headers);
17
17
  * return `Processed: ${data}`;
18
18
  * }
19
19
  * ```
@@ -16,7 +16,7 @@ const storage_1 = require("../../modules/storage");
16
16
  * export async function processData(data: string): Promise<string> {
17
17
  * const ctx = Durable.activity.getContext();
18
18
  * console.log(`Activity ${ctx.activityName} for workflow ${ctx.workflowId}`);
19
- * console.log(`Metadata:`, ctx.argumentMetadata);
19
+ * console.log(`Metadata:`, ctx.headers);
20
20
  * return `Processed: ${data}`;
21
21
  * }
22
22
  * ```
@@ -37,7 +37,7 @@ class ActivityService {
37
37
  return {
38
38
  activityName: store.get('activityName'),
39
39
  arguments: store.get('arguments'),
40
- argumentMetadata: store.get('argumentMetadata') ?? {},
40
+ headers: store.get('headers') ?? {},
41
41
  workflowId: store.get('workflowId'),
42
42
  workflowTopic: store.get('workflowTopic'),
43
43
  };
@@ -1,39 +1,34 @@
1
1
  import { HotMesh } from '../hotmesh';
2
2
  import { ClientConfig, ClientWorkflow, Connection, WorkflowOptions } from '../../types/durable';
3
3
  /**
4
- * The Durable `Client` service provides methods for
5
- * starting, signaling, and querying workflows.
6
- * Start a new workflow execution by calling
7
- * `workflow.start`. Note the direct connection to
8
- * Postgres.
4
+ * Workflow client. Starts workflows, sends signals, and reads results.
9
5
  *
10
- * NATS can be used as the message broker if advanced
11
- * messaging is required (i.e, patterned subscriptions).
12
6
  * @example
13
-
14
7
  * ```typescript
15
- * //client.ts
16
- * import { Client, HotMesh } from '@hotmeshio/hotmesh';
8
+ * import { Durable } from '@hotmeshio/hotmesh';
17
9
  * import { Client as Postgres } from 'pg';
18
-
19
- * async function run(): Promise<string> {
20
- * const client = new Client({
21
- * connection: {
22
- * class: Postgres,
23
- * options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
24
- * }
25
- * });
26
-
27
- * const handle = await client.workflow.start({
28
- * args: ['HotMesh'],
29
- * taskQueue: 'default',
30
- * workflowName: 'example',
31
- * workflowId: HotMesh.guid()
32
- * });
33
-
34
- * return await handle.result();
35
- * //returns ['Hello HotMesh', '¡Hola, HotMesh!']
36
- * }
10
+ *
11
+ * const client = new Durable.Client({
12
+ * connection: {
13
+ * class: Postgres,
14
+ * options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' },
15
+ * },
16
+ * });
17
+ *
18
+ * // Start a workflow and await its result
19
+ * const handle = await client.workflow.start({
20
+ * args: ['order-123'],
21
+ * taskQueue: 'orders',
22
+ * workflowName: 'orderWorkflow',
23
+ * workflowId: Durable.guid(),
24
+ * });
25
+ * const result = await handle.result();
26
+ *
27
+ * // Send a signal to a running workflow
28
+ * await handle.signal('approval', { approved: true });
29
+ *
30
+ * // Cancel a running workflow
31
+ * await handle.cancel();
37
32
  * ```
38
33
  */
39
34
  export declare class ClientService {
@@ -11,39 +11,34 @@ const search_1 = require("./search");
11
11
  const handle_1 = require("./handle");
12
12
  const factory_1 = require("./schemas/factory");
13
13
  /**
14
- * The Durable `Client` service provides methods for
15
- * starting, signaling, and querying workflows.
16
- * Start a new workflow execution by calling
17
- * `workflow.start`. Note the direct connection to
18
- * Postgres.
14
+ * Workflow client. Starts workflows, sends signals, and reads results.
19
15
  *
20
- * NATS can be used as the message broker if advanced
21
- * messaging is required (i.e, patterned subscriptions).
22
16
  * @example
23
-
24
17
  * ```typescript
25
- * //client.ts
26
- * import { Client, HotMesh } from '@hotmeshio/hotmesh';
18
+ * import { Durable } from '@hotmeshio/hotmesh';
27
19
  * import { Client as Postgres } from 'pg';
28
-
29
- * async function run(): Promise<string> {
30
- * const client = new Client({
31
- * connection: {
32
- * class: Postgres,
33
- * options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' }
34
- * }
35
- * });
36
-
37
- * const handle = await client.workflow.start({
38
- * args: ['HotMesh'],
39
- * taskQueue: 'default',
40
- * workflowName: 'example',
41
- * workflowId: HotMesh.guid()
42
- * });
43
-
44
- * return await handle.result();
45
- * //returns ['Hello HotMesh', '¡Hola, HotMesh!']
46
- * }
20
+ *
21
+ * const client = new Durable.Client({
22
+ * connection: {
23
+ * class: Postgres,
24
+ * options: { connectionString: 'postgresql://usr:pwd@localhost:5432/db' },
25
+ * },
26
+ * });
27
+ *
28
+ * // Start a workflow and await its result
29
+ * const handle = await client.workflow.start({
30
+ * args: ['order-123'],
31
+ * taskQueue: 'orders',
32
+ * workflowName: 'orderWorkflow',
33
+ * workflowId: Durable.guid(),
34
+ * });
35
+ * const result = await handle.result();
36
+ *
37
+ * // Send a signal to a running workflow
38
+ * await handle.signal('approval', { approved: true });
39
+ *
40
+ * // Cancel a running workflow
41
+ * await handle.cancel();
47
42
  * ```
48
43
  */
49
44
  class ClientService {
@@ -1,13 +1,12 @@
1
1
  import { Connection } from '../../types/durable';
2
2
  import { ProviderConfig, ProvidersConfig } from '../../types/provider';
3
3
  /**
4
- * The Connection service is used to declare the class
5
- * and connection options but does not connect quite yet. Connection
6
- * happens at a later lifecycle stage when a workflow
7
- * is started by the Durable Client module (`(new Durable.Client())).start()`).
4
+ * Declares connection configuration (driver class + options) without
5
+ * opening a connection. The actual Postgres connection is established
6
+ * lazily when a Worker or Client is started.
8
7
  *
9
- * The config options optionall support a multi-connection setup
10
- * where the `store` connection explicitly defined along with `stream`, `sub`, etc.
8
+ * Supports both single-connection and split-connection layouts (separate
9
+ * `store`, `stream`, and `sub` connections for advanced deployments).
11
10
  */
12
11
  export declare class ConnectionService {
13
12
  /**
@@ -15,7 +14,14 @@ export declare class ConnectionService {
15
14
  */
16
15
  constructor();
17
16
  /**
18
- * Instance initializer
17
+ * Create a connection configuration object.
18
+ *
19
+ * @param config - Single `{ class, options }` or split `{ store, stream, sub }`.
20
+ * @returns The normalized connection configuration.
19
21
  */
20
22
  static connect(config: ProviderConfig | ProvidersConfig): Promise<Connection>;
23
+ /**
24
+ * Alias for {@link connect}.
25
+ */
26
+ static create: typeof ConnectionService.connect;
21
27
  }
@@ -2,13 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConnectionService = void 0;
4
4
  /**
5
- * The Connection service is used to declare the class
6
- * and connection options but does not connect quite yet. Connection
7
- * happens at a later lifecycle stage when a workflow
8
- * is started by the Durable Client module (`(new Durable.Client())).start()`).
5
+ * Declares connection configuration (driver class + options) without
6
+ * opening a connection. The actual Postgres connection is established
7
+ * lazily when a Worker or Client is started.
9
8
  *
10
- * The config options optionall support a multi-connection setup
11
- * where the `store` connection explicitly defined along with `stream`, `sub`, etc.
9
+ * Supports both single-connection and split-connection layouts (separate
10
+ * `store`, `stream`, and `sub` connections for advanced deployments).
12
11
  */
13
12
  class ConnectionService {
14
13
  /**
@@ -16,7 +15,10 @@ class ConnectionService {
16
15
  */
17
16
  constructor() { }
18
17
  /**
19
- * Instance initializer
18
+ * Create a connection configuration object.
19
+ *
20
+ * @param config - Single `{ class, options }` or split `{ store, stream, sub }`.
21
+ * @returns The normalized connection configuration.
20
22
  */
21
23
  static async connect(config) {
22
24
  return 'store' in config
@@ -28,4 +30,8 @@ class ConnectionService {
28
30
  };
29
31
  }
30
32
  }
33
+ /**
34
+ * Alias for {@link connect}.
35
+ */
36
+ ConnectionService.create = ConnectionService.connect;
31
37
  exports.ConnectionService = ConnectionService;
@@ -4,28 +4,24 @@ import { JobInterruptOptions } from '../../types/job';
4
4
  import { StreamError } from '../../types/stream';
5
5
  import { ExporterService } from './exporter';
6
6
  /**
7
- * The WorkflowHandleService provides methods to interact with a running
8
- * workflow. This includes exporting the workflow, sending signals, and
9
- * querying the state of the workflow. It is instanced/accessed via the
10
- * Durable.Client class.
7
+ * Handle to a running or completed workflow execution. Returned by
8
+ * `client.workflow.start()` and `client.workflow.getHandle()`.
11
9
  *
12
10
  * @example
13
11
  * ```typescript
14
- * import { Client } from '@hotmeshio/hotmesh';
15
- * import { Client as Postgres } from 'pg';
16
- *
17
- * const client = new Client({ connection: {
18
- * class: Postgres,
19
- * options: { connectionString: 'postgres://user:pass@localhost:5432/db' }
20
- * }});
21
- *
22
12
  * const handle = await client.workflow.start({
23
- * args: ['HotMesh'],
24
- * taskQueue: 'hello-world',
13
+ * args: ['order-123'],
14
+ * taskQueue: 'orders',
15
+ * workflowName: 'orderWorkflow',
16
+ * workflowId: Durable.guid(),
25
17
  * });
26
18
  *
27
- * //perform actions like send a signal
28
- * await handle.signal('my-signal', { data: 'Hello' });
19
+ * // Await the final result
20
+ * const result = await handle.result();
21
+ *
22
+ * // Or interact while running
23
+ * await handle.signal('approval', { approved: true });
24
+ * await handle.cancel();
29
25
  * ```
30
26
  */
31
27
  export declare class WorkflowHandleService {
@@ -41,7 +37,8 @@ export declare class WorkflowHandleService {
41
37
  */
42
38
  constructor(hotMesh: HotMesh, workflowTopic: string, workflowId: string);
43
39
  /**
44
- * Exports the workflow state to a JSON object.
40
+ * Exports the full workflow state (job hash, metadata, activity
41
+ * results) as a JSON object.
45
42
  */
46
43
  export(options?: ExportOptions): Promise<DurableJobExport>;
47
44
  /**
@@ -56,43 +53,64 @@ export declare class WorkflowHandleService {
56
53
  */
57
54
  exportExecution(options?: ExecutionExportOptions): Promise<WorkflowExecution>;
58
55
  /**
59
- * Sends a signal to the workflow. This is a way to send
60
- * a message to a workflow that is paused due to having
61
- * executed `Durable.workflow.waitFor`. The workflow
62
- * will awaken if no other signals are pending.
56
+ * Delivers a named signal to the workflow. If the workflow is paused
57
+ * on `Durable.workflow.condition(signalId)`, it resumes with the
58
+ * provided data.
59
+ *
60
+ * @param signalId - Matches the `signalId` passed to `condition()`.
61
+ * @param data - Payload delivered to the waiting workflow.
63
62
  */
64
63
  signal(signalId: string, data: Record<any, any>): Promise<void>;
65
64
  /**
66
- * Returns the job state of the workflow. If the workflow has completed
67
- * this is also the job output. If the workflow is still running, this
68
- * is the current state of the job, but it may change depending upon
69
- * the activities that remain.
65
+ * Returns the current workflow state. For a completed workflow this
66
+ * is the final output; for a running workflow it reflects the latest
67
+ * persisted state (may change as activities complete).
68
+ *
69
+ * @param metadata - If `true`, returns the full job envelope including
70
+ * internal metadata alongside the data.
70
71
  */
71
72
  state(metadata?: boolean): Promise<Record<string, any>>;
72
73
  /**
73
- * Returns the current search state of the workflow. This is
74
- * different than the job state or individual activity state.
75
- * Search state represents name/value pairs that were added
76
- * to the workflow.
74
+ * Returns key-value pairs previously written via
75
+ * `Durable.workflow.search()` or `Durable.workflow.enrich()`.
76
+ *
77
+ * @param fields - The field names to retrieve.
77
78
  */
78
79
  queryState(fields: string[]): Promise<Record<string, any>>;
79
80
  /**
80
- * Returns the current status of the workflow. This is a semaphore
81
- * value that represents the current state of the workflow, where
82
- * 0 is complete and a negative value represents that the flow was
83
- * interrupted.
81
+ * Returns the workflow's numeric status code: `0` = completed,
82
+ * positive = still running, negative = interrupted/errored.
84
83
  */
85
84
  status(): Promise<number>;
86
85
  /**
87
- * Interrupts a running workflow. Standard Job Completion tasks will
88
- * run. Subscribers will be notified and the job hash will be expired.
86
+ * Immediately terminates the workflow. The job is marked as interrupted,
87
+ * subscribers are notified, and the job hash is expired. Unlike
88
+ * {@link cancel}, this does **not** give the workflow a chance to
89
+ * run cleanup code.
89
90
  */
90
- interrupt(options?: JobInterruptOptions): Promise<string>;
91
+ terminate(options?: JobInterruptOptions): Promise<string>;
91
92
  /**
92
- * Waits for the workflow to complete and returns the result. If
93
- * the workflow response includes an error, this method will rethrow
94
- * the error, including the stack trace if available.
95
- * Wrap calls in a try/catch as necessary to avoid unhandled exceptions.
93
+ * Requests cooperative cancellation of the workflow. Unlike
94
+ * `terminate()` (which terminates immediately), `cancel()` sets
95
+ * a durable flag that the workflow detects at its next durable
96
+ * operation (`sleep`, `proxyActivities`, `executeChild`, etc.).
97
+ * The workflow receives a `CancelledFailure` error that it can
98
+ * catch to perform cleanup before exiting.
99
+ *
100
+ * ```typescript
101
+ * const handle = await client.workflow.start({ ... });
102
+ * await handle.cancel();
103
+ * // Workflow will throw CancelledFailure at its next durable operation
104
+ * ```
105
+ */
106
+ cancel(): Promise<void>;
107
+ /**
108
+ * Blocks until the workflow completes and returns the result. If the
109
+ * workflow failed, the error is rethrown (with stack trace) unless
110
+ * `throwOnError: false` is set, in which case the error object is
111
+ * returned directly.
112
+ *
113
+ * @template T - The workflow's return type.
96
114
  */
97
115
  result<T>(config?: {
98
116
  state?: boolean;