1use std::collections::HashMap;
2
3use leaf_protocol::types::{
4 ComponentData, Digest, Entity, EntityPath, ExactLink, NamespaceId, NamespaceSecretKey,
5 SubspaceId, SubspaceSecretKey,
6};
7
8#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug)]
9pub struct Req {
10 pub id: u64,
11 pub kind: ReqKind,
12}
13
14#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
15pub struct Resp {
16 pub id: u64,
17 pub result: Result<RespKind, String>,
18}
19
20#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug)]
21pub enum ReqKind {
22 Authenticate(String),
23 ReadEntity(ExactLink),
24 DelEntity(ExactLink),
25 GetComponentsBySchema {
26 link: ExactLink,
27 schemas: Vec<Digest>,
28 },
29 DelComponentsBySchema {
30 link: ExactLink,
31 schemas: Vec<Digest>,
32 },
33 AddComponents {
37 link: ExactLink,
39 components: Vec<ComponentData>,
41 replace_existing: bool,
44 },
45 ListEntities(ExactLink),
46 CreateNamespace,
47 ImportNamespaceSecret(NamespaceSecretKey),
48 GetNamespaceSecret(NamespaceId),
49 CreateSubspace,
50 ImportSubspaceSecret(SubspaceSecretKey),
51 GetSubspaceSecret(SubspaceId),
52 GetLocalSecret(String),
53 SetLocalSecret(String, Option<String>),
54 ListLocalSecrets,
55 CreateDatabaseDump,
56 RestoreDatabaseDump(DatabaseDump),
57 ListNamespaces,
58 ListSubspaces,
59}
60
61#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
62pub struct GetComponentsInner {
63 pub entity_digest: Digest,
64 pub components: HashMap<Digest, Vec<Vec<u8>>>,
65}
66
67#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug)]
68pub enum RespKind {
69 Authenticated,
70 ReadEntity(Option<(Digest, Entity)>),
71 DelEntity,
72 GetComponentBySchema(Option<GetComponentsInner>),
73 DelComponentBySchema(Option<Digest>),
74 AddComponents(Digest),
75 ListEntities(Vec<ExactLink>),
76 CreateNamespace(NamespaceId),
77 ImportNamespaceSecret(NamespaceId),
78 GetNamespaceSecret(Option<NamespaceSecretKey>),
79 CreateSubspace(SubspaceId),
80 ImportSubspaceSecret(SubspaceId),
81 GetSubspaceSecret(Option<SubspaceSecretKey>),
82 GetLocalSecret(Option<String>),
83 SetLocalSecret,
84 ListLocalSecrets(HashMap<String, String>),
85 CreateDatabaseDump(DatabaseDump),
86 RestoreDatabaseDump,
87 ListNamespaces(Vec<NamespaceId>),
88 ListSubspaces(Vec<SubspaceId>),
89}
90
91#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug, Default)]
92pub struct DatabaseDump {
93 pub documents: HashMap<NamespaceId, DatabaseDumpDocument>,
94 pub subspace_secrets: HashMap<SubspaceId, SubspaceSecretKey>,
95}
96
97#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug, Default)]
98pub struct DatabaseDumpDocument {
99 pub secret: NamespaceSecretKey,
100 pub subspaces: HashMap<SubspaceId, DatabaseDumpSubspace>,
101}
102
103pub type DatabaseDumpSubspace = HashMap<EntityPath, DatabaseDumpEntity>;
104
105pub type SchemaId = Digest;
106
107#[derive(borsh::BorshSerialize, borsh::BorshDeserialize, Debug, Default)]
108pub struct DatabaseDumpEntity {
109 pub digest: Digest,
110 pub components: HashMap<SchemaId, Vec<Vec<u8>>>,
111}