nucleation 0.3.15

A high-performance Minecraft schematic parser and utility library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
use crate::blockpedia::{errors::*, BlockFacts, Result, BLOCKS};
use std::collections::HashMap;

/// Find all blocks that have a specific property with a specific value
pub fn find_blocks_by_property(
    property: &str,
    value: &str,
) -> impl Iterator<Item = &'static BlockFacts> {
    let property = property.to_string();
    let value = value.to_string();
    BLOCKS
        .values()
        .filter(move |block| {
            block.get_property(&property) == Some(value.as_str())
                || block
                    .get_property_values(&property)
                    .map(|values| values.contains(&value))
                    .unwrap_or(false)
        })
        .copied()
}

/// Find all blocks that match a predicate function
pub fn find_blocks_matching<F>(predicate: F) -> impl Iterator<Item = &'static BlockFacts>
where
    F: Fn(&BlockFacts) -> bool,
{
    BLOCKS
        .values()
        .filter(move |block| predicate(block))
        .copied()
}

/// Search for blocks using a glob-like pattern (supports * wildcard)
pub fn search_blocks(pattern: &str) -> impl Iterator<Item = &'static BlockFacts> {
    let pattern = pattern.to_lowercase();
    BLOCKS
        .values()
        .filter(move |block| {
            let block_id = block.id().to_lowercase();
            if pattern.contains('*') {
                // Simple glob matching - split on * and check each part exists in order
                let parts: Vec<&str> = pattern.split('*').collect();
                if parts.is_empty() {
                    return true;
                }

                let mut search_pos = 0;
                for (i, part) in parts.iter().enumerate() {
                    if part.is_empty() {
                        continue;
                    }

                    if i == 0 {
                        // First part - must be at the beginning
                        if !block_id.starts_with(part) {
                            return false;
                        }
                        search_pos = part.len();
                    } else if i == parts.len() - 1 {
                        // Last part - must be at the end
                        if !block_id.ends_with(part) {
                            return false;
                        }
                    } else {
                        // Middle part - must exist after current position
                        if let Some(pos) = block_id[search_pos..].find(part) {
                            search_pos += pos + part.len();
                        } else {
                            return false;
                        }
                    }
                }
                true
            } else {
                // Exact substring match
                block_id.contains(&pattern)
            }
        })
        .copied()
}

/// Get all possible values for a specific property across all blocks
pub fn get_property_values(property: &str) -> Option<Vec<String>> {
    let mut all_values = std::collections::HashSet::new();
    let mut found_property = false;

    for block in BLOCKS.values() {
        if let Some(values) = block.get_property_values(property) {
            found_property = true;
            for value in values {
                all_values.insert(value);
            }
        }
    }

    if found_property {
        let mut sorted_values: Vec<String> = all_values.into_iter().collect();
        sorted_values.sort();
        Some(sorted_values)
    } else {
        None
    }
}

/// Count blocks that match a predicate
pub fn count_blocks_where<F>(predicate: F) -> usize
where
    F: Fn(&BlockFacts) -> bool,
{
    BLOCKS
        .values()
        .filter(move |block| predicate(block))
        .count()
}

/// Get block families - groups of related blocks
pub fn get_block_families() -> HashMap<String, Vec<String>> {
    let mut families = HashMap::new();

    for block in BLOCKS.values() {
        let id = block.id();

        // Extract family name from block ID
        // minecraft:oak_stairs -> stairs
        // minecraft:red_wool -> wool
        // minecraft:stone_brick_slab -> slab

        if let Some(colon_pos) = id.find(':') {
            let name_part = &id[colon_pos + 1..];

            // Common patterns for families
            let family_name = if name_part.ends_with("_stairs") {
                "stairs"
            } else if name_part.ends_with("_slab") {
                "slab"
            } else if name_part.ends_with("_wool") {
                "wool"
            } else if name_part.ends_with("_log") {
                "log"
            } else if name_part.ends_with("_planks") {
                "planks"
            } else if name_part.ends_with("_leaves") {
                "leaves"
            } else if name_part.ends_with("_door") {
                "door"
            } else if name_part.ends_with("_fence") {
                "fence"
            } else if name_part.ends_with("_wall") {
                "wall"
            } else if name_part.contains("_wood") {
                "wood"
            } else if name_part.contains("stone") && !name_part.contains("redstone") {
                "stone"
            } else {
                // For blocks that don't match patterns, use the full name
                name_part
            };

            families
                .entry(family_name.to_string())
                .or_insert_with(Vec::new)
                .push(id.to_string());
        }
    }

    // Sort each family's blocks
    for blocks in families.values_mut() {
        blocks.sort();
    }

    families
}

