@@ -88,17 +88,27 @@ describe("generator", () => {
8888 ...params,
8989 ...queryKey[0],
9090 signal,
91- throwOnError: true,
9291 });
9392 return res as TEndpoint["response"];
9493 },
9594 queryKey: queryKey,
9695 }),
96+ mutationOptions: {
97+ mutationKey: queryKey,
98+ mutationFn: async (localOptions) => {
99+ const res = await this.client.put(path, {
100+ ...params,
101+ ...queryKey[0],
102+ ...localOptions,
103+ });
104+ return res as TEndpoint["response"];
105+ },
106+ },
97107 };
98108
99109 return query;
100110 }
101- // </ApiClient.get >
111+ // </ApiClient.put >
102112
103113 // <ApiClient.post>
104114 post<Path extends keyof PostEndpoints, TEndpoint extends PostEndpoints[Path]>(
@@ -116,17 +126,27 @@ describe("generator", () => {
116126 ...params,
117127 ...queryKey[0],
118128 signal,
119- throwOnError: true,
120129 });
121130 return res as TEndpoint["response"];
122131 },
123132 queryKey: queryKey,
124133 }),
134+ mutationOptions: {
135+ mutationKey: queryKey,
136+ mutationFn: async (localOptions) => {
137+ const res = await this.client.post(path, {
138+ ...params,
139+ ...queryKey[0],
140+ ...localOptions,
141+ });
142+ return res as TEndpoint["response"];
143+ },
144+ },
125145 };
126146
127147 return query;
128148 }
129- // </ApiClient.get >
149+ // </ApiClient.post >
130150
131151 // <ApiClient.get>
132152 get<Path extends keyof GetEndpoints, TEndpoint extends GetEndpoints[Path]>(
@@ -144,12 +164,22 @@ describe("generator", () => {
144164 ...params,
145165 ...queryKey[0],
146166 signal,
147- throwOnError: true,
148167 });
149168 return res as TEndpoint["response"];
150169 },
151170 queryKey: queryKey,
152171 }),
172+ mutationOptions: {
173+ mutationKey: queryKey,
174+ mutationFn: async (localOptions) => {
175+ const res = await this.client.get(path, {
176+ ...params,
177+ ...queryKey[0],
178+ ...localOptions,
179+ });
180+ return res as TEndpoint["response"];
181+ },
182+ },
153183 };
154184
155185 return query;
@@ -172,17 +202,48 @@ describe("generator", () => {
172202 ...params,
173203 ...queryKey[0],
174204 signal,
175- throwOnError: true,
176205 });
177206 return res as TEndpoint["response"];
178207 },
179208 queryKey: queryKey,
180209 }),
210+ mutationOptions: {
211+ mutationKey: queryKey,
212+ mutationFn: async (localOptions) => {
213+ const res = await this.client.delete(path, {
214+ ...params,
215+ ...queryKey[0],
216+ ...localOptions,
217+ });
218+ return res as TEndpoint["response"];
219+ },
220+ },
181221 };
182222
183223 return query;
184224 }
185- // </ApiClient.get>
225+ // </ApiClient.delete>
226+
227+ // <ApiClient.request>
228+ /**
229+ * Generic mutation method with full type-safety for any endpoint that doesnt require parameters to be passed initially
230+ */
231+ mutation<
232+ TMethod extends keyof EndpointByMethod,
233+ TPath extends keyof EndpointByMethod[TMethod],
234+ TEndpoint extends EndpointByMethod[TMethod][TPath],
235+ >(method: TMethod, path: TPath) {
236+ const mutationKey = [{ method, path }] as const;
237+ return {
238+ mutationKey: mutationKey,
239+ mutationOptions: {
240+ mutationKey: mutationKey,
241+ mutationFn: async (params: TEndpoint extends { parameters: infer Parameters } ? Parameters : never) =>
242+ this.client.request(method, path, params),
243+ },
244+ };
245+ }
246+ // </ApiClient.request>
186247 }
187248 "
188249 ` ) ;
0 commit comments