@accelbyte/codegen 0.0.0-dev-20240910111050 → 0.0.0-dev-20240912075533
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)
|
|
243
247
|
|
|
244
|
-
|
|
245
|
-
|
|
248
|
+
for (const interceptor of interceptorsOverride) {
|
|
249
|
+
if (interceptor.type === 'request') {
|
|
250
|
+
axiosInstance.interceptors.request.use(interceptor.onRequest, interceptor.onError)
|
|
251
|
+
}
|
|
252
|
+
|
|
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;
|
|
@@ -1425,7 +1438,7 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1425
1438
|
};
|
|
1426
1439
|
|
|
1427
1440
|
// src/templates/template-api-index.ts
|
|
1428
|
-
var templateApiIndex = (
|
|
1441
|
+
var templateApiIndex = (serviceNameTitle, apiList) => {
|
|
1429
1442
|
let imports = "";
|
|
1430
1443
|
let returnStatement = "";
|
|
1431
1444
|
for (const cl of apiList) {
|
|
@@ -1439,9 +1452,17 @@ ${cl}, `;
|
|
|
1439
1452
|
* AUTO GENERATED
|
|
1440
1453
|
*/
|
|
1441
1454
|
${imports}
|
|
1455
|
+
import { author, name, version } from '../package.json'
|
|
1456
|
+
|
|
1457
|
+
console.log(\`\${name}@\${version}\`)
|
|
1442
1458
|
|
|
1443
1459
|
const apis = {
|
|
1444
1460
|
${returnStatement}
|
|
1461
|
+
version: () => console.log({
|
|
1462
|
+
version,
|
|
1463
|
+
name,
|
|
1464
|
+
author
|
|
1465
|
+
})
|
|
1445
1466
|
}
|
|
1446
1467
|
|
|
1447
1468
|
export const ${serviceNameTitle} = apis
|
|
@@ -1841,7 +1862,7 @@ var CodeGenerator = class _CodeGenerator {
|
|
|
1841
1862
|
};
|
|
1842
1863
|
generatePublicOrAdmin(true);
|
|
1843
1864
|
generatePublicOrAdmin(false);
|
|
1844
|
-
const apiIndexBuff = templateApiIndex(
|
|
1865
|
+
const apiIndexBuff = templateApiIndex(serviceNameTitle, mainApiList);
|
|
1845
1866
|
ParserUtils.writeApiMainFile(_CodeGenerator.srcFolder(), serviceNameTitle, apiIndexBuff);
|
|
1846
1867
|
console.log("\nCOMPLETED\n----------\n\n");
|
|
1847
1868
|
return { indexImports: indexImportsSet, queryImports: queryImportsSet };
|