@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.
|
@@ -231,18 +231,28 @@ export function ${className}(sdk: AccelByteSDK, args?: SdkSetConfigParam) {
|
|
|
231
231
|
const sdkAssembly = sdk.assembly()
|
|
232
232
|
|
|
233
233
|
const namespace = args?.coreConfig?.namespace ?? sdkAssembly.coreConfig.namespace
|
|
234
|
-
const requestConfig = ApiUtils.mergeAxiosConfigs(sdkAssembly.axiosInstance.defaults as AxiosRequestConfig, {...(args?.coreConfig?.baseURL ? {baseURL: args?.coreConfig?.baseURL} : {}), ...args?.axiosConfig?.request})
|
|
235
|
-
const interceptors = args?.axiosConfig?.interceptors ?? sdkAssembly.axiosConfig.interceptors ?? []
|
|
236
234
|
const useSchemaValidation = args?.coreConfig?.useSchemaValidation ?? sdkAssembly.coreConfig.useSchemaValidation
|
|
237
|
-
const axiosInstance = Network.create(requestConfig)
|
|
238
235
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
236
|
+
let axiosInstance = sdkAssembly.axiosInstance
|
|
237
|
+
const requestConfigOverrides = args?.axiosConfig?.request
|
|
238
|
+
const baseURLOverride = args?.coreConfig?.baseURL
|
|
239
|
+
const interceptorsOverride = args?.axiosConfig?.interceptors ?? []
|
|
240
|
+
|
|
241
|
+
if (requestConfigOverrides || baseURLOverride || interceptorsOverride.length > 0) {
|
|
242
|
+
const requestConfig = ApiUtils.mergeAxiosConfigs(sdkAssembly.axiosInstance.defaults as AxiosRequestConfig, {
|
|
243
|
+
...(baseURLOverride ? { baseURL: baseURLOverride } : {}),
|
|
244
|
+
...requestConfigOverrides
|
|
245
|
+
})
|
|
246
|
+
axiosInstance = Network.create(requestConfig)
|
|
247
|
+
|
|
248
|
+
for (const interceptor of interceptorsOverride) {
|
|
249
|
+
if (interceptor.type === 'request') {
|
|
250
|
+
axiosInstance.interceptors.request.use(interceptor.onRequest, interceptor.onError)
|
|
251
|
+
}
|
|
243
252
|
|
|
244
|
-
|
|
245
|
-
|
|
253
|
+
if (interceptor.type === 'response') {
|
|
254
|
+
axiosInstance.interceptors.response.use(interceptor.onSuccess, interceptor.onError)
|
|
255
|
+
}
|
|
246
256
|
}
|
|
247
257
|
}
|
|
248
258
|
|
|
@@ -1082,7 +1092,7 @@ var templateQueryMethod = ({
|
|
|
1082
1092
|
}
|
|
1083
1093
|
}
|
|
1084
1094
|
const { responseType } = getResponseType({ responseClasses });
|
|
1085
|
-
let _methodName = convertMethodNameToHook({ classMethod, apiGenName,
|
|
1095
|
+
let _methodName = convertMethodNameToHook({ classMethod, apiGenName, isGet });
|
|
1086
1096
|
const _methodParams = methodParams && methodParams.length > 0 ? `& { ${methodParams} }` : "";
|
|
1087
1097
|
const _methodParamsImpl = convertToMethodImplArgs(methodParams);
|
|
1088
1098
|
const queryKey = createQueryKey(apiGenName, classMethod);
|
|
@@ -1147,6 +1157,13 @@ export const ${_methodName} = (
|
|
|
1147
1157
|
`;
|
|
1148
1158
|
return isGet ? queryMethodImpl : mutationMethodImpl;
|
|
1149
1159
|
};
|
|
1160
|
+
function versionMutationSuffixMethodName(baseMethodName) {
|
|
1161
|
+
const parts = baseMethodName.split(/(_v\d+)$/);
|
|
1162
|
+
const name = parts[0];
|
|
1163
|
+
const versionSuffix = parts[1] || "";
|
|
1164
|
+
const res = `${name}Mutation${versionSuffix}`;
|
|
1165
|
+
return res;
|
|
1166
|
+
}
|
|
1150
1167
|
function createQueryKey(className, methodName) {
|
|
1151
1168
|
const prefixRegex = /^(get|create|update|delete|patch|post|fetch)[_]?/i;
|
|
1152
1169
|
const cleanedMethodName = methodName.replace(prefixRegex, "").trim();
|
|
@@ -1162,15 +1179,11 @@ var prefixMappings = {
|
|
|
1162
1179
|
post: "usePost",
|
|
1163
1180
|
fetch: "useFetch"
|
|
1164
1181
|
};
|
|
1165
|
-
function convertMethodNameToHook({
|
|
1166
|
-
|
|
1167
|
-
apiGenName,
|
|
1168
|
-
isPostFetch,
|
|
1169
|
-
isFetch
|
|
1170
|
-
}) {
|
|
1171
|
-
for (const [originalPrefix, newPrefix] of Object.entries(prefixMappings)) {
|
|
1182
|
+
function convertMethodNameToHook({ classMethod, apiGenName, isGet }) {
|
|
1183
|
+
for (const [originalPrefix] of Object.entries(prefixMappings)) {
|
|
1172
1184
|
if (classMethod.startsWith(originalPrefix)) {
|
|
1173
|
-
|
|
1185
|
+
const methodName = !isGet ? versionMutationSuffixMethodName(classMethod) : classMethod;
|
|
1186
|
+
return `use${apiGenName}_${capitalize(methodName)}`;
|
|
1174
1187
|
}
|
|
1175
1188
|
}
|
|
1176
1189
|
return classMethod;
|