service-bridge 1.8.3-dev.44 → 1.8.4-dev.46
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 +26 -11
- package/dist/index.js +122 -111
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -203,8 +203,8 @@ await notifications.serve({ host: "localhost" });
|
|
|
203
203
|
// --- Orchestrate as a workflow ---
|
|
204
204
|
|
|
205
205
|
await orders.workflow("order.fulfillment", [
|
|
206
|
-
{ id: "reserve", type: "rpc", ref: "
|
|
207
|
-
{ id: "charge", type: "rpc", ref: "payment.charge", deps: ["reserve"] },
|
|
206
|
+
{ id: "reserve", type: "rpc", service: "inventory", ref: "stock.reserve" },
|
|
207
|
+
{ id: "charge", type: "rpc", service: "payments", ref: "payment.charge", deps: ["reserve"] },
|
|
208
208
|
{ id: "wait_dlv", type: "event_wait", ref: "shipping.delivered", deps: ["charge"] },
|
|
209
209
|
{ id: "notify", type: "event", ref: "orders.fulfilled", deps: ["wait_dlv"] },
|
|
210
210
|
]);
|
|
@@ -409,11 +409,24 @@ Registers a scheduled or delayed job.
|
|
|
409
409
|
| `retryPolicyJson` | `string` | Retry policy JSON string. |
|
|
410
410
|
|
|
411
411
|
```ts
|
|
412
|
-
|
|
412
|
+
// RPC job: explicit service and function
|
|
413
|
+
await sb.job("billing", "collect", {
|
|
413
414
|
cron: "0 * * * *",
|
|
414
415
|
timezone: "UTC",
|
|
415
416
|
via: "rpc",
|
|
416
417
|
});
|
|
418
|
+
|
|
419
|
+
// Event job: single target
|
|
420
|
+
await sb.job("user.signup", {
|
|
421
|
+
cron: "0 0 * * *",
|
|
422
|
+
via: "event",
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// Workflow job: single target
|
|
426
|
+
await sb.job("monthly_report", {
|
|
427
|
+
cron: "0 0 1 * *",
|
|
428
|
+
via: "workflow",
|
|
429
|
+
});
|
|
417
430
|
```
|
|
418
431
|
|
|
419
432
|
---
|
|
@@ -432,7 +445,8 @@ Registers (or updates) a workflow definition as a DAG of typed steps. Returns th
|
|
|
432
445
|
|---|---|---|
|
|
433
446
|
| `id` | `string` | Unique step identifier in the DAG. |
|
|
434
447
|
| `type` | `"rpc" \| "event" \| "event_wait" \| "sleep" \| "workflow"` | Step execution type. |
|
|
435
|
-
| `
|
|
448
|
+
| `service` | `string` | **Required** for `rpc` and `workflow` steps. Target logical service name (e.g. `"inventory"`, `"payments"`). |
|
|
449
|
+
| `ref` | `string` | Required for `rpc`, `event`, `event_wait`, `workflow`. For `rpc` — the registered function name (e.g. `"stock.reserve"`, `"payment.charge"`). For `event`/`event_wait` — topic or pattern. For `workflow` — child workflow name. Always use dots, never slashes. |
|
|
436
450
|
| `deps` | `string[]` | Dependencies. Empty/omitted means root step. |
|
|
437
451
|
| `if` | `string` | Optional filter expression (step is skipped if false). |
|
|
438
452
|
| `timeoutMs` | `number` | Optional timeout for `rpc` and `event_wait` steps. |
|
|
@@ -454,8 +468,8 @@ interface WorkflowOpts {
|
|
|
454
468
|
|
|
455
469
|
```ts
|
|
456
470
|
await sb.workflow("order.fulfillment", [
|
|
457
|
-
{ id: "reserve", type: "rpc", ref: "
|
|
458
|
-
{ id: "charge", type: "rpc", ref: "payment.charge", deps: ["reserve"] },
|
|
471
|
+
{ id: "reserve", type: "rpc", service: "inventory", ref: "stock.reserve" },
|
|
472
|
+
{ id: "charge", type: "rpc", service: "payments", ref: "payment.charge", deps: ["reserve"] },
|
|
459
473
|
{ id: "wait_5m", type: "sleep", durationMs: 300_000, deps: ["charge"] },
|
|
460
474
|
{ id: "notify", type: "event", ref: "orders.fulfilled", deps: ["wait_5m"] },
|
|
461
475
|
]);
|
|
@@ -469,18 +483,19 @@ await sb.workflow("checkout.flow", steps, { stepTimeoutMs: 60_000 });
|
|
|
469
483
|
|
|
470
484
|
---
|
|
471
485
|
|
|
472
|
-
### `executeWorkflow(name, input?, opts?)`
|
|
486
|
+
### `executeWorkflow(service, name, input?, opts?)`
|
|
473
487
|
|
|
474
488
|
```ts
|
|
475
|
-
executeWorkflow(name: string, input?: unknown, opts?: ExecuteWorkflowOpts): Promise<{ traceId: string; groupTraceId: string }>
|
|
489
|
+
executeWorkflow(service: string, name: string, input?: unknown, opts?: ExecuteWorkflowOpts): Promise<{ traceId: string; groupTraceId: string }>
|
|
476
490
|
```
|
|
477
491
|
|
|
478
|
-
Starts a workflow execution on demand. The workflow must be registered first via `workflow()
|
|
492
|
+
Starts a workflow execution on demand. The workflow must be registered first via `workflow()` on the target service.
|
|
479
493
|
An alternative to scheduling via `job(target, { via: "workflow" })` — triggers the execution immediately.
|
|
480
494
|
|
|
481
495
|
| Parameter | Type | Default | Description |
|
|
482
496
|
|---|---|---|---|
|
|
483
|
-
| `
|
|
497
|
+
| `service` | `string` | required | Logical service that owns the workflow definition (same as the worker identity that called `workflow()`). |
|
|
498
|
+
| `name` | `string` | required | Workflow name. |
|
|
484
499
|
| `input` | `unknown` | `undefined` | Optional JSON-serializable input payload. |
|
|
485
500
|
|
|
486
501
|
Returns `{ traceId, groupTraceId }`. Use `traceId` with `watchTrace()` to observe execution in real time.
|
|
@@ -492,7 +507,7 @@ Returns `{ traceId, groupTraceId }`. Use `traceId` with `watchTrace()` to observ
|
|
|
492
507
|
| `traceId` | `string` | Override trace ID for this workflow execution. |
|
|
493
508
|
|
|
494
509
|
```ts
|
|
495
|
-
const { traceId, groupTraceId } = await sb.executeWorkflow("user.onboarding", { userId: "u_123" });
|
|
510
|
+
const { traceId, groupTraceId } = await sb.executeWorkflow("users", "user.onboarding", { userId: "u_123" });
|
|
496
511
|
```
|
|
497
512
|
|
|
498
513
|
---
|