tag-rpc 1.0.5 → 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.
@@ -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 {
@@ -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;
@@ -26,42 +44,42 @@ declare function createTagRPC<TApiRoutes extends {
26
44
  pathParams?: never;
27
45
  } : {
28
46
  pathParams: TApiRoutes[TPath]["PathParams"];
29
- }) & (TApiRoutes[TPath]["Methods"][TMethod]["Body"] extends never ? {
47
+ }) & (TApiRoutes[TPath]["Methods"][TMethod]["Request"] extends never ? {
30
48
  body?: never;
31
49
  } : {
32
- body: TApiRoutes[TPath]["Methods"][TMethod]["Body"];
50
+ body: TApiRoutes[TPath]["Methods"][TMethod]["Request"];
33
51
  }) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
34
52
  query?: never;
35
53
  } : {
36
- query?: TApiRoutes[TPath]["Methods"][TMethod]["Query"] | undefined;
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;
40
58
  } : {
41
59
  pathParams: TApiRoutes[TPath]["PathParams"];
42
- }) & (TApiRoutes[TPath]["Methods"][TMethod]["Body"] extends never ? {
60
+ }) & (TApiRoutes[TPath]["Methods"][TMethod]["Request"] extends never ? {
43
61
  body?: never;
44
62
  } : {
45
- body: TApiRoutes[TPath]["Methods"][TMethod]["Body"];
63
+ body: TApiRoutes[TPath]["Methods"][TMethod]["Request"];
46
64
  }) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
47
65
  query?: never;
48
66
  } : {
49
- query?: TApiRoutes[TPath]["Methods"][TMethod]["Query"] | undefined;
67
+ query: TApiRoutes[TPath]["Methods"][TMethod]["Query"];
50
68
  })) => Promise<TApiRoutes[TPath]["Methods"][TMethod]["Response"]>;
51
69
  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 ? {
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 ? {
53
71
  pathParams?: never;
54
72
  } : {
55
73
  pathParams: TApiRoutes[TPath]["PathParams"];
56
- }) & (TApiRoutes[TPath]["Methods"][TMethod]["Body"] extends never ? {
74
+ }) & (TApiRoutes[TPath]["Methods"][TMethod]["Request"] extends never ? {
57
75
  body?: never;
58
76
  } : {
59
- body: TApiRoutes[TPath]["Methods"][TMethod]["Body"];
77
+ body: TApiRoutes[TPath]["Methods"][TMethod]["Request"];
60
78
  }) & (TApiRoutes[TPath]["Methods"][TMethod]["Query"] extends never ? {
61
79
  query?: never;
62
80
  } : {
63
- query?: TApiRoutes[TPath]["Methods"][TMethod]["Query"] | undefined;
81
+ query: TApiRoutes[TPath]["Methods"][TMethod]["Query"];
64
82
  })) => Promise<TApiRoutes[TPath]["Methods"][TMethod]["Response"]>;
65
83
  };
66
84
 
67
- export { TAG_API_ERROR, createTagRPC };
85
+ export { type MethodKind, type RouteType, type RouteTypeKind, TAG_API_ERROR, type TypeOf, createTagRPC };
package/dist/index.js CHANGED
@@ -50,13 +50,9 @@ function createTagRPC(registry) {
50
50
  };
51
51
  return new Proxy(baseFetcher, {
52
52
  get(target, prop) {
53
- if (prop in target) {
54
- return target[prop];
55
- }
53
+ if (prop in target) return target[prop];
56
54
  const route = registry.namedRoutes[prop];
57
- if (route) {
58
- return (options) => fetchData(route.path, route.method, options);
59
- }
55
+ if (route) return (options) => fetchData(route.path, route.method, options);
60
56
  return void 0;
61
57
  }
62
58
  });
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.7",
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",