ResiliencePipelineBuilder
Defined in: src/builder.ts:44
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Extends
Section titled “Extends”PipelineBuilder<T,E,C>
Type Parameters
Section titled “Type Parameters”T = any
E = never
C extends string = never
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ResiliencePipelineBuilder<
T,E,C>(options?):ResiliencePipelineBuilder<T,E,C>
Defined in: src/pipeline-builder.ts:62
Parameters
Section titled “Parameters”options?
Section titled “options?”ResiliencePipelineBuilderOptions = {}
Returns
Section titled “Returns”ResiliencePipelineBuilder<T, E, C>
Inherited from
Section titled “Inherited from”Properties
Section titled “Properties”
readonlyname:string|undefined
Defined in: src/pipeline-builder.ts:56
Inherited from
Section titled “Inherited from”
readonlytags:Readonly<Record<string,string>> |undefined
Defined in: src/pipeline-builder.ts:58
Inherited from
Section titled “Inherited from”timeProvider
Section titled “timeProvider”
readonlytimeProvider:TimeProvider
Defined in: src/pipeline-builder.ts:57
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”add<
D>(definition):ResiliencePipelineBuilder<T,WithErrors<E,C,ErrorsOf<D>>,C|CatchesOf<D>>
Defined in: src/builder.ts:45
Type Parameters
Section titled “Type Parameters”D extends StrategyDefinition<T, any>
Parameters
Section titled “Parameters”definition
Section titled “definition”D
Returns
Section titled “Returns”ResiliencePipelineBuilder<T, WithErrors<E, C, ErrorsOf<D>>, C | CatchesOf<D>>
Overrides
Section titled “Overrides”addAdaptiveConcurrencyLimiter()
Section titled “addAdaptiveConcurrencyLimiter()”addAdaptiveConcurrencyLimiter(
options?):Next<T,E,C,BulkheadRejectedError>
Defined in: src/builder.ts:108
Concurrency limit that tunes itself from observed latency and failures (gradient2 / vegas / aimd), so you don’t have to guess the right number: it grows while the dependency keeps up and backs off when it queues.
Parameters
Section titled “Parameters”options?
Section titled “options?”AdaptiveConcurrencyLimiterOptions<T> = {}
Returns
Section titled “Returns”Next<T, E, C, BulkheadRejectedError>
addCache()
Section titled “addCache()”addCache(
options):this
Defined in: src/builder.ts:128
Cache successful results by key, coalesce concurrent identical calls, optionally serve stale values on failure.
Parameters
Section titled “Parameters”options
Section titled “options”CacheOptions<T>
Returns
Section titled “Returns”this
addChaosBehavior()
Section titled “addChaosBehavior()”addChaosBehavior(
options):this
Defined in: src/builder.ts:154
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”this
addChaosFault()
Section titled “addChaosFault()”addChaosFault(
options):this
Defined in: src/builder.ts:142
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”this
addChaosLatency()
Section titled “addChaosLatency()”addChaosLatency(
options):this
Defined in: src/builder.ts:150
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”this
addChaosOutcome()
Section titled “addChaosOutcome()”addChaosOutcome(
options):this
Defined in: src/builder.ts:146
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”this
addCircuitBreaker()
Section titled “addCircuitBreaker()”addCircuitBreaker(
options?):Next<T,E,C,BrokenCircuitError>
Defined in: src/builder.ts:64
Parameters
Section titled “Parameters”options?
Section titled “options?”CircuitBreakerOptions<T> = {}
Returns
Section titled “Returns”Next<T, E, C, BrokenCircuitError>
addCoalesce()
Section titled “addCoalesce()”addCoalesce(
options?):this
Defined in: src/builder.ts:133
Single-flight only: concurrent executions with the same key share one call; nothing is cached.
Parameters
Section titled “Parameters”options?
Section titled “options?”Omit<CacheOptions<T>, "ttl" | "staleTtl" | "store" | "shouldCache"> = {}
Returns
Section titled “Returns”this
addConcurrencyLimiter()
Section titled “addConcurrencyLimiter()”addConcurrencyLimiter(
options,queueLimit?):Next<T,E,C,BulkheadRejectedError>
Defined in: src/builder.ts:95
addConcurrencyLimiter(10), addConcurrencyLimiter(10, 50) or full options.
Parameters
Section titled “Parameters”options
Section titled “options”number | ConcurrencyLimiterOptions
queueLimit?
Section titled “queueLimit?”number = 0
Returns
Section titled “Returns”Next<T, E, C, BulkheadRejectedError>
addFallback()
Section titled “addFallback()”Call Signature
Section titled “Call Signature”addFallback(
options):ResiliencePipelineBuilder<T,E,string>
Defined in: src/builder.ts:69
Without shouldHandle it catches every failure of the strategies added after it, so their errors leave the error type.
Parameters
Section titled “Parameters”options
Section titled “options”FallbackOptions<T> & object
Returns
Section titled “Returns”ResiliencePipelineBuilder<T, E, string>
Call Signature
Section titled “Call Signature”addFallback(
options):this
Defined in: src/builder.ts:70
Without shouldHandle it catches every failure of the strategies added after it, so their errors leave the error type.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”this
addFallbackOn()
Section titled “addFallbackOn()”addFallbackOn<
K>(codes,fallbackAction,options?):ResiliencePipelineBuilder<T,E,C|K>
Defined in: src/builder.ts:76
Fallback for these error codes only; they leave the settle() error type of the strategies added after it.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”readonly K[]
fallbackAction
Section titled “fallbackAction”(args) => MaybePromise<T>
options?
Section titled “options?”Omit<FallbackOptions<T>, "shouldHandle" | "fallbackAction">
Returns
Section titled “Returns”ResiliencePipelineBuilder<T, E, C | K>
addFixedWindowRateLimiter()
Section titled “addFixedWindowRateLimiter()”addFixedWindowRateLimiter(
options):Next<T,E,C,RateLimiterRejectedError>
Defined in: src/builder.ts:113
Fixed-window rate limit: permitLimit per window. Optional permits(ctx) weight and queueTimeout.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Next<T, E, C, RateLimiterRejectedError>
addHedging()
Section titled “addHedging()”addHedging(
options?):this
Defined in: src/builder.ts:90
Parameters
Section titled “Parameters”options?
Section titled “options?”HedgingOptions<T> = {}
Returns
Section titled “Returns”this
addLock()
Section titled “addLock()”addLock(
options):Next<T,E,C,LockNotAcquiredError|LockLostError>
Defined in: src/builder.ts:138
Run under a (distributed, with a custom store) lock: leases, renewal, fencing tokens.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Next<T, E, C, LockNotAcquiredError | LockLostError>
addMapError()
Section titled “addMapError()”addMapError<
E2>(mapper):ResiliencePipelineBuilder<T,E|E2,string>
Defined in: src/builder.ts:81
Turns every failure of the strategies added after it into your own error type (theirs leave the error type).
Type Parameters
Section titled “Type Parameters”E2
Parameters
Section titled “Parameters”mapper
Section titled “mapper”(error, context) => E2
Returns
Section titled “Returns”ResiliencePipelineBuilder<T, E | E2, string>
addPartitionedRateLimiter()
Section titled “addPartitionedRateLimiter()”addPartitionedRateLimiter(
options):Next<T,E,C,RateLimiterRejectedError>
Defined in: src/builder.ts:123
One limiter per key (user, tenant, API key…), created on demand and evicted when idle.
Parameters
Section titled “Parameters”options
Section titled “options”PartitionedRateLimiterOptions<T>
Returns
Section titled “Returns”Next<T, E, C, RateLimiterRejectedError>
addPipeline()
Section titled “addPipeline()”addPipeline<
E2>(pipeline):Next<T,E,C,E2>
Defined in: src/builder.ts:50
Nest an existing pipeline (and its state) as a single strategy.
Type Parameters
Section titled “Type Parameters”E2
Parameters
Section titled “Parameters”pipeline
Section titled “pipeline”ResiliencePipeline<T, E2>
Returns
Section titled “Returns”Next<T, E, C, E2>
Overrides
Section titled “Overrides”addRateLimiter()
Section titled “addRateLimiter()”addRateLimiter(
options):Next<T,E,C,RateLimiterRejectedError>
Defined in: src/builder.ts:100
Token bucket rate limiter.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Next<T, E, C, RateLimiterRejectedError>
addRetry()
Section titled “addRetry()”addRetry(
options?):this
Defined in: src/builder.ts:55
Parameters
Section titled “Parameters”options?
Section titled “options?”RetryOptions<T> = {}
Returns
Section titled “Returns”this
addSlidingWindowRateLimiter()
Section titled “addSlidingWindowRateLimiter()”addSlidingWindowRateLimiter(
options):Next<T,E,C,RateLimiterRejectedError>
Defined in: src/builder.ts:118
Sliding-window rate limit: smooths the burst a fixed window allows at its edges.
Parameters
Section titled “Parameters”options
Section titled “options”SlidingWindowRateLimiterOptions
Returns
Section titled “Returns”Next<T, E, C, RateLimiterRejectedError>
addStaleFallback()
Section titled “addStaleFallback()”addStaleFallback(
options):this
Defined in: src/builder.ts:86
Serve the last good value when a call fails (no caching of fresh calls): tenace’s withStaleFallback.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”this
addStrategy()
Section titled “addStrategy()”addStrategy(
create,name?):this
Defined in: src/pipeline-builder.ts:75
Plug in your own strategy.
Parameters
Section titled “Parameters”create
Section titled “create”string
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”addTimeout()
Section titled “addTimeout()”addTimeout(
options):Next<T,E,C,TimeoutRejectedError>
Defined in: src/builder.ts:60
addTimeout(5000), addTimeout('5s') or addTimeout({ timeout: '5s', onTimeout }).
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”Next<T, E, C, TimeoutRejectedError>
build()
Section titled “build()”build():
ResiliencePipeline<T,E>
Defined in: src/builder.ts:158
Returns
Section titled “Returns”ResiliencePipeline<T, E>