@procedures/client 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/README.md +61 -38
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters/http/client/transport.d.ts.map +1 -1
- package/dist/adapters/http/client/transport.js +35 -3
- package/dist/adapters/http/client/transport.js.map +1 -1
- package/dist/adapters/http/client/types.d.ts +3 -2
- package/dist/adapters/http/client/types.d.ts.map +1 -1
- package/dist/adapters/http/server/transport.d.ts +2 -2
- package/dist/adapters/http/server/transport.d.ts.map +1 -1
- package/dist/adapters/http/server/transport.js +53 -20
- package/dist/adapters/http/server/transport.js.map +1 -1
- package/dist/adapters/http/shared/headers.d.ts +1 -1
- package/dist/adapters/http/shared/headers.d.ts.map +1 -1
- package/dist/adapters/http/shared/headers.js +7 -6
- package/dist/adapters/http/shared/headers.js.map +1 -1
- package/dist/adapters/local/client/transport.d.ts +3 -0
- package/dist/adapters/local/client/transport.d.ts.map +1 -1
- package/dist/adapters/local/client/transport.js +63 -4
- package/dist/adapters/local/client/transport.js.map +1 -1
- package/dist/adapters/local/client/types.d.ts +15 -0
- package/dist/adapters/local/client/types.d.ts.map +1 -1
- package/dist/adapters/local/client/types.js.map +1 -1
- package/dist/adapters/mock/client/transport.d.ts +3 -2
- package/dist/adapters/mock/client/transport.d.ts.map +1 -1
- package/dist/adapters/mock/client/transport.js +8 -5
- package/dist/adapters/mock/client/transport.js.map +1 -1
- package/dist/adapters/mock/client/types.d.ts +7 -6
- package/dist/adapters/mock/client/types.d.ts.map +1 -1
- package/dist/adapters/port/transport.d.ts +62 -0
- package/dist/adapters/port/transport.d.ts.map +1 -0
- package/dist/adapters/port/transport.js +94 -0
- package/dist/adapters/port/transport.js.map +1 -0
- package/dist/adapters/websocket/client/index.d.ts +1 -1
- package/dist/adapters/websocket/client/index.d.ts.map +1 -1
- package/dist/adapters/websocket/client/index.js.map +1 -1
- package/dist/adapters/websocket/client/transport.d.ts +47 -7
- package/dist/adapters/websocket/client/transport.d.ts.map +1 -1
- package/dist/adapters/websocket/client/transport.js +213 -67
- package/dist/adapters/websocket/client/transport.js.map +1 -1
- package/dist/adapters/websocket/client/types.d.ts +70 -21
- package/dist/adapters/websocket/client/types.d.ts.map +1 -1
- package/dist/adapters/websocket/client/types.js.map +1 -1
- package/dist/adapters/websocket/server/transport.d.ts +65 -24
- package/dist/adapters/websocket/server/transport.d.ts.map +1 -1
- package/dist/adapters/websocket/server/transport.js +192 -263
- package/dist/adapters/websocket/server/transport.js.map +1 -1
- package/dist/adapters/websocket/server/types.d.ts +20 -1
- package/dist/adapters/websocket/server/types.d.ts.map +1 -1
- package/dist/adapters/websocket/shared/rpc.d.ts +129 -0
- package/dist/adapters/websocket/shared/rpc.d.ts.map +1 -0
- package/dist/adapters/websocket/shared/rpc.js +425 -0
- package/dist/adapters/websocket/shared/rpc.js.map +1 -0
- package/dist/browser.d.ts +29 -7
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +26 -3
- package/dist/browser.js.map +1 -1
- package/dist/client/call-types.d.ts +10 -10
- package/dist/client/call-types.d.ts.map +1 -1
- package/dist/client/call-types.js +1 -6
- package/dist/client/call-types.js.map +1 -1
- package/dist/client/client.d.ts +6 -1
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +23 -9
- package/dist/client/client.js.map +1 -1
- package/dist/client/deadline.d.ts +38 -0
- package/dist/client/deadline.d.ts.map +1 -0
- package/dist/client/deadline.js +60 -0
- package/dist/client/deadline.js.map +1 -0
- package/dist/client/errors/factory.d.ts.map +1 -1
- package/dist/client/errors/factory.js +11 -7
- package/dist/client/errors/factory.js.map +1 -1
- package/dist/client/index.d.ts +9 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +8 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/middleware/cache.d.ts +19 -5
- package/dist/client/middleware/cache.d.ts.map +1 -1
- package/dist/client/middleware/cache.js +106 -18
- package/dist/client/middleware/cache.js.map +1 -1
- package/dist/client/middleware/circuit-breaker.d.ts +28 -10
- package/dist/client/middleware/circuit-breaker.d.ts.map +1 -1
- package/dist/client/middleware/circuit-breaker.js +35 -24
- package/dist/client/middleware/circuit-breaker.js.map +1 -1
- package/dist/client/middleware/contexts.d.ts +16 -10
- package/dist/client/middleware/contexts.d.ts.map +1 -1
- package/dist/client/middleware/contexts.js.map +1 -1
- package/dist/client/middleware/items.d.ts +31 -2
- package/dist/client/middleware/items.d.ts.map +1 -1
- package/dist/client/middleware/items.js +86 -6
- package/dist/client/middleware/items.js.map +1 -1
- package/dist/client/middleware/lru.d.ts +2 -0
- package/dist/client/middleware/lru.d.ts.map +1 -1
- package/dist/client/middleware/lru.js +11 -0
- package/dist/client/middleware/lru.js.map +1 -1
- package/dist/client/middleware/rate-limit.d.ts +7 -6
- package/dist/client/middleware/rate-limit.d.ts.map +1 -1
- package/dist/client/middleware/rate-limit.js +9 -6
- package/dist/client/middleware/rate-limit.js.map +1 -1
- package/dist/client/middleware/resilience.d.ts +61 -0
- package/dist/client/middleware/resilience.d.ts.map +1 -0
- package/dist/client/middleware/resilience.js +59 -0
- package/dist/client/middleware/resilience.js.map +1 -0
- package/dist/client/middleware/retry.d.ts +45 -11
- package/dist/client/middleware/retry.d.ts.map +1 -1
- package/dist/client/middleware/retry.js +102 -22
- package/dist/client/middleware/retry.js.map +1 -1
- package/dist/client/middleware/timeout.d.ts +15 -12
- package/dist/client/middleware/timeout.d.ts.map +1 -1
- package/dist/client/middleware/timeout.js +46 -37
- package/dist/client/middleware/timeout.js.map +1 -1
- package/dist/client/middleware/tracing.d.ts.map +1 -1
- package/dist/client/middleware/tracing.js +11 -3
- package/dist/client/middleware/tracing.js.map +1 -1
- package/dist/client/types.d.ts +9 -1
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/clock.d.ts +19 -0
- package/dist/clock.d.ts.map +1 -0
- package/dist/clock.js +18 -0
- package/dist/clock.js.map +1 -0
- package/dist/duration.d.ts +37 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/duration.js +44 -0
- package/dist/duration.js.map +1 -0
- package/dist/machines.d.ts +90 -0
- package/dist/machines.d.ts.map +1 -0
- package/dist/machines.js +127 -0
- package/dist/machines.js.map +1 -0
- package/dist/procedures/capability.d.ts +3 -6
- package/dist/procedures/capability.d.ts.map +1 -1
- package/dist/procedures/capability.js +7 -8
- package/dist/procedures/capability.js.map +1 -1
- package/dist/procedures/collection/index.d.ts +3 -3
- package/dist/procedures/collection/index.d.ts.map +1 -1
- package/dist/procedures/collection/index.js +1 -1
- package/dist/procedures/collection/index.js.map +1 -1
- package/dist/procedures/collection/procedures.d.ts.map +1 -1
- package/dist/procedures/collection/procedures.js +49 -1
- package/dist/procedures/collection/procedures.js.map +1 -1
- package/dist/procedures/collection/schemas.d.ts +33 -0
- package/dist/procedures/collection/schemas.d.ts.map +1 -1
- package/dist/procedures/collection/schemas.js +68 -0
- package/dist/procedures/collection/schemas.js.map +1 -1
- package/dist/procedures/collection/storage.d.ts +37 -0
- package/dist/procedures/collection/storage.d.ts.map +1 -1
- package/dist/procedures/core/array.d.ts.map +1 -1
- package/dist/procedures/core/array.js +26 -15
- package/dist/procedures/core/array.js.map +1 -1
- package/dist/procedures/core/index.d.ts.map +1 -1
- package/dist/procedures/core/index.js +8 -0
- package/dist/procedures/core/index.js.map +1 -1
- package/dist/procedures/core/meta.d.ts.map +1 -1
- package/dist/procedures/core/meta.js +2 -1
- package/dist/procedures/core/meta.js.map +1 -1
- package/dist/procedures/core/object.d.ts.map +1 -1
- package/dist/procedures/core/object.js +42 -13
- package/dist/procedures/core/object.js.map +1 -1
- package/dist/procedures/core/operands.d.ts.map +1 -1
- package/dist/procedures/core/operands.js +6 -1
- package/dist/procedures/core/operands.js.map +1 -1
- package/dist/procedures/core/string.d.ts.map +1 -1
- package/dist/procedures/core/string.js +4 -2
- package/dist/procedures/core/string.js.map +1 -1
- package/dist/procedures/define-procedure.d.ts +19 -7
- package/dist/procedures/define-procedure.d.ts.map +1 -1
- package/dist/procedures/define-procedure.js +57 -17
- package/dist/procedures/define-procedure.js.map +1 -1
- package/dist/procedures/effects.d.ts +16 -0
- package/dist/procedures/effects.d.ts.map +1 -1
- package/dist/procedures/effects.js +33 -0
- package/dist/procedures/effects.js.map +1 -1
- package/dist/procedures/idempotency.d.ts +73 -0
- package/dist/procedures/idempotency.d.ts.map +1 -0
- package/dist/procedures/idempotency.js +131 -0
- package/dist/procedures/idempotency.js.map +1 -0
- package/dist/procedures/index.d.ts +7 -3
- package/dist/procedures/index.d.ts.map +1 -1
- package/dist/procedures/index.js +6 -2
- package/dist/procedures/index.js.map +1 -1
- package/dist/procedures/interceptors.d.ts +17 -4
- package/dist/procedures/interceptors.d.ts.map +1 -1
- package/dist/procedures/interceptors.js +18 -7
- package/dist/procedures/interceptors.js.map +1 -1
- package/dist/procedures/invoke.d.ts +15 -3
- package/dist/procedures/invoke.d.ts.map +1 -1
- package/dist/procedures/invoke.js +8 -3
- package/dist/procedures/invoke.js.map +1 -1
- package/dist/procedures/manifest.d.ts +83 -0
- package/dist/procedures/manifest.d.ts.map +1 -0
- package/dist/procedures/manifest.js +90 -0
- package/dist/procedures/manifest.js.map +1 -0
- package/dist/procedures/runtime-programs.d.ts +19 -0
- package/dist/procedures/runtime-programs.d.ts.map +1 -0
- package/dist/procedures/runtime-programs.js +24 -0
- package/dist/procedures/runtime-programs.js.map +1 -0
- package/dist/procedures/types.d.ts +16 -0
- package/dist/procedures/types.d.ts.map +1 -1
- package/dist/procedures/types.js.map +1 -1
- package/dist/protocol.d.ts +40 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +58 -0
- package/dist/protocol.js.map +1 -0
- package/dist/server/host-policy.d.ts +4 -3
- package/dist/server/host-policy.d.ts.map +1 -1
- package/dist/server/host-policy.js +6 -3
- package/dist/server/host-policy.js.map +1 -1
- package/dist/server/host-procedures.d.ts +31 -0
- package/dist/server/host-procedures.d.ts.map +1 -0
- package/dist/server/host-procedures.js +75 -0
- package/dist/server/host-procedures.js.map +1 -0
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/procedure-server.d.ts +110 -4
- package/dist/server/procedure-server.d.ts.map +1 -1
- package/dist/server/procedure-server.js +269 -17
- package/dist/server/procedure-server.js.map +1 -1
- package/dist/server/request-auth.d.ts +19 -0
- package/dist/server/request-auth.d.ts.map +1 -0
- package/dist/server/request-auth.js +32 -0
- package/dist/server/request-auth.js.map +1 -0
- package/dist/server/types.d.ts +32 -0
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js.map +1 -1
- package/dist/timers.d.ts +60 -0
- package/dist/timers.d.ts.map +1 -0
- package/dist/timers.js +33 -0
- package/dist/timers.js.map +1 -0
- package/dist/tracing/traceparent.d.ts +26 -0
- package/dist/tracing/traceparent.d.ts.map +1 -0
- package/dist/tracing/traceparent.js +53 -0
- package/dist/tracing/traceparent.js.map +1 -0
- package/package.json +7 -1
- package/src/adapters/http/client/transport.ts +31 -3
- package/src/adapters/http/client/types.ts +3 -2
- package/src/adapters/http/server/transport.ts +60 -24
- package/src/adapters/http/shared/headers.ts +7 -6
- package/src/adapters/local/client/transport.ts +70 -5
- package/src/adapters/local/client/types.ts +18 -0
- package/src/adapters/mock/client/transport.ts +9 -6
- package/src/adapters/mock/client/types.ts +7 -6
- package/src/adapters/port/transport.ts +124 -0
- package/src/adapters/websocket/client/index.ts +1 -0
- package/src/adapters/websocket/client/transport.ts +232 -73
- package/src/adapters/websocket/client/types.ts +80 -21
- package/src/adapters/websocket/server/transport.ts +199 -301
- package/src/adapters/websocket/server/types.ts +20 -1
- package/src/adapters/websocket/shared/rpc.ts +453 -0
- package/src/browser.ts +51 -3
- package/src/client/call-types.ts +10 -14
- package/src/client/client.ts +28 -9
- package/src/client/deadline.ts +64 -0
- package/src/client/errors/factory.ts +12 -8
- package/src/client/index.ts +21 -3
- package/src/client/middleware/cache.ts +120 -23
- package/src/client/middleware/circuit-breaker.ts +65 -35
- package/src/client/middleware/contexts.ts +17 -10
- package/src/client/middleware/items.ts +101 -6
- package/src/client/middleware/lru.ts +12 -0
- package/src/client/middleware/rate-limit.ts +9 -7
- package/src/client/middleware/resilience.ts +81 -0
- package/src/client/middleware/retry.ts +146 -34
- package/src/client/middleware/timeout.ts +55 -46
- package/src/client/middleware/tracing.ts +13 -4
- package/src/client/types.ts +9 -1
- package/src/clock.ts +21 -0
- package/src/duration.ts +56 -0
- package/src/machines.ts +186 -0
- package/src/procedures/capability.ts +7 -8
- package/src/procedures/collection/index.ts +9 -1
- package/src/procedures/collection/procedures.ts +57 -0
- package/src/procedures/collection/schemas.ts +110 -0
- package/src/procedures/collection/storage.ts +38 -0
- package/src/procedures/core/array.ts +27 -16
- package/src/procedures/core/index.ts +8 -0
- package/src/procedures/core/meta.ts +2 -1
- package/src/procedures/core/object.ts +48 -14
- package/src/procedures/core/operands.ts +7 -0
- package/src/procedures/core/string.ts +4 -2
- package/src/procedures/define-procedure.ts +73 -20
- package/src/procedures/effects.ts +35 -0
- package/src/procedures/idempotency.ts +152 -0
- package/src/procedures/index.ts +18 -2
- package/src/procedures/interceptors.ts +28 -11
- package/src/procedures/invoke.ts +19 -5
- package/src/procedures/manifest.ts +158 -0
- package/src/procedures/runtime-programs.ts +27 -0
- package/src/procedures/types.ts +16 -0
- package/src/protocol.ts +97 -0
- package/src/server/host-policy.ts +8 -5
- package/src/server/host-procedures.ts +102 -0
- package/src/server/index.ts +5 -2
- package/src/server/procedure-server.ts +324 -10
- package/src/server/request-auth.ts +35 -0
- package/src/server/types.ts +37 -0
- package/src/timers.ts +82 -0
- package/src/tracing/traceparent.ts +61 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../../src/client/middleware/rate-limit.ts"],"names":[],"mappings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C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;IAErD,KAAK,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACxD,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO;QACnC,CAAC,CAAC,yBAAyB,CAAC,MAAM,CAAC,OAAO,CAAC;QAC3C,CAAC,CAAC,IAAI,CAAC;IAET,OAAO,CAAa,IAA8B,EAA4B,EAAE;QAC9E,OAAO,KAAK,SAAS,CAAC,EAAE,OAA4B;YAClD,gCAAgC;YAChC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;YAE/C,0BAA0B;YAC1B,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC;YAExD,IAAI,OAAO,EAAE,CAAC;gBACZ,oCAAoC;gBACpC,MAAM,YAAY,GAAG,OAAuC,CAAC;gBAC7D,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;gBACvC,KAAK,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;iBAAM,CAAC;gBACN,iCAAiC;gBACjC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The resilience preset (roadmap R10): the timeouts, the cache, the retry, the circuit breaker and
|
|
3
|
+
* the rate limit of a client, in the one order that works.
|
|
4
|
+
*
|
|
5
|
+
* The first layer is the outermost one:
|
|
6
|
+
*
|
|
7
|
+
* 1. The overall timeout: it covers the whole call, retries included.
|
|
8
|
+
* 2. The cache: a hit makes no request, so no try and no slot of the rate limit.
|
|
9
|
+
* 3. The retry: it starts each try.
|
|
10
|
+
* 4. The circuit breaker: it counts each try, and an open breaker stops a retry loop.
|
|
11
|
+
* 5. The rate limit: each try takes a slot.
|
|
12
|
+
* 6. The timeout of one try: inside the retry, so the retry can start the next try.
|
|
13
|
+
*
|
|
14
|
+
* Each order pitfall of a hand-made stack is impossible here: an overall timeout inside the
|
|
15
|
+
* retry, a per-try timeout outside it, or a rate limit outside the retry. The deadline of the
|
|
16
|
+
* call goes to the server as `procedure-timeout` with each try (`client/deadline.ts`).
|
|
17
|
+
*/
|
|
18
|
+
import type { TypedClientMiddleware } from "../types.js";
|
|
19
|
+
import type { CacheContext, CircuitBreakerContext, RateLimitContext, RetryContext, TimeoutContext } from "./contexts.js";
|
|
20
|
+
import { type CacheOptions } from "./cache.js";
|
|
21
|
+
import { type CircuitBreakerOptions } from "./circuit-breaker.js";
|
|
22
|
+
import { type RateLimitOptions } from "./rate-limit.js";
|
|
23
|
+
import { type RetryOptions } from "./retry.js";
|
|
24
|
+
import type { Duration } from "../../duration.js";
|
|
25
|
+
/** The parts of the preset. An absent part is not in the stack. */
|
|
26
|
+
export interface ResilienceOptions {
|
|
27
|
+
/** The time of the whole call, retries included. */
|
|
28
|
+
overall?: Duration | undefined;
|
|
29
|
+
/** The time of one try. It is at most the remaining time of the call. */
|
|
30
|
+
perAttempt?: Duration | undefined;
|
|
31
|
+
/** The retry. Its `idempotent` option decides which calls go again after an indeterminate try. */
|
|
32
|
+
retry?: RetryOptions | undefined;
|
|
33
|
+
/** The circuit breaker. */
|
|
34
|
+
breaker?: CircuitBreakerOptions | undefined;
|
|
35
|
+
/** The cache of the reads that opt in. */
|
|
36
|
+
cache?: CacheOptions | undefined;
|
|
37
|
+
/** The rate limit of the tries. */
|
|
38
|
+
rateLimit?: RateLimitOptions | undefined;
|
|
39
|
+
/** The message of a timeout error. */
|
|
40
|
+
message?: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
/** The context that the preset gives: the context of each part that it can have. */
|
|
43
|
+
export type ResilienceContext = TimeoutContext & Partial<RetryContext & CacheContext & CircuitBreakerContext & RateLimitContext>;
|
|
44
|
+
/**
|
|
45
|
+
* This function gives one middleware with the parts of `options` in the correct order (see the
|
|
46
|
+
* file comment). Add it with one `use()`.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const client = new Client(transport).use(
|
|
51
|
+
* resilience({
|
|
52
|
+
* overall: seconds(10),
|
|
53
|
+
* perAttempt: seconds(3),
|
|
54
|
+
* retry: { maxRetries: 2, idempotent: idempotentIn(registry) },
|
|
55
|
+
* breaker: { failureThreshold: 5 },
|
|
56
|
+
* }),
|
|
57
|
+
* );
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function resilience(options: ResilienceOptions): TypedClientMiddleware<ResilienceContext, {}>;
|
|
61
|
+
//# sourceMappingURL=resilience.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resilience.d.ts","sourceRoot":"","sources":["../../../src/client/middleware/resilience.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAkC,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACzH,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAkC,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAA6B,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IAChC,oDAAoD;IACpD,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,yEAAyE;IACzE,UAAU,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAClC,kGAAkG;IAClG,KAAK,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IACjC,2BAA2B;IAC3B,OAAO,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC5C,0CAA0C;IAC1C,KAAK,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IACjC,mCAAmC;IACnC,SAAS,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACzC,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAED,oFAAoF;AACpF,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG,OAAO,CAAC,YAAY,GAAG,YAAY,GAAG,qBAAqB,GAAG,gBAAgB,CAAC,CAAC;AAEjI;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,qBAAqB,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAgBnG"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The resilience preset (roadmap R10): the timeouts, the cache, the retry, the circuit breaker and
|
|
3
|
+
* the rate limit of a client, in the one order that works.
|
|
4
|
+
*
|
|
5
|
+
* The first layer is the outermost one:
|
|
6
|
+
*
|
|
7
|
+
* 1. The overall timeout: it covers the whole call, retries included.
|
|
8
|
+
* 2. The cache: a hit makes no request, so no try and no slot of the rate limit.
|
|
9
|
+
* 3. The retry: it starts each try.
|
|
10
|
+
* 4. The circuit breaker: it counts each try, and an open breaker stops a retry loop.
|
|
11
|
+
* 5. The rate limit: each try takes a slot.
|
|
12
|
+
* 6. The timeout of one try: inside the retry, so the retry can start the next try.
|
|
13
|
+
*
|
|
14
|
+
* Each order pitfall of a hand-made stack is impossible here: an overall timeout inside the
|
|
15
|
+
* retry, a per-try timeout outside it, or a rate limit outside the retry. The deadline of the
|
|
16
|
+
* call goes to the server as `procedure-timeout` with each try (`client/deadline.ts`).
|
|
17
|
+
*/
|
|
18
|
+
import { createCacheMiddleware } from "./cache.js";
|
|
19
|
+
import { createCircuitBreakerMiddleware } from "./circuit-breaker.js";
|
|
20
|
+
import { createRateLimitMiddleware } from "./rate-limit.js";
|
|
21
|
+
import { createRetryMiddleware } from "./retry.js";
|
|
22
|
+
import { createOverallTimeoutMiddleware, createTimeoutMiddleware } from "./timeout.js";
|
|
23
|
+
/**
|
|
24
|
+
* This function gives one middleware with the parts of `options` in the correct order (see the
|
|
25
|
+
* file comment). Add it with one `use()`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const client = new Client(transport).use(
|
|
30
|
+
* resilience({
|
|
31
|
+
* overall: seconds(10),
|
|
32
|
+
* perAttempt: seconds(3),
|
|
33
|
+
* retry: { maxRetries: 2, idempotent: idempotentIn(registry) },
|
|
34
|
+
* breaker: { failureThreshold: 5 },
|
|
35
|
+
* }),
|
|
36
|
+
* );
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function resilience(options) {
|
|
40
|
+
const layers = [];
|
|
41
|
+
const message = options.message;
|
|
42
|
+
if (options.overall) {
|
|
43
|
+
layers.push(createOverallTimeoutMiddleware({ overall: options.overall, ...(message ? { message: `${message} (overall)` } : {}) }));
|
|
44
|
+
}
|
|
45
|
+
if (options.cache)
|
|
46
|
+
layers.push(createCacheMiddleware(options.cache));
|
|
47
|
+
if (options.retry)
|
|
48
|
+
layers.push(createRetryMiddleware(options.retry));
|
|
49
|
+
if (options.breaker)
|
|
50
|
+
layers.push(createCircuitBreakerMiddleware(options.breaker));
|
|
51
|
+
if (options.rateLimit)
|
|
52
|
+
layers.push(createRateLimitMiddleware(options.rateLimit));
|
|
53
|
+
if (options.perAttempt) {
|
|
54
|
+
layers.push(createTimeoutMiddleware({ perAttempt: options.perAttempt, ...(message ? { message: `${message} (per-attempt)` } : {}) }));
|
|
55
|
+
}
|
|
56
|
+
const composed = (next) => layers.reduceRight((inner, layer) => layer(inner), next);
|
|
57
|
+
return composed;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=resilience.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resilience.js","sourceRoot":"","sources":["../../../src/client/middleware/resilience.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,qBAAqB,EAAqB,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAA8B,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAE,yBAAyB,EAAyB,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAqB,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAwBvF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU,CAAC,OAA0B;IACnD,MAAM,MAAM,GAAuB,EAAE,CAAC;IACtC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAChC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAqB,CAAC,CAAC;IACzJ,CAAC;IACD,IAAI,OAAO,CAAC,KAAK;QAAE,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAqB,CAAC,CAAC;IACzF,IAAI,OAAO,CAAC,KAAK;QAAE,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAqB,CAAC,CAAC;IACzF,IAAI,OAAO,CAAC,OAAO;QAAE,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,OAAO,CAAC,OAAO,CAAqB,CAAC,CAAC;IACtG,IAAI,OAAO,CAAC,SAAS;QAAE,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,OAAO,CAAC,SAAS,CAAqB,CAAC,CAAC;IACrG,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAqB,CAAC,CAAC;IAC5J,CAAC;IACD,MAAM,QAAQ,GAAG,CAAa,IAA8B,EAA4B,EAAE,CACxF,MAAM,CAAC,WAAW,CAA2B,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAE,KAAsC,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;IACvH,OAAO,QAAwD,CAAC;AAClE,CAAC"}
|
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* Protocol-agnostic retry with exponential backoff and jitter.
|
|
5
5
|
* Works with any transport!
|
|
6
6
|
*/
|
|
7
|
-
import type { ResponseItem, TypedClientMiddleware } from "../types.js";
|
|
7
|
+
import type { Method, ResponseItem, TypedClientMiddleware } from "../types.js";
|
|
8
8
|
import type { RetryContext } from "./contexts.js";
|
|
9
|
+
import { type Clock } from "../../clock.js";
|
|
10
|
+
import { type Duration } from "../../duration.js";
|
|
9
11
|
/**
|
|
10
12
|
* Retry middleware options.
|
|
11
13
|
*/
|
|
@@ -16,30 +18,62 @@ export interface RetryOptions {
|
|
|
16
18
|
*/
|
|
17
19
|
maxRetries?: number;
|
|
18
20
|
/**
|
|
19
|
-
*
|
|
21
|
+
* The clock of the backoff and of the budget (roadmap R35). The default is the clock of the
|
|
22
|
+
* platform. A test gives a fake clock.
|
|
23
|
+
*/
|
|
24
|
+
clock?: Clock;
|
|
25
|
+
/**
|
|
26
|
+
* Base delay for exponential backoff, for example `ms(500)`.
|
|
20
27
|
* Actual delay will be: baseDelay * 2^attempt + jitter
|
|
21
|
-
* @default
|
|
28
|
+
* @default 1 second
|
|
22
29
|
*/
|
|
23
|
-
retryDelay?:
|
|
30
|
+
retryDelay?: Duration;
|
|
24
31
|
/**
|
|
25
32
|
* The factor of the delay from one attempt to the next.
|
|
26
33
|
* @default 2
|
|
27
34
|
*/
|
|
28
35
|
backoffMultiplier?: number;
|
|
29
36
|
/**
|
|
30
|
-
* The longest delay between two attempts
|
|
37
|
+
* The longest delay between two attempts.
|
|
31
38
|
* @default no limit
|
|
32
39
|
*/
|
|
33
|
-
maxDelay?:
|
|
40
|
+
maxDelay?: Duration;
|
|
34
41
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
42
|
+
* The random part of each delay, from 0 to 1. With 1 (full jitter), the delay is a random time
|
|
43
|
+
* from 0 to the backoff, so the clients that failed together do not retry together. 0 gives the
|
|
44
|
+
* backoff exactly.
|
|
45
|
+
* @default 1 (full jitter; roadmap R12: before, 0.1 gave a delay within 10 percent of the backoff)
|
|
38
46
|
*/
|
|
39
47
|
jitter?: number;
|
|
48
|
+
/**
|
|
49
|
+
* The retry budget of this middleware: each call adds `ratio` of a retry to the budget, and each
|
|
50
|
+
* retry takes one. When the budget is empty, an error goes to the caller without a retry, so a
|
|
51
|
+
* failing service gets at most `ratio` more requests, not `maxRetries` times more. Besides the
|
|
52
|
+
* budget, `minPerSecond` retries a second are always allowed. `false` turns the budget off.
|
|
53
|
+
* @default { ratio: 0.2, minPerSecond: 10 }
|
|
54
|
+
*/
|
|
55
|
+
budget?: {
|
|
56
|
+
ratio?: number;
|
|
57
|
+
minPerSecond?: number;
|
|
58
|
+
} | false;
|
|
59
|
+
/**
|
|
60
|
+
* The calls that the middleware can send again after a try with an indeterminate outcome: the
|
|
61
|
+
* request left, and no answer came (a reset, a closed connection, the timeout of one try). The
|
|
62
|
+
* server can have run such a call, so only an idempotent call goes again (roadmap R1).
|
|
63
|
+
*
|
|
64
|
+
* - a function: true for an idempotent method. `idempotentIn(registry)` reads the effects of
|
|
65
|
+
* the procedures that the client knows.
|
|
66
|
+
* - `true`: every call. Use it only with a server that removes duplicate calls by their
|
|
67
|
+
* idempotency key (`ProcedureServer` does).
|
|
68
|
+
* - absent: only a call with `retry: { idempotent: true }` in its context.
|
|
69
|
+
*
|
|
70
|
+
* A try that did not leave the client (a refused connection) and an error that the server
|
|
71
|
+
* marks retryable go again in each case.
|
|
72
|
+
*/
|
|
73
|
+
idempotent?: boolean | ((method: Method) => boolean | undefined);
|
|
40
74
|
/**
|
|
41
75
|
* Custom function to determine if a request should be retried.
|
|
42
|
-
* Takes precedence over Status.retryable flag.
|
|
76
|
+
* Takes precedence over Status.retryable flag. The rule of `idempotent` still applies.
|
|
43
77
|
*
|
|
44
78
|
* @param item - The response item
|
|
45
79
|
* @param attempt - Current attempt number (0-indexed)
|
|
@@ -88,7 +122,7 @@ export interface RetryOptions {
|
|
|
88
122
|
* @example
|
|
89
123
|
* ```typescript
|
|
90
124
|
* // Create middleware with defaults
|
|
91
|
-
* client.use(createRetryMiddleware({ maxRetries: 3 }));
|
|
125
|
+
* client.use(createRetryMiddleware({ maxRetries: 3, retryDelay: ms(500) }));
|
|
92
126
|
*
|
|
93
127
|
* // Override per-call via context
|
|
94
128
|
* await client.call(method, payload, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/client/middleware/retry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAA+B,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources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MAAM,CAAA;KAAE,CAAC,GAAG;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAEtG;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC5E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,YAAiB,GAAG,qBAAqB,CAAC,YAAY,EAAE,EAAE,CAAC,CA4MzG"}
|
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
* Protocol-agnostic retry with exponential backoff and jitter.
|
|
5
5
|
* Works with any transport!
|
|
6
6
|
*/
|
|
7
|
-
import { abortedItem, sleep, thrownItem } from "./items.js";
|
|
7
|
+
import { abortedItem, deliveryOf, retryAfterOf, sleep, thrownItem } from "./items.js";
|
|
8
|
+
import { realClock } from "../../clock.js";
|
|
9
|
+
import { backoffDelay } from "@mark1russell7/service/backoff";
|
|
10
|
+
import { IDEMPOTENCY_KEY_METADATA, idempotencyKeyOf, newIdempotencyKey } from "../../procedures/idempotency.js";
|
|
11
|
+
import { isDuration, optionalMs } from "../../duration.js";
|
|
12
|
+
import { TIMER_DEFAULTS } from "../../timers.js";
|
|
8
13
|
/**
|
|
9
14
|
* Create retry middleware with exponential backoff and jitter.
|
|
10
15
|
*
|
|
@@ -24,7 +29,7 @@ import { abortedItem, sleep, thrownItem } from "./items.js";
|
|
|
24
29
|
* @example
|
|
25
30
|
* ```typescript
|
|
26
31
|
* // Create middleware with defaults
|
|
27
|
-
* client.use(createRetryMiddleware({ maxRetries: 3 }));
|
|
32
|
+
* client.use(createRetryMiddleware({ maxRetries: 3, retryDelay: ms(500) }));
|
|
28
33
|
*
|
|
29
34
|
* // Override per-call via context
|
|
30
35
|
* await client.call(method, payload, {
|
|
@@ -33,45 +38,112 @@ import { abortedItem, sleep, thrownItem } from "./items.js";
|
|
|
33
38
|
* ```
|
|
34
39
|
*/
|
|
35
40
|
export function createRetryMiddleware(options = {}) {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
+
const defaultRetryDelay = optionalMs(options.retryDelay, "retryDelay") ?? TIMER_DEFAULTS.retry.retryDelayMs;
|
|
42
|
+
const { jitter: defaultJitter = 1, shouldRetry: customShouldRetry, onBeforeRetry, onAfterRetry, idempotent: idempotentOption, } = options;
|
|
43
|
+
const defaultMaxRetries = options.maxRetries ?? TIMER_DEFAULTS.retry.maxRetries;
|
|
44
|
+
const defaultMultiplier = options.backoffMultiplier ?? TIMER_DEFAULTS.retry.backoffMultiplier;
|
|
45
|
+
const defaultMaxDelay = optionalMs(options.maxDelay, "maxDelay") ?? TIMER_DEFAULTS.retry.maxDelayMs;
|
|
46
|
+
/**
|
|
47
|
+
* The overrides of one call (`retry: { ... }` in its context), with the delays in milliseconds.
|
|
48
|
+
* Before, only maxAttempts was read.
|
|
49
|
+
*/
|
|
41
50
|
const overridesOf = (value) => {
|
|
42
51
|
if (typeof value !== "object" || value === null)
|
|
43
52
|
return {};
|
|
44
53
|
const out = {};
|
|
45
|
-
for (const key of ["maxAttempts", "
|
|
54
|
+
for (const key of ["maxAttempts", "backoffMultiplier"]) {
|
|
46
55
|
const field = value[key];
|
|
47
56
|
if (typeof field === "number" && Number.isFinite(field) && field >= 0)
|
|
48
57
|
out[key] = field;
|
|
49
58
|
}
|
|
59
|
+
for (const key of ["delay", "maxDelay"]) {
|
|
60
|
+
const field = value[key];
|
|
61
|
+
if (field !== undefined) {
|
|
62
|
+
if (!isDuration(field))
|
|
63
|
+
throw new TypeError(`retry.${key} must be a duration such as ms(500) (roadmap R11)`);
|
|
64
|
+
out[key] = optionalMs(field, `retry.${key}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
50
67
|
return out;
|
|
51
68
|
};
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The backoff delay of an attempt (from 0): exponential, at most the maximum delay, with the
|
|
71
|
+
* random part of `jitter` (full jitter by default). The backoff is `backoffDelay` of
|
|
72
|
+
* `@mark1russell7/service/backoff` (roadmap R37), whose tries start at 1.
|
|
73
|
+
*/
|
|
74
|
+
const retryDelayOf = (attempt, overrides) => backoffDelay({
|
|
75
|
+
base: overrides.delay ?? defaultRetryDelay,
|
|
76
|
+
factor: overrides.backoffMultiplier ?? defaultMultiplier,
|
|
77
|
+
cap: overrides.maxDelay ?? defaultMaxDelay,
|
|
78
|
+
jitter: { kind: "subtract", fraction: Math.min(1, Math.max(0, defaultJitter)) },
|
|
79
|
+
}, attempt + 1);
|
|
80
|
+
// The retry budget (R12): a balance of retries that each call fills by `ratio`
|
|
81
|
+
const budget = options.budget === false ? undefined : { ratio: options.budget?.ratio ?? 0.2, minPerSecond: options.budget?.minPerSecond ?? 10 };
|
|
82
|
+
const budgetCap = budget ? Math.max(1, budget.ratio * 100) : 0;
|
|
83
|
+
let balance = budgetCap;
|
|
84
|
+
const clock = options.clock ?? realClock;
|
|
85
|
+
let secondStart = clock.now();
|
|
86
|
+
let retriesThisSecond = 0;
|
|
87
|
+
/** This function takes one retry from the budget, or gives false when the budget is empty. */
|
|
88
|
+
const takeRetry = () => {
|
|
89
|
+
if (!budget)
|
|
90
|
+
return true;
|
|
91
|
+
if (balance >= 1) {
|
|
92
|
+
balance -= 1;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
const now = clock.now();
|
|
96
|
+
if (now - secondStart >= 1000) {
|
|
97
|
+
secondStart = now;
|
|
98
|
+
retriesThisSecond = 0;
|
|
99
|
+
}
|
|
100
|
+
if (retriesThisSecond < budget.minPerSecond) {
|
|
101
|
+
retriesThisSecond++;
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
};
|
|
106
|
+
/** True when the call can go again after an indeterminate try: the call says so, or the option. */
|
|
107
|
+
const isIdempotent = (method, value) => {
|
|
108
|
+
const own = typeof value === "object" && value !== null ? value.idempotent : undefined;
|
|
109
|
+
if (typeof own === "boolean")
|
|
110
|
+
return own;
|
|
111
|
+
if (typeof idempotentOption === "function")
|
|
112
|
+
return idempotentOption(method) === true;
|
|
113
|
+
return idempotentOption === true;
|
|
57
114
|
};
|
|
58
115
|
return (next) => {
|
|
59
116
|
return async function* (context) {
|
|
60
117
|
// Read from metadata first (user-provided context), then fall back to options
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
118
|
+
const given = context.message.metadata.retry;
|
|
119
|
+
const overrides = overridesOf(given);
|
|
120
|
+
// maxAttempts counts the attempts: the first try and the retries (R12: before, the override
|
|
121
|
+
// was used as the number of retries, against its name and its documentation)
|
|
122
|
+
const maxRetries = overrides.maxAttempts !== undefined ? Math.max(0, overrides.maxAttempts - 1) : defaultMaxRetries;
|
|
123
|
+
if (budget)
|
|
124
|
+
balance = Math.min(budgetCap, balance + budget.ratio);
|
|
125
|
+
const idempotent = isIdempotent(context.message.method, context.message.metadata.retry);
|
|
126
|
+
const shouldRetryItem = (item, attempt) => {
|
|
127
|
+
const wanted = customShouldRetry
|
|
128
|
+
? customShouldRetry(item, attempt)
|
|
129
|
+
: item.status.type === "error" && item.status.retryable;
|
|
130
|
+
// A request that can have run goes again only when the call is idempotent (R1). Before,
|
|
131
|
+
// a reset or a timeout of one try sent a write again.
|
|
132
|
+
return wanted && (deliveryOf(item) !== "indeterminate" || idempotent);
|
|
133
|
+
};
|
|
66
134
|
const signal = context.message.signal;
|
|
67
135
|
const baseId = context.message.id;
|
|
136
|
+
// One key for all the tries of the call: a server that removes duplicates runs it one time
|
|
137
|
+
const idempotencyKey = idempotencyKeyOf(context.message.metadata) ?? newIdempotencyKey();
|
|
138
|
+
context.message.metadata[IDEMPOTENCY_KEY_METADATA] = idempotencyKey;
|
|
68
139
|
let attempt = 0;
|
|
69
140
|
for (;;) {
|
|
70
141
|
// Update retry metadata with current state
|
|
71
142
|
context.message.metadata.retry = {
|
|
72
|
-
...
|
|
143
|
+
...(typeof given === "object" && given !== null ? given : {}),
|
|
73
144
|
attempt,
|
|
74
|
-
maxAttempts: maxRetries,
|
|
145
|
+
maxAttempts: maxRetries + 1,
|
|
146
|
+
idempotent,
|
|
75
147
|
};
|
|
76
148
|
// Each attempt gets its own request id. The id correlates the frames of one attempt
|
|
77
149
|
// on the wire: a cancelled attempt can still answer under its id (deep dive TRN-8/9).
|
|
@@ -120,7 +192,15 @@ export function createRetryMiddleware(options = {}) {
|
|
|
120
192
|
}
|
|
121
193
|
return;
|
|
122
194
|
}
|
|
123
|
-
|
|
195
|
+
// The budget is empty: the error goes to the caller (R12)
|
|
196
|
+
if (!takeRetry()) {
|
|
197
|
+
yield retryItem;
|
|
198
|
+
if (onAfterRetry)
|
|
199
|
+
await onAfterRetry(false, attempt);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// A server that asks for a wait (Retry-After) gets at least that wait (R12)
|
|
203
|
+
let delay = Math.max(retryDelayOf(attempt, overrides), retryAfterOf(retryItem) ?? 0);
|
|
124
204
|
// Before retry hook
|
|
125
205
|
if (onBeforeRetry) {
|
|
126
206
|
const hookResult = await onBeforeRetry(retryItem, attempt);
|
|
@@ -138,7 +218,7 @@ export function createRetryMiddleware(options = {}) {
|
|
|
138
218
|
}
|
|
139
219
|
}
|
|
140
220
|
// The backoff stops at once when the caller aborts (deep dive TRN-8)
|
|
141
|
-
if (!(await sleep(delay, signal))) {
|
|
221
|
+
if (!(await sleep(delay, signal, clock))) {
|
|
142
222
|
yield abortedItem(context.message.id);
|
|
143
223
|
return;
|
|
144
224
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../src/client/middleware/retry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG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
6
6
|
*/
|
|
7
7
|
import type { TypedClientMiddleware } from "../types.js";
|
|
8
8
|
import type { TimeoutContext } from "./contexts.js";
|
|
9
|
+
import { type Duration } from "../../duration.js";
|
|
9
10
|
/**
|
|
10
11
|
* Timeout middleware options.
|
|
11
12
|
*/
|
|
12
13
|
export interface TimeoutOptions {
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
+
* The time of the entire request (including retries), for example `seconds(10)`.
|
|
15
16
|
* @default undefined (no overall timeout)
|
|
16
17
|
*/
|
|
17
|
-
overall?:
|
|
18
|
+
overall?: Duration | undefined;
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* The time of each individual attempt, for example `seconds(2)`.
|
|
20
21
|
* Useful with retry middleware for per-attempt timeouts.
|
|
21
22
|
* @default undefined (no per-attempt timeout)
|
|
22
23
|
*/
|
|
23
|
-
perAttempt?:
|
|
24
|
+
perAttempt?: Duration | undefined;
|
|
24
25
|
/**
|
|
25
26
|
* Custom timeout error message.
|
|
26
27
|
* @default "Request timeout"
|
|
@@ -41,11 +42,11 @@ export interface TimeoutOptions {
|
|
|
41
42
|
* @example
|
|
42
43
|
* ```typescript
|
|
43
44
|
* // Create middleware with default timeout
|
|
44
|
-
* client.use(createOverallTimeoutMiddleware({ overall:
|
|
45
|
+
* client.use(createOverallTimeoutMiddleware({ overall: seconds(5) }));
|
|
45
46
|
*
|
|
46
47
|
* // Override per-call via context
|
|
47
48
|
* await client.call(method, payload, {
|
|
48
|
-
* context: { timeout: { overall:
|
|
49
|
+
* context: { timeout: { overall: seconds(10) } }
|
|
49
50
|
* });
|
|
50
51
|
* ```
|
|
51
52
|
*/
|
|
@@ -64,11 +65,11 @@ export declare function createOverallTimeoutMiddleware(options: Pick<TimeoutOpti
|
|
|
64
65
|
* @example
|
|
65
66
|
* ```typescript
|
|
66
67
|
* // Create middleware with default timeout
|
|
67
|
-
* client.use(createTimeoutMiddleware({ perAttempt:
|
|
68
|
+
* client.use(createTimeoutMiddleware({ perAttempt: seconds(1) }));
|
|
68
69
|
*
|
|
69
70
|
* // Override per-call via context
|
|
70
71
|
* await client.call(method, payload, {
|
|
71
|
-
* context: { timeout: { perAttempt:
|
|
72
|
+
* context: { timeout: { perAttempt: seconds(2) } }
|
|
72
73
|
* });
|
|
73
74
|
* ```
|
|
74
75
|
*/
|
|
@@ -76,15 +77,17 @@ export declare function createTimeoutMiddleware(options: Pick<TimeoutOptions, "p
|
|
|
76
77
|
/**
|
|
77
78
|
* Create combined timeout middleware with both overall and per-attempt timeouts.
|
|
78
79
|
*
|
|
80
|
+
* @deprecated Use `resilience({ overall, perAttempt, retry })`. This function puts the two
|
|
81
|
+
* timeouts in one slot, so a retry middleware that you add with another `use()` cannot sit
|
|
82
|
+
* between them: the retry is outside both, or inside both. `resilience` puts the retry between
|
|
83
|
+
* them (roadmap R10).
|
|
84
|
+
*
|
|
79
85
|
* @param options - Timeout configuration
|
|
80
86
|
* @returns Middleware function
|
|
81
87
|
*
|
|
82
88
|
* @example
|
|
83
89
|
* ```typescript
|
|
84
|
-
* client.use(
|
|
85
|
-
* overall: 5000, // 5 seconds total
|
|
86
|
-
* perAttempt: 1000 // 1 second per attempt
|
|
87
|
-
* }));
|
|
90
|
+
* client.use(resilience({ overall: seconds(5), perAttempt: seconds(1), retry: { maxRetries: 2 } }));
|
|
88
91
|
* ```
|
|
89
92
|
*/
|
|
90
93
|
export declare function createCombinedTimeoutMiddleware(options: TimeoutOptions): TypedClientMiddleware<TimeoutContext, {}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../../src/client/middleware/timeout.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../../src/client/middleware/timeout.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAA6C,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAE/B;;;;OAIG;IACH,UAAU,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAElC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAuKD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,SAAS,CAAC,GAAG,qBAAqB,CAAC,cAAc,EAAE,EAAE,CAAC,CAqB9I;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,YAAY,GAAG,SAAS,CAAC,GAAG,qBAAqB,CAAC,cAAc,EAAE,EAAE,CAAC,CAyB1I;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,cAAc,GAAG,qBAAqB,CAAC,cAAc,EAAE,EAAE,CAAC,CAGlH"}
|