@accelbyte/codegen 2.0.0-beta.3 → 2.0.0-beta.5

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.
@@ -78,6 +78,9 @@ class CliParser {
78
78
  static getSnippetOutputPath = () => {
79
79
  return CliParser.instance().argv.snippetOutput;
80
80
  };
81
+ static skipVersionSync = () => {
82
+ return CliParser.instance().argv.skipVersionSync;
83
+ };
81
84
  }
82
85
 
83
86
  const getImportableVarMap$1 = () => ({
@@ -178,7 +181,8 @@ class VersionHelpers {
178
181
  throw new Error(`Invalid sdk version: ${sdkVersion}`);
179
182
  }
180
183
  const { major: currentMajor, minor: currentMinor, patch: currentPatch, prerelease: currentPrerelease } = sdkSemvers;
181
- const nextMajor = codegenSemvers.minor + predefinedMajorVersion;
184
+ const nextMajor = codegenSemvers.major + predefinedMajorVersion;
185
+ const shouldResetVersion = nextMajor !== currentMajor;
182
186
  let nextMinor = currentMinor;
183
187
  let nextPatch = currentPatch;
184
188
  switch (versionBumpType) {
@@ -194,6 +198,10 @@ class VersionHelpers {
194
198
  break;
195
199
  }
196
200
  }
201
+ if (shouldResetVersion) {
202
+ nextMinor = 0;
203
+ nextPatch = 0;
204
+ }
197
205
  let nextVersion = [
198
206
  codegenSemvers.major + predefinedMajorVersion,
199
207
  nextMinor,
@@ -203,7 +211,7 @@ class VersionHelpers {
203
211
  if (nextMinor !== currentMinor || nextMajor !== currentMajor) {
204
212
  nextVersion += `-${nextPrereleaseId}.0`;
205
213
  } else {
206
- nextVersion += `-${sdkSemvers.prerelease.join(".")}`;
214
+ nextVersion += `-${currentPrerelease.join(".")}`;
207
215
  nextVersion = semver.inc(nextVersion, "prerelease", void 0, nextPrereleaseId);
208
216
  }
209
217
  }
@@ -516,16 +524,15 @@ class ParserUtils {
516
524
  ParserUtils.mkdirIfNotExist(distDir);
517
525
  fs.writeFileSync(path.join(distDir, `all-${isAdminWebSdk ? "admin" : "public"}-imports.ts`), ParserUtils.prependCopyrightHeader(buffer));
518
526
  }
519
- static syncPackageVersion(apiInfo, isAdminWebSdk, prereleaseId) {
520
- if (isAdminWebSdk) {
527
+ static syncPackageVersion(apiInfo, skipVersionSync, prereleaseId) {
528
+ if (skipVersionSync)
521
529
  return;
522
- }
523
530
  const currDir = process.cwd();
524
531
  const { packageJSON, pathToPackageJSON } = ParserUtils.getPackageJSONInfo(currDir);
525
532
  const nextSemver = VersionHelpers.getNextVersion({
526
533
  codegenVersion: codegenPackageJSON.version,
527
534
  serviceVersion: apiInfo["x-version"] || apiInfo.version || UNDEFINED_SWAGGER_SEMVER,
528
- predefinedMajorVersion: packageJSON.predefinedMajorVersion,
535
+ predefinedMajorVersion: packageJSON.predefinedMajorVersion || 0,
529
536
  versionBumpType: process.env.VERSION_BUMP_TYPE,
530
537
  sdkVersion: packageJSON.version,
531
538
  nextPrereleaseId: prereleaseId
@@ -610,7 +617,9 @@ class ParserUtils {
610
617
  ${content}`;
611
618
  };
612
619
  static sortPathParamsByPath = (pathParams, path2) => {
613
- return pathParams.sort((a, b) => path2.indexOf(a.name) - path2.indexOf(b.name));
620
+ const params = path2.match(/{\w*}/g) || [];
621
+ const cleanParams = params.map((param) => param.replace("{", "").replace("}", ""));
622
+ return pathParams.sort((a, b) => cleanParams.indexOf(a.name) - cleanParams.indexOf(b.name));
614
623
  };
615
624
  }
616
625
  const mappedMethod = (httpMethod, isForm) => {
@@ -1297,6 +1306,7 @@ class CodeGenerator {
1297
1306
  continue;
1298
1307
  }
1299
1308
  const [tag] = endpoint.tags;
1309
+ const pathWithBase = `${api.basePath ?? ""}${path2}`;
1300
1310
  mapClassMethods[tag] = mapClassMethods[tag] ? mapClassMethods[tag] : {};
1301
1311
  const isForm = endpoint.consumes && endpoint.consumes[0] === "application/x-www-form-urlencoded";
1302
1312
  const classMethod = ParserUtils.generateNaturalLangMethod({
@@ -1307,7 +1317,7 @@ class CodeGenerator {
1307
1317
  existingMethods: mapClassMethods[tag]
1308
1318
  });
1309
1319
  mapClassMethods[tag][classMethod] = `${path2} ${httpMethod}`;
1310
- snippetMap[path2] = snippetMap[path2] ? snippetMap[path2] : {};
1320
+ snippetMap[pathWithBase] = snippetMap[pathWithBase] ? snippetMap[pathWithBase] : {};
1311
1321
  let description = endpoint.description;
1312
1322
  description = description || "";
1313
1323
  description = description.replace(/\s+/g, " ");
@@ -1322,7 +1332,6 @@ class CodeGenerator {
1322
1332
  arrayDefinitions.push(responseClass);
1323
1333
  }
1324
1334
  const queryParams = ParserUtils.filterQueryParameters(endpoint.parameters);
1325
- const pathWithBase = `${api.basePath ?? ""}${path2}`;
1326
1335
  const isFormUrlEncoded = ParserUtils.isFormUrlEncoded(httpMethod, endpoint.consumes);
1327
1336
  const pathParams = ParserUtils.filterPathParams(endpoint.parameters);
1328
1337
  let bodyParams = ParserUtils.filterBodyParams(endpoint.parameters);
@@ -1365,7 +1374,7 @@ class CodeGenerator {
1365
1374
  const serviceNameTitle = ParserUtils.convertDashesToTitleCase(serviceName);
1366
1375
  const { apiGenName } = ParserUtils.generateApiName(tag);
1367
1376
  const resultSnippet = templateSdkSnippet(serviceNameTitle, apiGenName, snippetMethod);
1368
- snippetMap[path2][httpMethod] = {
1377
+ snippetMap[pathWithBase][httpMethod] = {
1369
1378
  web: resultSnippet,
1370
1379
  webGit: GIT_URL + `/sdk-${serviceName}/src/generated-public/${serviceName}/${apiGenName}.ts`,
1371
1380
  shell: snippetShell
@@ -1399,7 +1408,7 @@ class CodeGenerator {
1399
1408
  ParserUtils.mkdirIfNotExist(DIST_DIR);
1400
1409
  ParserUtils.mkdirIfNotExist(DIST_DEFINITION_DIR);
1401
1410
  ParserUtils.mkdirIfNotExist(DIST_ENDPOINTS_DIR);
1402
- ParserUtils.syncPackageVersion(apiInfo, CliParser.isAdmin(), process.env.PRERELEASE_ID);
1411
+ ParserUtils.syncPackageVersion(apiInfo, CliParser.skipVersionSync(), process.env.PRERELEASE_ID);
1403
1412
  const { apiArgumentsByTag, apiBufferByTag, classBufferByTag, dependenciesByTag, classImports, arrayDefinitions, snippetMap } = await CodeGenerator.iterateApi(api, serviceName);
1404
1413
  if (CliParser.getSnippetOutputPath()) {
1405
1414
  try {