@mastra/mcp 1.8.0 → 1.8.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/CHANGELOG.md +18 -0
- package/dist/_types/hono/dist/types/client/client.d.ts +4 -0
- package/dist/_types/hono/dist/types/client/fetch-result-please.d.ts +35 -0
- package/dist/_types/hono/dist/types/client/index.d.ts +7 -0
- package/dist/_types/hono/dist/types/client/types.d.ts +229 -0
- package/dist/_types/hono/dist/types/client/utils.d.ts +18 -0
- package/dist/_types/hono/dist/types/context.d.ts +455 -0
- package/dist/_types/hono/dist/types/helper/streaming/index.d.ts +8 -0
- package/dist/_types/hono/dist/types/helper/streaming/sse.d.ts +13 -0
- package/dist/_types/hono/dist/types/helper/streaming/stream.d.ts +3 -0
- package/dist/_types/hono/dist/types/helper/streaming/text.d.ts +3 -0
- package/dist/_types/hono/dist/types/hono-base.d.ts +220 -0
- package/dist/_types/hono/dist/types/hono.d.ts +19 -0
- package/dist/_types/hono/dist/types/index.d.ts +36 -0
- package/dist/_types/hono/dist/types/request/constants.d.ts +1 -0
- package/dist/_types/hono/dist/types/request.d.ts +311 -0
- package/dist/_types/hono/dist/types/router.d.ts +97 -0
- package/dist/_types/hono/dist/types/types.d.ts +573 -0
- package/dist/_types/hono/dist/types/utils/body.d.ts +79 -0
- package/dist/_types/hono/dist/types/utils/headers.d.ts +8 -0
- package/dist/_types/hono/dist/types/utils/http-status.d.ts +32 -0
- package/dist/_types/hono/dist/types/utils/mime.d.ts +70 -0
- package/dist/_types/hono/dist/types/utils/stream.d.ts +31 -0
- package/dist/_types/hono/dist/types/utils/types.d.ts +74 -0
- package/dist/_types/hono-mcp-server-sse-transport/build/index.d.ts +1 -0
- package/dist/_types/hono-mcp-server-sse-transport/build/sse.d.ts +25 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-mcp-mcp-apps.md +3 -3
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/server/server.d.ts +2 -2
- package/package.json +8 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @mastra/mcp
|
|
2
2
|
|
|
3
|
+
## 1.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Removed zod as a required peer dependency. Internal schemas now use plain JSON Schema objects instead of zod runtime. ([#16726](https://github.com/mastra-ai/mastra/pull/16726))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`cfa2e3a`](https://github.com/mastra-ai/mastra/commit/cfa2e3a5292322f48bb28b4d257d631da7f9d3cc), [`0cbece9`](https://github.com/mastra-ai/mastra/commit/0cbece9d832cb134a74cdbf3682d390a058215a4), [`2f5f58a`](https://github.com/mastra-ai/mastra/commit/2f5f58a9a8bb13bcdc6789db221eef7c9bf1ff02), [`7dfe1bc`](https://github.com/mastra-ai/mastra/commit/7dfe1bcfe71d261a6fd6bbf29b1dec49d78fb98f), [`ac442a4`](https://github.com/mastra-ai/mastra/commit/ac442a42fda0354ac2bcea772bf6691cb3e9dbb3), [`b7286f4`](https://github.com/mastra-ai/mastra/commit/b7286f4308267f5fd70e6bfee10dba9472640906), [`6096445`](https://github.com/mastra-ai/mastra/commit/60964459733f0ab384584d95e19c36607ffdf7b0), [`d72dc4b`](https://github.com/mastra-ai/mastra/commit/d72dc4b12d832546c05c20255fa96fe4eb515900), [`a481027`](https://github.com/mastra-ai/mastra/commit/a481027b549ba1018414990c8f045eaee7b9f413), [`1e5c067`](https://github.com/mastra-ai/mastra/commit/1e5c067d2e20a781af670578180d1ee249806d41), [`168fa09`](https://github.com/mastra-ai/mastra/commit/168fa09d6b39114cb8c13bd06f1dccb9bc81c6cd), [`df1947a`](https://github.com/mastra-ai/mastra/commit/df1947affa40f742067542251fac7ca759492ef4), [`ee59b74`](https://github.com/mastra-ai/mastra/commit/ee59b743ce73ad11784b4d9c6fbba8568edee1c8), [`a97b1a0`](https://github.com/mastra-ai/mastra/commit/a97b1a0abaed83946c3519d1e0f680d0815b8a67), [`008baaf`](https://github.com/mastra-ai/mastra/commit/008baafd8d851f831407045aebead5a2e3342eff), [`801baa0`](https://github.com/mastra-ai/mastra/commit/801baa07cccdbaec1d00942a92bdc831111744a2), [`8116436`](https://github.com/mastra-ai/mastra/commit/81164363eb225d774e41ff27da6a5ea611406688), [`c35b962`](https://github.com/mastra-ai/mastra/commit/c35b9625c7e854fcfdeee226a3338a750d0ff211), [`c27c4b9`](https://github.com/mastra-ai/mastra/commit/c27c4b9f137df5414fca4e45896aceccff6b0ed5), [`08b3b59`](https://github.com/mastra-ai/mastra/commit/08b3b590dd960dee6c9a6e39272f8927d803db6e), [`b3c3b18`](https://github.com/mastra-ai/mastra/commit/b3c3b189121489a3a51a8fd8204b569be9a89fe5), [`4084113`](https://github.com/mastra-ai/mastra/commit/408411370fc48a822e8b616b3b63f9409774e0e9), [`70cb714`](https://github.com/mastra-ai/mastra/commit/70cb7149c8f16f478e15b58498254a53181750a4), [`91cf0e0`](https://github.com/mastra-ai/mastra/commit/91cf0e027e511b871481a8576b56b7af83b15afd), [`7f9da22`](https://github.com/mastra-ai/mastra/commit/7f9da22efd5aa595e138a31de55a5f0f2f28b33d)]:
|
|
10
|
+
- @mastra/core@1.37.0
|
|
11
|
+
|
|
12
|
+
## 1.8.1-alpha.0
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Removed zod as a required peer dependency. Internal schemas now use plain JSON Schema objects instead of zod runtime. ([#16726](https://github.com/mastra-ai/mastra/pull/16726))
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`c35b962`](https://github.com/mastra-ai/mastra/commit/c35b9625c7e854fcfdeee226a3338a750d0ff211), [`4084113`](https://github.com/mastra-ai/mastra/commit/408411370fc48a822e8b616b3b63f9409774e0e9)]:
|
|
19
|
+
- @mastra/core@1.37.0-alpha.8
|
|
20
|
+
|
|
3
21
|
## 1.8.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Hono } from '../hono';
|
|
2
|
+
import type { UnionToIntersection } from '../utils/types';
|
|
3
|
+
import type { Client, ClientRequestOptions } from './types';
|
|
4
|
+
export declare const hc: <T extends Hono<any, any, any>, Prefix extends string = string>(baseUrl: Prefix, options?: ClientRequestOptions) => UnionToIntersection<Client<T, Prefix>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file is a modified version of `fetch-result-please` (`ofetch`), minimalized and adapted to Hono's custom needs.
|
|
3
|
+
*
|
|
4
|
+
* @link https://www.npmjs.com/package/fetch-result-please
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Smartly parses and return the consumable result from a fetch `Response`.
|
|
8
|
+
*
|
|
9
|
+
* Throwing a structured error if the response is not `ok`. ({@link DetailedError})
|
|
10
|
+
*/
|
|
11
|
+
export declare function fetchRP(fetchRes: Response | Promise<Response>): Promise<any>;
|
|
12
|
+
export declare class DetailedError extends Error {
|
|
13
|
+
/**
|
|
14
|
+
* Additional `message` that will be logged AND returned to client
|
|
15
|
+
*/
|
|
16
|
+
detail?: any;
|
|
17
|
+
/**
|
|
18
|
+
* Additional `code` that will be logged AND returned to client
|
|
19
|
+
*/
|
|
20
|
+
code?: any;
|
|
21
|
+
/**
|
|
22
|
+
* Additional value that will be logged AND NOT returned to client
|
|
23
|
+
*/
|
|
24
|
+
log?: any;
|
|
25
|
+
/**
|
|
26
|
+
* Optionally set the status code to return, in a web server context
|
|
27
|
+
*/
|
|
28
|
+
statusCode?: any;
|
|
29
|
+
constructor(message: string, options?: {
|
|
30
|
+
detail?: any;
|
|
31
|
+
code?: any;
|
|
32
|
+
statusCode?: number;
|
|
33
|
+
log?: any;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* The HTTP Client for Hono.
|
|
4
|
+
*/
|
|
5
|
+
export { hc } from './client';
|
|
6
|
+
export { parseResponse, DetailedError } from './utils';
|
|
7
|
+
export type { InferResponseType, InferRequestType, Fetch, ClientRequestOptions, ClientRequest, ClientResponse, ApplyGlobalResponse, PickResponseByStatusCode, } from './types';
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { Hono } from '../hono';
|
|
2
|
+
import type { HonoBase } from '../hono-base';
|
|
3
|
+
import type { METHODS, METHOD_NAME_ALL_LOWERCASE } from '../router';
|
|
4
|
+
import type { Endpoint, ExtractSchema, KnownResponseFormat, ResponseFormat, Schema } from '../types';
|
|
5
|
+
import type { StatusCode, SuccessStatusCode } from '../utils/http-status';
|
|
6
|
+
import type { HasRequiredKeys } from '../utils/types';
|
|
7
|
+
/**
|
|
8
|
+
* Type representing the '$all' method name
|
|
9
|
+
*/
|
|
10
|
+
type MethodNameAll = `$${typeof METHOD_NAME_ALL_LOWERCASE}`;
|
|
11
|
+
/**
|
|
12
|
+
* Type representing all standard HTTP methods prefixed with '$'
|
|
13
|
+
* e.g., '$get' | '$post' | '$put' | '$delete' | '$options' | '$patch'
|
|
14
|
+
*/
|
|
15
|
+
type StandardMethods = `$${(typeof METHODS)[number]}`;
|
|
16
|
+
/**
|
|
17
|
+
* Expands '$all' into all standard HTTP methods.
|
|
18
|
+
* If the schema contains '$all', it creates a type where all standard HTTP methods
|
|
19
|
+
* point to the same endpoint definition as '$all', while removing '$all' itself.
|
|
20
|
+
*/
|
|
21
|
+
type ExpandAllMethod<S> = MethodNameAll extends keyof S ? {
|
|
22
|
+
[M in StandardMethods]: S[MethodNameAll];
|
|
23
|
+
} & Omit<S, MethodNameAll> : S;
|
|
24
|
+
type HonoRequest = (typeof Hono.prototype)['request'];
|
|
25
|
+
export type BuildSearchParamsFn = (query: Record<string, string | string[]>) => URLSearchParams;
|
|
26
|
+
export type ClientRequestOptions<T = unknown> = {
|
|
27
|
+
fetch?: typeof fetch | HonoRequest;
|
|
28
|
+
webSocket?: (...args: ConstructorParameters<typeof WebSocket>) => WebSocket;
|
|
29
|
+
/**
|
|
30
|
+
* Standard `RequestInit`, caution that this take highest priority
|
|
31
|
+
* and could be used to overwrite things that Hono sets for you, like `body | method | headers`.
|
|
32
|
+
*
|
|
33
|
+
* If you want to add some headers, use in `headers` instead of `init`
|
|
34
|
+
*/
|
|
35
|
+
init?: RequestInit;
|
|
36
|
+
/**
|
|
37
|
+
* Custom function to serialize query parameters into URLSearchParams.
|
|
38
|
+
* By default, arrays are serialized as multiple parameters with the same key (e.g., `key=a&key=b`).
|
|
39
|
+
* You can provide a custom function to change this behavior, for example to use bracket notation (e.g., `key[]=a&key[]=b`).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const client = hc('http://localhost', {
|
|
44
|
+
* buildSearchParams: (query) => {
|
|
45
|
+
* return new URLSearchParams(qs.stringify(query))
|
|
46
|
+
* }
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
buildSearchParams?: BuildSearchParamsFn;
|
|
51
|
+
} & (keyof T extends never ? {
|
|
52
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
53
|
+
} : {
|
|
54
|
+
headers: T | (() => T | Promise<T>);
|
|
55
|
+
});
|
|
56
|
+
export type ClientRequest<Prefix extends string, Path extends string, S extends Schema> = {
|
|
57
|
+
[M in keyof ExpandAllMethod<S>]: ExpandAllMethod<S>[M] extends Endpoint & {
|
|
58
|
+
input: infer R;
|
|
59
|
+
} ? R extends object ? HasRequiredKeys<R> extends true ? (args: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<ExpandAllMethod<S>[M]>> : (args?: R, options?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<ExpandAllMethod<S>[M]>> : never : never;
|
|
60
|
+
} & {
|
|
61
|
+
$url: <const Arg extends (S[keyof S] extends {
|
|
62
|
+
input: infer R;
|
|
63
|
+
} ? R extends {
|
|
64
|
+
param: infer P;
|
|
65
|
+
} ? R extends {
|
|
66
|
+
query: infer Q;
|
|
67
|
+
} ? {
|
|
68
|
+
param: P;
|
|
69
|
+
query: Q;
|
|
70
|
+
} : {
|
|
71
|
+
param: P;
|
|
72
|
+
} : R extends {
|
|
73
|
+
query: infer Q;
|
|
74
|
+
} ? {
|
|
75
|
+
query: Q;
|
|
76
|
+
} : {} : {}) | undefined = undefined>(arg?: Arg) => HonoURL<Prefix, Path, Arg>;
|
|
77
|
+
$path: <const Arg extends (S[keyof S] extends {
|
|
78
|
+
input: infer R;
|
|
79
|
+
} ? R extends {
|
|
80
|
+
param: infer P;
|
|
81
|
+
} ? R extends {
|
|
82
|
+
query: infer Q;
|
|
83
|
+
} ? {
|
|
84
|
+
param: P;
|
|
85
|
+
query: Q;
|
|
86
|
+
} : {
|
|
87
|
+
param: P;
|
|
88
|
+
} : R extends {
|
|
89
|
+
query: infer Q;
|
|
90
|
+
} ? {
|
|
91
|
+
query: Q;
|
|
92
|
+
} : {} : {}) | undefined = undefined>(arg?: Arg) => BuildPath<Path, Arg>;
|
|
93
|
+
} & (S['$get'] extends {
|
|
94
|
+
outputFormat: 'ws';
|
|
95
|
+
} ? S['$get'] extends {
|
|
96
|
+
input: infer I;
|
|
97
|
+
} ? {
|
|
98
|
+
$ws: (args?: I) => WebSocket;
|
|
99
|
+
} : {} : {});
|
|
100
|
+
type ClientResponseOfEndpoint<T extends Endpoint = Endpoint> = T extends {
|
|
101
|
+
output: infer O;
|
|
102
|
+
outputFormat: infer F;
|
|
103
|
+
status: infer S;
|
|
104
|
+
} ? ClientResponse<O, S extends number ? S : never, F extends ResponseFormat ? F : never> : never;
|
|
105
|
+
export interface ClientResponse<T, U extends number = StatusCode, F extends ResponseFormat = ResponseFormat> {
|
|
106
|
+
readonly body: ReadableStream | null;
|
|
107
|
+
readonly bodyUsed: boolean;
|
|
108
|
+
ok: U extends SuccessStatusCode ? true : U extends Exclude<StatusCode, SuccessStatusCode> ? false : boolean;
|
|
109
|
+
redirected: boolean;
|
|
110
|
+
status: U;
|
|
111
|
+
statusText: string;
|
|
112
|
+
type: 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect';
|
|
113
|
+
headers: Headers;
|
|
114
|
+
url: string;
|
|
115
|
+
redirect(url: string, status: number): Response;
|
|
116
|
+
clone(): Response;
|
|
117
|
+
bytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
118
|
+
json(): F extends 'text' ? Promise<never> : F extends 'json' ? Promise<T> : Promise<unknown>;
|
|
119
|
+
text(): F extends 'text' ? (T extends string ? Promise<T> : Promise<never>) : Promise<string>;
|
|
120
|
+
blob(): Promise<Blob>;
|
|
121
|
+
formData(): Promise<FormData>;
|
|
122
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
123
|
+
}
|
|
124
|
+
type BuildSearch<Arg, Key extends 'query'> = Arg extends {
|
|
125
|
+
[K in Key]: infer Query;
|
|
126
|
+
} ? IsEmptyObject<Query> extends true ? '' : `?${string}` : '';
|
|
127
|
+
type BuildPathname<P extends string, Arg> = Arg extends {
|
|
128
|
+
param: infer Param;
|
|
129
|
+
} ? `${ApplyParam<TrimStartSlash<P>, Param>}` : `/${TrimStartSlash<P>}`;
|
|
130
|
+
type BuildPath<P extends string, Arg> = `${BuildPathname<P, Arg>}${BuildSearch<Arg, 'query'>}`;
|
|
131
|
+
type BuildTypedURL<Protocol extends string, Host extends string, Port extends string, P extends string, Arg> = TypedURL<`${Protocol}:`, Host, Port, BuildPathname<P, Arg>, BuildSearch<Arg, 'query'>>;
|
|
132
|
+
type HonoURL<Prefix extends string, Path extends string, Arg> = IsLiteral<Prefix> extends true ? TrimEndSlash<Prefix> extends `${infer Protocol}://${infer Rest}` ? Rest extends `${infer Hostname}/${infer P}` ? ParseHostName<Hostname> extends [infer Host extends string, infer Port extends string] ? BuildTypedURL<Protocol, Host, Port, P, Arg> : never : ParseHostName<Rest> extends [infer Host extends string, infer Port extends string] ? BuildTypedURL<Protocol, Host, Port, Path, Arg> : never : URL : URL;
|
|
133
|
+
type ParseHostName<T extends string> = T extends `${infer Host}:${infer Port}` ? [Host, Port] : [T, ''];
|
|
134
|
+
type TrimStartSlash<T extends string> = T extends `/${infer R}` ? TrimStartSlash<R> : T;
|
|
135
|
+
type TrimEndSlash<T extends string> = T extends `${infer R}/` ? TrimEndSlash<R> : T;
|
|
136
|
+
type IsLiteral<T extends string> = [T] extends [never] ? false : string extends T ? false : true;
|
|
137
|
+
type ApplyParam<Path extends string, P, Result extends string = ''> = Path extends `${infer Head}/${infer Rest}` ? Head extends `:${infer Param}` ? P extends Record<Param, infer Value extends string> ? IsLiteral<Value> extends true ? ApplyParam<Rest, P, `${Result}/${Value & string}`> : ApplyParam<Rest, P, `${Result}/${Head}`> : ApplyParam<Rest, P, `${Result}/${Head}`> : ApplyParam<Rest, P, `${Result}/${Head}`> : Path extends `:${infer Param}` ? P extends Record<Param, infer Value extends string> ? IsLiteral<Value> extends true ? `${Result}/${Value & string}` : `${Result}/${Path}` : `${Result}/${Path}` : `${Result}/${Path}`;
|
|
138
|
+
type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
139
|
+
export interface TypedURL<Protocol extends string, Hostname extends string, Port extends string, Pathname extends string, Search extends string> extends URL {
|
|
140
|
+
protocol: Protocol;
|
|
141
|
+
hostname: Hostname;
|
|
142
|
+
port: Port;
|
|
143
|
+
host: Port extends '' ? Hostname : `${Hostname}:${Port}`;
|
|
144
|
+
origin: `${Protocol}//${Hostname}${Port extends '' ? '' : `:${Port}`}`;
|
|
145
|
+
pathname: Pathname;
|
|
146
|
+
search: Search;
|
|
147
|
+
href: `${Protocol}//${Hostname}${Port extends '' ? '' : `:${Port}`}${Pathname}${Search}`;
|
|
148
|
+
}
|
|
149
|
+
export interface Response extends ClientResponse<unknown> {
|
|
150
|
+
}
|
|
151
|
+
export type Fetch<T> = (args?: InferRequestType<T>, opt?: ClientRequestOptions) => Promise<ClientResponseOfEndpoint<InferEndpointType<T>>>;
|
|
152
|
+
type InferEndpointType<T> = T extends (args: infer R, options: any | undefined) => Promise<infer U> ? U extends ClientResponse<infer O, infer S, infer F> ? {
|
|
153
|
+
input: NonNullable<R>;
|
|
154
|
+
output: O;
|
|
155
|
+
outputFormat: F;
|
|
156
|
+
status: S;
|
|
157
|
+
} extends Endpoint ? {
|
|
158
|
+
input: NonNullable<R>;
|
|
159
|
+
output: O;
|
|
160
|
+
outputFormat: F;
|
|
161
|
+
status: S;
|
|
162
|
+
} : never : never : never;
|
|
163
|
+
export type InferResponseType<T, U extends StatusCode = StatusCode> = InferResponseTypeFromEndpoint<InferEndpointType<T>, U>;
|
|
164
|
+
type InferResponseTypeFromEndpoint<T extends Endpoint, U extends StatusCode> = T extends {
|
|
165
|
+
output: infer O;
|
|
166
|
+
status: infer S;
|
|
167
|
+
} ? S extends U ? O : never : never;
|
|
168
|
+
export type InferRequestType<T> = T extends (args: infer R, options: any | undefined) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
169
|
+
export type InferRequestOptionsType<T> = T extends (args: any, options: infer R) => Promise<ClientResponse<unknown>> ? NonNullable<R> : never;
|
|
170
|
+
/**
|
|
171
|
+
* Filter a ClientResponse type so it only includes responses of specific status codes.
|
|
172
|
+
*/
|
|
173
|
+
export type FilterClientResponseByStatusCode<T extends ClientResponse<any, any, any>, U extends number = StatusCode> = T extends ClientResponse<infer RT, infer RC, infer RF> ? RC extends U ? ClientResponse<RT, RC, RF> : never : never;
|
|
174
|
+
type PathToChain<Prefix extends string, Path extends string, E extends Schema, Original extends string = Path> = Path extends `/${infer P}` ? PathToChain<Prefix, P, E, Path> : Path extends `${infer P}/${infer R}` ? {
|
|
175
|
+
[K in P]: PathToChain<Prefix, R, E, Original>;
|
|
176
|
+
} : {
|
|
177
|
+
[K in Path extends '' ? 'index' : Path]: ClientRequest<Prefix, Original, E extends Record<string, unknown> ? E[Original] : never>;
|
|
178
|
+
};
|
|
179
|
+
export type Client<T, Prefix extends string> = T extends HonoBase<any, infer S, any> ? S extends Record<infer K, Schema> ? K extends string ? PathToChain<Prefix, K, S> : never : never : never;
|
|
180
|
+
export type Callback = (opts: CallbackOptions) => unknown;
|
|
181
|
+
interface CallbackOptions {
|
|
182
|
+
path: string[];
|
|
183
|
+
args: any[];
|
|
184
|
+
}
|
|
185
|
+
export type ObjectType<T = unknown> = {
|
|
186
|
+
[key: string]: T;
|
|
187
|
+
};
|
|
188
|
+
type GlobalResponseDefinition = {
|
|
189
|
+
[S in StatusCode]?: {
|
|
190
|
+
[F in KnownResponseFormat]?: unknown;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
type ToEndpoints<Def extends GlobalResponseDefinition, R> = {
|
|
194
|
+
[S in keyof Def & StatusCode]: {
|
|
195
|
+
[F in keyof Def[S] & KnownResponseFormat]: Omit<R, 'output' | 'status' | 'outputFormat'> & {
|
|
196
|
+
output: Def[S][F];
|
|
197
|
+
status: S;
|
|
198
|
+
outputFormat: F;
|
|
199
|
+
};
|
|
200
|
+
}[keyof Def[S] & KnownResponseFormat];
|
|
201
|
+
}[keyof Def & StatusCode];
|
|
202
|
+
type ModRoute<R, Def extends GlobalResponseDefinition> = R extends Endpoint ? R | ToEndpoints<Def, R> : R;
|
|
203
|
+
type ModSchema<D, Def extends GlobalResponseDefinition> = {
|
|
204
|
+
[K in keyof D]: {
|
|
205
|
+
[M in keyof D[K]]: ModRoute<D[K][M], Def>;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
export type ApplyGlobalResponse<App, Def extends GlobalResponseDefinition> = App extends HonoBase<infer E, infer _ extends Schema, infer B> ? ModSchema<ExtractSchema<App>, Def> extends infer S extends Schema ? Hono<E, S, B> : never : never;
|
|
209
|
+
type PickRoute<R, U extends StatusCode> = R extends Endpoint ? R extends {
|
|
210
|
+
status: U;
|
|
211
|
+
} ? R : never : R;
|
|
212
|
+
type PickSchema<D, U extends StatusCode> = {
|
|
213
|
+
[K in keyof D]: {
|
|
214
|
+
[M in keyof D[K]]: PickRoute<D[K][M], U>;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Keep only specific status code responses from all routes of an app.
|
|
219
|
+
* Useful when error responses are handled centrally (e.g., via custom fetch)
|
|
220
|
+
* and you want the client to only expose success response types.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* type AppSuccessOnly = PickResponseByStatusCode<typeof app, 200>
|
|
225
|
+
* const client = hc<AppSuccessOnly>('http://localhost')
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export type PickResponseByStatusCode<App, U extends StatusCode> = App extends HonoBase<infer E, infer _ extends Schema, infer B> ? PickSchema<ExtractSchema<App>, U> extends infer S extends Schema ? Hono<E, S, B> : never : never;
|
|
229
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ClientErrorStatusCode, ContentfulStatusCode, ServerErrorStatusCode } from '../utils/http-status';
|
|
2
|
+
import { DetailedError } from './fetch-result-please';
|
|
3
|
+
import type { ClientResponse, FilterClientResponseByStatusCode } from './types';
|
|
4
|
+
export { DetailedError };
|
|
5
|
+
export declare const mergePath: (base: string, path: string) => string;
|
|
6
|
+
export declare const replaceUrlParam: (urlString: string, params: Record<string, string | undefined>) => string;
|
|
7
|
+
export declare const buildSearchParams: (query: Record<string, string | string[]>) => URLSearchParams;
|
|
8
|
+
export declare const replaceUrlProtocol: (urlString: string, protocol: "ws" | "http") => string;
|
|
9
|
+
export declare const removeIndexString: (urlString: string) => string;
|
|
10
|
+
export declare function deepMerge<T>(target: T, source: Record<string, unknown>): T;
|
|
11
|
+
/**
|
|
12
|
+
* Shortcut to get a consumable response from `hc`'s fetch calls (Response), with types inference.
|
|
13
|
+
*
|
|
14
|
+
* Smartly parse the response data, throwing a structured error if the response is not `ok`. ({@link DetailedError})
|
|
15
|
+
*
|
|
16
|
+
* @example const result = await parseResponse(client.posts.$get())
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseResponse<T extends ClientResponse<any>>(fetchRes: T | Promise<T>): Promise<FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends never ? undefined : FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends ClientResponse<infer RT, infer _, infer RF> ? RF extends 'json' ? RT : RT extends string ? RT : string : undefined>;
|