@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.
- package/README.md +18 -22
- package/build/modules/enums.d.ts +60 -5
- package/build/modules/enums.js +62 -7
- package/build/modules/errors.d.ts +15 -3
- package/build/modules/errors.js +17 -2
- package/build/package.json +6 -1
- package/build/services/activities/activity/context.d.ts +22 -0
- package/build/services/activities/activity/context.js +76 -0
- package/build/services/activities/activity/index.d.ts +116 -0
- package/build/services/activities/activity/index.js +299 -0
- package/build/services/activities/activity/mapping.d.ts +12 -0
- package/build/services/activities/activity/mapping.js +63 -0
- package/build/services/activities/activity/process.d.ts +28 -0
- package/build/services/activities/activity/process.js +100 -0
- package/build/services/activities/activity/protocol.d.ts +39 -0
- package/build/services/activities/activity/protocol.js +151 -0
- package/build/services/activities/activity/state.d.ts +40 -0
- package/build/services/activities/activity/state.js +143 -0
- package/build/services/activities/activity/transition.d.ts +23 -0
- package/build/services/activities/activity/transition.js +71 -0
- package/build/services/activities/activity/verify.d.ts +22 -0
- package/build/services/activities/activity/verify.js +85 -0
- package/build/services/activities/await.d.ts +1 -4
- package/build/services/activities/await.js +2 -36
- package/build/services/activities/cycle.d.ts +1 -11
- package/build/services/activities/cycle.js +3 -46
- package/build/services/activities/hook.d.ts +2 -11
- package/build/services/activities/hook.js +30 -50
- package/build/services/activities/interrupt.d.ts +2 -4
- package/build/services/activities/interrupt.js +4 -38
- package/build/services/activities/signal.d.ts +1 -11
- package/build/services/activities/signal.js +3 -48
- package/build/services/activities/trigger.d.ts +1 -3
- package/build/services/activities/trigger.js +0 -3
- package/build/services/activities/worker.d.ts +3 -6
- package/build/services/activities/worker.js +4 -40
- package/build/services/connector/factory.d.ts +6 -0
- package/build/services/connector/factory.js +24 -0
- package/build/services/durable/activity.d.ts +1 -1
- package/build/services/durable/activity.js +2 -2
- package/build/services/durable/client.d.ts +24 -29
- package/build/services/durable/client.js +24 -29
- package/build/services/durable/connection.d.ts +13 -7
- package/build/services/durable/connection.js +13 -7
- package/build/services/durable/handle.d.ts +58 -40
- package/build/services/durable/handle.js +60 -40
- package/build/services/durable/index.d.ts +148 -286
- package/build/services/durable/index.js +157 -292
- package/build/services/durable/interceptor.d.ts +43 -33
- package/build/services/durable/interceptor.js +59 -39
- package/build/services/durable/schemas/factory.d.ts +1 -1
- package/build/services/durable/schemas/factory.js +168 -38
- package/build/services/durable/telemetry.d.ts +80 -0
- package/build/services/durable/telemetry.js +137 -0
- package/build/services/durable/worker.d.ts +100 -21
- package/build/services/durable/worker.js +304 -63
- package/build/services/durable/workflow/all.d.ts +1 -1
- package/build/services/durable/workflow/all.js +1 -1
- package/build/services/durable/workflow/cancellationScope.d.ts +104 -0
- package/build/services/durable/workflow/cancellationScope.js +139 -0
- package/build/services/durable/workflow/common.d.ts +5 -4
- package/build/services/durable/workflow/common.js +6 -1
- package/build/services/durable/workflow/{waitFor.d.ts → condition.d.ts} +9 -8
- package/build/services/durable/workflow/{waitFor.js → condition.js} +44 -11
- package/build/services/durable/workflow/continueAsNew.d.ts +65 -0
- package/build/services/durable/workflow/continueAsNew.js +92 -0
- package/build/services/durable/workflow/didRun.d.ts +1 -1
- package/build/services/durable/workflow/didRun.js +3 -3
- package/build/services/durable/workflow/enrich.d.ts +5 -0
- package/build/services/durable/workflow/enrich.js +5 -0
- package/build/services/durable/workflow/entityMethods.d.ts +7 -0
- package/build/services/durable/workflow/entityMethods.js +7 -0
- package/build/services/durable/workflow/execHook.js +3 -3
- package/build/services/durable/workflow/execHookBatch.js +2 -2
- package/build/services/durable/workflow/{execChild.d.ts → executeChild.d.ts} +4 -40
- package/build/services/durable/workflow/{execChild.js → executeChild.js} +36 -45
- package/build/services/durable/workflow/hook.d.ts +1 -1
- package/build/services/durable/workflow/hook.js +4 -3
- package/build/services/durable/workflow/index.d.ts +45 -50
- package/build/services/durable/workflow/index.js +46 -51
- package/build/services/durable/workflow/interruption.d.ts +7 -6
- package/build/services/durable/workflow/interruption.js +11 -7
- package/build/services/durable/workflow/patched.d.ts +72 -0
- package/build/services/durable/workflow/patched.js +110 -0
- package/build/services/durable/workflow/proxyActivities.d.ts +7 -7
- package/build/services/durable/workflow/proxyActivities.js +50 -15
- package/build/services/durable/workflow/searchMethods.d.ts +7 -0
- package/build/services/durable/workflow/searchMethods.js +7 -0
- package/build/services/durable/workflow/signal.d.ts +4 -4
- package/build/services/durable/workflow/signal.js +4 -4
- package/build/services/durable/workflow/{sleepFor.d.ts → sleep.d.ts} +7 -7
- package/build/services/durable/workflow/{sleepFor.js → sleep.js} +39 -10
- package/build/services/durable/workflow/terminate.d.ts +55 -0
- package/build/services/durable/workflow/{interrupt.js → terminate.js} +21 -21
- package/build/services/durable/workflow/trace.js +2 -2
- package/build/services/durable/workflow/uuid4.d.ts +14 -0
- package/build/services/durable/workflow/uuid4.js +39 -0
- package/build/services/durable/workflow/{context.d.ts → workflowInfo.d.ts} +5 -5
- package/build/services/durable/workflow/{context.js → workflowInfo.js} +7 -7
- package/build/services/engine/compiler.d.ts +19 -0
- package/build/services/engine/compiler.js +20 -0
- package/build/services/engine/completion.d.ts +46 -0
- package/build/services/engine/completion.js +145 -0
- package/build/services/engine/dispatch.d.ts +24 -0
- package/build/services/engine/dispatch.js +98 -0
- package/build/services/engine/index.d.ts +49 -81
- package/build/services/engine/index.js +175 -573
- package/build/services/engine/init.d.ts +42 -0
- package/build/services/engine/init.js +74 -0
- package/build/services/engine/pubsub.d.ts +50 -0
- package/build/services/engine/pubsub.js +118 -0
- package/build/services/engine/reporting.d.ts +20 -0
- package/build/services/engine/reporting.js +38 -0
- package/build/services/engine/schema.d.ts +23 -0
- package/build/services/engine/schema.js +62 -0
- package/build/services/engine/signal.d.ts +57 -0
- package/build/services/engine/signal.js +117 -0
- package/build/services/engine/state.d.ts +35 -0
- package/build/services/engine/state.js +61 -0
- package/build/services/engine/version.d.ts +31 -0
- package/build/services/engine/version.js +73 -0
- package/build/services/hotmesh/deployment.d.ts +21 -0
- package/build/services/hotmesh/deployment.js +25 -0
- package/build/services/hotmesh/index.d.ts +141 -532
- package/build/services/hotmesh/index.js +222 -673
- package/build/services/hotmesh/init.d.ts +42 -0
- package/build/services/hotmesh/init.js +93 -0
- package/build/services/hotmesh/jobs.d.ts +67 -0
- package/build/services/hotmesh/jobs.js +99 -0
- package/build/services/hotmesh/pubsub.d.ts +38 -0
- package/build/services/hotmesh/pubsub.js +54 -0
- package/build/services/hotmesh/quorum.d.ts +30 -0
- package/build/services/hotmesh/quorum.js +62 -0
- package/build/services/hotmesh/validation.d.ts +6 -0
- package/build/services/hotmesh/validation.js +28 -0
- package/build/services/quorum/index.js +1 -0
- package/build/services/router/consumption/index.d.ts +11 -5
- package/build/services/router/consumption/index.js +24 -17
- package/build/services/router/error-handling/index.d.ts +2 -2
- package/build/services/router/error-handling/index.js +14 -14
- package/build/services/router/index.d.ts +1 -1
- package/build/services/router/index.js +2 -2
- package/build/services/serializer/index.d.ts +22 -0
- package/build/services/serializer/index.js +39 -1
- package/build/services/store/index.d.ts +1 -0
- package/build/services/store/providers/postgres/exporter-sql.d.ts +2 -2
- package/build/services/store/providers/postgres/exporter-sql.js +4 -4
- package/build/services/store/providers/postgres/kvtables.js +7 -6
- package/build/services/store/providers/postgres/kvtypes/hash/basic.js +67 -52
- package/build/services/store/providers/postgres/kvtypes/hash/jsonb.js +87 -72
- package/build/services/store/providers/postgres/kvtypes/hash/udata.js +106 -79
- package/build/services/store/providers/postgres/kvtypes/hash/utils.d.ts +16 -0
- package/build/services/store/providers/postgres/kvtypes/hash/utils.js +29 -16
- package/build/services/store/providers/postgres/postgres.d.ts +1 -0
- package/build/services/store/providers/postgres/postgres.js +14 -4
- package/build/services/stream/factory.d.ts +3 -1
- package/build/services/stream/factory.js +2 -2
- package/build/services/stream/index.d.ts +1 -0
- package/build/services/stream/providers/nats/nats.d.ts +1 -0
- package/build/services/stream/providers/nats/nats.js +1 -0
- package/build/services/stream/providers/postgres/credentials.d.ts +56 -0
- package/build/services/stream/providers/postgres/credentials.js +129 -0
- package/build/services/stream/providers/postgres/kvtables.js +18 -0
- package/build/services/stream/providers/postgres/messages.js +7 -7
- package/build/services/stream/providers/postgres/notifications.js +16 -2
- package/build/services/stream/providers/postgres/postgres.d.ts +7 -0
- package/build/services/stream/providers/postgres/postgres.js +35 -4
- package/build/services/stream/providers/postgres/procedures.d.ts +21 -0
- package/build/services/stream/providers/postgres/procedures.js +213 -0
- package/build/services/stream/providers/postgres/secured.d.ts +34 -0
- package/build/services/stream/providers/postgres/secured.js +146 -0
- package/build/services/stream/providers/postgres/stats.d.ts +1 -0
- package/build/services/stream/providers/postgres/stats.js +1 -0
- package/build/services/stream/registry.d.ts +1 -1
- package/build/services/stream/registry.js +5 -2
- package/build/services/telemetry/index.d.ts +10 -1
- package/build/services/telemetry/index.js +40 -7
- package/build/services/worker/credentials.d.ts +51 -0
- package/build/services/worker/credentials.js +87 -0
- package/build/services/worker/index.d.ts +2 -2
- package/build/services/worker/index.js +7 -6
- package/build/types/codec.d.ts +84 -0
- package/build/types/codec.js +2 -0
- package/build/types/durable.d.ts +104 -28
- package/build/types/error.d.ts +10 -1
- package/build/types/hotmesh.d.ts +67 -4
- package/build/types/index.d.ts +2 -1
- package/build/types/provider.d.ts +2 -2
- package/build/types/quorum.d.ts +35 -1
- package/build/types/stream.d.ts +12 -6
- package/package.json +6 -1
- package/build/services/activities/activity.d.ts +0 -192
- package/build/services/activities/activity.js +0 -786
- 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 `
|
|
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
|
-
*
|
|
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
|
-
|
|
153
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
16
|
-
* import { Client, HotMesh } from '@hotmeshio/hotmesh';
|
|
8
|
+
* import { Durable } from '@hotmeshio/hotmesh';
|
|
17
9
|
* import { Client as Postgres } from 'pg';
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
26
|
-
* import { Client, HotMesh } from '@hotmeshio/hotmesh';
|
|
18
|
+
* import { Durable } from '@hotmeshio/hotmesh';
|
|
27
19
|
* import { Client as Postgres } from 'pg';
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
*
|
|
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
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
10
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
*
|
|
11
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
8
|
-
* workflow.
|
|
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
|
-
*
|
|
24
|
-
*
|
|
13
|
+
* args: ['order-123'],
|
|
14
|
+
* taskQueue: 'orders',
|
|
15
|
+
* workflowName: 'orderWorkflow',
|
|
16
|
+
* workflowId: Durable.guid(),
|
|
25
17
|
* });
|
|
26
18
|
*
|
|
27
|
-
* //
|
|
28
|
-
* await handle.
|
|
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
|
|
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
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
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
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
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
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* to
|
|
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
|
|
81
|
-
*
|
|
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
|
-
*
|
|
88
|
-
*
|
|
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
|
-
|
|
91
|
+
terminate(options?: JobInterruptOptions): Promise<string>;
|
|
91
92
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
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;
|