kayto_ts 0.1.11 → 0.1.13
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 +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/types.d.ts +12 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ kayto --lang ts --input "https://example.com/openapi.json" --output "generated/s
|
|
|
40
40
|
If you generate one schema file per microservice, keep clients centralized in one place.
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
|
-
import { clientApi, type
|
|
43
|
+
import { clientApi, type PartialEndpointsMap } from "kayto_ts";
|
|
44
44
|
import type { Endpoints as AccountsEndpoints } from "./schemas/accounts";
|
|
45
45
|
import type { Endpoints as BillingEndpoints } from "./schemas/billing";
|
|
46
46
|
import type { Endpoints as NotificationsEndpoints } from "./schemas/notifications";
|
|
@@ -51,7 +51,7 @@ const SERVICE_URLS = {
|
|
|
51
51
|
notifications: "https://notifications.example.com",
|
|
52
52
|
} as const;
|
|
53
53
|
|
|
54
|
-
function createServiceClient<TEndpoints extends
|
|
54
|
+
function createServiceClient<TEndpoints extends PartialEndpointsMap>(baseUrl: string) {
|
|
55
55
|
return clientApi<TEndpoints>({
|
|
56
56
|
baseUrl,
|
|
57
57
|
onRequest: ({ init }) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type Api, type ClientConfig, type
|
|
2
|
-
export type { Api, ClientConfig, ClientError, ClientHooks, EndpointsMap, EndpointOf, EndpointResponseMap, EndpointResult, FetchResult, RequestInput, RequestOptions, } from "./types.js";
|
|
3
|
-
export declare function clientApi<Endpoints extends
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
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
|
|
58
|
-
[Method in
|
|
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:
|
|
61
|
+
method: HttpMethod;
|
|
62
62
|
path: string;
|
|
63
63
|
init: RequestInit;
|
|
64
64
|
};
|
|
65
65
|
export type ResponseHookContext = {
|
|
66
|
-
method:
|
|
66
|
+
method: HttpMethod;
|
|
67
67
|
path: string;
|
|
68
68
|
response: Response;
|
|
69
69
|
durationMs: number;
|
|
70
70
|
};
|
|
71
71
|
export type ResponseInterceptorContext = {
|
|
72
|
-
method:
|
|
72
|
+
method: HttpMethod;
|
|
73
73
|
path: string;
|
|
74
74
|
response: Response;
|
|
75
75
|
};
|