@hotmeshio/hotmesh 0.8.0 → 0.9.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/.claude/settings.local.json +2 -1
- package/README.md +158 -38
- package/build/package.json +62 -67
- package/build/services/activities/activity.d.ts +58 -7
- package/build/services/activities/activity.js +66 -37
- package/build/services/activities/await.d.ts +101 -0
- package/build/services/activities/await.js +101 -0
- package/build/services/activities/cycle.d.ts +82 -0
- package/build/services/activities/cycle.js +86 -8
- package/build/services/activities/hook.d.ts +139 -1
- package/build/services/activities/hook.js +140 -2
- package/build/services/activities/interrupt.d.ts +112 -0
- package/build/services/activities/interrupt.js +118 -5
- package/build/services/activities/signal.d.ts +108 -3
- package/build/services/activities/signal.js +113 -8
- package/build/services/activities/trigger.d.ts +56 -4
- package/build/services/activities/trigger.js +119 -35
- package/build/services/activities/worker.d.ts +107 -0
- package/build/services/activities/worker.js +107 -0
- package/build/services/collator/index.d.ts +3 -15
- package/build/services/collator/index.js +7 -34
- package/build/services/engine/index.d.ts +18 -2
- package/build/services/engine/index.js +14 -4
- package/build/services/exporter/index.d.ts +2 -0
- package/build/services/exporter/index.js +1 -0
- package/build/services/hotmesh/index.d.ts +471 -236
- package/build/services/hotmesh/index.js +473 -238
- package/build/services/memflow/client.js +2 -2
- package/build/services/memflow/handle.js +1 -1
- package/build/services/memflow/index.d.ts +1 -1
- package/build/services/memflow/index.js +1 -1
- package/build/services/memflow/workflow/all.d.ts +28 -3
- package/build/services/memflow/workflow/all.js +28 -3
- package/build/services/memflow/workflow/context.d.ts +44 -1
- package/build/services/memflow/workflow/context.js +44 -1
- package/build/services/memflow/workflow/didRun.d.ts +23 -3
- package/build/services/memflow/workflow/didRun.js +23 -3
- package/build/services/memflow/workflow/emit.d.ts +43 -4
- package/build/services/memflow/workflow/emit.js +43 -4
- package/build/services/memflow/workflow/enrich.d.ts +32 -4
- package/build/services/memflow/workflow/enrich.js +32 -4
- package/build/services/memflow/workflow/entityMethods.d.ts +54 -7
- package/build/services/memflow/workflow/entityMethods.js +54 -7
- package/build/services/memflow/workflow/execChild.d.ts +96 -8
- package/build/services/memflow/workflow/execChild.js +96 -8
- package/build/services/memflow/workflow/execHook.d.ts +54 -39
- package/build/services/memflow/workflow/execHook.js +52 -38
- package/build/services/memflow/workflow/execHookBatch.d.ts +82 -29
- package/build/services/memflow/workflow/execHookBatch.js +80 -28
- package/build/services/memflow/workflow/hook.d.ts +68 -3
- package/build/services/memflow/workflow/hook.js +69 -4
- package/build/services/memflow/workflow/index.d.ts +65 -10
- package/build/services/memflow/workflow/index.js +65 -10
- package/build/services/memflow/workflow/interrupt.d.ts +50 -4
- package/build/services/memflow/workflow/interrupt.js +50 -4
- package/build/services/memflow/workflow/interruption.d.ts +49 -16
- package/build/services/memflow/workflow/interruption.js +49 -16
- package/build/services/memflow/workflow/isSideEffectAllowed.d.ts +21 -4
- package/build/services/memflow/workflow/isSideEffectAllowed.js +21 -4
- package/build/services/memflow/workflow/proxyActivities.d.ts +70 -42
- package/build/services/memflow/workflow/proxyActivities.js +70 -42
- package/build/services/memflow/workflow/random.d.ts +33 -3
- package/build/services/memflow/workflow/random.js +33 -3
- package/build/services/memflow/workflow/searchMethods.d.ts +49 -2
- package/build/services/memflow/workflow/searchMethods.js +49 -2
- package/build/services/memflow/workflow/signal.d.ts +51 -22
- package/build/services/memflow/workflow/signal.js +52 -23
- package/build/services/memflow/workflow/sleepFor.d.ts +57 -18
- package/build/services/memflow/workflow/sleepFor.js +57 -18
- package/build/services/memflow/workflow/trace.d.ts +39 -6
- package/build/services/memflow/workflow/trace.js +39 -6
- package/build/services/memflow/workflow/waitFor.d.ts +55 -18
- package/build/services/memflow/workflow/waitFor.js +55 -18
- package/build/services/store/index.d.ts +1 -1
- package/build/services/store/providers/postgres/postgres.d.ts +1 -1
- package/build/services/store/providers/postgres/postgres.js +4 -3
- package/build/services/telemetry/index.js +6 -0
- package/build/types/activity.d.ts +1 -1
- package/build/types/hotmesh.d.ts +1 -1
- package/build/types/job.d.ts +1 -1
- package/build/types/memflow.d.ts +1 -1
- package/build/types/quorum.d.ts +2 -2
- package/build/vitest.config.d.ts +2 -0
- package/build/vitest.config.js +18 -0
- package/package.json +62 -67
- package/vitest.config.ts +17 -0
package/README.md
CHANGED
|
@@ -4,27 +4,41 @@
|
|
|
4
4
|
|
|
5
5
|
Run durable workflows on Postgres. No servers, no queues, just your database.
|
|
6
6
|
|
|
7
|
+
```bash
|
|
8
|
+
npm install @hotmeshio/hotmesh
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Use HotMesh for
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
- **Durable pipelines** — Orchestrate long-running, multi-step pipelines transactionally.
|
|
14
|
+
- **Temporal replacement** — MemFlow provides a Temporal-compatible API that runs directly on Postgres. No app server required.
|
|
15
|
+
- **Distributed state machines** — Build stateful applications where every component can [fail and recover](https://github.com/hotmeshio/sdk-typescript/blob/main/services/collator/README.md).
|
|
16
|
+
- **AI and training pipelines** — Multi-step AI workloads where each stage is expensive and must not be repeated on failure. A crashed pipeline resumes from the last committed step, not from the beginning.
|
|
9
17
|
|
|
10
|
-
|
|
11
|
-
Transform Postgres into a durable pipeline processor. Orchestrate long-running, multi-step pipelines transactionally and durably.
|
|
18
|
+
> **MemFlow** is HotMesh's Temporal-compatible workflow module — a static class (`MemFlow.Client`, `MemFlow.Worker`, `MemFlow.workflow`) that provides the same developer experience as Temporal's SDK but runs entirely on Postgres.
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
Get the power of Temporal without the infrastructure. HotMesh includes MemFlow, a Temporal-compatible API that runs directly on your Postgres database. No app server required.
|
|
20
|
+
## How it works in 30 seconds
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
1. **You write workflow functions.** Plain TypeScript — branching, loops, error handling. HotMesh also supports a YAML syntax for declarative, functional workflows.
|
|
23
|
+
2. **HotMesh compiles them into a transactional execution plan.** Each step becomes a committed database row. If the process crashes mid-workflow, it resumes from the last committed step.
|
|
24
|
+
3. **Your Postgres database is the engine.** It stores state, coordinates retries, and delivers messages. Every connected client participates in execution — there is no central server.
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
Choose your style: procedural workflows with MemFlow's Temporal API, or functional workflows with HotMesh's YAML syntax.
|
|
26
|
+
## Quickstart
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
Start Postgres locally (or use an existing instance), then:
|
|
23
29
|
|
|
24
30
|
```bash
|
|
25
31
|
npm install @hotmeshio/hotmesh
|
|
26
32
|
```
|
|
27
33
|
|
|
34
|
+
The repo includes a `docker-compose.yml` that starts Postgres (and NATS, if needed):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
docker compose up -d postgres
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Then follow the [Quick Start guide](./docs/quickstart.md) for a progressive walkthrough — from a single trigger to conditional, parallel, and compositional workflows.
|
|
41
|
+
|
|
28
42
|
## Two ways to write workflows
|
|
29
43
|
|
|
30
44
|
Both approaches reuse your activity functions:
|
|
@@ -52,13 +66,13 @@ import { MemFlow } from '@hotmeshio/hotmesh';
|
|
|
52
66
|
import * as activities from './activities';
|
|
53
67
|
|
|
54
68
|
export async function orderWorkflow(itemId: string, qty: number) {
|
|
55
|
-
const { checkInventory, reserveItem, notifyBackorder } =
|
|
69
|
+
const { checkInventory, reserveItem, notifyBackorder } =
|
|
56
70
|
MemFlow.workflow.proxyActivities<typeof activities>({
|
|
57
71
|
taskQueue: 'inventory-tasks'
|
|
58
72
|
});
|
|
59
|
-
|
|
73
|
+
|
|
60
74
|
const available = await checkInventory(itemId);
|
|
61
|
-
|
|
75
|
+
|
|
62
76
|
if (available >= qty) {
|
|
63
77
|
return await reserveItem(itemId, qty);
|
|
64
78
|
} else {
|
|
@@ -102,23 +116,23 @@ const result = await handle.result();
|
|
|
102
116
|
activities:
|
|
103
117
|
trigger:
|
|
104
118
|
type: trigger
|
|
105
|
-
|
|
119
|
+
|
|
106
120
|
checkInventory:
|
|
107
121
|
type: worker
|
|
108
122
|
topic: inventory.check
|
|
109
|
-
|
|
123
|
+
|
|
110
124
|
reserveItem:
|
|
111
125
|
type: worker
|
|
112
126
|
topic: inventory.reserve
|
|
113
|
-
|
|
127
|
+
|
|
114
128
|
notifyBackorder:
|
|
115
129
|
type: worker
|
|
116
130
|
topic: inventory.backorder.notify
|
|
117
|
-
|
|
131
|
+
|
|
118
132
|
transitions:
|
|
119
133
|
trigger:
|
|
120
134
|
- to: checkInventory
|
|
121
|
-
|
|
135
|
+
|
|
122
136
|
checkInventory:
|
|
123
137
|
- to: reserveItem
|
|
124
138
|
conditions:
|
|
@@ -128,7 +142,7 @@ transitions:
|
|
|
128
142
|
'@pipe':
|
|
129
143
|
- ['{checkInventory.output.data.availableQty}', '{trigger.output.data.requestedQty}']
|
|
130
144
|
- ['{@conditional.gte}']
|
|
131
|
-
|
|
145
|
+
|
|
132
146
|
- to: notifyBackorder
|
|
133
147
|
conditions:
|
|
134
148
|
match:
|
|
@@ -139,6 +153,7 @@ transitions:
|
|
|
139
153
|
- ['{@conditional.gte}']
|
|
140
154
|
```
|
|
141
155
|
|
|
156
|
+
Deploy and run as follows:
|
|
142
157
|
```typescript
|
|
143
158
|
// main.ts (reuses same activities.ts)
|
|
144
159
|
import * as activities from './activities';
|
|
@@ -185,42 +200,147 @@ const result = await hotMesh.pubsub('order.requested', {
|
|
|
185
200
|
|
|
186
201
|
Both compile to the same distributed execution model.
|
|
187
202
|
|
|
188
|
-
##
|
|
203
|
+
## Common patterns
|
|
189
204
|
|
|
190
|
-
|
|
191
|
-
- **No infrastructure** - Runs on your existing Postgres
|
|
192
|
-
- **Temporal compatible** - Drop-in replacement for many use cases
|
|
193
|
-
- **Distributed** - Every client participates in execution
|
|
194
|
-
- **Observable** - Full execution history in your database
|
|
205
|
+
All snippets below run inside a workflow function (like `orderWorkflow` above). MemFlow methods are available as static imports:
|
|
195
206
|
|
|
196
|
-
|
|
207
|
+
```typescript
|
|
208
|
+
import { MemFlow } from '@hotmeshio/hotmesh';
|
|
209
|
+
```
|
|
197
210
|
|
|
198
|
-
**Long-running workflows**
|
|
211
|
+
**Long-running workflows** — `sleepFor` is durable. The process can restart; the timer survives.
|
|
199
212
|
|
|
200
213
|
```typescript
|
|
201
|
-
|
|
214
|
+
// sendFollowUp is a proxied activity from proxyActivities()
|
|
215
|
+
await MemFlow.workflow.sleepFor('30 days');
|
|
202
216
|
await sendFollowUp();
|
|
203
217
|
```
|
|
204
218
|
|
|
205
|
-
**Parallel execution**
|
|
219
|
+
**Parallel execution** — fan out to multiple activities and wait for all results.
|
|
206
220
|
|
|
207
221
|
```typescript
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
222
|
+
// proxied activities run as durable, retryable steps
|
|
223
|
+
const [payment, inventory, shipment] = await Promise.all([
|
|
224
|
+
processPayment(orderId),
|
|
225
|
+
updateInventory(orderId),
|
|
226
|
+
notifyWarehouse(orderId)
|
|
212
227
|
]);
|
|
213
228
|
```
|
|
214
229
|
|
|
215
|
-
**Child workflows**
|
|
230
|
+
**Child workflows** — compose workflows from other workflows.
|
|
216
231
|
|
|
217
232
|
```typescript
|
|
218
|
-
const childHandle = await startChild(validateOrder, {
|
|
233
|
+
const childHandle = await MemFlow.workflow.startChild(validateOrder, {
|
|
234
|
+
args: [orderId],
|
|
235
|
+
taskQueue: 'validation',
|
|
236
|
+
workflowId: `validate-${orderId}`
|
|
237
|
+
});
|
|
219
238
|
const validation = await childHandle.result();
|
|
220
239
|
```
|
|
221
240
|
|
|
222
|
-
|
|
241
|
+
**Signals** — pause a workflow until an external event arrives.
|
|
223
242
|
|
|
224
|
-
|
|
243
|
+
```typescript
|
|
244
|
+
const approval = await MemFlow.workflow.waitFor<{ approved: boolean }>('manager-approval');
|
|
245
|
+
if (!approval.approved) return 'rejected';
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Retries and error handling
|
|
249
|
+
|
|
250
|
+
Activities retry automatically on failure. Configure the policy per activity or per worker:
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
// MemFlow: per-activity retry policy
|
|
254
|
+
const { reserveItem } = MemFlow.workflow.proxyActivities<typeof activities>({
|
|
255
|
+
taskQueue: 'inventory-tasks',
|
|
256
|
+
retryPolicy: {
|
|
257
|
+
maximumAttempts: 5,
|
|
258
|
+
backoffCoefficient: 2,
|
|
259
|
+
maximumInterval: '60s'
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
// HotMesh: worker-level retry policy
|
|
266
|
+
const hotMesh = await HotMesh.init({
|
|
267
|
+
appId: 'orders',
|
|
268
|
+
engine: { connection },
|
|
269
|
+
workers: [{
|
|
270
|
+
topic: 'inventory.reserve',
|
|
271
|
+
connection,
|
|
272
|
+
retryPolicy: {
|
|
273
|
+
maximumAttempts: 5,
|
|
274
|
+
backoffCoefficient: 2,
|
|
275
|
+
maximumInterval: '60s'
|
|
276
|
+
},
|
|
277
|
+
callback: async (data) => { /* ... */ }
|
|
278
|
+
}]
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Defaults: 3 attempts, coefficient 10, 120s cap. Delay formula: `min(coefficient ^ attempt, maximumInterval)`. Duration strings like `'5 seconds'`, `'2 minutes'`, and `'1 hour'` are supported.
|
|
283
|
+
|
|
284
|
+
If all retries are exhausted, the activity fails and the error propagates to the workflow function — handle it with a standard `try/catch`.
|
|
285
|
+
|
|
286
|
+
## It's just data
|
|
287
|
+
|
|
288
|
+
There is nothing between you and your data. Workflow state lives in your database as ordinary rows — `jobs` and `jobs_attributes`. Query it directly, back it up with pg_dump, replicate it, join it against your application tables.
|
|
289
|
+
|
|
290
|
+
```sql
|
|
291
|
+
SELECT
|
|
292
|
+
j.key AS job_key,
|
|
293
|
+
j.status AS semaphore,
|
|
294
|
+
j.entity AS workflow,
|
|
295
|
+
a.field AS attribute,
|
|
296
|
+
a.value AS value,
|
|
297
|
+
j.created_at,
|
|
298
|
+
j.updated_at
|
|
299
|
+
FROM
|
|
300
|
+
jobs j
|
|
301
|
+
JOIN jobs_attributes a ON a.job_id = j.id
|
|
302
|
+
WHERE
|
|
303
|
+
j.key = 'order-456'
|
|
304
|
+
ORDER BY
|
|
305
|
+
a.field;
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
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.
|
|
309
|
+
|
|
310
|
+
You can also use the Temporal-compatible API:
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
const handle = client.workflow.getHandle('orders', 'orderWorkflow', 'order-456');
|
|
314
|
+
|
|
315
|
+
const result = await handle.result(); // final output
|
|
316
|
+
const status = await handle.status(); // semaphore (0 = complete)
|
|
317
|
+
const state = await handle.state(true); // full state with metadata
|
|
318
|
+
const exported = await handle.export({ // selective export
|
|
319
|
+
allow: ['data', 'state', 'status', 'timeline']
|
|
320
|
+
});
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## Observability
|
|
324
|
+
|
|
325
|
+
There is no proprietary dashboard. Workflow state lives in Postgres, so use whatever tools you already have:
|
|
326
|
+
|
|
327
|
+
- **Direct SQL** — query `jobs` and `jobs_attributes` to inspect state, as shown above.
|
|
328
|
+
- **Handle API** — `handle.status()`, `handle.state(true)`, and `handle.export()` give programmatic access to any running or completed workflow.
|
|
329
|
+
- **Logging** — set `HMSH_LOGLEVEL` (`debug`, `info`, `warn`, `error`, `silent`) to control log verbosity.
|
|
330
|
+
- **OpenTelemetry** — set `HMSH_TELEMETRY=true` to emit spans and metrics. Plug in any OTel-compatible collector (Jaeger, Datadog, etc.).
|
|
331
|
+
|
|
332
|
+
## Architecture
|
|
333
|
+
|
|
334
|
+
For a deep dive into the transactional execution model — how every step is crash-safe, how the monotonic collation ledger guarantees exactly-once delivery, and how cycles and retries remain correct under arbitrary failure — see the [Collation Design Document](https://github.com/hotmeshio/sdk-typescript/blob/main/services/collator/README.md). The symbolic system (how to design workflows) and lifecycle details (how to deploy workflows) are covered in the [Architectural Overview](https://zenodo.org/records/12168558).
|
|
335
|
+
|
|
336
|
+
## Familiar with Temporal?
|
|
337
|
+
|
|
338
|
+
MemFlow is designed as a drop-in-compatible alternative for common Temporal patterns.
|
|
339
|
+
|
|
340
|
+
**What's the same:** `Client`, `Worker`, `proxyActivities`, `sleepFor`, `startChild`/`execChild`, signals (`waitFor`/`signal`), retry policies, and the overall workflow-as-code programming model.
|
|
341
|
+
|
|
342
|
+
**What's different:** No Temporal server or cluster to operate. Postgres is the only infrastructure dependency — it stores state, coordinates workers, and delivers messages. HotMesh also offers a YAML-based approach for declarative workflows that compile to the same execution model.
|
|
343
|
+
|
|
344
|
+
## License
|
|
225
345
|
|
|
226
|
-
|
|
346
|
+
HotMesh is source-available under the [HotMesh Source Available License](./LICENSE).
|
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hotmeshio/hotmesh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Permanent-Memory Workflows & AI Agents",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -19,72 +19,69 @@
|
|
|
19
19
|
"lint": "eslint . --ext .ts",
|
|
20
20
|
"lint:fix": "eslint . --fix --ext .ts",
|
|
21
21
|
"start": "ts-node src/index.ts",
|
|
22
|
-
"test": "
|
|
23
|
-
"test:
|
|
24
|
-
"test:
|
|
25
|
-
"test:
|
|
26
|
-
"test:connect
|
|
27
|
-
"test:connect:
|
|
28
|
-
"test:
|
|
29
|
-
"test:memflow
|
|
30
|
-
"test:memflow:
|
|
31
|
-
"test:memflow:
|
|
32
|
-
"test:memflow:
|
|
33
|
-
"test:memflow:
|
|
34
|
-
"test:memflow:
|
|
35
|
-
"test:memflow:
|
|
36
|
-
"test:memflow:
|
|
37
|
-
"test:memflow:
|
|
38
|
-
"test:memflow:
|
|
39
|
-
"test:memflow:
|
|
40
|
-
"test:memflow:
|
|
41
|
-
"test:memflow:
|
|
42
|
-
"test:memflow:
|
|
43
|
-
"test:memflow:
|
|
44
|
-
"test:memflow:
|
|
45
|
-
"test:memflow:
|
|
46
|
-
"test:memflow:
|
|
47
|
-
"test:memflow:
|
|
48
|
-
"test:
|
|
49
|
-
"test:
|
|
50
|
-
"test:
|
|
51
|
-
"test:
|
|
52
|
-
"test:
|
|
53
|
-
"test:
|
|
54
|
-
"test:
|
|
55
|
-
"test:
|
|
56
|
-
"test:
|
|
57
|
-
"test:
|
|
58
|
-
"test:
|
|
59
|
-
"test:
|
|
60
|
-
"test:
|
|
61
|
-
"test:
|
|
62
|
-
"test:
|
|
63
|
-
"test:
|
|
64
|
-
"test:
|
|
65
|
-
"test:
|
|
66
|
-
"test:
|
|
67
|
-
"test:
|
|
68
|
-
"test:
|
|
69
|
-
"test:
|
|
70
|
-
"test:stream:
|
|
71
|
-
"test:
|
|
72
|
-
"test:sub:
|
|
73
|
-
"test:
|
|
74
|
-
"test:
|
|
75
|
-
"test:
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"test:await": "vitest run tests/functional/awaiter/postgres.test.ts",
|
|
25
|
+
"test:compile": "vitest run tests/functional/compile/index.test.ts",
|
|
26
|
+
"test:connect": "vitest run tests/unit/services/connector",
|
|
27
|
+
"test:connect:postgres": "vitest run tests/unit/services/connector/providers/postgres.test.ts",
|
|
28
|
+
"test:connect:nats": "vitest run tests/unit/services/connector/providers/nats.test.ts",
|
|
29
|
+
"test:memflow": "vitest run tests/memflow",
|
|
30
|
+
"test:memflow:postgres": "HMSH_LOGLEVEL=info vitest run tests/memflow",
|
|
31
|
+
"test:memflow:basic": "HMSH_LOGLEVEL=info vitest run tests/memflow/basic/postgres.test.ts",
|
|
32
|
+
"test:memflow:collision": "vitest run tests/memflow/collision/postgres.test.ts",
|
|
33
|
+
"test:memflow:fatal": "vitest run tests/memflow/fatal",
|
|
34
|
+
"test:memflow:goodbye": "HMSH_LOGLEVEL=debug vitest run tests/memflow/goodbye/postgres.test.ts",
|
|
35
|
+
"test:memflow:interceptor": "HMSH_LOGLEVEL=info vitest run tests/memflow/interceptor/postgres.test.ts",
|
|
36
|
+
"test:memflow:entity": "HMSH_LOGLEVEL=debug vitest run tests/memflow/entity/postgres.test.ts",
|
|
37
|
+
"test:memflow:agent": "HMSH_LOGLEVEL=debug vitest run tests/memflow/agent/postgres.test.ts",
|
|
38
|
+
"test:memflow:hello": "HMSH_TELEMETRY=debug HMSH_LOGLEVEL=info vitest run tests/memflow/helloworld/postgres.test.ts",
|
|
39
|
+
"test:memflow:hook": "vitest run tests/memflow/hook/postgres.test.ts",
|
|
40
|
+
"test:memflow:interrupt": "vitest run tests/memflow/interrupt/postgres.test.ts",
|
|
41
|
+
"test:memflow:loopactivity": "vitest run tests/memflow/loopactivity/postgres.test.ts",
|
|
42
|
+
"test:memflow:nested": "vitest run tests/memflow/nested/postgres.test.ts",
|
|
43
|
+
"test:memflow:pipeline": "vitest run tests/memflow/pipeline/postgres.test.ts",
|
|
44
|
+
"test:memflow:retry": "vitest run tests/memflow/retry/postgres.test.ts",
|
|
45
|
+
"test:memflow:retrypolicy": "vitest run tests/memflow/retry-policy",
|
|
46
|
+
"test:memflow:sleep": "vitest run tests/memflow/sleep/postgres.test.ts",
|
|
47
|
+
"test:memflow:signal": "vitest run tests/memflow/signal/postgres.test.ts",
|
|
48
|
+
"test:memflow:unknown": "vitest run tests/memflow/unknown/postgres.test.ts",
|
|
49
|
+
"test:cycle": "vitest run tests/functional/cycle",
|
|
50
|
+
"test:functional": "vitest run tests/functional",
|
|
51
|
+
"test:emit": "vitest run tests/functional/emit",
|
|
52
|
+
"test:pending": "vitest run tests/functional/pending/index.test.ts",
|
|
53
|
+
"test:hmsh": "vitest run tests/functional/postgres.test.ts",
|
|
54
|
+
"test:hook": "vitest run tests/functional/hook/postgres.test.ts",
|
|
55
|
+
"test:interrupt": "vitest run tests/functional/interrupt/postgres.test.ts",
|
|
56
|
+
"test:parallel": "vitest run tests/functional/parallel/index.test.ts",
|
|
57
|
+
"test:pipe": "vitest run tests/unit/services/pipe/index.test.ts",
|
|
58
|
+
"test:quorum": "vitest run tests/functional/quorum/postgres.test.ts",
|
|
59
|
+
"test:reclaim": "vitest run tests/functional/reclaim/postgres.test.ts",
|
|
60
|
+
"test:redeploy": "vitest run tests/functional/redeploy/postgres.test.ts",
|
|
61
|
+
"test:reporter": "vitest run tests/unit/services/reporter/index.test.ts",
|
|
62
|
+
"test:reentrant": "vitest run tests/functional/reentrant/postgres.test.ts",
|
|
63
|
+
"test:retry": "vitest run tests/functional/retry/postgres.test.ts",
|
|
64
|
+
"test:retrypolicy": "vitest run tests/functional/retry-policy",
|
|
65
|
+
"test:sequence": "HMSH_LOGLEVEL=info vitest run tests/functional/sequence/postgres.test.ts",
|
|
66
|
+
"test:signal": "vitest run tests/functional/signal/postgres.test.ts",
|
|
67
|
+
"test:status": "vitest run tests/functional/status/index.test.ts",
|
|
68
|
+
"test:providers": "vitest run tests/functional/*/providers",
|
|
69
|
+
"test:store:postgres": "vitest run tests/functional/store/providers/postgres/postgres.test.ts",
|
|
70
|
+
"test:stream:postgres": "vitest run tests/functional/stream/providers/postgres/postgres.test.ts",
|
|
71
|
+
"test:stream:nats": "vitest run tests/functional/stream/providers/nats/nats.test.ts",
|
|
72
|
+
"test:sub:postgres": "vitest run tests/functional/sub/providers/postgres/postgres.test.ts",
|
|
73
|
+
"test:sub:nats": "vitest run tests/functional/sub/providers/nats/nats.test.ts",
|
|
74
|
+
"test:trigger": "vitest run tests/unit/services/activities/trigger.test.ts",
|
|
75
|
+
"test:meshcall": "vitest run tests/meshcall",
|
|
76
|
+
"test:unit": "vitest run tests/unit"
|
|
76
77
|
},
|
|
77
78
|
"keywords": [
|
|
78
79
|
"Headless Orchestration",
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"Operational Data",
|
|
80
|
+
"Durable Workflows",
|
|
81
|
+
"Data in Motion",
|
|
82
82
|
"Service Mesh",
|
|
83
83
|
"HotMesh",
|
|
84
|
-
"Postgres"
|
|
85
|
-
"OLAP",
|
|
86
|
-
"OLTP",
|
|
87
|
-
"HTAP"
|
|
84
|
+
"Postgres"
|
|
88
85
|
],
|
|
89
86
|
"author": "luke.birdeau@gmail.com",
|
|
90
87
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -99,8 +96,7 @@
|
|
|
99
96
|
"winston": "^3.8.2"
|
|
100
97
|
},
|
|
101
98
|
"devDependencies": {
|
|
102
|
-
"@types/
|
|
103
|
-
"@types/node": "^18.15.11",
|
|
99
|
+
"@types/node": "^20.19.33",
|
|
104
100
|
"@types/pg": "^8.10.0",
|
|
105
101
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
106
102
|
"@typescript-eslint/parser": "^5.62.0",
|
|
@@ -110,17 +106,16 @@
|
|
|
110
106
|
"eslint-plugin-import": "^2.29.1",
|
|
111
107
|
"eslint-plugin-prettier": "^5.1.3",
|
|
112
108
|
"javascript-obfuscator": "^0.6.2",
|
|
113
|
-
"jest": "^29.5.0",
|
|
114
109
|
"nats": "^2.28.0",
|
|
115
110
|
"openai": "^5.9.0",
|
|
116
111
|
"pg": "^8.10.0",
|
|
117
112
|
"rimraf": "^4.4.1",
|
|
118
113
|
"terser": "^5.37.0",
|
|
119
|
-
"ts-jest": "^29.0.5",
|
|
120
114
|
"ts-node": "^10.9.1",
|
|
121
115
|
"ts-node-dev": "^2.0.0",
|
|
122
116
|
"typedoc": "^0.26.4",
|
|
123
|
-
"typescript": "^5.0.4"
|
|
117
|
+
"typescript": "^5.0.4",
|
|
118
|
+
"vitest": "^2.1.9"
|
|
124
119
|
},
|
|
125
120
|
"peerDependencies": {
|
|
126
121
|
"nats": "^2.0.0",
|
|
@@ -7,13 +7,69 @@ import { JobState, JobStatus } from '../../types/job';
|
|
|
7
7
|
import { StringAnyType } from '../../types/serializer';
|
|
8
8
|
import { StreamCode, StreamData, StreamStatus } from '../../types/stream';
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Base class for all HotMesh activity types. Activities are the execution
|
|
11
|
+
* units within a YAML-defined workflow graph. Each activity represents a
|
|
12
|
+
* node in a Directed Acyclic Graph (DAG) that the engine orchestrates.
|
|
13
|
+
*
|
|
14
|
+
* ## Activity Categories
|
|
15
|
+
*
|
|
16
|
+
* Activities fall into three execution categories:
|
|
17
|
+
*
|
|
18
|
+
* - **Category A (Duplex)**: Two-phase activities with Leg 1 (dispatch) and
|
|
19
|
+
* Leg 2 (response). Used by `Worker` and `Await`. Leg 1
|
|
20
|
+
* publishes a message and waits; Leg 2 handles the response via
|
|
21
|
+
* `processEvent` and transitions to adjacent activities.
|
|
22
|
+
*
|
|
23
|
+
* - **Category B (Leg1-only with children)**: Single-phase activities that
|
|
24
|
+
* execute work and transition to children using the crash-safe
|
|
25
|
+
* `executeLeg1StepProtocol`. Used by `Hook` (passthrough mode),
|
|
26
|
+
* `Signal`, and `Interrupt` (target mode).
|
|
27
|
+
*
|
|
28
|
+
* - **Category C (Leg1-only, no children)**: Terminal activities that
|
|
29
|
+
* execute without spawning children. Used by `Interrupt` (self mode).
|
|
30
|
+
*
|
|
31
|
+
* ## Shared YAML Configuration
|
|
32
|
+
*
|
|
33
|
+
* All activity types support these base properties in the YAML descriptor:
|
|
34
|
+
*
|
|
35
|
+
* | Property | Type | Description |
|
|
36
|
+
* |----------------------|---------|-------------|
|
|
37
|
+
* | `type` | string | Activity type: `trigger`, `worker`, `await`, `hook`, `signal`, `interrupt`, `cycle` |
|
|
38
|
+
* | `title` | string | Human-readable label for the activity |
|
|
39
|
+
* | `input.schema` | object | JSON Schema for input validation |
|
|
40
|
+
* | `input.maps` | object | Maps data from other activities into this activity's input |
|
|
41
|
+
* | `output.schema` | object | JSON Schema for output validation |
|
|
42
|
+
* | `output.maps` | object | Maps/transforms the activity's own output data |
|
|
43
|
+
* | `job.maps` | object | Maps activity data to the shared job state |
|
|
44
|
+
* | `emit` | boolean | If `true`, emits a message to the graph's `publishes` topic |
|
|
45
|
+
* | `persist` | boolean | If `true`, emits the job-completed event while keeping the job active |
|
|
46
|
+
* | `expire` | number | Seconds until the job expires after completion (`-1` = forever) |
|
|
47
|
+
* | `statusThreshold` | number | Custom semaphore threshold for Dynamic Activation Control |
|
|
48
|
+
* | `cycle` | boolean | If `true`, leaves Leg 2 open so the activity can be re-entered |
|
|
49
|
+
*
|
|
50
|
+
* ## Data Mapping Syntax
|
|
51
|
+
*
|
|
52
|
+
* Mapping expressions use curly-brace references to bind data between
|
|
53
|
+
* activities and the shared job state:
|
|
54
|
+
*
|
|
55
|
+
* ```yaml
|
|
56
|
+
* input:
|
|
57
|
+
* maps:
|
|
58
|
+
* x: '{t1.output.data.fieldName}' # reference another activity's output
|
|
59
|
+
* y: '{$self.output.data.fieldName}' # reference own output
|
|
60
|
+
* z: '{$job.data.fieldName}' # reference shared job state
|
|
61
|
+
* s: '{$app.settings.configKey}' # reference app-level settings
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @see {@link https://hotmeshio.github.io/sdk-typescript/docs/quickstart | Quick Start Guide}
|
|
65
|
+
* @see [Model Driven Development](https://hotmeshio.github.io/sdk-typescript/docs/model_driven_development)
|
|
11
66
|
*/
|
|
12
67
|
declare class Activity {
|
|
13
68
|
config: ActivityType;
|
|
14
69
|
data: ActivityData;
|
|
15
70
|
hook: ActivityData;
|
|
16
71
|
metadata: ActivityMetadata;
|
|
72
|
+
/** @hidden */
|
|
17
73
|
store: StoreService<ProviderClient, ProviderTransaction>;
|
|
18
74
|
context: JobState;
|
|
19
75
|
engine: EngineService;
|
|
@@ -95,7 +151,7 @@ declare class Activity {
|
|
|
95
151
|
getTriggerConfig(): Promise<ActivityType>;
|
|
96
152
|
getJobStatus(): null | number;
|
|
97
153
|
setStatus(amount: number, transaction?: ProviderTransaction): Promise<void | any>;
|
|
98
|
-
authorizeEntry(
|
|
154
|
+
authorizeEntry(_state: StringAnyType): string[];
|
|
99
155
|
bindDimensionalAddress(state: StringAnyType): void;
|
|
100
156
|
setState(transaction?: ProviderTransaction): Promise<string>;
|
|
101
157
|
bindJobMetadata(): void;
|
|
@@ -127,11 +183,6 @@ declare class Activity {
|
|
|
127
183
|
* @private
|
|
128
184
|
*/
|
|
129
185
|
shouldPersistJob(): boolean;
|
|
130
|
-
/**
|
|
131
|
-
* Transition method for Category C (Leg1-only, no children, no semaphore change)
|
|
132
|
-
* and Category D (Trigger) activities. NOT used by the Leg2 step protocol.
|
|
133
|
-
*/
|
|
134
|
-
transition(adjacencyList: StreamData[], jobStatus: JobStatus): Promise<string[]>;
|
|
135
186
|
/**
|
|
136
187
|
* A job with a vale < -100_000_000 is considered interrupted,
|
|
137
188
|
* as the interruption event decrements the job status by 1billion.
|