Skip to content

Commit

Permalink
feat: export common structs to TS
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <m@rtin.fyi>
  • Loading branch information
Martichou committed Feb 23, 2024
1 parent 428e141 commit c2072b5
Show file tree
Hide file tree
Showing 41 changed files with 472 additions and 6 deletions.
3 changes: 2 additions & 1 deletion core_lib/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
proto_comp/
proto_comp/
node_modules
171 changes: 171 additions & 0 deletions core_lib/Cargo.lock

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

1 change: 1 addition & 0 deletions core_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sys_metrics = "0.2"
tokio = { version = "1.25", features = ["macros", "rt", "rt-multi-thread", "net", "sync", "time", "io-util", "signal"] }
tokio-util = { version = "0.7", features = ["rt"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
ts-rs = { version = "7.1", features = ["serde-compat", "uuid-impl", "chrono-impl"] }
uuid = "1.7.0"
serde = { version = "1.0", features = ["derive"] }

Expand Down
3 changes: 3 additions & 0 deletions core_lib/bindings/ChannelAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type ChannelAction = "AcceptTransfer" | "RejectTransfer" | "CancelTransfer";
3 changes: 3 additions & 0 deletions core_lib/bindings/ChannelDirection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type ChannelDirection = "FrontToLib" | "LibToFront";
7 changes: 7 additions & 0 deletions core_lib/bindings/ChannelMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { ChannelAction } from "./ChannelAction";
import type { ChannelDirection } from "./ChannelDirection";
import type { State } from "./State";
import type { TransferMetadata } from "./TransferMetadata";

export interface ChannelMessage { id: string, direction: ChannelDirection, action: ChannelAction | null, state: State | null, meta: TransferMetadata | null, }
3 changes: 3 additions & 0 deletions core_lib/bindings/State.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "Disconnected" | "Finished";
3 changes: 3 additions & 0 deletions core_lib/bindings/TransferMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface TransferMetadata { id: string, files: Array<string>, pin_code: string | null, text_description: string | null, }
5 changes: 5 additions & 0 deletions core_lib/bindings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./ChannelDirection"
export * from "./ChannelMessage"
export * from "./TransferMetadata"
export * from "./ChannelAction"
export * from "./State"
20 changes: 20 additions & 0 deletions core_lib/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
extern crate prost_build;

use std::ffi::OsStr;
use std::fs::{self, File};
use std::io::Write;

fn main() {
prost_build::compile_protos(
&[
Expand All @@ -13,4 +17,20 @@ fn main() {
&["src/proto_src"],
)
.unwrap();

let exports: Vec<_> = fs::read_dir("./bindings")
.unwrap()
.filter_map(Result::ok)
.filter_map(|p| {
p.path()
.file_stem()
.and_then(OsStr::to_str)
.map(str::to_owned)
})
.filter(|f| f != "index")
.map(|f| format!("export * from \"./{}\"", f))
.collect();

let mut file = File::create("./bindings/index.ts").unwrap();
file.write_all(exports.join("\n").as_bytes()).unwrap();
}
1 change: 1 addition & 0 deletions core_lib/dist/ChannelAction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ChannelAction = "AcceptTransfer" | "RejectTransfer" | "CancelTransfer";
3 changes: 3 additions & 0 deletions core_lib/dist/ChannelAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
Object.defineProperty(exports, "__esModule", { value: true });
1 change: 1 addition & 0 deletions core_lib/dist/ChannelDirection.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ChannelDirection = "FrontToLib" | "LibToFront";
3 changes: 3 additions & 0 deletions core_lib/dist/ChannelDirection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
Object.defineProperty(exports, "__esModule", { value: true });
11 changes: 11 additions & 0 deletions core_lib/dist/ChannelMessage.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { ChannelAction } from "./ChannelAction";
import type { ChannelDirection } from "./ChannelDirection";
import type { State } from "./State";
import type { TransferMetadata } from "./TransferMetadata";
export interface ChannelMessage {
id: string;
direction: ChannelDirection;
action: ChannelAction | null;
state: State | null;
meta: TransferMetadata | null;
}
2 changes: 2 additions & 0 deletions core_lib/dist/ChannelMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
1 change: 1 addition & 0 deletions core_lib/dist/State.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "Disconnected" | "Finished";
3 changes: 3 additions & 0 deletions core_lib/dist/State.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
Object.defineProperty(exports, "__esModule", { value: true });
6 changes: 6 additions & 0 deletions core_lib/dist/TransferMetadata.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface TransferMetadata {
id: string;
files: Array<string>;
pin_code: string | null;
text_description: string | null;
}
3 changes: 3 additions & 0 deletions core_lib/dist/TransferMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use strict";
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
Object.defineProperty(exports, "__esModule", { value: true });
5 changes: 5 additions & 0 deletions core_lib/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./ChannelDirection";
export * from "./ChannelMessage";
export * from "./TransferMetadata";
export * from "./ChannelAction";
export * from "./State";
21 changes: 21 additions & 0 deletions core_lib/dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./ChannelDirection"), exports);
__exportStar(require("./ChannelMessage"), exports);
__exportStar(require("./TransferMetadata"), exports);
__exportStar(require("./ChannelAction"), exports);
__exportStar(require("./State"), exports);
1 change: 1 addition & 0 deletions core_lib/esm/ChannelAction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ChannelAction = "AcceptTransfer" | "RejectTransfer" | "CancelTransfer";
Loading

0 comments on commit c2072b5

Please sign in to comment.