From 7b48d80a9d259f0c2cbfb3ccc085d35f4fbb2bab Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 25 Dec 2021 23:26:00 -0800 Subject: [PATCH] TS bindings for Rust types --- apps/desktop/src-tauri/Cargo.lock | Bin 123770 -> 124341 bytes apps/desktop/src/components/file/Sidebar.tsx | 4 +-- .../src/components/items/DriveListItem.tsx | 13 ++++++++ apps/desktop/src/components/primitive/Tag.tsx | 14 +++++++-- apps/desktop/src/screens/Overview.tsx | 16 +++++++++- apps/desktop/src/screens/Settings.tsx | 3 +- packages/core/Cargo.lock | Bin 61838 -> 62409 bytes packages/core/Cargo.toml | 1 + packages/core/bindings/CaptureDevice.ts | 2 ++ packages/core/bindings/File.ts | 2 ++ packages/core/bindings/Library.ts | 2 ++ packages/core/bindings/Space.ts | 2 ++ packages/core/bindings/StorageDevice.ts | 2 ++ packages/core/bindings/Tag.ts | 2 ++ packages/core/lib/db/entity/capture_device.rs | 17 +++++++---- packages/core/lib/db/entity/file.rs | 16 ++++++---- packages/core/lib/db/entity/library.rs | 28 ++++++++++-------- packages/core/lib/db/entity/space.rs | 8 +++-- packages/core/lib/db/entity/storage_device.rs | 17 +++++++---- packages/core/lib/db/entity/tag.rs | 7 ++++- packages/core/lib/tx/type.rs | 10 +++---- 21 files changed, 122 insertions(+), 44 deletions(-) create mode 100644 apps/desktop/src/components/items/DriveListItem.tsx create mode 100644 packages/core/bindings/CaptureDevice.ts create mode 100644 packages/core/bindings/File.ts create mode 100644 packages/core/bindings/Library.ts create mode 100644 packages/core/bindings/Space.ts create mode 100644 packages/core/bindings/StorageDevice.ts create mode 100644 packages/core/bindings/Tag.ts diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lock index cf7116a83650ae6a2a3e9a56e0ab967f7df83324..fa1292c2632556e5c6c2f6c0ac370bb8ee603bda 100644 GIT binary patch delta 281 zcmXYqJ4(b*7=`(Z5Y!^-$e?JEnL-d9xR2aN1dS0vD;qa3H}@d}>OeAzy-P@OZM1O% zHj=_tY}|sou$#&REe;$GALpBYhHqct>kiZ(8$CZhgyo>Lm-fCMtZhDI&}0Bhc`&O+ zW#uQkuXiiec6(QDYj0lws3*%^ETG9$iT1P5czLV77KkGiah5kZ3oZ0ePPp>>ag{@}q I1iZ*96ZqH_9MqdX2_u~x& diff --git a/apps/desktop/src/components/file/Sidebar.tsx b/apps/desktop/src/components/file/Sidebar.tsx index 1be832d07..29c77189c 100644 --- a/apps/desktop/src/components/file/Sidebar.tsx +++ b/apps/desktop/src/components/file/Sidebar.tsx @@ -60,7 +60,7 @@ const Heading: React.FC<{}> = ({ children }) => ( export const Sidebar: React.FC = (props) => { const locations = useLocations(); return ( -
+
= (props) => { ]} /> -
+
Overview diff --git a/apps/desktop/src/components/items/DriveListItem.tsx b/apps/desktop/src/components/items/DriveListItem.tsx new file mode 100644 index 000000000..47fcaabc8 --- /dev/null +++ b/apps/desktop/src/components/items/DriveListItem.tsx @@ -0,0 +1,13 @@ +import clsx from 'clsx'; +import React from 'react'; +import { DefaultProps } from '../primitive/types'; + +export interface DriveListItemProps extends DefaultProps { + name: string; +} + +export const DriveListItem: React.FC = (props) => { + return
+ +
; +}; diff --git a/apps/desktop/src/components/primitive/Tag.tsx b/apps/desktop/src/components/primitive/Tag.tsx index aeef4a9e1..533bed27d 100644 --- a/apps/desktop/src/components/primitive/Tag.tsx +++ b/apps/desktop/src/components/primitive/Tag.tsx @@ -2,8 +2,18 @@ import clsx from 'clsx'; import React from 'react'; import { DefaultProps } from './types'; -export interface TagProps extends DefaultProps {} +export interface TagProps extends DefaultProps { + color: 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'pink'; +} export const Tag: React.FC = (props) => { - return
{props.children}
; + return
{props.children}
; }; diff --git a/apps/desktop/src/screens/Overview.tsx b/apps/desktop/src/screens/Overview.tsx index 567787662..bb662e86f 100644 --- a/apps/desktop/src/screens/Overview.tsx +++ b/apps/desktop/src/screens/Overview.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { Tag } from '../components/primitive/Tag'; interface StatItemProps { name: string; @@ -27,10 +28,23 @@ export const OverviewScreen: React.FC<{}> = (props) => { -
+
+
+ Videos + DSLR Photos + Camera Roll + NFTs + Screenshots + Documents + Repositories +
+
+
+ +
); }; diff --git a/apps/desktop/src/screens/Settings.tsx b/apps/desktop/src/screens/Settings.tsx index 7f83da002..0d6dfe1fa 100644 --- a/apps/desktop/src/screens/Settings.tsx +++ b/apps/desktop/src/screens/Settings.tsx @@ -26,7 +26,7 @@ const config = useAppState() ]); return ( -
+
{/* */} {/* */} @@ -67,7 +67,6 @@ const config = useAppState() > Test Scan -
diff --git a/packages/core/Cargo.lock b/packages/core/Cargo.lock index e1073c0cd76ccca16f58fbcc5b6e8db1de36d7f1..13b90a5fa84557a32ef93ee9142afd33d1a6b00d 100644 GIT binary patch delta 298 zcmZvXJ5B>J07Mm%DjgyOq@-B3;}h`T-Xi1*z}+yb#cOEJ%AKkal?$drJ_2ygKwOrnwhbUvE@}qv1dvjrK(qnJb%sOJV z5kuo1zD@>V;zQoQHa=ADDw}3GJBF!qIGmxyS_ z009PY#ZY0HM93Hg0m6bpt}QNg+cX@bR$g#K((`&J-7R<1*?8DqkH#;Qt6kbW7&Y~K GzV{6RXI!5E delta 32 qcmV+*0N?+~=L3%81F$IplN25mvugo4pOfa1A+yh*)i1NC(jg(}s1B0= diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml index 069edbfb1..3c03b23fc 100644 --- a/packages/core/Cargo.toml +++ b/packages/core/Cargo.toml @@ -33,6 +33,7 @@ sha256 = "1.0.2" once_cell = "1.8.0" int-enum = "0.4.0" # Project dependencies +ts-rs = "6.1" rusqlite = "0.25.3" refinery = { version = "0.6.0", features = ["rusqlite"] } sqlx = { version = "0.5.7", features = ["sqlite"] } diff --git a/packages/core/bindings/CaptureDevice.ts b/packages/core/bindings/CaptureDevice.ts new file mode 100644 index 000000000..32feb7cbf --- /dev/null +++ b/packages/core/bindings/CaptureDevice.ts @@ -0,0 +1,2 @@ + +export interface CaptureDevice { id: number, name: string, date_created: string, date_modified: string, } \ No newline at end of file diff --git a/packages/core/bindings/File.ts b/packages/core/bindings/File.ts new file mode 100644 index 000000000..caea15ca5 --- /dev/null +++ b/packages/core/bindings/File.ts @@ -0,0 +1,2 @@ + +export interface File { id: number, meta_checksum: string, uri: string, is_dir: boolean, name: string, extension: string, size_in_bytes: string, library_id: number, date_created: string, date_modified: string, date_indexed: string, ipfs_id: string | null, storage_device_id: number | null, capture_device_id: number | null, parent_id: number | null, } \ No newline at end of file diff --git a/packages/core/bindings/Library.ts b/packages/core/bindings/Library.ts new file mode 100644 index 000000000..8d1be77f3 --- /dev/null +++ b/packages/core/bindings/Library.ts @@ -0,0 +1,2 @@ + +export interface Library { id: number, name: string, is_primary: boolean, remote_id: string | null, total_file_count: number | null, total_bytes_used: string | null, total_byte_capacity: string | null, date_created: string, timezone: string | null, } \ No newline at end of file diff --git a/packages/core/bindings/Space.ts b/packages/core/bindings/Space.ts new file mode 100644 index 000000000..dfac99a66 --- /dev/null +++ b/packages/core/bindings/Space.ts @@ -0,0 +1,2 @@ + +export interface Space { id: number, name: string, calculated_size_in_bytes: string | null, calculated_file_count: number | null, library_id: string, date_created: string, date_modified: string, } \ No newline at end of file diff --git a/packages/core/bindings/StorageDevice.ts b/packages/core/bindings/StorageDevice.ts new file mode 100644 index 000000000..e0bb66849 --- /dev/null +++ b/packages/core/bindings/StorageDevice.ts @@ -0,0 +1,2 @@ + +export interface StorageDevice { id: number, name: string, date_created: string, date_modified: string, } \ No newline at end of file diff --git a/packages/core/bindings/Tag.ts b/packages/core/bindings/Tag.ts new file mode 100644 index 000000000..7107188e6 --- /dev/null +++ b/packages/core/bindings/Tag.ts @@ -0,0 +1,2 @@ + +export interface Tag { id: number, name: string, total_files: string | null, redundancy_goal: number | null, library_id: string, date_created: string, date_modified: string, } \ No newline at end of file diff --git a/packages/core/lib/db/entity/capture_device.rs b/packages/core/lib/db/entity/capture_device.rs index 4f1fdd97c..c0a1ede5a 100644 --- a/packages/core/lib/db/entity/capture_device.rs +++ b/packages/core/lib/db/entity/capture_device.rs @@ -1,18 +1,23 @@ use chrono::NaiveDateTime; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; +use ts_rs::TS; // ------------------------------------- // Entity: Space -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default, TS)] #[sea_orm(table_name = "capture_devices")] +#[serde(rename = "CaptureDevice")] +#[ts(export)] // ------------------------------------- pub struct Model { - #[sea_orm(primary_key)] - pub id: u32, - pub name: String, - pub date_created: Option, - pub date_modified: Option, + #[sea_orm(primary_key)] + pub id: u32, + pub name: String, + #[ts(type = "string")] + pub date_created: Option, + #[ts(type = "string")] + pub date_modified: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/packages/core/lib/db/entity/file.rs b/packages/core/lib/db/entity/file.rs index ca5395e36..38a2a0fe2 100644 --- a/packages/core/lib/db/entity/file.rs +++ b/packages/core/lib/db/entity/file.rs @@ -1,12 +1,15 @@ use chrono::NaiveDateTime; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; +use ts_rs::TS; // ------------------------------------- // Entity: File // Represents an item discovered on the filesystem -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default, TS)] #[sea_orm(table_name = "files")] +#[serde(rename = "File")] +#[ts(export)] // ------------------------------------- pub struct Model { // identity @@ -17,15 +20,18 @@ pub struct Model { pub meta_checksum: String, pub uri: String, pub is_dir: bool, - // date - pub date_created: Option, - pub date_modified: Option, - pub date_indexed: Option, // metadata pub name: String, pub extension: String, pub size_in_bytes: String, pub library_id: u32, + // date + #[ts(type = "string")] + pub date_created: Option, + #[ts(type = "string")] + pub date_modified: Option, + #[ts(type = "string")] + pub date_indexed: Option, // #[sea_orm(column_type = "Int")] // pub encryption: crypto::Encryption, // ownership diff --git a/packages/core/lib/db/entity/library.rs b/packages/core/lib/db/entity/library.rs index 0c4389e16..d828b85f8 100644 --- a/packages/core/lib/db/entity/library.rs +++ b/packages/core/lib/db/entity/library.rs @@ -1,25 +1,29 @@ use chrono::NaiveDateTime; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; +use ts_rs::TS; // ------------------------------------- // Entity: Directory // Represents an item discovered on the filesystem -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default, TS)] #[sea_orm(table_name = "libraries")] +#[serde(rename = "Library")] +#[ts(export)] // ------------------------------------- pub struct Model { - // identity - #[sea_orm(primary_key)] - pub id: u32, - pub name: String, - pub is_primary: bool, - pub remote_id: Option, - pub total_file_count: Option, - pub total_bytes_used: Option, - pub total_byte_capacity: Option, - pub date_created: Option, - pub timezone: Option, + // identity + #[sea_orm(primary_key)] + pub id: u32, + pub name: String, + pub is_primary: bool, + pub remote_id: Option, + pub total_file_count: Option, + pub total_bytes_used: Option, + pub total_byte_capacity: Option, + #[ts(type = "string")] + pub date_created: Option, + pub timezone: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/packages/core/lib/db/entity/space.rs b/packages/core/lib/db/entity/space.rs index 3fa2c1948..1fd89a76e 100644 --- a/packages/core/lib/db/entity/space.rs +++ b/packages/core/lib/db/entity/space.rs @@ -1,11 +1,13 @@ use chrono::NaiveDateTime; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; - +use ts_rs::TS; // ------------------------------------- // Entity: Space -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default, TS)] #[sea_orm(table_name = "spaces")] +#[serde(rename = "Space")] +#[ts(export)] // ------------------------------------- pub struct Model { #[sea_orm(primary_key)] @@ -14,7 +16,9 @@ pub struct Model { pub calculated_size_in_bytes: Option, pub calculated_file_count: Option, pub library_id: String, + #[ts(type = "string")] pub date_created: Option, + #[ts(type = "string")] pub date_modified: Option, } diff --git a/packages/core/lib/db/entity/storage_device.rs b/packages/core/lib/db/entity/storage_device.rs index e5cab98cb..43f0402bf 100644 --- a/packages/core/lib/db/entity/storage_device.rs +++ b/packages/core/lib/db/entity/storage_device.rs @@ -1,18 +1,23 @@ use chrono::NaiveDateTime; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; +use ts_rs::TS; // ------------------------------------- // Entity: Space -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default, TS)] #[sea_orm(table_name = "storage_devices")] +#[serde(rename = "StorageDevice")] +#[ts(export)] // ------------------------------------- pub struct Model { - #[sea_orm(primary_key)] - pub id: u32, - pub name: String, - pub date_created: Option, - pub date_modified: Option, + #[sea_orm(primary_key)] + pub id: u32, + pub name: String, + #[ts(type = "string")] + pub date_created: Option, + #[ts(type = "string")] + pub date_modified: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/packages/core/lib/db/entity/tag.rs b/packages/core/lib/db/entity/tag.rs index 50ba7100a..8459fbc64 100644 --- a/packages/core/lib/db/entity/tag.rs +++ b/packages/core/lib/db/entity/tag.rs @@ -1,11 +1,14 @@ use chrono::NaiveDateTime; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; +use ts_rs::TS; // ------------------------------------- // Entity: Tag -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default)] +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, DeriveEntityModel, Default, TS)] #[sea_orm(table_name = "tags")] +#[serde(rename = "Tag")] +#[ts(export)] // ------------------------------------- pub struct Model { #[sea_orm(primary_key)] @@ -14,7 +17,9 @@ pub struct Model { pub total_files: Option, pub redundancy_goal: Option, pub library_id: String, + #[ts(type = "string")] pub date_created: Option, + #[ts(type = "string")] pub date_modified: Option, } diff --git a/packages/core/lib/tx/type.rs b/packages/core/lib/tx/type.rs index 2b338bfa4..419f141a5 100644 --- a/packages/core/lib/tx/type.rs +++ b/packages/core/lib/tx/type.rs @@ -4,18 +4,18 @@ // - they are emitted by a given client and accepted or rejected by sister clients // - if a client rejects a transaction the entire database will be marked for re-sync pub struct Transaction { - pub id: i32, + pub id: i32, pub timestamp: i32, // unix timestamp pub client_id: i32, // the client that created the transaction pub model: String, // the model that the transaction is for - pub method TransactionMethod, + pub method: TransactionMethod, // vector of transaction entries - pub mutations: Option> + pub mutations: Option>, } -// +// pub struct ObjectMutation { pub primary_key: Vec, pub columns: Vec, @@ -33,4 +33,4 @@ pub enum TransactionMethod { // assign tag to file // create files // create action records -// \ No newline at end of file +//