Skip to content

Commit efc1744

Browse files
committed
Fix formatting
1 parent 84cd045 commit efc1744

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

.github/copilot-instructions.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,35 @@
22

33
## Project Architecture
44

5-
This is a **Deno-first TypeScript library** that provides a typed HTTP client with middleware support. The project builds to NPM for Node.js compatibility via `@deno/dnt`.
5+
This is a **Deno-first TypeScript library** that provides a typed HTTP client
6+
with middleware support. The project builds to NPM for Node.js compatibility via
7+
`@deno/dnt`.
68

79
### Core Components
810

9-
- **`FetchClient`** - Main HTTP client class with typed JSON methods (`getJSON`, `postJSON`, etc.)
10-
- **`FetchClientProvider`** - Singleton pattern for shared configuration, caching, and rate limiting across multiple client instances
11-
- **Middleware System** - Pipeline architecture using `FetchClientContext` and `next()` functions
12-
- **Rate Limiting** - Built-in middleware for HTTP 429 responses with `Retry-After` headers
11+
- **`FetchClient`** - Main HTTP client class with typed JSON methods (`getJSON`,
12+
`postJSON`, etc.)
13+
- **`FetchClientProvider`** - Singleton pattern for shared configuration,
14+
caching, and rate limiting across multiple client instances
15+
- **Middleware System** - Pipeline architecture using `FetchClientContext` and
16+
`next()` functions
17+
- **Rate Limiting** - Built-in middleware for HTTP 429 responses with
18+
`Retry-After` headers
1319
- **Caching** - Key-based response caching with TTL support
1420
- **Problem Details** - RFC 9457 compliant error handling
1521

1622
### Key Patterns
1723

1824
**Provider Pattern**: Use `FetchClientProvider` for shared state:
25+
1926
```typescript
2027
const provider = new FetchClientProvider();
2128
provider.enableRateLimit({ maxRequests: 100, windowMs: 60000 });
2229
const client = provider.getFetchClient();
2330
```
2431

2532
**Middleware Chain**: Always call `next()`, modify `context.response` after:
33+
2634
```typescript
2735
provider.useMiddleware(async (ctx, next) => {
2836
// pre-processing
@@ -31,41 +39,52 @@ provider.useMiddleware(async (ctx, next) => {
3139
});
3240
```
3341

34-
**Global Helpers**: Default provider instance accessible via `useFetchClient()`, `getJSON()`, `setBaseUrl()`
42+
**Global Helpers**: Default provider instance accessible via `useFetchClient()`,
43+
`getJSON()`, `setBaseUrl()`
3544

3645
## Development Workflow
3746

3847
### Essential Commands
48+
3949
- `deno task test` - Run tests with network access
4050
- `deno task build` - Generate NPM package in `./npm/`
4151
- `deno task check` - Type check all TypeScript files
4252
- `deno lint` and `deno fmt` - Linting and formatting
4353

4454
### Testing Patterns
55+
4556
- Use `FetchClientProvider` with `fakeFetch` for mocking
4657
- Rate limiting tests require `await delay()` for time windows
47-
- Cache tests use `provider.cache.has()` and `provider.cache.delete()` for assertions
58+
- Cache tests use `provider.cache.has()` and `provider.cache.delete()` for
59+
assertions
4860
- Middleware tests check `ctx.response` before/after `next()`
4961

5062
### File Organization
63+
5164
- `src/` - Core TypeScript source
5265
- `mod.ts` - Main export file
5366
- `scripts/build.ts` - Deno-to-NPM build configuration
5467
- Tests are co-located (`.test.ts` suffix)
5568

5669
## Critical Implementation Details
5770

58-
**Context Mutation**: Middleware modifies `FetchClientContext` in-place. The `response` property is null before `next()` and populated after.
71+
**Context Mutation**: Middleware modifies `FetchClientContext` in-place. The
72+
`response` property is null before `next()` and populated after.
5973

60-
**Error Handling**: Uses `expectedStatusCodes` array instead of try/catch for HTTP errors. `errorCallback` can suppress throwing.
74+
**Error Handling**: Uses `expectedStatusCodes` array instead of try/catch for
75+
HTTP errors. `errorCallback` can suppress throwing.
6176

62-
**Cache Keys**: Use array format `["resource", "id"]` for hierarchical cache invalidation.
77+
**Cache Keys**: Use array format `["resource", "id"]` for hierarchical cache
78+
invalidation.
6379

64-
**Rate Limiting**: Middleware returns HTTP 429 responses instead of throwing errors. Check `response.status === 429` for rate limit handling.
80+
**Rate Limiting**: Middleware returns HTTP 429 responses instead of throwing
81+
errors. Check `response.status === 429` for rate limit handling.
6582

66-
**Schema Validation**: Use `meta: { schema: ZodSchema }` option with middleware for runtime validation.
83+
**Schema Validation**: Use `meta: { schema: ZodSchema }` option with middleware
84+
for runtime validation.
6785

68-
**Date Parsing**: Enable with `shouldParseDates: true` option or custom `reviver` function.
86+
**Date Parsing**: Enable with `shouldParseDates: true` option or custom
87+
`reviver` function.
6988

7089
## Integration Points
7190

@@ -74,4 +93,5 @@ provider.useMiddleware(async (ctx, next) => {
7493
- **AbortController**: Native timeout and cancellation support
7594
- **Headers**: Link header parsing for pagination
7695

77-
When working on this codebase, always consider the middleware pipeline order and the provider/client distinction for shared vs. instance-specific behavior.
96+
When working on this codebase, always consider the middleware pipeline order and
97+
the provider/client distinction for shared vs. instance-specific behavior.

0 commit comments

Comments
 (0)