@fabricorg/platform 1.10.0 → 1.10.1
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 +46 -0
- package/README.md +31 -2
- package/dist/actions/index.cjs +45 -26
- package/dist/actions/index.cjs.map +1 -1
- package/dist/actions/index.d.cts +225 -226
- package/dist/actions/index.d.ts +225 -226
- package/dist/actions/index.js +41 -2
- package/dist/actions/index.js.map +1 -1
- package/dist/adapters/index.cjs +696 -66
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +367 -365
- package/dist/adapters/index.d.ts +367 -365
- package/dist/adapters/index.js +682 -2
- package/dist/adapters/index.js.map +1 -1
- package/dist/agent-hitl/index.cjs +21 -10
- package/dist/agent-hitl/index.cjs.map +1 -1
- package/dist/agent-hitl/index.d.cts +30 -30
- package/dist/agent-hitl/index.d.ts +30 -30
- package/dist/agent-hitl/index.js +21 -2
- package/dist/agent-hitl/index.js.map +1 -1
- package/dist/certification/index.cjs +109 -24
- package/dist/certification/index.cjs.map +1 -1
- package/dist/certification/index.d.cts +33 -39
- package/dist/certification/index.d.ts +33 -39
- package/dist/certification/index.js +107 -8
- package/dist/certification/index.js.map +1 -1
- package/dist/discovery/index.cjs +12 -10
- package/dist/discovery/index.cjs.map +1 -1
- package/dist/discovery/index.d.cts +2 -10
- package/dist/discovery/index.d.ts +2 -10
- package/dist/discovery/index.js +12 -2
- package/dist/discovery/index.js.map +1 -1
- package/dist/engine-B4csEOEc.js +223 -0
- package/dist/engine-B4csEOEc.js.map +1 -0
- package/dist/engine-BqScuhrT.cjs +246 -0
- package/dist/engine-BqScuhrT.cjs.map +1 -0
- package/dist/events/index.cjs +39 -10
- package/dist/events/index.cjs.map +1 -1
- package/dist/events/index.d.cts +43 -43
- package/dist/events/index.d.ts +43 -43
- package/dist/events/index.js +39 -2
- package/dist/events/index.js.map +1 -1
- package/dist/evidence/index.cjs +12 -50
- package/dist/evidence/index.d.cts +2 -229
- package/dist/evidence/index.d.ts +2 -229
- package/dist/evidence/index.js +1 -5
- package/dist/evidence-BuCICb0c.js +516 -0
- package/dist/evidence-BuCICb0c.js.map +1 -0
- package/dist/evidence-Cq48eDvA.cjs +575 -0
- package/dist/evidence-Cq48eDvA.cjs.map +1 -0
- package/dist/governance/index.cjs +24 -18
- package/dist/governance/index.cjs.map +1 -1
- package/dist/governance/index.d.cts +80 -83
- package/dist/governance/index.d.ts +80 -83
- package/dist/governance/index.js +22 -2
- package/dist/governance/index.js.map +1 -1
- package/dist/ids/index.cjs +52 -22
- package/dist/ids/index.cjs.map +1 -1
- package/dist/ids/index.d.cts +17 -17
- package/dist/ids/index.d.ts +17 -17
- package/dist/ids/index.js +49 -2
- package/dist/ids/index.js.map +1 -1
- package/dist/index-9jasmw76.d.cts +124 -0
- package/dist/index-BXpeFdk2.d.cts +190 -0
- package/dist/index-BXpeFdk2.d.ts +190 -0
- package/dist/index-BnbsKZsT.d.cts +231 -0
- package/dist/index-CIl1rYRv.d.cts +11 -0
- package/dist/index-CIl1rYRv.d.ts +11 -0
- package/dist/index-CVHA1ypT.d.cts +262 -0
- package/dist/index-DZ4mnNb7.d.cts +78 -0
- package/dist/index-DZ4mnNb7.d.ts +78 -0
- package/dist/index-IqcDvl69.d.ts +124 -0
- package/dist/index-fmUiRBXu.d.cts +57 -0
- package/dist/index-fmUiRBXu.d.ts +57 -0
- package/dist/index-sPUPs8pr.d.ts +262 -0
- package/dist/index-z9-CYOIo.d.ts +231 -0
- package/dist/index.cjs +111 -393
- package/dist/index.d.cts +18 -17
- package/dist/index.d.ts +18 -17
- package/dist/index.js +19 -20
- package/dist/manifest/index.cjs +224 -35
- package/dist/manifest/index.cjs.map +1 -1
- package/dist/manifest/index.d.cts +130 -131
- package/dist/manifest/index.d.ts +130 -131
- package/dist/manifest/index.js +219 -7
- package/dist/manifest/index.js.map +1 -1
- package/dist/modules/index.cjs +281 -42
- package/dist/modules/index.cjs.map +1 -1
- package/dist/modules/index.d.cts +157 -159
- package/dist/modules/index.d.ts +157 -159
- package/dist/modules/index.js +274 -6
- package/dist/modules/index.js.map +1 -1
- package/dist/objects/index.cjs +355 -22
- package/dist/objects/index.cjs.map +1 -1
- package/dist/objects/index.d.cts +2 -77
- package/dist/objects/index.d.ts +2 -77
- package/dist/objects/index.js +352 -2
- package/dist/objects/index.js.map +1 -1
- package/dist/policies/index.cjs +14 -56
- package/dist/policies/index.d.cts +2 -261
- package/dist/policies/index.d.ts +2 -261
- package/dist/policies/index.js +1 -3
- package/dist/policies-DH_GCXQ-.js +627 -0
- package/dist/policies-DH_GCXQ-.js.map +1 -0
- package/dist/policies-Nxbp1CH8.cjs +698 -0
- package/dist/policies-Nxbp1CH8.cjs.map +1 -0
- package/dist/privacy/index.cjs +26 -43
- package/dist/privacy/index.cjs.map +1 -1
- package/dist/privacy/index.d.cts +2 -189
- package/dist/privacy/index.d.ts +2 -189
- package/dist/privacy/index.js +18 -3
- package/dist/privacy/index.js.map +1 -1
- package/dist/projections/index.cjs +241 -23
- package/dist/projections/index.cjs.map +1 -1
- package/dist/projections/index.d.cts +2 -125
- package/dist/projections/index.d.ts +2 -125
- package/dist/projections/index.js +238 -3
- package/dist/projections/index.js.map +1 -1
- package/dist/state-machines/index.cjs +76 -18
- package/dist/state-machines/index.cjs.map +1 -1
- package/dist/state-machines/index.d.cts +2 -55
- package/dist/state-machines/index.d.ts +2 -55
- package/dist/state-machines/index.js +74 -2
- package/dist/state-machines/index.js.map +1 -1
- package/dist/testing/index.cjs +27 -19
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +17 -19
- package/dist/testing/index.d.ts +17 -19
- package/dist/testing/index.js +25 -3
- package/dist/testing/index.js.map +1 -1
- package/package.json +6 -5
- package/dist/chunk-2AE6TMAX.cjs +0 -44
- package/dist/chunk-2AE6TMAX.cjs.map +0 -1
- package/dist/chunk-6HY35TKB.cjs +0 -491
- package/dist/chunk-6HY35TKB.cjs.map +0 -1
- package/dist/chunk-6UGEIDLC.cjs +0 -26
- package/dist/chunk-6UGEIDLC.cjs.map +0 -1
- package/dist/chunk-7GAWSUOG.js +0 -64
- package/dist/chunk-7GAWSUOG.js.map +0 -1
- package/dist/chunk-A42JJIPL.cjs +0 -699
- package/dist/chunk-A42JJIPL.cjs.map +0 -1
- package/dist/chunk-AFXKSIVI.cjs +0 -540
- package/dist/chunk-AFXKSIVI.cjs.map +0 -1
- package/dist/chunk-B5DOGDPG.js +0 -42
- package/dist/chunk-B5DOGDPG.js.map +0 -1
- package/dist/chunk-BJGZE3GE.js +0 -20
- package/dist/chunk-BJGZE3GE.js.map +0 -1
- package/dist/chunk-CRZXTZ36.cjs +0 -258
- package/dist/chunk-CRZXTZ36.cjs.map +0 -1
- package/dist/chunk-D4SWRBUH.cjs +0 -22
- package/dist/chunk-D4SWRBUH.cjs.map +0 -1
- package/dist/chunk-DBTAUI6C.cjs +0 -395
- package/dist/chunk-DBTAUI6C.cjs.map +0 -1
- package/dist/chunk-EMSAFNPX.js +0 -98
- package/dist/chunk-EMSAFNPX.js.map +0 -1
- package/dist/chunk-F3E5SXPN.cjs +0 -28
- package/dist/chunk-F3E5SXPN.cjs.map +0 -1
- package/dist/chunk-HEYMMVDP.js +0 -480
- package/dist/chunk-HEYMMVDP.js.map +0 -1
- package/dist/chunk-IFW43ELT.cjs +0 -331
- package/dist/chunk-IFW43ELT.cjs.map +0 -1
- package/dist/chunk-LFE74IJX.js +0 -20
- package/dist/chunk-LFE74IJX.js.map +0 -1
- package/dist/chunk-LZSE6QGQ.cjs +0 -60
- package/dist/chunk-LZSE6QGQ.cjs.map +0 -1
- package/dist/chunk-MCWSUGB3.cjs +0 -102
- package/dist/chunk-MCWSUGB3.cjs.map +0 -1
- package/dist/chunk-MLBALEUR.js +0 -290
- package/dist/chunk-MLBALEUR.js.map +0 -1
- package/dist/chunk-NNXQZPB3.cjs +0 -31
- package/dist/chunk-NNXQZPB3.cjs.map +0 -1
- package/dist/chunk-OFCCZ27Z.js +0 -26
- package/dist/chunk-OFCCZ27Z.js.map +0 -1
- package/dist/chunk-PDN5DOLQ.js +0 -242
- package/dist/chunk-PDN5DOLQ.js.map +0 -1
- package/dist/chunk-PIDZQAEL.js +0 -50
- package/dist/chunk-PIDZQAEL.js.map +0 -1
- package/dist/chunk-PXD7NG6X.js +0 -686
- package/dist/chunk-PXD7NG6X.js.map +0 -1
- package/dist/chunk-Q4Q4JPR3.js +0 -524
- package/dist/chunk-Q4Q4JPR3.js.map +0 -1
- package/dist/chunk-RALMUSOX.js +0 -55
- package/dist/chunk-RALMUSOX.js.map +0 -1
- package/dist/chunk-SNTV45LH.cjs +0 -295
- package/dist/chunk-SNTV45LH.cjs.map +0 -1
- package/dist/chunk-TBS2S5AX.cjs +0 -40
- package/dist/chunk-TBS2S5AX.cjs.map +0 -1
- package/dist/chunk-TYNIFC7J.js +0 -253
- package/dist/chunk-TYNIFC7J.js.map +0 -1
- package/dist/chunk-UGWGHTNC.cjs +0 -56
- package/dist/chunk-UGWGHTNC.cjs.map +0 -1
- package/dist/chunk-WI7CWNYI.cjs +0 -68
- package/dist/chunk-WI7CWNYI.cjs.map +0 -1
- package/dist/chunk-WNZP53GI.js +0 -386
- package/dist/chunk-WNZP53GI.js.map +0 -1
- package/dist/chunk-WQ3BYI7T.cjs +0 -249
- package/dist/chunk-WQ3BYI7T.cjs.map +0 -1
- package/dist/chunk-Y2PJLRIY.js +0 -36
- package/dist/chunk-Y2PJLRIY.js.map +0 -1
- package/dist/chunk-ZAEVQSB5.js +0 -326
- package/dist/chunk-ZAEVQSB5.js.map +0 -1
- package/dist/chunk-ZMQTV5OJ.js +0 -27
- package/dist/chunk-ZMQTV5OJ.js.map +0 -1
- package/dist/evidence/index.cjs.map +0 -1
- package/dist/evidence/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/policies/index.cjs.map +0 -1
- package/dist/policies/index.js.map +0 -1
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region adapters/circuit-breaker.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* State of an adapter circuit breaker.
|
|
3
4
|
*
|
|
@@ -7,7 +8,7 @@
|
|
|
7
8
|
* - `half_open`: the cooldown elapsed. One probe call is admitted; its outcome
|
|
8
9
|
* closes the breaker (success) or reopens it (failure).
|
|
9
10
|
*/
|
|
10
|
-
type AdapterCircuitState = "closed" | "open" | "half_open";
|
|
11
|
+
export type AdapterCircuitState = "closed" | "open" | "half_open";
|
|
11
12
|
/**
|
|
12
13
|
* How a single adapter outcome counts toward the breaker.
|
|
13
14
|
*
|
|
@@ -17,7 +18,7 @@ type AdapterCircuitState = "closed" | "open" | "half_open";
|
|
|
17
18
|
* (a validation or business rejection). It is neither a success nor a
|
|
18
19
|
* dependency failure and does not enter the rolling window.
|
|
19
20
|
*/
|
|
20
|
-
type AdapterCircuitOutcome = "success" | "failure" | "ignored";
|
|
21
|
+
export type AdapterCircuitOutcome = "success" | "failure" | "ignored";
|
|
21
22
|
/**
|
|
22
23
|
* Map an {@link AdapterOutcomeKind} to how it counts toward a circuit breaker.
|
|
23
24
|
*
|
|
@@ -37,90 +38,90 @@ type AdapterCircuitOutcome = "success" | "failure" | "ignored";
|
|
|
37
38
|
* `classifyThrownError` (default `transient_failure`) and maps that kind here,
|
|
38
39
|
* so an unclassified thrown error counts as a failure.
|
|
39
40
|
*/
|
|
40
|
-
declare function classifyCircuitBreakerOutcome(kind: AdapterOutcomeKind): AdapterCircuitOutcome;
|
|
41
|
+
export declare function classifyCircuitBreakerOutcome(kind: AdapterOutcomeKind): AdapterCircuitOutcome;
|
|
41
42
|
/** The answer a breaker gives before a call. */
|
|
42
|
-
interface AdapterCircuitAdmission {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
43
|
+
export interface AdapterCircuitAdmission {
|
|
44
|
+
/**
|
|
45
|
+
* Whether the call may proceed. Always `true` in `monitor` mode; `false`
|
|
46
|
+
* only in `enforce` mode while the breaker is open, forced open, or
|
|
47
|
+
* half-open with its probe already in flight.
|
|
48
|
+
*/
|
|
49
|
+
allowed: boolean;
|
|
50
|
+
/** State at the time of the decision. */
|
|
51
|
+
state: AdapterCircuitState;
|
|
52
|
+
/** True when this admission is the half-open probe. Pass it back to `record`. */
|
|
53
|
+
probe: boolean;
|
|
54
|
+
/** Monitor mode only: true when `enforce` mode would have rejected this call. */
|
|
55
|
+
wouldReject?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Milliseconds until the breaker will admit a probe, when known. Absent while
|
|
58
|
+
* a manual `force_open` override is set or a half-open probe is in flight.
|
|
59
|
+
*/
|
|
60
|
+
retryAfterMs?: number;
|
|
61
|
+
/** Set when a manual override decided the admission. */
|
|
62
|
+
manualOverride?: AdapterCircuitBreakerManualOverride;
|
|
63
|
+
/**
|
|
64
|
+
* The breaker epoch the admission was granted in; opaque to callers.
|
|
65
|
+
* {@link InMemoryAdapterCircuitBreaker} lets an outcome change state only
|
|
66
|
+
* when this still matches its current epoch. An admission without it is
|
|
67
|
+
* treated as current.
|
|
68
|
+
*/
|
|
69
|
+
generation?: number;
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
72
|
* Contract between a circuit breaker and `executeWithAdapterRetry`.
|
|
72
73
|
* Implement it to plug in a shared or distributed breaker.
|
|
73
74
|
*/
|
|
74
|
-
interface AdapterCircuitBreaker {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
75
|
+
export interface AdapterCircuitBreaker {
|
|
76
|
+
/** Registry key this breaker guards; defaults to `adapterType:operation`. */
|
|
77
|
+
readonly key: string;
|
|
78
|
+
readonly mode: "monitor" | "enforce";
|
|
79
|
+
/** Current state, applying any elapsed cooldown or manual override. */
|
|
80
|
+
getState(): AdapterCircuitState;
|
|
81
|
+
/**
|
|
82
|
+
* Preview whether a call would be admitted now. Side-effect free: it does
|
|
83
|
+
* not commit an elapsed cooldown, take the half-open probe or emit
|
|
84
|
+
* telemetry.
|
|
85
|
+
*/
|
|
86
|
+
check(): AdapterCircuitAdmission;
|
|
87
|
+
/**
|
|
88
|
+
* Decide whether a call may start now. Call it immediately before the
|
|
89
|
+
* external effect and pass the returned admission to {@link record}.
|
|
90
|
+
*/
|
|
91
|
+
acquire(): AdapterCircuitAdmission;
|
|
92
|
+
/**
|
|
93
|
+
* Record the outcome of a call that was admitted by {@link acquire}. Pass
|
|
94
|
+
* that admission, not a {@link check} preview, so the breaker can tell a
|
|
95
|
+
* stale outcome from a current one.
|
|
96
|
+
*/
|
|
97
|
+
record(outcome: AdapterCircuitOutcome, admission?: AdapterCircuitAdmission): void;
|
|
97
98
|
}
|
|
98
|
-
type AdapterCircuitBreakerEventReason = "failure_threshold" | "cooldown_elapsed" | "probe_succeeded" | "probe_failed" | "manual_override" | "manual_override_cleared";
|
|
99
|
+
export type AdapterCircuitBreakerEventReason = "failure_threshold" | "cooldown_elapsed" | "probe_succeeded" | "probe_failed" | "manual_override" | "manual_override_cleared";
|
|
99
100
|
interface AdapterCircuitBreakerEventBase {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
key: string;
|
|
102
|
+
mode: "monitor" | "enforce";
|
|
103
|
+
/** Epoch milliseconds from the breaker's clock. */
|
|
104
|
+
at: number;
|
|
104
105
|
}
|
|
105
106
|
/** Telemetry reported by {@link InMemoryAdapterCircuitBreaker}. */
|
|
106
|
-
type AdapterCircuitBreakerEvent = (AdapterCircuitBreakerEventBase & {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
export type AdapterCircuitBreakerEvent = (AdapterCircuitBreakerEventBase & {
|
|
108
|
+
type: "state_change";
|
|
109
|
+
from: AdapterCircuitState;
|
|
110
|
+
to: AdapterCircuitState;
|
|
111
|
+
reason: AdapterCircuitBreakerEventReason;
|
|
112
|
+
manualOverride?: AdapterCircuitBreakerManualOverride;
|
|
112
113
|
}) | (AdapterCircuitBreakerEventBase & {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
/** Enforce mode refused a call; it was not attempted. */
|
|
115
|
+
type: "rejected";
|
|
116
|
+
state: AdapterCircuitState;
|
|
117
|
+
retryAfterMs?: number;
|
|
118
|
+
manualOverride?: AdapterCircuitBreakerManualOverride;
|
|
118
119
|
}) | (AdapterCircuitBreakerEventBase & {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
/** Monitor mode let a call through that enforce mode would have refused. */
|
|
121
|
+
type: "would_reject";
|
|
122
|
+
state: AdapterCircuitState;
|
|
123
|
+
retryAfterMs?: number;
|
|
124
|
+
manualOverride?: AdapterCircuitBreakerManualOverride;
|
|
124
125
|
});
|
|
125
126
|
/**
|
|
126
127
|
* Telemetry callback. Errors it throws and promises it rejects are caught
|
|
@@ -131,14 +132,14 @@ type AdapterCircuitBreakerEvent = (AdapterCircuitBreakerEventBase & {
|
|
|
131
132
|
* record. A callback may call back into the breaker; it sees committed state,
|
|
132
133
|
* and events its own calls produce are delivered after it returns, in order.
|
|
133
134
|
*/
|
|
134
|
-
type AdapterCircuitBreakerEventListener = (event: AdapterCircuitBreakerEvent) => void | Promise<void>;
|
|
135
|
-
interface InMemoryAdapterCircuitBreakerOptions {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
export type AdapterCircuitBreakerEventListener = (event: AdapterCircuitBreakerEvent) => void | Promise<void>;
|
|
136
|
+
export interface InMemoryAdapterCircuitBreakerOptions {
|
|
137
|
+
/** Usually `adapterType:operation`. */
|
|
138
|
+
key: string;
|
|
139
|
+
config: AdapterCircuitBreakerConfig;
|
|
140
|
+
/** Epoch-millisecond clock. Defaults to `Date.now`. */
|
|
141
|
+
now?: () => number;
|
|
142
|
+
onEvent?: AdapterCircuitBreakerEventListener;
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
144
145
|
* Validate a circuit-breaker config. Throws a `RangeError` naming the first
|
|
@@ -147,7 +148,7 @@ interface InMemoryAdapterCircuitBreakerOptions {
|
|
|
147
148
|
* finite numbers; `cooldownMs` a non-negative finite number; `manualOverride`
|
|
148
149
|
* `force_open` or `force_closed` when present.
|
|
149
150
|
*/
|
|
150
|
-
declare function assertAdapterCircuitBreakerConfig(config: AdapterCircuitBreakerConfig): void;
|
|
151
|
+
export declare function assertAdapterCircuitBreakerConfig(config: AdapterCircuitBreakerConfig): void;
|
|
151
152
|
/**
|
|
152
153
|
* Dependency-free, in-process circuit breaker for one adapter operation.
|
|
153
154
|
*
|
|
@@ -211,72 +212,72 @@ declare function assertAdapterCircuitBreakerConfig(config: AdapterCircuitBreaker
|
|
|
211
212
|
* automatic open, `force_open` blocks only in `enforce` mode. Clearing the
|
|
212
213
|
* override returns the breaker to `closed` with its window intact.
|
|
213
214
|
*/
|
|
214
|
-
declare class InMemoryAdapterCircuitBreaker implements AdapterCircuitBreaker {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
215
|
+
export declare class InMemoryAdapterCircuitBreaker implements AdapterCircuitBreaker {
|
|
216
|
+
readonly key: string;
|
|
217
|
+
readonly mode: "monitor" | "enforce";
|
|
218
|
+
private readonly config;
|
|
219
|
+
private readonly now;
|
|
220
|
+
private readonly onEvent;
|
|
221
|
+
private readonly probeLeaseMs;
|
|
222
|
+
private samples;
|
|
223
|
+
private state;
|
|
224
|
+
private openedAt;
|
|
225
|
+
private probeIssuedAt;
|
|
226
|
+
/** Advances on every state change, manual override change and probe grant. */
|
|
227
|
+
private generation;
|
|
228
|
+
private manualOverride;
|
|
229
|
+
/** Telemetry waiting for the current operation to commit. */
|
|
230
|
+
private readonly outbox;
|
|
231
|
+
private operationDepth;
|
|
232
|
+
private flushing;
|
|
233
|
+
constructor(options: InMemoryAdapterCircuitBreakerOptions);
|
|
234
|
+
getState(): AdapterCircuitState;
|
|
235
|
+
getManualOverride(): AdapterCircuitBreakerManualOverride | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* Set (`force_open` / `force_closed`) or clear (`undefined`) the manual
|
|
238
|
+
* override. Clearing returns the breaker to `closed` with its window intact.
|
|
239
|
+
*/
|
|
240
|
+
setManualOverride(override: AdapterCircuitBreakerManualOverride | undefined): void;
|
|
241
|
+
check(): AdapterCircuitAdmission;
|
|
242
|
+
acquire(): AdapterCircuitAdmission;
|
|
243
|
+
record(outcome: AdapterCircuitOutcome, admission?: AdapterCircuitAdmission): void;
|
|
244
|
+
private applyOutcome;
|
|
245
|
+
/**
|
|
246
|
+
* `take` is false for {@link check}: a pure preview that sees an elapsed
|
|
247
|
+
* cooldown without committing it, takes no probe and emits nothing.
|
|
248
|
+
*/
|
|
249
|
+
private decide;
|
|
250
|
+
private refuse;
|
|
251
|
+
private releaseProbe;
|
|
252
|
+
/** Apply the time-based open → half_open transition. */
|
|
253
|
+
private advance;
|
|
254
|
+
private shouldTrip;
|
|
255
|
+
private prune;
|
|
256
|
+
private transition;
|
|
257
|
+
private reportedState;
|
|
258
|
+
/**
|
|
259
|
+
* Commit an elapsed cooldown as an operation of its own, delivering its
|
|
260
|
+
* event before the caller's operation reads state.
|
|
261
|
+
*/
|
|
262
|
+
private settle;
|
|
263
|
+
/**
|
|
264
|
+
* Run `step` to completion, then deliver the telemetry it produced. The
|
|
265
|
+
* return value is fixed before any listener runs.
|
|
266
|
+
*/
|
|
267
|
+
private operation;
|
|
268
|
+
private emit;
|
|
269
|
+
/**
|
|
270
|
+
* Deliver buffered events in order. A listener that calls back into the
|
|
271
|
+
* breaker queues its own events; this loop delivers them after it returns
|
|
272
|
+
* instead of recursing.
|
|
273
|
+
*/
|
|
274
|
+
private flush;
|
|
275
|
+
private deliver;
|
|
275
276
|
}
|
|
276
277
|
/** Trusted invocation context available when selecting an adapter breaker. */
|
|
277
|
-
interface AdapterCircuitBreakerScope {
|
|
278
|
-
|
|
279
|
-
|
|
278
|
+
export interface AdapterCircuitBreakerScope {
|
|
279
|
+
tenantId: string;
|
|
280
|
+
spaceId?: string;
|
|
280
281
|
}
|
|
281
282
|
/**
|
|
282
283
|
* Key by tenant, optional space, vendor, and adapter operation. Components are
|
|
@@ -290,24 +291,24 @@ interface AdapterCircuitBreakerScope {
|
|
|
290
291
|
* adapter type, but its absence is tolerated for JavaScript callers.
|
|
291
292
|
* Keys appear in errors and telemetry: use non-secret identifiers.
|
|
292
293
|
*/
|
|
293
|
-
declare function scopedAdapterCircuitBreakerKey(adapter: AdapterImplementation, scope: AdapterCircuitBreakerScope | undefined): string;
|
|
294
|
+
export declare function scopedAdapterCircuitBreakerKey(adapter: AdapterImplementation, scope: AdapterCircuitBreakerScope | undefined): string;
|
|
294
295
|
/** Supplies the breaker, if any, that guards an adapter in invocation scope. */
|
|
295
|
-
interface AdapterCircuitBreakerProvider {
|
|
296
|
-
|
|
296
|
+
export interface AdapterCircuitBreakerProvider {
|
|
297
|
+
forAdapter(adapter: AdapterImplementation, scope?: AdapterCircuitBreakerScope): AdapterCircuitBreaker | undefined;
|
|
297
298
|
}
|
|
298
|
-
interface AdapterCircuitBreakerRegistryOptions {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
299
|
+
export interface AdapterCircuitBreakerRegistryOptions {
|
|
300
|
+
/**
|
|
301
|
+
* Defaults to `adapterType:operation`, shared across tenants and vendors in
|
|
302
|
+
* this registry. Use {@link scopedAdapterCircuitBreakerKey} for tenant,
|
|
303
|
+
* space, and vendor isolation. The first config seen for a key wins;
|
|
304
|
+
* later conflicting configs reuse that breaker without throwing. Breakers
|
|
305
|
+
* are never evicted, and scoped keys are high-cardinality: avoid them as
|
|
306
|
+
* metric labels.
|
|
307
|
+
*/
|
|
308
|
+
key?: (adapter: AdapterImplementation, scope: AdapterCircuitBreakerScope | undefined) => string;
|
|
309
|
+
/** Epoch-millisecond clock handed to every breaker. Defaults to `Date.now`. */
|
|
310
|
+
now?: () => number;
|
|
311
|
+
onEvent?: AdapterCircuitBreakerEventListener;
|
|
311
312
|
}
|
|
312
313
|
/**
|
|
313
314
|
* Lazily creates one {@link InMemoryAdapterCircuitBreaker} per
|
|
@@ -318,70 +319,71 @@ interface AdapterCircuitBreakerRegistryOptions {
|
|
|
318
319
|
* wins; later conflicting configs reuse the existing breaker without throwing.
|
|
319
320
|
* Share a key only between adapters intended to use the same configuration.
|
|
320
321
|
*/
|
|
321
|
-
declare class AdapterCircuitBreakerRegistry implements AdapterCircuitBreakerProvider {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
322
|
+
export declare class AdapterCircuitBreakerRegistry implements AdapterCircuitBreakerProvider {
|
|
323
|
+
private readonly options;
|
|
324
|
+
private readonly breakers;
|
|
325
|
+
constructor(options?: AdapterCircuitBreakerRegistryOptions);
|
|
326
|
+
forAdapter(adapter: AdapterImplementation, scope?: AdapterCircuitBreakerScope): InMemoryAdapterCircuitBreaker | undefined;
|
|
327
|
+
/** Looks up the default `adapterType:operation` key without creating a breaker. */
|
|
328
|
+
get(adapterType: string, operation: string): InMemoryAdapterCircuitBreaker | undefined;
|
|
329
|
+
/** Looks up an exact key, including a custom key, without creating a breaker. */
|
|
330
|
+
getByKey(key: string): InMemoryAdapterCircuitBreaker | undefined;
|
|
330
331
|
}
|
|
331
332
|
/**
|
|
332
333
|
* Thrown by `executeWithAdapterRetry` when an `enforce`-mode breaker refuses
|
|
333
334
|
* an attempt. The refused attempt never reached `execute`, so no external
|
|
334
335
|
* effect happened for it.
|
|
335
336
|
*/
|
|
336
|
-
declare class AdapterCircuitOpenError extends Error {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
337
|
+
export declare class AdapterCircuitOpenError extends Error {
|
|
338
|
+
readonly name = "AdapterCircuitOpenError";
|
|
339
|
+
readonly code: "ADAPTER_CIRCUIT_OPEN";
|
|
340
|
+
readonly reason: "circuit_open";
|
|
341
|
+
readonly adapterKey: string;
|
|
342
|
+
readonly state: AdapterCircuitState;
|
|
343
|
+
/** The attempt number that was refused (1 = refused before any call). */
|
|
344
|
+
readonly attempt: number;
|
|
345
|
+
readonly retryAfterMs?: number;
|
|
346
|
+
readonly manualOverride?: AdapterCircuitBreakerManualOverride;
|
|
347
|
+
/** Error of the previous attempt, when the breaker opened mid-retry. */
|
|
348
|
+
readonly lastError?: string;
|
|
349
|
+
constructor(input: {
|
|
350
|
+
adapterKey: string;
|
|
351
|
+
state: AdapterCircuitState;
|
|
352
|
+
attempt: number;
|
|
353
|
+
retryAfterMs?: number;
|
|
354
|
+
manualOverride?: AdapterCircuitBreakerManualOverride;
|
|
355
|
+
lastError?: string;
|
|
356
|
+
});
|
|
356
357
|
}
|
|
357
358
|
/**
|
|
358
359
|
* Recognise an {@link AdapterCircuitOpenError}, including one constructed by a
|
|
359
360
|
* second copy of this package (for example an ESM and a CommonJS build loaded
|
|
360
361
|
* side by side), where `instanceof` fails.
|
|
361
362
|
*/
|
|
362
|
-
declare function isAdapterCircuitOpenError(error: unknown): error is AdapterCircuitOpenError;
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
363
|
+
export declare function isAdapterCircuitOpenError(error: unknown): error is AdapterCircuitOpenError;
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region adapters/index.d.ts
|
|
366
|
+
export interface AdapterExecutionContext {
|
|
367
|
+
tenantId: string;
|
|
368
|
+
spaceId: string;
|
|
369
|
+
actionInvocationId: string;
|
|
370
|
+
adapterInvocationId: string;
|
|
371
|
+
correlationId: string;
|
|
372
|
+
causationId?: string;
|
|
373
|
+
attempt: number;
|
|
374
|
+
maxAttempts: number;
|
|
375
|
+
/** Epoch-millis deadline after which the adapter should abandon the call. */
|
|
376
|
+
deadlineMs?: number;
|
|
377
|
+
/** Set by the host when the invocation has been cancelled; adapters should stop work. */
|
|
378
|
+
cancelled?: boolean;
|
|
379
|
+
/** Non-secret reason the invocation was cancelled. */
|
|
380
|
+
cancellationReason?: string;
|
|
381
|
+
/**
|
|
382
|
+
* AbortSignal the host aborts when the deadline expires or the invocation is
|
|
383
|
+
* cancelled. Adapters should propagate this to underlying HTTP/database
|
|
384
|
+
* clients so in-flight work is abandoned rather than left dangling.
|
|
385
|
+
*/
|
|
386
|
+
signal?: AbortSignal;
|
|
385
387
|
}
|
|
386
388
|
/**
|
|
387
389
|
* Additive classification of an adapter outcome so the retry layer can
|
|
@@ -392,20 +394,20 @@ interface AdapterExecutionContext {
|
|
|
392
394
|
* layer treats a non-success result as `transient_failure` for backward
|
|
393
395
|
* compatibility.
|
|
394
396
|
*/
|
|
395
|
-
type AdapterOutcomeKind = "success" | "transient_failure" | "permanent_failure" | "timeout" | "ambiguous";
|
|
397
|
+
export type AdapterOutcomeKind = "success" | "transient_failure" | "permanent_failure" | "timeout" | "ambiguous";
|
|
396
398
|
/**
|
|
397
399
|
* Durable, non-secret evidence attached to a classified adapter outcome.
|
|
398
400
|
* Used by the host to record reconciliation evidence when an adapter returns
|
|
399
401
|
* an ambiguous result whose external effect may or may not have been applied.
|
|
400
402
|
*/
|
|
401
|
-
interface AdapterOutcomeEvidence {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
403
|
+
export interface AdapterOutcomeEvidence {
|
|
404
|
+
kind: AdapterOutcomeKind;
|
|
405
|
+
reason?: string;
|
|
406
|
+
/** Opaque, non-secret reference to external operation state for reconciliation. */
|
|
407
|
+
externalReference?: string;
|
|
408
|
+
/** Whether the external effect may have been applied (true for ambiguous/timeout). */
|
|
409
|
+
effectMayHaveApplied?: boolean;
|
|
410
|
+
observedAt: Date | string;
|
|
409
411
|
}
|
|
410
412
|
/**
|
|
411
413
|
* An adapter handed the work to an external system that will finish it later.
|
|
@@ -415,45 +417,45 @@ interface AdapterOutcomeEvidence {
|
|
|
415
417
|
* in someone else's hands. The host keeps the invocation running and expects a
|
|
416
418
|
* completion carrying this reference through its completion ingress.
|
|
417
419
|
*/
|
|
418
|
-
interface AcceptedExternalOperation {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
export interface AcceptedExternalOperation {
|
|
421
|
+
/** Opaque, non-secret reference the external system will complete by. */
|
|
422
|
+
externalReference: string;
|
|
423
|
+
/** When the external system said it expects to finish, if it said. */
|
|
424
|
+
expectedBy?: Date | string;
|
|
423
425
|
}
|
|
424
|
-
interface AdapterExecutionResult {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
426
|
+
export interface AdapterExecutionResult {
|
|
427
|
+
success: boolean;
|
|
428
|
+
correlationId?: string;
|
|
429
|
+
error?: string;
|
|
430
|
+
/** Additive outcome classification. Omitted = infer from `success`. */
|
|
431
|
+
outcome?: AdapterOutcomeKind;
|
|
432
|
+
/** Durable evidence for ambiguous or timeout outcomes requiring reconciliation. */
|
|
433
|
+
outcomeEvidence?: AdapterOutcomeEvidence;
|
|
434
|
+
/** Present when a successful call handed the work off to finish elsewhere. */
|
|
435
|
+
acceptedExternalOperation?: AcceptedExternalOperation;
|
|
434
436
|
}
|
|
435
|
-
type AdapterExecutor = (input: Record<string, unknown>, context: AdapterExecutionContext) => Promise<AdapterExecutionResult>;
|
|
436
|
-
interface AdapterRetryPolicy {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
437
|
+
export type AdapterExecutor = (input: Record<string, unknown>, context: AdapterExecutionContext) => Promise<AdapterExecutionResult>;
|
|
438
|
+
export interface AdapterRetryPolicy {
|
|
439
|
+
/** External calls must explicitly opt into retry by being idempotent. */
|
|
440
|
+
idempotent: boolean;
|
|
441
|
+
/** Total attempts including the first call. Non-idempotent policies are forced to 1. */
|
|
442
|
+
maxAttempts?: number;
|
|
443
|
+
/** First backoff delay in milliseconds. */
|
|
444
|
+
initialDelayMs?: number;
|
|
445
|
+
/** Exponential multiplier applied after each failed attempt. */
|
|
446
|
+
backoffMultiplier?: number;
|
|
447
|
+
/** Upper bound for any single retry delay in milliseconds. */
|
|
448
|
+
maxDelayMs?: number;
|
|
447
449
|
}
|
|
448
|
-
interface ResolvedAdapterRetryPolicy {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
450
|
+
export interface ResolvedAdapterRetryPolicy {
|
|
451
|
+
idempotent: boolean;
|
|
452
|
+
maxAttempts: number;
|
|
453
|
+
initialDelayMs: number;
|
|
454
|
+
backoffMultiplier: number;
|
|
455
|
+
maxDelayMs: number;
|
|
454
456
|
}
|
|
455
457
|
/** Manual circuit-breaker override: pin the breaker open or closed. */
|
|
456
|
-
type AdapterCircuitBreakerManualOverride = "force_open" | "force_closed";
|
|
458
|
+
export type AdapterCircuitBreakerManualOverride = "force_open" | "force_closed";
|
|
457
459
|
/**
|
|
458
460
|
* Per-adapter circuit-breaker configuration, read by
|
|
459
461
|
* {@link AdapterCircuitBreakerRegistry} (and so by Platform Host) to create one
|
|
@@ -461,113 +463,113 @@ type AdapterCircuitBreakerManualOverride = "force_open" | "force_closed";
|
|
|
461
463
|
* `adapterType:operation`; configurable through the registry `key` option).
|
|
462
464
|
* Validated by {@link assertAdapterCircuitBreakerConfig}.
|
|
463
465
|
*/
|
|
464
|
-
interface AdapterCircuitBreakerConfig {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
466
|
+
export interface AdapterCircuitBreakerConfig {
|
|
467
|
+
/**
|
|
468
|
+
* `monitor` records outcomes, runs the state machine and reports what it
|
|
469
|
+
* would have refused, but never blocks a call. `enforce` refuses calls
|
|
470
|
+
* while the breaker is open, without attempting them.
|
|
471
|
+
*/
|
|
472
|
+
mode: "monitor" | "enforce";
|
|
473
|
+
/**
|
|
474
|
+
* A failure count. Let `M = minimumSamples ?? failureThreshold`. Once at
|
|
475
|
+
* least `M` outcomes fall within `windowMs`, the breaker opens when the most
|
|
476
|
+
* recent `failureThreshold` of them are all failures, or when the failure
|
|
477
|
+
* ratio in the window reaches `failureThreshold / M`. Without
|
|
478
|
+
* `minimumSamples` this is "`failureThreshold` consecutive failures".
|
|
479
|
+
* Matches the .NET port's `InMemoryAdapterCircuitBreaker`. Positive integer.
|
|
480
|
+
*/
|
|
481
|
+
failureThreshold: number;
|
|
482
|
+
/** Rolling window, in milliseconds, of outcomes the thresholds consider. */
|
|
483
|
+
windowMs: number;
|
|
484
|
+
/** Milliseconds an open breaker waits before admitting one half-open probe. */
|
|
485
|
+
cooldownMs: number;
|
|
486
|
+
/** Outcomes required in the window before the breaker can open. Defaults to `failureThreshold`. */
|
|
487
|
+
minimumSamples?: number;
|
|
488
|
+
/**
|
|
489
|
+
* How long, in milliseconds, the single half-open probe holds its slot
|
|
490
|
+
* before it is presumed lost and another call may probe. Defaults to
|
|
491
|
+
* `max(cooldownMs, windowMs)`; it is independent of `cooldownMs`, so a zero
|
|
492
|
+
* or short cooldown never admits concurrent probes. Positive.
|
|
493
|
+
*/
|
|
494
|
+
probeLeaseMs?: number;
|
|
495
|
+
/**
|
|
496
|
+
* Optional initial manual override. `force_open` reports `open` (and blocks
|
|
497
|
+
* only in `enforce` mode); `force_closed` reports `closed` and never blocks.
|
|
498
|
+
* Change it at runtime with `InMemoryAdapterCircuitBreaker.setManualOverride`.
|
|
499
|
+
*/
|
|
500
|
+
manualOverride?: AdapterCircuitBreakerManualOverride;
|
|
499
501
|
}
|
|
500
|
-
interface AdapterImplementation {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
502
|
+
export interface AdapterImplementation {
|
|
503
|
+
adapterType: string;
|
|
504
|
+
operation: string;
|
|
505
|
+
vendor: string;
|
|
506
|
+
/** Whether this adapter operation can be safely retried by default. */
|
|
507
|
+
idempotent: boolean;
|
|
508
|
+
retryPolicy?: AdapterRetryPolicy;
|
|
509
|
+
/** Defaults to monitor-only; enforce mode must be explicitly configured. */
|
|
510
|
+
circuitBreaker?: AdapterCircuitBreakerConfig;
|
|
511
|
+
execute: AdapterExecutor;
|
|
510
512
|
}
|
|
511
|
-
interface AdapterAttempt<T> {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
513
|
+
export interface AdapterAttempt<T> {
|
|
514
|
+
attempt: number;
|
|
515
|
+
result?: T;
|
|
516
|
+
error?: string;
|
|
517
|
+
willRetry: boolean;
|
|
518
|
+
nextDelayMs?: number;
|
|
517
519
|
}
|
|
518
|
-
interface ExecuteWithRetryOptions<T> {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
520
|
+
export interface ExecuteWithRetryOptions<T> {
|
|
521
|
+
policy?: AdapterRetryPolicy;
|
|
522
|
+
defaultIdempotent: boolean;
|
|
523
|
+
execute: (attempt: number, maxAttempts: number) => Promise<T>;
|
|
524
|
+
isSuccessful: (result: T) => boolean;
|
|
525
|
+
getError: (result: T) => string | undefined;
|
|
526
|
+
/**
|
|
527
|
+
* Optional outcome classifier. When provided, the retry layer retries only
|
|
528
|
+
* `transient_failure` outcomes (and only when the policy is idempotent).
|
|
529
|
+
* `permanent_failure`, `timeout`, and `ambiguous` outcomes are never retried.
|
|
530
|
+
* When omitted, all non-success results are treated as transient (backward compatible).
|
|
531
|
+
*/
|
|
532
|
+
classifyOutcome?: (result: T) => AdapterOutcomeKind;
|
|
533
|
+
/**
|
|
534
|
+
* Optional classifier for errors thrown by the execute callback (not returned
|
|
535
|
+
* as results). When provided, the retry layer retries only `transient_failure`
|
|
536
|
+
* classifications. When omitted, thrown errors are never retried — the caller
|
|
537
|
+
* must explicitly opt into retrying a thrown failure by classifying it.
|
|
538
|
+
*/
|
|
539
|
+
classifyThrownError?: (error: unknown) => AdapterOutcomeKind;
|
|
540
|
+
sleep?: (delayMs: number) => Promise<void>;
|
|
541
|
+
onAttempt?: (attempt: AdapterAttempt<T>) => Promise<void> | void;
|
|
542
|
+
/**
|
|
543
|
+
* Optional per-attempt preparation, awaited before the circuit breaker is
|
|
544
|
+
* consulted and before `execute` (for example, persisting the attempt
|
|
545
|
+
* number). Put every await a caller needs before the call here, so that
|
|
546
|
+
* nothing awaits between breaker admission and the external call. If it
|
|
547
|
+
* throws, no admission is taken and no breaker outcome is recorded; the
|
|
548
|
+
* error is classified with `classifyThrownError` and retried or rethrown
|
|
549
|
+
* exactly like an error thrown by `execute`.
|
|
550
|
+
*/
|
|
551
|
+
prepareAttempt?: (attempt: number, maxAttempts: number) => Promise<void> | void;
|
|
552
|
+
/**
|
|
553
|
+
* Optional circuit breaker. When present, `acquire()` is called
|
|
554
|
+
* immediately before every `execute` call, with no await in between, and every attempt's outcome is
|
|
555
|
+
* recorded through {@link classifyCircuitBreakerOutcome}. In `enforce` mode
|
|
556
|
+
* a refused attempt is not executed and {@link AdapterCircuitOpenError} is
|
|
557
|
+
* thrown; if the breaker opens between attempts, retrying stops and the
|
|
558
|
+
* same error is thrown. When omitted, behaviour is unchanged.
|
|
559
|
+
*/
|
|
560
|
+
circuitBreaker?: AdapterCircuitBreaker;
|
|
559
561
|
}
|
|
560
|
-
declare class MissingAdapterRegistrationError extends Error {
|
|
561
|
-
|
|
562
|
+
export declare class MissingAdapterRegistrationError extends Error {
|
|
563
|
+
constructor(adapterType: string, operation: string);
|
|
562
564
|
}
|
|
563
|
-
declare class AdapterRegistry {
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
565
|
+
export declare class AdapterRegistry {
|
|
566
|
+
private readonly adapters;
|
|
567
|
+
register(adapter: AdapterImplementation): void;
|
|
568
|
+
resolve(adapterType: string, operation: string): AdapterImplementation | undefined;
|
|
569
|
+
require(adapterType: string, operation: string): AdapterImplementation;
|
|
568
570
|
}
|
|
569
|
-
declare function resolveAdapterRetryPolicy(policy: AdapterRetryPolicy | undefined, defaultIdempotent: boolean): ResolvedAdapterRetryPolicy;
|
|
570
|
-
declare function getRetryDelayMs(attempt: number, policy: ResolvedAdapterRetryPolicy): number;
|
|
571
|
+
export declare function resolveAdapterRetryPolicy(policy: AdapterRetryPolicy | undefined, defaultIdempotent: boolean): ResolvedAdapterRetryPolicy;
|
|
572
|
+
export declare function getRetryDelayMs(attempt: number, policy: ResolvedAdapterRetryPolicy): number;
|
|
571
573
|
/**
|
|
572
574
|
* Classify an {@link AdapterExecutionResult} into an {@link AdapterOutcomeKind}.
|
|
573
575
|
* When `outcome` is explicitly set, it is returned directly, after rejecting a
|
|
@@ -575,20 +577,20 @@ declare function getRetryDelayMs(attempt: number, policy: ResolvedAdapterRetryPo
|
|
|
575
577
|
* Otherwise a successful result maps to `success` and a failed result maps to
|
|
576
578
|
* `transient_failure` (the historical default).
|
|
577
579
|
*/
|
|
578
|
-
declare function classifyAdapterOutcome(result: AdapterExecutionResult): AdapterOutcomeKind;
|
|
580
|
+
export declare function classifyAdapterOutcome(result: AdapterExecutionResult): AdapterOutcomeKind;
|
|
579
581
|
/**
|
|
580
582
|
* Determine whether an outcome kind is retryable. Only `transient_failure`
|
|
581
583
|
* is retryable, and only when the adapter policy is idempotent. Permanent
|
|
582
584
|
* failures, timeouts, and ambiguous outcomes are never retried.
|
|
583
585
|
*/
|
|
584
|
-
declare function shouldRetryAdapterOutcome(kind: AdapterOutcomeKind, idempotent: boolean): boolean;
|
|
586
|
+
export declare function shouldRetryAdapterOutcome(kind: AdapterOutcomeKind, idempotent: boolean): boolean;
|
|
585
587
|
/**
|
|
586
588
|
* Reject a contradictory adapter result where `success` is true but the
|
|
587
589
|
* explicit `outcome` is a non-success kind. A successful result claiming an
|
|
588
590
|
* ambiguous, permanent, timeout, or transient outcome is a programming
|
|
589
591
|
* error — the adapter cannot have both succeeded and require reconciliation.
|
|
590
592
|
*/
|
|
591
|
-
declare function assertAdapterOutcomeConsistency(result: AdapterExecutionResult): void;
|
|
592
|
-
declare function executeWithAdapterRetry<T>(options: ExecuteWithRetryOptions<T>): Promise<T>;
|
|
593
|
-
|
|
594
|
-
export {
|
|
593
|
+
export declare function assertAdapterOutcomeConsistency(result: AdapterExecutionResult): void;
|
|
594
|
+
export declare function executeWithAdapterRetry<T>(options: ExecuteWithRetryOptions<T>): Promise<T>;
|
|
595
|
+
//#endregion
|
|
596
|
+
export {};
|