Skip to content

Commit 08e293f

Browse files
committed
prettier format
1 parent 45b1977 commit 08e293f

25 files changed

+566
-221
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ git checkout -b your-feature-or-bugfix
4949
3. Ensure that your changes don't break any existing functionality.
5050
You can test the functionality of your code depending on where
5151
you've made changes:
52+
5253
1. If you've made changes to the CommandKit package, you can use
5354
the "apps/test-bot" project to test your own bot. Just make sure
5455
to create a new `.env` file with the template from the

apps/website/docs/guide.old/01-getting-started/05-using-commandkit-cli.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ npx commandkit create event ready
103103
## Best Practices
104104

105105
1. **Development Workflow**:
106+
106107
- Use `commandkit dev` during development for instant feedback
107108
- Enable debug mode when troubleshooting issues
108109
- Keep your `.env` file updated with all required variables
109110

110111
2. **Production Deployment**:
112+
111113
- Always run `commandkit build` before deploying
112114
- Test the production build locally before deployment
113115
- Use environment variables for sensitive data

apps/website/docs/guide.old/04-caching/01-caching-in-commandkit.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ CommandKit's caching system works by:
8080

8181
1. **Generating a Cache Key**: Each cached function call generates a
8282
unique key based on:
83+
8384
- The function's identity
8485
- The arguments passed to the function
8586
- A build ID for stability
8687

