lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

lib.rs (1293B)


      1 pub use radroots_identity as upstream;
      2 
      3 use dto_bindgen_backend_ts::{TypeScriptDeclaration, TypeScriptModule, TypeScriptValue};
      4 use radroots_identity::username::{MAX_LENGTH, MIN_LENGTH};
      5 
      6 pub fn constants_module() -> TypeScriptModule {
      7     TypeScriptModule::new("src/generated/constants.ts")
      8         .with_declaration(TypeScriptDeclaration::constant(
      9             "RADROOTS_USERNAME_MIN_LENGTH",
     10             None,
     11             usize_value(MIN_LENGTH),
     12         ))
     13         .with_declaration(TypeScriptDeclaration::constant(
     14             "RADROOTS_USERNAME_MAX_LENGTH",
     15             None,
     16             usize_value(MAX_LENGTH),
     17         ))
     18 }
     19 
     20 fn usize_value(value: usize) -> TypeScriptValue {
     21     TypeScriptValue::number(i64::try_from(value).expect("TypeScript constant fits in i64"))
     22 }
     23 
     24 #[cfg(test)]
     25 mod tests {
     26     use super::{MAX_LENGTH, MIN_LENGTH, constants_module};
     27 
     28     #[test]
     29     fn preserves_username_constant_exports() {
     30         let rendered = constants_module().render_source();
     31         assert!(rendered.contains("RADROOTS_USERNAME_MIN_LENGTH"));
     32         assert!(rendered.contains(&MIN_LENGTH.to_string()));
     33         assert!(rendered.contains("RADROOTS_USERNAME_MAX_LENGTH"));
     34         assert!(rendered.contains(&MAX_LENGTH.to_string()));
     35         assert!(!rendered.contains("REGEX"));
     36     }
     37 }