kayto_ts 0.1.10 → 0.1.12

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
@@ -2,7 +2,9 @@
2
2
 
3
3
  [📦 npm: kayto_ts](https://www.npmjs.com/package/kayto_ts)
4
4
 
5
- 🚀 Build robust API integrations faster with `kayto_ts`.
5
+ `kayto_ts` is a type-safe HTTP client that works in pair with `kayto` 🦀 (Rust).
6
+
7
+ `kayto` generates `schema.ts` from your OpenAPI spec, and `kayto_ts` uses that schema to provide strongly-typed requests, responses, and hooks across any TypeScript platform: browser, Bun, Node.js, Deno, and more.
6
8
 
7
9
  - 🔒 End-to-end type safety for `method + path + params + body + response`
8
10
  - ⚡ Zero-boilerplate HTTP client usage with generated schema types
@@ -38,7 +40,7 @@ kayto --lang ts --input "https://example.com/openapi.json" --output "generated/s
38
40
  If you generate one schema file per microservice, keep clients centralized in one place.
39
41
 
40
42
  ```ts
41
- import { clientApi, type EndpointsMap } from "kayto_ts";
43
+ import { clientApi } from "kayto_ts";
42
44
  import type { Endpoints as AccountsEndpoints } from "./schemas/accounts";
43
45
  import type { Endpoints as BillingEndpoints } from "./schemas/billing";
44
46
  import type { Endpoints as NotificationsEndpoints } from "./schemas/notifications";
@@ -49,7 +51,7 @@ const SERVICE_URLS = {
49
51
  notifications: "https://notifications.example.com",
50
52
  } as const;
51
53
 
52
- function createServiceClient<TEndpoints extends EndpointsMap>(baseUrl: string) {
54
+ function createServiceClient<TEndpoints>(baseUrl: string) {
53
55
  return clientApi<TEndpoints>({
54
56
  baseUrl,
55
57
  onRequest: ({ init }) => {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { type Api, type ClientConfig, type EndpointsMap } from "./types.js";
2
- export type { Api, ClientConfig, ClientError, ClientHooks, EndpointsMap, EndpointOf, EndpointResponseMap, EndpointResult, FetchResult, RequestInput, RequestOptions, } from "./types.js";
3
- export declare function clientApi<Endpoints extends EndpointsMap>(config?: ClientConfig): Api<Endpoints>;
1
+ import { type Api, type ClientConfig, type PartialEndpointsMap } from "./types.js";
2
+ export type { Api, ClientConfig, ClientError, ClientHooks, EndpointsMap, PartialEndpointsMap, HttpMethod, EndpointOf, EndpointResponseMap, EndpointResult, FetchResult, RequestInput, RequestOptions, } from "./types.js";
3
+ export declare function clientApi<Endpoints extends PartialEndpointsMap>(config?: ClientConfig): Api<Endpoints>;
package/dist/index.js CHANGED
@@ -107,10 +107,10 @@ export function clientApi(config = {}) {
107
107
  return { ok: true, responses, response };
108
108
  };
109
109
  return {
110
- get: (path, ...args) => request("get", path, args[0]),
111
- post: (path, ...args) => request("post", path, args[0]),
112
- put: (path, ...args) => request("put", path, args[0]),
113
- patch: (path, ...args) => request("patch", path, args[0]),
114
- delete: (path, ...args) => request("delete", path, args[0]),
110
+ get: ((path, ...args) => request("get", path, args[0])),
111
+ post: ((path, ...args) => request("post", path, args[0])),
112
+ put: ((path, ...args) => request("put", path, args[0])),
113
+ patch: ((path, ...args) => request("patch", path, args[0])),
114
+ delete: ((path, ...args) => request("delete", path, args[0])),
115
115
  };
116
116
  }
package/dist/types.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export type EndpointsMap = {
2
- get: Record<PropertyKey, unknown>;
3
- post: Record<PropertyKey, unknown>;
4
- put: Record<PropertyKey, unknown>;
5
- patch: Record<PropertyKey, unknown>;
6
- delete: Record<PropertyKey, unknown>;
1
+ export type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
2
+ export type EndpointsMap = Record<HttpMethod, Record<PropertyKey, unknown>>;
3
+ export type PartialEndpointsMap = Partial<EndpointsMap>;
4
+ export type EnsureRecord<T> = T extends Record<PropertyKey, unknown> ? T : Record<never, never>;
5
+ export type NormalizeEndpoints<Endpoints extends PartialEndpointsMap> = {
6
+ [Method in HttpMethod]: EnsureRecord<Endpoints[Method]>;
7
7
  };
8
- export type EndpointOf<Endpoints extends EndpointsMap, Method extends keyof EndpointsMap, Path extends keyof EndpointsMap[Method]> = Endpoints[Method][Path];
8
+ export type EndpointOf<Endpoints extends PartialEndpointsMap, Method extends HttpMethod, Path extends keyof NormalizeEndpoints<Endpoints>[Method]> = NormalizeEndpoints<Endpoints>[Method][Path];
9
9
  export type EndpointParams<E> = E extends {
10
10
  params: infer P;
11
11
  } ? P : never;
@@ -54,22 +54,22 @@ export type RequestInput<E> = RequestOptions & ([EndpointParams<E>] extends [nev
54
54
  body: EndpointBody<E>;
55
55
  });
56
56
  export type RequestArgs<E> = [EndpointBody<E>] extends [never] ? [input?: RequestInput<E>] : [input: RequestInput<E>];
57
- export type Api<Endpoints extends EndpointsMap> = {
58
- [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>>>;
57
+ export type Api<Endpoints extends PartialEndpointsMap> = {
58
+ [Method in HttpMethod]: <Path extends Extract<keyof NormalizeEndpoints<Endpoints>[Method], string>>(path: Path, ...args: RequestArgs<EndpointOf<Endpoints, Method, Path>>) => Promise<FetchResult<EndpointOf<Endpoints, Method, Path>>>;
59
59
  };
60
60
  export type RequestHookContext = {
61
- method: keyof EndpointsMap;
61
+ method: HttpMethod;
62
62
  path: string;
63
63
  init: RequestInit;
64
64
  };
65
65
  export type ResponseHookContext = {
66
- method: keyof EndpointsMap;
66
+ method: HttpMethod;
67
67
  path: string;
68
68
  response: Response;
69
69
  durationMs: number;
70
70
  };
71
71
  export type ResponseInterceptorContext = {
72
- method: keyof EndpointsMap;
72
+ method: HttpMethod;
73
73
  path: string;
74
74
  response: Response;
75
75
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kayto_ts",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Type-safe HTTP client for working with kayto-generated endpoint schemas.",
5
5
  "repository": {
6
6
  "type": "git",