Highly ambitious ATProtocol AppView service and sdks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

dont include wasm libraries by default

+89 -85
+2 -16
api/Cargo.lock
··· 450 450 ] 451 451 452 452 [[package]] 453 - name = "console_error_panic_hook" 454 - version = "0.1.7" 455 - source = "registry+https://github.com/rust-lang/crates.io-index" 456 - checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" 457 - dependencies = [ 458 - "cfg-if", 459 - "wasm-bindgen", 460 - ] 461 - 462 - [[package]] 463 453 name = "const-oid" 464 454 version = "0.9.6" 465 455 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2669 2659 2670 2660 [[package]] 2671 2661 name = "slices-lexicon" 2672 - version = "0.1.2" 2662 + version = "0.1.3" 2673 2663 source = "registry+https://github.com/rust-lang/crates.io-index" 2674 - checksum = "b1be2a285e7cd61e0f18ac07a3d8f59c6fd7655ab45890497729c5c7f5722be1" 2664 + checksum = "b7324c3cd736ff0799b7bb47ffc6e45b476a0ec79c8fb99fdbeaac9cb91a7a31" 2675 2665 dependencies = [ 2676 2666 "chrono", 2677 - "console_error_panic_hook", 2678 - "js-sys", 2679 2667 "regex", 2680 2668 "serde", 2681 2669 "serde_json", 2682 2670 "thiserror 2.0.14", 2683 - "wasm-bindgen", 2684 - "web-sys", 2685 2671 ] 2686 2672 2687 2673 [[package]]
+1 -1
api/Cargo.toml
··· 15 15 serde_json = "1.0" 16 16 17 17 # Lexicon validation 18 - slices-lexicon = "0.1.2" 18 + slices-lexicon = "0.1.3" 19 19 20 20 # HTTP client and server 21 21 reqwest = { version = "0.12", features = ["json", "stream"] }
+1 -1
packages/lexicon-rs/Cargo.lock
··· 267 267 268 268 [[package]] 269 269 name = "slices-lexicon" 270 - version = "0.1.2" 270 + version = "0.1.3" 271 271 dependencies = [ 272 272 "chrono", 273 273 "console_error_panic_hook",
+9 -7
packages/lexicon-rs/Cargo.toml
··· 1 1 [package] 2 2 name = "slices-lexicon" 3 - version = "0.1.2" 3 + version = "0.1.3" 4 4 edition = "2021" 5 5 description = "AT Protocol lexicon validation library for Slices" 6 6 license = "MIT" ··· 26 26 # Regex for string format validation 27 27 regex = "1.0" 28 28 29 - # WASM bindings 30 - wasm-bindgen = "0.2" 29 + # WASM bindings (optional) 30 + wasm-bindgen = { version = "0.2", optional = true } 31 31 32 - # JavaScript interop types 33 - js-sys = "0.3" 32 + # JavaScript interop types (optional) 33 + js-sys = { version = "0.3", optional = true } 34 34 35 - # Console logging for WASM 35 + # Console logging for WASM (optional) 36 36 console_error_panic_hook = { version = "0.1", optional = true } 37 37 38 38 [dependencies.web-sys] ··· 40 40 features = [ 41 41 "console", 42 42 ] 43 + optional = true 43 44 44 45 [features] 45 - default = ["console_error_panic_hook"] 46 + default = [] 47 + wasm = ["wasm-bindgen", "js-sys", "web-sys", "console_error_panic_hook"] 46 48 console_error_panic_hook = ["dep:console_error_panic_hook"] 47 49 48 50 [package.metadata.wasm-pack.profile.release]
+76 -60
packages/lexicon-rs/src/lib.rs
··· 1 - use wasm_bindgen::prelude::*; 2 - use serde_json::Value; 3 - 4 1 pub mod errors; 5 2 pub mod types; 6 3 pub mod validator; ··· 9 6 pub use types::{LexiconDoc, StringFormat, ValidationContext}; 10 7 pub use validator::LexiconValidator; 11 8 12 - // When the `console_error_panic_hook` feature is enabled, we can call the 13 - // `set_panic_hook` function at least once during initialization, and then 14 - // we will get better error messages if our code ever panics. 15 - // 16 - // For more details see 17 - // https://github.com/rustwasm/console_error_panic_hook#readme 18 - #[cfg(feature = "console_error_panic_hook")] 19 - #[wasm_bindgen(start)] 20 - pub fn main() { 21 - console_error_panic_hook::set_once(); 22 - } 9 + // WASM-specific code - only compiled when the wasm feature is enabled 10 + #[cfg(feature = "wasm")] 11 + mod wasm_bindings { 12 + use wasm_bindgen::prelude::*; 13 + use serde_json::Value; 14 + use super::*; 23 15 24 - // WASM-exposed LexiconValidator wrapper 25 - #[wasm_bindgen] 26 - pub struct WasmLexiconValidator { 27 - inner: LexiconValidator, 28 - } 16 + // When the `console_error_panic_hook` feature is enabled, we can call the 17 + // `set_panic_hook` function at least once during initialization, and then 18 + // we will get better error messages if our code ever panics. 19 + // 20 + // For more details see 21 + // https://github.com/rustwasm/console_error_panic_hook#readme 22 + #[cfg(feature = "console_error_panic_hook")] 23 + #[wasm_bindgen(start)] 24 + pub fn main() { 25 + console_error_panic_hook::set_once(); 26 + } 29 27 30 - #[wasm_bindgen] 31 - impl WasmLexiconValidator { 32 - /// Create a new validator with the given lexicon documents 33 - /// Takes a JSON string containing an array of lexicon documents 34 - #[wasm_bindgen(constructor)] 35 - pub fn new(lexicons_json: &str) -> Result<WasmLexiconValidator, JsValue> { 36 - let lexicons: Vec<Value> = serde_json::from_str(lexicons_json) 37 - .map_err(|e| JsValue::from_str(&format!("Failed to parse lexicons JSON: {}", e)))?; 28 + // WASM-exposed LexiconValidator wrapper 29 + #[wasm_bindgen] 30 + pub struct WasmLexiconValidator { 31 + inner: LexiconValidator, 32 + } 38 33 39 - let validator = LexiconValidator::new(lexicons) 40 - .map_err(|e| JsValue::from_str(&format!("Failed to create validator: {}", e)))?; 34 + #[wasm_bindgen] 35 + impl WasmLexiconValidator { 36 + /// Create a new validator with the given lexicon documents 37 + /// Takes a JSON string containing an array of lexicon documents 38 + #[wasm_bindgen(constructor)] 39 + pub fn new(lexicons_json: &str) -> Result<WasmLexiconValidator, JsValue> { 40 + let lexicons: Vec<Value> = serde_json::from_str(lexicons_json) 41 + .map_err(|e| JsValue::from_str(&format!("Failed to parse lexicons JSON: {}", e)))?; 41 42 42 - Ok(WasmLexiconValidator { inner: validator }) 43 + let validator = LexiconValidator::new(lexicons) 44 + .map_err(|e| JsValue::from_str(&format!("Failed to create validator: {}", e)))?; 45 + 46 + Ok(WasmLexiconValidator { inner: validator }) 47 + } 48 + 49 + /// Validate a record against its collection's lexicon 50 + /// Takes collection name and record as JSON strings 51 + #[wasm_bindgen] 52 + pub fn validate_record(&self, collection: &str, record_json: &str) -> Result<(), JsValue> { 53 + let record: Value = serde_json::from_str(record_json) 54 + .map_err(|e| JsValue::from_str(&format!("Failed to parse record JSON: {}", e)))?; 55 + 56 + self.inner 57 + .validate_record(collection, &record) 58 + .map_err(|e| JsValue::from_str(&format!("Validation failed: {}", e))) 59 + } 60 + 61 + /// Validate that all cross-lexicon references can be resolved 62 + #[wasm_bindgen] 63 + pub fn validate_lexicon_set_completeness(&self) -> Result<(), JsValue> { 64 + self.inner 65 + .validate_lexicon_set_completeness() 66 + .map_err(|e| JsValue::from_str(&format!("Lexicon set validation failed: {}", e))) 67 + } 43 68 } 44 69 45 - /// Validate a record against its collection's lexicon 46 - /// Takes collection name and record as JSON strings 70 + // Export individual validation functions for more granular use 47 71 #[wasm_bindgen] 48 - pub fn validate_record(&self, collection: &str, record_json: &str) -> Result<(), JsValue> { 49 - let record: Value = serde_json::from_str(record_json) 50 - .map_err(|e| JsValue::from_str(&format!("Failed to parse record JSON: {}", e)))?; 72 + pub fn validate_string_format(value: &str, format: &str) -> Result<(), JsValue> { 73 + let format_enum = StringFormat::from_str(format) 74 + .ok_or_else(|| JsValue::from_str(&format!("Unknown format: {}", format)))?; 75 + 76 + // Create a minimal validator for string format validation 77 + let validator = LexiconValidator::new(vec![]) 78 + .map_err(|e| JsValue::from_str(&format!("Failed to create validator: {}", e)))?; 51 79 52 - self.inner 53 - .validate_record(collection, &record) 54 - .map_err(|e| JsValue::from_str(&format!("Validation failed: {}", e))) 80 + let ctx = ValidationContext::new(); 81 + validator 82 + .validate_string_format(value, format_enum, &ctx) 83 + .map_err(|e| JsValue::from_str(&format!("String format validation failed: {}", e))) 55 84 } 56 85 57 - /// Validate that all cross-lexicon references can be resolved 86 + // Utility function to check if a string is a valid lexicon ID 58 87 #[wasm_bindgen] 59 - pub fn validate_lexicon_set_completeness(&self) -> Result<(), JsValue> { 60 - self.inner 61 - .validate_lexicon_set_completeness() 62 - .map_err(|e| JsValue::from_str(&format!("Lexicon set validation failed: {}", e))) 88 + pub fn is_valid_nsid(nsid: &str) -> bool { 89 + use regex::Regex; 90 + let nsid_regex = Regex::new(r"^[a-zA-Z]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$").unwrap(); 91 + nsid_regex.is_match(nsid) 63 92 } 64 93 } 65 94 66 - // Export individual validation functions for more granular use 67 - #[wasm_bindgen] 68 - pub fn validate_string_format(value: &str, format: &str) -> Result<(), JsValue> { 69 - let format_enum = StringFormat::from_str(format) 70 - .ok_or_else(|| JsValue::from_str(&format!("Unknown format: {}", format)))?; 95 + // Re-export WASM bindings when the feature is enabled 96 + #[cfg(feature = "wasm")] 97 + pub use wasm_bindings::*; 71 98 72 - // Create a minimal validator for string format validation 73 - let validator = LexiconValidator::new(vec![]) 74 - .map_err(|e| JsValue::from_str(&format!("Failed to create validator: {}", e)))?; 75 - 76 - let ctx = ValidationContext::new(); 77 - validator 78 - .validate_string_format(value, format_enum, &ctx) 79 - .map_err(|e| JsValue::from_str(&format!("String format validation failed: {}", e))) 80 - } 81 - 82 - // Utility function to check if a string is a valid lexicon ID 83 - #[wasm_bindgen] 99 + // Non-WASM utility functions that are always available 84 100 pub fn is_valid_nsid(nsid: &str) -> bool { 85 101 use regex::Regex; 86 102 let nsid_regex = Regex::new(r"^[a-zA-Z]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$").unwrap();