spacetimedb/messages/
control_db.rs

1use spacetimedb_datastore::system_tables::ModuleKind;
2use spacetimedb_lib::Identity;
3use spacetimedb_sats::de::Deserialize;
4use spacetimedb_sats::hash::Hash;
5use spacetimedb_sats::ser::Serialize;
6
7#[derive(Clone, PartialEq, Serialize, Deserialize)]
8pub struct IdentityEmail {
9    pub identity: Identity,
10    pub email: String,
11}
12/// An energy balance (per identity).
13#[derive(Clone, PartialEq, Serialize, Deserialize)]
14pub struct EnergyBalance {
15    pub identity: Identity,
16    /// The balance for this identity this identity.
17    /// NOTE: This is a signed integer, because it is possible
18    /// for a user's balance to go negative. This is allowable
19    /// for reasons of eventual consistency motivated by performance.
20    pub balance: i128,
21}
22
23/// Description of a database.
24#[derive(Clone, PartialEq, Serialize, Deserialize)]
25pub struct Database {
26    /// Internal id of the database, assigned by the control database.
27    pub id: u64,
28    /// Public identity (i.e. [`Identity`]) of the database.
29    pub database_identity: Identity,
30    /// [`Identity`] of the database's owner.
31    pub owner_identity: Identity,
32    /// [`HostType`] of the module associated with the database.
33    ///
34    /// Valid only for as long as `initial_program` is valid.
35    pub host_type: HostType,
36    /// [`Hash`] of the compiled module to initialize the database with.
37    ///
38    /// Updating the database's module will **not** change this value.
39    pub initial_program: Hash,
40}
41
42#[derive(Clone, PartialEq, Serialize, Deserialize)]
43pub struct DatabaseStatus {
44    pub state: String,
45}
46#[derive(Clone, PartialEq, Serialize, Deserialize)]
47pub struct Replica {
48    pub id: u64,
49    pub database_id: u64,
50    pub node_id: u64,
51    pub leader: bool,
52}
53#[derive(Clone, PartialEq, Serialize, Deserialize)]
54pub struct ReplicaStatus {
55    pub state: String,
56}
57#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
58pub struct Node {
59    pub id: u64,
60    /// If `true`, no new user databases will be scheduled on this node.
61    pub unschedulable: bool,
62    /// The hostname this node is reachable at.
63    ///
64    /// If `None`, the node is not currently live.
65    pub advertise_addr: Option<String>,
66}
67#[derive(Clone, PartialEq, Serialize, Deserialize)]
68pub struct NodeStatus {
69    /// TODO: node memory, CPU, and storage capacity
70    /// TODO: node memory, CPU, and storage allocatable capacity
71    /// SEE: <https://kubernetes.io/docs/reference/kubernetes-api/cluster-resources/node-v1/#NodeStatus>
72    pub state: String,
73}
74#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
75#[repr(i32)]
76pub enum HostType {
77    Wasm = 0,
78    Js = 1,
79}
80
81impl From<crate::messages::control_db::HostType> for ModuleKind {
82    fn from(host_type: crate::messages::control_db::HostType) -> Self {
83        match host_type {
84            crate::messages::control_db::HostType::Wasm => Self::WASM,
85            crate::messages::control_db::HostType::Js => Self::JS,
86        }
87    }
88}