Releases: hckhanh/what-the-fetch
[email protected]
Patch Changes
-
4c749a5: Link "Standard Schema" references to https://standardschema.dev in documentation
Updated all unlinked "Standard Schema" text throughout documentation files (README.md, docs/content/docs/index.mdx, docs/content/docs/getting-started.mdx, and docs/content/docs/api-reference.mdx) to include hyperlinks to https://standardschema.dev, providing readers direct access to the specification.
[email protected]
Minor Changes
-
b5be69a: Add HTTP method prefix notation (@method/path) for declaring methods in API schema paths
New Feature: HTTP Method Prefix Notation
You can now declare HTTP methods directly in API schema paths using the
@method/pathsyntax:const api = { "@get/users": { response: z.array(z.object({ id: z.number(), name: z.string() })), }, "@post/users": { body: z.object({ name: z.string(), email: z.string() }), response: z.object({ id: z.number(), name: z.string(), email: z.string(), }), }, "@put/users/:id": { params: z.object({ id: z.number() }), body: z.object({ name: z.string() }), response: z.object({ id: z.number(), name: z.string() }), }, } as const;
Key Features:
- Supports all HTTP methods:
@get,@post,@put,@delete,@patch, etc. - Method names are case-insensitive (normalized to uppercase)
@get/apiis equivalent to/apiin URL, only the HTTP method differs- Backward compatible: paths without prefix continue to work as before
- Type-safe:
RequestInitparameters are nowOmit<RequestInit, 'method'>to prevent method override
Implementation:
- Added
parseMethodFromPath()utility function to extract method prefix - Updated
createFetch()to use the extracted method from path prefix - Restricted
RequestInittypes to prevent method override
- Supports all HTTP methods:
Patch Changes
-
52df593: Update
fast-urldependency to version 6.0.2 for significant performance optimizations. This release includes:- Pre-compiled regex: Path parameter regex is now extracted to module scope to avoid recompilation on every
path()call, improving efficiency for path template processing - Optimized string joining: URL joining now uses direct string indexing instead of
endsWith/startsWithmethods, with fast paths for empty strings and common scenarios, reducing unnecessary string slicing - Optimized parameter filtering: The
removeNullOrUndef()function now checks for null/undefined values before allocating new objects and uses direct property iteration instead ofObject.entries/Object.fromEntries, resulting in faster execution and less memory usage
For full details, see the fast-url 6.0.2 release notes.
- Pre-compiled regex: Path parameter regex is now extracted to module scope to avoid recompilation on every
[email protected]
Minor Changes
-
a4bafdd: This release refactors the API schema typing and validation logic to improve type safety and flexibility for API requests and responses. The main changes include replacing the
ApiResponsetype with a more generalApiDatatype, updating validation utilities to support dynamic schema options, and enhancing request validation for parameterized paths.Type system improvements
- Replaced the
ApiResponsetype with a new genericApiDatatype, allowing extraction of any schema option ('params','query','body','response') for a given API path. This change provides more flexible and accurate typing for API data throughout the codebase. - Updated all relevant type imports and exports to use
ApiDatainstead ofApiResponse, and clarified type parameter names for better readability and maintainability. [1] [2] [3]
Validation logic improvements
- Refactored the
validateDatautility to use the newApiDatatype and accept dynamic schema options, improving reusability and type safety for validating different parts of an API request or response. - Added a new
validateRequestDatautility that validatesparams,query, andbodyfor a given API path, and throws an error if a parameterized path lacks a correspondingparamsschema. This ensures runtime safety for parameterized API endpoints.
API fetch function changes
- Updated the
createFetchfunction to usevalidateRequestDatafor validating request options and to return the correctApiDatatype for responses. Also improved handling of request bodies to avoid sendingundefinedornullvalues. [1] [2]
- Replaced the
[email protected]
Major Changes
-
59203ac: Rework
createFetch()to support sharedRequestInitand improve validation logic withvalidateData().BREAKING CHANGES:
-
New
sharedInitparameter increateFetch()- Added optional third parameter
sharedInit?: RequestInittocreateFetch() - Allows setting shared request options (like headers) that apply to all requests
- Shared options are merged with per-request options
// Before const apiFetch = createFetch(api, "https://api.example.com"); // After - with shared headers const apiFetch = createFetch(api, "https://api.example.com", { headers: { Authorization: "Bearer token" }, });
- Added optional third parameter
-
Options parameter is now optional
- The second parameter of the fetch function changed from
optionstooptions? - Enables simpler API calls when no parameters are needed
// Before - required empty object await apiFetch("/users", {}); // After - options are optional await apiFetch("/users");
- The second parameter of the fetch function changed from
-
Renamed third parameter from
baseInittoinit- The per-request RequestInit parameter renamed for clarity
- This parameter is merged with
sharedInitfromcreateFetch()
// Before await apiFetch("/users", options, baseInit); // After await apiFetch("/users", options, init);
-
Body parameter in
FetchOptionsis now required when body schema exists- Changed from
{ body?: Body }to{ body: Body }in type definition - More accurately reflects that body must be provided when schema is defined
- TypeScript will now correctly require the body parameter
- Changed from
-
Validation logic refactored
- Replaced
validateResponse()withvalidateData()utility validateData()now accepts the full API path schema object and a key (e.g., 'response') to extract the specific schema- Function signature:
validateData(apiSchema: T[Path], key: keyof T[Path], data: unknown) - Extracts the schema internally using the provided key, improving flexibility and type safety
- Validation logic directly validates data against the extracted schema
- Better separation of concerns and improved type clarity
- Replaced
Migration Guide:
// Old API const apiFetch = createFetch(api, baseUrl); await apiFetch("/endpoint", options, baseInit); // New API - Basic usage (no changes needed if not using third param) const apiFetch = createFetch(api, baseUrl); await apiFetch("/endpoint", options); // New API - With shared configuration const apiFetch = createFetch(api, baseUrl, sharedInit); await apiFetch("/endpoint", options, init); // New API - Optional options parameter await apiFetch("/endpoint"); // No options needed
Files Updated:
src/index.ts: UpdatedcreateFetch()signature and implementationsrc/utils.ts: ReplacedvalidateResponse()withvalidateData()src/types.ts: UpdatedFetchOptionsto make body required when schema exists- Documentation and tests updated to reflect new API
-
Patch Changes
-
59203ac: Simplify
StandardSchemaV1type parameters across codebase and update related typings.Type Changes:
- Simplified
StandardSchemaV1usage fromStandardSchemaV1<T, unknown>toStandardSchemaV1<T>throughout the codebase - Updated
ApiSchema,FetchOptions, andApiResponsetype definitions to use the simplified signature - This change aligns with Standard Schema specification's usage patterns and improves type readability
Files Updated:
src/types.ts: Simplified allStandardSchemaV1type parameterstest/createFetch.test.ts: Updated test helper and assertionsdocs/content/docs/api-reference.mdx: Updated documentation examples
- Simplified
[email protected]
Patch Changes
- 0f609bc: Update dependency constraints for
@standard-schema/specandfast-urlto use caret ranges
[email protected]
Patch Changes
- bbf7b55: Fix the linked dependencies in JSR package
[email protected]
Patch Changes
-
6f915ca: Renamed package from
afetchtowhat-the-fetchto comply with npm naming requirements. The nameafetchwas too similar to the existinga-fetchpackage on npm.Breaking Changes:
- Package import name changed from
afetchtowhat-the-fetch - JSR package name changed from
@hckhanh/afetchto@hckhanh/what-the-fetch
Migration:
Update your imports:
// Before import { createFetch } from "afetch"; // After import { createFetch } from "what-the-fetch";
For JSR users:
# Before deno add jsr:@hckhanh/afetch # After deno add jsr:@hckhanh/what-the-fetch
No functional changes were made - only the package name was updated across all documentation, examples, and configuration files.
- Package import name changed from