Skip to content

[api] Add TS generator #1873#1878

Open
michaelvlach wants to merge 29 commits into
mainfrom
1873-api-add-ts-generator
Open

[api] Add TS generator #1873#1878
michaelvlach wants to merge 29 commits into
mainfrom
1873-api-add-ts-generator

Conversation

@michaelvlach

Copy link
Copy Markdown
Collaborator

No description provided.

@michaelvlach
michaelvlach requested review from agnesoft and Copilot May 27, 2026 19:53
@michaelvlach michaelvlach linked an issue May 27, 2026 that may be closed by this pull request
@vercel

vercel Bot commented May 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agdb Ready Ready Preview, Comment Jun 22, 2026 7:52pm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 agdb crate’s api feature for agdb_ci and 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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[api] Add TS generator

2 participants