tag-rpc 1.0.5 → 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.
@@ -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 body = r.extractedTypes[`${methodTitle}RequestType`] || "any";
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
- Body: ${body};
76
+ Request: ${req};
77
77
  Query: ${query};
78
78
  };`;
79
79
  }).join("\n")}
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  runScanner
4
- } from "./chunk-XFEVFUJZ.js";
4
+ } from "./chunk-QQFPCKNQ.js";
5
5
 
6
6
  // src/cli.ts
7
7
  import chokidar from "chokidar";
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  type MethodShape = {
2
2
  Response: unknown;
3
- Body: unknown;
3
+ Request: unknown;
4
4
  Query: unknown;
5
5
  };
6
6
  declare class TAG_API_ERROR extends Error {
@@ -26,10 +26,10 @@ declare function createTagRPC<TApiRoutes extends {
26
26
  pathParams?: never;
27
27
  } : {
28
28
  pathParams: TApiRoutes[TPath]["PathParams"];
29
- }) & (TApiRoutes[TPath]["Methods"][TMethod]["Body"] extends never ? {
29
+ }) & (TApiRoutes[TPath]["Methods"][TMethod]["Request"] extends never ? {
30
30
  body?: never;
31
31
  } : {
32
- body: TApiRoutes[TPath]["Methods"][TMethod]["Body"];
32
+ body: TApiRoutes[TPath]["Methods"][TMethod]["Request"];
33
33
  }) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
34
34
  query?: never;
35
35
  } : {
@@ -39,29 +39,49 @@ declare function createTagRPC<TApiRoutes extends {
39
39
  pathParams?: never;
40
40
  } : {
41
41
  pathParams: TApiRoutes[TPath]["PathParams"];
42
- }) & (TApiRoutes[TPath]["Methods"][TMethod]["Body"] extends never ? {
42
+ }) & (TApiRoutes[TPath]["Methods"][TMethod]["Request"] extends never ? {
43
43
  body?: never;
44
44
  } : {
45
- body: TApiRoutes[TPath]["Methods"][TMethod]["Body"];
45
+ body: TApiRoutes[TPath]["Methods"][TMethod]["Request"];
46
46
  }) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
47
47
  query?: never;
48
48
  } : {
49
49
  query?: TApiRoutes[TPath]["Methods"][TMethod]["Query"] | undefined;
50
50
  })) => Promise<TApiRoutes[TPath]["Methods"][TMethod]["Response"]>;
51
51
  routes: TNamedRoutes;
52
- call: <K_1 extends keyof TNamedRoutes, TRoute extends TNamedRoutes[K_1], TPath extends TRoute["path"] & keyof TApiRoutes, TMethod extends TRoute["method"] & keyof TApiRoutes[TPath]["Methods"] & string>(route: TRoute, options: Omit<RequestInit, "method" | "body"> & (TApiRoutes[TPath]["PathParams"] extends never ? {
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 ? {
53
53
  pathParams?: never;
54
54
  } : {
55
55
  pathParams: TApiRoutes[TPath]["PathParams"];
56
- }) & (TApiRoutes[TPath]["Methods"][TMethod]["Body"] extends never ? {
56
+ }) & (TApiRoutes[TPath]["Methods"][TMethod]["Request"] extends never ? {
57
57
  body?: never;
58
58
  } : {
59
- body: TApiRoutes[TPath]["Methods"][TMethod]["Body"];
59
+ body: TApiRoutes[TPath]["Methods"][TMethod]["Request"];
60
60
  }) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
61
61
  query?: never;
62
62
  } : {
63
63
  query?: TApiRoutes[TPath]["Methods"][TMethod]["Query"] | undefined;
64
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>];
65
85
  };
66
86
 
67
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
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runScanner
3
- } from "./chunk-XFEVFUJZ.js";
3
+ } from "./chunk-QQFPCKNQ.js";
4
4
  export {
5
5
  runScanner as default
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tag-rpc",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "End-to-end type safety for Next.js Route Handlers",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",