typed-openapi 1.1.0 → 1.1.1
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) => {
|
|
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
|
|
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
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -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) => {
|
|
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
|
|
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
|
|