Skip to content
Closed
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
1 change: 1 addition & 0 deletions changelog/fixed/rebuilt-raccoon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A TypeScript System Nexus operation that returns a resource builds the resource from the answer, where it cast the answer to the resource type.
12 changes: 12 additions & 0 deletions src/generator/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6328,6 +6328,18 @@ fn render_operation_function(
output.push_str(" return ");
output.push_str(transform_expr);
output.push_str(";\n");
} else if let Some(resource_return) = &operation.output_resource_return {
// The answer is the resource's wire message, so the resource is built from it.
let args = resource_return
.bindings
.iter()
.map(resource_return_binding_expr_typescript)
.collect::<Vec<_>>();
output.push_str(" return new ");
output.push_str(&resource_return.resource_type_name);
output.push('(');
output.push_str(&args.join(", "));
output.push_str(");\n");
} else {
output.push_str(" return result as ");
output.push_str(&operation.output_annotation);
Expand Down
35 changes: 35 additions & 0 deletions tests/generate_typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1800,3 +1800,38 @@ properties:
assert!(!models.contains("from 'long'"), "{models}");
fs::remove_dir_all(temp_dir).unwrap();
}

#[test]
fn typescript_system_nexus_operation_builds_the_returned_resource() {
let root = project_root();
let temp_dir = unique_output_path("typescript-system-nexus-resource");
let output_path = temp_dir.join("output");
generate_to_file(&GenerateRequest {
config: nexgen::nexgen_config::NexgenConfig {
mode: nexgen::generator::GenerationMode::NativeApi,
system_nexus: true,
..Default::default()
},
language: nexgen::language::Language::TypeScript,
input_paths: example_input_paths(&root, "start-workflow"),
support_package: Some("./support".to_string()),
descriptor_paths: vec![descriptor_path(&root)],
output_path: output_path.clone(),
format: false,
java_package_name: None,
ts_date_time_types: Default::default(),
})
.unwrap();
let start = fs::read_to_string(output_path.join("operations/start-workflow.ts")).unwrap();
assert!(
start.contains(
" return new StartedWorkflow(requiredField(request.namespace, \"resource\", \"namespace\"), request.workflowId, result.runId ?? undefined);\n"
),
"{start}"
);
assert!(
!start.contains("return result as StartedWorkflow"),
"{start}"
);
fs::remove_dir_all(temp_dir).unwrap();
}
Loading