Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4cecf83
feat(compiler): Add JavaScript/TypeScript IDL code generation for gRPC
miantalha45 Feb 23, 2026
42c840c
Fix linting issues
miantalha45 Feb 23, 2026
1cf6e76
chore: remove incorrect JavaScript codegen files
miantalha45 Feb 23, 2026
7d92cb2
feat(compiler): add TypeScript/JavaScript code generation
miantalha45 Feb 23, 2026
6dc214d
Pushing remaining changes
miantalha45 Feb 24, 2026
918f762
Fix linting issues
miantalha45 Feb 24, 2026
4fe3d0b
docs: improve TypeScript generator docstring
miantalha45 Feb 25, 2026
92cd483
fix(compiler): address Copilot code review comments on TypeScript gen…
miantalha45 Feb 25, 2026
361b2b6
Fix code generation for JS/TS
miantalha45 Feb 26, 2026
362eb44
Merge branch 'main' into generate-messageTypes-from-IDL
miantalha45 Feb 26, 2026
b33168b
Fix failing checks
miantalha45 Feb 26, 2026
8833cb1
Fix linting issues
miantalha45 Feb 26, 2026
3488282
Fix linting issue
miantalha45 Feb 26, 2026
469b122
chore(typescript): remove package-lock.json from tracking and add .gi…
miantalha45 Feb 28, 2026
a7f9b4e
Merge branch 'main' into generate-messageTypes-from-IDL
miantalha45 Feb 28, 2026
7fc0e87
ci(javascript): add TypeScript IDL tests to javascript_xlang CI job
miantalha45 Feb 28, 2026
61539b6
chore: apply formatter fixes (prettier, ruff)
miantalha45 Feb 28, 2026
eaf01c8
fix(typescript): align run_typescript_tests.sh with other language ID…
miantalha45 Feb 28, 2026
749889b
chore: trigger CI recheck
miantalha45 Feb 28, 2026
3abc1de
Addressing all comments from reviewer
miantalha45 Mar 1, 2026
75c679b
Fix failing checks
miantalha45 Mar 1, 2026
6d9a656
chore: trigger PR reprocessing
miantalha45 Mar 1, 2026
b2bfd69
fix(docs): fix mismatched code fence in generated-code.md
miantalha45 Mar 1, 2026
a4570bd
chore: trigger PR reprocessing
miantalha45 Mar 1, 2026
0368926
Rename TS to JS
miantalha45 Mar 1, 2026
7d4ba20
style: wrap long line in test_javascript_codegen.py
miantalha45 Mar 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ jobs:
run: |
cd javascript
npm install
npm run build
- name: Run JavaScript Xlang Test
env:
FORY_JAVASCRIPT_JAVA_CI: "1"
Expand All @@ -486,6 +487,8 @@ jobs:
mvn -T16 --no-transfer-progress clean install -DskipTests -Dmaven.javadoc.skip=true -Dmaven.source.skip=true
cd fory-core
mvn --no-transfer-progress test -Dtest=org.apache.fory.xlang.JavaScriptXlangTest -DforkCount=0
- name: Run JavaScript IDL Tests
run: ./integration_tests/idl_tests/run_javascript_tests.sh

rust:
name: Rust CI
Expand Down
58 changes: 39 additions & 19 deletions compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The FDL compiler generates cross-language serialization code from schema definit

## Features

