Skip to main content Link Search Menu Expand Document (external link)

RateLimiter.ts overview

Since v1.0.0


Exports Grouped by Category


Constructors

make

Signature

declare const make: Effect.Effect<RateLimiter, never, RateLimiterStore>

Source

Since v1.0.0

Errors

ErrorTypeId

Signature

declare const ErrorTypeId: "~@effect/experimental/RateLimiter/RateLimiterError"

Source

Since v1.0.0

ErrorTypeId (type alias)

Signature

type ErrorTypeId = "~@effect/experimental/RateLimiter/RateLimiterError"

Source

Since v1.0.0

RateLimitExceeded (class)

Signature

declare class RateLimitExceeded

Source

Since v1.0.0

[ErrorTypeId] (property)

Signature

readonly [ErrorTypeId]: "~@effect/experimental/RateLimiter/RateLimiterError"

Source

Since v1.0.0

reason (property)

Signature

readonly reason: "Exceeded"

Source

Since v1.0.0

RateLimitStoreError (class)

Signature

declare class RateLimitStoreError

Source

Since v1.0.0

[ErrorTypeId] (property)

Signature

readonly [ErrorTypeId]: "~@effect/experimental/RateLimiter/RateLimiterError"

Source

Since v1.0.0

reason (property)

Signature

readonly reason: "StoreError"

Source

Since v1.0.0

RateLimiterError

Signature

declare const RateLimiterError: Schema.Union<[typeof RateLimitExceeded, typeof RateLimitStoreError]>

Source

Since v1.0.0

RateLimiterError (type alias)

Signature

type RateLimiterError = RateLimitExceeded | RateLimitStoreError

Source

Since v1.0.0

Layers

layer

Signature

declare const layer: Layer.Layer<RateLimiter, never, RateLimiterStore>

Source

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
}

Source

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>
}

Source

Since v1.0.0

RateLimiterStore

RateLimiterStore (class)

Signature

declare class RateLimiterStore

Source

Since v1.0.0

layerStoreMemory

Signature

declare const layerStoreMemory: Layer.Layer<RateLimiterStore, never, never>

Source

Since v1.0.0

Tags

RateLimiter

Signature

declare const RateLimiter: Context.Tag<RateLimiter, RateLimiter>

Source

Since v1.0.0

Type IDs

TypeId

Signature

declare const TypeId: "~@effect/experimental/RateLimiter"

Source

Since v1.0.0

TypeId (type alias)

Signature

type TypeId = "~@effect/experimental/RateLimiter"

Source

Since v1.0.0