···116116}
117117118118// CreateDocument in a repo with the given rkey.
119119-// Always tries to validate the [Document] against the [Record] saved.
119119+// Always tries to validate the [Document] against the lexicon saved.
120120//
121121// Rkey can be nil.
122122func CreateDocument(ctx context.Context, client lexutil.LexClient, repo syntax.AtIdentifier, rkey *syntax.RecordKey, doc *Document) (*Result, error) {
···124124}
125125126126// UpdateDocument in a repo with the given rkey.
127127-// Always tries to validate the [Document] against the [Record] saved.
127127+// Always tries to validate the [Document] against the lexicon saved.
128128func UpdateDocument(ctx context.Context, client lexutil.LexClient, repo syntax.AtIdentifier, rkey syntax.RecordKey, doc *Document) (*Result, error) {
129129 return updateRecord(ctx, client, CollectionDocument, repo, rkey, doc)
130130}
···161161 err = ErrInvalidType{collection, v.Type}
162162 return
163163 }
164164+ if v.Record.Type() != collection {
165165+ err = ErrInvalidType{collection, v.Record.Type()}
166166+ return
167167+ }
164168 return v.Record.(T), nil
165169}
166170···184188 if v.Record == nil {
185189 return nil, nil, ErrInvalidType{collection, v.Type}
186190 }
191191+ if v.Record.Type() != collection {
192192+ return nil, nil, ErrInvalidType{collection, v.Record.Type()}
193193+ }
187194 docs[i] = v.Record.(T)
188195 i++
189196 }
···191198}
192199193200// createRecord a T in a repo with the given rkey.
194194-// Always tries to validate the [Document] against the [Record] saved.
201201+// Always tries to validate the [Document] against the lexicon saved.
195202//
196203// Rkey can be nil.
197204func createRecord[T Record](ctx context.Context, client lexutil.LexClient, collection string, repo syntax.AtIdentifier, rkey *syntax.RecordKey, v T) (*Result, error) {
···219226}
220227221228// updateRecord T in a repo with the given rkey.
222222-// Always tries to validate the [Document] against the [Record] saved.
229229+// Always tries to validate the [Document] against the lexicon saved.
223230func updateRecord[T Record](ctx context.Context, client lexutil.LexClient, collection string, repo syntax.AtIdentifier, rkey syntax.RecordKey, v T) (*Result, error) {
224231 mp, err := MarshalToMap(&RecordJSON{Record: v})
225232 if err != nil {
+39-1
publication.go
···11package site
2233-import "strings"
33+import (
44+ "context"
55+ "strings"
66+77+ "github.com/bluesky-social/indigo/atproto/syntax"
88+ lexutil "github.com/bluesky-social/indigo/lex/util"
99+)
410511const CollectionPublication = CollectionBase + ".publication"
612···4854 // ShowInDiscover decides whether the [Publication] should appear in discovery feeds.
4955 ShowInDiscover bool `json:"showInDiscover"`
5056}
5757+5858+// GetPublication returns the [Publication] in the repo associated with the rkey.
5959+// Automatically uses the latest CID.
6060+func GetPublication(ctx context.Context, client lexutil.LexClient, repo syntax.AtIdentifier, rkey syntax.RecordKey) (*Publication, error) {
6161+ return get[*Publication](ctx, client, CollectionPublication, repo, rkey)
6262+}
6363+6464+// ListPublications returns all the [Publication]s stored in the repo and the cursor.
6565+//
6666+// See [MaxItemsPerList].
6767+func ListPublications(ctx context.Context, client lexutil.LexClient, repo syntax.AtIdentifier, cursor string, reverse bool) ([]*Publication, *string, error) {
6868+ return listRecord[*Publication](ctx, client, CollectionPublication, repo, cursor, reverse)
6969+}
7070+7171+// CreatePublication in a repo with the given rkey.
7272+// Always tries to validate the [Publication] against the lexicon saved.
7373+//
7474+// Rkey can be nil.
7575+func CreatePublication(ctx context.Context, client lexutil.LexClient, repo syntax.AtIdentifier, rkey *syntax.RecordKey, pub *Publication) (*Result, error) {
7676+ return createRecord(ctx, client, CollectionPublication, repo, rkey, pub)
7777+}
7878+7979+// UpdatePublication in a repo with the given rkey.
8080+// Always tries to validate the [Publication] against the lexicon saved.
8181+func UpdatePublication(ctx context.Context, client lexutil.LexClient, repo syntax.AtIdentifier, rkey syntax.RecordKey, pub *Publication) (*Result, error) {
8282+ return updateRecord(ctx, client, CollectionPublication, repo, rkey, pub)
8383+}
8484+8585+// DeletePublication in a repo with the given rkey.
8686+func DeletePublication(ctx context.Context, client lexutil.LexClient, repo syntax.AtIdentifier, rkey syntax.RecordKey) error {
8787+ return deleteRecord(ctx, client, CollectionPublication, repo, rkey)
8888+}