@accelbyte/codegen 0.0.0-dev-20260320085237 → 0.0.0-dev-20260326093546

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 CHANGED
@@ -124,14 +124,16 @@ Place an `abcodegen.config.ts` file next to your `swaggers.json` to customize co
124
124
 
125
125
  ```typescript
126
126
  // abcodegen.config.ts
127
+ import { type CodegenConfigOptions } from '@accelbyte/codegen'
128
+
127
129
  export default {
128
130
  // Override the base path prepended to all API routes.
129
131
  // Default: uses basePath from the swagger spec.
130
132
  basePath: '/custom',
131
133
 
132
- // Skip generation of barrel index files (index.ts, all-query-imports.ts).
134
+ // Generate barrel index files (index.ts, all-imports.ts, all-query-imports.ts).
133
135
  // Default: true
134
- unstable_shouldProduceIndexFile: false,
136
+ unstable_shouldProduceIndexFiles: false,
135
137
 
136
138
  // Force specific definitions to emit `z.any()` instead of a full schema.
137
139
  // Keyed by definition file name. Value can be `true` or a function receiving the schema.
@@ -139,7 +141,7 @@ export default {
139
141
  ProtobufAny: true,
140
142
  SomeOther: (schema) => schema.properties?.['@type'] !== undefined
141
143
  }
142
- }
144
+ } satisfies CodegenConfigOptions
143
145
  ```
144
146
 
145
147
  ## Design Decisions
@@ -156,4 +158,10 @@ This triggers `@typescript-eslint/no-empty-object-type`. That rule guards agains
156
158
  files: ['src/generated-definitions/**'],
157
159
  rules: { '@typescript-eslint/no-empty-object-type': 'off' }
158
160
  }
159
- ```
161
+ ```
162
+
163
+ ## Troubleshooting
164
+
165
+ ### Type or lint errors in generated files
166
+
167
+ The generated code aims to use neutral, unopinionated style defaults. However, some generated syntax may conflict with your tsconfig or linter settings. In that case, you can ignore specific lint rules in the codegen folder, or create a `tsconfig.json` inside it to override your top-level configuration.
@@ -0,0 +1,22 @@
1
+ interface CodegenConfigOptions {
2
+ /**
3
+ * Force specific definitions to emit `z.any()` instead of a full schema.
4
+ * Keyed by definition file name. Value can be `true` or a function receiving the schema.
5
+ *
6
+ * @example
7
+ * { ProtobufAny: true, SomeOther: (schema) => schema.properties?.['@type'] !== undefined }
8
+ */
9
+ unstable_overrideAsAny?: Record<string, boolean | ((schema: Record<string, any>) => boolean)>;
10
+ /**
11
+ * Generate barrel index files (index.ts, all-imports.ts, all-query-imports.ts).
12
+ * @default true
13
+ */
14
+ unstable_shouldProduceIndexFiles?: boolean;
15
+ /**
16
+ * Override the base path prepended to all API routes.
17
+ * @default `basePath` from the swagger spec
18
+ */
19
+ basePath?: string;
20
+ }
21
+
22
+ export type { CodegenConfigOptions };
@@ -0,0 +1,22 @@
1
+ interface CodegenConfigOptions {
2
+ /**
3
+ * Force specific definitions to emit `z.any()` instead of a full schema.
4
+ * Keyed by definition file name. Value can be `true` or a function receiving the schema.
5
+ *
6
+ * @example
7
+ * { ProtobufAny: true, SomeOther: (schema) => schema.properties?.['@type'] !== undefined }
8
+ */
9
+ unstable_overrideAsAny?: Record<string, boolean | ((schema: Record<string, any>) => boolean)>;
10
+ /**
11
+ * Generate barrel index files (index.ts, all-imports.ts, all-query-imports.ts).
12
+ * @default true
13
+ */
14
+ unstable_shouldProduceIndexFiles?: boolean;
15
+ /**
16
+ * Override the base path prepended to all API routes.
17
+ * @default `basePath` from the swagger spec
18
+ */
19
+ basePath?: string;
20
+ }
21
+
22
+ export type { CodegenConfigOptions };
@@ -21,8 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
22
  mod
23
23
  ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
25
 
25
26
  // src/cli.ts
27
+ var cli_exports = {};
28
+ module.exports = __toCommonJS(cli_exports);
26
29
  var import_path6 = __toESM(require("path"));
27
30
  var import_yargs = __toESM(require("yargs"));
28
31
 
