RateLimiter.ts overview
Since v1.0.0
Exports Grouped by Category
Constructors
make
Signature
declare const make: Effect.Effect<RateLimiter, never, RateLimiterStore>
Since v1.0.0
Errors
ErrorTypeId
Signature
declare const ErrorTypeId: "~@effect/experimental/RateLimiter/RateLimiterError"
Since v1.0.0
ErrorTypeId (type alias)
Signature
type ErrorTypeId = "~@effect/experimental/RateLimiter/RateLimiterError"
Since v1.0.0
RateLimitExceeded (class)
Signature
declare class RateLimitExceeded
Since v1.0.0
[ErrorTypeId] (property)
Signature
readonly [ErrorTypeId]: "~@effect/experimental/RateLimiter/RateLimiterError"
Since v1.0.0
reason (property)
Signature
readonly reason: "Exceeded"
Since v1.0.0
RateLimitStoreError (class)
Signature
declare class RateLimitStoreError
Since v1.0.0
[ErrorTypeId] (property)
Signature
readonly [ErrorTypeId]: "~@effect/experimental/RateLimiter/RateLimiterError"
Since v1.0.0
reason (property)
Signature
readonly reason: "StoreError"
Since v1.0.0
RateLimiterError
Signature
declare const RateLimiterError: Schema.Union<[typeof RateLimitExceeded, typeof RateLimitStoreError]>
Since v1.0.0
RateLimiterError (type alias)
Signature
type RateLimiterError = RateLimitExceeded | RateLimitStoreError
Since v1.0.0
Layers
layer
Signature
declare const layer: Layer.Layer<RateLimiter, never, RateLimiterStore>
Since v1.0.0
Models
ConsumeResult (interface)
Signature
export interface ConsumeResult {
/**
* The amount of delay to wait before making the next request, when the rate
* limiter is using the "delay" `onExceeded` strategy.
*
* It will be Duration.zero if the request is allowed immediately.
*/
readonly delay: Duration.Duration
/**
* The maximum number of requests allowed in the current window.
*/
readonly limit: number
/**
* The number of remaining requests in the current window.
*/
readonly remaining: number
/**
* The time until the rate limit fully resets.
*/
readonly resetAfter: Duration.Duration
}
Since v1.0.0
RateLimiter (interface)
Signature
export interface RateLimiter {
readonly [TypeId]: TypeId
readonly consume: (options: {
readonly algorithm?: "fixed-window" | "token-bucket" | undefined
readonly onExceeded?: "delay" | "fail" | undefined
readonly window: Duration.DurationInput
readonly limit: number
readonly key: string
readonly tokens?: number | undefined
}) => Effect.Effect<ConsumeResult, RateLimiterError>
}
Since v1.0.0
RateLimiterStore
RateLimiterStore (class)
Signature
declare class RateLimiterStore
Since v1.0.0
layerStoreMemory
Signature
declare const layerStoreMemory: Layer.Layer<RateLimiterStore, never, never>
Since v1.0.0
Tags
RateLimiter
Signature
declare const RateLimiter: Context.Tag<RateLimiter, RateLimiter>
Since v1.0.0
Type IDs
TypeId
Signature
declare const TypeId: "~@effect/experimental/RateLimiter"
Since v1.0.0
TypeId (type alias)
Signature
type TypeId = "~@effect/experimental/RateLimiter"
Since v1.0.0