/// Find blocks that have multiple specific properties
pub fn blocks_with_properties(
    properties: &[(&str, &str)],
) -> impl Iterator<Item = &'static BlockFacts> {
    let properties: Vec<(String, String)> = properties
        .iter()
        .map(|(prop, value)| (prop.to_string(), value.to_string()))
        .collect();
    BLOCKS
        .values()
        .filter(move |block| {
            properties.iter().all(|(prop, value)| {
                if value == "*" {
                    // Wildcard - just check if property exists
                    block.has_property(prop)
                } else {
                    // Check for exact value match
                    block.get_property(prop) == Some(value.as_str())
                        || block
                            .get_property_values(prop)
                            .map(|values| values.contains(value))
                            .unwrap_or(false)
                }
            })
        })
        .copied()
}

/// Find properties that appear in less than a certain percentage of blocks
pub fn find_rare_properties(max_frequency: f64) -> HashMap<String, usize> {
    let total_blocks = BLOCKS.len();
    let mut property_counts = HashMap::new();

    // Count how many blocks have each property
    for block in BLOCKS.values() {
        for (property, _) in block.properties {
            *property_counts.entry(property.to_string()).or_insert(0) += 1;
        }
    }

    // Filter to rare properties
    property_counts
        .into_iter()
        .filter(|(_, count)| (*count as f64 / total_blocks as f64) < max_frequency)
        .collect()
}

/// Statistics about block properties
#[derive(Debug)]
pub struct PropertyStats {
    pub total_unique_properties: usize,
    pub most_common_property: (String, usize),
    pub blocks_with_no_properties: usize,
    pub average_properties_per_block: f64,
}

/// Get comprehensive statistics about block properties
pub fn get_property_stats() -> PropertyStats {
    let mut property_counts = HashMap::new();
    let mut blocks_with_no_properties = 0;
    let mut total_property_instances = 0;

    for block in BLOCKS.values() {
        if block.properties.is_empty() {
            blocks_with_no_properties += 1;
        } else {
            total_property_instances += block.properties.len();
            for (property, _) in block.properties {
                *property_counts.entry(property.to_string()).or_insert(0) += 1;
            }
        }
    }

    let most_common_property = property_counts
        .iter()
        .max_by_key(|(_, count)| *count)
        .map(|(prop, count)| (prop.clone(), *count))
        .unwrap_or(("none".to_string(), 0));

    PropertyStats {
        total_unique_properties: property_counts.len(),
        most_common_property,
        blocks_with_no_properties,
        average_properties_per_block: total_property_instances as f64 / BLOCKS.len() as f64,
    }
}

/// Enhanced block family detection with better categorization
pub fn get_enhanced_block_families() -> HashMap<String, Vec<String>> {
    let mut families = HashMap::new();

    for block in BLOCKS.values() {
        let id = block.id();

        if let Some(colon_pos) = id.find(':') {
            let name_part = &id[colon_pos + 1..];

            // Enhanced family detection with priority order
            let family_name = detect_block_family(name_part);

            families
                .entry(family_name.to_string())
                .or_insert_with(Vec::new)
                .push(id.to_string());
        }
    }

    // Sort each family's blocks
    for blocks in families.values_mut() {
        blocks.sort();
    }

    families
}

