A better Rust ATProto crate

codegen fixes

Orual ce692323 1f831994

Changed files
+22 -14
crates
jacquard-lexicon
+7 -5
Cargo.lock
··· 2290 2290 [[package]] 2291 2291 name = "jacquard-api" 2292 2292 version = "0.8.0" 2293 - source = "git+https://tangled.org/@nonbinary.computer/jacquard#1c7fc38baf8f100875ba178c19a255e34727b116" 2293 + source = "git+https://tangled.org/@nonbinary.computer/jacquard#1f831994b95d87fe938d4e7b2213e44bbd18e2bd" 2294 2294 dependencies = [ 2295 2295 "bon", 2296 2296 "bytes", 2297 2297 "jacquard-common 0.8.0 (git+https://tangled.org/@nonbinary.computer/jacquard)", 2298 2298 "jacquard-derive 0.8.0 (git+https://tangled.org/@nonbinary.computer/jacquard)", 2299 + "jacquard-lexicon 0.8.0 (git+https://tangled.org/@nonbinary.computer/jacquard)", 2299 2300 "miette", 2300 2301 "serde", 2301 2302 "serde_ipld_dagcbor", 2302 2303 "thiserror 2.0.17", 2304 + "unicode-segmentation", 2303 2305 ] 2304 2306 2305 2307 [[package]] ··· 2380 2382 [[package]] 2381 2383 name = "jacquard-common" 2382 2384 version = "0.8.0" 2383 - source = "git+https://tangled.org/@nonbinary.computer/jacquard#1c7fc38baf8f100875ba178c19a255e34727b116" 2385 + source = "git+https://tangled.org/@nonbinary.computer/jacquard#1f831994b95d87fe938d4e7b2213e44bbd18e2bd" 2384 2386 dependencies = [ 2385 2387 "base64 0.22.1", 2386 2388 "bon", ··· 2433 2435 [[package]] 2434 2436 name = "jacquard-derive" 2435 2437 version = "0.8.0" 2436 - source = "git+https://tangled.org/@nonbinary.computer/jacquard#1c7fc38baf8f100875ba178c19a255e34727b116" 2438 + source = "git+https://tangled.org/@nonbinary.computer/jacquard#1f831994b95d87fe938d4e7b2213e44bbd18e2bd" 2437 2439 dependencies = [ 2438 2440 "heck 0.5.0", 2439 2441 "jacquard-lexicon 0.8.0 (git+https://tangled.org/@nonbinary.computer/jacquard)", ··· 2470 2472 [[package]] 2471 2473 name = "jacquard-identity" 2472 2474 version = "0.8.0" 2473 - source = "git+https://tangled.org/@nonbinary.computer/jacquard#1c7fc38baf8f100875ba178c19a255e34727b116" 2475 + source = "git+https://tangled.org/@nonbinary.computer/jacquard#1f831994b95d87fe938d4e7b2213e44bbd18e2bd" 2474 2476 dependencies = [ 2475 2477 "bon", 2476 2478 "bytes", ··· 2544 2546 [[package]] 2545 2547 name = "jacquard-lexicon" 2546 2548 version = "0.8.0" 2547 - source = "git+https://tangled.org/@nonbinary.computer/jacquard#1c7fc38baf8f100875ba178c19a255e34727b116" 2549 + source = "git+https://tangled.org/@nonbinary.computer/jacquard#1f831994b95d87fe938d4e7b2213e44bbd18e2bd" 2548 2550 dependencies = [ 2549 2551 "glob", 2550 2552 "heck 0.5.0",
+12 -7
crates/jacquard-lexicon/src/codegen/schema_impl.rs
··· 13 13 /// 14 14 /// Takes the original lexicon doc and type metadata to generate a complete 15 15 /// impl with const literal and validation code. 16 - pub fn generate_schema_impl(type_name: &str, doc: &LexiconDoc, has_lifetime: bool) -> TokenStream { 16 + pub fn generate_schema_impl( 17 + type_name: &str, 18 + doc: &LexiconDoc, 19 + def_name: &str, 20 + has_lifetime: bool, 21 + ) -> TokenStream { 17 22 let nsid = doc.id.as_ref(); 18 23 19 24 // Generate lifetime parameter ··· 26 31 // Generate the lexicon doc literal using existing doc_to_tokens 27 32 let doc_literal = doc_to_tokens::doc_to_tokens(doc); 28 33 29 - // Extract validation checks from lexicon doc 30 - let validation_checks = extract_validation_checks(doc); 34 + // Extract validation checks from lexicon doc for the specific def 35 + let validation_checks = extract_validation_checks(doc, def_name); 31 36 32 37 // Generate validation code using existing validations_to_tokens 33 38 let validation_code = doc_to_tokens::validations_to_tokens(&validation_checks); ··· 57 62 /// 58 63 /// Walks the lexicon structure and builds ValidationCheck structs for all 59 64 /// constraint fields (max_length, max_graphemes, minimum, maximum, etc.) 60 - fn extract_validation_checks(doc: &LexiconDoc) -> Vec<ValidationCheck> { 65 + fn extract_validation_checks(doc: &LexiconDoc, def_name: &str) -> Vec<ValidationCheck> { 61 66 let mut checks = Vec::new(); 62 67 63 - // Get main def 64 - if let Some(main_def) = doc.defs.get("main") { 65 - match main_def { 68 + // Get the specified def 69 + if let Some(def) = doc.defs.get(def_name) { 70 + match def { 66 71 LexUserType::Record(rec) => { 67 72 match &rec.record { 68 73 LexRecordRecord::Object(obj) => {
+3 -2
crates/jacquard-lexicon/src/codegen/structs.rs
··· 219 219 // Generate LexiconSchema impl from original lexicon 220 220 let lex_doc = self.corpus.get(nsid).expect("nsid exists in corpus"); 221 221 let schema_impl = 222 - super::schema_impl::generate_schema_impl(&type_name, lex_doc, true); 222 + super::schema_impl::generate_schema_impl(&type_name, lex_doc, "main", true); 223 223 224 224 Ok(quote! { 225 225 #struct_def ··· 341 341 342 342 // Generate LexiconSchema impl from original lexicon 343 343 let lex_doc = self.corpus.get(nsid).expect("nsid exists in corpus"); 344 - let schema_impl = super::schema_impl::generate_schema_impl(&type_name, lex_doc, true); 344 + let schema_impl = 345 + super::schema_impl::generate_schema_impl(&type_name, lex_doc, def_name, true); 345 346 346 347 Ok(quote! { 347 348 #struct_def