1010#include < unordered_set>
1111#include < vector>
1212
13+ #include " oxen/log.hpp"
1314#include " oxenc/hex.h"
1415#include " session/config/namespaces.hpp"
1516#include " session/config/profile_pic.hpp"
17+ #include " session/session_protocol.hpp"
1618#include " session/types.h"
1719#include " session/types.hpp"
1820#include " utilities.hpp"
@@ -21,6 +23,8 @@ namespace session::nodeapi {
2123
2224using namespace std ::literals;
2325
26+ inline auto cat = oxen::log::Cat(" nodeapi" );
27+
2428static void checkOrThrow (bool condition, const char * msg) {
2529 if (!condition)
2630 throw std::invalid_argument{msg};
@@ -119,6 +123,11 @@ struct toJs_impl<session::config::Namespace> {
119123 }
120124};
121125
126+ template <>
127+ struct toJs_impl <size_t > {
128+ auto operator ()(const Napi::Env& env, size_t b) const { return Napi::Number::New (env, (b)); }
129+ };
130+
122131template <typename T>
123132struct toJs_impl <T, std::enable_if_t <std::is_arithmetic_v<T>>> {
124133 auto operator ()(const Napi::Env& env, T n) const { return Napi::Number::New (env, n); }
@@ -294,7 +303,7 @@ auto wrapResult(const Napi::Env& env, Call&& call) {
294303 if constexpr (std::is_base_of_v<Napi::Value, Result>)
295304 return res;
296305 else
297- return toJs (env, std::move (res));
306+ return toJs<Result> (env, std::move (res));
298307 }
299308 } catch (const std::exception& e) {
300309 throw Napi::Error::New (env, e.what ());
@@ -362,6 +371,8 @@ Napi::Object decrypt_result_to_JS(
362371
363372confirm_pushed_entry_t confirm_pushed_entry_from_JS (const Napi::Env& env, const Napi::Object& obj);
364373
374+ Napi::Object proFeaturesToJs (const Napi::Env& env, const SESSION_PROTOCOL_PRO_FEATURES bitset);
375+
365376std::span<const uint8_t > from_hex_to_span (std::string_view x);
366377
367378template <std::size_t N>
@@ -371,11 +382,10 @@ template <std::size_t N>
371382std::array<uint8_t , N> from_hex_to_array (std::string x) {
372383 std::string as_hex = oxenc::from_hex (x);
373384 if (as_hex.size () != N) {
374- throw std::invalid_argument (
375- std::format (
376- " from_hex_to_array: Decoded hex size mismatch: expected {}, got {}" ,
377- N,
378- as_hex.size ()));
385+ throw std::invalid_argument (std::format (
386+ " from_hex_to_array: Decoded hex size mismatch: expected {}, got {}" ,
387+ N,
388+ as_hex.size ()));
379389 }
380390
381391 std::array<uint8_t , N> result;
@@ -386,21 +396,21 @@ std::array<uint8_t, N> from_hex_to_array(std::string x) {
386396std::vector<unsigned char > from_hex_to_vector (std::string_view x);
387397
388398std::span<const uint8_t > from_base64_to_span (std::string_view x);
389- std::vector<unsigned char > from_base64_to_vector (std::string_view x) ;
390-
399+ std::vector<unsigned char > from_base64_to_vector (std::string_view x);
391400
392401// Concept to match containers with a size() method
393402template <typename T>
394403concept HasSize = requires (T t) {
395- {t.size ()}->std ::convertible_to<size_t >;
404+ {
405+ t.size ()
406+ } -> std::convertible_to<size_t >;
396407};
397408
398409template <HasSize T>
399410void assert_length (const T& x, size_t n, std::string_view base_identifier) {
400411 if (x.size () != n) {
401- throw std::invalid_argument (
402- std::format (
403- " assert_length: expected {}, got {} for {}" , n, x.size (), base_identifier));
412+ throw std::invalid_argument (std::format (
413+ " assert_length: expected {}, got {} for {}" , n, x.size (), base_identifier));
404414 }
405415}
406416
0 commit comments