- **Multi-language code generation**: Java, Python, Go, Rust, C++, C#
- **Multi-language code generation**: Java, Python, Go, Rust, C++, C#, Javascript, and Swift
- **Rich type system**: Primitives, enums, messages, lists, maps
- **Cross-language serialization**: Generated code works seamlessly with Apache Fory
- **Type ID and namespace support**: Both numeric IDs and name-based type registration
Expand Down Expand Up @@ -64,16 +64,16 @@ message Cat [id=103] {
foryc schema.fdl --output ./generated

# Generate for specific languages
foryc schema.fdl --lang java,python,csharp --output ./generated
foryc schema.fdl --lang java,python,csharp,javascript --output ./generated

# Override package name
foryc schema.fdl --package myapp.models --output ./generated

# Language-specific output directories (protoc-style)
foryc schema.fdl --java_out=./src/main/java --python_out=./python/src --csharp_out=./csharp/src/Generated
foryc schema.fdl --java_out=./src/main/java --python_out=./python/src --csharp_out=./csharp/src/Generated --javascript_out=./javascript

# Combine with other options
foryc schema.fdl --java_out=./gen --go_out=./gen/go --csharp_out=./gen/csharp -I ./proto
foryc schema.fdl --java_out=./gen --go_out=./gen/go --csharp_out=./gen/csharp --javascript_out=./gen/js -I ./proto
```

### 3. Use Generated Code
Expand Down Expand Up @@ -185,19 +185,19 @@ message Config { ... } // Registered as "package.Config"

### Primitive Types

| FDL Type | Java | Python | Go | Rust | C++ | C# |
| ----------- | ----------- | ------------------- | ----------- | ----------------------- | ---------------------- | ---------------- |
| `bool` | `boolean` | `bool` | `bool` | `bool` | `bool` | `bool` |
| `int8` | `byte` | `pyfory.int8` | `int8` | `i8` | `int8_t` | `sbyte` |
| `int16` | `short` | `pyfory.int16` | `int16` | `i16` | `int16_t` | `short` |
| `int32` | `int` | `pyfory.int32` | `int32` | `i32` | `int32_t` | `int` |
| `int64` | `long` | `pyfory.int64` | `int64` | `i64` | `int64_t` | `long` |
| `float32` | `float` | `pyfory.float32` | `float32` | `f32` | `float` | `float` |
| `float64` | `double` | `pyfory.float64` | `float64` | `f64` | `double` | `double` |
| `string` | `String` | `str` | `string` | `String` | `std::string` | `string` |
| `bytes` | `byte[]` | `bytes` | `[]byte` | `Vec<u8>` | `std::vector<uint8_t>` | `byte[]` |
| `date` | `LocalDate` | `datetime.date` | `time.Time` | `chrono::NaiveDate` | `fory::Date` | `DateOnly` |
| `timestamp` | `Instant` | `datetime.datetime` | `time.Time` | `chrono::NaiveDateTime` | `fory::Timestamp` | `DateTimeOffset` |
| FDL Type | Java | Python | Go | Rust | C++ | C# | JavaScript |
| ----------- | ----------- | ------------------- | ----------- | ----------------------- | ---------------------- | ---------------- | ------------------ |
| `bool` | `boolean` | `bool` | `bool` | `bool` | `bool` | `bool` | `boolean` |
| `int8` | `byte` | `pyfory.int8` | `int8` | `i8` | `int8_t` | `sbyte` | `number` |
| `int16` | `short` | `pyfory.int16` | `int16` | `i16` | `int16_t` | `short` | `number` |
| `int32` | `int` | `pyfory.int32` | `int32` | `i32` | `int32_t` | `int` | `number` |
| `int64` | `long` | `pyfory.int64` | `int64` | `i64` | `int64_t` | `long` | `bigint \| number` |
| `float32` | `float` | `pyfory.float32` | `float32` | `f32` | `float` | `float` | `number` |
| `float64` | `double` | `pyfory.float64` | `float64` | `f64` | `double` | `double` | `number` |
| `string` | `String` | `str` | `string` | `String` | `std::string` | `string` | `string` |
| `bytes` | `byte[]` | `bytes` | `[]byte` | `Vec<u8>` | `std::vector<uint8_t>` | `byte[]` | `Uint8Array` |
| `date` | `LocalDate` | `datetime.date` | `time.Time` | `chrono::NaiveDate` | `fory::Date` | `DateOnly` | `Date` |
| `timestamp` | `Instant` | `datetime.datetime` | `time.Time` | `chrono::NaiveDateTime` | `fory::Timestamp` | `DateTimeOffset` | `Date` |

### Collection Types

Expand Down Expand Up @@ -285,7 +285,8 @@ fory_compiler/
├── go.py # Go struct generator
├── rust.py # Rust struct generator
├── cpp.py # C++ struct generator
└── csharp.py # C# class generator
├── csharp.py # C# class generator
└── javascript.py # JavaScript interface generator
```

### FDL Frontend
Expand Down Expand Up @@ -422,6 +423,25 @@ cd integration_tests/idl_tests
./run_csharp_tests.sh
```

### JavaScript

Generates interfaces with:

- `export interface` declarations for messages
- `export enum` declarations for enums
- Discriminated unions with case enums
- Registration helper function

```javascript
export interface Cat {
friend?: Dog | undefined;
name?: string | undefined;
tags: string[];
scores: Record<string, number>;
lives: number;
}
```

## CLI Reference

```
Expand All @@ -431,7 +451,7 @@ Arguments:
FILES FDL files to compile

Options:
--lang TEXT Target languages (java,python,cpp,rust,go,csharp or "all")
--lang TEXT Target languages (java,python,cpp,rust,go,csharp,javascript or "all")
Default: all
--output, -o PATH Output directory
Default: ./generated
Expand Down
11 changes: 10 additions & 1 deletion compiler/fory_compiler/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def parse_args(args: Optional[List[str]] = None) -> argparse.Namespace:
"--lang",
type=str,
default="all",
help="Comma-separated list of target languages (java,python,cpp,rust,go,csharp,swift). Default: all",
help="Comma-separated list of target languages (java,python,cpp,rust,go,csharp,javascript,swift). Default: all",
)

parser.add_argument(
Expand Down Expand Up @@ -343,6 +343,14 @@ def parse_args(args: Optional[List[str]] = None) -> argparse.Namespace:
help="Generate C# code in DST_DIR",
)

parser.add_argument(
"--javascript_out",
type=Path,
default=None,
metavar="DST_DIR",
help="Generate JavaScript code in DST_DIR",
)

parser.add_argument(
"--swift_out",
type=Path,
Expand Down Expand Up @@ -650,6 +658,7 @@ def cmd_compile(args: argparse.Namespace) -> int:
"go": args.go_out,
"rust": args.rust_out,
"csharp": args.csharp_out,
"javascript": args.javascript_out,
"swift": args.swift_out,
}

Expand Down
3 changes: 3 additions & 0 deletions compiler/fory_compiler/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from fory_compiler.generators.rust import RustGenerator
from fory_compiler.generators.go import GoGenerator
from fory_compiler.generators.csharp import CSharpGenerator
from fory_compiler.generators.javascript import JavaScriptGenerator
from fory_compiler.generators.swift import SwiftGenerator

GENERATORS = {
Expand All @@ -33,6 +34,7 @@
"rust": RustGenerator,
"go": GoGenerator,
"csharp": CSharpGenerator,
"javascript": JavaScriptGenerator,
"swift": SwiftGenerator,
}

Expand All @@ -44,6 +46,7 @@
"RustGenerator",
"GoGenerator",
"CSharpGenerator",
"JavaScriptGenerator",
"SwiftGenerator",
"GENERATORS",
]
Loading
Loading