diff --git a/Cargo.lock b/Cargo.lock index 4e2e12f24..4a57f1dfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1546,10 +1546,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "fastn-jdebug" -version = "0.1.0" - [[package]] name = "fastn-js" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index d9714808f..b340ddf2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ members = [ "fastn-ds", "fastn-expr", "fastn-issues", - "fastn-jdebug", "fastn-js", "fastn-lang", "fastn-package", diff --git a/fastn-jdebug/src/lib.rs b/fastn-jdebug/src/lib.rs deleted file mode 100644 index 73f78314b..000000000 --- a/fastn-jdebug/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub trait JDebug { - fn debug(&self, source: &str) -> serde_json::Value; -} diff --git a/v0.5/Cargo.lock b/v0.5/Cargo.lock index 14a815bce..a1b01354a 100644 --- a/v0.5/Cargo.lock +++ b/v0.5/Cargo.lock @@ -88,6 +88,13 @@ dependencies = [ "serde_json", ] +[[package]] +name = "fastn-jdebug" +version = "0.1.1" +dependencies = [ + "serde_json", +] + [[package]] name = "fastn-lang" version = "0.1.0" @@ -102,6 +109,7 @@ dependencies = [ name = "fastn-section" version = "0.1.0" dependencies = [ + "fastn-jdebug", "serde", "serde_json", ] @@ -123,6 +131,7 @@ dependencies = [ name = "fastn-unresolved" version = "0.1.0" dependencies = [ + "fastn-jdebug", "fastn-section", "fastn-type", "serde", diff --git a/v0.5/Cargo.toml b/v0.5/Cargo.toml index 77f7edc6c..0d8cc30f4 100644 --- a/v0.5/Cargo.toml +++ b/v0.5/Cargo.toml @@ -7,6 +7,7 @@ members = [ "fastn-static", "fastn-unresolved", "fastn-update", + "fastn-jdebug", ] exclude = [] resolver = "2" @@ -39,6 +40,7 @@ homepage = "https://fastn.com" fastn-lang = { path = "fastn-lang" } fastn-type = "0.1.1" +fastn-jdebug = { version = "0.1.0", path = "fastn-jdebug" } fastn-section = { path = "fastn-section" } fastn-static = { path = "fastn-static" } fastn-core = { path = "fastn-core" } diff --git a/fastn-jdebug/Cargo.toml b/v0.5/fastn-jdebug/Cargo.toml similarity index 92% rename from fastn-jdebug/Cargo.toml rename to v0.5/fastn-jdebug/Cargo.toml index 6741d789f..cc5e92e6a 100644 --- a/fastn-jdebug/Cargo.toml +++ b/v0.5/fastn-jdebug/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fastn-jdebug" -version = "0.1.0" +version = "0.1.1" authors.workspace = true edition.workspace = true description.workspace = true diff --git a/v0.5/fastn-jdebug/src/lib.rs b/v0.5/fastn-jdebug/src/lib.rs new file mode 100644 index 000000000..5d742694b --- /dev/null +++ b/v0.5/fastn-jdebug/src/lib.rs @@ -0,0 +1,36 @@ +#![allow(clippy::derive_partial_eq_without_eq, clippy::get_first)] +#![deny(unused_crate_dependencies)] +#![warn(clippy::used_underscore_binding)] + +extern crate self as fastn_jdebug; + +pub trait JDebug { + fn debug(&self, source: &str) -> serde_json::Value; +} + +impl fastn_jdebug::JDebug for Vec { + fn debug(&self, source: &str) -> serde_json::Value { + serde_json::Value::Array(self.iter().map(|v| v.debug(source)).collect()) + } +} + +impl fastn_jdebug::JDebug for Option { + fn debug(&self, source: &str) -> serde_json::Value { + self.as_ref() + .map(|v| v.debug(source)) + .unwrap_or(serde_json::Value::Null) + } +} + +impl>, V: fastn_jdebug::JDebug> fastn_jdebug::JDebug + for std::collections::HashMap +{ + fn debug(&self, source: &str) -> serde_json::Value { + let mut o = serde_json::Map::new(); + for (k, v) in self { + let r = k.as_ref(); + o.insert(source[r.start..r.end].to_string(), v.debug(source)); + } + serde_json::Value::Object(o) + } +} diff --git a/v0.5/fastn-section/Cargo.toml b/v0.5/fastn-section/Cargo.toml index 4eff273dd..a369ec24e 100644 --- a/v0.5/fastn-section/Cargo.toml +++ b/v0.5/fastn-section/Cargo.toml @@ -10,6 +10,9 @@ homepage.workspace = true [dependencies] serde.workspace = true + +[dev-dependencies] serde_json.workspace = true +fastn-jdebug.workspace = true diff --git a/v0.5/fastn-section/src/debug.rs b/v0.5/fastn-section/src/debug.rs index b6b052fa6..be4664bf2 100644 --- a/v0.5/fastn-section/src/debug.rs +++ b/v0.5/fastn-section/src/debug.rs @@ -1,62 +1,33 @@ -fn span(s: &fastn_section::Span, key: &str, source: &str) -> serde_json::Value { - serde_json::json!({ key: (source[s.start..s.end]).to_string()}) -} +// fn span(s: &fastn_section::Span, key: &str, source: &str) -> serde_json::Value { +// serde_json::json!({ key: (source[s.start..s.end]).to_string()}) +// } -impl fastn_section::JDebug for fastn_section::Span { +impl fastn_jdebug::JDebug for fastn_section::Span { fn debug(&self, source: &str) -> serde_json::Value { let t = &source[self.start..self.end]; if t.is_empty() { "" } else { t }.into() } } -impl fastn_section::JDebug for fastn_section::Spanned { +impl fastn_jdebug::JDebug for fastn_section::Spanned { fn debug(&self, source: &str) -> serde_json::Value { self.value.debug(source) } } -impl fastn_section::JDebug for fastn_section::Spanned<()> { - fn debug(&self, source: &str) -> serde_json::Value { - span(&self.span, "spanned", source) - } -} - -impl fastn_section::JDebug for Vec { - fn debug(&self, source: &str) -> serde_json::Value { - serde_json::Value::Array(self.iter().map(|v| v.debug(source)).collect()) - } -} - -impl fastn_section::JDebug - for std::collections::HashMap -{ - fn debug(&self, source: &str) -> serde_json::Value { - let mut o = serde_json::Map::new(); - for (k, v) in self { - o.insert( - source[k.name.start..k.name.end].to_string(), - v.debug(source), - ); - } - serde_json::Value::Object(o) - } -} - -impl fastn_section::JDebug for Option { - fn debug(&self, source: &str) -> serde_json::Value { - self.as_ref() - .map(|v| v.debug(source)) - .unwrap_or(serde_json::Value::Null) - } -} +// impl fastn_jdebug::JDebug for fastn_section::Spanned<()> { +// fn debug(&self, source: &str) -> serde_json::Value { +// span(&self.span, "spanned", source) +// } +// } -impl fastn_section::JDebug for fastn_section::Visibility { +impl fastn_jdebug::JDebug for fastn_section::Visibility { fn debug(&self, _source: &str) -> serde_json::Value { format!("{self:?}").into() } } -impl fastn_section::JDebug for fastn_section::Document { +impl fastn_jdebug::JDebug for fastn_section::Document { fn debug(&self, source: &str) -> serde_json::Value { let mut o = serde_json::Map::new(); if self.module_doc.is_some() { @@ -80,7 +51,7 @@ impl fastn_section::JDebug for fastn_section::Document { } } -impl fastn_section::JDebug for fastn_section::Section { +impl fastn_jdebug::JDebug for fastn_section::Section { fn debug(&self, source: &str) -> serde_json::Value { // todo: add headers etc (only if they are not null) let mut o = serde_json::Map::new(); @@ -94,13 +65,13 @@ impl fastn_section::JDebug for fastn_section::Section { } } -impl fastn_section::JDebug for fastn_section::SectionInit { +impl fastn_jdebug::JDebug for fastn_section::SectionInit { fn debug(&self, source: &str) -> serde_json::Value { self.name.debug(source) } } -impl fastn_section::JDebug for fastn_section::KindedName { +impl fastn_jdebug::JDebug for fastn_section::KindedName { fn debug(&self, source: &str) -> serde_json::Value { let mut o = serde_json::Map::new(); if let Some(kind) = &self.kind { @@ -111,7 +82,7 @@ impl fastn_section::JDebug for fastn_section::KindedName { } } -impl fastn_section::JDebug for fastn_section::Kind { +impl fastn_jdebug::JDebug for fastn_section::Kind { fn debug(&self, source: &str) -> serde_json::Value { if let Some(v) = self.to_identifier() { return v.debug(source); @@ -132,7 +103,7 @@ impl fastn_section::JDebug for fastn_section::Kind { } } -impl fastn_section::JDebug for fastn_section::QualifiedIdentifier { +impl fastn_jdebug::JDebug for fastn_section::QualifiedIdentifier { fn debug(&self, source: &str) -> serde_json::Value { if self.terms.is_empty() { return self.module.debug(source); @@ -145,13 +116,13 @@ impl fastn_section::JDebug for fastn_section::QualifiedIdentifier { } } -impl fastn_section::JDebug for fastn_section::HeaderValue { +impl fastn_jdebug::JDebug for fastn_section::HeaderValue { fn debug(&self, source: &str) -> serde_json::Value { self.0.debug(source) } } -impl fastn_section::JDebug for fastn_section::Tes { +impl fastn_jdebug::JDebug for fastn_section::Tes { fn debug(&self, source: &str) -> serde_json::Value { match self { fastn_section::Tes::Text(e) => e.debug(source), @@ -161,13 +132,13 @@ impl fastn_section::JDebug for fastn_section::Tes { } } -impl fastn_section::JDebug for fastn_section::Identifier { +impl fastn_jdebug::JDebug for fastn_section::Identifier { fn debug(&self, source: &str) -> serde_json::Value { self.name.debug(source) } } -impl fastn_section::JDebug for fastn_section::PackageName { +impl fastn_jdebug::JDebug for fastn_section::PackageName { fn debug(&self, source: &str) -> serde_json::Value { format!( "{} as {}", @@ -178,7 +149,7 @@ impl fastn_section::JDebug for fastn_section::PackageName { } } -impl fastn_section::JDebug for fastn_section::AliasableIdentifier { +impl fastn_jdebug::JDebug for fastn_section::AliasableIdentifier { fn debug(&self, source: &str) -> serde_json::Value { if self.alias.is_none() { return self.name.debug(source); @@ -191,7 +162,7 @@ impl fastn_section::JDebug for fastn_section::AliasableIdentifier { } } -impl fastn_section::JDebug for fastn_section::ModuleName { +impl fastn_jdebug::JDebug for fastn_section::ModuleName { fn debug(&self, source: &str) -> serde_json::Value { if self.path.is_empty() && self.name.alias.is_none() @@ -220,7 +191,7 @@ impl fastn_section::JDebug for fastn_section::ModuleName { } } -impl fastn_section::JDebug for fastn_section::Error { +impl fastn_jdebug::JDebug for fastn_section::Error { fn debug(&self, source: &str) -> serde_json::Value { error(self, &Default::default(), source) } diff --git a/v0.5/fastn-section/src/parser/mod.rs b/v0.5/fastn-section/src/parser/mod.rs index 1a28d3322..ce98c4b6b 100644 --- a/v0.5/fastn-section/src/parser/mod.rs +++ b/v0.5/fastn-section/src/parser/mod.rs @@ -49,7 +49,7 @@ pub fn document(scanner: &mut fastn_section::Scanner) { #[cfg(test)] #[track_caller] fn p< - T: fastn_section::JDebug, + T: fastn_jdebug::JDebug, F: FnOnce(&mut fastn_section::Scanner) -> T, >( source: &str, diff --git a/v0.5/fastn-unresolved/Cargo.toml b/v0.5/fastn-unresolved/Cargo.toml index 56a442633..36c2eb07e 100644 --- a/v0.5/fastn-unresolved/Cargo.toml +++ b/v0.5/fastn-unresolved/Cargo.toml @@ -14,4 +14,5 @@ serde.workspace = true fastn-type.workspace = true [dev-dependencies] -serde_json.workspace = true \ No newline at end of file +fastn-jdebug.workspace = true +serde_json.workspace = true diff --git a/v0.5/fastn-unresolved/src/debug.rs b/v0.5/fastn-unresolved/src/debug.rs index 0204a01dd..1a50d0426 100644 --- a/v0.5/fastn-unresolved/src/debug.rs +++ b/v0.5/fastn-unresolved/src/debug.rs @@ -1,6 +1,6 @@ use serde_json::Value; -impl fastn_section::JDebug for fastn_unresolved::Import { +impl fastn_jdebug::JDebug for fastn_unresolved::Import { fn debug(&self, source: &str) -> serde_json::Value { let mut o = serde_json::Map::new(); @@ -33,7 +33,7 @@ impl fastn_section::JDebug for fastn_unresolved::Import { } } -impl fastn_section::JDebug for fastn_unresolved::Export { +impl fastn_jdebug::JDebug for fastn_unresolved::Export { fn debug(&self, source: &str) -> serde_json::Value { match self { fastn_unresolved::Export::All => "all".into(), @@ -44,7 +44,7 @@ impl fastn_section::JDebug for fastn_unresolved::Export { } } -impl fastn_section::JDebug for fastn_unresolved::AliasableIdentifier { +impl fastn_jdebug::JDebug for fastn_unresolved::AliasableIdentifier { fn debug(&self, _source: &str) -> serde_json::Value { match self.alias { Some(ref v) => format!("{}=>{}", self.name.0, v.0), @@ -54,13 +54,13 @@ impl fastn_section::JDebug for fastn_unresolved::AliasableIdentifier { } } -impl fastn_section::JDebug for fastn_unresolved::ComponentInvocation { +impl fastn_jdebug::JDebug for fastn_unresolved::ComponentInvocation { fn debug(&self, _source: &str) -> Value { todo!() } } -impl fastn_section::JDebug +impl fastn_jdebug::JDebug for fastn_unresolved::UR { fn debug(&self, _source: &str) -> Value { diff --git a/v0.5/fastn-unresolved/src/parser/component_invocation.rs b/v0.5/fastn-unresolved/src/parser/component_invocation.rs index 153aea265..c26acfaac 100644 --- a/v0.5/fastn-unresolved/src/parser/component_invocation.rs +++ b/v0.5/fastn-unresolved/src/parser/component_invocation.rs @@ -30,7 +30,7 @@ mod tests { assert_eq!(d.content.len(), 1); assert_eq!( - fastn_section::JDebug::debug(&d.content.pop().unwrap(), source), + fastn_jdebug::JDebug::debug(&d.content.pop().unwrap(), source), expected ) } diff --git a/v0.5/fastn-unresolved/src/parser/import.rs b/v0.5/fastn-unresolved/src/parser/import.rs index a5353afa0..da478d11e 100644 --- a/v0.5/fastn-unresolved/src/parser/import.rs +++ b/v0.5/fastn-unresolved/src/parser/import.rs @@ -115,7 +115,7 @@ mod tests { assert_eq!(d.imports.len(), 1); assert_eq!( - fastn_section::JDebug::debug(&d.imports.pop().unwrap(), source), + fastn_jdebug::JDebug::debug(&d.imports.pop().unwrap(), source), expected ) }