@accelbyte/codegen 0.0.0-dev-20240904033042 → 0.0.0-dev-20240910111050
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.
|
@@ -146,6 +146,18 @@ var extractDescription = (description, options) => {
|
|
|
146
146
|
indentation
|
|
147
147
|
}) : "";
|
|
148
148
|
};
|
|
149
|
+
var getResponseType = ({
|
|
150
|
+
responseClasses,
|
|
151
|
+
defaultType = "unknown"
|
|
152
|
+
}) => {
|
|
153
|
+
const responseClass = responseClasses.length === 1 ? responseClasses?.[0] : "unknown";
|
|
154
|
+
const responseType = responseClass !== "unknown" ? responseClasses?.[0] : defaultType;
|
|
155
|
+
return {
|
|
156
|
+
responseType,
|
|
157
|
+
responseTypeInAxiosResponse: `Promise<AxiosResponse<${responseType}>>`,
|
|
158
|
+
responseTypeInResponse: `Promise<Response<${responseType}>>`
|
|
159
|
+
};
|
|
160
|
+
};
|
|
149
161
|
|
|
150
162
|
// src/templates/template-class.ts
|
|
151
163
|
var getImportableVarMap = () => ({
|
|
@@ -199,6 +211,12 @@ var makeNewImportVarMap2 = () => ({
|
|
|
199
211
|
axios: ["AxiosRequestConfig", "AxiosResponse"]
|
|
200
212
|
});
|
|
201
213
|
var templateApiClass = (className, body, importStatements, returnMethods) => {
|
|
214
|
+
const returnsMethodsWithDescription = Object.keys(returnMethods).reduce((acc, key) => {
|
|
215
|
+
acc += `
|
|
216
|
+
${returnMethods[key]}
|
|
217
|
+
${key},`;
|
|
218
|
+
return acc;
|
|
219
|
+
}, "");
|
|
202
220
|
const $className = className.replace(/Api$/, "$");
|
|
203
221
|
return `/**
|
|
204
222
|
* AUTO GENERATED
|
|
@@ -213,9 +231,9 @@ export function ${className}(sdk: AccelByteSDK, args?: SdkSetConfigParam) {
|
|
|
213
231
|
const sdkAssembly = sdk.assembly()
|
|
214
232
|
|
|
215
233
|
const namespace = args?.coreConfig?.namespace ?? sdkAssembly.coreConfig.namespace
|
|
216
|
-
const requestConfig = ApiUtils.mergeAxiosConfigs(sdkAssembly.axiosInstance.defaults as AxiosRequestConfig, args?.axiosConfig?.request)
|
|
234
|
+
const requestConfig = ApiUtils.mergeAxiosConfigs(sdkAssembly.axiosInstance.defaults as AxiosRequestConfig, {...(args?.coreConfig?.baseURL ? {baseURL: args?.coreConfig?.baseURL} : {}), ...args?.axiosConfig?.request})
|
|
217
235
|
const interceptors = args?.axiosConfig?.interceptors ?? sdkAssembly.axiosConfig.interceptors ?? []
|
|
218
|
-
const useSchemaValidation = sdkAssembly.coreConfig.useSchemaValidation
|
|
236
|
+
const useSchemaValidation = args?.coreConfig?.useSchemaValidation ?? sdkAssembly.coreConfig.useSchemaValidation
|
|
219
237
|
const axiosInstance = Network.create(requestConfig)
|
|
220
238
|
|
|
221
239
|
for (const interceptor of interceptors) {
|
|
@@ -231,7 +249,7 @@ export function ${className}(sdk: AccelByteSDK, args?: SdkSetConfigParam) {
|
|
|
231
249
|
${body}
|
|
232
250
|
|
|
233
251
|
return {
|
|
234
|
-
${
|
|
252
|
+
${returnsMethodsWithDescription}
|
|
235
253
|
}
|
|
236
254
|
}
|
|
237
255
|
`;
|
|
@@ -616,12 +634,12 @@ var ParserUtils = class _ParserUtils {
|
|
|
616
634
|
import_fs3.default.writeFileSync(`${distDir}/version.json`, JSON.stringify(customVersion, null, 2));
|
|
617
635
|
}
|
|
618
636
|
}
|
|
619
|
-
static writeApiFile(distDir, apiName, apiBuffer, imports,
|
|
637
|
+
static writeApiFile(distDir, apiName, apiBuffer, imports, returnMethodsDescription) {
|
|
620
638
|
const newImports = [];
|
|
621
639
|
imports.forEach((el) => {
|
|
622
640
|
newImports.push(el.replace("../../generated-definitions", "../generated-definitions"));
|
|
623
641
|
});
|
|
624
|
-
const fileContent = templateApiClass(apiName, apiBuffer, newImports,
|
|
642
|
+
const fileContent = templateApiClass(apiName, apiBuffer, newImports, returnMethodsDescription);
|
|
625
643
|
import_fs3.default.writeFileSync(`${distDir}/${apiName}.ts`, _ParserUtils.prependCopyrightHeader(fileContent));
|
|
626
644
|
}
|
|
627
645
|
static writeApiMainFile(distDir, serviceName, fileContent) {
|
|
@@ -884,7 +902,6 @@ var OpenApiSpec = import_zod2.z.object({
|
|
|
884
902
|
// src/templates/template-api-method.ts
|
|
885
903
|
var templateApiMethod = ({
|
|
886
904
|
classMethod,
|
|
887
|
-
description,
|
|
888
905
|
httpMethod,
|
|
889
906
|
path: path7,
|
|
890
907
|
pathParams,
|
|
@@ -893,7 +910,6 @@ var templateApiMethod = ({
|
|
|
893
910
|
classGenName,
|
|
894
911
|
methodParams,
|
|
895
912
|
methodParamsNoTypes,
|
|
896
|
-
deprecated,
|
|
897
913
|
xSecurity
|
|
898
914
|
}) => {
|
|
899
915
|
let newPath = `'${path7}'`;
|
|
@@ -924,12 +940,9 @@ var templateApiMethod = ({
|
|
|
924
940
|
}
|
|
925
941
|
}
|
|
926
942
|
const snippetShell = `curl ${snippetShellArgs.join(" \\\n ")}`;
|
|
927
|
-
const
|
|
928
|
-
const resolvedResponseClass = responseClasses.length === 1 ? responseClasses?.[0] : "unknown";
|
|
929
|
-
const responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
|
|
943
|
+
const { responseType, responseTypeInAxiosResponse } = getResponseType({ responseClasses });
|
|
930
944
|
const methodImpl = `
|
|
931
|
-
${
|
|
932
|
-
async function ${classMethod}(${methodParams}): Promise<AxiosResponse<${responseType}>> {
|
|
945
|
+
async function ${classMethod}(${methodParams}): ${responseTypeInAxiosResponse} {
|
|
933
946
|
const $ = new ${classGenName}(axiosInstance, namespace, useSchemaValidation)
|
|
934
947
|
const resp = await $.${classMethod}(${methodParamsNoTypes})
|
|
935
948
|
if (resp.error) throw resp.error
|
|
@@ -1005,14 +1018,12 @@ var templateMethod = ({
|
|
|
1005
1018
|
dataPayload = dataType ? `{data, params}` : "{params}";
|
|
1006
1019
|
}
|
|
1007
1020
|
const isFileUpload = methodParams.indexOf("data: {file") > -1;
|
|
1008
|
-
const
|
|
1009
|
-
const resolvedResponseClassValidated =
|
|
1021
|
+
const { responseType, responseTypeInResponse } = getResponseType({ responseClasses });
|
|
1022
|
+
const resolvedResponseClassValidated = responseType !== "unknown" ? `${responseType}` : "z.unknown()";
|
|
1010
1023
|
methodParams = (queryParamsType ? `${methodParams} ${queryParamsType}` : methodParams).replace(/,\s*$/, "");
|
|
1011
1024
|
methodParamsNoTypes = queryParamsType ? `${methodParamsNoTypes} queryParams` : methodParamsNoTypes;
|
|
1012
1025
|
const isGuardInvoked = ["get", "post", "put", "patch", "delete"].includes(httpMethod);
|
|
1013
|
-
const
|
|
1014
|
-
const responseSyncType = "Response";
|
|
1015
|
-
const generatedMethodName = `${classMethod}(${methodParams}): Promise<${responseSyncType}<${responseType}>>`;
|
|
1026
|
+
const generatedMethodName = `${classMethod}(${methodParams}): ${responseTypeInResponse}`;
|
|
1016
1027
|
let methodImpl = `${descriptionText}
|
|
1017
1028
|
${generatedMethodName} {
|
|
1018
1029
|
${queryParamsDefault}
|
|
@@ -1070,9 +1081,8 @@ var templateQueryMethod = ({
|
|
|
1070
1081
|
}
|
|
1071
1082
|
}
|
|
1072
1083
|
}
|
|
1073
|
-
const
|
|
1084
|
+
const { responseType } = getResponseType({ responseClasses });
|
|
1074
1085
|
let _methodName = convertMethodNameToHook({ classMethod, apiGenName, isPostFetch, isFetch });
|
|
1075
|
-
const _responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
|
|
1076
1086
|
const _methodParams = methodParams && methodParams.length > 0 ? `& { ${methodParams} }` : "";
|
|
1077
1087
|
const _methodParamsImpl = convertToMethodImplArgs(methodParams);
|
|
1078
1088
|
const queryKey = createQueryKey(apiGenName, classMethod);
|
|
@@ -1087,9 +1097,9 @@ ${descriptionText}
|
|
|
1087
1097
|
export const ${_methodName} = (
|
|
1088
1098
|
sdk: AccelByteSDK,
|
|
1089
1099
|
input: SdkSetConfigParam ${_methodParams},
|
|
1090
|
-
options?: Omit<UseQueryOptions<${
|
|
1091
|
-
callback?: (data: AxiosResponse<${
|
|
1092
|
-
): UseQueryResult<${
|
|
1100
|
+
options?: Omit<UseQueryOptions<${responseType}, AxiosError<ApiError>>, 'queryKey'>,
|
|
1101
|
+
callback?: (data: AxiosResponse<${responseType}>) => void
|
|
1102
|
+
): UseQueryResult<${responseType}, AxiosError<ApiError>> => {
|
|
1093
1103
|
|
|
1094
1104
|
const queryFn = (
|
|
1095
1105
|
sdk: AccelByteSDK,
|
|
@@ -1102,7 +1112,7 @@ export const ${_methodName} = (
|
|
|
1102
1112
|
return response.data
|
|
1103
1113
|
}
|
|
1104
1114
|
|
|
1105
|
-
return ${queryMethod}<${
|
|
1115
|
+
return ${queryMethod}<${responseType}, AxiosError<ApiError>>({
|
|
1106
1116
|
queryKey: [${queryKey}, input],
|
|
1107
1117
|
queryFn: queryFn(sdk, input),
|
|
1108
1118
|
...options
|
|
@@ -1115,9 +1125,9 @@ export const ${_methodName} = (
|
|
|
1115
1125
|
${descriptionText}
|
|
1116
1126
|
export const ${_methodName} = (
|
|
1117
1127
|
sdk: AccelByteSDK,
|
|
1118
|
-
options?: Omit<UseMutationOptions<${
|
|
1119
|
-
callback?: (data: ${
|
|
1120
|
-
): UseMutationResult<${
|
|
1128
|
+
options?: Omit<UseMutationOptions<${responseType}, AxiosError<ApiError>, SdkSetConfigParam ${_methodParams}>, 'mutationKey'>,
|
|
1129
|
+
callback?: (data: ${responseType}) => void
|
|
1130
|
+
): UseMutationResult<${responseType}, AxiosError<ApiError>, SdkSetConfigParam ${_methodParams}> => {
|
|
1121
1131
|
|
|
1122
1132
|
const mutationFn = async (input: SdkSetConfigParam ${_methodParams}) => {
|
|
1123
1133
|
const response =
|
|
@@ -1246,7 +1256,8 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1246
1256
|
tagToSdkClientRecord: {},
|
|
1247
1257
|
tagToSdkFunctionNamesRecord: {},
|
|
1248
1258
|
tagToSdkImportsRecord: {},
|
|
1249
|
-
tagToEndpointQueryRecord: {}
|
|
1259
|
+
tagToEndpointQueryRecord: {},
|
|
1260
|
+
tagToSdkFunctionDescription: {}
|
|
1250
1261
|
},
|
|
1251
1262
|
public: {
|
|
1252
1263
|
arrayDefinitions: [],
|
|
@@ -1256,7 +1267,8 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1256
1267
|
tagToSdkClientRecord: {},
|
|
1257
1268
|
tagToSdkFunctionNamesRecord: {},
|
|
1258
1269
|
tagToSdkImportsRecord: {},
|
|
1259
|
-
tagToEndpointQueryRecord: {}
|
|
1270
|
+
tagToEndpointQueryRecord: {},
|
|
1271
|
+
tagToSdkFunctionDescription: {}
|
|
1260
1272
|
}
|
|
1261
1273
|
};
|
|
1262
1274
|
const sortedPathsByLength = new Map(
|
|
@@ -1288,7 +1300,8 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1288
1300
|
tagToSdkClientRecord,
|
|
1289
1301
|
tagToSdkFunctionNamesRecord,
|
|
1290
1302
|
tagToSdkImportsRecord,
|
|
1291
|
-
tagToEndpointQueryRecord
|
|
1303
|
+
tagToEndpointQueryRecord,
|
|
1304
|
+
tagToSdkFunctionDescription
|
|
1292
1305
|
} = picked;
|
|
1293
1306
|
const tagToClassMethodsMapByType = isAdminEndpoint ? tagToClassMethodsMap.admin : tagToClassMethodsMap.public;
|
|
1294
1307
|
const generatedMethods = {};
|
|
@@ -1368,9 +1381,14 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1368
1381
|
description
|
|
1369
1382
|
});
|
|
1370
1383
|
tagToEndpointQueryRecord[tag] = (tagToEndpointQueryRecord[tag] || "") + queryMethodImpl;
|
|
1384
|
+
const fnDescription = extractDescription(description, { isDeprecated: deprecated, responseClasses });
|
|
1385
|
+
const tagFnDescriptions = tagToSdkFunctionDescription[tag];
|
|
1386
|
+
tagToSdkFunctionDescription[tag] = {
|
|
1387
|
+
...tagFnDescriptions,
|
|
1388
|
+
[classMethod]: fnDescription
|
|
1389
|
+
};
|
|
1371
1390
|
const { generatedMethodString, snippetApiArgs, snippetMethod, snippetShell } = templateApiMethod({
|
|
1372
1391
|
classMethod,
|
|
1373
|
-
description,
|
|
1374
1392
|
httpMethod,
|
|
1375
1393
|
path: pathWithBase,
|
|
1376
1394
|
pathParams,
|
|
@@ -1379,7 +1397,6 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1379
1397
|
classGenName,
|
|
1380
1398
|
methodParams,
|
|
1381
1399
|
methodParamsNoTypes,
|
|
1382
|
-
deprecated,
|
|
1383
1400
|
xSecurity: endpoint["x-security"]
|
|
1384
1401
|
});
|
|
1385
1402
|
tagToSdkClientRecord[tag] = (tagToSdkClientRecord[tag] || "") + generatedMethodString;
|
|
@@ -1751,7 +1768,8 @@ var CodeGenerator = class _CodeGenerator {
|
|
|
1751
1768
|
tagToSdkClientRecord,
|
|
1752
1769
|
tagToSdkFunctionNamesRecord,
|
|
1753
1770
|
tagToSdkImportsRecord,
|
|
1754
|
-
tagToEndpointQueryRecord
|
|
1771
|
+
tagToEndpointQueryRecord,
|
|
1772
|
+
tagToSdkFunctionDescription
|
|
1755
1773
|
} = parsedInformationByType;
|
|
1756
1774
|
const writeApiEndpointFiles = (isAdminEndpoint) => {
|
|
1757
1775
|
const apiList = [];
|
|
@@ -1775,7 +1793,7 @@ var CodeGenerator = class _CodeGenerator {
|
|
|
1775
1793
|
sdkName
|
|
1776
1794
|
);
|
|
1777
1795
|
const apiBuffer = tagToSdkClientRecord[tag];
|
|
1778
|
-
ParserUtils.writeApiFile(DIST_DIR(isAdminEndpoint), apiGenName, apiBuffer, imports,
|
|
1796
|
+
ParserUtils.writeApiFile(DIST_DIR(isAdminEndpoint), apiGenName, apiBuffer, imports, tagToSdkFunctionDescription[tag]);
|
|
1779
1797
|
apiList.push(apiGenName);
|
|
1780
1798
|
indexImportsSet.add(
|
|
1781
1799
|
ParserUtils.getRelativePathToWebSdkSrcFolder(import_path3.default.join(DIST_DIR_ENDPOINTS(isAdminEndpoint), `${classGenName}`), targetSrcFolder)
|