diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..05fe660 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,162 @@ +# πŸ“„ `CONTRIBUTING.md` + +````md +# Contributing to vfetch + +Thanks for your interest in contributing. + +This project is designed to be **strict, predictable, and production-grade**. Contributions must follow the guidelines below to be accepted. + +--- + +## πŸ› οΈ Getting Started + +Clone the repo and install dependencies: + +```bash +git clone https://github.com/Gab-codes/vfetch.git +cd vfetch +npm install +``` +```` + +Run tests: + +```bash +npm run test +``` + +Run coverage: + +```bash +npm run coverage +``` + +--- + +## πŸ“ Project Structure + +``` +src/ β†’ core implementation +tests/ β†’ unit tests +tests/integration/ β†’ integration tests +``` + +Do **not** mix concerns: + +- Unit tests stay in `tests/` +- Full flow / real API tests go in `tests/integration/` + +--- + +## πŸ“ Rules & Standards + +### 1. No breaking changes without discussion + +If your change alters behavior, open an issue first. + +--- + +### 2. Tests are mandatory + +- Every feature or fix **must include tests** +- No exceptions +- If it’s not tested, it won’t be merged + +--- + +### 3. Keep types strict + +- Avoid `any` unless absolutely necessary +- Prefer explicit types +- Maintain full TypeScript safety + +--- + +### 4. Do not modify unrelated code + +Only change what your PR is responsible for. + +--- + +### 5. Maintain existing design decisions + +This library prioritizes: + +- Predictable `{ ok: boolean }` responses +- No throwing for HTTP errors +- Transport-layer responsibility only (no schema validation) + +Do not introduce patterns that break this philosophy. + +--- + +### 6. Keep it lightweight + +This is a **zero-dependency** library. + +Do not add dependencies unless absolutely justified. + +--- + +## πŸ§ͺ Testing Guidelines + +- Use **Vitest** +- Use mocks for controlled behavior +- Keep tests isolated and deterministic +- Avoid unnecessary real API calls (only in integration tests) + +--- + +## πŸš€ Pull Request Process + +1. Fork the repo +2. Create a new branch: + + ```bash + git checkout -b feat/your-feature + ``` + +3. Make your changes +4. Add/Update tests +5. Ensure everything passes: + + ```bash + npm run coverage + ``` + +6. Open a PR + +--- + +## βœ… PR Requirements + +- All tests must pass +- Coverage must not decrease +- No TypeScript errors +- Clear description of what changed and why + +--- + +## ❌ What Will Be Rejected + +- PRs without tests +- Introducing unnecessary dependencies +- Weak typing (`any` abuse) +- Breaking core API design without discussion + +--- + +## πŸ’‘ Philosophy + +vfetch is built to be: + +- Predictable +- Lightweight +- Safe under concurrency + +Keep that in mind when contributing. + +--- + +## Thanks for contributing. diff --git a/README.md b/README.md index 5040a5a..28b95f3 100644 --- a/README.md +++ b/README.md @@ -368,6 +368,12 @@ const { mutate } = useMutation({ --- +## Contributing + +Contributions are welcome. Please read the [Contributing Guide](.github/CONTRIBUTING.md) before opening a PR. + +--- + ## πŸ“„ License -MIT +MIT [License](LICENSE.md) diff --git a/src/client.ts b/src/client.ts index d583a1f..ea563b5 100644 --- a/src/client.ts +++ b/src/client.ts @@ -69,7 +69,7 @@ export class VfetchClient { /** * Internal request handler that implements the full request lifecycle. */ - private async request( + private async request( path: string, options: RequestOptions & { method: string; @@ -278,7 +278,7 @@ export class VfetchClient { * @param path - The URL path relative to baseURL * @param options - Optional request configuration */ - async get(path: string, options?: RequestOptions): Promise> { + async get(path: string, options?: RequestOptions): Promise> { return this.request(path, { ...options, method: "GET" }); } @@ -289,7 +289,7 @@ export class VfetchClient { * @param body - The request body, serialized as JSON * @param options - Optional request configuration */ - async post(path: string, body?: unknown, options?: RequestOptions): Promise> { + async post(path: string, body?: unknown, options?: RequestOptions): Promise> { return this.request(path, { ...options, method: "POST", body }); } @@ -300,7 +300,7 @@ export class VfetchClient { * @param body - The request body, serialized as JSON * @param options - Optional request configuration */ - async patch(path: string, body?: unknown, options?: RequestOptions): Promise> { + async patch(path: string, body?: unknown, options?: RequestOptions): Promise> { return this.request(path, { ...options, method: "PATCH", body }); } @@ -311,7 +311,7 @@ export class VfetchClient { * @param body - The request body, serialized as JSON * @param options - Optional request configuration */ - async put(path: string, body?: unknown, options?: RequestOptions): Promise> { + async put(path: string, body?: unknown, options?: RequestOptions): Promise> { return this.request(path, { ...options, method: "PUT", body }); } @@ -321,7 +321,7 @@ export class VfetchClient { * @param path - The URL path relative to baseURL * @param options - Optional request configuration */ - async delete(path: string, options?: RequestOptions): Promise> { + async delete(path: string, options?: RequestOptions): Promise> { return this.request(path, { ...options, method: "DELETE" }); } } diff --git a/src/index.ts b/src/index.ts index 169efbc..0330f5f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,11 +15,16 @@ import { VfetchConfig } from "./types"; * ```ts * const api = createClient({ * baseURL: "https://api.example.com", - * timeout: 5000, - * retry: 3, + * timeout: 5000, // optional - request timeout in ms + * retry: 3, // optional - retry network failures up to 3 times + * retryDelay: 1000, // optional - delay between retries in ms * }); * + * // With type annotation (fully typed) * const result = await api.get("/users"); + * + * // Without type annotation (response.data defaults to 'any') + * const result = await api.get("/users"); * ``` */ export function createClient(config: VfetchConfig): VfetchClient { diff --git a/src/types.ts b/src/types.ts index 85483f0..4deb115 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,7 +2,7 @@ * Represents a successful response from vfetch. * @template T The type of the data returned by the server. */ -export interface VfetchSuccess { +export interface VfetchSuccess { /** Indicates the request was successful. */ readonly ok: true; /** The parsed JSON data from the response. */ @@ -27,7 +27,7 @@ export interface VfetchError> { /** * The union type of all possible vfetch responses. */ -export type VfetchResponse = VfetchSuccess | VfetchError; +export type VfetchResponse = VfetchSuccess | VfetchError; /** * Configuration options for the vfetch client instance.