Μετάβαση στο περιεχόμενο

RateLimitBehavior

Αυτό το περιεχόμενο δεν είναι ακόμη διαθέσιμο στη γλώσσα σου.

Defined in: packages/pipeline-rate-limit/src/rate-limit.behavior.ts:99

Pipeline behavior that enforces rate limits before a handler runs.

For each request it consumes points (default 1, or computed per request when points is a function) from a bucket keyed by buildRateLimitKey. A cost of 0 charges nothing and skips the limiter. If the bucket is exhausted it throws RateLimitExceededError (map to HTTP 429 with toHttpResponse of @cqrs-ddd/pipeline-rate-limit/http); otherwise the handler proceeds.

context.request is the CQRS command/query/event, not an Express/Fastify request. Transport metadata needed for keying should be copied into the CQRS request or written to context.items by an earlier behavior.

Backend-agnostic: it depends only on RateLimiterLike, so any rate-limiter-flexible backend (memory, Redis/Valkey, Mongo, SQL) is a one-line swap in the constructor.

Per-handler limit, partitioned by tenant and authenticated caller

const perUser = createPartitionedRateLimitKeyFactory(
(ctx) => ctx.items.get('userId') as string | undefined,
);
class CreateUserHandler {
@pipeline.wrap({ kind: 'command' }, [RateLimitBehavior, { points: 1, keyFactory: perUser }])
async handle(command: CreateUserCommand) {}
}

new RateLimitBehavior(limiter, defaults?, logger?): RateLimitBehavior

Defined in: packages/pipeline-rate-limit/src/rate-limit.behavior.ts:160

RateLimiterLike

RateLimitBehaviorOptions

PipelineLogger

RateLimitBehavior

readonly static [PIPELINE_BEHAVIOR_CONTRACT]: IPipelineBehaviorContract

Defined in: packages/pipeline-rate-limit/src/rate-limit.behavior.ts:104

handle(context, next): Promise<unknown>

Defined in: packages/pipeline-rate-limit/src/rate-limit.behavior.ts:175

IPipelineContext

NextDelegate

Promise<unknown>

IPipelineBehavior.handle


resolveEffectiveOptions(options?): RateLimitBehaviorOptions

Defined in: packages/pipeline-rate-limit/src/rate-limit.behavior.ts:240

Shallow-merges pipeline-level options over the constructor defaults.

RateLimitBehaviorOptions

RateLimitBehaviorOptions

IPipelineBehaviorOptionsResolver.resolveEffectiveOptions