Skip to content

Commit b54b195

Browse files
Copilothckhanh
andcommitted
Add Copilot instructions for repository
Co-authored-by: hckhanh <[email protected]>
1 parent b4da9d5 commit b54b195

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

.github/copilot-instructions.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Copilot Instructions for afetch
2+
3+
## Project Overview
4+
5+
This is **afetch**, a type-safe API client library with schema validation using Standard Schema. The project provides end-to-end type inference for API requests and responses, integrating with popular schema validation libraries like Zod, Valibot, and ArkType.
6+
7+
## Installation & Setup
8+
9+
```bash
10+
# Install dependencies
11+
npm install
12+
13+
# Build the project
14+
npm run build
15+
16+
# Run tests
17+
npm test
18+
19+
# Format code
20+
npm run format
21+
```
22+
23+
## Code Style & Standards
24+
25+
### Formatter & Linter
26+
- **Biome** is used for both formatting and linting
27+
- Single quotes for strings
28+
- Semicolons only when needed (ASI style)
29+
- Arrow function parentheses always included
30+
- 2-space indentation
31+
- Run `npm run format` to auto-fix style issues
32+
33+
### TypeScript Guidelines
34+
- Use strict TypeScript with full type safety
35+
- Leverage type inference wherever possible
36+
- Use `type` for type aliases (not `interface`) for consistency
37+
- Include JSDoc comments for public APIs
38+
- Use `.ts` extension in imports (e.g., `from './types.ts'`)
39+
- Prefer `const` over `let`
40+
- Use `unknown` instead of `any` where possible
41+
42+
### Testing
43+
- Tests are located in the `test/` directory
44+
- Use Vitest as the test framework
45+
- Mock external dependencies (e.g., `global.fetch`)
46+
- Test file naming: `*.test.ts`
47+
- Include tests for:
48+
- Happy paths
49+
- Error cases
50+
- Edge cases
51+
- Type safety validations
52+
53+
## Project Structure
54+
55+
```
56+
src/
57+
├── index.ts # Main export and createFetch function
58+
├── types.ts # Type definitions
59+
└── utils.ts # Utility functions (e.g., validation)
60+
test/
61+
└── createFetch.test.ts # Test suite
62+
```
63+
64+
## Key Dependencies
65+
66+
- **@standard-schema/spec**: Standard Schema specification for validation
67+
- **fast-url**: URL building and parameter substitution
68+
- **vitest**: Testing framework
69+
- **biome**: Linting and formatting
70+
- **tsdown**: TypeScript bundler powered by rolldown
71+
72+
## Development Workflow
73+
74+
1. Make code changes in `src/`
75+
2. Add tests in `test/`
76+
3. Run `npm run format` to auto-format
77+
4. Run `npm test` to verify tests pass
78+
5. Run `npm run build` to ensure the build succeeds
79+
80+
## API Design Principles
81+
82+
- **Type Safety First**: All APIs must provide full type inference
83+
- **Standard Schema Compatible**: Work with any schema library implementing Standard Schema
84+
- **Minimal Surface Area**: Keep the API simple and focused
85+
- **Zero Breaking Changes**: Maintain backward compatibility
86+
- **Bundle Size**: Keep dependencies minimal and bundle size small
87+
88+
## Common Tasks
89+
90+
### Adding a New Feature
91+
1. Define types in `types.ts` if needed
92+
2. Implement functionality in `index.ts` or `utils.ts`
93+
3. Add JSDoc comments with examples
94+
4. Write comprehensive tests
95+
5. Update README.md if adding public APIs
96+
97+
### Fixing a Bug
98+
1. Write a failing test that reproduces the bug
99+
2. Fix the bug in the source code
100+
3. Verify the test passes
101+
4. Add regression tests if needed
102+
103+
### Refactoring
104+
1. Ensure all tests pass before starting
105+
2. Make incremental changes
106+
3. Run tests frequently
107+
4. Do not change public API signatures without careful consideration
108+
109+
## Important Notes
110+
111+
- This project uses **Bun** in CI but supports all package managers
112+
- The package is published to both npm and JSR (Deno)
113+
- The library must remain framework-agnostic
114+
- Response validation happens automatically when schemas are provided
115+
- Default method is GET; POST is used when body is present
116+
- Custom headers merge with default headers (Content-Type: application/json)

0 commit comments

Comments
 (0)