@accelbyte/codegen 2.3.1 → 3.0.3
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.
|
@@ -58,7 +58,7 @@ class CliParser {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const getImportableVarMap$1 = () => ({
|
|
61
|
-
"@accelbyte/sdk": ["CodeGenUtil", "
|
|
61
|
+
"@accelbyte/sdk": ["CodeGenUtil", "IResponse", "Validate"],
|
|
62
62
|
axios: ["AxiosRequestConfig", "AxiosResponse"],
|
|
63
63
|
zod: ["z"]
|
|
64
64
|
});
|
|
@@ -91,14 +91,14 @@ ${generateImports(body, importStatements, makeNewImportVarMap$1(), getImportable
|
|
|
91
91
|
|
|
92
92
|
export class ${className} {
|
|
93
93
|
// @ts-ignore
|
|
94
|
-
constructor(private axiosInstance: AxiosInstance, private namespace: string, private
|
|
94
|
+
constructor(private axiosInstance: AxiosInstance, private namespace: string, private isValidationEnabled = true) {}
|
|
95
95
|
${body}
|
|
96
96
|
}
|
|
97
97
|
`;
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
const getImportableVarMap = () => ({
|
|
101
|
-
"@accelbyte/sdk": ["CodeGenUtil", "
|
|
101
|
+
"@accelbyte/sdk": ["CodeGenUtil", "IResponse", "Validate", "ApiArgs", "Network", "AccelbyteSDK"]
|
|
102
102
|
});
|
|
103
103
|
const makeNewImportVarMap = () => ({
|
|
104
104
|
"@accelbyte/sdk": ["AccelbyteSDK", "ApiArgs", "ApiUtils"]
|
|
@@ -114,7 +114,6 @@ export function ${className}(sdk: AccelbyteSDK, args?: ApiArgs) {
|
|
|
114
114
|
const sdkAssembly = sdk.assembly()
|
|
115
115
|
|
|
116
116
|
const namespace = args?.namespace ? args?.namespace : sdkAssembly.namespace
|
|
117
|
-
const cache = args?.cache ? args?.cache : sdkAssembly.cache
|
|
118
117
|
const requestConfig = ApiUtils.mergedConfigs(sdkAssembly.config, args)
|
|
119
118
|
const isValidationEnabled = args?.isValidationEnabled !== false
|
|
120
119
|
${body}
|
|
@@ -1095,28 +1094,20 @@ const templateMethod = ({
|
|
|
1095
1094
|
methodParamsNoTypes = queryParamsType ? `${methodParamsNoTypes} queryParams` : methodParamsNoTypes;
|
|
1096
1095
|
let methodImpl = "";
|
|
1097
1096
|
const isCacheFetch = ["get"].includes(httpMethod) && resolvedResponseClass !== "unknown";
|
|
1098
|
-
const cachedFetchMethod = classMethod;
|
|
1099
1097
|
const deprecateTag = isCacheFetch ? `/**
|
|
1100
1098
|
* @deprecated Use "${classMethod}()" instead.
|
|
1101
1099
|
*/` : "";
|
|
1102
1100
|
const isGuardInvoked = ["get", "post", "put", "patch", "delete"].includes(httpMethod);
|
|
1103
|
-
const methodName = httpMethod === "get" ? cachedFetchMethod : ["post", "put", "patch", "delete"].includes(httpMethod) ? classMethod : "";
|
|
1104
1101
|
const responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
|
|
1105
|
-
const generateMethodName = () => `${
|
|
1106
|
-
const responseSyncType =
|
|
1102
|
+
const generateMethodName = () => `${classMethod}(${methodParams}): Promise<${responseSyncType}<${responseType}>>`;
|
|
1103
|
+
const responseSyncType = "IResponse";
|
|
1107
1104
|
methodImpl = `${descriptionText}
|
|
1108
1105
|
${generateMethodName()} {
|
|
1109
1106
|
${queryParamsDefault}
|
|
1110
1107
|
const url = ${newPath} ${formPayloadString} ${isFileUpload ? "\n// TODO file upload not implemented" : ""}
|
|
1111
1108
|
const resultPromise = this.axiosInstance.${httpMethod}(url, ${dataPayload})
|
|
1112
1109
|
|
|
1113
|
-
${
|
|
1114
|
-
|
|
1115
|
-
if (!this.cache) {
|
|
1116
|
-
return SdkCache.withoutCache(res)
|
|
1117
|
-
}
|
|
1118
|
-
const cacheKey = url + CodeGenUtil.hashCode(JSON.stringify({ params }))
|
|
1119
|
-
return SdkCache.withCache(cacheKey, res)` : ""}${["post", "put", "patch", "delete"].includes(httpMethod) ? ` return this.isValidationEnabled ? Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}') : Validate.unsafeResponse(() => resultPromise)` : ""}
|
|
1110
|
+
${` return this.isValidationEnabled ? Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}') : Validate.unsafeResponse(() => resultPromise)`}
|
|
1120
1111
|
}
|
|
1121
1112
|
`;
|
|
1122
1113
|
if (!isGuardInvoked) {
|
|
@@ -1189,7 +1180,7 @@ const templateApiMethod = ({
|
|
|
1189
1180
|
const methodImpl = `
|
|
1190
1181
|
${descriptionText}
|
|
1191
1182
|
async function ${classMethod}(${methodParams}): Promise<${responseType}> {
|
|
1192
|
-
const $ = new ${classGenName}(Network.create(requestConfig), namespace,
|
|
1183
|
+
const $ = new ${classGenName}(Network.create(requestConfig), namespace, isValidationEnabled)
|
|
1193
1184
|
const resp = await $.${classMethod}(${methodParamsNoTypes})
|
|
1194
1185
|
if (resp.error) throw resp.error
|
|
1195
1186
|
return resp.response.data
|