mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
test event from dart to rust using protobuf as bytes adaptor
This commit is contained in:
@ -4,6 +4,11 @@ pub struct EventTemplate {
|
||||
tera_context: Context,
|
||||
}
|
||||
|
||||
pub const DART_IMPORTED: &'static str = r#"
|
||||
/// Auto gen code from rust ast, do not edit
|
||||
part of 'cqrs.dart';
|
||||
"#;
|
||||
|
||||
pub struct EventRenderContext {
|
||||
pub input_deserializer: String,
|
||||
pub output_deserializer: String,
|
||||
@ -21,5 +26,67 @@ impl EventTemplate {
|
||||
|
||||
pub fn render(&mut self, _render_context: EventRenderContext, _index: usize) -> Option<String> {
|
||||
None
|
||||
// if index == 0 {
|
||||
// self.tera_context
|
||||
// .insert("imported_dart_files", DART_IMPORTED)
|
||||
// }
|
||||
// self.tera_context.insert("index", &index);
|
||||
//
|
||||
//
|
||||
//
|
||||
// self.tera_context.insert(
|
||||
// "command_request_struct_ident",
|
||||
// &render_context.command_request_struct_ident,
|
||||
// );
|
||||
//
|
||||
// self.tera_context
|
||||
// .insert("request_deserializer", &render_context.request_deserializer);
|
||||
//
|
||||
// if render_context.request_deserializer.is_empty() {
|
||||
// self.tera_context.insert("has_request_deserializer", &false);
|
||||
// } else {
|
||||
// self.tera_context.insert("has_request_deserializer", &true);
|
||||
// }
|
||||
// self.tera_context
|
||||
// .insert("command_ident", &render_context.event);
|
||||
//
|
||||
// if render_context.response_deserializer.is_empty() {
|
||||
// self.tera_context
|
||||
// .insert("has_response_deserializer", &false);
|
||||
// self.tera_context
|
||||
// .insert("response_deserializer", "ResponsePacket");
|
||||
// } else {
|
||||
// self.tera_context.insert("has_response_deserializer", &true);
|
||||
// self.tera_context.insert(
|
||||
// "response_deserializer",
|
||||
// &render_context.response_deserializer,
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// self.tera_context
|
||||
// .insert("async_cqrs_type", &render_context.async_cqrs_type);
|
||||
// let repo_absolute_path =
|
||||
// std::fs::canonicalize("./flowy-scripts/rust-tool/src/flutter/cqrs")
|
||||
// .unwrap()
|
||||
// .as_path()
|
||||
// .display()
|
||||
// .to_string();
|
||||
//
|
||||
// let template_path = format!("{}/**/*.tera", repo_absolute_path);
|
||||
// let tera = match Tera::new(&template_path) {
|
||||
// Ok(t) => t,
|
||||
// Err(e) => {
|
||||
// log::error!("Parsing error(s): {}", e);
|
||||
// ::std::process::exit(1);
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// match tera.render("command_request_template.tera", &self.tera_context) {
|
||||
// Ok(r) => Some(r),
|
||||
// Err(e) => {
|
||||
// log::error!("{:?}", e);
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
{%- if index == 0 %}
|
||||
{{ imported_dart_files }}
|
||||
{%- endif -%}
|
||||
|
||||
class {{ command_request_struct_ident }} {
|
||||
{%- if has_request_deserializer %}
|
||||
{{ request_deserializer }} body;
|
||||
{%- else %}
|
||||
Uint8List? body;
|
||||
{%- endif %}
|
||||
|
||||
{%- if has_request_deserializer %}
|
||||
{{ command_request_struct_ident }}(this.body);
|
||||
{%- else %}
|
||||
{{ command_request_struct_ident }}();
|
||||
{%- endif %}
|
||||
Future<Either<{{ response_deserializer }}, FlowyError>> send() {
|
||||
final command = Command.{{ command_ident }};
|
||||
var request = RequestPacket.create()
|
||||
..command = command
|
||||
..id = uuid();
|
||||
|
||||
{%- if has_request_deserializer %}
|
||||
return protobufToBytes(body).fold(
|
||||
(req_bytes) {
|
||||
request.body = req_bytes;
|
||||
return {{ async_cqrs_type }}(request).then((response) {
|
||||
{%- if has_response_deserializer %}
|
||||
try {
|
||||
if (response.hasErr()) {
|
||||
return right(FlowyError.from(response));
|
||||
} else {
|
||||
final pb = {{ response_deserializer }}.fromBuffer(response.body);
|
||||
return left(pb);
|
||||
}
|
||||
|
||||
} catch (e, s) {
|
||||
final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
|
||||
return right(error);
|
||||
}
|
||||
{%- else %}
|
||||
return left(response);
|
||||
{%- endif %}
|
||||
});
|
||||
},
|
||||
(err) => Future(() {
|
||||
final error = FlowyError.fromError(err, StatusCode.ProtobufSerializeError);
|
||||
return right(error);
|
||||
}),
|
||||
);
|
||||
{%- else %}
|
||||
return {{ async_cqrs_type }}(request).then((response) {
|
||||
{%- if has_response_deserializer %}
|
||||
try {
|
||||
if (response.hasErr()) {
|
||||
return right(FlowyError.from(response));
|
||||
} else {
|
||||
final pb = {{ response_deserializer }}.fromBuffer(response.body);
|
||||
return left(pb);
|
||||
}
|
||||
} catch (e, s) {
|
||||
final error = FlowyError.fromError('error: ${e.runtimeType}. Stack trace: $s', StatusCode.ProtobufDeserializeError);
|
||||
return right(error);
|
||||
}
|
||||
{%- else %}
|
||||
return left(response);
|
||||
{%- endif %}
|
||||
|
||||
});
|
||||
{%- endif %}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ pub fn parse_crate_config_from(entry: &walkdir::DirEntry) -> Option<CrateConfig>
|
||||
let folder_name = path.file_stem().unwrap().to_str().unwrap().to_string();
|
||||
let config_path = format!("{}/Flowy.toml", crate_path);
|
||||
|
||||
if std::path::Path::new(&config_path).exists() {
|
||||
if !std::path::Path::new(&config_path).exists() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user