peermerge/
options.rs

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