A community based topic aggregation platform built on atproto
1package repository 2 3import ( 4 "time" 5 6 "github.com/ipfs/go-cid" 7) 8 9// Repository represents an AT Protocol data repository 10type Repository struct { 11 DID string // Decentralized identifier of the repository owner 12 HeadCID cid.Cid // CID of the latest commit 13 Revision string // Current revision identifier 14 RecordCount int // Number of records in the repository 15 StorageSize int64 // Total storage size in bytes 16 CreatedAt time.Time 17 UpdatedAt time.Time 18} 19 20// Commit represents a signed repository commit 21type Commit struct { 22 CID cid.Cid // Content identifier of this commit 23 DID string // DID of the committer 24 Version int // Repository version 25 PrevCID *cid.Cid // CID of the previous commit (nil for first commit) 26 DataCID cid.Cid // CID of the MST root 27 Revision string // Revision identifier 28 Signature []byte // Cryptographic signature 29 SigningKeyID string // Key ID used for signing 30 CreatedAt time.Time 31} 32 33// Record represents a record in the repository 34type Record struct { 35 URI string // AT-URI of the record (e.g., at://did:plc:123/app.bsky.feed.post/abc) 36 CID cid.Cid // Content identifier 37 Collection string // Collection name (e.g., app.bsky.feed.post) 38 RecordKey string // Record key within collection 39 Value []byte // The actual record data (typically CBOR) 40 CreatedAt time.Time 41 UpdatedAt time.Time 42} 43 44 45// CreateRecordInput represents input for creating a record 46type CreateRecordInput struct { 47 DID string 48 Collection string 49 RecordKey string // Optional - will be generated if not provided 50 Record interface{} 51 Validate bool // Whether to validate against lexicon 52} 53 54// UpdateRecordInput represents input for updating a record 55type UpdateRecordInput struct { 56 DID string 57 Collection string 58 RecordKey string 59 Record interface{} 60 Validate bool 61} 62 63// GetRecordInput represents input for retrieving a record 64type GetRecordInput struct { 65 DID string 66 Collection string 67 RecordKey string 68} 69 70// DeleteRecordInput represents input for deleting a record 71type DeleteRecordInput struct { 72 DID string 73 Collection string 74 RecordKey string 75} 76 77// RepositoryService defines the business logic for repository operations 78type RepositoryService interface { 79 // Repository operations 80 CreateRepository(did string) (*Repository, error) 81 GetRepository(did string) (*Repository, error) 82 DeleteRepository(did string) error 83 84 // Record operations 85 CreateRecord(input CreateRecordInput) (*Record, error) 86 GetRecord(input GetRecordInput) (*Record, error) 87 UpdateRecord(input UpdateRecordInput) (*Record, error) 88 DeleteRecord(input DeleteRecordInput) error 89 90 // Collection operations 91 ListRecords(did string, collection string, limit int, cursor string) ([]*Record, string, error) 92 93 // Commit operations 94 GetCommit(did string, cid cid.Cid) (*Commit, error) 95 ListCommits(did string, limit int, cursor string) ([]*Commit, string, error) 96 97 // Export operations 98 ExportRepository(did string) ([]byte, error) // Returns CAR file 99 ImportRepository(did string, carData []byte) error 100} 101 102// RepositoryRepository defines the data access interface for repositories 103type RepositoryRepository interface { 104 // Repository operations 105 Create(repo *Repository) error 106 GetByDID(did string) (*Repository, error) 107 Update(repo *Repository) error 108 Delete(did string) error 109 110 // Commit operations 111 CreateCommit(commit *Commit) error 112 GetCommit(did string, cid cid.Cid) (*Commit, error) 113 GetLatestCommit(did string) (*Commit, error) 114 ListCommits(did string, limit int, offset int) ([]*Commit, error) 115 116 // Record operations 117 CreateRecord(record *Record) error 118 GetRecord(did string, collection string, recordKey string) (*Record, error) 119 UpdateRecord(record *Record) error 120 DeleteRecord(did string, collection string, recordKey string) error 121 ListRecords(did string, collection string, limit int, offset int) ([]*Record, error) 122 123}