From c2072b5260938317128c022fe8ac9ac687ea8eaf Mon Sep 17 00:00:00 2001 From: Martichou Date: Fri, 23 Feb 2024 18:19:11 +0100 Subject: [PATCH] feat: export common structs to TS Signed-off-by: Martichou --- core_lib/.gitignore | 3 +- core_lib/Cargo.lock | 171 ++++++++++++++++++++++++++ core_lib/Cargo.toml | 1 + core_lib/bindings/ChannelAction.ts | 3 + core_lib/bindings/ChannelDirection.ts | 3 + core_lib/bindings/ChannelMessage.ts | 7 ++ core_lib/bindings/State.ts | 3 + core_lib/bindings/TransferMetadata.ts | 3 + core_lib/bindings/index.ts | 5 + core_lib/build.rs | 20 +++ core_lib/dist/ChannelAction.d.ts | 1 + core_lib/dist/ChannelAction.js | 3 + core_lib/dist/ChannelDirection.d.ts | 1 + core_lib/dist/ChannelDirection.js | 3 + core_lib/dist/ChannelMessage.d.ts | 11 ++ core_lib/dist/ChannelMessage.js | 2 + core_lib/dist/State.d.ts | 1 + core_lib/dist/State.js | 3 + core_lib/dist/TransferMetadata.d.ts | 6 + core_lib/dist/TransferMetadata.js | 3 + core_lib/dist/index.d.ts | 5 + core_lib/dist/index.js | 21 ++++ core_lib/esm/ChannelAction.d.ts | 1 + core_lib/esm/ChannelAction.js | 3 + core_lib/esm/ChannelDirection.d.ts | 1 + core_lib/esm/ChannelDirection.js | 3 + core_lib/esm/ChannelMessage.d.ts | 11 ++ core_lib/esm/ChannelMessage.js | 2 + core_lib/esm/State.d.ts | 1 + core_lib/esm/State.js | 3 + core_lib/esm/TransferMetadata.d.ts | 6 + core_lib/esm/TransferMetadata.js | 3 + core_lib/esm/index.d.ts | 5 + core_lib/esm/index.js | 21 ++++ core_lib/package-lock.json | 36 ++++++ core_lib/package.json | 30 +++++ core_lib/src/channel.rs | 10 +- core_lib/src/hdl/info.rs | 4 +- core_lib/src/hdl/mod.rs | 4 +- core_lib/tsconfig.json | 12 ++ frontend/src-tauri/Cargo.lock | 43 +++++++ 41 files changed, 472 insertions(+), 6 deletions(-) create mode 100644 core_lib/bindings/ChannelAction.ts create mode 100644 core_lib/bindings/ChannelDirection.ts create mode 100644 core_lib/bindings/ChannelMessage.ts create mode 100644 core_lib/bindings/State.ts create mode 100644 core_lib/bindings/TransferMetadata.ts create mode 100644 core_lib/bindings/index.ts create mode 100644 core_lib/dist/ChannelAction.d.ts create mode 100644 core_lib/dist/ChannelAction.js create mode 100644 core_lib/dist/ChannelDirection.d.ts create mode 100644 core_lib/dist/ChannelDirection.js create mode 100644 core_lib/dist/ChannelMessage.d.ts create mode 100644 core_lib/dist/ChannelMessage.js create mode 100644 core_lib/dist/State.d.ts create mode 100644 core_lib/dist/State.js create mode 100644 core_lib/dist/TransferMetadata.d.ts create mode 100644 core_lib/dist/TransferMetadata.js create mode 100644 core_lib/dist/index.d.ts create mode 100644 core_lib/dist/index.js create mode 100644 core_lib/esm/ChannelAction.d.ts create mode 100644 core_lib/esm/ChannelAction.js create mode 100644 core_lib/esm/ChannelDirection.d.ts create mode 100644 core_lib/esm/ChannelDirection.js create mode 100644 core_lib/esm/ChannelMessage.d.ts create mode 100644 core_lib/esm/ChannelMessage.js create mode 100644 core_lib/esm/State.d.ts create mode 100644 core_lib/esm/State.js create mode 100644 core_lib/esm/TransferMetadata.d.ts create mode 100644 core_lib/esm/TransferMetadata.js create mode 100644 core_lib/esm/index.d.ts create mode 100644 core_lib/esm/index.js create mode 100644 core_lib/package-lock.json create mode 100644 core_lib/package.json create mode 100644 core_lib/tsconfig.json diff --git a/core_lib/.gitignore b/core_lib/.gitignore index b24d538..7c79672 100644 --- a/core_lib/.gitignore +++ b/core_lib/.gitignore @@ -1,2 +1,3 @@ /target -proto_comp/ \ No newline at end of file +proto_comp/ +node_modules diff --git a/core_lib/Cargo.lock b/core_lib/Cargo.lock index a0f4b5f..9dafb78 100644 --- a/core_lib/Cargo.lock +++ b/core_lib/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + [[package]] name = "addr2line" version = "0.21.0" @@ -44,6 +50,21 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.79" @@ -184,6 +205,12 @@ dependencies = [ "windows", ] +[[package]] +name = "bumpalo" +version = "3.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea184aa71bb362a1157c896979544cc23974e08fd265f29ea96b59f0b4a555b" + [[package]] name = "bytes" version = "1.5.0" @@ -211,6 +238,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.0", +] + [[package]] name = "cocoa" version = "0.25.0" @@ -730,6 +771,29 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "if-addrs" version = "0.10.2" @@ -832,6 +896,15 @@ dependencies = [ "uuid", ] +[[package]] +name = "js-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -973,6 +1046,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -1352,6 +1434,7 @@ dependencies = [ "tokio", "tokio-util", "tracing-subscriber", + "ts-rs", "uuid", ] @@ -1578,6 +1661,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.57" @@ -1713,6 +1805,31 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "ts-rs" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc2cae1fc5d05d47aa24b64f9a4f7cba24cdc9187a2084dd97ac57bef5eccae6" +dependencies = [ + "chrono", + "thiserror", + "ts-rs-macros", + "uuid", +] + +[[package]] +name = "ts-rs-macros" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f7f9b821696963053a89a7bd8b292dc34420aea8294d7b225274d488f3ec92" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn", + "termcolor", +] + [[package]] name = "typenum" version = "1.17.0" @@ -1759,6 +1876,60 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" + [[package]] name = "which" version = "4.4.2" diff --git a/core_lib/Cargo.toml b/core_lib/Cargo.toml index 48d6804..8f33087 100644 --- a/core_lib/Cargo.toml +++ b/core_lib/Cargo.toml @@ -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"] } diff --git a/core_lib/bindings/ChannelAction.ts b/core_lib/bindings/ChannelAction.ts new file mode 100644 index 0000000..76e691b --- /dev/null +++ b/core_lib/bindings/ChannelAction.ts @@ -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"; diff --git a/core_lib/bindings/ChannelDirection.ts b/core_lib/bindings/ChannelDirection.ts new file mode 100644 index 0000000..3f27d5d --- /dev/null +++ b/core_lib/bindings/ChannelDirection.ts @@ -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"; diff --git a/core_lib/bindings/ChannelMessage.ts b/core_lib/bindings/ChannelMessage.ts new file mode 100644 index 0000000..929a27e --- /dev/null +++ b/core_lib/bindings/ChannelMessage.ts @@ -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, } diff --git a/core_lib/bindings/State.ts b/core_lib/bindings/State.ts new file mode 100644 index 0000000..0bc2abe --- /dev/null +++ b/core_lib/bindings/State.ts @@ -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"; diff --git a/core_lib/bindings/TransferMetadata.ts b/core_lib/bindings/TransferMetadata.ts new file mode 100644 index 0000000..bbe0ae7 --- /dev/null +++ b/core_lib/bindings/TransferMetadata.ts @@ -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, pin_code: string | null, text_description: string | null, } diff --git a/core_lib/bindings/index.ts b/core_lib/bindings/index.ts new file mode 100644 index 0000000..6ae6f92 --- /dev/null +++ b/core_lib/bindings/index.ts @@ -0,0 +1,5 @@ +export * from "./ChannelDirection" +export * from "./ChannelMessage" +export * from "./TransferMetadata" +export * from "./ChannelAction" +export * from "./State" diff --git a/core_lib/build.rs b/core_lib/build.rs index 16a9c09..9b19527 100644 --- a/core_lib/build.rs +++ b/core_lib/build.rs @@ -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( &[ @@ -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(); } diff --git a/core_lib/dist/ChannelAction.d.ts b/core_lib/dist/ChannelAction.d.ts new file mode 100644 index 0000000..16a3020 --- /dev/null +++ b/core_lib/dist/ChannelAction.d.ts @@ -0,0 +1 @@ +export type ChannelAction = "AcceptTransfer" | "RejectTransfer" | "CancelTransfer"; diff --git a/core_lib/dist/ChannelAction.js b/core_lib/dist/ChannelAction.js new file mode 100644 index 0000000..ca914b0 --- /dev/null +++ b/core_lib/dist/ChannelAction.js @@ -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 }); diff --git a/core_lib/dist/ChannelDirection.d.ts b/core_lib/dist/ChannelDirection.d.ts new file mode 100644 index 0000000..d454bab --- /dev/null +++ b/core_lib/dist/ChannelDirection.d.ts @@ -0,0 +1 @@ +export type ChannelDirection = "FrontToLib" | "LibToFront"; diff --git a/core_lib/dist/ChannelDirection.js b/core_lib/dist/ChannelDirection.js new file mode 100644 index 0000000..ca914b0 --- /dev/null +++ b/core_lib/dist/ChannelDirection.js @@ -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 }); diff --git a/core_lib/dist/ChannelMessage.d.ts b/core_lib/dist/ChannelMessage.d.ts new file mode 100644 index 0000000..ca5d462 --- /dev/null +++ b/core_lib/dist/ChannelMessage.d.ts @@ -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; +} diff --git a/core_lib/dist/ChannelMessage.js b/core_lib/dist/ChannelMessage.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/core_lib/dist/ChannelMessage.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/core_lib/dist/State.d.ts b/core_lib/dist/State.d.ts new file mode 100644 index 0000000..962b4ee --- /dev/null +++ b/core_lib/dist/State.d.ts @@ -0,0 +1 @@ +export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "Disconnected" | "Finished"; diff --git a/core_lib/dist/State.js b/core_lib/dist/State.js new file mode 100644 index 0000000..ca914b0 --- /dev/null +++ b/core_lib/dist/State.js @@ -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 }); diff --git a/core_lib/dist/TransferMetadata.d.ts b/core_lib/dist/TransferMetadata.d.ts new file mode 100644 index 0000000..e5315db --- /dev/null +++ b/core_lib/dist/TransferMetadata.d.ts @@ -0,0 +1,6 @@ +export interface TransferMetadata { + id: string; + files: Array; + pin_code: string | null; + text_description: string | null; +} diff --git a/core_lib/dist/TransferMetadata.js b/core_lib/dist/TransferMetadata.js new file mode 100644 index 0000000..ca914b0 --- /dev/null +++ b/core_lib/dist/TransferMetadata.js @@ -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 }); diff --git a/core_lib/dist/index.d.ts b/core_lib/dist/index.d.ts new file mode 100644 index 0000000..8dd3941 --- /dev/null +++ b/core_lib/dist/index.d.ts @@ -0,0 +1,5 @@ +export * from "./ChannelDirection"; +export * from "./ChannelMessage"; +export * from "./TransferMetadata"; +export * from "./ChannelAction"; +export * from "./State"; diff --git a/core_lib/dist/index.js b/core_lib/dist/index.js new file mode 100644 index 0000000..66c5a53 --- /dev/null +++ b/core_lib/dist/index.js @@ -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); diff --git a/core_lib/esm/ChannelAction.d.ts b/core_lib/esm/ChannelAction.d.ts new file mode 100644 index 0000000..16a3020 --- /dev/null +++ b/core_lib/esm/ChannelAction.d.ts @@ -0,0 +1 @@ +export type ChannelAction = "AcceptTransfer" | "RejectTransfer" | "CancelTransfer"; diff --git a/core_lib/esm/ChannelAction.js b/core_lib/esm/ChannelAction.js new file mode 100644 index 0000000..ca914b0 --- /dev/null +++ b/core_lib/esm/ChannelAction.js @@ -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 }); diff --git a/core_lib/esm/ChannelDirection.d.ts b/core_lib/esm/ChannelDirection.d.ts new file mode 100644 index 0000000..d454bab --- /dev/null +++ b/core_lib/esm/ChannelDirection.d.ts @@ -0,0 +1 @@ +export type ChannelDirection = "FrontToLib" | "LibToFront"; diff --git a/core_lib/esm/ChannelDirection.js b/core_lib/esm/ChannelDirection.js new file mode 100644 index 0000000..ca914b0 --- /dev/null +++ b/core_lib/esm/ChannelDirection.js @@ -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 }); diff --git a/core_lib/esm/ChannelMessage.d.ts b/core_lib/esm/ChannelMessage.d.ts new file mode 100644 index 0000000..ca5d462 --- /dev/null +++ b/core_lib/esm/ChannelMessage.d.ts @@ -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; +} diff --git a/core_lib/esm/ChannelMessage.js b/core_lib/esm/ChannelMessage.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/core_lib/esm/ChannelMessage.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/core_lib/esm/State.d.ts b/core_lib/esm/State.d.ts new file mode 100644 index 0000000..962b4ee --- /dev/null +++ b/core_lib/esm/State.d.ts @@ -0,0 +1 @@ +export type State = "Initial" | "ReceivedConnectionRequest" | "SentUkeyServerInit" | "ReceivedUkeyClientFinish" | "SentConnectionResponse" | "SentPairedKeyResult" | "ReceivedPairedKeyResult" | "WaitingForUserConsent" | "ReceivingFiles" | "Disconnected" | "Finished"; diff --git a/core_lib/esm/State.js b/core_lib/esm/State.js new file mode 100644 index 0000000..ca914b0 --- /dev/null +++ b/core_lib/esm/State.js @@ -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 }); diff --git a/core_lib/esm/TransferMetadata.d.ts b/core_lib/esm/TransferMetadata.d.ts new file mode 100644 index 0000000..e5315db --- /dev/null +++ b/core_lib/esm/TransferMetadata.d.ts @@ -0,0 +1,6 @@ +export interface TransferMetadata { + id: string; + files: Array; + pin_code: string | null; + text_description: string | null; +} diff --git a/core_lib/esm/TransferMetadata.js b/core_lib/esm/TransferMetadata.js new file mode 100644 index 0000000..ca914b0 --- /dev/null +++ b/core_lib/esm/TransferMetadata.js @@ -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 }); diff --git a/core_lib/esm/index.d.ts b/core_lib/esm/index.d.ts new file mode 100644 index 0000000..8dd3941 --- /dev/null +++ b/core_lib/esm/index.d.ts @@ -0,0 +1,5 @@ +export * from "./ChannelDirection"; +export * from "./ChannelMessage"; +export * from "./TransferMetadata"; +export * from "./ChannelAction"; +export * from "./State"; diff --git a/core_lib/esm/index.js b/core_lib/esm/index.js new file mode 100644 index 0000000..66c5a53 --- /dev/null +++ b/core_lib/esm/index.js @@ -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); diff --git a/core_lib/package-lock.json b/core_lib/package-lock.json new file mode 100644 index 0000000..7823305 --- /dev/null +++ b/core_lib/package-lock.json @@ -0,0 +1,36 @@ +{ + "name": "@martichou/core_lib", + "version": "1.0.9", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "@martichou/core_lib", + "version": "1.0.9", + "devDependencies": { + "typescript": "^5.0.4" + } + }, + "node_modules/typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + }, + "dependencies": { + "typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true + } + } +} diff --git a/core_lib/package.json b/core_lib/package.json new file mode 100644 index 0000000..e86e678 --- /dev/null +++ b/core_lib/package.json @@ -0,0 +1,30 @@ +{ + "name": "@martichou/core_lib", + "version": "1.0.9", + "description": "Models being shared with the VueJS application", + "main": "dist/index.js", + "module": "esm/index.js", + "types": "dist/index.d.ts", + "files": [ + "dist", + "bindings", + "esm" + ], + "scripts": { + "build:cjs": "tsc --module commonjs --outDir dist", + "build:esm": "tsc --target es2018 --outDir esm", + "build": "npm run build:esm && npm run build:cjs" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Martichou/rquickshare.git" + }, + "author": "Martin ANDRE", + "bugs": { + "url": "https://github.com/Martichou/rquickshare/issues" + }, + "homepage": "https://github.com/Martichou/rquickshare#readme", + "devDependencies": { + "typescript": "^5.0.4" + } + } diff --git a/core_lib/src/channel.rs b/core_lib/src/channel.rs index 80a98ff..264692b 100644 --- a/core_lib/src/channel.rs +++ b/core_lib/src/channel.rs @@ -1,22 +1,26 @@ use serde::{Deserialize, Serialize}; +use ts_rs::TS; use crate::hdl::info::TransferMetadata; use crate::hdl::State; -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, TS)] +#[ts(export)] pub enum ChannelDirection { FrontToLib, LibToFront, } -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, TS)] +#[ts(export)] pub enum ChannelAction { AcceptTransfer, RejectTransfer, CancelTransfer, } -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, TS)] +#[ts(export)] pub struct ChannelMessage { pub id: String, pub direction: ChannelDirection, diff --git a/core_lib/src/hdl/info.rs b/core_lib/src/hdl/info.rs index 97abeb2..7ea7dda 100644 --- a/core_lib/src/hdl/info.rs +++ b/core_lib/src/hdl/info.rs @@ -2,6 +2,7 @@ use std::fs::File; use std::path::PathBuf; use serde::{Deserialize, Serialize}; +use ts_rs::TS; use crate::sharing_nearby::FileMetadata; @@ -14,7 +15,8 @@ pub struct InternalFileInfo { pub file: Option, } -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, TS)] +#[ts(export)] pub struct TransferMetadata { pub id: String, pub files: Vec, diff --git a/core_lib/src/hdl/mod.rs b/core_lib/src/hdl/mod.rs index 0732f2c..af7227a 100644 --- a/core_lib/src/hdl/mod.rs +++ b/core_lib/src/hdl/mod.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use p256::{PublicKey, SecretKey}; use serde::{Deserialize, Serialize}; +use ts_rs::TS; use self::info::{InternalFileInfo, TransferMetadata}; use crate::securegcm::ukey2_client_init::CipherCommitment; @@ -16,7 +17,8 @@ mod mdns; pub use mdns::*; #[allow(dead_code)] -#[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)] +#[ts(export)] pub enum State { #[default] Initial, diff --git a/core_lib/tsconfig.json b/core_lib/tsconfig.json new file mode 100644 index 0000000..205472c --- /dev/null +++ b/core_lib/tsconfig.json @@ -0,0 +1,12 @@ +{ + "include": ["bindings"], + "compilerOptions": { + "target": "es2016", + "module": "commonjs", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "declaration": true, + } +} diff --git a/frontend/src-tauri/Cargo.lock b/frontend/src-tauri/Cargo.lock index 6903fca..1c0b5ba 100644 --- a/frontend/src-tauri/Cargo.lock +++ b/frontend/src-tauri/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + [[package]] name = "addr2line" version = "0.21.0" @@ -596,8 +602,10 @@ checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "wasm-bindgen", "windows-targets 0.52.0", ] @@ -3627,6 +3635,7 @@ dependencies = [ "tokio", "tokio-util", "tracing-subscriber", + "ts-rs", "uuid", ] @@ -4570,6 +4579,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thin-slice" version = "0.1.1" @@ -4880,6 +4898,31 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "ts-rs" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc2cae1fc5d05d47aa24b64f9a4f7cba24cdc9187a2084dd97ac57bef5eccae6" +dependencies = [ + "chrono", + "thiserror", + "ts-rs-macros", + "uuid", +] + +[[package]] +name = "ts-rs-macros" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f7f9b821696963053a89a7bd8b292dc34420aea8294d7b225274d488f3ec92" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn 2.0.48", + "termcolor", +] + [[package]] name = "typenum" version = "1.17.0"