-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
NodeInfo
, RepositoryInfo
and Author
types
- Loading branch information
1 parent
98eca7e
commit 7dbb705
Showing
5 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
# will have compiled files and executables | ||
/target/ | ||
/gen/schemas | ||
|
||
# Generated by ts-rs | ||
/bindings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; }, }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |