@camunda8/orchestration-cluster-api 10.0.0-alpha.30 → 10.0.0-alpha.32

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.
@@ -0,0 +1,258 @@
1
+ import * as effect_Cause from 'effect/Cause';
2
+ import * as effect_Types from 'effect/Types';
3
+ import { Context, Effect, Duration, Layer, Schedule, Cause, Stream, Scope } from 'effect';
4
+ import { C as CamundaClient, a as CamundaOptions, A as ActivatedJobResult } from '../CamundaClient-D9CRR7D0.cjs';
5
+ import 'zod';
6
+ import '../logger-D-p21VHo.cjs';
7
+
8
+ declare const CamundaValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
9
+ readonly _tag: "CamundaValidationError";
10
+ } & Readonly<A>;
11
+ /** A request/response validation failure surfaced by the SDK. */
12
+ declare class CamundaValidationError extends CamundaValidationError_base<{
13
+ readonly side: 'request' | 'response';
14
+ readonly operationId?: string;
15
+ readonly summary: string;
16
+ readonly issues: string[];
17
+ readonly message: string;
18
+ readonly cause?: unknown;
19
+ }> {
20
+ }
21
+ declare const EventualConsistencyTimeout_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
22
+ readonly _tag: "EventualConsistencyTimeout";
23
+ } & Readonly<A>;
24
+ /** An eventual-consistency poll that did not converge within its budget. */
25
+ declare class EventualConsistencyTimeout extends EventualConsistencyTimeout_base<{
26
+ readonly attempts?: number;
27
+ readonly elapsedMs?: number;
28
+ readonly message: string;
29
+ readonly cause?: unknown;
30
+ }> {
31
+ }
32
+ declare const HttpError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
33
+ readonly _tag: "HttpError";
34
+ } & Readonly<A>;
35
+ /** An HTTP-level failure (non-2xx / transport carrying a status). */
36
+ declare class HttpError extends HttpError_base<{
37
+ readonly status?: number;
38
+ readonly body?: unknown;
39
+ readonly message: string;
40
+ readonly cause?: unknown;
41
+ }> {
42
+ }
43
+ declare const CamundaGenericError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
44
+ readonly _tag: "CamundaGenericError";
45
+ } & Readonly<A>;
46
+ /** Any other thrown value that does not map to a more specific tag. */
47
+ declare class CamundaGenericError extends CamundaGenericError_base<{
48
+ readonly message: string;
49
+ readonly cause?: unknown;
50
+ }> {
51
+ }
52
+ /** The typed error channel for every Effect the client produces. */
53
+ type DomainError = CamundaValidationError | EventualConsistencyTimeout | HttpError | CamundaGenericError;
54
+ /** The tag literals of the {@link DomainError} union. */
55
+ type DomainErrorTag = DomainError['_tag'];
56
+ /** Keys of `C` whose values are callable. */
57
+ type FnKeys<C> = {
58
+ [K in keyof C]: C[K] extends (...a: any) => any ? K : never;
59
+ }[keyof C];
60
+ /** Maps every method of `C` to an Effect-returning method, preserving non-fn members. */
61
+ type Effectify<C> = {
62
+ [K in FnKeys<C>]: C[K] extends (...a: infer A) => infer R ? (...a: A) => Effect.Effect<Awaited<R>, DomainError, never> : never;
63
+ } & {
64
+ inner: C;
65
+ } & {
66
+ [K in Exclude<keyof C, FnKeys<C>>]: C[K];
67
+ };
68
+ /** The Effect-flavoured Camunda client. Every operation returns an `Effect`. */
69
+ type CamundaEffectClient = Effectify<CamundaClient>;
70
+ /**
71
+ * Create an Effect-flavoured Camunda client.
72
+ *
73
+ * Every `CamundaClient` method becomes `(...args) => Effect.Effect<Awaited<R>,
74
+ * DomainError, never>`. Failures are narrowed into the tagged {@link DomainError}
75
+ * union so callers use `Effect.catchTag`/`catchTags`. The underlying throwing
76
+ * client is reachable via the `.inner` escape hatch.
77
+ *
78
+ * @description Camunda Effect Client. See the README and [this test](https://github.com/camunda/orchestration-cluster-api-js/blob/main/tests-integration/effect.test.ts) for example usage.
79
+ */
80
+ declare function createCamundaEffectClient(options?: CamundaOptions): CamundaEffectClient;
81
+ /**
82
+ * Retry an effect with exponential backoff (+ jitter), capped attempts, and an
83
+ * optional predicate over the error.
84
+ */
85
+ declare function retryWithBackoff<A, E, R>(effect: Effect.Effect<A, E, R>, opts: {
86
+ max: number;
87
+ baseDelay?: Duration.Input;
88
+ while?: (e: E) => boolean;
89
+ }): Effect.Effect<A, E, R>;
90
+ /**
91
+ * Fail an effect with a real interruption if it does not settle within `duration`
92
+ * (true interruption, not a best-effort `Promise.race`).
93
+ */
94
+ declare function withTimeout<A, E, R>(effect: Effect.Effect<A, E, R>, duration: Duration.Input, onTimeout?: () => E | EventualConsistencyTimeout): Effect.Effect<A, E | EventualConsistencyTimeout, R>;
95
+ /**
96
+ * Poll `effect` on the Effect `Clock` until `predicate` holds, timing out to
97
+ * {@link EventualConsistencyTimeout} once `waitUpTo` elapses. Because it uses the
98
+ * Effect `Clock` (not `Date.now`/`setTimeout`), `TestClock.adjust` advances it
99
+ * deterministically in tests — no real-clock burn.
100
+ */
101
+ declare function eventually<A, E, R>(effect: Effect.Effect<A, E, R>, predicate: (a: A) => boolean, opts: {
102
+ waitUpTo: Duration.Input;
103
+ interval?: Duration.Input;
104
+ }): Effect.Effect<A, E | EventualConsistencyTimeout, R>;
105
+ declare const CamundaEffect_base: Context.ServiceClass<CamundaEffect, "CamundaEffect", CamundaEffectClient>;
106
+ /**
107
+ * `Context` service key for the Effect Camunda client. Compose worker/orchestration
108
+ * code against this tag and provide {@link layer} (or a test double) via `Layer`.
109
+ */
110
+ declare class CamundaEffect extends CamundaEffect_base {
111
+ }
112
+ /**
113
+ * A `Layer` that constructs a {@link CamundaEffectClient} and provides it as the
114
+ * {@link CamundaEffect} service. Swap in a test double by providing a different
115
+ * `Layer` for the same tag.
116
+ */
117
+ declare function layer(options?: CamundaOptions): Layer.Layer<CamundaEffect>;
118
+
119
+ /**
120
+ * A single activated job handed to an Effect handler. This is the raw activation
121
+ * payload (variables + custom headers + lifecycle keys); acknowledgement is driven
122
+ * by the value/error the handler's `Effect` produces, not by imperative methods.
123
+ */
124
+ type Job = ActivatedJobResult;
125
+ /** Variables to complete a job with. `void`/`undefined` completes with no variables. */
126
+ type CompleteVars = {
127
+ readonly [key: string]: unknown;
128
+ } | void | undefined;
129
+ declare const RetryableJobError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
130
+ readonly _tag: "RetryableJobError";
131
+ } & Readonly<A>;
132
+ /**
133
+ * A retryable job failure: the handler could not complete the job now, but a later
134
+ * activation might succeed. Mapped to `failJob` with `retries - 1` and an optional
135
+ * server-side re-activation backoff.
136
+ */
137
+ declare class RetryableJobError extends RetryableJobError_base<{
138
+ readonly message: string;
139
+ /** Server-side delay before the job becomes re-activatable (`failJob` `retryBackOff`). */
140
+ readonly retryBackoff?: Duration.Input;
141
+ /** Optional variables to attach to the job on failure. */
142
+ readonly variables?: {
143
+ readonly [key: string]: unknown;
144
+ };
145
+ readonly cause?: unknown;
146
+ }> {
147
+ }
148
+ declare const TerminalJobError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
149
+ readonly _tag: "TerminalJobError";
150
+ } & Readonly<A>;
151
+ /**
152
+ * A terminal job failure: retrying will not help. Mapped to `throwJobError`, which
153
+ * is caught by a matching BPMN error boundary event or — if uncaught — raises an
154
+ * incident.
155
+ */
156
+ declare class TerminalJobError extends TerminalJobError_base<{
157
+ /** The BPMN error code matched against an error catch event. */
158
+ readonly code: string;
159
+ readonly message: string;
160
+ /** Optional variables to instantiate at the error catch event's scope. */
161
+ readonly variables?: {
162
+ readonly [key: string]: unknown;
163
+ };
164
+ readonly cause?: unknown;
165
+ }> {
166
+ }
167
+ /** The typed error channel a job handler may fail with. */
168
+ type JobError = RetryableJobError | TerminalJobError;
169
+ /** A job handler: consumes a {@link Job}, produces completion variables or a {@link JobError}. */
170
+ type JobHandler<A extends CompleteVars, R> = (job: Job) => Effect.Effect<A, JobError, R>;
171
+ interface ActivateJobsStreamOptions<R = never> {
172
+ /** Worker name recorded on the activation request. Defaults to `effect-worker-<type>-<n>`, where `<n>` is an incrementing per-process counter. */
173
+ readonly workerName?: string;
174
+ /** Max jobs to activate per poll (the activation batch size). Default `10`. */
175
+ readonly maxJobsToActivate?: number;
176
+ /**
177
+ * Delay between polls that returned **no** jobs, on the Effect `Clock` (so it is
178
+ * virtual under `TestClock`). A poll that returns jobs schedules the next poll
179
+ * immediately. Default `1 second`.
180
+ */
181
+ readonly pollInterval?: Duration.Input;
182
+ /** Per-job activation lock timeout (server-side). Default `60 seconds`. */
183
+ readonly jobTimeout?: Duration.Input;
184
+ /**
185
+ * Long-poll request timeout. `0` (the default) lets the broker hold the request
186
+ * for its configured default; a negative value returns immediately when idle.
187
+ */
188
+ readonly requestTimeout?: Duration.Input | number;
189
+ /** Restrict activation to these variable names. */
190
+ readonly fetchVariables?: readonly string[];
191
+ /**
192
+ * `Schedule` used to back off and retry a **failed activation request** (transport
193
+ * outage, broker restart, transient server error). Runs on the Effect `Clock`.
194
+ * When omitted, an activation failure fails the stream.
195
+ */
196
+ readonly activationRetrySchedule?: Schedule.Schedule<unknown, DomainError, never, R>;
197
+ }
198
+ interface EffectWorkerConfig<A extends CompleteVars, R = never> extends ActivateJobsStreamOptions<R> {
199
+ /** The job type to activate. */
200
+ readonly type: string;
201
+ /** The Effect job handler. */
202
+ readonly handler: JobHandler<A, R>;
203
+ /**
204
+ * Max jobs processed concurrently (handler parallelism / backpressure). The
205
+ * activation loop will not pull faster than handlers drain, and the activation
206
+ * batch is capped to this value (when it is a finite number) so the worker never
207
+ * leases more jobs than it can process at once. Default: the value of
208
+ * {@link ActivateJobsStreamOptions.maxJobsToActivate} (or `10`).
209
+ */
210
+ readonly concurrency?: number | 'unbounded';
211
+ /**
212
+ * `Schedule` used to retry the **handler** in-process on a {@link RetryableJobError}
213
+ * before the job is failed back to the broker. Runs on the Effect `Clock`
214
+ * (virtual under `TestClock`). A {@link TerminalJobError} is never retried.
215
+ */
216
+ readonly handlerRetrySchedule?: Schedule.Schedule<unknown, JobError, never, R>;
217
+ }
218
+ /** A handle to a running Effect worker. */
219
+ interface CamundaEffectWorkerHandle {
220
+ /** The job type this worker activates. */
221
+ readonly type: string;
222
+ /** Completes when the worker loop ends (only on a fatal, non-retryable activation error). */
223
+ readonly join: Effect.Effect<void, DomainError>;
224
+ /** Interrupt the worker (also happens automatically when the owning scope closes). */
225
+ readonly interrupt: Effect.Effect<void>;
226
+ }
227
+ /**
228
+ * A `Stream` of activated jobs of `type`. Repeatedly calls `activateJobs` (through the
229
+ * `/effect` client `Layer`, i.e. the same backpressure-aware runtime the Promise worker
230
+ * uses) and emits each activated job. The between-empty-polls delay and the optional
231
+ * activation-retry `Schedule` both run on the Effect `Clock`, so `TestClock.adjust`
232
+ * advances them deterministically in tests.
233
+ */
234
+ declare function activateJobsStream<R = never>(type: string, options?: ActivateJobsStreamOptions<R>): Stream.Stream<Job, DomainError, CamundaEffect | R>;
235
+ /**
236
+ * The worker loop: drains {@link activateJobsStream}, running the handler for each job
237
+ * with bounded `concurrency` (the backpressure knob), and acknowledging via
238
+ * `completeJob`/`failJob`/`throwJobError` per the handler's typed outcome.
239
+ */
240
+ declare function runWorkerLoop<A extends CompleteVars, R = never>(config: EffectWorkerConfig<A, R>): Effect.Effect<void, DomainError, CamundaEffect | R>;
241
+ /**
242
+ * Create and start an Effect job worker, forked into the current `Scope`. The worker
243
+ * runs until its scope closes (or {@link CamundaEffectWorkerHandle.interrupt} is run),
244
+ * at which point it is interrupted and any in-flight job's lease is released.
245
+ *
246
+ * Depends on the {@link CamundaEffect} service — provide the `/effect` client `layer`.
247
+ *
248
+ * @description Camunda Effect Worker. See the README and [this test](https://github.com/camunda/orchestration-cluster-api-js/blob/main/tests-integration/effect-worker.test.ts) for example usage.
249
+ */
250
+ declare function createCamundaEffectWorker<A extends CompleteVars, R = never>(config: EffectWorkerConfig<A, R>): Effect.Effect<CamundaEffectWorkerHandle, never, Scope.Scope | CamundaEffect | R>;
251
+ /**
252
+ * A `Layer` that runs a Camunda Effect worker for the layer's lifetime. Compose it
253
+ * with the `/effect` client `layer` (which provides its {@link CamundaEffect}
254
+ * dependency) plus a `Layer` for the handler's own requirements `R`.
255
+ */
256
+ declare function workerLayer<A extends CompleteVars, R = never>(config: EffectWorkerConfig<A, R>): Layer.Layer<never, never, CamundaEffect | R>;
257
+
258
+ export { type ActivateJobsStreamOptions, CamundaEffect, type CamundaEffectClient, type CamundaEffectWorkerHandle, CamundaGenericError, CamundaValidationError, type CompleteVars, type DomainError, type DomainErrorTag, type EffectWorkerConfig, type Effectify, EventualConsistencyTimeout, type FnKeys, HttpError, type Job, type JobError, type JobHandler, RetryableJobError, TerminalJobError, activateJobsStream, createCamundaEffectClient, createCamundaEffectWorker, eventually, layer, retryWithBackoff, runWorkerLoop, withTimeout, workerLayer };
@@ -0,0 +1,258 @@
1
+ import * as effect_Cause from 'effect/Cause';
2
+ import * as effect_Types from 'effect/Types';
3
+ import { Context, Effect, Duration, Layer, Schedule, Cause, Stream, Scope } from 'effect';
4
+ import { C as CamundaClient, a as CamundaOptions, A as ActivatedJobResult } from '../CamundaClient-BRj4omSA.js';
5
+ import 'zod';
6
+ import '../logger-D-p21VHo.js';
7
+
8
+ declare const CamundaValidationError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
9
+ readonly _tag: "CamundaValidationError";
10
+ } & Readonly<A>;
11
+ /** A request/response validation failure surfaced by the SDK. */
12
+ declare class CamundaValidationError extends CamundaValidationError_base<{
13
+ readonly side: 'request' | 'response';
14
+ readonly operationId?: string;
15
+ readonly summary: string;
16
+ readonly issues: string[];
17
+ readonly message: string;
18
+ readonly cause?: unknown;
19
+ }> {
20
+ }
21
+ declare const EventualConsistencyTimeout_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
22
+ readonly _tag: "EventualConsistencyTimeout";
23
+ } & Readonly<A>;
24
+ /** An eventual-consistency poll that did not converge within its budget. */
25
+ declare class EventualConsistencyTimeout extends EventualConsistencyTimeout_base<{
26
+ readonly attempts?: number;
27
+ readonly elapsedMs?: number;
28
+ readonly message: string;
29
+ readonly cause?: unknown;
30
+ }> {
31
+ }
32
+ declare const HttpError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
33
+ readonly _tag: "HttpError";
34
+ } & Readonly<A>;
35
+ /** An HTTP-level failure (non-2xx / transport carrying a status). */
36
+ declare class HttpError extends HttpError_base<{
37
+ readonly status?: number;
38
+ readonly body?: unknown;
39
+ readonly message: string;
40
+ readonly cause?: unknown;
41
+ }> {
42
+ }
43
+ declare const CamundaGenericError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => effect_Cause.YieldableError & {
44
+ readonly _tag: "CamundaGenericError";
45
+ } & Readonly<A>;
46
+ /** Any other thrown value that does not map to a more specific tag. */
47
+ declare class CamundaGenericError extends CamundaGenericError_base<{
48
+ readonly message: string;
49
+ readonly cause?: unknown;
50
+ }> {
51
+ }
52
+ /** The typed error channel for every Effect the client produces. */
53
+ type DomainError = CamundaValidationError | EventualConsistencyTimeout | HttpError | CamundaGenericError;
54
+ /** The tag literals of the {@link DomainError} union. */
55
+ type DomainErrorTag = DomainError['_tag'];
56
+ /** Keys of `C` whose values are callable. */
57
+ type FnKeys<C> = {
58
+ [K in keyof C]: C[K] extends (...a: any) => any ? K : never;
59
+ }[keyof C];
60
+ /** Maps every method of `C` to an Effect-returning method, preserving non-fn members. */
61
+ type Effectify<C> = {
62
+ [K in FnKeys<C>]: C[K] extends (...a: infer A) => infer R ? (...a: A) => Effect.Effect<Awaited<R>, DomainError, never> : never;
63
+ } & {
64
+ inner: C;
65
+ } & {
66
+ [K in Exclude<keyof C, FnKeys<C>>]: C[K];
67
+ };
68
+ /** The Effect-flavoured Camunda client. Every operation returns an `Effect`. */
69
+ type CamundaEffectClient = Effectify<CamundaClient>;
70
+ /**
71
+ * Create an Effect-flavoured Camunda client.
72
+ *
73
+ * Every `CamundaClient` method becomes `(...args) => Effect.Effect<Awaited<R>,
74
+ * DomainError, never>`. Failures are narrowed into the tagged {@link DomainError}
75
+ * union so callers use `Effect.catchTag`/`catchTags`. The underlying throwing
76
+ * client is reachable via the `.inner` escape hatch.
77
+ *
78
+ * @description Camunda Effect Client. See the README and [this test](https://github.com/camunda/orchestration-cluster-api-js/blob/main/tests-integration/effect.test.ts) for example usage.
79
+ */
80
+ declare function createCamundaEffectClient(options?: CamundaOptions): CamundaEffectClient;
81
+ /**
82
+ * Retry an effect with exponential backoff (+ jitter), capped attempts, and an
83
+ * optional predicate over the error.
84
+ */
85
+ declare function retryWithBackoff<A, E, R>(effect: Effect.Effect<A, E, R>, opts: {
86
+ max: number;
87
+ baseDelay?: Duration.Input;
88
+ while?: (e: E) => boolean;
89
+ }): Effect.Effect<A, E, R>;
90
+ /**
91
+ * Fail an effect with a real interruption if it does not settle within `duration`
92
+ * (true interruption, not a best-effort `Promise.race`).
93
+ */
94
+ declare function withTimeout<A, E, R>(effect: Effect.Effect<A, E, R>, duration: Duration.Input, onTimeout?: () => E | EventualConsistencyTimeout): Effect.Effect<A, E | EventualConsistencyTimeout, R>;
95
+ /**
96
+ * Poll `effect` on the Effect `Clock` until `predicate` holds, timing out to
97
+ * {@link EventualConsistencyTimeout} once `waitUpTo` elapses. Because it uses the
98
+ * Effect `Clock` (not `Date.now`/`setTimeout`), `TestClock.adjust` advances it
99
+ * deterministically in tests — no real-clock burn.
100
+ */
101
+ declare function eventually<A, E, R>(effect: Effect.Effect<A, E, R>, predicate: (a: A) => boolean, opts: {
102
+ waitUpTo: Duration.Input;
103
+ interval?: Duration.Input;
104
+ }): Effect.Effect<A, E | EventualConsistencyTimeout, R>;
105
+ declare const CamundaEffect_base: Context.ServiceClass<CamundaEffect, "CamundaEffect", CamundaEffectClient>;
106
+ /**
107
+ * `Context` service key for the Effect Camunda client. Compose worker/orchestration
108
+ * code against this tag and provide {@link layer} (or a test double) via `Layer`.
109
+ */
110
+ declare class CamundaEffect extends CamundaEffect_base {
111
+ }
112
+ /**
113
+ * A `Layer` that constructs a {@link CamundaEffectClient} and provides it as the
114
+ * {@link CamundaEffect} service. Swap in a test double by providing a different
115
+ * `Layer` for the same tag.
116
+ */
117
+ declare function layer(options?: CamundaOptions): Layer.Layer<CamundaEffect>;
118
+
119
+ /**
120
+ * A single activated job handed to an Effect handler. This is the raw activation
121
+ * payload (variables + custom headers + lifecycle keys); acknowledgement is driven
122
+ * by the value/error the handler's `Effect` produces, not by imperative methods.
123
+ */
124
+ type Job = ActivatedJobResult;
125
+ /** Variables to complete a job with. `void`/`undefined` completes with no variables. */
126
+ type CompleteVars = {
127
+ readonly [key: string]: unknown;
128
+ } | void | undefined;
129
+ declare const RetryableJobError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
130
+ readonly _tag: "RetryableJobError";
131
+ } & Readonly<A>;
132
+ /**
133
+ * A retryable job failure: the handler could not complete the job now, but a later
134
+ * activation might succeed. Mapped to `failJob` with `retries - 1` and an optional
135
+ * server-side re-activation backoff.
136
+ */
137
+ declare class RetryableJobError extends RetryableJobError_base<{
138
+ readonly message: string;
139
+ /** Server-side delay before the job becomes re-activatable (`failJob` `retryBackOff`). */
140
+ readonly retryBackoff?: Duration.Input;
141
+ /** Optional variables to attach to the job on failure. */
142
+ readonly variables?: {
143
+ readonly [key: string]: unknown;
144
+ };
145
+ readonly cause?: unknown;
146
+ }> {
147
+ }
148
+ declare const TerminalJobError_base: new <A extends Record<string, any> = {}>(args: effect_Types.VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
149
+ readonly _tag: "TerminalJobError";
150
+ } & Readonly<A>;
151
+ /**
152
+ * A terminal job failure: retrying will not help. Mapped to `throwJobError`, which
153
+ * is caught by a matching BPMN error boundary event or — if uncaught — raises an
154
+ * incident.
155
+ */
156
+ declare class TerminalJobError extends TerminalJobError_base<{
157
+ /** The BPMN error code matched against an error catch event. */
158
+ readonly code: string;
159
+ readonly message: string;
160
+ /** Optional variables to instantiate at the error catch event's scope. */
161
+ readonly variables?: {
162
+ readonly [key: string]: unknown;
163
+ };
164
+ readonly cause?: unknown;
165
+ }> {
166
+ }
167
+ /** The typed error channel a job handler may fail with. */
168
+ type JobError = RetryableJobError | TerminalJobError;
169
+ /** A job handler: consumes a {@link Job}, produces completion variables or a {@link JobError}. */
170
+ type JobHandler<A extends CompleteVars, R> = (job: Job) => Effect.Effect<A, JobError, R>;
171
+ interface ActivateJobsStreamOptions<R = never> {
172
+ /** Worker name recorded on the activation request. Defaults to `effect-worker-<type>-<n>`, where `<n>` is an incrementing per-process counter. */
173
+ readonly workerName?: string;
174
+ /** Max jobs to activate per poll (the activation batch size). Default `10`. */
175
+ readonly maxJobsToActivate?: number;
176
+ /**
177
+ * Delay between polls that returned **no** jobs, on the Effect `Clock` (so it is
178
+ * virtual under `TestClock`). A poll that returns jobs schedules the next poll
179
+ * immediately. Default `1 second`.
180
+ */
181
+ readonly pollInterval?: Duration.Input;
182
+ /** Per-job activation lock timeout (server-side). Default `60 seconds`. */
183
+ readonly jobTimeout?: Duration.Input;
184
+ /**
185
+ * Long-poll request timeout. `0` (the default) lets the broker hold the request
186
+ * for its configured default; a negative value returns immediately when idle.
187
+ */
188
+ readonly requestTimeout?: Duration.Input | number;
189
+ /** Restrict activation to these variable names. */
190
+ readonly fetchVariables?: readonly string[];
191
+ /**
192
+ * `Schedule` used to back off and retry a **failed activation request** (transport
193
+ * outage, broker restart, transient server error). Runs on the Effect `Clock`.
194
+ * When omitted, an activation failure fails the stream.
195
+ */
196
+ readonly activationRetrySchedule?: Schedule.Schedule<unknown, DomainError, never, R>;
197
+ }
198
+ interface EffectWorkerConfig<A extends CompleteVars, R = never> extends ActivateJobsStreamOptions<R> {
199
+ /** The job type to activate. */
200
+ readonly type: string;
201
+ /** The Effect job handler. */
202
+ readonly handler: JobHandler<A, R>;
203
+ /**
204
+ * Max jobs processed concurrently (handler parallelism / backpressure). The
205
+ * activation loop will not pull faster than handlers drain, and the activation
206
+ * batch is capped to this value (when it is a finite number) so the worker never
207
+ * leases more jobs than it can process at once. Default: the value of
208
+ * {@link ActivateJobsStreamOptions.maxJobsToActivate} (or `10`).
209
+ */
210
+ readonly concurrency?: number | 'unbounded';
211
+ /**
212
+ * `Schedule` used to retry the **handler** in-process on a {@link RetryableJobError}
213
+ * before the job is failed back to the broker. Runs on the Effect `Clock`
214
+ * (virtual under `TestClock`). A {@link TerminalJobError} is never retried.
215
+ */
216
+ readonly handlerRetrySchedule?: Schedule.Schedule<unknown, JobError, never, R>;
217
+ }
218
+ /** A handle to a running Effect worker. */
219
+ interface CamundaEffectWorkerHandle {
220
+ /** The job type this worker activates. */
221
+ readonly type: string;
222
+ /** Completes when the worker loop ends (only on a fatal, non-retryable activation error). */
223
+ readonly join: Effect.Effect<void, DomainError>;
224
+ /** Interrupt the worker (also happens automatically when the owning scope closes). */
225
+ readonly interrupt: Effect.Effect<void>;
226
+ }
227
+ /**
228
+ * A `Stream` of activated jobs of `type`. Repeatedly calls `activateJobs` (through the
229
+ * `/effect` client `Layer`, i.e. the same backpressure-aware runtime the Promise worker
230
+ * uses) and emits each activated job. The between-empty-polls delay and the optional
231
+ * activation-retry `Schedule` both run on the Effect `Clock`, so `TestClock.adjust`
232
+ * advances them deterministically in tests.
233
+ */
234
+ declare function activateJobsStream<R = never>(type: string, options?: ActivateJobsStreamOptions<R>): Stream.Stream<Job, DomainError, CamundaEffect | R>;
235
+ /**
236
+ * The worker loop: drains {@link activateJobsStream}, running the handler for each job
237
+ * with bounded `concurrency` (the backpressure knob), and acknowledging via
238
+ * `completeJob`/`failJob`/`throwJobError` per the handler's typed outcome.
239
+ */
240
+ declare function runWorkerLoop<A extends CompleteVars, R = never>(config: EffectWorkerConfig<A, R>): Effect.Effect<void, DomainError, CamundaEffect | R>;
241
+ /**
242
+ * Create and start an Effect job worker, forked into the current `Scope`. The worker
243
+ * runs until its scope closes (or {@link CamundaEffectWorkerHandle.interrupt} is run),
244
+ * at which point it is interrupted and any in-flight job's lease is released.
245
+ *
246
+ * Depends on the {@link CamundaEffect} service — provide the `/effect` client `layer`.
247
+ *
248
+ * @description Camunda Effect Worker. See the README and [this test](https://github.com/camunda/orchestration-cluster-api-js/blob/main/tests-integration/effect-worker.test.ts) for example usage.
249
+ */
250
+ declare function createCamundaEffectWorker<A extends CompleteVars, R = never>(config: EffectWorkerConfig<A, R>): Effect.Effect<CamundaEffectWorkerHandle, never, Scope.Scope | CamundaEffect | R>;
251
+ /**
252
+ * A `Layer` that runs a Camunda Effect worker for the layer's lifetime. Compose it
253
+ * with the `/effect` client `layer` (which provides its {@link CamundaEffect}
254
+ * dependency) plus a `Layer` for the handler's own requirements `R`.
255
+ */
256
+ declare function workerLayer<A extends CompleteVars, R = never>(config: EffectWorkerConfig<A, R>): Layer.Layer<never, never, CamundaEffect | R>;
257
+
258
+ export { type ActivateJobsStreamOptions, CamundaEffect, type CamundaEffectClient, type CamundaEffectWorkerHandle, CamundaGenericError, CamundaValidationError, type CompleteVars, type DomainError, type DomainErrorTag, type EffectWorkerConfig, type Effectify, EventualConsistencyTimeout, type FnKeys, HttpError, type Job, type JobError, type JobHandler, RetryableJobError, TerminalJobError, activateJobsStream, createCamundaEffectClient, createCamundaEffectWorker, eventually, layer, retryWithBackoff, runWorkerLoop, withTimeout, workerLayer };