@creatorem/next-trpc 1.0.14 → 1.0.16

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.
@@ -2,8 +2,10 @@ import { Router, type Endpoint, type router } from "./core";
2
2
  import z from "zod";
3
3
  export type EndpointClient<Input, Output> = Input extends undefined ? {
4
4
  fetch: () => Promise<Output>;
5
+ key: string;
5
6
  } : {
6
7
  fetch: (input: Input extends import("zod").Schema ? z.infer<Input> : Input) => Promise<Output>;
8
+ key: string;
7
9
  };
8
10
  type TrpcClient<R extends Router<any>> = {
9
11
  [K in keyof R]: R[K] extends Endpoint<infer Output, infer Input, any> ? EndpointClient<Input, Output> : never;
@@ -38,6 +38,7 @@ const createTrpcClient = (opts) => {
38
38
  if (typeof prop === "string") {
39
39
  return {
40
40
  fetch: (0, exports.getTrpcFetch)(Object.assign({ endpointSlug: prop }, opts)),
41
+ key: (0, utils_1.kebabize)(prop)
41
42
  };
42
43
  }
43
44
  return undefined;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.createTrpcQueryClient = void 0;
5
5
  const create_trpc_client_1 = require("./create-trpc-client");
6
+ const utils_1 = require("./utils");
6
7
  const createTrpcQueryClient = (opts) => {
7
8
  return new Proxy({}, {
8
9
  get(target, prop) {
@@ -10,12 +11,13 @@ const createTrpcQueryClient = (opts) => {
10
11
  return {
11
12
  fetch: (0, create_trpc_client_1.getTrpcFetch)(Object.assign({ endpointSlug: prop }, opts)),
12
13
  useQuery: (queryOptions) => {
13
- const endpointName = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
14
+ const endpointName = (0, utils_1.kebabize)(prop);
14
15
  return opts.useQuery(Object.assign(Object.assign({}, queryOptions), { queryKey: [endpointName], queryFn: async () => {
15
16
  const fetcher = (0, create_trpc_client_1.getTrpcFetch)(Object.assign({ endpointSlug: prop }, opts));
16
17
  return await fetcher(queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.input);
17
18
  } }));
18
19
  },
20
+ key: (0, utils_1.kebabize)(prop)
19
21
  };
20
22
  }
21
23
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creatorem/next-trpc",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/creatorem/next-trpc"