@accelbyte/codegen 0.0.0-dev-20250530101210 → 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
@@ -2,6 +2,10 @@
2
2
 
3
3
  AccelByte Code Generator is a CLI tool that facilitates creating an AccelByte TypeScript SDK from AccelByte OpenAPI definitions.
4
4
 
5
+ ## Requirements
6
+
7
+ - **Node.js >= 22.18.0** (LTS) — required for native TypeScript type stripping, used to load `abcodegen.config.ts` at runtime.
8
+
5
9
  ## CLI
6
10
  This codegen build a CLI called `accelbyte-codegen` that will be used to generate code from given config.
7
11
 
@@ -33,9 +37,11 @@ Provide swaggers url you wish to generate, store it in .json format file.
33
37
 
34
38
  ## How to Generate
35
39
 
36
- **Step 1: Set Up Your Node.js Environment** Make sure you have Node.js and npm (Node Package Manager) installed on your system. You can download and install them from the official website: https://nodejs.org/en/
40
+ **Step 1: Set Up Your Node.js Environment** Make sure you have **Node.js >= 22.18.0** (LTS) and npm (Node Package Manager) installed on your system. You can download and install them from the official website: https://nodejs.org/en/
41
+
42
+ This minimum version is required because the codegen loads `abcodegen.config.ts` at runtime using Node.js native TypeScript type stripping, which was unflagged in Node.js 22.18.0.
37
43
 
38
- __*It is recommended__ to use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install Node.js so you can switch between Node versions more easily
44
+ __*It is recommended__ to use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install Node.js so you can switch between Node versions more easily
39
45
 
40
46
  **Step 2: Create a New Node.js Project (if needed)** If you are starting a new project, create a new directory and initialize it as a Node.js project. You can do this using the following commands:
41
47
  ```
@@ -110,4 +116,52 @@ after installing, execute prettier as below
110
116
  npm exec prettier --write swaggers/*.json && prettier --write sdk/**/*
111
117
  # Or, with yarn:
112
118
  yarn prettier --write swaggers/*.json && prettier --write sdk/**/*
113
- ```
119
+ ```
120
+
121
+ ## Configuration
122
+
123
+ Place an `abcodegen.config.ts` file next to your `swaggers.json` to customize codegen behavior. All options are optional — if the file is absent, defaults apply.
124
+
125
+ ```typescript
126
+ // abcodegen.config.ts
127
+ import { type CodegenConfigOptions } from '@accelbyte/codegen'
128
+
129
+ export default {
130
+ // Override the base path prepended to all API routes.
131
+ // Default: uses basePath from the swagger spec.
132
+ basePath: '/custom',
133
+
134
+ // Generate barrel index files (index.ts, all-imports.ts, all-query-imports.ts).
135
+ // Default: true
136
+ unstable_shouldProduceIndexFiles: false,
137
+
138
+ // Force specific definitions to emit `z.any()` instead of a full schema.
139
+ // Keyed by definition file name. Value can be `true` or a function receiving the schema.
140
+ unstable_overrideAsAny: {
141
+ ProtobufAny: true,
142
+ SomeOther: (schema) => schema.properties?.['@type'] !== undefined
143
+ }
144
+ } satisfies CodegenConfigOptions
145
+ ```
146
+
147
+ ## Design Decisions
148
+
149
+ ### Zod definitions use `interface`, not `type`
150
+
151
+ Generated definitions use `interface Foo extends z.TypeOf<typeof Foo> {}` rather than a `type` alias. This makes editors display the object shape directly on hover instead of showing the `z.TypeOf<...>` indirection.
152
+
153
+ This triggers `@typescript-eslint/no-empty-object-type`. That rule guards against the `{}` gotcha in hand-written code, which does not apply to generated output. Consumers can disable it for generated files:
154
+
155
+ ```js
156
+ // eslint.config.js
157
+ {
158
+ files: ['src/generated-definitions/**'],
159
+ rules: { '@typescript-eslint/no-empty-object-type': 'off' }
160
+ }
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 };