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