8788
2. **Storing Results**: When a function is called:
89+
8890
- If the result isn't cached, the function executes and stores its
8991
result
9092
- If the result is cached, it's returned immediately without
@@ -116,16 +118,19 @@ async function fetchUserData(userId: string) {
116118
## Best Practices
117119

118120
1. **Choose What to Cache**:
121+
119122
- Cache expensive operations (API calls, database queries)
120123
- Cache data that doesn't change frequently
121124
- Don't cache sensitive or frequently changing data
122125

123126
2. **Set Appropriate TTL**:
127+
124128
- Use shorter TTL for frequently changing data
125129
- Use longer TTL for static data
126130
- Consider your data's update frequency
127131

128132
3. **Use Tags for Revalidation**:
133+
129134
- Add meaningful tags to your cache entries
130135
- Group related cache entries with the same tag
131136
- Use tags for targeted cache invalidation

apps/website/docs/guide.old/04-caching/02-cacheTag-function.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ await revalidateTag('user:123');
8383
## Best Practices
8484

8585
1. **Use Consistent Naming**:
86+
8687
- Follow a consistent pattern (e.g., `type:id`)
8788
- Make tags descriptive and meaningful
8889
- Use hierarchical tags when appropriate
8990

9091
2. **Group Related Data**:
92+
9193
- Tag related cache entries with the same tag
9294
- Use multiple tags for cross-category entries
9395
- Consider data relationships when tagging

apps/website/docs/guide.old/04-caching/03-cacheLife-function.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ async function fetchData(type: 'frequent' | 'rare') {
103103
## Best Practices
104104

105105
1. **Choose Appropriate Duration**:
106+
106107
- Use shorter TTL for frequently changing data
107108
- Use longer TTL for static content
108109
- Consider your data update patterns
109110

110111
2. **Balance Freshness and Performance**:
112+
111113
- Don't cache too long if data changes often
112114
- Don't cache too short if data is static
113115
- Consider your application's needs

apps/website/docs/guide.old/04-caching/05-revalidateTag-function.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@ setInterval(
7373
## Best Practices
7474

7575
1. **Strategic Invalidation**:
76+
7677
- Invalidate only what needs to be refreshed
7778
- Use specific tags for targeted invalidation
7879
- Consider the impact on performance
7980

8081
2. **Timing**:
82+
8183
- Invalidate after data changes
8284
- Consider using scheduled revalidation
8385
- Balance freshness and performance

apps/website/docs/guide.old/04-caching/06-cleanup-function.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ async function performConservativeCleanup() {
7272
## Best Practices
7373

7474
1. **Choose Appropriate Time Period**:
75+
7576
- Consider your application's memory constraints
7677
- Balance between memory usage and cache effectiveness
7778
- Monitor cache hit rates
7879

7980
2. **Schedule Regular Cleanup**:
81+
8082
- Set up automated cleanup tasks
8183
- Choose appropriate intervals
8284
- Handle cleanup errors gracefully

apps/website/docs/guide/14-useful-utilities/01-ratelimit.mdx

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
---
22
title: Rate Limiter
3-
description: Control request frequency with configurable limits and intervals
3+
description:
4+
Control request frequency with configurable limits and intervals
45
---
56

67
# Rate Limiter
78

8-
Think of a rate limiter like a traffic light for your application. It controls how often something can happen - like how many times a user can click a button or make an API request. This prevents your system from being overwhelmed.
9+
Think of a rate limiter like a traffic light for your application. It
10+
controls how often something can happen - like how many times a user
11+
can click a button or make an API request. This prevents your system
12+
from being overwhelmed.
913

1014
## Basic Usage
1115

@@ -27,7 +31,8 @@ if (allowed) {
2731

2832
## Custom Configuration
2933

30-
Sometimes you need different limits for different situations. You can create a custom rate limiter with specific settings:
34+
Sometimes you need different limits for different situations. You can
35+
create a custom rate limiter with specific settings:
3136

3237
```typescript
3338
import { createRateLimiter } from 'commandkit/ratelimit';
@@ -45,21 +50,28 @@ const allowed = await apiLimiter.limit('api:endpoint');
4550

4651
### Checking Remaining Requests
4752

48-
You can check how many requests a user has left and when the limit resets:
53+
You can check how many requests a user has left and when the limit
54+
resets:
4955

5056
```typescript
51-
import { getRemainingRequests, getResetTime } from 'commandkit/ratelimit';
57+
import {
58+
getRemainingRequests,
59+
getResetTime,
60+
} from 'commandkit/ratelimit';
5261

5362
const remaining = await getRemainingRequests('user:123');
5463
const resetTime = await getResetTime('user:123');
5564

5665
console.log(`${remaining} requests remaining`);
57-
console.log(`Limit resets in ${Math.round(resetTime / 1000)} seconds`);
66+
console.log(
67+
`Limit resets in ${Math.round(resetTime / 1000)} seconds`,
68+
);
5869
```
5970

6071
### Manual Reset
6172

62-
In some cases, you might want to reset a user's rate limit (like after they upgrade their account):
73+
In some cases, you might want to reset a user's rate limit (like after
74+
they upgrade their account):
6375

6476
```typescript
6577
import { resetRateLimit } from 'commandkit/ratelimit';
@@ -70,7 +82,9 @@ await resetRateLimit('user:123');
7082

7183
### Using External Storage
7284

73-
By default, rate limiters store data in memory. If you're running multiple servers, you'll want to use external storage like Redis so all servers can share the same rate limit information:
85+
By default, rate limiters store data in memory. If you're running
86+
multiple servers, you'll want to use external storage like Redis so
87+
all servers can share the same rate limit information:
7488

7589
```typescript
7690
import { RateLimiter, RateLimitStorage } from 'commandkit/ratelimit';
@@ -81,7 +95,11 @@ import { Redis } from 'ioredis';
8195
const redis = new Redis();
8296

8397
// Use Redis-based rate limit storage
84-
const limiter = new RateLimiter(10, 60000, new RedisRateLimitStorage(redis));
98+
const limiter = new RateLimiter(
99+
10,
100+
60000,
101+
new RedisRateLimitStorage(redis),
102+
);
85103
```
86104

87105
You can also use the convenience function:
@@ -106,14 +124,21 @@ const limiter = createRateLimiter({
106124
## Common Use Cases
107125

108126
- **API Rate Limiting**: Prevent users from making too many API calls
109-
- **User Action Throttling**: Limit how often users can click buttons or submit forms
127+
- **User Action Throttling**: Limit how often users can click buttons
128+
or submit forms
110129
- **Resource Access Control**: Control access to expensive operations
111-
- **Spam Prevention**: Stop automated bots from overwhelming your system
130+
- **Spam Prevention**: Stop automated bots from overwhelming your
131+
system
112132

113133
## Tips for Beginners
114134

115-
1. **Start Simple**: Use the default `ratelimit()` function for basic needs
116-
2. **Choose Good Keys**: Use descriptive keys like `user:123` or `api:endpoint` to make debugging easier
117-
3. **Set Reasonable Limits**: Don't make limits too strict or too loose - find the right balance
118-
4. **Handle Rejection**: Always check if the rate limit allows the action before proceeding
119-
5. **Consider Your Users**: Think about legitimate use cases when setting limits
135+
1. **Start Simple**: Use the default `ratelimit()` function for basic
136+
needs
137+
2. **Choose Good Keys**: Use descriptive keys like `user:123` or
138+
`api:endpoint` to make debugging easier
139+
3. **Set Reasonable Limits**: Don't make limits too strict or too
140+
loose - find the right balance
141+
4. **Handle Rejection**: Always check if the rate limit allows the
142+
action before proceeding
143+
5. **Consider Your Users**: Think about legitimate use cases when
144+
setting limits

apps/website/docs/guide/14-useful-utilities/02-mutex.mdx

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
---
22
title: Mutex
3-
description: Ensure exclusive access to shared resources with async mutex locks
3+
description:
4+
Ensure exclusive access to shared resources with async mutex locks
45
---
56

67
# Mutex
78

8-
A mutex is like a "do not disturb" sign for your data. It ensures that only one operation can access a shared resource at a time. Imagine multiple people trying to edit the same document - a mutex makes sure only one person can edit it at once.
9+
A mutex is like a "do not disturb" sign for your data. It ensures that
10+
only one operation can access a shared resource at a time. Imagine
11+
multiple people trying to edit the same document - a mutex makes sure
12+
only one person can edit it at once.
913

1014
## Basic Usage
1115

12-
The easiest way to use a mutex is with the `withMutex` function, which automatically handles locking and unlocking:
16+
The easiest way to use a mutex is with the `withMutex` function, which
17+
automatically handles locking and unlocking:
1318

1419
```typescript
1520
import { withMutex } from 'commandkit/mutex';
@@ -41,7 +46,8 @@ const result = await mutex.withLock('resource', async () => {
4146

4247
### Manual Lock Management
4348

44-
Sometimes you need more control over when locks are acquired and released:
49+
Sometimes you need more control over when locks are acquired and
50+
released:
4551

4652
```typescript
4753
import { acquireLock, releaseLock, isLocked } from 'commandkit/mutex';
@@ -65,7 +71,8 @@ console.log(`Resource is ${locked ? 'locked' : 'available'}`);
6571

6672
### Cancelling Operations
6773

68-
You can cancel a mutex operation if it takes too long or if you need to stop it for any reason:
74+
You can cancel a mutex operation if it takes too long or if you need
75+
to stop it for any reason:
6976

7077
```typescript
7178
import { withMutex } from 'commandkit/mutex';
@@ -91,7 +98,9 @@ try {
9198

9299
### Using External Storage
93100

94-
By default, mutexes store lock information in memory. If you're running multiple servers, you'll want to use external storage like Redis:
101+
By default, mutexes store lock information in memory. If you're
102+
running multiple servers, you'll want to use external storage like
103+
Redis:
95104

96105
```typescript
97106
import { Mutex, MutexStorage } from 'commandkit/mutex';
@@ -127,17 +136,26 @@ const mutex = createMutex({
127136

128137
## Common Use Cases
129138

130-
- **Database Transactions**: Ensure only one operation can modify data at a time
131-
- **File System Access**: Prevent multiple operations from writing to the same file
132-
- **Configuration Updates**: Make sure configuration changes don't conflict
133-
- **Cache Invalidation**: Control when cache is cleared to prevent race conditions
139+
- **Database Transactions**: Ensure only one operation can modify data
140+
at a time
141+
- **File System Access**: Prevent multiple operations from writing to
142+
the same file
143+
- **Configuration Updates**: Make sure configuration changes don't
144+
conflict
145+
- **Cache Invalidation**: Control when cache is cleared to prevent
146+
race conditions
134147
- **Resource Pool Management**: Manage access to limited resources
135148

136149
## Tips for Beginners
137150

138-
1. **Use `withMutex` When Possible**: It automatically handles cleanup, so you don't forget to release locks
139-
2. **Set Reasonable Timeouts**: Don't make timeouts too short (might fail unnecessarily) or too long (might hang forever)
140-
3. **Use Descriptive Names**: Give your resources meaningful names like `user:123:profile` or `database:users`
151+
1. **Use `withMutex` When Possible**: It automatically handles
152+
cleanup, so you don't forget to release locks
153+
2. **Set Reasonable Timeouts**: Don't make timeouts too short (might
154+
fail unnecessarily) or too long (might hang forever)
155+
3. **Use Descriptive Names**: Give your resources meaningful names
156+
like `user:123:profile` or `database:users`
141157
4. **Handle Errors**: Always handle cases where lock acquisition fails
142-
5. **Think About Deadlocks**: Be careful not to create situations where two operations wait for each other
143-
6. **Consider Your Setup**: Use external storage if you have multiple servers
158+
5. **Think About Deadlocks**: Be careful not to create situations
159+
where two operations wait for each other
160+
6. **Consider Your Setup**: Use external storage if you have multiple
161+
servers

0 commit comments

Comments
 (0)