sorbet-baml 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c97a86bec35a852f1d41ff171d595d2f414c999f0421cb19da7d825bc6af5ea6
4
- data.tar.gz: bc9c45e02ac421d272572b4383c10d4bdf5d87db445be05998ea67cec97fdadc
3
+ metadata.gz: e6ebc9d978b525e29a1a19ef184f073393d6a588e54d84dc2b9fd7034d1fa40c
4
+ data.tar.gz: f7d5e028fe65a4a4cc9b19c60dc17dd65fd13353634e55201db5189bb457447a
5
5
  SHA512:
6
- metadata.gz: c0ab662803d02f440767ea8385705ba0f00b4f54cd48343cee0ea067db2569d0b7845bce54882ea60d9a5e50ef3d6ef3688ed063e8720bedc0c5229a23901b95
7
- data.tar.gz: e36a8d5726d4ef489e21350827b9b0707382fb4fea29714c0583fb8b58ba7806d10dad9e214e326fc023e3750d2711f59bacd79ffd0f0ce54de7368c032a73de
6
+ metadata.gz: 40b4736cc561b5135ee32e08543148c018ea9963e016c6cbb66697cd346ff7cf30f7438d370853c045b40d062a47f38d7aaa1a9c6c8e92f8e7f6721b495966e0
7
+ data.tar.gz: 0caf0a19906655bbfae88723bbe5b38301601c1523c3cc3b8dc31a15bf6bdd02ceacb790cf0d4bddf718c1162ba51d7b0fcd08110578616cd7c7ac27272bcd42
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,5 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ </profile>
5
+ </component>
data/CLAUDE.md ADDED
@@ -0,0 +1,94 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Development Commands
6
+
7
+ **Running Tests:**
8
+ ```bash
9
+ bundle exec rspec # Run all tests
10
+ bundle exec rspec spec/path_spec.rb # Run specific test file
11
+ ```
12
+
13
+ **Type Checking:**
14
+ ```bash
15
+ bundle exec srb tc # Run Sorbet type checker
16
+ ```
17
+
18
+ **Development Setup:**
19
+ ```bash
20
+ bundle install # Install dependencies
21
+ bundle exec tapioca dsl # Generate RBI files for gems
22
+ bundle exec tapioca gem # Generate RBI files for dependencies
23
+ ```
24
+
25
+ **Linting:**
26
+ ```bash
27
+ bundle exec rubocop # Run RuboCop linter
28
+ bundle exec rubocop -a # Auto-fix violations where possible
29
+ ```
30
+
31
+ **Gem Tasks:**
32
+ ```bash
33
+ bundle exec rake build # Build the gem
34
+ bundle exec rake install # Install locally
35
+ bundle exec rake release # Release to RubyGems (maintainers only)
36
+ ```
37
+
38
+ ## Code Architecture
39
+
40
+ ### Core Components
41
+
42
+ **Main Library Entry Point:**
43
+ - `lib/sorbet_baml.rb` - Main module with public API methods and extension loading
44
+
45
+ **Core Conversion System:**
46
+ - `lib/sorbet_baml/converter.rb` - Main converter orchestrating BAML generation
47
+ - `lib/sorbet_baml/type_mapper.rb` - Maps Sorbet type objects to BAML type strings
48
+ - `lib/sorbet_baml/dependency_resolver.rb` - Handles topological sorting of dependencies
49
+
50
+ **Ruby-Idiomatic API Extensions:**
51
+ - `lib/sorbet_baml/struct_extensions.rb` - Adds `.to_baml` method to T::Struct
52
+ - `lib/sorbet_baml/enum_extensions.rb` - Adds `.to_baml` method to T::Enum
53
+
54
+ **Field Documentation:**
55
+ - `lib/sorbet_baml/comment_extractor.rb` - Extracts comments from source for field descriptions
56
+
57
+ ### Key Design Patterns
58
+
59
+ **Extension Pattern:** The gem extends T::Struct and T::Enum classes with `.to_baml` methods for a Ruby-idiomatic API.
60
+
61
+ **Dependency Resolution:** Uses topological sorting to ensure dependencies are output before types that reference them, preventing forward reference issues.
62
+
63
+ **Type Mapping:** Comprehensive mapping from Sorbet type system to BAML types:
64
+ - `T::Struct` → BAML classes
65
+ - `T::Enum` → BAML enums
66
+ - `T.nilable(T)` → optional types (`T?`)
67
+ - `T::Array[T]` → array types (`T[]`)
68
+ - `T::Hash[K,V]` → map types (`map<K,V>`)
69
+ - `T.any(T1, T2)` → union types (`T1 | T2`)
70
+
71
+ **Smart Defaults:** The API includes dependencies and field descriptions by default.
72
+
73
+ ### Type System Support
74
+
75
+ The gem provides complete coverage of Sorbet's type system:
76
+ - Basic types (String, Integer, Float, Boolean, Symbol, Date/Time)
77
+ - Complex types (Arrays, Hashes, Unions, Nilable)
78
+ - Structured types (T::Struct, T::Enum with full nesting support)
79
+ - Circular reference handling to prevent infinite loops
80
+
81
+ ### Testing Structure
82
+
83
+ - `spec/fixtures/` - Test data including complex type examples
84
+ - `spec/integration/` - End-to-end feature tests
85
+ - `spec/sorbet_baml/` - Unit tests for each component
86
+ - Comprehensive test coverage includes edge cases, circular references, and complex type combinations
87
+
88
+ ## Development Guidelines
89
+
90
+ **Type Safety:** All code uses `# typed: strict` and maintains full Sorbet compliance.
91
+
92
+ **Ruby Idioms:** The public API follows Ruby conventions with `.to_baml` instance methods rather than static factory methods.
93
+
94
+ **Field Descriptions:** Comments above field definitions are automatically extracted and included as BAML `@description` annotations for LLM context.