Onset: version control where nobody waits and nothing gets lost. The on command, its core and onset-server.
| 6 | //! ```text |
| 7 | //! GET /me → Me |
| 8 | //! POST /projects {owner, name, public} → ProjectView |
| 9 | //! GET /projects/{o}/{n} → ProjectView |
| 10 | //! GET /projects/{o}/{n}/versions?since=N → {versions: [Version]} (n > N, ascending) |
| 11 | //! POST /projects/{o}/{n}/objects/missing ids (32 bytes each) → the ones the host lacks |
| 12 | //! POST /projects/{o}/{n}/objects bundle → {stored} |
| 13 | //! GET /projects/{o}/{n}/trees/{tree}?have=T bundle: everything under tree, minus what T shares |
| 14 | //! GET /projects/{o}/{n}/changes → {changes: [ChangeRecord]} (the ones you can see) |
| 15 | //! GET /projects/{o}/{n}/changes/{prefix} → {change: ChangeRecord, saves: [SaveRecord]} |
| 16 | //! PUT /projects/{o}/{n}/changes/{id} PutChange → {change} (409 held_elsewhere) |
| 17 | //! POST /projects/{o}/{n}/changes/{id}/hold Hold → {previous} |
| 18 | //! POST /projects/{o}/{n}/changes/{id}/saves SaveRecord + workspace → {} (409 held_elsewhere) |
| 19 | //! POST /projects/{o}/{n}/changes/{id}/access Share → {shared} |
| 20 | //! POST /projects/{o}/{n}/land LandRequest → Landed |
| 21 | //! GET /projects/{o}/{n}/rules → {rules: [Rule]} |
| 22 | //! PUT /projects/{o}/{n}/rules Rule → {rules} (owners) |
| 23 | //! GET /projects/{o}/{n}/mine → {files: [MineFile]} (your own) |
| 24 | //! PUT /projects/{o}/{n}/mine {files: [MineFile]} |
| 25 | //! GET /projects/{o}/{n}/mine/bundle bundle of your own files |
| 26 | //! ``` |
| 27 | //! |
| 28 | //! Errors: an HTTP status and `{"error": {"code", "message"}}`. |
| 29 |
| 30 | use serde::{Deserialize, Serialize}; |
| 31 | use vcs_core::Id; |
| 32 | use vcs_core::version::Version; |
| 33 |
| 34 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 35 | pub struct Me { |
| 36 | pub handle: String, |
| 37 | pub name: String, |
| 38 | pub email: String, |
| 39 | } |
| 40 |
| 41 | #[derive(Debug, Clone, Serialize, Deserialize, Default)] |
| 42 | pub struct Can { |
| 43 | pub read: bool, |
| 44 | pub land: bool, |
| 45 | pub admin: bool, |
| 46 | } |
| 47 |
| 48 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 49 | pub struct ProjectView { |
| 50 | pub owner: String, |
| 51 | pub name: String, |
| 52 | #[serde(default)] |
| 53 | pub public: bool, |
| 54 | pub main: Option<Version>, |
| 55 | pub can: Can, |
| 56 | /// Where git clients clone this project's git view, if it has one. |
| 57 | #[serde(default)] |
| 58 | pub git: Option<String>, |
| 59 | } |
| 60 |
| 61 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 62 | pub struct ChangeRecord { |
| 63 | pub id: String, |
| 64 | #[serde(default)] |
| 65 | pub title: String, |
| 66 | #[serde(default)] |
| 67 | pub body: String, |
| 68 | pub base_tree: Id, |
| 69 | #[serde(default)] |
| 70 | pub base_version: Option<u64>, |
| 71 | #[serde(default)] |
| 72 | pub on_change: Option<String>, |
| 73 | #[serde(default)] |
| 74 | pub after_change: Option<String>, |
| 75 | #[serde(default)] |
| 76 | pub head_tree: Option<Id>, |
| 77 | #[serde(default)] |
| 78 | pub saves: i64, |
| 79 | #[serde(default = "open")] |
| 80 | pub state: String, |
| 81 | #[serde(default)] |
| 82 | pub version: Option<u64>, |
| 83 | #[serde(default)] |
| 84 | pub author: String, |
| 85 | /// The account that owns it (set by the host). |
| 86 | #[serde(default)] |
| 87 | pub owner: String, |
| 88 | #[serde(default)] |
| 89 | pub shared: Vec<Share>, |
| 90 | /// Where it's being worked on ("laptop:~/shop"), set by the host. |
| 91 | #[serde(default)] |
| 92 | pub holder: Option<String>, |
| 93 | #[serde(default)] |
| 94 | pub updated: i64, |
| 95 | } |
| 96 |
| 97 | fn open() -> String { |
| 98 | "open".into() |
| 99 | } |
| 100 |
| 101 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 102 | pub struct Share { |
| 103 | pub who: String, |
| 104 | #[serde(default)] |
| 105 | pub edit: bool, |
| 106 | } |
| 107 |
| 108 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 109 | pub struct PutChange { |
| 110 | pub change: ChangeRecord, |
| 111 | pub workspace: String, |
| 112 | #[serde(default)] |
| 113 | pub label: String, |
| 114 | } |
| 115 |
| 116 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 117 | pub struct Hold { |
| 118 | pub workspace: String, |
| 119 | #[serde(default)] |
| 120 | pub label: String, |
| 121 | } |
| 122 |
| 123 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 124 | pub struct SaveRecord { |
| 125 | pub n: i64, |
| 126 | pub tree: Id, |
| 127 | pub base_tree: Id, |
| 128 | pub at: i64, |
| 129 | #[serde(default)] |
| 130 | pub workspace: String, |
| 131 | } |
| 132 |
| 133 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 134 | pub struct ShareRequest { |
| 135 | pub who: Vec<String>, |
| 136 | #[serde(default)] |
| 137 | pub edit: bool, |
| 138 | } |
| 139 |
| 140 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 141 | pub struct Rule { |
| 142 | pub path: String, |
| 143 | /// `@group`, `@person`, `team`, `everyone`. |
| 144 | pub who: Vec<String>, |
| 145 | } |
| 146 |
| 147 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 148 | pub struct MineFile { |
| 149 | pub path: String, |
| 150 | pub file: Id, |
| 151 | #[serde(default)] |
| 152 | pub exec: bool, |
| 153 | } |
| 154 |
| 155 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 156 | pub struct ErrorBody { |
| 157 | pub error: ErrorInfo, |
| 158 | } |
| 159 |
| 160 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 161 | pub struct ErrorInfo { |
| 162 | pub code: String, |
| 163 | pub message: String, |
| 164 | #[serde(default)] |
| 165 | pub holder: Option<String>, |
| 166 | } |
| 167 |
| 168 | /// Concatenated 32-byte IDs, the body of objects/missing. |
| 169 | pub fn encode_ids(ids: &[Id]) -> Vec<u8> { |
| 170 | ids.iter().flat_map(|i| i.0).collect() |
| 171 | } |
| 172 |
| 173 | pub fn decode_ids(bytes: &[u8]) -> Vec<Id> { |
| 174 | bytes.chunks_exact(32).filter_map(Id::from_slice).collect() |
| 175 | } |
| 176 |