kayto_ts 0.1.4 → 0.1.5

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/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { type Api, type ClientConfig, type EndpointsMap } from "./types.js";
2
- export type { Api, ClientConfig, ClientError, ClientHooks, EndpointsMap, EndpointOf, FetchResult, RequestInput, RequestOptions, } from "./types.js";
2
+ export type { Api, ClientConfig, ClientError, ClientHooks, EndpointsMap, EndpointOf, EndpointResult, FetchResult, RequestInput, RequestOptions, } from "./types.js";
3
3
  export declare function clientApi<Endpoints extends EndpointsMap>(config?: ClientConfig): Api<Endpoints>;
package/dist/types.d.ts CHANGED
@@ -12,6 +12,10 @@ export type EndpointParams<E> = E extends {
12
12
  export type EndpointBody<E> = E extends {
13
13
  body: infer B;
14
14
  } ? B : never;
15
+ export type EndpointResponses<E> = E extends {
16
+ responses: infer R;
17
+ } ? R : never;
18
+ export type EndpointResult<E> = [EndpointResponses<E>] extends [never] ? unknown : EndpointResponses<E>[keyof EndpointResponses<E>];
15
19
  export type ErrorKind = "network" | "timeout" | "aborted" | "http" | "parse" | "hook";
16
20
  export type ClientError = {
17
21
  kind: ErrorKind;
@@ -48,7 +52,7 @@ export type RequestInput<E> = RequestOptions & ([EndpointParams<E>] extends [nev
48
52
  });
49
53
  export type RequestArgs<E> = [EndpointBody<E>] extends [never] ? [input?: RequestInput<E>] : [input: RequestInput<E>];
50
54
  export type Api<Endpoints extends EndpointsMap> = {
51
- [Method in keyof EndpointsMap]: <Path extends Extract<keyof Endpoints[Method], string>>(path: Path, ...args: RequestArgs<EndpointOf<Endpoints, Method, Path>>) => Promise<FetchResult<EndpointOf<Endpoints, Method, Path>>>;
55
+ [Method in keyof EndpointsMap]: <Path extends Extract<keyof Endpoints[Method], string>>(path: Path, ...args: RequestArgs<EndpointOf<Endpoints, Method, Path>>) => Promise<FetchResult<EndpointResult<EndpointOf<Endpoints, Method, Path>>>>;
52
56
  };
53
57
  export type RequestHookContext = {
54
58
  method: keyof EndpointsMap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kayto_ts",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Type-safe HTTP client for working with kayto-generated endpoint schemas.",
5
5
  "repository": "https://github.com/vladislav-yemelyanov/kayto_ts",
6
6
  "homepage": "https://www.npmjs.com/package/kayto_ts",