@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
package/README.md
CHANGED
|
@@ -61,13 +61,11 @@ export async function notifyBackorder(itemId: string): Promise<void> {
|
|
|
61
61
|
```typescript
|
|
62
62
|
// workflows.ts
|
|
63
63
|
import { Durable } from '@hotmeshio/hotmesh';
|
|
64
|
-
import * as activities from './activities';
|
|
64
|
+
import type * as activities from './activities';
|
|
65
65
|
|
|
66
66
|
export async function orderWorkflow(itemId: string, qty: number) {
|
|
67
67
|
const { checkInventory, reserveItem, notifyBackorder } =
|
|
68
|
-
Durable.workflow.proxyActivities<typeof activities>(
|
|
69
|
-
taskQueue: 'inventory-tasks'
|
|
70
|
-
});
|
|
68
|
+
Durable.workflow.proxyActivities<typeof activities>();
|
|
71
69
|
|
|
72
70
|
const available = await checkInventory(itemId);
|
|
73
71
|
|
|
@@ -80,20 +78,18 @@ export async function orderWorkflow(itemId: string, qty: number) {
|
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
// main.ts
|
|
81
|
+
import * as activities from './activities';
|
|
82
|
+
|
|
83
83
|
const connection = {
|
|
84
84
|
class: Postgres,
|
|
85
85
|
options: { connectionString: 'postgresql://localhost:5432/mydb' }
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
-
await Durable.registerActivityWorker({
|
|
89
|
-
connection,
|
|
90
|
-
taskQueue: 'inventory-tasks'
|
|
91
|
-
}, activities, 'inventory-activities');
|
|
92
|
-
|
|
93
88
|
await Durable.Worker.create({
|
|
94
89
|
connection,
|
|
95
90
|
taskQueue: 'orders',
|
|
96
|
-
workflow: orderWorkflow
|
|
91
|
+
workflow: orderWorkflow,
|
|
92
|
+
activities,
|
|
97
93
|
});
|
|
98
94
|
|
|
99
95
|
const client = new Durable.Client({ connection });
|
|
@@ -206,11 +202,11 @@ All snippets below run inside a workflow function (like `orderWorkflow` above).
|
|
|
206
202
|
import { Durable } from '@hotmeshio/hotmesh';
|
|
207
203
|
```
|
|
208
204
|
|
|
209
|
-
**Long-running workflows** — `
|
|
205
|
+
**Long-running workflows** — `sleep` is durable. The process can restart; the timer survives.
|
|
210
206
|
|
|
211
207
|
```typescript
|
|
212
208
|
// sendFollowUp is a proxied activity from proxyActivities()
|
|
213
|
-
await Durable.workflow.
|
|
209
|
+
await Durable.workflow.sleep('30 days');
|
|
214
210
|
await sendFollowUp();
|
|
215
211
|
```
|
|
216
212
|
|
|
@@ -228,18 +224,18 @@ const [payment, inventory, shipment] = await Promise.all([
|
|
|
228
224
|
**Child workflows** — compose workflows from other workflows.
|
|
229
225
|
|
|
230
226
|
```typescript
|
|
231
|
-
const
|
|
227
|
+
const result = await Durable.workflow.executeChild({
|
|
232
228
|
args: [orderId],
|
|
233
229
|
taskQueue: 'validation',
|
|
234
|
-
|
|
230
|
+
workflowName: 'validateOrder',
|
|
231
|
+
workflowId: `validate-${orderId}`,
|
|
235
232
|
});
|
|
236
|
-
const validation = await childHandle.result();
|
|
237
233
|
```
|
|
238
234
|
|
|
239
235
|
**Signals** — pause a workflow until an external event arrives.
|
|
240
236
|
|
|
241
237
|
```typescript
|
|
242
|
-
const approval = await Durable.workflow.
|
|
238
|
+
const approval = await Durable.workflow.condition<{ approved: boolean }>('manager-approval');
|
|
243
239
|
if (!approval.approved) return 'rejected';
|
|
244
240
|
```
|
|
245
241
|
|
|
@@ -248,10 +244,9 @@ if (!approval.approved) return 'rejected';
|
|
|
248
244
|
Activities retry automatically on failure. Configure the policy per activity or per worker:
|
|
249
245
|
|
|
250
246
|
```typescript
|
|
251
|
-
// Durable: per-activity retry policy
|
|
247
|
+
// Durable: per-activity retry policy (activities registered at Worker.create)
|
|
252
248
|
const { reserveItem } = Durable.workflow.proxyActivities<typeof activities>({
|
|
253
|
-
|
|
254
|
-
retryPolicy: {
|
|
249
|
+
retry: {
|
|
255
250
|
maximumAttempts: 5,
|
|
256
251
|
backoffCoefficient: 2,
|
|
257
252
|
maximumInterval: '60s'
|
|
@@ -267,7 +262,7 @@ const hotMesh = await HotMesh.init({
|
|
|
267
262
|
workers: [{
|
|
268
263
|
topic: 'inventory.reserve',
|
|
269
264
|
connection,
|
|
270
|
-
|
|
265
|
+
retry: {
|
|
271
266
|
maximumAttempts: 5,
|
|
272
267
|
backoffCoefficient: 2,
|
|
273
268
|
maximumInterval: '60s'
|
|
@@ -290,7 +285,8 @@ SELECT
|
|
|
290
285
|
j.key AS job_key,
|
|
291
286
|
j.status AS semaphore,
|
|
292
287
|
j.entity AS workflow,
|
|
293
|
-
a.
|
|
288
|
+
a.symbol AS attribute,
|
|
289
|
+
a.dimension AS dimension,
|
|
294
290
|
a.value AS value,
|
|
295
291
|
j.created_at,
|
|
296
292
|
j.updated_at
|
|
@@ -300,7 +296,7 @@ FROM
|
|
|
300
296
|
WHERE
|
|
301
297
|
j.key = 'order-456'
|
|
302
298
|
ORDER BY
|
|
303
|
-
a.
|
|
299
|
+
a.symbol, a.dimension;
|
|
304
300
|
```
|
|
305
301
|
|
|
306
302
|
What happened? Consult the database. What's still running? Query the semaphore. What failed? Read the row. The execution state isn't reconstructed from a log — it was committed transactionally as each step ran.
|
package/build/modules/enums.d.ts
CHANGED
|
@@ -4,7 +4,51 @@ import { LogLevel } from '../types/logger';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const HMSH_LOGLEVEL: LogLevel;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Controls which OpenTelemetry spans are emitted. Spans are only
|
|
8
|
+
* captured when an OTel SDK (TracerProvider + exporter) is registered
|
|
9
|
+
* before workers start. Without an SDK, all span calls are no-ops.
|
|
10
|
+
*
|
|
11
|
+
* ## Modes
|
|
12
|
+
*
|
|
13
|
+
* | Value | Durable workflows | YAML flows |
|
|
14
|
+
* |-------|-------------------|------------|
|
|
15
|
+
* | `'info'` (default) | `WORKFLOW/START`, `WORKFLOW/COMPLETE`, `WORKFLOW/ERROR`, `ACTIVITY/{name}` | trigger + worker spans |
|
|
16
|
+
* | `'debug'` | All `info` spans + `DISPATCH/{type}/{name}/{idx}`, `RETURN/{type}/{name}/{idx}` + engine internals | All activity types + all stream hops |
|
|
17
|
+
*
|
|
18
|
+
* ## Setup
|
|
19
|
+
*
|
|
20
|
+
* Register an OpenTelemetry SDK with a trace exporter **before**
|
|
21
|
+
* calling `Durable.Worker.create()`. Any OTLP-compatible backend
|
|
22
|
+
* works (Honeycomb, Jaeger, Grafana Tempo, etc.):
|
|
23
|
+
*
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
26
|
+
* import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
|
|
27
|
+
* import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
28
|
+
* import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
29
|
+
*
|
|
30
|
+
* const sdk = new NodeSDK({
|
|
31
|
+
* resource: resourceFromAttributes({
|
|
32
|
+
* [ATTR_SERVICE_NAME]: 'my-service',
|
|
33
|
+
* }),
|
|
34
|
+
* traceExporter: new OTLPTraceExporter({
|
|
35
|
+
* url: 'https://api.honeycomb.io/v1/traces',
|
|
36
|
+
* headers: { 'x-honeycomb-team': process.env.HONEYCOMB_API_KEY },
|
|
37
|
+
* }),
|
|
38
|
+
* });
|
|
39
|
+
* sdk.start();
|
|
40
|
+
*
|
|
41
|
+
* // Then start workers — spans flow automatically
|
|
42
|
+
* await Durable.Worker.create({ ... });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* ```bash
|
|
46
|
+
* # Concise: workflow lifecycle + activity execution only
|
|
47
|
+
* HMSH_TELEMETRY=info node worker.js
|
|
48
|
+
*
|
|
49
|
+
* # Verbose: adds per-operation DISPATCH/RETURN spans + engine internals
|
|
50
|
+
* HMSH_TELEMETRY=debug node worker.js
|
|
51
|
+
* ```
|
|
8
52
|
*/
|
|
9
53
|
export declare const HMSH_TELEMETRY: "debug" | "info";
|
|
10
54
|
/**
|
|
@@ -34,6 +78,10 @@ export declare const HMSH_CODE_DURABLE_CHILD = 590;
|
|
|
34
78
|
* This is thrown when a Durable has been interrupted by a proxyActivity call.
|
|
35
79
|
*/
|
|
36
80
|
export declare const HMSH_CODE_DURABLE_PROXY = 591;
|
|
81
|
+
/**
|
|
82
|
+
* This is thrown when a Durable has been interrupted by a continueAsNew call.
|
|
83
|
+
*/
|
|
84
|
+
export declare const HMSH_CODE_DURABLE_CONTINUE = 592;
|
|
37
85
|
/**
|
|
38
86
|
* This is thrown when a Durable has been interrupted by a waitForSignal call.
|
|
39
87
|
*/
|
|
@@ -83,9 +131,9 @@ export declare const HMSH_MAX_TIMEOUT_MS: number;
|
|
|
83
131
|
export declare const HMSH_GRADUATED_INTERVAL_MS: number;
|
|
84
132
|
/**
|
|
85
133
|
* The maximum number of attempts to retry a Durable job before it is considered failed.
|
|
86
|
-
* @default
|
|
134
|
+
* @default 50
|
|
87
135
|
*/
|
|
88
|
-
export declare const HMSH_DURABLE_MAX_ATTEMPTS =
|
|
136
|
+
export declare const HMSH_DURABLE_MAX_ATTEMPTS = 50;
|
|
89
137
|
/**
|
|
90
138
|
* The maximum interval to wait before retrying a Durable job.
|
|
91
139
|
* @default 120s
|
|
@@ -93,9 +141,16 @@ export declare const HMSH_DURABLE_MAX_ATTEMPTS = 3;
|
|
|
93
141
|
export declare const HMSH_DURABLE_MAX_INTERVAL = "120s";
|
|
94
142
|
/**
|
|
95
143
|
* The exponential backoff factor to apply to the interval between retries.
|
|
96
|
-
* @default
|
|
144
|
+
* @default 5
|
|
145
|
+
*/
|
|
146
|
+
export declare const HMSH_DURABLE_EXP_BACKOFF = 5;
|
|
147
|
+
/**
|
|
148
|
+
* The initial interval (in seconds) before the first retry attempt.
|
|
149
|
+
* The retry formula is: initialInterval * backoffCoefficient^retryCount,
|
|
150
|
+
* clamped by maximumInterval.
|
|
151
|
+
* @default 1
|
|
97
152
|
*/
|
|
98
|
-
export declare const
|
|
153
|
+
export declare const HMSH_DURABLE_INITIAL_INTERVAL = 1;
|
|
99
154
|
export declare const HMSH_BLOCK_TIME_MS: number;
|
|
100
155
|
export declare const HMSH_XCLAIM_DELAY_MS: number;
|
|
101
156
|
export declare const HMSH_XCLAIM_COUNT: number;
|
package/build/modules/enums.js
CHANGED
|
@@ -1,13 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.HMSH_ROUTER_POLL_FALLBACK_INTERVAL = void 0;
|
|
3
|
+
exports.HMSH_GUID_SIZE = exports.HMSH_ROUTER_SCOUT_INTERVAL_MS = exports.HMSH_ROUTER_SCOUT_INTERVAL_SECONDS = exports.HMSH_SCOUT_INTERVAL_SECONDS = exports.HMSH_FIDELITY_SECONDS = exports.HMSH_EXPIRE_DURATION = exports.HMSH_XPENDING_COUNT = exports.HMSH_XCLAIM_COUNT = exports.HMSH_XCLAIM_DELAY_MS = exports.HMSH_BLOCK_TIME_MS = exports.HMSH_DURABLE_INITIAL_INTERVAL = exports.HMSH_DURABLE_EXP_BACKOFF = exports.HMSH_DURABLE_MAX_INTERVAL = exports.HMSH_DURABLE_MAX_ATTEMPTS = exports.HMSH_GRADUATED_INTERVAL_MS = exports.HMSH_MAX_TIMEOUT_MS = exports.HMSH_POISON_MESSAGE_THRESHOLD = exports.HMSH_MAX_RETRIES = exports.MAX_DELAY = exports.MAX_STREAM_RETRIES = exports.INITIAL_STREAM_BACKOFF = exports.MAX_STREAM_BACKOFF = exports.HMSH_EXPIRE_JOB_SECONDS = exports.HMSH_OTT_WAIT_TIME = exports.HMSH_DEPLOYMENT_PAUSE = exports.HMSH_DEPLOYMENT_DELAY = exports.HMSH_ACTIVATION_MAX_RETRY = exports.HMSH_QUORUM_DELAY_MS = exports.HMSH_QUORUM_ROLLCALL_CYCLES = exports.HMSH_STATUS_UNKNOWN = exports.HMSH_CODE_DURABLE_RETRYABLE = exports.HMSH_CODE_DURABLE_FATAL = exports.HMSH_CODE_DURABLE_MAXED = exports.HMSH_CODE_DURABLE_TIMEOUT = exports.HMSH_CODE_DURABLE_WAIT = exports.HMSH_CODE_DURABLE_CONTINUE = exports.HMSH_CODE_DURABLE_PROXY = exports.HMSH_CODE_DURABLE_CHILD = exports.HMSH_CODE_DURABLE_ALL = exports.HMSH_CODE_DURABLE_SLEEP = exports.HMSH_CODE_UNACKED = exports.HMSH_CODE_TIMEOUT = exports.HMSH_CODE_UNKNOWN = exports.HMSH_CODE_INTERRUPT = exports.HMSH_CODE_NOTFOUND = exports.HMSH_CODE_PENDING = exports.HMSH_CODE_SUCCESS = exports.HMSH_SIGNAL_EXPIRE = exports.HMSH_TELEMETRY = exports.HMSH_LOGLEVEL = void 0;
|
|
4
|
+
exports.HMSH_ROUTER_POLL_FALLBACK_INTERVAL = exports.HMSH_NOTIFY_PAYLOAD_LIMIT = exports.DEFAULT_TASK_QUEUE = void 0;
|
|
5
5
|
/**
|
|
6
6
|
* Determines the log level for the application. The default is 'info'.
|
|
7
7
|
*/
|
|
8
8
|
exports.HMSH_LOGLEVEL = process.env.HMSH_LOGLEVEL || 'info';
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Controls which OpenTelemetry spans are emitted. Spans are only
|
|
11
|
+
* captured when an OTel SDK (TracerProvider + exporter) is registered
|
|
12
|
+
* before workers start. Without an SDK, all span calls are no-ops.
|
|
13
|
+
*
|
|
14
|
+
* ## Modes
|
|
15
|
+
*
|
|
16
|
+
* | Value | Durable workflows | YAML flows |
|
|
17
|
+
* |-------|-------------------|------------|
|
|
18
|
+
* | `'info'` (default) | `WORKFLOW/START`, `WORKFLOW/COMPLETE`, `WORKFLOW/ERROR`, `ACTIVITY/{name}` | trigger + worker spans |
|
|
19
|
+
* | `'debug'` | All `info` spans + `DISPATCH/{type}/{name}/{idx}`, `RETURN/{type}/{name}/{idx}` + engine internals | All activity types + all stream hops |
|
|
20
|
+
*
|
|
21
|
+
* ## Setup
|
|
22
|
+
*
|
|
23
|
+
* Register an OpenTelemetry SDK with a trace exporter **before**
|
|
24
|
+
* calling `Durable.Worker.create()`. Any OTLP-compatible backend
|
|
25
|
+
* works (Honeycomb, Jaeger, Grafana Tempo, etc.):
|
|
26
|
+
*
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
29
|
+
* import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
|
|
30
|
+
* import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
31
|
+
* import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
32
|
+
*
|
|
33
|
+
* const sdk = new NodeSDK({
|
|
34
|
+
* resource: resourceFromAttributes({
|
|
35
|
+
* [ATTR_SERVICE_NAME]: 'my-service',
|
|
36
|
+
* }),
|
|
37
|
+
* traceExporter: new OTLPTraceExporter({
|
|
38
|
+
* url: 'https://api.honeycomb.io/v1/traces',
|
|
39
|
+
* headers: { 'x-honeycomb-team': process.env.HONEYCOMB_API_KEY },
|
|
40
|
+
* }),
|
|
41
|
+
* });
|
|
42
|
+
* sdk.start();
|
|
43
|
+
*
|
|
44
|
+
* // Then start workers — spans flow automatically
|
|
45
|
+
* await Durable.Worker.create({ ... });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* ```bash
|
|
49
|
+
* # Concise: workflow lifecycle + activity execution only
|
|
50
|
+
* HMSH_TELEMETRY=info node worker.js
|
|
51
|
+
*
|
|
52
|
+
* # Verbose: adds per-operation DISPATCH/RETURN spans + engine internals
|
|
53
|
+
* HMSH_TELEMETRY=debug node worker.js
|
|
54
|
+
* ```
|
|
11
55
|
*/
|
|
12
56
|
exports.HMSH_TELEMETRY = process.env.HMSH_TELEMETRY || 'info';
|
|
13
57
|
/**
|
|
@@ -39,6 +83,10 @@ exports.HMSH_CODE_DURABLE_CHILD = 590;
|
|
|
39
83
|
* This is thrown when a Durable has been interrupted by a proxyActivity call.
|
|
40
84
|
*/
|
|
41
85
|
exports.HMSH_CODE_DURABLE_PROXY = 591;
|
|
86
|
+
/**
|
|
87
|
+
* This is thrown when a Durable has been interrupted by a continueAsNew call.
|
|
88
|
+
*/
|
|
89
|
+
exports.HMSH_CODE_DURABLE_CONTINUE = 592;
|
|
42
90
|
/**
|
|
43
91
|
* This is thrown when a Durable has been interrupted by a waitForSignal call.
|
|
44
92
|
*/
|
|
@@ -94,9 +142,9 @@ exports.HMSH_GRADUATED_INTERVAL_MS = parseInt(process.env.HMSH_GRADUATED_INTERVA
|
|
|
94
142
|
// DURABLE
|
|
95
143
|
/**
|
|
96
144
|
* The maximum number of attempts to retry a Durable job before it is considered failed.
|
|
97
|
-
* @default
|
|
145
|
+
* @default 50
|
|
98
146
|
*/
|
|
99
|
-
exports.HMSH_DURABLE_MAX_ATTEMPTS =
|
|
147
|
+
exports.HMSH_DURABLE_MAX_ATTEMPTS = 50;
|
|
100
148
|
/**
|
|
101
149
|
* The maximum interval to wait before retrying a Durable job.
|
|
102
150
|
* @default 120s
|
|
@@ -104,9 +152,16 @@ exports.HMSH_DURABLE_MAX_ATTEMPTS = 3;
|
|
|
104
152
|
exports.HMSH_DURABLE_MAX_INTERVAL = '120s';
|
|
105
153
|
/**
|
|
106
154
|
* The exponential backoff factor to apply to the interval between retries.
|
|
107
|
-
* @default
|
|
155
|
+
* @default 5
|
|
156
|
+
*/
|
|
157
|
+
exports.HMSH_DURABLE_EXP_BACKOFF = 5;
|
|
158
|
+
/**
|
|
159
|
+
* The initial interval (in seconds) before the first retry attempt.
|
|
160
|
+
* The retry formula is: initialInterval * backoffCoefficient^retryCount,
|
|
161
|
+
* clamped by maximumInterval.
|
|
162
|
+
* @default 1
|
|
108
163
|
*/
|
|
109
|
-
exports.
|
|
164
|
+
exports.HMSH_DURABLE_INITIAL_INTERVAL = 1;
|
|
110
165
|
const BASE_BLOCK_DURATION = 10000;
|
|
111
166
|
const TEST_BLOCK_DURATION = 1000;
|
|
112
167
|
exports.HMSH_BLOCK_TIME_MS = process.env.HMSH_BLOCK_TIME_MS
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActivityDuplex } from '../types/activity';
|
|
2
2
|
import { CollationFaultType, CollationStage } from '../types/collator';
|
|
3
|
-
import { DurableChildErrorType, DurableProxyErrorType, DurableSleepErrorType, DurableWaitForAllErrorType, DurableWaitForErrorType } from '../types/error';
|
|
3
|
+
import { DurableChildErrorType, DurableContinueAsNewErrorType, DurableProxyErrorType, DurableSleepErrorType, DurableWaitForAllErrorType, DurableWaitForErrorType } from '../types/error';
|
|
4
4
|
declare class GetStateError extends Error {
|
|
5
5
|
jobId: string;
|
|
6
6
|
code: number;
|
|
@@ -21,15 +21,17 @@ declare class DurableWaitForError extends Error {
|
|
|
21
21
|
declare class DurableProxyError extends Error {
|
|
22
22
|
activityName: string;
|
|
23
23
|
arguments: string[];
|
|
24
|
-
|
|
24
|
+
headers?: Record<string, any>;
|
|
25
25
|
backoffCoefficient: number;
|
|
26
26
|
code: number;
|
|
27
27
|
index: number;
|
|
28
|
+
initialInterval: number;
|
|
28
29
|
maximumAttempts: number;
|
|
29
30
|
maximumInterval: number;
|
|
30
31
|
originJobId: string | null;
|
|
31
32
|
parentWorkflowId: string;
|
|
32
33
|
expire: number;
|
|
34
|
+
startToCloseTimeout: number;
|
|
33
35
|
workflowDimension: string;
|
|
34
36
|
workflowId: string;
|
|
35
37
|
workflowTopic: string;
|
|
@@ -43,6 +45,7 @@ declare class DurableChildError extends Error {
|
|
|
43
45
|
backoffCoefficient: number;
|
|
44
46
|
code: number;
|
|
45
47
|
expire: number;
|
|
48
|
+
initialInterval: number;
|
|
46
49
|
persistent: boolean;
|
|
47
50
|
signalIn: boolean;
|
|
48
51
|
workflowDimension: string;
|
|
@@ -80,6 +83,15 @@ declare class DurableSleepError extends Error {
|
|
|
80
83
|
type: string;
|
|
81
84
|
constructor(params: DurableSleepErrorType);
|
|
82
85
|
}
|
|
86
|
+
declare class DurableContinueAsNewError extends Error {
|
|
87
|
+
workflowId: string;
|
|
88
|
+
code: number;
|
|
89
|
+
arguments: any[];
|
|
90
|
+
index: number;
|
|
91
|
+
workflowDimension: string;
|
|
92
|
+
type: string;
|
|
93
|
+
constructor(params: DurableContinueAsNewErrorType);
|
|
94
|
+
}
|
|
83
95
|
declare class DurableTimeoutError extends Error {
|
|
84
96
|
code: number;
|
|
85
97
|
type: string;
|
|
@@ -134,4 +146,4 @@ declare class CollationError extends Error {
|
|
|
134
146
|
fault: CollationFaultType;
|
|
135
147
|
constructor(status: number, leg: ActivityDuplex, stage: CollationStage, fault?: CollationFaultType);
|
|
136
148
|
}
|
|
137
|
-
export { CollationError, DurableChildError, DurableFatalError, DurableMaxedError, DurableProxyError, DurableRetryError, DurableSleepError, DurableTimeoutError, DurableWaitForAllError, DurableWaitForError, DuplicateJobError, ExecActivityError, GenerationalError, GetStateError, InactiveJobError, MapDataError, RegisterTimeoutError, SetStateError, };
|
|
149
|
+
export { CollationError, DurableChildError, DurableContinueAsNewError, DurableFatalError, DurableMaxedError, DurableProxyError, DurableRetryError, DurableSleepError, DurableTimeoutError, DurableWaitForAllError, DurableWaitForError, DuplicateJobError, ExecActivityError, GenerationalError, GetStateError, InactiveJobError, MapDataError, RegisterTimeoutError, SetStateError, };
|
package/build/modules/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SetStateError = exports.RegisterTimeoutError = exports.MapDataError = exports.InactiveJobError = exports.GetStateError = exports.GenerationalError = exports.ExecActivityError = exports.DuplicateJobError = exports.DurableWaitForError = exports.DurableWaitForAllError = exports.DurableTimeoutError = exports.DurableSleepError = exports.DurableRetryError = exports.DurableProxyError = exports.DurableMaxedError = exports.DurableFatalError = exports.DurableChildError = exports.CollationError = void 0;
|
|
3
|
+
exports.SetStateError = exports.RegisterTimeoutError = exports.MapDataError = exports.InactiveJobError = exports.GetStateError = exports.GenerationalError = exports.ExecActivityError = exports.DuplicateJobError = exports.DurableWaitForError = exports.DurableWaitForAllError = exports.DurableTimeoutError = exports.DurableSleepError = exports.DurableRetryError = exports.DurableProxyError = exports.DurableMaxedError = exports.DurableFatalError = exports.DurableContinueAsNewError = exports.DurableChildError = exports.CollationError = void 0;
|
|
4
4
|
const enums_1 = require("./enums");
|
|
5
5
|
class GetStateError extends Error {
|
|
6
6
|
constructor(jobId) {
|
|
@@ -32,7 +32,7 @@ class DurableProxyError extends Error {
|
|
|
32
32
|
super(`ProxyActivity Interruption`);
|
|
33
33
|
this.type = 'DurableProxyError';
|
|
34
34
|
this.arguments = params.arguments;
|
|
35
|
-
this.
|
|
35
|
+
this.headers = params.headers;
|
|
36
36
|
this.workflowId = params.workflowId;
|
|
37
37
|
this.workflowTopic = params.workflowTopic;
|
|
38
38
|
this.parentWorkflowId = params.parentWorkflowId;
|
|
@@ -42,8 +42,10 @@ class DurableProxyError extends Error {
|
|
|
42
42
|
this.activityName = params.activityName;
|
|
43
43
|
this.workflowDimension = params.workflowDimension;
|
|
44
44
|
this.backoffCoefficient = params.backoffCoefficient;
|
|
45
|
+
this.initialInterval = params.initialInterval;
|
|
45
46
|
this.maximumAttempts = params.maximumAttempts;
|
|
46
47
|
this.maximumInterval = params.maximumInterval;
|
|
48
|
+
this.startToCloseTimeout = params.startToCloseTimeout;
|
|
47
49
|
this.code = enums_1.HMSH_CODE_DURABLE_PROXY;
|
|
48
50
|
}
|
|
49
51
|
}
|
|
@@ -68,6 +70,7 @@ class DurableChildError extends Error {
|
|
|
68
70
|
this.code = enums_1.HMSH_CODE_DURABLE_CHILD;
|
|
69
71
|
this.await = params.await;
|
|
70
72
|
this.backoffCoefficient = params.backoffCoefficient;
|
|
73
|
+
this.initialInterval = params.initialInterval;
|
|
71
74
|
this.maximumAttempts = params.maximumAttempts;
|
|
72
75
|
this.maximumInterval = params.maximumInterval;
|
|
73
76
|
}
|
|
@@ -101,6 +104,18 @@ class DurableSleepError extends Error {
|
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
exports.DurableSleepError = DurableSleepError;
|
|
107
|
+
class DurableContinueAsNewError extends Error {
|
|
108
|
+
constructor(params) {
|
|
109
|
+
super(`ContinueAsNew Interruption`);
|
|
110
|
+
this.type = 'DurableContinueAsNewError';
|
|
111
|
+
this.arguments = params.arguments;
|
|
112
|
+
this.workflowId = params.workflowId;
|
|
113
|
+
this.index = params.index;
|
|
114
|
+
this.workflowDimension = params.workflowDimension;
|
|
115
|
+
this.code = enums_1.HMSH_CODE_DURABLE_CONTINUE;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.DurableContinueAsNewError = DurableContinueAsNewError;
|
|
104
119
|
class DurableTimeoutError extends Error {
|
|
105
120
|
constructor(message, stack) {
|
|
106
121
|
super(message);
|
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hotmeshio/hotmesh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Durable Workflow",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"test:durable:interceptor": "HMSH_LOGLEVEL=info vitest run tests/durable/interceptor/postgres.test.ts",
|
|
36
36
|
"test:durable:metadata": "HMSH_LOGLEVEL=info vitest run tests/durable/interceptor/postgres.test.ts -t 'argumentMetadata'",
|
|
37
37
|
"test:durable:entity": "HMSH_LOGLEVEL=debug vitest run tests/durable/entity/postgres.test.ts",
|
|
38
|
+
"test:durable:config": "HMSH_LOGLEVEL=debug vitest run tests/durable/config-parity/postgres.test.ts",
|
|
38
39
|
"test:durable:agent": "HMSH_LOGLEVEL=debug vitest run tests/durable/agent/postgres.test.ts",
|
|
39
40
|
"test:durable:hello": "HMSH_TELEMETRY=debug HMSH_LOGLEVEL=info vitest run tests/durable/helloworld/postgres.test.ts",
|
|
40
41
|
"test:durable:hook": "vitest run tests/durable/hook/postgres.test.ts",
|
|
@@ -49,11 +50,15 @@
|
|
|
49
50
|
"test:durable:unknown": "vitest run tests/durable/unknown/postgres.test.ts",
|
|
50
51
|
"test:durable:exporter": "HMSH_LOGLEVEL=info vitest run tests/durable/exporter",
|
|
51
52
|
"test:durable:exporter:debug": "EXPORT_DEBUG=1 HMSH_LOGLEVEL=error vitest run tests/durable/basic/postgres.test.ts",
|
|
53
|
+
"test:durable:codec": "vitest run tests/durable/codec/postgres.test.ts",
|
|
54
|
+
"test:durable:credentials": "vitest run tests/durable/credentials/postgres.test.ts",
|
|
52
55
|
"test:dba": "vitest run tests/dba",
|
|
53
56
|
"test:cycle": "vitest run tests/functional/cycle",
|
|
54
57
|
"test:functional": "vitest run tests/functional",
|
|
55
58
|
"test:emit": "vitest run tests/functional/emit",
|
|
56
59
|
"test:pending": "vitest run tests/functional/pending/index.test.ts",
|
|
60
|
+
"test:codec": "vitest run tests/functional/codec/postgres.test.ts",
|
|
61
|
+
"test:credentials": "vitest run tests/functional/credentials/postgres.test.ts",
|
|
57
62
|
"test:hmsh": "vitest run tests/functional/postgres.test.ts",
|
|
58
63
|
"test:hook": "vitest run tests/functional/hook/postgres.test.ts",
|
|
59
64
|
"test:interrupt": "vitest run tests/functional/interrupt/postgres.test.ts",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ActivityData, ActivityMetadata, ActivityType } from '../../../types/activity';
|
|
2
|
+
import { JobState } from '../../../types/job';
|
|
3
|
+
import { StringAnyType } from '../../../types/serializer';
|
|
4
|
+
import { StreamStatus } from '../../../types/stream';
|
|
5
|
+
interface ContextInstance {
|
|
6
|
+
config: ActivityType;
|
|
7
|
+
context: JobState;
|
|
8
|
+
metadata: ActivityMetadata;
|
|
9
|
+
data: ActivityData;
|
|
10
|
+
status: StreamStatus;
|
|
11
|
+
adjacentIndex: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function initSelf(instance: ContextInstance, context: StringAnyType): JobState;
|
|
14
|
+
export declare function initPolicies(instance: ContextInstance, context: JobState): void;
|
|
15
|
+
export declare function initDimensionalAddress(instance: ContextInstance, dad: string): void;
|
|
16
|
+
export declare function assertGenerationalId(jobGID: string, msgGID: string, context: JobState): void;
|
|
17
|
+
export declare function resolveDad(instance: ContextInstance): string;
|
|
18
|
+
export declare function resolveAdjacentDad(instance: ContextInstance): string;
|
|
19
|
+
export declare function bindActivityData(instance: ContextInstance, type: 'output' | 'hook'): void;
|
|
20
|
+
export declare function bindActivityError(instance: ContextInstance, data: Record<string, unknown>): void;
|
|
21
|
+
export declare function bindJobError(instance: ContextInstance, data: Record<string, unknown>): void;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bindJobError = exports.bindActivityError = exports.bindActivityData = exports.resolveAdjacentDad = exports.resolveDad = exports.assertGenerationalId = exports.initDimensionalAddress = exports.initPolicies = exports.initSelf = void 0;
|
|
4
|
+
const enums_1 = require("../../../modules/enums");
|
|
5
|
+
const errors_1 = require("../../../modules/errors");
|
|
6
|
+
const utils_1 = require("../../../modules/utils");
|
|
7
|
+
const collator_1 = require("../../collator");
|
|
8
|
+
const pipe_1 = require("../../pipe");
|
|
9
|
+
function initSelf(instance, context) {
|
|
10
|
+
const activityId = instance.metadata.aid;
|
|
11
|
+
if (!context[activityId]) {
|
|
12
|
+
context[activityId] = {};
|
|
13
|
+
}
|
|
14
|
+
const self = context[activityId];
|
|
15
|
+
if (!self.output)
|
|
16
|
+
self.output = {};
|
|
17
|
+
if (!self.input)
|
|
18
|
+
self.input = {};
|
|
19
|
+
if (!self.hook)
|
|
20
|
+
self.hook = {};
|
|
21
|
+
if (!self.output.metadata)
|
|
22
|
+
self.output.metadata = {};
|
|
23
|
+
self.output.metadata.au = (0, utils_1.formatISODate)(new Date());
|
|
24
|
+
context['$self'] = self;
|
|
25
|
+
context['$job'] = context; //NEVER call STRINGIFY! (now circular)
|
|
26
|
+
return context;
|
|
27
|
+
}
|
|
28
|
+
exports.initSelf = initSelf;
|
|
29
|
+
function initPolicies(instance, context) {
|
|
30
|
+
const expire = pipe_1.Pipe.resolve(instance.config.expire ?? enums_1.HMSH_EXPIRE_DURATION, context);
|
|
31
|
+
context.metadata.expire = expire;
|
|
32
|
+
if (instance.config.persistent != undefined) {
|
|
33
|
+
const persistent = pipe_1.Pipe.resolve(instance.config.persistent ?? false, context);
|
|
34
|
+
context.metadata.persistent = persistent;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.initPolicies = initPolicies;
|
|
38
|
+
function initDimensionalAddress(instance, dad) {
|
|
39
|
+
instance.metadata.dad = dad;
|
|
40
|
+
}
|
|
41
|
+
exports.initDimensionalAddress = initDimensionalAddress;
|
|
42
|
+
function assertGenerationalId(jobGID, msgGID, context) {
|
|
43
|
+
if (msgGID !== jobGID) {
|
|
44
|
+
throw new errors_1.GenerationalError(jobGID, msgGID, context?.metadata?.jid ?? '', context?.metadata?.aid ?? '', context?.metadata?.dad ?? '');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.assertGenerationalId = assertGenerationalId;
|
|
48
|
+
function resolveDad(instance) {
|
|
49
|
+
let dad = instance.metadata.dad;
|
|
50
|
+
if (instance.adjacentIndex > 0) {
|
|
51
|
+
dad = `${dad.substring(0, dad.lastIndexOf(','))},${instance.adjacentIndex}`;
|
|
52
|
+
}
|
|
53
|
+
return dad;
|
|
54
|
+
}
|
|
55
|
+
exports.resolveDad = resolveDad;
|
|
56
|
+
function resolveAdjacentDad(instance) {
|
|
57
|
+
return `${resolveDad(instance)}${collator_1.CollatorService.getDimensionalSeed(0)}`;
|
|
58
|
+
}
|
|
59
|
+
exports.resolveAdjacentDad = resolveAdjacentDad;
|
|
60
|
+
function bindActivityData(instance, type) {
|
|
61
|
+
instance.context[instance.metadata.aid][type].data = instance.data;
|
|
62
|
+
}
|
|
63
|
+
exports.bindActivityData = bindActivityData;
|
|
64
|
+
function bindActivityError(instance, data) {
|
|
65
|
+
const md = instance.context[instance.metadata.aid].output.metadata;
|
|
66
|
+
md.err = JSON.stringify(instance.data);
|
|
67
|
+
md.$error = { ...data, is_stream_error: true };
|
|
68
|
+
}
|
|
69
|
+
exports.bindActivityError = bindActivityError;
|
|
70
|
+
function bindJobError(instance, data) {
|
|
71
|
+
instance.context.metadata.err = JSON.stringify({
|
|
72
|
+
...data,
|
|
73
|
+
is_stream_error: true,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.bindJobError = bindJobError;
|