@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.
|
@@ -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)
|
|
221
225
|
|
|
222
|
-
|
|
223
|
-
|
|
226
|
+
for (const interceptor of interceptorsOverride) {
|
|
227
|
+
if (interceptor.type === 'request') {
|
|
228
|
+
axiosInstance.interceptors.request.use(interceptor.onRequest, interceptor.onError)
|
|
229
|
+
}
|
|
230
|
+
|
|
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;
|
|
@@ -1403,7 +1416,7 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1403
1416
|
};
|
|
1404
1417
|
|
|
1405
1418
|
// src/templates/template-api-index.ts
|
|
1406
|
-
var templateApiIndex = (
|
|
1419
|
+
var templateApiIndex = (serviceNameTitle, apiList) => {
|
|
1407
1420
|
let imports = "";
|
|
1408
1421
|
let returnStatement = "";
|
|
1409
1422
|
for (const cl of apiList) {
|
|
@@ -1417,9 +1430,17 @@ ${cl}, `;
|
|
|
1417
1430
|
* AUTO GENERATED
|
|
1418
1431
|
*/
|
|
1419
1432
|
${imports}
|
|
1433
|
+
import { author, name, version } from '../package.json'
|
|
1434
|
+
|
|
1435
|
+
console.log(\`\${name}@\${version}\`)
|
|
1420
1436
|
|
|
1421
1437
|
const apis = {
|
|
1422
1438
|
${returnStatement}
|
|
1439
|
+
version: () => console.log({
|
|
1440
|
+
version,
|
|
1441
|
+
name,
|
|
1442
|
+
author
|
|
1443
|
+
})
|
|
1423
1444
|
}
|
|
1424
1445
|
|
|
1425
1446
|
export const ${serviceNameTitle} = apis
|
|
@@ -1819,7 +1840,7 @@ var CodeGenerator = class _CodeGenerator {
|
|
|
1819
1840
|
};
|
|
1820
1841
|
generatePublicOrAdmin(true);
|
|
1821
1842
|
generatePublicOrAdmin(false);
|
|
1822
|
-
const apiIndexBuff = templateApiIndex(
|
|
1843
|
+
const apiIndexBuff = templateApiIndex(serviceNameTitle, mainApiList);
|
|
1823
1844
|
ParserUtils.writeApiMainFile(_CodeGenerator.srcFolder(), serviceNameTitle, apiIndexBuff);
|
|
1824
1845
|
console.log("\nCOMPLETED\n----------\n\n");
|
|
1825
1846
|
return { indexImports: indexImportsSet, queryImports: queryImportsSet };
|