[api] Add TS generator #1873#1878
Open
michaelvlach wants to merge 29 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a TypeScript transpiler under agdb_ci that converts agdb::type_def type/AST representations into TypeScript declarations (classes, interfaces, enums/unions) and emits TypeScript for function bodies/expressions, enabling TS code generation from the API/type-def metadata.
Changes:
- Added a TypeScript transpiler module with emitters for declarations and expressions plus formatting helpers.
- Implemented Rust
Type→ TS type annotation normalization/rendering (including arrays, tuples, nullables, functions, generics). - Enabled the
agdbcrate’sapifeature foragdb_ciand exposed the new transpiler module.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| agdb_ci/src/language/typescript/transpiler.rs | Public entrypoints/config for transpiling types, modules, and bodies to TS. |
| agdb_ci/src/language/typescript/transpiler/declarations.rs | Emits TS declarations (class/interface/enum/union/functions/statics) from Type. |
| agdb_ci/src/language/typescript/transpiler/expressions.rs | Emits TS expressions/statements from Expression AST. |
| agdb_ci/src/language/typescript/transpiler/format.rs | Adds an IndentWriter used by emitters to format TS output. |
| agdb_ci/src/language/typescript/transpiler/normalize.rs | Normalizes Rust Type into a simplified intermediate form for TS emission. |
| agdb_ci/src/language/typescript/transpiler/types.rs | Renders normalized types and generic parameter lists to TS syntax. |
| agdb_ci/src/language/typescript.rs | Exposes the new transpiler module. |
| agdb_ci/Cargo.toml | Enables agdb’s api feature required for type-def driven generation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+31
to
+34
| NormalizedType::Nullable(inner) => { | ||
| let inner_str = emit_normalized(inner); | ||
| format!("{inner_str} | null") | ||
| } |
Comment on lines
+509
to
+513
| } else if ch == '`' { | ||
| w.write("\\`"); | ||
| } else if ch == '$' { | ||
| w.write("\\$"); | ||
| } else { |
Comment on lines
+19
to
+26
| NormalizedType::Array(inner) => { | ||
| let inner_str = emit_normalized(inner); | ||
| if inner_str.contains('|') { | ||
| format!("({inner_str})[]") | ||
| } else { | ||
| format!("{inner_str}[]") | ||
| } | ||
| } |
Comment on lines
+140
to
+145
| let is_self_param = func.args.first().is_some_and(|a| { | ||
| a.name == "self" | ||
| || a.name == "&self" | ||
| || a.ty | ||
| .is_some_and(|ty_fn| matches!(ty_fn(), Type::SelfType(_) | Type::Reference(_))) | ||
| }); |
Comment on lines
+353
to
+372
| fn emit_fn_name(function: &Expression, w: &mut IndentWriter) { | ||
| match function { | ||
| Expression::Path { | ||
| ident, | ||
| parent: None, | ||
| .. | ||
| } => w.write(ident), | ||
| Expression::Path { | ||
| ident, | ||
| parent: Some(parent), | ||
| .. | ||
| } => { | ||
| emit_expression(parent, w); | ||
| w.write("."); | ||
| w.write(ident); | ||
| } | ||
| Expression::Ident(name) => w.write(name), | ||
| _ => emit_expression(function, w), | ||
| } | ||
| } |
Comment on lines
+483
to
+492
| if ch == '{' { | ||
| if chars.peek() == Some(&'}') { | ||
| chars.next(); | ||
| w.write("${"); | ||
| if let Some(arg) = arg_iter.next() { | ||
| emit_expression(arg, w); | ||
| } | ||
| w.write("}"); | ||
| } else { | ||
| let mut name = String::new(); |
Comment on lines
+90
to
+94
| if field.name.is_empty() { | ||
| w.write_line(&format!("value: {ann};")); | ||
| } else { | ||
| w.write_line(&format!("{}: {ann};", field.name)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.