Skip to content

Commit b72a486

Browse files
committed
chore: prettier
1 parent 3d421f5 commit b72a486

File tree

10 files changed

+273
-258
lines changed

10 files changed

+273
-258
lines changed

apps/test-bot/src/app/commands/(general)/ratelimit-basic.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
//
33
// Reports remaining/reset values captured in the env store.
44

5-
import type { ChatInputCommand, CommandData, CommandMetadata } from 'commandkit';
5+
import type {
6+
ChatInputCommand,
7+
CommandData,
8+
CommandMetadata,
9+
} from 'commandkit';
610
import { getRateLimitInfo } from '@commandkit/ratelimit';
711

812
export const command: CommandData = {
@@ -28,9 +32,7 @@ export const chatInput: ChatInputCommand = async (ctx) => {
2832
}
2933

3034
const now = Date.now();
31-
const resetAt = info.resetAt
32-
? new Date(info.resetAt).toISOString()
33-
: 'n/a';
35+
const resetAt = info.resetAt ? new Date(info.resetAt).toISOString() : 'n/a';
3436
const resetInMs = info.resetAt ? Math.max(0, info.resetAt - now) : 0;
3537

3638
const lines = [

apps/test-bot/src/app/commands/(general)/ratelimit-queue.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
//
33
// Shows queue delay by comparing interaction creation vs handling time.
44

5-
import type { ChatInputCommand, CommandData, CommandMetadata } from 'commandkit';
5+
import type {
6+
ChatInputCommand,
7+
CommandData,
8+
CommandMetadata,
9+
} from 'commandkit';
610

711
export const command: CommandData = {
812
name: 'ratelimit-queue',

apps/test-bot/src/app/events/(ratelimits)/ratelimited/logger.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// Logs aggregated retry info when commands are blocked.
44

55
import { Logger } from 'commandkit';
6-
import type { RateLimitResult, RateLimitStoreValue } from '@commandkit/ratelimit';
6+
import type {
7+
RateLimitResult,
8+
RateLimitStoreValue,
9+
} from '@commandkit/ratelimit';
710
import type { Interaction, Message } from 'discord.js';
811

912
type RateLimitedEventPayload = {

apps/test-bot/src/ratelimit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ configureRatelimit({
4141
Logger.info(`[ratelimit] allowed ${key} remaining=${result.remaining}`);
4242
},
4343
onRateLimited: ({ key, result }) => {
44-
Logger.warn(`[ratelimit] limited ${key} retryAfter=${result.retryAfter}ms`);
44+
Logger.warn(
45+
`[ratelimit] limited ${key} retryAfter=${result.retryAfter}ms`,
46+
);
4547
},
4648
onViolation: (key, count) => {
4749
Logger.warn(`[ratelimit] violation ${key} count=${count}`);

apps/website/docs/guide/05-official-plugins/07-commandkit-ratelimit.mdx

Lines changed: 239 additions & 234 deletions
Large diffs are not rendered by default.

packages/ratelimit/spec/algorithms.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { LeakyBucketAlgorithm } from '../src/engine/algorithms/leaky-bucket';
1313
import type { RateLimitStorage } from '../src/types';
1414

1515
const scope = 'user' as const;
16-
const delay = (ms = 0) => new Promise<void>((resolve) => setTimeout(resolve, ms));
16+
const delay = (ms = 0) =>
17+
new Promise<void>((resolve) => setTimeout(resolve, ms));
1718

1819
/**
1920
* Test storage that delays sorted-set calls to simulate contention.

packages/ratelimit/src/configure.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ export function getRateLimitConfig(): RateLimitPluginOptions {
9595
* @param config - Runtime options to merge into the active configuration.
9696
* @returns Nothing; updates runtime state in place.
9797
*/
98-
export function configureRatelimit(
99-
config: RateLimitPluginOptions = {},
100-
): void {
98+
export function configureRatelimit(config: RateLimitPluginOptions = {}): void {
10199
configured = true;
102100
Object.assign(rateLimitConfig, config);
103101
updateRuntime(config);

packages/ratelimit/src/engine/RateLimitEngine.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ export class RateLimitEngine {
4040
this.violations = new ViolationTracker(storage);
4141
}
4242

43-
/**
44-
* Create an algorithm instance for a resolved config.
45-
*
46-
* @param config - Resolved limiter configuration.
47-
* @returns Algorithm instance for the resolved config.
48-
*/
43+
/**
44+
* Create an algorithm instance for a resolved config.
45+
*
46+
* @param config - Resolved limiter configuration.
47+
* @returns Algorithm instance for the resolved config.
48+
*/
4949
private createAlgorithm(config: ResolvedLimiterConfig): RateLimitAlgorithm {
5050
switch (config.algorithm) {
5151
case 'fixed-window':

packages/ratelimit/src/engine/violations.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export class ViolationTracker {
3232
return `violation:${key}`;
3333
}
3434

35-
/**
36-
* Read stored violation state for a key, if present.
37-
*
38-
* @param key - Storage key for the limiter.
39-
* @returns Stored violation state or null when none is present.
40-
*/
35+
/**
36+
* Read stored violation state for a key, if present.
37+
*
38+
* @param key - Storage key for the limiter.
39+
* @returns Stored violation state or null when none is present.
40+
*/
4141
async getState(key: string): Promise<ViolationState | null> {
4242
const stored = await this.storage.get<ViolationState>(this.key(key));
4343
return isViolationState(stored) ? stored : null;

packages/ratelimit/src/utils/locking.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ export async function withStorageKeyLock<T>(
6363
mutexByStorage.set(storage, mutex);
6464
}
6565
return mutex.run(key, fn);
66-
}
66+
}

0 commit comments

Comments
 (0)