@kibinrpc/client 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ixexel661
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,24 @@
1
+ //#region src/types.d.ts
2
+ type AsyncifyMethod<T> = T extends ((...args: infer Args) => infer Return) ? (...args: Args) => Promise<Awaited<Return>> : never;
3
+ type ServiceClient<T> = { [K in keyof T as T[K] extends ((...args: never[]) => unknown) ? K : never]: AsyncifyMethod<T[K]> };
4
+ type ExtractServices<T> = T extends {
5
+ services: infer S;
6
+ } ? S : never;
7
+ type KibinClient<Router> = { [K in keyof ExtractServices<Router>]: ServiceClient<ExtractServices<Router>[K]> };
8
+ interface KibinClientConfig {
9
+ baseUrl: string;
10
+ headers?: Record<string, string>;
11
+ }
12
+ //#endregion
13
+ //#region src/client.d.ts
14
+ declare function createKibinClient<Router>(config: KibinClientConfig): KibinClient<Router>;
15
+ //#endregion
16
+ //#region src/errors.d.ts
17
+ declare class KibinError extends Error {
18
+ readonly code: string;
19
+ constructor(code: string, message: string);
20
+ }
21
+ declare function isKibinError(error: unknown): error is KibinError;
22
+ //#endregion
23
+ export { type KibinClient, type KibinClientConfig, KibinError, createKibinClient, isKibinError };
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/client.ts","../src/errors.ts"],"mappings":";KAAK,cAAA,MAAoB,CAAA,cAAc,IAAA,qCAChC,IAAA,EAAM,IAAA,KAAS,OAAA,CAAQ,OAAA,CAAQ,MAAA;AAAA,KAGjC,aAAA,oBACQ,CAAA,IAAK,CAAA,CAAE,CAAA,eAAe,IAAA,yBAA4B,CAAA,WAAY,cAAA,CAAe,CAAA,CAAE,CAAA;AAAA,KAGvF,eAAA,MAAqB,CAAC;EAAW,QAAA;AAAA,IAAsB,CAAA;AAAA,KAEhD,WAAA,yBACC,eAAA,CAAgB,MAAA,IAAU,aAAA,CAAc,eAAA,CAAgB,MAAA,EAAQ,CAAA;AAAA,UAG5D,iBAAA;EAChB,OAAA;EACA,OAAA,GAAU,MAAM;AAAA;;;iBCbD,iBAAA,QAAA,CAA0B,MAAA,EAAQ,iBAAA,GAAoB,WAAA,CAAY,MAAA;;;cCHrE,UAAA,SAAmB,KAAK;EAAA,SAC3B,IAAA;cAEG,IAAA,UAAc,OAAA;AAAA;AAAA,iBAOX,YAAA,CAAa,KAAA,YAAiB,KAAA,IAAS,UAAU"}
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ //#region src/errors.ts
2
+ var KibinError = class extends Error {
3
+ code;
4
+ constructor(code, message) {
5
+ super(message);
6
+ this.name = "KibinError";
7
+ this.code = code;
8
+ }
9
+ };
10
+ function isKibinError(error) {
11
+ return error instanceof KibinError;
12
+ }
13
+ //#endregion
14
+ //#region src/client.ts
15
+ function createKibinClient(config) {
16
+ return new Proxy({}, { get(_, namespace) {
17
+ return new Proxy({}, { get(_, method) {
18
+ return async (...args) => {
19
+ const result = await (await fetch(config.baseUrl, {
20
+ method: "POST",
21
+ headers: {
22
+ "Content-Type": "application/json",
23
+ ...config.headers
24
+ },
25
+ body: JSON.stringify({
26
+ namespace,
27
+ method,
28
+ args
29
+ })
30
+ })).json();
31
+ if (result.error) throw new KibinError(result.error.code ?? "RPC_ERROR", result.error.message ?? "RPC Error");
32
+ return result.data;
33
+ };
34
+ } });
35
+ } });
36
+ }
37
+ //#endregion
38
+ export { KibinError, createKibinClient, isKibinError };
39
+
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["export class KibinError extends Error {\n\treadonly code: string;\n\n\tconstructor(code: string, message: string) {\n\t\tsuper(message);\n\t\tthis.name = 'KibinError';\n\t\tthis.code = code;\n\t}\n}\n\nexport function isKibinError(error: unknown): error is KibinError {\n\treturn error instanceof KibinError;\n}\n","import { KibinError } from './errors.js';\nimport type { KibinClient, KibinClientConfig } from './types.js';\n\nexport function createKibinClient<Router>(config: KibinClientConfig): KibinClient<Router> {\n\treturn new Proxy(\n\t\t{},\n\t\t{\n\t\t\tget(_, namespace: string) {\n\t\t\t\treturn new Proxy(\n\t\t\t\t\t{},\n\t\t\t\t\t{\n\t\t\t\t\t\tget(_, method: string) {\n\t\t\t\t\t\t\treturn async (...args: unknown[]) => {\n\t\t\t\t\t\t\t\tconst response = await fetch(config.baseUrl, {\n\t\t\t\t\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t\t\t\t\t\t...config.headers,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tbody: JSON.stringify({ namespace, method, args }),\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tconst result = await response.json();\n\n\t\t\t\t\t\t\t\tif (result.error) {\n\t\t\t\t\t\t\t\t\tthrow new KibinError(\n\t\t\t\t\t\t\t\t\t\tresult.error.code ?? 'RPC_ERROR',\n\t\t\t\t\t\t\t\t\t\tresult.error.message ?? 'RPC Error',\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn result.data;\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t) as unknown as KibinClient<Router>;\n}\n"],"mappings":";AAAA,IAAa,aAAb,cAAgC,MAAM;CACrC;CAEA,YAAY,MAAc,SAAiB;EAC1C,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;CACb;AACD;AAEA,SAAgB,aAAa,OAAqC;CACjE,OAAO,iBAAiB;AACzB;;;ACTA,SAAgB,kBAA0B,QAAgD;CACzF,OAAO,IAAI,MACV,CAAC,GACD,EACC,IAAI,GAAG,WAAmB;EACzB,OAAO,IAAI,MACV,CAAC,GACD,EACC,IAAI,GAAG,QAAgB;GACtB,OAAO,OAAO,GAAG,SAAoB;IAUpC,MAAM,SAAS,OAAM,MATE,MAAM,OAAO,SAAS;KAC5C,QAAQ;KACR,SAAS;MACR,gBAAgB;MAChB,GAAG,OAAO;KACX;KACA,MAAM,KAAK,UAAU;MAAE;MAAW;MAAQ;KAAK,CAAC;IACjD,CAAC,GAE6B,KAAK;IAEnC,IAAI,OAAO,OACV,MAAM,IAAI,WACT,OAAO,MAAM,QAAQ,aACrB,OAAO,MAAM,WAAW,WACzB;IAGD,OAAO,OAAO;GACf;EACD,EACD,CACD;CACD,EACD,CACD;AACD"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@kibinrpc/client",
3
+ "version": "0.0.2",
4
+ "description": "Type-safe and developer-friendly RPC client with end-to-end type inference",
5
+ "license": "MIT",
6
+ "author": "ixexel661",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/ixexel661/kibin",
10
+ "directory": "packages/client"
11
+ },
12
+ "keywords": [
13
+ "rpc",
14
+ "client",
15
+ "typescript",
16
+ "fetch"
17
+ ],
18
+ "type": "module",
19
+ "sideEffects": false,
20
+ "exports": {
21
+ ".": {
22
+ "import": "./dist/index.js",
23
+ "types": "./dist/index.d.ts"
24
+ }
25
+ },
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "scripts": {
35
+ "build": "tsdown",
36
+ "dev": "tsdown --watch"
37
+ }
38
+ }