fn detect_block_family(name_part: &str) -> &str {
    // Priority-ordered family detection

    // Building materials
    if name_part.ends_with("_stairs") {
        return "stairs";
    }
    if name_part.ends_with("_slab") {
        return "slab";
    }
    if name_part.ends_with("_wall") {
        return "wall";
    }
    if name_part.ends_with("_fence") {
        return "fence";
    }
    if name_part.ends_with("_fence_gate") {
        return "fence_gate";
    }
    if name_part.ends_with("_door") {
        return "door";
    }
    if name_part.ends_with("_trapdoor") {
        return "trapdoor";
    }
    if name_part.ends_with("_button") {
        return "button";
    }
    if name_part.ends_with("_pressure_plate") {
        return "pressure_plate";
    }

    // Natural materials
    if name_part.ends_with("_wood") || name_part.ends_with("_log") {
        return "wood";
    }
    if name_part.ends_with("_planks") {
        return "planks";
    }
    if name_part.ends_with("_leaves") {
        return "leaves";
    }
    if name_part.ends_with("_sapling") {
        return "sapling";
    }

    // Decorative blocks
    if name_part.ends_with("_wool") {
        return "wool";
    }
    if name_part.ends_with("_carpet") {
        return "carpet";
    }
    if name_part.ends_with("_concrete") {
        return "concrete";
    }
    if name_part.ends_with("_concrete_powder") {
        return "concrete_powder";
    }
    if name_part.ends_with("_terracotta") {
        return "terracotta";
    }
    if name_part.ends_with("_glazed_terracotta") {
        return "glazed_terracotta";
    }
    if name_part.ends_with("_glass") {
        return "glass";
    }
    if name_part.ends_with("_glass_pane") {
        return "glass_pane";
    }
    if name_part.ends_with("_stained_glass") {
        return "stained_glass";
    }
    if name_part.ends_with("_stained_glass_pane") {
        return "stained_glass_pane";
    }

    // Stone variants
    if name_part.contains("stone")
        && !name_part.contains("redstone")
        && !name_part.contains("sandstone")
    {
        return "stone";
    }
    if name_part.contains("sandstone") {
        return "sandstone";
    }
    if name_part.contains("granite") {
        return "granite";
    }
    if name_part.contains("diorite") {
        return "diorite";
    }
    if name_part.contains("andesite") {
        return "andesite";
    }

    // Redstone components
    if name_part.contains("redstone") {
        return "redstone";
    }

    // Ores and metals
    if name_part.ends_with("_ore") {
        return "ore";
    }
    if name_part.starts_with("raw_") {
        return "raw_materials";
    }
    if name_part.contains("_ingot") || name_part.contains("_nugget") {
        return "metals";
    }

    // Tools and weapons
    if name_part.ends_with("_sword") {
        return "sword";
    }
    if name_part.ends_with("_pickaxe") {
        return "pickaxe";
    }
    if name_part.ends_with("_axe") && !name_part.ends_with("_pickaxe") {
        return "axe";
    }
    if name_part.ends_with("_shovel") {
        return "shovel";
    }
    if name_part.ends_with("_hoe") {
        return "hoe";
    }

    // Armor
    if name_part.ends_with("_helmet") {
        return "helmet";
    }
    if name_part.ends_with("_chestplate") {
        return "chestplate";
    }
    if name_part.ends_with("_leggings") {
        return "leggings";
    }
    if name_part.ends_with("_boots") {
        return "boots";
    }

    // Food
    if name_part.contains("bread") || name_part.contains("cake") || name_part.contains("cookie") {
        return "food";
    }

    // Use the full name as fallback
    name_part
}

/// Find blocks with complex property combinations
pub fn blocks_with_complex_properties(
    requirements: &[(String, Vec<String>)],
) -> impl Iterator<Item = &'static BlockFacts> {
    let requirements: Vec<(String, Vec<String>)> = requirements.to_vec();
    BLOCKS
        .values()
        .filter(move |block| {
            requirements.iter().all(|(prop, values)| {
                if let Some(block_values) = block.get_property_values(prop) {
                    values
                        .iter()
                        .any(|required_val| block_values.contains(required_val))
                } else {
                    false
                }
            })
        })
        .copied()
}

/// Analyze property correlation - find properties that often appear together
pub fn analyze_property_correlation() -> HashMap<String, Vec<(String, f64)>> {
    let mut correlations = HashMap::new();
    let mut property_pairs = HashMap::new();
    let mut individual_properties = HashMap::new();

    // Count property occurrences and co-occurrences
    for block in BLOCKS.values() {
        let block_properties: Vec<String> = block
            .properties
            .iter()
            .map(|(p, _)| p.to_string())
            .collect();

        // Count individual properties
        for prop in &block_properties {
            *individual_properties.entry(prop.clone()).or_insert(0) += 1;
        }

        // Count property pairs
        for i in 0..block_properties.len() {
            for j in (i + 1)..block_properties.len() {
                let pair = if block_properties[i] < block_properties[j] {
                    (block_properties[i].clone(), block_properties[j].clone())
                } else {
                    (block_properties[j].clone(), block_properties[i].clone())
                };
                *property_pairs.entry(pair).or_insert(0) += 1;
            }
        }
    }

    // Calculate correlations
    for ((prop1, prop2), pair_count) in property_pairs {
        let prop1_count = individual_properties.get(&prop1).unwrap_or(&0);
        let prop2_count = individual_properties.get(&prop2).unwrap_or(&0);

        if *prop1_count > 0 && *prop2_count > 0 {
            let correlation = pair_count as f64 / (*prop1_count as f64).min(*prop2_count as f64);

            correlations
                .entry(prop1.clone())
                .or_insert_with(Vec::new)
                .push((prop2.clone(), correlation));

            correlations
                .entry(prop2)
                .or_insert_with(Vec::new)
                .push((prop1, correlation));
        }
    }

    // Sort correlations by strength
    for correlations_list in correlations.values_mut() {
        correlations_list
            .sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap_or(std::cmp::Ordering::Equal));
    }

    correlations
}

