@accelbyte/codegen 0.0.0-dev-20240828055251 → 0.0.0-dev-20240904015634
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.
|
@@ -104,12 +104,26 @@ var getPermissionType = (permission) => {
|
|
|
104
104
|
return type || null;
|
|
105
105
|
};
|
|
106
106
|
var removeAdminPrefix = (name) => name.startsWith("Admin") && name !== "Admin" ? name.replace(/^Admin/, "") : name;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
107
|
+
var escapeComment = (string) => string.replace(/\*\//g, "*\\/").replace(/\n/g, "\n * ");
|
|
108
|
+
var generateJsDoc = ({ indentation = 4, lines }) => {
|
|
109
|
+
const indent = " ".repeat(indentation);
|
|
110
|
+
const formattedLines = lines.filter(Boolean).map((line) => `${indent} * ${line}`).join("\n");
|
|
111
|
+
return `${indent}/**
|
|
112
|
+
${formattedLines}
|
|
113
|
+
${indent} */`;
|
|
114
|
+
};
|
|
115
|
+
var extractDescription = (description, options) => {
|
|
116
|
+
const { indentation = 2, responseClasses, other, isDeprecated } = options;
|
|
117
|
+
return description ? generateJsDoc({
|
|
118
|
+
lines: [
|
|
119
|
+
isDeprecated ? "@deprecated" : "",
|
|
120
|
+
escapeComment(description),
|
|
121
|
+
...responseClasses.length > 1 ? [" ", "#### Response type:", ...responseClasses.map((val) => `- \`${val}\``)] : "",
|
|
122
|
+
...options?.other ? other : ""
|
|
123
|
+
],
|
|
124
|
+
indentation
|
|
125
|
+
}) : "";
|
|
126
|
+
};
|
|
113
127
|
|
|
114
128
|
// src/templates/template-class.ts
|
|
115
129
|
var getImportableVarMap = () => ({
|
|
@@ -160,7 +174,7 @@ var getImportableVarMap2 = () => ({
|
|
|
160
174
|
});
|
|
161
175
|
var makeNewImportVarMap2 = () => ({
|
|
162
176
|
"@accelbyte/sdk": ["AccelByteSDK", "SdkSetConfigParam", "ApiUtils", "Network"],
|
|
163
|
-
axios: ["AxiosResponse"]
|
|
177
|
+
axios: ["AxiosRequestConfig", "AxiosResponse"]
|
|
164
178
|
});
|
|
165
179
|
var templateApiClass = (className, body, importStatements, returnMethods) => {
|
|
166
180
|
const $className = className.replace(/Api$/, "$");
|
|
@@ -177,7 +191,7 @@ export function ${className}(sdk: AccelByteSDK, args?: SdkSetConfigParam) {
|
|
|
177
191
|
const sdkAssembly = sdk.assembly()
|
|
178
192
|
|
|
179
193
|
const namespace = args?.coreConfig?.namespace ?? sdkAssembly.coreConfig.namespace
|
|
180
|
-
const requestConfig = ApiUtils.mergeAxiosConfigs(sdkAssembly.
|
|
194
|
+
const requestConfig = ApiUtils.mergeAxiosConfigs(sdkAssembly.axiosInstance.defaults as AxiosRequestConfig, args?.axiosConfig?.request)
|
|
181
195
|
const interceptors = args?.axiosConfig?.interceptors ?? sdkAssembly.axiosConfig.interceptors ?? []
|
|
182
196
|
const useSchemaValidation = sdkAssembly.coreConfig.useSchemaValidation
|
|
183
197
|
const axiosInstance = Network.create(requestConfig)
|
|
@@ -437,25 +451,23 @@ var ParserUtils = class _ParserUtils {
|
|
|
437
451
|
}
|
|
438
452
|
return null;
|
|
439
453
|
};
|
|
440
|
-
static
|
|
454
|
+
static get2xxResponses(methodEntity) {
|
|
441
455
|
const keys = Object.keys(methodEntity);
|
|
442
|
-
|
|
443
|
-
keys.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
} else {
|
|
455
|
-
}
|
|
456
|
+
const responseClasses = [];
|
|
457
|
+
const statusCodes = keys.filter((key) => String(key).startsWith("2"));
|
|
458
|
+
statusCodes.forEach((key) => {
|
|
459
|
+
const sch = methodEntity[key].schema;
|
|
460
|
+
const schV3 = methodEntity[key].content && methodEntity[key].content["application/json"].schema;
|
|
461
|
+
if (sch?.$ref) {
|
|
462
|
+
responseClasses.push(_ParserUtils.parseRefType(sch.$ref));
|
|
463
|
+
} else if (sch?.type === "array" && sch.items?.$ref) {
|
|
464
|
+
responseClasses.push(`${_ParserUtils.parseRefType(sch.items.$ref)}Array`);
|
|
465
|
+
} else if (schV3?.$ref) {
|
|
466
|
+
responseClasses.push(_ParserUtils.parseRefType(schV3.$ref));
|
|
467
|
+
} else {
|
|
456
468
|
}
|
|
457
469
|
});
|
|
458
|
-
return
|
|
470
|
+
return responseClasses;
|
|
459
471
|
}
|
|
460
472
|
static isFormUrlEncoded(httpMethod, contentTypes) {
|
|
461
473
|
if (!contentTypes || contentTypes.length < 1) {
|
|
@@ -855,7 +867,7 @@ var templateApiMethod = ({
|
|
|
855
867
|
path: path7,
|
|
856
868
|
pathParams,
|
|
857
869
|
bodyParams,
|
|
858
|
-
|
|
870
|
+
responseClasses,
|
|
859
871
|
classGenName,
|
|
860
872
|
methodParams,
|
|
861
873
|
methodParamsNoTypes,
|
|
@@ -890,8 +902,8 @@ var templateApiMethod = ({
|
|
|
890
902
|
}
|
|
891
903
|
}
|
|
892
904
|
const snippetShell = `curl ${snippetShellArgs.join(" \\\n ")}`;
|
|
893
|
-
const descriptionText = extractDescription(description, { isDeprecated: deprecated });
|
|
894
|
-
const resolvedResponseClass =
|
|
905
|
+
const descriptionText = extractDescription(description, { isDeprecated: deprecated, responseClasses });
|
|
906
|
+
const resolvedResponseClass = responseClasses.length === 1 ? responseClasses?.[0] : "unknown";
|
|
895
907
|
const responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
|
|
896
908
|
const methodImpl = `
|
|
897
909
|
${descriptionText}
|
|
@@ -923,7 +935,7 @@ var templateMethod = ({
|
|
|
923
935
|
bodyParams,
|
|
924
936
|
queryParams,
|
|
925
937
|
isFormUrlEncoded,
|
|
926
|
-
|
|
938
|
+
responseClasses,
|
|
927
939
|
deprecated
|
|
928
940
|
}) => {
|
|
929
941
|
let methodParams = "";
|
|
@@ -959,7 +971,7 @@ var templateMethod = ({
|
|
|
959
971
|
const isPostPutPatch = ["post", "put", "patch"].includes(httpMethod);
|
|
960
972
|
const isDelete = ["delete"].includes(httpMethod);
|
|
961
973
|
let dataPayload = "{params}";
|
|
962
|
-
const descriptionText = extractDescription(description, { isDeprecated: deprecated });
|
|
974
|
+
const descriptionText = extractDescription(description, { isDeprecated: deprecated, responseClasses });
|
|
963
975
|
let formPayloadString = "";
|
|
964
976
|
if (isFormUrlEncoded) {
|
|
965
977
|
formPayloadString = ``;
|
|
@@ -971,8 +983,8 @@ var templateMethod = ({
|
|
|
971
983
|
dataPayload = dataType ? `{data, params}` : "{params}";
|
|
972
984
|
}
|
|
973
985
|
const isFileUpload = methodParams.indexOf("data: {file") > -1;
|
|
974
|
-
const resolvedResponseClass =
|
|
975
|
-
const resolvedResponseClassValidated =
|
|
986
|
+
const resolvedResponseClass = responseClasses.length === 1 ? responseClasses?.[0] : "unknown";
|
|
987
|
+
const resolvedResponseClassValidated = responseClasses.length === 1 ? responseClasses?.[0] : "z.unknown()";
|
|
976
988
|
methodParams = (queryParamsType ? `${methodParams} ${queryParamsType}` : methodParams).replace(/,\s*$/, "");
|
|
977
989
|
methodParamsNoTypes = queryParamsType ? `${methodParamsNoTypes} queryParams` : methodParamsNoTypes;
|
|
978
990
|
const isGuardInvoked = ["get", "post", "put", "patch", "delete"].includes(httpMethod);
|
|
@@ -1007,9 +1019,11 @@ var templateQueryMethod = ({
|
|
|
1007
1019
|
httpMethod,
|
|
1008
1020
|
path: path7,
|
|
1009
1021
|
pathParams,
|
|
1010
|
-
|
|
1022
|
+
responseClasses,
|
|
1011
1023
|
methodParams,
|
|
1012
|
-
apiGenName
|
|
1024
|
+
apiGenName,
|
|
1025
|
+
description,
|
|
1026
|
+
deprecated
|
|
1013
1027
|
}) => {
|
|
1014
1028
|
const isPostFetch = httpMethod === "post" && (POST_FETCH_INCLUDES_PATH.some((p) => path7.includes(p)) || path7.endsWith("/list"));
|
|
1015
1029
|
const isFetch = classMethod.startsWith("fetch");
|
|
@@ -1034,20 +1048,27 @@ var templateQueryMethod = ({
|
|
|
1034
1048
|
}
|
|
1035
1049
|
}
|
|
1036
1050
|
}
|
|
1037
|
-
const resolvedResponseClass =
|
|
1051
|
+
const resolvedResponseClass = responseClasses.length === 1 ? responseClasses?.[0] : "unknown";
|
|
1038
1052
|
let _methodName = convertMethodNameToHook({ classMethod, apiGenName, isPostFetch, isFetch });
|
|
1039
1053
|
const _responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
|
|
1040
1054
|
const _methodParams = methodParams && methodParams.length > 0 ? `& { ${methodParams} }` : "";
|
|
1041
1055
|
const _methodParamsImpl = convertToMethodImplArgs(methodParams);
|
|
1056
|
+
const queryKey = createQueryKey(apiGenName, classMethod);
|
|
1057
|
+
const descriptionText = extractDescription(description, {
|
|
1058
|
+
isDeprecated: deprecated,
|
|
1059
|
+
responseClasses,
|
|
1060
|
+
other: [" ", "#### Default Query Options", "The default options include:", "```", "{", ` queryKey: [${queryKey}, input]`, "}", "```"]
|
|
1061
|
+
});
|
|
1042
1062
|
const queryMethodImpl = `
|
|
1043
1063
|
|
|
1064
|
+
${descriptionText}
|
|
1044
1065
|
export const ${_methodName} = (
|
|
1045
1066
|
sdk: AccelByteSDK,
|
|
1046
1067
|
input: SdkSetConfigParam ${_methodParams},
|
|
1047
1068
|
options?: Omit<UseQueryOptions<${_responseType}, AxiosError<ApiError>>, 'queryKey'>,
|
|
1048
1069
|
callback?: (data: AxiosResponse<${_responseType}>) => void
|
|
1049
1070
|
): UseQueryResult<${_responseType}, AxiosError<ApiError>> => {
|
|
1050
|
-
|
|
1071
|
+
|
|
1051
1072
|
const queryFn = (
|
|
1052
1073
|
sdk: AccelByteSDK,
|
|
1053
1074
|
input: Parameters<typeof ${_methodName}>[1]
|
|
@@ -1060,7 +1081,7 @@ export const ${_methodName} = (
|
|
|
1060
1081
|
}
|
|
1061
1082
|
|
|
1062
1083
|
return ${queryMethod}<${_responseType}, AxiosError<ApiError>>({
|
|
1063
|
-
queryKey: [${
|
|
1084
|
+
queryKey: [${queryKey}, input],
|
|
1064
1085
|
queryFn: queryFn(sdk, input),
|
|
1065
1086
|
...options
|
|
1066
1087
|
})
|
|
@@ -1069,12 +1090,13 @@ export const ${_methodName} = (
|
|
|
1069
1090
|
`;
|
|
1070
1091
|
const mutationMethodImpl = `
|
|
1071
1092
|
|
|
1093
|
+
${descriptionText}
|
|
1072
1094
|
export const ${_methodName} = (
|
|
1073
1095
|
sdk: AccelByteSDK,
|
|
1074
1096
|
options?: Omit<UseMutationOptions<${_responseType}, AxiosError<ApiError>, SdkSetConfigParam ${_methodParams}>, 'mutationKey'>,
|
|
1075
1097
|
callback?: (data: ${_responseType}) => void
|
|
1076
1098
|
): UseMutationResult<${_responseType}, AxiosError<ApiError>, SdkSetConfigParam ${_methodParams}> => {
|
|
1077
|
-
|
|
1099
|
+
|
|
1078
1100
|
const mutationFn = async (input: SdkSetConfigParam ${_methodParams}) => {
|
|
1079
1101
|
const response =
|
|
1080
1102
|
(await ${apiGenName}(sdk, { coreConfig: input.coreConfig, axiosConfig: input.axiosConfig }).
|
|
@@ -1084,7 +1106,7 @@ export const ${_methodName} = (
|
|
|
1084
1106
|
}
|
|
1085
1107
|
|
|
1086
1108
|
return useMutation({
|
|
1087
|
-
mutationKey: [${
|
|
1109
|
+
mutationKey: [${queryKey}],
|
|
1088
1110
|
mutationFn,
|
|
1089
1111
|
...options
|
|
1090
1112
|
})
|
|
@@ -1274,12 +1296,12 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1274
1296
|
snippetMap[pathWithBase] = {};
|
|
1275
1297
|
}
|
|
1276
1298
|
const description = endpoint.description?.replace(/\s+/g, " ") || "";
|
|
1277
|
-
const
|
|
1299
|
+
const responseClasses = ParserUtils.get2xxResponses(endpoint.responses);
|
|
1300
|
+
const responseClass = responseClasses.length > 1 ? null : responseClasses?.[0];
|
|
1278
1301
|
const { className, classGenName } = ParserUtils.generateClassName(tag, isAdminEndpoint);
|
|
1279
1302
|
tagToClassImportsRecord[className] = tagToClassImportsRecord[className] ? tagToClassImportsRecord[className] : {};
|
|
1280
1303
|
if (responseClass) {
|
|
1281
|
-
|
|
1282
|
-
tagToClassImportsRecord[className][importTypeClass] = `import { ${importTypeClass} } from '../../generated-definitions/${importTypeClass}.js'`;
|
|
1304
|
+
tagToClassImportsRecord[className][responseClass] = `import { ${responseClass} } from '../../generated-definitions/${responseClass}.js'`;
|
|
1283
1305
|
}
|
|
1284
1306
|
if (responseClass && responseClass.endsWith("Array")) {
|
|
1285
1307
|
arrayDefinitions.push(responseClass);
|
|
@@ -1307,7 +1329,7 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1307
1329
|
bodyParams,
|
|
1308
1330
|
queryParams,
|
|
1309
1331
|
isFormUrlEncoded,
|
|
1310
|
-
|
|
1332
|
+
responseClasses,
|
|
1311
1333
|
deprecated
|
|
1312
1334
|
});
|
|
1313
1335
|
tagToEndpointClassesRecord[tag] = (tagToEndpointClassesRecord[tag] || "") + methodImpl;
|
|
@@ -1317,9 +1339,11 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1317
1339
|
httpMethod,
|
|
1318
1340
|
path: pathWithBase,
|
|
1319
1341
|
pathParams,
|
|
1320
|
-
|
|
1342
|
+
responseClasses,
|
|
1321
1343
|
methodParams,
|
|
1322
|
-
apiGenName
|
|
1344
|
+
apiGenName,
|
|
1345
|
+
deprecated,
|
|
1346
|
+
description
|
|
1323
1347
|
});
|
|
1324
1348
|
tagToEndpointQueryRecord[tag] = (tagToEndpointQueryRecord[tag] || "") + queryMethodImpl;
|
|
1325
1349
|
const { generatedMethodString, snippetApiArgs, snippetMethod, snippetShell } = templateApiMethod({
|
|
@@ -1329,7 +1353,7 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1329
1353
|
path: pathWithBase,
|
|
1330
1354
|
pathParams,
|
|
1331
1355
|
bodyParams,
|
|
1332
|
-
|
|
1356
|
+
responseClasses,
|
|
1333
1357
|
classGenName,
|
|
1334
1358
|
methodParams,
|
|
1335
1359
|
methodParamsNoTypes,
|