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 | //! POST /projects/{o}/{n}/import {versions} → {main} (owners, empty projects) |
| 22 | //! POST /projects/{o}/{n}/git/ids {ids: {native: git}} (owners; after an import) |
| 23 | //! POST /projects/{o}/{n}/git/resume → {adopted} (owners; restarts a paused git view) |
| 24 | //! GET /projects/{o}/{n}/rules → {rules: [Rule]} |
| 25 | //! PUT /projects/{o}/{n}/rules Rule → {rules} (owners) |
| 26 | //! GET /projects/{o}/{n}/mine → {files: [MineFile]} (your own) |
| 27 | //! PUT /projects/{o}/{n}/mine {files: [MineFile]} |
| 28 | //! GET /projects/{o}/{n}/mine/bundle bundle of your own files |
| 29 | //! ``` |
| 30 | //! |
| 31 | //! Errors: an HTTP status and `{"error": {"code", "message"}}`. |
| 32 |
| 33 | use serde::{Deserialize, Serialize}; |
| 34 | use vcs_core::Id; |
| 35 | use vcs_core::version::Version; |
| 36 |
| 37 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 38 | pub struct Me { |
| 39 | pub handle: String, |
| 40 | pub name: String, |
| 41 | pub email: String, |
| 42 | } |
| 43 |
| 44 | #[derive(Debug, Clone, Serialize, Deserialize, Default)] |
| 45 | pub struct Can { |
| 46 | pub read: bool, |
| 47 | pub land: bool, |
| 48 | pub admin: bool, |
| 49 | } |
| 50 |
| 51 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 52 | pub struct ProjectView { |
| 53 | pub owner: String, |
| 54 | pub name: String, |
| 55 | #[serde(default)] |
| 56 | pub public: bool, |
| 57 | pub main: Option<Version>, |
| 58 | pub can: Can, |
| 59 | /// Where git clients clone this project's git view, if it has one. |
| 60 | #[serde(default)] |
| 61 | pub git: Option<String>, |
| 62 | /// Why the git view stopped taking new versions, if it did. |
| 63 | #[serde(default)] |
| 64 | pub git_stopped: Option<String>, |
| 65 | } |
| 66 |
| 67 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 68 | pub struct ChangeRecord { |
| 69 | pub id: String, |
| 70 | #[serde(default)] |
| 71 | pub title: String, |
| 72 | #[serde(default)] |
| 73 | pub body: String, |
| 74 | pub base_tree: Id, |
| 75 | #[serde(default)] |
| 76 | pub base_version: Option<u64>, |
| 77 | #[serde(default)] |
| 78 | pub on_change: Option<String>, |
| 79 | #[serde(default)] |
| 80 | pub after_change: Option<String>, |
| 81 | #[serde(default)] |
| 82 | pub head_tree: Option<Id>, |
| 83 | #[serde(default)] |
| 84 | pub saves: i64, |
| 85 | #[serde(default = "open")] |
| 86 | pub state: String, |
| 87 | #[serde(default)] |
| 88 | pub version: Option<u64>, |
| 89 | #[serde(default)] |
| 90 | pub author: String, |
| 91 | /// The account that owns it (set by the host). |
| 92 | #[serde(default)] |
| 93 | pub owner: String, |
| 94 | #[serde(default)] |
| 95 | pub shared: Vec<Share>, |
| 96 | /// Where it's being worked on ("laptop:~/shop"), set by the host. |
| 97 | #[serde(default)] |
| 98 | pub holder: Option<String>, |
| 99 | #[serde(default)] |
| 100 | pub updated: i64, |
| 101 | } |
| 102 |
| 103 | fn open() -> String { |
| 104 | "open".into() |
| 105 | } |
| 106 |
| 107 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 108 | pub struct Share { |
| 109 | pub who: String, |
| 110 | #[serde(default)] |
| 111 | pub edit: bool, |
| 112 | } |
| 113 |
| 114 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 115 | pub struct PutChange { |
| 116 | pub change: ChangeRecord, |
| 117 | pub workspace: String, |
| 118 | #[serde(default)] |
| 119 | pub label: String, |
| 120 | } |
| 121 |
| 122 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 123 | pub struct Hold { |
| 124 | pub workspace: String, |
| 125 | #[serde(default)] |
| 126 | pub label: String, |
| 127 | } |
| 128 |
| 129 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 130 | pub struct SaveRecord { |
| 131 | pub n: i64, |
| 132 | pub tree: Id, |
| 133 | pub base_tree: Id, |
| 134 | pub at: i64, |
| 135 | #[serde(default)] |
| 136 | pub workspace: String, |
| 137 | } |
| 138 |
| 139 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 140 | pub struct ShareRequest { |
| 141 | pub who: Vec<String>, |
| 142 | #[serde(default)] |
| 143 | pub edit: bool, |
| 144 | } |
| 145 |
| 146 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 147 | pub struct Rule { |
| 148 | pub path: String, |
| 149 | /// `@group`, `@person`, `team`, `everyone`. |
| 150 | pub who: Vec<String>, |
| 151 | } |
| 152 |
| 153 | #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 154 | pub struct MineFile { |
| 155 | pub path: String, |
| 156 | pub file: Id, |
| 157 | #[serde(default)] |
| 158 | pub exec: bool, |
| 159 | } |
| 160 |
| 161 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 162 | pub struct ErrorBody { |
| 163 | pub error: ErrorInfo, |
| 164 | } |
| 165 |
| 166 | #[derive(Debug, Clone, Serialize, Deserialize)] |
| 167 | pub struct ErrorInfo { |
| 168 | pub code: String, |
| 169 | pub message: String, |
| 170 | #[serde(default)] |
| 171 | pub holder: Option<String>, |
| 172 | } |
| 173 |
| 174 | /// Concatenated 32-byte IDs, the body of objects/missing. |
| 175 | pub fn encode_ids(ids: &[Id]) -> Vec<u8> { |
| 176 | ids.iter().flat_map(|i| i.0).collect() |
| 177 | } |
| 178 |
| 179 | pub fn decode_ids(bytes: &[u8]) -> Vec<Id> { |
| 180 | bytes.chunks_exact(32).filter_map(Id::from_slice).collect() |
| 181 | } |
| 182 |