@adonis-agora/durable 0.4.0 → 0.6.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/CHANGELOG.md +9 -0
- package/README.md +47 -0
- package/dist/configure.d.ts +5 -2
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +7 -2
- package/dist/configure.js.map +1 -1
- package/dist/providers/durable_provider.d.ts +8 -4
- package/dist/providers/durable_provider.d.ts.map +1 -1
- package/dist/providers/durable_provider.js +38 -6
- package/dist/providers/durable_provider.js.map +1 -1
- package/dist/src/checkpoints.d.ts +2 -0
- package/dist/src/checkpoints.d.ts.map +1 -1
- package/dist/src/checkpoints.js +2 -0
- package/dist/src/checkpoints.js.map +1 -1
- package/dist/src/codec-state-store.d.ts +3 -3
- package/dist/src/codec-state-store.d.ts.map +1 -1
- package/dist/src/codec-state-store.js +6 -6
- package/dist/src/codec-state-store.js.map +1 -1
- package/dist/src/dashboard/index.d.ts +1 -1
- package/dist/src/dashboard/index.js +1 -1
- package/dist/src/define_config.d.ts +11 -3
- package/dist/src/define_config.d.ts.map +1 -1
- package/dist/src/define_config.js.map +1 -1
- package/dist/src/engine.d.ts +14 -0
- package/dist/src/engine.d.ts.map +1 -1
- package/dist/src/engine.js +74 -6
- package/dist/src/engine.js.map +1 -1
- package/dist/src/errors.d.ts +18 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +16 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/hooks/workflows.d.ts +53 -0
- package/dist/src/hooks/workflows.d.ts.map +1 -0
- package/dist/src/hooks/workflows.js +55 -0
- package/dist/src/hooks/workflows.js.map +1 -0
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/interfaces.d.ts +91 -8
- package/dist/src/interfaces.d.ts.map +1 -1
- package/dist/src/stores/lucid-mappers.d.ts +10 -1
- package/dist/src/stores/lucid-mappers.d.ts.map +1 -1
- package/dist/src/stores/lucid-mappers.js +17 -0
- package/dist/src/stores/lucid-mappers.js.map +1 -1
- package/dist/src/stores/lucid-schema.d.ts.map +1 -1
- package/dist/src/stores/lucid-schema.js +37 -6
- package/dist/src/stores/lucid-schema.js.map +1 -1
- package/dist/src/stores/lucid.d.ts +3 -3
- package/dist/src/stores/lucid.d.ts.map +1 -1
- package/dist/src/stores/lucid.js +31 -20
- package/dist/src/stores/lucid.js.map +1 -1
- package/dist/src/testing/in-memory-state-store.d.ts +3 -3
- package/dist/src/testing/in-memory-state-store.d.ts.map +1 -1
- package/dist/src/testing/in-memory-state-store.js +17 -7
- package/dist/src/testing/in-memory-state-store.js.map +1 -1
- package/dist/src/testing/in-memory-transport.d.ts +6 -0
- package/dist/src/testing/in-memory-transport.d.ts.map +1 -1
- package/dist/src/testing/in-memory-transport.js +8 -0
- package/dist/src/testing/in-memory-transport.js.map +1 -1
- package/dist/src/testing-kit/state-store-conformance.d.ts.map +1 -1
- package/dist/src/testing-kit/state-store-conformance.js +46 -0
- package/dist/src/testing-kit/state-store-conformance.js.map +1 -1
- package/dist/src/transport-pool.d.ts +7 -0
- package/dist/src/transport-pool.d.ts.map +1 -1
- package/dist/src/transport-pool.js +11 -0
- package/dist/src/transport-pool.js.map +1 -1
- package/dist/src/transports/event-emitter.d.ts +75 -0
- package/dist/src/transports/event-emitter.d.ts.map +1 -0
- package/dist/src/transports/event-emitter.js +133 -0
- package/dist/src/transports/event-emitter.js.map +1 -0
- package/dist/src/transports/factory.d.ts +23 -2
- package/dist/src/transports/factory.d.ts.map +1 -1
- package/dist/src/transports/factory.js +20 -1
- package/dist/src/transports/factory.js.map +1 -1
- package/dist/src/transports/queue.d.ts +14 -0
- package/dist/src/transports/queue.d.ts.map +1 -1
- package/dist/src/transports/queue.js +32 -4
- package/dist/src/transports/queue.js.map +1 -1
- package/dist/src/workflow-ctx.d.ts +3 -1
- package/dist/src/workflow-ctx.d.ts.map +1 -1
- package/dist/src/workflow-ctx.js +98 -1
- package/dist/src/workflow-ctx.js.map +1 -1
- package/dist/src/workflow-discovery.d.ts +15 -0
- package/dist/src/workflow-discovery.d.ts.map +1 -1
- package/dist/src/workflow-discovery.js +25 -0
- package/dist/src/workflow-discovery.js.map +1 -1
- package/dist/stubs/config/durable.stub +6 -1
- package/dist/stubs/database/migrations/create_durable_tables.stub +4 -0
- package/package.json +10 -1
|
@@ -69,6 +69,17 @@ export class TransportPool {
|
|
|
69
69
|
}
|
|
70
70
|
return [...groups];
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Propagate the engine's `namespace` to every transport that partitions by it — so the same
|
|
74
|
+
* namespace that scopes the store also scopes each transport's queues/keys. A transport that
|
|
75
|
+
* doesn't partition (no `useNamespace`) is skipped. Idempotent; a transport given an explicit
|
|
76
|
+
* namespace at construction ignores this (see {@link Transport.useNamespace}).
|
|
77
|
+
*/
|
|
78
|
+
useNamespace(namespace) {
|
|
79
|
+
for (const { transport } of this.transports) {
|
|
80
|
+
transport.useNamespace?.(namespace);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
72
83
|
/** Pinned `preferId` first, then the rest (failover order). */
|
|
73
84
|
ordered(preferId) {
|
|
74
85
|
if (!preferId)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-pool.js","sourceRoot":"","sources":["../../src/transport-pool.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACK;IAA7B,YAA6B,UAA4B;QAA5B,eAAU,GAAV,UAAU,CAAkB;IAAG,CAAC;IAE7D,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;qGAEiG;IACjG,IAAI,CACF,QAA+C,EAC/C,WAA+C,EAC/C,WAAyD;QAEzD,KAAK,MAAM,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAC5C,SAAS,CAAC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,qBAAqB,CAAC,CAAC;QACpF,OAAO,CAAC,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC;IACxE,CAAC;CACF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { type ControlMessage, type ControlPlane, type Heartbeat, type RemoteTask, type StepResult, type Transport } from '../interfaces.js';
|
|
3
|
+
import { type StepHandler } from '../protocol.js';
|
|
4
|
+
/** Event names the transport multiplexes over a single in-process emitter. */
|
|
5
|
+
export declare const TASK_EVENT = "durable.task";
|
|
6
|
+
export declare const RESULT_EVENT = "durable.result";
|
|
7
|
+
export declare const HEARTBEAT_EVENT = "durable.heartbeat";
|
|
8
|
+
export declare const CONTROL_EVENT = "durable.control";
|
|
9
|
+
export interface EventEmitterTransportOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The in-process emitter to multiplex over. Defaults to a fresh Node `EventEmitter` (listener cap
|
|
12
|
+
* lifted, since the engine wires several long-lived listeners). Pass `@adonisjs/core`'s `emitter`
|
|
13
|
+
* service if you'd rather ride the app's bus — it is API-compatible for `on`/`emit`.
|
|
14
|
+
*/
|
|
15
|
+
emitter?: EventEmitter;
|
|
16
|
+
/**
|
|
17
|
+
* The worker group this instance serves. Unused for routing (handlers are matched by step name in
|
|
18
|
+
* this same process) — accepted for parity with the broker transports, and stamped nowhere.
|
|
19
|
+
*/
|
|
20
|
+
group?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Logical deployment namespace, folded into the internal event-channel names so two namespaces over
|
|
23
|
+
* ONE shared in-process emitter don't cross-process each other's tasks/results. `"default"` (and
|
|
24
|
+
* absent) keeps the channel names BYTE-IDENTICAL to the un-namespaced scheme; any other value
|
|
25
|
+
* appends a `:<namespace>` segment. Explicit here wins over a later {@link EventEmitterTransport.useNamespace}.
|
|
26
|
+
*/
|
|
27
|
+
namespace?: string;
|
|
28
|
+
/** Stable id for this process (stamped on control `from` when a publisher leaves it unset). Default random. */
|
|
29
|
+
instanceId?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A production **in-process** {@link Transport} (and {@link ControlPlane}) backed by a single Node
|
|
33
|
+
* `EventEmitter`. Zero external infrastructure (no DB, no Redis, no broker): step handlers run in the
|
|
34
|
+
* same process, fully decoupled from the workflow that dispatched them, so a single-process app runs
|
|
35
|
+
* real durable workflows with nothing else to deploy.
|
|
36
|
+
*
|
|
37
|
+
* Distinct from the test-only {@link import('../testing/in-memory-transport.js').InMemoryTransport}:
|
|
38
|
+
* that one drives `dispatch` straight into the handler (synchronous-ish, for deterministic tests);
|
|
39
|
+
* this one decouples both directions through the emitter's event loop, mirroring how a real broker
|
|
40
|
+
* fans dispatch → worker → result back. Both funnel every step through {@link runStepHandler}, so the
|
|
41
|
+
* scoped context restore (the `@agora/context:scope` slot) works identically here.
|
|
42
|
+
*
|
|
43
|
+
* Swap to {@link import('./db.js').DbTransport} / {@link import('./queue.js').QueueTransport} for
|
|
44
|
+
* true cross-process or cross-language steps. The {@link ControlPlane} here broadcasts locally (every
|
|
45
|
+
* subscriber in this process), correct for single-instance; it does NOT fan out across pods.
|
|
46
|
+
*
|
|
47
|
+
* Usually you don't construct this directly: `config/durable.ts` selects it via
|
|
48
|
+
* `transports.eventEmitter()` (alias `transports.memory()` from the factory points at the test
|
|
49
|
+
* transport) and the provider builds it for you.
|
|
50
|
+
*/
|
|
51
|
+
export declare class EventEmitterTransport implements Transport, ControlPlane {
|
|
52
|
+
#private;
|
|
53
|
+
constructor(options?: EventEmitterTransportOptions);
|
|
54
|
+
/** Stable id stamped on control `from` when a publisher leaves it unset. */
|
|
55
|
+
get instanceId(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Adopt `namespace` (the engine's, typically), segmenting the internal channel names — but ONLY if a
|
|
58
|
+
* namespace wasn't passed explicitly to the constructor (an explicit one always wins). Idempotent.
|
|
59
|
+
* Safe before subscription (the task listener binds lazily on the first `handle()`, after this runs).
|
|
60
|
+
*/
|
|
61
|
+
useNamespace(namespace: string): void;
|
|
62
|
+
dispatch(task: RemoteTask): Promise<void>;
|
|
63
|
+
/** Register a step handler by name (the worker side, in this same process). Subscribes the task
|
|
64
|
+
* listener on the first call — bound to the (now-resolved) namespaced channel — so the worker side
|
|
65
|
+
* listens for every dispatched task and runs it if it owns the step name. */
|
|
66
|
+
handle(name: string, fn: StepHandler): void;
|
|
67
|
+
/** Worker side: a liveness heartbeat. In-process handlers run synchronously, so emit it straight
|
|
68
|
+
* through for symmetry — an engine that wired `onHeartbeat` still observes it. */
|
|
69
|
+
heartbeat(beat: Heartbeat): Promise<void>;
|
|
70
|
+
onResult(handler: (result: StepResult) => Promise<void>): void;
|
|
71
|
+
onHeartbeat(handler: (beat: Heartbeat) => Promise<void>): void;
|
|
72
|
+
publishControl(msg: ControlMessage): Promise<void>;
|
|
73
|
+
onControl(handler: (msg: ControlMessage) => void): void;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=event-emitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../../../src/transports/event-emitter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,gBAAgB,CAAC;AAElE,8EAA8E;AAC9E,eAAO,MAAM,UAAU,iBAAiB,CAAC;AACzC,eAAO,MAAM,YAAY,mBAAmB,CAAC;AAC7C,eAAO,MAAM,eAAe,sBAAsB,CAAC;AACnD,eAAO,MAAM,aAAa,oBAAoB,CAAC;AAE/C,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+GAA+G;IAC/G,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,qBAAsB,YAAW,SAAS,EAAE,YAAY;;gBAcvD,OAAO,GAAE,4BAAiC;IAWtD,4EAA4E;IAC5E,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAe/B,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ/C;;kFAE8E;IAC9E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI;IAU3C;uFACmF;IAC7E,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB/C,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAM9D,WAAW,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAUxD,cAAc,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxD,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;CAGxD"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { runStepHandler } from '../protocol.js';
|
|
4
|
+
/** Event names the transport multiplexes over a single in-process emitter. */
|
|
5
|
+
export const TASK_EVENT = 'durable.task';
|
|
6
|
+
export const RESULT_EVENT = 'durable.result';
|
|
7
|
+
export const HEARTBEAT_EVENT = 'durable.heartbeat';
|
|
8
|
+
export const CONTROL_EVENT = 'durable.control';
|
|
9
|
+
/**
|
|
10
|
+
* A production **in-process** {@link Transport} (and {@link ControlPlane}) backed by a single Node
|
|
11
|
+
* `EventEmitter`. Zero external infrastructure (no DB, no Redis, no broker): step handlers run in the
|
|
12
|
+
* same process, fully decoupled from the workflow that dispatched them, so a single-process app runs
|
|
13
|
+
* real durable workflows with nothing else to deploy.
|
|
14
|
+
*
|
|
15
|
+
* Distinct from the test-only {@link import('../testing/in-memory-transport.js').InMemoryTransport}:
|
|
16
|
+
* that one drives `dispatch` straight into the handler (synchronous-ish, for deterministic tests);
|
|
17
|
+
* this one decouples both directions through the emitter's event loop, mirroring how a real broker
|
|
18
|
+
* fans dispatch → worker → result back. Both funnel every step through {@link runStepHandler}, so the
|
|
19
|
+
* scoped context restore (the `@agora/context:scope` slot) works identically here.
|
|
20
|
+
*
|
|
21
|
+
* Swap to {@link import('./db.js').DbTransport} / {@link import('./queue.js').QueueTransport} for
|
|
22
|
+
* true cross-process or cross-language steps. The {@link ControlPlane} here broadcasts locally (every
|
|
23
|
+
* subscriber in this process), correct for single-instance; it does NOT fan out across pods.
|
|
24
|
+
*
|
|
25
|
+
* Usually you don't construct this directly: `config/durable.ts` selects it via
|
|
26
|
+
* `transports.eventEmitter()` (alias `transports.memory()` from the factory points at the test
|
|
27
|
+
* transport) and the provider builds it for you.
|
|
28
|
+
*/
|
|
29
|
+
export class EventEmitterTransport {
|
|
30
|
+
#emitter;
|
|
31
|
+
#instanceId;
|
|
32
|
+
#handlers = new Map();
|
|
33
|
+
// Logical deployment namespace folded into every channel name via `#suffix()`. Mutable so an engine
|
|
34
|
+
// can push its namespace via `useNamespace()` — but only when one wasn't passed explicitly to the
|
|
35
|
+
// constructor (`#explicitNamespace`), which always wins.
|
|
36
|
+
#namespace;
|
|
37
|
+
#explicitNamespace;
|
|
38
|
+
// Whether the worker-side task listener is subscribed yet. Subscription is LAZY (on first `handle()`)
|
|
39
|
+
// so the namespace the engine pushes via `useNamespace()` (before any handler registration) is the
|
|
40
|
+
// one the listener binds to — an engine-only instance with no handlers never subscribes.
|
|
41
|
+
#subscribed = false;
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
// A long-lived single emitter carries several engine listeners; lift Node's default cap so the
|
|
44
|
+
// engine wiring (result + heartbeat + control + task) never trips a MaxListenersExceededWarning.
|
|
45
|
+
const emitter = options.emitter ?? new EventEmitter();
|
|
46
|
+
if (emitter instanceof EventEmitter)
|
|
47
|
+
emitter.setMaxListeners(0);
|
|
48
|
+
this.#emitter = emitter;
|
|
49
|
+
this.#instanceId = options.instanceId ?? randomUUID();
|
|
50
|
+
this.#namespace = options.namespace;
|
|
51
|
+
this.#explicitNamespace = options.namespace !== undefined;
|
|
52
|
+
}
|
|
53
|
+
/** Stable id stamped on control `from` when a publisher leaves it unset. */
|
|
54
|
+
get instanceId() {
|
|
55
|
+
return this.#instanceId;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Adopt `namespace` (the engine's, typically), segmenting the internal channel names — but ONLY if a
|
|
59
|
+
* namespace wasn't passed explicitly to the constructor (an explicit one always wins). Idempotent.
|
|
60
|
+
* Safe before subscription (the task listener binds lazily on the first `handle()`, after this runs).
|
|
61
|
+
*/
|
|
62
|
+
useNamespace(namespace) {
|
|
63
|
+
if (this.#explicitNamespace)
|
|
64
|
+
return;
|
|
65
|
+
this.#namespace = namespace;
|
|
66
|
+
}
|
|
67
|
+
/** Non-`"default"` namespaces append a `:<namespace>` channel segment; default/absent stays bare so
|
|
68
|
+
* the un-namespaced channel names are byte-identical. */
|
|
69
|
+
#suffix() {
|
|
70
|
+
return this.#namespace && this.#namespace !== 'default' ? `:${this.#namespace}` : '';
|
|
71
|
+
}
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// engine → worker
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
async dispatch(task) {
|
|
76
|
+
this.#emitter.emit(`${TASK_EVENT}${this.#suffix()}`, task);
|
|
77
|
+
}
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// worker side — register a step handler, run it, emit the result back
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
/** Register a step handler by name (the worker side, in this same process). Subscribes the task
|
|
82
|
+
* listener on the first call — bound to the (now-resolved) namespaced channel — so the worker side
|
|
83
|
+
* listens for every dispatched task and runs it if it owns the step name. */
|
|
84
|
+
handle(name, fn) {
|
|
85
|
+
this.#handlers.set(name, fn);
|
|
86
|
+
if (!this.#subscribed) {
|
|
87
|
+
this.#subscribed = true;
|
|
88
|
+
this.#emitter.on(`${TASK_EVENT}${this.#suffix()}`, (task) => {
|
|
89
|
+
void this.#process(task);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Worker side: a liveness heartbeat. In-process handlers run synchronously, so emit it straight
|
|
94
|
+
* through for symmetry — an engine that wired `onHeartbeat` still observes it. */
|
|
95
|
+
async heartbeat(beat) {
|
|
96
|
+
this.#emitter.emit(`${HEARTBEAT_EVENT}${this.#suffix()}`, beat);
|
|
97
|
+
}
|
|
98
|
+
async #process(task) {
|
|
99
|
+
const handler = this.#handlers.get(task.name);
|
|
100
|
+
// Another subscriber may own this step name — stay silent, don't synthesize a "no handler" failure.
|
|
101
|
+
if (!handler)
|
|
102
|
+
return;
|
|
103
|
+
const result = await runStepHandler(task, handler);
|
|
104
|
+
// Emit the result on a LATER tick: a durable `ctx.call` suspends the run right after dispatch, so
|
|
105
|
+
// the result must land AFTER that unwinds (else the resume re-enters mid-suspend). Real brokers
|
|
106
|
+
// deliver asynchronously; this mirrors them.
|
|
107
|
+
setImmediate(() => this.#emitter.emit(`${RESULT_EVENT}${this.#suffix()}`, result));
|
|
108
|
+
}
|
|
109
|
+
// ---------------------------------------------------------------------------
|
|
110
|
+
// worker → engine — the engine consumes results + heartbeats
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
onResult(handler) {
|
|
113
|
+
this.#emitter.on(`${RESULT_EVENT}${this.#suffix()}`, (result) => {
|
|
114
|
+
void handler(result);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
onHeartbeat(handler) {
|
|
118
|
+
this.#emitter.on(`${HEARTBEAT_EVENT}${this.#suffix()}`, (beat) => {
|
|
119
|
+
void handler(beat);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
// control plane (broadcast within this process)
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
async publishControl(msg) {
|
|
126
|
+
const stamped = msg.from ? msg : { ...msg, from: this.#instanceId };
|
|
127
|
+
this.#emitter.emit(`${CONTROL_EVENT}${this.#suffix()}`, stamped);
|
|
128
|
+
}
|
|
129
|
+
onControl(handler) {
|
|
130
|
+
this.#emitter.on(`${CONTROL_EVENT}${this.#suffix()}`, (msg) => handler(msg));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=event-emitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-emitter.js","sourceRoot":"","sources":["../../../src/transports/event-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAS3C,OAAO,EAAoB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAElE,8EAA8E;AAC9E,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC;AACzC,MAAM,CAAC,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAC7C,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AACnD,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AA6B/C;;;;;;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C,CAAC;IACrF,CAAC;IAED,8EAA8E;IAC9E,6DAA6D;IAC7D,8EAA8E;IAE9E,QAAQ,CAAC,OAA8C;QACrD,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,MAAkB,EAAE,EAAE;YAC1E,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,WAAW,CAAC,OAA2C;QACrD,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,IAAe,EAAE,EAAE;YAC1E,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,8EAA8E;IAC9E,gDAAgD;IAChD,8EAA8E;IAE9E,KAAK,CAAC,cAAc,CAAC,GAAmB;QACtC,MAAM,OAAO,GAAmB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;QACpF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;IACnE,CAAC;IAED,SAAS,CAAC,OAAsC;QAC9C,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,GAAmB,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/F,CAAC;CACF"}
|
|
@@ -24,9 +24,19 @@ export interface TransportContext {
|
|
|
24
24
|
* actually selected — keeping those packages optional.
|
|
25
25
|
*/
|
|
26
26
|
export type TransportFactory = (ctx: TransportContext) => Promise<Transport & Partial<ControlPlane>>;
|
|
27
|
-
/** Options for the in-memory transport (no peer dependency). */
|
|
27
|
+
/** Options for the in-memory (test-only) transport (no peer dependency). */
|
|
28
28
|
export interface MemoryTransportConfig {
|
|
29
29
|
}
|
|
30
|
+
/** Options for the production in-process EventEmitter transport (no peer dependency). */
|
|
31
|
+
export interface EventEmitterTransportConfig {
|
|
32
|
+
/**
|
|
33
|
+
* The worker group this instance serves. Accepted for parity with the broker transports; handlers
|
|
34
|
+
* are matched by step name in-process, so it does not affect routing.
|
|
35
|
+
*/
|
|
36
|
+
group?: string;
|
|
37
|
+
/** Stable id for this process (stamped on control `from` when a publisher leaves it unset). Default random. */
|
|
38
|
+
instanceId?: string;
|
|
39
|
+
}
|
|
30
40
|
/** Options for the `@adonisjs/queue` transport. */
|
|
31
41
|
export interface QueueTransportConfig {
|
|
32
42
|
/**
|
|
@@ -69,8 +79,19 @@ export interface DbTransportConfig {
|
|
|
69
79
|
instanceId?: string;
|
|
70
80
|
}
|
|
71
81
|
export declare const transports: {
|
|
72
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* The test-only in-process transport + control plane (the engine's default when no `transport` is
|
|
84
|
+
* named). Drives `dispatch` straight into the handler for deterministic tests — for a real
|
|
85
|
+
* single-process production app, prefer {@link transports.eventEmitter}.
|
|
86
|
+
*/
|
|
73
87
|
memory(_config?: MemoryTransportConfig): TransportFactory;
|
|
88
|
+
/**
|
|
89
|
+
* Production **in-process** transport + control plane backed by a single Node `EventEmitter`. Zero
|
|
90
|
+
* external infrastructure (no DB, no Redis, no broker) — a single-process app runs real durable
|
|
91
|
+
* workflows with nothing else to deploy. Decouples dispatch → worker → result over the event loop
|
|
92
|
+
* (mirroring a real broker), unlike the test-only {@link transports.memory}.
|
|
93
|
+
*/
|
|
94
|
+
eventEmitter(config?: EventEmitterTransportConfig): TransportFactory;
|
|
74
95
|
/** Run remote steps cross-process over `@adonisjs/queue`, using a connection from `config/queue.ts`. */
|
|
75
96
|
queue(config?: QueueTransportConfig): TransportFactory;
|
|
76
97
|
/** Run remote steps cross-process over the app's database, using `@adonisjs/lucid` — no broker. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/transports/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGhE;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wFAAwF;IACxF,GAAG,EAAE;QACH,SAAS,EAAE;YAAE,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;SAAE,CAAC;QACxD,MAAM,EAAE;YAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;SAAE,CAAC;KACtD,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,GAAG,EAAE,gBAAgB,KAClB,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;AAEhD,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/transports/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGhE;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,wFAAwF;IACxF,GAAG,EAAE;QACH,SAAS,EAAE;YAAE,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;SAAE,CAAC;QACxD,MAAM,EAAE;YAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,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OAKG;0BACkB,2BAA2B,GAAQ,gBAAgB;IAUxE,wGAAwG;mBAC1F,oBAAoB,GAAQ,gBAAgB;IAc1D,mGAAmG;gBACxF,iBAAiB,GAAQ,gBAAgB;CAgBrD,CAAC"}
|
|
@@ -18,10 +18,29 @@ async function resolveQueueAdapter(ctx, connection) {
|
|
|
18
18
|
return typeof entry === 'function' ? entry : entry.resolver(ctx.app);
|
|
19
19
|
}
|
|
20
20
|
export const transports = {
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* The test-only in-process transport + control plane (the engine's default when no `transport` is
|
|
23
|
+
* named). Drives `dispatch` straight into the handler for deterministic tests — for a real
|
|
24
|
+
* single-process production app, prefer {@link transports.eventEmitter}.
|
|
25
|
+
*/
|
|
22
26
|
memory(_config = {}) {
|
|
23
27
|
return async () => new InMemoryTransport();
|
|
24
28
|
},
|
|
29
|
+
/**
|
|
30
|
+
* Production **in-process** transport + control plane backed by a single Node `EventEmitter`. Zero
|
|
31
|
+
* external infrastructure (no DB, no Redis, no broker) — a single-process app runs real durable
|
|
32
|
+
* workflows with nothing else to deploy. Decouples dispatch → worker → result over the event loop
|
|
33
|
+
* (mirroring a real broker), unlike the test-only {@link transports.memory}.
|
|
34
|
+
*/
|
|
35
|
+
eventEmitter(config = {}) {
|
|
36
|
+
return async () => {
|
|
37
|
+
const { EventEmitterTransport } = await import('./event-emitter.js');
|
|
38
|
+
return new EventEmitterTransport({
|
|
39
|
+
...(config.group !== undefined ? { group: config.group } : {}),
|
|
40
|
+
...(config.instanceId !== undefined ? { instanceId: config.instanceId } : {}),
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
},
|
|
25
44
|
/** Run remote steps cross-process over `@adonisjs/queue`, using a connection from `config/queue.ts`. */
|
|
26
45
|
queue(config = {}) {
|
|
27
46
|
return async (ctx) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/transports/factory.ts"],"names":[],"m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UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC9E,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -37,6 +37,14 @@ export interface QueueTransportOptions {
|
|
|
37
37
|
group?: string;
|
|
38
38
|
/** Queue-name prefix so several apps can share one backend without colliding. Default `durable`. */
|
|
39
39
|
prefix?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Logical deployment namespace, folded into every queue name so the same backend can host several
|
|
42
|
+
* worker-pool partitions without their tasks/results crossing. `"default"` (and absent) keeps queue
|
|
43
|
+
* names BYTE-IDENTICAL to the un-namespaced scheme (production is unchanged); any other value
|
|
44
|
+
* inserts a `-<namespace>` segment after the prefix. Passing it here is EXPLICIT and wins over a
|
|
45
|
+
* later {@link QueueTransport.useNamespace} (the engine's propagation).
|
|
46
|
+
*/
|
|
47
|
+
namespace?: string;
|
|
40
48
|
/** Poll interval (ms) for the result/task/heartbeat/control loops. Default 200ms. */
|
|
41
49
|
pollIntervalMs?: number;
|
|
42
50
|
/** Stable id for this process (stamped on heartbeats / control `from`). Default a random id. */
|
|
@@ -66,6 +74,12 @@ export declare class QueueTransport implements Transport, ControlPlane {
|
|
|
66
74
|
constructor(options: QueueTransportOptions);
|
|
67
75
|
/** Stable id stamped on heartbeats and control `from`. */
|
|
68
76
|
get instanceId(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Adopt `namespace` (the engine's, typically), folding it into every queue name — but ONLY if a
|
|
79
|
+
* namespace wasn't passed explicitly to the constructor (an explicit one always wins). Idempotent.
|
|
80
|
+
* Satisfies the optional `Transport.useNamespace` hook the engine calls when wiring a transport.
|
|
81
|
+
*/
|
|
82
|
+
useNamespace(namespace: string): void;
|
|
69
83
|
dispatch(task: RemoteTask): Promise<void>;
|
|
70
84
|
/**
|
|
71
85
|
* Register a step handler (worker side). Starts this group's task poll loop on the first call —
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/transports/queue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAwB,cAAc,EAAW,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,gBAAgB,CAAC;AAElE;;;;;;GAMG;AAEH,iGAAiG;AACjG,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAErC;AAED,wEAAwE;AACxE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,CAO7C;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC;AACrC,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC;AACvC,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;AACzC,MAAM,MAAM,cAAc,GAAG,cAAc,CAAC;AAc5C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAItE;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAC;IACxB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oGAAoG;IACpG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gGAAgG;IAChG,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,cAAe,YAAW,SAAS,EAAE,YAAY;;
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/transports/queue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAwB,cAAc,EAA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,IAAI;IAkD/B,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAW/C;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI;IAe3C,4EAA4E;IACtE,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ/C,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAM9D,WAAW,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAUxD,cAAc,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAKxD,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI;IAsCvD,4EAA4E;IACtE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
|
|
@@ -65,6 +65,11 @@ export class QueueTransport {
|
|
|
65
65
|
#adapter;
|
|
66
66
|
#group;
|
|
67
67
|
#prefix;
|
|
68
|
+
// Logical deployment namespace folded into every queue name via `#effectivePrefix()`. Mutable so an
|
|
69
|
+
// engine can push its namespace onto a transport via `useNamespace()` — but only when one wasn't
|
|
70
|
+
// passed explicitly to the constructor (`#explicitNamespace`), which always wins.
|
|
71
|
+
#namespace;
|
|
72
|
+
#explicitNamespace;
|
|
68
73
|
#pollIntervalMs;
|
|
69
74
|
#instanceId;
|
|
70
75
|
#handlers = new Map();
|
|
@@ -74,6 +79,8 @@ export class QueueTransport {
|
|
|
74
79
|
this.#adapter = options.adapter();
|
|
75
80
|
this.#group = options.group;
|
|
76
81
|
this.#prefix = options.prefix ?? 'durable';
|
|
82
|
+
this.#namespace = options.namespace;
|
|
83
|
+
this.#explicitNamespace = options.namespace !== undefined;
|
|
77
84
|
this.#pollIntervalMs = options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
78
85
|
this.#instanceId = options.instanceId ?? randomUUID();
|
|
79
86
|
// pop()/popFrom() require a worker id be set on the adapter before consuming.
|
|
@@ -84,17 +91,38 @@ export class QueueTransport {
|
|
|
84
91
|
get instanceId() {
|
|
85
92
|
return this.#instanceId;
|
|
86
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Adopt `namespace` (the engine's, typically), folding it into every queue name — but ONLY if a
|
|
96
|
+
* namespace wasn't passed explicitly to the constructor (an explicit one always wins). Idempotent.
|
|
97
|
+
* Satisfies the optional `Transport.useNamespace` hook the engine calls when wiring a transport.
|
|
98
|
+
*/
|
|
99
|
+
useNamespace(namespace) {
|
|
100
|
+
if (this.#explicitNamespace)
|
|
101
|
+
return;
|
|
102
|
+
this.#namespace = namespace;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The prefix every queue name is built from, folding in the namespace: a set, non-`"default"`
|
|
106
|
+
* namespace appends `-<namespace>`; otherwise the bare prefix (so the un-namespaced and `"default"`
|
|
107
|
+
* schemes are byte-identical — production names never change). Keep ALL name builders routed through
|
|
108
|
+
* this; a single direct `this.#prefix` would split an engine from its workers.
|
|
109
|
+
*/
|
|
110
|
+
#effectivePrefix() {
|
|
111
|
+
return this.#namespace && this.#namespace !== 'default'
|
|
112
|
+
? `${this.#prefix}-${this.#namespace}`
|
|
113
|
+
: this.#prefix;
|
|
114
|
+
}
|
|
87
115
|
#tasksQueue(group) {
|
|
88
|
-
return `${this.#
|
|
116
|
+
return `${this.#effectivePrefix()}:tasks:${group}`;
|
|
89
117
|
}
|
|
90
118
|
#resultsQueue() {
|
|
91
|
-
return `${this.#
|
|
119
|
+
return `${this.#effectivePrefix()}:results`;
|
|
92
120
|
}
|
|
93
121
|
#heartbeatsQueue() {
|
|
94
|
-
return `${this.#
|
|
122
|
+
return `${this.#effectivePrefix()}:heartbeats`;
|
|
95
123
|
}
|
|
96
124
|
#controlQueue() {
|
|
97
|
-
return `${this.#
|
|
125
|
+
return `${this.#effectivePrefix()}:control`;
|
|
98
126
|
}
|
|
99
127
|
/**
|
|
100
128
|
* Build the adapter `JobData` envelope for a JSON-safe payload. A translated `priority` is added
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/transports/queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAUzC,OAAO,EAAiB,OAAO,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAoB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAElE;;;;;;GAMG;AAEH,iGAAiG;AACjG,MAAM,UAAU,MAAM,CAAI,KAAQ;IAChC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAM,CAAC;AAChD,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,QAAQ,CAAI,KAAc;IACxC,uFAAuF;IACvF,mFAAmF;IACnF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAM,CAAC;IAChC,CAAC;IACD,OAAO,KAAU,CAAC;AACpB,CAAC;AAOD,2FAA2F;AAC3F,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,qGAAqG;AACrG,oGAAoG;AACpG,sGAAsG;AACtG,oGAAoG;AACpG,2EAA2E;AAC3E,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAEnC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAiB;IAChD,IAAI,QAAQ,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,wBAAwB,GAAG,QAAQ,CAA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GAAuB,CAAC;YAC5B,IAAI,CAAC;gBACH,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC3C,CAAC;YAAC,MAAM,CAAC;gBACP,yEAAyE;gBACzE,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,CAAC,GAAG;gBAAE,OAAO,KAAK,CAAC;YACvB,IAAI,CAAC;gBACH,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;gBACjB,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACjD,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,IAAI,CAAC,QAAQ;qBAChB,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;qBAC3E,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YACrB,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAED,4EAA4E;IAC5E,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RemoteStepDef, StateStore, StepCheckpoint, StepError, StepEvent, StepInvocation, StepKind, WorkflowCtx } from './interfaces.js';
|
|
1
|
+
import type { RemoteStepDef, SearchAttributes, StateStore, StepCheckpoint, StepError, StepEvent, StepInvocation, StepKind, WorkflowCtx } from './interfaces.js';
|
|
2
2
|
/** A saga undo registered by a completed step, kept with its step name for visibility on failure. */
|
|
3
3
|
export interface Compensation {
|
|
4
4
|
name: string;
|
|
@@ -49,6 +49,8 @@ export interface CtxHost {
|
|
|
49
49
|
}): Promise<TOutput>;
|
|
50
50
|
/** Start a child run once, deferred so it can't reentrantly resume a still-running parent. */
|
|
51
51
|
startChild(workflow: string, input: unknown, id: string, priority?: number): void;
|
|
52
|
+
/** Shallow-merge `attrs` into the run's `searchAttributes` (see {@link WorkflowCtx.upsertSearchAttributes}). */
|
|
53
|
+
upsertSearchAttributes(runId: string, attrs: SearchAttributes): Promise<void>;
|
|
52
54
|
/** Deliver an op to a durable entity (deferred), optionally with a `reply` token for the result. */
|
|
53
55
|
signalEntity?(name: string, key: string, op: string, arg: unknown, reply?: string): void;
|
|
54
56
|
/** Run a local step body through the registered step interceptors (identity if none). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-ctx.d.ts","sourceRoot":"","sources":["../../src/workflow-ctx.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow-ctx.d.ts","sourceRoot":"","sources":["../../src/workflow-ctx.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAGV,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,SAAS,EACT,SAAS,EACT,cAAc,EACd,QAAQ,EAGR,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAUzB,qGAAqG;AACrG,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,2FAA2F;AAC3F,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;IACjC,QAAQ,E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