Skip to content

Commit

Permalink
Add NodeInfo, RepositoryInfo and Author types
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinez committed Aug 13, 2024
1 parent 98eca7e commit 7dbb705
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src-tauri/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
# will have compiled files and executables
/target/
/gen/schemas

# Generated by ts-rs
/bindings
3 changes: 3 additions & 0 deletions src-tauri/bindings/Author.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 Author = { id: string, alias?: string, };
11 changes: 11 additions & 0 deletions src-tauri/bindings/NodeInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type NodeInfo = {
id: string;
state: string;
alias: string | null;
agent: string | null;
avatarUrl?: string;
bannerUrl?: string;
description?: string;
};
4 changes: 4 additions & 0 deletions src-tauri/bindings/RepositoryInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Author } from "./Author";

export type RepositoryInfo = { id: string, name: string, description: string, seeding: number, threshold: number, lastUpdate: number, defaultBranch: string, head: string, delegates: Array<Author>, visibility: { type: 'public' } | { type: 'private'; allow?: string[]; }, issues: { open: number; closed: number; }, patches: { open: number; draft: number; archived: number; merged: number; }, };
69 changes: 69 additions & 0 deletions src-tauri/src/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use serde::Serialize;
use ts_rs::TS;

use radicle::cob;
use radicle::crypto::PublicKey;
use radicle::git::{BranchName, Oid};
use radicle::identity::{RepoId, Visibility};
use radicle::node::{Alias, AliasStore, NodeId, UserAgent};
use radicle::profile::Aliases;

#[derive(Clone, Debug, Serialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export)]
pub struct NodeInfo {
#[ts(as = "String")]
pub id: PublicKey,
pub state: String,
#[ts(as = "Option<String>")]
pub alias: Option<Alias>,
#[ts(as = "Option<String>")]
pub agent: Option<UserAgent>,
#[ts(optional)]
pub avatar_url: Option<String>,
#[ts(optional)]
pub banner_url: Option<String>,
#[ts(optional)]
pub description: Option<String>,
}

#[derive(Serialize, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export)]
pub struct RepositoryInfo {
#[ts(as = "String")]
pub id: RepoId,
pub name: String,
pub description: String,
pub seeding: usize,
pub threshold: usize,
#[ts(type = "number")]
pub last_update: i64,
#[ts(as = "String")]
pub default_branch: BranchName,
#[ts(as = "String")]
pub head: Oid,
pub delegates: Vec<Author>,
#[ts(type = "{ type: 'public' } | { type: 'private'; allow?: string[]; }")]
pub visibility: Visibility,
#[ts(type = "{ open: number; closed: number; }")]
pub issues: cob::issue::IssueCounts,
#[ts(type = "{ open: number; draft: number; archived: number; merged: number; }")]
pub patches: cob::patch::PatchCounts,
}

#[derive(Serialize, TS)]
pub struct Author {
#[ts(as = "String")]
id: NodeId,
#[ts(optional, as = "Option<String>")]
alias: Option<Alias>,
}

impl Author {
pub fn new(id: NodeId, aliases: &Aliases) -> Self {
let alias = aliases.alias(&id);

Author { id, alias }
}
}

0 comments on commit 7dbb705

Please sign in to comment.