Skip to content

Commit

Permalink
Update a way to generate *.ts files based on protobuf scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Sep 26, 2024
1 parent 1c7f47a commit 19cab48
Show file tree
Hide file tree
Showing 131 changed files with 1,935 additions and 1,237 deletions.
120 changes: 97 additions & 23 deletions application/apps/protocol/binding/proto/Cargo.lock

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

4 changes: 2 additions & 2 deletions application/apps/protocol/binding/proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
prost = "0.13"
prost-types = "0.13"
serde = { version = "1.0", features = ["derive"] }
ts-rs = "9.0.1"
tslink = "0.2"

[build-dependencies]
prost-build = "0.13"
prost-build = "0.13"
23 changes: 17 additions & 6 deletions application/apps/protocol/binding/proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ fn main() {
}
})
.collect();
prost_build::Config::new()
.type_attribute(
".",
"#[derive(serde::Serialize, serde::Deserialize, ts_rs::TS)]#[ts(export)]",
)
.compile_protos(&protos, &[PROTO_SRC])
let binding = prost_build::Config::new();
let mut cfg = binding;
cfg.type_attribute(".", r#"#[derive(serde::Serialize, serde::Deserialize)]"#);
for proto in protos.iter() {
let file_name = proto
.file_stem()
.expect("Proto file has filename")
.to_str()
.expect("File name is valid UTF8");
cfg.type_attribute(
format!(".{file_name}"),
format!(
"#[tslink::tslink(target = \"./output/{file_name}.ts\", module = \"{file_name}\")]"
),
);
}
cfg.compile_protos(&protos, &[PROTO_SRC])
.expect("Fail to compile protos");
}
12 changes: 12 additions & 0 deletions application/apps/protocol/binding/proto/output/attachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface AttachmentInfoList {
elements: AttachmentInfo[];
}
export interface AttachmentInfo {
uuid: string;
filepath: string;
name: string;
ext: string;
size: number;
mime: string;
messages: number[];
}
28 changes: 28 additions & 0 deletions application/apps/protocol/binding/proto/output/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export interface StringVec {
values: string[];
}
export interface CommandOutcome {
outcome_oneof: OutcomeOneof | null;
}
export interface OutcomeOneof {
Finished?: Finished;
Cancelled?: Cancelled;
}
export interface OutputOneof {
StringValue?: string;
StringVecValue?: StringVec;
OptionStringValue?: string;
BoolValue?: boolean;
Int64Value?: number;
EmptyValue?: Empty;
}
export interface Output {
output_oneof: OutputOneof | null;
}
export interface Cancelled {
}
export interface Finished {
result: Output | null;
}
export interface Empty {
}
11 changes: 11 additions & 0 deletions application/apps/protocol/binding/proto/output/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface RangeInclusive {
start: number;
end: number;
}
export interface Range {
start: number;
end: number;
}
export interface RangeInclusiveList {
elements: RangeInclusive[];
}
Loading

0 comments on commit 19cab48

Please sign in to comment.