Skip to content

Commit

Permalink
feat(metagen): typescript client file upload (#934)
Browse files Browse the repository at this point in the history
<!--
Pull requests are squashed and merged using:
- their title as the commit message
- their description as the commit body

Having a good title and description is important for the users to get
readable changelog.
-->

<!-- 1. Explain WHAT the change is about -->

- Closes
[MET-768](https://linear.app/metatypedev/issue/MET-768/add-file-upload-support-for-typescript-metagen-client).

<!-- 3. Explain HOW users should update their code -->

#### Migration notes

---

- [x] The change comes with new or modified tests
- [ ] Hard-to-understand functions have explanatory comments
- [ ] End-user documentation is updated to reflect the change
  • Loading branch information
luckasRanarison authored Dec 6, 2024
1 parent 6f5adbc commit 4037040
Show file tree
Hide file tree
Showing 11 changed files with 1,567 additions and 257 deletions.
1 change: 1 addition & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 6 additions & 14 deletions src/metagen/src/client_py/node_metas.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0

use std::{collections::HashMap, fmt::Write, ops::Not};
use std::{collections::HashMap, fmt::Write};

use common::typegraph::*;

use super::utils::normalize_type_title;
use crate::{
interlude::*,
shared::{files::TypePath, types::*},
shared::{
files::{serialize_typepaths_json, TypePath},
types::*,
},
};

pub struct PyNodeMetasRenderer {
Expand Down Expand Up @@ -187,18 +190,7 @@ impl RenderType for PyNodeMetasRenderer {
let input_files = self
.input_files
.get(&cursor.id)
.map(|files| {
files
.iter()
.map(|path| path.to_vec_str())
.collect::<Vec<_>>()
})
.and_then(|files| {
files
.is_empty()
.not()
.then_some(serde_json::to_string(&files).unwrap())
});
.and_then(|files| serialize_typepaths_json(files));
self.render_for_func(renderer, &ty_name, &return_ty_name, props, input_files)?;
ty_name
}
Expand Down
1 change: 1 addition & 0 deletions src/metagen/src/client_ts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ fn render_node_metas(
Rc::new(node_metas::TsNodeMetasRenderer {
name_mapper,
named_types: named_types.clone(),
input_files: manifest.input_files.clone(),
}),
);
for &id in &manifest.node_metas {
Expand Down
25 changes: 22 additions & 3 deletions src/metagen/src/client_ts/node_metas.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0

use std::fmt::Write;
use std::{collections::HashMap, fmt::Write};

use common::typegraph::*;

use super::utils::normalize_type_title;
use crate::{interlude::*, shared::types::*};
use crate::{
interlude::*,
shared::{
files::{serialize_typepaths_json, TypePath},
types::*,
},
};

pub struct TsNodeMetasRenderer {
pub name_mapper: Rc<super::NameMapper>,
pub named_types: Rc<std::sync::Mutex<IndexSet<u32>>>,
pub input_files: Rc<HashMap<u32, Vec<TypePath>>>,
}

impl TsNodeMetasRenderer {
Expand Down Expand Up @@ -51,6 +58,7 @@ impl TsNodeMetasRenderer {
ty_name: &str,
return_node: &str,
argument_fields: Option<IndexMap<String, Rc<str>>>,
input_files: Option<String>,
) -> std::fmt::Result {
write!(
dest,
Expand Down Expand Up @@ -80,6 +88,13 @@ impl TsNodeMetasRenderer {
}},"#
)?;
}
if let Some(input_files) = input_files {
write!(
dest,
r#"
inputFiles: {input_files},"#
)?;
}
write!(
dest,
r#"
Expand Down Expand Up @@ -167,7 +182,11 @@ impl RenderType for TsNodeMetasRenderer {
};
let node_name = &base.title;
let ty_name = normalize_type_title(node_name).to_pascal_case();
self.render_for_func(renderer, &ty_name, &return_ty_name, props)?;
let input_files = self
.input_files
.get(&cursor.id)
.and_then(|files| serialize_typepaths_json(files));
self.render_for_func(renderer, &ty_name, &return_ty_name, props, input_files)?;
ty_name
}
TypeNode::Object { data, base } => {
Expand Down
Loading

0 comments on commit 4037040

Please sign in to comment.