@firtoz/hono-fetcher 2.7.0 → 2.7.1
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/dist/honoDirectFetcher.d.ts +3 -7
- package/dist/honoDoFetcher.d.ts +12 -15
- package/dist/honoFetcher.d.ts +17 -19
- package/dist/index.d.ts +5 -5
- package/package.json +6 -6
- package/src/index.ts +26 -24
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { Hono } from
|
|
2
|
-
import { TypedHonoFetcher } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare const honoDirectFetcher: <T extends Hono>(baseUrl: string) => TypedHonoFetcher<T>;
|
|
6
|
-
|
|
7
|
-
export { honoDirectFetcher };
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import { type TypedHonoFetcher } from "./honoFetcher";
|
|
3
|
+
export declare const honoDirectFetcher: <T extends Hono>(baseUrl: string) => TypedHonoFetcher<T>;
|
package/dist/honoDoFetcher.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ExtractSchema } from
|
|
3
|
-
import { BaseDisposableTypedHonoFetcher, TypedHonoFetcher } from
|
|
4
|
-
|
|
5
|
-
type DOWithHonoApp<S extends Schema = Schema> = Rpc.DurableObjectBranded & {
|
|
1
|
+
import type { Hono, Schema } from "hono";
|
|
2
|
+
import type { ExtractSchema } from "hono/types";
|
|
3
|
+
import { type BaseDisposableTypedHonoFetcher, type TypedHonoFetcher } from "./honoFetcher";
|
|
4
|
+
export type DOWithHonoApp<S extends Schema = Schema> = Rpc.DurableObjectBranded & {
|
|
6
5
|
app: Hono<any, S>;
|
|
7
6
|
};
|
|
8
|
-
type DOSchemaMap<T extends DOWithHonoApp> = T extends DOWithHonoApp ? ExtractSchema<T["app"]> : never;
|
|
9
|
-
type DOSchemaKeys<T extends DOWithHonoApp> = string & keyof DOSchemaMap<T>;
|
|
10
|
-
type DOStubSchema<T extends DurableObjectStub> = T extends DurableObjectStub<infer S> ? S extends DOWithHonoApp ? ExtractSchema<S["app"]> : never : never;
|
|
7
|
+
export type DOSchemaMap<T extends DOWithHonoApp> = T extends DOWithHonoApp ? ExtractSchema<T["app"]> : never;
|
|
8
|
+
export type DOSchemaKeys<T extends DOWithHonoApp> = string & keyof DOSchemaMap<T>;
|
|
9
|
+
export type DOStubSchema<T extends DurableObjectStub> = T extends DurableObjectStub<infer S> ? S extends DOWithHonoApp ? ExtractSchema<S["app"]> : never : never;
|
|
11
10
|
/**
|
|
12
11
|
* Fetcher for a **real** `DurableObjectStub`: HTTP results are {@link RpcDisposableJsonResponse}
|
|
13
12
|
* and `websocket` returns `Response & Disposable`, matching Workers RPC when the runtime attaches
|
|
@@ -17,7 +16,7 @@ type DOStubSchema<T extends DurableObjectStub> = T extends DurableObjectStub<inf
|
|
|
17
16
|
*
|
|
18
17
|
* @see https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
19
18
|
*/
|
|
20
|
-
type TypedDoFetcher<T extends DurableObjectStub> = BaseDisposableTypedHonoFetcher<Hono<any, DOStubSchema<T>>>;
|
|
19
|
+
export type TypedDoFetcher<T extends DurableObjectStub> = BaseDisposableTypedHonoFetcher<Hono<any, DOStubSchema<T>>>;
|
|
21
20
|
/**
|
|
22
21
|
* Argument to {@link honoDoFetcher}: a **full** {@link DurableObjectStub} (production) or a minimal
|
|
23
22
|
* **`{ fetch }`** mock. Only the full stub is typed as {@link TypedDoFetcher} with disposable RPC
|
|
@@ -26,7 +25,7 @@ type TypedDoFetcher<T extends DurableObjectStub> = BaseDisposableTypedHonoFetche
|
|
|
26
25
|
*
|
|
27
26
|
* @see https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
28
27
|
*/
|
|
29
|
-
type HonoDoFetcherStubInput = DurableObjectStub<DOWithHonoApp> | Pick<DurableObjectStub<DOWithHonoApp>, "fetch">;
|
|
28
|
+
export type HonoDoFetcherStubInput = DurableObjectStub<DOWithHonoApp> | Pick<DurableObjectStub<DOWithHonoApp>, "fetch">;
|
|
30
29
|
/**
|
|
31
30
|
* Typed fetcher for a Durable Object stub.
|
|
32
31
|
*
|
|
@@ -43,8 +42,6 @@ type HonoDoFetcherStubInput = DurableObjectStub<DOWithHonoApp> | Pick<DurableObj
|
|
|
43
42
|
*
|
|
44
43
|
* @see https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
45
44
|
*/
|
|
46
|
-
declare const honoDoFetcher: <const T extends HonoDoFetcherStubInput>(durableObject: T) => T extends DurableObjectStub<DOWithHonoApp> ? TypedDoFetcher<T> & Disposable : TypedHonoFetcher<Hono> & Disposable;
|
|
47
|
-
declare const honoDoFetcherWithName: <const T extends Rpc.DurableObjectBranded & DOWithHonoApp>(namespace: DurableObjectNamespace<T>, name: string) => TypedDoFetcher<DurableObjectStub<T>> & Disposable;
|
|
48
|
-
declare const honoDoFetcherWithId: <const T extends Rpc.DurableObjectBranded & DOWithHonoApp>(namespace: DurableObjectNamespace<T>, id: string) => TypedDoFetcher<DurableObjectStub<T>> & Disposable;
|
|
49
|
-
|
|
50
|
-
export { type DOSchemaKeys, type DOSchemaMap, type DOStubSchema, type DOWithHonoApp, type HonoDoFetcherStubInput, type TypedDoFetcher, honoDoFetcher, honoDoFetcherWithId, honoDoFetcherWithName };
|
|
45
|
+
export declare const honoDoFetcher: <const T extends HonoDoFetcherStubInput>(durableObject: T) => T extends DurableObjectStub<DOWithHonoApp> ? TypedDoFetcher<T> & Disposable : TypedHonoFetcher<Hono> & Disposable;
|
|
46
|
+
export declare const honoDoFetcherWithName: <const T extends Rpc.DurableObjectBranded & DOWithHonoApp>(namespace: DurableObjectNamespace<T>, name: string) => TypedDoFetcher<DurableObjectStub<T>> & Disposable;
|
|
47
|
+
export declare const honoDoFetcherWithId: <const T extends Rpc.DurableObjectBranded & DOWithHonoApp>(namespace: DurableObjectNamespace<T>, id: string) => TypedDoFetcher<DurableObjectStub<T>> & Disposable;
|
package/dist/honoFetcher.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Hono } from
|
|
2
|
-
import { ExtractSchema } from
|
|
3
|
-
|
|
4
|
-
type ParsePathParams<T extends string> = T extends `${infer _Start}/:${infer Param}/${infer Rest}` ? {
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import type { ExtractSchema } from "hono/types";
|
|
3
|
+
export type ParsePathParams<T extends string> = T extends `${infer _Start}/:${infer Param}/${infer Rest}` ? {
|
|
5
4
|
[K in Param | keyof ParsePathParams<`/${Rest}`>]: string;
|
|
6
5
|
} : T extends `${infer _Start}/:${infer Param}` ? {
|
|
7
6
|
[K in Param]: string;
|
|
8
7
|
} : never;
|
|
9
|
-
type HttpMethod = "get" | "post" | "put" | "delete" | "patch";
|
|
10
|
-
type HonoSchemaKeys<T extends Hono> = string & keyof ExtractSchema<T>;
|
|
8
|
+
export type HttpMethod = "get" | "post" | "put" | "delete" | "patch";
|
|
9
|
+
export type HonoSchemaKeys<T extends Hono> = string & keyof ExtractSchema<T>;
|
|
11
10
|
type FilterKeysByMethod<TApp extends ExtractSchema<unknown>, TMethod extends HttpMethod> = {
|
|
12
11
|
[K in keyof TApp as TApp[K] extends {
|
|
13
12
|
[key in `$${TMethod}`]: unknown;
|
|
@@ -16,7 +15,7 @@ type FilterKeysByMethod<TApp extends ExtractSchema<unknown>, TMethod extends Htt
|
|
|
16
15
|
type HonoSchema<TApp extends Hono> = {
|
|
17
16
|
[M in HttpMethod]: FilterKeysByMethod<ExtractSchema<TApp>, M>;
|
|
18
17
|
};
|
|
19
|
-
type JsonResponse<T> = Omit<Response, "json"> & {
|
|
18
|
+
export type JsonResponse<T> = Omit<Response, "json"> & {
|
|
20
19
|
json: () => Promise<T>;
|
|
21
20
|
};
|
|
22
21
|
/**
|
|
@@ -28,14 +27,14 @@ type JsonResponse<T> = Omit<Response, "json"> & {
|
|
|
28
27
|
*
|
|
29
28
|
* @see https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
30
29
|
*/
|
|
31
|
-
type RpcDisposableJsonResponse<T> = JsonResponse<T> & Disposable;
|
|
30
|
+
export type RpcDisposableJsonResponse<T> = JsonResponse<T> & Disposable;
|
|
32
31
|
type HasPathParams<T extends string> = T extends `${string}:${string}` ? true : false;
|
|
33
32
|
/**
|
|
34
33
|
* Values allowed in the optional `query` object on fetcher requests.
|
|
35
34
|
* `null` and `undefined` entries are omitted from the serialized query string.
|
|
36
35
|
*/
|
|
37
|
-
type HonoFetcherQueryParamValue = string | number | boolean;
|
|
38
|
-
type HonoFetcherQueryParams = Record<string, HonoFetcherQueryParamValue | null | undefined>;
|
|
36
|
+
export type HonoFetcherQueryParamValue = string | number | boolean;
|
|
37
|
+
export type HonoFetcherQueryParams = Record<string, HonoFetcherQueryParamValue | null | undefined>;
|
|
39
38
|
type FetcherParams<SchemaPath extends string> = HasPathParams<SchemaPath> extends true ? {
|
|
40
39
|
params: ParsePathParams<SchemaPath>;
|
|
41
40
|
query?: HonoFetcherQueryParams;
|
|
@@ -67,7 +66,7 @@ type BodyParams<TApp extends Hono, TMethod extends HttpMethod, SchemaPath extend
|
|
|
67
66
|
type AvailableMethods<T extends Hono> = {
|
|
68
67
|
[M in HttpMethod]: keyof HonoSchema<T>[M] extends never ? never : M;
|
|
69
68
|
}[HttpMethod];
|
|
70
|
-
interface WebSocketConfig {
|
|
69
|
+
export interface WebSocketConfig {
|
|
71
70
|
/**
|
|
72
71
|
* Whether to automatically call accept() on the WebSocket before returning.
|
|
73
72
|
* Defaults to true for convenience.
|
|
@@ -79,11 +78,11 @@ interface WebSocketConfig {
|
|
|
79
78
|
*/
|
|
80
79
|
autoAccept?: boolean;
|
|
81
80
|
}
|
|
82
|
-
type TypedWebSocketFetcher<T extends Hono> = <SchemaPath extends string & keyof HonoSchema<T>["get"]>(request: {
|
|
81
|
+
export type TypedWebSocketFetcher<T extends Hono> = <SchemaPath extends string & keyof HonoSchema<T>["get"]>(request: {
|
|
83
82
|
url: SchemaPath;
|
|
84
83
|
config?: WebSocketConfig;
|
|
85
84
|
} & FetcherParams<SchemaPath>) => Promise<Response>;
|
|
86
|
-
type BaseTypedHonoFetcher<T extends Hono> = {
|
|
85
|
+
export type BaseTypedHonoFetcher<T extends Hono> = {
|
|
87
86
|
[M in AvailableMethods<T>]: TypedMethodFetcher<T, M>;
|
|
88
87
|
} & (keyof HonoSchema<T>["get"] extends never ? {} : {
|
|
89
88
|
websocket: TypedWebSocketFetcher<T>;
|
|
@@ -91,7 +90,7 @@ type BaseTypedHonoFetcher<T extends Hono> = {
|
|
|
91
90
|
type TypedDisposableMethodFetcher<T extends Hono, M extends HttpMethod> = <SchemaPath extends string & keyof HonoSchema<T>[M]>(request: {
|
|
92
91
|
url: SchemaPath;
|
|
93
92
|
} & FetcherParams<SchemaPath> & (M extends "get" | "delete" ? EmptyObject : BodyParams<T, M, SchemaPath>)) => Promise<DoSchemaOutput<T, M, SchemaPath>>;
|
|
94
|
-
type TypedDisposableWebSocketFetcher<T extends Hono> = <SchemaPath extends string & keyof HonoSchema<T>["get"]>(request: {
|
|
93
|
+
export type TypedDisposableWebSocketFetcher<T extends Hono> = <SchemaPath extends string & keyof HonoSchema<T>["get"]>(request: {
|
|
95
94
|
url: SchemaPath;
|
|
96
95
|
config?: WebSocketConfig;
|
|
97
96
|
} & FetcherParams<SchemaPath>) => Promise<Response & Disposable>;
|
|
@@ -102,12 +101,11 @@ type TypedDisposableWebSocketFetcher<T extends Hono> = <SchemaPath extends strin
|
|
|
102
101
|
*
|
|
103
102
|
* @see https://developers.cloudflare.com/workers/runtime-apis/rpc/lifecycle/
|
|
104
103
|
*/
|
|
105
|
-
type BaseDisposableTypedHonoFetcher<T extends Hono> = {
|
|
104
|
+
export type BaseDisposableTypedHonoFetcher<T extends Hono> = {
|
|
106
105
|
[M in AvailableMethods<T>]: TypedDisposableMethodFetcher<T, M>;
|
|
107
106
|
} & (keyof HonoSchema<T>["get"] extends never ? {} : {
|
|
108
107
|
websocket: TypedDisposableWebSocketFetcher<T>;
|
|
109
108
|
});
|
|
110
|
-
type TypedHonoFetcher<T extends Hono> = BaseTypedHonoFetcher<T>;
|
|
111
|
-
declare const honoFetcher: <T extends Hono>(fetcher: (request: string, init?: RequestInit) => ReturnType<T["request"]> | Promise<ReturnType<T["request"]>>) => TypedHonoFetcher<T>;
|
|
112
|
-
|
|
113
|
-
export { type BaseDisposableTypedHonoFetcher, type BaseTypedHonoFetcher, type HonoFetcherQueryParamValue, type HonoFetcherQueryParams, type HonoSchemaKeys, type HttpMethod, type JsonResponse, type ParsePathParams, type RpcDisposableJsonResponse, type TypedDisposableWebSocketFetcher, type TypedHonoFetcher, type TypedWebSocketFetcher, type WebSocketConfig, honoFetcher };
|
|
109
|
+
export type TypedHonoFetcher<T extends Hono> = BaseTypedHonoFetcher<T>;
|
|
110
|
+
export declare const honoFetcher: <T extends Hono>(fetcher: (request: string, init?: RequestInit) => ReturnType<T["request"]> | Promise<ReturnType<T["request"]>>) => TypedHonoFetcher<T>;
|
|
111
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { honoDirectFetcher } from
|
|
2
|
-
export { DOSchemaKeys, DOSchemaMap, DOStubSchema, DOWithHonoApp, HonoDoFetcherStubInput, TypedDoFetcher,
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export { honoDirectFetcher } from "./honoDirectFetcher.js";
|
|
2
|
+
export type { DOSchemaKeys, DOSchemaMap, DOStubSchema, DOWithHonoApp, HonoDoFetcherStubInput, TypedDoFetcher, } from "./honoDoFetcher.js";
|
|
3
|
+
export { honoDoFetcher, honoDoFetcherWithId, honoDoFetcherWithName, } from "./honoDoFetcher.js";
|
|
4
|
+
export type { BaseDisposableTypedHonoFetcher, BaseTypedHonoFetcher, HonoFetcherQueryParamValue, HonoFetcherQueryParams, HonoSchemaKeys, HttpMethod, JsonResponse, ParsePathParams, RpcDisposableJsonResponse, TypedDisposableWebSocketFetcher, TypedHonoFetcher, TypedWebSocketFetcher, WebSocketConfig, } from "./honoFetcher.js";
|
|
5
|
+
export { honoFetcher } from "./honoFetcher.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firtoz/hono-fetcher",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"description": "Type-safe Hono API client with full TypeScript inference for routes, params, and payloads",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build": "tsup",
|
|
28
|
+
"build": "tsup && tsc -p tsconfig.emit-index-dts.json",
|
|
29
29
|
"prepack": "bun run build",
|
|
30
30
|
"typecheck": "tsgo --noEmit -p ./tsconfig.json",
|
|
31
31
|
"lint": "biome check --write src",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"url": "https://github.com/firtoz/fullstack-toolkit/issues"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@cloudflare/workers-types": "^4.
|
|
60
|
-
"hono": "^4.12.
|
|
59
|
+
"@cloudflare/workers-types": "^4.20260422.1",
|
|
60
|
+
"hono": "^4.12.14"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=18.0.0"
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
"access": "public"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@hono/node-server": "^
|
|
69
|
+
"@hono/node-server": "^2.0.0",
|
|
70
70
|
"@hono/zod-validator": "^0.7.6",
|
|
71
|
-
"bun-types": "^1.3.
|
|
71
|
+
"bun-types": "^1.3.13",
|
|
72
72
|
"zod": "^4.3.6"
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
// Convenience wrapper for direct HTTP fetching
|
|
2
|
-
export { honoDirectFetcher } from "./honoDirectFetcher";
|
|
2
|
+
export { honoDirectFetcher } from "./honoDirectFetcher.js";
|
|
3
3
|
// Durable Object integration
|
|
4
|
+
export type {
|
|
5
|
+
DOSchemaKeys,
|
|
6
|
+
DOSchemaMap,
|
|
7
|
+
DOStubSchema,
|
|
8
|
+
DOWithHonoApp,
|
|
9
|
+
HonoDoFetcherStubInput,
|
|
10
|
+
TypedDoFetcher,
|
|
11
|
+
} from "./honoDoFetcher.js";
|
|
4
12
|
export {
|
|
5
|
-
type DOSchemaKeys,
|
|
6
|
-
type DOSchemaMap,
|
|
7
|
-
type DOStubSchema,
|
|
8
|
-
type DOWithHonoApp,
|
|
9
|
-
type HonoDoFetcherStubInput,
|
|
10
13
|
honoDoFetcher,
|
|
11
14
|
honoDoFetcherWithId,
|
|
12
15
|
honoDoFetcherWithName,
|
|
13
|
-
|
|
14
|
-
} from "./honoDoFetcher";
|
|
16
|
+
} from "./honoDoFetcher.js";
|
|
15
17
|
// Core fetcher functionality
|
|
16
|
-
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} from "./honoFetcher";
|
|
18
|
+
export type {
|
|
19
|
+
BaseDisposableTypedHonoFetcher,
|
|
20
|
+
BaseTypedHonoFetcher,
|
|
21
|
+
HonoFetcherQueryParamValue,
|
|
22
|
+
HonoFetcherQueryParams,
|
|
23
|
+
HonoSchemaKeys,
|
|
24
|
+
HttpMethod,
|
|
25
|
+
JsonResponse,
|
|
26
|
+
ParsePathParams,
|
|
27
|
+
RpcDisposableJsonResponse,
|
|
28
|
+
TypedDisposableWebSocketFetcher,
|
|
29
|
+
TypedHonoFetcher,
|
|
30
|
+
TypedWebSocketFetcher,
|
|
31
|
+
WebSocketConfig,
|
|
32
|
+
} from "./honoFetcher.js";
|
|
33
|
+
export { honoFetcher } from "./honoFetcher.js";
|