Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion codegenerator/cli/CommandLineHelp.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Initialize an indexer with one of the initialization options
* `-n`, `--name <NAME>` — The name of your project
* `-l`, `--language <LANGUAGE>` — The language used to write handlers

Possible values: `javascript`, `typescript`, `rescript`
Possible values: `typescript`, `rescript`

* `--api-token <API_TOKEN>` — The hypersync API key to be initialized in your templates .env file

Expand Down
3 changes: 0 additions & 3 deletions codegenerator/cli/src/cli_args/init_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ impl Ecosystem {
)]
///Which language do you want to write in?
pub enum Language {
#[clap(name = "javascript")]
JavaScript,
#[clap(name = "typescript")]
TypeScript,
#[clap(name = "rescript")]
Expand All @@ -349,7 +347,6 @@ impl Language {
match self {
Language::ReScript => "./src/EventHandlers.res.js".to_string(),
Language::TypeScript => "src/EventHandlers.ts".to_string(),
Language::JavaScript => "./src/EventHandlers.js".to_string(),
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions codegenerator/cli/src/config_parsing/graph_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ pub struct BlockHandler {
fn get_event_handler_directory(language: &Language) -> String {
match language {
Language::ReScript => "./src/EventHandlers.res.js".to_string(),
Language::TypeScript => "src/EventHandlers.ts".to_string(),
Language::JavaScript => "./src/EventHandlers.js".to_string(),
Language::TypeScript => "./src/EventHandlers.ts".to_string(),
}
}
Comment on lines 115 to 120

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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify path consistency across functions with the same name.

The local get_event_handler_directory function returns "./src/EventHandlers.ts" for TypeScript (with ./ prefix), but the public method Language::get_event_handler_directory in codegenerator/cli/src/cli_args/init_config.rs returns "src/EventHandlers.ts" (without ./ prefix). Having two functions with the same name returning different paths is confusing and error-prone.

Run the following script to verify usage patterns and confirm which path format is expected:


🏁 Script executed:

#!/bin/bash
# Search for usages of get_event_handler_directory to understand which path format is needed
rg -nP --type=rust -C3 'get_event_handler_directory\(\)'

# Search for references to EventHandlers.ts to see which path format is used
rg -nP --type=rust -C3 'EventHandlers\.ts'

Length of output: 4446


Based on the script output, I can now verify the issue. The local function get_event_handler_directory in codegenerator/cli/src/config_parsing/graph_migration/mod.rs (lines 115-120) returns "./src/EventHandlers.ts" for TypeScript, while the public method Language::get_event_handler_directory in codegenerator/cli/src/cli_args/init_config.rs (lines 346-351) returns "src/EventHandlers.ts" without the ./ prefix.

The production code actually uses the public method (at lines 64 and 287 in init_config.rs), so the TypeScript handler path being used is "src/EventHandlers.ts". However, the local function in graph_migration/mod.rs is only used in its own unit test (line 556-559), which validates the local function's return value.


Unify TypeScript path format across get_event_handler_directory functions.

Two functions with the same name return different paths for TypeScript. The public method Language::get_event_handler_directory() in init_config.rs:349 returns "src/EventHandlers.ts", but the local function in graph_migration/mod.rs:118 returns "./src/EventHandlers.ts". Since production code uses the public method, align the local function or remove it if unused.

🤖 Prompt for AI Agents
In codegenerator/cli/src/config_parsing/graph_migration/mod.rs around lines 115
to 120, the local function get_event_handler_directory returns
"./src/EventHandlers.ts" for Language::TypeScript which conflicts with the
public Language::get_event_handler_directory in
codegenerator/cli/src/cli_args/init_config.rs (lines ~346-351) that returns
"src/EventHandlers.ts"; update the local function to return the same path string
"src/EventHandlers.ts" for TypeScript (remove the "./" prefix) so both
implementations match, or if the local function is only used by its unit test
and nowhere else, remove the local function and update the test to call the
public Language::get_event_handler_directory instead.


Expand Down Expand Up @@ -553,14 +552,11 @@ mod test {
#[test]
fn test_get_event_handler_directory() {
let language_1: Language = Language::ReScript;
let language_2: Language = Language::JavaScript;
let language_3: Language = Language::TypeScript;
let language_2: Language = Language::TypeScript;
let event_handler_directory_1 = super::get_event_handler_directory(&language_1);
let event_handler_directory_2 = super::get_event_handler_directory(&language_2);
let event_handler_directory_3 = super::get_event_handler_directory(&language_3);
assert_eq!(event_handler_directory_1, "./src/EventHandlers.res.js");
assert_eq!(event_handler_directory_2, "./src/EventHandlers.js");
assert_eq!(event_handler_directory_3, "src/EventHandlers.ts");
assert_eq!(event_handler_directory_2, "./src/EventHandlers.ts");
}
// Unit test to check that the correct network contract hashmap is generated
#[tokio::test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl Event {
pub fn get_entity_id_code(is_fuel: bool, language: &Language) -> String {
let int_as_string = |int_var_name| match language {
Language::ReScript => format!("{int_var_name}->Belt.Int.toString"),
Language::TypeScript | Language::JavaScript => int_var_name,
Language::TypeScript => int_var_name,
};
let int_event_prop_as_string =
|event_prop: &str| int_as_string(format!("event.{event_prop}"));
Expand Down Expand Up @@ -283,7 +283,6 @@ impl Event {
let data_code = match language {
Language::ReScript => "%raw(`{}`)",
Language::TypeScript => "{}",
Language::JavaScript => "{}",
};
format!(
"{event_module}.mock({{data: {data_code} /* It mocks event fields with \
Expand Down
3 changes: 0 additions & 3 deletions codegenerator/cli/src/hbs_templating/init_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct InitTemplates {
project_name: String,
is_rescript: bool,
is_typescript: bool,
is_javascript: bool,
envio_version: String,
//Used for the package.json reference to generated in handlers
relative_path_from_root_to_generated: String,
Expand Down Expand Up @@ -48,7 +47,6 @@ impl InitTemplates {
project_name,
is_rescript: lang == &Language::ReScript,
is_typescript: lang == &Language::TypeScript,
is_javascript: lang == &Language::JavaScript,
envio_version,
relative_path_from_root_to_generated,
envio_api_token,
Expand Down Expand Up @@ -78,7 +76,6 @@ mod test {
project_name: "my-project".to_string(),
is_rescript: true,
is_typescript: false,
is_javascript: false,
envio_version: "latest".to_string(),
relative_path_from_root_to_generated: "./generated".to_string(),
envio_api_token: None,
Expand Down
40 changes: 22 additions & 18 deletions codegenerator/cli/src/template_dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,26 +431,27 @@ mod test {
#[test]
fn all_init_templates_exist() {
let template_dirs = TemplateDirs::new();
let template_langs = [Language::TypeScript];

for template in evm::Template::iter() {
for lang in Language::iter() {
for lang in template_langs.iter() {
for template in evm::Template::iter() {
template_dirs
.get_template_lang_dir(&template, &lang)
.expect("static lang");

template_dirs
.get_template_shared_dir(&template)
.expect("static templte shared");
}
template_dirs
.get_template_shared_dir(&template)
.expect("static templte shared");
}
for template in fuel::Template::iter() {
for lang in Language::iter() {
for template in fuel::Template::iter() {
template_dirs
.get_template_lang_dir(&template, &lang)
.expect("static lang");

template_dirs
.get_template_shared_dir(&template)
.expect("static templte shared");
}
template_dirs
.get_template_shared_dir(&template)
.expect("static templte shared");
}

template_dirs
Expand All @@ -464,23 +465,24 @@ mod test {
let temp_dir =
TempDir::new("init_extract_lang_test").expect("Failed creating tempdir init template");

for template in evm::Template::iter() {
for lang in Language::iter() {
let template_langs = [Language::TypeScript];

for lang in template_langs.iter() {
for template in evm::Template::iter() {
template_dirs
.get_and_extract_template(&template, &lang, &(PathBuf::from(temp_dir.path())))
.expect("static lang");
}
}
for template in fuel::Template::iter() {
for lang in Language::iter() {
for template in fuel::Template::iter() {
template_dirs
.get_and_extract_template(&template, &lang, &(PathBuf::from(temp_dir.path())))
.expect("static lang");
}
}

let temp_dir =
TempDir::new("init_extract_blank_lang_test").expect("Failed creating tempdir blank");
for lang in Language::iter() {
for lang in template_langs.iter() {
template_dirs
.get_and_extract_blank_template(&lang, &temp_dir.path().into())
.expect("static blank");
Expand All @@ -494,7 +496,9 @@ mod test {
.get_blank_shared_dir()
.expect("static blank shared dir");

for lang in Language::iter() {
let template_langs = [Language::TypeScript];

for lang in template_langs.iter() {
template_dirs
.get_blank_lang_dir(&lang)
.expect("static blank lang");
Expand Down

This file was deleted.

This file was deleted.

Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading