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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Copyright (c) 2022-2024 Niko Bonnieure, Par le Peuple, NextGraph.org developers
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0>
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>,
// at your option. All files in the project carrying such
// notice may not be copied, modified, or distributed except
// according to those terms.

pub mod types;

pub mod block_storage;

pub mod block;

pub mod object;

pub mod file;

pub mod commit;

pub mod branch;

pub mod repo;

pub mod store;

pub mod event;

pub mod utils;

pub mod errors;

pub mod kcv_storage;

pub mod os_info;

#[macro_use]
extern crate slice_as_array;

pub mod log {

    #[cfg(not(target_arch = "wasm32"))]
    pub use debug_print::debug_println;
    #[cfg(target_arch = "wasm32")]
    pub use gloo_timers;
    #[cfg(not(target_arch = "wasm32"))]
    pub use log;

    #[cfg(target_arch = "wasm32")]
    use wasm_bindgen::prelude::*;

    #[cfg(target_arch = "wasm32")]
    #[wasm_bindgen]
    extern "C" {
        // Use `js_namespace` here to bind `console.log(..)` instead of just
        // `log(..)`
        #[wasm_bindgen(js_namespace = console)]
        pub fn log(s: &str);

        #[wasm_bindgen(js_namespace = console)]
        pub fn warn(s: &str);

        #[wasm_bindgen(js_namespace = console)]
        pub fn error(s: &str);

        // The `console.log` is quite polymorphic, so we can bind it with multiple
        // signatures. Note that we need to use `js_name` to ensure we always call
        // `log` in JS.
        #[wasm_bindgen(js_namespace = console, js_name = log)]
        fn log_u32(a: u32);

        // Multiple arguments too!
        #[wasm_bindgen(js_namespace = console, js_name = log)]
        fn log_many(a: &str, b: &str);
    }

    #[cfg(all(not(feature = "server_log_output"), not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_info {
    ($($t:tt)*) => (println!("INFO:{}",format!($($t)*)))
}

    #[cfg(all(not(feature = "server_log_output"), not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_err {
    ($($t:tt)*) => (println!("ERR:{}",format!($($t)*)))
}

    #[cfg(all(not(feature = "server_log_output"), not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_warn {
    ($($t:tt)*) => (println!("WARN:{}",format!($($t)*)))
}

    #[cfg(all(not(feature = "server_log_output"), not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_debug {
    ($($t:tt)*) => (debug_println!("DEBUG:{}",format!($($t)*)))
}

    #[cfg(all(not(feature = "server_log_output"), not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_trace {
    ($($t:tt)*) => (debug_println!("TRACE:{}",format!($($t)*)))
}

    #[cfg(all(feature = "server_log_output", not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_info {
    ($($t:tt)*) => (log::info!($($t)*))
}

    #[cfg(all(feature = "server_log_output", not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_err {
    ($($t:tt)*) => (log::error!($($t)*))
}

    #[cfg(all(feature = "server_log_output", not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_warn {
    ($($t:tt)*) => (log::warn!($($t)*))
}

    #[cfg(all(feature = "server_log_output", not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_debug {
    ($($t:tt)*) => (log::debug!($($t)*))
}

    #[cfg(all(feature = "server_log_output", not(target_arch = "wasm32")))]
    #[macro_export]
    macro_rules! log_trace {
    ($($t:tt)*) => (log::trace!($($t)*))
}

    #[cfg(target_arch = "wasm32")]
    #[macro_export]
    macro_rules! log_info {
    ($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}

    #[cfg(target_arch = "wasm32")]
    #[macro_export]
    macro_rules! log_err {
    ($($t:tt)*) => (error(&format_args!($($t)*).to_string()))
}

    #[cfg(target_arch = "wasm32")]
    #[macro_export]
    macro_rules! log_warn {
    ($($t:tt)*) => (warn(&format_args!($($t)*).to_string()))
}

    #[cfg(all(debug_assertions, target_arch = "wasm32"))]
    #[macro_export]
    macro_rules! log_debug {
    ($($t:tt)*) => (log(&format!("DEBUG:{}",&format_args!($($t)*).to_string()).to_string()))
}

    #[cfg(all(debug_assertions, target_arch = "wasm32"))]
    #[macro_export]
    macro_rules! log_trace {
    ($($t:tt)*) => (log(&format!("TRACE:{}",&format_args!($($t)*).to_string()).to_string()))
}

    #[cfg(all(not(debug_assertions), target_arch = "wasm32"))]
    #[macro_export]
    macro_rules! log_debug {
        ($($t:tt)*) => {};
    }

    #[cfg(all(not(debug_assertions), target_arch = "wasm32"))]
    #[macro_export]
    macro_rules! log_trace {
        ($($t:tt)*) => {};
    }

    #[cfg(target_arch = "wasm32")]
    #[macro_export]
    macro_rules! sleep {
    ($($t:tt)*) => (gloo_timers::future::sleep($($t)*).await)
}

    #[cfg(not(target_arch = "wasm32"))]
    #[macro_export]
    macro_rules! sleep {
    ($($t:tt)*) => (std::thread::sleep($($t)*))
}

    pub use log_debug;
    pub use log_err;
    pub use log_info;
    pub use log_trace;
    pub use log_warn;
    pub use sleep;
}