@@ -105,8 +108,8 @@ var CodegenConfig = class _CodegenConfig {
105
108
  const loaded = await import((0, import_url.pathToFileURL)(configPath).href);
106
109
  _CodegenConfig.config = loaded.default ?? loaded ?? {};
107
110
  }
108
- static shouldProduceIndexFile() {
109
- return _CodegenConfig.config.unstable_shouldProduceIndexFile ?? true;
111
+ static shouldProduceIndexFiles() {
112
+ return _CodegenConfig.config.unstable_shouldProduceIndexFiles ?? true;
110
113
  }
111
114
  static getBasePath() {
112
115
  return _CodegenConfig.config.basePath;
@@ -240,13 +243,28 @@ var generateImports = (body, importStatements, makeNewImportVarMap3, getImportab
240
243
  ${importStatements.sort().join("\n")}`;
241
244
  };
242
245
  var templateClass = (className, body, importStatements) => {
246
+ const attributes = {
247
+ definitions: ["private axiosInstance: AxiosInstance", "private namespace: string", "private useSchemaValidation: boolean"],
248
+ assignments: ["this.axiosInstance = axiosInstance", "this.namespace = namespace", "this.useSchemaValidation = useSchemaValidation"]
249
+ };
250
+ let namespaceConstructor = "namespace";
251
+ if (!body.includes(".replace('{namespace}', this.namespace)")) {
252
+ namespaceConstructor = "_namespace";
253
+ attributes.definitions.splice(1, 1);
254
+ attributes.assignments.splice(1, 1);
255
+ }
243
256
  return `/**
244
257
  * AUTO GENERATED
245
258
  */
246
259
  ${generateImports(body, importStatements, makeNewImportVarMap(), getImportableVarMap(), CLASS_TYPE_ONLY_VARS)}
247
260
 
248
261
  export class ${className} {
249
- constructor(private axiosInstance: AxiosInstance, private namespace: string, private useSchemaValidation = true) {}
262
+ ${attributes.definitions.join("\n")}
263
+
264
+ constructor(axiosInstance: AxiosInstance, ${namespaceConstructor}: string, useSchemaValidation = true) {
265
+ ${attributes.assignments.join("\n")}
266
+ }
267
+
250
268
  ${body}
251
269
  }
252
270
  `;
@@ -703,6 +721,7 @@ var ParserUtils = class _ParserUtils {
703
721
  return queryFileName;
704
722
  }
705
723
  static writeXVersion(distDir, xversionJson, apiInfo) {
724
+ import_fs4.default.mkdirSync(distDir, { recursive: true });
706
725
  if (xversionJson) {
707
726
  console.log("x-version:", xversionJson);
708
727
  import_fs4.default.writeFileSync(`${distDir}/version.json`, JSON.stringify(xversionJson, null, 2));
@@ -1963,7 +1982,7 @@ var CodeGenerator = class _CodeGenerator {
1963
1982
  );
1964
1983
  }
1965
1984
  mainApiList.push(...apiList);
1966
- if (CodegenConfig.shouldProduceIndexFile()) {
1985
+ if (CodegenConfig.shouldProduceIndexFiles()) {
1967
1986
  indexImportsSet.add(
1968
1987
  ParserUtils.getRelativePathToWebSdkSrcFolder(import_path4.default.join(_CodeGenerator.srcFolder(), serviceNameTitle), targetSrcFolder)
1969
1988
  );
@@ -1997,7 +2016,7 @@ var CodeGenerator = class _CodeGenerator {
1997
2016
  };
1998
2017
  generatePublicOrAdmin(true);
1999
2018
  generatePublicOrAdmin(false);
2000
- if (CodegenConfig.shouldProduceIndexFile()) {
2019
+ if (CodegenConfig.shouldProduceIndexFiles()) {
2001
2020
  const isGenerateWebSocket = CliParser.isGenerateWebSocket();
2002
2021
  const apiIndexBuff = templateApiIndex(serviceNameTitle, mainApiList, isGenerateWebSocket);
2003
2022
  ParserUtils.writeApiMainFile(_CodeGenerator.srcFolder(), serviceNameTitle, apiIndexBuff);
@@ -2425,6 +2444,9 @@ var generateSdk = async () => {
2425
2444
  if (CliParser.isGenerateWebSocket()) {
2426
2445
  WebsocketGenerator.main();
2427
2446
  }
2447
+ if (!CodegenConfig.shouldProduceIndexFiles()) {
2448
+ return;
2449
+ }
2428
2450
  const indexImportsSet = /* @__PURE__ */ new Set();
2429
2451
  const queryImportsSet = /* @__PURE__ */ new Set();
2430
2452
  const filenamesSet = /* @__PURE__ */ new Set();