@accelbyte/codegen 0.0.0-dev-20240910111050 → 0.0.0-dev-20240911051006
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.
|
@@ -209,18 +209,28 @@ export function ${className}(sdk: AccelByteSDK, args?: SdkSetConfigParam) {
|
|
|
209
209
|
const sdkAssembly = sdk.assembly()
|
|
210
210
|
|
|
211
211
|
const namespace = args?.coreConfig?.namespace ?? sdkAssembly.coreConfig.namespace
|
|
212
|
-
const requestConfig = ApiUtils.mergeAxiosConfigs(sdkAssembly.axiosInstance.defaults as AxiosRequestConfig, {...(args?.coreConfig?.baseURL ? {baseURL: args?.coreConfig?.baseURL} : {}), ...args?.axiosConfig?.request})
|
|
213
|
-
const interceptors = args?.axiosConfig?.interceptors ?? sdkAssembly.axiosConfig.interceptors ?? []
|
|
214
212
|
const useSchemaValidation = args?.coreConfig?.useSchemaValidation ?? sdkAssembly.coreConfig.useSchemaValidation
|
|
215
|
-
const axiosInstance = Network.create(requestConfig)
|
|
216
213
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
214
|
+
let axiosInstance = sdkAssembly.axiosInstance
|
|
215
|
+
const requestConfigOverrides = args?.axiosConfig?.request
|
|
216
|
+
const baseURLOverride = args?.coreConfig?.baseURL
|
|
217
|
+
const interceptorsOverride = args?.axiosConfig?.interceptors ?? []
|
|
218
|
+
|
|
219
|
+
if (requestConfigOverrides || baseURLOverride || interceptorsOverride.length > 0) {
|
|
220
|
+
const requestConfig = ApiUtils.mergeAxiosConfigs(sdkAssembly.axiosInstance.defaults as AxiosRequestConfig, {
|
|
221
|
+
...(baseURLOverride ? { baseURL: baseURLOverride } : {}),
|
|
222
|
+
...requestConfigOverrides
|
|
223
|
+
})
|
|
224
|
+
axiosInstance = Network.create(requestConfig)
|
|
225
|
+
|
|
226
|
+
for (const interceptor of interceptorsOverride) {
|
|
227
|
+
if (interceptor.type === 'request') {
|
|
228
|
+
axiosInstance.interceptors.request.use(interceptor.onRequest, interceptor.onError)
|
|
229
|
+
}
|
|
221
230
|
|
|
222
|
-
|
|
223
|
-
|
|
231
|
+
if (interceptor.type === 'response') {
|
|
232
|
+
axiosInstance.interceptors.response.use(interceptor.onSuccess, interceptor.onError)
|
|
233
|
+
}
|
|
224
234
|
}
|
|
225
235
|
}
|
|
226
236
|
|
|
@@ -1060,7 +1070,7 @@ var templateQueryMethod = ({
|
|
|
1060
1070
|
}
|
|
1061
1071
|
}
|
|
1062
1072
|
const { responseType } = getResponseType({ responseClasses });
|
|
1063
|
-
let _methodName = convertMethodNameToHook({ classMethod, apiGenName,
|
|
1073
|
+
let _methodName = convertMethodNameToHook({ classMethod, apiGenName, isGet });
|
|
1064
1074
|
const _methodParams = methodParams && methodParams.length > 0 ? `& { ${methodParams} }` : "";
|
|
1065
1075
|
const _methodParamsImpl = convertToMethodImplArgs(methodParams);
|
|
1066
1076
|
const queryKey = createQueryKey(apiGenName, classMethod);
|
|
@@ -1125,6 +1135,13 @@ export const ${_methodName} = (
|
|
|
1125
1135
|
`;
|
|
1126
1136
|
return isGet ? queryMethodImpl : mutationMethodImpl;
|
|
1127
1137
|
};
|
|
1138
|
+
function versionMutationSuffixMethodName(baseMethodName) {
|
|
1139
|
+
const parts = baseMethodName.split(/(_v\d+)$/);
|
|
1140
|
+
const name = parts[0];
|
|
1141
|
+
const versionSuffix = parts[1] || "";
|
|
1142
|
+
const res = `${name}Mutation${versionSuffix}`;
|
|
1143
|
+
return res;
|
|
1144
|
+
}
|
|
1128
1145
|
function createQueryKey(className, methodName) {
|
|
1129
1146
|
const prefixRegex = /^(get|create|update|delete|patch|post|fetch)[_]?/i;
|
|
1130
1147
|
const cleanedMethodName = methodName.replace(prefixRegex, "").trim();
|
|
@@ -1140,15 +1157,11 @@ var prefixMappings = {
|
|
|
1140
1157
|
post: "usePost",
|
|
1141
1158
|
fetch: "useFetch"
|
|
1142
1159
|
};
|
|
1143
|
-
function convertMethodNameToHook({
|
|
1144
|
-
|
|
1145
|
-
apiGenName,
|
|
1146
|
-
isPostFetch,
|
|
1147
|
-
isFetch
|
|
1148
|
-
}) {
|
|
1149
|
-
for (const [originalPrefix, newPrefix] of Object.entries(prefixMappings)) {
|
|
1160
|
+
function convertMethodNameToHook({ classMethod, apiGenName, isGet }) {
|
|
1161
|
+
for (const [originalPrefix] of Object.entries(prefixMappings)) {
|
|
1150
1162
|
if (classMethod.startsWith(originalPrefix)) {
|
|
1151
|
-
|
|
1163
|
+
const methodName = !isGet ? versionMutationSuffixMethodName(classMethod) : classMethod;
|
|
1164
|
+
return `use${apiGenName}_${capitalize(methodName)}`;
|
|
1152
1165
|
}
|
|
1153
1166
|
}
|
|
1154
1167
|
return classMethod;
|