/// Find blocks that are "similar" based on shared properties
pub fn find_similar_blocks(
    target_block_id: &str,
    min_shared_properties: usize,
) -> Vec<(&'static BlockFacts, usize)> {
    let target_block = match BLOCKS.get(target_block_id) {
        Some(block) => block,
        None => return Vec::new(),
    };

    let target_properties: std::collections::HashSet<&str> =
        target_block.properties.iter().map(|(p, _)| *p).collect();

    let mut similar_blocks = Vec::new();

    for block in BLOCKS.values() {
        if block.id() == target_block_id {
            continue; // Skip the target block itself
        }

        let block_properties: std::collections::HashSet<&str> =
            block.properties.iter().map(|(p, _)| *p).collect();
        let shared_count = target_properties.intersection(&block_properties).count();

        if shared_count >= min_shared_properties {
            similar_blocks.push((*block, shared_count));
        }
    }

    // Sort by number of shared properties (descending)
    similar_blocks.sort_by(|a, b| b.1.cmp(&a.1));
    similar_blocks
}

/// Advanced property statistics with more detailed analysis
#[derive(Debug)]
pub struct AdvancedPropertyStats {
    pub basic_stats: PropertyStats,
    pub property_distribution: HashMap<String, HashMap<String, usize>>, // property -> value -> count
    pub most_diverse_property: (String, usize), // property with most different values
    pub most_correlated_properties: Vec<(String, String, f64)>, // top correlated property pairs
}

pub fn get_advanced_property_stats() -> AdvancedPropertyStats {
    let basic_stats = get_property_stats();
    let mut property_distribution = HashMap::new();

    // Analyze value distribution for each property
    for block in BLOCKS.values() {
        for (property, _) in block.properties {
            if let Some(values) = block.get_property_values(property) {
                let prop_dist = property_distribution
                    .entry(property.to_string())
                    .or_insert_with(HashMap::new);
                for value in values {
                    *prop_dist.entry(value).or_insert(0) += 1;
                }
            }
        }
    }

    // Find most diverse property
    let most_diverse_property = property_distribution
        .iter()
        .max_by_key(|(_, values)| values.len())
        .map(|(prop, values)| (prop.clone(), values.len()))
        .unwrap_or(("none".to_string(), 0));

    // Get top correlated properties
    let correlations = analyze_property_correlation();
    let mut all_correlations = Vec::new();

    for (prop1, correlations_list) in correlations {
        for (prop2, correlation) in correlations_list {
            if prop1 < prop2 {
                // Avoid duplicates
                all_correlations.push((prop1.clone(), prop2, correlation));
            }
        }
    }

    all_correlations.sort_by(|a, b| b.2.partial_cmp(&a.2).unwrap_or(std::cmp::Ordering::Equal));
    let most_correlated_properties = all_correlations.into_iter().take(5).collect();

    AdvancedPropertyStats {
        basic_stats,
        property_distribution,
        most_diverse_property,
        most_correlated_properties,
    }
}

/// Validated query functions with proper error handling
pub mod validated {
    use super::*;

    /// Safely find blocks by property with validation
    pub fn find_blocks_by_property_safe(
        property: &str,
        value: &str,
    ) -> Result<Vec<&'static BlockFacts>> {
        // Validate inputs
        validation::validate_property_name(property)?;
        validation::validate_property_value(value)?;

        let results: Vec<_> = find_blocks_by_property(property, value).collect();

        if results.is_empty() {
            return Err(BlockpediaError::Query(QueryError::NoResults(format!(
                "No blocks found with property '{}' = '{}'",
                property, value
            ))));
        }

