tag-rpc 1.0.4 → 1.0.6
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/{chunk-XFEVFUJZ.js → chunk-QQFPCKNQ.js} +2 -2
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +35 -13
- package/dist/index.js +5 -1
- package/dist/scanner.js +1 -1
- package/package.json +1 -1
|
@@ -68,12 +68,12 @@ ${routes.map((r) => ` "${r.routePath}": {
|
|
|
68
68
|
Methods: {
|
|
69
69
|
${r.methods.map((m) => {
|
|
70
70
|
const methodTitle = m.charAt(0).toUpperCase() + m.slice(1).toLowerCase();
|
|
71
|
-
const
|
|
71
|
+
const req = r.extractedTypes[`${methodTitle}RequestType`] || "any";
|
|
72
72
|
const resp = r.extractedTypes[`${methodTitle}ResponseType`] || "any";
|
|
73
73
|
const query = r.extractedTypes[`${methodTitle}QueryType`] || "any";
|
|
74
74
|
return ` ${m}: {
|
|
75
75
|
Response: ${resp};
|
|
76
|
-
|
|
76
|
+
Request: ${req};
|
|
77
77
|
Query: ${query};
|
|
78
78
|
};`;
|
|
79
79
|
}).join("\n")}
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type MethodShape = {
|
|
2
2
|
Response: unknown;
|
|
3
|
-
|
|
3
|
+
Request: unknown;
|
|
4
4
|
Query: unknown;
|
|
5
5
|
};
|
|
6
6
|
declare class TAG_API_ERROR extends Error {
|
|
@@ -11,23 +11,25 @@ declare class TAG_API_ERROR extends Error {
|
|
|
11
11
|
constructor(status: number, statusText: string, body: any, url: string);
|
|
12
12
|
}
|
|
13
13
|
declare function createTagRPC<TApiRoutes extends {
|
|
14
|
-
[K in
|
|
14
|
+
[K in keyof TApiRoutes]: {
|
|
15
15
|
PathParams: any;
|
|
16
16
|
Methods: Record<string, MethodShape>;
|
|
17
17
|
};
|
|
18
|
-
}, TNamedRoutes extends
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
}, TNamedRoutes extends {
|
|
19
|
+
[K in keyof TNamedRoutes]: {
|
|
20
|
+
path: keyof TApiRoutes;
|
|
21
|
+
method: string;
|
|
22
|
+
};
|
|
23
|
+
}>(registry: {
|
|
22
24
|
namedRoutes: TNamedRoutes;
|
|
23
25
|
}): { [K in keyof TNamedRoutes]: <TPath extends TNamedRoutes[K]["path"] & keyof TApiRoutes, TMethod extends TNamedRoutes[K]["method"] & keyof TApiRoutes[TPath]["Methods"] & string>(options: Omit<RequestInit, "method" | "body"> & (TApiRoutes[TPath]["PathParams"] extends never ? {
|
|
24
26
|
pathParams?: never;
|
|
25
27
|
} : {
|
|
26
28
|
pathParams: TApiRoutes[TPath]["PathParams"];
|
|
27
|
-
}) & (TApiRoutes[TPath]["Methods"][TMethod]["
|
|
29
|
+
}) & (TApiRoutes[TPath]["Methods"][TMethod]["Request"] extends never ? {
|
|
28
30
|
body?: never;
|
|
29
31
|
} : {
|
|
30
|
-
body: TApiRoutes[TPath]["Methods"][TMethod]["
|
|
32
|
+
body: TApiRoutes[TPath]["Methods"][TMethod]["Request"];
|
|
31
33
|
}) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
|
|
32
34
|
query?: never;
|
|
33
35
|
} : {
|
|
@@ -37,29 +39,49 @@ declare function createTagRPC<TApiRoutes extends {
|
|
|
37
39
|
pathParams?: never;
|
|
38
40
|
} : {
|
|
39
41
|
pathParams: TApiRoutes[TPath]["PathParams"];
|
|
40
|
-
}) & (TApiRoutes[TPath]["Methods"][TMethod]["
|
|
42
|
+
}) & (TApiRoutes[TPath]["Methods"][TMethod]["Request"] extends never ? {
|
|
41
43
|
body?: never;
|
|
42
44
|
} : {
|
|
43
|
-
body: TApiRoutes[TPath]["Methods"][TMethod]["
|
|
45
|
+
body: TApiRoutes[TPath]["Methods"][TMethod]["Request"];
|
|
44
46
|
}) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
|
|
45
47
|
query?: never;
|
|
46
48
|
} : {
|
|
47
49
|
query?: TApiRoutes[TPath]["Methods"][TMethod]["Query"] | undefined;
|
|
48
50
|
})) => Promise<TApiRoutes[TPath]["Methods"][TMethod]["Response"]>;
|
|
49
51
|
routes: TNamedRoutes;
|
|
50
|
-
call: <K_1 extends keyof TNamedRoutes,
|
|
52
|
+
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 ? {
|
|
51
53
|
pathParams?: never;
|
|
52
54
|
} : {
|
|
53
55
|
pathParams: TApiRoutes[TPath]["PathParams"];
|
|
54
|
-
}) & (TApiRoutes[TPath]["Methods"][TMethod]["
|
|
56
|
+
}) & (TApiRoutes[TPath]["Methods"][TMethod]["Request"] extends never ? {
|
|
55
57
|
body?: never;
|
|
56
58
|
} : {
|
|
57
|
-
body: TApiRoutes[TPath]["Methods"][TMethod]["
|
|
59
|
+
body: TApiRoutes[TPath]["Methods"][TMethod]["Request"];
|
|
58
60
|
}) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
|
|
59
61
|
query?: never;
|
|
60
62
|
} : {
|
|
61
63
|
query?: TApiRoutes[TPath]["Methods"][TMethod]["Query"] | undefined;
|
|
62
64
|
})) => 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>];
|
|
63
85
|
};
|
|
64
86
|
|
|
65
87
|
export { TAG_API_ERROR, createTagRPC };
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,11 @@ 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)
|
|
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
|
+
}
|
|
50
54
|
};
|
|
51
55
|
return new Proxy(baseFetcher, {
|
|
52
56
|
get(target, prop) {
|
package/dist/scanner.js
CHANGED