createPartitionedRateLimitKeyFactory
createPartitionedRateLimitKeyFactory(
partitionFactory,options?):RateLimitKeyFactory
Defined in: packages/pipeline-rate-limit/src/helpers/partitioned-key.ts:77
Creates a RateLimitKeyFactory for per-caller limits.
Segments are escaped and joined through the core key helper so tenant, caller/account identity, and request name remain distinct even when values contain separator characters.
Parameters
Section titled “Parameters”partitionFactory
Section titled “partitionFactory”Resolves the stable caller/account identity.
options?
Section titled “options?”PartitionedRateLimitKeyOptions = {}
Tenant and missing-partition policy.
Returns
Section titled “Returns”A RateLimitKeyFactory suitable for RateLimitBehaviorOptions.keyFactory.
Throws
Section titled “Throws”When a required tenant or caller partition is absent.
The produced key is <tenantId>:<partition>:<requestName> when tenant
inclusion is enabled, <partition>:<requestName> otherwise.
RateLimitBehaviorOptions.keyPrefix is still applied afterwards by
buildRateLimitKey(), so environment/service prefixes remain orthogonal.
Examples
Section titled “Examples”Per authenticated user, tenant-aware and fail-closed by default
const perUserKey = createPartitionedRateLimitKeyFactory((ctx) => ctx.items.get('currentUserId') as string | undefined,);
class CreateOrderHandler { @pipeline.wrap({ kind: 'command' }, [RateLimitBehavior, { keyFactory: perUserKey, keyPrefix: 'write-api' }]) async handle(command: CreateOrderCommand) {}}Single-tenant deployment — say so explicitly
createPartitionedRateLimitKeyFactory(readUserId, { includeTenant: false });Account-wide bucket shared by every user in the account
createPartitionedRateLimitKeyFactory(readAccountId, { includeTenant: true });