        Ok(results)
    }

    /// Safely search blocks with pattern validation
    pub fn search_blocks_safe(pattern: &str) -> Result<Vec<&'static BlockFacts>> {
        if pattern.is_empty() {
            return Err(BlockpediaError::invalid_format(
                pattern,
                "non-empty search pattern",
            ));
        }

        if pattern.len() > 128 {
            return Err(BlockpediaError::Validation(
                ValidationError::InvalidLength {
                    input: pattern.to_string(),
                    min_length: 1,
                    max_length: 128,
                },
            ));
        }

        // Check for invalid pattern characters
        let invalid_chars: Vec<char> = pattern
            .chars()
            .filter(|c| {
                !c.is_ascii_alphanumeric() && *c != '_' && *c != '-' && *c != ':' && *c != '*'
            })
            .collect();

        if !invalid_chars.is_empty() {
            return Err(BlockpediaError::Validation(
                ValidationError::InvalidCharacters {
                    input: pattern.to_string(),
                    invalid_chars,
                },
            ));
        }

        let results: Vec<_> = search_blocks(pattern).collect();

        if results.is_empty() {
            // Try to suggest alternatives
            let suggestions = recovery::suggest_similar_blocks(pattern);
            let suggestion_text = if suggestions.is_empty() {
                "No suggestions available".to_string()
            } else {
                format!("Suggestions: {}", suggestions.join(", "))
            };

            return Err(BlockpediaError::Query(QueryError::NoResults(format!(
                "No blocks match pattern '{}'. {}",
                pattern, suggestion_text
            ))));
        }

        Ok(results)
    }

    /// Safely get property values with validation
    pub fn get_property_values_safe(property: &str) -> Result<Vec<String>> {
        validation::validate_property_name(property)?;

        get_property_values(property).ok_or_else(|| {
            BlockpediaError::Property(PropertyError::NotFound {
                block_id: "any".to_string(),
                property: property.to_string(),
            })
        })
    }

    /// Safely validate block properties with detailed error reporting
    pub fn validate_block_properties_safe(
        block_id: &str,
        properties: &[(String, String)],
    ) -> Result<()> {
        validation::validate_block_id(block_id)?;

        let block_facts = BLOCKS
            .get(block_id)
            .ok_or_else(|| BlockpediaError::block_not_found(block_id))?;

        let mut errors = Vec::new();

        for (property, value) in properties {
            // Validate property name format
            if let Err(e) = validation::validate_property_name(property) {
                errors.push(format!("Property '{}': {}", property, e));
                continue;
            }

            // Validate property value format
            if let Err(e) = validation::validate_property_value(value) {
                errors.push(format!("Value '{}': {}", value, e));
                continue;
            }

            // Check if property exists on block
            if !block_facts.has_property(property) {
                errors.push(format!(
                    "Property '{}' does not exist on block '{}'",
                    property, block_id
                ));
                continue;
            }

            // Check if value is valid for property
            if let Some(valid_values) = block_facts.get_property_values(property) {
                if !valid_values.contains(value) {
                    errors.push(format!(
                        "Invalid value '{}' for property '{}'. Valid values: {:?}",
                        value, property, valid_values
                    ));
                }
            }
        }

        if !errors.is_empty() {
            return Err(BlockpediaError::State(StateError::ValidationFailed {
                state: format!("{}[properties]", block_id),
                errors,
            }));
        }

        Ok(())
    }

    /// Safely create a BlockState with comprehensive validation and helpful error recovery
    pub fn create_block_state_safe(
        block_id: &str,
        properties: &[(String, String)],
    ) -> Result<crate::blockpedia::BlockState> {
        // First validate all properties before creating the state
        validate_block_properties_safe(block_id, properties)?;

        // If validation passed, create the state step by step
        let mut state = crate::blockpedia::BlockState::new(block_id)?;

        for (property, value) in properties {
            // This should not fail since we already validated, but handle errors gracefully
            state = state.with(property, value)?;
        }

        Ok(state)
    }

    /// Query with timeout simulation (for future async support)
    pub fn query_with_timeout<F, R>(query_name: &str, query_fn: F) -> Result<R>
    where
        F: FnOnce() -> R,
    {
        // For now, just execute the query
        // In a real async implementation, this would have actual timeout logic

        if query_name.len() > 64 {
            return Err(BlockpediaError::Query(QueryError::InvalidSyntax(
                "Query name too long".to_string(),
            )));
        }

        Ok(query_fn())
    }
}