TS bindings for Rust types

This commit is contained in:
Jamie
2021-12-25 23:26:00 -08:00
parent 836178ca45
commit 7b48d80a9d
21 changed files with 122 additions and 44 deletions

View File

Binary file not shown.

View File

@@ -60,7 +60,7 @@ const Heading: React.FC<{}> = ({ children }) => (
export const Sidebar: React.FC<SidebarProps> = (props) => {
const locations = useLocations();
return (
<div className="w-46 flex flex-col flex-wrap flex-shrink-0 min-h-full bg-gray-50 dark:bg-gray-650 !bg-opacity-60 border-gray-100 border-r dark:border-gray-600 px-3 space-y-0.5">
<div className="w-46 flex flex-col flex-wrap flex-shrink-0 min-h-full bg-gray-50 dark:bg-gray-650 !bg-opacity-60 border-gray-100 border-r dark:border-gray-600 px-3 py-1">
<Dropdown
buttonProps={{
justifyLeft: true,
@@ -79,7 +79,7 @@ export const Sidebar: React.FC<SidebarProps> = (props) => {
]}
/>
<div>
<div className='pt-1'>
<SidebarLink to="/overview">
<Icon component={Planet} />
Overview

View File

@@ -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<DriveListItemProps> = (props) => {
return <div className={clsx('rounded px-1.5 py-1 text-xs font-medium inline-block cursor-default', props.className)}>
</div>;
};

View File

@@ -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<TagProps> = (props) => {
return <div className={clsx('rounded px-2 py-1', props.className)}>{props.children}</div>;
return <div className={clsx('rounded px-1.5 py-1 text-xs font-medium inline-block cursor-default', {
'bg-red-500 hover:bg-red-400': props.color === 'red',
'bg-orange-500 hover:bg-orange-400': props.color === 'orange',
'bg-yellow-500 hover:bg-yellow-400': props.color === 'yellow',
'bg-green-500 hover:bg-green-400': props.color === 'green',
'bg-blue-500 hover:bg-blue-400': props.color === 'blue',
'bg-purple-500 hover:bg-purple-400': props.color === 'purple',
'bg-pink-500 hover:bg-pink-400': props.color === 'pink',
}, props.className)}>{props.children}</div>;
};

View File

@@ -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) => {
<StatItem name="Index size" value="103" unit="MB" />
<StatItem name="Preview media" value="23.5" unit="GB" />
<StatItem name="Free space" value="9.2" unit="TB" />
<StatItem name="Total at-risk" value="1.5" unit="TB" />
<StatItem name="Total backed up" value="25.3" unit="TB" />
</div>
<hr className="my-5 dark:border-gray-800" />
<div className='-mt-[1px] space-x-2'>
<Tag color='red'>Videos</Tag>
<Tag color='orange'>DSLR Photos</Tag>
<Tag color='yellow'>Camera Roll</Tag>
<Tag color='green'>NFTs</Tag>
<Tag color='pink'>Screenshots</Tag>
<Tag color='blue'>Documents</Tag>
<Tag color='purple'>Repositories</Tag>
</div>
<hr className="my-5 dark:border-gray-800" />
<div>
</div>
</div>
);
};

View File

@@ -26,7 +26,7 @@ const config = useAppState()
]);
return (
<div>
<div className='bg-gray-900'>
<div className="px-5">
{/* <FileList files={dummyIFile} /> */}
{/* <Spline scene={WINDOWS_SCENE} /> */}
@@ -67,7 +67,6 @@ const config = useAppState()
>
Test Scan
</Button>
<Button size="sm">Test</Button>
</div>
<div className="flex flex-row mt-4 space-x-2">

BIN
packages/core/Cargo.lock generated
View File

Binary file not shown.

View File

@@ -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"] }

View File

@@ -0,0 +1,2 @@
export interface CaptureDevice { id: number, name: string, date_created: string, date_modified: string, }

View File

@@ -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, }

View File

@@ -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, }

View File

@@ -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, }

View File

@@ -0,0 +1,2 @@
export interface StorageDevice { id: number, name: string, date_created: string, date_modified: string, }

View File

@@ -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, }

View File

@@ -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<NaiveDateTime>,
pub date_modified: Option<NaiveDateTime>,
#[sea_orm(primary_key)]
pub id: u32,
pub name: String,
#[ts(type = "string")]
pub date_created: Option<NaiveDateTime>,
#[ts(type = "string")]
pub date_modified: Option<NaiveDateTime>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@@ -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<NaiveDateTime>,
pub date_modified: Option<NaiveDateTime>,
pub date_indexed: Option<NaiveDateTime>,
// metadata
pub name: String,
pub extension: String,
pub size_in_bytes: String,
pub library_id: u32,
// date
#[ts(type = "string")]
pub date_created: Option<NaiveDateTime>,
#[ts(type = "string")]
pub date_modified: Option<NaiveDateTime>,
#[ts(type = "string")]
pub date_indexed: Option<NaiveDateTime>,
// #[sea_orm(column_type = "Int")]
// pub encryption: crypto::Encryption,
// ownership

View File

@@ -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<String>,
pub total_file_count: Option<u32>,
pub total_bytes_used: Option<String>,
pub total_byte_capacity: Option<String>,
pub date_created: Option<NaiveDateTime>,
pub timezone: Option<String>,
// identity
#[sea_orm(primary_key)]
pub id: u32,
pub name: String,
pub is_primary: bool,
pub remote_id: Option<String>,
pub total_file_count: Option<u32>,
pub total_bytes_used: Option<String>,
pub total_byte_capacity: Option<String>,
#[ts(type = "string")]
pub date_created: Option<NaiveDateTime>,
pub timezone: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@@ -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<String>,
pub calculated_file_count: Option<u32>,
pub library_id: String,
#[ts(type = "string")]
pub date_created: Option<NaiveDateTime>,
#[ts(type = "string")]
pub date_modified: Option<NaiveDateTime>,
}

View File

@@ -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<NaiveDateTime>,
pub date_modified: Option<NaiveDateTime>,
#[sea_orm(primary_key)]
pub id: u32,
pub name: String,
#[ts(type = "string")]
pub date_created: Option<NaiveDateTime>,
#[ts(type = "string")]
pub date_modified: Option<NaiveDateTime>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@@ -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<String>,
pub redundancy_goal: Option<u32>,
pub library_id: String,
#[ts(type = "string")]
pub date_created: Option<NaiveDateTime>,
#[ts(type = "string")]
pub date_modified: Option<NaiveDateTime>,
}

View File

@@ -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<Vec<ObjectMutation>>
pub mutations: Option<Vec<ObjectMutation>>,
}
//
//
pub struct ObjectMutation {
pub primary_key: Vec<i32>,
pub columns: Vec<String>,
@@ -33,4 +33,4 @@ pub enum TransactionMethod {
// assign tag to file
// create files
// create action records
//
//