@accelbyte/codegen 2.3.1 → 3.0.4
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.
|
@@ -81,7 +81,7 @@ class CliParser {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const getImportableVarMap$1 = () => ({
|
|
84
|
-
"@accelbyte/sdk": ["CodeGenUtil", "
|
|
84
|
+
"@accelbyte/sdk": ["CodeGenUtil", "IResponse", "Validate"],
|
|
85
85
|
axios: ["AxiosRequestConfig", "AxiosResponse"],
|
|
86
86
|
zod: ["z"]
|
|
87
87
|
});
|
|
@@ -114,14 +114,14 @@ ${generateImports(body, importStatements, makeNewImportVarMap$1(), getImportable
|
|
|
114
114
|
|
|
115
115
|
export class ${className} {
|
|
116
116
|
// @ts-ignore
|
|
117
|
-
constructor(private axiosInstance: AxiosInstance, private namespace: string, private
|
|
117
|
+
constructor(private axiosInstance: AxiosInstance, private namespace: string, private isValidationEnabled = true) {}
|
|
118
118
|
${body}
|
|
119
119
|
}
|
|
120
120
|
`;
|
|
121
121
|
};
|
|
122
122
|
|
|
123
123
|
const getImportableVarMap = () => ({
|
|
124
|
-
"@accelbyte/sdk": ["CodeGenUtil", "
|
|
124
|
+
"@accelbyte/sdk": ["CodeGenUtil", "IResponse", "Validate", "ApiArgs", "Network", "AccelbyteSDK"]
|
|
125
125
|
});
|
|
126
126
|
const makeNewImportVarMap = () => ({
|
|
127
127
|
"@accelbyte/sdk": ["AccelbyteSDK", "ApiArgs", "ApiUtils"]
|
|
@@ -137,7 +137,6 @@ export function ${className}(sdk: AccelbyteSDK, args?: ApiArgs) {
|
|
|
137
137
|
const sdkAssembly = sdk.assembly()
|
|
138
138
|
|
|
139
139
|
const namespace = args?.namespace ? args?.namespace : sdkAssembly.namespace
|
|
140
|
-
const cache = args?.cache ? args?.cache : sdkAssembly.cache
|
|
141
140
|
const requestConfig = ApiUtils.mergedConfigs(sdkAssembly.config, args)
|
|
142
141
|
const isValidationEnabled = args?.isValidationEnabled !== false
|
|
143
142
|
${body}
|
|
@@ -1118,28 +1117,20 @@ const templateMethod = ({
|
|
|
1118
1117
|
methodParamsNoTypes = queryParamsType ? `${methodParamsNoTypes} queryParams` : methodParamsNoTypes;
|
|
1119
1118
|
let methodImpl = "";
|
|
1120
1119
|
const isCacheFetch = ["get"].includes(httpMethod) && resolvedResponseClass !== "unknown";
|
|
1121
|
-
const cachedFetchMethod = classMethod;
|
|
1122
1120
|
const deprecateTag = isCacheFetch ? `/**
|
|
1123
1121
|
* @deprecated Use "${classMethod}()" instead.
|
|
1124
1122
|
*/` : "";
|
|
1125
1123
|
const isGuardInvoked = ["get", "post", "put", "patch", "delete"].includes(httpMethod);
|
|
1126
|
-
const methodName = httpMethod === "get" ? cachedFetchMethod : ["post", "put", "patch", "delete"].includes(httpMethod) ? classMethod : "";
|
|
1127
1124
|
const responseType = resolvedResponseClass !== "unknown" ? `${resolvedResponseClass}` : "unknown";
|
|
1128
|
-
const generateMethodName = () => `${
|
|
1129
|
-
const responseSyncType =
|
|
1125
|
+
const generateMethodName = () => `${classMethod}(${methodParams}): Promise<${responseSyncType}<${responseType}>>`;
|
|
1126
|
+
const responseSyncType = "IResponse";
|
|
1130
1127
|
methodImpl = `${descriptionText}
|
|
1131
1128
|
${generateMethodName()} {
|
|
1132
1129
|
${queryParamsDefault}
|
|
1133
1130
|
const url = ${newPath} ${formPayloadString} ${isFileUpload ? "\n// TODO file upload not implemented" : ""}
|
|
1134
1131
|
const resultPromise = this.axiosInstance.${httpMethod}(url, ${dataPayload})
|
|
1135
1132
|
|
|
1136
|
-
${
|
|
1137
|
-
|
|
1138
|
-
if (!this.cache) {
|
|
1139
|
-
return SdkCache.withoutCache(res)
|
|
1140
|
-
}
|
|
1141
|
-
const cacheKey = url + CodeGenUtil.hashCode(JSON.stringify({ params }))
|
|
1142
|
-
return SdkCache.withCache(cacheKey, res)` : ""}${["post", "put", "patch", "delete"].includes(httpMethod) ? ` return this.isValidationEnabled ? Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}') : Validate.unsafeResponse(() => resultPromise)` : ""}
|
|
1133
|
+
${` return this.isValidationEnabled ? Validate.responseType(() => resultPromise, ${resolvedResponseClassValidated}, '${resolvedResponseClassValidated}') : Validate.unsafeResponse(() => resultPromise)`}
|
|
1143
1134
|
}
|
|
1144
1135
|
`;
|
|
1145
1136
|
if (!isGuardInvoked) {
|
|
@@ -1212,7 +1203,7 @@ const templateApiMethod = ({
|
|
|
1212
1203
|
const methodImpl = `
|
|
1213
1204
|
${descriptionText}
|
|
1214
1205
|
async function ${classMethod}(${methodParams}): Promise<${responseType}> {
|
|
1215
|
-
const $ = new ${classGenName}(Network.create(requestConfig), namespace,
|
|
1206
|
+
const $ = new ${classGenName}(Network.create(requestConfig), namespace, isValidationEnabled)
|
|
1216
1207
|
const resp = await $.${classMethod}(${methodParamsNoTypes})
|
|
1217
1208
|
if (resp.error) throw resp.error
|
|
1218
1209
|
return resp.response.data
|