@accelbyte/codegen 0.0.0-dev-20240906023252 → 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.
|
@@ -124,6 +124,18 @@ var extractDescription = (description, options) => {
|
|
|
124
124
|
indentation
|
|
125
125
|
}) : "";
|
|
126
126
|
};
|
|
127
|
+
var getResponseType = ({
|
|
128
|
+
responseClasses,
|
|
129
|
+
defaultType = "unknown"
|
|
130
|
+
}) => {
|
|
131
|
+
const responseClass = responseClasses.length === 1 ? responseClasses?.[0] : "unknown";
|
|
132
|
+
const responseType = responseClass !== "unknown" ? responseClasses?.[0] : defaultType;
|
|
133
|
+
return {
|
|
134
|
+
responseType,
|
|
135
|
+
responseTypeInAxiosResponse: `Promise<AxiosResponse<${responseType}>>`,
|
|
136
|
+
responseTypeInResponse: `Promise<Response<${responseType}>>`
|
|
137
|
+
};
|
|
138
|
+
};
|
|
127
139
|
|
|
128
140
|
// src/templates/template-class.ts
|
|
129
141
|
var getImportableVarMap = () => ({
|
|
@@ -177,6 +189,12 @@ var makeNewImportVarMap2 = () => ({
|
|
|
177
189
|
axios: ["AxiosRequestConfig", "AxiosResponse"]
|
|
178
190
|
});
|
|
179
191
|
var templateApiClass = (className, body, importStatements, returnMethods) => {
|
|
192
|
+
const returnsMethodsWithDescription = Object.keys(returnMethods).reduce((acc, key) => {
|
|
193
|
+
acc += `
|
|
194
|
+
${returnMethods[key]}
|
|
195
|
+
${key},`;
|
|
196
|
+
return acc;
|
|
197
|
+
}, "");
|
|
180
198
|
const $className = className.replace(/Api$/, "$");
|
|
181
199
|
return `/**
|
|
182
200
|
* AUTO GENERATED
|
|
@@ -209,7 +227,7 @@ export function ${className}(sdk: AccelByteSDK, args?: SdkSetConfigParam) {
|
|
|
209
227
|
${body}
|
|
210
228
|
|
|
211
229
|
return {
|
|
212
|
-
${
|
|
230
|
+
${returnsMethodsWithDescription}
|
|
213
231
|
}
|
|
214
232
|
}
|
|
215
233
|
`;
|
|
@@ -594,12 +612,12 @@ var ParserUtils = class _ParserUtils {
|
|
|
594
612
|
fs3.writeFileSync(`${distDir}/version.json`, JSON.stringify(customVersion, null, 2));
|
|
595
613
|
}
|
|
596
614
|
}
|
|
597
|
-
static writeApiFile(distDir, apiName, apiBuffer, imports,
|
|
615
|
+
static writeApiFile(distDir, apiName, apiBuffer, imports, returnMethodsDescription) {
|
|
598
616
|
const newImports = [];
|
|
599
617
|
imports.forEach((el) => {
|
|
600
618
|
newImports.push(el.replace("../../generated-definitions", "../generated-definitions"));
|
|
601
619
|
});
|
|
602
|
-
const fileContent = templateApiClass(apiName, apiBuffer, newImports,
|
|
620
|
+
const fileContent = templateApiClass(apiName, apiBuffer, newImports, returnMethodsDescription);
|
|
603
621
|
fs3.writeFileSync(`${distDir}/${apiName}.ts`, _ParserUtils.prependCopyrightHeader(fileContent));
|
|
604
622
|
}
|
|
605
623
|
static writeApiMainFile(distDir, serviceName, fileContent) {
|
|
@@ -862,7 +880,6 @@ var OpenApiSpec = z2.object({
|
|
|
862
880
|
// src/templates/template-api-method.ts
|
|
863
881
|
var templateApiMethod = ({
|
|
864
882
|
classMethod,
|
|
865
|
-
description,
|
|
866
883
|
httpMethod,
|
|
867
884
|
path: path7,
|
|
868
885
|
pathParams,
|
|
@@ -871,7 +888,6 @@ var templateApiMethod = ({
|
|
|
871
888
|
classGenName,
|
|
872
889
|
methodParams,
|
|
873
890
|
methodParamsNoTypes,
|
|
874
|
-
deprecated,
|
|
875
891
|
xSecurity
|
|
876
892
|
}) => {
|
|
877
893
|
let newPath = `'${path7}'`;
|
|
@@ -902,12 +918,9 @@ var templateApiMethod = ({
|
|
|
902
918
|
}
|
|
903
919
|
}
|
|
904
920
|
const snippetShell = `curl ${snippetShellArgs.join(" \\\n ")}`;
|
|
905
|
-
const
|
|
906
|
-
const resolvedResponseClass = responseClasses.length === 1 ? responseClasses?.[0] : "unknown";
|
|
907
|
-
const responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
|
|
921
|
+
const { responseType, responseTypeInAxiosResponse } = getResponseType({ responseClasses });
|
|
908
922
|
const methodImpl = `
|
|
909
|
-
${
|
|
910
|
-
async function ${classMethod}(${methodParams}): Promise<AxiosResponse<${responseType}>> {
|
|
923
|
+
async function ${classMethod}(${methodParams}): ${responseTypeInAxiosResponse} {
|
|
911
924
|
const $ = new ${classGenName}(axiosInstance, namespace, useSchemaValidation)
|
|
912
925
|
const resp = await $.${classMethod}(${methodParamsNoTypes})
|
|
913
926
|
if (resp.error) throw resp.error
|
|
@@ -983,14 +996,12 @@ var templateMethod = ({
|
|
|
983
996
|
dataPayload = dataType ? `{data, params}` : "{params}";
|
|
984
997
|
}
|
|
985
998
|
const isFileUpload = methodParams.indexOf("data: {file") > -1;
|
|
986
|
-
const
|
|
987
|
-
const resolvedResponseClassValidated =
|
|
999
|
+
const { responseType, responseTypeInResponse } = getResponseType({ responseClasses });
|
|
1000
|
+
const resolvedResponseClassValidated = responseType !== "unknown" ? `${responseType}` : "z.unknown()";
|
|
988
1001
|
methodParams = (queryParamsType ? `${methodParams} ${queryParamsType}` : methodParams).replace(/,\s*$/, "");
|
|
989
1002
|
methodParamsNoTypes = queryParamsType ? `${methodParamsNoTypes} queryParams` : methodParamsNoTypes;
|
|
990
1003
|
const isGuardInvoked = ["get", "post", "put", "patch", "delete"].includes(httpMethod);
|
|
991
|
-
const
|
|
992
|
-
const responseSyncType = "Response";
|
|
993
|
-
const generatedMethodName = `${classMethod}(${methodParams}): Promise<${responseSyncType}<${responseType}>>`;
|
|
1004
|
+
const generatedMethodName = `${classMethod}(${methodParams}): ${responseTypeInResponse}`;
|
|
994
1005
|
let methodImpl = `${descriptionText}
|
|
995
1006
|
${generatedMethodName} {
|
|
996
1007
|
${queryParamsDefault}
|
|
@@ -1048,9 +1059,8 @@ var templateQueryMethod = ({
|
|
|
1048
1059
|
}
|
|
1049
1060
|
}
|
|
1050
1061
|
}
|
|
1051
|
-
const
|
|
1062
|
+
const { responseType } = getResponseType({ responseClasses });
|
|
1052
1063
|
let _methodName = convertMethodNameToHook({ classMethod, apiGenName, isPostFetch, isFetch });
|
|
1053
|
-
const _responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
|
|
1054
1064
|
const _methodParams = methodParams && methodParams.length > 0 ? `& { ${methodParams} }` : "";
|
|
1055
1065
|
const _methodParamsImpl = convertToMethodImplArgs(methodParams);
|
|
1056
1066
|
const queryKey = createQueryKey(apiGenName, classMethod);
|
|
@@ -1065,9 +1075,9 @@ ${descriptionText}
|
|
|
1065
1075
|
export const ${_methodName} = (
|
|
1066
1076
|
sdk: AccelByteSDK,
|
|
1067
1077
|
input: SdkSetConfigParam ${_methodParams},
|
|
1068
|
-
options?: Omit<UseQueryOptions<${
|
|
1069
|
-
callback?: (data: AxiosResponse<${
|
|
1070
|
-
): UseQueryResult<${
|
|
1078
|
+
options?: Omit<UseQueryOptions<${responseType}, AxiosError<ApiError>>, 'queryKey'>,
|
|
1079
|
+
callback?: (data: AxiosResponse<${responseType}>) => void
|
|
1080
|
+
): UseQueryResult<${responseType}, AxiosError<ApiError>> => {
|
|
1071
1081
|
|
|
1072
1082
|
const queryFn = (
|
|
1073
1083
|
sdk: AccelByteSDK,
|
|
@@ -1080,7 +1090,7 @@ export const ${_methodName} = (
|
|
|
1080
1090
|
return response.data
|
|
1081
1091
|
}
|
|
1082
1092
|
|
|
1083
|
-
return ${queryMethod}<${
|
|
1093
|
+
return ${queryMethod}<${responseType}, AxiosError<ApiError>>({
|
|
1084
1094
|
queryKey: [${queryKey}, input],
|
|
1085
1095
|
queryFn: queryFn(sdk, input),
|
|
1086
1096
|
...options
|
|
@@ -1093,9 +1103,9 @@ export const ${_methodName} = (
|
|
|
1093
1103
|
${descriptionText}
|
|
1094
1104
|
export const ${_methodName} = (
|
|
1095
1105
|
sdk: AccelByteSDK,
|
|
1096
|
-
options?: Omit<UseMutationOptions<${
|
|
1097
|
-
callback?: (data: ${
|
|
1098
|
-
): UseMutationResult<${
|
|
1106
|
+
options?: Omit<UseMutationOptions<${responseType}, AxiosError<ApiError>, SdkSetConfigParam ${_methodParams}>, 'mutationKey'>,
|
|
1107
|
+
callback?: (data: ${responseType}) => void
|
|
1108
|
+
): UseMutationResult<${responseType}, AxiosError<ApiError>, SdkSetConfigParam ${_methodParams}> => {
|
|
1099
1109
|
|
|
1100
1110
|
const mutationFn = async (input: SdkSetConfigParam ${_methodParams}) => {
|
|
1101
1111
|
const response =
|
|
@@ -1224,7 +1234,8 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1224
1234
|
tagToSdkClientRecord: {},
|
|
1225
1235
|
tagToSdkFunctionNamesRecord: {},
|
|
1226
1236
|
tagToSdkImportsRecord: {},
|
|
1227
|
-
tagToEndpointQueryRecord: {}
|
|
1237
|
+
tagToEndpointQueryRecord: {},
|
|
1238
|
+
tagToSdkFunctionDescription: {}
|
|
1228
1239
|
},
|
|
1229
1240
|
public: {
|
|
1230
1241
|
arrayDefinitions: [],
|
|
@@ -1234,7 +1245,8 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1234
1245
|
tagToSdkClientRecord: {},
|
|
1235
1246
|
tagToSdkFunctionNamesRecord: {},
|
|
1236
1247
|
tagToSdkImportsRecord: {},
|
|
1237
|
-
tagToEndpointQueryRecord: {}
|
|
1248
|
+
tagToEndpointQueryRecord: {},
|
|
1249
|
+
tagToSdkFunctionDescription: {}
|
|
1238
1250
|
}
|
|
1239
1251
|
};
|
|
1240
1252
|
const sortedPathsByLength = new Map(
|
|
@@ -1266,7 +1278,8 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1266
1278
|
tagToSdkClientRecord,
|
|
1267
1279
|
tagToSdkFunctionNamesRecord,
|
|
1268
1280
|
tagToSdkImportsRecord,
|
|
1269
|
-
tagToEndpointQueryRecord
|
|
1281
|
+
tagToEndpointQueryRecord,
|
|
1282
|
+
tagToSdkFunctionDescription
|
|
1270
1283
|
} = picked;
|
|
1271
1284
|
const tagToClassMethodsMapByType = isAdminEndpoint ? tagToClassMethodsMap.admin : tagToClassMethodsMap.public;
|
|
1272
1285
|
const generatedMethods = {};
|
|
@@ -1346,9 +1359,14 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1346
1359
|
description
|
|
1347
1360
|
});
|
|
1348
1361
|
tagToEndpointQueryRecord[tag] = (tagToEndpointQueryRecord[tag] || "") + queryMethodImpl;
|
|
1362
|
+
const fnDescription = extractDescription(description, { isDeprecated: deprecated, responseClasses });
|
|
1363
|
+
const tagFnDescriptions = tagToSdkFunctionDescription[tag];
|
|
1364
|
+
tagToSdkFunctionDescription[tag] = {
|
|
1365
|
+
...tagFnDescriptions,
|
|
1366
|
+
[classMethod]: fnDescription
|
|
1367
|
+
};
|
|
1349
1368
|
const { generatedMethodString, snippetApiArgs, snippetMethod, snippetShell } = templateApiMethod({
|
|
1350
1369
|
classMethod,
|
|
1351
|
-
description,
|
|
1352
1370
|
httpMethod,
|
|
1353
1371
|
path: pathWithBase,
|
|
1354
1372
|
pathParams,
|
|
@@ -1357,7 +1375,6 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1357
1375
|
classGenName,
|
|
1358
1376
|
methodParams,
|
|
1359
1377
|
methodParamsNoTypes,
|
|
1360
|
-
deprecated,
|
|
1361
1378
|
xSecurity: endpoint["x-security"]
|
|
1362
1379
|
});
|
|
1363
1380
|
tagToSdkClientRecord[tag] = (tagToSdkClientRecord[tag] || "") + generatedMethodString;
|
|
@@ -1729,7 +1746,8 @@ var CodeGenerator = class _CodeGenerator {
|
|
|
1729
1746
|
tagToSdkClientRecord,
|
|
1730
1747
|
tagToSdkFunctionNamesRecord,
|
|
1731
1748
|
tagToSdkImportsRecord,
|
|
1732
|
-
tagToEndpointQueryRecord
|
|
1749
|
+
tagToEndpointQueryRecord,
|
|
1750
|
+
tagToSdkFunctionDescription
|
|
1733
1751
|
} = parsedInformationByType;
|
|
1734
1752
|
const writeApiEndpointFiles = (isAdminEndpoint) => {
|
|
1735
1753
|
const apiList = [];
|
|
@@ -1753,7 +1771,7 @@ var CodeGenerator = class _CodeGenerator {
|
|
|
1753
1771
|
sdkName
|
|
1754
1772
|
);
|
|
1755
1773
|
const apiBuffer = tagToSdkClientRecord[tag];
|
|
1756
|
-
ParserUtils.writeApiFile(DIST_DIR(isAdminEndpoint), apiGenName, apiBuffer, imports,
|
|
1774
|
+
ParserUtils.writeApiFile(DIST_DIR(isAdminEndpoint), apiGenName, apiBuffer, imports, tagToSdkFunctionDescription[tag]);
|
|
1757
1775
|
apiList.push(apiGenName);
|
|
1758
1776
|
indexImportsSet.add(
|
|
1759
1777
|
ParserUtils.getRelativePathToWebSdkSrcFolder(path4.join(DIST_DIR_ENDPOINTS(isAdminEndpoint), `${classGenName}`), targetSrcFolder)
|