@accelbyte/codegen 0.0.0-dev-20260320085237 → 0.0.0-dev-20260406042959
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.
- package/README.md +12 -4
- package/dist/accelbyte-codegen.d.mts +22 -0
- package/dist/accelbyte-codegen.d.ts +22 -0
- package/dist/accelbyte-codegen.js +44 -10
- package/dist/accelbyte-codegen.js.map +1 -1
- package/dist/accelbyte-codegen.mjs +41 -10
- package/dist/accelbyte-codegen.mjs.map +1 -1
- package/package.json +3 -2
|
@@ -83,8 +83,8 @@ var CodegenConfig = class _CodegenConfig {
|
|
|
83
83
|
const loaded = await import(pathToFileURL(configPath).href);
|
|
84
84
|
_CodegenConfig.config = loaded.default ?? loaded ?? {};
|
|
85
85
|
}
|
|
86
|
-
static
|
|
87
|
-
return _CodegenConfig.config.
|
|
86
|
+
static shouldProduceIndexFiles() {
|
|
87
|
+
return _CodegenConfig.config.unstable_shouldProduceIndexFiles ?? true;
|
|
88
88
|
}
|
|
89
89
|
static getBasePath() {
|
|
90
90
|
return _CodegenConfig.config.basePath;
|
|
@@ -172,7 +172,8 @@ var getResponseType = ({
|
|
|
172
172
|
defaultType = "unknown"
|
|
173
173
|
}) => {
|
|
174
174
|
const responseClass = responseClasses.length === 1 ? responseClasses?.[0] : "unknown";
|
|
175
|
-
const
|
|
175
|
+
const rawResponseType = responseClass !== "unknown" ? responseClasses?.[0] : defaultType;
|
|
176
|
+
const responseType = rawResponseType === "__dictionary__" ? "Record<string, any>" : rawResponseType;
|
|
176
177
|
return {
|
|
177
178
|
responseType,
|
|
178
179
|
responseTypeInAxiosResponse: `Promise<AxiosResponse<${responseType}>>`,
|
|
@@ -218,13 +219,28 @@ var generateImports = (body, importStatements, makeNewImportVarMap3, getImportab
|
|
|
218
219
|
${importStatements.sort().join("\n")}`;
|
|
219
220
|
};
|
|
220
221
|
var templateClass = (className, body, importStatements) => {
|
|
222
|
+
const attributes = {
|
|
223
|
+
definitions: ["private axiosInstance: AxiosInstance", "private namespace: string", "private useSchemaValidation: boolean"],
|
|
224
|
+
assignments: ["this.axiosInstance = axiosInstance", "this.namespace = namespace", "this.useSchemaValidation = useSchemaValidation"]
|
|
225
|
+
};
|
|
226
|
+
let namespaceConstructor = "namespace";
|
|
227
|
+
if (!body.includes(".replace('{namespace}', this.namespace)")) {
|
|
228
|
+
namespaceConstructor = "_namespace";
|
|
229
|
+
attributes.definitions.splice(1, 1);
|
|
230
|
+
attributes.assignments.splice(1, 1);
|
|
231
|
+
}
|
|
221
232
|
return `/**
|
|
222
233
|
* AUTO GENERATED
|
|
223
234
|
*/
|
|
224
235
|
${generateImports(body, importStatements, makeNewImportVarMap(), getImportableVarMap(), CLASS_TYPE_ONLY_VARS)}
|
|
225
236
|
|
|
226
237
|
export class ${className} {
|
|
227
|
-
|
|
238
|
+
${attributes.definitions.join("\n")}
|
|
239
|
+
|
|
240
|
+
constructor(axiosInstance: AxiosInstance, ${namespaceConstructor}: string, useSchemaValidation = true) {
|
|
241
|
+
${attributes.assignments.join("\n")}
|
|
242
|
+
}
|
|
243
|
+
|
|
228
244
|
${body}
|
|
229
245
|
}
|
|
230
246
|
`;
|
|
@@ -477,13 +493,14 @@ var ParserUtils = class _ParserUtils {
|
|
|
477
493
|
};
|
|
478
494
|
static parseRefImport = (bodyParam) => {
|
|
479
495
|
const $ref = bodyParam?.schema?.$ref || bodyParam?.schema?.items?.$ref;
|
|
480
|
-
if (!$ref) {
|
|
496
|
+
if (!$ref || $ref.endsWith("__dictionary__")) {
|
|
481
497
|
return null;
|
|
482
498
|
}
|
|
483
499
|
const type = _ParserUtils.parseRefType($ref);
|
|
484
500
|
return `import { ${type} } from '../../generated-definitions/${type}.js'`;
|
|
485
501
|
};
|
|
486
502
|
static parseRefType = ($ref) => {
|
|
503
|
+
if ($ref.endsWith("__dictionary__")) return "__dictionary__";
|
|
487
504
|
let ref = $ref.replace(".", "/");
|
|
488
505
|
if (ref[ref.length - 1] === "." || ref[ref.length - 1] === "/") {
|
|
489
506
|
ref = ref.slice(0, -1);
|
|
@@ -681,6 +698,7 @@ var ParserUtils = class _ParserUtils {
|
|
|
681
698
|
return queryFileName;
|
|
682
699
|
}
|
|
683
700
|
static writeXVersion(distDir, xversionJson, apiInfo) {
|
|
701
|
+
fs4.mkdirSync(distDir, { recursive: true });
|
|
684
702
|
if (xversionJson) {
|
|
685
703
|
console.log("x-version:", xversionJson);
|
|
686
704
|
fs4.writeFileSync(`${distDir}/version.json`, JSON.stringify(xversionJson, null, 2));
|
|
@@ -1055,6 +1073,7 @@ var templateMethod = ({
|
|
|
1055
1073
|
let dataType = null;
|
|
1056
1074
|
if (httpMethod !== "get") {
|
|
1057
1075
|
dataType = ParserUtils.parseBodyParamsType(bodyParams);
|
|
1076
|
+
if (dataType === "__dictionary__") dataType = "Record<string, any>";
|
|
1058
1077
|
importStatements = ParserUtils.parseBodyParamsImports(bodyParams);
|
|
1059
1078
|
methodParams += dataType ? `data: ${dataType},` : "";
|
|
1060
1079
|
methodParamsNoTypes += dataType ? `data,` : "";
|
|
@@ -1078,7 +1097,7 @@ var templateMethod = ({
|
|
|
1078
1097
|
}
|
|
1079
1098
|
const isFileUpload = methodParams.indexOf("data: {file") > -1;
|
|
1080
1099
|
const { responseType, responseTypeInResponse } = getResponseType({ responseClasses });
|
|
1081
|
-
const resolvedResponseClassValidated = responseType !== "unknown" ? `${responseType}` : "z.unknown()";
|
|
1100
|
+
const resolvedResponseClassValidated = responseClasses.length === 1 && responseClasses[0] === "__dictionary__" ? "z.record(z.string(), z.any())" : responseType !== "unknown" ? `${responseType}` : "z.unknown()";
|
|
1082
1101
|
methodParams = (queryParamsType ? `${methodParams} ${queryParamsType}` : methodParams).replace(/,\s*$/, "");
|
|
1083
1102
|
methodParamsNoTypes = queryParamsType ? `${methodParamsNoTypes} queryParams` : methodParamsNoTypes;
|
|
1084
1103
|
const isGuardInvoked = ["get", "post", "put", "patch", "delete"].includes(httpMethod);
|
|
@@ -1422,7 +1441,7 @@ var SwaggerReaderHelpers = class _SwaggerReaderHelpers {
|
|
|
1422
1441
|
const responseClass = responseClasses.length > 1 ? null : responseClasses?.[0];
|
|
1423
1442
|
const { className, classGenName } = ParserUtils.generateClassName(tag, isAdminEndpoint);
|
|
1424
1443
|
tagToClassImportsRecord[className] = tagToClassImportsRecord[className] ? tagToClassImportsRecord[className] : {};
|
|
1425
|
-
if (responseClass) {
|
|
1444
|
+
if (responseClass && responseClass !== "__dictionary__") {
|
|
1426
1445
|
tagToClassImportsRecord[className][responseClass] = `import { ${responseClass} } from '../../generated-definitions/${responseClass}.js'`;
|
|
1427
1446
|
}
|
|
1428
1447
|
if (responseClass && responseClass.endsWith("Array")) {
|
|
@@ -1670,7 +1689,14 @@ ${exportedTypeString}
|
|
|
1670
1689
|
};
|
|
1671
1690
|
} else if (type) {
|
|
1672
1691
|
if (type === "object" && definition.additionalProperties) {
|
|
1673
|
-
const
|
|
1692
|
+
const additionalProps = definition.additionalProperties;
|
|
1693
|
+
if (Object.keys(additionalProps).length === 0) {
|
|
1694
|
+
return {
|
|
1695
|
+
schemaString: `${schemaAttribute} z.record(z.any())${schemaRequired}`,
|
|
1696
|
+
typeString: `${typeAttribute} Record<string, any>${typeNullishability}`
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
const zodAttribute = this.parseToZodAttribute("", additionalProps, [""]);
|
|
1674
1700
|
return {
|
|
1675
1701
|
schemaString: `${schemaAttribute} z.record(${zodAttribute.schemaString})${schemaRequired}`,
|
|
1676
1702
|
typeString: `${typeAttribute} Record<string, ${zodAttribute.typeString}>${typeNullishability}`
|
|
@@ -1941,7 +1967,7 @@ var CodeGenerator = class _CodeGenerator {
|
|
|
1941
1967
|
);
|
|
1942
1968
|
}
|
|
1943
1969
|
mainApiList.push(...apiList);
|
|
1944
|
-
if (CodegenConfig.
|
|
1970
|
+
if (CodegenConfig.shouldProduceIndexFiles()) {
|
|
1945
1971
|
indexImportsSet.add(
|
|
1946
1972
|
ParserUtils.getRelativePathToWebSdkSrcFolder(path5.join(_CodeGenerator.srcFolder(), serviceNameTitle), targetSrcFolder)
|
|
1947
1973
|
);
|
|
@@ -1951,6 +1977,7 @@ var CodeGenerator = class _CodeGenerator {
|
|
|
1951
1977
|
const duplicates = /* @__PURE__ */ new Map();
|
|
1952
1978
|
const definitions = api2?.components?.schemas || api2.definitions;
|
|
1953
1979
|
for (const ref in definitions) {
|
|
1980
|
+
if (ref === "__dictionary__") continue;
|
|
1954
1981
|
const definition = definitions[ref];
|
|
1955
1982
|
const fileName = ParserUtils.parseRefType(ref);
|
|
1956
1983
|
const fileExist = fs5.existsSync(path5.join(DIST_DEFINITION_DIR, `${fileName}.ts`));
|
|
@@ -1975,7 +2002,7 @@ var CodeGenerator = class _CodeGenerator {
|
|
|
1975
2002
|
};
|
|
1976
2003
|
generatePublicOrAdmin(true);
|
|
1977
2004
|
generatePublicOrAdmin(false);
|
|
1978
|
-
if (CodegenConfig.
|
|
2005
|
+
if (CodegenConfig.shouldProduceIndexFiles()) {
|
|
1979
2006
|
const isGenerateWebSocket = CliParser.isGenerateWebSocket();
|
|
1980
2007
|
const apiIndexBuff = templateApiIndex(serviceNameTitle, mainApiList, isGenerateWebSocket);
|
|
1981
2008
|
ParserUtils.writeApiMainFile(_CodeGenerator.srcFolder(), serviceNameTitle, apiIndexBuff);
|
|
@@ -2006,6 +2033,7 @@ var SwaggerDownloader = class _SwaggerDownloader {
|
|
|
2006
2033
|
fs6.readFile(filePath, "utf8", (err, data) => {
|
|
2007
2034
|
if (err) throw err;
|
|
2008
2035
|
let result = data;
|
|
2036
|
+
result = result.replace(new RegExp("map%5Bstring%5Dinterface%20%7B%7D", "g"), "__dictionary__").replace(new RegExp("map\\[string\\]interface \\{\\}", "g"), "__dictionary__").replace(new RegExp("map\\[string\\]any", "g"), "__dictionary__");
|
|
2009
2037
|
searchStr.forEach((s) => {
|
|
2010
2038
|
result = result.replace(new RegExp(s, "g"), " ");
|
|
2011
2039
|
});
|
|
@@ -2403,6 +2431,9 @@ var generateSdk = async () => {
|
|
|
2403
2431
|
if (CliParser.isGenerateWebSocket()) {
|
|
2404
2432
|
WebsocketGenerator.main();
|
|
2405
2433
|
}
|
|
2434
|
+
if (!CodegenConfig.shouldProduceIndexFiles()) {
|
|
2435
|
+
return;
|
|
2436
|
+
}
|
|
2406
2437
|
const indexImportsSet = /* @__PURE__ */ new Set();
|
|
2407
2438
|
const queryImportsSet = /* @__PURE__ */ new Set();
|
|
2408
2439
|
const filenamesSet = /* @__PURE__ */ new Set();
|