@firtoz/hono-fetcher 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @firtoz/hono-fetcher
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/%40firtoz%2Fhono-fetcher.svg)](https://www.npmjs.com/package/@firtoz/hono-fetcher)
4
+ [![npm downloads](https://img.shields.io/npm/dm/%40firtoz%2Fhono-fetcher.svg)](https://www.npmjs.com/package/@firtoz/hono-fetcher)
5
+ [![license](https://img.shields.io/npm/l/%40firtoz%2Fhono-fetcher.svg)](https://github.com/firtoz/fullstack-toolkit/blob/main/LICENSE)
6
+
3
7
  Type-safe Hono API client with full TypeScript inference for routes, params, and payloads.
4
8
 
5
9
  ## Features
@@ -70,11 +74,30 @@ await api.post({
70
74
 
71
75
  ### Remote API Usage
72
76
 
77
+ For remote APIs, you have two options:
78
+
79
+ #### Option 1: Using `honoDirectFetcher` (Recommended)
80
+
81
+ ```typescript
82
+ import { honoDirectFetcher } from '@firtoz/hono-fetcher';
83
+ import type { AppType } from './backend/app'; // Your backend app type
84
+
85
+ // Simply pass the base URL
86
+ const api = honoDirectFetcher<AppType>('https://api.example.com');
87
+
88
+ // Use it immediately
89
+ const response = await api.get({
90
+ url: '/users/:id',
91
+ params: { id: '123' }
92
+ });
93
+ ```
94
+
95
+ #### Option 2: Using `honoFetcher` with Custom Fetch
96
+
73
97
  ```typescript
74
98
  import { honoFetcher } from '@firtoz/hono-fetcher';
75
99
 
76
- // For a remote API, you need to define the app type
77
- // (Usually exported from your backend)
100
+ // For more control over the fetch behavior
78
101
  const api = honoFetcher<typeof app>((url, init) => {
79
102
  return fetch(`https://api.example.com${url}`, init);
80
103
  });
@@ -83,7 +106,7 @@ const api = honoFetcher<typeof app>((url, init) => {
83
106
  ### Durable Objects
84
107
 
85
108
  ```typescript
86
- import { honoDoFetcher, honoDoFetcherWithName } from '@firtoz/hono-fetcher/honoDoFetcher';
109
+ import { honoDoFetcher, honoDoFetcherWithName } from '@firtoz/hono-fetcher';
87
110
  import { DurableObject } from 'cloudflare:workers';
88
111
  import { Hono } from 'hono';
89
112
 
@@ -140,6 +163,33 @@ A typed fetcher with methods for each HTTP verb: `get`, `post`, `put`, `delete`,
140
163
  const api = honoFetcher<typeof app>(app.request);
141
164
  ```
142
165
 
166
+ ### `honoDirectFetcher<T>(baseUrl)`
167
+
168
+ Convenience wrapper around `honoFetcher` for remote APIs. Automatically prepends the base URL to all requests.
169
+
170
+ #### Parameters
171
+
172
+ - `baseUrl: string` - The base URL of your API (e.g., `'https://api.example.com'`)
173
+
174
+ #### Returns
175
+
176
+ A typed fetcher with methods for each HTTP verb: `get`, `post`, `put`, `delete`, `patch`
177
+
178
+ #### Example
179
+
180
+ ```typescript
181
+ import { honoDirectFetcher } from '@firtoz/hono-fetcher';
182
+ import type { AppType } from './backend/app';
183
+
184
+ const api = honoDirectFetcher<AppType>('https://api.example.com');
185
+
186
+ // Make requests
187
+ const response = await api.get({
188
+ url: '/users/:id',
189
+ params: { id: '123' }
190
+ });
191
+ ```
192
+
143
193
  ### Method Signature
144
194
 
145
195
  All methods follow this signature:
@@ -318,7 +368,7 @@ type Params = ParsePathParams<'/users/:id/posts/:postId'>;
318
368
  Type for Durable Objects that expose a Hono app.
319
369
 
320
370
  ```typescript
321
- import type { DOWithHonoApp } from '@firtoz/hono-fetcher/honoDoFetcher';
371
+ import type { DOWithHonoApp } from '@firtoz/hono-fetcher';
322
372
 
323
373
  export class MyDO extends DurableObject implements DOWithHonoApp {
324
374
  app = new Hono()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/hono-fetcher",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Type-safe Hono API client with full TypeScript inference for routes, params, and payloads",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -24,7 +24,8 @@
24
24
  ],
25
25
  "scripts": {
26
26
  "typecheck": "tsc --noEmit",
27
- "lint": "biome lint src --write",
27
+ "lint": "biome check --write src",
28
+ "lint:ci": "biome ci src",
28
29
  "format": "biome format src --write",
29
30
  "test": "bun test",
30
31
  "test:watch": "bun test --watch"
@@ -51,8 +52,8 @@
51
52
  "url": "https://github.com/firtoz/fullstack-toolkit/issues"
52
53
  },
53
54
  "peerDependencies": {
54
- "@cloudflare/workers-types": "^4.20251004.0",
55
- "hono": "^4.9.9"
55
+ "@cloudflare/workers-types": "^4.20251008.0",
56
+ "hono": "^4.9.10"
56
57
  },
57
58
  "engines": {
58
59
  "node": ">=18.0.0"
@@ -61,9 +62,9 @@
61
62
  "access": "public"
62
63
  },
63
64
  "devDependencies": {
64
- "@hono/node-server": "^1.14.1",
65
- "@hono/zod-validator": "^0.4.1",
65
+ "@hono/node-server": "^1.19.5",
66
+ "@hono/zod-validator": "^0.7.3",
66
67
  "bun-types": "^1.2.23",
67
- "zod": "^3.24.1"
68
+ "zod": "^4.1.12"
68
69
  }
69
70
  }
@@ -0,0 +1,10 @@
1
+ import type { Hono } from "hono";
2
+ import { honoFetcher, type TypedHonoFetcher } from "./honoFetcher";
3
+
4
+ export const honoDirectFetcher = <T extends Hono>(
5
+ baseUrl: string,
6
+ ): TypedHonoFetcher<T> => {
7
+ return honoFetcher<T>((request, init) => {
8
+ return fetch(`${baseUrl}${request}`, init) as ReturnType<T["request"]>;
9
+ });
10
+ };
package/src/index.ts CHANGED
@@ -1,19 +1,23 @@
1
+ // Convenience wrapper for direct HTTP fetching
2
+ export { honoDirectFetcher } from "./honoDirectFetcher";
3
+ // Durable Object integration
4
+ export {
5
+ type DOSchemaKeys,
6
+ type DOSchemaMap,
7
+ type DOStubSchema,
8
+ type DOWithHonoApp,
9
+ honoDoFetcher,
10
+ honoDoFetcherWithId,
11
+ honoDoFetcherWithName,
12
+ type TypedDoFetcher,
13
+ } from "./honoDoFetcher";
14
+ // Core fetcher functionality
1
15
  export {
2
- honoFetcher,
3
16
  type BaseTypedHonoFetcher,
4
17
  type HonoSchemaKeys,
5
18
  type HttpMethod,
19
+ honoFetcher,
6
20
  type JsonResponse,
7
21
  type ParsePathParams,
8
22
  type TypedHonoFetcher,
9
23
  } from "./honoFetcher";
10
- export {
11
- honoDoFetcher,
12
- honoDoFetcherWithId,
13
- honoDoFetcherWithName,
14
- type DOSchemaKeys,
15
- type DOSchemaMap,
16
- type DOStubSchema,
17
- type DOWithHonoApp,
18
- type TypedDoFetcher,
19
- } from "./honoDoFetcher";