use napi::bindgen_prelude::*;
use napi_derive::napi;
use tracing_subscriber::filter::LevelFilter;

mod author;
mod blob;
mod doc;
mod endpoint;
mod gossip;
mod key;
mod net;
mod node;
mod tag;
mod ticket;

pub use author::*;
pub use blob::*;
pub use doc::*;
pub use endpoint::*;
pub use gossip::*;
pub use key::*;
pub use net::*;
pub use node::*;
pub use tag::*;
pub use ticket::*;

/// The logging level. See the rust (log crate)[https://docs.rs/log] for more information.
#[derive(Debug)]
#[napi(string_enum)]
pub enum LogLevel {
    Trace,
    Debug,
    Info,
    Warn,
    Error,
    Off,
}

impl From<LogLevel> for LevelFilter {
    fn from(level: LogLevel) -> LevelFilter {
        match level {
            LogLevel::Trace => LevelFilter::TRACE,
            LogLevel::Debug => LevelFilter::DEBUG,
            LogLevel::Info => LevelFilter::INFO,
            LogLevel::Warn => LevelFilter::WARN,
            LogLevel::Error => LevelFilter::ERROR,
            LogLevel::Off => LevelFilter::OFF,
        }
    }
}

/// Set the logging level.
#[napi]
pub fn set_log_level(level: LogLevel) {
    use tracing_subscriber::{fmt, prelude::*, reload};
    let filter: LevelFilter = level.into();
    let (filter, _) = reload::Layer::new(filter);
    let mut layer = fmt::Layer::default();
    layer.set_ansi(false);
    tracing_subscriber::registry()
        .with(filter)
        .with(layer)
        .init();
}

/// Helper function that translates a key that was derived from the [`path_to_key`] function back
/// into a path.
///
/// If `prefix` exists, it will be stripped before converting back to a path
/// If `root` exists, will add the root as a parent to the created path
/// Removes any null byte that has been appened to the key
#[napi]
pub fn key_to_path(key: Vec<u8>, prefix: Option<String>, root: Option<String>) -> Result<String> {
    let path = iroh_blobs::util::fs::key_to_path(key, prefix, root.map(std::path::PathBuf::from))?;
    let path = path.to_str();
    let path = path.ok_or_else(|| anyhow::anyhow!("Unable to parse path {:?}", path))?;
    let path = path.to_string();

    Ok(path)
}

/// Helper function that creates a document key from a canonicalized path, removing the `root` and adding the `prefix`, if they exist
///
/// Appends the null byte to the end of the key.
#[napi]
pub fn path_to_key(path: String, prefix: Option<String>, root: Option<String>) -> Result<Vec<u8>> {
    let key = iroh_blobs::util::fs::path_to_key(
        std::path::PathBuf::from(path),
        prefix,
        root.map(std::path::PathBuf::from),
    )?;

    Ok(key.to_vec())
}

Synonyms

lens/src/lib.rs
bbg/src/lib.rs
strata/src/lib.rs
honeycrisp/src/lib.rs
optica/src/lib.rs
trident/src/lib.rs
zheng/src/lib.rs
nox/rs/lib.rs
lens/assayer/src/lib.rs
radio/iroh-dns-server/src/lib.rs
strata/kuro/rs/lib.rs
honeycrisp/rane/src/lib.rs
cyb/src-tauri/src/lib.rs
lens/binius/src/lib.rs
hemera/wgsl/src/lib.rs
strata/compute/src/lib.rs
honeycrisp/acpu/src/lib.rs
lens/core/src/lib.rs
radio/iroh-willow/src/lib.rs
strata/ext/src/lib.rs
honeycrisp/unimem/src/lib.rs
strata/nebu/rs/lib.rs
radio/cyber-bao/src/lib.rs
radio/iroh/src/lib.rs
hemera/rs/src/lib.rs
honeycrisp/aruminium/src/lib.rs
rs/macros/src/lib.rs
rs/core/src/lib.rs
radio/iroh-docs/src/lib.rs
rs/mir-format/src/lib.rs
lens/ikat/src/lib.rs
lens/brakedown/src/lib.rs
radio/iroh-gossip/src/lib.rs
strata/proof/src/lib.rs
radio/iroh-ffi/src/lib.rs
lens/porphyry/src/lib.rs
strata/core/src/lib.rs
radio/iroh-car/src/lib.rs
radio/iroh-blobs/src/lib.rs
radio/iroh-base/src/lib.rs
radio/iroh-relay/src/lib.rs
trident/editor/zed/src/lib.rs
rs/tests/macro-integration/src/lib.rs
cw-cyber/contracts/hub-protocols/src/lib.rs
radio/tests/integration/src/lib.rs
strata/trop/rs/src/lib.rs
cw-cyber/contracts/cw-cyber-passport/src/lib.rs
cw-cyber/contracts/std-test/src/lib.rs
cw-cyber/packages/cyber-std/src/lib.rs
cw-cyber/contracts/litium-wrap/src/lib.rs
strata/kuro/wgsl/src/lib.rs
cw-cyber/contracts/litium-refer/src/lib.rs
cw-cyber/contracts/litium-core/src/lib.rs
cw-cyber/contracts/hub-networks/src/lib.rs
radio/iroh/bench/src/lib.rs
cyb/cyb/cyb-services/src/lib.rs
cw-cyber/contracts/hub-tokens/src/lib.rs
cw-cyber/contracts/cw-cyber-gift/src/lib.rs
cw-cyber/contracts/litium-mine/src/lib.rs
strata/genies/wgsl/src/lib.rs
cw-cyber/packages/cyber-std-test/src/lib.rs
strata/jali/rs/src/lib.rs
cw-cyber/contracts/hub-channels/src/lib.rs
strata/jali/wgsl/src/lib.rs
cw-cyber/contracts/litium-stake/src/lib.rs
strata/nebu/wgsl/src/lib.rs
cw-cyber/contracts/cybernet/src/lib.rs
cw-cyber/contracts/cw-cyber-subgraph/src/lib.rs
cw-cyber/contracts/hub-skills/src/lib.rs
cw-cyber/packages/hub-base/src/lib.rs
strata/genies/rs/src/lib.rs
cw-cyber/contracts/hub-libs/src/lib.rs
strata/trop/wgsl/src/lib.rs
cw-cyber/contracts/graph-filter/src/lib.rs

Neighbours