@cleocode/lafs 2026.3.74 → 2026.4.3
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/LICENSE +0 -0
- package/README.md +97 -68
- package/dist/schemas/v1/agent-card.schema.json +230 -0
- package/dist/schemas/v1/conformance-profiles.json +0 -0
- package/dist/schemas/v1/context-ledger.schema.json +70 -0
- package/dist/schemas/v1/discovery.schema.json +132 -0
- package/dist/schemas/v1/envelope.schema.json +0 -0
- package/dist/schemas/v1/error-registry.json +0 -0
- package/dist/src/a2a/bindings/grpc.d.ts +118 -11
- package/dist/src/a2a/bindings/grpc.d.ts.map +1 -0
- package/dist/src/a2a/bindings/grpc.js +80 -8
- package/dist/src/a2a/bindings/grpc.js.map +1 -0
- package/dist/src/a2a/bindings/http.d.ts +131 -15
- package/dist/src/a2a/bindings/http.d.ts.map +1 -0
- package/dist/src/a2a/bindings/http.js +101 -14
- package/dist/src/a2a/bindings/http.js.map +1 -0
- package/dist/src/a2a/bindings/index.d.ts +83 -9
- package/dist/src/a2a/bindings/index.d.ts.map +1 -0
- package/dist/src/a2a/bindings/index.js +74 -6
- package/dist/src/a2a/bindings/index.js.map +1 -0
- package/dist/src/a2a/bindings/jsonrpc.d.ts +194 -9
- package/dist/src/a2a/bindings/jsonrpc.d.ts.map +1 -0
- package/dist/src/a2a/bindings/jsonrpc.js +155 -10
- package/dist/src/a2a/bindings/jsonrpc.js.map +1 -0
- package/dist/src/a2a/bridge.d.ts +237 -44
- package/dist/src/a2a/bridge.d.ts.map +1 -0
- package/dist/src/a2a/bridge.js +187 -48
- package/dist/src/a2a/bridge.js.map +1 -0
- package/dist/src/a2a/extensions.d.ts +222 -12
- package/dist/src/a2a/extensions.d.ts.map +1 -0
- package/dist/src/a2a/extensions.js +178 -13
- package/dist/src/a2a/extensions.js.map +1 -0
- package/dist/src/a2a/index.d.ts +10 -7
- package/dist/src/a2a/index.d.ts.map +1 -0
- package/dist/src/a2a/index.js +24 -27
- package/dist/src/a2a/index.js.map +1 -0
- package/dist/src/a2a/streaming.d.ts +276 -3
- package/dist/src/a2a/streaming.d.ts.map +1 -0
- package/dist/src/a2a/streaming.js +255 -11
- package/dist/src/a2a/streaming.js.map +1 -0
- package/dist/src/a2a/task-lifecycle.d.ts +341 -20
- package/dist/src/a2a/task-lifecycle.d.ts.map +1 -0
- package/dist/src/a2a/task-lifecycle.js +327 -26
- package/dist/src/a2a/task-lifecycle.js.map +1 -0
- package/dist/src/budgetEnforcement.d.ts +93 -20
- package/dist/src/budgetEnforcement.d.ts.map +1 -0
- package/dist/src/budgetEnforcement.js +146 -31
- package/dist/src/budgetEnforcement.js.map +1 -0
- package/dist/src/circuit-breaker/index.d.ts +260 -10
- package/dist/src/circuit-breaker/index.d.ts.map +1 -0
- package/dist/src/circuit-breaker/index.js +226 -14
- package/dist/src/circuit-breaker/index.js.map +1 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +12 -11
- package/dist/src/cli.js.map +1 -0
- package/dist/src/compliance.d.ts +180 -3
- package/dist/src/compliance.d.ts.map +1 -0
- package/dist/src/compliance.js +114 -13
- package/dist/src/compliance.js.map +1 -0
- package/dist/src/conformance.d.ts +55 -2
- package/dist/src/conformance.d.ts.map +1 -0
- package/dist/src/conformance.js +124 -76
- package/dist/src/conformance.js.map +1 -0
- package/dist/src/conformanceProfiles.d.ts +68 -1
- package/dist/src/conformanceProfiles.d.ts.map +1 -0
- package/dist/src/conformanceProfiles.js +53 -1
- package/dist/src/conformanceProfiles.js.map +1 -0
- package/dist/src/deprecationRegistry.d.ts +82 -1
- package/dist/src/deprecationRegistry.d.ts.map +1 -0
- package/dist/src/deprecationRegistry.js +58 -7
- package/dist/src/deprecationRegistry.js.map +1 -0
- package/dist/src/discovery.d.ts +347 -65
- package/dist/src/discovery.d.ts.map +1 -0
- package/dist/src/discovery.js +130 -72
- package/dist/src/discovery.js.map +1 -0
- package/dist/src/envelope.d.ts +262 -9
- package/dist/src/envelope.d.ts.map +1 -0
- package/dist/src/envelope.js +179 -15
- package/dist/src/envelope.js.map +1 -0
- package/dist/src/errorRegistry.d.ts +163 -3
- package/dist/src/errorRegistry.d.ts.map +1 -0
- package/dist/src/errorRegistry.js +119 -3
- package/dist/src/errorRegistry.js.map +1 -0
- package/dist/src/fieldExtraction.d.ts +128 -27
- package/dist/src/fieldExtraction.d.ts.map +1 -0
- package/dist/src/fieldExtraction.js +100 -27
- package/dist/src/fieldExtraction.js.map +1 -0
- package/dist/src/flagResolver.d.ts +77 -10
- package/dist/src/flagResolver.d.ts.map +1 -0
- package/dist/src/flagResolver.js +22 -5
- package/dist/src/flagResolver.js.map +1 -0
- package/dist/src/flagSemantics.d.ts +80 -4
- package/dist/src/flagSemantics.d.ts.map +1 -0
- package/dist/src/flagSemantics.js +78 -11
- package/dist/src/flagSemantics.js.map +1 -0
- package/dist/src/health/index.d.ts +103 -9
- package/dist/src/health/index.d.ts.map +1 -0
- package/dist/src/health/index.js +75 -26
- package/dist/src/health/index.js.map +1 -0
- package/dist/src/index.d.ts +34 -23
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +40 -28
- package/dist/src/index.js.map +1 -0
- package/dist/src/mviProjection.d.ts +43 -6
- package/dist/src/mviProjection.d.ts.map +1 -0
- package/dist/src/mviProjection.js +32 -5
- package/dist/src/mviProjection.js.map +1 -0
- package/dist/src/native-loader.d.ts +49 -0
- package/dist/src/native-loader.d.ts.map +1 -0
- package/dist/src/native-loader.js +56 -0
- package/dist/src/native-loader.js.map +1 -0
- package/dist/src/problemDetails.d.ts +71 -4
- package/dist/src/problemDetails.d.ts.map +1 -0
- package/dist/src/problemDetails.js +27 -3
- package/dist/src/problemDetails.js.map +1 -0
- package/dist/src/shutdown/index.d.ts +103 -9
- package/dist/src/shutdown/index.d.ts.map +1 -0
- package/dist/src/shutdown/index.js +78 -12
- package/dist/src/shutdown/index.js.map +1 -0
- package/dist/src/tokenEstimator.d.ts +98 -11
- package/dist/src/tokenEstimator.d.ts.map +1 -0
- package/dist/src/tokenEstimator.js +91 -13
- package/dist/src/tokenEstimator.js.map +1 -0
- package/dist/src/types.d.ts +477 -11
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +76 -2
- package/dist/src/types.js.map +1 -0
- package/dist/src/validateEnvelope.d.ts +61 -2
- package/dist/src/validateEnvelope.d.ts.map +1 -0
- package/dist/src/validateEnvelope.js +81 -14
- package/dist/src/validateEnvelope.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/lafs.md +3 -4
- package/package.json +14 -12
- package/schemas/v1/agent-card.schema.json +0 -0
- package/schemas/v1/conformance-profiles.json +0 -0
- package/schemas/v1/context-ledger.schema.json +0 -0
- package/schemas/v1/discovery.schema.json +0 -0
- package/schemas/v1/envelope.schema.json +0 -0
- package/schemas/v1/error-registry.json +0 -0
- package/dist/src/mcpAdapter.d.ts +0 -28
- package/dist/src/mcpAdapter.js +0 -281
|
@@ -1,29 +1,97 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LAFS Circuit Breaker Module
|
|
3
3
|
*
|
|
4
|
-
* Provides circuit breaker pattern for resilient service calls
|
|
4
|
+
* Provides circuit breaker pattern for resilient service calls.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Represents the three possible states of a circuit breaker.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* - `CLOSED` means the circuit is operating normally and requests pass through.
|
|
13
|
+
* - `OPEN` means the circuit has tripped due to failures and requests are rejected.
|
|
14
|
+
* - `HALF_OPEN` means the circuit is testing whether the downstream service has recovered.
|
|
5
15
|
*/
|
|
6
16
|
export type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN';
|
|
17
|
+
/** Configuration options for a {@link CircuitBreaker} instance. */
|
|
7
18
|
export interface CircuitBreakerConfig {
|
|
19
|
+
/** Unique identifier for this circuit breaker, used in log messages and metrics. */
|
|
8
20
|
name: string;
|
|
21
|
+
/**
|
|
22
|
+
* Number of failures required to trip the circuit from CLOSED to OPEN.
|
|
23
|
+
* @defaultValue 5
|
|
24
|
+
*/
|
|
9
25
|
failureThreshold?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Milliseconds to wait before transitioning from OPEN to HALF_OPEN.
|
|
28
|
+
* @defaultValue 30000
|
|
29
|
+
*/
|
|
10
30
|
resetTimeout?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Maximum number of trial calls allowed while in the HALF_OPEN state.
|
|
33
|
+
* @defaultValue 3
|
|
34
|
+
*/
|
|
11
35
|
halfOpenMaxCalls?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Consecutive successes required in HALF_OPEN to close the circuit.
|
|
38
|
+
* @defaultValue 2
|
|
39
|
+
*/
|
|
12
40
|
successThreshold?: number;
|
|
13
41
|
}
|
|
42
|
+
/** Snapshot of runtime metrics for a {@link CircuitBreaker}. */
|
|
14
43
|
export interface CircuitBreakerMetrics {
|
|
44
|
+
/** Current state of the circuit breaker. */
|
|
15
45
|
state: CircuitState;
|
|
46
|
+
/** Total number of recorded failures since the last reset. */
|
|
16
47
|
failures: number;
|
|
48
|
+
/** Total number of recorded successes since the last reset. */
|
|
17
49
|
successes: number;
|
|
50
|
+
/**
|
|
51
|
+
* Timestamp of the most recent failure, if any.
|
|
52
|
+
* @defaultValue undefined
|
|
53
|
+
*/
|
|
18
54
|
lastFailureTime?: Date;
|
|
55
|
+
/** Number of consecutive successes since the last failure. */
|
|
19
56
|
consecutiveSuccesses: number;
|
|
57
|
+
/** Total number of calls made through this circuit breaker. */
|
|
20
58
|
totalCalls: number;
|
|
21
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Error thrown when a circuit breaker rejects a call.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* This error is raised when the circuit is in the OPEN state or when the
|
|
65
|
+
* HALF_OPEN call limit has been reached. Callers should catch this to
|
|
66
|
+
* implement fallback logic or return a 503 response.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* try {
|
|
71
|
+
* await breaker.execute(() => fetch('/api'));
|
|
72
|
+
* } catch (err) {
|
|
73
|
+
* if (err instanceof CircuitBreakerError) {
|
|
74
|
+
* console.log('Circuit open, using fallback');
|
|
75
|
+
* }
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
22
79
|
export declare class CircuitBreakerError extends Error {
|
|
80
|
+
/**
|
|
81
|
+
* Creates a new CircuitBreakerError.
|
|
82
|
+
*
|
|
83
|
+
* @param message - Descriptive error message indicating why the call was rejected
|
|
84
|
+
*/
|
|
23
85
|
constructor(message: string);
|
|
24
86
|
}
|
|
25
87
|
/**
|
|
26
|
-
* Circuit breaker for protecting against cascading failures
|
|
88
|
+
* Circuit breaker for protecting against cascading failures.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* Implements the circuit breaker pattern with three states: CLOSED (normal),
|
|
92
|
+
* OPEN (rejecting calls), and HALF_OPEN (testing recovery). The breaker
|
|
93
|
+
* automatically transitions between states based on failure and success
|
|
94
|
+
* thresholds, and schedules reset timers when the circuit opens.
|
|
27
95
|
*
|
|
28
96
|
* @example
|
|
29
97
|
* ```typescript
|
|
@@ -48,44 +116,134 @@ export declare class CircuitBreakerError extends Error {
|
|
|
48
116
|
*/
|
|
49
117
|
export declare class CircuitBreaker {
|
|
50
118
|
private config;
|
|
119
|
+
/** Current circuit state. */
|
|
51
120
|
private state;
|
|
121
|
+
/** Total failure count since last reset. */
|
|
52
122
|
private failures;
|
|
123
|
+
/** Total success count since last reset. */
|
|
53
124
|
private successes;
|
|
125
|
+
/** Timestamp of the most recent failure. */
|
|
54
126
|
private lastFailureTime?;
|
|
127
|
+
/** Consecutive successes since the last failure. */
|
|
55
128
|
private consecutiveSuccesses;
|
|
129
|
+
/** Lifetime call count. */
|
|
56
130
|
private totalCalls;
|
|
131
|
+
/** Number of calls made while in the HALF_OPEN state. */
|
|
57
132
|
private halfOpenCalls;
|
|
133
|
+
/** Timer handle for the scheduled OPEN-to-HALF_OPEN transition. */
|
|
58
134
|
private resetTimer?;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a new CircuitBreaker with the given configuration.
|
|
137
|
+
*
|
|
138
|
+
* @param config - Circuit breaker configuration with name, thresholds, and timeouts
|
|
139
|
+
*/
|
|
59
140
|
constructor(config: CircuitBreakerConfig);
|
|
60
141
|
/**
|
|
61
|
-
* Execute a function with circuit breaker protection
|
|
142
|
+
* Execute a function with circuit breaker protection.
|
|
143
|
+
*
|
|
144
|
+
* @remarks
|
|
145
|
+
* When the circuit is CLOSED, calls pass through normally. When OPEN, calls
|
|
146
|
+
* are rejected with a {@link CircuitBreakerError} unless the reset timeout has
|
|
147
|
+
* elapsed (triggering HALF_OPEN). In HALF_OPEN, a limited number of trial
|
|
148
|
+
* calls are permitted; successes may close the circuit while failures re-open it.
|
|
149
|
+
*
|
|
150
|
+
* @typeParam T - Return type of the wrapped function
|
|
151
|
+
* @param fn - Async function to execute under circuit breaker protection
|
|
152
|
+
* @returns The result of invoking `fn`
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const result = await breaker.execute(async () => {
|
|
157
|
+
* return await fetch('https://api.example.com/data');
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
62
160
|
*/
|
|
63
161
|
execute<T>(fn: () => Promise<T>): Promise<T>;
|
|
64
162
|
/**
|
|
65
|
-
* Get current circuit breaker state
|
|
163
|
+
* Get the current circuit breaker state.
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* Returns one of `'CLOSED'`, `'OPEN'`, or `'HALF_OPEN'`. Useful for
|
|
167
|
+
* dashboards or conditional logic that needs to know whether calls will
|
|
168
|
+
* be accepted.
|
|
169
|
+
*
|
|
170
|
+
* @returns The current {@link CircuitState}
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* if (breaker.getState() === 'OPEN') {
|
|
175
|
+
* console.log('Circuit is open, requests will be rejected');
|
|
176
|
+
* }
|
|
177
|
+
* ```
|
|
66
178
|
*/
|
|
67
179
|
getState(): CircuitState;
|
|
68
180
|
/**
|
|
69
|
-
* Get circuit breaker metrics
|
|
181
|
+
* Get a snapshot of the circuit breaker's runtime metrics.
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* Returns a copy of the internal counters including failure/success counts,
|
|
185
|
+
* the current state, and the timestamp of the last failure. Useful for
|
|
186
|
+
* monitoring and observability.
|
|
187
|
+
*
|
|
188
|
+
* @returns A {@link CircuitBreakerMetrics} snapshot
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const metrics = breaker.getMetrics();
|
|
193
|
+
* console.log(`State: ${metrics.state}, Failures: ${metrics.failures}`);
|
|
194
|
+
* ```
|
|
70
195
|
*/
|
|
71
196
|
getMetrics(): CircuitBreakerMetrics;
|
|
72
197
|
/**
|
|
73
|
-
* Manually open the circuit breaker
|
|
198
|
+
* Manually open the circuit breaker, rejecting all subsequent calls.
|
|
199
|
+
*
|
|
200
|
+
* @remarks
|
|
201
|
+
* Forces the circuit into the OPEN state regardless of the current failure
|
|
202
|
+
* count. Useful for administrative controls or when an external signal
|
|
203
|
+
* indicates the downstream service is unavailable.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* breaker.forceOpen();
|
|
208
|
+
* console.log(breaker.getState()); // 'OPEN'
|
|
209
|
+
* ```
|
|
74
210
|
*/
|
|
75
211
|
forceOpen(): void;
|
|
76
212
|
/**
|
|
77
|
-
* Manually close the circuit breaker
|
|
213
|
+
* Manually close the circuit breaker and reset all counters.
|
|
214
|
+
*
|
|
215
|
+
* @remarks
|
|
216
|
+
* Forces the circuit into the CLOSED state and clears failure/success
|
|
217
|
+
* counters and any pending reset timer. Useful for administrative recovery
|
|
218
|
+
* after a known issue has been resolved.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* breaker.forceClose();
|
|
223
|
+
* console.log(breaker.getState()); // 'CLOSED'
|
|
224
|
+
* ```
|
|
78
225
|
*/
|
|
79
226
|
forceClose(): void;
|
|
227
|
+
/** Records a successful call and may transition from HALF_OPEN to CLOSED. */
|
|
80
228
|
private onSuccess;
|
|
229
|
+
/** Records a failed call and may trip the circuit to OPEN. */
|
|
81
230
|
private onFailure;
|
|
231
|
+
/** Transitions the circuit to the given state, resetting HALF_OPEN call count when entering HALF_OPEN. */
|
|
82
232
|
private transitionTo;
|
|
233
|
+
/** Returns `true` if enough time has elapsed since the last failure to attempt a reset. */
|
|
83
234
|
private shouldAttemptReset;
|
|
235
|
+
/** Schedules a timer to transition from OPEN to HALF_OPEN after the configured reset timeout. */
|
|
84
236
|
private scheduleReset;
|
|
237
|
+
/** Resets all failure/success counters and clears the pending reset timer. */
|
|
85
238
|
private reset;
|
|
86
239
|
}
|
|
87
240
|
/**
|
|
88
|
-
*
|
|
241
|
+
* Registry for managing multiple named circuit breakers.
|
|
242
|
+
*
|
|
243
|
+
* @remarks
|
|
244
|
+
* Provides centralized creation, lookup, and metrics aggregation for
|
|
245
|
+
* circuit breakers. Each breaker is stored by name and can be retrieved
|
|
246
|
+
* or lazily created via {@link CircuitBreakerRegistry.getOrCreate}.
|
|
89
247
|
*
|
|
90
248
|
* @example
|
|
91
249
|
* ```typescript
|
|
@@ -100,15 +258,102 @@ export declare class CircuitBreaker {
|
|
|
100
258
|
* ```
|
|
101
259
|
*/
|
|
102
260
|
export declare class CircuitBreakerRegistry {
|
|
261
|
+
/** Internal map of circuit breaker name to instance. */
|
|
103
262
|
private breakers;
|
|
263
|
+
/**
|
|
264
|
+
* Register a new circuit breaker with the given name and configuration.
|
|
265
|
+
*
|
|
266
|
+
* @remarks
|
|
267
|
+
* Creates a new {@link CircuitBreaker}, stores it in the registry, and
|
|
268
|
+
* returns it. If a breaker with the same name already exists, it is replaced.
|
|
269
|
+
*
|
|
270
|
+
* @param name - Unique name for the circuit breaker
|
|
271
|
+
* @param config - Configuration options (name is set automatically)
|
|
272
|
+
* @returns The newly created {@link CircuitBreaker}
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const breaker = registry.add('user-service', { failureThreshold: 3 });
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
104
279
|
add(name: string, config: Omit<CircuitBreakerConfig, 'name'>): CircuitBreaker;
|
|
280
|
+
/**
|
|
281
|
+
* Retrieve a circuit breaker by name.
|
|
282
|
+
*
|
|
283
|
+
* @remarks
|
|
284
|
+
* Returns `undefined` if no breaker with the given name has been registered.
|
|
285
|
+
*
|
|
286
|
+
* @param name - Name of the circuit breaker to look up
|
|
287
|
+
* @returns The matching {@link CircuitBreaker}, or `undefined` if not found
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* const breaker = registry.get('payment-api');
|
|
292
|
+
* if (breaker) {
|
|
293
|
+
* await breaker.execute(() => callPaymentApi());
|
|
294
|
+
* }
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
105
297
|
get(name: string): CircuitBreaker | undefined;
|
|
298
|
+
/**
|
|
299
|
+
* Retrieve an existing circuit breaker or create one if it does not exist.
|
|
300
|
+
*
|
|
301
|
+
* @remarks
|
|
302
|
+
* This is useful when callers want a breaker but do not know whether it
|
|
303
|
+
* has already been registered, avoiding duplicate creation.
|
|
304
|
+
*
|
|
305
|
+
* @param name - Name of the circuit breaker
|
|
306
|
+
* @param config - Configuration to use if a new breaker must be created
|
|
307
|
+
* @returns The existing or newly created {@link CircuitBreaker}
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* const breaker = registry.getOrCreate('cache-api', { failureThreshold: 10 });
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
106
314
|
getOrCreate(name: string, config: Omit<CircuitBreakerConfig, 'name'>): CircuitBreaker;
|
|
315
|
+
/**
|
|
316
|
+
* Collect metrics from all registered circuit breakers.
|
|
317
|
+
*
|
|
318
|
+
* @remarks
|
|
319
|
+
* Returns a record keyed by breaker name with each value being the
|
|
320
|
+
* corresponding {@link CircuitBreakerMetrics} snapshot.
|
|
321
|
+
*
|
|
322
|
+
* @returns A record mapping breaker names to their current metrics
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* const allMetrics = registry.getAllMetrics();
|
|
327
|
+
* for (const [name, metrics] of Object.entries(allMetrics)) {
|
|
328
|
+
* console.log(`${name}: ${metrics.state}`);
|
|
329
|
+
* }
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
107
332
|
getAllMetrics(): Record<string, CircuitBreakerMetrics>;
|
|
333
|
+
/**
|
|
334
|
+
* Force-close all registered circuit breakers, resetting their counters.
|
|
335
|
+
*
|
|
336
|
+
* @remarks
|
|
337
|
+
* Iterates over every registered breaker and calls {@link CircuitBreaker.forceClose}.
|
|
338
|
+
* Useful for administrative recovery or test teardown.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* registry.resetAll();
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
108
345
|
resetAll(): void;
|
|
109
346
|
}
|
|
110
347
|
/**
|
|
111
|
-
* Create a circuit breaker
|
|
348
|
+
* Create an Express middleware that wraps downstream handlers with a circuit breaker.
|
|
349
|
+
*
|
|
350
|
+
* @remarks
|
|
351
|
+
* Instantiates a {@link CircuitBreaker} from the provided config and wraps the
|
|
352
|
+
* `next()` call. When the circuit is open, the middleware responds with a 503
|
|
353
|
+
* status and a JSON error body instead of forwarding the request.
|
|
354
|
+
*
|
|
355
|
+
* @param config - Circuit breaker configuration for the middleware instance
|
|
356
|
+
* @returns An Express-compatible middleware function
|
|
112
357
|
*
|
|
113
358
|
* @example
|
|
114
359
|
* ```typescript
|
|
@@ -118,4 +363,9 @@ export declare class CircuitBreakerRegistry {
|
|
|
118
363
|
* }));
|
|
119
364
|
* ```
|
|
120
365
|
*/
|
|
121
|
-
export declare function circuitBreakerMiddleware(config: CircuitBreakerConfig): (
|
|
366
|
+
export declare function circuitBreakerMiddleware(config: CircuitBreakerConfig): (_req: unknown, res: {
|
|
367
|
+
status: (code: number) => {
|
|
368
|
+
json: (body: unknown) => void;
|
|
369
|
+
};
|
|
370
|
+
}, next: () => void) => Promise<void>;
|
|
371
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/circuit-breaker/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAE3D,mEAAmE;AACnE,MAAM,WAAW,oBAAoB;IACnC,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,gEAAgE;AAChE,MAAM,WAAW,qBAAqB;IACpC,4CAA4C;IAC5C,KAAK,EAAE,YAAY,CAAC;IAEpB,8DAA8D;IAC9D,QAAQ,EAAE,MAAM,CAAC;IAEjB,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,eAAe,CAAC,EAAE,IAAI,CAAC;IAEvB,8DAA8D;IAC9D,oBAAoB,EAAE,MAAM,CAAC;IAE7B,+DAA+D;IAC/D,UAAU,EAAE,MAAM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