kayto_ts 0.1.5 → 0.1.7
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 +1 -1
- package/dist/index.js +9 -7
- package/dist/types.d.ts +9 -6
- package/package.json +12 -12
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, EndpointResult, FetchResult, RequestInput, RequestOptions, } from "./types.js";
|
|
2
|
+
export type { Api, ClientConfig, ClientError, ClientHooks, EndpointsMap, EndpointOf, EndpointResponseMap, EndpointResult, FetchResult, RequestInput, RequestOptions, } from "./types.js";
|
|
3
3
|
export declare function clientApi<Endpoints extends EndpointsMap>(config?: ClientConfig): Api<Endpoints>;
|
package/dist/index.js
CHANGED
|
@@ -86,23 +86,25 @@ export function clientApi(config = {}) {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
const bodyResult = await safeResponseBody(response);
|
|
90
|
+
if (!bodyResult.ok) {
|
|
90
91
|
return {
|
|
91
92
|
ok: false,
|
|
92
|
-
error: makeClientError("
|
|
93
|
+
error: makeClientError("parse", "Failed to parse response body", bodyResult.error),
|
|
93
94
|
response,
|
|
94
95
|
};
|
|
95
96
|
}
|
|
96
|
-
const
|
|
97
|
-
|
|
97
|
+
const responses = {
|
|
98
|
+
[response.status]: bodyResult.result,
|
|
99
|
+
};
|
|
100
|
+
if (!response.ok) {
|
|
98
101
|
return {
|
|
99
102
|
ok: false,
|
|
100
|
-
error: makeClientError("
|
|
103
|
+
error: makeClientError("http", `Request failed with status ${response.status}`, undefined, response.status),
|
|
101
104
|
response,
|
|
102
105
|
};
|
|
103
106
|
}
|
|
104
|
-
|
|
105
|
-
return { ok: true, result, response };
|
|
107
|
+
return { ok: true, responses, response };
|
|
106
108
|
};
|
|
107
109
|
return {
|
|
108
110
|
get: (path, ...args) => request("get", path, args[0]),
|
package/dist/types.d.ts
CHANGED
|
@@ -14,8 +14,11 @@ export type EndpointBody<E> = E extends {
|
|
|
14
14
|
} ? B : never;
|
|
15
15
|
export type EndpointResponses<E> = E extends {
|
|
16
16
|
responses: infer R;
|
|
17
|
-
} ? R : never;
|
|
18
|
-
export type
|
|
17
|
+
} ? R extends Record<PropertyKey, unknown> ? R : never : never;
|
|
18
|
+
export type EndpointResponseMap<E> = [EndpointResponses<E>] extends [never] ? Record<number, unknown> : Partial<EndpointResponses<E>>;
|
|
19
|
+
export type EndpointResult<E> = {
|
|
20
|
+
responses: EndpointResponseMap<E>;
|
|
21
|
+
};
|
|
19
22
|
export type ErrorKind = "network" | "timeout" | "aborted" | "http" | "parse" | "hook";
|
|
20
23
|
export type ClientError = {
|
|
21
24
|
kind: ErrorKind;
|
|
@@ -23,13 +26,13 @@ export type ClientError = {
|
|
|
23
26
|
cause?: unknown;
|
|
24
27
|
status?: number;
|
|
25
28
|
};
|
|
26
|
-
export type FetchResult<
|
|
29
|
+
export type FetchResult<E, Err = ClientError> = {
|
|
27
30
|
ok: true;
|
|
28
|
-
|
|
31
|
+
responses: EndpointResponseMap<E>;
|
|
29
32
|
response: Response;
|
|
30
33
|
} | {
|
|
31
34
|
ok: false;
|
|
32
|
-
error:
|
|
35
|
+
error: Err;
|
|
33
36
|
response?: Response;
|
|
34
37
|
};
|
|
35
38
|
export type Result<R, E = string> = {
|
|
@@ -52,7 +55,7 @@ export type RequestInput<E> = RequestOptions & ([EndpointParams<E>] extends [nev
|
|
|
52
55
|
});
|
|
53
56
|
export type RequestArgs<E> = [EndpointBody<E>] extends [never] ? [input?: RequestInput<E>] : [input: RequestInput<E>];
|
|
54
57
|
export type Api<Endpoints extends EndpointsMap> = {
|
|
55
|
-
[Method in keyof EndpointsMap]: <Path extends Extract<keyof Endpoints[Method], string>>(path: Path, ...args: RequestArgs<EndpointOf<Endpoints, Method, Path>>) => Promise<FetchResult<
|
|
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>>>;
|
|
56
59
|
};
|
|
57
60
|
export type RequestHookContext = {
|
|
58
61
|
method: keyof EndpointsMap;
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kayto_ts",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Type-safe HTTP client for working with kayto-generated endpoint schemas.",
|
|
3
|
+
"version": "0.1.7",
|
|
5
4
|
"repository": "https://github.com/vladislav-yemelyanov/kayto_ts",
|
|
6
|
-
"homepage": "https://www.npmjs.com/package/kayto_ts",
|
|
7
|
-
"type": "module",
|
|
8
5
|
"main": "./dist/index.js",
|
|
9
6
|
"module": "./dist/index.js",
|
|
10
|
-
"
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@types/bun": "latest",
|
|
9
|
+
"typescript": "^5.9.3"
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"typescript": "^5"
|
|
13
|
+
},
|
|
11
14
|
"exports": {
|
|
12
15
|
".": {
|
|
13
16
|
"types": "./dist/index.d.ts",
|
|
14
17
|
"import": "./dist/index.js"
|
|
15
18
|
}
|
|
16
19
|
},
|
|
20
|
+
"description": "Type-safe HTTP client for working with kayto-generated endpoint schemas.",
|
|
17
21
|
"files": [
|
|
18
22
|
"dist",
|
|
19
23
|
"README.md",
|
|
20
24
|
"LICENSE"
|
|
21
25
|
],
|
|
26
|
+
"homepage": "https://www.npmjs.com/package/kayto_ts",
|
|
22
27
|
"scripts": {
|
|
23
28
|
"build": "tsc -p tsconfig.build.json",
|
|
24
29
|
"prepublishOnly": "npm run build",
|
|
25
30
|
"test": "bun test"
|
|
26
31
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"typescript": "^5.9.3"
|
|
30
|
-
},
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"typescript": "^5"
|
|
33
|
-
}
|
|
32
|
+
"type": "module",
|
|
33
|
+
"types": "./dist/index.d.ts"
|
|
34
34
|
}
|