typed-openapi 1.1.0 → 1.1.2

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.
@@ -924,18 +924,50 @@ var generateTanstackQueryFile = async (ctx) => {
924
924
  ...params,
925
925
  ...queryKey[0],
926
926
  signal,
927
- throwOnError: true
928
927
  });
929
928
  return res as TEndpoint["response"];
930
929
  },
931
930
  queryKey: queryKey
932
931
  }),
932
+ mutationOptions: {
933
+ mutationKey: queryKey,
934
+ mutationFn: async (localOptions: TEndpoint extends { parameters: infer Parameters} ? Parameters: never) => {
935
+ const res = await this.client.${method}(path, {
936
+ ...params,
937
+ ...queryKey[0],
938
+ ...localOptions,
939
+ });
940
+ return res as TEndpoint["response"];
941
+ }
942
+ }
933
943
  };
934
944
 
935
945
  return query
936
946
  }
937
- // </ApiClient.get>
947
+ // </ApiClient.${method}>
938
948
  `).join("\n")}
949
+
950
+ // <ApiClient.request>
951
+ /**
952
+ * Generic mutation method with full type-safety for any endpoint that doesnt require parameters to be passed initially
953
+ */
954
+ mutation<
955
+ TMethod extends keyof EndpointByMethod,
956
+ TPath extends keyof EndpointByMethod[TMethod],
957
+ TEndpoint extends EndpointByMethod[TMethod][TPath]
958
+ >(
959
+ method: TMethod,
960
+ path: TPath) {
961
+ const mutationKey = [{ method, path }] as const;
962
+ return {
963
+ mutationKey: mutationKey,
964
+ mutationOptions: {
965
+ mutationKey: mutationKey,
966
+ mutationFn: async (params: TEndpoint extends { parameters: infer Parameters} ? Parameters: never) => this.client.request(method, path, params)
967
+ }
968
+ }
969
+ }
970
+ // </ApiClient.request>
939
971
  }
940
972
  `;
941
973
  return prettify(file);
package/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  generateTanstackQueryFile,
5
5
  mapOpenApiEndpoints,
6
6
  prettify
7
- } from "./chunk-FTIKYHGK.js";
7
+ } from "./chunk-PXWODSHO.js";
8
8
 
9
9
  // src/cli.ts
10
10
  import SwaggerParser from "@apidevtools/swagger-parser";
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  openApiSchemaToTs,
9
9
  tsFactory,
10
10
  unwrap
11
- } from "./chunk-FTIKYHGK.js";
11
+ } from "./chunk-PXWODSHO.js";
12
12
  export {
13
13
  createBoxFactory,
14
14
  createFactory,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typed-openapi",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "exports": {
@@ -84,18 +84,50 @@ export const generateTanstackQueryFile = async (ctx: GeneratorContext & { relati
84
84
  ...params,
85
85
  ...queryKey[0],
86
86
  signal,
87
- throwOnError: true
88
87
  });
89
88
  return res as TEndpoint["response"];
90
89
  },
91
90
  queryKey: queryKey
92
91
  }),
92
+ mutationOptions: {
93
+ mutationKey: queryKey,
94
+ mutationFn: async (localOptions: TEndpoint extends { parameters: infer Parameters} ? Parameters: never) => {
95
+ const res = await this.client.${method}(path, {
96
+ ...params,
97
+ ...queryKey[0],
98
+ ...localOptions,
99
+ });
100
+ return res as TEndpoint["response"];
101
+ }
102
+ }
93
103
  };
94
104
 
95
105
  return query
96
106
  }
97
- // </ApiClient.get>
107
+ // </ApiClient.${method}>
98
108
  `).join("\n")}
109
+
110
+ // <ApiClient.request>
111
+ /**
112
+ * Generic mutation method with full type-safety for any endpoint that doesnt require parameters to be passed initially
113
+ */
114
+ mutation<
115
+ TMethod extends keyof EndpointByMethod,
116
+ TPath extends keyof EndpointByMethod[TMethod],
117
+ TEndpoint extends EndpointByMethod[TMethod][TPath]
118
+ >(
119
+ method: TMethod,
120
+ path: TPath) {
121
+ const mutationKey = [{ method, path }] as const;
122
+ return {
123
+ mutationKey: mutationKey,
124
+ mutationOptions: {
125
+ mutationKey: mutationKey,
126
+ mutationFn: async (params: TEndpoint extends { parameters: infer Parameters} ? Parameters: never) => this.client.request(method, path, params)
127
+ }
128
+ }
129
+ }
130
+ // </ApiClient.request>
99
131
  }
100
132
  `;
101
133