1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
use futures::channel::mpsc::UnboundedSender;
use std::collections::HashMap;
#[cfg(not(target_arch = "wasm32"))]
use std::path::PathBuf;
use crate::{
common::constants::{DEFAULT_MAX_ENTRY_DATA_SIZE_BYTES, DEFAULT_MAX_WRITE_FEED_LENGTH},
DocumentId, NameDescription, StateEvent,
};
/// In-memory Peermerge options
#[derive(Builder, Debug)]
pub struct PeermergeMemoryOptions {
/// Default peer name/description
pub default_peer_header: NameDescription,
/// State event sender, can also be given with
/// [set_state_event_sender()][crate::Peermerge::set_state_event_sender].
#[builder(setter(into, strip_option), default)]
pub state_event_sender: Option<UnboundedSender<StateEvent>>,
/// Reattach secrets used to prevent a new peer being when recreating an in-memory peer.
/// Value should be stored and updated from [crate::Peermerge::reattach_secret] whenever
/// a new [crate::StateEventContent::PeerChanged] is received.
#[builder(setter(into, strip_option), default)]
pub reattach_secrets: Option<HashMap<DocumentId, String>>,
/// Maximum size of a data entry. Defaults to [DEFAULT_MAX_ENTRY_DATA_SIZE_BYTES].
#[builder(default = "DEFAULT_MAX_ENTRY_DATA_SIZE_BYTES")]
pub max_entry_data_size_bytes: usize,
/// Maximum length of the write feed data entry. Defaults to [DEFAULT_MAX_WRITE_FEED_LENGTH].
#[builder(default = "DEFAULT_MAX_WRITE_FEED_LENGTH")]
pub max_write_feed_length: u64,
}
/// Disk Peermerge options
#[cfg(not(target_arch = "wasm32"))]
#[derive(Builder, Debug)]
pub struct PeermergeDiskOptions {
/// Root directory for all peermerge data. Sub-directories will
/// be created under this for each document.
pub data_root_dir: PathBuf,
/// Default peer name/description
pub default_peer_header: NameDescription,
/// State event sender, can also be given with
/// [set_state_event_sender()][crate::Peermerge::set_state_event_sender].
#[builder(setter(into, strip_option), default)]
pub state_event_sender: Option<UnboundedSender<StateEvent>>,
/// Maximum size of a data entry. Defaults to [DEFAULT_MAX_ENTRY_DATA_SIZE_BYTES].
#[builder(default = "DEFAULT_MAX_ENTRY_DATA_SIZE_BYTES")]
pub max_entry_data_size_bytes: usize,
/// Maximum length of the write feed data entry. Defaults to [DEFAULT_MAX_WRITE_FEED_LENGTH].
#[builder(default = "DEFAULT_MAX_WRITE_FEED_LENGTH")]
pub max_write_feed_length: u64,
}
/// Options for opening an existing peermerge
#[cfg(not(target_arch = "wasm32"))]
#[derive(Builder, Debug)]
pub struct OpenDiskOptions {
/// Root directory where to look for an existing peermerge
pub data_root_dir: PathBuf,
/// Document secrets needed to open parent documents. Use
/// [document_infos_disk()](crate::Peermerge::document_infos_disk)
/// to find out documents that need a document secret here.
#[builder(setter(into, strip_option), default)]
pub document_secrets: Option<HashMap<DocumentId, String>>,
/// State event sender, can also be given with
/// [set_state_event_sender()][crate::Peermerge::set_state_event_sender].
#[builder(setter(into, strip_option), default)]
pub state_event_sender: Option<UnboundedSender<StateEvent>>,
}
/// Options for creating new in-memory document.
#[derive(Builder, Debug)]
pub struct CreateNewDocumentMemoryOptions {
/// Mandatory type of document
pub document_type: String,
/// Optional document name/description
#[builder(setter(into, strip_option), default)]
pub document_header: Option<NameDescription>,
/// Parent ID of the document. If set, creates a child
/// document.
#[builder(setter(into, strip_option), default)]
pub parent_id: Option<DocumentId>,
/// Name and description of the parent as set for this
/// document. If None, sets the same values as the parent
/// has currently.
#[builder(setter(into, strip_option), default)]
pub parent_header: Option<NameDescription>,
/// If document is stored encrypted on all peers' feeds, defaults
/// to true. NB: Only if this is true, is it impossible for a proxy peer to
/// read the content of the document. Set this to false only if
/// you really know what you are doing.
#[builder(default = "true")]
pub encrypted: bool,
}
/// Options for creating new disk document.
#[cfg(not(target_arch = "wasm32"))]
#[derive(Builder, Debug)]
pub struct CreateNewDocumentDiskOptions {
/// Mandatory type of document
pub document_type: String,
/// Optional document name/description
#[builder(setter(into, strip_option), default)]
pub document_header: Option<NameDescription>,
/// Parent ID of the document. If set, creates a child
/// document.
#[builder(setter(into, strip_option), default)]
pub parent_id: Option<DocumentId>,
/// Name and description of the parent as set for this
/// document. If None, sets the same values as the parent
/// has currently.
#[builder(setter(into, strip_option), default)]
pub parent_header: Option<NameDescription>,
/// If document is stored encrypted on all peers' feeds, defaults
/// to true. NB: Only if this is true, is it impossible for a proxy peer to
/// read the content of the document. Set this to false only if
/// you really know what you are doing.
#[builder(default = "true")]
pub encrypted: bool,
}
/// Options for attaching an existing document to an in-memory Peermerge
#[derive(Builder, Debug)]
pub struct AttachDocumentMemoryOptions {
/// URL of the document. See [sharing_info()](crate::Peermerge::sharing_info).
pub document_url: String,
/// Document secret, if needed.
#[builder(setter(into, strip_option), default)]
pub document_secret: Option<String>,
/// Parent ID of the document. Needs to be set if attaching
/// a child document.
#[builder(setter(into, strip_option), default)]
pub parent_id: Option<DocumentId>,
/// Name and description of the parent as set for this
/// document. If None, sets the same values as the parent
/// has currently.
#[builder(setter(into, strip_option), default)]
pub parent_header: Option<NameDescription>,
}
/// Options for attaching an existing document to a disk Peermerge
#[cfg(not(target_arch = "wasm32"))]
#[derive(Builder, Debug)]
pub struct AttachDocumentDiskOptions {
/// URL of the document. See [sharing_info()](crate::Peermerge::sharing_info).
pub document_url: String,
/// Document secret, if needed.
#[builder(setter(into, strip_option), default)]
pub document_secret: Option<String>,
/// Parent ID of the document. Needs to be set if attaching
/// a child document.
#[builder(setter(into, strip_option), default)]
pub parent_id: Option<DocumentId>,
/// Name and description of the parent as set for this
/// document. If None, sets the same values as the parent
/// has currently.
#[builder(setter(into, strip_option), default)]
pub parent_header: Option<NameDescription>,
}