tag-rpc 1.0.6 → 1.0.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 +22 -24
- package/dist/index.js +3 -11
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,24 @@ declare class TAG_API_ERROR extends Error {
|
|
|
10
10
|
url: string;
|
|
11
11
|
constructor(status: number, statusText: string, body: any, url: string);
|
|
12
12
|
}
|
|
13
|
+
type MethodKind = keyof MethodShape;
|
|
14
|
+
type RouteTypeKind = MethodKind | "PathParams";
|
|
15
|
+
type RouteType<TApiRoutes extends Record<string, {
|
|
16
|
+
Methods: Record<string, MethodShape>;
|
|
17
|
+
PathParams: any;
|
|
18
|
+
}>, TNamedRoutes extends Record<string, {
|
|
19
|
+
path: keyof TApiRoutes;
|
|
20
|
+
method: string;
|
|
21
|
+
}>, K extends keyof TNamedRoutes, Kind extends RouteTypeKind> = Kind extends "PathParams" ? TApiRoutes[TNamedRoutes[K]["path"]]["PathParams"] : TApiRoutes[TNamedRoutes[K]["path"]]["Methods"][TNamedRoutes[K]["method"]][Extract<Kind, "Response" | "Request" | "Query">];
|
|
22
|
+
type TypeOf<TApiRoutes extends {
|
|
23
|
+
[K in keyof TApiRoutes]: {
|
|
24
|
+
PathParams: any;
|
|
25
|
+
Methods: Record<string, MethodShape>;
|
|
26
|
+
};
|
|
27
|
+
}, TNamedRoutes extends Record<string, {
|
|
28
|
+
path: keyof TApiRoutes;
|
|
29
|
+
method: string;
|
|
30
|
+
}>, K extends keyof TNamedRoutes, Kind extends RouteTypeKind> = RouteType<TApiRoutes, TNamedRoutes, K, Kind>;
|
|
13
31
|
declare function createTagRPC<TApiRoutes extends {
|
|
14
32
|
[K in keyof TApiRoutes]: {
|
|
15
33
|
PathParams: any;
|
|
@@ -33,7 +51,7 @@ declare function createTagRPC<TApiRoutes extends {
|
|
|
33
51
|
}) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
|
|
34
52
|
query?: never;
|
|
35
53
|
} : {
|
|
36
|
-
query
|
|
54
|
+
query: TApiRoutes[TPath]["Methods"][TMethod]["Query"];
|
|
37
55
|
})) => Promise<TApiRoutes[TPath]["Methods"][TMethod]["Response"]>; } & {
|
|
38
56
|
fetch: <TPath extends keyof TApiRoutes, TMethod extends keyof TApiRoutes[TPath]["Methods"] & string>(path: TPath, method: TMethod, options: Omit<RequestInit, "method" | "body"> & (TApiRoutes[TPath]["PathParams"] extends never ? {
|
|
39
57
|
pathParams?: never;
|
|
@@ -46,7 +64,7 @@ declare function createTagRPC<TApiRoutes extends {
|
|
|
46
64
|
}) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
|
|
47
65
|
query?: never;
|
|
48
66
|
} : {
|
|
49
|
-
query
|
|
67
|
+
query: TApiRoutes[TPath]["Methods"][TMethod]["Query"];
|
|
50
68
|
})) => Promise<TApiRoutes[TPath]["Methods"][TMethod]["Response"]>;
|
|
51
69
|
routes: TNamedRoutes;
|
|
52
70
|
call: <K_1 extends keyof TNamedRoutes, R extends TNamedRoutes[K_1], TPath extends R["path"] & keyof TApiRoutes, TMethod extends R["method"] & keyof TApiRoutes[TPath]["Methods"] & string>(route: R, options: Omit<RequestInit, "method" | "body"> & (TApiRoutes[TPath]["PathParams"] extends never ? {
|
|
@@ -60,28 +78,8 @@ declare function createTagRPC<TApiRoutes extends {
|
|
|
60
78
|
}) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
|
|
61
79
|
query?: never;
|
|
62
80
|
} : {
|
|
63
|
-
query
|
|
81
|
+
query: TApiRoutes[TPath]["Methods"][TMethod]["Query"];
|
|
64
82
|
})) => Promise<TApiRoutes[TPath]["Methods"][TMethod]["Response"]>;
|
|
65
|
-
/** 🔒 Compile-time only type extractor */
|
|
66
|
-
Type: <K_1 extends keyof TNamedRoutes, Kind extends "Response" | "Request" | "Query" | "PathParams">() => Kind extends "PathParams" ? TApiRoutes[(TNamedRoutes[K_1] extends {
|
|
67
|
-
path: infer P;
|
|
68
|
-
method: infer M;
|
|
69
|
-
} ? {
|
|
70
|
-
path: P & keyof TApiRoutes;
|
|
71
|
-
method: M & keyof TApiRoutes[P & keyof TApiRoutes]["Methods"];
|
|
72
|
-
} : never)["path"]]["PathParams"] : TApiRoutes[(TNamedRoutes[K_1] extends {
|
|
73
|
-
path: infer P;
|
|
74
|
-
method: infer M;
|
|
75
|
-
} ? {
|
|
76
|
-
path: P & keyof TApiRoutes;
|
|
77
|
-
method: M & keyof TApiRoutes[P & keyof TApiRoutes]["Methods"];
|
|
78
|
-
} : never)["path"]]["Methods"][(TNamedRoutes[K_1] extends {
|
|
79
|
-
path: infer P;
|
|
80
|
-
method: infer M;
|
|
81
|
-
} ? {
|
|
82
|
-
path: P & keyof TApiRoutes;
|
|
83
|
-
method: M & keyof TApiRoutes[P & keyof TApiRoutes]["Methods"];
|
|
84
|
-
} : never)["method"]][Extract<Kind, keyof MethodShape>];
|
|
85
83
|
};
|
|
86
84
|
|
|
87
|
-
export { TAG_API_ERROR, createTagRPC };
|
|
85
|
+
export { type MethodKind, type RouteType, type RouteTypeKind, TAG_API_ERROR, type TypeOf, createTagRPC };
|
package/dist/index.js
CHANGED
|
@@ -46,21 +46,13 @@ function createTagRPC(registry) {
|
|
|
46
46
|
const baseFetcher = {
|
|
47
47
|
fetch: fetchData,
|
|
48
48
|
routes: registry.namedRoutes,
|
|
49
|
-
call: (route, options) => fetchData(route.path, route.method, options)
|
|
50
|
-
// NEVER meant to run — type-only
|
|
51
|
-
Type: () => {
|
|
52
|
-
throw new Error("api.Type() is a compile-time only helper");
|
|
53
|
-
}
|
|
49
|
+
call: (route, options) => fetchData(route.path, route.method, options)
|
|
54
50
|
};
|
|
55
51
|
return new Proxy(baseFetcher, {
|
|
56
52
|
get(target, prop) {
|
|
57
|
-
if (prop in target)
|
|
58
|
-
return target[prop];
|
|
59
|
-
}
|
|
53
|
+
if (prop in target) return target[prop];
|
|
60
54
|
const route = registry.namedRoutes[prop];
|
|
61
|
-
if (route)
|
|
62
|
-
return (options) => fetchData(route.path, route.method, options);
|
|
63
|
-
}
|
|
55
|
+
if (route) return (options) => fetchData(route.path, route.method, options);
|
|
64
56
|
return void 0;
|
|
65
57
|
}
|
|
66
58
|
});
|