A Transparent and Verifiable Way to Sync the AT Protocol's PLC Directory

update lib docs

+62 -10
+62 -10
docs/library.md
··· 228 229 ```go 230 type PLCOperation struct { 231 - DID string // The DID (did:plc:...) 232 - Operation map[string]interface{} // The operation data 233 - CID string // Content identifier 234 - Nullified interface{} // nil, false, or CID string 235 - CreatedAt time.Time // When it was created 236 - RawJSON []byte // Original JSON bytes 237 } 238 239 // Check if operation was nullified 240 if op.IsNullified() { 241 log.Printf("Operation %s was nullified by %s", op.CID, op.GetNullifyingCID()) 242 } 243 ``` 244 245 --- 246 247 ## Common Patterns ··· 441 } 442 443 func (p *OperationProcessor) processOperation(op plcbundle.PLCOperation) { 444 // Example: Extract PDS endpoints 445 - if services, ok := op.Operation["services"].(map[string]interface{}); ok { 446 if pds, ok := services["atproto_pds"].(map[string]interface{}); ok { 447 if endpoint, ok := pds["endpoint"].(string); ok { 448 log.Printf("DID %s uses PDS: %s", op.DID, endpoint) ··· 450 } 451 } 452 } 453 454 func main() { 455 processor, err := NewOperationProcessor("./plc_data") ··· 815 } 816 817 func (pt *PDSTracker) extractPDS(op plcbundle.PLCOperation) string { 818 - services, ok := op.Operation["services"].(map[string]interface{}) 819 if !ok { 820 return "" 821 } ··· 832 833 return endpoint 834 } 835 836 func (pt *PDSTracker) PrintResults() { 837 log.Printf("\nFound %d unique PDS endpoints:\n", len(pt.endpoints)) ··· 1045 } 1046 1047 // Check for new DIDs (operation type "create") 1048 - if opType, ok := op.Operation["type"].(string); ok && opType == "create" { 1049 - log.Printf(" ➕ New DID: %s", op.DID) 1050 } 1051 } 1052 }
··· 228 229 ```go 230 type PLCOperation struct { 231 + DID string // The DID (did:plc:...) 232 + Operation json.RawMessage // Raw JSON bytes (use GetOperationMap() to parse) 233 + CID string // Content identifier 234 + Nullified interface{} // nil, false, or CID string 235 + CreatedAt time.Time // When it was created 236 + 237 + // Internal fields (populated automatically) 238 + RawJSON []byte // Original JSON line 239 + ParsedOperation map[string]interface{} // Cached parsed data 240 } 241 242 + // Accessing operation data: 243 + operation, err := op.GetOperationMap() // Parses Operation field (cached) 244 + if err != nil || operation == nil { 245 + return 246 + } 247 + 248 + // Now you can access fields 249 + services := operation["services"].(map[string]interface{}) 250 + 251 // Check if operation was nullified 252 if op.IsNullified() { 253 log.Printf("Operation %s was nullified by %s", op.CID, op.GetNullifyingCID()) 254 } 255 ``` 256 257 + ### Accessing Operation Data 258 + 259 + The `Operation` field uses lazy parsing for performance. Always parse it before accessing: 260 + 261 + ```go 262 + // ❌ Wrong - won't compile 263 + services := op.Operation["services"] 264 + 265 + // ✅ Correct 266 + operation, err := op.GetOperationMap() 267 + if err != nil || operation == nil { 268 + return 269 + } 270 + services, ok := operation["services"].(map[string]interface{}) 271 + ``` 272 + 273 + The parsed data is cached, so repeated calls are fast: 274 + // First call: parses JSON 275 + data1, _ := op.GetOperationMap() 276 + 277 + // Second call: returns cached data (fast) 278 + data2, _ := op.GetOperationMap() 279 + 280 --- 281 282 ## Common Patterns ··· 476 } 477 478 func (p *OperationProcessor) processOperation(op plcbundle.PLCOperation) { 479 + // Parse Operation field on-demand 480 + operation, err := op.GetOperationMap() 481 + if err != nil || operation == nil { 482 + return 483 + } 484 + 485 // Example: Extract PDS endpoints 486 + if services, ok := operation["services"].(map[string]interface{}); ok { 487 if pds, ok := services["atproto_pds"].(map[string]interface{}); ok { 488 if endpoint, ok := pds["endpoint"].(string); ok { 489 log.Printf("DID %s uses PDS: %s", op.DID, endpoint) ··· 491 } 492 } 493 } 494 + 495 496 func main() { 497 processor, err := NewOperationProcessor("./plc_data") ··· 857 } 858 859 func (pt *PDSTracker) extractPDS(op plcbundle.PLCOperation) string { 860 + // Parse Operation field on-demand 861 + operation, err := op.GetOperationMap() 862 + if err != nil || operation == nil { 863 + return "" 864 + } 865 + 866 + services, ok := operation["services"].(map[string]interface{}) 867 if !ok { 868 return "" 869 } ··· 880 881 return endpoint 882 } 883 + 884 885 func (pt *PDSTracker) PrintResults() { 886 log.Printf("\nFound %d unique PDS endpoints:\n", len(pt.endpoints)) ··· 1094 } 1095 1096 // Check for new DIDs (operation type "create") 1097 + operation, err := op.GetOperationMap() 1098 + if err == nil && operation != nil { 1099 + if opType, ok := operation["type"].(string); ok && opType == "create" { 1100 + log.Printf(" ➕ New DID: %s", op.DID) 1101 + } 1102 } 1103 } 1104 }